{"version":3,"file":"operation.mjs","names":["domainFactory","helpers","domainHelpers","entries","command","operationFactory","implementation","query"],"sources":["../../../src/modules/foundation/operation.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 { AuditEntryInput } from '../../components/foundation/client'\nimport type { ContractInput, ContractOutput, NeutralSchema } from '../contracts/contract'\nimport type { DomainOperationContract, ExactOperationKeys } from '../contracts/domain'\nimport { domainHelpers, type DeclaredSchemas } from '../contracts/binding'\n\ntype Supported<A> = A | PromiseLike<A>\nexport type Audit = Omit<AuditEntryInput, 'classification'> | null\nexport type NormalEntry = DomainOperationContract & {\n\tinput: NeutralSchema\n\tresult: NeutralSchema\n\treplayResult?: NeutralSchema\n\twire?: { schema: NeutralSchema; project: Function }\n}\ndeclare const checkedOperation: unique symbol\nexport type CheckedDefinition<Context, Definition, Key = unknown> = NoInfer<Definition> & {\n\treadonly [checkedOperation]: {\n\t\tcontext: (context: Context) => void\n\t\tdefinition: Definition\n\t\tkey: Key\n\t}\n}\nexport type CheckedOperation<Context> = {\n\treadonly [checkedOperation]: {\n\t\tcontext: (context: Context) => void\n\t\tdefinition: unknown\n\t\tkey: unknown\n\t}\n}\nexport type ValidatedOperations<Operations> = {\n\t[Key in keyof Operations]: Operations[Key] extends {\n\t\treadonly [checkedOperation]: { definition: infer Definition }\n\t}\n\t\t? Operations[Key] extends Definition\n\t\t\t? Operations[Key]\n\t\t\t: never\n\t\t: never\n}\nexport type ExactOperations<Operations, Entries> = ExactOperationKeys<Operations, Entries> & {\n\t[Key in keyof Operations]: Operations[Key] extends { readonly [checkedOperation]: { key: Key } }\n\t\t? Operations[Key]\n\t\t: never\n}\ntype Definition<Context, Entry extends NormalEntry> = {\n\thandler: (\n\t\tinput: ContractOutput<Entry['input']>,\n\t\tcontext: Context,\n\t) => Supported<ContractInput<Entry['result']>>\n\tpermission?: string\n\tmetadata?: object\n\taggregates?: readonly string[]\n\tguard?: (context: Context, input: ContractOutput<Entry['input']>) => Supported<void>\n\tprepare?: (\n\t\tcontext: Context,\n\t\tinput: ContractOutput<Entry['input']>,\n\t) => Supported<\n\t\t| { kind: 'replay'; result: unknown }\n\t\t| { kind: 'execute'; complete?: (result: ContractOutput<Entry['result']>) => Supported<void> }\n\t>\n\taudit?: (\n\t\tresolution: {\n\t\t\tcommand: ContractOutput<Entry['input']>\n\t\t\tresult: ContractOutput<Entry['result']>\n\t\t},\n\t\tcontext: Context,\n\t) => Supported<Audit>\n\tmiddleware?: (input: {\n\t\toperation: string\n\t\tinput: ContractOutput<Entry['input']>\n\t\tcommand: ContractOutput<Entry['input']>\n\t\tcontext: Context\n\t\tmetadata: object\n\t\tnext: (options?: { context?: object }) => Promise<ContractInput<Entry['result']>>\n\t}) => Supported<ContractInput<Entry['result']>>\n}\ntype CommandRules<\n\tContext,\n\tEntry extends NormalEntry,\n\tCommand extends boolean,\n\tRequired extends boolean,\n> = Command extends false\n\t? { audit?: never; prepare?: never; aggregates?: never; replayResult?: never }\n\t: Required extends true\n\t\t? { audit: NonNullable<Definition<Context, Entry>['audit']> }\n\t\t: {}\ntype Forbidden = {\n\tinput?: never\n\tresult?: never\n\tclassification?: never\n\treplayResult?: never\n\twire?: never\n}\ntype HandlerOptions<\n\tContext,\n\tInput extends NeutralSchema,\n\tResult extends NeutralSchema,\n\tCommand extends boolean,\n\tRequired extends boolean,\n> = Omit<Definition<Context, { input: Input; result: Result }>, 'handler'> &\n\tForbidden & { handler?: never } & CommandRules<\n\t\tContext,\n\t\t{ input: Input; result: Result },\n\t\tCommand,\n\t\tRequired\n\t>\ntype HandlerArguments<Options, Required extends boolean> = Required extends true\n\t? [options: Options]\n\t: [options?: Options]\n\nexport type DomainFactory<\n\tContext,\n\tEntries extends Readonly<Record<string, NormalEntry>>,\n\tCommand extends boolean,\n\tRequired extends boolean,\n> = {\n\t[Kind in Command extends true ? 'command' : 'query']: {\n\t\t[Key in keyof Entries]: <const Implementation extends object>(\n\t\t\timplementation: Implementation &\n\t\t\t\tDefinition<Context, Entries[Key]> &\n\t\t\t\tForbidden &\n\t\t\t\tCommandRules<Context, Entries[Key], Command, Required>,\n\t\t) => DeclaredSchemas<Pick<Entries[Key], 'input' | 'result'>> &\n\t\t\tCheckedDefinition<Context, Entries[Key] & Implementation, Key>\n\t} & {\n\t\thandler: <\n\t\t\tconst Input extends NeutralSchema,\n\t\t\tconst Result extends NeutralSchema,\n\t\t\tKey extends keyof Entries,\n\t\t\tHandler extends Supported<ContractInput<Result>>,\n\t\t\tconst Implementation extends object = Record<never, never>,\n\t\t>(\n\t\t\thandler: (input: ContractOutput<Input>, context: Context) => Handler,\n\t\t\t...options: HandlerArguments<\n\t\t\t\tImplementation & HandlerOptions<Context, Input, Result, Command, Required>,\n\t\t\t\tCommand extends true ? Required : false\n\t\t\t>\n\t\t) => DeclaredSchemas<{ input: Input; result: Result }> &\n\t\t\tCheckedDefinition<\n\t\t\t\tContext,\n\t\t\t\tNoInfer<Implementation> & {\n\t\t\t\t\thandler: (input: ContractOutput<Input>, context: Context) => Handler\n\t\t\t\t},\n\t\t\t\tKey\n\t\t\t>\n\t}\n}\nexport type DomainImplementations<\n\tContext,\n\tEntries extends Readonly<Record<string, NormalEntry>>,\n\tCommand extends boolean,\n\tRequired extends boolean,\n> = {\n\t[Key in keyof Entries]: DeclaredSchemas<Pick<Entries[Key], 'input' | 'result'>> &\n\t\tCheckedDefinition<\n\t\t\tContext,\n\t\t\tDefinition<Context, Entries[Key]> & CommandRules<Context, Entries[Key], Command, Required>,\n\t\t\tKey\n\t\t>\n}\nexport function domainFactory<\n\tContext,\n\tEntries extends Readonly<Record<string, NormalEntry>>,\n\tCommand extends boolean,\n\tRequired extends boolean,\n>(entries: Entries, command: Command): DomainFactory<Context, Entries, Command, Required> {\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 DomainFactory<\n\t\tContext,\n\t\tEntries,\n\t\tCommand,\n\t\tRequired\n\t>\n}\nexport function operationFactory<Context, Required extends boolean = true>() {\n\tfunction command<\n\t\tconst Input extends NeutralSchema,\n\t\tconst Result extends NeutralSchema,\n\t\tconst Wire extends NeutralSchema,\n\t\tconst Replay extends NeutralSchema,\n\t\tconst Implementation extends object,\n\t>(\n\t\timplementation: Implementation & {\n\t\t\tinput: Input\n\t\t\tresult: Result\n\t\t\tclassification: string\n\t\t\treplayResult?: Replay &\n\t\t\t\t(ContractOutput<Replay> extends ContractOutput<Result> ? unknown : never)\n\t\t\twire?: { schema: Wire; project: (result: ContractOutput<Result>) => ContractInput<Wire> }\n\t\t} & Definition<Context, { input: Input; result: Result }> &\n\t\t\tCommandRules<Context, { input: Input; result: Result }, true, Required>,\n\t) {\n\t\t// SAFETY: this type-only evidence records the complete helper-checked definition.\n\t\treturn implementation as CheckedDefinition<Context, typeof implementation>\n\t}\n\tfunction query<\n\t\tconst Input extends NeutralSchema,\n\t\tconst Result extends NeutralSchema,\n\t\tconst Wire extends NeutralSchema,\n\t\tconst Implementation extends object,\n\t>(\n\t\timplementation: Implementation & {\n\t\t\tinput: Input\n\t\t\tresult: Result\n\t\t\tclassification?: string\n\t\t\twire?: { schema: Wire; project: (result: ContractOutput<Result>) => ContractInput<Wire> }\n\t\t} & Definition<Context, { input: Input; result: Result }> &\n\t\t\tCommandRules<Context, { input: Input; result: Result }, false, true>,\n\t) {\n\t\t// SAFETY: this type-only evidence records the complete helper-checked definition.\n\t\treturn implementation as CheckedDefinition<Context, typeof implementation>\n\t}\n\treturn { command, query }\n}\nexport type InlineFactory<Context, Required extends boolean> = ReturnType<\n\ttypeof operationFactory<Context, Required>\n>\n"],"mappings":"yDA+JA,SAAgBA,EAKd,EAAkB,EAAsE,CACzF,IAAMC,EAAUC,EAAcC,CAAO,EAErC,MAAO,EAAGC,EAAU,UAAY,SAAUH,CAAQ,CAMnD,CACA,SAAgBI,GAA6D,CAC5E,SAASD,EAOR,EASC,CAED,OAAOE,CACR,CACA,SAASC,EAMR,EAOC,CAED,OAAOD,CACR,CACA,MAAO,CAAE,UAAS,OAAM,CACzB"}