@fedify/vocab-runtime 2.4.0-pr.936.41 → 2.4.1
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-B09jb9Pi.cjs} +173 -274
- package/dist/{tests/docloader-S_gQZ2tt.cjs → contexts-DWrj4AGR.js} +169 -293
- package/dist/{docloader-C_dir7Xb.d.ts → docloader-BMHljyYb.d.cts} +68 -2
- package/dist/{docloader-D2DTRiyA.d.cts → docloader-BMHljyYb.d.ts} +68 -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 +762 -4529
- package/dist/mod.d.cts +427 -9
- package/dist/mod.d.ts +427 -10
- package/dist/mod.js +742 -4524
- package/dist/portable-6Aj-7dZJ.d.cts +160 -0
- package/dist/portable-nkTiqH0w.d.ts +160 -0
- package/dist/tests/body-DpC9p-iG.mjs +130 -0
- package/dist/tests/body-cKLBprYm.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-C9Lj11SC.cjs +4533 -0
- package/dist/tests/contexts-duRA_dDC.mjs +4522 -0
- package/dist/tests/decimal.test.cjs +9 -7
- package/dist/tests/decimal.test.mjs +9 -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-DyZ1JGIl.cjs +398 -0
- package/dist/tests/docloader-tUmMeXjU.mjs +375 -0
- package/dist/tests/docloader.test.cjs +816 -39
- package/dist/tests/docloader.test.mjs +810 -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-CmDhHNTx.cjs +12 -0
- package/dist/tests/jsonld-DweIJ07b.mjs +5 -0
- package/dist/tests/jsonld-cache-BEXiiM-V.cjs +386 -0
- package/dist/tests/jsonld-cache-DFnWsLuZ.mjs +339 -0
- package/dist/tests/jsonld-cache.test.cjs +102 -298
- package/dist/tests/jsonld-cache.test.mjs +95 -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-Di5AvKpB.mjs → langstr-DYRmJqFn.mjs} +5 -2
- package/dist/tests/{langstr-CbAxaeEZ.cjs → langstr-_PqsL1ae.cjs} +5 -2
- package/dist/tests/langstr.test.cjs +11 -4
- package/dist/tests/langstr.test.mjs +9 -2
- package/dist/tests/langtag-CUppHs_s.mjs +45 -0
- package/dist/tests/langtag-Czjvxfzx.cjs +50 -0
- package/dist/tests/langtag.test.cjs +45 -0
- package/dist/tests/langtag.test.d.cts +1 -0
- package/dist/tests/langtag.test.d.mts +1 -0
- package/dist/tests/langtag.test.mjs +46 -0
- 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-DmTYDy2p.mjs +250 -0
- package/dist/tests/portable-dereference-qTLMqe2_.cjs +279 -0
- package/dist/tests/portable-media-5p8azal0.cjs +153 -0
- package/dist/tests/portable-media-B_lt9MMA.mjs +148 -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-BgjA9wyl.cjs} +10 -4
- package/dist/tests/{request-C8CaGwtt.mjs → request-DodZNukP.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/fep-6757.json +12 -0
- package/src/contexts/joinmastodon.json +1 -1
- package/src/contexts/miscellany.json +17 -0
- package/src/contexts.ts +47 -1
- package/src/digest.test.ts +220 -0
- package/src/digest.ts +229 -0
- package/src/docloader.test.ts +1066 -27
- package/src/docloader.ts +322 -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/langstr.test.ts +18 -1
- package/src/langstr.ts +6 -2
- package/src/langtag.test.ts +53 -0
- package/src/langtag.ts +76 -0
- package/src/mod.ts +29 -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/{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
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { _ as parseIri, c as getFe34Origin, d as haveSameIriOrigin, o as formatIri, s as fromCompatibleEf61Id, u as haveSameFe34Origin } from "./url-DMxmp7ZG.mjs";
|
|
2
|
+
import { t as jsonld_default } from "./jsonld-DweIJ07b.mjs";
|
|
3
|
+
//#region src/internal/jsonld-cache.ts
|
|
4
|
+
/**
|
|
5
|
+
* Reads expanded gateways, including an unmapped term on portable actors.
|
|
6
|
+
* The original values and their order are preserved for URL validation by
|
|
7
|
+
* the caller. An explicitly mapped FEP-ef61 property always takes precedence.
|
|
8
|
+
* @internal Used by generated vocabulary classes and portable proof checks.
|
|
9
|
+
*/
|
|
10
|
+
function getPortableActorGateways(node, allowUnmapped = true) {
|
|
11
|
+
const property = "https://w3id.org/fep/ef61/gateways";
|
|
12
|
+
if (globalThis.Object.hasOwn(node, property)) return Array.isArray(node[property]) ? node[property] : void 0;
|
|
13
|
+
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;
|
|
14
|
+
try {
|
|
15
|
+
if (!getFe34Origin(parseIri(fromCompatibleEf61Id(node["@id"]) ?? node["@id"])).startsWith("did:")) return void 0;
|
|
16
|
+
} catch (error) {
|
|
17
|
+
if (error instanceof TypeError) return void 0;
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
return Array.isArray(node["_:gateways"]) ? node["_:gateways"] : void 0;
|
|
21
|
+
}
|
|
22
|
+
const noJsonLdContext = Symbol("noJsonLdContext");
|
|
23
|
+
const documentLoaderWrappers = /* @__PURE__ */ new WeakMap();
|
|
24
|
+
/**
|
|
25
|
+
* Registers a loader wrapper with the shared released-wrapper registry.
|
|
26
|
+
* Both suppression and snapshot wrappers must use this registry so mixed
|
|
27
|
+
* chains can be unwrapped. The caller updates the state on release.
|
|
28
|
+
* @internal Not a public API.
|
|
29
|
+
*/
|
|
30
|
+
function registerDocumentLoaderWrapper(loader, state) {
|
|
31
|
+
documentLoaderWrappers.set(loader, state);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Removes released loader wrappers, stopping at the first active wrapper.
|
|
35
|
+
* Active wrappers retain their operation's suppression or snapshot cache.
|
|
36
|
+
* @internal Not a public API.
|
|
37
|
+
*/
|
|
38
|
+
function unwrapReleasedDocumentLoader(base) {
|
|
39
|
+
for (let state = documentLoaderWrappers.get(base); state?.released; state = documentLoaderWrappers.get(base)) base = state.base;
|
|
40
|
+
return base;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Lowers context loading failure logs for one accessor operation. Parsed
|
|
44
|
+
* objects retain the loader, so release it before returning to the caller.
|
|
45
|
+
* Released wrappers are unwrapped to avoid accumulating loader chains.
|
|
46
|
+
* @internal Used by generated vocabulary accessors; not a public API.
|
|
47
|
+
*/
|
|
48
|
+
function createScopedContextLoader(base, suppressError) {
|
|
49
|
+
base = unwrapReleasedDocumentLoader(base);
|
|
50
|
+
if (!suppressError) return {
|
|
51
|
+
loader: base,
|
|
52
|
+
release: () => {}
|
|
53
|
+
};
|
|
54
|
+
const state = {
|
|
55
|
+
base,
|
|
56
|
+
released: false
|
|
57
|
+
};
|
|
58
|
+
const loader = (url, options) => base(url, state.released ? options : {
|
|
59
|
+
...options,
|
|
60
|
+
suppressError: true
|
|
61
|
+
});
|
|
62
|
+
registerDocumentLoaderWrapper(loader, state);
|
|
63
|
+
return {
|
|
64
|
+
loader,
|
|
65
|
+
release: () => {
|
|
66
|
+
state.released = true;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Checks whether an IRI is trusted relative to another IRI.
|
|
72
|
+
*
|
|
73
|
+
* @internal Technically exported for generated vocabulary classes, but not
|
|
74
|
+
* part of the public API contract. This is not considered public API for
|
|
75
|
+
* Semantic Versioning decisions.
|
|
76
|
+
*/
|
|
77
|
+
function isTrustedIriOrigin(options, left, right) {
|
|
78
|
+
return options.crossOrigin === "trust" || left == null || right != null && (haveSameIriOrigin(left, right) || haveSameFe34Origin(left, right));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Normalizes portable IRIs in JSON-LD cache data.
|
|
82
|
+
*
|
|
83
|
+
* @internal Technically exported for generated vocabulary classes, but not
|
|
84
|
+
* part of the public API contract. This is not considered public API for
|
|
85
|
+
* Semantic Versioning decisions.
|
|
86
|
+
*/
|
|
87
|
+
function normalizeJsonLdIris(value, iriKeys, iriPattern = /^ap(?:\+ef61)?:\/\//i) {
|
|
88
|
+
return normalize(value, void 0, 0, void 0);
|
|
89
|
+
function isIriPosition(key, parentKey) {
|
|
90
|
+
return iriKeys.has(key) || (key === "@value" || key === "@list" || key === "@set") && parentKey != null && iriKeys.has(parentKey);
|
|
91
|
+
}
|
|
92
|
+
function arrayItemParentKey(key, parentKey) {
|
|
93
|
+
return key === "@list" || key === "@set" ? parentKey : key;
|
|
94
|
+
}
|
|
95
|
+
function entryParentKey(entryKey, key, parentKey) {
|
|
96
|
+
if (entryKey === "@list" || entryKey === "@set") return parentKey ?? key;
|
|
97
|
+
return key === "@list" || key === "@set" ? parentKey : key;
|
|
98
|
+
}
|
|
99
|
+
function normalize(value, key, depth = 0, parentKey) {
|
|
100
|
+
if (depth > 32 || key === "@context") return value;
|
|
101
|
+
if (typeof value === "string") {
|
|
102
|
+
if (key != null && isIriPosition(key, parentKey) && iriPattern.test(value)) try {
|
|
103
|
+
return formatIri(value);
|
|
104
|
+
} catch {
|
|
105
|
+
return value;
|
|
106
|
+
}
|
|
107
|
+
return value;
|
|
108
|
+
}
|
|
109
|
+
if (Array.isArray(value)) {
|
|
110
|
+
let clone;
|
|
111
|
+
const itemParentKey = arrayItemParentKey(key, parentKey);
|
|
112
|
+
for (let i = 0; i < value.length; i++) {
|
|
113
|
+
const result = normalize(value[i], key, depth + 1, itemParentKey);
|
|
114
|
+
if (result !== value[i]) {
|
|
115
|
+
clone ??= value.slice(0, i);
|
|
116
|
+
clone.push(result);
|
|
117
|
+
} else if (clone != null) clone.push(value[i]);
|
|
118
|
+
}
|
|
119
|
+
return clone ?? value;
|
|
120
|
+
}
|
|
121
|
+
if (value == null || typeof value !== "object") return value;
|
|
122
|
+
const object = value;
|
|
123
|
+
let clone;
|
|
124
|
+
for (const entryKey of globalThis.Object.keys(object)) {
|
|
125
|
+
const result = normalize(object[entryKey], entryKey, depth + 1, entryParentKey(entryKey, key, parentKey));
|
|
126
|
+
if (result !== object[entryKey]) {
|
|
127
|
+
clone ??= { ...object };
|
|
128
|
+
defineJsonLdProperty(clone, entryKey, result);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return clone ?? object;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Finds the first JSON-LD context in a value.
|
|
136
|
+
*
|
|
137
|
+
* @internal Technically exported for generated vocabulary classes, but not
|
|
138
|
+
* part of the public API contract. This is not considered public API for
|
|
139
|
+
* Semantic Versioning decisions.
|
|
140
|
+
*/
|
|
141
|
+
function getJsonLdContext(value, depth = 0) {
|
|
142
|
+
if (depth > 32) return void 0;
|
|
143
|
+
if (Array.isArray(value)) {
|
|
144
|
+
for (const item of value) {
|
|
145
|
+
const context = getJsonLdContext(item, depth + 1);
|
|
146
|
+
if (context !== void 0) return context;
|
|
147
|
+
}
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (value == null || typeof value !== "object" || !("@context" in value)) return;
|
|
151
|
+
return value["@context"];
|
|
152
|
+
}
|
|
153
|
+
function getOwnJsonLdContext(value) {
|
|
154
|
+
if (value == null || typeof value !== "object" || Array.isArray(value) || !("@context" in value)) return noJsonLdContext;
|
|
155
|
+
return value["@context"];
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Recompacts normalized JSON-LD cache data against the original context.
|
|
159
|
+
*
|
|
160
|
+
* @internal Technically exported for generated vocabulary classes, but not
|
|
161
|
+
* part of the public API contract. This is not considered public API for
|
|
162
|
+
* Semantic Versioning decisions.
|
|
163
|
+
*/
|
|
164
|
+
async function compactJsonLdCache(normalized, original, documentLoader, depth = 0, inheritedContext) {
|
|
165
|
+
if (depth > 32) return normalized;
|
|
166
|
+
if (Array.isArray(original)) {
|
|
167
|
+
const normalizedArray = Array.isArray(normalized) ? normalized : normalized != null && typeof normalized === "object" && "@graph" in normalized && Array.isArray(normalized["@graph"]) ? normalized["@graph"] : void 0;
|
|
168
|
+
if (normalizedArray == null) return normalized;
|
|
169
|
+
let clone;
|
|
170
|
+
for (let i = 0; i < normalizedArray.length; i++) {
|
|
171
|
+
const item = await compactJsonLdCache(normalizedArray[i], original[i], documentLoader, depth + 1, inheritedContext);
|
|
172
|
+
if (item !== normalizedArray[i]) {
|
|
173
|
+
clone ??= normalizedArray.slice(0, i);
|
|
174
|
+
clone.push(item);
|
|
175
|
+
} else if (clone != null) clone.push(normalizedArray[i]);
|
|
176
|
+
}
|
|
177
|
+
return clone ?? (Array.isArray(normalized) ? normalized : normalizedArray);
|
|
178
|
+
}
|
|
179
|
+
const ownContext = getOwnJsonLdContext(original);
|
|
180
|
+
const context = ownContext === noJsonLdContext ? inheritedContext : ownContext;
|
|
181
|
+
if (context == null) return preserveNoContextJsonLdShape(normalized, original, depth);
|
|
182
|
+
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);
|
|
183
|
+
}
|
|
184
|
+
function preserveNoContextJsonLdShape(normalized, original, depth = 0) {
|
|
185
|
+
if (depth > 32) return normalized;
|
|
186
|
+
if (original == null || typeof original !== "object" || Array.isArray(original)) return normalized;
|
|
187
|
+
const normalizedObject = Array.isArray(normalized) && normalized.length === 1 ? normalized[0] : normalized;
|
|
188
|
+
if (normalizedObject == null || typeof normalizedObject !== "object" || Array.isArray(normalizedObject)) return normalized;
|
|
189
|
+
const source = normalizedObject;
|
|
190
|
+
const originalObject = original;
|
|
191
|
+
let clone;
|
|
192
|
+
for (const key of globalThis.Object.keys(originalObject)) {
|
|
193
|
+
if (!globalThis.Object.prototype.hasOwnProperty.call(source, key)) continue;
|
|
194
|
+
const value = preserveNoContextValue(source[key], originalObject[key], depth + 1);
|
|
195
|
+
if (value !== originalObject[key]) {
|
|
196
|
+
clone ??= { ...originalObject };
|
|
197
|
+
defineJsonLdProperty(clone, key, value);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return clone ?? original;
|
|
201
|
+
}
|
|
202
|
+
function preserveNoContextValue(normalized, original, depth) {
|
|
203
|
+
if (depth > 32) return normalized;
|
|
204
|
+
if (Array.isArray(original)) {
|
|
205
|
+
const normalizedArray = Array.isArray(normalized) ? normalized : [normalized];
|
|
206
|
+
let clone;
|
|
207
|
+
for (let i = 0; i < original.length; i++) {
|
|
208
|
+
const value = preserveNoContextValue(normalizedArray[i], original[i], depth + 1);
|
|
209
|
+
if (value !== original[i]) {
|
|
210
|
+
clone ??= original.slice(0, i);
|
|
211
|
+
clone.push(value);
|
|
212
|
+
} else if (clone != null) clone.push(original[i]);
|
|
213
|
+
}
|
|
214
|
+
return clone ?? original;
|
|
215
|
+
}
|
|
216
|
+
const normalizedValue = Array.isArray(normalized) ? normalized[0] : normalized;
|
|
217
|
+
if (normalizedValue == null || typeof normalizedValue !== "object" || Array.isArray(normalizedValue)) return normalizedValue;
|
|
218
|
+
const normalizedObject = normalizedValue;
|
|
219
|
+
if (original != null && typeof original === "object" && !Array.isArray(original)) return preserveNoContextJsonLdShape(normalizedObject, original, depth + 1);
|
|
220
|
+
if (typeof normalizedObject["@id"] === "string") return normalizedObject["@id"];
|
|
221
|
+
if ("@value" in normalizedObject) return normalizedObject["@value"];
|
|
222
|
+
return normalizedValue;
|
|
223
|
+
}
|
|
224
|
+
function getTopLevelTerms(value) {
|
|
225
|
+
const terms = /* @__PURE__ */ new Set();
|
|
226
|
+
const nodes = Array.isArray(value) ? value : [value];
|
|
227
|
+
for (const node of nodes) {
|
|
228
|
+
if (node == null || typeof node !== "object" || Array.isArray(node)) continue;
|
|
229
|
+
for (const key of globalThis.Object.keys(node)) {
|
|
230
|
+
if (key.startsWith("@")) continue;
|
|
231
|
+
terms.add(key);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return terms;
|
|
235
|
+
}
|
|
236
|
+
async function mergeUnmappedTerms(compacted, original, context, documentLoader) {
|
|
237
|
+
if (original == null || typeof original !== "object" || Array.isArray(original) || compacted == null || typeof compacted !== "object" || Array.isArray(compacted)) return compacted;
|
|
238
|
+
const unmappedKeys = globalThis.Object.keys(original).filter((key) => key !== "@context" && !globalThis.Object.prototype.hasOwnProperty.call(compacted, key));
|
|
239
|
+
if (unmappedKeys.length < 1) return compacted;
|
|
240
|
+
const result = { ...compacted };
|
|
241
|
+
const compactedWithContext = compacted != null && typeof compacted === "object" && !Array.isArray(compacted) && !("@context" in compacted) ? {
|
|
242
|
+
"@context": context,
|
|
243
|
+
...compacted
|
|
244
|
+
} : compacted;
|
|
245
|
+
const compactedTerms = getTopLevelTerms(await jsonld_default.expand(compactedWithContext, { documentLoader }));
|
|
246
|
+
const dummyPrefix = "urn:fedify:dummy:";
|
|
247
|
+
const dummy = { "@context": context };
|
|
248
|
+
for (let i = 0; i < unmappedKeys.length; i++) defineJsonLdProperty(dummy, unmappedKeys[i], `${dummyPrefix}${i}`);
|
|
249
|
+
const expanded = await jsonld_default.expand(dummy, { documentLoader });
|
|
250
|
+
const representedKeys = /* @__PURE__ */ new Set();
|
|
251
|
+
const nodes = Array.isArray(expanded) ? expanded : [expanded];
|
|
252
|
+
for (const node of nodes) {
|
|
253
|
+
if (node == null || typeof node !== "object" || Array.isArray(node)) continue;
|
|
254
|
+
for (const [term, termValue] of globalThis.Object.entries(node)) {
|
|
255
|
+
if (!compactedTerms.has(term)) continue;
|
|
256
|
+
for (let i = 0; i < unmappedKeys.length; i++) if (containsValue(termValue, `${dummyPrefix}${i}`)) representedKeys.add(unmappedKeys[i]);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
for (const key of unmappedKeys) if (!representedKeys.has(key)) defineJsonLdProperty(result, key, original[key]);
|
|
260
|
+
return result;
|
|
261
|
+
}
|
|
262
|
+
function defineJsonLdProperty(object, key, value) {
|
|
263
|
+
globalThis.Object.defineProperty(object, key, {
|
|
264
|
+
value,
|
|
265
|
+
enumerable: true,
|
|
266
|
+
configurable: true,
|
|
267
|
+
writable: true
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
function containsValue(value, expected, depth = 0) {
|
|
271
|
+
if (depth > 32) return false;
|
|
272
|
+
if (value === expected) return true;
|
|
273
|
+
if (Array.isArray(value)) return value.some((item) => containsValue(item, expected, depth + 1));
|
|
274
|
+
if (value == null || typeof value !== "object") return false;
|
|
275
|
+
return globalThis.Object.entries(value).some(([key, item]) => key !== "@context" && containsValue(item, expected, depth + 1));
|
|
276
|
+
}
|
|
277
|
+
async function preserveJsonLdShape(compacted, original, context, documentLoader, depth = 0) {
|
|
278
|
+
if (depth > 32) return compacted;
|
|
279
|
+
if (compacted === original) return compacted;
|
|
280
|
+
if (original == null || typeof original !== "object" || compacted == null || typeof compacted !== "object") return compacted;
|
|
281
|
+
if (Array.isArray(original)) {
|
|
282
|
+
const compactedArray = Array.isArray(compacted) ? compacted : "@graph" in compacted && Array.isArray(compacted["@graph"]) ? compacted["@graph"] : void 0;
|
|
283
|
+
if (compactedArray == null) return compacted;
|
|
284
|
+
let clone;
|
|
285
|
+
for (let i = 0; i < compactedArray.length; i++) {
|
|
286
|
+
const value = await preserveJsonLdShape(compactedArray[i], original[i], context, documentLoader, depth + 1);
|
|
287
|
+
const originalContext = original[i] != null && typeof original[i] === "object" && !Array.isArray(original[i]) && "@context" in original[i] ? original[i]["@context"] : void 0;
|
|
288
|
+
const shaped = originalContext !== void 0 && value != null && typeof value === "object" && !Array.isArray(value) && !("@context" in value) ? {
|
|
289
|
+
"@context": originalContext,
|
|
290
|
+
...value
|
|
291
|
+
} : value;
|
|
292
|
+
if (shaped !== compactedArray[i]) {
|
|
293
|
+
clone ??= compactedArray.slice(0, i);
|
|
294
|
+
clone.push(shaped);
|
|
295
|
+
} else if (clone != null) clone.push(compactedArray[i]);
|
|
296
|
+
}
|
|
297
|
+
return clone ?? (Array.isArray(compacted) ? compacted : compactedArray);
|
|
298
|
+
}
|
|
299
|
+
if (Array.isArray(compacted)) return compacted;
|
|
300
|
+
let clone;
|
|
301
|
+
const ownContext = getOwnJsonLdContext(original);
|
|
302
|
+
const objectContext = combineContexts(context, ownContext);
|
|
303
|
+
const objectCompacted = depth > 0 && ownContext === null ? await compactWithEmptyContext(compacted, context, documentLoader) : compacted;
|
|
304
|
+
const compactedObject = depth > 0 ? await mergeUnmappedTerms(objectCompacted, original, objectContext, documentLoader) : objectCompacted;
|
|
305
|
+
const originalObject = original;
|
|
306
|
+
for (const key of globalThis.Object.keys(compactedObject)) {
|
|
307
|
+
if (key === "@context") continue;
|
|
308
|
+
const value = await preserveJsonLdShape(compactedObject[key], originalObject[key], objectContext, documentLoader, depth + 1);
|
|
309
|
+
const shaped = Array.isArray(originalObject[key]) && !Array.isArray(value) ? [value] : value;
|
|
310
|
+
if (shaped !== compactedObject[key]) {
|
|
311
|
+
clone ??= { ...compactedObject };
|
|
312
|
+
defineJsonLdProperty(clone, key, shaped);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (depth > 0) {
|
|
316
|
+
if ("@context" in originalObject && !("@context" in compactedObject)) {
|
|
317
|
+
clone ??= { ...compactedObject };
|
|
318
|
+
clone["@context"] = originalObject["@context"];
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return clone ?? compactedObject;
|
|
322
|
+
}
|
|
323
|
+
async function compactWithEmptyContext(compacted, context, documentLoader) {
|
|
324
|
+
const compactedWithContext = compacted != null && typeof compacted === "object" && !Array.isArray(compacted) && !("@context" in compacted) ? {
|
|
325
|
+
"@context": context,
|
|
326
|
+
...compacted
|
|
327
|
+
} : compacted;
|
|
328
|
+
const expanded = await jsonld_default.expand(compactedWithContext, { documentLoader });
|
|
329
|
+
return await jsonld_default.compact(expanded, {}, { documentLoader });
|
|
330
|
+
}
|
|
331
|
+
function combineContexts(inheritedContext, ownContext) {
|
|
332
|
+
if (ownContext === noJsonLdContext || ownContext === inheritedContext) return inheritedContext;
|
|
333
|
+
if (ownContext == null) return ownContext;
|
|
334
|
+
const inherited = Array.isArray(inheritedContext) ? inheritedContext : [inheritedContext];
|
|
335
|
+
const own = Array.isArray(ownContext) ? ownContext : [ownContext];
|
|
336
|
+
return [...inherited, ...own];
|
|
337
|
+
}
|
|
338
|
+
//#endregion
|
|
339
|
+
export { isTrustedIriOrigin as a, unwrapReleasedDocumentLoader as c, getPortableActorGateways as i, createScopedContextLoader as n, normalizeJsonLdIris as o, getJsonLdContext as r, registerDocumentLoaderWrapper as s, compactJsonLdCache as t };
|