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

Function initFlat

ark/schema/node.ts:817–848  ·  view source on GitHub ↗

collects its flat references and flat morphs

()

Source from the content-addressed store, hash-verified

815
816 /** collects its flat references and flat morphs */
817 protected initFlat(): void {
818 const flatRefs = uniqueFlatRefs(
819 this.children.flatMap(child => child.flatRefs)
820 )
821 const flatMorphs: FlatRef<Morph.Node | Intersection.Node>[] = []
822 for (const ref of flatRefs) {
823 for (const branch of ref.node.branches) {
824 if (
825 branch.is("morph") ||
826 (branch.is("intersection") &&
827 branch.structure?.structMorph !== undefined)
828 ) {
829 flatMorphs.push({
830 path: ref.path,
831 propString: ref.propString,
832 node: branch
833 })
834 }
835 }
836 }
837
838 this.c.flatRefs = flatRefs.sort((l, r) =>
839 l.path.length > r.path.length ? 1
840 : l.path.length < r.path.length ? -1
841 : l.propString > r.propString ? 1
842 : l.propString < r.propString ? -1
843 : l.node.expression < r.node.expression ? -1
844 : l.node.expression > r.node.expression ? 1
845 : 0
846 )
847 this.c.flatMorphs = flatMorphs
848 }
849
850 // a Type checks its first data uncompiled
851 private get checksUncompiled(): boolean {

Callers

nothing calls this directly

Calls 4

uniqueFlatRefsFunction · 0.85
isMethod · 0.80
sortMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected