@cardenelabs/cdl 0.80.0 → 0.81.0

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.d.cts CHANGED
@@ -1723,8 +1723,17 @@ interface SweepReport {
1723
1723
  profile: ValidationProfile;
1724
1724
  /** 用途によって見なかった軸。 `totalCounts` はこれらも 0 を返す。 */
1725
1725
  skippedAxes: VisualAxis[];
1726
+ /**
1727
+ * 速さを何で測ったか (`#897`)。
1728
+ *
1729
+ * 超過した時だけ文面に出すと、超過していない周では測り方が分からない。 呼ぶ側が
1730
+ * 「CPU 時間で測れているか」 を常に確かめられるように、超過の有無と切り離して返す。
1731
+ */
1732
+ perfClock: PerfClockKind;
1726
1733
  }
1727
1734
  declare function visualValidateAll(diagrams: CdlDiagram[], opts?: ValidateOptions): SweepReport;
1735
+ /** 時間を何で測ったか。 超過の文面に出して、黙って別の物を測らないようにする。 */
1736
+ type PerfClockKind = "cpu" | "wall";
1728
1737
 
1729
1738
  /**
1730
1739
  * 関係から lane と stack の並びを決める (#599)。
package/dist/index.d.ts CHANGED
@@ -1723,8 +1723,17 @@ interface SweepReport {
1723
1723
  profile: ValidationProfile;
1724
1724
  /** 用途によって見なかった軸。 `totalCounts` はこれらも 0 を返す。 */
1725
1725
  skippedAxes: VisualAxis[];
1726
+ /**
1727
+ * 速さを何で測ったか (`#897`)。
1728
+ *
1729
+ * 超過した時だけ文面に出すと、超過していない周では測り方が分からない。 呼ぶ側が
1730
+ * 「CPU 時間で測れているか」 を常に確かめられるように、超過の有無と切り離して返す。
1731
+ */
1732
+ perfClock: PerfClockKind;
1726
1733
  }
1727
1734
  declare function visualValidateAll(diagrams: CdlDiagram[], opts?: ValidateOptions): SweepReport;
1735
+ /** 時間を何で測ったか。 超過の文面に出して、黙って別の物を測らないようにする。 */
1736
+ type PerfClockKind = "cpu" | "wall";
1728
1737
 
1729
1738
  /**
1730
1739
  * 関係から lane と stack の並びを決める (#599)。
package/dist/index.js CHANGED
@@ -18409,11 +18409,12 @@ function runAxes(laid, diag, violations, counts, push, profile, skippedAxes, \u5
18409
18409
  }
18410
18410
  function visualValidateAll(diagrams, opts) {
18411
18411
  \u5668\u3092\u78BA\u304B\u3081\u308B(opts?.container);
18412
+ const \u6642\u8A08 = perfClock();
18412
18413
  const durations = [];
18413
18414
  const reports = diagrams.map((d) => {
18414
- const start = Date.now();
18415
+ const \u6B62\u3081\u308B = \u6642\u8A08.\u6E2C\u308B();
18415
18416
  const r = visualValidate(d, opts);
18416
- durations.push(Date.now() - start);
18417
+ durations.push(\u6B62\u3081\u308B());
18417
18418
  return r;
18418
18419
  });
18419
18420
  const fail = reports.filter((r) => !r.ok).length;
@@ -18423,7 +18424,7 @@ function visualValidateAll(diagrams, opts) {
18423
18424
  totalCounts[axis] += r.counts[axis];
18424
18425
  }
18425
18426
  }
18426
- const metaViolations = validateMetaAxes(totalCounts, diagrams, durations, reports);
18427
+ const metaViolations = validateMetaAxes(totalCounts, diagrams, durations, reports, \u6642\u8A08.kind);
18427
18428
  return {
18428
18429
  total: reports.length,
18429
18430
  pass: reports.length - fail,
@@ -18432,12 +18433,35 @@ function visualValidateAll(diagrams, opts) {
18432
18433
  totalCounts,
18433
18434
  profile: opts?.profile ?? "production",
18434
18435
  skippedAxes: [...SKIPPED_AXES[opts?.profile ?? "production"]],
18435
- metaViolations
18436
+ metaViolations,
18437
+ perfClock: \u6642\u8A08.kind
18436
18438
  };
18437
18439
  }
18438
18440
  var PERF_BUDGET_TOTAL_MS = 5e3;
18441
+ function perfClock() {
18442
+ const cpu = globalThis.process?.cpuUsage;
18443
+ if (typeof cpu === "function") {
18444
+ return {
18445
+ kind: "cpu",
18446
+ \u6E2C\u308B: () => {
18447
+ const \u59CB\u3081 = cpu();
18448
+ return () => {
18449
+ const \u5DEE = cpu(\u59CB\u3081);
18450
+ return (\u5DEE.user + \u5DEE.system) / 1e3;
18451
+ };
18452
+ }
18453
+ };
18454
+ }
18455
+ return {
18456
+ kind: "wall",
18457
+ \u6E2C\u308B: () => {
18458
+ const \u59CB\u3081 = Date.now();
18459
+ return () => Date.now() - \u59CB\u3081;
18460
+ }
18461
+ };
18462
+ }
18439
18463
  var PERF_SLOWEST_SAMPLE = 5;
18440
- function perfBudgetViolations(durations, diagrams = []) {
18464
+ function perfBudgetViolations(durations, diagrams = [], clock) {
18441
18465
  const total = durations.reduce((s, d) => s + d, 0);
18442
18466
  if (total <= PERF_BUDGET_TOTAL_MS) return [];
18443
18467
  const \u91CD\u3044\u9806 = durations.map((ms, i) => ({ id: diagrams[i]?.id ?? "?", ms })).sort((a, b) => b.ms - a.ms);
@@ -18448,12 +18472,13 @@ function perfBudgetViolations(durations, diagrams = []) {
18448
18472
  {
18449
18473
  axis: "validate-performance-budget",
18450
18474
  diagramId: "__meta__",
18451
- detail: `visualValidateAll \u5168 ${durations.length} \u56F3\u306E\u7D2F\u8A08 ${total}ms > ${PERF_BUDGET_TOTAL_MS}ms budget (\u91CD\u3044\u9806 ${\u5185\u8A33})`,
18475
+ detail: `visualValidateAll \u5168 ${durations.length} \u56F3\u306E\u7D2F\u8A08 ${total}ms > ${PERF_BUDGET_TOTAL_MS}ms budget (\u91CD\u3044\u9806 ${\u5185\u8A33})` + // 測り方が変わったのに同じ顔で報告すると、読み手が 2 つの値を同じものとして並べる
18476
+ (clock === void 0 ? "" : `\u3001 \u6E2C\u308A\u65B9 ${clock === "cpu" ? "CPU \u6642\u9593" : "\u58C1\u6642\u8A08 (CPU \u6642\u9593\u304C\u8AAD\u3081\u306A\u3044)"}`),
18452
18477
  severity: "warn"
18453
18478
  }
18454
18479
  ];
18455
18480
  }
18456
- function validateMetaAxes(totalCounts, diagrams = [], durations = [], reports = []) {
18481
+ function validateMetaAxes(totalCounts, diagrams = [], durations = [], reports = [], clock) {
18457
18482
  const out = [];
18458
18483
  const totalErrors = reports.reduce(
18459
18484
  (sum, r) => sum + r.violations.filter((v) => v.severity === "error").length,
@@ -18468,7 +18493,7 @@ function validateMetaAxes(totalCounts, diagrams = [], durations = [], reports =
18468
18493
  severity: "warn"
18469
18494
  });
18470
18495
  }
18471
- out.push(...perfBudgetViolations(durations, diagrams));
18496
+ out.push(...perfBudgetViolations(durations, diagrams, clock));
18472
18497
  const DEAD_ALLOWLIST = [
18473
18498
  // catalog で自然発火なしを許容する security / migration / performance / meta / dev-quality axis 群。
18474
18499
  // 実 diagram に該当データ (XSS / migration list / oversized / broken doc) が混入するのが稀なため。