MCPcopy Create free account
hub / github.com/arktypeio/arktype / readStandardSchema

Function readStandardSchema

ark/sets/formats.ts:77–109  ·  view source on GitHub ↗
(
	schema: StandardJSONSchemaV1,
	io: "in" | "out"
)

Source from the content-addressed store, hash-verified

75 : parse(schema).toJsonSchema(options)
76
77const readStandardSchema = (
78 schema: StandardJSONSchemaV1,
79 io: "in" | "out"
80): BaseRoot => {
81 // only its key was checked, so it may be anything
82 const standard = schema["~standard"] as
83 | Partial<StandardJSONSchemaV1.Props>
84 | null
85 | undefined
86 if (!hasDomain(standard, "object"))
87 return throwParseError(writeUnparsableSchemaMessage(printable(schema)))
88 const vendor = String(standard.vendor)
89 if (!hasDomain(standard.jsonSchema, "object")) {
90 return throwParseError(
91 writeUnparsableSchemaMessage(
92 `a ${vendor} Standard Schema without ~standard.jsonSchema`
93 )
94 )
95 }
96 const method = io === "in" ? "input" : "output"
97 let jsonSchema: JsonSchema.Input
98 try {
99 jsonSchema = standard.jsonSchema[method]({ target: "draft-2020-12" })
100 } catch (cause) {
101 throw Object.assign(
102 new ParseError(
103 writeUnreadableStandardSchemaMessage(vendor, method, cause)
104 ),
105 { cause }
106 )
107 }
108 return readJsonSchema(jsonSchema)
109}

Callers 1

parseFunction · 0.85

Calls 7

hasDomainFunction · 0.90
throwParseErrorFunction · 0.90
printableFunction · 0.90
readJsonSchemaFunction · 0.90
StringInterface · 0.85

Tested by

no test coverage detected