@pattern-stack/codegen 0.26.1 → 0.27.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.
- package/CHANGELOG.md +24 -0
- package/dist/{chunk-XNRKZCVH.js → chunk-36NRG2EP.js} +8 -8
- package/dist/{chunk-COGHTKXY.js → chunk-7625PLY7.js} +4 -4
- package/dist/{chunk-CDLWYZVQ.js → chunk-BHZP6LOV.js} +7 -7
- package/dist/{chunk-CZQUOIDY.js → chunk-DKKFTHHI.js} +4 -4
- package/dist/{chunk-HLURWFIT.js → chunk-IASPGFFK.js} +5 -5
- package/dist/{chunk-CKLM57IE.js → chunk-KS4BZHIA.js} +10 -10
- package/dist/{chunk-7XDB4OMR.js → chunk-VCXOPBYY.js} +9 -9
- package/dist/{chunk-3VEVGL74.js → chunk-VNBC3VXM.js} +4 -4
- package/dist/{chunk-QXYKV4CE.js → chunk-W4JYZSQK.js} +8 -8
- package/dist/{chunk-PNCOUFFI.js → chunk-Y6UZMYGX.js} +4 -3
- package/dist/chunk-Y6UZMYGX.js.map +1 -0
- package/dist/{chunk-6M6LZEP6.js → chunk-YHVZAL6U.js} +5 -5
- package/dist/{chunk-QO35B6BN.js → chunk-YIVQ7KLS.js} +4 -4
- package/dist/{chunk-ENAR3F5S.js → chunk-Z7YFYK6H.js} +7 -7
- package/dist/runtime/base-classes/index.js +17 -17
- package/dist/runtime/http/pagination.d.ts +151 -0
- package/dist/runtime/http/pagination.js +98 -0
- package/dist/runtime/http/pagination.js.map +1 -0
- package/dist/runtime/subsystems/analytics/analytics.module.js +2 -2
- package/dist/runtime/subsystems/analytics/index.js +4 -4
- package/dist/runtime/subsystems/auth/index.js +3 -3
- package/dist/runtime/subsystems/bridge/bridge.module.js +12 -12
- package/dist/runtime/subsystems/bridge/index.js +18 -18
- package/dist/runtime/subsystems/cache/cache.module.js +2 -2
- package/dist/runtime/subsystems/cache/index.js +4 -4
- package/dist/runtime/subsystems/events/event-bus.drizzle-backend.js +1 -1
- package/dist/runtime/subsystems/events/events.module.js +3 -3
- package/dist/runtime/subsystems/events/index.js +5 -5
- package/dist/runtime/subsystems/index.js +53 -53
- package/dist/runtime/subsystems/integration/execute-integration.use-case.js +2 -2
- package/dist/runtime/subsystems/integration/index.js +31 -31
- package/dist/runtime/subsystems/integration/integration-cursor-store.drizzle-backend.js +3 -3
- package/dist/runtime/subsystems/integration/integration-run-recorder.drizzle-backend.js +3 -3
- package/dist/runtime/subsystems/integration/integration.module.js +6 -6
- package/dist/runtime/subsystems/jobs/index.js +27 -27
- package/dist/runtime/subsystems/jobs/job-orchestrator.bullmq-backend.js +4 -4
- package/dist/runtime/subsystems/jobs/job-run-service.drizzle-backend.js +2 -2
- package/dist/runtime/subsystems/jobs/job-run-service.memory-backend.js +2 -2
- package/dist/runtime/subsystems/jobs/job-worker.module.js +8 -8
- package/dist/runtime/subsystems/jobs/jobs-domain.module.js +6 -6
- package/dist/runtime/subsystems/observability/index.js +3 -3
- package/dist/src/cli/index.js +195 -20
- package/dist/src/cli/index.js.map +1 -1
- package/dist/src/index.js +8 -8
- package/package.json +1 -1
- package/runtime/http/pagination.ts +233 -0
- package/runtime/subsystems/events/event-bus.drizzle-backend.ts +16 -4
- package/templates/entity/new/clean-lite-ps/controller.ejs.t +27 -6
- package/templates/entity/new/clean-lite-ps/dto/list-query.ejs.t +22 -0
- package/templates/entity/new/clean-lite-ps/index.ejs.t +1 -0
- package/templates/entity/new/clean-lite-ps/prompt-extension.js +14 -0
- package/templates/entity/new/clean-lite-ps/use-cases/list.ejs.t +56 -3
- package/templates/entity/new/prompt.js +17 -0
- package/dist/chunk-PNCOUFFI.js.map +0 -1
- /package/dist/{chunk-XNRKZCVH.js.map → chunk-36NRG2EP.js.map} +0 -0
- /package/dist/{chunk-COGHTKXY.js.map → chunk-7625PLY7.js.map} +0 -0
- /package/dist/{chunk-CDLWYZVQ.js.map → chunk-BHZP6LOV.js.map} +0 -0
- /package/dist/{chunk-CZQUOIDY.js.map → chunk-DKKFTHHI.js.map} +0 -0
- /package/dist/{chunk-HLURWFIT.js.map → chunk-IASPGFFK.js.map} +0 -0
- /package/dist/{chunk-CKLM57IE.js.map → chunk-KS4BZHIA.js.map} +0 -0
- /package/dist/{chunk-7XDB4OMR.js.map → chunk-VCXOPBYY.js.map} +0 -0
- /package/dist/{chunk-3VEVGL74.js.map → chunk-VNBC3VXM.js.map} +0 -0
- /package/dist/{chunk-QXYKV4CE.js.map → chunk-W4JYZSQK.js.map} +0 -0
- /package/dist/{chunk-6M6LZEP6.js.map → chunk-YHVZAL6U.js.map} +0 -0
- /package/dist/{chunk-QO35B6BN.js.map → chunk-YIVQ7KLS.js.map} +0 -0
- /package/dist/{chunk-ENAR3F5S.js.map → chunk-Z7YFYK6H.js.map} +0 -0
package/dist/src/index.js
CHANGED
|
@@ -47,14 +47,18 @@ import {
|
|
|
47
47
|
validatePatternProject
|
|
48
48
|
} from "../chunk-K4BQQ2NN.js";
|
|
49
49
|
import "../chunk-KVOWSC5S.js";
|
|
50
|
+
import "../chunk-VCXOPBYY.js";
|
|
50
51
|
import "../chunk-PRWIX6UW.js";
|
|
51
|
-
import "../chunk-
|
|
52
|
-
import "../chunk-QXYKV4CE.js";
|
|
52
|
+
import "../chunk-W4JYZSQK.js";
|
|
53
53
|
import "../chunk-EO2QPOKH.js";
|
|
54
|
-
import "../chunk-
|
|
54
|
+
import "../chunk-SQDOBLBP.js";
|
|
55
|
+
import "../chunk-YIVQ7KLS.js";
|
|
56
|
+
import "../chunk-LG57S2SC.js";
|
|
57
|
+
import "../chunk-IASPGFFK.js";
|
|
58
|
+
import "../chunk-S5G3HO7N.js";
|
|
59
|
+
import "../chunk-MZ6GV4YF.js";
|
|
55
60
|
import "../chunk-HNWZFNKP.js";
|
|
56
61
|
import "../chunk-AHV4GDYM.js";
|
|
57
|
-
import "../chunk-SQDOBLBP.js";
|
|
58
62
|
import "../chunk-43SBT72G.js";
|
|
59
63
|
import "../chunk-4MF3HKJA.js";
|
|
60
64
|
import "../chunk-TIZXQU26.js";
|
|
@@ -62,10 +66,6 @@ import "../chunk-JEINYUJH.js";
|
|
|
62
66
|
import "../chunk-5TK7MEN4.js";
|
|
63
67
|
import "../chunk-4KNXX6TI.js";
|
|
64
68
|
import "../chunk-3CJFPU6Q.js";
|
|
65
|
-
import "../chunk-QO35B6BN.js";
|
|
66
|
-
import "../chunk-MZ6GV4YF.js";
|
|
67
|
-
import "../chunk-LG57S2SC.js";
|
|
68
|
-
import "../chunk-S5G3HO7N.js";
|
|
69
69
|
import "../chunk-U64T4YZE.js";
|
|
70
70
|
import "../chunk-2E224ZSN.js";
|
|
71
71
|
export {
|
package/package.json
CHANGED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pagination envelope + ListQuery contract for generated entity list endpoints
|
|
3
|
+
* (pagination-by-default).
|
|
4
|
+
*
|
|
5
|
+
* Every generated `GET /<entities>` returns a {@link Page} envelope instead of
|
|
6
|
+
* a bare `T[]`. The request shape is {@link ListQuery} (page/cursor/pageSize +
|
|
7
|
+
* default sort) merged with arbitrary where-filters at the controller.
|
|
8
|
+
*
|
|
9
|
+
* Mirrors the in-repo precedent: the jobs subsystem's `JobRunPage`
|
|
10
|
+
* (`{ items, nextCursor }`) and its opaque keyset cursor codec
|
|
11
|
+
* (`runtime/subsystems/jobs/job-run-keyset-cursor.ts`). The entity envelope
|
|
12
|
+
* EXTENDS that minimal shape with `page/pageCount/total/pageSize` so a numbered
|
|
13
|
+
* UI (jump-to-page) works while `nextCursor` stays contract-stable for the
|
|
14
|
+
* later keyset upgrade.
|
|
15
|
+
*
|
|
16
|
+
* ENGINE NOTE (v1): the list use-case fetches by OFFSET (page-based). The
|
|
17
|
+
* `nextCursor` is computed from the last row and emitted from day one so the
|
|
18
|
+
* contract never changes, but cursor-REQUEST honoring (keyset seek) is a
|
|
19
|
+
* DEFERRED seam — see the TODO in the generated list use-case / the repository
|
|
20
|
+
* query branch. `ListQuery.cursor` is ACCEPTED (no validation error) even
|
|
21
|
+
* though v1 ignores it for fetching.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { z } from 'zod';
|
|
25
|
+
|
|
26
|
+
// ============================================================================
|
|
27
|
+
// Defaults + clamp
|
|
28
|
+
// ============================================================================
|
|
29
|
+
|
|
30
|
+
/** Default page size when `pageSize` is omitted. */
|
|
31
|
+
export const DEFAULT_PAGE_SIZE = 50;
|
|
32
|
+
/** Hard upper bound on page size to keep a single read bounded. */
|
|
33
|
+
export const MAX_PAGE_SIZE = 200;
|
|
34
|
+
/** Default page (1-based) when `page` is omitted. */
|
|
35
|
+
export const DEFAULT_PAGE = 1;
|
|
36
|
+
/** Default sort column. */
|
|
37
|
+
export const DEFAULT_SORT_BY = 'created_at';
|
|
38
|
+
/** Default sort direction. */
|
|
39
|
+
export const DEFAULT_SORT_ORDER = 'desc' as const;
|
|
40
|
+
|
|
41
|
+
/** Clamp a caller-supplied `pageSize` into `[1, MAX_PAGE_SIZE]`. */
|
|
42
|
+
export function clampPageSize(pageSize: number | undefined): number {
|
|
43
|
+
if (typeof pageSize !== 'number' || !Number.isFinite(pageSize)) {
|
|
44
|
+
return DEFAULT_PAGE_SIZE;
|
|
45
|
+
}
|
|
46
|
+
const floored = Math.floor(pageSize);
|
|
47
|
+
if (floored < 1) return 1;
|
|
48
|
+
if (floored > MAX_PAGE_SIZE) return MAX_PAGE_SIZE;
|
|
49
|
+
return floored;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Clamp a caller-supplied `page` to a 1-based integer (floor 1). */
|
|
53
|
+
export function clampPage(page: number | undefined): number {
|
|
54
|
+
if (typeof page !== 'number' || !Number.isFinite(page)) {
|
|
55
|
+
return DEFAULT_PAGE;
|
|
56
|
+
}
|
|
57
|
+
const floored = Math.floor(page);
|
|
58
|
+
return floored < 1 ? 1 : floored;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ============================================================================
|
|
62
|
+
// ListQuery schema (request)
|
|
63
|
+
// ============================================================================
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Zod schema for the universal list query string. All keys optional —
|
|
67
|
+
* pagination works fully UNFILTERED (the default mode). `pageSize` is clamped
|
|
68
|
+
* (default 50, max 200) and `sort_order` defaults to `desc`. Arbitrary where
|
|
69
|
+
* filters are NOT modeled here (they're parsed/passed through at the controller
|
|
70
|
+
* via `.passthrough()`); this schema owns ONLY the pagination + sort knobs so
|
|
71
|
+
* the defaults + clamp land in one place.
|
|
72
|
+
*
|
|
73
|
+
* `cursor` is accepted but v1 ignores it for fetching (offset engine) — the
|
|
74
|
+
* keyset seek is the deferred seam. Passing a `nextCursor` back never errors.
|
|
75
|
+
*/
|
|
76
|
+
export const ListQuerySchema = z
|
|
77
|
+
.object({
|
|
78
|
+
page: z.coerce.number().int().optional(),
|
|
79
|
+
cursor: z.string().optional(),
|
|
80
|
+
pageSize: z.coerce.number().int().optional(),
|
|
81
|
+
sort_by: z.string().optional(),
|
|
82
|
+
sort_order: z.enum(['asc', 'desc']).optional(),
|
|
83
|
+
})
|
|
84
|
+
.passthrough();
|
|
85
|
+
|
|
86
|
+
/** Parsed list query (pre-clamp). Use {@link resolveListQuery} to normalize. */
|
|
87
|
+
export type ListQuery = z.infer<typeof ListQuerySchema>;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Normalized pagination options resolved from a raw {@link ListQuery}: clamped
|
|
91
|
+
* `page`/`pageSize`, computed `offset`, and a defaulted sort. The generated
|
|
92
|
+
* list use-case feeds these straight into `service.list({ limit, offset, ... })`.
|
|
93
|
+
*/
|
|
94
|
+
export interface ResolvedListQuery {
|
|
95
|
+
page: number;
|
|
96
|
+
pageSize: number;
|
|
97
|
+
/** `(page - 1) * pageSize`. */
|
|
98
|
+
offset: number;
|
|
99
|
+
sortBy: string;
|
|
100
|
+
sortOrder: 'asc' | 'desc';
|
|
101
|
+
/** Opaque cursor as passed by the caller (v1: not honored — deferred seam). */
|
|
102
|
+
cursor?: string;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Resolve a raw list query into normalized, clamped pagination options.
|
|
107
|
+
* Defaults: page 1, pageSize 50 (max 200), sort `created_at desc`.
|
|
108
|
+
*/
|
|
109
|
+
export function resolveListQuery(query: ListQuery | undefined): ResolvedListQuery {
|
|
110
|
+
const page = clampPage(query?.page);
|
|
111
|
+
const pageSize = clampPageSize(query?.pageSize);
|
|
112
|
+
return {
|
|
113
|
+
page,
|
|
114
|
+
pageSize,
|
|
115
|
+
offset: (page - 1) * pageSize,
|
|
116
|
+
sortBy: query?.sort_by ?? DEFAULT_SORT_BY,
|
|
117
|
+
sortOrder: query?.sort_order ?? DEFAULT_SORT_ORDER,
|
|
118
|
+
cursor: query?.cursor,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// ============================================================================
|
|
123
|
+
// Page envelope (response)
|
|
124
|
+
// ============================================================================
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* One page of a paginated list response. EXTENDS the jobs subsystem's minimal
|
|
128
|
+
* `{ items, nextCursor }` shape with the numbered-UI fields:
|
|
129
|
+
*
|
|
130
|
+
* - `page` — 1-based page number of THIS page.
|
|
131
|
+
* - `pageCount` — total number of pages (`ceil(total / pageSize)`, min 1).
|
|
132
|
+
* - `total` — total matching rows (reflects any where-filter).
|
|
133
|
+
* - `pageSize` — the (clamped) page size used.
|
|
134
|
+
* - `nextCursor` — opaque keyset cursor of the LAST row, or `null` on the
|
|
135
|
+
* last page / empty result. Contract-stable from day one;
|
|
136
|
+
* v1 emits it but fetches by offset.
|
|
137
|
+
*/
|
|
138
|
+
export interface Page<T> {
|
|
139
|
+
items: T[];
|
|
140
|
+
page: number;
|
|
141
|
+
pageCount: number;
|
|
142
|
+
total: number;
|
|
143
|
+
pageSize: number;
|
|
144
|
+
nextCursor: string | null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ============================================================================
|
|
148
|
+
// Opaque cursor codec (encodes (createdAt, id))
|
|
149
|
+
// ============================================================================
|
|
150
|
+
|
|
151
|
+
/** Keyset tuple a {@link Page.nextCursor} encodes. */
|
|
152
|
+
export interface PageKeyset {
|
|
153
|
+
/** `created_at` of the last row on this page. */
|
|
154
|
+
createdAt: Date;
|
|
155
|
+
/** `id` (UUID) tie-break of the last row on this page. */
|
|
156
|
+
id: string;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Encode a `(createdAt, id)` keyset into an opaque, base64url cursor. The shape
|
|
161
|
+
* (a JSON tuple) is an implementation detail — never parse it outside this
|
|
162
|
+
* module. Mirrors `encodeKeysetCursor` in the jobs subsystem.
|
|
163
|
+
*/
|
|
164
|
+
export function encodeCursor(keyset: PageKeyset): string {
|
|
165
|
+
const tuple = [keyset.createdAt.toISOString(), keyset.id];
|
|
166
|
+
return Buffer.from(JSON.stringify(tuple), 'utf8').toString('base64url');
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Decode an opaque cursor back into its `(createdAt, id)` keyset. Returns
|
|
171
|
+
* `null` for a malformed cursor so a caller can treat garbage as "start from
|
|
172
|
+
* the beginning" rather than throw on user-supplied data.
|
|
173
|
+
*/
|
|
174
|
+
export function decodeCursor(cursor: string): PageKeyset | null {
|
|
175
|
+
try {
|
|
176
|
+
const json = Buffer.from(cursor, 'base64url').toString('utf8');
|
|
177
|
+
const parsed = JSON.parse(json) as unknown;
|
|
178
|
+
if (!Array.isArray(parsed) || parsed.length !== 2) return null;
|
|
179
|
+
const [iso, id] = parsed;
|
|
180
|
+
if (typeof iso !== 'string' || typeof id !== 'string') return null;
|
|
181
|
+
const createdAt = new Date(iso);
|
|
182
|
+
if (Number.isNaN(createdAt.getTime())) return null;
|
|
183
|
+
return { createdAt, id };
|
|
184
|
+
} catch {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Compute the `nextCursor` for a page of rows: the opaque cursor of the LAST
|
|
191
|
+
* row when more pages remain, else `null`. A row is expected to carry
|
|
192
|
+
* `createdAt: Date` and `id: string` (the default-sort keyset). Rows missing
|
|
193
|
+
* either field yield `null` (cursor not derivable — caller falls back to offset
|
|
194
|
+
* paging, which is the v1 engine anyway).
|
|
195
|
+
*
|
|
196
|
+
* @param rows the items on this page (already fetched, in sort order)
|
|
197
|
+
* @param hasMore whether more rows exist beyond this page
|
|
198
|
+
* (`offset + rows.length < total`)
|
|
199
|
+
*/
|
|
200
|
+
export function computeNextCursor(
|
|
201
|
+
rows: ReadonlyArray<unknown>,
|
|
202
|
+
hasMore: boolean,
|
|
203
|
+
): string | null {
|
|
204
|
+
if (!hasMore || rows.length === 0) return null;
|
|
205
|
+
const last = rows[rows.length - 1] as { createdAt?: unknown; id?: unknown };
|
|
206
|
+
const createdAt = last?.createdAt;
|
|
207
|
+
const id = last?.id;
|
|
208
|
+
if (!(createdAt instanceof Date) || typeof id !== 'string') return null;
|
|
209
|
+
return encodeCursor({ createdAt, id });
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Assemble a {@link Page} envelope from a fetched page of rows + the total
|
|
214
|
+
* matching count + the resolved query. Computes `pageCount` and `nextCursor`.
|
|
215
|
+
* The single place the envelope shape is constructed, so the generated list
|
|
216
|
+
* use-case stays a thin call.
|
|
217
|
+
*/
|
|
218
|
+
export function buildPage<T>(
|
|
219
|
+
items: T[],
|
|
220
|
+
total: number,
|
|
221
|
+
resolved: Pick<ResolvedListQuery, 'page' | 'pageSize' | 'offset'>,
|
|
222
|
+
): Page<T> {
|
|
223
|
+
const pageCount = total === 0 ? 1 : Math.ceil(total / resolved.pageSize);
|
|
224
|
+
const hasMore = resolved.offset + items.length < total;
|
|
225
|
+
return {
|
|
226
|
+
items,
|
|
227
|
+
page: resolved.page,
|
|
228
|
+
pageCount,
|
|
229
|
+
total,
|
|
230
|
+
pageSize: resolved.pageSize,
|
|
231
|
+
nextCursor: computeNextCursor(items as ReadonlyArray<unknown>, hasMore),
|
|
232
|
+
};
|
|
233
|
+
}
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
*/
|
|
31
31
|
import { randomUUID } from 'node:crypto';
|
|
32
32
|
import { Injectable, OnModuleDestroy, OnModuleInit, Inject, Logger, Optional } from '@nestjs/common';
|
|
33
|
-
import { eq, and, inArray, asc, desc, gte, lt, or, sql, type SQL } from 'drizzle-orm';
|
|
33
|
+
import { eq, and, inArray, asc, desc, gte, lt, lte, or, sql, type SQL } from 'drizzle-orm';
|
|
34
34
|
import type {
|
|
35
35
|
DomainEvent,
|
|
36
36
|
DrizzleTransaction,
|
|
@@ -584,10 +584,22 @@ export class DrizzleEventBus implements IEventBus, IEventReadPort, OnModuleInit,
|
|
|
584
584
|
private async processBatch(): Promise<void> {
|
|
585
585
|
const pools = this.opts.pools;
|
|
586
586
|
|
|
587
|
-
// Build WHERE: status='pending' [AND pool IN (...)]
|
|
587
|
+
// Build WHERE: status='pending' AND occurred_at <= now [AND pool IN (...)].
|
|
588
|
+
//
|
|
589
|
+
// The readiness gate (`occurred_at <= now`) is what makes a scheduler-
|
|
590
|
+
// materialised *future* slot wait. The EventScheduler pre-inserts the next
|
|
591
|
+
// slot with `occurred_at = slotStart` in the future and deliberately does
|
|
592
|
+
// NOT NOTIFY-wake the drainer for it (see materializeScheduledEvent: a
|
|
593
|
+
// future slot is claimed by polling once its `occurred_at` passes). Without
|
|
594
|
+
// this predicate the claim is status-only, so the very next poll grabs the
|
|
595
|
+
// future-dated row and stamps `processed_at = now()` early — surfacing rows
|
|
596
|
+
// that read "N minutes from now" yet are already processed, and firing
|
|
597
|
+
// scheduled triggers up to one interval ahead of their slot. Normal events
|
|
598
|
+
// publish with `occurred_at = now()`, so the gate is transparent to them.
|
|
599
|
+
const ready = lte(domainEvents.occurredAt, new Date());
|
|
588
600
|
const whereClause: SQL<unknown> = pools && pools.length > 0
|
|
589
|
-
? (and(eq(domainEvents.status, 'pending'), inArray(domainEvents.pool, pools)) as SQL<unknown>)
|
|
590
|
-
: eq(domainEvents.status, 'pending');
|
|
601
|
+
? (and(eq(domainEvents.status, 'pending'), ready, inArray(domainEvents.pool, pools)) as SQL<unknown>)
|
|
602
|
+
: (and(eq(domainEvents.status, 'pending'), ready) as SQL<unknown>);
|
|
591
603
|
|
|
592
604
|
// Claim a batch with FOR UPDATE SKIP LOCKED so multiple pollers don't
|
|
593
605
|
// double-dispatch. The lock is released when the outer transaction
|
|
@@ -4,8 +4,12 @@ skip_if: "<%= typeof clpOutputPaths === 'undefined' %>"
|
|
|
4
4
|
force: true
|
|
5
5
|
---
|
|
6
6
|
<%- typeof generatedBanner !== 'undefined' ? generatedBanner : '' %>
|
|
7
|
-
import { Controller, Get<% if (generateWrites) { %>, Post, Patch, Delete, Body, Headers<% } %>, NotFoundException, Param, ParseUUIDPipe } from '@nestjs/common';
|
|
8
|
-
import { ApiBearerAuth, <% if (generateWrites) { %>ApiBody, <% } %>ApiOperation, ApiParam, ApiResponse } from '@nestjs/swagger';
|
|
7
|
+
import { Controller, Get<% if (generateWrites) { %>, Post, Patch, Delete, Body, Headers<% } %>, NotFoundException, Param, ParseUUIDPipe, Query } from '@nestjs/common';
|
|
8
|
+
import { ApiBearerAuth, <% if (generateWrites) { %>ApiBody, <% } %>ApiOperation, ApiParam, ApiQuery, ApiResponse } from '@nestjs/swagger';
|
|
9
|
+
import { ZodValidationPipe } from '<%= typeof zodValidationPipeImport !== 'undefined' ? zodValidationPipeImport : '@shared/pipes/zod-validation.pipe' %>';
|
|
10
|
+
import type { Page } from '<%= typeof paginationImport !== 'undefined' ? paginationImport : '@shared/http/pagination' %>';
|
|
11
|
+
import { <%= classNames.listQuerySchema %> } from './dto/list-<%= entityNamePlural %>.query';
|
|
12
|
+
import type { <%= classNames.listQueryDto %> } from './dto/list-<%= entityNamePlural %>.query';
|
|
9
13
|
import { <%= classNames.findByIdUseCase %> } from './use-cases/find-<%= entityName %>-by-id.use-case';
|
|
10
14
|
import { <%= classNames.listUseCase %> } from './use-cases/list-<%= entityNamePlural %>.use-case';
|
|
11
15
|
<% if (eavEnabled) { -%>
|
|
@@ -13,7 +17,6 @@ import { <%= classNames.findByIdWithFieldsUseCase %> } from './use-cases/find-<%
|
|
|
13
17
|
import { <%= classNames.listWithFieldsUseCase %> } from './use-cases/list-<%= entityNamePlural %>-with-fields.use-case';
|
|
14
18
|
<% } -%>
|
|
15
19
|
<% if (generateWrites) { -%>
|
|
16
|
-
import { ZodValidationPipe } from '<%= typeof zodValidationPipeImport !== 'undefined' ? zodValidationPipeImport : '@shared/pipes/zod-validation.pipe' %>';
|
|
17
20
|
import { <%= classNames.createUseCase %> } from './use-cases/create-<%= entityName %>.use-case';
|
|
18
21
|
import { <%= classNames.updateUseCase %> } from './use-cases/update-<%= entityName %>.use-case';
|
|
19
22
|
import { <%= classNames.deleteUseCase %> } from './use-cases/delete-<%= entityName %>.use-case';
|
|
@@ -47,14 +50,32 @@ export class <%= classNames.controller %> {
|
|
|
47
50
|
) {}
|
|
48
51
|
|
|
49
52
|
@ApiOperation({ summary: 'List <%= entityNamePlural %>', operationId: 'list<%= classNames.entity %>s' })
|
|
53
|
+
@ApiQuery({ name: 'page', required: false, type: 'integer', description: '1-based page number (default 1).' })
|
|
54
|
+
@ApiQuery({ name: 'pageSize', required: false, type: 'integer', description: 'Page size (default 50, max 200).' })
|
|
55
|
+
@ApiQuery({ name: 'cursor', required: false, type: 'string', description: 'Opaque keyset cursor (accepted; v1 paginates by offset).' })
|
|
56
|
+
@ApiQuery({ name: 'sort_by', required: false, type: 'string', description: "Sort column (default 'created_at')." })
|
|
57
|
+
@ApiQuery({ name: 'sort_order', required: false, enum: ['asc', 'desc'], description: "Sort direction (default 'desc')." })
|
|
50
58
|
@ApiResponse({
|
|
51
59
|
status: 200,
|
|
52
|
-
schema: {
|
|
60
|
+
schema: {
|
|
61
|
+
type: 'object',
|
|
62
|
+
properties: {
|
|
63
|
+
items: { type: 'array', items: { $ref: '#/components/schemas/<%= classNames.outputDto %>' } },
|
|
64
|
+
page: { type: 'integer' },
|
|
65
|
+
pageCount: { type: 'integer' },
|
|
66
|
+
total: { type: 'integer' },
|
|
67
|
+
pageSize: { type: 'integer' },
|
|
68
|
+
nextCursor: { type: 'string', nullable: true },
|
|
69
|
+
},
|
|
70
|
+
required: ['items', 'page', 'pageCount', 'total', 'pageSize', 'nextCursor'],
|
|
71
|
+
},
|
|
53
72
|
})
|
|
54
73
|
@ApiResponse({ status: 401, schema: { $ref: '#/components/schemas/ErrorResponseDto' } })
|
|
55
74
|
@Get()
|
|
56
|
-
async getAll(
|
|
57
|
-
|
|
75
|
+
async getAll(
|
|
76
|
+
@Query(new ZodValidationPipe(<%= classNames.listQuerySchema %>)) query: <%= classNames.listQueryDto %>,
|
|
77
|
+
): Promise<Page<<%= classNames.entity %>>> {
|
|
78
|
+
return this.listUseCase.execute(query);
|
|
58
79
|
}
|
|
59
80
|
<% if (eavEnabled) { %>
|
|
60
81
|
@ApiOperation({
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: "<%= typeof clpOutputPaths !== 'undefined' ? clpOutputPaths.listQueryDto : null %>"
|
|
3
|
+
skip_if: "<%= typeof clpOutputPaths === 'undefined' %>"
|
|
4
|
+
force: true
|
|
5
|
+
---
|
|
6
|
+
<%- typeof generatedBanner !== 'undefined' ? generatedBanner : '' %>
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { ListQuerySchema } from '<%= typeof paginationImport !== 'undefined' ? paginationImport : '@shared/http/pagination' %>';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* List query DTO for `GET /<%= entityNamePlural %>` (pagination-by-default).
|
|
12
|
+
*
|
|
13
|
+
* Re-exports the shared `ListQuerySchema` (page/cursor/pageSize/sort_by/
|
|
14
|
+
* sort_order + `.passthrough()` for arbitrary where-filters). pageSize is
|
|
15
|
+
* clamped (default 50, max 200) and the default sort is `created_at desc, id
|
|
16
|
+
* desc` — both applied in the list use-case via `resolveListQuery`. `cursor` is
|
|
17
|
+
* accepted but v1 ignores it for fetching (offset engine); the keyset seek is a
|
|
18
|
+
* deferred seam.
|
|
19
|
+
*/
|
|
20
|
+
export const <%= classNames.listQuerySchema %> = ListQuerySchema;
|
|
21
|
+
|
|
22
|
+
export type <%= classNames.listQueryDto %> = z.infer<typeof <%= classNames.listQuerySchema %>>;
|
|
@@ -19,3 +19,4 @@ export type { <%= classNames.entity %> } from './<%= entityName %>.entity';
|
|
|
19
19
|
export type { <%= classNames.createDto %> } from './dto/create-<%= entityName %>.dto';
|
|
20
20
|
export type { <%= classNames.updateDto %> } from './dto/update-<%= entityName %>.dto';
|
|
21
21
|
export type { <%= classNames.outputDto %> } from './dto/<%= entityName %>-output.dto';
|
|
22
|
+
export type { <%= classNames.listQueryDto %> } from './dto/list-<%= entityNamePlural %>.query';
|
|
@@ -1296,6 +1296,9 @@ export function buildCleanLitePsLocals(definition, baseLocals) {
|
|
|
1296
1296
|
createDto: `${moduleGroupDir}/${entityNamePlural}/dto/create-${entityName}.dto.ts`,
|
|
1297
1297
|
updateDto: `${moduleGroupDir}/${entityNamePlural}/dto/update-${entityName}.dto.ts`,
|
|
1298
1298
|
outputDto: `${moduleGroupDir}/${entityNamePlural}/dto/${entityName}-output.dto.ts`,
|
|
1299
|
+
// Pagination-by-default: the universal list query DTO (page/cursor/pageSize
|
|
1300
|
+
// + sort). Always emitted — the list endpoint is unconditional.
|
|
1301
|
+
listQueryDto: `${moduleGroupDir}/${entityNamePlural}/dto/list-${entityNamePlural}.query.ts`,
|
|
1299
1302
|
searchUseCase: searchQueryResolved
|
|
1300
1303
|
? `${moduleGroupDir}/${entityNamePlural}/use-cases/search-${entityNamePlural}.use-case.ts`
|
|
1301
1304
|
: null,
|
|
@@ -1347,6 +1350,10 @@ export function buildCleanLitePsLocals(definition, baseLocals) {
|
|
|
1347
1350
|
createSchema: `Create${entityNamePascal}Schema`,
|
|
1348
1351
|
updateSchema: `Update${entityNamePascal}Schema`,
|
|
1349
1352
|
outputSchema: `${entityNamePascal}OutputSchema`,
|
|
1353
|
+
// Pagination-by-default: list query DTO + schema (re-export of the shared
|
|
1354
|
+
// ListQuerySchema). Named per-entity so the controller import is unambiguous.
|
|
1355
|
+
listQueryDto: `List${entityNamePluralPascal}QueryDto`,
|
|
1356
|
+
listQuerySchema: `List${entityNamePluralPascal}QuerySchema`,
|
|
1350
1357
|
};
|
|
1351
1358
|
|
|
1352
1359
|
// Fields for create DTO: exclude id, behavior-managed fields, and FK fields
|
|
@@ -1413,6 +1420,12 @@ export function buildCleanLitePsLocals(definition, baseLocals) {
|
|
|
1413
1420
|
baseLocals?.drizzleTokenImport ?? '@shared/constants/tokens';
|
|
1414
1421
|
const drizzleTypeImport =
|
|
1415
1422
|
baseLocals?.drizzleTypeImport ?? '@shared/types/drizzle';
|
|
1423
|
+
// Pagination contract (pagination-by-default). Package mode → the runtime
|
|
1424
|
+
// module `@pattern-stack/codegen/runtime/http/pagination`; vendored / default
|
|
1425
|
+
// → the consumer-owned `@shared/http/pagination`. Threaded from prompt.js;
|
|
1426
|
+
// unit tests that call buildCleanLitePsLocals directly get the @shared default.
|
|
1427
|
+
const paginationImport =
|
|
1428
|
+
baseLocals?.paginationImport ?? '@shared/http/pagination';
|
|
1416
1429
|
|
|
1417
1430
|
return {
|
|
1418
1431
|
// Clean-Lite-PS identity
|
|
@@ -1431,6 +1444,7 @@ export function buildCleanLitePsLocals(definition, baseLocals) {
|
|
|
1431
1444
|
typedEventBusImport,
|
|
1432
1445
|
drizzleTokenImport,
|
|
1433
1446
|
drizzleTypeImport,
|
|
1447
|
+
paginationImport,
|
|
1434
1448
|
|
|
1435
1449
|
// Pattern — registry-driven (ADR-031)
|
|
1436
1450
|
patternName,
|
|
@@ -4,14 +4,67 @@ force: true
|
|
|
4
4
|
---
|
|
5
5
|
<%- typeof generatedBanner !== 'undefined' ? generatedBanner : '' %>
|
|
6
6
|
import { Injectable } from '@nestjs/common';
|
|
7
|
+
import { asc, desc, sql, type SQL } from 'drizzle-orm';
|
|
8
|
+
import { buildPage, resolveListQuery, type ListQuery, type Page } from '<%= typeof paginationImport !== 'undefined' ? paginationImport : '@shared/http/pagination' %>';
|
|
7
9
|
import { <%= classNames.service %> } from '../<%= entityName %>.service';
|
|
8
|
-
import
|
|
10
|
+
import { <%= entityNamePlural %>, type <%= classNames.entity %> } from '../<%= entityName %>.entity';
|
|
9
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Paginated list use-case for <%= entityNamePlural %> (pagination-by-default).
|
|
14
|
+
*
|
|
15
|
+
* Composes `service.list({ where, limit, offset, orderBy })` + `service.count(where)`
|
|
16
|
+
* into a `Page<<%- classNames.entity %>>` envelope. Defaults: page 1,
|
|
17
|
+
* pageSize 50 (max 200), sort `created_at desc, id desc`. `total`/`pageCount`
|
|
18
|
+
* reflect the (optionally filtered) set, so pagination composes with where
|
|
19
|
+
* filters orthogonally — it works fully unfiltered too.
|
|
20
|
+
*
|
|
21
|
+
* v1 ENGINE = OFFSET. `nextCursor` is computed from the last row and emitted
|
|
22
|
+
* (contract-stable), but cursor-REQUEST honoring (keyset seek) is DEFERRED:
|
|
23
|
+
* `resolved.cursor` is accepted and ignored here. The keyset swap belongs in
|
|
24
|
+
* the marked seam below — fetch by `WHERE (created_at, id) < decodeCursor(cursor)`
|
|
25
|
+
* instead of `offset` — and is otherwise invisible to the controller/UI.
|
|
26
|
+
*/
|
|
10
27
|
@Injectable()
|
|
11
28
|
export class <%= classNames.listUseCase %> {
|
|
12
29
|
constructor(private readonly service: <%= classNames.service %>) {}
|
|
13
30
|
|
|
14
|
-
async execute(): Promise<<%= classNames.entity
|
|
15
|
-
|
|
31
|
+
async execute(query?: ListQuery): Promise<Page<<%= classNames.entity %>>> {
|
|
32
|
+
const resolved = resolveListQuery(query);
|
|
33
|
+
|
|
34
|
+
// Default sort: `created_at desc, id desc` (id is the stable keyset
|
|
35
|
+
// tie-break). A caller `sort_by` that names a real column is honored in the
|
|
36
|
+
// requested direction with the id tie-break appended; an unknown column
|
|
37
|
+
// falls back to the default. Composed as a single SQL fragment because the
|
|
38
|
+
// base repository's `orderBy` takes one expression.
|
|
39
|
+
const dir = resolved.sortOrder === 'asc' ? asc : desc;
|
|
40
|
+
const col = (<%= entityNamePlural %> as unknown as Record<string, unknown>)[
|
|
41
|
+
resolved.sortBy.replace(/_([a-z])/g, (_m: string, c: string) => c.toUpperCase())
|
|
42
|
+
];
|
|
43
|
+
const orderBy: SQL =
|
|
44
|
+
col === undefined
|
|
45
|
+
? sql`${desc(<%= entityNamePlural %>.createdAt)}, ${desc(<%= entityNamePlural %>.id)}`
|
|
46
|
+
: sql`${dir(col as never)}, ${desc(<%= entityNamePlural %>.id)}`;
|
|
47
|
+
|
|
48
|
+
// Arbitrary where-filters are NOT modeled in v1 (the ListQuery owns only
|
|
49
|
+
// pagination + sort); `where` stays undefined so the list is unfiltered by
|
|
50
|
+
// default. A future filter seam ANDs predicates here and passes the same
|
|
51
|
+
// `where` to both `list` and `count` so `total`/`pageCount` stay accurate.
|
|
52
|
+
const where: SQL | undefined = undefined;
|
|
53
|
+
|
|
54
|
+
// KEYSET SEAM (deferred — v1 fetches by offset). When the keyset upgrade
|
|
55
|
+
// lands, branch here on `resolved.cursor`: decode it and fetch by
|
|
56
|
+
// `WHERE (created_at, id) < (cursorCreatedAt, cursorId)` LIMIT pageSize,
|
|
57
|
+
// dropping the offset. The envelope + nextCursor below are unchanged.
|
|
58
|
+
const [items, total] = await Promise.all([
|
|
59
|
+
this.service.list({
|
|
60
|
+
where,
|
|
61
|
+
limit: resolved.pageSize,
|
|
62
|
+
offset: resolved.offset,
|
|
63
|
+
orderBy,
|
|
64
|
+
}),
|
|
65
|
+
this.service.count(where),
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
return buildPage(items, total, resolved);
|
|
16
69
|
}
|
|
17
70
|
}
|
|
@@ -1380,6 +1380,22 @@ export default {
|
|
|
1380
1380
|
const typedEventBusImport = subsystemsImport(runtimeMode, 'events');
|
|
1381
1381
|
const drizzleTokenImport = runtimeImport(runtimeMode, 'constants/tokens');
|
|
1382
1382
|
const drizzleTypeImport = runtimeImport(runtimeMode, 'types/drizzle');
|
|
1383
|
+
// Pagination contract (pagination-by-default). ASYMMETRIC by mode:
|
|
1384
|
+
// - package → `@pattern-stack/codegen/runtime/http/pagination` (Page<T>,
|
|
1385
|
+
// ListQuerySchema, resolveListQuery, buildPage, cursor codec) — the
|
|
1386
|
+
// package-published runtime; swe-brain consumes this green.
|
|
1387
|
+
// - vendored → `@shared/http/page` (vendored to `src/shared/http/page.ts`
|
|
1388
|
+
// by project init's VENDORED_RUNTIME_FILES). DISTINCT from the consumer's
|
|
1389
|
+
// OPTIONAL `@shared/http/pagination` search contract ({items,total,limit,
|
|
1390
|
+
// offset}) — vendoring the Page<T> envelope to `/pagination` would
|
|
1391
|
+
// clobber it, so the list envelope lives at `/page`.
|
|
1392
|
+
// Unlike most @shared/http/* files (which the package never owns), THIS one
|
|
1393
|
+
// IS package-published — the list endpoint is unconditional, so its contract
|
|
1394
|
+
// must ship with codegen (package mode) and be vendored (vendored mode).
|
|
1395
|
+
const paginationImport =
|
|
1396
|
+
runtimeMode === 'vendored'
|
|
1397
|
+
? '@shared/http/page'
|
|
1398
|
+
: runtimeImport(runtimeMode, 'http/pagination');
|
|
1383
1399
|
// Integration subsystem barrel (ADR-033.1 inline-sync `integration-source`
|
|
1384
1400
|
// module — emitted only for entities with an inline `detection:` block).
|
|
1385
1401
|
const integrationSubsystemImport = subsystemsImport(runtimeMode, 'integration');
|
|
@@ -1602,6 +1618,7 @@ export default {
|
|
|
1602
1618
|
typedEventBusImport,
|
|
1603
1619
|
drizzleTokenImport,
|
|
1604
1620
|
drizzleTypeImport,
|
|
1621
|
+
paginationImport,
|
|
1605
1622
|
integrationSubsystemImport,
|
|
1606
1623
|
withAnalyticsImport,
|
|
1607
1624
|
integrationUpsertConfigImport,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../runtime/subsystems/events/event-bus.drizzle-backend.ts"],"sourcesContent":["/**\n * DrizzleEventBus — Postgres-backed event bus using the transactional outbox pattern.\n *\n * Events are inserted into the `domain_events` table within the caller's\n * Drizzle transaction. A background polling loop (started on module init)\n * reads unprocessed events and dispatches them to registered subscribers.\n *\n * When the transaction rolls back, the event is never persisted — no\n * phantom events.\n *\n * Pool awareness (EVT-4):\n * - On `publish`/`publishMany` the backend writes `metadata.pool`,\n * `metadata.direction`, and `metadata.tenantId` into the first-class\n * `pool` / `direction` / `tenant_id` columns (metadata JSON is still\n * written unchanged for protocol stability).\n * - The drain loop filters by `opts.pools` when provided, so separate\n * processes (e.g. one per `events_inbound` / `events_change` /\n * `events_outbound`) can claim only their own lane. `pools: undefined`\n * drains all pending rows (backwards-compatible behaviour).\n *\n * EVT-Q7: No stale-event sweeper. `FOR UPDATE SKIP LOCKED` is\n * self-healing — the row is only locked for the duration of the\n * enclosing polling transaction; the `status='processed'` update happens\n * within that same transaction. There is no `claimed_at` semantic (unlike\n * jobs), so no stale rows can exist.\n *\n * This backend is suitable until you need real-time fan-out or very high\n * throughput. At that point, swap the backend for Redis Streams or similar\n * via EventsModule.forRoot({ backend: '...' }) without touching use cases.\n */\nimport { randomUUID } from 'node:crypto';\nimport { Injectable, OnModuleDestroy, OnModuleInit, Inject, Logger, Optional } from '@nestjs/common';\nimport { eq, and, inArray, asc, desc, gte, lt, or, sql, type SQL } from 'drizzle-orm';\nimport type {\n DomainEvent,\n DrizzleTransaction,\n IEventBus,\n ScheduledEventSpec,\n} from './event-bus.protocol';\nimport type {\n EventPage,\n IEventReadPort,\n ListEventsQuery,\n} from './event-read.protocol';\nimport {\n clampEventLimit,\n decodeEventCursor,\n encodeEventCursor,\n} from './event-keyset-cursor';\nimport type { DrizzleClient } from '../../types/drizzle';\nimport { domainEvents, type DomainEventRecord } from './domain-events.schema';\nimport { DRIZZLE } from '../../constants/tokens';\nimport { EVENTS_MODULE_OPTIONS } from './events.tokens';\nimport type { EventsModuleOptions } from './events.module';\nimport { BRIDGE_OUTBOX_DRAIN_HOOK } from '../bridge/bridge.tokens';\nimport type { IBridgeOutboxDrainHook } from '../bridge/bridge.protocol';\nimport {\n EVENTS_WAKE_CHANNEL,\n PgNotifyListener,\n pgNotify,\n} from '../jobs/pg-notify';\n\n/** How long to wait between polling cycles (ms). */\nconst POLL_INTERVAL_MS = 1_000;\n/** Max events claimed per polling cycle to bound memory usage. */\nconst POLL_BATCH_SIZE = 50;\n\n/**\n * Row shape built from `metadata` for writing into `domain_events`. Keeps\n * the per-event extraction logic in one place so publish/publishMany stay\n * in sync.\n */\nfunction toInsertValues(event: DomainEvent, multiTenant: boolean) {\n const metadata = event.metadata ?? undefined;\n const pool = (metadata?.['pool'] as string | undefined) ?? null;\n const direction = (metadata?.['direction'] as string | undefined) ?? null;\n // AUDIT-1: tier defaults to 'domain' when absent. The DB CHECK\n // constraint (`domain_events_tier_routing_check`) enforces the\n // tier ⇔ routing-fields invariant at the storage boundary; no\n // JS-side assertion is needed here.\n const tier = (metadata?.['tier'] as string | undefined) ?? 'domain';\n const base = {\n id: event.id,\n type: event.type,\n aggregateId: event.aggregateId,\n aggregateType: event.aggregateType,\n payload: event.payload,\n occurredAt: event.occurredAt,\n processedAt: null,\n status: 'pending' as const,\n metadata: event.metadata,\n pool,\n direction,\n tier,\n };\n // EVT-8: `tenant_id` is a scaffold-time conditional column, emitted only\n // when `events.multi_tenant: true`. Only write it when multi-tenancy is\n // on — under single-tenant scaffolds the column does not exist, so the\n // key must be omitted from the insert.\n if (!multiTenant) return base;\n const tenantId = (metadata?.['tenantId'] as string | undefined) ?? null;\n return { ...base, tenantId };\n}\n\n/**\n * Project a raw `domain_events` row into the narrow `EventSummary` shape.\n * Shared with the memory backend via this helper kept module-local to each\n * backend (the events subsystem has no cross-backend projection file yet;\n * the two are byte-identical and small).\n */\nfunction toEventSummary(r: DomainEventRecord) {\n const metadata = (r.metadata ?? undefined) as\n | Record<string, unknown>\n | undefined;\n const rootRunId = metadata?.['rootRunId'];\n return {\n id: r.id,\n type: r.type,\n aggregateId: r.aggregateId,\n aggregateType: r.aggregateType,\n status: r.status,\n pool: r.pool,\n direction: r.direction,\n tier: r.tier,\n rootRunId: typeof rootRunId === 'string' ? rootRunId : null,\n // EVT-8: `tenant_id` is a scaffold-time conditional column. Read it\n // structurally so this projection typechecks against both the\n // multi-tenant schema (column present) and the single-tenant schema\n // (column absent → undefined → null).\n tenantId: (r as { tenantId?: string | null }).tenantId ?? null,\n occurredAt:\n r.occurredAt instanceof Date\n ? r.occurredAt\n : new Date(r.occurredAt as unknown as string),\n processedAt:\n r.processedAt == null\n ? null\n : r.processedAt instanceof Date\n ? r.processedAt\n : new Date(r.processedAt as unknown as string),\n };\n}\n\n/**\n * Postgres unique-violation (SQLSTATE 23505) test. Used by the scheduled-event\n * materialiser (ADR-039) to treat a slot-key collision as the\n * already-materialised no-op. Reads `.code` defensively across driver shapes\n * (node-postgres surfaces it on the error, some wrappers nest it on `.cause`).\n */\nfunction isUniqueViolation(err: unknown): boolean {\n const code = (err as { code?: unknown; cause?: { code?: unknown } } | undefined);\n return code?.code === '23505' || code?.cause?.code === '23505';\n}\n\n@Injectable()\nexport class DrizzleEventBus implements IEventBus, IEventReadPort, OnModuleInit, OnModuleDestroy {\n private readonly logger = new Logger(DrizzleEventBus.name);\n private polling = false;\n private pollTimer: ReturnType<typeof setTimeout> | null = null;\n private readonly handlers = new Map<string, Set<(event: DomainEvent) => Promise<void>>>();\n private readonly opts: EventsModuleOptions;\n\n // LISTEN-NOTIFY-1 — dedicated wake listener + debounce state. `null` when\n // `listenNotify` is off (the common case); polling is the only driver then.\n private notifyListener: PgNotifyListener | null = null;\n /** True while a wake-driven drain is in flight (debounce gate). */\n private wakeDraining = false;\n /** A notify arrived mid-drain → re-drain once when the current drain ends. */\n private wakeRecheckPending = false;\n\n constructor(\n @Inject(DRIZZLE) private readonly db: DrizzleClient,\n @Optional() @Inject(EVENTS_MODULE_OPTIONS) opts?: EventsModuleOptions,\n /**\n * Bridge subsystem hook (BRIDGE-4). Optional — when the bridge\n * subsystem is not installed in the consuming app, this token is\n * undefined and the drain skips the bridge block entirely (preserves\n * EVT-4 baseline behaviour).\n *\n * When provided, `processEvent` is invoked once per drained event\n * INSIDE the per-event tx, before `processed_at` is stamped. The\n * hook owns all knowledge of `bridge_delivery + wrapper job_run`\n * shapes; the events subsystem stays unaware of bridge schemas.\n */\n @Optional()\n @Inject(BRIDGE_OUTBOX_DRAIN_HOOK)\n private readonly bridgeHook: IBridgeOutboxDrainHook | null = null,\n ) {\n // Default so direct construction (e.g. integration tests not going\n // through Nest DI) keeps working without an explicit options object.\n this.opts = opts ?? { backend: 'drizzle' };\n }\n\n // ============================================================================\n // Lifecycle\n // ============================================================================\n\n async onModuleInit(): Promise<void> {\n this.polling = true;\n this.schedulePoll();\n\n // LISTEN-NOTIFY-1 — start the wake listener ALONGSIDE the poll timer. A\n // notify for one of this drainer's pools triggers an immediate drain; the\n // interval timer above stays the durability heartbeat. Startup is\n // fire-and-forget — a connect failure self-heals via the listener's backoff.\n if (this.opts.listenNotify) {\n const pool = (this.db as unknown as { $client?: unknown }).$client;\n if (!pool || typeof (pool as { connect?: unknown }).connect !== 'function') {\n this.logger.warn(\n `listen_notify enabled but the Drizzle client exposes no pg Pool ` +\n `($client.connect missing) — falling back to interval polling only.`,\n );\n } else {\n this.notifyListener = new PgNotifyListener({\n channel: EVENTS_WAKE_CHANNEL,\n pool: pool as { connect(): Promise<never> },\n label: 'events',\n onNotify: (payload) => this.onWake(payload),\n });\n await this.notifyListener.start();\n }\n }\n }\n\n async onModuleDestroy(): Promise<void> {\n this.polling = false;\n if (this.pollTimer) {\n clearTimeout(this.pollTimer);\n this.pollTimer = null;\n }\n if (this.notifyListener) {\n try {\n await this.notifyListener.stop();\n } catch (err) {\n this.logger.error(`notify listener stop failed: ${err}`);\n }\n this.notifyListener = null;\n }\n }\n\n /**\n * Wake handler — a `codegen_events_wake` notification arrived. A pool-filtered\n * drainer (`opts.pools` set) ignores payloads naming a pool it doesn't own; an\n * all-pools drainer wakes for any. Debounced: a notify mid-drain just flags a\n * re-check so a burst collapses to at most one extra drain (D3).\n */\n private onWake(payload: string): void {\n if (!this.polling) return;\n const pools = this.opts.pools;\n if (pools && pools.length > 0 && !pools.includes(payload)) return;\n if (this.wakeDraining) {\n this.wakeRecheckPending = true;\n return;\n }\n void this.drainOnWake();\n }\n\n private async drainOnWake(): Promise<void> {\n this.wakeDraining = true;\n try {\n do {\n this.wakeRecheckPending = false;\n await this.processBatch();\n } while (this.wakeRecheckPending && this.polling);\n } catch (err) {\n this.logger.error(`wake drain error: ${err}`);\n } finally {\n this.wakeDraining = false;\n }\n }\n\n // ============================================================================\n // IEventBus\n // ============================================================================\n\n async publish(event: DomainEvent, tx?: DrizzleTransaction): Promise<void> {\n const client = (tx ?? this.db) as DrizzleClient;\n const multiTenant = this.opts.multiTenant ?? false;\n const values = toInsertValues(event, multiTenant);\n await client.insert(domainEvents).values(values);\n // LISTEN-NOTIFY-1 — wake the drainer on commit (D2: emitted through the same\n // `client`, so a rolled-back publish emits no phantom wake). The pool is the\n // payload; the drainer re-runs its own pool-filtered claim on wake.\n await this.emitWakeNotify(client, [values.pool]);\n }\n\n async publishMany(events: DomainEvent[], tx?: DrizzleTransaction): Promise<void> {\n if (events.length === 0) return;\n const client = (tx ?? this.db) as DrizzleClient;\n const multiTenant = this.opts.multiTenant ?? false;\n const valuesList = events.map((e) => toInsertValues(e, multiTenant));\n await client.insert(domainEvents).values(valuesList);\n // De-dup pools so a batch into one lane emits a single wake.\n await this.emitWakeNotify(client, valuesList.map((v) => v.pool));\n }\n\n /**\n * Emit one in-tx `pg_notify(codegen_events_wake, <pool>)` per distinct pool in\n * the just-inserted batch. No-op unless `listenNotify` is on. Best-effort: a\n * notify failure is non-fatal (interval polling still drains the rows), so we\n * log + swallow rather than failing the publish.\n */\n private async emitWakeNotify(\n client: DrizzleClient,\n pools: Array<string | null>,\n ): Promise<void> {\n if (!this.opts.listenNotify) return;\n const distinct = new Set(pools.map((p) => p ?? ''));\n for (const pool of distinct) {\n try {\n await pgNotify(client, EVENTS_WAKE_CHANNEL, pool);\n } catch (err) {\n this.logger.warn(\n `pg_notify(${EVENTS_WAKE_CHANNEL}, '${pool}') failed: ${err} ` +\n `(non-fatal — interval polling still drains the outbox).`,\n );\n }\n }\n }\n\n async findById(eventId: string): Promise<DomainEvent | null> {\n const rows = await this.db\n .select()\n .from(domainEvents)\n .where(eq(domainEvents.id, eventId))\n .limit(1);\n const row = rows[0];\n if (!row) return null;\n return {\n id: row.id,\n type: row.type,\n aggregateId: row.aggregateId,\n aggregateType: row.aggregateType,\n payload: row.payload as Record<string, unknown>,\n occurredAt:\n row.occurredAt instanceof Date\n ? row.occurredAt\n : new Date(row.occurredAt as unknown as string),\n metadata: (row.metadata ?? undefined) as\n | Record<string, unknown>\n | undefined,\n };\n }\n\n subscribe<T extends DomainEvent = DomainEvent>(\n eventType: string,\n handler: (event: T) => Promise<void>,\n ): () => void {\n if (!this.handlers.has(eventType)) {\n this.handlers.set(eventType, new Set());\n }\n const set = this.handlers.get(eventType)!;\n const h = handler as (event: DomainEvent) => Promise<void>;\n set.add(h);\n return () => {\n set.delete(h);\n };\n }\n\n // ============================================================================\n // ADR-039 — scheduled-event materialisation (time as an event source)\n // ============================================================================\n\n /**\n * Insert one scheduled tick event idempotently. The slot key is stamped onto\n * `metadata.scheduleSlot`; `ON CONFLICT DO NOTHING` against the partial UNIQUE\n * expression index `idx_domain_events_schedule_slot` makes a duplicate insert\n * a no-op — the DB constraint is the exactly-one-event-per-slot invariant.\n *\n * Reuses the standard outbox row shape (pool/direction/metadata) so the\n * existing drain carries the tick like any other event. A LISTEN/NOTIFY wake\n * fires for an immediately-due tick (boot/catch-up rows whose slot is already\n * in the past); a future slot is claimed by polling once `occurred_at` passes.\n */\n async materializeScheduledEvent(\n spec: ScheduledEventSpec,\n ): Promise<{ created: boolean }> {\n const multiTenant = this.opts.multiTenant ?? false;\n const metadata: Record<string, unknown> = {\n pool: spec.pool,\n direction: spec.direction,\n scheduleSlot: spec.slotKey,\n triggerSource: 'schedule',\n };\n const base = {\n id: randomUUID(),\n type: spec.type,\n // Payload-free scheduled fact (the dealbrain strict-producer pattern).\n aggregateId: spec.type,\n aggregateType: spec.type,\n payload: {} as Record<string, unknown>,\n occurredAt: spec.slotStart,\n processedAt: null,\n status: 'pending' as const,\n metadata,\n pool: spec.pool,\n direction: spec.direction,\n tier: 'domain' as const,\n };\n const values = multiTenant ? { ...base, tenantId: null } : base;\n\n // The idempotency guard is the partial UNIQUE expression index\n // `idx_domain_events_schedule_slot` on (type, metadata->>'scheduleSlot').\n // Use a BARE (no-target) `ON CONFLICT DO NOTHING`: Drizzle 0.45's typed\n // `onConflictDoNothing({ target })` only accepts columns so it can't NAME\n // the expression index, but the no-arg form emits target-less\n // `ON CONFLICT DO NOTHING`, which Postgres applies to ANY unique\n // constraint/index — including this expression index. `.returning({ id })`\n // then gives us the rowcount discriminator: zero rows back == the slot was\n // already materialised (DO NOTHING fired), so `created: false`. This keeps\n // the happy path off the exception channel — a repeat materialise no longer\n // raises SQLSTATE 23505, so Postgres logs no scary `duplicate key value\n // violates unique constraint` ERROR line on every colliding boot/tick.\n //\n // The unique-violation catch is retained as a fallback for the genuine\n // concurrent-insert race window (two sessions clear the conflict check and\n // both attempt the insert in the same instant) and for backends whose\n // driver surfaces a 23505 rather than honouring DO NOTHING; in both cases\n // it collapses to the same `created: false` no-op.\n let inserted: Array<{ id: string }>;\n try {\n inserted = await this.db\n .insert(domainEvents)\n .values(values)\n .onConflictDoNothing()\n .returning({ id: domainEvents.id });\n } catch (err) {\n if (isUniqueViolation(err)) return { created: false };\n throw err;\n }\n if (inserted.length === 0) return { created: false };\n\n // Wake the drainer for an already-due tick. A future slot waits for polling.\n if (spec.slotStart.getTime() <= Date.now()) {\n await this.emitWakeNotify(this.db, [spec.pool]);\n }\n return { created: true };\n }\n\n /** Most recent scheduled tick's `occurred_at` (epoch ms) for `type`, or null.\n * Read by the scheduler's catch-up backfill. */\n async lastScheduledSlotMs(type: string): Promise<number | null> {\n const rows = await this.db\n .select({ occurredAt: domainEvents.occurredAt })\n .from(domainEvents)\n .where(\n and(\n eq(domainEvents.type, type),\n sql`${domainEvents.metadata} ->> 'triggerSource' = 'schedule'`,\n ),\n )\n .orderBy(desc(domainEvents.occurredAt))\n .limit(1);\n const row = rows[0];\n if (!row?.occurredAt) return null;\n return row.occurredAt instanceof Date\n ? row.occurredAt.getTime()\n : new Date(row.occurredAt as unknown as string).getTime();\n }\n\n // ============================================================================\n // IEventReadPort (OBS-LIST-1)\n // ============================================================================\n\n async listEvents(query: ListEventsQuery = {}): Promise<EventPage> {\n const limit = clampEventLimit(query.limit);\n const conditions: SQL<unknown>[] = [];\n\n if (query.poolId) conditions.push(eq(domainEvents.pool, query.poolId));\n if (query.direction)\n conditions.push(eq(domainEvents.direction, query.direction));\n if (query.since) conditions.push(gte(domainEvents.occurredAt, query.since));\n if (query.rootRunId) {\n // Filter on the JSON correlation id: metadata->>'rootRunId'.\n conditions.push(\n sql`${domainEvents.metadata}->>'rootRunId' = ${query.rootRunId}`,\n );\n }\n // EVT-8: `tenant_id` is a scaffold-time conditional column (emitted only\n // under `events.multi_tenant: true`). Guard the filter behind the same\n // `multiTenant` flag, and read the column structurally so this backend\n // typechecks against both the multi-tenant schema (column present) and\n // the single-tenant schema (column absent). When multi-tenancy is off\n // there is no `tenant_id` column to filter on.\n if (this.opts.multiTenant && query.tenantId !== undefined) {\n const tenantIdColumn = (\n domainEvents as unknown as { tenantId: typeof domainEvents.pool }\n ).tenantId;\n conditions.push(\n query.tenantId === null\n ? (sql`${tenantIdColumn} is null` as SQL<unknown>)\n : eq(tenantIdColumn, query.tenantId),\n );\n }\n\n // Keyset seek: WHERE (occurred_at, id) < (cursorOccurredAt, cursorId).\n if (query.cursor) {\n const keyset = decodeEventCursor(query.cursor);\n if (keyset) {\n conditions.push(\n or(\n lt(domainEvents.occurredAt, keyset.occurredAt),\n and(\n eq(domainEvents.occurredAt, keyset.occurredAt),\n lt(domainEvents.id, keyset.id),\n ),\n )!,\n );\n }\n }\n\n const rows = (await this.db\n .select()\n .from(domainEvents)\n .where(conditions.length > 0 ? and(...conditions) : undefined)\n .orderBy(desc(domainEvents.occurredAt), desc(domainEvents.id))\n .limit(limit + 1)) as DomainEventRecord[];\n\n const hasMore = rows.length > limit;\n const page = hasMore ? rows.slice(0, limit) : rows;\n const items = page.map(toEventSummary);\n const last = page[page.length - 1];\n const nextCursor =\n hasMore && last\n ? encodeEventCursor({ occurredAt: last.occurredAt, id: last.id })\n : null;\n\n return { items, nextCursor };\n }\n\n // ============================================================================\n // Polling\n // ============================================================================\n\n /**\n * Test-only hook. Runs exactly one drain cycle and returns. Production\n * code goes through `onModuleInit` → `schedulePoll`, which calls the\n * same `processBatch` under a timer.\n */\n async drainOnce(): Promise<void> {\n await this.processBatch();\n }\n\n private schedulePoll(): void {\n if (!this.polling) return;\n this.pollTimer = setTimeout(async () => {\n try {\n await this.processBatch();\n } catch (err) {\n this.logger.error(`Poll cycle error: ${err}`);\n } finally {\n this.schedulePoll();\n }\n }, POLL_INTERVAL_MS);\n }\n\n /**\n * Drain one batch (BRIDGE-4 restructure of EVT-4).\n *\n * Two-phase per drained event:\n *\n * 1. **Per-event transaction** — bridge fanout (`bridgeHook.processEvent`)\n * + `processed_at` stamp. Both write through the same `tx`. A throw\n * inside the tx (only infra-level failures should reach here, since\n * the hook tolerates null direction and registry misses inline)\n * rolls back the bridge inserts AND the `processed_at` stamp; the\n * event re-claims on the next drain cycle. Bridge `UNIQUE\n * (event_id, trigger_id)` makes the retry idempotent.\n *\n * 2. **After commit** — dispatch in-process subscribers (`IEventBus.subscribe`\n * handlers). This deliberately runs OUTSIDE the per-event tx (lead\n * decision 2026-04-22): subscribers are best-effort and must not\n * gate forward progress or roll back bridge fanout. Subscriber\n * errors are caught + logged; `processed_at` is already committed.\n * The old `MAX_RETRIES=3` in-process retry loop and the\n * `failed`-stamping path were removed in BRIDGE-4 along with their\n * coupling.\n *\n * The `processed_at` UPDATE carries `AND status='pending'` (BRIDGE-4\n * tightening — without it, a hypothetical double-claim could double-stamp\n * the timestamp). The per-event tx + `FOR UPDATE SKIP LOCKED` claim\n * make this defensive belt-and-suspenders.\n */\n private async processBatch(): Promise<void> {\n const pools = this.opts.pools;\n\n // Build WHERE: status='pending' [AND pool IN (...)]\n const whereClause: SQL<unknown> = pools && pools.length > 0\n ? (and(eq(domainEvents.status, 'pending'), inArray(domainEvents.pool, pools)) as SQL<unknown>)\n : eq(domainEvents.status, 'pending');\n\n // Claim a batch with FOR UPDATE SKIP LOCKED so multiple pollers don't\n // double-dispatch. The lock is released when the outer transaction\n // commits — which is fine because the immediately-following per-event\n // tx flips status='processed' under its own `AND status='pending'`\n // guard, so a re-claim of the same row in a subsequent batch is a\n // no-op UPDATE.\n const rows = await this.db.transaction(async (tx) => {\n return tx\n .select()\n .from(domainEvents)\n .where(whereClause)\n .orderBy(asc(domainEvents.occurredAt))\n .limit(POLL_BATCH_SIZE)\n .for('update', { skipLocked: true });\n }) as Array<typeof domainEvents.$inferSelect>;\n\n for (const row of rows) {\n const event: DomainEvent = {\n id: row.id,\n type: row.type,\n aggregateId: row.aggregateId,\n aggregateType: row.aggregateType,\n payload: row.payload as Record<string, unknown>,\n occurredAt: row.occurredAt instanceof Date ? row.occurredAt : new Date(row.occurredAt as unknown as string),\n metadata: (row.metadata ?? undefined) as Record<string, unknown> | undefined,\n };\n\n // Phase 1 — per-event tx: bridge fanout + processed_at stamp.\n try {\n await this.db.transaction(async (tx) => {\n if (this.bridgeHook) {\n await this.bridgeHook.processEvent(event, tx);\n }\n await tx\n .update(domainEvents)\n .set({ status: 'processed', processedAt: new Date() })\n .where(\n and(\n eq(domainEvents.id, event.id),\n eq(domainEvents.status, 'pending'),\n ),\n );\n });\n } catch (err) {\n // Infra-level failure inside the per-event tx — bridge inserts\n // and processed_at both rolled back. Log and move on; the next\n // drain cycle re-claims the row. UNIQUE on bridge_delivery makes\n // the retry idempotent.\n this.logger.error(\n `Per-event tx failed for event id=${event.id} type=${event.type}: ${err}`,\n );\n continue;\n }\n\n // Phase 2 — best-effort subscriber dispatch. Errors are logged\n // and discarded; processed_at is already committed. Subscribers\n // are observability + cache-busts + small ancillary work; they\n // must not gate forward progress.\n try {\n await this.dispatch(event);\n } catch (err) {\n this.logger.error(\n `Subscriber dispatch failed for event id=${event.id} type=${event.type} ` +\n `(processed_at already committed; failure does not retry): ${err}`,\n );\n }\n }\n }\n\n private async dispatch(event: DomainEvent): Promise<void> {\n const set = this.handlers.get(event.type);\n if (!set) return;\n\n let firstError: unknown;\n for (const handler of set) {\n try {\n await handler(event);\n } catch (err) {\n this.logger.error(\n `Handler error for event type \"${event.type}\" (id: ${event.id}): ${err}`,\n );\n if (firstError === undefined) {\n firstError = err;\n }\n }\n }\n\n if (firstError !== undefined) {\n throw firstError;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAS,kBAAkB;AAC3B,SAAS,YAA2C,QAAQ,QAAQ,gBAAgB;AACpF,SAAS,IAAI,KAAK,SAAS,KAAK,MAAM,KAAK,IAAI,IAAI,WAAqB;AA+BxE,IAAM,mBAAmB;AAEzB,IAAM,kBAAkB;AAOxB,SAAS,eAAe,OAAoB,aAAsB;AAChE,QAAM,WAAW,MAAM,YAAY;AACnC,QAAM,OAAQ,WAAW,MAAM,KAA4B;AAC3D,QAAM,YAAa,WAAW,WAAW,KAA4B;AAKrE,QAAM,OAAQ,WAAW,MAAM,KAA4B;AAC3D,QAAM,OAAO;AAAA,IACX,IAAI,MAAM;AAAA,IACV,MAAM,MAAM;AAAA,IACZ,aAAa,MAAM;AAAA,IACnB,eAAe,MAAM;AAAA,IACrB,SAAS,MAAM;AAAA,IACf,YAAY,MAAM;AAAA,IAClB,aAAa;AAAA,IACb,QAAQ;AAAA,I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wBAAwB;AAAA,GA9BvB;","names":[]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|