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

Function joinKept

ark/schema/shared/transform.ts:192–223  ·  view source on GitHub ↗
(data: any, l: any, r: any)

Source from the content-addressed store, hash-verified

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
192const joinKept = (data: any, l: any, r: any): unknown => {
193 if (l === data || r === data) return data
194 // a value neither copied, which a getter returned each its own of
195 if (!hasDomain(l, "object") || !hasDomain(r, "object")) return l
196 // a branch alone leaves a key deleting doesn't read, like an Error's cause,
197 // as an object written in place holds it unless it transforms its value.
198 // So the copies of such an object keep one only where each of them holds it
199 const inPlace = copiedInPlace?.get(l)
200 for (const k of deletableKeysOf(r)) {
201 const kept = r[k]
202 if (!hasOwn(l, k)) {
203 if (inPlace && !isDeletableKeyOf(inPlace, k)) continue
204 // a key l's copy inherits, as from an accessor of its class, is
205 // defined: assigning it would call a setter, or throw without one
206 if (k in l) defineValue(l, k, kept)
207 else l[k] = kept
208 continue
209 }
210 const held = l[k]
211 if (Object.is(held, kept)) continue
212 const joined = joinKept(data[k], held, kept)
213 // joined where it's held, unless r kept all data holds there. Nothing
214 // is assigned otherwise, as what a getter returned each branch anew
215 // is neither's copy to write
216 if (joined !== held) setOwnValue(l, k, joined)
217 }
218 if (inPlace) {
219 for (const k of deletableKeysOf(l))
220 if (!hasOwn(r, k) && !isDeletableKeyOf(inPlace, k)) delete l[k]
221 }
222 return l
223}
224
225export const setOwnValue = (
226 out: object,

Callers 1

transformKeptFunction · 0.85

Calls 8

hasDomainFunction · 0.90
hasOwnFunction · 0.90
defineValueFunction · 0.90
isDeletableKeyOfFunction · 0.85
isMethod · 0.80
deletableKeysOfFunction · 0.70
setOwnValueFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected