| 43 | |
| 44 | /** the Root a schema's values make up */ |
| 45 | export const parse = (schema: Schema, options?: ParseOptions): Root => { |
| 46 | const io = options?.io ?? "in" |
| 47 | if (schema instanceof BaseRoot) return io === "in" ? schema._in : schema._out |
| 48 | if (typeof schema === "boolean") return readJsonSchema(schema, options?.root) |
| 49 | if (!hasDomain(schema, "object")) |
| 50 | return throwParseError(writeUnparsableSchemaMessage(printable(schema))) |
| 51 | if (!("~standard" in schema)) { |
| 52 | return isJsonSchemaObject(schema) ? |
| 53 | readJsonSchema(schema, options?.root) |
| 54 | : throwParseError(writeUnparsableSchemaMessage(printable(schema))) |
| 55 | } |
| 56 | let root = standardRootsByIo[io].get(schema) |
| 57 | if (!root) { |
| 58 | standardRootsByIo[io].set( |
| 59 | schema, |
| 60 | (root = readStandardSchema(schema as StandardJSONSchemaV1, io)) |
| 61 | ) |
| 62 | } |
| 63 | return root |
| 64 | } |
| 65 | |
| 66 | /** the JSON Schema of a schema's values */ |
| 67 | export const toJsonSchema = ( |