@@ -7,13 +7,18 @@ Parses URLSearchParams to JavaScript objects according to Zod schemas.
7
7
8
8
## Description
9
9
10
+ The set of allowed Zod schemas is restricted to ensure the parsing is unambiguous.
11
+ This parser may be used as a true inverse operation to [ @seamapi/url-search-params-serializer ] .
12
+
13
+ [ @url-search-params-serializer ] : https://github.com/seamapi/url-search-params-serializer
14
+
10
15
### Allowed Zod Schemas
11
16
12
17
- The top-level schema must be an ` z.object() ` or ` z.union() ` of ` z.object() ` .
13
18
- Properties may be a ` z.object() ` or ` z.union() ` of objects.
14
19
- All union object types must flatten to a parseable object schema with non-conflicting property types.
15
20
- Primitive properties must be a ` z.string() ` , ` z.number() ` , ` z.boolean() ` or ` z.date() ` .
16
- - Properties must be a single-value type
21
+ - Properties must be a single-value type.
17
22
- The primitives ` z.bigint() ` and ` z.symbol() ` are not supported.
18
23
- Strings with zero length are not allowed.
19
24
If not specified, a ` z.string() ` is always assumed to be ` z.string().min(1) ` .
@@ -26,15 +31,18 @@ Parses URLSearchParams to JavaScript objects according to Zod schemas.
26
31
- The value-types must obey all the same basic rules
27
32
for primitive object, union, and property types.
28
33
- Value-types may not be ` z.nullable() ` or ` z.undefined() ` .
34
+ - The value-type cannot be a ` z.object() ` .
29
35
- The value-type cannot be an ` z.array() ` or contain a nested ` z.array() ` at any level.
30
36
- A ` z.record() ` has less-strict schema constraints but weaker parsing guarantees:
31
37
- They keys must be ` z.string() ` .
32
38
- The value-type may be a single primitive type.
33
- - The value-type may be a union of primitives.
34
- This union must include ` z.string() `
35
- and all values will be parsed as ` z.string() ` .
36
39
- The value-type may be ` z.nullable() ` .
37
40
- The value-type may not be a ` z.record() ` , ` z.array() ` , or ` z.object() ` .
41
+ This restriction is not strictly necessary,
42
+ but a deliberate choice not to support such schemas in this version.
43
+ - The value-type may be a union of primitive types,
44
+ but this union must include ` z.string() ` and all values will be parsed as ` z.string() ` .
45
+ For schemas of this type, the parser is no longer a true inverse of the serialization.
38
46
39
47
## Installation
40
48
0 commit comments