import { TableBuilder } from './table-builder'; import { FieldRef } from '../query/conditions'; /** * Navigation configuration */ export interface NavigationConfig = TableBuilder, TTargetTable extends TableBuilder = TableBuilder> { /** * Array of foreign key fields from the source table * Example: [users.id] when defining a collection on users table */ foreignKeys: FieldRef[]; /** * Array of matching fields from the target table * Example: [posts.userId] when defining posts collection */ matches: FieldRef[]; /** * Determines if the join is mandatory (INNER JOIN) or optional (LEFT JOIN) * Default: false (LEFT JOIN) */ isMandatory?: boolean; } /** * Navigation property marker - represents a collection navigation property (one-to-many) * Represents a collection of related entities in a navigation property */ export declare class DbNavigationCollection = TableBuilder> { /** @internal */ readonly targetTableBuilder: TTarget; /** @internal */ readonly config: NavigationConfig; /** @internal */ readonly __targetTable: TTarget; /** @internal */ readonly __navigationType: "collection"; constructor( /** @internal */ targetTableBuilder: TTarget, /** @internal */ config: NavigationConfig); /** * Get the target table name */ get targetTable(): string; /** * Get foreign key column names (literals prefixed with __LIT:) */ get foreignKeyColumns(): string[]; /** * Get matching column names (literals prefixed with __LIT:) */ get matchColumns(): string[]; /** * Whether this navigation requires a mandatory join */ get isMandatory(): boolean; } /** * Navigation property marker for single reference (one-to-one or many-to-one) */ export declare class DbNavigation = TableBuilder> { /** @internal */ readonly builder: () => { targetTable: TTarget; config: NavigationConfig; }; /** @internal */ readonly __targetTable: TTarget; /** @internal */ readonly __navigationType: "navigation"; /** @internal */ targetTableBuilder: TTarget; /** @internal */ config: NavigationConfig; constructor( /** @internal */ builder: () => { targetTable: TTarget; config: NavigationConfig; }); private ensureNavigation; /** * Get the target table name */ getTargetTable(): string; /** * Get foreign key column names (literals prefixed with __LIT:) */ getForeignKeyColumns(): string[]; /** * Get matching column names (literals prefixed with __LIT:) */ getMatchColumns(): string[]; /** * Whether this navigation requires a mandatory join */ getIsMandatory(): boolean; } /** * Helper to create a collection navigation property (one-to-many) * * @example * ```typescript * const users = table('users', { * id: serial('id').primaryKey(), * posts: navigationCollection(posts, { * foreignKeys: [users.id], * matches: [posts.userId], * isMandatory: false * }) * }); * ``` */ export declare function navigationCollection>(targetTable: TTarget, config: NavigationConfig): DbNavigationCollection; /** * Helper to create a single navigation property (one-to-one or many-to-one) * * @example * ```typescript * const orders = table('orders', { * id: serial('id').primaryKey(), * userId: integer('user_id').notNull(), * user: navigation(users, { * foreignKeys: [orders.userId], * matches: [users.id], * isMandatory: true * }) * }); * ``` */ export declare function navigation>(builder: () => { targetTable: TTarget; config: NavigationConfig; }): DbNavigation; /** * @deprecated Use navigationCollection instead */ export declare class DbCollection = TableBuilder> { /** @internal */ readonly targetTable: string; /** @internal */ readonly foreignKey: string; /** @internal */ readonly __targetTable: TTarget; /** @internal */ readonly __navigationType: "collection"; constructor( /** @internal */ targetTable: string, /** @internal */ foreignKey: string); } /** * @deprecated Use navigation instead */ export declare class DbReference = TableBuilder> { /** @internal */ readonly targetTable: string; /** @internal */ readonly foreignKey: string; /** @internal */ readonly references: string; /** @internal */ readonly __targetTable: TTarget; /** @internal */ readonly __navigationType: "reference"; constructor( /** @internal */ targetTable: string, /** @internal */ foreignKey: string, /** @internal */ references?: string); } /** * @deprecated Use navigationCollection instead */ export declare function collection = TableBuilder>(targetTable: string, foreignKey: string): DbCollection; /** * @deprecated Use navigation instead */ export declare function reference = TableBuilder>(targetTable: string, foreignKey: string, references?: string): DbReference; /** * Type guard to check if a property is a navigation property */ export declare function isNavigationProperty(value: any): value is DbNavigationCollection | DbNavigation | DbCollection | DbReference; /** * Type guard for collection navigation (both old and new) */ export declare function isCollection(value: any): value is DbNavigationCollection | DbCollection; /** * Type guard for reference navigation (both old and new) */ export declare function isReference(value: any): value is DbNavigation | DbReference; /** * Type guard for new navigation collection */ export declare function isNavigationCollection(value: any): value is DbNavigationCollection; /** * Type guard for new single navigation */ export declare function isNavigation(value: any): value is DbNavigation; /** * Extract navigation properties from a schema definition */ export type NavigationProperties = { [K in keyof T]: T[K] extends DbNavigationCollection | DbNavigation | DbCollection | DbReference ? K : never; }[keyof T]; /** * Extract regular column properties from a schema definition */ export type ColumnProperties = { [K in keyof T]: T[K] extends DbNavigationCollection | DbNavigation | DbCollection | DbReference ? never : K; }[keyof T]; //# sourceMappingURL=navigation.d.ts.map