@hey-api/codegen-core 0.5.3 → 0.5.5

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/dist/index.mjs CHANGED
@@ -8,6 +8,53 @@ const fileBrand = "heyapi.file";
8
8
  const nodeBrand = "heyapi.node";
9
9
  const symbolBrand = "heyapi.symbol";
10
10
 
11
+ //#endregion
12
+ //#region src/config/interactive.ts
13
+ /**
14
+ * Detect if the current session is interactive based on TTY status and environment variables.
15
+ * This is used as a fallback when the user doesn't explicitly set the interactive option.
16
+ * @internal
17
+ */
18
+ function detectInteractiveSession() {
19
+ return Boolean(process.stdin.isTTY && process.stdout.isTTY && !process.env.CI && !process.env.NO_INTERACTIVE && !process.env.NO_INTERACTION);
20
+ }
21
+
22
+ //#endregion
23
+ //#region src/config/merge.ts
24
+ function isPlainObject(value) {
25
+ return typeof value === "object" && value !== null && !Array.isArray(value);
26
+ }
27
+ function mergeConfigs(configA, configB) {
28
+ const a = configA || {};
29
+ const b = configB || {};
30
+ const result = { ...a };
31
+ for (const key of Object.keys(b)) {
32
+ const valueA = a[key];
33
+ const valueB = b[key];
34
+ if (isPlainObject(valueA) && isPlainObject(valueB)) result[key] = mergeConfigs(valueA, valueB);
35
+ else result[key] = valueB;
36
+ }
37
+ return result;
38
+ }
39
+
40
+ //#endregion
41
+ //#region src/config/load.ts
42
+ async function loadConfigFile({ configFile, logger, name, userConfig }) {
43
+ const eventC12 = logger.timeEvent("c12");
44
+ const { loadConfig } = await import("c12");
45
+ const { config: fileConfig, configFile: loadedConfigFile } = await loadConfig({
46
+ configFile,
47
+ name
48
+ });
49
+ eventC12.timeEnd();
50
+ const fileConfigs = fileConfig instanceof Array ? fileConfig : [fileConfig];
51
+ return {
52
+ configFile: loadedConfigFile,
53
+ configs: fileConfigs.map((config) => mergeConfigs(config, userConfig)),
54
+ foundConfig: fileConfigs.some((config) => Object.keys(config).length > 0)
55
+ };
56
+ }
57
+
11
58
  //#endregion
12
59
  //#region src/log.ts
13
60
  colors.enabled = colorSupport().hasBasic;
@@ -312,6 +359,144 @@ const defaultNameConflictResolvers = {
312
359
  ruby: underscoreNameConflictResolver
313
360
  };
314
361
 
362
+ //#endregion
363
+ //#region src/logger.ts
364
+ let loggerCounter = 0;
365
+ const nameToId = (name) => `${name}-${loggerCounter++}`;
366
+ const idEnd = (id) => `${id}-end`;
367
+ const idLength = (id) => `${id}-length`;
368
+ const idStart = (id) => `${id}-start`;
369
+ const getSeverity = (duration, percentage) => {
370
+ if (duration > 200) return {
371
+ color: colors.red,
372
+ type: "duration"
373
+ };
374
+ if (percentage > 30) return {
375
+ color: colors.red,
376
+ type: "percentage"
377
+ };
378
+ if (duration > 50) return {
379
+ color: colors.yellow,
380
+ type: "duration"
381
+ };
382
+ if (percentage > 10) return {
383
+ color: colors.yellow,
384
+ type: "percentage"
385
+ };
386
+ };
387
+ var Logger = class {
388
+ events = [];
389
+ end(result) {
390
+ let event;
391
+ let events = this.events;
392
+ for (const index of result.position) {
393
+ event = events[index];
394
+ if (event?.events) events = event.events;
395
+ }
396
+ if (event && !event.end) event.end = performance.mark(idEnd(event.id));
397
+ }
398
+ /**
399
+ * Recursively end all unended events in the event tree.
400
+ * This ensures all events have end marks before measuring.
401
+ */
402
+ endAllEvents(events) {
403
+ for (const event of events) {
404
+ if (!event.end) event.end = performance.mark(idEnd(event.id));
405
+ if (event.events.length > 0) this.endAllEvents(event.events);
406
+ }
407
+ }
408
+ report(print = true) {
409
+ const firstEvent = this.events[0];
410
+ if (!firstEvent) return;
411
+ this.endAllEvents(this.events);
412
+ const lastEvent = this.events[this.events.length - 1];
413
+ const name = "root";
414
+ const id = nameToId(name);
415
+ try {
416
+ const measure = performance.measure(idLength(id), idStart(firstEvent.id), idEnd(lastEvent.id));
417
+ if (print) this.reportEvent({
418
+ end: lastEvent.end,
419
+ events: this.events,
420
+ id,
421
+ indent: 0,
422
+ measure,
423
+ name,
424
+ start: firstEvent.start
425
+ });
426
+ return measure;
427
+ } catch {
428
+ return;
429
+ }
430
+ }
431
+ reportEvent({ indent, ...parent }) {
432
+ const color = !indent ? colors.cyan : colors.gray;
433
+ const lastIndex = parent.events.length - 1;
434
+ parent.events.forEach((event, index) => {
435
+ try {
436
+ const measure = performance.measure(idLength(event.id), idStart(event.id), idEnd(event.id));
437
+ const duration = Math.ceil(measure.duration * 100) / 100;
438
+ const percentage = Math.ceil(measure.duration / parent.measure.duration * 100 * 100) / 100;
439
+ const severity = indent ? getSeverity(duration, percentage) : void 0;
440
+ let durationLabel = `${duration.toFixed(2).padStart(8)}ms`;
441
+ if (severity?.type === "duration") durationLabel = severity.color(durationLabel);
442
+ const branch = index === lastIndex ? "└─ " : "├─ ";
443
+ const prefix = !indent ? "" : "│ ".repeat(indent - 1) + branch;
444
+ const maxLength = 38 - prefix.length;
445
+ const percentageBranch = !indent ? "" : "↳ ";
446
+ let percentageLabel = `${indent ? " ".repeat(indent - 1) + percentageBranch : ""}${percentage.toFixed(2)}%`;
447
+ if (severity?.type === "percentage") percentageLabel = severity.color(percentageLabel);
448
+ const jobPrefix = colors.gray("[root] ");
449
+ console.log(`${jobPrefix}${colors.gray(prefix)}${color(`${event.name.padEnd(maxLength)} ${durationLabel} (${percentageLabel})`)}`);
450
+ this.reportEvent({
451
+ ...event,
452
+ indent: indent + 1,
453
+ measure
454
+ });
455
+ } catch {}
456
+ });
457
+ }
458
+ start(id) {
459
+ return performance.mark(idStart(id));
460
+ }
461
+ storeEvent({ result, ...event }) {
462
+ const lastEventIndex = event.events.length - 1;
463
+ const lastEvent = event.events[lastEventIndex];
464
+ if (lastEvent && !lastEvent.end) {
465
+ result.position = [...result.position, lastEventIndex];
466
+ this.storeEvent({
467
+ ...event,
468
+ events: lastEvent.events,
469
+ result
470
+ });
471
+ return;
472
+ }
473
+ const length = event.events.push({
474
+ ...event,
475
+ events: []
476
+ });
477
+ result.position = [...result.position, length - 1];
478
+ }
479
+ timeEvent(name) {
480
+ const id = nameToId(name);
481
+ const start = this.start(id);
482
+ const event = {
483
+ events: this.events,
484
+ id,
485
+ name,
486
+ start
487
+ };
488
+ const result = { position: [] };
489
+ this.storeEvent({
490
+ ...event,
491
+ result
492
+ });
493
+ return {
494
+ mark: start,
495
+ timeEnd: () => this.end(result)
496
+ };
497
+ }
498
+ };
499
+
315
500
  //#endregion
316
501
  //#region src/files/registry.ts
317
502
  var FileRegistry = class {
@@ -1566,5 +1751,5 @@ var StructureModel = class {
1566
1751
  };
1567
1752
 
1568
1753
  //#endregion
1569
- export { File, Project, StructureModel, StructureNode, Symbol, defaultExtensions, defaultNameConflictResolvers, fromRef, fromRefs, isNode, isNodeRef, isRef, isSymbol, isSymbolRef, log, nodeBrand, ref, refs, simpleNameConflictResolver, symbolBrand, underscoreNameConflictResolver };
1754
+ export { File, Logger, Project, StructureModel, StructureNode, Symbol, defaultExtensions, defaultNameConflictResolvers, detectInteractiveSession, fromRef, fromRefs, isNode, isNodeRef, isRef, isSymbol, isSymbolRef, loadConfigFile, log, mergeConfigs, nodeBrand, ref, refs, simpleNameConflictResolver, symbolBrand, underscoreNameConflictResolver };
1570
1755
  //# sourceMappingURL=index.mjs.map