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

Function writesOf

ark/schema/shared/inPlace.ts:83–113  ·  view source on GitHub ↗
(structure: StructureNode)

Source from the content-addressed store, hash-verified

81}
82
83const writesOf = (structure: StructureNode): Writes => {
84 const writes: Writes = {
85 values: keys(),
86 added: keys(),
87 addsOnlyDefaults: true
88 }
89 const sequence = structure.sequence
90 if (sequence?.children.some(element => !returnsInput(element)))
91 writes.values.indices = true
92 if (structure.undeclared === "delete") return writes
93 for (const prop of structure.props) {
94 if (!returnsInput(prop.value)) writes.values.named.add(prop.key)
95 if (prop.hasDef()) {
96 writes.added.named.add(prop.key)
97 if (prop.value.tfs || typeof prop.default === "function")
98 writes.addsOnlyDefaults = false
99 }
100 }
101 if (structure.index?.some(index => !returnsInput(index.value)))
102 writes.values.every = true
103 if (sequence?.defaultables) {
104 writes.added.indices = true
105 if (
106 sequence.defaultables.some(
107 ([node, value]) => node.tfs || typeof value === "function"
108 )
109 )
110 writes.addsOnlyDefaults = false
111 }
112 return writes
113}
114
115const readsOf = (node: BaseRoot): Reads | undefined => {
116 // a function can read any key of what it receives

Callers 1

writesUnreadFunction · 0.85

Calls 3

keysFunction · 0.85
returnsInputFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected