@dudousxd/nestjs-durable-store-typeorm 0.13.0 → 0.14.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 +92 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -1
- package/dist/index.d.ts +23 -1
- package/dist/index.js +91 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
// src/index.ts
|
|
22
22
|
var index_exports = {};
|
|
23
23
|
__export(index_exports, {
|
|
24
|
+
BufferedEventEntity: () => BufferedEventEntity,
|
|
24
25
|
BufferedSignalEntity: () => BufferedSignalEntity,
|
|
25
26
|
ENTITIES: () => ENTITIES,
|
|
26
27
|
JSON_BLOB_COLUMNS: () => JSON_BLOB_COLUMNS,
|
|
@@ -140,6 +141,15 @@ var BufferedSignalEntity = class {
|
|
|
140
141
|
token;
|
|
141
142
|
payload;
|
|
142
143
|
};
|
|
144
|
+
var BufferedEventEntity = class {
|
|
145
|
+
static {
|
|
146
|
+
__name(this, "BufferedEventEntity");
|
|
147
|
+
}
|
|
148
|
+
id;
|
|
149
|
+
name;
|
|
150
|
+
payload;
|
|
151
|
+
publishedAt;
|
|
152
|
+
};
|
|
143
153
|
function durableEntities(options = {}) {
|
|
144
154
|
const col = columnNamer(options.naming ?? "snake_case");
|
|
145
155
|
const workflowRuns = new import_typeorm.EntitySchema({
|
|
@@ -408,12 +418,44 @@ function durableEntities(options = {}) {
|
|
|
408
418
|
}
|
|
409
419
|
}
|
|
410
420
|
});
|
|
421
|
+
const bufferedEvents = new import_typeorm.EntitySchema({
|
|
422
|
+
name: "BufferedEventEntity",
|
|
423
|
+
target: BufferedEventEntity,
|
|
424
|
+
tableName: "durable_buffered_events",
|
|
425
|
+
// No `indices` here (unlike MikroORM's EntitySchema, which does declare one): this store manages
|
|
426
|
+
// its DDL — including the `(name, publishedAt)` index — via raw SQL in `schema.ts`'s
|
|
427
|
+
// `ensureTypeOrmDurableSchema`, the same as every other durable_* table's indexes.
|
|
428
|
+
columns: {
|
|
429
|
+
// Caller-minted uuid (engine.publishEvent), not autoincrement — removeBufferedEvent targets it
|
|
430
|
+
// directly and needs to be handed the SAME id it was buffered with.
|
|
431
|
+
id: {
|
|
432
|
+
type: "text",
|
|
433
|
+
primary: true,
|
|
434
|
+
name: col("id")
|
|
435
|
+
},
|
|
436
|
+
name: {
|
|
437
|
+
type: "text",
|
|
438
|
+
name: col("name")
|
|
439
|
+
},
|
|
440
|
+
payload: {
|
|
441
|
+
type: "text",
|
|
442
|
+
nullable: true,
|
|
443
|
+
name: col("payload"),
|
|
444
|
+
transformer: jsonColumnTransformer("buffered.eventPayload")
|
|
445
|
+
},
|
|
446
|
+
publishedAt: {
|
|
447
|
+
type: Date,
|
|
448
|
+
name: col("publishedAt")
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
});
|
|
411
452
|
return [
|
|
412
453
|
workflowRuns,
|
|
413
454
|
stepCheckpoints,
|
|
414
455
|
runAttributes,
|
|
415
456
|
signalWaiters,
|
|
416
|
-
bufferedSignals
|
|
457
|
+
bufferedSignals,
|
|
458
|
+
bufferedEvents
|
|
417
459
|
];
|
|
418
460
|
}
|
|
419
461
|
__name(durableEntities, "durableEntities");
|
|
@@ -440,7 +482,8 @@ var TABLE_TO_ENTITY = {
|
|
|
440
482
|
durable_step_checkpoints: StepCheckpointEntity,
|
|
441
483
|
durable_run_attributes: RunAttributeEntity,
|
|
442
484
|
durable_signal_waiters: SignalWaiterEntity,
|
|
443
|
-
durable_buffered_signals: BufferedSignalEntity
|
|
485
|
+
durable_buffered_signals: BufferedSignalEntity,
|
|
486
|
+
durable_buffered_events: BufferedEventEntity
|
|
444
487
|
};
|
|
445
488
|
function durableManagedTables() {
|
|
446
489
|
return Object.keys(TABLE_TO_ENTITY);
|
|
@@ -490,11 +533,13 @@ async function ensureTypeOrmDurableSchema(dataSource) {
|
|
|
490
533
|
const runAttributes = q("durable_run_attributes");
|
|
491
534
|
const waiters = q("durable_signal_waiters");
|
|
492
535
|
const buffered = q("durable_buffered_signals");
|
|
536
|
+
const bufferedEvents = q("durable_buffered_events");
|
|
493
537
|
const runsCol = /* @__PURE__ */ __name((property) => q(resolve("durable_workflow_runs", property)), "runsCol");
|
|
494
538
|
const cpCol = /* @__PURE__ */ __name((property) => q(resolve("durable_step_checkpoints", property)), "cpCol");
|
|
495
539
|
const attrCol = /* @__PURE__ */ __name((property) => q(resolve("durable_run_attributes", property)), "attrCol");
|
|
496
540
|
const waiterCol = /* @__PURE__ */ __name((property) => q(resolve("durable_signal_waiters", property)), "waiterCol");
|
|
497
541
|
const bufCol = /* @__PURE__ */ __name((property) => q(resolve("durable_buffered_signals", property)), "bufCol");
|
|
542
|
+
const bevCol = /* @__PURE__ */ __name((property) => q(resolve("durable_buffered_events", property)), "bevCol");
|
|
498
543
|
const num = isPg ? "double precision" : isMysql ? "double" : "real";
|
|
499
544
|
const bufferedId = isSqlite ? `${bufCol("id")} integer PRIMARY KEY AUTOINCREMENT` : isMysql ? `${bufCol("id")} bigint NOT NULL AUTO_INCREMENT PRIMARY KEY` : isPg ? `${bufCol("id")} bigserial PRIMARY KEY` : `${bufCol("id")} bigint NOT NULL AUTO_INCREMENT PRIMARY KEY`;
|
|
500
545
|
const tables = [
|
|
@@ -532,6 +577,12 @@ async function ensureTypeOrmDurableSchema(dataSource) {
|
|
|
532
577
|
)`,
|
|
533
578
|
`CREATE TABLE IF NOT EXISTS ${buffered} (
|
|
534
579
|
${bufferedId}, ${bufCol("token")} ${str} NOT NULL, ${bufCol("payload")} ${txt}
|
|
580
|
+
)`,
|
|
581
|
+
// Caller-minted uuid PK (engine.publishEvent), not auto-increment — unlike durable_buffered_signals
|
|
582
|
+
// above, removeBufferedEvent needs to target the EXACT id it was buffered with.
|
|
583
|
+
`CREATE TABLE IF NOT EXISTS ${bufferedEvents} (
|
|
584
|
+
${bevCol("id")} ${str} PRIMARY KEY, ${bevCol("name")} ${str} NOT NULL,
|
|
585
|
+
${bevCol("payload")} ${txt}, ${bevCol("publishedAt")} ${ts} NOT NULL
|
|
535
586
|
)`
|
|
536
587
|
];
|
|
537
588
|
const additive = {
|
|
@@ -643,6 +694,11 @@ async function ensureTypeOrmDurableSchema(dataSource) {
|
|
|
643
694
|
"durable_buffered_signals_token_idx",
|
|
644
695
|
`${buffered} (${bufCol("token")})`
|
|
645
696
|
],
|
|
697
|
+
// buffered events are scanned oldest-first per name — one composite index serves both.
|
|
698
|
+
[
|
|
699
|
+
"durable_buffered_events_name_published_at_idx",
|
|
700
|
+
`${bufferedEvents} (${bevCol("name")}, ${bevCol("publishedAt")})`
|
|
701
|
+
],
|
|
646
702
|
// Search-attribute pushdown: equality + range predicates probe by (key, value). Two composite
|
|
647
703
|
// indexes — one per typed column — so a numeric range or a string equality is an index scan.
|
|
648
704
|
[
|
|
@@ -705,6 +761,9 @@ var TypeOrmStateStore = class {
|
|
|
705
761
|
buffered() {
|
|
706
762
|
return this.dataSource.getRepository(BufferedSignalEntity);
|
|
707
763
|
}
|
|
764
|
+
bufferedEvents() {
|
|
765
|
+
return this.dataSource.getRepository(BufferedEventEntity);
|
|
766
|
+
}
|
|
708
767
|
attributes() {
|
|
709
768
|
return this.dataSource.getRepository(RunAttributeEntity);
|
|
710
769
|
}
|
|
@@ -999,6 +1058,36 @@ var TypeOrmStateStore = class {
|
|
|
999
1058
|
payload: e.payload ?? void 0
|
|
1000
1059
|
};
|
|
1001
1060
|
}
|
|
1061
|
+
async bufferEvent(input) {
|
|
1062
|
+
await this.bufferedEvents().save({
|
|
1063
|
+
id: input.id,
|
|
1064
|
+
name: input.name,
|
|
1065
|
+
payload: input.payload ?? null,
|
|
1066
|
+
publishedAt: new Date(input.publishedAt)
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
async listBufferedEvents(name, limit) {
|
|
1070
|
+
const rows = await this.bufferedEvents().find({
|
|
1071
|
+
where: {
|
|
1072
|
+
name
|
|
1073
|
+
},
|
|
1074
|
+
order: {
|
|
1075
|
+
publishedAt: "ASC"
|
|
1076
|
+
},
|
|
1077
|
+
take: limit
|
|
1078
|
+
});
|
|
1079
|
+
return rows.map((e) => ({
|
|
1080
|
+
id: e.id,
|
|
1081
|
+
payload: e.payload ?? void 0,
|
|
1082
|
+
publishedAt: e.publishedAt.getTime()
|
|
1083
|
+
}));
|
|
1084
|
+
}
|
|
1085
|
+
async removeBufferedEvent(id) {
|
|
1086
|
+
const result = await this.bufferedEvents().delete({
|
|
1087
|
+
id
|
|
1088
|
+
});
|
|
1089
|
+
return result.affected === 1;
|
|
1090
|
+
}
|
|
1002
1091
|
};
|
|
1003
1092
|
function toRunEntity(run) {
|
|
1004
1093
|
return {
|
|
@@ -1099,6 +1188,7 @@ function fromCheckpointEntity(e) {
|
|
|
1099
1188
|
__name(fromCheckpointEntity, "fromCheckpointEntity");
|
|
1100
1189
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1101
1190
|
0 && (module.exports = {
|
|
1191
|
+
BufferedEventEntity,
|
|
1102
1192
|
BufferedSignalEntity,
|
|
1103
1193
|
ENTITIES,
|
|
1104
1194
|
JSON_BLOB_COLUMNS,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/entities.ts","../src/schema.ts","../src/typeorm-state-store.ts"],"sourcesContent":["export * from './entities';\nexport * from './schema';\nexport * from './typeorm-state-store';\n","import type { RunStatus, StepKind } from '@dudousxd/nestjs-durable-core';\nimport { EntitySchema, type ValueTransformer } from 'typeorm';\n\n/**\n * Safely deserialize a JSON-text column back to an object on READ.\n *\n * A column truncated by the old MySQL `text` 64KB limit (or otherwise corrupt) makes `JSON.parse`\n * throw \"Unterminated string in JSON\" — which, without this guard, would 500 the *entire* run-detail\n * read just because one blob is damaged. Instead, log once and degrade the bad field to `undefined`\n * so the rest of the run still renders. Valid JSON is unchanged.\n */\nexport function parseJsonColumn<T = unknown>(raw: unknown, field: string): T | undefined {\n if (raw == null) return undefined;\n // Some drivers (e.g. a native `json` column) already hand back a parsed object.\n if (typeof raw !== 'string') return raw as T;\n try {\n return JSON.parse(raw) as T;\n } catch (err) {\n console.warn(\n `durable store: failed to parse ${field} column, degrading to undefined: ${\n (err as Error).message\n }`,\n );\n return undefined;\n }\n}\n\n/**\n * TypeORM transformer for the free-form JSON-blob columns. Mirrors the built-in `simple-json`\n * serialization on WRITE (`JSON.stringify`, SQL NULL stays NULL) but uses {@link parseJsonColumn}\n * on READ so a single corrupt/truncated row degrades to `undefined` instead of throwing.\n */\nfunction jsonColumnTransformer(field: string): ValueTransformer {\n return {\n to: (value: unknown) => (value == null ? null : JSON.stringify(value)),\n from: (value: unknown) => parseJsonColumn(value, field),\n };\n}\n\n/**\n * How property names map to physical column names. The durable tables are adapter-agnostic: a run\n * written by one store adapter must be readable by another, so every adapter has to agree on the\n * physical column names. The default is `'snake_case'` (the canonical, matched by the MikroORM,\n * Prisma and Drizzle adapters). `'preserve'` keeps the camelCase property name verbatim (what the\n * old TypeORM/Prisma adapters produced before they were pinned). A function lets you supply any\n * custom mapping.\n *\n * The choice is pinned EXPLICITLY onto the entity schema rather than left to the host ORM's naming\n * strategy — depending on the host strategy is what silently diverged the adapters and broke a store\n * swap against an existing table.\n */\nexport type DurableColumnNaming = 'snake_case' | 'preserve' | ((property: string) => string);\n\nfunction snakeCase(property: string): string {\n return property.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);\n}\n\n/** Resolve a `DurableColumnNaming` to a `(property) => columnName` function. */\nexport function columnNamer(naming: DurableColumnNaming): (property: string) => string {\n if (naming === 'snake_case') return snakeCase;\n if (naming === 'preserve') return (property) => property;\n return naming;\n}\n\n// Plain classes (no decorators): the schema/column mapping lives on the EntitySchema built by\n// `durableEntities`, so the same class can be registered under different column names. The store\n// still references these classes for `getRepository`/`getMetadata`.\n\nexport class WorkflowRunEntity {\n id!: string;\n workflow!: string;\n workflowVersion!: string;\n status!: RunStatus;\n input?: unknown;\n output?: unknown;\n error?: unknown;\n wakeAt?: Date;\n lockedBy?: string | null;\n lockedUntil?: Date;\n awaitingDecisionTaskId?: string | null;\n recoveryAttempts?: number;\n tags?: string[] | null;\n searchAttributes?: Record<string, string | number | boolean> | null;\n priority?: number | null;\n createdAt!: Date;\n updatedAt!: Date;\n}\n\nexport class StepCheckpointEntity {\n runId!: string;\n seq!: number;\n name!: string;\n kind!: StepKind;\n stepId!: string;\n status!: 'pending' | 'running' | 'completed' | 'failed';\n input?: unknown;\n output?: unknown;\n error?: unknown;\n events?: unknown;\n attempts!: number;\n workerGroup?: string | null;\n parallelGroup?: string | null;\n wakeAt?: Date;\n enqueuedAt?: Date;\n startedAt!: 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 */\nexport class RunAttributeEntity {\n runId!: string;\n key!: string;\n strValue?: string | null;\n numValue?: number | null;\n}\n\nexport class SignalWaiterEntity {\n token!: string;\n runId!: string;\n seq!: number;\n parallelGroup?: string | null;\n}\n\nexport class BufferedSignalEntity {\n id!: number;\n token!: string;\n payload?: unknown;\n}\n\n/**\n * Build the durable TypeORM entity schemas with column names pinned per `naming` (default\n * `'snake_case'`). Register the result in your `DataSource`/`TypeOrmModule.forFeature`. The JSON-blob\n * columns keep the `jsonColumnTransformer` (corruption-tolerant read), the primary keys / auto-\n * increment / nullability are preserved, and the `id` of `durable_buffered_signals` stays a driver-\n * native auto-increment column.\n *\n * ```ts\n * entities: durableEntities({ naming: 'snake_case' })\n * ```\n */\nexport function durableEntities(options: { naming?: DurableColumnNaming } = {}): EntitySchema[] {\n const col = columnNamer(options.naming ?? 'snake_case');\n\n const workflowRuns = new EntitySchema<WorkflowRunEntity>({\n name: 'WorkflowRunEntity',\n target: WorkflowRunEntity,\n tableName: 'durable_workflow_runs',\n columns: {\n id: { type: 'text', primary: true, name: col('id') },\n workflow: { type: 'text', name: col('workflow') },\n workflowVersion: { type: 'text', name: col('workflowVersion') },\n status: { type: 'text', name: col('status') },\n input: {\n type: 'text',\n nullable: true,\n name: col('input'),\n transformer: jsonColumnTransformer('runs.input'),\n },\n output: {\n type: 'text',\n nullable: true,\n name: col('output'),\n transformer: jsonColumnTransformer('runs.output'),\n },\n error: {\n type: 'text',\n nullable: true,\n name: col('error'),\n transformer: jsonColumnTransformer('runs.error'),\n },\n wakeAt: { type: Date, nullable: true, name: col('wakeAt') },\n lockedBy: { type: 'text', nullable: true, name: col('lockedBy') },\n lockedUntil: { type: Date, nullable: true, name: col('lockedUntil') },\n // REMOTE turn the engine suspended on awaiting a decision; matched by completeRemoteDecision so\n // only the currently-awaited turn's decision is applied. Nullable: cleared when a decision lands.\n awaitingDecisionTaskId: {\n type: 'text',\n nullable: true,\n name: col('awaitingDecisionTaskId'),\n },\n recoveryAttempts: { type: 'integer', nullable: true, name: col('recoveryAttempts') },\n tags: {\n type: 'text',\n nullable: true,\n name: col('tags'),\n transformer: jsonColumnTransformer('runs.tags'),\n },\n searchAttributes: {\n type: 'text',\n nullable: true,\n name: col('searchAttributes'),\n transformer: jsonColumnTransformer('runs.searchAttributes'),\n },\n priority: { type: 'integer', nullable: true, name: col('priority') },\n createdAt: { type: Date, name: col('createdAt') },\n updatedAt: { type: Date, name: col('updatedAt') },\n },\n });\n\n const stepCheckpoints = new EntitySchema<StepCheckpointEntity>({\n name: 'StepCheckpointEntity',\n target: StepCheckpointEntity,\n tableName: 'durable_step_checkpoints',\n columns: {\n runId: { type: 'text', primary: true, name: col('runId') },\n seq: { type: 'integer', primary: true, name: col('seq') },\n name: { type: 'text', name: col('name') },\n kind: { type: 'text', name: col('kind') },\n stepId: { type: 'text', name: col('stepId') },\n status: { type: 'text', name: col('status') },\n input: {\n type: 'text',\n nullable: true,\n name: col('input'),\n transformer: jsonColumnTransformer('checkpoints.input'),\n },\n output: {\n type: 'text',\n nullable: true,\n name: col('output'),\n transformer: jsonColumnTransformer('checkpoints.output'),\n },\n error: {\n type: 'text',\n nullable: true,\n name: col('error'),\n transformer: jsonColumnTransformer('checkpoints.error'),\n },\n events: {\n type: 'text',\n nullable: true,\n name: col('events'),\n transformer: jsonColumnTransformer('checkpoints.events'),\n },\n attempts: { type: 'integer', name: col('attempts') },\n workerGroup: { type: 'text', nullable: true, name: col('workerGroup') },\n // A ctx.gather/ctx.all fan tags every sibling step with the same group so the dashboard renders\n // them as one parallel group; the core engine sets it (incl. from a remote worker's recordStep).\n parallelGroup: { type: 'text', nullable: true, name: col('parallelGroup') },\n wakeAt: { type: Date, nullable: true, name: col('wakeAt') },\n enqueuedAt: { type: Date, nullable: true, name: col('enqueuedAt') },\n startedAt: { type: Date, name: col('startedAt') },\n finishedAt: { type: Date, name: col('finishedAt') },\n },\n });\n\n const runAttributes = new EntitySchema<RunAttributeEntity>({\n name: 'RunAttributeEntity',\n target: RunAttributeEntity,\n tableName: 'durable_run_attributes',\n columns: {\n runId: { type: 'text', primary: true, name: col('runId') },\n key: { type: 'text', primary: true, name: col('key') },\n strValue: { type: 'text', nullable: true, name: col('strValue') },\n // `float`/`double` portable across SQLite/MySQL/Postgres for numeric range scans.\n numValue: { type: 'float', nullable: true, name: col('numValue') },\n },\n });\n\n const signalWaiters = new EntitySchema<SignalWaiterEntity>({\n name: 'SignalWaiterEntity',\n target: SignalWaiterEntity,\n tableName: 'durable_signal_waiters',\n columns: {\n token: { type: 'text', primary: true, name: col('token') },\n runId: { type: 'text', name: col('runId') },\n seq: { type: 'integer', name: col('seq') },\n // A ctx.gather_children/ctx.all child fan-out tags every awaited child with the same group; the\n // engine threads it onto the waiter so the resolving `signal:child:` checkpoint carries it and the\n // dashboard renders the fan as one parallel group. Nullable: only fan-out child waiters carry it.\n parallelGroup: { type: 'text', nullable: true, name: col('parallelGroup') },\n },\n });\n\n const bufferedSignals = new EntitySchema<BufferedSignalEntity>({\n name: 'BufferedSignalEntity',\n target: BufferedSignalEntity,\n tableName: 'durable_buffered_signals',\n columns: {\n // Auto-increment PK for FIFO ordering. Left as TypeORM's default increment generation so it\n // maps to the driver-native auto-increment column (INTEGER on SQLite, BIGINT/SERIAL elsewhere).\n id: { type: Number, primary: true, generated: 'increment', name: col('id') },\n token: { type: 'text', name: col('token') },\n payload: {\n type: 'text',\n nullable: true,\n name: col('payload'),\n transformer: jsonColumnTransformer('buffered.payload'),\n },\n },\n });\n\n return [workflowRuns, stepCheckpoints, runAttributes, signalWaiters, bufferedSignals];\n}\n\n/** Durable entity schemas with the canonical `'snake_case'` column names. */\nexport const ENTITIES = durableEntities();\n","import type { DataSource } from 'typeorm';\nimport {\n BufferedSignalEntity,\n RunAttributeEntity,\n SignalWaiterEntity,\n StepCheckpointEntity,\n WorkflowRunEntity,\n} from './entities';\n\n/** The JSON-blob columns per table (keyed by table name) that hold free-form payloads and so must\n * be the unbounded text type — `longtext` on MySQL, `text` elsewhere. Keyed by entity PROPERTY name;\n * the physical column is resolved from the DataSource metadata so it tracks the configured naming. */\nexport const JSON_BLOB_COLUMNS: Record<string, string[]> = {\n durable_workflow_runs: ['input', 'output', 'error', 'tags', 'searchAttributes'],\n durable_step_checkpoints: ['input', 'output', 'error', 'events'],\n};\n\n/** Each durable table → its backing entity class, so a column resolver can look up the physical\n * column for any (table, property) from the DataSource metadata (which reflects the configured\n * `DurableColumnNaming`). Keeps the raw DDL/SQL in lock-step with the entity column mapping. */\nconst TABLE_TO_ENTITY = {\n durable_workflow_runs: WorkflowRunEntity,\n durable_step_checkpoints: StepCheckpointEntity,\n durable_run_attributes: RunAttributeEntity,\n durable_signal_waiters: SignalWaiterEntity,\n durable_buffered_signals: BufferedSignalEntity,\n} as const;\n\n/**\n * Tables this store creates and manages at boot (autoSchema, see {@link ensureTypeOrmDurableSchema}).\n * Feed to your ORM's migration differ exclude/skipTables so it never tries to drop them.\n *\n * ```ts\n * // MikroORM-flavoured example (TypeORM has no built-in equivalent option); adapt to whichever\n * // migration tool generates your diffs — e.g. exclude these names from a typeorm-generated\n * // migration, or filter them out of `SELECT table_name FROM information_schema.tables` before\n * // diffing against your own entities.\n * const skipTables = new Set(durableManagedTables());\n * ```\n *\n * Derived from the same {@link TABLE_TO_ENTITY} map the raw-SQL heal keys its column resolution off\n * — one list, so a consumer's denylist can never drift from what this store actually owns.\n */\nexport function durableManagedTables(): string[] {\n return Object.keys(TABLE_TO_ENTITY);\n}\n\n/**\n * Resolve `(table, property) => physical column name` from the DataSource's entity metadata. The\n * column names are NOT hardcoded here: they come from whatever the registered `durableEntities`\n * mapped (canonical `snake_case` by default, `'preserve'` for the legacy camelCase, or a custom\n * mapping), so the raw `CREATE TABLE`/index/EXISTS SQL always matches the entities and can never\n * silently diverge.\n */\nexport function durableColumnResolver(\n dataSource: DataSource,\n): (table: string, property: string) => string {\n return (table, property) => {\n const entity = TABLE_TO_ENTITY[table as keyof typeof TABLE_TO_ENTITY];\n if (!entity) throw new Error(`durable store: unknown table \"${table}\"`);\n const meta = dataSource.getMetadata(entity);\n const column = meta.findColumnWithPropertyName(property);\n if (!column) {\n throw new Error(`durable store: no column for ${table}.${property} in entity metadata`);\n }\n return column.databaseName;\n };\n}\n\n/** The SQL type for free-form JSON-blob columns. MySQL `text` caps at 64KB and silently truncates,\n * so use `longtext` (4GB) there; Postgres/SQLite `text` is already unbounded. */\nexport function jsonBlobColumnType(isMysql: boolean): 'longtext' | 'text' {\n return isMysql ? 'longtext' : 'text';\n}\n\n/** Idempotent `MODIFY COLUMN ... longtext` statements that widen pre-existing MySQL `text` JSON-blob\n * columns. Returns `[]` on non-MySQL dialects (their `text` is already unbounded — nothing to do).\n * `quote` quotes an identifier per the active driver; `col` resolves a property to its physical\n * column name so the widen tracks the configured naming. */\nexport function buildWidenStatements(\n isMysql: boolean,\n quote: (id: string) => string,\n col: (table: string, property: string) => string,\n): string[] {\n if (!isMysql) return [];\n const out: string[] = [];\n for (const [table, props] of Object.entries(JSON_BLOB_COLUMNS)) {\n for (const prop of props) {\n out.push(`ALTER TABLE ${quote(table)} MODIFY COLUMN ${quote(col(table, prop))} longtext`);\n }\n }\n return out;\n}\n\n/**\n * Idempotently create the durable tables. Safe to run on every boot (auto-schema) and the\n * exact function to call from your own TypeORM migration when you disable auto-schema:\n *\n * ```ts\n * export class AddDurableTables implements MigrationInterface {\n * async up(q: QueryRunner) { await ensureTypeOrmDurableSchema(q.connection); }\n * }\n * ```\n *\n * Dialect-aware (MySQL / MariaDB / Postgres / SQLite): identifiers are quoted per driver, keyed\n * string columns are `varchar` (MySQL can't key a `text` column), and the index is best-effort.\n * Only ever adds the three durable tables — it never touches your other tables.\n */\nexport async function ensureTypeOrmDurableSchema(dataSource: DataSource): Promise<void> {\n const q = (id: string) => dataSource.driver.escape(id);\n // Physical column names come from the entity metadata (canonical snake_case by default), so this\n // raw DDL always matches the registered `durableEntities` instead of hardcoding camelCase.\n const resolve = durableColumnResolver(dataSource);\n const type = String(dataSource.options.type);\n const isPg = type === 'postgres' || type === 'aurora-postgres';\n const isMysql = type === 'mysql' || type === 'mariadb' || type === 'aurora-mysql';\n const isSqlite = type === 'sqlite' || type === 'better-sqlite3' || type === 'expo';\n\n // Keyed/short strings must be varchar on MySQL (a `text` PK/index needs a key length); `text`\n // for the free-form JSON payloads. Dates use the dialect's native timestamp type.\n const str = 'varchar(191)';\n // Free-form JSON payloads (`input`/`output`/`error`/`events`/`tags`/`searchAttributes`). MySQL's\n // `text` caps at 64KB and *silently truncates* — a large fan-out step's `events` then fails to\n // parse on read (\"Unterminated string in JSON\"). Use `longtext` (4GB) on MySQL; Postgres `text`\n // is already unbounded and SQLite `text` has no length limit.\n const txt = jsonBlobColumnType(isMysql);\n const int = isMysql ? 'int' : 'integer';\n const ts = isPg ? 'timestamptz' : 'datetime';\n\n const runs = q('durable_workflow_runs');\n const checkpoints = q('durable_step_checkpoints');\n const runAttributes = q('durable_run_attributes');\n const waiters = q('durable_signal_waiters');\n const buffered = q('durable_buffered_signals');\n // Per-table quoted-column helpers: resolve an entity property to its physical column then quote it.\n const runsCol = (property: string) => q(resolve('durable_workflow_runs', property));\n const cpCol = (property: string) => q(resolve('durable_step_checkpoints', property));\n const attrCol = (property: string) => q(resolve('durable_run_attributes', property));\n const waiterCol = (property: string) => q(resolve('durable_signal_waiters', property));\n const bufCol = (property: string) => q(resolve('durable_buffered_signals', property));\n // Numeric side-table column for attribute range scans. `double precision` on Postgres, `double` on\n // MySQL, `real` on SQLite (all hold JS numbers without precision loss for the typical attribute).\n const num = isPg ? 'double precision' : isMysql ? 'double' : 'real';\n\n // Auto-increment PK syntax differs per dialect: SQLite wants `INTEGER PRIMARY KEY AUTOINCREMENT`,\n // MySQL `BIGINT AUTO_INCREMENT PRIMARY KEY`, Postgres `BIGSERIAL PRIMARY KEY`.\n const bufferedId = isSqlite\n ? `${bufCol('id')} integer PRIMARY KEY AUTOINCREMENT`\n : isMysql\n ? `${bufCol('id')} bigint NOT NULL AUTO_INCREMENT PRIMARY KEY`\n : isPg\n ? `${bufCol('id')} bigserial PRIMARY KEY`\n : `${bufCol('id')} bigint NOT NULL AUTO_INCREMENT PRIMARY KEY`;\n\n const tables = [\n `CREATE TABLE IF NOT EXISTS ${runs} (\n ${runsCol('id')} ${str} PRIMARY KEY,\n ${runsCol('workflow')} ${str} NOT NULL,\n ${runsCol('workflowVersion')} ${str} NOT NULL,\n ${runsCol('status')} ${str} NOT NULL,\n ${runsCol('input')} ${txt}, ${runsCol('output')} ${txt}, ${runsCol('error')} ${txt},\n ${runsCol('wakeAt')} ${ts}, ${runsCol('lockedBy')} ${str}, ${runsCol('lockedUntil')} ${ts},\n ${runsCol('awaitingDecisionTaskId')} ${str},\n ${runsCol('recoveryAttempts')} ${int}, ${runsCol('tags')} ${txt}, ${runsCol('searchAttributes')} ${txt},\n ${runsCol('priority')} ${int},\n ${runsCol('createdAt')} ${ts} NOT NULL, ${runsCol('updatedAt')} ${ts} NOT NULL\n )`,\n `CREATE TABLE IF NOT EXISTS ${checkpoints} (\n ${cpCol('runId')} ${str} NOT NULL, ${cpCol('seq')} ${int} NOT NULL,\n ${cpCol('name')} ${str} NOT NULL, ${cpCol('kind')} ${str} NOT NULL, ${cpCol('stepId')} ${str} NOT NULL,\n ${cpCol('status')} ${str} NOT NULL, ${cpCol('input')} ${txt}, ${cpCol('output')} ${txt}, ${cpCol('error')} ${txt}, ${cpCol('events')} ${txt},\n ${cpCol('attempts')} ${int} NOT NULL, ${cpCol('workerGroup')} ${str}, ${cpCol('parallelGroup')} ${str},\n ${cpCol('wakeAt')} ${ts}, ${cpCol('enqueuedAt')} ${ts},\n ${cpCol('startedAt')} ${ts} NOT NULL, ${cpCol('finishedAt')} ${ts} NOT NULL,\n PRIMARY KEY (${cpCol('runId')}, ${cpCol('seq')})\n )`,\n // Normalized search-attribute side-table: one row per (run, key) so attribute predicates push\n // DOWN into SQL via an EXISTS join (indexed below). `key` is keyed → must be varchar on MySQL.\n `CREATE TABLE IF NOT EXISTS ${runAttributes} (\n ${attrCol('runId')} ${str} NOT NULL, ${attrCol('key')} ${str} NOT NULL,\n ${attrCol('strValue')} ${str}, ${attrCol('numValue')} ${num},\n PRIMARY KEY (${attrCol('runId')}, ${attrCol('key')})\n )`,\n `CREATE TABLE IF NOT EXISTS ${waiters} (\n ${waiterCol('token')} ${str} PRIMARY KEY, ${waiterCol('runId')} ${str} NOT NULL, ${waiterCol('seq')} ${int} NOT NULL,\n ${waiterCol('parallelGroup')} ${str}\n )`,\n `CREATE TABLE IF NOT EXISTS ${buffered} (\n ${bufferedId}, ${bufCol('token')} ${str} NOT NULL, ${bufCol('payload')} ${txt}\n )`,\n ];\n\n // Additive nullable columns gained across versions (e.g. `input`, `events`, `enqueuedAt`). On a\n // table that predates them, `CREATE TABLE IF NOT EXISTS` above is a no-op, so back-fill the ones\n // that are actually missing — the auto-schema self-heals instead of needing a manual migration.\n // We check the live columns first (rather than ALTER-and-ignore) so a *real* ALTER failure\n // surfaces instead of being swallowed as a presumed \"column already exists\".\n // Keyed by entity PROPERTY name; the physical column is resolved per-table so the ADD COLUMN\n // tracks the configured naming.\n const additive: Record<string, Array<[string, string]>> = {\n durable_workflow_runs: [\n ['input', txt],\n ['output', txt],\n ['error', txt],\n ['awaitingDecisionTaskId', str],\n ['recoveryAttempts', int],\n ['tags', txt],\n ['searchAttributes', txt],\n ['priority', int],\n ],\n durable_step_checkpoints: [\n ['input', txt],\n ['output', txt],\n ['error', txt],\n ['events', txt],\n ['workerGroup', str],\n ['parallelGroup', str],\n ['enqueuedAt', ts],\n ],\n // Back-fill the child-await fan group onto signal-waiter tables that predate it (a remote\n // `gather_children` fan-out threads its group here so the resolved `signal:child:` checkpoint carries it).\n durable_signal_waiters: [['parallelGroup', str]],\n };\n\n const runner = dataSource.createQueryRunner();\n try {\n for (const sql of tables) await runner.query(sql);\n for (const [table, props] of Object.entries(additive)) {\n const have = await existingColumns(runner, table, { isSqlite, isMysql });\n for (const [property, colType] of props) {\n const column = resolve(table, property);\n if (!have.has(column)) {\n await runner.query(`ALTER TABLE ${q(table)} ADD COLUMN ${q(column)} ${colType}`);\n }\n }\n }\n // Widen pre-existing MySQL `text` JSON-blob columns to `longtext`. A table created before this\n // fix has these as `text` (64KB) and silently truncates large `events`/`output` payloads. MODIFY\n // to `longtext` is idempotent (no-op if already longtext), so it's safe to run on every boot.\n // MySQL-only: Postgres/SQLite `text` is already unbounded, so there's nothing to widen.\n for (const sql of buildWidenStatements(isMysql, q, resolve)) {\n try {\n await runner.query(sql);\n } catch {\n /* column already longtext, or table/column not present on this deploy */\n }\n }\n // MySQL has no `CREATE INDEX IF NOT EXISTS`; create each best-effort and ignore \"already exists\".\n // - status/wakeAt: the timer poller (listDueTimers) and recovery (listIncompleteRuns) scans.\n // - workflow/status: the dashboard's listRuns filters. (Checkpoints are keyed by the PK prefix\n // `(runId, seq)`, so listCheckpoints/getEvent already hit an index — no extra one needed.)\n const indexes: Array<[string, string]> = [\n ['durable_runs_status_idx', `${runs} (${runsCol('status')}, ${runsCol('wakeAt')})`],\n [\n 'durable_runs_workflow_status_idx',\n `${runs} (${runsCol('workflow')}, ${runsCol('status')})`,\n ],\n // buffered signals are taken FIFO per token (smallest id) — index the token for the scan.\n ['durable_buffered_signals_token_idx', `${buffered} (${bufCol('token')})`],\n // Search-attribute pushdown: equality + range predicates probe by (key, value). Two composite\n // indexes — one per typed column — so a numeric range or a string equality is an index scan.\n [\n 'durable_run_attributes_num_idx',\n `${runAttributes} (${attrCol('key')}, ${attrCol('numValue')})`,\n ],\n [\n 'durable_run_attributes_str_idx',\n `${runAttributes} (${attrCol('key')}, ${attrCol('strValue')})`,\n ],\n ];\n for (const [name, target] of indexes) {\n try {\n await runner.query(`CREATE INDEX ${q(name)} ON ${target}`);\n } catch {\n /* index already exists */\n }\n }\n } finally {\n await runner.release();\n }\n}\n\n/** The columns that currently exist on `table`, so the schema can add only the missing ones\n * (instead of ALTER-and-swallow, which would also hide a genuine ALTER failure). */\nasync function existingColumns(\n runner: { query: (sql: string, params?: unknown[]) => Promise<unknown> },\n table: string,\n d: { isSqlite: boolean; isMysql: boolean },\n): Promise<Set<string>> {\n if (d.isSqlite) {\n const rows = (await runner.query(`PRAGMA table_info(\"${table}\")`)) as Array<{ name: string }>;\n return new Set(rows.map((r) => r.name));\n }\n // Postgres + MySQL both expose information_schema; scope to the connection's own schema/db.\n // Bind-param placeholder differs: Postgres uses `$1`, MySQL uses `?` (TypeORM only rewrites `?`\n // inside the query builder, not for these raw `runner.query` calls), so pick per dialect.\n const scope = d.isMysql ? 'TABLE_SCHEMA = DATABASE()' : 'table_schema = current_schema()';\n const placeholder = d.isMysql ? '?' : '$1';\n const rows = (await runner.query(\n `SELECT column_name AS name FROM information_schema.columns WHERE table_name = ${placeholder} AND ${scope}`,\n [table],\n )) as Array<{ name?: string; COLUMN_NAME?: string }>;\n return new Set(rows.map((r) => (r.name ?? r.COLUMN_NAME) as string));\n}\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 {\n Brackets,\n type DataSource,\n type EntityManager,\n In,\n IsNull,\n LessThanOrEqual,\n Like,\n type SelectQueryBuilder,\n} from 'typeorm';\nimport type { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';\nimport {\n BufferedSignalEntity,\n RunAttributeEntity,\n SignalWaiterEntity,\n StepCheckpointEntity,\n WorkflowRunEntity,\n} from './entities';\nimport { durableColumnResolver, ensureTypeOrmDurableSchema } from './schema';\n\n/**\n * TypeORM-backed `StateStore`. Works on any TypeORM driver — Postgres, MySQL, SQLite (tested);\n * timestamps use native datetime columns and `wakeAt` is stored as a datetime too.\n */\nexport class TypeOrmStateStore implements StateStore {\n constructor(private readonly dataSource: DataSource) {}\n\n async ensureSchema(): Promise<void> {\n await ensureTypeOrmDurableSchema(this.dataSource);\n }\n\n private runs() {\n return this.dataSource.getRepository(WorkflowRunEntity);\n }\n private checkpoints() {\n return this.dataSource.getRepository(StepCheckpointEntity);\n }\n private waiters() {\n return this.dataSource.getRepository(SignalWaiterEntity);\n }\n private buffered() {\n return this.dataSource.getRepository(BufferedSignalEntity);\n }\n private attributes() {\n return this.dataSource.getRepository(RunAttributeEntity);\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 em?: EntityManager,\n ): Promise<void> {\n const repo = em ? em.getRepository(RunAttributeEntity) : this.attributes();\n await repo.delete({ runId });\n const rows = normalizeAttributeRows(runId, attributes);\n if (rows.length) await repo.insert(rows);\n }\n\n async createRun(run: WorkflowRun): Promise<void> {\n await this.runs().save(toRunEntity(run));\n await this.reindexAttributes(run.id, run.searchAttributes);\n }\n\n async updateRun(runId: string, patch: Partial<WorkflowRun>): Promise<void> {\n // Single UPDATE (no pre-SELECT + save round-trips): map only the patched fields. The query\n // builder still applies the entities' JSON column transformers to the `set` values (as in\n // listRuns/tryLockRun). Preserve the not-found throw any caller may rely on.\n const update: Record<string, unknown> = {};\n if ('workflow' in patch) update.workflow = patch.workflow;\n if ('workflowVersion' in patch) update.workflowVersion = patch.workflowVersion;\n if ('status' in patch) update.status = patch.status;\n if ('input' in patch) update.input = patch.input ?? null;\n if ('output' in patch) update.output = patch.output ?? null;\n if ('error' in patch) update.error = patch.error ?? null;\n if ('wakeAt' in patch) update.wakeAt = patch.wakeAt == null ? null : new Date(patch.wakeAt);\n if ('lockedBy' in patch) update.lockedBy = patch.lockedBy ?? null;\n if ('lockedUntil' in patch)\n update.lockedUntil = patch.lockedUntil == null ? null : new Date(patch.lockedUntil);\n if ('awaitingDecisionTaskId' in patch)\n update.awaitingDecisionTaskId = patch.awaitingDecisionTaskId ?? null;\n if ('recoveryAttempts' in patch) update.recoveryAttempts = patch.recoveryAttempts;\n if ('tags' in patch) update.tags = patch.tags ?? null;\n if ('searchAttributes' in patch) update.searchAttributes = patch.searchAttributes ?? null;\n if ('priority' in patch) update.priority = patch.priority ?? null;\n if ('createdAt' in patch) update.createdAt = patch.createdAt;\n if ('updatedAt' in patch) update.updatedAt = patch.updatedAt;\n const result = await this.runs()\n .createQueryBuilder()\n .update()\n .set(update)\n .where({ id: runId })\n .execute();\n if (!result.affected) throw new Error(`run ${runId} not found`);\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 async getRun(runId: string): Promise<WorkflowRun | null> {\n const e = await this.runs().findOneBy({ id: runId });\n return e ? fromRunEntity(e) : null;\n }\n\n async deleteRun(runId: string): Promise<void> {\n // Child rows first, then the run — checkpoints, signal waiters, attribute rows.\n await this.checkpoints().delete({ runId });\n await this.waiters().delete({ runId });\n await this.attributes().delete({ runId });\n await this.runs().delete({ id: runId });\n }\n\n async getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null> {\n const e = await this.checkpoints().findOneBy({ runId, seq });\n return e ? fromCheckpointEntity(e) : null;\n }\n\n async saveCheckpoint(checkpoint: StepCheckpoint): Promise<void> {\n // upsert = INSERT ... ON CONFLICT DO UPDATE on the (runId, seq) key — drops the pre-SELECT that\n // `.save()` does on each write. JSON column transformers still apply for upsert.\n const entity = toCheckpointEntity(checkpoint) as QueryDeepPartialEntity<StepCheckpointEntity>;\n await this.checkpoints().upsert(entity, ['runId', 'seq']);\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.dataSource.transaction(async (em) =>\n work({\n raw: em,\n saveCheckpoint: async (cp) => {\n await em.getRepository(StepCheckpointEntity).save(toCheckpointEntity(cp));\n },\n }),\n );\n }\n\n async listIncompleteRuns(): Promise<WorkflowRun[]> {\n const rows = await this.runs().findBy({ status: In(['running', 'cancelling']) });\n return rows.map(fromRunEntity);\n }\n\n async listPendingRuns(limit: number): Promise<WorkflowRun[]> {\n const rows = await this.runs().find({\n where: { status: 'pending' },\n order: { createdAt: 'ASC' }, // FIFO dispatch\n take: limit,\n });\n return rows.map(fromRunEntity);\n }\n\n async listDueTimers(nowMs: number): Promise<WorkflowRun[]> {\n const rows = await this.runs().findBy({\n status: 'suspended',\n wakeAt: LessThanOrEqual(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 result = await this.runs()\n .createQueryBuilder()\n .update()\n .set({ lockedBy: owner, lockedUntil: new Date(leaseUntilMs) })\n .where({ id: runId })\n .andWhere(\n new Brackets((qb) =>\n qb\n .where({ lockedUntil: IsNull() })\n .orWhere({ lockedUntil: LessThanOrEqual(new Date(nowMs)) }),\n ),\n )\n .execute();\n return result.affected === 1;\n }\n\n async releaseRunLock(runId: string): Promise<void> {\n await this.runs().update({ id: runId }, { lockedBy: null, lockedUntil: () => 'NULL' });\n }\n\n async renewRunLock(runId: string, owner: string, leaseUntilMs: number): Promise<boolean> {\n const result = await this.runs()\n .createQueryBuilder()\n .update()\n .set({ lockedUntil: new Date(leaseUntilMs) })\n .where({ id: runId, lockedBy: owner })\n .execute();\n return result.affected === 1;\n }\n\n async listRuns(query: RunQuery): Promise<WorkflowRun[]> {\n // `tags` carries a custom JSON transformer, and TypeORM applies a column transformer's `to()` to\n // FindOperator values too — so a `Like('%\"etl\"%')` in a plain `where` would be JSON-stringified\n // and corrupt the LIKE pattern. Use the query builder with a raw parameter to bypass that.\n const qb = this.runs().createQueryBuilder('r');\n if (query.workflow) qb.andWhere('r.workflow = :workflow', { workflow: query.workflow });\n if (query.status) qb.andWhere('r.status = :status', { status: query.status });\n if (query.statuses)\n qb.andWhere(\n query.statuses.length ? 'r.status IN (:...statuses)' : '1 = 0',\n query.statuses.length ? { statuses: query.statuses } : {},\n );\n // `tags` is a JSON-text column; match the quoted token so `etl` doesn't match `etl-foo`. NOTE: a\n // leading-wildcard LIKE on JSON text is NOT index-friendly (no B-tree index can serve `%\"x\"%`), so\n // tag-filtered scans (e.g. singleton admission) are sequential over `durable_runs_workflow_status_idx`'s\n // result set. The `statuses`/`workflow` predicates above bound that scan; if tag scans ever dominate,\n // promote tags to a normalized join table or a JSON/GIN index — a schema change, intentionally not done here.\n if (query.tag) qb.andWhere('r.tags LIKE :tagPattern', { tagPattern: `%\"${query.tag}\"%` });\n // Typed/range attribute predicates push DOWN into SQL: each filter becomes an EXISTS against the\n // normalized `durable_run_attributes` side-table (indexed on (key, numValue)/(key, strValue)), so\n // the DB does the filtering AND the LIMIT/OFFSET — no full scan + in-process filter. ANDed: a run\n // must satisfy every filter, so one EXISTS per filter.\n if (query.attributes?.length) {\n query.attributes.forEach((f, i) => this.applyAttributeExists(qb, f, i));\n }\n qb.orderBy('r.createdAt', 'DESC'); // newest first — recent runs on top in the dashboard\n if (query.limit != null) qb.take(query.limit);\n if (query.offset != null) qb.skip(query.offset);\n const rows = await qb.getMany();\n return rows.map(fromRunEntity);\n }\n\n /** Add one attribute predicate to `qb` as an EXISTS subquery on the side-table. `i` namespaces the\n * bind params so multiple ANDed filters don't collide. */\n private applyAttributeExists(\n qb: SelectQueryBuilder<WorkflowRunEntity>,\n f: AttributeFilter,\n i: number,\n ): void {\n const valueProperty = attributeColumnFor(f); // 'numValue' | 'strValue' (entity property)\n const cmp = sqlComparator(f.op);\n const keyParam = `attrKey${i}`;\n const valParam = `attrVal${i}`;\n // Resolve the PHYSICAL column names from the entity metadata so this raw subquery tracks the\n // configured naming (canonical snake_case by default) instead of hardcoding camelCase — which\n // would break the EXISTS pushdown the moment the table is snake_case.\n const resolve = durableColumnResolver(this.dataSource);\n const q = this.idQuote();\n const wrap = (name: string) => `${q}${name}${q}`;\n const runIdCol = wrap(resolve('durable_run_attributes', 'runId'));\n const keyCol = wrap(resolve('durable_run_attributes', 'key'));\n const valueCol = wrap(resolve('durable_run_attributes', valueProperty));\n const runPkCol = wrap(resolve('durable_workflow_runs', 'id'));\n const table = wrap('durable_run_attributes');\n // `<>` (ne) must also exclude rows where the attribute is absent: the missing-key-never-matches\n // contract (see core matchesAttributes). EXISTS already requires the key row to be present, and a\n // row only exists when the value is non-null, so EXISTS(... <> ...) gives exactly ne-with-present.\n const a = `a${i}`;\n const sql = `EXISTS (SELECT 1 FROM ${table} ${a} WHERE ${a}.${runIdCol} = r.${runPkCol} AND ${a}.${keyCol} = :${keyParam} AND ${a}.${valueCol} ${cmp} :${valParam})`;\n qb.andWhere(sql, {\n [keyParam]: f.key,\n [valParam]: attributeOperand(f),\n });\n }\n\n /** The identifier quote char for the active driver (MySQL backtick, others double-quote). */\n private idQuote(): string {\n const type = String(this.dataSource.options.type);\n return type === 'mysql' || type === 'mariadb' || type === 'aurora-mysql' ? '`' : '\"';\n }\n\n async listCheckpoints(runId: string): Promise<StepCheckpoint[]> {\n const rows = await this.checkpoints().find({ where: { runId }, order: { seq: 'ASC' } });\n return rows.map(fromCheckpointEntity);\n }\n\n async getLatestCheckpointByName(\n runId: string,\n name: string,\n ): Promise<StepCheckpoint | undefined> {\n const e = await this.checkpoints().findOne({ where: { runId, name }, order: { seq: 'DESC' } });\n return e ? fromCheckpointEntity(e) : undefined;\n }\n\n async listCheckpointsByNamePrefix(runId: string, prefixes: string[]): Promise<StepCheckpoint[]> {\n if (prefixes.length === 0) return [];\n const rows = await this.checkpoints().find({\n where: prefixes.map((p) => ({ runId, name: Like(`${p}%`) })),\n order: { seq: 'ASC' },\n });\n return rows.map(fromCheckpointEntity);\n }\n\n async putSignalWaiter(waiter: SignalWaiter): Promise<void> {\n await this.waiters().save({\n token: waiter.token,\n runId: waiter.runId,\n seq: waiter.seq,\n parallelGroup: waiter.parallelGroup ?? null,\n });\n }\n\n async listSignalWaiters(prefix: string): Promise<SignalWaiter[]> {\n const rows = await this.waiters().find({ where: { token: Like(`${prefix}%`) } });\n return rows.map((e) => ({\n token: e.token,\n runId: e.runId,\n seq: e.seq,\n parallelGroup: e.parallelGroup ?? undefined,\n }));\n }\n\n async takeSignalWaiter(token: string): Promise<SignalWaiter | null> {\n const e = await this.waiters().findOneBy({ token });\n if (!e) return null;\n const waiter: SignalWaiter = {\n token: e.token,\n runId: e.runId,\n seq: e.seq,\n parallelGroup: e.parallelGroup ?? undefined,\n };\n await this.waiters().delete({ token });\n return waiter;\n }\n\n async removeSignalWaiter(waiter: SignalWaiter): Promise<void> {\n // Exact-match delete (token AND runId AND seq) — a plain `delete({ token })` would remove\n // whatever row currently owns the token, even if a different run has since claimed it.\n await this.waiters().delete({ token: waiter.token, runId: waiter.runId, seq: waiter.seq });\n }\n\n async bufferSignal(token: string, payload: unknown): Promise<void> {\n await this.buffered().save({ token, payload: payload ?? null });\n }\n\n async takeBufferedSignal(token: string): Promise<{ payload: unknown } | null> {\n const e = await this.buffered().findOne({ where: { token }, order: { id: 'ASC' } });\n if (!e) return null;\n await this.buffered().delete({ id: e.id });\n return { payload: e.payload ?? undefined };\n }\n}\n\nfunction toRunEntity(run: WorkflowRun): WorkflowRunEntity {\n return {\n id: run.id,\n workflow: run.workflow,\n workflowVersion: run.workflowVersion,\n status: run.status,\n input: run.input ?? null,\n output: run.output ?? null,\n error: run.error ?? null,\n ...(run.wakeAt == null ? {} : { wakeAt: new Date(run.wakeAt) }),\n lockedBy: run.lockedBy ?? null,\n ...(run.lockedUntil == null ? {} : { lockedUntil: new Date(run.lockedUntil) }),\n awaitingDecisionTaskId: run.awaitingDecisionTaskId ?? null,\n ...(run.recoveryAttempts === undefined ? {} : { recoveryAttempts: run.recoveryAttempts }),\n tags: run.tags ?? null,\n searchAttributes: run.searchAttributes ?? null,\n priority: run.priority ?? null,\n createdAt: run.createdAt,\n updatedAt: run.updatedAt,\n };\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 == null ? undefined : e.wakeAt.getTime(),\n lockedBy: e.lockedBy ?? undefined,\n lockedUntil: e.lockedUntil == null ? undefined : e.lockedUntil.getTime(),\n awaitingDecisionTaskId: e.awaitingDecisionTaskId ?? undefined,\n recoveryAttempts: e.recoveryAttempts ?? undefined,\n tags: e.tags ?? undefined,\n searchAttributes: e.searchAttributes ?? undefined,\n priority: e.priority ?? undefined,\n createdAt: e.createdAt,\n updatedAt: e.updatedAt,\n };\n}\n\nfunction toCheckpointEntity(cp: StepCheckpoint): StepCheckpointEntity {\n return {\n runId: cp.runId,\n seq: cp.seq,\n name: cp.name,\n kind: cp.kind,\n stepId: cp.stepId,\n status: cp.status,\n input: cp.input ?? null,\n output: cp.output ?? null,\n error: cp.error ?? null,\n events: cp.events ?? null,\n attempts: cp.attempts,\n workerGroup: cp.workerGroup ?? null,\n parallelGroup: cp.parallelGroup ?? null,\n ...(cp.wakeAt == null ? {} : { wakeAt: new Date(cp.wakeAt) }),\n enqueuedAt: cp.enqueuedAt,\n startedAt: cp.startedAt,\n finishedAt: cp.finishedAt,\n };\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 parallelGroup: e.parallelGroup ?? undefined,\n wakeAt: e.wakeAt == null ? undefined : e.wakeAt.getTime(),\n // Older rows predate enqueuedAt; treat the worker start as enqueue time (queue-wait reads zero).\n enqueuedAt: e.enqueuedAt ?? e.startedAt,\n startedAt: e.startedAt,\n finishedAt: e.finishedAt,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;ACCA,qBAAoD;AAU7C,SAASA,gBAA6BC,KAAcC,OAAa;AACtE,MAAID,OAAO,KAAM,QAAOE;AAExB,MAAI,OAAOF,QAAQ,SAAU,QAAOA;AACpC,MAAI;AACF,WAAOG,KAAKC,MAAMJ,GAAAA;EACpB,SAASK,KAAK;AACZC,YAAQC,KACN,kCAAkCN,KAAAA,oCAC/BI,IAAcG,OAAO,EACtB;AAEJ,WAAON;EACT;AACF;AAdgBH;AAqBhB,SAASU,sBAAsBR,OAAa;AAC1C,SAAO;IACLS,IAAI,wBAACC,UAAoBA,SAAS,OAAO,OAAOR,KAAKS,UAAUD,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cAAcrG,EAAEsG;IAC9BA,WAAWtG,EAAEsG;IACbC,YAAYvG,EAAEuG;EAChB;AACF;AArBSjG;","names":["parseJsonColumn","raw","field","undefined","JSON","parse","err","console","warn","message","jsonColumnTransformer","to","value","stringify","from","snakeCase","property","replace","c","toLowerCase","columnNamer","naming","WorkflowRunEntity","id","workflow","workflowVersion","status","input","output","error","wakeAt","lockedBy","lockedUntil","awaitingDecisionTaskId","recoveryAttempts","tags","searchAttributes","priority","createdAt","updatedAt","StepCheckpointEntity","runId","seq","name","kind","stepId","events","attempts","workerGroup","parallelGroup","enqueuedAt","startedAt","finishedAt","RunAttributeEntity","key","strValue","numValue","SignalWaiterEntity","token","BufferedSignalEntity","payload","durableEntities","options","col","workflowRuns","EntitySchema","target","tableName","columns","type","primary","nullable","transformer","Date","stepCheckpoints","runAttributes","signalWaiters","bufferedSignals","Number","generated","ENTITIES","JSON_BLOB_COLUMNS","durable_workflow_runs","durable_step_checkpoints","TABLE_TO_ENTITY","WorkflowRunEntity","StepCheckpointEntity","durable_run_attributes","RunAttributeEntity","durable_signal_waiters","SignalWaiterEntity","durable_buffered_signals","BufferedSignalEntity","durableManagedTables","Object","keys","durableColumnResolver","dataSource","table","property","entity","Error","meta","getMetadata","column","findColumnWithPropertyName","databaseName","jsonBlobColumnType","isMysql","buildWidenStatements","quote","col","out","props","entries","prop","push","ensureTypeOrmDurableSchema","q","id","driver","escape","resolve","type","String","options","isPg","isSqlite","str","txt","int","ts","runs","checkpoints","runAttributes","waiters","buffered","runsCol","cpCol","attrCol","waiterCol","bufCol","num","bufferedId","tables","additive","runner","createQueryRunner","sql","query","have","existingColumns","colType","has","indexes","name","target","release","d","rows","Set","map","r","scope","placeholder","COLUMN_NAME","import_typeorm","TypeOrmStateStore","dataSource","ensureSchema","ensureTypeOrmDurableSchema","runs","getRepository","WorkflowRunEntity","checkpoints","StepCheckpointEntity","waiters","SignalWaiterEntity","buffered","BufferedSignalEntity","attributes","RunAttributeEntity","reindexAttributes","runId","em","repo","delete","rows","normalizeAttributeRows","length","insert","createRun","run","save","toRunEntity","id","searchAttributes","updateRun","patch","update","workflow","workflowVersion","status","input","output","error","wakeAt","Date","lockedBy","lockedUntil","awaitingDecisionTaskId","recoveryAttempts","tags","priority","createdAt","updatedAt","result","createQueryBuilder","set","where","execute","affected","Error","getRun","e","findOneBy","fromRunEntity","deleteRun","getCheckpoint","seq","fromCheckpointEntity","saveCheckpoint","checkpoint","entity","toCheckpointEntity","upsert","transaction","work","raw","cp","listIncompleteRuns","findBy","In","map","listPendingRuns","limit","find","order","take","listDueTimers","nowMs","LessThanOrEqual","tryLockRun","owner","leaseUntilMs","andWhere","Brackets","qb","IsNull","orWhere","releaseRunLock","renewRunLock","listRuns","query","statuses","tag","tagPattern","forEach","f","i","applyAttributeExists","orderBy","offset","skip","getMany","valueProperty","attributeColumnFor","cmp","sqlComparator","op","keyParam","valParam","resolve","durableColumnResolver","q","idQuote","wrap","name","runIdCol","keyCol","valueCol","runPkCol","table","a","sql","key","attributeOperand","type","String","options","listCheckpoints","getLatestCheckpointByName","findOne","undefined","listCheckpointsByNamePrefix","prefixes","p","Like","putSignalWaiter","waiter","token","parallelGroup","listSignalWaiters","prefix","takeSignalWaiter","removeSignalWaiter","bufferSignal","payload","takeBufferedSignal","getTime","kind","stepId","events","attempts","workerGroup","enqueuedAt","startedAt","finishedAt"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/entities.ts","../src/schema.ts","../src/typeorm-state-store.ts"],"sourcesContent":["export * from './entities';\nexport * from './schema';\nexport * from './typeorm-state-store';\n","import type { RunStatus, StepKind } from '@dudousxd/nestjs-durable-core';\nimport { EntitySchema, type ValueTransformer } from 'typeorm';\n\n/**\n * Safely deserialize a JSON-text column back to an object on READ.\n *\n * A column truncated by the old MySQL `text` 64KB limit (or otherwise corrupt) makes `JSON.parse`\n * throw \"Unterminated string in JSON\" — which, without this guard, would 500 the *entire* run-detail\n * read just because one blob is damaged. Instead, log once and degrade the bad field to `undefined`\n * so the rest of the run still renders. Valid JSON is unchanged.\n */\nexport function parseJsonColumn<T = unknown>(raw: unknown, field: string): T | undefined {\n if (raw == null) return undefined;\n // Some drivers (e.g. a native `json` column) already hand back a parsed object.\n if (typeof raw !== 'string') return raw as T;\n try {\n return JSON.parse(raw) as T;\n } catch (err) {\n console.warn(\n `durable store: failed to parse ${field} column, degrading to undefined: ${\n (err as Error).message\n }`,\n );\n return undefined;\n }\n}\n\n/**\n * TypeORM transformer for the free-form JSON-blob columns. Mirrors the built-in `simple-json`\n * serialization on WRITE (`JSON.stringify`, SQL NULL stays NULL) but uses {@link parseJsonColumn}\n * on READ so a single corrupt/truncated row degrades to `undefined` instead of throwing.\n */\nfunction jsonColumnTransformer(field: string): ValueTransformer {\n return {\n to: (value: unknown) => (value == null ? null : JSON.stringify(value)),\n from: (value: unknown) => parseJsonColumn(value, field),\n };\n}\n\n/**\n * How property names map to physical column names. The durable tables are adapter-agnostic: a run\n * written by one store adapter must be readable by another, so every adapter has to agree on the\n * physical column names. The default is `'snake_case'` (the canonical, matched by the MikroORM,\n * Prisma and Drizzle adapters). `'preserve'` keeps the camelCase property name verbatim (what the\n * old TypeORM/Prisma adapters produced before they were pinned). A function lets you supply any\n * custom mapping.\n *\n * The choice is pinned EXPLICITLY onto the entity schema rather than left to the host ORM's naming\n * strategy — depending on the host strategy is what silently diverged the adapters and broke a store\n * swap against an existing table.\n */\nexport type DurableColumnNaming = 'snake_case' | 'preserve' | ((property: string) => string);\n\nfunction snakeCase(property: string): string {\n return property.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);\n}\n\n/** Resolve a `DurableColumnNaming` to a `(property) => columnName` function. */\nexport function columnNamer(naming: DurableColumnNaming): (property: string) => string {\n if (naming === 'snake_case') return snakeCase;\n if (naming === 'preserve') return (property) => property;\n return naming;\n}\n\n// Plain classes (no decorators): the schema/column mapping lives on the EntitySchema built by\n// `durableEntities`, so the same class can be registered under different column names. The store\n// still references these classes for `getRepository`/`getMetadata`.\n\nexport class WorkflowRunEntity {\n id!: string;\n workflow!: string;\n workflowVersion!: string;\n status!: RunStatus;\n input?: unknown;\n output?: unknown;\n error?: unknown;\n wakeAt?: Date;\n lockedBy?: string | null;\n lockedUntil?: Date;\n awaitingDecisionTaskId?: string | null;\n recoveryAttempts?: number;\n tags?: string[] | null;\n searchAttributes?: Record<string, string | number | boolean> | null;\n priority?: number | null;\n createdAt!: Date;\n updatedAt!: Date;\n}\n\nexport class StepCheckpointEntity {\n runId!: string;\n seq!: number;\n name!: string;\n kind!: StepKind;\n stepId!: string;\n status!: 'pending' | 'running' | 'completed' | 'failed';\n input?: unknown;\n output?: unknown;\n error?: unknown;\n events?: unknown;\n attempts!: number;\n workerGroup?: string | null;\n parallelGroup?: string | null;\n wakeAt?: Date;\n enqueuedAt?: Date;\n startedAt!: 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 */\nexport class RunAttributeEntity {\n runId!: string;\n key!: string;\n strValue?: string | null;\n numValue?: number | null;\n}\n\nexport class SignalWaiterEntity {\n token!: string;\n runId!: string;\n seq!: number;\n parallelGroup?: string | null;\n}\n\nexport class BufferedSignalEntity {\n id!: number;\n token!: string;\n payload?: unknown;\n}\n\n/** A published event that matched no live waiter (see `engine.publishEvent`'s buffering). Keyed by a\n * caller-minted `id` (a uuid, not autoincrement — `removeBufferedEvent` targets it directly), not by\n * `runId`: events are name-based pub/sub, not tied to any one run. */\nexport class BufferedEventEntity {\n id!: string;\n name!: string;\n payload?: unknown;\n publishedAt!: Date;\n}\n\n/**\n * Build the durable TypeORM entity schemas with column names pinned per `naming` (default\n * `'snake_case'`). Register the result in your `DataSource`/`TypeOrmModule.forFeature`. The JSON-blob\n * columns keep the `jsonColumnTransformer` (corruption-tolerant read), the primary keys / auto-\n * increment / nullability are preserved, and the `id` of `durable_buffered_signals` stays a driver-\n * native auto-increment column.\n *\n * ```ts\n * entities: durableEntities({ naming: 'snake_case' })\n * ```\n */\nexport function durableEntities(options: { naming?: DurableColumnNaming } = {}): EntitySchema[] {\n const col = columnNamer(options.naming ?? 'snake_case');\n\n const workflowRuns = new EntitySchema<WorkflowRunEntity>({\n name: 'WorkflowRunEntity',\n target: WorkflowRunEntity,\n tableName: 'durable_workflow_runs',\n columns: {\n id: { type: 'text', primary: true, name: col('id') },\n workflow: { type: 'text', name: col('workflow') },\n workflowVersion: { type: 'text', name: col('workflowVersion') },\n status: { type: 'text', name: col('status') },\n input: {\n type: 'text',\n nullable: true,\n name: col('input'),\n transformer: jsonColumnTransformer('runs.input'),\n },\n output: {\n type: 'text',\n nullable: true,\n name: col('output'),\n transformer: jsonColumnTransformer('runs.output'),\n },\n error: {\n type: 'text',\n nullable: true,\n name: col('error'),\n transformer: jsonColumnTransformer('runs.error'),\n },\n wakeAt: { type: Date, nullable: true, name: col('wakeAt') },\n lockedBy: { type: 'text', nullable: true, name: col('lockedBy') },\n lockedUntil: { type: Date, nullable: true, name: col('lockedUntil') },\n // REMOTE turn the engine suspended on awaiting a decision; matched by completeRemoteDecision so\n // only the currently-awaited turn's decision is applied. Nullable: cleared when a decision lands.\n awaitingDecisionTaskId: {\n type: 'text',\n nullable: true,\n name: col('awaitingDecisionTaskId'),\n },\n recoveryAttempts: { type: 'integer', nullable: true, name: col('recoveryAttempts') },\n tags: {\n type: 'text',\n nullable: true,\n name: col('tags'),\n transformer: jsonColumnTransformer('runs.tags'),\n },\n searchAttributes: {\n type: 'text',\n nullable: true,\n name: col('searchAttributes'),\n transformer: jsonColumnTransformer('runs.searchAttributes'),\n },\n priority: { type: 'integer', nullable: true, name: col('priority') },\n createdAt: { type: Date, name: col('createdAt') },\n updatedAt: { type: Date, name: col('updatedAt') },\n },\n });\n\n const stepCheckpoints = new EntitySchema<StepCheckpointEntity>({\n name: 'StepCheckpointEntity',\n target: StepCheckpointEntity,\n tableName: 'durable_step_checkpoints',\n columns: {\n runId: { type: 'text', primary: true, name: col('runId') },\n seq: { type: 'integer', primary: true, name: col('seq') },\n name: { type: 'text', name: col('name') },\n kind: { type: 'text', name: col('kind') },\n stepId: { type: 'text', name: col('stepId') },\n status: { type: 'text', name: col('status') },\n input: {\n type: 'text',\n nullable: true,\n name: col('input'),\n transformer: jsonColumnTransformer('checkpoints.input'),\n },\n output: {\n type: 'text',\n nullable: true,\n name: col('output'),\n transformer: jsonColumnTransformer('checkpoints.output'),\n },\n error: {\n type: 'text',\n nullable: true,\n name: col('error'),\n transformer: jsonColumnTransformer('checkpoints.error'),\n },\n events: {\n type: 'text',\n nullable: true,\n name: col('events'),\n transformer: jsonColumnTransformer('checkpoints.events'),\n },\n attempts: { type: 'integer', name: col('attempts') },\n workerGroup: { type: 'text', nullable: true, name: col('workerGroup') },\n // A ctx.gather/ctx.all fan tags every sibling step with the same group so the dashboard renders\n // them as one parallel group; the core engine sets it (incl. from a remote worker's recordStep).\n parallelGroup: { type: 'text', nullable: true, name: col('parallelGroup') },\n wakeAt: { type: Date, nullable: true, name: col('wakeAt') },\n enqueuedAt: { type: Date, nullable: true, name: col('enqueuedAt') },\n startedAt: { type: Date, name: col('startedAt') },\n finishedAt: { type: Date, name: col('finishedAt') },\n },\n });\n\n const runAttributes = new EntitySchema<RunAttributeEntity>({\n name: 'RunAttributeEntity',\n target: RunAttributeEntity,\n tableName: 'durable_run_attributes',\n columns: {\n runId: { type: 'text', primary: true, name: col('runId') },\n key: { type: 'text', primary: true, name: col('key') },\n strValue: { type: 'text', nullable: true, name: col('strValue') },\n // `float`/`double` portable across SQLite/MySQL/Postgres for numeric range scans.\n numValue: { type: 'float', nullable: true, name: col('numValue') },\n },\n });\n\n const signalWaiters = new EntitySchema<SignalWaiterEntity>({\n name: 'SignalWaiterEntity',\n target: SignalWaiterEntity,\n tableName: 'durable_signal_waiters',\n columns: {\n token: { type: 'text', primary: true, name: col('token') },\n runId: { type: 'text', name: col('runId') },\n seq: { type: 'integer', name: col('seq') },\n // A ctx.gather_children/ctx.all child fan-out tags every awaited child with the same group; the\n // engine threads it onto the waiter so the resolving `signal:child:` checkpoint carries it and the\n // dashboard renders the fan as one parallel group. Nullable: only fan-out child waiters carry it.\n parallelGroup: { type: 'text', nullable: true, name: col('parallelGroup') },\n },\n });\n\n const bufferedSignals = new EntitySchema<BufferedSignalEntity>({\n name: 'BufferedSignalEntity',\n target: BufferedSignalEntity,\n tableName: 'durable_buffered_signals',\n columns: {\n // Auto-increment PK for FIFO ordering. Left as TypeORM's default increment generation so it\n // maps to the driver-native auto-increment column (INTEGER on SQLite, BIGINT/SERIAL elsewhere).\n id: { type: Number, primary: true, generated: 'increment', name: col('id') },\n token: { type: 'text', name: col('token') },\n payload: {\n type: 'text',\n nullable: true,\n name: col('payload'),\n transformer: jsonColumnTransformer('buffered.payload'),\n },\n },\n });\n\n const bufferedEvents = new EntitySchema<BufferedEventEntity>({\n name: 'BufferedEventEntity',\n target: BufferedEventEntity,\n tableName: 'durable_buffered_events',\n // No `indices` here (unlike MikroORM's EntitySchema, which does declare one): this store manages\n // its DDL — including the `(name, publishedAt)` index — via raw SQL in `schema.ts`'s\n // `ensureTypeOrmDurableSchema`, the same as every other durable_* table's indexes.\n columns: {\n // Caller-minted uuid (engine.publishEvent), not autoincrement — removeBufferedEvent targets it\n // directly and needs to be handed the SAME id it was buffered with.\n id: { type: 'text', primary: true, name: col('id') },\n name: { type: 'text', name: col('name') },\n payload: {\n type: 'text',\n nullable: true,\n name: col('payload'),\n transformer: jsonColumnTransformer('buffered.eventPayload'),\n },\n publishedAt: { type: Date, name: col('publishedAt') },\n },\n });\n\n return [\n workflowRuns,\n stepCheckpoints,\n runAttributes,\n signalWaiters,\n bufferedSignals,\n bufferedEvents,\n ];\n}\n\n/** Durable entity schemas with the canonical `'snake_case'` column names. */\nexport const ENTITIES = durableEntities();\n","import type { DataSource } from 'typeorm';\nimport {\n BufferedEventEntity,\n BufferedSignalEntity,\n RunAttributeEntity,\n SignalWaiterEntity,\n StepCheckpointEntity,\n WorkflowRunEntity,\n} from './entities';\n\n/** The JSON-blob columns per table (keyed by table name) that hold free-form payloads and so must\n * be the unbounded text type — `longtext` on MySQL, `text` elsewhere. Keyed by entity PROPERTY name;\n * the physical column is resolved from the DataSource metadata so it tracks the configured naming. */\nexport const JSON_BLOB_COLUMNS: Record<string, string[]> = {\n durable_workflow_runs: ['input', 'output', 'error', 'tags', 'searchAttributes'],\n durable_step_checkpoints: ['input', 'output', 'error', 'events'],\n // NOTE: durable_buffered_signals/durable_buffered_events intentionally omitted here, same as the\n // existing buffered-signals table — their `payload` column is created with the widened `txt` type\n // (see `${bufCol('payload')} ${txt}` / the new table's `${bevCol('payload')} ${txt}` below) directly\n // at CREATE TABLE time on a fresh install, so there's no pre-existing narrower column to widen.\n};\n\n/** Each durable table → its backing entity class, so a column resolver can look up the physical\n * column for any (table, property) from the DataSource metadata (which reflects the configured\n * `DurableColumnNaming`). Keeps the raw DDL/SQL in lock-step with the entity column mapping. */\nconst TABLE_TO_ENTITY = {\n durable_workflow_runs: WorkflowRunEntity,\n durable_step_checkpoints: StepCheckpointEntity,\n durable_run_attributes: RunAttributeEntity,\n durable_signal_waiters: SignalWaiterEntity,\n durable_buffered_signals: BufferedSignalEntity,\n durable_buffered_events: BufferedEventEntity,\n} as const;\n\n/**\n * Tables this store creates and manages at boot (autoSchema, see {@link ensureTypeOrmDurableSchema}).\n * Feed to your ORM's migration differ exclude/skipTables so it never tries to drop them.\n *\n * ```ts\n * // MikroORM-flavoured example (TypeORM has no built-in equivalent option); adapt to whichever\n * // migration tool generates your diffs — e.g. exclude these names from a typeorm-generated\n * // migration, or filter them out of `SELECT table_name FROM information_schema.tables` before\n * // diffing against your own entities.\n * const skipTables = new Set(durableManagedTables());\n * ```\n *\n * Derived from the same {@link TABLE_TO_ENTITY} map the raw-SQL heal keys its column resolution off\n * — one list, so a consumer's denylist can never drift from what this store actually owns.\n */\nexport function durableManagedTables(): string[] {\n return Object.keys(TABLE_TO_ENTITY);\n}\n\n/**\n * Resolve `(table, property) => physical column name` from the DataSource's entity metadata. The\n * column names are NOT hardcoded here: they come from whatever the registered `durableEntities`\n * mapped (canonical `snake_case` by default, `'preserve'` for the legacy camelCase, or a custom\n * mapping), so the raw `CREATE TABLE`/index/EXISTS SQL always matches the entities and can never\n * silently diverge.\n */\nexport function durableColumnResolver(\n dataSource: DataSource,\n): (table: string, property: string) => string {\n return (table, property) => {\n const entity = TABLE_TO_ENTITY[table as keyof typeof TABLE_TO_ENTITY];\n if (!entity) throw new Error(`durable store: unknown table \"${table}\"`);\n const meta = dataSource.getMetadata(entity);\n const column = meta.findColumnWithPropertyName(property);\n if (!column) {\n throw new Error(`durable store: no column for ${table}.${property} in entity metadata`);\n }\n return column.databaseName;\n };\n}\n\n/** The SQL type for free-form JSON-blob columns. MySQL `text` caps at 64KB and silently truncates,\n * so use `longtext` (4GB) there; Postgres/SQLite `text` is already unbounded. */\nexport function jsonBlobColumnType(isMysql: boolean): 'longtext' | 'text' {\n return isMysql ? 'longtext' : 'text';\n}\n\n/** Idempotent `MODIFY COLUMN ... longtext` statements that widen pre-existing MySQL `text` JSON-blob\n * columns. Returns `[]` on non-MySQL dialects (their `text` is already unbounded — nothing to do).\n * `quote` quotes an identifier per the active driver; `col` resolves a property to its physical\n * column name so the widen tracks the configured naming. */\nexport function buildWidenStatements(\n isMysql: boolean,\n quote: (id: string) => string,\n col: (table: string, property: string) => string,\n): string[] {\n if (!isMysql) return [];\n const out: string[] = [];\n for (const [table, props] of Object.entries(JSON_BLOB_COLUMNS)) {\n for (const prop of props) {\n out.push(`ALTER TABLE ${quote(table)} MODIFY COLUMN ${quote(col(table, prop))} longtext`);\n }\n }\n return out;\n}\n\n/**\n * Idempotently create the durable tables. Safe to run on every boot (auto-schema) and the\n * exact function to call from your own TypeORM migration when you disable auto-schema:\n *\n * ```ts\n * export class AddDurableTables implements MigrationInterface {\n * async up(q: QueryRunner) { await ensureTypeOrmDurableSchema(q.connection); }\n * }\n * ```\n *\n * Dialect-aware (MySQL / MariaDB / Postgres / SQLite): identifiers are quoted per driver, keyed\n * string columns are `varchar` (MySQL can't key a `text` column), and the index is best-effort.\n * Only ever adds the three durable tables — it never touches your other tables.\n */\nexport async function ensureTypeOrmDurableSchema(dataSource: DataSource): Promise<void> {\n const q = (id: string) => dataSource.driver.escape(id);\n // Physical column names come from the entity metadata (canonical snake_case by default), so this\n // raw DDL always matches the registered `durableEntities` instead of hardcoding camelCase.\n const resolve = durableColumnResolver(dataSource);\n const type = String(dataSource.options.type);\n const isPg = type === 'postgres' || type === 'aurora-postgres';\n const isMysql = type === 'mysql' || type === 'mariadb' || type === 'aurora-mysql';\n const isSqlite = type === 'sqlite' || type === 'better-sqlite3' || type === 'expo';\n\n // Keyed/short strings must be varchar on MySQL (a `text` PK/index needs a key length); `text`\n // for the free-form JSON payloads. Dates use the dialect's native timestamp type.\n const str = 'varchar(191)';\n // Free-form JSON payloads (`input`/`output`/`error`/`events`/`tags`/`searchAttributes`). MySQL's\n // `text` caps at 64KB and *silently truncates* — a large fan-out step's `events` then fails to\n // parse on read (\"Unterminated string in JSON\"). Use `longtext` (4GB) on MySQL; Postgres `text`\n // is already unbounded and SQLite `text` has no length limit.\n const txt = jsonBlobColumnType(isMysql);\n const int = isMysql ? 'int' : 'integer';\n const ts = isPg ? 'timestamptz' : 'datetime';\n\n const runs = q('durable_workflow_runs');\n const checkpoints = q('durable_step_checkpoints');\n const runAttributes = q('durable_run_attributes');\n const waiters = q('durable_signal_waiters');\n const buffered = q('durable_buffered_signals');\n const bufferedEvents = q('durable_buffered_events');\n // Per-table quoted-column helpers: resolve an entity property to its physical column then quote it.\n const runsCol = (property: string) => q(resolve('durable_workflow_runs', property));\n const cpCol = (property: string) => q(resolve('durable_step_checkpoints', property));\n const attrCol = (property: string) => q(resolve('durable_run_attributes', property));\n const waiterCol = (property: string) => q(resolve('durable_signal_waiters', property));\n const bufCol = (property: string) => q(resolve('durable_buffered_signals', property));\n const bevCol = (property: string) => q(resolve('durable_buffered_events', property));\n // Numeric side-table column for attribute range scans. `double precision` on Postgres, `double` on\n // MySQL, `real` on SQLite (all hold JS numbers without precision loss for the typical attribute).\n const num = isPg ? 'double precision' : isMysql ? 'double' : 'real';\n\n // Auto-increment PK syntax differs per dialect: SQLite wants `INTEGER PRIMARY KEY AUTOINCREMENT`,\n // MySQL `BIGINT AUTO_INCREMENT PRIMARY KEY`, Postgres `BIGSERIAL PRIMARY KEY`.\n const bufferedId = isSqlite\n ? `${bufCol('id')} integer PRIMARY KEY AUTOINCREMENT`\n : isMysql\n ? `${bufCol('id')} bigint NOT NULL AUTO_INCREMENT PRIMARY KEY`\n : isPg\n ? `${bufCol('id')} bigserial PRIMARY KEY`\n : `${bufCol('id')} bigint NOT NULL AUTO_INCREMENT PRIMARY KEY`;\n\n const tables = [\n `CREATE TABLE IF NOT EXISTS ${runs} (\n ${runsCol('id')} ${str} PRIMARY KEY,\n ${runsCol('workflow')} ${str} NOT NULL,\n ${runsCol('workflowVersion')} ${str} NOT NULL,\n ${runsCol('status')} ${str} NOT NULL,\n ${runsCol('input')} ${txt}, ${runsCol('output')} ${txt}, ${runsCol('error')} ${txt},\n ${runsCol('wakeAt')} ${ts}, ${runsCol('lockedBy')} ${str}, ${runsCol('lockedUntil')} ${ts},\n ${runsCol('awaitingDecisionTaskId')} ${str},\n ${runsCol('recoveryAttempts')} ${int}, ${runsCol('tags')} ${txt}, ${runsCol('searchAttributes')} ${txt},\n ${runsCol('priority')} ${int},\n ${runsCol('createdAt')} ${ts} NOT NULL, ${runsCol('updatedAt')} ${ts} NOT NULL\n )`,\n `CREATE TABLE IF NOT EXISTS ${checkpoints} (\n ${cpCol('runId')} ${str} NOT NULL, ${cpCol('seq')} ${int} NOT NULL,\n ${cpCol('name')} ${str} NOT NULL, ${cpCol('kind')} ${str} NOT NULL, ${cpCol('stepId')} ${str} NOT NULL,\n ${cpCol('status')} ${str} NOT NULL, ${cpCol('input')} ${txt}, ${cpCol('output')} ${txt}, ${cpCol('error')} ${txt}, ${cpCol('events')} ${txt},\n ${cpCol('attempts')} ${int} NOT NULL, ${cpCol('workerGroup')} ${str}, ${cpCol('parallelGroup')} ${str},\n ${cpCol('wakeAt')} ${ts}, ${cpCol('enqueuedAt')} ${ts},\n ${cpCol('startedAt')} ${ts} NOT NULL, ${cpCol('finishedAt')} ${ts} NOT NULL,\n PRIMARY KEY (${cpCol('runId')}, ${cpCol('seq')})\n )`,\n // Normalized search-attribute side-table: one row per (run, key) so attribute predicates push\n // DOWN into SQL via an EXISTS join (indexed below). `key` is keyed → must be varchar on MySQL.\n `CREATE TABLE IF NOT EXISTS ${runAttributes} (\n ${attrCol('runId')} ${str} NOT NULL, ${attrCol('key')} ${str} NOT NULL,\n ${attrCol('strValue')} ${str}, ${attrCol('numValue')} ${num},\n PRIMARY KEY (${attrCol('runId')}, ${attrCol('key')})\n )`,\n `CREATE TABLE IF NOT EXISTS ${waiters} (\n ${waiterCol('token')} ${str} PRIMARY KEY, ${waiterCol('runId')} ${str} NOT NULL, ${waiterCol('seq')} ${int} NOT NULL,\n ${waiterCol('parallelGroup')} ${str}\n )`,\n `CREATE TABLE IF NOT EXISTS ${buffered} (\n ${bufferedId}, ${bufCol('token')} ${str} NOT NULL, ${bufCol('payload')} ${txt}\n )`,\n // Caller-minted uuid PK (engine.publishEvent), not auto-increment — unlike durable_buffered_signals\n // above, removeBufferedEvent needs to target the EXACT id it was buffered with.\n `CREATE TABLE IF NOT EXISTS ${bufferedEvents} (\n ${bevCol('id')} ${str} PRIMARY KEY, ${bevCol('name')} ${str} NOT NULL,\n ${bevCol('payload')} ${txt}, ${bevCol('publishedAt')} ${ts} NOT NULL\n )`,\n ];\n\n // Additive nullable columns gained across versions (e.g. `input`, `events`, `enqueuedAt`). On a\n // table that predates them, `CREATE TABLE IF NOT EXISTS` above is a no-op, so back-fill the ones\n // that are actually missing — the auto-schema self-heals instead of needing a manual migration.\n // We check the live columns first (rather than ALTER-and-ignore) so a *real* ALTER failure\n // surfaces instead of being swallowed as a presumed \"column already exists\".\n // Keyed by entity PROPERTY name; the physical column is resolved per-table so the ADD COLUMN\n // tracks the configured naming.\n const additive: Record<string, Array<[string, string]>> = {\n durable_workflow_runs: [\n ['input', txt],\n ['output', txt],\n ['error', txt],\n ['awaitingDecisionTaskId', str],\n ['recoveryAttempts', int],\n ['tags', txt],\n ['searchAttributes', txt],\n ['priority', int],\n ],\n durable_step_checkpoints: [\n ['input', txt],\n ['output', txt],\n ['error', txt],\n ['events', txt],\n ['workerGroup', str],\n ['parallelGroup', str],\n ['enqueuedAt', ts],\n ],\n // Back-fill the child-await fan group onto signal-waiter tables that predate it (a remote\n // `gather_children` fan-out threads its group here so the resolved `signal:child:` checkpoint carries it).\n durable_signal_waiters: [['parallelGroup', str]],\n };\n\n const runner = dataSource.createQueryRunner();\n try {\n for (const sql of tables) await runner.query(sql);\n for (const [table, props] of Object.entries(additive)) {\n const have = await existingColumns(runner, table, { isSqlite, isMysql });\n for (const [property, colType] of props) {\n const column = resolve(table, property);\n if (!have.has(column)) {\n await runner.query(`ALTER TABLE ${q(table)} ADD COLUMN ${q(column)} ${colType}`);\n }\n }\n }\n // Widen pre-existing MySQL `text` JSON-blob columns to `longtext`. A table created before this\n // fix has these as `text` (64KB) and silently truncates large `events`/`output` payloads. MODIFY\n // to `longtext` is idempotent (no-op if already longtext), so it's safe to run on every boot.\n // MySQL-only: Postgres/SQLite `text` is already unbounded, so there's nothing to widen.\n for (const sql of buildWidenStatements(isMysql, q, resolve)) {\n try {\n await runner.query(sql);\n } catch {\n /* column already longtext, or table/column not present on this deploy */\n }\n }\n // MySQL has no `CREATE INDEX IF NOT EXISTS`; create each best-effort and ignore \"already exists\".\n // - status/wakeAt: the timer poller (listDueTimers) and recovery (listIncompleteRuns) scans.\n // - workflow/status: the dashboard's listRuns filters. (Checkpoints are keyed by the PK prefix\n // `(runId, seq)`, so listCheckpoints/getEvent already hit an index — no extra one needed.)\n const indexes: Array<[string, string]> = [\n ['durable_runs_status_idx', `${runs} (${runsCol('status')}, ${runsCol('wakeAt')})`],\n [\n 'durable_runs_workflow_status_idx',\n `${runs} (${runsCol('workflow')}, ${runsCol('status')})`,\n ],\n // buffered signals are taken FIFO per token (smallest id) — index the token for the scan.\n ['durable_buffered_signals_token_idx', `${buffered} (${bufCol('token')})`],\n // buffered events are scanned oldest-first per name — one composite index serves both.\n [\n 'durable_buffered_events_name_published_at_idx',\n `${bufferedEvents} (${bevCol('name')}, ${bevCol('publishedAt')})`,\n ],\n // Search-attribute pushdown: equality + range predicates probe by (key, value). Two composite\n // indexes — one per typed column — so a numeric range or a string equality is an index scan.\n [\n 'durable_run_attributes_num_idx',\n `${runAttributes} (${attrCol('key')}, ${attrCol('numValue')})`,\n ],\n [\n 'durable_run_attributes_str_idx',\n `${runAttributes} (${attrCol('key')}, ${attrCol('strValue')})`,\n ],\n ];\n for (const [name, target] of indexes) {\n try {\n await runner.query(`CREATE INDEX ${q(name)} ON ${target}`);\n } catch {\n /* index already exists */\n }\n }\n } finally {\n await runner.release();\n }\n}\n\n/** The columns that currently exist on `table`, so the schema can add only the missing ones\n * (instead of ALTER-and-swallow, which would also hide a genuine ALTER failure). */\nasync function existingColumns(\n runner: { query: (sql: string, params?: unknown[]) => Promise<unknown> },\n table: string,\n d: { isSqlite: boolean; isMysql: boolean },\n): Promise<Set<string>> {\n if (d.isSqlite) {\n const rows = (await runner.query(`PRAGMA table_info(\"${table}\")`)) as Array<{ name: string }>;\n return new Set(rows.map((r) => r.name));\n }\n // Postgres + MySQL both expose information_schema; scope to the connection's own schema/db.\n // Bind-param placeholder differs: Postgres uses `$1`, MySQL uses `?` (TypeORM only rewrites `?`\n // inside the query builder, not for these raw `runner.query` calls), so pick per dialect.\n const scope = d.isMysql ? 'TABLE_SCHEMA = DATABASE()' : 'table_schema = current_schema()';\n const placeholder = d.isMysql ? '?' : '$1';\n const rows = (await runner.query(\n `SELECT column_name AS name FROM information_schema.columns WHERE table_name = ${placeholder} AND ${scope}`,\n [table],\n )) as Array<{ name?: string; COLUMN_NAME?: string }>;\n return new Set(rows.map((r) => (r.name ?? r.COLUMN_NAME) as string));\n}\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 {\n Brackets,\n type DataSource,\n type EntityManager,\n In,\n IsNull,\n LessThanOrEqual,\n Like,\n type SelectQueryBuilder,\n} from 'typeorm';\nimport type { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';\nimport {\n BufferedEventEntity,\n BufferedSignalEntity,\n RunAttributeEntity,\n SignalWaiterEntity,\n StepCheckpointEntity,\n WorkflowRunEntity,\n} from './entities';\nimport { durableColumnResolver, ensureTypeOrmDurableSchema } from './schema';\n\n/**\n * TypeORM-backed `StateStore`. Works on any TypeORM driver — Postgres, MySQL, SQLite (tested);\n * timestamps use native datetime columns and `wakeAt` is stored as a datetime too.\n */\nexport class TypeOrmStateStore implements StateStore {\n constructor(private readonly dataSource: DataSource) {}\n\n async ensureSchema(): Promise<void> {\n await ensureTypeOrmDurableSchema(this.dataSource);\n }\n\n private runs() {\n return this.dataSource.getRepository(WorkflowRunEntity);\n }\n private checkpoints() {\n return this.dataSource.getRepository(StepCheckpointEntity);\n }\n private waiters() {\n return this.dataSource.getRepository(SignalWaiterEntity);\n }\n private buffered() {\n return this.dataSource.getRepository(BufferedSignalEntity);\n }\n private bufferedEvents() {\n return this.dataSource.getRepository(BufferedEventEntity);\n }\n private attributes() {\n return this.dataSource.getRepository(RunAttributeEntity);\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 em?: EntityManager,\n ): Promise<void> {\n const repo = em ? em.getRepository(RunAttributeEntity) : this.attributes();\n await repo.delete({ runId });\n const rows = normalizeAttributeRows(runId, attributes);\n if (rows.length) await repo.insert(rows);\n }\n\n async createRun(run: WorkflowRun): Promise<void> {\n await this.runs().save(toRunEntity(run));\n await this.reindexAttributes(run.id, run.searchAttributes);\n }\n\n async updateRun(runId: string, patch: Partial<WorkflowRun>): Promise<void> {\n // Single UPDATE (no pre-SELECT + save round-trips): map only the patched fields. The query\n // builder still applies the entities' JSON column transformers to the `set` values (as in\n // listRuns/tryLockRun). Preserve the not-found throw any caller may rely on.\n const update: Record<string, unknown> = {};\n if ('workflow' in patch) update.workflow = patch.workflow;\n if ('workflowVersion' in patch) update.workflowVersion = patch.workflowVersion;\n if ('status' in patch) update.status = patch.status;\n if ('input' in patch) update.input = patch.input ?? null;\n if ('output' in patch) update.output = patch.output ?? null;\n if ('error' in patch) update.error = patch.error ?? null;\n if ('wakeAt' in patch) update.wakeAt = patch.wakeAt == null ? null : new Date(patch.wakeAt);\n if ('lockedBy' in patch) update.lockedBy = patch.lockedBy ?? null;\n if ('lockedUntil' in patch)\n update.lockedUntil = patch.lockedUntil == null ? null : new Date(patch.lockedUntil);\n if ('awaitingDecisionTaskId' in patch)\n update.awaitingDecisionTaskId = patch.awaitingDecisionTaskId ?? null;\n if ('recoveryAttempts' in patch) update.recoveryAttempts = patch.recoveryAttempts;\n if ('tags' in patch) update.tags = patch.tags ?? null;\n if ('searchAttributes' in patch) update.searchAttributes = patch.searchAttributes ?? null;\n if ('priority' in patch) update.priority = patch.priority ?? null;\n if ('createdAt' in patch) update.createdAt = patch.createdAt;\n if ('updatedAt' in patch) update.updatedAt = patch.updatedAt;\n const result = await this.runs()\n .createQueryBuilder()\n .update()\n .set(update)\n .where({ id: runId })\n .execute();\n if (!result.affected) throw new Error(`run ${runId} not found`);\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 async getRun(runId: string): Promise<WorkflowRun | null> {\n const e = await this.runs().findOneBy({ id: runId });\n return e ? fromRunEntity(e) : null;\n }\n\n async deleteRun(runId: string): Promise<void> {\n // Child rows first, then the run — checkpoints, signal waiters, attribute rows.\n await this.checkpoints().delete({ runId });\n await this.waiters().delete({ runId });\n await this.attributes().delete({ runId });\n await this.runs().delete({ id: runId });\n }\n\n async getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null> {\n const e = await this.checkpoints().findOneBy({ runId, seq });\n return e ? fromCheckpointEntity(e) : null;\n }\n\n async saveCheckpoint(checkpoint: StepCheckpoint): Promise<void> {\n // upsert = INSERT ... ON CONFLICT DO UPDATE on the (runId, seq) key — drops the pre-SELECT that\n // `.save()` does on each write. JSON column transformers still apply for upsert.\n const entity = toCheckpointEntity(checkpoint) as QueryDeepPartialEntity<StepCheckpointEntity>;\n await this.checkpoints().upsert(entity, ['runId', 'seq']);\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.dataSource.transaction(async (em) =>\n work({\n raw: em,\n saveCheckpoint: async (cp) => {\n await em.getRepository(StepCheckpointEntity).save(toCheckpointEntity(cp));\n },\n }),\n );\n }\n\n async listIncompleteRuns(): Promise<WorkflowRun[]> {\n const rows = await this.runs().findBy({ status: In(['running', 'cancelling']) });\n return rows.map(fromRunEntity);\n }\n\n async listPendingRuns(limit: number): Promise<WorkflowRun[]> {\n const rows = await this.runs().find({\n where: { status: 'pending' },\n order: { createdAt: 'ASC' }, // FIFO dispatch\n take: limit,\n });\n return rows.map(fromRunEntity);\n }\n\n async listDueTimers(nowMs: number): Promise<WorkflowRun[]> {\n const rows = await this.runs().findBy({\n status: 'suspended',\n wakeAt: LessThanOrEqual(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 result = await this.runs()\n .createQueryBuilder()\n .update()\n .set({ lockedBy: owner, lockedUntil: new Date(leaseUntilMs) })\n .where({ id: runId })\n .andWhere(\n new Brackets((qb) =>\n qb\n .where({ lockedUntil: IsNull() })\n .orWhere({ lockedUntil: LessThanOrEqual(new Date(nowMs)) }),\n ),\n )\n .execute();\n return result.affected === 1;\n }\n\n async releaseRunLock(runId: string): Promise<void> {\n await this.runs().update({ id: runId }, { lockedBy: null, lockedUntil: () => 'NULL' });\n }\n\n async renewRunLock(runId: string, owner: string, leaseUntilMs: number): Promise<boolean> {\n const result = await this.runs()\n .createQueryBuilder()\n .update()\n .set({ lockedUntil: new Date(leaseUntilMs) })\n .where({ id: runId, lockedBy: owner })\n .execute();\n return result.affected === 1;\n }\n\n async listRuns(query: RunQuery): Promise<WorkflowRun[]> {\n // `tags` carries a custom JSON transformer, and TypeORM applies a column transformer's `to()` to\n // FindOperator values too — so a `Like('%\"etl\"%')` in a plain `where` would be JSON-stringified\n // and corrupt the LIKE pattern. Use the query builder with a raw parameter to bypass that.\n const qb = this.runs().createQueryBuilder('r');\n if (query.workflow) qb.andWhere('r.workflow = :workflow', { workflow: query.workflow });\n if (query.status) qb.andWhere('r.status = :status', { status: query.status });\n if (query.statuses)\n qb.andWhere(\n query.statuses.length ? 'r.status IN (:...statuses)' : '1 = 0',\n query.statuses.length ? { statuses: query.statuses } : {},\n );\n // `tags` is a JSON-text column; match the quoted token so `etl` doesn't match `etl-foo`. NOTE: a\n // leading-wildcard LIKE on JSON text is NOT index-friendly (no B-tree index can serve `%\"x\"%`), so\n // tag-filtered scans (e.g. singleton admission) are sequential over `durable_runs_workflow_status_idx`'s\n // result set. The `statuses`/`workflow` predicates above bound that scan; if tag scans ever dominate,\n // promote tags to a normalized join table or a JSON/GIN index — a schema change, intentionally not done here.\n if (query.tag) qb.andWhere('r.tags LIKE :tagPattern', { tagPattern: `%\"${query.tag}\"%` });\n // Typed/range attribute predicates push DOWN into SQL: each filter becomes an EXISTS against the\n // normalized `durable_run_attributes` side-table (indexed on (key, numValue)/(key, strValue)), so\n // the DB does the filtering AND the LIMIT/OFFSET — no full scan + in-process filter. ANDed: a run\n // must satisfy every filter, so one EXISTS per filter.\n if (query.attributes?.length) {\n query.attributes.forEach((f, i) => this.applyAttributeExists(qb, f, i));\n }\n qb.orderBy('r.createdAt', 'DESC'); // newest first — recent runs on top in the dashboard\n if (query.limit != null) qb.take(query.limit);\n if (query.offset != null) qb.skip(query.offset);\n const rows = await qb.getMany();\n return rows.map(fromRunEntity);\n }\n\n /** Add one attribute predicate to `qb` as an EXISTS subquery on the side-table. `i` namespaces the\n * bind params so multiple ANDed filters don't collide. */\n private applyAttributeExists(\n qb: SelectQueryBuilder<WorkflowRunEntity>,\n f: AttributeFilter,\n i: number,\n ): void {\n const valueProperty = attributeColumnFor(f); // 'numValue' | 'strValue' (entity property)\n const cmp = sqlComparator(f.op);\n const keyParam = `attrKey${i}`;\n const valParam = `attrVal${i}`;\n // Resolve the PHYSICAL column names from the entity metadata so this raw subquery tracks the\n // configured naming (canonical snake_case by default) instead of hardcoding camelCase — which\n // would break the EXISTS pushdown the moment the table is snake_case.\n const resolve = durableColumnResolver(this.dataSource);\n const q = this.idQuote();\n const wrap = (name: string) => `${q}${name}${q}`;\n const runIdCol = wrap(resolve('durable_run_attributes', 'runId'));\n const keyCol = wrap(resolve('durable_run_attributes', 'key'));\n const valueCol = wrap(resolve('durable_run_attributes', valueProperty));\n const runPkCol = wrap(resolve('durable_workflow_runs', 'id'));\n const table = wrap('durable_run_attributes');\n // `<>` (ne) must also exclude rows where the attribute is absent: the missing-key-never-matches\n // contract (see core matchesAttributes). EXISTS already requires the key row to be present, and a\n // row only exists when the value is non-null, so EXISTS(... <> ...) gives exactly ne-with-present.\n const a = `a${i}`;\n const sql = `EXISTS (SELECT 1 FROM ${table} ${a} WHERE ${a}.${runIdCol} = r.${runPkCol} AND ${a}.${keyCol} = :${keyParam} AND ${a}.${valueCol} ${cmp} :${valParam})`;\n qb.andWhere(sql, {\n [keyParam]: f.key,\n [valParam]: attributeOperand(f),\n });\n }\n\n /** The identifier quote char for the active driver (MySQL backtick, others double-quote). */\n private idQuote(): string {\n const type = String(this.dataSource.options.type);\n return type === 'mysql' || type === 'mariadb' || type === 'aurora-mysql' ? '`' : '\"';\n }\n\n async listCheckpoints(runId: string): Promise<StepCheckpoint[]> {\n const rows = await this.checkpoints().find({ where: { runId }, order: { seq: 'ASC' } });\n return rows.map(fromCheckpointEntity);\n }\n\n async getLatestCheckpointByName(\n runId: string,\n name: string,\n ): Promise<StepCheckpoint | undefined> {\n const e = await this.checkpoints().findOne({ where: { runId, name }, order: { seq: 'DESC' } });\n return e ? fromCheckpointEntity(e) : undefined;\n }\n\n async listCheckpointsByNamePrefix(runId: string, prefixes: string[]): Promise<StepCheckpoint[]> {\n if (prefixes.length === 0) return [];\n const rows = await this.checkpoints().find({\n where: prefixes.map((p) => ({ runId, name: Like(`${p}%`) })),\n order: { seq: 'ASC' },\n });\n return rows.map(fromCheckpointEntity);\n }\n\n async putSignalWaiter(waiter: SignalWaiter): Promise<void> {\n await this.waiters().save({\n token: waiter.token,\n runId: waiter.runId,\n seq: waiter.seq,\n parallelGroup: waiter.parallelGroup ?? null,\n });\n }\n\n async listSignalWaiters(prefix: string): Promise<SignalWaiter[]> {\n const rows = await this.waiters().find({ where: { token: Like(`${prefix}%`) } });\n return rows.map((e) => ({\n token: e.token,\n runId: e.runId,\n seq: e.seq,\n parallelGroup: e.parallelGroup ?? undefined,\n }));\n }\n\n async takeSignalWaiter(token: string): Promise<SignalWaiter | null> {\n const e = await this.waiters().findOneBy({ token });\n if (!e) return null;\n const waiter: SignalWaiter = {\n token: e.token,\n runId: e.runId,\n seq: e.seq,\n parallelGroup: e.parallelGroup ?? undefined,\n };\n await this.waiters().delete({ token });\n return waiter;\n }\n\n async removeSignalWaiter(waiter: SignalWaiter): Promise<void> {\n // Exact-match delete (token AND runId AND seq) — a plain `delete({ token })` would remove\n // whatever row currently owns the token, even if a different run has since claimed it.\n await this.waiters().delete({ token: waiter.token, runId: waiter.runId, seq: waiter.seq });\n }\n\n async bufferSignal(token: string, payload: unknown): Promise<void> {\n await this.buffered().save({ token, payload: payload ?? null });\n }\n\n async takeBufferedSignal(token: string): Promise<{ payload: unknown } | null> {\n const e = await this.buffered().findOne({ where: { token }, order: { id: 'ASC' } });\n if (!e) return null;\n await this.buffered().delete({ id: e.id });\n return { payload: e.payload ?? undefined };\n }\n\n async bufferEvent(input: {\n name: string;\n payload: unknown;\n id: string;\n publishedAt: number;\n }): Promise<void> {\n await this.bufferedEvents().save({\n id: input.id,\n name: input.name,\n payload: input.payload ?? null,\n publishedAt: new Date(input.publishedAt),\n });\n }\n\n async listBufferedEvents(\n name: string,\n limit: number,\n ): Promise<Array<{ id: string; payload: unknown; publishedAt: number }>> {\n const rows = await this.bufferedEvents().find({\n where: { name },\n order: { publishedAt: 'ASC' }, // oldest first\n take: limit,\n });\n return rows.map((e) => ({\n id: e.id,\n payload: e.payload ?? undefined,\n publishedAt: e.publishedAt.getTime(),\n }));\n }\n\n async removeBufferedEvent(id: string): Promise<boolean> {\n const result = await this.bufferedEvents().delete({ id });\n return result.affected === 1;\n }\n}\n\nfunction toRunEntity(run: WorkflowRun): WorkflowRunEntity {\n return {\n id: run.id,\n workflow: run.workflow,\n workflowVersion: run.workflowVersion,\n status: run.status,\n input: run.input ?? null,\n output: run.output ?? null,\n error: run.error ?? null,\n ...(run.wakeAt == null ? {} : { wakeAt: new Date(run.wakeAt) }),\n lockedBy: run.lockedBy ?? null,\n ...(run.lockedUntil == null ? {} : { lockedUntil: new Date(run.lockedUntil) }),\n awaitingDecisionTaskId: run.awaitingDecisionTaskId ?? null,\n ...(run.recoveryAttempts === undefined ? {} : { recoveryAttempts: run.recoveryAttempts }),\n tags: run.tags ?? null,\n searchAttributes: run.searchAttributes ?? null,\n priority: run.priority ?? null,\n createdAt: run.createdAt,\n updatedAt: run.updatedAt,\n };\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 == null ? undefined : e.wakeAt.getTime(),\n lockedBy: e.lockedBy ?? undefined,\n lockedUntil: e.lockedUntil == null ? undefined : e.lockedUntil.getTime(),\n awaitingDecisionTaskId: e.awaitingDecisionTaskId ?? undefined,\n recoveryAttempts: e.recoveryAttempts ?? undefined,\n tags: e.tags ?? undefined,\n searchAttributes: e.searchAttributes ?? undefined,\n priority: e.priority ?? undefined,\n createdAt: e.createdAt,\n updatedAt: e.updatedAt,\n };\n}\n\nfunction toCheckpointEntity(cp: StepCheckpoint): StepCheckpointEntity {\n return {\n runId: cp.runId,\n seq: cp.seq,\n name: cp.name,\n kind: cp.kind,\n stepId: cp.stepId,\n status: cp.status,\n input: cp.input ?? null,\n output: cp.output ?? null,\n error: cp.error ?? null,\n events: cp.events ?? null,\n attempts: cp.attempts,\n workerGroup: cp.workerGroup ?? null,\n parallelGroup: cp.parallelGroup ?? null,\n ...(cp.wakeAt == null ? {} : { wakeAt: new Date(cp.wakeAt) }),\n enqueuedAt: cp.enqueuedAt,\n startedAt: cp.startedAt,\n finishedAt: cp.finishedAt,\n };\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 parallelGroup: e.parallelGroup ?? undefined,\n wakeAt: e.wakeAt == null ? undefined : e.wakeAt.getTime(),\n // Older rows predate enqueuedAt; treat the worker start as enqueue time (queue-wait reads zero).\n enqueuedAt: e.enqueuedAt ?? e.startedAt,\n startedAt: e.startedAt,\n finishedAt: e.finishedAt,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;ACCA,qBAAoD;AAU7C,SAASA,gBAA6BC,KAAcC,OAAa;AACtE,MAAID,OAAO,KAAM,QAAOE;AAExB,MAAI,OAAOF,QAAQ,SAAU,QAAOA;AACpC,MAAI;AACF,WAAOG,KAAKC,MAAMJ,GAAAA;EACpB,SAASK,KAAK;AACZC,YAAQC,KACN,kCAAkCN,KAAAA,oCAC/BI,IAAcG,OAAO,EACtB;AAEJ,WAAON;EACT;AACF;AAdgBH;AAqBhB,SAASU,sBAAsBR,OAAa;AAC1C,SAAO;IACLS,IAAI,wBAACC,UAAoBA,SAAS,OAAO,OAAOR,KAAKS,UAAUD,KAAAA,GAA3D;IACJE,MAAM,wBAACF,UAAmBZ,gBAAgBY,OAAOV,KAAAA,GAA3C;EACR;AACF;AALSQ;AAqBT,SAASK,UAAUC,UAAgB;AACjC,SAAOA,SAASC,QAAQ,UAAU,CAACC,MAAM,IAAIA,EAAEC,YAAW,CAAA,EAAI;AAChE;AAFSJ;AAKF,SAASK,YAAYC,QAA2B;AACrD,MAAIA,WAAW,aAAc,QAAON;AACpC,MAAIM,WAAW,WAAY,QAAO,CAACL,aAAaA;AAChD,SAAOK;AACT;AAJgBD;AAUT,IAAME,oBAAN,MAAMA;EAnEb,OAmEaA;;;EACXC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;AACF;AAEO,IAAMC,uBAAN,MAAMA;EAvFb,OAuFaA;;;EACXC;EACAC;EACAC;EACAC;EACAC;EACAnB;EACAC;EACAC;EACAC;EACAiB;EAC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,IAAkB;AAC5C,SAAO;IACLxD,OAAOwD,GAAGxD;IACV8C,KAAKU,GAAGV;IACR0D,MAAMhD,GAAGgD;IACTqC,MAAMrF,GAAGqF;IACTC,QAAQtF,GAAGsF;IACX3H,QAAQqC,GAAGrC;IACXC,OAAOoC,GAAGpC,SAAS;IACnBC,QAAQmC,GAAGnC,UAAU;IACrBC,OAAOkC,GAAGlC,SAAS;IACnByH,QAAQvF,GAAGuF,UAAU;IACrBC,UAAUxF,GAAGwF;IACbC,aAAazF,GAAGyF,eAAe;IAC/BjB,eAAexE,GAAGwE,iBAAiB;IACnC,GAAIxE,GAAGjC,UAAU,OAAO,CAAC,IAAI;MAAEA,QAAQ,IAAIC,KAAKgC,GAAGjC,MAAM;IAAE;IAC3D2H,YAAY1F,GAAG0F;IACfC,WAAW3F,GAAG2F;IACdC,YAAY5F,GAAG4F;EACjB;AACF;AApBSjG;AAsBT,SAASJ,qBAAqBN,GAAuB;AACnD,SAAO;IACLzC,OAAOyC,EAAEzC;IACT8C,KAAKL,EAAEK;IACP0D,MAAM/D,EAAE+D;IACRqC,MAAMpG,EAAEoG;IACRC,QAAQrG,EAAEqG;IACV3H,QAAQsB,EAAEtB;IACVC,OAAOqB,EAAErB,SAASoG;IAClBnG,QAAQoB,EAAEpB,UAAUmG;IACpBlG,OAAQmB,EAAEnB,SAASkG;IACnBuB,QAAStG,EAAEsG,UAAUvB;IACrBwB,UAAUvG,EAAEuG;IACZC,aAAaxG,EAAEwG,eAAezB;IAC9BQ,eAAevF,EAAEuF,iBAAiBR;IAClCjG,QAAQkB,EAAElB,UAAU,OAAOiG,SAAY/E,EAAElB,OAAOoH,QAAO;;IAEvDO,YAAYzG,EAAEyG,cAAczG,EAAE0G;IAC9BA,WAAW1G,EAAE0G;IACbC,YAAY3G,EAAE2G;EAChB;AACF;AArBSrG;","names":["parseJsonColumn","raw","field","undefined","JSON","parse","err","console","warn","message","jsonColumnTransformer","to","value","stringify","from","snakeCase","property","replace","c","toLowerCase","columnNamer","naming","WorkflowRunEntity","id","workflow","workflowVersion","status","input","output","error","wakeAt","lockedBy","lockedUntil","awaitingDecisionTaskId","recoveryAttempts","tags","searchAttributes","priority","createdAt","updatedAt","StepCheckpointEntity","runId","seq","name","kind","stepId","events","attempts","workerGroup","parallelGroup","enqueuedAt","startedAt","finishedAt","RunAttributeEntity","key","strValue","numValue","SignalWaiterEntity","token","BufferedSignalEntity","payload","BufferedEventEntity","publishedAt","durableEntities","options","col","workflowRuns","EntitySchema","target","tableName","columns","type","primary","nullable","transformer","Date","stepCheckpoints","runAttributes","signalWaiters","bufferedSignals","Number","generated","bufferedEvents","ENTITIES","JSON_BLOB_COLUMNS","durable_workflow_runs","durable_step_checkpoints","TABLE_TO_ENTITY","WorkflowRunEntity","StepCheckpointEntity","durable_run_attributes","RunAttributeEntity","durable_signal_waiters","SignalWaiterEntity","durable_buffered_signals","BufferedSignalEntity","durable_buffered_events","BufferedEventEntity","durableManagedTables","Object","keys","durableColumnResolver","dataSource","table","property","entity","Error","meta","getMetadata","column","findColumnWithPropertyName","databaseName","jsonBlobColumnType","isMysql","buildWidenStatements","quote","col","out","props","entries","prop","push","ensureTypeOrmDurableSchema","q","id","driver","escape","resolve","type","String","options","isPg","isSqlite","str","txt","int","ts","runs","checkpoints","runAttributes","waiters","buffered","bufferedEvents","runsCol","cpCol","attrCol","waiterCol","bufCol","bevCol","num","bufferedId","tables","additive","runner","createQueryRunner","sql","query","have","existingColumns","colType","has","indexes","name","target","release","d","rows","Set","map","r","scope","placeholder","COLUMN_NAME","import_typeorm","TypeOrmStateStore","dataSource","ensureSchema","ensureTypeOrmDurableSchema","runs","getRepository","WorkflowRunEntity","checkpoints","StepCheckpointEntity","waiters","SignalWaiterEntity","buffered","BufferedSignalEntity","bufferedEvents","BufferedEventEntity","attributes","RunAttributeEntity","reindexAttributes","runId","em","repo","delete","rows","normalizeAttributeRows","length","insert","createRun","run","save","toRunEntity","id","searchAttributes","updateRun","patch","update","workflow","workflowVersion","status","input","output","error","wakeAt","Date","lockedBy","lockedUntil","awaitingDecisionTaskId","recoveryAttempts","tags","priority","createdAt","updatedAt","result","createQueryBuilder","set","where","execute","affected","Error","getRun","e","findOneBy","fromRunEntity","deleteRun","getCheckpoint","seq","fromCheckpointEntity","saveCheckpoint","checkpoint","entity","toCheckpointEntity","upsert","transaction","work","raw","cp","listIncompleteRuns","findBy","In","map","listPendingRuns","limit","find","order","take","listDueTimers","nowMs","LessThanOrEqual","tryLockRun","owner","leaseUntilMs","andWhere","Brackets","qb","IsNull","orWhere","releaseRunLock","renewRunLock","listRuns","query","statuses","tag","tagPattern","forEach","f","i","applyAttributeExists","orderBy","offset","skip","getMany","valueProperty","attributeColumnFor","cmp","sqlComparator","op","keyParam","valParam","resolve","durableColumnResolver","q","idQuote","wrap","name","runIdCol","keyCol","valueCol","runPkCol","table","a","sql","key","attributeOperand","type","String","options","listCheckpoints","getLatestCheckpointByName","findOne","undefined","listCheckpointsByNamePrefix","prefixes","p","Like","putSignalWaiter","waiter","token","parallelGroup","listSignalWaiters","prefix","takeSignalWaiter","removeSignalWaiter","bufferSignal","payload","takeBufferedSignal","bufferEvent","publishedAt","listBufferedEvents","getTime","removeBufferedEvent","kind","stepId","events","attempts","workerGroup","enqueuedAt","startedAt","finishedAt"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -86,6 +86,15 @@ declare class BufferedSignalEntity {
|
|
|
86
86
|
token: string;
|
|
87
87
|
payload?: unknown;
|
|
88
88
|
}
|
|
89
|
+
/** A published event that matched no live waiter (see `engine.publishEvent`'s buffering). Keyed by a
|
|
90
|
+
* caller-minted `id` (a uuid, not autoincrement — `removeBufferedEvent` targets it directly), not by
|
|
91
|
+
* `runId`: events are name-based pub/sub, not tied to any one run. */
|
|
92
|
+
declare class BufferedEventEntity {
|
|
93
|
+
id: string;
|
|
94
|
+
name: string;
|
|
95
|
+
payload?: unknown;
|
|
96
|
+
publishedAt: Date;
|
|
97
|
+
}
|
|
89
98
|
/**
|
|
90
99
|
* Build the durable TypeORM entity schemas with column names pinned per `naming` (default
|
|
91
100
|
* `'snake_case'`). Register the result in your `DataSource`/`TypeOrmModule.forFeature`. The JSON-blob
|
|
@@ -167,6 +176,7 @@ declare class TypeOrmStateStore implements StateStore {
|
|
|
167
176
|
private checkpoints;
|
|
168
177
|
private waiters;
|
|
169
178
|
private buffered;
|
|
179
|
+
private bufferedEvents;
|
|
170
180
|
private attributes;
|
|
171
181
|
/** Rewrite a run's normalized attribute rows: delete the old set, insert the current one. Mirrors
|
|
172
182
|
* the in-memory store's reindex so the side-table always reflects the run's live searchAttributes. */
|
|
@@ -204,6 +214,18 @@ declare class TypeOrmStateStore implements StateStore {
|
|
|
204
214
|
takeBufferedSignal(token: string): Promise<{
|
|
205
215
|
payload: unknown;
|
|
206
216
|
} | null>;
|
|
217
|
+
bufferEvent(input: {
|
|
218
|
+
name: string;
|
|
219
|
+
payload: unknown;
|
|
220
|
+
id: string;
|
|
221
|
+
publishedAt: number;
|
|
222
|
+
}): Promise<void>;
|
|
223
|
+
listBufferedEvents(name: string, limit: number): Promise<Array<{
|
|
224
|
+
id: string;
|
|
225
|
+
payload: unknown;
|
|
226
|
+
publishedAt: number;
|
|
227
|
+
}>>;
|
|
228
|
+
removeBufferedEvent(id: string): Promise<boolean>;
|
|
207
229
|
}
|
|
208
230
|
|
|
209
|
-
export { BufferedSignalEntity, type DurableColumnNaming, ENTITIES, JSON_BLOB_COLUMNS, RunAttributeEntity, SignalWaiterEntity, StepCheckpointEntity, TypeOrmStateStore, WorkflowRunEntity, buildWidenStatements, columnNamer, durableColumnResolver, durableEntities, durableManagedTables, ensureTypeOrmDurableSchema, jsonBlobColumnType, parseJsonColumn };
|
|
231
|
+
export { BufferedEventEntity, BufferedSignalEntity, type DurableColumnNaming, ENTITIES, JSON_BLOB_COLUMNS, RunAttributeEntity, SignalWaiterEntity, StepCheckpointEntity, TypeOrmStateStore, WorkflowRunEntity, buildWidenStatements, columnNamer, durableColumnResolver, durableEntities, durableManagedTables, ensureTypeOrmDurableSchema, jsonBlobColumnType, parseJsonColumn };
|
package/dist/index.d.ts
CHANGED
|
@@ -86,6 +86,15 @@ declare class BufferedSignalEntity {
|
|
|
86
86
|
token: string;
|
|
87
87
|
payload?: unknown;
|
|
88
88
|
}
|
|
89
|
+
/** A published event that matched no live waiter (see `engine.publishEvent`'s buffering). Keyed by a
|
|
90
|
+
* caller-minted `id` (a uuid, not autoincrement — `removeBufferedEvent` targets it directly), not by
|
|
91
|
+
* `runId`: events are name-based pub/sub, not tied to any one run. */
|
|
92
|
+
declare class BufferedEventEntity {
|
|
93
|
+
id: string;
|
|
94
|
+
name: string;
|
|
95
|
+
payload?: unknown;
|
|
96
|
+
publishedAt: Date;
|
|
97
|
+
}
|
|
89
98
|
/**
|
|
90
99
|
* Build the durable TypeORM entity schemas with column names pinned per `naming` (default
|
|
91
100
|
* `'snake_case'`). Register the result in your `DataSource`/`TypeOrmModule.forFeature`. The JSON-blob
|
|
@@ -167,6 +176,7 @@ declare class TypeOrmStateStore implements StateStore {
|
|
|
167
176
|
private checkpoints;
|
|
168
177
|
private waiters;
|
|
169
178
|
private buffered;
|
|
179
|
+
private bufferedEvents;
|
|
170
180
|
private attributes;
|
|
171
181
|
/** Rewrite a run's normalized attribute rows: delete the old set, insert the current one. Mirrors
|
|
172
182
|
* the in-memory store's reindex so the side-table always reflects the run's live searchAttributes. */
|
|
@@ -204,6 +214,18 @@ declare class TypeOrmStateStore implements StateStore {
|
|
|
204
214
|
takeBufferedSignal(token: string): Promise<{
|
|
205
215
|
payload: unknown;
|
|
206
216
|
} | null>;
|
|
217
|
+
bufferEvent(input: {
|
|
218
|
+
name: string;
|
|
219
|
+
payload: unknown;
|
|
220
|
+
id: string;
|
|
221
|
+
publishedAt: number;
|
|
222
|
+
}): Promise<void>;
|
|
223
|
+
listBufferedEvents(name: string, limit: number): Promise<Array<{
|
|
224
|
+
id: string;
|
|
225
|
+
payload: unknown;
|
|
226
|
+
publishedAt: number;
|
|
227
|
+
}>>;
|
|
228
|
+
removeBufferedEvent(id: string): Promise<boolean>;
|
|
207
229
|
}
|
|
208
230
|
|
|
209
|
-
export { BufferedSignalEntity, type DurableColumnNaming, ENTITIES, JSON_BLOB_COLUMNS, RunAttributeEntity, SignalWaiterEntity, StepCheckpointEntity, TypeOrmStateStore, WorkflowRunEntity, buildWidenStatements, columnNamer, durableColumnResolver, durableEntities, durableManagedTables, ensureTypeOrmDurableSchema, jsonBlobColumnType, parseJsonColumn };
|
|
231
|
+
export { BufferedEventEntity, BufferedSignalEntity, type DurableColumnNaming, ENTITIES, JSON_BLOB_COLUMNS, RunAttributeEntity, SignalWaiterEntity, StepCheckpointEntity, TypeOrmStateStore, WorkflowRunEntity, buildWidenStatements, columnNamer, durableColumnResolver, durableEntities, durableManagedTables, ensureTypeOrmDurableSchema, jsonBlobColumnType, parseJsonColumn };
|
package/dist/index.js
CHANGED
|
@@ -101,6 +101,15 @@ var BufferedSignalEntity = class {
|
|
|
101
101
|
token;
|
|
102
102
|
payload;
|
|
103
103
|
};
|
|
104
|
+
var BufferedEventEntity = class {
|
|
105
|
+
static {
|
|
106
|
+
__name(this, "BufferedEventEntity");
|
|
107
|
+
}
|
|
108
|
+
id;
|
|
109
|
+
name;
|
|
110
|
+
payload;
|
|
111
|
+
publishedAt;
|
|
112
|
+
};
|
|
104
113
|
function durableEntities(options = {}) {
|
|
105
114
|
const col = columnNamer(options.naming ?? "snake_case");
|
|
106
115
|
const workflowRuns = new EntitySchema({
|
|
@@ -369,12 +378,44 @@ function durableEntities(options = {}) {
|
|
|
369
378
|
}
|
|
370
379
|
}
|
|
371
380
|
});
|
|
381
|
+
const bufferedEvents = new EntitySchema({
|
|
382
|
+
name: "BufferedEventEntity",
|
|
383
|
+
target: BufferedEventEntity,
|
|
384
|
+
tableName: "durable_buffered_events",
|
|
385
|
+
// No `indices` here (unlike MikroORM's EntitySchema, which does declare one): this store manages
|
|
386
|
+
// its DDL — including the `(name, publishedAt)` index — via raw SQL in `schema.ts`'s
|
|
387
|
+
// `ensureTypeOrmDurableSchema`, the same as every other durable_* table's indexes.
|
|
388
|
+
columns: {
|
|
389
|
+
// Caller-minted uuid (engine.publishEvent), not autoincrement — removeBufferedEvent targets it
|
|
390
|
+
// directly and needs to be handed the SAME id it was buffered with.
|
|
391
|
+
id: {
|
|
392
|
+
type: "text",
|
|
393
|
+
primary: true,
|
|
394
|
+
name: col("id")
|
|
395
|
+
},
|
|
396
|
+
name: {
|
|
397
|
+
type: "text",
|
|
398
|
+
name: col("name")
|
|
399
|
+
},
|
|
400
|
+
payload: {
|
|
401
|
+
type: "text",
|
|
402
|
+
nullable: true,
|
|
403
|
+
name: col("payload"),
|
|
404
|
+
transformer: jsonColumnTransformer("buffered.eventPayload")
|
|
405
|
+
},
|
|
406
|
+
publishedAt: {
|
|
407
|
+
type: Date,
|
|
408
|
+
name: col("publishedAt")
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
});
|
|
372
412
|
return [
|
|
373
413
|
workflowRuns,
|
|
374
414
|
stepCheckpoints,
|
|
375
415
|
runAttributes,
|
|
376
416
|
signalWaiters,
|
|
377
|
-
bufferedSignals
|
|
417
|
+
bufferedSignals,
|
|
418
|
+
bufferedEvents
|
|
378
419
|
];
|
|
379
420
|
}
|
|
380
421
|
__name(durableEntities, "durableEntities");
|
|
@@ -401,7 +442,8 @@ var TABLE_TO_ENTITY = {
|
|
|
401
442
|
durable_step_checkpoints: StepCheckpointEntity,
|
|
402
443
|
durable_run_attributes: RunAttributeEntity,
|
|
403
444
|
durable_signal_waiters: SignalWaiterEntity,
|
|
404
|
-
durable_buffered_signals: BufferedSignalEntity
|
|
445
|
+
durable_buffered_signals: BufferedSignalEntity,
|
|
446
|
+
durable_buffered_events: BufferedEventEntity
|
|
405
447
|
};
|
|
406
448
|
function durableManagedTables() {
|
|
407
449
|
return Object.keys(TABLE_TO_ENTITY);
|
|
@@ -451,11 +493,13 @@ async function ensureTypeOrmDurableSchema(dataSource) {
|
|
|
451
493
|
const runAttributes = q("durable_run_attributes");
|
|
452
494
|
const waiters = q("durable_signal_waiters");
|
|
453
495
|
const buffered = q("durable_buffered_signals");
|
|
496
|
+
const bufferedEvents = q("durable_buffered_events");
|
|
454
497
|
const runsCol = /* @__PURE__ */ __name((property) => q(resolve("durable_workflow_runs", property)), "runsCol");
|
|
455
498
|
const cpCol = /* @__PURE__ */ __name((property) => q(resolve("durable_step_checkpoints", property)), "cpCol");
|
|
456
499
|
const attrCol = /* @__PURE__ */ __name((property) => q(resolve("durable_run_attributes", property)), "attrCol");
|
|
457
500
|
const waiterCol = /* @__PURE__ */ __name((property) => q(resolve("durable_signal_waiters", property)), "waiterCol");
|
|
458
501
|
const bufCol = /* @__PURE__ */ __name((property) => q(resolve("durable_buffered_signals", property)), "bufCol");
|
|
502
|
+
const bevCol = /* @__PURE__ */ __name((property) => q(resolve("durable_buffered_events", property)), "bevCol");
|
|
459
503
|
const num = isPg ? "double precision" : isMysql ? "double" : "real";
|
|
460
504
|
const bufferedId = isSqlite ? `${bufCol("id")} integer PRIMARY KEY AUTOINCREMENT` : isMysql ? `${bufCol("id")} bigint NOT NULL AUTO_INCREMENT PRIMARY KEY` : isPg ? `${bufCol("id")} bigserial PRIMARY KEY` : `${bufCol("id")} bigint NOT NULL AUTO_INCREMENT PRIMARY KEY`;
|
|
461
505
|
const tables = [
|
|
@@ -493,6 +537,12 @@ async function ensureTypeOrmDurableSchema(dataSource) {
|
|
|
493
537
|
)`,
|
|
494
538
|
`CREATE TABLE IF NOT EXISTS ${buffered} (
|
|
495
539
|
${bufferedId}, ${bufCol("token")} ${str} NOT NULL, ${bufCol("payload")} ${txt}
|
|
540
|
+
)`,
|
|
541
|
+
// Caller-minted uuid PK (engine.publishEvent), not auto-increment — unlike durable_buffered_signals
|
|
542
|
+
// above, removeBufferedEvent needs to target the EXACT id it was buffered with.
|
|
543
|
+
`CREATE TABLE IF NOT EXISTS ${bufferedEvents} (
|
|
544
|
+
${bevCol("id")} ${str} PRIMARY KEY, ${bevCol("name")} ${str} NOT NULL,
|
|
545
|
+
${bevCol("payload")} ${txt}, ${bevCol("publishedAt")} ${ts} NOT NULL
|
|
496
546
|
)`
|
|
497
547
|
];
|
|
498
548
|
const additive = {
|
|
@@ -604,6 +654,11 @@ async function ensureTypeOrmDurableSchema(dataSource) {
|
|
|
604
654
|
"durable_buffered_signals_token_idx",
|
|
605
655
|
`${buffered} (${bufCol("token")})`
|
|
606
656
|
],
|
|
657
|
+
// buffered events are scanned oldest-first per name — one composite index serves both.
|
|
658
|
+
[
|
|
659
|
+
"durable_buffered_events_name_published_at_idx",
|
|
660
|
+
`${bufferedEvents} (${bevCol("name")}, ${bevCol("publishedAt")})`
|
|
661
|
+
],
|
|
607
662
|
// Search-attribute pushdown: equality + range predicates probe by (key, value). Two composite
|
|
608
663
|
// indexes — one per typed column — so a numeric range or a string equality is an index scan.
|
|
609
664
|
[
|
|
@@ -666,6 +721,9 @@ var TypeOrmStateStore = class {
|
|
|
666
721
|
buffered() {
|
|
667
722
|
return this.dataSource.getRepository(BufferedSignalEntity);
|
|
668
723
|
}
|
|
724
|
+
bufferedEvents() {
|
|
725
|
+
return this.dataSource.getRepository(BufferedEventEntity);
|
|
726
|
+
}
|
|
669
727
|
attributes() {
|
|
670
728
|
return this.dataSource.getRepository(RunAttributeEntity);
|
|
671
729
|
}
|
|
@@ -960,6 +1018,36 @@ var TypeOrmStateStore = class {
|
|
|
960
1018
|
payload: e.payload ?? void 0
|
|
961
1019
|
};
|
|
962
1020
|
}
|
|
1021
|
+
async bufferEvent(input) {
|
|
1022
|
+
await this.bufferedEvents().save({
|
|
1023
|
+
id: input.id,
|
|
1024
|
+
name: input.name,
|
|
1025
|
+
payload: input.payload ?? null,
|
|
1026
|
+
publishedAt: new Date(input.publishedAt)
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
async listBufferedEvents(name, limit) {
|
|
1030
|
+
const rows = await this.bufferedEvents().find({
|
|
1031
|
+
where: {
|
|
1032
|
+
name
|
|
1033
|
+
},
|
|
1034
|
+
order: {
|
|
1035
|
+
publishedAt: "ASC"
|
|
1036
|
+
},
|
|
1037
|
+
take: limit
|
|
1038
|
+
});
|
|
1039
|
+
return rows.map((e) => ({
|
|
1040
|
+
id: e.id,
|
|
1041
|
+
payload: e.payload ?? void 0,
|
|
1042
|
+
publishedAt: e.publishedAt.getTime()
|
|
1043
|
+
}));
|
|
1044
|
+
}
|
|
1045
|
+
async removeBufferedEvent(id) {
|
|
1046
|
+
const result = await this.bufferedEvents().delete({
|
|
1047
|
+
id
|
|
1048
|
+
});
|
|
1049
|
+
return result.affected === 1;
|
|
1050
|
+
}
|
|
963
1051
|
};
|
|
964
1052
|
function toRunEntity(run) {
|
|
965
1053
|
return {
|
|
@@ -1059,6 +1147,7 @@ function fromCheckpointEntity(e) {
|
|
|
1059
1147
|
}
|
|
1060
1148
|
__name(fromCheckpointEntity, "fromCheckpointEntity");
|
|
1061
1149
|
export {
|
|
1150
|
+
BufferedEventEntity,
|
|
1062
1151
|
BufferedSignalEntity,
|
|
1063
1152
|
ENTITIES,
|
|
1064
1153
|
JSON_BLOB_COLUMNS,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/entities.ts","../src/schema.ts","../src/typeorm-state-store.ts"],"sourcesContent":["import type { RunStatus, StepKind } from '@dudousxd/nestjs-durable-core';\nimport { EntitySchema, type ValueTransformer } from 'typeorm';\n\n/**\n * Safely deserialize a JSON-text column back to an object on READ.\n *\n * A column truncated by the old MySQL `text` 64KB limit (or otherwise corrupt) makes `JSON.parse`\n * throw \"Unterminated string in JSON\" — which, without this guard, would 500 the *entire* run-detail\n * read just because one blob is damaged. Instead, log once and degrade the bad field to `undefined`\n * so the rest of the run still renders. Valid JSON is unchanged.\n */\nexport function parseJsonColumn<T = unknown>(raw: unknown, field: string): T | undefined {\n if (raw == null) return undefined;\n // Some drivers (e.g. a native `json` column) already hand back a parsed object.\n if (typeof raw !== 'string') return raw as T;\n try {\n return JSON.parse(raw) as T;\n } catch (err) {\n console.warn(\n `durable store: failed to parse ${field} column, degrading to undefined: ${\n (err as Error).message\n }`,\n );\n return undefined;\n }\n}\n\n/**\n * TypeORM transformer for the free-form JSON-blob columns. Mirrors the built-in `simple-json`\n * serialization on WRITE (`JSON.stringify`, SQL NULL stays NULL) but uses {@link parseJsonColumn}\n * on READ so a single corrupt/truncated row degrades to `undefined` instead of throwing.\n */\nfunction jsonColumnTransformer(field: string): ValueTransformer {\n return {\n to: (value: unknown) => (value == null ? null : JSON.stringify(value)),\n from: (value: unknown) => parseJsonColumn(value, field),\n };\n}\n\n/**\n * How property names map to physical column names. The durable tables are adapter-agnostic: a run\n * written by one store adapter must be readable by another, so every adapter has to agree on the\n * physical column names. The default is `'snake_case'` (the canonical, matched by the MikroORM,\n * Prisma and Drizzle adapters). `'preserve'` keeps the camelCase property name verbatim (what the\n * old TypeORM/Prisma adapters produced before they were pinned). A function lets you supply any\n * custom mapping.\n *\n * The choice is pinned EXPLICITLY onto the entity schema rather than left to the host ORM's naming\n * strategy — depending on the host strategy is what silently diverged the adapters and broke a store\n * swap against an existing table.\n */\nexport type DurableColumnNaming = 'snake_case' | 'preserve' | ((property: string) => string);\n\nfunction snakeCase(property: string): string {\n return property.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);\n}\n\n/** Resolve a `DurableColumnNaming` to a `(property) => columnName` function. */\nexport function columnNamer(naming: DurableColumnNaming): (property: string) => string {\n if (naming === 'snake_case') return snakeCase;\n if (naming === 'preserve') return (property) => property;\n return naming;\n}\n\n// Plain classes (no decorators): the schema/column mapping lives on the EntitySchema built by\n// `durableEntities`, so the same class can be registered under different column names. The store\n// still references these classes for `getRepository`/`getMetadata`.\n\nexport class WorkflowRunEntity {\n id!: string;\n workflow!: string;\n workflowVersion!: string;\n status!: RunStatus;\n input?: unknown;\n output?: unknown;\n error?: unknown;\n wakeAt?: Date;\n lockedBy?: string | null;\n lockedUntil?: Date;\n awaitingDecisionTaskId?: string | null;\n recoveryAttempts?: number;\n tags?: string[] | null;\n searchAttributes?: Record<string, string | number | boolean> | null;\n priority?: number | null;\n createdAt!: Date;\n updatedAt!: Date;\n}\n\nexport class StepCheckpointEntity {\n runId!: string;\n seq!: number;\n name!: string;\n kind!: StepKind;\n stepId!: string;\n status!: 'pending' | 'running' | 'completed' | 'failed';\n input?: unknown;\n output?: unknown;\n error?: unknown;\n events?: unknown;\n attempts!: number;\n workerGroup?: string | null;\n parallelGroup?: string | null;\n wakeAt?: Date;\n enqueuedAt?: Date;\n startedAt!: 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 */\nexport class RunAttributeEntity {\n runId!: string;\n key!: string;\n strValue?: string | null;\n numValue?: number | null;\n}\n\nexport class SignalWaiterEntity {\n token!: string;\n runId!: string;\n seq!: number;\n parallelGroup?: string | null;\n}\n\nexport class BufferedSignalEntity {\n id!: number;\n token!: string;\n payload?: unknown;\n}\n\n/**\n * Build the durable TypeORM entity schemas with column names pinned per `naming` (default\n * `'snake_case'`). Register the result in your `DataSource`/`TypeOrmModule.forFeature`. The JSON-blob\n * columns keep the `jsonColumnTransformer` (corruption-tolerant read), the primary keys / auto-\n * increment / nullability are preserved, and the `id` of `durable_buffered_signals` stays a driver-\n * native auto-increment column.\n *\n * ```ts\n * entities: durableEntities({ naming: 'snake_case' })\n * ```\n */\nexport function durableEntities(options: { naming?: DurableColumnNaming } = {}): EntitySchema[] {\n const col = columnNamer(options.naming ?? 'snake_case');\n\n const workflowRuns = new EntitySchema<WorkflowRunEntity>({\n name: 'WorkflowRunEntity',\n target: WorkflowRunEntity,\n tableName: 'durable_workflow_runs',\n columns: {\n id: { type: 'text', primary: true, name: col('id') },\n workflow: { type: 'text', name: col('workflow') },\n workflowVersion: { type: 'text', name: col('workflowVersion') },\n status: { type: 'text', name: col('status') },\n input: {\n type: 'text',\n nullable: true,\n name: col('input'),\n transformer: jsonColumnTransformer('runs.input'),\n },\n output: {\n type: 'text',\n nullable: true,\n name: col('output'),\n transformer: jsonColumnTransformer('runs.output'),\n },\n error: {\n type: 'text',\n nullable: true,\n name: col('error'),\n transformer: jsonColumnTransformer('runs.error'),\n },\n wakeAt: { type: Date, nullable: true, name: col('wakeAt') },\n lockedBy: { type: 'text', nullable: true, name: col('lockedBy') },\n lockedUntil: { type: Date, nullable: true, name: col('lockedUntil') },\n // REMOTE turn the engine suspended on awaiting a decision; matched by completeRemoteDecision so\n // only the currently-awaited turn's decision is applied. Nullable: cleared when a decision lands.\n awaitingDecisionTaskId: {\n type: 'text',\n nullable: true,\n name: col('awaitingDecisionTaskId'),\n },\n recoveryAttempts: { type: 'integer', nullable: true, name: col('recoveryAttempts') },\n tags: {\n type: 'text',\n nullable: true,\n name: col('tags'),\n transformer: jsonColumnTransformer('runs.tags'),\n },\n searchAttributes: {\n type: 'text',\n nullable: true,\n name: col('searchAttributes'),\n transformer: jsonColumnTransformer('runs.searchAttributes'),\n },\n priority: { type: 'integer', nullable: true, name: col('priority') },\n createdAt: { type: Date, name: col('createdAt') },\n updatedAt: { type: Date, name: col('updatedAt') },\n },\n });\n\n const stepCheckpoints = new EntitySchema<StepCheckpointEntity>({\n name: 'StepCheckpointEntity',\n target: StepCheckpointEntity,\n tableName: 'durable_step_checkpoints',\n columns: {\n runId: { type: 'text', primary: true, name: col('runId') },\n seq: { type: 'integer', primary: true, name: col('seq') },\n name: { type: 'text', name: col('name') },\n kind: { type: 'text', name: col('kind') },\n stepId: { type: 'text', name: col('stepId') },\n status: { type: 'text', name: col('status') },\n input: {\n type: 'text',\n nullable: true,\n name: col('input'),\n transformer: jsonColumnTransformer('checkpoints.input'),\n },\n output: {\n type: 'text',\n nullable: true,\n name: col('output'),\n transformer: jsonColumnTransformer('checkpoints.output'),\n },\n error: {\n type: 'text',\n nullable: true,\n name: col('error'),\n transformer: jsonColumnTransformer('checkpoints.error'),\n },\n events: {\n type: 'text',\n nullable: true,\n name: col('events'),\n transformer: jsonColumnTransformer('checkpoints.events'),\n },\n attempts: { type: 'integer', name: col('attempts') },\n workerGroup: { type: 'text', nullable: true, name: col('workerGroup') },\n // A ctx.gather/ctx.all fan tags every sibling step with the same group so the dashboard renders\n // them as one parallel group; the core engine sets it (incl. from a remote worker's recordStep).\n parallelGroup: { type: 'text', nullable: true, name: col('parallelGroup') },\n wakeAt: { type: Date, nullable: true, name: col('wakeAt') },\n enqueuedAt: { type: Date, nullable: true, name: col('enqueuedAt') },\n startedAt: { type: Date, name: col('startedAt') },\n finishedAt: { type: Date, name: col('finishedAt') },\n },\n });\n\n const runAttributes = new EntitySchema<RunAttributeEntity>({\n name: 'RunAttributeEntity',\n target: RunAttributeEntity,\n tableName: 'durable_run_attributes',\n columns: {\n runId: { type: 'text', primary: true, name: col('runId') },\n key: { type: 'text', primary: true, name: col('key') },\n strValue: { type: 'text', nullable: true, name: col('strValue') },\n // `float`/`double` portable across SQLite/MySQL/Postgres for numeric range scans.\n numValue: { type: 'float', nullable: true, name: col('numValue') },\n },\n });\n\n const signalWaiters = new EntitySchema<SignalWaiterEntity>({\n name: 'SignalWaiterEntity',\n target: SignalWaiterEntity,\n tableName: 'durable_signal_waiters',\n columns: {\n token: { type: 'text', primary: true, name: col('token') },\n runId: { type: 'text', name: col('runId') },\n seq: { type: 'integer', name: col('seq') },\n // A ctx.gather_children/ctx.all child fan-out tags every awaited child with the same group; the\n // engine threads it onto the waiter so the resolving `signal:child:` checkpoint carries it and the\n // dashboard renders the fan as one parallel group. Nullable: only fan-out child waiters carry it.\n parallelGroup: { type: 'text', nullable: true, name: col('parallelGroup') },\n },\n });\n\n const bufferedSignals = new EntitySchema<BufferedSignalEntity>({\n name: 'BufferedSignalEntity',\n target: BufferedSignalEntity,\n tableName: 'durable_buffered_signals',\n columns: {\n // Auto-increment PK for FIFO ordering. Left as TypeORM's default increment generation so it\n // maps to the driver-native auto-increment column (INTEGER on SQLite, BIGINT/SERIAL elsewhere).\n id: { type: Number, primary: true, generated: 'increment', name: col('id') },\n token: { type: 'text', name: col('token') },\n payload: {\n type: 'text',\n nullable: true,\n name: col('payload'),\n transformer: jsonColumnTransformer('buffered.payload'),\n },\n },\n });\n\n return [workflowRuns, stepCheckpoints, runAttributes, signalWaiters, bufferedSignals];\n}\n\n/** Durable entity schemas with the canonical `'snake_case'` column names. */\nexport const ENTITIES = durableEntities();\n","import type { DataSource } from 'typeorm';\nimport {\n BufferedSignalEntity,\n RunAttributeEntity,\n SignalWaiterEntity,\n StepCheckpointEntity,\n WorkflowRunEntity,\n} from './entities';\n\n/** The JSON-blob columns per table (keyed by table name) that hold free-form payloads and so must\n * be the unbounded text type — `longtext` on MySQL, `text` elsewhere. Keyed by entity PROPERTY name;\n * the physical column is resolved from the DataSource metadata so it tracks the configured naming. */\nexport const JSON_BLOB_COLUMNS: Record<string, string[]> = {\n durable_workflow_runs: ['input', 'output', 'error', 'tags', 'searchAttributes'],\n durable_step_checkpoints: ['input', 'output', 'error', 'events'],\n};\n\n/** Each durable table → its backing entity class, so a column resolver can look up the physical\n * column for any (table, property) from the DataSource metadata (which reflects the configured\n * `DurableColumnNaming`). Keeps the raw DDL/SQL in lock-step with the entity column mapping. */\nconst TABLE_TO_ENTITY = {\n durable_workflow_runs: WorkflowRunEntity,\n durable_step_checkpoints: StepCheckpointEntity,\n durable_run_attributes: RunAttributeEntity,\n durable_signal_waiters: SignalWaiterEntity,\n durable_buffered_signals: BufferedSignalEntity,\n} as const;\n\n/**\n * Tables this store creates and manages at boot (autoSchema, see {@link ensureTypeOrmDurableSchema}).\n * Feed to your ORM's migration differ exclude/skipTables so it never tries to drop them.\n *\n * ```ts\n * // MikroORM-flavoured example (TypeORM has no built-in equivalent option); adapt to whichever\n * // migration tool generates your diffs — e.g. exclude these names from a typeorm-generated\n * // migration, or filter them out of `SELECT table_name FROM information_schema.tables` before\n * // diffing against your own entities.\n * const skipTables = new Set(durableManagedTables());\n * ```\n *\n * Derived from the same {@link TABLE_TO_ENTITY} map the raw-SQL heal keys its column resolution off\n * — one list, so a consumer's denylist can never drift from what this store actually owns.\n */\nexport function durableManagedTables(): string[] {\n return Object.keys(TABLE_TO_ENTITY);\n}\n\n/**\n * Resolve `(table, property) => physical column name` from the DataSource's entity metadata. The\n * column names are NOT hardcoded here: they come from whatever the registered `durableEntities`\n * mapped (canonical `snake_case` by default, `'preserve'` for the legacy camelCase, or a custom\n * mapping), so the raw `CREATE TABLE`/index/EXISTS SQL always matches the entities and can never\n * silently diverge.\n */\nexport function durableColumnResolver(\n dataSource: DataSource,\n): (table: string, property: string) => string {\n return (table, property) => {\n const entity = TABLE_TO_ENTITY[table as keyof typeof TABLE_TO_ENTITY];\n if (!entity) throw new Error(`durable store: unknown table \"${table}\"`);\n const meta = dataSource.getMetadata(entity);\n const column = meta.findColumnWithPropertyName(property);\n if (!column) {\n throw new Error(`durable store: no column for ${table}.${property} in entity metadata`);\n }\n return column.databaseName;\n };\n}\n\n/** The SQL type for free-form JSON-blob columns. MySQL `text` caps at 64KB and silently truncates,\n * so use `longtext` (4GB) there; Postgres/SQLite `text` is already unbounded. */\nexport function jsonBlobColumnType(isMysql: boolean): 'longtext' | 'text' {\n return isMysql ? 'longtext' : 'text';\n}\n\n/** Idempotent `MODIFY COLUMN ... longtext` statements that widen pre-existing MySQL `text` JSON-blob\n * columns. Returns `[]` on non-MySQL dialects (their `text` is already unbounded — nothing to do).\n * `quote` quotes an identifier per the active driver; `col` resolves a property to its physical\n * column name so the widen tracks the configured naming. */\nexport function buildWidenStatements(\n isMysql: boolean,\n quote: (id: string) => string,\n col: (table: string, property: string) => string,\n): string[] {\n if (!isMysql) return [];\n const out: string[] = [];\n for (const [table, props] of Object.entries(JSON_BLOB_COLUMNS)) {\n for (const prop of props) {\n out.push(`ALTER TABLE ${quote(table)} MODIFY COLUMN ${quote(col(table, prop))} longtext`);\n }\n }\n return out;\n}\n\n/**\n * Idempotently create the durable tables. Safe to run on every boot (auto-schema) and the\n * exact function to call from your own TypeORM migration when you disable auto-schema:\n *\n * ```ts\n * export class AddDurableTables implements MigrationInterface {\n * async up(q: QueryRunner) { await ensureTypeOrmDurableSchema(q.connection); }\n * }\n * ```\n *\n * Dialect-aware (MySQL / MariaDB / Postgres / SQLite): identifiers are quoted per driver, keyed\n * string columns are `varchar` (MySQL can't key a `text` column), and the index is best-effort.\n * Only ever adds the three durable tables — it never touches your other tables.\n */\nexport async function ensureTypeOrmDurableSchema(dataSource: DataSource): Promise<void> {\n const q = (id: string) => dataSource.driver.escape(id);\n // Physical column names come from the entity metadata (canonical snake_case by default), so this\n // raw DDL always matches the registered `durableEntities` instead of hardcoding camelCase.\n const resolve = durableColumnResolver(dataSource);\n const type = String(dataSource.options.type);\n const isPg = type === 'postgres' || type === 'aurora-postgres';\n const isMysql = type === 'mysql' || type === 'mariadb' || type === 'aurora-mysql';\n const isSqlite = type === 'sqlite' || type === 'better-sqlite3' || type === 'expo';\n\n // Keyed/short strings must be varchar on MySQL (a `text` PK/index needs a key length); `text`\n // for the free-form JSON payloads. Dates use the dialect's native timestamp type.\n const str = 'varchar(191)';\n // Free-form JSON payloads (`input`/`output`/`error`/`events`/`tags`/`searchAttributes`). MySQL's\n // `text` caps at 64KB and *silently truncates* — a large fan-out step's `events` then fails to\n // parse on read (\"Unterminated string in JSON\"). Use `longtext` (4GB) on MySQL; Postgres `text`\n // is already unbounded and SQLite `text` has no length limit.\n const txt = jsonBlobColumnType(isMysql);\n const int = isMysql ? 'int' : 'integer';\n const ts = isPg ? 'timestamptz' : 'datetime';\n\n const runs = q('durable_workflow_runs');\n const checkpoints = q('durable_step_checkpoints');\n const runAttributes = q('durable_run_attributes');\n const waiters = q('durable_signal_waiters');\n const buffered = q('durable_buffered_signals');\n // Per-table quoted-column helpers: resolve an entity property to its physical column then quote it.\n const runsCol = (property: string) => q(resolve('durable_workflow_runs', property));\n const cpCol = (property: string) => q(resolve('durable_step_checkpoints', property));\n const attrCol = (property: string) => q(resolve('durable_run_attributes', property));\n const waiterCol = (property: string) => q(resolve('durable_signal_waiters', property));\n const bufCol = (property: string) => q(resolve('durable_buffered_signals', property));\n // Numeric side-table column for attribute range scans. `double precision` on Postgres, `double` on\n // MySQL, `real` on SQLite (all hold JS numbers without precision loss for the typical attribute).\n const num = isPg ? 'double precision' : isMysql ? 'double' : 'real';\n\n // Auto-increment PK syntax differs per dialect: SQLite wants `INTEGER PRIMARY KEY AUTOINCREMENT`,\n // MySQL `BIGINT AUTO_INCREMENT PRIMARY KEY`, Postgres `BIGSERIAL PRIMARY KEY`.\n const bufferedId = isSqlite\n ? `${bufCol('id')} integer PRIMARY KEY AUTOINCREMENT`\n : isMysql\n ? `${bufCol('id')} bigint NOT NULL AUTO_INCREMENT PRIMARY KEY`\n : isPg\n ? `${bufCol('id')} bigserial PRIMARY KEY`\n : `${bufCol('id')} bigint NOT NULL AUTO_INCREMENT PRIMARY KEY`;\n\n const tables = [\n `CREATE TABLE IF NOT EXISTS ${runs} (\n ${runsCol('id')} ${str} PRIMARY KEY,\n ${runsCol('workflow')} ${str} NOT NULL,\n ${runsCol('workflowVersion')} ${str} NOT NULL,\n ${runsCol('status')} ${str} NOT NULL,\n ${runsCol('input')} ${txt}, ${runsCol('output')} ${txt}, ${runsCol('error')} ${txt},\n ${runsCol('wakeAt')} ${ts}, ${runsCol('lockedBy')} ${str}, ${runsCol('lockedUntil')} ${ts},\n ${runsCol('awaitingDecisionTaskId')} ${str},\n ${runsCol('recoveryAttempts')} ${int}, ${runsCol('tags')} ${txt}, ${runsCol('searchAttributes')} ${txt},\n ${runsCol('priority')} ${int},\n ${runsCol('createdAt')} ${ts} NOT NULL, ${runsCol('updatedAt')} ${ts} NOT NULL\n )`,\n `CREATE TABLE IF NOT EXISTS ${checkpoints} (\n ${cpCol('runId')} ${str} NOT NULL, ${cpCol('seq')} ${int} NOT NULL,\n ${cpCol('name')} ${str} NOT NULL, ${cpCol('kind')} ${str} NOT NULL, ${cpCol('stepId')} ${str} NOT NULL,\n ${cpCol('status')} ${str} NOT NULL, ${cpCol('input')} ${txt}, ${cpCol('output')} ${txt}, ${cpCol('error')} ${txt}, ${cpCol('events')} ${txt},\n ${cpCol('attempts')} ${int} NOT NULL, ${cpCol('workerGroup')} ${str}, ${cpCol('parallelGroup')} ${str},\n ${cpCol('wakeAt')} ${ts}, ${cpCol('enqueuedAt')} ${ts},\n ${cpCol('startedAt')} ${ts} NOT NULL, ${cpCol('finishedAt')} ${ts} NOT NULL,\n PRIMARY KEY (${cpCol('runId')}, ${cpCol('seq')})\n )`,\n // Normalized search-attribute side-table: one row per (run, key) so attribute predicates push\n // DOWN into SQL via an EXISTS join (indexed below). `key` is keyed → must be varchar on MySQL.\n `CREATE TABLE IF NOT EXISTS ${runAttributes} (\n ${attrCol('runId')} ${str} NOT NULL, ${attrCol('key')} ${str} NOT NULL,\n ${attrCol('strValue')} ${str}, ${attrCol('numValue')} ${num},\n PRIMARY KEY (${attrCol('runId')}, ${attrCol('key')})\n )`,\n `CREATE TABLE IF NOT EXISTS ${waiters} (\n ${waiterCol('token')} ${str} PRIMARY KEY, ${waiterCol('runId')} ${str} NOT NULL, ${waiterCol('seq')} ${int} NOT NULL,\n ${waiterCol('parallelGroup')} ${str}\n )`,\n `CREATE TABLE IF NOT EXISTS ${buffered} (\n ${bufferedId}, ${bufCol('token')} ${str} NOT NULL, ${bufCol('payload')} ${txt}\n )`,\n ];\n\n // Additive nullable columns gained across versions (e.g. `input`, `events`, `enqueuedAt`). On a\n // table that predates them, `CREATE TABLE IF NOT EXISTS` above is a no-op, so back-fill the ones\n // that are actually missing — the auto-schema self-heals instead of needing a manual migration.\n // We check the live columns first (rather than ALTER-and-ignore) so a *real* ALTER failure\n // surfaces instead of being swallowed as a presumed \"column already exists\".\n // Keyed by entity PROPERTY name; the physical column is resolved per-table so the ADD COLUMN\n // tracks the configured naming.\n const additive: Record<string, Array<[string, string]>> = {\n durable_workflow_runs: [\n ['input', txt],\n ['output', txt],\n ['error', txt],\n ['awaitingDecisionTaskId', str],\n ['recoveryAttempts', int],\n ['tags', txt],\n ['searchAttributes', txt],\n ['priority', int],\n ],\n durable_step_checkpoints: [\n ['input', txt],\n ['output', txt],\n ['error', txt],\n ['events', txt],\n ['workerGroup', str],\n ['parallelGroup', str],\n ['enqueuedAt', ts],\n ],\n // Back-fill the child-await fan group onto signal-waiter tables that predate it (a remote\n // `gather_children` fan-out threads its group here so the resolved `signal:child:` checkpoint carries it).\n durable_signal_waiters: [['parallelGroup', str]],\n };\n\n const runner = dataSource.createQueryRunner();\n try {\n for (const sql of tables) await runner.query(sql);\n for (const [table, props] of Object.entries(additive)) {\n const have = await existingColumns(runner, table, { isSqlite, isMysql });\n for (const [property, colType] of props) {\n const column = resolve(table, property);\n if (!have.has(column)) {\n await runner.query(`ALTER TABLE ${q(table)} ADD COLUMN ${q(column)} ${colType}`);\n }\n }\n }\n // Widen pre-existing MySQL `text` JSON-blob columns to `longtext`. A table created before this\n // fix has these as `text` (64KB) and silently truncates large `events`/`output` payloads. MODIFY\n // to `longtext` is idempotent (no-op if already longtext), so it's safe to run on every boot.\n // MySQL-only: Postgres/SQLite `text` is already unbounded, so there's nothing to widen.\n for (const sql of buildWidenStatements(isMysql, q, resolve)) {\n try {\n await runner.query(sql);\n } catch {\n /* column already longtext, or table/column not present on this deploy */\n }\n }\n // MySQL has no `CREATE INDEX IF NOT EXISTS`; create each best-effort and ignore \"already exists\".\n // - status/wakeAt: the timer poller (listDueTimers) and recovery (listIncompleteRuns) scans.\n // - workflow/status: the dashboard's listRuns filters. (Checkpoints are keyed by the PK prefix\n // `(runId, seq)`, so listCheckpoints/getEvent already hit an index — no extra one needed.)\n const indexes: Array<[string, string]> = [\n ['durable_runs_status_idx', `${runs} (${runsCol('status')}, ${runsCol('wakeAt')})`],\n [\n 'durable_runs_workflow_status_idx',\n `${runs} (${runsCol('workflow')}, ${runsCol('status')})`,\n ],\n // buffered signals are taken FIFO per token (smallest id) — index the token for the scan.\n ['durable_buffered_signals_token_idx', `${buffered} (${bufCol('token')})`],\n // Search-attribute pushdown: equality + range predicates probe by (key, value). Two composite\n // indexes — one per typed column — so a numeric range or a string equality is an index scan.\n [\n 'durable_run_attributes_num_idx',\n `${runAttributes} (${attrCol('key')}, ${attrCol('numValue')})`,\n ],\n [\n 'durable_run_attributes_str_idx',\n `${runAttributes} (${attrCol('key')}, ${attrCol('strValue')})`,\n ],\n ];\n for (const [name, target] of indexes) {\n try {\n await runner.query(`CREATE INDEX ${q(name)} ON ${target}`);\n } catch {\n /* index already exists */\n }\n }\n } finally {\n await runner.release();\n }\n}\n\n/** The columns that currently exist on `table`, so the schema can add only the missing ones\n * (instead of ALTER-and-swallow, which would also hide a genuine ALTER failure). */\nasync function existingColumns(\n runner: { query: (sql: string, params?: unknown[]) => Promise<unknown> },\n table: string,\n d: { isSqlite: boolean; isMysql: boolean },\n): Promise<Set<string>> {\n if (d.isSqlite) {\n const rows = (await runner.query(`PRAGMA table_info(\"${table}\")`)) as Array<{ name: string }>;\n return new Set(rows.map((r) => r.name));\n }\n // Postgres + MySQL both expose information_schema; scope to the connection's own schema/db.\n // Bind-param placeholder differs: Postgres uses `$1`, MySQL uses `?` (TypeORM only rewrites `?`\n // inside the query builder, not for these raw `runner.query` calls), so pick per dialect.\n const scope = d.isMysql ? 'TABLE_SCHEMA = DATABASE()' : 'table_schema = current_schema()';\n const placeholder = d.isMysql ? '?' : '$1';\n const rows = (await runner.query(\n `SELECT column_name AS name FROM information_schema.columns WHERE table_name = ${placeholder} AND ${scope}`,\n [table],\n )) as Array<{ name?: string; COLUMN_NAME?: string }>;\n return new Set(rows.map((r) => (r.name ?? r.COLUMN_NAME) as string));\n}\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 {\n Brackets,\n type DataSource,\n type EntityManager,\n In,\n IsNull,\n LessThanOrEqual,\n Like,\n type SelectQueryBuilder,\n} from 'typeorm';\nimport type { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';\nimport {\n BufferedSignalEntity,\n RunAttributeEntity,\n SignalWaiterEntity,\n StepCheckpointEntity,\n WorkflowRunEntity,\n} from './entities';\nimport { durableColumnResolver, ensureTypeOrmDurableSchema } from './schema';\n\n/**\n * TypeORM-backed `StateStore`. Works on any TypeORM driver — Postgres, MySQL, SQLite (tested);\n * timestamps use native datetime columns and `wakeAt` is stored as a datetime too.\n */\nexport class TypeOrmStateStore implements StateStore {\n constructor(private readonly dataSource: DataSource) {}\n\n async ensureSchema(): Promise<void> {\n await ensureTypeOrmDurableSchema(this.dataSource);\n }\n\n private runs() {\n return this.dataSource.getRepository(WorkflowRunEntity);\n }\n private checkpoints() {\n return this.dataSource.getRepository(StepCheckpointEntity);\n }\n private waiters() {\n return this.dataSource.getRepository(SignalWaiterEntity);\n }\n private buffered() {\n return this.dataSource.getRepository(BufferedSignalEntity);\n }\n private attributes() {\n return this.dataSource.getRepository(RunAttributeEntity);\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 em?: EntityManager,\n ): Promise<void> {\n const repo = em ? em.getRepository(RunAttributeEntity) : this.attributes();\n await repo.delete({ runId });\n const rows = normalizeAttributeRows(runId, attributes);\n if (rows.length) await repo.insert(rows);\n }\n\n async createRun(run: WorkflowRun): Promise<void> {\n await this.runs().save(toRunEntity(run));\n await this.reindexAttributes(run.id, run.searchAttributes);\n }\n\n async updateRun(runId: string, patch: Partial<WorkflowRun>): Promise<void> {\n // Single UPDATE (no pre-SELECT + save round-trips): map only the patched fields. The query\n // builder still applies the entities' JSON column transformers to the `set` values (as in\n // listRuns/tryLockRun). Preserve the not-found throw any caller may rely on.\n const update: Record<string, unknown> = {};\n if ('workflow' in patch) update.workflow = patch.workflow;\n if ('workflowVersion' in patch) update.workflowVersion = patch.workflowVersion;\n if ('status' in patch) update.status = patch.status;\n if ('input' in patch) update.input = patch.input ?? null;\n if ('output' in patch) update.output = patch.output ?? null;\n if ('error' in patch) update.error = patch.error ?? null;\n if ('wakeAt' in patch) update.wakeAt = patch.wakeAt == null ? null : new Date(patch.wakeAt);\n if ('lockedBy' in patch) update.lockedBy = patch.lockedBy ?? null;\n if ('lockedUntil' in patch)\n update.lockedUntil = patch.lockedUntil == null ? null : new Date(patch.lockedUntil);\n if ('awaitingDecisionTaskId' in patch)\n update.awaitingDecisionTaskId = patch.awaitingDecisionTaskId ?? null;\n if ('recoveryAttempts' in patch) update.recoveryAttempts = patch.recoveryAttempts;\n if ('tags' in patch) update.tags = patch.tags ?? null;\n if ('searchAttributes' in patch) update.searchAttributes = patch.searchAttributes ?? null;\n if ('priority' in patch) update.priority = patch.priority ?? null;\n if ('createdAt' in patch) update.createdAt = patch.createdAt;\n if ('updatedAt' in patch) update.updatedAt = patch.updatedAt;\n const result = await this.runs()\n .createQueryBuilder()\n .update()\n .set(update)\n .where({ id: runId })\n .execute();\n if (!result.affected) throw new Error(`run ${runId} not found`);\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 async getRun(runId: string): Promise<WorkflowRun | null> {\n const e = await this.runs().findOneBy({ id: runId });\n return e ? fromRunEntity(e) : null;\n }\n\n async deleteRun(runId: string): Promise<void> {\n // Child rows first, then the run — checkpoints, signal waiters, attribute rows.\n await this.checkpoints().delete({ runId });\n await this.waiters().delete({ runId });\n await this.attributes().delete({ runId });\n await this.runs().delete({ id: runId });\n }\n\n async getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null> {\n const e = await this.checkpoints().findOneBy({ runId, seq });\n return e ? fromCheckpointEntity(e) : null;\n }\n\n async saveCheckpoint(checkpoint: StepCheckpoint): Promise<void> {\n // upsert = INSERT ... ON CONFLICT DO UPDATE on the (runId, seq) key — drops the pre-SELECT that\n // `.save()` does on each write. JSON column transformers still apply for upsert.\n const entity = toCheckpointEntity(checkpoint) as QueryDeepPartialEntity<StepCheckpointEntity>;\n await this.checkpoints().upsert(entity, ['runId', 'seq']);\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.dataSource.transaction(async (em) =>\n work({\n raw: em,\n saveCheckpoint: async (cp) => {\n await em.getRepository(StepCheckpointEntity).save(toCheckpointEntity(cp));\n },\n }),\n );\n }\n\n async listIncompleteRuns(): Promise<WorkflowRun[]> {\n const rows = await this.runs().findBy({ status: In(['running', 'cancelling']) });\n return rows.map(fromRunEntity);\n }\n\n async listPendingRuns(limit: number): Promise<WorkflowRun[]> {\n const rows = await this.runs().find({\n where: { status: 'pending' },\n order: { createdAt: 'ASC' }, // FIFO dispatch\n take: limit,\n });\n return rows.map(fromRunEntity);\n }\n\n async listDueTimers(nowMs: number): Promise<WorkflowRun[]> {\n const rows = await this.runs().findBy({\n status: 'suspended',\n wakeAt: LessThanOrEqual(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 result = await this.runs()\n .createQueryBuilder()\n .update()\n .set({ lockedBy: owner, lockedUntil: new Date(leaseUntilMs) })\n .where({ id: runId })\n .andWhere(\n new Brackets((qb) =>\n qb\n .where({ lockedUntil: IsNull() })\n .orWhere({ lockedUntil: LessThanOrEqual(new Date(nowMs)) }),\n ),\n )\n .execute();\n return result.affected === 1;\n }\n\n async releaseRunLock(runId: string): Promise<void> {\n await this.runs().update({ id: runId }, { lockedBy: null, lockedUntil: () => 'NULL' });\n }\n\n async renewRunLock(runId: string, owner: string, leaseUntilMs: number): Promise<boolean> {\n const result = await this.runs()\n .createQueryBuilder()\n .update()\n .set({ lockedUntil: new Date(leaseUntilMs) })\n .where({ id: runId, lockedBy: owner })\n .execute();\n return result.affected === 1;\n }\n\n async listRuns(query: RunQuery): Promise<WorkflowRun[]> {\n // `tags` carries a custom JSON transformer, and TypeORM applies a column transformer's `to()` to\n // FindOperator values too — so a `Like('%\"etl\"%')` in a plain `where` would be JSON-stringified\n // and corrupt the LIKE pattern. Use the query builder with a raw parameter to bypass that.\n const qb = this.runs().createQueryBuilder('r');\n if (query.workflow) qb.andWhere('r.workflow = :workflow', { workflow: query.workflow });\n if (query.status) qb.andWhere('r.status = :status', { status: query.status });\n if (query.statuses)\n qb.andWhere(\n query.statuses.length ? 'r.status IN (:...statuses)' : '1 = 0',\n query.statuses.length ? { statuses: query.statuses } : {},\n );\n // `tags` is a JSON-text column; match the quoted token so `etl` doesn't match `etl-foo`. NOTE: a\n // leading-wildcard LIKE on JSON text is NOT index-friendly (no B-tree index can serve `%\"x\"%`), so\n // tag-filtered scans (e.g. singleton admission) are sequential over `durable_runs_workflow_status_idx`'s\n // result set. The `statuses`/`workflow` predicates above bound that scan; if tag scans ever dominate,\n // promote tags to a normalized join table or a JSON/GIN index — a schema change, intentionally not done here.\n if (query.tag) qb.andWhere('r.tags LIKE :tagPattern', { tagPattern: `%\"${query.tag}\"%` });\n // Typed/range attribute predicates push DOWN into SQL: each filter becomes an EXISTS against the\n // normalized `durable_run_attributes` side-table (indexed on (key, numValue)/(key, strValue)), so\n // the DB does the filtering AND the LIMIT/OFFSET — no full scan + in-process filter. ANDed: a run\n // must satisfy every filter, so one EXISTS per filter.\n if (query.attributes?.length) {\n query.attributes.forEach((f, i) => this.applyAttributeExists(qb, f, i));\n }\n qb.orderBy('r.createdAt', 'DESC'); // newest first — recent runs on top in the dashboard\n if (query.limit != null) qb.take(query.limit);\n if (query.offset != null) qb.skip(query.offset);\n const rows = await qb.getMany();\n return rows.map(fromRunEntity);\n }\n\n /** Add one attribute predicate to `qb` as an EXISTS subquery on the side-table. `i` namespaces the\n * bind params so multiple ANDed filters don't collide. */\n private applyAttributeExists(\n qb: SelectQueryBuilder<WorkflowRunEntity>,\n f: AttributeFilter,\n i: number,\n ): void {\n const valueProperty = attributeColumnFor(f); // 'numValue' | 'strValue' (entity property)\n const cmp = sqlComparator(f.op);\n const keyParam = `attrKey${i}`;\n const valParam = `attrVal${i}`;\n // Resolve the PHYSICAL column names from the entity metadata so this raw subquery tracks the\n // configured naming (canonical snake_case by default) instead of hardcoding camelCase — which\n // would break the EXISTS pushdown the moment the table is snake_case.\n const resolve = durableColumnResolver(this.dataSource);\n const q = this.idQuote();\n const wrap = (name: string) => `${q}${name}${q}`;\n const runIdCol = wrap(resolve('durable_run_attributes', 'runId'));\n const keyCol = wrap(resolve('durable_run_attributes', 'key'));\n const valueCol = wrap(resolve('durable_run_attributes', valueProperty));\n const runPkCol = wrap(resolve('durable_workflow_runs', 'id'));\n const table = wrap('durable_run_attributes');\n // `<>` (ne) must also exclude rows where the attribute is absent: the missing-key-never-matches\n // contract (see core matchesAttributes). EXISTS already requires the key row to be present, and a\n // row only exists when the value is non-null, so EXISTS(... <> ...) gives exactly ne-with-present.\n const a = `a${i}`;\n const sql = `EXISTS (SELECT 1 FROM ${table} ${a} WHERE ${a}.${runIdCol} = r.${runPkCol} AND ${a}.${keyCol} = :${keyParam} AND ${a}.${valueCol} ${cmp} :${valParam})`;\n qb.andWhere(sql, {\n [keyParam]: f.key,\n [valParam]: attributeOperand(f),\n });\n }\n\n /** The identifier quote char for the active driver (MySQL backtick, others double-quote). */\n private idQuote(): string {\n const type = String(this.dataSource.options.type);\n return type === 'mysql' || type === 'mariadb' || type === 'aurora-mysql' ? '`' : '\"';\n }\n\n async listCheckpoints(runId: string): Promise<StepCheckpoint[]> {\n const rows = await this.checkpoints().find({ where: { runId }, order: { seq: 'ASC' } });\n return rows.map(fromCheckpointEntity);\n }\n\n async getLatestCheckpointByName(\n runId: string,\n name: string,\n ): Promise<StepCheckpoint | undefined> {\n const e = await this.checkpoints().findOne({ where: { runId, name }, order: { seq: 'DESC' } });\n return e ? fromCheckpointEntity(e) : undefined;\n }\n\n async listCheckpointsByNamePrefix(runId: string, prefixes: string[]): Promise<StepCheckpoint[]> {\n if (prefixes.length === 0) return [];\n const rows = await this.checkpoints().find({\n where: prefixes.map((p) => ({ runId, name: Like(`${p}%`) })),\n order: { seq: 'ASC' },\n });\n return rows.map(fromCheckpointEntity);\n }\n\n async putSignalWaiter(waiter: SignalWaiter): Promise<void> {\n await this.waiters().save({\n token: waiter.token,\n runId: waiter.runId,\n seq: waiter.seq,\n parallelGroup: waiter.parallelGroup ?? null,\n });\n }\n\n async listSignalWaiters(prefix: string): Promise<SignalWaiter[]> {\n const rows = await this.waiters().find({ where: { token: Like(`${prefix}%`) } });\n return rows.map((e) => ({\n token: e.token,\n runId: e.runId,\n seq: e.seq,\n parallelGroup: e.parallelGroup ?? undefined,\n }));\n }\n\n async takeSignalWaiter(token: string): Promise<SignalWaiter | null> {\n const e = await this.waiters().findOneBy({ token });\n if (!e) return null;\n const waiter: SignalWaiter = {\n token: e.token,\n runId: e.runId,\n seq: e.seq,\n parallelGroup: e.parallelGroup ?? undefined,\n };\n await this.waiters().delete({ token });\n return waiter;\n }\n\n async removeSignalWaiter(waiter: SignalWaiter): Promise<void> {\n // Exact-match delete (token AND runId AND seq) — a plain `delete({ token })` would remove\n // whatever row currently owns the token, even if a different run has since claimed it.\n await this.waiters().delete({ token: waiter.token, runId: waiter.runId, seq: waiter.seq });\n }\n\n async bufferSignal(token: string, payload: unknown): Promise<void> {\n await this.buffered().save({ token, payload: payload ?? null });\n }\n\n async takeBufferedSignal(token: string): Promise<{ payload: unknown } | null> {\n const e = await this.buffered().findOne({ where: { token }, order: { id: 'ASC' } });\n if (!e) return null;\n await this.buffered().delete({ id: e.id });\n return { payload: e.payload ?? undefined };\n }\n}\n\nfunction toRunEntity(run: WorkflowRun): WorkflowRunEntity {\n return {\n id: run.id,\n workflow: run.workflow,\n workflowVersion: run.workflowVersion,\n status: run.status,\n input: run.input ?? null,\n output: run.output ?? null,\n error: run.error ?? null,\n ...(run.wakeAt == null ? {} : { wakeAt: new Date(run.wakeAt) }),\n lockedBy: run.lockedBy ?? null,\n ...(run.lockedUntil == null ? {} : { lockedUntil: new Date(run.lockedUntil) }),\n awaitingDecisionTaskId: run.awaitingDecisionTaskId ?? null,\n ...(run.recoveryAttempts === undefined ? {} : { recoveryAttempts: run.recoveryAttempts }),\n tags: run.tags ?? null,\n searchAttributes: run.searchAttributes ?? null,\n priority: run.priority ?? null,\n createdAt: run.createdAt,\n updatedAt: run.updatedAt,\n };\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 == null ? undefined : e.wakeAt.getTime(),\n lockedBy: e.lockedBy ?? undefined,\n lockedUntil: e.lockedUntil == null ? undefined : e.lockedUntil.getTime(),\n awaitingDecisionTaskId: e.awaitingDecisionTaskId ?? undefined,\n recoveryAttempts: e.recoveryAttempts ?? undefined,\n tags: e.tags ?? undefined,\n searchAttributes: e.searchAttributes ?? undefined,\n priority: e.priority ?? undefined,\n createdAt: e.createdAt,\n updatedAt: e.updatedAt,\n };\n}\n\nfunction toCheckpointEntity(cp: StepCheckpoint): StepCheckpointEntity {\n return {\n runId: cp.runId,\n seq: cp.seq,\n name: cp.name,\n kind: cp.kind,\n stepId: cp.stepId,\n status: cp.status,\n input: cp.input ?? null,\n output: cp.output ?? null,\n error: cp.error ?? null,\n events: cp.events ?? null,\n attempts: cp.attempts,\n workerGroup: cp.workerGroup ?? null,\n parallelGroup: cp.parallelGroup ?? null,\n ...(cp.wakeAt == null ? {} : { wakeAt: new Date(cp.wakeAt) }),\n enqueuedAt: cp.enqueuedAt,\n startedAt: cp.startedAt,\n finishedAt: cp.finishedAt,\n };\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 parallelGroup: e.parallelGroup ?? undefined,\n wakeAt: e.wakeAt == null ? undefined : e.wakeAt.getTime(),\n // Older rows predate enqueuedAt; treat the worker start as enqueue time (queue-wait reads zero).\n enqueuedAt: e.enqueuedAt ?? e.startedAt,\n startedAt: e.startedAt,\n finishedAt: e.finishedAt,\n };\n}\n"],"mappings":";;;;AACA,SAASA,oBAA2C;AAU7C,SAASC,gBAA6BC,KAAcC,OAAa;AACtE,MAAID,OAAO,KAAM,QAAOE;AAExB,MAAI,OAAOF,QAAQ,SAAU,QAAOA;AACpC,MAAI;AACF,WAAOG,KAAKC,MAAMJ,GAAAA;EACpB,SAASK,KAAK;AACZC,YAAQC,KACN,kCAAkCN,KAAAA,oCAC/BI,IAAcG,OAAO,EACtB;AAEJ,WAAON;EACT;AACF;AAdgBH;AAqBhB,SAASU,sBAAsBR,OAAa;AAC1C,SAAO;IACLS,IAAI,wBAACC,UAAoBA,SAAS,OAAO,OAAOR,KAAKS,UAAUD,KAAAA,GAA3D;IACJE,MAAM,wBAACF,UAAmBZ,gBAAgBY,OAAOV,KAAAA,GAA3C;EACR;AACF;AALSQ;AAqBT,SAASK,UAAUC,UAAgB;AACjC,SAAOA,SAASC,QAAQ,UAAU,CAACC,MAAM,IAAIA,EAAEC,YAAW,CAAA,EAAI;AA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,SAASQ,mBAAmBK,IAAkB;AAC5C,SAAO;IACLxD,OAAOwD,GAAGxD;IACV8C,KAAKU,GAAGV;IACR0D,MAAMhD,GAAGgD;IACTiC,MAAMjF,GAAGiF;IACTC,QAAQlF,GAAGkF;IACXvH,QAAQqC,GAAGrC;IACXC,OAAOoC,GAAGpC,SAAS;IACnBC,QAAQmC,GAAGnC,UAAU;IACrBC,OAAOkC,GAAGlC,SAAS;IACnBqH,QAAQnF,GAAGmF,UAAU;IACrBC,UAAUpF,GAAGoF;IACbC,aAAarF,GAAGqF,eAAe;IAC/Bb,eAAexE,GAAGwE,iBAAiB;IACnC,GAAIxE,GAAGjC,UAAU,OAAO,CAAC,IAAI;MAAEA,QAAQ,IAAIC,KAAKgC,GAAGjC,MAAM;IAAE;IAC3DuH,YAAYtF,GAAGsF;IACfC,WAAWvF,GAAGuF;IACdC,YAAYxF,GAAGwF;EACjB;AACF;AApBS7F;AAsBT,SAASJ,qBAAqBN,GAAuB;AACnD,SAAO;IACLzC,OAAOyC,EAAEzC;IACT8C,KAAKL,EAAEK;IACP0D,MAAM/D,EAAE+D;IACRiC,MAAMhG,EAAEgG;IACRC,QAAQjG,EAAEiG;IACVvH,QAAQsB,EAAEtB;IACVC,OAAOqB,EAAErB,SAASoG;IAClBnG,QAAQoB,EAAEpB,UAAUmG;IACpBlG,OAAQmB,EAAEnB,SAASkG;IACnBmB,QAASlG,EAAEkG,UAAUnB;IACrBoB,UAAUnG,EAAEmG;IACZC,aAAapG,EAAEoG,eAAerB;IAC9BQ,eAAevF,EAAEuF,iBAAiBR;IAClCjG,QAAQkB,EAAElB,UAAU,OAAOiG,SAAY/E,EAAElB,OAAOiH,QAAO;;IAEvDM,YAAYrG,EAAEqG,cAAcrG,EAAEsG;IAC9BA,WAAWtG,EAAEsG;IACbC,YAAYvG,EAAEuG;EAChB;AACF;AArBSjG;","names":["EntitySchema","parseJsonColumn","raw","field","undefined","JSON","parse","err","console","warn","message","jsonColumnTransformer","to","value","stringify","from","snakeCase","property","replace","c","toLowerCase","columnNamer","naming","WorkflowRunEntity","id","workflow","workflowVersion","status","input","output","error","wakeAt","lockedBy","lockedUntil","awaitingDecisionTaskId","recoveryAttempts","tags","searchAttributes","priority","createdAt","updatedAt","StepCheckpointEntity","runId","seq","name","kind","stepId","events","attempts","workerGroup","parallelGroup","enqueuedAt","startedAt","finishedAt","RunAttributeEntity","key","strValue","numValue","SignalWaiterEntity","token","BufferedSignalEntity","payload","durableEntities","options","col","workflowRuns","EntitySchema","target","tableName","columns","type","primary","nullable","transformer","Date","stepCheckpoints","runAttributes","signalWaiters","bufferedSignals","Number","generated","ENTITIES","JSON_BLOB_COLUMNS","durable_workflow_runs","durable_step_checkpoints","TABLE_TO_ENTITY","WorkflowRunEntity","StepCheckpointEntity","durable_run_attributes","RunAttributeEntity","durable_signal_waiters","SignalWaiterEntity","durable_buffered_signals","BufferedSignalEntity","durableManagedTables","Object","keys","durableColumnResolver","dataSource","table","property","entity","Error","meta","getMetadata","column","findColumnWithPropertyName","databaseName","jsonBlobColumnType","isMysql","buildWidenStatements","quote","col","out","props","entries","prop","push","ensureTypeOrmDurableSchema","q","id","driver","escape","resolve","type","String","options","isPg","isSqlite","str","txt","int","ts","runs","checkpoints","runAttributes","waiters","buffered","runsCol","cpCol","attrCol","waiterCol","bufCol","num","bufferedId","tables","additive","runner","createQueryRunner","sql","query","have","existingColumns","colType","has","indexes","name","target","release","d","rows","Set","map","r","scope","placeholder","COLUMN_NAME","attributeColumnFor","attributeOperand","normalizeAttributeRows","sqlComparator","Brackets","In","IsNull","LessThanOrEqual","Like","TypeOrmStateStore","dataSource","ensureSchema","ensureTypeOrmDurableSchema","runs","getRepository","WorkflowRunEntity","checkpoints","StepCheckpointEntity","waiters","SignalWaiterEntity","buffered","BufferedSignalEntity","attributes","RunAttributeEntity","reindexAttributes","runId","em","repo","delete","rows","normalizeAttributeRows","length","insert","createRun","run","save","toRunEntity","id","searchAttributes","updateRun","patch","update","workflow","workflowVersion","status","input","output","error","wakeAt","Date","lockedBy","lockedUntil","awaitingDecisionTaskId","recoveryAttempts","tags","priority","createdAt","updatedAt","result","createQueryBuilder","set","where","execute","affected","Error","getRun","e","findOneBy","fromRunEntity","deleteRun","getCheckpoint","seq","fromCheckpointEntity","saveCheckpoint","checkpoint","entity","toCheckpointEntity","upsert","transaction","work","raw","cp","listIncompleteRuns","findBy","In","map","listPendingRuns","limit","find","order","take","listDueTimers","nowMs","LessThanOrEqual","tryLockRun","owner","leaseUntilMs","andWhere","Brackets","qb","IsNull","orWhere","releaseRunLock","renewRunLock","listRuns","query","statuses","tag","tagPattern","forEach","f","i","applyAttributeExists","orderBy","offset","skip","getMany","valueProperty","attributeColumnFor","cmp","sqlComparator","op","keyParam","valParam","resolve","durableColumnResolver","q","idQuote","wrap","name","runIdCol","keyCol","valueCol","runPkCol","table","a","sql","key","attributeOperand","type","String","options","listCheckpoints","getLatestCheckpointByName","findOne","undefined","listCheckpointsByNamePrefix","prefixes","p","Like","putSignalWaiter","waiter","token","parallelGroup","listSignalWaiters","prefix","takeSignalWaiter","removeSignalWaiter","bufferSignal","payload","takeBufferedSignal","getTime","kind","stepId","events","attempts","workerGroup","enqueuedAt","startedAt","finishedAt"]}
|
|
1
|
+
{"version":3,"sources":["../src/entities.ts","../src/schema.ts","../src/typeorm-state-store.ts"],"sourcesContent":["import type { RunStatus, StepKind } from '@dudousxd/nestjs-durable-core';\nimport { EntitySchema, type ValueTransformer } from 'typeorm';\n\n/**\n * Safely deserialize a JSON-text column back to an object on READ.\n *\n * A column truncated by the old MySQL `text` 64KB limit (or otherwise corrupt) makes `JSON.parse`\n * throw \"Unterminated string in JSON\" — which, without this guard, would 500 the *entire* run-detail\n * read just because one blob is damaged. Instead, log once and degrade the bad field to `undefined`\n * so the rest of the run still renders. Valid JSON is unchanged.\n */\nexport function parseJsonColumn<T = unknown>(raw: unknown, field: string): T | undefined {\n if (raw == null) return undefined;\n // Some drivers (e.g. a native `json` column) already hand back a parsed object.\n if (typeof raw !== 'string') return raw as T;\n try {\n return JSON.parse(raw) as T;\n } catch (err) {\n console.warn(\n `durable store: failed to parse ${field} column, degrading to undefined: ${\n (err as Error).message\n }`,\n );\n return undefined;\n }\n}\n\n/**\n * TypeORM transformer for the free-form JSON-blob columns. Mirrors the built-in `simple-json`\n * serialization on WRITE (`JSON.stringify`, SQL NULL stays NULL) but uses {@link parseJsonColumn}\n * on READ so a single corrupt/truncated row degrades to `undefined` instead of throwing.\n */\nfunction jsonColumnTransformer(field: string): ValueTransformer {\n return {\n to: (value: unknown) => (value == null ? null : JSON.stringify(value)),\n from: (value: unknown) => parseJsonColumn(value, field),\n };\n}\n\n/**\n * How property names map to physical column names. The durable tables are adapter-agnostic: a run\n * written by one store adapter must be readable by another, so every adapter has to agree on the\n * physical column names. The default is `'snake_case'` (the canonical, matched by the MikroORM,\n * Prisma and Drizzle adapters). `'preserve'` keeps the camelCase property name verbatim (what the\n * old TypeORM/Prisma adapters produced before they were pinned). A function lets you supply any\n * custom mapping.\n *\n * The choice is pinned EXPLICITLY onto the entity schema rather than left to the host ORM's naming\n * strategy — depending on the host strategy is what silently diverged the adapters and broke a store\n * swap against an existing table.\n */\nexport type DurableColumnNaming = 'snake_case' | 'preserve' | ((property: string) => string);\n\nfunction snakeCase(property: string): string {\n return property.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);\n}\n\n/** Resolve a `DurableColumnNaming` to a `(property) => columnName` function. */\nexport function columnNamer(naming: DurableColumnNaming): (property: string) => string {\n if (naming === 'snake_case') return snakeCase;\n if (naming === 'preserve') return (property) => property;\n return naming;\n}\n\n// Plain classes (no decorators): the schema/column mapping lives on the EntitySchema built by\n// `durableEntities`, so the same class can be registered under different column names. The store\n// still references these classes for `getRepository`/`getMetadata`.\n\nexport class WorkflowRunEntity {\n id!: string;\n workflow!: string;\n workflowVersion!: string;\n status!: RunStatus;\n input?: unknown;\n output?: unknown;\n error?: unknown;\n wakeAt?: Date;\n lockedBy?: string | null;\n lockedUntil?: Date;\n awaitingDecisionTaskId?: string | null;\n recoveryAttempts?: number;\n tags?: string[] | null;\n searchAttributes?: Record<string, string | number | boolean> | null;\n priority?: number | null;\n createdAt!: Date;\n updatedAt!: Date;\n}\n\nexport class StepCheckpointEntity {\n runId!: string;\n seq!: number;\n name!: string;\n kind!: StepKind;\n stepId!: string;\n status!: 'pending' | 'running' | 'completed' | 'failed';\n input?: unknown;\n output?: unknown;\n error?: unknown;\n events?: unknown;\n attempts!: number;\n workerGroup?: string | null;\n parallelGroup?: string | null;\n wakeAt?: Date;\n enqueuedAt?: Date;\n startedAt!: 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 */\nexport class RunAttributeEntity {\n runId!: string;\n key!: string;\n strValue?: string | null;\n numValue?: number | null;\n}\n\nexport class SignalWaiterEntity {\n token!: string;\n runId!: string;\n seq!: number;\n parallelGroup?: string | null;\n}\n\nexport class BufferedSignalEntity {\n id!: number;\n token!: string;\n payload?: unknown;\n}\n\n/** A published event that matched no live waiter (see `engine.publishEvent`'s buffering). Keyed by a\n * caller-minted `id` (a uuid, not autoincrement — `removeBufferedEvent` targets it directly), not by\n * `runId`: events are name-based pub/sub, not tied to any one run. */\nexport class BufferedEventEntity {\n id!: string;\n name!: string;\n payload?: unknown;\n publishedAt!: Date;\n}\n\n/**\n * Build the durable TypeORM entity schemas with column names pinned per `naming` (default\n * `'snake_case'`). Register the result in your `DataSource`/`TypeOrmModule.forFeature`. The JSON-blob\n * columns keep the `jsonColumnTransformer` (corruption-tolerant read), the primary keys / auto-\n * increment / nullability are preserved, and the `id` of `durable_buffered_signals` stays a driver-\n * native auto-increment column.\n *\n * ```ts\n * entities: durableEntities({ naming: 'snake_case' })\n * ```\n */\nexport function durableEntities(options: { naming?: DurableColumnNaming } = {}): EntitySchema[] {\n const col = columnNamer(options.naming ?? 'snake_case');\n\n const workflowRuns = new EntitySchema<WorkflowRunEntity>({\n name: 'WorkflowRunEntity',\n target: WorkflowRunEntity,\n tableName: 'durable_workflow_runs',\n columns: {\n id: { type: 'text', primary: true, name: col('id') },\n workflow: { type: 'text', name: col('workflow') },\n workflowVersion: { type: 'text', name: col('workflowVersion') },\n status: { type: 'text', name: col('status') },\n input: {\n type: 'text',\n nullable: true,\n name: col('input'),\n transformer: jsonColumnTransformer('runs.input'),\n },\n output: {\n type: 'text',\n nullable: true,\n name: col('output'),\n transformer: jsonColumnTransformer('runs.output'),\n },\n error: {\n type: 'text',\n nullable: true,\n name: col('error'),\n transformer: jsonColumnTransformer('runs.error'),\n },\n wakeAt: { type: Date, nullable: true, name: col('wakeAt') },\n lockedBy: { type: 'text', nullable: true, name: col('lockedBy') },\n lockedUntil: { type: Date, nullable: true, name: col('lockedUntil') },\n // REMOTE turn the engine suspended on awaiting a decision; matched by completeRemoteDecision so\n // only the currently-awaited turn's decision is applied. Nullable: cleared when a decision lands.\n awaitingDecisionTaskId: {\n type: 'text',\n nullable: true,\n name: col('awaitingDecisionTaskId'),\n },\n recoveryAttempts: { type: 'integer', nullable: true, name: col('recoveryAttempts') },\n tags: {\n type: 'text',\n nullable: true,\n name: col('tags'),\n transformer: jsonColumnTransformer('runs.tags'),\n },\n searchAttributes: {\n type: 'text',\n nullable: true,\n name: col('searchAttributes'),\n transformer: jsonColumnTransformer('runs.searchAttributes'),\n },\n priority: { type: 'integer', nullable: true, name: col('priority') },\n createdAt: { type: Date, name: col('createdAt') },\n updatedAt: { type: Date, name: col('updatedAt') },\n },\n });\n\n const stepCheckpoints = new EntitySchema<StepCheckpointEntity>({\n name: 'StepCheckpointEntity',\n target: StepCheckpointEntity,\n tableName: 'durable_step_checkpoints',\n columns: {\n runId: { type: 'text', primary: true, name: col('runId') },\n seq: { type: 'integer', primary: true, name: col('seq') },\n name: { type: 'text', name: col('name') },\n kind: { type: 'text', name: col('kind') },\n stepId: { type: 'text', name: col('stepId') },\n status: { type: 'text', name: col('status') },\n input: {\n type: 'text',\n nullable: true,\n name: col('input'),\n transformer: jsonColumnTransformer('checkpoints.input'),\n },\n output: {\n type: 'text',\n nullable: true,\n name: col('output'),\n transformer: jsonColumnTransformer('checkpoints.output'),\n },\n error: {\n type: 'text',\n nullable: true,\n name: col('error'),\n transformer: jsonColumnTransformer('checkpoints.error'),\n },\n events: {\n type: 'text',\n nullable: true,\n name: col('events'),\n transformer: jsonColumnTransformer('checkpoints.events'),\n },\n attempts: { type: 'integer', name: col('attempts') },\n workerGroup: { type: 'text', nullable: true, name: col('workerGroup') },\n // A ctx.gather/ctx.all fan tags every sibling step with the same group so the dashboard renders\n // them as one parallel group; the core engine sets it (incl. from a remote worker's recordStep).\n parallelGroup: { type: 'text', nullable: true, name: col('parallelGroup') },\n wakeAt: { type: Date, nullable: true, name: col('wakeAt') },\n enqueuedAt: { type: Date, nullable: true, name: col('enqueuedAt') },\n startedAt: { type: Date, name: col('startedAt') },\n finishedAt: { type: Date, name: col('finishedAt') },\n },\n });\n\n const runAttributes = new EntitySchema<RunAttributeEntity>({\n name: 'RunAttributeEntity',\n target: RunAttributeEntity,\n tableName: 'durable_run_attributes',\n columns: {\n runId: { type: 'text', primary: true, name: col('runId') },\n key: { type: 'text', primary: true, name: col('key') },\n strValue: { type: 'text', nullable: true, name: col('strValue') },\n // `float`/`double` portable across SQLite/MySQL/Postgres for numeric range scans.\n numValue: { type: 'float', nullable: true, name: col('numValue') },\n },\n });\n\n const signalWaiters = new EntitySchema<SignalWaiterEntity>({\n name: 'SignalWaiterEntity',\n target: SignalWaiterEntity,\n tableName: 'durable_signal_waiters',\n columns: {\n token: { type: 'text', primary: true, name: col('token') },\n runId: { type: 'text', name: col('runId') },\n seq: { type: 'integer', name: col('seq') },\n // A ctx.gather_children/ctx.all child fan-out tags every awaited child with the same group; the\n // engine threads it onto the waiter so the resolving `signal:child:` checkpoint carries it and the\n // dashboard renders the fan as one parallel group. Nullable: only fan-out child waiters carry it.\n parallelGroup: { type: 'text', nullable: true, name: col('parallelGroup') },\n },\n });\n\n const bufferedSignals = new EntitySchema<BufferedSignalEntity>({\n name: 'BufferedSignalEntity',\n target: BufferedSignalEntity,\n tableName: 'durable_buffered_signals',\n columns: {\n // Auto-increment PK for FIFO ordering. Left as TypeORM's default increment generation so it\n // maps to the driver-native auto-increment column (INTEGER on SQLite, BIGINT/SERIAL elsewhere).\n id: { type: Number, primary: true, generated: 'increment', name: col('id') },\n token: { type: 'text', name: col('token') },\n payload: {\n type: 'text',\n nullable: true,\n name: col('payload'),\n transformer: jsonColumnTransformer('buffered.payload'),\n },\n },\n });\n\n const bufferedEvents = new EntitySchema<BufferedEventEntity>({\n name: 'BufferedEventEntity',\n target: BufferedEventEntity,\n tableName: 'durable_buffered_events',\n // No `indices` here (unlike MikroORM's EntitySchema, which does declare one): this store manages\n // its DDL — including the `(name, publishedAt)` index — via raw SQL in `schema.ts`'s\n // `ensureTypeOrmDurableSchema`, the same as every other durable_* table's indexes.\n columns: {\n // Caller-minted uuid (engine.publishEvent), not autoincrement — removeBufferedEvent targets it\n // directly and needs to be handed the SAME id it was buffered with.\n id: { type: 'text', primary: true, name: col('id') },\n name: { type: 'text', name: col('name') },\n payload: {\n type: 'text',\n nullable: true,\n name: col('payload'),\n transformer: jsonColumnTransformer('buffered.eventPayload'),\n },\n publishedAt: { type: Date, name: col('publishedAt') },\n },\n });\n\n return [\n workflowRuns,\n stepCheckpoints,\n runAttributes,\n signalWaiters,\n bufferedSignals,\n bufferedEvents,\n ];\n}\n\n/** Durable entity schemas with the canonical `'snake_case'` column names. */\nexport const ENTITIES = durableEntities();\n","import type { DataSource } from 'typeorm';\nimport {\n BufferedEventEntity,\n BufferedSignalEntity,\n RunAttributeEntity,\n SignalWaiterEntity,\n StepCheckpointEntity,\n WorkflowRunEntity,\n} from './entities';\n\n/** The JSON-blob columns per table (keyed by table name) that hold free-form payloads and so must\n * be the unbounded text type — `longtext` on MySQL, `text` elsewhere. Keyed by entity PROPERTY name;\n * the physical column is resolved from the DataSource metadata so it tracks the configured naming. */\nexport const JSON_BLOB_COLUMNS: Record<string, string[]> = {\n durable_workflow_runs: ['input', 'output', 'error', 'tags', 'searchAttributes'],\n durable_step_checkpoints: ['input', 'output', 'error', 'events'],\n // NOTE: durable_buffered_signals/durable_buffered_events intentionally omitted here, same as the\n // existing buffered-signals table — their `payload` column is created with the widened `txt` type\n // (see `${bufCol('payload')} ${txt}` / the new table's `${bevCol('payload')} ${txt}` below) directly\n // at CREATE TABLE time on a fresh install, so there's no pre-existing narrower column to widen.\n};\n\n/** Each durable table → its backing entity class, so a column resolver can look up the physical\n * column for any (table, property) from the DataSource metadata (which reflects the configured\n * `DurableColumnNaming`). Keeps the raw DDL/SQL in lock-step with the entity column mapping. */\nconst TABLE_TO_ENTITY = {\n durable_workflow_runs: WorkflowRunEntity,\n durable_step_checkpoints: StepCheckpointEntity,\n durable_run_attributes: RunAttributeEntity,\n durable_signal_waiters: SignalWaiterEntity,\n durable_buffered_signals: BufferedSignalEntity,\n durable_buffered_events: BufferedEventEntity,\n} as const;\n\n/**\n * Tables this store creates and manages at boot (autoSchema, see {@link ensureTypeOrmDurableSchema}).\n * Feed to your ORM's migration differ exclude/skipTables so it never tries to drop them.\n *\n * ```ts\n * // MikroORM-flavoured example (TypeORM has no built-in equivalent option); adapt to whichever\n * // migration tool generates your diffs — e.g. exclude these names from a typeorm-generated\n * // migration, or filter them out of `SELECT table_name FROM information_schema.tables` before\n * // diffing against your own entities.\n * const skipTables = new Set(durableManagedTables());\n * ```\n *\n * Derived from the same {@link TABLE_TO_ENTITY} map the raw-SQL heal keys its column resolution off\n * — one list, so a consumer's denylist can never drift from what this store actually owns.\n */\nexport function durableManagedTables(): string[] {\n return Object.keys(TABLE_TO_ENTITY);\n}\n\n/**\n * Resolve `(table, property) => physical column name` from the DataSource's entity metadata. The\n * column names are NOT hardcoded here: they come from whatever the registered `durableEntities`\n * mapped (canonical `snake_case` by default, `'preserve'` for the legacy camelCase, or a custom\n * mapping), so the raw `CREATE TABLE`/index/EXISTS SQL always matches the entities and can never\n * silently diverge.\n */\nexport function durableColumnResolver(\n dataSource: DataSource,\n): (table: string, property: string) => string {\n return (table, property) => {\n const entity = TABLE_TO_ENTITY[table as keyof typeof TABLE_TO_ENTITY];\n if (!entity) throw new Error(`durable store: unknown table \"${table}\"`);\n const meta = dataSource.getMetadata(entity);\n const column = meta.findColumnWithPropertyName(property);\n if (!column) {\n throw new Error(`durable store: no column for ${table}.${property} in entity metadata`);\n }\n return column.databaseName;\n };\n}\n\n/** The SQL type for free-form JSON-blob columns. MySQL `text` caps at 64KB and silently truncates,\n * so use `longtext` (4GB) there; Postgres/SQLite `text` is already unbounded. */\nexport function jsonBlobColumnType(isMysql: boolean): 'longtext' | 'text' {\n return isMysql ? 'longtext' : 'text';\n}\n\n/** Idempotent `MODIFY COLUMN ... longtext` statements that widen pre-existing MySQL `text` JSON-blob\n * columns. Returns `[]` on non-MySQL dialects (their `text` is already unbounded — nothing to do).\n * `quote` quotes an identifier per the active driver; `col` resolves a property to its physical\n * column name so the widen tracks the configured naming. */\nexport function buildWidenStatements(\n isMysql: boolean,\n quote: (id: string) => string,\n col: (table: string, property: string) => string,\n): string[] {\n if (!isMysql) return [];\n const out: string[] = [];\n for (const [table, props] of Object.entries(JSON_BLOB_COLUMNS)) {\n for (const prop of props) {\n out.push(`ALTER TABLE ${quote(table)} MODIFY COLUMN ${quote(col(table, prop))} longtext`);\n }\n }\n return out;\n}\n\n/**\n * Idempotently create the durable tables. Safe to run on every boot (auto-schema) and the\n * exact function to call from your own TypeORM migration when you disable auto-schema:\n *\n * ```ts\n * export class AddDurableTables implements MigrationInterface {\n * async up(q: QueryRunner) { await ensureTypeOrmDurableSchema(q.connection); }\n * }\n * ```\n *\n * Dialect-aware (MySQL / MariaDB / Postgres / SQLite): identifiers are quoted per driver, keyed\n * string columns are `varchar` (MySQL can't key a `text` column), and the index is best-effort.\n * Only ever adds the three durable tables — it never touches your other tables.\n */\nexport async function ensureTypeOrmDurableSchema(dataSource: DataSource): Promise<void> {\n const q = (id: string) => dataSource.driver.escape(id);\n // Physical column names come from the entity metadata (canonical snake_case by default), so this\n // raw DDL always matches the registered `durableEntities` instead of hardcoding camelCase.\n const resolve = durableColumnResolver(dataSource);\n const type = String(dataSource.options.type);\n const isPg = type === 'postgres' || type === 'aurora-postgres';\n const isMysql = type === 'mysql' || type === 'mariadb' || type === 'aurora-mysql';\n const isSqlite = type === 'sqlite' || type === 'better-sqlite3' || type === 'expo';\n\n // Keyed/short strings must be varchar on MySQL (a `text` PK/index needs a key length); `text`\n // for the free-form JSON payloads. Dates use the dialect's native timestamp type.\n const str = 'varchar(191)';\n // Free-form JSON payloads (`input`/`output`/`error`/`events`/`tags`/`searchAttributes`). MySQL's\n // `text` caps at 64KB and *silently truncates* — a large fan-out step's `events` then fails to\n // parse on read (\"Unterminated string in JSON\"). Use `longtext` (4GB) on MySQL; Postgres `text`\n // is already unbounded and SQLite `text` has no length limit.\n const txt = jsonBlobColumnType(isMysql);\n const int = isMysql ? 'int' : 'integer';\n const ts = isPg ? 'timestamptz' : 'datetime';\n\n const runs = q('durable_workflow_runs');\n const checkpoints = q('durable_step_checkpoints');\n const runAttributes = q('durable_run_attributes');\n const waiters = q('durable_signal_waiters');\n const buffered = q('durable_buffered_signals');\n const bufferedEvents = q('durable_buffered_events');\n // Per-table quoted-column helpers: resolve an entity property to its physical column then quote it.\n const runsCol = (property: string) => q(resolve('durable_workflow_runs', property));\n const cpCol = (property: string) => q(resolve('durable_step_checkpoints', property));\n const attrCol = (property: string) => q(resolve('durable_run_attributes', property));\n const waiterCol = (property: string) => q(resolve('durable_signal_waiters', property));\n const bufCol = (property: string) => q(resolve('durable_buffered_signals', property));\n const bevCol = (property: string) => q(resolve('durable_buffered_events', property));\n // Numeric side-table column for attribute range scans. `double precision` on Postgres, `double` on\n // MySQL, `real` on SQLite (all hold JS numbers without precision loss for the typical attribute).\n const num = isPg ? 'double precision' : isMysql ? 'double' : 'real';\n\n // Auto-increment PK syntax differs per dialect: SQLite wants `INTEGER PRIMARY KEY AUTOINCREMENT`,\n // MySQL `BIGINT AUTO_INCREMENT PRIMARY KEY`, Postgres `BIGSERIAL PRIMARY KEY`.\n const bufferedId = isSqlite\n ? `${bufCol('id')} integer PRIMARY KEY AUTOINCREMENT`\n : isMysql\n ? `${bufCol('id')} bigint NOT NULL AUTO_INCREMENT PRIMARY KEY`\n : isPg\n ? `${bufCol('id')} bigserial PRIMARY KEY`\n : `${bufCol('id')} bigint NOT NULL AUTO_INCREMENT PRIMARY KEY`;\n\n const tables = [\n `CREATE TABLE IF NOT EXISTS ${runs} (\n ${runsCol('id')} ${str} PRIMARY KEY,\n ${runsCol('workflow')} ${str} NOT NULL,\n ${runsCol('workflowVersion')} ${str} NOT NULL,\n ${runsCol('status')} ${str} NOT NULL,\n ${runsCol('input')} ${txt}, ${runsCol('output')} ${txt}, ${runsCol('error')} ${txt},\n ${runsCol('wakeAt')} ${ts}, ${runsCol('lockedBy')} ${str}, ${runsCol('lockedUntil')} ${ts},\n ${runsCol('awaitingDecisionTaskId')} ${str},\n ${runsCol('recoveryAttempts')} ${int}, ${runsCol('tags')} ${txt}, ${runsCol('searchAttributes')} ${txt},\n ${runsCol('priority')} ${int},\n ${runsCol('createdAt')} ${ts} NOT NULL, ${runsCol('updatedAt')} ${ts} NOT NULL\n )`,\n `CREATE TABLE IF NOT EXISTS ${checkpoints} (\n ${cpCol('runId')} ${str} NOT NULL, ${cpCol('seq')} ${int} NOT NULL,\n ${cpCol('name')} ${str} NOT NULL, ${cpCol('kind')} ${str} NOT NULL, ${cpCol('stepId')} ${str} NOT NULL,\n ${cpCol('status')} ${str} NOT NULL, ${cpCol('input')} ${txt}, ${cpCol('output')} ${txt}, ${cpCol('error')} ${txt}, ${cpCol('events')} ${txt},\n ${cpCol('attempts')} ${int} NOT NULL, ${cpCol('workerGroup')} ${str}, ${cpCol('parallelGroup')} ${str},\n ${cpCol('wakeAt')} ${ts}, ${cpCol('enqueuedAt')} ${ts},\n ${cpCol('startedAt')} ${ts} NOT NULL, ${cpCol('finishedAt')} ${ts} NOT NULL,\n PRIMARY KEY (${cpCol('runId')}, ${cpCol('seq')})\n )`,\n // Normalized search-attribute side-table: one row per (run, key) so attribute predicates push\n // DOWN into SQL via an EXISTS join (indexed below). `key` is keyed → must be varchar on MySQL.\n `CREATE TABLE IF NOT EXISTS ${runAttributes} (\n ${attrCol('runId')} ${str} NOT NULL, ${attrCol('key')} ${str} NOT NULL,\n ${attrCol('strValue')} ${str}, ${attrCol('numValue')} ${num},\n PRIMARY KEY (${attrCol('runId')}, ${attrCol('key')})\n )`,\n `CREATE TABLE IF NOT EXISTS ${waiters} (\n ${waiterCol('token')} ${str} PRIMARY KEY, ${waiterCol('runId')} ${str} NOT NULL, ${waiterCol('seq')} ${int} NOT NULL,\n ${waiterCol('parallelGroup')} ${str}\n )`,\n `CREATE TABLE IF NOT EXISTS ${buffered} (\n ${bufferedId}, ${bufCol('token')} ${str} NOT NULL, ${bufCol('payload')} ${txt}\n )`,\n // Caller-minted uuid PK (engine.publishEvent), not auto-increment — unlike durable_buffered_signals\n // above, removeBufferedEvent needs to target the EXACT id it was buffered with.\n `CREATE TABLE IF NOT EXISTS ${bufferedEvents} (\n ${bevCol('id')} ${str} PRIMARY KEY, ${bevCol('name')} ${str} NOT NULL,\n ${bevCol('payload')} ${txt}, ${bevCol('publishedAt')} ${ts} NOT NULL\n )`,\n ];\n\n // Additive nullable columns gained across versions (e.g. `input`, `events`, `enqueuedAt`). On a\n // table that predates them, `CREATE TABLE IF NOT EXISTS` above is a no-op, so back-fill the ones\n // that are actually missing — the auto-schema self-heals instead of needing a manual migration.\n // We check the live columns first (rather than ALTER-and-ignore) so a *real* ALTER failure\n // surfaces instead of being swallowed as a presumed \"column already exists\".\n // Keyed by entity PROPERTY name; the physical column is resolved per-table so the ADD COLUMN\n // tracks the configured naming.\n const additive: Record<string, Array<[string, string]>> = {\n durable_workflow_runs: [\n ['input', txt],\n ['output', txt],\n ['error', txt],\n ['awaitingDecisionTaskId', str],\n ['recoveryAttempts', int],\n ['tags', txt],\n ['searchAttributes', txt],\n ['priority', int],\n ],\n durable_step_checkpoints: [\n ['input', txt],\n ['output', txt],\n ['error', txt],\n ['events', txt],\n ['workerGroup', str],\n ['parallelGroup', str],\n ['enqueuedAt', ts],\n ],\n // Back-fill the child-await fan group onto signal-waiter tables that predate it (a remote\n // `gather_children` fan-out threads its group here so the resolved `signal:child:` checkpoint carries it).\n durable_signal_waiters: [['parallelGroup', str]],\n };\n\n const runner = dataSource.createQueryRunner();\n try {\n for (const sql of tables) await runner.query(sql);\n for (const [table, props] of Object.entries(additive)) {\n const have = await existingColumns(runner, table, { isSqlite, isMysql });\n for (const [property, colType] of props) {\n const column = resolve(table, property);\n if (!have.has(column)) {\n await runner.query(`ALTER TABLE ${q(table)} ADD COLUMN ${q(column)} ${colType}`);\n }\n }\n }\n // Widen pre-existing MySQL `text` JSON-blob columns to `longtext`. A table created before this\n // fix has these as `text` (64KB) and silently truncates large `events`/`output` payloads. MODIFY\n // to `longtext` is idempotent (no-op if already longtext), so it's safe to run on every boot.\n // MySQL-only: Postgres/SQLite `text` is already unbounded, so there's nothing to widen.\n for (const sql of buildWidenStatements(isMysql, q, resolve)) {\n try {\n await runner.query(sql);\n } catch {\n /* column already longtext, or table/column not present on this deploy */\n }\n }\n // MySQL has no `CREATE INDEX IF NOT EXISTS`; create each best-effort and ignore \"already exists\".\n // - status/wakeAt: the timer poller (listDueTimers) and recovery (listIncompleteRuns) scans.\n // - workflow/status: the dashboard's listRuns filters. (Checkpoints are keyed by the PK prefix\n // `(runId, seq)`, so listCheckpoints/getEvent already hit an index — no extra one needed.)\n const indexes: Array<[string, string]> = [\n ['durable_runs_status_idx', `${runs} (${runsCol('status')}, ${runsCol('wakeAt')})`],\n [\n 'durable_runs_workflow_status_idx',\n `${runs} (${runsCol('workflow')}, ${runsCol('status')})`,\n ],\n // buffered signals are taken FIFO per token (smallest id) — index the token for the scan.\n ['durable_buffered_signals_token_idx', `${buffered} (${bufCol('token')})`],\n // buffered events are scanned oldest-first per name — one composite index serves both.\n [\n 'durable_buffered_events_name_published_at_idx',\n `${bufferedEvents} (${bevCol('name')}, ${bevCol('publishedAt')})`,\n ],\n // Search-attribute pushdown: equality + range predicates probe by (key, value). Two composite\n // indexes — one per typed column — so a numeric range or a string equality is an index scan.\n [\n 'durable_run_attributes_num_idx',\n `${runAttributes} (${attrCol('key')}, ${attrCol('numValue')})`,\n ],\n [\n 'durable_run_attributes_str_idx',\n `${runAttributes} (${attrCol('key')}, ${attrCol('strValue')})`,\n ],\n ];\n for (const [name, target] of indexes) {\n try {\n await runner.query(`CREATE INDEX ${q(name)} ON ${target}`);\n } catch {\n /* index already exists */\n }\n }\n } finally {\n await runner.release();\n }\n}\n\n/** The columns that currently exist on `table`, so the schema can add only the missing ones\n * (instead of ALTER-and-swallow, which would also hide a genuine ALTER failure). */\nasync function existingColumns(\n runner: { query: (sql: string, params?: unknown[]) => Promise<unknown> },\n table: string,\n d: { isSqlite: boolean; isMysql: boolean },\n): Promise<Set<string>> {\n if (d.isSqlite) {\n const rows = (await runner.query(`PRAGMA table_info(\"${table}\")`)) as Array<{ name: string }>;\n return new Set(rows.map((r) => r.name));\n }\n // Postgres + MySQL both expose information_schema; scope to the connection's own schema/db.\n // Bind-param placeholder differs: Postgres uses `$1`, MySQL uses `?` (TypeORM only rewrites `?`\n // inside the query builder, not for these raw `runner.query` calls), so pick per dialect.\n const scope = d.isMysql ? 'TABLE_SCHEMA = DATABASE()' : 'table_schema = current_schema()';\n const placeholder = d.isMysql ? '?' : '$1';\n const rows = (await runner.query(\n `SELECT column_name AS name FROM information_schema.columns WHERE table_name = ${placeholder} AND ${scope}`,\n [table],\n )) as Array<{ name?: string; COLUMN_NAME?: string }>;\n return new Set(rows.map((r) => (r.name ?? r.COLUMN_NAME) as string));\n}\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 {\n Brackets,\n type DataSource,\n type EntityManager,\n In,\n IsNull,\n LessThanOrEqual,\n Like,\n type SelectQueryBuilder,\n} from 'typeorm';\nimport type { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';\nimport {\n BufferedEventEntity,\n BufferedSignalEntity,\n RunAttributeEntity,\n SignalWaiterEntity,\n StepCheckpointEntity,\n WorkflowRunEntity,\n} from './entities';\nimport { durableColumnResolver, ensureTypeOrmDurableSchema } from './schema';\n\n/**\n * TypeORM-backed `StateStore`. Works on any TypeORM driver — Postgres, MySQL, SQLite (tested);\n * timestamps use native datetime columns and `wakeAt` is stored as a datetime too.\n */\nexport class TypeOrmStateStore implements StateStore {\n constructor(private readonly dataSource: DataSource) {}\n\n async ensureSchema(): Promise<void> {\n await ensureTypeOrmDurableSchema(this.dataSource);\n }\n\n private runs() {\n return this.dataSource.getRepository(WorkflowRunEntity);\n }\n private checkpoints() {\n return this.dataSource.getRepository(StepCheckpointEntity);\n }\n private waiters() {\n return this.dataSource.getRepository(SignalWaiterEntity);\n }\n private buffered() {\n return this.dataSource.getRepository(BufferedSignalEntity);\n }\n private bufferedEvents() {\n return this.dataSource.getRepository(BufferedEventEntity);\n }\n private attributes() {\n return this.dataSource.getRepository(RunAttributeEntity);\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 em?: EntityManager,\n ): Promise<void> {\n const repo = em ? em.getRepository(RunAttributeEntity) : this.attributes();\n await repo.delete({ runId });\n const rows = normalizeAttributeRows(runId, attributes);\n if (rows.length) await repo.insert(rows);\n }\n\n async createRun(run: WorkflowRun): Promise<void> {\n await this.runs().save(toRunEntity(run));\n await this.reindexAttributes(run.id, run.searchAttributes);\n }\n\n async updateRun(runId: string, patch: Partial<WorkflowRun>): Promise<void> {\n // Single UPDATE (no pre-SELECT + save round-trips): map only the patched fields. The query\n // builder still applies the entities' JSON column transformers to the `set` values (as in\n // listRuns/tryLockRun). Preserve the not-found throw any caller may rely on.\n const update: Record<string, unknown> = {};\n if ('workflow' in patch) update.workflow = patch.workflow;\n if ('workflowVersion' in patch) update.workflowVersion = patch.workflowVersion;\n if ('status' in patch) update.status = patch.status;\n if ('input' in patch) update.input = patch.input ?? null;\n if ('output' in patch) update.output = patch.output ?? null;\n if ('error' in patch) update.error = patch.error ?? null;\n if ('wakeAt' in patch) update.wakeAt = patch.wakeAt == null ? null : new Date(patch.wakeAt);\n if ('lockedBy' in patch) update.lockedBy = patch.lockedBy ?? null;\n if ('lockedUntil' in patch)\n update.lockedUntil = patch.lockedUntil == null ? null : new Date(patch.lockedUntil);\n if ('awaitingDecisionTaskId' in patch)\n update.awaitingDecisionTaskId = patch.awaitingDecisionTaskId ?? null;\n if ('recoveryAttempts' in patch) update.recoveryAttempts = patch.recoveryAttempts;\n if ('tags' in patch) update.tags = patch.tags ?? null;\n if ('searchAttributes' in patch) update.searchAttributes = patch.searchAttributes ?? null;\n if ('priority' in patch) update.priority = patch.priority ?? null;\n if ('createdAt' in patch) update.createdAt = patch.createdAt;\n if ('updatedAt' in patch) update.updatedAt = patch.updatedAt;\n const result = await this.runs()\n .createQueryBuilder()\n .update()\n .set(update)\n .where({ id: runId })\n .execute();\n if (!result.affected) throw new Error(`run ${runId} not found`);\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 async getRun(runId: string): Promise<WorkflowRun | null> {\n const e = await this.runs().findOneBy({ id: runId });\n return e ? fromRunEntity(e) : null;\n }\n\n async deleteRun(runId: string): Promise<void> {\n // Child rows first, then the run — checkpoints, signal waiters, attribute rows.\n await this.checkpoints().delete({ runId });\n await this.waiters().delete({ runId });\n await this.attributes().delete({ runId });\n await this.runs().delete({ id: runId });\n }\n\n async getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null> {\n const e = await this.checkpoints().findOneBy({ runId, seq });\n return e ? fromCheckpointEntity(e) : null;\n }\n\n async saveCheckpoint(checkpoint: StepCheckpoint): Promise<void> {\n // upsert = INSERT ... ON CONFLICT DO UPDATE on the (runId, seq) key — drops the pre-SELECT that\n // `.save()` does on each write. JSON column transformers still apply for upsert.\n const entity = toCheckpointEntity(checkpoint) as QueryDeepPartialEntity<StepCheckpointEntity>;\n await this.checkpoints().upsert(entity, ['runId', 'seq']);\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.dataSource.transaction(async (em) =>\n work({\n raw: em,\n saveCheckpoint: async (cp) => {\n await em.getRepository(StepCheckpointEntity).save(toCheckpointEntity(cp));\n },\n }),\n );\n }\n\n async listIncompleteRuns(): Promise<WorkflowRun[]> {\n const rows = await this.runs().findBy({ status: In(['running', 'cancelling']) });\n return rows.map(fromRunEntity);\n }\n\n async listPendingRuns(limit: number): Promise<WorkflowRun[]> {\n const rows = await this.runs().find({\n where: { status: 'pending' },\n order: { createdAt: 'ASC' }, // FIFO dispatch\n take: limit,\n });\n return rows.map(fromRunEntity);\n }\n\n async listDueTimers(nowMs: number): Promise<WorkflowRun[]> {\n const rows = await this.runs().findBy({\n status: 'suspended',\n wakeAt: LessThanOrEqual(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 result = await this.runs()\n .createQueryBuilder()\n .update()\n .set({ lockedBy: owner, lockedUntil: new Date(leaseUntilMs) })\n .where({ id: runId })\n .andWhere(\n new Brackets((qb) =>\n qb\n .where({ lockedUntil: IsNull() })\n .orWhere({ lockedUntil: LessThanOrEqual(new Date(nowMs)) }),\n ),\n )\n .execute();\n return result.affected === 1;\n }\n\n async releaseRunLock(runId: string): Promise<void> {\n await this.runs().update({ id: runId }, { lockedBy: null, lockedUntil: () => 'NULL' });\n }\n\n async renewRunLock(runId: string, owner: string, leaseUntilMs: number): Promise<boolean> {\n const result = await this.runs()\n .createQueryBuilder()\n .update()\n .set({ lockedUntil: new Date(leaseUntilMs) })\n .where({ id: runId, lockedBy: owner })\n .execute();\n return result.affected === 1;\n }\n\n async listRuns(query: RunQuery): Promise<WorkflowRun[]> {\n // `tags` carries a custom JSON transformer, and TypeORM applies a column transformer's `to()` to\n // FindOperator values too — so a `Like('%\"etl\"%')` in a plain `where` would be JSON-stringified\n // and corrupt the LIKE pattern. Use the query builder with a raw parameter to bypass that.\n const qb = this.runs().createQueryBuilder('r');\n if (query.workflow) qb.andWhere('r.workflow = :workflow', { workflow: query.workflow });\n if (query.status) qb.andWhere('r.status = :status', { status: query.status });\n if (query.statuses)\n qb.andWhere(\n query.statuses.length ? 'r.status IN (:...statuses)' : '1 = 0',\n query.statuses.length ? { statuses: query.statuses } : {},\n );\n // `tags` is a JSON-text column; match the quoted token so `etl` doesn't match `etl-foo`. NOTE: a\n // leading-wildcard LIKE on JSON text is NOT index-friendly (no B-tree index can serve `%\"x\"%`), so\n // tag-filtered scans (e.g. singleton admission) are sequential over `durable_runs_workflow_status_idx`'s\n // result set. The `statuses`/`workflow` predicates above bound that scan; if tag scans ever dominate,\n // promote tags to a normalized join table or a JSON/GIN index — a schema change, intentionally not done here.\n if (query.tag) qb.andWhere('r.tags LIKE :tagPattern', { tagPattern: `%\"${query.tag}\"%` });\n // Typed/range attribute predicates push DOWN into SQL: each filter becomes an EXISTS against the\n // normalized `durable_run_attributes` side-table (indexed on (key, numValue)/(key, strValue)), so\n // the DB does the filtering AND the LIMIT/OFFSET — no full scan + in-process filter. ANDed: a run\n // must satisfy every filter, so one EXISTS per filter.\n if (query.attributes?.length) {\n query.attributes.forEach((f, i) => this.applyAttributeExists(qb, f, i));\n }\n qb.orderBy('r.createdAt', 'DESC'); // newest first — recent runs on top in the dashboard\n if (query.limit != null) qb.take(query.limit);\n if (query.offset != null) qb.skip(query.offset);\n const rows = await qb.getMany();\n return rows.map(fromRunEntity);\n }\n\n /** Add one attribute predicate to `qb` as an EXISTS subquery on the side-table. `i` namespaces the\n * bind params so multiple ANDed filters don't collide. */\n private applyAttributeExists(\n qb: SelectQueryBuilder<WorkflowRunEntity>,\n f: AttributeFilter,\n i: number,\n ): void {\n const valueProperty = attributeColumnFor(f); // 'numValue' | 'strValue' (entity property)\n const cmp = sqlComparator(f.op);\n const keyParam = `attrKey${i}`;\n const valParam = `attrVal${i}`;\n // Resolve the PHYSICAL column names from the entity metadata so this raw subquery tracks the\n // configured naming (canonical snake_case by default) instead of hardcoding camelCase — which\n // would break the EXISTS pushdown the moment the table is snake_case.\n const resolve = durableColumnResolver(this.dataSource);\n const q = this.idQuote();\n const wrap = (name: string) => `${q}${name}${q}`;\n const runIdCol = wrap(resolve('durable_run_attributes', 'runId'));\n const keyCol = wrap(resolve('durable_run_attributes', 'key'));\n const valueCol = wrap(resolve('durable_run_attributes', valueProperty));\n const runPkCol = wrap(resolve('durable_workflow_runs', 'id'));\n const table = wrap('durable_run_attributes');\n // `<>` (ne) must also exclude rows where the attribute is absent: the missing-key-never-matches\n // contract (see core matchesAttributes). EXISTS already requires the key row to be present, and a\n // row only exists when the value is non-null, so EXISTS(... <> ...) gives exactly ne-with-present.\n const a = `a${i}`;\n const sql = `EXISTS (SELECT 1 FROM ${table} ${a} WHERE ${a}.${runIdCol} = r.${runPkCol} AND ${a}.${keyCol} = :${keyParam} AND ${a}.${valueCol} ${cmp} :${valParam})`;\n qb.andWhere(sql, {\n [keyParam]: f.key,\n [valParam]: attributeOperand(f),\n });\n }\n\n /** The identifier quote char for the active driver (MySQL backtick, others double-quote). */\n private idQuote(): string {\n const type = String(this.dataSource.options.type);\n return type === 'mysql' || type === 'mariadb' || type === 'aurora-mysql' ? '`' : '\"';\n }\n\n async listCheckpoints(runId: string): Promise<StepCheckpoint[]> {\n const rows = await this.checkpoints().find({ where: { runId }, order: { seq: 'ASC' } });\n return rows.map(fromCheckpointEntity);\n }\n\n async getLatestCheckpointByName(\n runId: string,\n name: string,\n ): Promise<StepCheckpoint | undefined> {\n const e = await this.checkpoints().findOne({ where: { runId, name }, order: { seq: 'DESC' } });\n return e ? fromCheckpointEntity(e) : undefined;\n }\n\n async listCheckpointsByNamePrefix(runId: string, prefixes: string[]): Promise<StepCheckpoint[]> {\n if (prefixes.length === 0) return [];\n const rows = await this.checkpoints().find({\n where: prefixes.map((p) => ({ runId, name: Like(`${p}%`) })),\n order: { seq: 'ASC' },\n });\n return rows.map(fromCheckpointEntity);\n }\n\n async putSignalWaiter(waiter: SignalWaiter): Promise<void> {\n await this.waiters().save({\n token: waiter.token,\n runId: waiter.runId,\n seq: waiter.seq,\n parallelGroup: waiter.parallelGroup ?? null,\n });\n }\n\n async listSignalWaiters(prefix: string): Promise<SignalWaiter[]> {\n const rows = await this.waiters().find({ where: { token: Like(`${prefix}%`) } });\n return rows.map((e) => ({\n token: e.token,\n runId: e.runId,\n seq: e.seq,\n parallelGroup: e.parallelGroup ?? undefined,\n }));\n }\n\n async takeSignalWaiter(token: string): Promise<SignalWaiter | null> {\n const e = await this.waiters().findOneBy({ token });\n if (!e) return null;\n const waiter: SignalWaiter = {\n token: e.token,\n runId: e.runId,\n seq: e.seq,\n parallelGroup: e.parallelGroup ?? undefined,\n };\n await this.waiters().delete({ token });\n return waiter;\n }\n\n async removeSignalWaiter(waiter: SignalWaiter): Promise<void> {\n // Exact-match delete (token AND runId AND seq) — a plain `delete({ token })` would remove\n // whatever row currently owns the token, even if a different run has since claimed it.\n await this.waiters().delete({ token: waiter.token, runId: waiter.runId, seq: waiter.seq });\n }\n\n async bufferSignal(token: string, payload: unknown): Promise<void> {\n await this.buffered().save({ token, payload: payload ?? null });\n }\n\n async takeBufferedSignal(token: string): Promise<{ payload: unknown } | null> {\n const e = await this.buffered().findOne({ where: { token }, order: { id: 'ASC' } });\n if (!e) return null;\n await this.buffered().delete({ id: e.id });\n return { payload: e.payload ?? undefined };\n }\n\n async bufferEvent(input: {\n name: string;\n payload: unknown;\n id: string;\n publishedAt: number;\n }): Promise<void> {\n await this.bufferedEvents().save({\n id: input.id,\n name: input.name,\n payload: input.payload ?? null,\n publishedAt: new Date(input.publishedAt),\n });\n }\n\n async listBufferedEvents(\n name: string,\n limit: number,\n ): Promise<Array<{ id: string; payload: unknown; publishedAt: number }>> {\n const rows = await this.bufferedEvents().find({\n where: { name },\n order: { publishedAt: 'ASC' }, // oldest first\n take: limit,\n });\n return rows.map((e) => ({\n id: e.id,\n payload: e.payload ?? undefined,\n publishedAt: e.publishedAt.getTime(),\n }));\n }\n\n async removeBufferedEvent(id: string): Promise<boolean> {\n const result = await this.bufferedEvents().delete({ id });\n return result.affected === 1;\n }\n}\n\nfunction toRunEntity(run: WorkflowRun): WorkflowRunEntity {\n return {\n id: run.id,\n workflow: run.workflow,\n workflowVersion: run.workflowVersion,\n status: run.status,\n input: run.input ?? null,\n output: run.output ?? null,\n error: run.error ?? null,\n ...(run.wakeAt == null ? {} : { wakeAt: new Date(run.wakeAt) }),\n lockedBy: run.lockedBy ?? null,\n ...(run.lockedUntil == null ? {} : { lockedUntil: new Date(run.lockedUntil) }),\n awaitingDecisionTaskId: run.awaitingDecisionTaskId ?? null,\n ...(run.recoveryAttempts === undefined ? {} : { recoveryAttempts: run.recoveryAttempts }),\n tags: run.tags ?? null,\n searchAttributes: run.searchAttributes ?? null,\n priority: run.priority ?? null,\n createdAt: run.createdAt,\n updatedAt: run.updatedAt,\n };\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 == null ? undefined : e.wakeAt.getTime(),\n lockedBy: e.lockedBy ?? undefined,\n lockedUntil: e.lockedUntil == null ? undefined : e.lockedUntil.getTime(),\n awaitingDecisionTaskId: e.awaitingDecisionTaskId ?? undefined,\n recoveryAttempts: e.recoveryAttempts ?? undefined,\n tags: e.tags ?? undefined,\n searchAttributes: e.searchAttributes ?? undefined,\n priority: e.priority ?? undefined,\n createdAt: e.createdAt,\n updatedAt: e.updatedAt,\n };\n}\n\nfunction toCheckpointEntity(cp: StepCheckpoint): StepCheckpointEntity {\n return {\n runId: cp.runId,\n seq: cp.seq,\n name: cp.name,\n kind: cp.kind,\n stepId: cp.stepId,\n status: cp.status,\n input: cp.input ?? null,\n output: cp.output ?? null,\n error: cp.error ?? null,\n events: cp.events ?? null,\n attempts: cp.attempts,\n workerGroup: cp.workerGroup ?? null,\n parallelGroup: cp.parallelGroup ?? null,\n ...(cp.wakeAt == null ? {} : { wakeAt: new Date(cp.wakeAt) }),\n enqueuedAt: cp.enqueuedAt,\n startedAt: cp.startedAt,\n finishedAt: cp.finishedAt,\n };\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 parallelGroup: e.parallelGroup ?? undefined,\n wakeAt: e.wakeAt == null ? undefined : e.wakeAt.getTime(),\n // Older rows predate enqueuedAt; treat the worker start as enqueue time (queue-wait reads zero).\n enqueuedAt: e.enqueuedAt ?? e.startedAt,\n startedAt: e.start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GrC;IACXC,OAAOoC,GAAGpC,SAAS;IACnBC,QAAQmC,GAAGnC,UAAU;IACrBC,OAAOkC,GAAGlC,SAAS;IACnByH,QAAQvF,GAAGuF,UAAU;IACrBC,UAAUxF,GAAGwF;IACbC,aAAazF,GAAGyF,eAAe;IAC/BjB,eAAexE,GAAGwE,iBAAiB;IACnC,GAAIxE,GAAGjC,UAAU,OAAO,CAAC,IAAI;MAAEA,QAAQ,IAAIC,KAAKgC,GAAGjC,MAAM;IAAE;IAC3D2H,YAAY1F,GAAG0F;IACfC,WAAW3F,GAAG2F;IACdC,YAAY5F,GAAG4F;EACjB;AACF;AApBSjG;AAsBT,SAASJ,qBAAqBN,GAAuB;AACnD,SAAO;IACLzC,OAAOyC,EAAEzC;IACT8C,KAAKL,EAAEK;IACP0D,MAAM/D,EAAE+D;IACRqC,MAAMpG,EAAEoG;IACRC,QAAQrG,EAAEqG;IACV3H,QAAQsB,EAAEtB;IACVC,OAAOqB,EAAErB,SAASoG;IAClBnG,QAAQoB,EAAEpB,UAAUmG;IACpBlG,OAAQmB,EAAEnB,SAASkG;IACnBuB,QAAStG,EAAEsG,UAAUvB;IACrBwB,UAAUvG,EAAEuG;IACZC,aAAaxG,EAAEwG,eAAezB;IAC9BQ,eAAevF,EAAEuF,iBAAiBR;IAClCjG,QAAQkB,EAAElB,UAAU,OAAOiG,SAAY/E,EAAElB,OAAOoH,QAAO;;IAEvDO,YAAYzG,EAAEyG,cAAczG,EAAE0G;IAC9BA,WAAW1G,EAAE0G;IACbC,YAAY3G,EAAE2G;EAChB;AACF;AArBSrG;","names":["EntitySchema","parseJsonColumn","raw","field","undefined","JSON","parse","err","console","warn","message","jsonColumnTransformer","to","value","stringify","from","snakeCase","property","replace","c","toLowerCase","columnNamer","naming","WorkflowRunEntity","id","workflow","workflowVersion","status","input","output","error","wakeAt","lockedBy","lockedUntil","awaitingDecisionTaskId","recoveryAttempts","tags","searchAttributes","priority","createdAt","updatedAt","StepCheckpointEntity","runId","seq","name","kind","stepId","events","attempts","workerGroup","parallelGroup","enqueuedAt","startedAt","finishedAt","RunAttributeEntity","key","strValue","numValue","SignalWaiterEntity","token","BufferedSignalEntity","payload","BufferedEventEntity","publishedAt","durableEntities","options","col","workflowRuns","EntitySchema","target","tableName","columns","type","primary","nullable","transformer","Date","stepCheckpoints","runAttributes","signalWaiters","bufferedSignals","Number","generated","bufferedEvents","ENTITIES","JSON_BLOB_COLUMNS","durable_workflow_runs","durable_step_checkpoints","TABLE_TO_ENTITY","WorkflowRunEntity","StepCheckpointEntity","durable_run_attributes","RunAttributeEntity","durable_signal_waiters","SignalWaiterEntity","durable_buffered_signals","BufferedSignalEntity","durable_buffered_events","BufferedEventEntity","durableManagedTables","Object","keys","durableColumnResolver","dataSource","table","property","entity","Error","meta","getMetadata","column","findColumnWithPropertyName","databaseName","jsonBlobColumnType","isMysql","buildWidenStatements","quote","col","out","props","entries","prop","push","ensureTypeOrmDurableSchema","q","id","driver","escape","resolve","type","String","options","isPg","isSqlite","str","txt","int","ts","runs","checkpoints","runAttributes","waiters","buffered","bufferedEvents","runsCol","cpCol","attrCol","waiterCol","bufCol","bevCol","num","bufferedId","tables","additive","runner","createQueryRunner","sql","query","have","existingColumns","colType","has","indexes","name","target","release","d","rows","Set","map","r","scope","placeholder","COLUMN_NAME","attributeColumnFor","attributeOperand","normalizeAttributeRows","sqlComparator","Brackets","In","IsNull","LessThanOrEqual","Like","TypeOrmStateStore","dataSource","ensureSchema","ensureTypeOrmDurableSchema","runs","getRepository","WorkflowRunEntity","checkpoints","StepCheckpointEntity","waiters","SignalWaiterEntity","buffered","BufferedSignalEntity","bufferedEvents","BufferedEventEntity","attributes","RunAttributeEntity","reindexAttributes","runId","em","repo","delete","rows","normalizeAttributeRows","length","insert","createRun","run","save","toRunEntity","id","searchAttributes","updateRun","patch","update","workflow","workflowVersion","status","input","output","error","wakeAt","Date","lockedBy","lockedUntil","awaitingDecisionTaskId","recoveryAttempts","tags","priority","createdAt","updatedAt","result","createQueryBuilder","set","where","execute","affected","Error","getRun","e","findOneBy","fromRunEntity","deleteRun","getCheckpoint","seq","fromCheckpointEntity","saveCheckpoint","checkpoint","entity","toCheckpointEntity","upsert","transaction","work","raw","cp","listIncompleteRuns","findBy","In","map","listPendingRuns","limit","find","order","take","listDueTimers","nowMs","LessThanOrEqual","tryLockRun","owner","leaseUntilMs","andWhere","Brackets","qb","IsNull","orWhere","releaseRunLock","renewRunLock","listRuns","query","statuses","tag","tagPattern","forEach","f","i","applyAttributeExists","orderBy","offset","skip","getMany","valueProperty","attributeColumnFor","cmp","sqlComparator","op","keyParam","valParam","resolve","durableColumnResolver","q","idQuote","wrap","name","runIdCol","keyCol","valueCol","runPkCol","table","a","sql","key","attributeOperand","type","String","options","listCheckpoints","getLatestCheckpointByName","findOne","undefined","listCheckpointsByNamePrefix","prefixes","p","Like","putSignalWaiter","waiter","token","parallelGroup","listSignalWaiters","prefix","takeSignalWaiter","removeSignalWaiter","bufferSignal","payload","takeBufferedSignal","bufferEvent","publishedAt","listBufferedEvents","getTime","removeBufferedEvent","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-typeorm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "TypeORM adapter for the nestjs-durable StateStore",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Davide Carvalho",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"typeorm": "0.3.30",
|
|
30
30
|
"typescript": "5.9.3",
|
|
31
31
|
"tsup": "8.3.5",
|
|
32
|
-
"@dudousxd/nestjs-durable-core": "^0.
|
|
33
|
-
"@dudousxd/nestjs-durable-testing": "^0.
|
|
32
|
+
"@dudousxd/nestjs-durable-core": "^0.54.0",
|
|
33
|
+
"@dudousxd/nestjs-durable-testing": "^0.9.0"
|
|
34
34
|
},
|
|
35
35
|
"module": "./dist/index.js",
|
|
36
36
|
"exports": {
|