durability 5.1.0 → 5.2.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/README.md +145 -12
- package/dist/{durability-alarms.d.ts → alarms/index.d.ts} +13 -5
- package/dist/{durability-alarms.js → alarms/index.js} +69 -55
- package/dist/alarms/migrations.d.ts +9 -0
- package/dist/alarms/migrations.js +133 -0
- package/dist/experimental.d.ts +10 -10
- package/dist/experimental.js +7 -7
- package/dist/{fanout.d.ts → fanout/index.d.ts} +13 -6
- package/dist/{fanout.js → fanout/index.js} +54 -46
- package/dist/fanout/migrations.d.ts +9 -0
- package/dist/fanout/migrations.js +181 -0
- package/dist/{stored-message.d.ts → fanout/stored-message.d.ts} +1 -1
- package/dist/index.d.ts +14 -9
- package/dist/index.js +13 -8
- package/dist/{log.d.ts → log/index.d.ts} +15 -3
- package/dist/{log.js → log/index.js} +152 -124
- package/dist/log/migrations.d.ts +18 -0
- package/dist/log/migrations.js +297 -0
- package/dist/{memoize.d.ts → memoize/index.d.ts} +1 -1
- package/dist/{memoize.js → memoize/index.js} +14 -11
- package/dist/memoize/migrations.d.ts +10 -0
- package/dist/memoize/migrations.js +21 -0
- package/dist/migrations.d.ts +0 -111
- package/dist/migrations.js +0 -612
- package/dist/{durability.d.ts → operations/index.d.ts} +13 -5
- package/dist/{durability.js → operations/index.js} +59 -47
- package/dist/operations/migrations.d.ts +10 -0
- package/dist/operations/migrations.js +150 -0
- package/dist/{outbox.d.ts → outbox/index.d.ts} +4 -4
- package/dist/{outbox.js → outbox/index.js} +16 -60
- package/dist/outbox/migrations.d.ts +9 -0
- package/dist/outbox/migrations.js +43 -0
- package/dist/{routing-client.js → routing/client.js} +1 -1
- package/dist/{routing.d.ts → routing/index.d.ts} +3 -3
- package/dist/{routing.js → routing/index.js} +3 -3
- package/dist/{load.d.ts → routing/load.d.ts} +1 -1
- package/dist/{schedule.d.ts → schedule/index.d.ts} +16 -8
- package/dist/{schedule.js → schedule/index.js} +65 -49
- package/dist/schedule/migrations.d.ts +9 -0
- package/dist/schedule/migrations.js +118 -0
- package/dist/{scheduler.d.ts → scheduler/index.d.ts} +75 -25
- package/dist/{scheduler.js → scheduler/index.js} +300 -63
- package/dist/{semaphore-client.d.ts → semaphore/client.d.ts} +1 -1
- package/dist/{semaphore-client.js → semaphore/client.js} +2 -2
- package/dist/{semaphore.d.ts → semaphore/index.d.ts} +10 -10
- package/dist/{semaphore.js → semaphore/index.js} +7 -7
- package/dist/{semaphore-leases.d.ts → semaphore/leases.d.ts} +17 -6
- package/dist/{semaphore-leases.js → semaphore/leases.js} +28 -12
- package/dist/semaphore/migrations.d.ts +18 -0
- package/dist/semaphore/migrations.js +444 -0
- package/dist/{semaphore-protocol.d.ts → semaphore/protocol.d.ts} +16 -8
- package/dist/{semaphore-protocol.js → semaphore/protocol.js} +37 -14
- package/dist/{semaphore-queue-store.d.ts → semaphore/queue-store.d.ts} +12 -6
- package/dist/{semaphore-queue-store.js → semaphore/queue-store.js} +69 -61
- package/dist/{semaphore-queue.d.ts → semaphore/queue.d.ts} +15 -5
- package/dist/{semaphore-queue.js → semaphore/queue.js} +105 -46
- package/dist/{semaphore-server.d.ts → semaphore/server.d.ts} +12 -4
- package/dist/{semaphore-server.js → semaphore/server.js} +51 -24
- package/dist/{semaphore-store.d.ts → semaphore/store.d.ts} +8 -3
- package/dist/{semaphore-store.js → semaphore/store.js} +35 -33
- package/dist/{client.d.ts → socket/client.d.ts} +3 -3
- package/dist/{client.js → socket/client.js} +4 -4
- package/dist/{socket.d.ts → socket/index.d.ts} +15 -4
- package/dist/{socket.js → socket/index.js} +66 -20
- package/dist/socket/migrations.d.ts +9 -0
- package/dist/socket/migrations.js +57 -0
- package/dist/{socket-protocol.d.ts → socket/protocol.d.ts} +1 -1
- package/dist/storage.d.ts +4 -0
- package/dist/storage.js +13 -6
- package/dist/{topology-client.d.ts → topology/client.d.ts} +2 -2
- package/dist/{topology-client.js → topology/client.js} +3 -3
- package/dist/{topology.d.ts → topology/index.d.ts} +17 -7
- package/dist/{topology.js → topology/index.js} +92 -58
- package/dist/topology/migrations.d.ts +10 -0
- package/dist/topology/migrations.js +138 -0
- package/dist/{tracker.d.ts → tracker/index.d.ts} +3 -3
- package/dist/{tracker.js → tracker/index.js} +2 -2
- package/package.json +11 -11
- /package/dist/{stored-message.js → fanout/stored-message.js} +0 -0
- /package/dist/{routing-client.d.ts → routing/client.d.ts} +0 -0
- /package/dist/{load.js → routing/load.js} +0 -0
- /package/dist/{socket-protocol.js → socket/protocol.js} +0 -0
- /package/dist/{topology-snapshot.d.ts → topology/snapshot.d.ts} +0 -0
- /package/dist/{topology-snapshot.js → topology/snapshot.js} +0 -0
- /package/dist/{tracked-source.d.ts → tracker/source.d.ts} +0 -0
- /package/dist/{tracked-source.js → tracker/source.js} +0 -0
package/dist/migrations.js
CHANGED
|
@@ -1,618 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { traceStorage } from './dev.js';
|
|
3
3
|
export const migrationTableName = 'durability_migrations';
|
|
4
|
-
/**
|
|
5
|
-
* Ordered SQLite migrations for the `durability_calls` table owned by
|
|
6
|
-
* {@link Durability}. Applied automatically on construction and tracked in the
|
|
7
|
-
* namespaced `durability_migrations` table alongside application migrations.
|
|
8
|
-
*/
|
|
9
|
-
export const durabilityOperationMigrations = [
|
|
10
|
-
{
|
|
11
|
-
name: 'durability_0001_create_calls',
|
|
12
|
-
up: `
|
|
13
|
-
CREATE TABLE IF NOT EXISTS durability_calls (
|
|
14
|
-
id TEXT PRIMARY KEY,
|
|
15
|
-
operation TEXT NOT NULL,
|
|
16
|
-
payload TEXT NOT NULL,
|
|
17
|
-
status TEXT NOT NULL CHECK (status IN ('pending', 'completed', 'failed')),
|
|
18
|
-
result TEXT,
|
|
19
|
-
attempt INTEGER NOT NULL DEFAULT 0,
|
|
20
|
-
next_attempt_at INTEGER NOT NULL,
|
|
21
|
-
last_error TEXT,
|
|
22
|
-
last_error_name TEXT,
|
|
23
|
-
completed_at INTEGER
|
|
24
|
-
);
|
|
25
|
-
`,
|
|
26
|
-
down: 'DROP TABLE IF EXISTS durability_calls;',
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
name: 'durability_0002_pending_index',
|
|
30
|
-
up: `
|
|
31
|
-
CREATE INDEX IF NOT EXISTS durability_calls_pending_idx
|
|
32
|
-
ON durability_calls (status, next_attempt_at);
|
|
33
|
-
`,
|
|
34
|
-
down: 'DROP INDEX IF EXISTS durability_calls_pending_idx;',
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
name: 'durability_0004_calls_generation_and_created_at',
|
|
38
|
-
up: `
|
|
39
|
-
DROP INDEX IF EXISTS durability_calls_pending_idx;
|
|
40
|
-
ALTER TABLE durability_calls RENAME TO durability_calls_v3;
|
|
41
|
-
CREATE TABLE durability_calls (
|
|
42
|
-
id TEXT PRIMARY KEY,
|
|
43
|
-
operation TEXT NOT NULL,
|
|
44
|
-
payload TEXT NOT NULL,
|
|
45
|
-
status TEXT NOT NULL CHECK (status IN ('pending', 'completed', 'failed')),
|
|
46
|
-
result TEXT,
|
|
47
|
-
attempt INTEGER NOT NULL DEFAULT 0,
|
|
48
|
-
next_attempt_at INTEGER NOT NULL,
|
|
49
|
-
last_error TEXT,
|
|
50
|
-
last_error_name TEXT,
|
|
51
|
-
completed_at INTEGER,
|
|
52
|
-
generation_id TEXT NOT NULL DEFAULT 'legacy',
|
|
53
|
-
created_at INTEGER NOT NULL DEFAULT (CAST(unixepoch('subsec') * 1000 AS INTEGER))
|
|
54
|
-
);
|
|
55
|
-
INSERT INTO durability_calls
|
|
56
|
-
SELECT id, operation, payload, status, result, attempt, next_attempt_at,
|
|
57
|
-
last_error, last_error_name, completed_at, 'legacy:' || id,
|
|
58
|
-
CAST(unixepoch('subsec') * 1000 AS INTEGER)
|
|
59
|
-
FROM durability_calls_v3;
|
|
60
|
-
DROP TABLE durability_calls_v3;
|
|
61
|
-
CREATE INDEX durability_calls_pending_idx
|
|
62
|
-
ON durability_calls (status, next_attempt_at);
|
|
63
|
-
CREATE INDEX durability_calls_created_idx
|
|
64
|
-
ON durability_calls (created_at);
|
|
65
|
-
`,
|
|
66
|
-
down: `
|
|
67
|
-
DROP INDEX IF EXISTS durability_calls_pending_idx;
|
|
68
|
-
DROP INDEX IF EXISTS durability_calls_created_idx;
|
|
69
|
-
ALTER TABLE durability_calls RENAME TO durability_calls_v4;
|
|
70
|
-
CREATE TABLE durability_calls (
|
|
71
|
-
id TEXT PRIMARY KEY,
|
|
72
|
-
operation TEXT NOT NULL,
|
|
73
|
-
payload TEXT NOT NULL,
|
|
74
|
-
status TEXT NOT NULL CHECK (status IN ('pending', 'completed', 'failed')),
|
|
75
|
-
result TEXT,
|
|
76
|
-
attempt INTEGER NOT NULL DEFAULT 0,
|
|
77
|
-
next_attempt_at INTEGER NOT NULL,
|
|
78
|
-
last_error TEXT,
|
|
79
|
-
last_error_name TEXT,
|
|
80
|
-
completed_at INTEGER
|
|
81
|
-
);
|
|
82
|
-
INSERT INTO durability_calls
|
|
83
|
-
SELECT id, operation, payload, status, result, attempt, next_attempt_at,
|
|
84
|
-
last_error, last_error_name, completed_at
|
|
85
|
-
FROM durability_calls_v4;
|
|
86
|
-
DROP TABLE durability_calls_v4;
|
|
87
|
-
CREATE INDEX durability_calls_pending_idx
|
|
88
|
-
ON durability_calls (status, next_attempt_at);
|
|
89
|
-
`,
|
|
90
|
-
},
|
|
91
|
-
];
|
|
92
|
-
/**
|
|
93
|
-
* Ordered SQLite migrations for the `durability_alarms` table owned by
|
|
94
|
-
* {@link DurabilityAlarms}. Applied automatically on construction.
|
|
95
|
-
*/
|
|
96
|
-
export const durabilityNamedAlarmMigrations = [
|
|
97
|
-
{
|
|
98
|
-
name: 'durability_0003_create_alarms',
|
|
99
|
-
up: `
|
|
100
|
-
CREATE TABLE IF NOT EXISTS durability_alarms (
|
|
101
|
-
name TEXT PRIMARY KEY,
|
|
102
|
-
generation_id TEXT NOT NULL,
|
|
103
|
-
status TEXT NOT NULL CHECK (status IN ('pending', 'failed')),
|
|
104
|
-
scheduled_at INTEGER NOT NULL,
|
|
105
|
-
next_attempt_at INTEGER NOT NULL,
|
|
106
|
-
attempt INTEGER NOT NULL DEFAULT 0,
|
|
107
|
-
last_error TEXT,
|
|
108
|
-
last_error_name TEXT
|
|
109
|
-
);
|
|
110
|
-
CREATE INDEX IF NOT EXISTS durability_alarms_pending_idx
|
|
111
|
-
ON durability_alarms (status, next_attempt_at);
|
|
112
|
-
`,
|
|
113
|
-
down: `
|
|
114
|
-
DROP INDEX IF EXISTS durability_alarms_pending_idx;
|
|
115
|
-
DROP TABLE IF EXISTS durability_alarms;
|
|
116
|
-
`,
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
name: 'durability_0004_alarms_generation_and_created_at',
|
|
120
|
-
up: `
|
|
121
|
-
DROP INDEX IF EXISTS durability_alarms_pending_idx;
|
|
122
|
-
ALTER TABLE durability_alarms RENAME TO durability_alarms_v3;
|
|
123
|
-
CREATE TABLE durability_alarms (
|
|
124
|
-
name TEXT PRIMARY KEY,
|
|
125
|
-
generation_id TEXT NOT NULL,
|
|
126
|
-
status TEXT NOT NULL CHECK (status IN ('pending', 'failed')),
|
|
127
|
-
scheduled_at INTEGER NOT NULL,
|
|
128
|
-
next_attempt_at INTEGER NOT NULL,
|
|
129
|
-
attempt INTEGER NOT NULL DEFAULT 0,
|
|
130
|
-
last_error TEXT,
|
|
131
|
-
last_error_name TEXT,
|
|
132
|
-
created_at INTEGER NOT NULL DEFAULT (CAST(unixepoch('subsec') * 1000 AS INTEGER))
|
|
133
|
-
);
|
|
134
|
-
INSERT INTO durability_alarms
|
|
135
|
-
SELECT name, generation_id, status, scheduled_at, next_attempt_at,
|
|
136
|
-
attempt, last_error, last_error_name,
|
|
137
|
-
CAST(unixepoch('subsec') * 1000 AS INTEGER)
|
|
138
|
-
FROM durability_alarms_v3;
|
|
139
|
-
DROP TABLE durability_alarms_v3;
|
|
140
|
-
CREATE INDEX durability_alarms_pending_idx
|
|
141
|
-
ON durability_alarms (status, next_attempt_at);
|
|
142
|
-
CREATE INDEX durability_alarms_created_idx
|
|
143
|
-
ON durability_alarms (created_at);
|
|
144
|
-
`,
|
|
145
|
-
down: `
|
|
146
|
-
DROP INDEX IF EXISTS durability_alarms_pending_idx;
|
|
147
|
-
DROP INDEX IF EXISTS durability_alarms_created_idx;
|
|
148
|
-
ALTER TABLE durability_alarms RENAME TO durability_alarms_v4;
|
|
149
|
-
CREATE TABLE durability_alarms (
|
|
150
|
-
name TEXT PRIMARY KEY,
|
|
151
|
-
generation_id TEXT NOT NULL,
|
|
152
|
-
status TEXT NOT NULL CHECK (status IN ('pending', 'failed')),
|
|
153
|
-
scheduled_at INTEGER NOT NULL,
|
|
154
|
-
next_attempt_at INTEGER NOT NULL,
|
|
155
|
-
attempt INTEGER NOT NULL DEFAULT 0,
|
|
156
|
-
last_error TEXT,
|
|
157
|
-
last_error_name TEXT
|
|
158
|
-
);
|
|
159
|
-
INSERT INTO durability_alarms
|
|
160
|
-
SELECT name, generation_id, status, scheduled_at, next_attempt_at,
|
|
161
|
-
attempt, last_error, last_error_name
|
|
162
|
-
FROM durability_alarms_v4;
|
|
163
|
-
DROP TABLE durability_alarms_v4;
|
|
164
|
-
CREATE INDEX durability_alarms_pending_idx
|
|
165
|
-
ON durability_alarms (status, next_attempt_at);
|
|
166
|
-
`,
|
|
167
|
-
},
|
|
168
|
-
];
|
|
169
|
-
/**
|
|
170
|
-
* Ordered SQLite migrations for `durability_memos`, the memoized results that
|
|
171
|
-
* {@link Durability} and {@link DurabilityAlarms} share. Applied by whichever
|
|
172
|
-
* helper is constructed first.
|
|
173
|
-
*/
|
|
174
|
-
export const durabilityMemoMigrations = [
|
|
175
|
-
{
|
|
176
|
-
name: 'durability_0012_create_memos',
|
|
177
|
-
up: `
|
|
178
|
-
CREATE TABLE IF NOT EXISTS durability_memos (
|
|
179
|
-
owner TEXT NOT NULL,
|
|
180
|
-
key TEXT NOT NULL,
|
|
181
|
-
generation_id TEXT NOT NULL,
|
|
182
|
-
memo_key TEXT NOT NULL,
|
|
183
|
-
result TEXT NOT NULL,
|
|
184
|
-
PRIMARY KEY (owner, key, generation_id, memo_key)
|
|
185
|
-
);
|
|
186
|
-
`,
|
|
187
|
-
down: 'DROP TABLE IF EXISTS durability_memos;',
|
|
188
|
-
},
|
|
189
|
-
];
|
|
190
|
-
/**
|
|
191
|
-
* Ordered SQLite migrations for fanout manifests and deliveries. Applied
|
|
192
|
-
* automatically on construction.
|
|
193
|
-
*/
|
|
194
|
-
export const durabilityFanoutMigrations = [
|
|
195
|
-
{
|
|
196
|
-
name: 'durability_0005_create_fanout',
|
|
197
|
-
up: `
|
|
198
|
-
CREATE TABLE IF NOT EXISTS durability_fanout_messages (
|
|
199
|
-
key TEXT PRIMARY KEY,
|
|
200
|
-
id TEXT NOT NULL,
|
|
201
|
-
payload TEXT NOT NULL,
|
|
202
|
-
targets TEXT NOT NULL,
|
|
203
|
-
remaining INTEGER NOT NULL,
|
|
204
|
-
seq INTEGER NOT NULL,
|
|
205
|
-
created_at INTEGER NOT NULL,
|
|
206
|
-
generation_id TEXT NOT NULL
|
|
207
|
-
);
|
|
208
|
-
CREATE TABLE IF NOT EXISTS durability_fanout_deliveries (
|
|
209
|
-
id TEXT PRIMARY KEY,
|
|
210
|
-
message_key TEXT NOT NULL,
|
|
211
|
-
target_id TEXT NOT NULL,
|
|
212
|
-
seq INTEGER NOT NULL,
|
|
213
|
-
status TEXT NOT NULL CHECK (status IN ('pending')),
|
|
214
|
-
phase TEXT NOT NULL CHECK (phase IN ('delivery', 'dead_letter')),
|
|
215
|
-
attempt INTEGER NOT NULL DEFAULT 0,
|
|
216
|
-
next_attempt_at INTEGER NOT NULL,
|
|
217
|
-
last_error TEXT,
|
|
218
|
-
last_error_name TEXT,
|
|
219
|
-
created_at INTEGER NOT NULL,
|
|
220
|
-
generation_id TEXT NOT NULL,
|
|
221
|
-
dead_lettered_at INTEGER,
|
|
222
|
-
dead_letter_reason TEXT CHECK (dead_letter_reason IN ('explicit', 'exhausted'))
|
|
223
|
-
);
|
|
224
|
-
CREATE INDEX IF NOT EXISTS durability_fanout_deliveries_due_idx
|
|
225
|
-
ON durability_fanout_deliveries
|
|
226
|
-
(target_id, phase, status, attempt, seq, next_attempt_at);
|
|
227
|
-
CREATE INDEX IF NOT EXISTS durability_fanout_deliveries_pending_idx
|
|
228
|
-
ON durability_fanout_deliveries (phase, status, next_attempt_at);
|
|
229
|
-
CREATE INDEX IF NOT EXISTS durability_fanout_deliveries_created_idx
|
|
230
|
-
ON durability_fanout_deliveries (created_at);
|
|
231
|
-
CREATE TABLE IF NOT EXISTS durability_fanout_seq (
|
|
232
|
-
id INTEGER PRIMARY KEY CHECK (id = 1),
|
|
233
|
-
next_seq INTEGER NOT NULL
|
|
234
|
-
);
|
|
235
|
-
INSERT OR IGNORE INTO durability_fanout_seq (id, next_seq) VALUES (1, 0);
|
|
236
|
-
`,
|
|
237
|
-
down: `
|
|
238
|
-
DROP INDEX IF EXISTS durability_fanout_deliveries_due_idx;
|
|
239
|
-
DROP INDEX IF EXISTS durability_fanout_deliveries_pending_idx;
|
|
240
|
-
DROP INDEX IF EXISTS durability_fanout_deliveries_created_idx;
|
|
241
|
-
DROP TABLE IF EXISTS durability_fanout_deliveries;
|
|
242
|
-
DROP TABLE IF EXISTS durability_fanout_messages;
|
|
243
|
-
DROP TABLE IF EXISTS durability_fanout_seq;
|
|
244
|
-
`,
|
|
245
|
-
},
|
|
246
|
-
];
|
|
247
|
-
/**
|
|
248
|
-
* Ordered SQLite migrations for the outbound event log owned by
|
|
249
|
-
* {@link DurabilitySocket}. Applied automatically on construction.
|
|
250
|
-
*/
|
|
251
|
-
export const durabilitySocketMigrations = [
|
|
252
|
-
{
|
|
253
|
-
name: 'durability_0006_create_socket_events',
|
|
254
|
-
up: `
|
|
255
|
-
CREATE TABLE IF NOT EXISTS durability_socket_events (
|
|
256
|
-
seq INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
257
|
-
name TEXT NOT NULL,
|
|
258
|
-
payload TEXT NOT NULL,
|
|
259
|
-
created_at INTEGER NOT NULL
|
|
260
|
-
);
|
|
261
|
-
`,
|
|
262
|
-
down: 'DROP TABLE IF EXISTS durability_socket_events;',
|
|
263
|
-
},
|
|
264
|
-
];
|
|
265
|
-
/**
|
|
266
|
-
* Ordered SQLite migrations for the retained log and its consumer cursors.
|
|
267
|
-
* Applied automatically on construction.
|
|
268
|
-
*/
|
|
269
|
-
export const durabilityLogMigrations = [
|
|
270
|
-
{
|
|
271
|
-
name: 'durability_0007_create_log',
|
|
272
|
-
up: `
|
|
273
|
-
CREATE TABLE IF NOT EXISTS durability_log_records (
|
|
274
|
-
"offset" INTEGER PRIMARY KEY,
|
|
275
|
-
dedup_key TEXT NOT NULL UNIQUE,
|
|
276
|
-
payload TEXT NOT NULL,
|
|
277
|
-
bytes INTEGER NOT NULL,
|
|
278
|
-
appended_at INTEGER NOT NULL
|
|
279
|
-
);
|
|
280
|
-
CREATE INDEX IF NOT EXISTS durability_log_records_appended_idx
|
|
281
|
-
ON durability_log_records (appended_at, "offset");
|
|
282
|
-
CREATE TABLE IF NOT EXISTS durability_log_cursors (
|
|
283
|
-
consumer TEXT PRIMARY KEY,
|
|
284
|
-
"offset" INTEGER NOT NULL,
|
|
285
|
-
committed_at INTEGER NOT NULL
|
|
286
|
-
);
|
|
287
|
-
CREATE TABLE IF NOT EXISTS durability_log_segments (
|
|
288
|
-
first_offset INTEGER PRIMARY KEY,
|
|
289
|
-
last_offset INTEGER NOT NULL,
|
|
290
|
-
locator TEXT NOT NULL,
|
|
291
|
-
bytes INTEGER NOT NULL,
|
|
292
|
-
flushed_at INTEGER NOT NULL
|
|
293
|
-
);
|
|
294
|
-
CREATE TABLE IF NOT EXISTS durability_log_seq (
|
|
295
|
-
id INTEGER PRIMARY KEY CHECK (id = 1),
|
|
296
|
-
next_offset INTEGER NOT NULL,
|
|
297
|
-
total_bytes INTEGER NOT NULL
|
|
298
|
-
);
|
|
299
|
-
INSERT OR IGNORE INTO durability_log_seq (id, next_offset, total_bytes)
|
|
300
|
-
VALUES (1, 0, 0);
|
|
301
|
-
`,
|
|
302
|
-
down: `
|
|
303
|
-
DROP INDEX IF EXISTS durability_log_records_appended_idx;
|
|
304
|
-
DROP TABLE IF EXISTS durability_log_records;
|
|
305
|
-
DROP TABLE IF EXISTS durability_log_cursors;
|
|
306
|
-
DROP TABLE IF EXISTS durability_log_segments;
|
|
307
|
-
DROP TABLE IF EXISTS durability_log_seq;
|
|
308
|
-
`,
|
|
309
|
-
},
|
|
310
|
-
];
|
|
311
|
-
/**
|
|
312
|
-
* Leases let several workers consume one log in parallel without handing the
|
|
313
|
-
* same offsets to two of them. Applied automatically when leases are enabled.
|
|
314
|
-
*/
|
|
315
|
-
export const durabilityLogLeaseMigrations = [
|
|
316
|
-
{
|
|
317
|
-
name: 'durability_0008_create_log_leases',
|
|
318
|
-
up: `
|
|
319
|
-
CREATE TABLE IF NOT EXISTS durability_log_leases (
|
|
320
|
-
batch_id TEXT PRIMARY KEY,
|
|
321
|
-
consumer TEXT NOT NULL,
|
|
322
|
-
first_offset INTEGER NOT NULL,
|
|
323
|
-
last_offset INTEGER NOT NULL,
|
|
324
|
-
state TEXT NOT NULL
|
|
325
|
-
CHECK (state IN ('active', 'pending', 'acked', 'skipped')),
|
|
326
|
-
attempt INTEGER NOT NULL,
|
|
327
|
-
expires_at INTEGER NOT NULL,
|
|
328
|
-
created_at INTEGER NOT NULL
|
|
329
|
-
);
|
|
330
|
-
CREATE INDEX IF NOT EXISTS durability_log_leases_claim_idx
|
|
331
|
-
ON durability_log_leases (consumer, state, expires_at, first_offset);
|
|
332
|
-
CREATE INDEX IF NOT EXISTS durability_log_leases_order_idx
|
|
333
|
-
ON durability_log_leases (consumer, first_offset);
|
|
334
|
-
CREATE TABLE IF NOT EXISTS durability_log_allocations (
|
|
335
|
-
consumer TEXT PRIMARY KEY,
|
|
336
|
-
allocated_offset INTEGER NOT NULL
|
|
337
|
-
);
|
|
338
|
-
`,
|
|
339
|
-
down: `
|
|
340
|
-
DROP INDEX IF EXISTS durability_log_leases_claim_idx;
|
|
341
|
-
DROP INDEX IF EXISTS durability_log_leases_order_idx;
|
|
342
|
-
DROP TABLE IF EXISTS durability_log_leases;
|
|
343
|
-
DROP TABLE IF EXISTS durability_log_allocations;
|
|
344
|
-
`,
|
|
345
|
-
},
|
|
346
|
-
];
|
|
347
|
-
/**
|
|
348
|
-
* Ordered SQLite migrations for outbox channels. Applied automatically on
|
|
349
|
-
* construction.
|
|
350
|
-
*/
|
|
351
|
-
export const durabilityOutboxMigrations = [
|
|
352
|
-
{
|
|
353
|
-
name: 'durability_0006_create_outbox',
|
|
354
|
-
up: `
|
|
355
|
-
CREATE TABLE IF NOT EXISTS durability_outbox (
|
|
356
|
-
id TEXT PRIMARY KEY,
|
|
357
|
-
channel TEXT NOT NULL,
|
|
358
|
-
entry_key TEXT NOT NULL,
|
|
359
|
-
version INTEGER NOT NULL,
|
|
360
|
-
payload TEXT NOT NULL,
|
|
361
|
-
status TEXT NOT NULL CHECK (status IN ('pending')),
|
|
362
|
-
attempt INTEGER NOT NULL DEFAULT 0,
|
|
363
|
-
next_attempt_at INTEGER NOT NULL,
|
|
364
|
-
last_error TEXT,
|
|
365
|
-
last_error_name TEXT,
|
|
366
|
-
created_at INTEGER NOT NULL,
|
|
367
|
-
generation_id TEXT NOT NULL
|
|
368
|
-
);
|
|
369
|
-
CREATE INDEX IF NOT EXISTS durability_outbox_due_idx
|
|
370
|
-
ON durability_outbox (channel, status, next_attempt_at, version);
|
|
371
|
-
CREATE INDEX IF NOT EXISTS durability_outbox_pending_idx
|
|
372
|
-
ON durability_outbox (status, next_attempt_at);
|
|
373
|
-
CREATE INDEX IF NOT EXISTS durability_outbox_created_idx
|
|
374
|
-
ON durability_outbox (created_at);
|
|
375
|
-
CREATE TABLE IF NOT EXISTS durability_outbox_seq (
|
|
376
|
-
id INTEGER PRIMARY KEY CHECK (id = 1),
|
|
377
|
-
next_version INTEGER NOT NULL
|
|
378
|
-
);
|
|
379
|
-
INSERT OR IGNORE INTO durability_outbox_seq (id, next_version) VALUES (1, 1);
|
|
380
|
-
`,
|
|
381
|
-
down: `
|
|
382
|
-
DROP INDEX IF EXISTS durability_outbox_due_idx;
|
|
383
|
-
DROP INDEX IF EXISTS durability_outbox_pending_idx;
|
|
384
|
-
DROP INDEX IF EXISTS durability_outbox_created_idx;
|
|
385
|
-
DROP TABLE IF EXISTS durability_outbox;
|
|
386
|
-
DROP TABLE IF EXISTS durability_outbox_seq;
|
|
387
|
-
`,
|
|
388
|
-
},
|
|
389
|
-
];
|
|
390
|
-
/**
|
|
391
|
-
* Ordered SQLite migrations for semaphore grants. Applied automatically on
|
|
392
|
-
* construction.
|
|
393
|
-
*/
|
|
394
|
-
export const durabilitySemaphoreMigrations = [
|
|
395
|
-
{
|
|
396
|
-
name: 'durability_0007_create_semaphore',
|
|
397
|
-
up: `
|
|
398
|
-
CREATE TABLE IF NOT EXISTS durability_semaphore_grants (
|
|
399
|
-
grant_id TEXT PRIMARY KEY,
|
|
400
|
-
client_id TEXT NOT NULL,
|
|
401
|
-
grp TEXT NOT NULL,
|
|
402
|
-
permits INTEGER NOT NULL,
|
|
403
|
-
claimed INTEGER NOT NULL DEFAULT 0,
|
|
404
|
-
released INTEGER NOT NULL DEFAULT 0,
|
|
405
|
-
created_at INTEGER NOT NULL,
|
|
406
|
-
expires_at INTEGER NOT NULL
|
|
407
|
-
);
|
|
408
|
-
CREATE INDEX IF NOT EXISTS durability_semaphore_grants_expires_idx
|
|
409
|
-
ON durability_semaphore_grants (expires_at) WHERE claimed < permits;
|
|
410
|
-
`,
|
|
411
|
-
down: `
|
|
412
|
-
DROP INDEX IF EXISTS durability_semaphore_grants_expires_idx;
|
|
413
|
-
DROP TABLE IF EXISTS durability_semaphore_grants;
|
|
414
|
-
`,
|
|
415
|
-
},
|
|
416
|
-
{
|
|
417
|
-
name: 'durability_0009_create_semaphore_leases',
|
|
418
|
-
up: `
|
|
419
|
-
CREATE TABLE IF NOT EXISTS durability_semaphore_leases (
|
|
420
|
-
lease_id TEXT PRIMARY KEY,
|
|
421
|
-
client_id TEXT NOT NULL,
|
|
422
|
-
grp TEXT NOT NULL,
|
|
423
|
-
permits INTEGER NOT NULL,
|
|
424
|
-
released INTEGER NOT NULL DEFAULT 0,
|
|
425
|
-
created_at INTEGER NOT NULL,
|
|
426
|
-
expires_at INTEGER NOT NULL,
|
|
427
|
-
retired INTEGER NOT NULL DEFAULT 0
|
|
428
|
-
);
|
|
429
|
-
CREATE INDEX IF NOT EXISTS durability_semaphore_leases_expires_idx
|
|
430
|
-
ON durability_semaphore_leases (expires_at);
|
|
431
|
-
`,
|
|
432
|
-
down: `
|
|
433
|
-
DROP INDEX IF EXISTS durability_semaphore_leases_expires_idx;
|
|
434
|
-
DROP TABLE IF EXISTS durability_semaphore_leases;
|
|
435
|
-
`,
|
|
436
|
-
},
|
|
437
|
-
];
|
|
438
|
-
/**
|
|
439
|
-
* Ordered SQLite migrations for a semaphore client's queue. Applied
|
|
440
|
-
* automatically on construction.
|
|
441
|
-
*/
|
|
442
|
-
export const durabilitySemaphoreQueueMigrations = [
|
|
443
|
-
{
|
|
444
|
-
name: 'durability_0008_create_semaphore_queue',
|
|
445
|
-
up: `
|
|
446
|
-
CREATE TABLE IF NOT EXISTS durability_semaphore_queue_items (
|
|
447
|
-
id TEXT PRIMARY KEY,
|
|
448
|
-
key TEXT NOT NULL,
|
|
449
|
-
grp TEXT NOT NULL,
|
|
450
|
-
payload TEXT NOT NULL,
|
|
451
|
-
status TEXT NOT NULL CHECK (status IN ('queued', 'claiming', 'admitted')),
|
|
452
|
-
grant_id TEXT,
|
|
453
|
-
created_at INTEGER NOT NULL,
|
|
454
|
-
admitted_at INTEGER,
|
|
455
|
-
notified INTEGER NOT NULL DEFAULT 0,
|
|
456
|
-
attempt INTEGER NOT NULL DEFAULT 0,
|
|
457
|
-
next_attempt_at INTEGER NOT NULL
|
|
458
|
-
);
|
|
459
|
-
CREATE INDEX IF NOT EXISTS durability_semaphore_queue_items_key_idx
|
|
460
|
-
ON durability_semaphore_queue_items (key, status, created_at, id);
|
|
461
|
-
CREATE INDEX IF NOT EXISTS durability_semaphore_queue_items_grant_idx
|
|
462
|
-
ON durability_semaphore_queue_items (grant_id, created_at, id);
|
|
463
|
-
CREATE INDEX IF NOT EXISTS durability_semaphore_queue_items_notify_idx
|
|
464
|
-
ON durability_semaphore_queue_items (next_attempt_at)
|
|
465
|
-
WHERE status = 'admitted' AND notified = 0;
|
|
466
|
-
CREATE TABLE IF NOT EXISTS durability_semaphore_queue_grants (
|
|
467
|
-
grant_id TEXT PRIMARY KEY,
|
|
468
|
-
key TEXT NOT NULL,
|
|
469
|
-
grp TEXT NOT NULL,
|
|
470
|
-
permits INTEGER NOT NULL,
|
|
471
|
-
claimed INTEGER NOT NULL DEFAULT 0,
|
|
472
|
-
confirmed INTEGER NOT NULL DEFAULT 0,
|
|
473
|
-
admitted INTEGER NOT NULL DEFAULT 0,
|
|
474
|
-
released INTEGER NOT NULL DEFAULT 0,
|
|
475
|
-
created_at INTEGER NOT NULL
|
|
476
|
-
);
|
|
477
|
-
CREATE INDEX IF NOT EXISTS durability_semaphore_queue_grants_key_idx
|
|
478
|
-
ON durability_semaphore_queue_grants (key, created_at);
|
|
479
|
-
CREATE TABLE IF NOT EXISTS durability_semaphore_queue_keys (
|
|
480
|
-
key TEXT PRIMARY KEY,
|
|
481
|
-
next_request_at INTEGER NOT NULL,
|
|
482
|
-
queued INTEGER NOT NULL
|
|
483
|
-
);
|
|
484
|
-
CREATE INDEX IF NOT EXISTS durability_semaphore_queue_keys_due_idx
|
|
485
|
-
ON durability_semaphore_queue_keys (next_request_at) WHERE queued > 0;
|
|
486
|
-
`,
|
|
487
|
-
down: `
|
|
488
|
-
DROP INDEX IF EXISTS durability_semaphore_queue_keys_due_idx;
|
|
489
|
-
DROP TABLE IF EXISTS durability_semaphore_queue_keys;
|
|
490
|
-
DROP INDEX IF EXISTS durability_semaphore_queue_grants_key_idx;
|
|
491
|
-
DROP TABLE IF EXISTS durability_semaphore_queue_grants;
|
|
492
|
-
DROP INDEX IF EXISTS durability_semaphore_queue_items_notify_idx;
|
|
493
|
-
DROP INDEX IF EXISTS durability_semaphore_queue_items_grant_idx;
|
|
494
|
-
DROP INDEX IF EXISTS durability_semaphore_queue_items_key_idx;
|
|
495
|
-
DROP TABLE IF EXISTS durability_semaphore_queue_items;
|
|
496
|
-
`,
|
|
497
|
-
},
|
|
498
|
-
{
|
|
499
|
-
name: 'durability_0010_add_semaphore_queue_leases',
|
|
500
|
-
up: `
|
|
501
|
-
ALTER TABLE durability_semaphore_queue_items ADD COLUMN lease_id TEXT;
|
|
502
|
-
CREATE TABLE IF NOT EXISTS durability_semaphore_queue_leases (
|
|
503
|
-
lease_id TEXT PRIMARY KEY,
|
|
504
|
-
key TEXT NOT NULL,
|
|
505
|
-
grp TEXT NOT NULL,
|
|
506
|
-
permits INTEGER NOT NULL,
|
|
507
|
-
drawn INTEGER NOT NULL DEFAULT 0,
|
|
508
|
-
released INTEGER NOT NULL DEFAULT 0,
|
|
509
|
-
created_at INTEGER NOT NULL,
|
|
510
|
-
expires_at INTEGER NOT NULL
|
|
511
|
-
);
|
|
512
|
-
CREATE INDEX IF NOT EXISTS durability_semaphore_queue_leases_key_idx
|
|
513
|
-
ON durability_semaphore_queue_leases (key, created_at);
|
|
514
|
-
`,
|
|
515
|
-
down: `
|
|
516
|
-
DROP INDEX IF EXISTS durability_semaphore_queue_leases_key_idx;
|
|
517
|
-
DROP TABLE IF EXISTS durability_semaphore_queue_leases;
|
|
518
|
-
ALTER TABLE durability_semaphore_queue_items DROP COLUMN lease_id;
|
|
519
|
-
`,
|
|
520
|
-
},
|
|
521
|
-
{
|
|
522
|
-
name: 'durability_0011_renew_semaphore_queue_leases',
|
|
523
|
-
up: `
|
|
524
|
-
ALTER TABLE durability_semaphore_queue_leases ADD COLUMN renew_at INTEGER NOT NULL DEFAULT 0;
|
|
525
|
-
ALTER TABLE durability_semaphore_queue_leases ADD COLUMN renew_ms INTEGER NOT NULL DEFAULT 30000;
|
|
526
|
-
ALTER TABLE durability_semaphore_queue_leases ADD COLUMN confirmed INTEGER NOT NULL DEFAULT 0;
|
|
527
|
-
`,
|
|
528
|
-
down: `
|
|
529
|
-
ALTER TABLE durability_semaphore_queue_leases DROP COLUMN confirmed;
|
|
530
|
-
ALTER TABLE durability_semaphore_queue_leases DROP COLUMN renew_ms;
|
|
531
|
-
ALTER TABLE durability_semaphore_queue_leases DROP COLUMN renew_at;
|
|
532
|
-
`,
|
|
533
|
-
},
|
|
534
|
-
];
|
|
535
|
-
/**
|
|
536
|
-
* Ordered SQLite migrations for the experimental topology coordinator.
|
|
537
|
-
* Publication and sync ride on outbox channels. Applied automatically on
|
|
538
|
-
* construction.
|
|
539
|
-
*/
|
|
540
|
-
export const durabilityTopologyMigrations = [
|
|
541
|
-
{
|
|
542
|
-
name: 'durability_0011_create_topology',
|
|
543
|
-
up: `
|
|
544
|
-
CREATE TABLE IF NOT EXISTS durability_topology_groups (
|
|
545
|
-
group_id TEXT PRIMARY KEY,
|
|
546
|
-
version INTEGER NOT NULL,
|
|
547
|
-
members TEXT NOT NULL,
|
|
548
|
-
deleted INTEGER NOT NULL CHECK (deleted IN (0, 1)),
|
|
549
|
-
updated_at INTEGER NOT NULL
|
|
550
|
-
);
|
|
551
|
-
CREATE TABLE IF NOT EXISTS durability_topology_states (
|
|
552
|
-
group_id TEXT NOT NULL,
|
|
553
|
-
channel TEXT NOT NULL,
|
|
554
|
-
value TEXT NOT NULL,
|
|
555
|
-
PRIMARY KEY (group_id, channel)
|
|
556
|
-
);
|
|
557
|
-
CREATE TABLE IF NOT EXISTS durability_topology_writes (
|
|
558
|
-
id TEXT PRIMARY KEY,
|
|
559
|
-
group_id TEXT NOT NULL,
|
|
560
|
-
land_by INTEGER NOT NULL
|
|
561
|
-
);
|
|
562
|
-
CREATE INDEX IF NOT EXISTS durability_topology_writes_group_idx
|
|
563
|
-
ON durability_topology_writes (group_id, land_by);
|
|
564
|
-
`,
|
|
565
|
-
down: `
|
|
566
|
-
DROP INDEX IF EXISTS durability_topology_writes_group_idx;
|
|
567
|
-
DROP TABLE IF EXISTS durability_topology_writes;
|
|
568
|
-
DROP TABLE IF EXISTS durability_topology_states;
|
|
569
|
-
DROP TABLE IF EXISTS durability_topology_groups;
|
|
570
|
-
`,
|
|
571
|
-
},
|
|
572
|
-
];
|
|
573
|
-
/**
|
|
574
|
-
* Ordered SQLite migrations for the experimental schedule. Applied
|
|
575
|
-
* automatically on construction.
|
|
576
|
-
*/
|
|
577
|
-
export const durabilityScheduleMigrations = [
|
|
578
|
-
{
|
|
579
|
-
name: 'durability_0013_create_schedule',
|
|
580
|
-
// INTEGER PRIMARY KEY aliases the rowid, so each table is a single b-tree
|
|
581
|
-
// with no secondary index for per-run writes to maintain.
|
|
582
|
-
up: `
|
|
583
|
-
CREATE TABLE IF NOT EXISTS durability_schedule (
|
|
584
|
-
id INTEGER PRIMARY KEY CHECK (id = 1),
|
|
585
|
-
version INTEGER NOT NULL,
|
|
586
|
-
expression TEXT,
|
|
587
|
-
next_at INTEGER
|
|
588
|
-
);
|
|
589
|
-
CREATE TABLE IF NOT EXISTS durability_schedule_runs (
|
|
590
|
-
scheduled_time INTEGER PRIMARY KEY,
|
|
591
|
-
state TEXT NOT NULL
|
|
592
|
-
CHECK (state IN ('queued', 'running', 'complete', 'errored')),
|
|
593
|
-
next_at INTEGER NOT NULL,
|
|
594
|
-
attempt INTEGER NOT NULL DEFAULT 0,
|
|
595
|
-
error TEXT
|
|
596
|
-
);
|
|
597
|
-
`,
|
|
598
|
-
down: `
|
|
599
|
-
DROP TABLE IF EXISTS durability_schedule_runs;
|
|
600
|
-
DROP TABLE IF EXISTS durability_schedule;
|
|
601
|
-
`,
|
|
602
|
-
},
|
|
603
|
-
{
|
|
604
|
-
name: 'durability_0014_add_schedule_jitter',
|
|
605
|
-
up: `
|
|
606
|
-
ALTER TABLE durability_schedule ADD COLUMN jitter_ms INTEGER NOT NULL DEFAULT 0;
|
|
607
|
-
ALTER TABLE durability_schedule_runs ADD COLUMN due_at INTEGER;
|
|
608
|
-
UPDATE durability_schedule_runs SET due_at = scheduled_time;
|
|
609
|
-
`,
|
|
610
|
-
down: `
|
|
611
|
-
ALTER TABLE durability_schedule_runs DROP COLUMN due_at;
|
|
612
|
-
ALTER TABLE durability_schedule DROP COLUMN jitter_ms;
|
|
613
|
-
`,
|
|
614
|
-
},
|
|
615
|
-
];
|
|
616
4
|
/**
|
|
617
5
|
* Newer library versions may leave migrations this one does not know about.
|
|
618
6
|
* On downgrade their stored `down` scripts are run, but only this many, so an
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type DurabilityLifecycleEvent, type LifecycleHook } from '
|
|
2
|
-
import { type DurabilityMigrationResult } from '
|
|
3
|
-
import { type DurabilityMethodOptions, type ExecutionPolicyOptions } from '
|
|
4
|
-
import { type SchedulerAttachment } from '
|
|
5
|
-
import { type DurableMemoize } from '
|
|
1
|
+
import { type DurabilityLifecycleEvent, type LifecycleHook } from '../lifecycle.js';
|
|
2
|
+
import { type DurabilityMigrationResult } from '../migrations.js';
|
|
3
|
+
import { type DurabilityMethodOptions, type ExecutionPolicyOptions } from '../policy.js';
|
|
4
|
+
import { type SchedulerAttachment } from '../scheduler/index.js';
|
|
5
|
+
import { type DurableMemoize } from '../memoize/index.js';
|
|
6
6
|
/**
|
|
7
7
|
* The context passed to a durable operation handler for each attempt.
|
|
8
8
|
*
|
|
@@ -149,6 +149,14 @@ export type DurabilityOptions<Handlers extends HandlerMap = HandlerMap> = Execut
|
|
|
149
149
|
export type DurabilityConfig<Handlers extends HandlerMap = HandlerMap> = DurabilityOptions<Handlers> & SchedulerAttachment & {
|
|
150
150
|
/** Operation handlers keyed by the method names they become. */
|
|
151
151
|
handlers: Handlers;
|
|
152
|
+
/**
|
|
153
|
+
* Stable channel ID. Instances on one scheduler share storage,
|
|
154
|
+
* partitioned by channel; call IDs are unique within a channel, and
|
|
155
|
+
* each instance runs, lists and purges only its own. A library should
|
|
156
|
+
* use its own channel so its calls never meet the application's.
|
|
157
|
+
* Defaults to `default`.
|
|
158
|
+
*/
|
|
159
|
+
channel?: string;
|
|
152
160
|
};
|
|
153
161
|
declare class DurabilityCore<Handlers extends HandlerMap> {
|
|
154
162
|
#private;
|