@dudousxd/nestjs-durable-store-prisma 0.28.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +57 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -2
- package/dist/index.d.ts +32 -2
- package/dist/index.js +55 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
-
|
|
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({
|
|
@@ -489,7 +513,7 @@ var PrismaStateStore = class {
|
|
|
489
513
|
const raw = tx;
|
|
490
514
|
for (let at = 0; at < firsts.length; at += 500) {
|
|
491
515
|
const chunk = firsts.slice(at, at + 500);
|
|
492
|
-
const won = await dialect(raw, chunk.map((i) => settlements[i]));
|
|
516
|
+
const won = await dialect(raw, chunk.map((i) => settlements[i]), this.schema);
|
|
493
517
|
for (const i of chunk) {
|
|
494
518
|
const s = settlements[i];
|
|
495
519
|
wrote[i] = won.has(checkpointKey(s.runId, s.seq));
|
|
@@ -1743,14 +1767,14 @@ function primaryOf(db) {
|
|
|
1743
1767
|
return typeof client.$primary === "function" ? client.$primary() : db;
|
|
1744
1768
|
}
|
|
1745
1769
|
__name(primaryOf, "primaryOf");
|
|
1746
|
-
function rowLockDialect(db) {
|
|
1770
|
+
function rowLockDialect(db, schema) {
|
|
1747
1771
|
const client = db;
|
|
1748
1772
|
if (typeof client.$queryRawUnsafe !== "function") return void 0;
|
|
1749
1773
|
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);
|
|
1774
|
+
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
1775
|
}
|
|
1752
1776
|
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);
|
|
1777
|
+
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
1778
|
}
|
|
1755
1779
|
return void 0;
|
|
1756
1780
|
}
|
|
@@ -1764,7 +1788,7 @@ function rawSettleDialect(db) {
|
|
|
1764
1788
|
return void 0;
|
|
1765
1789
|
}
|
|
1766
1790
|
__name(rawSettleDialect, "rawSettleDialect");
|
|
1767
|
-
var settleRowsPostgres = /* @__PURE__ */ __name(async (db, settlements) => {
|
|
1791
|
+
var settleRowsPostgres = /* @__PURE__ */ __name(async (db, settlements, schema) => {
|
|
1768
1792
|
const values = [];
|
|
1769
1793
|
const rows = settlements.map((s) => {
|
|
1770
1794
|
const n = values.length;
|
|
@@ -1772,7 +1796,7 @@ var settleRowsPostgres = /* @__PURE__ */ __name(async (db, settlements) => {
|
|
|
1772
1796
|
const p = /* @__PURE__ */ __name((k) => `$${n + k}`, "p");
|
|
1773
1797
|
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
1798
|
});
|
|
1775
|
-
const written = await db.$queryRawUnsafe(`UPDATE "durable_step_checkpoints" AS c SET status = v.status, output = v.output,
|
|
1799
|
+
const written = await db.$queryRawUnsafe(`UPDATE ${rawTable('"durable_step_checkpoints"', schema, "postgres")} AS c SET status = v.status, output = v.output,
|
|
1776
1800
|
error = v.error, events = v.events, started_at = v.started_at, finished_at = v.finished_at
|
|
1777
1801
|
FROM (VALUES ${rows.join(", ")}) AS v(run_id, seq, status, output, error, events, started_at,
|
|
1778
1802
|
finished_at)
|
|
@@ -1780,10 +1804,10 @@ var settleRowsPostgres = /* @__PURE__ */ __name(async (db, settlements) => {
|
|
|
1780
1804
|
RETURNING c.run_id, c.seq`, ...values);
|
|
1781
1805
|
return new Set(written.map((row) => checkpointKey(row.run_id, Number(row.seq))));
|
|
1782
1806
|
}, "settleRowsPostgres");
|
|
1783
|
-
var settleRowsMysql = /* @__PURE__ */ __name(async (db, settlements) => {
|
|
1807
|
+
var settleRowsMysql = /* @__PURE__ */ __name(async (db, settlements, schema) => {
|
|
1784
1808
|
const pending = /* @__PURE__ */ new Set();
|
|
1785
1809
|
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);
|
|
1810
|
+
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
1811
|
for (const row of rows2) pending.add(checkpointKey(row.run_id, Number(row.seq)));
|
|
1788
1812
|
}
|
|
1789
1813
|
const won = settlements.filter((s) => pending.has(checkpointKey(s.runId, s.seq)));
|
|
@@ -1794,7 +1818,7 @@ var settleRowsMysql = /* @__PURE__ */ __name(async (db, settlements) => {
|
|
|
1794
1818
|
values.push(s.runId, s.seq, s.status, jsonText(s.output), jsonText(s.error), jsonText(s.events), at(s.startedAt), at(s.finishedAt));
|
|
1795
1819
|
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
1820
|
});
|
|
1797
|
-
const updated = await db.$executeRawUnsafe(`UPDATE durable_step_checkpoints AS c JOIN (${rows.join(" UNION ALL ")}) AS v
|
|
1821
|
+
const updated = await db.$executeRawUnsafe(`UPDATE ${rawTable("durable_step_checkpoints", schema, "mysql")} AS c JOIN (${rows.join(" UNION ALL ")}) AS v
|
|
1798
1822
|
ON c.run_id = v.run_id AND c.seq = v.seq
|
|
1799
1823
|
SET c.status = v.status, c.output = CAST(v.output AS JSON), c.error = CAST(v.error AS JSON),
|
|
1800
1824
|
c.events = CAST(v.events AS JSON), c.started_at = v.started_at, c.finished_at = v.finished_at
|
|
@@ -1919,17 +1943,23 @@ var PrismaRoundTrips = class PrismaRoundTrips2 {
|
|
|
1919
1943
|
}
|
|
1920
1944
|
db;
|
|
1921
1945
|
store;
|
|
1946
|
+
schema;
|
|
1922
1947
|
pg;
|
|
1923
|
-
constructor(db, dialect, store) {
|
|
1948
|
+
constructor(db, dialect, store, schema) {
|
|
1924
1949
|
this.db = db;
|
|
1925
1950
|
this.store = store;
|
|
1951
|
+
this.schema = schema;
|
|
1926
1952
|
this.pg = dialect === "postgres";
|
|
1927
1953
|
}
|
|
1954
|
+
/** A durable table as this statement wrote it unqualified, with the schema when one is set. */
|
|
1955
|
+
t(unqualified) {
|
|
1956
|
+
return rawTable(unqualified, this.schema, this.pg ? "postgres" : "mysql");
|
|
1957
|
+
}
|
|
1928
1958
|
get raw() {
|
|
1929
1959
|
return this.db;
|
|
1930
1960
|
}
|
|
1931
1961
|
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());
|
|
1962
|
+
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
1963
|
const [row] = rows;
|
|
1934
1964
|
return row ? fromRunRow(fromRawRow(row)) : null;
|
|
1935
1965
|
}
|
|
@@ -2049,7 +2079,7 @@ var PrismaRoundTrips = class PrismaRoundTrips2 {
|
|
|
2049
2079
|
const names = columns.map(([name]) => this.q(name)).join(", ");
|
|
2050
2080
|
const marks = columns.map(([, kind], i) => this.param(kind, i + 1)).join(", ");
|
|
2051
2081
|
const values = columns.map(([, kind, v]) => this.value(kind, v));
|
|
2052
|
-
const insert = `INSERT INTO ${this.q("durable_step_checkpoints")} (${names}) VALUES (${marks})`;
|
|
2082
|
+
const insert = `INSERT INTO ${this.t(this.q("durable_step_checkpoints"))} (${names}) VALUES (${marks})`;
|
|
2053
2083
|
if (this.pg) {
|
|
2054
2084
|
const rows = await this.raw.$queryRawUnsafe(`${insert} ON CONFLICT (run_id, seq) DO NOTHING RETURNING seq`, ...values);
|
|
2055
2085
|
return rows.length === 1;
|
|
@@ -2157,12 +2187,12 @@ var PrismaRoundTrips = class PrismaRoundTrips2 {
|
|
|
2157
2187
|
values.push(status);
|
|
2158
2188
|
return this.param("text", values.length);
|
|
2159
2189
|
});
|
|
2160
|
-
return this.raw.$executeRawUnsafe(`UPDATE ${this.q("durable_workflow_runs")} SET ${set.join(", ")} WHERE id = ${id} AND status IN (${statuses.join(", ")})`, ...values);
|
|
2190
|
+
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
2191
|
}
|
|
2162
2192
|
/** `releaseRunLock` as one raw UPDATE (no transaction around it). */
|
|
2163
2193
|
async releaseRunLock(runId, owner) {
|
|
2164
2194
|
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 ? [] : [
|
|
2195
|
+
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
2196
|
owner
|
|
2167
2197
|
]);
|
|
2168
2198
|
}
|
|
@@ -2178,18 +2208,18 @@ var PrismaRoundTrips = class PrismaRoundTrips2 {
|
|
|
2178
2208
|
];
|
|
2179
2209
|
});
|
|
2180
2210
|
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'))`;
|
|
2211
|
+
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
2212
|
if (!this.pg) {
|
|
2183
2213
|
if (sent.length > 1) return (0, import_nestjs_durable_core.settleResultsWithPlainCalls)(this.store, results);
|
|
2184
2214
|
const i = sent[0];
|
|
2185
2215
|
const s = results[i];
|
|
2186
2216
|
const done = s.status === "completed";
|
|
2187
2217
|
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 ? [
|
|
2218
|
+
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 = ? WHERE c.run_id = ? AND c.seq = ? AND c.status = 'pending' AND ${finished}`, s.status, ...done ? [
|
|
2189
2219
|
jsonText(s.output)
|
|
2190
2220
|
] : [], jsonText(s.error), jsonText(s.events), s.startedAt ? at(s.startedAt) : null, at(s.finishedAt), s.runId, s.seq);
|
|
2191
2221
|
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);
|
|
2222
|
+
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
2223
|
out[i] = row ? fromCheckpointRow(fromRawRow({
|
|
2194
2224
|
...row,
|
|
2195
2225
|
input: null
|
|
@@ -2206,7 +2236,7 @@ var PrismaRoundTrips = class PrismaRoundTrips2 {
|
|
|
2206
2236
|
const p = /* @__PURE__ */ __name((k) => `$${n + k}`, "p");
|
|
2207
2237
|
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
2238
|
});
|
|
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);
|
|
2239
|
+
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 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
2240
|
const byKey = new Map(chunk.map((i) => {
|
|
2211
2241
|
const s = results[i];
|
|
2212
2242
|
return [
|
|
@@ -2230,7 +2260,7 @@ var PrismaRoundTrips = class PrismaRoundTrips2 {
|
|
|
2230
2260
|
const sort = /* @__PURE__ */ __name((runs) => runs.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime() || a.id.localeCompare(b.id)), "sort");
|
|
2231
2261
|
if (this.pg) {
|
|
2232
2262
|
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 ? [
|
|
2263
|
+
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
2264
|
namespace
|
|
2235
2265
|
] : []);
|
|
2236
2266
|
return sort(rows.map((raw) => fromRunRow(fromRawRow(raw))));
|
|
@@ -2239,11 +2269,11 @@ var PrismaRoundTrips = class PrismaRoundTrips2 {
|
|
|
2239
2269
|
const raw = tx;
|
|
2240
2270
|
const at = /* @__PURE__ */ __name((ms) => new Date(ms).toISOString().replace("T", " ").replace("Z", ""), "at");
|
|
2241
2271
|
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 ? [
|
|
2272
|
+
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
2273
|
namespace
|
|
2244
2274
|
] : [], limit)).map((row) => fromRunRow(fromRawRow(row)));
|
|
2245
2275
|
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));
|
|
2276
|
+
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
2277
|
return sort(picked.map((run) => ({
|
|
2248
2278
|
...run,
|
|
2249
2279
|
lockedBy: owner,
|
|
@@ -2270,6 +2300,7 @@ __name(durableManagedTables, "durableManagedTables");
|
|
|
2270
2300
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2271
2301
|
0 && (module.exports = {
|
|
2272
2302
|
PrismaStateStore,
|
|
2273
|
-
durableManagedTables
|
|
2303
|
+
durableManagedTables,
|
|
2304
|
+
durableSchemaName
|
|
2274
2305
|
});
|
|
2275
2306
|
//# sourceMappingURL=index.cjs.map
|