cvx-kit 0.2.0 → 2.0.0-beta.0
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/README.md +556 -99
- package/dist/agent-tools.d.mts +39 -26
- package/dist/agent-tools.mjs +1 -1
- package/dist/agent-tools.mjs.map +1 -1
- package/dist/auth.d.mts +120 -308
- package/dist/auth.mjs +1 -1
- package/dist/auth.mjs.map +1 -1
- package/dist/components/approvals/_generated/api.d.mts +7 -9
- package/dist/components/approvals/_generated/api.mjs.map +1 -1
- package/dist/components/approvals/_generated/component.d.mts +1 -4
- package/dist/components/approvals/_generated/dataModel.d.mts +5 -8
- package/dist/components/approvals/_generated/server.d.mts +12 -15
- package/dist/components/approvals/_generated/server.mjs.map +1 -1
- package/dist/components/approvals/audit.d.mts +8 -9
- package/dist/components/approvals/audit.mjs +1 -1
- package/dist/components/approvals/audit.mjs.map +1 -1
- package/dist/components/approvals/client.d.mts +11 -12
- package/dist/components/approvals/client.mjs +1 -1
- package/dist/components/approvals/client.mjs.map +1 -1
- package/dist/components/approvals/constants.d.mts +30 -31
- package/dist/components/approvals/constants.mjs.map +1 -1
- package/dist/components/approvals/convex.config.d.mts +0 -2
- package/dist/components/approvals/convex.config.mjs.map +1 -1
- package/dist/components/approvals/decisions.d.mts +13 -17
- package/dist/components/approvals/decisions.mjs +1 -1
- package/dist/components/approvals/decisions.mjs.map +1 -1
- package/dist/components/approvals/functions.d.mts +3 -4
- package/dist/components/approvals/functions.mjs +1 -1
- package/dist/components/approvals/functions.mjs.map +1 -1
- package/dist/components/approvals/health.d.mts +2 -3
- package/dist/components/approvals/health.mjs.map +1 -1
- package/dist/components/approvals/requests.d.mts +114 -131
- package/dist/components/approvals/requests.mjs +1 -1
- package/dist/components/approvals/requests.mjs.map +1 -1
- package/dist/components/approvals/schema.d.ts +106 -315
- package/dist/components/approvals/schema.js +1 -1
- package/dist/components/approvals/validators.d.mts +323 -395
- package/dist/components/approvals/validators.mjs +1 -1
- package/dist/components/approvals/validators.mjs.map +1 -1
- package/dist/components/approvals/workflow.d.mts +4 -5
- package/dist/components/approvals/workflow.mjs +1 -1
- package/dist/components/approvals/workflow.mjs.map +1 -1
- package/dist/components/approvals/workflow_steps.d.mts +16 -17
- package/dist/components/approvals/workflow_steps.mjs +1 -1
- package/dist/components/approvals/workflow_steps.mjs.map +1 -1
- package/dist/components/foundation/_generated/api.d.mts +6 -8
- package/dist/components/foundation/_generated/api.mjs.map +1 -1
- package/dist/components/foundation/_generated/component.d.mts +1 -4
- package/dist/components/foundation/_generated/dataModel.d.mts +5 -8
- package/dist/components/foundation/_generated/server.d.mts +12 -15
- package/dist/components/foundation/_generated/server.mjs.map +1 -1
- package/dist/components/foundation/client.d.mts +45 -38
- package/dist/components/foundation/client.mjs +1 -1
- package/dist/components/foundation/client.mjs.map +1 -1
- package/dist/components/foundation/convex.config.d.mts +0 -2
- package/dist/components/foundation/convex.config.mjs.map +1 -1
- package/dist/components/foundation/functions.d.mts +2 -3
- package/dist/components/foundation/functions.mjs.map +1 -1
- package/dist/components/foundation/modules/command/command.d.mts +65 -17
- 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 +78 -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 +13 -6
- 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/modules/query/query.d.mts +11 -12
- package/dist/components/foundation/modules/query/query.mjs +1 -1
- package/dist/components/foundation/modules/query/query.mjs.map +1 -1
- package/dist/components/foundation/operation.d.mts +72 -0
- package/dist/components/foundation/operation.mjs +2 -0
- package/dist/components/foundation/operation.mjs.map +1 -0
- package/dist/components/foundation/result.d.mts +7 -8
- package/dist/components/foundation/result.mjs.map +1 -1
- package/dist/components/foundation/schema.d.ts +0 -2
- package/dist/components/foundation/telemetry.d.mts +2 -3
- package/dist/components/foundation/telemetry.mjs +1 -1
- package/dist/components/foundation/telemetry.mjs.map +1 -1
- package/dist/contracts.d.mts +5 -0
- package/dist/contracts.mjs +1 -0
- package/dist/crud.d.mts +185 -27
- package/dist/crud.mjs +1 -1
- package/dist/crud.mjs.map +1 -1
- package/dist/effect.d.mts +16 -0
- package/dist/effect.mjs +1 -0
- package/dist/errors.d.mts +6 -6
- package/dist/errors.mjs +1 -1
- package/dist/errors.mjs.map +1 -1
- package/dist/filters.d.mts +4 -0
- package/dist/filters.mjs +1 -0
- package/dist/idempotency.d.mts +2 -0
- package/dist/idempotency.mjs +1 -0
- package/dist/index.d.mts +14 -7
- package/dist/index.mjs +1 -1
- package/dist/json-schema.d.mts +40 -0
- package/dist/json-schema.mjs +2 -0
- package/dist/json-schema.mjs.map +1 -0
- package/dist/k/compile.d.mts +17 -0
- package/dist/k/compile.mjs +2 -0
- package/dist/k/compile.mjs.map +1 -0
- package/dist/k/dates.d.mts +23 -0
- package/dist/k/dates.mjs +2 -0
- package/dist/k/dates.mjs.map +1 -0
- package/dist/k/formats.d.mts +24 -0
- package/dist/k/formats.mjs +2 -0
- package/dist/k/formats.mjs.map +1 -0
- package/dist/k/index.d.mts +32 -0
- package/dist/k/index.mjs +2 -0
- package/dist/k/index.mjs.map +1 -0
- package/dist/k/issues.d.mts +31 -0
- package/dist/k/issues.mjs +2 -0
- package/dist/k/issues.mjs.map +1 -0
- package/dist/k/kinds.d.mts +81 -0
- package/dist/k/kinds.mjs +2 -0
- package/dist/k/kinds.mjs.map +1 -0
- package/dist/k/object.d.mts +43 -0
- package/dist/k/object.mjs +2 -0
- package/dist/k/object.mjs.map +1 -0
- package/dist/k/parse.d.mts +29 -0
- package/dist/k/parse.mjs +2 -0
- package/dist/k/parse.mjs.map +1 -0
- package/dist/k/schema.d.mts +100 -0
- package/dist/k/schema.mjs +2 -0
- package/dist/k/schema.mjs.map +1 -0
- package/dist/k/standard.d.mts +8 -0
- package/dist/k/standard.mjs +2 -0
- package/dist/k/standard.mjs.map +1 -0
- package/dist/k/types.d.mts +64 -0
- package/dist/k/types.mjs +1 -0
- package/dist/k.d.mts +8 -0
- package/dist/k.mjs +1 -0
- package/dist/middleware.d.mts +8 -11
- package/dist/middleware.mjs +1 -1
- package/dist/middleware.mjs.map +1 -1
- package/dist/modules/contracts/binding.d.mts +23 -0
- package/dist/modules/contracts/binding.mjs +2 -0
- package/dist/modules/contracts/binding.mjs.map +1 -0
- package/dist/modules/contracts/contract.d.mts +67 -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 +18 -0
- package/dist/modules/contracts/convex.mjs +2 -0
- package/dist/modules/contracts/convex.mjs.map +1 -0
- package/dist/modules/contracts/domain.d.mts +62 -0
- package/dist/modules/contracts/domain.mjs +2 -0
- package/dist/modules/contracts/domain.mjs.map +1 -0
- package/dist/modules/contracts/errors.d.mts +737 -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 +103 -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 +85 -0
- package/dist/modules/contracts/idempotency.mjs +2 -0
- package/dist/modules/contracts/idempotency.mjs.map +1 -0
- package/dist/modules/contracts/lazy.d.mts +6 -0
- package/dist/modules/contracts/lazy.mjs +2 -0
- package/dist/modules/contracts/lazy.mjs.map +1 -0
- package/dist/modules/contracts/standard.d.mts +17 -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 +165 -0
- package/dist/modules/contracts/workflow.mjs +2 -0
- package/dist/modules/contracts/workflow.mjs.map +1 -0
- package/dist/modules/effect/action.d.mts +63 -0
- package/dist/modules/effect/action.mjs +2 -0
- package/dist/modules/effect/action.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 +36 -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.d.mts +46 -0
- package/dist/modules/effect/api.mjs +2 -0
- package/dist/modules/effect/api.mjs.map +1 -0
- package/dist/modules/effect/auth.d.mts +46 -0
- package/dist/modules/effect/auth.mjs +2 -0
- package/dist/modules/effect/auth.mjs.map +1 -0
- package/dist/modules/effect/client.d.mts +15 -0
- package/dist/modules/effect/client.mjs +1 -0
- package/dist/modules/effect/command.d.mts +108 -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 +885 -0
- package/dist/modules/effect/crud.mjs +2 -0
- package/dist/modules/effect/crud.mjs.map +1 -0
- package/dist/modules/effect/domain.d.mts +82 -0
- package/dist/modules/effect/domain.mjs +2 -0
- package/dist/modules/effect/domain.mjs.map +1 -0
- package/dist/modules/effect/errors.d.mts +13 -0
- package/dist/modules/effect/errors.mjs +2 -0
- package/dist/modules/effect/errors.mjs.map +1 -0
- package/dist/modules/effect/failure-audit.d.mts +48 -0
- package/dist/modules/effect/failure-audit.mjs +2 -0
- package/dist/modules/effect/failure-audit.mjs.map +1 -0
- package/dist/modules/effect/failures.d.mts +21 -0
- package/dist/modules/effect/failures.mjs +2 -0
- package/dist/modules/effect/failures.mjs.map +1 -0
- package/dist/modules/effect/foundation.d.mts +23 -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 +29 -0
- package/dist/modules/effect/idempotency.mjs +2 -0
- package/dist/modules/effect/idempotency.mjs.map +1 -0
- package/dist/modules/effect/input.d.mts +10 -0
- package/dist/modules/effect/input.mjs +2 -0
- package/dist/modules/effect/input.mjs.map +1 -0
- package/dist/modules/effect/normalize.d.mts +7 -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 +148 -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 +90 -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 +30 -0
- package/dist/modules/effect/schema.mjs +2 -0
- package/dist/modules/effect/schema.mjs.map +1 -0
- package/dist/modules/effect/scope.d.mts +25 -0
- package/dist/modules/effect/scope.mjs +2 -0
- package/dist/modules/effect/scope.mjs.map +1 -0
- package/dist/modules/effect/workflow.d.mts +75 -0
- package/dist/modules/effect/workflow.mjs +2 -0
- package/dist/modules/effect/workflow.mjs.map +1 -0
- package/dist/modules/foundation/foundation.d.mts +108 -0
- package/dist/modules/foundation/foundation.mjs +2 -0
- package/dist/modules/foundation/foundation.mjs.map +1 -0
- package/dist/modules/foundation/operation.d.mts +139 -0
- package/dist/modules/foundation/operation.mjs +2 -0
- package/dist/modules/foundation/operation.mjs.map +1 -0
- package/dist/namespace.d.mts +104 -0
- package/dist/namespace.mjs +2 -0
- package/dist/namespace.mjs.map +1 -0
- package/dist/oxlint/architecture.d.mts +23 -0
- package/dist/oxlint/architecture.mjs +2 -0
- package/dist/oxlint/architecture.mjs.map +1 -0
- package/dist/oxlint/ast.d.mts +51 -0
- package/dist/oxlint/ast.mjs +2 -0
- package/dist/oxlint/ast.mjs.map +1 -0
- package/dist/oxlint/components.d.mts +4 -0
- package/dist/oxlint/components.mjs +2 -0
- package/dist/oxlint/components.mjs.map +1 -0
- package/dist/oxlint/ownership.d.mts +59 -0
- package/dist/oxlint/ownership.mjs +2 -0
- package/dist/oxlint/ownership.mjs.map +1 -0
- package/dist/oxlint/reserved-files.d.mts +4 -0
- package/dist/oxlint/reserved-files.mjs +2 -0
- package/dist/oxlint/reserved-files.mjs.map +1 -0
- package/dist/oxlint.d.mts +9 -0
- package/dist/oxlint.mjs +2 -0
- package/dist/oxlint.mjs.map +1 -0
- package/dist/querying/cursors.d.mts +94 -0
- package/dist/querying/cursors.mjs +2 -0
- package/dist/querying/cursors.mjs.map +1 -0
- package/dist/querying/execution.d.mts +40 -0
- package/dist/querying/execution.mjs +2 -0
- package/dist/querying/execution.mjs.map +1 -0
- package/dist/querying/failures.d.mts +11 -0
- package/dist/querying/failures.mjs +2 -0
- package/dist/querying/failures.mjs.map +1 -0
- package/dist/querying/filter-boundary.d.mts +25 -0
- package/dist/querying/filter-boundary.mjs +2 -0
- package/dist/querying/filter-boundary.mjs.map +1 -0
- package/dist/querying/filters.d.mts +180 -0
- package/dist/querying/filters.mjs +2 -0
- package/dist/querying/filters.mjs.map +1 -0
- package/dist/querying/planner.d.mts +61 -0
- package/dist/querying/planner.mjs +2 -0
- package/dist/querying/planner.mjs.map +1 -0
- package/dist/querying/relationships.d.mts +58 -0
- package/dist/querying/relationships.mjs +2 -0
- package/dist/querying/relationships.mjs.map +1 -0
- package/dist/querying/search.d.mts +69 -0
- package/dist/querying/search.mjs +2 -0
- package/dist/querying/search.mjs.map +1 -0
- package/dist/querying/security.d.mts +123 -0
- package/dist/querying/security.mjs +2 -0
- package/dist/querying/security.mjs.map +1 -0
- package/dist/querying/shared/ast.d.mts +26 -0
- package/dist/querying/shared/ast.mjs +2 -0
- package/dist/querying/shared/ast.mjs.map +1 -0
- package/dist/querying/shared/contract.d.mts +98 -0
- package/dist/querying/shared/contract.mjs +2 -0
- package/dist/querying/shared/contract.mjs.map +1 -0
- package/dist/querying/shared/evaluate.d.mts +5 -0
- package/dist/querying/shared/evaluate.mjs +2 -0
- package/dist/querying/shared/evaluate.mjs.map +1 -0
- package/dist/querying/shared/filters.d.mts +65 -0
- package/dist/querying/shared/filters.mjs +2 -0
- package/dist/querying/shared/filters.mjs.map +1 -0
- package/dist/querying/shared/native-json.d.mts +7 -0
- package/dist/querying/shared/native-json.mjs +2 -0
- package/dist/querying/shared/native-json.mjs.map +1 -0
- package/dist/querying/shared/page.d.mts +20 -0
- package/dist/querying/shared/page.mjs +2 -0
- package/dist/querying/shared/page.mjs.map +1 -0
- package/dist/querying.d.mts +82 -0
- package/dist/querying.mjs +2 -0
- package/dist/querying.mjs.map +1 -0
- package/dist/react/failures.d.mts +24 -0
- package/dist/react/failures.mjs +2 -0
- package/dist/react/failures.mjs.map +1 -0
- package/dist/react/optimistic.d.mts +46 -0
- package/dist/react/optimistic.mjs +2 -0
- package/dist/react/optimistic.mjs.map +1 -0
- package/dist/react/pagination-state.d.mts +39 -0
- package/dist/react/pagination-state.mjs +2 -0
- package/dist/react/pagination-state.mjs.map +1 -0
- package/dist/react/use-command.d.mts +22 -0
- package/dist/react/use-command.mjs +2 -0
- package/dist/react/use-command.mjs.map +1 -0
- package/dist/react/use-paginated-list.d.mts +34 -0
- package/dist/react/use-paginated-list.mjs +2 -0
- package/dist/react/use-paginated-list.mjs.map +1 -0
- package/dist/react.d.mts +6 -0
- package/dist/react.mjs +1 -0
- package/dist/registration.d.mts +65 -0
- package/dist/registration.mjs +2 -0
- package/dist/registration.mjs.map +1 -0
- package/dist/relations-public.d.mts +2 -0
- package/dist/relations-public.mjs +1 -0
- package/dist/relations.d.mts +274 -0
- package/dist/relations.mjs +2 -0
- package/dist/relations.mjs.map +1 -0
- package/dist/state-machine.d.mts +1 -4
- package/dist/state-machine.mjs.map +1 -1
- package/dist/table.d.mts +222 -0
- package/dist/table.mjs +2 -0
- package/dist/table.mjs.map +1 -0
- package/dist/tenancy.d.mts +6 -8
- package/dist/tenancy.mjs +1 -1
- package/dist/tenancy.mjs.map +1 -1
- package/dist/triggers.d.mts +12 -10
- package/dist/triggers.mjs +1 -1
- package/dist/triggers.mjs.map +1 -1
- package/dist/webhooks.d.mts +22 -112
- package/dist/webhooks.mjs +1 -1
- package/dist/webhooks.mjs.map +1 -1
- package/dist/workflow.d.mts +2 -0
- package/dist/workflow.mjs +1 -0
- package/dist/zod.d.mts +30 -0
- package/dist/zod.mjs +2 -0
- package/dist/zod.mjs.map +1 -0
- package/package.json +145 -33
- package/src/test.ts +9 -17
- package/CHANGELOG.md +0 -145
- package/ROADMAP.md +0 -126
- package/dist/zod-table.d.mts +0 -175
- package/dist/zod-table.mjs +0 -2
- package/dist/zod-table.mjs.map +0 -1
- package/docs/agent-tools.md +0 -41
- package/docs/approvals.md +0 -200
- package/docs/architecture.md +0 -124
- package/docs/auth.md +0 -218
- package/docs/commands.md +0 -278
- package/docs/conventions.md +0 -291
- package/docs/crud.md +0 -62
- package/docs/llms.md +0 -220
- package/docs/maintainability.md +0 -124
- package/docs/migration.md +0 -351
- package/docs/plans/2026-08-14-001-feat-v0.1.0-feature-set-plan.md +0 -461
- package/docs/plans/2026-08-21-0930-feat-resolve-organization-hook-plan.md +0 -178
- package/docs/tenancy.md +0 -179
- package/docs/triggers.md +0 -75
- package/docs/upgrading.md +0 -175
- package/docs/webhooks.md +0 -58
- package/docs/zod-table.md +0 -173
- package/scripts/convex-config-bridge.mjs +0 -55
- package/scripts/extract-changelog.mjs +0 -29
- package/scripts/smoke-packed-components.mjs +0 -374
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { ContractInput, ContractOutput, ContractSchema } from "../contracts/contract.mjs";
|
|
2
|
+
import { ContractDecoderError, ContractDecoderRequirements } from "./schema.mjs";
|
|
3
|
+
import { AuditEntryInput } from "../../components/foundation/client.mjs";
|
|
4
|
+
import { RequestScope } from "./scope.mjs";
|
|
5
|
+
import { Effect } from "effect";
|
|
6
|
+
/** Ordinary failures are defects; only an explicit Effect supplies a typed error. */
|
|
7
|
+
export type CallbackError<Value> = Value extends ((...arguments_: never[]) => infer Returned) ? CallbackError<Returned> : Value extends Effect.Effect<infer Success, infer Error, unknown> ? Error | CallbackError<Success> : Value extends PromiseLike<infer Awaited> ? CallbackError<Awaited> : Value extends readonly (infer Item)[] ? CallbackError<Item> : Value extends {
|
|
8
|
+
kind: 'execute';
|
|
9
|
+
complete?: infer Complete;
|
|
10
|
+
} ? CallbackError<Complete> : never;
|
|
11
|
+
export type CallbackRequirements<Value> = Value extends ((...arguments_: never[]) => infer Returned) ? CallbackRequirements<Returned> : Value extends Effect.Effect<infer Success, unknown, infer Requirements> ? Requirements | CallbackRequirements<Success> : Value extends PromiseLike<infer Awaited> ? CallbackRequirements<Awaited> : Value extends readonly (infer Item)[] ? CallbackRequirements<Item> : Value extends {
|
|
12
|
+
kind: 'execute';
|
|
13
|
+
complete?: infer Complete;
|
|
14
|
+
} ? CallbackRequirements<Complete> : never;
|
|
15
|
+
export type EffectValue<Value> = Value extends Effect.Effect<infer Success, unknown, unknown> ? EffectValue<Success> : Value extends PromiseLike<infer Awaited> ? EffectValue<Awaited> : Value;
|
|
16
|
+
declare const checkedOperation: unique symbol;
|
|
17
|
+
/** Type-only evidence that the helper checked callbacks against the base context and schemas. */
|
|
18
|
+
export type CheckedEffectOperation<Context> = {
|
|
19
|
+
readonly [checkedOperation]: {
|
|
20
|
+
context: (context: Context) => void;
|
|
21
|
+
error: unknown;
|
|
22
|
+
requirements: unknown;
|
|
23
|
+
definition: unknown;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
type CheckedChannels<Context, Error, Requirements, Definition> = {
|
|
27
|
+
readonly [checkedOperation]: {
|
|
28
|
+
context: (context: Context) => void;
|
|
29
|
+
error: Error;
|
|
30
|
+
requirements: Requirements;
|
|
31
|
+
definition: Definition;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
/** Named checked-definition boundary keeps the private evidence marker inside this module's declarations. */
|
|
35
|
+
export type CheckedEffectDefinition<Context, Definition, Error = never, Requirements = never> = NoInfer<Omit<Definition, typeof checkedOperation>> & CheckedChannels<Context, Error, Requirements, Omit<Definition, typeof checkedOperation>>;
|
|
36
|
+
/** Reject stale helper evidence after callbacks or schemas are replaced. */
|
|
37
|
+
export type ValidatedEffectOperations<Operations> = { [Key in keyof Operations]: Operations[Key] extends {
|
|
38
|
+
readonly [checkedOperation]: {
|
|
39
|
+
definition: infer Definition;
|
|
40
|
+
};
|
|
41
|
+
} ? Operations[Key] extends Definition ? Operations[Key] : never : never; };
|
|
42
|
+
/** Only middleware whose next contract captured a default policy can discharge its channels. */
|
|
43
|
+
export type UnwrappedDefaultError<Definition, Guard> = Definition extends {
|
|
44
|
+
middleware: Function;
|
|
45
|
+
} ? Definition extends CheckedChannels<never, infer Error, unknown, unknown> ? Exclude<CallbackError<Guard>, Error> : CallbackError<Guard> : CallbackError<Guard>;
|
|
46
|
+
export type UnwrappedDefaultRequirements<Definition, Guard> = Definition extends {
|
|
47
|
+
middleware: Function;
|
|
48
|
+
} ? Definition extends CheckedChannels<never, unknown, infer Requirements, unknown> ? Exclude<CallbackRequirements<Guard>, Requirements> : CallbackRequirements<Guard> : CallbackRequirements<Guard>;
|
|
49
|
+
export type EffectOperationArgument<Definition extends {
|
|
50
|
+
input: ContractSchema;
|
|
51
|
+
}> = ContractInput<Definition['input']>;
|
|
52
|
+
export type EffectOperationInput<Definition extends {
|
|
53
|
+
input: ContractSchema;
|
|
54
|
+
}> = ContractOutput<Definition['input']>;
|
|
55
|
+
export type EffectOperationHandlerResult<Definition extends {
|
|
56
|
+
result: ContractSchema;
|
|
57
|
+
}> = ContractInput<Definition['result']>;
|
|
58
|
+
export type EffectOperationResult<Definition extends {
|
|
59
|
+
result: ContractSchema;
|
|
60
|
+
}> = ContractOutput<Definition['result']>;
|
|
61
|
+
type Hook<Definition, Key extends PropertyKey> = Key extends keyof Definition ? Definition[Key] : never;
|
|
62
|
+
type Returned<Callback> = Callback extends ((...arguments_: never[]) => infer Value) ? Value : never;
|
|
63
|
+
/** A conditional wrapper must retain the unwrapped channels for its absent branch. */
|
|
64
|
+
type CoreValue<Definition> = [Returned<Hook<Definition, 'middleware'>>] extends [never] ? Returned<Hook<Definition, 'handler'>> | Returned<Hook<Definition, 'guard'>> : undefined extends Hook<Definition, 'middleware'> ? Returned<Hook<Definition, 'handler'>> | Returned<Hook<Definition, 'guard'>> | Returned<Hook<Definition, 'middleware'>> : Returned<Hook<Definition, 'middleware'>>;
|
|
65
|
+
type OutsideHooks = 'prepare' | 'audit' | 'checkPermission' | 'writeAudit';
|
|
66
|
+
export type EffectOperationError<Definition> = ContractDecoderError<Hook<Definition, 'input'>> | ContractDecoderError<Hook<Definition, 'result'>> | ContractDecoderError<Hook<Definition, 'replayResult'>> | CallbackError<CoreValue<Definition>> | CallbackError<Definition[Extract<keyof Definition, OutsideHooks>]>;
|
|
67
|
+
export type EffectOperationRequirements<Definition> = ContractDecoderRequirements<Hook<Definition, 'input'>> | ContractDecoderRequirements<Hook<Definition, 'result'>> | ContractDecoderRequirements<Hook<Definition, 'replayResult'>> | CallbackRequirements<CoreValue<Definition>> | CallbackRequirements<Definition[Extract<keyof Definition, OutsideHooks>]>;
|
|
68
|
+
type Supported<Value, Error = unknown, Requirements = unknown> = Value | PromiseLike<Value> | Effect.Effect<Value, Error, Requirements>;
|
|
69
|
+
export type EffectPreparation<Result, Error = never, Requirements = never> = {
|
|
70
|
+
kind: 'replay';
|
|
71
|
+
result: unknown;
|
|
72
|
+
} | {
|
|
73
|
+
kind: 'execute';
|
|
74
|
+
complete?: (result: Result) => Supported<void, Error, Requirements>;
|
|
75
|
+
};
|
|
76
|
+
export type EffectMiddlewareInput<Context, Input, Result, Extension, Error = never, Requirements = never> = {
|
|
77
|
+
operation: string;
|
|
78
|
+
context: Context;
|
|
79
|
+
command: Input;
|
|
80
|
+
input: Input;
|
|
81
|
+
next: keyof Extension extends never ? (options?: {
|
|
82
|
+
context?: Extension;
|
|
83
|
+
}) => Effect.Effect<Result, Error, Requirements> : (options: {
|
|
84
|
+
context: Extension;
|
|
85
|
+
}) => Effect.Effect<Result, Error, Requirements>;
|
|
86
|
+
};
|
|
87
|
+
type Audit<Aggregates extends readonly string[]> = Omit<AuditEntryInput, 'classification' | 'aggregate'> & {
|
|
88
|
+
aggregate: {
|
|
89
|
+
type: Aggregates[number];
|
|
90
|
+
id: string;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
export type OperationDefinition<Context, Input extends ContractSchema, Output extends ContractSchema, Extension, Aggregates extends readonly string[], Handler, Guard, Preparation, AuditResult, Middleware, Metadata, BaseError, BaseRequirements, Wire extends ContractSchema, Replay extends ContractSchema> = {
|
|
94
|
+
input: Input;
|
|
95
|
+
result: Output;
|
|
96
|
+
handler: (input: ContractOutput<Input>, context: Context & Extension) => Handler;
|
|
97
|
+
classification?: string;
|
|
98
|
+
permission?: string;
|
|
99
|
+
metadata?: Metadata;
|
|
100
|
+
aggregates?: Aggregates;
|
|
101
|
+
replayResult?: Replay & (ContractOutput<Replay> extends ContractOutput<Output> ? unknown : never);
|
|
102
|
+
wire?: {
|
|
103
|
+
schema: Wire;
|
|
104
|
+
project: (value: ContractOutput<Output>) => ContractInput<Wire>;
|
|
105
|
+
};
|
|
106
|
+
guard?: (context: Context & Extension, input: ContractOutput<Input>) => Guard;
|
|
107
|
+
prepare?: (context: Context, input: ContractOutput<Input>) => Preparation;
|
|
108
|
+
audit?: (resolution: {
|
|
109
|
+
command: ContractOutput<Input>;
|
|
110
|
+
result: ContractOutput<Output>;
|
|
111
|
+
}, context: Context, scope: RequestScope | undefined) => AuditResult;
|
|
112
|
+
} & (keyof Extension extends never ? {
|
|
113
|
+
middleware?: (input: EffectMiddlewareInput<Context, ContractOutput<Input>, ContractInput<Output>, Extension, BaseError | CallbackError<Handler | Guard>, BaseRequirements | CallbackRequirements<Handler | Guard>>) => Middleware;
|
|
114
|
+
} : {
|
|
115
|
+
middleware: (input: EffectMiddlewareInput<Context, ContractOutput<Input>, ContractInput<Output>, Extension, BaseError | CallbackError<Handler | Guard>, BaseRequirements | CallbackRequirements<Handler | Guard>>) => Middleware;
|
|
116
|
+
});
|
|
117
|
+
/**
|
|
118
|
+
* Bind context once; middleware wraps the handler/guard channels and may discharge them.
|
|
119
|
+
* Declare contextual guards/handlers before middleware, or annotate their parameters
|
|
120
|
+
* and returned Effect channels when middleware comes first. TypeScript processes
|
|
121
|
+
* context-sensitive object callbacks in declaration order.
|
|
122
|
+
*/
|
|
123
|
+
export declare function effectOperationFactory<Context, Extension extends Record<string, unknown> = Record<never, never>, BaseError = never, BaseRequirements = never, AuditRequired extends boolean = true>(): {
|
|
124
|
+
operation: <const Input extends ContractSchema, const Output extends ContractSchema, Handler extends Supported<ContractInput<Output>>, Guard extends Supported<void> = never, Preparation extends Supported<EffectPreparation<ContractOutput<Output>, unknown, unknown>> = never, const Aggregates extends readonly string[] = readonly string[], AuditResult extends Supported<Audit<Aggregates> | null> = never, Middleware extends Supported<ContractInput<Output>> = never, const Metadata extends object = Record<never, never>, const Wire extends ContractSchema = ContractSchema, const Replay extends ContractSchema = never, const Definition extends object = object>(definition: Definition & OperationDefinition<Context, Input, Output, Extension, Aggregates, Handler, Guard, Preparation, AuditResult, Middleware, Metadata, BaseError, BaseRequirements, Wire, Replay>) => CheckedEffectDefinition<Context, typeof definition, BaseError, BaseRequirements>;
|
|
125
|
+
command: <const Input extends ContractSchema, const Output extends ContractSchema, Handler extends Supported<ContractInput<Output>>, Guard extends Supported<void> = never, Preparation extends Supported<EffectPreparation<ContractOutput<Output>, unknown, unknown>> = never, const Aggregates extends readonly string[] = readonly string[], AuditResult extends Supported<Audit<Aggregates> | null> = never, Middleware extends Supported<ContractInput<Output>> = never, const Metadata extends object = Record<never, never>, const Wire extends ContractSchema = ContractSchema, const Replay extends ContractSchema = never, const Definition extends object = object>(definition: Definition & OperationDefinition<Context, Input, Output, Extension, Aggregates, Handler, Guard, Preparation, AuditResult, Middleware, Metadata, BaseError, BaseRequirements, Wire, Replay> & {
|
|
126
|
+
classification: string;
|
|
127
|
+
} & (AuditRequired extends true ? {
|
|
128
|
+
audit: (resolution: {
|
|
129
|
+
command: ContractOutput<Input>;
|
|
130
|
+
result: ContractOutput<Output>;
|
|
131
|
+
}, context: Context, scope: RequestScope | undefined) => AuditResult;
|
|
132
|
+
} : {})) => CheckedEffectDefinition<Context, typeof definition, BaseError, BaseRequirements>;
|
|
133
|
+
query: <const Input extends ContractSchema, const Output extends ContractSchema, Handler extends Supported<ContractInput<Output>>, Guard extends Supported<void> = never, Middleware extends Supported<ContractInput<Output>> = never, const Metadata extends object = Record<never, never>, const Wire extends ContractSchema = ContractSchema, const Replay extends ContractSchema = never, const Definition extends object = object>(definition: Definition & OperationDefinition<Context, Input, Output, Extension, readonly string[], Handler, Guard, never, never, Middleware, Metadata, BaseError, BaseRequirements, Wire, Replay> & {
|
|
134
|
+
prepare?: never;
|
|
135
|
+
audit?: never;
|
|
136
|
+
aggregates?: never;
|
|
137
|
+
replayResult?: never;
|
|
138
|
+
}) => CheckedEffectDefinition<Context, typeof definition, BaseError, BaseRequirements>;
|
|
139
|
+
};
|
|
140
|
+
export declare function effectActionFactory<Context, BaseError = never, BaseRequirements = never>(): {
|
|
141
|
+
action: <const Input extends ContractSchema, const Output extends ContractSchema, Handler extends Supported<ContractInput<Output>>, Guard extends Supported<void> = never, const Aggregates extends readonly string[] = readonly string[], AuditResult extends Supported<Audit<Aggregates> | null> = never, Middleware extends Supported<ContractInput<Output>> = never, const Metadata extends object = Record<never, never>, const Wire extends ContractSchema = ContractSchema, const Definition extends object = object>(definition: Definition & OperationDefinition<Context, Input, Output, Record<never, never>, Aggregates, Handler, Guard, never, AuditResult, Middleware, Metadata, BaseError, BaseRequirements, Wire, never> & {
|
|
142
|
+
prepare?: never;
|
|
143
|
+
permission?: never;
|
|
144
|
+
replayResult?: never;
|
|
145
|
+
}) => CheckedEffectDefinition<Context, typeof definition, BaseError, BaseRequirements>;
|
|
146
|
+
};
|
|
147
|
+
export {};
|
|
148
|
+
//# sourceMappingURL=operation.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation.mjs","names":["effectOperationFactory","operation","definition","command","query","effectActionFactory","action"],"sources":["../../../src/modules/effect/operation.ts"],"sourcesContent":["import type { Effect } from 'effect'\nimport type { ContractSchema, ContractInput, ContractOutput } from '../contracts/contract'\nimport type { ContractDecoderError, ContractDecoderRequirements } from './schema'\nimport type { AuditEntryInput } from '../../components/foundation/client'\nimport type { RequestScope } from './scope'\n\n/** Ordinary failures are defects; only an explicit Effect supplies a typed error. */\nexport type CallbackError<Value> = Value extends (...arguments_: never[]) => infer Returned\n\t? CallbackError<Returned>\n\t: Value extends Effect.Effect<infer Success, infer Error, unknown>\n\t\t? Error | CallbackError<Success>\n\t\t: Value extends PromiseLike<infer Awaited>\n\t\t\t? CallbackError<Awaited>\n\t\t\t: Value extends readonly (infer Item)[]\n\t\t\t\t? CallbackError<Item>\n\t\t\t\t: Value extends { kind: 'execute'; complete?: infer Complete }\n\t\t\t\t\t? CallbackError<Complete>\n\t\t\t\t\t: never\n\nexport type CallbackRequirements<Value> = Value extends (...arguments_: never[]) => infer Returned\n\t? CallbackRequirements<Returned>\n\t: Value extends Effect.Effect<infer Success, unknown, infer Requirements>\n\t\t? Requirements | CallbackRequirements<Success>\n\t\t: Value extends PromiseLike<infer Awaited>\n\t\t\t? CallbackRequirements<Awaited>\n\t\t\t: Value extends readonly (infer Item)[]\n\t\t\t\t? CallbackRequirements<Item>\n\t\t\t\t: Value extends { kind: 'execute'; complete?: infer Complete }\n\t\t\t\t\t? CallbackRequirements<Complete>\n\t\t\t\t\t: never\n\nexport type EffectValue<Value> =\n\tValue extends Effect.Effect<infer Success, unknown, unknown>\n\t\t? EffectValue<Success>\n\t\t: Value extends PromiseLike<infer Awaited>\n\t\t\t? EffectValue<Awaited>\n\t\t\t: Value\n\ndeclare const checkedOperation: unique symbol\n/** Type-only evidence that the helper checked callbacks against the base context and schemas. */\nexport type CheckedEffectOperation<Context> = {\n\treadonly [checkedOperation]: {\n\t\tcontext: (context: Context) => void\n\t\terror: unknown\n\t\trequirements: unknown\n\t\tdefinition: unknown\n\t}\n}\ntype CheckedChannels<Context, Error, Requirements, Definition> = {\n\treadonly [checkedOperation]: {\n\t\tcontext: (context: Context) => void\n\t\terror: Error\n\t\trequirements: Requirements\n\t\tdefinition: Definition\n\t}\n}\n/** Named checked-definition boundary keeps the private evidence marker inside this module's declarations. */\nexport type CheckedEffectDefinition<\n\tContext,\n\tDefinition,\n\tError = never,\n\tRequirements = never,\n> = NoInfer<Omit<Definition, typeof checkedOperation>> &\n\tCheckedChannels<Context, Error, Requirements, Omit<Definition, typeof checkedOperation>>\n/** Reject stale helper evidence after callbacks or schemas are replaced. */\nexport type ValidatedEffectOperations<Operations> = {\n\t[Key in keyof Operations]: Operations[Key] extends {\n\t\treadonly [checkedOperation]: { definition: infer Definition }\n\t}\n\t\t? Operations[Key] extends Definition\n\t\t\t? Operations[Key]\n\t\t\t: never\n\t\t: never\n}\n/** Only middleware whose next contract captured a default policy can discharge its channels. */\nexport type UnwrappedDefaultError<Definition, Guard> = Definition extends { middleware: Function }\n\t? Definition extends CheckedChannels<never, infer Error, unknown, unknown>\n\t\t? Exclude<CallbackError<Guard>, Error>\n\t\t: CallbackError<Guard>\n\t: CallbackError<Guard>\nexport type UnwrappedDefaultRequirements<Definition, Guard> = Definition extends {\n\tmiddleware: Function\n}\n\t? Definition extends CheckedChannels<never, unknown, infer Requirements, unknown>\n\t\t? Exclude<CallbackRequirements<Guard>, Requirements>\n\t\t: CallbackRequirements<Guard>\n\t: CallbackRequirements<Guard>\nexport type EffectOperationArgument<Definition extends { input: ContractSchema }> = ContractInput<\n\tDefinition['input']\n>\nexport type EffectOperationInput<Definition extends { input: ContractSchema }> = ContractOutput<\n\tDefinition['input']\n>\nexport type EffectOperationHandlerResult<Definition extends { result: ContractSchema }> =\n\tContractInput<Definition['result']>\nexport type EffectOperationResult<Definition extends { result: ContractSchema }> = ContractOutput<\n\tDefinition['result']\n>\n\ntype Hook<Definition, Key extends PropertyKey> = Key extends keyof Definition\n\t? Definition[Key]\n\t: never\ntype Returned<Callback> = Callback extends (...arguments_: never[]) => infer Value ? Value : never\n/** A conditional wrapper must retain the unwrapped channels for its absent branch. */\ntype CoreValue<Definition> = [Returned<Hook<Definition, 'middleware'>>] extends [never]\n\t? Returned<Hook<Definition, 'handler'>> | Returned<Hook<Definition, 'guard'>>\n\t: undefined extends Hook<Definition, 'middleware'>\n\t\t?\n\t\t\t\t| Returned<Hook<Definition, 'handler'>>\n\t\t\t\t| Returned<Hook<Definition, 'guard'>>\n\t\t\t\t| Returned<Hook<Definition, 'middleware'>>\n\t\t: Returned<Hook<Definition, 'middleware'>>\ntype OutsideHooks = 'prepare' | 'audit' | 'checkPermission' | 'writeAudit'\nexport type EffectOperationError<Definition> =\n\t| ContractDecoderError<Hook<Definition, 'input'>>\n\t| ContractDecoderError<Hook<Definition, 'result'>>\n\t| ContractDecoderError<Hook<Definition, 'replayResult'>>\n\t| CallbackError<CoreValue<Definition>>\n\t| CallbackError<Definition[Extract<keyof Definition, OutsideHooks>]>\nexport type EffectOperationRequirements<Definition> =\n\t| ContractDecoderRequirements<Hook<Definition, 'input'>>\n\t| ContractDecoderRequirements<Hook<Definition, 'result'>>\n\t| ContractDecoderRequirements<Hook<Definition, 'replayResult'>>\n\t| CallbackRequirements<CoreValue<Definition>>\n\t| CallbackRequirements<Definition[Extract<keyof Definition, OutsideHooks>]>\n\ntype Supported<Value, Error = unknown, Requirements = unknown> =\n\t| Value\n\t| PromiseLike<Value>\n\t| Effect.Effect<Value, Error, Requirements>\nexport type EffectPreparation<Result, Error = never, Requirements = never> =\n\t| { kind: 'replay'; result: unknown }\n\t| { kind: 'execute'; complete?: (result: Result) => Supported<void, Error, Requirements> }\nexport type EffectMiddlewareInput<\n\tContext,\n\tInput,\n\tResult,\n\tExtension,\n\tError = never,\n\tRequirements = never,\n> = {\n\toperation: string\n\tcontext: Context\n\tcommand: Input\n\tinput: Input\n\tnext: keyof Extension extends never\n\t\t? (options?: { context?: Extension }) => Effect.Effect<Result, Error, Requirements>\n\t\t: (options: { context: Extension }) => Effect.Effect<Result, Error, Requirements>\n}\ntype Audit<Aggregates extends readonly string[]> = Omit<\n\tAuditEntryInput,\n\t'classification' | 'aggregate'\n> & {\n\taggregate: { type: Aggregates[number]; id: string }\n}\nexport type OperationDefinition<\n\tContext,\n\tInput extends ContractSchema,\n\tOutput extends ContractSchema,\n\tExtension,\n\tAggregates extends readonly string[],\n\tHandler,\n\tGuard,\n\tPreparation,\n\tAuditResult,\n\tMiddleware,\n\tMetadata,\n\tBaseError,\n\tBaseRequirements,\n\tWire extends ContractSchema,\n\tReplay extends ContractSchema,\n> = {\n\tinput: Input\n\tresult: Output\n\thandler: (input: ContractOutput<Input>, context: Context & Extension) => Handler\n\tclassification?: string\n\tpermission?: string\n\tmetadata?: Metadata\n\taggregates?: Aggregates\n\treplayResult?: Replay & (ContractOutput<Replay> extends ContractOutput<Output> ? unknown : never)\n\twire?: { schema: Wire; project: (value: ContractOutput<Output>) => ContractInput<Wire> }\n\tguard?: (context: Context & Extension, input: ContractOutput<Input>) => Guard\n\tprepare?: (context: Context, input: ContractOutput<Input>) => Preparation\n\taudit?: (\n\t\tresolution: { command: ContractOutput<Input>; result: ContractOutput<Output> },\n\t\tcontext: Context,\n\t\tscope: RequestScope | undefined,\n\t) => AuditResult\n} & (keyof Extension extends never\n\t? {\n\t\t\tmiddleware?: (\n\t\t\t\tinput: EffectMiddlewareInput<\n\t\t\t\t\tContext,\n\t\t\t\t\tContractOutput<Input>,\n\t\t\t\t\tContractInput<Output>,\n\t\t\t\t\tExtension,\n\t\t\t\t\tBaseError | CallbackError<Handler | Guard>,\n\t\t\t\t\tBaseRequirements | CallbackRequirements<Handler | Guard>\n\t\t\t\t>,\n\t\t\t) => Middleware\n\t\t}\n\t: {\n\t\t\tmiddleware: (\n\t\t\t\tinput: EffectMiddlewareInput<\n\t\t\t\t\tContext,\n\t\t\t\t\tContractOutput<Input>,\n\t\t\t\t\tContractInput<Output>,\n\t\t\t\t\tExtension,\n\t\t\t\t\tBaseError | CallbackError<Handler | Guard>,\n\t\t\t\t\tBaseRequirements | CallbackRequirements<Handler | Guard>\n\t\t\t\t>,\n\t\t\t) => Middleware\n\t\t})\n\n/**\n * Bind context once; middleware wraps the handler/guard channels and may discharge them.\n * Declare contextual guards/handlers before middleware, or annotate their parameters\n * and returned Effect channels when middleware comes first. TypeScript processes\n * context-sensitive object callbacks in declaration order.\n */\nexport function effectOperationFactory<\n\tContext,\n\tExtension extends Record<string, unknown> = Record<never, never>,\n\tBaseError = never,\n\tBaseRequirements = never,\n\tAuditRequired extends boolean = true,\n>() {\n\tfunction operation<\n\t\tconst Input extends ContractSchema,\n\t\tconst Output extends ContractSchema,\n\t\tHandler extends Supported<ContractInput<Output>>,\n\t\tGuard extends Supported<void> = never,\n\t\tPreparation extends Supported<EffectPreparation<ContractOutput<Output>, unknown, unknown>> =\n\t\t\tnever,\n\t\tconst Aggregates extends readonly string[] = readonly string[],\n\t\tAuditResult extends Supported<Audit<Aggregates> | null> = never,\n\t\tMiddleware extends Supported<ContractInput<Output>> = never,\n\t\tconst Metadata extends object = Record<never, never>,\n\t\t// Retain whether middleware is guaranteed, conditional, or omitted.\n\t\tconst Wire extends ContractSchema = ContractSchema,\n\t\tconst Replay extends ContractSchema = never,\n\t\tconst Definition extends object = object,\n\t>(\n\t\tdefinition: Definition &\n\t\t\tOperationDefinition<\n\t\t\t\tContext,\n\t\t\t\tInput,\n\t\t\t\tOutput,\n\t\t\t\tExtension,\n\t\t\t\tAggregates,\n\t\t\t\tHandler,\n\t\t\t\tGuard,\n\t\t\t\tPreparation,\n\t\t\t\tAuditResult,\n\t\t\t\tMiddleware,\n\t\t\t\tMetadata,\n\t\t\t\tBaseError,\n\t\t\t\tBaseRequirements,\n\t\t\t\tWire,\n\t\t\t\tReplay\n\t\t\t>,\n\t) {\n\t\t// SAFETY: the marker is type-only proof of the helper's checked callback contract.\n\t\treturn definition as CheckedEffectDefinition<\n\t\t\tContext,\n\t\t\ttypeof definition,\n\t\t\tBaseError,\n\t\t\tBaseRequirements\n\t\t>\n\t}\n\tfunction command<\n\t\tconst Input extends ContractSchema,\n\t\tconst Output extends ContractSchema,\n\t\tHandler extends Supported<ContractInput<Output>>,\n\t\tGuard extends Supported<void> = never,\n\t\tPreparation extends Supported<EffectPreparation<ContractOutput<Output>, unknown, unknown>> =\n\t\t\tnever,\n\t\tconst Aggregates extends readonly string[] = readonly string[],\n\t\tAuditResult extends Supported<Audit<Aggregates> | null> = never,\n\t\tMiddleware extends Supported<ContractInput<Output>> = never,\n\t\tconst Metadata extends object = Record<never, never>,\n\t\t// Retain whether middleware is guaranteed, conditional, or omitted.\n\t\tconst Wire extends ContractSchema = ContractSchema,\n\t\tconst Replay extends ContractSchema = never,\n\t\tconst Definition extends object = object,\n\t>(\n\t\tdefinition: Definition &\n\t\t\tOperationDefinition<\n\t\t\t\tContext,\n\t\t\t\tInput,\n\t\t\t\tOutput,\n\t\t\t\tExtension,\n\t\t\t\tAggregates,\n\t\t\t\tHandler,\n\t\t\t\tGuard,\n\t\t\t\tPreparation,\n\t\t\t\tAuditResult,\n\t\t\t\tMiddleware,\n\t\t\t\tMetadata,\n\t\t\t\tBaseError,\n\t\t\t\tBaseRequirements,\n\t\t\t\tWire,\n\t\t\t\tReplay\n\t\t\t> & {\n\t\t\t\tclassification: string\n\t\t\t} & (AuditRequired extends true\n\t\t\t\t? {\n\t\t\t\t\t\taudit: (\n\t\t\t\t\t\t\tresolution: { command: ContractOutput<Input>; result: ContractOutput<Output> },\n\t\t\t\t\t\t\tcontext: Context,\n\t\t\t\t\t\t\tscope: RequestScope | undefined,\n\t\t\t\t\t\t) => AuditResult\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t) {\n\t\t// SAFETY: the marker is type-only proof of the helper's checked callback contract.\n\t\t// oxlint-disable-next-line anti-slop/no-chained-type-assertions -- SAFETY: The private marker is type-only callback evidence, not a runtime field.\n\t\treturn definition as unknown as CheckedEffectDefinition<\n\t\t\tContext,\n\t\t\ttypeof definition,\n\t\t\tBaseError,\n\t\t\tBaseRequirements\n\t\t>\n\t}\n\tfunction query<\n\t\tconst Input extends ContractSchema,\n\t\tconst Output extends ContractSchema,\n\t\tHandler extends Supported<ContractInput<Output>>,\n\t\tGuard extends Supported<void> = never,\n\t\tMiddleware extends Supported<ContractInput<Output>> = never,\n\t\tconst Metadata extends object = Record<never, never>,\n\t\tconst Wire extends ContractSchema = ContractSchema,\n\t\tconst Replay extends ContractSchema = never,\n\t\tconst Definition extends object = object,\n\t>(\n\t\tdefinition: Definition &\n\t\t\tOperationDefinition<\n\t\t\t\tContext,\n\t\t\t\tInput,\n\t\t\t\tOutput,\n\t\t\t\tExtension,\n\t\t\t\treadonly string[],\n\t\t\t\tHandler,\n\t\t\t\tGuard,\n\t\t\t\tnever,\n\t\t\t\tnever,\n\t\t\t\tMiddleware,\n\t\t\t\tMetadata,\n\t\t\t\tBaseError,\n\t\t\t\tBaseRequirements,\n\t\t\t\tWire,\n\t\t\t\tReplay\n\t\t\t> & {\n\t\t\t\tprepare?: never\n\t\t\t\taudit?: never\n\t\t\t\taggregates?: never\n\t\t\t\treplayResult?: never\n\t\t\t},\n\t) {\n\t\t// SAFETY: the marker is type-only proof of the helper's checked callback contract.\n\t\treturn definition as CheckedEffectDefinition<\n\t\t\tContext,\n\t\t\ttypeof definition,\n\t\t\tBaseError,\n\t\t\tBaseRequirements\n\t\t>\n\t}\n\treturn { operation, command, query }\n}\n\nexport function effectActionFactory<Context, BaseError = never, BaseRequirements = never>() {\n\ttype Extension = Record<never, never>\n\t/** Actions have no transaction to replay and no permission host; guards authorize them. */\n\tfunction action<\n\t\tconst Input extends ContractSchema,\n\t\tconst Output extends ContractSchema,\n\t\tHandler extends Supported<ContractInput<Output>>,\n\t\tGuard extends Supported<void> = never,\n\t\tconst Aggregates extends readonly string[] = readonly string[],\n\t\tAuditResult extends Supported<Audit<Aggregates> | null> = never,\n\t\tMiddleware extends Supported<ContractInput<Output>> = never,\n\t\tconst Metadata extends object = Record<never, never>,\n\t\tconst Wire extends ContractSchema = ContractSchema,\n\t\tconst Definition extends object = object,\n\t>(\n\t\tdefinition: Definition &\n\t\t\tOperationDefinition<\n\t\t\t\tContext,\n\t\t\t\tInput,\n\t\t\t\tOutput,\n\t\t\t\tExtension,\n\t\t\t\tAggregates,\n\t\t\t\tHandler,\n\t\t\t\tGuard,\n\t\t\t\tnever,\n\t\t\t\tAuditResult,\n\t\t\t\tMiddleware,\n\t\t\t\tMetadata,\n\t\t\t\tBaseError,\n\t\t\t\tBaseRequirements,\n\t\t\t\tWire,\n\t\t\t\tnever\n\t\t\t> & {\n\t\t\t\tprepare?: never\n\t\t\t\tpermission?: never\n\t\t\t\treplayResult?: never\n\t\t\t},\n\t) {\n\t\t// SAFETY: the marker is type-only proof of the helper's checked callback contract.\n\t\treturn definition as CheckedEffectDefinition<\n\t\t\tContext,\n\t\t\ttypeof definition,\n\t\t\tBaseError,\n\t\t\tBaseRequirements\n\t\t>\n\t}\n\treturn { action }\n}\n"],"mappings":"AA4NA,SAAgBA,GAMZ,CACH,SAASC,EAgBR,EAkBC,CAED,OAAOC,CAMR,CACA,SAASC,EAgBR,EA4BC,CAGD,OAAOD,CAMR,CACA,SAASE,EAWR,EAuBC,CAED,OAAOF,CAMR,CACA,MAAO,CAAE,YAAW,UAAS,OAAM,CACpC,CAEA,SAAgBG,GAA4E,CAG3F,SAASC,EAYR,EAsBC,CAED,OAAOJ,CAMR,CACA,MAAO,CAAE,QAAO,CACjB,C"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { ContractOutput, ContractSchema } from "../contracts/contract.mjs";
|
|
2
|
+
import { ArgumentFailurePolicy } from "../contracts/errors.mjs";
|
|
3
|
+
import { OperationPublicResult, SelectedOperation } from "../contracts/exposure.mjs";
|
|
4
|
+
import { Observability, ObservabilityOptions } from "../../components/foundation/modules/observability/observability.mjs";
|
|
5
|
+
import { FailureAuditOptions } from "./failure-audit.mjs";
|
|
6
|
+
import { CallbackError, CallbackRequirements, CheckedEffectOperation, EffectOperationArgument, EffectOperationError, EffectOperationRequirements, EffectOperationResult, EffectValue, UnwrappedDefaultError, UnwrappedDefaultRequirements, ValidatedEffectOperations, effectOperationFactory } from "./operation.mjs";
|
|
7
|
+
import { DomainContract, DomainQueryContract } from "../contracts/domain.mjs";
|
|
8
|
+
import { BoundOperations } from "../contracts/binding.mjs";
|
|
9
|
+
import { DomainEffectFactory, DomainEffectImplementations, ExactDomainOperations } from "./domain.mjs";
|
|
10
|
+
import { Effect } from "effect";
|
|
11
|
+
type Supported<Value> = Value | PromiseLike<Value> | Effect.Effect<Value, unknown, unknown>;
|
|
12
|
+
type QueryDefinition = {
|
|
13
|
+
input: ContractSchema;
|
|
14
|
+
result: ContractSchema;
|
|
15
|
+
handler: (input: never, context: never) => unknown;
|
|
16
|
+
classification?: string;
|
|
17
|
+
permission?: string;
|
|
18
|
+
metadata?: object;
|
|
19
|
+
guard?: (context: never, input: never) => unknown;
|
|
20
|
+
middleware?: (input: never) => unknown;
|
|
21
|
+
};
|
|
22
|
+
type QueryRegistry<Context> = Readonly<Record<string, Pick<QueryDefinition, 'input' | 'result' | 'handler'> & CheckedEffectOperation<Context> & {
|
|
23
|
+
prepare?: never;
|
|
24
|
+
audit?: never;
|
|
25
|
+
aggregates?: never;
|
|
26
|
+
replayResult?: never;
|
|
27
|
+
}>>;
|
|
28
|
+
type OperationKey<Operations> = Extract<keyof Operations, string>;
|
|
29
|
+
/** Injectable domain queries compose lazily; the API chooses native function kind. */
|
|
30
|
+
export declare function createEffectQuery<Host, ContextReturned, const Operations extends QueryRegistry<EffectValue<ContextReturned>>, PermissionReturned = never, GuardReturned extends Supported<void> = never>(configuration: {
|
|
31
|
+
context: (host: Host) => ContextReturned;
|
|
32
|
+
operations: (definitions: ReturnType<typeof effectOperationFactory<EffectValue<ContextReturned>, Record<never, never>, NoInfer<CallbackError<GuardReturned>>, NoInfer<CallbackRequirements<GuardReturned>>>>) => Operations & NoInfer<ValidatedEffectOperations<Operations>>;
|
|
33
|
+
checkPermission?: (host: Host, input: {
|
|
34
|
+
permission: string;
|
|
35
|
+
operation: string;
|
|
36
|
+
}) => PermissionReturned;
|
|
37
|
+
defaults?: {
|
|
38
|
+
metadata?: object;
|
|
39
|
+
guard?: (context: EffectValue<ContextReturned>) => GuardReturned;
|
|
40
|
+
};
|
|
41
|
+
observability?: ObservabilityOptions | Observability;
|
|
42
|
+
auditFailure?: FailureAuditOptions;
|
|
43
|
+
argumentFailure?: ArgumentFailurePolicy;
|
|
44
|
+
contract?: Pick<DomainContract, 'errors'>;
|
|
45
|
+
}): {
|
|
46
|
+
exec: <const Key extends OperationKey<Operations>>(operation: Key, input: EffectOperationArgument<Operations[Key]>, host: Host) => Effect.Effect<EffectOperationResult<Operations[Key]>, EffectOperationError<Operations[Key]> | CallbackError<ContextReturned | PermissionReturned> | UnwrappedDefaultError<Operations[Key], GuardReturned>, EffectOperationRequirements<Operations[Key]> | CallbackRequirements<ContextReturned | PermissionReturned> | UnwrappedDefaultRequirements<Operations[Key], GuardReturned>>;
|
|
47
|
+
expose: <const Owner extends symbol, const Key extends OperationKey<Operations>>(owner: Owner, operation: Key) => SelectedOperation<Owner, Key, Operations[Key]['input'], OperationPublicResult<Operations[Key]>>;
|
|
48
|
+
/** Bind invocation context without resolving it or running an operation. */
|
|
49
|
+
withContext(context: Host): {
|
|
50
|
+
exec: <const Key extends OperationKey<Operations>>(operation: Key, input: EffectOperationArgument<Operations[Key]>) => Effect.Effect<ContractOutput<Operations[Key]["result"]>, UnwrappedDefaultError<Operations[Key], GuardReturned> | CallbackError<ContextReturned | PermissionReturned> | EffectOperationError<Operations[Key]>, UnwrappedDefaultRequirements<Operations[Key], GuardReturned> | CallbackRequirements<ContextReturned | PermissionReturned> | EffectOperationRequirements<Operations[Key]>>;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
type Policy<Dependencies> = 'checkPermission' extends keyof Dependencies ? Dependencies['checkPermission'] : never;
|
|
54
|
+
type CallbackHost<Callback> = Callback extends ((host: infer Host, input: never) => unknown) ? Host : never;
|
|
55
|
+
type CallbackReturned<Callback> = Callback extends ((...arguments_: never[]) => infer Returned) ? Returned : never;
|
|
56
|
+
type PolicyHost<Dependencies> = [CallbackHost<Policy<Dependencies>>] extends [never] ? unknown : CallbackHost<Policy<Dependencies>>;
|
|
57
|
+
type PolicyReturned<Dependencies> = CallbackReturned<Policy<Dependencies>>;
|
|
58
|
+
export type EffectQueryDependencies = {
|
|
59
|
+
observability: Observability;
|
|
60
|
+
auditFailure?: FailureAuditOptions;
|
|
61
|
+
argumentFailure?: ArgumentFailurePolicy;
|
|
62
|
+
checkPermission?: (host: never, input: {
|
|
63
|
+
permission: string;
|
|
64
|
+
operation: string;
|
|
65
|
+
}) => unknown;
|
|
66
|
+
};
|
|
67
|
+
/** The public Foundation binds trusted application policies once. */
|
|
68
|
+
export declare function bindEffectQuery<const Dependencies extends EffectQueryDependencies>(dependencies: Dependencies): {
|
|
69
|
+
<Host extends PolicyHost<Dependencies>, ContextReturned, const Contract extends DomainContract & {
|
|
70
|
+
queries: Readonly<Record<string, DomainQueryContract>>;
|
|
71
|
+
}, const Operations extends DomainEffectImplementations<EffectValue<ContextReturned>, Contract['queries']>, Mode extends false, GuardReturned extends Supported<void> = never>(configuration: {
|
|
72
|
+
contract: Contract & NoInfer<Operations extends ExactDomainOperations<Operations, Contract['queries']> & ValidatedEffectOperations<Operations> ? unknown : never>;
|
|
73
|
+
context: (host: Host) => ContextReturned;
|
|
74
|
+
operations: (define: DomainEffectFactory<EffectValue<ContextReturned>, Contract['queries'], Mode, never, NoInfer<CallbackError<GuardReturned>>, NoInfer<CallbackRequirements<GuardReturned>>, Contract['errors']>) => Operations;
|
|
75
|
+
defaults?: {
|
|
76
|
+
metadata?: object;
|
|
77
|
+
guard?: (context: EffectValue<ContextReturned>) => GuardReturned;
|
|
78
|
+
};
|
|
79
|
+
}): ReturnType<typeof createEffectQuery<Host, ContextReturned, BoundOperations<Operations, Contract['queries']>, PolicyReturned<Dependencies>, GuardReturned>>;
|
|
80
|
+
<Host extends PolicyHost<Dependencies>, ContextReturned, const Operations extends QueryRegistry<EffectValue<ContextReturned>>, GuardReturned extends Supported<void> = never>(configuration: {
|
|
81
|
+
context: (host: Host) => ContextReturned;
|
|
82
|
+
operations: (definitions: ReturnType<typeof effectOperationFactory<EffectValue<ContextReturned>, Record<never, never>, NoInfer<CallbackError<GuardReturned>>, NoInfer<CallbackRequirements<GuardReturned>>>>) => Operations & NoInfer<ValidatedEffectOperations<Operations>>;
|
|
83
|
+
defaults?: {
|
|
84
|
+
metadata?: object;
|
|
85
|
+
guard?: (context: EffectValue<ContextReturned>) => GuardReturned;
|
|
86
|
+
};
|
|
87
|
+
}): ReturnType<typeof createEffectQuery<Host, ContextReturned, Operations, PolicyReturned<Dependencies>, GuardReturned>>;
|
|
88
|
+
};
|
|
89
|
+
export {};
|
|
90
|
+
//# sourceMappingURL=query.d.mts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{memoize as e,registerLazyRegistry as t}from"../contracts/lazy.mjs";import{decodeOperationInput as n}from"./input.mjs";import{selectOperation as r}from"../contracts/exposure.mjs";import{decodeEffectContract as i}from"./schema.mjs";import{Observability as a}from"../../components/foundation/modules/observability/observability.mjs";import{normalizeEffect as o,observationFailure as s}from"./normalize.mjs";import{enterRequestScope as c}from"./scope.mjs";import{reportFailure as l}from"./failure-audit.mjs";import{effectOperationFactory as u}from"./operation.mjs";import{snapshotOperations as d}from"../contracts/binding.mjs";import{domainEffectFactory as f}from"./domain.mjs";import{Effect as p,Exit as m}from"effect";var h=class extends Error{code=`QUERY_MIDDLEWARE_NEXT_REUSED`;name=`QueryMiddlewareError`;constructor(){super(`A query middleware called next() more than once`)}},g=class extends Error{code=`QUERY_OPERATION_NOT_CONFIGURED`;name=`QueryConfigurationError`;constructor(){super(`The selected query operation is not configured`)}},_=class extends Error{code=`QUERY_PERMISSION_CHECKER_MISSING`;name=`QueryPermissionError`;constructor(){super(`Query permission requires an injected permission checker`)}};function v(d){let f=u(),v=e(()=>d.operations(f)),y=d.observability instanceof a?d.observability:new a(d.observability??{enabled:!1,classifyError:()=>({outcome:`failed`,errorCode:`UNEXPECTED`})});function b(e,t,r){return p.suspend(()=>{let a=v();if(!Object.prototype.hasOwnProperty.call(a,e))return p.die(new g);let u=a[e],f=u.classification??`query`,b=n(u.input,t,d.argumentFailure,d.auditFailure,{kind:`query`,operation:e,classification:f});return p.flatMap(b,t=>{let n=y.start({operation:e,classification:f}),a=p.gen(function*(){if(u.permission!==void 0){let t=d.checkPermission;if(!t)return yield*p.die(new _);yield*o(()=>t(r,{permission:u.permission,operation:e}))}let n=yield*o(()=>d.context(r)),a={...d.defaults?.metadata,...u.metadata},s=e=>p.gen(function*(){let n=d.defaults?.guard;return n&&(yield*o(()=>n(e))),u.guard&&(yield*o(()=>u.guard(e,t))),yield*o(()=>u.handler(t,e))}),c=!1,l=u.middleware,f=l?yield*o(()=>l({operation:e,input:t,command:t,context:n,metadata:a,next:e=>p.suspend(()=>c?p.die(new h):(c=!0,s(e?.context?Object.assign({},n,e.context):n)))})):yield*s(n);return yield*i(u.result,f)});return c(e,!1,(r,i)=>a.pipe(p.onExit(a=>p.sync(()=>{m.isSuccess(a)?n.completed():n.failed(s(a.cause))}).pipe(p.andThen(l(d.auditFailure,a,{kind:`query`,operation:e,classification:f,input:t,get contract(){return d.contract?.errors},entered:r,current:i}))))))})})}function x(e,t){let n=v();if(!Object.hasOwn(n,t))throw new g;return r(e,`query`,t,n[t])}return t({exec:b,expose:x,withContext(e){return{exec:(t,n)=>b(t,n,e)}}},v)}function y(e){function t(t){let n=()=>{let e=t.contract?f(t.contract.queries??{},!1,t.contract.errors):u();return d(t.operations(e),t.contract,`queries`)};return v({...t,...e,operations:n})}return t}export{y as bindEffectQuery,v as createEffectQuery};
|
|
2
|
+
//# sourceMappingURL=query.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.mjs","names":["QueryMiddlewareError","QueryConfigurationError","QueryPermissionError","createEffectQuery","definitions","effectOperationFactory","getOperations","memoize","configuration","observability","Observability","exec","Effect","operations","operation","definition","classification","decodedInput","decodeOperationInput","input","observation","run","check","normalizeEffect","host","context","metadata","core","guard","current","parsedInput","usedNext","middleware","output","options","decodeEffectContract","enterRequestScope","Exit","exit","observationFailure","reportFailure","expose","selectOperation","owner","registerLazyRegistry","bindEffectQuery","query","buildOperations","domainEffectFactory","snapshotOperations","dependencies"],"sources":["../../../src/modules/effect/query.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 { ContractSchema } from '../contracts/contract'\nimport type { ArgumentFailurePolicy } from '../contracts/errors'\nimport { decodeOperationInput } from './input'\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\tObservability,\n\ttype ObservabilityOptions,\n} from '../../components/foundation/modules/observability/observability'\nimport { normalizeEffect, observationFailure } from './normalize'\nimport { enterRequestScope } from './scope'\nimport { reportFailure, type FailureAuditOptions } from './failure-audit'\nimport {\n\teffectOperationFactory,\n\ttype CallbackError,\n\ttype CallbackRequirements,\n\ttype EffectOperationArgument,\n\ttype EffectOperationError,\n\ttype EffectOperationRequirements,\n\ttype EffectOperationResult,\n\ttype EffectValue,\n\ttype CheckedEffectOperation,\n\ttype UnwrappedDefaultError,\n\ttype UnwrappedDefaultRequirements,\n\ttype ValidatedEffectOperations,\n} from './operation'\n\nimport type { DomainContract, DomainQueryContract } from '../contracts/domain'\nimport { snapshotOperations, type BoundOperations } from '../contracts/binding'\nimport {\n\tdomainEffectFactory,\n\ttype DomainEffectFactory,\n\ttype DomainEffectImplementations,\n\ttype ExactDomainOperations,\n} from './domain'\n\ntype Supported<Value> = Value | PromiseLike<Value> | Effect.Effect<Value, unknown, unknown>\ntype QueryDefinition = {\n\tinput: ContractSchema\n\tresult: ContractSchema\n\t// oxlint-disable-next-line anti-slop/no-unknown-returns -- Internal heterogeneous storage; selected schemas restore the concrete result at exec.\n\thandler: (input: never, context: never) => unknown\n\tclassification?: string\n\tpermission?: string\n\tmetadata?: object\n\t// oxlint-disable-next-line anti-slop/no-unknown-returns -- Internal hook storage retains the concrete definition separately.\n\tguard?: (context: never, input: never) => unknown\n\t// oxlint-disable-next-line anti-slop/no-unknown-returns -- Internal hook storage retains the concrete definition separately.\n\tmiddleware?: (input: never) => unknown\n}\ntype QueryRegistry<Context> = Readonly<\n\tRecord<\n\t\tstring,\n\t\tPick<QueryDefinition, 'input' | 'result' | 'handler'> &\n\t\t\tCheckedEffectOperation<Context> & {\n\t\t\t\tprepare?: never\n\t\t\t\taudit?: never\n\t\t\t\taggregates?: never\n\t\t\t\treplayResult?: never\n\t\t\t}\n\t>\n>\ntype OperationKey<Operations> = Extract<keyof Operations, string>\n\nclass QueryMiddlewareError extends Error {\n\treadonly code = 'QUERY_MIDDLEWARE_NEXT_REUSED'\n\treadonly name = 'QueryMiddlewareError'\n\tconstructor() {\n\t\tsuper('A query middleware called next() more than once')\n\t}\n}\nclass QueryConfigurationError extends Error {\n\treadonly code = 'QUERY_OPERATION_NOT_CONFIGURED'\n\treadonly name = 'QueryConfigurationError'\n\tconstructor() {\n\t\tsuper('The selected query operation is not configured')\n\t}\n}\nclass QueryPermissionError extends Error {\n\treadonly code = 'QUERY_PERMISSION_CHECKER_MISSING'\n\treadonly name = 'QueryPermissionError'\n\tconstructor() {\n\t\tsuper('Query permission requires an injected permission checker')\n\t}\n}\n\n/** Injectable domain queries compose lazily; the API chooses native function kind. */\nexport function createEffectQuery<\n\tHost,\n\tContextReturned,\n\tconst Operations extends QueryRegistry<EffectValue<ContextReturned>>,\n\tPermissionReturned = never,\n\tGuardReturned extends Supported<void> = never,\n>(configuration: {\n\tcontext: (host: Host) => ContextReturned\n\toperations: (\n\t\tdefinitions: ReturnType<\n\t\t\ttypeof effectOperationFactory<\n\t\t\t\tEffectValue<ContextReturned>,\n\t\t\t\tRecord<never, never>,\n\t\t\t\tNoInfer<CallbackError<GuardReturned>>,\n\t\t\t\tNoInfer<CallbackRequirements<GuardReturned>>\n\t\t\t>\n\t\t>,\n\t) => Operations & NoInfer<ValidatedEffectOperations<Operations>>\n\tcheckPermission?: (\n\t\thost: Host,\n\t\tinput: { permission: string; operation: string },\n\t) => PermissionReturned\n\tdefaults?: { metadata?: object; guard?: (context: EffectValue<ContextReturned>) => GuardReturned }\n\tobservability?: ObservabilityOptions | Observability\n\tauditFailure?: FailureAuditOptions\n\targumentFailure?: ArgumentFailurePolicy\n\tcontract?: Pick<DomainContract, 'errors'>\n}) {\n\tconst definitions = effectOperationFactory<\n\t\tEffectValue<ContextReturned>,\n\t\tRecord<never, never>,\n\t\tCallbackError<GuardReturned>,\n\t\tCallbackRequirements<GuardReturned>\n\t>()\n\tconst getOperations = memoize<Operations>(() => configuration.operations(definitions))\n\tconst observability =\n\t\tconfiguration.observability instanceof Observability\n\t\t\t? configuration.observability\n\t\t\t: new Observability(\n\t\t\t\t\tconfiguration.observability ?? {\n\t\t\t\t\t\tenabled: false,\n\t\t\t\t\t\tclassifyError: () => ({ outcome: 'failed', errorCode: 'UNEXPECTED' }),\n\t\t\t\t\t},\n\t\t\t\t)\n\n\tfunction exec<const Key extends OperationKey<Operations>>(\n\t\toperation: Key,\n\t\tinput: EffectOperationArgument<Operations[Key]>,\n\t\thost: Host,\n\t): Effect.Effect<\n\t\tEffectOperationResult<Operations[Key]>,\n\t\t| EffectOperationError<Operations[Key]>\n\t\t| CallbackError<ContextReturned | PermissionReturned>\n\t\t| UnwrappedDefaultError<Operations[Key], GuardReturned>,\n\t\t| EffectOperationRequirements<Operations[Key]>\n\t\t| CallbackRequirements<ContextReturned | PermissionReturned>\n\t\t| UnwrappedDefaultRequirements<Operations[Key], GuardReturned>\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\treturn Effect.die(new QueryConfigurationError())\n\t\t\t}\n\t\t\t// SAFETY: operation helpers check hooks before this heterogeneous storage seam.\n\t\t\tconst definition: QueryDefinition = operations[operation]\n\t\t\tconst classification = definition.classification ?? 'query'\n\t\t\tconst decodedInput = decodeOperationInput(\n\t\t\t\tdefinition.input,\n\t\t\t\tinput,\n\t\t\t\tconfiguration.argumentFailure,\n\t\t\t\tconfiguration.auditFailure,\n\t\t\t\t{ kind: 'query', operation, classification },\n\t\t\t)\n\t\t\treturn Effect.flatMap(decodedInput, (parsedInput) => {\n\t\t\t\tconst observation = observability.start({ operation, classification })\n\t\t\t\tconst run = Effect.gen(function* () {\n\t\t\t\t\tif (definition.permission !== undefined) {\n\t\t\t\t\t\tconst check = configuration.checkPermission\n\t\t\t\t\t\tif (!check) return yield* Effect.die(new QueryPermissionError())\n\t\t\t\t\t\tyield* normalizeEffect(() =>\n\t\t\t\t\t\t\tcheck(host, { permission: definition.permission!, operation }),\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tconst context = yield* normalizeEffect(() => configuration.context(host))\n\t\t\t\t\tconst metadata = { ...configuration.defaults?.metadata, ...definition.metadata }\n\t\t\t\t\tconst core = (current: EffectValue<ContextReturned>) =>\n\t\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\t\tconst guard = configuration.defaults?.guard\n\t\t\t\t\t\t\tif (guard) yield* normalizeEffect(() => guard(current))\n\t\t\t\t\t\t\tif (definition.guard)\n\t\t\t\t\t\t\t\tyield* normalizeEffect(() => {\n\t\t\t\t\t\t\t\t\t// SAFETY: selected schemas and context own the stored guard parameters.\n\t\t\t\t\t\t\t\t\treturn definition.guard!(current as never, parsedInput as never)\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\treturn yield* normalizeEffect(() => {\n\t\t\t\t\t\t\t\t// SAFETY: selected schemas and context own the stored handler parameters.\n\t\t\t\t\t\t\t\treturn definition.handler(parsedInput as never, current as never)\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t})\n\t\t\t\t\tlet usedNext = false\n\t\t\t\t\tconst middleware = definition.middleware\n\t\t\t\t\tconst output = middleware\n\t\t\t\t\t\t? yield* normalizeEffect(() => {\n\t\t\t\t\t\t\t\t// SAFETY: the selected helper checked this middleware's input and next contract.\n\t\t\t\t\t\t\t\treturn middleware({\n\t\t\t\t\t\t\t\t\toperation,\n\t\t\t\t\t\t\t\t\tinput: parsedInput,\n\t\t\t\t\t\t\t\t\tcommand: parsedInput,\n\t\t\t\t\t\t\t\t\tcontext,\n\t\t\t\t\t\t\t\t\tmetadata,\n\t\t\t\t\t\t\t\t\tnext: (options?: { context?: object }) =>\n\t\t\t\t\t\t\t\t\t\tEffect.suspend(() => {\n\t\t\t\t\t\t\t\t\t\t\tif (usedNext) return Effect.die(new QueryMiddlewareError())\n\t\t\t\t\t\t\t\t\t\t\tusedNext = true\n\t\t\t\t\t\t\t\t\t\t\treturn core(\n\t\t\t\t\t\t\t\t\t\t\t\toptions?.context ? Object.assign({}, context, options.context) : context,\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} as never)\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t: yield* core(context)\n\t\t\t\t\treturn yield* decodeEffectContract(definition.result, output)\n\t\t\t\t})\n\t\t\t\treturn enterRequestScope(operation, false, (entered, current) =>\n\t\t\t\t\trun.pipe(\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 {\n\t\t\t\t\t\t\t\t\tobservation.failed(observationFailure(exit.cause))\n\t\t\t\t\t\t\t\t}\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: 'query',\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: parsedInput,\n\t\t\t\t\t\t\t\t\t\tget contract() {\n\t\t\t\t\t\t\t\t\t\t\treturn configuration.contract?.errors\n\t\t\t\t\t\t\t\t\t\t},\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\t)\n\t\t\t})\n\t\t})\n\t\t// SAFETY: selected schemas own A; concrete callbacks and the wrapped middleware\n\t\t// own E/R. No interpreter or runner executes this Effect before the caller does.\n\t\treturn execution as ReturnType<typeof exec<Key>>\n\t}\n\tfunction expose<const Owner extends symbol, const Key extends OperationKey<Operations>>(\n\t\towner: Owner,\n\t\toperation: Key,\n\t): SelectedOperation<\n\t\tOwner,\n\t\tKey,\n\t\tOperations[Key]['input'],\n\t\tOperationPublicResult<Operations[Key]>\n\t> {\n\t\tconst operations = getOperations()\n\t\tif (!Object.hasOwn(operations, operation)) throw new QueryConfigurationError()\n\t\treturn selectOperation(owner, 'query', operation, operations[operation])\n\t}\n\treturn registerLazyRegistry(\n\t\t{\n\t\t\texec,\n\t\t\texpose,\n\t\t\t/** Bind invocation context without resolving it or running an operation. */\n\t\t\twithContext(context: Host) {\n\t\t\t\treturn {\n\t\t\t\t\texec: <const Key extends OperationKey<Operations>>(\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},\n\t\tgetOperations,\n\t)\n}\n\ntype Policy<Dependencies> = 'checkPermission' extends keyof Dependencies\n\t? Dependencies['checkPermission']\n\t: never\n// oxlint-disable-next-line anti-slop/no-unknown-returns -- Conditional type extracts the host; no unknown result is exposed by the registry.\ntype CallbackHost<Callback> = Callback extends (host: infer Host, input: never) => unknown\n\t? Host\n\t: never\ntype CallbackReturned<Callback> = Callback extends (...arguments_: never[]) => infer Returned\n\t? Returned\n\t: never\ntype PolicyHost<Dependencies> = [CallbackHost<Policy<Dependencies>>] extends [never]\n\t? unknown\n\t: CallbackHost<Policy<Dependencies>>\ntype PolicyReturned<Dependencies> = CallbackReturned<Policy<Dependencies>>\nexport type EffectQueryDependencies = {\n\tobservability: Observability\n\tauditFailure?: FailureAuditOptions\n\targumentFailure?: ArgumentFailurePolicy\n\t// oxlint-disable-next-line anti-slop/no-unknown-returns -- Host policy storage is erased; the bound generic dependency retains its concrete E/R.\n\tcheckPermission?: (host: never, input: { permission: string; operation: string }) => unknown\n}\n\n/** The public Foundation binds trusted application policies once. */\nexport function bindEffectQuery<const Dependencies extends EffectQueryDependencies>(\n\tdependencies: Dependencies,\n) {\n\tfunction query<\n\t\tHost extends PolicyHost<Dependencies>,\n\t\tContextReturned,\n\t\tconst Contract extends DomainContract & {\n\t\t\tqueries: Readonly<Record<string, DomainQueryContract>>\n\t\t},\n\t\tconst Operations extends DomainEffectImplementations<\n\t\t\tEffectValue<ContextReturned>,\n\t\t\tContract['queries']\n\t\t>,\n\t\tMode extends false,\n\t\tGuardReturned extends Supported<void> = never,\n\t>(configuration: {\n\t\tcontract: Contract &\n\t\t\tNoInfer<\n\t\t\t\tOperations extends ExactDomainOperations<Operations, Contract['queries']> &\n\t\t\t\t\tValidatedEffectOperations<Operations>\n\t\t\t\t\t? unknown\n\t\t\t\t\t: never\n\t\t\t>\n\t\tcontext: (host: Host) => ContextReturned\n\t\toperations: (\n\t\t\tdefine: DomainEffectFactory<\n\t\t\t\tEffectValue<ContextReturned>,\n\t\t\t\tContract['queries'],\n\t\t\t\tMode,\n\t\t\t\tnever,\n\t\t\t\tNoInfer<CallbackError<GuardReturned>>,\n\t\t\t\tNoInfer<CallbackRequirements<GuardReturned>>,\n\t\t\t\tContract['errors']\n\t\t\t>,\n\t\t) => Operations\n\t\tdefaults?: {\n\t\t\tmetadata?: object\n\t\t\tguard?: (context: EffectValue<ContextReturned>) => GuardReturned\n\t\t}\n\t}): ReturnType<\n\t\ttypeof createEffectQuery<\n\t\t\tHost,\n\t\t\tContextReturned,\n\t\t\tBoundOperations<Operations, Contract['queries']>,\n\t\t\tPolicyReturned<Dependencies>,\n\t\t\tGuardReturned\n\t\t>\n\t>\n\n\tfunction query<\n\t\tHost extends PolicyHost<Dependencies>,\n\t\tContextReturned,\n\t\tconst Operations extends QueryRegistry<EffectValue<ContextReturned>>,\n\t\tGuardReturned extends Supported<void> = never,\n\t>(configuration: {\n\t\tcontext: (host: Host) => ContextReturned\n\t\toperations: (\n\t\t\tdefinitions: ReturnType<\n\t\t\t\ttypeof effectOperationFactory<\n\t\t\t\t\tEffectValue<ContextReturned>,\n\t\t\t\t\tRecord<never, never>,\n\t\t\t\t\tNoInfer<CallbackError<GuardReturned>>,\n\t\t\t\t\tNoInfer<CallbackRequirements<GuardReturned>>\n\t\t\t\t>\n\t\t\t>,\n\t\t) => Operations & NoInfer<ValidatedEffectOperations<Operations>>\n\t\tdefaults?: {\n\t\t\tmetadata?: object\n\t\t\tguard?: (context: EffectValue<ContextReturned>) => GuardReturned\n\t\t}\n\t}): ReturnType<\n\t\ttypeof createEffectQuery<\n\t\t\tHost,\n\t\t\tContextReturned,\n\t\t\tOperations,\n\t\t\tPolicyReturned<Dependencies>,\n\t\t\tGuardReturned\n\t\t>\n\t>\n\n\tfunction query(configuration: {\n\t\tcontext: (host: never) => unknown\n\t\tcontract?: DomainContract\n\t\toperations: (define: never) => Readonly<Record<string, object>>\n\t\tdefaults?: { metadata?: object; guard?: (context: never) => Supported<void> }\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.queries ?? {},\n\t\t\t\t\t\tfalse,\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'queries',\n\t\t\t)\n\t\t}\n\n\t\t// SAFETY: the overload verifies callback types; exact binding ownership is verified before execution.\n\t\treturn createEffectQuery({\n\t\t\t...configuration,\n\t\t\t...dependencies,\n\t\t\toperations: buildOperations,\n\t\t} as never)\n\t}\n\treturn query\n}\n"],"mappings":"A,mtBAwEA,IAAMA,EAAN,cAAmC,KAAM,CACxC,KAAgB,+BAChB,KAAgB,uBAChB,aAAc,CACb,MAAM,iDAAiD,CACxD,CACD,EACMC,EAAN,cAAsC,KAAM,CAC3C,KAAgB,iCAChB,KAAgB,0BAChB,aAAc,CACb,MAAM,gDAAgD,CACvD,CACD,EACMC,EAAN,cAAmC,KAAM,CACxC,KAAgB,mCAChB,KAAgB,uBAChB,aAAc,CACb,MAAM,0DAA0D,CACjE,CACD,EAGA,SAAgBC,EAMd,EAqBC,CACF,IAAMC,EAAcC,EAKlB,EACIC,EAAgBC,MAA0BC,EAAc,WAAWJ,CAAW,CAAC,EAC/EK,EACLD,EAAc,yBAAyBE,EACpCF,EAAc,cACd,IAAIE,EACJF,EAAc,eAAiB,CAC9B,QAAS,GACT,mBAAsB,CAAE,QAAS,SAAU,UAAW,YAAa,EACpE,CACD,EAEH,SAASG,EACR,EACA,EACA,EASC,CAgGD,OA/FkBC,EAAO,YAAc,CACtC,IAAMC,EAAaP,EAAc,EACjC,GAAI,CAAC,OAAO,UAAU,eAAe,KAAKO,EAAYC,CAAS,EAC9D,OAAOF,EAAO,IAAI,IAAIX,CAAyB,EAGhD,IAAMc,EAA8BF,EAAWC,GACzCE,EAAiBD,EAAW,gBAAkB,QAC9CE,EAAeC,EACpBH,EAAW,MACXI,EACAX,EAAc,gBACdA,EAAc,aACd,CAAE,KAAM,QAAS,YAAW,gBAAe,CAC5C,EACA,OAAOI,EAAO,QAAQK,EAAe,GAAgB,CACpD,IAAMG,EAAcX,EAAc,MAAM,CAAE,YAAW,gBAAe,CAAC,EAC/DY,EAAMT,EAAO,IAAI,WAAa,CACnC,GAAIG,EAAW,aAAe,IAAA,GAAW,CACxC,IAAMO,EAAQd,EAAc,gBAC5B,GAAI,CAACc,EAAO,OAAO,MAAOV,EAAO,IAAI,IAAIV,CAAsB,EAC/D,MAAOqB,MACND,EAAME,EAAM,CAAE,WAAYT,EAAW,WAAa,WAAU,CAAC,CAC9D,CACD,CACA,IAAMU,EAAU,MAAOF,MAAsBf,EAAc,QAAQgB,CAAI,CAAC,EAClEE,EAAW,CAAE,GAAGlB,EAAc,UAAU,SAAU,GAAGO,EAAW,QAAS,EACzEY,EAAQ,GACbf,EAAO,IAAI,WAAa,CACvB,IAAMgB,EAAQpB,EAAc,UAAU,MAOtC,OANIoB,IAAO,MAAOL,MAAsBK,EAAMC,CAAO,CAAC,GAClDd,EAAW,QACd,MAAOQ,MAECR,EAAW,MAAOc,EAAkBC,CAAoB,CAC/D,GACK,MAAOP,MAENR,EAAW,QAAQe,EAAsBD,CAAgB,CAChE,CACF,CAAC,EACEE,EAAW,GACTC,EAAajB,EAAW,WACxBkB,EAASD,EACZ,MAAOT,MAEAS,EAAW,CACjB,YACA,MAAOF,EACP,QAASA,EACT,UACA,WACA,KAAO,GACNlB,EAAO,YACFmB,EAAiBnB,EAAO,IAAI,IAAIZ,CAAsB,GAC1D,EAAW,GACJ2B,EACNO,GAAS,QAAU,OAAO,OAAO,CAAC,EAAGT,EAASS,EAAQ,OAAO,EAAIT,CAClE,EACA,CACH,CAAU,CACV,EACA,MAAOE,EAAKF,CAAO,EACtB,OAAO,MAAOU,EAAqBpB,EAAW,OAAQkB,CAAM,CAC7D,CAAC,EACD,OAAOG,EAAkBtB,EAAW,IAAQ,EAAS,IACpDO,EAAI,KACHT,EAAO,OAAQ,GACdA,EAAO,SAAW,CACbyB,EAAK,UAAUC,CAAI,EAAGlB,EAAY,UAAU,EAE/CA,EAAY,OAAOmB,EAAmBD,EAAK,KAAK,CAAC,CAEnD,CAAC,CAAC,CAAC,KACF1B,EAAO,QACN4B,EAAchC,EAAc,aAAc8B,EAAM,CAC/C,KAAM,QACN,YACA,iBACA,MAAOR,EACP,IAAI,UAAW,CACd,OAAOtB,EAAc,UAAU,MAChC,EACA,UACA,SACD,CAAC,CACF,CACD,CACD,CACD,CACD,CACD,CAAC,CACF,CAGe,CAChB,CACA,SAASiC,EACR,EACA,EAMC,CACD,IAAM5B,EAAaP,EAAc,EACjC,GAAI,CAAC,OAAO,OAAOO,EAAYC,CAAS,EAAG,MAAM,IAAIb,EACrD,OAAOyC,EAAgBC,EAAO,QAAS7B,EAAWD,EAAWC,EAAU,CACxE,CACA,OAAO8B,EACN,CACC,OACA,SAEA,YAAY,EAAe,CAC1B,MAAO,CACN,MACC,EACA,IACIjC,EAAKG,EAAWK,EAAOM,CAAO,CACpC,CACD,CACD,EACAnB,CACD,CACD,CAyBA,SAAgBuC,EACf,EACC,CA8ED,SAASC,EAAM,EAKH,CACX,IAAMC,MAAwB,CAC7B,IAAM3C,EAAcI,EAAc,SAC/BwC,EACAxC,EAAc,SAAS,SAAW,CAAC,EACnC,GACAA,EAAc,SAAS,MACxB,EACCH,EAAuB,EAC1B,OAAO4C,EACNzC,EAAc,WAEbJ,CACD,EACAI,EAAc,SACd,SACD,CACD,EAGA,OAAOL,EAAkB,CACxB,GAAGK,EACH,GAAG0C,EACH,WAAYH,CACb,CAAU,CACX,CACA,OAAOD,CACR,C"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ContractOutput, ContractSchema, Decoder, LegacyParser, ValidationIssue } from "../contracts/contract.mjs";
|
|
2
|
+
import { Effect, Schema } from "effect";
|
|
3
|
+
export declare class ContractValidationError {
|
|
4
|
+
readonly issues: readonly ValidationIssue[];
|
|
5
|
+
readonly _tag = "ContractValidationError";
|
|
6
|
+
constructor(issues: readonly ValidationIssue[]);
|
|
7
|
+
}
|
|
8
|
+
export interface EffectDecoder<Input, Output, Error = never, Requirements = never> extends Decoder<Input, Output, Effect.Effect<Output, Error, Requirements>> {
|
|
9
|
+
readonly kind: 'effect-contract';
|
|
10
|
+
}
|
|
11
|
+
/** Explicit custom decoders preserve their exact typed error and service channels. */
|
|
12
|
+
export declare function effectContract<Input, Output, Error = never, Requirements = never>(decode: (value: unknown) => Effect.Effect<Output, Error, Requirements>): EffectDecoder<Input, Output, Error, Requirements>;
|
|
13
|
+
/** Encoding requirements remain independent of the decoder's requirements. */
|
|
14
|
+
export declare function effectSchema<const S extends Schema.Constraint>(schema: S): {
|
|
15
|
+
types?: {
|
|
16
|
+
readonly input: S["Encoded"];
|
|
17
|
+
readonly output: S["Type"];
|
|
18
|
+
} | undefined;
|
|
19
|
+
decode: (value: unknown) => Effect.Effect<S["Type"], Schema.SchemaError, S["DecodingServices"]>;
|
|
20
|
+
kind: 'effect-contract';
|
|
21
|
+
schema: S;
|
|
22
|
+
encode: (input: S["Type"], options?: import("effect/SchemaAST").ParseOptions) => Effect.Effect<S["Encoded"], Schema.SchemaError, S["EncodingServices"]>;
|
|
23
|
+
};
|
|
24
|
+
/** The service-free bridge cannot erase decoder requirements. */
|
|
25
|
+
export declare function effectStandardSchema<const S extends Schema.ConstraintDecoder<unknown>>(schema: S): import("effect/StandardSchema").StandardSchemaV1<S["Encoded"], S["Type"]> & S;
|
|
26
|
+
export type ContractDecoderError<S> = S extends EffectDecoder<unknown, unknown, infer Error, unknown> ? Error : S extends LegacyParser ? never : S extends ContractSchema ? ContractValidationError : never;
|
|
27
|
+
export type ContractDecoderRequirements<S> = S extends EffectDecoder<unknown, unknown, unknown, infer Requirements> ? Requirements : never;
|
|
28
|
+
/** Decode input, fresh results, and final replay values within the current Effect scope. */
|
|
29
|
+
export declare function decodeEffectContract<S extends ContractSchema>(schema: S, value: unknown): Effect.Effect<ContractOutput<S>, ContractDecoderError<S>, ContractDecoderRequirements<S>>;
|
|
30
|
+
//# sourceMappingURL=schema.d.mts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{decodeContract as e}from"../contracts/contract.mjs";import{Effect as t,Schema as n}from"effect";var r=class{issues;_tag=`ContractValidationError`;constructor(e){this.issues=e}};function i(e){return{kind:`effect-contract`,decode:e}}function a(e){return{...i(n.decodeUnknownEffect(e)),schema:e,encode:n.encodeEffect(e)}}function o(e){return n.toStandardSchemaV1(e)}function s(n,i){return t.suspend(()=>`kind`in n&&n.kind===`effect-contract`?n.decode(i):t.promise(()=>e(n,i)).pipe(t.flatMap(e=>{if(!e.issues)return t.succeed(e.value);let i=new r(e.issues);return`parse`in n?t.die(i):t.fail(i)})))}export{r as ContractValidationError,s as decodeEffectContract,i as effectContract,a as effectSchema,o as effectStandardSchema};
|
|
2
|
+
//# sourceMappingURL=schema.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.mjs","names":["ContractValidationError","issues","effectContract","effectSchema","Schema","schema","effectStandardSchema","decodeEffectContract","Effect","value","decodeContract","result","error"],"sources":["../../../src/modules/effect/schema.ts"],"sourcesContent":["/* oxlint-disable anti-slop/no-unknown-parameters -- Explicit schema decoder boundaries validate untrusted transport input. */\nimport { Effect, Schema } from 'effect'\nimport type {\n\tContractSchema,\n\tContractOutput,\n\tDecoder,\n\tLegacyParser,\n\tNeutralSchema,\n\tValidationIssue,\n} from '../contracts/contract'\nimport { decodeContract } from '../contracts/contract'\n\nexport class ContractValidationError {\n\treadonly _tag = 'ContractValidationError'\n\tconstructor(readonly issues: readonly ValidationIssue[]) {}\n}\nexport interface EffectDecoder<Input, Output, Error = never, Requirements = never> extends Decoder<\n\tInput,\n\tOutput,\n\tEffect.Effect<Output, Error, Requirements>\n> {\n\treadonly kind: 'effect-contract'\n}\n/** Explicit custom decoders preserve their exact typed error and service channels. */\nexport function effectContract<Input, Output, Error = never, Requirements = never>(\n\tdecode: (value: unknown) => Effect.Effect<Output, Error, Requirements>,\n): EffectDecoder<Input, Output, Error, Requirements> {\n\treturn { kind: 'effect-contract', decode }\n}\n/** Encoding requirements remain independent of the decoder's requirements. */\nexport function effectSchema<const S extends Schema.Constraint>(schema: S) {\n\treturn {\n\t\t...effectContract<S['Encoded'], S['Type'], Schema.SchemaError, S['DecodingServices']>(\n\t\t\tSchema.decodeUnknownEffect(schema),\n\t\t),\n\t\tschema,\n\t\tencode: Schema.encodeEffect(schema),\n\t}\n}\n/** The service-free bridge cannot erase decoder requirements. */\nexport function effectStandardSchema<const S extends Schema.ConstraintDecoder<unknown>>(schema: S) {\n\treturn Schema.toStandardSchemaV1(schema)\n}\nexport type ContractDecoderError<S> =\n\tS extends EffectDecoder<unknown, unknown, infer Error, unknown>\n\t\t? Error\n\t\t: S extends LegacyParser\n\t\t\t? never\n\t\t\t: S extends ContractSchema\n\t\t\t\t? ContractValidationError\n\t\t\t\t: never\nexport type ContractDecoderRequirements<S> =\n\tS extends EffectDecoder<unknown, unknown, unknown, infer Requirements> ? Requirements : never\n\n/** Decode input, fresh results, and final replay values within the current Effect scope. */\nexport function decodeEffectContract<S extends ContractSchema>(\n\tschema: S,\n\tvalue: unknown,\n): Effect.Effect<ContractOutput<S>, ContractDecoderError<S>, ContractDecoderRequirements<S>> {\n\tconst decoded = Effect.suspend(() => {\n\t\tif ('kind' in schema && schema.kind === 'effect-contract') {\n\t\t\t// SAFETY: only the explicit optional adapter exposes this discriminator.\n\t\t\treturn schema.decode(value) as Effect.Effect<unknown, unknown, unknown>\n\t\t}\n\t\t// SAFETY: the Effect discriminator was excluded; ordinary adapters return validation results.\n\t\treturn Effect.promise(() => decodeContract(schema as NeutralSchema, value)).pipe(\n\t\t\tEffect.flatMap((result) => {\n\t\t\t\tif (!result.issues) return Effect.succeed(result.value)\n\t\t\t\tconst error = new ContractValidationError(result.issues)\n\t\t\t\t// Legacy parsers have always exposed validation throws as defects.\n\t\t\t\treturn 'parse' in schema ? Effect.die(error) : Effect.fail(error)\n\t\t\t}),\n\t\t)\n\t})\n\t// SAFETY: conditional channels correspond to the explicit Effect branch or neutral validation branch.\n\treturn decoded as Effect.Effect<\n\t\tContractOutput<S>,\n\t\tContractDecoderError<S>,\n\t\tContractDecoderRequirements<S>\n\t>\n}\n"],"mappings":"A,uGAYA,IAAaA,EAAb,KAAqC,CAEf,OADrB,KAAgB,0BAChB,YAAY,EAA6C,CAApC,KAAA,OAAAC,CAAqC,CAC3D,EASA,SAAgBC,EACf,EACoD,CACpD,MAAO,CAAE,KAAM,kBAAmB,QAAO,CAC1C,CAEA,SAAgBC,EAAgD,EAAW,CAC1E,MAAO,CACN,GAAGD,EACFE,EAAO,oBAAoBC,CAAM,CAClC,EACA,SACA,OAAQD,EAAO,aAAaC,CAAM,CACnC,CACD,CAEA,SAAgBC,EAAwE,EAAW,CAClG,OAAOF,EAAO,mBAAmBC,CAAM,CACxC,CAaA,SAAgBE,EACf,EACA,EAC4F,CAiB5F,OAhBgBC,EAAO,YAClB,SAAUH,GAAUA,EAAO,OAAS,kBAEhCA,EAAO,OAAOI,CAAK,EAGpBD,EAAO,YAAcE,EAAeL,EAAyBI,CAAK,CAAC,CAAC,CAAC,KAC3ED,EAAO,QAAS,GAAW,CAC1B,GAAI,CAACG,EAAO,OAAQ,OAAOH,EAAO,QAAQG,EAAO,KAAK,EACtD,IAAMC,EAAQ,IAAIZ,EAAwBW,EAAO,MAAM,EAEvD,MAAO,UAAWN,EAASG,EAAO,IAAII,CAAK,EAAIJ,EAAO,KAAKI,CAAK,CACjE,CAAC,CACF,CAGY,CAKd,C"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
/** The request an operation joined: its outermost operation, its direct caller, and its nesting depth. */
|
|
3
|
+
export type RequestScope = Readonly<{
|
|
4
|
+
root: string;
|
|
5
|
+
parent: string;
|
|
6
|
+
depth: number;
|
|
7
|
+
}>;
|
|
8
|
+
/** How nested operations audit when an enclosing operation already declares an audit callback. */
|
|
9
|
+
export type NestedAuditMode = 'fold' | 'separate';
|
|
10
|
+
/** Request-wide state shared by every operation yielded inside the same Effect program. */
|
|
11
|
+
export type ScopeState = Readonly<{
|
|
12
|
+
scope: RequestScope;
|
|
13
|
+
/** Whether some enclosing operation declares an audit callback. */
|
|
14
|
+
audited: boolean;
|
|
15
|
+
/** Failure values already reported to the failure-audit sink in this request. */
|
|
16
|
+
reported: WeakSet<object>;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* Run an operation inside the current request scope, opening one when none exists.
|
|
20
|
+
* `run` receives the state the operation entered (`undefined` for a root) and the
|
|
21
|
+
* state it provides to the operations yielded inside it.
|
|
22
|
+
*/
|
|
23
|
+
export declare function enterRequestScope<Value, Error, Requirements>(operation: string, audits: boolean, run: (entered: ScopeState | undefined, current: ScopeState) => Effect.Effect<Value, Error, Requirements>): Effect.Effect<Value, Error, Requirements>;
|
|
24
|
+
export declare function auditFolded(mode: NestedAuditMode | undefined, entered: ScopeState | undefined): boolean;
|
|
25
|
+
//# sourceMappingURL=scope.d.mts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{Context as e,Effect as t}from"effect";const n=e.Reference(`cvx-kit/effect/RequestScope`,{defaultValue:()=>void 0});function r(e,r,i){return n.use(a=>{let o={scope:{root:a?.scope.root??e,parent:e,depth:(a?.scope.depth??0)+1},audited:r||(a?.audited??!1),reported:a?.reported??/* @__PURE__ */ new WeakSet};return i(a,o).pipe(t.provideService(n,o))})}function i(e,t){return(e??`fold`)===`fold`&&t?.audited===!0}export{i as auditFolded,r as enterRequestScope};
|
|
2
|
+
//# sourceMappingURL=scope.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.mjs","names":["CurrentScope","Context","enterRequestScope","current","entered","operation","audits","run","Effect","auditFolded","mode"],"sources":["../../../src/modules/effect/scope.ts"],"sourcesContent":["import { Context, Effect } from 'effect'\n\n/** The request an operation joined: its outermost operation, its direct caller, and its nesting depth. */\nexport type RequestScope = Readonly<{ root: string; parent: string; depth: number }>\n\n/** How nested operations audit when an enclosing operation already declares an audit callback. */\nexport type NestedAuditMode = 'fold' | 'separate'\n\n/** Request-wide state shared by every operation yielded inside the same Effect program. */\nexport type ScopeState = Readonly<{\n\tscope: RequestScope\n\t/** Whether some enclosing operation declares an audit callback. */\n\taudited: boolean\n\t/** Failure values already reported to the failure-audit sink in this request. */\n\treported: WeakSet<object>\n}>\n\nconst CurrentScope = Context.Reference<ScopeState | undefined>('cvx-kit/effect/RequestScope', {\n\tdefaultValue: () => undefined,\n})\n\n/**\n * Run an operation inside the current request scope, opening one when none exists.\n * `run` receives the state the operation entered (`undefined` for a root) and the\n * state it provides to the operations yielded inside it.\n */\nexport function enterRequestScope<Value, Error, Requirements>(\n\toperation: string,\n\taudits: boolean,\n\trun: (\n\t\tentered: ScopeState | undefined,\n\t\tcurrent: ScopeState,\n\t) => Effect.Effect<Value, Error, Requirements>,\n): Effect.Effect<Value, Error, Requirements> {\n\treturn CurrentScope.use((entered) => {\n\t\tconst current: ScopeState = {\n\t\t\tscope: {\n\t\t\t\troot: entered?.scope.root ?? operation,\n\t\t\t\tparent: operation,\n\t\t\t\tdepth: (entered?.scope.depth ?? 0) + 1,\n\t\t\t},\n\t\t\taudited: audits || (entered?.audited ?? false),\n\t\t\treported: entered?.reported ?? new WeakSet(),\n\t\t}\n\t\treturn run(entered, current).pipe(Effect.provideService(CurrentScope, current))\n\t})\n}\n\nexport function auditFolded(mode: NestedAuditMode | undefined, entered: ScopeState | undefined) {\n\treturn (mode ?? 'fold') === 'fold' && entered?.audited === true\n}\n"],"mappings":"A,6CAiBA,MAAMA,EAAeC,EAAQ,UAAkC,8BAA+B,CAC7F,iBAAoB,IAAA,EACrB,CAAC,EAOD,SAAgBC,EACf,EACA,EACA,EAI4C,CAC5C,OAAOF,EAAa,IAAK,GAAY,CACpC,IAAMG,EAAsB,CAC3B,MAAO,CACN,KAAMC,GAAS,MAAM,MAAQC,EAC7B,OAAQA,EACR,OAAQD,GAAS,MAAM,OAAS,GAAK,CACtC,EACA,QAASE,IAAWF,GAAS,SAAW,IACxC,SAAUA,GAAS,0BAAY,IAAI,OACpC,EACA,OAAOG,EAAIH,EAASD,CAAO,CAAC,CAAC,KAAKK,EAAO,eAAeR,EAAcG,CAAO,CAAC,CAC/E,CAAC,CACF,CAEA,SAAgBM,EAAY,EAAmC,EAAiC,CAC/F,OAAQC,GAAQ,UAAY,QAAUN,GAAS,UAAY,EAC5D,C"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { WorkflowBindingError, WorkflowExecution, WorkflowHostState, WorkflowNativeStatus, WorkflowOutcome, WorkflowTransition } from "../contracts/workflow.mjs";
|
|
2
|
+
import { ContractInput, ContractOutput, ContractSchema } from "../contracts/contract.mjs";
|
|
3
|
+
import { IdempotencyInvocation } from "../contracts/idempotency.mjs";
|
|
4
|
+
import { EffectIdempotencyPreparation } from "./idempotency.mjs";
|
|
5
|
+
import { CallbackError, CallbackRequirements, EffectValue } from "./operation.mjs";
|
|
6
|
+
import { ContractDecoderError, ContractDecoderRequirements } from "./schema.mjs";
|
|
7
|
+
import { Effect } from "effect";
|
|
8
|
+
type Supported<A> = A | PromiseLike<A> | Effect.Effect<A, unknown, unknown>;
|
|
9
|
+
/** Services exist only inside a new native invocation; ordinary throws/rejections remain defects. */
|
|
10
|
+
export declare function effectWorkflowAttempt<Args, Authorize, Execute>(configuration: {
|
|
11
|
+
authorize: (execution: WorkflowExecution<Args>) => Authorize;
|
|
12
|
+
execute: (execution: WorkflowExecution<Args>, authority: EffectValue<Authorize>) => Execute;
|
|
13
|
+
}): (input: WorkflowExecution<Args>) => Effect.Effect<EffectValue<Execute>, WorkflowBindingError | CallbackError<Authorize | Execute>, CallbackRequirements<Authorize | Execute>>;
|
|
14
|
+
/** Native mutation promise rejects outside the child transaction before mapping declared terminal details. */
|
|
15
|
+
export declare function effectTerminalWorkflowAttempt<Args, Authorize, const Result extends ContractSchema, const Failure extends ContractSchema, Terminal extends Supported<ContractInput<Failure> | undefined>>(configuration: ({
|
|
16
|
+
kind: 'mutation';
|
|
17
|
+
atomicJournalProof: 'host-verified';
|
|
18
|
+
} | {
|
|
19
|
+
kind: 'action';
|
|
20
|
+
protectedMutation: EffectReceiptProtectedWorkflowMutation<Args, unknown, unknown, unknown>;
|
|
21
|
+
}) & {
|
|
22
|
+
authorize: (execution: WorkflowExecution<Args>) => Authorize;
|
|
23
|
+
invokeMutation: (execution: WorkflowExecution<Args>, authority: EffectValue<Authorize>) => Promise<ContractInput<Result>>;
|
|
24
|
+
terminal: (error: unknown) => Terminal;
|
|
25
|
+
result: Result;
|
|
26
|
+
failure: Failure;
|
|
27
|
+
}): (input: WorkflowExecution<Args>) => Effect.Effect<WorkflowOutcome<ContractInput<Result>, ContractOutput<Failure>>, WorkflowBindingError | CallbackError<Authorize | Terminal> | ContractDecoderError<Result | Failure>, CallbackRequirements<Authorize | Terminal> | ContractDecoderRequirements<Result | Failure>>;
|
|
28
|
+
declare const protectedMutation: unique symbol;
|
|
29
|
+
export interface EffectReceiptProtectedWorkflowMutation<Args, Result, Error, Requirements> {
|
|
30
|
+
readonly [protectedMutation]: {
|
|
31
|
+
args: Args;
|
|
32
|
+
result: Result;
|
|
33
|
+
};
|
|
34
|
+
readonly handler: (execution: WorkflowExecution<Args>) => Effect.Effect<Result, Error, Requirements>;
|
|
35
|
+
}
|
|
36
|
+
type Completion<Prepare> = Extract<EffectValue<Prepare>, {
|
|
37
|
+
kind: 'execute';
|
|
38
|
+
}> extends {
|
|
39
|
+
complete: (...arguments_: never[]) => infer Returned;
|
|
40
|
+
} ? Returned : never;
|
|
41
|
+
/** Host runs the handler in the secured inner native mutation transaction, including receipt completion. */
|
|
42
|
+
export declare function effectReceiptWorkflowMutation<Args, Authorize, const Replay extends ContractSchema, Prepare extends Supported<EffectIdempotencyPreparation<ContractOutput<Replay>, unknown, unknown>>, Execute extends Supported<ContractOutput<Replay>>>(configuration: {
|
|
43
|
+
authorize: (execution: WorkflowExecution<Args>) => Authorize;
|
|
44
|
+
receipt: (authority: EffectValue<Authorize>) => {
|
|
45
|
+
replayResult: Replay;
|
|
46
|
+
prepare: (invocation: IdempotencyInvocation) => Prepare;
|
|
47
|
+
};
|
|
48
|
+
invocation: (execution: WorkflowExecution<Args>, authority: EffectValue<Authorize>) => IdempotencyInvocation;
|
|
49
|
+
execute: (execution: WorkflowExecution<Args>, authority: EffectValue<Authorize>) => Execute;
|
|
50
|
+
}): EffectReceiptProtectedWorkflowMutation<Args, ContractOutput<Replay>, WorkflowBindingError | CallbackError<Authorize | Prepare | Execute | Completion<Prepare>> | ContractDecoderError<Replay>, CallbackRequirements<Authorize | Prepare | Execute | Completion<Prepare>> | ContractDecoderRequirements<Replay>>;
|
|
51
|
+
type StateResult<Read> = EffectValue<Read> extends WorkflowHostState<infer Result, unknown> ? Result : never;
|
|
52
|
+
type StateFailure<Read> = EffectValue<Read> extends WorkflowHostState<unknown, infer Failure> ? Failure : never;
|
|
53
|
+
/** The host still owns native manager calls and transactional/CAS writes; each method retains only its used channels. */
|
|
54
|
+
export declare function effectWorkflowStatusBindings<Authorize, Read extends Supported<WorkflowHostState>, Write, Native extends Supported<WorkflowNativeStatus>, Receipt extends Supported<WorkflowOutcome<StateResult<Read>, StateFailure<Read>> | undefined>, Cancel, Restart>(configuration: {
|
|
55
|
+
authorize: () => Authorize;
|
|
56
|
+
read: () => Read;
|
|
57
|
+
write: (expectedGeneration: number, state: WorkflowHostState<StateResult<Read>, StateFailure<Read>>) => Write;
|
|
58
|
+
nativeStatus: () => Native;
|
|
59
|
+
receiptOutcome: () => Receipt;
|
|
60
|
+
cancelNative: () => Cancel;
|
|
61
|
+
restartNative: () => Restart;
|
|
62
|
+
}): {
|
|
63
|
+
callback(expectedGeneration: number, nativeStatus: WorkflowNativeStatus, outcome?: WorkflowOutcome<StateResult<Read>, StateFailure<Read>>): Effect.Effect<WorkflowTransition<StateResult<Read>, StateFailure<Read>>, WorkflowBindingError | CallbackError<Authorize> | CallbackError<Read> | CallbackError<Write>, CallbackRequirements<Authorize> | CallbackRequirements<Read> | CallbackRequirements<Write>>;
|
|
64
|
+
reconcile(expectedGeneration: number): Effect.Effect<WorkflowTransition<StateResult<Read>, StateFailure<Read>>, WorkflowBindingError | CallbackError<Authorize> | CallbackError<Native> | CallbackError<Read> | CallbackError<Receipt> | CallbackError<Write>, CallbackRequirements<Authorize> | CallbackRequirements<Native> | CallbackRequirements<Read> | CallbackRequirements<Receipt> | CallbackRequirements<Write>>;
|
|
65
|
+
cancel(expectedGeneration: number): Effect.Effect<WorkflowTransition<StateResult<Read>, StateFailure<Read>>, WorkflowBindingError | CallbackError<Authorize> | CallbackError<Cancel> | CallbackError<Read> | CallbackError<Write>, CallbackRequirements<Authorize> | CallbackRequirements<Cancel> | CallbackRequirements<Read> | CallbackRequirements<Write>>;
|
|
66
|
+
restart(expectedGeneration: number): Effect.Effect<{
|
|
67
|
+
kind: 'ignored';
|
|
68
|
+
state: WorkflowHostState<StateResult<Read>, StateFailure<Read>>;
|
|
69
|
+
} | {
|
|
70
|
+
kind: 'applied';
|
|
71
|
+
state: WorkflowHostState<StateResult<Read>, StateFailure<Read>>;
|
|
72
|
+
}, WorkflowBindingError | CallbackError<Authorize> | CallbackError<Read> | CallbackError<Restart> | CallbackError<Write>, CallbackRequirements<Authorize> | CallbackRequirements<Read> | CallbackRequirements<Restart> | CallbackRequirements<Write>>;
|
|
73
|
+
};
|
|
74
|
+
export {};
|
|
75
|
+
//# sourceMappingURL=workflow.d.mts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{WorkflowBindingError as e,workflowCancel as t,workflowExecution as n,workflowRestart as r,workflowTransition as i}from"../contracts/workflow.mjs";import{normalizeEffect as a}from"./normalize.mjs";import{decodeEffectContract as o}from"./schema.mjs";import{Effect as s}from"effect";function c(e){return t=>s.gen(function*(){let n=yield*f(t),r=yield*a(()=>e.authorize(n));return yield*a(()=>e.execute(n,r))})}function l(e){return t=>s.gen(function*(){let n=yield*f(t),r=yield*a(()=>e.authorize(n)),i=yield*s.tryPromise({try:()=>e.invokeMutation(n,r),catch:e=>e}).pipe(s.map(e=>({kind:`success`,value:e})),s.catch(e=>s.succeed({kind:`rejected`,error:e})));if(i.kind===`rejected`){let t=yield*a(()=>e.terminal(i.error));if(t===void 0)return yield*s.die(i.error);let r=yield*o(e.failure,t);return yield*f({...n,args:r}),{version:1,kind:`failed`,error:r}}return yield*o(e.result,i.value),yield*f({...n,args:i.value}),{version:1,kind:`succeeded`,value:i.value}})}function u(e){return{handler:t=>s.gen(function*(){let n=yield*f(t),r=yield*a(()=>e.authorize(n)),i=e.receipt(r),s=yield*a(()=>i.prepare(e.invocation(n,r)));if(s.kind===`replay`)return yield*o(i.replayResult,s.result);let c=yield*a(()=>e.execute(n,r)),l=s.complete;return yield*a(()=>l(c)),c})}}function d(e){function n(){return a(()=>e.read()).pipe(s.map(e=>e))}function o(t,r,o){return s.gen(function*(){let s=yield*n(),c={generation:t,nativeStatus:r},l=yield*p(()=>i(s,o===void 0?c:{...c,outcome:o}));return l.kind===`applied`&&(yield*a(()=>e.write(t,l.state))),l})}return{callback(t,n,r){return a(()=>e.authorize()).pipe(s.flatMap(()=>o(t,n,r)))},reconcile(t){return s.gen(function*(){return yield*a(()=>e.authorize()),yield*o(t,yield*a(()=>e.nativeStatus()),yield*a(()=>e.receiptOutcome()))})},cancel(r){return s.gen(function*(){yield*a(()=>e.authorize());let i=yield*n(),o=yield*p(()=>t(i,r));return o.kind===`applied`&&i.status===`running`&&(yield*a(()=>e.cancelNative()),yield*a(()=>e.write(r,o.state))),o})},restart(t){return s.gen(function*(){yield*a(()=>e.authorize());let i=yield*n();if(i.generation!==t)return{kind:`ignored`,state:i};let o=yield*p(()=>r(i));return yield*a(()=>e.restartNative()),yield*a(()=>e.write(t,o)),{kind:`applied`,state:o}})}}}function f(e){return p(()=>n(e))}function p(t){return s.try({try:t,catch:t=>{if(t instanceof e)return t;throw t}})}export{u as effectReceiptWorkflowMutation,l as effectTerminalWorkflowAttempt,c as effectWorkflowAttempt,d as effectWorkflowStatusBindings};
|
|
2
|
+
//# sourceMappingURL=workflow.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow.mjs","names":["effectWorkflowAttempt","Effect","execution","descriptor","input","authority","normalizeEffect","configuration","effectTerminalWorkflowAttempt","native","error","failure","decodeEffectContract","effectReceiptWorkflowMutation","adapter","preparation","value","complete","effectWorkflowStatusBindings","read","state","apply","current","update","expectedGeneration","transition","protocol","workflowTransition","outcome","nativeStatus","workflowCancel","workflowRestart","workflowExecution","evaluate","WorkflowBindingError"],"sources":["../../../src/modules/effect/workflow.ts"],"sourcesContent":["import { Effect } from 'effect'\nimport type { ContractInput, ContractOutput, ContractSchema } from '../contracts/contract'\nimport {\n\tWorkflowBindingError,\n\tworkflowExecution,\n\tworkflowTransition,\n\tworkflowCancel,\n\tworkflowRestart,\n\ttype WorkflowExecution,\n\ttype WorkflowOutcome,\n\ttype WorkflowHostState,\n\ttype WorkflowNativeStatus,\n} from '../contracts/workflow'\nimport type { IdempotencyInvocation } from '../contracts/idempotency'\nimport type { EffectIdempotencyPreparation } from './idempotency'\nimport type { CallbackError, CallbackRequirements, EffectValue } from './operation'\nimport { normalizeEffect } from './normalize'\nimport {\n\tdecodeEffectContract,\n\ttype ContractDecoderError,\n\ttype ContractDecoderRequirements,\n} from './schema'\n\ntype Supported<A> = A | PromiseLike<A> | Effect.Effect<A, unknown, unknown>\n/** Services exist only inside a new native invocation; ordinary throws/rejections remain defects. */\nexport function effectWorkflowAttempt<Args, Authorize, Execute>(configuration: {\n\tauthorize: (execution: WorkflowExecution<Args>) => Authorize\n\texecute: (execution: WorkflowExecution<Args>, authority: EffectValue<Authorize>) => Execute\n}) {\n\treturn (\n\t\tinput: WorkflowExecution<Args>,\n\t): Effect.Effect<\n\t\tEffectValue<Execute>,\n\t\tWorkflowBindingError | CallbackError<Authorize | Execute>,\n\t\tCallbackRequirements<Authorize | Execute>\n\t> =>\n\t\tEffect.gen(function* () {\n\t\t\tconst execution = yield* descriptor(input)\n\t\t\tconst authority = yield* normalizeEffect(() => configuration.authorize(execution))\n\t\t\treturn yield* normalizeEffect(() => configuration.execute(execution, authority))\n\t\t})\n}\n/** Native mutation promise rejects outside the child transaction before mapping declared terminal details. */\nexport function effectTerminalWorkflowAttempt<\n\tArgs,\n\tAuthorize,\n\tconst Result extends ContractSchema,\n\tconst Failure extends ContractSchema,\n\tTerminal extends Supported<ContractInput<Failure> | undefined>,\n>(\n\tconfiguration: (\n\t\t| { kind: 'mutation'; atomicJournalProof: 'host-verified' }\n\t\t| {\n\t\t\t\tkind: 'action'\n\t\t\t\tprotectedMutation: EffectReceiptProtectedWorkflowMutation<Args, unknown, unknown, unknown>\n\t\t }\n\t) & {\n\t\tauthorize: (execution: WorkflowExecution<Args>) => Authorize\n\t\tinvokeMutation: (\n\t\t\texecution: WorkflowExecution<Args>,\n\t\t\tauthority: EffectValue<Authorize>,\n\t\t) => Promise<ContractInput<Result>>\n\t\t// oxlint-disable-next-line anti-slop/no-unknown-parameters -- A rejected native mutation can throw any value; the host terminal callback classifies it before failure contract validation.\n\t\tterminal: (error: unknown) => Terminal\n\t\tresult: Result\n\t\tfailure: Failure\n\t},\n) {\n\treturn (\n\t\tinput: WorkflowExecution<Args>,\n\t): Effect.Effect<\n\t\tWorkflowOutcome<ContractInput<Result>, ContractOutput<Failure>>,\n\t\t| WorkflowBindingError\n\t\t| CallbackError<Authorize | Terminal>\n\t\t| ContractDecoderError<Result | Failure>,\n\t\tCallbackRequirements<Authorize | Terminal> | ContractDecoderRequirements<Result | Failure>\n\t> =>\n\t\tEffect.gen(function* () {\n\t\t\tconst execution = yield* descriptor(input)\n\t\t\tconst authority = yield* normalizeEffect(() => configuration.authorize(execution))\n\t\t\tconst native = yield* Effect.tryPromise({\n\t\t\t\ttry: () => configuration.invokeMutation(execution, authority),\n\t\t\t\tcatch: (error) => error,\n\t\t\t}).pipe(\n\t\t\t\tEffect.map((value) => ({ kind: 'success' as const, value })),\n\t\t\t\tEffect.catch((error) => Effect.succeed({ kind: 'rejected' as const, error })),\n\t\t\t)\n\t\t\tif (native.kind === 'rejected') {\n\t\t\t\tconst failure = yield* normalizeEffect(() => configuration.terminal(native.error))\n\t\t\t\tif (failure === undefined) return yield* Effect.die(native.error)\n\t\t\t\t// SAFETY: Terminal is constrained to this exact failure wire input or undefined.\n\t\t\t\tconst error = yield* decodeEffectContract(\n\t\t\t\t\tconfiguration.failure,\n\t\t\t\t\tfailure as ContractInput<Failure>,\n\t\t\t\t)\n\t\t\t\tyield* descriptor({ ...execution, args: error })\n\t\t\t\treturn { version: 1 as const, kind: 'failed' as const, error }\n\t\t\t}\n\t\t\tyield* decodeEffectContract(configuration.result, native.value)\n\t\t\tyield* descriptor({ ...execution, args: native.value })\n\t\t\treturn { version: 1 as const, kind: 'succeeded' as const, value: native.value }\n\t\t})\n}\ndeclare const protectedMutation: unique symbol\nexport interface EffectReceiptProtectedWorkflowMutation<Args, Result, Error, Requirements> {\n\treadonly [protectedMutation]: { args: Args; result: Result }\n\treadonly handler: (\n\t\texecution: WorkflowExecution<Args>,\n\t) => Effect.Effect<Result, Error, Requirements>\n}\ntype Completion<Prepare> =\n\tExtract<EffectValue<Prepare>, { kind: 'execute' }> extends {\n\t\tcomplete: (...arguments_: never[]) => infer Returned\n\t}\n\t\t? Returned\n\t\t: never\n/** Host runs the handler in the secured inner native mutation transaction, including receipt completion. */\nexport function effectReceiptWorkflowMutation<\n\tArgs,\n\tAuthorize,\n\tconst Replay extends ContractSchema,\n\tPrepare extends Supported<EffectIdempotencyPreparation<ContractOutput<Replay>, unknown, unknown>>,\n\tExecute extends Supported<ContractOutput<Replay>>,\n>(configuration: {\n\tauthorize: (execution: WorkflowExecution<Args>) => Authorize\n\treceipt: (authority: EffectValue<Authorize>) => {\n\t\treplayResult: Replay\n\t\tprepare: (invocation: IdempotencyInvocation) => Prepare\n\t}\n\tinvocation: (\n\t\texecution: WorkflowExecution<Args>,\n\t\tauthority: EffectValue<Authorize>,\n\t) => IdempotencyInvocation\n\texecute: (execution: WorkflowExecution<Args>, authority: EffectValue<Authorize>) => Execute\n}): EffectReceiptProtectedWorkflowMutation<\n\tArgs,\n\tContractOutput<Replay>,\n\t| WorkflowBindingError\n\t| CallbackError<Authorize | Prepare | Execute | Completion<Prepare>>\n\t| ContractDecoderError<Replay>,\n\t| CallbackRequirements<Authorize | Prepare | Execute | Completion<Prepare>>\n\t| ContractDecoderRequirements<Replay>\n> {\n\tconst handler = (input: WorkflowExecution<Args>) =>\n\t\tEffect.gen(function* () {\n\t\t\tconst execution = yield* descriptor(input)\n\t\t\tconst authority = yield* normalizeEffect(() => configuration.authorize(execution))\n\t\t\tconst adapter = configuration.receipt(authority)\n\t\t\tconst preparation = yield* normalizeEffect(() =>\n\t\t\t\tadapter.prepare(configuration.invocation(execution, authority)),\n\t\t\t)\n\t\t\tif (preparation.kind === 'replay')\n\t\t\t\treturn yield* decodeEffectContract(adapter.replayResult, preparation.result)\n\t\t\tconst value = yield* normalizeEffect(() => configuration.execute(execution, authority))\n\t\t\t// SAFETY: the execute branch came from this exact Prepare value; recover its complete callback rather than the broad constraint.\n\t\t\tconst complete = preparation.complete as (\n\t\t\t\tresult: ContractOutput<Replay>,\n\t\t\t) => Completion<Prepare>\n\t\t\t// SAFETY: Execute's supported success is the exact final replay output contract.\n\t\t\tyield* normalizeEffect(() => complete(value as ContractOutput<Replay>))\n\t\t\t// SAFETY: Execute's supported success is the exact final replay output contract.\n\t\t\treturn value as ContractOutput<Replay>\n\t\t})\n\t// SAFETY: only private receipt evidence is asserted; handler's inferred E/R remain checked against the public return.\n\treturn { handler } as ReceiptEvidence<Args, ContractOutput<Replay>, typeof handler>\n}\ntype ReceiptEvidence<Args, Result, Handler> = {\n\thandler: Handler\n\treadonly [protectedMutation]: { args: Args; result: Result }\n}\ntype StateResult<Read> =\n\tEffectValue<Read> extends WorkflowHostState<infer Result, unknown> ? Result : never\ntype StateFailure<Read> =\n\tEffectValue<Read> extends WorkflowHostState<unknown, infer Failure> ? Failure : never\n/** The host still owns native manager calls and transactional/CAS writes; each method retains only its used channels. */\nexport function effectWorkflowStatusBindings<\n\tAuthorize,\n\tRead extends Supported<WorkflowHostState>,\n\tWrite,\n\tNative extends Supported<WorkflowNativeStatus>,\n\tReceipt extends Supported<WorkflowOutcome<StateResult<Read>, StateFailure<Read>> | undefined>,\n\tCancel,\n\tRestart,\n>(configuration: {\n\tauthorize: () => Authorize\n\tread: () => Read\n\twrite: (\n\t\texpectedGeneration: number,\n\t\tstate: WorkflowHostState<StateResult<Read>, StateFailure<Read>>,\n\t) => Write\n\tnativeStatus: () => Native\n\treceiptOutcome: () => Receipt\n\tcancelNative: () => Cancel\n\trestartNative: () => Restart\n}) {\n\ttype State = WorkflowHostState<StateResult<Read>, StateFailure<Read>>\n\tfunction read() {\n\t\t// SAFETY: Read's supported success is the host state whose outcome types are extracted above.\n\t\treturn normalizeEffect(() => configuration.read()).pipe(Effect.map((state) => state as State))\n\t}\n\tfunction apply(\n\t\texpectedGeneration: number,\n\t\tnativeStatus: WorkflowNativeStatus,\n\t\toutcome?: WorkflowOutcome<StateResult<Read>, StateFailure<Read>>,\n\t) {\n\t\treturn Effect.gen(function* () {\n\t\t\tconst current = yield* read()\n\t\t\tconst update = { generation: expectedGeneration, nativeStatus }\n\t\t\tconst transition = yield* protocol(() =>\n\t\t\t\tworkflowTransition(current, outcome === undefined ? update : { ...update, outcome }),\n\t\t\t)\n\t\t\tif (transition.kind === 'applied')\n\t\t\t\tyield* normalizeEffect(() => configuration.write(expectedGeneration, transition.state))\n\t\t\treturn transition\n\t\t})\n\t}\n\treturn {\n\t\tcallback(\n\t\t\texpectedGeneration: number,\n\t\t\tnativeStatus: WorkflowNativeStatus,\n\t\t\toutcome?: WorkflowOutcome<StateResult<Read>, StateFailure<Read>>,\n\t\t) {\n\t\t\treturn normalizeEffect(() => configuration.authorize()).pipe(\n\t\t\t\tEffect.flatMap(() => apply(expectedGeneration, nativeStatus, outcome)),\n\t\t\t)\n\t\t},\n\t\treconcile(expectedGeneration: number) {\n\t\t\treturn Effect.gen(function* () {\n\t\t\t\tyield* normalizeEffect(() => configuration.authorize())\n\t\t\t\tconst native = yield* normalizeEffect(() => configuration.nativeStatus())\n\t\t\t\tconst outcome = yield* normalizeEffect(() => configuration.receiptOutcome())\n\t\t\t\t// SAFETY: Native and Receipt are constrained to these exact host transport values.\n\t\t\t\treturn yield* apply(\n\t\t\t\t\texpectedGeneration,\n\t\t\t\t\tnative as WorkflowNativeStatus,\n\t\t\t\t\toutcome as WorkflowOutcome<StateResult<Read>, StateFailure<Read>> | undefined,\n\t\t\t\t)\n\t\t\t})\n\t\t},\n\t\tcancel(expectedGeneration: number) {\n\t\t\treturn Effect.gen(function* () {\n\t\t\t\tyield* normalizeEffect(() => configuration.authorize())\n\t\t\t\tconst current = yield* read()\n\t\t\t\tconst transition = yield* protocol(() => workflowCancel(current, expectedGeneration))\n\t\t\t\tif (transition.kind === 'applied' && current.status === 'running') {\n\t\t\t\t\tyield* normalizeEffect(() => configuration.cancelNative())\n\t\t\t\t\tyield* normalizeEffect(() => configuration.write(expectedGeneration, transition.state))\n\t\t\t\t}\n\t\t\t\treturn transition\n\t\t\t})\n\t\t},\n\t\trestart(expectedGeneration: number) {\n\t\t\treturn Effect.gen(function* () {\n\t\t\t\tyield* normalizeEffect(() => configuration.authorize())\n\t\t\t\tconst current = yield* read()\n\t\t\t\tif (current.generation !== expectedGeneration)\n\t\t\t\t\treturn { kind: 'ignored' as const, state: current }\n\t\t\t\tconst state = yield* protocol(() => workflowRestart(current))\n\t\t\t\tyield* normalizeEffect(() => configuration.restartNative())\n\t\t\t\tyield* normalizeEffect(() => configuration.write(expectedGeneration, state))\n\t\t\t\treturn { kind: 'applied' as const, state }\n\t\t\t})\n\t\t},\n\t}\n}\nfunction descriptor<Args>(\n\tvalue: WorkflowExecution<Args>,\n): Effect.Effect<WorkflowExecution<Args>, WorkflowBindingError> {\n\treturn protocol(() => workflowExecution(value))\n}\nfunction protocol<A>(evaluate: () => A): Effect.Effect<A, WorkflowBindingError> {\n\treturn Effect.try({\n\t\ttry: evaluate,\n\t\tcatch: (error) => {\n\t\t\tif (error instanceof WorkflowBindingError) return error\n\t\t\tthrow error\n\t\t},\n\t})\n}\n"],"mappings":"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"}
|