( ast: SchemaAST.Arrays, value: ReadonlyArray<unknown>, walk: Walk )
| 2091 | } |
| 2092 | /** Elements, then the rest, then the trailing elements, which take the last positions. */ |
| 2093 | const encodeArray = ( |
| 2094 | ast: SchemaAST.Arrays, |
| 2095 | value: ReadonlyArray<unknown>, |
| 2096 | walk: Walk |
| 2097 | ): Schema.Json => { |
| 2098 | const [rest, ...tail] = ast.rest |
| 2099 | const tailStart = Math.max(ast.elements.length, value.length - tail.length) |
| 2100 | return value.map((item, i) => { |
| 2101 | const element = i < ast.elements.length |
| 2102 | ? ast.elements[i] |
| 2103 | : rest === undefined |
| 2104 | ? undefined |
| 2105 | : i >= tailStart |
| 2106 | ? tail[i - tailStart] |
| 2107 | : rest |
| 2108 | return element === undefined |
| 2109 | ? walk.leaf(ast, item) |
| 2110 | : encodeAt(element, item, walk) |
| 2111 | }) |
| 2112 | } |
| 2113 | const fallback = (ast: SchemaAST.AST, value: unknown): Schema.Json => |
| 2114 | holdsRedacted(ast) ? redacted : guarded(() => structural(value)) |
| 2115 |
no test coverage detected