zod_rails 0.1.5 → 0.1.6
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.
- checksums.yaml +4 -4
- data/README.md +6 -4
- data/lib/zod_rails/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b3bbdef55113e82c23ae843f93fb14074b05799036856202bc615028373993c1
|
|
4
|
+
data.tar.gz: b638454c118e1f666b971769492f5787bf4e7d20bc736dbac106b77d80689bc2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 16e639e56112401f8ffbab59263642fd0c244f5a08be5ed17b8d68eb185e7f6294d849596378eef24123f65ef4b2a79bb2e9dd71e1970154ad616288b334b8b3
|
|
7
|
+
data.tar.gz: 11adc59ed2fbab1da351ab6981ce9de6ff3830c8491e40ebe8ccc31eb5d0f9fd93ef148da41a803d8767f0be6d4f72412c640c755c4793ec4ee161a10b6fcbb5
|
data/README.md
CHANGED
|
@@ -120,6 +120,8 @@ end
|
|
|
120
120
|
| `datetime`, `timestamp` | `z.iso.datetime()` |
|
|
121
121
|
| `json`, `jsonb` | `z.json()` |
|
|
122
122
|
| `uuid` | `z.uuid()` |
|
|
123
|
+
| `time` | `z.string()` |
|
|
124
|
+
| `binary` | `z.string()` |
|
|
123
125
|
| `enum` | `z.enum([...])` |
|
|
124
126
|
|
|
125
127
|
## Validation Mappings
|
|
@@ -128,7 +130,7 @@ ZodRails introspects your model validations and maps them to Zod constraints:
|
|
|
128
130
|
|
|
129
131
|
| Rails Validation | Zod Constraint |
|
|
130
132
|
|------------------|----------------|
|
|
131
|
-
| `presence: true` | `.min(1)` for
|
|
133
|
+
| `presence: true` | `.min(1)` for string/text columns |
|
|
132
134
|
| `length: { minimum: n }` | `.min(n)` |
|
|
133
135
|
| `length: { maximum: n }` | `.max(n)` |
|
|
134
136
|
| `length: { is: n }` | `.length(n)` |
|
|
@@ -160,7 +162,7 @@ import { z } from "zod";
|
|
|
160
162
|
|
|
161
163
|
export const UserSchema = z.object({
|
|
162
164
|
id: z.int(),
|
|
163
|
-
email: z.string().min(1).regex(
|
|
165
|
+
email: z.string().min(1).regex(/^[^@\s]+@[^@\s]+$/),
|
|
164
166
|
name: z.string().min(2).max(100),
|
|
165
167
|
age: z.int().gt(0).lt(150).nullable(),
|
|
166
168
|
role: z.enum(["member", "admin", "moderator"]),
|
|
@@ -171,7 +173,7 @@ export const UserSchema = z.object({
|
|
|
171
173
|
export type User = z.infer<typeof UserSchema>;
|
|
172
174
|
|
|
173
175
|
export const UserInputSchema = z.object({
|
|
174
|
-
email: z.string().min(1).regex(
|
|
176
|
+
email: z.string().min(1).regex(/^[^@\s]+@[^@\s]+$/),
|
|
175
177
|
name: z.string().min(2).max(100),
|
|
176
178
|
age: z.int().gt(0).lt(150).nullish(),
|
|
177
179
|
role: z.enum(["member", "admin", "moderator"]).optional()
|
|
@@ -193,7 +195,7 @@ ZodRails generates two schema variants:
|
|
|
193
195
|
- Represents data for form submission
|
|
194
196
|
- Excludes configured columns (defaults: `id`, `created_at`, `updated_at`)
|
|
195
197
|
- Uses `.optional()` for columns with database defaults
|
|
196
|
-
- Uses `.nullish()` for nullable columns
|
|
198
|
+
- Uses `.nullish()` for nullable columns (accepts both `null` and `undefined`)
|
|
197
199
|
|
|
198
200
|
## Integrating with Forms
|
|
199
201
|
|
data/lib/zod_rails/version.rb
CHANGED