userdo
Version:
A Durable Object base class for building applications on Cloudflare Workers.
39 lines (38 loc) • 1.34 kB
TypeScript
import { z } from 'zod';
import { GenericQuery } from './query.js';
export type Table<T = any> = GenericTable<T>;
export declare class GenericTable<T = any> {
private tableName;
private schema;
private storage;
private userId;
private getOrganizationContext;
private broadcast?;
constructor(tableName: string, schema: z.ZodSchema<T>, storage: DurableObjectStorage, userId: string, getOrganizationContext: () => string | undefined, broadcast?: ((event: string, data: any) => void) | undefined);
private get organizationContext();
create(data: T): Promise<T & {
id: string;
createdAt: Date;
updatedAt: Date;
}>;
findById(id: string): Promise<(T & {
id: string;
createdAt: Date;
updatedAt: Date;
}) | null>;
update(id: string, updates: Partial<T>): Promise<T & {
id: string;
createdAt: Date;
updatedAt: Date;
}>;
delete(id: string): Promise<void>;
where(path: string, operator: '==' | '!=' | '>' | '<' | 'includes', value: any): GenericQuery<T>;
orderBy(field: string, direction?: 'asc' | 'desc'): GenericQuery<T>;
limit(count: number): GenericQuery<T>;
getAll(): Promise<Array<T & {
id: string;
createdAt: Date;
updatedAt: Date;
}>>;
count(): Promise<number>;
}