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

Function rootKeyOf

ark/type/standalone/keys.ts:126–147  ·  view source on GitHub ↗
(root: BaseRoot, isScoped = true)

Source from the content-addressed store, hash-verified

124export const traversalKeyOf = (root: BaseRoot): Key => rootKeyOf(root, false)
125
126const rootKeyOf = (root: BaseRoot, isScoped = true): Key => {
127 const units = rootUnitsOf(root)
128 const defaultsByMorph = new Map<unknown, CollectedDefault>()
129 // held so a codec's validator can be encoded where it's received
130 const inverses: unknown[] = []
131 for (const node of writtenSelectedOf(units, isKeyedBehavior)) {
132 if (node.is("optional") || node.is("sequence"))
133 collectDefaults(node, defaultsByMorph)
134 else if (node.is("morph") && node.inverse) inverses.push(node.inverse)
135 }
136 return encodeKey(
137 {
138 name: units[0].names[root.id],
139 refs: units.map(unit => unit.refs),
140 ...(inverses.length && { inverses }),
141 meta: root.meta,
142 // where its methods, like `and` and `or`, parse their arguments
143 ...(isScoped && { $: root.$ })
144 },
145 defaultsByMorph
146 )
147}
148
149// a default or a codec's inverse, each part of a key
150const isKeyedBehavior = (node: BaseNode): boolean =>

Callers 2

keyOfFunction · 0.85
traversalKeyOfFunction · 0.85

Calls 7

rootUnitsOfFunction · 0.90
writtenSelectedOfFunction · 0.90
collectDefaultsFunction · 0.90
encodeKeyFunction · 0.85
isMethod · 0.80
mapMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected