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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.mjs","names":["KPlan","declared","transform","base","normalisers","checks","dispatch","parseSchema","context","WalkContext","output","walk","schema","input","KValidationError","safeParseSchema","runDeclared","planOf","value","hasDeclaredBehaviour","containsTransform","FAIL","noRecords","emptyPlan","checkedPlan","transformPlan","path","below","CheckContext","issue","compilePlan","node","rootPlan","runPlan","run","isRunOp","index","record","isNormaliser","root","argSchema","fields","fieldsOf","key","plan","asSchema","combined","recordOf","keyPlan","valuePlan","member","membersOf","dispatchOf","option","options","field","rootOf","fieldRoot","dispatchTo","literalOf","enumOf","full","walkRoot","strip","defaultsBelow","callbackResult","callbackOf","walkRun","normaliser","normalise","before","check","runCheck","stringOf","limit","numberArg","sizeOf","messageOf","unitOf","size","pattern","settled","optionsOf","isThenable","invalidType","walkArray","isPlainObject","walkObject","walkRecord","walkUnion","walkDiscriminated","isIsoDate","isIsoDateTime","walkTimestamp","isJson","walkLeaf","time","isTimestamp","maxTimestamp","expected","values","quoted","element","out","failed","copyKnown","setOwn","stripped","stop","keySchema","valueSchema","keys","outputKey","isRecordKey","recordKeyMessage","issues","discriminator","KConversionFailure","kind","result","code","target","receivedOf","prototype","relation","message","fallback","current"],"sources":["../../src/k/parse.ts"],"sourcesContent":["/* oxlint-disable anti-slop/no-runtime-typeof, anti-slop/no-unknown-parameters, anti-slop/no-unknown-returns, anti-slop/no-unsafe-dictionary-type -- This module is the decoding boundary: it receives undecoded values, narrows them by representation and hands them back as the schema's output, which the typed callers in schema.ts name. */\nimport { membersOf } from './compile'\nimport { KConversionFailure, isIsoDate, isIsoDateTime, isTimestamp, maxTimestamp } from './formats'\nimport {\n\tKValidationError,\n\ttype KIssue,\n\ttype KIssueCode,\n\ttype KIssueInput,\n\ttype KSafeParseResult,\n} from './issues'\nimport type { KCheckContext } from './schema'\nimport type {\n\tKDiscriminated,\n\tKFields,\n\tKLiteralValue,\n\tKNode,\n\tKPath,\n\tKRefineOptions,\n\tKType,\n} from './types'\n\n/**\n * The memoised parse plan of one chain record. `declared` says whether the subtree declares any\n * behaviour a structurally valid value still needs (default, normaliser, check, transform, integer or\n * JSON check); `transform` whether it holds a transform or pipe. A record at the tip of a run of checks\n * and normalisers also records the run: the record below it and the run's normalisers and checks in\n * declared order. A discriminated union root records its dispatch table.\n */\nexport class KPlan {\n\treadonly declared: boolean\n\treadonly transform: boolean\n\treadonly base: KNode | null\n\treadonly normalisers: readonly KNode[]\n\treadonly checks: readonly KNode[]\n\treadonly dispatch: ReadonlyMap<KLiteralValue, KNode> | null\n\n\tconstructor(\n\t\tdeclared: boolean,\n\t\ttransform: boolean,\n\t\tbase: KNode | null,\n\t\tnormalisers: readonly KNode[],\n\t\tchecks: readonly KNode[],\n\t\tdispatch: ReadonlyMap<KLiteralValue, KNode> | null,\n\t) {\n\t\tthis.declared = declared\n\t\tthis.transform = transform\n\t\tthis.base = base\n\t\tthis.normalisers = normalisers\n\t\tthis.checks = checks\n\t\tthis.dispatch = dispatch\n\t}\n}\n\nexport function parseSchema(schema: KNode, input: unknown): unknown {\n\tconst context = new WalkContext()\n\tconst output = walk(schema, input, context, true, false)\n\tif (context.issues.length > 0) throw new KValidationError(context.issues)\n\treturn output\n}\n\nexport function safeParseSchema(schema: KNode, input: unknown): KSafeParseResult<unknown> {\n\tconst context = new WalkContext()\n\tconst output = walk(schema, input, context, true, false)\n\tif (context.issues.length > 0) return { success: false, issues: context.issues }\n\treturn { success: true, data: output }\n}\n\n/**\n * The function-boundary entry (KTD3): `value` has already passed the schema's native validator, so only\n * planned paths are visited. With an empty plan the very same value is returned without a walk.\n */\nexport function runDeclared(schema: KNode, value: unknown): unknown {\n\tif (!planOf(schema).declared) return value\n\tconst context = new WalkContext()\n\tconst output = walk(schema, value, context, false, false)\n\tif (context.issues.length > 0) throw new KValidationError(context.issues)\n\treturn output\n}\n\nexport function hasDeclaredBehaviour(schema: KNode): boolean {\n\treturn planOf(schema).declared\n}\n\n/** Whether a transform or pipe sits anywhere in the schema's tree; table fields and return shapes reject it. */\nexport function containsTransform(schema: KNode): boolean {\n\treturn planOf(schema).transform\n}\n\nconst FAIL: unique symbol = Symbol('k.fail')\nconst noRecords: readonly KNode[] = []\nconst emptyPlan = new KPlan(false, false, null, noRecords, noRecords, null)\nconst checkedPlan = new KPlan(true, false, null, noRecords, noRecords, null)\nconst transformPlan = new KPlan(true, true, null, noRecords, noRecords, null)\n\nclass WalkContext {\n\tissues: KIssue[] = []\n\treadonly path: KPath = []\n\n\tadd(code: KIssueCode, message: string, below: KPath | undefined): void {\n\t\tconst path = below === undefined ? [...this.path] : [...this.path, ...below]\n\t\tthis.issues.push({ path, code, message })\n\t}\n}\n\nclass CheckContext implements KCheckContext {\n\treadonly context: WalkContext\n\n\tconstructor(context: WalkContext) {\n\t\tthis.context = context\n\t}\n\n\taddIssue(issue: KIssueInput): void {\n\t\tthis.context.add(issue.code ?? 'custom', issue.message, issue.path)\n\t}\n}\n\nfunction planOf(node: KNode): KPlan {\n\treturn (node.plan ??= compilePlan(node))\n}\n\nfunction compilePlan(node: KNode): KPlan {\n\tif (node.prev === null) return rootPlan(node)\n\tswitch (node.op) {\n\t\tcase 'optional':\n\t\tcase 'partial':\n\t\tcase 'nullable':\n\t\tcase 'strip':\n\t\tcase 'describe':\n\t\t\treturn planOf(node.prev)\n\t\tcase 'default':\n\t\t\treturn planOf(node.prev).transform ? transformPlan : checkedPlan\n\t\tcase 'transform':\n\t\tcase 'pipe':\n\t\t\treturn transformPlan\n\t\tdefault:\n\t\t\treturn runPlan(node)\n\t}\n}\n\nfunction runPlan(node: KNode): KPlan {\n\tconst run: KNode[] = []\n\tlet base = node\n\twhile (base.prev !== null && (isRunOp(base) || base.op === 'describe')) {\n\t\tif (base.op !== 'describe') run.push(base)\n\t\tbase = base.prev\n\t}\n\tconst normalisers: KNode[] = []\n\tconst checks: KNode[] = []\n\tfor (let index = run.length - 1; index >= 0; index--) {\n\t\tconst record = run[index]\n\t\tif (isNormaliser(record)) normalisers.push(record)\n\t\telse checks.push(record)\n\t}\n\treturn new KPlan(true, planOf(base).transform, base, normalisers, checks, null)\n}\n\nfunction rootPlan(root: KNode): KPlan {\n\tswitch (root.op) {\n\t\tcase 'int':\n\t\tcase 'json':\n\t\tcase 'isoDate':\n\t\tcase 'isoDateTime':\n\t\tcase 'timestamp':\n\t\t\treturn checkedPlan\n\t\tcase 'array':\n\t\t\treturn planOf(argSchema(root))\n\t\tcase 'object': {\n\t\t\tconst fields = fieldsOf(root)\n\t\t\tlet declared = false\n\t\t\tlet transform = false\n\t\t\tfor (const key in fields) {\n\t\t\t\tconst plan = planOf(asSchema(fields[key]))\n\t\t\t\tdeclared ||= plan.declared\n\t\t\t\ttransform ||= plan.transform\n\t\t\t}\n\t\t\treturn combined(declared, transform)\n\t\t}\n\t\tcase 'record': {\n\t\t\tconst [key, value] = recordOf(root)\n\t\t\tconst keyPlan = planOf(key)\n\t\t\tconst valuePlan = planOf(value)\n\t\t\treturn combined(\n\t\t\t\tkeyPlan.declared || valuePlan.declared,\n\t\t\t\tkeyPlan.transform || valuePlan.transform,\n\t\t\t)\n\t\t}\n\t\tcase 'union':\n\t\tcase 'discriminatedUnion': {\n\t\t\tlet declared = false\n\t\t\tlet transform = false\n\t\t\tfor (const member of membersOf(root)) {\n\t\t\t\tconst plan = planOf(member)\n\t\t\t\tdeclared ||= plan.declared\n\t\t\t\ttransform ||= plan.transform\n\t\t\t}\n\t\t\tif (root.op === 'union') return combined(declared, transform)\n\t\t\treturn new KPlan(declared, transform, null, noRecords, noRecords, dispatchOf(root))\n\t\t}\n\t\tdefault:\n\t\t\treturn emptyPlan\n\t}\n}\n\nfunction combined(declared: boolean, transform: boolean): KPlan {\n\tif (transform) return transformPlan\n\treturn declared ? checkedPlan : emptyPlan\n}\n\nfunction dispatchOf(root: KNode): Map<KLiteralValue, KNode> {\n\t// SAFETY: k.discriminatedUnion stores its key and object options as the root argument.\n\tconst { key, options } = root.arg as KDiscriminated\n\tconst dispatch = new Map<KLiteralValue, KNode>()\n\tfor (const option of options) {\n\t\tconst member = asSchema(option)\n\t\tconst field = fieldsOf(rootOf(member))[key]\n\t\tif (field === undefined)\n\t\t\tthrow new Error(`k.discriminatedUnion: an option has no '${key}' field`)\n\t\tconst fieldRoot = rootOf(asSchema(field))\n\t\tif (fieldRoot.op === 'literal') dispatchTo(dispatch, key, literalOf(fieldRoot), member)\n\t\telse if (fieldRoot.op === 'enum')\n\t\t\tfor (const value of enumOf(fieldRoot)) dispatchTo(dispatch, key, value, member)\n\t\telse throw new Error(`k.discriminatedUnion: '${key}' must be a literal or enum on every option`)\n\t}\n\treturn dispatch\n}\n\n/** Two options sharing a discriminator value would make dispatch pick a branch the native union may not. */\nfunction dispatchTo(\n\tdispatch: Map<KLiteralValue, KNode>,\n\tkey: string,\n\tvalue: KLiteralValue,\n\tmember: KNode,\n): void {\n\tif (dispatch.has(value))\n\t\tthrow new Error(\n\t\t\t`k.discriminatedUnion: more than one option has '${key}' value ${JSON.stringify(String(value))}`,\n\t\t)\n\tdispatch.set(value, member)\n}\n\nfunction walk(\n\tnode: KNode,\n\tvalue: unknown,\n\tcontext: WalkContext,\n\tfull: boolean,\n\tstrip: boolean,\n): unknown {\n\tif (!full && !planOf(node).declared) return value\n\tif (node.prev === null) return walkRoot(node, value, context, full, strip)\n\tswitch (node.op) {\n\t\tcase 'optional':\n\t\t\tif (value === undefined && !defaultsBelow(node.prev)) return undefined\n\t\t\treturn walk(node.prev, value, context, full, strip)\n\t\tcase 'partial':\n\t\t\treturn value === undefined ? undefined : walk(node.prev, value, context, full, strip)\n\t\tcase 'describe':\n\t\t\treturn walk(node.prev, value, context, full, strip)\n\t\tcase 'nullable':\n\t\t\treturn value === null ? null : walk(node.prev, value, context, full, strip)\n\t\tcase 'default':\n\t\t\tif (value !== undefined) return walk(node.prev, value, context, full, strip)\n\t\t\tif (planOf(node.prev).transform) return node.arg\n\t\t\treturn walk(node.prev, node.arg, context, full, strip)\n\t\tcase 'strip':\n\t\t\treturn walk(node.prev, value, context, full, true)\n\t\tcase 'transform': {\n\t\t\tconst input = walk(node.prev, value, context, full, strip)\n\t\t\treturn input === FAIL ? FAIL : callbackResult(callbackOf(node)(input), context, 'transform')\n\t\t}\n\t\tcase 'pipe': {\n\t\t\tconst input = walk(node.prev, value, context, full, strip)\n\t\t\treturn input === FAIL ? FAIL : walk(argSchema(node), input, context, true, false)\n\t\t}\n\t\tdefault:\n\t\t\treturn walkRun(node, value, context, full, strip)\n\t}\n}\n\nfunction walkRun(\n\tnode: KNode,\n\tvalue: unknown,\n\tcontext: WalkContext,\n\tfull: boolean,\n\tstrip: boolean,\n): unknown {\n\tconst plan = planOf(node)\n\t// SAFETY: runPlan always records the base below a run.\n\tlet output = walk(plan.base as KNode, value, context, full, strip)\n\tif (output === FAIL) return FAIL\n\tfor (const normaliser of plan.normalisers) {\n\t\toutput = callbackResult(normalise(normaliser, output), context, 'overwrite')\n\t\tif (output === FAIL) return FAIL\n\t}\n\tconst before = context.issues.length\n\tfor (const check of plan.checks) runCheck(check, output, context)\n\treturn context.issues.length === before ? output : FAIL\n}\n\nfunction normalise(record: KNode, value: unknown): unknown {\n\tswitch (record.op) {\n\t\tcase 'trim':\n\t\t\treturn stringOf(value).trim()\n\t\tcase 'lower':\n\t\t\treturn stringOf(value).toLowerCase()\n\t\tcase 'upper':\n\t\t\treturn stringOf(value).toUpperCase()\n\t\tdefault:\n\t\t\treturn callbackOf(record)(value)\n\t}\n}\n\nfunction runCheck(record: KNode, value: unknown, context: WalkContext): void {\n\tswitch (record.op) {\n\t\tcase 'min': {\n\t\t\tconst limit = numberArg(record)\n\t\t\tif (!(sizeOf(value) >= limit))\n\t\t\t\tcontext.add(\n\t\t\t\t\t'too_small',\n\t\t\t\t\tmessageOf(record, `Too small: expected ${unitOf(value, limit, '>=')}`),\n\t\t\t\t\tundefined,\n\t\t\t\t)\n\t\t\treturn\n\t\t}\n\t\tcase 'max': {\n\t\t\tconst limit = numberArg(record)\n\t\t\tif (!(sizeOf(value) <= limit))\n\t\t\t\tcontext.add(\n\t\t\t\t\t'too_big',\n\t\t\t\t\tmessageOf(record, `Too big: expected ${unitOf(value, limit, '<=')}`),\n\t\t\t\t\tundefined,\n\t\t\t\t)\n\t\t\treturn\n\t\t}\n\t\tcase 'length': {\n\t\t\tconst limit = numberArg(record)\n\t\t\tconst size = sizeOf(value)\n\t\t\tif (size === limit) return\n\t\t\tif (!(size > limit))\n\t\t\t\tcontext.add(\n\t\t\t\t\t'too_small',\n\t\t\t\t\tmessageOf(record, `Too small: expected ${unitOf(value, limit, '==')}`),\n\t\t\t\t\tundefined,\n\t\t\t\t)\n\t\t\telse\n\t\t\t\tcontext.add(\n\t\t\t\t\t'too_big',\n\t\t\t\t\tmessageOf(record, `Too big: expected ${unitOf(value, limit, '==')}`),\n\t\t\t\t\tundefined,\n\t\t\t\t)\n\t\t\treturn\n\t\t}\n\t\tcase 'regex': {\n\t\t\t// SAFETY: .regex stores its pattern as the record argument.\n\t\t\tconst pattern = record.arg as RegExp\n\t\t\tpattern.lastIndex = 0\n\t\t\tif (!pattern.test(stringOf(value)))\n\t\t\t\tcontext.add(\n\t\t\t\t\t'invalid_format',\n\t\t\t\t\tmessageOf(record, `Invalid string: must match ${pattern}`),\n\t\t\t\t\tundefined,\n\t\t\t\t)\n\t\t\treturn\n\t\t}\n\t\tcase 'int':\n\t\t\tif (!Number.isInteger(value))\n\t\t\t\tcontext.add('not_integer', messageOf(record, 'Expected an integer'), undefined)\n\t\t\treturn\n\t\tcase 'refine':\n\t\t\tif (settled(callbackOf(record)(value)) !== true) {\n\t\t\t\tconst options = optionsOf(record)\n\t\t\t\tcontext.add('custom', options?.message ?? 'Invalid input', options?.path)\n\t\t\t}\n\t\t\treturn\n\t\tcase 'check': {\n\t\t\tconst result = callbackOf(record)(value, new CheckContext(context))\n\t\t\tif (isThenable(settled(result)))\n\t\t\t\tcontext.add('custom', 'A check must be synchronous', undefined)\n\t\t\treturn\n\t\t}\n\t\tdefault:\n\t\t\tthrow new Error(`k: '${record.op}' is not a check`)\n\t}\n}\n\nfunction walkRoot(\n\troot: KNode,\n\tvalue: unknown,\n\tcontext: WalkContext,\n\tfull: boolean,\n\tstrip: boolean,\n): unknown {\n\tswitch (root.op) {\n\t\tcase 'array':\n\t\t\tif (full && !Array.isArray(value)) return invalidType(context, 'array', value)\n\t\t\t// SAFETY: checked above, or already validated natively at a function boundary.\n\t\t\treturn walkArray(root, value as unknown[], context, full)\n\t\tcase 'object':\n\t\t\tif (full && !isPlainObject(value)) return invalidType(context, 'object', value)\n\t\t\t// SAFETY: checked above, or already validated natively at a function boundary.\n\t\t\treturn walkObject(root, value as Record<string, unknown>, context, full, strip)\n\t\tcase 'record':\n\t\t\tif (full && !isPlainObject(value)) return invalidType(context, 'record', value)\n\t\t\t// SAFETY: checked above, or already validated natively at a function boundary.\n\t\t\treturn walkRecord(root, value as Record<string, unknown>, context, full)\n\t\tcase 'union':\n\t\t\treturn walkUnion(root, value, context)\n\t\tcase 'discriminatedUnion':\n\t\t\tif (full && !isPlainObject(value)) return invalidType(context, 'object', value)\n\t\t\t// SAFETY: checked above, or already validated natively at a function boundary.\n\t\t\treturn walkDiscriminated(root, value as Record<string, unknown>, context, full)\n\t\tcase 'int':\n\t\t\tif (full && typeof value !== 'number') return invalidType(context, 'number', value)\n\t\t\tif (Number.isInteger(value)) return value\n\t\t\tcontext.add('not_integer', 'Expected an integer', undefined)\n\t\t\treturn FAIL\n\t\tcase 'isoDate':\n\t\t\tif (full && typeof value !== 'string') return invalidType(context, 'string', value)\n\t\t\tif (isIsoDate(stringOf(value))) return value\n\t\t\tcontext.add('invalid_format', 'Invalid ISO date: expected YYYY-MM-DD', undefined)\n\t\t\treturn FAIL\n\t\tcase 'isoDateTime':\n\t\t\tif (full && typeof value !== 'string') return invalidType(context, 'string', value)\n\t\t\tif (isIsoDateTime(stringOf(value))) return value\n\t\t\tcontext.add('invalid_format', 'Invalid ISO date-time', undefined)\n\t\t\treturn FAIL\n\t\tcase 'timestamp':\n\t\t\treturn walkTimestamp(value, context, full)\n\t\tcase 'json':\n\t\t\tif (isJson(value)) return value\n\t\t\tcontext.add('invalid_type', 'Expected a JSON value', undefined)\n\t\t\treturn FAIL\n\t\tdefault:\n\t\t\treturn full ? walkLeaf(root, value, context) : value\n\t}\n}\n\nfunction walkTimestamp(value: unknown, context: WalkContext, full: boolean): unknown {\n\tif (full && typeof value !== 'number') return invalidType(context, 'number', value)\n\t// SAFETY: checked above, or already validated natively at a function boundary.\n\tconst time = value as number\n\tif (isTimestamp(time)) return value\n\tif (!Number.isFinite(time)) context.add('invalid_type', 'Expected a finite timestamp', undefined)\n\telse if (!Number.isInteger(time))\n\t\tcontext.add('not_integer', 'Expected integer milliseconds', undefined)\n\telse if (time < 0) context.add('too_small', 'Expected a timestamp >= 0', undefined)\n\telse\n\t\tcontext.add(\n\t\t\t'too_big',\n\t\t\t`Expected a timestamp <= ${maxTimestamp} (9999-12-31T23:59:59.999Z)`,\n\t\t\tundefined,\n\t\t)\n\treturn FAIL\n}\n\nfunction walkLeaf(root: KNode, value: unknown, context: WalkContext): unknown {\n\tswitch (root.op) {\n\t\tcase 'string':\n\t\tcase 'id':\n\t\t\treturn typeof value === 'string' ? value : invalidType(context, 'string', value)\n\t\tcase 'number':\n\t\t\treturn typeof value === 'number' ? value : invalidType(context, 'number', value)\n\t\tcase 'int64':\n\t\t\treturn typeof value === 'bigint' ? value : invalidType(context, 'bigint', value)\n\t\tcase 'boolean':\n\t\t\treturn typeof value === 'boolean' ? value : invalidType(context, 'boolean', value)\n\t\tcase 'null':\n\t\t\treturn value === null ? value : invalidType(context, 'null', value)\n\t\tcase 'bytes':\n\t\t\treturn value instanceof ArrayBuffer ? value : invalidType(context, 'ArrayBuffer', value)\n\t\tcase 'any':\n\t\t\treturn value === undefined ? invalidType(context, 'a value', value) : value\n\t\tcase 'literal': {\n\t\t\tconst expected = literalOf(root)\n\t\t\tif (value === expected) return value\n\t\t\tcontext.add(\n\t\t\t\t'invalid_value',\n\t\t\t\t`Invalid input: expected ${JSON.stringify(String(expected))}`,\n\t\t\t\tundefined,\n\t\t\t)\n\t\t\treturn FAIL\n\t\t}\n\t\tcase 'enum': {\n\t\t\tconst values = enumOf(root)\n\t\t\tif (typeof value === 'string' && values.includes(value)) return value\n\t\t\tcontext.add(\n\t\t\t\t'invalid_value',\n\t\t\t\t`Invalid option: expected one of ${values.map(quoted).join('|')}`,\n\t\t\t\tundefined,\n\t\t\t)\n\t\t\treturn FAIL\n\t\t}\n\t\tdefault:\n\t\t\tthrow new Error(`k: '${root.op}' is not a root operation`)\n\t}\n}\n\nfunction walkArray(root: KNode, value: unknown[], context: WalkContext, full: boolean): unknown {\n\tconst element = argSchema(root)\n\tlet out: unknown[] | undefined\n\tlet failed = false\n\tfor (let index = 0; index < value.length; index++) {\n\t\tconst input = value[index]\n\t\tcontext.path.push(index)\n\t\tconst output = walk(element, input, context, full, false)\n\t\tcontext.path.pop()\n\t\tif (output === FAIL) failed = true\n\t\telse {\n\t\t\tif (out === undefined && output !== input) out = value.slice(0, index)\n\t\t\tout?.push(output)\n\t\t}\n\t}\n\tif (failed) return FAIL\n\treturn out ?? value\n}\n\nfunction walkObject(\n\troot: KNode,\n\tvalue: Record<string, unknown>,\n\tcontext: WalkContext,\n\tfull: boolean,\n\tstrip: boolean,\n): unknown {\n\tconst fields = fieldsOf(root)\n\tlet out: Record<string, unknown> | undefined\n\tlet failed = false\n\tfor (const key in fields) {\n\t\tconst input = Object.hasOwn(value, key) ? value[key] : undefined\n\t\tcontext.path.push(key)\n\t\tconst output = walk(asSchema(fields[key]), input, context, full, false)\n\t\tcontext.path.pop()\n\t\tif (output === FAIL) {\n\t\t\tfailed = true\n\t\t\tcontinue\n\t\t}\n\t\tif (out === undefined && output !== input) {\n\t\t\tout = {}\n\t\t\tcopyKnown(out, value, fields, key)\n\t\t}\n\t\tif (out !== undefined && output !== undefined) setOwn(out, key, output)\n\t}\n\tlet stripped = false\n\tif (full) {\n\t\tfor (const key of Object.keys(value)) {\n\t\t\tif (Object.hasOwn(fields, key)) continue\n\t\t\tif (strip) stripped = true\n\t\t\telse {\n\t\t\t\tfailed = true\n\t\t\t\tcontext.add('unrecognized_key', `Unrecognized key: ${JSON.stringify(key)}`, [key])\n\t\t\t}\n\t\t}\n\t}\n\tif (failed) return FAIL\n\tif (stripped && out === undefined) {\n\t\tout = {}\n\t\tcopyKnown(out, value, fields, null)\n\t}\n\treturn out ?? value\n}\n\n/** Copy into `out` the known fields of `value` before `stop` in declaration order (all of them for `null`). */\nfunction copyKnown(\n\tout: Record<string, unknown>,\n\tvalue: Record<string, unknown>,\n\tfields: KFields,\n\tstop: string | null,\n): void {\n\tfor (const key in fields) {\n\t\tif (key === stop) break\n\t\tif (Object.hasOwn(value, key) && value[key] !== undefined) setOwn(out, key, value[key])\n\t}\n}\n\nfunction walkRecord(\n\troot: KNode,\n\tvalue: Record<string, unknown>,\n\tcontext: WalkContext,\n\tfull: boolean,\n): unknown {\n\tconst [keySchema, valueSchema] = recordOf(root)\n\tconst keys = Object.keys(value)\n\tlet out: Record<string, unknown> | undefined\n\tlet failed = false\n\tfor (let index = 0; index < keys.length; index++) {\n\t\tconst key = keys[index]\n\t\tconst input = value[key]\n\t\tcontext.path.push(key)\n\t\tlet outputKey = walk(keySchema, key, context, full, false)\n\t\tif (outputKey !== FAIL && (full || outputKey !== key) && !isRecordKey(stringOf(outputKey))) {\n\t\t\tcontext.add('invalid_format', recordKeyMessage, undefined)\n\t\t\toutputKey = FAIL\n\t\t}\n\t\tconst output = walk(valueSchema, input, context, full, false)\n\t\tcontext.path.pop()\n\t\tif (outputKey === FAIL || output === FAIL) {\n\t\t\tfailed = true\n\t\t\tcontinue\n\t\t}\n\t\tif (out === undefined && (outputKey !== key || output !== input)) {\n\t\t\tout = {}\n\t\t\tfor (let before = 0; before < index; before++) setOwn(out, keys[before], value[keys[before]])\n\t\t}\n\t\tif (out !== undefined) setOwn(out, stringOf(outputKey), output)\n\t}\n\tif (failed) return FAIL\n\treturn out ?? value\n}\n\nfunction walkUnion(root: KNode, value: unknown, context: WalkContext): unknown {\n\tconst issues = context.issues\n\tfor (const member of membersOf(root)) {\n\t\tcontext.issues = []\n\t\tconst output = walk(member, value, context, true, false)\n\t\tif (output !== FAIL) {\n\t\t\tcontext.issues = issues\n\t\t\treturn output\n\t\t}\n\t}\n\tcontext.issues = issues\n\tcontext.add('invalid_union', 'Invalid input: no union member matched', undefined)\n\treturn FAIL\n}\n\nfunction walkDiscriminated(\n\troot: KNode,\n\tvalue: Record<string, unknown>,\n\tcontext: WalkContext,\n\tfull: boolean,\n): unknown {\n\tconst plan = planOf(root)\n\t// SAFETY: k.discriminatedUnion stores its key with the options as the root argument.\n\tconst { key } = root.arg as KDiscriminated\n\tconst discriminator = value[key]\n\t// SAFETY: rootPlan records a dispatch table for every discriminated union root.\n\tconst option = (plan.dispatch as ReadonlyMap<unknown, KNode>).get(discriminator)\n\tif (option === undefined) {\n\t\tcontext.add('invalid_union', `Invalid discriminator value at ${JSON.stringify(key)}`, [key])\n\t\treturn FAIL\n\t}\n\treturn walk(option, value, context, full, false)\n}\n\n/** A transform or overwrite is synchronous; a promise or a conversion failure becomes an issue. */\nfunction callbackResult(output: unknown, context: WalkContext, kind: string): unknown {\n\tif (output instanceof KConversionFailure) {\n\t\tcontext.add('invalid_value', output.message, undefined)\n\t\treturn FAIL\n\t}\n\tif (!isThenable(settled(output))) return output\n\tcontext.add(\n\t\t'custom',\n\t\t`Async ${kind} is not supported: ${kind} callbacks must be synchronous`,\n\t\tundefined,\n\t)\n\treturn FAIL\n}\n\n/**\n * A check is synchronous. One that returns a promise (an untyped caller's async callback) fails, and\n * its rejection is contained so no detail escapes as an unhandled rejection.\n */\nfunction settled(result: unknown): unknown {\n\tif (isThenable(result)) result.then(undefined, () => {})\n\treturn result\n}\n\nfunction isThenable(value: unknown): value is PromiseLike<unknown> {\n\treturn (\n\t\tvalue !== null &&\n\t\t(typeof value === 'object' || typeof value === 'function') &&\n\t\t'then' in value &&\n\t\ttypeof value.then === 'function'\n\t)\n}\n\nconst recordKeyMessage =\n\t\"Invalid record key: Convex record keys are non-empty ASCII, at most 1024 characters, and do not start with '$' or '_'\"\n\n/** The Convex record key rule (`v.record`), applied to the key after normalisation. */\nfunction isRecordKey(key: string): boolean {\n\tif (key.length === 0 || key.length > 1024 || key[0] === '$' || key[0] === '_') return false\n\tfor (let index = 0; index < key.length; index++) {\n\t\tconst code = key.charCodeAt(index)\n\t\tif (code < 32 || code >= 127) return false\n\t}\n\treturn true\n}\n\n/** Write an own data property: a key taken from input (`__proto__`) never reaches a setter. */\nfunction setOwn(target: Record<string, unknown>, key: string, value: unknown): void {\n\tObject.defineProperty(target, key, {\n\t\tvalue,\n\t\tenumerable: true,\n\t\twritable: true,\n\t\tconfigurable: true,\n\t})\n}\n\nfunction invalidType(context: WalkContext, expected: string, value: unknown): typeof FAIL {\n\tcontext.add(\n\t\t'invalid_type',\n\t\t`Invalid input: expected ${expected}, received ${receivedOf(value)}`,\n\t\tundefined,\n\t)\n\treturn FAIL\n}\n\nfunction receivedOf(value: unknown): string {\n\tif (value === null) return 'null'\n\tif (Array.isArray(value)) return 'array'\n\tif (value instanceof ArrayBuffer) return 'ArrayBuffer'\n\treturn typeof value\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n\tif (value === null || typeof value !== 'object') return false\n\tconst prototype = Object.getPrototypeOf(value)\n\treturn prototype === Object.prototype || prototype === null\n}\n\nfunction isJson(value: unknown): boolean {\n\tif (value === null || typeof value === 'string' || typeof value === 'boolean') return true\n\tif (typeof value === 'number') return Number.isFinite(value)\n\tif (Array.isArray(value)) return value.every(isJson)\n\tif (!isPlainObject(value)) return false\n\tfor (const key in value) if (!isJson(value[key])) return false\n\treturn true\n}\n\nfunction sizeOf(value: unknown): number {\n\tif (typeof value === 'string' || Array.isArray(value)) return value.length\n\treturn Number(value)\n}\n\nfunction unitOf(value: unknown, limit: number, relation: string): string {\n\tif (typeof value === 'string') return `string to have ${relation}${limit} characters`\n\tif (Array.isArray(value)) return `array to have ${relation}${limit} items`\n\treturn `number to be ${relation}${limit}`\n}\n\nfunction messageOf(record: KNode, fallback: string): string {\n\tconst message = record.message\n\tif (typeof message === 'string') return message\n\treturn message?.message ?? fallback\n}\n\nfunction optionsOf(record: KNode): KRefineOptions | undefined {\n\tconst message = record.message\n\treturn typeof message === 'string' ? { message } : message\n}\n\nfunction quoted(value: string): string {\n\treturn JSON.stringify(value)\n}\n\nfunction isRunOp(record: KNode): boolean {\n\tswitch (record.op) {\n\t\tcase 'min':\n\t\tcase 'max':\n\t\tcase 'length':\n\t\tcase 'regex':\n\t\tcase 'int':\n\t\tcase 'refine':\n\t\tcase 'check':\n\t\tcase 'trim':\n\t\tcase 'lower':\n\t\tcase 'upper':\n\t\tcase 'overwrite':\n\t\t\treturn true\n\t\tdefault:\n\t\t\treturn false\n\t}\n}\n\nfunction isNormaliser(record: KNode): boolean {\n\treturn (\n\t\trecord.op === 'trim' ||\n\t\trecord.op === 'lower' ||\n\t\trecord.op === 'upper' ||\n\t\trecord.op === 'overwrite'\n\t)\n}\n\n/** Whether a default sits inside an optional wrapper, so `undefined` still receives it (as in Zod 4). */\nfunction defaultsBelow(node: KNode): boolean {\n\tfor (let current: KNode | null = node; current !== null; current = current.prev) {\n\t\tif (current.op === 'default') return true\n\t\tif (current.op === 'transform' || current.op === 'pipe') return false\n\t}\n\treturn false\n}\n\nfunction rootOf(node: KNode): KNode {\n\tlet root = node\n\twhile (root.prev !== null) root = root.prev\n\treturn root\n}\n\nfunction asSchema(value: unknown): KNode {\n\t// SAFETY: every schema reachable from a k root was created by a k factory.\n\treturn value as KNode\n}\n\nfunction argSchema(record: KNode): KNode {\n\treturn asSchema(record.arg)\n}\n\nfunction fieldsOf(root: KNode): KFields {\n\t// SAFETY: k.object stores its field map as the root argument.\n\treturn root.arg as KFields\n}\n\nfunction recordOf(root: KNode): readonly KNode[] {\n\t// SAFETY: k.record stores its key and value schemas as the root argument.\n\treturn root.arg as readonly KType[]\n}\n\nfunction literalOf(root: KNode): KLiteralValue {\n\t// SAFETY: k.literal stores its literal value as the root argument.\n\treturn root.arg as KLiteralValue\n}\n\nfunction enumOf(root: KNode): readonly string[] {\n\t// SAFETY: k.enum stores its value list as the root argument.\n\treturn root.arg as readonly string[]\n}\n\nfunction numberArg(record: KNode): number {\n\t// SAFETY: min, max and length store their numeric limit as the record argument.\n\treturn record.arg as number\n}\n\nfunction stringOf(value: unknown): string {\n\t// SAFETY: string normalisers and record keys run only after the string structure check passed.\n\treturn value as string\n}\n\nfunction callbackOf(record: KNode): (value: unknown, context?: CheckContext) => unknown {\n\t// SAFETY: refine, check, overwrite and transform store their callback as the record argument.\n\treturn record.arg as (value: unknown, context?: CheckContext) => unknown\n}\n"],"mappings":"A,kNA4BA,IAAaA,EAAb,KAAmB,CAClB,SACA,UACA,KACA,YACA,OACA,SAEA,YACC,EACA,EACA,EACA,EACA,EACA,EACC,CACD,KAAK,SAAWC,EAChB,KAAK,UAAYC,EACjB,KAAK,KAAOC,EACZ,KAAK,YAAcC,EACnB,KAAK,OAASC,EACd,KAAK,SAAWC,CACjB,CACD,EAEA,SAAgBC,EAAY,EAAe,EAAyB,CACnE,IAAMC,EAAU,IAAIC,EACdC,EAASC,EAAKC,EAAQC,EAAOL,EAAS,GAAM,EAAK,EACvD,GAAIA,EAAQ,OAAO,OAAS,EAAG,MAAM,IAAIM,EAAiBN,EAAQ,MAAM,EACxE,OAAOE,CACR,CAEA,SAAgBK,EAAgB,EAAe,EAA2C,CACzF,IAAMP,EAAU,IAAIC,EACdC,EAASC,EAAKC,EAAQC,EAAOL,EAAS,GAAM,EAAK,EAEvD,OADIA,EAAQ,OAAO,OAAS,EAAU,CAAE,QAAS,GAAO,OAAQA,EAAQ,MAAO,EACxE,CAAE,QAAS,GAAM,KAAME,CAAO,CACtC,CAMA,SAAgBM,EAAY,EAAe,EAAyB,CACnE,GAAI,CAACC,EAAOL,CAAM,CAAC,CAAC,SAAU,OAAOM,EACrC,IAAMV,EAAU,IAAIC,EACdC,EAASC,EAAKC,EAAQM,EAAOV,EAAS,GAAO,EAAK,EACxD,GAAIA,EAAQ,OAAO,OAAS,EAAG,MAAM,IAAIM,EAAiBN,EAAQ,MAAM,EACxE,OAAOE,CACR,CAEA,SAAgBS,EAAqB,EAAwB,CAC5D,OAAOF,EAAOL,CAAM,CAAC,CAAC,QACvB,CAGA,SAAgBQ,EAAkB,EAAwB,CACzD,OAAOH,EAAOL,CAAM,CAAC,CAAC,SACvB,CAEA,MAAMS,EAAsB,OAAO,QAAQ,EACrCC,EAA8B,CAAC,EAC/BC,EAAY,IAAIvB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AASC,GAAa,EAAwB,CAC7C,OACCD,EAAO,KAAO,QACdA,EAAO,KAAO,SACdA,EAAO,KAAO,SACdA,EAAO,KAAO,WAEhB,CAGA,SAAS2B,GAAc,EAAsB,CAC5C,IAAK,IAAI+D,EAAwBhG,EAAMgG,IAAY,KAAM,EAAUA,EAAQ,KAAM,CAChF,GAAIA,EAAQ,KAAO,UAAW,MAAO,GACrC,GAAIA,EAAQ,KAAO,aAAeA,EAAQ,KAAO,OAAQ,MAAO,EACjE,CACA,MAAO,EACR,CAEA,SAASvE,EAAO,EAAoB,CACnC,IAAIjB,EAAOR,EACX,KAAOQ,EAAK,OAAS,MAAM,EAAOA,EAAK,KACvC,OAAOA,CACR,CAEA,SAASM,EAAS,EAAuB,CAExC,OAAO3B,CACR,CAEA,SAASsB,EAAU,EAAsB,CACxC,OAAOK,EAASR,EAAO,GAAG,CAC3B,CAEA,SAASK,EAAS,EAAsB,CAEvC,OAAOH,EAAK,GACb,CAEA,SAASQ,EAAS,EAA+B,CAEhD,OAAOR,EAAK,GACb,CAEA,SAASoB,EAAU,EAA4B,CAE9C,OAAOpB,EAAK,GACb,CAEA,SAASqB,EAAO,EAAgC,CAE/C,OAAOrB,EAAK,GACb,CAEA,SAASoC,EAAU,EAAuB,CAEzC,OAAOtC,EAAO,GACf,CAEA,SAASoC,EAAS,EAAwB,CAEzC,OAAOvD,CACR,CAEA,SAASgD,EAAW,EAAoE,CAEvF,OAAO7B,EAAO,GACf,C"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { KIssueInput, KSafeParseResult } from "./issues.mjs";
|
|
2
|
+
import { KPlan } from "./parse.mjs";
|
|
3
|
+
import { KArg, KMessage, KNode, KOp, KOutputRequired, KRefineOptions, KRequiredValidator, KType, OutputNativeOf } from "./types.mjs";
|
|
4
|
+
import { GenericValidator, VAny, VNull, VUnion } from "convex/values";
|
|
5
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
|
+
/**
|
|
7
|
+
* An immutable chain record. A root has `prev === null` and a kind op; every chained call allocates one
|
|
8
|
+
* record pointing at its predecessor. Nothing is compiled until `validator`, `outputValidator` or a
|
|
9
|
+
* parse first needs it; each product is memoised in its own pre-declared slot.
|
|
10
|
+
*
|
|
11
|
+
* Type arguments: `Out` the parsed output, `R` the required native validator, `D` whether a default or
|
|
12
|
+
* transform sits inside, `N` the input-side native validator (`R` unless the chain is optional or
|
|
13
|
+
* defaulted), `T` whether a transform or pipe sits inside.
|
|
14
|
+
*/
|
|
15
|
+
export declare abstract class KSchema<Out = any, R extends KRequiredValidator = KRequiredValidator, D extends boolean = false, N extends GenericValidator = R, T extends boolean = false> implements KType {
|
|
16
|
+
readonly _output: Out;
|
|
17
|
+
readonly _input: N['type'];
|
|
18
|
+
readonly _req: R;
|
|
19
|
+
readonly _d: D;
|
|
20
|
+
readonly _t: T;
|
|
21
|
+
/** Required output-side native validator; read only when `D` is true. */
|
|
22
|
+
readonly _or: KRequiredValidator;
|
|
23
|
+
/** Output-side native validator; read only when `D` is true. */
|
|
24
|
+
readonly _oo: GenericValidator;
|
|
25
|
+
readonly prev: KNode | null;
|
|
26
|
+
readonly op: KOp;
|
|
27
|
+
readonly arg: KArg;
|
|
28
|
+
readonly message: KMessage;
|
|
29
|
+
/** Memo slot for the input-side native validator. */
|
|
30
|
+
native: GenericValidator | undefined;
|
|
31
|
+
/** Memo slot for the output-side native validator. */
|
|
32
|
+
outputNative: GenericValidator | undefined;
|
|
33
|
+
/** Memo slot for the parse plan. */
|
|
34
|
+
plan: KPlan | undefined;
|
|
35
|
+
constructor(prev: KNode | null, op: KOp, arg: KArg, message: KMessage);
|
|
36
|
+
get validator(): N;
|
|
37
|
+
get outputValidator(): D extends true ? this['_oo'] : N;
|
|
38
|
+
optional(): KOptional<this>;
|
|
39
|
+
nullable(): KNullable<this>;
|
|
40
|
+
default(value: Exclude<Out, undefined>): KDefault<this>;
|
|
41
|
+
/** A check on the parsed value; `options.path` attaches the issue below this value (object refinements). */
|
|
42
|
+
refine(check: (value: Out) => boolean, message?: string | KRefineOptions): this;
|
|
43
|
+
/** A check that may add several issues through `context.addIssue`. */
|
|
44
|
+
check(check: (value: Out, context: KCheckContext) => void): this;
|
|
45
|
+
/** A type-preserving normaliser; allowed everywhere, including table fields. */
|
|
46
|
+
overwrite(normalise: (value: Out) => Out): this;
|
|
47
|
+
/** A type-changing step. Produces a distinct kind that table fields and return shapes reject. */
|
|
48
|
+
transform<O>(map: (value: Out) => O): KTransform<this, O>;
|
|
49
|
+
/** Parse this schema's output with `target`. Produces a distinct kind, like `transform`. */
|
|
50
|
+
pipe<P extends KType>(target: P): KPipe<this, P>;
|
|
51
|
+
parse(input: unknown): Out;
|
|
52
|
+
safeParse(input: unknown): KSafeParseResult<Out>;
|
|
53
|
+
/** A description for JSON Schema and tooling; it changes neither the validators nor parsing. */
|
|
54
|
+
describe(text: string): this;
|
|
55
|
+
/** The nearest description declared on this chain. */
|
|
56
|
+
get description(): string | undefined;
|
|
57
|
+
/** Standard Schema v1, so contracts and form libraries consume `k` schemas directly. */
|
|
58
|
+
get '~standard'(): StandardSchemaV1.Props<N['type'], Out>;
|
|
59
|
+
protected link(op: KOp, arg: KArg, message: KMessage): this;
|
|
60
|
+
protected wrapped<W>(op: KOp): W;
|
|
61
|
+
}
|
|
62
|
+
/** The context handed to `.check()`; `addIssue` may be called any number of times. */
|
|
63
|
+
export interface KCheckContext {
|
|
64
|
+
addIssue(issue: KIssueInput): void;
|
|
65
|
+
}
|
|
66
|
+
declare global {
|
|
67
|
+
/**
|
|
68
|
+
* Methods that optional cvx-kit entries add to every `k` schema; `cvx-kit/zod` adds `toZod()`. Empty
|
|
69
|
+
* in core, so core declarations never name an optional peer's types.
|
|
70
|
+
*/
|
|
71
|
+
interface CvxKitSchemaMethods {}
|
|
72
|
+
}
|
|
73
|
+
/** Adds the optional entries' methods to the class type; the entries install them at runtime. */
|
|
74
|
+
export interface KSchema<Out = any, R extends KRequiredValidator = KRequiredValidator, D extends boolean = false, N extends GenericValidator = R, T extends boolean = false> extends CvxKitSchemaMethods {}
|
|
75
|
+
export declare class KOptional<I extends KType> extends KSchema<I['_output'] | undefined, I['_req'], I['_d'], ReturnType<I['_req']['optional']>, I['_t']> {
|
|
76
|
+
readonly _or: KOutputRequired<I>;
|
|
77
|
+
readonly _oo: ReturnType<KOutputRequired<I>['optional']>;
|
|
78
|
+
unwrap(): I;
|
|
79
|
+
}
|
|
80
|
+
export declare class KDefault<I extends KType> extends KSchema<Exclude<I['_output'], undefined>, I['_req'], true, ReturnType<I['_req']['optional']>, I['_t']> {
|
|
81
|
+
readonly _or: KOutputRequired<I>;
|
|
82
|
+
readonly _oo: KOutputRequired<I>;
|
|
83
|
+
unwrap(): I;
|
|
84
|
+
}
|
|
85
|
+
export declare class KNullable<I extends KType> extends KSchema<I['_output'] | null, NullableOf<I['_req']>, I['_d'], I['validator']['isOptional'] extends 'optional' ? ReturnType<NullableOf<I['_req']>['optional']> : NullableOf<I['_req']>, I['_t']> {
|
|
86
|
+
readonly _or: NullableOf<KOutputRequired<I>>;
|
|
87
|
+
readonly _oo: OutputNativeOf<I>['isOptional'] extends 'optional' ? ReturnType<NullableOf<KOutputRequired<I>>['optional']> : NullableOf<KOutputRequired<I>>;
|
|
88
|
+
unwrap(): I;
|
|
89
|
+
}
|
|
90
|
+
export declare class KTransform<I extends KType, O> extends KSchema<O, I['_req'], true, I['validator'], true> {
|
|
91
|
+
readonly _or: VAny<O>;
|
|
92
|
+
readonly _oo: VAny<O>;
|
|
93
|
+
}
|
|
94
|
+
export declare class KPipe<I extends KType, P extends KType> extends KSchema<P['_output'], I['_req'], true, I['validator'], true> {
|
|
95
|
+
readonly _or: KOutputRequired<P>;
|
|
96
|
+
readonly _oo: OutputNativeOf<P>;
|
|
97
|
+
}
|
|
98
|
+
type NullableOf<V extends KRequiredValidator> = VUnion<V['type'] | null, [V, VNull<null>]>;
|
|
99
|
+
export {};
|
|
100
|
+
//# sourceMappingURL=schema.d.mts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{compileNative as e,compileOutput as t}from"./compile.mjs";import{parseSchema as n,safeParseSchema as r}from"./parse.mjs";import{standardProps as i}from"./standard.mjs";var a=class{prev;op;arg;message;native;outputNative;plan;constructor(e,t,n,r){this.prev=e,this.op=t,this.arg=n,this.message=r,this.native=void 0,this.outputNative=void 0,this.plan=void 0}get validator(){return this.native??=e(this)}get outputValidator(){return this.outputNative??=t(this)}optional(){return new o(this,`optional`,void 0,void 0)}nullable(){return new c(this,`nullable`,void 0,void 0)}default(e){return new s(this,`default`,e,void 0)}refine(e,t){return this.link(`refine`,e,d(t))}check(e){return this.link(`check`,e,void 0)}overwrite(e){return this.link(`overwrite`,e,void 0)}transform(e){return new l(this,`transform`,e,void 0)}pipe(e){return new u(this,`pipe`,e,void 0)}parse(e){return n(this,e)}safeParse(e){return r(this,e)}describe(e){return this.link(`describe`,e,void 0)}get description(){return p(this)}get"~standard"(){return i(this)}link(e,t,n){let r=this.constructor,i=new r(this,e,t,n);return this.op!==`any`&&(i.native=this.native),i}wrapped(e){return m(this,e)}};Object.defineProperty(a.prototype,"toZod",{value:f,writable:!0,configurable:!0});var o=class extends a{unwrap(){return this.wrapped(`optional`)}},s=class extends a{unwrap(){return this.wrapped(`default`)}},c=class extends a{unwrap(){return this.wrapped(`nullable`)}},l=class extends a{},u=class extends a{};function d(e){return e===void 0||typeof e==`string`?e:(e.path!==void 0&&Object.freeze(e.path),Object.freeze(e))}function f(){throw Error("k: .toZod() needs the Zod interop entry; add `import 'cvx-kit/zod'` first")}function p(e){for(let t=e;t!==null;t=t.prev)if(t.op===`describe`)return t.arg}function m(e,t){let n=e;for(;n.op!==t&&(t!==`optional`||n.op!==`partial`);)n=h(n);return h(n)}function h(e){if(e.prev===null)throw Error(`k: no '${e.op}' wrapper to unwrap`);return e.prev}export{s as KDefault,c as KNullable,o as KOptional,u as KPipe,a as KSchema,l as KTransform};
|
|
2
|
+
//# sourceMappingURL=schema.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.mjs","names":["KSchema","prev","op","arg","message","compileNative","compileOutput","KOptional","KNullable","KDefault","value","check","frozenMessage","normalise","KTransform","map","KPipe","target","parseSchema","input","safeParseSchema","text","descriptionOf","standardProps","Next","next","wrappedBy","missingZodEntry","current","node","prevOf"],"sources":["../../src/k/schema.ts"],"sourcesContent":["import type { StandardSchemaV1 } from '@standard-schema/spec'\nimport type { GenericValidator, VAny, VNull, VUnion } from 'convex/values'\nimport { compileNative, compileOutput } from './compile'\nimport type { KIssueInput, KSafeParseResult } from './issues'\nimport { parseSchema, safeParseSchema, type KPlan } from './parse'\nimport { standardProps } from './standard'\nimport type {\n\tKArg,\n\tKMessage,\n\tKOp,\n\tKOutputRequired,\n\tKRefineOptions,\n\tKRequiredValidator,\n\tKNode,\n\tKType,\n\tOutputNativeOf,\n} from './types'\n\n/**\n * An immutable chain record. A root has `prev === null` and a kind op; every chained call allocates one\n * record pointing at its predecessor. Nothing is compiled until `validator`, `outputValidator` or a\n * parse first needs it; each product is memoised in its own pre-declared slot.\n *\n * Type arguments: `Out` the parsed output, `R` the required native validator, `D` whether a default or\n * transform sits inside, `N` the input-side native validator (`R` unless the chain is optional or\n * defaulted), `T` whether a transform or pipe sits inside.\n */\n// oxlint-disable-next-line typescript/no-unsafe-declaration-merging -- the merged interface only adds methods that cvx-kit/zod installs on the prototype.\nexport abstract class KSchema<\n\tOut = any,\n\tR extends KRequiredValidator = KRequiredValidator,\n\tD extends boolean = false,\n\tN extends GenericValidator = R,\n\tT extends boolean = false,\n> implements KType {\n\tdeclare readonly _output: Out\n\tdeclare readonly _input: N['type']\n\tdeclare readonly _req: R\n\tdeclare readonly _d: D\n\tdeclare readonly _t: T\n\t/** Required output-side native validator; read only when `D` is true. */\n\tdeclare readonly _or: KRequiredValidator\n\t/** Output-side native validator; read only when `D` is true. */\n\tdeclare readonly _oo: GenericValidator\n\treadonly prev: KNode | null\n\treadonly op: KOp\n\treadonly arg: KArg\n\treadonly message: KMessage\n\t/** Memo slot for the input-side native validator. */\n\tnative: GenericValidator | undefined\n\t/** Memo slot for the output-side native validator. */\n\toutputNative: GenericValidator | undefined\n\t/** Memo slot for the parse plan. */\n\tplan: KPlan | undefined\n\n\tconstructor(prev: KNode | null, op: KOp, arg: KArg, message: KMessage) {\n\t\tthis.prev = prev\n\t\tthis.op = op\n\t\tthis.arg = arg\n\t\tthis.message = message\n\t\tthis.native = undefined\n\t\tthis.outputNative = undefined\n\t\tthis.plan = undefined\n\t}\n\n\tget validator(): N {\n\t\t// SAFETY: compileNative builds the validator that this record's class declares as N.\n\t\treturn (this.native ??= compileNative(this)) as N\n\t}\n\n\tget outputValidator(): D extends true ? this['_oo'] : N {\n\t\t// SAFETY: compileOutput builds the output-side validator this record's class declares.\n\t\treturn (this.outputNative ??= compileOutput(this)) as D extends true ? this['_oo'] : N\n\t}\n\n\toptional(): KOptional<this> {\n\t\treturn new KOptional(this, 'optional', undefined, undefined)\n\t}\n\n\tnullable(): KNullable<this> {\n\t\treturn new KNullable(this, 'nullable', undefined, undefined)\n\t}\n\n\tdefault(value: Exclude<Out, undefined>): KDefault<this> {\n\t\t// SAFETY: a default is a Convex value of this schema's output type.\n\t\treturn new KDefault(this, 'default', value as KArg, undefined)\n\t}\n\n\t/** A check on the parsed value; `options.path` attaches the issue below this value (object refinements). */\n\trefine(check: (value: Out) => boolean, message?: string | KRefineOptions): this {\n\t\treturn this.link('refine', check, frozenMessage(message))\n\t}\n\n\t/** A check that may add several issues through `context.addIssue`. */\n\tcheck(check: (value: Out, context: KCheckContext) => void): this {\n\t\treturn this.link('check', check, undefined)\n\t}\n\n\t/** A type-preserving normaliser; allowed everywhere, including table fields. */\n\toverwrite(normalise: (value: Out) => Out): this {\n\t\treturn this.link('overwrite', normalise, undefined)\n\t}\n\n\t/** A type-changing step. Produces a distinct kind that table fields and return shapes reject. */\n\ttransform<O>(map: (value: Out) => O): KTransform<this, O> {\n\t\treturn new KTransform(this, 'transform', map, undefined)\n\t}\n\n\t/** Parse this schema's output with `target`. Produces a distinct kind, like `transform`. */\n\tpipe<P extends KType>(target: P): KPipe<this, P> {\n\t\treturn new KPipe(this, 'pipe', target, undefined)\n\t}\n\n\t// oxlint-disable-next-line anti-slop/no-unknown-parameters -- parse is the decoding boundary for undecoded input.\n\tparse(input: unknown): Out {\n\t\t// SAFETY: a successful walk of this schema produces its declared output.\n\t\treturn parseSchema(this, input) as Out\n\t}\n\n\t// oxlint-disable-next-line anti-slop/no-unknown-parameters -- safeParse is the decoding boundary for undecoded input.\n\tsafeParse(input: unknown): KSafeParseResult<Out> {\n\t\t// SAFETY: a successful walk of this schema produces its declared output.\n\t\treturn safeParseSchema(this, input) as KSafeParseResult<Out>\n\t}\n\n\t/** A description for JSON Schema and tooling; it changes neither the validators nor parsing. */\n\tdescribe(text: string): this {\n\t\treturn this.link('describe', text, undefined)\n\t}\n\n\t/** The nearest description declared on this chain. */\n\tget description(): string | undefined {\n\t\treturn descriptionOf(this)\n\t}\n\n\t/** Standard Schema v1, so contracts and form libraries consume `k` schemas directly. */\n\tget '~standard'(): StandardSchemaV1.Props<N['type'], Out> {\n\t\treturn standardProps(this)\n\t}\n\n\tprotected link(op: KOp, arg: KArg, message: KMessage): this {\n\t\t// SAFETY: every subclass inherits this constructor unchanged, so the record keeps its predecessor's class.\n\t\tconst Next = this.constructor as new (\n\t\t\tprev: KNode,\n\t\t\top: KOp,\n\t\t\targ: KArg,\n\t\t\tmessage: KMessage,\n\t\t) => this\n\t\tconst next = new Next(this, op, arg, message)\n\t\t// link only records checks, normalisers and descriptions: its native shape is unchanged.\n\t\t// Private filter boundaries use an any root with a lazy native accessor. Do not force it here.\n\t\tif (this.op !== 'any') next.native = this.native\n\t\treturn next\n\t}\n\n\tprotected wrapped<W>(op: KOp): W {\n\t\t// SAFETY: the record below a wrapper record is the schema the wrapper's class names as W.\n\t\treturn wrappedBy(this, op) as W\n\t}\n}\n\n/** The context handed to `.check()`; `addIssue` may be called any number of times. */\nexport interface KCheckContext {\n\taddIssue(issue: KIssueInput): void\n}\n\ndeclare global {\n\t/**\n\t * Methods that optional cvx-kit entries add to every `k` schema; `cvx-kit/zod` adds `toZod()`. Empty\n\t * in core, so core declarations never name an optional peer's types.\n\t */\n\tinterface CvxKitSchemaMethods {}\n}\n\n/* oxlint-disable no-unused-vars -- A merged declaration must repeat the class's type parameters. */\n/** Adds the optional entries' methods to the class type; the entries install them at runtime. */\nexport interface KSchema<\n\tOut = any,\n\tR extends KRequiredValidator = KRequiredValidator,\n\tD extends boolean = false,\n\tN extends GenericValidator = R,\n\tT extends boolean = false,\n> extends CvxKitSchemaMethods {}\n/* oxlint-enable no-unused-vars */\n\n/**\n * `.toZod()` exists only once `cvx-kit/zod` is imported, which also adds its type. Until then this stub\n * names the entry; core declarations stay free of Zod types.\n */\nObject.defineProperty(KSchema.prototype, 'toZod', {\n\tvalue: missingZodEntry,\n\twritable: true,\n\tconfigurable: true,\n})\n\nexport class KOptional<I extends KType> extends KSchema<\n\tI['_output'] | undefined,\n\tI['_req'],\n\tI['_d'],\n\tReturnType<I['_req']['optional']>,\n\tI['_t']\n> {\n\tdeclare readonly _or: KOutputRequired<I>\n\tdeclare readonly _oo: ReturnType<KOutputRequired<I>['optional']>\n\n\tunwrap(): I {\n\t\treturn this.wrapped<I>('optional')\n\t}\n}\n\nexport class KDefault<I extends KType> extends KSchema<\n\tExclude<I['_output'], undefined>,\n\tI['_req'],\n\ttrue,\n\tReturnType<I['_req']['optional']>,\n\tI['_t']\n> {\n\tdeclare readonly _or: KOutputRequired<I>\n\tdeclare readonly _oo: KOutputRequired<I>\n\n\tunwrap(): I {\n\t\treturn this.wrapped<I>('default')\n\t}\n}\n\nexport class KNullable<I extends KType> extends KSchema<\n\tI['_output'] | null,\n\tNullableOf<I['_req']>,\n\tI['_d'],\n\tI['validator']['isOptional'] extends 'optional'\n\t\t? ReturnType<NullableOf<I['_req']>['optional']>\n\t\t: NullableOf<I['_req']>,\n\tI['_t']\n> {\n\tdeclare readonly _or: NullableOf<KOutputRequired<I>>\n\tdeclare readonly _oo: OutputNativeOf<I>['isOptional'] extends 'optional'\n\t\t? ReturnType<NullableOf<KOutputRequired<I>>['optional']>\n\t\t: NullableOf<KOutputRequired<I>>\n\n\tunwrap(): I {\n\t\treturn this.wrapped<I>('nullable')\n\t}\n}\n\nexport class KTransform<I extends KType, O> extends KSchema<\n\tO,\n\tI['_req'],\n\ttrue,\n\tI['validator'],\n\ttrue\n> {\n\tdeclare readonly _or: VAny<O>\n\tdeclare readonly _oo: VAny<O>\n}\n\nexport class KPipe<I extends KType, P extends KType> extends KSchema<\n\tP['_output'],\n\tI['_req'],\n\ttrue,\n\tI['validator'],\n\ttrue\n> {\n\tdeclare readonly _or: KOutputRequired<P>\n\tdeclare readonly _oo: OutputNativeOf<P>\n}\n\ntype NullableOf<V extends KRequiredValidator> = VUnion<V['type'] | null, [V, VNull<null>]>\n\n/** Freezes a refine options object and its path in place, like every other container a record holds. */\nfunction frozenMessage(message: string | KRefineOptions | undefined): KMessage {\n\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- refine takes either its message or an options object.\n\tif (message === undefined || typeof message === 'string') return message\n\tif (message.path !== undefined) Object.freeze(message.path)\n\treturn Object.freeze(message)\n}\n\nfunction missingZodEntry(): never {\n\tthrow new Error(\"k: .toZod() needs the Zod interop entry; add `import 'cvx-kit/zod'` first\")\n}\n\nfunction descriptionOf(node: KNode): string | undefined {\n\tfor (let current: KNode | null = node; current !== null; current = current.prev) {\n\t\tif (current.op === 'describe') {\n\t\t\t// SAFETY: a describe record stores its text as the record argument.\n\t\t\treturn current.arg as string\n\t\t}\n\t}\n\treturn undefined\n}\n\nfunction wrappedBy(node: KNode, op: KOp): KNode {\n\tlet current = node\n\twhile (current.op !== op && !(op === 'optional' && current.op === 'partial'))\n\t\tcurrent = prevOf(current)\n\treturn prevOf(current)\n}\n\nfunction prevOf(node: KNode): KNode {\n\tif (node.prev === null) throw new Error(`k: no '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EACd,KAAOD,EAAQ,KAAO1B,IAAQA,IAAO,YAAc0B,EAAQ,KAAO,YACjE,EAAUE,EAAOF,CAAO,EACzB,OAAOE,EAAOF,CAAO,CACtB,CAEA,SAASE,EAAO,EAAoB,CACnC,GAAID,EAAK,OAAS,KAAM,MAAU,MAAM,UAAUA,EAAK,GAAG,oBAAoB,EAC9E,OAAOA,EAAK,IACb,C"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { KNode } from "./types.mjs";
|
|
2
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
+
/**
|
|
4
|
+
* The Standard Schema v1 props of a schema, built when `~standard` is read; nothing is stored on the
|
|
5
|
+
* schema. `validate` delegates to the same walker as `safeParse`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function standardProps<In, Out>(schema: KNode): StandardSchemaV1.Props<In, Out>;
|
|
8
|
+
//# sourceMappingURL=standard.d.mts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{safeParseSchema as e}from"./parse.mjs";function t(e){return{version:1,vendor:`cvx-kit`,validate:t=>n(e,t)}}function n(t,n){let i=e(t,n);return i.success?{value:i.data}:{issues:i.issues.map(r)}}function r(e){return{message:e.message,path:e.path}}export{t as standardProps};
|
|
2
|
+
//# sourceMappingURL=standard.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standard.mjs","names":["standardProps","standardResult","schema","value","result","safeParseSchema","standardIssue","issue"],"sources":["../../src/k/standard.ts"],"sourcesContent":["import type { StandardSchemaV1 } from '@standard-schema/spec'\nimport { safeParseSchema } from './parse'\nimport type { KNode } from './types'\n\n/**\n * The Standard Schema v1 props of a schema, built when `~standard` is read; nothing is stored on the\n * schema. `validate` delegates to the same walker as `safeParse`.\n */\nexport function standardProps<In, Out>(schema: KNode): StandardSchemaV1.Props<In, Out> {\n\treturn {\n\t\tversion: 1,\n\t\tvendor: 'cvx-kit',\n\t\t// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Standard Schema validates undecoded input.\n\t\tvalidate: (value: unknown) => standardResult<Out>(schema, value),\n\t}\n}\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Standard Schema validates undecoded input.\nfunction standardResult<Out>(schema: KNode, value: unknown): StandardSchemaV1.Result<Out> {\n\tconst result = safeParseSchema(schema, value)\n\tif (result.success) {\n\t\t// SAFETY: a successful walk of the schema produces its declared output.\n\t\treturn { value: result.data as Out }\n\t}\n\treturn { issues: result.issues.map(standardIssue) }\n}\n\nfunction standardIssue(issue: {\n\treadonly message: string\n\treadonly path: readonly (string | number)[]\n}): StandardSchemaV1.Issue {\n\treturn { message: issue.message, path: issue.path }\n}\n"],"mappings":"A,8CAQA,SAAgBA,EAAuB,EAAgD,CACtF,MAAO,CACN,QAAS,EACT,OAAQ,UAER,SAAW,GAAmBC,EAAoBC,EAAQC,CAAK,CAChE,CACD,CAGA,SAASF,EAAoB,EAAe,EAA8C,CACzF,IAAMG,EAASC,EAAgBH,EAAQC,CAAK,EAK5C,OAJIC,EAAO,QAEH,CAAE,MAAOA,EAAO,IAAY,EAE7B,CAAE,OAAQA,EAAO,OAAO,IAAIE,CAAa,CAAE,CACnD,CAEA,SAASA,EAAc,EAGI,CAC1B,MAAO,CAAE,QAASC,EAAM,QAAS,KAAMA,EAAM,IAAK,CACnD,C"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { KPlan } from "./parse.mjs";
|
|
2
|
+
import { GenericValidator, Validator, Value } from "convex/values";
|
|
3
|
+
/** Runtime record operation. Roots (`prev === null`) carry a kind op; every other record carries a chain op. */
|
|
4
|
+
export type KOp = 'string' | 'number' | 'int' | 'int64' | 'boolean' | 'null' | 'bytes' | 'any' | 'json' | 'isoDate' | 'isoDateTime' | 'timestamp' | 'literal' | 'enum' | 'id' | 'array' | 'object' | 'record' | 'union' | 'discriminatedUnion' | 'min' | 'max' | 'length' | 'regex' | 'refine' | 'check' | 'trim' | 'lower' | 'upper' | 'overwrite' | 'optional' | 'partial' | 'describe' | 'nullable' | 'default' | 'strip' | 'transform' | 'pipe';
|
|
5
|
+
export type KRequiredValidator = Validator<any, 'required', any>;
|
|
6
|
+
/**
|
|
7
|
+
* Structural constraint for any `k` schema. Every member is a plain read of a class type argument:
|
|
8
|
+
* `_req` is the required native validator, `validator` the input-side one (optional when the chain is
|
|
9
|
+
* optional or defaulted), `_d` whether a default or transform sits anywhere inside (the only case where
|
|
10
|
+
* the output side differs from the input side) and `_t` whether a transform or pipe does.
|
|
11
|
+
*/
|
|
12
|
+
export interface KType extends KNode {
|
|
13
|
+
readonly _output: any;
|
|
14
|
+
readonly _req: KRequiredValidator;
|
|
15
|
+
readonly _d: boolean;
|
|
16
|
+
readonly _t: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The runtime view of any chain record, used by the compilers and the walker without the schema
|
|
20
|
+
* generics. The memo slots are written once, on first use.
|
|
21
|
+
*/
|
|
22
|
+
export interface KNode {
|
|
23
|
+
readonly prev: KNode | null;
|
|
24
|
+
readonly op: KOp;
|
|
25
|
+
readonly arg: KArg;
|
|
26
|
+
readonly message: KMessage;
|
|
27
|
+
native: GenericValidator | undefined;
|
|
28
|
+
outputNative: GenericValidator | undefined;
|
|
29
|
+
plan: KPlan | undefined;
|
|
30
|
+
readonly validator: GenericValidator;
|
|
31
|
+
}
|
|
32
|
+
export type KFields = Readonly<Record<string, KType>>;
|
|
33
|
+
export type KLiteralValue = string | number | bigint | boolean;
|
|
34
|
+
export type KPath = (string | number)[];
|
|
35
|
+
/** Options for `refine`: a replacement message and a path, relative to the refined value, for the issue. */
|
|
36
|
+
export type KRefineOptions = {
|
|
37
|
+
readonly message?: string;
|
|
38
|
+
readonly path?: KPath;
|
|
39
|
+
};
|
|
40
|
+
export type KMessage = string | KRefineOptions | undefined;
|
|
41
|
+
export type KCallback = (...args: never[]) => any;
|
|
42
|
+
export type KDiscriminated = {
|
|
43
|
+
readonly key: string;
|
|
44
|
+
readonly options: readonly KType[];
|
|
45
|
+
};
|
|
46
|
+
export type KArg = Value | undefined | RegExp | KType | readonly KType[] | readonly string[] | KFields | KCallback | KDiscriminated;
|
|
47
|
+
/** Input-side native Convex validator type of a `k` schema: a defaulted field is optional. */
|
|
48
|
+
export type NativeOf<T extends KType> = T['validator'];
|
|
49
|
+
/** Output-side native Convex validator type of a `k` schema: a defaulted field is required. */
|
|
50
|
+
export type OutputNativeOf<T extends KType> = T['_d'] extends true ? T extends {
|
|
51
|
+
readonly _oo: infer O extends GenericValidator;
|
|
52
|
+
} ? O : never : T['validator'];
|
|
53
|
+
/** Required output-side native validator, for array elements, union members and record values. */
|
|
54
|
+
export type KOutputRequired<T extends KType> = T['_d'] extends true ? T extends {
|
|
55
|
+
readonly _or: infer O extends KRequiredValidator;
|
|
56
|
+
} ? O : never : T['_req'];
|
|
57
|
+
export type KNativeFields<F extends KFields> = { [K in keyof F]: F[K]['validator']; };
|
|
58
|
+
export type KOutputFields<F extends KFields> = { [K in keyof F]: OutputNativeOf<F[K]>; };
|
|
59
|
+
export type KAnyDiffers<F extends KFields> = true extends F[keyof F]['_d'] ? true : false;
|
|
60
|
+
export type KAnyTransform<F extends KFields> = true extends F[keyof F]['_t'] ? true : false;
|
|
61
|
+
/** Output of an object that holds a default or transform somewhere: a defaulted field is required. */
|
|
62
|
+
export type KObjectOutput<F extends KFields> = Flat<{ [K in keyof F as undefined extends F[K]['_output'] ? K : never]?: Exclude<F[K]['_output'], undefined>; } & { [K in keyof F as undefined extends F[K]['_output'] ? never : K]: F[K]['_output']; }>;
|
|
63
|
+
export type Flat<T> = { [K in keyof T]: T[K]; };
|
|
64
|
+
//# sourceMappingURL=types.d.mts.map
|
package/dist/k/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
package/dist/k.d.mts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { k } from "./k/index.mjs";
|
|
2
|
+
import { KIssue, KIssueCode, KIssueInput, KSafeParseResult, KValidationData, KValidationError } from "./k/issues.mjs";
|
|
3
|
+
import { KAny, KArray, KBoolean, KBytes, KDiscriminatedUnion, KEnum, KId, KInt64, KJson, KLiteral, KNull, KNumber, KRecord, KString, KUnion } from "./k/kinds.mjs";
|
|
4
|
+
import { KIsoDate, KIsoDateTime, KTimestamp } from "./k/dates.mjs";
|
|
5
|
+
import { KObject } from "./k/object.mjs";
|
|
6
|
+
import { KCheckContext, KDefault, KNullable, KOptional, KPipe, KSchema, KTransform } from "./k/schema.mjs";
|
|
7
|
+
import { KFields, KPath, KRefineOptions, KType, NativeOf, OutputNativeOf } from "./k/types.mjs";
|
|
8
|
+
export { type KAny, type KArray, type KBoolean, type KBytes, type KCheckContext, type KDefault, type KDiscriminatedUnion, type KEnum, type KFields, type KId, type KInt64, type KIsoDate, type KIsoDateTime, type KIssue, type KIssueCode, type KIssueInput, type KJson, type KLiteral, type KNull, type KNullable, type KNumber, type KObject, type KOptional, type KPath, type KPipe, type KRecord, type KRefineOptions, type KSafeParseResult, type KSchema, type KString, type KTimestamp, type KTransform, type KType, type KUnion, type KValidationData, KValidationError, type NativeOf, type OutputNativeOf, k };
|
package/dist/k.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{k as e}from"./k/index.mjs";import{KValidationError as t}from"./k/issues.mjs";export{t as KValidationError,e as k};
|
package/dist/middleware.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ErrorFactory } from "./errors.mjs";
|
|
2
|
-
//#region src/middleware.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Structural surface of @convex-dev/rate-limiter's RateLimiter (checked
|
|
5
4
|
* against 0.3.x; re-verify at install). The host mounts the component and
|
|
@@ -41,5 +40,4 @@ export declare function rateLimit<Context = never>(config: {
|
|
|
41
40
|
context?: object;
|
|
42
41
|
}) => Promise<Result>;
|
|
43
42
|
}) => Promise<Result>;
|
|
44
|
-
//#endregion
|
|
45
43
|
//# sourceMappingURL=middleware.d.mts.map
|
package/dist/middleware.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{defaultErrors as e}from"./errors.mjs";import{
|
|
1
|
+
import{defaultErrors as e}from"./errors.mjs";import{k as t}from"./k/index.mjs";function n(t){let n=t.errors??e;return async e=>{let r=t.key?t.key(e.context):i(e.context);if(r===void 0)return n.throw({code:`RATE_LIMIT_KEY_MISSING`,message:`rateLimit("${t.name}") has no key: ctx.tenant is undefined and no key fn was configured`});let a=await t.limiter.limit(e.context,t.name,{key:r});return a.ok?e.next():(await t.onLimit?.(a,e.context),n.throw({code:`RATE_LIMITED`,message:`Rate limit "${t.name}" exceeded${a.retryAfter===void 0?``:`; retry after ${Math.ceil(a.retryAfter)}ms`}`}))}}const r=t.string().optional();function i(e){return r.parse(e.tenant)}export{n as rateLimit};
|
|
2
2
|
//# sourceMappingURL=middleware.mjs.map
|
package/dist/middleware.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.mjs","names":["rateLimit","errors","config","defaultErrors","key","input","
|
|
1
|
+
{"version":3,"file":"middleware.mjs","names":["rateLimit","errors","config","defaultErrors","key","input","contextTenant","status","tenantField","k","context"],"sources":["../src/middleware.ts"],"sourcesContent":["import { defaultErrors, type ErrorFactory } from './errors'\nimport { k } from './k'\n\n/**\n * Structural surface of @convex-dev/rate-limiter's RateLimiter (checked\n * against 0.3.x; re-verify at install). The host mounts the component and\n * constructs the limiter; the kit only ever receives the instance —\n * injection keeps the kit dependency-free.\n */\nexport type RateLimiterLike = {\n\tlimit: (\n\t\tctx: never,\n\t\tname: string,\n\t\toptions?: { key?: string },\n\t) => Promise<{ ok: boolean; retryAfter?: number }>\n}\n\n/**\n * The first packaged middleware: rate limiting on the Command/Query\n * middleware seams. Runs before guards and the handler; a rejected call\n * throws RATE_LIMITED (audit and handler never run). Keyed by ctx.tenant by\n * default — when no key fn is given and ctx.tenant is undefined, this is a\n * configuration error, not a silent shared bucket.\n *\n * The returned middleware is shape-compatible with both AnyCommandMiddleware\n * and AnyQueryMiddleware.\n */\nexport function rateLimit<Context = never>(config: {\n\tlimiter: RateLimiterLike\n\tname: string\n\t/** Defaults to ctx.tenant. */\n\tkey?: (context: Context) => string\n\t/** Observe a rejection before the throw (metrics, headers). */\n\tonLimit?: (status: { ok: boolean; retryAfter?: number }, context: Context) => void | Promise<void>\n\terrors?: ErrorFactory\n}) {\n\tconst errors = config.errors ?? defaultErrors\n\treturn async <Result>(input: {\n\t\tcontext: never\n\t\tnext: (options?: { context?: object }) => Promise<Result>\n\t}): Promise<Result> => {\n\t\tconst key = config.key ? config.key(input.context) : contextTenant(input.context)\n\t\tif (key === undefined) {\n\t\t\treturn errors.throw({\n\t\t\t\tcode: 'RATE_LIMIT_KEY_MISSING',\n\t\t\t\tmessage: `rateLimit(\"${config.name}\") has no key: ctx.tenant is undefined and no key fn was configured`,\n\t\t\t})\n\t\t}\n\t\tconst status = await config.limiter.limit(input.context, config.name, {\n\t\t\tkey,\n\t\t})\n\t\tif (!status.ok) {\n\t\t\tawait config.onLimit?.(status, input.context)\n\t\t\treturn errors.throw({\n\t\t\t\tcode: 'RATE_LIMITED',\n\t\t\t\tmessage: `Rate limit \"${config.name}\" exceeded${\n\t\t\t\t\tstatus.retryAfter === undefined ? '' : `; retry after ${Math.ceil(status.retryAfter)}ms`\n\t\t\t\t}`,\n\t\t\t})\n\t\t}\n\t\treturn input.next()\n\t}\n}\n\nconst tenantField = k.string().optional()\n\n/** The only context member the default key reads; the rest of the context is never inspected. */\ntype TenantCarrier = { readonly tenant?: unknown }\n\n/** `ctx.tenant`, which must be a string when present (VALIDATION otherwise). */\nfunction contextTenant(context: TenantCarrier): string | undefined {\n\treturn tenantField.parse(context.tenant)\n}\n"],"mappings":"A,+EA2BA,SAAgBA,EAA2B,EAQxC,CACF,IAAMC,EAASC,EAAO,QAAUC,EAChC,OAAO,KAAe,IAGC,CACtB,IAAMC,EAAMF,EAAO,IAAMA,EAAO,IAAIG,EAAM,OAAO,EAAIC,EAAcD,EAAM,OAAO,EAChF,GAAID,IAAQ,IAAA,GACX,OAAOH,EAAO,MAAM,CACnB,KAAM,yBACN,QAAS,cAAcC,EAAO,KAAK,oEACpC,CAAC,EAEF,IAAMK,EAAS,MAAML,EAAO,QAAQ,MAAMG,EAAM,QAASH,EAAO,KAAM,CACrE,KACD,CAAC,EAUD,OATKK,EAAO,GASLF,EAAM,KAAK,GARjB,MAAMH,EAAO,UAAUK,EAAQF,EAAM,OAAO,EACrCJ,EAAO,MAAM,CACnB,KAAM,eACN,QAAS,eAAeC,EAAO,KAAK,YACnCK,EAAO,aAAe,IAAA,GAAY,GAAK,iBAAiB,KAAK,KAAKA,EAAO,UAAU,EAAE,KAEvF,CAAC,EAGH,CACD,CAEA,MAAMC,EAAcC,EAAE,OAAO,CAAC,CAAC,SAAS,EAMxC,SAASH,EAAc,EAA4C,CAClE,OAAOE,EAAY,MAAME,EAAQ,MAAM,CACxC,C"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { DomainContract, DomainOperationContract } from "./domain.mjs";
|
|
2
|
-
//#region src/modules/contracts/binding.d.ts
|
|
3
2
|
declare const declaredSchemas: unique symbol;
|
|
4
3
|
/** Private evidence for contextual inference; schemas are installed only at registration. */
|
|
5
4
|
export type DeclaredSchemas<Entry> = {
|
|
@@ -20,5 +19,5 @@ export declare function domainHelpers(entries: Readonly<Record<string, object>>)
|
|
|
20
19
|
export declare function bindDomainImplementation(key: string, declaration: object, implementation: object): {};
|
|
21
20
|
/** Snapshot records and verify key ownership before the executor closes over them. */
|
|
22
21
|
export declare function snapshotOperations(operations: Readonly<Record<string, object>>, contract: DomainContract | undefined, section: 'commands' | 'queries' | 'actions', audit?: (resolution: never, context: never, scope: never) => unknown): Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
23
|
-
|
|
22
|
+
export {};
|
|
24
23
|
//# sourceMappingURL=binding.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binding.mjs","names":["protectedFields","bindings","pending","deferred","domainHelpers","helpers","entries","key","isLazyOperation","bindDomainImplementation","implementation","draft","namedHandler","handler","options","field","declaration","definition","snapshotOperations","audit","declarations","contract","section","keys","operations","bind","original","binding","override","resolution","context","scope","snapshot","memoize","descriptor","value"],"sources":["../../../src/modules/contracts/binding.ts"],"sourcesContent":["/* oxlint-disable anti-slop/no-object-parameters, anti-slop/no-unsafe-dictionary-type, anti-slop/no-known-value-widening, anti-slop/no-runtime-typeof, anti-slop/no-unknown-parameters, anti-slop/no-unknown-returns -- Configuration boundary validates heterogeneous own-key records and callback presence; validators remain opaque identities. */\nimport { memoize } from './lazy'\nimport type { DomainContract, DomainOperationContract } from './domain'\n\ndeclare const declaredSchemas: unique symbol\n/** Private evidence for contextual inference; schemas are installed only at registration. */\nexport type DeclaredSchemas<Entry> = { readonly [declaredSchemas]: Entry }\nexport type BoundOperations<\n\tOperations extends Readonly<\n\t\tRecord<keyof Entries, { handler: (...arguments_: never[]) => unknown }>\n\t>,\n\tEntries extends Readonly<Record<string, DomainOperationContract>>,\n> = {\n\t[Key in keyof Entries]: Entries[Key] &\n\t\tOperations[Key] & {\n\t\t\tinput: Entries[Key]['input']\n\t\t\tresult: Entries[Key]['result']\n\t\t\thandler: Operations[Key]['handler']\n\t\t}\n}\n\n// SAFETY: this configuration boundary compares opaque fields or restores callback slots checked by the public helpers.\nconst protectedFields = ['input', 'result', 'classification', 'replayResult', 'wire'] as const\nconst bindings = new WeakMap<object, { key: string; declaration: object }>()\nconst pending = new WeakMap<object, Readonly<Record<string, object>>>()\nconst deferred = new WeakMap<object, { key: string; entries: Readonly<Record<string, object>> }>()\n\n/** Both adapters bind declarations through the same configuration boundary. */\nexport function domainHelpers(entries: Readonly<Record<string, object>>) {\n\tconst helpers = Object.fromEntries(\n\t\tObject.keys(entries).map((key) => [\n\t\t\tkey,\n\t\t\t(implementation: object) => {\n\t\t\t\tif (!isLazyOperation(entries, key))\n\t\t\t\t\treturn bindDomainImplementation(key, entries[key], implementation)\n\t\t\t\tconst draft = { ...implementation }\n\t\t\t\tdeferred.set(draft, { key, entries })\n\t\t\t\treturn draft\n\t\t\t},\n\t\t]),\n\t)\n\tconst namedHandler = helpers.handler\n\thelpers.handler = (handler: Function | object, options?: object) => {\n\t\tif (typeof handler !== 'function' && namedHandler) return namedHandler(handler)\n\t\tif (typeof handler !== 'function') throw Error('Invalid operation handler')\n\t\tconst implementation = { ...options, handler }\n\t\tpending.set(implementation, entries)\n\t\treturn implementation\n\t}\n\treturn helpers\n}\n\n/** Bind only opaque schema references; never invoke user callbacks at construction. */\nexport function bindDomainImplementation(key: string, declaration: object, implementation: object) {\n\tfor (const field of ['handler', 'audit', 'prepare', 'guard', 'middleware', 'context']) {\n\t\tif (Object.prototype.hasOwnProperty.call(declaration, field))\n\t\t\tthrow Error(`Domain contract ${key} cannot contain ${field}`)\n\t}\n\tfor (const field of protectedFields) {\n\t\tif (Object.prototype.hasOwnProperty.call(implementation, field))\n\t\t\tthrow Error(`Contracted operation ${key} cannot override ${field}`)\n\t}\n\tconst definition = { ...implementation, ...declaration }\n\tbindings.set(definition, { key, declaration })\n\treturn definition\n}\n\n/** Snapshot records and verify key ownership before the executor closes over them. */\nexport function snapshotOperations(\n\toperations: Readonly<Record<string, object>>,\n\tcontract: DomainContract | undefined,\n\tsection: 'commands' | 'queries' | 'actions',\n\taudit?: (resolution: never, context: never, scope: never) => unknown,\n) {\n\tif (audit !== undefined && typeof audit !== 'function')\n\t\tthrow Error('Invalid registry audit callback')\n\tconst declarations = contract?.[section]\n\tif (contract && !declarations) throw Error(`Domain contract has no ${section} section`)\n\tconst keys = Object.keys(operations)\n\tif (\n\t\tdeclarations &&\n\t\t(keys.length !== Object.keys(declarations).length ||\n\t\t\tkeys.some((key) => !Object.prototype.hasOwnProperty.call(declarations, key)))\n\t)\n\t\tthrow Error('Contract operation keys must match exactly')\n\tconst bind = (key: string) => {\n\t\tlet original = operations[key]\n\t\t// A deferred helper result binds to its own declaration wherever it is registered.\n\t\tconst draft = deferred.get(original)\n\t\tif (draft) original = bindDomainImplementation(draft.key, draft.entries[draft.key], original)\n\t\tif (declarations) {\n\t\t\tif (pending.has(original)) {\n\t\t\t\tif (pending.get(original) !== declarations)\n\t\t\t\t\tthrow Error(`Operation ${key} must use its own contract helper`)\n\t\t\t\toriginal = bindDomainImplementation(key, declarations[key], original)\n\t\t\t}\n\t\t\tconst binding = bindings.get(original)\n\t\t\tif (\n\t\t\t\t!binding ||\n\t\t\t\tbinding.key !== key ||\n\t\t\t\tbinding.declaration !== declarations[key] ||\n\t\t\t\tprotectedFields.some(\n\t\t\t\t\t(field) =>\n\t\t\t\t\t\t// SAFETY: this configuration boundary compares opaque fields or restores callback slots checked by the public helpers.\n\t\t\t\t\t\t(original as Record<string, unknown>)[field] !==\n\t\t\t\t\t\t// SAFETY: this configuration boundary compares opaque fields or restores callback slots checked by the public helpers.\n\t\t\t\t\t\t(declarations[key] as Record<string, unknown>)[field],\n\t\t\t\t)\n\t\t\t)\n\t\t\t\tthrow Error(`Operation ${key} must use its own contract helper`)\n\t\t}\n\t\t// SAFETY: this configuration boundary compares opaque fields or restores callback slots checked by the public helpers.\n\t\tconst definition = { ...original } as Record<string, unknown>\n\t\tif (definition.wire) {\n\t\t\t// SAFETY: wire is configuration, while its schema stays an opaque reference.\n\t\t\tdefinition.wire = Object.freeze({ ...(definition.wire as object) })\n\t\t}\n\t\tif (section === 'commands' || section === 'actions') {\n\t\t\tconst override = definition.audit\n\t\t\tif (override !== undefined && typeof override !== 'function')\n\t\t\t\tthrow Error(`Invalid audit for ${key}`)\n\t\t\tif (override === undefined && !audit && section === 'commands')\n\t\t\t\tthrow Error(`Command ${key} requires an audit callback`)\n\t\t\tif (override === undefined && audit) {\n\t\t\t\tdefinition.audit = (\n\t\t\t\t\tresolution: { command: unknown; result: unknown },\n\t\t\t\t\tcontext: unknown,\n\t\t\t\t\tscope: unknown,\n\t\t\t\t) =>\n\t\t\t\t\taudit(\n\t\t\t\t\t\t// SAFETY: this configuration boundary compares opaque fields or restores callback slots checked by the public helpers.\n\t\t\t\t\t\t{ operation: key, input: resolution.command, result: resolution.result } as never,\n\t\t\t\t\t\t// SAFETY: this configuration boundary compares opaque fields or restores callback slots checked by the public helpers.\n\t\t\t\t\t\tcontext as never,\n\t\t\t\t\t\t// SAFETY: the registry audit signature declares the scope its executor passes.\n\t\t\t\t\t\tscope as never,\n\t\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\t// SAFETY: this configuration boundary compares opaque fields or restores callback slots checked by the public helpers.\n\t\treturn Object.freeze(definition)\n\t}\n\tconst snapshot: Record<string, Readonly<Record<string, unknown>>> = {}\n\tfor (const key of keys) {\n\t\tif (declarations && isLazyOperation(declarations, key))\n\t\t\tObject.defineProperty(snapshot, key, { enumerable: true, get: memoize(() => bind(key)) })\n\t\telse snapshot[key] = bind(key)\n\t}\n\treturn Object.freeze(snapshot)\n}\n\n/** Getter-declared operations, or operations with getter-declared protected fields, bind on first access. */\nfunction isLazyOperation(entries: Readonly<Record<string, object>>, key: string) {\n\tconst descriptor = Object.getOwnPropertyDescriptor(entries, key)\n\tif (!descriptor) return false\n\tif (descriptor.get) return true\n\tconst value: unknown = descriptor.value\n\treturn (\n\t\t!!value &&\n\t\ttypeof value === 'object' &&\n\t\tprotectedFields.some((field) => !!Object.getOwnPropertyDescriptor(value, field)?.get)\n\t)\n}\n"],"mappings":"qCAsBA,MAAMA,EAAkB,CAAC,QAAS,SAAU,iBAAkB,eAAgB,MAAM,EAC9EC,kBAAW,IAAI,QACfC,kBAAU,IAAI,QACdC,kBAAW,IAAI,QAGrB,SAAgBC,EAAc,EAA2C,CACxE,IAAMC,EAAU,OAAO,YACtB,OAAO,KAAKC,CAAO,CAAC,CAAC,IAAK,GAAQ,CACjCC,EACC,GAA2B,CAC3B,GAAI,CAACC,EAAgBF,EAASC,CAAG,EAChC,OAAOE,EAAyBF,EAAKD,EAAQC,GAAMG,CAAc,EAClE,IAAMC,EAAQ,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EACbH,GAAgBZ,EAAgBY,EAAcb,CAAG,EACpD,OAAO,eAAeyB,EAAUzB,EAAK,CAAE,WAAY,GAAM,IAAK0B,MAAcR,EAAKlB,CAAG,CAAC,CAAE,CAAC,EACpF,EAASA,GAAOkB,EAAKlB,CAAG,EAE9B,OAAO,OAAO,OAAOyB,CAAQ,CAC9B,CAGA,SAASxB,EAAgB,EAA2C,EAAa,CAChF,IAAM0B,EAAa,OAAO,yBAAyB5B,EAASC,CAAG,EAC/D,GAAI,CAAC2B,EAAY,MAAO,GACxB,GAAIA,EAAW,IAAK,MAAO,GAC3B,IAAMC,EAAiBD,EAAW,MAClC,MACC,CAAC,CAACC,GACF,OAAOA,GAAU,UACjBnC,EAAgB,KAAM,GAAU,CAAC,CAAC,OAAO,yBAAyBmC,EAAOpB,CAAK,CAAC,EAAE,GAAG,CAEtF"}
|
|
1
|
+
{"version":3,"file":"binding.mjs","names":["protectedFields","bindings","pending","deferred","domainHelpers","helpers","entries","key","isLazyOperation","bindDomainImplementation","implementation","draft","namedHandler","handler","options","field","declaration","definition","snapshotOperations","audit","declarations","contract","section","keys","operations","bind","original","binding","override","resolution","context","scope","snapshot","memoize","descriptor","value"],"sources":["../../../src/modules/contracts/binding.ts"],"sourcesContent":["/* oxlint-disable anti-slop/no-object-parameters, anti-slop/no-unsafe-dictionary-type, anti-slop/no-known-value-widening, anti-slop/no-runtime-typeof, anti-slop/no-unknown-parameters, anti-slop/no-unknown-returns -- Configuration boundary validates heterogeneous own-key records and callback presence; validators remain opaque identities. */\nimport { memoize } from './lazy'\nimport type { DomainContract, DomainOperationContract } from './domain'\n\ndeclare const declaredSchemas: unique symbol\n/** Private evidence for contextual inference; schemas are installed only at registration. */\nexport type DeclaredSchemas<Entry> = { readonly [declaredSchemas]: Entry }\nexport type BoundOperations<\n\tOperations extends Readonly<\n\t\tRecord<keyof Entries, { handler: (...arguments_: never[]) => unknown }>\n\t>,\n\tEntries extends Readonly<Record<string, DomainOperationContract>>,\n> = {\n\t[Key in keyof Entries]: Entries[Key] &\n\t\tOperations[Key] & {\n\t\t\tinput: Entries[Key]['input']\n\t\t\tresult: Entries[Key]['result']\n\t\t\thandler: Operations[Key]['handler']\n\t\t}\n}\n\n// SAFETY: this configuration boundary compares opaque fields or restores callback slots checked by the public helpers.\nconst protectedFields = ['input', 'result', 'classification', 'replayResult', 'wire'] as const\nconst bindings = new WeakMap<object, { key: string; declaration: object }>()\nconst pending = new WeakMap<object, Readonly<Record<string, object>>>()\nconst deferred = new WeakMap<object, { key: string; entries: Readonly<Record<string, object>> }>()\n\n/** Both adapters bind declarations through the same configuration boundary. */\nexport function domainHelpers(entries: Readonly<Record<string, object>>) {\n\tconst helpers = Object.fromEntries(\n\t\tObject.keys(entries).map((key) => [\n\t\t\tkey,\n\t\t\t(implementation: object) => {\n\t\t\t\tif (!isLazyOperation(entries, key))\n\t\t\t\t\treturn bindDomainImplementation(key, entries[key], implementation)\n\t\t\t\tconst draft = { ...implementation }\n\t\t\t\tdeferred.set(draft, { key, entries })\n\t\t\t\treturn draft\n\t\t\t},\n\t\t]),\n\t)\n\tconst namedHandler = helpers.handler\n\thelpers.handler = (handler: Function | object, options?: object) => {\n\t\tif (typeof handler !== 'function' && namedHandler) return namedHandler(handler)\n\t\tif (typeof handler !== 'function') throw Error('Invalid operation handler')\n\t\tconst implementation = { ...options, handler }\n\t\tpending.set(implementation, entries)\n\t\treturn implementation\n\t}\n\treturn helpers\n}\n\n/** Bind only opaque schema references; never invoke user callbacks at construction. */\nexport function bindDomainImplementation(key: string, declaration: object, implementation: object) {\n\tfor (const field of ['handler', 'audit', 'prepare', 'guard', 'middleware', 'context']) {\n\t\tif (Object.prototype.hasOwnProperty.call(declaration, field))\n\t\t\tthrow Error(`Domain contract ${key} cannot contain ${field}`)\n\t}\n\tfor (const field of protectedFields) {\n\t\tif (Object.prototype.hasOwnProperty.call(implementation, field))\n\t\t\tthrow Error(`Contracted operation ${key} cannot override ${field}`)\n\t}\n\tconst definition = { ...implementation, ...declaration }\n\tbindings.set(definition, { key, declaration })\n\treturn definition\n}\n\n/** Snapshot records and verify key ownership before the executor closes over them. */\nexport function snapshotOperations(\n\toperations: Readonly<Record<string, object>>,\n\tcontract: DomainContract | undefined,\n\tsection: 'commands' | 'queries' | 'actions',\n\taudit?: (resolution: never, context: never, scope: never) => unknown,\n) {\n\tif (audit !== undefined && typeof audit !== 'function')\n\t\tthrow Error('Invalid registry audit callback')\n\tconst declarations = contract?.[section]\n\tif (contract && !declarations) throw Error(`Domain contract has no ${section} section`)\n\tconst keys = Object.keys(operations)\n\tif (\n\t\tdeclarations &&\n\t\t(keys.length !== Object.keys(declarations).length ||\n\t\t\tkeys.some((key) => !Object.prototype.hasOwnProperty.call(declarations, key)))\n\t)\n\t\tthrow Error('Contract operation keys must match exactly')\n\tconst bind = (key: string) => {\n\t\tlet original = operations[key]\n\t\t// A deferred helper result binds to its own declaration wherever it is registered.\n\t\tconst draft = deferred.get(original)\n\t\tif (draft) original = bindDomainImplementation(draft.key, draft.entries[draft.key], original)\n\t\tif (declarations) {\n\t\t\tif (pending.has(original)) {\n\t\t\t\tif (pending.get(original) !== declarations)\n\t\t\t\t\tthrow Error(`Operation ${key} must use its own contract helper`)\n\t\t\t\toriginal = bindDomainImplementation(key, declarations[key], original)\n\t\t\t}\n\t\t\tconst binding = bindings.get(original)\n\t\t\tif (\n\t\t\t\t!binding ||\n\t\t\t\tbinding.key !== key ||\n\t\t\t\tbinding.declaration !== declarations[key] ||\n\t\t\t\tprotectedFields.some(\n\t\t\t\t\t(field) =>\n\t\t\t\t\t\t// SAFETY: this configuration boundary compares opaque fields or restores callback slots checked by the public helpers.\n\t\t\t\t\t\t(original as Record<string, unknown>)[field] !==\n\t\t\t\t\t\t// SAFETY: this configuration boundary compares opaque fields or restores callback slots checked by the public helpers.\n\t\t\t\t\t\t(declarations[key] as Record<string, unknown>)[field],\n\t\t\t\t)\n\t\t\t)\n\t\t\t\tthrow Error(`Operation ${key} must use its own contract helper`)\n\t\t}\n\t\t// SAFETY: this configuration boundary compares opaque fields or restores callback slots checked by the public helpers.\n\t\tconst definition = { ...original } as Record<string, unknown>\n\t\tif (definition.wire) {\n\t\t\t// SAFETY: wire is configuration, while its schema stays an opaque reference.\n\t\t\tdefinition.wire = Object.freeze({ ...(definition.wire as object) })\n\t\t}\n\t\tif (section === 'commands' || section === 'actions') {\n\t\t\tconst override = definition.audit\n\t\t\tif (override !== undefined && typeof override !== 'function')\n\t\t\t\tthrow Error(`Invalid audit for ${key}`)\n\t\t\tif (override === undefined && !audit && section === 'commands')\n\t\t\t\tthrow Error(`Command ${key} requires an audit callback`)\n\t\t\tif (override === undefined && audit) {\n\t\t\t\tdefinition.audit = (\n\t\t\t\t\tresolution: { command: unknown; result: unknown },\n\t\t\t\t\tcontext: unknown,\n\t\t\t\t\tscope: unknown,\n\t\t\t\t) =>\n\t\t\t\t\taudit(\n\t\t\t\t\t\t// SAFETY: this configuration boundary compares opaque fields or restores callback slots checked by the public helpers.\n\t\t\t\t\t\t{ operation: key, input: resolution.command, result: resolution.result } as never,\n\t\t\t\t\t\t// SAFETY: this configuration boundary compares opaque fields or restores callback slots checked by the public helpers.\n\t\t\t\t\t\tcontext as never,\n\t\t\t\t\t\t// SAFETY: the registry audit signature declares the scope its executor passes.\n\t\t\t\t\t\tscope as never,\n\t\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\t// SAFETY: this configuration boundary compares opaque fields or restores callback slots checked by the public helpers.\n\t\treturn Object.freeze(definition)\n\t}\n\tconst snapshot: Record<string, Readonly<Record<string, unknown>>> = {}\n\tfor (const key of keys) {\n\t\tif (declarations && isLazyOperation(declarations, key))\n\t\t\tObject.defineProperty(snapshot, key, { enumerable: true, get: memoize(() => bind(key)) })\n\t\telse snapshot[key] = bind(key)\n\t}\n\treturn Object.freeze(snapshot)\n}\n\n/** Getter-declared operations, or operations with getter-declared protected fields, bind on first access. */\nfunction isLazyOperation(entries: Readonly<Record<string, object>>, key: string) {\n\tconst descriptor = Object.getOwnPropertyDescriptor(entries, key)\n\tif (!descriptor) return false\n\tif (descriptor.get) return true\n\tconst value: unknown = descriptor.value\n\treturn (\n\t\t!!value &&\n\t\ttypeof value === 'object' &&\n\t\tprotectedFields.some((field) => !!Object.getOwnPropertyDescriptor(value, field)?.get)\n\t)\n}\n"],"mappings":"A,qCAsBA,MAAMA,EAAkB,CAAC,QAAS,SAAU,iBAAkB,eAAgB,MAAM,EAC9EC,kBAAW,IAAI,QACfC,kBAAU,IAAI,QACdC,kBAAW,IAAI,QAGrB,SAAgBC,EAAc,EAA2C,CACxE,IAAMC,EAAU,OAAO,YACtB,OAAO,KAAKC,CAAO,CAAC,CAAC,IAAK,GAAQ,CACjCC,EACC,GAA2B,CAC3B,GAAI,CAACC,EAAgBF,EAASC,CAAG,EAChC,OAAOE,EAAyBF,EAAKD,EAAQC,GAAMG,CAAc,EAClE,IAAMC,EAAQ,CAAE,GAAGD,CAAe,EAElC,OADAP,EAAS,IAAIQ,EAAO,CAAE,MAAK,SAAQ,CAAC,EAC7BA,CACR,CACD,CAAC,CACF,EACMC,EAAeP,EAAQ,QAQ7B,MAPA,GAAQ,SAAW,EAA4B,IAAqB,CACnE,GAAI,OAAOQ,GAAY,YAAcD,EAAc,OAAOA,EAAaC,CAAO,EAC9E,GAAI,OAAOA,GAAY,WAAY,MAAM,MAAM,2BAA2B,EAC1E,IAAMH,EAAiB,CAAE,GAAGI,EAAS,SAAQ,EAE7C,OADAZ,EAAQ,IAAIQ,EAAgBJ,CAAO,EAC5BI,CACR,EACOL,CACR,CAGA,SAAgBI,EAAyB,EAAa,EAAqB,EAAwB,CAClG,IAAK,IAAMM,IAAS,CAAC,UAAW,QAAS,UAAW,QAAS,aAAc,SAAS,EACnF,GAAI,OAAO,UAAU,eAAe,KAAKC,EAAaD,CAAK,EAC1D,MAAM,MAAM,mBAAmBR,EAAI,kBAAkBQ,GAAO,EAE9D,IAAK,IAAMA,KAASf,EACnB,GAAI,OAAO,UAAU,eAAe,KAAKU,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GS,CAAS,EAKjC,GAJA,AAECT,EAAW,OAAO,OAAO,OAAO,CAAE,GAAIA,EAAW,IAAgB,CAAC,EAE/DK,IAAY,YAAcA,IAAY,UAAW,CACpD,IAAMM,EAAWX,EAAW,MAC5B,GAAIW,IAAa,IAAA,IAAa,OAAOA,GAAa,WACjD,MAAM,MAAM,qBAAqBrB,GAAK,EACvC,GAAIqB,IAAa,IAAA,IAAa,CAACT,GAASG,IAAY,WACnD,MAAM,MAAM,WAAWf,EAAI,4BAA4B,EACpDqB,IAAa,IAAA,IAAaT,IAC7B,EAAW,OACV,EACA,EACA,IAEAA,EAEC,CAAE,UAAWZ,EAAK,MAAOsB,EAAW,QAAS,OAAQA,EAAW,MAAO,EAEvEC,EAEAC,CACD,EAEH,CAEA,OAAO,OAAO,OAAOd,CAAU,CAChC,EACMe,EAA8D,CAAC,EACrE,IAAK,IAAMzB,KAAOgB,EACbH,GAAgBZ,EAAgBY,EAAcb,CAAG,EACpD,OAAO,eAAeyB,EAAUzB,EAAK,CAAE,WAAY,GAAM,IAAK0B,MAAcR,EAAKlB,CAAG,CAAC,CAAE,CAAC,EACpF,EAASA,GAAOkB,EAAKlB,CAAG,EAE9B,OAAO,OAAO,OAAOyB,CAAQ,CAC9B,CAGA,SAASxB,EAAgB,EAA2C,EAAa,CAChF,IAAM0B,EAAa,OAAO,yBAAyB5B,EAASC,CAAG,EAC/D,GAAI,CAAC2B,EAAY,MAAO,GACxB,GAAIA,EAAW,IAAK,MAAO,GAC3B,IAAMC,EAAiBD,EAAW,MAClC,MACC,CAAC,CAACC,GACF,OAAOA,GAAU,UACjBnC,EAAgB,KAAM,GAAU,CAAC,CAAC,OAAO,yBAAyBmC,EAAOpB,CAAK,CAAC,EAAE,GAAG,CAEtF,C"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/modules/contracts/contract.d.ts
|
|
2
1
|
/** Structural contracts keep the optional Effect peer out of this module. */
|
|
3
2
|
export interface StandardSchema<Input = unknown, Output = Input> {
|
|
4
3
|
readonly '~standard': {
|
|
@@ -65,5 +64,4 @@ export declare function operationContract<const Input extends ContractSchema, co
|
|
|
65
64
|
schema: Wire;
|
|
66
65
|
};
|
|
67
66
|
};
|
|
68
|
-
//#endregion
|
|
69
67
|
//# sourceMappingURL=contract.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.mjs","names":["decodeContract","result","schema","value","operationContract","definition"],"sources":["../../../src/modules/contracts/contract.ts"],"sourcesContent":["/* oxlint-disable anti-slop/no-unknown-parameters -- These explicit validation boundaries receive untrusted transport values before schema decoding. */\n/** Structural contracts keep the optional Effect peer out of this module. */\nexport interface StandardSchema<Input = unknown, Output = Input> {\n\treadonly '~standard': {\n\t\treadonly version: 1\n\t\treadonly vendor: string\n\t\treadonly types?: { readonly input: Input; readonly output: Output }\n\t\treadonly validate: (\n\t\t\tvalue: unknown,\n\t\t) => ValidationResult<Output> | Promise<ValidationResult<Output>>\n\t}\n}\nexport interface ValidationIssue {\n\treadonly message: string\n\treadonly path?: readonly (PropertyKey | { readonly key: PropertyKey })[]\n}\nexport type ValidationResult<Output> =\n\t| { readonly value: Output; readonly issues?: undefined }\n\t| { readonly issues: readonly ValidationIssue[] }\nexport interface LegacyParser<Output = unknown> {\n\treadonly parse: (value: unknown) => Output\n\treadonly parseAsync?: (value: unknown) => Promise<Output>\n}\n/** Decode execution is an opaque channel here; optional adapters give it concrete semantics. */\nexport interface Decoder<Input = unknown, Output = unknown, Execution = unknown> {\n\treadonly kind: 'contract' | 'effect-contract'\n\treadonly types?: { readonly input: Input; readonly output: Output }\n\treadonly decode: (value: unknown) => Execution\n}\nexport type ContractSchema = LegacyParser | StandardSchema<unknown, unknown> | Decoder\nexport type NeutralSchema =\n\t| LegacyParser\n\t| StandardSchema<unknown, unknown>\n\t| (Decoder<unknown, unknown, ValidationResult<unknown> | Promise<ValidationResult<unknown>>> & {\n\t\t\treadonly kind: 'contract'\n\t })\nexport type ContractInput<S> =\n\tS extends Decoder<infer Input, unknown, unknown>\n\t\t? Input\n\t\t: S extends StandardSchema<infer Input, unknown>\n\t\t\t? Input\n\t\t\t: S extends { readonly _input: infer Input }\n\t\t\t\t? Input\n\t\t\t\t: S extends LegacyParser<infer Output>\n\t\t\t\t\t? Awaited<Output>\n\t\t\t\t\t: never\nexport type ContractOutput<S> =\n\tS extends Decoder<unknown, infer Output, unknown>\n\t\t? Output\n\t\t: S extends StandardSchema<unknown, infer Output>\n\t\t\t? Output\n\t\t\t: S extends LegacyParser<infer Output>\n\t\t\t\t? Awaited<Output>\n\t\t\t\t: never\nexport type ContractExecution<S> =\n\tS extends Decoder<unknown, unknown, infer Execution> ? Execution : never\n\n/** Validation failures are values. Throws/rejections are deliberately left as defects. */\nexport async function decodeContract<S extends NeutralSchema>(\n\tschema: S,\n\tvalue: unknown,\n): Promise<ValidationResult<ContractOutput<S>>> {\n\tlet result: ValidationResult<unknown>\n\tif ('kind' in schema) result = await schema.decode(value)\n\telse if ('parse' in schema)\n\t\tresult = { value: await (schema.parseAsync ? schema.parseAsync(value) : schema.parse(value)) }\n\telse result = await schema['~standard'].validate(value)\n\t// SAFETY: each branch returns the output associated with this exact schema.\n\treturn result as ValidationResult<ContractOutput<S>>\n}\n\n/** Independent final and wire contracts never reuse the fresh-result transform. */\nexport function operationContract<\n\tconst Input extends ContractSchema,\n\tconst Result extends ContractSchema,\n\tconst Replay extends ContractSchema,\n\tconst Wire extends ContractSchema,\n\tconst Definition extends object,\n>(\n\tdefinition: Definition & {\n\t\tinput: Input\n\t\tresult: Result\n\t\treplayResult: Replay & (ContractOutput<Replay> extends ContractOutput<Result> ? unknown : never)\n\t\twire: { project: (value: ContractOutput<Result>) => ContractInput<Wire>; schema: Wire }\n\t},\n) {\n\treturn definition\n}\n"],"mappings":"AA0DA,eAAsBA,EACrB,EACA,EAC+C,CAC/C,IAAIC,EAMJ,MALA,CAGKA,EAHD,SAAUC,EAAiB,MAAMA,EAAO,OAAOC,CAAK,EAC/C,UAAWD,EACV,CAAE,MAAO,MAAOA,EAAO,WAAaA,EAAO,WAAWC,CAAK,EAAID,EAAO,MAAMC,CAAK,EAAG,EAChF,MAAMD,EAAO,YAAY,CAAC,SAASC,CAAK,EAE/CF,CACR,CAGA,SAAgBG,EAOf,EAMC,CACD,OAAOC,CACR"}
|
|
1
|
+
{"version":3,"file":"contract.mjs","names":["decodeContract","result","schema","value","operationContract","definition"],"sources":["../../../src/modules/contracts/contract.ts"],"sourcesContent":["/* oxlint-disable anti-slop/no-unknown-parameters -- These explicit validation boundaries receive untrusted transport values before schema decoding. */\n/** Structural contracts keep the optional Effect peer out of this module. */\nexport interface StandardSchema<Input = unknown, Output = Input> {\n\treadonly '~standard': {\n\t\treadonly version: 1\n\t\treadonly vendor: string\n\t\treadonly types?: { readonly input: Input; readonly output: Output }\n\t\treadonly validate: (\n\t\t\tvalue: unknown,\n\t\t) => ValidationResult<Output> | Promise<ValidationResult<Output>>\n\t}\n}\nexport interface ValidationIssue {\n\treadonly message: string\n\treadonly path?: readonly (PropertyKey | { readonly key: PropertyKey })[]\n}\nexport type ValidationResult<Output> =\n\t| { readonly value: Output; readonly issues?: undefined }\n\t| { readonly issues: readonly ValidationIssue[] }\nexport interface LegacyParser<Output = unknown> {\n\treadonly parse: (value: unknown) => Output\n\treadonly parseAsync?: (value: unknown) => Promise<Output>\n}\n/** Decode execution is an opaque channel here; optional adapters give it concrete semantics. */\nexport interface Decoder<Input = unknown, Output = unknown, Execution = unknown> {\n\treadonly kind: 'contract' | 'effect-contract'\n\treadonly types?: { readonly input: Input; readonly output: Output }\n\treadonly decode: (value: unknown) => Execution\n}\nexport type ContractSchema = LegacyParser | StandardSchema<unknown, unknown> | Decoder\nexport type NeutralSchema =\n\t| LegacyParser\n\t| StandardSchema<unknown, unknown>\n\t| (Decoder<unknown, unknown, ValidationResult<unknown> | Promise<ValidationResult<unknown>>> & {\n\t\t\treadonly kind: 'contract'\n\t })\nexport type ContractInput<S> =\n\tS extends Decoder<infer Input, unknown, unknown>\n\t\t? Input\n\t\t: S extends StandardSchema<infer Input, unknown>\n\t\t\t? Input\n\t\t\t: S extends { readonly _input: infer Input }\n\t\t\t\t? Input\n\t\t\t\t: S extends LegacyParser<infer Output>\n\t\t\t\t\t? Awaited<Output>\n\t\t\t\t\t: never\nexport type ContractOutput<S> =\n\tS extends Decoder<unknown, infer Output, unknown>\n\t\t? Output\n\t\t: S extends StandardSchema<unknown, infer Output>\n\t\t\t? Output\n\t\t\t: S extends LegacyParser<infer Output>\n\t\t\t\t? Awaited<Output>\n\t\t\t\t: never\nexport type ContractExecution<S> =\n\tS extends Decoder<unknown, unknown, infer Execution> ? Execution : never\n\n/** Validation failures are values. Throws/rejections are deliberately left as defects. */\nexport async function decodeContract<S extends NeutralSchema>(\n\tschema: S,\n\tvalue: unknown,\n): Promise<ValidationResult<ContractOutput<S>>> {\n\tlet result: ValidationResult<unknown>\n\tif ('kind' in schema) result = await schema.decode(value)\n\telse if ('parse' in schema)\n\t\tresult = { value: await (schema.parseAsync ? schema.parseAsync(value) : schema.parse(value)) }\n\telse result = await schema['~standard'].validate(value)\n\t// SAFETY: each branch returns the output associated with this exact schema.\n\treturn result as ValidationResult<ContractOutput<S>>\n}\n\n/** Independent final and wire contracts never reuse the fresh-result transform. */\nexport function operationContract<\n\tconst Input extends ContractSchema,\n\tconst Result extends ContractSchema,\n\tconst Replay extends ContractSchema,\n\tconst Wire extends ContractSchema,\n\tconst Definition extends object,\n>(\n\tdefinition: Definition & {\n\t\tinput: Input\n\t\tresult: Result\n\t\treplayResult: Replay & (ContractOutput<Replay> extends ContractOutput<Result> ? unknown : never)\n\t\twire: { project: (value: ContractOutput<Result>) => ContractInput<Wire>; schema: Wire }\n\t},\n) {\n\treturn definition\n}\n"],"mappings":"AA0DA,eAAsBA,EACrB,EACA,EAC+C,CAC/C,IAAIC,EAMJ,MALA,CAGKA,EAHD,SAAUC,EAAiB,MAAMA,EAAO,OAAOC,CAAK,EAC/C,UAAWD,EACV,CAAE,MAAO,MAAOA,EAAO,WAAaA,EAAO,WAAWC,CAAK,EAAID,EAAO,MAAMC,CAAK,EAAG,EAChF,MAAMD,EAAO,YAAY,CAAC,SAASC,CAAK,EAE/CF,CACR,CAGA,SAAgBG,EAOf,EAMC,CACD,OAAOC,CACR,C"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ValidationResult } from "./contract.mjs";
|
|
2
|
-
import { GenericDataModel, GenericDatabaseReader } from "convex/server";
|
|
3
2
|
import { Infer, Validator } from "convex/values";
|
|
4
|
-
|
|
3
|
+
import { GenericDataModel, GenericDatabaseReader } from "convex/server";
|
|
5
4
|
/** Keep native registration authoritative, especially for actions with no db. */
|
|
6
5
|
export declare function convexContract<const V extends Validator<unknown, 'required' | 'optional', string>>(validator: V, options?: {
|
|
7
6
|
db?: GenericDatabaseReader<GenericDataModel>;
|
|
@@ -16,5 +15,4 @@ export declare function convexContract<const V extends Validator<unknown, 'requi
|
|
|
16
15
|
nativeValidator: V;
|
|
17
16
|
};
|
|
18
17
|
export type ConvexContractValue<V extends Validator<unknown, 'required' | 'optional', string>> = Infer<V>;
|
|
19
|
-
//#endregion
|
|
20
18
|
//# sourceMappingURL=convex.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convex.mjs","names":["convexContract","standardContract","toStandardSchema","validator","options"],"sources":["../../../src/modules/contracts/convex.ts"],"sourcesContent":["import type { GenericDatabaseReader, GenericDataModel } from 'convex/server'\nimport type { Infer, Validator } from 'convex/values'\nimport { toStandardSchema } from 'convex-helpers/standardSchema'\nimport { standardContract } from './standard'\n\n/** Keep native registration authoritative, especially for actions with no db. */\nexport function convexContract<const V extends Validator<unknown, 'required' | 'optional', string>>(\n\tvalidator: V,\n\toptions?: { db?: GenericDatabaseReader<GenericDataModel> },\n) {\n\treturn { ...standardContract(toStandardSchema(validator, options)), nativeValidator: validator }\n}\nexport type ConvexContractValue<V extends Validator<unknown, 'required' | 'optional', string>> =\n\tInfer<V>\n"],"mappings":"mHAMA,SAAgBA,EACf,EACA,EACC,CACD,MAAO,CAAE,GAAGC,EAAiBC,EAAiBC,EAAWC,CAAO,CAAC,EAAG,gBAAiBD,CAAU,CAChG"}
|
|
1
|
+
{"version":3,"file":"convex.mjs","names":["convexContract","standardContract","toStandardSchema","validator","options"],"sources":["../../../src/modules/contracts/convex.ts"],"sourcesContent":["import type { GenericDatabaseReader, GenericDataModel } from 'convex/server'\nimport type { Infer, Validator } from 'convex/values'\nimport { toStandardSchema } from 'convex-helpers/standardSchema'\nimport { standardContract } from './standard'\n\n/** Keep native registration authoritative, especially for actions with no db. */\nexport function convexContract<const V extends Validator<unknown, 'required' | 'optional', string>>(\n\tvalidator: V,\n\toptions?: { db?: GenericDatabaseReader<GenericDataModel> },\n) {\n\treturn { ...standardContract(toStandardSchema(validator, options)), nativeValidator: validator }\n}\nexport type ConvexContractValue<V extends Validator<unknown, 'required' | 'optional', string>> =\n\tInfer<V>\n"],"mappings":"A,mHAMA,SAAgBA,EACf,EACA,EACC,CACD,MAAO,CAAE,GAAGC,EAAiBC,EAAiBC,EAAWC,CAAO,CAAC,EAAG,gBAAiBD,CAAU,CAChG,C"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ContractInput, ContractOutput, ContractSchema } from "./contract.mjs";
|
|
2
2
|
import { ErrorContract, ErrorDefinitions } from "./errors.mjs";
|
|
3
|
-
//#region src/modules/contracts/domain.d.ts
|
|
4
3
|
/** Schema-only domain vocabulary; implementations and host policies live in registries. */
|
|
5
4
|
export type DomainOperationContract = {
|
|
6
5
|
readonly input: ContractSchema;
|
|
@@ -59,5 +58,5 @@ export type DomainAuditInput<Commands> = { [Key in Extract<keyof Commands, strin
|
|
|
59
58
|
input: ContractOutput<Commands[Key]['input']>;
|
|
60
59
|
result: ContractOutput<Commands[Key]['result']>;
|
|
61
60
|
} : never; }[Extract<keyof Commands, string>];
|
|
62
|
-
|
|
61
|
+
export {};
|
|
63
62
|
//# sourceMappingURL=domain.d.mts.map
|