@@ -2,12 +2,11 @@ import { describe, test, beforeEach, afterEach, expect, beforeAll, afterAll } fr
22import { MockAgent , setGlobalDispatcher } from "undici" ;
33import { toAbsoluteIri } from "@hyperjump/uri" ;
44import { Hyperjump } from "./index.js" ;
5- import { fromJref , toJref } from "../jref/index.js" ;
5+ import { fromJref } from "../jref/index.js" ;
6+ import { toJson } from "../json/jsonast-util.js" ;
67
78/**
89 * @import { DocumentNode } from "./index.js"
9- * @import { JrefNode } from "../jref/index.js"
10- * @import { Reviver } from "../jref/index.js"
1110 */
1211
1312
@@ -20,23 +19,22 @@ describe("JSON Browser", () => {
2019 beforeAll ( ( ) => {
2120 /** @type (uri: string, text: string, embedded?: Record<string, DocumentNode>) => DocumentNode */
2221 const parseToDocument = ( uri , text , embedded = { } ) => {
23- /** @type Reviver<JrefNode | undefined> */
24- const embeddedReviver = ( node , key ) => {
25- if ( key === "$embedded" && node . type === "json" && node . jsonType === "object" ) {
22+ const rootNode = fromJref ( text , uri , ( node , key ) => {
23+ if ( key === "$embedded" && node . jsonType === "object" ) {
2624 for ( const propertyNode of node . children ) {
2725 const embeddedUri = toAbsoluteIri ( propertyNode . children [ 0 ] . value ) ;
28- const embeddedJref = toJref ( propertyNode . children [ 1 ] , uri ) ;
26+ const embeddedJref = toJson ( propertyNode . children [ 1 ] ) ;
2927 embedded [ embeddedUri ] = parseToDocument ( embeddedUri , embeddedJref , embedded ) ;
3028 }
3129 return ;
3230 } else {
3331 return node ;
3432 }
35- } ;
33+ } ) ;
3634
3735 return {
3836 type : "embedded-document" ,
39- children : [ fromJref ( text , uri , embeddedReviver ) ] ,
37+ children : [ rootNode ] ,
4038 uri : uri ,
4139 fragmentKind : "json-pointer" ,
4240 embedded : embedded
@@ -81,7 +79,7 @@ describe("JSON Browser", () => {
8179 const uri = `${ testDomain } /main#/foo` ;
8280 const subject = await hyperjump . get ( uri ) ;
8381
84- expect ( toJref ( subject , uri ) ) . to . equal ( `42` ) ;
82+ expect ( toJson ( subject ) ) . to . equal ( `42` ) ;
8583 } ) ;
8684
8785 test ( "getting the main document from an embedded document" , async ( ) => {
@@ -100,7 +98,7 @@ describe("JSON Browser", () => {
10098 const uri = `${ testDomain } /main#/foo` ;
10199 const subject = await hyperjump . get ( uri ) ;
102100
103- expect ( toJref ( subject , uri ) ) . to . equal ( `42` ) ;
101+ expect ( toJson ( subject ) ) . to . equal ( `42` ) ;
104102 } ) ;
105103
106104 test ( "getting an embedded document from an embedded document" , async ( ) => {
@@ -119,7 +117,7 @@ describe("JSON Browser", () => {
119117 const uri = `${ testDomain } /main#/foo` ;
120118 const subject = await hyperjump . get ( uri ) ;
121119
122- expect ( toJref ( subject , uri ) ) . to . equal ( `42` ) ;
120+ expect ( toJson ( subject ) ) . to . equal ( `42` ) ;
123121 } ) ;
124122
125123 test ( "a cached document takes precence over an embedded document" , async ( ) => {
@@ -148,7 +146,7 @@ describe("JSON Browser", () => {
148146 const uri = `${ testDomain } /main#/foo` ;
149147 const subject = await hyperjump . get ( uri ) ;
150148
151- expect ( toJref ( subject , uri ) ) . to . equal ( `42` ) ;
149+ expect ( toJson ( subject ) ) . to . equal ( `42` ) ;
152150 } ) ;
153151 } ) ;
154152} ) ;
0 commit comments