cvx-kit 0.1.30 → 0.1.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/effect.d.mts +5 -1
  2. package/dist/effect.mjs +1 -1
  3. package/dist/modules/contracts/binding.d.mts +1 -1
  4. package/dist/modules/contracts/binding.mjs +1 -1
  5. package/dist/modules/contracts/binding.mjs.map +1 -1
  6. package/dist/modules/contracts/domain.d.mts +5 -1
  7. package/dist/modules/contracts/domain.mjs +1 -1
  8. package/dist/modules/contracts/domain.mjs.map +1 -1
  9. package/dist/modules/contracts/errors.d.mts +4 -0
  10. package/dist/modules/contracts/errors.mjs +1 -1
  11. package/dist/modules/contracts/errors.mjs.map +1 -1
  12. package/dist/modules/effect/action.d.mts +64 -0
  13. package/dist/modules/effect/action.mjs +2 -0
  14. package/dist/modules/effect/action.mjs.map +1 -0
  15. package/dist/modules/effect/client.d.mts +5 -1
  16. package/dist/modules/effect/client.mjs +1 -1
  17. package/dist/modules/effect/command.d.mts +15 -9
  18. package/dist/modules/effect/command.mjs +1 -1
  19. package/dist/modules/effect/command.mjs.map +1 -1
  20. package/dist/modules/effect/crud.d.mts +17 -16
  21. package/dist/modules/effect/domain.d.mts +19 -8
  22. package/dist/modules/effect/domain.mjs +1 -1
  23. package/dist/modules/effect/domain.mjs.map +1 -1
  24. package/dist/modules/effect/errors.d.mts +5 -1
  25. package/dist/modules/effect/errors.mjs +1 -1
  26. package/dist/modules/effect/errors.mjs.map +1 -1
  27. package/dist/modules/effect/failure-audit.d.mts +48 -0
  28. package/dist/modules/effect/failure-audit.mjs +2 -0
  29. package/dist/modules/effect/failure-audit.mjs.map +1 -0
  30. package/dist/modules/effect/failures.d.mts +22 -0
  31. package/dist/modules/effect/failures.mjs +2 -0
  32. package/dist/modules/effect/failures.mjs.map +1 -0
  33. package/dist/modules/effect/foundation.d.mts +6 -1
  34. package/dist/modules/effect/foundation.mjs +1 -1
  35. package/dist/modules/effect/foundation.mjs.map +1 -1
  36. package/dist/modules/effect/operation.d.mts +10 -2
  37. package/dist/modules/effect/operation.mjs +1 -1
  38. package/dist/modules/effect/operation.mjs.map +1 -1
  39. package/dist/modules/effect/query.d.mts +5 -1
  40. package/dist/modules/effect/query.mjs +1 -1
  41. package/dist/modules/effect/query.mjs.map +1 -1
  42. package/dist/modules/effect/scope.d.mts +27 -0
  43. package/dist/modules/effect/scope.mjs +2 -0
  44. package/dist/modules/effect/scope.mjs.map +1 -0
  45. package/dist/zod-table.d.mts +72 -1
  46. package/dist/zod-table.mjs +1 -1
  47. package/dist/zod-table.mjs.map +1 -1
  48. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"command.mjs","names":["effectLifecycle","Effect","createEffectCommand","getOperations","memoize","configuration","effectOperationFactory","exec","operations","operation","definition","decodeEffectContract","input","command","decoded","observation","resolve","normalizeEffect","host","executeCommandLifecycle","CommandPermissionError","context","preparation","result","value","normalizeCommandResult","input_","enriched","entry","Exit","exit","observationFailure","registerLazyRegistry","selectOperation","owner","bindEffectCommand","buildOperations","definitions","domainEffectFactory","snapshotOperations","dependencies","invoke"],"sources":["../../../src/modules/effect/command.ts"],"sourcesContent":["import { memoize, registerLazyRegistry } from '../contracts/lazy'\n/* oxlint-disable anti-slop/no-unknown-returns, anti-slop/no-unsafe-dictionary-type -- Overload implementation storage is erased; public signatures retain concrete values, errors and services. */\nimport { Effect, Exit } from 'effect'\nimport type { AuditEntryInput } from '../../components/foundation/client'\nimport type { ContractSchema } from '../contracts/contract'\nimport {\n\tselectOperation,\n\ttype SelectedOperation,\n\ttype OperationPublicResult,\n} from '../contracts/exposure'\nimport { decodeEffectContract } from './schema'\n// oxlint-disable-next-line cvx/component-boundaries -- SAFETY: Internal optional adapter shares the Effect-free Foundation lifecycle and types without entering the Convex component deployment graph.\nimport {\n\tCommandPermissionError,\n\texecuteCommandLifecycle,\n\ttype ExecutionKind,\n\ttype LifecycleAlgebra,\n\ttype LifecyclePreparation,\n} from '../../components/foundation/modules/command/lifecycle'\n// oxlint-disable-next-line cvx/component-boundaries -- SAFETY: Internal optional adapter shares the Effect-free Foundation lifecycle and types without entering the Convex component deployment graph.\nimport type { Observability } from '../../components/foundation/modules/observability/observability'\nimport { normalizeEffect, observationFailure } from './normalize'\nimport {\n\teffectOperationFactory,\n\ttype CallbackError,\n\ttype CallbackRequirements,\n\ttype EffectValue,\n\ttype EffectOperationArgument,\n\ttype EffectOperationInput,\n\ttype EffectOperationHandlerResult,\n\ttype EffectPreparation,\n\ttype EffectOperationResult,\n\ttype EffectOperationError,\n\ttype EffectOperationRequirements,\n\ttype CheckedEffectOperation,\n\ttype UnwrappedDefaultError,\n\ttype UnwrappedDefaultRequirements,\n\ttype ValidatedEffectOperations,\n} from './operation'\n\nimport type { DomainContract, DomainCommandContract, DomainAuditInput } from '../contracts/domain'\nimport { snapshotOperations, type BoundOperations } from '../contracts/binding'\nimport {\n\tdomainEffectFactory,\n\ttype DomainEffectFactory,\n\ttype DomainEffectImplementations,\n\ttype ExactDomainOperations,\n\ttype AuditedOperations,\n\ttype SharedEffectFactory,\n\ttype AuditValue,\n} from './domain'\n\ntype Supported<Value> = Value | PromiseLike<Value> | Effect.Effect<Value, unknown, unknown>\n// Heterogeneous storage constraints preserve concrete callbacks in inferred definitions.\n// oxlint-disable-next-line anti-slop/no-unknown-returns -- Internal callback storage; selected definitions retain concrete return contracts.\ntype Callback = (...arguments_: never[]) => Supported<unknown>\n// oxlint-disable-next-line anti-slop/no-unknown-returns -- Resolver constraint captures its concrete return in Resolve; it never exposes this storage type at exec.\ntype Resolver = (host: never) => Supported<unknown>\ntype HostOf<Resolve extends Resolver> = Parameters<Resolve>[0]\ntype DomainOf<Resolve extends Resolver> = EffectValue<ReturnType<Resolve>>\ntype Operation = {\n\tinput: ContractSchema\n\tresult: ContractSchema\n\tclassification: string\n\thandler: Callback\n\taudit: Callback\n\tguard?: Callback\n\tprepare?: Callback\n\tmiddleware?: Callback\n\tpermission?: string\n\taggregates?: readonly string[]\n\treplayResult?: ContractSchema\n}\ntype Registry<Context> = Readonly<\n\tRecord<\n\t\tstring,\n\t\tPick<Operation, 'input' | 'result' | 'classification' | 'handler' | 'audit'> &\n\t\t\tCheckedEffectOperation<Context>\n\t>\n>\nexport type EffectCommandDependencies = {\n\tobservability: Observability\n\tcheckPermission?: (\n\t\thost: never,\n\t\tinput: { permission: string; operation: string },\n\t) => Supported<void>\n\t// oxlint-disable-next-line anti-slop/no-unknown-returns -- Audit writer storage; its concrete return/error/services remain in Dependencies.\n\twriteAudit: (host: never, entry: AuditEntryInput) => Supported<unknown>\n}\ntype HostParameter<Policy> = [Exclude<Policy, undefined>] extends [never]\n\t? unknown\n\t: // oxlint-disable-next-line anti-slop/no-unknown-returns -- Conditional parameter-extraction predicate, not an executable callback contract.\n\t\tExclude<Policy, undefined> extends (...arguments_: infer Arguments) => Supported<unknown>\n\t\t? Arguments extends []\n\t\t\t? unknown\n\t\t\t: Arguments[0]\n\t\t: unknown\ntype PolicyHost<Dependencies extends EffectCommandDependencies> = HostParameter<\n\tDependencies['writeAudit']\n> &\n\tHostParameter<Dependencies['checkPermission']>\ntype HostCompatible<Resolve extends Resolver, Dependencies extends EffectCommandDependencies> = [\n\tHostOf<Resolve>,\n] extends [PolicyHost<Dependencies>]\n\t? unknown\n\t: { context: never }\ntype Factory<Resolve extends Resolver, Guard> = ReturnType<\n\ttypeof effectOperationFactory<\n\t\tDomainOf<Resolve>,\n\t\tRecord<never, never>,\n\t\tNoInfer<CallbackError<Guard>>,\n\t\tNoInfer<CallbackRequirements<Guard>>\n\t>\n>\nexport type EffectCommandConfiguration<\n\tResolve extends Resolver,\n\tOperations extends Registry<DomainOf<Resolve>>,\n\tGuard,\n> = {\n\tcontext: Resolve\n\toperations: (\n\t\tdefine: Factory<Resolve, Guard>,\n\t) => Operations & NoInfer<ValidatedEffectOperations<Operations>>\n\tdefaults?: { guard?: (context: DomainOf<Resolve>) => Guard }\n}\ntype ErrorOf<Definition, Resolve, Dependencies, Guard> =\n\t| EffectOperationError<Definition>\n\t| CallbackError<Resolve | Dependencies[keyof Dependencies]>\n\t| UnwrappedDefaultError<Definition, Guard>\ntype RequirementsOf<Definition, Resolve, Dependencies, Guard> =\n\t| EffectOperationRequirements<Definition>\n\t| CallbackRequirements<Resolve | Dependencies[keyof Dependencies]>\n\t| UnwrappedDefaultRequirements<Definition, Guard>\ninterface EffectExecution extends ExecutionKind {\n\treadonly type: Effect.Effect<this['value'], unknown, unknown>\n}\nconst effectLifecycle: LifecycleAlgebra<EffectExecution> = {\n\tsucceed: Effect.succeed,\n\tsuspend: Effect.suspend,\n\tflatMap: Effect.flatMap,\n}\ntype RuntimeOperation<Context, Input, Raw, Result> = {\n\tinput: ContractSchema\n\tresult: ContractSchema\n\tclassification: string\n\tpermission?: string\n\taggregates?: readonly string[]\n\treplayResult?: ContractSchema\n\thandler: (input: Input, context: Context) => Supported<Raw>\n\tguard?: (context: Context, input: Input) => Supported<void>\n\tprepare?: (\n\t\tcontext: Context,\n\t\tinput: Input,\n\t) => Supported<EffectPreparation<Result, unknown, unknown>>\n\taudit: (\n\t\tresolution: { command: Input; result: Result },\n\t\tcontext: Context,\n\t) => Supported<Omit<AuditEntryInput, 'classification'> | null>\n\tmiddleware?: (input: {\n\t\toperation: string\n\t\tcommand: Input\n\t\tinput: Input\n\t\tcontext: Context\n\t\tnext: (options?: { context?: object }) => Effect.Effect<Raw, unknown, unknown>\n\t}) => Supported<Raw>\n}\n\n/** Internal registry constructor: the public Foundation binds host policies once. */\nexport function createEffectCommand<\n\tResolve extends Resolver,\n\tconst Operations extends Registry<DomainOf<Resolve>>,\n\tconst Dependencies extends EffectCommandDependencies,\n\tGuard = never,\n>(\n\tconfiguration: EffectCommandConfiguration<Resolve, Operations, Guard> &\n\t\tDependencies &\n\t\tHostCompatible<Resolve, Dependencies>,\n) {\n\tconst getOperations = memoize<Operations>(() =>\n\t\tconfiguration.operations(\n\t\t\teffectOperationFactory<\n\t\t\t\tDomainOf<Resolve>,\n\t\t\t\tRecord<never, never>,\n\t\t\t\tCallbackError<Guard>,\n\t\t\t\tCallbackRequirements<Guard>\n\t\t\t>(),\n\t\t),\n\t)\n\tconst exec = <Key extends Extract<keyof Operations, string>>(\n\t\toperation: Key,\n\t\tinput: EffectOperationArgument<Operations[Key]>,\n\t\thost: HostOf<Resolve>,\n\t): Effect.Effect<\n\t\tEffectOperationResult<Operations[Key]>,\n\t\tErrorOf<Operations[Key], Resolve, Dependencies, Guard>,\n\t\tRequirementsOf<Operations[Key], Resolve, Dependencies, Guard>\n\t> => {\n\t\tconst execution = Effect.suspend(() => {\n\t\t\tconst operations = getOperations()\n\t\t\tif (!Object.prototype.hasOwnProperty.call(operations, operation))\n\t\t\t\tthrow Error('The selected command operation is not configured')\n\t\t\t// SAFETY: this helper checked selected callbacks against their parsed schemas and domain context.\n\t\t\tconst definition = operations[operation] as Operations[Key] &\n\t\t\t\tRuntimeOperation<\n\t\t\t\t\tDomainOf<Resolve>,\n\t\t\t\t\tEffectOperationInput<Operations[Key]>,\n\t\t\t\t\tEffectOperationHandlerResult<Operations[Key]>,\n\t\t\t\t\tEffectOperationResult<Operations[Key]>\n\t\t\t\t>\n\t\t\t// SAFETY: selected command input was parsed by its own paired schema.\n\t\t\treturn Effect.flatMap(decodeEffectContract(definition.input, input), (decoded) => {\n\t\t\t\t// SAFETY: the selected operation's decoder owns this concrete domain input.\n\t\t\t\tconst command = decoded as EffectOperationInput<Operations[Key]>\n\t\t\t\tconst observation = configuration.observability.start({\n\t\t\t\t\toperation,\n\t\t\t\t\tclassification: definition.classification,\n\t\t\t\t})\n\t\t\t\t// SAFETY: resolver identity owns its concrete invocation return and host parameter.\n\t\t\t\tconst resolve = configuration.context as (host: HostOf<Resolve>) => ReturnType<Resolve>\n\t\t\t\treturn normalizeEffect(() => resolve(host)).pipe(\n\t\t\t\t\tEffect.flatMap((context) => {\n\t\t\t\t\t\tconst lifecycle = executeCommandLifecycle<\n\t\t\t\t\t\t\tEffectExecution,\n\t\t\t\t\t\t\tDomainOf<Resolve>,\n\t\t\t\t\t\t\tEffectOperationInput<Operations[Key]>,\n\t\t\t\t\t\t\tEffectOperationHandlerResult<Operations[Key]>,\n\t\t\t\t\t\t\tEffectOperationResult<Operations[Key]>\n\t\t\t\t\t\t>(effectLifecycle, {\n\t\t\t\t\t\t\toperation,\n\t\t\t\t\t\t\tclassification: definition.classification,\n\t\t\t\t\t\t\tcontext,\n\t\t\t\t\t\t\tcommand,\n\t\t\t\t\t\t\tpermission:\n\t\t\t\t\t\t\t\tdefinition.permission === undefined\n\t\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t\t: () =>\n\t\t\t\t\t\t\t\t\t\t\tnormalizeEffect(() => {\n\t\t\t\t\t\t\t\t\t\t\t\tif (!configuration.checkPermission)\n\t\t\t\t\t\t\t\t\t\t\t\t\tthrow new CommandPermissionError(operation)\n\t\t\t\t\t\t\t\t\t\t\t\t// SAFETY: HostCompatible proves this invocation satisfies the configured policy host.\n\t\t\t\t\t\t\t\t\t\t\t\treturn configuration.checkPermission(host as never, {\n\t\t\t\t\t\t\t\t\t\t\t\t\tpermission: definition.permission!,\n\t\t\t\t\t\t\t\t\t\t\t\t\toperation,\n\t\t\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t\t\t}).pipe(Effect.asVoid),\n\t\t\t\t\t\t\tprepare: () =>\n\t\t\t\t\t\t\t\tnormalizeEffect(() => definition.prepare?.(context, command)).pipe(\n\t\t\t\t\t\t\t\t\tEffect.map((preparation) => {\n\t\t\t\t\t\t\t\t\t\tif (preparation?.kind !== 'execute') return preparation\n\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\tkind: 'execute',\n\t\t\t\t\t\t\t\t\t\t\tcomplete: preparation.complete\n\t\t\t\t\t\t\t\t\t\t\t\t? (result) =>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnormalizeEffect(() => preparation.complete!(result)).pipe(Effect.asVoid)\n\t\t\t\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\t\t\t\t} satisfies LifecyclePreparation<\n\t\t\t\t\t\t\t\t\t\t\tEffectExecution,\n\t\t\t\t\t\t\t\t\t\t\tEffectOperationResult<Operations[Key]>\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t// SAFETY: the selected final replay contract owns this result; operation types retain its E/R.\n\t\t\t\t\t\t\tdecodeReplay: (value) =>\n\t\t\t\t\t\t\t\tdecodeEffectContract(\n\t\t\t\t\t\t\t\t\tdefinition.replayResult ?? definition.result,\n\t\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t\t) as Effect.Effect<EffectOperationResult<Operations[Key]>, unknown, unknown>,\n\t\t\t\t\t\t\tmiddleware: definition.middleware\n\t\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t\t(input_) =>\n\t\t\t\t\t\t\t\t\t\t\tnormalizeCommandResult(() =>\n\t\t\t\t\t\t\t\t\t\t\t\tdefinition.middleware!({ ...input_, input: command }),\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t: [],\n\t\t\t\t\t\t\tdefaultGuard: (enriched) =>\n\t\t\t\t\t\t\t\tnormalizeEffect(() => configuration.defaults?.guard?.(enriched)).pipe(\n\t\t\t\t\t\t\t\t\tEffect.asVoid,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tguard: (enriched) =>\n\t\t\t\t\t\t\t\tnormalizeEffect(() => definition.guard?.(enriched, command)).pipe(Effect.asVoid),\n\t\t\t\t\t\t\trun: (enriched) =>\n\t\t\t\t\t\t\t\tnormalizeCommandResult(() => definition.handler(command, enriched)),\n\t\t\t\t\t\t\t// SAFETY: the selected contract owns the decoded result; the public operation retains decoder E/R.\n\t\t\t\t\t\t\tdecodeResult: (value) =>\n\t\t\t\t\t\t\t\tdecodeEffectContract(definition.result, value) as Effect.Effect<\n\t\t\t\t\t\t\t\t\tEffectOperationResult<Operations[Key]>,\n\t\t\t\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t\t\t\tunknown\n\t\t\t\t\t\t\t\t>,\n\t\t\t\t\t\t\taudit: (result) =>\n\t\t\t\t\t\t\t\tnormalizeEffect(() => definition.audit({ command, result }, context)),\n\t\t\t\t\t\t\twriteAudit: (entry) =>\n\t\t\t\t\t\t\t\tnormalizeEffect(() => {\n\t\t\t\t\t\t\t\t\t// SAFETY: HostCompatible proves this invocation satisfies the configured writer host.\n\t\t\t\t\t\t\t\t\treturn configuration.writeAudit(host as never, entry)\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\taggregates: definition.aggregates,\n\t\t\t\t\t\t})\n\t\t\t\t\t\treturn lifecycle\n\t\t\t\t\t}),\n\t\t\t\t\tEffect.onExit((exit) =>\n\t\t\t\t\t\tEffect.sync(() => {\n\t\t\t\t\t\t\tif (Exit.isSuccess(exit)) observation.completed()\n\t\t\t\t\t\t\telse observation.failed(observationFailure(exit.cause))\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t})\n\t\t})\n\t\t// SAFETY: dispatch selects exactly this operation; callbacks preserve the concrete definition/policy E/R.\n\t\treturn execution as Effect.Effect<\n\t\t\tEffectOperationResult<Operations[Key]>,\n\t\t\tErrorOf<Operations[Key], Resolve, Dependencies, Guard>,\n\t\t\tRequirementsOf<Operations[Key], Resolve, Dependencies, Guard>\n\t\t>\n\t}\n\treturn registerLazyRegistry(\n\t\t{\n\t\t\t/** Bind invocation context without resolving it or running an operation. */\n\t\t\twithContext(context: HostOf<Resolve>) {\n\t\t\t\treturn {\n\t\t\t\t\texec: <Key extends Extract<keyof Operations, string>>(\n\t\t\t\t\t\toperation: Key,\n\t\t\t\t\t\tinput: EffectOperationArgument<Operations[Key]>,\n\t\t\t\t\t) => exec(operation, input, context),\n\t\t\t\t}\n\t\t\t},\n\t\t\texpose<const Owner extends symbol, const Key extends Extract<keyof Operations, string>>(\n\t\t\t\towner: Owner,\n\t\t\t\toperation: Key,\n\t\t\t): SelectedOperation<\n\t\t\t\tOwner,\n\t\t\t\tKey,\n\t\t\t\tOperations[Key]['input'],\n\t\t\t\tOperationPublicResult<Operations[Key]>\n\t\t\t> {\n\t\t\t\tconst operations = getOperations()\n\t\t\t\tif (!Object.hasOwn(operations, operation))\n\t\t\t\t\tthrow Error('The selected command operation is not configured')\n\t\t\t\treturn selectOperation(owner, 'mutation', operation, operations[operation])\n\t\t\t},\n\t\t\texec,\n\t\t},\n\t\tgetOperations,\n\t)\n}\n\n/** Bind trusted application policies without exposing a loose public command kernel. */\nexport function bindEffectCommand<const Dependencies extends EffectCommandDependencies>(\n\tdependencies: Dependencies,\n) {\n\ttype LooseRegistry<Context> = Readonly<\n\t\tRecord<\n\t\t\tstring,\n\t\t\tPick<Operation, 'input' | 'result' | 'classification' | 'handler'> &\n\t\t\t\tCheckedEffectOperation<Context>\n\t\t>\n\t>\n\n\tfunction command<\n\t\tResolve extends Resolver,\n\t\tconst Contract extends DomainContract & {\n\t\t\tcommands: Readonly<Record<string, DomainCommandContract>>\n\t\t},\n\t\tconst Operations extends DomainEffectImplementations<\n\t\t\tDomainOf<Resolve>,\n\t\t\tContract['commands'],\n\t\t\ttrue\n\t\t>,\n\t\tMode extends true,\n\t\tGuard = never,\n\t>(\n\t\tconfiguration: {\n\t\t\tcontract: Contract &\n\t\t\t\tNoInfer<\n\t\t\t\t\tOperations extends ExactDomainOperations<Operations, Contract['commands']> &\n\t\t\t\t\t\tValidatedEffectOperations<Operations>\n\t\t\t\t\t\t? unknown\n\t\t\t\t\t\t: never\n\t\t\t\t>\n\t\t\tcontext: Resolve\n\t\t\taudit?: never\n\t\t\toperations: (\n\t\t\t\tdefine: DomainEffectFactory<\n\t\t\t\t\tDomainOf<Resolve>,\n\t\t\t\t\tContract['commands'],\n\t\t\t\t\tMode,\n\t\t\t\t\tnever,\n\t\t\t\t\tNoInfer<CallbackError<Guard>>,\n\t\t\t\t\tNoInfer<CallbackRequirements<Guard>>\n\t\t\t\t>,\n\t\t\t) => Operations\n\t\t\tdefaults?: { guard?: (context: DomainOf<Resolve>) => Guard }\n\t\t} & HostCompatible<Resolve, Dependencies>,\n\t): ReturnType<\n\t\ttypeof createEffectCommand<\n\t\t\tResolve,\n\t\t\tBoundOperations<Operations, Contract['commands']> & {\n\t\t\t\t[Key in keyof Contract['commands']]: {\n\t\t\t\t\tclassification: Contract['commands'][Key]['classification']\n\t\t\t\t\taudit: Operations[Key]['audit']\n\t\t\t\t}\n\t\t\t},\n\t\t\tDependencies,\n\t\t\tGuard\n\t\t>\n\t>\n\tfunction command<\n\t\tResolve extends Resolver,\n\t\tconst Contract extends DomainContract & {\n\t\t\tcommands: Readonly<Record<string, DomainCommandContract>>\n\t\t},\n\t\tconst Operations extends DomainEffectImplementations<DomainOf<Resolve>, Contract['commands']>,\n\t\tReturned extends AuditValue,\n\t\tGuard = never,\n\t>(\n\t\tconfiguration: {\n\t\t\tcontract: Contract &\n\t\t\t\tNoInfer<\n\t\t\t\t\tOperations extends ExactDomainOperations<Operations, Contract['commands']> &\n\t\t\t\t\t\tValidatedEffectOperations<Operations>\n\t\t\t\t\t\t? unknown\n\t\t\t\t\t\t: never\n\t\t\t\t>\n\t\t\tcontext: Resolve\n\t\t\taudit: (\n\t\t\t\tresolution: DomainAuditInput<Contract['commands']>,\n\t\t\t\tcontext: DomainOf<Resolve>,\n\t\t\t) => Returned\n\t\t\toperations: (\n\t\t\t\tdefine: DomainEffectFactory<\n\t\t\t\t\tDomainOf<Resolve>,\n\t\t\t\t\tContract['commands'],\n\t\t\t\t\ttrue,\n\t\t\t\t\t[Returned] extends [never] ? never : (resolution: never, context: never) => Returned,\n\t\t\t\t\tNoInfer<CallbackError<Guard>>,\n\t\t\t\t\tNoInfer<CallbackRequirements<Guard>>\n\t\t\t\t>,\n\t\t\t) => Operations\n\t\t\tdefaults?: { guard?: (context: DomainOf<Resolve>) => Guard }\n\t\t} & HostCompatible<Resolve, Dependencies>,\n\t): ReturnType<\n\t\ttypeof createEffectCommand<\n\t\t\tResolve,\n\t\t\tAuditedOperations<\n\t\t\t\tBoundOperations<Operations, Contract['commands']>,\n\t\t\t\t(resolution: never, context: never) => Returned\n\t\t\t>,\n\t\t\tDependencies,\n\t\t\tGuard\n\t\t>\n\t>\n\tfunction command<\n\t\tResolve extends Resolver,\n\t\tconst Operations extends LooseRegistry<DomainOf<Resolve>>,\n\t\tReturned extends AuditValue,\n\t\tGuard,\n\t>(\n\t\tconfiguration: {\n\t\t\tcontext: Resolve\n\t\t\taudit: (resolution: DomainAuditInput<Operations>, context: DomainOf<Resolve>) => Returned\n\t\t\toperations: (\n\t\t\t\tdefine: SharedEffectFactory<DomainOf<Resolve>, Guard>,\n\t\t\t) => Operations & NoInfer<ValidatedEffectOperations<Operations>>\n\t\t\tdefaults?: { guard?: (context: DomainOf<Resolve>) => Guard }\n\t\t} & HostCompatible<Resolve, Dependencies>,\n\t): ReturnType<\n\t\ttypeof createEffectCommand<\n\t\t\tResolve,\n\t\t\tAuditedOperations<Operations, (resolution: never, context: never) => Returned>,\n\t\t\tDependencies,\n\t\t\tGuard\n\t\t>\n\t>\n\n\tfunction command<\n\t\tResolve extends Resolver,\n\t\tconst Operations extends Registry<DomainOf<Resolve>>,\n\t\tGuard = never,\n\t>(\n\t\tconfiguration: EffectCommandConfiguration<Resolve, Operations, Guard> &\n\t\t\tHostCompatible<Resolve, Dependencies>,\n\t): ReturnType<typeof createEffectCommand<Resolve, Operations, Dependencies, Guard>>\n\tfunction command(configuration: {\n\t\tcontext: Resolver\n\t\tcontract?: DomainContract\n\t\taudit?: (resolution: never, context: never) => AuditValue\n\t\toperations: (define: never) => Readonly<Record<string, object>>\n\t\tdefaults?: { guard?: (context: never) => unknown }\n\t}): unknown {\n\t\tconst buildOperations = () => {\n\t\t\tconst definitions = configuration.contract\n\t\t\t\t? domainEffectFactory(configuration.contract.commands ?? {}, true)\n\t\t\t\t: effectOperationFactory()\n\t\t\treturn snapshotOperations(\n\t\t\t\tconfiguration.operations(\n\t\t\t\t\t// SAFETY: the overload chooses this exact inline or contracted helper factory.\n\t\t\t\t\tdefinitions as never,\n\t\t\t\t),\n\t\t\t\tconfiguration.contract,\n\t\t\t\t'commands',\n\t\t\t\tconfiguration.audit,\n\t\t\t)\n\t\t}\n\n\t\t// SAFETY: overloads check callbacks and schemas; binding validates exact keys and snapshots runtime records.\n\t\treturn createEffectCommand({\n\t\t\t...configuration,\n\t\t\t...dependencies,\n\t\t\toperations: buildOperations,\n\t\t} as never)\n\t}\n\treturn command\n}\n\nfunction normalizeCommandResult<Value>(\n\tinvoke: () => Supported<Value>,\n): Effect.Effect<Value, unknown, unknown> {\n\t// SAFETY: selected definition helper checks the callback's normalized success against the schema input.\n\treturn normalizeEffect(invoke) as Effect.Effect<Value, unknown, unknown>\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"command.mjs","names":["effectLifecycle","Effect","createEffectCommand","getOperations","memoize","configuration","effectOperationFactory","internal","errorContract","kind","exec","operations","operation","definition","decodeEffectContract","input","command","decoded","classification","audit","observation","resolve","enterRequestScope","normalizeEffect","host","executeCommandLifecycle","CommandPermissionError","context","preparation","result","value","normalizeCommandResult","input_","enriched","auditFolded","entered","write","entry","Cause","cause","reportAuditWriteFailure","Exit","exit","observationFailure","reportFailure","registerLazyRegistry","selectOperation","owner","bindEffectCommand","buildOperations","definitions","domainEffectFactory","snapshotOperations","dependencies","invoke"],"sources":["../../../src/modules/effect/command.ts"],"sourcesContent":["import { memoize, registerLazyRegistry } from '../contracts/lazy'\n/* oxlint-disable anti-slop/no-unknown-returns, anti-slop/no-unsafe-dictionary-type -- Overload implementation storage is erased; public signatures retain concrete values, errors and services. */\nimport { Cause, Effect, Exit } from 'effect'\nimport type { AuditEntryInput } from '../../components/foundation/client'\nimport type { ContractSchema } from '../contracts/contract'\nimport {\n\tselectOperation,\n\ttype SelectedOperation,\n\ttype OperationPublicResult,\n} from '../contracts/exposure'\nimport { decodeEffectContract } from './schema'\n// oxlint-disable-next-line cvx/component-boundaries -- SAFETY: Internal optional adapter shares the Effect-free Foundation lifecycle and types without entering the Convex component deployment graph.\nimport {\n\tCommandPermissionError,\n\texecuteCommandLifecycle,\n\ttype ExecutionKind,\n\ttype LifecycleAlgebra,\n\ttype LifecyclePreparation,\n} from '../../components/foundation/modules/command/lifecycle'\n// oxlint-disable-next-line cvx/component-boundaries -- SAFETY: Internal optional adapter shares the Effect-free Foundation lifecycle and types without entering the Convex component deployment graph.\nimport type { Observability } from '../../components/foundation/modules/observability/observability'\nimport { normalizeEffect, observationFailure } from './normalize'\nimport { reportAuditWriteFailure, reportFailure, type FailureAuditOptions } from './failure-audit'\nimport {\n\tauditFolded,\n\tenterRequestScope,\n\ttype NestedAuditMode,\n\ttype RequestScope,\n\ttype ScopeState,\n} from './scope'\nimport {\n\teffectOperationFactory,\n\ttype CallbackError,\n\ttype CallbackRequirements,\n\ttype EffectValue,\n\ttype EffectOperationArgument,\n\ttype EffectOperationInput,\n\ttype EffectOperationHandlerResult,\n\ttype EffectPreparation,\n\ttype EffectOperationResult,\n\ttype EffectOperationError,\n\ttype EffectOperationRequirements,\n\ttype CheckedEffectOperation,\n\ttype UnwrappedDefaultError,\n\ttype UnwrappedDefaultRequirements,\n\ttype ValidatedEffectOperations,\n} from './operation'\n\nimport type { DomainContract, DomainCommandContract, DomainAuditInput } from '../contracts/domain'\nimport { snapshotOperations, type BoundOperations } from '../contracts/binding'\nimport {\n\tdomainEffectFactory,\n\ttype DomainEffectFactory,\n\ttype DomainEffectImplementations,\n\ttype ExactDomainOperations,\n\ttype AuditedOperations,\n\ttype SharedEffectFactory,\n\ttype AuditValue,\n} from './domain'\n\ntype Supported<Value> = Value | PromiseLike<Value> | Effect.Effect<Value, unknown, unknown>\n// Heterogeneous storage constraints preserve concrete callbacks in inferred definitions.\n// oxlint-disable-next-line anti-slop/no-unknown-returns -- Internal callback storage; selected definitions retain concrete return contracts.\ntype Callback = (...arguments_: never[]) => Supported<unknown>\n// oxlint-disable-next-line anti-slop/no-unknown-returns -- Resolver constraint captures its concrete return in Resolve; it never exposes this storage type at exec.\nexport type Resolver = (host: never) => Supported<unknown>\nexport type HostOf<Resolve extends Resolver> = Parameters<Resolve>[0]\nexport type DomainOf<Resolve extends Resolver> = EffectValue<ReturnType<Resolve>>\ntype Operation = {\n\tinput: ContractSchema\n\tresult: ContractSchema\n\tclassification: string\n\thandler: Callback\n\taudit: Callback\n\tguard?: Callback\n\tprepare?: Callback\n\tmiddleware?: Callback\n\tpermission?: string\n\taggregates?: readonly string[]\n\treplayResult?: ContractSchema\n}\nexport type Registry<Context> = Readonly<\n\tRecord<\n\t\tstring,\n\t\tPick<Operation, 'input' | 'result' | 'handler'> &\n\t\t\tPartial<Pick<Operation, 'classification' | 'audit'>> &\n\t\t\tCheckedEffectOperation<Context>\n\t>\n>\nexport type EffectCommandDependencies = {\n\tobservability: Observability\n\tcheckPermission?: (\n\t\thost: never,\n\t\tinput: { permission: string; operation: string },\n\t) => Supported<void>\n\t// oxlint-disable-next-line anti-slop/no-unknown-returns -- Audit writer storage; its concrete return/error/services remain in Dependencies.\n\twriteAudit: (host: never, entry: AuditEntryInput) => Supported<unknown>\n\t/** `fold` (default): an operation nested under an auditing operation leaves the audit to it. */\n\tnestedAudit?: NestedAuditMode\n\t/** Host-free sink for failed operations; see `FailureAuditOptions`. */\n\tauditFailure?: FailureAuditOptions\n}\nexport type HostParameter<Policy> = [Exclude<Policy, undefined>] extends [never]\n\t? unknown\n\t: // oxlint-disable-next-line anti-slop/no-unknown-returns -- Conditional parameter-extraction predicate, not an executable callback contract.\n\t\tExclude<Policy, undefined> extends (...arguments_: infer Arguments) => Supported<unknown>\n\t\t? Arguments extends []\n\t\t\t? unknown\n\t\t\t: Arguments[0]\n\t\t: unknown\ntype PolicyHost<Dependencies extends EffectCommandDependencies> = HostParameter<\n\tDependencies['writeAudit']\n> &\n\tHostParameter<Dependencies['checkPermission']>\ntype HostCompatible<Resolve extends Resolver, Dependencies extends EffectCommandDependencies> = [\n\tHostOf<Resolve>,\n] extends [PolicyHost<Dependencies>]\n\t? unknown\n\t: { context: never }\ntype Factory<Resolve extends Resolver, Guard> = ReturnType<\n\ttypeof effectOperationFactory<\n\t\tDomainOf<Resolve>,\n\t\tRecord<never, never>,\n\t\tNoInfer<CallbackError<Guard>>,\n\t\tNoInfer<CallbackRequirements<Guard>>\n\t>\n>\nexport type EffectCommandConfiguration<\n\tResolve extends Resolver,\n\tOperations extends Registry<DomainOf<Resolve>>,\n\tGuard,\n> = {\n\tcontext: Resolve\n\toperations: (\n\t\tdefine: Factory<Resolve, Guard>,\n\t) => Operations & NoInfer<ValidatedEffectOperations<Operations>>\n\tdefaults?: { guard?: (context: DomainOf<Resolve>) => Guard }\n}\ntype ErrorOf<Definition, Resolve, Dependencies, Guard> =\n\t| EffectOperationError<Definition>\n\t| CallbackError<Resolve | Dependencies[keyof Dependencies]>\n\t| UnwrappedDefaultError<Definition, Guard>\ntype RequirementsOf<Definition, Resolve, Dependencies, Guard> =\n\t| EffectOperationRequirements<Definition>\n\t| CallbackRequirements<Resolve | Dependencies[keyof Dependencies]>\n\t| UnwrappedDefaultRequirements<Definition, Guard>\ninterface EffectExecution extends ExecutionKind {\n\treadonly type: Effect.Effect<this['value'], unknown, unknown>\n}\nconst effectLifecycle: LifecycleAlgebra<EffectExecution> = {\n\tsucceed: Effect.succeed,\n\tsuspend: Effect.suspend,\n\tflatMap: Effect.flatMap,\n}\ntype RuntimeOperation<Context, Input, Raw, Result> = {\n\tinput: ContractSchema\n\tresult: ContractSchema\n\tclassification?: string\n\tpermission?: string\n\taggregates?: readonly string[]\n\treplayResult?: ContractSchema\n\thandler: (input: Input, context: Context) => Supported<Raw>\n\tguard?: (context: Context, input: Input) => Supported<void>\n\tprepare?: (\n\t\tcontext: Context,\n\t\tinput: Input,\n\t) => Supported<EffectPreparation<Result, unknown, unknown>>\n\taudit?: (\n\t\tresolution: { command: Input; result: Result },\n\t\tcontext: Context,\n\t\tscope: RequestScope | undefined,\n\t) => Supported<Omit<AuditEntryInput, 'classification'> | null>\n\tmiddleware?: (input: {\n\t\toperation: string\n\t\tcommand: Input\n\t\tinput: Input\n\t\tcontext: Context\n\t\tnext: (options?: { context?: object }) => Effect.Effect<Raw, unknown, unknown>\n\t}) => Supported<Raw>\n}\n\n/** Internal registry constructor: the public Foundation binds host policies once. */\nexport function createEffectCommand<\n\tResolve extends Resolver,\n\tconst Operations extends Registry<DomainOf<Resolve>>,\n\tconst Dependencies extends EffectCommandDependencies,\n\tGuard = never,\n>(\n\tconfiguration: EffectCommandConfiguration<Resolve, Operations, Guard> &\n\t\tDependencies &\n\t\tHostCompatible<Resolve, Dependencies>,\n) {\n\tconst getOperations = memoize<Operations>(() =>\n\t\tconfiguration.operations(\n\t\t\teffectOperationFactory<\n\t\t\t\tDomainOf<Resolve>,\n\t\t\t\tRecord<never, never>,\n\t\t\t\tCallbackError<Guard>,\n\t\t\t\tCallbackRequirements<Guard>\n\t\t\t>(),\n\t\t),\n\t)\n\t// SAFETY: the contracted overloads spread their checked `contract`, and the action binding its\n\t// `mode`, into this configuration.\n\tconst internal = configuration as {\n\t\tcontract?: Pick<DomainContract, 'errors'>\n\t\tmode?: 'action'\n\t}\n\tconst errorContract = internal.contract?.errors\n\tconst kind = internal.mode ?? 'command'\n\tconst exec = <Key extends Extract<keyof Operations, string>>(\n\t\toperation: Key,\n\t\tinput: EffectOperationArgument<Operations[Key]>,\n\t\thost: HostOf<Resolve>,\n\t): Effect.Effect<\n\t\tEffectOperationResult<Operations[Key]>,\n\t\tErrorOf<Operations[Key], Resolve, Dependencies, Guard>,\n\t\tRequirementsOf<Operations[Key], Resolve, Dependencies, Guard>\n\t> => {\n\t\tconst execution = Effect.suspend(() => {\n\t\t\tconst operations = getOperations()\n\t\t\tif (!Object.prototype.hasOwnProperty.call(operations, operation))\n\t\t\t\tthrow Error('The selected command operation is not configured')\n\t\t\t// SAFETY: this helper checked selected callbacks against their parsed schemas and domain context.\n\t\t\tconst definition = operations[operation] as Operations[Key] &\n\t\t\t\tRuntimeOperation<\n\t\t\t\t\tDomainOf<Resolve>,\n\t\t\t\t\tEffectOperationInput<Operations[Key]>,\n\t\t\t\t\tEffectOperationHandlerResult<Operations[Key]>,\n\t\t\t\t\tEffectOperationResult<Operations[Key]>\n\t\t\t\t>\n\t\t\t// SAFETY: selected command input was parsed by its own paired schema.\n\t\t\treturn Effect.flatMap(decodeEffectContract(definition.input, input), (decoded) => {\n\t\t\t\t// SAFETY: the selected operation's decoder owns this concrete domain input.\n\t\t\t\tconst command = decoded as EffectOperationInput<Operations[Key]>\n\t\t\t\tconst classification = definition.classification ?? kind\n\t\t\t\tconst audit = definition.audit\n\t\t\t\tconst observation = configuration.observability.start({ operation, classification })\n\t\t\t\t// SAFETY: resolver identity owns its concrete invocation return and host parameter.\n\t\t\t\tconst resolve = configuration.context as (host: HostOf<Resolve>) => ReturnType<Resolve>\n\t\t\t\tconst run = (entered: ScopeState | undefined, current: ScopeState) =>\n\t\t\t\t\tnormalizeEffect(() => resolve(host)).pipe(\n\t\t\t\t\t\tEffect.flatMap((context) => {\n\t\t\t\t\t\t\tconst lifecycle = executeCommandLifecycle<\n\t\t\t\t\t\t\t\tEffectExecution,\n\t\t\t\t\t\t\t\tDomainOf<Resolve>,\n\t\t\t\t\t\t\t\tEffectOperationInput<Operations[Key]>,\n\t\t\t\t\t\t\t\tEffectOperationHandlerResult<Operations[Key]>,\n\t\t\t\t\t\t\t\tEffectOperationResult<Operations[Key]>\n\t\t\t\t\t\t\t>(effectLifecycle, {\n\t\t\t\t\t\t\t\toperation,\n\t\t\t\t\t\t\t\tclassification,\n\t\t\t\t\t\t\t\tcontext,\n\t\t\t\t\t\t\t\tcommand,\n\t\t\t\t\t\t\t\tpermission:\n\t\t\t\t\t\t\t\t\tdefinition.permission === undefined\n\t\t\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t\t\t: () =>\n\t\t\t\t\t\t\t\t\t\t\t\tnormalizeEffect(() => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (!configuration.checkPermission)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tthrow new CommandPermissionError(operation)\n\t\t\t\t\t\t\t\t\t\t\t\t\t// SAFETY: HostCompatible proves this invocation satisfies the configured policy host.\n\t\t\t\t\t\t\t\t\t\t\t\t\treturn configuration.checkPermission(host as never, {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tpermission: definition.permission!,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\toperation,\n\t\t\t\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t\t\t\t}).pipe(Effect.asVoid),\n\t\t\t\t\t\t\t\tprepare: () =>\n\t\t\t\t\t\t\t\t\tnormalizeEffect(() => definition.prepare?.(context, command)).pipe(\n\t\t\t\t\t\t\t\t\t\tEffect.map((preparation) => {\n\t\t\t\t\t\t\t\t\t\t\tif (preparation?.kind !== 'execute') return preparation\n\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\tkind: 'execute',\n\t\t\t\t\t\t\t\t\t\t\t\tcomplete: preparation.complete\n\t\t\t\t\t\t\t\t\t\t\t\t\t? (result) =>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tnormalizeEffect(() => preparation.complete!(result)).pipe(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tEffect.asVoid,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\t\t\t\t\t} satisfies LifecyclePreparation<\n\t\t\t\t\t\t\t\t\t\t\t\tEffectExecution,\n\t\t\t\t\t\t\t\t\t\t\t\tEffectOperationResult<Operations[Key]>\n\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t// SAFETY: the selected final replay contract owns this result; operation types retain its E/R.\n\t\t\t\t\t\t\t\tdecodeReplay: (value) =>\n\t\t\t\t\t\t\t\t\tdecodeEffectContract(\n\t\t\t\t\t\t\t\t\t\tdefinition.replayResult ?? definition.result,\n\t\t\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t\t\t) as Effect.Effect<EffectOperationResult<Operations[Key]>, unknown, unknown>,\n\t\t\t\t\t\t\t\tmiddleware: definition.middleware\n\t\t\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t\t\t(input_) =>\n\t\t\t\t\t\t\t\t\t\t\t\tnormalizeCommandResult(() =>\n\t\t\t\t\t\t\t\t\t\t\t\t\tdefinition.middleware!({ ...input_, input: command }),\n\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t\t: [],\n\t\t\t\t\t\t\t\tdefaultGuard: (enriched) =>\n\t\t\t\t\t\t\t\t\tnormalizeEffect(() => configuration.defaults?.guard?.(enriched)).pipe(\n\t\t\t\t\t\t\t\t\t\tEffect.asVoid,\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\tguard: (enriched) =>\n\t\t\t\t\t\t\t\t\tnormalizeEffect(() => definition.guard?.(enriched, command)).pipe(Effect.asVoid),\n\t\t\t\t\t\t\t\trun: (enriched) =>\n\t\t\t\t\t\t\t\t\tnormalizeCommandResult(() => definition.handler(command, enriched)),\n\t\t\t\t\t\t\t\t// SAFETY: the selected contract owns the decoded result; the public operation retains decoder E/R.\n\t\t\t\t\t\t\t\tdecodeResult: (value) =>\n\t\t\t\t\t\t\t\t\tdecodeEffectContract(definition.result, value) as Effect.Effect<\n\t\t\t\t\t\t\t\t\t\tEffectOperationResult<Operations[Key]>,\n\t\t\t\t\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t\t\t\t\tunknown\n\t\t\t\t\t\t\t\t\t>,\n\t\t\t\t\t\t\t\taudit: (result) =>\n\t\t\t\t\t\t\t\t\t// Actions commit as they go, so a nested action's effects always need their own entry.\n\t\t\t\t\t\t\t\t\t!audit || (kind !== 'action' && auditFolded(configuration.nestedAudit, entered))\n\t\t\t\t\t\t\t\t\t\t? Effect.succeed(null)\n\t\t\t\t\t\t\t\t\t\t: normalizeEffect(() => audit({ command, result }, context, entered?.scope)),\n\t\t\t\t\t\t\t\twriteAudit: (entry) => {\n\t\t\t\t\t\t\t\t\tconst write = normalizeEffect(() => {\n\t\t\t\t\t\t\t\t\t\t// SAFETY: HostCompatible proves this invocation satisfies the configured writer host.\n\t\t\t\t\t\t\t\t\t\treturn configuration.writeAudit(host as never, entry)\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\treturn kind === 'action'\n\t\t\t\t\t\t\t\t\t\t? write.pipe(\n\t\t\t\t\t\t\t\t\t\t\t\tEffect.catchCause((cause) =>\n\t\t\t\t\t\t\t\t\t\t\t\t\tCause.hasInterrupts(cause)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t? Effect.failCause(cause)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t: reportAuditWriteFailure(configuration.auditFailure, {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\toperation,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tclassification,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tentered,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t: write\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\taggregates: definition.aggregates,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\treturn lifecycle\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tEffect.onExit((exit) =>\n\t\t\t\t\t\t\tEffect.sync(() => {\n\t\t\t\t\t\t\t\tif (Exit.isSuccess(exit)) observation.completed()\n\t\t\t\t\t\t\t\telse observation.failed(observationFailure(exit.cause))\n\t\t\t\t\t\t\t}).pipe(\n\t\t\t\t\t\t\t\tEffect.andThen(\n\t\t\t\t\t\t\t\t\treportFailure(configuration.auditFailure, exit, {\n\t\t\t\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\t\t\t\toperation,\n\t\t\t\t\t\t\t\t\t\tclassification,\n\t\t\t\t\t\t\t\t\t\tinput: command,\n\t\t\t\t\t\t\t\t\t\tcontract: errorContract,\n\t\t\t\t\t\t\t\t\t\tentered,\n\t\t\t\t\t\t\t\t\t\tcurrent,\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\treturn enterRequestScope(operation, audit !== undefined, run)\n\t\t\t})\n\t\t})\n\t\t// SAFETY: dispatch selects exactly this operation; callbacks preserve the concrete definition/policy E/R.\n\t\treturn execution as Effect.Effect<\n\t\t\tEffectOperationResult<Operations[Key]>,\n\t\t\tErrorOf<Operations[Key], Resolve, Dependencies, Guard>,\n\t\t\tRequirementsOf<Operations[Key], Resolve, Dependencies, Guard>\n\t\t>\n\t}\n\treturn registerLazyRegistry(\n\t\t{\n\t\t\t/** Bind invocation context without resolving it or running an operation. */\n\t\t\twithContext(context: HostOf<Resolve>) {\n\t\t\t\treturn {\n\t\t\t\t\texec: <Key extends Extract<keyof Operations, string>>(\n\t\t\t\t\t\toperation: Key,\n\t\t\t\t\t\tinput: EffectOperationArgument<Operations[Key]>,\n\t\t\t\t\t) => exec(operation, input, context),\n\t\t\t\t}\n\t\t\t},\n\t\t\texpose<const Owner extends symbol, const Key extends Extract<keyof Operations, string>>(\n\t\t\t\towner: Owner,\n\t\t\t\toperation: Key,\n\t\t\t): SelectedOperation<\n\t\t\t\tOwner,\n\t\t\t\tKey,\n\t\t\t\tOperations[Key]['input'],\n\t\t\t\tOperationPublicResult<Operations[Key]>\n\t\t\t> {\n\t\t\t\tconst operations = getOperations()\n\t\t\t\tif (!Object.hasOwn(operations, operation))\n\t\t\t\t\tthrow Error('The selected command operation is not configured')\n\t\t\t\treturn selectOperation(owner, 'mutation', operation, operations[operation])\n\t\t\t},\n\t\t\texec,\n\t\t},\n\t\tgetOperations,\n\t)\n}\n\n/** Bind trusted application policies without exposing a loose public command kernel. */\nexport function bindEffectCommand<const Dependencies extends EffectCommandDependencies>(\n\tdependencies: Dependencies,\n) {\n\ttype LooseRegistry<Context> = Readonly<\n\t\tRecord<\n\t\t\tstring,\n\t\t\tPick<Operation, 'input' | 'result' | 'classification' | 'handler'> &\n\t\t\t\tCheckedEffectOperation<Context>\n\t\t>\n\t>\n\n\tfunction command<\n\t\tResolve extends Resolver,\n\t\tconst Contract extends DomainContract & {\n\t\t\tcommands: Readonly<Record<string, DomainCommandContract>>\n\t\t},\n\t\tconst Operations extends DomainEffectImplementations<\n\t\t\tDomainOf<Resolve>,\n\t\t\tContract['commands'],\n\t\t\ttrue\n\t\t>,\n\t\tMode extends true,\n\t\tGuard = never,\n\t>(\n\t\tconfiguration: {\n\t\t\tcontract: Contract &\n\t\t\t\tNoInfer<\n\t\t\t\t\tOperations extends ExactDomainOperations<Operations, Contract['commands']> &\n\t\t\t\t\t\tValidatedEffectOperations<Operations>\n\t\t\t\t\t\t? unknown\n\t\t\t\t\t\t: never\n\t\t\t\t>\n\t\t\tcontext: Resolve\n\t\t\taudit?: never\n\t\t\toperations: (\n\t\t\t\tdefine: DomainEffectFactory<\n\t\t\t\t\tDomainOf<Resolve>,\n\t\t\t\t\tContract['commands'],\n\t\t\t\t\tMode,\n\t\t\t\t\tnever,\n\t\t\t\t\tNoInfer<CallbackError<Guard>>,\n\t\t\t\t\tNoInfer<CallbackRequirements<Guard>>,\n\t\t\t\t\tContract['errors']\n\t\t\t\t>,\n\t\t\t) => Operations\n\t\t\tdefaults?: { guard?: (context: DomainOf<Resolve>) => Guard }\n\t\t} & HostCompatible<Resolve, Dependencies>,\n\t): ReturnType<\n\t\ttypeof createEffectCommand<\n\t\t\tResolve,\n\t\t\tBoundOperations<Operations, Contract['commands']> & {\n\t\t\t\t[Key in keyof Contract['commands']]: {\n\t\t\t\t\tclassification: Contract['commands'][Key]['classification']\n\t\t\t\t\taudit: Operations[Key]['audit']\n\t\t\t\t}\n\t\t\t},\n\t\t\tDependencies,\n\t\t\tGuard\n\t\t>\n\t>\n\tfunction command<\n\t\tResolve extends Resolver,\n\t\tconst Contract extends DomainContract & {\n\t\t\tcommands: Readonly<Record<string, DomainCommandContract>>\n\t\t},\n\t\tconst Operations extends DomainEffectImplementations<DomainOf<Resolve>, Contract['commands']>,\n\t\tReturned extends AuditValue,\n\t\tGuard = never,\n\t>(\n\t\tconfiguration: {\n\t\t\tcontract: Contract &\n\t\t\t\tNoInfer<\n\t\t\t\t\tOperations extends ExactDomainOperations<Operations, Contract['commands']> &\n\t\t\t\t\t\tValidatedEffectOperations<Operations>\n\t\t\t\t\t\t? unknown\n\t\t\t\t\t\t: never\n\t\t\t\t>\n\t\t\tcontext: Resolve\n\t\t\taudit: (\n\t\t\t\tresolution: DomainAuditInput<Contract['commands']>,\n\t\t\t\tcontext: DomainOf<Resolve>,\n\t\t\t\tscope: RequestScope | undefined,\n\t\t\t) => Returned\n\t\t\toperations: (\n\t\t\t\tdefine: DomainEffectFactory<\n\t\t\t\t\tDomainOf<Resolve>,\n\t\t\t\t\tContract['commands'],\n\t\t\t\t\ttrue,\n\t\t\t\t\t[Returned] extends [never] ? never : (resolution: never, context: never) => Returned,\n\t\t\t\t\tNoInfer<CallbackError<Guard>>,\n\t\t\t\t\tNoInfer<CallbackRequirements<Guard>>,\n\t\t\t\t\tContract['errors']\n\t\t\t\t>,\n\t\t\t) => Operations\n\t\t\tdefaults?: { guard?: (context: DomainOf<Resolve>) => Guard }\n\t\t} & HostCompatible<Resolve, Dependencies>,\n\t): ReturnType<\n\t\ttypeof createEffectCommand<\n\t\t\tResolve,\n\t\t\tAuditedOperations<\n\t\t\t\tBoundOperations<Operations, Contract['commands']>,\n\t\t\t\t(resolution: never, context: never) => Returned\n\t\t\t>,\n\t\t\tDependencies,\n\t\t\tGuard\n\t\t>\n\t>\n\tfunction command<\n\t\tResolve extends Resolver,\n\t\tconst Operations extends LooseRegistry<DomainOf<Resolve>>,\n\t\tReturned extends AuditValue,\n\t\tGuard,\n\t>(\n\t\tconfiguration: {\n\t\t\tcontext: Resolve\n\t\t\taudit: (\n\t\t\t\tresolution: DomainAuditInput<Operations>,\n\t\t\t\tcontext: DomainOf<Resolve>,\n\t\t\t\tscope: RequestScope | undefined,\n\t\t\t) => Returned\n\t\t\toperations: (\n\t\t\t\tdefine: SharedEffectFactory<DomainOf<Resolve>, Guard>,\n\t\t\t) => Operations & NoInfer<ValidatedEffectOperations<Operations>>\n\t\t\tdefaults?: { guard?: (context: DomainOf<Resolve>) => Guard }\n\t\t} & HostCompatible<Resolve, Dependencies>,\n\t): ReturnType<\n\t\ttypeof createEffectCommand<\n\t\t\tResolve,\n\t\t\tAuditedOperations<Operations, (resolution: never, context: never) => Returned>,\n\t\t\tDependencies,\n\t\t\tGuard\n\t\t>\n\t>\n\n\tfunction command<\n\t\tResolve extends Resolver,\n\t\tconst Operations extends Registry<DomainOf<Resolve>>,\n\t\tGuard = never,\n\t>(\n\t\tconfiguration: EffectCommandConfiguration<Resolve, Operations, Guard> &\n\t\t\tHostCompatible<Resolve, Dependencies>,\n\t): ReturnType<typeof createEffectCommand<Resolve, Operations, Dependencies, Guard>>\n\tfunction command(configuration: {\n\t\tcontext: Resolver\n\t\tcontract?: DomainContract\n\t\taudit?: (resolution: never, context: never, scope: never) => AuditValue\n\t\toperations: (define: never) => Readonly<Record<string, object>>\n\t\tdefaults?: { guard?: (context: never) => unknown }\n\t}): unknown {\n\t\tconst buildOperations = () => {\n\t\t\tconst definitions = configuration.contract\n\t\t\t\t? domainEffectFactory(\n\t\t\t\t\t\tconfiguration.contract.commands ?? {},\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t\tconfiguration.contract.errors,\n\t\t\t\t\t)\n\t\t\t\t: effectOperationFactory()\n\t\t\treturn snapshotOperations(\n\t\t\t\tconfiguration.operations(\n\t\t\t\t\t// SAFETY: the overload chooses this exact inline or contracted helper factory.\n\t\t\t\t\tdefinitions as never,\n\t\t\t\t),\n\t\t\t\tconfiguration.contract,\n\t\t\t\t'commands',\n\t\t\t\tconfiguration.audit,\n\t\t\t)\n\t\t}\n\n\t\t// SAFETY: overloads check callbacks and schemas; binding validates exact keys and snapshots runtime records.\n\t\treturn createEffectCommand({\n\t\t\t...configuration,\n\t\t\t...dependencies,\n\t\t\toperations: buildOperations,\n\t\t} as never)\n\t}\n\treturn command\n}\n\nfunction normalizeCommandResult<Value>(\n\tinvoke: () => Supported<Value>,\n): Effect.Effect<Value, unknown, unknown> {\n\t// SAFETY: selected definition helper checks the callback's normalized success against the schema input.\n\treturn normalizeEffect(invoke) as Effect.Effect<Value, unknown, unknown>\n}\n"],"mappings":"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"}
@@ -1,5 +1,6 @@
1
1
  import { ContractSchema, LegacyParser, StandardSchema } from "../contracts/contract.mjs";
2
2
  import { Observability } from "../../components/foundation/modules/observability/observability.mjs";
3
+ import { RequestScope } from "./scope.mjs";
3
4
  import { CallbackError, CallbackRequirements, CheckedEffectDefinition, EffectMiddlewareInput, EffectOperationArgument, EffectOperationError, EffectOperationRequirements, EffectOperationResult, EffectValue, UnwrappedDefaultError, UnwrappedDefaultRequirements } from "./operation.mjs";
4
5
  import { EffectFoundation, EffectFoundationOptions } from "./foundation.mjs";
5
6
  import { PaginationOptions, PaginationResult } from "convex/server";
@@ -159,7 +160,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
159
160
  result: {
160
161
  id: Id<Table>;
161
162
  };
162
- }, context: EffectValue<ContextReturned>) => Effect.Effect<{
163
+ }, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => Effect.Effect<{
163
164
  operation: `${Table["tableName"]}.create`;
164
165
  actorId: string;
165
166
  aggregate: {
@@ -183,7 +184,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
183
184
  result: {
184
185
  id: Id<Table>;
185
186
  };
186
- }, context: EffectValue<ContextReturned>) => Effect.Effect<{
187
+ }, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => Effect.Effect<{
187
188
  operation: `${Table["tableName"]}.create`;
188
189
  actorId: string;
189
190
  aggregate: {
@@ -221,7 +222,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
221
222
  result: {
222
223
  ok: true;
223
224
  };
224
- }, context: EffectValue<ContextReturned>) => Effect.Effect<{
225
+ }, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => Effect.Effect<{
225
226
  operation: `${Table["tableName"]}.update`;
226
227
  actorId: string;
227
228
  aggregate: {
@@ -249,7 +250,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
249
250
  result: {
250
251
  ok: true;
251
252
  };
252
- }, context: EffectValue<ContextReturned>) => Effect.Effect<{
253
+ }, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => Effect.Effect<{
253
254
  operation: `${Table["tableName"]}.update`;
254
255
  actorId: string;
255
256
  aggregate: {
@@ -287,7 +288,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
287
288
  result: {
288
289
  ok: true;
289
290
  };
290
- }, context: EffectValue<ContextReturned>) => Effect.Effect<{
291
+ }, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => Effect.Effect<{
291
292
  operation: `${Table["tableName"]}.archive`;
292
293
  actorId: string;
293
294
  aggregate: {
@@ -315,7 +316,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
315
316
  result: {
316
317
  ok: true;
317
318
  };
318
- }, context: EffectValue<ContextReturned>) => Effect.Effect<{
319
+ }, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => Effect.Effect<{
319
320
  operation: `${Table["tableName"]}.archive`;
320
321
  actorId: string;
321
322
  aggregate: {
@@ -342,7 +343,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
342
343
  audit?: ((resolution: {
343
344
  command: z.infer<Table["tools"]["id"]>;
344
345
  result: z.infer<Table["publicDto"]> | null;
345
- }, context: EffectValue<ContextReturned>) => never) | undefined;
346
+ }, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => never) | undefined;
346
347
  } & {
347
348
  middleware?: ((input: EffectMiddlewareInput<EffectValue<ContextReturned>, z.infer<Table["tools"]["id"]>, z.core.input<Table["publicDto"]> | null, Record<never, never>, CallbackError<CheckId> | CallbackError<Get> | CallbackError<GetGuard> | CallbackError<Policy> | CallbackError<Project> | CallbackError<z.core.input<Table["publicDto"]>>, CallbackRequirements<CheckId> | CallbackRequirements<Get> | CallbackRequirements<GetGuard> | CallbackRequirements<Policy> | CallbackRequirements<Project> | CallbackRequirements<z.core.input<Table["publicDto"]>>>) => never) | undefined;
348
349
  } & {
@@ -442,7 +443,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
442
443
  pageStatus?: "SplitRecommended" | "SplitRequired" | null | undefined;
443
444
  completeness?: "byte-budget" | "complete" | "native-limit" | "result-cap" | "row-budget" | undefined;
444
445
  };
445
- }, context: EffectValue<ContextReturned>) => never) | undefined;
446
+ }, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => never) | undefined;
446
447
  } & {
447
448
  middleware?: ((input: EffectMiddlewareInput<EffectValue<ContextReturned>, {
448
449
  numItems: number;
@@ -498,7 +499,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
498
499
  result: {
499
500
  id: Id<Table>;
500
501
  };
501
- }, context: EffectValue<ContextReturned>) => Effect.Effect<{
502
+ }, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => Effect.Effect<{
502
503
  operation: `${Table["tableName"]}.create`;
503
504
  actorId: string;
504
505
  aggregate: {
@@ -522,7 +523,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
522
523
  result: {
523
524
  id: Id<Table>;
524
525
  };
525
- }, context: EffectValue<ContextReturned>) => Effect.Effect<{
526
+ }, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => Effect.Effect<{
526
527
  operation: `${Table["tableName"]}.create`;
527
528
  actorId: string;
528
529
  aggregate: {
@@ -560,7 +561,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
560
561
  result: {
561
562
  ok: true;
562
563
  };
563
- }, context: EffectValue<ContextReturned>) => Effect.Effect<{
564
+ }, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => Effect.Effect<{
564
565
  operation: `${Table["tableName"]}.update`;
565
566
  actorId: string;
566
567
  aggregate: {
@@ -588,7 +589,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
588
589
  result: {
589
590
  ok: true;
590
591
  };
591
- }, context: EffectValue<ContextReturned>) => Effect.Effect<{
592
+ }, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => Effect.Effect<{
592
593
  operation: `${Table["tableName"]}.update`;
593
594
  actorId: string;
594
595
  aggregate: {
@@ -626,7 +627,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
626
627
  result: {
627
628
  ok: true;
628
629
  };
629
- }, context: EffectValue<ContextReturned>) => Effect.Effect<{
630
+ }, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => Effect.Effect<{
630
631
  operation: `${Table["tableName"]}.archive`;
631
632
  actorId: string;
632
633
  aggregate: {
@@ -654,7 +655,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
654
655
  result: {
655
656
  ok: true;
656
657
  };
657
- }, context: EffectValue<ContextReturned>) => Effect.Effect<{
658
+ }, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => Effect.Effect<{
658
659
  operation: `${Table["tableName"]}.archive`;
659
660
  actorId: string;
660
661
  aggregate: {
@@ -681,7 +682,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
681
682
  audit?: ((resolution: {
682
683
  command: z.infer<Table["tools"]["id"]>;
683
684
  result: z.infer<Table["publicDto"]> | null;
684
- }, context: EffectValue<ContextReturned>) => never) | undefined;
685
+ }, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => never) | undefined;
685
686
  } & {
686
687
  middleware?: ((input: EffectMiddlewareInput<EffectValue<ContextReturned>, z.infer<Table["tools"]["id"]>, z.core.input<Table["publicDto"]> | null, Record<never, never>, CallbackError<CheckId> | CallbackError<Get> | CallbackError<GetGuard> | CallbackError<Policy> | CallbackError<Project> | CallbackError<z.core.input<Table["publicDto"]>>, CallbackRequirements<CheckId> | CallbackRequirements<Get> | CallbackRequirements<GetGuard> | CallbackRequirements<Policy> | CallbackRequirements<Project> | CallbackRequirements<z.core.input<Table["publicDto"]>>>) => never) | undefined;
687
688
  } & {
@@ -781,7 +782,7 @@ export declare function createEffectCrud<const Options extends EffectFoundationO
781
782
  pageStatus?: "SplitRecommended" | "SplitRequired" | null | undefined;
782
783
  completeness?: "byte-budget" | "complete" | "native-limit" | "result-cap" | "row-budget" | undefined;
783
784
  };
784
- }, context: EffectValue<ContextReturned>) => never) | undefined;
785
+ }, context: EffectValue<ContextReturned>, scope: RequestScope | undefined) => never) | undefined;
785
786
  } & {
786
787
  middleware?: ((input: EffectMiddlewareInput<EffectValue<ContextReturned>, {
787
788
  numItems: number;
@@ -1,8 +1,11 @@
1
1
  import { ContractInput, ContractOutput, ContractSchema } from "../contracts/contract.mjs";
2
+ import { ErrorContract } from "../contracts/errors.mjs";
2
3
  import { AuditEntryInput } from "../../components/foundation/client.mjs";
3
4
  import { DomainOperationContract, ExactOperationKeys } from "../contracts/domain.mjs";
5
+ import { RequestScope } from "./scope.mjs";
4
6
  import { CallbackError, CallbackRequirements, CheckedEffectDefinition, CheckedEffectOperation, EffectPreparation, OperationDefinition, effectOperationFactory } from "./operation.mjs";
5
7
  import { DeclaredSchemas } from "../contracts/binding.mjs";
8
+ import { EffectErrors } from "./failures.mjs";
6
9
  import { Effect } from "effect";
7
10
  //#region src/modules/effect/domain.d.ts
8
11
  type Supported<A> = A | PromiseLike<A> | Effect.Effect<A, unknown, unknown>;
@@ -22,7 +25,7 @@ type Forbidden = {
22
25
  type AuditCallback<Context, Entry extends DomainOperationContract, Value> = (resolution: {
23
26
  command: ContractOutput<Entry['input']>;
24
27
  result: ContractOutput<Entry['result']>;
25
- }, context: Context) => Value;
28
+ }, context: Context, scope: RequestScope | undefined) => Value;
26
29
  export type SelectedAudit<Definition, Default> = Definition extends {
27
30
  audit: infer Override;
28
31
  } ? Override : 'audit' extends keyof Definition ? Exclude<Definition['audit' & keyof Definition], undefined> | Default : Default;
@@ -30,17 +33,23 @@ export type AuditedOperations<Operations, Default> = { [Key in keyof Operations]
30
33
  audit: SelectedAudit<Operations[Key], Default>;
31
34
  }; };
32
35
  export type ExactDomainOperations<Operations, Contracts> = ExactOperationKeys<Operations, Contracts> & { [Key in keyof Operations]: Operations[Key] extends BoundKey<Key> ? Operations[Key] : never; };
33
- type Helper<Context, Entry extends DomainOperationContract, Key, Command extends boolean, Default, BaseError, BaseRequirements> = <Handler extends Supported<ContractInput<Entry['result']>>, Guard extends Supported<void> = never, Preparation extends Supported<EffectPreparation<ContractOutput<Entry['result']>, unknown, unknown>> = never, const Aggregates extends readonly string[] = readonly string[], AuditReturned extends Supported<Audit> = never, Middleware extends Supported<ContractInput<Entry['result']>> = never, const Metadata extends object = Record<never, never>, const Definition extends object = object>(implementation: Definition & Forbidden & Omit<OperationDefinition<Context, Entry['input'], Entry['result'], Record<never, never>, Aggregates, Handler, Guard, Preparation, AuditReturned, Middleware, Metadata, BaseError, BaseRequirements, ContractSchema, never>, 'input' | 'result' | 'classification' | 'replayResult' | 'wire'> & (Command extends true ? [Default] extends [never] ? {
36
+ type Helper<Context, Entry extends DomainOperationContract, Key, Command extends boolean | 'action', Default, BaseError, BaseRequirements> = <Handler extends Supported<ContractInput<Entry['result']>>, Guard extends Supported<void> = never, Preparation extends Supported<EffectPreparation<ContractOutput<Entry['result']>, unknown, unknown>> = never, const Aggregates extends readonly string[] = readonly string[], AuditReturned extends Supported<Audit> = never, Middleware extends Supported<ContractInput<Entry['result']>> = never, const Metadata extends object = Record<never, never>, const Definition extends object = object>(implementation: Definition & Forbidden & Omit<OperationDefinition<Context, Entry['input'], Entry['result'], Record<never, never>, Aggregates, Handler, Guard, Preparation, AuditReturned, Middleware, Metadata, BaseError, BaseRequirements, ContractSchema, never>, 'input' | 'result' | 'classification' | 'replayResult' | 'wire'> & (Command extends true ? [Default] extends [never] ? {
34
37
  audit: AuditCallback<Context, Entry, AuditReturned>;
35
- } : {} : {
38
+ } : {} : Command extends 'action' ? {
39
+ prepare?: never;
40
+ permission?: never;
41
+ } : {
36
42
  audit?: never;
37
43
  prepare?: never;
38
44
  aggregates?: never;
39
45
  })) => DeclaredSchemas<Entry> & CheckedEffectDefinition<Context, Schemas<Entry> & Definition & BoundKey<Key>, BaseError, BaseRequirements>;
40
- type HandlerArguments<Options, Command extends boolean, Default, RequiredAudit> = Command extends true ? [Default] extends [never] ? [options: Options & RequiredAudit] : [options?: Options] : [options?: Options];
41
- type HandlerHelper<Context, Entries extends Readonly<Record<string, DomainOperationContract>>, Command extends boolean, Default, BaseError, BaseRequirements> = <const Input extends ContractSchema, const Result extends ContractSchema, Key extends keyof Entries, Handler extends Supported<ContractInput<Result>>, Guard extends Supported<void> = never, Preparation extends Supported<EffectPreparation<ContractOutput<Result>, unknown, unknown>> = never, const Aggregates extends readonly string[] = readonly string[], AuditReturned extends Supported<Audit> = never, Middleware extends Supported<ContractInput<Result>> = never, const Metadata extends object = Record<never, never>, const Definition extends object = object>(handler: (input: ContractOutput<Input>, context: Context) => Handler, ...options: HandlerArguments<Definition & Forbidden & {
46
+ type HandlerArguments<Options, Command extends boolean | 'action', Default, RequiredAudit> = Command extends true ? [Default] extends [never] ? [options: Options & RequiredAudit] : [options?: Options] : [options?: Options];
47
+ type HandlerHelper<Context, Entries extends Readonly<Record<string, DomainOperationContract>>, Command extends boolean | 'action', Default, BaseError, BaseRequirements> = <const Input extends ContractSchema, const Result extends ContractSchema, Key extends keyof Entries, Handler extends Supported<ContractInput<Result>>, Guard extends Supported<void> = never, Preparation extends Supported<EffectPreparation<ContractOutput<Result>, unknown, unknown>> = never, const Aggregates extends readonly string[] = readonly string[], AuditReturned extends Supported<Audit> = never, Middleware extends Supported<ContractInput<Result>> = never, const Metadata extends object = Record<never, never>, const Definition extends object = object>(handler: (input: ContractOutput<Input>, context: Context) => Handler, ...options: HandlerArguments<Definition & Forbidden & {
42
48
  handler?: never;
43
- } & Omit<OperationDefinition<Context, Input, Result, Record<never, never>, Aggregates, Handler, Guard, Preparation, AuditReturned, Middleware, Metadata, BaseError, BaseRequirements, ContractSchema, never>, 'handler' | 'input' | 'result' | 'classification' | 'replayResult' | 'wire'> & (Command extends true ? {} : {
49
+ } & Omit<OperationDefinition<Context, Input, Result, Record<never, never>, Aggregates, Handler, Guard, Preparation, AuditReturned, Middleware, Metadata, BaseError, BaseRequirements, ContractSchema, never>, 'handler' | 'input' | 'result' | 'classification' | 'replayResult' | 'wire'> & (Command extends true ? {} : Command extends 'action' ? {
50
+ prepare?: never;
51
+ permission?: never;
52
+ } : {
44
53
  audit?: never;
45
54
  prepare?: never;
46
55
  aggregates?: never;
@@ -57,7 +66,7 @@ type HandlerHelper<Context, Entries extends Readonly<Record<string, DomainOperat
57
66
  } & NoInfer<Definition> & BoundKey<Key> & CheckedEffectDefinition<Context, NoInfer<Definition> & {
58
67
  handler: (input: ContractOutput<Input>, context: Context) => Handler;
59
68
  } & BoundKey<Key>, BaseError, BaseRequirements>;
60
- export type DomainEffectFactory<Context, Entries extends Readonly<Record<string, DomainOperationContract>>, Command extends boolean, Default = never, BaseError = never, BaseRequirements = never> = { [Kind in Command extends true ? 'command' : 'query']: { readonly [Key in keyof Entries]: Helper<Context, Entries[Key], Key, Command, Default, BaseError, BaseRequirements>; } & {
69
+ export type DomainEffectFactory<Context, Entries extends Readonly<Record<string, DomainOperationContract>>, Command extends boolean | 'action', Default = never, BaseError = never, BaseRequirements = never, Errors = never> = ContractErrorHelpers<Errors> & { [Kind in Command extends true ? 'command' : Command extends 'action' ? 'action' : 'query']: { readonly [Key in keyof Entries]: Helper<Context, Entries[Key], Key, Command, Default, BaseError, BaseRequirements>; } & {
61
70
  handler: HandlerHelper<Context, Entries, Command, Default, BaseError, BaseRequirements>;
62
71
  }; };
63
72
  export type DomainEffectImplementations<Context, Entries extends Readonly<Record<string, DomainOperationContract>>, Required extends boolean = false> = { [Key in keyof Entries]: DeclaredSchemas<Pick<Entries[Key], 'input' | 'result'>> & BoundKey<Key> & CheckedEffectOperation<Context> & {
@@ -65,8 +74,10 @@ export type DomainEffectImplementations<Context, Entries extends Readonly<Record
65
74
  } & (Required extends true ? {
66
75
  audit: AuditCallback<Context, Entries[Key], Supported<Audit>>;
67
76
  } : {}); };
68
- export declare function domainEffectFactory<Context, Entries extends Readonly<Record<string, DomainOperationContract>>, Command extends boolean, Default, Guard>(entries: Entries, command: Command): DomainEffectFactory<Context, Entries, Command, Default, CallbackError<Guard>, CallbackRequirements<Guard>>;
77
+ export declare function domainEffectFactory<Context, Entries extends Readonly<Record<string, DomainOperationContract>>, Command extends boolean | 'action', Default, Guard>(entries: Entries, command: Command, errors?: object): DomainEffectFactory<Context, Entries, Command, Default, CallbackError<Guard>, CallbackRequirements<Guard>>;
69
78
  export type SharedEffectFactory<Context, Guard> = ReturnType<typeof effectOperationFactory<Context, Record<never, never>, NoInfer<CallbackError<Guard>>, NoInfer<CallbackRequirements<Guard>>, false>>;
70
79
  export type AuditValue = Supported<Audit>;
80
+ /** A contract that can create its declared errors also gives the factory `fail` and `attempt`. */
81
+ type ContractErrorHelpers<Errors> = [Errors] extends [never] ? {} : Errors extends ErrorContract<infer Definitions> ? EffectErrors<Definitions> : {};
71
82
  //#endregion
72
83
  //# sourceMappingURL=domain.d.mts.map
@@ -1,2 +1,2 @@
1
- import{domainHelpers as e}from"../contracts/binding.mjs";function t(t,n){let r=e(t);return{[n?`command`:`query`]:r}}export{t as domainEffectFactory};
1
+ import{domainHelpers as e}from"../contracts/binding.mjs";import{effectErrors as t}from"./failures.mjs";function n(n,i,a){let o=e(n),s={[i===`action`?`action`:i?`command`:`query`]:o};return a&&r(a)&&Object.assign(s,t(a)),s}function r(e){let t=e;return[t.create,t.project,t.decode].every(e=>e instanceof Function)}export{n as domainEffectFactory};
2
2
  //# sourceMappingURL=domain.mjs.map
@@ -1 +1 @@
1
- {"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"}
1
+ {"version":3,"file":"domain.mjs","names":["domainEffectFactory","helpers","domainHelpers","entries","factory","command","errors","isFullErrorContract","effectErrors","candidate","member"],"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 type { ErrorContract, ErrorDefinitions } from '../contracts/errors'\nimport { effectErrors, type EffectErrors } from './failures'\nimport {\n\teffectOperationFactory,\n\ttype OperationDefinition,\n\ttype CheckedEffectDefinition,\n\ttype CheckedEffectOperation,\n\ttype CallbackError,\n\ttype CallbackRequirements,\n\ttype EffectPreparation,\n} from './operation'\nimport type { RequestScope } from './scope'\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\tscope: RequestScope | undefined,\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 | 'action',\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: Command extends 'action'\n\t\t\t\t? { prepare?: never; permission?: never }\n\t\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 | 'action',\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 | 'action',\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\n\t\t\t\t? {}\n\t\t\t\t: Command extends 'action'\n\t\t\t\t\t? { prepare?: never; permission?: never }\n\t\t\t\t\t: { 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 | 'action',\n\tDefault = never,\n\tBaseError = never,\n\tBaseRequirements = never,\n\tErrors = never,\n> = ContractErrorHelpers<Errors> & {\n\t[Kind in Command extends true ? 'command' : Command extends 'action' ? 'action' : '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 | 'action',\n\tDefault,\n\tGuard,\n>(\n\tentries: Entries,\n\tcommand: Command,\n\terrors?: object,\n): DomainEffectFactory<\n\tContext,\n\tEntries,\n\tCommand,\n\tDefault,\n\tCallbackError<Guard>,\n\tCallbackRequirements<Guard>\n> {\n\tconst helpers = domainHelpers(entries)\n\tconst factory = { [command === 'action' ? 'action' : command ? 'command' : 'query']: helpers }\n\tif (errors && isFullErrorContract(errors)) Object.assign(factory, effectErrors(errors))\n\t// SAFETY: helper signatures check callbacks; registration pairs drafts with their declarations.\n\treturn factory 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\n/** A contract that can create its declared errors also gives the factory `fail` and `attempt`. */\ntype ContractErrorHelpers<Errors> = [Errors] extends [never]\n\t? {}\n\t: Errors extends ErrorContract<infer Definitions>\n\t\t? EffectErrors<Definitions>\n\t\t: {}\n\nfunction isFullErrorContract(\n\terrors: object,\n): errors is Pick<ErrorContract<ErrorDefinitions>, 'create' | 'project' | 'decode'> {\n\t// SAFETY: only the presence of the three callable members is read here.\n\tconst candidate = errors as Partial<Record<'create' | 'project' | 'decode', Function>>\n\treturn [candidate.create, candidate.project, candidate.decode].every(\n\t\t(member) => member instanceof Function,\n\t)\n}\n"],"mappings":"uGAmOA,SAAgBA,EAOf,EACA,EACA,EAQC,CACD,IAAMC,EAAUC,EAAcC,CAAO,EAC/BC,EAAU,EAAGC,IAAY,SAAW,SAAWA,EAAU,UAAY,SAAUJ,CAAQ,EAG7F,OAFIK,GAAUC,EAAoBD,CAAM,GAAG,OAAO,OAAOF,EAASI,EAAaF,CAAM,CAAC,EAE/EF,CAQR,CAoBA,SAASG,EACR,EACmF,CAEnF,IAAME,EAAYH,EAClB,MAAO,CAACG,EAAU,OAAQA,EAAU,QAASA,EAAU,MAAM,CAAC,CAAC,MAC7D,GAAWC,aAAkB,QAC/B,CACD"}
@@ -1,7 +1,11 @@
1
1
  import { DecodedFailure, ErrorContract, ErrorDefinitions } from "../contracts/errors.mjs";
2
2
  import { Cause } from "effect";
3
3
  //#region src/modules/effect/errors.d.ts
4
- /** Inspect the whole Cause; cleanup defects and other composite reasons cannot become expected data. */
4
+ /**
5
+ * Inspect the whole Cause; cleanup defects and other composite reasons cannot become expected data.
6
+ * A single defect projects only when the contract itself recognizes it, such as a declared error
7
+ * that a handler threw instead of failing with; any other defect stays an UnknownFailure.
8
+ */
5
9
  export declare function projectErrorCause<Definitions extends ErrorDefinitions>(contract: Pick<ErrorContract<Definitions>, 'project'>, cause: Cause.Cause<unknown>): DecodedFailure<Definitions>;
6
10
  //#endregion
7
11
  //# sourceMappingURL=errors.d.mts.map
@@ -1,2 +1,2 @@
1
- import{Cause as e}from"effect";function t(t,n){if(n.reasons.length!==1)return{_tag:`UnknownFailure`,version:1};let r=n.reasons[0];return e.isFailReason(r)?t.project(r.error):{_tag:`UnknownFailure`,version:1}}export{t as projectErrorCause};
1
+ import{Cause as e}from"effect";function t(t,n){if(n.reasons.length!==1)return{_tag:`UnknownFailure`,version:1};let r=n.reasons[0];return e.isFailReason(r)?t.project(r.error):e.isDieReason(r)?t.project(r.defect):{_tag:`UnknownFailure`,version:1}}export{t as projectErrorCause};
2
2
  //# sourceMappingURL=errors.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.mjs","names":["projectErrorCause","cause","reason","Cause","contract"],"sources":["../../../src/modules/effect/errors.ts"],"sourcesContent":["import { Cause } from 'effect'\nimport type { DecodedFailure, ErrorContract, ErrorDefinitions } from '../contracts/errors'\n\n/** Inspect the whole Cause; cleanup defects and other composite reasons cannot become expected data. */\nexport function projectErrorCause<Definitions extends ErrorDefinitions>(\n\tcontract: Pick<ErrorContract<Definitions>, 'project'>,\n\tcause: Cause.Cause<unknown>,\n): DecodedFailure<Definitions> {\n\tif (cause.reasons.length !== 1) return { _tag: 'UnknownFailure', version: 1 }\n\tconst reason = cause.reasons[0]\n\treturn Cause.isFailReason(reason)\n\t\t? contract.project(reason.error)\n\t\t: { _tag: 'UnknownFailure', version: 1 }\n}\n"],"mappings":"+BAIA,SAAgBA,EACf,EACA,EAC8B,CAC9B,GAAIC,EAAM,QAAQ,SAAW,EAAG,MAAO,CAAE,KAAM,iBAAkB,QAAS,CAAE,EAC5E,IAAMC,EAASD,EAAM,QAAQ,GAC7B,OAAOE,EAAM,aAAaD,CAAM,EAC7BE,EAAS,QAAQF,EAAO,KAAK,EAC7B,CAAE,KAAM,iBAAkB,QAAS,CAAE,CACzC"}
1
+ {"version":3,"file":"errors.mjs","names":["projectErrorCause","cause","reason","Cause","contract"],"sources":["../../../src/modules/effect/errors.ts"],"sourcesContent":["import { Cause } from 'effect'\nimport type { DecodedFailure, ErrorContract, ErrorDefinitions } from '../contracts/errors'\n\n/**\n * Inspect the whole Cause; cleanup defects and other composite reasons cannot become expected data.\n * A single defect projects only when the contract itself recognizes it, such as a declared error\n * that a handler threw instead of failing with; any other defect stays an UnknownFailure.\n */\nexport function projectErrorCause<Definitions extends ErrorDefinitions>(\n\tcontract: Pick<ErrorContract<Definitions>, 'project'>,\n\tcause: Cause.Cause<unknown>,\n): DecodedFailure<Definitions> {\n\tif (cause.reasons.length !== 1) return { _tag: 'UnknownFailure', version: 1 }\n\tconst reason = cause.reasons[0]\n\tif (Cause.isFailReason(reason)) return contract.project(reason.error)\n\tif (Cause.isDieReason(reason)) return contract.project(reason.defect)\n\treturn { _tag: 'UnknownFailure', version: 1 }\n}\n"],"mappings":"+BAQA,SAAgBA,EACf,EACA,EAC8B,CAC9B,GAAIC,EAAM,QAAQ,SAAW,EAAG,MAAO,CAAE,KAAM,iBAAkB,QAAS,CAAE,EAC5E,IAAMC,EAASD,EAAM,QAAQ,GAG7B,OAFIE,EAAM,aAAaD,CAAM,EAAUE,EAAS,QAAQF,EAAO,KAAK,EAChEC,EAAM,YAAYD,CAAM,EAAUE,EAAS,QAAQF,EAAO,MAAM,EAC7D,CAAE,KAAM,iBAAkB,QAAS,CAAE,CAC7C"}
@@ -0,0 +1,48 @@
1
+ import { ErrorContract, ErrorDefinitions } from "../contracts/errors.mjs";
2
+ import { ScopeState } from "./scope.mjs";
3
+ import { Value } from "convex/values";
4
+ import { Effect, Exit } from "effect";
5
+ //#region src/modules/effect/failure-audit.d.ts
6
+ type JsonRecord = Readonly<Record<string, Value>>;
7
+ type ProjectingContract = Pick<ErrorContract<ErrorDefinitions>, 'project'>;
8
+ /** One failed operation, without raw input, unredacted details, defect messages or stacks. */
9
+ export type FailureAuditEntry = Readonly<{
10
+ kind: 'command' | 'query' | 'action';
11
+ operation: string;
12
+ classification: string;
13
+ /** The declared contract code, or `UNKNOWN_FAILURE` when no contract recognizes the failure. */
14
+ errorCode: string;
15
+ declared: boolean;
16
+ /** The outermost operation of the request and this operation's nesting depth (0 for the root). */
17
+ root: string;
18
+ depth: number;
19
+ /** Present only when the `details` redactor returned a plain JSON record. */
20
+ details?: JsonRecord;
21
+ /** Present only when the `input` redactor returned a plain JSON record. */
22
+ input?: JsonRecord;
23
+ }>;
24
+ /**
25
+ * Host-free failure sink. A failed mutation rolls back every write it made, so failure
26
+ * entries go to logs or log streams; inside queries and mutations `emit` has no `fetch`.
27
+ */
28
+ export type FailureAuditOptions = Readonly<{
29
+ emit: (entry: FailureAuditEntry) => void | PromiseLike<void>;
30
+ /** Projects failures that the operation's own registry contract does not recognize. */
31
+ errors?: ProjectingContract;
32
+ details?: (details: unknown, errorCode: string, operation: string) => JsonRecord | undefined;
33
+ input?: (input: unknown, operation: string) => JsonRecord | undefined;
34
+ }>;
35
+ type FailureReport = Readonly<{
36
+ kind: FailureAuditEntry['kind'];
37
+ operation: string;
38
+ classification: string;
39
+ input: unknown;
40
+ contract?: ProjectingContract;
41
+ entered: ScopeState | undefined;
42
+ current: ScopeState;
43
+ }>;
44
+ /** Report a failed exit once per failure value in the request; never changes the original outcome. */
45
+ export declare function reportFailure(options: FailureAuditOptions | undefined, exit: Exit.Exit<unknown, unknown>, report: FailureReport): Effect.Effect<void>;
46
+ export declare function reportAuditWriteFailure(options: FailureAuditOptions | undefined, report: Pick<FailureReport, 'operation' | 'classification' | 'entered'>): Effect.Effect<void>;
47
+ //#endregion
48
+ //# sourceMappingURL=failure-audit.d.mts.map
@@ -0,0 +1,2 @@
1
+ import{isRecord as e}from"../contracts/errors.mjs";import{projectErrorCause as t}from"./errors.mjs";import{observationFailure as n}from"./normalize.mjs";import{Cause as r,Effect as i,Exit as a}from"effect";function o(e,o,s){if(!e||a.isSuccess(o))return i.void;let d=o.cause;return!r.hasFails(d)&&!r.hasDies(d)?i.void:c(e,()=>{let r=n(d);if(r instanceof Object){if(s.current.reported.has(r))return;s.current.reported.add(r)}let i=s.contract?t(s.contract,d):{_tag:`UnknownFailure`,version:1};i._tag!==`DeclaredFailure`&&e.errors&&(i=t(e.errors,d));let a=i._tag===`DeclaredFailure`?i:void 0,o=a?.code??`UNKNOWN_FAILURE`,c=a&&e.details?u(()=>e.details(a.details,o,s.operation)):void 0,f=e.input?u(()=>e.input(s.input,s.operation)):void 0;return Object.assign({kind:s.kind,operation:s.operation,classification:s.classification,errorCode:o,declared:a!==void 0,...l(s)},c===void 0?void 0:{details:c},f===void 0?void 0:{input:f})})}function s(e,t){return e?c(e,()=>({kind:`action`,operation:t.operation,classification:t.classification,errorCode:`ACTION_AUDIT_WRITE_FAILED`,declared:!1,...l(t)})):i.sync(()=>{try{console.error(JSON.stringify({event:`action.audit_write_failed`,errorCode:`ACTION_AUDIT_WRITE_FAILED`,operation:t.operation,classification:t.classification}))}catch{}})}function c(e,t){return i.tryPromise({try:async()=>{let n=t();n&&await e.emit(Object.freeze(n))},catch:()=>void 0}).pipe(i.ignore)}function l(e){return{root:e.entered?.scope.root??e.operation,depth:e.entered?.scope.depth??0}}function u(t){try{let n=t();return e(n)?JSON.parse(JSON.stringify(n)):void 0}catch{return}}export{s as reportAuditWriteFailure,o as reportFailure};
2
+ //# sourceMappingURL=failure-audit.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"failure-audit.mjs","names":["reportFailure","options","Exit","exit","Effect","cause","Cause","emitQuietly","failure","observationFailure","report","projected","projectErrorCause","declaredFailure","errorCode","details","redact","input","position","reportAuditWriteFailure","entry","build","value","read","isRecord"],"sources":["../../../src/modules/effect/failure-audit.ts"],"sourcesContent":["import { Cause, Effect, Exit } from 'effect'\nimport type { Value } from 'convex/values'\nimport { isRecord, type ErrorContract, type ErrorDefinitions } from '../contracts/errors'\nimport { projectErrorCause } from './errors'\nimport { observationFailure } from './normalize'\nimport type { ScopeState } from './scope'\n\ntype JsonRecord = Readonly<Record<string, Value>>\ntype ProjectingContract = Pick<ErrorContract<ErrorDefinitions>, 'project'>\n\n/** One failed operation, without raw input, unredacted details, defect messages or stacks. */\nexport type FailureAuditEntry = Readonly<{\n\tkind: 'command' | 'query' | 'action'\n\toperation: string\n\tclassification: string\n\t/** The declared contract code, or `UNKNOWN_FAILURE` when no contract recognizes the failure. */\n\terrorCode: string\n\tdeclared: boolean\n\t/** The outermost operation of the request and this operation's nesting depth (0 for the root). */\n\troot: string\n\tdepth: number\n\t/** Present only when the `details` redactor returned a plain JSON record. */\n\tdetails?: JsonRecord\n\t/** Present only when the `input` redactor returned a plain JSON record. */\n\tinput?: JsonRecord\n}>\n\n/**\n * Host-free failure sink. A failed mutation rolls back every write it made, so failure\n * entries go to logs or log streams; inside queries and mutations `emit` has no `fetch`.\n */\nexport type FailureAuditOptions = Readonly<{\n\temit: (entry: FailureAuditEntry) => void | PromiseLike<void>\n\t/** Projects failures that the operation's own registry contract does not recognize. */\n\terrors?: ProjectingContract\n\t// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Redactors receive validated declared details of any registered contract.\n\tdetails?: (details: unknown, errorCode: string, operation: string) => JsonRecord | undefined\n\t// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Redactors receive the operation's decoded input of any registered schema.\n\tinput?: (input: unknown, operation: string) => JsonRecord | undefined\n}>\n\ntype FailureReport = Readonly<{\n\tkind: FailureAuditEntry['kind']\n\toperation: string\n\tclassification: string\n\t// oxlint-disable-next-line anti-slop/no-unknown-type-aliases -- The decoded input of the failed operation; only a redactor may read it.\n\tinput: unknown\n\tcontract?: ProjectingContract\n\tentered: ScopeState | undefined\n\tcurrent: ScopeState\n}>\n\n/** Report a failed exit once per failure value in the request; never changes the original outcome. */\nexport function reportFailure(\n\toptions: FailureAuditOptions | undefined,\n\texit: Exit.Exit<unknown, unknown>,\n\treport: FailureReport,\n): Effect.Effect<void> {\n\tif (!options || Exit.isSuccess(exit)) return Effect.void\n\tconst cause = exit.cause\n\tif (!Cause.hasFails(cause) && !Cause.hasDies(cause)) return Effect.void\n\treturn emitQuietly(options, () => {\n\t\tconst failure = observationFailure(cause)\n\t\tif (failure instanceof Object) {\n\t\t\tif (report.current.reported.has(failure)) return undefined\n\t\t\treport.current.reported.add(failure)\n\t\t}\n\t\tlet projected = report.contract\n\t\t\t? projectErrorCause(report.contract, cause)\n\t\t\t: ({ _tag: 'UnknownFailure', version: 1 } as const)\n\t\tif (projected._tag !== 'DeclaredFailure' && options.errors)\n\t\t\tprojected = projectErrorCause(options.errors, cause)\n\t\tconst declaredFailure = projected._tag === 'DeclaredFailure' ? projected : undefined\n\t\tconst errorCode = declaredFailure?.code ?? 'UNKNOWN_FAILURE'\n\t\tconst details =\n\t\t\tdeclaredFailure && options.details\n\t\t\t\t? redact(() => options.details!(declaredFailure.details, errorCode, report.operation))\n\t\t\t\t: undefined\n\t\tconst input = options.input\n\t\t\t? redact(() => options.input!(report.input, report.operation))\n\t\t\t: undefined\n\t\treturn Object.assign(\n\t\t\t{\n\t\t\t\tkind: report.kind,\n\t\t\t\toperation: report.operation,\n\t\t\t\tclassification: report.classification,\n\t\t\t\terrorCode,\n\t\t\t\tdeclared: declaredFailure !== undefined,\n\t\t\t\t...position(report),\n\t\t\t},\n\t\t\tdetails === undefined ? undefined : { details },\n\t\t\tinput === undefined ? undefined : { input },\n\t\t)\n\t})\n}\n\nexport function reportAuditWriteFailure(\n\toptions: FailureAuditOptions | undefined,\n\treport: Pick<FailureReport, 'operation' | 'classification' | 'entered'>,\n): Effect.Effect<void> {\n\t// Without a sink, still leave a payload-free trace that an audited action went unrecorded.\n\tif (!options)\n\t\treturn Effect.sync(() => {\n\t\t\ttry {\n\t\t\t\tconsole.error(\n\t\t\t\t\tJSON.stringify({\n\t\t\t\t\t\tevent: 'action.audit_write_failed',\n\t\t\t\t\t\terrorCode: 'ACTION_AUDIT_WRITE_FAILED',\n\t\t\t\t\t\toperation: report.operation,\n\t\t\t\t\t\tclassification: report.classification,\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t} catch {\n\t\t\t\t// The fallback trace is as inert as the sink it replaces.\n\t\t\t}\n\t\t})\n\treturn emitQuietly(options, () => ({\n\t\tkind: 'action',\n\t\toperation: report.operation,\n\t\tclassification: report.classification,\n\t\terrorCode: 'ACTION_AUDIT_WRITE_FAILED',\n\t\tdeclared: false,\n\t\t...position(report),\n\t}))\n}\n\n/** The sink is inert: building or emitting an entry can never change the operation's outcome. */\nfunction emitQuietly(\n\toptions: FailureAuditOptions,\n\tbuild: () => FailureAuditEntry | undefined,\n): Effect.Effect<void> {\n\treturn Effect.tryPromise({\n\t\ttry: async () => {\n\t\t\tconst entry = build()\n\t\t\tif (entry) await options.emit(Object.freeze(entry))\n\t\t},\n\t\tcatch: () => undefined,\n\t}).pipe(Effect.ignore)\n}\n\nfunction position(report: Pick<FailureReport, 'operation' | 'entered'>) {\n\treturn {\n\t\troot: report.entered?.scope.root ?? report.operation,\n\t\tdepth: report.entered?.scope.depth ?? 0,\n\t}\n}\n\nfunction redact(read: () => JsonRecord | undefined): JsonRecord | undefined {\n\ttry {\n\t\tconst value: unknown = read()\n\t\t// Application redactors are untrusted; only a plain record may enter the entry.\n\t\tif (!isRecord(value)) return undefined\n\t\t// SAFETY: the JSON round trip yields plain JSON values, a subset of Convex values.\n\t\treturn JSON.parse(JSON.stringify(value)) as JsonRecord\n\t} catch {\n\t\treturn undefined\n\t}\n}\n"],"mappings":"8MAqDA,SAAgBA,EACf,EACA,EACA,EACsB,CACtB,GAAI,CAACC,GAAWC,EAAK,UAAUC,CAAI,EAAG,OAAOC,EAAO,KACpD,IAAMC,EAAQF,EAAK,MAEnB,MADI,CAACG,EAAM,SAASD,CAAK,GAAK,CAACC,EAAM,QAAQD,CAAK,EAAUD,EAAO,KAC5DG,EAAYN,MAAe,CACjC,IAAMO,EAAUC,EAAmBJ,CAAK,EACxC,GAAIG,aAAmB,OAAQ,CAC9B,GAAIE,EAAO,QAAQ,SAAS,IAAIF,CAAO,EAAG,OAC1CE,EAAO,QAAQ,SAAS,IAAIF,CAAO,CACpC,CACA,IAAIG,EAAYD,EAAO,SACpBE,EAAkBF,EAAO,SAAUL,CAAK,EACvC,CAAE,KAAM,iBAAkB,QAAS,CAAE,EACrCM,EAAU,OAAS,mBAAqBV,EAAQ,SACnD,EAAYW,EAAkBX,EAAQ,OAAQI,CAAK,GACpD,IAAMQ,EAAkBF,EAAU,OAAS,kBAAoBA,EAAY,IAAA,GACrEG,EAAYD,GAAiB,MAAQ,kBACrCE,EACLF,GAAmBZ,EAAQ,QACxBe,MAAaf,EAAQ,QAASY,EAAgB,QAASC,EAAWJ,EAAO,SAAS,CAAC,EACnF,IAAA,GACEO,EAAQhB,EAAQ,MACnBe,MAAaf,EAAQ,MAAOS,EAAO,MAAOA,EAAO,SAAS,CAAC,EAC3D,IAAA,GACH,OAAO,OAAO,OACb,CACC,KAAMA,EAAO,KACb,UAAWA,EAAO,UAClB,eAAgBA,EAAO,eACvB,YACA,SAAUG,IAAoB,IAAA,GAC9B,GAAGK,EAASR,CAAM,CACnB,EACAK,IAAY,IAAA,GAAY,IAAA,GAAY,CAAE,SAAQ,EAC9CE,IAAU,IAAA,GAAY,IAAA,GAAY,CAAE,OAAM,CAC3C,CACD,CAAC,CACF,CAEA,SAAgBE,EACf,EACA,EACsB,CAiBtB,OAfKlB,EAeEM,EAAYN,OAAgB,CAClC,KAAM,SACN,UAAWS,EAAO,UAClB,eAAgBA,EAAO,eACvB,UAAW,4BACX,SAAU,GACV,GAAGQ,EAASR,CAAM,CACnB,EAAE,EArBMN,EAAO,SAAW,CACxB,GAAI,CACH,QAAQ,MACP,KAAK,UAAU,CACd,MAAO,4BACP,UAAW,4BACX,UAAWM,EAAO,UAClB,eAAgBA,EAAO,cACxB,CAAC,CACF,CACD,MAAQ,CAER,CACD,CAAC,CASH,CAGA,SAASH,EACR,EACA,EACsB,CACtB,OAAOH,EAAO,WAAW,CACxB,IAAK,SAAY,CAChB,IAAMgB,EAAQC,EAAM,EAChBD,GAAO,MAAMnB,EAAQ,KAAK,OAAO,OAAOmB,CAAK,CAAC,CACnD,EACA,UAAa,IAAA,EACd,CAAC,CAAC,CAAC,KAAKhB,EAAO,MAAM,CACtB,CAEA,SAASc,EAAS,EAAsD,CACvE,MAAO,CACN,KAAMR,EAAO,SAAS,MAAM,MAAQA,EAAO,UAC3C,MAAOA,EAAO,SAAS,MAAM,OAAS,CACvC,CACD,CAEA,SAASM,EAAO,EAA4D,CAC3E,GAAI,CACH,IAAMM,EAAiBC,EAAK,EAI5B,OAFKC,EAASF,CAAK,EAEZ,KAAK,MAAM,KAAK,UAAUA,CAAK,CAAC,EAFjB,MAGvB,MAAQ,CACP,MACD,CACD"}
@@ -0,0 +1,22 @@
1
+ import { DeclaredError, DeclaredErrorDetails, ErrorContract, ErrorDefinitions } from "../contracts/errors.mjs";
2
+ import { Effect } from "effect";
3
+ //#region src/modules/effect/failures.d.ts
4
+ type Code<Definitions extends ErrorDefinitions> = Extract<keyof Definitions, string>;
5
+ /** Details are optional exactly when the code declares no detail fields. */
6
+ type DetailArguments<Definitions extends ErrorDefinitions, Key extends Code<Definitions>> = [keyof Definitions[Key]['details']] extends [never] ? [details?: DeclaredErrorDetails<Definitions, Key>] : [details: DeclaredErrorDetails<Definitions, Key>];
7
+ /** Effect helpers bound to one declared error contract. */
8
+ export type EffectErrors<Definitions extends ErrorDefinitions> = Readonly<{
9
+ /** A yieldable failure with the contract's typed declared error: `return yield* fail('NOT_FOUND')`. */
10
+ fail: <Key extends Code<Definitions>>(code: Key, ...details: DetailArguments<Definitions, NoInfer<Key>>) => Effect.Effect<never, Extract<DeclaredError<Definitions>, {
11
+ code: Key;
12
+ }>>;
13
+ /**
14
+ * Run sync or async work; a thrown declared error of this contract, or a ConvexError carrying
15
+ * one of its declared envelopes, lands in the typed failure channel. Any other throw is a defect.
16
+ */
17
+ attempt: <Value>(run: () => Value | PromiseLike<Value>) => Effect.Effect<Value, DeclaredError<Definitions>>;
18
+ }>;
19
+ /** Bind `fail` and `attempt` to a declared error contract. */
20
+ export declare function effectErrors<const Definitions extends ErrorDefinitions>(contract: Pick<ErrorContract<Definitions>, 'create' | 'project' | 'decode'>): EffectErrors<Definitions>;
21
+ //#endregion
22
+ //# sourceMappingURL=failures.d.mts.map
@@ -0,0 +1,2 @@
1
+ import{decodeFailure as e}from"../contracts/errors.mjs";import{Effect as t}from"effect";function n(n){return Object.freeze({fail:(e,...r)=>t.suspend(()=>t.fail(n.create(e,r[0]??{}))),attempt:r=>t.tryPromise({try:async()=>r(),catch:e=>e}).pipe(t.catch(r=>{if(n.project(r)._tag===`DeclaredFailure`)return t.fail(r);let i=e(r,n);return i._tag===`DeclaredFailure`?t.fail(n.create(i.code,i.details)):t.die(r)}))})}export{n as effectErrors};
2
+ //# sourceMappingURL=failures.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"failures.mjs","names":["effectErrors","details","Effect","contract","code","run","thrown","decoded","decodeFailure"],"sources":["../../../src/modules/effect/failures.ts"],"sourcesContent":["import { Effect } from 'effect'\nimport {\n\tdecodeFailure,\n\ttype DeclaredError,\n\ttype DeclaredErrorDetails,\n\ttype ErrorContract,\n\ttype ErrorDefinitions,\n} from '../contracts/errors'\n\ntype Code<Definitions extends ErrorDefinitions> = Extract<keyof Definitions, string>\n/** Details are optional exactly when the code declares no detail fields. */\ntype DetailArguments<Definitions extends ErrorDefinitions, Key extends Code<Definitions>> = [\n\tkeyof Definitions[Key]['details'],\n] extends [never]\n\t? [details?: DeclaredErrorDetails<Definitions, Key>]\n\t: [details: DeclaredErrorDetails<Definitions, Key>]\n\n/** Effect helpers bound to one declared error contract. */\nexport type EffectErrors<Definitions extends ErrorDefinitions> = Readonly<{\n\t/** A yieldable failure with the contract's typed declared error: `return yield* fail('NOT_FOUND')`. */\n\tfail: <Key extends Code<Definitions>>(\n\t\tcode: Key,\n\t\t...details: DetailArguments<Definitions, NoInfer<Key>>\n\t) => Effect.Effect<never, Extract<DeclaredError<Definitions>, { code: Key }>>\n\t/**\n\t * Run sync or async work; a thrown declared error of this contract, or a ConvexError carrying\n\t * one of its declared envelopes, lands in the typed failure channel. Any other throw is a defect.\n\t */\n\tattempt: <Value>(\n\t\trun: () => Value | PromiseLike<Value>,\n\t) => Effect.Effect<Value, DeclaredError<Definitions>>\n}>\n\n/** Bind `fail` and `attempt` to a declared error contract. */\nexport function effectErrors<const Definitions extends ErrorDefinitions>(\n\tcontract: Pick<ErrorContract<Definitions>, 'create' | 'project' | 'decode'>,\n): EffectErrors<Definitions> {\n\treturn Object.freeze({\n\t\tfail: (code, ...details) =>\n\t\t\tEffect.suspend(() =>\n\t\t\t\t// SAFETY: omitted details are allowed only for codes that declare no detail fields; `create` validates them.\n\t\t\t\tEffect.fail(contract.create(code, (details[0] ?? {}) as never)),\n\t\t\t),\n\t\tattempt: (run) =>\n\t\t\tEffect.tryPromise({ try: async () => run(), catch: (thrown) => thrown }).pipe(\n\t\t\t\tEffect.catch((thrown) => {\n\t\t\t\t\tif (contract.project(thrown)._tag === 'DeclaredFailure')\n\t\t\t\t\t\t// SAFETY: `project` recognizes only declared errors this contract created.\n\t\t\t\t\t\treturn Effect.fail(thrown as DeclaredError<Definitions>)\n\t\t\t\t\tconst decoded = decodeFailure(thrown, contract)\n\t\t\t\t\tif (decoded._tag === 'DeclaredFailure')\n\t\t\t\t\t\t// SAFETY: `decode` validated these details against this code's declaration.\n\t\t\t\t\t\treturn Effect.fail(contract.create(decoded.code, decoded.details as never))\n\t\t\t\t\treturn Effect.die(thrown)\n\t\t\t\t}),\n\t\t\t),\n\t} satisfies EffectErrors<Definitions>)\n}\n"],"mappings":"wFAkCA,SAAgBA,EACf,EAC4B,CAC5B,OAAO,OAAO,OAAO,CACpB,MAAO,EAAM,GAAGC,IACfC,EAAO,YAENA,EAAO,KAAKC,EAAS,OAAOC,EAAOH,EAAQ,IAAM,CAAC,CAAW,CAAC,CAC/D,EACD,QAAU,GACTC,EAAO,WAAW,CAAE,IAAK,SAAYG,EAAI,EAAG,MAAQ,GAAWC,CAAO,CAAC,CAAC,CAAC,KACxEJ,EAAO,MAAO,GAAW,CACxB,GAAIC,EAAS,QAAQG,CAAM,CAAC,CAAC,OAAS,kBAErC,OAAOJ,EAAO,KAAKI,CAAoC,EACxD,IAAMC,EAAUC,EAAcF,EAAQH,CAAQ,EAI9C,OAHII,EAAQ,OAAS,kBAEbL,EAAO,KAAKC,EAAS,OAAOI,EAAQ,KAAMA,EAAQ,OAAgB,CAAC,EACpEL,EAAO,IAAII,CAAM,CACzB,CAAC,CACF,CACF,CAAqC,CACtC"}
@@ -1,9 +1,10 @@
1
1
  import { Observability, ObservabilityOptions } from "../../components/foundation/modules/observability/observability.mjs";
2
2
  import { EffectCommandDependencies, bindEffectCommand } from "./command.mjs";
3
3
  import { bindEffectQuery } from "./query.mjs";
4
+ import { EffectActionDependencies, bindEffectAction } from "./action.mjs";
4
5
  //#region src/modules/effect/foundation.d.ts
5
6
  /** Shared host capabilities are bound once; registry resolvers stay invocation-local. */
6
- export type EffectFoundationOptions = Omit<EffectCommandDependencies, 'observability'> & {
7
+ export type EffectFoundationOptions = Omit<EffectCommandDependencies, 'observability'> & Pick<EffectActionDependencies, 'writeActionAudit'> & {
7
8
  observability: ObservabilityOptions;
8
9
  };
9
10
  export type EffectFoundation<Options extends EffectFoundationOptions> = {
@@ -13,6 +14,10 @@ export type EffectFoundation<Options extends EffectFoundationOptions> = {
13
14
  Query: ReturnType<typeof bindEffectQuery<Options & {
14
15
  observability: Observability;
15
16
  }>>;
17
+ /** Contract-typed Convex actions with context injection, guards, middleware and optional audit. */
18
+ Action: ReturnType<typeof bindEffectAction<Options & {
19
+ observability: Observability;
20
+ }>>;
16
21
  observability: Observability;
17
22
  };
18
23
  export declare function createEffectFoundation<const Options extends EffectFoundationOptions>(options: Options): EffectFoundation<Options>;
@@ -1,2 +1,2 @@
1
- import{Observability as e}from"../../components/foundation/modules/observability/observability.mjs";import{bindEffectCommand as t}from"./command.mjs";import{bindEffectQuery as n}from"./query.mjs";function r(r){let i=new e(r.observability),a={...r,observability:i};return{Command:t(a),Query:n(a),observability:i}}export{r as createEffectFoundation};
1
+ import{Observability as e}from"../../components/foundation/modules/observability/observability.mjs";import{bindEffectCommand as t}from"./command.mjs";import{bindEffectQuery as n}from"./query.mjs";import{bindEffectAction as r}from"./action.mjs";function i(i){let a=new e(i.observability),o={...i,observability:a};return{Command:t(o),Query:n(o),Action:r(o),observability:a}}export{i as createEffectFoundation};
2
2
  //# sourceMappingURL=foundation.mjs.map