@api-buddy/types
Version:
Shared types for API Buddy
79 lines • 2.53 kB
TypeScript
import { z } from 'zod';
export type FieldType = 'String' | 'Number' | 'Boolean' | 'Date' | 'JSON' | 'ID' | 'Relation';
export declare const fieldTypeSchema: z.ZodEnum<["String", "Number", "Boolean", "Date", "JSON", "ID", "Relation"]>;
export interface BaseFieldDefinition {
type: FieldType;
required?: boolean;
unique?: boolean;
default?: any;
isArray?: boolean;
validators?: Array<(value: any) => string | null>;
description?: string;
}
export interface StringFieldDefinition extends BaseFieldDefinition {
type: 'String';
enum?: string[];
minLength?: number;
maxLength?: number;
pattern?: string;
format?: 'email' | 'uri' | 'uuid' | 'date-time' | 'date' | 'time' | string;
}
export interface NumberFieldDefinition extends BaseFieldDefinition {
type: 'Number';
minimum?: number;
maximum?: number;
exclusiveMinimum?: boolean;
exclusiveMaximum?: boolean;
multipleOf?: number;
}
export interface BooleanFieldDefinition extends BaseFieldDefinition {
type: 'Boolean';
}
export interface DateFieldDefinition extends BaseFieldDefinition {
type: 'Date';
}
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: {
model: string;
type: 'hasOne' | 'hasMany' | 'belongsTo' | 'manyToMany';
foreignKey?: string;
through?: string;
};
}
export type FieldDefinition = StringFieldDefinition | NumberFieldDefinition | BooleanFieldDefinition | DateFieldDefinition | JsonFieldDefinition | IDFieldDefinition | RelationFieldDefinition;
export interface ModelDefinition {
fields: Record<string, FieldDefinition>;
timestamps?: boolean;
softDelete?: boolean;
tableName?: string;
indexes?: Array<{
fields: string | string[];
unique?: boolean;
name?: string;
}>;
}
export interface Schema {
models: Record<string, ModelDefinition>;
enums?: Record<string, string[]>;
config?: {
database?: {
provider?: 'postgresql' | 'mysql' | 'sqlite' | 'mongodb';
url?: string;
ssl?: boolean;
};
auth?: {
enabled?: boolean;
providers?: ('credentials' | 'github' | 'google')[];
};
};
}
//# sourceMappingURL=types.d.ts.map