MCPcopy Create free account
hub / github.com/Effect-TS/effect / encodeArray

Function encodeArray

packages/effect/src/ui/MessageLog.ts:2093–2112  ·  view source on GitHub ↗
(
  ast: SchemaAST.Arrays,
  value: ReadonlyArray<unknown>,
  walk: Walk
)

Source from the content-addressed store, hash-verified

2091}
2092/** Elements, then the rest, then the trailing elements, which take the last positions. */
2093const 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}
2113const fallback = (ast: SchemaAST.AST, value: unknown): Schema.Json =>
2114 holdsRedacted(ast) ? redacted : guarded(() => structural(value))
2115

Callers 2

encodeAtFunction · 0.70

Calls 2

encodeAtFunction · 0.85
mapMethod · 0.45

Tested by

no test coverage detected