@fedify/vocab-tools 2.5.0-dev.2619 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/vocab-tools",
3
- "version": "2.5.0-dev.2619+88aa7efd",
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 fmt --check && deno lint && deno check src/*.ts",
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.2619+88aa7efd";
11
+ var version = "2.5.0-dev.2687+924da5ce";
12
12
  //#endregion
13
13
  //#region src/type.ts
14
14
  const HEURISTICS_CONTEXTS = [
@@ -710,7 +710,7 @@ async function loadSchema(path) {
710
710
  const errors = [];
711
711
  if (result.valid) return schema;
712
712
  for (const e of result.errors) errors.push(new SchemaError(path, `${path}:${e.instanceLocation}: ${e.error}`));
713
- throw new AggregateError(errors);
713
+ throw new AggregateError(errors, "Invalid schema data");
714
714
  }
715
715
  /**
716
716
  * Loads all schema files in the directory.
@@ -739,7 +739,7 @@ async function loadSchemaFiles(dir) {
739
739
  }
740
740
  result[schema.uri] = schema;
741
741
  }
742
- if (errors.length > 0) throw new AggregateError(errors);
742
+ if (errors.length > 0) throw new AggregateError(errors, "Failed to load schema files");
743
743
  const entries = Object.entries(result);
744
744
  entries.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
745
745
  return Object.fromEntries(entries);
@@ -2964,10 +2964,10 @@ async function* generateClass(typeUri, types, moduleVarNames) {
2964
2964
  for await (const code of generateInspectorPostClass(typeUri, types)) yield code;
2965
2965
  }
2966
2966
  function* generateEntityTypeHelpers(sortedTypeUris, types) {
2967
- const entityTypes = sortedTypeUris.filter((typeUri) => types[typeUri].entity).map((typeUri) => ({
2967
+ const entityTypes = sortedTypeUris.flatMap((typeUri) => types[typeUri].entity ? [{
2968
2968
  name: types[typeUri].name,
2969
2969
  uri: typeUri
2970
- }));
2970
+ }] : []);
2971
2971
  const entityTypeNames = entityTypes.map((entityType) => entityType.name);
2972
2972
  yield `/**
2973
2973
  * Constructor types for all generated vocabulary entity classes.
@@ -3024,6 +3024,7 @@ function addPortableIriKeys(keys, property, types) {
3024
3024
  async function* generateClasses(types) {
3025
3025
  validateTypeSchemas(types);
3026
3026
  yield "// deno-lint-ignore-file ban-unused-ignore no-explicit-any no-unused-vars prefer-const verbatim-module-syntax\n";
3027
+ yield "// oxlint-disable typescript/no-explicit-any, no-unused-vars, prefer-const\n";
3027
3028
  yield "import jsonld from \"@fedify/vocab-runtime/jsonld\";\n";
3028
3029
  yield "import { getLogger } from \"@logtape/logtape\";\n";
3029
3030
  yield `import { type Span, SpanStatusCode, type TracerProvider, trace }
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.2619+88aa7efd";
10
+ var version = "2.5.0-dev.2687+924da5ce";
11
11
  //#endregion
12
12
  //#region src/type.ts
13
13
  const HEURISTICS_CONTEXTS = [
@@ -709,7 +709,7 @@ async function loadSchema(path) {
709
709
  const errors = [];
710
710
  if (result.valid) return schema;
711
711
  for (const e of result.errors) errors.push(new SchemaError(path, `${path}:${e.instanceLocation}: ${e.error}`));
712
- throw new AggregateError(errors);
712
+ throw new AggregateError(errors, "Invalid schema data");
713
713
  }
714
714
  /**
715
715
  * Loads all schema files in the directory.
@@ -738,7 +738,7 @@ async function loadSchemaFiles(dir) {
738
738
  }
739
739
  result[schema.uri] = schema;
740
740
  }
741
- if (errors.length > 0) throw new AggregateError(errors);
741
+ if (errors.length > 0) throw new AggregateError(errors, "Failed to load schema files");
742
742
  const entries = Object.entries(result);
743
743
  entries.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
744
744
  return Object.fromEntries(entries);
@@ -2963,10 +2963,10 @@ async function* generateClass(typeUri, types, moduleVarNames) {
2963
2963
  for await (const code of generateInspectorPostClass(typeUri, types)) yield code;
2964
2964
  }
2965
2965
  function* generateEntityTypeHelpers(sortedTypeUris, types) {
2966
- const entityTypes = sortedTypeUris.filter((typeUri) => types[typeUri].entity).map((typeUri) => ({
2966
+ const entityTypes = sortedTypeUris.flatMap((typeUri) => types[typeUri].entity ? [{
2967
2967
  name: types[typeUri].name,
2968
2968
  uri: typeUri
2969
- }));
2969
+ }] : []);
2970
2970
  const entityTypeNames = entityTypes.map((entityType) => entityType.name);
2971
2971
  yield `/**
2972
2972
  * Constructor types for all generated vocabulary entity classes.
@@ -3023,6 +3023,7 @@ function addPortableIriKeys(keys, property, types) {
3023
3023
  async function* generateClasses(types) {
3024
3024
  validateTypeSchemas(types);
3025
3025
  yield "// deno-lint-ignore-file ban-unused-ignore no-explicit-any no-unused-vars prefer-const verbatim-module-syntax\n";
3026
+ yield "// oxlint-disable typescript/no-explicit-any, no-unused-vars, prefer-const\n";
3026
3027
  yield "import jsonld from \"@fedify/vocab-runtime/jsonld\";\n";
3027
3028
  yield "import { getLogger } from \"@logtape/logtape\";\n";
3028
3029
  yield `import { type Span, SpanStatusCode, type TracerProvider, trace }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/vocab-tools",
3
- "version": "2.5.0-dev.2619+88aa7efd",
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": {
@@ -46,12 +46,12 @@
46
46
  },
47
47
  "license": "MIT",
48
48
  "devDependencies": {
49
- "@logtape/logtape": "^2.2.0",
49
+ "@logtape/logtape": "2.4.2",
50
50
  "@opentelemetry/api": "~1.9.1",
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.2619+88aa7efd"
54
+ "@fedify/vocab-runtime": "^2.5.0-dev.2687+924da5ce"
55
55
  },
56
56
  "dependencies": {
57
57
  "@cfworker/json-schema": "^4.1.1",
@@ -2,6 +2,7 @@ export const snapshot = {};
2
2
 
3
3
  snapshot[`generateClasses() 1`] = `
4
4
  "// deno-lint-ignore-file ban-unused-ignore no-explicit-any no-unused-vars prefer-const verbatim-module-syntax
5
+ // oxlint-disable typescript/no-explicit-any, no-unused-vars, prefer-const
5
6
  import jsonld from \\"@fedify/vocab-runtime/jsonld\\";
6
7
  import { getLogger } from \\"@logtape/logtape\\";
7
8
  import { type Span, SpanStatusCode, type TracerProvider, trace }
@@ -1,5 +1,6 @@
1
1
  exports[`generateClasses() 1`] = `
2
2
  "// deno-lint-ignore-file ban-unused-ignore no-explicit-any no-unused-vars prefer-const verbatim-module-syntax
3
+ // oxlint-disable typescript/no-explicit-any, no-unused-vars, prefer-const
3
4
  import jsonld from \\"@fedify/vocab-runtime/jsonld\\";
4
5
  import { getLogger } from \\"@logtape/logtape\\";
5
6
  import { type Span, SpanStatusCode, type TracerProvider, trace }
@@ -2,6 +2,7 @@
2
2
 
3
3
  exports[`generateClasses() 1`] = `
4
4
  "// deno-lint-ignore-file ban-unused-ignore no-explicit-any no-unused-vars prefer-const verbatim-module-syntax
5
+ // oxlint-disable typescript/no-explicit-any, no-unused-vars, prefer-const
5
6
  import jsonld from "@fedify/vocab-runtime/jsonld";
6
7
  import { getLogger } from "@logtape/logtape";
7
8
  import { type Span, SpanStatusCode, type TracerProvider, trace }
package/src/class.test.ts CHANGED
@@ -53,16 +53,13 @@ test("sortTopologically()", () => {
53
53
  defaultContext: {},
54
54
  },
55
55
  });
56
- deepStrictEqual(
57
- sorted,
58
- [
59
- "https://example.com/foo",
60
- "https://example.com/bar",
61
- "https://example.com/qux",
62
- "https://example.com/quux",
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(generateClasses({
137
- "https://example.com/measure": {
138
- name: "Measure",
139
- uri: "https://example.com/measure",
140
- compactName: "Measure",
141
- entity: false,
142
- description: "A measure.",
143
- properties: [
144
- {
145
- singularName: "amount",
146
- functional: true,
147
- compactName: "amount",
148
- uri: "https://example.com/amount",
149
- description: "An exact decimal amount.",
150
- range: [
151
- "http://www.w3.org/2001/XMLSchema#decimal",
152
- "http://www.w3.org/2001/XMLSchema#string",
153
- ],
154
- },
155
- ],
156
- defaultContext:
157
- "https://example.com/context" as TypeSchema["defaultContext"],
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
- if (!path) {
284
- throw new Error("path is undefined");
285
- }
286
- return join(
287
- dirname(path),
288
- "__snapshots__",
289
- basename(path.replace(extname(path), ".ts")) + ".node.snap",
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
@@ -226,12 +226,14 @@ function* generateEntityTypeHelpers(
226
226
  sortedTypeUris: string[],
227
227
  types: Record<string, TypeSchema>,
228
228
  ): Iterable<string> {
229
- const entityTypes = sortedTypeUris.filter((typeUri) => types[typeUri].entity)
230
- .map((typeUri) => ({ name: types[typeUri].name, uri: typeUri }));
229
+ const entityTypes = sortedTypeUris.flatMap((typeUri) =>
230
+ types[typeUri].entity ? [{ name: types[typeUri].name, uri: typeUri }] : [],
231
+ );
231
232
  const entityTypeNames = entityTypes.map((entityType) => entityType.name);
232
- const entityTypeUnion = entityTypeNames.length < 1
233
- ? " never"
234
- : `\n | typeof ${entityTypeNames.join("\n | typeof ")}`;
233
+ const entityTypeUnion =
234
+ entityTypeNames.length < 1
235
+ ? " never"
236
+ : `\n | typeof ${entityTypeNames.join("\n | typeof ")}`;
235
237
  yield `/**
236
238
  * Constructor types for all generated vocabulary entity classes.
237
239
  */
@@ -276,9 +278,12 @@ function canContainIriValue(
276
278
  property: PropertySchema,
277
279
  types: Record<string, TypeSchema>,
278
280
  ): boolean {
279
- return property.range.some((typeUri) =>
280
- typeUri === XSD_ANY_URI || typeUri === FEDIFY_URL ||
281
- typeUri === FEDIFY_ABSOLUTE_IRI || types[typeUri]?.entity
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,
282
287
  );
283
288
  }
284
289
 
@@ -317,6 +322,7 @@ export async function* generateClasses(
317
322
  ): AsyncIterable<string> {
318
323
  validateTypeSchemas(types);
319
324
  yield "// deno-lint-ignore-file ban-unused-ignore no-explicit-any no-unused-vars prefer-const verbatim-module-syntax\n";
325
+ yield "// oxlint-disable typescript/no-explicit-any, no-unused-vars, prefer-const\n";
320
326
  yield 'import jsonld from "@fedify/vocab-runtime/jsonld";\n';
321
327
  yield 'import { getLogger } from "@logtape/logtape";\n';
322
328
  yield `import { type Span, SpanStatusCode, type TracerProvider, trace }
@@ -362,8 +368,8 @@ function isValidLanguageTag(language: string): boolean {
362
368
  if (
363
369
  Object.values(types).some((type) =>
364
370
  type.properties.some((property) =>
365
- property.range.includes(FEDIFY_ABSOLUTE_IRI)
366
- )
371
+ property.range.includes(FEDIFY_ABSOLUTE_IRI),
372
+ ),
367
373
  )
368
374
  ) {
369
375
  // An absolute IRI may arrive as an IRI node or, when the publisher's
@@ -403,8 +409,8 @@ function isAbsoluteIriValue(value: unknown): boolean {
403
409
  type.properties.flatMap((property) =>
404
410
  property.extraContext == null
405
411
  ? []
406
- : [[property.uri, property.extraContext]]
407
- )
412
+ : [[property.uri, property.extraContext]],
413
+ ),
408
414
  ),
409
415
  );
410
416
  if (Object.keys(extraContexts).length > 0) {
@@ -455,9 +461,9 @@ function getExtraContexts(document: unknown): string[] {
455
461
  }
456
462
  }
457
463
  yield "const PORTABLE_IRI_PATTERN = /^ap(?:\\+ef61)?:\\/\\//i;\n";
458
- yield `const PORTABLE_IRI_KEYS: ReadonlySet<string> = new Set(${
459
- JSON.stringify([...portableIriKeys].sort())
460
- });\n\n`;
464
+ yield `const PORTABLE_IRI_KEYS: ReadonlySet<string> = new Set(${JSON.stringify(
465
+ [...portableIriKeys].sort(),
466
+ )});\n\n`;
461
467
  const moduleVarNames = new Map<string, string>();
462
468
  const sorted = sortTopologically(types);
463
469
  for (const typeUri of sorted) {