durability 5.2.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 +9 -9
- package/dist/alarms/index.js +18 -21
- package/dist/fanout/index.js +39 -39
- package/dist/log/index.d.ts +12 -17
- package/dist/log/index.js +59 -53
- package/dist/memoize/index.js +9 -10
- package/dist/migrations.js +12 -16
- package/dist/operations/index.js +22 -28
- package/dist/outbox/index.js +19 -17
- package/dist/policy.d.ts +19 -19
- package/dist/policy.js +13 -12
- package/dist/schedule/index.js +34 -36
- package/dist/scheduler/index.js +13 -12
- package/dist/semaphore/client.js +6 -5
- package/dist/semaphore/protocol.d.ts +446 -234
- package/dist/semaphore/protocol.js +46 -61
- package/dist/semaphore/queue-store.d.ts +58 -52
- package/dist/semaphore/queue-store.js +55 -57
- package/dist/semaphore/server.js +5 -4
- package/dist/semaphore/store.d.ts +30 -25
- package/dist/semaphore/store.js +31 -34
- package/dist/serialization.d.ts +5 -0
- package/dist/serialization.js +41 -16
- package/dist/storage.js +9 -9
- package/dist/topology/index.js +16 -16
- package/dist/topology/snapshot.d.ts +20 -40
- package/dist/topology/snapshot.js +18 -28
- package/dist/tracker/index.js +7 -7
- package/package.json +4 -4
package/dist/semaphore/store.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import
|
|
2
|
-
export const grantRowSchema =
|
|
3
|
-
grant_id:
|
|
4
|
-
client_id:
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
export const grantRowSchema = v.object({
|
|
3
|
+
grant_id: v.string(),
|
|
4
|
+
client_id: v.string(),
|
|
5
5
|
/** The client's queue channel; `clientId` alone does not identify a client. */
|
|
6
|
-
client_channel:
|
|
7
|
-
grp:
|
|
8
|
-
permits:
|
|
9
|
-
claimed:
|
|
10
|
-
released:
|
|
11
|
-
created_at:
|
|
6
|
+
client_channel: v.string(),
|
|
7
|
+
grp: v.string(),
|
|
8
|
+
permits: v.pipe(v.number(), v.safeInteger(), v.minValue(0)),
|
|
9
|
+
claimed: v.pipe(v.number(), v.safeInteger(), v.minValue(0)),
|
|
10
|
+
released: v.pipe(v.number(), v.safeInteger(), v.minValue(0)),
|
|
11
|
+
created_at: v.pipe(v.number(), v.safeInteger(), v.minValue(0)),
|
|
12
12
|
/** Unclaimed permits are reclaimed once this passes. */
|
|
13
|
-
expires_at:
|
|
13
|
+
expires_at: v.pipe(v.number(), v.safeInteger(), v.minValue(0)),
|
|
14
14
|
});
|
|
15
15
|
/** Permits a client may draw locally without a round trip; held by the holder. */
|
|
16
|
-
export const leaseRowSchema =
|
|
17
|
-
lease_id:
|
|
18
|
-
client_id:
|
|
19
|
-
client_channel:
|
|
20
|
-
grp:
|
|
21
|
-
permits:
|
|
16
|
+
export const leaseRowSchema = v.object({
|
|
17
|
+
lease_id: v.string(),
|
|
18
|
+
client_id: v.string(),
|
|
19
|
+
client_channel: v.string(),
|
|
20
|
+
grp: v.string(),
|
|
21
|
+
permits: v.pipe(v.number(), v.safeInteger(), v.minValue(0)),
|
|
22
22
|
/** Drawn permits the client has returned, as a high-water mark. */
|
|
23
|
-
released:
|
|
24
|
-
created_at:
|
|
23
|
+
released: v.pipe(v.number(), v.safeInteger(), v.minValue(0)),
|
|
24
|
+
created_at: v.pipe(v.number(), v.safeInteger(), v.minValue(0)),
|
|
25
25
|
/** Refreshed by every report; the lease is swept once this passes. */
|
|
26
|
-
expires_at:
|
|
26
|
+
expires_at: v.pipe(v.number(), v.safeInteger(), v.minValue(0)),
|
|
27
27
|
/** 1 once no more permits may be drawn; footprint stays until released. */
|
|
28
|
-
retired:
|
|
28
|
+
retired: v.pipe(v.number(), v.safeInteger(), v.minValue(0), v.maxValue(1)),
|
|
29
29
|
});
|
|
30
|
-
const grantColumns =
|
|
31
|
-
const leaseColumns =
|
|
30
|
+
const grantColumns = v.keyof(grantRowSchema).options;
|
|
31
|
+
const leaseColumns = v.keyof(leaseRowSchema).options;
|
|
32
32
|
/**
|
|
33
33
|
* Permits one semaphore channel has handed out. Every query is scoped to the
|
|
34
34
|
* channel, so semaphores sharing an object never see each other's grants or
|
|
@@ -41,26 +41,23 @@ export class HolderStore {
|
|
|
41
41
|
this.channel = channel;
|
|
42
42
|
}
|
|
43
43
|
list() {
|
|
44
|
-
return
|
|
44
|
+
return v.parse(v.array(grantRowSchema), this.sql
|
|
45
45
|
.exec(`SELECT * FROM durability_semaphore_grants
|
|
46
46
|
WHERE channel = ? ORDER BY created_at`, this.channel)
|
|
47
47
|
.toArray());
|
|
48
48
|
}
|
|
49
49
|
get(grantId) {
|
|
50
|
-
return
|
|
50
|
+
return v.parse(v.optional(grantRowSchema), this.sql
|
|
51
51
|
.exec(`SELECT * FROM durability_semaphore_grants
|
|
52
52
|
WHERE channel = ? AND grant_id = ? LIMIT 1`, this.channel, grantId)
|
|
53
53
|
.toArray()[0]);
|
|
54
54
|
}
|
|
55
55
|
nextPendingAt() {
|
|
56
|
-
return grantRowSchema
|
|
57
|
-
.pick({ expires_at: true })
|
|
58
|
-
.optional()
|
|
59
|
-
.parse(this.sql
|
|
56
|
+
return v.parse(v.optional(v.pick(grantRowSchema, ['expires_at'])), this.sql
|
|
60
57
|
.exec(`SELECT expires_at FROM durability_semaphore_grants
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
WHERE channel = ? AND claimed < permits
|
|
59
|
+
ORDER BY expires_at ASC
|
|
60
|
+
LIMIT 1`, this.channel)
|
|
64
61
|
.toArray()[0])?.expires_at;
|
|
65
62
|
}
|
|
66
63
|
insert(row) {
|
|
@@ -80,13 +77,13 @@ export class HolderStore {
|
|
|
80
77
|
this.sql.exec('DELETE FROM durability_semaphore_grants WHERE channel = ? AND grant_id = ?', this.channel, grantId);
|
|
81
78
|
}
|
|
82
79
|
listLeases() {
|
|
83
|
-
return
|
|
80
|
+
return v.parse(v.array(leaseRowSchema), this.sql
|
|
84
81
|
.exec(`SELECT * FROM durability_semaphore_leases
|
|
85
82
|
WHERE channel = ? ORDER BY created_at`, this.channel)
|
|
86
83
|
.toArray());
|
|
87
84
|
}
|
|
88
85
|
getLease(leaseId) {
|
|
89
|
-
return
|
|
86
|
+
return v.parse(v.optional(leaseRowSchema), this.sql
|
|
90
87
|
.exec(`SELECT * FROM durability_semaphore_leases
|
|
91
88
|
WHERE channel = ? AND lease_id = ? LIMIT 1`, this.channel, leaseId)
|
|
92
89
|
.toArray()[0]);
|
package/dist/serialization.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
export type Json = string | number | boolean | null | Json[] | {
|
|
3
|
+
[key: string]: Json;
|
|
4
|
+
};
|
|
5
|
+
export declare const jsonSchema: v.CustomSchema<Json, v.ErrorMessage<v.CustomIssue> | undefined>;
|
|
1
6
|
export declare const serialize: (value: unknown) => string;
|
|
2
7
|
export declare const deserialize: (value: string) => unknown;
|
|
3
8
|
/**
|
package/dist/serialization.js
CHANGED
|
@@ -1,11 +1,40 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
const isPlainObject = (value) => {
|
|
3
|
+
if (value === null || typeof value !== 'object') {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
const prototype = Object.getPrototypeOf(value);
|
|
7
|
+
return prototype === Object.prototype || prototype === null;
|
|
8
|
+
};
|
|
9
|
+
const isJson = (value) => {
|
|
10
|
+
if (value === null ||
|
|
11
|
+
typeof value === 'string' ||
|
|
12
|
+
typeof value === 'boolean') {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
if (typeof value === 'number') {
|
|
16
|
+
return Number.isFinite(value);
|
|
17
|
+
}
|
|
18
|
+
if (Array.isArray(value)) {
|
|
19
|
+
// `every` would skip the holes of a sparse array, which are not JSON.
|
|
20
|
+
for (const item of value) {
|
|
21
|
+
if (!isJson(item)) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return isPlainObject(value) && Object.values(value).every(isJson);
|
|
28
|
+
};
|
|
29
|
+
// Not built from `v.record`, which silently drops `constructor` and `prototype` keys.
|
|
30
|
+
export const jsonSchema = v.custom(isJson, 'Invalid JSON value');
|
|
31
|
+
const storedValueSchema = v.variant('kind', [
|
|
32
|
+
v.object({ kind: v.literal('value'), value: jsonSchema }),
|
|
33
|
+
v.object({ kind: v.literal('undefined') }),
|
|
5
34
|
]);
|
|
6
35
|
/**
|
|
7
36
|
* What `JSON.stringify` would produce: `undefined` properties are dropped and
|
|
8
|
-
* `undefined` array elements become `null`. `
|
|
37
|
+
* `undefined` array elements become `null`. `jsonSchema` rejects both as given,
|
|
9
38
|
* although they are routine in values such as lifecycle events whose handler
|
|
10
39
|
* returned nothing.
|
|
11
40
|
*/
|
|
@@ -13,24 +42,20 @@ const asJson = (value) => {
|
|
|
13
42
|
if (Array.isArray(value)) {
|
|
14
43
|
return value.map((item) => (item === undefined ? null : asJson(item)));
|
|
15
44
|
}
|
|
16
|
-
if (value === null || typeof value !== 'object') {
|
|
17
|
-
return value;
|
|
18
|
-
}
|
|
19
45
|
// Only plain objects are rewritten; anything else must fail validation as is.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return Object.fromEntries(Object.entries(value)
|
|
23
|
-
.filter(([, item]) => item !== undefined)
|
|
24
|
-
.map(([key, item]) => [key, asJson(item)]));
|
|
46
|
+
if (!isPlainObject(value)) {
|
|
47
|
+
return value;
|
|
25
48
|
}
|
|
26
|
-
return value
|
|
49
|
+
return Object.fromEntries(Object.entries(value)
|
|
50
|
+
.filter(([, item]) => item !== undefined)
|
|
51
|
+
.map(([key, item]) => [key, asJson(item)]));
|
|
27
52
|
};
|
|
28
53
|
// Wrapping preserves a successful `undefined` result, which bare JSON cannot represent.
|
|
29
54
|
export const serialize = (value) => JSON.stringify(value === undefined
|
|
30
55
|
? { kind: 'undefined' }
|
|
31
|
-
: { kind: 'value', value:
|
|
56
|
+
: { kind: 'value', value: v.parse(jsonSchema, asJson(value)) });
|
|
32
57
|
export const deserialize = (value) => {
|
|
33
|
-
const stored =
|
|
58
|
+
const stored = v.parse(storedValueSchema, JSON.parse(value));
|
|
34
59
|
return stored.kind === 'undefined' ? undefined : stored.value;
|
|
35
60
|
};
|
|
36
61
|
const canonicalize = (value) => {
|
package/dist/storage.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as v from 'valibot';
|
|
2
2
|
export const channelClause = (table) => table.channel === undefined ? '' : ' AND channel = ?';
|
|
3
3
|
export const channelBindings = (table) => table.channel === undefined ? [] : [table.channel];
|
|
4
4
|
// Keep existing memo owners on the default channel, without restricting record IDs.
|
|
5
5
|
export const tableOwner = (table) => table.channel === undefined || table.channel === 'default'
|
|
6
6
|
? table.name
|
|
7
7
|
: JSON.stringify([table.name, table.channel]);
|
|
8
|
-
const attemptRowSchema =
|
|
9
|
-
attempt:
|
|
8
|
+
const attemptRowSchema = v.object({
|
|
9
|
+
attempt: v.pipe(v.number(), v.safeInteger(), v.minValue(0)),
|
|
10
10
|
});
|
|
11
11
|
// Every write is conditional on the record's generation and pending status, so a
|
|
12
12
|
// stale execution can never overwrite a replacement or a later attempt.
|
|
@@ -17,7 +17,7 @@ export const pendingGeneration = (table) => `${table.key} = ? AND generation_id
|
|
|
17
17
|
*/
|
|
18
18
|
export const claimAttempt = (sql, table, key, generation, maxAttempts, nextAttemptAt) => {
|
|
19
19
|
const deadlineAssignment = nextAttemptAt === undefined ? '' : ', next_attempt_at = ?';
|
|
20
|
-
return
|
|
20
|
+
return v.parse(v.optional(attemptRowSchema), sql
|
|
21
21
|
.exec(`UPDATE ${table.name}
|
|
22
22
|
SET attempt = attempt + 1${deadlineAssignment}
|
|
23
23
|
WHERE ${pendingGeneration(table)} AND attempt < ?
|
|
@@ -41,15 +41,15 @@ export const deleteAttempt = (sql, table, ref) => sql
|
|
|
41
41
|
RETURNING ${table.key}`, ref.key, ref.generation, ...channelBindings(table), ref.attempt)
|
|
42
42
|
.toArray().length > 0;
|
|
43
43
|
/** Fails a generation that has used every attempt and returns its attempt count. */
|
|
44
|
-
export const exhaustAttempts = (sql, table, key, generation, maxAttempts, error) =>
|
|
44
|
+
export const exhaustAttempts = (sql, table, key, generation, maxAttempts, error) => v.parse(v.optional(attemptRowSchema), sql
|
|
45
45
|
.exec(`UPDATE ${table.name}
|
|
46
46
|
SET status = 'failed', last_error = ?, last_error_name = ?
|
|
47
47
|
WHERE ${pendingGeneration(table)} AND attempt >= ?
|
|
48
48
|
RETURNING attempt`, error.message, error.name, key, generation, ...channelBindings(table), maxAttempts)
|
|
49
49
|
.toArray()[0])?.attempt;
|
|
50
|
-
const createdCursorSchema =
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
const createdCursorSchema = v.strictTuple([
|
|
51
|
+
v.pipe(v.number(), v.safeInteger(), v.minValue(0)),
|
|
52
|
+
v.string(),
|
|
53
53
|
]);
|
|
54
54
|
/**
|
|
55
55
|
* Lists records in creation order, then by key, filtered by status and by the
|
|
@@ -58,7 +58,7 @@ const createdCursorSchema = z.tuple([
|
|
|
58
58
|
export const listCreated = (sql, table, nameColumn, query) => {
|
|
59
59
|
const [createdAt, key] = query.after === undefined
|
|
60
60
|
? [-1, '']
|
|
61
|
-
:
|
|
61
|
+
: v.parse(createdCursorSchema, JSON.parse(query.after));
|
|
62
62
|
const status = query.status ?? null;
|
|
63
63
|
const name = query.name ?? null;
|
|
64
64
|
const found = sql
|
package/dist/topology/index.js
CHANGED
|
@@ -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 _DurabilityTopology_instances, _DurabilityTopology_engine, _DurabilityTopology_ownerChannel, _DurabilityTopology_coordinator, _DurabilityTopology_publication, _DurabilityTopology_channels, _DurabilityTopology_publishNow, _DurabilityTopology_stagePublication, _DurabilityTopology_publishSnapshots, _DurabilityTopology_settleLate, _DurabilityTopology_stageLatest, _DurabilityTopology_deliver, _DurabilityTopology_parseDraft, _DurabilityTopology_normalize, _DurabilityTopology_writeStates, _DurabilityTopology_stageDeliveries;
|
|
13
|
-
import
|
|
13
|
+
import * as v from 'valibot';
|
|
14
14
|
import { reportFailure, TopologyError } from '../errors.js';
|
|
15
15
|
import { durabilityTopologyMigrations } from './migrations.js';
|
|
16
16
|
import { migrateCapability } from '../migrations.js';
|
|
@@ -29,15 +29,15 @@ const publicationChannelFor = (ownerChannel) => ownerChannel === defaultChannel
|
|
|
29
29
|
const stateChannelFor = (ownerChannel, state) => ownerChannel === defaultChannel
|
|
30
30
|
? `${outboxChannelPrefix}.${state}`
|
|
31
31
|
: JSON.stringify([outboxChannelPrefix, ownerChannel, 'state', state]);
|
|
32
|
-
const groupRowSchema =
|
|
33
|
-
group_id:
|
|
34
|
-
version:
|
|
35
|
-
members:
|
|
36
|
-
deleted:
|
|
32
|
+
const groupRowSchema = v.object({
|
|
33
|
+
group_id: v.string(),
|
|
34
|
+
version: v.pipe(v.number(), v.safeInteger(), v.gtValue(0)),
|
|
35
|
+
members: v.string(),
|
|
36
|
+
deleted: v.union([v.literal(0), v.literal(1)]),
|
|
37
37
|
});
|
|
38
|
-
const stateRowSchema =
|
|
39
|
-
channel:
|
|
40
|
-
value:
|
|
38
|
+
const stateRowSchema = v.object({
|
|
39
|
+
channel: v.string(),
|
|
40
|
+
value: v.string(),
|
|
41
41
|
});
|
|
42
42
|
class TopologyTimeoutError extends Error {
|
|
43
43
|
constructor(label, timeoutMs) {
|
|
@@ -92,7 +92,7 @@ const forgetWrite = (sql, ownerChannel, id) => {
|
|
|
92
92
|
const outstandingWritesUntil = (sql, ownerChannel, group, now) => {
|
|
93
93
|
sql.exec(`DELETE FROM durability_topology_writes
|
|
94
94
|
WHERE owner_channel = ? AND group_id = ? AND land_by <= ?`, ownerChannel, group, now);
|
|
95
|
-
const { until } =
|
|
95
|
+
const { until } = v.parse(v.object({ until: v.nullable(v.pipe(v.number(), v.safeInteger())) }), sql
|
|
96
96
|
.exec(`SELECT MAX(land_by) AS until FROM durability_topology_writes
|
|
97
97
|
WHERE owner_channel = ? AND group_id = ?`, ownerChannel, group)
|
|
98
98
|
.toArray()[0]);
|
|
@@ -107,16 +107,16 @@ const deliveryKey = (group, member) => JSON.stringify([group, member]);
|
|
|
107
107
|
const isThenable = (value) => value !== null &&
|
|
108
108
|
typeof value === 'object' &&
|
|
109
109
|
typeof Reflect.get(value, 'then') === 'function';
|
|
110
|
-
const readGroup = (sql, ownerChannel, group) =>
|
|
110
|
+
const readGroup = (sql, ownerChannel, group) => v.parse(v.optional(groupRowSchema), sql
|
|
111
111
|
.exec(`SELECT group_id, version, members, deleted
|
|
112
112
|
FROM durability_topology_groups
|
|
113
113
|
WHERE owner_channel = ? AND group_id = ?`, ownerChannel, group)
|
|
114
114
|
.toArray()[0]);
|
|
115
|
-
const readStates = (sql, ownerChannel, group) =>
|
|
115
|
+
const readStates = (sql, ownerChannel, group) => v.parse(v.array(stateRowSchema), sql
|
|
116
116
|
.exec(`SELECT channel, value FROM durability_topology_states
|
|
117
117
|
WHERE owner_channel = ? AND group_id = ?`, ownerChannel, group)
|
|
118
118
|
.toArray());
|
|
119
|
-
const parseMembers = (row) =>
|
|
119
|
+
const parseMembers = (row) => v.parse(membersSchema, JSON.parse(row.members));
|
|
120
120
|
const inRole = (member, role) => role === 'read' || member.state === 'active';
|
|
121
121
|
/**
|
|
122
122
|
* Experimental. Holds the membership of shard groups inside one coordinator
|
|
@@ -426,11 +426,11 @@ async function _DurabilityTopology_publishSnapshots(publisher, entries, timeoutM
|
|
|
426
426
|
const joinedAt = new Map(before.map((member) => [member.id, member.joinedAt]));
|
|
427
427
|
const seen = new Set();
|
|
428
428
|
const members = inputs.map((input) => {
|
|
429
|
-
const parsed =
|
|
429
|
+
const parsed = v.safeParse(memberInputSchema, input);
|
|
430
430
|
if (!parsed.success) {
|
|
431
|
-
throw new TopologyError(`Invalid member: ${parsed.
|
|
431
|
+
throw new TopologyError(`Invalid member: ${v.summarize(parsed.issues)}`);
|
|
432
432
|
}
|
|
433
|
-
const { id, state, locationHint, meta } = parsed.
|
|
433
|
+
const { id, state, locationHint, meta } = parsed.output;
|
|
434
434
|
if (seen.has(id)) {
|
|
435
435
|
throw new TopologyError(`Duplicate member "${id}"`);
|
|
436
436
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as v from 'valibot';
|
|
2
2
|
/** `active` members are in the write and read sets; `draining` members only in the read set. */
|
|
3
3
|
export type TopologyMemberState = 'active' | 'draining';
|
|
4
4
|
type MetaField<Meta> = undefined extends Meta ? {
|
|
@@ -25,45 +25,25 @@ export type TopologySnapshot<Meta = undefined> = {
|
|
|
25
25
|
/** Sorted by ID. */
|
|
26
26
|
members: readonly TopologyMember<Meta>[];
|
|
27
27
|
};
|
|
28
|
-
export declare const memberInputSchema:
|
|
29
|
-
id:
|
|
30
|
-
state:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
meta
|
|
46
|
-
},
|
|
47
|
-
export declare const membersSchema: z.ZodArray<z.ZodObject<{
|
|
48
|
-
id: z.ZodString;
|
|
49
|
-
state: z.ZodEnum<{
|
|
50
|
-
active: "active";
|
|
51
|
-
draining: "draining";
|
|
52
|
-
}>;
|
|
53
|
-
locationHint: z.ZodOptional<z.ZodEnum<{
|
|
54
|
-
wnam: "wnam";
|
|
55
|
-
enam: "enam";
|
|
56
|
-
sam: "sam";
|
|
57
|
-
weur: "weur";
|
|
58
|
-
eeur: "eeur";
|
|
59
|
-
apac: "apac";
|
|
60
|
-
oc: "oc";
|
|
61
|
-
afr: "afr";
|
|
62
|
-
me: "me";
|
|
63
|
-
}>>;
|
|
64
|
-
meta: z.ZodOptional<z.ZodJSONSchema>;
|
|
65
|
-
joinedAt: z.ZodNumber;
|
|
66
|
-
}, z.core.$strip>>;
|
|
28
|
+
export declare const memberInputSchema: v.ObjectSchema<{
|
|
29
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
30
|
+
readonly state: v.PicklistSchema<["active", "draining"], undefined>;
|
|
31
|
+
readonly locationHint: v.OptionalSchema<v.PicklistSchema<readonly ["wnam", "enam", "sam", "weur", "eeur", "apac", "oc", "afr", "me"], undefined>, undefined>;
|
|
32
|
+
readonly meta: v.OptionalSchema<v.CustomSchema<import("../serialization.js").Json, v.ErrorMessage<v.CustomIssue> | undefined>, undefined>;
|
|
33
|
+
}, undefined>;
|
|
34
|
+
export declare const membersSchema: v.SchemaWithPipe<readonly [v.ArraySchema<v.ObjectSchema<{
|
|
35
|
+
readonly joinedAt: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
36
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
37
|
+
readonly state: v.PicklistSchema<["active", "draining"], undefined>;
|
|
38
|
+
readonly locationHint: v.OptionalSchema<v.PicklistSchema<readonly ["wnam", "enam", "sam", "weur", "eeur", "apac", "oc", "afr", "me"], undefined>, undefined>;
|
|
39
|
+
readonly meta: v.OptionalSchema<v.CustomSchema<import("../serialization.js").Json, v.ErrorMessage<v.CustomIssue> | undefined>, undefined>;
|
|
40
|
+
}, undefined>, undefined>, v.CheckAction<{
|
|
41
|
+
joinedAt: number;
|
|
42
|
+
id: string;
|
|
43
|
+
state: "active" | "draining";
|
|
44
|
+
locationHint?: "wnam" | "enam" | "sam" | "weur" | "eeur" | "apac" | "oc" | "afr" | "me" | undefined;
|
|
45
|
+
meta?: import("../serialization.js").Json | undefined;
|
|
46
|
+
}[], "Members must be sorted by ID and unique">]>;
|
|
67
47
|
export declare const encodeSnapshot: <Meta>(snapshot: TopologySnapshot<Meta>) => string;
|
|
68
48
|
/** The stored value crossed a trust boundary, so every field is re-validated. */
|
|
69
49
|
export declare const decodeSnapshot: <Meta>(encoded: string) => TopologySnapshot<Meta>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
import { jsonSchema } from '../serialization.js';
|
|
2
3
|
const locationHints = [
|
|
3
4
|
'wnam',
|
|
4
5
|
'enam',
|
|
@@ -11,38 +12,27 @@ const locationHints = [
|
|
|
11
12
|
'me',
|
|
12
13
|
];
|
|
13
14
|
// Unknown keys are stripped, so current members (which carry `joinedAt`) can be returned as input.
|
|
14
|
-
export const memberInputSchema =
|
|
15
|
-
id:
|
|
16
|
-
state:
|
|
17
|
-
locationHint:
|
|
18
|
-
meta:
|
|
15
|
+
export const memberInputSchema = v.object({
|
|
16
|
+
id: v.pipe(v.string(), v.minLength(1)),
|
|
17
|
+
state: v.picklist(['active', 'draining']),
|
|
18
|
+
locationHint: v.optional(v.picklist(locationHints)),
|
|
19
|
+
meta: v.optional(jsonSchema),
|
|
19
20
|
});
|
|
20
|
-
const memberSchema =
|
|
21
|
-
|
|
21
|
+
const memberSchema = v.object({
|
|
22
|
+
...memberInputSchema.entries,
|
|
23
|
+
joinedAt: v.pipe(v.number(), v.safeInteger(), v.minValue(0)),
|
|
22
24
|
});
|
|
23
|
-
export const membersSchema = memberSchema
|
|
24
|
-
|
|
25
|
-
.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
message: 'Members must be sorted by ID and unique',
|
|
31
|
-
path: [index, 'id'],
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
const encodedSchema = z.object({
|
|
37
|
-
format: z.literal(1),
|
|
38
|
-
group: z.string().min(1),
|
|
39
|
-
version: z.number().int().positive(),
|
|
40
|
-
coordinator: z.string().min(1),
|
|
41
|
-
members: membersSchema.min(1),
|
|
25
|
+
export const membersSchema = v.pipe(v.array(memberSchema), v.check((members) => members.every((member, index) => index === 0 || members[index - 1].id < member.id), 'Members must be sorted by ID and unique'));
|
|
26
|
+
const encodedSchema = v.object({
|
|
27
|
+
format: v.literal(1),
|
|
28
|
+
group: v.pipe(v.string(), v.minLength(1)),
|
|
29
|
+
version: v.pipe(v.number(), v.safeInteger(), v.gtValue(0)),
|
|
30
|
+
coordinator: v.pipe(v.string(), v.minLength(1)),
|
|
31
|
+
members: v.pipe(membersSchema, v.minLength(1)),
|
|
42
32
|
});
|
|
43
33
|
export const encodeSnapshot = (snapshot) => JSON.stringify({ format: 1, ...snapshot });
|
|
44
34
|
/** The stored value crossed a trust boundary, so every field is re-validated. */
|
|
45
35
|
export const decodeSnapshot = (encoded) => {
|
|
46
|
-
const { format: _format, ...snapshot } =
|
|
36
|
+
const { format: _format, ...snapshot } = v.parse(encodedSchema, JSON.parse(encoded));
|
|
47
37
|
return snapshot;
|
|
48
38
|
};
|
package/dist/tracker/index.js
CHANGED
|
@@ -10,13 +10,13 @@ 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 _DurabilityTracker_instances, _DurabilityTracker_sources, _DurabilityTracker_collect, _DurabilityTracker_source, _DurabilityTracker_handle, _DurabilityTracker_wait;
|
|
13
|
-
import
|
|
13
|
+
import * as v from 'valibot';
|
|
14
14
|
import { traceMethods } from '../dev.js';
|
|
15
15
|
import { trackedSourceOf, } from './source.js';
|
|
16
|
-
const limitSchema =
|
|
17
|
-
const cursorSchema =
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const limitSchema = v.pipe(v.number(), v.safeInteger(), v.minValue(1), v.maxValue(100));
|
|
17
|
+
const cursorSchema = v.strictTuple([
|
|
18
|
+
v.pipe(v.number(), v.safeInteger(), v.minValue(0)),
|
|
19
|
+
v.nullable(v.string()),
|
|
20
20
|
]);
|
|
21
21
|
const resultFor = (entry, record) => record?.generation === entry.generation
|
|
22
22
|
? record.state
|
|
@@ -87,11 +87,11 @@ export class DurabilityTracker {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
_DurabilityTracker_sources = new WeakMap(), _DurabilityTracker_instances = new WeakSet(), _DurabilityTracker_collect = async function _DurabilityTracker_collect(query) {
|
|
90
|
-
const limit =
|
|
90
|
+
const limit = v.parse(limitSchema, query.limit ?? 50);
|
|
91
91
|
const candidates = query.source === undefined ? __classPrivateFieldGet(this, _DurabilityTracker_sources, "f") : [__classPrivateFieldGet(this, _DurabilityTracker_instances, "m", _DurabilityTracker_source).call(this, query.source)];
|
|
92
92
|
const [start, startCursor] = query.cursor === undefined
|
|
93
93
|
? [0, null]
|
|
94
|
-
:
|
|
94
|
+
: v.parse(cursorSchema, JSON.parse(query.cursor));
|
|
95
95
|
const found = [];
|
|
96
96
|
for (const [offset, [key, source]] of candidates.slice(start).entries()) {
|
|
97
97
|
const index = start + offset;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "durability",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.1",
|
|
4
4
|
"description": "Alarm-backed durable operations and typed WebSocket sync for Cloudflare Durable Objects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "ISC",
|
|
@@ -63,9 +63,9 @@
|
|
|
63
63
|
],
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@standard-schema/spec": "^1.1.0",
|
|
66
|
-
"
|
|
67
|
-
"@durability/
|
|
68
|
-
"@durability/
|
|
66
|
+
"valibot": "^1.5.0",
|
|
67
|
+
"@durability/storage": "^0.1.1",
|
|
68
|
+
"@durability/transforms": "^0.6.1"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"@cloudflare/workers-types": "^4.20260702.1"
|