@dudousxd/nestjs-durable-store-mikro-orm 0.12.0 → 0.13.2

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 CHANGED
@@ -62,6 +62,7 @@ var WorkflowRunEntity = class {
62
62
  recoveryAttempts;
63
63
  tags;
64
64
  searchAttributes;
65
+ priority;
65
66
  createdAt;
66
67
  updatedAt;
67
68
  };
@@ -179,6 +180,11 @@ function durableEntities(options = {}) {
179
180
  nullable: true,
180
181
  fieldName: col("searchAttributes")
181
182
  },
183
+ priority: {
184
+ type: "integer",
185
+ nullable: true,
186
+ fieldName: col("priority")
187
+ },
182
188
  createdAt: {
183
189
  type: "Date",
184
190
  fieldName: col("createdAt")
@@ -363,6 +369,10 @@ function targetTable(statement) {
363
369
  return match?.[1]?.toLowerCase();
364
370
  }
365
371
  __name(targetTable, "targetTable");
372
+ function isRequiredStructure(statement) {
373
+ return /\b(?:create\s+table|add\s+(?:column|index|constraint|key|unique|fulltext))\b/i.test(statement);
374
+ }
375
+ __name(isRequiredStructure, "isRequiredStructure");
366
376
  async function ensureMikroOrmDurableSchema(orm) {
367
377
  const sql = await orm.schema.getUpdateSchemaSQL({
368
378
  safe: true
@@ -371,15 +381,56 @@ async function ensureMikroOrmDurableSchema(orm) {
371
381
  const table = targetTable(statement);
372
382
  return table !== void 0 && DURABLE_TABLE_NAMES.has(table);
373
383
  });
374
- if (ours.length === 0) {
375
- return;
376
- }
377
384
  const connection = orm.em.getConnection();
378
385
  for (const statement of ours) {
379
- await connection.execute(statement);
386
+ try {
387
+ await connection.execute(statement);
388
+ } catch (err) {
389
+ if (isRequiredStructure(statement)) {
390
+ throw err;
391
+ }
392
+ const message = err instanceof Error ? err.message : String(err);
393
+ console.warn(`[nestjs-durable-store-mikro-orm] skipped a non-structural durable-schema statement that failed; the column is left as-is (functional) \u2014 repair the data out of band to converge its type. Statement: ${statement} \u2014 ${message}`);
394
+ }
380
395
  }
396
+ await alignDurableCollation(orm);
381
397
  }
382
398
  __name(ensureMikroOrmDurableSchema, "ensureMikroOrmDurableSchema");
399
+ function isSafeSqlIdentifier(value) {
400
+ return /^[A-Za-z0-9_]+$/.test(value);
401
+ }
402
+ __name(isSafeSqlIdentifier, "isSafeSqlIdentifier");
403
+ async function alignDurableCollation(orm) {
404
+ const platform = String(orm.em.getPlatform().constructor.name).toLowerCase();
405
+ if (!platform.includes("mysql") && !platform.includes("maria")) {
406
+ return;
407
+ }
408
+ const collate = orm.config.get("collate");
409
+ if (typeof collate !== "string" || !isSafeSqlIdentifier(collate)) {
410
+ return;
411
+ }
412
+ const charset = collate.split("_")[0];
413
+ if (!charset || !isSafeSqlIdentifier(charset)) {
414
+ return;
415
+ }
416
+ const connection = orm.em.getConnection();
417
+ for (const table of DURABLE_TABLE_NAMES) {
418
+ try {
419
+ const rows = await connection.execute("select table_collation as collation from information_schema.tables where table_schema = database() and table_name = ? limit 1", [
420
+ table
421
+ ]);
422
+ const current = rows[0]?.collation;
423
+ if (current == null || current === collate) {
424
+ continue;
425
+ }
426
+ await connection.execute(`alter table \`${table}\` convert to character set ${charset} collate ${collate}`);
427
+ } catch (err) {
428
+ const message = err instanceof Error ? err.message : String(err);
429
+ console.warn(`[nestjs-durable-store-mikro-orm] could not align collation for \`${table}\` to ${collate} (left as-is): ${message}`);
430
+ }
431
+ }
432
+ }
433
+ __name(alignDurableCollation, "alignDurableCollation");
383
434
 
384
435
  // src/mikro-orm-state-store.ts
385
436
  var MikroOrmStateStore = class {
@@ -754,6 +805,7 @@ function toRunEntity(run) {
754
805
  if (run.recoveryAttempts !== void 0) e.recoveryAttempts = run.recoveryAttempts;
755
806
  e.tags = run.tags ?? null;
756
807
  e.searchAttributes = run.searchAttributes ?? null;
808
+ e.priority = run.priority ?? null;
757
809
  e.createdAt = run.createdAt;
758
810
  e.updatedAt = run.updatedAt;
759
811
  return e;
@@ -774,6 +826,7 @@ function fromRunEntity(e) {
774
826
  recoveryAttempts: e.recoveryAttempts ?? void 0,
775
827
  tags: e.tags ?? void 0,
776
828
  searchAttributes: e.searchAttributes ?? void 0,
829
+ priority: e.priority ?? void 0,
777
830
  createdAt: e.createdAt,
778
831
  updatedAt: e.updatedAt
779
832
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/entities.ts","../src/mikro-orm-state-store.ts","../src/schema.ts"],"sourcesContent":["export * from './entities';\nexport * from './mikro-orm-state-store';\nexport * from './schema';\n","import type { RunStatus, StepKind } from '@dudousxd/nestjs-durable-core';\nimport { EntitySchema } from '@mikro-orm/core';\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 TypeORM,\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\nfunction 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 `em.create`/`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;\n lockedUntil?: Date;\n recoveryAttempts?: number;\n tags?: string[] | null;\n searchAttributes?: Record<string, string | number | boolean> | 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;\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}\n\nexport class BufferedSignalEntity {\n id!: number;\n token!: string;\n payload?: unknown;\n}\n\n/**\n * Build the durable MikroORM entity schemas with column names pinned per `naming` (default\n * `'snake_case'`). Register the result in your MikroORM config / `MikroOrmModule.forFeature`.\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 class: WorkflowRunEntity,\n tableName: 'durable_workflow_runs',\n properties: {\n id: { type: 'string', primary: true, fieldName: col('id') },\n workflow: { type: 'string', fieldName: col('workflow') },\n workflowVersion: { type: 'string', fieldName: col('workflowVersion') },\n status: { type: 'string', fieldName: col('status') },\n input: { type: 'json', nullable: true, fieldName: col('input') },\n output: { type: 'json', nullable: true, fieldName: col('output') },\n error: { type: 'json', nullable: true, fieldName: col('error') },\n wakeAt: { type: 'Date', nullable: true, fieldName: col('wakeAt') },\n lockedBy: { type: 'string', nullable: true, fieldName: col('lockedBy') },\n lockedUntil: { type: 'Date', nullable: true, fieldName: col('lockedUntil') },\n recoveryAttempts: { type: 'integer', nullable: true, fieldName: col('recoveryAttempts') },\n tags: { type: 'json', nullable: true, fieldName: col('tags') },\n searchAttributes: { type: 'json', nullable: true, fieldName: col('searchAttributes') },\n createdAt: { type: 'Date', fieldName: col('createdAt') },\n updatedAt: { type: 'Date', fieldName: col('updatedAt') },\n },\n });\n\n const stepCheckpoints = new EntitySchema<StepCheckpointEntity>({\n class: StepCheckpointEntity,\n tableName: 'durable_step_checkpoints',\n properties: {\n runId: { type: 'string', primary: true, fieldName: col('runId') },\n seq: { type: 'integer', primary: true, fieldName: col('seq') },\n name: { type: 'string', fieldName: col('name') },\n kind: { type: 'string', fieldName: col('kind') },\n stepId: { type: 'string', fieldName: col('stepId') },\n status: { type: 'string', fieldName: col('status') },\n input: { type: 'json', nullable: true, fieldName: col('input') },\n output: { type: 'json', nullable: true, fieldName: col('output') },\n error: { type: 'json', nullable: true, fieldName: col('error') },\n events: { type: 'json', nullable: true, fieldName: col('events') },\n attempts: { type: 'integer', fieldName: col('attempts') },\n workerGroup: { type: 'string', nullable: true, fieldName: col('workerGroup') },\n wakeAt: { type: 'Date', nullable: true, fieldName: col('wakeAt') },\n enqueuedAt: { type: 'Date', nullable: true, fieldName: col('enqueuedAt') },\n startedAt: { type: 'Date', fieldName: col('startedAt') },\n finishedAt: { type: 'Date', fieldName: col('finishedAt') },\n },\n });\n\n const runAttributes = new EntitySchema<RunAttributeEntity>({\n class: RunAttributeEntity,\n tableName: 'durable_run_attributes',\n properties: {\n runId: { type: 'string', primary: true, fieldName: col('runId') },\n key: { type: 'string', primary: true, fieldName: col('key') },\n strValue: { type: 'string', nullable: true, fieldName: col('strValue') },\n // `float`/`double` is portable across SQLite/MySQL/Postgres for numeric range scans.\n numValue: { type: 'float', nullable: true, fieldName: col('numValue') },\n },\n });\n\n const signalWaiters = new EntitySchema<SignalWaiterEntity>({\n class: SignalWaiterEntity,\n tableName: 'durable_signal_waiters',\n properties: {\n token: { type: 'string', primary: true, fieldName: col('token') },\n runId: { type: 'string', fieldName: col('runId') },\n seq: { type: 'integer', fieldName: col('seq') },\n },\n });\n\n const bufferedSignals = new EntitySchema<BufferedSignalEntity>({\n class: BufferedSignalEntity,\n tableName: 'durable_buffered_signals',\n properties: {\n id: { type: 'integer', primary: true, autoincrement: true, fieldName: col('id') },\n token: { type: 'string', index: true, fieldName: col('token') },\n payload: { type: 'json', nullable: true, fieldName: col('payload') },\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 {\n type AttributeFilter,\n type RunQuery,\n type SignalWaiter,\n type StateStore,\n type StepCheckpoint,\n type StepError,\n type StepEvent,\n type WorkflowRun,\n attributeColumnFor,\n attributeOperand,\n normalizeAttributeRows,\n sqlComparator,\n} from '@dudousxd/nestjs-durable-core';\nimport type { EntityManager, MikroORM } from '@mikro-orm/core';\n\n/** Minimal structural surface of the SQL EntityManager's QueryBuilder (from `@mikro-orm/knex`),\n * typed here so the adapter needn't add a hard dependency on the knex types — a real SQL-driver EM\n * satisfies it at runtime. */\ninterface DurableQueryBuilder<T> {\n where(cond: Record<string, unknown>): DurableQueryBuilder<T>;\n andWhere(cond: string): DurableQueryBuilder<T>;\n orderBy(cond: Record<string, unknown>): DurableQueryBuilder<T>;\n limit(n: number): DurableQueryBuilder<T>;\n offset(n: number): DurableQueryBuilder<T>;\n getResultList(): Promise<T[]>;\n}\ntype SqlEm = EntityManager & {\n createQueryBuilder<T>(entity: unknown, alias: string): DurableQueryBuilder<T>;\n};\n\n/** Resolved side-table column names (per the active naming strategy) for the raw EXISTS pushdown. */\ninterface AttributeColumns {\n table: string;\n /** Side-table FK column (the run id on `durable_run_attributes`). */\n runId: string;\n /** Run table PK column (the `id` on `durable_workflow_runs`) used for the outer correlation. */\n runPk: string;\n key: string;\n strValue: string;\n numValue: string;\n}\nimport {\n BufferedSignalEntity,\n RunAttributeEntity,\n SignalWaiterEntity,\n StepCheckpointEntity,\n WorkflowRunEntity,\n} from './entities';\nimport { ensureMikroOrmDurableSchema } from './schema';\n\n/**\n * MikroORM-backed `StateStore`. Works on any MikroORM driver — Postgres, MySQL, SQLite (tested);\n * timestamps and `wakeAt` use native datetime columns. Each operation runs on a forked\n * EntityManager so it owns its unit of work.\n */\nexport class MikroOrmStateStore implements StateStore {\n constructor(private readonly orm: MikroORM) {}\n\n async ensureSchema(): Promise<void> {\n await ensureMikroOrmDurableSchema(this.orm);\n }\n\n async createRun(run: WorkflowRun): Promise<void> {\n const em = this.orm.em.fork();\n em.create(WorkflowRunEntity, toRunEntity(run));\n await em.flush();\n await this.reindexAttributes(run.id, run.searchAttributes);\n }\n\n async updateRun(runId: string, patch: Partial<WorkflowRun>): Promise<void> {\n const em = this.orm.em.fork();\n const entity = await em.findOneOrFail(WorkflowRunEntity, { id: runId });\n Object.assign(entity, toRunEntity({ ...fromRunEntity(entity), ...patch } as WorkflowRun));\n await em.flush();\n // Keep the side-table in step with the run's attributes whenever they're patched.\n if ('searchAttributes' in patch) await this.reindexAttributes(runId, patch.searchAttributes);\n }\n\n /** Rewrite a run's normalized attribute rows: delete the old set, insert the current one. Mirrors\n * the in-memory store's reindex so the side-table always reflects the run's live searchAttributes. */\n private async reindexAttributes(\n runId: string,\n attributes: WorkflowRun['searchAttributes'],\n forked?: EntityManager,\n ): Promise<void> {\n const em = forked ?? this.orm.em.fork();\n await em.nativeDelete(RunAttributeEntity, { runId });\n const rows = normalizeAttributeRows(runId, attributes);\n if (rows.length) await em.insertMany(RunAttributeEntity, rows);\n }\n\n async getRun(runId: string): Promise<WorkflowRun | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(WorkflowRunEntity, { id: runId });\n return entity ? fromRunEntity(entity) : null;\n }\n\n async deleteRun(runId: string): Promise<void> {\n const em = this.orm.em.fork();\n // Children first, then the run row — checkpoints, signal waiters, and the normalized\n // attribute side-table, so nothing dangles after the run is gone.\n await em.nativeDelete(StepCheckpointEntity, { runId });\n await em.nativeDelete(SignalWaiterEntity, { runId });\n await em.nativeDelete(RunAttributeEntity, { runId });\n await em.nativeDelete(WorkflowRunEntity, { id: runId });\n }\n\n async getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(StepCheckpointEntity, { runId, seq });\n return entity ? fromCheckpointEntity(entity) : null;\n }\n\n async saveCheckpoint(checkpoint: StepCheckpoint): Promise<void> {\n const em = this.orm.em.fork();\n await em.upsert(StepCheckpointEntity, toCheckpointEntity(checkpoint));\n await em.flush();\n }\n\n async transaction<T>(\n work: (tx: {\n raw: unknown;\n saveCheckpoint: (cp: StepCheckpoint) => Promise<void>;\n }) => Promise<T>,\n ): Promise<T> {\n return this.orm.em.fork().transactional(async (em) =>\n work({\n raw: em,\n saveCheckpoint: async (cp) => {\n await em.upsert(StepCheckpointEntity, toCheckpointEntity(cp));\n },\n }),\n );\n }\n\n async listIncompleteRuns(): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(WorkflowRunEntity, { status: 'running' });\n return rows.map(fromRunEntity);\n }\n\n async listPendingRuns(limit: number): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(\n WorkflowRunEntity,\n { status: 'pending' },\n { orderBy: { createdAt: 'asc' }, limit }, // FIFO dispatch\n );\n return rows.map(fromRunEntity);\n }\n\n async listDueTimers(nowMs: number): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(WorkflowRunEntity, {\n status: 'suspended',\n wakeAt: { $ne: null, $lte: new Date(nowMs) },\n });\n return rows.map(fromRunEntity);\n }\n\n async tryLockRun(\n runId: string,\n owner: string,\n leaseUntilMs: number,\n nowMs: number,\n ): Promise<boolean> {\n const em = this.orm.em.fork();\n const affected = await em.nativeUpdate(\n WorkflowRunEntity,\n { id: runId, $or: [{ lockedUntil: null }, { lockedUntil: { $lte: new Date(nowMs) } }] },\n { lockedBy: owner, lockedUntil: new Date(leaseUntilMs) },\n );\n return affected === 1;\n }\n\n async releaseRunLock(runId: string): Promise<void> {\n const em = this.orm.em.fork();\n await em.nativeUpdate(WorkflowRunEntity, { id: runId }, { lockedBy: null, lockedUntil: null });\n }\n\n async renewRunLock(runId: string, owner: string, leaseUntilMs: number): Promise<boolean> {\n const em = this.orm.em.fork();\n const affected = await em.nativeUpdate(\n WorkflowRunEntity,\n { id: runId, lockedBy: owner },\n { lockedUntil: new Date(leaseUntilMs) },\n );\n return affected === 1;\n }\n\n async listRuns(query: RunQuery): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const where: Record<string, unknown> = {};\n if (query.workflow) where.workflow = query.workflow;\n // `status IN (...)`; an empty set matches nothing (mirrors the in-memory store). When both the\n // single `status` and `statuses` are set, AND them so the narrower set wins.\n if (query.status && query.statuses) {\n where.$and = [{ status: query.status }, { status: { $in: query.statuses } }];\n } else if (query.status) {\n where.status = query.status;\n } else if (query.statuses) {\n where.status = { $in: query.statuses };\n }\n const orderBy = { createdAt: 'desc' as const }; // newest first — recent runs on top in the dashboard\n // `tags`/attributes need raw SQL pushed through the QueryBuilder:\n // - tag: `tags` is a JSON column (native json/jsonb on PG/MySQL), and MikroORM JSON-serializes a\n // `{ $like }` operand (wrapping/escaping the LIKE pattern) so a plain where corrupts it to no\n // matches. A raw LIKE on the column-as-text matches the quoted token so `etl` doesn't match\n // `etl-foo`. Postgres `jsonb` rejects `LIKE` directly, so cast to text per dialect.\n // - attributes: each filter becomes a raw EXISTS against the normalized side-table, so the DB\n // filters AND paginates — no full scan + in-process filter (ANDed: one EXISTS per filter).\n // Use a QueryBuilder with a fixed root alias `r` so the raw correlations are stable across drivers.\n if (query.tag || query.attributes?.length) {\n const quote = this.idQuote(em);\n const cols = this.attributeColumns(em);\n const qb = (em as SqlEm)\n .createQueryBuilder<WorkflowRunEntity>(WorkflowRunEntity, 'r')\n .where(where)\n .orderBy(orderBy);\n if (query.tag) {\n const tagsCol = this.tagsColumn(em);\n const pattern = `%\"${query.tag.replace(/'/g, \"''\")}\"%`;\n const colExpr = this.jsonAsText(em, `${quote('r')}.${quote(tagsCol)}`);\n qb.andWhere(`${colExpr} LIKE '${pattern}'`);\n }\n for (const f of query.attributes ?? []) {\n qb.andWhere(this.attributeExistsSql(f, quote, 'r', cols));\n }\n if (query.limit != null) qb.limit(query.limit);\n if (query.offset != null) qb.offset(query.offset);\n const rows = await qb.getResultList();\n return rows.map(fromRunEntity);\n }\n const rows = await em.find(WorkflowRunEntity, where, {\n ...(query.limit != null ? { limit: query.limit } : {}),\n ...(query.offset != null ? { offset: query.offset } : {}),\n orderBy,\n });\n return rows.map(fromRunEntity);\n }\n\n /** One attribute predicate as a raw EXISTS subquery on the side-table, correlated to the outer run\n * alias. `<>` (ne) also excludes runs where the attribute is absent (missing-key-never-matches):\n * EXISTS already requires a present row, so EXISTS(... <> ...) is exactly ne-with-present. Numeric\n * operands compare the num column, everything else the str column. Identifiers are quoted per\n * driver and operands are inlined as literals (string operands are escaped by doubling quotes). */\n private attributeExistsSql(\n f: AttributeFilter,\n quote: (id: string) => string,\n alias: string,\n cols: AttributeColumns,\n ): string {\n const col = attributeColumnFor(f) === 'numValue' ? cols.numValue : cols.strValue;\n const cmp = sqlComparator(f.op);\n const operand = attributeOperand(f);\n const literal =\n typeof operand === 'number' ? String(operand) : `'${String(operand).replace(/'/g, \"''\")}'`;\n const a = quote(cols.table);\n const sub = quote('a');\n const outerId = `${quote(alias)}.${quote(cols.runPk)}`; // run PK column on the outer alias\n return `EXISTS (SELECT 1 FROM ${a} ${sub} WHERE ${sub}.${quote(cols.runId)} = ${outerId} AND ${sub}.${quote(cols.key)} = '${f.key.replace(/'/g, \"''\")}' AND ${sub}.${quote(col)} ${cmp} ${literal})`;\n }\n\n /** Resolve the side-table's actual column names from MikroORM metadata, so the raw EXISTS matches\n * the active naming strategy (underscore vs camelCase) rather than guessing. The run PK column is\n * reused for BOTH the outer correlation and the side-table FK (they share the same fieldName). */\n private attributeColumns(em: EntityManager): AttributeColumns {\n const meta = em.getMetadata().get(RunAttributeEntity);\n const field = (prop: string) =>\n meta.props.find((p) => p.name === prop)?.fieldNames?.[0] ?? prop;\n const runMeta = em.getMetadata().get(WorkflowRunEntity);\n const runPk = runMeta.properties.id?.fieldNames?.[0] ?? 'id';\n return {\n table: meta.tableName,\n runId: field('runId'),\n runPk,\n key: field('key'),\n strValue: field('strValue'),\n numValue: field('numValue'),\n };\n }\n\n /** Resolve the `tags` column name from metadata (per the active naming strategy), for the raw LIKE. */\n private tagsColumn(em: EntityManager): string {\n const runMeta = em.getMetadata().get(WorkflowRunEntity);\n return runMeta.properties.tags?.fieldNames?.[0] ?? 'tags';\n }\n\n /** Wrap a JSON column reference so it can be `LIKE`d as text. Postgres `jsonb`/`json` rejects `LIKE`\n * directly (`operator does not exist: jsonb ~~ unknown`) — cast to `text`; MySQL JSON needs an\n * explicit `CHAR` cast; SQLite stores JSON as text already, so no cast. */\n private jsonAsText(em: EntityManager, colRef: string): string {\n const platform = String(em.getPlatform().constructor.name).toLowerCase();\n if (platform.includes('postgre')) return `${colRef}::text`;\n if (platform.includes('mysql') || platform.includes('mariadb'))\n return `CAST(${colRef} AS CHAR)`;\n return colRef;\n }\n\n /** Quote an identifier per the active SQL driver (MySQL/MariaDB backtick, others double-quote). */\n private idQuote(em: EntityManager): (id: string) => string {\n const platform = String(em.getPlatform().constructor.name).toLowerCase();\n const isMysql = platform.includes('mysql') || platform.includes('mariadb');\n const ch = isMysql ? '`' : '\"';\n return (id: string) => `${ch}${id}${ch}`;\n }\n\n async listCheckpoints(runId: string): Promise<StepCheckpoint[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(StepCheckpointEntity, { runId }, { orderBy: { seq: 'asc' } });\n return rows.map(fromCheckpointEntity);\n }\n\n async getLatestCheckpointByName(\n runId: string,\n name: string,\n ): Promise<StepCheckpoint | undefined> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(\n StepCheckpointEntity,\n { runId, name },\n { orderBy: { seq: 'desc' } },\n );\n return entity ? fromCheckpointEntity(entity) : undefined;\n }\n\n async listCheckpointsByNamePrefix(runId: string, prefixes: string[]): Promise<StepCheckpoint[]> {\n if (prefixes.length === 0) return [];\n const em = this.orm.em.fork();\n const rows = await em.find(\n StepCheckpointEntity,\n { runId, $or: prefixes.map((p) => ({ name: { $like: `${p}%` } })) },\n { orderBy: { seq: 'asc' } },\n );\n return rows.map(fromCheckpointEntity);\n }\n\n async putSignalWaiter(waiter: SignalWaiter): Promise<void> {\n const em = this.orm.em.fork();\n await em.upsert(SignalWaiterEntity, { ...waiter });\n await em.flush();\n }\n\n async takeSignalWaiter(token: string): Promise<SignalWaiter | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(SignalWaiterEntity, { token });\n if (!entity) return null;\n const waiter: SignalWaiter = { token: entity.token, runId: entity.runId, seq: entity.seq };\n await em.remove(entity).flush();\n return waiter;\n }\n\n async listSignalWaiters(prefix: string): Promise<SignalWaiter[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(SignalWaiterEntity, { token: { $like: `${prefix}%` } });\n return rows.map((e) => ({ token: e.token, runId: e.runId, seq: e.seq }));\n }\n\n async bufferSignal(token: string, payload: unknown): Promise<void> {\n const em = this.orm.em.fork();\n const e = new BufferedSignalEntity();\n e.token = token;\n e.payload = payload ?? null;\n em.persist(e);\n await em.flush();\n }\n\n async takeBufferedSignal(token: string): Promise<{ payload: unknown } | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(BufferedSignalEntity, { token }, { orderBy: { id: 'asc' } });\n if (!entity) return null;\n const payload = entity.payload ?? undefined;\n await em.remove(entity).flush();\n return { payload };\n }\n}\n\nfunction toRunEntity(run: WorkflowRun): WorkflowRunEntity {\n const e = new WorkflowRunEntity();\n e.id = run.id;\n e.workflow = run.workflow;\n e.workflowVersion = run.workflowVersion;\n e.status = run.status;\n e.input = run.input ?? null;\n e.output = run.output ?? null;\n e.error = run.error ?? null;\n if (run.wakeAt != null) e.wakeAt = new Date(run.wakeAt);\n if (run.lockedBy !== undefined) e.lockedBy = run.lockedBy;\n if (run.lockedUntil != null) e.lockedUntil = new Date(run.lockedUntil);\n if (run.recoveryAttempts !== undefined) e.recoveryAttempts = run.recoveryAttempts;\n e.tags = run.tags ?? null;\n e.searchAttributes = run.searchAttributes ?? null;\n e.createdAt = run.createdAt;\n e.updatedAt = run.updatedAt;\n return e;\n}\n\nfunction fromRunEntity(e: WorkflowRunEntity): WorkflowRun {\n return {\n id: e.id,\n workflow: e.workflow,\n workflowVersion: e.workflowVersion,\n status: e.status,\n input: e.input ?? undefined,\n output: e.output ?? undefined,\n error: (e.error ?? undefined) as StepError | undefined,\n wakeAt: e.wakeAt?.getTime(),\n lockedBy: e.lockedBy ?? undefined,\n lockedUntil: e.lockedUntil?.getTime(),\n recoveryAttempts: e.recoveryAttempts ?? undefined,\n tags: e.tags ?? undefined,\n searchAttributes: e.searchAttributes ?? undefined,\n createdAt: e.createdAt,\n updatedAt: e.updatedAt,\n };\n}\n\nfunction toCheckpointEntity(cp: StepCheckpoint): StepCheckpointEntity {\n const e = new StepCheckpointEntity();\n e.runId = cp.runId;\n e.seq = cp.seq;\n e.name = cp.name;\n e.kind = cp.kind;\n e.stepId = cp.stepId;\n e.status = cp.status;\n e.input = cp.input ?? null;\n e.output = cp.output ?? null;\n e.error = cp.error ?? null;\n e.events = cp.events ?? null;\n e.attempts = cp.attempts;\n if (cp.workerGroup !== undefined) e.workerGroup = cp.workerGroup;\n if (cp.wakeAt != null) e.wakeAt = new Date(cp.wakeAt);\n e.enqueuedAt = cp.enqueuedAt;\n e.startedAt = cp.startedAt;\n e.finishedAt = cp.finishedAt;\n return e;\n}\n\nfunction fromCheckpointEntity(e: StepCheckpointEntity): StepCheckpoint {\n return {\n runId: e.runId,\n seq: e.seq,\n name: e.name,\n kind: e.kind,\n stepId: e.stepId,\n status: e.status,\n input: e.input ?? undefined,\n output: e.output ?? undefined,\n error: (e.error ?? undefined) as StepError | undefined,\n events: (e.events ?? undefined) as StepEvent[] | undefined,\n attempts: e.attempts,\n workerGroup: e.workerGroup ?? undefined,\n wakeAt: e.wakeAt?.getTime(),\n enqueuedAt: e.enqueuedAt ?? e.startedAt,\n startedAt: e.startedAt,\n finishedAt: e.finishedAt,\n };\n}\n","import type { MikroORM } from '@mikro-orm/core';\n\n/**\n * The tables this store owns. Kept in sync with the `tableName`s in `./entities`. Used to scope\n * schema management to our own tables (see {@link ensureMikroOrmDurableSchema}).\n */\nconst DURABLE_TABLE_NAMES = new Set([\n 'durable_workflow_runs',\n 'durable_step_checkpoints',\n 'durable_run_attributes',\n 'durable_signal_waiters',\n 'durable_buffered_signals',\n]);\n\n/** The table a `create table` / `alter table` statement targets, lower-cased; undefined otherwise. */\nfunction targetTable(statement: string): string | undefined {\n const match = statement.match(\n /^(?:create|alter)\\s+table\\s+(?:if\\s+not\\s+exists\\s+)?[`\"']?([\\w$]+)[`\"']?/i,\n );\n return match?.[1]?.toLowerCase();\n}\n\n/**\n * Idempotently create/extend ONLY the durable tables (additive — never drops). Safe to run on every\n * boot (auto-schema) and from a MikroORM migration when you disable auto-schema:\n *\n * ```ts\n * export class AddDurableTables extends Migration {\n * async up() { await ensureMikroOrmDurableSchema(this.getEntityManager().getOrm()); }\n * }\n * ```\n *\n * It does NOT run a whole-ORM `schema.update()`. When the store shares the host app's ORM (the\n * recommended setup — a single ORM avoids MikroORM's global-metadata clobber between instances),\n * a full `schema.update()` would try to reconcile EVERY app table to the entity metadata: on a\n * migration-managed schema that means recreating the migrations table and dropping app foreign keys.\n * Instead we compute the safe additive diff and execute only the statements that target our own\n * `durable_*` tables. `getUpdateSchemaSQL` already emits a `create table` only for a missing table\n * and `alter table ... add` only for missing columns, so existing tables — and the entire rest of\n * the host schema — are left untouched.\n */\nexport async function ensureMikroOrmDurableSchema(orm: MikroORM): Promise<void> {\n const sql = await orm.schema.getUpdateSchemaSQL({ safe: true });\n const ours = sql\n .split(';')\n .map((statement) => statement.trim())\n .filter((statement) => {\n const table = targetTable(statement);\n return table !== undefined && DURABLE_TABLE_NAMES.has(table);\n });\n if (ours.length === 0) {\n return;\n }\n const connection = orm.em.getConnection();\n for (const statement of ours) {\n await connection.execute(statement);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;ACCA,kBAA6B;AAgB7B,SAASA,UAAUC,UAAgB;AACjC,SAAOA,SAASC,QAAQ,UAAU,CAACC,MAAM,IAAIA,EAAEC,YAAW,CAAA,EAAI;AAChE;AAFSJ;AAIT,SAASK,YAAYC,QAA2B;AAC9C,MAAIA,WAAW,aAAc,QAAON;AACpC,MAAIM,WAAW,WAAY,QAAO,CAACL,aAAaA;AAChD,SAAOK;AACT;AAJSD;AAUF,IAAME,oBAAN,MAAMA;EA9Bb,OA8BaA;;;EACXC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;AACF;AAEO,IAAMC,uBAAN,MAAMA;EAhDb,OAgDaA;;;EACXC;EACAC;EACAC;EACAC;EACAC;EACAjB;EACAC;EACAC;EACAC;EACAe;EACAC;EACAC;EACAhB;EACAiB;EACAC;EACAC;AACF;AAQO,IAAMC,qBAAN,MAAMA;EAzEb,OAyEaA;;;EACXX;EACAY;EACAC;EACAC;AACF;AAEO,IAAMC,qBAAN,MAAMA;EAhFb,OAgFaA;;;EACXC;EACAhB;EACAC;AACF;AAEO,IAAMgB,uBAAN,MAAMA;EAtFb,OAsFaA;;;EACXjC;EACAgC;EACAE;AACF;AAUO,SAASC,gBAAgBC,UAA4C,CAAC,GAAC;AAC5E,QAAMC,MAAMxC,YAAYuC,QAAQtC,UAAU,YAAA;AAE1C,QAAMwC,eAAe,IAAIC,yBAAgC;IACvDC,OAAOzC;IACP0C,WAAW;IACXC,YAAY;MACV1C,IAAI;QAAE2C,MAAM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IACVyG,OAAOP,EAAEO,SAASlB;IAClBmB,QAAQR,EAAEQ,UAAUnB;IACpBoB,OAAQT,EAAES,SAASpB;IACnB0B,QAASf,EAAEe,UAAU1B;IACrB2B,UAAUhB,EAAEgB;IACZC,aAAajB,EAAEiB,eAAe5B;IAC9B/E,QAAQ0F,EAAE1F,QAAQsG,QAAAA;IAClBM,YAAYlB,EAAEkB,cAAclB,EAAEmB;IAC9BA,WAAWnB,EAAEmB;IACbC,YAAYpB,EAAEoB;EAChB;AACF;AAnBSlI;","names":["snakeCase","property","replace","c","toLowerCase","columnNamer","naming","WorkflowRunEntity","id","workflow","workflowVersion","status","input","output","error","wakeAt","lockedBy","lockedUntil","recoveryAttempts","tags","searchAttributes","createdAt","updatedAt","StepCheckpointEntity","runId","seq","name","kind","stepId","events","attempts","workerGroup","enqueuedAt","startedAt","finishedAt","RunAttributeEntity","key","strValue","numValue","SignalWaiterEntity","token","BufferedSignalEntity","payload","durableEntities","options","col","workflowRuns","EntitySchema","class","tableName","properties","type","primary","fieldName","nullable","stepCheckpoints","runAttributes","signalWaiters","bufferedSignals","autoincrement","index","ENTITIES","DURABLE_TABLE_NAMES","Set","targetTable","statement","match","toLowerCase","ensureMikroOrmDurableSchema","orm","sql","schema","getUpdateSchemaSQL","safe","ours","split","map","trim","filter","table","undefined","has","length","connection","em","getConnection","execute","MikroOrmStateStore","orm","ensureSchema","ensureMikroOrmDurableSchema","createRun","run","em","fork","create","WorkflowRunEntity","toRunEntity","flush","reindexAttributes","id","searchAttributes","updateRun","runId","patch","entity","findOneOrFail","Object","assign","fromRunEntity","attributes","forked","nativeDelete","RunAttributeEntity","rows","normalizeAttributeRows","length","insertMany","getRun","findOne","deleteRun","StepCheckpointEntity","SignalWaiterEntity","getCheckpoint","seq","fromCheckpointEntity","saveCheckpoint","checkpoint","upsert","toCheckpointEntity","transaction","work","transactional","raw","cp","listIncompleteRuns","find","status","map","listPendingRuns","limit","orderBy","createdAt","listDueTimers","nowMs","wakeAt","$ne","$lte","Date","tryLockRun","owner","leaseUntilMs","affected","nativeUpdate","$or","lockedUntil","lockedBy","releaseRunLock","renewRunLock","listRuns","query","where","workflow","statuses","$and","$in","tag","quote","idQuote","cols","attributeColumns","qb","createQueryBuilder","tagsCol","tagsColumn","pattern","replace","colExpr","jsonAsText","andWhere","f","attributeExistsSql","offset","getResultList","alias","col","attributeColumnFor","numValue","strValue","cmp","sqlComparator","op","operand","attributeOperand","literal","String","a","table","sub","outerId","runPk","key","meta","getMetadata","get","field","prop","props","p","name","fieldNames","runMeta","properties","tableName","tags","colRef","platform","getPlatform","toLowerCase","includes","isMysql","ch","listCheckpoints","getLatestCheckpointByName","undefined","listCheckpointsByNamePrefix","prefixes","$like","putSignalWaiter","waiter","takeSignalWaiter","token","remove","listSignalWaiters","prefix","e","bufferSignal","payload","BufferedSignalEntity","persist","takeBufferedSignal","workflowVersion","input","output","error","recoveryAttempts","updatedAt","getTime","kind","stepId","events","attempts","workerGroup","enqueuedAt","startedAt","finishedAt"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/entities.ts","../src/mikro-orm-state-store.ts","../src/schema.ts"],"sourcesContent":["export * from './entities';\nexport * from './mikro-orm-state-store';\nexport * from './schema';\n","import type { RunStatus, StepKind } from '@dudousxd/nestjs-durable-core';\nimport { EntitySchema } from '@mikro-orm/core';\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 TypeORM,\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\nfunction 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 `em.create`/`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;\n lockedUntil?: Date;\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;\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}\n\nexport class BufferedSignalEntity {\n id!: number;\n token!: string;\n payload?: unknown;\n}\n\n/**\n * Build the durable MikroORM entity schemas with column names pinned per `naming` (default\n * `'snake_case'`). Register the result in your MikroORM config / `MikroOrmModule.forFeature`.\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 class: WorkflowRunEntity,\n tableName: 'durable_workflow_runs',\n properties: {\n id: { type: 'string', primary: true, fieldName: col('id') },\n workflow: { type: 'string', fieldName: col('workflow') },\n workflowVersion: { type: 'string', fieldName: col('workflowVersion') },\n status: { type: 'string', fieldName: col('status') },\n input: { type: 'json', nullable: true, fieldName: col('input') },\n output: { type: 'json', nullable: true, fieldName: col('output') },\n error: { type: 'json', nullable: true, fieldName: col('error') },\n wakeAt: { type: 'Date', nullable: true, fieldName: col('wakeAt') },\n lockedBy: { type: 'string', nullable: true, fieldName: col('lockedBy') },\n lockedUntil: { type: 'Date', nullable: true, fieldName: col('lockedUntil') },\n recoveryAttempts: { type: 'integer', nullable: true, fieldName: col('recoveryAttempts') },\n tags: { type: 'json', nullable: true, fieldName: col('tags') },\n searchAttributes: { type: 'json', nullable: true, fieldName: col('searchAttributes') },\n priority: { type: 'integer', nullable: true, fieldName: col('priority') },\n createdAt: { type: 'Date', fieldName: col('createdAt') },\n updatedAt: { type: 'Date', fieldName: col('updatedAt') },\n },\n });\n\n const stepCheckpoints = new EntitySchema<StepCheckpointEntity>({\n class: StepCheckpointEntity,\n tableName: 'durable_step_checkpoints',\n properties: {\n runId: { type: 'string', primary: true, fieldName: col('runId') },\n seq: { type: 'integer', primary: true, fieldName: col('seq') },\n name: { type: 'string', fieldName: col('name') },\n kind: { type: 'string', fieldName: col('kind') },\n stepId: { type: 'string', fieldName: col('stepId') },\n status: { type: 'string', fieldName: col('status') },\n input: { type: 'json', nullable: true, fieldName: col('input') },\n output: { type: 'json', nullable: true, fieldName: col('output') },\n error: { type: 'json', nullable: true, fieldName: col('error') },\n events: { type: 'json', nullable: true, fieldName: col('events') },\n attempts: { type: 'integer', fieldName: col('attempts') },\n workerGroup: { type: 'string', nullable: true, fieldName: col('workerGroup') },\n wakeAt: { type: 'Date', nullable: true, fieldName: col('wakeAt') },\n enqueuedAt: { type: 'Date', nullable: true, fieldName: col('enqueuedAt') },\n startedAt: { type: 'Date', fieldName: col('startedAt') },\n finishedAt: { type: 'Date', fieldName: col('finishedAt') },\n },\n });\n\n const runAttributes = new EntitySchema<RunAttributeEntity>({\n class: RunAttributeEntity,\n tableName: 'durable_run_attributes',\n properties: {\n runId: { type: 'string', primary: true, fieldName: col('runId') },\n key: { type: 'string', primary: true, fieldName: col('key') },\n strValue: { type: 'string', nullable: true, fieldName: col('strValue') },\n // `float`/`double` is portable across SQLite/MySQL/Postgres for numeric range scans.\n numValue: { type: 'float', nullable: true, fieldName: col('numValue') },\n },\n });\n\n const signalWaiters = new EntitySchema<SignalWaiterEntity>({\n class: SignalWaiterEntity,\n tableName: 'durable_signal_waiters',\n properties: {\n token: { type: 'string', primary: true, fieldName: col('token') },\n runId: { type: 'string', fieldName: col('runId') },\n seq: { type: 'integer', fieldName: col('seq') },\n },\n });\n\n const bufferedSignals = new EntitySchema<BufferedSignalEntity>({\n class: BufferedSignalEntity,\n tableName: 'durable_buffered_signals',\n properties: {\n id: { type: 'integer', primary: true, autoincrement: true, fieldName: col('id') },\n token: { type: 'string', index: true, fieldName: col('token') },\n payload: { type: 'json', nullable: true, fieldName: col('payload') },\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 {\n type AttributeFilter,\n type RunQuery,\n type SignalWaiter,\n type StateStore,\n type StepCheckpoint,\n type StepError,\n type StepEvent,\n type WorkflowRun,\n attributeColumnFor,\n attributeOperand,\n normalizeAttributeRows,\n sqlComparator,\n} from '@dudousxd/nestjs-durable-core';\nimport type { EntityManager, MikroORM } from '@mikro-orm/core';\n\n/** Minimal structural surface of the SQL EntityManager's QueryBuilder (from `@mikro-orm/knex`),\n * typed here so the adapter needn't add a hard dependency on the knex types — a real SQL-driver EM\n * satisfies it at runtime. */\ninterface DurableQueryBuilder<T> {\n where(cond: Record<string, unknown>): DurableQueryBuilder<T>;\n andWhere(cond: string): DurableQueryBuilder<T>;\n orderBy(cond: Record<string, unknown>): DurableQueryBuilder<T>;\n limit(n: number): DurableQueryBuilder<T>;\n offset(n: number): DurableQueryBuilder<T>;\n getResultList(): Promise<T[]>;\n}\ntype SqlEm = EntityManager & {\n createQueryBuilder<T>(entity: unknown, alias: string): DurableQueryBuilder<T>;\n};\n\n/** Resolved side-table column names (per the active naming strategy) for the raw EXISTS pushdown. */\ninterface AttributeColumns {\n table: string;\n /** Side-table FK column (the run id on `durable_run_attributes`). */\n runId: string;\n /** Run table PK column (the `id` on `durable_workflow_runs`) used for the outer correlation. */\n runPk: string;\n key: string;\n strValue: string;\n numValue: string;\n}\nimport {\n BufferedSignalEntity,\n RunAttributeEntity,\n SignalWaiterEntity,\n StepCheckpointEntity,\n WorkflowRunEntity,\n} from './entities';\nimport { ensureMikroOrmDurableSchema } from './schema';\n\n/**\n * MikroORM-backed `StateStore`. Works on any MikroORM driver — Postgres, MySQL, SQLite (tested);\n * timestamps and `wakeAt` use native datetime columns. Each operation runs on a forked\n * EntityManager so it owns its unit of work.\n */\nexport class MikroOrmStateStore implements StateStore {\n constructor(private readonly orm: MikroORM) {}\n\n async ensureSchema(): Promise<void> {\n await ensureMikroOrmDurableSchema(this.orm);\n }\n\n async createRun(run: WorkflowRun): Promise<void> {\n const em = this.orm.em.fork();\n em.create(WorkflowRunEntity, toRunEntity(run));\n await em.flush();\n await this.reindexAttributes(run.id, run.searchAttributes);\n }\n\n async updateRun(runId: string, patch: Partial<WorkflowRun>): Promise<void> {\n const em = this.orm.em.fork();\n const entity = await em.findOneOrFail(WorkflowRunEntity, { id: runId });\n Object.assign(entity, toRunEntity({ ...fromRunEntity(entity), ...patch } as WorkflowRun));\n await em.flush();\n // Keep the side-table in step with the run's attributes whenever they're patched.\n if ('searchAttributes' in patch) await this.reindexAttributes(runId, patch.searchAttributes);\n }\n\n /** Rewrite a run's normalized attribute rows: delete the old set, insert the current one. Mirrors\n * the in-memory store's reindex so the side-table always reflects the run's live searchAttributes. */\n private async reindexAttributes(\n runId: string,\n attributes: WorkflowRun['searchAttributes'],\n forked?: EntityManager,\n ): Promise<void> {\n const em = forked ?? this.orm.em.fork();\n await em.nativeDelete(RunAttributeEntity, { runId });\n const rows = normalizeAttributeRows(runId, attributes);\n if (rows.length) await em.insertMany(RunAttributeEntity, rows);\n }\n\n async getRun(runId: string): Promise<WorkflowRun | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(WorkflowRunEntity, { id: runId });\n return entity ? fromRunEntity(entity) : null;\n }\n\n async deleteRun(runId: string): Promise<void> {\n const em = this.orm.em.fork();\n // Children first, then the run row — checkpoints, signal waiters, and the normalized\n // attribute side-table, so nothing dangles after the run is gone.\n await em.nativeDelete(StepCheckpointEntity, { runId });\n await em.nativeDelete(SignalWaiterEntity, { runId });\n await em.nativeDelete(RunAttributeEntity, { runId });\n await em.nativeDelete(WorkflowRunEntity, { id: runId });\n }\n\n async getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(StepCheckpointEntity, { runId, seq });\n return entity ? fromCheckpointEntity(entity) : null;\n }\n\n async saveCheckpoint(checkpoint: StepCheckpoint): Promise<void> {\n const em = this.orm.em.fork();\n await em.upsert(StepCheckpointEntity, toCheckpointEntity(checkpoint));\n await em.flush();\n }\n\n async transaction<T>(\n work: (tx: {\n raw: unknown;\n saveCheckpoint: (cp: StepCheckpoint) => Promise<void>;\n }) => Promise<T>,\n ): Promise<T> {\n return this.orm.em.fork().transactional(async (em) =>\n work({\n raw: em,\n saveCheckpoint: async (cp) => {\n await em.upsert(StepCheckpointEntity, toCheckpointEntity(cp));\n },\n }),\n );\n }\n\n async listIncompleteRuns(): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(WorkflowRunEntity, { status: 'running' });\n return rows.map(fromRunEntity);\n }\n\n async listPendingRuns(limit: number): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(\n WorkflowRunEntity,\n { status: 'pending' },\n { orderBy: { createdAt: 'asc' }, limit }, // FIFO dispatch\n );\n return rows.map(fromRunEntity);\n }\n\n async listDueTimers(nowMs: number): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(WorkflowRunEntity, {\n status: 'suspended',\n wakeAt: { $ne: null, $lte: new Date(nowMs) },\n });\n return rows.map(fromRunEntity);\n }\n\n async tryLockRun(\n runId: string,\n owner: string,\n leaseUntilMs: number,\n nowMs: number,\n ): Promise<boolean> {\n const em = this.orm.em.fork();\n const affected = await em.nativeUpdate(\n WorkflowRunEntity,\n { id: runId, $or: [{ lockedUntil: null }, { lockedUntil: { $lte: new Date(nowMs) } }] },\n { lockedBy: owner, lockedUntil: new Date(leaseUntilMs) },\n );\n return affected === 1;\n }\n\n async releaseRunLock(runId: string): Promise<void> {\n const em = this.orm.em.fork();\n await em.nativeUpdate(WorkflowRunEntity, { id: runId }, { lockedBy: null, lockedUntil: null });\n }\n\n async renewRunLock(runId: string, owner: string, leaseUntilMs: number): Promise<boolean> {\n const em = this.orm.em.fork();\n const affected = await em.nativeUpdate(\n WorkflowRunEntity,\n { id: runId, lockedBy: owner },\n { lockedUntil: new Date(leaseUntilMs) },\n );\n return affected === 1;\n }\n\n async listRuns(query: RunQuery): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const where: Record<string, unknown> = {};\n if (query.workflow) where.workflow = query.workflow;\n // `status IN (...)`; an empty set matches nothing (mirrors the in-memory store). When both the\n // single `status` and `statuses` are set, AND them so the narrower set wins.\n if (query.status && query.statuses) {\n where.$and = [{ status: query.status }, { status: { $in: query.statuses } }];\n } else if (query.status) {\n where.status = query.status;\n } else if (query.statuses) {\n where.status = { $in: query.statuses };\n }\n const orderBy = { createdAt: 'desc' as const }; // newest first — recent runs on top in the dashboard\n // `tags`/attributes need raw SQL pushed through the QueryBuilder:\n // - tag: `tags` is a JSON column (native json/jsonb on PG/MySQL), and MikroORM JSON-serializes a\n // `{ $like }` operand (wrapping/escaping the LIKE pattern) so a plain where corrupts it to no\n // matches. A raw LIKE on the column-as-text matches the quoted token so `etl` doesn't match\n // `etl-foo`. Postgres `jsonb` rejects `LIKE` directly, so cast to text per dialect.\n // - attributes: each filter becomes a raw EXISTS against the normalized side-table, so the DB\n // filters AND paginates — no full scan + in-process filter (ANDed: one EXISTS per filter).\n // Use a QueryBuilder with a fixed root alias `r` so the raw correlations are stable across drivers.\n if (query.tag || query.attributes?.length) {\n const quote = this.idQuote(em);\n const cols = this.attributeColumns(em);\n const qb = (em as SqlEm)\n .createQueryBuilder<WorkflowRunEntity>(WorkflowRunEntity, 'r')\n .where(where)\n .orderBy(orderBy);\n if (query.tag) {\n const tagsCol = this.tagsColumn(em);\n const pattern = `%\"${query.tag.replace(/'/g, \"''\")}\"%`;\n const colExpr = this.jsonAsText(em, `${quote('r')}.${quote(tagsCol)}`);\n qb.andWhere(`${colExpr} LIKE '${pattern}'`);\n }\n for (const f of query.attributes ?? []) {\n qb.andWhere(this.attributeExistsSql(f, quote, 'r', cols));\n }\n if (query.limit != null) qb.limit(query.limit);\n if (query.offset != null) qb.offset(query.offset);\n const rows = await qb.getResultList();\n return rows.map(fromRunEntity);\n }\n const rows = await em.find(WorkflowRunEntity, where, {\n ...(query.limit != null ? { limit: query.limit } : {}),\n ...(query.offset != null ? { offset: query.offset } : {}),\n orderBy,\n });\n return rows.map(fromRunEntity);\n }\n\n /** One attribute predicate as a raw EXISTS subquery on the side-table, correlated to the outer run\n * alias. `<>` (ne) also excludes runs where the attribute is absent (missing-key-never-matches):\n * EXISTS already requires a present row, so EXISTS(... <> ...) is exactly ne-with-present. Numeric\n * operands compare the num column, everything else the str column. Identifiers are quoted per\n * driver and operands are inlined as literals (string operands are escaped by doubling quotes). */\n private attributeExistsSql(\n f: AttributeFilter,\n quote: (id: string) => string,\n alias: string,\n cols: AttributeColumns,\n ): string {\n const col = attributeColumnFor(f) === 'numValue' ? cols.numValue : cols.strValue;\n const cmp = sqlComparator(f.op);\n const operand = attributeOperand(f);\n const literal =\n typeof operand === 'number' ? String(operand) : `'${String(operand).replace(/'/g, \"''\")}'`;\n const a = quote(cols.table);\n const sub = quote('a');\n const outerId = `${quote(alias)}.${quote(cols.runPk)}`; // run PK column on the outer alias\n return `EXISTS (SELECT 1 FROM ${a} ${sub} WHERE ${sub}.${quote(cols.runId)} = ${outerId} AND ${sub}.${quote(cols.key)} = '${f.key.replace(/'/g, \"''\")}' AND ${sub}.${quote(col)} ${cmp} ${literal})`;\n }\n\n /** Resolve the side-table's actual column names from MikroORM metadata, so the raw EXISTS matches\n * the active naming strategy (underscore vs camelCase) rather than guessing. The run PK column is\n * reused for BOTH the outer correlation and the side-table FK (they share the same fieldName). */\n private attributeColumns(em: EntityManager): AttributeColumns {\n const meta = em.getMetadata().get(RunAttributeEntity);\n const field = (prop: string) =>\n meta.props.find((p) => p.name === prop)?.fieldNames?.[0] ?? prop;\n const runMeta = em.getMetadata().get(WorkflowRunEntity);\n const runPk = runMeta.properties.id?.fieldNames?.[0] ?? 'id';\n return {\n table: meta.tableName,\n runId: field('runId'),\n runPk,\n key: field('key'),\n strValue: field('strValue'),\n numValue: field('numValue'),\n };\n }\n\n /** Resolve the `tags` column name from metadata (per the active naming strategy), for the raw LIKE. */\n private tagsColumn(em: EntityManager): string {\n const runMeta = em.getMetadata().get(WorkflowRunEntity);\n return runMeta.properties.tags?.fieldNames?.[0] ?? 'tags';\n }\n\n /** Wrap a JSON column reference so it can be `LIKE`d as text. Postgres `jsonb`/`json` rejects `LIKE`\n * directly (`operator does not exist: jsonb ~~ unknown`) — cast to `text`; MySQL JSON needs an\n * explicit `CHAR` cast; SQLite stores JSON as text already, so no cast. */\n private jsonAsText(em: EntityManager, colRef: string): string {\n const platform = String(em.getPlatform().constructor.name).toLowerCase();\n if (platform.includes('postgre')) return `${colRef}::text`;\n if (platform.includes('mysql') || platform.includes('mariadb'))\n return `CAST(${colRef} AS CHAR)`;\n return colRef;\n }\n\n /** Quote an identifier per the active SQL driver (MySQL/MariaDB backtick, others double-quote). */\n private idQuote(em: EntityManager): (id: string) => string {\n const platform = String(em.getPlatform().constructor.name).toLowerCase();\n const isMysql = platform.includes('mysql') || platform.includes('mariadb');\n const ch = isMysql ? '`' : '\"';\n return (id: string) => `${ch}${id}${ch}`;\n }\n\n async listCheckpoints(runId: string): Promise<StepCheckpoint[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(StepCheckpointEntity, { runId }, { orderBy: { seq: 'asc' } });\n return rows.map(fromCheckpointEntity);\n }\n\n async getLatestCheckpointByName(\n runId: string,\n name: string,\n ): Promise<StepCheckpoint | undefined> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(\n StepCheckpointEntity,\n { runId, name },\n { orderBy: { seq: 'desc' } },\n );\n return entity ? fromCheckpointEntity(entity) : undefined;\n }\n\n async listCheckpointsByNamePrefix(runId: string, prefixes: string[]): Promise<StepCheckpoint[]> {\n if (prefixes.length === 0) return [];\n const em = this.orm.em.fork();\n const rows = await em.find(\n StepCheckpointEntity,\n { runId, $or: prefixes.map((p) => ({ name: { $like: `${p}%` } })) },\n { orderBy: { seq: 'asc' } },\n );\n return rows.map(fromCheckpointEntity);\n }\n\n async putSignalWaiter(waiter: SignalWaiter): Promise<void> {\n const em = this.orm.em.fork();\n await em.upsert(SignalWaiterEntity, { ...waiter });\n await em.flush();\n }\n\n async takeSignalWaiter(token: string): Promise<SignalWaiter | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(SignalWaiterEntity, { token });\n if (!entity) return null;\n const waiter: SignalWaiter = { token: entity.token, runId: entity.runId, seq: entity.seq };\n await em.remove(entity).flush();\n return waiter;\n }\n\n async listSignalWaiters(prefix: string): Promise<SignalWaiter[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(SignalWaiterEntity, { token: { $like: `${prefix}%` } });\n return rows.map((e) => ({ token: e.token, runId: e.runId, seq: e.seq }));\n }\n\n async bufferSignal(token: string, payload: unknown): Promise<void> {\n const em = this.orm.em.fork();\n const e = new BufferedSignalEntity();\n e.token = token;\n e.payload = payload ?? null;\n em.persist(e);\n await em.flush();\n }\n\n async takeBufferedSignal(token: string): Promise<{ payload: unknown } | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(BufferedSignalEntity, { token }, { orderBy: { id: 'asc' } });\n if (!entity) return null;\n const payload = entity.payload ?? undefined;\n await em.remove(entity).flush();\n return { payload };\n }\n}\n\nfunction toRunEntity(run: WorkflowRun): WorkflowRunEntity {\n const e = new WorkflowRunEntity();\n e.id = run.id;\n e.workflow = run.workflow;\n e.workflowVersion = run.workflowVersion;\n e.status = run.status;\n e.input = run.input ?? null;\n e.output = run.output ?? null;\n e.error = run.error ?? null;\n if (run.wakeAt != null) e.wakeAt = new Date(run.wakeAt);\n if (run.lockedBy !== undefined) e.lockedBy = run.lockedBy;\n if (run.lockedUntil != null) e.lockedUntil = new Date(run.lockedUntil);\n if (run.recoveryAttempts !== undefined) e.recoveryAttempts = run.recoveryAttempts;\n e.tags = run.tags ?? null;\n e.searchAttributes = run.searchAttributes ?? null;\n e.priority = run.priority ?? null;\n e.createdAt = run.createdAt;\n e.updatedAt = run.updatedAt;\n return e;\n}\n\nfunction fromRunEntity(e: WorkflowRunEntity): WorkflowRun {\n return {\n id: e.id,\n workflow: e.workflow,\n workflowVersion: e.workflowVersion,\n status: e.status,\n input: e.input ?? undefined,\n output: e.output ?? undefined,\n error: (e.error ?? undefined) as StepError | undefined,\n wakeAt: e.wakeAt?.getTime(),\n lockedBy: e.lockedBy ?? undefined,\n lockedUntil: e.lockedUntil?.getTime(),\n recoveryAttempts: e.recoveryAttempts ?? undefined,\n tags: e.tags ?? undefined,\n searchAttributes: e.searchAttributes ?? undefined,\n priority: e.priority ?? undefined,\n createdAt: e.createdAt,\n updatedAt: e.updatedAt,\n };\n}\n\nfunction toCheckpointEntity(cp: StepCheckpoint): StepCheckpointEntity {\n const e = new StepCheckpointEntity();\n e.runId = cp.runId;\n e.seq = cp.seq;\n e.name = cp.name;\n e.kind = cp.kind;\n e.stepId = cp.stepId;\n e.status = cp.status;\n e.input = cp.input ?? null;\n e.output = cp.output ?? null;\n e.error = cp.error ?? null;\n e.events = cp.events ?? null;\n e.attempts = cp.attempts;\n if (cp.workerGroup !== undefined) e.workerGroup = cp.workerGroup;\n if (cp.wakeAt != null) e.wakeAt = new Date(cp.wakeAt);\n e.enqueuedAt = cp.enqueuedAt;\n e.startedAt = cp.startedAt;\n e.finishedAt = cp.finishedAt;\n return e;\n}\n\nfunction fromCheckpointEntity(e: StepCheckpointEntity): StepCheckpoint {\n return {\n runId: e.runId,\n seq: e.seq,\n name: e.name,\n kind: e.kind,\n stepId: e.stepId,\n status: e.status,\n input: e.input ?? undefined,\n output: e.output ?? undefined,\n error: (e.error ?? undefined) as StepError | undefined,\n events: (e.events ?? undefined) as StepEvent[] | undefined,\n attempts: e.attempts,\n workerGroup: e.workerGroup ?? undefined,\n wakeAt: e.wakeAt?.getTime(),\n enqueuedAt: e.enqueuedAt ?? e.startedAt,\n startedAt: e.startedAt,\n finishedAt: e.finishedAt,\n };\n}\n","import type { MikroORM } from '@mikro-orm/core';\n\n/**\n * The tables this store owns. Kept in sync with the `tableName`s in `./entities`. Used to scope\n * schema management to our own tables (see {@link ensureMikroOrmDurableSchema}).\n */\nconst DURABLE_TABLE_NAMES = new Set([\n 'durable_workflow_runs',\n 'durable_step_checkpoints',\n 'durable_run_attributes',\n 'durable_signal_waiters',\n 'durable_buffered_signals',\n]);\n\n/** The table a `create table` / `alter table` statement targets, lower-cased; undefined otherwise. */\nfunction targetTable(statement: string): string | undefined {\n const match = statement.match(\n /^(?:create|alter)\\s+table\\s+(?:if\\s+not\\s+exists\\s+)?[`\"']?([\\w$]+)[`\"']?/i,\n );\n return match?.[1]?.toLowerCase();\n}\n\n/**\n * Whether a statement adds structure the store REQUIRES — a failure here is fatal (the store can't\n * run without the table/column/index). A column TYPE alignment (`modify`/`alter column ... type`)\n * is best-effort: the column already holds the data (the store serializes JSON to/from it regardless\n * of the declared type), so failing to converge its type — e.g. a legacy `longtext` value that won't\n * cast to `json` because it was truncated under an older `text` column — must NOT crash boot.\n */\nfunction isRequiredStructure(statement: string): boolean {\n return /\\b(?:create\\s+table|add\\s+(?:column|index|constraint|key|unique|fulltext))\\b/i.test(\n statement,\n );\n}\n\n/**\n * Idempotently create/extend ONLY the durable tables (additive — never drops). Safe to run on every\n * boot (auto-schema) and from a MikroORM migration when you disable auto-schema:\n *\n * ```ts\n * export class AddDurableTables extends Migration {\n * async up() { await ensureMikroOrmDurableSchema(this.getEntityManager().getOrm()); }\n * }\n * ```\n *\n * It does NOT run a whole-ORM `schema.update()`. When the store shares the host app's ORM (the\n * recommended setup — a single ORM avoids MikroORM's global-metadata clobber between instances),\n * a full `schema.update()` would try to reconcile EVERY app table to the entity metadata: on a\n * migration-managed schema that means recreating the migrations table and dropping app foreign keys.\n * Instead we compute the safe additive diff and execute only the statements that target our own\n * `durable_*` tables. `getUpdateSchemaSQL` already emits a `create table` only for a missing table\n * and `alter table ... add` only for missing columns, so existing tables — and the entire rest of\n * the host schema — are left untouched.\n */\nexport async function ensureMikroOrmDurableSchema(orm: MikroORM): Promise<void> {\n const sql = await orm.schema.getUpdateSchemaSQL({ safe: true });\n const ours = sql\n .split(';')\n .map((statement) => statement.trim())\n .filter((statement) => {\n const table = targetTable(statement);\n return table !== undefined && DURABLE_TABLE_NAMES.has(table);\n });\n const connection = orm.em.getConnection();\n for (const statement of ours) {\n try {\n await connection.execute(statement);\n } catch (err) {\n // Required structure (create table / add column / add index) must succeed — rethrow.\n if (isRequiredStructure(statement)) {\n throw err;\n }\n // A best-effort type alignment (e.g. legacy `longtext` → `json`) failed, typically because an\n // existing column holds a value that can't cast to the target type (a relic of an older column\n // type). The column already stores the data and the store reads/writes it via serialization, so\n // leave it as-is and continue rather than crashing boot. Surfaced so the data can be repaired\n // out of band (e.g. `UPDATE … SET col = NULL WHERE JSON_VALID(col) = 0` for a disposable column).\n const message = err instanceof Error ? err.message : String(err);\n console.warn(\n `[nestjs-durable-store-mikro-orm] skipped a non-structural durable-schema statement that failed; the column is left as-is (functional) — repair the data out of band to converge its type. Statement: ${statement} — ${message}`,\n );\n }\n }\n\n // Converge collation last, once the tables exist (whether just created above or pre-existing).\n await alignDurableCollation(orm);\n}\n\n/** A MySQL identifier we are willing to interpolate into DDL (charset / collation names). */\nfunction isSafeSqlIdentifier(value: string): boolean {\n return /^[A-Za-z0-9_]+$/.test(value);\n}\n\n/**\n * Align each durable table's collation to the ORM's configured `collate` (MySQL/MariaDB only).\n *\n * MikroORM's auto-schema (`getUpdateSchemaSQL`) creates tables with the server's DEFAULT collation —\n * on MySQL 8.4 that's `utf8mb4_0900_ai_ci` — and ignores the `collate` config option. When the host\n * app pins a different collation on its own tables (commonly `utf8mb4_unicode_ci` via migrations), a\n * JOIN between a durable table and an app table throws \"Illegal mix of collations\". We converge it\n * here: read the configured collation and `CONVERT` only the durable tables whose collation differs.\n *\n * Idempotent (matching tables are skipped), non-fatal (a CONVERT failure is warned, never crashes\n * boot), and a no-op when no `collate` is configured or the platform isn't MySQL/MariaDB.\n */\nasync function alignDurableCollation(orm: MikroORM): Promise<void> {\n const platform = String(orm.em.getPlatform().constructor.name).toLowerCase();\n if (!platform.includes('mysql') && !platform.includes('maria')) {\n return;\n }\n const collate = orm.config.get('collate');\n if (typeof collate !== 'string' || !isSafeSqlIdentifier(collate)) {\n return;\n }\n // utf8mb4_unicode_ci → utf8mb4. CONVERT TO needs the charset that owns the collation.\n const charset = collate.split('_')[0];\n if (!charset || !isSafeSqlIdentifier(charset)) {\n return;\n }\n const connection = orm.em.getConnection();\n for (const table of DURABLE_TABLE_NAMES) {\n try {\n const rows = (await connection.execute(\n 'select table_collation as collation from information_schema.tables where table_schema = database() and table_name = ? limit 1',\n [table],\n )) as Array<{ collation?: string | null }>;\n const current = rows[0]?.collation;\n // Table absent (nothing to align) or already at the target collation — skip.\n if (current == null || current === collate) {\n continue;\n }\n await connection.execute(\n `alter table \\`${table}\\` convert to character set ${charset} collate ${collate}`,\n );\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n console.warn(\n `[nestjs-durable-store-mikro-orm] could not align collation for \\`${table}\\` to ${collate} (left as-is): ${message}`,\n );\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;ACCA,kBAA6B;AAgB7B,SAASA,UAAUC,UAAgB;AACjC,SAAOA,SAASC,QAAQ,UAAU,CAACC,MAAM,IAAIA,EAAEC,YAAW,CAAA,EAAI;AAChE;AAFSJ;AAIT,SAASK,YAAYC,QAA2B;AAC9C,MAAIA,WAAW,aAAc,QAAON;AACpC,MAAIM,WAAW,WAAY,QAAO,CAACL,aAAaA;AAChD,SAAOK;AACT;AAJSD;AAUF,IAAME,oBAAN,MAAMA;EA9Bb,OA8BaA;;;EACXC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;AACF;AAEO,IAAMC,uBAAN,MAAMA;EAjDb,OAiDaA;;;EACXC;EACAC;EACAC;EACAC;EACAC;EACAlB;EACAC;EACAC;EACAC;EACAgB;EACAC;EACAC;EACAjB;EACAkB;EACAC;EACAC;AACF;AAQO,IAAMC,qBAAN,MAAMA;EA1Eb,OA0EaA;;;EACXX;EACAY;EACAC;EACAC;AACF;AAEO,IAAMC,qBAAN,MAAMA;EAjFb,OAiFaA;;;EACXC;EACAhB;EACAC;AACF;AAEO,IAAMgB,uBAAN,MAAMA;EAvFb,OAuFaA;;;EACXlC;EACAiC;EACAE;AACF;AAUO,SAASC,gBAAgBC,UAA4C,CAAC,GAAC;AAC5E,QAAMC,MAAMzC,YAAYwC,QAAQvC,UAAU,YAAA;AAE1C,QAAMyC,eAAe,I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GAAGW,MAAM;AACpD0F,IAAEmB,aAAaxH,GAAGwH;AAClBnB,IAAEoB,YAAYzH,GAAGyH;AACjBpB,IAAEqB,aAAa1H,GAAG0H;AAClB,SAAOrB;AACT;AAnBS1G;AAqBT,SAASJ,qBAAqB8G,GAAuB;AACnD,SAAO;IACLpI,OAAOoI,EAAEpI;IACTqB,KAAK+G,EAAE/G;IACPqF,MAAM0B,EAAE1B;IACRwC,MAAMd,EAAEc;IACRC,QAAQf,EAAEe;IACVjH,QAAQkG,EAAElG;IACVyG,OAAOP,EAAEO,SAASlB;IAClBmB,QAAQR,EAAEQ,UAAUnB;IACpBoB,OAAQT,EAAES,SAASpB;IACnB2B,QAAShB,EAAEgB,UAAU3B;IACrB4B,UAAUjB,EAAEiB;IACZC,aAAalB,EAAEkB,eAAe7B;IAC9B/E,QAAQ0F,EAAE1F,QAAQuG,QAAAA;IAClBM,YAAYnB,EAAEmB,cAAcnB,EAAEoB;IAC9BA,WAAWpB,EAAEoB;IACbC,YAAYrB,EAAEqB;EAChB;AACF;AAnBSnI;","names":["snakeCase","property","replace","c","toLowerCase","columnNamer","naming","WorkflowRunEntity","id","workflow","workflowVersion","status","input","output","error","wakeAt","lockedBy","lockedUntil","recoveryAttempts","tags","searchAttributes","priority","createdAt","updatedAt","StepCheckpointEntity","runId","seq","name","kind","stepId","events","attempts","workerGroup","enqueuedAt","startedAt","finishedAt","RunAttributeEntity","key","strValue","numValue","SignalWaiterEntity","token","BufferedSignalEntity","payload","durableEntities","options","col","workflowRuns","EntitySchema","class","tableName","properties","type","primary","fieldName","nullable","stepCheckpoints","runAttributes","signalWaiters","bufferedSignals","autoincrement","index","ENTITIES","DURABLE_TABLE_NAMES","Set","targetTable","statement","match","toLowerCase","isRequiredStructure","test","ensureMikroOrmDurableSchema","orm","sql","schema","getUpdateSchemaSQL","safe","ours","split","map","trim","filter","table","undefined","has","connection","em","getConnection","execute","err","message","Error","String","console","warn","alignDurableCollation","isSafeSqlIdentifier","value","platform","getPlatform","name","includes","collate","config","get","charset","rows","current","collation","MikroOrmStateStore","orm","ensureSchema","ensureMikroOrmDurableSchema","createRun","run","em","fork","create","WorkflowRunEntity","toRunEntity","flush","reindexAttributes","id","searchAttributes","updateRun","runId","patch","entity","findOneOrFail","Object","assign","fromRunEntity","attributes","forked","nativeDelete","RunAttributeEntity","rows","normalizeAttributeRows","length","insertMany","getRun","findOne","deleteRun","StepCheckpointEntity","SignalWaiterEntity","getCheckpoint","seq","fromCheckpointEntity","saveCheckpoint","checkpoint","upsert","toCheckpointEntity","transaction","work","transactional","raw","cp","listIncompleteRuns","find","status","map","listPendingRuns","limit","orderBy","createdAt","listDueTimers","nowMs","wakeAt","$ne","$lte","Date","tryLockRun","owner","leaseUntilMs","affected","nativeUpdate","$or","lockedUntil","lockedBy","releaseRunLock","renewRunLock","listRuns","query","where","workflow","statuses","$and","$in","tag","quote","idQuote","cols","attributeColumns","qb","createQueryBuilder","tagsCol","tagsColumn","pattern","replace","colExpr","jsonAsText","andWhere","f","attributeExistsSql","offset","getResultList","alias","col","attributeColumnFor","numValue","strValue","cmp","sqlComparator","op","operand","attributeOperand","literal","String","a","table","sub","outerId","runPk","key","meta","getMetadata","get","field","prop","props","p","name","fieldNames","runMeta","properties","tableName","tags","colRef","platform","getPlatform","toLowerCase","includes","isMysql","ch","listCheckpoints","getLatestCheckpointByName","undefined","listCheckpointsByNamePrefix","prefixes","$like","putSignalWaiter","waiter","takeSignalWaiter","token","remove","listSignalWaiters","prefix","e","bufferSignal","payload","BufferedSignalEntity","persist","takeBufferedSignal","workflowVersion","input","output","error","recoveryAttempts","priority","updatedAt","getTime","kind","stepId","events","attempts","workerGroup","enqueuedAt","startedAt","finishedAt"]}
package/dist/index.d.cts CHANGED
@@ -29,6 +29,7 @@ declare class WorkflowRunEntity {
29
29
  recoveryAttempts?: number;
30
30
  tags?: string[] | null;
31
31
  searchAttributes?: Record<string, string | number | boolean> | null;
32
+ priority?: number | null;
32
33
  createdAt: Date;
33
34
  updatedAt: Date;
34
35
  }
package/dist/index.d.ts CHANGED
@@ -29,6 +29,7 @@ declare class WorkflowRunEntity {
29
29
  recoveryAttempts?: number;
30
30
  tags?: string[] | null;
31
31
  searchAttributes?: Record<string, string | number | boolean> | null;
32
+ priority?: number | null;
32
33
  createdAt: Date;
33
34
  updatedAt: Date;
34
35
  }
package/dist/index.js CHANGED
@@ -30,6 +30,7 @@ var WorkflowRunEntity = class {
30
30
  recoveryAttempts;
31
31
  tags;
32
32
  searchAttributes;
33
+ priority;
33
34
  createdAt;
34
35
  updatedAt;
35
36
  };
@@ -147,6 +148,11 @@ function durableEntities(options = {}) {
147
148
  nullable: true,
148
149
  fieldName: col("searchAttributes")
149
150
  },
151
+ priority: {
152
+ type: "integer",
153
+ nullable: true,
154
+ fieldName: col("priority")
155
+ },
150
156
  createdAt: {
151
157
  type: "Date",
152
158
  fieldName: col("createdAt")
@@ -331,6 +337,10 @@ function targetTable(statement) {
331
337
  return match?.[1]?.toLowerCase();
332
338
  }
333
339
  __name(targetTable, "targetTable");
340
+ function isRequiredStructure(statement) {
341
+ return /\b(?:create\s+table|add\s+(?:column|index|constraint|key|unique|fulltext))\b/i.test(statement);
342
+ }
343
+ __name(isRequiredStructure, "isRequiredStructure");
334
344
  async function ensureMikroOrmDurableSchema(orm) {
335
345
  const sql = await orm.schema.getUpdateSchemaSQL({
336
346
  safe: true
@@ -339,15 +349,56 @@ async function ensureMikroOrmDurableSchema(orm) {
339
349
  const table = targetTable(statement);
340
350
  return table !== void 0 && DURABLE_TABLE_NAMES.has(table);
341
351
  });
342
- if (ours.length === 0) {
343
- return;
344
- }
345
352
  const connection = orm.em.getConnection();
346
353
  for (const statement of ours) {
347
- await connection.execute(statement);
354
+ try {
355
+ await connection.execute(statement);
356
+ } catch (err) {
357
+ if (isRequiredStructure(statement)) {
358
+ throw err;
359
+ }
360
+ const message = err instanceof Error ? err.message : String(err);
361
+ console.warn(`[nestjs-durable-store-mikro-orm] skipped a non-structural durable-schema statement that failed; the column is left as-is (functional) \u2014 repair the data out of band to converge its type. Statement: ${statement} \u2014 ${message}`);
362
+ }
348
363
  }
364
+ await alignDurableCollation(orm);
349
365
  }
350
366
  __name(ensureMikroOrmDurableSchema, "ensureMikroOrmDurableSchema");
367
+ function isSafeSqlIdentifier(value) {
368
+ return /^[A-Za-z0-9_]+$/.test(value);
369
+ }
370
+ __name(isSafeSqlIdentifier, "isSafeSqlIdentifier");
371
+ async function alignDurableCollation(orm) {
372
+ const platform = String(orm.em.getPlatform().constructor.name).toLowerCase();
373
+ if (!platform.includes("mysql") && !platform.includes("maria")) {
374
+ return;
375
+ }
376
+ const collate = orm.config.get("collate");
377
+ if (typeof collate !== "string" || !isSafeSqlIdentifier(collate)) {
378
+ return;
379
+ }
380
+ const charset = collate.split("_")[0];
381
+ if (!charset || !isSafeSqlIdentifier(charset)) {
382
+ return;
383
+ }
384
+ const connection = orm.em.getConnection();
385
+ for (const table of DURABLE_TABLE_NAMES) {
386
+ try {
387
+ const rows = await connection.execute("select table_collation as collation from information_schema.tables where table_schema = database() and table_name = ? limit 1", [
388
+ table
389
+ ]);
390
+ const current = rows[0]?.collation;
391
+ if (current == null || current === collate) {
392
+ continue;
393
+ }
394
+ await connection.execute(`alter table \`${table}\` convert to character set ${charset} collate ${collate}`);
395
+ } catch (err) {
396
+ const message = err instanceof Error ? err.message : String(err);
397
+ console.warn(`[nestjs-durable-store-mikro-orm] could not align collation for \`${table}\` to ${collate} (left as-is): ${message}`);
398
+ }
399
+ }
400
+ }
401
+ __name(alignDurableCollation, "alignDurableCollation");
351
402
 
352
403
  // src/mikro-orm-state-store.ts
353
404
  var MikroOrmStateStore = class {
@@ -722,6 +773,7 @@ function toRunEntity(run) {
722
773
  if (run.recoveryAttempts !== void 0) e.recoveryAttempts = run.recoveryAttempts;
723
774
  e.tags = run.tags ?? null;
724
775
  e.searchAttributes = run.searchAttributes ?? null;
776
+ e.priority = run.priority ?? null;
725
777
  e.createdAt = run.createdAt;
726
778
  e.updatedAt = run.updatedAt;
727
779
  return e;
@@ -742,6 +794,7 @@ function fromRunEntity(e) {
742
794
  recoveryAttempts: e.recoveryAttempts ?? void 0,
743
795
  tags: e.tags ?? void 0,
744
796
  searchAttributes: e.searchAttributes ?? void 0,
797
+ priority: e.priority ?? void 0,
745
798
  createdAt: e.createdAt,
746
799
  updatedAt: e.updatedAt
747
800
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/entities.ts","../src/mikro-orm-state-store.ts","../src/schema.ts"],"sourcesContent":["import type { RunStatus, StepKind } from '@dudousxd/nestjs-durable-core';\nimport { EntitySchema } from '@mikro-orm/core';\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 TypeORM,\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\nfunction 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 `em.create`/`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;\n lockedUntil?: Date;\n recoveryAttempts?: number;\n tags?: string[] | null;\n searchAttributes?: Record<string, string | number | boolean> | 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;\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}\n\nexport class BufferedSignalEntity {\n id!: number;\n token!: string;\n payload?: unknown;\n}\n\n/**\n * Build the durable MikroORM entity schemas with column names pinned per `naming` (default\n * `'snake_case'`). Register the result in your MikroORM config / `MikroOrmModule.forFeature`.\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 class: WorkflowRunEntity,\n tableName: 'durable_workflow_runs',\n properties: {\n id: { type: 'string', primary: true, fieldName: col('id') },\n workflow: { type: 'string', fieldName: col('workflow') },\n workflowVersion: { type: 'string', fieldName: col('workflowVersion') },\n status: { type: 'string', fieldName: col('status') },\n input: { type: 'json', nullable: true, fieldName: col('input') },\n output: { type: 'json', nullable: true, fieldName: col('output') },\n error: { type: 'json', nullable: true, fieldName: col('error') },\n wakeAt: { type: 'Date', nullable: true, fieldName: col('wakeAt') },\n lockedBy: { type: 'string', nullable: true, fieldName: col('lockedBy') },\n lockedUntil: { type: 'Date', nullable: true, fieldName: col('lockedUntil') },\n recoveryAttempts: { type: 'integer', nullable: true, fieldName: col('recoveryAttempts') },\n tags: { type: 'json', nullable: true, fieldName: col('tags') },\n searchAttributes: { type: 'json', nullable: true, fieldName: col('searchAttributes') },\n createdAt: { type: 'Date', fieldName: col('createdAt') },\n updatedAt: { type: 'Date', fieldName: col('updatedAt') },\n },\n });\n\n const stepCheckpoints = new EntitySchema<StepCheckpointEntity>({\n class: StepCheckpointEntity,\n tableName: 'durable_step_checkpoints',\n properties: {\n runId: { type: 'string', primary: true, fieldName: col('runId') },\n seq: { type: 'integer', primary: true, fieldName: col('seq') },\n name: { type: 'string', fieldName: col('name') },\n kind: { type: 'string', fieldName: col('kind') },\n stepId: { type: 'string', fieldName: col('stepId') },\n status: { type: 'string', fieldName: col('status') },\n input: { type: 'json', nullable: true, fieldName: col('input') },\n output: { type: 'json', nullable: true, fieldName: col('output') },\n error: { type: 'json', nullable: true, fieldName: col('error') },\n events: { type: 'json', nullable: true, fieldName: col('events') },\n attempts: { type: 'integer', fieldName: col('attempts') },\n workerGroup: { type: 'string', nullable: true, fieldName: col('workerGroup') },\n wakeAt: { type: 'Date', nullable: true, fieldName: col('wakeAt') },\n enqueuedAt: { type: 'Date', nullable: true, fieldName: col('enqueuedAt') },\n startedAt: { type: 'Date', fieldName: col('startedAt') },\n finishedAt: { type: 'Date', fieldName: col('finishedAt') },\n },\n });\n\n const runAttributes = new EntitySchema<RunAttributeEntity>({\n class: RunAttributeEntity,\n tableName: 'durable_run_attributes',\n properties: {\n runId: { type: 'string', primary: true, fieldName: col('runId') },\n key: { type: 'string', primary: true, fieldName: col('key') },\n strValue: { type: 'string', nullable: true, fieldName: col('strValue') },\n // `float`/`double` is portable across SQLite/MySQL/Postgres for numeric range scans.\n numValue: { type: 'float', nullable: true, fieldName: col('numValue') },\n },\n });\n\n const signalWaiters = new EntitySchema<SignalWaiterEntity>({\n class: SignalWaiterEntity,\n tableName: 'durable_signal_waiters',\n properties: {\n token: { type: 'string', primary: true, fieldName: col('token') },\n runId: { type: 'string', fieldName: col('runId') },\n seq: { type: 'integer', fieldName: col('seq') },\n },\n });\n\n const bufferedSignals = new EntitySchema<BufferedSignalEntity>({\n class: BufferedSignalEntity,\n tableName: 'durable_buffered_signals',\n properties: {\n id: { type: 'integer', primary: true, autoincrement: true, fieldName: col('id') },\n token: { type: 'string', index: true, fieldName: col('token') },\n payload: { type: 'json', nullable: true, fieldName: col('payload') },\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 {\n type AttributeFilter,\n type RunQuery,\n type SignalWaiter,\n type StateStore,\n type StepCheckpoint,\n type StepError,\n type StepEvent,\n type WorkflowRun,\n attributeColumnFor,\n attributeOperand,\n normalizeAttributeRows,\n sqlComparator,\n} from '@dudousxd/nestjs-durable-core';\nimport type { EntityManager, MikroORM } from '@mikro-orm/core';\n\n/** Minimal structural surface of the SQL EntityManager's QueryBuilder (from `@mikro-orm/knex`),\n * typed here so the adapter needn't add a hard dependency on the knex types — a real SQL-driver EM\n * satisfies it at runtime. */\ninterface DurableQueryBuilder<T> {\n where(cond: Record<string, unknown>): DurableQueryBuilder<T>;\n andWhere(cond: string): DurableQueryBuilder<T>;\n orderBy(cond: Record<string, unknown>): DurableQueryBuilder<T>;\n limit(n: number): DurableQueryBuilder<T>;\n offset(n: number): DurableQueryBuilder<T>;\n getResultList(): Promise<T[]>;\n}\ntype SqlEm = EntityManager & {\n createQueryBuilder<T>(entity: unknown, alias: string): DurableQueryBuilder<T>;\n};\n\n/** Resolved side-table column names (per the active naming strategy) for the raw EXISTS pushdown. */\ninterface AttributeColumns {\n table: string;\n /** Side-table FK column (the run id on `durable_run_attributes`). */\n runId: string;\n /** Run table PK column (the `id` on `durable_workflow_runs`) used for the outer correlation. */\n runPk: string;\n key: string;\n strValue: string;\n numValue: string;\n}\nimport {\n BufferedSignalEntity,\n RunAttributeEntity,\n SignalWaiterEntity,\n StepCheckpointEntity,\n WorkflowRunEntity,\n} from './entities';\nimport { ensureMikroOrmDurableSchema } from './schema';\n\n/**\n * MikroORM-backed `StateStore`. Works on any MikroORM driver — Postgres, MySQL, SQLite (tested);\n * timestamps and `wakeAt` use native datetime columns. Each operation runs on a forked\n * EntityManager so it owns its unit of work.\n */\nexport class MikroOrmStateStore implements StateStore {\n constructor(private readonly orm: MikroORM) {}\n\n async ensureSchema(): Promise<void> {\n await ensureMikroOrmDurableSchema(this.orm);\n }\n\n async createRun(run: WorkflowRun): Promise<void> {\n const em = this.orm.em.fork();\n em.create(WorkflowRunEntity, toRunEntity(run));\n await em.flush();\n await this.reindexAttributes(run.id, run.searchAttributes);\n }\n\n async updateRun(runId: string, patch: Partial<WorkflowRun>): Promise<void> {\n const em = this.orm.em.fork();\n const entity = await em.findOneOrFail(WorkflowRunEntity, { id: runId });\n Object.assign(entity, toRunEntity({ ...fromRunEntity(entity), ...patch } as WorkflowRun));\n await em.flush();\n // Keep the side-table in step with the run's attributes whenever they're patched.\n if ('searchAttributes' in patch) await this.reindexAttributes(runId, patch.searchAttributes);\n }\n\n /** Rewrite a run's normalized attribute rows: delete the old set, insert the current one. Mirrors\n * the in-memory store's reindex so the side-table always reflects the run's live searchAttributes. */\n private async reindexAttributes(\n runId: string,\n attributes: WorkflowRun['searchAttributes'],\n forked?: EntityManager,\n ): Promise<void> {\n const em = forked ?? this.orm.em.fork();\n await em.nativeDelete(RunAttributeEntity, { runId });\n const rows = normalizeAttributeRows(runId, attributes);\n if (rows.length) await em.insertMany(RunAttributeEntity, rows);\n }\n\n async getRun(runId: string): Promise<WorkflowRun | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(WorkflowRunEntity, { id: runId });\n return entity ? fromRunEntity(entity) : null;\n }\n\n async deleteRun(runId: string): Promise<void> {\n const em = this.orm.em.fork();\n // Children first, then the run row — checkpoints, signal waiters, and the normalized\n // attribute side-table, so nothing dangles after the run is gone.\n await em.nativeDelete(StepCheckpointEntity, { runId });\n await em.nativeDelete(SignalWaiterEntity, { runId });\n await em.nativeDelete(RunAttributeEntity, { runId });\n await em.nativeDelete(WorkflowRunEntity, { id: runId });\n }\n\n async getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(StepCheckpointEntity, { runId, seq });\n return entity ? fromCheckpointEntity(entity) : null;\n }\n\n async saveCheckpoint(checkpoint: StepCheckpoint): Promise<void> {\n const em = this.orm.em.fork();\n await em.upsert(StepCheckpointEntity, toCheckpointEntity(checkpoint));\n await em.flush();\n }\n\n async transaction<T>(\n work: (tx: {\n raw: unknown;\n saveCheckpoint: (cp: StepCheckpoint) => Promise<void>;\n }) => Promise<T>,\n ): Promise<T> {\n return this.orm.em.fork().transactional(async (em) =>\n work({\n raw: em,\n saveCheckpoint: async (cp) => {\n await em.upsert(StepCheckpointEntity, toCheckpointEntity(cp));\n },\n }),\n );\n }\n\n async listIncompleteRuns(): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(WorkflowRunEntity, { status: 'running' });\n return rows.map(fromRunEntity);\n }\n\n async listPendingRuns(limit: number): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(\n WorkflowRunEntity,\n { status: 'pending' },\n { orderBy: { createdAt: 'asc' }, limit }, // FIFO dispatch\n );\n return rows.map(fromRunEntity);\n }\n\n async listDueTimers(nowMs: number): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(WorkflowRunEntity, {\n status: 'suspended',\n wakeAt: { $ne: null, $lte: new Date(nowMs) },\n });\n return rows.map(fromRunEntity);\n }\n\n async tryLockRun(\n runId: string,\n owner: string,\n leaseUntilMs: number,\n nowMs: number,\n ): Promise<boolean> {\n const em = this.orm.em.fork();\n const affected = await em.nativeUpdate(\n WorkflowRunEntity,\n { id: runId, $or: [{ lockedUntil: null }, { lockedUntil: { $lte: new Date(nowMs) } }] },\n { lockedBy: owner, lockedUntil: new Date(leaseUntilMs) },\n );\n return affected === 1;\n }\n\n async releaseRunLock(runId: string): Promise<void> {\n const em = this.orm.em.fork();\n await em.nativeUpdate(WorkflowRunEntity, { id: runId }, { lockedBy: null, lockedUntil: null });\n }\n\n async renewRunLock(runId: string, owner: string, leaseUntilMs: number): Promise<boolean> {\n const em = this.orm.em.fork();\n const affected = await em.nativeUpdate(\n WorkflowRunEntity,\n { id: runId, lockedBy: owner },\n { lockedUntil: new Date(leaseUntilMs) },\n );\n return affected === 1;\n }\n\n async listRuns(query: RunQuery): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const where: Record<string, unknown> = {};\n if (query.workflow) where.workflow = query.workflow;\n // `status IN (...)`; an empty set matches nothing (mirrors the in-memory store). When both the\n // single `status` and `statuses` are set, AND them so the narrower set wins.\n if (query.status && query.statuses) {\n where.$and = [{ status: query.status }, { status: { $in: query.statuses } }];\n } else if (query.status) {\n where.status = query.status;\n } else if (query.statuses) {\n where.status = { $in: query.statuses };\n }\n const orderBy = { createdAt: 'desc' as const }; // newest first — recent runs on top in the dashboard\n // `tags`/attributes need raw SQL pushed through the QueryBuilder:\n // - tag: `tags` is a JSON column (native json/jsonb on PG/MySQL), and MikroORM JSON-serializes a\n // `{ $like }` operand (wrapping/escaping the LIKE pattern) so a plain where corrupts it to no\n // matches. A raw LIKE on the column-as-text matches the quoted token so `etl` doesn't match\n // `etl-foo`. Postgres `jsonb` rejects `LIKE` directly, so cast to text per dialect.\n // - attributes: each filter becomes a raw EXISTS against the normalized side-table, so the DB\n // filters AND paginates — no full scan + in-process filter (ANDed: one EXISTS per filter).\n // Use a QueryBuilder with a fixed root alias `r` so the raw correlations are stable across drivers.\n if (query.tag || query.attributes?.length) {\n const quote = this.idQuote(em);\n const cols = this.attributeColumns(em);\n const qb = (em as SqlEm)\n .createQueryBuilder<WorkflowRunEntity>(WorkflowRunEntity, 'r')\n .where(where)\n .orderBy(orderBy);\n if (query.tag) {\n const tagsCol = this.tagsColumn(em);\n const pattern = `%\"${query.tag.replace(/'/g, \"''\")}\"%`;\n const colExpr = this.jsonAsText(em, `${quote('r')}.${quote(tagsCol)}`);\n qb.andWhere(`${colExpr} LIKE '${pattern}'`);\n }\n for (const f of query.attributes ?? []) {\n qb.andWhere(this.attributeExistsSql(f, quote, 'r', cols));\n }\n if (query.limit != null) qb.limit(query.limit);\n if (query.offset != null) qb.offset(query.offset);\n const rows = await qb.getResultList();\n return rows.map(fromRunEntity);\n }\n const rows = await em.find(WorkflowRunEntity, where, {\n ...(query.limit != null ? { limit: query.limit } : {}),\n ...(query.offset != null ? { offset: query.offset } : {}),\n orderBy,\n });\n return rows.map(fromRunEntity);\n }\n\n /** One attribute predicate as a raw EXISTS subquery on the side-table, correlated to the outer run\n * alias. `<>` (ne) also excludes runs where the attribute is absent (missing-key-never-matches):\n * EXISTS already requires a present row, so EXISTS(... <> ...) is exactly ne-with-present. Numeric\n * operands compare the num column, everything else the str column. Identifiers are quoted per\n * driver and operands are inlined as literals (string operands are escaped by doubling quotes). */\n private attributeExistsSql(\n f: AttributeFilter,\n quote: (id: string) => string,\n alias: string,\n cols: AttributeColumns,\n ): string {\n const col = attributeColumnFor(f) === 'numValue' ? cols.numValue : cols.strValue;\n const cmp = sqlComparator(f.op);\n const operand = attributeOperand(f);\n const literal =\n typeof operand === 'number' ? String(operand) : `'${String(operand).replace(/'/g, \"''\")}'`;\n const a = quote(cols.table);\n const sub = quote('a');\n const outerId = `${quote(alias)}.${quote(cols.runPk)}`; // run PK column on the outer alias\n return `EXISTS (SELECT 1 FROM ${a} ${sub} WHERE ${sub}.${quote(cols.runId)} = ${outerId} AND ${sub}.${quote(cols.key)} = '${f.key.replace(/'/g, \"''\")}' AND ${sub}.${quote(col)} ${cmp} ${literal})`;\n }\n\n /** Resolve the side-table's actual column names from MikroORM metadata, so the raw EXISTS matches\n * the active naming strategy (underscore vs camelCase) rather than guessing. The run PK column is\n * reused for BOTH the outer correlation and the side-table FK (they share the same fieldName). */\n private attributeColumns(em: EntityManager): AttributeColumns {\n const meta = em.getMetadata().get(RunAttributeEntity);\n const field = (prop: string) =>\n meta.props.find((p) => p.name === prop)?.fieldNames?.[0] ?? prop;\n const runMeta = em.getMetadata().get(WorkflowRunEntity);\n const runPk = runMeta.properties.id?.fieldNames?.[0] ?? 'id';\n return {\n table: meta.tableName,\n runId: field('runId'),\n runPk,\n key: field('key'),\n strValue: field('strValue'),\n numValue: field('numValue'),\n };\n }\n\n /** Resolve the `tags` column name from metadata (per the active naming strategy), for the raw LIKE. */\n private tagsColumn(em: EntityManager): string {\n const runMeta = em.getMetadata().get(WorkflowRunEntity);\n return runMeta.properties.tags?.fieldNames?.[0] ?? 'tags';\n }\n\n /** Wrap a JSON column reference so it can be `LIKE`d as text. Postgres `jsonb`/`json` rejects `LIKE`\n * directly (`operator does not exist: jsonb ~~ unknown`) — cast to `text`; MySQL JSON needs an\n * explicit `CHAR` cast; SQLite stores JSON as text already, so no cast. */\n private jsonAsText(em: EntityManager, colRef: string): string {\n const platform = String(em.getPlatform().constructor.name).toLowerCase();\n if (platform.includes('postgre')) return `${colRef}::text`;\n if (platform.includes('mysql') || platform.includes('mariadb'))\n return `CAST(${colRef} AS CHAR)`;\n return colRef;\n }\n\n /** Quote an identifier per the active SQL driver (MySQL/MariaDB backtick, others double-quote). */\n private idQuote(em: EntityManager): (id: string) => string {\n const platform = String(em.getPlatform().constructor.name).toLowerCase();\n const isMysql = platform.includes('mysql') || platform.includes('mariadb');\n const ch = isMysql ? '`' : '\"';\n return (id: string) => `${ch}${id}${ch}`;\n }\n\n async listCheckpoints(runId: string): Promise<StepCheckpoint[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(StepCheckpointEntity, { runId }, { orderBy: { seq: 'asc' } });\n return rows.map(fromCheckpointEntity);\n }\n\n async getLatestCheckpointByName(\n runId: string,\n name: string,\n ): Promise<StepCheckpoint | undefined> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(\n StepCheckpointEntity,\n { runId, name },\n { orderBy: { seq: 'desc' } },\n );\n return entity ? fromCheckpointEntity(entity) : undefined;\n }\n\n async listCheckpointsByNamePrefix(runId: string, prefixes: string[]): Promise<StepCheckpoint[]> {\n if (prefixes.length === 0) return [];\n const em = this.orm.em.fork();\n const rows = await em.find(\n StepCheckpointEntity,\n { runId, $or: prefixes.map((p) => ({ name: { $like: `${p}%` } })) },\n { orderBy: { seq: 'asc' } },\n );\n return rows.map(fromCheckpointEntity);\n }\n\n async putSignalWaiter(waiter: SignalWaiter): Promise<void> {\n const em = this.orm.em.fork();\n await em.upsert(SignalWaiterEntity, { ...waiter });\n await em.flush();\n }\n\n async takeSignalWaiter(token: string): Promise<SignalWaiter | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(SignalWaiterEntity, { token });\n if (!entity) return null;\n const waiter: SignalWaiter = { token: entity.token, runId: entity.runId, seq: entity.seq };\n await em.remove(entity).flush();\n return waiter;\n }\n\n async listSignalWaiters(prefix: string): Promise<SignalWaiter[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(SignalWaiterEntity, { token: { $like: `${prefix}%` } });\n return rows.map((e) => ({ token: e.token, runId: e.runId, seq: e.seq }));\n }\n\n async bufferSignal(token: string, payload: unknown): Promise<void> {\n const em = this.orm.em.fork();\n const e = new BufferedSignalEntity();\n e.token = token;\n e.payload = payload ?? null;\n em.persist(e);\n await em.flush();\n }\n\n async takeBufferedSignal(token: string): Promise<{ payload: unknown } | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(BufferedSignalEntity, { token }, { orderBy: { id: 'asc' } });\n if (!entity) return null;\n const payload = entity.payload ?? undefined;\n await em.remove(entity).flush();\n return { payload };\n }\n}\n\nfunction toRunEntity(run: WorkflowRun): WorkflowRunEntity {\n const e = new WorkflowRunEntity();\n e.id = run.id;\n e.workflow = run.workflow;\n e.workflowVersion = run.workflowVersion;\n e.status = run.status;\n e.input = run.input ?? null;\n e.output = run.output ?? null;\n e.error = run.error ?? null;\n if (run.wakeAt != null) e.wakeAt = new Date(run.wakeAt);\n if (run.lockedBy !== undefined) e.lockedBy = run.lockedBy;\n if (run.lockedUntil != null) e.lockedUntil = new Date(run.lockedUntil);\n if (run.recoveryAttempts !== undefined) e.recoveryAttempts = run.recoveryAttempts;\n e.tags = run.tags ?? null;\n e.searchAttributes = run.searchAttributes ?? null;\n e.createdAt = run.createdAt;\n e.updatedAt = run.updatedAt;\n return e;\n}\n\nfunction fromRunEntity(e: WorkflowRunEntity): WorkflowRun {\n return {\n id: e.id,\n workflow: e.workflow,\n workflowVersion: e.workflowVersion,\n status: e.status,\n input: e.input ?? undefined,\n output: e.output ?? undefined,\n error: (e.error ?? undefined) as StepError | undefined,\n wakeAt: e.wakeAt?.getTime(),\n lockedBy: e.lockedBy ?? undefined,\n lockedUntil: e.lockedUntil?.getTime(),\n recoveryAttempts: e.recoveryAttempts ?? undefined,\n tags: e.tags ?? undefined,\n searchAttributes: e.searchAttributes ?? undefined,\n createdAt: e.createdAt,\n updatedAt: e.updatedAt,\n };\n}\n\nfunction toCheckpointEntity(cp: StepCheckpoint): StepCheckpointEntity {\n const e = new StepCheckpointEntity();\n e.runId = cp.runId;\n e.seq = cp.seq;\n e.name = cp.name;\n e.kind = cp.kind;\n e.stepId = cp.stepId;\n e.status = cp.status;\n e.input = cp.input ?? null;\n e.output = cp.output ?? null;\n e.error = cp.error ?? null;\n e.events = cp.events ?? null;\n e.attempts = cp.attempts;\n if (cp.workerGroup !== undefined) e.workerGroup = cp.workerGroup;\n if (cp.wakeAt != null) e.wakeAt = new Date(cp.wakeAt);\n e.enqueuedAt = cp.enqueuedAt;\n e.startedAt = cp.startedAt;\n e.finishedAt = cp.finishedAt;\n return e;\n}\n\nfunction fromCheckpointEntity(e: StepCheckpointEntity): StepCheckpoint {\n return {\n runId: e.runId,\n seq: e.seq,\n name: e.name,\n kind: e.kind,\n stepId: e.stepId,\n status: e.status,\n input: e.input ?? undefined,\n output: e.output ?? undefined,\n error: (e.error ?? undefined) as StepError | undefined,\n events: (e.events ?? undefined) as StepEvent[] | undefined,\n attempts: e.attempts,\n workerGroup: e.workerGroup ?? undefined,\n wakeAt: e.wakeAt?.getTime(),\n enqueuedAt: e.enqueuedAt ?? e.startedAt,\n startedAt: e.startedAt,\n finishedAt: e.finishedAt,\n };\n}\n","import type { MikroORM } from '@mikro-orm/core';\n\n/**\n * The tables this store owns. Kept in sync with the `tableName`s in `./entities`. Used to scope\n * schema management to our own tables (see {@link ensureMikroOrmDurableSchema}).\n */\nconst DURABLE_TABLE_NAMES = new Set([\n 'durable_workflow_runs',\n 'durable_step_checkpoints',\n 'durable_run_attributes',\n 'durable_signal_waiters',\n 'durable_buffered_signals',\n]);\n\n/** The table a `create table` / `alter table` statement targets, lower-cased; undefined otherwise. */\nfunction targetTable(statement: string): string | undefined {\n const match = statement.match(\n /^(?:create|alter)\\s+table\\s+(?:if\\s+not\\s+exists\\s+)?[`\"']?([\\w$]+)[`\"']?/i,\n );\n return match?.[1]?.toLowerCase();\n}\n\n/**\n * Idempotently create/extend ONLY the durable tables (additive — never drops). Safe to run on every\n * boot (auto-schema) and from a MikroORM migration when you disable auto-schema:\n *\n * ```ts\n * export class AddDurableTables extends Migration {\n * async up() { await ensureMikroOrmDurableSchema(this.getEntityManager().getOrm()); }\n * }\n * ```\n *\n * It does NOT run a whole-ORM `schema.update()`. When the store shares the host app's ORM (the\n * recommended setup — a single ORM avoids MikroORM's global-metadata clobber between instances),\n * a full `schema.update()` would try to reconcile EVERY app table to the entity metadata: on a\n * migration-managed schema that means recreating the migrations table and dropping app foreign keys.\n * Instead we compute the safe additive diff and execute only the statements that target our own\n * `durable_*` tables. `getUpdateSchemaSQL` already emits a `create table` only for a missing table\n * and `alter table ... add` only for missing columns, so existing tables — and the entire rest of\n * the host schema — are left untouched.\n */\nexport async function ensureMikroOrmDurableSchema(orm: MikroORM): Promise<void> {\n const sql = await orm.schema.getUpdateSchemaSQL({ safe: true });\n const ours = sql\n .split(';')\n .map((statement) => statement.trim())\n .filter((statement) => {\n const table = targetTable(statement);\n return table !== undefined && DURABLE_TABLE_NAMES.has(table);\n });\n if (ours.length === 0) {\n return;\n }\n const connection = orm.em.getConnection();\n for (const statement of ours) {\n await connection.execute(statement);\n }\n}\n"],"mappings":";;;;AACA,SAASA,oBAAoB;AAgB7B,SAASC,UAAUC,UAAgB;AACjC,SAAOA,SAASC,QAAQ,UAAU,CAACC,MAAM,IAAIA,EAAEC,YAAW,CAAA,EAAI;AAChE;AAFSJ;AAIT,SAASK,YAAYC,QAA2B;AAC9C,MAAIA,WAAW,aAAc,QAAON;AACpC,MAAIM,WAAW,WAAY,QAAO,CAACL,aAAaA;AAChD,SAAOK;AACT;AAJSD;AAUF,IAAME,oBAAN,MAAMA;EA9Bb,OA8BaA;;;EACXC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;AACF;AAEO,IAAMC,uBAAN,MAAMA;EAhDb,OAgDaA;;;EACXC;EACAC;EACAC;EACAC;EACAC;EACAjB;EACAC;EACAC;EACAC;EACAe;EACAC;EACAC;EACAhB;EACAiB;EACAC;EACAC;AACF;AAQO,IAAMC,qBAAN,MAAMA;EAzEb,OAyEaA;;;EACXX;EACAY;EACAC;EACAC;AACF;AAEO,IAAMC,qBAAN,MAAMA;EAhFb,OAgFaA;;;EACXC;EACAhB;EACAC;AACF;AAEO,IAAMgB,uBAAN,MAAMA;EAtFb,OAsFaA;;;EACXjC;EACAgC;EACAE;AACF;AAUO,SAASC,gBAAgBC,UAA4C,CAAC,GAAC;AAC5E,QAAMC,MAAMxC,YAAYuC,QAAQtC,UAAU,YAAA;AAE1C,QAAMwC,eAAe,IAAIC,aAAgC;IACvDC,OAAOzC;IACP0C,WAAW;IACXC,YAAY;MACV1C,IAAI;QAAE2C,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c;IACVhH,QAAQkG,EAAElG;IACVyG,OAAOP,EAAEO,SAASlB;IAClBmB,QAAQR,EAAEQ,UAAUnB;IACpBoB,OAAQT,EAAES,SAASpB;IACnB0B,QAASf,EAAEe,UAAU1B;IACrB2B,UAAUhB,EAAEgB;IACZC,aAAajB,EAAEiB,eAAe5B;IAC9B/E,QAAQ0F,EAAE1F,QAAQsG,QAAAA;IAClBM,YAAYlB,EAAEkB,cAAclB,EAAEmB;IAC9BA,WAAWnB,EAAEmB;IACbC,YAAYpB,EAAEoB;EAChB;AACF;AAnBSlI;","names":["EntitySchema","snakeCase","property","replace","c","toLowerCase","columnNamer","naming","WorkflowRunEntity","id","workflow","workflowVersion","status","input","output","error","wakeAt","lockedBy","lockedUntil","recoveryAttempts","tags","searchAttributes","createdAt","updatedAt","StepCheckpointEntity","runId","seq","name","kind","stepId","events","attempts","workerGroup","enqueuedAt","startedAt","finishedAt","RunAttributeEntity","key","strValue","numValue","SignalWaiterEntity","token","BufferedSignalEntity","payload","durableEntities","options","col","workflowRuns","EntitySchema","class","tableName","properties","type","primary","fieldName","nullable","stepCheckpoints","runAttributes","signalWaiters","bufferedSignals","autoincrement","index","ENTITIES","attributeColumnFor","attributeOperand","normalizeAttributeRows","sqlComparator","DURABLE_TABLE_NAMES","Set","targetTable","statement","match","toLowerCase","ensureMikroOrmDurableSchema","orm","sql","schema","getUpdateSchemaSQL","safe","ours","split","map","trim","filter","table","undefined","has","length","connection","em","getConnection","execute","MikroOrmStateStore","orm","ensureSchema","ensureMikroOrmDurableSchema","createRun","run","em","fork","create","WorkflowRunEntity","toRunEntity","flush","reindexAttributes","id","searchAttributes","updateRun","runId","patch","entity","findOneOrFail","Object","assign","fromRunEntity","attributes","forked","nativeDelete","RunAttributeEntity","rows","normalizeAttributeRows","length","insertMany","getRun","findOne","deleteRun","StepCheckpointEntity","SignalWaiterEntity","getCheckpoint","seq","fromCheckpointEntity","saveCheckpoint","checkpoint","upsert","toCheckpointEntity","transaction","work","transactional","raw","cp","listIncompleteRuns","find","status","map","listPendingRuns","limit","orderBy","createdAt","listDueTimers","nowMs","wakeAt","$ne","$lte","Date","tryLockRun","owner","leaseUntilMs","affected","nativeUpdate","$or","lockedUntil","lockedBy","releaseRunLock","renewRunLock","listRuns","query","where","workflow","statuses","$and","$in","tag","quote","idQuote","cols","attributeColumns","qb","createQueryBuilder","tagsCol","tagsColumn","pattern","replace","colExpr","jsonAsText","andWhere","f","attributeExistsSql","offset","getResultList","alias","col","attributeColumnFor","numValue","strValue","cmp","sqlComparator","op","operand","attributeOperand","literal","String","a","table","sub","outerId","runPk","key","meta","getMetadata","get","field","prop","props","p","name","fieldNames","runMeta","properties","tableName","tags","colRef","platform","getPlatform","toLowerCase","includes","isMysql","ch","listCheckpoints","getLatestCheckpointByName","undefined","listCheckpointsByNamePrefix","prefixes","$like","putSignalWaiter","waiter","takeSignalWaiter","token","remove","listSignalWaiters","prefix","e","bufferSignal","payload","BufferedSignalEntity","persist","takeBufferedSignal","workflowVersion","input","output","error","recoveryAttempts","updatedAt","getTime","kind","stepId","events","attempts","workerGroup","enqueuedAt","startedAt","finishedAt"]}
1
+ {"version":3,"sources":["../src/entities.ts","../src/mikro-orm-state-store.ts","../src/schema.ts"],"sourcesContent":["import type { RunStatus, StepKind } from '@dudousxd/nestjs-durable-core';\nimport { EntitySchema } from '@mikro-orm/core';\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 TypeORM,\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\nfunction 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 `em.create`/`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;\n lockedUntil?: Date;\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;\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}\n\nexport class BufferedSignalEntity {\n id!: number;\n token!: string;\n payload?: unknown;\n}\n\n/**\n * Build the durable MikroORM entity schemas with column names pinned per `naming` (default\n * `'snake_case'`). Register the result in your MikroORM config / `MikroOrmModule.forFeature`.\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 class: WorkflowRunEntity,\n tableName: 'durable_workflow_runs',\n properties: {\n id: { type: 'string', primary: true, fieldName: col('id') },\n workflow: { type: 'string', fieldName: col('workflow') },\n workflowVersion: { type: 'string', fieldName: col('workflowVersion') },\n status: { type: 'string', fieldName: col('status') },\n input: { type: 'json', nullable: true, fieldName: col('input') },\n output: { type: 'json', nullable: true, fieldName: col('output') },\n error: { type: 'json', nullable: true, fieldName: col('error') },\n wakeAt: { type: 'Date', nullable: true, fieldName: col('wakeAt') },\n lockedBy: { type: 'string', nullable: true, fieldName: col('lockedBy') },\n lockedUntil: { type: 'Date', nullable: true, fieldName: col('lockedUntil') },\n recoveryAttempts: { type: 'integer', nullable: true, fieldName: col('recoveryAttempts') },\n tags: { type: 'json', nullable: true, fieldName: col('tags') },\n searchAttributes: { type: 'json', nullable: true, fieldName: col('searchAttributes') },\n priority: { type: 'integer', nullable: true, fieldName: col('priority') },\n createdAt: { type: 'Date', fieldName: col('createdAt') },\n updatedAt: { type: 'Date', fieldName: col('updatedAt') },\n },\n });\n\n const stepCheckpoints = new EntitySchema<StepCheckpointEntity>({\n class: StepCheckpointEntity,\n tableName: 'durable_step_checkpoints',\n properties: {\n runId: { type: 'string', primary: true, fieldName: col('runId') },\n seq: { type: 'integer', primary: true, fieldName: col('seq') },\n name: { type: 'string', fieldName: col('name') },\n kind: { type: 'string', fieldName: col('kind') },\n stepId: { type: 'string', fieldName: col('stepId') },\n status: { type: 'string', fieldName: col('status') },\n input: { type: 'json', nullable: true, fieldName: col('input') },\n output: { type: 'json', nullable: true, fieldName: col('output') },\n error: { type: 'json', nullable: true, fieldName: col('error') },\n events: { type: 'json', nullable: true, fieldName: col('events') },\n attempts: { type: 'integer', fieldName: col('attempts') },\n workerGroup: { type: 'string', nullable: true, fieldName: col('workerGroup') },\n wakeAt: { type: 'Date', nullable: true, fieldName: col('wakeAt') },\n enqueuedAt: { type: 'Date', nullable: true, fieldName: col('enqueuedAt') },\n startedAt: { type: 'Date', fieldName: col('startedAt') },\n finishedAt: { type: 'Date', fieldName: col('finishedAt') },\n },\n });\n\n const runAttributes = new EntitySchema<RunAttributeEntity>({\n class: RunAttributeEntity,\n tableName: 'durable_run_attributes',\n properties: {\n runId: { type: 'string', primary: true, fieldName: col('runId') },\n key: { type: 'string', primary: true, fieldName: col('key') },\n strValue: { type: 'string', nullable: true, fieldName: col('strValue') },\n // `float`/`double` is portable across SQLite/MySQL/Postgres for numeric range scans.\n numValue: { type: 'float', nullable: true, fieldName: col('numValue') },\n },\n });\n\n const signalWaiters = new EntitySchema<SignalWaiterEntity>({\n class: SignalWaiterEntity,\n tableName: 'durable_signal_waiters',\n properties: {\n token: { type: 'string', primary: true, fieldName: col('token') },\n runId: { type: 'string', fieldName: col('runId') },\n seq: { type: 'integer', fieldName: col('seq') },\n },\n });\n\n const bufferedSignals = new EntitySchema<BufferedSignalEntity>({\n class: BufferedSignalEntity,\n tableName: 'durable_buffered_signals',\n properties: {\n id: { type: 'integer', primary: true, autoincrement: true, fieldName: col('id') },\n token: { type: 'string', index: true, fieldName: col('token') },\n payload: { type: 'json', nullable: true, fieldName: col('payload') },\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 {\n type AttributeFilter,\n type RunQuery,\n type SignalWaiter,\n type StateStore,\n type StepCheckpoint,\n type StepError,\n type StepEvent,\n type WorkflowRun,\n attributeColumnFor,\n attributeOperand,\n normalizeAttributeRows,\n sqlComparator,\n} from '@dudousxd/nestjs-durable-core';\nimport type { EntityManager, MikroORM } from '@mikro-orm/core';\n\n/** Minimal structural surface of the SQL EntityManager's QueryBuilder (from `@mikro-orm/knex`),\n * typed here so the adapter needn't add a hard dependency on the knex types — a real SQL-driver EM\n * satisfies it at runtime. */\ninterface DurableQueryBuilder<T> {\n where(cond: Record<string, unknown>): DurableQueryBuilder<T>;\n andWhere(cond: string): DurableQueryBuilder<T>;\n orderBy(cond: Record<string, unknown>): DurableQueryBuilder<T>;\n limit(n: number): DurableQueryBuilder<T>;\n offset(n: number): DurableQueryBuilder<T>;\n getResultList(): Promise<T[]>;\n}\ntype SqlEm = EntityManager & {\n createQueryBuilder<T>(entity: unknown, alias: string): DurableQueryBuilder<T>;\n};\n\n/** Resolved side-table column names (per the active naming strategy) for the raw EXISTS pushdown. */\ninterface AttributeColumns {\n table: string;\n /** Side-table FK column (the run id on `durable_run_attributes`). */\n runId: string;\n /** Run table PK column (the `id` on `durable_workflow_runs`) used for the outer correlation. */\n runPk: string;\n key: string;\n strValue: string;\n numValue: string;\n}\nimport {\n BufferedSignalEntity,\n RunAttributeEntity,\n SignalWaiterEntity,\n StepCheckpointEntity,\n WorkflowRunEntity,\n} from './entities';\nimport { ensureMikroOrmDurableSchema } from './schema';\n\n/**\n * MikroORM-backed `StateStore`. Works on any MikroORM driver — Postgres, MySQL, SQLite (tested);\n * timestamps and `wakeAt` use native datetime columns. Each operation runs on a forked\n * EntityManager so it owns its unit of work.\n */\nexport class MikroOrmStateStore implements StateStore {\n constructor(private readonly orm: MikroORM) {}\n\n async ensureSchema(): Promise<void> {\n await ensureMikroOrmDurableSchema(this.orm);\n }\n\n async createRun(run: WorkflowRun): Promise<void> {\n const em = this.orm.em.fork();\n em.create(WorkflowRunEntity, toRunEntity(run));\n await em.flush();\n await this.reindexAttributes(run.id, run.searchAttributes);\n }\n\n async updateRun(runId: string, patch: Partial<WorkflowRun>): Promise<void> {\n const em = this.orm.em.fork();\n const entity = await em.findOneOrFail(WorkflowRunEntity, { id: runId });\n Object.assign(entity, toRunEntity({ ...fromRunEntity(entity), ...patch } as WorkflowRun));\n await em.flush();\n // Keep the side-table in step with the run's attributes whenever they're patched.\n if ('searchAttributes' in patch) await this.reindexAttributes(runId, patch.searchAttributes);\n }\n\n /** Rewrite a run's normalized attribute rows: delete the old set, insert the current one. Mirrors\n * the in-memory store's reindex so the side-table always reflects the run's live searchAttributes. */\n private async reindexAttributes(\n runId: string,\n attributes: WorkflowRun['searchAttributes'],\n forked?: EntityManager,\n ): Promise<void> {\n const em = forked ?? this.orm.em.fork();\n await em.nativeDelete(RunAttributeEntity, { runId });\n const rows = normalizeAttributeRows(runId, attributes);\n if (rows.length) await em.insertMany(RunAttributeEntity, rows);\n }\n\n async getRun(runId: string): Promise<WorkflowRun | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(WorkflowRunEntity, { id: runId });\n return entity ? fromRunEntity(entity) : null;\n }\n\n async deleteRun(runId: string): Promise<void> {\n const em = this.orm.em.fork();\n // Children first, then the run row — checkpoints, signal waiters, and the normalized\n // attribute side-table, so nothing dangles after the run is gone.\n await em.nativeDelete(StepCheckpointEntity, { runId });\n await em.nativeDelete(SignalWaiterEntity, { runId });\n await em.nativeDelete(RunAttributeEntity, { runId });\n await em.nativeDelete(WorkflowRunEntity, { id: runId });\n }\n\n async getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(StepCheckpointEntity, { runId, seq });\n return entity ? fromCheckpointEntity(entity) : null;\n }\n\n async saveCheckpoint(checkpoint: StepCheckpoint): Promise<void> {\n const em = this.orm.em.fork();\n await em.upsert(StepCheckpointEntity, toCheckpointEntity(checkpoint));\n await em.flush();\n }\n\n async transaction<T>(\n work: (tx: {\n raw: unknown;\n saveCheckpoint: (cp: StepCheckpoint) => Promise<void>;\n }) => Promise<T>,\n ): Promise<T> {\n return this.orm.em.fork().transactional(async (em) =>\n work({\n raw: em,\n saveCheckpoint: async (cp) => {\n await em.upsert(StepCheckpointEntity, toCheckpointEntity(cp));\n },\n }),\n );\n }\n\n async listIncompleteRuns(): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(WorkflowRunEntity, { status: 'running' });\n return rows.map(fromRunEntity);\n }\n\n async listPendingRuns(limit: number): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(\n WorkflowRunEntity,\n { status: 'pending' },\n { orderBy: { createdAt: 'asc' }, limit }, // FIFO dispatch\n );\n return rows.map(fromRunEntity);\n }\n\n async listDueTimers(nowMs: number): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(WorkflowRunEntity, {\n status: 'suspended',\n wakeAt: { $ne: null, $lte: new Date(nowMs) },\n });\n return rows.map(fromRunEntity);\n }\n\n async tryLockRun(\n runId: string,\n owner: string,\n leaseUntilMs: number,\n nowMs: number,\n ): Promise<boolean> {\n const em = this.orm.em.fork();\n const affected = await em.nativeUpdate(\n WorkflowRunEntity,\n { id: runId, $or: [{ lockedUntil: null }, { lockedUntil: { $lte: new Date(nowMs) } }] },\n { lockedBy: owner, lockedUntil: new Date(leaseUntilMs) },\n );\n return affected === 1;\n }\n\n async releaseRunLock(runId: string): Promise<void> {\n const em = this.orm.em.fork();\n await em.nativeUpdate(WorkflowRunEntity, { id: runId }, { lockedBy: null, lockedUntil: null });\n }\n\n async renewRunLock(runId: string, owner: string, leaseUntilMs: number): Promise<boolean> {\n const em = this.orm.em.fork();\n const affected = await em.nativeUpdate(\n WorkflowRunEntity,\n { id: runId, lockedBy: owner },\n { lockedUntil: new Date(leaseUntilMs) },\n );\n return affected === 1;\n }\n\n async listRuns(query: RunQuery): Promise<WorkflowRun[]> {\n const em = this.orm.em.fork();\n const where: Record<string, unknown> = {};\n if (query.workflow) where.workflow = query.workflow;\n // `status IN (...)`; an empty set matches nothing (mirrors the in-memory store). When both the\n // single `status` and `statuses` are set, AND them so the narrower set wins.\n if (query.status && query.statuses) {\n where.$and = [{ status: query.status }, { status: { $in: query.statuses } }];\n } else if (query.status) {\n where.status = query.status;\n } else if (query.statuses) {\n where.status = { $in: query.statuses };\n }\n const orderBy = { createdAt: 'desc' as const }; // newest first — recent runs on top in the dashboard\n // `tags`/attributes need raw SQL pushed through the QueryBuilder:\n // - tag: `tags` is a JSON column (native json/jsonb on PG/MySQL), and MikroORM JSON-serializes a\n // `{ $like }` operand (wrapping/escaping the LIKE pattern) so a plain where corrupts it to no\n // matches. A raw LIKE on the column-as-text matches the quoted token so `etl` doesn't match\n // `etl-foo`. Postgres `jsonb` rejects `LIKE` directly, so cast to text per dialect.\n // - attributes: each filter becomes a raw EXISTS against the normalized side-table, so the DB\n // filters AND paginates — no full scan + in-process filter (ANDed: one EXISTS per filter).\n // Use a QueryBuilder with a fixed root alias `r` so the raw correlations are stable across drivers.\n if (query.tag || query.attributes?.length) {\n const quote = this.idQuote(em);\n const cols = this.attributeColumns(em);\n const qb = (em as SqlEm)\n .createQueryBuilder<WorkflowRunEntity>(WorkflowRunEntity, 'r')\n .where(where)\n .orderBy(orderBy);\n if (query.tag) {\n const tagsCol = this.tagsColumn(em);\n const pattern = `%\"${query.tag.replace(/'/g, \"''\")}\"%`;\n const colExpr = this.jsonAsText(em, `${quote('r')}.${quote(tagsCol)}`);\n qb.andWhere(`${colExpr} LIKE '${pattern}'`);\n }\n for (const f of query.attributes ?? []) {\n qb.andWhere(this.attributeExistsSql(f, quote, 'r', cols));\n }\n if (query.limit != null) qb.limit(query.limit);\n if (query.offset != null) qb.offset(query.offset);\n const rows = await qb.getResultList();\n return rows.map(fromRunEntity);\n }\n const rows = await em.find(WorkflowRunEntity, where, {\n ...(query.limit != null ? { limit: query.limit } : {}),\n ...(query.offset != null ? { offset: query.offset } : {}),\n orderBy,\n });\n return rows.map(fromRunEntity);\n }\n\n /** One attribute predicate as a raw EXISTS subquery on the side-table, correlated to the outer run\n * alias. `<>` (ne) also excludes runs where the attribute is absent (missing-key-never-matches):\n * EXISTS already requires a present row, so EXISTS(... <> ...) is exactly ne-with-present. Numeric\n * operands compare the num column, everything else the str column. Identifiers are quoted per\n * driver and operands are inlined as literals (string operands are escaped by doubling quotes). */\n private attributeExistsSql(\n f: AttributeFilter,\n quote: (id: string) => string,\n alias: string,\n cols: AttributeColumns,\n ): string {\n const col = attributeColumnFor(f) === 'numValue' ? cols.numValue : cols.strValue;\n const cmp = sqlComparator(f.op);\n const operand = attributeOperand(f);\n const literal =\n typeof operand === 'number' ? String(operand) : `'${String(operand).replace(/'/g, \"''\")}'`;\n const a = quote(cols.table);\n const sub = quote('a');\n const outerId = `${quote(alias)}.${quote(cols.runPk)}`; // run PK column on the outer alias\n return `EXISTS (SELECT 1 FROM ${a} ${sub} WHERE ${sub}.${quote(cols.runId)} = ${outerId} AND ${sub}.${quote(cols.key)} = '${f.key.replace(/'/g, \"''\")}' AND ${sub}.${quote(col)} ${cmp} ${literal})`;\n }\n\n /** Resolve the side-table's actual column names from MikroORM metadata, so the raw EXISTS matches\n * the active naming strategy (underscore vs camelCase) rather than guessing. The run PK column is\n * reused for BOTH the outer correlation and the side-table FK (they share the same fieldName). */\n private attributeColumns(em: EntityManager): AttributeColumns {\n const meta = em.getMetadata().get(RunAttributeEntity);\n const field = (prop: string) =>\n meta.props.find((p) => p.name === prop)?.fieldNames?.[0] ?? prop;\n const runMeta = em.getMetadata().get(WorkflowRunEntity);\n const runPk = runMeta.properties.id?.fieldNames?.[0] ?? 'id';\n return {\n table: meta.tableName,\n runId: field('runId'),\n runPk,\n key: field('key'),\n strValue: field('strValue'),\n numValue: field('numValue'),\n };\n }\n\n /** Resolve the `tags` column name from metadata (per the active naming strategy), for the raw LIKE. */\n private tagsColumn(em: EntityManager): string {\n const runMeta = em.getMetadata().get(WorkflowRunEntity);\n return runMeta.properties.tags?.fieldNames?.[0] ?? 'tags';\n }\n\n /** Wrap a JSON column reference so it can be `LIKE`d as text. Postgres `jsonb`/`json` rejects `LIKE`\n * directly (`operator does not exist: jsonb ~~ unknown`) — cast to `text`; MySQL JSON needs an\n * explicit `CHAR` cast; SQLite stores JSON as text already, so no cast. */\n private jsonAsText(em: EntityManager, colRef: string): string {\n const platform = String(em.getPlatform().constructor.name).toLowerCase();\n if (platform.includes('postgre')) return `${colRef}::text`;\n if (platform.includes('mysql') || platform.includes('mariadb'))\n return `CAST(${colRef} AS CHAR)`;\n return colRef;\n }\n\n /** Quote an identifier per the active SQL driver (MySQL/MariaDB backtick, others double-quote). */\n private idQuote(em: EntityManager): (id: string) => string {\n const platform = String(em.getPlatform().constructor.name).toLowerCase();\n const isMysql = platform.includes('mysql') || platform.includes('mariadb');\n const ch = isMysql ? '`' : '\"';\n return (id: string) => `${ch}${id}${ch}`;\n }\n\n async listCheckpoints(runId: string): Promise<StepCheckpoint[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(StepCheckpointEntity, { runId }, { orderBy: { seq: 'asc' } });\n return rows.map(fromCheckpointEntity);\n }\n\n async getLatestCheckpointByName(\n runId: string,\n name: string,\n ): Promise<StepCheckpoint | undefined> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(\n StepCheckpointEntity,\n { runId, name },\n { orderBy: { seq: 'desc' } },\n );\n return entity ? fromCheckpointEntity(entity) : undefined;\n }\n\n async listCheckpointsByNamePrefix(runId: string, prefixes: string[]): Promise<StepCheckpoint[]> {\n if (prefixes.length === 0) return [];\n const em = this.orm.em.fork();\n const rows = await em.find(\n StepCheckpointEntity,\n { runId, $or: prefixes.map((p) => ({ name: { $like: `${p}%` } })) },\n { orderBy: { seq: 'asc' } },\n );\n return rows.map(fromCheckpointEntity);\n }\n\n async putSignalWaiter(waiter: SignalWaiter): Promise<void> {\n const em = this.orm.em.fork();\n await em.upsert(SignalWaiterEntity, { ...waiter });\n await em.flush();\n }\n\n async takeSignalWaiter(token: string): Promise<SignalWaiter | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(SignalWaiterEntity, { token });\n if (!entity) return null;\n const waiter: SignalWaiter = { token: entity.token, runId: entity.runId, seq: entity.seq };\n await em.remove(entity).flush();\n return waiter;\n }\n\n async listSignalWaiters(prefix: string): Promise<SignalWaiter[]> {\n const em = this.orm.em.fork();\n const rows = await em.find(SignalWaiterEntity, { token: { $like: `${prefix}%` } });\n return rows.map((e) => ({ token: e.token, runId: e.runId, seq: e.seq }));\n }\n\n async bufferSignal(token: string, payload: unknown): Promise<void> {\n const em = this.orm.em.fork();\n const e = new BufferedSignalEntity();\n e.token = token;\n e.payload = payload ?? null;\n em.persist(e);\n await em.flush();\n }\n\n async takeBufferedSignal(token: string): Promise<{ payload: unknown } | null> {\n const em = this.orm.em.fork();\n const entity = await em.findOne(BufferedSignalEntity, { token }, { orderBy: { id: 'asc' } });\n if (!entity) return null;\n const payload = entity.payload ?? undefined;\n await em.remove(entity).flush();\n return { payload };\n }\n}\n\nfunction toRunEntity(run: WorkflowRun): WorkflowRunEntity {\n const e = new WorkflowRunEntity();\n e.id = run.id;\n e.workflow = run.workflow;\n e.workflowVersion = run.workflowVersion;\n e.status = run.status;\n e.input = run.input ?? null;\n e.output = run.output ?? null;\n e.error = run.error ?? null;\n if (run.wakeAt != null) e.wakeAt = new Date(run.wakeAt);\n if (run.lockedBy !== undefined) e.lockedBy = run.lockedBy;\n if (run.lockedUntil != null) e.lockedUntil = new Date(run.lockedUntil);\n if (run.recoveryAttempts !== undefined) e.recoveryAttempts = run.recoveryAttempts;\n e.tags = run.tags ?? null;\n e.searchAttributes = run.searchAttributes ?? null;\n e.priority = run.priority ?? null;\n e.createdAt = run.createdAt;\n e.updatedAt = run.updatedAt;\n return e;\n}\n\nfunction fromRunEntity(e: WorkflowRunEntity): WorkflowRun {\n return {\n id: e.id,\n workflow: e.workflow,\n workflowVersion: e.workflowVersion,\n status: e.status,\n input: e.input ?? undefined,\n output: e.output ?? undefined,\n error: (e.error ?? undefined) as StepError | undefined,\n wakeAt: e.wakeAt?.getTime(),\n lockedBy: e.lockedBy ?? undefined,\n lockedUntil: e.lockedUntil?.getTime(),\n recoveryAttempts: e.recoveryAttempts ?? undefined,\n tags: e.tags ?? undefined,\n searchAttributes: e.searchAttributes ?? undefined,\n priority: e.priority ?? undefined,\n createdAt: e.createdAt,\n updatedAt: e.updatedAt,\n };\n}\n\nfunction toCheckpointEntity(cp: StepCheckpoint): StepCheckpointEntity {\n const e = new StepCheckpointEntity();\n e.runId = cp.runId;\n e.seq = cp.seq;\n e.name = cp.name;\n e.kind = cp.kind;\n e.stepId = cp.stepId;\n e.status = cp.status;\n e.input = cp.input ?? null;\n e.output = cp.output ?? null;\n e.error = cp.error ?? null;\n e.events = cp.events ?? null;\n e.attempts = cp.attempts;\n if (cp.workerGroup !== undefined) e.workerGroup = cp.workerGroup;\n if (cp.wakeAt != null) e.wakeAt = new Date(cp.wakeAt);\n e.enqueuedAt = cp.enqueuedAt;\n e.startedAt = cp.startedAt;\n e.finishedAt = cp.finishedAt;\n return e;\n}\n\nfunction fromCheckpointEntity(e: StepCheckpointEntity): StepCheckpoint {\n return {\n runId: e.runId,\n seq: e.seq,\n name: e.name,\n kind: e.kind,\n stepId: e.stepId,\n status: e.status,\n input: e.input ?? undefined,\n output: e.output ?? undefined,\n error: (e.error ?? undefined) as StepError | undefined,\n events: (e.events ?? undefined) as StepEvent[] | undefined,\n attempts: e.attempts,\n workerGroup: e.workerGroup ?? undefined,\n wakeAt: e.wakeAt?.getTime(),\n enqueuedAt: e.enqueuedAt ?? e.startedAt,\n startedAt: e.startedAt,\n finishedAt: e.finishedAt,\n };\n}\n","import type { MikroORM } from '@mikro-orm/core';\n\n/**\n * The tables this store owns. Kept in sync with the `tableName`s in `./entities`. Used to scope\n * schema management to our own tables (see {@link ensureMikroOrmDurableSchema}).\n */\nconst DURABLE_TABLE_NAMES = new Set([\n 'durable_workflow_runs',\n 'durable_step_checkpoints',\n 'durable_run_attributes',\n 'durable_signal_waiters',\n 'durable_buffered_signals',\n]);\n\n/** The table a `create table` / `alter table` statement targets, lower-cased; undefined otherwise. */\nfunction targetTable(statement: string): string | undefined {\n const match = statement.match(\n /^(?:create|alter)\\s+table\\s+(?:if\\s+not\\s+exists\\s+)?[`\"']?([\\w$]+)[`\"']?/i,\n );\n return match?.[1]?.toLowerCase();\n}\n\n/**\n * Whether a statement adds structure the store REQUIRES — a failure here is fatal (the store can't\n * run without the table/column/index). A column TYPE alignment (`modify`/`alter column ... type`)\n * is best-effort: the column already holds the data (the store serializes JSON to/from it regardless\n * of the declared type), so failing to converge its type — e.g. a legacy `longtext` value that won't\n * cast to `json` because it was truncated under an older `text` column — must NOT crash boot.\n */\nfunction isRequiredStructure(statement: string): boolean {\n return /\\b(?:create\\s+table|add\\s+(?:column|index|constraint|key|unique|fulltext))\\b/i.test(\n statement,\n );\n}\n\n/**\n * Idempotently create/extend ONLY the durable tables (additive — never drops). Safe to run on every\n * boot (auto-schema) and from a MikroORM migration when you disable auto-schema:\n *\n * ```ts\n * export class AddDurableTables extends Migration {\n * async up() { await ensureMikroOrmDurableSchema(this.getEntityManager().getOrm()); }\n * }\n * ```\n *\n * It does NOT run a whole-ORM `schema.update()`. When the store shares the host app's ORM (the\n * recommended setup — a single ORM avoids MikroORM's global-metadata clobber between instances),\n * a full `schema.update()` would try to reconcile EVERY app table to the entity metadata: on a\n * migration-managed schema that means recreating the migrations table and dropping app foreign keys.\n * Instead we compute the safe additive diff and execute only the statements that target our own\n * `durable_*` tables. `getUpdateSchemaSQL` already emits a `create table` only for a missing table\n * and `alter table ... add` only for missing columns, so existing tables — and the entire rest of\n * the host schema — are left untouched.\n */\nexport async function ensureMikroOrmDurableSchema(orm: MikroORM): Promise<void> {\n const sql = await orm.schema.getUpdateSchemaSQL({ safe: true });\n const ours = sql\n .split(';')\n .map((statement) => statement.trim())\n .filter((statement) => {\n const table = targetTable(statement);\n return table !== undefined && DURABLE_TABLE_NAMES.has(table);\n });\n const connection = orm.em.getConnection();\n for (const statement of ours) {\n try {\n await connection.execute(statement);\n } catch (err) {\n // Required structure (create table / add column / add index) must succeed — rethrow.\n if (isRequiredStructure(statement)) {\n throw err;\n }\n // A best-effort type alignment (e.g. legacy `longtext` → `json`) failed, typically because an\n // existing column holds a value that can't cast to the target type (a relic of an older column\n // type). The column already stores the data and the store reads/writes it via serialization, so\n // leave it as-is and continue rather than crashing boot. Surfaced so the data can be repaired\n // out of band (e.g. `UPDATE … SET col = NULL WHERE JSON_VALID(col) = 0` for a disposable column).\n const message = err instanceof Error ? err.message : String(err);\n console.warn(\n `[nestjs-durable-store-mikro-orm] skipped a non-structural durable-schema statement that failed; the column is left as-is (functional) — repair the data out of band to converge its type. Statement: ${statement} — ${message}`,\n );\n }\n }\n\n // Converge collation last, once the tables exist (whether just created above or pre-existing).\n await alignDurableCollation(orm);\n}\n\n/** A MySQL identifier we are willing to interpolate into DDL (charset / collation names). */\nfunction isSafeSqlIdentifier(value: string): boolean {\n return /^[A-Za-z0-9_]+$/.test(value);\n}\n\n/**\n * Align each durable table's collation to the ORM's configured `collate` (MySQL/MariaDB only).\n *\n * MikroORM's auto-schema (`getUpdateSchemaSQL`) creates tables with the server's DEFAULT collation —\n * on MySQL 8.4 that's `utf8mb4_0900_ai_ci` — and ignores the `collate` config option. When the host\n * app pins a different collation on its own tables (commonly `utf8mb4_unicode_ci` via migrations), a\n * JOIN between a durable table and an app table throws \"Illegal mix of collations\". We converge it\n * here: read the configured collation and `CONVERT` only the durable tables whose collation differs.\n *\n * Idempotent (matching tables are skipped), non-fatal (a CONVERT failure is warned, never crashes\n * boot), and a no-op when no `collate` is configured or the platform isn't MySQL/MariaDB.\n */\nasync function alignDurableCollation(orm: MikroORM): Promise<void> {\n const platform = String(orm.em.getPlatform().constructor.name).toLowerCase();\n if (!platform.includes('mysql') && !platform.includes('maria')) {\n return;\n }\n const collate = orm.config.get('collate');\n if (typeof collate !== 'string' || !isSafeSqlIdentifier(collate)) {\n return;\n }\n // utf8mb4_unicode_ci → utf8mb4. CONVERT TO needs the charset that owns the collation.\n const charset = collate.split('_')[0];\n if (!charset || !isSafeSqlIdentifier(charset)) {\n return;\n }\n const connection = orm.em.getConnection();\n for (const table of DURABLE_TABLE_NAMES) {\n try {\n const rows = (await connection.execute(\n 'select table_collation as collation from information_schema.tables where table_schema = database() and table_name = ? limit 1',\n [table],\n )) as Array<{ collation?: string | null }>;\n const current = rows[0]?.collation;\n // Table absent (nothing to align) or already at the target collation — skip.\n if (current == null || current === collate) {\n continue;\n }\n await connection.execute(\n `alter table \\`${table}\\` convert to character set ${charset} collate ${collate}`,\n );\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n console.warn(\n `[nestjs-durable-store-mikro-orm] could not align collation for \\`${table}\\` to ${collate} (left as-is): ${message}`,\n );\n }\n }\n}\n"],"mappings":";;;;AACA,SAASA,oBAAoB;AAgB7B,SAASC,UAAUC,UAAgB;AACjC,SAAOA,SAASC,QAAQ,UAAU,CAACC,MAAM,IAAIA,EAAEC,YAAW,CAAA,EAAI;AAChE;AAFSJ;AAIT,SAASK,YAAYC,QAA2B;AAC9C,MAAIA,WAAW,aAAc,QAAON;AACpC,MAAIM,WAAW,WAAY,QAAO,CAACL,aAAaA;AAChD,SAAOK;AACT;AAJSD;AAUF,IAAME,oBAAN,MAAMA;EA9Bb,OA8BaA;;;EACXC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;AACF;AAEO,IAAMC,uBAAN,MAAMA;EAjDb,OAiDaA;;;EACXC;EACAC;EACAC;EACAC;EACAC;EACAlB;EACAC;EACAC;EACAC;EACAgB;EACAC;EACAC;EACAjB;EACAkB;EACAC;EACAC;AACF;AAQO,IAAMC,qBAAN,MAAMA;EA1Eb,OA0EaA;;;EACXX;EACAY;EACAC;EACAC;AACF;AAEO,IAAMC,qBAAN,MAAMA;EAjFb,OAiFaA;;;EACXC;EACAhB;EACAC;AACF;AAEO,IAAMgB,uBAAN,MAAMA;EAvFb,OAuFaA;;;EACXlC;EACAiC;EACAE;AACF;AAUO,SAASC,gBAAgBC,UAA4C,CAAC,GAAC;AAC5E,QAAMC,MAAMzC,YAAYwC,QAAQvC,UAAU,YAAA;AAE1C,QAAMyC,eAAe,IAAIC,aAAgC;IACvDC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GAAGW,MAAM;AACpD0F,IAAEmB,aAAaxH,GAAGwH;AAClBnB,IAAEoB,YAAYzH,GAAGyH;AACjBpB,IAAEqB,aAAa1H,GAAG0H;AAClB,SAAOrB;AACT;AAnBS1G;AAqBT,SAASJ,qBAAqB8G,GAAuB;AACnD,SAAO;IACLpI,OAAOoI,EAAEpI;IACTqB,KAAK+G,EAAE/G;IACPqF,MAAM0B,EAAE1B;IACRwC,MAAMd,EAAEc;IACRC,QAAQf,EAAEe;IACVjH,QAAQkG,EAAElG;IACVyG,OAAOP,EAAEO,SAASlB;IAClBmB,QAAQR,EAAEQ,UAAUnB;IACpBoB,OAAQT,EAAES,SAASpB;IACnB2B,QAAShB,EAAEgB,UAAU3B;IACrB4B,UAAUjB,EAAEiB;IACZC,aAAalB,EAAEkB,eAAe7B;IAC9B/E,QAAQ0F,EAAE1F,QAAQuG,QAAAA;IAClBM,YAAYnB,EAAEmB,cAAcnB,EAAEoB;IAC9BA,WAAWpB,EAAEoB;IACbC,YAAYrB,EAAEqB;EAChB;AACF;AAnBSnI;","names":["EntitySchema","snakeCase","property","replace","c","toLowerCase","columnNamer","naming","WorkflowRunEntity","id","workflow","workflowVersion","status","input","output","error","wakeAt","lockedBy","lockedUntil","recoveryAttempts","tags","searchAttributes","priority","createdAt","updatedAt","StepCheckpointEntity","runId","seq","name","kind","stepId","events","attempts","workerGroup","enqueuedAt","startedAt","finishedAt","RunAttributeEntity","key","strValue","numValue","SignalWaiterEntity","token","BufferedSignalEntity","payload","durableEntities","options","col","workflowRuns","EntitySchema","class","tableName","properties","type","primary","fieldName","nullable","stepCheckpoints","runAttributes","signalWaiters","bufferedSignals","autoincrement","index","ENTITIES","attributeColumnFor","attributeOperand","normalizeAttributeRows","sqlComparator","DURABLE_TABLE_NAMES","Set","targetTable","statement","match","toLowerCase","isRequiredStructure","test","ensureMikroOrmDurableSchema","orm","sql","schema","getUpdateSchemaSQL","safe","ours","split","map","trim","filter","table","undefined","has","connection","em","getConnection","execute","err","message","Error","String","console","warn","alignDurableCollation","isSafeSqlIdentifier","value","platform","getPlatform","name","includes","collate","config","get","charset","rows","current","collation","MikroOrmStateStore","orm","ensureSchema","ensureMikroOrmDurableSchema","createRun","run","em","fork","create","WorkflowRunEntity","toRunEntity","flush","reindexAttributes","id","searchAttributes","updateRun","runId","patch","entity","findOneOrFail","Object","assign","fromRunEntity","attributes","forked","nativeDelete","RunAttributeEntity","rows","normalizeAttributeRows","length","insertMany","getRun","findOne","deleteRun","StepCheckpointEntity","SignalWaiterEntity","getCheckpoint","seq","fromCheckpointEntity","saveCheckpoint","checkpoint","upsert","toCheckpointEntity","transaction","work","transactional","raw","cp","listIncompleteRuns","find","status","map","listPendingRuns","limit","orderBy","createdAt","listDueTimers","nowMs","wakeAt","$ne","$lte","Date","tryLockRun","owner","leaseUntilMs","affected","nativeUpdate","$or","lockedUntil","lockedBy","releaseRunLock","renewRunLock","listRuns","query","where","workflow","statuses","$and","$in","tag","quote","idQuote","cols","attributeColumns","qb","createQueryBuilder","tagsCol","tagsColumn","pattern","replace","colExpr","jsonAsText","andWhere","f","attributeExistsSql","offset","getResultList","alias","col","attributeColumnFor","numValue","strValue","cmp","sqlComparator","op","operand","attributeOperand","literal","String","a","table","sub","outerId","runPk","key","meta","getMetadata","get","field","prop","props","p","name","fieldNames","runMeta","properties","tableName","tags","colRef","platform","getPlatform","toLowerCase","includes","isMysql","ch","listCheckpoints","getLatestCheckpointByName","undefined","listCheckpointsByNamePrefix","prefixes","$like","putSignalWaiter","waiter","takeSignalWaiter","token","remove","listSignalWaiters","prefix","e","bufferSignal","payload","BufferedSignalEntity","persist","takeBufferedSignal","workflowVersion","input","output","error","recoveryAttempts","priority","updatedAt","getTime","kind","stepId","events","attempts","workerGroup","enqueuedAt","startedAt","finishedAt"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dudousxd/nestjs-durable-store-mikro-orm",
3
- "version": "0.12.0",
3
+ "version": "0.13.2",
4
4
  "description": "MikroORM adapter for the nestjs-durable StateStore (reference ORM adapter)",
5
5
  "license": "MIT",
6
6
  "author": "Davide Carvalho",
@@ -31,8 +31,8 @@
31
31
  "reflect-metadata": "0.2.2",
32
32
  "tsup": "8.3.5",
33
33
  "typescript": "5.9.3",
34
- "@dudousxd/nestjs-durable-core": "^0.30.0",
35
- "@dudousxd/nestjs-durable-testing": "^0.6.0"
34
+ "@dudousxd/nestjs-durable-core": "^0.32.1",
35
+ "@dudousxd/nestjs-durable-testing": "^0.7.0"
36
36
  },
37
37
  "module": "./dist/index.js",
38
38
  "exports": {