import { type Ref, type Refable, type RefByPrimary, type RefByUnique } from 'domain-objects'; import type { DeclastructDao } from './DeclastructDao'; /** * .what = input type for genDeclastructDao without get.ref and get.one.byRef (auto-wired by factory) * .why = derives from DeclastructDao to stay in sync, omits auto-wired methods * .note = uses `| null` syntax to force explicit decision on nullable methods */ export type DeclastructDaoInput, TContext> = Omit, 'get' | 'set'> & { get: { one: Omit['get']['one'], 'byRef' | 'byPrimary'> & { byPrimary: ((input: RefByPrimary, context: TContext) => Promise | null>) | null; }; }; set: Omit['set'], 'upsert' | 'delete'> & { upsert: ((input: InstanceType, context: TContext) => Promise>) | null; delete: ((input: Ref, context: TContext) => Promise) | null; }; }; /** * .what = input type for daos with byPrimary defined * .why = enables overload to distinguish daos with primary key support */ export type DeclastructDaoInputWithPrimary, TContext> = Omit, 'get'> & { get: { one: Omit['get']['one'], 'byPrimary' | 'byRef'> & { byPrimary: NonNullable['get']['one']['byPrimary']>; }; }; }; /** * .what = input type for daos without byPrimary * .why = enables overload to distinguish daos without primary key support */ export type DeclastructDaoInputWoutPrimary, TContext> = Omit, 'get'> & { get: { one: Omit['get']['one'], 'byPrimary' | 'byRef'> & { byPrimary: null; }; }; }; /** * .what = output type for daos with ref methods defined * .why = enables type-safe access to ref resolution methods * .note = uses method syntax for bivariance (enables assignment to DeclastructDao) */ export type DeclastructDaoWithRef, TContext> = Omit, 'get'> & { get: { one: DeclastructDao['get']['one']; ref: { byPrimary(input: Ref, context: TContext): Promise | null>; byUnique(input: Ref, context: TContext): Promise | null>; }; }; }; /** * .what = output type for daos without ref methods * .why = ref methods are undefined when byPrimary is not supported */ export type DeclastructDaoWoutRef, TContext> = Omit, 'get'> & { get: { one: DeclastructDao['get']['one']; ref: { byPrimary: undefined; byUnique: undefined; }; }; }; /** * .what = factory to create DeclastructDao with auto-wired ref methods * .why = enforces that ref methods are defined iff byPrimary is defined * .note = TContext must be explicitly provided as a generic parameter to avoid hazardous Record inference * * @overload input with byPrimary defined → output with ref methods defined */ export declare function genDeclastructDao, TContext extends Record = never>(input: DeclastructDaoInputWithPrimary): DeclastructDaoWithRef; /** * @overload input without byPrimary → output with ref methods null */ export declare function genDeclastructDao, TContext extends Record = never>(input: DeclastructDaoInputWoutPrimary): DeclastructDaoWoutRef;