@fedify/vocab-tools 2.4.0-dev.2122 → 2.4.0-dev.2129
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 -1
- package/dist/mod.cjs +63 -7
- package/dist/mod.js +63 -7
- package/package.json +1 -1
- package/src/__snapshots__/class.test.ts.deno.snap +6911 -964
- package/src/__snapshots__/class.test.ts.node.snap +6911 -964
- package/src/__snapshots__/class.test.ts.snap +6911 -964
- package/src/class.ts +6 -0
- package/src/codec.ts +7 -0
- package/src/constructor.ts +3 -0
- package/src/property.ts +46 -6
package/deno.json
CHANGED
package/dist/mod.cjs
CHANGED
|
@@ -8,7 +8,7 @@ let yaml = require("yaml");
|
|
|
8
8
|
let es_toolkit = require("es-toolkit");
|
|
9
9
|
//#region deno.json
|
|
10
10
|
var name = "@fedify/vocab-tools";
|
|
11
|
-
var version = "2.4.0-dev.
|
|
11
|
+
var version = "2.4.0-dev.2129+c0ddb433";
|
|
12
12
|
//#endregion
|
|
13
13
|
//#region src/type.ts
|
|
14
14
|
const HEURISTICS_CONTEXTS = [
|
|
@@ -737,6 +737,7 @@ function* generatePreprocessorBlock(property, rangeTypeName, variable, baseUrlEx
|
|
|
737
737
|
documentLoader: options.documentLoader,
|
|
738
738
|
contextLoader: options.contextLoader,
|
|
739
739
|
tracerProvider: options.tracerProvider,
|
|
740
|
+
verifyPortableObject: options.verifyPortableObject,
|
|
740
741
|
baseUrl: ${baseUrlExpr},
|
|
741
742
|
});
|
|
742
743
|
if (_result instanceof Error) throw _result;
|
|
@@ -1005,6 +1006,10 @@ async function* generateDecoder(typeUri, types, moduleVarNames) {
|
|
|
1005
1006
|
* - \`contextLoader\`: The loader for remote JSON-LD contexts.
|
|
1006
1007
|
* - \`tracerProvider\`: The OpenTelemetry tracer provider to use.
|
|
1007
1008
|
* If omitted, the global tracer provider is used.
|
|
1009
|
+
* - \`verifyPortableObject\`: The default FEP-ef61 portable
|
|
1010
|
+
* object verifier for the property accessors of the
|
|
1011
|
+
* returned object and the objects obtained from it. It
|
|
1012
|
+
* does not verify the given \`json\` itself.
|
|
1008
1013
|
* @returns The object of this type.
|
|
1009
1014
|
* @throws {TypeError} If the given \`json\` is invalid.
|
|
1010
1015
|
*/
|
|
@@ -1014,6 +1019,7 @@ async function* generateDecoder(typeUri, types, moduleVarNames) {
|
|
|
1014
1019
|
documentLoader?: DocumentLoader,
|
|
1015
1020
|
contextLoader?: DocumentLoader,
|
|
1016
1021
|
tracerProvider?: TracerProvider,
|
|
1022
|
+
verifyPortableObject?: PortableObjectVerifier,
|
|
1017
1023
|
baseUrl?: URL,
|
|
1018
1024
|
} = {},
|
|
1019
1025
|
): Promise<${type.name}> {
|
|
@@ -1052,6 +1058,7 @@ async function* generateDecoder(typeUri, types, moduleVarNames) {
|
|
|
1052
1058
|
documentLoader?: DocumentLoader,
|
|
1053
1059
|
contextLoader?: DocumentLoader,
|
|
1054
1060
|
tracerProvider?: TracerProvider,
|
|
1061
|
+
verifyPortableObject?: PortableObjectVerifier,
|
|
1055
1062
|
baseUrl?: URL,
|
|
1056
1063
|
} = {},
|
|
1057
1064
|
): Promise<${type.name}> {
|
|
@@ -1287,6 +1294,7 @@ async function* generateConstructor(typeUri, types) {
|
|
|
1287
1294
|
documentLoader?: DocumentLoader,
|
|
1288
1295
|
contextLoader?: DocumentLoader,
|
|
1289
1296
|
tracerProvider?: TracerProvider,
|
|
1297
|
+
verifyPortableObject?: PortableObjectVerifier,
|
|
1290
1298
|
} = {},
|
|
1291
1299
|
) {
|
|
1292
1300
|
`;
|
|
@@ -1294,6 +1302,7 @@ async function* generateConstructor(typeUri, types) {
|
|
|
1294
1302
|
this.#documentLoader = options.documentLoader;
|
|
1295
1303
|
this.#contextLoader = options.contextLoader;
|
|
1296
1304
|
this.#tracerProvider = options.tracerProvider;
|
|
1305
|
+
this.#verifyPortableObject = options.verifyPortableObject;
|
|
1297
1306
|
const baseUrl = (options as { baseUrl?: URL }).baseUrl;
|
|
1298
1307
|
this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href);
|
|
1299
1308
|
if ("$warning" in options) {
|
|
@@ -1408,6 +1417,7 @@ async function* generateCloner(typeUri, types) {
|
|
|
1408
1417
|
options: {
|
|
1409
1418
|
documentLoader?: DocumentLoader,
|
|
1410
1419
|
contextLoader?: DocumentLoader,
|
|
1420
|
+
verifyPortableObject?: PortableObjectVerifier,
|
|
1411
1421
|
} = {}
|
|
1412
1422
|
): ${type.name} {
|
|
1413
1423
|
if (this._warning != null) {
|
|
@@ -1702,6 +1712,9 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1702
1712
|
documentLoader,
|
|
1703
1713
|
contextLoader: parseOptions.contextLoader,
|
|
1704
1714
|
tracerProvider,
|
|
1715
|
+
// Only the parent's own default is inherited, never the
|
|
1716
|
+
// verifier given to this call:
|
|
1717
|
+
verifyPortableObject: this._verifyPortableObject,
|
|
1705
1718
|
baseUrl: parseOptions.baseUrl,
|
|
1706
1719
|
}),
|
|
1707
1720
|
});
|
|
@@ -1743,7 +1756,9 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1743
1756
|
}
|
|
1744
1757
|
let fetchResult: RemoteDocument;
|
|
1745
1758
|
try {
|
|
1746
|
-
fetchResult = await documentLoader(lookupUrl
|
|
1759
|
+
fetchResult = await documentLoader(lookupUrl, {
|
|
1760
|
+
suppressError: options.suppressError,
|
|
1761
|
+
});
|
|
1747
1762
|
} catch (error) {
|
|
1748
1763
|
span.setStatus({
|
|
1749
1764
|
code: SpanStatusCode.ERROR,
|
|
@@ -1751,7 +1766,7 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1751
1766
|
});
|
|
1752
1767
|
span.end();
|
|
1753
1768
|
if (options.suppressError) {
|
|
1754
|
-
getLogger(["fedify", "vocab"]).
|
|
1769
|
+
getLogger(["fedify", "vocab"]).warn(
|
|
1755
1770
|
"Failed to fetch {url}: {error}",
|
|
1756
1771
|
{ error, url: lookupUrl }
|
|
1757
1772
|
);
|
|
@@ -1763,8 +1778,12 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1763
1778
|
// In portable mode, the document may turn out to be a portable object,
|
|
1764
1779
|
// which has to be verified with the same context documents:
|
|
1765
1780
|
const snapshot = portableMode
|
|
1766
|
-
? createSnapshotContextLoader(contextLoader)
|
|
1781
|
+
? createSnapshotContextLoader(contextLoader, options.suppressError)
|
|
1767
1782
|
: null;
|
|
1783
|
+
const scopedContext = createScopedContextLoader(
|
|
1784
|
+
snapshot?.loader ?? contextLoader,
|
|
1785
|
+
snapshot == null && options.suppressError,
|
|
1786
|
+
);
|
|
1768
1787
|
try {
|
|
1769
1788
|
let claim: PortableResponseClaim | null | undefined;
|
|
1770
1789
|
try {
|
|
@@ -1773,8 +1792,9 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1773
1792
|
document,
|
|
1774
1793
|
{
|
|
1775
1794
|
documentLoader,
|
|
1776
|
-
contextLoader:
|
|
1795
|
+
contextLoader: scopedContext.loader,
|
|
1777
1796
|
tracerProvider,
|
|
1797
|
+
verifyPortableObject: this._verifyPortableObject,
|
|
1778
1798
|
baseUrl,
|
|
1779
1799
|
}
|
|
1780
1800
|
);
|
|
@@ -1817,7 +1837,7 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1817
1837
|
}
|
|
1818
1838
|
} catch (e) {
|
|
1819
1839
|
if (options.suppressError) {
|
|
1820
|
-
getLogger(["fedify", "vocab"]).
|
|
1840
|
+
getLogger(["fedify", "vocab"]).warn(
|
|
1821
1841
|
"Failed to parse {url}: {error}",
|
|
1822
1842
|
{ error: e, url: lookupUrl }
|
|
1823
1843
|
);
|
|
@@ -1843,6 +1863,7 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1843
1863
|
contextLoader: snapshot?.loader,
|
|
1844
1864
|
});
|
|
1845
1865
|
} finally {
|
|
1866
|
+
scopedContext.release();
|
|
1846
1867
|
snapshot?.release();
|
|
1847
1868
|
}
|
|
1848
1869
|
});
|
|
@@ -1854,6 +1875,7 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1854
1875
|
documentLoader?: DocumentLoader,
|
|
1855
1876
|
contextLoader?: DocumentLoader,
|
|
1856
1877
|
tracerProvider?: TracerProvider,
|
|
1878
|
+
verifyPortableObject?: PortableObjectVerifier,
|
|
1857
1879
|
baseUrl?: URL
|
|
1858
1880
|
}
|
|
1859
1881
|
): Promise<${getTypeNames(property.range, types)}> {
|
|
@@ -1864,6 +1886,7 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1864
1886
|
const tracerProvider = options.tracerProvider ??
|
|
1865
1887
|
this._tracerProvider ?? trace.getTracerProvider();
|
|
1866
1888
|
const baseUrl = options.baseUrl;
|
|
1889
|
+
const verifyPortableObject = options.verifyPortableObject;
|
|
1867
1890
|
`;
|
|
1868
1891
|
if (property.preprocessors != null && property.preprocessors.length > 0) {
|
|
1869
1892
|
yield `
|
|
@@ -1883,6 +1906,7 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1883
1906
|
documentLoader,
|
|
1884
1907
|
contextLoader,
|
|
1885
1908
|
tracerProvider,
|
|
1909
|
+
verifyPortableObject,
|
|
1886
1910
|
baseUrl,
|
|
1887
1911
|
});
|
|
1888
1912
|
if (_result instanceof Error) throw _result;
|
|
@@ -1901,7 +1925,13 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1901
1925
|
try {
|
|
1902
1926
|
return await ${types[range].name}.fromJsonLd(
|
|
1903
1927
|
jsonLd,
|
|
1904
|
-
{
|
|
1928
|
+
{
|
|
1929
|
+
documentLoader,
|
|
1930
|
+
contextLoader,
|
|
1931
|
+
tracerProvider,
|
|
1932
|
+
verifyPortableObject,
|
|
1933
|
+
baseUrl,
|
|
1934
|
+
},
|
|
1905
1935
|
);
|
|
1906
1936
|
} catch (e) {
|
|
1907
1937
|
if (!(e instanceof TypeError)) throw e;
|
|
@@ -1954,6 +1984,15 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1954
1984
|
);
|
|
1955
1985
|
}
|
|
1956
1986
|
if (this.${await getFieldName(property.uri)}.length < 1) return null;
|
|
1987
|
+
if (
|
|
1988
|
+
options.verifyPortableObject == null &&
|
|
1989
|
+
this._verifyPortableObject != null
|
|
1990
|
+
) {
|
|
1991
|
+
options = {
|
|
1992
|
+
...options,
|
|
1993
|
+
verifyPortableObject: this._verifyPortableObject,
|
|
1994
|
+
};
|
|
1995
|
+
}
|
|
1957
1996
|
let v = this.${await getFieldName(property.uri)}[0];
|
|
1958
1997
|
if (!(v instanceof URL) &&
|
|
1959
1998
|
!this.${await getFieldName(property.uri, "#_trust")}.has(0)) {
|
|
@@ -2000,6 +2039,7 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
2000
2039
|
yield `
|
|
2001
2040
|
v = await this.#${property.singularName}_fromJsonLd(doc, {
|
|
2002
2041
|
...options,
|
|
2042
|
+
verifyPortableObject: this._verifyPortableObject,
|
|
2003
2043
|
baseUrl: ${cachedPropertyBaseUrl},
|
|
2004
2044
|
});
|
|
2005
2045
|
`;
|
|
@@ -2078,6 +2118,15 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
2078
2118
|
this._warning.values
|
|
2079
2119
|
);
|
|
2080
2120
|
}
|
|
2121
|
+
if (
|
|
2122
|
+
options.verifyPortableObject == null &&
|
|
2123
|
+
this._verifyPortableObject != null
|
|
2124
|
+
) {
|
|
2125
|
+
options = {
|
|
2126
|
+
...options,
|
|
2127
|
+
verifyPortableObject: this._verifyPortableObject,
|
|
2128
|
+
};
|
|
2129
|
+
}
|
|
2081
2130
|
const vs = this.${await getFieldName(property.uri)};
|
|
2082
2131
|
for (let i = 0; i < vs.length; i++) {
|
|
2083
2132
|
let v = vs[i];
|
|
@@ -2130,6 +2179,7 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
2130
2179
|
yield `
|
|
2131
2180
|
v = await this.#${property.singularName}_fromJsonLd(obj, {
|
|
2132
2181
|
...options,
|
|
2182
|
+
verifyPortableObject: this._verifyPortableObject,
|
|
2133
2183
|
baseUrl: ${cachedPropertyBaseUrl},
|
|
2134
2184
|
});
|
|
2135
2185
|
`;
|
|
@@ -2183,6 +2233,7 @@ const XSD_ANY_URI = "http://www.w3.org/2001/XMLSchema#anyURI";
|
|
|
2183
2233
|
const FEDIFY_URL = "fedify:url";
|
|
2184
2234
|
const INTERNAL_RUNTIME_IMPORTS = [
|
|
2185
2235
|
"compactJsonLdCache",
|
|
2236
|
+
"createScopedContextLoader",
|
|
2186
2237
|
"getJsonLdContext",
|
|
2187
2238
|
"isTrustedIriOrigin",
|
|
2188
2239
|
"normalizeJsonLdIris"
|
|
@@ -2264,6 +2315,7 @@ async function* generateClass(typeUri, types, moduleVarNames) {
|
|
|
2264
2315
|
readonly #documentLoader?: DocumentLoader;
|
|
2265
2316
|
readonly #contextLoader?: DocumentLoader;
|
|
2266
2317
|
readonly #tracerProvider?: TracerProvider;
|
|
2318
|
+
readonly #verifyPortableObject?: PortableObjectVerifier;
|
|
2267
2319
|
readonly #warning?: {
|
|
2268
2320
|
category: string[];
|
|
2269
2321
|
message: string;
|
|
@@ -2286,6 +2338,10 @@ async function* generateClass(typeUri, types, moduleVarNames) {
|
|
|
2286
2338
|
return this.#tracerProvider;
|
|
2287
2339
|
}
|
|
2288
2340
|
|
|
2341
|
+
protected get _verifyPortableObject(): PortableObjectVerifier | undefined {
|
|
2342
|
+
return this.#verifyPortableObject;
|
|
2343
|
+
}
|
|
2344
|
+
|
|
2289
2345
|
protected get _warning(): {
|
|
2290
2346
|
category: string[];
|
|
2291
2347
|
message: string;
|
package/dist/mod.js
CHANGED
|
@@ -7,7 +7,7 @@ import { parse } from "yaml";
|
|
|
7
7
|
import { pascalCase } from "es-toolkit";
|
|
8
8
|
//#region deno.json
|
|
9
9
|
var name = "@fedify/vocab-tools";
|
|
10
|
-
var version = "2.4.0-dev.
|
|
10
|
+
var version = "2.4.0-dev.2129+c0ddb433";
|
|
11
11
|
//#endregion
|
|
12
12
|
//#region src/type.ts
|
|
13
13
|
const HEURISTICS_CONTEXTS = [
|
|
@@ -736,6 +736,7 @@ function* generatePreprocessorBlock(property, rangeTypeName, variable, baseUrlEx
|
|
|
736
736
|
documentLoader: options.documentLoader,
|
|
737
737
|
contextLoader: options.contextLoader,
|
|
738
738
|
tracerProvider: options.tracerProvider,
|
|
739
|
+
verifyPortableObject: options.verifyPortableObject,
|
|
739
740
|
baseUrl: ${baseUrlExpr},
|
|
740
741
|
});
|
|
741
742
|
if (_result instanceof Error) throw _result;
|
|
@@ -1004,6 +1005,10 @@ async function* generateDecoder(typeUri, types, moduleVarNames) {
|
|
|
1004
1005
|
* - \`contextLoader\`: The loader for remote JSON-LD contexts.
|
|
1005
1006
|
* - \`tracerProvider\`: The OpenTelemetry tracer provider to use.
|
|
1006
1007
|
* If omitted, the global tracer provider is used.
|
|
1008
|
+
* - \`verifyPortableObject\`: The default FEP-ef61 portable
|
|
1009
|
+
* object verifier for the property accessors of the
|
|
1010
|
+
* returned object and the objects obtained from it. It
|
|
1011
|
+
* does not verify the given \`json\` itself.
|
|
1007
1012
|
* @returns The object of this type.
|
|
1008
1013
|
* @throws {TypeError} If the given \`json\` is invalid.
|
|
1009
1014
|
*/
|
|
@@ -1013,6 +1018,7 @@ async function* generateDecoder(typeUri, types, moduleVarNames) {
|
|
|
1013
1018
|
documentLoader?: DocumentLoader,
|
|
1014
1019
|
contextLoader?: DocumentLoader,
|
|
1015
1020
|
tracerProvider?: TracerProvider,
|
|
1021
|
+
verifyPortableObject?: PortableObjectVerifier,
|
|
1016
1022
|
baseUrl?: URL,
|
|
1017
1023
|
} = {},
|
|
1018
1024
|
): Promise<${type.name}> {
|
|
@@ -1051,6 +1057,7 @@ async function* generateDecoder(typeUri, types, moduleVarNames) {
|
|
|
1051
1057
|
documentLoader?: DocumentLoader,
|
|
1052
1058
|
contextLoader?: DocumentLoader,
|
|
1053
1059
|
tracerProvider?: TracerProvider,
|
|
1060
|
+
verifyPortableObject?: PortableObjectVerifier,
|
|
1054
1061
|
baseUrl?: URL,
|
|
1055
1062
|
} = {},
|
|
1056
1063
|
): Promise<${type.name}> {
|
|
@@ -1286,6 +1293,7 @@ async function* generateConstructor(typeUri, types) {
|
|
|
1286
1293
|
documentLoader?: DocumentLoader,
|
|
1287
1294
|
contextLoader?: DocumentLoader,
|
|
1288
1295
|
tracerProvider?: TracerProvider,
|
|
1296
|
+
verifyPortableObject?: PortableObjectVerifier,
|
|
1289
1297
|
} = {},
|
|
1290
1298
|
) {
|
|
1291
1299
|
`;
|
|
@@ -1293,6 +1301,7 @@ async function* generateConstructor(typeUri, types) {
|
|
|
1293
1301
|
this.#documentLoader = options.documentLoader;
|
|
1294
1302
|
this.#contextLoader = options.contextLoader;
|
|
1295
1303
|
this.#tracerProvider = options.tracerProvider;
|
|
1304
|
+
this.#verifyPortableObject = options.verifyPortableObject;
|
|
1296
1305
|
const baseUrl = (options as { baseUrl?: URL }).baseUrl;
|
|
1297
1306
|
this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href);
|
|
1298
1307
|
if ("$warning" in options) {
|
|
@@ -1407,6 +1416,7 @@ async function* generateCloner(typeUri, types) {
|
|
|
1407
1416
|
options: {
|
|
1408
1417
|
documentLoader?: DocumentLoader,
|
|
1409
1418
|
contextLoader?: DocumentLoader,
|
|
1419
|
+
verifyPortableObject?: PortableObjectVerifier,
|
|
1410
1420
|
} = {}
|
|
1411
1421
|
): ${type.name} {
|
|
1412
1422
|
if (this._warning != null) {
|
|
@@ -1701,6 +1711,9 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1701
1711
|
documentLoader,
|
|
1702
1712
|
contextLoader: parseOptions.contextLoader,
|
|
1703
1713
|
tracerProvider,
|
|
1714
|
+
// Only the parent's own default is inherited, never the
|
|
1715
|
+
// verifier given to this call:
|
|
1716
|
+
verifyPortableObject: this._verifyPortableObject,
|
|
1704
1717
|
baseUrl: parseOptions.baseUrl,
|
|
1705
1718
|
}),
|
|
1706
1719
|
});
|
|
@@ -1742,7 +1755,9 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1742
1755
|
}
|
|
1743
1756
|
let fetchResult: RemoteDocument;
|
|
1744
1757
|
try {
|
|
1745
|
-
fetchResult = await documentLoader(lookupUrl
|
|
1758
|
+
fetchResult = await documentLoader(lookupUrl, {
|
|
1759
|
+
suppressError: options.suppressError,
|
|
1760
|
+
});
|
|
1746
1761
|
} catch (error) {
|
|
1747
1762
|
span.setStatus({
|
|
1748
1763
|
code: SpanStatusCode.ERROR,
|
|
@@ -1750,7 +1765,7 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1750
1765
|
});
|
|
1751
1766
|
span.end();
|
|
1752
1767
|
if (options.suppressError) {
|
|
1753
|
-
getLogger(["fedify", "vocab"]).
|
|
1768
|
+
getLogger(["fedify", "vocab"]).warn(
|
|
1754
1769
|
"Failed to fetch {url}: {error}",
|
|
1755
1770
|
{ error, url: lookupUrl }
|
|
1756
1771
|
);
|
|
@@ -1762,8 +1777,12 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1762
1777
|
// In portable mode, the document may turn out to be a portable object,
|
|
1763
1778
|
// which has to be verified with the same context documents:
|
|
1764
1779
|
const snapshot = portableMode
|
|
1765
|
-
? createSnapshotContextLoader(contextLoader)
|
|
1780
|
+
? createSnapshotContextLoader(contextLoader, options.suppressError)
|
|
1766
1781
|
: null;
|
|
1782
|
+
const scopedContext = createScopedContextLoader(
|
|
1783
|
+
snapshot?.loader ?? contextLoader,
|
|
1784
|
+
snapshot == null && options.suppressError,
|
|
1785
|
+
);
|
|
1767
1786
|
try {
|
|
1768
1787
|
let claim: PortableResponseClaim | null | undefined;
|
|
1769
1788
|
try {
|
|
@@ -1772,8 +1791,9 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1772
1791
|
document,
|
|
1773
1792
|
{
|
|
1774
1793
|
documentLoader,
|
|
1775
|
-
contextLoader:
|
|
1794
|
+
contextLoader: scopedContext.loader,
|
|
1776
1795
|
tracerProvider,
|
|
1796
|
+
verifyPortableObject: this._verifyPortableObject,
|
|
1777
1797
|
baseUrl,
|
|
1778
1798
|
}
|
|
1779
1799
|
);
|
|
@@ -1816,7 +1836,7 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1816
1836
|
}
|
|
1817
1837
|
} catch (e) {
|
|
1818
1838
|
if (options.suppressError) {
|
|
1819
|
-
getLogger(["fedify", "vocab"]).
|
|
1839
|
+
getLogger(["fedify", "vocab"]).warn(
|
|
1820
1840
|
"Failed to parse {url}: {error}",
|
|
1821
1841
|
{ error: e, url: lookupUrl }
|
|
1822
1842
|
);
|
|
@@ -1842,6 +1862,7 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1842
1862
|
contextLoader: snapshot?.loader,
|
|
1843
1863
|
});
|
|
1844
1864
|
} finally {
|
|
1865
|
+
scopedContext.release();
|
|
1845
1866
|
snapshot?.release();
|
|
1846
1867
|
}
|
|
1847
1868
|
});
|
|
@@ -1853,6 +1874,7 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1853
1874
|
documentLoader?: DocumentLoader,
|
|
1854
1875
|
contextLoader?: DocumentLoader,
|
|
1855
1876
|
tracerProvider?: TracerProvider,
|
|
1877
|
+
verifyPortableObject?: PortableObjectVerifier,
|
|
1856
1878
|
baseUrl?: URL
|
|
1857
1879
|
}
|
|
1858
1880
|
): Promise<${getTypeNames(property.range, types)}> {
|
|
@@ -1863,6 +1885,7 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1863
1885
|
const tracerProvider = options.tracerProvider ??
|
|
1864
1886
|
this._tracerProvider ?? trace.getTracerProvider();
|
|
1865
1887
|
const baseUrl = options.baseUrl;
|
|
1888
|
+
const verifyPortableObject = options.verifyPortableObject;
|
|
1866
1889
|
`;
|
|
1867
1890
|
if (property.preprocessors != null && property.preprocessors.length > 0) {
|
|
1868
1891
|
yield `
|
|
@@ -1882,6 +1905,7 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1882
1905
|
documentLoader,
|
|
1883
1906
|
contextLoader,
|
|
1884
1907
|
tracerProvider,
|
|
1908
|
+
verifyPortableObject,
|
|
1885
1909
|
baseUrl,
|
|
1886
1910
|
});
|
|
1887
1911
|
if (_result instanceof Error) throw _result;
|
|
@@ -1900,7 +1924,13 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1900
1924
|
try {
|
|
1901
1925
|
return await ${types[range].name}.fromJsonLd(
|
|
1902
1926
|
jsonLd,
|
|
1903
|
-
{
|
|
1927
|
+
{
|
|
1928
|
+
documentLoader,
|
|
1929
|
+
contextLoader,
|
|
1930
|
+
tracerProvider,
|
|
1931
|
+
verifyPortableObject,
|
|
1932
|
+
baseUrl,
|
|
1933
|
+
},
|
|
1904
1934
|
);
|
|
1905
1935
|
} catch (e) {
|
|
1906
1936
|
if (!(e instanceof TypeError)) throw e;
|
|
@@ -1953,6 +1983,15 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1953
1983
|
);
|
|
1954
1984
|
}
|
|
1955
1985
|
if (this.${await getFieldName(property.uri)}.length < 1) return null;
|
|
1986
|
+
if (
|
|
1987
|
+
options.verifyPortableObject == null &&
|
|
1988
|
+
this._verifyPortableObject != null
|
|
1989
|
+
) {
|
|
1990
|
+
options = {
|
|
1991
|
+
...options,
|
|
1992
|
+
verifyPortableObject: this._verifyPortableObject,
|
|
1993
|
+
};
|
|
1994
|
+
}
|
|
1956
1995
|
let v = this.${await getFieldName(property.uri)}[0];
|
|
1957
1996
|
if (!(v instanceof URL) &&
|
|
1958
1997
|
!this.${await getFieldName(property.uri, "#_trust")}.has(0)) {
|
|
@@ -1999,6 +2038,7 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
1999
2038
|
yield `
|
|
2000
2039
|
v = await this.#${property.singularName}_fromJsonLd(doc, {
|
|
2001
2040
|
...options,
|
|
2041
|
+
verifyPortableObject: this._verifyPortableObject,
|
|
2002
2042
|
baseUrl: ${cachedPropertyBaseUrl},
|
|
2003
2043
|
});
|
|
2004
2044
|
`;
|
|
@@ -2077,6 +2117,15 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
2077
2117
|
this._warning.values
|
|
2078
2118
|
);
|
|
2079
2119
|
}
|
|
2120
|
+
if (
|
|
2121
|
+
options.verifyPortableObject == null &&
|
|
2122
|
+
this._verifyPortableObject != null
|
|
2123
|
+
) {
|
|
2124
|
+
options = {
|
|
2125
|
+
...options,
|
|
2126
|
+
verifyPortableObject: this._verifyPortableObject,
|
|
2127
|
+
};
|
|
2128
|
+
}
|
|
2080
2129
|
const vs = this.${await getFieldName(property.uri)};
|
|
2081
2130
|
for (let i = 0; i < vs.length; i++) {
|
|
2082
2131
|
let v = vs[i];
|
|
@@ -2129,6 +2178,7 @@ async function* generateProperty(type, property, types, moduleVarNames) {
|
|
|
2129
2178
|
yield `
|
|
2130
2179
|
v = await this.#${property.singularName}_fromJsonLd(obj, {
|
|
2131
2180
|
...options,
|
|
2181
|
+
verifyPortableObject: this._verifyPortableObject,
|
|
2132
2182
|
baseUrl: ${cachedPropertyBaseUrl},
|
|
2133
2183
|
});
|
|
2134
2184
|
`;
|
|
@@ -2182,6 +2232,7 @@ const XSD_ANY_URI = "http://www.w3.org/2001/XMLSchema#anyURI";
|
|
|
2182
2232
|
const FEDIFY_URL = "fedify:url";
|
|
2183
2233
|
const INTERNAL_RUNTIME_IMPORTS = [
|
|
2184
2234
|
"compactJsonLdCache",
|
|
2235
|
+
"createScopedContextLoader",
|
|
2185
2236
|
"getJsonLdContext",
|
|
2186
2237
|
"isTrustedIriOrigin",
|
|
2187
2238
|
"normalizeJsonLdIris"
|
|
@@ -2263,6 +2314,7 @@ async function* generateClass(typeUri, types, moduleVarNames) {
|
|
|
2263
2314
|
readonly #documentLoader?: DocumentLoader;
|
|
2264
2315
|
readonly #contextLoader?: DocumentLoader;
|
|
2265
2316
|
readonly #tracerProvider?: TracerProvider;
|
|
2317
|
+
readonly #verifyPortableObject?: PortableObjectVerifier;
|
|
2266
2318
|
readonly #warning?: {
|
|
2267
2319
|
category: string[];
|
|
2268
2320
|
message: string;
|
|
@@ -2285,6 +2337,10 @@ async function* generateClass(typeUri, types, moduleVarNames) {
|
|
|
2285
2337
|
return this.#tracerProvider;
|
|
2286
2338
|
}
|
|
2287
2339
|
|
|
2340
|
+
protected get _verifyPortableObject(): PortableObjectVerifier | undefined {
|
|
2341
|
+
return this.#verifyPortableObject;
|
|
2342
|
+
}
|
|
2343
|
+
|
|
2288
2344
|
protected get _warning(): {
|
|
2289
2345
|
category: string[];
|
|
2290
2346
|
message: string;
|