{"version":3,"file":"domain.mjs","names":["domainEffectFactory","helpers","domainHelpers","entries","command"],"sources":["../../../src/modules/effect/domain.ts"],"sourcesContent":["/* oxlint-disable anti-slop/no-object-parameters -- Internal helper storage is heterogeneous; the exported mapped signatures validate the schema-paired implementation. */\nimport type { Effect } from 'effect'\nimport type { AuditEntryInput } from '../../components/foundation/client'\nimport type { ContractInput, ContractOutput, ContractSchema } from '../contracts/contract'\nimport type { DomainOperationContract, ExactOperationKeys } from '../contracts/domain'\nimport { domainHelpers, type DeclaredSchemas } from '../contracts/binding'\nimport {\n\teffectOperationFactory,\n\ttype OperationDefinition,\n\ttype CheckedEffectDefinition,\n\ttype CheckedEffectOperation,\n\ttype CallbackError,\n\ttype CallbackRequirements,\n\ttype EffectPreparation,\n} from './operation'\n\ntype Supported<A> = A | PromiseLike<A> | Effect.Effect<A, unknown, unknown>\ntype Audit = Omit<AuditEntryInput, 'classification'> | null\ndeclare const domainKey: unique symbol\ntype BoundKey<Key> = { readonly [domainKey]: Key }\ntype Schemas<Entry extends DomainOperationContract> = Pick<Entry, 'input' | 'result'> &\n\tOmit<Entry, 'input' | 'result'>\ntype Forbidden = {\n\tinput?: never\n\tresult?: never\n\tclassification?: never\n\treplayResult?: never\n\twire?: never\n}\ntype AuditCallback<Context, Entry extends DomainOperationContract, Value> = (\n\tresolution: { command: ContractOutput<Entry['input']>; result: ContractOutput<Entry['result']> },\n\tcontext: Context,\n) => Value\nexport type SelectedAudit<Definition, Default> = Definition extends { audit: infer Override }\n\t? Override\n\t: 'audit' extends keyof Definition\n\t\t? Exclude<Definition['audit' & keyof Definition], undefined> | Default\n\t\t: Default\nexport type AuditedOperations<Operations, Default> = {\n\t[Key in keyof Operations]: Omit<Operations[Key], 'audit'> & {\n\t\taudit: SelectedAudit<Operations[Key], Default>\n\t}\n}\nexport type ExactDomainOperations<Operations, Contracts> = ExactOperationKeys<\n\tOperations,\n\tContracts\n> & {\n\t[Key in keyof Operations]: Operations[Key] extends BoundKey<Key> ? Operations[Key] : never\n}\n\ntype Helper<\n\tContext,\n\tEntry extends DomainOperationContract,\n\tKey,\n\tCommand extends boolean,\n\tDefault,\n\tBaseError,\n\tBaseRequirements,\n> = <\n\tHandler extends Supported<ContractInput<Entry['result']>>,\n\tGuard extends Supported<void> = never,\n\tPreparation extends Supported<\n\t\tEffectPreparation<ContractOutput<Entry['result']>, unknown, unknown>\n\t> = never,\n\tconst Aggregates extends readonly string[] = readonly string[],\n\tAuditReturned extends Supported<Audit> = never,\n\tMiddleware extends Supported<ContractInput<Entry['result']>> = never,\n\tconst Metadata extends object = Record<never, never>,\n\tconst Definition extends object = object,\n>(\n\timplementation: Definition &\n\t\tForbidden &\n\t\tOmit<\n\t\t\tOperationDefinition<\n\t\t\t\tContext,\n\t\t\t\tEntry['input'],\n\t\t\t\tEntry['result'],\n\t\t\t\tRecord<never, never>,\n\t\t\t\tAggregates,\n\t\t\t\tHandler,\n\t\t\t\tGuard,\n\t\t\t\tPreparation,\n\t\t\t\tAuditReturned,\n\t\t\t\tMiddleware,\n\t\t\t\tMetadata,\n\t\t\t\tBaseError,\n\t\t\t\tBaseRequirements,\n\t\t\t\tContractSchema,\n\t\t\t\tnever\n\t\t\t>,\n\t\t\t'input' | 'result' | 'classification' | 'replayResult' | 'wire'\n\t\t> &\n\t\t(Command extends true\n\t\t\t? [Default] extends [never]\n\t\t\t\t? { audit: AuditCallback<Context, Entry, AuditReturned> }\n\t\t\t\t: {}\n\t\t\t: { audit?: never; prepare?: never; aggregates?: never }),\n) => DeclaredSchemas<Entry> &\n\tCheckedEffectDefinition<\n\t\tContext,\n\t\tSchemas<Entry> & Definition & BoundKey<Key>,\n\t\tBaseError,\n\t\tBaseRequirements\n\t>\n\ntype HandlerArguments<\n\tOptions,\n\tCommand extends boolean,\n\tDefault,\n\tRequiredAudit,\n> = Command extends true\n\t? [Default] extends [never]\n\t\t? [options: Options & RequiredAudit]\n\t\t: [options?: Options]\n\t: [options?: Options]\n\ntype HandlerHelper<\n\tContext,\n\tEntries extends Readonly<Record<string, DomainOperationContract>>,\n\tCommand extends boolean,\n\tDefault,\n\tBaseError,\n\tBaseRequirements,\n> = <\n\tconst Input extends ContractSchema,\n\tconst Result extends ContractSchema,\n\tKey extends keyof Entries,\n\tHandler extends Supported<ContractInput<Result>>,\n\tGuard extends Supported<void> = never,\n\tPreparation extends Supported<EffectPreparation<ContractOutput<Result>, unknown, unknown>> =\n\t\tnever,\n\tconst Aggregates extends readonly string[] = readonly string[],\n\tAuditReturned extends Supported<Audit> = never,\n\tMiddleware extends Supported<ContractInput<Result>> = never,\n\tconst Metadata extends object = Record<never, never>,\n\tconst Definition extends object = object,\n>(\n\thandler: (input: ContractOutput<Input>, context: Context) => Handler,\n\t...options: HandlerArguments<\n\t\tDefinition &\n\t\t\tForbidden & { handler?: never } & Omit<\n\t\t\t\tOperationDefinition<\n\t\t\t\t\tContext,\n\t\t\t\t\tInput,\n\t\t\t\t\tResult,\n\t\t\t\t\tRecord<never, never>,\n\t\t\t\t\tAggregates,\n\t\t\t\t\tHandler,\n\t\t\t\t\tGuard,\n\t\t\t\t\tPreparation,\n\t\t\t\t\tAuditReturned,\n\t\t\t\t\tMiddleware,\n\t\t\t\t\tMetadata,\n\t\t\t\t\tBaseError,\n\t\t\t\t\tBaseRequirements,\n\t\t\t\t\tContractSchema,\n\t\t\t\t\tnever\n\t\t\t\t>,\n\t\t\t\t'handler' | 'input' | 'result' | 'classification' | 'replayResult' | 'wire'\n\t\t\t> &\n\t\t\t(Command extends true ? {} : { audit?: never; prepare?: never; aggregates?: never }),\n\t\tCommand,\n\t\tDefault,\n\t\t{ audit: AuditCallback<Context, { input: Input; result: Result }, AuditReturned> }\n\t>\n) => DeclaredSchemas<{ input: Input; result: Result }> & {\n\thandler: (input: ContractOutput<Input>, context: Context) => NoInfer<Handler>\n} & NoInfer<Definition> &\n\tBoundKey<Key> &\n\tCheckedEffectDefinition<\n\t\tContext,\n\t\tNoInfer<Definition> & {\n\t\t\thandler: (input: ContractOutput<Input>, context: Context) => Handler\n\t\t} & BoundKey<Key>,\n\t\tBaseError,\n\t\tBaseRequirements\n\t>\n\nexport type DomainEffectFactory<\n\tContext,\n\tEntries extends Readonly<Record<string, DomainOperationContract>>,\n\tCommand extends boolean,\n\tDefault = never,\n\tBaseError = never,\n\tBaseRequirements = never,\n> = {\n\t[Kind in Command extends true ? 'command' : 'query']: {\n\t\treadonly [Key in keyof Entries]: Helper<\n\t\t\tContext,\n\t\t\tEntries[Key],\n\t\t\tKey,\n\t\t\tCommand,\n\t\t\tDefault,\n\t\t\tBaseError,\n\t\t\tBaseRequirements\n\t\t>\n\t} & { handler: HandlerHelper<Context, Entries, Command, Default, BaseError, BaseRequirements> }\n}\n\nexport type DomainEffectImplementations<\n\tContext,\n\tEntries extends Readonly<Record<string, DomainOperationContract>>,\n\tRequired extends boolean = false,\n> = {\n\t[Key in keyof Entries]: DeclaredSchemas<Pick<Entries[Key], 'input' | 'result'>> &\n\t\tBoundKey<Key> &\n\t\tCheckedEffectOperation<Context> & {\n\t\t\thandler: (\n\t\t\t\tinput: ContractOutput<Entries[Key]['input']>,\n\t\t\t\tcontext: Context,\n\t\t\t) => Supported<ContractInput<Entries[Key]['result']>>\n\t\t} & (Required extends true\n\t\t\t? { audit: AuditCallback<Context, Entries[Key], Supported<Audit>> }\n\t\t\t: {})\n}\n\nexport function domainEffectFactory<\n\tContext,\n\tEntries extends Readonly<Record<string, DomainOperationContract>>,\n\tCommand extends boolean,\n\tDefault,\n\tGuard,\n>(\n\tentries: Entries,\n\tcommand: Command,\n): DomainEffectFactory<\n\tContext,\n\tEntries,\n\tCommand,\n\tDefault,\n\tCallbackError<Guard>,\n\tCallbackRequirements<Guard>\n> {\n\tconst helpers = domainHelpers(entries)\n\t// SAFETY: helper signatures check callbacks; registration pairs drafts with their declarations.\n\treturn { [command ? 'command' : 'query']: helpers } as DomainEffectFactory<\n\t\tContext,\n\t\tEntries,\n\t\tCommand,\n\t\tDefault,\n\t\tCallbackError<Guard>,\n\t\tCallbackRequirements<Guard>\n\t>\n}\n\nexport type SharedEffectFactory<Context, Guard> = ReturnType<\n\ttypeof effectOperationFactory<\n\t\tContext,\n\t\tRecord<never, never>,\n\t\tNoInfer<CallbackError<Guard>>,\n\t\tNoInfer<CallbackRequirements<Guard>>,\n\t\tfalse\n\t>\n>\nexport type AuditValue = Supported<Audit>\n"],"mappings":"yDAwNA,SAAgBA,EAOf,EACA,EAQC,CACD,IAAMC,EAAUC,EAAcC,CAAO,EAErC,MAAO,EAAGC,EAAU,UAAY,SAAUH,CAAQ,CAQnD"}