( ref: string, fragment: string, from: Resource, refPointer: string, ctx: ReadContext )
| 530 | |
| 531 | // segments are percent-decoded, then unescaped (RFC 6901) |
| 532 | const 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 | |
| 577 | const decodePointerSegment = ( |
| 578 | segment: string, |
no test coverage detected