( shape: z.ZodRawShape, paramsArray: Record<string, string[]>, isPartOfUnion = false )
| 60 | } |
| 61 | |
| 62 | function parseShape( |
| 63 | shape: z.ZodRawShape, |
| 64 | paramsArray: Record<string, string[]>, |
| 65 | isPartOfUnion = false |
| 66 | ): Record<string, any> { |
| 67 | const parsed: Record<string, any> = {}; |
| 68 | |
| 69 | for (const key in shape) { |
| 70 | if (shape.hasOwnProperty(key)) { |
| 71 | const fieldSchema: z.ZodTypeAny = shape[key]; |
| 72 | if (paramsArray[key]) { |
| 73 | const fieldData = convertToRequiredType(paramsArray[key], fieldSchema); |
| 74 | |
| 75 | if (fieldData.error) { |
| 76 | if (isPartOfUnion) return {}; |
| 77 | continue; |
| 78 | } |
| 79 | const result = fieldSchema.safeParse(fieldData.data!); |
| 80 | if (result.success) parsed[key] = result.data; |
| 81 | } else if (fieldSchema instanceof z.ZodDefault) { |
| 82 | const result = fieldSchema.safeParse(undefined); |
| 83 | if (result.success) parsed[key] = result.data; |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | return parsed; |
| 89 | } |
| 90 | |
| 91 | function getAllParamsAsArrays( |
| 92 | searchParams: URLSearchParams |
no test coverage detected