Skip to content

Conversation

razor-x
Copy link
Member

@razor-x razor-x commented Feb 25, 2025

  • Add @seamapi/url-search-params-serializer for testing
  • Add zod for testing
  • Add parseUrlSearchParams with failing tests

Note: consider adding a strict mode parameter that both rejects non-invertable schemas (for example record types with union value types) as well ignoring as values that would not be generated by the serializer for example the bracket array format.

@razor-x
Copy link
Member Author

razor-x commented Mar 1, 2025

@phpnode I have a minimal implementation of the parsing strategy that handles basic schemas. Let me know what you think 😄

@stale stale bot added the stale label Mar 4, 2025
@seamapi seamapi deleted a comment from stale bot Mar 4, 2025
@razor-x razor-x removed the stale label Mar 4, 2025
Comment on lines 10 to 37
### Allowed Zod Schemas

- The top-level schema must be an `z.object()` or `z.union()` of `z.object()`.
- Properties may be a `z.object()` or `z.union()` of objects.
- All union object types must flatten to a parseable object schema with non-conflicting property types.
- Primitive properties must be a `z.string()`, `z.number()`, `z.boolean()` or `z.date()`.
- Properties must be a single-value type
- The primitives `z.bigint()` and `z.symbol()` are not supported.
- Strings with zero length are not allowed.
If not specified, a `z.string()` is always assumed to be `z.string().min(1)`.
- Using `z.enum()` is allowed and equivalent to `z.string()`.
- Any property may be `z.optional()` or `z.never()`.
- No property may `z.void()`, `z.undefined()`, `z.any()`, or `z.unknown()`.
- Any property may be `z.nullable()` except `z.array()`.
- Properties that are `z.literal()` are allowed and must still obey all of these rules.
- A `z.array()` must be of a single value-type.
- The value-types must obey all the same basic rules
for primitive object, union, and property types.
- Value-types may not be `z.nullable()` or `z.undefined()`.
- The value-type cannot be an `z.array()` or contain a nested `z.array()` at any level.
- A `z.record()` has less-strict schema constraints but weaker parsing guarantees:
- They keys must be `z.string()`.
- The value-type may be a single primitive type.
- The value-type may be a union of primitives.
This union must include `z.string()`
and all values will be parsed as `z.string()`.
- The value-type may be `z.nullable()`.
- The value-type may not be a `z.record()`, `z.array()`, or `z.object()`.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phpnode Let me know if these rules make sense 🙏🏻

@stale stale bot added the stale label Mar 7, 2025
@seamapi seamapi deleted a comment from stale bot Mar 7, 2025
@razor-x razor-x removed the stale label Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants