durability 5.1.0 → 5.2.1

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 (98) hide show
  1. package/README.md +154 -21
  2. package/dist/{durability-alarms.d.ts → alarms/index.d.ts} +13 -5
  3. package/dist/{durability-alarms.js → alarms/index.js} +85 -74
  4. package/dist/alarms/migrations.d.ts +9 -0
  5. package/dist/alarms/migrations.js +133 -0
  6. package/dist/experimental.d.ts +10 -10
  7. package/dist/experimental.js +7 -7
  8. package/dist/{fanout.d.ts → fanout/index.d.ts} +13 -6
  9. package/dist/{fanout.js → fanout/index.js} +91 -83
  10. package/dist/fanout/migrations.d.ts +9 -0
  11. package/dist/fanout/migrations.js +181 -0
  12. package/dist/{stored-message.d.ts → fanout/stored-message.d.ts} +1 -1
  13. package/dist/index.d.ts +14 -9
  14. package/dist/index.js +13 -8
  15. package/dist/{log.d.ts → log/index.d.ts} +27 -20
  16. package/dist/{log.js → log/index.js} +200 -166
  17. package/dist/log/migrations.d.ts +18 -0
  18. package/dist/log/migrations.js +297 -0
  19. package/dist/{memoize.d.ts → memoize/index.d.ts} +1 -1
  20. package/dist/{memoize.js → memoize/index.js} +23 -21
  21. package/dist/memoize/migrations.d.ts +10 -0
  22. package/dist/memoize/migrations.js +21 -0
  23. package/dist/migrations.d.ts +0 -111
  24. package/dist/migrations.js +12 -628
  25. package/dist/{durability.d.ts → operations/index.d.ts} +13 -5
  26. package/dist/{durability.js → operations/index.js} +76 -70
  27. package/dist/operations/migrations.d.ts +10 -0
  28. package/dist/operations/migrations.js +150 -0
  29. package/dist/{outbox.d.ts → outbox/index.d.ts} +4 -4
  30. package/dist/{outbox.js → outbox/index.js} +35 -77
  31. package/dist/outbox/migrations.d.ts +9 -0
  32. package/dist/outbox/migrations.js +43 -0
  33. package/dist/policy.d.ts +19 -19
  34. package/dist/policy.js +13 -12
  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.d.ts → schedule/index.d.ts} +16 -8
  40. package/dist/{schedule.js → schedule/index.js} +97 -83
  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} +75 -25
  44. package/dist/{scheduler.js → scheduler/index.js} +308 -70
  45. package/dist/{semaphore-client.d.ts → semaphore/client.d.ts} +1 -1
  46. package/dist/{semaphore-client.js → semaphore/client.js} +8 -7
  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 +451 -0
  54. package/dist/semaphore/protocol.js +114 -0
  55. package/dist/semaphore/queue-store.d.ts +107 -0
  56. package/dist/semaphore/queue-store.js +258 -0
  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} +56 -28
  61. package/dist/semaphore/store.d.ts +53 -0
  62. package/dist/semaphore/store.js +107 -0
  63. package/dist/serialization.d.ts +5 -0
  64. package/dist/serialization.js +41 -16
  65. package/dist/{client.d.ts → socket/client.d.ts} +3 -3
  66. package/dist/{client.js → socket/client.js} +4 -4
  67. package/dist/{socket.d.ts → socket/index.d.ts} +15 -4
  68. package/dist/{socket.js → socket/index.js} +66 -20
  69. package/dist/socket/migrations.d.ts +9 -0
  70. package/dist/socket/migrations.js +57 -0
  71. package/dist/{socket-protocol.d.ts → socket/protocol.d.ts} +1 -1
  72. package/dist/storage.d.ts +4 -0
  73. package/dist/storage.js +22 -15
  74. package/dist/{topology-client.d.ts → topology/client.d.ts} +2 -2
  75. package/dist/{topology-client.js → topology/client.js} +3 -3
  76. package/dist/{topology.d.ts → topology/index.d.ts} +17 -7
  77. package/dist/{topology.js → topology/index.js} +106 -72
  78. package/dist/topology/migrations.d.ts +10 -0
  79. package/dist/topology/migrations.js +138 -0
  80. package/dist/topology/snapshot.d.ts +50 -0
  81. package/dist/topology/snapshot.js +38 -0
  82. package/dist/{tracker.d.ts → tracker/index.d.ts} +3 -3
  83. package/dist/{tracker.js → tracker/index.js} +9 -9
  84. package/package.json +11 -11
  85. package/dist/semaphore-protocol.d.ts +0 -231
  86. package/dist/semaphore-protocol.js +0 -106
  87. package/dist/semaphore-queue-store.d.ts +0 -95
  88. package/dist/semaphore-queue-store.js +0 -252
  89. package/dist/semaphore-store.d.ts +0 -43
  90. package/dist/semaphore-store.js +0 -108
  91. package/dist/topology-snapshot.d.ts +0 -70
  92. package/dist/topology-snapshot.js +0 -48
  93. /package/dist/{stored-message.js → fanout/stored-message.js} +0 -0
  94. /package/dist/{routing-client.d.ts → routing/client.d.ts} +0 -0
  95. /package/dist/{load.js → routing/load.js} +0 -0
  96. /package/dist/{socket-protocol.js → socket/protocol.js} +0 -0
  97. /package/dist/{tracked-source.d.ts → tracker/source.d.ts} +0 -0
  98. /package/dist/{tracked-source.js → tracker/source.js} +0 -0
@@ -10,33 +10,35 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _DurabilityOutbox_instances, _DurabilityOutbox_engine, _DurabilityOutbox_channel, _DurabilityOutbox_publish, _DurabilityOutbox_maxBatchSize, _DurabilityOutbox_batchDelayMs, _DurabilityOutbox_attemptTimeoutMs, _DurabilityOutbox_delay, _DurabilityOutbox_emit, _DurabilityOutbox_running, _DurabilityOutbox_stageIn, _DurabilityOutbox_emitRegistered, _DurabilityOutbox_attach, _DurabilityOutbox_firstAttemptAt, _DurabilityOutbox_runDue, _DurabilityOutbox_publishNow, _DurabilityOutbox_exclusive, _DurabilityOutbox_runBatch, _DurabilityOutbox_publishBatch, _DurabilityOutbox_retryDelay, _DurabilityOutbox_deadline;
13
- import { traceLifecycle, traceMethods } from './dev.js';
14
- import { OutboxTimeoutError, reportFailure, serializeError, } from './errors.js';
15
- import { durabilityOutboxMigrations, migrateCapability, } from './migrations.js';
16
- import { assertPositiveInteger, } from './policy.js';
17
- import { engineFor, } from './scheduler.js';
18
- import { deserialize, serialize } from './serialization.js';
19
- import { claimAttempt, deleteAttempt, updateAttempt, } from './storage.js';
20
- import { exponential, jitter } from './utils.js';
21
- import { z } from 'zod';
13
+ import { traceLifecycle, traceMethods } from '../dev.js';
14
+ import { OutboxTimeoutError, reportFailure, serializeError, } from '../errors.js';
15
+ import { durabilityOutboxMigrations } from './migrations.js';
16
+ import { migrateCapability, } from '../migrations.js';
17
+ import { assertPositiveInteger, } from '../policy.js';
18
+ import { assertChannel, defaultChannel, engineFor, } from '../scheduler/index.js';
19
+ import { deserialize, serialize } from '../serialization.js';
20
+ import { claimAttempt, deleteAttempt, updateAttempt, } from '../storage.js';
21
+ import { exponential, jitter } from '../utils.js';
22
+ import * as v from 'valibot';
22
23
  const outboxTable = { name: 'durability_outbox', key: 'id' };
23
- const outboxRowSchema = z.object({
24
- id: z.string(),
25
- channel: z.string(),
26
- entry_key: z.string(),
27
- version: z.number().int().positive(),
28
- payload: z.string(),
29
- status: z.literal('pending'),
30
- attempt: z.number().int().nonnegative(),
31
- next_attempt_at: z.number().int().nonnegative(),
32
- last_error: z.string().nullable(),
33
- last_error_name: z.string().nullable(),
34
- created_at: z.number().int().nonnegative(),
35
- generation_id: z.string(),
24
+ const outboxRowSchema = v.object({
25
+ id: v.string(),
26
+ channel: v.string(),
27
+ entry_key: v.string(),
28
+ version: v.pipe(v.number(), v.safeInteger(), v.gtValue(0)),
29
+ payload: v.string(),
30
+ status: v.literal('pending'),
31
+ attempt: v.pipe(v.number(), v.safeInteger(), v.minValue(0)),
32
+ next_attempt_at: v.pipe(v.number(), v.safeInteger(), v.minValue(0)),
33
+ last_error: v.nullable(v.string()),
34
+ last_error_name: v.nullable(v.string()),
35
+ created_at: v.pipe(v.number(), v.safeInteger(), v.minValue(0)),
36
+ generation_id: v.string(),
36
37
  });
37
- const versionRowSchema = z.object({ version: z.number().int().positive() });
38
- const channelRowSchema = z.object({ channel: z.string() });
39
- const listDueForChannel = (sql, channel, now, limit, key) => outboxRowSchema.array().parse(sql
38
+ const versionRowSchema = v.object({
39
+ version: v.pipe(v.number(), v.safeInteger(), v.gtValue(0)),
40
+ });
41
+ const listDueForChannel = (sql, channel, now, limit, key) => v.parse(v.array(outboxRowSchema), sql
40
42
  .exec(`SELECT * FROM durability_outbox
41
43
  WHERE channel = ? AND status = 'pending' AND next_attempt_at <= ?
42
44
  AND (? IS NULL OR entry_key = ?)
@@ -45,7 +47,7 @@ const listDueForChannel = (sql, channel, now, limit, key) => outboxRowSchema.arr
45
47
  .toArray());
46
48
  /** Allocates a version from a durable counter that survives row deletion. */
47
49
  const nextVersion = (sql) => {
48
- const { version } = versionRowSchema.parse(sql
50
+ const { version } = v.parse(versionRowSchema, sql
49
51
  .exec(`UPDATE durability_outbox_seq
50
52
  SET next_version = next_version + 1
51
53
  WHERE id = 1
@@ -79,8 +81,6 @@ const infrastructureRetryMs = 60000;
79
81
  // setTimeout overflows past 2^31 - 1 ms, and it keeps every derived timestamp
80
82
  // far inside the safe-integer range the storage indexes accept.
81
83
  const maxDelayMs = 2 ** 31 - 1;
82
- const orphanBatchSize = 50;
83
- const channelsByEngine = new WeakMap();
84
84
  const rowId = (channel, key) => JSON.stringify([channel, key]);
85
85
  const entity = (row) => ({
86
86
  entityKind: 'outbox_entry',
@@ -88,33 +88,6 @@ const entity = (row) => ({
88
88
  id: row.entry_key,
89
89
  generation: row.generation_id,
90
90
  });
91
- /**
92
- * Rows of a channel no outbox registers would stay due forever and keep the
93
- * alarm awake, so they are postponed like a removed fanout target's work.
94
- */
95
- const postponeOrphans = async (engine, channels) => {
96
- const orphans = channelRowSchema
97
- .array()
98
- .parse(engine.sql
99
- .exec('SELECT DISTINCT channel FROM durability_outbox ORDER BY channel')
100
- .toArray())
101
- .map((row) => row.channel)
102
- .filter((channel) => !channels.has(channel));
103
- for (const channel of orphans) {
104
- const due = listDueForChannel(engine.sql, channel, Date.now(), orphanBatchSize);
105
- if (due.length === 0) {
106
- continue;
107
- }
108
- reportFailure('durability.outbox.channel_missing', { channel }, new Error(`Outbox channel "${channel}" is no longer configured; retaining entries`));
109
- // eslint-disable-next-line no-await-in-loop
110
- await engine.transaction((sql) => {
111
- const postponedTo = Date.now() + infrastructureRetryMs;
112
- for (const row of due) {
113
- updateAttempt(sql, outboxTable, { key: row.id, generation: row.generation_id, attempt: row.attempt }, 'next_attempt_at = ?', postponedTo);
114
- }
115
- });
116
- }
117
- };
118
91
  /**
119
92
  * A composable DO capability: keyed latest-state publication. Stage the
120
93
  * newest value for a key in the same transaction as the state it describes;
@@ -134,10 +107,7 @@ export class DurabilityOutbox {
134
107
  _DurabilityOutbox_emit.set(this, void 0);
135
108
  /** The channel's one publish run, never one still waiting for a permit. */
136
109
  _DurabilityOutbox_running.set(this, void 0);
137
- __classPrivateFieldSet(this, _DurabilityOutbox_channel, config.channel ?? 'default', "f");
138
- if (typeof __classPrivateFieldGet(this, _DurabilityOutbox_channel, "f") !== 'string' || __classPrivateFieldGet(this, _DurabilityOutbox_channel, "f").length === 0) {
139
- throw new TypeError('Outbox channel must be a non-empty string');
140
- }
110
+ __classPrivateFieldSet(this, _DurabilityOutbox_channel, assertChannel('Outbox', config.channel ?? defaultChannel), "f");
141
111
  if (typeof config.publish !== 'function') {
142
112
  throw new TypeError('Outbox requires a publish function');
143
113
  }
@@ -215,24 +185,12 @@ _DurabilityOutbox_engine = new WeakMap(), _DurabilityOutbox_channel = new WeakMa
215
185
  attempt: 0,
216
186
  });
217
187
  }, _DurabilityOutbox_attach = function _DurabilityOutbox_attach() {
218
- let channels = channelsByEngine.get(__classPrivateFieldGet(this, _DurabilityOutbox_engine, "f"));
219
- if (!channels) {
220
- const created = new Map();
221
- const engine = __classPrivateFieldGet(this, _DurabilityOutbox_engine, "f");
222
- engine.register({
223
- table: outboxTable,
224
- runDue: async () => {
225
- await Promise.all([...created.values()].map((run) => run()));
226
- await postponeOrphans(engine, created);
227
- },
228
- });
229
- channelsByEngine.set(engine, created);
230
- channels = created;
231
- }
232
- if (channels.has(__classPrivateFieldGet(this, _DurabilityOutbox_channel, "f"))) {
233
- throw new Error(`An outbox for channel "${__classPrivateFieldGet(this, _DurabilityOutbox_channel, "f")}" is already attached to this scheduler`);
234
- }
235
- channels.set(__classPrivateFieldGet(this, _DurabilityOutbox_channel, "f"), () => __classPrivateFieldGet(this, _DurabilityOutbox_instances, "m", _DurabilityOutbox_runDue).call(this));
188
+ __classPrivateFieldGet(this, _DurabilityOutbox_engine, "f").registerChannel({
189
+ table: outboxTable,
190
+ channel: __classPrivateFieldGet(this, _DurabilityOutbox_channel, "f"),
191
+ helper: 'An outbox',
192
+ runDue: () => __classPrivateFieldGet(this, _DurabilityOutbox_instances, "m", _DurabilityOutbox_runDue).call(this),
193
+ });
236
194
  }, _DurabilityOutbox_firstAttemptAt = function _DurabilityOutbox_firstAttemptAt(createdAt) {
237
195
  if (__classPrivateFieldGet(this, _DurabilityOutbox_batchDelayMs, "f") === 0) {
238
196
  return createdAt;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Ordered SQLite migrations for outbox channels. Applied automatically on
3
+ * construction.
4
+ */
5
+ export declare const durabilityOutboxMigrations: {
6
+ name: string;
7
+ up: string;
8
+ down: string;
9
+ }[];
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Ordered SQLite migrations for outbox channels. Applied automatically on
3
+ * construction.
4
+ */
5
+ export const durabilityOutboxMigrations = [
6
+ {
7
+ name: 'durability_0006_create_outbox',
8
+ up: `
9
+ CREATE TABLE IF NOT EXISTS durability_outbox (
10
+ id TEXT PRIMARY KEY,
11
+ channel TEXT NOT NULL,
12
+ entry_key TEXT NOT NULL,
13
+ version INTEGER NOT NULL,
14
+ payload TEXT NOT NULL,
15
+ status TEXT NOT NULL CHECK (status IN ('pending')),
16
+ attempt INTEGER NOT NULL DEFAULT 0,
17
+ next_attempt_at INTEGER NOT NULL,
18
+ last_error TEXT,
19
+ last_error_name TEXT,
20
+ created_at INTEGER NOT NULL,
21
+ generation_id TEXT NOT NULL
22
+ );
23
+ CREATE INDEX IF NOT EXISTS durability_outbox_due_idx
24
+ ON durability_outbox (channel, status, next_attempt_at, version);
25
+ CREATE INDEX IF NOT EXISTS durability_outbox_pending_idx
26
+ ON durability_outbox (status, next_attempt_at);
27
+ CREATE INDEX IF NOT EXISTS durability_outbox_created_idx
28
+ ON durability_outbox (created_at);
29
+ CREATE TABLE IF NOT EXISTS durability_outbox_seq (
30
+ id INTEGER PRIMARY KEY CHECK (id = 1),
31
+ next_version INTEGER NOT NULL
32
+ );
33
+ INSERT OR IGNORE INTO durability_outbox_seq (id, next_version) VALUES (1, 1);
34
+ `,
35
+ down: `
36
+ DROP INDEX IF EXISTS durability_outbox_due_idx;
37
+ DROP INDEX IF EXISTS durability_outbox_pending_idx;
38
+ DROP INDEX IF EXISTS durability_outbox_created_idx;
39
+ DROP TABLE IF EXISTS durability_outbox;
40
+ DROP TABLE IF EXISTS durability_outbox_seq;
41
+ `,
42
+ },
43
+ ];
package/dist/policy.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { z } from 'zod';
1
+ import * as v from 'valibot';
2
2
  /**
3
3
  * Retry policy shared by all methods or overridden for one method.
4
4
  *
@@ -46,23 +46,23 @@ export type AttemptPolicy = {
46
46
  delay: (attempt: number) => number;
47
47
  maxAttempts: number;
48
48
  };
49
- export declare const methodOptionsSchema: z.ZodObject<{
50
- attemptTimeoutMs: z.ZodOptional<z.ZodNumber>;
51
- retries: z.ZodOptional<z.ZodObject<{
52
- delay: z.ZodOptional<z.ZodCustom<(attempt: number) => number, (attempt: number) => number>>;
53
- maxAttempts: z.ZodOptional<z.ZodNumber>;
54
- }, z.core.$strip>>;
55
- }, z.core.$strip>;
56
- export declare const alarmMethodOptionsSchema: z.ZodObject<{
57
- attemptTimeoutMs: z.ZodOptional<z.ZodNumber>;
58
- retries: z.ZodOptional<z.ZodObject<{
59
- delay: z.ZodOptional<z.ZodCustom<(attempt: number) => number, (attempt: number) => number>>;
60
- maxAttempts: z.ZodOptional<z.ZodNumber>;
61
- }, z.core.$strip>>;
62
- retryTimeouts: z.ZodOptional<z.ZodBoolean>;
63
- }, z.core.$strip>;
64
- export type MethodPolicy = z.infer<typeof methodOptionsSchema>;
65
- export type AlarmMethodPolicy = z.infer<typeof alarmMethodOptionsSchema>;
49
+ export declare const methodOptionsSchema: v.ObjectSchema<{
50
+ readonly attemptTimeoutMs: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
51
+ readonly retries: v.OptionalSchema<v.ObjectSchema<{
52
+ readonly delay: v.OptionalSchema<v.CustomSchema<(attempt: number) => number, undefined>, undefined>;
53
+ readonly maxAttempts: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
54
+ }, undefined>, undefined>;
55
+ }, undefined>;
56
+ export declare const alarmMethodOptionsSchema: v.ObjectSchema<{
57
+ readonly retryTimeouts: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
58
+ readonly attemptTimeoutMs: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
59
+ readonly retries: v.OptionalSchema<v.ObjectSchema<{
60
+ readonly delay: v.OptionalSchema<v.CustomSchema<(attempt: number) => number, undefined>, undefined>;
61
+ readonly maxAttempts: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
62
+ }, undefined>, undefined>;
63
+ }, undefined>;
64
+ export type MethodPolicy = v.InferOutput<typeof methodOptionsSchema>;
65
+ export type AlarmMethodPolicy = v.InferOutput<typeof alarmMethodOptionsSchema>;
66
66
  export declare const assertPositiveInteger: (name: string, value: number) => void;
67
67
  /**
68
68
  * Validates global and per-method policy options once and resolves the
@@ -71,4 +71,4 @@ export declare const assertPositiveInteger: (name: string, value: number) => voi
71
71
  export type PolicyResolver<Method> = (name: string) => AttemptPolicy & {
72
72
  method: Method | undefined;
73
73
  };
74
- export declare const createPolicyResolver: <Method extends MethodPolicy>(options: ExecutionPolicyOptions, methods: Record<string, unknown>, methodSchema: z.ZodType<Method>) => PolicyResolver<Method>;
74
+ export declare const createPolicyResolver: <Method extends MethodPolicy>(options: ExecutionPolicyOptions, methods: Record<string, unknown>, methodSchema: v.GenericSchema<unknown, Method>) => PolicyResolver<Method>;
package/dist/policy.js CHANGED
@@ -1,16 +1,17 @@
1
- import { z } from 'zod';
1
+ import * as v from 'valibot';
2
2
  import { exponential, jitter } from './utils.js';
3
- const functionSchema = () => z.custom((value) => typeof value === 'function');
4
- const retryOptionsSchema = z.object({
5
- delay: functionSchema().optional(),
6
- maxAttempts: z.number().optional(),
3
+ const functionSchema = () => v.custom((value) => typeof value === 'function');
4
+ const retryOptionsSchema = v.object({
5
+ delay: v.optional(functionSchema()),
6
+ maxAttempts: v.optional(v.number()),
7
7
  });
8
- export const methodOptionsSchema = z.object({
9
- attemptTimeoutMs: z.number().optional(),
10
- retries: retryOptionsSchema.optional(),
8
+ export const methodOptionsSchema = v.object({
9
+ attemptTimeoutMs: v.optional(v.number()),
10
+ retries: v.optional(retryOptionsSchema),
11
11
  });
12
- export const alarmMethodOptionsSchema = methodOptionsSchema.extend({
13
- retryTimeouts: z.boolean().optional(),
12
+ export const alarmMethodOptionsSchema = v.object({
13
+ ...methodOptionsSchema.entries,
14
+ retryTimeouts: v.optional(v.boolean()),
14
15
  });
15
16
  export const assertPositiveInteger = (name, value) => {
16
17
  if (!Number.isInteger(value) || value < 1) {
@@ -27,13 +28,13 @@ const assertMethodOptions = (prefix, method) => {
27
28
  };
28
29
  export const createPolicyResolver = (options, methods, methodSchema) => {
29
30
  const attemptTimeoutMs = options.attemptTimeoutMs ?? 5 * 60000;
30
- const retries = retryOptionsSchema.parse(options.retries ?? {});
31
+ const retries = v.parse(retryOptionsSchema, options.retries ?? {});
31
32
  const delay = retries.delay ?? ((attempt) => jitter(exponential(attempt)));
32
33
  const maxAttempts = retries.maxAttempts ?? 5;
33
34
  assertPositiveInteger('attemptTimeoutMs', attemptTimeoutMs);
34
35
  assertPositiveInteger('retries.maxAttempts', maxAttempts);
35
36
  const parsed = new Map(Object.entries(methods).map(([name, method]) => {
36
- const valid = methodSchema.parse(method);
37
+ const valid = v.parse(methodSchema, method);
37
38
  assertMethodOptions(`methods.${name}`, valid);
38
39
  return [name, valid];
39
40
  }));
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _RoutingClient_instances, _RoutingClient_config, _RoutingClient_observations, _RoutingClient_limit, _RoutingClient_width, _RoutingClient_lastResize, _RoutingClient_select, _RoutingClient_resize;
13
- import { RoutingError } from './errors.js';
13
+ import { RoutingError } from '../errors.js';
14
14
  /**
15
15
  * Transport-independent selection and observation. Every push invokes ONE
16
16
  * shard once. A false result is returned unchanged; transport failures throw.
@@ -1,9 +1,9 @@
1
1
  import { type TransformContext, type TransformStub } from '@durability/transforms';
2
- import { type DurableObjectTarget } from './durable-object-target.js';
2
+ import { type DurableObjectTarget } from '../durable-object-target.js';
3
3
  import { RoutingLoad, type EnqueueResult } from './load.js';
4
- import { type Sharding } from './routing-client.js';
4
+ import { type Sharding } from './client.js';
5
5
  export type { EnqueueResult, LoadSnapshot, ProcessingLoad } from './load.js';
6
- export type { RoutingAddress, RoutingTarget, Sharding, } from './routing-client.js';
6
+ export type { RoutingAddress, RoutingTarget, Sharding } from './client.js';
7
7
  export type RoutingSession<Input, Value, Context = unknown> = {
8
8
  push(input: Input, context?: Context): Promise<EnqueueResult<Value>>;
9
9
  setContext(context: TransformContext): {
@@ -1,8 +1,8 @@
1
1
  import { createTransformStub, } from '@durability/transforms';
2
- import { resolveNamespace, } from './durable-object-target.js';
3
- import { RoutingError } from './errors.js';
2
+ import { resolveNamespace, } from '../durable-object-target.js';
3
+ import { RoutingError } from '../errors.js';
4
4
  import { RoutingLoad } from './load.js';
5
- import { RoutingClient } from './routing-client.js';
5
+ import { RoutingClient } from './client.js';
6
6
  /**
7
7
  * Inside a DO, attach this local load observer to a fanout capability. Outside
8
8
  * the DO, client() routes calls to an application-owned class using ordinary
@@ -1,4 +1,4 @@
1
- import type { SerializedError } from './errors.js';
1
+ import type { SerializedError } from '../errors.js';
2
2
  /** Completion counts and timings cover the same rolling observation window. */
3
3
  export type ProcessingLoad = {
4
4
  inFlight: number;
@@ -1,7 +1,7 @@
1
- import { type SerializedError } from './errors.js';
2
- import { type DurabilityMigrationResult } from './migrations.js';
3
- import { type DurabilityRetryOptions } from './policy.js';
4
- import { type SchedulerAttachment } from './scheduler.js';
1
+ import { type SerializedError } from '../errors.js';
2
+ import { type DurabilityMigrationResult } from '../migrations.js';
3
+ import { type DurabilityRetryOptions } from '../policy.js';
4
+ import { type SchedulerAttachment } from '../scheduler/index.js';
5
5
  /** A schedule as passed to {@link DurabilitySchedule.set}. */
6
6
  export type ScheduleDefinition = {
7
7
  /** Opaque to durability: only `nextOccurrence` interprets it. */
@@ -45,7 +45,8 @@ export type ScheduledRun = {
45
45
  dueAt: number;
46
46
  /**
47
47
  * `<objectId>:<scheduledTime>`, or the bare scheduled time when the context
48
- * has no object ID. A tick fires at most once, so the key is unique per run.
48
+ * has no object ID. A named channel appends `:` and its JSON-encoded name.
49
+ * A tick fires at most once per channel, so the key is unique per run.
49
50
  */
50
51
  idempotencyKey: string;
51
52
  };
@@ -101,6 +102,13 @@ export type DurabilityScheduleEvent = ScheduledRunEntity & ({
101
102
  error: SerializedError;
102
103
  });
103
104
  export type DurabilityScheduleConfig = SchedulerAttachment & {
105
+ /**
106
+ * Stable channel ID. Instances on one scheduler share storage, partitioned
107
+ * by channel; each has its own schedule, runs and hooks. A library should
108
+ * use its own channel so its schedule never meets the application's.
109
+ * Defaults to `default`.
110
+ */
111
+ channel?: string;
104
112
  /**
105
113
  * Returns the first tick strictly after `after`, or `undefined` for none.
106
114
  * Must be synchronous and deterministic; durability ships no cron parser.
@@ -124,9 +132,9 @@ export type DurabilityScheduleConfig = SchedulerAttachment & {
124
132
  onLifecycleEvent?: (event: DurabilityScheduleEvent) => void | Promise<void>;
125
133
  };
126
134
  /**
127
- * Experimental. One recurring schedule per Durable Object whose ticks start
128
- * individually tracked, overlapping runs and report each run's outcome once,
129
- * keeping a run's row only until its outcome is delivered.
135
+ * Experimental. One recurring schedule per channel of a Durable Object whose
136
+ * ticks start individually tracked, overlapping runs and report each run's
137
+ * outcome once, keeping a run's row only until its outcome is delivered.
130
138
  *
131
139
  * A tick inserts its run in the transaction that advances the stored next
132
140
  * tick, so a tick fires at most once without retaining finished runs. Missed