/** * Schema loader using esbuild * Bundles and executes TypeScript schema files at runtime */ import { type ProjectDefinition, type DatasourcesDefinition, type PipesDefinition, type ConnectionsDefinition } from "../schema/project.js"; import { type DatasourceDefinition } from "../schema/datasource.js"; import { type PipeDefinition } from "../schema/pipe.js"; import { type ConnectionDefinition } from "../schema/connection.js"; /** * Result of loading a schema file */ export interface LoadedSchema { /** The loaded project definition */ project: ProjectDefinition; /** The resolved path to the schema file */ schemaPath: string; /** The directory containing the schema */ schemaDir: string; } /** * Options for the schema loader */ export interface LoaderOptions { /** The path to the schema file (can be relative or absolute) */ schemaPath: string; /** The working directory for resolution (defaults to cwd) */ cwd?: string; } /** * Load and execute a TypeScript schema file * * Uses esbuild to bundle the schema and its dependencies, * then dynamically imports the bundle to get the ProjectDefinition. * * @param options - Loader options * @returns The loaded project definition * * @example * ```ts * const { project } = await loadSchema({ * schemaPath: 'src/tinybird/schema.ts', * }); * * console.log(project.datasources); * console.log(project.pipes); * ``` */ export declare function loadSchema(options: LoaderOptions): Promise; /** * Information about an entity discovered from a source file */ export interface EntityInfo { /** The export name used in the source file */ exportName: string; /** The source file path (relative to cwd) */ sourceFile: string; } /** * Raw datafile loaded directly from disk */ export interface RawDatafile { /** The file name (without extension) */ name: string; /** The raw content of the file */ content: string; /** The source file path (relative to cwd) */ sourceFile: string; } /** * Result of loading entities from multiple files */ export interface LoadedEntities { /** Discovered datasources with their metadata */ datasources: Record; /** Discovered pipes with their metadata */ pipes: Record; /** Discovered connections with their metadata */ connections: Record; /** Raw .datasource files loaded directly */ rawDatasources: RawDatafile[]; /** Raw .pipe files loaded directly */ rawPipes: RawDatafile[]; /** All source files that were scanned */ sourceFiles: string[]; } /** * Options for loading entities */ export interface LoadEntitiesOptions { /** Array of file paths or glob patterns to scan (can be relative or absolute) */ includePaths: string[]; /** The working directory for resolution (defaults to cwd) */ cwd?: string; } /** * Load datasources and pipes from multiple TypeScript files * * Uses esbuild to bundle each file and scans exports for datasource * and pipe definitions. * * @param options - Loader options * @returns Discovered entities with metadata * * @example * ```ts * const entities = await loadEntities({ * includePaths: ['src/datasources.ts', 'src/pipes.ts'], * }); * * console.log(Object.keys(entities.datasources)); // ['pageViews', 'events'] * console.log(Object.keys(entities.pipes)); // ['topPages', 'topEvents'] * ``` */ export declare function loadEntities(options: LoadEntitiesOptions): Promise; /** * Convert loaded entities to a format compatible with generators */ export declare function entitiesToProject(entities: LoadedEntities): { datasources: DatasourcesDefinition; pipes: PipesDefinition; connections: ConnectionsDefinition; }; /** * Watch options for the schema loader */ export interface WatchOptions extends LoaderOptions { /** Callback when the schema changes */ onChange: (result: LoadedSchema) => void | Promise; /** Callback when there's an error loading the schema */ onError?: (error: Error) => void; /** Debounce delay in milliseconds (default: 100) */ debounce?: number; } /** * Schema watcher controller */ export interface SchemaWatcher { /** Stop watching for changes */ close: () => Promise; /** The initial loaded schema */ initialSchema: LoadedSchema; } /** * Watch a TypeScript schema file for changes * * Performs an initial load, then watches for file changes and reloads. * Uses debouncing to coalesce rapid file system events. * * @param options - Watch options * @returns A controller to stop watching * * @example * ```ts * const watcher = await watchSchema({ * schemaPath: 'src/tinybird/schema.ts', * onChange: (schema) => { * console.log('Schema updated:', schema.project); * }, * onError: (err) => { * console.error('Load error:', err.message); * }, * }); * * // Later, stop watching * await watcher.close(); * ``` */ export declare function watchSchema(options: WatchOptions): Promise; //# sourceMappingURL=loader.d.ts.map