@fedify/vocab-runtime 2.4.0-pr.936.41 → 2.4.0

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.
Files changed (138) hide show
  1. package/deno.json +4 -2
  2. package/dist/{tests/docloader-Ck8bcBir.mjs → contexts-BK1CqBR5.cjs} +164 -275
  3. package/dist/{tests/docloader-S_gQZ2tt.cjs → contexts-DPuJ4UYL.js} +160 -294
  4. package/dist/{docloader-C_dir7Xb.d.ts → docloader-CYwqh5Df.d.cts} +66 -2
  5. package/dist/{docloader-D2DTRiyA.d.cts → docloader-CYwqh5Df.d.ts} +66 -2
  6. package/dist/internal/jsonld-cache.cjs +70 -1
  7. package/dist/internal/jsonld-cache.d.cts +35 -2
  8. package/dist/internal/jsonld-cache.d.ts +35 -2
  9. package/dist/internal/jsonld-cache.js +67 -2
  10. package/dist/internal/portable-dereference.cjs +721 -0
  11. package/dist/internal/portable-dereference.d.cts +349 -0
  12. package/dist/internal/portable-dereference.d.ts +349 -0
  13. package/dist/internal/portable-dereference.js +702 -0
  14. package/dist/internal/signed-representation.cjs +378 -0
  15. package/dist/internal/signed-representation.d.cts +144 -0
  16. package/dist/internal/signed-representation.d.ts +144 -0
  17. package/dist/internal/signed-representation.js +371 -0
  18. package/dist/jsonld.cjs +2 -2
  19. package/dist/mod.cjs +711 -4527
  20. package/dist/mod.d.cts +400 -8
  21. package/dist/mod.d.ts +400 -9
  22. package/dist/mod.js +692 -4522
  23. package/dist/portable-DqtfLy_1.d.cts +160 -0
  24. package/dist/portable-DtWsu2yU.d.ts +160 -0
  25. package/dist/tests/body-CYiu9CO-.mjs +130 -0
  26. package/dist/tests/body-CkEwROsn.cjs +153 -0
  27. package/dist/tests/body.test.cjs +89 -0
  28. package/dist/tests/body.test.d.cts +1 -0
  29. package/dist/tests/body.test.d.mts +1 -0
  30. package/dist/tests/body.test.mjs +90 -0
  31. package/dist/tests/contexts-CIKsin4e.mjs +4512 -0
  32. package/dist/tests/contexts-DizzBjz4.cjs +4523 -0
  33. package/dist/tests/decimal.test.cjs +8 -7
  34. package/dist/tests/decimal.test.mjs +8 -6
  35. package/dist/tests/digest-3FeH2Y-Q.cjs +176 -0
  36. package/dist/tests/digest-COC7xDiQ.mjs +141 -0
  37. package/dist/tests/digest.test.cjs +102 -0
  38. package/dist/tests/digest.test.d.cts +1 -0
  39. package/dist/tests/digest.test.d.mts +1 -0
  40. package/dist/tests/digest.test.mjs +103 -0
  41. package/dist/tests/docloader-C3YFl6y4.cjs +396 -0
  42. package/dist/tests/docloader-CvmS4sVq.mjs +373 -0
  43. package/dist/tests/docloader.test.cjs +692 -39
  44. package/dist/tests/docloader.test.mjs +686 -34
  45. package/dist/tests/internal/multicodec.test.cjs +2 -3
  46. package/dist/tests/internal/multicodec.test.mjs +2 -2
  47. package/dist/tests/internal/portable-dereference.test.cjs +172 -0
  48. package/dist/tests/internal/portable-dereference.test.d.cts +1 -0
  49. package/dist/tests/internal/portable-dereference.test.d.mts +1 -0
  50. package/dist/tests/internal/portable-dereference.test.mjs +173 -0
  51. package/dist/tests/jsonld-cache-BPQmOZWD.mjs +342 -0
  52. package/dist/tests/jsonld-cache-C07AyNOY.cjs +397 -0
  53. package/dist/tests/jsonld-cache.test.cjs +101 -298
  54. package/dist/tests/jsonld-cache.test.mjs +94 -289
  55. package/dist/tests/{key-_wXwomh_.cjs → key-C-AYkdJJ.cjs} +11 -4
  56. package/dist/tests/{key-CDGDH_vC.mjs → key-C2Db_TAJ.mjs} +11 -3
  57. package/dist/tests/key.test.cjs +6 -5
  58. package/dist/tests/key.test.mjs +6 -4
  59. package/dist/tests/langstr.test.cjs +4 -4
  60. package/dist/tests/langstr.test.mjs +2 -2
  61. package/dist/tests/link.test.cjs +2 -3
  62. package/dist/tests/link.test.mjs +2 -2
  63. package/dist/tests/multibase/multibase.test.cjs +8 -9
  64. package/dist/tests/multibase/multibase.test.mjs +6 -6
  65. package/dist/tests/{multibase-Bz_UUDtL.cjs → multibase-B5Mea7Ip.cjs} +19 -2
  66. package/dist/tests/{multibase-B4bvakyA.mjs → multibase-BPnF_L4e.mjs} +12 -1
  67. package/dist/tests/portable-dereference-BNXtgg5U.cjs +278 -0
  68. package/dist/tests/portable-dereference-DRE5bz-l.mjs +249 -0
  69. package/dist/tests/portable-media-BLKllU56.cjs +153 -0
  70. package/dist/tests/portable-media-DRSGBORB.mjs +148 -0
  71. package/dist/tests/portable-media.test.cjs +222 -0
  72. package/dist/tests/portable-media.test.d.cts +1 -0
  73. package/dist/tests/portable-media.test.d.mts +1 -0
  74. package/dist/tests/portable-media.test.mjs +223 -0
  75. package/dist/tests/portable-workers.test.cjs +36 -0
  76. package/dist/tests/portable-workers.test.d.cts +2 -0
  77. package/dist/tests/portable-workers.test.d.mts +2 -0
  78. package/dist/tests/portable-workers.test.mjs +35 -0
  79. package/dist/tests/{request-uk51rkhO.cjs → request-8vPWtV1-.cjs} +10 -4
  80. package/dist/tests/{request-C8CaGwtt.mjs → request-DRaOaTqD.mjs} +8 -2
  81. package/dist/tests/request.test.cjs +7 -4
  82. package/dist/tests/request.test.mjs +5 -2
  83. package/dist/tests/signed-representation.test.cjs +588 -0
  84. package/dist/tests/signed-representation.test.d.cts +1 -0
  85. package/dist/tests/signed-representation.test.d.mts +1 -0
  86. package/dist/tests/signed-representation.test.mjs +589 -0
  87. package/dist/tests/temporal.test.cjs +1 -2
  88. package/dist/tests/temporal.test.mjs +1 -1
  89. package/dist/tests/url-BNakuZ8k.cjs +998 -0
  90. package/dist/tests/url-DMxmp7ZG.mjs +859 -0
  91. package/dist/tests/url.test.cjs +489 -6
  92. package/dist/tests/url.test.mjs +489 -5
  93. package/dist/url-DrGTR8yv.cjs +993 -0
  94. package/dist/url-Dzyp-NsC.js +860 -0
  95. package/package.json +27 -4
  96. package/scripts/test-bun.mjs +17 -0
  97. package/src/body.test.ts +125 -0
  98. package/src/body.ts +152 -0
  99. package/src/contexts/cid-v1.json +114 -0
  100. package/src/contexts/fep-22cd.json +21 -0
  101. package/src/contexts/miscellany.json +17 -0
  102. package/src/contexts.ts +39 -1
  103. package/src/digest.test.ts +220 -0
  104. package/src/digest.ts +229 -0
  105. package/src/docloader.test.ts +918 -27
  106. package/src/docloader.ts +320 -105
  107. package/src/internal/jsonld-cache.ts +97 -1
  108. package/src/internal/portable-dereference.test.ts +254 -0
  109. package/src/internal/portable-dereference.ts +1000 -0
  110. package/src/internal/signed-representation.ts +565 -0
  111. package/src/jsonld-cache.test.ts +89 -0
  112. package/src/key.test.ts +9 -0
  113. package/src/key.ts +11 -1
  114. package/src/mod.ts +28 -0
  115. package/src/multibase/multibase.test.ts +5 -5
  116. package/src/portable-media.test.ts +293 -0
  117. package/src/portable-media.ts +264 -0
  118. package/src/portable-workers.test.ts +81 -0
  119. package/src/portable.ts +180 -0
  120. package/src/preprocessor.ts +7 -0
  121. package/src/request.test.ts +10 -1
  122. package/src/request.ts +9 -1
  123. package/src/signed-representation.test.ts +338 -0
  124. package/src/url.test.ts +823 -3
  125. package/src/url.ts +700 -23
  126. package/tsdown.config.ts +2 -0
  127. package/dist/tests/url-CsOV_B_P.cjs +0 -482
  128. package/dist/tests/url-Du7RQQgP.mjs +0 -392
  129. package/dist/url-DD4F0ULf.cjs +0 -483
  130. package/dist/url-DGVbSVVi.js +0 -393
  131. /package/dist/{chunk-M78iaK0I.cjs → rolldown-runtime-B7lfambq.cjs} +0 -0
  132. /package/dist/tests/{langstr-CbAxaeEZ.cjs → langstr-C4Fl80ae.cjs} +0 -0
  133. /package/dist/tests/{langstr-Di5AvKpB.mjs → langstr-CQ26J_L7.mjs} +0 -0
  134. /package/dist/tests/{link-NUUWCdnK.mjs → link-Cevmc87v.mjs} +0 -0
  135. /package/dist/tests/{link-FguCydMA.cjs → link-DlKm8bEr.cjs} +0 -0
  136. /package/dist/tests/{multicodec-CxGVGa91.cjs → multicodec-CLRPeW4N.cjs} +0 -0
  137. /package/dist/tests/{multicodec-CyFp54fI.mjs → multicodec-CRIj_05H.mjs} +0 -0
  138. /package/dist/tests/{chunk-C2EiDwsr.cjs → rolldown-runtime-emK7D4bc.cjs} +0 -0
@@ -0,0 +1,397 @@
1
+ const require_rolldown_runtime = require("./rolldown-runtime-emK7D4bc.cjs");
2
+ const require_url = require("./url-BNakuZ8k.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
+ /**
10
+ * Reads expanded gateways, including an unmapped term on portable actors.
11
+ * The original values and their order are preserved for URL validation by
12
+ * the caller. An explicitly mapped FEP-ef61 property always takes precedence.
13
+ * @internal Used by generated vocabulary classes and portable proof checks.
14
+ */
15
+ function getPortableActorGateways(node, allowUnmapped = true) {
16
+ const property = "https://w3id.org/fep/ef61/gateways";
17
+ if (globalThis.Object.hasOwn(node, property)) return Array.isArray(node[property]) ? node[property] : void 0;
18
+ if (!allowUnmapped || typeof node["@id"] !== "string" || !("http://www.w3.org/ns/ldp#inbox" in node) || !("https://www.w3.org/ns/activitystreams#outbox" in node)) return void 0;
19
+ try {
20
+ if (!require_url.getFe34Origin(require_url.parseIri(require_url.fromCompatibleEf61Id(node["@id"]) ?? node["@id"])).startsWith("did:")) return void 0;
21
+ } catch (error) {
22
+ if (error instanceof TypeError) return void 0;
23
+ throw error;
24
+ }
25
+ return Array.isArray(node["_:gateways"]) ? node["_:gateways"] : void 0;
26
+ }
27
+ const noJsonLdContext = Symbol("noJsonLdContext");
28
+ const documentLoaderWrappers = /* @__PURE__ */ new WeakMap();
29
+ /**
30
+ * Registers a loader wrapper with the shared released-wrapper registry.
31
+ * Both suppression and snapshot wrappers must use this registry so mixed
32
+ * chains can be unwrapped. The caller updates the state on release.
33
+ * @internal Not a public API.
34
+ */
35
+ function registerDocumentLoaderWrapper(loader, state) {
36
+ documentLoaderWrappers.set(loader, state);
37
+ }
38
+ /**
39
+ * Removes released loader wrappers, stopping at the first active wrapper.
40
+ * Active wrappers retain their operation's suppression or snapshot cache.
41
+ * @internal Not a public API.
42
+ */
43
+ function unwrapReleasedDocumentLoader(base) {
44
+ for (let state = documentLoaderWrappers.get(base); state?.released; state = documentLoaderWrappers.get(base)) base = state.base;
45
+ return base;
46
+ }
47
+ /**
48
+ * Lowers context loading failure logs for one accessor operation. Parsed
49
+ * objects retain the loader, so release it before returning to the caller.
50
+ * Released wrappers are unwrapped to avoid accumulating loader chains.
51
+ * @internal Used by generated vocabulary accessors; not a public API.
52
+ */
53
+ function createScopedContextLoader(base, suppressError) {
54
+ base = unwrapReleasedDocumentLoader(base);
55
+ if (!suppressError) return {
56
+ loader: base,
57
+ release: () => {}
58
+ };
59
+ const state = {
60
+ base,
61
+ released: false
62
+ };
63
+ const loader = (url, options) => base(url, state.released ? options : {
64
+ ...options,
65
+ suppressError: true
66
+ });
67
+ registerDocumentLoaderWrapper(loader, state);
68
+ return {
69
+ loader,
70
+ release: () => {
71
+ state.released = true;
72
+ }
73
+ };
74
+ }
75
+ /**
76
+ * Checks whether an IRI is trusted relative to another IRI.
77
+ *
78
+ * @internal Technically exported for generated vocabulary classes, but not
79
+ * part of the public API contract. This is not considered public API for
80
+ * Semantic Versioning decisions.
81
+ */
82
+ function isTrustedIriOrigin(options, left, right) {
83
+ return options.crossOrigin === "trust" || left == null || right != null && (require_url.haveSameIriOrigin(left, right) || require_url.haveSameFe34Origin(left, right));
84
+ }
85
+ /**
86
+ * Normalizes portable IRIs in JSON-LD cache data.
87
+ *
88
+ * @internal Technically exported for generated vocabulary classes, but not
89
+ * part of the public API contract. This is not considered public API for
90
+ * Semantic Versioning decisions.
91
+ */
92
+ function normalizeJsonLdIris(value, iriKeys, iriPattern = /^ap(?:\+ef61)?:\/\//i) {
93
+ return normalize(value, void 0, 0, void 0);
94
+ function isIriPosition(key, parentKey) {
95
+ return iriKeys.has(key) || (key === "@value" || key === "@list" || key === "@set") && parentKey != null && iriKeys.has(parentKey);
96
+ }
97
+ function arrayItemParentKey(key, parentKey) {
98
+ return key === "@list" || key === "@set" ? parentKey : key;
99
+ }
100
+ function entryParentKey(entryKey, key, parentKey) {
101
+ if (entryKey === "@list" || entryKey === "@set") return parentKey ?? key;
102
+ return key === "@list" || key === "@set" ? parentKey : key;
103
+ }
104
+ function normalize(value, key, depth = 0, parentKey) {
105
+ if (depth > 32 || key === "@context") return value;
106
+ if (typeof value === "string") {
107
+ if (key != null && isIriPosition(key, parentKey) && iriPattern.test(value)) try {
108
+ return require_url.formatIri(value);
109
+ } catch {
110
+ return value;
111
+ }
112
+ return value;
113
+ }
114
+ if (Array.isArray(value)) {
115
+ let clone;
116
+ const itemParentKey = arrayItemParentKey(key, parentKey);
117
+ for (let i = 0; i < value.length; i++) {
118
+ const result = normalize(value[i], key, depth + 1, itemParentKey);
119
+ if (result !== value[i]) {
120
+ clone ??= value.slice(0, i);
121
+ clone.push(result);
122
+ } else if (clone != null) clone.push(value[i]);
123
+ }
124
+ return clone ?? value;
125
+ }
126
+ if (value == null || typeof value !== "object") return value;
127
+ const object = value;
128
+ let clone;
129
+ for (const entryKey of globalThis.Object.keys(object)) {
130
+ const result = normalize(object[entryKey], entryKey, depth + 1, entryParentKey(entryKey, key, parentKey));
131
+ if (result !== object[entryKey]) {
132
+ clone ??= { ...object };
133
+ defineJsonLdProperty(clone, entryKey, result);
134
+ }
135
+ }
136
+ return clone ?? object;
137
+ }
138
+ }
139
+ /**
140
+ * Finds the first JSON-LD context in a value.
141
+ *
142
+ * @internal Technically exported for generated vocabulary classes, but not
143
+ * part of the public API contract. This is not considered public API for
144
+ * Semantic Versioning decisions.
145
+ */
146
+ function getJsonLdContext(value, depth = 0) {
147
+ if (depth > 32) return void 0;
148
+ if (Array.isArray(value)) {
149
+ for (const item of value) {
150
+ const context = getJsonLdContext(item, depth + 1);
151
+ if (context !== void 0) return context;
152
+ }
153
+ return;
154
+ }
155
+ if (value == null || typeof value !== "object" || !("@context" in value)) return;
156
+ return value["@context"];
157
+ }
158
+ function getOwnJsonLdContext(value) {
159
+ if (value == null || typeof value !== "object" || Array.isArray(value) || !("@context" in value)) return noJsonLdContext;
160
+ return value["@context"];
161
+ }
162
+ /**
163
+ * Recompacts normalized JSON-LD cache data against the original context.
164
+ *
165
+ * @internal Technically exported for generated vocabulary classes, but not
166
+ * part of the public API contract. This is not considered public API for
167
+ * Semantic Versioning decisions.
168
+ */
169
+ async function compactJsonLdCache(normalized, original, documentLoader, depth = 0, inheritedContext) {
170
+ if (depth > 32) return normalized;
171
+ if (Array.isArray(original)) {
172
+ const normalizedArray = Array.isArray(normalized) ? normalized : normalized != null && typeof normalized === "object" && "@graph" in normalized && Array.isArray(normalized["@graph"]) ? normalized["@graph"] : void 0;
173
+ if (normalizedArray == null) return normalized;
174
+ let clone;
175
+ for (let i = 0; i < normalizedArray.length; i++) {
176
+ const item = await compactJsonLdCache(normalizedArray[i], original[i], documentLoader, depth + 1, inheritedContext);
177
+ if (item !== normalizedArray[i]) {
178
+ clone ??= normalizedArray.slice(0, i);
179
+ clone.push(item);
180
+ } else if (clone != null) clone.push(normalizedArray[i]);
181
+ }
182
+ return clone ?? (Array.isArray(normalized) ? normalized : normalizedArray);
183
+ }
184
+ const ownContext = getOwnJsonLdContext(original);
185
+ const context = ownContext === noJsonLdContext ? inheritedContext : ownContext;
186
+ if (context == null) return preserveNoContextJsonLdShape(normalized, original, depth);
187
+ 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);
188
+ }
189
+ function preserveNoContextJsonLdShape(normalized, original, depth = 0) {
190
+ if (depth > 32) return normalized;
191
+ if (original == null || typeof original !== "object" || Array.isArray(original)) return normalized;
192
+ const normalizedObject = Array.isArray(normalized) && normalized.length === 1 ? normalized[0] : normalized;
193
+ if (normalizedObject == null || typeof normalizedObject !== "object" || Array.isArray(normalizedObject)) return normalized;
194
+ const source = normalizedObject;
195
+ const originalObject = original;
196
+ let clone;
197
+ for (const key of globalThis.Object.keys(originalObject)) {
198
+ if (!globalThis.Object.prototype.hasOwnProperty.call(source, key)) continue;
199
+ const value = preserveNoContextValue(source[key], originalObject[key], depth + 1);
200
+ if (value !== originalObject[key]) {
201
+ clone ??= { ...originalObject };
202
+ defineJsonLdProperty(clone, key, value);
203
+ }
204
+ }
205
+ return clone ?? original;
206
+ }
207
+ function preserveNoContextValue(normalized, original, depth) {
208
+ if (depth > 32) return normalized;
209
+ if (Array.isArray(original)) {
210
+ const normalizedArray = Array.isArray(normalized) ? normalized : [normalized];
211
+ let clone;
212
+ for (let i = 0; i < original.length; i++) {
213
+ const value = preserveNoContextValue(normalizedArray[i], original[i], depth + 1);
214
+ if (value !== original[i]) {
215
+ clone ??= original.slice(0, i);
216
+ clone.push(value);
217
+ } else if (clone != null) clone.push(original[i]);
218
+ }
219
+ return clone ?? original;
220
+ }
221
+ const normalizedValue = Array.isArray(normalized) ? normalized[0] : normalized;
222
+ if (normalizedValue == null || typeof normalizedValue !== "object" || Array.isArray(normalizedValue)) return normalizedValue;
223
+ const normalizedObject = normalizedValue;
224
+ if (original != null && typeof original === "object" && !Array.isArray(original)) return preserveNoContextJsonLdShape(normalizedObject, original, depth + 1);
225
+ if (typeof normalizedObject["@id"] === "string") return normalizedObject["@id"];
226
+ if ("@value" in normalizedObject) return normalizedObject["@value"];
227
+ return normalizedValue;
228
+ }
229
+ function getTopLevelTerms(value) {
230
+ const terms = /* @__PURE__ */ new Set();
231
+ const nodes = Array.isArray(value) ? value : [value];
232
+ for (const node of nodes) {
233
+ if (node == null || typeof node !== "object" || Array.isArray(node)) continue;
234
+ for (const key of globalThis.Object.keys(node)) {
235
+ if (key.startsWith("@")) continue;
236
+ terms.add(key);
237
+ }
238
+ }
239
+ return terms;
240
+ }
241
+ async function mergeUnmappedTerms(compacted, original, context, documentLoader) {
242
+ if (original == null || typeof original !== "object" || Array.isArray(original) || compacted == null || typeof compacted !== "object" || Array.isArray(compacted)) return compacted;
243
+ const unmappedKeys = globalThis.Object.keys(original).filter((key) => key !== "@context" && !globalThis.Object.prototype.hasOwnProperty.call(compacted, key));
244
+ if (unmappedKeys.length < 1) return compacted;
245
+ const result = { ...compacted };
246
+ const compactedWithContext = compacted != null && typeof compacted === "object" && !Array.isArray(compacted) && !("@context" in compacted) ? {
247
+ "@context": context,
248
+ ...compacted
249
+ } : compacted;
250
+ const compactedTerms = getTopLevelTerms(await jsonld_default.expand(compactedWithContext, { documentLoader }));
251
+ const dummyPrefix = "urn:fedify:dummy:";
252
+ const dummy = { "@context": context };
253
+ for (let i = 0; i < unmappedKeys.length; i++) defineJsonLdProperty(dummy, unmappedKeys[i], `${dummyPrefix}${i}`);
254
+ const expanded = await jsonld_default.expand(dummy, { documentLoader });
255
+ const representedKeys = /* @__PURE__ */ new Set();
256
+ const nodes = Array.isArray(expanded) ? expanded : [expanded];
257
+ for (const node of nodes) {
258
+ if (node == null || typeof node !== "object" || Array.isArray(node)) continue;
259
+ for (const [term, termValue] of globalThis.Object.entries(node)) {
260
+ if (!compactedTerms.has(term)) continue;
261
+ for (let i = 0; i < unmappedKeys.length; i++) if (containsValue(termValue, `${dummyPrefix}${i}`)) representedKeys.add(unmappedKeys[i]);
262
+ }
263
+ }
264
+ for (const key of unmappedKeys) if (!representedKeys.has(key)) defineJsonLdProperty(result, key, original[key]);
265
+ return result;
266
+ }
267
+ function defineJsonLdProperty(object, key, value) {
268
+ globalThis.Object.defineProperty(object, key, {
269
+ value,
270
+ enumerable: true,
271
+ configurable: true,
272
+ writable: true
273
+ });
274
+ }
275
+ function containsValue(value, expected, depth = 0) {
276
+ if (depth > 32) return false;
277
+ if (value === expected) return true;
278
+ if (Array.isArray(value)) return value.some((item) => containsValue(item, expected, depth + 1));
279
+ if (value == null || typeof value !== "object") return false;
280
+ return globalThis.Object.entries(value).some(([key, item]) => key !== "@context" && containsValue(item, expected, depth + 1));
281
+ }
282
+ async function preserveJsonLdShape(compacted, original, context, documentLoader, depth = 0) {
283
+ if (depth > 32) return compacted;
284
+ if (compacted === original) return compacted;
285
+ if (original == null || typeof original !== "object" || compacted == null || typeof compacted !== "object") return compacted;
286
+ if (Array.isArray(original)) {
287
+ const compactedArray = Array.isArray(compacted) ? compacted : "@graph" in compacted && Array.isArray(compacted["@graph"]) ? compacted["@graph"] : void 0;
288
+ if (compactedArray == null) return compacted;
289
+ let clone;
290
+ for (let i = 0; i < compactedArray.length; i++) {
291
+ const value = await preserveJsonLdShape(compactedArray[i], original[i], context, documentLoader, depth + 1);
292
+ const originalContext = original[i] != null && typeof original[i] === "object" && !Array.isArray(original[i]) && "@context" in original[i] ? original[i]["@context"] : void 0;
293
+ const shaped = originalContext !== void 0 && value != null && typeof value === "object" && !Array.isArray(value) && !("@context" in value) ? {
294
+ "@context": originalContext,
295
+ ...value
296
+ } : value;
297
+ if (shaped !== compactedArray[i]) {
298
+ clone ??= compactedArray.slice(0, i);
299
+ clone.push(shaped);
300
+ } else if (clone != null) clone.push(compactedArray[i]);
301
+ }
302
+ return clone ?? (Array.isArray(compacted) ? compacted : compactedArray);
303
+ }
304
+ if (Array.isArray(compacted)) return compacted;
305
+ let clone;
306
+ const ownContext = getOwnJsonLdContext(original);
307
+ const objectContext = combineContexts(context, ownContext);
308
+ const objectCompacted = depth > 0 && ownContext === null ? await compactWithEmptyContext(compacted, context, documentLoader) : compacted;
309
+ const compactedObject = depth > 0 ? await mergeUnmappedTerms(objectCompacted, original, objectContext, documentLoader) : objectCompacted;
310
+ const originalObject = original;
311
+ for (const key of globalThis.Object.keys(compactedObject)) {
312
+ if (key === "@context") continue;
313
+ const value = await preserveJsonLdShape(compactedObject[key], originalObject[key], objectContext, documentLoader, depth + 1);
314
+ const shaped = Array.isArray(originalObject[key]) && !Array.isArray(value) ? [value] : value;
315
+ if (shaped !== compactedObject[key]) {
316
+ clone ??= { ...compactedObject };
317
+ defineJsonLdProperty(clone, key, shaped);
318
+ }
319
+ }
320
+ if (depth > 0) {
321
+ if ("@context" in originalObject && !("@context" in compactedObject)) {
322
+ clone ??= { ...compactedObject };
323
+ clone["@context"] = originalObject["@context"];
324
+ }
325
+ }
326
+ return clone ?? compactedObject;
327
+ }
328
+ async function compactWithEmptyContext(compacted, context, documentLoader) {
329
+ const compactedWithContext = compacted != null && typeof compacted === "object" && !Array.isArray(compacted) && !("@context" in compacted) ? {
330
+ "@context": context,
331
+ ...compacted
332
+ } : compacted;
333
+ const expanded = await jsonld_default.expand(compactedWithContext, { documentLoader });
334
+ return await jsonld_default.compact(expanded, {}, { documentLoader });
335
+ }
336
+ function combineContexts(inheritedContext, ownContext) {
337
+ if (ownContext === noJsonLdContext || ownContext === inheritedContext) return inheritedContext;
338
+ if (ownContext == null) return ownContext;
339
+ const inherited = Array.isArray(inheritedContext) ? inheritedContext : [inheritedContext];
340
+ const own = Array.isArray(ownContext) ? ownContext : [ownContext];
341
+ return [...inherited, ...own];
342
+ }
343
+ //#endregion
344
+ Object.defineProperty(exports, "compactJsonLdCache", {
345
+ enumerable: true,
346
+ get: function() {
347
+ return compactJsonLdCache;
348
+ }
349
+ });
350
+ Object.defineProperty(exports, "createScopedContextLoader", {
351
+ enumerable: true,
352
+ get: function() {
353
+ return createScopedContextLoader;
354
+ }
355
+ });
356
+ Object.defineProperty(exports, "getJsonLdContext", {
357
+ enumerable: true,
358
+ get: function() {
359
+ return getJsonLdContext;
360
+ }
361
+ });
362
+ Object.defineProperty(exports, "getPortableActorGateways", {
363
+ enumerable: true,
364
+ get: function() {
365
+ return getPortableActorGateways;
366
+ }
367
+ });
368
+ Object.defineProperty(exports, "isTrustedIriOrigin", {
369
+ enumerable: true,
370
+ get: function() {
371
+ return isTrustedIriOrigin;
372
+ }
373
+ });
374
+ Object.defineProperty(exports, "jsonld_default", {
375
+ enumerable: true,
376
+ get: function() {
377
+ return jsonld_default;
378
+ }
379
+ });
380
+ Object.defineProperty(exports, "normalizeJsonLdIris", {
381
+ enumerable: true,
382
+ get: function() {
383
+ return normalizeJsonLdIris;
384
+ }
385
+ });
386
+ Object.defineProperty(exports, "registerDocumentLoaderWrapper", {
387
+ enumerable: true,
388
+ get: function() {
389
+ return registerDocumentLoaderWrapper;
390
+ }
391
+ });
392
+ Object.defineProperty(exports, "unwrapReleasedDocumentLoader", {
393
+ enumerable: true,
394
+ get: function() {
395
+ return unwrapReleasedDocumentLoader;
396
+ }
397
+ });