cvx-kit 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +200 -0
  3. package/dist/_virtual/_rolldown/runtime.mjs +1 -0
  4. package/dist/auth.d.mts +353 -0
  5. package/dist/auth.mjs +2 -0
  6. package/dist/auth.mjs.map +1 -0
  7. package/dist/components/approvals/_generated/api.d.mts +47 -0
  8. package/dist/components/approvals/_generated/api.mjs +2 -0
  9. package/dist/components/approvals/_generated/api.mjs.map +1 -0
  10. package/dist/components/approvals/_generated/component.d.mts +297 -0
  11. package/dist/components/approvals/_generated/component.mjs +1 -0
  12. package/dist/components/approvals/_generated/dataModel.d.mts +41 -0
  13. package/dist/components/approvals/_generated/dataModel.mjs +1 -0
  14. package/dist/components/approvals/_generated/server.d.mts +116 -0
  15. package/dist/components/approvals/_generated/server.mjs +2 -0
  16. package/dist/components/approvals/_generated/server.mjs.map +1 -0
  17. package/dist/components/approvals/audit.d.mts +40 -0
  18. package/dist/components/approvals/audit.mjs +2 -0
  19. package/dist/components/approvals/audit.mjs.map +1 -0
  20. package/dist/components/approvals/client.d.mts +98 -0
  21. package/dist/components/approvals/client.mjs +2 -0
  22. package/dist/components/approvals/client.mjs.map +1 -0
  23. package/dist/components/approvals/constants.d.mts +31 -0
  24. package/dist/components/approvals/constants.mjs +2 -0
  25. package/dist/components/approvals/constants.mjs.map +1 -0
  26. package/dist/components/approvals/convex.config.d.mts +5 -0
  27. package/dist/components/approvals/convex.config.mjs +2 -0
  28. package/dist/components/approvals/convex.config.mjs.map +1 -0
  29. package/dist/components/approvals/decisions.d.mts +61 -0
  30. package/dist/components/approvals/decisions.mjs +2 -0
  31. package/dist/components/approvals/decisions.mjs.map +1 -0
  32. package/dist/components/approvals/functions.d.mts +9 -0
  33. package/dist/components/approvals/functions.mjs +2 -0
  34. package/dist/components/approvals/functions.mjs.map +1 -0
  35. package/dist/components/approvals/requests.d.mts +323 -0
  36. package/dist/components/approvals/requests.mjs +2 -0
  37. package/dist/components/approvals/requests.mjs.map +1 -0
  38. package/dist/components/approvals/schema.d.mts +376 -0
  39. package/dist/components/approvals/schema.mjs +2 -0
  40. package/dist/components/approvals/schema.mjs.map +1 -0
  41. package/dist/components/approvals/validators.d.mts +302 -0
  42. package/dist/components/approvals/validators.mjs +2 -0
  43. package/dist/components/approvals/validators.mjs.map +1 -0
  44. package/dist/components/approvals/workflow.d.mts +11 -0
  45. package/dist/components/approvals/workflow.mjs +2 -0
  46. package/dist/components/approvals/workflow.mjs.map +1 -0
  47. package/dist/components/approvals/workflow_steps.d.mts +83 -0
  48. package/dist/components/approvals/workflow_steps.mjs +2 -0
  49. package/dist/components/approvals/workflow_steps.mjs.map +1 -0
  50. package/dist/components/foundation/_generated/api.d.mts +40 -0
  51. package/dist/components/foundation/_generated/api.mjs +2 -0
  52. package/dist/components/foundation/_generated/api.mjs.map +1 -0
  53. package/dist/components/foundation/_generated/component.d.mts +21 -0
  54. package/dist/components/foundation/_generated/component.mjs +1 -0
  55. package/dist/components/foundation/_generated/dataModel.d.mts +41 -0
  56. package/dist/components/foundation/_generated/dataModel.mjs +1 -0
  57. package/dist/components/foundation/_generated/server.d.mts +116 -0
  58. package/dist/components/foundation/_generated/server.mjs +2 -0
  59. package/dist/components/foundation/_generated/server.mjs.map +1 -0
  60. package/dist/components/foundation/client.d.mts +93 -0
  61. package/dist/components/foundation/client.mjs +2 -0
  62. package/dist/components/foundation/client.mjs.map +1 -0
  63. package/dist/components/foundation/convex.config.d.mts +5 -0
  64. package/dist/components/foundation/convex.config.mjs +2 -0
  65. package/dist/components/foundation/convex.config.mjs.map +1 -0
  66. package/dist/components/foundation/functions.d.mts +8 -0
  67. package/dist/components/foundation/functions.mjs +2 -0
  68. package/dist/components/foundation/functions.mjs.map +1 -0
  69. package/dist/components/foundation/modules/command/command.d.mts +47 -0
  70. package/dist/components/foundation/modules/command/command.mjs +2 -0
  71. package/dist/components/foundation/modules/command/command.mjs.map +1 -0
  72. package/dist/components/foundation/modules/observability/observability.d.mts +31 -0
  73. package/dist/components/foundation/modules/observability/observability.mjs +2 -0
  74. package/dist/components/foundation/modules/observability/observability.mjs.map +1 -0
  75. package/dist/components/foundation/modules/query/query.d.mts +24 -0
  76. package/dist/components/foundation/modules/query/query.mjs +2 -0
  77. package/dist/components/foundation/modules/query/query.mjs.map +1 -0
  78. package/dist/components/foundation/result.d.mts +27 -0
  79. package/dist/components/foundation/result.mjs +2 -0
  80. package/dist/components/foundation/result.mjs.map +1 -0
  81. package/dist/components/foundation/schema.d.mts +6 -0
  82. package/dist/components/foundation/schema.mjs +2 -0
  83. package/dist/components/foundation/schema.mjs.map +1 -0
  84. package/dist/components/foundation/telemetry.d.mts +9 -0
  85. package/dist/components/foundation/telemetry.mjs +2 -0
  86. package/dist/components/foundation/telemetry.mjs.map +1 -0
  87. package/dist/errors.d.mts +24 -0
  88. package/dist/errors.mjs +2 -0
  89. package/dist/errors.mjs.map +1 -0
  90. package/dist/index.d.mts +6 -0
  91. package/dist/index.mjs +1 -0
  92. package/dist/triggers.d.mts +27 -0
  93. package/dist/triggers.mjs +2 -0
  94. package/dist/triggers.mjs.map +1 -0
  95. package/dist/zod-table.d.mts +124 -0
  96. package/dist/zod-table.mjs +2 -0
  97. package/dist/zod-table.mjs.map +1 -0
  98. package/package.json +108 -0
  99. package/src/auth.ts +360 -0
  100. package/src/components/approvals/_generated/api.ts +69 -0
  101. package/src/components/approvals/_generated/component.ts +335 -0
  102. package/src/components/approvals/_generated/dataModel.ts +60 -0
  103. package/src/components/approvals/_generated/server.ts +156 -0
  104. package/src/components/approvals/audit.ts +148 -0
  105. package/src/components/approvals/client.ts +321 -0
  106. package/src/components/approvals/constants.ts +51 -0
  107. package/src/components/approvals/convex.config.ts +10 -0
  108. package/src/components/approvals/decisions.ts +376 -0
  109. package/src/components/approvals/functions.ts +27 -0
  110. package/src/components/approvals/requests.ts +240 -0
  111. package/src/components/approvals/schema.ts +23 -0
  112. package/src/components/approvals/validators.ts +272 -0
  113. package/src/components/approvals/workflow.ts +204 -0
  114. package/src/components/approvals/workflow_steps.ts +189 -0
  115. package/src/components/foundation/_generated/api.ts +62 -0
  116. package/src/components/foundation/_generated/component.ts +29 -0
  117. package/src/components/foundation/_generated/dataModel.ts +60 -0
  118. package/src/components/foundation/_generated/server.ts +156 -0
  119. package/src/components/foundation/client.ts +190 -0
  120. package/src/components/foundation/convex.config.ts +3 -0
  121. package/src/components/foundation/functions.ts +10 -0
  122. package/src/components/foundation/modules/command/__tests__/command.test.ts +106 -0
  123. package/src/components/foundation/modules/command/command.ts +154 -0
  124. package/src/components/foundation/modules/observability/__tests__/observability.test.ts +79 -0
  125. package/src/components/foundation/modules/observability/observability.ts +95 -0
  126. package/src/components/foundation/modules/query/__tests__/query.test.ts +25 -0
  127. package/src/components/foundation/modules/query/query.ts +47 -0
  128. package/src/components/foundation/result.ts +77 -0
  129. package/src/components/foundation/schema.ts +4 -0
  130. package/src/components/foundation/telemetry.ts +23 -0
  131. package/src/errors.ts +25 -0
  132. package/src/index.ts +41 -0
  133. package/src/test.ts +36 -0
  134. package/src/triggers.ts +90 -0
  135. package/src/zod-table.ts +197 -0
@@ -0,0 +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}from"convex-helpers/server/zod4";import{z as o}from"zod";const s=o.enum(r),c=o.enum(t),l=o.enum(i),u=o.enum(e),d=o.enum(n),f=o.string().trim().min(1).max(256),p=o.string().trim().min(1).max(96).regex(/^[A-Za-z][A-Za-z0-9._-]*$/),m=o.string().trim().min(1).max(500),h=o.record(o.string().min(1).max(64).regex(/^(?![$_])[\x20-\x7E]+$/),o.string().max(512)).refine(e=>Object.keys(e).length<=32,`Metadata may contain at most 32 entries`),g=o.object({actorRef:f,capabilities:o.array(p).max(32),metadata:h.optional()}).strict(),_=o.object({kind:o.literal(`mutation`),handle:f,retry:o.boolean()}).strict(),v=o.object({kind:o.literal(`action`),handle:f,retry:o.boolean()}).strict(),y=o.discriminatedUnion(`kind`,[_,v]),b=o.object({kind:d,approvals:o.number().int().positive().max(8)}).strict(),x=o.discriminatedUnion(`kind`,[o.object({kind:o.literal(`mutation`),key:p,callback:_}).strict(),o.object({kind:o.literal(`action`),key:p,callback:v}).strict()]),S=o.object({kind:o.literal(`notify`),key:p,callback:v}).strict(),C=o.object({kind:o.literal(`decision`),key:p,decisions:o.array(c).min(1).max(8),quorum:b,makerChecker:o.boolean(),expiresAfterMs:o.number().int().positive().optional()}).strict(),w=o.object({kind:o.literal(`branch`),key:p,approvedStepKey:p,rejectedStepKey:p}).strict(),T=o.discriminatedUnion(`kind`,[x,S,C,w]),E=o.object({schemaVersion:o.literal(1),compatibilityKey:p,name:p,steps:o.array(T).min(1).max(32)}).strict().superRefine((e,t)=>{let n=new Set,r=new Map(e.steps.map(e=>[e.key,e])),i=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`]})}),D=o.object({scopeRef:f,resourceType:p,resourceRef:f,requester:g,metadata:h.optional(),workflow:E,state:s,currentStepKey:p.optional(),executionFailedStepKey:p.optional(),expiresAt:o.number().optional(),workflowId:f.optional(),createdAt:o.number(),updatedAt:o.number(),terminalAt:o.number().optional()}).strict(),O=o.object({runId:a(`approvalRuns`),stepKey:p,actor:g,decision:c,reason:m.optional(),decidedAt:o.number()}).strict();export{v as approvalActionCallback,g as approvalActor,w as approvalBranchStep,y as approvalCallback,u as approvalCallbackKind,x as approvalCallbackStep,c as approvalDecision,O as approvalDecisionDocument,C as approvalDecisionStep,h as approvalMetadata,_ as approvalMutationCallback,p as approvalName,S as approvalNotifyStep,b as approvalQuorum,d as approvalQuorumKind,m as approvalReason,f as approvalReference,D as approvalRunDocument,s as approvalRunState,l as approvalStepKind,E as approvalWorkflowDescriptor,T as approvalWorkflowStep};
2
+ //# sourceMappingURL=validators.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.mjs","names":[],"sources":["../../../src/components/approvals/validators.ts"],"sourcesContent":["import { zid } from 'convex-helpers/server/zod4'\nimport { z } from 'zod'\n\nimport {\n\tAPPROVAL_CALLBACK_KINDS,\n\tAPPROVAL_DECISIONS,\n\tAPPROVAL_DESCRIPTOR_SCHEMA_VERSION,\n\tAPPROVAL_QUORUM_KINDS,\n\tAPPROVAL_RUN_STATES,\n\tAPPROVAL_STEP_KINDS,\n\tMAX_APPROVAL_CAPABILITIES,\n\tMAX_APPROVAL_DECISIONS_PER_STEP,\n\tMAX_APPROVAL_METADATA_ENTRIES,\n\tMAX_APPROVAL_METADATA_KEY_LENGTH,\n\tMAX_APPROVAL_METADATA_VALUE_LENGTH,\n\tMAX_APPROVAL_NAME_LENGTH,\n\tMAX_APPROVAL_REASON_LENGTH,\n\tMAX_APPROVAL_REFERENCE_LENGTH,\n\tMAX_APPROVAL_WORKFLOW_STEPS,\n} from './constants'\n\nexport const approvalRunState = z.enum(APPROVAL_RUN_STATES)\nexport const approvalDecision = z.enum(APPROVAL_DECISIONS)\nexport const approvalStepKind = z.enum(APPROVAL_STEP_KINDS)\nexport const approvalCallbackKind = z.enum(APPROVAL_CALLBACK_KINDS)\nexport const approvalQuorumKind = z.enum(APPROVAL_QUORUM_KINDS)\n\nexport const approvalReference = z\n\t.string()\n\t.trim()\n\t.min(1)\n\t.max(MAX_APPROVAL_REFERENCE_LENGTH)\n\nexport const approvalName = z\n\t.string()\n\t.trim()\n\t.min(1)\n\t.max(MAX_APPROVAL_NAME_LENGTH)\n\t.regex(/^[A-Za-z][A-Za-z0-9._-]*$/)\n\nexport const approvalReason = z\n\t.string()\n\t.trim()\n\t.min(1)\n\t.max(MAX_APPROVAL_REASON_LENGTH)\n\nexport const approvalMetadata = z\n\t.record(\n\t\tz\n\t\t\t.string()\n\t\t\t.min(1)\n\t\t\t.max(MAX_APPROVAL_METADATA_KEY_LENGTH)\n\t\t\t.regex(/^(?![$_])[\\x20-\\x7E]+$/),\n\t\tz.string().max(MAX_APPROVAL_METADATA_VALUE_LENGTH),\n\t)\n\t.refine(\n\t\t(value) => Object.keys(value).length <= MAX_APPROVAL_METADATA_ENTRIES,\n\t\t`Metadata may contain at most ${MAX_APPROVAL_METADATA_ENTRIES} entries`,\n\t)\n\nexport const approvalActor = z\n\t.object({\n\t\tactorRef: approvalReference,\n\t\tcapabilities: z.array(approvalName).max(MAX_APPROVAL_CAPABILITIES),\n\t\tmetadata: approvalMetadata.optional(),\n\t})\n\t.strict()\n\nexport const approvalMutationCallback = z\n\t.object({\n\t\tkind: z.literal('mutation'),\n\t\thandle: approvalReference,\n\t\tretry: z.boolean(),\n\t})\n\t.strict()\n\nexport const approvalActionCallback = z\n\t.object({\n\t\tkind: z.literal('action'),\n\t\thandle: approvalReference,\n\t\tretry: z.boolean(),\n\t})\n\t.strict()\n\nexport const approvalCallback = z.discriminatedUnion('kind', [\n\tapprovalMutationCallback,\n\tapprovalActionCallback,\n])\n\nexport const approvalQuorum = z\n\t.object({\n\t\tkind: approvalQuorumKind,\n\t\tapprovals: z.number().int().positive().max(MAX_APPROVAL_DECISIONS_PER_STEP),\n\t})\n\t.strict()\n\nexport const approvalCallbackStep = z.discriminatedUnion('kind', [\n\tz\n\t\t.object({\n\t\t\tkind: z.literal('mutation'),\n\t\t\tkey: approvalName,\n\t\t\tcallback: approvalMutationCallback,\n\t\t})\n\t\t.strict(),\n\tz\n\t\t.object({\n\t\t\tkind: z.literal('action'),\n\t\t\tkey: approvalName,\n\t\t\tcallback: approvalActionCallback,\n\t\t})\n\t\t.strict(),\n])\n\nexport const approvalNotifyStep = z\n\t.object({\n\t\tkind: z.literal('notify'),\n\t\tkey: approvalName,\n\t\tcallback: approvalActionCallback,\n\t})\n\t.strict()\n\nexport const approvalDecisionStep = z\n\t.object({\n\t\tkind: z.literal('decision'),\n\t\tkey: approvalName,\n\t\tdecisions: z\n\t\t\t.array(approvalDecision)\n\t\t\t.min(1)\n\t\t\t.max(MAX_APPROVAL_DECISIONS_PER_STEP),\n\t\tquorum: approvalQuorum,\n\t\tmakerChecker: z.boolean(),\n\t\texpiresAfterMs: z.number().int().positive().optional(),\n\t})\n\t.strict()\n\nexport const approvalBranchStep = z\n\t.object({\n\t\tkind: z.literal('branch'),\n\t\tkey: approvalName,\n\t\tapprovedStepKey: approvalName,\n\t\trejectedStepKey: approvalName,\n\t})\n\t.strict()\n\nexport const approvalWorkflowStep = z.discriminatedUnion('kind', [\n\tapprovalCallbackStep,\n\tapprovalNotifyStep,\n\tapprovalDecisionStep,\n\tapprovalBranchStep,\n])\n\nexport const approvalWorkflowDescriptor = z\n\t.object({\n\t\tschemaVersion: z.literal(APPROVAL_DESCRIPTOR_SCHEMA_VERSION),\n\t\tcompatibilityKey: approvalName,\n\t\tname: approvalName,\n\t\tsteps: z\n\t\t\t.array(approvalWorkflowStep)\n\t\t\t.min(1)\n\t\t\t.max(MAX_APPROVAL_WORKFLOW_STEPS),\n\t})\n\t.strict()\n\t.superRefine((descriptor, context) => {\n\t\tconst keys = new Set<string>()\n\t\tconst stepsByKey = new Map(\n\t\t\tdescriptor.steps.map((step) => [step.key, step] as const),\n\t\t)\n\t\tconst branchTargetOwners = new Map<string, number>()\n\t\tfor (const [index, step] of descriptor.steps.entries()) {\n\t\t\tif (keys.has(step.key))\n\t\t\t\tcontext.addIssue({\n\t\t\t\t\tcode: 'custom',\n\t\t\t\t\tmessage: `Duplicate workflow step key: ${step.key}`,\n\t\t\t\t\tpath: ['steps', index, 'key'],\n\t\t\t\t})\n\t\t\tkeys.add(step.key)\n\t\t\tif (\n\t\t\t\tstep.kind === 'decision' &&\n\t\t\t\tnew Set(step.decisions).size !== step.decisions.length\n\t\t\t)\n\t\t\t\tcontext.addIssue({\n\t\t\t\t\tcode: 'custom',\n\t\t\t\t\tmessage: `Duplicate decision value in step: ${step.key}`,\n\t\t\t\t\tpath: ['steps', index, 'decisions'],\n\t\t\t\t})\n\t\t}\n\t\tfor (const [index, step] of descriptor.steps.entries()) {\n\t\t\tif (step.kind !== 'branch') continue\n\t\t\tif (descriptor.steps[index - 1]?.kind !== 'decision')\n\t\t\t\tcontext.addIssue({\n\t\t\t\t\tcode: 'custom',\n\t\t\t\t\tmessage: `Branch must immediately follow a decision: ${step.key}`,\n\t\t\t\t\tpath: ['steps', index],\n\t\t\t\t})\n\t\t\tfor (const target of [step.approvedStepKey, step.rejectedStepKey]) {\n\t\t\t\tconst targetStep = stepsByKey.get(target)\n\t\t\t\tconst targetIndex = descriptor.steps.findIndex(\n\t\t\t\t\t(candidate) => candidate.key === target,\n\t\t\t\t)\n\t\t\t\tif (!targetStep)\n\t\t\t\t\tcontext.addIssue({\n\t\t\t\t\t\tcode: 'custom',\n\t\t\t\t\t\tmessage: `Unknown branch target: ${target}`,\n\t\t\t\t\t\tpath: ['steps', index],\n\t\t\t\t\t})\n\t\t\t\telse if (\n\t\t\t\t\ttargetStep.kind !== 'mutation' &&\n\t\t\t\t\ttargetStep.kind !== 'action' &&\n\t\t\t\t\ttargetStep.kind !== 'notify'\n\t\t\t\t)\n\t\t\t\t\tcontext.addIssue({\n\t\t\t\t\t\tcode: 'custom',\n\t\t\t\t\t\tmessage: `Branch target must be a callback step: ${target}`,\n\t\t\t\t\t\tpath: ['steps', index],\n\t\t\t\t\t})\n\t\t\t\telse if (targetIndex <= index)\n\t\t\t\t\tcontext.addIssue({\n\t\t\t\t\t\tcode: 'custom',\n\t\t\t\t\t\tmessage: `Branch target must be declared after its branch: ${target}`,\n\t\t\t\t\t\tpath: ['steps', index],\n\t\t\t\t\t})\n\t\t\t\tbranchTargetOwners.set(\n\t\t\t\t\ttarget,\n\t\t\t\t\t(branchTargetOwners.get(target) ?? 0) + 1,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\tfor (const [target, owners] of branchTargetOwners) {\n\t\t\tif (owners !== 1)\n\t\t\t\tcontext.addIssue({\n\t\t\t\t\tcode: 'custom',\n\t\t\t\t\tmessage: `Branch callback must belong to exactly one branch: ${target}`,\n\t\t\t\t\tpath: ['steps'],\n\t\t\t\t})\n\t\t}\n\t})\n\nexport const approvalRunDocument = z\n\t.object({\n\t\tscopeRef: approvalReference,\n\t\tresourceType: approvalName,\n\t\tresourceRef: approvalReference,\n\t\trequester: approvalActor,\n\t\tmetadata: approvalMetadata.optional(),\n\t\tworkflow: approvalWorkflowDescriptor,\n\t\tstate: approvalRunState,\n\t\tcurrentStepKey: approvalName.optional(),\n\t\texecutionFailedStepKey: approvalName.optional(),\n\t\texpiresAt: z.number().optional(),\n\t\tworkflowId: approvalReference.optional(),\n\t\tcreatedAt: z.number(),\n\t\tupdatedAt: z.number(),\n\t\tterminalAt: z.number().optional(),\n\t})\n\t.strict()\n\nexport const approvalDecisionDocument = z\n\t.object({\n\t\trunId: zid('approvalRuns'),\n\t\tstepKey: approvalName,\n\t\tactor: approvalActor,\n\t\tdecision: approvalDecision,\n\t\treason: approvalReason.optional(),\n\t\tdecidedAt: z.number(),\n\t})\n\t.strict()\n\nexport type ApprovalWorkflowDescriptor = z.infer<\n\ttypeof approvalWorkflowDescriptor\n>\nexport type ApprovalActor = z.infer<typeof approvalActor>\nexport type ApprovalMetadata = z.infer<typeof approvalMetadata>\n"],"mappings":"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"}
@@ -0,0 +1,11 @@
1
+ import { WorkflowManager } from "@convex-dev/workflow";
2
+ declare namespace workflow_d_exports {
3
+ export { approvalWorkflow, run };
4
+ }
5
+ declare const approvalWorkflow: WorkflowManager;
6
+ declare const run: import("convex/server").RegisteredMutation<"internal", import("@convex-dev/workflow").WorkflowArgs<{
7
+ runId: import("convex/values").VId<import("convex/values").GenericId<"approvalRuns">, "required">;
8
+ }>, import("@convex-dev/workflow").WorkflowId>;
9
+ //#endregion
10
+ export { approvalWorkflow, run, workflow_d_exports };
11
+ //# sourceMappingURL=workflow.d.mts.map
@@ -0,0 +1,2 @@
1
+ import{components as e,internal as t}from"./_generated/api.mjs";import{APPROVAL_DECISIONS as n,APPROVAL_RUN_STATES as r}from"./constants.mjs";import{approvalDecisionEventName as i,callbackReference as a,resolveWorkflowStepIndex as o}from"./workflow_steps.mjs";import{v as s}from"convex/values";import{WorkflowManager as c}from"@convex-dev/workflow";const l=new c(e.workflow),u=l.define({args:{runId:s.id(`approvalRuns`)},returns:s.null(),handler:async(e,a)=>{let c;try{let l=await e.runQuery(t.requests.getForWorkflow,{runId:a.runId},{name:`loadLinkedApproval`});if(!l)throw Error(`Approval request not found`);if(l.workflowId!==e.workflowId)throw Error(`Approval workflow linkage is incomplete`);let u=d(l),p=l.workflow.steps.map(e=>e.key),m=new Set(l.workflow.steps.flatMap(e=>e.kind===`branch`?[e.approvedStepKey,e.rejectedStepKey]:[])),h=null,g=null,_,v=0;for(;v<l.workflow.steps.length;){let a=l.workflow.steps[v];if(a.kind===`mutation`||a.kind===`action`||a.kind===`notify`){if(m.has(a.key)){v+=1;continue}c=a.key,await f(e,a,u),c=void 0,v+=1;continue}if(a.kind===`decision`){await e.runMutation(t.decisions.enter,{runId:l._id,stepKey:a.key,workflowId:e.workflowId,...a.expiresAfterMs===void 0?{}:{expiresAfterMs:a.expiresAfterMs}},{name:`enter:${a.key}`});let o=await e.awaitEvent({name:i(l._id,a.key),validator:s.object({outcome:s.union(s.literal(n[0]),s.literal(n[1]),s.literal(r[3])),terminalEvidence:s.optional(s.object({actorRef:s.string(),decision:s.union(s.literal(n[0]),s.literal(n[1])),reason:s.optional(s.string()),decidedAt:s.number()}))})});if(h=o.outcome,_=o.terminalEvidence,g=a.key,h!==`approved`&&l.workflow.steps[v+1]?.kind!==`branch`)break;v+=1;continue}if(!h)throw Error(`Branch requires a preceding decision step`);let d=h===`approved`?a.approvedStepKey:a.rejectedStepKey,y=o(p,d),b=l.workflow.steps[y];if(b.kind!==`mutation`&&b.kind!==`action`&&b.kind!==`notify`)throw Error(`Approval branch target must be a callback step`);let x=await e.runQuery(t.decisions.listForWorkflow,{runId:l._id,stepKey:g??a.key},{name:`evidence:${a.key}`});if(c=b.key,await f(e,b,{...u,decision:{stepKey:g??a.key,outcome:h,evidence:x,..._===void 0?{}:{terminalEvidence:_}}}),c=void 0,h===`rejected`||h===`expired`)break;v+=1}return await e.runMutation(t.requests.recordExecutionTerminal,{runId:l._id,outcome:`completed`},{name:`recordExecutionCompleted`}),null}catch(n){throw await e.runMutation(t.requests.recordExecutionTerminal,{runId:a.runId,outcome:`failed`,...c===void 0?{}:{failedStepKey:c}},{name:`recordExecutionFailed`}),n}}});function d(e){return{runId:e._id,scopeRef:e.scopeRef,resourceType:e.resourceType,resourceRef:e.resourceRef,...e.metadata===void 0?{}:{metadata:e.metadata}}}async function f(e,t,n){if(t.callback.kind===`mutation`){await e.runMutation(a(t.callback.handle),n,{name:t.key});return}await e.runAction(a(t.callback.handle),n,{name:t.key,retry:t.callback.retry})}export{l as approvalWorkflow,u as run};
2
+ //# sourceMappingURL=workflow.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow.mjs","names":[],"sources":["../../../src/components/approvals/workflow.ts"],"sourcesContent":["import { WorkflowManager, type WorkflowCtx } from '@convex-dev/workflow'\nimport { v } from 'convex/values'\n\nimport { components, internal } from './_generated/api'\nimport type { Doc } from './_generated/dataModel'\nimport { APPROVAL_DECISIONS, APPROVAL_RUN_STATES } from './constants'\nimport {\n\tapprovalDecisionEventName,\n\tcallbackReference,\n\tresolveWorkflowStepIndex,\n\ttype ApprovalCallbackInput,\n} from './workflow_steps'\n\nexport const approvalWorkflow = new WorkflowManager(components.workflow)\n\nexport const run = approvalWorkflow.define({\n\targs: { runId: v.id('approvalRuns') },\n\treturns: v.null(),\n\thandler: async (step, input) => {\n\t\tlet failedStepKey: string | undefined\n\t\ttry {\n\t\t\tconst run: Doc<'approvalRuns'> | null = await step.runQuery(\n\t\t\t\tinternal.requests.getForWorkflow,\n\t\t\t\t{ runId: input.runId },\n\t\t\t\t{ name: 'loadLinkedApproval' },\n\t\t\t)\n\t\t\tif (!run) throw new Error('Approval request not found')\n\t\t\tif (run.workflowId !== step.workflowId)\n\t\t\t\tthrow new Error('Approval workflow linkage is incomplete')\n\n\t\t\tconst callbackInput = buildCallbackInput(run)\n\t\t\tconst stepKeys = run.workflow.steps.map(\n\t\t\t\t(workflowStep) => workflowStep.key,\n\t\t\t)\n\t\t\tconst branchTargets = new Set(\n\t\t\t\trun.workflow.steps.flatMap((workflowStep) =>\n\t\t\t\t\tworkflowStep.kind === 'branch'\n\t\t\t\t\t\t? [workflowStep.approvedStepKey, workflowStep.rejectedStepKey]\n\t\t\t\t\t\t: [],\n\t\t\t\t),\n\t\t\t)\n\t\t\tlet lastDecision: 'approved' | 'rejected' | 'expired' | null = null\n\t\t\tlet lastDecisionStepKey: string | null = null\n\t\t\tlet terminalEvidence:\n\t\t\t\t| {\n\t\t\t\t\t\tactorRef: string\n\t\t\t\t\t\tdecision: 'approved' | 'rejected'\n\t\t\t\t\t\treason?: string\n\t\t\t\t\t\tdecidedAt: number\n\t\t\t\t }\n\t\t\t\t| undefined\n\t\t\tlet index = 0\n\t\t\twhile (index < run.workflow.steps.length) {\n\t\t\t\tconst workflowStep = run.workflow.steps[index]\n\t\t\t\tif (\n\t\t\t\t\tworkflowStep.kind === 'mutation' ||\n\t\t\t\t\tworkflowStep.kind === 'action' ||\n\t\t\t\t\tworkflowStep.kind === 'notify'\n\t\t\t\t) {\n\t\t\t\t\tif (branchTargets.has(workflowStep.key)) {\n\t\t\t\t\t\tindex += 1\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfailedStepKey = workflowStep.key\n\t\t\t\t\tawait executeCallback(step, workflowStep, callbackInput)\n\t\t\t\t\tfailedStepKey = undefined\n\t\t\t\t\tindex += 1\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (workflowStep.kind === 'decision') {\n\t\t\t\t\tawait step.runMutation(\n\t\t\t\t\t\tinternal.decisions.enter,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\trunId: run._id,\n\t\t\t\t\t\t\tstepKey: workflowStep.key,\n\t\t\t\t\t\t\tworkflowId: step.workflowId,\n\t\t\t\t\t\t\t...(workflowStep.expiresAfterMs === undefined\n\t\t\t\t\t\t\t\t? {}\n\t\t\t\t\t\t\t\t: { expiresAfterMs: workflowStep.expiresAfterMs }),\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ name: `enter:${workflowStep.key}` },\n\t\t\t\t\t)\n\t\t\t\t\tconst event = await step.awaitEvent({\n\t\t\t\t\t\tname: approvalDecisionEventName(run._id, workflowStep.key),\n\t\t\t\t\t\tvalidator: v.object({\n\t\t\t\t\t\t\toutcome: v.union(\n\t\t\t\t\t\t\t\tv.literal(APPROVAL_DECISIONS[0]),\n\t\t\t\t\t\t\t\tv.literal(APPROVAL_DECISIONS[1]),\n\t\t\t\t\t\t\t\tv.literal(APPROVAL_RUN_STATES[3]),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tterminalEvidence: v.optional(\n\t\t\t\t\t\t\t\tv.object({\n\t\t\t\t\t\t\t\t\tactorRef: v.string(),\n\t\t\t\t\t\t\t\t\tdecision: v.union(\n\t\t\t\t\t\t\t\t\t\tv.literal(APPROVAL_DECISIONS[0]),\n\t\t\t\t\t\t\t\t\t\tv.literal(APPROVAL_DECISIONS[1]),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\treason: v.optional(v.string()),\n\t\t\t\t\t\t\t\t\tdecidedAt: v.number(),\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t}),\n\t\t\t\t\t})\n\t\t\t\t\tlastDecision = event.outcome\n\t\t\t\t\tterminalEvidence = event.terminalEvidence\n\t\t\t\t\tlastDecisionStepKey = workflowStep.key\n\t\t\t\t\tif (\n\t\t\t\t\t\tlastDecision !== 'approved' &&\n\t\t\t\t\t\trun.workflow.steps[index + 1]?.kind !== 'branch'\n\t\t\t\t\t)\n\t\t\t\t\t\tbreak\n\t\t\t\t\tindex += 1\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (!lastDecision)\n\t\t\t\t\tthrow new Error('Branch requires a preceding decision step')\n\t\t\t\tconst targetKey =\n\t\t\t\t\tlastDecision === 'approved'\n\t\t\t\t\t\t? workflowStep.approvedStepKey\n\t\t\t\t\t\t: workflowStep.rejectedStepKey\n\t\t\t\tconst targetIndex = resolveWorkflowStepIndex(stepKeys, targetKey)\n\t\t\t\tconst target = run.workflow.steps[targetIndex]\n\t\t\t\tif (\n\t\t\t\t\ttarget.kind !== 'mutation' &&\n\t\t\t\t\ttarget.kind !== 'action' &&\n\t\t\t\t\ttarget.kind !== 'notify'\n\t\t\t\t)\n\t\t\t\t\tthrow new Error('Approval branch target must be a callback step')\n\t\t\t\tconst evidence = await step.runQuery(\n\t\t\t\t\tinternal.decisions.listForWorkflow,\n\t\t\t\t\t{ runId: run._id, stepKey: lastDecisionStepKey ?? workflowStep.key },\n\t\t\t\t\t{ name: `evidence:${workflowStep.key}` },\n\t\t\t\t)\n\t\t\t\tfailedStepKey = target.key\n\t\t\t\tawait executeCallback(step, target, {\n\t\t\t\t\t...callbackInput,\n\t\t\t\t\tdecision: {\n\t\t\t\t\t\tstepKey: lastDecisionStepKey ?? workflowStep.key,\n\t\t\t\t\t\toutcome: lastDecision,\n\t\t\t\t\t\tevidence,\n\t\t\t\t\t\t...(terminalEvidence === undefined ? {} : { terminalEvidence }),\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\tfailedStepKey = undefined\n\t\t\t\tif (lastDecision === 'rejected' || lastDecision === 'expired') break\n\t\t\t\tindex += 1\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tawait step.runMutation(\n\t\t\t\tinternal.requests.recordExecutionTerminal,\n\t\t\t\t{ runId: run._id, outcome: 'completed' },\n\t\t\t\t{ name: 'recordExecutionCompleted' },\n\t\t\t)\n\t\t\treturn null\n\t\t} catch (error) {\n\t\t\tawait step.runMutation(\n\t\t\t\tinternal.requests.recordExecutionTerminal,\n\t\t\t\t{\n\t\t\t\t\trunId: input.runId,\n\t\t\t\t\toutcome: 'failed',\n\t\t\t\t\t...(failedStepKey === undefined ? {} : { failedStepKey }),\n\t\t\t\t},\n\t\t\t\t{ name: 'recordExecutionFailed' },\n\t\t\t)\n\t\t\tthrow error\n\t\t}\n\t},\n})\n\ntype CallbackStep = Extract<\n\tDoc<'approvalRuns'>['workflow']['steps'][number],\n\t{ kind: 'mutation' | 'action' | 'notify' }\n>\n\nfunction buildCallbackInput(run: Doc<'approvalRuns'>): ApprovalCallbackInput {\n\treturn {\n\t\trunId: run._id,\n\t\tscopeRef: run.scopeRef,\n\t\tresourceType: run.resourceType,\n\t\tresourceRef: run.resourceRef,\n\t\t...(run.metadata === undefined ? {} : { metadata: run.metadata }),\n\t}\n}\n\nasync function executeCallback(\n\tstep: WorkflowCtx,\n\tworkflowStep: CallbackStep,\n\tinput: ApprovalCallbackInput,\n): Promise<void> {\n\tif (workflowStep.callback.kind === 'mutation') {\n\t\tawait step.runMutation(\n\t\t\tcallbackReference<'mutation'>(workflowStep.callback.handle),\n\t\t\tinput,\n\t\t\t{ name: workflowStep.key },\n\t\t)\n\t\treturn\n\t}\n\tawait step.runAction(\n\t\tcallbackReference<'action'>(workflowStep.callback.handle),\n\t\tinput,\n\t\t{ name: workflowStep.key, retry: workflowStep.callback.retry },\n\t)\n}\n"],"mappings":"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"}
@@ -0,0 +1,83 @@
1
+ import { ApprovalDecision } from "./constants.mjs";
2
+ import { ApprovalWorkflowDescriptor } from "./validators.mjs";
3
+ import { FunctionReference, FunctionType } from "convex/server";
4
+ declare namespace workflow_steps_d_exports {
5
+ export { ApprovalActionStep, ApprovalBranchStep, ApprovalCallbackInput, ApprovalDecisionEvidence, ApprovalDecisionStep, ApprovalDefinition, ApprovalMutationStep, ApprovalNotifyStep, ApprovalWorkflowStep, CreateApprovalHandle, approvalDecisionEventName, callbackReference, compileApprovalDescriptor, evaluateDecisionOutcome, resolveWorkflowStepIndex };
6
+ }
7
+ type ApprovalMutationStep = Readonly<{
8
+ kind: 'mutation';
9
+ key: string;
10
+ handler: FunctionReference<'mutation', 'internal'>;
11
+ retry: boolean;
12
+ }>;
13
+ type ApprovalActionStep = Readonly<{
14
+ kind: 'action';
15
+ key: string;
16
+ handler: FunctionReference<'action', 'internal'>;
17
+ retry: boolean;
18
+ }>;
19
+ type ApprovalNotifyStep = Readonly<{
20
+ kind: 'notify';
21
+ key: string;
22
+ handler: FunctionReference<'action', 'internal'>;
23
+ retry: boolean;
24
+ }>;
25
+ type ApprovalDecisionStep = Readonly<{
26
+ kind: 'decision';
27
+ key: string;
28
+ decisions: readonly ApprovalDecision[];
29
+ quorum: Readonly<{
30
+ kind: 'count';
31
+ approvals: number;
32
+ }>;
33
+ makerChecker: boolean;
34
+ expiresAfterMs?: number;
35
+ }>;
36
+ type ApprovalBranchStep = Readonly<{
37
+ kind: 'branch';
38
+ key: string;
39
+ approvedStepKey: string;
40
+ rejectedStepKey: string;
41
+ }>;
42
+ type ApprovalWorkflowStep = ApprovalMutationStep | ApprovalActionStep | ApprovalNotifyStep | ApprovalDecisionStep | ApprovalBranchStep;
43
+ type ApprovalDefinition = Readonly<{
44
+ name: string;
45
+ compatibilityKey: string;
46
+ steps: readonly ApprovalWorkflowStep[];
47
+ }>;
48
+ type CreateApprovalHandle = (reference: FunctionReference<'mutation' | 'action', 'internal'>) => Promise<string>;
49
+ type ApprovalDecisionEvidence = Readonly<{
50
+ actorRef: string;
51
+ decision: ApprovalDecision;
52
+ }>;
53
+ type ApprovalCallbackInput = Readonly<{
54
+ runId: string;
55
+ scopeRef: string;
56
+ resourceType: string;
57
+ resourceRef: string;
58
+ metadata?: Readonly<Record<string, string>>;
59
+ decision?: Readonly<{
60
+ stepKey: string;
61
+ outcome: ApprovalDecision | 'expired';
62
+ evidence: readonly Readonly<{
63
+ actorRef: string;
64
+ decision: ApprovalDecision;
65
+ reason?: string;
66
+ decidedAt: number;
67
+ }>[];
68
+ terminalEvidence?: Readonly<{
69
+ actorRef: string;
70
+ decision: ApprovalDecision;
71
+ reason?: string;
72
+ decidedAt: number;
73
+ }>;
74
+ }>;
75
+ }>;
76
+ declare function approvalDecisionEventName(runId: string, stepKey: string): string;
77
+ declare function evaluateDecisionOutcome(decisions: readonly ApprovalDecisionEvidence[], approvalsRequired: number): ApprovalDecision | null;
78
+ declare function resolveWorkflowStepIndex(stepKeys: readonly string[], targetKey: string): number;
79
+ declare function callbackReference<Type extends FunctionType>(handle: string): FunctionReference<Type, 'internal', ApprovalCallbackInput, unknown>;
80
+ declare function compileApprovalDescriptor(definition: ApprovalDefinition, createHandle?: CreateApprovalHandle): Promise<Readonly<ApprovalWorkflowDescriptor>>;
81
+ //#endregion
82
+ export { ApprovalActionStep, ApprovalBranchStep, ApprovalCallbackInput, ApprovalDecisionEvidence, ApprovalDecisionStep, ApprovalDefinition, ApprovalMutationStep, ApprovalNotifyStep, ApprovalWorkflowStep, CreateApprovalHandle, approvalDecisionEventName, callbackReference, compileApprovalDescriptor, evaluateDecisionOutcome, resolveWorkflowStepIndex, workflow_steps_d_exports };
83
+ //# sourceMappingURL=workflow_steps.d.mts.map
@@ -0,0 +1,2 @@
1
+ import{approvalWorkflowDescriptor as e}from"./validators.mjs";import{createFunctionHandle as t}from"convex/server";function n(e,t){return`approval:${e}:${t}`}function r(e,t){return e.some(e=>e.decision===`rejected`)?`rejected`:e.filter(e=>e.decision===`approved`).length>=t?`approved`:null}function i(e,t){let n=e.indexOf(t);if(n===-1)throw Error(`Unknown approval workflow step: ${t}`);return n}function a(e){return e}async function o(n,r=t){let i=await Promise.all(n.steps.map(async e=>e.kind===`mutation`||e.kind===`action`?{kind:e.kind,key:e.key,callback:{kind:e.kind,handle:await r(e.handler),retry:e.retry}}:e.kind===`notify`?{kind:e.kind,key:e.key,callback:{kind:`action`,handle:await r(e.handler),retry:e.retry}}:e.kind===`decision`?{...e,decisions:[...e.decisions],quorum:{...e.quorum}}:{...e}));return s(e.parse({schemaVersion:1,compatibilityKey:n.compatibilityKey,name:n.name,steps:i}))}function s(e){if(e&&typeof e==`object`){Object.freeze(e);for(let t of Object.values(e))s(t)}return e}export{n as approvalDecisionEventName,a as callbackReference,o as compileApprovalDescriptor,r as evaluateDecisionOutcome,i as resolveWorkflowStepIndex};
2
+ //# sourceMappingURL=workflow_steps.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow_steps.mjs","names":[],"sources":["../../../src/components/approvals/workflow_steps.ts"],"sourcesContent":["import {\n\tcreateFunctionHandle,\n\ttype FunctionReference,\n\ttype FunctionType,\n} from 'convex/server'\n\nimport type { ApprovalDecision } from './constants'\nimport {\n\tapprovalWorkflowDescriptor,\n\ttype 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 type ApprovalCallbackInput = Readonly<{\n\trunId: string\n\tscopeRef: string\n\tresourceType: string\n\tresourceRef: string\n\tmetadata?: Readonly<Record<string, string>>\n\tdecision?: Readonly<{\n\t\tstepKey: string\n\t\toutcome: ApprovalDecision | 'expired'\n\t\tevidence: readonly Readonly<{\n\t\t\tactorRef: string\n\t\t\tdecision: ApprovalDecision\n\t\t\treason?: string\n\t\t\tdecidedAt: number\n\t\t}>[]\n\t\tterminalEvidence?: Readonly<{\n\t\t\tactorRef: string\n\t\t\tdecision: ApprovalDecision\n\t\t\treason?: string\n\t\t\tdecidedAt: number\n\t\t}>\n\t}>\n}>\n\nexport function approvalDecisionEventName(\n\trunId: string,\n\tstepKey: string,\n): 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'))\n\t\treturn 'rejected'\n\treturn decisions.filter((decision) => decision.decision === 'approved')\n\t\t.length >= approvalsRequired\n\t\t? 'approved'\n\t\t: null\n}\n\nexport function resolveWorkflowStepIndex(\n\tstepKeys: readonly string[],\n\ttargetKey: string,\n): number {\n\tconst index = stepKeys.indexOf(targetKey)\n\tif (index === -1)\n\t\tthrow 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\treturn handle as unknown as FunctionReference<\n\t\tType,\n\t\t'internal',\n\t\tApprovalCallbackInput,\n\t\tunknown\n\t>\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<Value>(value: Value): Readonly<Value> {\n\tif (value && typeof value === 'object') {\n\t\tObject.freeze(value)\n\t\tfor (const nested of Object.values(value)) deepFreeze(nested)\n\t}\n\treturn value\n}\n"],"mappings":"mHA+FA,SAAgB,EACf,EACA,EACS,CACT,MAAO,YAAY,EAAM,GAAG,GAC7B,CAEA,SAAgB,EACf,EACA,EAC0B,CAG1B,OAFI,EAAU,KAAM,GAAa,EAAS,WAAa,UAAU,EACzD,WACD,EAAU,OAAQ,GAAa,EAAS,WAAa,UAAU,CAAC,CACrE,QAAU,EACT,WACA,IACJ,CAEA,SAAgB,EACf,EACA,EACS,CACT,IAAM,EAAQ,EAAS,QAAQ,CAAS,EACxC,GAAI,IAAU,GACb,MAAU,MAAM,mCAAmC,GAAW,EAC/D,OAAO,CACR,CAEA,SAAgB,EACf,EACsE,CACtE,OAAO,CAMR,CAEA,eAAsB,EACrB,EACA,EAAqC,EACW,CAChD,IAAM,EAAQ,MAAM,QAAQ,IAC3B,EAAW,MAAM,IAAI,KAAO,IACvB,EAAK,OAAS,YAAc,EAAK,OAAS,SACtC,CACN,KAAM,EAAK,KACX,IAAK,EAAK,IACV,SAAU,CACT,KAAM,EAAK,KACX,OAAQ,MAAM,EAAa,EAAK,OAAO,EACvC,MAAO,EAAK,KACb,CACD,EAEG,EAAK,OAAS,SACV,CACN,KAAM,EAAK,KACX,IAAK,EAAK,IACV,SAAU,CACT,KAAM,SACN,OAAQ,MAAM,EAAa,EAAK,OAAO,EACvC,MAAO,EAAK,KACb,CACD,EAEG,EAAK,OAAS,WACV,CACN,GAAG,EACH,UAAW,CAAC,GAAG,EAAK,SAAS,EAC7B,OAAQ,CAAE,GAAG,EAAK,MAAO,CAC1B,EAEM,CAAE,GAAG,CAAK,CACjB,CACF,EAOA,OAAO,EANY,EAA2B,MAAM,CACnD,cAAe,EACf,iBAAkB,EAAW,iBAC7B,KAAM,EAAW,KACjB,OACD,CAC2B,CAAC,CAC7B,CAEA,SAAS,EAAkB,EAA+B,CACzD,GAAI,GAAS,OAAO,GAAU,SAAU,CACvC,OAAO,OAAO,CAAK,EACnB,IAAK,IAAM,KAAU,OAAO,OAAO,CAAK,EAAG,EAAW,CAAM,CAC7D,CACA,OAAO,CACR"}
@@ -0,0 +1,40 @@
1
+ import { command_d_exports } from "../modules/command/command.mjs";
2
+ import { observability_d_exports } from "../modules/observability/observability.mjs";
3
+ import { query_d_exports } from "../modules/query/query.mjs";
4
+ import { result_d_exports } from "../result.mjs";
5
+ import { telemetry_d_exports } from "../telemetry.mjs";
6
+ import { client_d_exports } from "../client.mjs";
7
+ import { functions_d_exports } from "../functions.mjs";
8
+ import { ApiFromModules, FilterApi, FunctionReference } from "convex/server";
9
+ //#region src/components/foundation/_generated/api.d.ts
10
+ declare const fullApi: ApiFromModules<{
11
+ client: typeof client_d_exports;
12
+ functions: typeof functions_d_exports;
13
+ "modules/command/command": typeof command_d_exports;
14
+ "modules/observability/observability": typeof observability_d_exports;
15
+ "modules/query/query": typeof query_d_exports;
16
+ result: typeof result_d_exports;
17
+ telemetry: typeof telemetry_d_exports;
18
+ }>;
19
+ /**
20
+ * A utility for referencing Convex functions in your app's public API.
21
+ *
22
+ * Usage:
23
+ * ```js
24
+ * const myFunctionReference = api.myModule.myFunction;
25
+ * ```
26
+ */
27
+ declare const api: FilterApi<typeof fullApi, FunctionReference<any, "public">>;
28
+ /**
29
+ * A utility for referencing Convex functions in your app's internal API.
30
+ *
31
+ * Usage:
32
+ * ```js
33
+ * const myFunctionReference = internal.myModule.myFunction;
34
+ * ```
35
+ */
36
+ declare const internal: FilterApi<typeof fullApi, FunctionReference<any, "internal">>;
37
+ declare const components: {};
38
+ //#endregion
39
+ export { api, components, internal };
40
+ //# sourceMappingURL=api.d.mts.map
@@ -0,0 +1,2 @@
1
+ import{anyApi as e,componentsGeneric as t}from"convex/server";const n=e,r=e,i=t();export{n as api,i as components,r as internal};
2
+ //# sourceMappingURL=api.mjs.map
@@ -0,0 +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,MAAa,EAGT,EAUS,EAGT,EAES,EAAa,EAAkB"}
@@ -0,0 +1,21 @@
1
+ import { FunctionReference } from "convex/server";
2
+ //#region src/components/foundation/_generated/component.d.ts
3
+ /**
4
+ * A utility for referencing a Convex component's exposed API.
5
+ *
6
+ * Useful when expecting a parameter like `components.myComponent`.
7
+ * Usage:
8
+ * ```ts
9
+ * async function myFunction(ctx: QueryCtx, component: ComponentApi) {
10
+ * return ctx.runQuery(component.someFile.someQuery, { ...args });
11
+ * }
12
+ * ```
13
+ */
14
+ type ComponentApi<Name extends string | undefined = string | undefined> = {
15
+ functions: {
16
+ status: FunctionReference<"query", "internal", {}, "ready", Name>;
17
+ };
18
+ };
19
+ //#endregion
20
+ export { ComponentApi };
21
+ //# sourceMappingURL=component.d.mts.map
@@ -0,0 +1,41 @@
1
+ import _default from "../schema.mjs";
2
+ import { DataModelFromSchemaDefinition, DocumentByName, SystemTableNames, TableNamesInDataModel } from "convex/server";
3
+ import { GenericId } from "convex/values";
4
+ //#region src/components/foundation/_generated/dataModel.d.ts
5
+ /**
6
+ * The names of all of your Convex tables.
7
+ */
8
+ type TableNames = TableNamesInDataModel<DataModel>;
9
+ /**
10
+ * The type of a document stored in Convex.
11
+ *
12
+ * @typeParam TableName - A string literal type of the table name (like "users").
13
+ */
14
+ type Doc<TableName extends TableNames> = DocumentByName<DataModel, TableName>;
15
+ /**
16
+ * An identifier for a document in Convex.
17
+ *
18
+ * Convex documents are uniquely identified by their `Id`, which is accessible
19
+ * on the `_id` field. To learn more, see [Document IDs](https://docs.convex.dev/using/document-ids).
20
+ *
21
+ * Documents can be loaded using `db.get(tableName, id)` in query and mutation functions.
22
+ *
23
+ * IDs are just strings at runtime, but this type can be used to distinguish them from other
24
+ * strings when type checking.
25
+ *
26
+ * @typeParam TableName - A string literal type of the table name (like "users").
27
+ */
28
+ type Id<TableName extends TableNames | SystemTableNames> = GenericId<TableName>;
29
+ /**
30
+ * A type describing your Convex data model.
31
+ *
32
+ * This type includes information about what tables you have, the type of
33
+ * documents stored in those tables, and the indexes defined on them.
34
+ *
35
+ * This type is used to parameterize methods like `queryGeneric` and
36
+ * `mutationGeneric` to make them type-safe.
37
+ */
38
+ type DataModel = DataModelFromSchemaDefinition<typeof _default>;
39
+ //#endregion
40
+ export { DataModel, Doc, Id, TableNames };
41
+ //# sourceMappingURL=dataModel.d.mts.map
@@ -0,0 +1,116 @@
1
+ import { DataModel } from "./dataModel.mjs";
2
+ import { ActionBuilder, GenericActionCtx, GenericDatabaseReader, GenericDatabaseWriter, GenericMutationCtx, GenericQueryCtx, HttpActionBuilder, MutationBuilder, QueryBuilder } from "convex/server";
3
+ //#region src/components/foundation/_generated/server.d.ts
4
+ /**
5
+ * Define a query in this Convex app's public API.
6
+ *
7
+ * This function will be allowed to read your Convex database and will be accessible from the client.
8
+ *
9
+ * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
10
+ * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
11
+ */
12
+ declare const query: QueryBuilder<DataModel, "public">;
13
+ /**
14
+ * Define a query that is only accessible from other Convex functions (but not from the client).
15
+ *
16
+ * This function will be allowed to read from your Convex database. It will not be accessible from the client.
17
+ *
18
+ * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
19
+ * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
20
+ */
21
+ declare const internalQuery: QueryBuilder<DataModel, "internal">;
22
+ /**
23
+ * Define a mutation in this Convex app's public API.
24
+ *
25
+ * This function will be allowed to modify your Convex database and will be accessible from the client.
26
+ *
27
+ * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
28
+ * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
29
+ */
30
+ declare const mutation: MutationBuilder<DataModel, "public">;
31
+ /**
32
+ * Define a mutation that is only accessible from other Convex functions (but not from the client).
33
+ *
34
+ * This function will be allowed to modify your Convex database. It will not be accessible from the client.
35
+ *
36
+ * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
37
+ * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
38
+ */
39
+ declare const internalMutation: MutationBuilder<DataModel, "internal">;
40
+ /**
41
+ * Define an action in this Convex app's public API.
42
+ *
43
+ * An action is a function which can execute any JavaScript code, including non-deterministic
44
+ * code and code with side-effects, like calling third-party services.
45
+ * They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
46
+ * They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
47
+ *
48
+ * @param func - The action. It receives an {@link ActionCtx} as its first argument.
49
+ * @returns The wrapped action. Include this as an `export` to name it and make it accessible.
50
+ */
51
+ declare const action: ActionBuilder<DataModel, "public">;
52
+ /**
53
+ * Define an action that is only accessible from other Convex functions (but not from the client).
54
+ *
55
+ * @param func - The function. It receives an {@link ActionCtx} as its first argument.
56
+ * @returns The wrapped function. Include this as an `export` to name it and make it accessible.
57
+ */
58
+ declare const internalAction: ActionBuilder<DataModel, "internal">;
59
+ /**
60
+ * Define an HTTP action.
61
+ *
62
+ * The wrapped function will be used to respond to HTTP requests received
63
+ * by a Convex deployment if the requests matches the path and method where
64
+ * this action is routed. Be sure to route your httpAction in `convex/http.js`.
65
+ *
66
+ * @param func - The function. It receives an {@link ActionCtx} as its first argument
67
+ * and a Fetch API `Request` object as its second.
68
+ * @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
69
+ */
70
+ declare const httpAction: HttpActionBuilder;
71
+ /**
72
+ * A set of services for use within Convex query functions.
73
+ *
74
+ * The query context is passed as the first argument to any Convex query
75
+ * function run on the server.
76
+ *
77
+ * If you're using code generation, use the `QueryCtx` type in `convex/_generated/server.d.ts` instead.
78
+ */
79
+ type QueryCtx = GenericQueryCtx<DataModel>;
80
+ /**
81
+ * A set of services for use within Convex mutation functions.
82
+ *
83
+ * The mutation context is passed as the first argument to any Convex mutation
84
+ * function run on the server.
85
+ *
86
+ * If you're using code generation, use the `MutationCtx` type in `convex/_generated/server.d.ts` instead.
87
+ */
88
+ type MutationCtx = GenericMutationCtx<DataModel>;
89
+ /**
90
+ * A set of services for use within Convex action functions.
91
+ *
92
+ * The action context is passed as the first argument to any Convex action
93
+ * function run on the server.
94
+ */
95
+ type ActionCtx = GenericActionCtx<DataModel>;
96
+ /**
97
+ * An interface to read from the database within Convex query functions.
98
+ *
99
+ * The two entry points are {@link DatabaseReader.get}, which fetches a single
100
+ * document by its {@link Id}, or {@link DatabaseReader.query}, which starts
101
+ * building a query.
102
+ */
103
+ type DatabaseReader = GenericDatabaseReader<DataModel>;
104
+ /**
105
+ * An interface to read from and write to the database within Convex mutation
106
+ * functions.
107
+ *
108
+ * Convex guarantees that all writes within a single mutation are
109
+ * executed atomically, so you never have to worry about partial writes leaving
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
+ * for the guarantees Convex provides your functions.
112
+ */
113
+ type DatabaseWriter = GenericDatabaseWriter<DataModel>;
114
+ //#endregion
115
+ export { ActionCtx, DatabaseReader, DatabaseWriter, MutationCtx, QueryCtx, action, httpAction, internalAction, internalMutation, internalQuery, mutation, query };
116
+ //# sourceMappingURL=server.d.mts.map
@@ -0,0 +1,2 @@
1
+ import{actionGeneric as e,httpActionGeneric as t,internalActionGeneric as n,internalMutationGeneric as r,internalQueryGeneric as i,mutationGeneric as a,queryGeneric as o}from"convex/server";const s=o,c=i,l=a,u=r,d=e,f=n,p=t;export{d as action,p as httpAction,f as internalAction,u as internalMutation,c as internalQuery,l as mutation,s as query};
2
+ //# sourceMappingURL=server.mjs.map
@@ -0,0 +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,MAAa,EAA2C,EAU3C,EACX,EAUW,EAAiD,EAUjD,EACX,EAaW,EAA6C,EAQ7C,EACX,EAaW,EAAgC"}
@@ -0,0 +1,93 @@
1
+ import { CommandExecution, CommandInput, CommandRegistry, CommandResult, Parseable } from "./modules/command/command.mjs";
2
+ import { CommandObservation, Observability, ObservabilityOptions } from "./modules/observability/observability.mjs";
3
+ import { Query, QueryExecution } from "./modules/query/query.mjs";
4
+ import { Result, ResultBoundary, TransactionMetricsContext, executeResultBoundary, projectResult } from "./result.mjs";
5
+ import { emitSemanticEvent } from "./telemetry.mjs";
6
+ import _default from "./convex.config.mjs";
7
+ declare namespace client_d_exports {
8
+ export { ApplicationCommand, AuditEntryInput, AuditWriter, AuditedOperation, AuditedRegistry, CommandExecution, CommandInput, CommandObservation, CommandRegistry, CommandResult, Foundation, FoundationOptions, Observability, ObservabilityOptions, Parseable, Query, QueryExecution, Result, ResultBoundary, TransactionMetricsContext, _default as default, emitSemanticEvent, executeResultBoundary, projectResult };
9
+ }
10
+ /** Shape handed to the injected audit writer; classification comes from the operation. */
11
+ type AuditEntryInput = {
12
+ operation: string;
13
+ actorId: string;
14
+ aggregate: {
15
+ type: string;
16
+ id: string;
17
+ };
18
+ metadata?: Record<string, unknown>;
19
+ classification: string;
20
+ };
21
+ type AuditWriter = (context: never, entry: AuditEntryInput) => Promise<unknown> | unknown;
22
+ type MaybePromise<Value> = Value | Promise<Value>;
23
+ type OperationKey<Operations extends CommandRegistry> = Extract<keyof Operations, string>;
24
+ type AuditedOperation = Readonly<{
25
+ command: Readonly<{
26
+ parse: (value: unknown) => unknown;
27
+ }>;
28
+ result: Readonly<{
29
+ parse: (value: unknown) => unknown;
30
+ }>;
31
+ classification: string;
32
+ audit: (resolution: Readonly<{
33
+ command: never;
34
+ result: never;
35
+ }>, context: never) => MaybePromise<Omit<AuditEntryInput, 'classification'> | null>;
36
+ }>;
37
+ type AuditedRegistry = Readonly<Record<string, AuditedOperation>>;
38
+ type FoundationOptions = Readonly<{
39
+ observability: ObservabilityOptions & Readonly<{
40
+ /**
41
+ * In-transaction audit writer used by Command. Operations that
42
+ * return an audit record get it written here automatically.
43
+ */
44
+ writeAudit?: AuditWriter;
45
+ }>;
46
+ }>;
47
+ type FoundationComponentApi = Readonly<{
48
+ functions: Readonly<{
49
+ status: unknown;
50
+ }>;
51
+ }>;
52
+ /**
53
+ * Application command protocol bound to a Foundation instance:
54
+ * validate, observe, execute, and audit. `classification` and `audit()`
55
+ * are mandatory per operation — auditing is type-enforced, not opt-in.
56
+ * Obtain it by destructuring the Foundation: `const { Command } = new Foundation(...)`.
57
+ */
58
+ declare class BoundCommand<Context, const Operations extends AuditedRegistry> {
59
+ #private;
60
+ static operation<const Definition extends AuditedOperation>(definition: Definition): Definition;
61
+ constructor(operations: Operations, deps: {
62
+ observability: Observability;
63
+ writeAudit: AuditWriter;
64
+ });
65
+ exec<const Key extends OperationKey<Operations>>(executor: {
66
+ operation: Key;
67
+ handler: (context: Context, command: CommandInput<Operations, Key>) => MaybePromise<CommandResult<Operations, Key>>;
68
+ }): (context: Context, command: Operations[Key]["command"] extends (infer T) ? T extends Operations[Key]["command"] ? T extends Readonly<{
69
+ parse: (value: unknown) => infer Output;
70
+ }> ? Output : never : never : never) => Promise<Operations[Key]["result"] extends (infer T_1) ? T_1 extends Operations[Key]["result"] ? T_1 extends Readonly<{
71
+ parse: (value: unknown) => infer Output;
72
+ }> ? Output : never : never : never>;
73
+ }
74
+ type ApplicationCommand<Context, Operations extends AuditedRegistry> = BoundCommand<Context, Operations>;
75
+ type CommandConstructor = {
76
+ new <Context, const Operations extends AuditedRegistry>(operations: Operations): BoundCommand<Context, Operations>;
77
+ operation: (typeof BoundCommand)['operation'];
78
+ };
79
+ /**
80
+ * Host facade for a component that owns no application execution capability.
81
+ * Declared once; the sole source of the command protocol, query kernel, and
82
+ * observability: `const { Command, Query, observability } = new Foundation(...)`.
83
+ */
84
+ declare class Foundation<Component extends FoundationComponentApi = FoundationComponentApi> {
85
+ readonly status: Component['functions']['status'];
86
+ readonly Command: CommandConstructor;
87
+ readonly Query: typeof Query;
88
+ readonly observability: Observability;
89
+ constructor(component: Component, options: FoundationOptions);
90
+ }
91
+ //#endregion
92
+ export { ApplicationCommand, AuditEntryInput, AuditWriter, AuditedOperation, AuditedRegistry, type CommandExecution, type CommandInput, type CommandObservation, type CommandRegistry, type CommandResult, Foundation, FoundationOptions, Observability, type ObservabilityOptions, type Parseable, Query, type QueryExecution, type Result, type ResultBoundary, type TransactionMetricsContext, client_d_exports, _default as default, emitSemanticEvent, executeResultBoundary, projectResult };
93
+ //# sourceMappingURL=client.d.mts.map
@@ -0,0 +1,2 @@
1
+ import{Command as e}from"./modules/command/command.mjs";import{Observability as t}from"./modules/observability/observability.mjs";import{Query as n}from"./modules/query/query.mjs";import{executeResultBoundary as r,projectResult as i}from"./result.mjs";import{emitSemanticEvent as a}from"./telemetry.mjs";import o from"./convex.config.mjs";var s=class{#e;#t;#n;static operation(e){return e}constructor(t,n){this.#t=n.observability,this.#n=n.writeAudit,this.#e=new e({operations:t,execute:e=>this.#r(e)})}exec(e){return this.#e.exec(e)}async#r(e){return this.#t.observe({operation:e.operation,classification:e.definition.classification},async()=>{let t=await e.run(),n=await e.definition.audit({command:e.command,result:t},e.context);return n&&await this.#n(e.context,{...n,classification:e.definition.classification}),t})}},c=class{status;Command;Query=n;observability;constructor(e,n){this.status=e.functions.status;let r=new t(n.observability);this.observability=r;let i=n.observability.writeAudit??(()=>void 0);this.Command=class extends s{constructor(e){super(e,{observability:r,writeAudit:i})}}}};export{c as Foundation,t as Observability,n as Query,o as default,a as emitSemanticEvent,r as executeResultBoundary,i as projectResult};
2
+ //# sourceMappingURL=client.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.mjs","names":["#kernel","#observability","#writeAudit","CommandKernelClass","#execute"],"sources":["../../../src/components/foundation/client.ts"],"sourcesContent":["import {\n\tCommand as CommandKernelClass,\n\ttype CommandExecution,\n\ttype CommandInput,\n\ttype CommandRegistry,\n\ttype CommandResult,\n} from './modules/command/command'\nimport {\n\tObservability,\n\ttype ObservabilityOptions,\n} from './modules/observability/observability'\nimport { Query } from './modules/query/query'\n\n/** Shape handed to the injected audit writer; classification comes from the operation. */\nexport type AuditEntryInput = {\n\toperation: string\n\tactorId: string\n\taggregate: { type: string; id: string }\n\tmetadata?: Record<string, unknown>\n\tclassification: string\n}\n\nexport type AuditWriter = (\n\tcontext: never,\n\tentry: AuditEntryInput,\n) => Promise<unknown> | unknown\n\ntype MaybePromise<Value> = Value | Promise<Value>\ntype OperationKey<Operations extends CommandRegistry> = Extract<\n\tkeyof Operations,\n\tstring\n>\n\nexport type AuditedOperation = Readonly<{\n\tcommand: Readonly<{ parse: (value: unknown) => unknown }>\n\tresult: Readonly<{ parse: (value: unknown) => unknown }>\n\tclassification: string\n\taudit: (\n\t\tresolution: Readonly<{ command: never; result: never }>,\n\t\tcontext: never,\n\t) => MaybePromise<Omit<AuditEntryInput, 'classification'> | null>\n}>\n\nexport type AuditedRegistry = Readonly<Record<string, AuditedOperation>>\n\nexport type FoundationOptions = Readonly<{\n\tobservability: ObservabilityOptions &\n\t\tReadonly<{\n\t\t\t/**\n\t\t\t * In-transaction audit writer used by Command. Operations that\n\t\t\t * return an audit record get it written here automatically.\n\t\t\t */\n\t\t\twriteAudit?: AuditWriter\n\t\t}>\n}>\n\ntype FoundationComponentApi = Readonly<{\n\tfunctions: Readonly<{ status: unknown }>\n}>\n\n/**\n * Application command protocol bound to a Foundation instance:\n * validate, observe, execute, and audit. `classification` and `audit()`\n * are mandatory per operation — auditing is type-enforced, not opt-in.\n * Obtain it by destructuring the Foundation: `const { Command } = new Foundation(...)`.\n */\nclass BoundCommand<Context, const Operations extends AuditedRegistry> {\n\treadonly #kernel: CommandKernelClass<Context, Operations>\n\treadonly #observability: Observability\n\treadonly #writeAudit: AuditWriter\n\n\tstatic operation<const Definition extends AuditedOperation>(\n\t\tdefinition: Definition,\n\t): Definition {\n\t\treturn definition\n\t}\n\n\tconstructor(\n\t\toperations: Operations,\n\t\tdeps: { observability: Observability; writeAudit: AuditWriter },\n\t) {\n\t\tthis.#observability = deps.observability\n\t\tthis.#writeAudit = deps.writeAudit\n\t\tthis.#kernel = new CommandKernelClass<Context, Operations>({\n\t\t\toperations,\n\t\t\texecute: (execution) => this.#execute(execution),\n\t\t})\n\t}\n\n\texec<const Key extends OperationKey<Operations>>(executor: {\n\t\toperation: Key\n\t\thandler: (\n\t\t\tcontext: Context,\n\t\t\tcommand: CommandInput<Operations, Key>,\n\t\t) => MaybePromise<CommandResult<Operations, Key>>\n\t}) {\n\t\treturn this.#kernel.exec(executor)\n\t}\n\n\tasync #execute<Key extends OperationKey<Operations>>(\n\t\texecution: CommandExecution<Context, Operations, Key>,\n\t): Promise<CommandResult<Operations, Key>> {\n\t\treturn this.#observability.observe(\n\t\t\t{\n\t\t\t\toperation: execution.operation,\n\t\t\t\tclassification: execution.definition.classification,\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\tconst result = await execution.run()\n\t\t\t\tconst audit = await execution.definition.audit(\n\t\t\t\t\t{ command: execution.command, result } as never,\n\t\t\t\t\texecution.context as never,\n\t\t\t\t)\n\t\t\t\tif (audit) {\n\t\t\t\t\tawait this.#writeAudit(execution.context as never, {\n\t\t\t\t\t\t...audit,\n\t\t\t\t\t\tclassification: execution.definition.classification,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\treturn result\n\t\t\t},\n\t\t)\n\t}\n}\n\nexport type ApplicationCommand<\n\tContext,\n\tOperations extends AuditedRegistry,\n> = BoundCommand<Context, Operations>\n\ntype CommandConstructor = {\n\tnew <Context, const Operations extends AuditedRegistry>(\n\t\toperations: Operations,\n\t): BoundCommand<Context, Operations>\n\toperation: (typeof BoundCommand)['operation']\n}\n\n/**\n * Host facade for a component that owns no application execution capability.\n * Declared once; the sole source of the command protocol, query kernel, and\n * observability: `const { Command, Query, observability } = new Foundation(...)`.\n */\nexport class Foundation<\n\tComponent extends FoundationComponentApi = FoundationComponentApi,\n> {\n\treadonly status: Component['functions']['status']\n\treadonly Command: CommandConstructor\n\treadonly Query = Query\n\treadonly observability: Observability\n\n\tconstructor(component: Component, options: FoundationOptions) {\n\t\tthis.status = component.functions.status\n\t\tconst observability = new Observability(options.observability)\n\t\tthis.observability = observability\n\t\tconst writeAudit = options.observability.writeAudit ?? (() => undefined)\n\t\tthis.Command = class <\n\t\t\tContext,\n\t\t\tconst Operations extends AuditedRegistry,\n\t\t> extends BoundCommand<Context, Operations> {\n\t\t\tconstructor(operations: Operations) {\n\t\t\t\tsuper(operations, { observability, writeAudit })\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport type {\n\tCommandExecution,\n\tCommandInput,\n\tCommandRegistry,\n\tCommandResult,\n\tParseable,\n} from './modules/command/command'\nexport { Observability } from './modules/observability/observability'\nexport type {\n\tCommandObservation,\n\tObservabilityOptions,\n} from './modules/observability/observability'\nexport { Query } from './modules/query/query'\nexport type { QueryExecution } from './modules/query/query'\nexport { executeResultBoundary, projectResult } from './result'\nexport type {\n\tResult,\n\tResultBoundary,\n\tTransactionMetricsContext,\n} from './result'\nexport { emitSemanticEvent } from './telemetry'\n\n// Component definition as default export: `import foundation from \"cvx-kit/components/foundation\"` → app.use(foundation)\nexport { default } from \"./convex.config\"\n"],"mappings":"mVAkEA,IAAM,EAAN,KAAsE,CACrE,GACA,GACA,GAEA,OAAO,UACN,EACa,CACb,OAAO,CACR,CAEA,YACC,EACA,EACC,CACD,KAAKC,GAAiB,EAAK,cAC3B,KAAKC,GAAc,EAAK,WACxB,KAAKF,GAAU,IAAIG,EAAwC,CAC1D,aACA,QAAU,GAAc,KAAKC,GAAS,CAAS,CAChD,CAAC,CACF,CAEA,KAAiD,EAM9C,CACF,OAAO,KAAKJ,GAAQ,KAAK,CAAQ,CAClC,CAEA,KAAMI,GACL,EAC0C,CAC1C,OAAO,KAAKH,GAAe,QAC1B,CACC,UAAW,EAAU,UACrB,eAAgB,EAAU,WAAW,cACtC,EACA,SAAY,CACX,IAAM,EAAS,MAAM,EAAU,IAAI,EAC7B,EAAQ,MAAM,EAAU,WAAW,MACxC,CAAE,QAAS,EAAU,QAAS,QAAO,EACrC,EAAU,OACX,EAOA,OANI,GACH,MAAM,KAAKC,GAAY,EAAU,QAAkB,CAClD,GAAG,EACH,eAAgB,EAAU,WAAW,cACtC,CAAC,EAEK,CACR,CACD,CACD,CACD,EAmBa,EAAb,KAEE,CACD,OACA,QACA,MAAiB,EACjB,cAEA,YAAY,EAAsB,EAA4B,CAC7D,KAAK,OAAS,EAAU,UAAU,OAClC,IAAM,EAAgB,IAAI,EAAc,EAAQ,aAAa,EAC7D,KAAK,cAAgB,EACrB,IAAM,EAAa,EAAQ,cAAc,iBAAqB,IAAA,IAC9D,KAAK,QAAU,cAGL,CAAkC,CAC3C,YAAY,EAAwB,CACnC,MAAM,EAAY,CAAE,gBAAe,YAAW,CAAC,CAChD,CACD,CACD,CACD"}
@@ -0,0 +1,5 @@
1
+ //#region src/components/foundation/convex.config.d.ts
2
+ declare const _default: import("convex/server").ComponentDefinition<any, {}>;
3
+ //#endregion
4
+ export { _default as default };
5
+ //# sourceMappingURL=convex.config.d.mts.map
@@ -0,0 +1,2 @@
1
+ import{defineComponent as e}from"convex/server";var t=e(`foundation`);export{t as default};
2
+ //# sourceMappingURL=convex.config.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convex.config.mjs","names":[],"sources":["../../../src/components/foundation/convex.config.ts"],"sourcesContent":["import { defineComponent } from 'convex/server'\n\nexport default defineComponent('foundation')\n"],"mappings":"gDAEA,IAAA,EAAe,EAAgB,YAAY"}
@@ -0,0 +1,8 @@
1
+ declare namespace functions_d_exports {
2
+ export { status };
3
+ }
4
+ /** Minimal health signal exposed only through the configured host facade. */
5
+ declare const status: import("convex/server").RegisteredQuery<"public", {}, Promise<"ready">>;
6
+ //#endregion
7
+ export { functions_d_exports, status };
8
+ //# sourceMappingURL=functions.d.mts.map
@@ -0,0 +1,2 @@
1
+ import{query as e}from"./_generated/server.mjs";import{v as t}from"convex/values";const n=e({args:{},returns:t.literal(`ready`),handler:async()=>`ready`});export{n as status};
2
+ //# sourceMappingURL=functions.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functions.mjs","names":[],"sources":["../../../src/components/foundation/functions.ts"],"sourcesContent":["import { v } from 'convex/values'\n\nimport { query } from './_generated/server'\n\n/** Minimal health signal exposed only through the configured host facade. */\nexport const status = query({\n\targs: {},\n\treturns: v.literal('ready'),\n\thandler: async () => 'ready' as const,\n})\n"],"mappings":"kFAKA,MAAa,EAAS,EAAM,CAC3B,KAAM,CAAC,EACP,QAAS,EAAE,QAAQ,OAAO,EAC1B,QAAS,SAAY,OACtB,CAAC"}