@pattern-stack/codegen 0.14.0 → 0.14.1

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.
Files changed (30) hide show
  1. package/dist/runtime/subsystems/bridge/bridge-delivery.memory-backend.d.ts +1 -1
  2. package/dist/runtime/subsystems/bridge/bridge-delivery.memory-backend.js +2 -2
  3. package/dist/runtime/subsystems/bridge/bridge-delivery.memory-backend.js.map +1 -1
  4. package/dist/runtime/subsystems/bridge/bridge.module.js +172 -159
  5. package/dist/runtime/subsystems/bridge/bridge.module.js.map +1 -1
  6. package/dist/runtime/subsystems/bridge/index.js +154 -141
  7. package/dist/runtime/subsystems/bridge/index.js.map +1 -1
  8. package/dist/runtime/subsystems/index.js +161 -148
  9. package/dist/runtime/subsystems/index.js.map +1 -1
  10. package/dist/runtime/subsystems/jobs/index.js +128 -115
  11. package/dist/runtime/subsystems/jobs/index.js.map +1 -1
  12. package/dist/runtime/subsystems/jobs/job-orchestrator.memory-backend.js +128 -6
  13. package/dist/runtime/subsystems/jobs/job-orchestrator.memory-backend.js.map +1 -1
  14. package/dist/runtime/subsystems/jobs/job-run-service.memory-backend.js +17 -0
  15. package/dist/runtime/subsystems/jobs/job-run-service.memory-backend.js.map +1 -1
  16. package/dist/runtime/subsystems/jobs/job-step-service.memory-backend.js +25 -2
  17. package/dist/runtime/subsystems/jobs/job-step-service.memory-backend.js.map +1 -1
  18. package/dist/runtime/subsystems/jobs/job-worker.module.d.ts +26 -1
  19. package/dist/runtime/subsystems/jobs/job-worker.module.js +150 -137
  20. package/dist/runtime/subsystems/jobs/job-worker.module.js.map +1 -1
  21. package/dist/runtime/subsystems/jobs/jobs-domain.module.js +133 -124
  22. package/dist/runtime/subsystems/jobs/jobs-domain.module.js.map +1 -1
  23. package/dist/src/cli/index.js +804 -454
  24. package/dist/src/cli/index.js.map +1 -1
  25. package/package.json +1 -1
  26. package/runtime/subsystems/bridge/bridge-delivery.memory-backend.ts +8 -1
  27. package/runtime/subsystems/jobs/job-orchestrator.memory-backend.ts +8 -3
  28. package/runtime/subsystems/jobs/job-run-service.memory-backend.ts +4 -1
  29. package/runtime/subsystems/jobs/job-step-service.memory-backend.ts +7 -2
  30. package/runtime/subsystems/jobs/job-worker.module.ts +13 -1
@@ -442,11 +442,11 @@ var MemoryBridgeDeliveryRepo = class {
442
442
  * Unlike `insertDelivery`, this read does NOT call `assertTenantId`:
443
443
  * `tenantId === undefined` is the supported cross-tenant admin view.
444
444
  */
445
- async getStatusHistogram(windowHours, tenantId) {
445
+ async getStatusHistogram(windowHours, tenantId, nowMs = Date.now()) {
446
446
  if (!Number.isFinite(windowHours) || windowHours <= 0) {
447
447
  throw new RangeError("windowHours must be positive");
448
448
  }
449
- const cutoffMs = Date.now() - windowHours * 36e5;
449
+ const cutoffMs = nowMs - windowHours * 36e5;
450
450
  const histogram = {
451
451
  pending: 0,
452
452
  delivered: 0,
@@ -938,19 +938,20 @@ EventFlowService = __decorateClass([
938
938
 
939
939
  // runtime/subsystems/bridge/bridge.module.ts
940
940
  import {
941
- Inject as Inject12,
941
+ Inject as Inject13,
942
942
  Module as Module3,
943
943
  Optional as Optional7
944
944
  } from "@nestjs/common";
945
945
 
946
946
  // runtime/subsystems/jobs/job-worker.module.ts
947
947
  import {
948
- Inject as Inject11,
948
+ Inject as Inject12,
949
949
  Injectable as Injectable12,
950
950
  Logger as Logger6,
951
951
  Module as Module2,
952
952
  Optional as Optional6
953
953
  } from "@nestjs/common";
954
+ import { ModuleRef as ModuleRef2 } from "@nestjs/core";
954
955
 
955
956
  // runtime/subsystems/jobs/jobs-domain.module.ts
956
957
  import { Module } from "@nestjs/common";
@@ -1635,8 +1636,129 @@ DrizzleJobStepService = __decorateClass([
1635
1636
  ], DrizzleJobStepService);
1636
1637
 
1637
1638
  // runtime/subsystems/jobs/job-orchestrator.memory-backend.ts
1639
+ import { randomUUID as randomUUID5 } from "crypto";
1640
+ import { Inject as Inject9, Injectable as Injectable9, Logger as Logger4, Optional as Optional5 } from "@nestjs/common";
1641
+ import { ModuleRef } from "@nestjs/core";
1642
+
1643
+ // runtime/subsystems/jobs/memory-job-store.ts
1644
+ var MemoryJobStore = class {
1645
+ /** Runs keyed by `id` (single source of truth for status/scope/lineage). */
1646
+ runs = /* @__PURE__ */ new Map();
1647
+ /** Steps keyed by `job_run_id`; array order matches insertion order. */
1648
+ steps = /* @__PURE__ */ new Map();
1649
+ /** Job definitions keyed by `type` — memory mirror of the `job` table. */
1650
+ jobs = /* @__PURE__ */ new Map();
1651
+ /** Reset everything. Tests call this in `beforeEach`. */
1652
+ clear() {
1653
+ this.runs.clear();
1654
+ this.steps.clear();
1655
+ this.jobs.clear();
1656
+ }
1657
+ };
1658
+
1659
+ // runtime/subsystems/jobs/job-step-service.memory-backend.ts
1638
1660
  import { randomUUID as randomUUID4 } from "crypto";
1639
- import { Inject as Inject8, Injectable as Injectable8, Logger as Logger4, Optional as Optional5 } from "@nestjs/common";
1661
+ import { Inject as Inject8, Injectable as Injectable8 } from "@nestjs/common";
1662
+ var MemoryJobStepService = class {
1663
+ // ADR-037 (package-mode DI): explicit `@Inject(MemoryJobStore)` — the
1664
+ // published bundle carries no `design:paramtypes`, so a by-type inject
1665
+ // would resolve to `undefined` in package mode.
1666
+ constructor(store) {
1667
+ this.store = store;
1668
+ }
1669
+ store;
1670
+ async findStep(runId, stepId) {
1671
+ const rows = this.store.steps.get(runId);
1672
+ if (!rows) return null;
1673
+ const match = rows.find(
1674
+ (r) => r.stepId === stepId && r.status === "completed"
1675
+ );
1676
+ return match ?? null;
1677
+ }
1678
+ async recordStep(input) {
1679
+ const rows = this.getOrCreateRows(input.jobRunId);
1680
+ const existingIdx = rows.findIndex((r) => r.stepId === input.stepId);
1681
+ const normalisedInput = input.input ?? null;
1682
+ const normalisedOutput = input.output ?? null;
1683
+ if (existingIdx >= 0) {
1684
+ const prev = rows[existingIdx];
1685
+ const next = {
1686
+ ...prev,
1687
+ status: input.status,
1688
+ input: normalisedInput ?? prev.input,
1689
+ output: normalisedOutput ?? prev.output,
1690
+ error: input.error ?? prev.error,
1691
+ attempts: input.attempts ?? prev.attempts,
1692
+ startedAt: input.startedAt ?? prev.startedAt,
1693
+ finishedAt: input.finishedAt ?? prev.finishedAt
1694
+ };
1695
+ rows[existingIdx] = next;
1696
+ return next;
1697
+ }
1698
+ const seq = input.seq ?? this.nextSeq(rows);
1699
+ const row = {
1700
+ id: randomUUID4(),
1701
+ jobRunId: input.jobRunId,
1702
+ stepId: input.stepId,
1703
+ kind: input.kind,
1704
+ seq,
1705
+ status: input.status,
1706
+ input: normalisedInput,
1707
+ output: normalisedOutput,
1708
+ error: input.error ?? null,
1709
+ attempts: input.attempts ?? 0,
1710
+ startedAt: input.startedAt ?? null,
1711
+ finishedAt: input.finishedAt ?? null
1712
+ };
1713
+ rows.push(row);
1714
+ return row;
1715
+ }
1716
+ /**
1717
+ * Replay helper — wipe every step row for a run. Mirrors the `scratch`
1718
+ * replay mode of the Drizzle backend (`DELETE FROM job_step WHERE job_run_id = …`).
1719
+ */
1720
+ clearStepsForRun(runId) {
1721
+ this.store.steps.delete(runId);
1722
+ }
1723
+ /**
1724
+ * Remove every non-`completed` row for the run. Memoized (`completed`)
1725
+ * rows are preserved — this is the `last_checkpoint` / `last_step`
1726
+ * semantics the Drizzle backend implements via
1727
+ * `DELETE … WHERE status != 'completed'`. Both replay modes route here
1728
+ * (Phase 1 collapses `last_step` onto this behaviour; see JOB-3 notes).
1729
+ */
1730
+ clearIncompleteSteps(runId) {
1731
+ const rows = this.store.steps.get(runId);
1732
+ if (!rows) return;
1733
+ const kept = rows.filter((r) => r.status === "completed");
1734
+ if (kept.length === 0) {
1735
+ this.store.steps.delete(runId);
1736
+ } else {
1737
+ this.store.steps.set(runId, kept);
1738
+ }
1739
+ }
1740
+ getOrCreateRows(runId) {
1741
+ let rows = this.store.steps.get(runId);
1742
+ if (!rows) {
1743
+ rows = [];
1744
+ this.store.steps.set(runId, rows);
1745
+ }
1746
+ return rows;
1747
+ }
1748
+ nextSeq(rows) {
1749
+ let max = 0;
1750
+ for (const r of rows) {
1751
+ if (r.seq > max) max = r.seq;
1752
+ }
1753
+ return max + 1;
1754
+ }
1755
+ };
1756
+ MemoryJobStepService = __decorateClass([
1757
+ Injectable8(),
1758
+ __decorateParam(0, Inject8(MemoryJobStore))
1759
+ ], MemoryJobStepService);
1760
+
1761
+ // runtime/subsystems/jobs/job-orchestrator.memory-backend.ts
1640
1762
  var QUEUED_RUN_AT = /* @__PURE__ */ new Date(864e13);
1641
1763
  var TERMINAL_STATUSES2 = [
1642
1764
  "completed",
@@ -1807,7 +1929,7 @@ var MemoryJobOrchestrator = class {
1807
1929
  }
1808
1930
  }
1809
1931
  }
1810
- const newId = randomUUID4();
1932
+ const newId = randomUUID5();
1811
1933
  let rootRunId = newId;
1812
1934
  if (opts.parentRunId) {
1813
1935
  const parent = this.store.runs.get(opts.parentRunId);
@@ -2205,9 +2327,12 @@ var MemoryJobOrchestrator = class {
2205
2327
  }
2206
2328
  };
2207
2329
  MemoryJobOrchestrator = __decorateClass([
2208
- Injectable8(),
2209
- __decorateParam(2, Inject8(JOBS_MULTI_TENANT)),
2210
- __decorateParam(3, Optional5())
2330
+ Injectable9(),
2331
+ __decorateParam(0, Inject9(MemoryJobStore)),
2332
+ __decorateParam(1, Inject9(MemoryJobStepService)),
2333
+ __decorateParam(2, Inject9(JOBS_MULTI_TENANT)),
2334
+ __decorateParam(3, Optional5()),
2335
+ __decorateParam(3, Inject9(ModuleRef))
2211
2336
  ], MemoryJobOrchestrator);
2212
2337
  function classifyError(err, policy, currentAttempts) {
2213
2338
  if (!policy) return "fail";
@@ -2241,7 +2366,7 @@ function serialiseError(err, attempt, retryable) {
2241
2366
  }
2242
2367
 
2243
2368
  // runtime/subsystems/jobs/job-run-service.memory-backend.ts
2244
- import { Inject as Inject9, Injectable as Injectable9 } from "@nestjs/common";
2369
+ import { Inject as Inject10, Injectable as Injectable10 } from "@nestjs/common";
2245
2370
  var NON_TERMINAL_STATUSES2 = [
2246
2371
  "pending",
2247
2372
  "running",
@@ -2408,9 +2533,10 @@ var MemoryJobRunService = class {
2408
2533
  }
2409
2534
  };
2410
2535
  MemoryJobRunService = __decorateClass([
2411
- Injectable9(),
2412
- __decorateParam(1, Inject9(JOB_ORCHESTRATOR)),
2413
- __decorateParam(2, Inject9(JOBS_MULTI_TENANT))
2536
+ Injectable10(),
2537
+ __decorateParam(0, Inject10(MemoryJobStore)),
2538
+ __decorateParam(1, Inject10(JOB_ORCHESTRATOR)),
2539
+ __decorateParam(2, Inject10(JOBS_MULTI_TENANT))
2414
2540
  ], MemoryJobRunService);
2415
2541
  function compareBy(a, b, order) {
2416
2542
  switch (order) {
@@ -2426,120 +2552,6 @@ function compareBy(a, b, order) {
2426
2552
  }
2427
2553
  }
2428
2554
 
2429
- // runtime/subsystems/jobs/job-step-service.memory-backend.ts
2430
- import { randomUUID as randomUUID5 } from "crypto";
2431
- import { Injectable as Injectable10 } from "@nestjs/common";
2432
- var MemoryJobStepService = class {
2433
- constructor(store) {
2434
- this.store = store;
2435
- }
2436
- store;
2437
- async findStep(runId, stepId) {
2438
- const rows = this.store.steps.get(runId);
2439
- if (!rows) return null;
2440
- const match = rows.find(
2441
- (r) => r.stepId === stepId && r.status === "completed"
2442
- );
2443
- return match ?? null;
2444
- }
2445
- async recordStep(input) {
2446
- const rows = this.getOrCreateRows(input.jobRunId);
2447
- const existingIdx = rows.findIndex((r) => r.stepId === input.stepId);
2448
- const normalisedInput = input.input ?? null;
2449
- const normalisedOutput = input.output ?? null;
2450
- if (existingIdx >= 0) {
2451
- const prev = rows[existingIdx];
2452
- const next = {
2453
- ...prev,
2454
- status: input.status,
2455
- input: normalisedInput ?? prev.input,
2456
- output: normalisedOutput ?? prev.output,
2457
- error: input.error ?? prev.error,
2458
- attempts: input.attempts ?? prev.attempts,
2459
- startedAt: input.startedAt ?? prev.startedAt,
2460
- finishedAt: input.finishedAt ?? prev.finishedAt
2461
- };
2462
- rows[existingIdx] = next;
2463
- return next;
2464
- }
2465
- const seq = input.seq ?? this.nextSeq(rows);
2466
- const row = {
2467
- id: randomUUID5(),
2468
- jobRunId: input.jobRunId,
2469
- stepId: input.stepId,
2470
- kind: input.kind,
2471
- seq,
2472
- status: input.status,
2473
- input: normalisedInput,
2474
- output: normalisedOutput,
2475
- error: input.error ?? null,
2476
- attempts: input.attempts ?? 0,
2477
- startedAt: input.startedAt ?? null,
2478
- finishedAt: input.finishedAt ?? null
2479
- };
2480
- rows.push(row);
2481
- return row;
2482
- }
2483
- /**
2484
- * Replay helper — wipe every step row for a run. Mirrors the `scratch`
2485
- * replay mode of the Drizzle backend (`DELETE FROM job_step WHERE job_run_id = …`).
2486
- */
2487
- clearStepsForRun(runId) {
2488
- this.store.steps.delete(runId);
2489
- }
2490
- /**
2491
- * Remove every non-`completed` row for the run. Memoized (`completed`)
2492
- * rows are preserved — this is the `last_checkpoint` / `last_step`
2493
- * semantics the Drizzle backend implements via
2494
- * `DELETE … WHERE status != 'completed'`. Both replay modes route here
2495
- * (Phase 1 collapses `last_step` onto this behaviour; see JOB-3 notes).
2496
- */
2497
- clearIncompleteSteps(runId) {
2498
- const rows = this.store.steps.get(runId);
2499
- if (!rows) return;
2500
- const kept = rows.filter((r) => r.status === "completed");
2501
- if (kept.length === 0) {
2502
- this.store.steps.delete(runId);
2503
- } else {
2504
- this.store.steps.set(runId, kept);
2505
- }
2506
- }
2507
- getOrCreateRows(runId) {
2508
- let rows = this.store.steps.get(runId);
2509
- if (!rows) {
2510
- rows = [];
2511
- this.store.steps.set(runId, rows);
2512
- }
2513
- return rows;
2514
- }
2515
- nextSeq(rows) {
2516
- let max = 0;
2517
- for (const r of rows) {
2518
- if (r.seq > max) max = r.seq;
2519
- }
2520
- return max + 1;
2521
- }
2522
- };
2523
- MemoryJobStepService = __decorateClass([
2524
- Injectable10()
2525
- ], MemoryJobStepService);
2526
-
2527
- // runtime/subsystems/jobs/memory-job-store.ts
2528
- var MemoryJobStore = class {
2529
- /** Runs keyed by `id` (single source of truth for status/scope/lineage). */
2530
- runs = /* @__PURE__ */ new Map();
2531
- /** Steps keyed by `job_run_id`; array order matches insertion order. */
2532
- steps = /* @__PURE__ */ new Map();
2533
- /** Job definitions keyed by `type` — memory mirror of the `job` table. */
2534
- jobs = /* @__PURE__ */ new Map();
2535
- /** Reset everything. Tests call this in `beforeEach`. */
2536
- clear() {
2537
- this.runs.clear();
2538
- this.steps.clear();
2539
- this.jobs.clear();
2540
- }
2541
- };
2542
-
2543
2555
  // runtime/subsystems/jobs/pool-config.loader.ts
2544
2556
  import { existsSync, readFileSync } from "fs";
2545
2557
  import { resolve } from "path";
@@ -2755,7 +2767,7 @@ JobsDomainModule = __decorateClass([
2755
2767
  ], JobsDomainModule);
2756
2768
 
2757
2769
  // runtime/subsystems/jobs/job-worker.ts
2758
- import { Inject as Inject10, Injectable as Injectable11, Logger as Logger5 } from "@nestjs/common";
2770
+ import { Inject as Inject11, Injectable as Injectable11, Logger as Logger5 } from "@nestjs/common";
2759
2771
  import { and as and5, asc as asc2, desc as desc3, eq as eq5, inArray as inArray3, lt as lt2, lte, sql as sql7 } from "drizzle-orm";
2760
2772
  var JOB_WORKER_OPTIONS = Symbol.for(tokenKey("jobs", "worker-options"));
2761
2773
  var DEFAULT_POLL_INTERVAL_MS = 1e3;
@@ -3142,11 +3154,11 @@ var JobWorker = class {
3142
3154
  };
3143
3155
  JobWorker = __decorateClass([
3144
3156
  Injectable11(),
3145
- __decorateParam(0, Inject10(DRIZZLE)),
3146
- __decorateParam(1, Inject10(JOB_ORCHESTRATOR)),
3147
- __decorateParam(2, Inject10(JOB_RUN_SERVICE)),
3148
- __decorateParam(3, Inject10(JOB_STEP_SERVICE)),
3149
- __decorateParam(4, Inject10(JOB_WORKER_OPTIONS))
3157
+ __decorateParam(0, Inject11(DRIZZLE)),
3158
+ __decorateParam(1, Inject11(JOB_ORCHESTRATOR)),
3159
+ __decorateParam(2, Inject11(JOB_RUN_SERVICE)),
3160
+ __decorateParam(3, Inject11(JOB_STEP_SERVICE)),
3161
+ __decorateParam(4, Inject11(JOB_WORKER_OPTIONS))
3150
3162
  ], JobWorker);
3151
3163
 
3152
3164
  // runtime/subsystems/jobs/job-worker.module.ts
@@ -3344,16 +3356,17 @@ var JobWorkerOrchestrator = class {
3344
3356
  };
3345
3357
  JobWorkerOrchestrator = __decorateClass([
3346
3358
  Injectable12(),
3347
- __decorateParam(0, Inject11(JOB_ORCHESTRATOR)),
3348
- __decorateParam(1, Inject11(JOB_RUN_SERVICE)),
3349
- __decorateParam(2, Inject11(JOB_STEP_SERVICE)),
3350
- __decorateParam(3, Inject11(JOB_WORKER_MODULE_OPTIONS)),
3359
+ __decorateParam(0, Inject12(JOB_ORCHESTRATOR)),
3360
+ __decorateParam(1, Inject12(JOB_RUN_SERVICE)),
3361
+ __decorateParam(2, Inject12(JOB_STEP_SERVICE)),
3362
+ __decorateParam(3, Inject12(JOB_WORKER_MODULE_OPTIONS)),
3351
3363
  __decorateParam(4, Optional6()),
3352
- __decorateParam(4, Inject11(DRIZZLE)),
3364
+ __decorateParam(4, Inject12(DRIZZLE)),
3365
+ __decorateParam(5, Inject12(ModuleRef2)),
3353
3366
  __decorateParam(6, Optional6()),
3354
- __decorateParam(6, Inject11(BULLMQ_CONNECTION)),
3367
+ __decorateParam(6, Inject12(BULLMQ_CONNECTION)),
3355
3368
  __decorateParam(7, Optional6()),
3356
- __decorateParam(7, Inject11(BULLMQ_RESOLVED_CONFIG))
3369
+ __decorateParam(7, Inject12(BULLMQ_RESOLVED_CONFIG))
3357
3370
  ], JobWorkerOrchestrator);
3358
3371
  var JobWorkerModule = class {
3359
3372
  static forRoot(opts) {
@@ -3454,7 +3467,7 @@ var BridgeModule = class {
3454
3467
  BridgeModule = __decorateClass([
3455
3468
  Module3({}),
3456
3469
  __decorateParam(0, Optional7()),
3457
- __decorateParam(0, Inject12(JOB_WORKER_MODULE_OPTIONS))
3470
+ __decorateParam(0, Inject13(JOB_WORKER_MODULE_OPTIONS))
3458
3471
  ], BridgeModule);
3459
3472
  export {
3460
3473
  BRIDGE_DELIVERY_JOB_TYPE,