@dudousxd/nestjs-durable-store-drizzle 0.24.7 → 0.26.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 +75 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +148 -1
- package/dist/index.d.ts +148 -1
- package/dist/index.js +75 -6
- package/dist/index.js.map +1 -1
- package/dist/pg/index.cjs +719 -121
- package/dist/pg/index.cjs.map +1 -1
- package/dist/pg/index.d.cts +159 -2
- package/dist/pg/index.d.ts +159 -2
- package/dist/pg/index.js +600 -13
- package/dist/pg/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -97,6 +97,13 @@ declare class DrizzleStateStore implements StateStore {
|
|
|
97
97
|
takeBufferedSignal(token: string): Promise<{
|
|
98
98
|
payload: unknown;
|
|
99
99
|
} | null>;
|
|
100
|
+
takeOldestBufferedSignal(tokens: string[]): Promise<{
|
|
101
|
+
token: string;
|
|
102
|
+
payload: unknown;
|
|
103
|
+
} | null>;
|
|
104
|
+
claimSignalId(token: string, id: string, expiresAt: number, nowMs: number): Promise<boolean>;
|
|
105
|
+
releaseSignalId(token: string, id: string): Promise<void>;
|
|
106
|
+
deleteExpiredSignalIds(nowMs: number, limit: number): Promise<number>;
|
|
100
107
|
listBufferedSignals(tokenPrefix: string, afterId: string | undefined, limit: number): Promise<BufferedSignalRow[]>;
|
|
101
108
|
deleteBufferedSignals(ids: string[]): Promise<void>;
|
|
102
109
|
bufferEvent(input: {
|
|
@@ -1077,6 +1084,84 @@ declare const bufferedEvents: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
|
|
|
1077
1084
|
};
|
|
1078
1085
|
dialect: "sqlite";
|
|
1079
1086
|
}>;
|
|
1087
|
+
/**
|
|
1088
|
+
* Signal dedupe ids (`engine.signal(token, payload, { id })`): one row per `(token, signal_id)`,
|
|
1089
|
+
* deduplicating until `expires_at` (epoch ms). Expired rows are ignored by `claimSignalId` and
|
|
1090
|
+
* deleted by `engine.sweepExpiredSignalIds()`.
|
|
1091
|
+
*
|
|
1092
|
+
* MIGRATION (you own this adapter's migrations): `drizzle-kit generate` picks the table up from
|
|
1093
|
+
* `durableSchema`; by hand:
|
|
1094
|
+
*
|
|
1095
|
+
* ```sql
|
|
1096
|
+
* CREATE TABLE durable_signal_ids (token TEXT NOT NULL, signal_id TEXT NOT NULL,
|
|
1097
|
+
* expires_at INTEGER NOT NULL, PRIMARY KEY (token, signal_id));
|
|
1098
|
+
* CREATE INDEX durable_signal_ids_expires_at_idx ON durable_signal_ids (expires_at);
|
|
1099
|
+
* ```
|
|
1100
|
+
*
|
|
1101
|
+
* Only needed if you send signals with an `id`.
|
|
1102
|
+
*/
|
|
1103
|
+
declare const signalIds: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
|
|
1104
|
+
name: "durable_signal_ids";
|
|
1105
|
+
schema: undefined;
|
|
1106
|
+
columns: {
|
|
1107
|
+
token: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
1108
|
+
name: "token";
|
|
1109
|
+
tableName: "durable_signal_ids";
|
|
1110
|
+
dataType: "string";
|
|
1111
|
+
columnType: "SQLiteText";
|
|
1112
|
+
data: string;
|
|
1113
|
+
driverParam: string;
|
|
1114
|
+
notNull: true;
|
|
1115
|
+
hasDefault: false;
|
|
1116
|
+
isPrimaryKey: false;
|
|
1117
|
+
isAutoincrement: false;
|
|
1118
|
+
hasRuntimeDefault: false;
|
|
1119
|
+
enumValues: [string, ...string[]];
|
|
1120
|
+
baseColumn: never;
|
|
1121
|
+
identity: undefined;
|
|
1122
|
+
generated: undefined;
|
|
1123
|
+
}, {}, {
|
|
1124
|
+
length: number | undefined;
|
|
1125
|
+
}>;
|
|
1126
|
+
signalId: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
1127
|
+
name: "signal_id";
|
|
1128
|
+
tableName: "durable_signal_ids";
|
|
1129
|
+
dataType: "string";
|
|
1130
|
+
columnType: "SQLiteText";
|
|
1131
|
+
data: string;
|
|
1132
|
+
driverParam: string;
|
|
1133
|
+
notNull: true;
|
|
1134
|
+
hasDefault: false;
|
|
1135
|
+
isPrimaryKey: false;
|
|
1136
|
+
isAutoincrement: false;
|
|
1137
|
+
hasRuntimeDefault: false;
|
|
1138
|
+
enumValues: [string, ...string[]];
|
|
1139
|
+
baseColumn: never;
|
|
1140
|
+
identity: undefined;
|
|
1141
|
+
generated: undefined;
|
|
1142
|
+
}, {}, {
|
|
1143
|
+
length: number | undefined;
|
|
1144
|
+
}>;
|
|
1145
|
+
expiresAt: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
1146
|
+
name: "expires_at";
|
|
1147
|
+
tableName: "durable_signal_ids";
|
|
1148
|
+
dataType: "number";
|
|
1149
|
+
columnType: "SQLiteInteger";
|
|
1150
|
+
data: number;
|
|
1151
|
+
driverParam: number;
|
|
1152
|
+
notNull: true;
|
|
1153
|
+
hasDefault: false;
|
|
1154
|
+
isPrimaryKey: false;
|
|
1155
|
+
isAutoincrement: false;
|
|
1156
|
+
hasRuntimeDefault: false;
|
|
1157
|
+
enumValues: undefined;
|
|
1158
|
+
baseColumn: never;
|
|
1159
|
+
identity: undefined;
|
|
1160
|
+
generated: undefined;
|
|
1161
|
+
}, {}, {}>;
|
|
1162
|
+
};
|
|
1163
|
+
dialect: "sqlite";
|
|
1164
|
+
}>;
|
|
1080
1165
|
/**
|
|
1081
1166
|
* Persisted schedules (`engine.schedules`). `spec`/`state` are JSON documents the engine owns; the
|
|
1082
1167
|
* store only filters on the columns. `next_fire_at` is epoch ms, NULL when it never fires again.
|
|
@@ -2236,6 +2321,68 @@ declare const durableSchema: {
|
|
|
2236
2321
|
};
|
|
2237
2322
|
dialect: "sqlite";
|
|
2238
2323
|
}>;
|
|
2324
|
+
signalIds: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
|
|
2325
|
+
name: "durable_signal_ids";
|
|
2326
|
+
schema: undefined;
|
|
2327
|
+
columns: {
|
|
2328
|
+
token: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
2329
|
+
name: "token";
|
|
2330
|
+
tableName: "durable_signal_ids";
|
|
2331
|
+
dataType: "string";
|
|
2332
|
+
columnType: "SQLiteText";
|
|
2333
|
+
data: string;
|
|
2334
|
+
driverParam: string;
|
|
2335
|
+
notNull: true;
|
|
2336
|
+
hasDefault: false;
|
|
2337
|
+
isPrimaryKey: false;
|
|
2338
|
+
isAutoincrement: false;
|
|
2339
|
+
hasRuntimeDefault: false;
|
|
2340
|
+
enumValues: [string, ...string[]];
|
|
2341
|
+
baseColumn: never;
|
|
2342
|
+
identity: undefined;
|
|
2343
|
+
generated: undefined;
|
|
2344
|
+
}, {}, {
|
|
2345
|
+
length: number | undefined;
|
|
2346
|
+
}>;
|
|
2347
|
+
signalId: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
2348
|
+
name: "signal_id";
|
|
2349
|
+
tableName: "durable_signal_ids";
|
|
2350
|
+
dataType: "string";
|
|
2351
|
+
columnType: "SQLiteText";
|
|
2352
|
+
data: string;
|
|
2353
|
+
driverParam: string;
|
|
2354
|
+
notNull: true;
|
|
2355
|
+
hasDefault: false;
|
|
2356
|
+
isPrimaryKey: false;
|
|
2357
|
+
isAutoincrement: false;
|
|
2358
|
+
hasRuntimeDefault: false;
|
|
2359
|
+
enumValues: [string, ...string[]];
|
|
2360
|
+
baseColumn: never;
|
|
2361
|
+
identity: undefined;
|
|
2362
|
+
generated: undefined;
|
|
2363
|
+
}, {}, {
|
|
2364
|
+
length: number | undefined;
|
|
2365
|
+
}>;
|
|
2366
|
+
expiresAt: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
2367
|
+
name: "expires_at";
|
|
2368
|
+
tableName: "durable_signal_ids";
|
|
2369
|
+
dataType: "number";
|
|
2370
|
+
columnType: "SQLiteInteger";
|
|
2371
|
+
data: number;
|
|
2372
|
+
driverParam: number;
|
|
2373
|
+
notNull: true;
|
|
2374
|
+
hasDefault: false;
|
|
2375
|
+
isPrimaryKey: false;
|
|
2376
|
+
isAutoincrement: false;
|
|
2377
|
+
hasRuntimeDefault: false;
|
|
2378
|
+
enumValues: undefined;
|
|
2379
|
+
baseColumn: never;
|
|
2380
|
+
identity: undefined;
|
|
2381
|
+
generated: undefined;
|
|
2382
|
+
}, {}, {}>;
|
|
2383
|
+
};
|
|
2384
|
+
dialect: "sqlite";
|
|
2385
|
+
}>;
|
|
2239
2386
|
durableSchedules: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
|
|
2240
2387
|
name: "durable_schedules";
|
|
2241
2388
|
schema: undefined;
|
|
@@ -2442,4 +2589,4 @@ declare const durableSchema: {
|
|
|
2442
2589
|
*/
|
|
2443
2590
|
declare function durableManagedTables(): string[];
|
|
2444
2591
|
|
|
2445
|
-
export { DEFAULT_NAMESPACE, DrizzleStateStore, bufferedEvents, bufferedSignals, durableManagedTables, durableSchedules, durableSchema, runAttributes, signalWaiters, stepCheckpoints, workflowRuns };
|
|
2592
|
+
export { DEFAULT_NAMESPACE, DrizzleStateStore, bufferedEvents, bufferedSignals, durableManagedTables, durableSchedules, durableSchema, runAttributes, signalIds, signalWaiters, stepCheckpoints, workflowRuns };
|
package/dist/index.d.ts
CHANGED
|
@@ -97,6 +97,13 @@ declare class DrizzleStateStore implements StateStore {
|
|
|
97
97
|
takeBufferedSignal(token: string): Promise<{
|
|
98
98
|
payload: unknown;
|
|
99
99
|
} | null>;
|
|
100
|
+
takeOldestBufferedSignal(tokens: string[]): Promise<{
|
|
101
|
+
token: string;
|
|
102
|
+
payload: unknown;
|
|
103
|
+
} | null>;
|
|
104
|
+
claimSignalId(token: string, id: string, expiresAt: number, nowMs: number): Promise<boolean>;
|
|
105
|
+
releaseSignalId(token: string, id: string): Promise<void>;
|
|
106
|
+
deleteExpiredSignalIds(nowMs: number, limit: number): Promise<number>;
|
|
100
107
|
listBufferedSignals(tokenPrefix: string, afterId: string | undefined, limit: number): Promise<BufferedSignalRow[]>;
|
|
101
108
|
deleteBufferedSignals(ids: string[]): Promise<void>;
|
|
102
109
|
bufferEvent(input: {
|
|
@@ -1077,6 +1084,84 @@ declare const bufferedEvents: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
|
|
|
1077
1084
|
};
|
|
1078
1085
|
dialect: "sqlite";
|
|
1079
1086
|
}>;
|
|
1087
|
+
/**
|
|
1088
|
+
* Signal dedupe ids (`engine.signal(token, payload, { id })`): one row per `(token, signal_id)`,
|
|
1089
|
+
* deduplicating until `expires_at` (epoch ms). Expired rows are ignored by `claimSignalId` and
|
|
1090
|
+
* deleted by `engine.sweepExpiredSignalIds()`.
|
|
1091
|
+
*
|
|
1092
|
+
* MIGRATION (you own this adapter's migrations): `drizzle-kit generate` picks the table up from
|
|
1093
|
+
* `durableSchema`; by hand:
|
|
1094
|
+
*
|
|
1095
|
+
* ```sql
|
|
1096
|
+
* CREATE TABLE durable_signal_ids (token TEXT NOT NULL, signal_id TEXT NOT NULL,
|
|
1097
|
+
* expires_at INTEGER NOT NULL, PRIMARY KEY (token, signal_id));
|
|
1098
|
+
* CREATE INDEX durable_signal_ids_expires_at_idx ON durable_signal_ids (expires_at);
|
|
1099
|
+
* ```
|
|
1100
|
+
*
|
|
1101
|
+
* Only needed if you send signals with an `id`.
|
|
1102
|
+
*/
|
|
1103
|
+
declare const signalIds: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
|
|
1104
|
+
name: "durable_signal_ids";
|
|
1105
|
+
schema: undefined;
|
|
1106
|
+
columns: {
|
|
1107
|
+
token: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
1108
|
+
name: "token";
|
|
1109
|
+
tableName: "durable_signal_ids";
|
|
1110
|
+
dataType: "string";
|
|
1111
|
+
columnType: "SQLiteText";
|
|
1112
|
+
data: string;
|
|
1113
|
+
driverParam: string;
|
|
1114
|
+
notNull: true;
|
|
1115
|
+
hasDefault: false;
|
|
1116
|
+
isPrimaryKey: false;
|
|
1117
|
+
isAutoincrement: false;
|
|
1118
|
+
hasRuntimeDefault: false;
|
|
1119
|
+
enumValues: [string, ...string[]];
|
|
1120
|
+
baseColumn: never;
|
|
1121
|
+
identity: undefined;
|
|
1122
|
+
generated: undefined;
|
|
1123
|
+
}, {}, {
|
|
1124
|
+
length: number | undefined;
|
|
1125
|
+
}>;
|
|
1126
|
+
signalId: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
1127
|
+
name: "signal_id";
|
|
1128
|
+
tableName: "durable_signal_ids";
|
|
1129
|
+
dataType: "string";
|
|
1130
|
+
columnType: "SQLiteText";
|
|
1131
|
+
data: string;
|
|
1132
|
+
driverParam: string;
|
|
1133
|
+
notNull: true;
|
|
1134
|
+
hasDefault: false;
|
|
1135
|
+
isPrimaryKey: false;
|
|
1136
|
+
isAutoincrement: false;
|
|
1137
|
+
hasRuntimeDefault: false;
|
|
1138
|
+
enumValues: [string, ...string[]];
|
|
1139
|
+
baseColumn: never;
|
|
1140
|
+
identity: undefined;
|
|
1141
|
+
generated: undefined;
|
|
1142
|
+
}, {}, {
|
|
1143
|
+
length: number | undefined;
|
|
1144
|
+
}>;
|
|
1145
|
+
expiresAt: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
1146
|
+
name: "expires_at";
|
|
1147
|
+
tableName: "durable_signal_ids";
|
|
1148
|
+
dataType: "number";
|
|
1149
|
+
columnType: "SQLiteInteger";
|
|
1150
|
+
data: number;
|
|
1151
|
+
driverParam: number;
|
|
1152
|
+
notNull: true;
|
|
1153
|
+
hasDefault: false;
|
|
1154
|
+
isPrimaryKey: false;
|
|
1155
|
+
isAutoincrement: false;
|
|
1156
|
+
hasRuntimeDefault: false;
|
|
1157
|
+
enumValues: undefined;
|
|
1158
|
+
baseColumn: never;
|
|
1159
|
+
identity: undefined;
|
|
1160
|
+
generated: undefined;
|
|
1161
|
+
}, {}, {}>;
|
|
1162
|
+
};
|
|
1163
|
+
dialect: "sqlite";
|
|
1164
|
+
}>;
|
|
1080
1165
|
/**
|
|
1081
1166
|
* Persisted schedules (`engine.schedules`). `spec`/`state` are JSON documents the engine owns; the
|
|
1082
1167
|
* store only filters on the columns. `next_fire_at` is epoch ms, NULL when it never fires again.
|
|
@@ -2236,6 +2321,68 @@ declare const durableSchema: {
|
|
|
2236
2321
|
};
|
|
2237
2322
|
dialect: "sqlite";
|
|
2238
2323
|
}>;
|
|
2324
|
+
signalIds: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
|
|
2325
|
+
name: "durable_signal_ids";
|
|
2326
|
+
schema: undefined;
|
|
2327
|
+
columns: {
|
|
2328
|
+
token: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
2329
|
+
name: "token";
|
|
2330
|
+
tableName: "durable_signal_ids";
|
|
2331
|
+
dataType: "string";
|
|
2332
|
+
columnType: "SQLiteText";
|
|
2333
|
+
data: string;
|
|
2334
|
+
driverParam: string;
|
|
2335
|
+
notNull: true;
|
|
2336
|
+
hasDefault: false;
|
|
2337
|
+
isPrimaryKey: false;
|
|
2338
|
+
isAutoincrement: false;
|
|
2339
|
+
hasRuntimeDefault: false;
|
|
2340
|
+
enumValues: [string, ...string[]];
|
|
2341
|
+
baseColumn: never;
|
|
2342
|
+
identity: undefined;
|
|
2343
|
+
generated: undefined;
|
|
2344
|
+
}, {}, {
|
|
2345
|
+
length: number | undefined;
|
|
2346
|
+
}>;
|
|
2347
|
+
signalId: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
2348
|
+
name: "signal_id";
|
|
2349
|
+
tableName: "durable_signal_ids";
|
|
2350
|
+
dataType: "string";
|
|
2351
|
+
columnType: "SQLiteText";
|
|
2352
|
+
data: string;
|
|
2353
|
+
driverParam: string;
|
|
2354
|
+
notNull: true;
|
|
2355
|
+
hasDefault: false;
|
|
2356
|
+
isPrimaryKey: false;
|
|
2357
|
+
isAutoincrement: false;
|
|
2358
|
+
hasRuntimeDefault: false;
|
|
2359
|
+
enumValues: [string, ...string[]];
|
|
2360
|
+
baseColumn: never;
|
|
2361
|
+
identity: undefined;
|
|
2362
|
+
generated: undefined;
|
|
2363
|
+
}, {}, {
|
|
2364
|
+
length: number | undefined;
|
|
2365
|
+
}>;
|
|
2366
|
+
expiresAt: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
2367
|
+
name: "expires_at";
|
|
2368
|
+
tableName: "durable_signal_ids";
|
|
2369
|
+
dataType: "number";
|
|
2370
|
+
columnType: "SQLiteInteger";
|
|
2371
|
+
data: number;
|
|
2372
|
+
driverParam: number;
|
|
2373
|
+
notNull: true;
|
|
2374
|
+
hasDefault: false;
|
|
2375
|
+
isPrimaryKey: false;
|
|
2376
|
+
isAutoincrement: false;
|
|
2377
|
+
hasRuntimeDefault: false;
|
|
2378
|
+
enumValues: undefined;
|
|
2379
|
+
baseColumn: never;
|
|
2380
|
+
identity: undefined;
|
|
2381
|
+
generated: undefined;
|
|
2382
|
+
}, {}, {}>;
|
|
2383
|
+
};
|
|
2384
|
+
dialect: "sqlite";
|
|
2385
|
+
}>;
|
|
2239
2386
|
durableSchedules: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
|
|
2240
2387
|
name: "durable_schedules";
|
|
2241
2388
|
schema: undefined;
|
|
@@ -2442,4 +2589,4 @@ declare const durableSchema: {
|
|
|
2442
2589
|
*/
|
|
2443
2590
|
declare function durableManagedTables(): string[];
|
|
2444
2591
|
|
|
2445
|
-
export { DEFAULT_NAMESPACE, DrizzleStateStore, bufferedEvents, bufferedSignals, durableManagedTables, durableSchedules, durableSchema, runAttributes, signalWaiters, stepCheckpoints, workflowRuns };
|
|
2592
|
+
export { DEFAULT_NAMESPACE, DrizzleStateStore, bufferedEvents, bufferedSignals, durableManagedTables, durableSchedules, durableSchema, runAttributes, signalIds, signalWaiters, stepCheckpoints, workflowRuns };
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// src/drizzle-state-store.ts
|
|
5
|
-
import { RUN_VALUE_FACET_SCAN, SINGLETON_ACTIVE_STATUSES, TERMINAL_RUN_STATUSES, attributePredicateOperands, axisIsRunColumn, clearTerminalSingletonAdmission, mergeRunFacetRows, mergeRunValueFacetRows, normalizeAttributeRows, parseDuration, runValueFacetsFromRuns, singletonAdmissionDenialPatch, singletonAdmissionTags } from "@dudousxd/nestjs-durable-core";
|
|
5
|
+
import { LIFECYCLE_REGISTRY_WORKFLOW, RUN_VALUE_FACET_SCAN, SINGLETON_ACTIVE_STATUSES, TERMINAL_RUN_STATUSES, attributePredicateOperands, axisIsRunColumn, clearTerminalSingletonAdmission, mergeRunFacetRows, mergeRunValueFacetRows, normalizeAttributeRows, parseDuration, retentionKeeps, runValueFacetsFromRuns, singletonAdmissionDenialPatch, singletonAdmissionTags } from "@dudousxd/nestjs-durable-core";
|
|
6
6
|
import { and, asc, desc, eq, exists, getTableColumns, gt, gte, inArray, isNotNull, isNull, like, lt, lte, notInArray, or, sql } from "drizzle-orm";
|
|
7
7
|
|
|
8
8
|
// src/schema.ts
|
|
@@ -174,6 +174,20 @@ var bufferedEvents = sqliteTable("durable_buffered_events", {
|
|
|
174
174
|
}),
|
|
175
175
|
publishedAt: integer("published_at").notNull()
|
|
176
176
|
});
|
|
177
|
+
var signalIds = sqliteTable("durable_signal_ids", {
|
|
178
|
+
token: text("token").notNull(),
|
|
179
|
+
signalId: text("signal_id").notNull(),
|
|
180
|
+
expiresAt: integer("expires_at").notNull()
|
|
181
|
+
}, (t) => [
|
|
182
|
+
primaryKey({
|
|
183
|
+
columns: [
|
|
184
|
+
t.token,
|
|
185
|
+
t.signalId
|
|
186
|
+
]
|
|
187
|
+
}),
|
|
188
|
+
// The sweep's "expired by T" scan.
|
|
189
|
+
index("durable_signal_ids_expires_at_idx").on(t.expiresAt)
|
|
190
|
+
]);
|
|
177
191
|
var durableSchedules = sqliteTable(
|
|
178
192
|
"durable_schedules",
|
|
179
193
|
{
|
|
@@ -208,6 +222,7 @@ var durableSchema = {
|
|
|
208
222
|
signalWaiters,
|
|
209
223
|
bufferedSignals,
|
|
210
224
|
bufferedEvents,
|
|
225
|
+
signalIds,
|
|
211
226
|
durableSchedules
|
|
212
227
|
};
|
|
213
228
|
function durableManagedTables() {
|
|
@@ -216,6 +231,9 @@ function durableManagedTables() {
|
|
|
216
231
|
__name(durableManagedTables, "durableManagedTables");
|
|
217
232
|
|
|
218
233
|
// src/drizzle-state-store.ts
|
|
234
|
+
var RETENTION_EXCLUDED = [
|
|
235
|
+
LIFECYCLE_REGISTRY_WORKFLOW
|
|
236
|
+
];
|
|
219
237
|
function anyOf(conditions) {
|
|
220
238
|
const present = conditions.filter((c) => c !== void 0);
|
|
221
239
|
return present.length ? or(...present) : sql`1 = 0`;
|
|
@@ -324,23 +342,26 @@ var DrizzleStateStore = class {
|
|
|
324
342
|
if (policy.maxAge == null && policy.maxCount == null) return 0;
|
|
325
343
|
const scoped = this.runFilters({
|
|
326
344
|
...policy.scope ?? {},
|
|
327
|
-
statuses
|
|
345
|
+
statuses,
|
|
346
|
+
excludeWorkflows: RETENTION_EXCLUDED
|
|
328
347
|
});
|
|
329
348
|
const ids = /* @__PURE__ */ new Set();
|
|
330
349
|
if (policy.maxAge != null) {
|
|
331
350
|
const cutoff = nowMs - parseDuration(policy.maxAge);
|
|
332
351
|
const rows = await this.db.select({
|
|
333
|
-
id: workflowRuns.id
|
|
352
|
+
id: workflowRuns.id,
|
|
353
|
+
tags: workflowRuns.tags
|
|
334
354
|
}).from(workflowRuns).where(and(...scoped, lt(workflowRuns.updatedAt, cutoff))).orderBy(asc(workflowRuns.updatedAt)).limit(limit);
|
|
335
|
-
for (const r of rows) ids.add(r.id);
|
|
355
|
+
for (const r of rows) if (!retentionKeeps(r.tags)) ids.add(r.id);
|
|
336
356
|
}
|
|
337
357
|
if (policy.maxCount != null && ids.size < limit) {
|
|
338
358
|
const rows = await this.db.select({
|
|
339
|
-
id: workflowRuns.id
|
|
359
|
+
id: workflowRuns.id,
|
|
360
|
+
tags: workflowRuns.tags
|
|
340
361
|
}).from(workflowRuns).where(and(...scoped)).orderBy(desc(workflowRuns.updatedAt), desc(workflowRuns.id)).limit(limit).offset(policy.maxCount);
|
|
341
362
|
for (const r of rows) {
|
|
342
363
|
if (ids.size >= limit) break;
|
|
343
|
-
ids.add(r.id);
|
|
364
|
+
if (!retentionKeeps(r.tags)) ids.add(r.id);
|
|
344
365
|
}
|
|
345
366
|
}
|
|
346
367
|
const doomed = [
|
|
@@ -589,6 +610,8 @@ var DrizzleStateStore = class {
|
|
|
589
610
|
// The plural form of each axis below: ORed within itself, ANDed with everything else, and an
|
|
590
611
|
// empty set matches nothing — the same contract `statuses` already had.
|
|
591
612
|
query.workflows ? anyOf(query.workflows.map((w) => eq(workflowRuns.workflow, w))) : void 0,
|
|
613
|
+
query.excludeWorkflows?.length ? notInArray(workflowRuns.workflow, query.excludeWorkflows) : void 0,
|
|
614
|
+
query.updatedAfter !== void 0 ? gte(workflowRuns.updatedAt, query.updatedAfter) : void 0,
|
|
592
615
|
// The tenant boundary, ANDed with everything else. This is not only a dashboard facet: it is
|
|
593
616
|
// the fourth namespace-scoped worker path, because `engine.sweepTimeouts` cancels runs past
|
|
594
617
|
// their `executionTimeout` via `listRuns({ workflow, status, namespace })` — unscoped here, a
|
|
@@ -935,6 +958,51 @@ var DrizzleStateStore = class {
|
|
|
935
958
|
payload: row.payload ?? void 0
|
|
936
959
|
};
|
|
937
960
|
}
|
|
961
|
+
async takeOldestBufferedSignal(tokens) {
|
|
962
|
+
if (tokens.length === 0) return null;
|
|
963
|
+
const oldest = this.db.select({
|
|
964
|
+
id: bufferedSignals.id
|
|
965
|
+
}).from(bufferedSignals).where(inArray(bufferedSignals.token, [
|
|
966
|
+
...new Set(tokens)
|
|
967
|
+
])).orderBy(asc(bufferedSignals.id)).limit(1);
|
|
968
|
+
const rows = await this.db.delete(bufferedSignals).where(inArray(bufferedSignals.id, oldest)).returning({
|
|
969
|
+
token: bufferedSignals.token,
|
|
970
|
+
payload: bufferedSignals.payload
|
|
971
|
+
});
|
|
972
|
+
const row = rows[0];
|
|
973
|
+
return row ? {
|
|
974
|
+
token: row.token,
|
|
975
|
+
payload: row.payload ?? void 0
|
|
976
|
+
} : null;
|
|
977
|
+
}
|
|
978
|
+
async claimSignalId(token, id, expiresAt, nowMs) {
|
|
979
|
+
const rows = await this.db.insert(signalIds).values({
|
|
980
|
+
token,
|
|
981
|
+
signalId: id,
|
|
982
|
+
expiresAt
|
|
983
|
+
}).onConflictDoUpdate({
|
|
984
|
+
target: [
|
|
985
|
+
signalIds.token,
|
|
986
|
+
signalIds.signalId
|
|
987
|
+
],
|
|
988
|
+
set: {
|
|
989
|
+
expiresAt
|
|
990
|
+
},
|
|
991
|
+
setWhere: lte(signalIds.expiresAt, nowMs)
|
|
992
|
+
}).returning({
|
|
993
|
+
token: signalIds.token
|
|
994
|
+
});
|
|
995
|
+
return rows.length > 0;
|
|
996
|
+
}
|
|
997
|
+
async releaseSignalId(token, id) {
|
|
998
|
+
await this.db.delete(signalIds).where(and(eq(signalIds.token, token), eq(signalIds.signalId, id)));
|
|
999
|
+
}
|
|
1000
|
+
async deleteExpiredSignalIds(nowMs, limit) {
|
|
1001
|
+
const rows = await this.db.delete(signalIds).where(sql`(${signalIds.token}, ${signalIds.signalId}) in (select ${signalIds.token}, ${signalIds.signalId} from ${signalIds} where ${signalIds.expiresAt} <= ${nowMs} limit ${limit})`).returning({
|
|
1002
|
+
token: signalIds.token
|
|
1003
|
+
});
|
|
1004
|
+
return rows.length;
|
|
1005
|
+
}
|
|
938
1006
|
async listBufferedSignals(tokenPrefix, afterId, limit) {
|
|
939
1007
|
const rows = await this.db.select().from(bufferedSignals).where(and(like(bufferedSignals.token, `${tokenPrefix}%`), afterId !== void 0 ? gt(bufferedSignals.id, Number(afterId)) : void 0)).orderBy(asc(bufferedSignals.id)).limit(limit);
|
|
940
1008
|
return rows.filter((r) => r.token.startsWith(tokenPrefix)).map((r) => ({
|
|
@@ -1208,6 +1276,7 @@ export {
|
|
|
1208
1276
|
durableSchedules,
|
|
1209
1277
|
durableSchema,
|
|
1210
1278
|
runAttributes,
|
|
1279
|
+
signalIds,
|
|
1211
1280
|
signalWaiters,
|
|
1212
1281
|
stepCheckpoints,
|
|
1213
1282
|
workflowRuns
|