cvx-kit 0.1.8 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +28 -28
- package/dist/agent-tools.d.mts +5 -5
- package/dist/agent-tools.mjs.map +1 -1
- package/dist/auth.d.mts +39 -289
- package/dist/auth.mjs.map +1 -1
- package/dist/components/approvals/_generated/api.d.mts +3 -4
- package/dist/components/approvals/_generated/api.mjs.map +1 -1
- package/dist/components/approvals/_generated/component.d.mts +1 -2
- package/dist/components/approvals/_generated/dataModel.d.mts +4 -5
- package/dist/components/approvals/_generated/server.d.mts +12 -13
- package/dist/components/approvals/_generated/server.mjs.map +1 -1
- package/dist/components/approvals/audit.d.mts +8 -8
- package/dist/components/approvals/audit.mjs +1 -1
- package/dist/components/approvals/audit.mjs.map +1 -1
- package/dist/components/approvals/client.d.mts +10 -10
- package/dist/components/approvals/client.mjs.map +1 -1
- package/dist/components/approvals/constants.d.mts +30 -30
- package/dist/components/approvals/constants.mjs.map +1 -1
- package/dist/components/approvals/convex.config.mjs.map +1 -1
- package/dist/components/approvals/decisions.d.mts +6 -6
- package/dist/components/approvals/decisions.mjs.map +1 -1
- package/dist/components/approvals/functions.d.mts +3 -3
- package/dist/components/approvals/functions.mjs.map +1 -1
- package/dist/components/approvals/health.d.mts +2 -2
- package/dist/components/approvals/health.mjs.map +1 -1
- package/dist/components/approvals/requests.d.mts +8 -8
- package/dist/components/approvals/requests.mjs.map +1 -1
- package/dist/components/approvals/validators.d.mts +29 -29
- package/dist/components/approvals/validators.mjs +1 -1
- package/dist/components/approvals/validators.mjs.map +1 -1
- package/dist/components/approvals/workflow.d.mts +3 -3
- package/dist/components/approvals/workflow.mjs.map +1 -1
- package/dist/components/approvals/workflow_steps.d.mts +15 -15
- package/dist/components/approvals/workflow_steps.mjs.map +1 -1
- package/dist/components/foundation/_generated/api.d.mts +3 -4
- package/dist/components/foundation/_generated/api.mjs.map +1 -1
- package/dist/components/foundation/_generated/component.d.mts +1 -2
- package/dist/components/foundation/_generated/dataModel.d.mts +4 -5
- package/dist/components/foundation/_generated/server.d.mts +12 -13
- package/dist/components/foundation/_generated/server.mjs.map +1 -1
- package/dist/components/foundation/client.d.mts +13 -13
- package/dist/components/foundation/client.mjs.map +1 -1
- package/dist/components/foundation/convex.config.mjs.map +1 -1
- package/dist/components/foundation/functions.d.mts +2 -2
- package/dist/components/foundation/functions.mjs.map +1 -1
- package/dist/components/foundation/modules/command/command.d.mts +14 -14
- package/dist/components/foundation/modules/command/command.mjs.map +1 -1
- package/dist/components/foundation/modules/command/lifecycle.d.mts +12 -13
- package/dist/components/foundation/modules/command/lifecycle.mjs.map +1 -1
- package/dist/components/foundation/modules/observability/observability.d.mts +4 -4
- package/dist/components/foundation/modules/observability/observability.mjs.map +1 -1
- package/dist/components/foundation/modules/query/query.d.mts +5 -5
- package/dist/components/foundation/modules/query/query.mjs.map +1 -1
- package/dist/components/foundation/operation.d.mts +5 -6
- package/dist/components/foundation/operation.mjs.map +1 -1
- package/dist/components/foundation/result.d.mts +6 -6
- package/dist/components/foundation/result.mjs.map +1 -1
- package/dist/components/foundation/telemetry.d.mts +2 -2
- package/dist/components/foundation/telemetry.mjs.map +1 -1
- package/dist/crud.d.mts +6 -5
- package/dist/crud.mjs.map +1 -1
- package/dist/errors.d.mts +4 -4
- package/dist/errors.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/middleware.d.mts +2 -3
- package/dist/middleware.mjs.map +1 -1
- package/dist/modules/contracts/contract.d.mts +12 -13
- package/dist/modules/contracts/contract.mjs.map +1 -1
- package/dist/modules/contracts/convex.d.mts +3 -5
- package/dist/modules/contracts/convex.mjs.map +1 -1
- package/dist/modules/contracts/errors.d.mts +8 -9
- package/dist/modules/contracts/errors.mjs +1 -1
- package/dist/modules/contracts/errors.mjs.map +1 -1
- package/dist/modules/contracts/exposure.d.mts +13 -14
- package/dist/modules/contracts/exposure.mjs +1 -1
- package/dist/modules/contracts/exposure.mjs.map +1 -1
- package/dist/modules/contracts/idempotency.d.mts +15 -16
- package/dist/modules/contracts/idempotency.mjs +1 -1
- package/dist/modules/contracts/idempotency.mjs.map +1 -1
- package/dist/modules/contracts/standard.d.mts +2 -3
- package/dist/modules/contracts/standard.mjs.map +1 -1
- package/dist/modules/contracts/workflow.d.mts +26 -27
- package/dist/modules/contracts/workflow.mjs.map +1 -1
- package/dist/modules/effect/api-runtime.d.mts +10 -11
- package/dist/modules/effect/api-runtime.mjs.map +1 -1
- package/dist/modules/effect/api-zod.d.mts +2 -3
- package/dist/modules/effect/api-zod.mjs.map +1 -1
- package/dist/modules/effect/api.d.mts +4 -5
- package/dist/modules/effect/api.mjs.map +1 -1
- package/dist/modules/effect/command.d.mts +4 -5
- package/dist/modules/effect/command.mjs.map +1 -1
- package/dist/modules/effect/crud.d.mts +7 -8
- package/dist/modules/effect/crud.mjs.map +1 -1
- package/dist/modules/effect/errors.d.mts +1 -2
- package/dist/modules/effect/errors.mjs.map +1 -1
- package/dist/modules/effect/foundation.d.mts +3 -4
- package/dist/modules/effect/foundation.mjs.map +1 -1
- package/dist/modules/effect/idempotency.d.mts +2 -3
- package/dist/modules/effect/idempotency.mjs.map +1 -1
- package/dist/modules/effect/normalize.d.mts +2 -3
- package/dist/modules/effect/normalize.mjs.map +1 -1
- package/dist/modules/effect/operation.d.mts +17 -18
- package/dist/modules/effect/operation.mjs.map +1 -1
- package/dist/modules/effect/query.d.mts +3 -4
- package/dist/modules/effect/query.mjs.map +1 -1
- package/dist/modules/effect/schema.d.mts +8 -9
- package/dist/modules/effect/schema.mjs.map +1 -1
- package/dist/modules/effect/workflow.d.mts +5 -6
- package/dist/modules/effect/workflow.mjs.map +1 -1
- package/dist/oxlint/architecture.d.mts +6 -7
- package/dist/oxlint/architecture.mjs +1 -1
- package/dist/oxlint/architecture.mjs.map +1 -1
- package/dist/oxlint/ast.d.mts +22 -23
- package/dist/oxlint/ast.mjs +1 -1
- package/dist/oxlint/ast.mjs.map +1 -1
- package/dist/oxlint/ownership.d.mts +2 -3
- package/dist/oxlint/ownership.mjs +1 -1
- package/dist/oxlint/ownership.mjs.map +1 -1
- package/dist/oxlint.d.mts +4 -4
- package/dist/oxlint.mjs +1 -1
- package/dist/oxlint.mjs.map +1 -1
- package/dist/state-machine.d.mts +1 -2
- package/dist/state-machine.mjs.map +1 -1
- package/dist/tenancy.d.mts +6 -6
- package/dist/tenancy.mjs.map +1 -1
- package/dist/triggers.d.mts +6 -6
- package/dist/triggers.mjs.map +1 -1
- package/dist/webhooks.d.mts +5 -6
- package/dist/webhooks.mjs.map +1 -1
- package/dist/zod-table.d.mts +10 -10
- package/dist/zod-table.mjs.map +1 -1
- package/docs/oxlint.md +1 -1
- package/docs/upgrading.md +9 -1
- package/docs/zod-table.md +1 -1
- package/package.json +21 -15
- package/scripts/test-packed-auth.mjs +68 -0
- package/scripts/test-packed-effect.mjs +1 -1
- package/scripts/test-packed-ids.mjs +2 -2
- package/dist/node_modules/@standard-schema/spec/dist/index.d.mts +0 -79
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{APPROVAL_CALLBACK_KINDS as e,APPROVAL_DECISIONS as t,APPROVAL_QUORUM_KINDS as n,APPROVAL_RUN_STATES as r,APPROVAL_STEP_KINDS as i}from"./constants.mjs";import{zid as a,zodToConvex as o}from"convex-helpers/server/zod4";import{z as s}from"zod";const c=s.enum(r),l=s.enum(t),u=s.enum(i),d=s.enum(e),f=s.enum(n),p=s.string().trim().min(1).max(256),m=s.string().trim().min(1).max(96).regex(/^[A-Za-z][A-Za-z0-9._-]*$/),h=s.string().trim().min(1).max(500),g=s.record(s.string().min(1).max(64).regex(/^(?![$_])[\x20-\x7E]+$/),s.string().max(512)).refine(e=>Object.keys(e).length<=32,`Metadata may contain at most 32 entries`),_=s.object({stepKey:m,actorRef:p,decision:l,reason:h.optional(),decidedAt:s.number()}).strict(),v=_.omit({stepKey:!0}),y=s.object({runId:p,scopeRef:p,resourceType:m,resourceRef:p,metadata:g.optional(),decision:s.object({stepKey:m,outcome:s.union([l,s.literal(`expired`)]),evidence:s.array(_),terminalEvidence:v.optional()}).strict().optional()}).strict(),b=o(y),x=s.object({actorRef:p,capabilities:s.array(m).max(32),metadata:g.optional()}).strict(),S=s.object({kind:s.literal(`mutation`),handle:p,retry:s.boolean()}).strict(),C=s.object({kind:s.literal(`action`),handle:p,retry:s.boolean()}).strict(),w=s.discriminatedUnion(`kind`,[S,C]),T=s.object({kind:f,approvals:s.number().int().positive().max(8)}).strict(),E=s.discriminatedUnion(`kind`,[s.object({kind:s.literal(`mutation`),key:m,callback:S}).strict(),s.object({kind:s.literal(`action`),key:m,callback:C}).strict()]),D=s.object({kind:s.literal(`notify`),key:m,callback:C}).strict(),O=s.object({kind:s.literal(`decision`),key:m,decisions:s.array(l).min(1).max(8),quorum:T,makerChecker:s.boolean(),expiresAfterMs:s.number().int().positive().optional()}).strict(),k=s.object({kind:s.literal(`branch`),key:m,approvedStepKey:m,rejectedStepKey:m}).strict(),A=s.discriminatedUnion(`kind`,[E,D,O,k]),j=s.object({schemaVersion:s.literal(1),compatibilityKey:m,name:m,steps:s.array(A).min(1).max(32)}).strict().superRefine((e,t)=>{let n
|
|
1
|
+
import{APPROVAL_CALLBACK_KINDS as e,APPROVAL_DECISIONS as t,APPROVAL_QUORUM_KINDS as n,APPROVAL_RUN_STATES as r,APPROVAL_STEP_KINDS as i}from"./constants.mjs";import{zid as a,zodToConvex as o}from"convex-helpers/server/zod4";import{z as s}from"zod";const c=s.enum(r),l=s.enum(t),u=s.enum(i),d=s.enum(e),f=s.enum(n),p=s.string().trim().min(1).max(256),m=s.string().trim().min(1).max(96).regex(/^[A-Za-z][A-Za-z0-9._-]*$/),h=s.string().trim().min(1).max(500),g=s.record(s.string().min(1).max(64).regex(/^(?![$_])[\x20-\x7E]+$/),s.string().max(512)).refine(e=>Object.keys(e).length<=32,`Metadata may contain at most 32 entries`),_=s.object({stepKey:m,actorRef:p,decision:l,reason:h.optional(),decidedAt:s.number()}).strict(),v=_.omit({stepKey:!0}),y=s.object({runId:p,scopeRef:p,resourceType:m,resourceRef:p,metadata:g.optional(),decision:s.object({stepKey:m,outcome:s.union([l,s.literal(`expired`)]),evidence:s.array(_),terminalEvidence:v.optional()}).strict().optional()}).strict(),b=o(y),x=s.object({actorRef:p,capabilities:s.array(m).max(32),metadata:g.optional()}).strict(),S=s.object({kind:s.literal(`mutation`),handle:p,retry:s.boolean()}).strict(),C=s.object({kind:s.literal(`action`),handle:p,retry:s.boolean()}).strict(),w=s.discriminatedUnion(`kind`,[S,C]),T=s.object({kind:f,approvals:s.number().int().positive().max(8)}).strict(),E=s.discriminatedUnion(`kind`,[s.object({kind:s.literal(`mutation`),key:m,callback:S}).strict(),s.object({kind:s.literal(`action`),key:m,callback:C}).strict()]),D=s.object({kind:s.literal(`notify`),key:m,callback:C}).strict(),O=s.object({kind:s.literal(`decision`),key:m,decisions:s.array(l).min(1).max(8),quorum:T,makerChecker:s.boolean(),expiresAfterMs:s.number().int().positive().optional()}).strict(),k=s.object({kind:s.literal(`branch`),key:m,approvedStepKey:m,rejectedStepKey:m}).strict(),A=s.discriminatedUnion(`kind`,[E,D,O,k]),j=s.object({schemaVersion:s.literal(1),compatibilityKey:m,name:m,steps:s.array(A).min(1).max(32)}).strict().superRefine((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({code:`custom`,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({code:`custom`,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({code:`custom`,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({code:`custom`,message:`Branch target must be a callback step: ${o}`,path:[`steps`,n]}):s<=n&&t.addIssue({code:`custom`,message:`Branch target must be declared after its branch: ${o}`,path:[`steps`,n]}):t.addIssue({code:`custom`,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({code:`custom`,message:`Branch callback must belong to exactly one branch: ${e}`,path:[`steps`]})}),M=s.object({scopeRef:p,resourceType:m,resourceRef:p,requester:x,metadata:g.optional(),workflow:j,state:c,currentStepKey:m.optional(),executionFailedStepKey:m.optional(),expiresAt:s.number().optional(),workflowId:p.optional(),createdAt:s.number(),updatedAt:s.number(),terminalAt:s.number().optional()}).strict(),N=s.object({runId:a(`approvalRuns`),stepKey:m,actor:x,decision:l,reason:h.optional(),decidedAt:s.number()}).strict();export{C as approvalActionCallback,x as approvalActor,k as approvalBranchStep,w as approvalCallback,b as approvalCallbackArgs,y as approvalCallbackInput,d as approvalCallbackKind,E as approvalCallbackStep,l as approvalDecision,N as approvalDecisionDocument,O as approvalDecisionStep,g as approvalMetadata,S as approvalMutationCallback,m as approvalName,D as approvalNotifyStep,T as approvalQuorum,f as approvalQuorumKind,h as approvalReason,p as approvalReference,M as approvalRunDocument,c as approvalRunState,u as approvalStepKind,j as approvalWorkflowDescriptor,A 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.string().trim().min(1).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.string().trim().min(1).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.array(approvalDecision).min(1).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.array(approvalWorkflowStep).min(1).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(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\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 (step.kind === 'decision' && new Set(step.decisions).size !== step.decisions.length)\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((candidate) => candidate.key === target)\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(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\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<typeof approvalWorkflowDescriptor>\nexport type ApprovalActor = z.infer<typeof approvalActor>\nexport type ApprovalMetadata = z.infer<typeof approvalMetadata>\nexport type ApprovalCallbackInput = Readonly<z.infer<typeof approvalCallbackInput>>\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,EAAE,OAAO,CAAC,CAAC,KAAK,C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AAS,0CAA0C,IACnD,KAAM,CAAC,QAAS,CAAK,CACtB,CAAC,EACO,GAAe,GACvB,EAAQ,SAAS,CAChB,KAAM,SACN,QAAS,oDAAoD,IAC7D,KAAM,CAAC,QAAS,CAAK,CACtB,CAAC,EApBD,EAAQ,SAAS,CAChB,KAAM,SACN,QAAS,0BAA0B,IACnC,KAAM,CAAC,QAAS,CAAK,CACtB,CAAC,EAiBF,EAAmB,IAAI,GAAS,EAAmB,IAAI,CAAM,GAAK,GAAK,CAAC,CACzE,CA3BE,CA6BH,IAAK,GAAM,CAAC,EAAQ,KAAW,EAC1B,IAAW,GACd,EAAQ,SAAS,CAChB,KAAM,SACN,QAAS,sDAAsD,IAC/D,KAAM,CAAC,OAAO,CACf,CAAC,CAEJ,CAAC,EAEW,EAAsB,EACjC,OAAO,CACP,SAAU,EACV,aAAc,EACd,YAAa,EACb,UAAW,EACX,SAAU,EAAiB,SAAS,EACpC,SAAU,EACV,MAAO,EACP,eAAgB,EAAa,SAAS,EACtC,uBAAwB,EAAa,SAAS,EAC9C,UAAW,EAAE,OAAO,CAAC,CAAC,SAAS,EAC/B,WAAY,EAAkB,SAAS,EACvC,UAAW,EAAE,OAAO,EACpB,UAAW,EAAE,OAAO,EACpB,WAAY,EAAE,OAAO,CAAC,CAAC,SAAS,CACjC,CAAC,CAAC,CACD,OAAO,EAEI,EAA2B,EACtC,OAAO,CACP,MAAO,EAAI,cAAc,EACzB,QAAS,EACT,MAAO,EACP,SAAU,EACV,OAAQ,EAAe,SAAS,EAChC,UAAW,EAAE,OAAO,CACrB,CAAC,CAAC,CACD,OAAO"}
|
|
1
|
+
{"version":3,"file":"validators.mjs","names":["approvalRunState","z","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","zodToConvex","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","zid"],"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.string().trim().min(1).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.string().trim().min(1).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.array(approvalDecision).min(1).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.array(approvalWorkflowStep).min(1).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(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\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 (step.kind === 'decision' && new Set(step.decisions).size !== step.decisions.length)\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((candidate) => candidate.key === target)\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(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\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<typeof approvalWorkflowDescriptor>\nexport type ApprovalActor = z.infer<typeof approvalActor>\nexport type ApprovalMetadata = z.infer<typeof approvalMetadata>\nexport type ApprovalCallbackInput = Readonly<z.infer<typeof approvalCallbackInput>>\n"],"mappings":"yPAqBA,MAAaA,EAAmBC,EAAE,KAAKC,CAAmB,EAC7CC,EAAmBF,EAAE,KAAKG,CAAkB,EAC5CC,EAAmBJ,EAAE,KAAKK,CAAmB,EAC7CC,EAAuBN,EAAE,KAAKO,CAAuB,EACrDC,EAAqBR,EAAE,KAAKS,CAAqB,EAEjDC,EAAoBV,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,GAAiC,EAE9EW,EAAeX,EAC1B,OAAO,CAAC,CACR,KAAK,CAAC,CACN,IAAI,CAAC,CAAC,CACN,IAAA,EAA4B,CAAC,CAC7B,MAAM,2BAA2B,EAEtBY,EAAiBZ,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,GAA8B,EAExEa,EAAmBb,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,KAAKc,CAAK,CAAC,CAAC,QAAA,GAC9B,yCACD,EAEKC,EAA2Bf,EAC/B,OAAO,CACP,QAASW,EACT,SAAUD,EACV,SAAUR,EACV,OAAQU,EAAe,SAAS,EAChC,UAAWZ,EAAE,OAAO,CACrB,CAAC,CAAC,CACD,OAAO,EAEHgB,EAAmCD,EAAyB,KAAK,CACtE,QAAS,EACV,CAAC,EAEYE,EAAwBjB,EACnC,OAAO,CACP,MAAOU,EACP,SAAUA,EACV,aAAcC,E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AAWU,EACX,SAAUP,EAAiB,SAAS,EACpC,SAAUiB,EACV,MAAO/B,EACP,eAAgBY,EAAa,SAAS,EACtC,uBAAwBA,EAAa,SAAS,EAC9C,UAAWX,EAAE,OAAO,CAAC,CAAC,SAAS,EAC/B,WAAYU,EAAkB,SAAS,EACvC,UAAWV,EAAE,OAAO,EACpB,UAAWA,EAAE,OAAO,EACpB,WAAYA,EAAE,OAAO,CAAC,CAAC,SAAS,CACjC,CAAC,CAAC,CACD,OAAO,EAEI4C,EAA2B5C,EACtC,OAAO,CACP,MAAO6C,EAAI,cAAc,EACzB,QAASlC,EACT,MAAOS,EACP,SAAUlB,EACV,OAAQU,EAAe,SAAS,EAChC,UAAWZ,EAAE,OAAO,CACrB,CAAC,CAAC,CACD,OAAO"}
|
|
@@ -2,10 +2,10 @@ 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
8
|
}>, import("@convex-dev/workflow").WorkflowMutationResult<null>>;
|
|
9
9
|
//#endregion
|
|
10
|
-
export {
|
|
10
|
+
export { workflow_d_exports };
|
|
11
11
|
//# sourceMappingURL=workflow.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.mjs","names":[],"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":"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,eA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B,EAAiD,CAC5E,MAAO,CACN,MAAO,EAAI,IACX,SAAU,EAAI,SACd,aAAc,EAAI,aAClB,YAAa,EAAI,YACjB,SAAU,EAAI,QACf,CACD,CAEA,eAAe,EACd,EACA,EACA,EACgB,CAChB,GAAI,EAAa,SAAS,OAAS,WAAY,CAC9C,MAAM,EAAK,YAAY,EAA8B,EAAa,SAAS,MAAM,EAAG,EAAO,CAC1F,KAAM,EAAa,GACpB,CAAC,EACD,MACD,CACA,MAAM,EAAK,UAAU,EAA4B,EAAa,SAAS,MAAM,EAAG,EAAO,CACtF,KAAM,EAAa,IACnB,MAAO,EAAa,SAAS,KAC9B,CAAC,CACF"}
|
|
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":"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,KA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AAMI,EAAa,GACpB,CAAC,EACD,MACD,CACA,MAAMN,EAAK,UAAUuB,EAA4BjB,EAAa,SAAS,MAAM,EAAGJ,EAAO,CACtF,KAAMI,EAAa,IACnB,MAAOA,EAAa,SAAS,KAC9B,CAAC,CACF"}
|
|
@@ -4,25 +4,25 @@ import { FunctionReference, FunctionType } from "convex/server";
|
|
|
4
4
|
declare namespace workflow_steps_d_exports {
|
|
5
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,28 @@ 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>>;
|
|
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
58
|
//#endregion
|
|
59
|
-
export {
|
|
59
|
+
export { workflow_steps_d_exports };
|
|
60
60
|
//# sourceMappingURL=workflow_steps.d.mts.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\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":"mHAyEA,
|
|
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":"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"}
|
|
@@ -24,7 +24,7 @@ declare const fullApi: ApiFromModules<{
|
|
|
24
24
|
* const myFunctionReference = api.myModule.myFunction;
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
|
-
declare const api: FilterApi<typeof fullApi, FunctionReference<any, "public">>;
|
|
27
|
+
export declare const api: FilterApi<typeof fullApi, FunctionReference<any, "public">>;
|
|
28
28
|
/**
|
|
29
29
|
* A utility for referencing Convex functions in your app's internal API.
|
|
30
30
|
*
|
|
@@ -33,8 +33,7 @@ declare const api: FilterApi<typeof fullApi, FunctionReference<any, "public">>;
|
|
|
33
33
|
* const myFunctionReference = internal.myModule.myFunction;
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
|
-
declare const internal: FilterApi<typeof fullApi, FunctionReference<any, "internal">>;
|
|
37
|
-
declare const components: {};
|
|
36
|
+
export declare const internal: FilterApi<typeof fullApi, FunctionReference<any, "internal">>;
|
|
37
|
+
export declare const components: {};
|
|
38
38
|
//#endregion
|
|
39
|
-
export { api, components, internal };
|
|
40
39
|
//# 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":"8DA2CA,MAAaA,EAGTC,EAUSC,EAGTD,EAESE,EAAaC,EAAkB"}
|
|
@@ -11,11 +11,10 @@ import { FunctionReference } from "convex/server";
|
|
|
11
11
|
* }
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
|
-
type ComponentApi<Name extends string | undefined = string | undefined> = {
|
|
14
|
+
export type ComponentApi<Name extends string | undefined = string | undefined> = {
|
|
15
15
|
functions: {
|
|
16
16
|
status: FunctionReference<"query", "internal", {}, "ready", Name>;
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
19
|
//#endregion
|
|
20
|
-
export { ComponentApi };
|
|
21
20
|
//# sourceMappingURL=component.d.mts.map
|
|
@@ -5,13 +5,13 @@ import { GenericId } from "convex/values";
|
|
|
5
5
|
/**
|
|
6
6
|
* The names of all of your Convex tables.
|
|
7
7
|
*/
|
|
8
|
-
type TableNames = TableNamesInDataModel<DataModel>;
|
|
8
|
+
export type TableNames = TableNamesInDataModel<DataModel>;
|
|
9
9
|
/**
|
|
10
10
|
* The type of a document stored in Convex.
|
|
11
11
|
*
|
|
12
12
|
* @typeParam TableName - A string literal type of the table name (like "users").
|
|
13
13
|
*/
|
|
14
|
-
type Doc<TableName extends TableNames> = DocumentByName<DataModel, TableName>;
|
|
14
|
+
export type Doc<TableName extends TableNames> = DocumentByName<DataModel, TableName>;
|
|
15
15
|
/**
|
|
16
16
|
* An identifier for a document in Convex.
|
|
17
17
|
*
|
|
@@ -25,7 +25,7 @@ type Doc<TableName extends TableNames> = DocumentByName<DataModel, TableName>;
|
|
|
25
25
|
*
|
|
26
26
|
* @typeParam TableName - A string literal type of the table name (like "users").
|
|
27
27
|
*/
|
|
28
|
-
type Id<TableName extends TableNames | SystemTableNames> = GenericId<TableName>;
|
|
28
|
+
export type Id<TableName extends TableNames | SystemTableNames> = GenericId<TableName>;
|
|
29
29
|
/**
|
|
30
30
|
* A type describing your Convex data model.
|
|
31
31
|
*
|
|
@@ -35,7 +35,6 @@ type Id<TableName extends TableNames | SystemTableNames> = GenericId<TableName>;
|
|
|
35
35
|
* This type is used to parameterize methods like `queryGeneric` and
|
|
36
36
|
* `mutationGeneric` to make them type-safe.
|
|
37
37
|
*/
|
|
38
|
-
type DataModel = DataModelFromSchemaDefinition<typeof _default>;
|
|
38
|
+
export type DataModel = DataModelFromSchemaDefinition<typeof _default>;
|
|
39
39
|
//#endregion
|
|
40
|
-
export { DataModel, Doc, Id, TableNames };
|
|
41
40
|
//# sourceMappingURL=dataModel.d.mts.map
|
|
@@ -9,7 +9,7 @@ import { ActionBuilder, GenericActionCtx, GenericDatabaseReader, GenericDatabase
|
|
|
9
9
|
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
|
|
10
10
|
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
|
|
11
11
|
*/
|
|
12
|
-
declare const query: QueryBuilder<DataModel, "public">;
|
|
12
|
+
export declare const query: QueryBuilder<DataModel, "public">;
|
|
13
13
|
/**
|
|
14
14
|
* Define a query that is only accessible from other Convex functions (but not from the client).
|
|
15
15
|
*
|
|
@@ -18,7 +18,7 @@ declare const query: QueryBuilder<DataModel, "public">;
|
|
|
18
18
|
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
|
|
19
19
|
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
|
|
20
20
|
*/
|
|
21
|
-
declare const internalQuery: QueryBuilder<DataModel, "internal">;
|
|
21
|
+
export declare const internalQuery: QueryBuilder<DataModel, "internal">;
|
|
22
22
|
/**
|
|
23
23
|
* Define a mutation in this Convex app's public API.
|
|
24
24
|
*
|
|
@@ -27,7 +27,7 @@ declare const internalQuery: QueryBuilder<DataModel, "internal">;
|
|
|
27
27
|
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
|
|
28
28
|
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
|
|
29
29
|
*/
|
|
30
|
-
declare const mutation: MutationBuilder<DataModel, "public">;
|
|
30
|
+
export declare const mutation: MutationBuilder<DataModel, "public">;
|
|
31
31
|
/**
|
|
32
32
|
* Define a mutation that is only accessible from other Convex functions (but not from the client).
|
|
33
33
|
*
|
|
@@ -36,7 +36,7 @@ declare const mutation: MutationBuilder<DataModel, "public">;
|
|
|
36
36
|
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
|
|
37
37
|
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
|
|
38
38
|
*/
|
|
39
|
-
declare const internalMutation: MutationBuilder<DataModel, "internal">;
|
|
39
|
+
export declare const internalMutation: MutationBuilder<DataModel, "internal">;
|
|
40
40
|
/**
|
|
41
41
|
* Define an action in this Convex app's public API.
|
|
42
42
|
*
|
|
@@ -48,14 +48,14 @@ declare const internalMutation: MutationBuilder<DataModel, "internal">;
|
|
|
48
48
|
* @param func - The action. It receives an {@link ActionCtx} as its first argument.
|
|
49
49
|
* @returns The wrapped action. Include this as an `export` to name it and make it accessible.
|
|
50
50
|
*/
|
|
51
|
-
declare const action: ActionBuilder<DataModel, "public">;
|
|
51
|
+
export declare const action: ActionBuilder<DataModel, "public">;
|
|
52
52
|
/**
|
|
53
53
|
* Define an action that is only accessible from other Convex functions (but not from the client).
|
|
54
54
|
*
|
|
55
55
|
* @param func - The function. It receives an {@link ActionCtx} as its first argument.
|
|
56
56
|
* @returns The wrapped function. Include this as an `export` to name it and make it accessible.
|
|
57
57
|
*/
|
|
58
|
-
declare const internalAction: ActionBuilder<DataModel, "internal">;
|
|
58
|
+
export declare const internalAction: ActionBuilder<DataModel, "internal">;
|
|
59
59
|
/**
|
|
60
60
|
* Define an HTTP action.
|
|
61
61
|
*
|
|
@@ -67,7 +67,7 @@ declare const internalAction: ActionBuilder<DataModel, "internal">;
|
|
|
67
67
|
* and a Fetch API `Request` object as its second.
|
|
68
68
|
* @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
|
|
69
69
|
*/
|
|
70
|
-
declare const httpAction: HttpActionBuilder;
|
|
70
|
+
export declare const httpAction: HttpActionBuilder;
|
|
71
71
|
/**
|
|
72
72
|
* A set of services for use within Convex query functions.
|
|
73
73
|
*
|
|
@@ -76,7 +76,7 @@ declare const httpAction: HttpActionBuilder;
|
|
|
76
76
|
*
|
|
77
77
|
* If you're using code generation, use the `QueryCtx` type in `convex/_generated/server.d.ts` instead.
|
|
78
78
|
*/
|
|
79
|
-
type QueryCtx = GenericQueryCtx<DataModel>;
|
|
79
|
+
export type QueryCtx = GenericQueryCtx<DataModel>;
|
|
80
80
|
/**
|
|
81
81
|
* A set of services for use within Convex mutation functions.
|
|
82
82
|
*
|
|
@@ -85,14 +85,14 @@ type QueryCtx = GenericQueryCtx<DataModel>;
|
|
|
85
85
|
*
|
|
86
86
|
* If you're using code generation, use the `MutationCtx` type in `convex/_generated/server.d.ts` instead.
|
|
87
87
|
*/
|
|
88
|
-
type MutationCtx = GenericMutationCtx<DataModel>;
|
|
88
|
+
export type MutationCtx = GenericMutationCtx<DataModel>;
|
|
89
89
|
/**
|
|
90
90
|
* A set of services for use within Convex action functions.
|
|
91
91
|
*
|
|
92
92
|
* The action context is passed as the first argument to any Convex action
|
|
93
93
|
* function run on the server.
|
|
94
94
|
*/
|
|
95
|
-
type ActionCtx = GenericActionCtx<DataModel>;
|
|
95
|
+
export type ActionCtx = GenericActionCtx<DataModel>;
|
|
96
96
|
/**
|
|
97
97
|
* An interface to read from the database within Convex query functions.
|
|
98
98
|
*
|
|
@@ -100,7 +100,7 @@ type ActionCtx = GenericActionCtx<DataModel>;
|
|
|
100
100
|
* document by its {@link Id}, or {@link DatabaseReader.query}, which starts
|
|
101
101
|
* building a query.
|
|
102
102
|
*/
|
|
103
|
-
type DatabaseReader = GenericDatabaseReader<DataModel>;
|
|
103
|
+
export type DatabaseReader = GenericDatabaseReader<DataModel>;
|
|
104
104
|
/**
|
|
105
105
|
* An interface to read from and write to the database within Convex mutation
|
|
106
106
|
* functions.
|
|
@@ -110,7 +110,6 @@ type DatabaseReader = GenericDatabaseReader<DataModel>;
|
|
|
110
110
|
* your data in an inconsistent state. See [the Convex Guide](https://docs.convex.dev/understanding/convex-fundamentals/functions#atomicity-and-optimistic-concurrency-control)
|
|
111
111
|
* for the guarantees Convex provides your functions.
|
|
112
112
|
*/
|
|
113
|
-
type DatabaseWriter = GenericDatabaseWriter<DataModel>;
|
|
113
|
+
export type DatabaseWriter = GenericDatabaseWriter<DataModel>;
|
|
114
114
|
//#endregion
|
|
115
|
-
export { ActionCtx, DatabaseReader, DatabaseWriter, MutationCtx, QueryCtx, action, httpAction, internalAction, internalMutation, internalQuery, mutation, query };
|
|
116
115
|
//# 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":"8LAwCA,MAAaA,EAA2CC,EAU3CC,EACXC,EAUWC,EAAiDC,EAUjDC,EACXC,EAaWC,EAA6CC,EAQ7CC,EACXC,EAaWC,EAAgCC"}
|
|
@@ -10,7 +10,7 @@ declare namespace client_d_exports {
|
|
|
10
10
|
export { AnyCommandMiddleware, AnyQueryMiddleware, ApplicationCommand, AuditEntryInput, AuditWriter, AuditedOperation, AuditedRegistry, CommandArgument, CommandConstructor, CommandDefaults, CommandExecution, CommandHandlerResult, CommandInput, CommandMiddleware, CommandObservation, CommandPreparation, CommandRegistry, CommandResult, Foundation, FoundationOptions, ObservabilityOptions, Parseable, PermissionChecker, QueryExecution, QueryMiddleware, Result, ResultBoundary, SchemaOutput, TransactionMetricsContext, TypedOperation };
|
|
11
11
|
}
|
|
12
12
|
/** Shape handed to the injected audit writer; classification comes from the operation. */
|
|
13
|
-
type AuditEntryInput = {
|
|
13
|
+
export type AuditEntryInput = {
|
|
14
14
|
operation: string;
|
|
15
15
|
actorId: string;
|
|
16
16
|
aggregate: {
|
|
@@ -20,10 +20,10 @@ type AuditEntryInput = {
|
|
|
20
20
|
metadata?: Record<string, Value>;
|
|
21
21
|
classification: string;
|
|
22
22
|
};
|
|
23
|
-
type AuditWriter<Result = unknown> = (context: never, entry: AuditEntryInput) => MaybePromise<Result>;
|
|
23
|
+
export type AuditWriter<Result = unknown> = (context: never, entry: AuditEntryInput) => MaybePromise<Result>;
|
|
24
24
|
type MaybePromise<Value> = Value | Promise<Value>;
|
|
25
25
|
type OperationKey<Operations extends CommandRegistry> = Extract<keyof Operations, string>;
|
|
26
|
-
type AuditedOperation = Readonly<{
|
|
26
|
+
export type AuditedOperation = Readonly<{
|
|
27
27
|
command: CommandSchema;
|
|
28
28
|
result: CommandSchema;
|
|
29
29
|
classification: string;
|
|
@@ -61,7 +61,7 @@ type AuditedOperation = Readonly<{
|
|
|
61
61
|
* transform results, but can never skip authorization, return an invalid
|
|
62
62
|
* result, or desynchronize audit from effects.
|
|
63
63
|
*/
|
|
64
|
-
type CommandMiddleware<Context = never, Extension extends object = object, Input = unknown, Result = unknown> = (input: {
|
|
64
|
+
export type CommandMiddleware<Context = never, Extension extends object = object, Input = unknown, Result = unknown> = (input: {
|
|
65
65
|
operation: string;
|
|
66
66
|
command: Input;
|
|
67
67
|
context: Context;
|
|
@@ -71,7 +71,7 @@ type CommandMiddleware<Context = never, Extension extends object = object, Input
|
|
|
71
71
|
}) => Promise<Result>;
|
|
72
72
|
}) => Promise<Result>;
|
|
73
73
|
/** Any-context middleware — what registries and operations accept. */
|
|
74
|
-
type AnyCommandMiddleware<Input = never, Result = unknown, NextResult = never> = (input: {
|
|
74
|
+
export type AnyCommandMiddleware<Input = never, Result = unknown, NextResult = never> = (input: {
|
|
75
75
|
operation: string;
|
|
76
76
|
definition?: AuditedOperation;
|
|
77
77
|
command: Input;
|
|
@@ -81,19 +81,19 @@ type AnyCommandMiddleware<Input = never, Result = unknown, NextResult = never> =
|
|
|
81
81
|
}) => Promise<NextResult>;
|
|
82
82
|
}) => Promise<Result>;
|
|
83
83
|
/** Registry-wide defaults applied to every operation of one Command. */
|
|
84
|
-
type CommandDefaults = Readonly<{
|
|
84
|
+
export type CommandDefaults = Readonly<{
|
|
85
85
|
/** Runs before every operation's own guard. Throw to deny. */
|
|
86
86
|
guard?: (context: never) => MaybePromise<void>;
|
|
87
87
|
/** Outermost middleware, in array order, around every operation. */
|
|
88
88
|
middleware?: readonly AnyCommandMiddleware[];
|
|
89
89
|
}>;
|
|
90
90
|
/** Injected permission policy: throw to deny. Host semantics, kit ordering. */
|
|
91
|
-
type PermissionChecker = (context: never, input: Readonly<{
|
|
91
|
+
export type PermissionChecker = (context: never, input: Readonly<{
|
|
92
92
|
permission: string;
|
|
93
93
|
operation: string;
|
|
94
94
|
}>) => MaybePromise<void>;
|
|
95
|
-
type AuditedRegistry = Readonly<Record<string, AuditedOperation>>;
|
|
96
|
-
type FoundationOptions = Readonly<{
|
|
95
|
+
export type AuditedRegistry = Readonly<Record<string, AuditedOperation>>;
|
|
96
|
+
export type FoundationOptions = Readonly<{
|
|
97
97
|
observability: ObservabilityOptions & Readonly<{
|
|
98
98
|
/**
|
|
99
99
|
* In-transaction audit writer used by Command. Operations that
|
|
@@ -146,14 +146,14 @@ declare class BoundCommand<Context, const Operations extends AuditedRegistry> {
|
|
|
146
146
|
}): (context: Context, command: SchemaInput<Operations[Key]["command"]>) => Promise<SchemaOutput<Operations[Key]["result"]>>;
|
|
147
147
|
}
|
|
148
148
|
/** @deprecated Use the registry returned by createEffectFoundation(...).Command from cvx-kit/effect. */
|
|
149
|
-
type ApplicationCommand<Context, Operations extends AuditedRegistry> = BoundCommand<Context, Operations>;
|
|
149
|
+
export type ApplicationCommand<Context, Operations extends AuditedRegistry> = BoundCommand<Context, Operations>;
|
|
150
150
|
/**
|
|
151
151
|
* The constructor shape a Foundation instance exposes as `Command`.
|
|
152
152
|
* Exported as a TYPE ONLY so factories (e.g. cvx-kit/crud) can accept the
|
|
153
153
|
* destructured facade class as input without importing any runtime kernel.
|
|
154
154
|
* @deprecated Use createEffectFoundation from cvx-kit/effect and declare handlers inside command({...}).
|
|
155
155
|
*/
|
|
156
|
-
type CommandConstructor = {
|
|
156
|
+
export type CommandConstructor = {
|
|
157
157
|
/** @deprecated Use createEffectFoundation(...).Command({ context, operations }) from cvx-kit/effect. */
|
|
158
158
|
new <Context, const Operations extends AuditedRegistry>(operations: Operations & { readonly [Key in keyof Operations]: OperationHostContext<Context>; }, defaults?: CommandDefaults): BoundCommand<Context, Operations>;
|
|
159
159
|
operation: (typeof BoundCommand)['operation'];
|
|
@@ -165,7 +165,7 @@ type CommandConstructor = {
|
|
|
165
165
|
* Declared once; the sole source of the command protocol, query kernel, and
|
|
166
166
|
* observability: `const { Command, Query, observability } = new Foundation(...)`.
|
|
167
167
|
*/
|
|
168
|
-
declare class Foundation<Component extends FoundationComponentApi = FoundationComponentApi> {
|
|
168
|
+
export declare class Foundation<Component extends FoundationComponentApi = FoundationComponentApi> {
|
|
169
169
|
readonly status: Component['functions']['status'];
|
|
170
170
|
/** @deprecated Use createEffectFoundation(...).Command from cvx-kit/effect. */
|
|
171
171
|
readonly Command: CommandConstructor;
|
|
@@ -178,5 +178,5 @@ declare class Foundation<Component extends FoundationComponentApi = FoundationCo
|
|
|
178
178
|
constructor(component: Component, options: FoundationOptions);
|
|
179
179
|
}
|
|
180
180
|
//#endregion
|
|
181
|
-
export {
|
|
181
|
+
export { type AnyQueryMiddleware, type CommandArgument, type CommandExecution, type CommandHandlerResult, type CommandInput, type CommandObservation, type CommandPreparation, type CommandRegistry, type CommandResult, type ObservabilityOptions, type Parseable, type QueryExecution, type QueryMiddleware, type Result, type ResultBoundary, type SchemaOutput, type TransactionMetricsContext, type TypedOperation, client_d_exports };
|
|
182
182
|
//# sourceMappingURL=client.d.mts.map
|