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

Function heldHandlerOf

ark/aot/shadow.ts:419–447  ·  view source on GitHub ↗
(pair: Pair)

Source from the content-addressed store, hash-verified

417
418// e.g. a Module, Scope or Generic, whose members its validator must have
419const heldHandlerOf = (pair: Pair): ProxyHandler<any> => {
420 const membersByKey: Record<PropertyKey, unknown> = Object.create(null)
421 return {
422 get: (target, k) => {
423 if (arktypeDepth) return Reflect.get(target, k)
424 const value = checkedMember(pair, target, k)
425 if (!hasArkKind(value, "root") && !isHeld(value))
426 return boundTo(target, value)
427 return (membersByKey[k] ??= shadowOf(
428 pair.contract,
429 `${pair.site}.${String(k)}`,
430 () => value,
431 () => (pair.counterpart as Record<PropertyKey, unknown>)[k]
432 ))
433 },
434 has: hasOf(pair),
435 // e.g. a Generic, which a validator holds as a reference it can't call
436 apply: (target, self, args) =>
437 arktypeDepth ?
438 inArktype(() => Reflect.apply(target, self, args))
439 : fail(
440 pair,
441 "calling it",
442 printable("function"),
443 printable(typeof pair.counterpart),
444 "since its validator can't be called"
445 )
446 }
447}
448
449const isHeld = (value: unknown) =>
450 hasArkKind(value, "module") ||

Callers 1

shadowOfFunction · 0.85

Calls 12

hasArkKindFunction · 0.90
printableFunction · 0.90
checkedMemberFunction · 0.85
boundToFunction · 0.85
shadowOfFunction · 0.85
StringInterface · 0.85
hasOfFunction · 0.85
inArktypeFunction · 0.85
isHeldFunction · 0.70
failFunction · 0.70
getMethod · 0.65
applyMethod · 0.45

Tested by

no test coverage detected