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

Function resolvePointer

ark/sets/fromJsonSchema.ts:532–575  ·  view source on GitHub ↗
(
	ref: string,
	fragment: string,
	from: Resource,
	refPointer: string,
	ctx: ReadContext
)

Source from the content-addressed store, hash-verified

530
531// segments are percent-decoded, then unescaped (RFC 6901)
532const resolvePointer = (
533 ref: string,
534 fragment: string,
535 from: Resource,
536 refPointer: string,
537 ctx: ReadContext
538): RefTarget => {
539 let resource = from
540 const target = fragment
541 .split("/")
542 .slice(1)
543 .reduce((target, segment) => {
544 if (target !== resource.schema) {
545 const id = idOf(target, resource.dialect)
546 if (id !== undefined) {
547 const parsed = resolveUriParts(id, resource.uri, ref)
548 const dialect = dialectOf(
549 isJsonSchemaObject(target) ? (target as dict).$schema : undefined,
550 resource.dialect
551 )
552 const isAnchorId =
553 dialect.dialectBefore2019 && isPlainAnchor(parsed.fragment)
554 resource = {
555 schema:
556 isAnchorId ?
557 parsed.uri === resource.uri ?
558 resource.schema
559 : ((ctx.resourcesByUri ??= indexResources(ctx))[parsed.uri]
560 ?.schema ?? target)
561 : target,
562 uri: parsed.uri,
563 dialect
564 }
565 }
566 }
567 const key = decodePointerSegment(segment, ref, refPointer)
568 return (
569 typeof target === "object" && target !== null && hasOwn(target, key)
570 ) ?
571 (target as dict)[key]
572 : throwParseError(writeUnresolvableRefMessage(ref, refPointer))
573 }, from.schema)
574 return { schema: target, resource, fragment }
575}
576
577const decodePointerSegment = (
578 segment: string,

Callers 1

resolveRefFunction · 0.85

Calls 11

hasOwnFunction · 0.90
throwParseErrorFunction · 0.90
resolveUriPartsFunction · 0.85
dialectOfFunction · 0.85
isJsonSchemaObjectFunction · 0.85
isPlainAnchorFunction · 0.85
indexResourcesFunction · 0.85
decodePointerSegmentFunction · 0.85
reduceMethod · 0.80
idOfFunction · 0.70

Tested by

no test coverage detected