@fedify/vocab-tools 2.3.2-dev.1556 → 2.3.2
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 +55 -14
- package/dist/mod.js +55 -14
- package/package.json +1 -1
- package/src/__snapshots__/class.test.ts.deno.snap +4241 -824
- package/src/__snapshots__/class.test.ts.node.snap +4241 -824
- package/src/__snapshots__/class.test.ts.snap +4241 -824
- package/src/class.ts +26 -0
- package/src/codec.ts +32 -20
- package/src/type.ts +2 -1
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.3.2
|
|
11
|
+
var version = "2.3.2";
|
|
12
12
|
//#endregion
|
|
13
13
|
//#region src/type.ts
|
|
14
14
|
const HEURISTICS_CONTEXTS = [
|
|
@@ -199,7 +199,8 @@ const scalarTypes = {
|
|
|
199
199
|
dataCheck(v) {
|
|
200
200
|
return `typeof ${v} === "object" && "@language" in ${v} && "@value" in ${v}
|
|
201
201
|
&& typeof ${v}["@language"] === "string"
|
|
202
|
-
&& typeof ${v}["@value"] === "string"
|
|
202
|
+
&& typeof ${v}["@value"] === "string"
|
|
203
|
+
&& isValidLanguageTag(${v}["@language"])`;
|
|
203
204
|
},
|
|
204
205
|
decoder(v) {
|
|
205
206
|
return `new LanguageString(${v}["@value"], ${v}["@language"])`;
|
|
@@ -1071,6 +1072,9 @@ async function* generateDecoder(typeUri, types, moduleVarNames) {
|
|
|
1071
1072
|
throw new TypeError("Unexpected type: " + instance.constructor.name);
|
|
1072
1073
|
}
|
|
1073
1074
|
`;
|
|
1075
|
+
yield `
|
|
1076
|
+
let shouldCacheJsonLd = instance._shouldCacheJsonLd;
|
|
1077
|
+
`;
|
|
1074
1078
|
for (const property of type.properties) {
|
|
1075
1079
|
const variable = await getFieldName(property.uri, "");
|
|
1076
1080
|
yield await generateField(property, types, "const ");
|
|
@@ -1107,29 +1111,40 @@ async function* generateDecoder(typeUri, types, moduleVarNames) {
|
|
|
1107
1111
|
continue;
|
|
1108
1112
|
}
|
|
1109
1113
|
`;
|
|
1110
|
-
|
|
1111
|
-
const decoded = ${getDecoder(property.range[0], types, "v", "options", propertyBaseUrl)};
|
|
1112
|
-
if (typeof decoded === "undefined") continue;
|
|
1113
|
-
${variable}.push(decoded);`;
|
|
1114
|
-
else {
|
|
1115
|
-
yield `
|
|
1114
|
+
yield `
|
|
1116
1115
|
const decoded =
|
|
1117
|
-
|
|
1116
|
+
`;
|
|
1117
|
+
if (property.range.length == 1) yield getDecoder(property.range[0], types, "v", "options", propertyBaseUrl);
|
|
1118
|
+
else {
|
|
1118
1119
|
const decoders = getDecoders(property.range, types, "v", "options", propertyBaseUrl);
|
|
1119
1120
|
for (const code of decoders) yield code;
|
|
1120
|
-
|
|
1121
|
+
}
|
|
1122
|
+
yield `
|
|
1121
1123
|
;
|
|
1122
|
-
|
|
1124
|
+
`;
|
|
1125
|
+
yield `
|
|
1126
|
+
if (typeof decoded === "undefined") {
|
|
1127
|
+
shouldCacheJsonLd = false;
|
|
1128
|
+
continue;
|
|
1129
|
+
}
|
|
1130
|
+
`;
|
|
1131
|
+
yield `
|
|
1132
|
+
if (!this._shouldCacheDecodedJsonLd(decoded)) {
|
|
1133
|
+
shouldCacheJsonLd = false;
|
|
1134
|
+
}
|
|
1123
1135
|
${variable}.push(decoded);
|
|
1124
|
-
|
|
1125
|
-
}
|
|
1136
|
+
`;
|
|
1126
1137
|
yield `
|
|
1127
1138
|
}
|
|
1128
1139
|
instance.${await getFieldName(property.uri)} = ${variable};
|
|
1129
1140
|
`;
|
|
1130
1141
|
}
|
|
1131
1142
|
yield `
|
|
1132
|
-
|
|
1143
|
+
instance._shouldCacheJsonLd = shouldCacheJsonLd;
|
|
1144
|
+
if (
|
|
1145
|
+
shouldCacheJsonLd &&
|
|
1146
|
+
(!("_fromSubclass" in options) || !options._fromSubclass)
|
|
1147
|
+
) {
|
|
1133
1148
|
try {
|
|
1134
1149
|
instance._cachedJsonLd = structuredClone(json);
|
|
1135
1150
|
} catch {
|
|
@@ -1954,6 +1969,7 @@ async function* generateClass(typeUri, types, moduleVarNames) {
|
|
|
1954
1969
|
};
|
|
1955
1970
|
#cachedJsonLd?: unknown;
|
|
1956
1971
|
readonly #_baseUrl?: URL;
|
|
1972
|
+
#shouldCacheJsonLd = true;
|
|
1957
1973
|
readonly id: URL | null;
|
|
1958
1974
|
|
|
1959
1975
|
protected get _documentLoader(): DocumentLoader | undefined {
|
|
@@ -1987,6 +2003,20 @@ async function* generateClass(typeUri, types, moduleVarNames) {
|
|
|
1987
2003
|
protected get _baseUrl(): URL | undefined {
|
|
1988
2004
|
return this.#_baseUrl;
|
|
1989
2005
|
}
|
|
2006
|
+
|
|
2007
|
+
protected get _shouldCacheJsonLd(): boolean {
|
|
2008
|
+
return this.#shouldCacheJsonLd;
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2011
|
+
protected set _shouldCacheJsonLd(value: boolean) {
|
|
2012
|
+
this.#shouldCacheJsonLd = value;
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
protected static _shouldCacheDecodedJsonLd(value: unknown): boolean {
|
|
2016
|
+
if (value == null || typeof value !== "object") return true;
|
|
2017
|
+
if (!("_shouldCacheJsonLd" in value)) return true;
|
|
2018
|
+
return (value as { _shouldCacheJsonLd: boolean })._shouldCacheJsonLd;
|
|
2019
|
+
}
|
|
1990
2020
|
`;
|
|
1991
2021
|
yield `
|
|
1992
2022
|
/**
|
|
@@ -2080,6 +2110,17 @@ async function* generateClasses(types) {
|
|
|
2080
2110
|
isTemporalDuration,
|
|
2081
2111
|
isTemporalInstant,
|
|
2082
2112
|
} from "@fedify/vocab-runtime/temporal";\n`;
|
|
2113
|
+
yield `
|
|
2114
|
+
function isValidLanguageTag(language: string): boolean {
|
|
2115
|
+
try {
|
|
2116
|
+
new Intl.Locale(language);
|
|
2117
|
+
return true;
|
|
2118
|
+
} catch (error) {
|
|
2119
|
+
if (error instanceof RangeError) return false;
|
|
2120
|
+
throw error;
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
2123
|
+
`;
|
|
2083
2124
|
yield "\n\n";
|
|
2084
2125
|
const moduleVarNames = /* @__PURE__ */ new Map();
|
|
2085
2126
|
const sorted = sortTopologically(types);
|
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.3.2
|
|
10
|
+
var version = "2.3.2";
|
|
11
11
|
//#endregion
|
|
12
12
|
//#region src/type.ts
|
|
13
13
|
const HEURISTICS_CONTEXTS = [
|
|
@@ -198,7 +198,8 @@ const scalarTypes = {
|
|
|
198
198
|
dataCheck(v) {
|
|
199
199
|
return `typeof ${v} === "object" && "@language" in ${v} && "@value" in ${v}
|
|
200
200
|
&& typeof ${v}["@language"] === "string"
|
|
201
|
-
&& typeof ${v}["@value"] === "string"
|
|
201
|
+
&& typeof ${v}["@value"] === "string"
|
|
202
|
+
&& isValidLanguageTag(${v}["@language"])`;
|
|
202
203
|
},
|
|
203
204
|
decoder(v) {
|
|
204
205
|
return `new LanguageString(${v}["@value"], ${v}["@language"])`;
|
|
@@ -1070,6 +1071,9 @@ async function* generateDecoder(typeUri, types, moduleVarNames) {
|
|
|
1070
1071
|
throw new TypeError("Unexpected type: " + instance.constructor.name);
|
|
1071
1072
|
}
|
|
1072
1073
|
`;
|
|
1074
|
+
yield `
|
|
1075
|
+
let shouldCacheJsonLd = instance._shouldCacheJsonLd;
|
|
1076
|
+
`;
|
|
1073
1077
|
for (const property of type.properties) {
|
|
1074
1078
|
const variable = await getFieldName(property.uri, "");
|
|
1075
1079
|
yield await generateField(property, types, "const ");
|
|
@@ -1106,29 +1110,40 @@ async function* generateDecoder(typeUri, types, moduleVarNames) {
|
|
|
1106
1110
|
continue;
|
|
1107
1111
|
}
|
|
1108
1112
|
`;
|
|
1109
|
-
|
|
1110
|
-
const decoded = ${getDecoder(property.range[0], types, "v", "options", propertyBaseUrl)};
|
|
1111
|
-
if (typeof decoded === "undefined") continue;
|
|
1112
|
-
${variable}.push(decoded);`;
|
|
1113
|
-
else {
|
|
1114
|
-
yield `
|
|
1113
|
+
yield `
|
|
1115
1114
|
const decoded =
|
|
1116
|
-
|
|
1115
|
+
`;
|
|
1116
|
+
if (property.range.length == 1) yield getDecoder(property.range[0], types, "v", "options", propertyBaseUrl);
|
|
1117
|
+
else {
|
|
1117
1118
|
const decoders = getDecoders(property.range, types, "v", "options", propertyBaseUrl);
|
|
1118
1119
|
for (const code of decoders) yield code;
|
|
1119
|
-
|
|
1120
|
+
}
|
|
1121
|
+
yield `
|
|
1120
1122
|
;
|
|
1121
|
-
|
|
1123
|
+
`;
|
|
1124
|
+
yield `
|
|
1125
|
+
if (typeof decoded === "undefined") {
|
|
1126
|
+
shouldCacheJsonLd = false;
|
|
1127
|
+
continue;
|
|
1128
|
+
}
|
|
1129
|
+
`;
|
|
1130
|
+
yield `
|
|
1131
|
+
if (!this._shouldCacheDecodedJsonLd(decoded)) {
|
|
1132
|
+
shouldCacheJsonLd = false;
|
|
1133
|
+
}
|
|
1122
1134
|
${variable}.push(decoded);
|
|
1123
|
-
|
|
1124
|
-
}
|
|
1135
|
+
`;
|
|
1125
1136
|
yield `
|
|
1126
1137
|
}
|
|
1127
1138
|
instance.${await getFieldName(property.uri)} = ${variable};
|
|
1128
1139
|
`;
|
|
1129
1140
|
}
|
|
1130
1141
|
yield `
|
|
1131
|
-
|
|
1142
|
+
instance._shouldCacheJsonLd = shouldCacheJsonLd;
|
|
1143
|
+
if (
|
|
1144
|
+
shouldCacheJsonLd &&
|
|
1145
|
+
(!("_fromSubclass" in options) || !options._fromSubclass)
|
|
1146
|
+
) {
|
|
1132
1147
|
try {
|
|
1133
1148
|
instance._cachedJsonLd = structuredClone(json);
|
|
1134
1149
|
} catch {
|
|
@@ -1953,6 +1968,7 @@ async function* generateClass(typeUri, types, moduleVarNames) {
|
|
|
1953
1968
|
};
|
|
1954
1969
|
#cachedJsonLd?: unknown;
|
|
1955
1970
|
readonly #_baseUrl?: URL;
|
|
1971
|
+
#shouldCacheJsonLd = true;
|
|
1956
1972
|
readonly id: URL | null;
|
|
1957
1973
|
|
|
1958
1974
|
protected get _documentLoader(): DocumentLoader | undefined {
|
|
@@ -1986,6 +2002,20 @@ async function* generateClass(typeUri, types, moduleVarNames) {
|
|
|
1986
2002
|
protected get _baseUrl(): URL | undefined {
|
|
1987
2003
|
return this.#_baseUrl;
|
|
1988
2004
|
}
|
|
2005
|
+
|
|
2006
|
+
protected get _shouldCacheJsonLd(): boolean {
|
|
2007
|
+
return this.#shouldCacheJsonLd;
|
|
2008
|
+
}
|
|
2009
|
+
|
|
2010
|
+
protected set _shouldCacheJsonLd(value: boolean) {
|
|
2011
|
+
this.#shouldCacheJsonLd = value;
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
protected static _shouldCacheDecodedJsonLd(value: unknown): boolean {
|
|
2015
|
+
if (value == null || typeof value !== "object") return true;
|
|
2016
|
+
if (!("_shouldCacheJsonLd" in value)) return true;
|
|
2017
|
+
return (value as { _shouldCacheJsonLd: boolean })._shouldCacheJsonLd;
|
|
2018
|
+
}
|
|
1989
2019
|
`;
|
|
1990
2020
|
yield `
|
|
1991
2021
|
/**
|
|
@@ -2079,6 +2109,17 @@ async function* generateClasses(types) {
|
|
|
2079
2109
|
isTemporalDuration,
|
|
2080
2110
|
isTemporalInstant,
|
|
2081
2111
|
} from "@fedify/vocab-runtime/temporal";\n`;
|
|
2112
|
+
yield `
|
|
2113
|
+
function isValidLanguageTag(language: string): boolean {
|
|
2114
|
+
try {
|
|
2115
|
+
new Intl.Locale(language);
|
|
2116
|
+
return true;
|
|
2117
|
+
} catch (error) {
|
|
2118
|
+
if (error instanceof RangeError) return false;
|
|
2119
|
+
throw error;
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
`;
|
|
2082
2123
|
yield "\n\n";
|
|
2083
2124
|
const moduleVarNames = /* @__PURE__ */ new Map();
|
|
2084
2125
|
const sorted = sortTopologically(types);
|