UNPKG

@flatfile/safe-api

Version:

Flatfile Safe API client with streaming capabilities

79 lines (78 loc) 3.33 kB
import { FlatfileClient, Flatfile } from '@flatfile/api'; import { StreamRecordsQuery, StreamRecordsPatchQuery } from '../streaming/records'; import { FlatfileRecord, Primitive, SimpleRecord, Collection } from '@flatfile/records'; type MappedRecord = { __id: string; [key: string]: any; }; type RecordWithLinks = Flatfile.RecordWithLinks; export interface EnhancedStreamRecordsQuery extends StreamRecordsQuery { /** * When true, returns an AsyncGenerator for streaming records * When false or not specified, returns all records at once */ stream?: boolean; } export type EnhancedRecords = FlatfileClient['records'] & { insert(sheetId: string, records: SimpleRecord[]): Promise<{ commitId?: string; success: boolean; }>; counts(sheetId: string, opts?: Flatfile.GetRecordCountsRequest): Promise<Flatfile.RecordCounts>; all: { /** * Get all records in their raw form with links */ simple(sheetId: string, options?: Flatfile.GetRecordsRequest): Promise<RecordWithLinks[]>; /** * Get all records mapped to plain objects */ object(sheetId: string, options?: Flatfile.GetRecordsRequest): Promise<MappedRecord[]>; }; stream: { /** * Get records with full metadata and configuration * @param opts - Stream options including workbook/sheet ID and include flags * @returns When stream: true, returns AsyncGenerator for streaming records * When stream: false (default), returns all records at once */ get: { (opts: EnhancedStreamRecordsQuery & { stream: true; }): AsyncGenerator<Collection<FlatfileRecord<any>>>; (opts?: EnhancedStreamRecordsQuery): Promise<Collection<FlatfileRecord<any>>>; }; /** * Get records in a simplified format without internal metadata * @param opts - Stream options including workbook/sheet ID * @returns When stream: true, returns AsyncGenerator for streaming records * When stream: false (default), returns all records at once */ simple: { (opts: EnhancedStreamRecordsQuery & { stream: true; }): AsyncGenerator<SimpleRecord>; (opts?: EnhancedStreamRecordsQuery): Promise<SimpleRecord[]>; }; /** * Update records using JSONL format with Collection support * @param opts - Update options including workbook/sheet ID and update flags * @param records - Collection of records to update * @returns Promise indicating success */ update: (opts: StreamRecordsPatchQuery, records: Collection<FlatfileRecord<any>>) => Promise<{ success: true; }>; /** * Raw upsert of records using JSONL format * @param opts - Update options including workbook/sheet ID * @param records - Array of records to upsert * @returns Promise indicating success */ raw: (opts: StreamRecordsPatchQuery, records: Array<Record<string, Primitive>>) => Promise<{ success: true; }>; }; }; export declare function getRecordsExtension(client: FlatfileClient): EnhancedRecords; export {};