@gravionlabs/helix-zod 22.2.14 → 22.2.15
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 +53 -54
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,11 +9,11 @@ Zod v4 adapter for Helix forms. The validators and their keys come from `@gravio
|
|
|
9
9
|
|
|
10
10
|
## Peer Dependencies
|
|
11
11
|
|
|
12
|
-
| Package
|
|
13
|
-
|
|
14
|
-
| `zod`
|
|
15
|
-
| `@gravionlabs/helix-ui`
|
|
16
|
-
| `@angular/core` / `@angular/common` / `@angular/forms` | `>=21` (dynamic forms: `>=21.2`)
|
|
12
|
+
| Package | Version |
|
|
13
|
+
| ------------------------------------------------------ | ---------------------------------------- |
|
|
14
|
+
| `zod` | `^4.0.0` |
|
|
15
|
+
| `@gravionlabs/helix-ui` | `>=0.1.0` (the `validators` entry point) |
|
|
16
|
+
| `@angular/core` / `@angular/common` / `@angular/forms` | `>=21` (dynamic forms: `>=21.2`) |
|
|
17
17
|
|
|
18
18
|
---
|
|
19
19
|
|
|
@@ -59,16 +59,16 @@ Validation runs through signal forms' `validateStandardSchema` against the whole
|
|
|
59
59
|
|
|
60
60
|
### Widget inference
|
|
61
61
|
|
|
62
|
-
| Zod type
|
|
63
|
-
|
|
64
|
-
| `z.string()`
|
|
65
|
-
| `z.number()` / `z.int()`
|
|
66
|
-
| `z.boolean()`
|
|
67
|
-
| `z.date()`
|
|
68
|
-
| `z.enum()` / `z.literal()` | `select`
|
|
69
|
-
| `z.array()`
|
|
70
|
-
| `z.object()`
|
|
71
|
-
| `z.discriminatedUnion()`
|
|
62
|
+
| Zod type | Widget |
|
|
63
|
+
| -------------------------- | ---------------------------------------------------------------- |
|
|
64
|
+
| `z.string()` | `text` (`z.email()` → `email`) |
|
|
65
|
+
| `z.number()` / `z.int()` | `number` |
|
|
66
|
+
| `z.boolean()` | `checkbox` |
|
|
67
|
+
| `z.date()` | `date` (`Date | null` model) |
|
|
68
|
+
| `z.enum()` / `z.literal()` | `select` |
|
|
69
|
+
| `z.array()` | `array` (add/remove UI) |
|
|
70
|
+
| `z.object()` | `object` (fieldset recursion) |
|
|
71
|
+
| `z.discriminatedUnion()` | `union` (variant switcher; switching **resets** the union value) |
|
|
72
72
|
|
|
73
73
|
Anything else needs a `widget` override in its metadata pointing at a registered (custom) widget — unmapped types throw in dev mode.
|
|
74
74
|
|
|
@@ -148,10 +148,10 @@ fromZod(schema: ZodSchema, options?: ZodHelixOptions): ValidatorFn
|
|
|
148
148
|
|
|
149
149
|
**Parameters**
|
|
150
150
|
|
|
151
|
-
| Parameter | Type
|
|
152
|
-
|
|
153
|
-
| `schema`
|
|
154
|
-
| `options` | `ZodHelixOptions` | Optional configuration (see below).
|
|
151
|
+
| Parameter | Type | Description |
|
|
152
|
+
| --------- | ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
153
|
+
| `schema` | `ZodSchema` | A Zod field schema. Prefer `UserSchema.shape.email` over a full object schema. Do **not** pass schemas with `.transform()` — use the pre-transform shape for form controls. |
|
|
154
|
+
| `options` | `ZodHelixOptions` | Optional configuration (see below). |
|
|
155
155
|
|
|
156
156
|
### `ZodHelixOptions`
|
|
157
157
|
|
|
@@ -169,30 +169,30 @@ export interface ZodHelixOptions {
|
|
|
169
169
|
> This library targets **Zod v4**. Zod v4 introduced breaking changes from v3:
|
|
170
170
|
> `invalid_string` → `invalid_format` (with a `format` property), `too_small`/`too_big` use `origin` instead of `type`, and `not_integer` was replaced by `invalid_type` with `expected: 'int'`.
|
|
171
171
|
|
|
172
|
-
| Zod v4 issue code | Condition
|
|
173
|
-
|
|
174
|
-
| `invalid_type`
|
|
175
|
-
| `invalid_type`
|
|
176
|
-
| `invalid_type`
|
|
177
|
-
| `invalid_format`
|
|
178
|
-
| `invalid_format`
|
|
179
|
-
| `invalid_format`
|
|
180
|
-
| `too_small`
|
|
181
|
-
| `too_big`
|
|
182
|
-
| `too_small`
|
|
183
|
-
| `too_big`
|
|
184
|
-
| `custom`
|
|
185
|
-
| anything else
|
|
172
|
+
| Zod v4 issue code | Condition | `ValidatorKey` |
|
|
173
|
+
| ----------------- | --------------------------------------------- | ---------------------------------- |
|
|
174
|
+
| `invalid_type` | value is `''`, `null`, or `undefined` | `Required` |
|
|
175
|
+
| `invalid_type` | `expected === 'int'` | `Integer` |
|
|
176
|
+
| `invalid_type` | `expected === 'number'` / `'float'` | `Number` |
|
|
177
|
+
| `invalid_format` | `format === 'email'` | `Email` |
|
|
178
|
+
| `invalid_format` | `format === 'regex'` | `Pattern` |
|
|
179
|
+
| `invalid_format` | `format === 'datetime'` / `'date'` / `'time'` | `Date` |
|
|
180
|
+
| `too_small` | `origin === 'string'` or `'array'` | `MinLength` |
|
|
181
|
+
| `too_big` | `origin === 'string'` or `'array'` | `MaxLength` |
|
|
182
|
+
| `too_small` | `origin === 'number'` | `Min` |
|
|
183
|
+
| `too_big` | `origin === 'number'` | `Max` |
|
|
184
|
+
| `custom` | — | requires `fallbackKey` (see below) |
|
|
185
|
+
| anything else | — | requires `fallbackKey` (see below) |
|
|
186
186
|
|
|
187
187
|
All issues from a single `safeParse` are processed simultaneously, producing one error key per issue — equivalent to stacking multiple `Validators` calls.
|
|
188
188
|
|
|
189
189
|
### Known gaps — no automatic mapping
|
|
190
190
|
|
|
191
|
-
| Scenario
|
|
192
|
-
|
|
193
|
-
| `z.enum()` → `invalid_value`
|
|
194
|
-
| `z.array()` item-level errors | Use `fallbackKey` or `Validators.allOf`
|
|
195
|
-
| `invalid_type` for `boolean`
|
|
191
|
+
| Scenario | Recommendation |
|
|
192
|
+
| ----------------------------- | -------------------------------------------------- |
|
|
193
|
+
| `z.enum()` → `invalid_value` | Use `fallbackKey` or keep using `Validators.oneOf` |
|
|
194
|
+
| `z.array()` item-level errors | Use `fallbackKey` or `Validators.allOf` |
|
|
195
|
+
| `invalid_type` for `boolean` | Helix has no `Boolean` key — use `fallbackKey` |
|
|
196
196
|
|
|
197
197
|
---
|
|
198
198
|
|
|
@@ -200,11 +200,11 @@ All issues from a single `safeParse` are processed simultaneously, producing one
|
|
|
200
200
|
|
|
201
201
|
`Validators` defaults to `allowEmpty = true`: validation passes silently on empty values. `fromZod` mirrors this:
|
|
202
202
|
|
|
203
|
-
| Scenario
|
|
204
|
-
|
|
205
|
-
| Optional field with format check
|
|
206
|
-
| Mandatory field (required + format) | Stack `Validators.required('msg')` alongside `fromZod(schema)`
|
|
207
|
-
| Required via Zod only
|
|
203
|
+
| Scenario | Recommended pattern |
|
|
204
|
+
| ----------------------------------- | ---------------------------------------------------------------------------------------------- |
|
|
205
|
+
| Optional field with format check | Default `allowEmpty: true` — empty passes, invalid format shows error |
|
|
206
|
+
| Mandatory field (required + format) | Stack `Validators.required('msg')` alongside `fromZod(schema)` |
|
|
207
|
+
| Required via Zod only | `allowEmpty: false` — empty triggers `Required` (null/undefined) or `MinLength` (empty string) |
|
|
208
208
|
|
|
209
209
|
```ts
|
|
210
210
|
// Optional — empty passes, bad format shows Email error
|
|
@@ -336,7 +336,6 @@ export class RegisterComponent {
|
|
|
336
336
|
|
|
337
337
|
The same errors are on `form.controls.email.errors`, so any code that reads `control.errors` (for example a summary of all field errors) works the same way.
|
|
338
338
|
|
|
339
|
-
|
|
340
339
|
---
|
|
341
340
|
|
|
342
341
|
## `UserSchema.shape` — Single Source of Truth
|
|
@@ -386,13 +385,13 @@ Those patterns live in your application (`src/app/schemas/`, `src/app/api/`, etc
|
|
|
386
385
|
|
|
387
386
|
The library fully implements the `helix-zod` scope defined in `ZOD_ARCHITECTURE_HELIX.md §6b`:
|
|
388
387
|
|
|
389
|
-
| Plan item
|
|
390
|
-
|
|
391
|
-
| `ZodHelixOptions` interface (`fallbackKey`, `allowEmpty`) | Implemented
|
|
392
|
-
| `HelixZodValidators.fromZod()` factory
|
|
393
|
-
| Full Zod v4 issue → `ValidatorKey` mapping
|
|
394
|
-
| `allowEmpty = true` default mirroring `Validators`
|
|
395
|
-
| `ngDevMode` throw on unmapped issue without `fallbackKey` | Implemented
|
|
396
|
-
| Silent skip in production builds
|
|
397
|
-
| `z.array().min()` → `MinLength`
|
|
398
|
-
| App-level patterns (schemas, API services, Luxon)
|
|
388
|
+
| Plan item | Status |
|
|
389
|
+
| --------------------------------------------------------- | -------------------------------- |
|
|
390
|
+
| `ZodHelixOptions` interface (`fallbackKey`, `allowEmpty`) | Implemented |
|
|
391
|
+
| `HelixZodValidators.fromZod()` factory | Implemented |
|
|
392
|
+
| Full Zod v4 issue → `ValidatorKey` mapping | Implemented |
|
|
393
|
+
| `allowEmpty = true` default mirroring `Validators` | Implemented |
|
|
394
|
+
| `ngDevMode` throw on unmapped issue without `fallbackKey` | Implemented |
|
|
395
|
+
| Silent skip in production builds | Implemented |
|
|
396
|
+
| `z.array().min()` → `MinLength` | Implemented |
|
|
397
|
+
| App-level patterns (schemas, API services, Luxon) | Out of scope — application layer |
|
package/package.json
CHANGED