@fedify/vocab-runtime 2.4.0-dev.2122 → 2.4.0-dev.2129
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deno.json +1 -1
- package/dist/{docloader-Dr8wEkif.d.cts → docloader-oRpq1nQ8.d.cts} +8 -1
- package/dist/{docloader-Dr8wEkif.d.ts → docloader-oRpq1nQ8.d.ts} +8 -1
- package/dist/internal/jsonld-cache.cjs +50 -0
- package/dist/internal/jsonld-cache.d.cts +28 -2
- package/dist/internal/jsonld-cache.d.ts +28 -2
- package/dist/internal/jsonld-cache.js +48 -1
- package/dist/internal/portable-dereference.cjs +28 -12
- package/dist/internal/portable-dereference.d.cts +12 -4
- package/dist/internal/portable-dereference.d.ts +12 -4
- package/dist/internal/portable-dereference.js +28 -12
- package/dist/mod.cjs +15 -9
- package/dist/mod.d.cts +8 -2
- package/dist/mod.d.ts +8 -2
- package/dist/mod.js +15 -9
- package/dist/{portable-comBI05Y.d.cts → portable-Drfl02vZ.d.cts} +1 -1
- package/dist/{portable-DH3947GK.d.ts → portable-rwhiyMvY.d.ts} +1 -1
- package/dist/tests/{body-tLaZa-9t.cjs → body-B98QT2cn.cjs} +1 -1
- package/dist/tests/{body-DkyJy_0c.mjs → body-CrD70FCs.mjs} +1 -1
- package/dist/tests/body.test.cjs +1 -1
- package/dist/tests/body.test.mjs +1 -1
- package/dist/tests/decimal.test.cjs +1 -1
- package/dist/tests/decimal.test.mjs +1 -1
- package/dist/tests/{docloader-DFs6K8ol.cjs → docloader-BVoNdutR.cjs} +16 -10
- package/dist/tests/{docloader-CSfFzxWm.mjs → docloader-CBscxl9w.mjs} +16 -10
- package/dist/tests/docloader.test.cjs +49 -2
- package/dist/tests/docloader.test.mjs +49 -2
- package/dist/tests/internal/portable-dereference.test.cjs +67 -6
- package/dist/tests/internal/portable-dereference.test.mjs +67 -6
- package/dist/tests/jsonld-cache-9jap4yM0.cjs +373 -0
- package/dist/tests/jsonld-cache-DnZS0z1G.mjs +324 -0
- package/dist/tests/jsonld-cache.test.cjs +20 -291
- package/dist/tests/jsonld-cache.test.mjs +2 -273
- package/dist/tests/{request-BLe2W5ua.cjs → request-BMNsRCJF.cjs} +1 -1
- package/dist/tests/{request-CmMy4YVK.mjs → request-CRVyLEa-.mjs} +1 -1
- package/dist/tests/request.test.cjs +1 -1
- package/dist/tests/request.test.mjs +1 -1
- package/package.json +1 -1
- package/src/docloader.test.ts +73 -0
- package/src/docloader.ts +46 -17
- package/src/internal/jsonld-cache.ts +60 -0
- package/src/internal/portable-dereference.test.ts +71 -0
- package/src/internal/portable-dereference.ts +37 -24
- package/src/preprocessor.ts +7 -0
- package/dist/tests/jsonld-CmDhHNTx.cjs +0 -12
- package/dist/tests/jsonld-DweIJ07b.mjs +0 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_contexts = require("../contexts-Ch3v2Cgu.cjs");
|
|
2
2
|
const require_url = require("../url-BqlldzT8.cjs");
|
|
3
|
-
require("../jsonld-
|
|
3
|
+
const require_jsonld_cache = require("../jsonld-cache-9jap4yM0.cjs");
|
|
4
4
|
let node_assert_strict = require("node:assert/strict");
|
|
5
5
|
let node_test = require("node:test");
|
|
6
6
|
let _logtape_logtape = require("@logtape/logtape");
|
|
@@ -98,8 +98,8 @@ function parseGatewayOrigin(gateway) {
|
|
|
98
98
|
* part of the public API contract. This is not considered public API for
|
|
99
99
|
* Semantic Versioning decisions.
|
|
100
100
|
*/
|
|
101
|
-
function createSnapshotContextLoader(contextLoader) {
|
|
102
|
-
|
|
101
|
+
function createSnapshotContextLoader(contextLoader, suppressError) {
|
|
102
|
+
contextLoader = require_jsonld_cache.unwrapReleasedDocumentLoader(contextLoader);
|
|
103
103
|
const cache = /* @__PURE__ */ new Map();
|
|
104
104
|
let released = false;
|
|
105
105
|
const release = () => {
|
|
@@ -117,7 +117,10 @@ function createSnapshotContextLoader(contextLoader) {
|
|
|
117
117
|
};
|
|
118
118
|
let promise = cache.get(key);
|
|
119
119
|
if (promise == null) {
|
|
120
|
-
const loading = contextLoader(url,
|
|
120
|
+
const loading = contextLoader(url, suppressError ? {
|
|
121
|
+
...options,
|
|
122
|
+
suppressError: true
|
|
123
|
+
} : options).then((document) => structuredClone(document));
|
|
121
124
|
promise = loading;
|
|
122
125
|
cache.set(key, loading);
|
|
123
126
|
loading.catch(() => {
|
|
@@ -130,13 +133,12 @@ function createSnapshotContextLoader(contextLoader) {
|
|
|
130
133
|
base: contextLoader,
|
|
131
134
|
released: false
|
|
132
135
|
};
|
|
133
|
-
|
|
136
|
+
require_jsonld_cache.registerDocumentLoaderWrapper(loader, state);
|
|
134
137
|
return {
|
|
135
138
|
loader,
|
|
136
139
|
release
|
|
137
140
|
};
|
|
138
141
|
}
|
|
139
|
-
const snapshotLoaders = /* @__PURE__ */ new WeakMap();
|
|
140
142
|
//#endregion
|
|
141
143
|
//#region src/internal/portable-dereference.test.ts
|
|
142
144
|
const hrefs = (urls) => urls.map((url) => url.href);
|
|
@@ -207,4 +209,63 @@ const hrefs = (urls) => urls.map((url) => url.href);
|
|
|
207
209
|
inner.release();
|
|
208
210
|
outer.release();
|
|
209
211
|
});
|
|
212
|
+
(0, node_test.test)("context loaders unwrap mixed released wrappers", async () => {
|
|
213
|
+
const calls = [];
|
|
214
|
+
const base = (url) => {
|
|
215
|
+
calls.push(url);
|
|
216
|
+
return Promise.resolve({
|
|
217
|
+
contextUrl: null,
|
|
218
|
+
documentUrl: url,
|
|
219
|
+
document: { "@context": {} }
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
for (const snapshotFirst of [false, true]) {
|
|
223
|
+
let loader = base;
|
|
224
|
+
for (let i = 0; i < 1e4; i++) {
|
|
225
|
+
const wrapper = i % 2 === 0 === snapshotFirst ? createSnapshotContextLoader(loader, true) : require_jsonld_cache.createScopedContextLoader(loader, true);
|
|
226
|
+
wrapper.release();
|
|
227
|
+
loader = wrapper.loader;
|
|
228
|
+
}
|
|
229
|
+
const unwrapped = require_jsonld_cache.createScopedContextLoader(loader, false).loader;
|
|
230
|
+
(0, node_assert_strict.deepStrictEqual)(unwrapped, base);
|
|
231
|
+
await unwrapped("https://example.com/context");
|
|
232
|
+
}
|
|
233
|
+
(0, node_assert_strict.deepStrictEqual)(calls, ["https://example.com/context", "https://example.com/context"]);
|
|
234
|
+
});
|
|
235
|
+
(0, node_test.test)("mixed context wrappers preserve active suppression and snapshots", async () => {
|
|
236
|
+
for (const activeSnapshot of [false, true]) {
|
|
237
|
+
const calls = [];
|
|
238
|
+
const base = (url, options) => {
|
|
239
|
+
calls.push(options);
|
|
240
|
+
return Promise.resolve({
|
|
241
|
+
contextUrl: null,
|
|
242
|
+
documentUrl: url,
|
|
243
|
+
document: { "@context": {} }
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
const active = activeSnapshot ? createSnapshotContextLoader(base, true) : require_jsonld_cache.createScopedContextLoader(base, true);
|
|
247
|
+
let loader = active.loader;
|
|
248
|
+
for (let i = 0; i < 4; i++) {
|
|
249
|
+
const wrapper = i % 2 === 0 ? require_jsonld_cache.createScopedContextLoader(loader, true) : createSnapshotContextLoader(loader, true);
|
|
250
|
+
wrapper.release();
|
|
251
|
+
loader = wrapper.loader;
|
|
252
|
+
}
|
|
253
|
+
const unwrapped = require_jsonld_cache.createScopedContextLoader(loader, false).loader;
|
|
254
|
+
(0, node_assert_strict.deepStrictEqual)(unwrapped, active.loader);
|
|
255
|
+
const options = { signal: new AbortController().signal };
|
|
256
|
+
const first = await unwrapped("https://example.com/context", options);
|
|
257
|
+
(0, node_assert_strict.ok)(first.document != null && typeof first.document === "object");
|
|
258
|
+
Reflect.set(first.document, "changed", true);
|
|
259
|
+
(0, node_assert_strict.deepStrictEqual)((await unwrapped("https://example.com/context", options)).document, { "@context": {} });
|
|
260
|
+
(0, node_assert_strict.deepStrictEqual)(calls.length, activeSnapshot ? 1 : 2);
|
|
261
|
+
for (const call of calls) (0, node_assert_strict.deepStrictEqual)(call, {
|
|
262
|
+
...options,
|
|
263
|
+
suppressError: true
|
|
264
|
+
});
|
|
265
|
+
active.release();
|
|
266
|
+
(0, node_assert_strict.deepStrictEqual)(require_jsonld_cache.createScopedContextLoader(loader, false).loader, base);
|
|
267
|
+
await unwrapped("https://example.com/context", options);
|
|
268
|
+
(0, node_assert_strict.deepStrictEqual)(calls.at(-1), options);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
210
271
|
//#endregion
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as preloadedContexts } from "../contexts-BBX_qhBL.mjs";
|
|
2
2
|
import { a as formatIri, m as parseIri } from "../url-DgJM9WJn.mjs";
|
|
3
|
-
import "../jsonld-
|
|
3
|
+
import { n as createScopedContextLoader, o as registerDocumentLoaderWrapper, s as unwrapReleasedDocumentLoader } from "../jsonld-cache-DnZS0z1G.mjs";
|
|
4
4
|
import { deepStrictEqual, ok, throws } from "node:assert/strict";
|
|
5
5
|
import { test } from "node:test";
|
|
6
6
|
import { getLogger } from "@logtape/logtape";
|
|
@@ -98,8 +98,8 @@ function parseGatewayOrigin(gateway) {
|
|
|
98
98
|
* part of the public API contract. This is not considered public API for
|
|
99
99
|
* Semantic Versioning decisions.
|
|
100
100
|
*/
|
|
101
|
-
function createSnapshotContextLoader(contextLoader) {
|
|
102
|
-
|
|
101
|
+
function createSnapshotContextLoader(contextLoader, suppressError) {
|
|
102
|
+
contextLoader = unwrapReleasedDocumentLoader(contextLoader);
|
|
103
103
|
const cache = /* @__PURE__ */ new Map();
|
|
104
104
|
let released = false;
|
|
105
105
|
const release = () => {
|
|
@@ -117,7 +117,10 @@ function createSnapshotContextLoader(contextLoader) {
|
|
|
117
117
|
};
|
|
118
118
|
let promise = cache.get(key);
|
|
119
119
|
if (promise == null) {
|
|
120
|
-
const loading = contextLoader(url,
|
|
120
|
+
const loading = contextLoader(url, suppressError ? {
|
|
121
|
+
...options,
|
|
122
|
+
suppressError: true
|
|
123
|
+
} : options).then((document) => structuredClone(document));
|
|
121
124
|
promise = loading;
|
|
122
125
|
cache.set(key, loading);
|
|
123
126
|
loading.catch(() => {
|
|
@@ -130,13 +133,12 @@ function createSnapshotContextLoader(contextLoader) {
|
|
|
130
133
|
base: contextLoader,
|
|
131
134
|
released: false
|
|
132
135
|
};
|
|
133
|
-
|
|
136
|
+
registerDocumentLoaderWrapper(loader, state);
|
|
134
137
|
return {
|
|
135
138
|
loader,
|
|
136
139
|
release
|
|
137
140
|
};
|
|
138
141
|
}
|
|
139
|
-
const snapshotLoaders = /* @__PURE__ */ new WeakMap();
|
|
140
142
|
//#endregion
|
|
141
143
|
//#region src/internal/portable-dereference.test.ts
|
|
142
144
|
const hrefs = (urls) => urls.map((url) => url.href);
|
|
@@ -207,5 +209,64 @@ test("createSnapshotContextLoader() does not nest released snapshots", async ()
|
|
|
207
209
|
inner.release();
|
|
208
210
|
outer.release();
|
|
209
211
|
});
|
|
212
|
+
test("context loaders unwrap mixed released wrappers", async () => {
|
|
213
|
+
const calls = [];
|
|
214
|
+
const base = (url) => {
|
|
215
|
+
calls.push(url);
|
|
216
|
+
return Promise.resolve({
|
|
217
|
+
contextUrl: null,
|
|
218
|
+
documentUrl: url,
|
|
219
|
+
document: { "@context": {} }
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
for (const snapshotFirst of [false, true]) {
|
|
223
|
+
let loader = base;
|
|
224
|
+
for (let i = 0; i < 1e4; i++) {
|
|
225
|
+
const wrapper = i % 2 === 0 === snapshotFirst ? createSnapshotContextLoader(loader, true) : createScopedContextLoader(loader, true);
|
|
226
|
+
wrapper.release();
|
|
227
|
+
loader = wrapper.loader;
|
|
228
|
+
}
|
|
229
|
+
const unwrapped = createScopedContextLoader(loader, false).loader;
|
|
230
|
+
deepStrictEqual(unwrapped, base);
|
|
231
|
+
await unwrapped("https://example.com/context");
|
|
232
|
+
}
|
|
233
|
+
deepStrictEqual(calls, ["https://example.com/context", "https://example.com/context"]);
|
|
234
|
+
});
|
|
235
|
+
test("mixed context wrappers preserve active suppression and snapshots", async () => {
|
|
236
|
+
for (const activeSnapshot of [false, true]) {
|
|
237
|
+
const calls = [];
|
|
238
|
+
const base = (url, options) => {
|
|
239
|
+
calls.push(options);
|
|
240
|
+
return Promise.resolve({
|
|
241
|
+
contextUrl: null,
|
|
242
|
+
documentUrl: url,
|
|
243
|
+
document: { "@context": {} }
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
const active = activeSnapshot ? createSnapshotContextLoader(base, true) : createScopedContextLoader(base, true);
|
|
247
|
+
let loader = active.loader;
|
|
248
|
+
for (let i = 0; i < 4; i++) {
|
|
249
|
+
const wrapper = i % 2 === 0 ? createScopedContextLoader(loader, true) : createSnapshotContextLoader(loader, true);
|
|
250
|
+
wrapper.release();
|
|
251
|
+
loader = wrapper.loader;
|
|
252
|
+
}
|
|
253
|
+
const unwrapped = createScopedContextLoader(loader, false).loader;
|
|
254
|
+
deepStrictEqual(unwrapped, active.loader);
|
|
255
|
+
const options = { signal: new AbortController().signal };
|
|
256
|
+
const first = await unwrapped("https://example.com/context", options);
|
|
257
|
+
ok(first.document != null && typeof first.document === "object");
|
|
258
|
+
Reflect.set(first.document, "changed", true);
|
|
259
|
+
deepStrictEqual((await unwrapped("https://example.com/context", options)).document, { "@context": {} });
|
|
260
|
+
deepStrictEqual(calls.length, activeSnapshot ? 1 : 2);
|
|
261
|
+
for (const call of calls) deepStrictEqual(call, {
|
|
262
|
+
...options,
|
|
263
|
+
suppressError: true
|
|
264
|
+
});
|
|
265
|
+
active.release();
|
|
266
|
+
deepStrictEqual(createScopedContextLoader(loader, false).loader, base);
|
|
267
|
+
await unwrapped("https://example.com/context", options);
|
|
268
|
+
deepStrictEqual(calls.at(-1), options);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
210
271
|
//#endregion
|
|
211
272
|
export {};
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-emK7D4bc.cjs");
|
|
2
|
+
const require_url = require("./url-BqlldzT8.cjs");
|
|
3
|
+
let jsonld_dist_jsonld_esm_js = require("jsonld/dist/jsonld.esm.js");
|
|
4
|
+
jsonld_dist_jsonld_esm_js = require_rolldown_runtime.__toESM(jsonld_dist_jsonld_esm_js, 1);
|
|
5
|
+
//#region src/jsonld.ts
|
|
6
|
+
var jsonld_default = jsonld_dist_jsonld_esm_js.default;
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/internal/jsonld-cache.ts
|
|
9
|
+
const noJsonLdContext = Symbol("noJsonLdContext");
|
|
10
|
+
const documentLoaderWrappers = /* @__PURE__ */ new WeakMap();
|
|
11
|
+
/**
|
|
12
|
+
* Registers a loader wrapper with the shared released-wrapper registry.
|
|
13
|
+
* Both suppression and snapshot wrappers must use this registry so mixed
|
|
14
|
+
* chains can be unwrapped. The caller updates the state on release.
|
|
15
|
+
* @internal Not a public API.
|
|
16
|
+
*/
|
|
17
|
+
function registerDocumentLoaderWrapper(loader, state) {
|
|
18
|
+
documentLoaderWrappers.set(loader, state);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Removes released loader wrappers, stopping at the first active wrapper.
|
|
22
|
+
* Active wrappers retain their operation's suppression or snapshot cache.
|
|
23
|
+
* @internal Not a public API.
|
|
24
|
+
*/
|
|
25
|
+
function unwrapReleasedDocumentLoader(base) {
|
|
26
|
+
for (let state = documentLoaderWrappers.get(base); state?.released; state = documentLoaderWrappers.get(base)) base = state.base;
|
|
27
|
+
return base;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Lowers context loading failure logs for one accessor operation. Parsed
|
|
31
|
+
* objects retain the loader, so release it before returning to the caller.
|
|
32
|
+
* Released wrappers are unwrapped to avoid accumulating loader chains.
|
|
33
|
+
* @internal Used by generated vocabulary accessors; not a public API.
|
|
34
|
+
*/
|
|
35
|
+
function createScopedContextLoader(base, suppressError) {
|
|
36
|
+
base = unwrapReleasedDocumentLoader(base);
|
|
37
|
+
if (!suppressError) return {
|
|
38
|
+
loader: base,
|
|
39
|
+
release: () => {}
|
|
40
|
+
};
|
|
41
|
+
const state = {
|
|
42
|
+
base,
|
|
43
|
+
released: false
|
|
44
|
+
};
|
|
45
|
+
const loader = (url, options) => base(url, state.released ? options : {
|
|
46
|
+
...options,
|
|
47
|
+
suppressError: true
|
|
48
|
+
});
|
|
49
|
+
registerDocumentLoaderWrapper(loader, state);
|
|
50
|
+
return {
|
|
51
|
+
loader,
|
|
52
|
+
release: () => {
|
|
53
|
+
state.released = true;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Checks whether an IRI is trusted relative to another IRI.
|
|
59
|
+
*
|
|
60
|
+
* @internal Technically exported for generated vocabulary classes, but not
|
|
61
|
+
* part of the public API contract. This is not considered public API for
|
|
62
|
+
* Semantic Versioning decisions.
|
|
63
|
+
*/
|
|
64
|
+
function isTrustedIriOrigin(options, left, right) {
|
|
65
|
+
return options.crossOrigin === "trust" || left == null || right != null && (require_url.haveSameIriOrigin(left, right) || require_url.haveSameFe34Origin(left, right));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Normalizes portable IRIs in JSON-LD cache data.
|
|
69
|
+
*
|
|
70
|
+
* @internal Technically exported for generated vocabulary classes, but not
|
|
71
|
+
* part of the public API contract. This is not considered public API for
|
|
72
|
+
* Semantic Versioning decisions.
|
|
73
|
+
*/
|
|
74
|
+
function normalizeJsonLdIris(value, iriKeys, iriPattern = /^ap(?:\+ef61)?:\/\//i) {
|
|
75
|
+
return normalize(value, void 0, 0, void 0);
|
|
76
|
+
function isIriPosition(key, parentKey) {
|
|
77
|
+
return iriKeys.has(key) || (key === "@value" || key === "@list" || key === "@set") && parentKey != null && iriKeys.has(parentKey);
|
|
78
|
+
}
|
|
79
|
+
function arrayItemParentKey(key, parentKey) {
|
|
80
|
+
return key === "@list" || key === "@set" ? parentKey : key;
|
|
81
|
+
}
|
|
82
|
+
function entryParentKey(entryKey, key, parentKey) {
|
|
83
|
+
if (entryKey === "@list" || entryKey === "@set") return parentKey ?? key;
|
|
84
|
+
return key === "@list" || key === "@set" ? parentKey : key;
|
|
85
|
+
}
|
|
86
|
+
function normalize(value, key, depth = 0, parentKey) {
|
|
87
|
+
if (depth > 32 || key === "@context") return value;
|
|
88
|
+
if (typeof value === "string") {
|
|
89
|
+
if (key != null && isIriPosition(key, parentKey) && iriPattern.test(value)) try {
|
|
90
|
+
return require_url.formatIri(value);
|
|
91
|
+
} catch {
|
|
92
|
+
return value;
|
|
93
|
+
}
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
if (Array.isArray(value)) {
|
|
97
|
+
let clone;
|
|
98
|
+
const itemParentKey = arrayItemParentKey(key, parentKey);
|
|
99
|
+
for (let i = 0; i < value.length; i++) {
|
|
100
|
+
const result = normalize(value[i], key, depth + 1, itemParentKey);
|
|
101
|
+
if (result !== value[i]) {
|
|
102
|
+
clone ??= value.slice(0, i);
|
|
103
|
+
clone.push(result);
|
|
104
|
+
} else if (clone != null) clone.push(value[i]);
|
|
105
|
+
}
|
|
106
|
+
return clone ?? value;
|
|
107
|
+
}
|
|
108
|
+
if (value == null || typeof value !== "object") return value;
|
|
109
|
+
const object = value;
|
|
110
|
+
let clone;
|
|
111
|
+
for (const entryKey of globalThis.Object.keys(object)) {
|
|
112
|
+
const result = normalize(object[entryKey], entryKey, depth + 1, entryParentKey(entryKey, key, parentKey));
|
|
113
|
+
if (result !== object[entryKey]) {
|
|
114
|
+
clone ??= { ...object };
|
|
115
|
+
defineJsonLdProperty(clone, entryKey, result);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return clone ?? object;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Finds the first JSON-LD context in a value.
|
|
123
|
+
*
|
|
124
|
+
* @internal Technically exported for generated vocabulary classes, but not
|
|
125
|
+
* part of the public API contract. This is not considered public API for
|
|
126
|
+
* Semantic Versioning decisions.
|
|
127
|
+
*/
|
|
128
|
+
function getJsonLdContext(value, depth = 0) {
|
|
129
|
+
if (depth > 32) return void 0;
|
|
130
|
+
if (Array.isArray(value)) {
|
|
131
|
+
for (const item of value) {
|
|
132
|
+
const context = getJsonLdContext(item, depth + 1);
|
|
133
|
+
if (context !== void 0) return context;
|
|
134
|
+
}
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (value == null || typeof value !== "object" || !("@context" in value)) return;
|
|
138
|
+
return value["@context"];
|
|
139
|
+
}
|
|
140
|
+
function getOwnJsonLdContext(value) {
|
|
141
|
+
if (value == null || typeof value !== "object" || Array.isArray(value) || !("@context" in value)) return noJsonLdContext;
|
|
142
|
+
return value["@context"];
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Recompacts normalized JSON-LD cache data against the original context.
|
|
146
|
+
*
|
|
147
|
+
* @internal Technically exported for generated vocabulary classes, but not
|
|
148
|
+
* part of the public API contract. This is not considered public API for
|
|
149
|
+
* Semantic Versioning decisions.
|
|
150
|
+
*/
|
|
151
|
+
async function compactJsonLdCache(normalized, original, documentLoader, depth = 0, inheritedContext) {
|
|
152
|
+
if (depth > 32) return normalized;
|
|
153
|
+
if (Array.isArray(original)) {
|
|
154
|
+
const normalizedArray = Array.isArray(normalized) ? normalized : normalized != null && typeof normalized === "object" && "@graph" in normalized && Array.isArray(normalized["@graph"]) ? normalized["@graph"] : void 0;
|
|
155
|
+
if (normalizedArray == null) return normalized;
|
|
156
|
+
let clone;
|
|
157
|
+
for (let i = 0; i < normalizedArray.length; i++) {
|
|
158
|
+
const item = await compactJsonLdCache(normalizedArray[i], original[i], documentLoader, depth + 1, inheritedContext);
|
|
159
|
+
if (item !== normalizedArray[i]) {
|
|
160
|
+
clone ??= normalizedArray.slice(0, i);
|
|
161
|
+
clone.push(item);
|
|
162
|
+
} else if (clone != null) clone.push(normalizedArray[i]);
|
|
163
|
+
}
|
|
164
|
+
return clone ?? (Array.isArray(normalized) ? normalized : normalizedArray);
|
|
165
|
+
}
|
|
166
|
+
const ownContext = getOwnJsonLdContext(original);
|
|
167
|
+
const context = ownContext === noJsonLdContext ? inheritedContext : ownContext;
|
|
168
|
+
if (context == null) return preserveNoContextJsonLdShape(normalized, original, depth);
|
|
169
|
+
return await preserveJsonLdShape(await mergeUnmappedTerms(await jsonld_default.compact(Array.isArray(normalized) && normalized.length === 1 ? normalized[0] : normalized, context, { documentLoader }), original, context, documentLoader), original, context, documentLoader, depth);
|
|
170
|
+
}
|
|
171
|
+
function preserveNoContextJsonLdShape(normalized, original, depth = 0) {
|
|
172
|
+
if (depth > 32) return normalized;
|
|
173
|
+
if (original == null || typeof original !== "object" || Array.isArray(original)) return normalized;
|
|
174
|
+
const normalizedObject = Array.isArray(normalized) && normalized.length === 1 ? normalized[0] : normalized;
|
|
175
|
+
if (normalizedObject == null || typeof normalizedObject !== "object" || Array.isArray(normalizedObject)) return normalized;
|
|
176
|
+
const source = normalizedObject;
|
|
177
|
+
const originalObject = original;
|
|
178
|
+
let clone;
|
|
179
|
+
for (const key of globalThis.Object.keys(originalObject)) {
|
|
180
|
+
if (!globalThis.Object.prototype.hasOwnProperty.call(source, key)) continue;
|
|
181
|
+
const value = preserveNoContextValue(source[key], originalObject[key], depth + 1);
|
|
182
|
+
if (value !== originalObject[key]) {
|
|
183
|
+
clone ??= { ...originalObject };
|
|
184
|
+
defineJsonLdProperty(clone, key, value);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return clone ?? original;
|
|
188
|
+
}
|
|
189
|
+
function preserveNoContextValue(normalized, original, depth) {
|
|
190
|
+
if (depth > 32) return normalized;
|
|
191
|
+
if (Array.isArray(original)) {
|
|
192
|
+
const normalizedArray = Array.isArray(normalized) ? normalized : [normalized];
|
|
193
|
+
let clone;
|
|
194
|
+
for (let i = 0; i < original.length; i++) {
|
|
195
|
+
const value = preserveNoContextValue(normalizedArray[i], original[i], depth + 1);
|
|
196
|
+
if (value !== original[i]) {
|
|
197
|
+
clone ??= original.slice(0, i);
|
|
198
|
+
clone.push(value);
|
|
199
|
+
} else if (clone != null) clone.push(original[i]);
|
|
200
|
+
}
|
|
201
|
+
return clone ?? original;
|
|
202
|
+
}
|
|
203
|
+
const normalizedValue = Array.isArray(normalized) ? normalized[0] : normalized;
|
|
204
|
+
if (normalizedValue == null || typeof normalizedValue !== "object" || Array.isArray(normalizedValue)) return normalizedValue;
|
|
205
|
+
const normalizedObject = normalizedValue;
|
|
206
|
+
if (original != null && typeof original === "object" && !Array.isArray(original)) return preserveNoContextJsonLdShape(normalizedObject, original, depth + 1);
|
|
207
|
+
if (typeof normalizedObject["@id"] === "string") return normalizedObject["@id"];
|
|
208
|
+
if ("@value" in normalizedObject) return normalizedObject["@value"];
|
|
209
|
+
return normalizedValue;
|
|
210
|
+
}
|
|
211
|
+
function getTopLevelTerms(value) {
|
|
212
|
+
const terms = /* @__PURE__ */ new Set();
|
|
213
|
+
const nodes = Array.isArray(value) ? value : [value];
|
|
214
|
+
for (const node of nodes) {
|
|
215
|
+
if (node == null || typeof node !== "object" || Array.isArray(node)) continue;
|
|
216
|
+
for (const key of globalThis.Object.keys(node)) {
|
|
217
|
+
if (key.startsWith("@")) continue;
|
|
218
|
+
terms.add(key);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return terms;
|
|
222
|
+
}
|
|
223
|
+
async function mergeUnmappedTerms(compacted, original, context, documentLoader) {
|
|
224
|
+
if (original == null || typeof original !== "object" || Array.isArray(original) || compacted == null || typeof compacted !== "object" || Array.isArray(compacted)) return compacted;
|
|
225
|
+
const unmappedKeys = globalThis.Object.keys(original).filter((key) => key !== "@context" && !globalThis.Object.prototype.hasOwnProperty.call(compacted, key));
|
|
226
|
+
if (unmappedKeys.length < 1) return compacted;
|
|
227
|
+
const result = { ...compacted };
|
|
228
|
+
const compactedWithContext = compacted != null && typeof compacted === "object" && !Array.isArray(compacted) && !("@context" in compacted) ? {
|
|
229
|
+
"@context": context,
|
|
230
|
+
...compacted
|
|
231
|
+
} : compacted;
|
|
232
|
+
const compactedTerms = getTopLevelTerms(await jsonld_default.expand(compactedWithContext, { documentLoader }));
|
|
233
|
+
const dummyPrefix = "urn:fedify:dummy:";
|
|
234
|
+
const dummy = { "@context": context };
|
|
235
|
+
for (let i = 0; i < unmappedKeys.length; i++) defineJsonLdProperty(dummy, unmappedKeys[i], `${dummyPrefix}${i}`);
|
|
236
|
+
const expanded = await jsonld_default.expand(dummy, { documentLoader });
|
|
237
|
+
const representedKeys = /* @__PURE__ */ new Set();
|
|
238
|
+
const nodes = Array.isArray(expanded) ? expanded : [expanded];
|
|
239
|
+
for (const node of nodes) {
|
|
240
|
+
if (node == null || typeof node !== "object" || Array.isArray(node)) continue;
|
|
241
|
+
for (const [term, termValue] of globalThis.Object.entries(node)) {
|
|
242
|
+
if (!compactedTerms.has(term)) continue;
|
|
243
|
+
for (let i = 0; i < unmappedKeys.length; i++) if (containsValue(termValue, `${dummyPrefix}${i}`)) representedKeys.add(unmappedKeys[i]);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
for (const key of unmappedKeys) if (!representedKeys.has(key)) defineJsonLdProperty(result, key, original[key]);
|
|
247
|
+
return result;
|
|
248
|
+
}
|
|
249
|
+
function defineJsonLdProperty(object, key, value) {
|
|
250
|
+
globalThis.Object.defineProperty(object, key, {
|
|
251
|
+
value,
|
|
252
|
+
enumerable: true,
|
|
253
|
+
configurable: true,
|
|
254
|
+
writable: true
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
function containsValue(value, expected, depth = 0) {
|
|
258
|
+
if (depth > 32) return false;
|
|
259
|
+
if (value === expected) return true;
|
|
260
|
+
if (Array.isArray(value)) return value.some((item) => containsValue(item, expected, depth + 1));
|
|
261
|
+
if (value == null || typeof value !== "object") return false;
|
|
262
|
+
return globalThis.Object.entries(value).some(([key, item]) => key !== "@context" && containsValue(item, expected, depth + 1));
|
|
263
|
+
}
|
|
264
|
+
async function preserveJsonLdShape(compacted, original, context, documentLoader, depth = 0) {
|
|
265
|
+
if (depth > 32) return compacted;
|
|
266
|
+
if (compacted === original) return compacted;
|
|
267
|
+
if (original == null || typeof original !== "object" || compacted == null || typeof compacted !== "object") return compacted;
|
|
268
|
+
if (Array.isArray(original)) {
|
|
269
|
+
const compactedArray = Array.isArray(compacted) ? compacted : "@graph" in compacted && Array.isArray(compacted["@graph"]) ? compacted["@graph"] : void 0;
|
|
270
|
+
if (compactedArray == null) return compacted;
|
|
271
|
+
let clone;
|
|
272
|
+
for (let i = 0; i < compactedArray.length; i++) {
|
|
273
|
+
const value = await preserveJsonLdShape(compactedArray[i], original[i], context, documentLoader, depth + 1);
|
|
274
|
+
const originalContext = original[i] != null && typeof original[i] === "object" && !Array.isArray(original[i]) && "@context" in original[i] ? original[i]["@context"] : void 0;
|
|
275
|
+
const shaped = originalContext !== void 0 && value != null && typeof value === "object" && !Array.isArray(value) && !("@context" in value) ? {
|
|
276
|
+
"@context": originalContext,
|
|
277
|
+
...value
|
|
278
|
+
} : value;
|
|
279
|
+
if (shaped !== compactedArray[i]) {
|
|
280
|
+
clone ??= compactedArray.slice(0, i);
|
|
281
|
+
clone.push(shaped);
|
|
282
|
+
} else if (clone != null) clone.push(compactedArray[i]);
|
|
283
|
+
}
|
|
284
|
+
return clone ?? (Array.isArray(compacted) ? compacted : compactedArray);
|
|
285
|
+
}
|
|
286
|
+
if (Array.isArray(compacted)) return compacted;
|
|
287
|
+
let clone;
|
|
288
|
+
const ownContext = getOwnJsonLdContext(original);
|
|
289
|
+
const objectContext = combineContexts(context, ownContext);
|
|
290
|
+
const objectCompacted = depth > 0 && ownContext === null ? await compactWithEmptyContext(compacted, context, documentLoader) : compacted;
|
|
291
|
+
const compactedObject = depth > 0 ? await mergeUnmappedTerms(objectCompacted, original, objectContext, documentLoader) : objectCompacted;
|
|
292
|
+
const originalObject = original;
|
|
293
|
+
for (const key of globalThis.Object.keys(compactedObject)) {
|
|
294
|
+
if (key === "@context") continue;
|
|
295
|
+
const value = await preserveJsonLdShape(compactedObject[key], originalObject[key], objectContext, documentLoader, depth + 1);
|
|
296
|
+
const shaped = Array.isArray(originalObject[key]) && !Array.isArray(value) ? [value] : value;
|
|
297
|
+
if (shaped !== compactedObject[key]) {
|
|
298
|
+
clone ??= { ...compactedObject };
|
|
299
|
+
defineJsonLdProperty(clone, key, shaped);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if (depth > 0) {
|
|
303
|
+
if ("@context" in originalObject && !("@context" in compactedObject)) {
|
|
304
|
+
clone ??= { ...compactedObject };
|
|
305
|
+
clone["@context"] = originalObject["@context"];
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return clone ?? compactedObject;
|
|
309
|
+
}
|
|
310
|
+
async function compactWithEmptyContext(compacted, context, documentLoader) {
|
|
311
|
+
const compactedWithContext = compacted != null && typeof compacted === "object" && !Array.isArray(compacted) && !("@context" in compacted) ? {
|
|
312
|
+
"@context": context,
|
|
313
|
+
...compacted
|
|
314
|
+
} : compacted;
|
|
315
|
+
const expanded = await jsonld_default.expand(compactedWithContext, { documentLoader });
|
|
316
|
+
return await jsonld_default.compact(expanded, {}, { documentLoader });
|
|
317
|
+
}
|
|
318
|
+
function combineContexts(inheritedContext, ownContext) {
|
|
319
|
+
if (ownContext === noJsonLdContext || ownContext === inheritedContext) return inheritedContext;
|
|
320
|
+
if (ownContext == null) return ownContext;
|
|
321
|
+
const inherited = Array.isArray(inheritedContext) ? inheritedContext : [inheritedContext];
|
|
322
|
+
const own = Array.isArray(ownContext) ? ownContext : [ownContext];
|
|
323
|
+
return [...inherited, ...own];
|
|
324
|
+
}
|
|
325
|
+
//#endregion
|
|
326
|
+
Object.defineProperty(exports, "compactJsonLdCache", {
|
|
327
|
+
enumerable: true,
|
|
328
|
+
get: function() {
|
|
329
|
+
return compactJsonLdCache;
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
Object.defineProperty(exports, "createScopedContextLoader", {
|
|
333
|
+
enumerable: true,
|
|
334
|
+
get: function() {
|
|
335
|
+
return createScopedContextLoader;
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
Object.defineProperty(exports, "getJsonLdContext", {
|
|
339
|
+
enumerable: true,
|
|
340
|
+
get: function() {
|
|
341
|
+
return getJsonLdContext;
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
Object.defineProperty(exports, "isTrustedIriOrigin", {
|
|
345
|
+
enumerable: true,
|
|
346
|
+
get: function() {
|
|
347
|
+
return isTrustedIriOrigin;
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
Object.defineProperty(exports, "jsonld_default", {
|
|
351
|
+
enumerable: true,
|
|
352
|
+
get: function() {
|
|
353
|
+
return jsonld_default;
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
Object.defineProperty(exports, "normalizeJsonLdIris", {
|
|
357
|
+
enumerable: true,
|
|
358
|
+
get: function() {
|
|
359
|
+
return normalizeJsonLdIris;
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
Object.defineProperty(exports, "registerDocumentLoaderWrapper", {
|
|
363
|
+
enumerable: true,
|
|
364
|
+
get: function() {
|
|
365
|
+
return registerDocumentLoaderWrapper;
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
Object.defineProperty(exports, "unwrapReleasedDocumentLoader", {
|
|
369
|
+
enumerable: true,
|
|
370
|
+
get: function() {
|
|
371
|
+
return unwrapReleasedDocumentLoader;
|
|
372
|
+
}
|
|
373
|
+
});
|