/** * DataBridge Type Definitions * Auto-generated helper types for custom queries and schemas * * This file is generated by DataBridge CLI and provides TypeScript * type inference for your databridge.queries.ts and databridge.schemas.ts files. * * You can safely modify this file or remove it if you prefer plain JavaScript. */ /** * Generic PrismaClient interface. * * This is a minimal interface representing the PrismaClient contract. * The actual PrismaClient type is generated in your project after running `prisma generate`. * Your code will have the fully-typed PrismaClient that satisfies this interface. * * We use this approach because: * 1. The CLI package has no schema.prisma, so can't run `prisma generate` * 2. @prisma/client is a stub package before generation * 3. This matches how Prisma extension libraries handle typing */ interface PrismaClient { [key: string]: any; $connect(): Promise; $disconnect(): Promise; $transaction(fn: (prisma: PrismaClient) => Promise): Promise; $queryRaw(query: TemplateStringsArray | string, ...values: any[]): Promise; $executeRaw(query: TemplateStringsArray | string, ...values: any[]): Promise; } // ============================================================================ // Custom Queries Types // ============================================================================ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'; export type ParamType = 'string' | 'number' | 'boolean'; export interface ParamDefinition { type: ParamType; required?: boolean; description?: string; default?: any; min?: number; max?: number; enum?: readonly string[]; format?: 'date' | 'date-time' | 'email' | 'uuid'; } export interface ArrayParamDefinition extends Omit { type: 'array'; items: Record; } export type AnyParamDefinition = ParamDefinition | ArrayParamDefinition; export interface QueryContext< TParams = Record, TQuery = Record, TBody = Record > { params: TParams; query: TQuery; body: TBody; user?: any; } export interface AuthConfig { required: boolean; roles?: string[]; } export interface QueryDefinition< TParams = Record, TQuery = Record, TBody = Record, TResponse = any > { method: HttpMethod; path: string; description?: string; tags?: string[]; params?: Record; query?: Record; body?: Record | ArrayParamDefinition; auth?: AuthConfig; handler: ( prisma: PrismaClient, context: QueryContext ) => Promise | TResponse; responseType?: string; statusCode?: number; } export type QueryDefinitions = Record; /** * Helper function to define queries with type inference. * This is a pass-through function that just returns your queries, * but helps TypeScript infer types for better IDE autocomplete. */ export function defineQueries(queries: T): T { return queries; } // ============================================================================ // Custom Schemas Types // ============================================================================ export type FieldType = 'string' | 'number' | 'boolean' | 'object' | 'array' | 'date'; export interface ComputedFieldDefinition { compute: (data: any) => any | Promise; type: FieldType; description?: string; } export interface RenamedFieldDefinition { from: string; type: FieldType; transform?: (value: any) => any; description?: string; } export interface RelationFieldDefinition { include: true; shape?: Record; select?: string[]; where?: Record; } export type FieldDefinition = | boolean | ComputedFieldDefinition | RenamedFieldDefinition | RelationFieldDefinition; export interface SchemaDefinition { from: string; description?: string; fields: Record; } export type SchemaDefinitions = Record; /** * Helper function to define schemas with type inference. * This is a pass-through function that just returns your schemas, * but helps TypeScript infer types for better IDE autocomplete. */ export function defineSchemas(schemas: T): T { return schemas; }