( write: () => JsonSchema, byTarget: readonly ((() => JsonSchema) | 0)[], // each target's, then the default's replays: readonly (((fallBack: FallBack) => JsonSchema) | 0)[] )
| 662 | // a baked schema written again with the fallback a call passes, as the build |
| 663 | // recorded arktype writing it; a target's replay is 0 where it has none |
| 664 | export const replayedJsonSchema = ( |
| 665 | write: () => JsonSchema, |
| 666 | byTarget: readonly ((() => JsonSchema) | 0)[], |
| 667 | // each target's, then the default's |
| 668 | replays: readonly (((fallBack: FallBack) => JsonSchema) | 0)[] |
| 669 | ): ((opts?: JsonSchemaOptions) => JsonSchema) => |
| 670 | freeze((opts?: JsonSchemaOptions) => { |
| 671 | const target = bakedTargetOf(opts, true) |
| 672 | const fallback = opts?.fallback |
| 673 | // a nullish fallback names no handler |
| 674 | if (fallback === undefined || fallback === null) { |
| 675 | const written = target === undefined ? write : byTarget[target] |
| 676 | return written ? written() : throwError(bakedJsonSchemaOptionsMessage) |
| 677 | } |
| 678 | const replay = replays[target ?? byTarget.length] |
| 679 | return replay ? |
| 680 | replay(fallingBackTo(fallback)) |
| 681 | : throwError(bakedJsonSchemaOptionsMessage) |
| 682 | }) |
| 683 | |
| 684 | // arktype calls a function for every code, else an object's handler for the |
| 685 | // code or its default, else the configured one |
no test coverage detected