longcelot-sheet-db
Version:
Google Sheets-backed staging database adapter for Node.js with schema-first design
80 lines • 4.57 kB
TypeScript
import { TableSchema, FindOptions, UpdateOptions, DeleteOptions, CreateOptions, UpsertOptions, UserContext, ActorPermission, FKResolver } from '../../schema/types';
import type { DatabaseAdapter, TableOperations } from '../types';
export interface PrismaAdapterConfig {
/**
* An already-constructed, already-`prisma generate`'d PrismaClient instance from the consumer's
* own project. Typed `unknown` deliberately — this package doesn't know the consumer's
* generated client shape, and doesn't perform schema.prisma generation or `prisma generate`
* itself (see TODO.md Phase 16.2 decision — avoids in-process codegen fragility). Run
* `lsdb migrate --prisma` to get schema.prisma, then `prisma generate` as a normal build step.
*/
client: unknown;
/** Column injected into every non-admin table to scope rows to a tenant. Default: 'tenant_id'. */
tenantColumn?: string;
permissions?: Record<string, ActorPermission>;
}
/**
* TableOperations backed by a consumer-provided PrismaClient. Same validation/defaults/FK/
* soft-delete/uniqueness/timestamps semantics as CRUDOperations and SQLTableOperations — see
* TODO.md Phase 16.2. Deliberately its own copy of the validation logic rather than a shared
* module yet, matching SQLTableOperations' documented first-pass tradeoff.
*/
declare class PrismaTableOperations implements TableOperations {
private client;
private schema;
private tenantColumn;
private tenantValue;
private fkResolver?;
private fieldMap;
constructor(client: unknown, schema: TableSchema, tenantColumn: string, tenantValue: string | undefined, fkResolver?: FKResolver | undefined);
private get delegate();
/**
* Drops any key that isn't a declared column on this schema before it reaches
* toFieldKeys()/the Prisma delegate — a stray key (e.g. a legacy/leftover Sheets column
* migrate-data read verbatim off a real spreadsheet row) would otherwise hit Prisma's
* "Unknown argument" error, the Prisma-side equivalent of the raw SQL adapters' native "column
* ... does not exist" (found via a real F2 cutover run — see FAQ.md §13, and the matching fix
* in SQLTableOperations.serializeRow()). Every column this table actually has, including the
* system ones, is a real entry in this.schema.columns. Only ever applied to a data payload
* (create/createMany/update), never to a where clause — the tenant/soft-delete keys buildWhere()
* adds aren't schema columns and must pass through untouched there.
*/
private filterKnownColumns;
/** Raw column names (e.g. `_id`) -> Prisma Client field names (e.g. `id`) — see toPrismaFieldName(). */
private toFieldKeys;
/** Prisma Client field names -> raw column names — the inverse of toFieldKeys(). */
private toRawKeys;
create(data: Record<string, unknown>, options?: CreateOptions): Promise<Record<string, unknown>>;
createMany(records: 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>>;
count(options?: Pick<FindOptions, 'where' | 'includeDeleted'>): Promise<number>;
delete(options: DeleteOptions): Promise<number>;
private buildWhere;
private stripTenantColumn;
private validateAndApplyDefaults;
private validateForeignKeys;
private checkUniqueness;
}
export declare class PrismaAdapterBase implements DatabaseAdapter {
private client;
private tenantColumn;
private permissions?;
private schemas;
private context?;
constructor(client: unknown, tenantColumn: string, permissions?: Record<string, ActorPermission> | undefined);
registerSchema(schema: TableSchema): void;
registerSchemas(schemas: TableSchema[]): void;
withContext(context: UserContext): PrismaAdapterBase;
asActor(targetActor: string, targetSheetId: string): PrismaAdapterBase;
table(tableName: string): PrismaTableOperations;
}
/**
* Wraps a consumer-provided PrismaClient to implement DatabaseAdapter — see PrismaAdapterConfig
* for why this package doesn't generate/`prisma generate` a client itself (Phase 16.2).
*/
export declare function createPrismaAdapter(config: PrismaAdapterConfig): PrismaAdapterBase;
export {};
//# sourceMappingURL=prismaAdapter.d.ts.map