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

Function nodeKeyOf

ark/schema/parse.ts:370–398  ·  view source on GitHub ↗
(
	kind: NodeKind,
	impl: UnknownNodeImplementation,
	inner: dict,
	metaJson: JsonObject | undefined,
	$: BaseScope
)

Source from the content-addressed store, hash-verified

368// a reference bound to a scope keeps its original's id, so a child from
369// another scope is keyed by that scope too
370const nodeKeyOf = (
371 kind: NodeKind,
372 impl: UnknownNodeImplementation,
373 inner: dict,
374 metaJson: JsonObject | undefined,
375 $: BaseScope
376): string => {
377 let key: string = kind
378 for (const k in inner) {
379 const v = inner[k]
380 key += `,${k}:${
381 impl.keys[k].child === true ?
382 isArray(v) ? `[${idsOf(v as BaseNode[], $)}]`
383 : idOf(v as BaseNode, $)
384 : k === "unit" ?
385 kind === "unit" ?
386 literalKeyOf(v)
387 : `${JSON.stringify((v as BoundUnit).singular)}/${JSON.stringify((v as BoundUnit).plural)}`
388 : valueKeyOf(v, $)
389 }`
390 }
391 // an alias inlines a reference that has resolved when it's written
392 if (
393 kind === "alias" &&
394 hasArkKind(nodesById.get(inner.reference as string), "root")
395 )
396 key += ",!"
397 return metaJson ? `${key},${JSON.stringify(metaJson)}` : key
398}
399
400const idsOf = (nodes: readonly BaseNode[], $: BaseScope): string => {
401 let ids = ""

Callers 1

createNodeFunction · 0.85

Calls 6

hasArkKindFunction · 0.90
literalKeyOfFunction · 0.85
valueKeyOfFunction · 0.85
idsOfFunction · 0.70
idOfFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected