durability 5.0.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.
Files changed (89) hide show
  1. package/README.md +238 -7
  2. package/dist/{durability-alarms.d.ts → alarms/index.d.ts} +23 -6
  3. package/dist/{durability-alarms.js → alarms/index.js} +96 -52
  4. package/dist/alarms/migrations.d.ts +9 -0
  5. package/dist/alarms/migrations.js +133 -0
  6. package/dist/errors.d.ts +15 -0
  7. package/dist/errors.js +24 -0
  8. package/dist/experimental.d.ts +11 -8
  9. package/dist/experimental.js +8 -5
  10. package/dist/{fanout.d.ts → fanout/index.d.ts} +13 -6
  11. package/dist/{fanout.js → fanout/index.js} +55 -49
  12. package/dist/fanout/migrations.d.ts +9 -0
  13. package/dist/fanout/migrations.js +181 -0
  14. package/dist/{stored-message.d.ts → fanout/stored-message.d.ts} +1 -1
  15. package/dist/index.d.ts +14 -9
  16. package/dist/index.js +13 -8
  17. package/dist/{log.d.ts → log/index.d.ts} +15 -3
  18. package/dist/{log.js → log/index.js} +152 -124
  19. package/dist/log/migrations.d.ts +18 -0
  20. package/dist/log/migrations.js +297 -0
  21. package/dist/{memoize.d.ts → memoize/index.d.ts} +1 -1
  22. package/dist/{memoize.js → memoize/index.js} +14 -11
  23. package/dist/memoize/migrations.d.ts +10 -0
  24. package/dist/memoize/migrations.js +21 -0
  25. package/dist/migrations.d.ts +1 -103
  26. package/dist/migrations.js +1 -570
  27. package/dist/{durability.d.ts → operations/index.d.ts} +13 -5
  28. package/dist/{durability.js → operations/index.js} +63 -46
  29. package/dist/operations/migrations.d.ts +10 -0
  30. package/dist/operations/migrations.js +150 -0
  31. package/dist/{outbox.d.ts → outbox/index.d.ts} +4 -4
  32. package/dist/{outbox.js → outbox/index.js} +18 -63
  33. package/dist/outbox/migrations.d.ts +9 -0
  34. package/dist/outbox/migrations.js +43 -0
  35. package/dist/{routing-client.js → routing/client.js} +1 -1
  36. package/dist/{routing.d.ts → routing/index.d.ts} +3 -3
  37. package/dist/{routing.js → routing/index.js} +3 -3
  38. package/dist/{load.d.ts → routing/load.d.ts} +1 -1
  39. package/dist/schedule/index.d.ts +165 -0
  40. package/dist/schedule/index.js +667 -0
  41. package/dist/schedule/migrations.d.ts +9 -0
  42. package/dist/schedule/migrations.js +118 -0
  43. package/dist/{scheduler.d.ts → scheduler/index.d.ts} +122 -22
  44. package/dist/scheduler/index.js +925 -0
  45. package/dist/{semaphore-client.d.ts → semaphore/client.d.ts} +1 -1
  46. package/dist/{semaphore-client.js → semaphore/client.js} +2 -2
  47. package/dist/{semaphore.d.ts → semaphore/index.d.ts} +10 -10
  48. package/dist/{semaphore.js → semaphore/index.js} +7 -7
  49. package/dist/{semaphore-leases.d.ts → semaphore/leases.d.ts} +17 -6
  50. package/dist/{semaphore-leases.js → semaphore/leases.js} +28 -12
  51. package/dist/semaphore/migrations.d.ts +18 -0
  52. package/dist/semaphore/migrations.js +444 -0
  53. package/dist/{semaphore-protocol.d.ts → semaphore/protocol.d.ts} +16 -8
  54. package/dist/{semaphore-protocol.js → semaphore/protocol.js} +37 -14
  55. package/dist/{semaphore-queue-store.d.ts → semaphore/queue-store.d.ts} +12 -6
  56. package/dist/{semaphore-queue-store.js → semaphore/queue-store.js} +87 -75
  57. package/dist/{semaphore-queue.d.ts → semaphore/queue.d.ts} +15 -5
  58. package/dist/{semaphore-queue.js → semaphore/queue.js} +105 -46
  59. package/dist/{semaphore-server.d.ts → semaphore/server.d.ts} +12 -4
  60. package/dist/{semaphore-server.js → semaphore/server.js} +51 -24
  61. package/dist/{semaphore-store.d.ts → semaphore/store.d.ts} +8 -3
  62. package/dist/{semaphore-store.js → semaphore/store.js} +35 -33
  63. package/dist/{client.d.ts → socket/client.d.ts} +3 -3
  64. package/dist/{client.js → socket/client.js} +4 -4
  65. package/dist/{socket.d.ts → socket/index.d.ts} +15 -4
  66. package/dist/{socket.js → socket/index.js} +66 -20
  67. package/dist/socket/migrations.d.ts +9 -0
  68. package/dist/socket/migrations.js +57 -0
  69. package/dist/{socket-protocol.d.ts → socket/protocol.d.ts} +1 -1
  70. package/dist/storage.d.ts +9 -2
  71. package/dist/storage.js +24 -11
  72. package/dist/{topology-client.d.ts → topology/client.d.ts} +2 -2
  73. package/dist/{topology-client.js → topology/client.js} +3 -3
  74. package/dist/{topology.d.ts → topology/index.d.ts} +17 -7
  75. package/dist/{topology.js → topology/index.js} +92 -58
  76. package/dist/topology/migrations.d.ts +10 -0
  77. package/dist/topology/migrations.js +138 -0
  78. package/dist/{tracker.d.ts → tracker/index.d.ts} +3 -3
  79. package/dist/{tracker.js → tracker/index.js} +2 -2
  80. package/package.json +11 -11
  81. package/dist/scheduler.js +0 -577
  82. /package/dist/{stored-message.js → fanout/stored-message.js} +0 -0
  83. /package/dist/{routing-client.d.ts → routing/client.d.ts} +0 -0
  84. /package/dist/{load.js → routing/load.js} +0 -0
  85. /package/dist/{socket-protocol.js → socket/protocol.js} +0 -0
  86. /package/dist/{topology-snapshot.d.ts → topology/snapshot.d.ts} +0 -0
  87. /package/dist/{topology-snapshot.js → topology/snapshot.js} +0 -0
  88. /package/dist/{tracked-source.d.ts → tracker/source.d.ts} +0 -0
  89. /package/dist/{tracked-source.js → tracker/source.js} +0 -0
@@ -9,18 +9,20 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _DurabilityFanout_instances, _DurabilityFanout_engine, _DurabilityFanout_routing, _DurabilityFanout_targets, _DurabilityFanout_policies, _DurabilityFanout_dlq, _DurabilityFanout_maxBatchSize, _DurabilityFanout_batchDelayMs, _DurabilityFanout_lifecycle, _DurabilityFanout_emit, _DurabilityFanout_running, _DurabilityFanout_pending, _DurabilityFanout_firstAttemptAt, _DurabilityFanout_runDue, _DurabilityFanout_runTarget, _DurabilityFanout_postpone, _DurabilityFanout_deliver, _DurabilityFanout_ackUnsettled, _DurabilityFanout_message, _DurabilityFanout_remove, _DurabilityFanout_removeDelivery, _DurabilityFanout_retry, _DurabilityFanout_deadLetter, _DurabilityFanout_emitTerminal, _DurabilityFanout_transaction, _DurabilityFanout_pendingCount, _DurabilityFanout_adjustPending, _DurabilityFanout_listDue, _DurabilityFanout_deadline;
12
+ var _DurabilityFanout_instances, _DurabilityFanout_engine, _DurabilityFanout_channel, _DurabilityFanout_table, _DurabilityFanout_routing, _DurabilityFanout_targets, _DurabilityFanout_policies, _DurabilityFanout_dlq, _DurabilityFanout_maxBatchSize, _DurabilityFanout_batchDelayMs, _DurabilityFanout_lifecycle, _DurabilityFanout_emit, _DurabilityFanout_running, _DurabilityFanout_pending, _DurabilityFanout_firstAttemptAt, _DurabilityFanout_runDue, _DurabilityFanout_runTarget, _DurabilityFanout_postpone, _DurabilityFanout_deliver, _DurabilityFanout_ackUnsettled, _DurabilityFanout_message, _DurabilityFanout_remove, _DurabilityFanout_removeDelivery, _DurabilityFanout_retry, _DurabilityFanout_deadLetter, _DurabilityFanout_emitTerminal, _DurabilityFanout_transaction, _DurabilityFanout_pendingCount, _DurabilityFanout_adjustPending, _DurabilityFanout_listDue, _DurabilityFanout_deadline;
13
13
  import { z } from 'zod';
14
- import { traceFunction, traceMethods } from './dev.js';
15
- import { DurableRetryPolicyError, FanoutEnqueueError, FanoutSettlementError, FanoutTimeoutError, reportFailure, serializeError, } from './errors.js';
16
- import { createLifecycleHooks, } from './lifecycle.js';
17
- import { RoutingLoad } from './load.js';
18
- import { createMemoize, deleteMemos, deleteMemosOfDroppedTable, } from './memoize.js';
19
- import { durabilityFanoutMigrations, durabilityMemoMigrations, migrateCapability, } from './migrations.js';
20
- import { assertPositiveInteger, createPolicyResolver, methodOptionsSchema, } from './policy.js';
21
- import { engineFor, } from './scheduler.js';
22
- import { deserialize, serialize } from './serialization.js';
23
- import { claimAttempt, deleteAttempt, updateAttempt, } from './storage.js';
14
+ import { traceFunction, traceMethods } from '../dev.js';
15
+ import { DurableRetryPolicyError, FanoutEnqueueError, FanoutSettlementError, FanoutTimeoutError, reportFailure, serializeError, } from '../errors.js';
16
+ import { createLifecycleHooks, } from '../lifecycle.js';
17
+ import { RoutingLoad, } from '../routing/load.js';
18
+ import { createMemoize, deleteMemos, deleteMemosOfDroppedTable, } from '../memoize/index.js';
19
+ import { durabilityFanoutMigrations } from './migrations.js';
20
+ import { durabilityMemoMigrations } from '../memoize/migrations.js';
21
+ import { migrateCapability } from '../migrations.js';
22
+ import { assertPositiveInteger, createPolicyResolver, methodOptionsSchema, } from '../policy.js';
23
+ import { assertChannel, defaultChannel, engineFor, } from '../scheduler/index.js';
24
+ import { deserialize, serialize } from '../serialization.js';
25
+ import { claimAttempt, deleteAttempt, updateAttempt, } from '../storage.js';
24
26
  const fanoutMessageRowSchema = z.object({
25
27
  key: z.string(),
26
28
  id: z.string(),
@@ -53,10 +55,10 @@ const deliveriesTable = {
53
55
  };
54
56
  const countRowSchema = z.object({ count: z.number().int().nonnegative() });
55
57
  const seqRowSchema = z.object({ seq: z.number().int().nonnegative() });
56
- const readManifest = (sql, key) => fanoutMessageRowSchema
58
+ const readManifest = (sql, channel, key) => fanoutMessageRowSchema
57
59
  .optional()
58
60
  .parse(sql
59
- .exec('SELECT * FROM durability_fanout_messages WHERE key = ?', key)
61
+ .exec('SELECT * FROM durability_fanout_messages WHERE channel = ? AND key = ?', channel, key)
60
62
  .toArray()[0]);
61
63
  const attemptOf = (row) => ({
62
64
  key: row.id,
@@ -80,6 +82,8 @@ export class DurabilityFanout {
80
82
  constructor(config) {
81
83
  _DurabilityFanout_instances.add(this);
82
84
  _DurabilityFanout_engine.set(this, void 0);
85
+ _DurabilityFanout_channel.set(this, void 0);
86
+ _DurabilityFanout_table.set(this, void 0);
83
87
  _DurabilityFanout_routing.set(this, void 0);
84
88
  _DurabilityFanout_targets.set(this, void 0);
85
89
  _DurabilityFanout_policies.set(this, void 0);
@@ -96,6 +100,8 @@ export class DurabilityFanout {
96
100
  * may leave it wrong, so it is discarded and recounted on the next read.
97
101
  */
98
102
  _DurabilityFanout_pending.set(this, void 0);
103
+ __classPrivateFieldSet(this, _DurabilityFanout_channel, assertChannel('DurabilityFanout', config.channel ?? defaultChannel), "f");
104
+ __classPrivateFieldSet(this, _DurabilityFanout_table, { ...deliveriesTable, channel: __classPrivateFieldGet(this, _DurabilityFanout_channel, "f") }, "f");
99
105
  __classPrivateFieldSet(this, _DurabilityFanout_maxBatchSize, config.maxBatchSize ?? 10, "f");
100
106
  assertPositiveInteger('maxBatchSize', __classPrivateFieldGet(this, _DurabilityFanout_maxBatchSize, "f"));
101
107
  __classPrivateFieldSet(this, _DurabilityFanout_batchDelayMs, config.batchDelayMs ?? 0, "f");
@@ -122,8 +128,10 @@ export class DurabilityFanout {
122
128
  __classPrivateFieldSet(this, _DurabilityFanout_emit, __classPrivateFieldGet(this, _DurabilityFanout_lifecycle, "f").emit, "f");
123
129
  __classPrivateFieldGet(this, _DurabilityFanout_engine, "f").migrateSchema('fanout', durabilityFanoutMigrations);
124
130
  __classPrivateFieldGet(this, _DurabilityFanout_engine, "f").migrateSchema('memos', durabilityMemoMigrations);
125
- __classPrivateFieldGet(this, _DurabilityFanout_engine, "f").register({
126
- table: deliveriesTable,
131
+ __classPrivateFieldGet(this, _DurabilityFanout_engine, "f").registerChannel({
132
+ table: __classPrivateFieldGet(this, _DurabilityFanout_table, "f"),
133
+ channel: __classPrivateFieldGet(this, _DurabilityFanout_channel, "f"),
134
+ helper: 'DurabilityFanout',
127
135
  runDue: () => __classPrivateFieldGet(this, _DurabilityFanout_instances, "m", _DurabilityFanout_runDue).call(this),
128
136
  });
129
137
  }
@@ -187,7 +195,7 @@ export class DurabilityFanout {
187
195
  registered = await __classPrivateFieldGet(this, _DurabilityFanout_instances, "m", _DurabilityFanout_transaction).call(this, (sql) => {
188
196
  const claims = [];
189
197
  for (const entry of entries) {
190
- const existing = readManifest(sql, entry.key);
198
+ const existing = readManifest(sql, __classPrivateFieldGet(this, _DurabilityFanout_channel, "f"), entry.key);
191
199
  if (existing) {
192
200
  if (existing.id !== entry.id ||
193
201
  existing.payload !== entry.payload ||
@@ -211,9 +219,9 @@ export class DurabilityFanout {
211
219
  generation_id: crypto.randomUUID(),
212
220
  };
213
221
  sql.exec(`INSERT INTO durability_fanout_messages
214
- (key, id, payload, targets, remaining, seq, created_at,
215
- generation_id)
216
- VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, message.key, message.id, message.payload, message.targets, message.remaining, message.seq, message.created_at, message.generation_id);
222
+ (channel, key, id, payload, targets, remaining, seq,
223
+ created_at, generation_id)
224
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`, __classPrivateFieldGet(this, _DurabilityFanout_channel, "f"), message.key, message.id, message.payload, message.targets, message.remaining, message.seq, message.created_at, message.generation_id);
217
225
  for (const target of targets) {
218
226
  const row = {
219
227
  id: JSON.stringify([entry.key, target]),
@@ -233,11 +241,11 @@ export class DurabilityFanout {
233
241
  };
234
242
  const inserted = sql
235
243
  .exec(`INSERT INTO durability_fanout_deliveries
236
- (id, message_key, target_id, seq, status, phase, attempt,
237
- next_attempt_at, created_at, generation_id)
238
- VALUES (?, ?, ?, ?, 'pending', 'delivery', 0, ?, ?, ?)
239
- ON CONFLICT(id) DO NOTHING
240
- RETURNING id`, row.id, row.message_key, row.target_id, row.seq, row.next_attempt_at, row.created_at, row.generation_id)
244
+ (channel, id, message_key, target_id, seq, status, phase,
245
+ attempt, next_attempt_at, created_at, generation_id)
246
+ VALUES (?, ?, ?, ?, ?, 'pending', 'delivery', 0, ?, ?, ?)
247
+ ON CONFLICT(channel, id) DO NOTHING
248
+ RETURNING id`, __classPrivateFieldGet(this, _DurabilityFanout_channel, "f"), row.id, row.message_key, row.target_id, row.seq, row.next_attempt_at, row.created_at, row.generation_id)
241
249
  .toArray().length > 0;
242
250
  if (!inserted) {
243
251
  throw new Error('Fanout manifest and delivery state disagree');
@@ -283,7 +291,7 @@ export class DurabilityFanout {
283
291
  return { success: true, value: entries.map(({ id }) => id), load };
284
292
  }
285
293
  }
286
- _DurabilityFanout_engine = new WeakMap(), _DurabilityFanout_routing = new WeakMap(), _DurabilityFanout_targets = new WeakMap(), _DurabilityFanout_policies = new WeakMap(), _DurabilityFanout_dlq = new WeakMap(), _DurabilityFanout_maxBatchSize = new WeakMap(), _DurabilityFanout_batchDelayMs = new WeakMap(), _DurabilityFanout_lifecycle = new WeakMap(), _DurabilityFanout_emit = new WeakMap(), _DurabilityFanout_running = new WeakMap(), _DurabilityFanout_pending = new WeakMap(), _DurabilityFanout_instances = new WeakSet(), _DurabilityFanout_firstAttemptAt = function _DurabilityFanout_firstAttemptAt(createdAt) {
294
+ _DurabilityFanout_engine = new WeakMap(), _DurabilityFanout_channel = new WeakMap(), _DurabilityFanout_table = new WeakMap(), _DurabilityFanout_routing = new WeakMap(), _DurabilityFanout_targets = new WeakMap(), _DurabilityFanout_policies = new WeakMap(), _DurabilityFanout_dlq = new WeakMap(), _DurabilityFanout_maxBatchSize = new WeakMap(), _DurabilityFanout_batchDelayMs = new WeakMap(), _DurabilityFanout_lifecycle = new WeakMap(), _DurabilityFanout_emit = new WeakMap(), _DurabilityFanout_running = new WeakMap(), _DurabilityFanout_pending = new WeakMap(), _DurabilityFanout_instances = new WeakSet(), _DurabilityFanout_firstAttemptAt = function _DurabilityFanout_firstAttemptAt(createdAt) {
287
295
  if (__classPrivateFieldGet(this, _DurabilityFanout_batchDelayMs, "f") === 0) {
288
296
  return createdAt;
289
297
  }
@@ -294,7 +302,8 @@ _DurabilityFanout_engine = new WeakMap(), _DurabilityFanout_routing = new WeakMa
294
302
  .array()
295
303
  .parse(__classPrivateFieldGet(this, _DurabilityFanout_engine, "f").sql
296
304
  .exec(`SELECT DISTINCT target_id FROM durability_fanout_deliveries
297
- ORDER BY target_id`)
305
+ WHERE channel = ?
306
+ ORDER BY target_id`, __classPrivateFieldGet(this, _DurabilityFanout_channel, "f"))
298
307
  .toArray())
299
308
  .map((row) => row.target_id);
300
309
  // Each target advances independently; a missing or slow target cannot hide
@@ -329,7 +338,7 @@ _DurabilityFanout_engine = new WeakMap(), _DurabilityFanout_routing = new WeakMa
329
338
  const exhausted = [];
330
339
  const deadline = Date.now() + policy.attemptTimeoutMs;
331
340
  for (const row of due) {
332
- const message = readManifest(sql, row.message_key);
341
+ const message = readManifest(sql, __classPrivateFieldGet(this, _DurabilityFanout_channel, "f"), row.message_key);
333
342
  if (!message || message.generation_id !== row.generation_id) {
334
343
  throw new Error('Fanout delivery is missing its message manifest');
335
344
  }
@@ -338,13 +347,11 @@ _DurabilityFanout_engine = new WeakMap(), _DurabilityFanout_routing = new WeakMa
338
347
  exhausted.push({ row, message });
339
348
  continue;
340
349
  }
341
- const attempt = claimAttempt(sql, deliveriesTable, row.id, row.generation_id, policy.maxAttempts);
350
+ const attempt = claimAttempt(sql, __classPrivateFieldGet(this, _DurabilityFanout_table, "f"), row.id, row.generation_id, policy.maxAttempts, deadline);
342
351
  if (attempt === undefined) {
343
352
  continue;
344
353
  }
345
- const claim = { row: { ...row, attempt }, message };
346
- updateAttempt(sql, deliveriesTable, attemptOf(claim.row), 'next_attempt_at = ?', deadline);
347
- claimed.push(claim);
354
+ claimed.push({ row: { ...row, attempt }, message });
348
355
  }
349
356
  return { claims: claimed, terminal: exhausted };
350
357
  });
@@ -362,7 +369,7 @@ _DurabilityFanout_engine = new WeakMap(), _DurabilityFanout_routing = new WeakMa
362
369
  }, _DurabilityFanout_postpone = async function _DurabilityFanout_postpone(rows) {
363
370
  await __classPrivateFieldGet(this, _DurabilityFanout_instances, "m", _DurabilityFanout_transaction).call(this, (sql) => {
364
371
  for (const row of rows) {
365
- updateAttempt(sql, deliveriesTable, attemptOf(row), 'next_attempt_at = ?', Date.now() + infrastructureRetryMs);
372
+ updateAttempt(sql, __classPrivateFieldGet(this, _DurabilityFanout_table, "f"), attemptOf(row), 'next_attempt_at = ?', Date.now() + infrastructureRetryMs);
366
373
  }
367
374
  });
368
375
  }, _DurabilityFanout_deliver = async function _DurabilityFanout_deliver(target, claims, policy) {
@@ -450,10 +457,9 @@ _DurabilityFanout_engine = new WeakMap(), _DurabilityFanout_routing = new WeakMa
450
457
  if (!state.finished) {
451
458
  continue;
452
459
  }
453
- const current = deliveryRowSchema
454
- .optional()
455
- .parse(__classPrivateFieldGet(this, _DurabilityFanout_engine, "f").sql
456
- .exec('SELECT * FROM durability_fanout_deliveries WHERE id = ?', state.claim.row.id)
460
+ const current = deliveryRowSchema.optional().parse(__classPrivateFieldGet(this, _DurabilityFanout_engine, "f").sql
461
+ .exec(`SELECT * FROM durability_fanout_deliveries
462
+ WHERE channel = ? AND id = ?`, __classPrivateFieldGet(this, _DurabilityFanout_channel, "f"), state.claim.row.id)
457
463
  .toArray()[0]);
458
464
  if (!current ||
459
465
  current.generation_id !== state.claim.row.generation_id ||
@@ -532,7 +538,7 @@ _DurabilityFanout_engine = new WeakMap(), _DurabilityFanout_routing = new WeakMa
532
538
  body: deserialize(message.payload),
533
539
  enqueuedAt: message.created_at,
534
540
  attempt: row.attempt,
535
- memoize: createMemoize(__classPrivateFieldGet(this, _DurabilityFanout_engine, "f").sql, deliveriesTable, attemptOf(row)),
541
+ memoize: createMemoize(__classPrivateFieldGet(this, _DurabilityFanout_engine, "f").sql, __classPrivateFieldGet(this, _DurabilityFanout_table, "f"), attemptOf(row)),
536
542
  ack: traceFunction('DurabilityFanoutMessage.ack', () => settle('ack', async () => {
537
543
  await __classPrivateFieldGet(this, _DurabilityFanout_instances, "m", _DurabilityFanout_remove).call(this, row);
538
544
  __classPrivateFieldGet(this, _DurabilityFanout_emit, "f").call(this, {
@@ -562,16 +568,16 @@ _DurabilityFanout_engine = new WeakMap(), _DurabilityFanout_routing = new WeakMa
562
568
  }
563
569
  });
564
570
  }, _DurabilityFanout_removeDelivery = function _DurabilityFanout_removeDelivery(sql, row) {
565
- if (!deleteAttempt(sql, deliveriesTable, attemptOf(row))) {
571
+ if (!deleteAttempt(sql, __classPrivateFieldGet(this, _DurabilityFanout_table, "f"), attemptOf(row))) {
566
572
  return false;
567
573
  }
568
- deleteMemos(sql, deliveriesTable, row.id);
574
+ deleteMemos(sql, __classPrivateFieldGet(this, _DurabilityFanout_table, "f"), row.id);
569
575
  __classPrivateFieldGet(this, _DurabilityFanout_instances, "m", _DurabilityFanout_adjustPending).call(this, -1);
570
576
  sql.exec(`UPDATE durability_fanout_messages
571
577
  SET remaining = remaining - 1
572
- WHERE key = ?`, row.message_key);
578
+ WHERE channel = ? AND key = ?`, __classPrivateFieldGet(this, _DurabilityFanout_channel, "f"), row.message_key);
573
579
  sql.exec(`DELETE FROM durability_fanout_messages
574
- WHERE key = ? AND remaining = 0`, row.message_key);
580
+ WHERE channel = ? AND key = ? AND remaining = 0`, __classPrivateFieldGet(this, _DurabilityFanout_channel, "f"), row.message_key);
575
581
  return true;
576
582
  }, _DurabilityFanout_retry = async function _DurabilityFanout_retry(claim, policy, override, error, startedAt) {
577
583
  const { row } = claim;
@@ -595,7 +601,7 @@ _DurabilityFanout_engine = new WeakMap(), _DurabilityFanout_routing = new WeakMa
595
601
  return;
596
602
  }
597
603
  await __classPrivateFieldGet(this, _DurabilityFanout_instances, "m", _DurabilityFanout_transaction).call(this, (sql) => {
598
- const updated = updateAttempt(sql, deliveriesTable, attemptOf(row), 'next_attempt_at = ?, last_error = ?, last_error_name = ?', nextAttemptAt, error.message, error.name);
604
+ const updated = updateAttempt(sql, __classPrivateFieldGet(this, _DurabilityFanout_table, "f"), attemptOf(row), 'next_attempt_at = ?, last_error = ?, last_error_name = ?', nextAttemptAt, error.message, error.name);
599
605
  if (!updated) {
600
606
  throw new FanoutSettlementError(row.id);
601
607
  }
@@ -627,7 +633,7 @@ _DurabilityFanout_engine = new WeakMap(), _DurabilityFanout_routing = new WeakMa
627
633
  // Persist intent BEFORE external I/O: eviction or timeout must never turn
628
634
  // a terminal decision into another consumer delivery.
629
635
  await __classPrivateFieldGet(this, _DurabilityFanout_instances, "m", _DurabilityFanout_transaction).call(this, (sql) => {
630
- const updated = updateAttempt(sql, deliveriesTable, attemptOf(row), `phase = 'dead_letter', dead_lettered_at = ?, dead_letter_reason = ?,
636
+ const updated = updateAttempt(sql, __classPrivateFieldGet(this, _DurabilityFanout_table, "f"), attemptOf(row), `phase = 'dead_letter', dead_lettered_at = ?, dead_letter_reason = ?,
631
637
  next_attempt_at = ?, last_error = ?, last_error_name = ?`, timestamp, reason, Date.now() + infrastructureRetryMs, error?.message ?? null, error?.name ?? null);
632
638
  if (!updated) {
633
639
  throw new FanoutSettlementError(row.id);
@@ -674,7 +680,7 @@ _DurabilityFanout_engine = new WeakMap(), _DurabilityFanout_routing = new WeakMa
674
680
  }, _DurabilityFanout_pendingCount = function _DurabilityFanout_pendingCount() {
675
681
  __classPrivateFieldSet(this, _DurabilityFanout_pending, __classPrivateFieldGet(this, _DurabilityFanout_pending, "f") ?? countRowSchema.parse(__classPrivateFieldGet(this, _DurabilityFanout_engine, "f").sql
676
682
  .exec(`SELECT COUNT(*) AS count FROM durability_fanout_deliveries
677
- WHERE status = 'pending'`)
683
+ WHERE channel = ? AND status = 'pending'`, __classPrivateFieldGet(this, _DurabilityFanout_channel, "f"))
678
684
  .toArray()[0]).count, "f");
679
685
  return __classPrivateFieldGet(this, _DurabilityFanout_pending, "f");
680
686
  }, _DurabilityFanout_adjustPending = function _DurabilityFanout_adjustPending(delta) {
@@ -684,20 +690,20 @@ _DurabilityFanout_engine = new WeakMap(), _DurabilityFanout_routing = new WeakMa
684
690
  }, _DurabilityFanout_listDue = function _DurabilityFanout_listDue(target, now) {
685
691
  const first = deliveryRowSchema.array().parse(__classPrivateFieldGet(this, _DurabilityFanout_engine, "f").sql
686
692
  .exec(`SELECT * FROM durability_fanout_deliveries
687
- WHERE target_id = ? AND phase = 'delivery' AND status = 'pending'
688
- AND attempt = 0 AND next_attempt_at <= ?
693
+ WHERE channel = ? AND target_id = ? AND phase = 'delivery'
694
+ AND status = 'pending' AND attempt = 0 AND next_attempt_at <= ?
689
695
  ORDER BY seq ASC
690
- LIMIT ?`, target, now, __classPrivateFieldGet(this, _DurabilityFanout_maxBatchSize, "f"))
696
+ LIMIT ?`, __classPrivateFieldGet(this, _DurabilityFanout_channel, "f"), target, now, __classPrivateFieldGet(this, _DurabilityFanout_maxBatchSize, "f"))
691
697
  .toArray());
692
698
  if (first.length >= __classPrivateFieldGet(this, _DurabilityFanout_maxBatchSize, "f")) {
693
699
  return first;
694
700
  }
695
701
  const retries = deliveryRowSchema.array().parse(__classPrivateFieldGet(this, _DurabilityFanout_engine, "f").sql
696
702
  .exec(`SELECT * FROM durability_fanout_deliveries
697
- WHERE target_id = ? AND status = 'pending'
703
+ WHERE channel = ? AND target_id = ? AND status = 'pending'
698
704
  AND attempt > 0 AND next_attempt_at <= ?
699
705
  ORDER BY seq ASC
700
- LIMIT ?`, target, now, __classPrivateFieldGet(this, _DurabilityFanout_maxBatchSize, "f") - first.length)
706
+ LIMIT ?`, __classPrivateFieldGet(this, _DurabilityFanout_channel, "f"), target, now, __classPrivateFieldGet(this, _DurabilityFanout_maxBatchSize, "f") - first.length)
701
707
  .toArray());
702
708
  return [...first, ...retries];
703
709
  }, _DurabilityFanout_deadline = async function _DurabilityFanout_deadline(run, timeoutMs) {
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Ordered SQLite migrations for fanout manifests and deliveries. Applied
3
+ * automatically on construction.
4
+ */
5
+ export declare const durabilityFanoutMigrations: {
6
+ name: string;
7
+ up: string;
8
+ down: string;
9
+ }[];
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Ordered SQLite migrations for fanout manifests and deliveries. Applied
3
+ * automatically on construction.
4
+ */
5
+ export const durabilityFanoutMigrations = [
6
+ {
7
+ name: 'durability_0005_create_fanout',
8
+ up: `
9
+ CREATE TABLE IF NOT EXISTS durability_fanout_messages (
10
+ key TEXT PRIMARY KEY,
11
+ id TEXT NOT NULL,
12
+ payload TEXT NOT NULL,
13
+ targets TEXT NOT NULL,
14
+ remaining INTEGER NOT NULL,
15
+ seq INTEGER NOT NULL,
16
+ created_at INTEGER NOT NULL,
17
+ generation_id TEXT NOT NULL
18
+ );
19
+ CREATE TABLE IF NOT EXISTS durability_fanout_deliveries (
20
+ id TEXT PRIMARY KEY,
21
+ message_key TEXT NOT NULL,
22
+ target_id TEXT NOT NULL,
23
+ seq INTEGER NOT NULL,
24
+ status TEXT NOT NULL CHECK (status IN ('pending')),
25
+ phase TEXT NOT NULL CHECK (phase IN ('delivery', 'dead_letter')),
26
+ attempt INTEGER NOT NULL DEFAULT 0,
27
+ next_attempt_at INTEGER NOT NULL,
28
+ last_error TEXT,
29
+ last_error_name TEXT,
30
+ created_at INTEGER NOT NULL,
31
+ generation_id TEXT NOT NULL,
32
+ dead_lettered_at INTEGER,
33
+ dead_letter_reason TEXT CHECK (dead_letter_reason IN ('explicit', 'exhausted'))
34
+ );
35
+ CREATE INDEX IF NOT EXISTS durability_fanout_deliveries_due_idx
36
+ ON durability_fanout_deliveries
37
+ (target_id, phase, status, attempt, seq, next_attempt_at);
38
+ CREATE INDEX IF NOT EXISTS durability_fanout_deliveries_pending_idx
39
+ ON durability_fanout_deliveries (phase, status, next_attempt_at);
40
+ CREATE INDEX IF NOT EXISTS durability_fanout_deliveries_created_idx
41
+ ON durability_fanout_deliveries (created_at);
42
+ CREATE TABLE IF NOT EXISTS durability_fanout_seq (
43
+ id INTEGER PRIMARY KEY CHECK (id = 1),
44
+ next_seq INTEGER NOT NULL
45
+ );
46
+ INSERT OR IGNORE INTO durability_fanout_seq (id, next_seq) VALUES (1, 0);
47
+ `,
48
+ down: `
49
+ DROP INDEX IF EXISTS durability_fanout_deliveries_due_idx;
50
+ DROP INDEX IF EXISTS durability_fanout_deliveries_pending_idx;
51
+ DROP INDEX IF EXISTS durability_fanout_deliveries_created_idx;
52
+ DROP TABLE IF EXISTS durability_fanout_deliveries;
53
+ DROP TABLE IF EXISTS durability_fanout_messages;
54
+ DROP TABLE IF EXISTS durability_fanout_seq;
55
+ `,
56
+ },
57
+ {
58
+ name: 'durability_0017_fanout_channels',
59
+ up: `
60
+ ALTER TABLE durability_fanout_messages
61
+ RENAME TO durability_fanout_messages_before_channels;
62
+ CREATE TABLE durability_fanout_messages (
63
+ key TEXT NOT NULL,
64
+ id TEXT NOT NULL,
65
+ payload TEXT NOT NULL,
66
+ targets TEXT NOT NULL,
67
+ remaining INTEGER NOT NULL,
68
+ seq INTEGER NOT NULL,
69
+ created_at INTEGER NOT NULL,
70
+ generation_id TEXT NOT NULL,
71
+ channel TEXT NOT NULL DEFAULT 'default',
72
+ PRIMARY KEY (channel, key)
73
+ );
74
+ INSERT INTO durability_fanout_messages
75
+ (key, id, payload, targets, remaining, seq, created_at,
76
+ generation_id, channel)
77
+ SELECT key, id, payload, targets, remaining, seq, created_at,
78
+ generation_id, 'default'
79
+ FROM durability_fanout_messages_before_channels;
80
+ DROP TABLE durability_fanout_messages_before_channels;
81
+
82
+ ALTER TABLE durability_fanout_deliveries
83
+ RENAME TO durability_fanout_deliveries_before_channels;
84
+ CREATE TABLE durability_fanout_deliveries (
85
+ id TEXT NOT NULL,
86
+ message_key TEXT NOT NULL,
87
+ target_id TEXT NOT NULL,
88
+ seq INTEGER NOT NULL,
89
+ status TEXT NOT NULL CHECK (status IN ('pending')),
90
+ phase TEXT NOT NULL CHECK (phase IN ('delivery', 'dead_letter')),
91
+ attempt INTEGER NOT NULL DEFAULT 0,
92
+ next_attempt_at INTEGER NOT NULL,
93
+ last_error TEXT,
94
+ last_error_name TEXT,
95
+ created_at INTEGER NOT NULL,
96
+ generation_id TEXT NOT NULL,
97
+ dead_lettered_at INTEGER,
98
+ dead_letter_reason TEXT CHECK (dead_letter_reason IN ('explicit', 'exhausted')),
99
+ channel TEXT NOT NULL DEFAULT 'default',
100
+ PRIMARY KEY (channel, id)
101
+ );
102
+ INSERT INTO durability_fanout_deliveries
103
+ (id, message_key, target_id, seq, status, phase, attempt,
104
+ next_attempt_at, last_error, last_error_name, created_at,
105
+ generation_id, dead_lettered_at, dead_letter_reason, channel)
106
+ SELECT id, message_key, target_id, seq, status, phase, attempt,
107
+ next_attempt_at, last_error, last_error_name, created_at,
108
+ generation_id, dead_lettered_at, dead_letter_reason, 'default'
109
+ FROM durability_fanout_deliveries_before_channels;
110
+ DROP TABLE durability_fanout_deliveries_before_channels;
111
+ CREATE INDEX durability_fanout_deliveries_due_idx
112
+ ON durability_fanout_deliveries
113
+ (channel, target_id, phase, status, attempt, seq, next_attempt_at);
114
+ CREATE INDEX durability_fanout_deliveries_pending_idx
115
+ ON durability_fanout_deliveries (phase, status, next_attempt_at);
116
+ CREATE INDEX durability_fanout_deliveries_created_idx
117
+ ON durability_fanout_deliveries (created_at);
118
+ CREATE INDEX durability_fanout_deliveries_channel_pending_idx
119
+ ON durability_fanout_deliveries (channel, status, next_attempt_at);
120
+ `,
121
+ down: `
122
+ CREATE TABLE durability_fanout_channel_guard (
123
+ channel TEXT CONSTRAINT cannot_downgrade_nondefault_channels CHECK (channel = 'default')
124
+ );
125
+ INSERT INTO durability_fanout_channel_guard
126
+ SELECT DISTINCT channel FROM durability_fanout_messages
127
+ UNION SELECT DISTINCT channel FROM durability_fanout_deliveries;
128
+ DROP TABLE durability_fanout_channel_guard;
129
+
130
+ ALTER TABLE durability_fanout_messages
131
+ RENAME TO durability_fanout_messages_with_channels;
132
+ CREATE TABLE durability_fanout_messages (
133
+ key TEXT PRIMARY KEY,
134
+ id TEXT NOT NULL,
135
+ payload TEXT NOT NULL,
136
+ targets TEXT NOT NULL,
137
+ remaining INTEGER NOT NULL,
138
+ seq INTEGER NOT NULL,
139
+ created_at INTEGER NOT NULL,
140
+ generation_id TEXT NOT NULL
141
+ );
142
+ INSERT INTO durability_fanout_messages
143
+ SELECT key, id, payload, targets, remaining, seq, created_at,
144
+ generation_id
145
+ FROM durability_fanout_messages_with_channels;
146
+ DROP TABLE durability_fanout_messages_with_channels;
147
+
148
+ ALTER TABLE durability_fanout_deliveries
149
+ RENAME TO durability_fanout_deliveries_with_channels;
150
+ CREATE TABLE durability_fanout_deliveries (
151
+ id TEXT PRIMARY KEY,
152
+ message_key TEXT NOT NULL,
153
+ target_id TEXT NOT NULL,
154
+ seq INTEGER NOT NULL,
155
+ status TEXT NOT NULL CHECK (status IN ('pending')),
156
+ phase TEXT NOT NULL CHECK (phase IN ('delivery', 'dead_letter')),
157
+ attempt INTEGER NOT NULL DEFAULT 0,
158
+ next_attempt_at INTEGER NOT NULL,
159
+ last_error TEXT,
160
+ last_error_name TEXT,
161
+ created_at INTEGER NOT NULL,
162
+ generation_id TEXT NOT NULL,
163
+ dead_lettered_at INTEGER,
164
+ dead_letter_reason TEXT CHECK (dead_letter_reason IN ('explicit', 'exhausted'))
165
+ );
166
+ INSERT INTO durability_fanout_deliveries
167
+ SELECT id, message_key, target_id, seq, status, phase, attempt,
168
+ next_attempt_at, last_error, last_error_name, created_at,
169
+ generation_id, dead_lettered_at, dead_letter_reason
170
+ FROM durability_fanout_deliveries_with_channels;
171
+ DROP TABLE durability_fanout_deliveries_with_channels;
172
+ CREATE INDEX durability_fanout_deliveries_due_idx
173
+ ON durability_fanout_deliveries
174
+ (target_id, phase, status, attempt, seq, next_attempt_at);
175
+ CREATE INDEX durability_fanout_deliveries_pending_idx
176
+ ON durability_fanout_deliveries (phase, status, next_attempt_at);
177
+ CREATE INDEX durability_fanout_deliveries_created_idx
178
+ ON durability_fanout_deliveries (created_at);
179
+ `,
180
+ },
181
+ ];
@@ -1,4 +1,4 @@
1
- import type { SerializedError } from './errors.js';
1
+ import type { SerializedError } from '../errors.js';
2
2
  /**
3
3
  * One message as handed to a storage destination. Archive and dead-letter
4
4
  * writes share this envelope; only `failure` distinguishes them.
package/dist/index.d.ts CHANGED
@@ -1,13 +1,18 @@
1
- export { Durability, type DurabilityConfig, type DurabilityConstructor, type DurabilityOptions, type DurableCall, type DurableHandler, type DurableOperation, type DurableOperationResult, type DurabilityOperationEvent, type HandlerMap, } from './durability.js';
2
- export { DurabilityAlarms, type DurabilityAlarmsConfig, type DurabilityAlarmsConstructor, type DurabilityAlarmsOptions, type DurabilityAlarmEvent, type DurableAlarmHandler, type DurableAlarmInfo, type DurableNamedAlarm, } from './durability-alarms.js';
3
- export { maxMemoBytes, maxMemosPerRecord, type DurableMemoize, } from './memoize.js';
4
- export { DurabilityFanout, type DurabilityFanoutConfig, type DurabilityFanoutEvent, type DurabilityFanoutMessage, type FanoutInput, type FanoutTarget, type FanoutEnqueueOptions, } from './fanout.js';
5
- export { DurabilityLog, maxLogBytes, type DurabilityLogConfig, type LogAppendInput, type LogColdStorage, type LogLease, type LogLeaseOptions, type LogPage, type LogReadOptions, type LogRecord, type LogRetention, type LogSegment, type LogBounds, } from './log.js';
6
- export { RoutingLoad, type EnqueueResult, type LoadSnapshot, type ProcessingLoad, } from './load.js';
7
- export type { MessageWrite, StoredMessage } from './stored-message.js';
8
- export { DurabilityScheduler, type DurabilityContext, type DurabilitySchedulerConfig, type DurabilitySchedulerOptions, type SchedulerAttachment, } from './scheduler.js';
1
+ export { Durability, type DurabilityConfig, type DurabilityConstructor, type DurabilityOptions, type DurableCall, type DurableHandler, type DurableOperation, type DurableOperationResult, type DurabilityOperationEvent, type HandlerMap, } from './operations/index.js';
2
+ export { DurabilityAlarms, type DurabilityAlarmsConfig, type DurabilityAlarmsConstructor, type DurabilityAlarmsOptions, type DurabilityAlarmEvent, type DurableAlarmHandler, type DurableAlarmInfo, type DurableNamedAlarm, } from './alarms/index.js';
3
+ export { maxMemoBytes, maxMemosPerRecord, type DurableMemoize, } from './memoize/index.js';
4
+ export { DurabilityFanout, type DurabilityFanoutConfig, type DurabilityFanoutEvent, type DurabilityFanoutMessage, type FanoutInput, type FanoutTarget, type FanoutEnqueueOptions, } from './fanout/index.js';
5
+ export { DurabilityLog, maxLogBytes, type DurabilityLogConfig, type LogAppendInput, type LogColdStorage, type LogLease, type LogLeaseOptions, type LogPage, type LogReadOptions, type LogRecord, type LogRetention, type LogSegment, type LogBounds, } from './log/index.js';
6
+ export { RoutingLoad, type EnqueueResult, type LoadSnapshot, type ProcessingLoad, } from './routing/load.js';
7
+ export type { MessageWrite, StoredMessage } from './fanout/stored-message.js';
8
+ export { DurabilityScheduler, type AlarmRetryInfo, type DurabilityContext, type DurabilitySchedulerConfig, type DurabilitySchedulerOptions, type SchedulerAttachment, } from './scheduler/index.js';
9
9
  export { DuplicateDurableCallError, DuplicateDurablePayloadError, DurableAlarmTimeoutError, DurableAttemptsExhaustedError, DurableAttemptTimeoutError, DurableResultSerializationError, DurableRetryPolicyError, DurableMemoLimitError, DurableMemoSerializationError, NonRetryableError, FanoutTimeoutError, FanoutSettlementError, FanoutEnqueueError, LogAppendError, LogLeaseError, LogTruncatedError, RoutingError, } from './errors.js';
10
10
  export type { DurabilityLifecycleEvent, LifecycleHook } from './lifecycle.js';
11
- export { durabilityNamedAlarmMigrations, durabilityOperationMigrations, durabilityFanoutMigrations, durabilityLogLeaseMigrations, durabilityLogMigrations, durabilityMemoMigrations, migrate, type DurabilityMigrationResult, type MigrateOptions, type MigrationCapability, } from './migrations.js';
11
+ export { durabilityNamedAlarmMigrations } from './alarms/migrations.js';
12
+ export { durabilityOperationMigrations } from './operations/migrations.js';
13
+ export { durabilityFanoutMigrations } from './fanout/migrations.js';
14
+ export { durabilityLogLeaseMigrations, durabilityLogMigrations, } from './log/migrations.js';
15
+ export { durabilityMemoMigrations } from './memoize/migrations.js';
16
+ export { migrate, type DurabilityMigrationResult, type MigrateOptions, type MigrationCapability, } from './migrations.js';
12
17
  export type { DurableMigrations } from '@durability/storage';
13
18
  export type { DurabilityAlarmMethodOptions, DurabilityMethodOptions, DurabilityRetryOptions, } from './policy.js';
package/dist/index.js CHANGED
@@ -1,9 +1,14 @@
1
- export { Durability, } from './durability.js';
2
- export { DurabilityAlarms, } from './durability-alarms.js';
3
- export { maxMemoBytes, maxMemosPerRecord, } from './memoize.js';
4
- export { DurabilityFanout, } from './fanout.js';
5
- export { DurabilityLog, maxLogBytes, } from './log.js';
6
- export { RoutingLoad, } from './load.js';
7
- export { DurabilityScheduler, } from './scheduler.js';
1
+ export { Durability, } from './operations/index.js';
2
+ export { DurabilityAlarms, } from './alarms/index.js';
3
+ export { maxMemoBytes, maxMemosPerRecord, } from './memoize/index.js';
4
+ export { DurabilityFanout, } from './fanout/index.js';
5
+ export { DurabilityLog, maxLogBytes, } from './log/index.js';
6
+ export { RoutingLoad, } from './routing/load.js';
7
+ export { DurabilityScheduler, } from './scheduler/index.js';
8
8
  export { DuplicateDurableCallError, DuplicateDurablePayloadError, DurableAlarmTimeoutError, DurableAttemptsExhaustedError, DurableAttemptTimeoutError, DurableResultSerializationError, DurableRetryPolicyError, DurableMemoLimitError, DurableMemoSerializationError, NonRetryableError, FanoutTimeoutError, FanoutSettlementError, FanoutEnqueueError, LogAppendError, LogLeaseError, LogTruncatedError, RoutingError, } from './errors.js';
9
- export { durabilityNamedAlarmMigrations, durabilityOperationMigrations, durabilityFanoutMigrations, durabilityLogLeaseMigrations, durabilityLogMigrations, durabilityMemoMigrations, migrate, } from './migrations.js';
9
+ export { durabilityNamedAlarmMigrations } from './alarms/migrations.js';
10
+ export { durabilityOperationMigrations } from './operations/migrations.js';
11
+ export { durabilityFanoutMigrations } from './fanout/migrations.js';
12
+ export { durabilityLogLeaseMigrations, durabilityLogMigrations, } from './log/migrations.js';
13
+ export { durabilityMemoMigrations } from './memoize/migrations.js';
14
+ export { migrate, } from './migrations.js';
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
- import { RoutingLoad, type EnqueueResult, type LoadSnapshot } from './load.js';
3
- import { type SchedulerAttachment } from './scheduler.js';
2
+ import { RoutingLoad, type EnqueueResult, type LoadSnapshot } from '../routing/load.js';
3
+ import { type SchedulerAttachment } from '../scheduler/index.js';
4
4
  /**
5
5
  * One in-flight or settled range of offsets held by a consumer. A range is
6
6
  * redelivered under a fresh `batch_id`, so an ack from a previous holder is
@@ -60,6 +60,12 @@ export type LogReadOptions = {
60
60
  };
61
61
  /** One contiguous run of records leaving the object, oldest first. */
62
62
  export type LogSegment<Body = unknown> = {
63
+ /**
64
+ * The log always supplies its channel. Optional for legacy callers that
65
+ * construct segments themselves; omitted means `default`. Shared external
66
+ * storage must include the channel in the location it writes to.
67
+ */
68
+ channel?: string;
63
69
  firstOffset: number;
64
70
  lastOffset: number;
65
71
  records: LogRecord<Body>[];
@@ -109,6 +115,12 @@ export type LogRetention = {
109
115
  maxBytes?: number;
110
116
  };
111
117
  export type DurabilityLogConfig<Body = unknown> = SchedulerAttachment & {
118
+ /**
119
+ * Partitions records, offsets, cursors, cold segments, and leases, so
120
+ * several logs share one object without seeing each other. Defaults to
121
+ * `default`; one instance per channel may attach to a scheduler.
122
+ */
123
+ channel?: string;
112
124
  /** Without retention the log grows until the object's storage limit. */
113
125
  retention?: LogRetention;
114
126
  cold?: LogColdStorage<Body>;
@@ -135,7 +147,7 @@ export declare const maxLogBytes = 1073741824;
135
147
  export declare class DurabilityLog<Body = unknown> {
136
148
  #private;
137
149
  constructor(config: DurabilityLogConfig<Body>);
138
- static migrate(context: Pick<DurableObjectState, 'storage'>, target?: string | null): import("./migrations.js").DurabilityMigrationResult;
150
+ static migrate(context: Pick<DurableObjectState, 'storage'>, target?: string | null): import("../migrations.js").DurabilityMigrationResult;
139
151
  /**
140
152
  * Appends the batch atomically. Definite input rejections return
141
153
  * success:false; storage and commit uncertainty throws, so a caller never