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

Function writesUnread

ark/schema/shared/inPlace.ts:252–288  ·  view source on GitHub ↗
(places: Map<string, Place>)

Source from the content-addressed store, hash-verified

250}
251
252const writesUnread = (places: Map<string, Place>): boolean => {
253 const readers: [Place, Reads][] = []
254 for (const place of places.values()) {
255 const reads = readsOf(place.node)
256 if (reads) readers.push([place, reads])
257 }
258 for (const place of places.values()) {
259 const writer = writerOf(place.node)
260 if (!writer) continue
261 // a function can return an object that outlives the call
262 if (place.afterFunction) return false
263 const writes = writesOf(writer)
264 if (
265 place.count > 1 &&
266 (!isEmpty(writes.values) ||
267 (!isEmpty(writes.added) && !writes.addsOnlyDefaults))
268 )
269 return false
270 for (const [reader, reads] of readers) {
271 if (
272 reader === place ||
273 (reader.count === 1 &&
274 place.count === 1 &&
275 reader.position === place.position)
276 )
277 continue
278 if (
279 (meet(writes.values, reads.values) ||
280 meet(writes.added, reads.values) ||
281 (reads.everyPresence && !isEmpty(writes.added))) &&
282 overlaps(place.node, reader.node)
283 )
284 return false
285 }
286 }
287 return true
288}
289
290/** arktype's morphs passed ctx that read only their input through it */
291export const inputOnlyMorphs: WeakSet<Function> = new WeakSet()

Callers 1

writesInPlaceFunction · 0.85

Calls 7

writesOfFunction · 0.85
readsOfFunction · 0.70
writerOfFunction · 0.70
isEmptyFunction · 0.70
meetFunction · 0.70
overlapsFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected