UNPKG

@api-buddy/types

Version:

Shared types for API Buddy

166 lines 5.17 kB
export type ID = string | number; /** * Database Type Definitions * * This file contains type definitions for database operations and schemas. */ export type FieldType = 'String' | 'Int' | 'Float' | 'Boolean' | 'DateTime' | 'JSON' | 'ID' | 'Relation'; export type SortOrder = 'asc' | 'desc'; export type WhereInput = { [key: string]: any; AND?: WhereInput | WhereInput[]; OR?: WhereInput | WhereInput[]; NOT?: WhereInput | WhereInput[]; }; export type IncludeInput = { [key: string]: boolean | IncludeInput; }; export interface BaseFieldDefinition { type: FieldType; required?: boolean; unique?: boolean; default?: any; description?: string; } export interface StringFieldDefinition extends BaseFieldDefinition { type: 'String'; minLength?: number; maxLength?: number; pattern?: string; enum?: string[]; } export interface NumberFieldDefinition extends BaseFieldDefinition { type: 'Int' | 'Float'; min?: number; max?: number; } export interface BooleanFieldDefinition extends BaseFieldDefinition { type: 'Boolean'; } export interface DateTimeFieldDefinition extends BaseFieldDefinition { type: 'DateTime'; defaultNow?: boolean; } export interface JsonFieldDefinition extends BaseFieldDefinition { type: 'JSON'; } export interface IdFieldDefinition extends BaseFieldDefinition { type: 'ID'; autoIncrement?: boolean; autoGenerate?: boolean; } export interface RelationFieldDefinition extends BaseFieldDefinition { type: 'Relation'; relation: { type: 'hasOne' | 'hasMany' | 'belongsTo' | 'manyToMany'; model: string; foreignKey?: string; through?: string; }; } export type FieldDefinition = StringFieldDefinition | NumberFieldDefinition | BooleanFieldDefinition | DateTimeFieldDefinition | JsonFieldDefinition | IdFieldDefinition | RelationFieldDefinition; export interface RelationDefinition { type: 'hasOne' | 'hasMany' | 'belongsTo' | 'manyToMany'; model: string; foreignKey?: string; through?: string; } export interface ModelDefinition { name: string; fields: Record<string, FieldDefinition>; timestamps?: boolean; description?: string; tableName?: string; } export interface Schema { models: Record<string, ModelDefinition>; enums?: Record<string, string[]>; config?: { database?: { provider?: 'postgresql' | 'mysql' | 'sqlite' | 'mongodb'; url?: string; }; auth?: { enabled?: boolean; providers?: string[]; }; }; } export interface FindManyArgs { model: string; where?: WhereInput; include?: Record<string, boolean | IncludeInput>; select?: Record<string, boolean>; orderBy?: Record<string, SortOrder>; skip?: number; take?: number; cursor?: Record<string, any>; distinct?: string | string[]; } export interface FindUniqueArgs { model: string; where: Record<string, any>; include?: Record<string, boolean | IncludeInput>; select?: Record<string, boolean>; } export interface CreateArgs<T = any> { model: string; data: Partial<T>; include?: Record<string, boolean | IncludeInput>; select?: Record<string, boolean>; } export interface UpdateArgs<T = any> { model: string; where: Record<string, any>; data: Partial<T>; include?: Record<string, boolean | IncludeInput>; select?: Record<string, boolean>; } export interface DeleteArgs { model: string; where: Record<string, any>; } export interface ConnectArgs { model: string; id: any; relation: string; targetId: any; } export interface DisconnectArgs { model: string; id: any; relation: string; targetId?: any; } export interface Transaction { $transaction: <T>(fn: (tx: any) => Promise<T>) => Promise<T>; $executeRaw: (query: string, ...values: any[]) => Promise<number>; $queryRaw: <T = any>(query: string, ...values: any[]) => Promise<T>; } export interface QueryBuilder { findMany: <T = any>(args: FindManyArgs) => Promise<T[]>; findUnique: <T = any>(args: FindUniqueArgs) => Promise<T | null>; create: <T = any>(args: CreateArgs) => Promise<T>; update: <T = any>(args: UpdateArgs) => Promise<T>; delete: (args: DeleteArgs) => Promise<any>; count: (model: string, where?: WhereInput) => Promise<number>; aggregate: <T = any>(model: string, args: { where?: WhereInput; orderBy?: Record<string, SortOrder>; skip?: number; take?: number; }) => Promise<T>; } export interface DatabaseAdapter<T = any> { findMany(args: FindManyArgs): Promise<T[]>; findUnique(args: FindUniqueArgs): Promise<T | null>; create(args: CreateArgs): Promise<T>; update(args: UpdateArgs): Promise<T>; delete(args: DeleteArgs): Promise<T>; connectRelated(args: ConnectArgs): Promise<void>; disconnectRelated(args: DisconnectArgs): Promise<void>; transaction<T>(fn: (tx: Transaction) => Promise<T>): Promise<T>; syncSchema(schema: Schema): Promise<void>; query: QueryBuilder; } //# sourceMappingURL=database.types.d.ts.map