@pattern-stack/codegen 0.4.2 → 0.4.3

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 (29) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/runtime/subsystems/bridge/bridge.module.d.ts +1 -0
  3. package/dist/runtime/subsystems/bridge/bridge.module.js +38 -21
  4. package/dist/runtime/subsystems/bridge/bridge.module.js.map +1 -1
  5. package/dist/runtime/subsystems/bridge/index.d.ts +1 -0
  6. package/dist/runtime/subsystems/bridge/index.js +29 -12
  7. package/dist/runtime/subsystems/bridge/index.js.map +1 -1
  8. package/dist/runtime/subsystems/index.js +31 -14
  9. package/dist/runtime/subsystems/index.js.map +1 -1
  10. package/dist/runtime/subsystems/jobs/index.d.ts +1 -0
  11. package/dist/runtime/subsystems/jobs/index.js +27 -10
  12. package/dist/runtime/subsystems/jobs/index.js.map +1 -1
  13. package/dist/runtime/subsystems/jobs/job-orchestrator.memory-backend.d.ts +3 -1
  14. package/dist/runtime/subsystems/jobs/job-orchestrator.memory-backend.js +9 -4
  15. package/dist/runtime/subsystems/jobs/job-orchestrator.memory-backend.js.map +1 -1
  16. package/dist/runtime/subsystems/jobs/job-worker.d.ts +3 -1
  17. package/dist/runtime/subsystems/jobs/job-worker.js +6 -2
  18. package/dist/runtime/subsystems/jobs/job-worker.js.map +1 -1
  19. package/dist/runtime/subsystems/jobs/job-worker.module.d.ts +3 -1
  20. package/dist/runtime/subsystems/jobs/job-worker.module.js +27 -10
  21. package/dist/runtime/subsystems/jobs/job-worker.module.js.map +1 -1
  22. package/dist/runtime/subsystems/jobs/jobs-domain.module.js +9 -4
  23. package/dist/runtime/subsystems/jobs/jobs-domain.module.js.map +1 -1
  24. package/dist/src/cli/index.js +29 -2
  25. package/dist/src/cli/index.js.map +1 -1
  26. package/package.json +1 -1
  27. package/runtime/subsystems/jobs/job-orchestrator.memory-backend.ts +12 -2
  28. package/runtime/subsystems/jobs/job-worker.module.ts +10 -0
  29. package/runtime/subsystems/jobs/job-worker.ts +12 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pattern-stack/codegen",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "Entity-driven code generation for full-stack TypeScript applications",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,7 +14,8 @@
14
14
  * the orchestrator's mutex.
15
15
  */
16
16
  import { randomUUID } from 'node:crypto';
17
- import { Inject, Injectable, Logger } from '@nestjs/common';
17
+ import { Inject, Injectable, Logger, Optional } from '@nestjs/common';
18
+ import { ModuleRef } from '@nestjs/core';
18
19
  import type {
19
20
  JobDefinitionRow,
20
21
  JobRunRow,
@@ -139,6 +140,7 @@ export class MemoryJobOrchestrator implements IJobOrchestrator {
139
140
  private readonly store: MemoryJobStore,
140
141
  private readonly stepService: MemoryJobStepService,
141
142
  @Inject(JOBS_MULTI_TENANT) private readonly multiTenant: boolean,
143
+ @Optional() private readonly moduleRef?: ModuleRef,
142
144
  ) {}
143
145
 
144
146
  /**
@@ -590,7 +592,15 @@ export class MemoryJobOrchestrator implements IJobOrchestrator {
590
592
  }
591
593
  const meta = registration.meta;
592
594
  const HandlerClass = registration.handlerClass;
593
- const handler = new HandlerClass();
595
+ // Match the Drizzle backend: resolve the handler through Nest's
596
+ // ModuleRef so `@Inject` constructor params work. ModuleRef is
597
+ // @Optional() — zero-dep test stubs that construct this orchestrator
598
+ // manually still hit the legacy `new HandlerClass()` path.
599
+ const handler = this.moduleRef
600
+ ? ((await this.moduleRef.create(
601
+ HandlerClass as unknown as new (...args: unknown[]) => unknown,
602
+ )) as JobHandlerBase<unknown>)
603
+ : new HandlerClass();
594
604
 
595
605
  const ctx: JobContext<unknown> = {
596
606
  input: run.input,
@@ -29,6 +29,7 @@ import {
29
29
  type OnModuleDestroy,
30
30
  type OnModuleInit,
31
31
  } from '@nestjs/common';
32
+ import { ModuleRef } from '@nestjs/core';
32
33
  import { DRIZZLE } from '../../constants/tokens';
33
34
  import type { DrizzleClient } from '../../types/drizzle';
34
35
  import { HandlerRegistry, type HandlerRegistryEntry } from './job-handler.base';
@@ -126,6 +127,7 @@ export class JobWorkerOrchestrator implements OnModuleInit, OnModuleDestroy {
126
127
  * without supplying a `DRIZZLE` provider.
127
128
  */
128
129
  @Optional() @Inject(DRIZZLE) private readonly db: DrizzleClient | null = null,
130
+ private readonly moduleRef?: ModuleRef,
129
131
  ) {}
130
132
 
131
133
  // ============================================================================
@@ -270,12 +272,20 @@ export class JobWorkerOrchestrator implements OnModuleInit, OnModuleDestroy {
270
272
  `pass 'workerFactory' to inject a stub.`,
271
273
  );
272
274
  }
275
+ if (!this.moduleRef) {
276
+ throw new Error(
277
+ `JobWorkerModule: ModuleRef not available — cannot construct JobWorker ` +
278
+ `with handler DI support. Ensure the orchestrator is resolved through ` +
279
+ `the Nest container (not instantiated manually in tests).`,
280
+ );
281
+ }
273
282
  return new JobWorker(
274
283
  this.db,
275
284
  this.orchestrator,
276
285
  this.runService,
277
286
  this.stepService,
278
287
  workerOptions,
288
+ this.moduleRef,
279
289
  );
280
290
  }
281
291
  }
@@ -14,6 +14,7 @@
14
14
  */
15
15
  // TODO(logging-subsystem): swap to ILogger once ADR-028 lands
16
16
  import { Inject, Injectable, Logger, type OnModuleDestroy, type OnModuleInit } from '@nestjs/common';
17
+ import { ModuleRef } from '@nestjs/core';
17
18
  import { and, asc, desc, eq, inArray, lt, lte, sql } from 'drizzle-orm';
18
19
  import type { DrizzleClient } from '../../types/drizzle';
19
20
  import { DRIZZLE } from '../../constants/tokens';
@@ -194,6 +195,7 @@ export class JobWorker implements OnModuleInit, OnModuleDestroy {
194
195
  @Inject(JOB_RUN_SERVICE) private readonly runService: IJobRunService,
195
196
  @Inject(JOB_STEP_SERVICE) private readonly stepService: IJobStepService,
196
197
  @Inject(JOB_WORKER_OPTIONS) private readonly options: JobWorkerOptions,
198
+ private readonly moduleRef: ModuleRef,
197
199
  ) {
198
200
  this.pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
199
201
  this.staleSweeperIntervalMs =
@@ -419,9 +421,16 @@ export class JobWorker implements OnModuleInit, OnModuleDestroy {
419
421
  const meta = registryEntry.meta as JobHandlerMeta<unknown>;
420
422
  const HandlerClass = registryEntry.handlerClass;
421
423
 
422
- // (c) Build JobContext. Phase 1: instantiate handler with no args.
423
- // DI-for-handlers lands with JOB-5's boot wiring.
424
- const handler = new HandlerClass() as JobHandlerBase<unknown>;
424
+ // (c) Build JobContext. Instantiate handler via Nest's ModuleRef so
425
+ // `@Inject` constructor params resolve. `create({ strict: false })`
426
+ // walks the whole module graph for providers (handlers don't need to
427
+ // be registered as providers themselves; the @JobHandler decorator
428
+ // is the only registration required). A fresh instance per run
429
+ // mirrors the contract handlers were authored against and keeps
430
+ // run-scoped state from leaking across claims.
431
+ const handler = (await this.moduleRef.create(
432
+ HandlerClass as unknown as new (...args: unknown[]) => unknown,
433
+ )) as JobHandlerBase<unknown>;
425
434
  const ctx: JobContext<unknown> = {
426
435
  input: claimed.input,
427
436
  run: claimed as JobRun,