cvx-kit 0.1.27 → 0.1.29

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.
@@ -1,4 +1,4 @@
1
- import { GenericDataModel, TableNamesInDataModel } from "convex/server";
1
+ import { GenericDataModel, GenericMutationCtx, TableNamesInDataModel } from "convex/server";
2
2
  import { Change, Trigger, Triggers } from "convex-helpers/server/triggers";
3
3
  //#region src/triggers.d.ts
4
4
  /**
@@ -8,6 +8,10 @@ import { Change, Trigger, Triggers } from "convex-helpers/server/triggers";
8
8
  * structural, not a convention.
9
9
  */
10
10
  export declare function createTriggers<DataModel extends GenericDataModel>(): Triggers<DataModel>;
11
+ /** Customize zCustomMutation/customMutation with this component's trigger registry. */
12
+ export declare function triggerContext<DataModel extends GenericDataModel>(triggers: Triggers<DataModel>): import("convex-helpers/server/customFunctions").Customization<GenericMutationCtx<DataModel>, Record<string, never>, {
13
+ db: import("convex/server").GenericDatabaseWriter<DataModel>;
14
+ }, Record<string, never>, Record<string, any>>;
11
15
  /**
12
16
  * Marks tables as append-only evidence tables: inserts pass, every update or
13
17
  * delete throws. The ontology pattern for votes/history/audit-style tables.
package/dist/triggers.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{z as e}from"zod";import{Triggers as t}from"convex-helpers/server/triggers";function n(){return new t}function r(e,...t){for(let n of t)e.register(n,async(e,t)=>{if(t.operation!==`insert`)throw Error(`${n} is append-only`)})}function i(e,...t){for(let n of t)e.register(n,async(e,t)=>{if(t.operation===`delete`)throw Error(`${n} rows cannot be deleted`)})}function a(e,...t){for(let n of t)e.register(n,async(e,t)=>{if(t.operation===`insert`){if(!s.safeParse(t.newDoc).success)throw Error(`${n} rows require a tenant`);return}if(t.operation===`update`){let e=t.oldDoc,r=t.newDoc;if(e.tenant!==r.tenant)throw Error(`${n} tenant ownership cannot be reassigned`)}})}function o(e,...t){for(let n of t)e.register(n,async(e,t)=>{if(t.operation===`delete`)return;let n=Date.now();if(t.operation===`insert`){t.newDoc.createdAt===void 0&&await e.innerDb.patch(t.id,{createdAt:n,updatedAt:n});return}let r=t.oldDoc;t.newDoc.updatedAt===r.updatedAt&&await e.innerDb.patch(t.id,{updatedAt:n})})}const s=e.object({tenant:e.string().min(1)});export{t as Triggers,r as appendOnly,n as createTriggers,i as noDelete,a as tenantOwnership,o as timestamps};
1
+ import{z as e}from"zod";import{customCtx as t}from"convex-helpers/server/customFunctions";import{Triggers as n}from"convex-helpers/server/triggers";function r(){return new n}function i(e){return t(t=>({db:e.wrapDB(t).db}))}function a(e,...t){for(let n of t)e.register(n,async(e,t)=>{if(t.operation!==`insert`)throw Error(`${n} is append-only`)})}function o(e,...t){for(let n of t)e.register(n,async(e,t)=>{if(t.operation===`delete`)throw Error(`${n} rows cannot be deleted`)})}function s(e,...t){for(let n of t)e.register(n,async(e,t)=>{if(t.operation===`insert`){if(!l.safeParse(t.newDoc).success)throw Error(`${n} rows require a tenant`);return}if(t.operation===`update`){let e=t.oldDoc,r=t.newDoc;if(e.tenant!==r.tenant)throw Error(`${n} tenant ownership cannot be reassigned`)}})}function c(e,...t){for(let n of t)e.register(n,async(e,t)=>{if(t.operation===`delete`)return;let n=Date.now();if(t.operation===`insert`){t.newDoc.createdAt===void 0&&await e.innerDb.patch(t.id,{createdAt:n,updatedAt:n});return}let r=t.oldDoc;t.newDoc.updatedAt===r.updatedAt&&await e.innerDb.patch(t.id,{updatedAt:n})})}const l=e.object({tenant:e.string().min(1)});export{n as Triggers,a as appendOnly,r as createTriggers,o as noDelete,s as tenantOwnership,c as timestamps,i as triggerContext};
2
2
  //# sourceMappingURL=triggers.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"triggers.mjs","names":["createTriggers","Triggers","appendOnly","tables","table","triggers","change","noDelete","tenantOwnership","tenantDocument","previous","current","timestamps","now","ctx","z"],"sources":["../src/triggers.ts"],"sourcesContent":["import { z } from 'zod'\nimport { Triggers, type Change, type Trigger } from 'convex-helpers/server/triggers'\nimport type { GenericDataModel, TableNamesInDataModel } from 'convex/server'\n\nexport { Triggers }\nexport type { Change, Trigger }\n\n/**\n * One application-wide mutation interceptor registry. Pass it to\n * createAuthFunctions({ triggers }) so every authMutation/roleMutation/\n * systemMutation runs writes through it — trigger enforcement becomes\n * structural, not a convention.\n */\nexport function createTriggers<DataModel extends GenericDataModel>(): Triggers<DataModel> {\n\treturn new Triggers<DataModel>()\n}\n\n/**\n * Marks tables as append-only evidence tables: inserts pass, every update or\n * delete throws. The ontology pattern for votes/history/audit-style tables.\n */\nexport function appendOnly<DataModel extends GenericDataModel>(\n\ttriggers: Triggers<DataModel>,\n\t...tables: readonly TableNamesInDataModel<DataModel>[]\n) {\n\tfor (const table of tables) {\n\t\ttriggers.register(table, async (_ctx, change) => {\n\t\t\tif (change.operation !== 'insert') {\n\t\t\t\tthrow new Error(`${table} is append-only`)\n\t\t\t}\n\t\t})\n\t}\n}\n\n/** Forbids hard deletes on the given tables (soft-delete discipline). */\nexport function noDelete<DataModel extends GenericDataModel>(\n\ttriggers: Triggers<DataModel>,\n\t...tables: readonly TableNamesInDataModel<DataModel>[]\n) {\n\tfor (const table of tables) {\n\t\ttriggers.register(table, async (_ctx, change) => {\n\t\t\tif (change.operation === 'delete') {\n\t\t\t\tthrow new Error(`${table} rows cannot be deleted`)\n\t\t\t}\n\t\t})\n\t}\n}\n\n/**\n * Post-image tenant invariant for tenantTable rows. Row-level security\n * authorizes a modification against the PRE-image, so ownership must also be\n * enforced against the post-image: inserts must carry a tenant, and updates\n * may never reassign it. Register for every tenant table (same registry that\n * drives createTenantRules).\n */\nexport function tenantOwnership<DataModel extends GenericDataModel>(\n\ttriggers: Triggers<DataModel>,\n\t...tables: readonly TableNamesInDataModel<DataModel>[]\n) {\n\tfor (const table of tables) {\n\t\ttriggers.register(table, async (_ctx, change) => {\n\t\t\tif (change.operation === 'insert') {\n\t\t\t\tconst ownership = tenantDocument.safeParse(change.newDoc)\n\t\t\t\tif (!ownership.success) {\n\t\t\t\t\tthrow new Error(`${table} rows require a tenant`)\n\t\t\t\t}\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif (change.operation === 'update') {\n\t\t\t\tconst previous = change.oldDoc\n\t\t\t\tconst current = change.newDoc\n\t\t\t\tif (previous.tenant !== current.tenant) {\n\t\t\t\t\tthrow new Error(`${table} tenant ownership cannot be reassigned`)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n}\n\n/**\n * Maintains zod-table's opinionated lifecycle timestamps: createdAt and\n * updatedAt on insert, updatedAt on every update. archivedAt stays under\n * application control. Register once per table; writes made through the\n * auth constructors keep these fields correct automatically.\n */\nexport function timestamps<DataModel extends GenericDataModel>(\n\ttriggers: Triggers<DataModel>,\n\t...tables: readonly TableNamesInDataModel<DataModel>[]\n) {\n\tfor (const table of tables) {\n\t\ttriggers.register(table, async (ctx, change) => {\n\t\t\tif (change.operation === 'delete') return\n\t\t\tconst now = Date.now()\n\t\t\tif (change.operation === 'insert') {\n\t\t\t\tconst document = change.newDoc\n\t\t\t\tif (document.createdAt === undefined) {\n\t\t\t\t\t// SAFETY: registration requires zod-table lifecycle fields; Convex validates this numeric timestamp patch.\n\t\t\t\t\tawait ctx.innerDb.patch(change.id, {\n\t\t\t\t\t\tcreatedAt: now,\n\t\t\t\t\t\tupdatedAt: now,\n\t\t\t\t\t} as never)\n\t\t\t\t}\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst previous = change.oldDoc\n\t\t\tconst current = change.newDoc\n\t\t\t// A write that already moved updatedAt (including our own patch)\n\t\t\t// is left alone — this is the recursion guard.\n\t\t\tif (current.updatedAt === previous.updatedAt) {\n\t\t\t\t// SAFETY: registration requires zod-table lifecycle fields; Convex validates this numeric timestamp patch.\n\t\t\t\tawait ctx.innerDb.patch(change.id, { updatedAt: now } as never)\n\t\t\t}\n\t\t})\n\t}\n}\n\nconst tenantDocument = z.object({ tenant: z.string().min(1) })\n"],"mappings":"kFAaA,SAAgBA,GAA0E,CACzF,OAAO,IAAIC,CACZ,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,CAAI,CAAU,CAEhE,CAAC,CAEH,CAEA,MAAMJ,EAAiBM,EAAE,OAAO,CAAE,OAAQA,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAE,CAAC"}
1
+ {"version":3,"file":"triggers.mjs","names":["createTriggers","Triggers","triggerContext","customCtx","triggers","ctx","appendOnly","tables","table","change","noDelete","tenantOwnership","tenantDocument","previous","current","timestamps","now","z"],"sources":["../src/triggers.ts"],"sourcesContent":["import { z } from 'zod'\nimport { Triggers, type Change, type Trigger } from 'convex-helpers/server/triggers'\nimport type { GenericDataModel, GenericMutationCtx, TableNamesInDataModel } from 'convex/server'\nimport { customCtx } from 'convex-helpers/server/customFunctions'\n\nexport { Triggers }\nexport type { Change, Trigger }\n\n/**\n * One application-wide mutation interceptor registry. Pass it to\n * createAuthFunctions({ triggers }) so every authMutation/roleMutation/\n * systemMutation runs writes through it — trigger enforcement becomes\n * structural, not a convention.\n */\nexport function createTriggers<DataModel extends GenericDataModel>(): Triggers<DataModel> {\n\treturn new Triggers<DataModel>()\n}\n\n/** Customize zCustomMutation/customMutation with this component's trigger registry. */\nexport function triggerContext<DataModel extends GenericDataModel>(triggers: Triggers<DataModel>) {\n\treturn customCtx((ctx: GenericMutationCtx<DataModel>) => ({ db: triggers.wrapDB(ctx).db }))\n}\n\n/**\n * Marks tables as append-only evidence tables: inserts pass, every update or\n * delete throws. The ontology pattern for votes/history/audit-style tables.\n */\nexport function appendOnly<DataModel extends GenericDataModel>(\n\ttriggers: Triggers<DataModel>,\n\t...tables: readonly TableNamesInDataModel<DataModel>[]\n) {\n\tfor (const table of tables) {\n\t\ttriggers.register(table, async (_ctx, change) => {\n\t\t\tif (change.operation !== 'insert') {\n\t\t\t\tthrow new Error(`${table} is append-only`)\n\t\t\t}\n\t\t})\n\t}\n}\n\n/** Forbids hard deletes on the given tables (soft-delete discipline). */\nexport function noDelete<DataModel extends GenericDataModel>(\n\ttriggers: Triggers<DataModel>,\n\t...tables: readonly TableNamesInDataModel<DataModel>[]\n) {\n\tfor (const table of tables) {\n\t\ttriggers.register(table, async (_ctx, change) => {\n\t\t\tif (change.operation === 'delete') {\n\t\t\t\tthrow new Error(`${table} rows cannot be deleted`)\n\t\t\t}\n\t\t})\n\t}\n}\n\n/**\n * Post-image tenant invariant for tenantTable rows. Row-level security\n * authorizes a modification against the PRE-image, so ownership must also be\n * enforced against the post-image: inserts must carry a tenant, and updates\n * may never reassign it. Register for every tenant table (same registry that\n * drives createTenantRules).\n */\nexport function tenantOwnership<DataModel extends GenericDataModel>(\n\ttriggers: Triggers<DataModel>,\n\t...tables: readonly TableNamesInDataModel<DataModel>[]\n) {\n\tfor (const table of tables) {\n\t\ttriggers.register(table, async (_ctx, change) => {\n\t\t\tif (change.operation === 'insert') {\n\t\t\t\tconst ownership = tenantDocument.safeParse(change.newDoc)\n\t\t\t\tif (!ownership.success) {\n\t\t\t\t\tthrow new Error(`${table} rows require a tenant`)\n\t\t\t\t}\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif (change.operation === 'update') {\n\t\t\t\tconst previous = change.oldDoc\n\t\t\t\tconst current = change.newDoc\n\t\t\t\tif (previous.tenant !== current.tenant) {\n\t\t\t\t\tthrow new Error(`${table} tenant ownership cannot be reassigned`)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n}\n\n/**\n * Maintains zod-table's opinionated lifecycle timestamps: createdAt and\n * updatedAt on insert, updatedAt on every update. archivedAt stays under\n * application control. Register once per table; writes made through the\n * auth constructors keep these fields correct automatically.\n */\nexport function timestamps<DataModel extends GenericDataModel>(\n\ttriggers: Triggers<DataModel>,\n\t...tables: readonly TableNamesInDataModel<DataModel>[]\n) {\n\tfor (const table of tables) {\n\t\ttriggers.register(table, async (ctx, change) => {\n\t\t\tif (change.operation === 'delete') return\n\t\t\tconst now = Date.now()\n\t\t\tif (change.operation === 'insert') {\n\t\t\t\tconst document = change.newDoc\n\t\t\t\tif (document.createdAt === undefined) {\n\t\t\t\t\t// SAFETY: registration requires zod-table lifecycle fields; Convex validates this numeric timestamp patch.\n\t\t\t\t\tawait ctx.innerDb.patch(change.id, {\n\t\t\t\t\t\tcreatedAt: now,\n\t\t\t\t\t\tupdatedAt: now,\n\t\t\t\t\t} as never)\n\t\t\t\t}\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst previous = change.oldDoc\n\t\t\tconst current = change.newDoc\n\t\t\t// A write that already moved updatedAt (including our own patch)\n\t\t\t// is left alone — this is the recursion guard.\n\t\t\tif (current.updatedAt === previous.updatedAt) {\n\t\t\t\t// SAFETY: registration requires zod-table lifecycle fields; Convex validates this numeric timestamp patch.\n\t\t\t\tawait ctx.innerDb.patch(change.id, { updatedAt: now } as never)\n\t\t\t}\n\t\t})\n\t}\n}\n\nconst tenantDocument = z.object({ tenant: z.string().min(1) })\n"],"mappings":"oJAcA,SAAgBA,GAA0E,CACzF,OAAO,IAAIC,CACZ,CAGA,SAAgBC,EAAmD,EAA+B,CACjG,OAAOC,EAAW,IAAwC,CAAE,GAAIC,EAAS,OAAOC,CAAG,CAAC,CAAC,EAAG,EAAE,CAC3F,CAMA,SAAgBC,EACf,EACA,GAAGC,EACF,CACD,IAAK,IAAMC,KAASD,EACnBH,EAAS,SAASI,EAAO,MAAO,EAAM,IAAW,CAChD,GAAIC,EAAO,YAAc,SACxB,MAAU,MAAM,GAAGD,EAAM,gBAAgB,CAE3C,CAAC,CAEH,CAGA,SAAgBE,EACf,EACA,GAAGH,EACF,CACD,IAAK,IAAMC,KAASD,EACnBH,EAAS,SAASI,EAAO,MAAO,EAAM,IAAW,CAChD,GAAIC,EAAO,YAAc,SACxB,MAAU,MAAM,GAAGD,EAAM,wBAAwB,CAEnD,CAAC,CAEH,CASA,SAAgBG,EACf,EACA,GAAGJ,EACF,CACD,IAAK,IAAMC,KAASD,EACnBH,EAAS,SAASI,EAAO,MAAO,EAAM,IAAW,CAChD,GAAIC,EAAO,YAAc,SAAU,CAElC,GAAI,CADcG,EAAe,UAAUH,EAAO,MACrC,CAAC,CAAC,QACd,MAAU,MAAM,GAAGD,EAAM,uBAAuB,EAEjD,MACD,CACA,GAAIC,EAAO,YAAc,SAAU,CAClC,IAAMI,EAAWJ,EAAO,OAClBK,EAAUL,EAAO,OACvB,GAAII,EAAS,SAAWC,EAAQ,OAC/B,MAAU,MAAM,GAAGN,EAAM,uCAAuC,CAElE,CACD,CAAC,CAEH,CAQA,SAAgBO,EACf,EACA,GAAGR,EACF,CACD,IAAK,IAAMC,KAASD,EACnBH,EAAS,SAASI,EAAO,MAAO,EAAK,IAAW,CAC/C,GAAIC,EAAO,YAAc,SAAU,OACnC,IAAMO,EAAM,KAAK,IAAI,EACrB,GAAIP,EAAO,YAAc,SAAU,CACjBA,EAAO,OACX,YAAc,IAAA,IAE1B,MAAMJ,EAAI,QAAQ,MAAMI,EAAO,GAAI,CAClC,UAAWO,EACX,UAAWA,CACZ,CAAU,EAEX,MACD,CACA,IAAMH,EAAWJ,EAAO,OACRA,EAAO,OAGX,YAAcI,EAAS,WAElC,MAAMR,EAAI,QAAQ,MAAMI,EAAO,GAAI,CAAE,UAAWO,CAAI,CAAU,CAEhE,CAAC,CAEH,CAEA,MAAMJ,EAAiBK,EAAE,OAAO,CAAE,OAAQA,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAE,CAAC"}
@@ -1,10 +1,15 @@
1
1
  import { CustomBuilder } from "convex-helpers/server/zod4";
2
- import { ActionBuilder, FunctionVisibility, GenericActionCtx, GenericDataModel, GenericMutationCtx, GenericQueryCtx, MutationBuilder, QueryBuilder } from "convex/server";
2
+ import { ActionBuilder, DefaultFunctionArgs, FunctionVisibility, GenericActionCtx, GenericDataModel, GenericMutationCtx, GenericQueryCtx, MutationBuilder, QueryBuilder } from "convex/server";
3
3
  import { PropertyValidators } from "convex/values";
4
4
  import { Customization } from "convex-helpers/server/customFunctions";
5
5
  //#region src/zod-registration.d.ts
6
6
  export declare function zCustomQuery<CustomArgsValidator extends PropertyValidators, CustomCtx extends Record<string, any>, CustomMadeArgs extends Record<string, any>, Visibility extends FunctionVisibility, DataModel extends GenericDataModel, ExtraArgs extends Record<string, any> = object>(query: QueryBuilder<DataModel, Visibility>, customization: Customization<GenericQueryCtx<DataModel>, CustomArgsValidator, CustomCtx, CustomMadeArgs, ExtraArgs>): CustomBuilder<'query', CustomArgsValidator, CustomCtx, CustomMadeArgs, GenericQueryCtx<DataModel>, Visibility, ExtraArgs>;
7
7
  export declare function zCustomMutation<CustomArgsValidator extends PropertyValidators, CustomCtx extends Record<string, any>, CustomMadeArgs extends Record<string, any>, Visibility extends FunctionVisibility, DataModel extends GenericDataModel, ExtraArgs extends Record<string, any> = object>(mutation: MutationBuilder<DataModel, Visibility>, customization: Customization<GenericMutationCtx<DataModel>, CustomArgsValidator, CustomCtx, CustomMadeArgs, ExtraArgs>): CustomBuilder<'mutation', CustomArgsValidator, CustomCtx, CustomMadeArgs, GenericMutationCtx<DataModel>, Visibility, ExtraArgs>;
8
8
  export declare function zCustomAction<CustomArgsValidator extends PropertyValidators, CustomCtx extends Record<string, any>, CustomMadeArgs extends Record<string, any>, Visibility extends FunctionVisibility, DataModel extends GenericDataModel, ExtraArgs extends Record<string, any> = object>(action: ActionBuilder<DataModel, Visibility>, customization: Customization<GenericActionCtx<DataModel>, CustomArgsValidator, CustomCtx, CustomMadeArgs, ExtraArgs>): CustomBuilder<'action', CustomArgsValidator, CustomCtx, CustomMadeArgs, GenericActionCtx<DataModel>, Visibility, ExtraArgs>;
9
+ /**
10
+ * The raw arguments of the invocation that produced `ctx`, before zod parsing.
11
+ * Available inside a customization `input` callback; empty for unknown contexts.
12
+ */
13
+ export declare function rawFunctionArgs<DataModel extends GenericDataModel>(ctx: GenericQueryCtx<DataModel> | GenericMutationCtx<DataModel> | GenericActionCtx<DataModel>): DefaultFunctionArgs;
9
14
  //#endregion
10
15
  //# sourceMappingURL=zod-registration.d.mts.map
@@ -1,2 +1,2 @@
1
- import{zodToConvex as e}from"./zod-convex.mjs";import{compactArgumentBoundary as t}from"./querying/filter-boundary.mjs";import{zodOutputToConvex as n}from"convex-helpers/server/zod4";import{ConvexError as r}from"convex/values";import{pick as i}from"convex-helpers";import{NoOp as a}from"convex-helpers/server/customFunctions";import{addFieldsToValidator as o}from"convex-helpers/validators";import*as s from"zod/v4";import*as c from"zod/v4/core";function l(e,t){return f(e,t)}function u(e,t){return f(e,t)}function d(e,t){return f(e,t)}function f(l,u){let d=u.input??a.input,f=u.args??a.args;return function(a){let{args:u,handler:p=a,skipConvexValidation:m=!1,returns:h,...g}=a,_=h&&!(h instanceof c.$ZodType)?s.object(h):h,v=_&&!m?{returns:n(_)}:null;if(u){let n=u;if(n instanceof c.$ZodType){if(n instanceof c.$ZodObject)n=n._zod.def.shape;else throw Error(`Unsupported zod type as args validator: `+n.constructor.name)}let a=s.object({...n}),h=Object.keys(a.shape),y=m?void 0:t(a),b=y?.validator??e(a);return l({args:m?void 0:o(b,f),...v,handler:async(e,t)=>{y?.preflight(t);let n=await d(e,i(t,Object.keys(f)),g),o=i(t,h),s=await a.safeParseAsync(o);if(!s.success)throw new r({ZodError:JSON.parse(JSON.stringify(s.error.issues,null,2))});let c=s.data,l={...e,...n.ctx},u={...c,...n.args},m=await p(l,u),v=_?await _.parseAsync(m===void 0?null:m):m;return n.onSuccess&&await n.onSuccess({ctx:e,args:c,result:v}),v}})}if(m&&Object.keys(f).length>0)throw Error(`If you're using a custom function with arguments for the input customization, you cannot skip convex validation.`);return l({...v,handler:async(e,t)=>{let n=await d(e,t,g),r={...e,...n.ctx},i={...t,...n.args},a=await p(r,i),o=_?await _.parseAsync(a===void 0?null:a):a;return n.onSuccess&&await n.onSuccess({ctx:e,args:t,result:o}),o}})}}export{d as zCustomAction,u as zCustomMutation,l as zCustomQuery};
1
+ import{zodToConvex as e}from"./zod-convex.mjs";import{compactArgumentBoundary as t}from"./querying/filter-boundary.mjs";import{zodOutputToConvex as n}from"convex-helpers/server/zod4";import{ConvexError as r}from"convex/values";import{pick as i}from"convex-helpers";import{NoOp as a}from"convex-helpers/server/customFunctions";import{addFieldsToValidator as o}from"convex-helpers/validators";import*as s from"zod/v4";import*as c from"zod/v4/core";function l(e,t){return m(e,t)}function u(e,t){return m(e,t)}function d(e,t){return m(e,t)}const f=/* @__PURE__ */ new WeakMap;function p(e){return f.get(e)??{}}function m(l,u){let d=u.input??a.input,p=u.args??a.args;return function(a){let{args:u,handler:m=a,skipConvexValidation:h=!1,returns:g,..._}=a,v=g&&!(g instanceof c.$ZodType)?s.object(g):g,y=v&&!h?{returns:n(v)}:null;if(u){let n=u;if(n instanceof c.$ZodType){if(n instanceof c.$ZodObject)n=n._zod.def.shape;else throw Error(`Unsupported zod type as args validator: `+n.constructor.name)}let a=s.object({...n}),g=Object.keys(a.shape),b=h?void 0:t(a),x=b?.validator??e(a);return l({args:h?void 0:o(x,p),...y,handler:async(e,t)=>{b?.preflight(t),f.set(e,t);let n=await d(e,i(t,Object.keys(p)),_),o=i(t,g),s=await a.safeParseAsync(o);if(!s.success)throw new r({ZodError:JSON.parse(JSON.stringify(s.error.issues,null,2))});let c=s.data,l={...e,...n.ctx},u={...c,...n.args},h=await m(l,u),y=v?await v.parseAsync(h===void 0?null:h):h;return n.onSuccess&&await n.onSuccess({ctx:e,args:c,result:y}),y}})}if(h&&Object.keys(p).length>0)throw Error(`If you're using a custom function with arguments for the input customization, you cannot skip convex validation.`);return l({...y,handler:async(e,t)=>{f.set(e,t);let n=await d(e,t,_),r={...e,...n.ctx},i={...t,...n.args},a=await m(r,i),o=v?await v.parseAsync(a===void 0?null:a):a;return n.onSuccess&&await n.onSuccess({ctx:e,args:t,result:o}),o}})}}export{p as rawFunctionArgs,d as zCustomAction,u as zCustomMutation,l as zCustomQuery};
2
2
  //# sourceMappingURL=zod-registration.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"zod-registration.mjs","names":["zodToConvex","zodToConvex$1","z","zCore","zCustomQuery","customFnBuilder","query","customization","zCustomMutation","mutation","zCustomAction","action","customInput","NoOp","inputArgs","fn","maybeObject","extra","returns","returnValidator","skipConvexValidation","zodOutputToConvex","args","argsValidator","argsSchema","argsKeys","boundary","compactArgumentBoundary","convexValidator","builder","addFieldsToValidator","allArgs","added","ctx","pick","rawArgs","parsed","ConvexError","finalCtx","finalArgs","ret","handler","result"],"sources":["../src/zod-registration.ts"],"sourcesContent":["// Internal auth registration seam. Public wrapper contracts match convex-helpers zod4.\n// Keep the installed helper's registration branches; only argument conversion differs.\nimport { pick } from 'convex-helpers'\nimport { NoOp, type Customization } from 'convex-helpers/server/customFunctions'\nimport { zodOutputToConvex, type CustomBuilder } from 'convex-helpers/server/zod4'\nimport { addFieldsToValidator } from 'convex-helpers/validators'\nimport type {\n\tActionBuilder,\n\tFunctionVisibility,\n\tGenericActionCtx,\n\tGenericDataModel,\n\tGenericMutationCtx,\n\tGenericQueryCtx,\n\tMutationBuilder,\n\tQueryBuilder,\n} from 'convex/server'\nimport { ConvexError, type PropertyValidators, type Value } from 'convex/values'\nimport * as z from 'zod/v4'\nimport * as zCore from 'zod/v4/core'\nimport { zodToConvex } from './zod-convex'\nimport { compactArgumentBoundary } from './querying/filter-boundary'\n\nexport function zCustomQuery<\n\tCustomArgsValidator extends PropertyValidators,\n\tCustomCtx extends Record<string, any>,\n\tCustomMadeArgs extends Record<string, any>,\n\tVisibility extends FunctionVisibility,\n\tDataModel extends GenericDataModel,\n\tExtraArgs extends Record<string, any> = object,\n>(\n\tquery: QueryBuilder<DataModel, Visibility>,\n\tcustomization: Customization<\n\t\tGenericQueryCtx<DataModel>,\n\t\tCustomArgsValidator,\n\t\tCustomCtx,\n\t\tCustomMadeArgs,\n\t\tExtraArgs\n\t>,\n) {\n\t// SAFETY: the private adapter preserves helper registration semantics; this is\n\t// the same generic boundary assertion used by the public helper wrappers.\n\treturn customFnBuilder(query, customization) as CustomBuilder<\n\t\t'query',\n\t\tCustomArgsValidator,\n\t\tCustomCtx,\n\t\tCustomMadeArgs,\n\t\tGenericQueryCtx<DataModel>,\n\t\tVisibility,\n\t\tExtraArgs\n\t>\n}\n\nexport function zCustomMutation<\n\tCustomArgsValidator extends PropertyValidators,\n\tCustomCtx extends Record<string, any>,\n\tCustomMadeArgs extends Record<string, any>,\n\tVisibility extends FunctionVisibility,\n\tDataModel extends GenericDataModel,\n\tExtraArgs extends Record<string, any> = object,\n>(\n\tmutation: MutationBuilder<DataModel, Visibility>,\n\tcustomization: Customization<\n\t\tGenericMutationCtx<DataModel>,\n\t\tCustomArgsValidator,\n\t\tCustomCtx,\n\t\tCustomMadeArgs,\n\t\tExtraArgs\n\t>,\n) {\n\t// SAFETY: the private adapter preserves helper registration semantics; this is\n\t// the same generic boundary assertion used by the public helper wrappers.\n\treturn customFnBuilder(mutation, customization) as CustomBuilder<\n\t\t'mutation',\n\t\tCustomArgsValidator,\n\t\tCustomCtx,\n\t\tCustomMadeArgs,\n\t\tGenericMutationCtx<DataModel>,\n\t\tVisibility,\n\t\tExtraArgs\n\t>\n}\n\nexport function zCustomAction<\n\tCustomArgsValidator extends PropertyValidators,\n\tCustomCtx extends Record<string, any>,\n\tCustomMadeArgs extends Record<string, any>,\n\tVisibility extends FunctionVisibility,\n\tDataModel extends GenericDataModel,\n\tExtraArgs extends Record<string, any> = object,\n>(\n\taction: ActionBuilder<DataModel, Visibility>,\n\tcustomization: Customization<\n\t\tGenericActionCtx<DataModel>,\n\t\tCustomArgsValidator,\n\t\tCustomCtx,\n\t\tCustomMadeArgs,\n\t\tExtraArgs\n\t>,\n) {\n\t// SAFETY: the private adapter preserves helper registration semantics; this is\n\t// the same generic boundary assertion used by the public helper wrappers.\n\treturn customFnBuilder(action, customization) as CustomBuilder<\n\t\t'action',\n\t\tCustomArgsValidator,\n\t\tCustomCtx,\n\t\tCustomMadeArgs,\n\t\tGenericActionCtx<DataModel>,\n\t\tVisibility,\n\t\tExtraArgs\n\t>\n}\n\nfunction customFnBuilder(\n\tbuilder: (args: any) => any,\n\tcustomization: Customization<any, any, any, any, any>,\n) {\n\t// Looking forward to when input / args / ... are optional\n\tconst customInput: Customization<any, any, any, any, any>['input'] =\n\t\tcustomization.input ?? NoOp.input\n\tconst inputArgs = customization.args ?? NoOp.args\n\treturn function customBuilder(fn: any): any {\n\t\tconst { args, handler = fn, skipConvexValidation = false, returns: maybeObject, ...extra } = fn\n\n\t\tconst returns =\n\t\t\tmaybeObject && !(maybeObject instanceof zCore.$ZodType) ? z.object(maybeObject) : maybeObject\n\n\t\tconst returnValidator =\n\t\t\treturns && !skipConvexValidation ? { returns: zodOutputToConvex(returns) } : null\n\n\t\tif (args) {\n\t\t\tlet argsValidator = args\n\t\t\tif (argsValidator instanceof zCore.$ZodType) {\n\t\t\t\tif (argsValidator instanceof zCore.$ZodObject) {\n\t\t\t\t\targsValidator = argsValidator._zod.def.shape\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t'Unsupported zod type as args validator: ' + argsValidator.constructor.name,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Capture top-level fields once, matching the native validator's registration lifetime.\n\t\t\t// Nested schemas retain their identity; parsing and callbacks still run per invocation.\n\t\t\tconst argsSchema = z.object({ ...argsValidator })\n\t\t\tconst argsKeys = Object.keys(argsSchema.shape)\n\t\t\t// One conversion preserves graph sharing across all user argument fields.\n\t\t\tconst boundary = skipConvexValidation ? undefined : compactArgumentBoundary(argsSchema)\n\t\t\tconst convexValidator = boundary?.validator ?? zodToConvex(argsSchema)\n\t\t\treturn builder({\n\t\t\t\targs: skipConvexValidation ? undefined : addFieldsToValidator(convexValidator, inputArgs),\n\t\t\t\t...returnValidator,\n\t\t\t\thandler: async (ctx: any, allArgs: any) => {\n\t\t\t\t\tboundary?.preflight(allArgs)\n\t\t\t\t\tconst added = await customInput(ctx, pick(allArgs, Object.keys(inputArgs)), extra)\n\t\t\t\t\tconst rawArgs = pick(allArgs, argsKeys)\n\t\t\t\t\tconst parsed = await argsSchema.safeParseAsync(rawArgs)\n\t\t\t\t\tif (!parsed.success) {\n\t\t\t\t\t\tthrow new ConvexError({\n\t\t\t\t\t\t\t// SAFETY: serialized Zod issues are the helper's existing Convex Value[] error payload.\n\t\t\t\t\t\t\tZodError: JSON.parse(JSON.stringify(parsed.error.issues, null, 2)) as Value[],\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t\tconst args = parsed.data\n\t\t\t\t\tconst finalCtx = { ...ctx, ...added.ctx }\n\t\t\t\t\tconst finalArgs = { ...args, ...added.args }\n\t\t\t\t\tconst ret = await handler(finalCtx, finalArgs)\n\t\t\t\t\t// We don't catch the error here. It's a developer error and we\n\t\t\t\t\t// don't want to risk exposing the unexpected value to the client.\n\t\t\t\t\tconst result = returns ? await returns.parseAsync(ret === undefined ? null : ret) : ret\n\t\t\t\t\tif (added.onSuccess) {\n\t\t\t\t\t\tawait added.onSuccess({ ctx, args, result })\n\t\t\t\t\t}\n\t\t\t\t\treturn result\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t\tif (skipConvexValidation && Object.keys(inputArgs).length > 0) {\n\t\t\tthrow new Error(\n\t\t\t\t\"If you're using a custom function with arguments for the input \" +\n\t\t\t\t\t'customization, you cannot skip convex validation.',\n\t\t\t)\n\t\t}\n\t\treturn builder({\n\t\t\t...returnValidator,\n\t\t\thandler: async (ctx: any, args: any) => {\n\t\t\t\tconst added = await customInput(ctx, args, extra)\n\t\t\t\tconst finalCtx = { ...ctx, ...added.ctx }\n\t\t\t\tconst finalArgs = { ...args, ...added.args }\n\t\t\t\tconst ret = await handler(finalCtx, finalArgs)\n\t\t\t\t// We don't catch the error here. It's a developer error and we\n\t\t\t\t// don't want to risk exposing the unexpected value to the client.\n\t\t\t\tconst result = returns ? await returns.parseAsync(ret === undefined ? null : ret) : ret\n\t\t\t\tif (added.onSuccess) {\n\t\t\t\t\tawait added.onSuccess({ ctx, args, result })\n\t\t\t\t}\n\t\t\t\treturn result\n\t\t\t},\n\t\t})\n\t}\n}\n"],"mappings":"8bAsBA,SAAgBI,EAQf,EACA,EAOC,CAGD,O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eW,CAAO,EACtD,GAAI,CAACC,EAAO,QACX,MAAM,IAAIC,EAAY,CAErB,SAAU,KAAK,MAAM,KAAK,UAAUD,EAAO,MAAM,OAAQ,KAAM,CAAC,CAAC,CAClE,CAAC,EAEF,IAAMd,EAAOc,EAAO,KACdE,EAAW,CAAE,GAAGL,EAAK,GAAGD,EAAM,GAAI,EAClCO,EAAY,CAAE,GAAGjB,EAAM,GAAGU,EAAM,IAAK,EACrCQ,EAAM,MAAMC,EAAQH,EAAUC,CAAS,EAGvCG,EAASxB,EAAU,MAAMA,EAAQ,WAAWsB,IAAQ,IAAA,GAAY,KAAOA,CAAG,EAAIA,EAIpF,OAHIR,EAAM,WACT,MAAMA,EAAM,UAAU,CAAE,MAAK,OAAM,QAAO,CAAC,EAErCU,CACR,CACD,CAAC,CACF,CACA,GAAItB,GAAwB,OAAO,KAAKN,CAAS,CAAC,CAAC,OAAS,EAC3D,MAAU,MACT,kHAED,EAED,OAAOe,EAAQ,CACd,GAAGV,EACH,QAAS,MAAO,EAAU,IAAc,CACvC,IAAMa,EAAQ,MAAMpB,EAAYqB,EAAKX,EAAML,CAAK,EAC1CqB,EAAW,CAAE,GAAGL,EAAK,GAAGD,EAAM,GAAI,EAClCO,EAAY,CAAE,GAAGjB,EAAM,GAAGU,EAAM,IAAK,EACrCQ,EAAM,MAAMC,EAAQH,EAAUC,CAAS,EAGvCG,EAASxB,EAAU,MAAMA,EAAQ,WAAWsB,IAAQ,IAAA,GAAY,KAAOA,CAAG,EAAIA,EAIpF,OAHIR,EAAM,WACT,MAAMA,EAAM,UAAU,CAAE,MAAK,OAAM,QAAO,CAAC,EAErCU,CACR,CACD,CAAC,CACF,CACD"}
1
+ {"version":3,"file":"zod-registration.mjs","names":["zodToConvex","zodToConvex$1","z","zCore","zCustomQuery","customFnBuilder","query","customization","zCustomMutation","mutation","zCustomAction","action","rawArguments","rawFunctionArgs","ctx","customInput","NoOp","inputArgs","fn","maybeObject","extra","returns","returnValidator","skipConvexValidation","zodOutputToConvex","args","argsValidator","argsSchema","argsKeys","boundary","compactArgumentBoundary","convexValidator","builder","addFieldsToValidator","allArgs","added","pick","rawArgs","parsed","ConvexError","finalCtx","finalArgs","ret","handler","result"],"sources":["../src/zod-registration.ts"],"sourcesContent":["// Internal auth registration seam. Public wrapper contracts match convex-helpers zod4.\n// Keep the installed helper's registration branches; only argument conversion differs.\nimport { pick } from 'convex-helpers'\nimport { NoOp, type Customization } from 'convex-helpers/server/customFunctions'\nimport { zodOutputToConvex, type CustomBuilder } from 'convex-helpers/server/zod4'\nimport { addFieldsToValidator } from 'convex-helpers/validators'\nimport type {\n\tActionBuilder,\n\tDefaultFunctionArgs,\n\tFunctionVisibility,\n\tGenericActionCtx,\n\tGenericDataModel,\n\tGenericMutationCtx,\n\tGenericQueryCtx,\n\tMutationBuilder,\n\tQueryBuilder,\n} from 'convex/server'\nimport { ConvexError, type PropertyValidators, type Value } from 'convex/values'\nimport * as z from 'zod/v4'\nimport * as zCore from 'zod/v4/core'\nimport { zodToConvex } from './zod-convex'\nimport { compactArgumentBoundary } from './querying/filter-boundary'\n\nexport function zCustomQuery<\n\tCustomArgsValidator extends PropertyValidators,\n\tCustomCtx extends Record<string, any>,\n\tCustomMadeArgs extends Record<string, any>,\n\tVisibility extends FunctionVisibility,\n\tDataModel extends GenericDataModel,\n\tExtraArgs extends Record<string, any> = object,\n>(\n\tquery: QueryBuilder<DataModel, Visibility>,\n\tcustomization: Customization<\n\t\tGenericQueryCtx<DataModel>,\n\t\tCustomArgsValidator,\n\t\tCustomCtx,\n\t\tCustomMadeArgs,\n\t\tExtraArgs\n\t>,\n) {\n\t// SAFETY: the private adapter preserves helper registration semantics; this is\n\t// the same generic boundary assertion used by the public helper wrappers.\n\treturn customFnBuilder(query, customization) as CustomBuilder<\n\t\t'query',\n\t\tCustomArgsValidator,\n\t\tCustomCtx,\n\t\tCustomMadeArgs,\n\t\tGenericQueryCtx<DataModel>,\n\t\tVisibility,\n\t\tExtraArgs\n\t>\n}\n\nexport function zCustomMutation<\n\tCustomArgsValidator extends PropertyValidators,\n\tCustomCtx extends Record<string, any>,\n\tCustomMadeArgs extends Record<string, any>,\n\tVisibility extends FunctionVisibility,\n\tDataModel extends GenericDataModel,\n\tExtraArgs extends Record<string, any> = object,\n>(\n\tmutation: MutationBuilder<DataModel, Visibility>,\n\tcustomization: Customization<\n\t\tGenericMutationCtx<DataModel>,\n\t\tCustomArgsValidator,\n\t\tCustomCtx,\n\t\tCustomMadeArgs,\n\t\tExtraArgs\n\t>,\n) {\n\t// SAFETY: the private adapter preserves helper registration semantics; this is\n\t// the same generic boundary assertion used by the public helper wrappers.\n\treturn customFnBuilder(mutation, customization) as CustomBuilder<\n\t\t'mutation',\n\t\tCustomArgsValidator,\n\t\tCustomCtx,\n\t\tCustomMadeArgs,\n\t\tGenericMutationCtx<DataModel>,\n\t\tVisibility,\n\t\tExtraArgs\n\t>\n}\n\nexport function zCustomAction<\n\tCustomArgsValidator extends PropertyValidators,\n\tCustomCtx extends Record<string, any>,\n\tCustomMadeArgs extends Record<string, any>,\n\tVisibility extends FunctionVisibility,\n\tDataModel extends GenericDataModel,\n\tExtraArgs extends Record<string, any> = object,\n>(\n\taction: ActionBuilder<DataModel, Visibility>,\n\tcustomization: Customization<\n\t\tGenericActionCtx<DataModel>,\n\t\tCustomArgsValidator,\n\t\tCustomCtx,\n\t\tCustomMadeArgs,\n\t\tExtraArgs\n\t>,\n) {\n\t// SAFETY: the private adapter preserves helper registration semantics; this is\n\t// the same generic boundary assertion used by the public helper wrappers.\n\treturn customFnBuilder(action, customization) as CustomBuilder<\n\t\t'action',\n\t\tCustomArgsValidator,\n\t\tCustomCtx,\n\t\tCustomMadeArgs,\n\t\tGenericActionCtx<DataModel>,\n\t\tVisibility,\n\t\tExtraArgs\n\t>\n}\n\n/** Raw (unparsed) function arguments, keyed by the native ctx of one invocation. */\nconst rawArguments = new WeakMap<object, DefaultFunctionArgs>()\n\n/**\n * The raw arguments of the invocation that produced `ctx`, before zod parsing.\n * Available inside a customization `input` callback; empty for unknown contexts.\n */\nexport function rawFunctionArgs<DataModel extends GenericDataModel>(\n\tctx: GenericQueryCtx<DataModel> | GenericMutationCtx<DataModel> | GenericActionCtx<DataModel>,\n): DefaultFunctionArgs {\n\treturn rawArguments.get(ctx) ?? {}\n}\n\nfunction customFnBuilder(\n\tbuilder: (args: any) => any,\n\tcustomization: Customization<any, any, any, any, any>,\n) {\n\t// Looking forward to when input / args / ... are optional\n\tconst customInput: Customization<any, any, any, any, any>['input'] =\n\t\tcustomization.input ?? NoOp.input\n\tconst inputArgs = customization.args ?? NoOp.args\n\treturn function customBuilder(fn: any): any {\n\t\tconst { args, handler = fn, skipConvexValidation = false, returns: maybeObject, ...extra } = fn\n\n\t\tconst returns =\n\t\t\tmaybeObject && !(maybeObject instanceof zCore.$ZodType) ? z.object(maybeObject) : maybeObject\n\n\t\tconst returnValidator =\n\t\t\treturns && !skipConvexValidation ? { returns: zodOutputToConvex(returns) } : null\n\n\t\tif (args) {\n\t\t\tlet argsValidator = args\n\t\t\tif (argsValidator instanceof zCore.$ZodType) {\n\t\t\t\tif (argsValidator instanceof zCore.$ZodObject) {\n\t\t\t\t\targsValidator = argsValidator._zod.def.shape\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t'Unsupported zod type as args validator: ' + argsValidator.constructor.name,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Capture top-level fields once, matching the native validator's registration lifetime.\n\t\t\t// Nested schemas retain their identity; parsing and callbacks still run per invocation.\n\t\t\tconst argsSchema = z.object({ ...argsValidator })\n\t\t\tconst argsKeys = Object.keys(argsSchema.shape)\n\t\t\t// One conversion preserves graph sharing across all user argument fields.\n\t\t\tconst boundary = skipConvexValidation ? undefined : compactArgumentBoundary(argsSchema)\n\t\t\tconst convexValidator = boundary?.validator ?? zodToConvex(argsSchema)\n\t\t\treturn builder({\n\t\t\t\targs: skipConvexValidation ? undefined : addFieldsToValidator(convexValidator, inputArgs),\n\t\t\t\t...returnValidator,\n\t\t\t\thandler: async (ctx: any, allArgs: any) => {\n\t\t\t\t\tboundary?.preflight(allArgs)\n\t\t\t\t\trawArguments.set(ctx, allArgs)\n\t\t\t\t\tconst added = await customInput(ctx, pick(allArgs, Object.keys(inputArgs)), extra)\n\t\t\t\t\tconst rawArgs = pick(allArgs, argsKeys)\n\t\t\t\t\tconst parsed = await argsSchema.safeParseAsync(rawArgs)\n\t\t\t\t\tif (!parsed.success) {\n\t\t\t\t\t\tthrow new ConvexError({\n\t\t\t\t\t\t\t// SAFETY: serialized Zod issues are the helper's existing Convex Value[] error payload.\n\t\t\t\t\t\t\tZodError: JSON.parse(JSON.stringify(parsed.error.issues, null, 2)) as Value[],\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t\tconst args = parsed.data\n\t\t\t\t\tconst finalCtx = { ...ctx, ...added.ctx }\n\t\t\t\t\tconst finalArgs = { ...args, ...added.args }\n\t\t\t\t\tconst ret = await handler(finalCtx, finalArgs)\n\t\t\t\t\t// We don't catch the error here. It's a developer error and we\n\t\t\t\t\t// don't want to risk exposing the unexpected value to the client.\n\t\t\t\t\tconst result = returns ? await returns.parseAsync(ret === undefined ? null : ret) : ret\n\t\t\t\t\tif (added.onSuccess) {\n\t\t\t\t\t\tawait added.onSuccess({ ctx, args, result })\n\t\t\t\t\t}\n\t\t\t\t\treturn result\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t\tif (skipConvexValidation && Object.keys(inputArgs).length > 0) {\n\t\t\tthrow new Error(\n\t\t\t\t\"If you're using a custom function with arguments for the input \" +\n\t\t\t\t\t'customization, you cannot skip convex validation.',\n\t\t\t)\n\t\t}\n\t\treturn builder({\n\t\t\t...returnValidator,\n\t\t\thandler: async (ctx: any, args: any) => {\n\t\t\t\trawArguments.set(ctx, args)\n\t\t\t\tconst added = await customInput(ctx, args, extra)\n\t\t\t\tconst finalCtx = { ...ctx, ...added.ctx }\n\t\t\t\tconst finalArgs = { ...args, ...added.args }\n\t\t\t\tconst ret = await handler(finalCtx, finalArgs)\n\t\t\t\t// We don't catch the error here. It's a developer error and we\n\t\t\t\t// don't want to risk exposing the unexpected value to the client.\n\t\t\t\tconst result = returns ? await returns.parseAsync(ret === undefined ? null : ret) : ret\n\t\t\t\tif (added.onSuccess) {\n\t\t\t\t\tawait added.onSuccess({ ctx, args, result })\n\t\t\t\t}\n\t\t\t\treturn result\n\t\t\t},\n\t\t})\n\t}\n}\n"],"mappings":"8bAuBA,SAAgBI,EAQf,EACA,EAOC,CAGD,OAAOC,EAAgBC,EAAOC,CAAa,CAS5C,CAEA,SAAgBC,EAQf,EACA,EAOC,CAGD,OAAOH,EAAgBI,EAAUF,CAAa,CAS/C,CAEA,SAAgBG,EAQf,EACA,EAOC,CAGD,OAAOL,EAAgBM,EAAQJ,CAAa,CAS7C,CAGA,MAAMK,kBAAe,IAAI,QAMzB,SAAgBC,EACf,EACsB,CACtB,OAAOD,EAAa,IAAIE,CAAG,GAAK,CAAC,CAClC,CAEA,SAAST,EACR,EACA,EACC,CAED,IAAMU,EACLR,EAAc,OAASS,EAAK,MACvBC,EAAYV,EAAc,MAAQS,EAAK,KAC7C,OAAO,SAAuB,EAAc,CAC3C,GAAM,CAAE,OAAM,UAAUE,EAAI,uBAAuB,GAAO,QAASC,EAAa,GAAGC,GAAUF,EAEvFG,EACLF,GAAe,EAAEA,aAAuBhB,EAAM,UAAYD,EAAE,OAAOiB,CAAW,EAAIA,EAE7EG,EACLD,GAAW,CAACE,EAAuB,CAAE,QAASC,EAAkBH,CAAO,CAAE,EAAI,KAE9E,GAAII,EAAM,CACT,IAAIC,EAAgBD,EACpB,GAAIC,aAAyBvB,EAAM,SAAU,CAC5C,GAAIuB,aAAyBvB,EAAM,WAClC,EAAgBuB,EAAc,KAAK,IAAI,WAEvC,MAAU,MACT,2CAA6CA,EAAc,YAAY,IACxE,CAEF,CAGA,IAAMC,EAAazB,EAAE,OAAO,CAAE,GAAGw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AK,EAC1CoB,EAAW,CAAE,GAAG1B,EAAK,GAAGqB,EAAM,GAAI,EAClCM,EAAY,CAAE,GAAGhB,EAAM,GAAGU,EAAM,IAAK,EACrCO,EAAM,MAAMC,EAAQH,EAAUC,CAAS,EAGvCG,EAASvB,EAAU,MAAMA,EAAQ,WAAWqB,IAAQ,IAAA,GAAY,KAAOA,CAAG,EAAIA,EAIpF,OAHIP,EAAM,WACT,MAAMA,EAAM,UAAU,CAAE,MAAK,OAAM,QAAO,CAAC,EAErCS,CACR,CACD,CAAC,CACF,CACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cvx-kit",
3
- "version": "0.1.27",
3
+ "version": "0.1.29",
4
4
  "description": "Reusable Convex application kit: foundation kernels, approvals component, zod table boundaries, WorkOS-backed auth function constructors, and audited command protocol.",
5
5
  "keywords": [
6
6
  "component",