@formkit/zod 2.2.0 → 2.3.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/package.json +3 -3
- package/CLAUDE.md +0 -122
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formkit/zod",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Zod validation for FormKit.",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
],
|
|
37
37
|
"license": "MIT",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@formkit/core": "^2.
|
|
39
|
+
"@formkit/core": "^2.3.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@formkit/vue": "^2.
|
|
42
|
+
"@formkit/vue": "^2.3.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"zod": "^3.0.0"
|
package/CLAUDE.md
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
# @formkit/zod
|
|
2
|
-
|
|
3
|
-
Zod schema validation plugin for FormKit forms. Bridges Zod's type-safe validation with FormKit's error display system.
|
|
4
|
-
|
|
5
|
-
## Architecture
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
src/
|
|
9
|
-
index.ts # Re-exports createZodPlugin
|
|
10
|
-
zod.ts # Plugin implementation (~215 lines)
|
|
11
|
-
__tests__/
|
|
12
|
-
zod.spec.ts # Vitest tests with Vue mounting
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Key Abstractions
|
|
16
|
-
|
|
17
|
-
### Public API
|
|
18
|
-
|
|
19
|
-
- **`createZodPlugin(zodSchema, submitCallback)`**: Factory function returning `[FormKitPlugin, submitHandler]` tuple
|
|
20
|
-
- `zodSchema`: Any Zod schema (`z.ZodTypeAny`)
|
|
21
|
-
- `submitCallback`: `(payload: z.infer<typeof zodSchema>, node: FormKitNode | undefined) => void | Promise<void>`
|
|
22
|
-
- Returns: Tuple of plugin and submit handler to use with `@submit`
|
|
23
|
-
|
|
24
|
-
### Node Extension
|
|
25
|
-
|
|
26
|
-
- **`node.setZodErrors(zodError)`**: Method added to form nodes via `node.extend()`. Hydrates FormKit errors from a `z.ZodError` object. Useful for server-side validation.
|
|
27
|
-
|
|
28
|
-
### Internal Functions
|
|
29
|
-
|
|
30
|
-
- `performZodValidation()`: Runs `safeParse` and maps errors to nodes
|
|
31
|
-
- `setFormValidations()`: Distributes errors to matching nodes or form-level
|
|
32
|
-
- `zodErrorToFormKitErrors()`: Converts `z.ZodError` to `[formErrors[], fieldErrors{}]`
|
|
33
|
-
- `createMessageName()`: Resolves display name from `validationLabel > label > name`
|
|
34
|
-
|
|
35
|
-
## How It Works
|
|
36
|
-
|
|
37
|
-
1. Plugin attaches to `type="form"` nodes only (returns `false` for non-forms)
|
|
38
|
-
2. Creates ledger counter `existingValidation` to track native FormKit validation
|
|
39
|
-
3. On `commit` event: Debounced validation (150ms) with 600ms max interval
|
|
40
|
-
4. On `message-added` with `submitted` state: Immediate validation
|
|
41
|
-
5. Errors set as blocking validation messages with key pattern `{path}:zod`
|
|
42
|
-
6. When native validation appears (`existingValidation` unsettles), zod errors clear for that field
|
|
43
|
-
|
|
44
|
-
## Integration Points
|
|
45
|
-
|
|
46
|
-
- **Depends on**: `@formkit/core` (FormKitNode, FormKitPlugin, createMessage)
|
|
47
|
-
- **Peer dependency**: `zod ^3.0.0`
|
|
48
|
-
- **Dev dependency**: `@formkit/vue` (testing only)
|
|
49
|
-
- **Depended on by**: None (leaf package)
|
|
50
|
-
- **Root CLAUDE.md section**: "Addons" category
|
|
51
|
-
|
|
52
|
-
## Usage Pattern
|
|
53
|
-
|
|
54
|
-
```ts
|
|
55
|
-
import { createZodPlugin } from '@formkit/zod'
|
|
56
|
-
import { z } from 'zod'
|
|
57
|
-
|
|
58
|
-
const schema = z.object({
|
|
59
|
-
email: z.string().email(),
|
|
60
|
-
name: z.string().min(3)
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
const [zodPlugin, submitHandler] = createZodPlugin(schema, async (data) => {
|
|
64
|
-
// data is typed as z.infer<typeof schema>
|
|
65
|
-
await api.submit(data)
|
|
66
|
-
})
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
```vue
|
|
70
|
-
<FormKit type="form" :plugins="[zodPlugin]" @submit="submitHandler">
|
|
71
|
-
<FormKit name="email" />
|
|
72
|
-
<FormKit name="name" />
|
|
73
|
-
</FormKit>
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
## Modification Guide
|
|
77
|
-
|
|
78
|
-
### Adding Features
|
|
79
|
-
|
|
80
|
-
- All logic lives in `src/zod.ts`
|
|
81
|
-
- Follow existing pattern: functions inside `createZodPlugin` closure for access to `zodValidationSet` and `zodValidationListeners`
|
|
82
|
-
- New node methods: Add via `node.extend()` in the `created` event handler
|
|
83
|
-
- New TypeScript types: Extend `FormKitNodeExtensions` interface in `@formkit/core` module declaration
|
|
84
|
-
|
|
85
|
-
### Adding Tests
|
|
86
|
-
|
|
87
|
-
- Location: `__tests__/zod.spec.ts`
|
|
88
|
-
- Pattern: Mount Vue components with `@vue/test-utils`, trigger form submission, assert on DOM or spy calls
|
|
89
|
-
- Helper: `nextTick(timeout?)` for async settling
|
|
90
|
-
- Run: `pnpm test` from monorepo root
|
|
91
|
-
|
|
92
|
-
### Breaking Changes
|
|
93
|
-
|
|
94
|
-
- Changing `createZodPlugin` signature or return type
|
|
95
|
-
- Changing `setZodErrors` method signature
|
|
96
|
-
- Altering error message key format (`{path}:zod`)
|
|
97
|
-
- Modifying timing behavior (debounce/throttle values)
|
|
98
|
-
|
|
99
|
-
## Error Mapping Logic
|
|
100
|
-
|
|
101
|
-
1. Zod errors parsed via `zodError.issues`
|
|
102
|
-
2. Each issue's `path` joined with `.` (e.g., `personalInfo.firstName`)
|
|
103
|
-
3. `node.at(path)` locates target FormKit node
|
|
104
|
-
4. If node found: Error added to that node's store
|
|
105
|
-
5. If node not found: Error added to form-level errors (only on submit)
|
|
106
|
-
|
|
107
|
-
## Auto-Update Triggers
|
|
108
|
-
|
|
109
|
-
Update this CLAUDE.md when:
|
|
110
|
-
- New export added to `src/index.ts`
|
|
111
|
-
- New method added to `FormKitNodeExtensions`
|
|
112
|
-
- Validation timing logic changes
|
|
113
|
-
- Error mapping behavior changes
|
|
114
|
-
- Dependencies updated in `package.json`
|
|
115
|
-
|
|
116
|
-
## Deep Dive References
|
|
117
|
-
|
|
118
|
-
- Zod plugin implementation: `src/zod.ts`
|
|
119
|
-
- FormKit node API: `packages/core/src/node.ts`
|
|
120
|
-
- Ledger system: `packages/core/src/ledger.ts`
|
|
121
|
-
- Message creation: `packages/core/src/store.ts`
|
|
122
|
-
- Example usage: `examples/src/vue/examples/Zod.vue`
|