
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
@flatfile/implementation-utils-collection-wrapper
Advanced tools
Provides a wrapper on top of @flatfile/api to provide a more convenient interface for working with V2 records using collect.js.
Provides a wrapper on top of @flatfile/api
to provide a more convenient interface for working with V2 records using collect.js. This package includes three main components: Item
for individual record management, ItemCollection
for working with groups of records, and CollectionClient
as a simplified API client wrapper.
Item
: A wrapper class for a single V2 API record that provides additional functionality for working with records such as tracking mutations, merging, hashing, and type-safe property access.ItemCollection
: A collection wrapper built on collect.js that provides specialized filtering methods for working with groups of Items.CollectionClient
: A simplified wrapper around the Flatfile API client that automatically converts raw records to Items and handles batch operations.npm install @flatfile/implementation-utils-collection-wrapper
import {
CollectionClient,
Item,
ItemCollection,
} from "@flatfile/implementation-utils-collection-wrapper";
// Initialize the client
const client = new CollectionClient();
// Define your record type
interface Person {
firstName?: string;
lastName?: string;
email?: string;
age?: number;
}
// Fetch records from a sheet
const records = await client.get<Person>("sheet-id", { limit: 100 });
// Work with individual items
records.each((person) => {
if (person.str("firstName") === "John") {
person.set("lastName", "Updated");
person.info("firstName", "Name was processed");
}
});
// Update records back to Flatfile
await client.update(records, { sheetId: "sheet-id" });
A wrapper around the Flatfile API client that simplifies record operations.
class CollectionClient {
constructor(client?: FlatfileClient);
// Fetch records from a sheet and convert to ItemCollection
async get<T>(
sheetId: string,
options?: GetRecordsRequestOptions
): Promise<ItemCollection<T>>;
// Update changed records back to Flatfile
async update<T>(
records: ItemCollection<T>,
options?: WriteRecordsRequestOptions
): Promise<void>;
}
Methods:
get()
- Fetches records from a sheet, filters invalid records, and returns an ItemCollectionupdate()
- Sends only changed records back to Flatfile and commits the changesA wrapper class for individual V2 API records with change tracking and utility methods.
class Item<T> {
// Property access
get<K>(key: K): T[K] | undefined;
set<K>(key: K, value: T[K]): this;
unset(key: K): this;
// Type-safe getters
str(key: K): string | undefined; // Get as trimmed string
defStr(key: K): string; // Get as string with empty fallback
bool(key: K): boolean; // Get as boolean
num(key: K): number; // Get as parsed number
// State management
isDirty(options?: { key?: K }): boolean;
commit(): void;
// Messages
info(key: K, message: string): this;
warn(key: K, message: string): this;
err(key: K, message: string): this;
// Utility methods
keys(): K[];
values(): Record<K, T[K]>;
entries(): [K, T[K]][];
hash(...keys: K[]): string;
// Record operations
merge<U>(item: Item<U>, options?: { overwrite?: boolean }): Item<T & U>;
hasConflict(item: Item<T>, options?: { keys?: K[] }): boolean;
copy<U>(options: CopyOptions<U>): Item<T & U>;
// Deletion
delete(): void;
isDeleted(): boolean;
}
Key Features:
A collection wrapper built on collect.js with specialized filtering methods.
class ItemCollection<T> extends Collection<Item<T>> {
// Specialized filters
forSheet(slugOrId: string): ItemCollection<T>;
changes(options?: { writeRequired?: boolean }): ItemCollection<T>;
onlyPresent(): ItemCollection<T>;
deletions(): ItemCollection<T>;
}
Methods:
forSheet()
- Filter items by sheet slug or IDchanges()
- Get only items with pending changesonlyPresent()
- Exclude deleted itemsdeletions()
- Get only deleted itemsPlus all standard collect.js methods: filter()
, map()
, each()
, first()
, count()
, etc.
const item = new Item<Person>({ firstName: "John", email: "invalid-email" });
// Add different types of messages
item.info("firstName", "Name looks good");
item.warn("email", "Email format seems unusual");
item.err("email", "Invalid email format");
// Messages are included in changesets
const changeset = item.changeset();
console.log(changeset.__i); // Array of message objects
const person1 = new Item({
firstName: "John",
lastName: "Doe",
email: "john@example.com",
});
const person2 = new Item({
firstName: "John",
lastName: "Smith",
phone: "555-1234",
});
// Check for conflicts
if (person1.hasConflict(person2)) {
console.log("Records have conflicting values");
}
// Merge records
const merged = person1.merge(person2, { overwrite: false }); // Only adds missing fields
// or
const merged = person1.merge(person2, { overwrite: true }); // Overwrites with truthy values
// Fetch records
const records = await client.get<Person>("sheet-id");
// Process records
records
.filter((person) => person.str("email")?.includes("@gmail.com"))
.each((person) => {
person.set("emailProvider", "Gmail");
person.info("emailProvider", "Detected Gmail address");
});
// Update only changed records
await client.update(records.changes(), { sheetId: "sheet-id" });
const records = await client.get<Person>("sheet-id");
// Get records with changes
const dirtyRecords = records.changes();
// Get records for a specific sheet
const sheetRecords = records.forSheet("contacts");
// Get non-deleted records
const activeRecords = records.onlyPresent();
// Get deleted records
const deletedRecords = records.deletions();
// Chain filters
const recentUpdates = records
.changes({ writeRequired: true })
.filter((person) => person.str("lastName")?.startsWith("S"))
.onlyPresent();
The package provides full TypeScript support:
interface Contact {
firstName?: string;
lastName?: string;
email?: string;
phone?: string;
}
const contact = new Item<Contact>({ firstName: "John" });
// Type-safe property access
contact.set("firstName", "Jane"); // Valid
contact.set("invalid", "value"); // TypeScript error
// Type-safe getters
const name: string | undefined = contact.get("firstName"); // Correctly typed
const age: number = contact.get("age"); // TypeScript error - 'age' not in Contact
try {
const records = await client.get<Person>("sheet-id");
await client.update(records, { sheetId: "sheet-id" });
} catch (error) {
console.error("Failed to process records:", error);
}
// Individual item validation
const item = new Item<Person>({
__i: [{ key: "email", message: "Invalid email" }],
});
if (!item.valid) {
console.log("Item has validation errors");
}
FAQs
Provides a wrapper on top of @flatfile/api to provide a more convenient interface for working with V2 records using collect.js.
We found that @flatfile/implementation-utils-collection-wrapper demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 15 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.