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

Function bakedTargetOf

ark/type/runtime.ts:623–647  ·  view source on GitHub ↗
(
	opts: JsonSchemaOptions | undefined,
	allowsFallback: boolean
)

Source from the content-addressed store, hash-verified

621// returns the target index (-1 if unsupported) or undefined for the default
622// target; throws on any option a baked schema can't answer
623const bakedTargetOf = (
624 opts: JsonSchemaOptions | undefined,
625 allowsFallback: boolean
626): number | undefined => {
627 let target: number | undefined
628 let hasUndefinedDialect = false
629 for (const k in opts) {
630 const value = opts[k as keyof JsonSchemaOptions]
631 if (k === "target") {
632 if (value !== undefined)
633 target = supportedJsonSchemaTargets.indexOf(value as never)
634 } else if (k === "dialect") {
635 if (value === undefined) hasUndefinedDialect = true
636 else throwError(bakedJsonSchemaOptionsMessage)
637 } else if (k === "fallback") {
638 if (!allowsFallback && value !== undefined && value !== null)
639 throwError(bakedJsonSchemaOptionsMessage)
640 } else throwError(bakedJsonSchemaOptionsMessage)
641 }
642 // arktype resolves target to dialect only when target is defined;
643 // `{ dialect: undefined }` alone clears the configured dialect
644 if (hasUndefinedDialect && target === undefined)
645 throwError(bakedJsonSchemaOptionsMessage)
646 return target
647}
648
649// a target's is 0 where the validator doesn't bake its schema
650export const bakedJsonSchema = (

Callers 2

bakedJsonSchemaFunction · 0.85
replayedJsonSchemaFunction · 0.85

Calls 1

throwErrorFunction · 0.90

Tested by

no test coverage detected