@haneinfo/domain-events 11.0.4
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/LICENSE +14 -0
- package/admin.d.ts +2 -0
- package/admin.js +7 -0
- package/dist/admin/domain-events-admin.controller.d.ts +18 -0
- package/dist/admin/domain-events-admin.controller.d.ts.map +1 -0
- package/dist/admin/domain-events-admin.controller.js +95 -0
- package/dist/admin/domain-events-admin.controller.js.map +1 -0
- package/dist/admin/domain-events-admin.module.d.ts +19 -0
- package/dist/admin/domain-events-admin.module.d.ts.map +1 -0
- package/dist/admin/domain-events-admin.module.js +56 -0
- package/dist/admin/domain-events-admin.module.js.map +1 -0
- package/dist/admin/domain-events-admin.service.d.ts +23 -0
- package/dist/admin/domain-events-admin.service.d.ts.map +1 -0
- package/dist/admin/domain-events-admin.service.js +212 -0
- package/dist/admin/domain-events-admin.service.js.map +1 -0
- package/dist/admin/dto/domain-event-admin.dto.d.ts +17 -0
- package/dist/admin/dto/domain-event-admin.dto.d.ts.map +1 -0
- package/dist/admin/dto/domain-event-admin.dto.js +12 -0
- package/dist/admin/dto/domain-event-admin.dto.js.map +1 -0
- package/dist/admin/types.d.ts +48 -0
- package/dist/admin/types.d.ts.map +1 -0
- package/dist/admin/types.js +5 -0
- package/dist/admin/types.js.map +1 -0
- package/dist/admin.d.ts +6 -0
- package/dist/admin.d.ts.map +1 -0
- package/dist/admin.js +26 -0
- package/dist/admin.js.map +1 -0
- package/dist/diff-changed-fields.d.ts +4 -0
- package/dist/diff-changed-fields.d.ts.map +1 -0
- package/dist/diff-changed-fields.js +38 -0
- package/dist/diff-changed-fields.js.map +1 -0
- package/dist/dispatcher-config.d.ts +6 -0
- package/dist/dispatcher-config.d.ts.map +1 -0
- package/dist/dispatcher-config.js +26 -0
- package/dist/dispatcher-config.js.map +1 -0
- package/dist/domain-event-dispatcher.service.d.ts +40 -0
- package/dist/domain-event-dispatcher.service.d.ts.map +1 -0
- package/dist/domain-event-dispatcher.service.js +261 -0
- package/dist/domain-event-dispatcher.service.js.map +1 -0
- package/dist/domain-event-errors.d.ts +16 -0
- package/dist/domain-event-errors.d.ts.map +1 -0
- package/dist/domain-event-errors.js +28 -0
- package/dist/domain-event-errors.js.map +1 -0
- package/dist/domain-event-registry.d.ts +47 -0
- package/dist/domain-event-registry.d.ts.map +1 -0
- package/dist/domain-event-registry.js +98 -0
- package/dist/domain-event-registry.js.map +1 -0
- package/dist/domain-event-subscriber.decorator.d.ts +27 -0
- package/dist/domain-event-subscriber.decorator.d.ts.map +1 -0
- package/dist/domain-event-subscriber.decorator.js +55 -0
- package/dist/domain-event-subscriber.decorator.js.map +1 -0
- package/dist/domain-events.module.d.ts +24 -0
- package/dist/domain-events.module.d.ts.map +1 -0
- package/dist/domain-events.module.js +88 -0
- package/dist/domain-events.module.js.map +1 -0
- package/dist/domain-events.service.d.ts +22 -0
- package/dist/domain-events.service.d.ts.map +1 -0
- package/dist/domain-events.service.js +105 -0
- package/dist/domain-events.service.js.map +1 -0
- package/dist/frontend/domain-event-catalog-table.d.ts +3 -0
- package/dist/frontend/domain-event-catalog-table.d.ts.map +1 -0
- package/dist/frontend/domain-event-catalog-table.js +20 -0
- package/dist/frontend/domain-event-catalog-table.js.map +1 -0
- package/dist/frontend/domain-event-deliveries-panel.d.ts +3 -0
- package/dist/frontend/domain-event-deliveries-panel.d.ts.map +1 -0
- package/dist/frontend/domain-event-deliveries-panel.js +36 -0
- package/dist/frontend/domain-event-deliveries-panel.js.map +1 -0
- package/dist/frontend/domain-event-detail-panel.d.ts +3 -0
- package/dist/frontend/domain-event-detail-panel.d.ts.map +1 -0
- package/dist/frontend/domain-event-detail-panel.js +15 -0
- package/dist/frontend/domain-event-detail-panel.js.map +1 -0
- package/dist/frontend/domain-events-table.d.ts +3 -0
- package/dist/frontend/domain-events-table.d.ts.map +1 -0
- package/dist/frontend/domain-events-table.js +10 -0
- package/dist/frontend/domain-events-table.js.map +1 -0
- package/dist/frontend/index.d.ts +6 -0
- package/dist/frontend/index.d.ts.map +1 -0
- package/dist/frontend/index.js +19 -0
- package/dist/frontend/index.js.map +1 -0
- package/dist/frontend/types.d.ts +104 -0
- package/dist/frontend/types.d.ts.map +1 -0
- package/dist/frontend/types.js +3 -0
- package/dist/frontend/types.js.map +1 -0
- package/dist/frontend.d.ts +9 -0
- package/dist/frontend.d.ts.map +1 -0
- package/dist/frontend.js +11 -0
- package/dist/frontend.js.map +1 -0
- package/dist/guards/domain-events-admin.guard.d.ts +24 -0
- package/dist/guards/domain-events-admin.guard.d.ts.map +1 -0
- package/dist/guards/domain-events-admin.guard.js +99 -0
- package/dist/guards/domain-events-admin.guard.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin.d.ts +11 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +98 -0
- package/dist/plugin.js.map +1 -0
- package/dist/receipt.d.ts +41 -0
- package/dist/receipt.d.ts.map +1 -0
- package/dist/receipt.js +77 -0
- package/dist/receipt.js.map +1 -0
- package/dist/schema-drift-check.d.ts +42 -0
- package/dist/schema-drift-check.d.ts.map +1 -0
- package/dist/schema-drift-check.js +324 -0
- package/dist/schema-drift-check.js.map +1 -0
- package/dist/testing.d.ts +150 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +148 -0
- package/dist/testing.js.map +1 -0
- package/dist/types.d.ts +162 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +29 -0
- package/dist/types.js.map +1 -0
- package/dist/webhook.d.ts +21 -0
- package/dist/webhook.d.ts.map +1 -0
- package/dist/webhook.js +234 -0
- package/dist/webhook.js.map +1 -0
- package/docs/check-domain-events-subscribers.template.ts +95 -0
- package/docs/prisma-model.md +160 -0
- package/haneinfo.plugin.json +79 -0
- package/package.json +108 -0
- package/plugin.d.ts +1 -0
- package/plugin.js +4 -0
- package/prisma/domain-events.prisma +102 -0
- package/testing.d.ts +2 -0
- package/testing.js +7 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-drift-check.d.ts","sourceRoot":"","sources":["../src/schema-drift-check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAE5F,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AA+NvD;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,oBAAoB,GAAG,MAAM,EAAE,CAqGrF"}
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Structural drift check for the `DomainEvent`/`DomainEventDelivery` Prisma model pattern this
|
|
4
|
+
* package documents in `docs/prisma-model.md`. The package intentionally does not ship or inject
|
|
5
|
+
* a `.prisma` schema fragment (plan 026 §11.1 G6; Z20 §19-5) — each app owns its own migration
|
|
6
|
+
* history — so this is the same "documented pattern + drift-check script" approach
|
|
7
|
+
* `check:schema-docs` already uses for enum doc-comments (dev_docs/002 §Prisma conventions).
|
|
8
|
+
*
|
|
9
|
+
* `DomainEventDispatcherService.claimDueDeliveries()` hardcodes the physical table/column names
|
|
10
|
+
* below in raw SQL (see its comment). A consuming app whose schema drifts from this pattern would
|
|
11
|
+
* fail at runtime with an opaque Postgres error; this check catches that at migration/CI time
|
|
12
|
+
* instead, against the app's own generated `Prisma.dmmf.datamodel` — never a hand-maintained
|
|
13
|
+
* schema string.
|
|
14
|
+
*
|
|
15
|
+
* Usage from a consuming app (mirrors `check:schema-docs`'s own entrypoint pattern):
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { Prisma } from "@prisma/client";
|
|
19
|
+
* import { checkDomainEventSchemaDrift } from "@haneinfo/domain-events";
|
|
20
|
+
*
|
|
21
|
+
* const issues = checkDomainEventSchemaDrift(Prisma.dmmf.datamodel);
|
|
22
|
+
* for (const issue of issues) console.error(`[domain-events-schema-drift] ${issue}`);
|
|
23
|
+
* if (issues.length > 0) process.exit(1);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.checkDomainEventSchemaDrift = checkDomainEventSchemaDrift;
|
|
28
|
+
const EXPECTED_MODELS = [
|
|
29
|
+
{
|
|
30
|
+
name: 'DomainEvent',
|
|
31
|
+
table: 'domain_events',
|
|
32
|
+
fields: [
|
|
33
|
+
{ name: 'id', kind: 'scalar', type: 'String', isId: true, default: { name: 'cuid' } },
|
|
34
|
+
{ name: 'seq', kind: 'scalar', type: 'BigInt', default: { name: 'autoincrement' } },
|
|
35
|
+
{ name: 'aggregateType', kind: 'scalar', type: 'String', column: 'aggregate_type' },
|
|
36
|
+
{ name: 'aggregateId', kind: 'scalar', type: 'String', column: 'aggregate_id' },
|
|
37
|
+
{ name: 'eventType', kind: 'scalar', type: 'String', column: 'event_type' },
|
|
38
|
+
{ name: 'operation', kind: 'enum', type: 'DomainEventOperation' },
|
|
39
|
+
{ name: 'schemaVersion', kind: 'scalar', type: 'Int', column: 'schema_version', default: 1 },
|
|
40
|
+
{
|
|
41
|
+
name: 'actorUserId',
|
|
42
|
+
kind: 'scalar',
|
|
43
|
+
type: 'String',
|
|
44
|
+
optional: true,
|
|
45
|
+
column: 'actor_user_id',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'correlationId',
|
|
49
|
+
kind: 'scalar',
|
|
50
|
+
type: 'String',
|
|
51
|
+
optional: true,
|
|
52
|
+
column: 'correlation_id',
|
|
53
|
+
},
|
|
54
|
+
{ name: 'workflowId', kind: 'scalar', type: 'String', optional: true, column: 'workflow_id' },
|
|
55
|
+
{ name: 'before', kind: 'scalar', type: 'Json', optional: true },
|
|
56
|
+
{ name: 'after', kind: 'scalar', type: 'Json', optional: true },
|
|
57
|
+
{
|
|
58
|
+
name: 'changedFields',
|
|
59
|
+
kind: 'scalar',
|
|
60
|
+
type: 'String',
|
|
61
|
+
isList: true,
|
|
62
|
+
column: 'changed_fields',
|
|
63
|
+
},
|
|
64
|
+
{ name: 'metadata', kind: 'scalar', type: 'Json', optional: true },
|
|
65
|
+
{
|
|
66
|
+
name: 'integrationCapabilityId',
|
|
67
|
+
kind: 'scalar',
|
|
68
|
+
type: 'String',
|
|
69
|
+
optional: true,
|
|
70
|
+
column: 'integration_capability_id',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: 'integrationCapabilityVersion',
|
|
74
|
+
kind: 'scalar',
|
|
75
|
+
type: 'String',
|
|
76
|
+
optional: true,
|
|
77
|
+
column: 'integration_capability_version',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: 'integrationCapabilityDigest',
|
|
81
|
+
kind: 'scalar',
|
|
82
|
+
type: 'String',
|
|
83
|
+
optional: true,
|
|
84
|
+
column: 'integration_capability_digest',
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: 'integrationBindingId',
|
|
88
|
+
kind: 'scalar',
|
|
89
|
+
type: 'String',
|
|
90
|
+
optional: true,
|
|
91
|
+
column: 'integration_binding_id',
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: 'integrationBindingVersion',
|
|
95
|
+
kind: 'scalar',
|
|
96
|
+
type: 'String',
|
|
97
|
+
optional: true,
|
|
98
|
+
column: 'integration_binding_version',
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: 'integrationEnvelopeVersion',
|
|
102
|
+
kind: 'scalar',
|
|
103
|
+
type: 'String',
|
|
104
|
+
optional: true,
|
|
105
|
+
column: 'integration_envelope_version',
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: 'integrationSourceApp',
|
|
109
|
+
kind: 'scalar',
|
|
110
|
+
type: 'String',
|
|
111
|
+
optional: true,
|
|
112
|
+
column: 'integration_source_app',
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: 'integrationPayload',
|
|
116
|
+
kind: 'scalar',
|
|
117
|
+
type: 'Json',
|
|
118
|
+
optional: true,
|
|
119
|
+
column: 'integration_payload',
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
name: 'integrationPayloadDigest',
|
|
123
|
+
kind: 'scalar',
|
|
124
|
+
type: 'String',
|
|
125
|
+
optional: true,
|
|
126
|
+
column: 'integration_payload_digest',
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: 'createdAt',
|
|
130
|
+
kind: 'scalar',
|
|
131
|
+
type: 'DateTime',
|
|
132
|
+
column: 'created_at',
|
|
133
|
+
default: { name: 'now' },
|
|
134
|
+
},
|
|
135
|
+
{ name: 'deliveries', kind: 'object', type: 'DomainEventDelivery', isList: true },
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: 'DomainEventDelivery',
|
|
140
|
+
table: 'domain_event_deliveries',
|
|
141
|
+
uniqueFields: [['eventId', 'handlerKey']],
|
|
142
|
+
fields: [
|
|
143
|
+
{ name: 'id', kind: 'scalar', type: 'String', isId: true, default: { name: 'cuid' } },
|
|
144
|
+
{ name: 'eventId', kind: 'scalar', type: 'String', column: 'event_id' },
|
|
145
|
+
{
|
|
146
|
+
name: 'event',
|
|
147
|
+
kind: 'object',
|
|
148
|
+
type: 'DomainEvent',
|
|
149
|
+
relationFromFields: ['eventId'],
|
|
150
|
+
relationToFields: ['id'],
|
|
151
|
+
},
|
|
152
|
+
{ name: 'handlerKey', kind: 'scalar', type: 'String', column: 'handler_key' },
|
|
153
|
+
{ name: 'status', kind: 'enum', type: 'DomainEventDeliveryStatus', default: 'PENDING' },
|
|
154
|
+
{ name: 'attempts', kind: 'scalar', type: 'Int', default: 0 },
|
|
155
|
+
{
|
|
156
|
+
name: 'nextAttemptAt',
|
|
157
|
+
kind: 'scalar',
|
|
158
|
+
type: 'DateTime',
|
|
159
|
+
optional: true,
|
|
160
|
+
column: 'next_attempt_at',
|
|
161
|
+
},
|
|
162
|
+
{ name: 'lockedAt', kind: 'scalar', type: 'DateTime', optional: true, column: 'locked_at' },
|
|
163
|
+
{ name: 'lockedBy', kind: 'scalar', type: 'String', optional: true, column: 'locked_by' },
|
|
164
|
+
{ name: 'lastError', kind: 'scalar', type: 'String', optional: true, column: 'last_error' },
|
|
165
|
+
{
|
|
166
|
+
name: 'processedAt',
|
|
167
|
+
kind: 'scalar',
|
|
168
|
+
type: 'DateTime',
|
|
169
|
+
optional: true,
|
|
170
|
+
column: 'processed_at',
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
name: 'createdAt',
|
|
174
|
+
kind: 'scalar',
|
|
175
|
+
type: 'DateTime',
|
|
176
|
+
column: 'created_at',
|
|
177
|
+
default: { name: 'now' },
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
name: 'IntegrationEventReceipt',
|
|
183
|
+
table: 'integration_event_receipts',
|
|
184
|
+
uniqueFields: [['sourceApp', 'eventId']],
|
|
185
|
+
fields: [
|
|
186
|
+
{ name: 'id', kind: 'scalar', type: 'String', isId: true, default: { name: 'cuid' } },
|
|
187
|
+
{ name: 'sourceApp', kind: 'scalar', type: 'String', column: 'source_app' },
|
|
188
|
+
{ name: 'eventId', kind: 'scalar', type: 'String', column: 'event_id' },
|
|
189
|
+
{ name: 'capabilityId', kind: 'scalar', type: 'String', column: 'capability_id' },
|
|
190
|
+
{ name: 'capabilityVersion', kind: 'scalar', type: 'String', column: 'capability_version' },
|
|
191
|
+
{ name: 'capabilityDigest', kind: 'scalar', type: 'String', column: 'capability_digest' },
|
|
192
|
+
{ name: 'bindingId', kind: 'scalar', type: 'String', column: 'binding_id' },
|
|
193
|
+
{ name: 'bindingVersion', kind: 'scalar', type: 'String', column: 'binding_version' },
|
|
194
|
+
{ name: 'payloadDigest', kind: 'scalar', type: 'String', column: 'payload_digest' },
|
|
195
|
+
{
|
|
196
|
+
name: 'processedAt',
|
|
197
|
+
kind: 'scalar',
|
|
198
|
+
type: 'DateTime',
|
|
199
|
+
column: 'processed_at',
|
|
200
|
+
default: { name: 'now' },
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
name: 'createdAt',
|
|
204
|
+
kind: 'scalar',
|
|
205
|
+
type: 'DateTime',
|
|
206
|
+
column: 'created_at',
|
|
207
|
+
default: { name: 'now' },
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
},
|
|
211
|
+
];
|
|
212
|
+
const EXPECTED_ENUMS = [
|
|
213
|
+
{ name: 'DomainEventOperation', values: ['CREATE', 'UPDATE', 'DELETE'] },
|
|
214
|
+
{
|
|
215
|
+
name: 'DomainEventDeliveryStatus',
|
|
216
|
+
values: ['PENDING', 'PROCESSING', 'PROCESSED', 'DEAD_LETTER', 'IGNORED'],
|
|
217
|
+
},
|
|
218
|
+
];
|
|
219
|
+
/**
|
|
220
|
+
* Compares an app's generated `Prisma.dmmf.datamodel` against the documented
|
|
221
|
+
* `DomainEvent`/`DomainEventDelivery` model pattern. Returns a human-readable issue per drift;
|
|
222
|
+
* an empty array means the schema matches closely enough for this package's dispatcher and
|
|
223
|
+
* service code to operate correctly (field presence, type, optionality, list-ness, and the
|
|
224
|
+
* physical table/column names the dispatcher's raw SQL depends on).
|
|
225
|
+
*/
|
|
226
|
+
function checkDomainEventSchemaDrift(datamodel) {
|
|
227
|
+
const issues = [];
|
|
228
|
+
for (const expectedModel of EXPECTED_MODELS) {
|
|
229
|
+
const model = datamodel.models.find((candidate) => candidate.name === expectedModel.name);
|
|
230
|
+
if (!model) {
|
|
231
|
+
issues.push(`model ${expectedModel.name} not found`);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
const actualTable = model.dbName ?? model.name;
|
|
235
|
+
if (actualTable !== expectedModel.table) {
|
|
236
|
+
issues.push(`model ${expectedModel.name} maps to table "${actualTable}", expected "${expectedModel.table}"`);
|
|
237
|
+
}
|
|
238
|
+
for (const expectedUnique of expectedModel.uniqueFields ?? []) {
|
|
239
|
+
if (!hasUniqueFields(model, expectedUnique)) {
|
|
240
|
+
issues.push(`model ${expectedModel.name} is missing @@unique([${expectedUnique.join(', ')}])`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
for (const expectedField of expectedModel.fields) {
|
|
244
|
+
const field = model.fields.find((candidate) => candidate.name === expectedField.name);
|
|
245
|
+
if (!field) {
|
|
246
|
+
issues.push(`model ${expectedModel.name} is missing field ${expectedField.name}`);
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
if (field.kind !== expectedField.kind || field.type !== expectedField.type) {
|
|
250
|
+
issues.push(`model ${expectedModel.name}.${expectedField.name} has type ${field.kind}:${field.type}, expected ${expectedField.kind}:${expectedField.type}`);
|
|
251
|
+
}
|
|
252
|
+
const expectedRequired = !expectedField.optional;
|
|
253
|
+
if (field.isRequired !== expectedRequired) {
|
|
254
|
+
issues.push(`model ${expectedModel.name}.${expectedField.name} is ${field.isRequired ? 'required' : 'optional'}, expected ${expectedRequired ? 'required' : 'optional'}`);
|
|
255
|
+
}
|
|
256
|
+
const expectedIsList = expectedField.isList ?? false;
|
|
257
|
+
if (field.isList !== expectedIsList) {
|
|
258
|
+
issues.push(`model ${expectedModel.name}.${expectedField.name} isList=${field.isList}, expected ${expectedIsList}`);
|
|
259
|
+
}
|
|
260
|
+
const expectedColumn = expectedField.column ?? expectedField.name;
|
|
261
|
+
const actualColumn = field.dbName ?? field.name;
|
|
262
|
+
if (actualColumn !== expectedColumn) {
|
|
263
|
+
issues.push(`model ${expectedModel.name}.${expectedField.name} maps to column "${actualColumn}", expected "${expectedColumn}"`);
|
|
264
|
+
}
|
|
265
|
+
if ((field.isId ?? false) !== (expectedField.isId ?? false)) {
|
|
266
|
+
issues.push(`model ${expectedModel.name}.${expectedField.name} isId=${field.isId ?? false}, expected ${expectedField.isId ?? false}`);
|
|
267
|
+
}
|
|
268
|
+
if (!defaultMatches(field.default, expectedField.default)) {
|
|
269
|
+
issues.push(`model ${expectedModel.name}.${expectedField.name} default is ${formatDefault(field.default)}, expected ${formatDefault(expectedField.default)}`);
|
|
270
|
+
}
|
|
271
|
+
if (!sameStringArray(field.relationFromFields, expectedField.relationFromFields)) {
|
|
272
|
+
issues.push(`model ${expectedModel.name}.${expectedField.name} relationFromFields is ${formatStringArray(field.relationFromFields)}, expected ${formatStringArray(expectedField.relationFromFields)}`);
|
|
273
|
+
}
|
|
274
|
+
if (!sameStringArray(field.relationToFields, expectedField.relationToFields)) {
|
|
275
|
+
issues.push(`model ${expectedModel.name}.${expectedField.name} relationToFields is ${formatStringArray(field.relationToFields)}, expected ${formatStringArray(expectedField.relationToFields)}`);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
for (const expectedEnum of EXPECTED_ENUMS) {
|
|
280
|
+
const found = datamodel.enums.find((candidate) => candidate.name === expectedEnum.name);
|
|
281
|
+
if (!found) {
|
|
282
|
+
issues.push(`enum ${expectedEnum.name} not found`);
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
const actualValues = new Set(found.values.map((value) => value.name));
|
|
286
|
+
const missing = expectedEnum.values.filter((value) => !actualValues.has(value));
|
|
287
|
+
if (missing.length > 0) {
|
|
288
|
+
issues.push(`enum ${expectedEnum.name} is missing value(s): ${missing.join(', ')}`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return issues;
|
|
292
|
+
}
|
|
293
|
+
function hasUniqueFields(model, expectedFields) {
|
|
294
|
+
const matches = (fields) => sameStringArray(fields, expectedFields);
|
|
295
|
+
return (model.uniqueFields?.some(matches) === true ||
|
|
296
|
+
model.uniqueIndexes?.some((index) => matches(index.fields)) === true);
|
|
297
|
+
}
|
|
298
|
+
function defaultMatches(actual, expected) {
|
|
299
|
+
if (expected === undefined)
|
|
300
|
+
return actual === undefined;
|
|
301
|
+
if (typeof expected !== 'object')
|
|
302
|
+
return actual === expected;
|
|
303
|
+
return (typeof actual === 'object' &&
|
|
304
|
+
actual !== null &&
|
|
305
|
+
actual.name === expected.name);
|
|
306
|
+
}
|
|
307
|
+
function sameStringArray(actual, expected) {
|
|
308
|
+
const normalizedActual = actual ?? [];
|
|
309
|
+
const normalizedExpected = expected ?? [];
|
|
310
|
+
return (normalizedActual.length === normalizedExpected.length &&
|
|
311
|
+
normalizedActual.every((value, index) => value === normalizedExpected[index]));
|
|
312
|
+
}
|
|
313
|
+
function formatDefault(value) {
|
|
314
|
+
if (value === undefined)
|
|
315
|
+
return 'undefined';
|
|
316
|
+
if (typeof value === 'object' && value !== null && 'name' in value) {
|
|
317
|
+
return String(value.name);
|
|
318
|
+
}
|
|
319
|
+
return JSON.stringify(value);
|
|
320
|
+
}
|
|
321
|
+
function formatStringArray(value) {
|
|
322
|
+
return `[${(value ?? []).join(', ')}]`;
|
|
323
|
+
}
|
|
324
|
+
//# sourceMappingURL=schema-drift-check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-drift-check.js","sourceRoot":"","sources":["../src/schema-drift-check.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;AAkPH,kEAqGC;AA7SD,MAAM,eAAe,GAAoB;IACvC;QACE,IAAI,EAAE,aAAa;QACnB,KAAK,EAAE,eAAe;QACtB,MAAM,EAAE;YACN,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE;YACrF,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE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I,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,EAAE,CAAC;QACnE,OAAO,MAAM,CAAE,KAA2B,CAAC,IAAI,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAoC;IAC7D,OAAO,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reusable test doubles for `@haneinfo/domain-events` consumers. None of these touch a real
|
|
3
|
+
* database — they satisfy the structural shapes `DomainEventsService`/`DomainEventDispatcherService`
|
|
4
|
+
* depend on (see types.ts), so app-local tests can exercise record()/fan-out and dispatcher tick
|
|
5
|
+
* behavior without spinning up Postgres or generating a real Prisma client.
|
|
6
|
+
*/
|
|
7
|
+
import { DomainEventDeliveryStatus, type DomainEventOperation } from './types';
|
|
8
|
+
export type MockDomainEventRow = {
|
|
9
|
+
id: string;
|
|
10
|
+
aggregateType: string;
|
|
11
|
+
aggregateId: string;
|
|
12
|
+
eventType: string;
|
|
13
|
+
operation: DomainEventOperation;
|
|
14
|
+
changedFields: string[];
|
|
15
|
+
integrationCapabilityId?: string | null;
|
|
16
|
+
integrationCapabilityVersion?: string | null;
|
|
17
|
+
integrationCapabilityDigest?: string | null;
|
|
18
|
+
integrationBindingId?: string | null;
|
|
19
|
+
integrationBindingVersion?: string | null;
|
|
20
|
+
integrationEnvelopeVersion?: string | null;
|
|
21
|
+
integrationSourceApp?: string | null;
|
|
22
|
+
integrationPayload?: unknown;
|
|
23
|
+
integrationPayloadDigest?: string | null;
|
|
24
|
+
};
|
|
25
|
+
export type MockDomainEventTxState = {
|
|
26
|
+
events: MockDomainEventRow[];
|
|
27
|
+
deliveries: {
|
|
28
|
+
eventId: string;
|
|
29
|
+
handlerKey: string;
|
|
30
|
+
}[];
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Builds a `DomainEventTxClient`-shaped mock for exercising `DomainEventsService.record()`.
|
|
34
|
+
* Pass `failDelivery: true` to simulate the delivery insert failing after the event row commits,
|
|
35
|
+
* for asserting the caller's own transaction rolls the event back too.
|
|
36
|
+
*/
|
|
37
|
+
export declare function createMockDomainEventTx(options?: {
|
|
38
|
+
failDelivery?: boolean;
|
|
39
|
+
}): {
|
|
40
|
+
state: MockDomainEventTxState;
|
|
41
|
+
tx: {
|
|
42
|
+
domainEvent: {
|
|
43
|
+
create: (args: {
|
|
44
|
+
data: Omit<MockDomainEventRow, 'id'>;
|
|
45
|
+
}) => Promise<MockDomainEventRow>;
|
|
46
|
+
};
|
|
47
|
+
domainEventDelivery: {
|
|
48
|
+
createMany: (args: {
|
|
49
|
+
data: {
|
|
50
|
+
eventId: string;
|
|
51
|
+
handlerKey: string;
|
|
52
|
+
}[];
|
|
53
|
+
}) => Promise<{
|
|
54
|
+
count: number;
|
|
55
|
+
}>;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export type MockDeliveryRow = {
|
|
60
|
+
id: string;
|
|
61
|
+
eventId: string;
|
|
62
|
+
handlerKey: string;
|
|
63
|
+
status: DomainEventDeliveryStatus;
|
|
64
|
+
attempts: number;
|
|
65
|
+
nextAttemptAt: Date | null;
|
|
66
|
+
lockedAt: Date | null;
|
|
67
|
+
lockedBy: string | null;
|
|
68
|
+
lastError: string | null;
|
|
69
|
+
processedAt: Date | null;
|
|
70
|
+
createdAt: Date;
|
|
71
|
+
event: {
|
|
72
|
+
id: string;
|
|
73
|
+
seq: bigint;
|
|
74
|
+
eventType: string;
|
|
75
|
+
integrationBindingId?: string | null;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
/** Builds one `DomainEventDelivery` + joined `event` row for dispatcher tests. */
|
|
79
|
+
export declare function createMockDeliveryRow(id: string, seq: bigint, handlerKey: string, overrides?: Partial<Pick<MockDeliveryRow, 'attempts' | 'status' | 'lockedAt'>> & {
|
|
80
|
+
eventType?: string;
|
|
81
|
+
integrationBindingId?: string | null;
|
|
82
|
+
}): MockDeliveryRow;
|
|
83
|
+
type MockDeliveryWhere = {
|
|
84
|
+
id?: string | {
|
|
85
|
+
in: string[];
|
|
86
|
+
};
|
|
87
|
+
status?: DomainEventDeliveryStatus;
|
|
88
|
+
lockedBy?: string;
|
|
89
|
+
attempts?: {
|
|
90
|
+
gte?: number;
|
|
91
|
+
lt?: number;
|
|
92
|
+
};
|
|
93
|
+
lockedAt?: {
|
|
94
|
+
lt: Date;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
type MockDeliveryUpdateData = Omit<Partial<MockDeliveryRow>, 'attempts'> & {
|
|
98
|
+
attempts?: number | {
|
|
99
|
+
increment: number;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
type MockDispatcherCounters = {
|
|
103
|
+
transactions: number;
|
|
104
|
+
updateManyCalls?: number;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Builds a `PrismaService`-shaped mock (findMany/update/$transaction/$queryRaw) that
|
|
108
|
+
* `DomainEventDispatcherService` can run its `tick()` against. `rows` is mutated in place so
|
|
109
|
+
* assertions can inspect delivery state after `tick()` resolves.
|
|
110
|
+
*/
|
|
111
|
+
export declare function createMockDispatcherPrisma(rows: MockDeliveryRow[], counters?: MockDispatcherCounters): {
|
|
112
|
+
domainEventDelivery: {
|
|
113
|
+
findMany: ({ where }: {
|
|
114
|
+
where: MockDeliveryWhere;
|
|
115
|
+
}) => Promise<{
|
|
116
|
+
event: {
|
|
117
|
+
id: string;
|
|
118
|
+
seq: bigint;
|
|
119
|
+
eventType: string;
|
|
120
|
+
integrationBindingId?: string | null;
|
|
121
|
+
};
|
|
122
|
+
id: string;
|
|
123
|
+
eventId: string;
|
|
124
|
+
handlerKey: string;
|
|
125
|
+
status: DomainEventDeliveryStatus;
|
|
126
|
+
attempts: number;
|
|
127
|
+
nextAttemptAt: Date | null;
|
|
128
|
+
lockedAt: Date | null;
|
|
129
|
+
lockedBy: string | null;
|
|
130
|
+
lastError: string | null;
|
|
131
|
+
processedAt: Date | null;
|
|
132
|
+
createdAt: Date;
|
|
133
|
+
}[]>;
|
|
134
|
+
update: ({ where, data }: {
|
|
135
|
+
where: {
|
|
136
|
+
id: string;
|
|
137
|
+
};
|
|
138
|
+
data: MockDeliveryUpdateData;
|
|
139
|
+
}) => Promise<MockDeliveryRow>;
|
|
140
|
+
updateMany: ({ where, data, }: {
|
|
141
|
+
where: MockDeliveryWhere;
|
|
142
|
+
data: MockDeliveryUpdateData;
|
|
143
|
+
}) => Promise<{
|
|
144
|
+
count: number;
|
|
145
|
+
}>;
|
|
146
|
+
};
|
|
147
|
+
$transaction: (callback: (tx: unknown) => Promise<unknown>) => Promise<unknown>;
|
|
148
|
+
};
|
|
149
|
+
export {};
|
|
150
|
+
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,yBAAyB,EAAE,KAAK,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE/E,MAAM,MAAM,kBAAkB,GAAG;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,oBAAoB,CAAC;IAChC,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,uBAAuB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,4BAA4B,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7C,2BAA2B,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5C,oBAAoB,CAAC,EA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AG;IACzE,QAAQ,CAAC,EAAE,MAAM,GAAG;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3C,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AA+BF;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,eAAe,EAAE,EACvB,QAAQ,CAAC,EAAE,sBAAsB;;8BAIE;YAAE,KAAK,EAAE,iBAAiB,CAAA;SAAE;;oBA3FlD,MAAM;qBAAO,MAAM;2BAAa,MAAM;uCAAyB,MAAM,GAAG,IAAI;;gBAXrF,MAAM;qBACD,MAAM;wBACH,MAAM;oBACV,yBAAyB;sBACvB,MAAM;2BACD,IAAI,GAAG,IAAI;sBAChB,IAAI,GAAG,IAAI;sBACX,MAAM,GAAG,IAAI;uBACZ,MAAM,GAAG,IAAI;yBACX,IAAI,GAAG,IAAI;uBACb,IAAI;;kCAqGqB;YAAE,KAAK,EAAE;gBAAE,EAAE,EAAE,MAAM,CAAA;aAAE,CAAC;YAAC,IAAI,EAAE,sBAAsB,CAAA;SAAE;uCASpF;YACD,KAAK,EAAE,iBAAiB,CAAC;YACzB,IAAI,EAAE,sBAAsB,CAAC;SAC9B;;;;6BAO4B,CAAC,EAAE,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC;EAuBnE"}
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMockDomainEventTx = createMockDomainEventTx;
|
|
4
|
+
exports.createMockDeliveryRow = createMockDeliveryRow;
|
|
5
|
+
exports.createMockDispatcherPrisma = createMockDispatcherPrisma;
|
|
6
|
+
/**
|
|
7
|
+
* Reusable test doubles for `@haneinfo/domain-events` consumers. None of these touch a real
|
|
8
|
+
* database — they satisfy the structural shapes `DomainEventsService`/`DomainEventDispatcherService`
|
|
9
|
+
* depend on (see types.ts), so app-local tests can exercise record()/fan-out and dispatcher tick
|
|
10
|
+
* behavior without spinning up Postgres or generating a real Prisma client.
|
|
11
|
+
*/
|
|
12
|
+
const types_1 = require("./types");
|
|
13
|
+
/**
|
|
14
|
+
* Builds a `DomainEventTxClient`-shaped mock for exercising `DomainEventsService.record()`.
|
|
15
|
+
* Pass `failDelivery: true` to simulate the delivery insert failing after the event row commits,
|
|
16
|
+
* for asserting the caller's own transaction rolls the event back too.
|
|
17
|
+
*/
|
|
18
|
+
function createMockDomainEventTx(options) {
|
|
19
|
+
const state = { events: [], deliveries: [] };
|
|
20
|
+
const tx = {
|
|
21
|
+
domainEvent: {
|
|
22
|
+
create: async ({ data }) => {
|
|
23
|
+
const event = { id: `event-${state.events.length + 1}`, ...data };
|
|
24
|
+
state.events.push(event);
|
|
25
|
+
return event;
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
domainEventDelivery: {
|
|
29
|
+
createMany: async ({ data }) => {
|
|
30
|
+
if (options?.failDelivery)
|
|
31
|
+
throw new Error('delivery insert failed');
|
|
32
|
+
for (const row of data) {
|
|
33
|
+
if (!state.deliveries.some((existing) => existing.eventId === row.eventId && existing.handlerKey === row.handlerKey)) {
|
|
34
|
+
state.deliveries.push(row);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return { count: data.length };
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
return { state, tx };
|
|
42
|
+
}
|
|
43
|
+
/** Builds one `DomainEventDelivery` + joined `event` row for dispatcher tests. */
|
|
44
|
+
function createMockDeliveryRow(id, seq, handlerKey, overrides) {
|
|
45
|
+
return {
|
|
46
|
+
id,
|
|
47
|
+
eventId: `event-${id}`,
|
|
48
|
+
handlerKey,
|
|
49
|
+
status: overrides?.status ?? types_1.DomainEventDeliveryStatus.PENDING,
|
|
50
|
+
attempts: overrides?.attempts ?? 0,
|
|
51
|
+
nextAttemptAt: null,
|
|
52
|
+
lockedAt: overrides?.lockedAt ?? null,
|
|
53
|
+
lockedBy: null,
|
|
54
|
+
lastError: null,
|
|
55
|
+
processedAt: null,
|
|
56
|
+
createdAt: new Date('2026-07-17T00:00:00.000Z'),
|
|
57
|
+
event: {
|
|
58
|
+
id: `event-${id}`,
|
|
59
|
+
seq,
|
|
60
|
+
eventType: overrides?.eventType ?? 'test.event',
|
|
61
|
+
integrationBindingId: overrides?.integrationBindingId ?? null,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
// Every condition present in `where` must match — this used to short-circuit true on `id.in`
|
|
66
|
+
// alone, silently ignoring any `status` (or other) condition passed alongside it in the same
|
|
67
|
+
// where clause, which would have made a combined `{ id, status: PROCESSING }` guard (used to
|
|
68
|
+
// close the completion-vs-admin-action race) untestable against this mock.
|
|
69
|
+
function matchesWhere(row, where) {
|
|
70
|
+
if (where.id !== undefined) {
|
|
71
|
+
const matchesId = typeof where.id === 'string' ? row.id === where.id : where.id.in.includes(row.id);
|
|
72
|
+
if (!matchesId)
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
if (where.status !== undefined) {
|
|
76
|
+
if (row.status !== where.status)
|
|
77
|
+
return false;
|
|
78
|
+
if (where.lockedAt?.lt && !(row.lockedAt !== null && row.lockedAt < where.lockedAt.lt)) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (where.lockedBy !== undefined && row.lockedBy !== where.lockedBy)
|
|
83
|
+
return false;
|
|
84
|
+
if (where.attempts?.gte !== undefined && row.attempts < where.attempts.gte)
|
|
85
|
+
return false;
|
|
86
|
+
if (where.attempts?.lt !== undefined && row.attempts >= where.attempts.lt)
|
|
87
|
+
return false;
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
function applyDeliveryUpdate(row, data) {
|
|
91
|
+
const { attempts, ...fields } = data;
|
|
92
|
+
Object.assign(row, fields);
|
|
93
|
+
if (typeof attempts === 'number')
|
|
94
|
+
row.attempts = attempts;
|
|
95
|
+
if (typeof attempts === 'object')
|
|
96
|
+
row.attempts += attempts.increment;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Builds a `PrismaService`-shaped mock (findMany/update/$transaction/$queryRaw) that
|
|
100
|
+
* `DomainEventDispatcherService` can run its `tick()` against. `rows` is mutated in place so
|
|
101
|
+
* assertions can inspect delivery state after `tick()` resolves.
|
|
102
|
+
*/
|
|
103
|
+
function createMockDispatcherPrisma(rows, counters) {
|
|
104
|
+
const stats = counters ?? { transactions: 0 };
|
|
105
|
+
const findMany = async ({ where }) => rows
|
|
106
|
+
.filter((row) => matchesWhere(row, where))
|
|
107
|
+
.sort((left, right) => Number(left.event.seq - right.event.seq))
|
|
108
|
+
.map((row) => ({ ...row, event: { ...row.event } }));
|
|
109
|
+
return {
|
|
110
|
+
domainEventDelivery: {
|
|
111
|
+
findMany,
|
|
112
|
+
update: async ({ where, data }) => {
|
|
113
|
+
const row = rows.find((candidate) => candidate.id === where.id);
|
|
114
|
+
if (!row)
|
|
115
|
+
throw new Error(`Missing row ${where.id}`);
|
|
116
|
+
applyDeliveryUpdate(row, data);
|
|
117
|
+
return row;
|
|
118
|
+
},
|
|
119
|
+
updateMany: async ({ where, data, }) => {
|
|
120
|
+
stats.updateManyCalls = (stats.updateManyCalls ?? 0) + 1;
|
|
121
|
+
const matchingRows = rows.filter((row) => matchesWhere(row, where));
|
|
122
|
+
for (const row of matchingRows)
|
|
123
|
+
applyDeliveryUpdate(row, data);
|
|
124
|
+
return { count: matchingRows.length };
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
$transaction: async (callback) => {
|
|
128
|
+
stats.transactions++;
|
|
129
|
+
return callback({
|
|
130
|
+
$queryRaw: async () => {
|
|
131
|
+
const claimed = rows
|
|
132
|
+
.filter((row) => row.status === types_1.DomainEventDeliveryStatus.PENDING &&
|
|
133
|
+
(!row.nextAttemptAt || row.nextAttemptAt <= new Date()))
|
|
134
|
+
.sort((left, right) => Number(left.event.seq - right.event.seq))
|
|
135
|
+
.slice(0, 20);
|
|
136
|
+
for (const row of claimed) {
|
|
137
|
+
row.status = types_1.DomainEventDeliveryStatus.PROCESSING;
|
|
138
|
+
row.lockedAt = new Date();
|
|
139
|
+
row.lockedBy = 'test';
|
|
140
|
+
}
|
|
141
|
+
return claimed.map((row) => ({ id: row.id }));
|
|
142
|
+
},
|
|
143
|
+
domainEventDelivery: { findMany },
|
|
144
|
+
});
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=testing.js.map
|