@dudousxd/nestjs-durable-store-mikro-orm 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +133 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +107 -30
- package/dist/index.js.map +1 -1
- package/package.json +11 -9
package/dist/index.cjs
CHANGED
|
@@ -33,7 +33,7 @@ __export(index_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(index_exports);
|
|
34
34
|
|
|
35
35
|
// src/entities.ts
|
|
36
|
-
var
|
|
36
|
+
var import_legacy = require("@mikro-orm/decorators/legacy");
|
|
37
37
|
function _ts_decorate(decorators, target, key, desc) {
|
|
38
38
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
39
39
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -66,91 +66,106 @@ var WorkflowRunEntity = class {
|
|
|
66
66
|
updatedAt;
|
|
67
67
|
};
|
|
68
68
|
_ts_decorate([
|
|
69
|
-
(0,
|
|
69
|
+
(0, import_legacy.PrimaryKey)({
|
|
70
|
+
type: "string"
|
|
71
|
+
}),
|
|
70
72
|
_ts_metadata("design:type", String)
|
|
71
73
|
], WorkflowRunEntity.prototype, "id", void 0);
|
|
72
74
|
_ts_decorate([
|
|
73
|
-
(0,
|
|
75
|
+
(0, import_legacy.Property)({
|
|
76
|
+
type: "string"
|
|
77
|
+
}),
|
|
74
78
|
_ts_metadata("design:type", String)
|
|
75
79
|
], WorkflowRunEntity.prototype, "workflow", void 0);
|
|
76
80
|
_ts_decorate([
|
|
77
|
-
(0,
|
|
81
|
+
(0, import_legacy.Property)({
|
|
82
|
+
type: "string"
|
|
83
|
+
}),
|
|
78
84
|
_ts_metadata("design:type", String)
|
|
79
85
|
], WorkflowRunEntity.prototype, "workflowVersion", void 0);
|
|
80
86
|
_ts_decorate([
|
|
81
|
-
(0,
|
|
87
|
+
(0, import_legacy.Property)({
|
|
88
|
+
type: "string"
|
|
89
|
+
}),
|
|
82
90
|
_ts_metadata("design:type", typeof RunStatus === "undefined" ? Object : RunStatus)
|
|
83
91
|
], WorkflowRunEntity.prototype, "status", void 0);
|
|
84
92
|
_ts_decorate([
|
|
85
|
-
(0,
|
|
93
|
+
(0, import_legacy.Property)({
|
|
86
94
|
type: "json",
|
|
87
95
|
nullable: true
|
|
88
96
|
}),
|
|
89
97
|
_ts_metadata("design:type", Object)
|
|
90
98
|
], WorkflowRunEntity.prototype, "input", void 0);
|
|
91
99
|
_ts_decorate([
|
|
92
|
-
(0,
|
|
100
|
+
(0, import_legacy.Property)({
|
|
93
101
|
type: "json",
|
|
94
102
|
nullable: true
|
|
95
103
|
}),
|
|
96
104
|
_ts_metadata("design:type", Object)
|
|
97
105
|
], WorkflowRunEntity.prototype, "output", void 0);
|
|
98
106
|
_ts_decorate([
|
|
99
|
-
(0,
|
|
107
|
+
(0, import_legacy.Property)({
|
|
100
108
|
type: "json",
|
|
101
109
|
nullable: true
|
|
102
110
|
}),
|
|
103
111
|
_ts_metadata("design:type", Object)
|
|
104
112
|
], WorkflowRunEntity.prototype, "error", void 0);
|
|
105
113
|
_ts_decorate([
|
|
106
|
-
(0,
|
|
114
|
+
(0, import_legacy.Property)({
|
|
115
|
+
type: "Date",
|
|
107
116
|
nullable: true
|
|
108
117
|
}),
|
|
109
118
|
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
110
119
|
], WorkflowRunEntity.prototype, "wakeAt", void 0);
|
|
111
120
|
_ts_decorate([
|
|
112
|
-
(0,
|
|
121
|
+
(0, import_legacy.Property)({
|
|
122
|
+
type: "string",
|
|
113
123
|
nullable: true
|
|
114
124
|
}),
|
|
115
125
|
_ts_metadata("design:type", String)
|
|
116
126
|
], WorkflowRunEntity.prototype, "lockedBy", void 0);
|
|
117
127
|
_ts_decorate([
|
|
118
|
-
(0,
|
|
128
|
+
(0, import_legacy.Property)({
|
|
129
|
+
type: "Date",
|
|
119
130
|
nullable: true
|
|
120
131
|
}),
|
|
121
132
|
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
122
133
|
], WorkflowRunEntity.prototype, "lockedUntil", void 0);
|
|
123
134
|
_ts_decorate([
|
|
124
|
-
(0,
|
|
135
|
+
(0, import_legacy.Property)({
|
|
125
136
|
type: "integer",
|
|
126
137
|
nullable: true
|
|
127
138
|
}),
|
|
128
139
|
_ts_metadata("design:type", Number)
|
|
129
140
|
], WorkflowRunEntity.prototype, "recoveryAttempts", void 0);
|
|
130
141
|
_ts_decorate([
|
|
131
|
-
(0,
|
|
142
|
+
(0, import_legacy.Property)({
|
|
132
143
|
type: "json",
|
|
133
144
|
nullable: true
|
|
134
145
|
}),
|
|
135
146
|
_ts_metadata("design:type", Object)
|
|
136
147
|
], WorkflowRunEntity.prototype, "tags", void 0);
|
|
137
148
|
_ts_decorate([
|
|
138
|
-
(0,
|
|
149
|
+
(0, import_legacy.Property)({
|
|
139
150
|
type: "json",
|
|
140
151
|
nullable: true
|
|
141
152
|
}),
|
|
142
153
|
_ts_metadata("design:type", Object)
|
|
143
154
|
], WorkflowRunEntity.prototype, "searchAttributes", void 0);
|
|
144
155
|
_ts_decorate([
|
|
145
|
-
(0,
|
|
156
|
+
(0, import_legacy.Property)({
|
|
157
|
+
type: "Date"
|
|
158
|
+
}),
|
|
146
159
|
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
147
160
|
], WorkflowRunEntity.prototype, "createdAt", void 0);
|
|
148
161
|
_ts_decorate([
|
|
149
|
-
(0,
|
|
162
|
+
(0, import_legacy.Property)({
|
|
163
|
+
type: "Date"
|
|
164
|
+
}),
|
|
150
165
|
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
151
166
|
], WorkflowRunEntity.prototype, "updatedAt", void 0);
|
|
152
167
|
WorkflowRunEntity = _ts_decorate([
|
|
153
|
-
(0,
|
|
168
|
+
(0, import_legacy.Entity)({
|
|
154
169
|
tableName: "durable_workflow_runs"
|
|
155
170
|
})
|
|
156
171
|
], WorkflowRunEntity);
|
|
@@ -176,89 +191,110 @@ var StepCheckpointEntity = class {
|
|
|
176
191
|
finishedAt;
|
|
177
192
|
};
|
|
178
193
|
_ts_decorate([
|
|
179
|
-
(0,
|
|
194
|
+
(0, import_legacy.PrimaryKey)({
|
|
195
|
+
type: "string"
|
|
196
|
+
}),
|
|
180
197
|
_ts_metadata("design:type", String)
|
|
181
198
|
], StepCheckpointEntity.prototype, "runId", void 0);
|
|
182
199
|
_ts_decorate([
|
|
183
|
-
(0,
|
|
200
|
+
(0, import_legacy.PrimaryKey)({
|
|
201
|
+
type: "integer"
|
|
202
|
+
}),
|
|
184
203
|
_ts_metadata("design:type", Number)
|
|
185
204
|
], StepCheckpointEntity.prototype, "seq", void 0);
|
|
186
205
|
_ts_decorate([
|
|
187
|
-
(0,
|
|
206
|
+
(0, import_legacy.Property)({
|
|
207
|
+
type: "string"
|
|
208
|
+
}),
|
|
188
209
|
_ts_metadata("design:type", String)
|
|
189
210
|
], StepCheckpointEntity.prototype, "name", void 0);
|
|
190
211
|
_ts_decorate([
|
|
191
|
-
(0,
|
|
212
|
+
(0, import_legacy.Property)({
|
|
213
|
+
type: "string"
|
|
214
|
+
}),
|
|
192
215
|
_ts_metadata("design:type", typeof StepKind === "undefined" ? Object : StepKind)
|
|
193
216
|
], StepCheckpointEntity.prototype, "kind", void 0);
|
|
194
217
|
_ts_decorate([
|
|
195
|
-
(0,
|
|
218
|
+
(0, import_legacy.Property)({
|
|
219
|
+
type: "string"
|
|
220
|
+
}),
|
|
196
221
|
_ts_metadata("design:type", String)
|
|
197
222
|
], StepCheckpointEntity.prototype, "stepId", void 0);
|
|
198
223
|
_ts_decorate([
|
|
199
|
-
(0,
|
|
224
|
+
(0, import_legacy.Property)({
|
|
225
|
+
type: "string"
|
|
226
|
+
}),
|
|
200
227
|
_ts_metadata("design:type", String)
|
|
201
228
|
], StepCheckpointEntity.prototype, "status", void 0);
|
|
202
229
|
_ts_decorate([
|
|
203
|
-
(0,
|
|
230
|
+
(0, import_legacy.Property)({
|
|
204
231
|
type: "json",
|
|
205
232
|
nullable: true
|
|
206
233
|
}),
|
|
207
234
|
_ts_metadata("design:type", Object)
|
|
208
235
|
], StepCheckpointEntity.prototype, "input", void 0);
|
|
209
236
|
_ts_decorate([
|
|
210
|
-
(0,
|
|
237
|
+
(0, import_legacy.Property)({
|
|
211
238
|
type: "json",
|
|
212
239
|
nullable: true
|
|
213
240
|
}),
|
|
214
241
|
_ts_metadata("design:type", Object)
|
|
215
242
|
], StepCheckpointEntity.prototype, "output", void 0);
|
|
216
243
|
_ts_decorate([
|
|
217
|
-
(0,
|
|
244
|
+
(0, import_legacy.Property)({
|
|
218
245
|
type: "json",
|
|
219
246
|
nullable: true
|
|
220
247
|
}),
|
|
221
248
|
_ts_metadata("design:type", Object)
|
|
222
249
|
], StepCheckpointEntity.prototype, "error", void 0);
|
|
223
250
|
_ts_decorate([
|
|
224
|
-
(0,
|
|
251
|
+
(0, import_legacy.Property)({
|
|
225
252
|
type: "json",
|
|
226
253
|
nullable: true
|
|
227
254
|
}),
|
|
228
255
|
_ts_metadata("design:type", Object)
|
|
229
256
|
], StepCheckpointEntity.prototype, "events", void 0);
|
|
230
257
|
_ts_decorate([
|
|
231
|
-
(0,
|
|
258
|
+
(0, import_legacy.Property)({
|
|
259
|
+
type: "integer"
|
|
260
|
+
}),
|
|
232
261
|
_ts_metadata("design:type", Number)
|
|
233
262
|
], StepCheckpointEntity.prototype, "attempts", void 0);
|
|
234
263
|
_ts_decorate([
|
|
235
|
-
(0,
|
|
264
|
+
(0, import_legacy.Property)({
|
|
265
|
+
type: "string",
|
|
236
266
|
nullable: true
|
|
237
267
|
}),
|
|
238
268
|
_ts_metadata("design:type", String)
|
|
239
269
|
], StepCheckpointEntity.prototype, "workerGroup", void 0);
|
|
240
270
|
_ts_decorate([
|
|
241
|
-
(0,
|
|
271
|
+
(0, import_legacy.Property)({
|
|
272
|
+
type: "Date",
|
|
242
273
|
nullable: true
|
|
243
274
|
}),
|
|
244
275
|
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
245
276
|
], StepCheckpointEntity.prototype, "wakeAt", void 0);
|
|
246
277
|
_ts_decorate([
|
|
247
|
-
(0,
|
|
278
|
+
(0, import_legacy.Property)({
|
|
279
|
+
type: "Date",
|
|
248
280
|
nullable: true
|
|
249
281
|
}),
|
|
250
282
|
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
251
283
|
], StepCheckpointEntity.prototype, "enqueuedAt", void 0);
|
|
252
284
|
_ts_decorate([
|
|
253
|
-
(0,
|
|
285
|
+
(0, import_legacy.Property)({
|
|
286
|
+
type: "Date"
|
|
287
|
+
}),
|
|
254
288
|
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
255
289
|
], StepCheckpointEntity.prototype, "startedAt", void 0);
|
|
256
290
|
_ts_decorate([
|
|
257
|
-
(0,
|
|
291
|
+
(0, import_legacy.Property)({
|
|
292
|
+
type: "Date"
|
|
293
|
+
}),
|
|
258
294
|
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
259
295
|
], StepCheckpointEntity.prototype, "finishedAt", void 0);
|
|
260
296
|
StepCheckpointEntity = _ts_decorate([
|
|
261
|
-
(0,
|
|
297
|
+
(0, import_legacy.Entity)({
|
|
262
298
|
tableName: "durable_step_checkpoints"
|
|
263
299
|
})
|
|
264
300
|
], StepCheckpointEntity);
|
|
@@ -273,29 +309,33 @@ var RunAttributeEntity = class {
|
|
|
273
309
|
numValue;
|
|
274
310
|
};
|
|
275
311
|
_ts_decorate([
|
|
276
|
-
(0,
|
|
312
|
+
(0, import_legacy.PrimaryKey)({
|
|
313
|
+
type: "string"
|
|
314
|
+
}),
|
|
277
315
|
_ts_metadata("design:type", String)
|
|
278
316
|
], RunAttributeEntity.prototype, "runId", void 0);
|
|
279
317
|
_ts_decorate([
|
|
280
|
-
(0,
|
|
318
|
+
(0, import_legacy.PrimaryKey)({
|
|
319
|
+
type: "string"
|
|
320
|
+
}),
|
|
281
321
|
_ts_metadata("design:type", String)
|
|
282
322
|
], RunAttributeEntity.prototype, "key", void 0);
|
|
283
323
|
_ts_decorate([
|
|
284
|
-
(0,
|
|
324
|
+
(0, import_legacy.Property)({
|
|
285
325
|
type: "string",
|
|
286
326
|
nullable: true
|
|
287
327
|
}),
|
|
288
328
|
_ts_metadata("design:type", Object)
|
|
289
329
|
], RunAttributeEntity.prototype, "strValue", void 0);
|
|
290
330
|
_ts_decorate([
|
|
291
|
-
(0,
|
|
331
|
+
(0, import_legacy.Property)({
|
|
292
332
|
type: "float",
|
|
293
333
|
nullable: true
|
|
294
334
|
}),
|
|
295
335
|
_ts_metadata("design:type", Object)
|
|
296
336
|
], RunAttributeEntity.prototype, "numValue", void 0);
|
|
297
337
|
RunAttributeEntity = _ts_decorate([
|
|
298
|
-
(0,
|
|
338
|
+
(0, import_legacy.Entity)({
|
|
299
339
|
tableName: "durable_run_attributes"
|
|
300
340
|
})
|
|
301
341
|
], RunAttributeEntity);
|
|
@@ -308,19 +348,25 @@ var SignalWaiterEntity = class {
|
|
|
308
348
|
seq;
|
|
309
349
|
};
|
|
310
350
|
_ts_decorate([
|
|
311
|
-
(0,
|
|
351
|
+
(0, import_legacy.PrimaryKey)({
|
|
352
|
+
type: "string"
|
|
353
|
+
}),
|
|
312
354
|
_ts_metadata("design:type", String)
|
|
313
355
|
], SignalWaiterEntity.prototype, "token", void 0);
|
|
314
356
|
_ts_decorate([
|
|
315
|
-
(0,
|
|
357
|
+
(0, import_legacy.Property)({
|
|
358
|
+
type: "string"
|
|
359
|
+
}),
|
|
316
360
|
_ts_metadata("design:type", String)
|
|
317
361
|
], SignalWaiterEntity.prototype, "runId", void 0);
|
|
318
362
|
_ts_decorate([
|
|
319
|
-
(0,
|
|
363
|
+
(0, import_legacy.Property)({
|
|
364
|
+
type: "integer"
|
|
365
|
+
}),
|
|
320
366
|
_ts_metadata("design:type", Number)
|
|
321
367
|
], SignalWaiterEntity.prototype, "seq", void 0);
|
|
322
368
|
SignalWaiterEntity = _ts_decorate([
|
|
323
|
-
(0,
|
|
369
|
+
(0, import_legacy.Entity)({
|
|
324
370
|
tableName: "durable_signal_waiters"
|
|
325
371
|
})
|
|
326
372
|
], SignalWaiterEntity);
|
|
@@ -333,26 +379,28 @@ var BufferedSignalEntity = class {
|
|
|
333
379
|
payload;
|
|
334
380
|
};
|
|
335
381
|
_ts_decorate([
|
|
336
|
-
(0,
|
|
337
|
-
autoincrement: true
|
|
382
|
+
(0, import_legacy.PrimaryKey)({
|
|
383
|
+
autoincrement: true,
|
|
384
|
+
type: "integer"
|
|
338
385
|
}),
|
|
339
386
|
_ts_metadata("design:type", Number)
|
|
340
387
|
], BufferedSignalEntity.prototype, "id", void 0);
|
|
341
388
|
_ts_decorate([
|
|
342
|
-
(0,
|
|
343
|
-
index: true
|
|
389
|
+
(0, import_legacy.Property)({
|
|
390
|
+
index: true,
|
|
391
|
+
type: "string"
|
|
344
392
|
}),
|
|
345
393
|
_ts_metadata("design:type", String)
|
|
346
394
|
], BufferedSignalEntity.prototype, "token", void 0);
|
|
347
395
|
_ts_decorate([
|
|
348
|
-
(0,
|
|
396
|
+
(0, import_legacy.Property)({
|
|
349
397
|
type: "json",
|
|
350
398
|
nullable: true
|
|
351
399
|
}),
|
|
352
400
|
_ts_metadata("design:type", Object)
|
|
353
401
|
], BufferedSignalEntity.prototype, "payload", void 0);
|
|
354
402
|
BufferedSignalEntity = _ts_decorate([
|
|
355
|
-
(0,
|
|
403
|
+
(0, import_legacy.Entity)({
|
|
356
404
|
tableName: "durable_buffered_signals"
|
|
357
405
|
})
|
|
358
406
|
], BufferedSignalEntity);
|
|
@@ -369,7 +417,7 @@ var import_nestjs_durable_core = require("@dudousxd/nestjs-durable-core");
|
|
|
369
417
|
|
|
370
418
|
// src/schema.ts
|
|
371
419
|
async function ensureMikroOrmDurableSchema(orm) {
|
|
372
|
-
await orm.schema.
|
|
420
|
+
await orm.schema.update({
|
|
373
421
|
safe: true
|
|
374
422
|
});
|
|
375
423
|
}
|
|
@@ -585,9 +633,9 @@ var MikroOrmStateStore = class {
|
|
|
585
633
|
* the active naming strategy (underscore vs camelCase) rather than guessing. The run PK column is
|
|
586
634
|
* reused for BOTH the outer correlation and the side-table FK (they share the same fieldName). */
|
|
587
635
|
attributeColumns(em) {
|
|
588
|
-
const meta = em.getMetadata().get(RunAttributeEntity
|
|
589
|
-
const field = /* @__PURE__ */ __name((prop) => meta.
|
|
590
|
-
const runMeta = em.getMetadata().get(WorkflowRunEntity
|
|
636
|
+
const meta = em.getMetadata().get(RunAttributeEntity);
|
|
637
|
+
const field = /* @__PURE__ */ __name((prop) => meta.props.find((p) => p.name === prop)?.fieldNames?.[0] ?? prop, "field");
|
|
638
|
+
const runMeta = em.getMetadata().get(WorkflowRunEntity);
|
|
591
639
|
const runPk = runMeta.properties.id?.fieldNames?.[0] ?? "id";
|
|
592
640
|
return {
|
|
593
641
|
table: meta.tableName,
|
|
@@ -600,7 +648,7 @@ var MikroOrmStateStore = class {
|
|
|
600
648
|
}
|
|
601
649
|
/** Resolve the `tags` column name from metadata (per the active naming strategy), for the raw LIKE. */
|
|
602
650
|
tagsColumn(em) {
|
|
603
|
-
const runMeta = em.getMetadata().get(WorkflowRunEntity
|
|
651
|
+
const runMeta = em.getMetadata().get(WorkflowRunEntity);
|
|
604
652
|
return runMeta.properties.tags?.fieldNames?.[0] ?? "tags";
|
|
605
653
|
}
|
|
606
654
|
/** Wrap a JSON column reference so it can be `LIKE`d as text. Postgres `jsonb`/`json` rejects `LIKE`
|
|
@@ -630,6 +678,35 @@ var MikroOrmStateStore = class {
|
|
|
630
678
|
});
|
|
631
679
|
return rows.map(fromCheckpointEntity);
|
|
632
680
|
}
|
|
681
|
+
async getLatestCheckpointByName(runId, name) {
|
|
682
|
+
const em = this.orm.em.fork();
|
|
683
|
+
const entity = await em.findOne(StepCheckpointEntity, {
|
|
684
|
+
runId,
|
|
685
|
+
name
|
|
686
|
+
}, {
|
|
687
|
+
orderBy: {
|
|
688
|
+
seq: "desc"
|
|
689
|
+
}
|
|
690
|
+
});
|
|
691
|
+
return entity ? fromCheckpointEntity(entity) : void 0;
|
|
692
|
+
}
|
|
693
|
+
async listCheckpointsByNamePrefix(runId, prefixes) {
|
|
694
|
+
if (prefixes.length === 0) return [];
|
|
695
|
+
const em = this.orm.em.fork();
|
|
696
|
+
const rows = await em.find(StepCheckpointEntity, {
|
|
697
|
+
runId,
|
|
698
|
+
$or: prefixes.map((p) => ({
|
|
699
|
+
name: {
|
|
700
|
+
$like: `${p}%`
|
|
701
|
+
}
|
|
702
|
+
}))
|
|
703
|
+
}, {
|
|
704
|
+
orderBy: {
|
|
705
|
+
seq: "asc"
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
return rows.map(fromCheckpointEntity);
|
|
709
|
+
}
|
|
633
710
|
async putSignalWaiter(waiter) {
|
|
634
711
|
const em = this.orm.em.fork();
|
|
635
712
|
await em.upsert(SignalWaiterEntity, {
|
|
@@ -648,7 +725,7 @@ var MikroOrmStateStore = class {
|
|
|
648
725
|
runId: entity.runId,
|
|
649
726
|
seq: entity.seq
|
|
650
727
|
};
|
|
651
|
-
await em.
|
|
728
|
+
await em.remove(entity).flush();
|
|
652
729
|
return waiter;
|
|
653
730
|
}
|
|
654
731
|
async listSignalWaiters(prefix) {
|
|
@@ -683,7 +760,7 @@ var MikroOrmStateStore = class {
|
|
|
683
760
|
});
|
|
684
761
|
if (!entity) return null;
|
|
685
762
|
const payload = entity.payload ?? void 0;
|
|
686
|
-
await em.
|
|
763
|
+
await em.remove(entity).flush();
|
|
687
764
|
return {
|
|
688
765
|
payload
|
|
689
766
|
};
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/entities.ts","../src/mikro-orm-state-store.ts","../src/schema.ts"],"sourcesContent":["export * from './entities';\nexport * from './mikro-orm-state-store';\nexport * from './schema';\n","import type { RunStatus, StepKind } from '@dudousxd/nestjs-durable-core';\nimport { Entity, PrimaryKey, Property } from '@mikro-orm/core';\n\n@Entity({ tableName: 'durable_workflow_runs' })\nexport class WorkflowRunEntity {\n @PrimaryKey()\n id!: string;\n\n @Property()\n workflow!: string;\n\n @Property()\n workflowVersion!: string;\n\n @Property()\n status!: RunStatus;\n\n @Property({ type: 'json', nullable: true })\n input?: unknown;\n\n @Property({ type: 'json', nullable: true })\n output?: unknown;\n\n @Property({ type: 'json', nullable: true })\n error?: unknown;\n\n @Property({ nullable: true })\n wakeAt?: Date;\n\n @Property({ nullable: true })\n lockedBy?: string;\n\n @Property({ nullable: true })\n lockedUntil?: Date;\n\n @Property({ type: 'integer', nullable: true })\n recoveryAttempts?: number;\n\n @Property({ type: 'json', nullable: true })\n tags?: string[] | null;\n\n @Property({ type: 'json', nullable: true })\n searchAttributes?: Record<string, string | number | boolean> | null;\n\n @Property()\n createdAt!: Date;\n\n @Property()\n updatedAt!: Date;\n}\n\n@Entity({ tableName: 'durable_step_checkpoints' })\nexport class StepCheckpointEntity {\n @PrimaryKey()\n runId!: string;\n\n @PrimaryKey()\n seq!: number;\n\n @Property()\n name!: string;\n\n @Property()\n kind!: StepKind;\n\n @Property()\n stepId!: string;\n\n @Property()\n status!: 'pending' | 'running' | 'completed' | 'failed';\n\n @Property({ type: 'json', nullable: true })\n input?: unknown;\n\n @Property({ type: 'json', nullable: true })\n output?: unknown;\n\n @Property({ type: 'json', nullable: true })\n error?: unknown;\n\n @Property({ type: 'json', nullable: true })\n events?: unknown;\n\n @Property()\n attempts!: number;\n\n @Property({ nullable: true })\n workerGroup?: string;\n\n @Property({ nullable: true })\n wakeAt?: Date;\n\n @Property({ nullable: true })\n enqueuedAt?: Date;\n\n @Property()\n startedAt!: Date;\n\n @Property()\n finishedAt!: Date;\n}\n\n/**\n * Normalized side-table for search attributes: one row per (run, key), so range/equality predicates\n * push DOWN into SQL (an EXISTS join indexed on `(key, numValue)` / `(key, strValue)`) instead of a\n * coarse scan + in-process filter. Maintained on every createRun/updateRun. Numbers land in\n * `numValue`, strings/booleans in `strValue` (booleans as \"true\"/\"false\"); see normalizeAttributeRows.\n */\n@Entity({ tableName: 'durable_run_attributes' })\nexport class RunAttributeEntity {\n @PrimaryKey()\n runId!: string;\n\n @PrimaryKey()\n key!: string;\n\n @Property({ type: 'string', nullable: true })\n strValue?: string | null;\n\n // `float`/`double` is portable across SQLite/MySQL/Postgres for numeric range scans.\n @Property({ type: 'float', nullable: true })\n numValue?: number | null;\n}\n\n@Entity({ tableName: 'durable_signal_waiters' })\nexport class SignalWaiterEntity {\n @PrimaryKey()\n token!: string;\n\n @Property()\n runId!: string;\n\n @Property()\n seq!: number;\n}\n\n@Entity({ tableName: 'durable_buffered_signals' })\nexport class BufferedSignalEntity {\n @PrimaryKey({ autoincrement: true })\n id!: number;\n\n @Property({ index: true })\n token!: string;\n\n @Property({ type: 'json', nullable: true })\n payload?: unknown;\n}\n\nexport const ENTITIES = [\n WorkflowRunEntity,\n StepCheckpointEntity,\n RunAttributeEntity,\n SignalWaiterEntity,\n BufferedSignalEntity,\n] as const;\n","import {\n type AttributeFilter,\n type RunQuery,\n type SignalWaiter,\n type StateStore,\n type StepCheckpoint,\n type StepError,\n type StepEvent,\n type WorkflowRun,\n attributeColumnFor,\n attributeOperand,\n normalizeAttributeRows,\n sqlComparator,\n} from '@dudousxd/nestjs-durable-core';\nimport type { EntityManager, MikroORM } from '@mikro-orm/core';\n\n/** Minimal structural surface of the SQL EntityManager's QueryBuilder (from `@mikro-orm/knex`),\n * typed here so the adapter needn't add a hard dependency on the knex types — a real SQL-driver EM\n * satisfies it at runtime. */\ninterface DurableQueryBuilder<T> {\n where(cond: Record<string, unknown>): DurableQueryBuilder<T>;\n andWhere(cond: string): DurableQueryBuilder<T>;\n orderBy(cond: Record<string, unknown>): DurableQueryBuilder<T>;\n limit(n: number): DurableQueryBuilder<T>;\n offset(n: number): DurableQueryBuilder<T>;\n getResultList(): Promise<T[]>;\n}\ntype SqlEm = EntityManager & {\n createQueryBuilder<T>(entity: unknown, alias: string): DurableQueryBuilder<T>;\n};\n\n/** Resolved side-table column names (per the active naming strategy) for the raw EXISTS pushdown. */\ninterface AttributeColumns {\n table: string;\n /** Side-table FK column (the run id on `durable_run_attributes`). */\n runId: string;\n /** Run table PK column (the `id` on `durable_workflow_runs`) used for the outer correlation. */\n runPk: string;\n key: string;\n strValue: string;\n numValue: string;\n}\nimport {\n BufferedSignalEntity,\n RunAttributeEntity,\n SignalWaiterEntity,\n StepCheckpointEntity,\n WorkflowRunEntity,\n} from './entities';\nimport { ensureMikroOrmDurableSchema } from './schema';\n\n/**\n * MikroORM-backed `StateStore`. Works on any MikroORM driver — Postgres, MySQL, SQLite (tested);\n * timestamps and `wakeAt` use native datetime columns. Each operation runs on a forked\n * EntityManager so it owns its unit of work.\n */\nexport class MikroOrmStateStore implements StateStore {\n constructor(private readonly orm: MikroORM) {}\n\n async ensureSchema(): Promise<void> {\n await ensureMikroOrmDurableSchema(this.orm);\n }\n\n async createRun(run: WorkflowRun): Promise<void> {\n const em = this.orm.em.fork();\n em.create(WorkflowRunEntity, toRunEntity(run));\n await em.flush();\n await this.reindexAttributes(run.id, run.searchAttributes);\n }\n\n async updateRun(runId: string, patch: Partial<WorkflowRun>): Promise<void> {\n const em = this.orm.em.fork();\n const entity = await em.findOneOrFail(WorkflowRunEntity, { id: runId });\n Object.assign(entity, toRunEntity({ ...fromRunEntity(entity), ...patch } as WorkflowRun));\n await em.flush();\n // Keep the side-table in step with the run's attributes whenever they're patched.\n if ('searchAttributes' in patch) await this.reindexAttributes(runId, patch.searchAttributes);\n }\n\n /** Rewrite a run's normalized attribute rows: delete the old set, insert the current one. Mirrors\n * the in-memory store's reindex so the side-table always reflects the run's live searchAttributes. */\n private async reindexAttributes(\n runId: string,\n attributes: WorkflowRun['searchAttributes'],\n forked?: EntityManager,\n ): Promise<void> {\n const em = forked ?? this.orm.em.fork();\n await em.nativeDelete(RunAttributeEntity, { runId });\n const rows = normalizeAttributeRows(runId, attributes);\n if (rows.length) await em.insertMany(RunAttributeEntity, rows);\n }\n\n async getRun(runId: string): Promise<WorkflowRun | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(WorkflowRunEntity, { id: runId });\n return entity ? fromRunEntity(entity) : null;\n }\n\n async getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(StepCheckpointEntity, { runId, seq });\n return entity ? fromCheckpointEntity(entity) : null;\n }\n\n async saveCheckpoint(checkpoint: StepCheckpoint): Promise<void> {\n const em = this.orm.em.fork();\n await em.upsert(StepCheckpointEntity, toCheckpointEntity(checkpoint));\n await em.flush();\n }\n\n async transaction<T>(\n work: (tx: {\n raw: unknown;\n saveCheckpoint: (cp: StepCheckpoint) => Promise<void>;\n }) => Promise<T>,\n ): Promise<T> {\n return this.orm.em.fork().transactional(async (em) =>\n work({\n raw: em,\n saveCheckpoint: async (cp) => {\n await em.upsert(StepCheckpointEntity, toCheckpointEntity(cp));\n },\n }),\n );\n }\n\n async listIncompleteRuns(): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(WorkflowRunEntity, { status: 'running' });\n return rows.map(fromRunEntity);\n }\n\n async listPendingRuns(limit: number): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(\n WorkflowRunEntity,\n { status: 'pending' },\n { orderBy: { createdAt: 'asc' }, limit }, // FIFO dispatch\n );\n return rows.map(fromRunEntity);\n }\n\n async listDueTimers(nowMs: number): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(WorkflowRunEntity, {\n status: 'suspended',\n wakeAt: { $ne: null, $lte: new Date(nowMs) },\n });\n return rows.map(fromRunEntity);\n }\n\n async tryLockRun(\n runId: string,\n owner: string,\n leaseUntilMs: number,\n nowMs: number,\n ): Promise<boolean> {\n const em = this.orm.em.fork();\n const affected = await em.nativeUpdate(\n WorkflowRunEntity,\n { id: runId, $or: [{ lockedUntil: null }, { lockedUntil: { $lte: new Date(nowMs) } }] },\n { lockedBy: owner, lockedUntil: new Date(leaseUntilMs) },\n );\n return affected === 1;\n }\n\n async releaseRunLock(runId: string): Promise<void> {\n const em = this.orm.em.fork();\n await em.nativeUpdate(WorkflowRunEntity, { id: runId }, { lockedBy: null, lockedUntil: null });\n }\n\n async renewRunLock(runId: string, owner: string, leaseUntilMs: number): Promise<boolean> {\n const em = this.orm.em.fork();\n const affected = await em.nativeUpdate(\n WorkflowRunEntity,\n { id: runId, lockedBy: owner },\n { lockedUntil: new Date(leaseUntilMs) },\n );\n return affected === 1;\n }\n\n async listRuns(query: RunQuery): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const where: Record<string, unknown> = {};\n if (query.workflow) where.workflow = query.workflow;\n // `status IN (...)`; an empty set matches nothing (mirrors the in-memory store). When both the\n // single `status` and `statuses` are set, AND them so the narrower set wins.\n if (query.status && query.statuses) {\n where.$and = [{ status: query.status }, { status: { $in: query.statuses } }];\n } else if (query.status) {\n where.status = query.status;\n } else if (query.statuses) {\n where.status = { $in: query.statuses };\n }\n const orderBy = { createdAt: 'desc' as const }; // newest first — recent runs on top in the dashboard\n // `tags`/attributes need raw SQL pushed through the QueryBuilder:\n // - tag: `tags` is a JSON column (native json/jsonb on PG/MySQL), and MikroORM JSON-serializes a\n // `{ $like }` operand (wrapping/escaping the LIKE pattern) so a plain where corrupts it to no\n // matches. A raw LIKE on the column-as-text matches the quoted token so `etl` doesn't match\n // `etl-foo`. Postgres `jsonb` rejects `LIKE` directly, so cast to text per dialect.\n // - attributes: each filter becomes a raw EXISTS against the normalized side-table, so the DB\n // filters AND paginates — no full scan + in-process filter (ANDed: one EXISTS per filter).\n // Use a QueryBuilder with a fixed root alias `r` so the raw correlations are stable across drivers.\n if (query.tag || query.attributes?.length) {\n const quote = this.idQuote(em);\n const cols = this.attributeColumns(em);\n const qb = (em as SqlEm)\n .createQueryBuilder<WorkflowRunEntity>(WorkflowRunEntity, 'r')\n .where(where)\n .orderBy(orderBy);\n if (query.tag) {\n const tagsCol = this.tagsColumn(em);\n const pattern = `%\"${query.tag.replace(/'/g, \"''\")}\"%`;\n const colExpr = this.jsonAsText(em, `${quote('r')}.${quote(tagsCol)}`);\n qb.andWhere(`${colExpr} LIKE '${pattern}'`);\n }\n for (const f of query.attributes ?? []) {\n qb.andWhere(this.attributeExistsSql(f, quote, 'r', cols));\n }\n if (query.limit != null) qb.limit(query.limit);\n if (query.offset != null) qb.offset(query.offset);\n const rows = await qb.getResultList();\n return rows.map(fromRunEntity);\n }\n const rows = await em.find(WorkflowRunEntity, where, {\n ...(query.limit != null ? { limit: query.limit } : {}),\n ...(query.offset != null ? { offset: query.offset } : {}),\n orderBy,\n });\n return rows.map(fromRunEntity);\n }\n\n /** One attribute predicate as a raw EXISTS subquery on the side-table, correlated to the outer run\n * alias. `<>` (ne) also excludes runs where the attribute is absent (missing-key-never-matches):\n * EXISTS already requires a present row, so EXISTS(... <> ...) is exactly ne-with-present. Numeric\n * operands compare the num column, everything else the str column. Identifiers are quoted per\n * driver and operands are inlined as literals (string operands are escaped by doubling quotes). */\n private attributeExistsSql(\n f: AttributeFilter,\n quote: (id: string) => string,\n alias: string,\n cols: AttributeColumns,\n ): string {\n const col = attributeColumnFor(f) === 'numValue' ? cols.numValue : cols.strValue;\n const cmp = sqlComparator(f.op);\n const operand = attributeOperand(f);\n const literal =\n typeof operand === 'number' ? String(operand) : `'${String(operand).replace(/'/g, \"''\")}'`;\n const a = quote(cols.table);\n const sub = quote('a');\n const outerId = `${quote(alias)}.${quote(cols.runPk)}`; // run PK column on the outer alias\n return `EXISTS (SELECT 1 FROM ${a} ${sub} WHERE ${sub}.${quote(cols.runId)} = ${outerId} AND ${sub}.${quote(cols.key)} = '${f.key.replace(/'/g, \"''\")}' AND ${sub}.${quote(col)} ${cmp} ${literal})`;\n }\n\n /** Resolve the side-table's actual column names from MikroORM metadata, so the raw EXISTS matches\n * the active naming strategy (underscore vs camelCase) rather than guessing. The run PK column is\n * reused for BOTH the outer correlation and the side-table FK (they share the same fieldName). */\n private attributeColumns(em: EntityManager): AttributeColumns {\n const meta = em.getMetadata().get(RunAttributeEntity.name);\n const field = (prop: string) => meta.properties[prop]?.fieldNames?.[0] ?? prop;\n const runMeta = em.getMetadata().get(WorkflowRunEntity.name);\n const runPk = runMeta.properties.id?.fieldNames?.[0] ?? 'id';\n return {\n table: meta.tableName,\n runId: field('runId'),\n runPk,\n key: field('key'),\n strValue: field('strValue'),\n numValue: field('numValue'),\n };\n }\n\n /** Resolve the `tags` column name from metadata (per the active naming strategy), for the raw LIKE. */\n private tagsColumn(em: EntityManager): string {\n const runMeta = em.getMetadata().get(WorkflowRunEntity.name);\n return runMeta.properties.tags?.fieldNames?.[0] ?? 'tags';\n }\n\n /** Wrap a JSON column reference so it can be `LIKE`d as text. Postgres `jsonb`/`json` rejects `LIKE`\n * directly (`operator does not exist: jsonb ~~ unknown`) — cast to `text`; MySQL JSON needs an\n * explicit `CHAR` cast; SQLite stores JSON as text already, so no cast. */\n private jsonAsText(em: EntityManager, colRef: string): string {\n const platform = String(em.getPlatform().constructor.name).toLowerCase();\n if (platform.includes('postgre')) return `${colRef}::text`;\n if (platform.includes('mysql') || platform.includes('mariadb'))\n return `CAST(${colRef} AS CHAR)`;\n return colRef;\n }\n\n /** Quote an identifier per the active SQL driver (MySQL/MariaDB backtick, others double-quote). */\n private idQuote(em: EntityManager): (id: string) => string {\n const platform = String(em.getPlatform().constructor.name).toLowerCase();\n const isMysql = platform.includes('mysql') || platform.includes('mariadb');\n const ch = isMysql ? '`' : '\"';\n return (id: string) => `${ch}${id}${ch}`;\n }\n\n async listCheckpoints(runId: string): Promise<StepCheckpoint[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(StepCheckpointEntity, { runId }, { orderBy: { seq: 'asc' } });\n return rows.map(fromCheckpointEntity);\n }\n\n async putSignalWaiter(waiter: SignalWaiter): Promise<void> {\n const em = this.orm.em.fork();\n await em.upsert(SignalWaiterEntity, { ...waiter });\n await em.flush();\n }\n\n async takeSignalWaiter(token: string): Promise<SignalWaiter | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(SignalWaiterEntity, { token });\n if (!entity) return null;\n const waiter: SignalWaiter = { token: entity.token, runId: entity.runId, seq: entity.seq };\n await em.removeAndFlush(entity);\n return waiter;\n }\n\n async listSignalWaiters(prefix: string): Promise<SignalWaiter[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(SignalWaiterEntity, { token: { $like: `${prefix}%` } });\n return rows.map((e) => ({ token: e.token, runId: e.runId, seq: e.seq }));\n }\n\n async bufferSignal(token: string, payload: unknown): Promise<void> {\n const em = this.orm.em.fork();\n const e = new BufferedSignalEntity();\n e.token = token;\n e.payload = payload ?? null;\n em.persist(e);\n await em.flush();\n }\n\n async takeBufferedSignal(token: string): Promise<{ payload: unknown } | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(BufferedSignalEntity, { token }, { orderBy: { id: 'asc' } });\n if (!entity) return null;\n const payload = entity.payload ?? undefined;\n await em.removeAndFlush(entity);\n return { payload };\n }\n}\n\nfunction toRunEntity(run: WorkflowRun): WorkflowRunEntity {\n const e = new WorkflowRunEntity();\n e.id = run.id;\n e.workflow = run.workflow;\n e.workflowVersion = run.workflowVersion;\n e.status = run.status;\n e.input = run.input ?? null;\n e.output = run.output ?? null;\n e.error = run.error ?? null;\n if (run.wakeAt != null) e.wakeAt = new Date(run.wakeAt);\n if (run.lockedBy !== undefined) e.lockedBy = run.lockedBy;\n if (run.lockedUntil != null) e.lockedUntil = new Date(run.lockedUntil);\n if (run.recoveryAttempts !== undefined) e.recoveryAttempts = run.recoveryAttempts;\n e.tags = run.tags ?? null;\n e.searchAttributes = run.searchAttributes ?? null;\n e.createdAt = run.createdAt;\n e.updatedAt = run.updatedAt;\n return e;\n}\n\nfunction fromRunEntity(e: WorkflowRunEntity): WorkflowRun {\n return {\n id: e.id,\n workflow: e.workflow,\n workflowVersion: e.workflowVersion,\n status: e.status,\n input: e.input ?? undefined,\n output: e.output ?? undefined,\n error: (e.error ?? undefined) as StepError | undefined,\n wakeAt: e.wakeAt?.getTime(),\n lockedBy: e.lockedBy ?? undefined,\n lockedUntil: e.lockedUntil?.getTime(),\n recoveryAttempts: e.recoveryAttempts ?? undefined,\n tags: e.tags ?? undefined,\n searchAttributes: e.searchAttributes ?? undefined,\n createdAt: e.createdAt,\n updatedAt: e.updatedAt,\n };\n}\n\nfunction toCheckpointEntity(cp: StepCheckpoint): StepCheckpointEntity {\n const e = new StepCheckpointEntity();\n e.runId = cp.runId;\n e.seq = cp.seq;\n e.name = cp.name;\n e.kind = cp.kind;\n e.stepId = cp.stepId;\n e.status = cp.status;\n e.input = cp.input ?? null;\n e.output = cp.output ?? null;\n e.error = cp.error ?? null;\n e.events = cp.events ?? null;\n e.attempts = cp.attempts;\n if (cp.workerGroup !== undefined) e.workerGroup = cp.workerGroup;\n if (cp.wakeAt != null) e.wakeAt = new Date(cp.wakeAt);\n e.enqueuedAt = cp.enqueuedAt;\n e.startedAt = cp.startedAt;\n e.finishedAt = cp.finishedAt;\n return e;\n}\n\nfunction fromCheckpointEntity(e: StepCheckpointEntity): StepCheckpoint {\n return {\n runId: e.runId,\n seq: e.seq,\n name: e.name,\n kind: e.kind,\n stepId: e.stepId,\n status: e.status,\n input: e.input ?? undefined,\n output: e.output ?? undefined,\n error: (e.error ?? undefined) as StepError | undefined,\n events: (e.events ?? undefined) as StepEvent[] | undefined,\n attempts: e.attempts,\n workerGroup: e.workerGroup ?? undefined,\n wakeAt: e.wakeAt?.getTime(),\n enqueuedAt: e.enqueuedAt ?? e.startedAt,\n startedAt: e.startedAt,\n finishedAt: e.finishedAt,\n };\n}\n","import type { MikroORM } from '@mikro-orm/core';\n\n/**\n * Idempotently create/extend the durable tables (additive, never drops). Safe to run on every\n * boot (auto-schema) and the function to call from a MikroORM migration when you disable\n * auto-schema:\n *\n * ```ts\n * export class AddDurableTables extends Migration {\n * async up() { await ensureMikroOrmDurableSchema(this.getEntityManager().getOrm()); }\n * }\n * ```\n */\nexport async function ensureMikroOrmDurableSchema(orm: MikroORM): Promise<void> {\n await orm.schema.updateSchema({ safe: true });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;ACCA,kBAA6C;;;;;;;;;;;;AAGtC,IAAMA,oBAAN,MAAMA;SAAAA;;;EAEXC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;AACF;;;;;;;;;;;;;;;;;;;IAhCcC,MAAM;IAAQC,UAAU;;;;;;IAGxBD,MAAM;IAAQC,UAAU;;;;;;IAGxBD,MAAM;IAAQC,UAAU;;;;;;IAGxBA,UAAU;;;;;;IAGVA,UAAU;;;;;;IAGVA,UAAU;;;;;;IAGVD,MAAM;IAAWC,UAAU;;;;;;IAG3BD,MAAM;IAAQC,UAAU;;;;;;IAGxBD,MAAM;IAAQC,UAAU;;;;;;;;;;;;;;IAtC5BC,WAAW;;;AAiDd,IAAMC,uBAAN,MAAMA;SAAAA;;;EAEXC;EAGAC;EAGAC;EAGAC;EAGAC;EAGApB;EAGAC;EAGAC;EAGAC;EAGAkB;EAGAC;EAGAC;EAGAnB;EAGAoB;EAGAC;EAGAC;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;IA7Bcd,MAAM;IAAQC,UAAU;;;;;;IAGxBD,MAAM;IAAQC,UAAU;;;;;;IAGxBD,MAAM;IAAQC,UAAU;;;;;;IAGxBD,MAAM;IAAQC,UAAU;;;;;;;;;;IAMxBA,UAAU;;;;;;IAGVA,UAAU;;;;;;IAGVA,UAAU;;;;;;;;;;;;;;IAzCdC,WAAW;;;AA0Dd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AAgBZ,OAAWN,GAAEkB,cAAclH,GAAGkH;AACrD,MAAIlH,GAAGW,UAAU,KAAMqF,GAAErF,SAAS,IAAIG,KAAKd,GAAGW,MAAM;AACpDqF,IAAEmB,aAAanH,GAAGmH;AAClBnB,IAAEoB,YAAYpH,GAAGoH;AACjBpB,IAAEqB,aAAarH,GAAGqH;AAClB,SAAOrB;AACT;AAnBSrG;AAqBT,SAASJ,qBAAqByG,GAAuB;AACnD,SAAO;IACL7H,OAAO6H,EAAE7H;IACTkB,KAAK2G,EAAE3G;IACPkF,MAAMyB,EAAEzB;IACRuC,MAAMd,EAAEc;IACRC,QAAQf,EAAEe;IACV5G,QAAQ6F,EAAE7F;IACVqG,OAAOR,EAAEQ,SAASF;IAClBG,QAAQT,EAAES,UAAUH;IACpBI,OAAQV,EAAEU,SAASJ;IACnBU,QAAShB,EAAEgB,UAAUV;IACrBW,UAAUjB,EAAEiB;IACZC,aAAalB,EAAEkB,eAAeZ;IAC9B3F,QAAQqF,EAAErF,QAAQkG,QAAAA;IAClBM,YAAYnB,EAAEmB,cAAcnB,EAAEoB;IAC9BA,WAAWpB,EAAEoB;IACbC,YAAYrB,EAAEqB;EAChB;AACF;AAnBS9H;","names":["WorkflowRunEntity","id","workflow","workflowVersion","status","input","output","error","wakeAt","lockedBy","lockedUntil","recoveryAttempts","tags","searchAttributes","createdAt","updatedAt","type","nullable","tableName","StepCheckpointEntity","runId","seq","name","kind","stepId","events","attempts","workerGroup","enqueuedAt","startedAt","finishedAt","RunAttributeEntity","key","strValue","numValue","SignalWaiterEntity","token","BufferedSignalEntity","payload","autoincrement","index","ENTITIES","ensureMikroOrmDurableSchema","orm","schema","updateSchema","safe","MikroOrmStateStore","orm","ensureSchema","ensureMikroOrmDurableSchema","createRun","run","em","fork","create","WorkflowRunEntity","toRunEntity","flush","reindexAttributes","id","searchAttributes","updateRun","runId","patch","entity","findOneOrFail","Object","assign","fromRunEntity","attributes","forked","nativeDelete","RunAttributeEntity","rows","normalizeAttributeRows","length","insertMany","getRun","findOne","getCheckpoint","seq","StepCheckpointEntity","fromCheckpointEntity","saveCheckpoint","checkpoint","upsert","toCheckpointEntity","transaction","work","transactional","raw","cp","listIncompleteRuns","find","status","map","listPendingRuns","limit","orderBy","createdAt","listDueTimers","nowMs","wakeAt","$ne","$lte","Date","tryLockRun","owner","leaseUntilMs","affected","nativeUpdate","$or","lockedUntil","lockedBy","releaseRunLock","renewRunLock","listRuns","query","where","workflow","statuses","$and","$in","tag","quote","idQuote","cols","attributeColumns","qb","createQueryBuilder","tagsCol","tagsColumn","pattern","replace","colExpr","jsonAsText","andWhere","f","attributeExistsSql","offset","getResultList","alias","col","attributeColumnFor","numValue","strValue","cmp","sqlComparator","op","operand","attributeOperand","literal","String","a","table","sub","outerId","runPk","key","meta","getMetadata","get","name","field","prop","properties","fieldNames","runMeta","tableName","tags","colRef","platform","getPlatform","toLowerCase","includes","isMysql","ch","listCheckpoints","putSignalWaiter","waiter","SignalWaiterEntity","takeSignalWaiter","token","removeAndFlush","listSignalWaiters","prefix","$like","e","bufferSignal","payload","BufferedSignalEntity","persist","takeBufferedSignal","undefined","workflowVersion","input","output","error","recoveryAttempts","updatedAt","getTime","kind","stepId","events","attempts","workerGroup","enqueuedAt","startedAt","finishedAt"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/entities.ts","../src/mikro-orm-state-store.ts","../src/schema.ts"],"sourcesContent":["export * from './entities';\nexport * from './mikro-orm-state-store';\nexport * from './schema';\n","import type { RunStatus, StepKind } from '@dudousxd/nestjs-durable-core';\nimport { Entity, PrimaryKey, Property } from '@mikro-orm/decorators/legacy';\n\n@Entity({ tableName: 'durable_workflow_runs' })\nexport class WorkflowRunEntity {\n @PrimaryKey({ type: 'string' })\n id!: string;\n\n @Property({ type: 'string' })\n workflow!: string;\n\n @Property({ type: 'string' })\n workflowVersion!: string;\n\n @Property({ type: 'string' })\n status!: RunStatus;\n\n @Property({ type: 'json', nullable: true })\n input?: unknown;\n\n @Property({ type: 'json', nullable: true })\n output?: unknown;\n\n @Property({ type: 'json', nullable: true })\n error?: unknown;\n\n @Property({ type: 'Date', nullable: true })\n wakeAt?: Date;\n\n @Property({ type: 'string', nullable: true })\n lockedBy?: string;\n\n @Property({ type: 'Date', nullable: true })\n lockedUntil?: Date;\n\n @Property({ type: 'integer', nullable: true })\n recoveryAttempts?: number;\n\n @Property({ type: 'json', nullable: true })\n tags?: string[] | null;\n\n @Property({ type: 'json', nullable: true })\n searchAttributes?: Record<string, string | number | boolean> | null;\n\n @Property({ type: 'Date' })\n createdAt!: Date;\n\n @Property({ type: 'Date' })\n updatedAt!: Date;\n}\n\n@Entity({ tableName: 'durable_step_checkpoints' })\nexport class StepCheckpointEntity {\n @PrimaryKey({ type: 'string' })\n runId!: string;\n\n @PrimaryKey({ type: 'integer' })\n seq!: number;\n\n @Property({ type: 'string' })\n name!: string;\n\n @Property({ type: 'string' })\n kind!: StepKind;\n\n @Property({ type: 'string' })\n stepId!: string;\n\n @Property({ type: 'string' })\n status!: 'pending' | 'running' | 'completed' | 'failed';\n\n @Property({ type: 'json', nullable: true })\n input?: unknown;\n\n @Property({ type: 'json', nullable: true })\n output?: unknown;\n\n @Property({ type: 'json', nullable: true })\n error?: unknown;\n\n @Property({ type: 'json', nullable: true })\n events?: unknown;\n\n @Property({ type: 'integer' })\n attempts!: number;\n\n @Property({ type: 'string', nullable: true })\n workerGroup?: string;\n\n @Property({ type: 'Date', nullable: true })\n wakeAt?: Date;\n\n @Property({ type: 'Date', nullable: true })\n enqueuedAt?: Date;\n\n @Property({ type: 'Date' })\n startedAt!: Date;\n\n @Property({ type: 'Date' })\n finishedAt!: Date;\n}\n\n/**\n * Normalized side-table for search attributes: one row per (run, key), so range/equality predicates\n * push DOWN into SQL (an EXISTS join indexed on `(key, numValue)` / `(key, strValue)`) instead of a\n * coarse scan + in-process filter. Maintained on every createRun/updateRun. Numbers land in\n * `numValue`, strings/booleans in `strValue` (booleans as \"true\"/\"false\"); see normalizeAttributeRows.\n */\n@Entity({ tableName: 'durable_run_attributes' })\nexport class RunAttributeEntity {\n @PrimaryKey({ type: 'string' })\n runId!: string;\n\n @PrimaryKey({ type: 'string' })\n key!: string;\n\n @Property({ type: 'string', nullable: true })\n strValue?: string | null;\n\n // `float`/`double` is portable across SQLite/MySQL/Postgres for numeric range scans.\n @Property({ type: 'float', nullable: true })\n numValue?: number | null;\n}\n\n@Entity({ tableName: 'durable_signal_waiters' })\nexport class SignalWaiterEntity {\n @PrimaryKey({ type: 'string' })\n token!: string;\n\n @Property({ type: 'string' })\n runId!: string;\n\n @Property({ type: 'integer' })\n seq!: number;\n}\n\n@Entity({ tableName: 'durable_buffered_signals' })\nexport class BufferedSignalEntity {\n @PrimaryKey({ autoincrement: true, type: 'integer' })\n id!: number;\n\n @Property({ index: true, type: 'string' })\n token!: string;\n\n @Property({ type: 'json', nullable: true })\n payload?: unknown;\n}\n\nexport const ENTITIES = [\n WorkflowRunEntity,\n StepCheckpointEntity,\n RunAttributeEntity,\n SignalWaiterEntity,\n BufferedSignalEntity,\n] as const;\n","import {\n type AttributeFilter,\n type RunQuery,\n type SignalWaiter,\n type StateStore,\n type StepCheckpoint,\n type StepError,\n type StepEvent,\n type WorkflowRun,\n attributeColumnFor,\n attributeOperand,\n normalizeAttributeRows,\n sqlComparator,\n} from '@dudousxd/nestjs-durable-core';\nimport type { EntityManager, MikroORM } from '@mikro-orm/core';\n\n/** Minimal structural surface of the SQL EntityManager's QueryBuilder (from `@mikro-orm/knex`),\n * typed here so the adapter needn't add a hard dependency on the knex types — a real SQL-driver EM\n * satisfies it at runtime. */\ninterface DurableQueryBuilder<T> {\n where(cond: Record<string, unknown>): DurableQueryBuilder<T>;\n andWhere(cond: string): DurableQueryBuilder<T>;\n orderBy(cond: Record<string, unknown>): DurableQueryBuilder<T>;\n limit(n: number): DurableQueryBuilder<T>;\n offset(n: number): DurableQueryBuilder<T>;\n getResultList(): Promise<T[]>;\n}\ntype SqlEm = EntityManager & {\n createQueryBuilder<T>(entity: unknown, alias: string): DurableQueryBuilder<T>;\n};\n\n/** Resolved side-table column names (per the active naming strategy) for the raw EXISTS pushdown. */\ninterface AttributeColumns {\n table: string;\n /** Side-table FK column (the run id on `durable_run_attributes`). */\n runId: string;\n /** Run table PK column (the `id` on `durable_workflow_runs`) used for the outer correlation. */\n runPk: string;\n key: string;\n strValue: string;\n numValue: string;\n}\nimport {\n BufferedSignalEntity,\n RunAttributeEntity,\n SignalWaiterEntity,\n StepCheckpointEntity,\n WorkflowRunEntity,\n} from './entities';\nimport { ensureMikroOrmDurableSchema } from './schema';\n\n/**\n * MikroORM-backed `StateStore`. Works on any MikroORM driver — Postgres, MySQL, SQLite (tested);\n * timestamps and `wakeAt` use native datetime columns. Each operation runs on a forked\n * EntityManager so it owns its unit of work.\n */\nexport class MikroOrmStateStore implements StateStore {\n constructor(private readonly orm: MikroORM) {}\n\n async ensureSchema(): Promise<void> {\n await ensureMikroOrmDurableSchema(this.orm);\n }\n\n async createRun(run: WorkflowRun): Promise<void> {\n const em = this.orm.em.fork();\n em.create(WorkflowRunEntity, toRunEntity(run));\n await em.flush();\n await this.reindexAttributes(run.id, run.searchAttributes);\n }\n\n async updateRun(runId: string, patch: Partial<WorkflowRun>): Promise<void> {\n const em = this.orm.em.fork();\n const entity = await em.findOneOrFail(WorkflowRunEntity, { id: runId });\n Object.assign(entity, toRunEntity({ ...fromRunEntity(entity), ...patch } as WorkflowRun));\n await em.flush();\n // Keep the side-table in step with the run's attributes whenever they're patched.\n if ('searchAttributes' in patch) await this.reindexAttributes(runId, patch.searchAttributes);\n }\n\n /** Rewrite a run's normalized attribute rows: delete the old set, insert the current one. Mirrors\n * the in-memory store's reindex so the side-table always reflects the run's live searchAttributes. */\n private async reindexAttributes(\n runId: string,\n attributes: WorkflowRun['searchAttributes'],\n forked?: EntityManager,\n ): Promise<void> {\n const em = forked ?? this.orm.em.fork();\n await em.nativeDelete(RunAttributeEntity, { runId });\n const rows = normalizeAttributeRows(runId, attributes);\n if (rows.length) await em.insertMany(RunAttributeEntity, rows);\n }\n\n async getRun(runId: string): Promise<WorkflowRun | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(WorkflowRunEntity, { id: runId });\n return entity ? fromRunEntity(entity) : null;\n }\n\n async getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(StepCheckpointEntity, { runId, seq });\n return entity ? fromCheckpointEntity(entity) : null;\n }\n\n async saveCheckpoint(checkpoint: StepCheckpoint): Promise<void> {\n const em = this.orm.em.fork();\n await em.upsert(StepCheckpointEntity, toCheckpointEntity(checkpoint));\n await em.flush();\n }\n\n async transaction<T>(\n work: (tx: {\n raw: unknown;\n saveCheckpoint: (cp: StepCheckpoint) => Promise<void>;\n }) => Promise<T>,\n ): Promise<T> {\n return this.orm.em.fork().transactional(async (em) =>\n work({\n raw: em,\n saveCheckpoint: async (cp) => {\n await em.upsert(StepCheckpointEntity, toCheckpointEntity(cp));\n },\n }),\n );\n }\n\n async listIncompleteRuns(): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(WorkflowRunEntity, { status: 'running' });\n return rows.map(fromRunEntity);\n }\n\n async listPendingRuns(limit: number): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(\n WorkflowRunEntity,\n { status: 'pending' },\n { orderBy: { createdAt: 'asc' }, limit }, // FIFO dispatch\n );\n return rows.map(fromRunEntity);\n }\n\n async listDueTimers(nowMs: number): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(WorkflowRunEntity, {\n status: 'suspended',\n wakeAt: { $ne: null, $lte: new Date(nowMs) },\n });\n return rows.map(fromRunEntity);\n }\n\n async tryLockRun(\n runId: string,\n owner: string,\n leaseUntilMs: number,\n nowMs: number,\n ): Promise<boolean> {\n const em = this.orm.em.fork();\n const affected = await em.nativeUpdate(\n WorkflowRunEntity,\n { id: runId, $or: [{ lockedUntil: null }, { lockedUntil: { $lte: new Date(nowMs) } }] },\n { lockedBy: owner, lockedUntil: new Date(leaseUntilMs) },\n );\n return affected === 1;\n }\n\n async releaseRunLock(runId: string): Promise<void> {\n const em = this.orm.em.fork();\n await em.nativeUpdate(WorkflowRunEntity, { id: runId }, { lockedBy: null, lockedUntil: null });\n }\n\n async renewRunLock(runId: string, owner: string, leaseUntilMs: number): Promise<boolean> {\n const em = this.orm.em.fork();\n const affected = await em.nativeUpdate(\n WorkflowRunEntity,\n { id: runId, lockedBy: owner },\n { lockedUntil: new Date(leaseUntilMs) },\n );\n return affected === 1;\n }\n\n async listRuns(query: RunQuery): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const where: Record<string, unknown> = {};\n if (query.workflow) where.workflow = query.workflow;\n // `status IN (...)`; an empty set matches nothing (mirrors the in-memory store). When both the\n // single `status` and `statuses` are set, AND them so the narrower set wins.\n if (query.status && query.statuses) {\n where.$and = [{ status: query.status }, { status: { $in: query.statuses } }];\n } else if (query.status) {\n where.status = query.status;\n } else if (query.statuses) {\n where.status = { $in: query.statuses };\n }\n const orderBy = { createdAt: 'desc' as const }; // newest first — recent runs on top in the dashboard\n // `tags`/attributes need raw SQL pushed through the QueryBuilder:\n // - tag: `tags` is a JSON column (native json/jsonb on PG/MySQL), and MikroORM JSON-serializes a\n // `{ $like }` operand (wrapping/escaping the LIKE pattern) so a plain where corrupts it to no\n // matches. A raw LIKE on the column-as-text matches the quoted token so `etl` doesn't match\n // `etl-foo`. Postgres `jsonb` rejects `LIKE` directly, so cast to text per dialect.\n // - attributes: each filter becomes a raw EXISTS against the normalized side-table, so the DB\n // filters AND paginates — no full scan + in-process filter (ANDed: one EXISTS per filter).\n // Use a QueryBuilder with a fixed root alias `r` so the raw correlations are stable across drivers.\n if (query.tag || query.attributes?.length) {\n const quote = this.idQuote(em);\n const cols = this.attributeColumns(em);\n const qb = (em as SqlEm)\n .createQueryBuilder<WorkflowRunEntity>(WorkflowRunEntity, 'r')\n .where(where)\n .orderBy(orderBy);\n if (query.tag) {\n const tagsCol = this.tagsColumn(em);\n const pattern = `%\"${query.tag.replace(/'/g, \"''\")}\"%`;\n const colExpr = this.jsonAsText(em, `${quote('r')}.${quote(tagsCol)}`);\n qb.andWhere(`${colExpr} LIKE '${pattern}'`);\n }\n for (const f of query.attributes ?? []) {\n qb.andWhere(this.attributeExistsSql(f, quote, 'r', cols));\n }\n if (query.limit != null) qb.limit(query.limit);\n if (query.offset != null) qb.offset(query.offset);\n const rows = await qb.getResultList();\n return rows.map(fromRunEntity);\n }\n const rows = await em.find(WorkflowRunEntity, where, {\n ...(query.limit != null ? { limit: query.limit } : {}),\n ...(query.offset != null ? { offset: query.offset } : {}),\n orderBy,\n });\n return rows.map(fromRunEntity);\n }\n\n /** One attribute predicate as a raw EXISTS subquery on the side-table, correlated to the outer run\n * alias. `<>` (ne) also excludes runs where the attribute is absent (missing-key-never-matches):\n * EXISTS already requires a present row, so EXISTS(... <> ...) is exactly ne-with-present. Numeric\n * operands compare the num column, everything else the str column. Identifiers are quoted per\n * driver and operands are inlined as literals (string operands are escaped by doubling quotes). */\n private attributeExistsSql(\n f: AttributeFilter,\n quote: (id: string) => string,\n alias: string,\n cols: AttributeColumns,\n ): string {\n const col = attributeColumnFor(f) === 'numValue' ? cols.numValue : cols.strValue;\n const cmp = sqlComparator(f.op);\n const operand = attributeOperand(f);\n const literal =\n typeof operand === 'number' ? String(operand) : `'${String(operand).replace(/'/g, \"''\")}'`;\n const a = quote(cols.table);\n const sub = quote('a');\n const outerId = `${quote(alias)}.${quote(cols.runPk)}`; // run PK column on the outer alias\n return `EXISTS (SELECT 1 FROM ${a} ${sub} WHERE ${sub}.${quote(cols.runId)} = ${outerId} AND ${sub}.${quote(cols.key)} = '${f.key.replace(/'/g, \"''\")}' AND ${sub}.${quote(col)} ${cmp} ${literal})`;\n }\n\n /** Resolve the side-table's actual column names from MikroORM metadata, so the raw EXISTS matches\n * the active naming strategy (underscore vs camelCase) rather than guessing. The run PK column is\n * reused for BOTH the outer correlation and the side-table FK (they share the same fieldName). */\n private attributeColumns(em: EntityManager): AttributeColumns {\n const meta = em.getMetadata().get(RunAttributeEntity);\n const field = (prop: string) =>\n meta.props.find((p) => p.name === prop)?.fieldNames?.[0] ?? prop;\n const runMeta = em.getMetadata().get(WorkflowRunEntity);\n const runPk = runMeta.properties.id?.fieldNames?.[0] ?? 'id';\n return {\n table: meta.tableName,\n runId: field('runId'),\n runPk,\n key: field('key'),\n strValue: field('strValue'),\n numValue: field('numValue'),\n };\n }\n\n /** Resolve the `tags` column name from metadata (per the active naming strategy), for the raw LIKE. */\n private tagsColumn(em: EntityManager): string {\n const runMeta = em.getMetadata().get(WorkflowRunEntity);\n return runMeta.properties.tags?.fieldNames?.[0] ?? 'tags';\n }\n\n /** Wrap a JSON column reference so it can be `LIKE`d as text. Postgres `jsonb`/`json` rejects `LIKE`\n * directly (`operator does not exist: jsonb ~~ unknown`) — cast to `text`; MySQL JSON needs an\n * explicit `CHAR` cast; SQLite stores JSON as text already, so no cast. */\n private jsonAsText(em: EntityManager, colRef: string): string {\n const platform = String(em.getPlatform().constructor.name).toLowerCase();\n if (platform.includes('postgre')) return `${colRef}::text`;\n if (platform.includes('mysql') || platform.includes('mariadb'))\n return `CAST(${colRef} AS CHAR)`;\n return colRef;\n }\n\n /** Quote an identifier per the active SQL driver (MySQL/MariaDB backtick, others double-quote). */\n private idQuote(em: EntityManager): (id: string) => string {\n const platform = String(em.getPlatform().constructor.name).toLowerCase();\n const isMysql = platform.includes('mysql') || platform.includes('mariadb');\n const ch = isMysql ? '`' : '\"';\n return (id: string) => `${ch}${id}${ch}`;\n }\n\n async listCheckpoints(runId: string): Promise<StepCheckpoint[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(StepCheckpointEntity, { runId }, { orderBy: { seq: 'asc' } });\n return rows.map(fromCheckpointEntity);\n }\n\n async getLatestCheckpointByName(\n runId: string,\n name: string,\n ): Promise<StepCheckpoint | undefined> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(\n StepCheckpointEntity,\n { runId, name },\n { orderBy: { seq: 'desc' } },\n );\n return entity ? fromCheckpointEntity(entity) : undefined;\n }\n\n async listCheckpointsByNamePrefix(runId: string, prefixes: string[]): Promise<StepCheckpoint[]> {\n if (prefixes.length === 0) return [];\n const em = this.orm.em.fork();\n const rows = await em.find(\n StepCheckpointEntity,\n { runId, $or: prefixes.map((p) => ({ name: { $like: `${p}%` } })) },\n { orderBy: { seq: 'asc' } },\n );\n return rows.map(fromCheckpointEntity);\n }\n\n async putSignalWaiter(waiter: SignalWaiter): Promise<void> {\n const em = this.orm.em.fork();\n await em.upsert(SignalWaiterEntity, { ...waiter });\n await em.flush();\n }\n\n async takeSignalWaiter(token: string): Promise<SignalWaiter | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(SignalWaiterEntity, { token });\n if (!entity) return null;\n const waiter: SignalWaiter = { token: entity.token, runId: entity.runId, seq: entity.seq };\n await em.remove(entity).flush();\n return waiter;\n }\n\n async listSignalWaiters(prefix: string): Promise<SignalWaiter[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(SignalWaiterEntity, { token: { $like: `${prefix}%` } });\n return rows.map((e) => ({ token: e.token, runId: e.runId, seq: e.seq }));\n }\n\n async bufferSignal(token: string, payload: unknown): Promise<void> {\n const em = this.orm.em.fork();\n const e = new BufferedSignalEntity();\n e.token = token;\n e.payload = payload ?? null;\n em.persist(e);\n await em.flush();\n }\n\n async takeBufferedSignal(token: string): Promise<{ payload: unknown } | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(BufferedSignalEntity, { token }, { orderBy: { id: 'asc' } });\n if (!entity) return null;\n const payload = entity.payload ?? undefined;\n await em.remove(entity).flush();\n return { payload };\n }\n}\n\nfunction toRunEntity(run: WorkflowRun): WorkflowRunEntity {\n const e = new WorkflowRunEntity();\n e.id = run.id;\n e.workflow = run.workflow;\n e.workflowVersion = run.workflowVersion;\n e.status = run.status;\n e.input = run.input ?? null;\n e.output = run.output ?? null;\n e.error = run.error ?? null;\n if (run.wakeAt != null) e.wakeAt = new Date(run.wakeAt);\n if (run.lockedBy !== undefined) e.lockedBy = run.lockedBy;\n if (run.lockedUntil != null) e.lockedUntil = new Date(run.lockedUntil);\n if (run.recoveryAttempts !== undefined) e.recoveryAttempts = run.recoveryAttempts;\n e.tags = run.tags ?? null;\n e.searchAttributes = run.searchAttributes ?? null;\n e.createdAt = run.createdAt;\n e.updatedAt = run.updatedAt;\n return e;\n}\n\nfunction fromRunEntity(e: WorkflowRunEntity): WorkflowRun {\n return {\n id: e.id,\n workflow: e.workflow,\n workflowVersion: e.workflowVersion,\n status: e.status,\n input: e.input ?? undefined,\n output: e.output ?? undefined,\n error: (e.error ?? undefined) as StepError | undefined,\n wakeAt: e.wakeAt?.getTime(),\n lockedBy: e.lockedBy ?? undefined,\n lockedUntil: e.lockedUntil?.getTime(),\n recoveryAttempts: e.recoveryAttempts ?? undefined,\n tags: e.tags ?? undefined,\n searchAttributes: e.searchAttributes ?? undefined,\n createdAt: e.createdAt,\n updatedAt: e.updatedAt,\n };\n}\n\nfunction toCheckpointEntity(cp: StepCheckpoint): StepCheckpointEntity {\n const e = new StepCheckpointEntity();\n e.runId = cp.runId;\n e.seq = cp.seq;\n e.name = cp.name;\n e.kind = cp.kind;\n e.stepId = cp.stepId;\n e.status = cp.status;\n e.input = cp.input ?? null;\n e.output = cp.output ?? null;\n e.error = cp.error ?? null;\n e.events = cp.events ?? null;\n e.attempts = cp.attempts;\n if (cp.workerGroup !== undefined) e.workerGroup = cp.workerGroup;\n if (cp.wakeAt != null) e.wakeAt = new Date(cp.wakeAt);\n e.enqueuedAt = cp.enqueuedAt;\n e.startedAt = cp.startedAt;\n e.finishedAt = cp.finishedAt;\n return e;\n}\n\nfunction fromCheckpointEntity(e: StepCheckpointEntity): StepCheckpoint {\n return {\n runId: e.runId,\n seq: e.seq,\n name: e.name,\n kind: e.kind,\n stepId: e.stepId,\n status: e.status,\n input: e.input ?? undefined,\n output: e.output ?? undefined,\n error: (e.error ?? undefined) as StepError | undefined,\n events: (e.events ?? undefined) as StepEvent[] | undefined,\n attempts: e.attempts,\n workerGroup: e.workerGroup ?? undefined,\n wakeAt: e.wakeAt?.getTime(),\n enqueuedAt: e.enqueuedAt ?? e.startedAt,\n startedAt: e.startedAt,\n finishedAt: e.finishedAt,\n };\n}\n","import type { MikroORM } from '@mikro-orm/core';\n\n/**\n * Idempotently create/extend the durable tables (additive, never drops). Safe to run on every\n * boot (auto-schema) and the function to call from a MikroORM migration when you disable\n * auto-schema:\n *\n * ```ts\n * export class AddDurableTables extends Migration {\n * async up() { await ensureMikroOrmDurableSchema(this.getEntityManager().getOrm()); }\n * }\n * ```\n */\nexport async function ensureMikroOrmDurableSchema(orm: MikroORM): Promise<void> {\n await orm.schema.update({ safe: true });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;ACCA,oBAA6C;;;;;;;;;;;;AAGtC,IAAMA,oBAAN,MAAMA;SAAAA;;;EAEXC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;AACF;;;IA5CgBC,MAAM;;;;;;IAGRA,MAAM;;;;;;IAGNA,MAAM;;;;;;IAGNA,MAAM;;;;;;IAGNA,MAAM;IAAQC,UAAU;;;;;;IAGxBD,MAAM;IAAQC,UAAU;;;;;;IAGxBD,MAAM;IAAQC,UAAU;;;;;;IAGxBD,MAAM;IAAQC,UAAU;;;;;;IAGxBD,MAAM;IAAUC,UAAU;;;;;;IAG1BD,MAAM;IAAQC,UAAU;;;;;;IAGxBD,MAAM;IAAWC,UAAU;;;;;;IAG3BD,MAAM;IAAQC,UAAU;;;;;;IAGxBD,MAAM;IAAQC,UAAU;;;;;;IAGxBD,MAAM;;;;;;IAGNA,MAAM;;;;;;IA5CVE,WAAW;;;AAiDd,IAAMC,uBAAN,MAAMA;SAAAA;;;EAEXC;E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SAAS9G,GAAG8G,UAAU;AACxBR,IAAES,QAAQ/G,GAAG+G,SAAS;AACtBT,IAAEe,SAASrH,GAAGqH,UAAU;AACxBf,IAAEgB,WAAWtH,GAAGsH;AAChB,MAAItH,GAAGuH,gBAAgB7B,OAAWY,GAAEiB,cAAcvH,GAAGuH;AACrD,MAAIvH,GAAGW,UAAU,KAAM2F,GAAE3F,SAAS,IAAIG,KAAKd,GAAGW,MAAM;AACpD2F,IAAEkB,aAAaxH,GAAGwH;AAClBlB,IAAEmB,YAAYzH,GAAGyH;AACjBnB,IAAEoB,aAAa1H,GAAG0H;AAClB,SAAOpB;AACT;AAnBS3G;AAqBT,SAASJ,qBAAqB+G,GAAuB;AACnD,SAAO;IACLnI,OAAOmI,EAAEnI;IACTkB,KAAKiH,EAAEjH;IACPsF,MAAM2B,EAAE3B;IACRwC,MAAMb,EAAEa;IACRC,QAAQd,EAAEc;IACVjH,QAAQmG,EAAEnG;IACV0G,OAAOP,EAAEO,SAASnB;IAClBoB,QAAQR,EAAEQ,UAAUpB;IACpBqB,OAAQT,EAAES,SAASrB;IACnB2B,QAASf,EAAEe,UAAU3B;IACrB4B,UAAUhB,EAAEgB;IACZC,aAAajB,EAAEiB,eAAe7B;IAC9B/E,QAAQ2F,EAAE3F,QAAQuG,QAAAA;IAClBM,YAAYlB,EAAEkB,cAAclB,EAAEmB;IAC9BA,WAAWnB,EAAEmB;IACbC,YAAYpB,EAAEoB;EAChB;AACF;AAnBSnI;","names":["WorkflowRunEntity","id","workflow","workflowVersion","status","input","output","error","wakeAt","lockedBy","lockedUntil","recoveryAttempts","tags","searchAttributes","createdAt","updatedAt","type","nullable","tableName","StepCheckpointEntity","runId","seq","name","kind","stepId","events","attempts","workerGroup","enqueuedAt","startedAt","finishedAt","RunAttributeEntity","key","strValue","numValue","SignalWaiterEntity","token","BufferedSignalEntity","payload","autoincrement","index","ENTITIES","ensureMikroOrmDurableSchema","orm","schema","update","safe","MikroOrmStateStore","orm","ensureSchema","ensureMikroOrmDurableSchema","createRun","run","em","fork","create","WorkflowRunEntity","toRunEntity","flush","reindexAttributes","id","searchAttributes","updateRun","runId","patch","entity","findOneOrFail","Object","assign","fromRunEntity","attributes","forked","nativeDelete","RunAttributeEntity","rows","normalizeAttributeRows","length","insertMany","getRun","findOne","getCheckpoint","seq","StepCheckpointEntity","fromCheckpointEntity","saveCheckpoint","checkpoint","upsert","toCheckpointEntity","transaction","work","transactional","raw","cp","listIncompleteRuns","find","status","map","listPendingRuns","limit","orderBy","createdAt","listDueTimers","nowMs","wakeAt","$ne","$lte","Date","tryLockRun","owner","leaseUntilMs","affected","nativeUpdate","$or","lockedUntil","lockedBy","releaseRunLock","renewRunLock","listRuns","query","where","workflow","statuses","$and","$in","tag","quote","idQuote","cols","attributeColumns","qb","createQueryBuilder","tagsCol","tagsColumn","pattern","replace","colExpr","jsonAsText","andWhere","f","attributeExistsSql","offset","getResultList","alias","col","attributeColumnFor","numValue","strValue","cmp","sqlComparator","op","operand","attributeOperand","literal","String","a","table","sub","outerId","runPk","key","meta","getMetadata","get","field","prop","props","p","name","fieldNames","runMeta","properties","tableName","tags","colRef","platform","getPlatform","toLowerCase","includes","isMysql","ch","listCheckpoints","getLatestCheckpointByName","undefined","listCheckpointsByNamePrefix","prefixes","$like","putSignalWaiter","waiter","SignalWaiterEntity","takeSignalWaiter","token","remove","listSignalWaiters","prefix","e","bufferSignal","payload","BufferedSignalEntity","persist","takeBufferedSignal","workflowVersion","input","output","error","recoveryAttempts","updatedAt","getTime","kind","stepId","events","attempts","workerGroup","enqueuedAt","startedAt","finishedAt"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -107,6 +107,8 @@ declare class MikroOrmStateStore implements StateStore {
|
|
|
107
107
|
/** Quote an identifier per the active SQL driver (MySQL/MariaDB backtick, others double-quote). */
|
|
108
108
|
private idQuote;
|
|
109
109
|
listCheckpoints(runId: string): Promise<StepCheckpoint[]>;
|
|
110
|
+
getLatestCheckpointByName(runId: string, name: string): Promise<StepCheckpoint | undefined>;
|
|
111
|
+
listCheckpointsByNamePrefix(runId: string, prefixes: string[]): Promise<StepCheckpoint[]>;
|
|
110
112
|
putSignalWaiter(waiter: SignalWaiter): Promise<void>;
|
|
111
113
|
takeSignalWaiter(token: string): Promise<SignalWaiter | null>;
|
|
112
114
|
listSignalWaiters(prefix: string): Promise<SignalWaiter[]>;
|
package/dist/index.d.ts
CHANGED
|
@@ -107,6 +107,8 @@ declare class MikroOrmStateStore implements StateStore {
|
|
|
107
107
|
/** Quote an identifier per the active SQL driver (MySQL/MariaDB backtick, others double-quote). */
|
|
108
108
|
private idQuote;
|
|
109
109
|
listCheckpoints(runId: string): Promise<StepCheckpoint[]>;
|
|
110
|
+
getLatestCheckpointByName(runId: string, name: string): Promise<StepCheckpoint | undefined>;
|
|
111
|
+
listCheckpointsByNamePrefix(runId: string, prefixes: string[]): Promise<StepCheckpoint[]>;
|
|
110
112
|
putSignalWaiter(waiter: SignalWaiter): Promise<void>;
|
|
111
113
|
takeSignalWaiter(token: string): Promise<SignalWaiter | null>;
|
|
112
114
|
listSignalWaiters(prefix: string): Promise<SignalWaiter[]>;
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// src/entities.ts
|
|
5
|
-
import { Entity, PrimaryKey, Property } from "@mikro-orm/
|
|
5
|
+
import { Entity, PrimaryKey, Property } from "@mikro-orm/decorators/legacy";
|
|
6
6
|
function _ts_decorate(decorators, target, key, desc) {
|
|
7
7
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -35,19 +35,27 @@ var WorkflowRunEntity = class {
|
|
|
35
35
|
updatedAt;
|
|
36
36
|
};
|
|
37
37
|
_ts_decorate([
|
|
38
|
-
PrimaryKey(
|
|
38
|
+
PrimaryKey({
|
|
39
|
+
type: "string"
|
|
40
|
+
}),
|
|
39
41
|
_ts_metadata("design:type", String)
|
|
40
42
|
], WorkflowRunEntity.prototype, "id", void 0);
|
|
41
43
|
_ts_decorate([
|
|
42
|
-
Property(
|
|
44
|
+
Property({
|
|
45
|
+
type: "string"
|
|
46
|
+
}),
|
|
43
47
|
_ts_metadata("design:type", String)
|
|
44
48
|
], WorkflowRunEntity.prototype, "workflow", void 0);
|
|
45
49
|
_ts_decorate([
|
|
46
|
-
Property(
|
|
50
|
+
Property({
|
|
51
|
+
type: "string"
|
|
52
|
+
}),
|
|
47
53
|
_ts_metadata("design:type", String)
|
|
48
54
|
], WorkflowRunEntity.prototype, "workflowVersion", void 0);
|
|
49
55
|
_ts_decorate([
|
|
50
|
-
Property(
|
|
56
|
+
Property({
|
|
57
|
+
type: "string"
|
|
58
|
+
}),
|
|
51
59
|
_ts_metadata("design:type", typeof RunStatus === "undefined" ? Object : RunStatus)
|
|
52
60
|
], WorkflowRunEntity.prototype, "status", void 0);
|
|
53
61
|
_ts_decorate([
|
|
@@ -73,18 +81,21 @@ _ts_decorate([
|
|
|
73
81
|
], WorkflowRunEntity.prototype, "error", void 0);
|
|
74
82
|
_ts_decorate([
|
|
75
83
|
Property({
|
|
84
|
+
type: "Date",
|
|
76
85
|
nullable: true
|
|
77
86
|
}),
|
|
78
87
|
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
79
88
|
], WorkflowRunEntity.prototype, "wakeAt", void 0);
|
|
80
89
|
_ts_decorate([
|
|
81
90
|
Property({
|
|
91
|
+
type: "string",
|
|
82
92
|
nullable: true
|
|
83
93
|
}),
|
|
84
94
|
_ts_metadata("design:type", String)
|
|
85
95
|
], WorkflowRunEntity.prototype, "lockedBy", void 0);
|
|
86
96
|
_ts_decorate([
|
|
87
97
|
Property({
|
|
98
|
+
type: "Date",
|
|
88
99
|
nullable: true
|
|
89
100
|
}),
|
|
90
101
|
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
@@ -111,11 +122,15 @@ _ts_decorate([
|
|
|
111
122
|
_ts_metadata("design:type", Object)
|
|
112
123
|
], WorkflowRunEntity.prototype, "searchAttributes", void 0);
|
|
113
124
|
_ts_decorate([
|
|
114
|
-
Property(
|
|
125
|
+
Property({
|
|
126
|
+
type: "Date"
|
|
127
|
+
}),
|
|
115
128
|
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
116
129
|
], WorkflowRunEntity.prototype, "createdAt", void 0);
|
|
117
130
|
_ts_decorate([
|
|
118
|
-
Property(
|
|
131
|
+
Property({
|
|
132
|
+
type: "Date"
|
|
133
|
+
}),
|
|
119
134
|
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
120
135
|
], WorkflowRunEntity.prototype, "updatedAt", void 0);
|
|
121
136
|
WorkflowRunEntity = _ts_decorate([
|
|
@@ -145,27 +160,39 @@ var StepCheckpointEntity = class {
|
|
|
145
160
|
finishedAt;
|
|
146
161
|
};
|
|
147
162
|
_ts_decorate([
|
|
148
|
-
PrimaryKey(
|
|
163
|
+
PrimaryKey({
|
|
164
|
+
type: "string"
|
|
165
|
+
}),
|
|
149
166
|
_ts_metadata("design:type", String)
|
|
150
167
|
], StepCheckpointEntity.prototype, "runId", void 0);
|
|
151
168
|
_ts_decorate([
|
|
152
|
-
PrimaryKey(
|
|
169
|
+
PrimaryKey({
|
|
170
|
+
type: "integer"
|
|
171
|
+
}),
|
|
153
172
|
_ts_metadata("design:type", Number)
|
|
154
173
|
], StepCheckpointEntity.prototype, "seq", void 0);
|
|
155
174
|
_ts_decorate([
|
|
156
|
-
Property(
|
|
175
|
+
Property({
|
|
176
|
+
type: "string"
|
|
177
|
+
}),
|
|
157
178
|
_ts_metadata("design:type", String)
|
|
158
179
|
], StepCheckpointEntity.prototype, "name", void 0);
|
|
159
180
|
_ts_decorate([
|
|
160
|
-
Property(
|
|
181
|
+
Property({
|
|
182
|
+
type: "string"
|
|
183
|
+
}),
|
|
161
184
|
_ts_metadata("design:type", typeof StepKind === "undefined" ? Object : StepKind)
|
|
162
185
|
], StepCheckpointEntity.prototype, "kind", void 0);
|
|
163
186
|
_ts_decorate([
|
|
164
|
-
Property(
|
|
187
|
+
Property({
|
|
188
|
+
type: "string"
|
|
189
|
+
}),
|
|
165
190
|
_ts_metadata("design:type", String)
|
|
166
191
|
], StepCheckpointEntity.prototype, "stepId", void 0);
|
|
167
192
|
_ts_decorate([
|
|
168
|
-
Property(
|
|
193
|
+
Property({
|
|
194
|
+
type: "string"
|
|
195
|
+
}),
|
|
169
196
|
_ts_metadata("design:type", String)
|
|
170
197
|
], StepCheckpointEntity.prototype, "status", void 0);
|
|
171
198
|
_ts_decorate([
|
|
@@ -197,33 +224,42 @@ _ts_decorate([
|
|
|
197
224
|
_ts_metadata("design:type", Object)
|
|
198
225
|
], StepCheckpointEntity.prototype, "events", void 0);
|
|
199
226
|
_ts_decorate([
|
|
200
|
-
Property(
|
|
227
|
+
Property({
|
|
228
|
+
type: "integer"
|
|
229
|
+
}),
|
|
201
230
|
_ts_metadata("design:type", Number)
|
|
202
231
|
], StepCheckpointEntity.prototype, "attempts", void 0);
|
|
203
232
|
_ts_decorate([
|
|
204
233
|
Property({
|
|
234
|
+
type: "string",
|
|
205
235
|
nullable: true
|
|
206
236
|
}),
|
|
207
237
|
_ts_metadata("design:type", String)
|
|
208
238
|
], StepCheckpointEntity.prototype, "workerGroup", void 0);
|
|
209
239
|
_ts_decorate([
|
|
210
240
|
Property({
|
|
241
|
+
type: "Date",
|
|
211
242
|
nullable: true
|
|
212
243
|
}),
|
|
213
244
|
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
214
245
|
], StepCheckpointEntity.prototype, "wakeAt", void 0);
|
|
215
246
|
_ts_decorate([
|
|
216
247
|
Property({
|
|
248
|
+
type: "Date",
|
|
217
249
|
nullable: true
|
|
218
250
|
}),
|
|
219
251
|
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
220
252
|
], StepCheckpointEntity.prototype, "enqueuedAt", void 0);
|
|
221
253
|
_ts_decorate([
|
|
222
|
-
Property(
|
|
254
|
+
Property({
|
|
255
|
+
type: "Date"
|
|
256
|
+
}),
|
|
223
257
|
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
224
258
|
], StepCheckpointEntity.prototype, "startedAt", void 0);
|
|
225
259
|
_ts_decorate([
|
|
226
|
-
Property(
|
|
260
|
+
Property({
|
|
261
|
+
type: "Date"
|
|
262
|
+
}),
|
|
227
263
|
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
228
264
|
], StepCheckpointEntity.prototype, "finishedAt", void 0);
|
|
229
265
|
StepCheckpointEntity = _ts_decorate([
|
|
@@ -242,11 +278,15 @@ var RunAttributeEntity = class {
|
|
|
242
278
|
numValue;
|
|
243
279
|
};
|
|
244
280
|
_ts_decorate([
|
|
245
|
-
PrimaryKey(
|
|
281
|
+
PrimaryKey({
|
|
282
|
+
type: "string"
|
|
283
|
+
}),
|
|
246
284
|
_ts_metadata("design:type", String)
|
|
247
285
|
], RunAttributeEntity.prototype, "runId", void 0);
|
|
248
286
|
_ts_decorate([
|
|
249
|
-
PrimaryKey(
|
|
287
|
+
PrimaryKey({
|
|
288
|
+
type: "string"
|
|
289
|
+
}),
|
|
250
290
|
_ts_metadata("design:type", String)
|
|
251
291
|
], RunAttributeEntity.prototype, "key", void 0);
|
|
252
292
|
_ts_decorate([
|
|
@@ -277,15 +317,21 @@ var SignalWaiterEntity = class {
|
|
|
277
317
|
seq;
|
|
278
318
|
};
|
|
279
319
|
_ts_decorate([
|
|
280
|
-
PrimaryKey(
|
|
320
|
+
PrimaryKey({
|
|
321
|
+
type: "string"
|
|
322
|
+
}),
|
|
281
323
|
_ts_metadata("design:type", String)
|
|
282
324
|
], SignalWaiterEntity.prototype, "token", void 0);
|
|
283
325
|
_ts_decorate([
|
|
284
|
-
Property(
|
|
326
|
+
Property({
|
|
327
|
+
type: "string"
|
|
328
|
+
}),
|
|
285
329
|
_ts_metadata("design:type", String)
|
|
286
330
|
], SignalWaiterEntity.prototype, "runId", void 0);
|
|
287
331
|
_ts_decorate([
|
|
288
|
-
Property(
|
|
332
|
+
Property({
|
|
333
|
+
type: "integer"
|
|
334
|
+
}),
|
|
289
335
|
_ts_metadata("design:type", Number)
|
|
290
336
|
], SignalWaiterEntity.prototype, "seq", void 0);
|
|
291
337
|
SignalWaiterEntity = _ts_decorate([
|
|
@@ -303,13 +349,15 @@ var BufferedSignalEntity = class {
|
|
|
303
349
|
};
|
|
304
350
|
_ts_decorate([
|
|
305
351
|
PrimaryKey({
|
|
306
|
-
autoincrement: true
|
|
352
|
+
autoincrement: true,
|
|
353
|
+
type: "integer"
|
|
307
354
|
}),
|
|
308
355
|
_ts_metadata("design:type", Number)
|
|
309
356
|
], BufferedSignalEntity.prototype, "id", void 0);
|
|
310
357
|
_ts_decorate([
|
|
311
358
|
Property({
|
|
312
|
-
index: true
|
|
359
|
+
index: true,
|
|
360
|
+
type: "string"
|
|
313
361
|
}),
|
|
314
362
|
_ts_metadata("design:type", String)
|
|
315
363
|
], BufferedSignalEntity.prototype, "token", void 0);
|
|
@@ -338,7 +386,7 @@ import { attributeColumnFor, attributeOperand, normalizeAttributeRows, sqlCompar
|
|
|
338
386
|
|
|
339
387
|
// src/schema.ts
|
|
340
388
|
async function ensureMikroOrmDurableSchema(orm) {
|
|
341
|
-
await orm.schema.
|
|
389
|
+
await orm.schema.update({
|
|
342
390
|
safe: true
|
|
343
391
|
});
|
|
344
392
|
}
|
|
@@ -554,9 +602,9 @@ var MikroOrmStateStore = class {
|
|
|
554
602
|
* the active naming strategy (underscore vs camelCase) rather than guessing. The run PK column is
|
|
555
603
|
* reused for BOTH the outer correlation and the side-table FK (they share the same fieldName). */
|
|
556
604
|
attributeColumns(em) {
|
|
557
|
-
const meta = em.getMetadata().get(RunAttributeEntity
|
|
558
|
-
const field = /* @__PURE__ */ __name((prop) => meta.
|
|
559
|
-
const runMeta = em.getMetadata().get(WorkflowRunEntity
|
|
605
|
+
const meta = em.getMetadata().get(RunAttributeEntity);
|
|
606
|
+
const field = /* @__PURE__ */ __name((prop) => meta.props.find((p) => p.name === prop)?.fieldNames?.[0] ?? prop, "field");
|
|
607
|
+
const runMeta = em.getMetadata().get(WorkflowRunEntity);
|
|
560
608
|
const runPk = runMeta.properties.id?.fieldNames?.[0] ?? "id";
|
|
561
609
|
return {
|
|
562
610
|
table: meta.tableName,
|
|
@@ -569,7 +617,7 @@ var MikroOrmStateStore = class {
|
|
|
569
617
|
}
|
|
570
618
|
/** Resolve the `tags` column name from metadata (per the active naming strategy), for the raw LIKE. */
|
|
571
619
|
tagsColumn(em) {
|
|
572
|
-
const runMeta = em.getMetadata().get(WorkflowRunEntity
|
|
620
|
+
const runMeta = em.getMetadata().get(WorkflowRunEntity);
|
|
573
621
|
return runMeta.properties.tags?.fieldNames?.[0] ?? "tags";
|
|
574
622
|
}
|
|
575
623
|
/** Wrap a JSON column reference so it can be `LIKE`d as text. Postgres `jsonb`/`json` rejects `LIKE`
|
|
@@ -599,6 +647,35 @@ var MikroOrmStateStore = class {
|
|
|
599
647
|
});
|
|
600
648
|
return rows.map(fromCheckpointEntity);
|
|
601
649
|
}
|
|
650
|
+
async getLatestCheckpointByName(runId, name) {
|
|
651
|
+
const em = this.orm.em.fork();
|
|
652
|
+
const entity = await em.findOne(StepCheckpointEntity, {
|
|
653
|
+
runId,
|
|
654
|
+
name
|
|
655
|
+
}, {
|
|
656
|
+
orderBy: {
|
|
657
|
+
seq: "desc"
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
return entity ? fromCheckpointEntity(entity) : void 0;
|
|
661
|
+
}
|
|
662
|
+
async listCheckpointsByNamePrefix(runId, prefixes) {
|
|
663
|
+
if (prefixes.length === 0) return [];
|
|
664
|
+
const em = this.orm.em.fork();
|
|
665
|
+
const rows = await em.find(StepCheckpointEntity, {
|
|
666
|
+
runId,
|
|
667
|
+
$or: prefixes.map((p) => ({
|
|
668
|
+
name: {
|
|
669
|
+
$like: `${p}%`
|
|
670
|
+
}
|
|
671
|
+
}))
|
|
672
|
+
}, {
|
|
673
|
+
orderBy: {
|
|
674
|
+
seq: "asc"
|
|
675
|
+
}
|
|
676
|
+
});
|
|
677
|
+
return rows.map(fromCheckpointEntity);
|
|
678
|
+
}
|
|
602
679
|
async putSignalWaiter(waiter) {
|
|
603
680
|
const em = this.orm.em.fork();
|
|
604
681
|
await em.upsert(SignalWaiterEntity, {
|
|
@@ -617,7 +694,7 @@ var MikroOrmStateStore = class {
|
|
|
617
694
|
runId: entity.runId,
|
|
618
695
|
seq: entity.seq
|
|
619
696
|
};
|
|
620
|
-
await em.
|
|
697
|
+
await em.remove(entity).flush();
|
|
621
698
|
return waiter;
|
|
622
699
|
}
|
|
623
700
|
async listSignalWaiters(prefix) {
|
|
@@ -652,7 +729,7 @@ var MikroOrmStateStore = class {
|
|
|
652
729
|
});
|
|
653
730
|
if (!entity) return null;
|
|
654
731
|
const payload = entity.payload ?? void 0;
|
|
655
|
-
await em.
|
|
732
|
+
await em.remove(entity).flush();
|
|
656
733
|
return {
|
|
657
734
|
payload
|
|
658
735
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/entities.ts","../src/mikro-orm-state-store.ts","../src/schema.ts"],"sourcesContent":["import type { RunStatus, StepKind } from '@dudousxd/nestjs-durable-core';\nimport { Entity, PrimaryKey, Property } from '@mikro-orm/core';\n\n@Entity({ tableName: 'durable_workflow_runs' })\nexport class WorkflowRunEntity {\n @PrimaryKey()\n id!: string;\n\n @Property()\n workflow!: string;\n\n @Property()\n workflowVersion!: string;\n\n @Property()\n status!: RunStatus;\n\n @Property({ type: 'json', nullable: true })\n input?: unknown;\n\n @Property({ type: 'json', nullable: true })\n output?: unknown;\n\n @Property({ type: 'json', nullable: true })\n error?: unknown;\n\n @Property({ nullable: true })\n wakeAt?: Date;\n\n @Property({ nullable: true })\n lockedBy?: string;\n\n @Property({ nullable: true })\n lockedUntil?: Date;\n\n @Property({ type: 'integer', nullable: true })\n recoveryAttempts?: number;\n\n @Property({ type: 'json', nullable: true })\n tags?: string[] | null;\n\n @Property({ type: 'json', nullable: true })\n searchAttributes?: Record<string, string | number | boolean> | null;\n\n @Property()\n createdAt!: Date;\n\n @Property()\n updatedAt!: Date;\n}\n\n@Entity({ tableName: 'durable_step_checkpoints' })\nexport class StepCheckpointEntity {\n @PrimaryKey()\n runId!: string;\n\n @PrimaryKey()\n seq!: number;\n\n @Property()\n name!: string;\n\n @Property()\n kind!: StepKind;\n\n @Property()\n stepId!: string;\n\n @Property()\n status!: 'pending' | 'running' | 'completed' | 'failed';\n\n @Property({ type: 'json', nullable: true })\n input?: unknown;\n\n @Property({ type: 'json', nullable: true })\n output?: unknown;\n\n @Property({ type: 'json', nullable: true })\n error?: unknown;\n\n @Property({ type: 'json', nullable: true })\n events?: unknown;\n\n @Property()\n attempts!: number;\n\n @Property({ nullable: true })\n workerGroup?: string;\n\n @Property({ nullable: true })\n wakeAt?: Date;\n\n @Property({ nullable: true })\n enqueuedAt?: Date;\n\n @Property()\n startedAt!: Date;\n\n @Property()\n finishedAt!: Date;\n}\n\n/**\n * Normalized side-table for search attributes: one row per (run, key), so range/equality predicates\n * push DOWN into SQL (an EXISTS join indexed on `(key, numValue)` / `(key, strValue)`) instead of a\n * coarse scan + in-process filter. Maintained on every createRun/updateRun. Numbers land in\n * `numValue`, strings/booleans in `strValue` (booleans as \"true\"/\"false\"); see normalizeAttributeRows.\n */\n@Entity({ tableName: 'durable_run_attributes' })\nexport class RunAttributeEntity {\n @PrimaryKey()\n runId!: string;\n\n @PrimaryKey()\n key!: string;\n\n @Property({ type: 'string', nullable: true })\n strValue?: string | null;\n\n // `float`/`double` is portable across SQLite/MySQL/Postgres for numeric range scans.\n @Property({ type: 'float', nullable: true })\n numValue?: number | null;\n}\n\n@Entity({ tableName: 'durable_signal_waiters' })\nexport class SignalWaiterEntity {\n @PrimaryKey()\n token!: string;\n\n @Property()\n runId!: string;\n\n @Property()\n seq!: number;\n}\n\n@Entity({ tableName: 'durable_buffered_signals' })\nexport class BufferedSignalEntity {\n @PrimaryKey({ autoincrement: true })\n id!: number;\n\n @Property({ index: true })\n token!: string;\n\n @Property({ type: 'json', nullable: true })\n payload?: unknown;\n}\n\nexport const ENTITIES = [\n WorkflowRunEntity,\n StepCheckpointEntity,\n RunAttributeEntity,\n SignalWaiterEntity,\n BufferedSignalEntity,\n] as const;\n","import {\n type AttributeFilter,\n type RunQuery,\n type SignalWaiter,\n type StateStore,\n type StepCheckpoint,\n type StepError,\n type StepEvent,\n type WorkflowRun,\n attributeColumnFor,\n attributeOperand,\n normalizeAttributeRows,\n sqlComparator,\n} from '@dudousxd/nestjs-durable-core';\nimport type { EntityManager, MikroORM } from '@mikro-orm/core';\n\n/** Minimal structural surface of the SQL EntityManager's QueryBuilder (from `@mikro-orm/knex`),\n * typed here so the adapter needn't add a hard dependency on the knex types — a real SQL-driver EM\n * satisfies it at runtime. */\ninterface DurableQueryBuilder<T> {\n where(cond: Record<string, unknown>): DurableQueryBuilder<T>;\n andWhere(cond: string): DurableQueryBuilder<T>;\n orderBy(cond: Record<string, unknown>): DurableQueryBuilder<T>;\n limit(n: number): DurableQueryBuilder<T>;\n offset(n: number): DurableQueryBuilder<T>;\n getResultList(): Promise<T[]>;\n}\ntype SqlEm = EntityManager & {\n createQueryBuilder<T>(entity: unknown, alias: string): DurableQueryBuilder<T>;\n};\n\n/** Resolved side-table column names (per the active naming strategy) for the raw EXISTS pushdown. */\ninterface AttributeColumns {\n table: string;\n /** Side-table FK column (the run id on `durable_run_attributes`). */\n runId: string;\n /** Run table PK column (the `id` on `durable_workflow_runs`) used for the outer correlation. */\n runPk: string;\n key: string;\n strValue: string;\n numValue: string;\n}\nimport {\n BufferedSignalEntity,\n RunAttributeEntity,\n SignalWaiterEntity,\n StepCheckpointEntity,\n WorkflowRunEntity,\n} from './entities';\nimport { ensureMikroOrmDurableSchema } from './schema';\n\n/**\n * MikroORM-backed `StateStore`. Works on any MikroORM driver — Postgres, MySQL, SQLite (tested);\n * timestamps and `wakeAt` use native datetime columns. Each operation runs on a forked\n * EntityManager so it owns its unit of work.\n */\nexport class MikroOrmStateStore implements StateStore {\n constructor(private readonly orm: MikroORM) {}\n\n async ensureSchema(): Promise<void> {\n await ensureMikroOrmDurableSchema(this.orm);\n }\n\n async createRun(run: WorkflowRun): Promise<void> {\n const em = this.orm.em.fork();\n em.create(WorkflowRunEntity, toRunEntity(run));\n await em.flush();\n await this.reindexAttributes(run.id, run.searchAttributes);\n }\n\n async updateRun(runId: string, patch: Partial<WorkflowRun>): Promise<void> {\n const em = this.orm.em.fork();\n const entity = await em.findOneOrFail(WorkflowRunEntity, { id: runId });\n Object.assign(entity, toRunEntity({ ...fromRunEntity(entity), ...patch } as WorkflowRun));\n await em.flush();\n // Keep the side-table in step with the run's attributes whenever they're patched.\n if ('searchAttributes' in patch) await this.reindexAttributes(runId, patch.searchAttributes);\n }\n\n /** Rewrite a run's normalized attribute rows: delete the old set, insert the current one. Mirrors\n * the in-memory store's reindex so the side-table always reflects the run's live searchAttributes. */\n private async reindexAttributes(\n runId: string,\n attributes: WorkflowRun['searchAttributes'],\n forked?: EntityManager,\n ): Promise<void> {\n const em = forked ?? this.orm.em.fork();\n await em.nativeDelete(RunAttributeEntity, { runId });\n const rows = normalizeAttributeRows(runId, attributes);\n if (rows.length) await em.insertMany(RunAttributeEntity, rows);\n }\n\n async getRun(runId: string): Promise<WorkflowRun | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(WorkflowRunEntity, { id: runId });\n return entity ? fromRunEntity(entity) : null;\n }\n\n async getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(StepCheckpointEntity, { runId, seq });\n return entity ? fromCheckpointEntity(entity) : null;\n }\n\n async saveCheckpoint(checkpoint: StepCheckpoint): Promise<void> {\n const em = this.orm.em.fork();\n await em.upsert(StepCheckpointEntity, toCheckpointEntity(checkpoint));\n await em.flush();\n }\n\n async transaction<T>(\n work: (tx: {\n raw: unknown;\n saveCheckpoint: (cp: StepCheckpoint) => Promise<void>;\n }) => Promise<T>,\n ): Promise<T> {\n return this.orm.em.fork().transactional(async (em) =>\n work({\n raw: em,\n saveCheckpoint: async (cp) => {\n await em.upsert(StepCheckpointEntity, toCheckpointEntity(cp));\n },\n }),\n );\n }\n\n async listIncompleteRuns(): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(WorkflowRunEntity, { status: 'running' });\n return rows.map(fromRunEntity);\n }\n\n async listPendingRuns(limit: number): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(\n WorkflowRunEntity,\n { status: 'pending' },\n { orderBy: { createdAt: 'asc' }, limit }, // FIFO dispatch\n );\n return rows.map(fromRunEntity);\n }\n\n async listDueTimers(nowMs: number): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(WorkflowRunEntity, {\n status: 'suspended',\n wakeAt: { $ne: null, $lte: new Date(nowMs) },\n });\n return rows.map(fromRunEntity);\n }\n\n async tryLockRun(\n runId: string,\n owner: string,\n leaseUntilMs: number,\n nowMs: number,\n ): Promise<boolean> {\n const em = this.orm.em.fork();\n const affected = await em.nativeUpdate(\n WorkflowRunEntity,\n { id: runId, $or: [{ lockedUntil: null }, { lockedUntil: { $lte: new Date(nowMs) } }] },\n { lockedBy: owner, lockedUntil: new Date(leaseUntilMs) },\n );\n return affected === 1;\n }\n\n async releaseRunLock(runId: string): Promise<void> {\n const em = this.orm.em.fork();\n await em.nativeUpdate(WorkflowRunEntity, { id: runId }, { lockedBy: null, lockedUntil: null });\n }\n\n async renewRunLock(runId: string, owner: string, leaseUntilMs: number): Promise<boolean> {\n const em = this.orm.em.fork();\n const affected = await em.nativeUpdate(\n WorkflowRunEntity,\n { id: runId, lockedBy: owner },\n { lockedUntil: new Date(leaseUntilMs) },\n );\n return affected === 1;\n }\n\n async listRuns(query: RunQuery): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const where: Record<string, unknown> = {};\n if (query.workflow) where.workflow = query.workflow;\n // `status IN (...)`; an empty set matches nothing (mirrors the in-memory store). When both the\n // single `status` and `statuses` are set, AND them so the narrower set wins.\n if (query.status && query.statuses) {\n where.$and = [{ status: query.status }, { status: { $in: query.statuses } }];\n } else if (query.status) {\n where.status = query.status;\n } else if (query.statuses) {\n where.status = { $in: query.statuses };\n }\n const orderBy = { createdAt: 'desc' as const }; // newest first — recent runs on top in the dashboard\n // `tags`/attributes need raw SQL pushed through the QueryBuilder:\n // - tag: `tags` is a JSON column (native json/jsonb on PG/MySQL), and MikroORM JSON-serializes a\n // `{ $like }` operand (wrapping/escaping the LIKE pattern) so a plain where corrupts it to no\n // matches. A raw LIKE on the column-as-text matches the quoted token so `etl` doesn't match\n // `etl-foo`. Postgres `jsonb` rejects `LIKE` directly, so cast to text per dialect.\n // - attributes: each filter becomes a raw EXISTS against the normalized side-table, so the DB\n // filters AND paginates — no full scan + in-process filter (ANDed: one EXISTS per filter).\n // Use a QueryBuilder with a fixed root alias `r` so the raw correlations are stable across drivers.\n if (query.tag || query.attributes?.length) {\n const quote = this.idQuote(em);\n const cols = this.attributeColumns(em);\n const qb = (em as SqlEm)\n .createQueryBuilder<WorkflowRunEntity>(WorkflowRunEntity, 'r')\n .where(where)\n .orderBy(orderBy);\n if (query.tag) {\n const tagsCol = this.tagsColumn(em);\n const pattern = `%\"${query.tag.replace(/'/g, \"''\")}\"%`;\n const colExpr = this.jsonAsText(em, `${quote('r')}.${quote(tagsCol)}`);\n qb.andWhere(`${colExpr} LIKE '${pattern}'`);\n }\n for (const f of query.attributes ?? []) {\n qb.andWhere(this.attributeExistsSql(f, quote, 'r', cols));\n }\n if (query.limit != null) qb.limit(query.limit);\n if (query.offset != null) qb.offset(query.offset);\n const rows = await qb.getResultList();\n return rows.map(fromRunEntity);\n }\n const rows = await em.find(WorkflowRunEntity, where, {\n ...(query.limit != null ? { limit: query.limit } : {}),\n ...(query.offset != null ? { offset: query.offset } : {}),\n orderBy,\n });\n return rows.map(fromRunEntity);\n }\n\n /** One attribute predicate as a raw EXISTS subquery on the side-table, correlated to the outer run\n * alias. `<>` (ne) also excludes runs where the attribute is absent (missing-key-never-matches):\n * EXISTS already requires a present row, so EXISTS(... <> ...) is exactly ne-with-present. Numeric\n * operands compare the num column, everything else the str column. Identifiers are quoted per\n * driver and operands are inlined as literals (string operands are escaped by doubling quotes). */\n private attributeExistsSql(\n f: AttributeFilter,\n quote: (id: string) => string,\n alias: string,\n cols: AttributeColumns,\n ): string {\n const col = attributeColumnFor(f) === 'numValue' ? cols.numValue : cols.strValue;\n const cmp = sqlComparator(f.op);\n const operand = attributeOperand(f);\n const literal =\n typeof operand === 'number' ? String(operand) : `'${String(operand).replace(/'/g, \"''\")}'`;\n const a = quote(cols.table);\n const sub = quote('a');\n const outerId = `${quote(alias)}.${quote(cols.runPk)}`; // run PK column on the outer alias\n return `EXISTS (SELECT 1 FROM ${a} ${sub} WHERE ${sub}.${quote(cols.runId)} = ${outerId} AND ${sub}.${quote(cols.key)} = '${f.key.replace(/'/g, \"''\")}' AND ${sub}.${quote(col)} ${cmp} ${literal})`;\n }\n\n /** Resolve the side-table's actual column names from MikroORM metadata, so the raw EXISTS matches\n * the active naming strategy (underscore vs camelCase) rather than guessing. The run PK column is\n * reused for BOTH the outer correlation and the side-table FK (they share the same fieldName). */\n private attributeColumns(em: EntityManager): AttributeColumns {\n const meta = em.getMetadata().get(RunAttributeEntity.name);\n const field = (prop: string) => meta.properties[prop]?.fieldNames?.[0] ?? prop;\n const runMeta = em.getMetadata().get(WorkflowRunEntity.name);\n const runPk = runMeta.properties.id?.fieldNames?.[0] ?? 'id';\n return {\n table: meta.tableName,\n runId: field('runId'),\n runPk,\n key: field('key'),\n strValue: field('strValue'),\n numValue: field('numValue'),\n };\n }\n\n /** Resolve the `tags` column name from metadata (per the active naming strategy), for the raw LIKE. */\n private tagsColumn(em: EntityManager): string {\n const runMeta = em.getMetadata().get(WorkflowRunEntity.name);\n return runMeta.properties.tags?.fieldNames?.[0] ?? 'tags';\n }\n\n /** Wrap a JSON column reference so it can be `LIKE`d as text. Postgres `jsonb`/`json` rejects `LIKE`\n * directly (`operator does not exist: jsonb ~~ unknown`) — cast to `text`; MySQL JSON needs an\n * explicit `CHAR` cast; SQLite stores JSON as text already, so no cast. */\n private jsonAsText(em: EntityManager, colRef: string): string {\n const platform = String(em.getPlatform().constructor.name).toLowerCase();\n if (platform.includes('postgre')) return `${colRef}::text`;\n if (platform.includes('mysql') || platform.includes('mariadb'))\n return `CAST(${colRef} AS CHAR)`;\n return colRef;\n }\n\n /** Quote an identifier per the active SQL driver (MySQL/MariaDB backtick, others double-quote). */\n private idQuote(em: EntityManager): (id: string) => string {\n const platform = String(em.getPlatform().constructor.name).toLowerCase();\n const isMysql = platform.includes('mysql') || platform.includes('mariadb');\n const ch = isMysql ? '`' : '\"';\n return (id: string) => `${ch}${id}${ch}`;\n }\n\n async listCheckpoints(runId: string): Promise<StepCheckpoint[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(StepCheckpointEntity, { runId }, { orderBy: { seq: 'asc' } });\n return rows.map(fromCheckpointEntity);\n }\n\n async putSignalWaiter(waiter: SignalWaiter): Promise<void> {\n const em = this.orm.em.fork();\n await em.upsert(SignalWaiterEntity, { ...waiter });\n await em.flush();\n }\n\n async takeSignalWaiter(token: string): Promise<SignalWaiter | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(SignalWaiterEntity, { token });\n if (!entity) return null;\n const waiter: SignalWaiter = { token: entity.token, runId: entity.runId, seq: entity.seq };\n await em.removeAndFlush(entity);\n return waiter;\n }\n\n async listSignalWaiters(prefix: string): Promise<SignalWaiter[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(SignalWaiterEntity, { token: { $like: `${prefix}%` } });\n return rows.map((e) => ({ token: e.token, runId: e.runId, seq: e.seq }));\n }\n\n async bufferSignal(token: string, payload: unknown): Promise<void> {\n const em = this.orm.em.fork();\n const e = new BufferedSignalEntity();\n e.token = token;\n e.payload = payload ?? null;\n em.persist(e);\n await em.flush();\n }\n\n async takeBufferedSignal(token: string): Promise<{ payload: unknown } | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(BufferedSignalEntity, { token }, { orderBy: { id: 'asc' } });\n if (!entity) return null;\n const payload = entity.payload ?? undefined;\n await em.removeAndFlush(entity);\n return { payload };\n }\n}\n\nfunction toRunEntity(run: WorkflowRun): WorkflowRunEntity {\n const e = new WorkflowRunEntity();\n e.id = run.id;\n e.workflow = run.workflow;\n e.workflowVersion = run.workflowVersion;\n e.status = run.status;\n e.input = run.input ?? null;\n e.output = run.output ?? null;\n e.error = run.error ?? null;\n if (run.wakeAt != null) e.wakeAt = new Date(run.wakeAt);\n if (run.lockedBy !== undefined) e.lockedBy = run.lockedBy;\n if (run.lockedUntil != null) e.lockedUntil = new Date(run.lockedUntil);\n if (run.recoveryAttempts !== undefined) e.recoveryAttempts = run.recoveryAttempts;\n e.tags = run.tags ?? null;\n e.searchAttributes = run.searchAttributes ?? null;\n e.createdAt = run.createdAt;\n e.updatedAt = run.updatedAt;\n return e;\n}\n\nfunction fromRunEntity(e: WorkflowRunEntity): WorkflowRun {\n return {\n id: e.id,\n workflow: e.workflow,\n workflowVersion: e.workflowVersion,\n status: e.status,\n input: e.input ?? undefined,\n output: e.output ?? undefined,\n error: (e.error ?? undefined) as StepError | undefined,\n wakeAt: e.wakeAt?.getTime(),\n lockedBy: e.lockedBy ?? undefined,\n lockedUntil: e.lockedUntil?.getTime(),\n recoveryAttempts: e.recoveryAttempts ?? undefined,\n tags: e.tags ?? undefined,\n searchAttributes: e.searchAttributes ?? undefined,\n createdAt: e.createdAt,\n updatedAt: e.updatedAt,\n };\n}\n\nfunction toCheckpointEntity(cp: StepCheckpoint): StepCheckpointEntity {\n const e = new StepCheckpointEntity();\n e.runId = cp.runId;\n e.seq = cp.seq;\n e.name = cp.name;\n e.kind = cp.kind;\n e.stepId = cp.stepId;\n e.status = cp.status;\n e.input = cp.input ?? null;\n e.output = cp.output ?? null;\n e.error = cp.error ?? null;\n e.events = cp.events ?? null;\n e.attempts = cp.attempts;\n if (cp.workerGroup !== undefined) e.workerGroup = cp.workerGroup;\n if (cp.wakeAt != null) e.wakeAt = new Date(cp.wakeAt);\n e.enqueuedAt = cp.enqueuedAt;\n e.startedAt = cp.startedAt;\n e.finishedAt = cp.finishedAt;\n return e;\n}\n\nfunction fromCheckpointEntity(e: StepCheckpointEntity): StepCheckpoint {\n return {\n runId: e.runId,\n seq: e.seq,\n name: e.name,\n kind: e.kind,\n stepId: e.stepId,\n status: e.status,\n input: e.input ?? undefined,\n output: e.output ?? undefined,\n error: (e.error ?? undefined) as StepError | undefined,\n events: (e.events ?? undefined) as StepEvent[] | undefined,\n attempts: e.attempts,\n workerGroup: e.workerGroup ?? undefined,\n wakeAt: e.wakeAt?.getTime(),\n enqueuedAt: e.enqueuedAt ?? e.startedAt,\n startedAt: e.startedAt,\n finishedAt: e.finishedAt,\n };\n}\n","import type { MikroORM } from '@mikro-orm/core';\n\n/**\n * Idempotently create/extend the durable tables (additive, never drops). Safe to run on every\n * boot (auto-schema) and the function to call from a MikroORM migration when you disable\n * auto-schema:\n *\n * ```ts\n * export class AddDurableTables extends Migration {\n * async up() { await ensureMikroOrmDurableSchema(this.getEntityManager().getOrm()); }\n * }\n * ```\n */\nexport async function ensureMikroOrmDurableSchema(orm: MikroORM): Promise<void> {\n await orm.schema.updateSchema({ safe: true });\n}\n"],"mappings":";;;;AACA,SAASA,QAAQC,YAAYC,gBAAgB;;;;;;;;;;;;AAGtC,IAAMC,oBAAN,MAAMA;SAAAA;;;EAEXC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;EAGAC;E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EQ,SAASF;IAClBG,QAAQT,EAAES,UAAUH;IACpBI,OAAQV,EAAEU,SAASJ;IACnBU,QAAShB,EAAEgB,UAAUV;IACrBW,UAAUjB,EAAEiB;IACZC,aAAalB,EAAEkB,eAAeZ;IAC9B3F,QAAQqF,EAAErF,QAAQkG,QAAAA;IAClBM,YAAYnB,EAAEmB,cAAcnB,EAAEoB;IAC9BA,WAAWpB,EAAEoB;IACbC,YAAYrB,EAAEqB;EAChB;AACF;AAnBS9H;","names":["Entity","PrimaryKey","Property","WorkflowRunEntity","id","workflow","workflowVersion","status","input","output","error","wakeAt","lockedBy","lockedUntil","recoveryAttempts","tags","searchAttributes","createdAt","updatedAt","type","nullable","tableName","StepCheckpointEntity","runId","seq","name","kind","stepId","events","attempts","workerGroup","enqueuedAt","startedAt","finishedAt","RunAttributeEntity","key","strValue","numValue","SignalWaiterEntity","token","BufferedSignalEntity","payload","autoincrement","index","ENTITIES","attributeColumnFor","attributeOperand","normalizeAttributeRows","sqlComparator","ensureMikroOrmDurableSchema","orm","schema","updateSchema","safe","MikroOrmStateStore","orm","ensureSchema","ensureMikroOrmDurableSchema","createRun","run","em","fork","create","WorkflowRunEntity","toRunEntity","flush","reindexAttributes","id","searchAttributes","updateRun","runId","patch","entity","findOneOrFail","Object","assign","fromRunEntity","attributes","forked","nativeDelete","RunAttributeEntity","rows","normalizeAttributeRows","length","insertMany","getRun","findOne","getCheckpoint","seq","StepCheckpointEntity","fromCheckpointEntity","saveCheckpoint","checkpoint","upsert","toCheckpointEntity","transaction","work","transactional","raw","cp","listIncompleteRuns","find","status","map","listPendingRuns","limit","orderBy","createdAt","listDueTimers","nowMs","wakeAt","$ne","$lte","Date","tryLockRun","owner","leaseUntilMs","affected","nativeUpdate","$or","lockedUntil","lockedBy","releaseRunLock","renewRunLock","listRuns","query","where","workflow","statuses","$and","$in","tag","quote","idQuote","cols","attributeColumns","qb","createQueryBuilder","tagsCol","tagsColumn","pattern","replace","colExpr","jsonAsText","andWhere","f","attributeExistsSql","offset","getResultList","alias","col","attributeColumnFor","numValue","strValue","cmp","sqlComparator","op","operand","attributeOperand","literal","String","a","table","sub","outerId","runPk","key","meta","getMetadata","get","name","field","prop","properties","fieldNames","runMeta","tableName","tags","colRef","platform","getPlatform","toLowerCase","includes","isMysql","ch","listCheckpoints","putSignalWaiter","waiter","SignalWaiterEntity","takeSignalWaiter","token","removeAndFlush","listSignalWaiters","prefix","$like","e","bufferSignal","payload","BufferedSignalEntity","persist","takeBufferedSignal","undefined","workflowVersion","input","output","error","recoveryAttempts","updatedAt","getTime","kind","stepId","events","attempts","workerGroup","enqueuedAt","startedAt","finishedAt"]}
|
|
1
|
+
{"version":3,"sources":["../src/entities.ts","../src/mikro-orm-state-store.ts","../src/schema.ts"],"sourcesContent":["import type { RunStatus, StepKind } from '@dudousxd/nestjs-durable-core';\nimport { Entity, PrimaryKey, Property } from '@mikro-orm/decorators/legacy';\n\n@Entity({ tableName: 'durable_workflow_runs' })\nexport class WorkflowRunEntity {\n @PrimaryKey({ type: 'string' })\n id!: string;\n\n @Property({ type: 'string' })\n workflow!: string;\n\n @Property({ type: 'string' })\n workflowVersion!: string;\n\n @Property({ type: 'string' })\n status!: RunStatus;\n\n @Property({ type: 'json', nullable: true })\n input?: unknown;\n\n @Property({ type: 'json', nullable: true })\n output?: unknown;\n\n @Property({ type: 'json', nullable: true })\n error?: unknown;\n\n @Property({ type: 'Date', nullable: true })\n wakeAt?: Date;\n\n @Property({ type: 'string', nullable: true })\n lockedBy?: string;\n\n @Property({ type: 'Date', nullable: true })\n lockedUntil?: Date;\n\n @Property({ type: 'integer', nullable: true })\n recoveryAttempts?: number;\n\n @Property({ type: 'json', nullable: true })\n tags?: string[] | null;\n\n @Property({ type: 'json', nullable: true })\n searchAttributes?: Record<string, string | number | boolean> | null;\n\n @Property({ type: 'Date' })\n createdAt!: Date;\n\n @Property({ type: 'Date' })\n updatedAt!: Date;\n}\n\n@Entity({ tableName: 'durable_step_checkpoints' })\nexport class StepCheckpointEntity {\n @PrimaryKey({ type: 'string' })\n runId!: string;\n\n @PrimaryKey({ type: 'integer' })\n seq!: number;\n\n @Property({ type: 'string' })\n name!: string;\n\n @Property({ type: 'string' })\n kind!: StepKind;\n\n @Property({ type: 'string' })\n stepId!: string;\n\n @Property({ type: 'string' })\n status!: 'pending' | 'running' | 'completed' | 'failed';\n\n @Property({ type: 'json', nullable: true })\n input?: unknown;\n\n @Property({ type: 'json', nullable: true })\n output?: unknown;\n\n @Property({ type: 'json', nullable: true })\n error?: unknown;\n\n @Property({ type: 'json', nullable: true })\n events?: unknown;\n\n @Property({ type: 'integer' })\n attempts!: number;\n\n @Property({ type: 'string', nullable: true })\n workerGroup?: string;\n\n @Property({ type: 'Date', nullable: true })\n wakeAt?: Date;\n\n @Property({ type: 'Date', nullable: true })\n enqueuedAt?: Date;\n\n @Property({ type: 'Date' })\n startedAt!: Date;\n\n @Property({ type: 'Date' })\n finishedAt!: Date;\n}\n\n/**\n * Normalized side-table for search attributes: one row per (run, key), so range/equality predicates\n * push DOWN into SQL (an EXISTS join indexed on `(key, numValue)` / `(key, strValue)`) instead of a\n * coarse scan + in-process filter. Maintained on every createRun/updateRun. Numbers land in\n * `numValue`, strings/booleans in `strValue` (booleans as \"true\"/\"false\"); see normalizeAttributeRows.\n */\n@Entity({ tableName: 'durable_run_attributes' })\nexport class RunAttributeEntity {\n @PrimaryKey({ type: 'string' })\n runId!: string;\n\n @PrimaryKey({ type: 'string' })\n key!: string;\n\n @Property({ type: 'string', nullable: true })\n strValue?: string | null;\n\n // `float`/`double` is portable across SQLite/MySQL/Postgres for numeric range scans.\n @Property({ type: 'float', nullable: true })\n numValue?: number | null;\n}\n\n@Entity({ tableName: 'durable_signal_waiters' })\nexport class SignalWaiterEntity {\n @PrimaryKey({ type: 'string' })\n token!: string;\n\n @Property({ type: 'string' })\n runId!: string;\n\n @Property({ type: 'integer' })\n seq!: number;\n}\n\n@Entity({ tableName: 'durable_buffered_signals' })\nexport class BufferedSignalEntity {\n @PrimaryKey({ autoincrement: true, type: 'integer' })\n id!: number;\n\n @Property({ index: true, type: 'string' })\n token!: string;\n\n @Property({ type: 'json', nullable: true })\n payload?: unknown;\n}\n\nexport const ENTITIES = [\n WorkflowRunEntity,\n StepCheckpointEntity,\n RunAttributeEntity,\n SignalWaiterEntity,\n BufferedSignalEntity,\n] as const;\n","import {\n type AttributeFilter,\n type RunQuery,\n type SignalWaiter,\n type StateStore,\n type StepCheckpoint,\n type StepError,\n type StepEvent,\n type WorkflowRun,\n attributeColumnFor,\n attributeOperand,\n normalizeAttributeRows,\n sqlComparator,\n} from '@dudousxd/nestjs-durable-core';\nimport type { EntityManager, MikroORM } from '@mikro-orm/core';\n\n/** Minimal structural surface of the SQL EntityManager's QueryBuilder (from `@mikro-orm/knex`),\n * typed here so the adapter needn't add a hard dependency on the knex types — a real SQL-driver EM\n * satisfies it at runtime. */\ninterface DurableQueryBuilder<T> {\n where(cond: Record<string, unknown>): DurableQueryBuilder<T>;\n andWhere(cond: string): DurableQueryBuilder<T>;\n orderBy(cond: Record<string, unknown>): DurableQueryBuilder<T>;\n limit(n: number): DurableQueryBuilder<T>;\n offset(n: number): DurableQueryBuilder<T>;\n getResultList(): Promise<T[]>;\n}\ntype SqlEm = EntityManager & {\n createQueryBuilder<T>(entity: unknown, alias: string): DurableQueryBuilder<T>;\n};\n\n/** Resolved side-table column names (per the active naming strategy) for the raw EXISTS pushdown. */\ninterface AttributeColumns {\n table: string;\n /** Side-table FK column (the run id on `durable_run_attributes`). */\n runId: string;\n /** Run table PK column (the `id` on `durable_workflow_runs`) used for the outer correlation. */\n runPk: string;\n key: string;\n strValue: string;\n numValue: string;\n}\nimport {\n BufferedSignalEntity,\n RunAttributeEntity,\n SignalWaiterEntity,\n StepCheckpointEntity,\n WorkflowRunEntity,\n} from './entities';\nimport { ensureMikroOrmDurableSchema } from './schema';\n\n/**\n * MikroORM-backed `StateStore`. Works on any MikroORM driver — Postgres, MySQL, SQLite (tested);\n * timestamps and `wakeAt` use native datetime columns. Each operation runs on a forked\n * EntityManager so it owns its unit of work.\n */\nexport class MikroOrmStateStore implements StateStore {\n constructor(private readonly orm: MikroORM) {}\n\n async ensureSchema(): Promise<void> {\n await ensureMikroOrmDurableSchema(this.orm);\n }\n\n async createRun(run: WorkflowRun): Promise<void> {\n const em = this.orm.em.fork();\n em.create(WorkflowRunEntity, toRunEntity(run));\n await em.flush();\n await this.reindexAttributes(run.id, run.searchAttributes);\n }\n\n async updateRun(runId: string, patch: Partial<WorkflowRun>): Promise<void> {\n const em = this.orm.em.fork();\n const entity = await em.findOneOrFail(WorkflowRunEntity, { id: runId });\n Object.assign(entity, toRunEntity({ ...fromRunEntity(entity), ...patch } as WorkflowRun));\n await em.flush();\n // Keep the side-table in step with the run's attributes whenever they're patched.\n if ('searchAttributes' in patch) await this.reindexAttributes(runId, patch.searchAttributes);\n }\n\n /** Rewrite a run's normalized attribute rows: delete the old set, insert the current one. Mirrors\n * the in-memory store's reindex so the side-table always reflects the run's live searchAttributes. */\n private async reindexAttributes(\n runId: string,\n attributes: WorkflowRun['searchAttributes'],\n forked?: EntityManager,\n ): Promise<void> {\n const em = forked ?? this.orm.em.fork();\n await em.nativeDelete(RunAttributeEntity, { runId });\n const rows = normalizeAttributeRows(runId, attributes);\n if (rows.length) await em.insertMany(RunAttributeEntity, rows);\n }\n\n async getRun(runId: string): Promise<WorkflowRun | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(WorkflowRunEntity, { id: runId });\n return entity ? fromRunEntity(entity) : null;\n }\n\n async getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(StepCheckpointEntity, { runId, seq });\n return entity ? fromCheckpointEntity(entity) : null;\n }\n\n async saveCheckpoint(checkpoint: StepCheckpoint): Promise<void> {\n const em = this.orm.em.fork();\n await em.upsert(StepCheckpointEntity, toCheckpointEntity(checkpoint));\n await em.flush();\n }\n\n async transaction<T>(\n work: (tx: {\n raw: unknown;\n saveCheckpoint: (cp: StepCheckpoint) => Promise<void>;\n }) => Promise<T>,\n ): Promise<T> {\n return this.orm.em.fork().transactional(async (em) =>\n work({\n raw: em,\n saveCheckpoint: async (cp) => {\n await em.upsert(StepCheckpointEntity, toCheckpointEntity(cp));\n },\n }),\n );\n }\n\n async listIncompleteRuns(): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(WorkflowRunEntity, { status: 'running' });\n return rows.map(fromRunEntity);\n }\n\n async listPendingRuns(limit: number): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(\n WorkflowRunEntity,\n { status: 'pending' },\n { orderBy: { createdAt: 'asc' }, limit }, // FIFO dispatch\n );\n return rows.map(fromRunEntity);\n }\n\n async listDueTimers(nowMs: number): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(WorkflowRunEntity, {\n status: 'suspended',\n wakeAt: { $ne: null, $lte: new Date(nowMs) },\n });\n return rows.map(fromRunEntity);\n }\n\n async tryLockRun(\n runId: string,\n owner: string,\n leaseUntilMs: number,\n nowMs: number,\n ): Promise<boolean> {\n const em = this.orm.em.fork();\n const affected = await em.nativeUpdate(\n WorkflowRunEntity,\n { id: runId, $or: [{ lockedUntil: null }, { lockedUntil: { $lte: new Date(nowMs) } }] },\n { lockedBy: owner, lockedUntil: new Date(leaseUntilMs) },\n );\n return affected === 1;\n }\n\n async releaseRunLock(runId: string): Promise<void> {\n const em = this.orm.em.fork();\n await em.nativeUpdate(WorkflowRunEntity, { id: runId }, { lockedBy: null, lockedUntil: null });\n }\n\n async renewRunLock(runId: string, owner: string, leaseUntilMs: number): Promise<boolean> {\n const em = this.orm.em.fork();\n const affected = await em.nativeUpdate(\n WorkflowRunEntity,\n { id: runId, lockedBy: owner },\n { lockedUntil: new Date(leaseUntilMs) },\n );\n return affected === 1;\n }\n\n async listRuns(query: RunQuery): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const where: Record<string, unknown> = {};\n if (query.workflow) where.workflow = query.workflow;\n // `status IN (...)`; an empty set matches nothing (mirrors the in-memory store). When both the\n // single `status` and `statuses` are set, AND them so the narrower set wins.\n if (query.status && query.statuses) {\n where.$and = [{ status: query.status }, { status: { $in: query.statuses } }];\n } else if (query.status) {\n where.status = query.status;\n } else if (query.statuses) {\n where.status = { $in: query.statuses };\n }\n const orderBy = { createdAt: 'desc' as const }; // newest first — recent runs on top in the dashboard\n // `tags`/attributes need raw SQL pushed through the QueryBuilder:\n // - tag: `tags` is a JSON column (native json/jsonb on PG/MySQL), and MikroORM JSON-serializes a\n // `{ $like }` operand (wrapping/escaping the LIKE pattern) so a plain where corrupts it to no\n // matches. A raw LIKE on the column-as-text matches the quoted token so `etl` doesn't match\n // `etl-foo`. Postgres `jsonb` rejects `LIKE` directly, so cast to text per dialect.\n // - attributes: each filter becomes a raw EXISTS against the normalized side-table, so the DB\n // filters AND paginates — no full scan + in-process filter (ANDed: one EXISTS per filter).\n // Use a QueryBuilder with a fixed root alias `r` so the raw correlations are stable across drivers.\n if (query.tag || query.attributes?.length) {\n const quote = this.idQuote(em);\n const cols = this.attributeColumns(em);\n const qb = (em as SqlEm)\n .createQueryBuilder<WorkflowRunEntity>(WorkflowRunEntity, 'r')\n .where(where)\n .orderBy(orderBy);\n if (query.tag) {\n const tagsCol = this.tagsColumn(em);\n const pattern = `%\"${query.tag.replace(/'/g, \"''\")}\"%`;\n const colExpr = this.jsonAsText(em, `${quote('r')}.${quote(tagsCol)}`);\n qb.andWhere(`${colExpr} LIKE '${pattern}'`);\n }\n for (const f of query.attributes ?? []) {\n qb.andWhere(this.attributeExistsSql(f, quote, 'r', cols));\n }\n if (query.limit != null) qb.limit(query.limit);\n if (query.offset != null) qb.offset(query.offset);\n const rows = await qb.getResultList();\n return rows.map(fromRunEntity);\n }\n const rows = await em.find(WorkflowRunEntity, where, {\n ...(query.limit != null ? { limit: query.limit } : {}),\n ...(query.offset != null ? { offset: query.offset } : {}),\n orderBy,\n });\n return rows.map(fromRunEntity);\n }\n\n /** One attribute predicate as a raw EXISTS subquery on the side-table, correlated to the outer run\n * alias. `<>` (ne) also excludes runs where the attribute is absent (missing-key-never-matches):\n * EXISTS already requires a present row, so EXISTS(... <> ...) is exactly ne-with-present. Numeric\n * operands compare the num column, everything else the str column. Identifiers are quoted per\n * driver and operands are inlined as literals (string operands are escaped by doubling quotes). */\n private attributeExistsSql(\n f: AttributeFilter,\n quote: (id: string) => string,\n alias: string,\n cols: AttributeColumns,\n ): string {\n const col = attributeColumnFor(f) === 'numValue' ? cols.numValue : cols.strValue;\n const cmp = sqlComparator(f.op);\n const operand = attributeOperand(f);\n const literal =\n typeof operand === 'number' ? String(operand) : `'${String(operand).replace(/'/g, \"''\")}'`;\n const a = quote(cols.table);\n const sub = quote('a');\n const outerId = `${quote(alias)}.${quote(cols.runPk)}`; // run PK column on the outer alias\n return `EXISTS (SELECT 1 FROM ${a} ${sub} WHERE ${sub}.${quote(cols.runId)} = ${outerId} AND ${sub}.${quote(cols.key)} = '${f.key.replace(/'/g, \"''\")}' AND ${sub}.${quote(col)} ${cmp} ${literal})`;\n }\n\n /** Resolve the side-table's actual column names from MikroORM metadata, so the raw EXISTS matches\n * the active naming strategy (underscore vs camelCase) rather than guessing. The run PK column is\n * reused for BOTH the outer correlation and the side-table FK (they share the same fieldName). */\n private attributeColumns(em: EntityManager): AttributeColumns {\n const meta = em.getMetadata().get(RunAttributeEntity);\n const field = (prop: string) =>\n meta.props.find((p) => p.name === prop)?.fieldNames?.[0] ?? prop;\n const runMeta = em.getMetadata().get(WorkflowRunEntity);\n const runPk = runMeta.properties.id?.fieldNames?.[0] ?? 'id';\n return {\n table: meta.tableName,\n runId: field('runId'),\n runPk,\n key: field('key'),\n strValue: field('strValue'),\n numValue: field('numValue'),\n };\n }\n\n /** Resolve the `tags` column name from metadata (per the active naming strategy), for the raw LIKE. */\n private tagsColumn(em: EntityManager): string {\n const runMeta = em.getMetadata().get(WorkflowRunEntity);\n return runMeta.properties.tags?.fieldNames?.[0] ?? 'tags';\n }\n\n /** Wrap a JSON column reference so it can be `LIKE`d as text. Postgres `jsonb`/`json` rejects `LIKE`\n * directly (`operator does not exist: jsonb ~~ unknown`) — cast to `text`; MySQL JSON needs an\n * explicit `CHAR` cast; SQLite stores JSON as text already, so no cast. */\n private jsonAsText(em: EntityManager, colRef: string): string {\n const platform = String(em.getPlatform().constructor.name).toLowerCase();\n if (platform.includes('postgre')) return `${colRef}::text`;\n if (platform.includes('mysql') || platform.includes('mariadb'))\n return `CAST(${colRef} AS CHAR)`;\n return colRef;\n }\n\n /** Quote an identifier per the active SQL driver (MySQL/MariaDB backtick, others double-quote). */\n private idQuote(em: EntityManager): (id: string) => string {\n const platform = String(em.getPlatform().constructor.name).toLowerCase();\n const isMysql = platform.includes('mysql') || platform.includes('mariadb');\n const ch = isMysql ? '`' : '\"';\n return (id: string) => `${ch}${id}${ch}`;\n }\n\n async listCheckpoints(runId: string): Promise<StepCheckpoint[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(StepCheckpointEntity, { runId }, { orderBy: { seq: 'asc' } });\n return rows.map(fromCheckpointEntity);\n }\n\n async getLatestCheckpointByName(\n runId: string,\n name: string,\n ): Promise<StepCheckpoint | undefined> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(\n StepCheckpointEntity,\n { runId, name },\n { orderBy: { seq: 'desc' } },\n );\n return entity ? fromCheckpointEntity(entity) : undefined;\n }\n\n async listCheckpointsByNamePrefix(runId: string, prefixes: string[]): Promise<StepCheckpoint[]> {\n if (prefixes.length === 0) return [];\n const em = this.orm.em.fork();\n const rows = await em.find(\n StepCheckpointEntity,\n { runId, $or: prefixes.map((p) => ({ name: { $like: `${p}%` } })) },\n { orderBy: { seq: 'asc' } },\n );\n return rows.map(fromCheckpointEntity);\n }\n\n async putSignalWaiter(waiter: SignalWaiter): Promise<void> {\n const em = this.orm.em.fork();\n await em.upsert(SignalWaiterEntity, { ...waiter });\n await em.flush();\n }\n\n async takeSignalWaiter(token: string): Promise<SignalWaiter | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(SignalWaiterEntity, { token });\n if (!entity) return null;\n const waiter: SignalWaiter = { token: entity.token, runId: entity.runId, seq: entity.seq };\n await em.remove(entity).flush();\n return waiter;\n }\n\n async listSignalWaiters(prefix: string): Promise<SignalWaiter[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(SignalWaiterEntity, { token: { $like: `${prefix}%` } });\n return rows.map((e) => ({ token: e.token, runId: e.runId, seq: e.seq }));\n }\n\n async bufferSignal(token: string, payload: unknown): Promise<void> {\n const em = this.orm.em.fork();\n const e = new BufferedSignalEntity();\n e.token = token;\n e.payload = payload ?? null;\n em.persist(e);\n await em.flush();\n }\n\n async takeBufferedSignal(token: string): Promise<{ payload: unknown } | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(BufferedSignalEntity, { token }, { orderBy: { id: 'asc' } });\n if (!entity) return null;\n const payload = entity.payload ?? undefined;\n await em.remove(entity).flush();\n return { payload };\n }\n}\n\nfunction toRunEntity(run: WorkflowRun): WorkflowRunEntity {\n const e = new WorkflowRunEntity();\n e.id = run.id;\n e.workflow = run.workflow;\n e.workflowVersion = run.workflowVersion;\n e.status = run.status;\n e.input = run.input ?? null;\n e.output = run.output ?? null;\n e.error = run.error ?? null;\n if (run.wakeAt != null) e.wakeAt = new Date(run.wakeAt);\n if (run.lockedBy !== undefined) e.lockedBy = run.lockedBy;\n if (run.lockedUntil != null) e.lockedUntil = new Date(run.lockedUntil);\n if (run.recoveryAttempts !== undefined) e.recoveryAttempts = run.recoveryAttempts;\n e.tags = run.tags ?? null;\n e.searchAttributes = run.searchAttributes ?? null;\n e.createdAt = run.createdAt;\n e.updatedAt = run.updatedAt;\n return e;\n}\n\nfunction fromRunEntity(e: WorkflowRunEntity): WorkflowRun {\n return {\n id: e.id,\n workflow: e.workflow,\n workflowVersion: e.workflowVersion,\n status: e.status,\n input: e.input ?? undefined,\n output: e.output ?? undefined,\n error: (e.error ?? undefined) as StepError | undefined,\n wakeAt: e.wakeAt?.getTime(),\n lockedBy: e.lockedBy ?? undefined,\n lockedUntil: e.lockedUntil?.getTime(),\n recoveryAttempts: e.recoveryAttempts ?? undefined,\n tags: e.tags ?? undefined,\n searchAttributes: e.searchAttributes ?? undefined,\n createdAt: e.createdAt,\n updatedAt: e.updatedAt,\n };\n}\n\nfunction toCheckpointEntity(cp: StepCheckpoint): StepCheckpointEntity {\n const e = new StepCheckpointEntity();\n e.runId = cp.runId;\n e.seq = cp.seq;\n e.name = cp.name;\n e.kind = cp.kind;\n e.stepId = cp.stepId;\n e.status = cp.status;\n e.input = cp.input ?? null;\n e.output = cp.output ?? null;\n e.error = cp.error ?? null;\n e.events = cp.events ?? null;\n e.attempts = cp.attempts;\n if (cp.workerGroup !== undefined) e.workerGroup = cp.workerGroup;\n if (cp.wakeAt != null) e.wakeAt = new Date(cp.wakeAt);\n e.enqueuedAt = cp.enqueuedAt;\n e.startedAt = cp.startedAt;\n e.finishedAt = cp.finishedAt;\n return e;\n}\n\nfunction fromCheckpointEntity(e: StepCheckpointEntity): StepCheckpoint {\n return {\n runId: e.runId,\n seq: e.seq,\n name: e.name,\n kind: e.kind,\n stepId: e.stepId,\n status: e.status,\n input: e.input ?? undefined,\n output: e.output ?? undefined,\n error: (e.error ?? undefined) as StepError | undefined,\n events: (e.events ?? undefined) as StepEvent[] | undefined,\n attempts: e.attempts,\n workerGroup: e.workerGroup ?? undefined,\n wakeAt: e.wakeAt?.getTime(),\n enqueuedAt: e.enqueuedAt ?? e.startedAt,\n startedAt: e.startedAt,\n finishedAt: e.finishedAt,\n };\n}\n","import type { MikroORM } from '@mikro-orm/core';\n\n/**\n * Idempotently create/extend the durable tables (additive, never drops). Safe to run on every\n * boot (auto-schema) and the function to call from a MikroORM migration when you disable\n * auto-schema:\n *\n * ```ts\n * export class AddDurableTables extends Migration {\n * async up() { await ensureMikroOrmDurableSchema(this.getEntityManager().getOrm()); }\n * }\n * ```\n */\nex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,SAAO;IACLnI,OAAOmI,EAAEnI;IACTkB,KAAKiH,EAAEjH;IACPsF,MAAM2B,EAAE3B;IACRwC,MAAMb,EAAEa;IACRC,QAAQd,EAAEc;IACVjH,QAAQmG,EAAEnG;IACV0G,OAAOP,EAAEO,SAASnB;IAClBoB,QAAQR,EAAEQ,UAAUpB;IACpBqB,OAAQT,EAAES,SAASrB;IACnB2B,QAASf,EAAEe,UAAU3B;IACrB4B,UAAUhB,EAAEgB;IACZC,aAAajB,EAAEiB,eAAe7B;IAC9B/E,QAAQ2F,EAAE3F,QAAQuG,QAAAA;IAClBM,YAAYlB,EAAEkB,cAAclB,EAAEmB;IAC9BA,WAAWnB,EAAEmB;IACbC,YAAYpB,EAAEoB;EAChB;AACF;AAnBSnI;","names":["Entity","PrimaryKey","Property","WorkflowRunEntity","id","workflow","workflowVersion","status","input","output","error","wakeAt","lockedBy","lockedUntil","recoveryAttempts","tags","searchAttributes","createdAt","updatedAt","type","nullable","tableName","StepCheckpointEntity","runId","seq","name","kind","stepId","events","attempts","workerGroup","enqueuedAt","startedAt","finishedAt","RunAttributeEntity","key","strValue","numValue","SignalWaiterEntity","token","BufferedSignalEntity","payload","autoincrement","index","ENTITIES","attributeColumnFor","attributeOperand","normalizeAttributeRows","sqlComparator","ensureMikroOrmDurableSchema","orm","schema","update","safe","MikroOrmStateStore","orm","ensureSchema","ensureMikroOrmDurableSchema","createRun","run","em","fork","create","WorkflowRunEntity","toRunEntity","flush","reindexAttributes","id","searchAttributes","updateRun","runId","patch","entity","findOneOrFail","Object","assign","fromRunEntity","attributes","forked","nativeDelete","RunAttributeEntity","rows","normalizeAttributeRows","length","insertMany","getRun","findOne","getCheckpoint","seq","StepCheckpointEntity","fromCheckpointEntity","saveCheckpoint","checkpoint","upsert","toCheckpointEntity","transaction","work","transactional","raw","cp","listIncompleteRuns","find","status","map","listPendingRuns","limit","orderBy","createdAt","listDueTimers","nowMs","wakeAt","$ne","$lte","Date","tryLockRun","owner","leaseUntilMs","affected","nativeUpdate","$or","lockedUntil","lockedBy","releaseRunLock","renewRunLock","listRuns","query","where","workflow","statuses","$and","$in","tag","quote","idQuote","cols","attributeColumns","qb","createQueryBuilder","tagsCol","tagsColumn","pattern","replace","colExpr","jsonAsText","andWhere","f","attributeExistsSql","offset","getResultList","alias","col","attributeColumnFor","numValue","strValue","cmp","sqlComparator","op","operand","attributeOperand","literal","String","a","table","sub","outerId","runPk","key","meta","getMetadata","get","field","prop","props","p","name","fieldNames","runMeta","properties","tableName","tags","colRef","platform","getPlatform","toLowerCase","includes","isMysql","ch","listCheckpoints","getLatestCheckpointByName","undefined","listCheckpointsByNamePrefix","prefixes","$like","putSignalWaiter","waiter","SignalWaiterEntity","takeSignalWaiter","token","remove","listSignalWaiters","prefix","e","bufferSignal","payload","BufferedSignalEntity","persist","takeBufferedSignal","workflowVersion","input","output","error","recoveryAttempts","updatedAt","getTime","kind","stepId","events","attempts","workerGroup","enqueuedAt","startedAt","finishedAt"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dudousxd/nestjs-durable-store-mikro-orm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "MikroORM adapter for the nestjs-durable StateStore (reference ORM adapter)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Davide Carvalho",
|
|
@@ -17,20 +17,22 @@
|
|
|
17
17
|
],
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"@dudousxd/nestjs-durable-core": ">=0.1.0 <1.0.0",
|
|
20
|
-
"@mikro-orm/core": "^
|
|
20
|
+
"@mikro-orm/core": "^7.0.0",
|
|
21
|
+
"@mikro-orm/decorators": "^7.0.0"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
23
|
-
"@mikro-orm/
|
|
24
|
-
"@mikro-orm/
|
|
25
|
-
"@mikro-orm/mysql": "
|
|
26
|
-
"@mikro-orm/postgresql": "
|
|
24
|
+
"@mikro-orm/core": "7.1.4",
|
|
25
|
+
"@mikro-orm/decorators": "7.1.4",
|
|
26
|
+
"@mikro-orm/mysql": "7.1.4",
|
|
27
|
+
"@mikro-orm/postgresql": "7.1.4",
|
|
28
|
+
"@mikro-orm/sqlite": "7.1.4",
|
|
27
29
|
"@testcontainers/mysql": "10.18.0",
|
|
28
30
|
"@testcontainers/postgresql": "10.18.0",
|
|
29
31
|
"reflect-metadata": "0.2.2",
|
|
30
|
-
"typescript": "5.9.3",
|
|
31
32
|
"tsup": "8.3.5",
|
|
32
|
-
"
|
|
33
|
-
"@dudousxd/nestjs-durable-
|
|
33
|
+
"typescript": "5.9.3",
|
|
34
|
+
"@dudousxd/nestjs-durable-core": "^0.28.2",
|
|
35
|
+
"@dudousxd/nestjs-durable-testing": "^0.4.1"
|
|
34
36
|
},
|
|
35
37
|
"module": "./dist/index.js",
|
|
36
38
|
"exports": {
|