@fedify/vocab-tools 2.2.0-dev.610 → 2.2.0-dev.622

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.2.0-dev.610+2d418352",
3
+ "version": "2.2.0-dev.622+e54cb037",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./src/mod.ts"
package/dist/mod.cjs CHANGED
@@ -1,70 +1,14 @@
1
- //#region rolldown:runtime
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
- });
15
- }
16
- return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
- value: mod,
20
- enumerable: true
21
- }) : target, mod));
22
-
23
- //#endregion
24
- const node_fs_promises = __toESM(require("node:fs/promises"));
25
- const byte_encodings_base58 = __toESM(require("byte-encodings/base58"));
26
- const __cfworker_json_schema = __toESM(require("@cfworker/json-schema"));
27
- const node_path = __toESM(require("node:path"));
28
- const node_url = __toESM(require("node:url"));
29
- const yaml = __toESM(require("yaml"));
30
- const es_toolkit = __toESM(require("es-toolkit"));
31
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let node_fs_promises = require("node:fs/promises");
3
+ let byte_encodings_base58 = require("byte-encodings/base58");
4
+ let _cfworker_json_schema = require("@cfworker/json-schema");
5
+ let node_path = require("node:path");
6
+ let node_url = require("node:url");
7
+ let yaml = require("yaml");
8
+ let es_toolkit = require("es-toolkit");
32
9
  //#region deno.json
33
10
  var name = "@fedify/vocab-tools";
34
- var version = "2.2.0-dev.610+2d418352";
35
- var license = "MIT";
36
- var exports$1 = { ".": "./src/mod.ts" };
37
- var author = {
38
- "name": "Hong Minhee",
39
- "email": "hong@minhee.org",
40
- "url": "https://hongminhee.org/"
41
- };
42
- var imports = {
43
- "@cfworker/json-schema": "npm:@cfworker/json-schema@^4.1.1",
44
- "yaml": "npm:yaml@^2.8.1"
45
- };
46
- var exclude = [
47
- "dist",
48
- "node_modules",
49
- "src/schema.yaml"
50
- ];
51
- var publish = { "exclude": ["**/*.test.ts", "tsdown.config.ts"] };
52
- var tasks = {
53
- "check": "deno fmt --check && deno lint && deno check src/*.ts",
54
- "test": "deno test -A"
55
- };
56
- var deno_default = {
57
- name,
58
- version,
59
- license,
60
- exports: exports$1,
61
- author,
62
- imports,
63
- exclude,
64
- publish,
65
- tasks
66
- };
67
-
11
+ var version = "2.2.0-dev.622+e54cb037";
68
12
  //#endregion
69
13
  //#region src/type.ts
70
14
  const HEURISTICS_CONTEXTS = [
@@ -498,7 +442,7 @@ function getTypeNames(typeUris, types, parentheses = false) {
498
442
  if (typeUris.length < 1) return "never";
499
443
  else if (typeUris.length === 1) return getTypeName(typeUris[0], types);
500
444
  let typeNames = typeUris.map((typeUri) => getTypeName(typeUri, types));
501
- typeNames = typeNames.filter((t$1, i) => typeNames.indexOf(t$1) === i);
445
+ typeNames = typeNames.filter((t, i) => typeNames.indexOf(t) === i);
502
446
  const t = typeNames.join(" | ");
503
447
  return parentheses && typeNames.length > 1 ? `(${t})` : t;
504
448
  }
@@ -523,10 +467,7 @@ function isCompactableType(typeUri, types) {
523
467
  }
524
468
  function getSubtypes(typeUri, types, excludeSelf = false) {
525
469
  const subtypes = excludeSelf ? [] : [typeUri];
526
- for (const uri in types) {
527
- const type = types[uri];
528
- if (type.extends === typeUri) subtypes.push(...getSubtypes(uri, types));
529
- }
470
+ for (const uri in types) if (types[uri].extends === typeUri) subtypes.push(...getSubtypes(uri, types));
530
471
  return subtypes.filter((t, i) => subtypes.indexOf(t) === i);
531
472
  }
532
473
  function getSupertypes(typeUri, types, excludeSelf = false) {
@@ -596,11 +537,10 @@ function* getDecoders(typeUris, types, variable, optionsVariable, baseUrlVariabl
596
537
  }
597
538
  yield "undefined";
598
539
  }
599
- function emitOverride(typeUri, types) {
540
+ function emitOverride$1(typeUri, types) {
600
541
  if (types[typeUri].extends == null) return "";
601
542
  return "override";
602
543
  }
603
-
604
544
  //#endregion
605
545
  //#region src/field.ts
606
546
  async function getFieldName(propertyUri, prefix = "#") {
@@ -612,20 +552,15 @@ async function getFieldName(propertyUri, prefix = "#") {
612
552
  async function generateField(property, types, prefix = "#") {
613
553
  const fieldName = await getFieldName(property.uri, prefix);
614
554
  if (areAllScalarTypes(property.range, types)) return `${fieldName}: (${getTypeNames(property.range, types, true)})[] = [];\n`;
615
- else {
616
- const typeNames = getTypeNames(property.range, types);
617
- const trustFieldName = await getFieldName(property.uri, `${prefix}_trust`);
618
- return `
619
- ${fieldName}: (${typeNames} | URL)[] = [];
620
- ${trustFieldName}: Set<number> = new Set();
555
+ else return `
556
+ ${fieldName}: (${getTypeNames(property.range, types)} | URL)[] = [];
557
+ ${await getFieldName(property.uri, `${prefix}_trust`)}: Set<number> = new Set();
621
558
  `;
622
- }
623
559
  }
624
560
  async function* generateFields(typeUri, types) {
625
561
  const type = types[typeUri];
626
562
  for (const property of type.properties) yield await generateField(property, types);
627
563
  }
628
-
629
564
  //#endregion
630
565
  //#region src/fs.ts
631
566
  /**
@@ -640,7 +575,6 @@ async function* readDirRecursive(dir) {
640
575
  for await (const subentry of readDirRecursive(path)) yield (0, node_path.join)(entry.name, subentry);
641
576
  } else yield entry.name;
642
577
  }
643
-
644
578
  //#endregion
645
579
  //#region src/schema.ts
646
580
  /**
@@ -698,17 +632,13 @@ async function loadSchemaValidator() {
698
632
  const thisFile = require("url").pathToFileURL(__filename).href;
699
633
  const schemaFile = new URL(node_path.posix.join(node_path.posix.dirname(thisFile), "schema.yaml"));
700
634
  let content;
701
- if (schemaFile.protocol !== "file:") {
702
- const response = await fetch(schemaFile);
703
- content = await response.text();
704
- } else content = await (0, node_fs_promises.readFile)((0, node_url.fileURLToPath)(schemaFile), { encoding: "utf-8" });
705
- const schemaObject = (0, yaml.parse)(content);
706
- return new __cfworker_json_schema.Validator(schemaObject);
635
+ if (schemaFile.protocol !== "file:") content = await (await fetch(schemaFile)).text();
636
+ else content = await (0, node_fs_promises.readFile)((0, node_url.fileURLToPath)(schemaFile), { encoding: "utf-8" });
637
+ return new _cfworker_json_schema.Validator((0, yaml.parse)(content));
707
638
  }
708
639
  let schemaValidator = void 0;
709
640
  async function loadSchema(path) {
710
- const content = await (0, node_fs_promises.readFile)(path, { encoding: "utf-8" });
711
- const schema = (0, yaml.parse)(content);
641
+ const schema = (0, yaml.parse)(await (0, node_fs_promises.readFile)(path, { encoding: "utf-8" }));
712
642
  if (schemaValidator == null) schemaValidator = await loadSchemaValidator();
713
643
  const result = schemaValidator.validate(schema);
714
644
  const errors = [];
@@ -748,7 +678,6 @@ async function loadSchemaFiles(dir) {
748
678
  entries.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
749
679
  return Object.fromEntries(entries);
750
680
  }
751
-
752
681
  //#endregion
753
682
  //#region src/codec.ts
754
683
  async function* generateEncoder(typeUri, types) {
@@ -764,7 +693,7 @@ async function* generateEncoder(typeUri, types) {
764
693
  when \`format\` is set to \`'expand'\`.
765
694
  * @returns The JSON-LD representation of this object.
766
695
  */
767
- ${emitOverride(typeUri, types)} async toJsonLd(options: {
696
+ ${emitOverride$1(typeUri, types)} async toJsonLd(options: {
768
697
  format?: "compact" | "expand",
769
698
  contextLoader?: DocumentLoader,
770
699
  context?: string | Record<string, string> | (string | Record<string, string>)[],
@@ -938,7 +867,7 @@ async function* generateEncoder(typeUri, types) {
938
867
  return compacted;
939
868
  }
940
869
 
941
- protected ${emitOverride(typeUri, types)} isCompactable(): boolean {
870
+ protected ${emitOverride$1(typeUri, types)} isCompactable(): boolean {
942
871
  `;
943
872
  for (const property of type.properties) if (!property.range.every((r) => isCompactableType(r, types))) yield `
944
873
  if (
@@ -965,7 +894,7 @@ async function* generateDecoder(typeUri, types) {
965
894
  * @returns The object of this type.
966
895
  * @throws {TypeError} If the given \`json\` is invalid.
967
896
  */
968
- static ${emitOverride(typeUri, types)} async fromJsonLd(
897
+ static ${emitOverride$1(typeUri, types)} async fromJsonLd(
969
898
  json: unknown,
970
899
  options: {
971
900
  documentLoader?: DocumentLoader,
@@ -976,8 +905,8 @@ async function* generateDecoder(typeUri, types) {
976
905
  ): Promise<${type.name}> {
977
906
  const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
978
907
  const tracer = tracerProvider.getTracer(
979
- ${JSON.stringify(deno_default.name)},
980
- ${JSON.stringify(deno_default.version)},
908
+ ${JSON.stringify(name)},
909
+ ${JSON.stringify(version)},
981
910
  );
982
911
  return await tracer.startActiveSpan(
983
912
  "activitypub.parse_object",
@@ -1141,7 +1070,6 @@ async function* generateDecoder(typeUri, types) {
1141
1070
  }
1142
1071
  `;
1143
1072
  }
1144
-
1145
1073
  //#endregion
1146
1074
  //#region src/constructor.ts
1147
1075
  function generateParameterType(property, types) {
@@ -1210,8 +1138,7 @@ async function* generateConstructor(typeUri, types) {
1210
1138
  if (hasSingularAccessor(property)) {
1211
1139
  let typeGuards = getTypeGuards(property.range, types, `values.${property.singularName}`);
1212
1140
  let typeNames = getTypeNames(property.range, types);
1213
- const scalar = areAllScalarTypes(property.range, types);
1214
- if (!scalar) {
1141
+ if (!areAllScalarTypes(property.range, types)) {
1215
1142
  typeGuards = `${typeGuards} || values.${property.singularName} instanceof URL`;
1216
1143
  typeNames = `${typeNames} | URL`;
1217
1144
  }
@@ -1236,8 +1163,7 @@ async function* generateConstructor(typeUri, types) {
1236
1163
  if (isNonFunctionalProperty(property)) {
1237
1164
  let typeGuards = getTypeGuards(property.range, types, `v`);
1238
1165
  let typeNames = getTypeNames(property.range, types);
1239
- const scalar = areAllScalarTypes(property.range, types);
1240
- if (!scalar) {
1166
+ if (!areAllScalarTypes(property.range, types)) {
1241
1167
  typeGuards = `${typeGuards} || v instanceof URL`;
1242
1168
  typeNames = `${typeNames} | URL`;
1243
1169
  }
@@ -1287,7 +1213,7 @@ async function* generateCloner(typeUri, types) {
1287
1213
  * @param options The options to use for cloning.
1288
1214
  * @returns The cloned instance.
1289
1215
  */
1290
- ${emitOverride(typeUri, types)} clone(
1216
+ ${emitOverride$1(typeUri, types)} clone(
1291
1217
  values:
1292
1218
  `;
1293
1219
  for await (const code of generateParametersType(typeUri, types)) yield code;
@@ -1324,8 +1250,7 @@ async function* generateCloner(typeUri, types) {
1324
1250
  if (hasSingularAccessor(property)) {
1325
1251
  let typeGuards = getTypeGuards(property.range, types, `values.${property.singularName}`);
1326
1252
  let typeNames = getTypeNames(property.range, types);
1327
- const scalar = areAllScalarTypes(property.range, types);
1328
- if (!scalar) {
1253
+ if (!areAllScalarTypes(property.range, types)) {
1329
1254
  typeGuards = `${typeGuards} || values.${property.singularName} instanceof URL`;
1330
1255
  typeNames = `${typeNames} | URL`;
1331
1256
  }
@@ -1350,8 +1275,7 @@ async function* generateCloner(typeUri, types) {
1350
1275
  if (isNonFunctionalProperty(property)) {
1351
1276
  let typeGuards = getTypeGuards(property.range, types, `v`);
1352
1277
  let typeNames = getTypeNames(property.range, types);
1353
- const scalar = areAllScalarTypes(property.range, types);
1354
- if (!scalar) {
1278
+ if (!areAllScalarTypes(property.range, types)) {
1355
1279
  typeGuards = `${typeGuards} || v instanceof URL`;
1356
1280
  typeNames = `${typeNames} | URL`;
1357
1281
  }
@@ -1396,13 +1320,12 @@ async function* generateCloner(typeUri, types) {
1396
1320
  }
1397
1321
  `;
1398
1322
  }
1399
-
1400
1323
  //#endregion
1401
1324
  //#region src/inspector.ts
1402
1325
  async function* generateInspector(typeUri, types) {
1403
1326
  const type = types[typeUri];
1404
1327
  yield `
1405
- protected ${emitOverride(typeUri, types)} _getCustomInspectProxy(): Record<string, unknown> {
1328
+ protected ${emitOverride$1(typeUri, types)} _getCustomInspectProxy(): Record<string, unknown> {
1406
1329
  `;
1407
1330
  if (type.extends == null) yield `
1408
1331
  const proxy: Record<string, unknown> = {};
@@ -1494,12 +1417,10 @@ async function* generateInspectorPostClass(typeUri, types) {
1494
1417
  };
1495
1418
  `;
1496
1419
  }
1497
-
1498
1420
  //#endregion
1499
1421
  //#region src/property.ts
1500
- function emitOverride$1(typeUri, types, property) {
1501
- const type = types[typeUri];
1502
- let supertypeUri = type.extends;
1422
+ function emitOverride(typeUri, types, property) {
1423
+ let supertypeUri = types[typeUri].extends;
1503
1424
  while (supertypeUri != null) {
1504
1425
  const st = types[supertypeUri];
1505
1426
  if (st.properties.find((p) => p.singularName === property.singularName)) return "override";
@@ -1508,7 +1429,7 @@ function emitOverride$1(typeUri, types, property) {
1508
1429
  return "";
1509
1430
  }
1510
1431
  async function* generateProperty(type, property, types) {
1511
- const override = emitOverride$1(type.uri, types, property);
1432
+ const override = emitOverride(type.uri, types, property);
1512
1433
  const doc = `\n/** ${property.description.replaceAll("\n", "\n * ")}\n */\n`;
1513
1434
  if (areAllScalarTypes(property.range, types)) {
1514
1435
  if (hasSingularAccessor(property)) {
@@ -1551,8 +1472,8 @@ async function* generateProperty(type, property, types) {
1551
1472
  const tracerProvider = options.tracerProvider ??
1552
1473
  this._tracerProvider ?? trace.getTracerProvider();
1553
1474
  const tracer = tracerProvider.getTracer(
1554
- ${JSON.stringify(deno_default.name)},
1555
- ${JSON.stringify(deno_default.version)},
1475
+ ${JSON.stringify(name)},
1476
+ ${JSON.stringify(version)},
1556
1477
  );
1557
1478
  return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => {
1558
1479
  let fetchResult: RemoteDocument;
@@ -1644,10 +1565,9 @@ async function* generateProperty(type, property, types) {
1644
1565
  `;
1645
1566
  for (const range of property.range) {
1646
1567
  if (!(range in types)) continue;
1647
- const rangeType = types[range];
1648
1568
  yield `
1649
1569
  try {
1650
- return await ${rangeType.name}.fromJsonLd(
1570
+ return await ${types[range].name}.fromJsonLd(
1651
1571
  jsonLd,
1652
1572
  { documentLoader, contextLoader, tracerProvider, baseUrl },
1653
1573
  );
@@ -1862,7 +1782,6 @@ async function* generateProperties(typeUri, types) {
1862
1782
  const type = types[typeUri];
1863
1783
  for (const property of type.properties) yield* generateProperty(type, property, types);
1864
1784
  }
1865
-
1866
1785
  //#endregion
1867
1786
  //#region src/class.ts
1868
1787
  /**
@@ -1938,7 +1857,7 @@ async function* generateClass(typeUri, types) {
1938
1857
  /**
1939
1858
  * The type URI of {@link ${type.name}}: \`${typeUri}\`.
1940
1859
  */
1941
- static ${emitOverride(typeUri, types)} get typeId(): URL {
1860
+ static ${emitOverride$1(typeUri, types)} get typeId(): URL {
1942
1861
  return new URL(${JSON.stringify(typeUri)});
1943
1862
  }
1944
1863
  `;
@@ -1985,7 +1904,6 @@ async function* generateClasses(types) {
1985
1904
  const sorted = sortTopologically(types);
1986
1905
  for (const typeUri of sorted) for await (const code of generateClass(typeUri, types)) yield code;
1987
1906
  }
1988
-
1989
1907
  //#endregion
1990
1908
  //#region src/generate.ts
1991
1909
  async function generateVocab(schemaDir, generatedPath) {
@@ -2000,8 +1918,7 @@ async function generateVocab(schemaDir, generatedPath) {
2000
1918
  writer.end();
2001
1919
  });
2002
1920
  }
2003
-
2004
1921
  //#endregion
2005
1922
  exports.areAllScalarTypes = areAllScalarTypes;
2006
1923
  exports.generateVocab = generateVocab;
2007
- exports.loadSchemaFiles = loadSchemaFiles;
1924
+ exports.loadSchemaFiles = loadSchemaFiles;
package/dist/mod.d.cts CHANGED
@@ -184,7 +184,6 @@ type TermDefinition = Uri | Record<string, Uri | "@id">;
184
184
  /**
185
185
  * Type guard to check if a property is not functional (has pluralName).
186
186
  */
187
-
188
187
  /**
189
188
  * Loads all schema files in the directory.
190
189
  * @param dir The path of the directory to load schema files from.
@@ -197,4 +196,4 @@ declare function loadSchemaFiles(dir: string): Promise<Record<string, TypeSchema
197
196
  //#region src/type.d.ts
198
197
  declare function areAllScalarTypes(typeUris: string[], types: Record<string, TypeSchema>): boolean;
199
198
  //#endregion
200
- export { PropertySchema, TypeSchema, areAllScalarTypes, generateVocab, loadSchemaFiles };
199
+ export { type PropertySchema, type TypeSchema, areAllScalarTypes, generateVocab, loadSchemaFiles };
package/dist/mod.d.ts CHANGED
@@ -184,7 +184,6 @@ type TermDefinition = Uri | Record<string, Uri | "@id">;
184
184
  /**
185
185
  * Type guard to check if a property is not functional (has pluralName).
186
186
  */
187
-
188
187
  /**
189
188
  * Loads all schema files in the directory.
190
189
  * @param dir The path of the directory to load schema files from.
@@ -197,4 +196,4 @@ declare function loadSchemaFiles(dir: string): Promise<Record<string, TypeSchema
197
196
  //#region src/type.d.ts
198
197
  declare function areAllScalarTypes(typeUris: string[], types: Record<string, TypeSchema>): boolean;
199
198
  //#endregion
200
- export { PropertySchema, TypeSchema, areAllScalarTypes, generateVocab, loadSchemaFiles };
199
+ export { type PropertySchema, type TypeSchema, areAllScalarTypes, generateVocab, loadSchemaFiles };
package/dist/mod.js CHANGED
@@ -5,43 +5,9 @@ import { join, posix } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import { parse } from "yaml";
7
7
  import { pascalCase } from "es-toolkit";
8
-
9
8
  //#region deno.json
10
9
  var name = "@fedify/vocab-tools";
11
- var version = "2.2.0-dev.610+2d418352";
12
- var license = "MIT";
13
- var exports = { ".": "./src/mod.ts" };
14
- var author = {
15
- "name": "Hong Minhee",
16
- "email": "hong@minhee.org",
17
- "url": "https://hongminhee.org/"
18
- };
19
- var imports = {
20
- "@cfworker/json-schema": "npm:@cfworker/json-schema@^4.1.1",
21
- "yaml": "npm:yaml@^2.8.1"
22
- };
23
- var exclude = [
24
- "dist",
25
- "node_modules",
26
- "src/schema.yaml"
27
- ];
28
- var publish = { "exclude": ["**/*.test.ts", "tsdown.config.ts"] };
29
- var tasks = {
30
- "check": "deno fmt --check && deno lint && deno check src/*.ts",
31
- "test": "deno test -A"
32
- };
33
- var deno_default = {
34
- name,
35
- version,
36
- license,
37
- exports,
38
- author,
39
- imports,
40
- exclude,
41
- publish,
42
- tasks
43
- };
44
-
10
+ var version = "2.2.0-dev.622+e54cb037";
45
11
  //#endregion
46
12
  //#region src/type.ts
47
13
  const HEURISTICS_CONTEXTS = [
@@ -475,7 +441,7 @@ function getTypeNames(typeUris, types, parentheses = false) {
475
441
  if (typeUris.length < 1) return "never";
476
442
  else if (typeUris.length === 1) return getTypeName(typeUris[0], types);
477
443
  let typeNames = typeUris.map((typeUri) => getTypeName(typeUri, types));
478
- typeNames = typeNames.filter((t$1, i) => typeNames.indexOf(t$1) === i);
444
+ typeNames = typeNames.filter((t, i) => typeNames.indexOf(t) === i);
479
445
  const t = typeNames.join(" | ");
480
446
  return parentheses && typeNames.length > 1 ? `(${t})` : t;
481
447
  }
@@ -500,10 +466,7 @@ function isCompactableType(typeUri, types) {
500
466
  }
501
467
  function getSubtypes(typeUri, types, excludeSelf = false) {
502
468
  const subtypes = excludeSelf ? [] : [typeUri];
503
- for (const uri in types) {
504
- const type = types[uri];
505
- if (type.extends === typeUri) subtypes.push(...getSubtypes(uri, types));
506
- }
469
+ for (const uri in types) if (types[uri].extends === typeUri) subtypes.push(...getSubtypes(uri, types));
507
470
  return subtypes.filter((t, i) => subtypes.indexOf(t) === i);
508
471
  }
509
472
  function getSupertypes(typeUri, types, excludeSelf = false) {
@@ -573,11 +536,10 @@ function* getDecoders(typeUris, types, variable, optionsVariable, baseUrlVariabl
573
536
  }
574
537
  yield "undefined";
575
538
  }
576
- function emitOverride(typeUri, types) {
539
+ function emitOverride$1(typeUri, types) {
577
540
  if (types[typeUri].extends == null) return "";
578
541
  return "override";
579
542
  }
580
-
581
543
  //#endregion
582
544
  //#region src/field.ts
583
545
  async function getFieldName(propertyUri, prefix = "#") {
@@ -589,20 +551,15 @@ async function getFieldName(propertyUri, prefix = "#") {
589
551
  async function generateField(property, types, prefix = "#") {
590
552
  const fieldName = await getFieldName(property.uri, prefix);
591
553
  if (areAllScalarTypes(property.range, types)) return `${fieldName}: (${getTypeNames(property.range, types, true)})[] = [];\n`;
592
- else {
593
- const typeNames = getTypeNames(property.range, types);
594
- const trustFieldName = await getFieldName(property.uri, `${prefix}_trust`);
595
- return `
596
- ${fieldName}: (${typeNames} | URL)[] = [];
597
- ${trustFieldName}: Set<number> = new Set();
554
+ else return `
555
+ ${fieldName}: (${getTypeNames(property.range, types)} | URL)[] = [];
556
+ ${await getFieldName(property.uri, `${prefix}_trust`)}: Set<number> = new Set();
598
557
  `;
599
- }
600
558
  }
601
559
  async function* generateFields(typeUri, types) {
602
560
  const type = types[typeUri];
603
561
  for (const property of type.properties) yield await generateField(property, types);
604
562
  }
605
-
606
563
  //#endregion
607
564
  //#region src/fs.ts
608
565
  /**
@@ -617,7 +574,6 @@ async function* readDirRecursive(dir) {
617
574
  for await (const subentry of readDirRecursive(path)) yield join(entry.name, subentry);
618
575
  } else yield entry.name;
619
576
  }
620
-
621
577
  //#endregion
622
578
  //#region src/schema.ts
623
579
  /**
@@ -675,17 +631,13 @@ async function loadSchemaValidator() {
675
631
  const thisFile = import.meta.url;
676
632
  const schemaFile = new URL(posix.join(posix.dirname(thisFile), "schema.yaml"));
677
633
  let content;
678
- if (schemaFile.protocol !== "file:") {
679
- const response = await fetch(schemaFile);
680
- content = await response.text();
681
- } else content = await readFile(fileURLToPath(schemaFile), { encoding: "utf-8" });
682
- const schemaObject = parse(content);
683
- return new Validator(schemaObject);
634
+ if (schemaFile.protocol !== "file:") content = await (await fetch(schemaFile)).text();
635
+ else content = await readFile(fileURLToPath(schemaFile), { encoding: "utf-8" });
636
+ return new Validator(parse(content));
684
637
  }
685
638
  let schemaValidator = void 0;
686
639
  async function loadSchema(path) {
687
- const content = await readFile(path, { encoding: "utf-8" });
688
- const schema = parse(content);
640
+ const schema = parse(await readFile(path, { encoding: "utf-8" }));
689
641
  if (schemaValidator == null) schemaValidator = await loadSchemaValidator();
690
642
  const result = schemaValidator.validate(schema);
691
643
  const errors = [];
@@ -725,7 +677,6 @@ async function loadSchemaFiles(dir) {
725
677
  entries.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
726
678
  return Object.fromEntries(entries);
727
679
  }
728
-
729
680
  //#endregion
730
681
  //#region src/codec.ts
731
682
  async function* generateEncoder(typeUri, types) {
@@ -741,7 +692,7 @@ async function* generateEncoder(typeUri, types) {
741
692
  when \`format\` is set to \`'expand'\`.
742
693
  * @returns The JSON-LD representation of this object.
743
694
  */
744
- ${emitOverride(typeUri, types)} async toJsonLd(options: {
695
+ ${emitOverride$1(typeUri, types)} async toJsonLd(options: {
745
696
  format?: "compact" | "expand",
746
697
  contextLoader?: DocumentLoader,
747
698
  context?: string | Record<string, string> | (string | Record<string, string>)[],
@@ -915,7 +866,7 @@ async function* generateEncoder(typeUri, types) {
915
866
  return compacted;
916
867
  }
917
868
 
918
- protected ${emitOverride(typeUri, types)} isCompactable(): boolean {
869
+ protected ${emitOverride$1(typeUri, types)} isCompactable(): boolean {
919
870
  `;
920
871
  for (const property of type.properties) if (!property.range.every((r) => isCompactableType(r, types))) yield `
921
872
  if (
@@ -942,7 +893,7 @@ async function* generateDecoder(typeUri, types) {
942
893
  * @returns The object of this type.
943
894
  * @throws {TypeError} If the given \`json\` is invalid.
944
895
  */
945
- static ${emitOverride(typeUri, types)} async fromJsonLd(
896
+ static ${emitOverride$1(typeUri, types)} async fromJsonLd(
946
897
  json: unknown,
947
898
  options: {
948
899
  documentLoader?: DocumentLoader,
@@ -953,8 +904,8 @@ async function* generateDecoder(typeUri, types) {
953
904
  ): Promise<${type.name}> {
954
905
  const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
955
906
  const tracer = tracerProvider.getTracer(
956
- ${JSON.stringify(deno_default.name)},
957
- ${JSON.stringify(deno_default.version)},
907
+ ${JSON.stringify(name)},
908
+ ${JSON.stringify(version)},
958
909
  );
959
910
  return await tracer.startActiveSpan(
960
911
  "activitypub.parse_object",
@@ -1118,7 +1069,6 @@ async function* generateDecoder(typeUri, types) {
1118
1069
  }
1119
1070
  `;
1120
1071
  }
1121
-
1122
1072
  //#endregion
1123
1073
  //#region src/constructor.ts
1124
1074
  function generateParameterType(property, types) {
@@ -1187,8 +1137,7 @@ async function* generateConstructor(typeUri, types) {
1187
1137
  if (hasSingularAccessor(property)) {
1188
1138
  let typeGuards = getTypeGuards(property.range, types, `values.${property.singularName}`);
1189
1139
  let typeNames = getTypeNames(property.range, types);
1190
- const scalar = areAllScalarTypes(property.range, types);
1191
- if (!scalar) {
1140
+ if (!areAllScalarTypes(property.range, types)) {
1192
1141
  typeGuards = `${typeGuards} || values.${property.singularName} instanceof URL`;
1193
1142
  typeNames = `${typeNames} | URL`;
1194
1143
  }
@@ -1213,8 +1162,7 @@ async function* generateConstructor(typeUri, types) {
1213
1162
  if (isNonFunctionalProperty(property)) {
1214
1163
  let typeGuards = getTypeGuards(property.range, types, `v`);
1215
1164
  let typeNames = getTypeNames(property.range, types);
1216
- const scalar = areAllScalarTypes(property.range, types);
1217
- if (!scalar) {
1165
+ if (!areAllScalarTypes(property.range, types)) {
1218
1166
  typeGuards = `${typeGuards} || v instanceof URL`;
1219
1167
  typeNames = `${typeNames} | URL`;
1220
1168
  }
@@ -1264,7 +1212,7 @@ async function* generateCloner(typeUri, types) {
1264
1212
  * @param options The options to use for cloning.
1265
1213
  * @returns The cloned instance.
1266
1214
  */
1267
- ${emitOverride(typeUri, types)} clone(
1215
+ ${emitOverride$1(typeUri, types)} clone(
1268
1216
  values:
1269
1217
  `;
1270
1218
  for await (const code of generateParametersType(typeUri, types)) yield code;
@@ -1301,8 +1249,7 @@ async function* generateCloner(typeUri, types) {
1301
1249
  if (hasSingularAccessor(property)) {
1302
1250
  let typeGuards = getTypeGuards(property.range, types, `values.${property.singularName}`);
1303
1251
  let typeNames = getTypeNames(property.range, types);
1304
- const scalar = areAllScalarTypes(property.range, types);
1305
- if (!scalar) {
1252
+ if (!areAllScalarTypes(property.range, types)) {
1306
1253
  typeGuards = `${typeGuards} || values.${property.singularName} instanceof URL`;
1307
1254
  typeNames = `${typeNames} | URL`;
1308
1255
  }
@@ -1327,8 +1274,7 @@ async function* generateCloner(typeUri, types) {
1327
1274
  if (isNonFunctionalProperty(property)) {
1328
1275
  let typeGuards = getTypeGuards(property.range, types, `v`);
1329
1276
  let typeNames = getTypeNames(property.range, types);
1330
- const scalar = areAllScalarTypes(property.range, types);
1331
- if (!scalar) {
1277
+ if (!areAllScalarTypes(property.range, types)) {
1332
1278
  typeGuards = `${typeGuards} || v instanceof URL`;
1333
1279
  typeNames = `${typeNames} | URL`;
1334
1280
  }
@@ -1373,13 +1319,12 @@ async function* generateCloner(typeUri, types) {
1373
1319
  }
1374
1320
  `;
1375
1321
  }
1376
-
1377
1322
  //#endregion
1378
1323
  //#region src/inspector.ts
1379
1324
  async function* generateInspector(typeUri, types) {
1380
1325
  const type = types[typeUri];
1381
1326
  yield `
1382
- protected ${emitOverride(typeUri, types)} _getCustomInspectProxy(): Record<string, unknown> {
1327
+ protected ${emitOverride$1(typeUri, types)} _getCustomInspectProxy(): Record<string, unknown> {
1383
1328
  `;
1384
1329
  if (type.extends == null) yield `
1385
1330
  const proxy: Record<string, unknown> = {};
@@ -1471,12 +1416,10 @@ async function* generateInspectorPostClass(typeUri, types) {
1471
1416
  };
1472
1417
  `;
1473
1418
  }
1474
-
1475
1419
  //#endregion
1476
1420
  //#region src/property.ts
1477
- function emitOverride$1(typeUri, types, property) {
1478
- const type = types[typeUri];
1479
- let supertypeUri = type.extends;
1421
+ function emitOverride(typeUri, types, property) {
1422
+ let supertypeUri = types[typeUri].extends;
1480
1423
  while (supertypeUri != null) {
1481
1424
  const st = types[supertypeUri];
1482
1425
  if (st.properties.find((p) => p.singularName === property.singularName)) return "override";
@@ -1485,7 +1428,7 @@ function emitOverride$1(typeUri, types, property) {
1485
1428
  return "";
1486
1429
  }
1487
1430
  async function* generateProperty(type, property, types) {
1488
- const override = emitOverride$1(type.uri, types, property);
1431
+ const override = emitOverride(type.uri, types, property);
1489
1432
  const doc = `\n/** ${property.description.replaceAll("\n", "\n * ")}\n */\n`;
1490
1433
  if (areAllScalarTypes(property.range, types)) {
1491
1434
  if (hasSingularAccessor(property)) {
@@ -1528,8 +1471,8 @@ async function* generateProperty(type, property, types) {
1528
1471
  const tracerProvider = options.tracerProvider ??
1529
1472
  this._tracerProvider ?? trace.getTracerProvider();
1530
1473
  const tracer = tracerProvider.getTracer(
1531
- ${JSON.stringify(deno_default.name)},
1532
- ${JSON.stringify(deno_default.version)},
1474
+ ${JSON.stringify(name)},
1475
+ ${JSON.stringify(version)},
1533
1476
  );
1534
1477
  return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => {
1535
1478
  let fetchResult: RemoteDocument;
@@ -1621,10 +1564,9 @@ async function* generateProperty(type, property, types) {
1621
1564
  `;
1622
1565
  for (const range of property.range) {
1623
1566
  if (!(range in types)) continue;
1624
- const rangeType = types[range];
1625
1567
  yield `
1626
1568
  try {
1627
- return await ${rangeType.name}.fromJsonLd(
1569
+ return await ${types[range].name}.fromJsonLd(
1628
1570
  jsonLd,
1629
1571
  { documentLoader, contextLoader, tracerProvider, baseUrl },
1630
1572
  );
@@ -1839,7 +1781,6 @@ async function* generateProperties(typeUri, types) {
1839
1781
  const type = types[typeUri];
1840
1782
  for (const property of type.properties) yield* generateProperty(type, property, types);
1841
1783
  }
1842
-
1843
1784
  //#endregion
1844
1785
  //#region src/class.ts
1845
1786
  /**
@@ -1915,7 +1856,7 @@ async function* generateClass(typeUri, types) {
1915
1856
  /**
1916
1857
  * The type URI of {@link ${type.name}}: \`${typeUri}\`.
1917
1858
  */
1918
- static ${emitOverride(typeUri, types)} get typeId(): URL {
1859
+ static ${emitOverride$1(typeUri, types)} get typeId(): URL {
1919
1860
  return new URL(${JSON.stringify(typeUri)});
1920
1861
  }
1921
1862
  `;
@@ -1962,7 +1903,6 @@ async function* generateClasses(types) {
1962
1903
  const sorted = sortTopologically(types);
1963
1904
  for (const typeUri of sorted) for await (const code of generateClass(typeUri, types)) yield code;
1964
1905
  }
1965
-
1966
1906
  //#endregion
1967
1907
  //#region src/generate.ts
1968
1908
  async function generateVocab(schemaDir, generatedPath) {
@@ -1977,6 +1917,5 @@ async function generateVocab(schemaDir, generatedPath) {
1977
1917
  writer.end();
1978
1918
  });
1979
1919
  }
1980
-
1981
1920
  //#endregion
1982
- export { areAllScalarTypes, generateVocab, loadSchemaFiles };
1921
+ export { areAllScalarTypes, generateVocab, loadSchemaFiles };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/vocab-tools",
3
- "version": "2.2.0-dev.610+2d418352",
3
+ "version": "2.2.0-dev.622+e54cb037",
4
4
  "description": "Code generator for Activity Vocabulary APIs",
5
5
  "homepage": "https://fedify.dev/",
6
6
  "repository": {
@@ -50,8 +50,8 @@
50
50
  "license": "MIT",
51
51
  "devDependencies": {
52
52
  "@types/node": "^22.17.0",
53
- "tsdown": "^0.12.9",
54
- "typescript": "^5.9.3"
53
+ "tsdown": "^0.21.6",
54
+ "typescript": "^5.9.2"
55
55
  },
56
56
  "dependencies": {
57
57
  "@cfworker/json-schema": "^4.1.1",
package/tsdown.config.ts CHANGED
@@ -13,7 +13,7 @@ export default defineConfig({
13
13
  await cp(
14
14
  join("src", "schema.yaml"),
15
15
  join(ctx.options.outDir, "schema.yaml"),
16
- { force: true },
16
+ { force: false, errorOnExist: false },
17
17
  );
18
18
  },
19
19
  },