@api-buddy/types
Version:
Shared types for API Buddy
207 lines (199 loc) • 6.69 kB
text/typescript
// @ts-nocheck
import { z } from 'zod';
export { z } from 'zod';
type FieldType = 'String' | 'Number' | 'Boolean' | 'Date' | 'JSON' | 'ID' | 'Relation';
declare const fieldTypeSchema: z.ZodEnum<["String", "Number", "Boolean", "Date", "JSON", "ID", "Relation"]>;
interface BaseFieldDefinition {
type: FieldType;
required?: boolean;
unique?: boolean;
default?: any;
isArray?: boolean;
validators?: Array<(value: any) => string | null>;
description?: string;
}
interface StringFieldDefinition extends BaseFieldDefinition {
type: 'String';
enum?: string[];
minLength?: number;
maxLength?: number;
pattern?: string;
format?: 'email' | 'uri' | 'uuid' | 'date-time' | 'date' | 'time' | string;
}
interface NumberFieldDefinition extends BaseFieldDefinition {
type: 'Number';
minimum?: number;
maximum?: number;
exclusiveMinimum?: boolean;
exclusiveMaximum?: boolean;
multipleOf?: number;
}
interface BooleanFieldDefinition extends BaseFieldDefinition {
type: 'Boolean';
}
interface DateFieldDefinition extends BaseFieldDefinition {
type: 'Date';
}
interface JsonFieldDefinition extends BaseFieldDefinition {
type: 'JSON';
}
interface IDFieldDefinition extends BaseFieldDefinition {
type: 'ID';
autoIncrement?: boolean;
autoGenerate?: boolean;
}
interface RelationFieldDefinition extends BaseFieldDefinition {
type: 'Relation';
relation: {
model: string;
type: 'hasOne' | 'hasMany' | 'belongsTo' | 'manyToMany';
foreignKey?: string;
through?: string;
};
}
type FieldDefinition = StringFieldDefinition | NumberFieldDefinition | BooleanFieldDefinition | DateFieldDefinition | JsonFieldDefinition | IDFieldDefinition | RelationFieldDefinition;
interface ModelDefinition {
fields: Record<string, FieldDefinition>;
timestamps?: boolean;
softDelete?: boolean;
tableName?: string;
indexes?: Array<{
fields: string | string[];
unique?: boolean;
name?: string;
}>;
}
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')[];
};
};
}
/**
* API Buddy Shared Types
*
* This is the main entry point for all shared types used across the API Buddy ecosystem.
* All types are re-exported from their respective modules to avoid circular dependencies.
*/
/**
* Base logger interface used throughout the application
*/
interface Logger$1 {
info: (message: string, ...args: any[]) => void;
warn: (message: string, ...args: any[]) => void;
error: (message: string, ...args: any[]) => void;
debug: (message: string, ...args: any[]) => void;
}
declare enum PluginHook {
BeforeSchemaLoad = "beforeSchemaLoad",
AfterSchemaLoad = "afterSchemaLoad",
BeforeCodegen = "beforeCodegen",
AfterCodegen = "afterCodegen",
BeforeTypegen = "beforeTypegen",
AfterTypegen = "afterTypegen",
BeforeMigrate = "beforeMigrate",
AfterMigrate = "afterMigrate"
}
interface PluginContext {
/** Current working directory */
cwd: string;
/** Plugin configuration */
config: Record<string, unknown>;
/** Logger instance */
logger: Logger$1;
/** Plugin data storage */
data: Map<string, unknown>;
/** Plugin utilities */
utils: {
/** Register a hook */
registerHook: (hookName: string, handler: (...args: any[]) => any) => void;
/** Unregister a hook */
unregisterHook: (hookName: string, handler: (...args: any[]) => any) => void;
/** Call a hook */
callHook: (hookName: string, ...args: any[]) => Promise<any>;
};
}
interface Plugin {
/** Plugin name (must be unique) */
name: string;
/** Plugin version */
version: string;
/** Plugin description */
description?: string;
/**
* Initialize the plugin
* Called when the plugin is loaded
* @param context - The plugin context containing logger, config, etc.
*/
initialize?(context: PluginContext): Promise<void> | void;
/**
* Cleanup function
* Called when the plugin is unloaded
*/
destroy?(): Promise<void> | void;
/**
* Optional cleanup function (alias for destroy)
* Called when the plugin is unregistered
*/
cleanup?(context: PluginContext): Promise<void> | void;
/**
* Plugin hooks
* Keys are hook names, values are arrays of handler functions
*/
hooks?: {
[K in PluginHook]?: Array<(context: PluginContext, ...args: any[]) => Promise<void> | void>;
};
/**
* Plugin configuration schema (JSON Schema)
* Used to validate plugin configuration
*/
configSchema?: Record<string, unknown>;
}
/**
* Base interface for plugin manager options
*/
interface PluginManagerOptions {
/** Current working directory */
cwd?: string;
/** Logger instance */
logger?: Partial<Logger$1>;
/** Enable debug mode */
debug?: boolean;
/** Plugin configurations */
plugins?: Record<string, unknown>;
/** Directories to search for plugins */
pluginsDir?: string | string[];
/** Node modules directories to search for plugins */
nodeModulesDirs?: string[];
/** Configuration object */
config?: Record<string, unknown>;
/** Callback when a plugin is loaded */
onPluginLoaded?: (plugin: Plugin) => void;
/** Error handler */
onError?: (error: Error, plugin?: string, phase?: string) => void;
}
/**
* API Buddy Shared Types
*
* This is the main entry point for all shared types used across the API Buddy ecosystem.
* All types are re-exported from their respective modules to avoid circular dependencies.
*/
/**
* Base logger interface used throughout the application
*/
interface Logger {
info: (message: string, ...args: any[]) => void;
warn: (message: string, ...args: any[]) => void;
error: (message: string, ...args: any[]) => void;
debug: (message: string, ...args: any[]) => void;
}
export { type BaseFieldDefinition, type BooleanFieldDefinition, type DateFieldDefinition, type FieldDefinition, type FieldType, type IDFieldDefinition, type JsonFieldDefinition, type Logger, type ModelDefinition, type NumberFieldDefinition, type Plugin, type PluginContext, PluginHook, type PluginManagerOptions, type RelationFieldDefinition, type Schema, type StringFieldDefinition, fieldTypeSchema };