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

Function rebuildFromStack

packages/effect/src/JsonPatch.ts:398–416  ·  view source on GitHub ↗
(stack: ReadonlyArray<StackEntry>, newParent: Schema.Json)

Source from the content-addressed store, hash-verified

396
397// Rebuild the document by writing `newParent` back through `stack`.
398function rebuildFromStack(stack: ReadonlyArray<StackEntry>, newParent: Schema.Json): Schema.Json {
399 let acc: Schema.Json = newParent
400
401 for (let i = stack.length - 1; i >= 0; i--) {
402 const { container, token } = stack[i]
403
404 if (Array.isArray(container)) {
405 const copy = container.slice()
406 copy[token as number] = acc
407 acc = copy
408 } else {
409 const copy = { ...(container as Schema.JsonObject) }
410 InternalRecord.assignProperty(copy, token as string, acc)
411 acc = copy
412 }
413 }
414
415 return acc
416}

Callers 1

applyOperationFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected