@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.
- package/CHANGELOG.md +70 -0
- package/dist/runtime/subsystems/auth/controllers/auth.controller.d.ts +1 -0
- package/dist/runtime/subsystems/auth/index.d.ts +2 -0
- package/dist/runtime/subsystems/auth/index.js +55 -0
- package/dist/runtime/subsystems/auth/index.js.map +1 -1
- package/dist/runtime/subsystems/auth/middleware/requester-context.d.ts +81 -0
- package/dist/runtime/subsystems/auth/middleware/requester-context.js +60 -0
- package/dist/runtime/subsystems/auth/middleware/requester-context.js.map +1 -0
- package/dist/runtime/subsystems/auth/protocols/user-context.d.ts +18 -0
- package/dist/runtime/subsystems/bridge/bridge-delivery-handler.js.map +1 -1
- package/dist/runtime/subsystems/bridge/bridge-outbox-drain-hook.js.map +1 -1
- package/dist/runtime/subsystems/bridge/bridge.module.d.ts +3 -0
- package/dist/runtime/subsystems/bridge/bridge.module.js +930 -275
- package/dist/runtime/subsystems/bridge/bridge.module.js.map +1 -1
- package/dist/runtime/subsystems/bridge/event-flow.service.js.map +1 -1
- package/dist/runtime/subsystems/bridge/index.d.ts +3 -0
- package/dist/runtime/subsystems/bridge/index.js +837 -182
- package/dist/runtime/subsystems/bridge/index.js.map +1 -1
- package/dist/runtime/subsystems/events/event-bus.drizzle-backend.d.ts +3 -1
- package/dist/runtime/subsystems/events/event-bus.drizzle-backend.js +92 -1
- package/dist/runtime/subsystems/events/event-bus.drizzle-backend.js.map +1 -1
- package/dist/runtime/subsystems/events/event-bus.memory-backend.d.ts +3 -1
- package/dist/runtime/subsystems/events/event-bus.memory-backend.js +99 -0
- package/dist/runtime/subsystems/events/event-bus.memory-backend.js.map +1 -1
- package/dist/runtime/subsystems/events/event-bus.redis-backend.js.map +1 -1
- package/dist/runtime/subsystems/events/event-keyset-cursor.d.ts +32 -0
- package/dist/runtime/subsystems/events/event-keyset-cursor.js +38 -0
- package/dist/runtime/subsystems/events/event-keyset-cursor.js.map +1 -0
- package/dist/runtime/subsystems/events/event-read.protocol.d.ts +94 -0
- package/dist/runtime/subsystems/events/event-read.protocol.js +9 -0
- package/dist/runtime/subsystems/events/event-read.protocol.js.map +1 -0
- package/dist/runtime/subsystems/events/events.module.js +177 -3
- package/dist/runtime/subsystems/events/events.module.js.map +1 -1
- package/dist/runtime/subsystems/events/events.tokens.d.ts +16 -1
- package/dist/runtime/subsystems/events/events.tokens.js +2 -0
- package/dist/runtime/subsystems/events/events.tokens.js.map +1 -1
- package/dist/runtime/subsystems/events/generated/bus.js.map +1 -1
- package/dist/runtime/subsystems/events/generated/index.js.map +1 -1
- package/dist/runtime/subsystems/events/index.d.ts +2 -1
- package/dist/runtime/subsystems/events/index.js +178 -3
- package/dist/runtime/subsystems/events/index.js.map +1 -1
- package/dist/runtime/subsystems/index.d.ts +2 -0
- package/dist/runtime/subsystems/index.js +1198 -264
- package/dist/runtime/subsystems/index.js.map +1 -1
- package/dist/runtime/subsystems/jobs/bullmq.config.d.ts +98 -0
- package/dist/runtime/subsystems/jobs/bullmq.config.js +143 -0
- package/dist/runtime/subsystems/jobs/bullmq.config.js.map +1 -0
- package/dist/runtime/subsystems/jobs/index.d.ts +6 -2
- package/dist/runtime/subsystems/jobs/index.js +861 -201
- package/dist/runtime/subsystems/jobs/index.js.map +1 -1
- package/dist/runtime/subsystems/jobs/job-orchestrator.bullmq-backend.d.ts +107 -0
- package/dist/runtime/subsystems/jobs/job-orchestrator.bullmq-backend.js +922 -0
- package/dist/runtime/subsystems/jobs/job-orchestrator.bullmq-backend.js.map +1 -0
- package/dist/runtime/subsystems/jobs/job-run-keyset-cursor.d.ts +52 -0
- package/dist/runtime/subsystems/jobs/job-run-keyset-cursor.js +57 -0
- package/dist/runtime/subsystems/jobs/job-run-keyset-cursor.js.map +1 -0
- package/dist/runtime/subsystems/jobs/job-run-service.drizzle-backend.d.ts +2 -1
- package/dist/runtime/subsystems/jobs/job-run-service.drizzle-backend.js +81 -1
- package/dist/runtime/subsystems/jobs/job-run-service.drizzle-backend.js.map +1 -1
- package/dist/runtime/subsystems/jobs/job-run-service.memory-backend.d.ts +2 -1
- package/dist/runtime/subsystems/jobs/job-run-service.memory-backend.js +81 -0
- package/dist/runtime/subsystems/jobs/job-run-service.memory-backend.js.map +1 -1
- package/dist/runtime/subsystems/jobs/job-run-service.protocol.d.ts +74 -1
- package/dist/runtime/subsystems/jobs/job-worker.bullmq-backend.d.ts +48 -0
- package/dist/runtime/subsystems/jobs/job-worker.bullmq-backend.js +374 -0
- package/dist/runtime/subsystems/jobs/job-worker.bullmq-backend.js.map +1 -0
- package/dist/runtime/subsystems/jobs/job-worker.module.d.ts +42 -4
- package/dist/runtime/subsystems/jobs/job-worker.module.js +832 -178
- package/dist/runtime/subsystems/jobs/job-worker.module.js.map +1 -1
- package/dist/runtime/subsystems/jobs/jobs-domain.module.d.ts +10 -1
- package/dist/runtime/subsystems/jobs/jobs-domain.module.js +519 -20
- package/dist/runtime/subsystems/jobs/jobs-domain.module.js.map +1 -1
- package/dist/runtime/subsystems/jobs/pool-config.loader.d.ts +9 -1
- package/dist/runtime/subsystems/jobs/pool-config.loader.js +4 -0
- package/dist/runtime/subsystems/jobs/pool-config.loader.js.map +1 -1
- package/dist/runtime/subsystems/observability/index.d.ts +4 -3
- package/dist/runtime/subsystems/observability/index.js +109 -2
- package/dist/runtime/subsystems/observability/index.js.map +1 -1
- package/dist/runtime/subsystems/observability/observability.module.js +109 -2
- package/dist/runtime/subsystems/observability/observability.module.js.map +1 -1
- package/dist/runtime/subsystems/observability/observability.protocol.d.ts +63 -2
- package/dist/runtime/subsystems/observability/observability.service.d.ts +21 -3
- package/dist/runtime/subsystems/observability/observability.service.js +109 -2
- package/dist/runtime/subsystems/observability/observability.service.js.map +1 -1
- package/dist/runtime/subsystems/observability/reporters/bridge-metrics.reporter.d.ts +1 -0
- package/dist/runtime/subsystems/observability/reporters/index.d.ts +1 -0
- package/dist/src/cli/index.js +43 -7
- package/dist/src/cli/index.js.map +1 -1
- package/package.json +1 -1
- package/runtime/subsystems/auth/index.ts +8 -0
- package/runtime/subsystems/auth/middleware/requester-context.ts +141 -0
- package/runtime/subsystems/auth/protocols/user-context.ts +17 -0
- package/runtime/subsystems/bridge/bridge.module.ts +5 -0
- package/runtime/subsystems/events/event-bus.drizzle-backend.ts +109 -3
- package/runtime/subsystems/events/event-bus.memory-backend.ts +103 -1
- package/runtime/subsystems/events/event-keyset-cursor.ts +59 -0
- package/runtime/subsystems/events/event-read.protocol.ts +97 -0
- package/runtime/subsystems/events/events.module.ts +18 -2
- package/runtime/subsystems/events/events.tokens.ts +16 -0
- package/runtime/subsystems/events/index.ts +7 -0
- package/runtime/subsystems/jobs/bullmq.config.ts +125 -0
- package/runtime/subsystems/jobs/index.ts +22 -0
- package/runtime/subsystems/jobs/job-orchestrator.bullmq-backend.ts +381 -0
- package/runtime/subsystems/jobs/job-run-keyset-cursor.ts +88 -0
- package/runtime/subsystems/jobs/job-run-service.drizzle-backend.ts +59 -1
- package/runtime/subsystems/jobs/job-run-service.memory-backend.ts +53 -0
- package/runtime/subsystems/jobs/job-run-service.protocol.ts +77 -0
- package/runtime/subsystems/jobs/job-worker.bullmq-backend.ts +311 -0
- package/runtime/subsystems/jobs/job-worker.module.ts +124 -10
- package/runtime/subsystems/jobs/jobs-domain.module.ts +40 -21
- package/runtime/subsystems/jobs/pool-config.loader.ts +11 -0
- package/runtime/subsystems/observability/index.ts +8 -0
- package/runtime/subsystems/observability/observability.protocol.ts +76 -0
- package/runtime/subsystems/observability/observability.service.ts +148 -1
- package/templates/entity/new/clean-lite-ps/prompt-extension.js +14 -12
- package/templates/relationship/new/prompt.js +8 -5
- package/templates/subsystem/jobs/worker.ejs.t +30 -7
- 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 };
|