@dudousxd/nestjs-durable-store-prisma 0.7.0 → 0.8.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/LICENSE +21 -0
- package/dist/index.cjs +439 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{prisma-state-store.d.ts → index.d.cts} +23 -6
- package/dist/index.d.ts +121 -2
- package/dist/index.js +411 -15
- package/dist/index.js.map +1 -1
- package/package.json +22 -6
- package/prisma/schema.prisma +21 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/prisma-state-store.d.ts.map +0 -1
- package/dist/prisma-state-store.js +0 -255
- package/dist/prisma-state-store.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,121 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { StateStore, WorkflowRun, StepCheckpoint, RunQuery, SignalWaiter } from '@dudousxd/nestjs-durable-core';
|
|
2
|
+
|
|
3
|
+
interface RunRow {
|
|
4
|
+
id: string;
|
|
5
|
+
workflow: string;
|
|
6
|
+
workflowVersion: string;
|
|
7
|
+
status: string;
|
|
8
|
+
input: unknown;
|
|
9
|
+
output: unknown;
|
|
10
|
+
error: unknown;
|
|
11
|
+
wakeAt: bigint | null;
|
|
12
|
+
lockedBy: string | null;
|
|
13
|
+
lockedUntil: Date | null;
|
|
14
|
+
recoveryAttempts: number | null;
|
|
15
|
+
tags: unknown;
|
|
16
|
+
searchAttributes: unknown;
|
|
17
|
+
createdAt: Date;
|
|
18
|
+
updatedAt: Date;
|
|
19
|
+
}
|
|
20
|
+
interface CheckpointRow {
|
|
21
|
+
runId: string;
|
|
22
|
+
seq: number;
|
|
23
|
+
name: string;
|
|
24
|
+
kind: string;
|
|
25
|
+
stepId: string;
|
|
26
|
+
status: string;
|
|
27
|
+
input: unknown;
|
|
28
|
+
output: unknown;
|
|
29
|
+
error: unknown;
|
|
30
|
+
events: unknown;
|
|
31
|
+
attempts: number;
|
|
32
|
+
workerGroup: string | null;
|
|
33
|
+
wakeAt: bigint | null;
|
|
34
|
+
enqueuedAt: Date | null;
|
|
35
|
+
startedAt: Date;
|
|
36
|
+
finishedAt: Date;
|
|
37
|
+
}
|
|
38
|
+
interface WaiterRow {
|
|
39
|
+
token: string;
|
|
40
|
+
runId: string;
|
|
41
|
+
seq: number;
|
|
42
|
+
}
|
|
43
|
+
interface RunAttributeRow {
|
|
44
|
+
runId: string;
|
|
45
|
+
key: string;
|
|
46
|
+
strValue: string | null;
|
|
47
|
+
numValue: number | null;
|
|
48
|
+
}
|
|
49
|
+
interface BufferedSignalRow {
|
|
50
|
+
id: bigint;
|
|
51
|
+
token: string;
|
|
52
|
+
payload: unknown;
|
|
53
|
+
}
|
|
54
|
+
type Args = any;
|
|
55
|
+
interface Delegate<Row> {
|
|
56
|
+
create(args: Args): Promise<Row>;
|
|
57
|
+
createMany(args: Args): Promise<{
|
|
58
|
+
count: number;
|
|
59
|
+
}>;
|
|
60
|
+
findUnique(args: Args): Promise<Row | null>;
|
|
61
|
+
findFirst(args?: Args): Promise<Row | null>;
|
|
62
|
+
findMany(args?: Args): Promise<Row[]>;
|
|
63
|
+
update(args: Args): Promise<Row>;
|
|
64
|
+
updateMany(args: Args): Promise<{
|
|
65
|
+
count: number;
|
|
66
|
+
}>;
|
|
67
|
+
upsert(args: Args): Promise<Row>;
|
|
68
|
+
delete(args: Args): Promise<Row>;
|
|
69
|
+
deleteMany(args?: Args): Promise<{
|
|
70
|
+
count: number;
|
|
71
|
+
}>;
|
|
72
|
+
}
|
|
73
|
+
interface DurablePrismaTx {
|
|
74
|
+
durableWorkflowRun: Delegate<RunRow>;
|
|
75
|
+
durableStepCheckpoint: Delegate<CheckpointRow>;
|
|
76
|
+
durableRunAttribute: Delegate<RunAttributeRow>;
|
|
77
|
+
durableSignalWaiter: Delegate<WaiterRow>;
|
|
78
|
+
durableBufferedSignal: Delegate<BufferedSignalRow>;
|
|
79
|
+
}
|
|
80
|
+
interface DurablePrismaClient extends DurablePrismaTx {
|
|
81
|
+
/** Prisma's interactive-transaction form: runs `fn` with a tx-scoped client and commits on resolve. */
|
|
82
|
+
$transaction<T>(fn: (tx: DurablePrismaTx) => Promise<T>): Promise<T>;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Prisma-backed `StateStore`. Pass your `PrismaClient` after adding the models from
|
|
86
|
+
* `prisma/schema.prisma` to your schema. JSON columns carry the run/step payloads directly;
|
|
87
|
+
* `wakeAt` is a `BigInt` (epoch ms).
|
|
88
|
+
*/
|
|
89
|
+
declare class PrismaStateStore implements StateStore {
|
|
90
|
+
private readonly db;
|
|
91
|
+
constructor(db: DurablePrismaClient);
|
|
92
|
+
createRun(run: WorkflowRun): Promise<void>;
|
|
93
|
+
updateRun(runId: string, patch: Partial<WorkflowRun>): Promise<void>;
|
|
94
|
+
/** Rewrite a run's normalized attribute rows: delete the old set, insert the current one. Mirrors
|
|
95
|
+
* the in-memory store's reindex so the side-table always reflects the run's live searchAttributes. */
|
|
96
|
+
private reindexAttributes;
|
|
97
|
+
getRun(runId: string): Promise<WorkflowRun | null>;
|
|
98
|
+
getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null>;
|
|
99
|
+
saveCheckpoint(checkpoint: StepCheckpoint): Promise<void>;
|
|
100
|
+
transaction<T>(work: (tx: {
|
|
101
|
+
raw: unknown;
|
|
102
|
+
saveCheckpoint: (cp: StepCheckpoint) => Promise<void>;
|
|
103
|
+
}) => Promise<T>): Promise<T>;
|
|
104
|
+
listIncompleteRuns(): Promise<WorkflowRun[]>;
|
|
105
|
+
listPendingRuns(limit: number): Promise<WorkflowRun[]>;
|
|
106
|
+
listDueTimers(nowMs: number): Promise<WorkflowRun[]>;
|
|
107
|
+
tryLockRun(runId: string, owner: string, leaseUntilMs: number, nowMs: number): Promise<boolean>;
|
|
108
|
+
releaseRunLock(runId: string): Promise<void>;
|
|
109
|
+
renewRunLock(runId: string, owner: string, leaseUntilMs: number): Promise<boolean>;
|
|
110
|
+
listRuns(query: RunQuery): Promise<WorkflowRun[]>;
|
|
111
|
+
listCheckpoints(runId: string): Promise<StepCheckpoint[]>;
|
|
112
|
+
putSignalWaiter(waiter: SignalWaiter): Promise<void>;
|
|
113
|
+
takeSignalWaiter(token: string): Promise<SignalWaiter | null>;
|
|
114
|
+
listSignalWaiters(prefix: string): Promise<SignalWaiter[]>;
|
|
115
|
+
bufferSignal(token: string, payload: unknown): Promise<void>;
|
|
116
|
+
takeBufferedSignal(token: string): Promise<{
|
|
117
|
+
payload: unknown;
|
|
118
|
+
} | null>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export { type DurablePrismaClient, type DurablePrismaTx, PrismaStateStore };
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,414 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/prisma-state-store.ts
|
|
5
|
+
import { attributeColumnFor, attributeOperand, normalizeAttributeRows } from "@dudousxd/nestjs-durable-core";
|
|
6
|
+
var PrismaStateStore = class {
|
|
7
|
+
static {
|
|
8
|
+
__name(this, "PrismaStateStore");
|
|
9
|
+
}
|
|
10
|
+
db;
|
|
11
|
+
constructor(db) {
|
|
12
|
+
this.db = db;
|
|
13
|
+
}
|
|
14
|
+
async createRun(run) {
|
|
15
|
+
await this.db.durableWorkflowRun.create({
|
|
16
|
+
data: toRunData(run)
|
|
17
|
+
});
|
|
18
|
+
await this.reindexAttributes(run.id, run.searchAttributes);
|
|
19
|
+
}
|
|
20
|
+
async updateRun(runId, patch) {
|
|
21
|
+
await this.db.durableWorkflowRun.update({
|
|
22
|
+
where: {
|
|
23
|
+
id: runId
|
|
24
|
+
},
|
|
25
|
+
data: toRunPatch(patch)
|
|
26
|
+
});
|
|
27
|
+
if ("searchAttributes" in patch) await this.reindexAttributes(runId, patch.searchAttributes);
|
|
28
|
+
}
|
|
29
|
+
/** Rewrite a run's normalized attribute rows: delete the old set, insert the current one. Mirrors
|
|
30
|
+
* the in-memory store's reindex so the side-table always reflects the run's live searchAttributes. */
|
|
31
|
+
async reindexAttributes(runId, attributes) {
|
|
32
|
+
await this.db.durableRunAttribute.deleteMany({
|
|
33
|
+
where: {
|
|
34
|
+
runId
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
const rows = normalizeAttributeRows(runId, attributes);
|
|
38
|
+
if (rows.length) await this.db.durableRunAttribute.createMany({
|
|
39
|
+
data: rows
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async getRun(runId) {
|
|
43
|
+
const row = await this.db.durableWorkflowRun.findUnique({
|
|
44
|
+
where: {
|
|
45
|
+
id: runId
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return row ? fromRunRow(row) : null;
|
|
49
|
+
}
|
|
50
|
+
async getCheckpoint(runId, seq) {
|
|
51
|
+
const row = await this.db.durableStepCheckpoint.findUnique({
|
|
52
|
+
where: {
|
|
53
|
+
runId_seq: {
|
|
54
|
+
runId,
|
|
55
|
+
seq
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return row ? fromCheckpointRow(row) : null;
|
|
60
|
+
}
|
|
61
|
+
async saveCheckpoint(checkpoint) {
|
|
62
|
+
const data = toCheckpointData(checkpoint);
|
|
63
|
+
await this.db.durableStepCheckpoint.upsert({
|
|
64
|
+
where: {
|
|
65
|
+
runId_seq: {
|
|
66
|
+
runId: checkpoint.runId,
|
|
67
|
+
seq: checkpoint.seq
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
create: data,
|
|
71
|
+
update: data
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async transaction(work) {
|
|
75
|
+
return this.db.$transaction(async (tx) => work({
|
|
76
|
+
raw: tx,
|
|
77
|
+
saveCheckpoint: /* @__PURE__ */ __name(async (cp) => {
|
|
78
|
+
const data = toCheckpointData(cp);
|
|
79
|
+
await tx.durableStepCheckpoint.upsert({
|
|
80
|
+
where: {
|
|
81
|
+
runId_seq: {
|
|
82
|
+
runId: cp.runId,
|
|
83
|
+
seq: cp.seq
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
create: data,
|
|
87
|
+
update: data
|
|
88
|
+
});
|
|
89
|
+
}, "saveCheckpoint")
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
async listIncompleteRuns() {
|
|
93
|
+
const rows = await this.db.durableWorkflowRun.findMany({
|
|
94
|
+
where: {
|
|
95
|
+
status: "running"
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
return rows.map(fromRunRow);
|
|
99
|
+
}
|
|
100
|
+
async listPendingRuns(limit) {
|
|
101
|
+
const rows = await this.db.durableWorkflowRun.findMany({
|
|
102
|
+
where: {
|
|
103
|
+
status: "pending"
|
|
104
|
+
},
|
|
105
|
+
orderBy: {
|
|
106
|
+
createdAt: "asc"
|
|
107
|
+
},
|
|
108
|
+
take: limit
|
|
109
|
+
});
|
|
110
|
+
return rows.map(fromRunRow);
|
|
111
|
+
}
|
|
112
|
+
async listDueTimers(nowMs) {
|
|
113
|
+
const rows = await this.db.durableWorkflowRun.findMany({
|
|
114
|
+
where: {
|
|
115
|
+
status: "suspended",
|
|
116
|
+
wakeAt: {
|
|
117
|
+
not: null,
|
|
118
|
+
lte: BigInt(nowMs)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
return rows.map(fromRunRow);
|
|
123
|
+
}
|
|
124
|
+
async tryLockRun(runId, owner, leaseUntilMs, nowMs) {
|
|
125
|
+
const result = await this.db.durableWorkflowRun.updateMany({
|
|
126
|
+
where: {
|
|
127
|
+
id: runId,
|
|
128
|
+
OR: [
|
|
129
|
+
{
|
|
130
|
+
lockedUntil: null
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
lockedUntil: {
|
|
134
|
+
lte: new Date(nowMs)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
]
|
|
138
|
+
},
|
|
139
|
+
data: {
|
|
140
|
+
lockedBy: owner,
|
|
141
|
+
lockedUntil: new Date(leaseUntilMs)
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
return result.count === 1;
|
|
145
|
+
}
|
|
146
|
+
async releaseRunLock(runId) {
|
|
147
|
+
await this.db.durableWorkflowRun.update({
|
|
148
|
+
where: {
|
|
149
|
+
id: runId
|
|
150
|
+
},
|
|
151
|
+
data: {
|
|
152
|
+
lockedBy: null,
|
|
153
|
+
lockedUntil: null
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
async renewRunLock(runId, owner, leaseUntilMs) {
|
|
158
|
+
const result = await this.db.durableWorkflowRun.updateMany({
|
|
159
|
+
where: {
|
|
160
|
+
id: runId,
|
|
161
|
+
lockedBy: owner
|
|
162
|
+
},
|
|
163
|
+
data: {
|
|
164
|
+
lockedUntil: new Date(leaseUntilMs)
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
return result.count === 1;
|
|
168
|
+
}
|
|
169
|
+
async listRuns(query) {
|
|
170
|
+
const where = {};
|
|
171
|
+
if (query.workflow) where.workflow = query.workflow;
|
|
172
|
+
if (query.status && query.statuses) {
|
|
173
|
+
where.AND = [
|
|
174
|
+
{
|
|
175
|
+
status: query.status
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
status: {
|
|
179
|
+
in: query.statuses
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
];
|
|
183
|
+
} else if (query.status) {
|
|
184
|
+
where.status = query.status;
|
|
185
|
+
} else if (query.statuses) {
|
|
186
|
+
where.status = {
|
|
187
|
+
in: query.statuses
|
|
188
|
+
};
|
|
7
189
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
190
|
+
if (query.tag) where.tags = {
|
|
191
|
+
array_contains: query.tag
|
|
192
|
+
};
|
|
193
|
+
if (query.attributes?.length) {
|
|
194
|
+
const existing = where.AND ?? [];
|
|
195
|
+
where.AND = [
|
|
196
|
+
...existing,
|
|
197
|
+
...query.attributes.map((f) => attributeSome(f))
|
|
198
|
+
];
|
|
199
|
+
}
|
|
200
|
+
const orderBy = {
|
|
201
|
+
createdAt: "desc"
|
|
202
|
+
};
|
|
203
|
+
const rows = await this.db.durableWorkflowRun.findMany({
|
|
204
|
+
where,
|
|
205
|
+
take: query.limit,
|
|
206
|
+
skip: query.offset,
|
|
207
|
+
orderBy
|
|
208
|
+
});
|
|
209
|
+
return rows.map(fromRunRow);
|
|
210
|
+
}
|
|
211
|
+
async listCheckpoints(runId) {
|
|
212
|
+
const rows = await this.db.durableStepCheckpoint.findMany({
|
|
213
|
+
where: {
|
|
214
|
+
runId
|
|
215
|
+
},
|
|
216
|
+
orderBy: {
|
|
217
|
+
seq: "asc"
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
return rows.map(fromCheckpointRow);
|
|
221
|
+
}
|
|
222
|
+
async putSignalWaiter(waiter) {
|
|
223
|
+
await this.db.durableSignalWaiter.upsert({
|
|
224
|
+
where: {
|
|
225
|
+
token: waiter.token
|
|
226
|
+
},
|
|
227
|
+
create: {
|
|
228
|
+
...waiter
|
|
229
|
+
},
|
|
230
|
+
update: {
|
|
231
|
+
runId: waiter.runId,
|
|
232
|
+
seq: waiter.seq
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
async takeSignalWaiter(token) {
|
|
237
|
+
const row = await this.db.durableSignalWaiter.findUnique({
|
|
238
|
+
where: {
|
|
239
|
+
token
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
if (!row) return null;
|
|
243
|
+
await this.db.durableSignalWaiter.delete({
|
|
244
|
+
where: {
|
|
245
|
+
token
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
return {
|
|
249
|
+
token: row.token,
|
|
250
|
+
runId: row.runId,
|
|
251
|
+
seq: row.seq
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
async listSignalWaiters(prefix) {
|
|
255
|
+
const rows = await this.db.durableSignalWaiter.findMany({
|
|
256
|
+
where: {
|
|
257
|
+
token: {
|
|
258
|
+
startsWith: prefix
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
return rows.map((r) => ({
|
|
263
|
+
token: r.token,
|
|
264
|
+
runId: r.runId,
|
|
265
|
+
seq: r.seq
|
|
266
|
+
}));
|
|
267
|
+
}
|
|
268
|
+
async bufferSignal(token, payload) {
|
|
269
|
+
await this.db.durableBufferedSignal.create({
|
|
270
|
+
data: {
|
|
271
|
+
token,
|
|
272
|
+
payload: jsonOrNull(payload)
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
async takeBufferedSignal(token) {
|
|
277
|
+
const row = await this.db.durableBufferedSignal.findFirst({
|
|
278
|
+
where: {
|
|
279
|
+
token
|
|
280
|
+
},
|
|
281
|
+
orderBy: {
|
|
282
|
+
id: "asc"
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
if (!row) return null;
|
|
286
|
+
await this.db.durableBufferedSignal.delete({
|
|
287
|
+
where: {
|
|
288
|
+
id: row.id
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
return {
|
|
292
|
+
payload: row.payload ?? void 0
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
function attributeSome(f) {
|
|
297
|
+
const col = attributeColumnFor(f);
|
|
298
|
+
const operand = attributeOperand(f);
|
|
299
|
+
const condition = f.op === "eq" ? operand : f.op === "ne" ? {
|
|
300
|
+
not: operand
|
|
301
|
+
} : {
|
|
302
|
+
[f.op]: operand
|
|
303
|
+
};
|
|
304
|
+
return {
|
|
305
|
+
attributes: {
|
|
306
|
+
some: {
|
|
307
|
+
key: f.key,
|
|
308
|
+
[col]: condition
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
__name(attributeSome, "attributeSome");
|
|
314
|
+
var bigOrNull = /* @__PURE__ */ __name((n) => n == null ? null : BigInt(n), "bigOrNull");
|
|
315
|
+
var numOrUndef = /* @__PURE__ */ __name((n) => n == null ? void 0 : Number(n), "numOrUndef");
|
|
316
|
+
var jsonOrNull = /* @__PURE__ */ __name((v) => v ?? null, "jsonOrNull");
|
|
317
|
+
function toRunData(run) {
|
|
318
|
+
return {
|
|
319
|
+
id: run.id,
|
|
320
|
+
workflow: run.workflow,
|
|
321
|
+
workflowVersion: run.workflowVersion,
|
|
322
|
+
status: run.status,
|
|
323
|
+
input: jsonOrNull(run.input),
|
|
324
|
+
output: jsonOrNull(run.output),
|
|
325
|
+
error: jsonOrNull(run.error),
|
|
326
|
+
wakeAt: bigOrNull(run.wakeAt),
|
|
327
|
+
lockedBy: run.lockedBy ?? null,
|
|
328
|
+
lockedUntil: run.lockedUntil == null ? null : new Date(run.lockedUntil),
|
|
329
|
+
recoveryAttempts: run.recoveryAttempts ?? null,
|
|
330
|
+
tags: jsonOrNull(run.tags),
|
|
331
|
+
searchAttributes: jsonOrNull(run.searchAttributes),
|
|
332
|
+
createdAt: run.createdAt,
|
|
333
|
+
updatedAt: run.updatedAt
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
__name(toRunData, "toRunData");
|
|
337
|
+
function toRunPatch(patch) {
|
|
338
|
+
const data = {};
|
|
339
|
+
if (patch.status !== void 0) data.status = patch.status;
|
|
340
|
+
if (patch.output !== void 0) data.output = jsonOrNull(patch.output);
|
|
341
|
+
if (patch.error !== void 0) data.error = jsonOrNull(patch.error);
|
|
342
|
+
if (patch.wakeAt !== void 0) data.wakeAt = bigOrNull(patch.wakeAt);
|
|
343
|
+
if (patch.recoveryAttempts !== void 0) data.recoveryAttempts = patch.recoveryAttempts ?? null;
|
|
344
|
+
if ("searchAttributes" in patch) data.searchAttributes = jsonOrNull(patch.searchAttributes);
|
|
345
|
+
if (patch.updatedAt !== void 0) data.updatedAt = patch.updatedAt;
|
|
346
|
+
return data;
|
|
347
|
+
}
|
|
348
|
+
__name(toRunPatch, "toRunPatch");
|
|
349
|
+
function fromRunRow(row) {
|
|
350
|
+
return {
|
|
351
|
+
id: row.id,
|
|
352
|
+
workflow: row.workflow,
|
|
353
|
+
workflowVersion: row.workflowVersion,
|
|
354
|
+
status: row.status,
|
|
355
|
+
input: row.input ?? void 0,
|
|
356
|
+
output: row.output ?? void 0,
|
|
357
|
+
error: row.error ?? void 0,
|
|
358
|
+
wakeAt: numOrUndef(row.wakeAt),
|
|
359
|
+
lockedBy: row.lockedBy ?? void 0,
|
|
360
|
+
lockedUntil: row.lockedUntil == null ? void 0 : row.lockedUntil.getTime(),
|
|
361
|
+
recoveryAttempts: row.recoveryAttempts ?? void 0,
|
|
362
|
+
tags: row.tags ?? void 0,
|
|
363
|
+
searchAttributes: row.searchAttributes ?? void 0,
|
|
364
|
+
createdAt: row.createdAt,
|
|
365
|
+
updatedAt: row.updatedAt
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
__name(fromRunRow, "fromRunRow");
|
|
369
|
+
function toCheckpointData(cp) {
|
|
370
|
+
return {
|
|
371
|
+
runId: cp.runId,
|
|
372
|
+
seq: cp.seq,
|
|
373
|
+
name: cp.name,
|
|
374
|
+
kind: cp.kind,
|
|
375
|
+
stepId: cp.stepId,
|
|
376
|
+
status: cp.status,
|
|
377
|
+
input: jsonOrNull(cp.input),
|
|
378
|
+
output: jsonOrNull(cp.output),
|
|
379
|
+
error: jsonOrNull(cp.error),
|
|
380
|
+
events: jsonOrNull(cp.events),
|
|
381
|
+
attempts: cp.attempts,
|
|
382
|
+
workerGroup: cp.workerGroup ?? null,
|
|
383
|
+
wakeAt: bigOrNull(cp.wakeAt),
|
|
384
|
+
enqueuedAt: cp.enqueuedAt,
|
|
385
|
+
startedAt: cp.startedAt,
|
|
386
|
+
finishedAt: cp.finishedAt
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
__name(toCheckpointData, "toCheckpointData");
|
|
390
|
+
function fromCheckpointRow(row) {
|
|
391
|
+
return {
|
|
392
|
+
runId: row.runId,
|
|
393
|
+
seq: row.seq,
|
|
394
|
+
name: row.name,
|
|
395
|
+
kind: row.kind,
|
|
396
|
+
stepId: row.stepId,
|
|
397
|
+
status: row.status,
|
|
398
|
+
input: row.input ?? void 0,
|
|
399
|
+
output: row.output ?? void 0,
|
|
400
|
+
error: row.error ?? void 0,
|
|
401
|
+
events: row.events ?? void 0,
|
|
402
|
+
attempts: row.attempts,
|
|
403
|
+
workerGroup: row.workerGroup ?? void 0,
|
|
404
|
+
wakeAt: numOrUndef(row.wakeAt),
|
|
405
|
+
enqueuedAt: row.enqueuedAt ?? row.startedAt,
|
|
406
|
+
startedAt: row.startedAt,
|
|
407
|
+
finishedAt: row.finishedAt
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
__name(fromCheckpointRow, "fromCheckpointRow");
|
|
411
|
+
export {
|
|
412
|
+
PrismaStateStore
|
|
15
413
|
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./prisma-state-store"), exports);
|
|
18
414
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC"}
|
|
1
|
+
{"version":3,"sources":["../src/prisma-state-store.ts"],"sourcesContent":["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} from '@dudousxd/nestjs-durable-core';\n\n/* The Prisma client is generated per-schema, so the adapter can't import a concrete one. Instead\n it depends on this structural surface — the three model delegates and the methods it uses. A\n real `PrismaClient` (with the models from prisma/schema.prisma added) satisfies it. Query-arg\n shapes are Prisma's own generics, so they're left as `any` at this single boundary; the row\n return types are precise, which is what the mapping code below relies on. */\n\ninterface RunRow {\n id: string;\n workflow: string;\n workflowVersion: string;\n status: string;\n input: unknown;\n output: unknown;\n error: unknown;\n wakeAt: bigint | null;\n lockedBy: string | null;\n lockedUntil: Date | null;\n recoveryAttempts: number | null;\n tags: unknown;\n searchAttributes: unknown;\n createdAt: Date;\n updatedAt: Date;\n}\n\ninterface CheckpointRow {\n runId: string;\n seq: number;\n name: string;\n kind: string;\n stepId: string;\n status: string;\n input: unknown;\n output: unknown;\n error: unknown;\n events: unknown;\n attempts: number;\n workerGroup: string | null;\n wakeAt: bigint | null;\n enqueuedAt: Date | null;\n startedAt: Date;\n finishedAt: Date;\n}\n\ninterface WaiterRow {\n token: string;\n runId: string;\n seq: number;\n}\n\ninterface RunAttributeRow {\n runId: string;\n key: string;\n strValue: string | null;\n numValue: number | null;\n}\n\ninterface BufferedSignalRow {\n id: bigint;\n token: string;\n payload: unknown;\n}\n\n// Prisma's per-model query args are generated generics; left as `any` at this single boundary.\ntype Args = any;\n\ninterface Delegate<Row> {\n create(args: Args): Promise<Row>;\n createMany(args: Args): Promise<{ count: number }>;\n findUnique(args: Args): Promise<Row | null>;\n findFirst(args?: Args): Promise<Row | null>;\n findMany(args?: Args): Promise<Row[]>;\n update(args: Args): Promise<Row>;\n updateMany(args: Args): Promise<{ count: number }>;\n upsert(args: Args): Promise<Row>;\n delete(args: Args): Promise<Row>;\n deleteMany(args?: Args): Promise<{ count: number }>;\n}\n\nexport interface DurablePrismaTx {\n durableWorkflowRun: Delegate<RunRow>;\n durableStepCheckpoint: Delegate<CheckpointRow>;\n durableRunAttribute: Delegate<RunAttributeRow>;\n durableSignalWaiter: Delegate<WaiterRow>;\n durableBufferedSignal: Delegate<BufferedSignalRow>;\n}\n\nexport interface DurablePrismaClient extends DurablePrismaTx {\n /** Prisma's interactive-transaction form: runs `fn` with a tx-scoped client and commits on resolve. */\n $transaction<T>(fn: (tx: DurablePrismaTx) => Promise<T>): Promise<T>;\n}\n\n/**\n * Prisma-backed `StateStore`. Pass your `PrismaClient` after adding the models from\n * `prisma/schema.prisma` to your schema. JSON columns carry the run/step payloads directly;\n * `wakeAt` is a `BigInt` (epoch ms).\n */\nexport class PrismaStateStore implements StateStore {\n constructor(private readonly db: DurablePrismaClient) {}\n\n async createRun(run: WorkflowRun): Promise<void> {\n await this.db.durableWorkflowRun.create({ data: toRunData(run) });\n await this.reindexAttributes(run.id, run.searchAttributes);\n }\n\n async updateRun(runId: string, patch: Partial<WorkflowRun>): Promise<void> {\n await this.db.durableWorkflowRun.update({ where: { id: runId }, data: toRunPatch(patch) });\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 ): Promise<void> {\n await this.db.durableRunAttribute.deleteMany({ where: { runId } });\n const rows = normalizeAttributeRows(runId, attributes);\n if (rows.length) await this.db.durableRunAttribute.createMany({ data: rows });\n }\n\n async getRun(runId: string): Promise<WorkflowRun | null> {\n const row = await this.db.durableWorkflowRun.findUnique({ where: { id: runId } });\n return row ? fromRunRow(row) : null;\n }\n\n async getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null> {\n const row = await this.db.durableStepCheckpoint.findUnique({\n where: { runId_seq: { runId, seq } },\n });\n return row ? fromCheckpointRow(row) : null;\n }\n\n async saveCheckpoint(checkpoint: StepCheckpoint): Promise<void> {\n const data = toCheckpointData(checkpoint);\n await this.db.durableStepCheckpoint.upsert({\n where: { runId_seq: { runId: checkpoint.runId, seq: checkpoint.seq } },\n create: data,\n update: data,\n });\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.db.$transaction(async (tx) =>\n work({\n raw: tx,\n saveCheckpoint: async (cp) => {\n const data = toCheckpointData(cp);\n await tx.durableStepCheckpoint.upsert({\n where: { runId_seq: { runId: cp.runId, seq: cp.seq } },\n create: data,\n update: data,\n });\n },\n }),\n );\n }\n\n async listIncompleteRuns(): Promise<WorkflowRun[]> {\n const rows = await this.db.durableWorkflowRun.findMany({ where: { status: 'running' } });\n return rows.map(fromRunRow);\n }\n\n async listPendingRuns(limit: number): Promise<WorkflowRun[]> {\n const rows = await this.db.durableWorkflowRun.findMany({\n where: { status: 'pending' },\n orderBy: { createdAt: 'asc' }, // FIFO dispatch\n take: limit,\n });\n return rows.map(fromRunRow);\n }\n\n async listDueTimers(nowMs: number): Promise<WorkflowRun[]> {\n const rows = await this.db.durableWorkflowRun.findMany({\n where: { status: 'suspended', wakeAt: { not: null, lte: BigInt(nowMs) } },\n });\n return rows.map(fromRunRow);\n }\n\n async tryLockRun(\n runId: string,\n owner: string,\n leaseUntilMs: number,\n nowMs: number,\n ): Promise<boolean> {\n const result = await this.db.durableWorkflowRun.updateMany({\n where: {\n id: runId,\n OR: [{ lockedUntil: null }, { lockedUntil: { lte: new Date(nowMs) } }],\n },\n data: { lockedBy: owner, lockedUntil: new Date(leaseUntilMs) },\n });\n return result.count === 1;\n }\n\n async releaseRunLock(runId: string): Promise<void> {\n await this.db.durableWorkflowRun.update({\n where: { id: runId },\n data: { lockedBy: null, lockedUntil: null },\n });\n }\n\n async renewRunLock(runId: string, owner: string, leaseUntilMs: number): Promise<boolean> {\n const result = await this.db.durableWorkflowRun.updateMany({\n where: { id: runId, lockedBy: owner },\n data: { lockedUntil: new Date(leaseUntilMs) },\n });\n return result.count === 1;\n }\n\n async listRuns(query: RunQuery): Promise<WorkflowRun[]> {\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). Combined with the\n // single-value `status` via AND when both are present, 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 if (query.tag) where.tags = { array_contains: query.tag };\n // Typed/range attribute predicates push DOWN into SQL: each filter becomes a relation `some`\n // (EXISTS) on the normalized `durable_run_attributes` side-table, so the DB filters AND paginates\n // — no full scan + in-process filter. ANDed: a run must match every filter, so one `some` each.\n if (query.attributes?.length) {\n const existing = (where.AND as unknown[] | undefined) ?? [];\n where.AND = [...existing, ...query.attributes.map((f) => attributeSome(f))];\n }\n const orderBy = { createdAt: 'desc' as const }; // newest first — recent runs on top in the dashboard\n const rows = await this.db.durableWorkflowRun.findMany({\n where,\n take: query.limit,\n skip: query.offset,\n orderBy,\n });\n return rows.map(fromRunRow);\n }\n\n async listCheckpoints(runId: string): Promise<StepCheckpoint[]> {\n const rows = await this.db.durableStepCheckpoint.findMany({\n where: { runId },\n orderBy: { seq: 'asc' },\n });\n return rows.map(fromCheckpointRow);\n }\n\n async putSignalWaiter(waiter: SignalWaiter): Promise<void> {\n await this.db.durableSignalWaiter.upsert({\n where: { token: waiter.token },\n create: { ...waiter },\n update: { runId: waiter.runId, seq: waiter.seq },\n });\n }\n\n async takeSignalWaiter(token: string): Promise<SignalWaiter | null> {\n const row = await this.db.durableSignalWaiter.findUnique({ where: { token } });\n if (!row) return null;\n await this.db.durableSignalWaiter.delete({ where: { token } });\n return { token: row.token, runId: row.runId, seq: row.seq };\n }\n\n async listSignalWaiters(prefix: string): Promise<SignalWaiter[]> {\n const rows = await this.db.durableSignalWaiter.findMany({\n where: { token: { startsWith: prefix } },\n });\n return rows.map((r) => ({ token: r.token, runId: r.runId, seq: r.seq }));\n }\n\n async bufferSignal(token: string, payload: unknown): Promise<void> {\n await this.db.durableBufferedSignal.create({ data: { token, payload: jsonOrNull(payload) } });\n }\n\n async takeBufferedSignal(token: string): Promise<{ payload: unknown } | null> {\n const row = await this.db.durableBufferedSignal.findFirst({\n where: { token },\n orderBy: { id: 'asc' },\n });\n if (!row) return null;\n await this.db.durableBufferedSignal.delete({ where: { id: row.id } });\n return { payload: row.payload ?? undefined };\n }\n}\n\n/**\n * One attribute predicate as a Prisma relation `some` filter on the side-table — compiles to an\n * EXISTS, so the predicate runs in SQL. `<>` (ne) maps to `{ not }`, which under `some` also excludes\n * runs where the attribute is absent (the missing-key-never-matches contract): `some` already\n * requires a matching row to exist. Numeric operands compare `numValue`, everything else `strValue`.\n */\nfunction attributeSome(f: AttributeFilter): { attributes: { some: Record<string, unknown> } } {\n const col = attributeColumnFor(f); // 'numValue' | 'strValue'\n const operand = attributeOperand(f);\n const condition =\n f.op === 'eq' ? operand : f.op === 'ne' ? { not: operand } : { [f.op]: operand }; // gt/gte/lt/lte map 1:1 to Prisma operators\n return { attributes: { some: { key: f.key, [col]: condition } } };\n}\n\nconst bigOrNull = (n: number | undefined) => (n == null ? null : BigInt(n));\nconst numOrUndef = (n: bigint | null) => (n == null ? undefined : Number(n));\nconst jsonOrNull = (v: unknown) => v ?? null;\n\nfunction toRunData(run: WorkflowRun) {\n return {\n id: run.id,\n workflow: run.workflow,\n workflowVersion: run.workflowVersion,\n status: run.status,\n input: jsonOrNull(run.input),\n output: jsonOrNull(run.output),\n error: jsonOrNull(run.error),\n wakeAt: bigOrNull(run.wakeAt),\n lockedBy: run.lockedBy ?? null,\n lockedUntil: run.lockedUntil == null ? null : new Date(run.lockedUntil),\n recoveryAttempts: run.recoveryAttempts ?? null,\n tags: jsonOrNull(run.tags),\n searchAttributes: jsonOrNull(run.searchAttributes),\n createdAt: run.createdAt,\n updatedAt: run.updatedAt,\n };\n}\n\nfunction toRunPatch(patch: Partial<WorkflowRun>) {\n const data: Record<string, unknown> = {};\n if (patch.status !== undefined) data.status = patch.status;\n if (patch.output !== undefined) data.output = jsonOrNull(patch.output);\n if (patch.error !== undefined) data.error = jsonOrNull(patch.error);\n if (patch.wakeAt !== undefined) data.wakeAt = bigOrNull(patch.wakeAt);\n if (patch.recoveryAttempts !== undefined) data.recoveryAttempts = patch.recoveryAttempts ?? null;\n if ('searchAttributes' in patch) data.searchAttributes = jsonOrNull(patch.searchAttributes);\n if (patch.updatedAt !== undefined) data.updatedAt = patch.updatedAt;\n return data;\n}\n\nfunction fromRunRow(row: RunRow): WorkflowRun {\n return {\n id: row.id,\n workflow: row.workflow,\n workflowVersion: row.workflowVersion,\n status: row.status as WorkflowRun['status'],\n input: row.input ?? undefined,\n output: row.output ?? undefined,\n error: (row.error ?? undefined) as StepError | undefined,\n wakeAt: numOrUndef(row.wakeAt),\n lockedBy: row.lockedBy ?? undefined,\n lockedUntil: row.lockedUntil == null ? undefined : row.lockedUntil.getTime(),\n recoveryAttempts: row.recoveryAttempts ?? undefined,\n tags: (row.tags as string[] | null) ?? undefined,\n searchAttributes:\n (row.searchAttributes as Record<string, string | number | boolean> | null) ?? undefined,\n createdAt: row.createdAt,\n updatedAt: row.updatedAt,\n };\n}\n\nfunction toCheckpointData(cp: StepCheckpoint) {\n return {\n runId: cp.runId,\n seq: cp.seq,\n name: cp.name,\n kind: cp.kind,\n stepId: cp.stepId,\n status: cp.status,\n input: jsonOrNull(cp.input),\n output: jsonOrNull(cp.output),\n error: jsonOrNull(cp.error),\n events: jsonOrNull(cp.events),\n attempts: cp.attempts,\n workerGroup: cp.workerGroup ?? null,\n wakeAt: bigOrNull(cp.wakeAt),\n enqueuedAt: cp.enqueuedAt,\n startedAt: cp.startedAt,\n finishedAt: cp.finishedAt,\n };\n}\n\nfunction fromCheckpointRow(row: CheckpointRow): StepCheckpoint {\n return {\n runId: row.runId,\n seq: row.seq,\n name: row.name,\n kind: row.kind as StepCheckpoint['kind'],\n stepId: row.stepId,\n status: row.status as StepCheckpoint['status'],\n input: row.input ?? undefined,\n output: row.output ?? undefined,\n error: (row.error ?? undefined) as StepError | undefined,\n events: (row.events ?? undefined) as StepEvent[] | undefined,\n attempts: row.attempts,\n workerGroup: row.workerGroup ?? undefined,\n wakeAt: numOrUndef(row.wakeAt),\n enqueuedAt: row.enqueuedAt ?? row.startedAt,\n startedAt: row.startedAt,\n finishedAt: row.finishedAt,\n };\n}\n"],"mappings":";;;;AAAA,SASEA,oBACAC,kBACAC,8BACK;AAkGA,IAAMC,mBAAN,MAAMA;EA9Gb,OA8GaA;;;;EACX,YAA6BC,IAAyB;SAAzBA,KAAAA;EAA0B;EAEvD,MAAMC,UAAUC,KAAiC;AAC/C,UAAM,KAAKF,GAAGG,mBAAmBC,OAAO;MAAEC,MAAMC,UAAUJ,GAAAA;IAAK,CAAA;AAC/D,UAAM,KAAKK,kBAAkBL,IAAIM,IAAIN,IAAIO,gBAAgB;EAC3D;EAEA,MAAMC,UAAUC,OAAeC,OAA4C;AACzE,UAAM,KAAKZ,GAAGG,mBAAmBU,OAAO;MAAEC,OAAO;QAAEN,IAAIG;MAAM;MAAGN,MAAMU,WAAWH,KAAAA;IAAO,CAAA;AAExF,QAAI,sBAAsBA,MAAO,OAAM,KAAKL,kBAAkBI,OAAOC,MAAMH,gBAAgB;EAC7F;;;EAIA,MAAcF,kBACZI,OACAK,YACe;AACf,UAAM,KAAKhB,GAAGiB,oBAAoBC,WAAW;MAAEJ,OAAO;QAAEH;MAAM;IAAE,CAAA;AAChE,UAAMQ,OAAOC,uBAAuBT,OAAOK,UAAAA;AAC3C,QAAIG,KAAKE,OAAQ,OAAM,KAAKrB,GAAGiB,oBAAoBK,WAAW;MAAEjB,MAAMc;IAAK,CAAA;EAC7E;EAEA,MAAMI,OAAOZ,OAA4C;AACvD,UAAMa,MAAM,MAAM,KAAKxB,GAAGG,mBAAmBsB,WAAW;MAAEX,OAAO;QAAEN,IAAIG;MAAM;IAAE,CAAA;AAC/E,WAAOa,MAAME,WAAWF,GAAAA,IAAO;EACjC;EAEA,MAAMG,cAAchB,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GAAGmF,MAAM;IAC5BC,UAAUpF,GAAGoF;IACbC,aAAarF,GAAGqF,eAAe;IAC/BzE,QAAQwD,UAAUpE,GAAGY,MAAM;IAC3B0E,YAAYtF,GAAGsF;IACfC,WAAWvF,GAAGuF;IACdC,YAAYxF,GAAGwF;EACjB;AACF;AAnBS/F;AAqBT,SAASH,kBAAkBP,KAAkB;AAC3C,SAAO;IACLb,OAAOa,IAAIb;IACXiB,KAAKJ,IAAII;IACT6F,MAAMjG,IAAIiG;IACVC,MAAMlG,IAAIkG;IACVC,QAAQnG,IAAImG;IACZ/E,QAAQpB,IAAIoB;IACZuE,OAAO3F,IAAI2F,SAASf;IACpBgB,QAAQ5F,IAAI4F,UAAUhB;IACtBiB,OAAQ7F,IAAI6F,SAASjB;IACrBwB,QAASpG,IAAIoG,UAAUxB;IACvByB,UAAUrG,IAAIqG;IACdC,aAAatG,IAAIsG,eAAe1B;IAChC/C,QAAQ0D,WAAWvF,IAAI6B,MAAM;IAC7B0E,YAAYvG,IAAIuG,cAAcvG,IAAIwG;IAClCA,WAAWxG,IAAIwG;IACfC,YAAYzG,IAAIyG;EAClB;AACF;AAnBSlG;","names":["attributeColumnFor","attributeOperand","normalizeAttributeRows","PrismaStateStore","db","createRun","run","durableWorkflowRun","create","data","toRunData","reindexAttributes","id","searchAttributes","updateRun","runId","patch","update","where","toRunPatch","attributes","durableRunAttribute","deleteMany","rows","normalizeAttributeRows","length","createMany","getRun","row","findUnique","fromRunRow","getCheckpoint","seq","durableStepCheckpoint","runId_seq","fromCheckpointRow","saveCheckpoint","checkpoint","toCheckpointData","upsert","transaction","work","$transaction","tx","raw","cp","listIncompleteRuns","findMany","status","map","listPendingRuns","limit","orderBy","createdAt","take","listDueTimers","nowMs","wakeAt","not","lte","BigInt","tryLockRun","owner","leaseUntilMs","result","updateMany","OR","lockedUntil","Date","lockedBy","count","releaseRunLock","renewRunLock","listRuns","query","workflow","statuses","AND","in","tag","tags","array_contains","existing","f","attributeSome","skip","offset","listCheckpoints","putSignalWaiter","waiter","durableSignalWaiter","token","takeSignalWaiter","delete","listSignalWaiters","prefix","startsWith","r","bufferSignal","payload","durableBufferedSignal","jsonOrNull","takeBufferedSignal","findFirst","undefined","col","attributeColumnFor","operand","attributeOperand","condition","op","some","key","bigOrNull","n","numOrUndef","Number","v","workflowVersion","input","output","error","recoveryAttempts","updatedAt","getTime","name","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-prisma",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Prisma adapter for the nestjs-durable StateStore",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Davide Carvalho",
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
"url": "https://github.com/DavideCarvalho/nestjs-durable.git",
|
|
10
10
|
"directory": "packages/store-prisma"
|
|
11
11
|
},
|
|
12
|
-
"type": "
|
|
13
|
-
"main": "dist/index.
|
|
14
|
-
"types": "dist/index.d.ts",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"main": "./dist/index.cjs",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
15
|
"files": [
|
|
16
16
|
"dist",
|
|
17
17
|
"prisma/schema.prisma"
|
|
@@ -22,12 +22,28 @@
|
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@prisma/client": "6.19.3",
|
|
25
|
+
"@testcontainers/postgresql": "10.18.0",
|
|
25
26
|
"prisma": "6.19.3",
|
|
26
27
|
"typescript": "5.9.3",
|
|
27
|
-
"
|
|
28
|
+
"tsup": "8.3.5",
|
|
29
|
+
"@dudousxd/nestjs-durable-core": "^0.28.0",
|
|
30
|
+
"@dudousxd/nestjs-durable-testing": "^0.4.0"
|
|
31
|
+
},
|
|
32
|
+
"module": "./dist/index.js",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"import": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"default": "./dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"require": {
|
|
40
|
+
"types": "./dist/index.d.cts",
|
|
41
|
+
"default": "./dist/index.cjs"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
28
44
|
},
|
|
29
45
|
"scripts": {
|
|
30
|
-
"build": "
|
|
46
|
+
"build": "tsup",
|
|
31
47
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
32
48
|
"prisma:generate": "prisma generate --schema prisma/test.prisma"
|
|
33
49
|
}
|