@fedify/vocab-runtime 2.4.0-dev.1564 → 2.4.0-dev.1570
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deno.json +1 -2
- package/dist/mod.cjs +190 -107
- package/dist/mod.d.cts +200 -18
- package/dist/mod.d.ts +200 -18
- package/dist/mod.js +184 -97
- package/dist/tests/decimal.test.cjs +2 -2
- package/dist/tests/decimal.test.mjs +2 -2
- package/dist/tests/{docloader-CYQvKbtL.mjs → docloader-C76ldE5C.mjs} +10 -97
- package/dist/tests/{docloader-UAdXnDwt.cjs → docloader-mvgIWKI7.cjs} +9 -102
- package/dist/tests/docloader.test.cjs +6 -58
- package/dist/tests/docloader.test.mjs +6 -58
- package/dist/tests/{request-DgAlI7RF.mjs → request-BEXkv1ul.mjs} +1 -1
- package/dist/tests/{request-DnzhAfki.cjs → request-SworbvLc.cjs} +1 -1
- package/dist/tests/request.test.cjs +1 -1
- package/dist/tests/request.test.mjs +1 -1
- package/dist/tests/{url-2XwVbUS_.cjs → url-C20FhC7p.cjs} +0 -108
- package/dist/tests/{url-YWJbnRlf.mjs → url-m9Qzxy-Y.mjs} +1 -85
- package/dist/tests/url.test.cjs +1 -104
- package/dist/tests/url.test.mjs +2 -105
- package/package.json +1 -11
- package/src/contexts.ts +0 -2
- package/src/docloader.test.ts +6 -102
- package/src/docloader.ts +8 -76
- package/src/mod.ts +0 -4
- package/src/url.test.ts +1 -252
- package/src/url.ts +0 -141
- package/tsdown.config.ts +1 -6
- package/dist/docloader-DnUMWHaJ.d.cts +0 -202
- package/dist/docloader-xRGn1azD.d.ts +0 -202
- package/dist/internal/jsonld-cache.cjs +0 -279
- package/dist/internal/jsonld-cache.d.cts +0 -48
- package/dist/internal/jsonld-cache.d.ts +0 -48
- package/dist/internal/jsonld-cache.js +0 -275
- package/dist/tests/jsonld-cache.test.cjs +0 -652
- package/dist/tests/jsonld-cache.test.d.cts +0 -1
- package/dist/tests/jsonld-cache.test.d.mts +0 -1
- package/dist/tests/jsonld-cache.test.mjs +0 -651
- package/dist/url-BAdyyqAa.cjs +0 -315
- package/dist/url-BuxPHxK2.js +0 -261
- package/src/contexts/fep-7aa9.json +0 -24
- package/src/internal/jsonld-cache.ts +0 -538
- package/src/jsonld-cache.test.ts +0 -554
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import { Logger } from "@logtape/logtape";
|
|
3
|
-
|
|
4
|
-
//#region src/request.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Error thrown when fetching a JSON-LD document failed.
|
|
7
|
-
*/
|
|
8
|
-
declare class FetchError extends Error {
|
|
9
|
-
/**
|
|
10
|
-
* The URL that failed to fetch.
|
|
11
|
-
*/
|
|
12
|
-
url: URL;
|
|
13
|
-
/**
|
|
14
|
-
* The HTTP response that failed, if available.
|
|
15
|
-
*/
|
|
16
|
-
response?: Response;
|
|
17
|
-
/**
|
|
18
|
-
* Constructs a new `FetchError`.
|
|
19
|
-
*
|
|
20
|
-
* @param url The URL that failed to fetch.
|
|
21
|
-
* @param message Error message.
|
|
22
|
-
* @param response The failed HTTP response, if available.
|
|
23
|
-
*/
|
|
24
|
-
constructor(url: URL | string, message?: string, response?: Response);
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Options for creating a request.
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
|
-
interface CreateRequestOptions {
|
|
31
|
-
userAgent?: GetUserAgentOptions | string;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Creates a request for the given URL.
|
|
35
|
-
* @param url The URL to create the request for.
|
|
36
|
-
* @param options The options for the request.
|
|
37
|
-
* @returns The created request.
|
|
38
|
-
* @internal
|
|
39
|
-
*/
|
|
40
|
-
declare function createActivityPubRequest(url: string, options?: CreateRequestOptions): Request;
|
|
41
|
-
/**
|
|
42
|
-
* Options for making `User-Agent` string.
|
|
43
|
-
* @see {@link getUserAgent}
|
|
44
|
-
* @since 1.3.0
|
|
45
|
-
*/
|
|
46
|
-
interface GetUserAgentOptions {
|
|
47
|
-
/**
|
|
48
|
-
* An optional software name and version, e.g., `"Hollo/1.0.0"`.
|
|
49
|
-
*/
|
|
50
|
-
software?: string | null;
|
|
51
|
-
/**
|
|
52
|
-
* An optional URL to append to the user agent string.
|
|
53
|
-
* Usually the URL of the ActivityPub instance.
|
|
54
|
-
*/
|
|
55
|
-
url?: string | URL | null;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Gets the user agent string for the given application and URL.
|
|
59
|
-
* @param options The options for making the user agent string.
|
|
60
|
-
* @returns The user agent string.
|
|
61
|
-
* @since 1.3.0
|
|
62
|
-
*/
|
|
63
|
-
declare function getUserAgent({
|
|
64
|
-
software,
|
|
65
|
-
url
|
|
66
|
-
}?: GetUserAgentOptions): string;
|
|
67
|
-
/**
|
|
68
|
-
* Logs the request.
|
|
69
|
-
* @param request The request to log.
|
|
70
|
-
* @internal
|
|
71
|
-
*/
|
|
72
|
-
declare function logRequest(logger: Logger, request: Request): void;
|
|
73
|
-
//#endregion
|
|
74
|
-
//#region src/docloader.d.ts
|
|
75
|
-
/**
|
|
76
|
-
* A remote JSON-LD document and its context fetched by
|
|
77
|
-
* a {@link DocumentLoader}.
|
|
78
|
-
*/
|
|
79
|
-
interface RemoteDocument {
|
|
80
|
-
/**
|
|
81
|
-
* The URL of the context document.
|
|
82
|
-
*/
|
|
83
|
-
contextUrl: string | null;
|
|
84
|
-
/**
|
|
85
|
-
* The fetched JSON-LD document.
|
|
86
|
-
*/
|
|
87
|
-
document: unknown;
|
|
88
|
-
/**
|
|
89
|
-
* The URL of the fetched document.
|
|
90
|
-
*/
|
|
91
|
-
documentUrl: string;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Options for {@link DocumentLoader}.
|
|
95
|
-
* @since 1.8.0
|
|
96
|
-
*/
|
|
97
|
-
interface DocumentLoaderOptions {
|
|
98
|
-
/**
|
|
99
|
-
* An `AbortSignal` for cancellation.
|
|
100
|
-
* @since 1.8.0
|
|
101
|
-
*/
|
|
102
|
-
signal?: AbortSignal;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* A JSON-LD document loader that fetches documents from the Web.
|
|
106
|
-
* @param url The URL of the document to load.
|
|
107
|
-
* @param options The options for the document loader.
|
|
108
|
-
* @returns The loaded remote document.
|
|
109
|
-
*/
|
|
110
|
-
type DocumentLoader = (url: string, options?: DocumentLoaderOptions) => Promise<RemoteDocument>;
|
|
111
|
-
/**
|
|
112
|
-
* A factory function that creates a {@link DocumentLoader} with options.
|
|
113
|
-
* @param options The options for the document loader.
|
|
114
|
-
* @returns The document loader.
|
|
115
|
-
* @since 1.4.0
|
|
116
|
-
*/
|
|
117
|
-
type DocumentLoaderFactory = (options?: DocumentLoaderFactoryOptions) => DocumentLoader;
|
|
118
|
-
/**
|
|
119
|
-
* Options for {@link DocumentLoaderFactory}.
|
|
120
|
-
* @see {@link DocumentLoaderFactory}
|
|
121
|
-
* @see {@link AuthenticatedDocumentLoaderFactory}
|
|
122
|
-
* @since 1.4.0
|
|
123
|
-
*/
|
|
124
|
-
interface DocumentLoaderFactoryOptions {
|
|
125
|
-
/**
|
|
126
|
-
* Whether to allow fetching private network addresses.
|
|
127
|
-
* Turned off by default.
|
|
128
|
-
* @default `false``
|
|
129
|
-
*/
|
|
130
|
-
allowPrivateAddress?: boolean;
|
|
131
|
-
/**
|
|
132
|
-
* Options for making `User-Agent` string.
|
|
133
|
-
* If a string is given, it is used as the `User-Agent` header value.
|
|
134
|
-
* If an object is given, it is passed to {@link getUserAgent} function.
|
|
135
|
-
*/
|
|
136
|
-
userAgent?: GetUserAgentOptions | string;
|
|
137
|
-
/**
|
|
138
|
-
* The maximum number of redirections to follow.
|
|
139
|
-
* @default `20`
|
|
140
|
-
* @since 2.2.0
|
|
141
|
-
*/
|
|
142
|
-
maxRedirection?: number;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* A factory function that creates an authenticated {@link DocumentLoader} for
|
|
146
|
-
* a given identity. This is used for fetching documents that require
|
|
147
|
-
* authentication.
|
|
148
|
-
* @param identity The identity to create the document loader for.
|
|
149
|
-
* The actor's key pair.
|
|
150
|
-
* @param options The options for the document loader.
|
|
151
|
-
* @returns The authenticated document loader.
|
|
152
|
-
* @since 0.4.0
|
|
153
|
-
*/
|
|
154
|
-
type AuthenticatedDocumentLoaderFactory = (identity: {
|
|
155
|
-
keyId: URL;
|
|
156
|
-
privateKey: CryptoKey;
|
|
157
|
-
}, options?: DocumentLoaderFactoryOptions) => DocumentLoader;
|
|
158
|
-
/**
|
|
159
|
-
* Gets a {@link RemoteDocument} from the given response.
|
|
160
|
-
* @param url The URL of the document to load.
|
|
161
|
-
* @param response The response to get the document from.
|
|
162
|
-
* @param fetch The function to fetch the document.
|
|
163
|
-
* @returns The loaded remote document.
|
|
164
|
-
* @throws {FetchError} If the response is not OK.
|
|
165
|
-
* @internal
|
|
166
|
-
*/
|
|
167
|
-
declare function getRemoteDocument(url: string, response: Response, fetch: (url: string, options?: DocumentLoaderOptions) => Promise<RemoteDocument>): Promise<RemoteDocument>;
|
|
168
|
-
/**
|
|
169
|
-
* Options for {@link getDocumentLoader}.
|
|
170
|
-
* @since 1.3.0
|
|
171
|
-
*/
|
|
172
|
-
interface GetDocumentLoaderOptions extends DocumentLoaderFactoryOptions {
|
|
173
|
-
/**
|
|
174
|
-
* Whether to preload the frequently used contexts.
|
|
175
|
-
*/
|
|
176
|
-
skipPreloadedContexts?: boolean;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Creates a JSON-LD document loader that utilizes the browser's `fetch` API.
|
|
180
|
-
*
|
|
181
|
-
* The created loader preloads the below frequently used contexts by default
|
|
182
|
-
* (unless `options.skipPreloadedContexts` is set to `true`):
|
|
183
|
-
*
|
|
184
|
-
* - <https://www.w3.org/ns/activitystreams>
|
|
185
|
-
* - <https://w3id.org/security/v1>
|
|
186
|
-
* - <https://w3id.org/security/data-integrity/v1>
|
|
187
|
-
* - <https://www.w3.org/ns/did/v1>
|
|
188
|
-
* - <https://w3id.org/security/multikey/v1>
|
|
189
|
-
* - <https://purl.archive.org/socialweb/webfinger>
|
|
190
|
-
* - <http://schema.org/>
|
|
191
|
-
* @param options Options for the document loader.
|
|
192
|
-
* @returns The document loader.
|
|
193
|
-
* @since 1.3.0
|
|
194
|
-
*/
|
|
195
|
-
declare function getDocumentLoader({
|
|
196
|
-
allowPrivateAddress,
|
|
197
|
-
maxRedirection,
|
|
198
|
-
skipPreloadedContexts,
|
|
199
|
-
userAgent
|
|
200
|
-
}?: GetDocumentLoaderOptions): DocumentLoader;
|
|
201
|
-
//#endregion
|
|
202
|
-
export { DocumentLoaderOptions as a, getDocumentLoader as c, FetchError as d, GetUserAgentOptions as f, logRequest as h, DocumentLoaderFactoryOptions as i, getRemoteDocument as l, getUserAgent as m, DocumentLoader as n, GetDocumentLoaderOptions as o, createActivityPubRequest as p, DocumentLoaderFactory as r, RemoteDocument as s, AuthenticatedDocumentLoaderFactory as t, CreateRequestOptions as u };
|
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const require_url = require("../url-BAdyyqAa.cjs");
|
|
4
|
-
const require_jsonld = require("../jsonld.cjs");
|
|
5
|
-
//#region src/internal/jsonld-cache.ts
|
|
6
|
-
const noJsonLdContext = Symbol("noJsonLdContext");
|
|
7
|
-
/**
|
|
8
|
-
* Checks whether an IRI is trusted relative to another IRI.
|
|
9
|
-
*
|
|
10
|
-
* @internal Technically exported for generated vocabulary classes, but not
|
|
11
|
-
* part of the public API contract. This is not considered public API for
|
|
12
|
-
* Semantic Versioning decisions.
|
|
13
|
-
*/
|
|
14
|
-
function isTrustedIriOrigin(options, left, right) {
|
|
15
|
-
return options.crossOrigin === "trust" || left == null || right != null && require_url.haveSameIriOrigin(left, right);
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Normalizes portable IRIs in JSON-LD cache data.
|
|
19
|
-
*
|
|
20
|
-
* @internal Technically exported for generated vocabulary classes, but not
|
|
21
|
-
* part of the public API contract. This is not considered public API for
|
|
22
|
-
* Semantic Versioning decisions.
|
|
23
|
-
*/
|
|
24
|
-
function normalizeJsonLdIris(value, iriKeys, iriPattern = /^ap(?:\+ef61)?:\/\//i) {
|
|
25
|
-
return normalize(value, void 0, 0, void 0);
|
|
26
|
-
function isIriPosition(key, parentKey) {
|
|
27
|
-
return iriKeys.has(key) || (key === "@value" || key === "@list" || key === "@set") && parentKey != null && iriKeys.has(parentKey);
|
|
28
|
-
}
|
|
29
|
-
function arrayItemParentKey(key, parentKey) {
|
|
30
|
-
return key === "@list" || key === "@set" ? parentKey : key;
|
|
31
|
-
}
|
|
32
|
-
function entryParentKey(entryKey, key, parentKey) {
|
|
33
|
-
if (entryKey === "@list" || entryKey === "@set") return parentKey ?? key;
|
|
34
|
-
return key === "@list" || key === "@set" ? parentKey : key;
|
|
35
|
-
}
|
|
36
|
-
function normalize(value, key, depth = 0, parentKey) {
|
|
37
|
-
if (depth > 32 || key === "@context") return value;
|
|
38
|
-
if (typeof value === "string") {
|
|
39
|
-
if (key != null && isIriPosition(key, parentKey) && iriPattern.test(value)) try {
|
|
40
|
-
return require_url.formatIri(value);
|
|
41
|
-
} catch {
|
|
42
|
-
return value;
|
|
43
|
-
}
|
|
44
|
-
return value;
|
|
45
|
-
}
|
|
46
|
-
if (Array.isArray(value)) {
|
|
47
|
-
let clone;
|
|
48
|
-
const itemParentKey = arrayItemParentKey(key, parentKey);
|
|
49
|
-
for (let i = 0; i < value.length; i++) {
|
|
50
|
-
const result = normalize(value[i], key, depth + 1, itemParentKey);
|
|
51
|
-
if (result !== value[i]) {
|
|
52
|
-
clone ??= value.slice(0, i);
|
|
53
|
-
clone.push(result);
|
|
54
|
-
} else if (clone != null) clone.push(value[i]);
|
|
55
|
-
}
|
|
56
|
-
return clone ?? value;
|
|
57
|
-
}
|
|
58
|
-
if (value == null || typeof value !== "object") return value;
|
|
59
|
-
const object = value;
|
|
60
|
-
let clone;
|
|
61
|
-
for (const entryKey of globalThis.Object.keys(object)) {
|
|
62
|
-
const result = normalize(object[entryKey], entryKey, depth + 1, entryParentKey(entryKey, key, parentKey));
|
|
63
|
-
if (result !== object[entryKey]) {
|
|
64
|
-
clone ??= { ...object };
|
|
65
|
-
defineJsonLdProperty(clone, entryKey, result);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return clone ?? object;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Finds the first JSON-LD context in a value.
|
|
73
|
-
*
|
|
74
|
-
* @internal Technically exported for generated vocabulary classes, but not
|
|
75
|
-
* part of the public API contract. This is not considered public API for
|
|
76
|
-
* Semantic Versioning decisions.
|
|
77
|
-
*/
|
|
78
|
-
function getJsonLdContext(value, depth = 0) {
|
|
79
|
-
if (depth > 32) return void 0;
|
|
80
|
-
if (Array.isArray(value)) {
|
|
81
|
-
for (const item of value) {
|
|
82
|
-
const context = getJsonLdContext(item, depth + 1);
|
|
83
|
-
if (context !== void 0) return context;
|
|
84
|
-
}
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
if (value == null || typeof value !== "object" || !("@context" in value)) return;
|
|
88
|
-
return value["@context"];
|
|
89
|
-
}
|
|
90
|
-
function getOwnJsonLdContext(value) {
|
|
91
|
-
if (value == null || typeof value !== "object" || Array.isArray(value) || !("@context" in value)) return noJsonLdContext;
|
|
92
|
-
return value["@context"];
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Recompacts normalized JSON-LD cache data against the original context.
|
|
96
|
-
*
|
|
97
|
-
* @internal Technically exported for generated vocabulary classes, but not
|
|
98
|
-
* part of the public API contract. This is not considered public API for
|
|
99
|
-
* Semantic Versioning decisions.
|
|
100
|
-
*/
|
|
101
|
-
async function compactJsonLdCache(normalized, original, documentLoader, depth = 0, inheritedContext) {
|
|
102
|
-
if (depth > 32) return normalized;
|
|
103
|
-
if (Array.isArray(original)) {
|
|
104
|
-
const normalizedArray = Array.isArray(normalized) ? normalized : normalized != null && typeof normalized === "object" && "@graph" in normalized && Array.isArray(normalized["@graph"]) ? normalized["@graph"] : void 0;
|
|
105
|
-
if (normalizedArray == null) return normalized;
|
|
106
|
-
let clone;
|
|
107
|
-
for (let i = 0; i < normalizedArray.length; i++) {
|
|
108
|
-
const item = await compactJsonLdCache(normalizedArray[i], original[i], documentLoader, depth + 1, inheritedContext);
|
|
109
|
-
if (item !== normalizedArray[i]) {
|
|
110
|
-
clone ??= normalizedArray.slice(0, i);
|
|
111
|
-
clone.push(item);
|
|
112
|
-
} else if (clone != null) clone.push(normalizedArray[i]);
|
|
113
|
-
}
|
|
114
|
-
return clone ?? (Array.isArray(normalized) ? normalized : normalizedArray);
|
|
115
|
-
}
|
|
116
|
-
const ownContext = getOwnJsonLdContext(original);
|
|
117
|
-
const context = ownContext === noJsonLdContext ? inheritedContext : ownContext;
|
|
118
|
-
if (context == null) return preserveNoContextJsonLdShape(normalized, original, depth);
|
|
119
|
-
return await preserveJsonLdShape(await mergeUnmappedTerms(await require_jsonld.compact(Array.isArray(normalized) && normalized.length === 1 ? normalized[0] : normalized, context, { documentLoader }), original, context, documentLoader), original, context, documentLoader, depth);
|
|
120
|
-
}
|
|
121
|
-
function preserveNoContextJsonLdShape(normalized, original, depth = 0) {
|
|
122
|
-
if (depth > 32) return normalized;
|
|
123
|
-
if (original == null || typeof original !== "object" || Array.isArray(original)) return normalized;
|
|
124
|
-
const normalizedObject = Array.isArray(normalized) && normalized.length === 1 ? normalized[0] : normalized;
|
|
125
|
-
if (normalizedObject == null || typeof normalizedObject !== "object" || Array.isArray(normalizedObject)) return normalized;
|
|
126
|
-
const source = normalizedObject;
|
|
127
|
-
const originalObject = original;
|
|
128
|
-
let clone;
|
|
129
|
-
for (const key of globalThis.Object.keys(originalObject)) {
|
|
130
|
-
if (!globalThis.Object.prototype.hasOwnProperty.call(source, key)) continue;
|
|
131
|
-
const value = preserveNoContextValue(source[key], originalObject[key], depth + 1);
|
|
132
|
-
if (value !== originalObject[key]) {
|
|
133
|
-
clone ??= { ...originalObject };
|
|
134
|
-
defineJsonLdProperty(clone, key, value);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return clone ?? original;
|
|
138
|
-
}
|
|
139
|
-
function preserveNoContextValue(normalized, original, depth) {
|
|
140
|
-
if (depth > 32) return normalized;
|
|
141
|
-
if (Array.isArray(original)) {
|
|
142
|
-
const normalizedArray = Array.isArray(normalized) ? normalized : [normalized];
|
|
143
|
-
let clone;
|
|
144
|
-
for (let i = 0; i < original.length; i++) {
|
|
145
|
-
const value = preserveNoContextValue(normalizedArray[i], original[i], depth + 1);
|
|
146
|
-
if (value !== original[i]) {
|
|
147
|
-
clone ??= original.slice(0, i);
|
|
148
|
-
clone.push(value);
|
|
149
|
-
} else if (clone != null) clone.push(original[i]);
|
|
150
|
-
}
|
|
151
|
-
return clone ?? original;
|
|
152
|
-
}
|
|
153
|
-
const normalizedValue = Array.isArray(normalized) ? normalized[0] : normalized;
|
|
154
|
-
if (normalizedValue == null || typeof normalizedValue !== "object" || Array.isArray(normalizedValue)) return normalizedValue;
|
|
155
|
-
const normalizedObject = normalizedValue;
|
|
156
|
-
if (original != null && typeof original === "object" && !Array.isArray(original)) return preserveNoContextJsonLdShape(normalizedObject, original, depth + 1);
|
|
157
|
-
if (typeof normalizedObject["@id"] === "string") return normalizedObject["@id"];
|
|
158
|
-
if ("@value" in normalizedObject) return normalizedObject["@value"];
|
|
159
|
-
return normalizedValue;
|
|
160
|
-
}
|
|
161
|
-
function getTopLevelTerms(value) {
|
|
162
|
-
const terms = /* @__PURE__ */ new Set();
|
|
163
|
-
const nodes = Array.isArray(value) ? value : [value];
|
|
164
|
-
for (const node of nodes) {
|
|
165
|
-
if (node == null || typeof node !== "object" || Array.isArray(node)) continue;
|
|
166
|
-
for (const key of globalThis.Object.keys(node)) {
|
|
167
|
-
if (key.startsWith("@")) continue;
|
|
168
|
-
terms.add(key);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
return terms;
|
|
172
|
-
}
|
|
173
|
-
async function mergeUnmappedTerms(compacted, original, context, documentLoader) {
|
|
174
|
-
if (original == null || typeof original !== "object" || Array.isArray(original) || compacted == null || typeof compacted !== "object" || Array.isArray(compacted)) return compacted;
|
|
175
|
-
const unmappedKeys = globalThis.Object.keys(original).filter((key) => key !== "@context" && !globalThis.Object.prototype.hasOwnProperty.call(compacted, key));
|
|
176
|
-
if (unmappedKeys.length < 1) return compacted;
|
|
177
|
-
const result = { ...compacted };
|
|
178
|
-
const compactedWithContext = compacted != null && typeof compacted === "object" && !Array.isArray(compacted) && !("@context" in compacted) ? {
|
|
179
|
-
"@context": context,
|
|
180
|
-
...compacted
|
|
181
|
-
} : compacted;
|
|
182
|
-
const compactedTerms = getTopLevelTerms(await require_jsonld.expand(compactedWithContext, { documentLoader }));
|
|
183
|
-
const dummyPrefix = "urn:fedify:dummy:";
|
|
184
|
-
const dummy = { "@context": context };
|
|
185
|
-
for (let i = 0; i < unmappedKeys.length; i++) defineJsonLdProperty(dummy, unmappedKeys[i], `${dummyPrefix}${i}`);
|
|
186
|
-
const expanded = await require_jsonld.expand(dummy, { documentLoader });
|
|
187
|
-
const representedKeys = /* @__PURE__ */ new Set();
|
|
188
|
-
const nodes = Array.isArray(expanded) ? expanded : [expanded];
|
|
189
|
-
for (const node of nodes) {
|
|
190
|
-
if (node == null || typeof node !== "object" || Array.isArray(node)) continue;
|
|
191
|
-
for (const [term, termValue] of globalThis.Object.entries(node)) {
|
|
192
|
-
if (!compactedTerms.has(term)) continue;
|
|
193
|
-
for (let i = 0; i < unmappedKeys.length; i++) if (containsValue(termValue, `${dummyPrefix}${i}`)) representedKeys.add(unmappedKeys[i]);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
for (const key of unmappedKeys) if (!representedKeys.has(key)) defineJsonLdProperty(result, key, original[key]);
|
|
197
|
-
return result;
|
|
198
|
-
}
|
|
199
|
-
function defineJsonLdProperty(object, key, value) {
|
|
200
|
-
globalThis.Object.defineProperty(object, key, {
|
|
201
|
-
value,
|
|
202
|
-
enumerable: true,
|
|
203
|
-
configurable: true,
|
|
204
|
-
writable: true
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
function containsValue(value, expected, depth = 0) {
|
|
208
|
-
if (depth > 32) return false;
|
|
209
|
-
if (value === expected) return true;
|
|
210
|
-
if (Array.isArray(value)) return value.some((item) => containsValue(item, expected, depth + 1));
|
|
211
|
-
if (value == null || typeof value !== "object") return false;
|
|
212
|
-
return globalThis.Object.entries(value).some(([key, item]) => key !== "@context" && containsValue(item, expected, depth + 1));
|
|
213
|
-
}
|
|
214
|
-
async function preserveJsonLdShape(compacted, original, context, documentLoader, depth = 0) {
|
|
215
|
-
if (depth > 32) return compacted;
|
|
216
|
-
if (compacted === original) return compacted;
|
|
217
|
-
if (original == null || typeof original !== "object" || compacted == null || typeof compacted !== "object") return compacted;
|
|
218
|
-
if (Array.isArray(original)) {
|
|
219
|
-
const compactedArray = Array.isArray(compacted) ? compacted : "@graph" in compacted && Array.isArray(compacted["@graph"]) ? compacted["@graph"] : void 0;
|
|
220
|
-
if (compactedArray == null) return compacted;
|
|
221
|
-
let clone;
|
|
222
|
-
for (let i = 0; i < compactedArray.length; i++) {
|
|
223
|
-
const value = await preserveJsonLdShape(compactedArray[i], original[i], context, documentLoader, depth + 1);
|
|
224
|
-
const originalContext = original[i] != null && typeof original[i] === "object" && !Array.isArray(original[i]) && "@context" in original[i] ? original[i]["@context"] : void 0;
|
|
225
|
-
const shaped = originalContext !== void 0 && value != null && typeof value === "object" && !Array.isArray(value) && !("@context" in value) ? {
|
|
226
|
-
"@context": originalContext,
|
|
227
|
-
...value
|
|
228
|
-
} : value;
|
|
229
|
-
if (shaped !== compactedArray[i]) {
|
|
230
|
-
clone ??= compactedArray.slice(0, i);
|
|
231
|
-
clone.push(shaped);
|
|
232
|
-
} else if (clone != null) clone.push(compactedArray[i]);
|
|
233
|
-
}
|
|
234
|
-
return clone ?? (Array.isArray(compacted) ? compacted : compactedArray);
|
|
235
|
-
}
|
|
236
|
-
if (Array.isArray(compacted)) return compacted;
|
|
237
|
-
let clone;
|
|
238
|
-
const ownContext = getOwnJsonLdContext(original);
|
|
239
|
-
const objectContext = combineContexts(context, ownContext);
|
|
240
|
-
const objectCompacted = depth > 0 && ownContext === null ? await compactWithEmptyContext(compacted, context, documentLoader) : compacted;
|
|
241
|
-
const compactedObject = depth > 0 ? await mergeUnmappedTerms(objectCompacted, original, objectContext, documentLoader) : objectCompacted;
|
|
242
|
-
const originalObject = original;
|
|
243
|
-
for (const key of globalThis.Object.keys(compactedObject)) {
|
|
244
|
-
if (key === "@context") continue;
|
|
245
|
-
const value = await preserveJsonLdShape(compactedObject[key], originalObject[key], objectContext, documentLoader, depth + 1);
|
|
246
|
-
const shaped = Array.isArray(originalObject[key]) && !Array.isArray(value) ? [value] : value;
|
|
247
|
-
if (shaped !== compactedObject[key]) {
|
|
248
|
-
clone ??= { ...compactedObject };
|
|
249
|
-
defineJsonLdProperty(clone, key, shaped);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
if (depth > 0) {
|
|
253
|
-
if ("@context" in originalObject && !("@context" in compactedObject)) {
|
|
254
|
-
clone ??= { ...compactedObject };
|
|
255
|
-
clone["@context"] = originalObject["@context"];
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
return clone ?? compactedObject;
|
|
259
|
-
}
|
|
260
|
-
async function compactWithEmptyContext(compacted, context, documentLoader) {
|
|
261
|
-
const compactedWithContext = compacted != null && typeof compacted === "object" && !Array.isArray(compacted) && !("@context" in compacted) ? {
|
|
262
|
-
"@context": context,
|
|
263
|
-
...compacted
|
|
264
|
-
} : compacted;
|
|
265
|
-
const expanded = await require_jsonld.expand(compactedWithContext, { documentLoader });
|
|
266
|
-
return await require_jsonld.compact(expanded, {}, { documentLoader });
|
|
267
|
-
}
|
|
268
|
-
function combineContexts(inheritedContext, ownContext) {
|
|
269
|
-
if (ownContext === noJsonLdContext || ownContext === inheritedContext) return inheritedContext;
|
|
270
|
-
if (ownContext == null) return ownContext;
|
|
271
|
-
const inherited = Array.isArray(inheritedContext) ? inheritedContext : [inheritedContext];
|
|
272
|
-
const own = Array.isArray(ownContext) ? ownContext : [ownContext];
|
|
273
|
-
return [...inherited, ...own];
|
|
274
|
-
}
|
|
275
|
-
//#endregion
|
|
276
|
-
exports.compactJsonLdCache = compactJsonLdCache;
|
|
277
|
-
exports.getJsonLdContext = getJsonLdContext;
|
|
278
|
-
exports.isTrustedIriOrigin = isTrustedIriOrigin;
|
|
279
|
-
exports.normalizeJsonLdIris = normalizeJsonLdIris;
|
|
@@ -1,48 +0,0 @@
|
|
|
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 };
|
|
@@ -1,48 +0,0 @@
|
|
|
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 };
|