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.
- package/README.md +154 -21
- package/dist/{durability-alarms.d.ts → alarms/index.d.ts} +13 -5
- package/dist/{durability-alarms.js → alarms/index.js} +85 -74
- 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} +91 -83
- 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} +27 -20
- package/dist/{log.js → log/index.js} +200 -166
- 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} +23 -21
- 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 +12 -628
- package/dist/{durability.d.ts → operations/index.d.ts} +13 -5
- package/dist/{durability.js → operations/index.js} +76 -70
- 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} +35 -77
- package/dist/outbox/migrations.d.ts +9 -0
- package/dist/outbox/migrations.js +43 -0
- package/dist/policy.d.ts +19 -19
- package/dist/policy.js +13 -12
- 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} +97 -83
- 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} +308 -70
- package/dist/{semaphore-client.d.ts → semaphore/client.d.ts} +1 -1
- package/dist/{semaphore-client.js → semaphore/client.js} +8 -7
- 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 +451 -0
- package/dist/semaphore/protocol.js +114 -0
- package/dist/semaphore/queue-store.d.ts +107 -0
- package/dist/semaphore/queue-store.js +258 -0
- 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} +56 -28
- package/dist/semaphore/store.d.ts +53 -0
- package/dist/semaphore/store.js +107 -0
- package/dist/serialization.d.ts +5 -0
- package/dist/serialization.js +41 -16
- 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 +22 -15
- 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} +106 -72
- package/dist/topology/migrations.d.ts +10 -0
- package/dist/topology/migrations.js +138 -0
- package/dist/topology/snapshot.d.ts +50 -0
- package/dist/topology/snapshot.js +38 -0
- package/dist/{tracker.d.ts → tracker/index.d.ts} +3 -3
- package/dist/{tracker.js → tracker/index.js} +9 -9
- package/package.json +11 -11
- package/dist/semaphore-protocol.d.ts +0 -231
- package/dist/semaphore-protocol.js +0 -106
- package/dist/semaphore-queue-store.d.ts +0 -95
- package/dist/semaphore-queue-store.js +0 -252
- package/dist/semaphore-store.d.ts +0 -43
- package/dist/semaphore-store.js +0 -108
- package/dist/topology-snapshot.d.ts +0 -70
- package/dist/topology-snapshot.js +0 -48
- /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/{tracked-source.d.ts → tracker/source.d.ts} +0 -0
- /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 '
|
|
14
|
-
import { OutboxTimeoutError, reportFailure, serializeError, } from '
|
|
15
|
-
import { durabilityOutboxMigrations
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
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 =
|
|
24
|
-
id:
|
|
25
|
-
channel:
|
|
26
|
-
entry_key:
|
|
27
|
-
version:
|
|
28
|
-
payload:
|
|
29
|
-
status:
|
|
30
|
-
attempt:
|
|
31
|
-
next_attempt_at:
|
|
32
|
-
last_error:
|
|
33
|
-
last_error_name:
|
|
34
|
-
created_at:
|
|
35
|
-
generation_id:
|
|
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 =
|
|
38
|
-
|
|
39
|
-
|
|
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 } =
|
|
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 ??
|
|
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
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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,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
|
|
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:
|
|
50
|
-
attemptTimeoutMs:
|
|
51
|
-
retries:
|
|
52
|
-
delay:
|
|
53
|
-
maxAttempts:
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
export declare const alarmMethodOptionsSchema:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
},
|
|
64
|
-
export type MethodPolicy =
|
|
65
|
-
export type AlarmMethodPolicy =
|
|
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:
|
|
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
|
|
1
|
+
import * as v from 'valibot';
|
|
2
2
|
import { exponential, jitter } from './utils.js';
|
|
3
|
-
const functionSchema = () =>
|
|
4
|
-
const retryOptionsSchema =
|
|
5
|
-
delay:
|
|
6
|
-
maxAttempts:
|
|
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 =
|
|
9
|
-
attemptTimeoutMs:
|
|
10
|
-
retries:
|
|
8
|
+
export const methodOptionsSchema = v.object({
|
|
9
|
+
attemptTimeoutMs: v.optional(v.number()),
|
|
10
|
+
retries: v.optional(retryOptionsSchema),
|
|
11
11
|
});
|
|
12
|
-
export const alarmMethodOptionsSchema =
|
|
13
|
-
|
|
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 =
|
|
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 =
|
|
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 '
|
|
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 '
|
|
2
|
+
import { type DurableObjectTarget } from '../durable-object-target.js';
|
|
3
3
|
import { RoutingLoad, type EnqueueResult } from './load.js';
|
|
4
|
-
import { type Sharding } from './
|
|
4
|
+
import { type Sharding } from './client.js';
|
|
5
5
|
export type { EnqueueResult, LoadSnapshot, ProcessingLoad } from './load.js';
|
|
6
|
-
export type { RoutingAddress, RoutingTarget, Sharding
|
|
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 '
|
|
3
|
-
import { RoutingError } from '
|
|
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 './
|
|
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,7 +1,7 @@
|
|
|
1
|
-
import { type SerializedError } from '
|
|
2
|
-
import { type DurabilityMigrationResult } from '
|
|
3
|
-
import { type DurabilityRetryOptions } from '
|
|
4
|
-
import { type SchedulerAttachment } from '
|
|
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
|
|
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
|
|
128
|
-
* individually tracked, overlapping runs and report each run's
|
|
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
|