@fedify/vocab-runtime 2.4.0-dev.1504 → 2.4.0-dev.1528
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 +2 -1
- package/dist/docloader-DnUMWHaJ.d.cts +202 -0
- package/dist/docloader-xRGn1azD.d.ts +202 -0
- package/dist/internal/jsonld-cache.cjs +279 -0
- package/dist/internal/jsonld-cache.d.cts +48 -0
- package/dist/internal/jsonld-cache.d.ts +48 -0
- package/dist/internal/jsonld-cache.js +275 -0
- package/dist/mod.cjs +13 -183
- package/dist/mod.d.cts +18 -200
- package/dist/mod.d.ts +18 -200
- package/dist/mod.js +3 -177
- package/dist/tests/decimal.test.cjs +2 -2
- package/dist/tests/decimal.test.mjs +2 -2
- package/dist/tests/{docloader-4-QUV2zw.mjs → docloader-9JRkIgYh.mjs} +2 -2
- package/dist/tests/{docloader-YkaAm2yn.cjs → docloader-yxXccHZv.cjs} +2 -2
- package/dist/tests/docloader.test.cjs +3 -3
- package/dist/tests/docloader.test.mjs +3 -3
- package/dist/tests/jsonld-cache.test.cjs +652 -0
- package/dist/tests/jsonld-cache.test.d.cts +1 -0
- package/dist/tests/jsonld-cache.test.d.mts +1 -0
- package/dist/tests/jsonld-cache.test.mjs +651 -0
- package/dist/tests/{request-CfFe6X2X.mjs → request-4-bNhrbG.mjs} +1 -1
- package/dist/tests/{request-C0jvpDAj.cjs → request-_LWX0dnv.cjs} +1 -1
- package/dist/tests/request.test.cjs +1 -1
- package/dist/tests/request.test.mjs +1 -1
- package/dist/tests/{url-C20FhC7p.cjs → url-2XwVbUS_.cjs} +108 -0
- package/dist/tests/{url-m9Qzxy-Y.mjs → url-YWJbnRlf.mjs} +85 -1
- package/dist/tests/url.test.cjs +104 -1
- package/dist/tests/url.test.mjs +105 -2
- package/dist/url-BAdyyqAa.cjs +315 -0
- package/dist/url-BuxPHxK2.js +261 -0
- package/package.json +12 -5
- package/src/internal/jsonld-cache.ts +538 -0
- package/src/jsonld-cache.test.ts +554 -0
- package/src/mod.ts +4 -0
- package/src/url.test.ts +252 -1
- package/src/url.ts +141 -0
- package/tsdown.config.ts +6 -1
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/// <reference lib="esnext.temporal" />
|
|
2
|
+
import { n as DocumentLoader } from "../docloader-DnUMWHaJ.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/internal/jsonld-cache.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Options for deciding whether two IRIs should be treated as same-origin.
|
|
7
|
+
*
|
|
8
|
+
* @internal Technically exported for generated vocabulary classes, but not
|
|
9
|
+
* part of the public API contract. This is not considered public API for
|
|
10
|
+
* Semantic Versioning decisions.
|
|
11
|
+
*/
|
|
12
|
+
interface IriTrustOptions {
|
|
13
|
+
crossOrigin?: "ignore" | "throw" | "trust";
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Checks whether an IRI is trusted relative to another IRI.
|
|
17
|
+
*
|
|
18
|
+
* @internal Technically exported for generated vocabulary classes, but not
|
|
19
|
+
* part of the public API contract. This is not considered public API for
|
|
20
|
+
* Semantic Versioning decisions.
|
|
21
|
+
*/
|
|
22
|
+
declare function isTrustedIriOrigin(options: IriTrustOptions, left: URL | null | undefined, right: URL | null | undefined): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Normalizes portable IRIs in JSON-LD cache data.
|
|
25
|
+
*
|
|
26
|
+
* @internal Technically exported for generated vocabulary classes, but not
|
|
27
|
+
* part of the public API contract. This is not considered public API for
|
|
28
|
+
* Semantic Versioning decisions.
|
|
29
|
+
*/
|
|
30
|
+
declare function normalizeJsonLdIris(value: unknown, iriKeys: ReadonlySet<string>, iriPattern?: RegExp): unknown;
|
|
31
|
+
/**
|
|
32
|
+
* Finds the first JSON-LD context in a value.
|
|
33
|
+
*
|
|
34
|
+
* @internal Technically exported for generated vocabulary classes, but not
|
|
35
|
+
* part of the public API contract. This is not considered public API for
|
|
36
|
+
* Semantic Versioning decisions.
|
|
37
|
+
*/
|
|
38
|
+
declare function getJsonLdContext(value: unknown, depth?: number): unknown;
|
|
39
|
+
/**
|
|
40
|
+
* Recompacts normalized JSON-LD cache data against the original context.
|
|
41
|
+
*
|
|
42
|
+
* @internal Technically exported for generated vocabulary classes, but not
|
|
43
|
+
* part of the public API contract. This is not considered public API for
|
|
44
|
+
* Semantic Versioning decisions.
|
|
45
|
+
*/
|
|
46
|
+
declare function compactJsonLdCache(normalized: unknown, original: unknown, documentLoader?: DocumentLoader, depth?: number, inheritedContext?: unknown): Promise<unknown>;
|
|
47
|
+
//#endregion
|
|
48
|
+
export { IriTrustOptions, compactJsonLdCache, getJsonLdContext, isTrustedIriOrigin, normalizeJsonLdIris };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/// <reference lib="esnext.temporal" />
|
|
2
|
+
import { n as DocumentLoader } from "../docloader-xRGn1azD.js";
|
|
3
|
+
|
|
4
|
+
//#region src/internal/jsonld-cache.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Options for deciding whether two IRIs should be treated as same-origin.
|
|
7
|
+
*
|
|
8
|
+
* @internal Technically exported for generated vocabulary classes, but not
|
|
9
|
+
* part of the public API contract. This is not considered public API for
|
|
10
|
+
* Semantic Versioning decisions.
|
|
11
|
+
*/
|
|
12
|
+
interface IriTrustOptions {
|
|
13
|
+
crossOrigin?: "ignore" | "throw" | "trust";
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Checks whether an IRI is trusted relative to another IRI.
|
|
17
|
+
*
|
|
18
|
+
* @internal Technically exported for generated vocabulary classes, but not
|
|
19
|
+
* part of the public API contract. This is not considered public API for
|
|
20
|
+
* Semantic Versioning decisions.
|
|
21
|
+
*/
|
|
22
|
+
declare function isTrustedIriOrigin(options: IriTrustOptions, left: URL | null | undefined, right: URL | null | undefined): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Normalizes portable IRIs in JSON-LD cache data.
|
|
25
|
+
*
|
|
26
|
+
* @internal Technically exported for generated vocabulary classes, but not
|
|
27
|
+
* part of the public API contract. This is not considered public API for
|
|
28
|
+
* Semantic Versioning decisions.
|
|
29
|
+
*/
|
|
30
|
+
declare function normalizeJsonLdIris(value: unknown, iriKeys: ReadonlySet<string>, iriPattern?: RegExp): unknown;
|
|
31
|
+
/**
|
|
32
|
+
* Finds the first JSON-LD context in a value.
|
|
33
|
+
*
|
|
34
|
+
* @internal Technically exported for generated vocabulary classes, but not
|
|
35
|
+
* part of the public API contract. This is not considered public API for
|
|
36
|
+
* Semantic Versioning decisions.
|
|
37
|
+
*/
|
|
38
|
+
declare function getJsonLdContext(value: unknown, depth?: number): unknown;
|
|
39
|
+
/**
|
|
40
|
+
* Recompacts normalized JSON-LD cache data against the original context.
|
|
41
|
+
*
|
|
42
|
+
* @internal Technically exported for generated vocabulary classes, but not
|
|
43
|
+
* part of the public API contract. This is not considered public API for
|
|
44
|
+
* Semantic Versioning decisions.
|
|
45
|
+
*/
|
|
46
|
+
declare function compactJsonLdCache(normalized: unknown, original: unknown, documentLoader?: DocumentLoader, depth?: number, inheritedContext?: unknown): Promise<unknown>;
|
|
47
|
+
//#endregion
|
|
48
|
+
export { IriTrustOptions, compactJsonLdCache, getJsonLdContext, isTrustedIriOrigin, normalizeJsonLdIris };
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
|
|
2
|
+
import { i as haveSameIriOrigin, r as formatIri } from "../url-BuxPHxK2.js";
|
|
3
|
+
import jsonld_default from "../jsonld.js";
|
|
4
|
+
//#region src/internal/jsonld-cache.ts
|
|
5
|
+
const noJsonLdContext = Symbol("noJsonLdContext");
|
|
6
|
+
/**
|
|
7
|
+
* Checks whether an IRI is trusted relative to another IRI.
|
|
8
|
+
*
|
|
9
|
+
* @internal Technically exported for generated vocabulary classes, but not
|
|
10
|
+
* part of the public API contract. This is not considered public API for
|
|
11
|
+
* Semantic Versioning decisions.
|
|
12
|
+
*/
|
|
13
|
+
function isTrustedIriOrigin(options, left, right) {
|
|
14
|
+
return options.crossOrigin === "trust" || left == null || right != null && haveSameIriOrigin(left, right);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Normalizes portable IRIs in JSON-LD cache data.
|
|
18
|
+
*
|
|
19
|
+
* @internal Technically exported for generated vocabulary classes, but not
|
|
20
|
+
* part of the public API contract. This is not considered public API for
|
|
21
|
+
* Semantic Versioning decisions.
|
|
22
|
+
*/
|
|
23
|
+
function normalizeJsonLdIris(value, iriKeys, iriPattern = /^ap(?:\+ef61)?:\/\//i) {
|
|
24
|
+
return normalize(value, void 0, 0, void 0);
|
|
25
|
+
function isIriPosition(key, parentKey) {
|
|
26
|
+
return iriKeys.has(key) || (key === "@value" || key === "@list" || key === "@set") && parentKey != null && iriKeys.has(parentKey);
|
|
27
|
+
}
|
|
28
|
+
function arrayItemParentKey(key, parentKey) {
|
|
29
|
+
return key === "@list" || key === "@set" ? parentKey : key;
|
|
30
|
+
}
|
|
31
|
+
function entryParentKey(entryKey, key, parentKey) {
|
|
32
|
+
if (entryKey === "@list" || entryKey === "@set") return parentKey ?? key;
|
|
33
|
+
return key === "@list" || key === "@set" ? parentKey : key;
|
|
34
|
+
}
|
|
35
|
+
function normalize(value, key, depth = 0, parentKey) {
|
|
36
|
+
if (depth > 32 || key === "@context") return value;
|
|
37
|
+
if (typeof value === "string") {
|
|
38
|
+
if (key != null && isIriPosition(key, parentKey) && iriPattern.test(value)) try {
|
|
39
|
+
return formatIri(value);
|
|
40
|
+
} catch {
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
if (Array.isArray(value)) {
|
|
46
|
+
let clone;
|
|
47
|
+
const itemParentKey = arrayItemParentKey(key, parentKey);
|
|
48
|
+
for (let i = 0; i < value.length; i++) {
|
|
49
|
+
const result = normalize(value[i], key, depth + 1, itemParentKey);
|
|
50
|
+
if (result !== value[i]) {
|
|
51
|
+
clone ??= value.slice(0, i);
|
|
52
|
+
clone.push(result);
|
|
53
|
+
} else if (clone != null) clone.push(value[i]);
|
|
54
|
+
}
|
|
55
|
+
return clone ?? value;
|
|
56
|
+
}
|
|
57
|
+
if (value == null || typeof value !== "object") return value;
|
|
58
|
+
const object = value;
|
|
59
|
+
let clone;
|
|
60
|
+
for (const entryKey of globalThis.Object.keys(object)) {
|
|
61
|
+
const result = normalize(object[entryKey], entryKey, depth + 1, entryParentKey(entryKey, key, parentKey));
|
|
62
|
+
if (result !== object[entryKey]) {
|
|
63
|
+
clone ??= { ...object };
|
|
64
|
+
defineJsonLdProperty(clone, entryKey, result);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return clone ?? object;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Finds the first JSON-LD context in a value.
|
|
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 getJsonLdContext(value, depth = 0) {
|
|
78
|
+
if (depth > 32) return void 0;
|
|
79
|
+
if (Array.isArray(value)) {
|
|
80
|
+
for (const item of value) {
|
|
81
|
+
const context = getJsonLdContext(item, depth + 1);
|
|
82
|
+
if (context !== void 0) return context;
|
|
83
|
+
}
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (value == null || typeof value !== "object" || !("@context" in value)) return;
|
|
87
|
+
return value["@context"];
|
|
88
|
+
}
|
|
89
|
+
function getOwnJsonLdContext(value) {
|
|
90
|
+
if (value == null || typeof value !== "object" || Array.isArray(value) || !("@context" in value)) return noJsonLdContext;
|
|
91
|
+
return value["@context"];
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Recompacts normalized JSON-LD cache data against the original context.
|
|
95
|
+
*
|
|
96
|
+
* @internal Technically exported for generated vocabulary classes, but not
|
|
97
|
+
* part of the public API contract. This is not considered public API for
|
|
98
|
+
* Semantic Versioning decisions.
|
|
99
|
+
*/
|
|
100
|
+
async function compactJsonLdCache(normalized, original, documentLoader, depth = 0, inheritedContext) {
|
|
101
|
+
if (depth > 32) return normalized;
|
|
102
|
+
if (Array.isArray(original)) {
|
|
103
|
+
const normalizedArray = Array.isArray(normalized) ? normalized : normalized != null && typeof normalized === "object" && "@graph" in normalized && Array.isArray(normalized["@graph"]) ? normalized["@graph"] : void 0;
|
|
104
|
+
if (normalizedArray == null) return normalized;
|
|
105
|
+
let clone;
|
|
106
|
+
for (let i = 0; i < normalizedArray.length; i++) {
|
|
107
|
+
const item = await compactJsonLdCache(normalizedArray[i], original[i], documentLoader, depth + 1, inheritedContext);
|
|
108
|
+
if (item !== normalizedArray[i]) {
|
|
109
|
+
clone ??= normalizedArray.slice(0, i);
|
|
110
|
+
clone.push(item);
|
|
111
|
+
} else if (clone != null) clone.push(normalizedArray[i]);
|
|
112
|
+
}
|
|
113
|
+
return clone ?? (Array.isArray(normalized) ? normalized : normalizedArray);
|
|
114
|
+
}
|
|
115
|
+
const ownContext = getOwnJsonLdContext(original);
|
|
116
|
+
const context = ownContext === noJsonLdContext ? inheritedContext : ownContext;
|
|
117
|
+
if (context == null) return preserveNoContextJsonLdShape(normalized, original, depth);
|
|
118
|
+
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);
|
|
119
|
+
}
|
|
120
|
+
function preserveNoContextJsonLdShape(normalized, original, depth = 0) {
|
|
121
|
+
if (depth > 32) return normalized;
|
|
122
|
+
if (original == null || typeof original !== "object" || Array.isArray(original)) return normalized;
|
|
123
|
+
const normalizedObject = Array.isArray(normalized) && normalized.length === 1 ? normalized[0] : normalized;
|
|
124
|
+
if (normalizedObject == null || typeof normalizedObject !== "object" || Array.isArray(normalizedObject)) return normalized;
|
|
125
|
+
const source = normalizedObject;
|
|
126
|
+
const originalObject = original;
|
|
127
|
+
let clone;
|
|
128
|
+
for (const key of globalThis.Object.keys(originalObject)) {
|
|
129
|
+
if (!globalThis.Object.prototype.hasOwnProperty.call(source, key)) continue;
|
|
130
|
+
const value = preserveNoContextValue(source[key], originalObject[key], depth + 1);
|
|
131
|
+
if (value !== originalObject[key]) {
|
|
132
|
+
clone ??= { ...originalObject };
|
|
133
|
+
defineJsonLdProperty(clone, key, value);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return clone ?? original;
|
|
137
|
+
}
|
|
138
|
+
function preserveNoContextValue(normalized, original, depth) {
|
|
139
|
+
if (depth > 32) return normalized;
|
|
140
|
+
if (Array.isArray(original)) {
|
|
141
|
+
const normalizedArray = Array.isArray(normalized) ? normalized : [normalized];
|
|
142
|
+
let clone;
|
|
143
|
+
for (let i = 0; i < original.length; i++) {
|
|
144
|
+
const value = preserveNoContextValue(normalizedArray[i], original[i], depth + 1);
|
|
145
|
+
if (value !== original[i]) {
|
|
146
|
+
clone ??= original.slice(0, i);
|
|
147
|
+
clone.push(value);
|
|
148
|
+
} else if (clone != null) clone.push(original[i]);
|
|
149
|
+
}
|
|
150
|
+
return clone ?? original;
|
|
151
|
+
}
|
|
152
|
+
const normalizedValue = Array.isArray(normalized) ? normalized[0] : normalized;
|
|
153
|
+
if (normalizedValue == null || typeof normalizedValue !== "object" || Array.isArray(normalizedValue)) return normalizedValue;
|
|
154
|
+
const normalizedObject = normalizedValue;
|
|
155
|
+
if (original != null && typeof original === "object" && !Array.isArray(original)) return preserveNoContextJsonLdShape(normalizedObject, original, depth + 1);
|
|
156
|
+
if (typeof normalizedObject["@id"] === "string") return normalizedObject["@id"];
|
|
157
|
+
if ("@value" in normalizedObject) return normalizedObject["@value"];
|
|
158
|
+
return normalizedValue;
|
|
159
|
+
}
|
|
160
|
+
function getTopLevelTerms(value) {
|
|
161
|
+
const terms = /* @__PURE__ */ new Set();
|
|
162
|
+
const nodes = Array.isArray(value) ? value : [value];
|
|
163
|
+
for (const node of nodes) {
|
|
164
|
+
if (node == null || typeof node !== "object" || Array.isArray(node)) continue;
|
|
165
|
+
for (const key of globalThis.Object.keys(node)) {
|
|
166
|
+
if (key.startsWith("@")) continue;
|
|
167
|
+
terms.add(key);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return terms;
|
|
171
|
+
}
|
|
172
|
+
async function mergeUnmappedTerms(compacted, original, context, documentLoader) {
|
|
173
|
+
if (original == null || typeof original !== "object" || Array.isArray(original) || compacted == null || typeof compacted !== "object" || Array.isArray(compacted)) return compacted;
|
|
174
|
+
const unmappedKeys = globalThis.Object.keys(original).filter((key) => key !== "@context" && !globalThis.Object.prototype.hasOwnProperty.call(compacted, key));
|
|
175
|
+
if (unmappedKeys.length < 1) return compacted;
|
|
176
|
+
const result = { ...compacted };
|
|
177
|
+
const compactedWithContext = compacted != null && typeof compacted === "object" && !Array.isArray(compacted) && !("@context" in compacted) ? {
|
|
178
|
+
"@context": context,
|
|
179
|
+
...compacted
|
|
180
|
+
} : compacted;
|
|
181
|
+
const compactedTerms = getTopLevelTerms(await jsonld_default.expand(compactedWithContext, { documentLoader }));
|
|
182
|
+
const dummyPrefix = "urn:fedify:dummy:";
|
|
183
|
+
const dummy = { "@context": context };
|
|
184
|
+
for (let i = 0; i < unmappedKeys.length; i++) defineJsonLdProperty(dummy, unmappedKeys[i], `${dummyPrefix}${i}`);
|
|
185
|
+
const expanded = await jsonld_default.expand(dummy, { documentLoader });
|
|
186
|
+
const representedKeys = /* @__PURE__ */ new Set();
|
|
187
|
+
const nodes = Array.isArray(expanded) ? expanded : [expanded];
|
|
188
|
+
for (const node of nodes) {
|
|
189
|
+
if (node == null || typeof node !== "object" || Array.isArray(node)) continue;
|
|
190
|
+
for (const [term, termValue] of globalThis.Object.entries(node)) {
|
|
191
|
+
if (!compactedTerms.has(term)) continue;
|
|
192
|
+
for (let i = 0; i < unmappedKeys.length; i++) if (containsValue(termValue, `${dummyPrefix}${i}`)) representedKeys.add(unmappedKeys[i]);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
for (const key of unmappedKeys) if (!representedKeys.has(key)) defineJsonLdProperty(result, key, original[key]);
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
function defineJsonLdProperty(object, key, value) {
|
|
199
|
+
globalThis.Object.defineProperty(object, key, {
|
|
200
|
+
value,
|
|
201
|
+
enumerable: true,
|
|
202
|
+
configurable: true,
|
|
203
|
+
writable: true
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
function containsValue(value, expected, depth = 0) {
|
|
207
|
+
if (depth > 32) return false;
|
|
208
|
+
if (value === expected) return true;
|
|
209
|
+
if (Array.isArray(value)) return value.some((item) => containsValue(item, expected, depth + 1));
|
|
210
|
+
if (value == null || typeof value !== "object") return false;
|
|
211
|
+
return globalThis.Object.entries(value).some(([key, item]) => key !== "@context" && containsValue(item, expected, depth + 1));
|
|
212
|
+
}
|
|
213
|
+
async function preserveJsonLdShape(compacted, original, context, documentLoader, depth = 0) {
|
|
214
|
+
if (depth > 32) return compacted;
|
|
215
|
+
if (compacted === original) return compacted;
|
|
216
|
+
if (original == null || typeof original !== "object" || compacted == null || typeof compacted !== "object") return compacted;
|
|
217
|
+
if (Array.isArray(original)) {
|
|
218
|
+
const compactedArray = Array.isArray(compacted) ? compacted : "@graph" in compacted && Array.isArray(compacted["@graph"]) ? compacted["@graph"] : void 0;
|
|
219
|
+
if (compactedArray == null) return compacted;
|
|
220
|
+
let clone;
|
|
221
|
+
for (let i = 0; i < compactedArray.length; i++) {
|
|
222
|
+
const value = await preserveJsonLdShape(compactedArray[i], original[i], context, documentLoader, depth + 1);
|
|
223
|
+
const originalContext = original[i] != null && typeof original[i] === "object" && !Array.isArray(original[i]) && "@context" in original[i] ? original[i]["@context"] : void 0;
|
|
224
|
+
const shaped = originalContext !== void 0 && value != null && typeof value === "object" && !Array.isArray(value) && !("@context" in value) ? {
|
|
225
|
+
"@context": originalContext,
|
|
226
|
+
...value
|
|
227
|
+
} : value;
|
|
228
|
+
if (shaped !== compactedArray[i]) {
|
|
229
|
+
clone ??= compactedArray.slice(0, i);
|
|
230
|
+
clone.push(shaped);
|
|
231
|
+
} else if (clone != null) clone.push(compactedArray[i]);
|
|
232
|
+
}
|
|
233
|
+
return clone ?? (Array.isArray(compacted) ? compacted : compactedArray);
|
|
234
|
+
}
|
|
235
|
+
if (Array.isArray(compacted)) return compacted;
|
|
236
|
+
let clone;
|
|
237
|
+
const ownContext = getOwnJsonLdContext(original);
|
|
238
|
+
const objectContext = combineContexts(context, ownContext);
|
|
239
|
+
const objectCompacted = depth > 0 && ownContext === null ? await compactWithEmptyContext(compacted, context, documentLoader) : compacted;
|
|
240
|
+
const compactedObject = depth > 0 ? await mergeUnmappedTerms(objectCompacted, original, objectContext, documentLoader) : objectCompacted;
|
|
241
|
+
const originalObject = original;
|
|
242
|
+
for (const key of globalThis.Object.keys(compactedObject)) {
|
|
243
|
+
if (key === "@context") continue;
|
|
244
|
+
const value = await preserveJsonLdShape(compactedObject[key], originalObject[key], objectContext, documentLoader, depth + 1);
|
|
245
|
+
const shaped = Array.isArray(originalObject[key]) && !Array.isArray(value) ? [value] : value;
|
|
246
|
+
if (shaped !== compactedObject[key]) {
|
|
247
|
+
clone ??= { ...compactedObject };
|
|
248
|
+
defineJsonLdProperty(clone, key, shaped);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (depth > 0) {
|
|
252
|
+
if ("@context" in originalObject && !("@context" in compactedObject)) {
|
|
253
|
+
clone ??= { ...compactedObject };
|
|
254
|
+
clone["@context"] = originalObject["@context"];
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return clone ?? compactedObject;
|
|
258
|
+
}
|
|
259
|
+
async function compactWithEmptyContext(compacted, context, documentLoader) {
|
|
260
|
+
const compactedWithContext = compacted != null && typeof compacted === "object" && !Array.isArray(compacted) && !("@context" in compacted) ? {
|
|
261
|
+
"@context": context,
|
|
262
|
+
...compacted
|
|
263
|
+
} : compacted;
|
|
264
|
+
const expanded = await jsonld_default.expand(compactedWithContext, { documentLoader });
|
|
265
|
+
return await jsonld_default.compact(expanded, {}, { documentLoader });
|
|
266
|
+
}
|
|
267
|
+
function combineContexts(inheritedContext, ownContext) {
|
|
268
|
+
if (ownContext === noJsonLdContext || ownContext === inheritedContext) return inheritedContext;
|
|
269
|
+
if (ownContext == null) return ownContext;
|
|
270
|
+
const inherited = Array.isArray(inheritedContext) ? inheritedContext : [inheritedContext];
|
|
271
|
+
const own = Array.isArray(ownContext) ? ownContext : [ownContext];
|
|
272
|
+
return [...inherited, ...own];
|
|
273
|
+
}
|
|
274
|
+
//#endregion
|
|
275
|
+
export { compactJsonLdCache, getJsonLdContext, isTrustedIriOrigin, normalizeJsonLdIris };
|
package/dist/mod.cjs
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const require_chunk = require("./chunk-M78iaK0I.cjs");
|
|
4
|
+
const require_url = require("./url-BAdyyqAa.cjs");
|
|
4
5
|
let _logtape_logtape = require("@logtape/logtape");
|
|
5
6
|
let _opentelemetry_api = require("@opentelemetry/api");
|
|
6
7
|
let node_process = require("node:process");
|
|
7
8
|
node_process = require_chunk.__toESM(node_process, 1);
|
|
8
|
-
let node_dns_promises = require("node:dns/promises");
|
|
9
|
-
let node_net = require("node:net");
|
|
10
9
|
let asn1js = require("asn1js");
|
|
11
10
|
let byte_encodings_base64 = require("byte-encodings/base64");
|
|
12
11
|
let byte_encodings_base64url = require("byte-encodings/base64url");
|
|
@@ -4346,7 +4345,7 @@ const preloadedContexts = {
|
|
|
4346
4345
|
//#endregion
|
|
4347
4346
|
//#region deno.json
|
|
4348
4347
|
var name = "@fedify/vocab-runtime";
|
|
4349
|
-
var version = "2.4.0-dev.
|
|
4348
|
+
var version = "2.4.0-dev.1528+fea670ad";
|
|
4350
4349
|
//#endregion
|
|
4351
4350
|
//#region src/link.ts
|
|
4352
4351
|
const parametersNeedLowerCase = ["rel", "type"];
|
|
@@ -4599,179 +4598,6 @@ function logRequest(logger, request) {
|
|
|
4599
4598
|
});
|
|
4600
4599
|
}
|
|
4601
4600
|
//#endregion
|
|
4602
|
-
//#region src/url.ts
|
|
4603
|
-
var UrlError = class extends Error {
|
|
4604
|
-
constructor(message) {
|
|
4605
|
-
super(message);
|
|
4606
|
-
this.name = "UrlError";
|
|
4607
|
-
}
|
|
4608
|
-
};
|
|
4609
|
-
/**
|
|
4610
|
-
* Validates a URL to prevent SSRF attacks.
|
|
4611
|
-
*/
|
|
4612
|
-
async function validatePublicUrl(url) {
|
|
4613
|
-
const parsed = new URL(url);
|
|
4614
|
-
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new UrlError(`Unsupported protocol: ${parsed.protocol}`);
|
|
4615
|
-
let hostname = parsed.hostname;
|
|
4616
|
-
if (hostname.startsWith("[") && hostname.endsWith("]")) hostname = hostname.slice(1, -1);
|
|
4617
|
-
if (hostname === "localhost") throw new UrlError("Localhost is not allowed");
|
|
4618
|
-
const hostnameFamily = (0, node_net.isIP)(hostname);
|
|
4619
|
-
if (hostnameFamily !== 0) {
|
|
4620
|
-
validatePublicIpAddress(hostname, hostnameFamily);
|
|
4621
|
-
return;
|
|
4622
|
-
}
|
|
4623
|
-
if ("Deno" in globalThis && !(0, node_net.isIP)(hostname)) {
|
|
4624
|
-
if ((await Deno.permissions.query({ name: "net" })).state !== "granted") return;
|
|
4625
|
-
}
|
|
4626
|
-
if ("Bun" in globalThis) {
|
|
4627
|
-
if (hostname === "example.com" || hostname.endsWith(".example.com")) return;
|
|
4628
|
-
else if (hostname === "fedify-test.internal") throw new UrlError("Invalid or private address: fedify-test.internal");
|
|
4629
|
-
}
|
|
4630
|
-
let addresses;
|
|
4631
|
-
try {
|
|
4632
|
-
addresses = await (0, node_dns_promises.lookup)(hostname, { all: true });
|
|
4633
|
-
} catch {
|
|
4634
|
-
addresses = [];
|
|
4635
|
-
}
|
|
4636
|
-
for (const { address, family } of addresses) validatePublicIpAddress(address, family);
|
|
4637
|
-
}
|
|
4638
|
-
function validatePublicIpAddress(address, family) {
|
|
4639
|
-
if (family === 4 && isValidPublicIPv4Address(address) || family === 6 && isValidPublicIPv6Address(address)) return;
|
|
4640
|
-
throw new UrlError(`Invalid or private address: ${address}`);
|
|
4641
|
-
}
|
|
4642
|
-
function isValidPublicIPv4Address(address) {
|
|
4643
|
-
const parts = parseIPv4Address(address);
|
|
4644
|
-
if (parts == null) return false;
|
|
4645
|
-
const value = ipv4PartsToNumber(parts);
|
|
4646
|
-
return !nonPublicIPv4Prefixes.some(({ base, prefix }) => matchesIPv4Prefix(value, base, prefix));
|
|
4647
|
-
}
|
|
4648
|
-
function isValidPublicIPv6Address(address) {
|
|
4649
|
-
const words = parseIPv6Address(address);
|
|
4650
|
-
if (words == null) return false;
|
|
4651
|
-
if (nonPublicIPv6Prefixes.some(({ words: prefixWords, prefix }) => matchesIPv6Prefix(words, prefixWords, prefix))) return false;
|
|
4652
|
-
for (const { extractIPv4, prefix, words: prefixWords } of ipv6WithIPv4Prefixes) {
|
|
4653
|
-
if (!matchesIPv6Prefix(words, prefixWords, prefix)) continue;
|
|
4654
|
-
const ipv4Address = extractIPv4(words);
|
|
4655
|
-
if (ipv4Address != null && !isValidPublicIPv4Address(ipv4Address)) return false;
|
|
4656
|
-
}
|
|
4657
|
-
return true;
|
|
4658
|
-
}
|
|
4659
|
-
function expandIPv6Address(address) {
|
|
4660
|
-
address = address.toLowerCase();
|
|
4661
|
-
const ipv4Delimiter = address.lastIndexOf(":");
|
|
4662
|
-
if (address.includes(".") && ipv4Delimiter >= 0) {
|
|
4663
|
-
const ipv4Parts = parseIPv4Address(address.substring(ipv4Delimiter + 1));
|
|
4664
|
-
if (ipv4Parts == null) return address;
|
|
4665
|
-
const high = (ipv4Parts[0] << 8) + ipv4Parts[1];
|
|
4666
|
-
const low = (ipv4Parts[2] << 8) + ipv4Parts[3];
|
|
4667
|
-
address = address.substring(0, ipv4Delimiter + 1) + high.toString(16) + ":" + low.toString(16);
|
|
4668
|
-
}
|
|
4669
|
-
if (address === "::") return "0000:0000:0000:0000:0000:0000:0000:0000";
|
|
4670
|
-
if (address.startsWith("::")) address = "0000" + address;
|
|
4671
|
-
if (address.endsWith("::")) address = address + "0000";
|
|
4672
|
-
address = address.replace("::", ":0000".repeat(8 - (address.match(/:/g) || []).length) + ":");
|
|
4673
|
-
return address.split(":").map((part) => part.padStart(4, "0")).join(":");
|
|
4674
|
-
}
|
|
4675
|
-
const nonPublicIPv4Prefixes = [
|
|
4676
|
-
ipv4Prefix("0.0.0.0/8", "RFC 6890"),
|
|
4677
|
-
ipv4Prefix("10.0.0.0/8", "RFC 1918"),
|
|
4678
|
-
ipv4Prefix("100.64.0.0/10", "RFC 6598"),
|
|
4679
|
-
ipv4Prefix("127.0.0.0/8", "RFC 1122"),
|
|
4680
|
-
ipv4Prefix("169.254.0.0/16", "RFC 3927"),
|
|
4681
|
-
ipv4Prefix("172.16.0.0/12", "RFC 1918"),
|
|
4682
|
-
ipv4Prefix("192.0.0.0/24", "RFC 6890"),
|
|
4683
|
-
ipv4Prefix("192.0.2.0/24", "RFC 5737"),
|
|
4684
|
-
ipv4Prefix("192.88.99.0/24", "RFC 7526"),
|
|
4685
|
-
ipv4Prefix("192.168.0.0/16", "RFC 1918"),
|
|
4686
|
-
ipv4Prefix("198.18.0.0/15", "RFC 2544"),
|
|
4687
|
-
ipv4Prefix("198.51.100.0/24", "RFC 5737"),
|
|
4688
|
-
ipv4Prefix("203.0.113.0/24", "RFC 5737"),
|
|
4689
|
-
ipv4Prefix("224.0.0.0/4", "RFC 5771"),
|
|
4690
|
-
ipv4Prefix("240.0.0.0/4", "RFC 1112")
|
|
4691
|
-
];
|
|
4692
|
-
const nonPublicIPv6Prefixes = [
|
|
4693
|
-
ipv6Prefix("::/16", "RFC 4291"),
|
|
4694
|
-
ipv6Prefix("2001::/32", "RFC 4380"),
|
|
4695
|
-
ipv6Prefix("2002::/16", "RFC 3056"),
|
|
4696
|
-
ipv6Prefix("64:ff9b:1::/48", "RFC 8215"),
|
|
4697
|
-
ipv6Prefix("fc00::/7", "RFC 4193"),
|
|
4698
|
-
ipv6Prefix("fe80::/10", "RFC 4291"),
|
|
4699
|
-
ipv6Prefix("ff00::/8", "RFC 4291")
|
|
4700
|
-
];
|
|
4701
|
-
const ipv6WithIPv4Prefixes = [{
|
|
4702
|
-
...ipv6Prefix("64:ff9b::/96", "RFC 6052"),
|
|
4703
|
-
extractIPv4: (words) => ipv4FromWords(words[6], words[7])
|
|
4704
|
-
}];
|
|
4705
|
-
function ipv4Prefix(cidr, rfc) {
|
|
4706
|
-
const [address, prefixText] = cidr.split("/");
|
|
4707
|
-
const prefix = parseInt(prefixText, 10);
|
|
4708
|
-
const parts = parseIPv4Address(address);
|
|
4709
|
-
if (parts == null || !Number.isInteger(prefix) || prefix < 0 || prefix > 32) throw new Error(`Invalid IPv4 prefix: ${cidr}`);
|
|
4710
|
-
return {
|
|
4711
|
-
cidr,
|
|
4712
|
-
base: ipv4PartsToNumber(parts),
|
|
4713
|
-
prefix,
|
|
4714
|
-
rfc
|
|
4715
|
-
};
|
|
4716
|
-
}
|
|
4717
|
-
function ipv6Prefix(cidr, rfc) {
|
|
4718
|
-
const [address, prefixText] = cidr.split("/");
|
|
4719
|
-
const prefix = parseInt(prefixText, 10);
|
|
4720
|
-
const words = parseIPv6Address(address);
|
|
4721
|
-
if (words == null || !Number.isInteger(prefix) || prefix < 0 || prefix > 128) throw new Error(`Invalid IPv6 prefix: ${cidr}`);
|
|
4722
|
-
return {
|
|
4723
|
-
cidr,
|
|
4724
|
-
words,
|
|
4725
|
-
prefix,
|
|
4726
|
-
rfc
|
|
4727
|
-
};
|
|
4728
|
-
}
|
|
4729
|
-
function parseIPv4Address(address) {
|
|
4730
|
-
const parts = address.split(".").map((part) => {
|
|
4731
|
-
if (!/^\d+$/.test(part)) return NaN;
|
|
4732
|
-
return parseInt(part, 10);
|
|
4733
|
-
});
|
|
4734
|
-
if (parts.length !== 4 || parts.some((part) => !Number.isInteger(part) || part < 0 || part > 255)) return null;
|
|
4735
|
-
return parts;
|
|
4736
|
-
}
|
|
4737
|
-
function parseIPv6Address(address) {
|
|
4738
|
-
const parts = expandIPv6Address(address).split(":");
|
|
4739
|
-
if (parts.length !== 8) return null;
|
|
4740
|
-
const words = parts.map((part) => {
|
|
4741
|
-
if (!/^[0-9a-f]{1,4}$/i.test(part)) return NaN;
|
|
4742
|
-
return parseInt(part, 16);
|
|
4743
|
-
});
|
|
4744
|
-
if (words.some((word) => !Number.isInteger(word) || word < 0 || word > 65535)) return null;
|
|
4745
|
-
return words;
|
|
4746
|
-
}
|
|
4747
|
-
function ipv4PartsToNumber(parts) {
|
|
4748
|
-
return parts[0] * 2 ** 24 + parts[1] * 2 ** 16 + parts[2] * 2 ** 8 + parts[3];
|
|
4749
|
-
}
|
|
4750
|
-
function ipv4FromWords(highWord, lowWord) {
|
|
4751
|
-
return [
|
|
4752
|
-
highWord >> 8,
|
|
4753
|
-
highWord & 255,
|
|
4754
|
-
lowWord >> 8,
|
|
4755
|
-
lowWord & 255
|
|
4756
|
-
].join(".");
|
|
4757
|
-
}
|
|
4758
|
-
function matchesIPv4Prefix(address, prefixBase, prefixLength) {
|
|
4759
|
-
const blockSize = 2 ** (32 - prefixLength);
|
|
4760
|
-
return Math.floor(address / blockSize) === Math.floor(prefixBase / blockSize);
|
|
4761
|
-
}
|
|
4762
|
-
function matchesIPv6Prefix(address, prefixWords, prefixLength) {
|
|
4763
|
-
let remaining = prefixLength;
|
|
4764
|
-
for (let i = 0; i < 8 && remaining > 0; i++) if (remaining >= 16) {
|
|
4765
|
-
if (address[i] !== prefixWords[i]) return false;
|
|
4766
|
-
remaining -= 16;
|
|
4767
|
-
} else {
|
|
4768
|
-
const mask = 65535 << 16 - remaining & 65535;
|
|
4769
|
-
if ((address[i] & mask) !== (prefixWords[i] & mask)) return false;
|
|
4770
|
-
remaining = 0;
|
|
4771
|
-
}
|
|
4772
|
-
return true;
|
|
4773
|
-
}
|
|
4774
|
-
//#endregion
|
|
4775
4601
|
//#region src/docloader.ts
|
|
4776
4602
|
const logger = (0, _logtape_logtape.getLogger)([
|
|
4777
4603
|
"fedify",
|
|
@@ -4908,9 +4734,9 @@ function getDocumentLoader({ allowPrivateAddress, maxRedirection, skipPreloadedC
|
|
|
4908
4734
|
};
|
|
4909
4735
|
}
|
|
4910
4736
|
if (!allowPrivateAddress) try {
|
|
4911
|
-
await validatePublicUrl(currentUrl);
|
|
4737
|
+
await require_url.validatePublicUrl(currentUrl);
|
|
4912
4738
|
} catch (error) {
|
|
4913
|
-
if (error instanceof UrlError) logger.error("Disallowed private URL: {url}", {
|
|
4739
|
+
if (error instanceof require_url.UrlError) logger.error("Disallowed private URL: {url}", {
|
|
4914
4740
|
url: currentUrl,
|
|
4915
4741
|
error
|
|
4916
4742
|
});
|
|
@@ -5569,26 +5395,30 @@ LanguageString.prototype[Symbol.for("nodejs.util.inspect.custom")] = function(_d
|
|
|
5569
5395
|
//#endregion
|
|
5570
5396
|
exports.FetchError = FetchError;
|
|
5571
5397
|
exports.LanguageString = LanguageString;
|
|
5572
|
-
exports.UrlError = UrlError;
|
|
5398
|
+
exports.UrlError = require_url.UrlError;
|
|
5573
5399
|
exports.canParseDecimal = canParseDecimal;
|
|
5574
5400
|
exports.createActivityPubRequest = createActivityPubRequest;
|
|
5575
5401
|
exports.decodeMultibase = decodeMultibase;
|
|
5576
5402
|
exports.encodeMultibase = encodeMultibase;
|
|
5577
5403
|
exports.encodingFromBaseData = encodingFromBaseData;
|
|
5578
|
-
exports.expandIPv6Address = expandIPv6Address;
|
|
5404
|
+
exports.expandIPv6Address = require_url.expandIPv6Address;
|
|
5579
5405
|
exports.exportMultibaseKey = exportMultibaseKey;
|
|
5580
5406
|
exports.exportSpki = exportSpki;
|
|
5407
|
+
exports.formatIri = require_url.formatIri;
|
|
5581
5408
|
exports.getDocumentLoader = getDocumentLoader;
|
|
5582
5409
|
exports.getRemoteDocument = getRemoteDocument;
|
|
5583
5410
|
exports.getUserAgent = getUserAgent;
|
|
5411
|
+
exports.haveSameIriOrigin = require_url.haveSameIriOrigin;
|
|
5584
5412
|
exports.importMultibaseKey = importMultibaseKey;
|
|
5585
5413
|
exports.importPem = importPem;
|
|
5586
5414
|
exports.importPkcs1 = importPkcs1;
|
|
5587
5415
|
exports.importSpki = importSpki;
|
|
5588
5416
|
exports.isDecimal = isDecimal;
|
|
5589
|
-
exports.isValidPublicIPv4Address = isValidPublicIPv4Address;
|
|
5590
|
-
exports.isValidPublicIPv6Address = isValidPublicIPv6Address;
|
|
5417
|
+
exports.isValidPublicIPv4Address = require_url.isValidPublicIPv4Address;
|
|
5418
|
+
exports.isValidPublicIPv6Address = require_url.isValidPublicIPv6Address;
|
|
5591
5419
|
exports.logRequest = logRequest;
|
|
5592
5420
|
exports.parseDecimal = parseDecimal;
|
|
5421
|
+
exports.parseIri = require_url.parseIri;
|
|
5422
|
+
exports.parseJsonLdId = require_url.parseJsonLdId;
|
|
5593
5423
|
exports.preloadedContexts = preloadedContexts;
|
|
5594
|
-
exports.validatePublicUrl = validatePublicUrl;
|
|
5424
|
+
exports.validatePublicUrl = require_url.validatePublicUrl;
|