@dudousxd/nestjs-durable-store-drizzle 0.25.0 → 0.27.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 +190 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +300 -1
- package/dist/index.d.ts +300 -1
- package/dist/index.js +189 -8
- package/dist/index.js.map +1 -1
- package/dist/pg/index.cjs +832 -122
- package/dist/pg/index.cjs.map +1 -1
- package/dist/pg/index.d.cts +295 -2
- package/dist/pg/index.d.ts +295 -2
- package/dist/pg/index.js +714 -15
- package/dist/pg/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -29,6 +29,7 @@ __export(src_exports, {
|
|
|
29
29
|
durableSchedules: () => durableSchedules,
|
|
30
30
|
durableSchema: () => durableSchema,
|
|
31
31
|
runAttributes: () => runAttributes,
|
|
32
|
+
signalIds: () => signalIds,
|
|
32
33
|
signalWaiters: () => signalWaiters,
|
|
33
34
|
stepCheckpoints: () => stepCheckpoints,
|
|
34
35
|
workflowRuns: () => workflowRuns
|
|
@@ -107,9 +108,23 @@ var workflowRuns = (0, import_sqlite_core.sqliteTable)("durable_workflow_runs",
|
|
|
107
108
|
// declared here, so until that runs, EVERY run query fails with "no such column: origin" — the same
|
|
108
109
|
// step `priority` needed before it.
|
|
109
110
|
origin: (0, import_sqlite_core.text)("origin"),
|
|
111
|
+
// The CUSTOMER (organization, clinic…) the run belongs to — tenancy, not the worker-pool
|
|
112
|
+
// `namespace`. Nullable: NULL = no tenant, which is every run while tenancy is off.
|
|
113
|
+
//
|
|
114
|
+
// MIGRATION (you own this adapter's migrations; until it runs, every run query fails with
|
|
115
|
+
// "no such column: tenant_id"):
|
|
116
|
+
//
|
|
117
|
+
// ALTER TABLE durable_workflow_runs ADD COLUMN tenant_id TEXT;
|
|
118
|
+
// ALTER TABLE durable_workflow_runs ADD COLUMN tenant_kind TEXT;
|
|
119
|
+
// CREATE INDEX IF NOT EXISTS durable_workflow_runs_tenant_idx
|
|
120
|
+
// ON durable_workflow_runs (tenant_id, created_at);
|
|
121
|
+
tenantId: (0, import_sqlite_core.text)("tenant_id"),
|
|
122
|
+
tenantKind: (0, import_sqlite_core.text)("tenant_kind"),
|
|
110
123
|
createdAt: (0, import_sqlite_core.integer)("created_at").notNull(),
|
|
111
124
|
updatedAt: (0, import_sqlite_core.integer)("updated_at").notNull()
|
|
112
125
|
}, (t) => [
|
|
126
|
+
// App-facing reads with tenancy on filter by tenant and page newest first.
|
|
127
|
+
(0, import_sqlite_core.index)("durable_workflow_runs_tenant_idx").on(t.tenantId, t.createdAt),
|
|
113
128
|
// `namespace` sits on EVERY poll tick's predicate — the pending (FIFO by `created_at`),
|
|
114
129
|
// incomplete and due-timer scans all filter by it and then by `status` — unlike `origin`, which
|
|
115
130
|
// only the dashboard's listing touches. Mirrors the MikroORM adapter's
|
|
@@ -208,6 +223,20 @@ var bufferedEvents = (0, import_sqlite_core.sqliteTable)("durable_buffered_event
|
|
|
208
223
|
}),
|
|
209
224
|
publishedAt: (0, import_sqlite_core.integer)("published_at").notNull()
|
|
210
225
|
});
|
|
226
|
+
var signalIds = (0, import_sqlite_core.sqliteTable)("durable_signal_ids", {
|
|
227
|
+
token: (0, import_sqlite_core.text)("token").notNull(),
|
|
228
|
+
signalId: (0, import_sqlite_core.text)("signal_id").notNull(),
|
|
229
|
+
expiresAt: (0, import_sqlite_core.integer)("expires_at").notNull()
|
|
230
|
+
}, (t) => [
|
|
231
|
+
(0, import_sqlite_core.primaryKey)({
|
|
232
|
+
columns: [
|
|
233
|
+
t.token,
|
|
234
|
+
t.signalId
|
|
235
|
+
]
|
|
236
|
+
}),
|
|
237
|
+
// The sweep's "expired by T" scan.
|
|
238
|
+
(0, import_sqlite_core.index)("durable_signal_ids_expires_at_idx").on(t.expiresAt)
|
|
239
|
+
]);
|
|
211
240
|
var durableSchedules = (0, import_sqlite_core.sqliteTable)(
|
|
212
241
|
"durable_schedules",
|
|
213
242
|
{
|
|
@@ -227,12 +256,19 @@ var durableSchedules = (0, import_sqlite_core.sqliteTable)(
|
|
|
227
256
|
state: (0, import_sqlite_core.text)("state", {
|
|
228
257
|
mode: "json"
|
|
229
258
|
}).$type().notNull(),
|
|
259
|
+
// The customer the schedule (and every run it starts) belongs to. MIGRATION:
|
|
260
|
+
// ALTER TABLE durable_schedules ADD COLUMN tenant_id TEXT;
|
|
261
|
+
// ALTER TABLE durable_schedules ADD COLUMN tenant_kind TEXT;
|
|
262
|
+
// CREATE INDEX IF NOT EXISTS durable_schedules_tenant_idx ON durable_schedules (tenant_id);
|
|
263
|
+
tenantId: (0, import_sqlite_core.text)("tenant_id"),
|
|
264
|
+
tenantKind: (0, import_sqlite_core.text)("tenant_kind"),
|
|
230
265
|
createdAt: (0, import_sqlite_core.integer)("created_at").notNull(),
|
|
231
266
|
updatedAt: (0, import_sqlite_core.integer)("updated_at").notNull()
|
|
232
267
|
},
|
|
233
268
|
// The poll's "due by T" scan: `paused = 0 AND next_fire_at <= T ORDER BY next_fire_at`.
|
|
234
269
|
(t) => [
|
|
235
|
-
(0, import_sqlite_core.index)("durable_schedules_due_idx").on(t.paused, t.nextFireAt)
|
|
270
|
+
(0, import_sqlite_core.index)("durable_schedules_due_idx").on(t.paused, t.nextFireAt),
|
|
271
|
+
(0, import_sqlite_core.index)("durable_schedules_tenant_idx").on(t.tenantId)
|
|
236
272
|
]
|
|
237
273
|
);
|
|
238
274
|
var durableSchema = {
|
|
@@ -242,6 +278,7 @@ var durableSchema = {
|
|
|
242
278
|
signalWaiters,
|
|
243
279
|
bufferedSignals,
|
|
244
280
|
bufferedEvents,
|
|
281
|
+
signalIds,
|
|
245
282
|
durableSchedules
|
|
246
283
|
};
|
|
247
284
|
function durableManagedTables() {
|
|
@@ -249,6 +286,74 @@ function durableManagedTables() {
|
|
|
249
286
|
}
|
|
250
287
|
__name(durableManagedTables, "durableManagedTables");
|
|
251
288
|
|
|
289
|
+
// src/tenant-columns.ts
|
|
290
|
+
var PG_STATEMENTS = [
|
|
291
|
+
'ALTER TABLE "durable_workflow_runs" ADD COLUMN IF NOT EXISTS "tenant_id" text;',
|
|
292
|
+
'ALTER TABLE "durable_workflow_runs" ADD COLUMN IF NOT EXISTS "tenant_kind" text;',
|
|
293
|
+
'ALTER TABLE "durable_schedules" ADD COLUMN IF NOT EXISTS "tenant_id" text;',
|
|
294
|
+
'ALTER TABLE "durable_schedules" ADD COLUMN IF NOT EXISTS "tenant_kind" text;',
|
|
295
|
+
'CREATE INDEX IF NOT EXISTS "durable_workflow_runs_tenant_idx" ON "durable_workflow_runs" USING btree ("tenant_id","created_at");',
|
|
296
|
+
'CREATE INDEX IF NOT EXISTS "durable_schedules_tenant_idx" ON "durable_schedules" USING btree ("tenant_id");'
|
|
297
|
+
];
|
|
298
|
+
var SQLITE_STATEMENTS = [
|
|
299
|
+
"ALTER TABLE durable_workflow_runs ADD COLUMN tenant_id TEXT;",
|
|
300
|
+
"ALTER TABLE durable_workflow_runs ADD COLUMN tenant_kind TEXT;",
|
|
301
|
+
"ALTER TABLE durable_schedules ADD COLUMN tenant_id TEXT;",
|
|
302
|
+
"ALTER TABLE durable_schedules ADD COLUMN tenant_kind TEXT;",
|
|
303
|
+
"CREATE INDEX IF NOT EXISTS durable_workflow_runs_tenant_idx ON durable_workflow_runs (tenant_id, created_at);",
|
|
304
|
+
"CREATE INDEX IF NOT EXISTS durable_schedules_tenant_idx ON durable_schedules (tenant_id);"
|
|
305
|
+
];
|
|
306
|
+
var TENANT_COLUMN = /tenant_(id|kind)/;
|
|
307
|
+
function isMissingTenantColumn(err) {
|
|
308
|
+
let cur = err;
|
|
309
|
+
for (let depth = 0; cur && depth < 5; depth += 1) {
|
|
310
|
+
const e = cur;
|
|
311
|
+
const message = typeof e.message === "string" ? e.message : "";
|
|
312
|
+
if (TENANT_COLUMN.test(message)) {
|
|
313
|
+
if (e.code === "42703" || /does not exist/.test(message) || /no such column/i.test(message)) {
|
|
314
|
+
return true;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
cur = e.cause;
|
|
318
|
+
}
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
__name(isMissingTenantColumn, "isMissingTenantColumn");
|
|
322
|
+
var MissingTenantColumnsError = class extends Error {
|
|
323
|
+
static {
|
|
324
|
+
__name(this, "MissingTenantColumnsError");
|
|
325
|
+
}
|
|
326
|
+
constructor(dialect, cause) {
|
|
327
|
+
const statements = dialect === "pg" ? PG_STATEMENTS : SQLITE_STATEMENTS;
|
|
328
|
+
const fix = dialect === "pg" ? "Generate a migration with drizzle-kit (`drizzle-kit generate`) from the store schema and apply it, or turn on the module's `autoSchema`, which adds them on boot." : "Generate a migration with drizzle-kit (`drizzle-kit generate`) from the store schema and apply it.";
|
|
329
|
+
super([
|
|
330
|
+
"[nestjs-durable] The durable tables are missing the tenancy columns (tenant_id, tenant_kind).",
|
|
331
|
+
"This version of the Drizzle store reads them on every run and schedule query, even with tenancy off.",
|
|
332
|
+
fix,
|
|
333
|
+
"The migration must contain:",
|
|
334
|
+
...statements.map((s) => ` ${s}`)
|
|
335
|
+
].join("\n"), {
|
|
336
|
+
cause
|
|
337
|
+
});
|
|
338
|
+
this.name = "MissingTenantColumnsError";
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
function tenantColumnsHint(dialect) {
|
|
342
|
+
return (err) => {
|
|
343
|
+
if (isMissingTenantColumn(err)) throw new MissingTenantColumnsError(dialect, err);
|
|
344
|
+
throw err;
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
__name(tenantColumnsHint, "tenantColumnsHint");
|
|
348
|
+
async function withTenantColumnsHint(dialect, query) {
|
|
349
|
+
try {
|
|
350
|
+
return await query;
|
|
351
|
+
} catch (err) {
|
|
352
|
+
return tenantColumnsHint(dialect)(err);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
__name(withTenantColumnsHint, "withTenantColumnsHint");
|
|
356
|
+
|
|
252
357
|
// src/drizzle-state-store.ts
|
|
253
358
|
var RETENTION_EXCLUDED = [
|
|
254
359
|
import_nestjs_durable_core.LIFECYCLE_REGISTRY_WORKFLOW
|
|
@@ -258,6 +363,14 @@ function anyOf(conditions) {
|
|
|
258
363
|
return present.length ? (0, import_drizzle_orm2.or)(...present) : import_drizzle_orm2.sql`1 = 0`;
|
|
259
364
|
}
|
|
260
365
|
__name(anyOf, "anyOf");
|
|
366
|
+
function tenantFilters(column, query) {
|
|
367
|
+
const one = /* @__PURE__ */ __name((id) => id === null ? (0, import_drizzle_orm2.isNull)(column) : (0, import_drizzle_orm2.eq)(column, id), "one");
|
|
368
|
+
return [
|
|
369
|
+
query.tenantId !== void 0 ? one(query.tenantId) : void 0,
|
|
370
|
+
query.tenantIds ? anyOf(query.tenantIds.map(one)) : void 0
|
|
371
|
+
];
|
|
372
|
+
}
|
|
373
|
+
__name(tenantFilters, "tenantFilters");
|
|
261
374
|
function namespaceFilter(namespace) {
|
|
262
375
|
if (namespace === void 0) return void 0;
|
|
263
376
|
if (namespace === DEFAULT_NAMESPACE || namespace === "") return (0, import_drizzle_orm2.or)((0, import_drizzle_orm2.eq)(workflowRuns.namespace, DEFAULT_NAMESPACE), (0, import_drizzle_orm2.eq)(workflowRuns.namespace, ""), (0, import_drizzle_orm2.isNull)(workflowRuns.namespace));
|
|
@@ -571,15 +684,15 @@ var DrizzleStateStore = class {
|
|
|
571
684
|
/** Recovery on boot. Namespace-scoped: a worker re-drives only its own tenant's crashed runs.
|
|
572
685
|
* `and(...)` drops an `undefined` predicate, so an unscoped caller recovers every namespace. */
|
|
573
686
|
async listIncompleteRuns(namespace) {
|
|
574
|
-
const rows = await this.db.select().from(workflowRuns).where((0, import_drizzle_orm2.and)((0, import_drizzle_orm2.inArray)(workflowRuns.status, [
|
|
687
|
+
const rows = await withTenantColumnsHint("sqlite", this.db.select().from(workflowRuns).where((0, import_drizzle_orm2.and)((0, import_drizzle_orm2.inArray)(workflowRuns.status, [
|
|
575
688
|
"running",
|
|
576
689
|
"cancelling"
|
|
577
|
-
]), namespaceFilter(namespace)));
|
|
690
|
+
]), namespaceFilter(namespace))));
|
|
578
691
|
return rows.map(fromRunRow);
|
|
579
692
|
}
|
|
580
693
|
async listOrphanedRuns(nowMs, limit, namespace, ownedBy) {
|
|
581
694
|
if (limit <= 0) return [];
|
|
582
|
-
const rows = await this.db.select().from(workflowRuns).where((0, import_drizzle_orm2.and)((0, import_drizzle_orm2.inArray)(workflowRuns.status, [
|
|
695
|
+
const rows = await withTenantColumnsHint("sqlite", this.db.select().from(workflowRuns).where((0, import_drizzle_orm2.and)((0, import_drizzle_orm2.inArray)(workflowRuns.status, [
|
|
583
696
|
"running",
|
|
584
697
|
"cancelling"
|
|
585
698
|
]), (0, import_drizzle_orm2.or)(
|
|
@@ -587,19 +700,19 @@ var DrizzleStateStore = class {
|
|
|
587
700
|
(0, import_drizzle_orm2.lte)(workflowRuns.lockedUntil, nowMs),
|
|
588
701
|
// A live lease left by a previous process with the caller's own instance id.
|
|
589
702
|
ownedBy ? (0, import_drizzle_orm2.and)((0, import_drizzle_orm2.eq)(workflowRuns.lockedBy, ownedBy.owner), (0, import_drizzle_orm2.lt)(workflowRuns.lockedUntil, ownedBy.lockedBefore)) : void 0
|
|
590
|
-
), namespaceFilter(namespace))).orderBy((0, import_drizzle_orm2.asc)(workflowRuns.createdAt)).limit(limit);
|
|
703
|
+
), namespaceFilter(namespace))).orderBy((0, import_drizzle_orm2.asc)(workflowRuns.createdAt)).limit(limit));
|
|
591
704
|
return rows.map(fromRunRow);
|
|
592
705
|
}
|
|
593
706
|
/** Dispatch pick-up. Namespace-scoped — without it a worker serving one tenant drains another
|
|
594
707
|
* tenant's queue, and the `limit` makes it worse: foreign runs consume the FIFO budget. */
|
|
595
708
|
async listPendingRuns(limit, namespace) {
|
|
596
|
-
const rows = await this.db.select().from(workflowRuns).where((0, import_drizzle_orm2.and)((0, import_drizzle_orm2.eq)(workflowRuns.status, "pending"), namespaceFilter(namespace))).orderBy((0, import_drizzle_orm2.asc)(workflowRuns.createdAt)).limit(limit);
|
|
709
|
+
const rows = await withTenantColumnsHint("sqlite", this.db.select().from(workflowRuns).where((0, import_drizzle_orm2.and)((0, import_drizzle_orm2.eq)(workflowRuns.status, "pending"), namespaceFilter(namespace))).orderBy((0, import_drizzle_orm2.asc)(workflowRuns.createdAt)).limit(limit));
|
|
597
710
|
return rows.map(fromRunRow);
|
|
598
711
|
}
|
|
599
712
|
/** Due durable timers. Namespace-scoped: a worker resumes only its own tenant's suspended runs. */
|
|
600
713
|
async listDueTimers(nowMs, namespace, limit) {
|
|
601
714
|
const query = this.db.select().from(workflowRuns).where((0, import_drizzle_orm2.and)((0, import_drizzle_orm2.eq)(workflowRuns.status, "suspended"), (0, import_drizzle_orm2.isNotNull)(workflowRuns.wakeAt), (0, import_drizzle_orm2.lte)(workflowRuns.wakeAt, nowMs), namespaceFilter(namespace))).orderBy((0, import_drizzle_orm2.asc)(workflowRuns.wakeAt));
|
|
602
|
-
const rows = limit !== void 0 ?
|
|
715
|
+
const rows = await withTenantColumnsHint("sqlite", limit !== void 0 ? query.limit(limit) : query);
|
|
603
716
|
return rows.map(fromRunRow);
|
|
604
717
|
}
|
|
605
718
|
async tryLockRun(runId, owner, leaseUntilMs, nowMs) {
|
|
@@ -649,6 +762,8 @@ var DrizzleStateStore = class {
|
|
|
649
762
|
// A set of origins may include `null` (the unattributed bucket), which `IN` cannot carry —
|
|
650
763
|
// `IN (NULL)` is never true — so it becomes its own ORed `IS NULL` branch.
|
|
651
764
|
query.origins ? anyOf(query.origins.map((o) => o === null ? (0, import_drizzle_orm2.isNull)(workflowRuns.origin) : (0, import_drizzle_orm2.eq)(workflowRuns.origin, o))) : void 0,
|
|
765
|
+
// The customer (tenancy matching rule): `null` = runs with no tenant.
|
|
766
|
+
...tenantFilters(workflowRuns.tenantId, query),
|
|
652
767
|
query.status ? (0, import_drizzle_orm2.eq)(workflowRuns.status, query.status) : void 0,
|
|
653
768
|
// `status IN (...)`; an empty set matches nothing (mirrors the in-memory store).
|
|
654
769
|
query.statuses ? query.statuses.length ? (0, import_drizzle_orm2.inArray)(workflowRuns.status, query.statuses) : import_drizzle_orm2.sql`1 = 0` : void 0,
|
|
@@ -749,7 +864,7 @@ var DrizzleStateStore = class {
|
|
|
749
864
|
return rows.length > 0;
|
|
750
865
|
}
|
|
751
866
|
async listSchedules(query) {
|
|
752
|
-
const rows = await this.db.select().from(durableSchedules).where((0, import_drizzle_orm2.and)(query.namespace !== void 0 ? (0, import_drizzle_orm2.eq)(durableSchedules.namespace, query.namespace) : void 0, query.workflow !== void 0 ? (0, import_drizzle_orm2.eq)(durableSchedules.workflow, query.workflow) : void 0, query.paused !== void 0 ? (0, import_drizzle_orm2.eq)(durableSchedules.paused, query.paused) : void 0, query.tag !== void 0 ? (0, import_drizzle_orm2.like)(durableSchedules.tags, `%"${query.tag}"%`) : void 0, query.dueBy !== void 0 ? (0, import_drizzle_orm2.and)((0, import_drizzle_orm2.eq)(durableSchedules.paused, false), (0, import_drizzle_orm2.lte)(durableSchedules.nextFireAt, query.dueBy)) : void 0)).orderBy(import_drizzle_orm2.sql`${durableSchedules.nextFireAt} IS NULL`, (0, import_drizzle_orm2.asc)(durableSchedules.nextFireAt), (0, import_drizzle_orm2.asc)(durableSchedules.id)).limit(query.limit ?? -1).offset(query.offset ?? 0);
|
|
867
|
+
const rows = await withTenantColumnsHint("sqlite", this.db.select().from(durableSchedules).where((0, import_drizzle_orm2.and)(query.namespace !== void 0 ? (0, import_drizzle_orm2.eq)(durableSchedules.namespace, query.namespace) : void 0, query.workflow !== void 0 ? (0, import_drizzle_orm2.eq)(durableSchedules.workflow, query.workflow) : void 0, query.paused !== void 0 ? (0, import_drizzle_orm2.eq)(durableSchedules.paused, query.paused) : void 0, query.tag !== void 0 ? (0, import_drizzle_orm2.like)(durableSchedules.tags, `%"${query.tag}"%`) : void 0, ...tenantFilters(durableSchedules.tenantId, query), query.dueBy !== void 0 ? (0, import_drizzle_orm2.and)((0, import_drizzle_orm2.eq)(durableSchedules.paused, false), (0, import_drizzle_orm2.lte)(durableSchedules.nextFireAt, query.dueBy)) : void 0)).orderBy(import_drizzle_orm2.sql`${durableSchedules.nextFireAt} IS NULL`, (0, import_drizzle_orm2.asc)(durableSchedules.nextFireAt), (0, import_drizzle_orm2.asc)(durableSchedules.id)).limit(query.limit ?? -1).offset(query.offset ?? 0));
|
|
753
868
|
return rows.map(fromScheduleRow);
|
|
754
869
|
}
|
|
755
870
|
async listCheckpoints(runId) {
|
|
@@ -977,6 +1092,51 @@ var DrizzleStateStore = class {
|
|
|
977
1092
|
payload: row.payload ?? void 0
|
|
978
1093
|
};
|
|
979
1094
|
}
|
|
1095
|
+
async takeOldestBufferedSignal(tokens) {
|
|
1096
|
+
if (tokens.length === 0) return null;
|
|
1097
|
+
const oldest = this.db.select({
|
|
1098
|
+
id: bufferedSignals.id
|
|
1099
|
+
}).from(bufferedSignals).where((0, import_drizzle_orm2.inArray)(bufferedSignals.token, [
|
|
1100
|
+
...new Set(tokens)
|
|
1101
|
+
])).orderBy((0, import_drizzle_orm2.asc)(bufferedSignals.id)).limit(1);
|
|
1102
|
+
const rows = await this.db.delete(bufferedSignals).where((0, import_drizzle_orm2.inArray)(bufferedSignals.id, oldest)).returning({
|
|
1103
|
+
token: bufferedSignals.token,
|
|
1104
|
+
payload: bufferedSignals.payload
|
|
1105
|
+
});
|
|
1106
|
+
const row = rows[0];
|
|
1107
|
+
return row ? {
|
|
1108
|
+
token: row.token,
|
|
1109
|
+
payload: row.payload ?? void 0
|
|
1110
|
+
} : null;
|
|
1111
|
+
}
|
|
1112
|
+
async claimSignalId(token, id, expiresAt, nowMs) {
|
|
1113
|
+
const rows = await this.db.insert(signalIds).values({
|
|
1114
|
+
token,
|
|
1115
|
+
signalId: id,
|
|
1116
|
+
expiresAt
|
|
1117
|
+
}).onConflictDoUpdate({
|
|
1118
|
+
target: [
|
|
1119
|
+
signalIds.token,
|
|
1120
|
+
signalIds.signalId
|
|
1121
|
+
],
|
|
1122
|
+
set: {
|
|
1123
|
+
expiresAt
|
|
1124
|
+
},
|
|
1125
|
+
setWhere: (0, import_drizzle_orm2.lte)(signalIds.expiresAt, nowMs)
|
|
1126
|
+
}).returning({
|
|
1127
|
+
token: signalIds.token
|
|
1128
|
+
});
|
|
1129
|
+
return rows.length > 0;
|
|
1130
|
+
}
|
|
1131
|
+
async releaseSignalId(token, id) {
|
|
1132
|
+
await this.db.delete(signalIds).where((0, import_drizzle_orm2.and)((0, import_drizzle_orm2.eq)(signalIds.token, token), (0, import_drizzle_orm2.eq)(signalIds.signalId, id)));
|
|
1133
|
+
}
|
|
1134
|
+
async deleteExpiredSignalIds(nowMs, limit) {
|
|
1135
|
+
const rows = await this.db.delete(signalIds).where(import_drizzle_orm2.sql`(${signalIds.token}, ${signalIds.signalId}) in (select ${signalIds.token}, ${signalIds.signalId} from ${signalIds} where ${signalIds.expiresAt} <= ${nowMs} limit ${limit})`).returning({
|
|
1136
|
+
token: signalIds.token
|
|
1137
|
+
});
|
|
1138
|
+
return rows.length;
|
|
1139
|
+
}
|
|
980
1140
|
async listBufferedSignals(tokenPrefix, afterId, limit) {
|
|
981
1141
|
const rows = await this.db.select().from(bufferedSignals).where((0, import_drizzle_orm2.and)((0, import_drizzle_orm2.like)(bufferedSignals.token, `${tokenPrefix}%`), afterId !== void 0 ? (0, import_drizzle_orm2.gt)(bufferedSignals.id, Number(afterId)) : void 0)).orderBy((0, import_drizzle_orm2.asc)(bufferedSignals.id)).limit(limit);
|
|
982
1142
|
return rows.filter((r) => r.token.startsWith(tokenPrefix)).map((r) => ({
|
|
@@ -1033,6 +1193,8 @@ function toRunRow(run) {
|
|
|
1033
1193
|
namespace: run.namespace || DEFAULT_NAMESPACE,
|
|
1034
1194
|
// Absent origin stays SQL NULL — "unknown", never coerced into a real-looking library name.
|
|
1035
1195
|
origin: run.origin ?? null,
|
|
1196
|
+
tenantId: run.tenantId ?? null,
|
|
1197
|
+
tenantKind: run.tenantKind ?? null,
|
|
1036
1198
|
createdAt: run.createdAt.getTime(),
|
|
1037
1199
|
updatedAt: run.updatedAt.getTime()
|
|
1038
1200
|
};
|
|
@@ -1056,6 +1218,8 @@ function toRunPatch(patch) {
|
|
|
1056
1218
|
if ("priority" in patch) row.priority = patch.priority ?? null;
|
|
1057
1219
|
if ("namespace" in patch) row.namespace = patch.namespace || DEFAULT_NAMESPACE;
|
|
1058
1220
|
if ("origin" in patch) row.origin = patch.origin ?? null;
|
|
1221
|
+
if ("tenantId" in patch) row.tenantId = patch.tenantId ?? null;
|
|
1222
|
+
if ("tenantKind" in patch) row.tenantKind = patch.tenantKind ?? null;
|
|
1059
1223
|
if (patch.createdAt != null) row.createdAt = patch.createdAt.getTime();
|
|
1060
1224
|
if (patch.updatedAt != null) row.updatedAt = patch.updatedAt.getTime();
|
|
1061
1225
|
return row;
|
|
@@ -1085,6 +1249,13 @@ function fromRunRow(row) {
|
|
|
1085
1249
|
namespace: row.namespace || DEFAULT_NAMESPACE,
|
|
1086
1250
|
// NULL (a row written before the column existed) surfaces as `undefined` = unknown origin.
|
|
1087
1251
|
origin: row.origin ?? void 0,
|
|
1252
|
+
// NULL = no tenant; left off the object entirely so a tenancy-off run reads back unchanged.
|
|
1253
|
+
...row.tenantId != null ? {
|
|
1254
|
+
tenantId: row.tenantId
|
|
1255
|
+
} : {},
|
|
1256
|
+
...row.tenantKind != null ? {
|
|
1257
|
+
tenantKind: row.tenantKind
|
|
1258
|
+
} : {},
|
|
1088
1259
|
createdAt: new Date(row.createdAt),
|
|
1089
1260
|
updatedAt: new Date(row.updatedAt)
|
|
1090
1261
|
};
|
|
@@ -1144,6 +1315,8 @@ function toScheduleRow(r) {
|
|
|
1144
1315
|
tags: r.tags ?? null,
|
|
1145
1316
|
spec: r.spec,
|
|
1146
1317
|
state: r.state,
|
|
1318
|
+
tenantId: r.tenantId ?? null,
|
|
1319
|
+
tenantKind: r.tenantKind ?? null,
|
|
1147
1320
|
createdAt: r.createdAt.getTime(),
|
|
1148
1321
|
updatedAt: r.updatedAt.getTime()
|
|
1149
1322
|
};
|
|
@@ -1158,6 +1331,8 @@ function toSchedulePatch(patch) {
|
|
|
1158
1331
|
if ("tags" in patch) set.tags = patch.tags ?? null;
|
|
1159
1332
|
if ("spec" in patch && patch.spec !== void 0) set.spec = patch.spec;
|
|
1160
1333
|
if ("state" in patch && patch.state !== void 0) set.state = patch.state;
|
|
1334
|
+
if ("tenantId" in patch) set.tenantId = patch.tenantId ?? null;
|
|
1335
|
+
if ("tenantKind" in patch) set.tenantKind = patch.tenantKind ?? null;
|
|
1161
1336
|
if ("updatedAt" in patch && patch.updatedAt !== void 0) set.updatedAt = patch.updatedAt.getTime();
|
|
1162
1337
|
return set;
|
|
1163
1338
|
}
|
|
@@ -1174,6 +1349,12 @@ function fromScheduleRow(row) {
|
|
|
1174
1349
|
} : {},
|
|
1175
1350
|
spec: row.spec ?? {},
|
|
1176
1351
|
state: row.state ?? {},
|
|
1352
|
+
...row.tenantId != null ? {
|
|
1353
|
+
tenantId: row.tenantId
|
|
1354
|
+
} : {},
|
|
1355
|
+
...row.tenantKind != null ? {
|
|
1356
|
+
tenantKind: row.tenantKind
|
|
1357
|
+
} : {},
|
|
1177
1358
|
createdAt: new Date(row.createdAt),
|
|
1178
1359
|
updatedAt: new Date(row.updatedAt)
|
|
1179
1360
|
};
|
|
@@ -1251,6 +1432,7 @@ __name(excludedSet, "excludedSet");
|
|
|
1251
1432
|
durableSchedules,
|
|
1252
1433
|
durableSchema,
|
|
1253
1434
|
runAttributes,
|
|
1435
|
+
signalIds,
|
|
1254
1436
|
signalWaiters,
|
|
1255
1437
|
stepCheckpoints,
|
|
1256
1438
|
workflowRuns
|