longcelot-sheet-db
Version:
Google Sheets-backed staging database adapter for Node.js with schema-first design
53 lines • 3.01 kB
TypeScript
import type { StorageClient, TableOperations } from './types';
import { TableSchema, BooleanFormat, FindOptions, UpdateOptions, DeleteOptions, CreateOptions, UpsertOptions, FKResolver } from '../schema/types';
export declare class CRUDOperations implements TableOperations {
private client;
private spreadsheetId;
private schema;
private fkResolver?;
private preFlight?;
private defaultBooleanFormat;
constructor(client: StorageClient, spreadsheetId: string, schema: TableSchema, fkResolver?: FKResolver | undefined, preFlight?: Promise<void> | undefined, defaultBooleanFormat?: BooleanFormat);
create(data: Record<string, unknown>, options?: CreateOptions): Promise<Record<string, unknown>>;
findMany(options?: FindOptions): Promise<Record<string, unknown>[]>;
findOne(options?: FindOptions): Promise<Record<string, unknown> | null>;
update(options: UpdateOptions): Promise<number>;
upsert(options: UpsertOptions): Promise<Record<string, unknown>>;
createMany(records: Record<string, unknown>[], options?: CreateOptions): Promise<Record<string, unknown>[]>;
count(options?: Pick<FindOptions, 'where' | 'includeDeleted'>): Promise<number>;
delete(options: DeleteOptions): Promise<number>;
/**
* Reads all rows and filters out phantom rows — sheet cells that have
* formatting/validation applied (e.g. a checkbox dropdown past the real data,
* see FAQ.md #10) but were never actually written by create()/createMany().
* A real row always has a non-empty `_id`; anything else is grid noise, not a record.
*/
private getDataRows;
/**
* The validated range applied by sync/formatSheet() only covers data rows that existed
* at sync time plus a fixed buffer (see FAQ.md #10) — it doesn't grow on its own as rows
* are appended via create() between syncs. Every VALIDATION_CHECK_INTERVAL rows, re-extend
* the range by one more buffer's worth so checkbox/dropdown UI keeps pace with real growth
* without re-checking (let alone re-extending) on every single insert.
*/
private maybeExtendValidation;
private getHeaders;
private validateAndApplyDefaults;
private validateForeignKeys;
private serializeValue;
private deserializeRow;
/**
* Normalizes a date() cell back to a clean ISO string. Also defends against rows
* written before the serializeValue() fix above (or by any other writer that passed
* a raw Date object through the generic JSON.stringify() path) — those cells carry a
* literal quote pair around the ISO string, which `new Date(value)` on the consuming
* end fails to parse. Falls back to the unwrapped raw value, unchanged, if it still
* doesn't parse as a valid date rather than discarding whatever was actually stored.
*/
private cleanDateValue;
private checkUniqueness;
private matchesWhere;
private compareOrderValues;
private toOrderNumber;
}
//# sourceMappingURL=crud.d.ts.map