adorn-api 1.0.16 → 1.0.18

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.
@@ -90,11 +90,26 @@ export declare class Spinner {
90
90
  private frames;
91
91
  private interval?;
92
92
  private message;
93
+ private current;
94
+ private total;
95
+ private customStatus?;
93
96
  constructor(message?: string);
94
97
  /**
95
98
  * Start the spinner.
96
99
  */
97
100
  start(): void;
101
+ /**
102
+ * Set progress counters.
103
+ */
104
+ setProgress(current: number, total: number): void;
105
+ /**
106
+ * Set a custom status message (overrides counters).
107
+ */
108
+ setStatus(status: string): void;
109
+ /**
110
+ * Clear the custom status message.
111
+ */
112
+ clearStatus(): void;
98
113
  /**
99
114
  * Stop the spinner with a completion message.
100
115
  */
@@ -1 +1 @@
1
- {"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../../src/cli/progress.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;IACvD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED;;GAEG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAyC;IACvD,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,OAAO,CAAkB;IACjC,OAAO,CAAC,KAAK,CAAkB;IAC/B,OAAO,CAAC,WAAW,CAAa;gBAEpB,OAAO,GAAE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E,MAAM,GAAG,IAAI;IAK1B;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAM7B;;OAEG;IACH,eAAe,IAAI,MAAM;IAIzB;;OAEG;IACH,aAAa,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM;IAW3D;;OAEG;IACH,SAAS,IAAI,aAAa,EAAE;IAI5B;;OAEG;IACH,YAAY,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI;IA6B1C;;OAEG;IACH,cAAc,CAAC,SAAS,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,IAAI;CAWxE;AAED;;GAEG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,MAAM,CAAsD;IACpE,OAAO,CAAC,QAAQ,CAAC,CAAiB;IAClC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,OAAO,CAAa;IAC5B,OAAO,CAAC,KAAK,CAAa;IAC1B,OAAO,CAAC,YAAY,CAAC,CAAS;gBAElB,OAAO,GAAE,MAAW;IAIhC;;OAEG;IACH,KAAK,IAAI,IAAI;IAoBb;;OAEG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAKjD;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAU/B;;OAEG;IACH,WAAW,IAAI,IAAI;IAInB;;OAEG;IACH,IAAI,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI;IAgBrC;;OAEG;IACH,IAAI,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI;CAMnC"}
package/dist/cli.cjs CHANGED
@@ -26,6 +26,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  // src/cli.ts
27
27
  var import_node_fs6 = require("fs");
28
28
  var import_node_path6 = require("path");
29
+ var import_node_url = require("url");
29
30
 
30
31
  // src/compiler/runner/createProgram.ts
31
32
  var import_typescript = __toESM(require("typescript"), 1);
@@ -994,7 +995,7 @@ function handleMetalOrmWrapper(type, ctx) {
994
995
  required: ["id"]
995
996
  };
996
997
  if (wrapperName === "ManyToManyCollection" && typeArgs?.[1]) {
997
- wrapperRel.pivot = typeArgs[1];
998
+ wrapperRel.pivot = ctx.checker.typeToString(typeArgs[1]);
998
999
  }
999
1000
  return {
1000
1001
  type: "array",
@@ -1004,7 +1005,7 @@ function handleMetalOrmWrapper(type, ctx) {
1004
1005
  }
1005
1006
  const items = targetType ? typeToJsonSchema(targetType, ctx) : {};
1006
1007
  if (wrapperName === "ManyToManyCollection" && typeArgs?.[1]) {
1007
- wrapperRel.pivot = typeArgs[1];
1008
+ wrapperRel.pivot = ctx.checker.typeToString(typeArgs[1]);
1008
1009
  }
1009
1010
  return {
1010
1011
  type: "array",
@@ -1590,7 +1591,12 @@ function generateOpenAPI(controllers, checker, options = {}) {
1590
1591
  mode: "response"
1591
1592
  };
1592
1593
  const paths = {};
1593
- for (const controller of controllers) {
1594
+ const { onProgress } = options;
1595
+ for (let i = 0; i < controllers.length; i++) {
1596
+ const controller = controllers[i];
1597
+ if (onProgress) {
1598
+ onProgress(`Processing controller ${controller.className}`, i + 1, controllers.length);
1599
+ }
1594
1600
  for (const operation of controller.operations) {
1595
1601
  const fullPath = convertToOpenApiPath(controller.basePath, operation.path);
1596
1602
  if (!paths[fullPath]) {
@@ -1601,6 +1607,9 @@ function generateOpenAPI(controllers, checker, options = {}) {
1601
1607
  }
1602
1608
  }
1603
1609
  const schemas = Object.fromEntries(components);
1610
+ if (onProgress) {
1611
+ onProgress("Generating and cleaning schemas", controllers.length, controllers.length);
1612
+ }
1604
1613
  cleanupMetalOrmWrappers(schemas, paths);
1605
1614
  return {
1606
1615
  openapi: "3.1.0",
@@ -2390,7 +2399,7 @@ var ProgressTracker = class {
2390
2399
  }
2391
2400
  if (!this.quiet) {
2392
2401
  const elapsed = phase ? this.formatElapsed(phase.startTime, phase.endTime) : "";
2393
- const status = this.verbose ? `\u2713 ${message || name} ${elapsed}` : `\u2713 ${message || name}`;
2402
+ const status = this.verbose ? `\u2713 ${message || name} ${elapsed}` : `\u2713 ${message || name} ${elapsed}`;
2394
2403
  this.log(status);
2395
2404
  }
2396
2405
  }
@@ -2462,7 +2471,6 @@ var ProgressTracker = class {
2462
2471
  */
2463
2472
  printSummary(stats) {
2464
2473
  if (this.quiet) return;
2465
- const totalTime = this.getTotalElapsed();
2466
2474
  this.log("");
2467
2475
  this.log("Build Summary:");
2468
2476
  this.log(` Controllers: ${stats.controllers}`);
@@ -2499,6 +2507,9 @@ var Spinner = class {
2499
2507
  frames = ["\u280B", "\u2819", "\u2839", "\u2838", "\u28B0", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
2500
2508
  interval;
2501
2509
  message;
2510
+ current = 0;
2511
+ total = 0;
2512
+ customStatus;
2502
2513
  constructor(message = "") {
2503
2514
  this.message = message;
2504
2515
  }
@@ -2509,10 +2520,45 @@ var Spinner = class {
2509
2520
  let frameIndex = 0;
2510
2521
  this.interval = setInterval(() => {
2511
2522
  const frame = this.frames[frameIndex];
2512
- import_node_process.default.stdout.write(`\r${frame} ${this.message}`);
2523
+ let output;
2524
+ if (this.customStatus) {
2525
+ output = `\r${frame} ${this.customStatus}`;
2526
+ } else if (this.total > 0) {
2527
+ output = `\r${frame} ${this.message} (${this.current}/${this.total})`;
2528
+ } else {
2529
+ output = `\r${frame} ${this.message}`;
2530
+ }
2531
+ import_node_process.default.stdout.write(output);
2532
+ if (import_node_process.default.stdout.writable) {
2533
+ import_node_process.default.stdout.write("");
2534
+ }
2513
2535
  frameIndex = (frameIndex + 1) % this.frames.length;
2514
2536
  }, 80);
2515
2537
  }
2538
+ /**
2539
+ * Set progress counters.
2540
+ */
2541
+ setProgress(current, total) {
2542
+ this.current = current;
2543
+ this.total = total;
2544
+ }
2545
+ /**
2546
+ * Set a custom status message (overrides counters).
2547
+ */
2548
+ setStatus(status) {
2549
+ this.customStatus = status;
2550
+ const frame = this.frames[this.current];
2551
+ import_node_process.default.stdout.write(`\r${frame} ${status}`);
2552
+ if (import_node_process.default.stdout.writable) {
2553
+ import_node_process.default.stdout.write("");
2554
+ }
2555
+ }
2556
+ /**
2557
+ * Clear the custom status message.
2558
+ */
2559
+ clearStatus() {
2560
+ this.customStatus = void 0;
2561
+ }
2516
2562
  /**
2517
2563
  * Stop the spinner with a completion message.
2518
2564
  */
@@ -2521,10 +2567,13 @@ var Spinner = class {
2521
2567
  clearInterval(this.interval);
2522
2568
  this.interval = void 0;
2523
2569
  }
2524
- import_node_process.default.stdout.write("\r" + " ".repeat(50) + "\r");
2570
+ import_node_process.default.stdout.write("\r" + " ".repeat(60) + "\r");
2525
2571
  if (completedMessage) {
2526
2572
  import_node_process.default.stdout.write(completedMessage + "\n");
2527
2573
  }
2574
+ if (import_node_process.default.stdout.writable) {
2575
+ import_node_process.default.stdout.write("");
2576
+ }
2528
2577
  }
2529
2578
  /**
2530
2579
  * Stop the spinner with a failure message.
@@ -2919,12 +2968,17 @@ function generateModularOpenAPI(openapi, partitioning, config) {
2919
2968
  outputDir,
2920
2969
  schemasDir = "schemas",
2921
2970
  createIndexFile = true,
2922
- prettyPrint = true
2971
+ prettyPrint = true,
2972
+ onProgress
2923
2973
  } = config;
2924
2974
  const indent = prettyPrint ? 2 : 0;
2925
2975
  let totalSize = 0;
2926
2976
  const schemaFiles = [];
2977
+ (0, import_node_fs5.mkdirSync)(outputDir, { recursive: true });
2927
2978
  if (!partitioning.shouldSplit || partitioning.groups.length === 1) {
2979
+ if (onProgress) {
2980
+ onProgress("Writing single OpenAPI file", 1, 1);
2981
+ }
2928
2982
  const mainPath2 = (0, import_node_path5.resolve)(outputDir, "openapi.json");
2929
2983
  (0, import_node_fs5.writeFileSync)(mainPath2, JSON.stringify(openapi, null, indent));
2930
2984
  totalSize = Buffer.byteLength(JSON.stringify(openapi));
@@ -2937,9 +2991,16 @@ function generateModularOpenAPI(openapi, partitioning, config) {
2937
2991
  }
2938
2992
  const schemasPath = (0, import_node_path5.resolve)(outputDir, schemasDir);
2939
2993
  (0, import_node_fs5.mkdirSync)(schemasPath, { recursive: true });
2994
+ if (onProgress) {
2995
+ onProgress("Creating schemas directory", 0, partitioning.groups.length + 2);
2996
+ }
2940
2997
  const schemaMap = collectAllSchemas(partitioning.groups);
2941
2998
  const schemaToFile = /* @__PURE__ */ new Map();
2942
- for (const group of partitioning.groups) {
2999
+ for (let i = 0; i < partitioning.groups.length; i++) {
3000
+ const group = partitioning.groups[i];
3001
+ if (onProgress) {
3002
+ onProgress(`Writing schema group ${group.name} (${group.schemas.size} schemas)`, i + 1, partitioning.groups.length + 2);
3003
+ }
2943
3004
  const filename = getSchemaFilename(group);
2944
3005
  const filePath = (0, import_node_path5.resolve)(outputDir, filename);
2945
3006
  const content = generateSchemaFileContent(group, schemaMap);
@@ -2952,12 +3013,18 @@ function generateModularOpenAPI(openapi, partitioning, config) {
2952
3013
  }
2953
3014
  let indexFile;
2954
3015
  if (createIndexFile) {
3016
+ if (onProgress) {
3017
+ onProgress("Generating index file", partitioning.groups.length + 1, partitioning.groups.length + 2);
3018
+ }
2955
3019
  const indexPath = (0, import_node_path5.resolve)(outputDir, "schemas/index.json");
2956
3020
  const indexContent = generateSchemaIndex(partitioning.groups, schemaMap);
2957
3021
  (0, import_node_fs5.writeFileSync)(indexPath, JSON.stringify(indexContent, null, indent));
2958
3022
  totalSize += Buffer.byteLength(JSON.stringify(indexContent));
2959
3023
  indexFile = indexPath;
2960
3024
  }
3025
+ if (onProgress) {
3026
+ onProgress("Generating main OpenAPI spec", partitioning.groups.length + 2, partitioning.groups.length + 2);
3027
+ }
2961
3028
  const mainSpec = generateMainSpec(openapi, schemaMap, schemaToFile);
2962
3029
  const mainPath = (0, import_node_path5.resolve)(outputDir, "openapi.json");
2963
3030
  (0, import_node_fs5.writeFileSync)(mainPath, JSON.stringify(mainSpec, null, indent));
@@ -3288,7 +3355,28 @@ var SchemaGraph = class {
3288
3355
  // src/cli.ts
3289
3356
  var import_typescript13 = __toESM(require("typescript"), 1);
3290
3357
  var import_node_process2 = __toESM(require("process"), 1);
3291
- var ADORN_VERSION = "0.1.0";
3358
+ var import_meta2 = {};
3359
+ var ADORN_VERSION = (() => {
3360
+ const tryReadPackageJson = (filePath) => {
3361
+ try {
3362
+ const pkg = JSON.parse((0, import_node_fs6.readFileSync)(filePath, "utf-8"));
3363
+ return pkg.version ?? null;
3364
+ } catch {
3365
+ return null;
3366
+ }
3367
+ };
3368
+ const cliDir = (0, import_node_path6.dirname)((0, import_node_url.fileURLToPath)(import_meta2.url));
3369
+ const bundledPkgPath = (0, import_node_path6.resolve)(cliDir, "..", "package.json");
3370
+ const bundledVersion = tryReadPackageJson(bundledPkgPath);
3371
+ if (bundledVersion) return bundledVersion;
3372
+ const localPkgPath = (0, import_node_path6.resolve)(import_node_process2.default.cwd(), "package.json");
3373
+ const localVersion = tryReadPackageJson(localPkgPath);
3374
+ if (localVersion) return localVersion;
3375
+ const nodeModulesPath = (0, import_node_path6.resolve)(cliDir, "..", "package.json");
3376
+ const nodeModulesVersion = tryReadPackageJson(nodeModulesPath);
3377
+ if (nodeModulesVersion) return nodeModulesVersion;
3378
+ return "0.0.0";
3379
+ })();
3292
3380
  function log(msg, options) {
3293
3381
  if (options?.indent) {
3294
3382
  import_node_process2.default.stdout.write(" " + msg + "\n");
@@ -3481,10 +3569,21 @@ async function buildCommand(args) {
3481
3569
  }
3482
3570
  }
3483
3571
  progress.startPhase("openapi", "Generating OpenAPI schema");
3484
- if (verbose) {
3485
- progress.verboseLog("Processing schemas from type definitions");
3572
+ const openapiSpinner = new Spinner("Processing schemas");
3573
+ if (!quiet) openapiSpinner.start();
3574
+ const openapi = generateOpenAPI(controllers, checker, {
3575
+ title: "API",
3576
+ version: "1.0.0",
3577
+ onProgress: (message, current, total) => {
3578
+ if (!quiet) {
3579
+ openapiSpinner.setStatus(`${message} (${current}/${total})`);
3580
+ }
3581
+ }
3582
+ });
3583
+ if (!quiet) {
3584
+ openapiSpinner.setStatus(`Processed ${controllers.length} controllers, ${totalOperations} operations`);
3486
3585
  }
3487
- const openapi = generateOpenAPI(controllers, checker, { title: "API", version: "1.0.0" });
3586
+ if (!quiet) openapiSpinner.stop();
3488
3587
  const schemaCount = Object.keys(openapi.components?.schemas || {}).length;
3489
3588
  let splitEnabled = false;
3490
3589
  if (!noSplit && schemaCount >= splitThreshold) {
@@ -3502,14 +3601,24 @@ async function buildCommand(args) {
3502
3601
  if (splitEnabled) {
3503
3602
  progress.verboseLog(`Partitioning result: ${partitioning.strategy} strategy`);
3504
3603
  progress.verboseLog(`Recommendation: ${partitioning.recommendation}`);
3604
+ if (!quiet) {
3605
+ log(` Auto-split enabled: ${partitioning.strategy} strategy`);
3606
+ }
3607
+ const splitSpinner = new Spinner("Writing split schema files");
3608
+ if (!quiet) splitSpinner.start();
3505
3609
  generateModularOpenAPI(openapi, partitioning, {
3506
3610
  outputDir: outputPath,
3507
3611
  schemasDir: "schemas",
3508
3612
  createIndexFile: true,
3509
- prettyPrint: true
3613
+ prettyPrint: true,
3614
+ onProgress: (step, index, total) => {
3615
+ if (!quiet) {
3616
+ progress.logSub(`${step} (${index}/${total})`);
3617
+ }
3618
+ }
3510
3619
  });
3620
+ if (!quiet) splitSpinner.stop();
3511
3621
  if (!quiet) {
3512
- log(` Auto-split enabled: ${partitioning.strategy} strategy`);
3513
3622
  log(` Schema groups: ${partitioning.groups.length}`);
3514
3623
  }
3515
3624
  } else {