@fedify/vocab-runtime 2.4.0-dev.1564 → 2.4.0-dev.1570
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 -2
- package/dist/mod.cjs +190 -107
- package/dist/mod.d.cts +200 -18
- package/dist/mod.d.ts +200 -18
- package/dist/mod.js +184 -97
- package/dist/tests/decimal.test.cjs +2 -2
- package/dist/tests/decimal.test.mjs +2 -2
- package/dist/tests/{docloader-CYQvKbtL.mjs → docloader-C76ldE5C.mjs} +10 -97
- package/dist/tests/{docloader-UAdXnDwt.cjs → docloader-mvgIWKI7.cjs} +9 -102
- package/dist/tests/docloader.test.cjs +6 -58
- package/dist/tests/docloader.test.mjs +6 -58
- package/dist/tests/{request-DgAlI7RF.mjs → request-BEXkv1ul.mjs} +1 -1
- package/dist/tests/{request-DnzhAfki.cjs → request-SworbvLc.cjs} +1 -1
- package/dist/tests/request.test.cjs +1 -1
- package/dist/tests/request.test.mjs +1 -1
- package/dist/tests/{url-2XwVbUS_.cjs → url-C20FhC7p.cjs} +0 -108
- package/dist/tests/{url-YWJbnRlf.mjs → url-m9Qzxy-Y.mjs} +1 -85
- package/dist/tests/url.test.cjs +1 -104
- package/dist/tests/url.test.mjs +2 -105
- package/package.json +1 -11
- package/src/contexts.ts +0 -2
- package/src/docloader.test.ts +6 -102
- package/src/docloader.ts +8 -76
- package/src/mod.ts +0 -4
- package/src/url.test.ts +1 -252
- package/src/url.ts +0 -141
- package/tsdown.config.ts +1 -6
- package/dist/docloader-DnUMWHaJ.d.cts +0 -202
- package/dist/docloader-xRGn1azD.d.ts +0 -202
- package/dist/internal/jsonld-cache.cjs +0 -279
- package/dist/internal/jsonld-cache.d.cts +0 -48
- package/dist/internal/jsonld-cache.d.ts +0 -48
- package/dist/internal/jsonld-cache.js +0 -275
- package/dist/tests/jsonld-cache.test.cjs +0 -652
- package/dist/tests/jsonld-cache.test.d.cts +0 -1
- package/dist/tests/jsonld-cache.test.d.mts +0 -1
- package/dist/tests/jsonld-cache.test.mjs +0 -651
- package/dist/url-BAdyyqAa.cjs +0 -315
- package/dist/url-BuxPHxK2.js +0 -261
- package/src/contexts/fep-7aa9.json +0 -24
- package/src/internal/jsonld-cache.ts +0 -538
- package/src/jsonld-cache.test.ts +0 -554
|
@@ -1,652 +0,0 @@
|
|
|
1
|
-
const require_chunk = require("./chunk-C2EiDwsr.cjs");
|
|
2
|
-
const require_url = require("./url-2XwVbUS_.cjs");
|
|
3
|
-
let node_assert = require("node:assert");
|
|
4
|
-
let node_test = require("node:test");
|
|
5
|
-
let jsonld_dist_jsonld_esm_js = require("jsonld/dist/jsonld.esm.js");
|
|
6
|
-
jsonld_dist_jsonld_esm_js = require_chunk.__toESM(jsonld_dist_jsonld_esm_js, 1);
|
|
7
|
-
//#region src/jsonld.ts
|
|
8
|
-
var jsonld_default = jsonld_dist_jsonld_esm_js.default;
|
|
9
|
-
//#endregion
|
|
10
|
-
//#region src/internal/jsonld-cache.ts
|
|
11
|
-
const noJsonLdContext = Symbol("noJsonLdContext");
|
|
12
|
-
/**
|
|
13
|
-
* Checks whether an IRI is trusted relative to another IRI.
|
|
14
|
-
*
|
|
15
|
-
* @internal Technically exported for generated vocabulary classes, but not
|
|
16
|
-
* part of the public API contract. This is not considered public API for
|
|
17
|
-
* Semantic Versioning decisions.
|
|
18
|
-
*/
|
|
19
|
-
function isTrustedIriOrigin(options, left, right) {
|
|
20
|
-
return options.crossOrigin === "trust" || left == null || right != null && require_url.haveSameIriOrigin(left, right);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Normalizes portable IRIs in JSON-LD cache data.
|
|
24
|
-
*
|
|
25
|
-
* @internal Technically exported for generated vocabulary classes, but not
|
|
26
|
-
* part of the public API contract. This is not considered public API for
|
|
27
|
-
* Semantic Versioning decisions.
|
|
28
|
-
*/
|
|
29
|
-
function normalizeJsonLdIris(value, iriKeys, iriPattern = /^ap(?:\+ef61)?:\/\//i) {
|
|
30
|
-
return normalize(value, void 0, 0, void 0);
|
|
31
|
-
function isIriPosition(key, parentKey) {
|
|
32
|
-
return iriKeys.has(key) || (key === "@value" || key === "@list" || key === "@set") && parentKey != null && iriKeys.has(parentKey);
|
|
33
|
-
}
|
|
34
|
-
function arrayItemParentKey(key, parentKey) {
|
|
35
|
-
return key === "@list" || key === "@set" ? parentKey : key;
|
|
36
|
-
}
|
|
37
|
-
function entryParentKey(entryKey, key, parentKey) {
|
|
38
|
-
if (entryKey === "@list" || entryKey === "@set") return parentKey ?? key;
|
|
39
|
-
return key === "@list" || key === "@set" ? parentKey : key;
|
|
40
|
-
}
|
|
41
|
-
function normalize(value, key, depth = 0, parentKey) {
|
|
42
|
-
if (depth > 32 || key === "@context") return value;
|
|
43
|
-
if (typeof value === "string") {
|
|
44
|
-
if (key != null && isIriPosition(key, parentKey) && iriPattern.test(value)) try {
|
|
45
|
-
return require_url.formatIri(value);
|
|
46
|
-
} catch {
|
|
47
|
-
return value;
|
|
48
|
-
}
|
|
49
|
-
return value;
|
|
50
|
-
}
|
|
51
|
-
if (Array.isArray(value)) {
|
|
52
|
-
let clone;
|
|
53
|
-
const itemParentKey = arrayItemParentKey(key, parentKey);
|
|
54
|
-
for (let i = 0; i < value.length; i++) {
|
|
55
|
-
const result = normalize(value[i], key, depth + 1, itemParentKey);
|
|
56
|
-
if (result !== value[i]) {
|
|
57
|
-
clone ??= value.slice(0, i);
|
|
58
|
-
clone.push(result);
|
|
59
|
-
} else if (clone != null) clone.push(value[i]);
|
|
60
|
-
}
|
|
61
|
-
return clone ?? value;
|
|
62
|
-
}
|
|
63
|
-
if (value == null || typeof value !== "object") return value;
|
|
64
|
-
const object = value;
|
|
65
|
-
let clone;
|
|
66
|
-
for (const entryKey of globalThis.Object.keys(object)) {
|
|
67
|
-
const result = normalize(object[entryKey], entryKey, depth + 1, entryParentKey(entryKey, key, parentKey));
|
|
68
|
-
if (result !== object[entryKey]) {
|
|
69
|
-
clone ??= { ...object };
|
|
70
|
-
defineJsonLdProperty(clone, entryKey, result);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return clone ?? object;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Finds the first JSON-LD context in a value.
|
|
78
|
-
*
|
|
79
|
-
* @internal Technically exported for generated vocabulary classes, but not
|
|
80
|
-
* part of the public API contract. This is not considered public API for
|
|
81
|
-
* Semantic Versioning decisions.
|
|
82
|
-
*/
|
|
83
|
-
function getJsonLdContext(value, depth = 0) {
|
|
84
|
-
if (depth > 32) return void 0;
|
|
85
|
-
if (Array.isArray(value)) {
|
|
86
|
-
for (const item of value) {
|
|
87
|
-
const context = getJsonLdContext(item, depth + 1);
|
|
88
|
-
if (context !== void 0) return context;
|
|
89
|
-
}
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
if (value == null || typeof value !== "object" || !("@context" in value)) return;
|
|
93
|
-
return value["@context"];
|
|
94
|
-
}
|
|
95
|
-
function getOwnJsonLdContext(value) {
|
|
96
|
-
if (value == null || typeof value !== "object" || Array.isArray(value) || !("@context" in value)) return noJsonLdContext;
|
|
97
|
-
return value["@context"];
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Recompacts normalized JSON-LD cache data against the original context.
|
|
101
|
-
*
|
|
102
|
-
* @internal Technically exported for generated vocabulary classes, but not
|
|
103
|
-
* part of the public API contract. This is not considered public API for
|
|
104
|
-
* Semantic Versioning decisions.
|
|
105
|
-
*/
|
|
106
|
-
async function compactJsonLdCache(normalized, original, documentLoader, depth = 0, inheritedContext) {
|
|
107
|
-
if (depth > 32) return normalized;
|
|
108
|
-
if (Array.isArray(original)) {
|
|
109
|
-
const normalizedArray = Array.isArray(normalized) ? normalized : normalized != null && typeof normalized === "object" && "@graph" in normalized && Array.isArray(normalized["@graph"]) ? normalized["@graph"] : void 0;
|
|
110
|
-
if (normalizedArray == null) return normalized;
|
|
111
|
-
let clone;
|
|
112
|
-
for (let i = 0; i < normalizedArray.length; i++) {
|
|
113
|
-
const item = await compactJsonLdCache(normalizedArray[i], original[i], documentLoader, depth + 1, inheritedContext);
|
|
114
|
-
if (item !== normalizedArray[i]) {
|
|
115
|
-
clone ??= normalizedArray.slice(0, i);
|
|
116
|
-
clone.push(item);
|
|
117
|
-
} else if (clone != null) clone.push(normalizedArray[i]);
|
|
118
|
-
}
|
|
119
|
-
return clone ?? (Array.isArray(normalized) ? normalized : normalizedArray);
|
|
120
|
-
}
|
|
121
|
-
const ownContext = getOwnJsonLdContext(original);
|
|
122
|
-
const context = ownContext === noJsonLdContext ? inheritedContext : ownContext;
|
|
123
|
-
if (context == null) return preserveNoContextJsonLdShape(normalized, original, depth);
|
|
124
|
-
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);
|
|
125
|
-
}
|
|
126
|
-
function preserveNoContextJsonLdShape(normalized, original, depth = 0) {
|
|
127
|
-
if (depth > 32) return normalized;
|
|
128
|
-
if (original == null || typeof original !== "object" || Array.isArray(original)) return normalized;
|
|
129
|
-
const normalizedObject = Array.isArray(normalized) && normalized.length === 1 ? normalized[0] : normalized;
|
|
130
|
-
if (normalizedObject == null || typeof normalizedObject !== "object" || Array.isArray(normalizedObject)) return normalized;
|
|
131
|
-
const source = normalizedObject;
|
|
132
|
-
const originalObject = original;
|
|
133
|
-
let clone;
|
|
134
|
-
for (const key of globalThis.Object.keys(originalObject)) {
|
|
135
|
-
if (!globalThis.Object.prototype.hasOwnProperty.call(source, key)) continue;
|
|
136
|
-
const value = preserveNoContextValue(source[key], originalObject[key], depth + 1);
|
|
137
|
-
if (value !== originalObject[key]) {
|
|
138
|
-
clone ??= { ...originalObject };
|
|
139
|
-
defineJsonLdProperty(clone, key, value);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return clone ?? original;
|
|
143
|
-
}
|
|
144
|
-
function preserveNoContextValue(normalized, original, depth) {
|
|
145
|
-
if (depth > 32) return normalized;
|
|
146
|
-
if (Array.isArray(original)) {
|
|
147
|
-
const normalizedArray = Array.isArray(normalized) ? normalized : [normalized];
|
|
148
|
-
let clone;
|
|
149
|
-
for (let i = 0; i < original.length; i++) {
|
|
150
|
-
const value = preserveNoContextValue(normalizedArray[i], original[i], depth + 1);
|
|
151
|
-
if (value !== original[i]) {
|
|
152
|
-
clone ??= original.slice(0, i);
|
|
153
|
-
clone.push(value);
|
|
154
|
-
} else if (clone != null) clone.push(original[i]);
|
|
155
|
-
}
|
|
156
|
-
return clone ?? original;
|
|
157
|
-
}
|
|
158
|
-
const normalizedValue = Array.isArray(normalized) ? normalized[0] : normalized;
|
|
159
|
-
if (normalizedValue == null || typeof normalizedValue !== "object" || Array.isArray(normalizedValue)) return normalizedValue;
|
|
160
|
-
const normalizedObject = normalizedValue;
|
|
161
|
-
if (original != null && typeof original === "object" && !Array.isArray(original)) return preserveNoContextJsonLdShape(normalizedObject, original, depth + 1);
|
|
162
|
-
if (typeof normalizedObject["@id"] === "string") return normalizedObject["@id"];
|
|
163
|
-
if ("@value" in normalizedObject) return normalizedObject["@value"];
|
|
164
|
-
return normalizedValue;
|
|
165
|
-
}
|
|
166
|
-
function getTopLevelTerms(value) {
|
|
167
|
-
const terms = /* @__PURE__ */ new Set();
|
|
168
|
-
const nodes = Array.isArray(value) ? value : [value];
|
|
169
|
-
for (const node of nodes) {
|
|
170
|
-
if (node == null || typeof node !== "object" || Array.isArray(node)) continue;
|
|
171
|
-
for (const key of globalThis.Object.keys(node)) {
|
|
172
|
-
if (key.startsWith("@")) continue;
|
|
173
|
-
terms.add(key);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return terms;
|
|
177
|
-
}
|
|
178
|
-
async function mergeUnmappedTerms(compacted, original, context, documentLoader) {
|
|
179
|
-
if (original == null || typeof original !== "object" || Array.isArray(original) || compacted == null || typeof compacted !== "object" || Array.isArray(compacted)) return compacted;
|
|
180
|
-
const unmappedKeys = globalThis.Object.keys(original).filter((key) => key !== "@context" && !globalThis.Object.prototype.hasOwnProperty.call(compacted, key));
|
|
181
|
-
if (unmappedKeys.length < 1) return compacted;
|
|
182
|
-
const result = { ...compacted };
|
|
183
|
-
const compactedWithContext = compacted != null && typeof compacted === "object" && !Array.isArray(compacted) && !("@context" in compacted) ? {
|
|
184
|
-
"@context": context,
|
|
185
|
-
...compacted
|
|
186
|
-
} : compacted;
|
|
187
|
-
const compactedTerms = getTopLevelTerms(await jsonld_default.expand(compactedWithContext, { documentLoader }));
|
|
188
|
-
const dummyPrefix = "urn:fedify:dummy:";
|
|
189
|
-
const dummy = { "@context": context };
|
|
190
|
-
for (let i = 0; i < unmappedKeys.length; i++) defineJsonLdProperty(dummy, unmappedKeys[i], `${dummyPrefix}${i}`);
|
|
191
|
-
const expanded = await jsonld_default.expand(dummy, { documentLoader });
|
|
192
|
-
const representedKeys = /* @__PURE__ */ new Set();
|
|
193
|
-
const nodes = Array.isArray(expanded) ? expanded : [expanded];
|
|
194
|
-
for (const node of nodes) {
|
|
195
|
-
if (node == null || typeof node !== "object" || Array.isArray(node)) continue;
|
|
196
|
-
for (const [term, termValue] of globalThis.Object.entries(node)) {
|
|
197
|
-
if (!compactedTerms.has(term)) continue;
|
|
198
|
-
for (let i = 0; i < unmappedKeys.length; i++) if (containsValue(termValue, `${dummyPrefix}${i}`)) representedKeys.add(unmappedKeys[i]);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
for (const key of unmappedKeys) if (!representedKeys.has(key)) defineJsonLdProperty(result, key, original[key]);
|
|
202
|
-
return result;
|
|
203
|
-
}
|
|
204
|
-
function defineJsonLdProperty(object, key, value) {
|
|
205
|
-
globalThis.Object.defineProperty(object, key, {
|
|
206
|
-
value,
|
|
207
|
-
enumerable: true,
|
|
208
|
-
configurable: true,
|
|
209
|
-
writable: true
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
function containsValue(value, expected, depth = 0) {
|
|
213
|
-
if (depth > 32) return false;
|
|
214
|
-
if (value === expected) return true;
|
|
215
|
-
if (Array.isArray(value)) return value.some((item) => containsValue(item, expected, depth + 1));
|
|
216
|
-
if (value == null || typeof value !== "object") return false;
|
|
217
|
-
return globalThis.Object.entries(value).some(([key, item]) => key !== "@context" && containsValue(item, expected, depth + 1));
|
|
218
|
-
}
|
|
219
|
-
async function preserveJsonLdShape(compacted, original, context, documentLoader, depth = 0) {
|
|
220
|
-
if (depth > 32) return compacted;
|
|
221
|
-
if (compacted === original) return compacted;
|
|
222
|
-
if (original == null || typeof original !== "object" || compacted == null || typeof compacted !== "object") return compacted;
|
|
223
|
-
if (Array.isArray(original)) {
|
|
224
|
-
const compactedArray = Array.isArray(compacted) ? compacted : "@graph" in compacted && Array.isArray(compacted["@graph"]) ? compacted["@graph"] : void 0;
|
|
225
|
-
if (compactedArray == null) return compacted;
|
|
226
|
-
let clone;
|
|
227
|
-
for (let i = 0; i < compactedArray.length; i++) {
|
|
228
|
-
const value = await preserveJsonLdShape(compactedArray[i], original[i], context, documentLoader, depth + 1);
|
|
229
|
-
const originalContext = original[i] != null && typeof original[i] === "object" && !Array.isArray(original[i]) && "@context" in original[i] ? original[i]["@context"] : void 0;
|
|
230
|
-
const shaped = originalContext !== void 0 && value != null && typeof value === "object" && !Array.isArray(value) && !("@context" in value) ? {
|
|
231
|
-
"@context": originalContext,
|
|
232
|
-
...value
|
|
233
|
-
} : value;
|
|
234
|
-
if (shaped !== compactedArray[i]) {
|
|
235
|
-
clone ??= compactedArray.slice(0, i);
|
|
236
|
-
clone.push(shaped);
|
|
237
|
-
} else if (clone != null) clone.push(compactedArray[i]);
|
|
238
|
-
}
|
|
239
|
-
return clone ?? (Array.isArray(compacted) ? compacted : compactedArray);
|
|
240
|
-
}
|
|
241
|
-
if (Array.isArray(compacted)) return compacted;
|
|
242
|
-
let clone;
|
|
243
|
-
const ownContext = getOwnJsonLdContext(original);
|
|
244
|
-
const objectContext = combineContexts(context, ownContext);
|
|
245
|
-
const objectCompacted = depth > 0 && ownContext === null ? await compactWithEmptyContext(compacted, context, documentLoader) : compacted;
|
|
246
|
-
const compactedObject = depth > 0 ? await mergeUnmappedTerms(objectCompacted, original, objectContext, documentLoader) : objectCompacted;
|
|
247
|
-
const originalObject = original;
|
|
248
|
-
for (const key of globalThis.Object.keys(compactedObject)) {
|
|
249
|
-
if (key === "@context") continue;
|
|
250
|
-
const value = await preserveJsonLdShape(compactedObject[key], originalObject[key], objectContext, documentLoader, depth + 1);
|
|
251
|
-
const shaped = Array.isArray(originalObject[key]) && !Array.isArray(value) ? [value] : value;
|
|
252
|
-
if (shaped !== compactedObject[key]) {
|
|
253
|
-
clone ??= { ...compactedObject };
|
|
254
|
-
defineJsonLdProperty(clone, key, shaped);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
if (depth > 0) {
|
|
258
|
-
if ("@context" in originalObject && !("@context" in compactedObject)) {
|
|
259
|
-
clone ??= { ...compactedObject };
|
|
260
|
-
clone["@context"] = originalObject["@context"];
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
return clone ?? compactedObject;
|
|
264
|
-
}
|
|
265
|
-
async function compactWithEmptyContext(compacted, context, documentLoader) {
|
|
266
|
-
const compactedWithContext = compacted != null && typeof compacted === "object" && !Array.isArray(compacted) && !("@context" in compacted) ? {
|
|
267
|
-
"@context": context,
|
|
268
|
-
...compacted
|
|
269
|
-
} : compacted;
|
|
270
|
-
const expanded = await jsonld_default.expand(compactedWithContext, { documentLoader });
|
|
271
|
-
return await jsonld_default.compact(expanded, {}, { documentLoader });
|
|
272
|
-
}
|
|
273
|
-
function combineContexts(inheritedContext, ownContext) {
|
|
274
|
-
if (ownContext === noJsonLdContext || ownContext === inheritedContext) return inheritedContext;
|
|
275
|
-
if (ownContext == null) return ownContext;
|
|
276
|
-
const inherited = Array.isArray(inheritedContext) ? inheritedContext : [inheritedContext];
|
|
277
|
-
const own = Array.isArray(ownContext) ? ownContext : [ownContext];
|
|
278
|
-
return [...inherited, ...own];
|
|
279
|
-
}
|
|
280
|
-
//#endregion
|
|
281
|
-
//#region src/jsonld-cache.test.ts
|
|
282
|
-
(0, node_test.test)("isTrustedIriOrigin() trusts same portable IRI origins", () => {
|
|
283
|
-
(0, node_assert.ok)(isTrustedIriOrigin({}, require_url.parseIri("ap://did:key:z6Mkabc/actor"), require_url.parseIri("ap+ef61://did:key:z6Mkabc/outbox")));
|
|
284
|
-
(0, node_assert.ok)(!isTrustedIriOrigin({}, require_url.parseIri("ap://did:key:z6Mkabc/actor"), require_url.parseIri("ap://did:key:z6Mkdef/outbox")));
|
|
285
|
-
(0, node_assert.ok)(isTrustedIriOrigin({ crossOrigin: "trust" }, require_url.parseIri("ap://did:key:z6Mkabc/actor"), require_url.parseIri("ap://did:key:z6Mkdef/outbox")));
|
|
286
|
-
});
|
|
287
|
-
(0, node_test.test)("normalizeJsonLdIris() normalizes selected JSON-LD IRI positions", () => {
|
|
288
|
-
(0, node_assert.deepStrictEqual)(normalizeJsonLdIris({
|
|
289
|
-
"@id": "ap://did:key:z6Mkabc/object",
|
|
290
|
-
"https://example.com/ns#ref": [{ "@value": "ap://did:key:z6Mkabc/ref" }],
|
|
291
|
-
"https://example.com/ns#text": [{ "@value": "ap://did:key:z6Mkabc/not-an-iri-position" }]
|
|
292
|
-
}, new Set(["@id", "https://example.com/ns#ref"])), {
|
|
293
|
-
"@id": "ap+ef61://did:key:z6Mkabc/object",
|
|
294
|
-
"https://example.com/ns#ref": [{ "@value": "ap+ef61://did:key:z6Mkabc/ref" }],
|
|
295
|
-
"https://example.com/ns#text": [{ "@value": "ap://did:key:z6Mkabc/not-an-iri-position" }]
|
|
296
|
-
});
|
|
297
|
-
});
|
|
298
|
-
(0, node_test.test)("normalizeJsonLdIris() preserves IRI context in list/set wrappers", () => {
|
|
299
|
-
(0, node_assert.deepStrictEqual)(normalizeJsonLdIris({ "https://example.com/ns#ref": [{ "@list": [{ "@value": "ap://did:key:z6Mkabc/listed" }] }, { "@set": [{ "@value": "ap://did:key:z6Mkabc/set" }] }] }, new Set(["https://example.com/ns#ref"])), { "https://example.com/ns#ref": [{ "@list": [{ "@value": "ap+ef61://did:key:z6Mkabc/listed" }] }, { "@set": [{ "@value": "ap+ef61://did:key:z6Mkabc/set" }] }] });
|
|
300
|
-
});
|
|
301
|
-
(0, node_test.test)("normalizeJsonLdIris() defines prototype-like keys safely", () => {
|
|
302
|
-
const iriKeys = new Set(["__proto__"]);
|
|
303
|
-
const value = {};
|
|
304
|
-
globalThis.Object.defineProperty(value, "__proto__", {
|
|
305
|
-
value: "ap://did:key:z6Mkabc/object",
|
|
306
|
-
enumerable: true,
|
|
307
|
-
configurable: true,
|
|
308
|
-
writable: true
|
|
309
|
-
});
|
|
310
|
-
const normalized = normalizeJsonLdIris(value, iriKeys);
|
|
311
|
-
(0, node_assert.strictEqual)(globalThis.Object.getOwnPropertyDescriptor(normalized, "__proto__")?.value, "ap+ef61://did:key:z6Mkabc/object");
|
|
312
|
-
(0, node_assert.strictEqual)(globalThis.Object.getPrototypeOf(normalized), Object.prototype);
|
|
313
|
-
});
|
|
314
|
-
(0, node_test.test)("getJsonLdContext() finds nested contexts", () => {
|
|
315
|
-
const context = { name: "https://example.com/ns#name" };
|
|
316
|
-
(0, node_assert.deepStrictEqual)(getJsonLdContext([{ type: "Note" }, { "@context": context }]), context);
|
|
317
|
-
});
|
|
318
|
-
(0, node_test.test)("compactJsonLdCache() preserves no-context object shape", async () => {
|
|
319
|
-
const original = {
|
|
320
|
-
"@id": "ap://did:key:z6Mkabc/objects/1",
|
|
321
|
-
"@type": ["https://www.w3.org/ns/activitystreams#Note"],
|
|
322
|
-
"https://www.w3.org/ns/activitystreams#attributedTo": [{ "@id": "ap://did:key:z6Mkabc/actor" }],
|
|
323
|
-
"https://www.w3.org/ns/activitystreams#content": [{ "@value": "No-context object shape should stay cached." }]
|
|
324
|
-
};
|
|
325
|
-
(0, node_assert.deepStrictEqual)(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id", "https://www.w3.org/ns/activitystreams#attributedTo"])), original), {
|
|
326
|
-
"@id": "ap+ef61://did:key:z6Mkabc/objects/1",
|
|
327
|
-
"@type": ["https://www.w3.org/ns/activitystreams#Note"],
|
|
328
|
-
"https://www.w3.org/ns/activitystreams#attributedTo": [{ "@id": "ap+ef61://did:key:z6Mkabc/actor" }],
|
|
329
|
-
"https://www.w3.org/ns/activitystreams#content": [{ "@value": "No-context object shape should stay cached." }]
|
|
330
|
-
});
|
|
331
|
-
});
|
|
332
|
-
(0, node_test.test)("compactJsonLdCache() ignores nested contexts for no-context parents", async () => {
|
|
333
|
-
const nestedContext = {
|
|
334
|
-
type: "@type",
|
|
335
|
-
name: "https://www.w3.org/ns/activitystreams#name"
|
|
336
|
-
};
|
|
337
|
-
const original = {
|
|
338
|
-
"@id": "ap://did:key:z6Mkabc/objects/1",
|
|
339
|
-
"@type": ["https://www.w3.org/ns/activitystreams#Note"],
|
|
340
|
-
"https://www.w3.org/ns/activitystreams#attachment": [{
|
|
341
|
-
"@context": nestedContext,
|
|
342
|
-
type: "https://www.w3.org/ns/activitystreams#Object",
|
|
343
|
-
name: "Nested object"
|
|
344
|
-
}]
|
|
345
|
-
};
|
|
346
|
-
(0, node_assert.deepStrictEqual)(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original), {
|
|
347
|
-
"@id": "ap+ef61://did:key:z6Mkabc/objects/1",
|
|
348
|
-
"@type": ["https://www.w3.org/ns/activitystreams#Note"],
|
|
349
|
-
"https://www.w3.org/ns/activitystreams#attachment": [{
|
|
350
|
-
"@context": nestedContext,
|
|
351
|
-
type: "https://www.w3.org/ns/activitystreams#Object",
|
|
352
|
-
name: "Nested object"
|
|
353
|
-
}]
|
|
354
|
-
});
|
|
355
|
-
});
|
|
356
|
-
(0, node_test.test)("compactJsonLdCache() defines no-context prototype-like keys safely", async () => {
|
|
357
|
-
const original = { "@id": "ap://did:key:z6Mkabc/objects/1" };
|
|
358
|
-
globalThis.Object.defineProperty(original, "__proto__", {
|
|
359
|
-
value: "ap://did:key:z6Mkabc/proto",
|
|
360
|
-
enumerable: true,
|
|
361
|
-
configurable: true,
|
|
362
|
-
writable: true
|
|
363
|
-
});
|
|
364
|
-
const normalized = { "@id": "ap+ef61://did:key:z6Mkabc/objects/1" };
|
|
365
|
-
globalThis.Object.defineProperty(normalized, "__proto__", {
|
|
366
|
-
value: "ap+ef61://did:key:z6Mkabc/proto",
|
|
367
|
-
enumerable: true,
|
|
368
|
-
configurable: true,
|
|
369
|
-
writable: true
|
|
370
|
-
});
|
|
371
|
-
const compacted = await compactJsonLdCache([normalized], original);
|
|
372
|
-
(0, node_assert.strictEqual)(globalThis.Object.getOwnPropertyDescriptor(compacted, "__proto__")?.value, "ap+ef61://did:key:z6Mkabc/proto");
|
|
373
|
-
(0, node_assert.strictEqual)(globalThis.Object.getPrototypeOf(compacted), Object.prototype);
|
|
374
|
-
});
|
|
375
|
-
(0, node_test.test)("compactJsonLdCache() preserves nested unmapped terms", async () => {
|
|
376
|
-
const context = {
|
|
377
|
-
as: "https://www.w3.org/ns/activitystreams#",
|
|
378
|
-
id: "@id",
|
|
379
|
-
type: "@type",
|
|
380
|
-
attachment: { "@id": "as:attachment" },
|
|
381
|
-
name: "as:name"
|
|
382
|
-
};
|
|
383
|
-
const original = {
|
|
384
|
-
"@context": context,
|
|
385
|
-
type: "as:Note",
|
|
386
|
-
id: "ap://did:key:z6Mkabc/objects/1",
|
|
387
|
-
attachment: {
|
|
388
|
-
type: "as:Object",
|
|
389
|
-
name: "Attachment with an unmapped extension.",
|
|
390
|
-
extra: "This nested unmapped property should stay cached."
|
|
391
|
-
}
|
|
392
|
-
};
|
|
393
|
-
(0, node_assert.deepStrictEqual)(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original), {
|
|
394
|
-
"@context": context,
|
|
395
|
-
type: "as:Note",
|
|
396
|
-
id: "ap+ef61://did:key:z6Mkabc/objects/1",
|
|
397
|
-
attachment: {
|
|
398
|
-
type: "as:Object",
|
|
399
|
-
name: "Attachment with an unmapped extension.",
|
|
400
|
-
extra: "This nested unmapped property should stay cached."
|
|
401
|
-
}
|
|
402
|
-
});
|
|
403
|
-
});
|
|
404
|
-
(0, node_test.test)("compactJsonLdCache() reuses unchanged unmapped values", async () => {
|
|
405
|
-
const context = {
|
|
406
|
-
as: "https://www.w3.org/ns/activitystreams#",
|
|
407
|
-
id: "@id",
|
|
408
|
-
type: "@type",
|
|
409
|
-
attachment: { "@id": "as:attachment" },
|
|
410
|
-
name: "as:name"
|
|
411
|
-
};
|
|
412
|
-
const extra = { source: "unchanged nested extension" };
|
|
413
|
-
const rootExtra = { source: "unchanged root extension" };
|
|
414
|
-
const original = {
|
|
415
|
-
"@context": context,
|
|
416
|
-
type: "as:Note",
|
|
417
|
-
id: "ap://did:key:z6Mkabc/objects/1",
|
|
418
|
-
rootExtra,
|
|
419
|
-
attachment: {
|
|
420
|
-
type: "as:Object",
|
|
421
|
-
name: "Attachment with an unmapped extension.",
|
|
422
|
-
extra
|
|
423
|
-
}
|
|
424
|
-
};
|
|
425
|
-
const compacted = await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original);
|
|
426
|
-
(0, node_assert.strictEqual)(compacted.rootExtra, rootExtra);
|
|
427
|
-
(0, node_assert.strictEqual)(compacted.attachment.extra, extra);
|
|
428
|
-
});
|
|
429
|
-
(0, node_test.test)("compactJsonLdCache() defines prototype-like unmapped keys safely", async () => {
|
|
430
|
-
const context = {
|
|
431
|
-
id: "@id",
|
|
432
|
-
type: "@type"
|
|
433
|
-
};
|
|
434
|
-
const protoValue = { source: "own __proto__ extension" };
|
|
435
|
-
const original = {
|
|
436
|
-
"@context": context,
|
|
437
|
-
type: "https://example.com/ns#Object",
|
|
438
|
-
id: "ap://did:key:z6Mkabc/objects/1"
|
|
439
|
-
};
|
|
440
|
-
globalThis.Object.defineProperty(original, "__proto__", {
|
|
441
|
-
value: protoValue,
|
|
442
|
-
enumerable: true,
|
|
443
|
-
configurable: true,
|
|
444
|
-
writable: true
|
|
445
|
-
});
|
|
446
|
-
const compacted = await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original);
|
|
447
|
-
(0, node_assert.strictEqual)(globalThis.Object.getOwnPropertyDescriptor(compacted, "__proto__")?.value, protoValue);
|
|
448
|
-
(0, node_assert.strictEqual)(globalThis.Object.getPrototypeOf(compacted), Object.prototype);
|
|
449
|
-
});
|
|
450
|
-
(0, node_test.test)("compactJsonLdCache() checks prototype-like aliases safely", async () => {
|
|
451
|
-
const context = {
|
|
452
|
-
ex: "https://example.com/ns#",
|
|
453
|
-
id: "@id",
|
|
454
|
-
represented: "ex:represented"
|
|
455
|
-
};
|
|
456
|
-
globalThis.Object.defineProperty(context, "__proto__", {
|
|
457
|
-
value: "ex:represented",
|
|
458
|
-
enumerable: true,
|
|
459
|
-
configurable: true,
|
|
460
|
-
writable: true
|
|
461
|
-
});
|
|
462
|
-
const original = {
|
|
463
|
-
"@context": context,
|
|
464
|
-
id: "ap://did:key:z6Mkabc/objects/1",
|
|
465
|
-
represented: "Compacted term already present."
|
|
466
|
-
};
|
|
467
|
-
globalThis.Object.defineProperty(original, "__proto__", {
|
|
468
|
-
value: "Alias represented by the compacted term.",
|
|
469
|
-
enumerable: true,
|
|
470
|
-
configurable: true,
|
|
471
|
-
writable: true
|
|
472
|
-
});
|
|
473
|
-
const compacted = await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original);
|
|
474
|
-
const protoDescriptor = globalThis.Object.getOwnPropertyDescriptor(compacted, "__proto__");
|
|
475
|
-
(0, node_assert.ok)(protoDescriptor?.value === "Alias represented by the compacted term." || Array.isArray(protoDescriptor?.value) && protoDescriptor.value.includes("Alias represented by the compacted term."));
|
|
476
|
-
(0, node_assert.strictEqual)(protoDescriptor?.enumerable, true);
|
|
477
|
-
(0, node_assert.strictEqual)(compacted.id, "ap+ef61://did:key:z6Mkabc/objects/1");
|
|
478
|
-
(0, node_assert.strictEqual)(globalThis.Object.getPrototypeOf(compacted), Object.prototype);
|
|
479
|
-
});
|
|
480
|
-
(0, node_test.test)("compactJsonLdCache() preserves nested contexts", async () => {
|
|
481
|
-
const context = {
|
|
482
|
-
as: "https://www.w3.org/ns/activitystreams#",
|
|
483
|
-
id: "@id",
|
|
484
|
-
type: "@type",
|
|
485
|
-
attachment: { "@id": "as:attachment" },
|
|
486
|
-
name: "as:name"
|
|
487
|
-
};
|
|
488
|
-
const nestedContext = {
|
|
489
|
-
id: "@id",
|
|
490
|
-
type: "@type",
|
|
491
|
-
title: "https://example.com/ns#title"
|
|
492
|
-
};
|
|
493
|
-
const original = {
|
|
494
|
-
"@context": context,
|
|
495
|
-
type: "as:Note",
|
|
496
|
-
id: "ap://did:key:z6Mkabc/objects/1",
|
|
497
|
-
attachment: {
|
|
498
|
-
"@context": nestedContext,
|
|
499
|
-
type: "as:Object",
|
|
500
|
-
title: "Nested title."
|
|
501
|
-
}
|
|
502
|
-
};
|
|
503
|
-
(0, node_assert.deepStrictEqual)(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original), {
|
|
504
|
-
"@context": context,
|
|
505
|
-
type: "as:Note",
|
|
506
|
-
id: "ap+ef61://did:key:z6Mkabc/objects/1",
|
|
507
|
-
attachment: {
|
|
508
|
-
"@context": nestedContext,
|
|
509
|
-
type: "as:Object",
|
|
510
|
-
"https://example.com/ns#title": "Nested title."
|
|
511
|
-
}
|
|
512
|
-
});
|
|
513
|
-
});
|
|
514
|
-
(0, node_test.test)("compactJsonLdCache() preserves nested array contexts", async () => {
|
|
515
|
-
const context = {
|
|
516
|
-
as: "https://www.w3.org/ns/activitystreams#",
|
|
517
|
-
id: "@id",
|
|
518
|
-
type: "@type",
|
|
519
|
-
attachment: { "@id": "as:attachment" }
|
|
520
|
-
};
|
|
521
|
-
const nestedContext = [{
|
|
522
|
-
id: "@id",
|
|
523
|
-
type: "@type"
|
|
524
|
-
}, { title: "https://example.com/ns#title" }];
|
|
525
|
-
const original = {
|
|
526
|
-
"@context": context,
|
|
527
|
-
type: "as:Note",
|
|
528
|
-
id: "ap://did:key:z6Mkabc/objects/1",
|
|
529
|
-
attachment: {
|
|
530
|
-
"@context": nestedContext,
|
|
531
|
-
type: "as:Object",
|
|
532
|
-
title: "Nested title."
|
|
533
|
-
}
|
|
534
|
-
};
|
|
535
|
-
(0, node_assert.deepStrictEqual)(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original), {
|
|
536
|
-
"@context": context,
|
|
537
|
-
type: "as:Note",
|
|
538
|
-
id: "ap+ef61://did:key:z6Mkabc/objects/1",
|
|
539
|
-
attachment: {
|
|
540
|
-
"@context": nestedContext,
|
|
541
|
-
type: "as:Object",
|
|
542
|
-
"https://example.com/ns#title": "Nested title."
|
|
543
|
-
}
|
|
544
|
-
});
|
|
545
|
-
});
|
|
546
|
-
(0, node_test.test)("compactJsonLdCache() preserves nested null contexts", async () => {
|
|
547
|
-
const context = {
|
|
548
|
-
as: "https://www.w3.org/ns/activitystreams#",
|
|
549
|
-
id: "@id",
|
|
550
|
-
type: "@type",
|
|
551
|
-
attachment: { "@id": "as:attachment" },
|
|
552
|
-
title: "https://example.com/ns#title"
|
|
553
|
-
};
|
|
554
|
-
const original = {
|
|
555
|
-
"@context": context,
|
|
556
|
-
type: "as:Note",
|
|
557
|
-
id: "ap://did:key:z6Mkabc/objects/1",
|
|
558
|
-
attachment: {
|
|
559
|
-
"@context": null,
|
|
560
|
-
"https://example.com/ns#title": "Absolute title."
|
|
561
|
-
}
|
|
562
|
-
};
|
|
563
|
-
(0, node_assert.deepStrictEqual)(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original), {
|
|
564
|
-
"@context": context,
|
|
565
|
-
type: "as:Note",
|
|
566
|
-
id: "ap+ef61://did:key:z6Mkabc/objects/1",
|
|
567
|
-
attachment: {
|
|
568
|
-
"@context": null,
|
|
569
|
-
"https://example.com/ns#title": "Absolute title."
|
|
570
|
-
}
|
|
571
|
-
});
|
|
572
|
-
});
|
|
573
|
-
(0, node_test.test)("compactJsonLdCache() does not re-add represented nested aliases", async () => {
|
|
574
|
-
const context = {
|
|
575
|
-
as: "https://www.w3.org/ns/activitystreams#",
|
|
576
|
-
id: "@id",
|
|
577
|
-
type: "@type",
|
|
578
|
-
attachment: { "@id": "as:attachment" },
|
|
579
|
-
actor: {
|
|
580
|
-
"@id": "as:actor",
|
|
581
|
-
"@type": "@id"
|
|
582
|
-
}
|
|
583
|
-
};
|
|
584
|
-
const nestedContext = {
|
|
585
|
-
id: "@id",
|
|
586
|
-
type: "@type",
|
|
587
|
-
actorRef: {
|
|
588
|
-
"@id": "as:actor",
|
|
589
|
-
"@type": "@id"
|
|
590
|
-
}
|
|
591
|
-
};
|
|
592
|
-
const original = {
|
|
593
|
-
"@context": context,
|
|
594
|
-
type: "as:Note",
|
|
595
|
-
id: "ap://did:key:z6Mkabc/objects/1",
|
|
596
|
-
attachment: {
|
|
597
|
-
"@context": nestedContext,
|
|
598
|
-
type: "as:Object",
|
|
599
|
-
actorRef: "ap://did:key:z6Mkabc/actor"
|
|
600
|
-
}
|
|
601
|
-
};
|
|
602
|
-
(0, node_assert.deepStrictEqual)(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id", "https://www.w3.org/ns/activitystreams#actor"])), original), {
|
|
603
|
-
"@context": context,
|
|
604
|
-
type: "as:Note",
|
|
605
|
-
id: "ap+ef61://did:key:z6Mkabc/objects/1",
|
|
606
|
-
attachment: {
|
|
607
|
-
"@context": nestedContext,
|
|
608
|
-
type: "as:Object",
|
|
609
|
-
actor: "ap+ef61://did:key:z6Mkabc/actor"
|
|
610
|
-
}
|
|
611
|
-
});
|
|
612
|
-
});
|
|
613
|
-
(0, node_test.test)("compactJsonLdCache() does not confuse dummy marker prefixes", async () => {
|
|
614
|
-
const context = {
|
|
615
|
-
ex: "https://example.com/ns#",
|
|
616
|
-
id: "@id",
|
|
617
|
-
represented: "ex:represented",
|
|
618
|
-
key10: "ex:represented"
|
|
619
|
-
};
|
|
620
|
-
const original = {
|
|
621
|
-
"@context": context,
|
|
622
|
-
id: "ap://did:key:z6Mkabc/objects/1",
|
|
623
|
-
represented: "Compacted term already present.",
|
|
624
|
-
key0: "Extension 0",
|
|
625
|
-
key1: "Extension 1",
|
|
626
|
-
key2: "Extension 2",
|
|
627
|
-
key3: "Extension 3",
|
|
628
|
-
key4: "Extension 4",
|
|
629
|
-
key5: "Extension 5",
|
|
630
|
-
key6: "Extension 6",
|
|
631
|
-
key7: "Extension 7",
|
|
632
|
-
key8: "Extension 8",
|
|
633
|
-
key9: "Extension 9",
|
|
634
|
-
key10: "Alias represented by the compacted term."
|
|
635
|
-
};
|
|
636
|
-
(0, node_assert.deepStrictEqual)(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original), {
|
|
637
|
-
"@context": context,
|
|
638
|
-
id: "ap+ef61://did:key:z6Mkabc/objects/1",
|
|
639
|
-
key0: "Extension 0",
|
|
640
|
-
key1: "Extension 1",
|
|
641
|
-
key2: "Extension 2",
|
|
642
|
-
key3: "Extension 3",
|
|
643
|
-
key4: "Extension 4",
|
|
644
|
-
key5: "Extension 5",
|
|
645
|
-
key6: "Extension 6",
|
|
646
|
-
key7: "Extension 7",
|
|
647
|
-
key8: "Extension 8",
|
|
648
|
-
key9: "Extension 9",
|
|
649
|
-
key10: ["Alias represented by the compacted term.", "Compacted term already present."]
|
|
650
|
-
});
|
|
651
|
-
});
|
|
652
|
-
//#endregion
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|