MCPcopy Create free account
hub / github.com/arktypeio/arktype / writeCopied

Function writeCopied

ark/schema/shared/transform.ts:157–188  ·  view source on GitHub ↗
(
	data: any,
	out: any,
	copied: Map<object, object>
)

Source from the content-addressed store, hash-verified

155// copy's place. Only a copy holds one, so what out holds as data does is
156// passed over
157const writeCopied = (
158 data: any,
159 out: any,
160 copied: Map<object, object>
161): unknown => {
162 const inPlace: any = copied.get(out)
163 // what a getter returns anew isn't the object out is a copy of
164 if (inPlace) data = inPlace
165 for (const k of deletableKeysOf(out)) {
166 const held = data[k]
167 let made = out[k]
168 if (Object.is(made, held)) continue
169 if (hasDomain(made, "object") && hasDomain(held, "object")) {
170 const written = writeCopied(held, made, copied)
171 if (written !== made) setOwnValue(out, k, (made = written))
172 }
173 // assigned as a branch alone would, unless the key was deleted for
174 // another place the object is held, or is read anew each time, so that
175 // no branch made its value
176 if (
177 inPlace &&
178 k in inPlace &&
179 !Object.is(made, held) &&
180 Object.is(held, inPlace[k])
181 )
182 setOwnValue(inPlace, k, made)
183 }
184 if (!inPlace) return out
185 for (const k of deletableKeysOf(inPlace))
186 if (!hasOwn(out, k)) delete inPlace[k]
187 return inPlace
188}
189
190// what two branches made of data both allow, each a copy without the keys it
191// deleted. Written into l's, whose keys r's others follow

Callers 1

transformKeptFunction · 0.85

Calls 6

hasDomainFunction · 0.90
hasOwnFunction · 0.90
isMethod · 0.80
deletableKeysOfFunction · 0.70
setOwnValueFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected