MCPcopy Create free account
hub / github.com/ProNextJS/declarative-routing / processSchema

Function processSchema

assets/shared/utils.ts:13–47  ·  view source on GitHub ↗
(
  schema: z.ZodTypeAny,
  paramsArray: Record<string, string[]>
)

Source from the content-addressed store, hash-verified

11}
12
13function processSchema(
14 schema: z.ZodTypeAny,
15 paramsArray: Record<string, string[]>
16): Record<string, any> {
17 if (schema instanceof z.ZodOptional) {
18 schema = schema._def.innerType;
19 }
20 switch (schema.constructor) {
21 case z.ZodObject: {
22 const shape = (schema as z.ZodObject<z.ZodRawShape>).shape;
23 return parseShape(shape, paramsArray);
24 }
25 case z.ZodUnion: {
26 const options = (
27 schema as z.ZodUnion<
28 [z.ZodObject<z.ZodRawShape>, ...z.ZodObject<z.ZodRawShape>[]]
29 >
30 )._def.options;
31 for (const option of options) {
32 const shape = option.shape;
33 const requireds = getRequireds(shape);
34
35 const result = parseShape(shape, paramsArray, true);
36 const keys = Object.keys(result);
37
38 if (requireds.every((key) => keys.includes(key))) {
39 return result;
40 }
41 }
42 return {};
43 }
44 default:
45 throw new Error("Unsupported schema type");
46 }
47}
48
49function getRequireds(shape: z.ZodRawShape) {
50 const keys: string[] = [];

Callers 1

safeParseSearchParamsFunction · 0.70

Calls 2

parseShapeFunction · 0.70
getRequiredsFunction · 0.70

Tested by

no test coverage detected