Skip to content

Commit 40ffb39

Browse files
committed
Extend README
1 parent 753923d commit 40ffb39

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@ Parses URLSearchParams to JavaScript objects according to Zod schemas.
77

88
## Description
99

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+
1015
### Allowed Zod Schemas
1116

1217
- The top-level schema must be an `z.object()` or `z.union()` of `z.object()`.
1318
- Properties may be a `z.object()` or `z.union()` of objects.
1419
- All union object types must flatten to a parseable object schema with non-conflicting property types.
1520
- 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.
1722
- The primitives `z.bigint()` and `z.symbol()` are not supported.
1823
- Strings with zero length are not allowed.
1924
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.
2631
- The value-types must obey all the same basic rules
2732
for primitive object, union, and property types.
2833
- Value-types may not be `z.nullable()` or `z.undefined()`.
34+
- The value-type cannot be a `z.object()`.
2935
- The value-type cannot be an `z.array()` or contain a nested `z.array()` at any level.
3036
- A `z.record()` has less-strict schema constraints but weaker parsing guarantees:
3137
- They keys must be `z.string()`.
3238
- 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()`.
3639
- The value-type may be `z.nullable()`.
3740
- 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.
3846

3947
## Installation
4048

0 commit comments

Comments
 (0)