UNPKG

@flavoai/fastfold

Version:

Zero-boilerplate backend for React apps with auto-generated CRUD and declarative security

183 lines 5.48 kB
export type CrudOperation = 'create' | 'read' | 'update' | 'delete'; export interface SecurityRule { type: 'public' | 'admin' | 'owner' | 'custom' | 'authenticated'; ownerField?: string; customRule?: (context: SecurityContext) => boolean | Promise<boolean>; } export interface SecurityContext { user?: { id: string; role: string; [key: string]: any; }; operation: CrudOperation; data?: any; existingData?: any; tableName: string; } export interface TableConfig { security: SecurityRule; operations?: CrudOperation[]; } export interface DrizzleConfig { db: any; schema: Record<string, any>; } export interface AuthConfig { providers?: ('email' | 'google' | 'github')[]; userTable?: string; endpoints?: { register?: string; login?: string; logout?: string; me?: string; }; secret?: string; expiresIn?: string; } export interface UploadsConfig { provider: 'local' | 's3' | 'cloudinary'; path?: string; maxSize?: string; allowedTypes?: string[]; } export interface RateLimitConfig { windowMs: number; max: number; } export interface StaticMount { directory: string; urlPath?: string; spaFallback?: boolean; excludePaths?: Array<string | RegExp>; indexFile?: string; staticOptions?: { index?: string | false; maxAge?: number | string; etag?: boolean; immutable?: boolean; cacheControl?: boolean; setHeaders?: (res: any, path: string, stat: any) => void; }; } export type StaticFrontendConfig = StaticMount | StaticMount[]; export interface HooksConfig { onServerStart?: (server: any) => Promise<void> | void; onRequest?: (req: any, res: any, next: any) => void; beforeCreate?: Record<string, (data: any, context: SecurityContext) => Promise<any> | any>; afterCreate?: Record<string, (record: any, context: SecurityContext) => Promise<void> | void>; beforeUpdate?: Record<string, (data: any, existing: any, context: SecurityContext) => Promise<any> | any>; afterUpdate?: Record<string, (record: any, context: SecurityContext) => Promise<void> | void>; } export interface DrizzleQuickStartConfig { drizzle: DrizzleConfig; tables: { [tableName: string]: TableConfig; }; auth?: AuthConfig; uploads?: UploadsConfig; rateLimit?: RateLimitConfig; endpoints?: (app: any) => void; hooks?: HooksConfig; staticFrontend?: StaticFrontendConfig; } export interface LegacyTableDefinition { schema: { [fieldName: string]: 'string' | 'number' | 'boolean' | 'date' | 'json'; }; security: SecurityRule; } export interface LegacyQuickStartConfig { tables: { [tableName: string]: LegacyTableDefinition; }; endpoints?: (app: any) => void; hooks?: { onServerStart?: (server: any) => Promise<void> | void; onRequest?: (req: any, res: any, next: any) => void; }; } export interface QueryParams { where?: Record<string, any>; orderBy?: Record<string, 'asc' | 'desc'>; limit?: number; offset?: number; select?: string[]; with?: Record<string, any>; } export interface CreateData<T = any> { data: T; } export interface UpdateData<T = any> { id: string | number; data: Partial<T>; } export interface DeleteData { id: string | number; } export interface ApiResponse<T = any> { success: boolean; data?: T; error?: string; count?: number; } export interface UseQueryOptions { enabled?: boolean; refetchOnWindowFocus?: boolean; refetchInterval?: number; } export interface UseMutationOptions<TData = any, TVariables = any> { onSuccess?: (data: TData) => void; onError?: (error: Error) => void; } export interface QueryState<T = any> { data: T | undefined; isLoading: boolean; error: Error | null; refetch: () => Promise<void>; } export interface MutationState<TData = any, TVariables = any> { mutate: (variables: TVariables) => Promise<TData>; isLoading: boolean; error: Error | null; reset: () => void; } export type DatabaseProvider = 'sqlite' | 'postgresql' | 'mysql'; export type FieldType = 'string' | 'number' | 'boolean' | 'date' | 'json' | 'text'; export interface TableSchema { [fieldName: string]: FieldType; } export interface TableDefinition { schema: TableSchema; security: SecurityRule; } export interface FastfoldConfig { tables: { [tableName: string]: TableDefinition; }; endpoints?: (app: any) => void; hooks?: { onServerStart?: (server: any) => Promise<void> | void; onRequest?: (req: any, res: any, next: any) => void; }; } export interface DatabaseAdapter { connect(): Promise<void>; disconnect(): Promise<void>; createTable(tableName: string, schema: TableSchema): Promise<void>; query<T = any>(tableName: string, params: QueryParams): Promise<T[]>; create<T = any>(tableName: string, data: any): Promise<T>; update<T = any>(tableName: string, id: string | number, data: any): Promise<T>; delete(tableName: string, id: string | number): Promise<boolean>; count(tableName: string, where?: Record<string, any>): Promise<number>; } export interface AuthUser { id: string; role: string; [key: string]: any; } export interface RequestContext extends SecurityContext { req: any; res: any; } //# sourceMappingURL=index.d.ts.map