cvx-kit 0.1.6 → 0.1.8
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.
- package/CHANGELOG.md +23 -0
- package/README.md +63 -38
- package/dist/agent-tools.d.mts +2 -1
- package/dist/agent-tools.mjs +1 -1
- package/dist/agent-tools.mjs.map +1 -1
- package/dist/components/approvals/audit.mjs +1 -1
- package/dist/components/foundation/client.d.mts +16 -7
- package/dist/components/foundation/client.mjs +1 -1
- package/dist/components/foundation/client.mjs.map +1 -1
- package/dist/components/foundation/modules/command/command.d.mts +50 -10
- package/dist/components/foundation/modules/command/command.mjs +1 -1
- package/dist/components/foundation/modules/command/command.mjs.map +1 -1
- package/dist/components/foundation/modules/command/lifecycle.d.mts +81 -0
- package/dist/components/foundation/modules/command/lifecycle.mjs +2 -0
- package/dist/components/foundation/modules/command/lifecycle.mjs.map +1 -0
- package/dist/components/foundation/modules/observability/observability.d.mts +8 -0
- package/dist/components/foundation/modules/observability/observability.mjs +1 -1
- package/dist/components/foundation/modules/observability/observability.mjs.map +1 -1
- package/dist/components/foundation/operation.d.mts +6 -6
- package/dist/components/foundation/operation.mjs.map +1 -1
- package/dist/contracts.d.mts +4 -0
- package/dist/contracts.mjs +1 -0
- package/dist/crud.d.mts +2 -2
- package/dist/crud.mjs.map +1 -1
- package/dist/effect.d.mts +12 -0
- package/dist/effect.mjs +1 -0
- package/dist/errors.d.mts +2 -1
- package/dist/errors.mjs +1 -1
- package/dist/errors.mjs.map +1 -1
- package/dist/idempotency.d.mts +2 -0
- package/dist/idempotency.mjs +1 -0
- package/dist/modules/contracts/contract.d.mts +70 -0
- package/dist/modules/contracts/contract.mjs +2 -0
- package/dist/modules/contracts/contract.mjs.map +1 -0
- package/dist/modules/contracts/convex.d.mts +22 -0
- package/dist/modules/contracts/convex.mjs +2 -0
- package/dist/modules/contracts/convex.mjs.map +1 -0
- package/dist/modules/contracts/errors.d.mts +44 -0
- package/dist/modules/contracts/errors.mjs +2 -0
- package/dist/modules/contracts/errors.mjs.map +1 -0
- package/dist/modules/contracts/exposure.d.mts +105 -0
- package/dist/modules/contracts/exposure.mjs +2 -0
- package/dist/modules/contracts/exposure.mjs.map +1 -0
- package/dist/modules/contracts/idempotency.d.mts +87 -0
- package/dist/modules/contracts/idempotency.mjs +2 -0
- package/dist/modules/contracts/idempotency.mjs.map +1 -0
- package/dist/modules/contracts/standard.d.mts +16 -0
- package/dist/modules/contracts/standard.mjs +2 -0
- package/dist/modules/contracts/standard.mjs.map +1 -0
- package/dist/modules/contracts/workflow.d.mts +167 -0
- package/dist/modules/contracts/workflow.mjs +2 -0
- package/dist/modules/contracts/workflow.mjs.map +1 -0
- package/dist/modules/effect/agent-tools.d.mts +2 -0
- package/dist/modules/effect/agent-tools.mjs +1 -0
- package/dist/modules/effect/api-runtime.d.mts +38 -0
- package/dist/modules/effect/api-runtime.mjs +2 -0
- package/dist/modules/effect/api-runtime.mjs.map +1 -0
- package/dist/modules/effect/api-zod.d.mts +35 -0
- package/dist/modules/effect/api-zod.mjs +2 -0
- package/dist/modules/effect/api-zod.mjs.map +1 -0
- package/dist/modules/effect/api.d.mts +21 -0
- package/dist/modules/effect/api.mjs +2 -0
- package/dist/modules/effect/api.mjs.map +1 -0
- package/dist/modules/effect/client.d.mts +11 -0
- package/dist/modules/effect/client.mjs +1 -0
- package/dist/modules/effect/command.d.mts +63 -0
- package/dist/modules/effect/command.mjs +2 -0
- package/dist/modules/effect/command.mjs.map +1 -0
- package/dist/modules/effect/crud.d.mts +785 -0
- package/dist/modules/effect/crud.mjs +2 -0
- package/dist/modules/effect/crud.mjs.map +1 -0
- package/dist/modules/effect/errors.d.mts +8 -0
- package/dist/modules/effect/errors.mjs +2 -0
- package/dist/modules/effect/errors.mjs.map +1 -0
- package/dist/modules/effect/foundation.d.mts +21 -0
- package/dist/modules/effect/foundation.mjs +2 -0
- package/dist/modules/effect/foundation.mjs.map +1 -0
- package/dist/modules/effect/idempotency.d.mts +31 -0
- package/dist/modules/effect/idempotency.mjs +2 -0
- package/dist/modules/effect/idempotency.mjs.map +1 -0
- package/dist/modules/effect/normalize.d.mts +10 -0
- package/dist/modules/effect/normalize.mjs +2 -0
- package/dist/modules/effect/normalize.mjs.map +1 -0
- package/dist/modules/effect/operation.d.mts +141 -0
- package/dist/modules/effect/operation.mjs +2 -0
- package/dist/modules/effect/operation.mjs.map +1 -0
- package/dist/modules/effect/query.d.mts +69 -0
- package/dist/modules/effect/query.mjs +2 -0
- package/dist/modules/effect/query.mjs.map +1 -0
- package/dist/modules/effect/schema.d.mts +33 -0
- package/dist/modules/effect/schema.mjs +2 -0
- package/dist/modules/effect/schema.mjs.map +1 -0
- package/dist/modules/effect/workflow.d.mts +77 -0
- package/dist/modules/effect/workflow.mjs +2 -0
- package/dist/modules/effect/workflow.mjs.map +1 -0
- package/dist/node_modules/@standard-schema/spec/dist/index.d.mts +79 -0
- package/dist/workflow.d.mts +2 -0
- package/dist/workflow.mjs +1 -0
- package/docs/architecture.md +3 -3
- package/docs/auth.md +71 -0
- package/docs/command-context.md +150 -0
- package/docs/commands-legacy.md +511 -0
- package/docs/commands.md +143 -363
- package/docs/conventions.md +15 -5
- package/docs/crud.md +4 -0
- package/docs/domain-operations.md +615 -0
- package/docs/effect.md +395 -0
- package/docs/llms.md +69 -45
- package/docs/migration.md +1 -1
- package/docs/upgrading.md +9 -0
- package/package.json +33 -1
- package/scripts/convex-smoke-env.mjs +33 -0
- package/scripts/smoke-packed-components.mjs +9 -2
- package/scripts/smoke-packed-effect.mjs +439 -0
- package/scripts/test-packed-effect.mjs +460 -0
- package/scripts/test-packed-ids.mjs +1 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ErrorContract, ErrorDefinitions } from "../contracts/errors.mjs";
|
|
2
|
+
import { CallbackRequirements, EffectValue } from "./operation.mjs";
|
|
3
|
+
import { Context, Effect, Scope } from "effect";
|
|
4
|
+
//#region src/modules/effect/api-runtime.d.ts
|
|
5
|
+
type EffectApiErrorProjection = (error: unknown) => unknown;
|
|
6
|
+
type EffectApiErrorContract = Pick<ErrorContract<ErrorDefinitions>, 'project'>;
|
|
7
|
+
type EffectApiHandlerValue<Value> = Value | PromiseLike<Value> | Effect.Effect<Value, unknown, unknown>;
|
|
8
|
+
type EffectApiServices = Context.Context<never> | PromiseLike<Context.Context<never>> | Effect.Effect<Context.Context<never>, unknown, Scope.Scope>;
|
|
9
|
+
type ProvidedServices<Provider> = EffectValue<Provider> extends Context.Context<infer Services> ? Services : never;
|
|
10
|
+
type EffectApiContext = EffectApiHandlerValue<Record<string, unknown>>;
|
|
11
|
+
type KeysOfUnion<Value> = Value extends object ? keyof Value : never;
|
|
12
|
+
type CheckedContext<Ctx, Added> = Extract<KeysOfUnion<EffectValue<Added>>, keyof Ctx> extends never ? unknown : never;
|
|
13
|
+
type EffectApiOptions<Ctx, Provider extends EffectApiServices, Added = {}> = ([ProvidedServices<Provider>] extends [never] ? {
|
|
14
|
+
services?: (ctx: Ctx) => Provider;
|
|
15
|
+
} : {
|
|
16
|
+
services: (ctx: Ctx) => Provider;
|
|
17
|
+
}) & ([KeysOfUnion<EffectValue<Added>>] extends [never] ? {
|
|
18
|
+
context?: (ctx: Ctx) => Added & CheckedContext<Ctx, Added>;
|
|
19
|
+
} : {
|
|
20
|
+
context: (ctx: Ctx) => Added & CheckedContext<Ctx, Added>;
|
|
21
|
+
}) & ({
|
|
22
|
+
errors: EffectApiErrorContract;
|
|
23
|
+
mapError?: never;
|
|
24
|
+
} | {
|
|
25
|
+
errors?: never;
|
|
26
|
+
mapError?: EffectApiErrorProjection;
|
|
27
|
+
});
|
|
28
|
+
type CheckedApiRequirements<Returned, Provider> = [Exclude<CallbackRequirements<NoInfer<Returned>>, ProvidedServices<Provider> | Scope.Scope>] extends [never] ? unknown : never;
|
|
29
|
+
/** Internal erasure is limited to the registration boundary; public adapters check A/E/R. */
|
|
30
|
+
declare function wrapEffectBuilder(builder: Function, options: {
|
|
31
|
+
services?: Function;
|
|
32
|
+
context?: Function;
|
|
33
|
+
mapError?: EffectApiErrorProjection;
|
|
34
|
+
errors?: EffectApiErrorContract;
|
|
35
|
+
}): Function;
|
|
36
|
+
//#endregion
|
|
37
|
+
export { CheckedApiRequirements, CheckedContext, EffectApiContext, EffectApiErrorContract, EffectApiErrorProjection, EffectApiHandlerValue, EffectApiOptions, EffectApiServices, ProvidedServices, wrapEffectBuilder };
|
|
38
|
+
//# sourceMappingURL=api-runtime.d.mts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{normalizeEffect as e}from"./normalize.mjs";import{projectErrorCause as t}from"./errors.mjs";import{ConvexError as n}from"convex/values";import{Cause as r,Context as i,Effect as a,Exit as o}from"effect";function s(s,c){return l=>{let u=typeof l==`function`?l:l.handler,d=async(s,...l)=>{let d=e(()=>c.services?c.services(s):i.empty()).pipe(a.flatMap(t=>e(()=>c.context?c.context(s):{}).pipe(a.flatMap(e=>a.sync(()=>{if(typeof e!=`object`||!e)throw Error(`Effect API context must be an object`);let t=Object.getPrototypeOf(e);if(t!==Object.prototype&&t!==null)throw Error(`Effect API context additions must be a plain record`);let n=s;for(let t of Reflect.ownKeys(e))if(t in n)throw Error(`Effect API context cannot replace ${String(t)}`);return c.context?Object.create(Object.getPrototypeOf(n),{...Object.getOwnPropertyDescriptors(n),...Object.getOwnPropertyDescriptors(e)}):s})),a.flatMap(t=>e(()=>u(t,...l))),a.provideContext(t)))),f=await a.runPromiseExit(a.scoped(d));if(o.isSuccess(f))return f.value;if(c.errors)throw new n(t(c.errors,f.cause));let p=f.cause.reasons.length===1?f.cause.reasons[0]:void 0;throw p&&r.isFailReason(p)?c.mapError?c.mapError(p.error):p.error:p&&r.isDieReason(p)?p.defect:Error(`Effect API execution failed`,{cause:f.cause})};return s(typeof l==`function`?d:{...l,handler:d})}}export{s as wrapEffectBuilder};
|
|
2
|
+
//# sourceMappingURL=api-runtime.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-runtime.mjs","names":[],"sources":["../../../src/modules/effect/api-runtime.ts"],"sourcesContent":["import { Cause, Context, Effect, Exit } from 'effect'\nimport type { Scope } from 'effect'\nimport { ConvexError, type Value } from 'convex/values'\nimport type { ErrorContract, ErrorDefinitions } from '../contracts/errors'\nimport { projectErrorCause } from './errors'\nimport { normalizeEffect } from './normalize'\nimport type { CallbackRequirements, EffectValue } from './operation'\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters, anti-slop/no-unknown-returns -- Projection receives any expected failure and its result is always thrown, never returned as public data.\nexport type EffectApiErrorProjection = (error: unknown) => unknown\nexport type EffectApiErrorContract = Pick<ErrorContract<ErrorDefinitions>, 'project'>\n\nexport type EffectApiHandlerValue<Value> =\n\t| Value\n\t| PromiseLike<Value>\n\t| Effect.Effect<Value, unknown, unknown>\n\nexport type EffectApiServices =\n\t| Context.Context<never>\n\t| PromiseLike<Context.Context<never>>\n\t| Effect.Effect<Context.Context<never>, unknown, Scope.Scope>\nexport type ProvidedServices<Provider> =\n\tEffectValue<Provider> extends Context.Context<infer Services> ? Services : never\n// oxlint-disable-next-line anti-slop/no-unsafe-dictionary-type -- This inference constraint requires record-shaped additions; each adapter preserves its concrete inferred fields and runtime checks the record boundary.\nexport type EffectApiContext = EffectApiHandlerValue<Record<string, unknown>>\ntype KeysOfUnion<Value> = Value extends object ? keyof Value : never\nexport type CheckedContext<Ctx, Added> =\n\tExtract<KeysOfUnion<EffectValue<Added>>, keyof Ctx> extends never ? unknown : never\nexport type EffectApiOptions<Ctx, Provider extends EffectApiServices, Added = {}> = (\n\t[ProvidedServices<Provider>] extends [never]\n\t\t? { services?: (ctx: Ctx) => Provider }\n\t\t: { services: (ctx: Ctx) => Provider }\n) & (\n\t[KeysOfUnion<EffectValue<Added>>] extends [never]\n\t\t? { context?: (ctx: Ctx) => Added & CheckedContext<Ctx, Added> }\n\t\t: { context: (ctx: Ctx) => Added & CheckedContext<Ctx, Added> }\n) & (\n\t| { errors: EffectApiErrorContract; mapError?: never }\n\t| { errors?: never; mapError?: EffectApiErrorProjection }\n)\nexport type CheckedApiRequirements<Returned, Provider> = [\n\tExclude<CallbackRequirements<NoInfer<Returned>>, ProvidedServices<Provider> | Scope.Scope>,\n] extends [never]\n\t? unknown\n\t: never\n\n/** Internal erasure is limited to the registration boundary; public adapters check A/E/R. */\nexport function wrapEffectBuilder(\n\tbuilder: Function,\n\toptions: {\n\t\tservices?: Function\n\t\tcontext?: Function\n\t\tmapError?: EffectApiErrorProjection\n\t\terrors?: EffectApiErrorContract\n\t},\n): Function {\n\treturn (definition: Function | { handler: Function }) => {\n\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- Native registration explicitly accepts a callable or an object with a handler.\n\t\tconst original = typeof definition === 'function' ? definition : definition.handler\n\t\t// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Private erased callback receives the context already constructed by the checked native/custom builder.\n\t\tconst handler = async (ctx: unknown, ...args: unknown[]) => {\n\t\t\tconst program = normalizeEffect(() =>\n\t\t\t\toptions.services ? options.services(ctx) : Context.empty(),\n\t\t\t).pipe(\n\t\t\t\tEffect.flatMap((services) =>\n\t\t\t\t\tnormalizeEffect(() => (options.context ? options.context(ctx) : {})).pipe(\n\t\t\t\t\t\tEffect.flatMap((added) =>\n\t\t\t\t\t\t\tEffect.sync(() => {\n\t\t\t\t\t\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- Validate erased context additions before enumerating or merging their fields.\n\t\t\t\t\t\t\t\tif (added === null || typeof added !== 'object')\n\t\t\t\t\t\t\t\t\tthrow Error('Effect API context must be an object')\n\t\t\t\t\t\t\t\tconst additionsPrototype = Object.getPrototypeOf(added)\n\t\t\t\t\t\t\t\tif (additionsPrototype !== Object.prototype && additionsPrototype !== null)\n\t\t\t\t\t\t\t\t\tthrow Error('Effect API context additions must be a plain record')\n\t\t\t\t\t\t\t\t// SAFETY: native and custom builders construct an object context before invoking this private handler.\n\t\t\t\t\t\t\t\tconst originalContext = ctx as object\n\t\t\t\t\t\t\t\tfor (const key of Reflect.ownKeys(added)) {\n\t\t\t\t\t\t\t\t\tif (key in originalContext)\n\t\t\t\t\t\t\t\t\t\tthrow Error(`Effect API context cannot replace ${String(key)}`)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn options.context\n\t\t\t\t\t\t\t\t\t? Object.create(Object.getPrototypeOf(originalContext), {\n\t\t\t\t\t\t\t\t\t\t\t...Object.getOwnPropertyDescriptors(originalContext),\n\t\t\t\t\t\t\t\t\t\t\t...Object.getOwnPropertyDescriptors(added),\n\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t: ctx\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tEffect.flatMap((context) => normalizeEffect(() => original(context, ...args))),\n\t\t\t\t\t\tEffect.provideContext(services),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t)\n\t\t\t// SAFETY: checked public signatures prohibit unprovided handler requirements and\n\t\t\t// permit only Scope in providers; services are constructed within this same scope.\n\t\t\tconst exit = await Effect.runPromiseExit(\n\t\t\t\tEffect.scoped(program) as Effect.Effect<unknown, unknown>,\n\t\t\t)\n\t\t\tif (Exit.isSuccess(exit)) return exit.value\n\t\t\tif (options.errors) {\n\t\t\t\t// SAFETY: declared projection copies validated JSON-safe fields; all other Causes have a fixed safe envelope.\n\t\t\t\tthrow new ConvexError(projectErrorCause(options.errors, exit.cause) as Value)\n\t\t\t}\n\t\t\tconst reason = exit.cause.reasons.length === 1 ? exit.cause.reasons[0] : undefined\n\t\t\tif (reason && Cause.isFailReason(reason)) {\n\t\t\t\tthrow options.mapError ? options.mapError(reason.error) : reason.error\n\t\t\t}\n\t\t\tif (reason && Cause.isDieReason(reason)) throw reason.defect\n\t\t\tthrow new Error('Effect API execution failed', { cause: exit.cause })\n\t\t}\n\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- Preserve the original native callable or object registration form.\n\t\treturn builder(typeof definition === 'function' ? handler : { ...definition, handler })\n\t}\n}\n"],"mappings":"iNA+CA,SAAgB,EACf,EACA,EAMW,CACX,MAAQ,IAAiD,CAExD,IAAM,EAAW,OAAO,GAAe,WAAa,EAAa,EAAW,QAEtE,EAAU,MAAO,EAAc,GAAG,IAAoB,CAC3D,IAAM,EAAU,MACf,EAAQ,SAAW,EAAQ,SAAS,CAAG,EAAI,EAAQ,MAAM,CAC1D,CAAC,CAAC,KACD,EAAO,QAAS,GACf,MAAuB,EAAQ,QAAU,EAAQ,QAAQ,CAAG,EAAI,CAAC,CAAE,CAAC,CAAC,KACpE,EAAO,QAAS,GACf,EAAO,SAAW,CAEjB,GAAsB,OAAO,GAAU,WAAnC,EACH,MAAM,MAAM,sCAAsC,EACnD,IAAM,EAAqB,OAAO,eAAe,CAAK,EACtD,GAAI,IAAuB,OAAO,WAAa,IAAuB,KACrE,MAAM,MAAM,qDAAqD,EAElE,IAAM,EAAkB,EACxB,IAAK,IAAM,KAAO,QAAQ,QAAQ,CAAK,EACtC,GAAI,KAAO,EACV,MAAM,MAAM,qCAAqC,OAAO,CAAG,GAAG,EAEhE,OAAO,EAAQ,QACZ,OAAO,OAAO,OAAO,eAAe,CAAe,EAAG,CACtD,GAAG,OAAO,0BAA0B,CAAe,EACnD,GAAG,OAAO,0BAA0B,CAAK,CAC1C,CAAC,EACA,CACJ,CAAC,CACF,EACA,EAAO,QAAS,GAAY,MAAsB,EAAS,EAAS,GAAG,CAAI,CAAC,CAAC,EAC7E,EAAO,eAAe,CAAQ,CAC/B,CACD,CACD,EAGM,EAAO,MAAM,EAAO,eACzB,EAAO,OAAO,CAAO,CACtB,EACA,GAAI,EAAK,UAAU,CAAI,EAAG,OAAO,EAAK,MACtC,GAAI,EAAQ,OAEX,MAAM,IAAI,EAAY,EAAkB,EAAQ,OAAQ,EAAK,KAAK,CAAU,EAE7E,IAAM,EAAS,EAAK,MAAM,QAAQ,SAAW,EAAI,EAAK,MAAM,QAAQ,GAAK,IAAA,GAKzE,MAJI,GAAU,EAAM,aAAa,CAAM,EAChC,EAAQ,SAAW,EAAQ,SAAS,EAAO,KAAK,EAAI,EAAO,MAE9D,GAAU,EAAM,YAAY,CAAM,EAAS,EAAO,OAC5C,MAAM,8BAA+B,CAAE,MAAO,EAAK,KAAM,CAAC,CACrE,EAEA,OAAO,EAAQ,OAAO,GAAe,WAAa,EAAU,CAAE,GAAG,EAAY,SAAQ,CAAC,CACvF,CACD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { CallbackRequirements, EffectValue } from "./operation.mjs";
|
|
2
|
+
import { EffectApiContext, EffectApiHandlerValue, EffectApiOptions, EffectApiServices, ProvidedServices } from "./api-runtime.mjs";
|
|
3
|
+
import { CustomBuilder } from "convex-helpers/server/zod4";
|
|
4
|
+
import { ArgsArrayToObject, DefaultFunctionArgs, FunctionVisibility } from "convex/server";
|
|
5
|
+
import { ObjectType, PropertyValidators } from "convex/values";
|
|
6
|
+
import { Scope } from "effect";
|
|
7
|
+
import { Registration } from "convex-helpers/server/customFunctions";
|
|
8
|
+
import * as zCore from "zod/v4/core";
|
|
9
|
+
//#region src/modules/effect/api-zod.d.ts
|
|
10
|
+
type Fields = Record<string, zCore.$ZodType>;
|
|
11
|
+
type ArgumentsValidator = Fields | zCore.$ZodObject<Fields> | void;
|
|
12
|
+
type ResultValidator = zCore.$ZodType | Fields | void;
|
|
13
|
+
type Expand<Value> = { [Key in keyof Value]: Value[Key]; };
|
|
14
|
+
type Overwrite<Input, Custom> = Omit<Input, keyof Custom> & Custom;
|
|
15
|
+
type ArgsInput<Validator extends ArgumentsValidator> = [Validator] extends [zCore.$ZodObject<Fields>] ? [zCore.input<Validator>] : Validator extends Record<string, never> ? [Record<never, never>] : [Validator] extends [Fields] ? [zCore.input<zCore.$ZodObject<Validator, zCore.$strict>>] : [DefaultFunctionArgs];
|
|
16
|
+
type ArgsOutput<Validator extends ArgumentsValidator> = [Validator] extends [zCore.$ZodObject<Fields>] ? [zCore.output<Validator>] : [Validator] extends [Fields] ? [zCore.output<zCore.$ZodObject<Validator, zCore.$strict>>] : [DefaultFunctionArgs];
|
|
17
|
+
type HandlerArgs<Validator extends ArgumentsValidator, Made> = Made extends Record<string, never> ? ArgsOutput<Validator> : [Expand<ArgsOutput<Validator>[0] & Made>];
|
|
18
|
+
type RawArgs<Validator extends ArgumentsValidator, Custom extends PropertyValidators> = ArgsArrayToObject<Custom extends Record<string, never> ? ArgsInput<Validator> : [Expand<ArgsInput<Validator>[0] & ObjectType<Custom>>]>;
|
|
19
|
+
type ResultInput<Validator extends ResultValidator> = [Validator] extends [zCore.$ZodType] ? zCore.input<Validator> : [Validator] extends [Fields] ? zCore.input<zCore.$ZodObject<Validator>> : unknown;
|
|
20
|
+
type ResultOutput<Validator extends ResultValidator, Returned> = [Validator] extends [void] ? EffectValue<Returned> : [Validator] extends [zCore.$ZodType] ? zCore.output<Validator> : [Validator] extends [Fields] ? zCore.output<zCore.$ZodObject<Validator, zCore.$strict>> : never;
|
|
21
|
+
type CheckedRequirements<Returned, Services> = [Exclude<CallbackRequirements<NoInfer<Returned>>, Services | Scope.Scope>] extends [never] ? unknown : never;
|
|
22
|
+
/** Retains the installed Zod custom builder's raw/parsed boundaries and customization options. */
|
|
23
|
+
type EffectZodApiBuilder<Kind extends 'query' | 'mutation' | 'action', CustomArgs extends PropertyValidators, CustomCtx extends Record<string, unknown>, CustomMadeArgs extends Record<string, unknown>, InputCtx, Visibility extends FunctionVisibility, ExtraArgs extends Record<string, unknown>, Services, Added = {}, Initialized = {}> = {
|
|
24
|
+
<Args extends ArgumentsValidator, Returns extends ResultValidator = void, Returned extends EffectApiHandlerValue<ResultInput<Returns> | (null extends ResultInput<Returns> ? undefined | void : never)> = EffectApiHandlerValue<ResultInput<Returns> | (null extends ResultInput<Returns> ? undefined | void : never)>>(definition: (({
|
|
25
|
+
args?: Args;
|
|
26
|
+
returns?: Returns;
|
|
27
|
+
skipConvexValidation?: boolean;
|
|
28
|
+
handler: (ctx: Overwrite<InputCtx, CustomCtx> & Added, ...args: HandlerArgs<Args, CustomMadeArgs>) => Returned;
|
|
29
|
+
} & Omit<ExtraArgs, 'args' | 'returns' | 'handler' | 'skipConvexValidation'>) | ((ctx: Overwrite<InputCtx, CustomCtx> & Added, ...args: HandlerArgs<Args, CustomMadeArgs>) => Returned)) & CheckedRequirements<Returned, Services> & CheckedRequirements<Initialized, Services>): Registration<Kind, Visibility, RawArgs<Args, CustomArgs>, ResultOutput<Returns, Returned>>;
|
|
30
|
+
};
|
|
31
|
+
/** Build request services after the original custom builder resolves its trusted context. */
|
|
32
|
+
declare function effectZodApiBuilder<Kind extends 'query' | 'mutation' | 'action', CustomArgs extends PropertyValidators, CustomCtx extends Record<string, unknown>, CustomMadeArgs extends Record<string, unknown>, InputCtx, Visibility extends FunctionVisibility, ExtraArgs extends Record<string, unknown>, Provider extends EffectApiServices = import('effect').Context.Context<never>, Added extends EffectApiContext = {}>(builder: CustomBuilder<Kind, CustomArgs, CustomCtx, CustomMadeArgs, InputCtx, Visibility, ExtraArgs>, options: EffectApiOptions<Overwrite<InputCtx, CustomCtx>, Provider, Added>): EffectZodApiBuilder<Kind, CustomArgs, CustomCtx, CustomMadeArgs, InputCtx, Visibility, ExtraArgs, ProvidedServices<Provider>, EffectValue<Added>, Added>;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { EffectZodApiBuilder, effectZodApiBuilder };
|
|
35
|
+
//# sourceMappingURL=api-zod.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-zod.mjs","names":[],"sources":["../../../src/modules/effect/api-zod.ts"],"sourcesContent":["import type { ArgsArrayToObject, DefaultFunctionArgs, FunctionVisibility } from 'convex/server'\nimport type { ObjectType, PropertyValidators } from 'convex/values'\nimport type { Registration } from 'convex-helpers/server/customFunctions'\nimport type { CustomBuilder } from 'convex-helpers/server/zod4'\nimport type { Scope } from 'effect'\nimport type * as zCore from 'zod/v4/core'\nimport {\n\twrapEffectBuilder,\n\ttype EffectApiOptions,\n\ttype ProvidedServices,\n\ttype EffectApiServices,\n\ttype EffectApiHandlerValue,\n\ttype EffectApiContext,\n} from './api-runtime'\nimport type { CallbackRequirements, EffectValue } from './operation'\n\ntype Fields = Record<string, zCore.$ZodType>\ntype ArgumentsValidator = Fields | zCore.$ZodObject<Fields> | void\ntype ResultValidator = zCore.$ZodType | Fields | void\ntype Expand<Value> = { [Key in keyof Value]: Value[Key] }\ntype Overwrite<Input, Custom> = Omit<Input, keyof Custom> & Custom\ntype ArgsInput<Validator extends ArgumentsValidator> = [Validator] extends [\n\tzCore.$ZodObject<Fields>,\n]\n\t? [zCore.input<Validator>]\n\t: Validator extends Record<string, never>\n\t\t? [Record<never, never>]\n\t\t: [Validator] extends [Fields]\n\t\t\t? [zCore.input<zCore.$ZodObject<Validator, zCore.$strict>>]\n\t\t\t: [DefaultFunctionArgs]\ntype ArgsOutput<Validator extends ArgumentsValidator> = [Validator] extends [\n\tzCore.$ZodObject<Fields>,\n]\n\t? [zCore.output<Validator>]\n\t: [Validator] extends [Fields]\n\t\t? [zCore.output<zCore.$ZodObject<Validator, zCore.$strict>>]\n\t\t: [DefaultFunctionArgs]\ntype HandlerArgs<Validator extends ArgumentsValidator, Made> =\n\tMade extends Record<string, never>\n\t\t? ArgsOutput<Validator>\n\t\t: [Expand<ArgsOutput<Validator>[0] & Made>]\ntype RawArgs<\n\tValidator extends ArgumentsValidator,\n\tCustom extends PropertyValidators,\n> = ArgsArrayToObject<\n\tCustom extends Record<string, never>\n\t\t? ArgsInput<Validator>\n\t\t: [Expand<ArgsInput<Validator>[0] & ObjectType<Custom>>]\n>\ntype ResultInput<Validator extends ResultValidator> = [Validator] extends [zCore.$ZodType]\n\t? zCore.input<Validator>\n\t: [Validator] extends [Fields]\n\t\t? zCore.input<zCore.$ZodObject<Validator>>\n\t\t: unknown\ntype ResultOutput<Validator extends ResultValidator, Returned> = [Validator] extends [void]\n\t? EffectValue<Returned>\n\t: [Validator] extends [zCore.$ZodType]\n\t\t? zCore.output<Validator>\n\t\t: [Validator] extends [Fields]\n\t\t\t? zCore.output<zCore.$ZodObject<Validator, zCore.$strict>>\n\t\t\t: never\ntype CheckedRequirements<Returned, Services> = [\n\tExclude<CallbackRequirements<NoInfer<Returned>>, Services | Scope.Scope>,\n] extends [never]\n\t? unknown\n\t: never\n\n/** Retains the installed Zod custom builder's raw/parsed boundaries and customization options. */\nexport type EffectZodApiBuilder<\n\tKind extends 'query' | 'mutation' | 'action',\n\tCustomArgs extends PropertyValidators,\n\tCustomCtx extends Record<string, unknown>,\n\tCustomMadeArgs extends Record<string, unknown>,\n\tInputCtx,\n\tVisibility extends FunctionVisibility,\n\tExtraArgs extends Record<string, unknown>,\n\tServices,\n\tAdded = {},\n\tInitialized = {},\n> = {\n\t<\n\t\tArgs extends ArgumentsValidator,\n\t\tReturns extends ResultValidator = void,\n\t\tReturned extends EffectApiHandlerValue<\n\t\t\tResultInput<Returns> | (null extends ResultInput<Returns> ? undefined | void : never)\n\t\t> = EffectApiHandlerValue<\n\t\t\tResultInput<Returns> | (null extends ResultInput<Returns> ? undefined | void : never)\n\t\t>,\n\t>(\n\t\tdefinition: (\n\t\t\t| ({\n\t\t\t\t\targs?: Args\n\t\t\t\t\treturns?: Returns\n\t\t\t\t\tskipConvexValidation?: boolean\n\t\t\t\t\thandler: (\n\t\t\t\t\t\tctx: Overwrite<InputCtx, CustomCtx> & Added,\n\t\t\t\t\t\t...args: HandlerArgs<Args, CustomMadeArgs>\n\t\t\t\t\t) => Returned\n\t\t\t } & Omit<ExtraArgs, 'args' | 'returns' | 'handler' | 'skipConvexValidation'>)\n\t\t\t| ((\n\t\t\t\t\tctx: Overwrite<InputCtx, CustomCtx> & Added,\n\t\t\t\t\t...args: HandlerArgs<Args, CustomMadeArgs>\n\t\t\t ) => Returned)\n\t\t) &\n\t\t\tCheckedRequirements<Returned, Services> &\n\t\t\tCheckedRequirements<Initialized, Services>,\n\t): Registration<Kind, Visibility, RawArgs<Args, CustomArgs>, ResultOutput<Returns, Returned>>\n}\n\n/** Build request services after the original custom builder resolves its trusted context. */\nexport function effectZodApiBuilder<\n\tKind extends 'query' | 'mutation' | 'action',\n\tCustomArgs extends PropertyValidators,\n\tCustomCtx extends Record<string, unknown>,\n\tCustomMadeArgs extends Record<string, unknown>,\n\tInputCtx,\n\tVisibility extends FunctionVisibility,\n\tExtraArgs extends Record<string, unknown>,\n\tProvider extends EffectApiServices = import('effect').Context.Context<never>,\n\tAdded extends EffectApiContext = {},\n>(\n\tbuilder: CustomBuilder<\n\t\tKind,\n\t\tCustomArgs,\n\t\tCustomCtx,\n\t\tCustomMadeArgs,\n\t\tInputCtx,\n\t\tVisibility,\n\t\tExtraArgs\n\t>,\n\toptions: EffectApiOptions<Overwrite<InputCtx, CustomCtx>, Provider, Added>,\n): EffectZodApiBuilder<\n\tKind,\n\tCustomArgs,\n\tCustomCtx,\n\tCustomMadeArgs,\n\tInputCtx,\n\tVisibility,\n\tExtraArgs,\n\tProvidedServices<Provider>,\n\tEffectValue<Added>,\n\tAdded\n> {\n\t// SAFETY: Runtime substitution changes only the handler. The original builder retains validation,\n\t// customization, registration kind and visibility; the public call signature above checks Effects.\n\treturn wrapEffectBuilder(builder, options) as EffectZodApiBuilder<\n\t\tKind,\n\t\tCustomArgs,\n\t\tCustomCtx,\n\t\tCustomMadeArgs,\n\t\tInputCtx,\n\t\tVisibility,\n\t\tExtraArgs,\n\t\tProvidedServices<Provider>,\n\t\tEffectValue<Added>,\n\t\tAdded\n\t>\n}\n"],"mappings":"sDA8GA,SAAgB,EAWf,EASA,EAYC,CAGD,OAAO,EAAkB,EAAS,CAAO,CAY1C"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { EffectValue } from "./operation.mjs";
|
|
2
|
+
import { CheckedApiRequirements, EffectApiContext, EffectApiHandlerValue, EffectApiOptions, EffectApiServices } from "./api-runtime.mjs";
|
|
3
|
+
import { ActionBuilder, ArgsArrayForOptionalValidator, ArgsArrayToObject, DefaultArgsForOptionalValidator, FunctionVisibility, GenericActionCtx, GenericDataModel, GenericMutationCtx, GenericQueryCtx, MutationBuilder, QueryBuilder, RegisteredAction, RegisteredMutation, RegisteredQuery, ReturnValueForOptionalValidator } from "convex/server";
|
|
4
|
+
import { PropertyValidators, Validator } from "convex/values";
|
|
5
|
+
//#region src/modules/effect/api.d.ts
|
|
6
|
+
type ApiValidator = PropertyValidators | Validator<unknown, 'required', string> | void;
|
|
7
|
+
type ApiOutput<Returns extends ApiValidator> = [Returns] extends [void] ? unknown : ReturnValueForOptionalValidator<Returns>;
|
|
8
|
+
type EffectApiBuilder<Ctx, Visibility extends FunctionVisibility, Kind extends 'query' | 'mutation' | 'action', Provider, Initialized = {}> = {
|
|
9
|
+
<Args extends ApiValidator, Returns extends ApiValidator = void, Returned extends EffectApiHandlerValue<ApiOutput<Returns>> = EffectApiHandlerValue<ApiOutput<Returns>>, OneOrZeroArgs extends ArgsArrayForOptionalValidator<Args> = DefaultArgsForOptionalValidator<Args>>(definition: ({
|
|
10
|
+
args?: Args;
|
|
11
|
+
returns?: Returns;
|
|
12
|
+
handler: (ctx: Ctx, ...args: OneOrZeroArgs) => Returned;
|
|
13
|
+
} | ((ctx: Ctx, ...args: OneOrZeroArgs) => Returned)) & CheckedApiRequirements<Returned, Provider> & CheckedApiRequirements<Initialized, Provider>): Kind extends 'query' ? RegisteredQuery<Visibility, ArgsArrayToObject<OneOrZeroArgs>, Promise<EffectValue<Returned>>> : Kind extends 'mutation' ? RegisteredMutation<Visibility, ArgsArrayToObject<OneOrZeroArgs>, Promise<EffectValue<Returned>>> : RegisteredAction<Visibility, ArgsArrayToObject<OneOrZeroArgs>, Promise<EffectValue<Returned>>>;
|
|
14
|
+
};
|
|
15
|
+
/** Provision request services after the supplied builder has constructed its trusted context. */
|
|
16
|
+
declare function effectApiBuilder<DM extends GenericDataModel, V extends FunctionVisibility, Provider extends EffectApiServices = import('effect').Context.Context<never>, Added extends EffectApiContext = {}>(builder: QueryBuilder<DM, V>, options: EffectApiOptions<GenericQueryCtx<DM>, Provider, Added>): EffectApiBuilder<GenericQueryCtx<DM> & EffectValue<Added>, V, 'query', Provider, Added>;
|
|
17
|
+
declare function effectApiBuilder<DM extends GenericDataModel, V extends FunctionVisibility, Provider extends EffectApiServices = import('effect').Context.Context<never>, Added extends EffectApiContext = {}>(builder: MutationBuilder<DM, V>, options: EffectApiOptions<GenericMutationCtx<DM>, Provider, Added>): EffectApiBuilder<GenericMutationCtx<DM> & EffectValue<Added>, V, 'mutation', Provider, Added>;
|
|
18
|
+
declare function effectApiBuilder<DM extends GenericDataModel, V extends FunctionVisibility, Provider extends EffectApiServices = import('effect').Context.Context<never>, Added extends EffectApiContext = {}>(builder: ActionBuilder<DM, V>, options: EffectApiOptions<GenericActionCtx<DM>, Provider, Added>): EffectApiBuilder<GenericActionCtx<DM> & EffectValue<Added>, V, 'action', Provider, Added>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { EffectApiBuilder, effectApiBuilder };
|
|
21
|
+
//# sourceMappingURL=api.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.mjs","names":[],"sources":["../../../src/modules/effect/api.ts"],"sourcesContent":["import type {\n\tActionBuilder,\n\tArgsArrayForOptionalValidator,\n\tArgsArrayToObject,\n\tDefaultArgsForOptionalValidator,\n\tFunctionVisibility,\n\tGenericActionCtx,\n\tGenericDataModel,\n\tGenericMutationCtx,\n\tGenericQueryCtx,\n\tMutationBuilder,\n\tQueryBuilder,\n\tRegisteredAction,\n\tRegisteredMutation,\n\tRegisteredQuery,\n\tReturnValueForOptionalValidator,\n} from 'convex/server'\nimport type { PropertyValidators, Validator } from 'convex/values'\nimport type { EffectValue } from './operation'\nimport {\n\twrapEffectBuilder,\n\ttype CheckedApiRequirements,\n\ttype EffectApiOptions,\n\ttype EffectApiErrorProjection,\n\ttype EffectApiErrorContract,\n\ttype EffectApiServices,\n\ttype EffectApiHandlerValue,\n\ttype EffectApiContext,\n} from './api-runtime'\n\n// Convex's optional-validator grammar, restricted to unknown instead of public any.\ntype ApiValidator = PropertyValidators | Validator<unknown, 'required', string> | void\ntype ApiOutput<Returns extends ApiValidator> = [Returns] extends [void]\n\t? unknown\n\t: ReturnValueForOptionalValidator<Returns>\nexport type EffectApiBuilder<\n\tCtx,\n\tVisibility extends FunctionVisibility,\n\tKind extends 'query' | 'mutation' | 'action',\n\tProvider,\n\tInitialized = {},\n> = {\n\t<\n\t\tArgs extends ApiValidator,\n\t\tReturns extends ApiValidator = void,\n\t\tReturned extends EffectApiHandlerValue<ApiOutput<Returns>> = EffectApiHandlerValue<\n\t\t\tApiOutput<Returns>\n\t\t>,\n\t\tOneOrZeroArgs extends ArgsArrayForOptionalValidator<Args> =\n\t\t\tDefaultArgsForOptionalValidator<Args>,\n\t>(\n\t\tdefinition: (\n\t\t\t| { args?: Args; returns?: Returns; handler: (ctx: Ctx, ...args: OneOrZeroArgs) => Returned }\n\t\t\t| ((ctx: Ctx, ...args: OneOrZeroArgs) => Returned)\n\t\t) &\n\t\t\tCheckedApiRequirements<Returned, Provider> &\n\t\t\tCheckedApiRequirements<Initialized, Provider>,\n\t): Kind extends 'query'\n\t\t? RegisteredQuery<Visibility, ArgsArrayToObject<OneOrZeroArgs>, Promise<EffectValue<Returned>>>\n\t\t: Kind extends 'mutation'\n\t\t\t? RegisteredMutation<\n\t\t\t\t\tVisibility,\n\t\t\t\t\tArgsArrayToObject<OneOrZeroArgs>,\n\t\t\t\t\tPromise<EffectValue<Returned>>\n\t\t\t\t>\n\t\t\t: RegisteredAction<\n\t\t\t\t\tVisibility,\n\t\t\t\t\tArgsArrayToObject<OneOrZeroArgs>,\n\t\t\t\t\tPromise<EffectValue<Returned>>\n\t\t\t\t>\n}\n\n/** Provision request services after the supplied builder has constructed its trusted context. */\nexport function effectApiBuilder<\n\tDM extends GenericDataModel,\n\tV extends FunctionVisibility,\n\tProvider extends EffectApiServices = import('effect').Context.Context<never>,\n\tAdded extends EffectApiContext = {},\n>(\n\tbuilder: QueryBuilder<DM, V>,\n\toptions: EffectApiOptions<GenericQueryCtx<DM>, Provider, Added>,\n): EffectApiBuilder<GenericQueryCtx<DM> & EffectValue<Added>, V, 'query', Provider, Added>\nexport function effectApiBuilder<\n\tDM extends GenericDataModel,\n\tV extends FunctionVisibility,\n\tProvider extends EffectApiServices = import('effect').Context.Context<never>,\n\tAdded extends EffectApiContext = {},\n>(\n\tbuilder: MutationBuilder<DM, V>,\n\toptions: EffectApiOptions<GenericMutationCtx<DM>, Provider, Added>,\n): EffectApiBuilder<GenericMutationCtx<DM> & EffectValue<Added>, V, 'mutation', Provider, Added>\nexport function effectApiBuilder<\n\tDM extends GenericDataModel,\n\tV extends FunctionVisibility,\n\tProvider extends EffectApiServices = import('effect').Context.Context<never>,\n\tAdded extends EffectApiContext = {},\n>(\n\tbuilder: ActionBuilder<DM, V>,\n\toptions: EffectApiOptions<GenericActionCtx<DM>, Provider, Added>,\n): EffectApiBuilder<GenericActionCtx<DM> & EffectValue<Added>, V, 'action', Provider, Added>\nexport function effectApiBuilder(\n\tbuilder: Function,\n\toptions: {\n\t\tservices?: Function\n\t\tcontext?: Function\n\t\tmapError?: EffectApiErrorProjection\n\t\terrors?: EffectApiErrorContract\n\t},\n): Function {\n\treturn wrapEffectBuilder(builder, options)\n}\n"],"mappings":"sDAoGA,SAAgB,EACf,EACA,EAMW,CACX,OAAO,EAAkB,EAAS,CAAO,CAC1C"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { OperationExecutor, OperationPublicResult, OperationTool, OperationToolConverter, OperationToolDefinition, OperationToolJsonSchema, OperationToolOutcome, SelectedOperation, bindOperationExecutor, createOperationTools, operationToolDialect, selectOperation } from "../contracts/exposure.mjs";
|
|
2
|
+
import { ContractDecoderError, ContractDecoderRequirements, ContractValidationError, EffectDecoder, decodeEffectContract, effectContract, effectSchema, effectStandardSchema } from "./schema.mjs";
|
|
3
|
+
import { CallbackError, CallbackRequirements, EffectMiddlewareInput, EffectOperationArgument, EffectOperationError, EffectOperationHandlerResult, EffectOperationInput, EffectOperationRequirements, EffectOperationResult, EffectPreparation, EffectValue, effectOperationFactory } from "./operation.mjs";
|
|
4
|
+
import { EffectFoundationOptions, createEffectFoundation } from "./foundation.mjs";
|
|
5
|
+
import { EffectIdempotencyPreparation, effectTransactionalIdempotency } from "./idempotency.mjs";
|
|
6
|
+
import { EffectCrudConfig, EffectCrudContext, EffectCrudPage, EffectCrudPagination, EffectCrudRepository, EffectCrudTable, createEffectCrud } from "./crud.mjs";
|
|
7
|
+
import { EffectApiBuilder, effectApiBuilder } from "./api.mjs";
|
|
8
|
+
import { EffectZodApiBuilder, effectZodApiBuilder } from "./api-zod.mjs";
|
|
9
|
+
import { projectErrorCause } from "./errors.mjs";
|
|
10
|
+
import { EffectReceiptProtectedWorkflowMutation, effectReceiptWorkflowMutation, effectTerminalWorkflowAttempt, effectWorkflowAttempt, effectWorkflowStatusBindings } from "./workflow.mjs";
|
|
11
|
+
export { type CallbackError, type CallbackRequirements, type ContractDecoderError, type ContractDecoderRequirements, ContractValidationError, type EffectApiBuilder, type EffectCrudConfig, type EffectCrudContext, type EffectCrudPage, type EffectCrudPagination, type EffectCrudRepository, type EffectCrudTable, type EffectDecoder, type EffectFoundationOptions, type EffectIdempotencyPreparation, type EffectMiddlewareInput, type EffectOperationArgument, type EffectOperationError, type EffectOperationHandlerResult, type EffectOperationInput, type EffectOperationRequirements, type EffectOperationResult, type EffectPreparation, type EffectReceiptProtectedWorkflowMutation, type EffectValue, type EffectZodApiBuilder, type OperationExecutor, type OperationPublicResult, type OperationTool, type OperationToolConverter, type OperationToolDefinition, type OperationToolJsonSchema, type OperationToolOutcome, type SelectedOperation, bindOperationExecutor, createEffectCrud, createEffectFoundation, createOperationTools, decodeEffectContract, effectApiBuilder, effectContract, effectOperationFactory, effectReceiptWorkflowMutation, effectSchema, effectStandardSchema, effectTerminalWorkflowAttempt, effectTransactionalIdempotency, effectWorkflowAttempt, effectWorkflowStatusBindings, effectZodApiBuilder, operationToolDialect, projectErrorCause, selectOperation };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{bindOperationExecutor as e,createOperationTools as t,operationToolDialect as n,selectOperation as r}from"../contracts/exposure.mjs";import{effectOperationFactory as i}from"./operation.mjs";import{ContractValidationError as a,decodeEffectContract as o,effectContract as s,effectSchema as c,effectStandardSchema as l}from"./schema.mjs";import{createEffectFoundation as u}from"./foundation.mjs";import{effectTransactionalIdempotency as d}from"./idempotency.mjs";import{createEffectCrud as f}from"./crud.mjs";import{projectErrorCause as p}from"./errors.mjs";import{effectApiBuilder as m}from"./api.mjs";import{effectZodApiBuilder as h}from"./api-zod.mjs";import{effectReceiptWorkflowMutation as g,effectTerminalWorkflowAttempt as _,effectWorkflowAttempt as v,effectWorkflowStatusBindings as y}from"./workflow.mjs";export{a as ContractValidationError,e as bindOperationExecutor,f as createEffectCrud,u as createEffectFoundation,t as createOperationTools,o as decodeEffectContract,m as effectApiBuilder,s as effectContract,i as effectOperationFactory,g as effectReceiptWorkflowMutation,c as effectSchema,l as effectStandardSchema,_ as effectTerminalWorkflowAttempt,d as effectTransactionalIdempotency,v as effectWorkflowAttempt,y as effectWorkflowStatusBindings,h as effectZodApiBuilder,n as operationToolDialect,p as projectErrorCause,r as selectOperation};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ContractOutput, ContractSchema } from "../contracts/contract.mjs";
|
|
2
|
+
import { OperationPublicResult, SelectedOperation } from "../contracts/exposure.mjs";
|
|
3
|
+
import { Observability } from "../../components/foundation/modules/observability/observability.mjs";
|
|
4
|
+
import { AuditEntryInput } from "../../components/foundation/client.mjs";
|
|
5
|
+
import { CallbackError, CallbackRequirements, CheckedEffectOperation, EffectOperationArgument, EffectOperationError, EffectOperationRequirements, EffectOperationResult, EffectValue, UnwrappedDefaultError, UnwrappedDefaultRequirements, ValidatedEffectOperations, effectOperationFactory } from "./operation.mjs";
|
|
6
|
+
import { Effect } from "effect";
|
|
7
|
+
//#region src/modules/effect/command.d.ts
|
|
8
|
+
type Supported<Value> = Value | PromiseLike<Value> | Effect.Effect<Value, unknown, unknown>;
|
|
9
|
+
type Callback = (...arguments_: never[]) => Supported<unknown>;
|
|
10
|
+
type Resolver = (host: never) => Supported<unknown>;
|
|
11
|
+
type HostOf<Resolve extends Resolver> = Parameters<Resolve>[0];
|
|
12
|
+
type DomainOf<Resolve extends Resolver> = EffectValue<ReturnType<Resolve>>;
|
|
13
|
+
type Operation = {
|
|
14
|
+
input: ContractSchema;
|
|
15
|
+
result: ContractSchema;
|
|
16
|
+
classification: string;
|
|
17
|
+
handler: Callback;
|
|
18
|
+
audit: Callback;
|
|
19
|
+
guard?: Callback;
|
|
20
|
+
prepare?: Callback;
|
|
21
|
+
middleware?: Callback;
|
|
22
|
+
permission?: string;
|
|
23
|
+
aggregates?: readonly string[];
|
|
24
|
+
replayResult?: ContractSchema;
|
|
25
|
+
};
|
|
26
|
+
type Registry<Context> = Readonly<Record<string, Pick<Operation, 'input' | 'result' | 'classification' | 'handler' | 'audit'> & CheckedEffectOperation<Context>>>;
|
|
27
|
+
type EffectCommandDependencies = {
|
|
28
|
+
observability: Observability;
|
|
29
|
+
checkPermission?: (host: never, input: {
|
|
30
|
+
permission: string;
|
|
31
|
+
operation: string;
|
|
32
|
+
}) => Supported<void>;
|
|
33
|
+
writeAudit: (host: never, entry: AuditEntryInput) => Supported<unknown>;
|
|
34
|
+
};
|
|
35
|
+
type HostParameter<Policy> = [Exclude<Policy, undefined>] extends [never] ? unknown : Exclude<Policy, undefined> extends ((...arguments_: infer Arguments) => Supported<unknown>) ? Arguments extends [] ? unknown : Arguments[0] : unknown;
|
|
36
|
+
type PolicyHost<Dependencies extends EffectCommandDependencies> = HostParameter<Dependencies['writeAudit']> & HostParameter<Dependencies['checkPermission']>;
|
|
37
|
+
type HostCompatible<Resolve extends Resolver, Dependencies extends EffectCommandDependencies> = [HostOf<Resolve>] extends [PolicyHost<Dependencies>] ? unknown : {
|
|
38
|
+
context: never;
|
|
39
|
+
};
|
|
40
|
+
type Factory<Resolve extends Resolver, Guard> = ReturnType<typeof effectOperationFactory<DomainOf<Resolve>, Record<never, never>, NoInfer<CallbackError<Guard>>, NoInfer<CallbackRequirements<Guard>>>>;
|
|
41
|
+
type EffectCommandConfiguration<Resolve extends Resolver, Operations extends Registry<DomainOf<Resolve>>, Guard> = {
|
|
42
|
+
context: Resolve;
|
|
43
|
+
operations: (define: Factory<Resolve, Guard>) => Operations & NoInfer<ValidatedEffectOperations<Operations>>;
|
|
44
|
+
defaults?: {
|
|
45
|
+
guard?: (context: DomainOf<Resolve>) => Guard;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
type ErrorOf<Definition, Resolve, Dependencies, Guard> = EffectOperationError<Definition> | CallbackError<Resolve | Dependencies[keyof Dependencies]> | UnwrappedDefaultError<Definition, Guard>;
|
|
49
|
+
type RequirementsOf<Definition, Resolve, Dependencies, Guard> = EffectOperationRequirements<Definition> | CallbackRequirements<Resolve | Dependencies[keyof Dependencies]> | UnwrappedDefaultRequirements<Definition, Guard>;
|
|
50
|
+
/** Internal registry constructor: the public Foundation binds host policies once. */
|
|
51
|
+
declare function createEffectCommand<Resolve extends Resolver, const Operations extends Registry<DomainOf<Resolve>>, const Dependencies extends EffectCommandDependencies, Guard = never>(configuration: EffectCommandConfiguration<Resolve, Operations, Guard> & Dependencies & HostCompatible<Resolve, Dependencies>): {
|
|
52
|
+
/** Bind invocation context without resolving it or running an operation. */
|
|
53
|
+
withContext(context: HostOf<Resolve>): {
|
|
54
|
+
exec: <Key extends Extract<keyof Operations, string>>(operation: Key, input: EffectOperationArgument<Operations[Key]>) => Effect.Effect<ContractOutput<Operations[Key]["result"]>, ErrorOf<Operations[Key], Resolve, Dependencies, Guard>, RequirementsOf<Operations[Key], Resolve, Dependencies, Guard>>;
|
|
55
|
+
};
|
|
56
|
+
expose<const Owner extends symbol, const Key extends Extract<keyof Operations, string>>(owner: Owner, operation: Key): SelectedOperation<Owner, Key, Operations[Key]['input'], OperationPublicResult<Operations[Key]>>;
|
|
57
|
+
exec: <Key extends Extract<keyof Operations, string>>(operation: Key, input: EffectOperationArgument<Operations[Key]>, host: HostOf<Resolve>) => Effect.Effect<EffectOperationResult<Operations[Key]>, ErrorOf<Operations[Key], Resolve, Dependencies, Guard>, RequirementsOf<Operations[Key], Resolve, Dependencies, Guard>>;
|
|
58
|
+
};
|
|
59
|
+
/** Bind trusted application policies without exposing a loose public command kernel. */
|
|
60
|
+
declare function bindEffectCommand<const Dependencies extends EffectCommandDependencies>(dependencies: Dependencies): <Resolve extends Resolver, const Operations extends Registry<DomainOf<Resolve>>, Guard = never>(configuration: EffectCommandConfiguration<Resolve, Operations, Guard> & HostCompatible<Resolve, Dependencies>) => ReturnType<typeof createEffectCommand<Resolve, Operations, Dependencies, Guard>>;
|
|
61
|
+
//#endregion
|
|
62
|
+
export { EffectCommandConfiguration, EffectCommandDependencies, bindEffectCommand, createEffectCommand };
|
|
63
|
+
//# sourceMappingURL=command.d.mts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{selectOperation as e}from"../contracts/exposure.mjs";import{effectOperationFactory as t}from"./operation.mjs";import{decodeEffectContract as n}from"./schema.mjs";import{CommandPermissionError as r,executeCommandLifecycle as i}from"../../components/foundation/modules/command/lifecycle.mjs";import{normalizeEffect as a,observationFailure as o}from"./normalize.mjs";import{Effect as s,Exit as c}from"effect";const l={succeed:s.succeed,suspend:s.suspend,flatMap:s.flatMap};function u(u){let d=u.operations(t()),p=(e,t,p)=>s.suspend(()=>{if(!Object.prototype.hasOwnProperty.call(d,e))throw Error(`The selected command operation is not configured`);let m=d[e];return s.flatMap(n(m.input,t),t=>{let d=t,h=u.observability.start({operation:e,classification:m.classification}),g=u.context;return a(()=>g(p)).pipe(s.flatMap(t=>i(l,{operation:e,classification:m.classification,context:t,command:d,permission:m.permission===void 0?void 0:()=>a(()=>{if(!u.checkPermission)throw new r(e);return u.checkPermission(p,{permission:m.permission,operation:e})}).pipe(s.asVoid),prepare:()=>a(()=>m.prepare?.(t,d)).pipe(s.map(e=>e?.kind===`execute`?{kind:`execute`,complete:e.complete?t=>a(()=>e.complete(t)).pipe(s.asVoid):void 0}:e)),decodeReplay:e=>n(m.replayResult??m.result,e),middleware:m.middleware?[e=>f(()=>m.middleware({...e,input:d}))]:[],defaultGuard:e=>a(()=>u.defaults?.guard?.(e)).pipe(s.asVoid),guard:e=>a(()=>m.guard?.(e,d)).pipe(s.asVoid),run:e=>f(()=>m.handler(d,e)),decodeResult:e=>n(m.result,e),audit:e=>a(()=>m.audit({command:d,result:e},t)),writeAudit:e=>a(()=>u.writeAudit(p,e)),aggregates:m.aggregates})),s.onExit(e=>s.sync(()=>{c.isSuccess(e)?h.completed():h.failed(o(e.cause))})))})});return{withContext(e){return{exec:(t,n)=>p(t,n,e)}},expose(t,n){if(!Object.hasOwn(d,n))throw Error(`The selected command operation is not configured`);return e(t,`mutation`,n,d[n])},exec:p}}function d(e){return function(t){return u({...t,...e})}}function f(e){return a(e)}export{d as bindEffectCommand,u as createEffectCommand};
|
|
2
|
+
//# sourceMappingURL=command.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.mjs","names":[],"sources":["../../../src/modules/effect/command.ts"],"sourcesContent":["import { 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\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 operations: 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\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\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(\n\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)\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 {\n\t\t/** Bind invocation context without resolving it or running an operation. */\n\t\twithContext(context: HostOf<Resolve>) {\n\t\t\treturn {\n\t\t\t\texec: <Key extends Extract<keyof Operations, string>>(\n\t\t\t\t\toperation: Key,\n\t\t\t\t\tinput: EffectOperationArgument<Operations[Key]>,\n\t\t\t\t) => exec(operation, input, context),\n\t\t\t}\n\t\t},\n\t\texpose<const Owner extends symbol, const Key extends Extract<keyof Operations, string>>(\n\t\t\towner: Owner,\n\t\t\toperation: Key,\n\t\t): SelectedOperation<\n\t\t\tOwner,\n\t\t\tKey,\n\t\t\tOperations[Key]['input'],\n\t\t\tOperationPublicResult<Operations[Key]>\n\t\t> {\n\t\t\tif (!Object.hasOwn(operations, operation))\n\t\t\t\tthrow Error('The selected command operation is not configured')\n\t\t\treturn selectOperation(owner, 'mutation', operation, operations[operation])\n\t\t},\n\t\texec,\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\treturn function 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\t\treturn createEffectCommand<Resolve, Operations, Dependencies, Guard>({\n\t\t\t...configuration,\n\t\t\t...dependencies,\n\t\t})\n\t}\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":"6ZA0HA,MAAM,EAAqD,CAC1D,QAAS,EAAO,QAChB,QAAS,EAAO,QAChB,QAAS,EAAO,OACjB,EA4BA,SAAgB,EAMf,EAGC,CACD,IAAM,EACL,EAAc,WACb,EAKE,CACH,EACK,GACL,EACA,EACA,IAMkB,EAAO,YAAc,CACtC,GAAI,CAAC,OAAO,UAAU,eAAe,KAAK,EAAY,CAAS,EAC9D,MAAM,MAAM,kDAAkD,EAE/D,IAAM,EAAa,EAAW,GAQ9B,OAAO,EAAO,QAAQ,EAAqB,EAAW,MAAO,CAAK,EAAI,GAAY,CAEjF,IAAM,EAAU,EACV,EAAc,EAAc,cAAc,MAAM,CACrD,YACA,eAAgB,EAAW,cAC5B,CAAC,EAEK,EAAU,EAAc,QAC9B,OAAO,MAAsB,EAAQ,CAAI,CAAC,CAAC,CAAC,KAC3C,EAAO,QAAS,GACG,EAMhB,EAAiB,CAClB,YACA,eAAgB,EAAW,eAC3B,UACA,UACA,WACC,EAAW,aAAe,IAAA,GACvB,IAAA,OAEA,MAAsB,CACrB,GAAI,CAAC,EAAc,gBAClB,MAAM,IAAI,EAAuB,CAAS,EAE3C,OAAO,EAAc,gBAAgB,EAAe,CACnD,WAAY,EAAW,WACvB,WACD,CAAC,CACF,CAAC,CAAC,CAAC,KAAK,EAAO,MAAM,EACzB,YACC,MAAsB,EAAW,UAAU,EAAS,CAAO,CAAC,CAAC,CAAC,KAC7D,EAAO,IAAK,GACP,GAAa,OAAS,UACnB,CACN,KAAM,UACN,SAAU,EAAY,SAClB,GACD,MAAsB,EAAY,SAAU,CAAM,CAAC,CAAC,CAAC,KACpD,EAAO,MACR,EACA,IAAA,EACJ,EAT4C,CAa5C,CACF,EAED,aAAe,GACd,EACC,EAAW,cAAgB,EAAW,OACtC,CACD,EACD,WAAY,EAAW,WACpB,CACC,GACA,MACC,EAAW,WAAY,CAAE,GAAG,EAAQ,MAAO,CAAQ,CAAC,CACrD,CACF,EACC,CAAC,EACJ,aAAe,GACd,MAAsB,EAAc,UAAU,QAAQ,CAAQ,CAAC,CAAC,CAAC,KAChE,EAAO,MACR,EACD,MAAQ,GACP,MAAsB,EAAW,QAAQ,EAAU,CAAO,CAAC,CAAC,CAAC,KAAK,EAAO,MAAM,EAChF,IAAM,GACL,MAA6B,EAAW,QAAQ,EAAS,CAAQ,CAAC,EAEnE,aAAe,GACd,EAAqB,EAAW,OAAQ,CAAK,EAK9C,MAAQ,GACP,MAAsB,EAAW,MAAM,CAAE,UAAS,QAAO,EAAG,CAAO,CAAC,EACrE,WAAa,GACZ,MAEQ,EAAc,WAAW,EAAe,CAAK,CACpD,EACF,WAAY,EAAW,UACxB,CACe,CACf,EACD,EAAO,OAAQ,GACd,EAAO,SAAW,CACb,EAAK,UAAU,CAAI,EAAG,EAAY,UAAU,EAC3C,EAAY,OAAO,EAAmB,EAAK,KAAK,CAAC,CACvD,CAAC,CACF,CACD,CACD,CAAC,CACF,CAEe,EAMhB,MAAO,CAEN,YAAY,EAA0B,CACrC,MAAO,CACN,MACC,EACA,IACI,EAAK,EAAW,EAAO,CAAO,CACpC,CACD,EACA,OACC,EACA,EAMC,CACD,GAAI,CAAC,OAAO,OAAO,EAAY,CAAS,EACvC,MAAM,MAAM,kDAAkD,EAC/D,OAAO,EAAgB,EAAO,WAAY,EAAW,EAAW,EAAU,CAC3E,EACA,MACD,CACD,CAGA,SAAgB,EACf,EACC,CACD,OAAO,SAKN,EAEmF,CACnF,OAAO,EAA8D,CACpE,GAAG,EACH,GAAG,CACJ,CAAC,CACF,CACD,CAEA,SAAS,EACR,EACyC,CAEzC,OAAO,EAAgB,CAAM,CAC9B"}
|