@fedify/vocab-tools 2.5.0-dev.2664 → 2.5.0-dev.2687
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 -2
- package/dist/mod.cjs +1 -1
- package/dist/mod.d.cts +3 -3
- package/dist/mod.d.ts +3 -3
- package/dist/mod.js +1 -1
- package/package.json +2 -2
- package/src/class.test.ts +43 -46
- package/src/class.ts +18 -14
- package/src/codec.test.ts +281 -248
- package/src/codec.ts +14 -22
- package/src/constructor.ts +20 -17
- package/src/deep-clone.ts +3 -2
- package/src/field.ts +5 -3
- package/src/inspector.ts +4 -3
- package/src/property.ts +64 -63
- package/src/schema.test.ts +60 -62
- package/src/schema.ts +75 -70
- package/src/type.ts +23 -17
- package/tsdown.config.ts +9 -7
package/deno.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/vocab-tools",
|
|
3
|
-
"version": "2.5.0-dev.
|
|
3
|
+
"version": "2.5.0-dev.2687+924da5ce",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./src/mod.ts"
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
]
|
|
27
27
|
},
|
|
28
28
|
"tasks": {
|
|
29
|
-
"check": "deno
|
|
29
|
+
"check": "deno check src/*.ts",
|
|
30
30
|
"test": "deno test -A"
|
|
31
31
|
}
|
|
32
32
|
}
|
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.5.0-dev.
|
|
11
|
+
var version = "2.5.0-dev.2687+924da5ce";
|
|
12
12
|
//#endregion
|
|
13
13
|
//#region src/type.ts
|
|
14
14
|
const HEURISTICS_CONTEXTS = [
|
package/dist/mod.d.cts
CHANGED
|
@@ -180,7 +180,7 @@ type PropertySchemaTyping = {
|
|
|
180
180
|
* The schema of a property. It is used to generate property accessors of
|
|
181
181
|
* a class.
|
|
182
182
|
*/
|
|
183
|
-
type PropertySchema = PropertySchemaBase & PropertySchemaTyping & {
|
|
183
|
+
type PropertySchema = (PropertySchemaBase & PropertySchemaTyping & {
|
|
184
184
|
/**
|
|
185
185
|
* Marks the property that it can have only one value. Turning on this
|
|
186
186
|
* flag will generate only singular property accessors, so `pluralName`
|
|
@@ -202,14 +202,14 @@ type PropertySchema = PropertySchemaBase & PropertySchemaTyping & {
|
|
|
202
202
|
* The container type of the property values. It can be unspecified.
|
|
203
203
|
*/
|
|
204
204
|
container?: "graph" | "list";
|
|
205
|
-
} | PropertySchemaBase & PropertySchemaTyping & {
|
|
205
|
+
}) | (PropertySchemaBase & PropertySchemaTyping & {
|
|
206
206
|
/**
|
|
207
207
|
* Marks the property that it can have only one value. Turning on this
|
|
208
208
|
* flag will generate only singular property accessors, so `pluralName`
|
|
209
209
|
* and `singularAccessor` should not be specified.
|
|
210
210
|
*/
|
|
211
211
|
functional: true;
|
|
212
|
-
};
|
|
212
|
+
});
|
|
213
213
|
/**
|
|
214
214
|
* A JSON-LD context, which is placed in the `@context` property of a JSON-LD
|
|
215
215
|
* document.
|
package/dist/mod.d.ts
CHANGED
|
@@ -180,7 +180,7 @@ type PropertySchemaTyping = {
|
|
|
180
180
|
* The schema of a property. It is used to generate property accessors of
|
|
181
181
|
* a class.
|
|
182
182
|
*/
|
|
183
|
-
type PropertySchema = PropertySchemaBase & PropertySchemaTyping & {
|
|
183
|
+
type PropertySchema = (PropertySchemaBase & PropertySchemaTyping & {
|
|
184
184
|
/**
|
|
185
185
|
* Marks the property that it can have only one value. Turning on this
|
|
186
186
|
* flag will generate only singular property accessors, so `pluralName`
|
|
@@ -202,14 +202,14 @@ type PropertySchema = PropertySchemaBase & PropertySchemaTyping & {
|
|
|
202
202
|
* The container type of the property values. It can be unspecified.
|
|
203
203
|
*/
|
|
204
204
|
container?: "graph" | "list";
|
|
205
|
-
} | PropertySchemaBase & PropertySchemaTyping & {
|
|
205
|
+
}) | (PropertySchemaBase & PropertySchemaTyping & {
|
|
206
206
|
/**
|
|
207
207
|
* Marks the property that it can have only one value. Turning on this
|
|
208
208
|
* flag will generate only singular property accessors, so `pluralName`
|
|
209
209
|
* and `singularAccessor` should not be specified.
|
|
210
210
|
*/
|
|
211
211
|
functional: true;
|
|
212
|
-
};
|
|
212
|
+
});
|
|
213
213
|
/**
|
|
214
214
|
* A JSON-LD context, which is placed in the `@context` property of a JSON-LD
|
|
215
215
|
* document.
|
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.5.0-dev.
|
|
10
|
+
var version = "2.5.0-dev.2687+924da5ce";
|
|
11
11
|
//#endregion
|
|
12
12
|
//#region src/type.ts
|
|
13
13
|
const HEURISTICS_CONTEXTS = [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/vocab-tools",
|
|
3
|
-
"version": "2.5.0-dev.
|
|
3
|
+
"version": "2.5.0-dev.2687+924da5ce",
|
|
4
4
|
"description": "Code generator for Activity Vocabulary APIs",
|
|
5
5
|
"homepage": "https://fedify.dev/",
|
|
6
6
|
"repository": {
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@types/node": "^24.12.2",
|
|
52
52
|
"tsdown": "^0.22.0",
|
|
53
53
|
"typescript": "^6.0.3",
|
|
54
|
-
"@fedify/vocab-runtime": "^2.5.0-dev.
|
|
54
|
+
"@fedify/vocab-runtime": "^2.5.0-dev.2687+924da5ce"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@cfworker/json-schema": "^4.1.1",
|
package/src/class.test.ts
CHANGED
|
@@ -53,16 +53,13 @@ test("sortTopologically()", () => {
|
|
|
53
53
|
defaultContext: {},
|
|
54
54
|
},
|
|
55
55
|
});
|
|
56
|
-
deepStrictEqual(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"https://example.com/baz",
|
|
64
|
-
],
|
|
65
|
-
);
|
|
56
|
+
deepStrictEqual(sorted, [
|
|
57
|
+
"https://example.com/foo",
|
|
58
|
+
"https://example.com/bar",
|
|
59
|
+
"https://example.com/qux",
|
|
60
|
+
"https://example.com/quux",
|
|
61
|
+
"https://example.com/baz",
|
|
62
|
+
]);
|
|
66
63
|
});
|
|
67
64
|
|
|
68
65
|
test("generateClasses() imports the browser-safe jsonld entrypoint", async () => {
|
|
@@ -133,30 +130,32 @@ test("getDataCheck() uses canParseDecimal() for xsd:decimal", () => {
|
|
|
133
130
|
|
|
134
131
|
test("generateClasses() rejects xsd:string and xsd:decimal unions", async () => {
|
|
135
132
|
await rejects(
|
|
136
|
-
Array.fromAsync(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
133
|
+
Array.fromAsync(
|
|
134
|
+
generateClasses({
|
|
135
|
+
"https://example.com/measure": {
|
|
136
|
+
name: "Measure",
|
|
137
|
+
uri: "https://example.com/measure",
|
|
138
|
+
compactName: "Measure",
|
|
139
|
+
entity: false,
|
|
140
|
+
description: "A measure.",
|
|
141
|
+
properties: [
|
|
142
|
+
{
|
|
143
|
+
singularName: "amount",
|
|
144
|
+
functional: true,
|
|
145
|
+
compactName: "amount",
|
|
146
|
+
uri: "https://example.com/amount",
|
|
147
|
+
description: "An exact decimal amount.",
|
|
148
|
+
range: [
|
|
149
|
+
"http://www.w3.org/2001/XMLSchema#decimal",
|
|
150
|
+
"http://www.w3.org/2001/XMLSchema#string",
|
|
151
|
+
],
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
defaultContext:
|
|
155
|
+
"https://example.com/context" as TypeSchema["defaultContext"],
|
|
156
|
+
},
|
|
157
|
+
}),
|
|
158
|
+
),
|
|
160
159
|
/cannot have both xsd:string and xsd:decimal in its range/,
|
|
161
160
|
);
|
|
162
161
|
});
|
|
@@ -278,18 +277,16 @@ async function getEntityTypeFixtureCode() {
|
|
|
278
277
|
|
|
279
278
|
async function changeNodeSnapshotPath() {
|
|
280
279
|
const { snapshot } = await import("node:test");
|
|
281
|
-
snapshot.setResolveSnapshotPath(
|
|
282
|
-
(path)
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
},
|
|
292
|
-
);
|
|
280
|
+
snapshot.setResolveSnapshotPath((path) => {
|
|
281
|
+
if (!path) {
|
|
282
|
+
throw new Error("path is undefined");
|
|
283
|
+
}
|
|
284
|
+
return join(
|
|
285
|
+
dirname(path),
|
|
286
|
+
"__snapshots__",
|
|
287
|
+
basename(path.replace(extname(path), ".ts")) + ".node.snap",
|
|
288
|
+
);
|
|
289
|
+
});
|
|
293
290
|
snapshot.setDefaultSnapshotSerializers([
|
|
294
291
|
(value) => JSON.stringify(value, null, 2),
|
|
295
292
|
(value) => value.replaceAll("\\n", "\n"),
|
package/src/class.ts
CHANGED
|
@@ -227,12 +227,13 @@ function* generateEntityTypeHelpers(
|
|
|
227
227
|
types: Record<string, TypeSchema>,
|
|
228
228
|
): Iterable<string> {
|
|
229
229
|
const entityTypes = sortedTypeUris.flatMap((typeUri) =>
|
|
230
|
-
types[typeUri].entity ? [{ name: types[typeUri].name, uri: typeUri }] : []
|
|
230
|
+
types[typeUri].entity ? [{ name: types[typeUri].name, uri: typeUri }] : [],
|
|
231
231
|
);
|
|
232
232
|
const entityTypeNames = entityTypes.map((entityType) => entityType.name);
|
|
233
|
-
const entityTypeUnion =
|
|
234
|
-
|
|
235
|
-
|
|
233
|
+
const entityTypeUnion =
|
|
234
|
+
entityTypeNames.length < 1
|
|
235
|
+
? " never"
|
|
236
|
+
: `\n | typeof ${entityTypeNames.join("\n | typeof ")}`;
|
|
236
237
|
yield `/**
|
|
237
238
|
* Constructor types for all generated vocabulary entity classes.
|
|
238
239
|
*/
|
|
@@ -277,9 +278,12 @@ function canContainIriValue(
|
|
|
277
278
|
property: PropertySchema,
|
|
278
279
|
types: Record<string, TypeSchema>,
|
|
279
280
|
): boolean {
|
|
280
|
-
return property.range.some(
|
|
281
|
-
typeUri
|
|
282
|
-
|
|
281
|
+
return property.range.some(
|
|
282
|
+
(typeUri) =>
|
|
283
|
+
typeUri === XSD_ANY_URI ||
|
|
284
|
+
typeUri === FEDIFY_URL ||
|
|
285
|
+
typeUri === FEDIFY_ABSOLUTE_IRI ||
|
|
286
|
+
types[typeUri]?.entity,
|
|
283
287
|
);
|
|
284
288
|
}
|
|
285
289
|
|
|
@@ -364,8 +368,8 @@ function isValidLanguageTag(language: string): boolean {
|
|
|
364
368
|
if (
|
|
365
369
|
Object.values(types).some((type) =>
|
|
366
370
|
type.properties.some((property) =>
|
|
367
|
-
property.range.includes(FEDIFY_ABSOLUTE_IRI)
|
|
368
|
-
)
|
|
371
|
+
property.range.includes(FEDIFY_ABSOLUTE_IRI),
|
|
372
|
+
),
|
|
369
373
|
)
|
|
370
374
|
) {
|
|
371
375
|
// An absolute IRI may arrive as an IRI node or, when the publisher's
|
|
@@ -405,8 +409,8 @@ function isAbsoluteIriValue(value: unknown): boolean {
|
|
|
405
409
|
type.properties.flatMap((property) =>
|
|
406
410
|
property.extraContext == null
|
|
407
411
|
? []
|
|
408
|
-
: [[property.uri, property.extraContext]]
|
|
409
|
-
)
|
|
412
|
+
: [[property.uri, property.extraContext]],
|
|
413
|
+
),
|
|
410
414
|
),
|
|
411
415
|
);
|
|
412
416
|
if (Object.keys(extraContexts).length > 0) {
|
|
@@ -457,9 +461,9 @@ function getExtraContexts(document: unknown): string[] {
|
|
|
457
461
|
}
|
|
458
462
|
}
|
|
459
463
|
yield "const PORTABLE_IRI_PATTERN = /^ap(?:\\+ef61)?:\\/\\//i;\n";
|
|
460
|
-
yield `const PORTABLE_IRI_KEYS: ReadonlySet<string> = new Set(${
|
|
461
|
-
|
|
462
|
-
});\n\n`;
|
|
464
|
+
yield `const PORTABLE_IRI_KEYS: ReadonlySet<string> = new Set(${JSON.stringify(
|
|
465
|
+
[...portableIriKeys].sort(),
|
|
466
|
+
)});\n\n`;
|
|
463
467
|
const moduleVarNames = new Map<string, string>();
|
|
464
468
|
const sorted = sortTopologically(types);
|
|
465
469
|
for (const typeUri of sorted) {
|