@dudousxd/nestjs-durable-store-prisma 0.28.0 → 0.29.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -22,7 +22,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
22
22
  var index_exports = {};
23
23
  __export(index_exports, {
24
24
  PrismaStateStore: () => PrismaStateStore,
25
- durableManagedTables: () => durableManagedTables
25
+ durableManagedTables: () => durableManagedTables,
26
+ durableSchemaName: () => durableSchemaName
26
27
  });
27
28
  module.exports = __toCommonJS(index_exports);
28
29
 
@@ -31,6 +32,21 @@ var import_nestjs_durable_core = require("@dudousxd/nestjs-durable-core");
31
32
  var RETENTION_EXCLUDED = [
32
33
  import_nestjs_durable_core.LIFECYCLE_REGISTRY_WORKFLOW
33
34
  ];
35
+ var SCHEMA_NAME = /^[A-Za-z_][A-Za-z0-9_$]*$/;
36
+ function durableSchemaName(schema) {
37
+ if (schema === void 0) return void 0;
38
+ if (!SCHEMA_NAME.test(schema) || schema.length > 63) {
39
+ throw new Error(`[nestjs-durable] invalid schema ${JSON.stringify(schema)}: use letters, digits, _ or $ (not first), at most 63 characters.`);
40
+ }
41
+ return schema;
42
+ }
43
+ __name(durableSchemaName, "durableSchemaName");
44
+ function rawTable(unqualified, schema, dialect) {
45
+ if (schema === void 0) return unqualified;
46
+ const name = unqualified.replace(/^["`]|["`]$/g, "");
47
+ return dialect === "postgres" ? `"${schema}"."${name}"` : `\`${schema}\`.\`${name}\``;
48
+ }
49
+ __name(rawTable, "rawTable");
34
50
  function namespaceWhere(namespace) {
35
51
  if (namespace === void 0) return {};
36
52
  return {
@@ -51,13 +67,21 @@ var PrismaStateStore = class {
51
67
  claimPendingRuns;
52
68
  /** Raw single-statement writes on Postgres/MySQL (Prisma wraps `updateMany` in a transaction). */
53
69
  fast;
54
- constructor(db) {
70
+ schema;
71
+ constructor(db, options = {}) {
55
72
  this.db = db;
56
73
  const provider = db._activeProvider;
74
+ this.schema = durableSchemaName(options.schema);
75
+ if (this.schema !== void 0 && provider === "sqlite") {
76
+ throw new Error(`[nestjs-durable] store-prisma: the schema option (${JSON.stringify(this.schema)}) is not supported on SQLite, which has no schemas. Remove it.`);
77
+ }
78
+ if (this.schema !== void 0 && provider === "mysql") {
79
+ throw new Error(`[nestjs-durable] store-prisma: the schema option (${JSON.stringify(this.schema)}) is not supported on MySQL, where Prisma has no multi-schema support (\`@@schema\`). Point the client's connection at that database instead, or use the MikroORM or TypeORM store.`);
80
+ }
57
81
  const raw = typeof db.$queryRawUnsafe === "function";
58
82
  const dialect = raw && provider === "postgresql" ? "postgres" : raw && provider === "mysql" ? "mysql" : void 0;
59
83
  if (!dialect) return;
60
- const fast = new PrismaRoundTrips(db, dialect, this);
84
+ const fast = new PrismaRoundTrips(db, dialect, this, this.schema);
61
85
  this.fast = fast;
62
86
  this.insertCheckpointIfAbsent = (cp) => fast.insertCheckpointIfAbsent(cp);
63
87
  this.settleResultsIfPending = (results) => fast.settleResultsIfPending(results);
@@ -73,7 +97,7 @@ var PrismaStateStore = class {
73
97
  in: import_nestjs_durable_core.SINGLETON_ACTIVE_STATUSES
74
98
  }
75
99
  };
76
- const lockRows = rowLockDialect(this.db);
100
+ const lockRows = rowLockDialect(this.db, this.schema);
77
101
  const claimants = lockRows ? (0, import_nestjs_durable_core.singletonClaimantIds)(
78
102
  // The primary, under the read-replicas extension: a lagging replica would leave rows out.
79
103
  await primaryOf(this.db).durableWorkflowRun.findMany({
@@ -475,7 +499,9 @@ var PrismaStateStore = class {
475
499
  error: jsonOrNull(s.error),
476
500
  events: jsonOrNull(s.events),
477
501
  startedAt: s.startedAt,
478
- finishedAt: s.finishedAt
502
+ finishedAt: s.finishedAt,
503
+ // A settled step has no dispatch lease left.
504
+ wakeAt: null
479
505
  }
480
506
  });
481
507
  wrote[i] = count > 0;
@@ -489,7 +515,7 @@ var PrismaStateStore = class {
489
515
  const raw = tx;
490
516
  for (let at = 0; at < firsts.length; at += 500) {
491
517
  const chunk = firsts.slice(at, at + 500);
492
- const won = await dialect(raw, chunk.map((i) => settlements[i]));
518
+ const won = await dialect(raw, chunk.map((i) => settlements[i]), this.schema);
493
519
  for (const i of chunk) {
494
520
  const s = settlements[i];
495
521
  wrote[i] = won.has(checkpointKey(s.runId, s.seq));
@@ -1743,14 +1769,14 @@ function primaryOf(db) {
1743
1769
  return typeof client.$primary === "function" ? client.$primary() : db;
1744
1770
  }
1745
1771
  __name(primaryOf, "primaryOf");
1746
- function rowLockDialect(db) {
1772
+ function rowLockDialect(db, schema) {
1747
1773
  const client = db;
1748
1774
  if (typeof client.$queryRawUnsafe !== "function") return void 0;
1749
1775
  if (client._activeProvider === "postgresql") {
1750
- return (tx, ids) => tx.$queryRawUnsafe(`SELECT id FROM "durable_workflow_runs" WHERE id IN (${ids.map((_, i) => `$${i + 1}`).join(", ")}) ORDER BY id FOR UPDATE`, ...ids);
1776
+ return (tx, ids) => tx.$queryRawUnsafe(`SELECT id FROM ${rawTable('"durable_workflow_runs"', schema, "postgres")} WHERE id IN (${ids.map((_, i) => `$${i + 1}`).join(", ")}) ORDER BY id FOR UPDATE`, ...ids);
1751
1777
  }
1752
1778
  if (client._activeProvider === "mysql") {
1753
- return (tx, ids) => tx.$queryRawUnsafe(`SELECT id FROM durable_workflow_runs WHERE id IN (${ids.map(() => "?").join(", ")}) ORDER BY id FOR UPDATE`, ...ids);
1779
+ return (tx, ids) => tx.$queryRawUnsafe(`SELECT id FROM ${rawTable("durable_workflow_runs", schema, "mysql")} WHERE id IN (${ids.map(() => "?").join(", ")}) ORDER BY id FOR UPDATE`, ...ids);
1754
1780
  }
1755
1781
  return void 0;
1756
1782
  }
@@ -1764,7 +1790,7 @@ function rawSettleDialect(db) {
1764
1790
  return void 0;
1765
1791
  }
1766
1792
  __name(rawSettleDialect, "rawSettleDialect");
1767
- var settleRowsPostgres = /* @__PURE__ */ __name(async (db, settlements) => {
1793
+ var settleRowsPostgres = /* @__PURE__ */ __name(async (db, settlements, schema) => {
1768
1794
  const values = [];
1769
1795
  const rows = settlements.map((s) => {
1770
1796
  const n = values.length;
@@ -1772,18 +1798,19 @@ var settleRowsPostgres = /* @__PURE__ */ __name(async (db, settlements) => {
1772
1798
  const p = /* @__PURE__ */ __name((k) => `$${n + k}`, "p");
1773
1799
  return `(${p(1)}::text, ${p(2)}::integer, ${p(3)}::text, ${p(4)}::jsonb, ${p(5)}::jsonb, ${p(6)}::jsonb, (${p(7)}::timestamptz AT TIME ZONE 'UTC'), (${p(8)}::timestamptz AT TIME ZONE 'UTC'))`;
1774
1800
  });
1775
- const written = await db.$queryRawUnsafe(`UPDATE "durable_step_checkpoints" AS c SET status = v.status, output = v.output,
1776
- error = v.error, events = v.events, started_at = v.started_at, finished_at = v.finished_at
1801
+ const written = await db.$queryRawUnsafe(`UPDATE ${rawTable('"durable_step_checkpoints"', schema, "postgres")} AS c SET status = v.status, output = v.output,
1802
+ error = v.error, events = v.events, started_at = v.started_at, finished_at = v.finished_at,
1803
+ wake_at = NULL
1777
1804
  FROM (VALUES ${rows.join(", ")}) AS v(run_id, seq, status, output, error, events, started_at,
1778
1805
  finished_at)
1779
1806
  WHERE c.run_id = v.run_id AND c.seq = v.seq AND c.status = 'pending'
1780
1807
  RETURNING c.run_id, c.seq`, ...values);
1781
1808
  return new Set(written.map((row) => checkpointKey(row.run_id, Number(row.seq))));
1782
1809
  }, "settleRowsPostgres");
1783
- var settleRowsMysql = /* @__PURE__ */ __name(async (db, settlements) => {
1810
+ var settleRowsMysql = /* @__PURE__ */ __name(async (db, settlements, schema) => {
1784
1811
  const pending = /* @__PURE__ */ new Set();
1785
1812
  for (const [runId, seqs] of seqsByRun(settlements)) {
1786
- const rows2 = await db.$queryRawUnsafe(`SELECT run_id, seq FROM durable_step_checkpoints WHERE run_id = ? AND seq IN (${seqs.map(() => "?").join(", ")}) AND status = 'pending' FOR UPDATE`, runId, ...seqs);
1813
+ const rows2 = await db.$queryRawUnsafe(`SELECT run_id, seq FROM ${rawTable("durable_step_checkpoints", schema, "mysql")} WHERE run_id = ? AND seq IN (${seqs.map(() => "?").join(", ")}) AND status = 'pending' FOR UPDATE`, runId, ...seqs);
1787
1814
  for (const row of rows2) pending.add(checkpointKey(row.run_id, Number(row.seq)));
1788
1815
  }
1789
1816
  const won = settlements.filter((s) => pending.has(checkpointKey(s.runId, s.seq)));
@@ -1794,10 +1821,11 @@ var settleRowsMysql = /* @__PURE__ */ __name(async (db, settlements) => {
1794
1821
  values.push(s.runId, s.seq, s.status, jsonText(s.output), jsonText(s.error), jsonText(s.events), at(s.startedAt), at(s.finishedAt));
1795
1822
  return i === 0 ? "SELECT ? AS run_id, ? AS seq, ? AS status, ? AS output, ? AS error, ? AS events, ? AS started_at, ? AS finished_at" : "SELECT ?, ?, ?, ?, ?, ?, ?, ?";
1796
1823
  });
1797
- const updated = await db.$executeRawUnsafe(`UPDATE durable_step_checkpoints AS c JOIN (${rows.join(" UNION ALL ")}) AS v
1824
+ const updated = await db.$executeRawUnsafe(`UPDATE ${rawTable("durable_step_checkpoints", schema, "mysql")} AS c JOIN (${rows.join(" UNION ALL ")}) AS v
1798
1825
  ON c.run_id = v.run_id AND c.seq = v.seq
1799
1826
  SET c.status = v.status, c.output = CAST(v.output AS JSON), c.error = CAST(v.error AS JSON),
1800
- c.events = CAST(v.events AS JSON), c.started_at = v.started_at, c.finished_at = v.finished_at
1827
+ c.events = CAST(v.events AS JSON), c.started_at = v.started_at, c.finished_at = v.finished_at,
1828
+ c.wake_at = NULL
1801
1829
  WHERE c.status = 'pending'`, ...values);
1802
1830
  if (updated !== won.length) {
1803
1831
  throw new Error("a checkpoint of the batch was settled while the batch was written");
@@ -1812,7 +1840,7 @@ var settleRowsSqlite = /* @__PURE__ */ __name(async (db, settlements) => {
1812
1840
  });
1813
1841
  const written = await db.$queryRawUnsafe(`WITH v(run_id, seq, status, output, error, events, started_at, finished_at) AS (VALUES ${rows.join(", ")})
1814
1842
  UPDATE durable_step_checkpoints SET status = v.status, output = v.output, error = v.error,
1815
- events = v.events, started_at = v.started_at, finished_at = v.finished_at
1843
+ events = v.events, started_at = v.started_at, finished_at = v.finished_at, wake_at = NULL
1816
1844
  FROM v
1817
1845
  WHERE durable_step_checkpoints.run_id = v.run_id AND durable_step_checkpoints.seq = v.seq
1818
1846
  AND durable_step_checkpoints.status = 'pending'
@@ -1919,17 +1947,23 @@ var PrismaRoundTrips = class PrismaRoundTrips2 {
1919
1947
  }
1920
1948
  db;
1921
1949
  store;
1950
+ schema;
1922
1951
  pg;
1923
- constructor(db, dialect, store) {
1952
+ constructor(db, dialect, store, schema) {
1924
1953
  this.db = db;
1925
1954
  this.store = store;
1955
+ this.schema = schema;
1926
1956
  this.pg = dialect === "postgres";
1927
1957
  }
1958
+ /** A durable table as this statement wrote it unqualified, with the schema when one is set. */
1959
+ t(unqualified) {
1960
+ return rawTable(unqualified, this.schema, this.pg ? "postgres" : "mysql");
1961
+ }
1928
1962
  get raw() {
1929
1963
  return this.db;
1930
1964
  }
1931
1965
  async tryLockRunAndGet(runId, owner, leaseUntilMs, nowMs) {
1932
- const rows = await this.raw.$queryRawUnsafe(`UPDATE "durable_workflow_runs" SET locked_by = $1, locked_until = ($2::timestamptz AT TIME ZONE 'UTC') WHERE id = $3 AND (locked_until IS NULL OR locked_until <= ($4::timestamptz AT TIME ZONE 'UTC')) RETURNING *`, owner, new Date(leaseUntilMs).toISOString(), runId, new Date(nowMs).toISOString());
1966
+ const rows = await this.raw.$queryRawUnsafe(`UPDATE ${this.t('"durable_workflow_runs"')} SET locked_by = $1, locked_until = ($2::timestamptz AT TIME ZONE 'UTC') WHERE id = $3 AND (locked_until IS NULL OR locked_until <= ($4::timestamptz AT TIME ZONE 'UTC')) RETURNING *`, owner, new Date(leaseUntilMs).toISOString(), runId, new Date(nowMs).toISOString());
1933
1967
  const [row] = rows;
1934
1968
  return row ? fromRunRow(fromRawRow(row)) : null;
1935
1969
  }
@@ -2049,7 +2083,7 @@ var PrismaRoundTrips = class PrismaRoundTrips2 {
2049
2083
  const names = columns.map(([name]) => this.q(name)).join(", ");
2050
2084
  const marks = columns.map(([, kind], i) => this.param(kind, i + 1)).join(", ");
2051
2085
  const values = columns.map(([, kind, v]) => this.value(kind, v));
2052
- const insert = `INSERT INTO ${this.q("durable_step_checkpoints")} (${names}) VALUES (${marks})`;
2086
+ const insert = `INSERT INTO ${this.t(this.q("durable_step_checkpoints"))} (${names}) VALUES (${marks})`;
2053
2087
  if (this.pg) {
2054
2088
  const rows = await this.raw.$queryRawUnsafe(`${insert} ON CONFLICT (run_id, seq) DO NOTHING RETURNING seq`, ...values);
2055
2089
  return rows.length === 1;
@@ -2157,12 +2191,12 @@ var PrismaRoundTrips = class PrismaRoundTrips2 {
2157
2191
  values.push(status);
2158
2192
  return this.param("text", values.length);
2159
2193
  });
2160
- return this.raw.$executeRawUnsafe(`UPDATE ${this.q("durable_workflow_runs")} SET ${set.join(", ")} WHERE id = ${id} AND status IN (${statuses.join(", ")})`, ...values);
2194
+ return this.raw.$executeRawUnsafe(`UPDATE ${this.t(this.q("durable_workflow_runs"))} SET ${set.join(", ")} WHERE id = ${id} AND status IN (${statuses.join(", ")})`, ...values);
2161
2195
  }
2162
2196
  /** `releaseRunLock` as one raw UPDATE (no transaction around it). */
2163
2197
  async releaseRunLock(runId, owner) {
2164
2198
  const where = owner === void 0 ? "" : ` AND locked_by = ${this.param("text", 2)}`;
2165
- await this.raw.$executeRawUnsafe(`UPDATE ${this.q("durable_workflow_runs")} SET locked_by = NULL, locked_until = NULL WHERE id = ${this.param("text", 1)}${where}`, runId, ...owner === void 0 ? [] : [
2199
+ await this.raw.$executeRawUnsafe(`UPDATE ${this.t(this.q("durable_workflow_runs"))} SET locked_by = NULL, locked_until = NULL WHERE id = ${this.param("text", 1)}${where}`, runId, ...owner === void 0 ? [] : [
2166
2200
  owner
2167
2201
  ]);
2168
2202
  }
@@ -2178,18 +2212,18 @@ var PrismaRoundTrips = class PrismaRoundTrips2 {
2178
2212
  ];
2179
2213
  });
2180
2214
  if (sent.length === 0) return out;
2181
- const finished = `NOT EXISTS (SELECT 1 FROM durable_workflow_runs r WHERE r.id = c.run_id AND r.status IN ('cancelled', 'completed'))`;
2215
+ const finished = `NOT EXISTS (SELECT 1 FROM ${this.t("durable_workflow_runs")} r WHERE r.id = c.run_id AND r.status IN ('cancelled', 'completed'))`;
2182
2216
  if (!this.pg) {
2183
2217
  if (sent.length > 1) return (0, import_nestjs_durable_core.settleResultsWithPlainCalls)(this.store, results);
2184
2218
  const i = sent[0];
2185
2219
  const s = results[i];
2186
2220
  const done = s.status === "completed";
2187
2221
  const at = /* @__PURE__ */ __name((d) => d.toISOString().replace("T", " ").replace("Z", ""), "at");
2188
- const wrote = await this.raw.$executeRawUnsafe(`UPDATE durable_step_checkpoints c SET c.status = ?, c.output = ${done ? "CAST(? AS JSON)" : "c.output"}, c.error = CAST(? AS JSON), c.events = COALESCE(CAST(? AS JSON), c.events), c.started_at = COALESCE(?, c.started_at), c.finished_at = ? WHERE c.run_id = ? AND c.seq = ? AND c.status = 'pending' AND ${finished}`, s.status, ...done ? [
2222
+ const wrote = await this.raw.$executeRawUnsafe(`UPDATE ${this.t("durable_step_checkpoints")} c SET c.status = ?, c.output = ${done ? "CAST(? AS JSON)" : "c.output"}, c.error = CAST(? AS JSON), c.events = COALESCE(CAST(? AS JSON), c.events), c.started_at = COALESCE(?, c.started_at), c.finished_at = ?, c.wake_at = NULL WHERE c.run_id = ? AND c.seq = ? AND c.status = 'pending' AND ${finished}`, s.status, ...done ? [
2189
2223
  jsonText(s.output)
2190
2224
  ] : [], jsonText(s.error), jsonText(s.events), s.startedAt ? at(s.startedAt) : null, at(s.finishedAt), s.runId, s.seq);
2191
2225
  if (wrote !== 1) return out;
2192
- const [row] = await this.raw.$queryRawUnsafe(`SELECT ${SETTLED_CHECKPOINT_COLUMNS} FROM durable_step_checkpoints WHERE run_id = ? AND seq = ?`, s.runId, s.seq);
2226
+ const [row] = await this.raw.$queryRawUnsafe(`SELECT ${SETTLED_CHECKPOINT_COLUMNS} FROM ${this.t("durable_step_checkpoints")} WHERE run_id = ? AND seq = ?`, s.runId, s.seq);
2193
2227
  out[i] = row ? fromCheckpointRow(fromRawRow({
2194
2228
  ...row,
2195
2229
  input: null
@@ -2206,7 +2240,7 @@ var PrismaRoundTrips = class PrismaRoundTrips2 {
2206
2240
  const p = /* @__PURE__ */ __name((k) => `$${n + k}`, "p");
2207
2241
  return `(${p(1)}::text, ${p(2)}::integer, ${p(3)}::text, ${p(4)}::jsonb, ${p(5)}::jsonb, ${p(6)}::jsonb, (${p(7)}::timestamptz AT TIME ZONE 'UTC'), (${p(8)}::timestamptz AT TIME ZONE 'UTC'))`;
2208
2242
  });
2209
- const settled = await this.raw.$queryRawUnsafe(`UPDATE "durable_step_checkpoints" AS c SET status = v.status, output = CASE WHEN v.status = 'completed' THEN v.output ELSE c.output END, error = v.error, events = COALESCE(v.events, c.events), started_at = COALESCE(v.started_at, c.started_at), finished_at = v.finished_at FROM (VALUES ${rows.join(", ")}) AS v(run_id, seq, status, output, error, events, started_at, finished_at) WHERE c.run_id = v.run_id AND c.seq = v.seq AND c.status = 'pending' AND ${finished} RETURNING ${SETTLED_CHECKPOINT_COLUMNS.split(", ").map((col) => `c.${col}`).join(", ")}`, ...values);
2243
+ const settled = await this.raw.$queryRawUnsafe(`UPDATE ${this.t('"durable_step_checkpoints"')} AS c SET status = v.status, output = CASE WHEN v.status = 'completed' THEN v.output ELSE c.output END, error = v.error, events = COALESCE(v.events, c.events), started_at = COALESCE(v.started_at, c.started_at), finished_at = v.finished_at, wake_at = NULL FROM (VALUES ${rows.join(", ")}) AS v(run_id, seq, status, output, error, events, started_at, finished_at) WHERE c.run_id = v.run_id AND c.seq = v.seq AND c.status = 'pending' AND ${finished} RETURNING ${SETTLED_CHECKPOINT_COLUMNS.split(", ").map((col) => `c.${col}`).join(", ")}`, ...values);
2210
2244
  const byKey = new Map(chunk.map((i) => {
2211
2245
  const s = results[i];
2212
2246
  return [
@@ -2230,7 +2264,7 @@ var PrismaRoundTrips = class PrismaRoundTrips2 {
2230
2264
  const sort = /* @__PURE__ */ __name((runs) => runs.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime() || a.id.localeCompare(b.id)), "sort");
2231
2265
  if (this.pg) {
2232
2266
  const ns = namespace !== void 0 ? " AND namespace = $5" : "";
2233
- const rows = await this.raw.$queryRawUnsafe(`WITH claimed AS MATERIALIZED (SELECT id AS claimed_id FROM "durable_workflow_runs" WHERE status = 'pending' AND (locked_until IS NULL OR locked_until <= ($3::timestamptz AT TIME ZONE 'UTC'))${ns} ORDER BY created_at, id LIMIT $4 FOR UPDATE SKIP LOCKED) UPDATE "durable_workflow_runs" AS r SET locked_by = $1, locked_until = ($2::timestamptz AT TIME ZONE 'UTC') FROM claimed WHERE r.id = claimed.claimed_id RETURNING r.*`, owner, new Date(leaseUntilMs).toISOString(), new Date(nowMs).toISOString(), limit, ...namespace !== void 0 ? [
2267
+ const rows = await this.raw.$queryRawUnsafe(`WITH claimed AS MATERIALIZED (SELECT id AS claimed_id FROM ${this.t('"durable_workflow_runs"')} WHERE status = 'pending' AND (locked_until IS NULL OR locked_until <= ($3::timestamptz AT TIME ZONE 'UTC'))${ns} ORDER BY created_at, id LIMIT $4 FOR UPDATE SKIP LOCKED) UPDATE ${this.t('"durable_workflow_runs"')} AS r SET locked_by = $1, locked_until = ($2::timestamptz AT TIME ZONE 'UTC') FROM claimed WHERE r.id = claimed.claimed_id RETURNING r.*`, owner, new Date(leaseUntilMs).toISOString(), new Date(nowMs).toISOString(), limit, ...namespace !== void 0 ? [
2234
2268
  namespace
2235
2269
  ] : []);
2236
2270
  return sort(rows.map((raw) => fromRunRow(fromRawRow(raw))));
@@ -2239,11 +2273,11 @@ var PrismaRoundTrips = class PrismaRoundTrips2 {
2239
2273
  const raw = tx;
2240
2274
  const at = /* @__PURE__ */ __name((ms) => new Date(ms).toISOString().replace("T", " ").replace("Z", ""), "at");
2241
2275
  const ns = namespace !== void 0 ? " AND namespace = ?" : "";
2242
- const picked = (await raw.$queryRawUnsafe(`SELECT * FROM durable_workflow_runs WHERE status = 'pending' AND (locked_until IS NULL OR locked_until <= ?)${ns} ORDER BY created_at, id LIMIT ? FOR UPDATE SKIP LOCKED`, at(nowMs), ...namespace !== void 0 ? [
2276
+ const picked = (await raw.$queryRawUnsafe(`SELECT * FROM ${this.t("durable_workflow_runs")} WHERE status = 'pending' AND (locked_until IS NULL OR locked_until <= ?)${ns} ORDER BY created_at, id LIMIT ? FOR UPDATE SKIP LOCKED`, at(nowMs), ...namespace !== void 0 ? [
2243
2277
  namespace
2244
2278
  ] : [], limit)).map((row) => fromRunRow(fromRawRow(row)));
2245
2279
  if (picked.length === 0) return [];
2246
- await raw.$executeRawUnsafe(`UPDATE durable_workflow_runs SET locked_by = ?, locked_until = ? WHERE id IN (${picked.map(() => "?").join(", ")})`, owner, at(leaseUntilMs), ...picked.map((run) => run.id));
2280
+ await raw.$executeRawUnsafe(`UPDATE ${this.t("durable_workflow_runs")} SET locked_by = ?, locked_until = ? WHERE id IN (${picked.map(() => "?").join(", ")})`, owner, at(leaseUntilMs), ...picked.map((run) => run.id));
2247
2281
  return sort(picked.map((run) => ({
2248
2282
  ...run,
2249
2283
  lockedBy: owner,
@@ -2270,6 +2304,7 @@ __name(durableManagedTables, "durableManagedTables");
2270
2304
  // Annotate the CommonJS export names for ESM import in node:
2271
2305
  0 && (module.exports = {
2272
2306
  PrismaStateStore,
2273
- durableManagedTables
2307
+ durableManagedTables,
2308
+ durableSchemaName
2274
2309
  });
2275
2310
  //# sourceMappingURL=index.cjs.map