@fedify/vocab-runtime 2.4.0-pr.936.41 → 2.5.0-dev.2271
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 +4 -2
- package/dist/{tests/docloader-Ck8bcBir.mjs → contexts-BK1CqBR5.cjs} +164 -275
- package/dist/{tests/docloader-S_gQZ2tt.cjs → contexts-DPuJ4UYL.js} +160 -294
- package/dist/{docloader-C_dir7Xb.d.ts → docloader-CYwqh5Df.d.cts} +66 -2
- package/dist/{docloader-D2DTRiyA.d.cts → docloader-CYwqh5Df.d.ts} +66 -2
- package/dist/internal/jsonld-cache.cjs +70 -1
- package/dist/internal/jsonld-cache.d.cts +35 -2
- package/dist/internal/jsonld-cache.d.ts +35 -2
- package/dist/internal/jsonld-cache.js +67 -2
- package/dist/internal/portable-dereference.cjs +721 -0
- package/dist/internal/portable-dereference.d.cts +349 -0
- package/dist/internal/portable-dereference.d.ts +349 -0
- package/dist/internal/portable-dereference.js +702 -0
- package/dist/internal/signed-representation.cjs +378 -0
- package/dist/internal/signed-representation.d.cts +144 -0
- package/dist/internal/signed-representation.d.ts +144 -0
- package/dist/internal/signed-representation.js +371 -0
- package/dist/jsonld.cjs +2 -2
- package/dist/mod.cjs +711 -4527
- package/dist/mod.d.cts +400 -8
- package/dist/mod.d.ts +400 -9
- package/dist/mod.js +692 -4522
- package/dist/portable-DqtfLy_1.d.cts +160 -0
- package/dist/portable-DtWsu2yU.d.ts +160 -0
- package/dist/tests/body-CVR1bABr.mjs +130 -0
- package/dist/tests/body-T_yQWql3.cjs +153 -0
- package/dist/tests/body.test.cjs +89 -0
- package/dist/tests/body.test.d.cts +1 -0
- package/dist/tests/body.test.d.mts +1 -0
- package/dist/tests/body.test.mjs +90 -0
- package/dist/tests/contexts-CIKsin4e.mjs +4512 -0
- package/dist/tests/contexts-DizzBjz4.cjs +4523 -0
- package/dist/tests/decimal.test.cjs +8 -7
- package/dist/tests/decimal.test.mjs +8 -6
- package/dist/tests/digest-3FeH2Y-Q.cjs +176 -0
- package/dist/tests/digest-COC7xDiQ.mjs +141 -0
- package/dist/tests/digest.test.cjs +102 -0
- package/dist/tests/digest.test.d.cts +1 -0
- package/dist/tests/digest.test.d.mts +1 -0
- package/dist/tests/digest.test.mjs +103 -0
- package/dist/tests/docloader-C6yApEts.mjs +373 -0
- package/dist/tests/docloader-CJK2w3l-.cjs +396 -0
- package/dist/tests/docloader.test.cjs +692 -39
- package/dist/tests/docloader.test.mjs +686 -34
- package/dist/tests/internal/multicodec.test.cjs +2 -3
- package/dist/tests/internal/multicodec.test.mjs +2 -2
- package/dist/tests/internal/portable-dereference.test.cjs +172 -0
- package/dist/tests/internal/portable-dereference.test.d.cts +1 -0
- package/dist/tests/internal/portable-dereference.test.d.mts +1 -0
- package/dist/tests/internal/portable-dereference.test.mjs +173 -0
- package/dist/tests/jsonld-cache-BPQmOZWD.mjs +342 -0
- package/dist/tests/jsonld-cache-C07AyNOY.cjs +397 -0
- package/dist/tests/jsonld-cache.test.cjs +101 -298
- package/dist/tests/jsonld-cache.test.mjs +94 -289
- package/dist/tests/{key-_wXwomh_.cjs → key-C-AYkdJJ.cjs} +11 -4
- package/dist/tests/{key-CDGDH_vC.mjs → key-C2Db_TAJ.mjs} +11 -3
- package/dist/tests/key.test.cjs +6 -5
- package/dist/tests/key.test.mjs +6 -4
- package/dist/tests/langstr.test.cjs +4 -4
- package/dist/tests/langstr.test.mjs +2 -2
- package/dist/tests/link.test.cjs +2 -3
- package/dist/tests/link.test.mjs +2 -2
- package/dist/tests/multibase/multibase.test.cjs +8 -9
- package/dist/tests/multibase/multibase.test.mjs +6 -6
- package/dist/tests/{multibase-Bz_UUDtL.cjs → multibase-B5Mea7Ip.cjs} +19 -2
- package/dist/tests/{multibase-B4bvakyA.mjs → multibase-BPnF_L4e.mjs} +12 -1
- package/dist/tests/portable-dereference-BNXtgg5U.cjs +278 -0
- package/dist/tests/portable-dereference-DRE5bz-l.mjs +249 -0
- package/dist/tests/portable-media-C4LEXJk4.mjs +148 -0
- package/dist/tests/portable-media-D05JJIJg.cjs +153 -0
- package/dist/tests/portable-media.test.cjs +222 -0
- package/dist/tests/portable-media.test.d.cts +1 -0
- package/dist/tests/portable-media.test.d.mts +1 -0
- package/dist/tests/portable-media.test.mjs +223 -0
- package/dist/tests/portable-workers.test.cjs +36 -0
- package/dist/tests/portable-workers.test.d.cts +2 -0
- package/dist/tests/portable-workers.test.d.mts +2 -0
- package/dist/tests/portable-workers.test.mjs +35 -0
- package/dist/tests/{request-uk51rkhO.cjs → request-C-VZ9TLj.cjs} +10 -4
- package/dist/tests/{request-C8CaGwtt.mjs → request-Cf-A3DU-.mjs} +8 -2
- package/dist/tests/request.test.cjs +7 -4
- package/dist/tests/request.test.mjs +5 -2
- package/dist/tests/signed-representation.test.cjs +588 -0
- package/dist/tests/signed-representation.test.d.cts +1 -0
- package/dist/tests/signed-representation.test.d.mts +1 -0
- package/dist/tests/signed-representation.test.mjs +589 -0
- package/dist/tests/temporal.test.cjs +1 -2
- package/dist/tests/temporal.test.mjs +1 -1
- package/dist/tests/url-BNakuZ8k.cjs +998 -0
- package/dist/tests/url-DMxmp7ZG.mjs +859 -0
- package/dist/tests/url.test.cjs +489 -6
- package/dist/tests/url.test.mjs +489 -5
- package/dist/url-DrGTR8yv.cjs +993 -0
- package/dist/url-Dzyp-NsC.js +860 -0
- package/package.json +27 -4
- package/scripts/test-bun.mjs +17 -0
- package/src/body.test.ts +125 -0
- package/src/body.ts +152 -0
- package/src/contexts/cid-v1.json +114 -0
- package/src/contexts/fep-22cd.json +21 -0
- package/src/contexts/miscellany.json +17 -0
- package/src/contexts.ts +39 -1
- package/src/digest.test.ts +220 -0
- package/src/digest.ts +229 -0
- package/src/docloader.test.ts +918 -27
- package/src/docloader.ts +320 -105
- package/src/internal/jsonld-cache.ts +97 -1
- package/src/internal/portable-dereference.test.ts +254 -0
- package/src/internal/portable-dereference.ts +1000 -0
- package/src/internal/signed-representation.ts +565 -0
- package/src/jsonld-cache.test.ts +89 -0
- package/src/key.test.ts +9 -0
- package/src/key.ts +11 -1
- package/src/mod.ts +28 -0
- package/src/multibase/multibase.test.ts +5 -5
- package/src/portable-media.test.ts +293 -0
- package/src/portable-media.ts +264 -0
- package/src/portable-workers.test.ts +81 -0
- package/src/portable.ts +180 -0
- package/src/preprocessor.ts +7 -0
- package/src/request.test.ts +10 -1
- package/src/request.ts +9 -1
- package/src/signed-representation.test.ts +338 -0
- package/src/url.test.ts +823 -3
- package/src/url.ts +700 -23
- package/tsdown.config.ts +2 -0
- package/dist/tests/url-CsOV_B_P.cjs +0 -482
- package/dist/tests/url-Du7RQQgP.mjs +0 -392
- package/dist/url-DD4F0ULf.cjs +0 -483
- package/dist/url-DGVbSVVi.js +0 -393
- /package/dist/{chunk-M78iaK0I.cjs → rolldown-runtime-B7lfambq.cjs} +0 -0
- /package/dist/tests/{langstr-CbAxaeEZ.cjs → langstr-C4Fl80ae.cjs} +0 -0
- /package/dist/tests/{langstr-Di5AvKpB.mjs → langstr-CQ26J_L7.mjs} +0 -0
- /package/dist/tests/{link-NUUWCdnK.mjs → link-Cevmc87v.mjs} +0 -0
- /package/dist/tests/{link-FguCydMA.cjs → link-DlKm8bEr.cjs} +0 -0
- /package/dist/tests/{multicodec-CxGVGa91.cjs → multicodec-CLRPeW4N.cjs} +0 -0
- /package/dist/tests/{multicodec-CyFp54fI.mjs → multicodec-CRIj_05H.mjs} +0 -0
- /package/dist/tests/{chunk-C2EiDwsr.cjs → rolldown-runtime-emK7D4bc.cjs} +0 -0
|
@@ -1,305 +1,108 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
let node_assert = require("node:assert");
|
|
1
|
+
const require_url = require("./url-BNakuZ8k.cjs");
|
|
2
|
+
const require_jsonld_cache = require("./jsonld-cache-C07AyNOY.cjs");
|
|
4
3
|
let node_test = require("node:test");
|
|
5
|
-
let
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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);
|
|
4
|
+
let node_assert = require("node:assert");
|
|
5
|
+
//#region src/jsonld-cache.test.ts
|
|
6
|
+
(0, node_test.test)("getPortableActorGateways() preserves unmapped portable actor gateways", () => {
|
|
7
|
+
const gateways = [
|
|
8
|
+
{ "@value": "https://second.example" },
|
|
9
|
+
{ "@value": "https://first.example" },
|
|
10
|
+
{ "@value": "not a valid gateway" }
|
|
11
|
+
];
|
|
12
|
+
for (const id of [
|
|
13
|
+
"ap://did:key:z6Mkabc/actor",
|
|
14
|
+
"ap+ef61://did:key:z6Mkabc/actor",
|
|
15
|
+
"https://gateway.example/.well-known/apgateway/did:key:z6Mkabc/actor"
|
|
16
|
+
]) {
|
|
17
|
+
const node = {
|
|
18
|
+
"@id": id,
|
|
19
|
+
"http://www.w3.org/ns/ldp#inbox": [{ "@id": `${id}/inbox` }],
|
|
20
|
+
"https://www.w3.org/ns/activitystreams#outbox": [{ "@id": `${id}/outbox` }],
|
|
21
|
+
"_:gateways": gateways
|
|
22
|
+
};
|
|
23
|
+
const original = structuredClone(node);
|
|
24
|
+
(0, node_assert.strictEqual)(require_jsonld_cache.getPortableActorGateways(node), gateways, id);
|
|
25
|
+
(0, node_assert.strictEqual)(require_jsonld_cache.getPortableActorGateways(node, false), void 0, id);
|
|
26
|
+
(0, node_assert.deepStrictEqual)(node, original);
|
|
240
27
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const
|
|
244
|
-
const
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
28
|
+
});
|
|
29
|
+
(0, node_test.test)("getPortableActorGateways() gives mapped gateways precedence", () => {
|
|
30
|
+
const canonical = "https://w3id.org/fep/ef61/gateways";
|
|
31
|
+
const gateways = [{ "@list": [{ "@id": "https://gateway.example" }] }];
|
|
32
|
+
const node = {
|
|
33
|
+
"@id": "ap://did:key:z6Mkabc/actor",
|
|
34
|
+
"http://www.w3.org/ns/ldp#inbox": [],
|
|
35
|
+
"https://www.w3.org/ns/activitystreams#outbox": [],
|
|
36
|
+
"_:gateways": [{ "@value": "https://other.example" }],
|
|
37
|
+
[canonical]: gateways
|
|
38
|
+
};
|
|
39
|
+
(0, node_assert.strictEqual)(require_jsonld_cache.getPortableActorGateways(node), gateways);
|
|
40
|
+
(0, node_assert.strictEqual)(require_jsonld_cache.getPortableActorGateways(node, false), gateways);
|
|
41
|
+
for (const value of [
|
|
42
|
+
void 0,
|
|
43
|
+
null,
|
|
44
|
+
{},
|
|
45
|
+
"https://gateway.example",
|
|
46
|
+
[]
|
|
47
|
+
]) {
|
|
48
|
+
node[canonical] = value;
|
|
49
|
+
(0, node_assert.strictEqual)(require_jsonld_cache.getPortableActorGateways(node), Array.isArray(value) ? value : void 0);
|
|
256
50
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
51
|
+
});
|
|
52
|
+
(0, node_test.test)("getPortableActorGateways() limits unmapped terms to portable actors", () => {
|
|
53
|
+
const node = {
|
|
54
|
+
"@id": "ap://did:key:z6Mkabc/actor",
|
|
55
|
+
"http://www.w3.org/ns/ldp#inbox": [],
|
|
56
|
+
"https://www.w3.org/ns/activitystreams#outbox": [],
|
|
57
|
+
"_:gateways": [{ "@value": "https://gateway.example" }]
|
|
58
|
+
};
|
|
59
|
+
for (const id of [
|
|
60
|
+
void 0,
|
|
61
|
+
1,
|
|
62
|
+
"not an IRI",
|
|
63
|
+
"https://ordinary.example/actor",
|
|
64
|
+
"https://gateway.example/.well-known/apgateway/not-a-did/actor",
|
|
65
|
+
"https://user@gateway.example/.well-known/apgateway/did:key:z6Mkabc/actor"
|
|
66
|
+
]) (0, node_assert.strictEqual)(require_jsonld_cache.getPortableActorGateways({
|
|
67
|
+
...node,
|
|
68
|
+
"@id": id
|
|
69
|
+
}), void 0);
|
|
70
|
+
for (const property of ["http://www.w3.org/ns/ldp#inbox", "https://www.w3.org/ns/activitystreams#outbox"]) {
|
|
71
|
+
const nonActor = { ...node };
|
|
72
|
+
delete nonActor[property];
|
|
73
|
+
(0, node_assert.strictEqual)(require_jsonld_cache.getPortableActorGateways(nonActor), void 0);
|
|
262
74
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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
|
|
75
|
+
(0, node_assert.strictEqual)(require_jsonld_cache.getPortableActorGateways({
|
|
76
|
+
...node,
|
|
77
|
+
"_:gateways": null
|
|
78
|
+
}), void 0);
|
|
79
|
+
const empty = [];
|
|
80
|
+
(0, node_assert.strictEqual)(require_jsonld_cache.getPortableActorGateways({
|
|
81
|
+
...node,
|
|
82
|
+
"_:gateways": empty
|
|
83
|
+
}), empty);
|
|
84
|
+
});
|
|
282
85
|
(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")));
|
|
86
|
+
(0, node_assert.ok)(require_jsonld_cache.isTrustedIriOrigin({}, require_url.parseIri("ap://did:key:z6Mkabc/actor"), require_url.parseIri("ap+ef61://did:key:z6Mkabc/outbox")));
|
|
87
|
+
(0, node_assert.ok)(!require_jsonld_cache.isTrustedIriOrigin({}, require_url.parseIri("ap://did:key:z6Mkabc/actor"), require_url.parseIri("ap://did:key:z6Mkdef/outbox")));
|
|
88
|
+
(0, node_assert.ok)(require_jsonld_cache.isTrustedIriOrigin({ crossOrigin: "trust" }, require_url.parseIri("ap://did:key:z6Mkabc/actor"), require_url.parseIri("ap://did:key:z6Mkdef/outbox")));
|
|
286
89
|
});
|
|
287
90
|
(0, node_test.test)("normalizeJsonLdIris() normalizes selected JSON-LD IRI positions", () => {
|
|
288
|
-
(0, node_assert.deepStrictEqual)(normalizeJsonLdIris({
|
|
91
|
+
(0, node_assert.deepStrictEqual)(require_jsonld_cache.normalizeJsonLdIris({
|
|
289
92
|
"@id": "ap://did:key:z6Mkabc/object",
|
|
290
93
|
"https://example.com/ns#ref": [{ "@value": "ap://did:key:z6Mkabc/ref" }],
|
|
291
94
|
"https://example.com/ns#text": [{ "@value": "ap://did:key:z6Mkabc/not-an-iri-position" }]
|
|
292
|
-
}, new Set(["@id", "https://example.com/ns#ref"])), {
|
|
95
|
+
}, /* @__PURE__ */ new Set(["@id", "https://example.com/ns#ref"])), {
|
|
293
96
|
"@id": "ap+ef61://did:key:z6Mkabc/object",
|
|
294
97
|
"https://example.com/ns#ref": [{ "@value": "ap+ef61://did:key:z6Mkabc/ref" }],
|
|
295
98
|
"https://example.com/ns#text": [{ "@value": "ap://did:key:z6Mkabc/not-an-iri-position" }]
|
|
296
99
|
});
|
|
297
100
|
});
|
|
298
101
|
(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" }] }] });
|
|
102
|
+
(0, node_assert.deepStrictEqual)(require_jsonld_cache.normalizeJsonLdIris({ "https://example.com/ns#ref": [{ "@list": [{ "@value": "ap://did:key:z6Mkabc/listed" }] }, { "@set": [{ "@value": "ap://did:key:z6Mkabc/set" }] }] }, /* @__PURE__ */ 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
103
|
});
|
|
301
104
|
(0, node_test.test)("normalizeJsonLdIris() defines prototype-like keys safely", () => {
|
|
302
|
-
const iriKeys = new Set(["__proto__"]);
|
|
105
|
+
const iriKeys = /* @__PURE__ */ new Set(["__proto__"]);
|
|
303
106
|
const value = {};
|
|
304
107
|
globalThis.Object.defineProperty(value, "__proto__", {
|
|
305
108
|
value: "ap://did:key:z6Mkabc/object",
|
|
@@ -307,13 +110,13 @@ function combineContexts(inheritedContext, ownContext) {
|
|
|
307
110
|
configurable: true,
|
|
308
111
|
writable: true
|
|
309
112
|
});
|
|
310
|
-
const normalized = normalizeJsonLdIris(value, iriKeys);
|
|
113
|
+
const normalized = require_jsonld_cache.normalizeJsonLdIris(value, iriKeys);
|
|
311
114
|
(0, node_assert.strictEqual)(globalThis.Object.getOwnPropertyDescriptor(normalized, "__proto__")?.value, "ap+ef61://did:key:z6Mkabc/object");
|
|
312
115
|
(0, node_assert.strictEqual)(globalThis.Object.getPrototypeOf(normalized), Object.prototype);
|
|
313
116
|
});
|
|
314
117
|
(0, node_test.test)("getJsonLdContext() finds nested contexts", () => {
|
|
315
118
|
const context = { name: "https://example.com/ns#name" };
|
|
316
|
-
(0, node_assert.deepStrictEqual)(getJsonLdContext([{ type: "Note" }, { "@context": context }]), context);
|
|
119
|
+
(0, node_assert.deepStrictEqual)(require_jsonld_cache.getJsonLdContext([{ type: "Note" }, { "@context": context }]), context);
|
|
317
120
|
});
|
|
318
121
|
(0, node_test.test)("compactJsonLdCache() preserves no-context object shape", async () => {
|
|
319
122
|
const original = {
|
|
@@ -322,7 +125,7 @@ function combineContexts(inheritedContext, ownContext) {
|
|
|
322
125
|
"https://www.w3.org/ns/activitystreams#attributedTo": [{ "@id": "ap://did:key:z6Mkabc/actor" }],
|
|
323
126
|
"https://www.w3.org/ns/activitystreams#content": [{ "@value": "No-context object shape should stay cached." }]
|
|
324
127
|
};
|
|
325
|
-
(0, node_assert.deepStrictEqual)(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id", "https://www.w3.org/ns/activitystreams#attributedTo"])), original), {
|
|
128
|
+
(0, node_assert.deepStrictEqual)(await require_jsonld_cache.compactJsonLdCache(require_jsonld_cache.normalizeJsonLdIris(await require_jsonld_cache.jsonld_default.expand(original), /* @__PURE__ */ new Set(["@id", "https://www.w3.org/ns/activitystreams#attributedTo"])), original), {
|
|
326
129
|
"@id": "ap+ef61://did:key:z6Mkabc/objects/1",
|
|
327
130
|
"@type": ["https://www.w3.org/ns/activitystreams#Note"],
|
|
328
131
|
"https://www.w3.org/ns/activitystreams#attributedTo": [{ "@id": "ap+ef61://did:key:z6Mkabc/actor" }],
|
|
@@ -343,7 +146,7 @@ function combineContexts(inheritedContext, ownContext) {
|
|
|
343
146
|
name: "Nested object"
|
|
344
147
|
}]
|
|
345
148
|
};
|
|
346
|
-
(0, node_assert.deepStrictEqual)(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original), {
|
|
149
|
+
(0, node_assert.deepStrictEqual)(await require_jsonld_cache.compactJsonLdCache(require_jsonld_cache.normalizeJsonLdIris(await require_jsonld_cache.jsonld_default.expand(original), /* @__PURE__ */ new Set(["@id"])), original), {
|
|
347
150
|
"@id": "ap+ef61://did:key:z6Mkabc/objects/1",
|
|
348
151
|
"@type": ["https://www.w3.org/ns/activitystreams#Note"],
|
|
349
152
|
"https://www.w3.org/ns/activitystreams#attachment": [{
|
|
@@ -368,7 +171,7 @@ function combineContexts(inheritedContext, ownContext) {
|
|
|
368
171
|
configurable: true,
|
|
369
172
|
writable: true
|
|
370
173
|
});
|
|
371
|
-
const compacted = await compactJsonLdCache([normalized], original);
|
|
174
|
+
const compacted = await require_jsonld_cache.compactJsonLdCache([normalized], original);
|
|
372
175
|
(0, node_assert.strictEqual)(globalThis.Object.getOwnPropertyDescriptor(compacted, "__proto__")?.value, "ap+ef61://did:key:z6Mkabc/proto");
|
|
373
176
|
(0, node_assert.strictEqual)(globalThis.Object.getPrototypeOf(compacted), Object.prototype);
|
|
374
177
|
});
|
|
@@ -390,7 +193,7 @@ function combineContexts(inheritedContext, ownContext) {
|
|
|
390
193
|
extra: "This nested unmapped property should stay cached."
|
|
391
194
|
}
|
|
392
195
|
};
|
|
393
|
-
(0, node_assert.deepStrictEqual)(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original), {
|
|
196
|
+
(0, node_assert.deepStrictEqual)(await require_jsonld_cache.compactJsonLdCache(require_jsonld_cache.normalizeJsonLdIris(await require_jsonld_cache.jsonld_default.expand(original), /* @__PURE__ */ new Set(["@id"])), original), {
|
|
394
197
|
"@context": context,
|
|
395
198
|
type: "as:Note",
|
|
396
199
|
id: "ap+ef61://did:key:z6Mkabc/objects/1",
|
|
@@ -422,7 +225,7 @@ function combineContexts(inheritedContext, ownContext) {
|
|
|
422
225
|
extra
|
|
423
226
|
}
|
|
424
227
|
};
|
|
425
|
-
const compacted = await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original);
|
|
228
|
+
const compacted = await require_jsonld_cache.compactJsonLdCache(require_jsonld_cache.normalizeJsonLdIris(await require_jsonld_cache.jsonld_default.expand(original), /* @__PURE__ */ new Set(["@id"])), original);
|
|
426
229
|
(0, node_assert.strictEqual)(compacted.rootExtra, rootExtra);
|
|
427
230
|
(0, node_assert.strictEqual)(compacted.attachment.extra, extra);
|
|
428
231
|
});
|
|
@@ -443,7 +246,7 @@ function combineContexts(inheritedContext, ownContext) {
|
|
|
443
246
|
configurable: true,
|
|
444
247
|
writable: true
|
|
445
248
|
});
|
|
446
|
-
const compacted = await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original);
|
|
249
|
+
const compacted = await require_jsonld_cache.compactJsonLdCache(require_jsonld_cache.normalizeJsonLdIris(await require_jsonld_cache.jsonld_default.expand(original), /* @__PURE__ */ new Set(["@id"])), original);
|
|
447
250
|
(0, node_assert.strictEqual)(globalThis.Object.getOwnPropertyDescriptor(compacted, "__proto__")?.value, protoValue);
|
|
448
251
|
(0, node_assert.strictEqual)(globalThis.Object.getPrototypeOf(compacted), Object.prototype);
|
|
449
252
|
});
|
|
@@ -470,7 +273,7 @@ function combineContexts(inheritedContext, ownContext) {
|
|
|
470
273
|
configurable: true,
|
|
471
274
|
writable: true
|
|
472
275
|
});
|
|
473
|
-
const compacted = await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original);
|
|
276
|
+
const compacted = await require_jsonld_cache.compactJsonLdCache(require_jsonld_cache.normalizeJsonLdIris(await require_jsonld_cache.jsonld_default.expand(original), /* @__PURE__ */ new Set(["@id"])), original);
|
|
474
277
|
const protoDescriptor = globalThis.Object.getOwnPropertyDescriptor(compacted, "__proto__");
|
|
475
278
|
(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
279
|
(0, node_assert.strictEqual)(protoDescriptor?.enumerable, true);
|
|
@@ -500,7 +303,7 @@ function combineContexts(inheritedContext, ownContext) {
|
|
|
500
303
|
title: "Nested title."
|
|
501
304
|
}
|
|
502
305
|
};
|
|
503
|
-
(0, node_assert.deepStrictEqual)(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original), {
|
|
306
|
+
(0, node_assert.deepStrictEqual)(await require_jsonld_cache.compactJsonLdCache(require_jsonld_cache.normalizeJsonLdIris(await require_jsonld_cache.jsonld_default.expand(original), /* @__PURE__ */ new Set(["@id"])), original), {
|
|
504
307
|
"@context": context,
|
|
505
308
|
type: "as:Note",
|
|
506
309
|
id: "ap+ef61://did:key:z6Mkabc/objects/1",
|
|
@@ -532,7 +335,7 @@ function combineContexts(inheritedContext, ownContext) {
|
|
|
532
335
|
title: "Nested title."
|
|
533
336
|
}
|
|
534
337
|
};
|
|
535
|
-
(0, node_assert.deepStrictEqual)(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original), {
|
|
338
|
+
(0, node_assert.deepStrictEqual)(await require_jsonld_cache.compactJsonLdCache(require_jsonld_cache.normalizeJsonLdIris(await require_jsonld_cache.jsonld_default.expand(original), /* @__PURE__ */ new Set(["@id"])), original), {
|
|
536
339
|
"@context": context,
|
|
537
340
|
type: "as:Note",
|
|
538
341
|
id: "ap+ef61://did:key:z6Mkabc/objects/1",
|
|
@@ -560,7 +363,7 @@ function combineContexts(inheritedContext, ownContext) {
|
|
|
560
363
|
"https://example.com/ns#title": "Absolute title."
|
|
561
364
|
}
|
|
562
365
|
};
|
|
563
|
-
(0, node_assert.deepStrictEqual)(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original), {
|
|
366
|
+
(0, node_assert.deepStrictEqual)(await require_jsonld_cache.compactJsonLdCache(require_jsonld_cache.normalizeJsonLdIris(await require_jsonld_cache.jsonld_default.expand(original), /* @__PURE__ */ new Set(["@id"])), original), {
|
|
564
367
|
"@context": context,
|
|
565
368
|
type: "as:Note",
|
|
566
369
|
id: "ap+ef61://did:key:z6Mkabc/objects/1",
|
|
@@ -599,7 +402,7 @@ function combineContexts(inheritedContext, ownContext) {
|
|
|
599
402
|
actorRef: "ap://did:key:z6Mkabc/actor"
|
|
600
403
|
}
|
|
601
404
|
};
|
|
602
|
-
(0, node_assert.deepStrictEqual)(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id", "https://www.w3.org/ns/activitystreams#actor"])), original), {
|
|
405
|
+
(0, node_assert.deepStrictEqual)(await require_jsonld_cache.compactJsonLdCache(require_jsonld_cache.normalizeJsonLdIris(await require_jsonld_cache.jsonld_default.expand(original), /* @__PURE__ */ new Set(["@id", "https://www.w3.org/ns/activitystreams#actor"])), original), {
|
|
603
406
|
"@context": context,
|
|
604
407
|
type: "as:Note",
|
|
605
408
|
id: "ap+ef61://did:key:z6Mkabc/objects/1",
|
|
@@ -633,7 +436,7 @@ function combineContexts(inheritedContext, ownContext) {
|
|
|
633
436
|
key9: "Extension 9",
|
|
634
437
|
key10: "Alias represented by the compacted term."
|
|
635
438
|
};
|
|
636
|
-
(0, node_assert.deepStrictEqual)(await compactJsonLdCache(normalizeJsonLdIris(await jsonld_default.expand(original), new Set(["@id"])), original), {
|
|
439
|
+
(0, node_assert.deepStrictEqual)(await require_jsonld_cache.compactJsonLdCache(require_jsonld_cache.normalizeJsonLdIris(await require_jsonld_cache.jsonld_default.expand(original), /* @__PURE__ */ new Set(["@id"])), original), {
|
|
637
440
|
"@context": context,
|
|
638
441
|
id: "ap+ef61://did:key:z6Mkabc/objects/1",
|
|
639
442
|
key0: "Extension 0",
|