@pattern-stack/codegen 0.8.0 → 0.9.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.
Files changed (118) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/dist/runtime/subsystems/auth/controllers/auth.controller.d.ts +1 -0
  3. package/dist/runtime/subsystems/auth/index.d.ts +2 -0
  4. package/dist/runtime/subsystems/auth/index.js +55 -0
  5. package/dist/runtime/subsystems/auth/index.js.map +1 -1
  6. package/dist/runtime/subsystems/auth/middleware/requester-context.d.ts +81 -0
  7. package/dist/runtime/subsystems/auth/middleware/requester-context.js +60 -0
  8. package/dist/runtime/subsystems/auth/middleware/requester-context.js.map +1 -0
  9. package/dist/runtime/subsystems/auth/protocols/user-context.d.ts +18 -0
  10. package/dist/runtime/subsystems/bridge/bridge-delivery-handler.js.map +1 -1
  11. package/dist/runtime/subsystems/bridge/bridge-outbox-drain-hook.js.map +1 -1
  12. package/dist/runtime/subsystems/bridge/bridge.module.d.ts +3 -0
  13. package/dist/runtime/subsystems/bridge/bridge.module.js +930 -275
  14. package/dist/runtime/subsystems/bridge/bridge.module.js.map +1 -1
  15. package/dist/runtime/subsystems/bridge/event-flow.service.js.map +1 -1
  16. package/dist/runtime/subsystems/bridge/index.d.ts +3 -0
  17. package/dist/runtime/subsystems/bridge/index.js +837 -182
  18. package/dist/runtime/subsystems/bridge/index.js.map +1 -1
  19. package/dist/runtime/subsystems/events/event-bus.drizzle-backend.d.ts +3 -1
  20. package/dist/runtime/subsystems/events/event-bus.drizzle-backend.js +92 -1
  21. package/dist/runtime/subsystems/events/event-bus.drizzle-backend.js.map +1 -1
  22. package/dist/runtime/subsystems/events/event-bus.memory-backend.d.ts +3 -1
  23. package/dist/runtime/subsystems/events/event-bus.memory-backend.js +99 -0
  24. package/dist/runtime/subsystems/events/event-bus.memory-backend.js.map +1 -1
  25. package/dist/runtime/subsystems/events/event-bus.redis-backend.js.map +1 -1
  26. package/dist/runtime/subsystems/events/event-keyset-cursor.d.ts +32 -0
  27. package/dist/runtime/subsystems/events/event-keyset-cursor.js +38 -0
  28. package/dist/runtime/subsystems/events/event-keyset-cursor.js.map +1 -0
  29. package/dist/runtime/subsystems/events/event-read.protocol.d.ts +94 -0
  30. package/dist/runtime/subsystems/events/event-read.protocol.js +9 -0
  31. package/dist/runtime/subsystems/events/event-read.protocol.js.map +1 -0
  32. package/dist/runtime/subsystems/events/events.module.js +177 -3
  33. package/dist/runtime/subsystems/events/events.module.js.map +1 -1
  34. package/dist/runtime/subsystems/events/events.tokens.d.ts +16 -1
  35. package/dist/runtime/subsystems/events/events.tokens.js +2 -0
  36. package/dist/runtime/subsystems/events/events.tokens.js.map +1 -1
  37. package/dist/runtime/subsystems/events/generated/bus.js.map +1 -1
  38. package/dist/runtime/subsystems/events/generated/index.js.map +1 -1
  39. package/dist/runtime/subsystems/events/index.d.ts +2 -1
  40. package/dist/runtime/subsystems/events/index.js +178 -3
  41. package/dist/runtime/subsystems/events/index.js.map +1 -1
  42. package/dist/runtime/subsystems/index.d.ts +2 -0
  43. package/dist/runtime/subsystems/index.js +1198 -264
  44. package/dist/runtime/subsystems/index.js.map +1 -1
  45. package/dist/runtime/subsystems/jobs/bullmq.config.d.ts +98 -0
  46. package/dist/runtime/subsystems/jobs/bullmq.config.js +143 -0
  47. package/dist/runtime/subsystems/jobs/bullmq.config.js.map +1 -0
  48. package/dist/runtime/subsystems/jobs/index.d.ts +6 -2
  49. package/dist/runtime/subsystems/jobs/index.js +861 -201
  50. package/dist/runtime/subsystems/jobs/index.js.map +1 -1
  51. package/dist/runtime/subsystems/jobs/job-orchestrator.bullmq-backend.d.ts +107 -0
  52. package/dist/runtime/subsystems/jobs/job-orchestrator.bullmq-backend.js +922 -0
  53. package/dist/runtime/subsystems/jobs/job-orchestrator.bullmq-backend.js.map +1 -0
  54. package/dist/runtime/subsystems/jobs/job-run-keyset-cursor.d.ts +52 -0
  55. package/dist/runtime/subsystems/jobs/job-run-keyset-cursor.js +57 -0
  56. package/dist/runtime/subsystems/jobs/job-run-keyset-cursor.js.map +1 -0
  57. package/dist/runtime/subsystems/jobs/job-run-service.drizzle-backend.d.ts +2 -1
  58. package/dist/runtime/subsystems/jobs/job-run-service.drizzle-backend.js +81 -1
  59. package/dist/runtime/subsystems/jobs/job-run-service.drizzle-backend.js.map +1 -1
  60. package/dist/runtime/subsystems/jobs/job-run-service.memory-backend.d.ts +2 -1
  61. package/dist/runtime/subsystems/jobs/job-run-service.memory-backend.js +81 -0
  62. package/dist/runtime/subsystems/jobs/job-run-service.memory-backend.js.map +1 -1
  63. package/dist/runtime/subsystems/jobs/job-run-service.protocol.d.ts +74 -1
  64. package/dist/runtime/subsystems/jobs/job-worker.bullmq-backend.d.ts +48 -0
  65. package/dist/runtime/subsystems/jobs/job-worker.bullmq-backend.js +374 -0
  66. package/dist/runtime/subsystems/jobs/job-worker.bullmq-backend.js.map +1 -0
  67. package/dist/runtime/subsystems/jobs/job-worker.module.d.ts +42 -4
  68. package/dist/runtime/subsystems/jobs/job-worker.module.js +832 -178
  69. package/dist/runtime/subsystems/jobs/job-worker.module.js.map +1 -1
  70. package/dist/runtime/subsystems/jobs/jobs-domain.module.d.ts +10 -1
  71. package/dist/runtime/subsystems/jobs/jobs-domain.module.js +519 -20
  72. package/dist/runtime/subsystems/jobs/jobs-domain.module.js.map +1 -1
  73. package/dist/runtime/subsystems/jobs/pool-config.loader.d.ts +9 -1
  74. package/dist/runtime/subsystems/jobs/pool-config.loader.js +4 -0
  75. package/dist/runtime/subsystems/jobs/pool-config.loader.js.map +1 -1
  76. package/dist/runtime/subsystems/observability/index.d.ts +4 -3
  77. package/dist/runtime/subsystems/observability/index.js +109 -2
  78. package/dist/runtime/subsystems/observability/index.js.map +1 -1
  79. package/dist/runtime/subsystems/observability/observability.module.js +109 -2
  80. package/dist/runtime/subsystems/observability/observability.module.js.map +1 -1
  81. package/dist/runtime/subsystems/observability/observability.protocol.d.ts +63 -2
  82. package/dist/runtime/subsystems/observability/observability.service.d.ts +21 -3
  83. package/dist/runtime/subsystems/observability/observability.service.js +109 -2
  84. package/dist/runtime/subsystems/observability/observability.service.js.map +1 -1
  85. package/dist/runtime/subsystems/observability/reporters/bridge-metrics.reporter.d.ts +1 -0
  86. package/dist/runtime/subsystems/observability/reporters/index.d.ts +1 -0
  87. package/dist/src/cli/index.js +43 -7
  88. package/dist/src/cli/index.js.map +1 -1
  89. package/package.json +1 -1
  90. package/runtime/subsystems/auth/index.ts +8 -0
  91. package/runtime/subsystems/auth/middleware/requester-context.ts +141 -0
  92. package/runtime/subsystems/auth/protocols/user-context.ts +17 -0
  93. package/runtime/subsystems/bridge/bridge.module.ts +5 -0
  94. package/runtime/subsystems/events/event-bus.drizzle-backend.ts +109 -3
  95. package/runtime/subsystems/events/event-bus.memory-backend.ts +103 -1
  96. package/runtime/subsystems/events/event-keyset-cursor.ts +59 -0
  97. package/runtime/subsystems/events/event-read.protocol.ts +97 -0
  98. package/runtime/subsystems/events/events.module.ts +18 -2
  99. package/runtime/subsystems/events/events.tokens.ts +16 -0
  100. package/runtime/subsystems/events/index.ts +7 -0
  101. package/runtime/subsystems/jobs/bullmq.config.ts +125 -0
  102. package/runtime/subsystems/jobs/index.ts +22 -0
  103. package/runtime/subsystems/jobs/job-orchestrator.bullmq-backend.ts +381 -0
  104. package/runtime/subsystems/jobs/job-run-keyset-cursor.ts +88 -0
  105. package/runtime/subsystems/jobs/job-run-service.drizzle-backend.ts +59 -1
  106. package/runtime/subsystems/jobs/job-run-service.memory-backend.ts +53 -0
  107. package/runtime/subsystems/jobs/job-run-service.protocol.ts +77 -0
  108. package/runtime/subsystems/jobs/job-worker.bullmq-backend.ts +311 -0
  109. package/runtime/subsystems/jobs/job-worker.module.ts +124 -10
  110. package/runtime/subsystems/jobs/jobs-domain.module.ts +40 -21
  111. package/runtime/subsystems/jobs/pool-config.loader.ts +11 -0
  112. package/runtime/subsystems/observability/index.ts +8 -0
  113. package/runtime/subsystems/observability/observability.protocol.ts +76 -0
  114. package/runtime/subsystems/observability/observability.service.ts +148 -1
  115. package/templates/entity/new/clean-lite-ps/prompt-extension.js +14 -12
  116. package/templates/relationship/new/prompt.js +8 -5
  117. package/templates/subsystem/jobs/worker.ejs.t +30 -7
  118. package/templates/subsystem/sync/sync-audit.schema.ejs.t +12 -16
@@ -0,0 +1,107 @@
1
+ import { ConnectionOptions, FlowProducer } from 'bullmq';
2
+ import { DrizzleClient } from '../../types/drizzle.js';
3
+ import { DrizzleTransaction } from '../events/event-bus.protocol.js';
4
+ import { DrizzleJobOrchestrator } from './job-orchestrator.drizzle-backend.js';
5
+ import { l as StartOptions, i as JobRun, C as CancelOptions } from '../../../job-orchestrator.protocol-BwsBd37o.js';
6
+ import { BullMqResolvedConfig } from './bullmq.config.js';
7
+ import 'drizzle-orm/node-postgres';
8
+ import './job-orchestration.schema.js';
9
+ import 'drizzle-orm/pg-core';
10
+ import 'drizzle-orm';
11
+ import '@nestjs/common';
12
+ import './pool-config.loader.js';
13
+
14
+ /**
15
+ * Derive a colon-safe, stable BullMQ `jobId` from a logical idempotency key.
16
+ *
17
+ * SHA-1 over the raw key. Collision analysis (spec §Gotcha 1, resolved during
18
+ * implementation): SHA-1's 160-bit space makes an accidental collision between
19
+ * two *distinct* logical keys astronomically unlikely at any realistic job
20
+ * volume (the birthday bound is ~2^80 keys before a 50% collision chance —
21
+ * orders of magnitude beyond any job throughput). SHA-1's cryptographic
22
+ * weakness is irrelevant here: there is no adversary forging idempotency keys,
23
+ * and even a forged collision only deduplicates two jobs that the caller chose
24
+ * to key identically. We therefore accept SHA-1 with no mitigation. The *same*
25
+ * logical key intentionally maps to the *same* jobId — that is the dedup
26
+ * mechanism, not a collision.
27
+ */
28
+ declare function sha1JobId(idempotencyKey: string): string;
29
+ declare class BullMQJobOrchestrator extends DrizzleJobOrchestrator {
30
+ private readonly connection;
31
+ private readonly bullConfig;
32
+ private readonly bullLogger;
33
+ /** Lazily-opened `Queue` handles, one per pool. */
34
+ private readonly queues;
35
+ /** Single FlowProducer for parent/child hierarchies. Lazily opened. */
36
+ private _flow;
37
+ /**
38
+ * Cached `bullmq` value constructors, populated by `loadBullMq()` on first
39
+ * use (the `start`/`cancel`/`replay` entrypoints `await` it before touching
40
+ * a queue). Kept off the import graph so a `drizzle`-only consumer never
41
+ * resolves the optional `'bullmq'` package.
42
+ */
43
+ private QueueCtor;
44
+ private FlowProducerCtor;
45
+ private bullMqLoad;
46
+ /**
47
+ * Own reference to the Drizzle client. `DrizzleJobOrchestrator.db` is
48
+ * `private` (can't be redeclared even privately in a subclass), and the
49
+ * spec forbids touching that file — so the subclass keeps its own handle
50
+ * under a distinct name (same instance, passed through to `super`) for the
51
+ * cancel-cascade snapshot + definition/run loads below.
52
+ */
53
+ private readonly bullDb;
54
+ constructor(db: DrizzleClient, multiTenant: boolean, connection: ConnectionOptions, bullConfig?: BullMqResolvedConfig | null);
55
+ /**
56
+ * Lazily load the optional `bullmq` package and cache its value
57
+ * constructors. Idempotent (single in-flight promise). Throws a friendly,
58
+ * actionable error when the consumer selected `backend: 'bullmq'` but did
59
+ * not install the package — mirrors `createRedisClient` in the redis event
60
+ * backend. Must be `await`ed before any `queueFor`/`flow` access.
61
+ */
62
+ private loadBullMq;
63
+ /**
64
+ * Open (or reuse) the `Queue` for a pool. Synchronous — callers `await
65
+ * loadBullMq()` first so `QueueCtor` is populated.
66
+ */
67
+ private queueFor;
68
+ private flow;
69
+ start(type: string, input: unknown, opts?: StartOptions, tx?: DrizzleTransaction): Promise<JobRun>;
70
+ /**
71
+ * Map a `job_run` row onto a BullMQ job via `queue.add`. When the run has a
72
+ * `parentRunId` we attach it to the parent's existing BullMQ job through the
73
+ * `parent: { id, queue }` opt — BullMQ then tracks the parent/child link in
74
+ * its own graph. (The FlowProducer is reserved for whole-tree atomic
75
+ * submits, exposed as an opt-in extension via `flowProducer()`; runtime
76
+ * `ctx.spawnChild` is incremental, so `queue.add` with a parent ref is the
77
+ * correct primitive here.)
78
+ *
79
+ * The `jobId` is colon-safe + stable: `sha1(dedupeKey)` when a dedupe key is
80
+ * present (so the same logical key dedups), else the `job_run.id` UUID
81
+ * (already colon-free).
82
+ *
83
+ * The domain `parentClosePolicy` cascade is still enforced in Postgres by
84
+ * the shared `cancel` path — BullMQ's parent link is dispatch bookkeeping,
85
+ * not the authority.
86
+ */
87
+ private dispatch;
88
+ /**
89
+ * Opt-in extension (spec §Extensions): expose the FlowProducer for
90
+ * consumers that want to submit a whole parent/child DAG atomically up
91
+ * front, rather than incrementally via `ctx.spawnChild`. Backend-specific —
92
+ * code using it is not portable to the Drizzle backend. Async because it
93
+ * lazily loads the optional `bullmq` package on first use.
94
+ */
95
+ flowProducer(): Promise<FlowProducer>;
96
+ private retryOpts;
97
+ private dedupeOpts;
98
+ cancel(runId: string, opts?: CancelOptions): Promise<void>;
99
+ private removeFromQueue;
100
+ replay(runId: string): Promise<JobRun>;
101
+ private loadDefinition;
102
+ private loadRun;
103
+ /** Close all open queue + flow connections. Called on module destroy. */
104
+ closeConnections(): Promise<void>;
105
+ }
106
+
107
+ export { BullMQJobOrchestrator, sha1JobId };