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
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{APPROVAL_CALLBACK_KINDS as
|
|
1
|
+
import{k as e}from"../../k/index.mjs";import{APPROVAL_CALLBACK_KINDS as t,APPROVAL_DECISIONS as n,APPROVAL_QUORUM_KINDS as r,APPROVAL_RUN_STATES as i,APPROVAL_STEP_KINDS as a}from"./constants.mjs";const o=e.number().refine(Number.isFinite,`Expected a finite number`),s=e.enum(i),c=e.enum(n),l=e.enum(a),u=e.enum(t),d=e.enum(r),f=e.string().trim().min(1).max(256),p=e.string().trim().min(1).max(96).regex(/^[A-Za-z][A-Za-z0-9._-]*$/),m=e.string().trim().min(1).max(500),h=e.record(e.string().min(1).max(64).regex(/^(?![$_])[\x20-\x7E]+$/),e.string().max(512)).refine(e=>Object.keys(e).length<=32,`Metadata may contain at most 32 entries`),g=e.object({stepKey:p,actorRef:f,decision:c,reason:m.optional(),decidedAt:o}),_=g.omit(`stepKey`),v=e.object({runId:f,scopeRef:f,resourceType:p,resourceRef:f,metadata:h.optional(),decision:e.object({stepKey:p,outcome:e.union([c,e.literal(`expired`)]),evidence:e.array(g),terminalEvidence:_.optional()}).optional()}),y=v.validator,b=e.object({actorRef:f,capabilities:e.array(p).max(32),metadata:h.optional()}),x=e.object({kind:e.literal(`mutation`),handle:f,retry:e.boolean()}),S=e.object({kind:e.literal(`action`),handle:f,retry:e.boolean()}),C=e.discriminatedUnion(`kind`,[x,S]),w=e.object({kind:d,approvals:e.int().min(1).max(8)}),T=e.discriminatedUnion(`kind`,[e.object({kind:e.literal(`mutation`),key:p,callback:x}),e.object({kind:e.literal(`action`),key:p,callback:S})]),E=e.object({kind:e.literal(`notify`),key:p,callback:S}),D=e.object({kind:e.literal(`decision`),key:p,decisions:e.array(c).min(1).max(8),quorum:w,makerChecker:e.boolean(),expiresAfterMs:e.int().min(1).refine(Number.isSafeInteger,`Expected a safe integer`).optional()}),O=e.object({kind:e.literal(`branch`),key:p,approvedStepKey:p,rejectedStepKey:p}),k=e.union([T,E,D,O]),A=e.object({schemaVersion:e.literal(1),compatibilityKey:p,name:p,steps:e.array(k).min(1).max(32)}).check((e,t)=>{let n=/* @__PURE__ */ new Set,r=new Map(e.steps.map(e=>[e.key,e])),i=/* @__PURE__ */ new Map;for(let[r,i]of e.steps.entries())n.has(i.key)&&t.addIssue({message:`Duplicate workflow step key: ${i.key}`,path:[`steps`,r,`key`]}),n.add(i.key),i.kind===`decision`&&new Set(i.decisions).size!==i.decisions.length&&t.addIssue({message:`Duplicate decision value in step: ${i.key}`,path:[`steps`,r,`decisions`]});for(let[n,a]of e.steps.entries())if(a.kind===`branch`){e.steps[n-1]?.kind!==`decision`&&t.addIssue({message:`Branch must immediately follow a decision: ${a.key}`,path:[`steps`,n]});for(let o of[a.approvedStepKey,a.rejectedStepKey]){let a=r.get(o),s=e.steps.findIndex(e=>e.key===o);a?a.kind!==`mutation`&&a.kind!==`action`&&a.kind!==`notify`?t.addIssue({message:`Branch target must be a callback step: ${o}`,path:[`steps`,n]}):s<=n&&t.addIssue({message:`Branch target must be declared after its branch: ${o}`,path:[`steps`,n]}):t.addIssue({message:`Unknown branch target: ${o}`,path:[`steps`,n]}),i.set(o,(i.get(o)??0)+1)}}for(let[e,n]of i)n!==1&&t.addIssue({message:`Branch callback must belong to exactly one branch: ${e}`,path:[`steps`]})}),j=e.object({scopeRef:f,resourceType:p,resourceRef:f,requester:b,metadata:h.optional(),workflow:A,state:s,currentStepKey:p.optional(),executionFailedStepKey:p.optional(),expiresAt:o.optional(),workflowId:f.optional(),createdAt:o,updatedAt:o,terminalAt:o.optional()}),M=e.object({runId:e.id(`approvalRuns`),stepKey:p,actor:b,decision:c,reason:m.optional(),decidedAt:o}),N=e.object({action:e.string(),actorId:e.any().optional(),metadata:e.object({correlationKey:e.string(),transition:e.string()}).strip()}).strip(),P=e.string().optional();export{S as approvalActionCallback,b as approvalActor,N as approvalAuditEventProjection,O as approvalBranchStep,C as approvalCallback,y as approvalCallbackArgs,v as approvalCallbackInput,u as approvalCallbackKind,T as approvalCallbackStep,c as approvalDecision,M as approvalDecisionDocument,D as approvalDecisionStep,h as approvalMetadata,x as approvalMutationCallback,p as approvalName,E as approvalNotifyStep,P as approvalOptionalString,w as approvalQuorum,d as approvalQuorumKind,m as approvalReason,f as approvalReference,j as approvalRunDocument,s as approvalRunState,l as approvalStepKind,A as approvalWorkflowDescriptor,k as approvalWorkflowStep};
|
|
2
2
|
//# sourceMappingURL=validators.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.mjs","names":[],"sources":["../../../src/components/approvals/validators.ts"],"sourcesContent":["import { zid, zodToConvex } from 'convex-helpers/server/zod4'\nimport { z } from 'zod'\n\nimport {\n\tAPPROVAL_CALLBACK_KINDS,\n\tAPPROVAL_DECISIONS,\n\tAPPROVAL_DESCRIPTOR_SCHEMA_VERSION,\n\tAPPROVAL_QUORUM_KINDS,\n\tAPPROVAL_RUN_STATES,\n\tAPPROVAL_STEP_KINDS,\n\tMAX_APPROVAL_CAPABILITIES,\n\tMAX_APPROVAL_DECISIONS_PER_STEP,\n\tMAX_APPROVAL_METADATA_ENTRIES,\n\tMAX_APPROVAL_METADATA_KEY_LENGTH,\n\tMAX_APPROVAL_METADATA_VALUE_LENGTH,\n\tMAX_APPROVAL_NAME_LENGTH,\n\tMAX_APPROVAL_REASON_LENGTH,\n\tMAX_APPROVAL_REFERENCE_LENGTH,\n\tMAX_APPROVAL_WORKFLOW_STEPS,\n} from './constants'\n\nexport const approvalRunState = z.enum(APPROVAL_RUN_STATES)\nexport const approvalDecision = z.enum(APPROVAL_DECISIONS)\nexport const approvalStepKind = z.enum(APPROVAL_STEP_KINDS)\nexport const approvalCallbackKind = z.enum(APPROVAL_CALLBACK_KINDS)\nexport const approvalQuorumKind = z.enum(APPROVAL_QUORUM_KINDS)\n\nexport const approvalReference = z\n\t.string()\n\t.trim()\n\t.min(1)\n\t.max(MAX_APPROVAL_REFERENCE_LENGTH)\n\nexport const approvalName = z\n\t.string()\n\t.trim()\n\t.min(1)\n\t.max(MAX_APPROVAL_NAME_LENGTH)\n\t.regex(/^[A-Za-z][A-Za-z0-9._-]*$/)\n\nexport const approvalReason = z\n\t.string()\n\t.trim()\n\t.min(1)\n\t.max(MAX_APPROVAL_REASON_LENGTH)\n\nexport const approvalMetadata = z\n\t.record(\n\t\tz\n\t\t\t.string()\n\t\t\t.min(1)\n\t\t\t.max(MAX_APPROVAL_METADATA_KEY_LENGTH)\n\t\t\t.regex(/^(?![$_])[\\x20-\\x7E]+$/),\n\t\tz.string().max(MAX_APPROVAL_METADATA_VALUE_LENGTH),\n\t)\n\t.refine(\n\t\t(value) => Object.keys(value).length <= MAX_APPROVAL_METADATA_ENTRIES,\n\t\t`Metadata may contain at most ${MAX_APPROVAL_METADATA_ENTRIES} entries`,\n\t)\n\nconst approvalCallbackEvidence = z\n\t.object({\n\t\tstepKey: approvalName,\n\t\tactorRef: approvalReference,\n\t\tdecision: approvalDecision,\n\t\treason: approvalReason.optional(),\n\t\tdecidedAt: z.number(),\n\t})\n\t.strict()\n\nconst approvalCallbackTerminalEvidence = approvalCallbackEvidence.omit({\n\tstepKey: true,\n})\n\nexport const approvalCallbackInput = z\n\t.object({\n\t\trunId: approvalReference,\n\t\tscopeRef: approvalReference,\n\t\tresourceType: approvalName,\n\t\tresourceRef: approvalReference,\n\t\tmetadata: approvalMetadata.optional(),\n\t\tdecision: z\n\t\t\t.object({\n\t\t\t\tstepKey: approvalName,\n\t\t\t\toutcome: z.union([approvalDecision, z.literal('expired')]),\n\t\t\t\tevidence: z.array(approvalCallbackEvidence),\n\t\t\t\tterminalEvidence: approvalCallbackTerminalEvidence.optional(),\n\t\t\t})\n\t\t\t.strict()\n\t\t\t.optional(),\n\t})\n\t.strict()\n\n/** Convex argument validator for approval mutation, action, and notify callbacks. */\nexport const approvalCallbackArgs = zodToConvex(approvalCallbackInput)\n\nexport const approvalActor = z\n\t.object({\n\t\tactorRef: approvalReference,\n\t\tcapabilities: z.array(approvalName).max(MAX_APPROVAL_CAPABILITIES),\n\t\tmetadata: approvalMetadata.optional(),\n\t})\n\t.strict()\n\nexport const approvalMutationCallback = z\n\t.object({\n\t\tkind: z.literal('mutation'),\n\t\thandle: approvalReference,\n\t\tretry: z.boolean(),\n\t})\n\t.strict()\n\nexport const approvalActionCallback = z\n\t.object({\n\t\tkind: z.literal('action'),\n\t\thandle: approvalReference,\n\t\tretry: z.boolean(),\n\t})\n\t.strict()\n\nexport const approvalCallback = z.discriminatedUnion('kind', [\n\tapprovalMutationCallback,\n\tapprovalActionCallback,\n])\n\nexport const approvalQuorum = z\n\t.object({\n\t\tkind: approvalQuorumKind,\n\t\tapprovals: z.number().int().positive().max(MAX_APPROVAL_DECISIONS_PER_STEP),\n\t})\n\t.strict()\n\nexport const approvalCallbackStep = z.discriminatedUnion('kind', [\n\tz\n\t\t.object({\n\t\t\tkind: z.literal('mutation'),\n\t\t\tkey: approvalName,\n\t\t\tcallback: approvalMutationCallback,\n\t\t})\n\t\t.strict(),\n\tz\n\t\t.object({\n\t\t\tkind: z.literal('action'),\n\t\t\tkey: approvalName,\n\t\t\tcallback: approvalActionCallback,\n\t\t})\n\t\t.strict(),\n])\n\nexport const approvalNotifyStep = z\n\t.object({\n\t\tkind: z.literal('notify'),\n\t\tkey: approvalName,\n\t\tcallback: approvalActionCallback,\n\t})\n\t.strict()\n\nexport const approvalDecisionStep = z\n\t.object({\n\t\tkind: z.literal('decision'),\n\t\tkey: approvalName,\n\t\tdecisions: z\n\t\t\t.array(approvalDecision)\n\t\t\t.min(1)\n\t\t\t.max(MAX_APPROVAL_DECISIONS_PER_STEP),\n\t\tquorum: approvalQuorum,\n\t\tmakerChecker: z.boolean(),\n\t\texpiresAfterMs: z.number().int().positive().optional(),\n\t})\n\t.strict()\n\nexport const approvalBranchStep = z\n\t.object({\n\t\tkind: z.literal('branch'),\n\t\tkey: approvalName,\n\t\tapprovedStepKey: approvalName,\n\t\trejectedStepKey: approvalName,\n\t})\n\t.strict()\n\nexport const approvalWorkflowStep = z.discriminatedUnion('kind', [\n\tapprovalCallbackStep,\n\tapprovalNotifyStep,\n\tapprovalDecisionStep,\n\tapprovalBranchStep,\n])\n\nexport const approvalWorkflowDescriptor = z\n\t.object({\n\t\tschemaVersion: z.literal(APPROVAL_DESCRIPTOR_SCHEMA_VERSION),\n\t\tcompatibilityKey: approvalName,\n\t\tname: approvalName,\n\t\tsteps: z\n\t\t\t.array(approvalWorkflowStep)\n\t\t\t.min(1)\n\t\t\t.max(MAX_APPROVAL_WORKFLOW_STEPS),\n\t})\n\t.strict()\n\t.superRefine((descriptor, context) => {\n\t\tconst keys = new Set<string>()\n\t\tconst stepsByKey = new Map(\n\t\t\tdescriptor.steps.map((step) => [step.key, step] as const),\n\t\t)\n\t\tconst branchTargetOwners = new Map<string, number>()\n\t\tfor (const [index, step] of descriptor.steps.entries()) {\n\t\t\tif (keys.has(step.key))\n\t\t\t\tcontext.addIssue({\n\t\t\t\t\tcode: 'custom',\n\t\t\t\t\tmessage: `Duplicate workflow step key: ${step.key}`,\n\t\t\t\t\tpath: ['steps', index, 'key'],\n\t\t\t\t})\n\t\t\tkeys.add(step.key)\n\t\t\tif (\n\t\t\t\tstep.kind === 'decision' &&\n\t\t\t\tnew Set(step.decisions).size !== step.decisions.length\n\t\t\t)\n\t\t\t\tcontext.addIssue({\n\t\t\t\t\tcode: 'custom',\n\t\t\t\t\tmessage: `Duplicate decision value in step: ${step.key}`,\n\t\t\t\t\tpath: ['steps', index, 'decisions'],\n\t\t\t\t})\n\t\t}\n\t\tfor (const [index, step] of descriptor.steps.entries()) {\n\t\t\tif (step.kind !== 'branch') continue\n\t\t\tif (descriptor.steps[index - 1]?.kind !== 'decision')\n\t\t\t\tcontext.addIssue({\n\t\t\t\t\tcode: 'custom',\n\t\t\t\t\tmessage: `Branch must immediately follow a decision: ${step.key}`,\n\t\t\t\t\tpath: ['steps', index],\n\t\t\t\t})\n\t\t\tfor (const target of [step.approvedStepKey, step.rejectedStepKey]) {\n\t\t\t\tconst targetStep = stepsByKey.get(target)\n\t\t\t\tconst targetIndex = descriptor.steps.findIndex(\n\t\t\t\t\t(candidate) => candidate.key === target,\n\t\t\t\t)\n\t\t\t\tif (!targetStep)\n\t\t\t\t\tcontext.addIssue({\n\t\t\t\t\t\tcode: 'custom',\n\t\t\t\t\t\tmessage: `Unknown branch target: ${target}`,\n\t\t\t\t\t\tpath: ['steps', index],\n\t\t\t\t\t})\n\t\t\t\telse if (\n\t\t\t\t\ttargetStep.kind !== 'mutation' &&\n\t\t\t\t\ttargetStep.kind !== 'action' &&\n\t\t\t\t\ttargetStep.kind !== 'notify'\n\t\t\t\t)\n\t\t\t\t\tcontext.addIssue({\n\t\t\t\t\t\tcode: 'custom',\n\t\t\t\t\t\tmessage: `Branch target must be a callback step: ${target}`,\n\t\t\t\t\t\tpath: ['steps', index],\n\t\t\t\t\t})\n\t\t\t\telse if (targetIndex <= index)\n\t\t\t\t\tcontext.addIssue({\n\t\t\t\t\t\tcode: 'custom',\n\t\t\t\t\t\tmessage: `Branch target must be declared after its branch: ${target}`,\n\t\t\t\t\t\tpath: ['steps', index],\n\t\t\t\t\t})\n\t\t\t\tbranchTargetOwners.set(\n\t\t\t\t\ttarget,\n\t\t\t\t\t(branchTargetOwners.get(target) ?? 0) + 1,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\tfor (const [target, owners] of branchTargetOwners) {\n\t\t\tif (owners !== 1)\n\t\t\t\tcontext.addIssue({\n\t\t\t\t\tcode: 'custom',\n\t\t\t\t\tmessage: `Branch callback must belong to exactly one branch: ${target}`,\n\t\t\t\t\tpath: ['steps'],\n\t\t\t\t})\n\t\t}\n\t})\n\nexport const approvalRunDocument = z\n\t.object({\n\t\tscopeRef: approvalReference,\n\t\tresourceType: approvalName,\n\t\tresourceRef: approvalReference,\n\t\trequester: approvalActor,\n\t\tmetadata: approvalMetadata.optional(),\n\t\tworkflow: approvalWorkflowDescriptor,\n\t\tstate: approvalRunState,\n\t\tcurrentStepKey: approvalName.optional(),\n\t\texecutionFailedStepKey: approvalName.optional(),\n\t\texpiresAt: z.number().optional(),\n\t\tworkflowId: approvalReference.optional(),\n\t\tcreatedAt: z.number(),\n\t\tupdatedAt: z.number(),\n\t\tterminalAt: z.number().optional(),\n\t})\n\t.strict()\n\nexport const approvalDecisionDocument = z\n\t.object({\n\t\trunId: zid('approvalRuns'),\n\t\tstepKey: approvalName,\n\t\tactor: approvalActor,\n\t\tdecision: approvalDecision,\n\t\treason: approvalReason.optional(),\n\t\tdecidedAt: z.number(),\n\t})\n\t.strict()\n\nexport type ApprovalWorkflowDescriptor = z.infer<\n\ttypeof approvalWorkflowDescriptor\n>\nexport type ApprovalActor = z.infer<typeof approvalActor>\nexport type ApprovalMetadata = z.infer<typeof approvalMetadata>\nexport type ApprovalCallbackInput = Readonly<\n\tz.infer<typeof approvalCallbackInput>\n>\n"],"mappings":"yPAqBA,MAAa,EAAmB,EAAE,KAAK,CAAmB,EAC7C,EAAmB,EAAE,KAAK,CAAkB,EAC5C,EAAmB,EAAE,KAAK,CAAmB,EAC7C,EAAuB,EAAE,KAAK,CAAuB,EACrD,EAAqB,EAAE,KAAK,CAAqB,EAEjD,EAAoB,EAC/B,OAAO,CAAC,CACR,KAAK,CAAC,CACN,IAAI,CAAC,CAAC,CACN,IAAA,GAAiC,EAEtB,EAAe,EAC1B,OAAO,CAAC,CACR,KAAK,CAAC,CACN,IAAI,CAAC,CAAC,CACN,IAAA,EAA4B,CAAC,CAC7B,MAAM,2BAA2B,EAEtB,EAAiB,EAC5B,OAAO,CAAC,CACR,KAAK,CAAC,CACN,IAAI,CAAC,CAAC,CACN,IAAA,GAA8B,EAEnB,EAAmB,EAC9B,OACA,EACE,OAAO,CAAC,CACR,IAAI,CAAC,CAAC,CACN,IAAA,EAAoC,CAAC,CACrC,MAAM,wBAAwB,EAChC,EAAE,OAAO,CAAC,CAAC,IAAA,GAAsC,CAClD,CAAC,CACA,OACC,GAAU,OAAO,KAAK,CAAK,CAAC,CAAC,QAAA,GAC9B,yCACD,EAEK,EAA2B,EAC/B,OAAO,CACP,QAAS,EACT,SAAU,EACV,SAAU,EACV,OAAQ,EAAe,SAAS,EAChC,UAAW,EAAE,OAAO,CACrB,CAAC,CAAC,CACD,OAAO,EAEH,EAAmC,EAAyB,KAAK,CACtE,QAAS,EACV,CAAC,EAEY,EAAwB,EACnC,OAAO,CACP,MAAO,EACP,SAAU,EACV,aAAc,EACd,YAAa,EACb,SAAU,EAAiB,SAAS,EACpC,SAAU,EACR,OAAO,CACP,QAAS,EACT,QAAS,EAAE,MAAM,CAAC,EAAkB,EAAE,QAAQ,SAAS,CAAC,CAAC,EACzD,SAAU,EAAE,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T,MAAO,EACP,SAAU,EACV,OAAQ,EAAe,SAAS,EAChC,UAAW,EAAE,OAAO,CACrB,CAAC,CAAC,CACD,OAAO"}
|
|
1
|
+
{"version":3,"file":"validators.mjs","names":["approvalNumber","k","approvalRunState","APPROVAL_RUN_STATES","approvalDecision","APPROVAL_DECISIONS","approvalStepKind","APPROVAL_STEP_KINDS","approvalCallbackKind","APPROVAL_CALLBACK_KINDS","approvalQuorumKind","APPROVAL_QUORUM_KINDS","approvalReference","approvalName","approvalReason","approvalMetadata","value","approvalCallbackEvidence","approvalCallbackTerminalEvidence","approvalCallbackInput","approvalCallbackArgs","approvalActor","approvalMutationCallback","approvalActionCallback","approvalCallback","approvalQuorum","approvalCallbackStep","approvalNotifyStep","approvalDecisionStep","approvalBranchStep","approvalWorkflowStep","approvalWorkflowDescriptor","keys","stepsByKey","descriptor","step","branchTargetOwners","index","context","target","targetStep","targetIndex","candidate","owners","approvalRunDocument","approvalDecisionDocument","approvalAuditEventProjection","approvalOptionalString"],"sources":["../../../src/components/approvals/validators.ts"],"sourcesContent":["import { k } from '../../k'\n\nimport {\n\tAPPROVAL_CALLBACK_KINDS,\n\tAPPROVAL_DECISIONS,\n\tAPPROVAL_DESCRIPTOR_SCHEMA_VERSION,\n\tAPPROVAL_QUORUM_KINDS,\n\tAPPROVAL_RUN_STATES,\n\tAPPROVAL_STEP_KINDS,\n\tMAX_APPROVAL_CAPABILITIES,\n\tMAX_APPROVAL_DECISIONS_PER_STEP,\n\tMAX_APPROVAL_METADATA_ENTRIES,\n\tMAX_APPROVAL_METADATA_KEY_LENGTH,\n\tMAX_APPROVAL_METADATA_VALUE_LENGTH,\n\tMAX_APPROVAL_NAME_LENGTH,\n\tMAX_APPROVAL_REASON_LENGTH,\n\tMAX_APPROVAL_REFERENCE_LENGTH,\n\tMAX_APPROVAL_WORKFLOW_STEPS,\n} from './constants'\n\n/** v1's `z.number()` rejected `NaN` and infinities on parse; natively this stays `v.number()`. */\nconst approvalNumber = k.number().refine(Number.isFinite, 'Expected a finite number')\n\nexport const approvalRunState = k.enum(APPROVAL_RUN_STATES)\nexport const approvalDecision = k.enum(APPROVAL_DECISIONS)\nexport const approvalStepKind = k.enum(APPROVAL_STEP_KINDS)\nexport const approvalCallbackKind = k.enum(APPROVAL_CALLBACK_KINDS)\nexport const approvalQuorumKind = k.enum(APPROVAL_QUORUM_KINDS)\n\nexport const approvalReference = k.string().trim().min(1).max(MAX_APPROVAL_REFERENCE_LENGTH)\n\nexport const approvalName = k\n\t.string()\n\t.trim()\n\t.min(1)\n\t.max(MAX_APPROVAL_NAME_LENGTH)\n\t.regex(/^[A-Za-z][A-Za-z0-9._-]*$/)\n\nexport const approvalReason = k.string().trim().min(1).max(MAX_APPROVAL_REASON_LENGTH)\n\nexport const approvalMetadata = k\n\t.record(\n\t\tk\n\t\t\t.string()\n\t\t\t.min(1)\n\t\t\t.max(MAX_APPROVAL_METADATA_KEY_LENGTH)\n\t\t\t.regex(/^(?![$_])[\\x20-\\x7E]+$/),\n\t\tk.string().max(MAX_APPROVAL_METADATA_VALUE_LENGTH),\n\t)\n\t.refine(\n\t\t(value) => Object.keys(value).length <= MAX_APPROVAL_METADATA_ENTRIES,\n\t\t`Metadata may contain at most ${MAX_APPROVAL_METADATA_ENTRIES} entries`,\n\t)\n\nconst approvalCallbackEvidence = k.object({\n\tstepKey: approvalName,\n\tactorRef: approvalReference,\n\tdecision: approvalDecision,\n\treason: approvalReason.optional(),\n\tdecidedAt: approvalNumber,\n})\n\nconst approvalCallbackTerminalEvidence = approvalCallbackEvidence.omit('stepKey')\n\nexport const approvalCallbackInput = k.object({\n\trunId: approvalReference,\n\tscopeRef: approvalReference,\n\tresourceType: approvalName,\n\tresourceRef: approvalReference,\n\tmetadata: approvalMetadata.optional(),\n\tdecision: k\n\t\t.object({\n\t\t\tstepKey: approvalName,\n\t\t\toutcome: k.union([approvalDecision, k.literal('expired')]),\n\t\t\tevidence: k.array(approvalCallbackEvidence),\n\t\t\tterminalEvidence: approvalCallbackTerminalEvidence.optional(),\n\t\t})\n\t\t.optional(),\n})\n\n/** Convex argument validator for approval mutation, action, and notify callbacks. */\nexport const approvalCallbackArgs = approvalCallbackInput.validator\n\nexport const approvalActor = k.object({\n\tactorRef: approvalReference,\n\tcapabilities: k.array(approvalName).max(MAX_APPROVAL_CAPABILITIES),\n\tmetadata: approvalMetadata.optional(),\n})\n\nexport const approvalMutationCallback = k.object({\n\tkind: k.literal('mutation'),\n\thandle: approvalReference,\n\tretry: k.boolean(),\n})\n\nexport const approvalActionCallback = k.object({\n\tkind: k.literal('action'),\n\thandle: approvalReference,\n\tretry: k.boolean(),\n})\n\nexport const approvalCallback = k.discriminatedUnion('kind', [\n\tapprovalMutationCallback,\n\tapprovalActionCallback,\n])\n\nexport const approvalQuorum = k.object({\n\tkind: approvalQuorumKind,\n\tapprovals: k.int().min(1).max(MAX_APPROVAL_DECISIONS_PER_STEP),\n})\n\nexport const approvalCallbackStep = k.discriminatedUnion('kind', [\n\tk.object({\n\t\tkind: k.literal('mutation'),\n\t\tkey: approvalName,\n\t\tcallback: approvalMutationCallback,\n\t}),\n\tk.object({\n\t\tkind: k.literal('action'),\n\t\tkey: approvalName,\n\t\tcallback: approvalActionCallback,\n\t}),\n])\n\nexport const approvalNotifyStep = k.object({\n\tkind: k.literal('notify'),\n\tkey: approvalName,\n\tcallback: approvalActionCallback,\n})\n\nexport const approvalDecisionStep = k.object({\n\tkind: k.literal('decision'),\n\tkey: approvalName,\n\tdecisions: k.array(approvalDecision).min(1).max(MAX_APPROVAL_DECISIONS_PER_STEP),\n\tquorum: approvalQuorum,\n\tmakerChecker: k.boolean(),\n\t// v1's `.int()` accepted safe integers only.\n\texpiresAfterMs: k.int().min(1).refine(Number.isSafeInteger, 'Expected a safe integer').optional(),\n})\n\nexport const approvalBranchStep = k.object({\n\tkind: k.literal('branch'),\n\tkey: approvalName,\n\tapprovedStepKey: approvalName,\n\trejectedStepKey: approvalName,\n})\n\n/**\n * A plain union, not a discriminated one: its first member is itself a union over `kind`, which a\n * discriminated union cannot dispatch to. Natively both are the same `v.union`.\n */\nexport const approvalWorkflowStep = k.union([\n\tapprovalCallbackStep,\n\tapprovalNotifyStep,\n\tapprovalDecisionStep,\n\tapprovalBranchStep,\n])\n\nexport const approvalWorkflowDescriptor = k\n\t.object({\n\t\tschemaVersion: k.literal(APPROVAL_DESCRIPTOR_SCHEMA_VERSION),\n\t\tcompatibilityKey: approvalName,\n\t\tname: approvalName,\n\t\tsteps: k.array(approvalWorkflowStep).min(1).max(MAX_APPROVAL_WORKFLOW_STEPS),\n\t})\n\t.check((descriptor, context) => {\n\t\tconst keys = new Set<string>()\n\t\tconst stepsByKey = new Map(descriptor.steps.map((step) => [step.key, step] as const))\n\t\tconst branchTargetOwners = new Map<string, number>()\n\t\tfor (const [index, step] of descriptor.steps.entries()) {\n\t\t\tif (keys.has(step.key))\n\t\t\t\tcontext.addIssue({\n\t\t\t\t\tmessage: `Duplicate workflow step key: ${step.key}`,\n\t\t\t\t\tpath: ['steps', index, 'key'],\n\t\t\t\t})\n\t\t\tkeys.add(step.key)\n\t\t\tif (step.kind === 'decision' && new Set(step.decisions).size !== step.decisions.length)\n\t\t\t\tcontext.addIssue({\n\t\t\t\t\tmessage: `Duplicate decision value in step: ${step.key}`,\n\t\t\t\t\tpath: ['steps', index, 'decisions'],\n\t\t\t\t})\n\t\t}\n\t\tfor (const [index, step] of descriptor.steps.entries()) {\n\t\t\tif (step.kind !== 'branch') continue\n\t\t\tif (descriptor.steps[index - 1]?.kind !== 'decision')\n\t\t\t\tcontext.addIssue({\n\t\t\t\t\tmessage: `Branch must immediately follow a decision: ${step.key}`,\n\t\t\t\t\tpath: ['steps', index],\n\t\t\t\t})\n\t\t\tfor (const target of [step.approvedStepKey, step.rejectedStepKey]) {\n\t\t\t\tconst targetStep = stepsByKey.get(target)\n\t\t\t\tconst targetIndex = descriptor.steps.findIndex((candidate) => candidate.key === target)\n\t\t\t\tif (!targetStep)\n\t\t\t\t\tcontext.addIssue({\n\t\t\t\t\t\tmessage: `Unknown branch target: ${target}`,\n\t\t\t\t\t\tpath: ['steps', index],\n\t\t\t\t\t})\n\t\t\t\telse if (\n\t\t\t\t\ttargetStep.kind !== 'mutation' &&\n\t\t\t\t\ttargetStep.kind !== 'action' &&\n\t\t\t\t\ttargetStep.kind !== 'notify'\n\t\t\t\t)\n\t\t\t\t\tcontext.addIssue({\n\t\t\t\t\t\tmessage: `Branch target must be a callback step: ${target}`,\n\t\t\t\t\t\tpath: ['steps', index],\n\t\t\t\t\t})\n\t\t\t\telse if (targetIndex <= index)\n\t\t\t\t\tcontext.addIssue({\n\t\t\t\t\t\tmessage: `Branch target must be declared after its branch: ${target}`,\n\t\t\t\t\t\tpath: ['steps', index],\n\t\t\t\t\t})\n\t\t\t\tbranchTargetOwners.set(target, (branchTargetOwners.get(target) ?? 0) + 1)\n\t\t\t}\n\t\t}\n\t\tfor (const [target, owners] of branchTargetOwners) {\n\t\t\tif (owners !== 1)\n\t\t\t\tcontext.addIssue({\n\t\t\t\t\tmessage: `Branch callback must belong to exactly one branch: ${target}`,\n\t\t\t\t\tpath: ['steps'],\n\t\t\t\t})\n\t\t}\n\t})\n\nexport const approvalRunDocument = k.object({\n\tscopeRef: approvalReference,\n\tresourceType: approvalName,\n\tresourceRef: approvalReference,\n\trequester: approvalActor,\n\tmetadata: approvalMetadata.optional(),\n\tworkflow: approvalWorkflowDescriptor,\n\tstate: approvalRunState,\n\tcurrentStepKey: approvalName.optional(),\n\texecutionFailedStepKey: approvalName.optional(),\n\texpiresAt: approvalNumber.optional(),\n\tworkflowId: approvalReference.optional(),\n\tcreatedAt: approvalNumber,\n\tupdatedAt: approvalNumber,\n\tterminalAt: approvalNumber.optional(),\n})\n\nexport const approvalDecisionDocument = k.object({\n\trunId: k.id('approvalRuns'),\n\tstepKey: approvalName,\n\tactor: approvalActor,\n\tdecision: approvalDecision,\n\treason: approvalReason.optional(),\n\tdecidedAt: approvalNumber,\n})\n\n/**\n * The fields `approvals.audit.history` reads from an audit-log event. Unknown keys are stripped, as\n * v1's non-strict Zod objects did, and a non-string `actorId` is dropped by the caller.\n */\nexport const approvalAuditEventProjection = k\n\t.object({\n\t\taction: k.string(),\n\t\tactorId: k.any().optional(),\n\t\tmetadata: k.object({ correlationKey: k.string(), transition: k.string() }).strip(),\n\t})\n\t.strip()\n\nexport const approvalOptionalString = k.string().optional()\n\nexport type ApprovalWorkflowDescriptor = k.infer<typeof approvalWorkflowDescriptor>\nexport type ApprovalActor = k.infer<typeof approvalActor>\nexport type ApprovalMetadata = k.infer<typeof approvalMetadata>\nexport type ApprovalCallbackInput = Readonly<k.infer<typeof approvalCallbackInput>>\n"],"mappings":"A,qMAqBA,MAAMA,EAAiBC,EAAE,OAAO,CAAC,CAAC,OAAO,OAAO,SAAU,0BAA0B,EAEvEC,EAAmBD,EAAE,KAAKE,CAAmB,EAC7CC,EAAmBH,EAAE,KAAKI,CAAkB,EAC5CC,EAAmBL,EAAE,KAAKM,CAAmB,EAC7CC,EAAuBP,EAAE,KAAKQ,CAAuB,EACrDC,EAAqBT,EAAE,KAAKU,CAAqB,EAEjDC,EAAoBX,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,GAAiC,EAE9EY,EAAeZ,EAC1B,OAAO,CAAC,CACR,KAAK,CAAC,CACN,IAAI,CAAC,CAAC,CACN,IAAA,EAA4B,CAAC,CAC7B,MAAM,2BAA2B,EAEtBa,EAAiBb,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,GAA8B,EAExEc,EAAmBd,EAC9B,OACAA,EACE,OAAO,CAAC,CACR,IAAI,CAAC,CAAC,CACN,IAAA,EAAoC,CAAC,CACrC,MAAM,wBAAwB,EAChCA,EAAE,OAAO,CAAC,CAAC,IAAA,GAAsC,CAClD,CAAC,CACA,OACC,GAAU,OAAO,KAAKe,CAAK,CAAC,CAAC,QAAA,GAC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AS,EACpC,SAAUgB,EACV,MAAO7B,EACP,eAAgBW,EAAa,SAAS,EACtC,uBAAwBA,EAAa,SAAS,EAC9C,UAAWb,EAAe,SAAS,EACnC,WAAYY,EAAkB,SAAS,EACvC,UAAWZ,EACX,UAAWA,EACX,WAAYA,EAAe,SAAS,CACrC,CAAC,EAEY6C,EAA2B5C,EAAE,OAAO,CAChD,MAAOA,EAAE,GAAG,cAAc,EAC1B,QAASY,EACT,MAAOQ,EACP,SAAUjB,EACV,OAAQU,EAAe,SAAS,EAChC,UAAWd,CACZ,CAAC,EAMY8C,EAA+B7C,EAC1C,OAAO,CACP,OAAQA,EAAE,OAAO,EACjB,QAASA,EAAE,IAAI,CAAC,CAAC,SAAS,EAC1B,SAAUA,EAAE,OAAO,CAAE,eAAgBA,EAAE,OAAO,EAAG,WAAYA,EAAE,OAAO,CAAE,CAAC,CAAC,CAAC,MAAM,CAClF,CAAC,CAAC,CACD,MAAM,EAEK8C,EAAyB9C,EAAE,OAAO,CAAC,CAAC,SAAS,E"}
|
|
@@ -2,10 +2,9 @@ import { WorkflowManager } from "@convex-dev/workflow";
|
|
|
2
2
|
declare namespace workflow_d_exports {
|
|
3
3
|
export { approvalWorkflow, run };
|
|
4
4
|
}
|
|
5
|
-
declare const approvalWorkflow: WorkflowManager;
|
|
6
|
-
declare const run: import("convex/server").RegisteredMutation<"internal", import("@convex-dev/workflow").WorkflowArgs<{
|
|
5
|
+
export declare const approvalWorkflow: WorkflowManager;
|
|
6
|
+
export declare const run: import("convex/server").RegisteredMutation<"internal", import("@convex-dev/workflow").WorkflowArgs<{
|
|
7
7
|
runId: import("convex/values").VId<import("convex/values").GenericId<"approvalRuns">, "required">;
|
|
8
|
-
}>, import("@convex-dev/workflow").
|
|
9
|
-
|
|
10
|
-
export { approvalWorkflow, run, workflow_d_exports };
|
|
8
|
+
}>, import("@convex-dev/workflow").WorkflowMutationResult<null>>;
|
|
9
|
+
export { workflow_d_exports };
|
|
11
10
|
//# sourceMappingURL=workflow.d.mts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{components as e,internal as t}from"./_generated/api.mjs";import{APPROVAL_DECISIONS as n,APPROVAL_RUN_STATES as r}from"./constants.mjs";import{approvalDecisionEventName as i,callbackReference as a,resolveWorkflowStepIndex as o}from"./workflow_steps.mjs";import{v as s}from"convex/values";import{WorkflowManager as c}from"@convex-dev/workflow";const l=new c(e.workflow),u=l.define({args:{runId:s.id(`approvalRuns`)},returns:s.null(),handler:async(e,a)=>{let c;try{let l=await e.runQuery(t.requests.getForWorkflow,{runId:a.runId},{name:`loadLinkedApproval`});if(!l)throw Error(`Approval request not found`);if(l.workflowId!==e.workflowId)throw Error(`Approval workflow linkage is incomplete`);let u=d(l),p=l.workflow.steps.map(e=>e.key),m=new Set(l.workflow.steps.flatMap(e=>e.kind===`branch`?[e.approvedStepKey,e.rejectedStepKey]:[])),h=null,g=null,_,v=0;for(;v<l.workflow.steps.length;){let a=l.workflow.steps[v];if(a.kind===`mutation`||a.kind===`action`||a.kind===`notify`){if(m.has(a.key)){v+=1;continue}c=a.key,await f(e,a,u),c=void 0,v+=1;continue}if(a.kind===`decision`){await e.runMutation(t.decisions.enter,{runId:l._id,stepKey:a.key,workflowId:e.workflowId
|
|
1
|
+
import{components as e,internal as t}from"./_generated/api.mjs";import{APPROVAL_DECISIONS as n,APPROVAL_RUN_STATES as r}from"./constants.mjs";import{approvalDecisionEventName as i,callbackReference as a,resolveWorkflowStepIndex as o}from"./workflow_steps.mjs";import{v as s}from"convex/values";import{WorkflowManager as c}from"@convex-dev/workflow";const l=new c(e.workflow),u=l.define({args:{runId:s.id(`approvalRuns`)},returns:s.null(),handler:async(e,a)=>{let c;try{let l=await e.runQuery(t.requests.getForWorkflow,{runId:a.runId},{name:`loadLinkedApproval`});if(!l)throw Error(`Approval request not found`);if(l.workflowId!==e.workflowId)throw Error(`Approval workflow linkage is incomplete`);let u=d(l),p=l.workflow.steps.map(e=>e.key),m=new Set(l.workflow.steps.flatMap(e=>e.kind===`branch`?[e.approvedStepKey,e.rejectedStepKey]:[])),h=null,g=null,_,v=0;for(;v<l.workflow.steps.length;){let a=l.workflow.steps[v];if(a.kind===`mutation`||a.kind===`action`||a.kind===`notify`){if(m.has(a.key)){v+=1;continue}c=a.key,await f(e,a,u),c=void 0,v+=1;continue}if(a.kind===`decision`){await e.runMutation(t.decisions.enter,{runId:l._id,stepKey:a.key,workflowId:e.workflowId,expiresAfterMs:a.expiresAfterMs},{name:`enter:${a.key}`});let o=await e.awaitEvent({name:i(l._id,a.key),validator:s.object({outcome:s.union(s.literal(n[0]),s.literal(n[1]),s.literal(r[3])),terminalEvidence:s.optional(s.object({actorRef:s.string(),decision:s.union(s.literal(n[0]),s.literal(n[1])),reason:s.optional(s.string()),decidedAt:s.number()}))})});if(h=o.outcome,_=o.terminalEvidence,g=a.key,h!==`approved`&&l.workflow.steps[v+1]?.kind!==`branch`)break;v+=1;continue}if(!h)throw Error(`Branch requires a preceding decision step`);let d=h===`approved`?a.approvedStepKey:a.rejectedStepKey,y=o(p,d),b=l.workflow.steps[y];if(b.kind!==`mutation`&&b.kind!==`action`&&b.kind!==`notify`)throw Error(`Approval branch target must be a callback step`);let x=await e.runQuery(t.decisions.listForWorkflow,{runId:l._id,stepKey:g??a.key},{name:`evidence:${a.key}`});if(c=b.key,await f(e,b,{...u,decision:{stepKey:g??a.key,outcome:h,evidence:x,terminalEvidence:_}}),c=void 0,h===`rejected`||h===`expired`)break;v+=1}return await e.runMutation(t.requests.recordExecutionTerminal,{runId:l._id,outcome:`completed`},{name:`recordExecutionCompleted`}),null}catch(n){throw await e.runMutation(t.requests.recordExecutionTerminal,{runId:a.runId,outcome:`failed`,failedStepKey:c},{name:`recordExecutionFailed`}),n}}});function d(e){return{runId:e._id,scopeRef:e.scopeRef,resourceType:e.resourceType,resourceRef:e.resourceRef,metadata:e.metadata}}async function f(e,t,n){t.callback.kind===`mutation`?await e.runMutation(a(t.callback.handle),n,{name:t.key}):await e.runAction(a(t.callback.handle),n,{name:t.key,retry:t.callback.retry})}export{l as approvalWorkflow,u as run};
|
|
2
2
|
//# sourceMappingURL=workflow.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.mjs","names":[],"sources":["../../../src/components/approvals/workflow.ts"],"sourcesContent":["import { WorkflowManager, type WorkflowCtx } from '@convex-dev/workflow'\nimport { v } from 'convex/values'\n\nimport { components, internal } from './_generated/api'\nimport type { Doc } from './_generated/dataModel'\nimport { APPROVAL_DECISIONS, APPROVAL_RUN_STATES } from './constants'\nimport {\n\tapprovalDecisionEventName,\n\tcallbackReference,\n\tresolveWorkflowStepIndex,\n\ttype ApprovalCallbackInput,\n} from './workflow_steps'\n\nexport const approvalWorkflow = new WorkflowManager(components.workflow)\n\nexport const run = approvalWorkflow.define({\n\targs: { runId: v.id('approvalRuns') },\n\treturns: v.null(),\n\thandler: async (step, input) => {\n\t\tlet failedStepKey: string | undefined\n\t\ttry {\n\t\t\tconst run: Doc<'approvalRuns'> | null = await step.runQuery(\n\t\t\t\tinternal.requests.getForWorkflow,\n\t\t\t\t{ runId: input.runId },\n\t\t\t\t{ name: 'loadLinkedApproval' },\n\t\t\t)\n\t\t\tif (!run) throw new Error('Approval request not found')\n\t\t\tif (run.workflowId !== step.workflowId)\n\t\t\t\tthrow new Error('Approval workflow linkage is incomplete')\n\n\t\t\tconst callbackInput = buildCallbackInput(run)\n\t\t\tconst stepKeys = run.workflow.steps.map(\n\t\t\t\t(workflowStep) => workflowStep.key,\n\t\t\t)\n\t\t\tconst branchTargets = new Set(\n\t\t\t\trun.workflow.steps.flatMap((workflowStep) =>\n\t\t\t\t\tworkflowStep.kind === 'branch'\n\t\t\t\t\t\t? [workflowStep.approvedStepKey, workflowStep.rejectedStepKey]\n\t\t\t\t\t\t: [],\n\t\t\t\t),\n\t\t\t)\n\t\t\tlet lastDecision: 'approved' | 'rejected' | 'expired' | null = null\n\t\t\tlet lastDecisionStepKey: string | null = null\n\t\t\tlet terminalEvidence:\n\t\t\t\t| {\n\t\t\t\t\t\tactorRef: string\n\t\t\t\t\t\tdecision: 'approved' | 'rejected'\n\t\t\t\t\t\treason?: string\n\t\t\t\t\t\tdecidedAt: number\n\t\t\t\t }\n\t\t\t\t| undefined\n\t\t\tlet index = 0\n\t\t\twhile (index < run.workflow.steps.length) {\n\t\t\t\tconst workflowStep = run.workflow.steps[index]\n\t\t\t\tif (\n\t\t\t\t\tworkflowStep.kind === 'mutation' ||\n\t\t\t\t\tworkflowStep.kind === 'action' ||\n\t\t\t\t\tworkflowStep.kind === 'notify'\n\t\t\t\t) {\n\t\t\t\t\tif (branchTargets.has(workflowStep.key)) {\n\t\t\t\t\t\tindex += 1\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfailedStepKey = workflowStep.key\n\t\t\t\t\tawait executeCallback(step, workflowStep, callbackInput)\n\t\t\t\t\tfailedStepKey = undefined\n\t\t\t\t\tindex += 1\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (workflowStep.kind === 'decision') {\n\t\t\t\t\tawait step.runMutation(\n\t\t\t\t\t\tinternal.decisions.enter,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\trunId: run._id,\n\t\t\t\t\t\t\tstepKey: workflowStep.key,\n\t\t\t\t\t\t\tworkflowId: step.workflowId,\n\t\t\t\t\t\t\t...(workflowStep.expiresAfterMs === undefined\n\t\t\t\t\t\t\t\t? {}\n\t\t\t\t\t\t\t\t: { expiresAfterMs: workflowStep.expiresAfterMs }),\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ name: `enter:${workflowStep.key}` },\n\t\t\t\t\t)\n\t\t\t\t\tconst event = await step.awaitEvent({\n\t\t\t\t\t\tname: approvalDecisionEventName(run._id, workflowStep.key),\n\t\t\t\t\t\tvalidator: v.object({\n\t\t\t\t\t\t\toutcome: v.union(\n\t\t\t\t\t\t\t\tv.literal(APPROVAL_DECISIONS[0]),\n\t\t\t\t\t\t\t\tv.literal(APPROVAL_DECISIONS[1]),\n\t\t\t\t\t\t\t\tv.literal(APPROVAL_RUN_STATES[3]),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tterminalEvidence: v.optional(\n\t\t\t\t\t\t\t\tv.object({\n\t\t\t\t\t\t\t\t\tactorRef: v.string(),\n\t\t\t\t\t\t\t\t\tdecision: v.union(\n\t\t\t\t\t\t\t\t\t\tv.literal(APPROVAL_DECISIONS[0]),\n\t\t\t\t\t\t\t\t\t\tv.literal(APPROVAL_DECISIONS[1]),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\treason: v.optional(v.string()),\n\t\t\t\t\t\t\t\t\tdecidedAt: v.number(),\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\tlastDecision = event.outcome\n\t\t\t\t\tterminalEvidence = event.terminalEvidence\n\t\t\t\t\tlastDecisionStepKey = workflowStep.key\n\t\t\t\t\tif (\n\t\t\t\t\t\tlastDecision !== 'approved' &&\n\t\t\t\t\t\trun.workflow.steps[index + 1]?.kind !== 'branch'\n\t\t\t\t\t)\n\t\t\t\t\t\tbreak\n\t\t\t\t\tindex += 1\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (!lastDecision)\n\t\t\t\t\tthrow new Error('Branch requires a preceding decision step')\n\t\t\t\tconst targetKey =\n\t\t\t\t\tlastDecision === 'approved'\n\t\t\t\t\t\t? workflowStep.approvedStepKey\n\t\t\t\t\t\t: workflowStep.rejectedStepKey\n\t\t\t\tconst targetIndex = resolveWorkflowStepIndex(stepKeys, targetKey)\n\t\t\t\tconst target = run.workflow.steps[targetIndex]\n\t\t\t\tif (\n\t\t\t\t\ttarget.kind !== 'mutation' &&\n\t\t\t\t\ttarget.kind !== 'action' &&\n\t\t\t\t\ttarget.kind !== 'notify'\n\t\t\t\t)\n\t\t\t\t\tthrow new Error('Approval branch target must be a callback step')\n\t\t\t\tconst evidence = await step.runQuery(\n\t\t\t\t\tinternal.decisions.listForWorkflow,\n\t\t\t\t\t{ runId: run._id, stepKey: lastDecisionStepKey ?? workflowStep.key },\n\t\t\t\t\t{ name: `evidence:${workflowStep.key}` },\n\t\t\t\t)\n\t\t\t\tfailedStepKey = target.key\n\t\t\t\tawait executeCallback(step, target, {\n\t\t\t\t\t...callbackInput,\n\t\t\t\t\tdecision: {\n\t\t\t\t\t\tstepKey: lastDecisionStepKey ?? workflowStep.key,\n\t\t\t\t\t\toutcome: lastDecision,\n\t\t\t\t\t\tevidence,\n\t\t\t\t\t\t...(terminalEvidence === undefined ? {} : { terminalEvidence }),\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\tfailedStepKey = undefined\n\t\t\t\tif (lastDecision === 'rejected' || lastDecision === 'expired') break\n\t\t\t\tindex += 1\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tawait step.runMutation(\n\t\t\t\tinternal.requests.recordExecutionTerminal,\n\t\t\t\t{ runId: run._id, outcome: 'completed' },\n\t\t\t\t{ name: 'recordExecutionCompleted' },\n\t\t\t)\n\t\t\treturn null\n\t\t} catch (error) {\n\t\t\tawait step.runMutation(\n\t\t\t\tinternal.requests.recordExecutionTerminal,\n\t\t\t\t{\n\t\t\t\t\trunId: input.runId,\n\t\t\t\t\toutcome: 'failed',\n\t\t\t\t\t...(failedStepKey === undefined ? {} : { failedStepKey }),\n\t\t\t\t},\n\t\t\t\t{ name: 'recordExecutionFailed' },\n\t\t\t)\n\t\t\tthrow error\n\t\t}\n\t},\n})\n\ntype CallbackStep = Extract<\n\tDoc<'approvalRuns'>['workflow']['steps'][number],\n\t{ kind: 'mutation' | 'action' | 'notify' }\n>\n\nfunction buildCallbackInput(run: Doc<'approvalRuns'>): ApprovalCallbackInput {\n\treturn {\n\t\trunId: run._id,\n\t\tscopeRef: run.scopeRef,\n\t\tresourceType: run.resourceType,\n\t\tresourceRef: run.resourceRef,\n\t\t...(run.metadata === undefined ? {} : { metadata: run.metadata }),\n\t}\n}\n\nasync function executeCallback(\n\tstep: WorkflowCtx,\n\tworkflowStep: CallbackStep,\n\tinput: ApprovalCallbackInput,\n): Promise<void> {\n\tif (workflowStep.callback.kind === 'mutation') {\n\t\tawait step.runMutation(\n\t\t\tcallbackReference<'mutation'>(workflowStep.callback.handle),\n\t\t\tinput,\n\t\t\t{ name: workflowStep.key },\n\t\t)\n\t\treturn\n\t}\n\tawait step.runAction(\n\t\tcallbackReference<'action'>(workflowStep.callback.handle),\n\t\tinput,\n\t\t{ name: workflowStep.key, retry: workflowStep.callback.retry },\n\t)\n}\n"],"mappings":"6VAaA,MAAa,EAAmB,IAAI,EAAgB,EAAW,QAAQ,EAE1D,EAAM,EAAiB,OAAO,CAC1C,KAAM,CAAE,MAAO,EAAE,GAAG,cAAc,CAAE,EACpC,QAAS,EAAE,KAAK,EAChB,QAAS,MAAO,EAAM,IAAU,CAC/B,IAAI,EACJ,GAAI,CACH,IAAM,EAAkC,MAAM,EAAK,SAClD,EAAS,SAAS,eAClB,CAAE,MAAO,EAAM,KAAM,EACrB,CAAE,KAAM,oBAAqB,CAC9B,EACA,GAAI,CAAC,EAAK,MAAU,MAAM,4BAA4B,EACtD,GAAI,EAAI,aAAe,EAAK,WAC3B,MAAU,MAAM,yCAAyC,EAE1D,IAAM,EAAgB,EAAmB,CAAG,EACtC,EAAW,EAAI,SAAS,MAAM,IAClC,GAAiB,EAAa,GAChC,EACM,EAAgB,IAAI,IACzB,EAAI,SAAS,MAAM,QAAS,GAC3B,EAAa,OAAS,SACnB,CAAC,EAAa,gBAAiB,EAAa,eAAe,EAC3D,CAAC,CACL,CACD,EACI,EAA2D,KAC3D,EAAqC,KACrC,EAQA,EAAQ,EACZ,KAAO,EAAQ,EAAI,SAAS,MAAM,QAAQ,CACzC,IAAM,EAAe,EAAI,SAAS,MAAM,GACxC,GACC,EAAa,OAAS,YACtB,EAAa,OAAS,UACtB,EAAa,OAAS,SACrB,CACD,GAAI,EAAc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S,KAAM,CAC9D,CACD"}
|
|
1
|
+
{"version":3,"file":"workflow.mjs","names":["approvalWorkflow","WorkflowManager","components","run","v","failedStepKey","step","internal","input","callbackInput","buildCallbackInput","stepKeys","workflowStep","branchTargets","lastDecision","lastDecisionStepKey","terminalEvidence","index","executeCallback","event","approvalDecisionEventName","APPROVAL_DECISIONS","APPROVAL_RUN_STATES","targetKey","targetIndex","resolveWorkflowStepIndex","target","evidence","error","callbackReference"],"sources":["../../../src/components/approvals/workflow.ts"],"sourcesContent":["import type { ApprovalCallbackInput } from './validators'\nimport { WorkflowManager, type WorkflowCtx } from '@convex-dev/workflow'\nimport { v } from 'convex/values'\n\nimport { components, internal } from './_generated/api'\nimport type { Doc } from './_generated/dataModel'\nimport { APPROVAL_DECISIONS, APPROVAL_RUN_STATES } from './constants'\nimport {\n\tapprovalDecisionEventName,\n\tcallbackReference,\n\tresolveWorkflowStepIndex,\n} from './workflow_steps'\n\nexport const approvalWorkflow = new WorkflowManager(components.workflow)\n\nexport const run = approvalWorkflow.define({\n\targs: { runId: v.id('approvalRuns') },\n\treturns: v.null(),\n\thandler: async (step, input) => {\n\t\tlet failedStepKey: string | undefined\n\t\ttry {\n\t\t\tconst run: Doc<'approvalRuns'> | null = await step.runQuery(\n\t\t\t\tinternal.requests.getForWorkflow,\n\t\t\t\t{ runId: input.runId },\n\t\t\t\t{ name: 'loadLinkedApproval' },\n\t\t\t)\n\t\t\tif (!run) throw new Error('Approval request not found')\n\t\t\tif (run.workflowId !== step.workflowId)\n\t\t\t\tthrow new Error('Approval workflow linkage is incomplete')\n\n\t\t\tconst callbackInput = buildCallbackInput(run)\n\t\t\tconst stepKeys = run.workflow.steps.map((workflowStep) => workflowStep.key)\n\t\t\tconst branchTargets = new Set(\n\t\t\t\trun.workflow.steps.flatMap((workflowStep) =>\n\t\t\t\t\tworkflowStep.kind === 'branch'\n\t\t\t\t\t\t? [workflowStep.approvedStepKey, workflowStep.rejectedStepKey]\n\t\t\t\t\t\t: [],\n\t\t\t\t),\n\t\t\t)\n\t\t\tlet lastDecision: 'approved' | 'rejected' | 'expired' | null = null\n\t\t\tlet lastDecisionStepKey: string | null = null\n\t\t\tlet terminalEvidence:\n\t\t\t\t| {\n\t\t\t\t\t\tactorRef: string\n\t\t\t\t\t\tdecision: 'approved' | 'rejected'\n\t\t\t\t\t\treason?: string\n\t\t\t\t\t\tdecidedAt: number\n\t\t\t\t }\n\t\t\t\t| undefined\n\t\t\tlet index = 0\n\t\t\twhile (index < run.workflow.steps.length) {\n\t\t\t\tconst workflowStep = run.workflow.steps[index]\n\t\t\t\tif (\n\t\t\t\t\tworkflowStep.kind === 'mutation' ||\n\t\t\t\t\tworkflowStep.kind === 'action' ||\n\t\t\t\t\tworkflowStep.kind === 'notify'\n\t\t\t\t) {\n\t\t\t\t\tif (branchTargets.has(workflowStep.key)) {\n\t\t\t\t\t\tindex += 1\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfailedStepKey = workflowStep.key\n\t\t\t\t\tawait executeCallback(step, workflowStep, callbackInput)\n\t\t\t\t\tfailedStepKey = undefined\n\t\t\t\t\tindex += 1\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (workflowStep.kind === 'decision') {\n\t\t\t\t\tawait step.runMutation(\n\t\t\t\t\t\tinternal.decisions.enter,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\trunId: run._id,\n\t\t\t\t\t\t\tstepKey: workflowStep.key,\n\t\t\t\t\t\t\tworkflowId: step.workflowId,\n\t\t\t\t\t\t\texpiresAfterMs: workflowStep.expiresAfterMs,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ name: `enter:${workflowStep.key}` },\n\t\t\t\t\t)\n\t\t\t\t\tconst event = await step.awaitEvent({\n\t\t\t\t\t\tname: approvalDecisionEventName(run._id, workflowStep.key),\n\t\t\t\t\t\tvalidator: v.object({\n\t\t\t\t\t\t\toutcome: v.union(\n\t\t\t\t\t\t\t\tv.literal(APPROVAL_DECISIONS[0]),\n\t\t\t\t\t\t\t\tv.literal(APPROVAL_DECISIONS[1]),\n\t\t\t\t\t\t\t\tv.literal(APPROVAL_RUN_STATES[3]),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tterminalEvidence: v.optional(\n\t\t\t\t\t\t\t\tv.object({\n\t\t\t\t\t\t\t\t\tactorRef: v.string(),\n\t\t\t\t\t\t\t\t\tdecision: v.union(\n\t\t\t\t\t\t\t\t\t\tv.literal(APPROVAL_DECISIONS[0]),\n\t\t\t\t\t\t\t\t\t\tv.literal(APPROVAL_DECISIONS[1]),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\treason: v.optional(v.string()),\n\t\t\t\t\t\t\t\t\tdecidedAt: v.number(),\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\tlastDecision = event.outcome\n\t\t\t\t\tterminalEvidence = event.terminalEvidence\n\t\t\t\t\tlastDecisionStepKey = workflowStep.key\n\t\t\t\t\tif (lastDecision !== 'approved' && run.workflow.steps[index + 1]?.kind !== 'branch') break\n\t\t\t\t\tindex += 1\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (!lastDecision) throw new Error('Branch requires a preceding decision step')\n\t\t\t\tconst targetKey =\n\t\t\t\t\tlastDecision === 'approved' ? workflowStep.approvedStepKey : workflowStep.rejectedStepKey\n\t\t\t\tconst targetIndex = resolveWorkflowStepIndex(stepKeys, targetKey)\n\t\t\t\tconst target = run.workflow.steps[targetIndex]\n\t\t\t\tif (target.kind !== 'mutation' && target.kind !== 'action' && target.kind !== 'notify')\n\t\t\t\t\tthrow new Error('Approval branch target must be a callback step')\n\t\t\t\tconst evidence = await step.runQuery(\n\t\t\t\t\tinternal.decisions.listForWorkflow,\n\t\t\t\t\t{ runId: run._id, stepKey: lastDecisionStepKey ?? workflowStep.key },\n\t\t\t\t\t{ name: `evidence:${workflowStep.key}` },\n\t\t\t\t)\n\t\t\t\tfailedStepKey = target.key\n\t\t\t\tawait executeCallback(step, target, {\n\t\t\t\t\t...callbackInput,\n\t\t\t\t\tdecision: {\n\t\t\t\t\t\tstepKey: lastDecisionStepKey ?? workflowStep.key,\n\t\t\t\t\t\toutcome: lastDecision,\n\t\t\t\t\t\tevidence,\n\t\t\t\t\t\tterminalEvidence: terminalEvidence,\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\tfailedStepKey = undefined\n\t\t\t\tif (lastDecision === 'rejected' || lastDecision === 'expired') break\n\t\t\t\tindex += 1\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tawait step.runMutation(\n\t\t\t\tinternal.requests.recordExecutionTerminal,\n\t\t\t\t{ runId: run._id, outcome: 'completed' },\n\t\t\t\t{ name: 'recordExecutionCompleted' },\n\t\t\t)\n\t\t\treturn null\n\t\t} catch (error) {\n\t\t\tawait step.runMutation(\n\t\t\t\tinternal.requests.recordExecutionTerminal,\n\t\t\t\t{\n\t\t\t\t\trunId: input.runId,\n\t\t\t\t\toutcome: 'failed',\n\t\t\t\t\tfailedStepKey: failedStepKey,\n\t\t\t\t},\n\t\t\t\t{ name: 'recordExecutionFailed' },\n\t\t\t)\n\t\t\tthrow error\n\t\t}\n\t},\n})\n\ntype CallbackStep = Extract<\n\tDoc<'approvalRuns'>['workflow']['steps'][number],\n\t{ kind: 'mutation' | 'action' | 'notify' }\n>\n\nfunction buildCallbackInput(run: Doc<'approvalRuns'>): ApprovalCallbackInput {\n\treturn {\n\t\trunId: run._id,\n\t\tscopeRef: run.scopeRef,\n\t\tresourceType: run.resourceType,\n\t\tresourceRef: run.resourceRef,\n\t\tmetadata: run.metadata,\n\t}\n}\n\nasync function executeCallback(\n\tstep: WorkflowCtx,\n\tworkflowStep: CallbackStep,\n\tinput: ApprovalCallbackInput,\n): Promise<void> {\n\tif (workflowStep.callback.kind === 'mutation') {\n\t\tawait step.runMutation(callbackReference<'mutation'>(workflowStep.callback.handle), input, {\n\t\t\tname: workflowStep.key,\n\t\t})\n\t\treturn\n\t}\n\tawait step.runAction(callbackReference<'action'>(workflowStep.callback.handle), input, {\n\t\tname: workflowStep.key,\n\t\tretry: workflowStep.callback.retry,\n\t})\n}\n"],"mappings":"A,6VAaA,MAAaA,EAAmB,IAAIC,EAAgBC,EAAW,QAAQ,EAE1DC,EAAMH,EAAiB,OAAO,CAC1C,KAAM,CAAE,MAAOI,EAAE,GAAG,cAAc,CAAE,EACpC,QAASA,EAAE,KAAK,EAChB,QAAS,MAAO,EAAM,IAAU,CAC/B,IAAIC,EACJ,GAAI,CACH,IAAMF,EAAkC,MAAMG,EAAK,SAClDC,EAAS,SAAS,eAClB,CAAE,MAAOC,EAAM,KAAM,EACrB,CAAE,KAAM,oBAAqB,CAC9B,EACA,GAAI,CAACL,EAAK,MAAU,MAAM,4BAA4B,EACtD,GAAIA,EAAI,aAAeG,EAAK,WAC3B,MAAU,MAAM,yCAAyC,EAE1D,IAAMG,EAAgBC,EAAmBP,CAAG,EACtCQ,EAAWR,EAAI,SAAS,MAAM,IAAK,GAAiBS,EAAa,GAAG,EACpEC,EAAgB,IAAI,IACzBV,EAAI,SAAS,MAAM,QAAS,GAC3BS,EAAa,OAAS,SACnB,CAACA,EAAa,gBAAiBA,EAAa,eAAe,EAC3D,CAAC,CACL,CACD,EACIE,EAA2D,KAC3DC,EAAqC,KACrCC,EAQAC,EAAQ,EACZ,KAAOA,EAAQd,EAAI,SAAS,MAAM,QAAQ,CACzC,IAAMS,EAAeT,EAAI,SAAS,MAAMc,GACxC,GACCL,EAAa,OAAS,YACtBA,EAAa,OAAS,UACtBA,EAAa,OAAS,SACrB,CACD,GAAIC,EAAc,IAAID,EAAa,GAAG,EAAG,CACxC,GAAS,EACT,QACD,CACA,EAAgBA,EAAa,IAC7B,MAAMM,EAAgBZ,EAAMM,EAAcH,CAAa,EACvD,EAAgB,IAAA,GAChB,GAAS,EACT,QACD,CACA,GAAIG,EAAa,OAAS,WAAY,C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AAM,YAAYA,EAAa,KAAM,CACxC,EAYA,GAXA,EAAgBc,EAAO,IACvB,MAAMR,EAAgBZ,EAAMoB,EAAQ,CACnC,GAAGjB,EACH,SAAU,CACT,QAASM,GAAuBH,EAAa,IAC7C,QAASE,EACT,WACkB,kBACnB,CACD,CAAC,EACD,EAAgB,IAAA,GACZA,IAAiB,YAAcA,IAAiB,UAAW,MAC/D,GAAS,CAEV,CAOA,OALA,MAAMR,EAAK,YACVC,EAAS,SAAS,wBAClB,CAAE,MAAOJ,EAAI,IAAK,QAAS,WAAY,EACvC,CAAE,KAAM,0BAA2B,CACpC,EACO,IACR,OAASyB,EAAO,CAUf,MATA,MAAMtB,EAAK,YACVC,EAAS,SAAS,wBAClB,CACC,MAAOC,EAAM,MACb,QAAS,SACM,eAChB,EACA,CAAE,KAAM,uBAAwB,CACjC,EACMoB,CACP,CACD,CACD,CAAC,EAOD,SAASlB,EAAmB,EAAiD,CAC5E,MAAO,CACN,MAAOP,EAAI,IACX,SAAUA,EAAI,SACd,aAAcA,EAAI,aAClB,YAAaA,EAAI,YACjB,SAAUA,EAAI,QACf,CACD,CAEA,eAAee,EACd,EACA,EACA,EACgB,CACZN,EAAa,SAAS,OAAS,WAClC,MAAMN,EAAK,YAAYuB,EAA8BjB,EAAa,SAAS,MAAM,EAAGJ,EAAO,CAC1F,KAAMI,EAAa,GACpB,CAAC,EAGF,MAAMN,EAAK,UAAUuB,EAA4BjB,EAAa,SAAS,MAAM,EAAGJ,EAAO,CACtF,KAAMI,EAAa,IACnB,MAAOA,EAAa,SAAS,KAC9B,CAAC,CACF,C"}
|
|
@@ -2,27 +2,27 @@ import { ApprovalDecision } from "./constants.mjs";
|
|
|
2
2
|
import { ApprovalCallbackInput, ApprovalWorkflowDescriptor } from "./validators.mjs";
|
|
3
3
|
import { FunctionReference, FunctionType } from "convex/server";
|
|
4
4
|
declare namespace workflow_steps_d_exports {
|
|
5
|
-
export { ApprovalActionStep, ApprovalBranchStep,
|
|
5
|
+
export { ApprovalActionStep, ApprovalBranchStep, ApprovalDecisionEvidence, ApprovalDecisionStep, ApprovalDefinition, ApprovalMutationStep, ApprovalNotifyStep, ApprovalWorkflowStep, CreateApprovalHandle, approvalDecisionEventName, callbackReference, compileApprovalDescriptor, evaluateDecisionOutcome, resolveWorkflowStepIndex };
|
|
6
6
|
}
|
|
7
|
-
type ApprovalMutationStep = Readonly<{
|
|
7
|
+
export type ApprovalMutationStep = Readonly<{
|
|
8
8
|
kind: 'mutation';
|
|
9
9
|
key: string;
|
|
10
10
|
handler: FunctionReference<'mutation', 'internal'>;
|
|
11
11
|
retry: boolean;
|
|
12
12
|
}>;
|
|
13
|
-
type ApprovalActionStep = Readonly<{
|
|
13
|
+
export type ApprovalActionStep = Readonly<{
|
|
14
14
|
kind: 'action';
|
|
15
15
|
key: string;
|
|
16
16
|
handler: FunctionReference<'action', 'internal'>;
|
|
17
17
|
retry: boolean;
|
|
18
18
|
}>;
|
|
19
|
-
type ApprovalNotifyStep = Readonly<{
|
|
19
|
+
export type ApprovalNotifyStep = Readonly<{
|
|
20
20
|
kind: 'notify';
|
|
21
21
|
key: string;
|
|
22
22
|
handler: FunctionReference<'action', 'internal'>;
|
|
23
23
|
retry: boolean;
|
|
24
24
|
}>;
|
|
25
|
-
type ApprovalDecisionStep = Readonly<{
|
|
25
|
+
export type ApprovalDecisionStep = Readonly<{
|
|
26
26
|
kind: 'decision';
|
|
27
27
|
key: string;
|
|
28
28
|
decisions: readonly ApprovalDecision[];
|
|
@@ -33,28 +33,27 @@ type ApprovalDecisionStep = Readonly<{
|
|
|
33
33
|
makerChecker: boolean;
|
|
34
34
|
expiresAfterMs?: number;
|
|
35
35
|
}>;
|
|
36
|
-
type ApprovalBranchStep = Readonly<{
|
|
36
|
+
export type ApprovalBranchStep = Readonly<{
|
|
37
37
|
kind: 'branch';
|
|
38
38
|
key: string;
|
|
39
39
|
approvedStepKey: string;
|
|
40
40
|
rejectedStepKey: string;
|
|
41
41
|
}>;
|
|
42
|
-
type ApprovalWorkflowStep = ApprovalMutationStep | ApprovalActionStep | ApprovalNotifyStep | ApprovalDecisionStep | ApprovalBranchStep;
|
|
43
|
-
type ApprovalDefinition = Readonly<{
|
|
42
|
+
export type ApprovalWorkflowStep = ApprovalMutationStep | ApprovalActionStep | ApprovalNotifyStep | ApprovalDecisionStep | ApprovalBranchStep;
|
|
43
|
+
export type ApprovalDefinition = Readonly<{
|
|
44
44
|
name: string;
|
|
45
45
|
compatibilityKey: string;
|
|
46
46
|
steps: readonly ApprovalWorkflowStep[];
|
|
47
47
|
}>;
|
|
48
|
-
type CreateApprovalHandle = (reference: FunctionReference<'mutation' | 'action', 'internal'>) => Promise<string>;
|
|
49
|
-
type ApprovalDecisionEvidence = Readonly<{
|
|
48
|
+
export type CreateApprovalHandle = (reference: FunctionReference<'mutation' | 'action', 'internal'>) => Promise<string>;
|
|
49
|
+
export type ApprovalDecisionEvidence = Readonly<{
|
|
50
50
|
actorRef: string;
|
|
51
51
|
decision: ApprovalDecision;
|
|
52
52
|
}>;
|
|
53
|
-
declare function approvalDecisionEventName(runId: string, stepKey: string): string;
|
|
54
|
-
declare function evaluateDecisionOutcome(decisions: readonly ApprovalDecisionEvidence[], approvalsRequired: number): ApprovalDecision | null;
|
|
55
|
-
declare function resolveWorkflowStepIndex(stepKeys: readonly string[], targetKey: string): number;
|
|
56
|
-
declare function callbackReference<Type extends FunctionType>(handle: string): FunctionReference<Type, 'internal', ApprovalCallbackInput, unknown>;
|
|
57
|
-
declare function compileApprovalDescriptor(definition: ApprovalDefinition, createHandle?: CreateApprovalHandle): Promise<Readonly<ApprovalWorkflowDescriptor>>;
|
|
58
|
-
|
|
59
|
-
export { ApprovalActionStep, ApprovalBranchStep, type ApprovalCallbackInput, ApprovalDecisionEvidence, ApprovalDecisionStep, ApprovalDefinition, ApprovalMutationStep, ApprovalNotifyStep, ApprovalWorkflowStep, CreateApprovalHandle, approvalDecisionEventName, callbackReference, compileApprovalDescriptor, evaluateDecisionOutcome, resolveWorkflowStepIndex, workflow_steps_d_exports };
|
|
53
|
+
export declare function approvalDecisionEventName(runId: string, stepKey: string): string;
|
|
54
|
+
export declare function evaluateDecisionOutcome(decisions: readonly ApprovalDecisionEvidence[], approvalsRequired: number): ApprovalDecision | null;
|
|
55
|
+
export declare function resolveWorkflowStepIndex(stepKeys: readonly string[], targetKey: string): number;
|
|
56
|
+
export declare function callbackReference<Type extends FunctionType>(handle: string): FunctionReference<Type, 'internal', ApprovalCallbackInput, unknown>;
|
|
57
|
+
export declare function compileApprovalDescriptor(definition: ApprovalDefinition, createHandle?: CreateApprovalHandle): Promise<Readonly<ApprovalWorkflowDescriptor>>;
|
|
58
|
+
export { workflow_steps_d_exports };
|
|
60
59
|
//# sourceMappingURL=workflow_steps.d.mts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{approvalWorkflowDescriptor as e}from"./validators.mjs";import{createFunctionHandle as t}from"convex/server";function n(e,t){return`approval:${e}:${t}`}function r(e,t){return e.some(e=>e.decision===`rejected`)?`rejected`:e.filter(e=>e.decision===`approved`).length>=t?`approved`:null}function i(e,t){let n=e.indexOf(t);if(n===-1)throw Error(`Unknown approval workflow step: ${t}`);return n}function a(e){return e}async function o(n,r=t){let i=await Promise.all(n.steps.map(async e=>e.kind===`mutation`||e.kind===`action`?{kind:e.kind,key:e.key,callback:{kind:e.kind,handle:await r(e.handler),retry:e.retry}}:e.kind===`notify`?{kind:e.kind,key:e.key,callback:{kind:`action`,handle:await r(e.handler),retry:e.retry}}:e.kind===`decision`?{...e,decisions:[...e.decisions],quorum:{...e.quorum}}:{...e}));return s(e.parse({schemaVersion:1,compatibilityKey:n.compatibilityKey,name:n.name,steps:i}))}function s(e){
|
|
1
|
+
import{approvalWorkflowDescriptor as e}from"./validators.mjs";import{createFunctionHandle as t}from"convex/server";function n(e,t){return`approval:${e}:${t}`}function r(e,t){return e.some(e=>e.decision===`rejected`)?`rejected`:e.filter(e=>e.decision===`approved`).length>=t?`approved`:null}function i(e,t){let n=e.indexOf(t);if(n===-1)throw Error(`Unknown approval workflow step: ${t}`);return n}function a(e){return e}async function o(n,r=t){let i=await Promise.all(n.steps.map(async e=>e.kind===`mutation`||e.kind===`action`?{kind:e.kind,key:e.key,callback:{kind:e.kind,handle:await r(e.handler),retry:e.retry}}:e.kind===`notify`?{kind:e.kind,key:e.key,callback:{kind:`action`,handle:await r(e.handler),retry:e.retry}}:e.kind===`decision`?{...e,decisions:[...e.decisions],quorum:{...e.quorum}}:{...e}));return s(e.parse({schemaVersion:1,compatibilityKey:n.compatibilityKey,name:n.name,steps:i}))}function s(e){for(let t of e.steps)t.kind===`decision`?(Object.freeze(t.decisions),Object.freeze(t.quorum)):`callback`in t&&Object.freeze(t.callback),Object.freeze(t);return Object.freeze(e.steps),Object.freeze(e)}export{n as approvalDecisionEventName,a as callbackReference,o as compileApprovalDescriptor,r as evaluateDecisionOutcome,i as resolveWorkflowStepIndex};
|
|
2
2
|
//# sourceMappingURL=workflow_steps.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow_steps.mjs","names":[],"sources":["../../../src/components/approvals/workflow_steps.ts"],"sourcesContent":["import {\n\tcreateFunctionHandle,\n\ttype FunctionReference,\n\ttype FunctionType,\n} from 'convex/server'\n\nimport type { ApprovalDecision } from './constants'\nimport {\n\tapprovalWorkflowDescriptor,\n\ttype ApprovalCallbackInput,\n\ttype ApprovalWorkflowDescriptor,\n} from './validators'\n\nexport type
|
|
1
|
+
{"version":3,"file":"workflow_steps.mjs","names":["approvalDecisionEventName","runId","stepKey","evaluateDecisionOutcome","decisions","decision","approvalsRequired","resolveWorkflowStepIndex","index","stepKeys","targetKey","callbackReference","handle","compileApprovalDescriptor","createFunctionHandle","steps","definition","step","createHandle","deepFreeze","approvalWorkflowDescriptor","descriptor"],"sources":["../../../src/components/approvals/workflow_steps.ts"],"sourcesContent":["import {\n\tcreateFunctionHandle,\n\ttype FunctionReference,\n\ttype FunctionType,\n\ttype FunctionHandle,\n} from 'convex/server'\n\nimport type { ApprovalDecision } from './constants'\nimport {\n\tapprovalWorkflowDescriptor,\n\ttype ApprovalCallbackInput,\n\ttype ApprovalWorkflowDescriptor,\n} from './validators'\n\nexport type ApprovalMutationStep = Readonly<{\n\tkind: 'mutation'\n\tkey: string\n\thandler: FunctionReference<'mutation', 'internal'>\n\tretry: boolean\n}>\n\nexport type ApprovalActionStep = Readonly<{\n\tkind: 'action'\n\tkey: string\n\thandler: FunctionReference<'action', 'internal'>\n\tretry: boolean\n}>\n\nexport type ApprovalNotifyStep = Readonly<{\n\tkind: 'notify'\n\tkey: string\n\thandler: FunctionReference<'action', 'internal'>\n\tretry: boolean\n}>\n\nexport type ApprovalDecisionStep = Readonly<{\n\tkind: 'decision'\n\tkey: string\n\tdecisions: readonly ApprovalDecision[]\n\tquorum: Readonly<{ kind: 'count'; approvals: number }>\n\tmakerChecker: boolean\n\texpiresAfterMs?: number\n}>\n\nexport type ApprovalBranchStep = Readonly<{\n\tkind: 'branch'\n\tkey: string\n\tapprovedStepKey: string\n\trejectedStepKey: string\n}>\n\nexport type ApprovalWorkflowStep =\n\t| ApprovalMutationStep\n\t| ApprovalActionStep\n\t| ApprovalNotifyStep\n\t| ApprovalDecisionStep\n\t| ApprovalBranchStep\n\nexport type ApprovalDefinition = Readonly<{\n\tname: string\n\tcompatibilityKey: string\n\tsteps: readonly ApprovalWorkflowStep[]\n}>\n\nexport type CreateApprovalHandle = (\n\treference: FunctionReference<'mutation' | 'action', 'internal'>,\n) => Promise<string>\n\nexport type ApprovalDecisionEvidence = Readonly<{\n\tactorRef: string\n\tdecision: ApprovalDecision\n}>\n\nexport function approvalDecisionEventName(runId: string, stepKey: string): string {\n\treturn `approval:${runId}:${stepKey}`\n}\n\nexport function evaluateDecisionOutcome(\n\tdecisions: readonly ApprovalDecisionEvidence[],\n\tapprovalsRequired: number,\n): ApprovalDecision | null {\n\tif (decisions.some((decision) => decision.decision === 'rejected')) return 'rejected'\n\treturn decisions.filter((decision) => decision.decision === 'approved').length >=\n\t\tapprovalsRequired\n\t\t? 'approved'\n\t\t: null\n}\n\nexport function resolveWorkflowStepIndex(stepKeys: readonly string[], targetKey: string): number {\n\tconst index = stepKeys.indexOf(targetKey)\n\tif (index === -1) throw new Error(`Unknown approval workflow step: ${targetKey}`)\n\treturn index\n}\n\nexport function callbackReference<Type extends FunctionType>(\n\thandle: string,\n): FunctionReference<Type, 'internal', ApprovalCallbackInput, unknown> {\n\t// SAFETY: descriptors persist handles produced by createFunctionHandle; Convex resolves them on invocation.\n\treturn handle as FunctionHandle<Type, ApprovalCallbackInput, unknown>\n}\n\nexport async function compileApprovalDescriptor(\n\tdefinition: ApprovalDefinition,\n\tcreateHandle: CreateApprovalHandle = createFunctionHandle,\n): Promise<Readonly<ApprovalWorkflowDescriptor>> {\n\tconst steps = await Promise.all(\n\t\tdefinition.steps.map(async (step) => {\n\t\t\tif (step.kind === 'mutation' || step.kind === 'action') {\n\t\t\t\treturn {\n\t\t\t\t\tkind: step.kind,\n\t\t\t\t\tkey: step.key,\n\t\t\t\t\tcallback: {\n\t\t\t\t\t\tkind: step.kind,\n\t\t\t\t\t\thandle: await createHandle(step.handler),\n\t\t\t\t\t\tretry: step.retry,\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (step.kind === 'notify') {\n\t\t\t\treturn {\n\t\t\t\t\tkind: step.kind,\n\t\t\t\t\tkey: step.key,\n\t\t\t\t\tcallback: {\n\t\t\t\t\t\tkind: 'action' as const,\n\t\t\t\t\t\thandle: await createHandle(step.handler),\n\t\t\t\t\t\tretry: step.retry,\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (step.kind === 'decision') {\n\t\t\t\treturn {\n\t\t\t\t\t...step,\n\t\t\t\t\tdecisions: [...step.decisions],\n\t\t\t\t\tquorum: { ...step.quorum },\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn { ...step }\n\t\t}),\n\t)\n\tconst descriptor = approvalWorkflowDescriptor.parse({\n\t\tschemaVersion: 1,\n\t\tcompatibilityKey: definition.compatibilityKey,\n\t\tname: definition.name,\n\t\tsteps,\n\t})\n\treturn deepFreeze(descriptor)\n}\n\nfunction deepFreeze(descriptor: ApprovalWorkflowDescriptor): Readonly<ApprovalWorkflowDescriptor> {\n\tfor (const step of descriptor.steps) {\n\t\tif (step.kind === 'decision') {\n\t\t\tObject.freeze(step.decisions)\n\t\t\tObject.freeze(step.quorum)\n\t\t} else if ('callback' in step) {\n\t\t\tObject.freeze(step.callback)\n\t\t}\n\t\tObject.freeze(step)\n\t}\n\tObject.freeze(descriptor.steps)\n\treturn Object.freeze(descriptor)\n}\n"],"mappings":"A,mHAyEA,SAAgBA,EAA0B,EAAe,EAAyB,CACjF,MAAO,YAAYC,EAAM,GAAGC,GAC7B,CAEA,SAAgBC,EACf,EACA,EAC0B,CAE1B,OADIC,EAAU,KAAM,GAAaC,EAAS,WAAa,UAAU,EAAU,WACpED,EAAU,OAAQ,GAAaC,EAAS,WAAa,UAAU,CAAC,CAAC,QACvEC,EACE,WACA,IACJ,CAEA,SAAgBC,EAAyB,EAA6B,EAA2B,CAChG,IAAMC,EAAQC,EAAS,QAAQC,CAAS,EACxC,GAAIF,IAAU,GAAI,MAAU,MAAM,mCAAmCE,GAAW,EAChF,OAAOF,CACR,CAEA,SAAgBG,EACf,EACsE,CAEtE,OAAOC,CACR,CAEA,eAAsBC,EACrB,EACA,EAAqCC,EACW,CAChD,IAAMC,EAAQ,MAAM,QAAQ,IAC3BC,EAAW,MAAM,IAAI,KAAO,IACvBC,EAAK,OAAS,YAAcA,EAAK,OAAS,SACtC,CACN,KAAMA,EAAK,KACX,IAAKA,EAAK,IACV,SAAU,CACT,KAAMA,EAAK,KACX,OAAQ,MAAMC,EAAaD,EAAK,OAAO,EACvC,MAAOA,EAAK,KACb,CACD,EAEGA,EAAK,OAAS,SACV,CACN,KAAMA,EAAK,KACX,IAAKA,EAAK,IACV,SAAU,CACT,KAAM,SACN,OAAQ,MAAMC,EAAaD,EAAK,OAAO,EACvC,MAAOA,EAAK,KACb,CACD,EAEGA,EAAK,OAAS,WACV,CACN,GAAGA,EACH,UAAW,CAAC,GAAGA,EAAK,SAAS,EAC7B,OAAQ,CAAE,GAAGA,EAAK,MAAO,CAC1B,EAEM,CAAE,GAAGA,CAAK,CACjB,CACF,EAOA,OAAOE,EANYC,EAA2B,MAAM,CACnD,cAAe,EACf,iBAAkBJ,EAAW,iBAC7B,KAAMA,EAAW,KACjB,OACD,CAC2B,CAAC,CAC7B,CAEA,SAASG,EAAW,EAA8E,CACjG,IAAK,IAAMF,KAAQI,EAAW,MACzBJ,EAAK,OAAS,YACjB,OAAO,OAAOA,EAAK,SAAS,EAC5B,OAAO,OAAOA,EAAK,MAAM,GACf,aAAcA,GACxB,OAAO,OAAOA,EAAK,QAAQ,EAE5B,OAAO,OAAOA,CAAI,EAGnB,OADA,OAAO,OAAOI,EAAW,KAAK,EACvB,OAAO,OAAOA,CAAU,CAChC,C"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
+
import { client_d_exports } from "../client.mjs";
|
|
2
|
+
import { functions_d_exports } from "../functions.mjs";
|
|
1
3
|
import { command_d_exports } from "../modules/command/command.mjs";
|
|
2
4
|
import { observability_d_exports } from "../modules/observability/observability.mjs";
|
|
3
5
|
import { query_d_exports } from "../modules/query/query.mjs";
|
|
4
6
|
import { result_d_exports } from "../result.mjs";
|
|
5
7
|
import { telemetry_d_exports } from "../telemetry.mjs";
|
|
6
|
-
import { client_d_exports } from "../client.mjs";
|
|
7
|
-
import { functions_d_exports } from "../functions.mjs";
|
|
8
8
|
import { ApiFromModules, FilterApi, FunctionReference } from "convex/server";
|
|
9
|
-
//#region src/components/foundation/_generated/api.d.ts
|
|
10
9
|
declare const fullApi: ApiFromModules<{
|
|
11
10
|
client: typeof client_d_exports;
|
|
12
11
|
functions: typeof functions_d_exports;
|
|
@@ -24,7 +23,7 @@ declare const fullApi: ApiFromModules<{
|
|
|
24
23
|
* const myFunctionReference = api.myModule.myFunction;
|
|
25
24
|
* ```
|
|
26
25
|
*/
|
|
27
|
-
declare const api: FilterApi<typeof fullApi, FunctionReference<any, "public">>;
|
|
26
|
+
export declare const api: FilterApi<typeof fullApi, FunctionReference<any, "public">>;
|
|
28
27
|
/**
|
|
29
28
|
* A utility for referencing Convex functions in your app's internal API.
|
|
30
29
|
*
|
|
@@ -33,8 +32,7 @@ declare const api: FilterApi<typeof fullApi, FunctionReference<any, "public">>;
|
|
|
33
32
|
* const myFunctionReference = internal.myModule.myFunction;
|
|
34
33
|
* ```
|
|
35
34
|
*/
|
|
36
|
-
declare const internal: FilterApi<typeof fullApi, FunctionReference<any, "internal">>;
|
|
37
|
-
declare const components: {};
|
|
38
|
-
|
|
39
|
-
export { api, components, internal };
|
|
35
|
+
export declare const internal: FilterApi<typeof fullApi, FunctionReference<any, "internal">>;
|
|
36
|
+
export declare const components: {};
|
|
37
|
+
export {};
|
|
40
38
|
//# sourceMappingURL=api.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.mjs","names":[],"sources":["../../../../src/components/foundation/_generated/api.ts"],"sourcesContent":["/* eslint-disable */\n/**\n * Generated `api` utility.\n *\n * THIS CODE IS AUTOMATICALLY GENERATED.\n *\n * To regenerate, run `npx convex dev`.\n * @module\n */\n\nimport type * as client from \"../client.js\";\nimport type * as functions from \"../functions.js\";\nimport type * as modules_command_command from \"../modules/command/command.js\";\nimport type * as modules_observability_observability from \"../modules/observability/observability.js\";\nimport type * as modules_query_query from \"../modules/query/query.js\";\nimport type * as result from \"../result.js\";\nimport type * as telemetry from \"../telemetry.js\";\n\nimport type {\n ApiFromModules,\n FilterApi,\n FunctionReference,\n} from \"convex/server\";\nimport { anyApi, componentsGeneric } from \"convex/server\";\n\nconst fullApi: ApiFromModules<{\n client: typeof client;\n functions: typeof functions;\n \"modules/command/command\": typeof modules_command_command;\n \"modules/observability/observability\": typeof modules_observability_observability;\n \"modules/query/query\": typeof modules_query_query;\n result: typeof result;\n telemetry: typeof telemetry;\n}> = anyApi as any;\n\n/**\n * A utility for referencing Convex functions in your app's public API.\n *\n * Usage:\n * ```js\n * const myFunctionReference = api.myModule.myFunction;\n * ```\n */\nexport const api: FilterApi<\n typeof fullApi,\n FunctionReference<any, \"public\">\n> = anyApi as any;\n\n/**\n * A utility for referencing Convex functions in your app's internal API.\n *\n * Usage:\n * ```js\n * const myFunctionReference = internal.myModule.myFunction;\n * ```\n */\nexport const internal: FilterApi<\n typeof fullApi,\n FunctionReference<any, \"internal\">\n> = anyApi as any;\n\nexport const components = componentsGeneric() as unknown as {};\n"],"mappings":"8DA2CA,
|
|
1
|
+
{"version":3,"file":"api.mjs","names":["api","anyApi","internal","components","componentsGeneric"],"sources":["../../../../src/components/foundation/_generated/api.ts"],"sourcesContent":["/* eslint-disable */\n/**\n * Generated `api` utility.\n *\n * THIS CODE IS AUTOMATICALLY GENERATED.\n *\n * To regenerate, run `npx convex dev`.\n * @module\n */\n\nimport type * as client from \"../client.js\";\nimport type * as functions from \"../functions.js\";\nimport type * as modules_command_command from \"../modules/command/command.js\";\nimport type * as modules_observability_observability from \"../modules/observability/observability.js\";\nimport type * as modules_query_query from \"../modules/query/query.js\";\nimport type * as result from \"../result.js\";\nimport type * as telemetry from \"../telemetry.js\";\n\nimport type {\n ApiFromModules,\n FilterApi,\n FunctionReference,\n} from \"convex/server\";\nimport { anyApi, componentsGeneric } from \"convex/server\";\n\nconst fullApi: ApiFromModules<{\n client: typeof client;\n functions: typeof functions;\n \"modules/command/command\": typeof modules_command_command;\n \"modules/observability/observability\": typeof modules_observability_observability;\n \"modules/query/query\": typeof modules_query_query;\n result: typeof result;\n telemetry: typeof telemetry;\n}> = anyApi as any;\n\n/**\n * A utility for referencing Convex functions in your app's public API.\n *\n * Usage:\n * ```js\n * const myFunctionReference = api.myModule.myFunction;\n * ```\n */\nexport const api: FilterApi<\n typeof fullApi,\n FunctionReference<any, \"public\">\n> = anyApi as any;\n\n/**\n * A utility for referencing Convex functions in your app's internal API.\n *\n * Usage:\n * ```js\n * const myFunctionReference = internal.myModule.myFunction;\n * ```\n */\nexport const internal: FilterApi<\n typeof fullApi,\n FunctionReference<any, \"internal\">\n> = anyApi as any;\n\nexport const components = componentsGeneric() as unknown as {};\n"],"mappings":"A,8DA2CA,MAAaA,EAGTC,EAUSC,EAGTD,EAESE,EAAaC,EAAkB,E"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { FunctionReference } from "convex/server";
|
|
2
|
-
//#region src/components/foundation/_generated/component.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* A utility for referencing a Convex component's exposed API.
|
|
5
4
|
*
|
|
@@ -11,11 +10,9 @@ import { FunctionReference } from "convex/server";
|
|
|
11
10
|
* }
|
|
12
11
|
* ```
|
|
13
12
|
*/
|
|
14
|
-
type ComponentApi<Name extends string | undefined = string | undefined> = {
|
|
13
|
+
export type ComponentApi<Name extends string | undefined = string | undefined> = {
|
|
15
14
|
functions: {
|
|
16
15
|
status: FunctionReference<"query", "internal", {}, "ready", Name>;
|
|
17
16
|
};
|
|
18
17
|
};
|
|
19
|
-
//#endregion
|
|
20
|
-
export { ComponentApi };
|
|
21
18
|
//# sourceMappingURL=component.d.mts.map
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import _default from "../schema.js";
|
|
2
|
-
import { DataModelFromSchemaDefinition, DocumentByName, SystemTableNames, TableNamesInDataModel } from "convex/server";
|
|
3
2
|
import { GenericId } from "convex/values";
|
|
4
|
-
|
|
3
|
+
import { DataModelFromSchemaDefinition, DocumentByName, SystemTableNames, TableNamesInDataModel } from "convex/server";
|
|
5
4
|
/**
|
|
6
5
|
* The names of all of your Convex tables.
|
|
7
6
|
*/
|
|
8
|
-
type TableNames = TableNamesInDataModel<DataModel>;
|
|
7
|
+
export type TableNames = TableNamesInDataModel<DataModel>;
|
|
9
8
|
/**
|
|
10
9
|
* The type of a document stored in Convex.
|
|
11
10
|
*
|
|
12
11
|
* @typeParam TableName - A string literal type of the table name (like "users").
|
|
13
12
|
*/
|
|
14
|
-
type Doc<TableName extends TableNames> = DocumentByName<DataModel, TableName>;
|
|
13
|
+
export type Doc<TableName extends TableNames> = DocumentByName<DataModel, TableName>;
|
|
15
14
|
/**
|
|
16
15
|
* An identifier for a document in Convex.
|
|
17
16
|
*
|
|
@@ -25,7 +24,7 @@ type Doc<TableName extends TableNames> = DocumentByName<DataModel, TableName>;
|
|
|
25
24
|
*
|
|
26
25
|
* @typeParam TableName - A string literal type of the table name (like "users").
|
|
27
26
|
*/
|
|
28
|
-
type Id<TableName extends TableNames | SystemTableNames> = GenericId<TableName>;
|
|
27
|
+
export type Id<TableName extends TableNames | SystemTableNames> = GenericId<TableName>;
|
|
29
28
|
/**
|
|
30
29
|
* A type describing your Convex data model.
|
|
31
30
|
*
|
|
@@ -35,7 +34,5 @@ type Id<TableName extends TableNames | SystemTableNames> = GenericId<TableName>;
|
|
|
35
34
|
* This type is used to parameterize methods like `queryGeneric` and
|
|
36
35
|
* `mutationGeneric` to make them type-safe.
|
|
37
36
|
*/
|
|
38
|
-
type DataModel = DataModelFromSchemaDefinition<typeof _default>;
|
|
39
|
-
//#endregion
|
|
40
|
-
export { DataModel, Doc, Id, TableNames };
|
|
37
|
+
export type DataModel = DataModelFromSchemaDefinition<typeof _default>;
|
|
41
38
|
//# sourceMappingURL=dataModel.d.mts.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { DataModel } from "./dataModel.mjs";
|
|
2
2
|
import { ActionBuilder, GenericActionCtx, GenericDatabaseReader, GenericDatabaseWriter, GenericMutationCtx, GenericQueryCtx, HttpActionBuilder, MutationBuilder, QueryBuilder } from "convex/server";
|
|
3
|
-
//#region src/components/foundation/_generated/server.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Define a query in this Convex app's public API.
|
|
6
5
|
*
|
|
@@ -9,7 +8,7 @@ import { ActionBuilder, GenericActionCtx, GenericDatabaseReader, GenericDatabase
|
|
|
9
8
|
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
|
|
10
9
|
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
|
|
11
10
|
*/
|
|
12
|
-
declare const query: QueryBuilder<DataModel, "public">;
|
|
11
|
+
export declare const query: QueryBuilder<DataModel, "public">;
|
|
13
12
|
/**
|
|
14
13
|
* Define a query that is only accessible from other Convex functions (but not from the client).
|
|
15
14
|
*
|
|
@@ -18,7 +17,7 @@ declare const query: QueryBuilder<DataModel, "public">;
|
|
|
18
17
|
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
|
|
19
18
|
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
|
|
20
19
|
*/
|
|
21
|
-
declare const internalQuery: QueryBuilder<DataModel, "internal">;
|
|
20
|
+
export declare const internalQuery: QueryBuilder<DataModel, "internal">;
|
|
22
21
|
/**
|
|
23
22
|
* Define a mutation in this Convex app's public API.
|
|
24
23
|
*
|
|
@@ -27,7 +26,7 @@ declare const internalQuery: QueryBuilder<DataModel, "internal">;
|
|
|
27
26
|
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
|
|
28
27
|
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
|
|
29
28
|
*/
|
|
30
|
-
declare const mutation: MutationBuilder<DataModel, "public">;
|
|
29
|
+
export declare const mutation: MutationBuilder<DataModel, "public">;
|
|
31
30
|
/**
|
|
32
31
|
* Define a mutation that is only accessible from other Convex functions (but not from the client).
|
|
33
32
|
*
|
|
@@ -36,7 +35,7 @@ declare const mutation: MutationBuilder<DataModel, "public">;
|
|
|
36
35
|
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
|
|
37
36
|
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
|
|
38
37
|
*/
|
|
39
|
-
declare const internalMutation: MutationBuilder<DataModel, "internal">;
|
|
38
|
+
export declare const internalMutation: MutationBuilder<DataModel, "internal">;
|
|
40
39
|
/**
|
|
41
40
|
* Define an action in this Convex app's public API.
|
|
42
41
|
*
|
|
@@ -48,14 +47,14 @@ declare const internalMutation: MutationBuilder<DataModel, "internal">;
|
|
|
48
47
|
* @param func - The action. It receives an {@link ActionCtx} as its first argument.
|
|
49
48
|
* @returns The wrapped action. Include this as an `export` to name it and make it accessible.
|
|
50
49
|
*/
|
|
51
|
-
declare const action: ActionBuilder<DataModel, "public">;
|
|
50
|
+
export declare const action: ActionBuilder<DataModel, "public">;
|
|
52
51
|
/**
|
|
53
52
|
* Define an action that is only accessible from other Convex functions (but not from the client).
|
|
54
53
|
*
|
|
55
54
|
* @param func - The function. It receives an {@link ActionCtx} as its first argument.
|
|
56
55
|
* @returns The wrapped function. Include this as an `export` to name it and make it accessible.
|
|
57
56
|
*/
|
|
58
|
-
declare const internalAction: ActionBuilder<DataModel, "internal">;
|
|
57
|
+
export declare const internalAction: ActionBuilder<DataModel, "internal">;
|
|
59
58
|
/**
|
|
60
59
|
* Define an HTTP action.
|
|
61
60
|
*
|
|
@@ -67,7 +66,7 @@ declare const internalAction: ActionBuilder<DataModel, "internal">;
|
|
|
67
66
|
* and a Fetch API `Request` object as its second.
|
|
68
67
|
* @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
|
|
69
68
|
*/
|
|
70
|
-
declare const httpAction: HttpActionBuilder;
|
|
69
|
+
export declare const httpAction: HttpActionBuilder;
|
|
71
70
|
/**
|
|
72
71
|
* A set of services for use within Convex query functions.
|
|
73
72
|
*
|
|
@@ -76,7 +75,7 @@ declare const httpAction: HttpActionBuilder;
|
|
|
76
75
|
*
|
|
77
76
|
* If you're using code generation, use the `QueryCtx` type in `convex/_generated/server.d.ts` instead.
|
|
78
77
|
*/
|
|
79
|
-
type QueryCtx = GenericQueryCtx<DataModel>;
|
|
78
|
+
export type QueryCtx = GenericQueryCtx<DataModel>;
|
|
80
79
|
/**
|
|
81
80
|
* A set of services for use within Convex mutation functions.
|
|
82
81
|
*
|
|
@@ -85,14 +84,14 @@ type QueryCtx = GenericQueryCtx<DataModel>;
|
|
|
85
84
|
*
|
|
86
85
|
* If you're using code generation, use the `MutationCtx` type in `convex/_generated/server.d.ts` instead.
|
|
87
86
|
*/
|
|
88
|
-
type MutationCtx = GenericMutationCtx<DataModel>;
|
|
87
|
+
export type MutationCtx = GenericMutationCtx<DataModel>;
|
|
89
88
|
/**
|
|
90
89
|
* A set of services for use within Convex action functions.
|
|
91
90
|
*
|
|
92
91
|
* The action context is passed as the first argument to any Convex action
|
|
93
92
|
* function run on the server.
|
|
94
93
|
*/
|
|
95
|
-
type ActionCtx = GenericActionCtx<DataModel>;
|
|
94
|
+
export type ActionCtx = GenericActionCtx<DataModel>;
|
|
96
95
|
/**
|
|
97
96
|
* An interface to read from the database within Convex query functions.
|
|
98
97
|
*
|
|
@@ -100,7 +99,7 @@ type ActionCtx = GenericActionCtx<DataModel>;
|
|
|
100
99
|
* document by its {@link Id}, or {@link DatabaseReader.query}, which starts
|
|
101
100
|
* building a query.
|
|
102
101
|
*/
|
|
103
|
-
type DatabaseReader = GenericDatabaseReader<DataModel>;
|
|
102
|
+
export type DatabaseReader = GenericDatabaseReader<DataModel>;
|
|
104
103
|
/**
|
|
105
104
|
* An interface to read from and write to the database within Convex mutation
|
|
106
105
|
* functions.
|
|
@@ -110,7 +109,5 @@ type DatabaseReader = GenericDatabaseReader<DataModel>;
|
|
|
110
109
|
* your data in an inconsistent state. See [the Convex Guide](https://docs.convex.dev/understanding/convex-fundamentals/functions#atomicity-and-optimistic-concurrency-control)
|
|
111
110
|
* for the guarantees Convex provides your functions.
|
|
112
111
|
*/
|
|
113
|
-
type DatabaseWriter = GenericDatabaseWriter<DataModel>;
|
|
114
|
-
//#endregion
|
|
115
|
-
export { ActionCtx, DatabaseReader, DatabaseWriter, MutationCtx, QueryCtx, action, httpAction, internalAction, internalMutation, internalQuery, mutation, query };
|
|
112
|
+
export type DatabaseWriter = GenericDatabaseWriter<DataModel>;
|
|
116
113
|
//# sourceMappingURL=server.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.mjs","names":[],"sources":["../../../../src/components/foundation/_generated/server.ts"],"sourcesContent":["/* eslint-disable */\n/**\n * Generated utilities for implementing server-side Convex query and mutation functions.\n *\n * THIS CODE IS AUTOMATICALLY GENERATED.\n *\n * To regenerate, run `npx convex dev`.\n * @module\n */\n\nimport type {\n ActionBuilder,\n HttpActionBuilder,\n MutationBuilder,\n QueryBuilder,\n GenericActionCtx,\n GenericMutationCtx,\n GenericQueryCtx,\n GenericDatabaseReader,\n GenericDatabaseWriter,\n} from \"convex/server\";\nimport {\n actionGeneric,\n httpActionGeneric,\n queryGeneric,\n mutationGeneric,\n internalActionGeneric,\n internalMutationGeneric,\n internalQueryGeneric,\n} from \"convex/server\";\nimport type { DataModel } from \"./dataModel.js\";\n\n/**\n * Define a query in this Convex app's public API.\n *\n * This function will be allowed to read your Convex database and will be accessible from the client.\n *\n * @param func - The query function. It receives a {@link QueryCtx} as its first argument.\n * @returns The wrapped query. Include this as an `export` to name it and make it accessible.\n */\nexport const query: QueryBuilder<DataModel, \"public\"> = queryGeneric;\n\n/**\n * Define a query that is only accessible from other Convex functions (but not from the client).\n *\n * This function will be allowed to read from your Convex database. It will not be accessible from the client.\n *\n * @param func - The query function. It receives a {@link QueryCtx} as its first argument.\n * @returns The wrapped query. Include this as an `export` to name it and make it accessible.\n */\nexport const internalQuery: QueryBuilder<DataModel, \"internal\"> =\n internalQueryGeneric;\n\n/**\n * Define a mutation in this Convex app's public API.\n *\n * This function will be allowed to modify your Convex database and will be accessible from the client.\n *\n * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.\n * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.\n */\nexport const mutation: MutationBuilder<DataModel, \"public\"> = mutationGeneric;\n\n/**\n * Define a mutation that is only accessible from other Convex functions (but not from the client).\n *\n * This function will be allowed to modify your Convex database. It will not be accessible from the client.\n *\n * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.\n * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.\n */\nexport const internalMutation: MutationBuilder<DataModel, \"internal\"> =\n internalMutationGeneric;\n\n/**\n * Define an action in this Convex app's public API.\n *\n * An action is a function which can execute any JavaScript code, including non-deterministic\n * code and code with side-effects, like calling third-party services.\n * They can be run in Convex's JavaScript environment or in Node.js using the \"use node\" directive.\n * They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.\n *\n * @param func - The action. It receives an {@link ActionCtx} as its first argument.\n * @returns The wrapped action. Include this as an `export` to name it and make it accessible.\n */\nexport const action: ActionBuilder<DataModel, \"public\"> = actionGeneric;\n\n/**\n * Define an action that is only accessible from other Convex functions (but not from the client).\n *\n * @param func - The function. It receives an {@link ActionCtx} as its first argument.\n * @returns The wrapped function. Include this as an `export` to name it and make it accessible.\n */\nexport const internalAction: ActionBuilder<DataModel, \"internal\"> =\n internalActionGeneric;\n\n/**\n * Define an HTTP action.\n *\n * The wrapped function will be used to respond to HTTP requests received\n * by a Convex deployment if the requests matches the path and method where\n * this action is routed. Be sure to route your httpAction in `convex/http.js`.\n *\n * @param func - The function. It receives an {@link ActionCtx} as its first argument\n * and a Fetch API `Request` object as its second.\n * @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.\n */\nexport const httpAction: HttpActionBuilder = httpActionGeneric;\n\n/**\n * A set of services for use within Convex query functions.\n *\n * The query context is passed as the first argument to any Convex query\n * function run on the server.\n *\n * If you're using code generation, use the `QueryCtx` type in `convex/_generated/server.d.ts` instead.\n */\nexport type QueryCtx = GenericQueryCtx<DataModel>;\n\n/**\n * A set of services for use within Convex mutation functions.\n *\n * The mutation context is passed as the first argument to any Convex mutation\n * function run on the server.\n *\n * If you're using code generation, use the `MutationCtx` type in `convex/_generated/server.d.ts` instead.\n */\nexport type MutationCtx = GenericMutationCtx<DataModel>;\n\n/**\n * A set of services for use within Convex action functions.\n *\n * The action context is passed as the first argument to any Convex action\n * function run on the server.\n */\nexport type ActionCtx = GenericActionCtx<DataModel>;\n\n/**\n * An interface to read from the database within Convex query functions.\n *\n * The two entry points are {@link DatabaseReader.get}, which fetches a single\n * document by its {@link Id}, or {@link DatabaseReader.query}, which starts\n * building a query.\n */\nexport type DatabaseReader = GenericDatabaseReader<DataModel>;\n\n/**\n * An interface to read from and write to the database within Convex mutation\n * functions.\n *\n * Convex guarantees that all writes within a single mutation are\n * executed atomically, so you never have to worry about partial writes leaving\n * your data in an inconsistent state. See [the Convex Guide](https://docs.convex.dev/understanding/convex-fundamentals/functions#atomicity-and-optimistic-concurrency-control)\n * for the guarantees Convex provides your functions.\n */\nexport type DatabaseWriter = GenericDatabaseWriter<DataModel>;\n"],"mappings":"8LAwCA,
|
|
1
|
+
{"version":3,"file":"server.mjs","names":["query","queryGeneric","internalQuery","internalQueryGeneric","mutation","mutationGeneric","internalMutation","internalMutationGeneric","action","actionGeneric","internalAction","internalActionGeneric","httpAction","httpActionGeneric"],"sources":["../../../../src/components/foundation/_generated/server.ts"],"sourcesContent":["/* eslint-disable */\n/**\n * Generated utilities for implementing server-side Convex query and mutation functions.\n *\n * THIS CODE IS AUTOMATICALLY GENERATED.\n *\n * To regenerate, run `npx convex dev`.\n * @module\n */\n\nimport type {\n ActionBuilder,\n HttpActionBuilder,\n MutationBuilder,\n QueryBuilder,\n GenericActionCtx,\n GenericMutationCtx,\n GenericQueryCtx,\n GenericDatabaseReader,\n GenericDatabaseWriter,\n} from \"convex/server\";\nimport {\n actionGeneric,\n httpActionGeneric,\n queryGeneric,\n mutationGeneric,\n internalActionGeneric,\n internalMutationGeneric,\n internalQueryGeneric,\n} from \"convex/server\";\nimport type { DataModel } from \"./dataModel.js\";\n\n/**\n * Define a query in this Convex app's public API.\n *\n * This function will be allowed to read your Convex database and will be accessible from the client.\n *\n * @param func - The query function. It receives a {@link QueryCtx} as its first argument.\n * @returns The wrapped query. Include this as an `export` to name it and make it accessible.\n */\nexport const query: QueryBuilder<DataModel, \"public\"> = queryGeneric;\n\n/**\n * Define a query that is only accessible from other Convex functions (but not from the client).\n *\n * This function will be allowed to read from your Convex database. It will not be accessible from the client.\n *\n * @param func - The query function. It receives a {@link QueryCtx} as its first argument.\n * @returns The wrapped query. Include this as an `export` to name it and make it accessible.\n */\nexport const internalQuery: QueryBuilder<DataModel, \"internal\"> =\n internalQueryGeneric;\n\n/**\n * Define a mutation in this Convex app's public API.\n *\n * This function will be allowed to modify your Convex database and will be accessible from the client.\n *\n * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.\n * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.\n */\nexport const mutation: MutationBuilder<DataModel, \"public\"> = mutationGeneric;\n\n/**\n * Define a mutation that is only accessible from other Convex functions (but not from the client).\n *\n * This function will be allowed to modify your Convex database. It will not be accessible from the client.\n *\n * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.\n * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.\n */\nexport const internalMutation: MutationBuilder<DataModel, \"internal\"> =\n internalMutationGeneric;\n\n/**\n * Define an action in this Convex app's public API.\n *\n * An action is a function which can execute any JavaScript code, including non-deterministic\n * code and code with side-effects, like calling third-party services.\n * They can be run in Convex's JavaScript environment or in Node.js using the \"use node\" directive.\n * They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.\n *\n * @param func - The action. It receives an {@link ActionCtx} as its first argument.\n * @returns The wrapped action. Include this as an `export` to name it and make it accessible.\n */\nexport const action: ActionBuilder<DataModel, \"public\"> = actionGeneric;\n\n/**\n * Define an action that is only accessible from other Convex functions (but not from the client).\n *\n * @param func - The function. It receives an {@link ActionCtx} as its first argument.\n * @returns The wrapped function. Include this as an `export` to name it and make it accessible.\n */\nexport const internalAction: ActionBuilder<DataModel, \"internal\"> =\n internalActionGeneric;\n\n/**\n * Define an HTTP action.\n *\n * The wrapped function will be used to respond to HTTP requests received\n * by a Convex deployment if the requests matches the path and method where\n * this action is routed. Be sure to route your httpAction in `convex/http.js`.\n *\n * @param func - The function. It receives an {@link ActionCtx} as its first argument\n * and a Fetch API `Request` object as its second.\n * @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.\n */\nexport const httpAction: HttpActionBuilder = httpActionGeneric;\n\n/**\n * A set of services for use within Convex query functions.\n *\n * The query context is passed as the first argument to any Convex query\n * function run on the server.\n *\n * If you're using code generation, use the `QueryCtx` type in `convex/_generated/server.d.ts` instead.\n */\nexport type QueryCtx = GenericQueryCtx<DataModel>;\n\n/**\n * A set of services for use within Convex mutation functions.\n *\n * The mutation context is passed as the first argument to any Convex mutation\n * function run on the server.\n *\n * If you're using code generation, use the `MutationCtx` type in `convex/_generated/server.d.ts` instead.\n */\nexport type MutationCtx = GenericMutationCtx<DataModel>;\n\n/**\n * A set of services for use within Convex action functions.\n *\n * The action context is passed as the first argument to any Convex action\n * function run on the server.\n */\nexport type ActionCtx = GenericActionCtx<DataModel>;\n\n/**\n * An interface to read from the database within Convex query functions.\n *\n * The two entry points are {@link DatabaseReader.get}, which fetches a single\n * document by its {@link Id}, or {@link DatabaseReader.query}, which starts\n * building a query.\n */\nexport type DatabaseReader = GenericDatabaseReader<DataModel>;\n\n/**\n * An interface to read from and write to the database within Convex mutation\n * functions.\n *\n * Convex guarantees that all writes within a single mutation are\n * executed atomically, so you never have to worry about partial writes leaving\n * your data in an inconsistent state. See [the Convex Guide](https://docs.convex.dev/understanding/convex-fundamentals/functions#atomicity-and-optimistic-concurrency-control)\n * for the guarantees Convex provides your functions.\n */\nexport type DatabaseWriter = GenericDatabaseWriter<DataModel>;\n"],"mappings":"A,8LAwCA,MAAaA,EAA2CC,EAU3CC,EACXC,EAUWC,EAAiDC,EAUjDC,EACXC,EAaWC,EAA6CC,EAQ7CC,EACXC,EAaWC,EAAgCC,E"}
|