( opts: JsonSchemaOptions | undefined, allowsFallback: boolean )
| 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 |
| 623 | const 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 |
| 650 | export const bakedJsonSchema = ( |
no test coverage detected