cvx-kit 0.1.35 → 2.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -49
- package/dist/agent-tools.d.mts +21 -25
- package/dist/agent-tools.mjs +1 -1
- package/dist/agent-tools.mjs.map +1 -1
- package/dist/auth.d.mts +20 -14
- package/dist/auth.mjs +1 -1
- package/dist/auth.mjs.map +1 -1
- package/dist/components/approvals/_generated/api.d.mts +4 -5
- package/dist/components/approvals/_generated/api.mjs.map +1 -1
- package/dist/components/approvals/_generated/component.d.mts +0 -2
- package/dist/components/approvals/_generated/dataModel.d.mts +1 -3
- package/dist/components/approvals/_generated/server.d.mts +0 -2
- package/dist/components/approvals/_generated/server.mjs.map +1 -1
- package/dist/components/approvals/audit.d.mts +0 -1
- package/dist/components/approvals/audit.mjs +1 -1
- package/dist/components/approvals/audit.mjs.map +1 -1
- package/dist/components/approvals/client.d.mts +0 -1
- package/dist/components/approvals/client.mjs +1 -1
- package/dist/components/approvals/client.mjs.map +1 -1
- package/dist/components/approvals/constants.d.mts +0 -1
- package/dist/components/approvals/constants.mjs.map +1 -1
- package/dist/components/approvals/convex.config.d.mts +0 -2
- package/dist/components/approvals/convex.config.mjs.map +1 -1
- package/dist/components/approvals/decisions.d.mts +1 -4
- package/dist/components/approvals/decisions.mjs +1 -1
- package/dist/components/approvals/decisions.mjs.map +1 -1
- package/dist/components/approvals/functions.d.mts +0 -1
- package/dist/components/approvals/functions.mjs.map +1 -1
- package/dist/components/approvals/health.d.mts +0 -1
- package/dist/components/approvals/health.mjs.map +1 -1
- package/dist/components/approvals/requests.d.mts +106 -123
- package/dist/components/approvals/requests.mjs +1 -1
- package/dist/components/approvals/requests.mjs.map +1 -1
- package/dist/components/approvals/schema.d.ts +106 -315
- package/dist/components/approvals/schema.js +1 -1
- package/dist/components/approvals/validators.d.mts +321 -393
- package/dist/components/approvals/validators.mjs +1 -1
- package/dist/components/approvals/validators.mjs.map +1 -1
- package/dist/components/approvals/workflow.d.mts +0 -1
- package/dist/components/approvals/workflow.mjs +1 -1
- package/dist/components/approvals/workflow.mjs.map +1 -1
- package/dist/components/approvals/workflow_steps.d.mts +1 -2
- package/dist/components/approvals/workflow_steps.mjs.map +1 -1
- package/dist/components/foundation/_generated/api.d.mts +3 -4
- package/dist/components/foundation/_generated/api.mjs.map +1 -1
- package/dist/components/foundation/_generated/component.d.mts +0 -2
- package/dist/components/foundation/_generated/dataModel.d.mts +1 -3
- package/dist/components/foundation/_generated/server.d.mts +0 -2
- package/dist/components/foundation/_generated/server.mjs.map +1 -1
- package/dist/components/foundation/client.d.mts +0 -1
- package/dist/components/foundation/client.mjs +1 -1
- package/dist/components/foundation/client.mjs.map +1 -1
- package/dist/components/foundation/convex.config.d.mts +0 -2
- package/dist/components/foundation/convex.config.mjs.map +1 -1
- package/dist/components/foundation/functions.d.mts +0 -1
- package/dist/components/foundation/functions.mjs.map +1 -1
- package/dist/components/foundation/modules/command/command.d.mts +0 -1
- package/dist/components/foundation/modules/command/command.mjs.map +1 -1
- package/dist/components/foundation/modules/command/lifecycle.d.mts +0 -2
- package/dist/components/foundation/modules/command/lifecycle.mjs.map +1 -1
- package/dist/components/foundation/modules/observability/observability.d.mts +0 -1
- package/dist/components/foundation/modules/observability/observability.mjs.map +1 -1
- package/dist/components/foundation/modules/query/query.d.mts +0 -1
- package/dist/components/foundation/modules/query/query.mjs.map +1 -1
- package/dist/components/foundation/operation.d.mts +2 -3
- package/dist/components/foundation/operation.mjs.map +1 -1
- package/dist/components/foundation/result.d.mts +0 -1
- package/dist/components/foundation/result.mjs.map +1 -1
- package/dist/components/foundation/schema.d.ts +0 -2
- package/dist/components/foundation/telemetry.d.mts +0 -1
- package/dist/components/foundation/telemetry.mjs +1 -1
- package/dist/components/foundation/telemetry.mjs.map +1 -1
- package/dist/contracts.d.mts +2 -2
- package/dist/contracts.mjs +1 -1
- package/dist/crud.d.mts +93 -97
- package/dist/crud.mjs +1 -1
- package/dist/crud.mjs.map +1 -1
- package/dist/effect.d.mts +2 -3
- package/dist/effect.mjs +1 -1
- package/dist/errors.d.mts +2 -4
- package/dist/errors.mjs +1 -1
- package/dist/errors.mjs.map +1 -1
- package/dist/filters.d.mts +1 -1
- package/dist/filters.mjs +1 -1
- package/dist/idempotency.mjs +1 -1
- package/dist/index.d.mts +10 -7
- package/dist/index.mjs +1 -1
- package/dist/json-schema.d.mts +40 -0
- package/dist/json-schema.mjs +2 -0
- package/dist/json-schema.mjs.map +1 -0
- package/dist/k/compile.d.mts +17 -0
- package/dist/k/compile.mjs +2 -0
- package/dist/k/compile.mjs.map +1 -0
- package/dist/k/dates.d.mts +23 -0
- package/dist/k/dates.mjs +2 -0
- package/dist/k/dates.mjs.map +1 -0
- package/dist/k/formats.d.mts +24 -0
- package/dist/k/formats.mjs +2 -0
- package/dist/k/formats.mjs.map +1 -0
- package/dist/k/index.d.mts +32 -0
- package/dist/k/index.mjs +2 -0
- package/dist/k/index.mjs.map +1 -0
- package/dist/k/issues.d.mts +31 -0
- package/dist/k/issues.mjs +2 -0
- package/dist/k/issues.mjs.map +1 -0
- package/dist/k/kinds.d.mts +81 -0
- package/dist/k/kinds.mjs +2 -0
- package/dist/k/kinds.mjs.map +1 -0
- package/dist/k/object.d.mts +43 -0
- package/dist/k/object.mjs +2 -0
- package/dist/k/object.mjs.map +1 -0
- package/dist/k/parse.d.mts +29 -0
- package/dist/k/parse.mjs +2 -0
- package/dist/k/parse.mjs.map +1 -0
- package/dist/k/schema.d.mts +100 -0
- package/dist/k/schema.mjs +2 -0
- package/dist/k/schema.mjs.map +1 -0
- package/dist/k/standard.d.mts +8 -0
- package/dist/k/standard.mjs +2 -0
- package/dist/k/standard.mjs.map +1 -0
- package/dist/k/types.d.mts +64 -0
- package/dist/k/types.mjs +1 -0
- package/dist/k.d.mts +8 -0
- package/dist/k.mjs +1 -0
- package/dist/middleware.d.mts +0 -2
- package/dist/middleware.mjs +1 -1
- package/dist/middleware.mjs.map +1 -1
- package/dist/modules/contracts/binding.d.mts +1 -2
- package/dist/modules/contracts/binding.mjs.map +1 -1
- package/dist/modules/contracts/contract.d.mts +0 -2
- package/dist/modules/contracts/contract.mjs.map +1 -1
- package/dist/modules/contracts/convex.d.mts +1 -3
- package/dist/modules/contracts/convex.mjs.map +1 -1
- package/dist/modules/contracts/domain.d.mts +1 -2
- package/dist/modules/contracts/domain.mjs.map +1 -1
- package/dist/modules/contracts/errors.d.mts +161 -2
- package/dist/modules/contracts/errors.mjs +1 -1
- package/dist/modules/contracts/errors.mjs.map +1 -1
- package/dist/modules/contracts/exposure.d.mts +1 -2
- package/dist/modules/contracts/exposure.mjs.map +1 -1
- package/dist/modules/contracts/idempotency.d.mts +1 -2
- package/dist/modules/contracts/idempotency.mjs +1 -1
- package/dist/modules/contracts/idempotency.mjs.map +1 -1
- package/dist/modules/contracts/lazy.d.mts +0 -2
- package/dist/modules/contracts/lazy.mjs.map +1 -1
- package/dist/modules/contracts/standard.d.mts +7 -5
- package/dist/modules/contracts/standard.mjs +1 -1
- package/dist/modules/contracts/standard.mjs.map +1 -1
- package/dist/modules/contracts/workflow.d.mts +1 -2
- package/dist/modules/contracts/workflow.mjs.map +1 -1
- package/dist/modules/effect/action.d.mts +6 -7
- package/dist/modules/effect/action.mjs +1 -1
- package/dist/modules/effect/action.mjs.map +1 -1
- package/dist/modules/effect/agent-tools.mjs +1 -1
- package/dist/modules/effect/api-runtime.d.mts +1 -2
- package/dist/modules/effect/api-runtime.mjs +1 -1
- package/dist/modules/effect/api-runtime.mjs.map +1 -1
- package/dist/modules/effect/api.d.mts +41 -15
- package/dist/modules/effect/api.mjs +1 -1
- package/dist/modules/effect/api.mjs.map +1 -1
- package/dist/modules/effect/auth.d.mts +5 -6
- package/dist/modules/effect/auth.mjs +1 -1
- package/dist/modules/effect/auth.mjs.map +1 -1
- package/dist/modules/effect/client.d.mts +7 -8
- package/dist/modules/effect/client.mjs +1 -1
- package/dist/modules/effect/command.d.mts +7 -5
- package/dist/modules/effect/command.mjs +1 -1
- package/dist/modules/effect/command.mjs.map +1 -1
- package/dist/modules/effect/crud.d.mts +272 -206
- package/dist/modules/effect/crud.mjs +1 -1
- package/dist/modules/effect/crud.mjs.map +1 -1
- package/dist/modules/effect/domain.d.mts +5 -6
- package/dist/modules/effect/domain.mjs.map +1 -1
- package/dist/modules/effect/errors.d.mts +4 -2
- package/dist/modules/effect/errors.mjs +1 -1
- package/dist/modules/effect/errors.mjs.map +1 -1
- package/dist/modules/effect/failure-audit.d.mts +2 -2
- package/dist/modules/effect/failure-audit.mjs +1 -1
- package/dist/modules/effect/failure-audit.mjs.map +1 -1
- package/dist/modules/effect/failures.d.mts +1 -2
- package/dist/modules/effect/failures.mjs.map +1 -1
- package/dist/modules/effect/foundation.d.mts +0 -2
- package/dist/modules/effect/foundation.mjs.map +1 -1
- package/dist/modules/effect/idempotency.d.mts +2 -3
- package/dist/modules/effect/idempotency.mjs +1 -1
- package/dist/modules/effect/idempotency.mjs.map +1 -1
- package/dist/modules/effect/input.d.mts +10 -0
- package/dist/modules/effect/input.mjs +2 -0
- package/dist/modules/effect/input.mjs.map +1 -0
- package/dist/modules/effect/normalize.d.mts +0 -2
- package/dist/modules/effect/normalize.mjs.map +1 -1
- package/dist/modules/effect/operation.d.mts +2 -3
- package/dist/modules/effect/operation.mjs.map +1 -1
- package/dist/modules/effect/query.d.mts +6 -4
- package/dist/modules/effect/query.mjs +1 -1
- package/dist/modules/effect/query.mjs.map +1 -1
- package/dist/modules/effect/schema.d.mts +0 -2
- package/dist/modules/effect/schema.mjs.map +1 -1
- package/dist/modules/effect/scope.d.mts +0 -2
- package/dist/modules/effect/scope.mjs.map +1 -1
- package/dist/modules/effect/workflow.d.mts +4 -5
- package/dist/modules/effect/workflow.mjs +1 -1
- package/dist/modules/effect/workflow.mjs.map +1 -1
- package/dist/modules/foundation/foundation.d.mts +4 -5
- package/dist/modules/foundation/foundation.mjs +1 -1
- package/dist/modules/foundation/foundation.mjs.map +1 -1
- package/dist/modules/foundation/operation.d.mts +2 -3
- package/dist/modules/foundation/operation.mjs.map +1 -1
- package/dist/namespace.d.mts +104 -0
- package/dist/namespace.mjs +2 -0
- package/dist/namespace.mjs.map +1 -0
- package/dist/oxlint/architecture.d.mts +0 -2
- package/dist/oxlint/architecture.mjs +1 -1
- package/dist/oxlint/architecture.mjs.map +1 -1
- package/dist/oxlint/ast.d.mts +16 -8
- package/dist/oxlint/ast.mjs +1 -1
- package/dist/oxlint/ast.mjs.map +1 -1
- package/dist/oxlint/components.d.mts +0 -2
- package/dist/oxlint/components.mjs.map +1 -1
- package/dist/oxlint/ownership.d.mts +0 -2
- package/dist/oxlint/ownership.mjs +1 -1
- package/dist/oxlint/ownership.mjs.map +1 -1
- package/dist/oxlint/reserved-files.d.mts +0 -2
- package/dist/oxlint/reserved-files.mjs +1 -1
- package/dist/oxlint/reserved-files.mjs.map +1 -1
- package/dist/oxlint.d.mts +0 -2
- package/dist/oxlint.mjs +1 -1
- package/dist/oxlint.mjs.map +1 -1
- package/dist/querying/cursors.d.mts +27 -9
- package/dist/querying/cursors.mjs +1 -1
- package/dist/querying/cursors.mjs.map +1 -1
- package/dist/querying/execution.d.mts +6 -7
- package/dist/querying/execution.mjs +1 -1
- package/dist/querying/execution.mjs.map +1 -1
- package/dist/querying/failures.d.mts +0 -2
- package/dist/querying/failures.mjs +1 -1
- package/dist/querying/failures.mjs.map +1 -1
- package/dist/querying/filter-boundary.d.mts +18 -9
- package/dist/querying/filter-boundary.mjs +1 -1
- package/dist/querying/filter-boundary.mjs.map +1 -1
- package/dist/querying/filters.d.mts +71 -35
- package/dist/querying/filters.mjs +1 -1
- package/dist/querying/filters.mjs.map +1 -1
- package/dist/querying/planner.d.mts +16 -20
- package/dist/querying/planner.mjs +1 -1
- package/dist/querying/planner.mjs.map +1 -1
- package/dist/querying/relationships.d.mts +6 -6
- package/dist/querying/relationships.mjs +1 -1
- package/dist/querying/relationships.mjs.map +1 -1
- package/dist/querying/search.d.mts +12 -12
- package/dist/querying/search.mjs +1 -1
- package/dist/querying/search.mjs.map +1 -1
- package/dist/querying/security.d.mts +2 -3
- package/dist/querying/security.mjs.map +1 -1
- package/dist/querying/shared/ast.d.mts +0 -2
- package/dist/querying/shared/ast.mjs.map +1 -1
- package/dist/querying/shared/contract.d.mts +17 -23
- package/dist/querying/shared/contract.mjs +1 -1
- package/dist/querying/shared/contract.mjs.map +1 -1
- package/dist/querying/shared/evaluate.d.mts +0 -2
- package/dist/querying/shared/evaluate.mjs.map +1 -1
- package/dist/querying/shared/filters.d.mts +47 -29
- package/dist/querying/shared/filters.mjs +1 -1
- package/dist/querying/shared/filters.mjs.map +1 -1
- package/dist/querying/shared/native-json.d.mts +7 -0
- package/dist/querying/shared/native-json.mjs +2 -0
- package/dist/querying/shared/native-json.mjs.map +1 -0
- package/dist/querying/shared/page.d.mts +19 -22
- package/dist/querying/shared/page.mjs +1 -1
- package/dist/querying/shared/page.mjs.map +1 -1
- package/dist/querying.d.mts +6 -9
- package/dist/querying.mjs +1 -1
- package/dist/querying.mjs.map +1 -1
- package/dist/react/failures.d.mts +0 -2
- package/dist/react/failures.mjs.map +1 -1
- package/dist/react/optimistic.d.mts +2 -3
- package/dist/react/optimistic.mjs.map +1 -1
- package/dist/react/pagination-state.d.mts +1 -2
- package/dist/react/pagination-state.mjs.map +1 -1
- package/dist/react/use-command.d.mts +0 -2
- package/dist/react/use-command.mjs.map +1 -1
- package/dist/react/use-paginated-list.d.mts +1 -3
- package/dist/react/use-paginated-list.mjs +1 -1
- package/dist/react/use-paginated-list.mjs.map +1 -1
- package/dist/react.d.mts +1 -1
- package/dist/react.mjs +1 -1
- package/dist/registration.d.mts +65 -0
- package/dist/registration.mjs +2 -0
- package/dist/registration.mjs.map +1 -0
- package/dist/relations-public.d.mts +2 -2
- package/dist/relations-public.mjs +1 -1
- package/dist/relations.d.mts +55 -46
- package/dist/relations.mjs +1 -1
- package/dist/relations.mjs.map +1 -1
- package/dist/state-machine.d.mts +0 -2
- package/dist/state-machine.mjs.map +1 -1
- package/dist/table.d.mts +222 -0
- package/dist/table.mjs +2 -0
- package/dist/table.mjs.map +1 -0
- package/dist/tenancy.d.mts +0 -2
- package/dist/tenancy.mjs.map +1 -1
- package/dist/triggers.d.mts +2 -4
- package/dist/triggers.mjs +1 -1
- package/dist/triggers.mjs.map +1 -1
- package/dist/webhooks.d.mts +9 -9
- package/dist/webhooks.mjs +1 -1
- package/dist/webhooks.mjs.map +1 -1
- package/dist/workflow.mjs +1 -1
- package/dist/zod.d.mts +30 -0
- package/dist/zod.mjs +2 -0
- package/dist/zod.mjs.map +1 -0
- package/package.json +51 -29
- package/dist/modules/effect/api-zod.d.mts +0 -34
- package/dist/modules/effect/api-zod.mjs +0 -2
- package/dist/modules/effect/api-zod.mjs.map +0 -1
- package/dist/querying/schema-snapshot.d.mts +0 -49
- package/dist/querying/schema-snapshot.mjs +0 -2
- package/dist/querying/schema-snapshot.mjs.map +0 -1
- package/dist/zod-convex.d.mts +0 -10
- package/dist/zod-convex.mjs +0 -2
- package/dist/zod-convex.mjs.map +0 -1
- package/dist/zod-registration.d.mts +0 -15
- package/dist/zod-registration.mjs +0 -2
- package/dist/zod-registration.mjs.map +0 -1
- package/dist/zod-table.d.mts +0 -351
- package/dist/zod-table.mjs +0 -2
- package/dist/zod-table.mjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"zod-registration.mjs","names":["zodToConvex","zodToConvex$1","z","zCore","zCustomQuery","customFnBuilder","query","customization","zCustomMutation","mutation","zCustomAction","action","rawArguments","rawFunctionArgs","ctx","declared","target","definition","descriptor","key","presence","value","reserved","extraOptions","extra","argumentFields","args","customInput","NoOp","inputArgs","handler","fn","skipConvexValidation","declaredArgs","declaredReturns","returnsSchema","memoize","maybeObject","returnsValidator","returns","zodOutputToConvex","nativeDefinition","native","handle","dataArgs","capturedFields","argsState","argsSchema","argsKeys","compactArgumentBoundary","argsValidator","addFieldsToValidator","boundary","allArgs","added","pick","rawArgs","parsed","ConvexError","finalCtx","finalArgs","ret","result","builder"],"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'\nimport { memoize } from './modules/contracts/lazy'\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\n/* oxlint-disable anti-slop/no-object-parameters, anti-slop/no-reflect-get, anti-slop/no-unsafe-dictionary-type, anti-slop/no-known-value-widening -- Registration reads arbitrary user definition records by descriptor so declared accessors stay unread. */\n/** Descriptor lookup that never invokes an accessor; follows the chain like destructuring does. */\nfunction declared(definition: object, key: PropertyKey): PropertyDescriptor | undefined {\n\tfor (let target: object | null = definition; target; target = Object.getPrototypeOf(target)) {\n\t\tconst descriptor = Object.getOwnPropertyDescriptor(target, key)\n\t\tif (descriptor) return descriptor\n\t}\n\treturn undefined\n}\n\n/** Present means the destructured value would select the declared branch; accessors always do. */\nfunction presence(definition: object, key: PropertyKey) {\n\tconst descriptor = declared(definition, key)\n\tif (!descriptor) return { present: false, data: false, read: () => undefined }\n\tif (!('value' in descriptor))\n\t\treturn { present: true, data: false, read: () => Reflect.get(definition, key) }\n\tconst value = descriptor.value\n\treturn { present: Boolean(value), data: true, read: () => value }\n}\n\nconst reserved = new Set<PropertyKey>(['args', 'returns', 'handler', 'skipConvexValidation'])\n\n/** Object-rest equivalent that skips the lazily read keys. */\nfunction extraOptions(definition: object): Record<PropertyKey, unknown> {\n\tconst extra: Record<PropertyKey, unknown> = {}\n\tfor (const key of Reflect.ownKeys(definition)) {\n\t\tif (reserved.has(key) || !Object.prototype.propertyIsEnumerable.call(definition, key)) continue\n\t\t// Define rather than assign, as object rest does, so a `__proto__` key stays an own property.\n\t\tObject.defineProperty(extra, key, {\n\t\t\tvalue: Reflect.get(definition, key),\n\t\t\tenumerable: true,\n\t\t\twritable: true,\n\t\t\tconfigurable: true,\n\t\t})\n\t}\n\treturn extra\n}\n\n/* oxlint-enable anti-slop/no-object-parameters, anti-slop/no-reflect-get, anti-slop/no-unsafe-dictionary-type, anti-slop/no-known-value-widening */\n\nfunction argumentFields(args: any) {\n\tif (!(args instanceof zCore.$ZodType)) return args\n\tif (args instanceof zCore.$ZodObject) return args._zod.def.shape\n\tthrow new Error('Unsupported zod type as args validator: ' + args.constructor.name)\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\t// Descriptor reads keep getter-declared args/returns unread until Convex or a call needs them.\n\t\tconst handler = fn.handler === undefined ? fn : fn.handler\n\t\tconst skipConvexValidation =\n\t\t\tfn.skipConvexValidation === undefined ? false : fn.skipConvexValidation\n\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- Builders accept a bare handler function or a definition object.\n\t\tconst extra = typeof fn === 'object' && fn !== null ? extraOptions(fn) : {}\n\t\tconst declaredArgs = presence(fn, 'args')\n\t\tconst declaredReturns = presence(fn, 'returns')\n\n\t\tconst returnsSchema = memoize(() => {\n\t\t\tconst maybeObject = declaredReturns.read()\n\t\t\treturn maybeObject && !(maybeObject instanceof zCore.$ZodType)\n\t\t\t\t? z.object(maybeObject)\n\t\t\t\t: maybeObject\n\t\t})\n\t\tconst returnsValidator = memoize(() => {\n\t\t\tconst returns = returnsSchema()\n\t\t\treturn returns ? zodOutputToConvex(returns) : undefined\n\t\t})\n\t\tconst nativeDefinition = (handle: (ctx: any, args: any) => Promise<any>) => {\n\t\t\t// oxlint-disable-next-line anti-slop/no-unsafe-dictionary-type -- The native definition carries opaque validators and the handler.\n\t\t\tconst native: Record<string, unknown> = {}\n\t\t\tif (declaredReturns.present && !skipConvexValidation)\n\t\t\t\tObject.defineProperty(native, 'returns', { enumerable: true, get: returnsValidator })\n\t\t\tnative.handler = handle\n\t\t\treturn native\n\t\t}\n\n\t\tif (declaredArgs.present) {\n\t\t\tconst dataArgs = declaredArgs.data\n\t\t\t// Data-declared fields are shape-checked and captured now, as registration always did;\n\t\t\t// only schema construction waits.\n\t\t\tconst capturedFields = dataArgs ? { ...argumentFields(declaredArgs.read()) } : undefined\n\t\t\tconst argsState = memoize(() => {\n\t\t\t\t// Capture top-level fields once, matching the native validator's registration lifetime.\n\t\t\t\t// Nested schemas retain their identity; parsing and callbacks still run per invocation.\n\t\t\t\tconst argsSchema = z.object(capturedFields ?? { ...argumentFields(declaredArgs.read()) })\n\t\t\t\tconst argsKeys = Object.keys(argsSchema.shape)\n\t\t\t\t// Skipped validation still rejects schemas Convex cannot represent.\n\t\t\t\tif (skipConvexValidation) zodToConvex(argsSchema)\n\t\t\t\tconst boundary = skipConvexValidation ? undefined : compactArgumentBoundary(argsSchema)\n\t\t\t\treturn { argsSchema, argsKeys, boundary }\n\t\t\t})\n\t\t\tconst argsValidator = memoize(() => {\n\t\t\t\tconst { argsSchema, boundary } = argsState()\n\t\t\t\t// One conversion preserves graph sharing across all user argument fields.\n\t\t\t\treturn addFieldsToValidator(boundary?.validator ?? zodToConvex(argsSchema), inputArgs)\n\t\t\t})\n\t\t\tconst native = nativeDefinition(async (ctx: any, allArgs: any) => {\n\t\t\t\tconst { argsSchema, argsKeys, boundary } = argsState()\n\t\t\t\tconst returns = returnsSchema()\n\t\t\t\tboundary?.preflight(allArgs)\n\t\t\t\trawArguments.set(ctx, allArgs)\n\t\t\t\tconst added = await customInput(ctx, pick(allArgs, Object.keys(inputArgs)), extra)\n\t\t\t\tconst rawArgs = pick(allArgs, argsKeys)\n\t\t\t\tconst parsed = await argsSchema.safeParseAsync(rawArgs)\n\t\t\t\tif (!parsed.success) {\n\t\t\t\t\tthrow new ConvexError({\n\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\tZodError: JSON.parse(JSON.stringify(parsed.error.issues, null, 2)) as Value[],\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tconst args = parsed.data\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\t// Skipping is rare and has no export thunk to defer to, so data args keep registration errors.\n\t\t\tif (skipConvexValidation && dataArgs) argsState()\n\t\t\tif (skipConvexValidation) native.args = undefined\n\t\t\telse Object.defineProperty(native, 'args', { enumerable: true, get: argsValidator })\n\t\t\treturn builder(native)\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\tnativeDefinition(async (ctx: any, args: any) => {\n\t\t\t\tconst returns = returnsSchema()\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":"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"}
|
package/dist/zod-table.d.mts
DELETED
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
import { PaginationValidatorOptions } from "./querying/shared/filters.mjs";
|
|
2
|
-
import { ExactScalarSelection, ScalarPaginationSchema, ScalarSelection } from "./querying/filters.mjs";
|
|
3
|
-
import { zodToConvex } from "./zod-convex.mjs";
|
|
4
|
-
import { ConvexValidatorFromZod, Zid, convexToZod, zid, zid as zid$1 } from "convex-helpers/server/zod4";
|
|
5
|
-
import { PaginationResult, TableDefinition } from "convex/server";
|
|
6
|
-
import { z } from "zod";
|
|
7
|
-
import { GenericId } from "convex/values";
|
|
8
|
-
//#region src/zod-table.d.ts
|
|
9
|
-
type FieldSchemas = Record<string, z.ZodType>;
|
|
10
|
-
type FieldKey<Fields extends FieldSchemas> = Extract<keyof Fields, string>;
|
|
11
|
-
/**
|
|
12
|
-
* Opinionated lifecycle timestamps — every table has them, server-owned,
|
|
13
|
-
* always excluded from insert/command boundaries. Maintained by the
|
|
14
|
-
* `timestamps` trigger helper (see cvx-kit/triggers).
|
|
15
|
-
*/
|
|
16
|
-
declare const timestampFields: {
|
|
17
|
-
createdAt: z.ZodOptional<z.ZodNumber>;
|
|
18
|
-
updatedAt: z.ZodOptional<z.ZodNumber>;
|
|
19
|
-
archivedAt: z.ZodOptional<z.ZodNumber>;
|
|
20
|
-
};
|
|
21
|
-
type TimestampFields = typeof timestampFields;
|
|
22
|
-
type ReservedStorageField = '_id' | '_creationTime' | keyof TimestampFields;
|
|
23
|
-
type OwnedFields<Fields> = { [Key in keyof Fields]: Key extends ReservedStorageField ? never : Fields[Key]; };
|
|
24
|
-
type SystemFields<Table extends string> = {
|
|
25
|
-
_id: Zid<Table>;
|
|
26
|
-
_creationTime: z.ZodNumber;
|
|
27
|
-
};
|
|
28
|
-
export declare const TIMESTAMP_FIELDS: readonly ['createdAt', 'updatedAt', 'archivedAt'];
|
|
29
|
-
export type TableBoundaryOptions<Fields extends FieldSchemas, ServerFields extends readonly FieldKey<Fields>[], CommandFields extends readonly FieldKey<Fields>[], PublicFields extends readonly FieldKey<Fields & TimestampFields>[]> = {
|
|
30
|
-
serverFields?: ServerFields;
|
|
31
|
-
commandFields?: CommandFields & readonly Exclude<FieldKey<Fields>, ServerFields[number] | keyof TimestampFields>[];
|
|
32
|
-
publicFields?: PublicFields;
|
|
33
|
-
};
|
|
34
|
-
type StrictObject<Fields extends FieldSchemas> = z.ZodObject<Fields, z.core.$strict>;
|
|
35
|
-
type WriteFields<Fields extends FieldSchemas, ServerFields extends readonly FieldKey<Fields>[]> = Omit<Fields & TimestampFields, ServerFields[number] | (typeof TIMESTAMP_FIELDS)[number]>;
|
|
36
|
-
type PartialFields<Fields extends FieldSchemas> = { [Key in keyof Fields]: z.ZodOptional<Fields[Key]>; };
|
|
37
|
-
/** Options shared by the DTO return schema and row projector.
|
|
38
|
-
* Promised contributions must be present, including in reusable options.
|
|
39
|
-
* New extension schemas support validation only: no transforms, pipes,
|
|
40
|
-
* coercion, preprocess, defaults, catches, or overwrites, even when nested.
|
|
41
|
-
* Refinements must validate without mutating their input.
|
|
42
|
-
*/
|
|
43
|
-
export type DtoOptions<IncludeId extends boolean = false, Extension extends FieldSchemas = {}> = ([IncludeId] extends [true] ? {
|
|
44
|
-
_id: IncludeId;
|
|
45
|
-
} : {
|
|
46
|
-
_id?: IncludeId;
|
|
47
|
-
}) & (keyof Extension extends never ? {
|
|
48
|
-
extend?: Extension;
|
|
49
|
-
} : {
|
|
50
|
-
extend: Extension;
|
|
51
|
-
});
|
|
52
|
-
type DtoProjectionOptions<IncludeId extends boolean> = DtoOptions<IncludeId> & {
|
|
53
|
-
extend?: Record<string, never>;
|
|
54
|
-
values?: never;
|
|
55
|
-
};
|
|
56
|
-
type ReservedDtoField = '_id' | '_creationTime' | 'tenant' | '__proto__' | (typeof TIMESTAMP_FIELDS)[number];
|
|
57
|
-
type DtoExtension<Public extends FieldSchemas, Extension extends FieldSchemas> = { [Key in keyof Extension]: Key extends keyof Public | ReservedDtoField ? never : Extension[Key] extends z.ZodPipe | z.ZodTransform ? never : unknown; };
|
|
58
|
-
type KnownExtension<Extension> = string extends keyof Extension ? {} : Extension;
|
|
59
|
-
type DtoSchema<Table extends string, Public extends FieldSchemas, IncludeId extends boolean, Extension extends FieldSchemas = {}> = IncludeId extends true ? StrictObject<Public & {
|
|
60
|
-
_id: Zid<Table>;
|
|
61
|
-
} & KnownExtension<Extension>> : StrictObject<Public & KnownExtension<Extension>>;
|
|
62
|
-
type DtoRow<Row, IncludeId extends boolean> = Row & (true extends IncludeId ? {
|
|
63
|
-
_id: string;
|
|
64
|
-
} : {});
|
|
65
|
-
type DtoValues<Extension extends FieldSchemas> = keyof Extension extends never ? {
|
|
66
|
-
values?: never;
|
|
67
|
-
} : {
|
|
68
|
-
values: z.input<StrictObject<NoInfer<Extension>>>;
|
|
69
|
-
};
|
|
70
|
-
type DtoBoundary<Table extends string, Fields extends FieldSchemas, Public extends FieldSchemas> = {
|
|
71
|
-
dto(): StrictObject<Public>;
|
|
72
|
-
dto<const IncludeId extends boolean>(includeId: IncludeId): DtoSchema<Table, Public, IncludeId>;
|
|
73
|
-
dto<const IncludeId extends boolean = false>(options: DtoProjectionOptions<IncludeId>): DtoSchema<Table, Public, IncludeId>;
|
|
74
|
-
dto<const IncludeId extends boolean = false, const Extension extends FieldSchemas = {}>(options: DtoOptions<IncludeId, Extension> & {
|
|
75
|
-
extend?: DtoExtension<Public, Extension>;
|
|
76
|
-
}): DtoSchema<Table, Public, IncludeId, Extension>;
|
|
77
|
-
toPublicDto(row: z.input<StrictObject<Fields>>): z.output<StrictObject<Public>>;
|
|
78
|
-
toPublicDto<const IncludeId extends boolean>(row: DtoRow<z.input<StrictObject<Fields>>, IncludeId>, includeId: IncludeId): z.output<DtoSchema<Table, Public, IncludeId>>;
|
|
79
|
-
toPublicDto<const IncludeId extends boolean = false>(row: DtoRow<z.input<StrictObject<Fields>>, IncludeId>, options: DtoProjectionOptions<IncludeId>): z.output<DtoSchema<Table, Public, IncludeId>>;
|
|
80
|
-
toPublicDto<const IncludeId extends boolean = false, const Extension extends FieldSchemas = {}>(row: DtoRow<z.input<StrictObject<Fields>>, IncludeId>, options: DtoOptions<IncludeId, Extension> & {
|
|
81
|
-
extend?: DtoExtension<Public, Extension>;
|
|
82
|
-
} & DtoValues<Extension>): z.output<DtoSchema<Table, Public, IncludeId, Extension>>;
|
|
83
|
-
};
|
|
84
|
-
/** Named schema relationships keep generated declarations bounded and consumers fully typed. */
|
|
85
|
-
export type TableBoundary<Table extends string, Fields extends FieldSchemas, ServerFields extends readonly FieldKey<Fields>[], CommandFields extends readonly FieldKey<Fields>[], PublicFields extends readonly FieldKey<Fields & TimestampFields>[]> = DtoBoundary<Table, Fields & TimestampFields, Pick<Fields & TimestampFields, PublicFields[number]>> & {
|
|
86
|
-
paginationOpts<const Selection extends ScalarSelection<Fields & TimestampFields & SystemFields<Table>>>(selection: ExactScalarSelection<Fields & TimestampFields & SystemFields<Table>, Selection>, options?: PaginationValidatorOptions): ScalarPaginationSchema<Fields & TimestampFields & SystemFields<Table>, Selection>;
|
|
87
|
-
tableName: Table;
|
|
88
|
-
storage: StrictObject<Fields & TimestampFields>;
|
|
89
|
-
schema: ReturnType<typeof documentSchema<Fields & TimestampFields, Table>>;
|
|
90
|
-
insertSchema: StrictObject<WriteFields<Fields, ServerFields>>;
|
|
91
|
-
updateSchema: StrictObject<PartialFields<WriteFields<Fields, ServerFields>>>;
|
|
92
|
-
commandInput: StrictObject<Pick<Fields & TimestampFields, CommandFields[number]>>;
|
|
93
|
-
publicDto: StrictObject<Pick<Fields & TimestampFields, PublicFields[number]>>;
|
|
94
|
-
table: TableDefinition<ConvexValidatorFromZod<StrictObject<Fields & TimestampFields>, 'required'>>;
|
|
95
|
-
insert(): StrictObject<WriteFields<Fields, ServerFields>>;
|
|
96
|
-
insert<Mask extends z.util.Mask<keyof WriteFields<Fields, ServerFields>>>(omit: Mask): ZodObjectOmit<StrictObject<WriteFields<Fields, ServerFields>>, Mask>;
|
|
97
|
-
update(): StrictObject<PartialFields<WriteFields<Fields, ServerFields>>>;
|
|
98
|
-
update<Mask extends z.util.Mask<keyof WriteFields<Fields, ServerFields>>>(omit: Mask): ZodObjectOmit<StrictObject<PartialFields<WriteFields<Fields, ServerFields>>>, Mask>;
|
|
99
|
-
tools: {
|
|
100
|
-
insert: StrictObject<Pick<Fields & TimestampFields, CommandFields[number]>>;
|
|
101
|
-
update: StrictObject<{
|
|
102
|
-
data: StrictObject<PartialFields<Pick<Fields & TimestampFields, CommandFields[number]>>>;
|
|
103
|
-
id: z.ZodType<GenericId<Table>, string>;
|
|
104
|
-
}>;
|
|
105
|
-
id: StrictObject<{
|
|
106
|
-
id: z.ZodType<GenericId<Table>, string>;
|
|
107
|
-
}>;
|
|
108
|
-
};
|
|
109
|
-
};
|
|
110
|
-
/** Defines one table and derives its storage, document, write, and DTO boundaries. */
|
|
111
|
-
export declare function zodTable<Table extends string, Fields extends FieldSchemas, const ServerFields extends readonly FieldKey<Fields>[] = readonly [], const CommandFields extends readonly FieldKey<Fields>[] = readonly [], const PublicFields extends readonly FieldKey<Fields & TimestampFields>[] = readonly []>(tableName: Table, fields: (id: typeof zid$1) => Fields & OwnedFields<Fields>, options?: TableBoundaryOptions<Fields, ServerFields, CommandFields, PublicFields>): TableBoundary<Table, Fields, ServerFields, CommandFields, PublicFields>;
|
|
112
|
-
/** Reuses ordinary fields while deriving every boundary through zodTable. */
|
|
113
|
-
export declare function createTable<Shared extends FieldSchemas>(shared: Shared & OwnedFields<Shared>): <Table extends string, Fields extends FieldSchemas, const ServerFields extends readonly FieldKey<Shared & Fields>[] = readonly [], const CommandFields extends readonly FieldKey<Shared & Fields>[] = readonly [], const PublicFields extends readonly FieldKey<Shared & Fields & TimestampFields>[] = readonly []>(tableName: Table, fields: (id: typeof zid$1) => Fields & OwnedFields<Fields> & { [Key in keyof Fields]: Key extends (string extends keyof Shared ? never : keyof Shared) ? never : Fields[Key]; }, options?: TableBoundaryOptions<Shared & Fields, ServerFields, CommandFields, PublicFields>) => TableBoundary<Table, Shared & Fields, ServerFields, CommandFields, PublicFields>;
|
|
114
|
-
declare const tenantFields: {
|
|
115
|
-
tenant: z.ZodString;
|
|
116
|
-
};
|
|
117
|
-
type TenantFields = typeof tenantFields;
|
|
118
|
-
/**
|
|
119
|
-
* A zodTable whose rows are tenant-owned: injects the server-owned `tenant`
|
|
120
|
-
* field (the tenancy boundary — see cvx-kit/tenancy). Like timestamps, it is
|
|
121
|
-
* excluded from insert/update/command boundaries; handlers stamp it from
|
|
122
|
-
* ctx.tenant, row-level security matches on it, and the tenantOwnership
|
|
123
|
-
* trigger forbids reassigning it. Expose it via publicFields only when a DTO
|
|
124
|
-
* genuinely needs it.
|
|
125
|
-
*/
|
|
126
|
-
export declare function tenantTable<Table extends string, Fields extends FieldSchemas, const ServerFields extends readonly FieldKey<Fields>[] = readonly [], const CommandFields extends readonly FieldKey<Fields>[] = readonly [], const PublicFields extends readonly FieldKey<Fields & TenantFields & TimestampFields>[] = readonly []>(tableName: Table, fields: (id: typeof zid$1) => Fields & OwnedFields<Fields> & { [Key in keyof Fields]: Key extends 'tenant' ? never : Fields[Key]; }, options?: TableBoundaryOptions<Fields & TenantFields, readonly (ServerFields[number] | 'tenant')[], CommandFields, PublicFields>): TableBoundary<Table, Fields & {
|
|
127
|
-
tenant: z.ZodString;
|
|
128
|
-
}, readonly ("tenant" | ServerFields[number])[], CommandFields, PublicFields>;
|
|
129
|
-
/**
|
|
130
|
-
* Merges per-module table maps into the application schema map, rejecting
|
|
131
|
-
* duplicate table names across modules — the module-registry combinator for
|
|
132
|
-
* domain/table.ts: `defineSchema(createModule(catalogTables, salesTables))`.
|
|
133
|
-
* Accepts plain maps and `namespace(...)` maps side by side; namespaces add
|
|
134
|
-
* no keys, so the result is the same flat `{ tableName: TableDefinition }`.
|
|
135
|
-
*/
|
|
136
|
-
export declare function createModule<const Maps extends readonly Record<string, TableDefinition<any>>[]>(...maps: Maps): FlatTables<UnionToIntersection<Maps[number]>>;
|
|
137
|
-
type FlatTables<Map> = { [Key in keyof Map as Key extends string ? Key : never]: Map[Key]; };
|
|
138
|
-
declare const namespaceKey: unique symbol;
|
|
139
|
-
/** Declaration-level metadata carried by a `namespace(...)` table map. */
|
|
140
|
-
export type NamespaceInfo<Name extends string, Tables extends string> = {
|
|
141
|
-
readonly name: Name;
|
|
142
|
-
readonly tables: readonly Tables[];
|
|
143
|
-
};
|
|
144
|
-
/**
|
|
145
|
-
* A table map tagged with a namespace. It is still a plain
|
|
146
|
-
* `{ tableName: TableDefinition }` map (the tag is a non-enumerable symbol),
|
|
147
|
-
* so `createModule`/`defineSchema` see exactly the tables they saw before.
|
|
148
|
-
*/
|
|
149
|
-
export type Namespace<Name extends string, Tables extends Record<string, TableDefinition<any>>> = Tables & NamespaceTag<Name, keyof Tables & string>;
|
|
150
|
-
/** The metadata-only shape of a `namespace(...)` map. */
|
|
151
|
-
export type NamespaceTag<Name extends string, Tables extends string> = {
|
|
152
|
-
readonly [namespaceKey]: NamespaceInfo<Name, Tables>;
|
|
153
|
-
};
|
|
154
|
-
type DotsToUnderscores<Name extends string> = Name extends `${infer Head}.${infer Tail}` ? `${Head}_${DotsToUnderscores<Tail>}` : Name;
|
|
155
|
-
/** Stored-table prefix of a namespace: `Microsoft.Inventory` → `Microsoft_Inventory_`. */
|
|
156
|
-
export type NamespacePrefix<Name extends string> = `${DotsToUnderscores<Name>}_`;
|
|
157
|
-
/**
|
|
158
|
-
* Member name of a table. A table stored with its namespace prefix drops it
|
|
159
|
-
* (`Inventory_Items` in `Inventory` → `Items`); any other table name is
|
|
160
|
-
* PascalCased (`itemLedgerEntries` → `ItemLedgerEntries`).
|
|
161
|
-
*/
|
|
162
|
-
export type MemberName<TableName extends string, Name extends string = never> = [Name] extends [never] ? Capitalize<TableName> : TableName extends `${NamespacePrefix<Name>}${infer Rest extends string}` ? Rest extends '' ? Capitalize<TableName> : Rest : Capitalize<TableName>;
|
|
163
|
-
/** Fully qualified name: `<Namespace>.<Member>`, e.g. `Inventory.Items`. */
|
|
164
|
-
export type QualifiedName<Name extends string, TableName extends string> = `${Name}.${MemberName<TableName, Name>}`;
|
|
165
|
-
/** Options for `namespace(...)`. */
|
|
166
|
-
export type NamespaceOptions<Prefixed extends boolean = boolean> = {
|
|
167
|
-
/** Require every key to start with the namespace prefix (`Inventory_`). */
|
|
168
|
-
prefixed?: Prefixed;
|
|
169
|
-
};
|
|
170
|
-
type NamespaceMember = TableDefinition<any> | {
|
|
171
|
-
tableName: string;
|
|
172
|
-
table: TableDefinition<any>;
|
|
173
|
-
};
|
|
174
|
-
type MemberTables<Members extends Record<string, NamespaceMember>> = { [Key in keyof Members]: Members[Key] extends {
|
|
175
|
-
table: infer Table extends TableDefinition<any>;
|
|
176
|
-
} ? Table : Extract<Members[Key], TableDefinition<any>>; };
|
|
177
|
-
type CheckedMembers<Members extends Record<string, NamespaceMember>, Name extends string, Prefixed extends boolean> = { [Key in keyof Members]: Prefixed extends true ? Key extends `${NamespacePrefix<Name>}${infer Rest}` ? Rest extends '' ? never : CheckedMember<Members[Key], Key> : never : CheckedMember<Members[Key], Key>; };
|
|
178
|
-
type CheckedMember<Member, Key> = Member extends {
|
|
179
|
-
tableName: infer TableName;
|
|
180
|
-
} ? TableName extends Key ? Member : {
|
|
181
|
-
tableName: Key;
|
|
182
|
-
table: TableDefinition<any>;
|
|
183
|
-
} : Member;
|
|
184
|
-
type CheckedNamespaceName<Name extends string> = Name extends '' ? never : Name extends `${string}..${string}` | `.${string}` | `${string}.` ? never : Name;
|
|
185
|
-
/**
|
|
186
|
-
* Groups tables under a declaration-level namespace, like AL's
|
|
187
|
-
* `namespace Microsoft.Inventory.Item;`. Keys are the real (stored) table
|
|
188
|
-
* names, exactly as in an un-namespaced module map. A key stored with the
|
|
189
|
-
* namespace prefix (`Inventory_Items`, or `Microsoft_Inventory_Items` for
|
|
190
|
-
* `Microsoft.Inventory`) has the remainder as its member name (`Items`);
|
|
191
|
-
* any other key is PascalCased (`items` → `Items`). The qualified name is
|
|
192
|
-
* `<Namespace>.<Member>` (`Inventory.Items`). Storage, ids, queries and
|
|
193
|
-
* generated types are unchanged.
|
|
194
|
-
*
|
|
195
|
-
* `{ prefixed: true }` requires every key to carry the prefix: a key
|
|
196
|
-
* without it is a type error and a runtime error.
|
|
197
|
-
*
|
|
198
|
-
* A member may be a `TableDefinition` (`items.table.index(...)`) or a table
|
|
199
|
-
* boundary (`items`); a boundary whose `tableName` differs from its key is a
|
|
200
|
-
* type error and a runtime error. Dotted names (`Microsoft.Inventory`) are
|
|
201
|
-
* allowed; each segment is an identifier (`Microsoft.Inventory`, `sales`).
|
|
202
|
-
*/
|
|
203
|
-
export declare function namespace<const Name extends string, const Members extends Record<string, NamespaceMember>, const Prefixed extends boolean = false>(name: Name & CheckedNamespaceName<Name>, members: Members & CheckedMembers<Members, Name, Prefixed>, options?: NamespaceOptions<Prefixed>): Namespace<Name, MemberTables<Members>>;
|
|
204
|
-
/** Stored-table prefix of a namespace: `Microsoft.Inventory` → `Microsoft_Inventory_`. */
|
|
205
|
-
export declare function namespacePrefix<const Name extends string>(name: Name): NamespacePrefix<Name>;
|
|
206
|
-
/**
|
|
207
|
-
* Member name of a table name: without the namespace prefix when given and
|
|
208
|
-
* present (`memberName('Inventory_Items', 'Inventory')` → `Items`), else PascalCased.
|
|
209
|
-
*/
|
|
210
|
-
export declare function memberName<const TableName extends string, const Name extends string = never>(tableName: TableName, namespaceName?: Name): MemberName<TableName, Name>;
|
|
211
|
-
/** The namespace name of a `namespace(...)` map. */
|
|
212
|
-
export declare function namespaceName<const Name extends string>(ns: NamespaceTag<Name, string>): Name;
|
|
213
|
-
/** The stored table names declared in a namespace, in declaration order. */
|
|
214
|
-
export declare function tablesOf<const Tables extends string>(ns: NamespaceTag<string, Tables>): readonly Tables[];
|
|
215
|
-
type NamespaceEntries<Spaces extends readonly NamespaceTag<string, string>[]> = { [Index in keyof Spaces]: Spaces[Index] extends NamespaceTag<infer Name, infer Tables> ? { [TableName in Tables]: Name; } : never; }[number];
|
|
216
|
-
/**
|
|
217
|
-
* Typed, read-only qualified-name lookup over namespaces (no global registry:
|
|
218
|
-
* build one next to `createModule` and import it where labels are needed).
|
|
219
|
-
* Rejects duplicate namespace names and tables claimed by two namespaces.
|
|
220
|
-
*/
|
|
221
|
-
export declare function namespaceIndex<const Spaces extends readonly NamespaceTag<string, string>[]>(...spaces: Spaces): {
|
|
222
|
-
qualifiedName<const Table extends keyof UnionToIntersection<NamespaceEntries<Spaces>> & string>(table: Table): { [Key in Table]: QualifiedName<UnionToIntersection<NamespaceEntries<Spaces>>[Key] & string, Key>; }[Table];
|
|
223
|
-
namespaceOf<const Table extends keyof UnionToIntersection<NamespaceEntries<Spaces>> & string>(table: Table): UnionToIntersection<NamespaceEntries<Spaces>>[Table];
|
|
224
|
-
memberName: typeof memberName;
|
|
225
|
-
tablesOf<const Name extends Spaces[number] extends NamespaceTag<infer Name_1 extends string, string> ? Name_1 : never>(name: Name): readonly { [Table in keyof UnionToIntersection<NamespaceEntries<Spaces>> & string]: UnionToIntersection<NamespaceEntries<Spaces>>[Table] extends Name ? Table : never; }[keyof UnionToIntersection<NamespaceEntries<Spaces>> & string][];
|
|
226
|
-
namespaces: readonly (Spaces[number] extends NamespaceTag<infer Name_1 extends string, string> ? Name_1 : never)[];
|
|
227
|
-
has(table: string): table is keyof UnionToIntersection<NamespaceEntries<Spaces>> & string;
|
|
228
|
-
};
|
|
229
|
-
type UnionToIntersection<Union> = (Union extends unknown ? (member: Union) => void : never) extends ((member: infer Intersection) => void) ? Intersection : never;
|
|
230
|
-
/**
|
|
231
|
-
* Cursor-pagination boundary schemas bridged from Convex's own validators:
|
|
232
|
-
* `args.paginationOpts` for function args, `result` for the page shape.
|
|
233
|
-
* Pair with `include(...).paginate(opts)` (cvx-kit/auth). The result object
|
|
234
|
-
* is deliberately non-strict — Convex may attach engine fields (splitCursor,
|
|
235
|
-
* pageStatus); the page items themselves are validated against the dto.
|
|
236
|
-
* Note: under row-level security, pages may be SHORTER than numItems when
|
|
237
|
-
* rules reject rows mid-page; cursors remain correct.
|
|
238
|
-
*/
|
|
239
|
-
/** Completeness of the requested page, independently of global isDone exhaustion. */
|
|
240
|
-
export type PageCompleteness = 'complete' | 'row-budget' | 'byte-budget' | 'native-limit' | 'result-cap';
|
|
241
|
-
export type EnginePaginationResult<Row> = PaginationResult<Row> & {
|
|
242
|
-
paginationMode?: 'native-search';
|
|
243
|
-
completeness?: PageCompleteness;
|
|
244
|
-
};
|
|
245
|
-
export declare function paginated<Dto extends z.ZodType>(dto: Dto): {
|
|
246
|
-
args: {
|
|
247
|
-
paginationOpts: z.ZodObject<{
|
|
248
|
-
numItems: z.ZodNumber;
|
|
249
|
-
cursor: z.ZodUnion<readonly [z.ZodString, z.ZodNull]>;
|
|
250
|
-
endCursor: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
251
|
-
id: z.ZodOptional<z.ZodNumber>;
|
|
252
|
-
maximumRowsRead: z.ZodOptional<z.ZodNumber>;
|
|
253
|
-
maximumBytesRead: z.ZodOptional<z.ZodNumber>;
|
|
254
|
-
}, z.core.$strict>;
|
|
255
|
-
};
|
|
256
|
-
result: z.ZodObject<{
|
|
257
|
-
page: z.ZodArray<Dto>;
|
|
258
|
-
paginationMode: z.ZodOptional<z.ZodLiteral<"native-search">>;
|
|
259
|
-
isDone: z.ZodBoolean;
|
|
260
|
-
continueCursor: z.ZodString;
|
|
261
|
-
splitCursor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
262
|
-
pageStatus: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
263
|
-
SplitRecommended: "SplitRecommended";
|
|
264
|
-
SplitRequired: "SplitRequired";
|
|
265
|
-
}>>>;
|
|
266
|
-
completeness: z.ZodOptional<z.ZodEnum<{
|
|
267
|
-
"byte-budget": "byte-budget";
|
|
268
|
-
complete: "complete";
|
|
269
|
-
"native-limit": "native-limit";
|
|
270
|
-
"result-cap": "result-cap";
|
|
271
|
-
"row-budget": "row-budget";
|
|
272
|
-
}>>;
|
|
273
|
-
}, z.core.$strip>;
|
|
274
|
-
};
|
|
275
|
-
type VariantSchema = z.ZodDiscriminatedUnion<readonly StrictObject<FieldSchemas>[], string>;
|
|
276
|
-
type VariantDiscriminator<Schema extends VariantSchema> = Schema['_zod']['def']['discriminator'];
|
|
277
|
-
type VariantTags<Schema extends VariantSchema> = Extract<z.output<Schema>[VariantDiscriminator<Schema>], string>;
|
|
278
|
-
type VariantBranch<Schema extends VariantSchema, Tag extends string> = Extract<Schema['options'][number], z.ZodObject<{ [Key in VariantDiscriminator<Schema>]: z.ZodLiteral<Tag>; }, z.core.$strict>>;
|
|
279
|
-
type VariantKeys<Schema extends VariantSchema, Tag extends string> = FieldKey<VariantBranch<Schema, Tag>['shape']>;
|
|
280
|
-
/** Boundary mode supports strict object branches with one string literal tag each. */
|
|
281
|
-
export type VariantBoundaryOptions<Schema extends VariantSchema> = {
|
|
282
|
-
discriminator: VariantDiscriminator<Schema>;
|
|
283
|
-
timestamps?: boolean;
|
|
284
|
-
variants: { [Tag in VariantTags<Schema>]: {
|
|
285
|
-
serverFields?: readonly Exclude<VariantKeys<Schema, Tag>, VariantDiscriminator<Schema>>[];
|
|
286
|
-
commandFields?: readonly Exclude<VariantKeys<Schema, Tag>, VariantDiscriminator<Schema>>[];
|
|
287
|
-
publicFields?: readonly (Exclude<VariantKeys<Schema, Tag>, VariantDiscriminator<Schema>> | keyof TimestampFields)[];
|
|
288
|
-
}; };
|
|
289
|
-
};
|
|
290
|
-
type VariantMaskKeys<Config, Mask extends string> = Config extends { [Key in Mask]?: readonly (infer Field)[]; } ? Extract<Field, string> : never;
|
|
291
|
-
type CheckedVariantOptions<Schema extends VariantSchema, Options extends VariantBoundaryOptions<Schema>> = {
|
|
292
|
-
variants: { [Tag in keyof Options['variants']]: Tag extends VariantTags<Schema> ? {
|
|
293
|
-
commandFields?: readonly Exclude<VariantKeys<Schema, Tag>, VariantDiscriminator<Schema> | VariantMaskKeys<Options['variants'][Tag], 'serverFields'>>[];
|
|
294
|
-
publicFields?: readonly (Exclude<VariantKeys<Schema, Tag>, VariantDiscriminator<Schema>> | (Options extends {
|
|
295
|
-
timestamps: true;
|
|
296
|
-
} ? keyof TimestampFields : never))[];
|
|
297
|
-
} : never; };
|
|
298
|
-
};
|
|
299
|
-
type VariantMode = 'storage' | 'document' | 'insert' | 'update' | 'command' | 'commandUpdate' | 'public';
|
|
300
|
-
type VariantFields<Table extends string, Branch extends StrictObject<FieldSchemas>, Discriminator extends string, Config, Timestamps extends boolean, Mode extends VariantMode> = Mode extends 'storage' ? Branch['shape'] & (true extends Timestamps ? TimestampFields : {}) : Mode extends 'document' ? VariantFields<Table, Branch, Discriminator, Config, Timestamps, 'storage'> & SystemFields<Table> : Mode extends 'public' | 'command' ? Pick<VariantFields<Table, Branch, Discriminator, Config, Timestamps, 'storage'>, Extract<Discriminator | VariantMaskKeys<Config, Mode extends 'public' ? 'publicFields' : 'commandFields'>, keyof VariantFields<Table, Branch, Discriminator, Config, Timestamps, 'storage'>>> : Mode extends 'insert' ? Omit<Branch['shape'], VariantMaskKeys<Config, 'serverFields'>> : PartialFields<Omit<VariantFields<Table, Branch, Discriminator, Config, Timestamps, Mode extends 'update' ? 'insert' : 'command'>, Discriminator>> & Pick<Branch['shape'], Extract<Discriminator, keyof Branch['shape']>>;
|
|
301
|
-
type DerivedVariantBranches<Table extends string, Schema extends VariantSchema, Options extends VariantBoundaryOptions<Schema>, Mode extends VariantMode, IncludeId extends boolean, Branches extends readonly StrictObject<FieldSchemas>[]> = { [Index in keyof Branches]: Branches[Index] extends StrictObject<FieldSchemas> ? StrictObject<VariantFields<Table, Branches[Index], VariantDiscriminator<Schema>, Options['variants'][Extract<z.output<Branches[Index]>[VariantDiscriminator<Schema>], keyof Options['variants']>], Options extends {
|
|
302
|
-
timestamps: infer Enabled;
|
|
303
|
-
} ? true extends Enabled ? true : false : false, Mode> & (IncludeId extends true ? {
|
|
304
|
-
_id: Zid<Table>;
|
|
305
|
-
} : {})> : never; };
|
|
306
|
-
type DerivedVariant<Table extends string, Schema extends VariantSchema, Options extends VariantBoundaryOptions<Schema>, Mode extends VariantMode, IncludeId extends boolean = false> = IncludeId extends true ? z.ZodDiscriminatedUnion<DerivedVariantBranches<Table, Schema, Options, Mode, true, Schema['options']>, VariantDiscriminator<Schema>> : z.ZodDiscriminatedUnion<DerivedVariantBranches<Table, Schema, Options, Mode, false, Schema['options']>, VariantDiscriminator<Schema>>;
|
|
307
|
-
export type VariantTableBoundary<Table extends string, Schema extends VariantSchema, Options extends VariantBoundaryOptions<Schema>> = {
|
|
308
|
-
tableName: Table;
|
|
309
|
-
storage: DerivedVariant<Table, Schema, Options, 'storage'>;
|
|
310
|
-
schema: DerivedVariant<Table, Schema, Options, 'document'>;
|
|
311
|
-
insertSchema: DerivedVariant<Table, Schema, Options, 'insert'>;
|
|
312
|
-
updateSchema: DerivedVariant<Table, Schema, Options, 'update'>;
|
|
313
|
-
commandInput: DerivedVariant<Table, Schema, Options, 'command'>;
|
|
314
|
-
publicDto: DerivedVariant<Table, Schema, Options, 'public'>;
|
|
315
|
-
table: TableDefinition<ConvexValidatorFromZod<DerivedVariant<Table, Schema, Options, 'storage'>, 'required'>>;
|
|
316
|
-
dto(): DerivedVariant<Table, Schema, Options, 'public'>;
|
|
317
|
-
dto<const IncludeId extends boolean>(includeId: IncludeId): DerivedVariant<Table, Schema, Options, 'public', IncludeId>;
|
|
318
|
-
toPublicDto(row: z.input<DerivedVariant<Table, Schema, Options, 'storage'>>): z.output<DerivedVariant<Table, Schema, Options, 'public'>>;
|
|
319
|
-
toPublicDto<const IncludeId extends boolean>(row: DtoRow<z.input<DerivedVariant<Table, Schema, Options, 'storage'>>, IncludeId>, includeId: IncludeId): z.output<DerivedVariant<Table, Schema, Options, 'public', IncludeId>>;
|
|
320
|
-
tools: {
|
|
321
|
-
id: StrictObject<{
|
|
322
|
-
id: z.ZodType<GenericId<Table>, string>;
|
|
323
|
-
}>;
|
|
324
|
-
insert: z.ZodType<z.output<DerivedVariant<Table, Schema, Options, 'command'>>, z.input<DerivedVariant<Table, Schema, Options, 'command'>>>;
|
|
325
|
-
update: StrictObject<{
|
|
326
|
-
id: z.ZodType<GenericId<Table>, string>;
|
|
327
|
-
data: z.ZodType<z.output<DerivedVariant<Table, Schema, Options, 'commandUpdate'>>, z.input<DerivedVariant<Table, Schema, Options, 'commandUpdate'>>>;
|
|
328
|
-
}>;
|
|
329
|
-
};
|
|
330
|
-
};
|
|
331
|
-
/** Legacy mode preserves arbitrary storage; the third argument opts into derived boundaries. */
|
|
332
|
-
export declare function zodVariantTable<Table extends string, Schema extends z.ZodType>(tableName: Table, storage: Schema): {
|
|
333
|
-
tableName: Table;
|
|
334
|
-
storage: Schema;
|
|
335
|
-
insertSchema: Schema;
|
|
336
|
-
table: TableDefinition<ConvexValidatorFromZod<Schema, 'required'>>;
|
|
337
|
-
};
|
|
338
|
-
export declare function zodVariantTable<Table extends string, Schema extends VariantSchema, const Options extends VariantBoundaryOptions<Schema>>(tableName: Table, storage: Schema, options: Options & CheckedVariantOptions<Schema, NoInfer<Options>>): VariantTableBoundary<Table, Schema, Options>;
|
|
339
|
-
/**
|
|
340
|
-
* A zid that presents as a plain string in generated JSON schemas so
|
|
341
|
-
* LLM-tool inputs stay primitive, while keeping the Id type at compile time.
|
|
342
|
-
*/
|
|
343
|
-
export declare function jsonSafeZid<Table extends string>(tableName: Table): z.ZodType<GenericId<Table>, string>;
|
|
344
|
-
type ZodObjectOmit<Schema extends z.ZodObject<any, any>, OmitMask extends z.util.Mask<keyof Schema['shape']>> = Schema extends z.ZodObject<infer ObjectFields, infer Config> ? z.ZodObject<z.util.Flatten<Omit<ObjectFields, Extract<keyof ObjectFields, keyof OmitMask>>>, Config> : never;
|
|
345
|
-
declare function documentSchema<Fields extends FieldSchemas, Table extends string>(fields: Fields, tableName: Table): z.ZodObject<Fields & {
|
|
346
|
-
_id: Zid<Table>;
|
|
347
|
-
_creationTime: z.ZodNumber;
|
|
348
|
-
} extends (infer T) ? { -readonly [P in keyof T]: T[P]; } : never, z.core.$strict>;
|
|
349
|
-
//#endregion
|
|
350
|
-
export { convexToZod, zid, zodToConvex };
|
|
351
|
-
//# sourceMappingURL=zod-table.d.mts.map
|
package/dist/zod-table.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{zodToConvex as e}from"./zod-convex.mjs";import{memoize as t}from"./modules/contracts/lazy.mjs";import{pageResult as n}from"./querying/shared/page.mjs";import{scalarPaginationSchema as r}from"./querying/filters.mjs";import{convexToZod as i,convexToZod as a,zid as o,zid as s}from"convex-helpers/server/zod4";import{defineTable as c,paginationOptsValidator as l}from"convex/server";import{z as u}from"zod";const d={createdAt:u.number().optional(),updatedAt:u.number().optional(),archivedAt:u.number().optional()},f=[`createdAt`,`updatedAt`,`archivedAt`];function p(n,i,a={}){let o=i(s);B(o,[`_id`,`_creationTime`,...f]);let l={...o,...d};V(l,a.serverFields??[],a.commandFields??[],a.publicFields??[]);let p=u.strictObject({...l}),m=t(()=>I(l,n)),h=[...f,...a.serverFields??[]],g=[...a.commandFields??[]],_=[...a.publicFields??[]],v=t(()=>R(l,h)),y=t(()=>L(l,g)),b=t(()=>u.strictObject({...v()})),x=t(()=>u.strictObject({...v()}).partial()),S=t(()=>u.strictObject({...y()})),C=t(()=>u.strictObject(L(l,_))),w={get schema(){return m()},get insertSchema(){return b()},get updateSchema(){return x()},get commandInput(){return S()},get publicDto(){return C()}},T=t(()=>u.strictObject({})),E=t(()=>/* @__PURE__ */ new Set([`_id`,`_creationTime`,`tenant`,`__proto__`,...f]));function D(e){return O(e)}function O(e){let t=e===!0||e===!1?{_id:e}:e,n=t?.extend??{};if(k(n),!t?._id&&Object.keys(n).length===0)return w.publicDto;let r=u.strictObject({...w.publicDto.shape,...n});return t?._id?r.extend({_id:w.schema.shape._id}):r}function k(e){for(let t of Object.keys(e)){if(E().has(t)||Object.hasOwn(w.publicDto.shape,t))throw Error(`DTO extension collision for field "${t}" on table "${n}"`);z(e[t])}}function A(e,t){let n=t===!0||t===!1?{_id:t}:t;k(n?.extend??{});let r=w.publicDto.parse(Object.fromEntries(Object.keys(w.publicDto.shape).map(t=>[t,e[t]]))),i=n?.extend,a=(i==null?T():u.strictObject(i)).parse(n?.values??{}),o={...r,...a};return n?._id&&(o._id=w.schema.shape._id.parse(`_id`in e?e._id:void 0)),o}function M(e){return e?w.insertSchema.omit(e):w.insertSchema}function N(e){return e?w.updateSchema.omit(e):w.updateSchema}let P=e(p),H=c(P),U=()=>Object.fromEntries(Object.entries(w.schema.shape).map(([t,n])=>[t,e(n)]));function W(e,t){return r(U(),e,t)}let G=t(()=>({insert:w.commandInput,update:u.strictObject({data:u.strictObject({...y()}).partial(),id:j(n)}),id:u.strictObject({id:j(n)})}));return{tableName:n,get schema(){return w.schema},set schema(e){F(this,`schema`,e)},storage:p,get insertSchema(){return w.insertSchema},set insertSchema(e){F(this,`insertSchema`,e)},get updateSchema(){return w.updateSchema},set updateSchema(e){F(this,`updateSchema`,e)},get commandInput(){return w.commandInput},set commandInput(e){F(this,`commandInput`,e)},get publicDto(){return w.publicDto},set publicDto(e){F(this,`publicDto`,e)},dto:D,toPublicDto:A,paginationOpts:W,table:H,insert:M,update:N,get tools(){return G()},set tools(e){F(this,`tools`,e)}}}function m(e){return B(e,[`_id`,`_creationTime`,...f]),function(t,n,r={}){return p(t,r=>{let i=n(r);for(let n of Object.keys(i))if(Object.hasOwn(e,n))throw Error(`Duplicate shared table field "${n}" on table "${t}"`);return B(i,[`_id`,`_creationTime`,...f]),{...e,...i}},r)}}const h={tenant:u.string().min(1)};function g(e,t,n={}){return p(e,e=>{let n=t(e);return B(n,[`tenant`,`_id`,`_creationTime`,...f]),{...n,...h}},{...n,serverFields:[...n.serverFields??[],`tenant`]})}function _(...e){let t={},n=/* @__PURE__ */ new Set;for(let r of e){let e=S(r);if(e){if(n.has(e.name))throw Error(`Namespace "${e.name}" is declared more than once`);n.add(e.name)}for(let[e,n]of Object.entries(r)){if(e in t)throw Error(`Table "${e}" is declared by more than one module`);t[e]=n}}return t}const v=Symbol.for(`cvx-kit/zod-table/namespace`),y=/^[A-Za-z][A-Za-z0-9]*$/,b=/^[A-Za-z][A-Za-z0-9_]*$/;function x(e,t,n={}){if(!e.split(`.`).every(e=>y.test(e)))throw Error(`Namespace "${e}" must be dot-separated identifiers (e.g. "Microsoft.Inventory" or "sales")`);let r={};for(let[i,a]of Object.entries(t)){if(!b.test(i))throw Error(`Namespace "${e}" member "${i}" must be a table name (letters, digits and underscores)`);if(n.prefixed&&!w(i,e))throw Error(`Namespace "${e}" member "${i}" must start with "${C(e)}"`);if(`tableName`in a){if(a.tableName!==i)throw Error(`Namespace "${e}" member "${i}" holds table "${a.tableName}"; keys must be the table name`);r[i]=a.table}else r[i]=a}return Object.defineProperty(r,v,{value:Object.freeze({name:e,tables:Object.freeze(Object.keys(r))}),enumerable:!1}),r}function S(e){return e[v]}function C(e){return`${e.replaceAll(`.`,`_`)}_`}function w(e,t){let n=C(t);return e.startsWith(n)&&e.length>n.length}function T(e,t){return t!==void 0&&w(e,t)?e.slice(C(t).length):e.charAt(0).toUpperCase()+e.slice(1)}function E(e){return S(e).name}function D(e){return S(e).tables}function O(...e){let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Map;for(let r of e){let e=S(r);if(!e)throw Error(`namespaceIndex accepts only namespace(...) maps`);if(n.has(e.name))throw Error(`Namespace "${e.name}" is declared more than once`);n.set(e.name,e.tables);for(let n of e.tables){let r=t.get(n);if(r)throw Error(`Table "${n}" is declared by namespaces "${r}" and "${e.name}"`);t.set(n,e.name)}}let r=e=>{let n=t.get(e);if(n===void 0)throw Error(`Table "${e}" is not in a namespace`);return n};return{qualifiedName(e){let t=r(e);return`${t}.${T(e,t)}`},namespaceOf(e){return r(e)},memberName:T,tablesOf(e){let t=n.get(e);if(!t)throw Error(`Namespace "${e}" is not indexed`);return t},namespaces:[...n.keys()],has(e){return t.has(e)}}}function k(e){return{args:{paginationOpts:a(l)},result:n(e)}}function A(t,n,r){return r?M(t,n,r):{tableName:t,storage:n,insertSchema:n,table:c(e(n))}}function j(e){let t=s(e);return u.string().refine(e=>t.safeParse(e).success).describe(`Convex document id for table "${e}"; validated against the table by Convex`)}function M(n,r,i){if(!(r instanceof u.ZodDiscriminatedUnion)||r.def.discriminator!==i.discriminator)throw Error(`Variant boundaries require a discriminated union with the configured discriminator`);if(r.def.checks?.length)throw Error(`Variant boundaries do not support union-level refinements`);let a=i.timestamps,o=i.discriminator;if([`_id`,`_creationTime`,...f].includes(o))throw Error(`Variant discriminator cannot be a reserved field`);let l=/* @__PURE__ */ new Map;for(let e of r.options){if(!(e instanceof u.ZodObject)||!(e.def.catchall instanceof u.ZodNever))throw Error(`Variant boundaries require strict object branches`);if(e.def.checks?.length)throw Error(`Variant boundaries do not support object-level refinements`);try{z(e,/* @__PURE__ */ new Set,!0)}catch(e){throw Error(`Variant boundaries require supported value-preserving field validators without object catchalls`,{cause:e})}let r=e.shape[o];if(!(r instanceof u.ZodLiteral)||r.values.size!==1)throw Error(`Variant branches require one string literal discriminator`);let s=[...r.values][0];if(!u.string().safeParse(s).success)throw Error(`Variant branches require a string discriminator`);let c=s;if(l.has(c))throw Error(`Duplicate variant discriminator "${c}"`);if(!Object.hasOwn(i.variants,c))throw Error(`Missing variant configuration "${c}"`);let p={serverFields:[...i.variants[c].serverFields??[]],commandFields:[...i.variants[c].commandFields??[]],publicFields:[...i.variants[c].publicFields??[]]};B(e.shape,[`_id`,`_creationTime`,...a===!1?[]:f]);let m={...e.shape};a&&Object.assign(m,d),V(m,p.serverFields??[],p.commandFields??[],p.publicFields??[],a!==!1);for(let e of[p.serverFields,p.commandFields,p.publicFields])if(e?.includes(o))throw Error(`The variant discriminator is retained automatically and cannot appear in masks`);for(let e of p.commandFields)N(m[e]);let h=u.strictObject({...m}),g=t(()=>u.strictObject(R(m,[...a===!1?[]:f,...p.serverFields??[]]))),_=t(()=>u.strictObject(L(m,[o,...p.commandFields??[]]))),v=e=>e.partial().extend({[o]:r}),y=t(()=>I(m,n)),b=t(()=>v(u.strictObject(R(m,[...a===!1?[]:f,...p.serverFields])))),x=t(()=>v(u.strictObject(L(m,[o,...p.commandFields])))),S=t(()=>u.strictObject(L(m,[o,...p.commandFields]))),C=t(()=>u.strictObject(L(m,[o,...p.publicFields??[]])));l.set(c,{storage:h,get document(){return y()},get insert(){return g()},get update(){return b()},get command(){return _()},get commandUpdate(){return x()},get toolCommand(){return S()},get public(){return C()}})}for(let e of Object.keys(i.variants))if(!l.has(e))throw Error(`Unknown variant configuration "${e}"`);function p(e,t=!1,r=!1){let i=[...l.values()].map(i=>{let a=r&&e===`command`?i.toolCommand:i[e];return r?u.strictObject(Object.fromEntries(Object.entries(a.shape).map(([e,t])=>[e,P(t)]))):t?a.extend({_id:s(n)}):a});if(!i.length)throw Error(`Variant boundaries require at least one branch`);return u.discriminatedUnion(o,i)}let m=p(`storage`),h=t(()=>p(`document`)),g=t(()=>p(`insert`)),_=t(()=>p(`update`)),v=t(()=>p(`command`)),y=t(()=>p(`public`));function b(e=!1){return e?p(`public`,!0):y()}let x;function S(e,t=!1){let r=u.string().parse(e[o]),i=l.get(r);if(!i)throw Error(`Unknown variant discriminator "${r}"`);let a=t?i.public.extend({_id:x??=s(n)}):i.public;return a.parse(Object.fromEntries(Object.keys(a.shape).filter(t=>Object.hasOwn(e,t)).map(t=>[t,e[t]])))}let C=t(()=>({id:u.strictObject({id:j(n)}),insert:p(`command`,!1,!0),update:u.strictObject({id:j(n),data:p(`commandUpdate`,!1,!0)})}));return{tableName:n,storage:m,get schema(){return h()},set schema(e){F(this,`schema`,e)},get insertSchema(){return g()},set insertSchema(e){F(this,`insertSchema`,e)},get updateSchema(){return _()},set updateSchema(e){F(this,`updateSchema`,e)},get commandInput(){return v()},set commandInput(e){F(this,`commandInput`,e)},get publicDto(){return y()},set publicDto(e){F(this,`publicDto`,e)},dto:b,toPublicDto:S,table:c(e(m)),get tools(){return C()},set tools(e){F(this,`tools`,e)}}}function N(e){if(!(e instanceof u.ZodType))throw Error(`Variant tools require classic Zod field schemas`);if(e instanceof u.ZodBigInt||e instanceof u.ZodLiteral&&[...e.values].some(e=>u.bigint().safeParse(e).success))throw Error(`Variant tool command fields cannot contain bigint; JSON Schema cannot represent it`);e instanceof u.ZodOptional||e instanceof u.ZodNullable||e instanceof u.ZodNonOptional?N(e.unwrap()):e instanceof u.ZodArray?N(e.element):e instanceof u.ZodObject?Object.values(e.shape).forEach(N):e instanceof u.ZodUnion?e.options.forEach(N):e instanceof u.ZodRecord?(N(e.keyType),N(e.valueType)):e instanceof u.ZodTuple?(e.def.items.forEach(N),e.def.rest&&N(e.def.rest)):e instanceof u.ZodIntersection&&(N(e.def.left),N(e.def.right))}function P(t){if(!(t instanceof u.ZodType))throw Error(`Variant tools require classic Zod field schemas`);if(t instanceof u.ZodBigInt||t instanceof u.ZodLiteral&&[...t.values].some(e=>u.bigint().safeParse(e).success))throw Error(`Variant tool command fields cannot contain bigint; JSON Schema cannot represent it`);let n=e(t);if(n.kind===`id`){let e=j(n.tableName);return n.isOptional===`optional`?e.optional().refine(e=>t.safeParse(e).success):e.refine(e=>t.safeParse(e).success)}if(t instanceof u.ZodOptional||t instanceof u.ZodNullable||t instanceof u.ZodNonOptional)return t.clone({...t.def,innerType:P(t.unwrap())});if(t instanceof u.ZodArray)return t.clone({...t.def,element:P(t.element)});if(t instanceof u.ZodObject){let e=Object.fromEntries(Object.entries(t.shape).map(([e,t])=>[e,P(t)]));return t.clone(Object.assign({},t.def,{shape:e}))}return t instanceof u.ZodUnion?t.clone({...t.def,options:t.options.map(P)}):t instanceof u.ZodRecord?t.clone({...t.def,keyType:P(t.keyType),valueType:P(t.valueType)}):t instanceof u.ZodTuple?t.clone({...t.def,items:t.def.items.map(P),rest:t.def.rest?P(t.def.rest):null}):t instanceof u.ZodIntersection?t.clone({...t.def,left:P(t.def.left),right:P(t.def.right)}):t}function F(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function I(e,t){return u.strictObject({...e,_id:s(t),_creationTime:u.number()})}function L(e,t){return Object.fromEntries(t.map(t=>[t,e[t]]))}function R(e,t){let n=new Set(t);return Object.fromEntries(Object.entries(e).filter(([e])=>!n.has(e)))}function z(t,n=/* @__PURE__ */ new Set,r=!1){if(n.has(t))return;n.add(t);let i=t._zod.def,a=()=>{throw Error(`DTO extensions require supported value-preserving validation schemas`)};`coerce`in i&&i.coerce&&a(),`normalize`in i&&i.normalize&&a();let o=e=>z(e,n,r);for(let e of i.checks??[])if(e._zod.def.check===`overwrite`&&a(),`normalize`in e._zod.def&&e._zod.def.normalize&&a(),e._zod.def.check===`property`&&o(e._zod.def.schema),e._zod.def.check===`properties`)for(let t of Object.values(e._zod.def.shape))o(t);switch(i.type){case`custom`:if(r&&e(t).kind===`id`)return;a();return;case`string`:case`number`:case`boolean`:case`bigint`:case`date`:case`symbol`:case`null`:case`undefined`:case`void`:case`never`:case`literal`:case`enum`:return;case`object`:if(r&&i.catchall&&i.catchall._zod.def.type!==`never`)throw Error(`Variant fields cannot use object catchalls; use a record field instead`);for(let e of Object.values(i.shape))o(e);i.catchall&&o(i.catchall);return;case`array`:o(i.element);return;case`optional`:case`nullable`:case`nonoptional`:o(i.innerType);return;case`union`:for(let e of i.options)o(e);return;case`intersection`:o(i.left),o(i.right);return;case`tuple`:for(let e of i.items)o(e);i.rest&&o(i.rest);return;case`record`:o(i.keyType),o(i.valueType);return;default:a()}}function B(e,t){for(let n of t)if(Object.hasOwn(e,n))throw Error(`Reserved table field "${n}" cannot be declared`)}function V(e,t,n,r,i=!0){for(let i of[...t,...n,...r])if(!Object.hasOwn(e,i))throw Error(`Unknown table field "${i}"`);let a=/* @__PURE__ */ new Set([...i?f:[],...t]);for(let e of n)if(a.has(e))throw Error(`Server-owned field "${e}" cannot be a command input`)}export{f as TIMESTAMP_FIELDS,i as convexToZod,_ as createModule,m as createTable,j as jsonSafeZid,T as memberName,x as namespace,O as namespaceIndex,E as namespaceName,C as namespacePrefix,k as paginated,D as tablesOf,g as tenantTable,o as zid,p as zodTable,e as zodToConvex,A as zodVariantTable};
|
|
2
|
-
//# sourceMappingURL=zod-table.mjs.map
|