zodvex 0.8.0-beta.0 → 0.8.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +78 -107
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +604 -1364
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/inspect-schema/census.mjs +112 -0
- package/dist/cli/inspect-schema/inspect-worker.mjs +24 -0
- package/dist/cli/inspect-schema/inspect.mjs +177 -0
- package/dist/client/index.js +106 -24
- package/dist/client/index.js.map +1 -1
- package/dist/codegen/index.js +373 -508
- package/dist/codegen/index.js.map +1 -1
- package/dist/core/index.js +312 -253
- package/dist/core/index.js.map +1 -1
- package/dist/index.js +312 -253
- package/dist/index.js.map +1 -1
- package/dist/internal/actionCtx.d.ts.map +1 -1
- package/dist/internal/boundaryHelpers.d.ts +12 -15
- package/dist/internal/boundaryHelpers.d.ts.map +1 -1
- package/dist/internal/codec.d.ts +4 -0
- package/dist/internal/codec.d.ts.map +1 -1
- package/dist/internal/customization.d.ts +33 -15
- package/dist/internal/customization.d.ts.map +1 -1
- package/dist/internal/db.d.ts +174 -29
- package/dist/internal/db.d.ts.map +1 -1
- package/dist/internal/functions/contracts.d.ts +66 -0
- package/dist/internal/functions/contracts.d.ts.map +1 -0
- package/dist/internal/{custom.d.ts → functions/customFunctions.d.ts} +32 -30
- package/dist/internal/functions/customFunctions.d.ts.map +1 -0
- package/dist/internal/{init.d.ts → functions/init.d.ts} +69 -66
- package/dist/internal/functions/init.d.ts.map +1 -0
- package/dist/internal/ids.d.ts +1 -1
- package/dist/internal/ids.d.ts.map +1 -1
- package/dist/internal/{builders.d.ts → legacy/builders.d.ts} +2 -2
- package/dist/internal/legacy/builders.d.ts.map +1 -0
- package/dist/internal/{wrappers.d.ts → legacy/wrappers.d.ts} +2 -2
- package/dist/internal/legacy/wrappers.d.ts.map +1 -0
- package/dist/internal/model.d.ts +105 -6
- package/dist/internal/model.d.ts.map +1 -1
- package/dist/internal/modelSchemaBundle.d.ts.map +1 -1
- package/dist/internal/paginationCodec.d.ts +8 -0
- package/dist/internal/paginationCodec.d.ts.map +1 -0
- package/dist/internal/registry.d.ts +7 -2
- package/dist/internal/registry.d.ts.map +1 -1
- package/dist/internal/schema/id.d.ts +29 -0
- package/dist/internal/schema/id.d.ts.map +1 -0
- package/dist/internal/schema.d.ts +13 -55
- package/dist/internal/schema.d.ts.map +1 -1
- package/dist/internal/schemaHelpers.d.ts +1 -1
- package/dist/internal/schemaHelpers.d.ts.map +1 -1
- package/dist/internal/stream.d.ts +110 -0
- package/dist/internal/stream.d.ts.map +1 -0
- package/dist/internal/zx.d.ts +2 -28
- package/dist/internal/zx.d.ts.map +1 -1
- package/dist/internal/zxDateBrand.d.ts +5 -0
- package/dist/internal/zxDateBrand.d.ts.map +1 -0
- package/dist/labs/index.js +122 -78
- package/dist/labs/index.js.map +1 -1
- package/dist/legacy/index.d.ts +1 -1
- package/dist/legacy/index.d.ts.map +1 -1
- package/dist/legacy/index.js +101 -293
- package/dist/legacy/index.js.map +1 -1
- package/dist/mini/client/index.js +106 -24
- package/dist/mini/client/index.js.map +1 -1
- package/dist/mini/index.js +312 -253
- package/dist/mini/index.js.map +1 -1
- package/dist/mini/react/index.js +143 -23
- package/dist/mini/react/index.js.map +1 -1
- package/dist/mini/server/index.js +1210 -1202
- package/dist/mini/server/index.js.map +1 -1
- package/dist/public/cli/commands.d.ts.map +1 -1
- package/dist/public/cli/index.d.ts +1 -1
- package/dist/public/cli/init.d.ts +1 -2
- package/dist/public/cli/init.d.ts.map +1 -1
- package/dist/public/cli/migrate.d.ts.map +1 -1
- package/dist/public/client/index.d.ts +1 -1
- package/dist/public/client/index.d.ts.map +1 -1
- package/dist/public/client/zodvexClient.d.ts +23 -9
- package/dist/public/client/zodvexClient.d.ts.map +1 -1
- package/dist/public/codegen/discover.d.ts +0 -44
- package/dist/public/codegen/discover.d.ts.map +1 -1
- package/dist/public/codegen/discovery-hooks.d.ts +2 -1
- package/dist/public/codegen/discovery-hooks.d.ts.map +1 -1
- package/dist/public/codegen/extractCodec.d.ts.map +1 -1
- package/dist/public/codegen/generate.d.ts +6 -79
- package/dist/public/codegen/generate.d.ts.map +1 -1
- package/dist/public/codegen/index.d.ts +1 -1
- package/dist/public/codegen/index.d.ts.map +1 -1
- package/dist/public/codegen/tsconfigPaths.d.ts +41 -0
- package/dist/public/codegen/tsconfigPaths.d.ts.map +1 -0
- package/dist/public/codegen/zodToSource.d.ts.map +1 -1
- package/dist/public/mini/index.d.ts +1 -1
- package/dist/public/mini/index.d.ts.map +1 -1
- package/dist/public/mini/model.d.ts +53 -3
- package/dist/public/mini/model.d.ts.map +1 -1
- package/dist/public/model.d.ts +53 -3
- package/dist/public/model.d.ts.map +1 -1
- package/dist/public/react/hooks.d.ts +28 -2
- package/dist/public/react/hooks.d.ts.map +1 -1
- package/dist/public/react/index.d.ts +1 -1
- package/dist/public/react/index.d.ts.map +1 -1
- package/dist/public/react/zodvexReactClient.d.ts.map +1 -1
- package/dist/public/server/index.d.ts +7 -6
- package/dist/public/server/index.d.ts.map +1 -1
- package/dist/react/index.js +143 -23
- package/dist/react/index.js.map +1 -1
- package/dist/server/index.js +1210 -1202
- package/dist/server/index.js.map +1 -1
- package/package.json +8 -4
- package/src/cli/index.ts +1 -1
- package/src/internal/actionCtx.ts +9 -14
- package/src/internal/boundaryHelpers.ts +44 -14
- package/src/internal/codec.ts +36 -8
- package/src/internal/customization.ts +84 -32
- package/src/internal/db.ts +819 -63
- package/src/internal/functions/contracts.ts +313 -0
- package/src/internal/{custom.ts → functions/customFunctions.ts} +173 -151
- package/src/internal/{init.ts → functions/init.ts} +202 -187
- package/src/internal/ids.ts +11 -4
- package/src/internal/{builders.ts → legacy/builders.ts} +38 -65
- package/src/internal/{wrappers.ts → legacy/wrappers.ts} +6 -14
- package/src/internal/mapping/types.ts +2 -2
- package/src/internal/model.ts +312 -76
- package/src/internal/modelSchemaBundle.ts +2 -2
- package/src/internal/paginationCodec.ts +60 -0
- package/src/internal/registry.ts +50 -3
- package/src/internal/schema/id.ts +52 -0
- package/src/internal/schema.ts +45 -78
- package/src/internal/schemaHelpers.ts +3 -3
- package/src/internal/stream.ts +242 -0
- package/src/internal/types.ts +2 -2
- package/src/internal/zx.ts +15 -60
- package/src/internal/zxDateBrand.ts +34 -0
- package/src/legacy/index.ts +1 -1
- package/src/public/cli/commands.ts +59 -180
- package/src/public/cli/index.ts +16 -1
- package/src/public/cli/init.ts +3 -16
- package/src/public/cli/inspect-schema/census.mjs +112 -0
- package/src/public/cli/inspect-schema/inspect-worker.mjs +24 -0
- package/src/public/cli/inspect-schema/inspect.mjs +177 -0
- package/src/public/cli/migrate.ts +0 -120
- package/src/public/client/index.ts +1 -1
- package/src/public/client/zodvexClient.ts +74 -22
- package/src/public/codegen/discover.ts +34 -148
- package/src/public/codegen/discovery-hooks.ts +73 -8
- package/src/public/codegen/extractCodec.ts +5 -11
- package/src/public/codegen/generate.ts +45 -719
- package/src/public/codegen/index.ts +0 -1
- package/src/public/codegen/tsconfigPaths.ts +224 -0
- package/src/public/codegen/zodToSource.ts +17 -10
- package/src/public/mini/index.ts +2 -0
- package/src/public/mini/model.ts +89 -3
- package/src/public/model.ts +89 -3
- package/src/public/react/hooks.ts +145 -16
- package/src/public/react/index.ts +1 -1
- package/src/public/react/zodvexReactClient.ts +6 -2
- package/src/public/server/index.ts +51 -35
- package/dist/internal/builders.d.ts.map +0 -1
- package/dist/internal/custom.d.ts.map +0 -1
- package/dist/internal/functionContracts.d.ts +0 -60
- package/dist/internal/functionContracts.d.ts.map +0 -1
- package/dist/internal/init.d.ts.map +0 -1
- package/dist/internal/ruleTypes.d.ts +0 -104
- package/dist/internal/ruleTypes.d.ts.map +0 -1
- package/dist/internal/rules.d.ts +0 -27
- package/dist/internal/rules.d.ts.map +0 -1
- package/dist/internal/wrappers.d.ts.map +0 -1
- package/src/internal/functionContracts.ts +0 -270
- package/src/internal/ruleTypes.ts +0 -120
- package/src/internal/rules.ts +0 -779
package/README.md
CHANGED
|
@@ -2,43 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
#### [Zod](https://zod.dev/) + [Convex](https://www.convex.dev/)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
- [Why zodvex?](#why-zodvex)
|
|
12
|
-
- [Installation](#installation)
|
|
13
|
-
- [Quick Start](#quick-start)
|
|
14
|
-
- [Import Paths](#import-paths)
|
|
15
|
-
- [Features](#features)
|
|
16
|
-
- [Codec-Aware Database](#codec-aware-database)
|
|
17
|
-
- [Codegen & Client-Side Schema Sharing](#codegen--client-side-schema-sharing)
|
|
18
|
-
- [Using zodvex Without Codecs](#using-zodvex-without-codecs)
|
|
19
|
-
- [Supported Types](#supported-types)
|
|
20
|
-
- [Upgrading?](#upgrading)
|
|
21
|
-
- [API Reference](#api-reference)
|
|
22
|
-
- [Roadmap](#roadmap)
|
|
23
|
-
- [License](#license)
|
|
5
|
+
Use Zod v4 as your schema language for Convex — define your data once and use it end to end, with automatic function validation and a codec-aware database.
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/zodvex)
|
|
8
|
+
[](https://github.com/panzacoder/zodvex/actions/workflows/ci.yml)
|
|
9
|
+
[](./LICENSE)
|
|
24
10
|
|
|
25
11
|
## Why zodvex?
|
|
26
12
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
- **
|
|
30
|
-
|
|
13
|
+
**Your Zod schemas are the source of truth** — tables, function arguments, and return types defined once, used database to frontend. Two things make that real:
|
|
14
|
+
|
|
15
|
+
- **Functions execute your Zod schemas.** Wrappers parse declared arguments before the handler and encode declared returns. Zod refinements and codec logic run alongside Convex’s structural checks. Parsing and encoding have different transform/default behavior; current wrappers use synchronous Zod operations.
|
|
16
|
+
|
|
17
|
+
- **Modeled database reads run full Zod validation.** The wrapped `ctx.db` parses modeled documents on reads and encodes insert/replace values through the model schema. Codecs live in the schema itself, so handlers can work with `Date` objects while Convex stores plain values.
|
|
31
18
|
|
|
32
|
-
|
|
33
|
-
|---------|--------|---------------------|
|
|
34
|
-
| Codec-aware DB | `initZodvex` wraps `ctx.db` automatically | Manual |
|
|
35
|
-
| Date handling | `zx.date()` — automatic Date ↔ timestamp | Manual `z.codec()` |
|
|
36
|
-
| Typed IDs | `zx.id('table')` with type branding | Manual |
|
|
37
|
-
| Custom codecs | `zx.codec()` with auto-detection | Not provided |
|
|
38
|
-
| Client-safe models | `defineZodModel` (importable in React) | Not provided |
|
|
39
|
-
| Codegen | Optional typed hooks, boundary helpers | Not provided |
|
|
19
|
+
What you gain over Convex out of the box:
|
|
40
20
|
|
|
41
|
-
|
|
21
|
+
| | Convex | with zodvex |
|
|
22
|
+
|---|---|---|
|
|
23
|
+
| Type safety | end-to-end inference | same — driven by your Zod schemas |
|
|
24
|
+
| Runtime validation | structural checks | Zod parsing/encoding for declared function schemas and modeled data |
|
|
25
|
+
| End-to-end validation | per-function validators | shared Zod definitions across configured client, function, and database paths |
|
|
26
|
+
| Client calls | `useQuery(api.fn)` infers types | registry args encoded and results parsed, with a configurable decode-error policy |
|
|
27
|
+
| Dates & custom types | `number` timestamps | `Date` objects and custom codecs (`zx.date()`, `zx.codec()`) |
|
|
28
|
+
| Rows on read | as stored | modeled documents parsed & decoded through your schema |
|
|
29
|
+
| Row-level rules & audit | build your own | `.withRules()` / `.audit()` on `ctx.db` |
|
|
30
|
+
|
|
31
|
+
All of it wired once with `initZodvex` — see [Features](#features).
|
|
42
32
|
|
|
43
33
|
## Installation
|
|
44
34
|
|
|
@@ -72,7 +62,9 @@ export const EventModel = defineZodModel('events', {
|
|
|
72
62
|
|
|
73
63
|
> `defineZodModel` is client-safe — you can import it in React.
|
|
74
64
|
|
|
75
|
-
### Step 2.
|
|
65
|
+
### Step 2. Wire it up
|
|
66
|
+
|
|
67
|
+
Two one-time files: build your Convex schema from your models, and create your function builders.
|
|
76
68
|
|
|
77
69
|
```ts
|
|
78
70
|
// convex/schema.ts
|
|
@@ -84,8 +76,6 @@ export default defineZodSchema({
|
|
|
84
76
|
})
|
|
85
77
|
```
|
|
86
78
|
|
|
87
|
-
### Step 3. Set up builders
|
|
88
|
-
|
|
89
79
|
```ts
|
|
90
80
|
// convex/functions.ts
|
|
91
81
|
import { initZodvex } from 'zodvex/server'
|
|
@@ -101,9 +91,9 @@ export const { zq, zm, za, ziq, zim, zia } = initZodvex(schema, {
|
|
|
101
91
|
})
|
|
102
92
|
```
|
|
103
93
|
|
|
104
|
-
`initZodvex` returns builders for all six Convex function types
|
|
94
|
+
`initZodvex` returns builders for all six Convex function types, with `ctx.db` wrapped for automatic codec encode/decode. You write these two files once and rarely touch them again.
|
|
105
95
|
|
|
106
|
-
### Step
|
|
96
|
+
### Step 3. Write functions
|
|
107
97
|
|
|
108
98
|
```ts
|
|
109
99
|
// convex/events.ts
|
|
@@ -114,7 +104,7 @@ import { EventModel } from './models'
|
|
|
114
104
|
|
|
115
105
|
export const list = zq({
|
|
116
106
|
args: {},
|
|
117
|
-
returns:
|
|
107
|
+
returns: zx.docArray(EventModel),
|
|
118
108
|
handler: async (ctx) => {
|
|
119
109
|
// Dates come back as Date objects, not numbers
|
|
120
110
|
return await ctx.db.query('events').collect()
|
|
@@ -136,42 +126,75 @@ export const create = zm({
|
|
|
136
126
|
})
|
|
137
127
|
```
|
|
138
128
|
|
|
139
|
-
> `zx.id('events')` is a typed
|
|
129
|
+
> `zx.id('events')` is a typed ID validator — branding only, no wire transform. `zx.date()` and `zx.codec()` are codecs. Details in [Features](#features).
|
|
140
130
|
|
|
141
131
|
See the full [quickstart example](./examples/quickstart/) for a runnable project.
|
|
142
132
|
|
|
143
133
|
## Import Paths
|
|
144
134
|
|
|
145
|
-
Four entry points:
|
|
135
|
+
Four primary entry points:
|
|
146
136
|
|
|
147
137
|
- **`zodvex`** — Client-safe full-Zod surface. Use in React components and shared code.
|
|
148
138
|
- **`zodvex/server`** — Server-only. Use in Convex functions and schema definitions.
|
|
149
139
|
- **`zodvex/mini`** — Client-safe zod/mini surface.
|
|
150
140
|
- **`zodvex/mini/server`** — Server-only zod/mini surface.
|
|
151
|
-
- **`zodvex/legacy`** — Deprecated runtime APIs kept only for migration.
|
|
152
141
|
|
|
153
|
-
|
|
142
|
+
Focused entrypoints — `zodvex/react`, `zodvex/client`, `zodvex/codegen` (and their `zodvex/mini` variants) — back the codegen workflow and are mostly consumed by generated code; see [Codegen](#codegen--client-side-schema-sharing).
|
|
143
|
+
|
|
144
|
+
Two deprecated paths remain for migration only:
|
|
145
|
+
|
|
146
|
+
- **`zodvex/legacy`** — Deprecated runtime APIs kept only for migration.
|
|
147
|
+
- **`zodvex/core`** — Deprecated compatibility alias for `zodvex`.
|
|
154
148
|
|
|
155
149
|
## Features
|
|
156
150
|
|
|
157
151
|
### Codec-Aware Database
|
|
158
152
|
|
|
159
|
-
`initZodvex` wraps `ctx.db` so reads decode automatically and
|
|
153
|
+
`initZodvex` wraps `ctx.db` so modeled reads decode automatically and insert/replace values encode automatically. Codecs are opt-in per field — schemas without them get the same validation, typed IDs, and correct optional/nullable mapping through the exact same setup.
|
|
160
154
|
|
|
161
155
|
- **`zx.date()`** — Date ↔ timestamp codec. Stored as `v.float64()`, used as `Date` in handlers.
|
|
162
156
|
- **`zx.codec(wire, runtime, transforms)`** — Custom codecs for complex transformations (encryption, serialization, etc.).
|
|
163
|
-
- **`zx.id('table')`** — Typed Convex ID validator with `GenericId<T>` branding
|
|
157
|
+
- **`zx.id('table')`** — Typed Convex ID validator with `GenericId<T>` branding — no wire transform (not a codec).
|
|
158
|
+
|
|
159
|
+
Object patches encode supplied fields without validating the merged document or retaining outer object refinements; union patches use full encoding. Unmodeled tables and system access pass through. `unwrap()` or `wrapDb: false` bypass wrapping. See the [boundary contract](./docs/decisions/2026-09-07-boundary-contract.md).
|
|
164
160
|
|
|
165
161
|
Guides: [Custom Codecs](./docs/guide/custom-codecs.md), [Date Handling](./docs/guide/date-handling.md)
|
|
166
162
|
|
|
163
|
+
### Row-Level Rules & Audit
|
|
164
|
+
|
|
165
|
+
The same wrapped `ctx.db` carries per-row rules and audit hooks. Modeled reads and supplied write values use decoded runtime types:
|
|
166
|
+
|
|
167
|
+
- **`.withRules(ruleCtx, rules)`** — gate and transform reads and writes per table (`read`, `insert`, `patch`, `replace`, `delete`), with an optional deny-by-default policy.
|
|
168
|
+
- **`.audit({ afterRead, afterWrite })`** — observe completed inner reads and writes. Composition order determines what audit sees; an audit layer outside `.withRules()` observes the rules-processed results.
|
|
169
|
+
|
|
170
|
+
Guide: [Rules & Audit](./docs/guide/rules-and-audit.md)
|
|
171
|
+
|
|
172
|
+
### Composable with Triggers
|
|
173
|
+
|
|
174
|
+
The codec wrapper can delegate to an underlying db you supply, so `ctx.db`-wrapping libraries like `convex-helpers/server/triggers` compose instead of colliding — codec on top, triggers underneath, real db at the bottom:
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
const triggers = new Triggers<DataModel>()
|
|
178
|
+
export const { zq, zm, zim /* ... */ } = initZodvex(schema, server, {
|
|
179
|
+
underlyingDb: { mutation: (ctx) => triggers.wrapDB(ctx).db },
|
|
180
|
+
})
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Triggers fire inside zodvex mutations and observe native wire-format writes — which unlocks the aggregate component's table-trigger mode, model-bound cascades, and similar reactive patterns. `ctx.db.unwrap()` is the matching escape hatch for direct access to the underlying db.
|
|
184
|
+
|
|
185
|
+
Guide: [Builders — Composing with triggers](./docs/guide/builders.md#composing-with-convex-helpers-triggers-underlyingdb)
|
|
186
|
+
|
|
167
187
|
### Codegen & Client-Side Schema Sharing
|
|
168
188
|
|
|
169
189
|
zodvex includes an optional CLI that generates typed client code:
|
|
170
190
|
|
|
171
|
-
- **Typed hooks** — `useZodQuery`, `useZodMutation`
|
|
191
|
+
- **Typed hooks** — `useZodQuery`, `useZodMutation`, generated into `convex/_zodvex/client` — import them from there; args are encoded and results decoded automatically
|
|
192
|
+
Invalid query arguments throw during render and can be handled by a React error boundary. Pass `'skip'` explicitly while required inputs are unavailable; encoding failures no longer silently look like a loading query.
|
|
172
193
|
- **Boundary helpers** — `encodeArgs`, `decodeResult` for custom client integrations
|
|
173
194
|
- **Cross-function auto-codec** — `ctx.runQuery` / `ctx.runMutation` encode args + decode results, and `ctx.scheduler.runAfter` / `ctx.scheduler.runAt` encode args, via the registry. Pass natural decoded values; zodvex encodes them to wire at the call site.
|
|
174
195
|
|
|
196
|
+
Registry-backed clients and outbound helpers warn and return raw wire data when result parsing fails by default; use `onDecodeError: 'throw'` to reject failed result parses. Missing registry schemas pass through unchanged.
|
|
197
|
+
|
|
175
198
|
```bash
|
|
176
199
|
zodvex generate # one-shot generation
|
|
177
200
|
zodvex dev # watch mode
|
|
@@ -183,20 +206,6 @@ zodvex dev # watch mode
|
|
|
183
206
|
|
|
184
207
|
Guides: [Codegen](./docs/guide/codegen.md) | Example: [examples/task-manager/](./examples/task-manager/)
|
|
185
208
|
|
|
186
|
-
### Using zodvex Without Codecs
|
|
187
|
-
|
|
188
|
-
`zodTable` and `zQueryBuilder` still work without `initZodvex`:
|
|
189
|
-
|
|
190
|
-
```ts
|
|
191
|
-
import { zodTable, zQueryBuilder } from 'zodvex/legacy'
|
|
192
|
-
import { query } from './_generated/server'
|
|
193
|
-
|
|
194
|
-
const Users = zodTable('users', { name: z.string() })
|
|
195
|
-
const zq = zQueryBuilder(query)
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
At this level, zodvex is roughly equivalent to convex-helpers. This is a valid stepping-stone, but the API is deprecated. When you're ready for codecs, see the [Quick Start](#quick-start) above.
|
|
199
|
-
|
|
200
209
|
## Supported Types
|
|
201
210
|
|
|
202
211
|
| Zod Type | Convex Validator |
|
|
@@ -217,52 +226,13 @@ At this level, zodvex is roughly equivalent to convex-helpers. This is a valid s
|
|
|
217
226
|
|
|
218
227
|
> **Note:** Native `z.date()` is **not supported** — use `zx.date()` instead. See [Date Handling](./docs/guide/date-handling.md) for details.
|
|
219
228
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
¹ Enum types in Zod v4 produce a slightly different TypeScript signature than manually created unions:
|
|
223
|
-
|
|
224
|
-
```typescript
|
|
225
|
-
// Manual union (precise tuple type)
|
|
226
|
-
const manual = v.union(v.literal('a'), v.literal('b'))
|
|
227
|
-
// Type: VUnion<"a" | "b", [VLiteral<"a", "required">, VLiteral<"b", "required">], "required", never>
|
|
228
|
-
|
|
229
|
-
// From Zod enum (array type)
|
|
230
|
-
const fromZod = zodToConvex(z.enum(['a', 'b']))
|
|
231
|
-
// Type: VUnion<"a" | "b", Array<VLiteral<"a" | "b", "required">>, "required", never>
|
|
232
|
-
```
|
|
229
|
+
¹ Enum unions carry a cosmetically different TypeScript signature than hand-written `v.union(v.literal(...))` calls — identical values, runtime validation, and type safety. Details: [Mapping Helpers](./docs/guide/mapping-helpers.md#zod-v4-enum-type-note).
|
|
233
230
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
- Value types are identical (`"a" | "b"`)
|
|
237
|
-
- Runtime validation is identical
|
|
238
|
-
- Type safety for function arguments/returns is preserved
|
|
239
|
-
- Convex uses `T[number]` which works identically for both array and tuple types
|
|
240
|
-
|
|
241
|
-
This limitation exists because Zod v4 changed enum types from tuple-based to Record-based ([`ToEnum<T>`](https://github.com/colinhacks/zod/blob/v4/src/v4/core/util.ts#L83-L85)). TypeScript cannot convert a Record type to a specific tuple without knowing the keys at compile time. See [Zod v4 changelog](https://zod.dev/v4/changelog) and [enum evolution discussion](https://github.com/colinhacks/zod/discussions/2125) for more details.
|
|
242
|
-
|
|
243
|
-
**zx namespace types:**
|
|
244
|
-
|
|
245
|
-
```ts
|
|
246
|
-
import { zx } from 'zodvex'
|
|
247
|
-
|
|
248
|
-
// Convex IDs — typed validator, NOT a codec
|
|
249
|
-
zx.id('tableName') // → v.id('tableName')
|
|
250
|
-
zx.id('tableName').optional() // → v.optional(v.id('tableName'))
|
|
251
|
-
|
|
252
|
-
// Dates — codec (Date ↔ timestamp)
|
|
253
|
-
zx.date() // → v.float64() (timestamp)
|
|
254
|
-
zx.date().optional() // → v.optional(v.float64())
|
|
255
|
-
zx.date().nullable() // → v.union(v.float64(), v.null())
|
|
256
|
-
|
|
257
|
-
// Custom codecs
|
|
258
|
-
zx.codec(wireSchema, runtimeSchema, { encode, decode })
|
|
259
|
-
```
|
|
231
|
+
For zodvex's own types — `zx.id()`, `zx.date()`, `zx.codec()` — and exactly how they map to Convex validators, see [The zx Namespace](./docs/guide/zx-namespace.md).
|
|
260
232
|
|
|
261
233
|
## Upgrading?
|
|
262
234
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
Automated renames are available:
|
|
235
|
+
Read the [migration guide](./MIGRATION.md) for what changed in each release and why. Automated renames are available:
|
|
266
236
|
|
|
267
237
|
```bash
|
|
268
238
|
npx zodvex migrate ./convex # apply renames
|
|
@@ -273,7 +243,8 @@ npx zodvex migrate ./convex --dry-run # preview changes
|
|
|
273
243
|
|
|
274
244
|
- [The zx Namespace](./docs/guide/zx-namespace.md) — `zx.id()`, `zx.date()`, `zx.codec()`
|
|
275
245
|
- [Builders](./docs/guide/builders.md) — `initZodvex` and legacy builders
|
|
276
|
-
- [Custom Context](./docs/guide/custom-context.md) — `.withContext()`, `onSuccess`
|
|
246
|
+
- [Custom Context](./docs/guide/custom-context.md) — `.withContext()`, `defineContext`, `onSuccess`
|
|
247
|
+
- [Rules & Audit](./docs/guide/rules-and-audit.md) — `.withRules()`, `.audit()` on `ctx.db`
|
|
277
248
|
- [Custom Codecs](./docs/guide/custom-codecs.md) — `zx.codec()`, `decodeDoc`/`encodeDoc`
|
|
278
249
|
- [Date Handling](./docs/guide/date-handling.md) — `zx.date()` deep dive
|
|
279
250
|
- [Form Validation](./docs/guide/form-validation.md) — react-hook-form integration
|
|
@@ -281,16 +252,16 @@ npx zodvex migrate ./convex --dry-run # preview changes
|
|
|
281
252
|
- [Mapping Helpers](./docs/guide/mapping-helpers.md) — `zodToConvex`, `zodToConvexFields`
|
|
282
253
|
- [Return Type Helpers](./docs/guide/return-type-helpers.md) — `returnsAs`
|
|
283
254
|
- [Large Schemas](./docs/guide/large-schemas.md) — `pickShape`, `safePick`
|
|
255
|
+
- [Staged Indexes](./docs/guide/staged-indexes.md) — `{ staged: true }` on `index`, `searchIndex`, `vectorIndex`
|
|
284
256
|
- [Polymorphic Tables](./docs/guide/polymorphic-tables.md) — Union/discriminated union tables
|
|
257
|
+
- [Streams](./docs/guide/streams.md) — `zodvexStream`, `zodvexMergedStream` for fan-out pagination
|
|
285
258
|
- [AI SDK Compatibility](./docs/guide/ai-sdk.md) — Vercel AI SDK integration
|
|
286
259
|
- [Codegen](./docs/guide/codegen.md) — CLI, registry, typed hooks
|
|
260
|
+
- [Schema Diagnostics](./docs/guide/schema-diagnostics.md) — local aggregate reports for support
|
|
287
261
|
|
|
288
262
|
## Roadmap
|
|
289
263
|
|
|
290
|
-
|
|
291
|
-
- Migration tooling: pre-0.5 → current zodvex
|
|
292
|
-
- Additional example projects (e.g., full-stack with React, codegen showcase)
|
|
293
|
-
- Per-feature READMEs in examples/task-manager/
|
|
264
|
+
See the [roadmap](./docs/roadmap.md) for where zodvex is heading — deploy-scale performance, ecosystem interop, and the model/namespace evolution.
|
|
294
265
|
|
|
295
266
|
## License
|
|
296
267
|
|
|
@@ -298,4 +269,4 @@ MIT
|
|
|
298
269
|
|
|
299
270
|
---
|
|
300
271
|
|
|
301
|
-
Built with ❤️
|
|
272
|
+
Built with ❤️ for the [Convex](https://www.convex.dev/) ecosystem. Thanks to [convex-helpers](https://github.com/get-convex/convex-helpers) for the early foundations.
|
package/dist/cli/index.d.ts
CHANGED