@dudousxd/nestjs-durable-store-prisma 0.27.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 +7 -4
package/dist/index.d.cts
CHANGED
|
@@ -125,6 +125,35 @@ interface DurablePrismaClient extends DurablePrismaTx {
|
|
|
125
125
|
/** Prisma's interactive-transaction form: runs `fn` with a tx-scoped client and commits on resolve. */
|
|
126
126
|
$transaction<T>(fn: (tx: DurablePrismaTx) => Promise<T>): Promise<T>;
|
|
127
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* The `namespace` read boundary as a spreadable Prisma `where` fragment.
|
|
130
|
+
*
|
|
131
|
+
* `undefined` means NO RESTRICTION — `{}` — because that is the operator (control-plane) view that
|
|
132
|
+
* sees every tenant, and it is what the engine passes when it runs unscoped. It does NOT mean
|
|
133
|
+
* "namespace IS NULL": the column is NOT NULL, so `{ namespace: undefined }` would be Prisma's
|
|
134
|
+
* "ignore this predicate" anyway, but `{ namespace: null }` would match nothing in production while
|
|
135
|
+
* still looking correct in a single-tenant test where every worker polls unscoped.
|
|
136
|
+
*
|
|
137
|
+
* A named namespace is plain equality, so a worker sees only its own tenant's rows — the boundary
|
|
138
|
+
* {@link WorkflowRun.namespace} promises for the four worker paths (pick up, recover, resume timers,
|
|
139
|
+
* time out).
|
|
140
|
+
*/
|
|
141
|
+
/** Options for a {@link PrismaStateStore}. */
|
|
142
|
+
interface PrismaStateStoreOptions {
|
|
143
|
+
/**
|
|
144
|
+
* The schema (Postgres) or database (MySQL) the durable tables live in. Put the same name on the
|
|
145
|
+
* durable models (`@@schema("durable")`, with `schemas = [...]` on your datasource) so the Prisma
|
|
146
|
+
* client qualifies its own queries; this option qualifies the store's raw SQL. Never set
|
|
147
|
+
* `search_path` (or the URL's `?schema=`) for this. Postgres only: Prisma has no `@@schema` on
|
|
148
|
+
* MySQL, and SQLite has no schemas, so either fails at construction. Default: unqualified.
|
|
149
|
+
*/
|
|
150
|
+
schema?: string | undefined;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Validate a durable `schema` option: an identifier of at most 63 characters. Returns it, or
|
|
154
|
+
* `undefined` when none is set.
|
|
155
|
+
*/
|
|
156
|
+
declare function durableSchemaName(schema: string | undefined): string | undefined;
|
|
128
157
|
/**
|
|
129
158
|
* Prisma-backed `StateStore`. Pass your `PrismaClient` after adding the models from
|
|
130
159
|
* `prisma/schema.prisma` to your schema. JSON columns carry the run/step payloads directly;
|
|
@@ -143,7 +172,8 @@ declare class PrismaStateStore implements StateStore {
|
|
|
143
172
|
readonly claimPendingRuns?: (limit: number, owner: string, leaseUntilMs: number, nowMs: number, namespace?: string) => Promise<WorkflowRun[]>;
|
|
144
173
|
/** Raw single-statement writes on Postgres/MySQL (Prisma wraps `updateMany` in a transaction). */
|
|
145
174
|
private readonly fast?;
|
|
146
|
-
|
|
175
|
+
private readonly schema;
|
|
176
|
+
constructor(db: DurablePrismaClient, options?: PrismaStateStoreOptions);
|
|
147
177
|
tryAdmitSingleton(runId: string, tag: string, workflow: string, limit: number, retryWakeAt?: number): Promise<boolean>;
|
|
148
178
|
createRun(run: WorkflowRun): Promise<void>;
|
|
149
179
|
updateRun(runId: string, inputPatch: Partial<WorkflowRun>): Promise<void>;
|
|
@@ -279,4 +309,4 @@ declare class PrismaStateStore implements StateStore {
|
|
|
279
309
|
*/
|
|
280
310
|
declare function durableManagedTables(): string[];
|
|
281
311
|
|
|
282
|
-
export { type DurablePrismaClient, type DurablePrismaTx, PrismaStateStore, durableManagedTables };
|
|
312
|
+
export { type DurablePrismaClient, type DurablePrismaTx, PrismaStateStore, type PrismaStateStoreOptions, durableManagedTables, durableSchemaName };
|
package/dist/index.d.ts
CHANGED
|
@@ -125,6 +125,35 @@ interface DurablePrismaClient extends DurablePrismaTx {
|
|
|
125
125
|
/** Prisma's interactive-transaction form: runs `fn` with a tx-scoped client and commits on resolve. */
|
|
126
126
|
$transaction<T>(fn: (tx: DurablePrismaTx) => Promise<T>): Promise<T>;
|
|
127
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* The `namespace` read boundary as a spreadable Prisma `where` fragment.
|
|
130
|
+
*
|
|
131
|
+
* `undefined` means NO RESTRICTION — `{}` — because that is the operator (control-plane) view that
|
|
132
|
+
* sees every tenant, and it is what the engine passes when it runs unscoped. It does NOT mean
|
|
133
|
+
* "namespace IS NULL": the column is NOT NULL, so `{ namespace: undefined }` would be Prisma's
|
|
134
|
+
* "ignore this predicate" anyway, but `{ namespace: null }` would match nothing in production while
|
|
135
|
+
* still looking correct in a single-tenant test where every worker polls unscoped.
|
|
136
|
+
*
|
|
137
|
+
* A named namespace is plain equality, so a worker sees only its own tenant's rows — the boundary
|
|
138
|
+
* {@link WorkflowRun.namespace} promises for the four worker paths (pick up, recover, resume timers,
|
|
139
|
+
* time out).
|
|
140
|
+
*/
|
|
141
|
+
/** Options for a {@link PrismaStateStore}. */
|
|
142
|
+
interface PrismaStateStoreOptions {
|
|
143
|
+
/**
|
|
144
|
+
* The schema (Postgres) or database (MySQL) the durable tables live in. Put the same name on the
|
|
145
|
+
* durable models (`@@schema("durable")`, with `schemas = [...]` on your datasource) so the Prisma
|
|
146
|
+
* client qualifies its own queries; this option qualifies the store's raw SQL. Never set
|
|
147
|
+
* `search_path` (or the URL's `?schema=`) for this. Postgres only: Prisma has no `@@schema` on
|
|
148
|
+
* MySQL, and SQLite has no schemas, so either fails at construction. Default: unqualified.
|
|
149
|
+
*/
|
|
150
|
+
schema?: string | undefined;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Validate a durable `schema` option: an identifier of at most 63 characters. Returns it, or
|
|
154
|
+
* `undefined` when none is set.
|
|
155
|
+
*/
|
|
156
|
+
declare function durableSchemaName(schema: string | undefined): string | undefined;
|
|
128
157
|
/**
|
|
129
158
|
* Prisma-backed `StateStore`. Pass your `PrismaClient` after adding the models from
|
|
130
159
|
* `prisma/schema.prisma` to your schema. JSON columns carry the run/step payloads directly;
|
|
@@ -143,7 +172,8 @@ declare class PrismaStateStore implements StateStore {
|
|
|
143
172
|
readonly claimPendingRuns?: (limit: number, owner: string, leaseUntilMs: number, nowMs: number, namespace?: string) => Promise<WorkflowRun[]>;
|
|
144
173
|
/** Raw single-statement writes on Postgres/MySQL (Prisma wraps `updateMany` in a transaction). */
|
|
145
174
|
private readonly fast?;
|
|
146
|
-
|
|
175
|
+
private readonly schema;
|
|
176
|
+
constructor(db: DurablePrismaClient, options?: PrismaStateStoreOptions);
|
|
147
177
|
tryAdmitSingleton(runId: string, tag: string, workflow: string, limit: number, retryWakeAt?: number): Promise<boolean>;
|
|
148
178
|
createRun(run: WorkflowRun): Promise<void>;
|
|
149
179
|
updateRun(runId: string, inputPatch: Partial<WorkflowRun>): Promise<void>;
|
|
@@ -279,4 +309,4 @@ declare class PrismaStateStore implements StateStore {
|
|
|
279
309
|
*/
|
|
280
310
|
declare function durableManagedTables(): string[];
|
|
281
311
|
|
|
282
|
-
export { type DurablePrismaClient, type DurablePrismaTx, PrismaStateStore, durableManagedTables };
|
|
312
|
+
export { type DurablePrismaClient, type DurablePrismaTx, PrismaStateStore, type PrismaStateStoreOptions, durableManagedTables, durableSchemaName };
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,21 @@ import { LIFECYCLE_REGISTRY_WORKFLOW, RUN_VALUE_FACET_SCAN, SINGLETON_ACTIVE_STA
|
|
|
6
6
|
var RETENTION_EXCLUDED = [
|
|
7
7
|
LIFECYCLE_REGISTRY_WORKFLOW
|
|
8
8
|
];
|
|
9
|
+
var SCHEMA_NAME = /^[A-Za-z_][A-Za-z0-9_$]*$/;
|
|
10
|
+
function durableSchemaName(schema) {
|
|
11
|
+
if (schema === void 0) return void 0;
|
|
12
|
+
if (!SCHEMA_NAME.test(schema) || schema.length > 63) {
|
|
13
|
+
throw new Error(`[nestjs-durable] invalid schema ${JSON.stringify(schema)}: use letters, digits, _ or $ (not first), at most 63 characters.`);
|
|
14
|
+
}
|
|
15
|
+
return schema;
|
|
16
|
+
}
|
|
17
|
+
__name(durableSchemaName, "durableSchemaName");
|
|
18
|
+
function rawTable(unqualified, schema, dialect) {
|
|
19
|
+
if (schema === void 0) return unqualified;
|
|
20
|
+
const name = unqualified.replace(/^["`]|["`]$/g, "");
|
|
21
|
+
return dialect === "postgres" ? `"${schema}"."${name}"` : `\`${schema}\`.\`${name}\``;
|
|
22
|
+
}
|
|
23
|
+
__name(rawTable, "rawTable");
|
|
9
24
|
function namespaceWhere(namespace) {
|
|
10
25
|
if (namespace === void 0) return {};
|
|
11
26
|
return {
|
|
@@ -26,13 +41,21 @@ var PrismaStateStore = class {
|
|
|
26
41
|
claimPendingRuns;
|
|
27
42
|
/** Raw single-statement writes on Postgres/MySQL (Prisma wraps `updateMany` in a transaction). */
|
|
28
43
|
fast;
|
|
29
|
-
|
|
44
|
+
schema;
|
|
45
|
+
constructor(db, options = {}) {
|
|
30
46
|
this.db = db;
|
|
31
47
|
const provider = db._activeProvider;
|
|
48
|
+
this.schema = durableSchemaName(options.schema);
|
|
49
|
+
if (this.schema !== void 0 && provider === "sqlite") {
|
|
50
|
+
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.`);
|
|
51
|
+
}
|
|
52
|
+
if (this.schema !== void 0 && provider === "mysql") {
|
|
53
|
+
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.`);
|
|
54
|
+
}
|
|
32
55
|
const raw = typeof db.$queryRawUnsafe === "function";
|
|
33
56
|
const dialect = raw && provider === "postgresql" ? "postgres" : raw && provider === "mysql" ? "mysql" : void 0;
|
|
34
57
|
if (!dialect) return;
|
|
35
|
-
const fast = new PrismaRoundTrips(db, dialect, this);
|
|
58
|
+
const fast = new PrismaRoundTrips(db, dialect, this, this.schema);
|
|
36
59
|
this.fast = fast;
|
|
37
60
|
this.insertCheckpointIfAbsent = (cp) => fast.insertCheckpointIfAbsent(cp);
|
|
38
61
|
this.settleResultsIfPending = (results) => fast.settleResultsIfPending(results);
|
|
@@ -48,7 +71,7 @@ var PrismaStateStore = class {
|
|
|
48
71
|
in: SINGLETON_ACTIVE_STATUSES
|
|
49
72
|
}
|
|
50
73
|
};
|
|
51
|
-
const lockRows = rowLockDialect(this.db);
|
|
74
|
+
const lockRows = rowLockDialect(this.db, this.schema);
|
|
52
75
|
const claimants = lockRows ? singletonClaimantIds(
|
|
53
76
|
// The primary, under the read-replicas extension: a lagging replica would leave rows out.
|
|
54
77
|
await primaryOf(this.db).durableWorkflowRun.findMany({
|
|
@@ -464,7 +487,7 @@ var PrismaStateStore = class {
|
|
|
464
487
|
const raw = tx;
|
|
465
488
|
for (let at = 0; at < firsts.length; at += 500) {
|
|
466
489
|
const chunk = firsts.slice(at, at + 500);
|
|
467
|
-
const won = await dialect(raw, chunk.map((i) => settlements[i]));
|
|
490
|
+
const won = await dialect(raw, chunk.map((i) => settlements[i]), this.schema);
|
|
468
491
|
for (const i of chunk) {
|
|
469
492
|
const s = settlements[i];
|
|
470
493
|
wrote[i] = won.has(checkpointKey(s.runId, s.seq));
|
|
@@ -1718,14 +1741,14 @@ function primaryOf(db) {
|
|
|
1718
1741
|
return typeof client.$primary === "function" ? client.$primary() : db;
|
|
1719
1742
|
}
|
|
1720
1743
|
__name(primaryOf, "primaryOf");
|
|
1721
|
-
function rowLockDialect(db) {
|
|
1744
|
+
function rowLockDialect(db, schema) {
|
|
1722
1745
|
const client = db;
|
|
1723
1746
|
if (typeof client.$queryRawUnsafe !== "function") return void 0;
|
|
1724
1747
|
if (client._activeProvider === "postgresql") {
|
|
1725
|
-
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);
|
|
1748
|
+
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);
|
|
1726
1749
|
}
|
|
1727
1750
|
if (client._activeProvider === "mysql") {
|
|
1728
|
-
return (tx, ids) => tx.$queryRawUnsafe(`SELECT id FROM durable_workflow_runs WHERE id IN (${ids.map(() => "?").join(", ")}) ORDER BY id FOR UPDATE`, ...ids);
|
|
1751
|
+
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);
|
|
1729
1752
|
}
|
|
1730
1753
|
return void 0;
|
|
1731
1754
|
}
|
|
@@ -1739,7 +1762,7 @@ function rawSettleDialect(db) {
|
|
|
1739
1762
|
return void 0;
|
|
1740
1763
|
}
|
|
1741
1764
|
__name(rawSettleDialect, "rawSettleDialect");
|
|
1742
|
-
var settleRowsPostgres = /* @__PURE__ */ __name(async (db, settlements) => {
|
|
1765
|
+
var settleRowsPostgres = /* @__PURE__ */ __name(async (db, settlements, schema) => {
|
|
1743
1766
|
const values = [];
|
|
1744
1767
|
const rows = settlements.map((s) => {
|
|
1745
1768
|
const n = values.length;
|
|
@@ -1747,7 +1770,7 @@ var settleRowsPostgres = /* @__PURE__ */ __name(async (db, settlements) => {
|
|
|
1747
1770
|
const p = /* @__PURE__ */ __name((k) => `$${n + k}`, "p");
|
|
1748
1771
|
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'))`;
|
|
1749
1772
|
});
|
|
1750
|
-
const written = await db.$queryRawUnsafe(`UPDATE "durable_step_checkpoints" AS c SET status = v.status, output = v.output,
|
|
1773
|
+
const written = await db.$queryRawUnsafe(`UPDATE ${rawTable('"durable_step_checkpoints"', schema, "postgres")} AS c SET status = v.status, output = v.output,
|
|
1751
1774
|
error = v.error, events = v.events, started_at = v.started_at, finished_at = v.finished_at
|
|
1752
1775
|
FROM (VALUES ${rows.join(", ")}) AS v(run_id, seq, status, output, error, events, started_at,
|
|
1753
1776
|
finished_at)
|
|
@@ -1755,10 +1778,10 @@ var settleRowsPostgres = /* @__PURE__ */ __name(async (db, settlements) => {
|
|
|
1755
1778
|
RETURNING c.run_id, c.seq`, ...values);
|
|
1756
1779
|
return new Set(written.map((row) => checkpointKey(row.run_id, Number(row.seq))));
|
|
1757
1780
|
}, "settleRowsPostgres");
|
|
1758
|
-
var settleRowsMysql = /* @__PURE__ */ __name(async (db, settlements) => {
|
|
1781
|
+
var settleRowsMysql = /* @__PURE__ */ __name(async (db, settlements, schema) => {
|
|
1759
1782
|
const pending = /* @__PURE__ */ new Set();
|
|
1760
1783
|
for (const [runId, seqs] of seqsByRun(settlements)) {
|
|
1761
|
-
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);
|
|
1784
|
+
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);
|
|
1762
1785
|
for (const row of rows2) pending.add(checkpointKey(row.run_id, Number(row.seq)));
|
|
1763
1786
|
}
|
|
1764
1787
|
const won = settlements.filter((s) => pending.has(checkpointKey(s.runId, s.seq)));
|
|
@@ -1769,7 +1792,7 @@ var settleRowsMysql = /* @__PURE__ */ __name(async (db, settlements) => {
|
|
|
1769
1792
|
values.push(s.runId, s.seq, s.status, jsonText(s.output), jsonText(s.error), jsonText(s.events), at(s.startedAt), at(s.finishedAt));
|
|
1770
1793
|
return i === 0 ? "SELECT ? AS run_id, ? AS seq, ? AS status, ? AS output, ? AS error, ? AS events, ? AS started_at, ? AS finished_at" : "SELECT ?, ?, ?, ?, ?, ?, ?, ?";
|
|
1771
1794
|
});
|
|
1772
|
-
const updated = await db.$executeRawUnsafe(`UPDATE durable_step_checkpoints AS c JOIN (${rows.join(" UNION ALL ")}) AS v
|
|
1795
|
+
const updated = await db.$executeRawUnsafe(`UPDATE ${rawTable("durable_step_checkpoints", schema, "mysql")} AS c JOIN (${rows.join(" UNION ALL ")}) AS v
|
|
1773
1796
|
ON c.run_id = v.run_id AND c.seq = v.seq
|
|
1774
1797
|
SET c.status = v.status, c.output = CAST(v.output AS JSON), c.error = CAST(v.error AS JSON),
|
|
1775
1798
|
c.events = CAST(v.events AS JSON), c.started_at = v.started_at, c.finished_at = v.finished_at
|
|
@@ -1894,17 +1917,23 @@ var PrismaRoundTrips = class PrismaRoundTrips2 {
|
|
|
1894
1917
|
}
|
|
1895
1918
|
db;
|
|
1896
1919
|
store;
|
|
1920
|
+
schema;
|
|
1897
1921
|
pg;
|
|
1898
|
-
constructor(db, dialect, store) {
|
|
1922
|
+
constructor(db, dialect, store, schema) {
|
|
1899
1923
|
this.db = db;
|
|
1900
1924
|
this.store = store;
|
|
1925
|
+
this.schema = schema;
|
|
1901
1926
|
this.pg = dialect === "postgres";
|
|
1902
1927
|
}
|
|
1928
|
+
/** A durable table as this statement wrote it unqualified, with the schema when one is set. */
|
|
1929
|
+
t(unqualified) {
|
|
1930
|
+
return rawTable(unqualified, this.schema, this.pg ? "postgres" : "mysql");
|
|
1931
|
+
}
|
|
1903
1932
|
get raw() {
|
|
1904
1933
|
return this.db;
|
|
1905
1934
|
}
|
|
1906
1935
|
async tryLockRunAndGet(runId, owner, leaseUntilMs, nowMs) {
|
|
1907
|
-
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());
|
|
1936
|
+
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());
|
|
1908
1937
|
const [row] = rows;
|
|
1909
1938
|
return row ? fromRunRow(fromRawRow(row)) : null;
|
|
1910
1939
|
}
|
|
@@ -2024,7 +2053,7 @@ var PrismaRoundTrips = class PrismaRoundTrips2 {
|
|
|
2024
2053
|
const names = columns.map(([name]) => this.q(name)).join(", ");
|
|
2025
2054
|
const marks = columns.map(([, kind], i) => this.param(kind, i + 1)).join(", ");
|
|
2026
2055
|
const values = columns.map(([, kind, v]) => this.value(kind, v));
|
|
2027
|
-
const insert = `INSERT INTO ${this.q("durable_step_checkpoints")} (${names}) VALUES (${marks})`;
|
|
2056
|
+
const insert = `INSERT INTO ${this.t(this.q("durable_step_checkpoints"))} (${names}) VALUES (${marks})`;
|
|
2028
2057
|
if (this.pg) {
|
|
2029
2058
|
const rows = await this.raw.$queryRawUnsafe(`${insert} ON CONFLICT (run_id, seq) DO NOTHING RETURNING seq`, ...values);
|
|
2030
2059
|
return rows.length === 1;
|
|
@@ -2132,12 +2161,12 @@ var PrismaRoundTrips = class PrismaRoundTrips2 {
|
|
|
2132
2161
|
values.push(status);
|
|
2133
2162
|
return this.param("text", values.length);
|
|
2134
2163
|
});
|
|
2135
|
-
return this.raw.$executeRawUnsafe(`UPDATE ${this.q("durable_workflow_runs")} SET ${set.join(", ")} WHERE id = ${id} AND status IN (${statuses.join(", ")})`, ...values);
|
|
2164
|
+
return this.raw.$executeRawUnsafe(`UPDATE ${this.t(this.q("durable_workflow_runs"))} SET ${set.join(", ")} WHERE id = ${id} AND status IN (${statuses.join(", ")})`, ...values);
|
|
2136
2165
|
}
|
|
2137
2166
|
/** `releaseRunLock` as one raw UPDATE (no transaction around it). */
|
|
2138
2167
|
async releaseRunLock(runId, owner) {
|
|
2139
2168
|
const where = owner === void 0 ? "" : ` AND locked_by = ${this.param("text", 2)}`;
|
|
2140
|
-
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 ? [] : [
|
|
2169
|
+
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 ? [] : [
|
|
2141
2170
|
owner
|
|
2142
2171
|
]);
|
|
2143
2172
|
}
|
|
@@ -2153,18 +2182,18 @@ var PrismaRoundTrips = class PrismaRoundTrips2 {
|
|
|
2153
2182
|
];
|
|
2154
2183
|
});
|
|
2155
2184
|
if (sent.length === 0) return out;
|
|
2156
|
-
const finished = `NOT EXISTS (SELECT 1 FROM durable_workflow_runs r WHERE r.id = c.run_id AND r.status IN ('cancelled', 'completed'))`;
|
|
2185
|
+
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'))`;
|
|
2157
2186
|
if (!this.pg) {
|
|
2158
2187
|
if (sent.length > 1) return settleResultsWithPlainCalls(this.store, results);
|
|
2159
2188
|
const i = sent[0];
|
|
2160
2189
|
const s = results[i];
|
|
2161
2190
|
const done = s.status === "completed";
|
|
2162
2191
|
const at = /* @__PURE__ */ __name((d) => d.toISOString().replace("T", " ").replace("Z", ""), "at");
|
|
2163
|
-
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 ? [
|
|
2192
|
+
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 ? [
|
|
2164
2193
|
jsonText(s.output)
|
|
2165
2194
|
] : [], jsonText(s.error), jsonText(s.events), s.startedAt ? at(s.startedAt) : null, at(s.finishedAt), s.runId, s.seq);
|
|
2166
2195
|
if (wrote !== 1) return out;
|
|
2167
|
-
const [row] = await this.raw.$queryRawUnsafe(`SELECT ${SETTLED_CHECKPOINT_COLUMNS} FROM durable_step_checkpoints WHERE run_id = ? AND seq = ?`, s.runId, s.seq);
|
|
2196
|
+
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);
|
|
2168
2197
|
out[i] = row ? fromCheckpointRow(fromRawRow({
|
|
2169
2198
|
...row,
|
|
2170
2199
|
input: null
|
|
@@ -2181,7 +2210,7 @@ var PrismaRoundTrips = class PrismaRoundTrips2 {
|
|
|
2181
2210
|
const p = /* @__PURE__ */ __name((k) => `$${n + k}`, "p");
|
|
2182
2211
|
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'))`;
|
|
2183
2212
|
});
|
|
2184
|
-
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);
|
|
2213
|
+
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);
|
|
2185
2214
|
const byKey = new Map(chunk.map((i) => {
|
|
2186
2215
|
const s = results[i];
|
|
2187
2216
|
return [
|
|
@@ -2205,7 +2234,7 @@ var PrismaRoundTrips = class PrismaRoundTrips2 {
|
|
|
2205
2234
|
const sort = /* @__PURE__ */ __name((runs) => runs.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime() || a.id.localeCompare(b.id)), "sort");
|
|
2206
2235
|
if (this.pg) {
|
|
2207
2236
|
const ns = namespace !== void 0 ? " AND namespace = $5" : "";
|
|
2208
|
-
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 ? [
|
|
2237
|
+
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 ? [
|
|
2209
2238
|
namespace
|
|
2210
2239
|
] : []);
|
|
2211
2240
|
return sort(rows.map((raw) => fromRunRow(fromRawRow(raw))));
|
|
@@ -2214,11 +2243,11 @@ var PrismaRoundTrips = class PrismaRoundTrips2 {
|
|
|
2214
2243
|
const raw = tx;
|
|
2215
2244
|
const at = /* @__PURE__ */ __name((ms) => new Date(ms).toISOString().replace("T", " ").replace("Z", ""), "at");
|
|
2216
2245
|
const ns = namespace !== void 0 ? " AND namespace = ?" : "";
|
|
2217
|
-
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 ? [
|
|
2246
|
+
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 ? [
|
|
2218
2247
|
namespace
|
|
2219
2248
|
] : [], limit)).map((row) => fromRunRow(fromRawRow(row)));
|
|
2220
2249
|
if (picked.length === 0) return [];
|
|
2221
|
-
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));
|
|
2250
|
+
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));
|
|
2222
2251
|
return sort(picked.map((run) => ({
|
|
2223
2252
|
...run,
|
|
2224
2253
|
lockedBy: owner,
|
|
@@ -2244,6 +2273,7 @@ function durableManagedTables() {
|
|
|
2244
2273
|
__name(durableManagedTables, "durableManagedTables");
|
|
2245
2274
|
export {
|
|
2246
2275
|
PrismaStateStore,
|
|
2247
|
-
durableManagedTables
|
|
2276
|
+
durableManagedTables,
|
|
2277
|
+
durableSchemaName
|
|
2248
2278
|
};
|
|
2249
2279
|
//# sourceMappingURL=index.js.map
|