Skip to content

Commit af489b8

Browse files
committed
Add suggested strategy with zodSchemaToParamSchema
1 parent 5dfd48e commit af489b8

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/lib/parse.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ export const parseUrlSearchParams = (
2222
)
2323
}
2424

25+
// TODO:
26+
// const paramSchema = zodSchemaToParamSchema(schema)
27+
// traverse paramSchema, and build a new object
28+
// for each node, lookup expected key in searchParams
29+
// if match, try to parse and include in object, otherwise, skip node
30+
31+
// TODO: For array parsing, try to lookup foo=, then foo[]= patterns,
32+
// if only one match, try to detect commas, otherwise ignore commas.
33+
// if both foo= and foo[]= this is a parse error
34+
2535
const obj: Record<string, unknown> = {}
2636
for (const [k, v] of Object.entries(
2737
schema.shape as unknown as Record<string, unknown>,

src/lib/schema.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// TODO: unsupported types (parsing error):
2+
// bigint: strings that are too big for Number
3+
// any other arrays types, e.g., boolean_array, null_array
4+
// arrays with mixed value types
5+
// arrays containing object schemas or other arrays
6+
7+
import type { ZodTypeAny } from 'zod'
8+
9+
type ValueType =
10+
| 'string'
11+
| 'number'
12+
| 'boolean'
13+
| 'date'
14+
| 'string_array'
15+
| 'number_array'
16+
17+
interface ParamSchema {
18+
[key: string]: ParamSchema | ValueType
19+
}
20+
21+
export const zodSchemaToParamSchema = (_schema: ZodTypeAny): ParamSchema => {
22+
return {}
23+
}

0 commit comments

Comments
 (0)