( content: unknown, Schema: z.ZodType<Output, Def, Input>, )
| 53 | }) |
| 54 | |
| 55 | export function parseProps<Output, Def extends ZodTypeDef, Input>( |
| 56 | content: unknown, |
| 57 | Schema: z.ZodType<Output, Def, Input>, |
| 58 | ): Output { |
| 59 | if ((content as any)?.__hike) { |
| 60 | throw new Error( |
| 61 | "Code Hike Error: can't parse component content. Looks like you are missing CodeHike's recma plugin or the framework you are using doesn't support it.", |
| 62 | ) |
| 63 | } |
| 64 | |
| 65 | const result = Schema.safeParse(content) |
| 66 | if (result.success) { |
| 67 | return result.data |
| 68 | } |
| 69 | |
| 70 | const error = result.error.errors[0] |
| 71 | |
| 72 | let p = error.path.slice() |
| 73 | let block = content as any |
| 74 | let location = "" |
| 75 | while (p.length) { |
| 76 | const key = p.shift()! |
| 77 | block = block[key] |
| 78 | if (block?._data?.header) { |
| 79 | location += `\n${block._data.header}` |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | const { path, code, message, ...rest } = error |
| 84 | const name = path[path.length - 1] |
| 85 | |
| 86 | throw new Error(`at ${location || "root"} |
| 87 | Error for \`${name}\`: ${message} |
| 88 | ${JSON.stringify(rest, null, 2)} |
| 89 | `) |
| 90 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…