@spine-event-engine/delivery-client 2.0.0-snapshot.2
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/LICENSE +201 -0
- package/README.md +133 -0
- package/REFERENCE.md +89 -0
- package/dist/client/client.d.ts +143 -0
- package/dist/client/client.d.ts.map +1 -0
- package/dist/client/client.js +459 -0
- package/dist/client/client.js.map +1 -0
- package/dist/client/shard-observation.d.ts +35 -0
- package/dist/client/shard-observation.d.ts.map +1 -0
- package/dist/client/shard-observation.js +178 -0
- package/dist/client/shard-observation.js.map +1 -0
- package/dist/client/types.d.ts +229 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +128 -0
- package/dist/client/types.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/remote/adapters.d.ts +102 -0
- package/dist/remote/adapters.d.ts.map +1 -0
- package/dist/remote/adapters.js +405 -0
- package/dist/remote/adapters.js.map +1 -0
- package/dist/remote/remote-delivery.d.ts +65 -0
- package/dist/remote/remote-delivery.d.ts.map +1 -0
- package/dist/remote/remote-delivery.js +176 -0
- package/dist/remote/remote-delivery.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/wire/codec.d.ts +107 -0
- package/dist/wire/codec.d.ts.map +1 -0
- package/dist/wire/codec.js +776 -0
- package/dist/wire/codec.js.map +1 -0
- package/package.json +35 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { DeliveryInbox, DeliveryOperationOptions, DeliveryWorkRegistry, DeliveryWorkSession, ExclusiveDeliveryWorkSession, InboxMessage, InboxMessageId, InboxMessageInput, InboxReadOptions, InboxWriteResult } from "@spine-event-engine/server";
|
|
2
|
+
import { ShardIndex } from "@spine-event-engine/server";
|
|
3
|
+
import type { WorkerId } from "@spine-event-engine/proto/delivery";
|
|
4
|
+
import { DeliveryClient } from "../client/client.js";
|
|
5
|
+
import { type RemoteShardObservation } from "../client/types.js";
|
|
6
|
+
/**
|
|
7
|
+
* Adapts a delivery-server client to the server-owned inbox port.
|
|
8
|
+
*/
|
|
9
|
+
export declare class RemoteInbox implements DeliveryInbox {
|
|
10
|
+
private readonly client;
|
|
11
|
+
/**
|
|
12
|
+
* Remote inbox work requires an exclusive remote shard session.
|
|
13
|
+
*/
|
|
14
|
+
readonly sessionKind: "EXCLUSIVE";
|
|
15
|
+
/**
|
|
16
|
+
* Creates a remote inbox.
|
|
17
|
+
*
|
|
18
|
+
* @param client Sends inbox calls to the delivery server.
|
|
19
|
+
*/
|
|
20
|
+
constructor(client: DeliveryClient);
|
|
21
|
+
/**
|
|
22
|
+
* Writes a new inbox message.
|
|
23
|
+
*
|
|
24
|
+
* @param input Supplies the message fields excluding its generated identity.
|
|
25
|
+
* @param options Bounds or cancels the remote mutation.
|
|
26
|
+
* @returns The written message result.
|
|
27
|
+
*/
|
|
28
|
+
receive(input: InboxMessageInput, options?: DeliveryOperationOptions): Promise<InboxWriteResult>;
|
|
29
|
+
/**
|
|
30
|
+
* Reads a bounded page of messages from one shard.
|
|
31
|
+
*
|
|
32
|
+
* @param shardIndex Identifies the shard to read.
|
|
33
|
+
* @param options Supplies paging, status filtering, and call bounds.
|
|
34
|
+
* @returns Detached messages in safely continued remote order.
|
|
35
|
+
*/
|
|
36
|
+
read(shardIndex: ShardIndex, options?: InboxReadOptions & DeliveryOperationOptions): Promise<readonly InboxMessage[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Reads one message by its remote identity.
|
|
39
|
+
*
|
|
40
|
+
* @param id Identifies the message and shard.
|
|
41
|
+
* @param options Bounds or cancels the remote read.
|
|
42
|
+
* @returns The detached message, or `undefined` when it is absent.
|
|
43
|
+
*/
|
|
44
|
+
readMessage(id: InboxMessageId, options?: DeliveryOperationOptions): Promise<InboxMessage | undefined>;
|
|
45
|
+
/**
|
|
46
|
+
* Removes one exact authoritative pending row and returns its delivered fact.
|
|
47
|
+
*
|
|
48
|
+
* @param message Supplies the expected pending message snapshot.
|
|
49
|
+
* @param options Bounds or cancels remote reads and removal.
|
|
50
|
+
* @returns The delivered acknowledgement, or `undefined` when the pending
|
|
51
|
+
* row is absent or no longer matches.
|
|
52
|
+
*/
|
|
53
|
+
markDelivered(message: InboxMessage, options?: DeliveryOperationOptions): Promise<InboxMessage | undefined>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Adapts one per-registry remote session owner to the server work-registry port.
|
|
57
|
+
*/
|
|
58
|
+
export declare class RemoteWorkRegistry implements DeliveryWorkRegistry {
|
|
59
|
+
#private;
|
|
60
|
+
/**
|
|
61
|
+
* Identifies the exclusive session model used by the remote registry.
|
|
62
|
+
*/
|
|
63
|
+
readonly sessionKind: "EXCLUSIVE";
|
|
64
|
+
/**
|
|
65
|
+
* Creates a registry backed by the supplied delivery client.
|
|
66
|
+
*
|
|
67
|
+
* @param client Sends shard operations to the delivery server.
|
|
68
|
+
*/
|
|
69
|
+
constructor(client: DeliveryClient);
|
|
70
|
+
/**
|
|
71
|
+
* Acquires a remote shard for a complete worker identity.
|
|
72
|
+
*
|
|
73
|
+
* @param shardIndex Identifies the shard to acquire.
|
|
74
|
+
* @param worker Identifies the worker requesting the shard.
|
|
75
|
+
* @param options Bounds or cancels the remote operation.
|
|
76
|
+
* @returns The acquired exclusive session, or `undefined` when unavailable.
|
|
77
|
+
*/
|
|
78
|
+
pickUp(shardIndex: ShardIndex, worker: WorkerId, options?: DeliveryOperationOptions): Promise<ExclusiveDeliveryWorkSession | undefined>;
|
|
79
|
+
/**
|
|
80
|
+
* Removes a remote shard session owned by this registry.
|
|
81
|
+
*
|
|
82
|
+
* @param session Identifies the session to release.
|
|
83
|
+
* @param options Bounds or cancels the remote operation.
|
|
84
|
+
* @returns Whether the registry recognized and released the session.
|
|
85
|
+
*/
|
|
86
|
+
release(session: DeliveryWorkSession, options?: DeliveryOperationOptions): Promise<boolean>;
|
|
87
|
+
/**
|
|
88
|
+
* Validates current remote ownership before a guarded side effect.
|
|
89
|
+
*
|
|
90
|
+
* @param session Supplies the exclusive session to validate.
|
|
91
|
+
* @param options Bounds or cancels the authoritative probe.
|
|
92
|
+
* @returns The retained session, or `undefined` when validation fails.
|
|
93
|
+
*/
|
|
94
|
+
validateOwnership(session: DeliveryWorkSession, options?: DeliveryOperationOptions): Promise<ExclusiveDeliveryWorkSession | undefined>;
|
|
95
|
+
/**
|
|
96
|
+
* Applies an Admin shard observation to local ownership.
|
|
97
|
+
*
|
|
98
|
+
* @param observation Describes the current remote shard state.
|
|
99
|
+
*/
|
|
100
|
+
reconcile(observation: RemoteShardObservation): void;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=adapters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapters.d.ts","sourceRoot":"","sources":["../../src/remote/adapters.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EACV,aAAa,EACb,wBAAwB,EACxB,oBAAoB,EACpB,mBAAmB,EACnB,4BAA4B,EAC5B,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAGnE,OAAO,EAAE,cAAc,EAAwB,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAIL,KAAK,sBAAsB,EAE5B,MAAM,oBAAoB,CAAC;AAG5B;;GAEG;AACH,qBAAa,WAAY,YAAW,aAAa;IAanC,OAAO,CAAC,QAAQ,CAAC,MAAM;IAVnC;;OAEG;IACH,QAAQ,CAAC,WAAW,EAAG,WAAW,CAAU;IAE5C;;;;OAIG;gBAC0B,MAAM,EAAE,cAAc;IAInD;;;;;;OAMG;IACG,OAAO,CACX,KAAK,EAAE,iBAAiB,EACxB,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,gBAAgB,CAAC;IAM5B;;;;;;OAMG;IACG,IAAI,CACR,UAAU,EAAE,UAAU,EACtB,OAAO,GAAE,gBAAgB,GAAG,wBAA6B,GACxD,OAAO,CAAC,SAAS,YAAY,EAAE,CAAC;IAwCnC;;;;;;OAMG;IACH,WAAW,CACT,EAAE,EAAE,cAAc,EAClB,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC;IAIpC;;;;;;;OAOG;IACG,aAAa,CACjB,OAAO,EAAE,YAAY,EACrB,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC;CAOrC;AAmKD;;GAEG;AACH,qBAAa,kBAAmB,YAAW,oBAAoB;;IAG7D;;OAEG;IACH,QAAQ,CAAC,WAAW,EAAG,WAAW,CAAU;IAG5C;;;;OAIG;gBACS,MAAM,EAAE,cAAc;IAQlC;;;;;;;OAOG;IACH,MAAM,CACJ,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,QAAQ,EAChB,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,4BAA4B,GAAG,SAAS,CAAC;IAIpD;;;;;;OAMG;IACH,OAAO,CAAC,OAAO,EAAE,mBAAmB,EAAE,OAAO,CAAC,EAAE,wBAAwB,GAAG,OAAO,CAAC,OAAO,CAAC;IAI3F;;;;;;OAMG;IACH,iBAAiB,CACf,OAAO,EAAE,mBAAmB,EAC5B,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,4BAA4B,GAAG,SAAS,CAAC;IAIpD;;;;OAIG;IACH,SAAS,CAAC,WAAW,EAAE,sBAAsB,GAAG,IAAI;CAGrD"}
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026, CodeMatters. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
|
5
|
+
* in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
10
|
+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
11
|
+
* or implied. See the License for the specific language governing permissions and limitations under
|
|
12
|
+
* the License.
|
|
13
|
+
*/
|
|
14
|
+
import { randomUUID } from "node:crypto";
|
|
15
|
+
import { ShardIndex } from "@spine-event-engine/server";
|
|
16
|
+
import { conditionalPickUp } from "@spine-event-engine/server/internal/conditional-pickup";
|
|
17
|
+
import { DeliveryClient, deliveryClientAccess } from "../client/client.js";
|
|
18
|
+
import { DeliveryPagingError, DeliveryProtocolError, } from "../client/types.js";
|
|
19
|
+
import { DeliveryMessageCodec, DeliveryRequestCodec, DeliveryShardCodec } from "../wire/codec.js";
|
|
20
|
+
/**
|
|
21
|
+
* Adapts a delivery-server client to the server-owned inbox port.
|
|
22
|
+
*/
|
|
23
|
+
export class RemoteInbox {
|
|
24
|
+
client;
|
|
25
|
+
// prettier-ignore
|
|
26
|
+
/**
|
|
27
|
+
* Remote inbox work requires an exclusive remote shard session.
|
|
28
|
+
*/
|
|
29
|
+
sessionKind = "EXCLUSIVE";
|
|
30
|
+
/**
|
|
31
|
+
* Creates a remote inbox.
|
|
32
|
+
*
|
|
33
|
+
* @param client Sends inbox calls to the delivery server.
|
|
34
|
+
*/
|
|
35
|
+
constructor(client) {
|
|
36
|
+
this.client = client;
|
|
37
|
+
Object.freeze(this);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Writes a new inbox message.
|
|
41
|
+
*
|
|
42
|
+
* @param input Supplies the message fields excluding its generated identity.
|
|
43
|
+
* @param options Bounds or cancels the remote mutation.
|
|
44
|
+
* @returns The written message result.
|
|
45
|
+
*/
|
|
46
|
+
async receive(input, options) {
|
|
47
|
+
const message = RemoteValues.receiveMessage(input);
|
|
48
|
+
await this.client.writeOne(message, options);
|
|
49
|
+
return RemoteValues.freeze({ outcome: "WRITTEN", message });
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Reads a bounded page of messages from one shard.
|
|
53
|
+
*
|
|
54
|
+
* @param shardIndex Identifies the shard to read.
|
|
55
|
+
* @param options Supplies paging, status filtering, and call bounds.
|
|
56
|
+
* @returns Detached messages in safely continued remote order.
|
|
57
|
+
*/
|
|
58
|
+
async read(shardIndex, options = {}) {
|
|
59
|
+
if (options.offset !== undefined && options.offset !== 0)
|
|
60
|
+
throw new DeliveryPagingError();
|
|
61
|
+
const limit = options.limit === undefined
|
|
62
|
+
? this.client.pageSize
|
|
63
|
+
: DeliveryRequestCodec.pageSize(options.limit);
|
|
64
|
+
let after = options.after;
|
|
65
|
+
let scanned = 0;
|
|
66
|
+
const result = [];
|
|
67
|
+
while (result.length < limit) {
|
|
68
|
+
const page = await this.client.readPage(shardIndex, {
|
|
69
|
+
pageSize: limit,
|
|
70
|
+
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
71
|
+
...(options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs }),
|
|
72
|
+
...(after === undefined ? {} : { sinceWhen: RemoteValues.pageAnchor(after.whenReceived) }),
|
|
73
|
+
});
|
|
74
|
+
const start = after === undefined ? 0 : RemoteValues.exactAfter(page, after);
|
|
75
|
+
const raw = page.slice(start);
|
|
76
|
+
scanned += raw.length;
|
|
77
|
+
if (scanned > 1_000 + limit)
|
|
78
|
+
throw new DeliveryPagingError();
|
|
79
|
+
const last = page.at(-1);
|
|
80
|
+
const prior = page.at(-2);
|
|
81
|
+
if (page.length === limit &&
|
|
82
|
+
(last === undefined || prior?.whenReceived.getTime() === last.whenReceived.getTime()))
|
|
83
|
+
throw new DeliveryPagingError();
|
|
84
|
+
for (const message of raw) {
|
|
85
|
+
if (options.statuses === undefined || options.statuses.includes(message.status)) {
|
|
86
|
+
result.push(message);
|
|
87
|
+
if (result.length === limit)
|
|
88
|
+
return Object.freeze(result);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (page.length < limit)
|
|
92
|
+
return Object.freeze(result);
|
|
93
|
+
if (last === undefined)
|
|
94
|
+
throw new DeliveryPagingError();
|
|
95
|
+
after = { messageId: last.id.value, whenReceived: last.whenReceived, version: last.version };
|
|
96
|
+
}
|
|
97
|
+
return Object.freeze(result);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Reads one message by its remote identity.
|
|
101
|
+
*
|
|
102
|
+
* @param id Identifies the message and shard.
|
|
103
|
+
* @param options Bounds or cancels the remote read.
|
|
104
|
+
* @returns The detached message, or `undefined` when it is absent.
|
|
105
|
+
*/
|
|
106
|
+
readMessage(id, options) {
|
|
107
|
+
return this.client.findOne(id, options);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Removes one exact authoritative pending row and returns its delivered fact.
|
|
111
|
+
*
|
|
112
|
+
* @param message Supplies the expected pending message snapshot.
|
|
113
|
+
* @param options Bounds or cancels remote reads and removal.
|
|
114
|
+
* @returns The delivered acknowledgement, or `undefined` when the pending
|
|
115
|
+
* row is absent or no longer matches.
|
|
116
|
+
*/
|
|
117
|
+
async markDelivered(message, options) {
|
|
118
|
+
const current = await this.client.findOne(message.id, options);
|
|
119
|
+
if (current?.status !== "TO_DELIVER" || !RemoteValues.sameMessage(current, message))
|
|
120
|
+
return undefined;
|
|
121
|
+
await this.client.removeOne(current, options);
|
|
122
|
+
return DeliveryMessageCodec.snapshot({ ...current, status: "DELIVERED" });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Adapts remote exclusive shard sessions to the server work registry.
|
|
127
|
+
*/
|
|
128
|
+
class RemoteSessionOwner {
|
|
129
|
+
client;
|
|
130
|
+
// prettier-ignore
|
|
131
|
+
/**
|
|
132
|
+
* Frozen remote pickup produces non-renewable exclusive sessions.
|
|
133
|
+
*/
|
|
134
|
+
#sessions = new WeakMap();
|
|
135
|
+
#sessionsByShard = new Map();
|
|
136
|
+
/**
|
|
137
|
+
* Creates a registry backed by the supplied delivery client.
|
|
138
|
+
*
|
|
139
|
+
* @param client Sends shard operations to the delivery server.
|
|
140
|
+
*/
|
|
141
|
+
constructor(client) {
|
|
142
|
+
this.client = client;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Acquires a shard for the supplied complete worker identity.
|
|
146
|
+
*
|
|
147
|
+
* @param shardIndex Identifies the shard to acquire.
|
|
148
|
+
* @param worker Identifies the worker requesting work.
|
|
149
|
+
* @param options Bounds or cancels the remote mutation.
|
|
150
|
+
* @returns A local exclusive session, or `undefined` when unavailable.
|
|
151
|
+
*/
|
|
152
|
+
async pickUp(shardIndex, worker, options) {
|
|
153
|
+
const operation = {
|
|
154
|
+
...(options?.signal === undefined ? {} : { signal: options.signal }),
|
|
155
|
+
...(options?.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs }),
|
|
156
|
+
};
|
|
157
|
+
const remote = await this.client.pickUp(shardIndex, RemoteValues.worker(worker), operation);
|
|
158
|
+
if (remote === undefined)
|
|
159
|
+
return undefined;
|
|
160
|
+
const session = RemoteValues.freeze({
|
|
161
|
+
kind: "EXCLUSIVE",
|
|
162
|
+
shard: DeliveryShardCodec.snapshot(shardIndex),
|
|
163
|
+
});
|
|
164
|
+
this.#sessions.set(session, remote);
|
|
165
|
+
const key = RemoteValues.shardKey(shardIndex);
|
|
166
|
+
const sessions = this.#sessionsByShard.get(key) ?? new Set();
|
|
167
|
+
sessions.add(session);
|
|
168
|
+
this.#sessionsByShard.set(key, sessions);
|
|
169
|
+
return session;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Removes a previously acquired exclusive session.
|
|
173
|
+
*
|
|
174
|
+
* @param session Supplies the local session to release.
|
|
175
|
+
* @param options Bounds or cancels the remote mutation.
|
|
176
|
+
* @returns Whether this registry released a known session.
|
|
177
|
+
*/
|
|
178
|
+
async release(session, options) {
|
|
179
|
+
if (session.kind !== "EXCLUSIVE")
|
|
180
|
+
return false;
|
|
181
|
+
const remote = this.#sessions.get(session);
|
|
182
|
+
if (remote === undefined)
|
|
183
|
+
return false;
|
|
184
|
+
const key = RemoteValues.shardKey(session.shard);
|
|
185
|
+
this.#sessions.delete(session);
|
|
186
|
+
this.#removeSession(key, session);
|
|
187
|
+
await this.client.release(remote, options);
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Validates that an exclusive remote session still owns its shard.
|
|
192
|
+
*
|
|
193
|
+
* An exact worker and pickup-time match retains the local session. A free
|
|
194
|
+
* shard accidentally acquired by the probe is released and invalidated, as
|
|
195
|
+
* is a session held by a different current owner. Unknown outcomes fail
|
|
196
|
+
* closed without storing quarantine or marker state.
|
|
197
|
+
*
|
|
198
|
+
* @param session Supplies the locally issued exclusive session.
|
|
199
|
+
* @param options Bounds or cancels the authoritative probe.
|
|
200
|
+
* @returns The retained session, or `undefined` when validation fails.
|
|
201
|
+
*/
|
|
202
|
+
async validateOwnership(session, options) {
|
|
203
|
+
if (session.kind !== "EXCLUSIVE")
|
|
204
|
+
return undefined;
|
|
205
|
+
const remote = this.#sessions.get(session);
|
|
206
|
+
if (remote === undefined)
|
|
207
|
+
return undefined;
|
|
208
|
+
const probe = await deliveryClientAccess.probePickUp(this.client, session.shard, remote.worker, options ?? {});
|
|
209
|
+
if (probe.kind === "PICKED") {
|
|
210
|
+
await this.#cleanupAccidentalPickup(probe.session);
|
|
211
|
+
this.#invalidate(session);
|
|
212
|
+
return undefined;
|
|
213
|
+
}
|
|
214
|
+
if (RemoteValues.sameWorker(probe.session.worker, remote.worker) &&
|
|
215
|
+
probe.session.whenPicked.getTime() === remote.whenPicked.getTime()) {
|
|
216
|
+
return session;
|
|
217
|
+
}
|
|
218
|
+
this.#invalidate(session);
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
async #cleanupAccidentalPickup(session) {
|
|
222
|
+
try {
|
|
223
|
+
await this.client.release(session, { timeoutMs: 1_000 });
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
// Validation remains failed closed when bounded cleanup is uncertain.
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
#invalidate(session) {
|
|
230
|
+
this.#sessions.delete(session);
|
|
231
|
+
this.#removeSession(RemoteValues.shardKey(session.shard), session);
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Applies a validated Admin observation to local remote-session state.
|
|
235
|
+
*
|
|
236
|
+
* A `PICKED` observation cannot prove ownership because the frozen wire
|
|
237
|
+
* omits a session identity. Only `NOT_PICKED` invalidates stale sessions.
|
|
238
|
+
*
|
|
239
|
+
* @param observation Supplies the detached remote shard observation.
|
|
240
|
+
*/
|
|
241
|
+
reconcile(observation) {
|
|
242
|
+
if (!(observation.shard instanceof ShardIndex) ||
|
|
243
|
+
!Number.isSafeInteger(observation.messages) ||
|
|
244
|
+
observation.messages < 0 ||
|
|
245
|
+
(observation.lastPicked !== undefined &&
|
|
246
|
+
(!(observation.lastPicked instanceof Date) ||
|
|
247
|
+
Number.isNaN(observation.lastPicked.getTime()))))
|
|
248
|
+
throw new DeliveryProtocolError();
|
|
249
|
+
if (observation.status !== "NOT_PICKED")
|
|
250
|
+
return;
|
|
251
|
+
const key = RemoteValues.shardKey(observation.shard);
|
|
252
|
+
const sessions = this.#sessionsByShard.get(key);
|
|
253
|
+
if (sessions !== undefined) {
|
|
254
|
+
for (const session of sessions) {
|
|
255
|
+
this.#sessions.delete(session);
|
|
256
|
+
}
|
|
257
|
+
this.#sessionsByShard.delete(key);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
#removeSession(key, session) {
|
|
261
|
+
const sessions = this.#sessionsByShard.get(key);
|
|
262
|
+
if (sessions === undefined)
|
|
263
|
+
return;
|
|
264
|
+
sessions.delete(session);
|
|
265
|
+
if (sessions.size === 0)
|
|
266
|
+
this.#sessionsByShard.delete(key);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Adapts one per-registry remote session owner to the server work-registry port.
|
|
271
|
+
*/
|
|
272
|
+
export class RemoteWorkRegistry {
|
|
273
|
+
// prettier-ignore
|
|
274
|
+
/**
|
|
275
|
+
* Identifies the exclusive session model used by the remote registry.
|
|
276
|
+
*/
|
|
277
|
+
sessionKind = "EXCLUSIVE";
|
|
278
|
+
#owner;
|
|
279
|
+
/**
|
|
280
|
+
* Creates a registry backed by the supplied delivery client.
|
|
281
|
+
*
|
|
282
|
+
* @param client Sends shard operations to the delivery server.
|
|
283
|
+
*/
|
|
284
|
+
constructor(client) {
|
|
285
|
+
this.#owner = new RemoteSessionOwner(client);
|
|
286
|
+
conditionalPickUp.register(this, (shard, worker, options) => this.#owner.pickUp(shard, worker, options));
|
|
287
|
+
Object.freeze(this);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Acquires a remote shard for a complete worker identity.
|
|
291
|
+
*
|
|
292
|
+
* @param shardIndex Identifies the shard to acquire.
|
|
293
|
+
* @param worker Identifies the worker requesting the shard.
|
|
294
|
+
* @param options Bounds or cancels the remote operation.
|
|
295
|
+
* @returns The acquired exclusive session, or `undefined` when unavailable.
|
|
296
|
+
*/
|
|
297
|
+
pickUp(shardIndex, worker, options) {
|
|
298
|
+
return this.#owner.pickUp(shardIndex, worker, options);
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Removes a remote shard session owned by this registry.
|
|
302
|
+
*
|
|
303
|
+
* @param session Identifies the session to release.
|
|
304
|
+
* @param options Bounds or cancels the remote operation.
|
|
305
|
+
* @returns Whether the registry recognized and released the session.
|
|
306
|
+
*/
|
|
307
|
+
release(session, options) {
|
|
308
|
+
return this.#owner.release(session, options);
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Validates current remote ownership before a guarded side effect.
|
|
312
|
+
*
|
|
313
|
+
* @param session Supplies the exclusive session to validate.
|
|
314
|
+
* @param options Bounds or cancels the authoritative probe.
|
|
315
|
+
* @returns The retained session, or `undefined` when validation fails.
|
|
316
|
+
*/
|
|
317
|
+
validateOwnership(session, options) {
|
|
318
|
+
return this.#owner.validateOwnership(session, options);
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Applies an Admin shard observation to local ownership.
|
|
322
|
+
*
|
|
323
|
+
* @param observation Describes the current remote shard state.
|
|
324
|
+
*/
|
|
325
|
+
reconcile(observation) {
|
|
326
|
+
this.#owner.reconcile(observation);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Groups immutable remote-adapter value operations.
|
|
331
|
+
*/
|
|
332
|
+
const RemoteValues = Object.freeze({
|
|
333
|
+
receiveMessage(input) {
|
|
334
|
+
const message = DeliveryMessageCodec.snapshot({
|
|
335
|
+
...input,
|
|
336
|
+
id: RemoteValues.freeze({
|
|
337
|
+
value: randomUUID(),
|
|
338
|
+
shard: DeliveryShardCodec.snapshot(input.shard),
|
|
339
|
+
}),
|
|
340
|
+
shard: DeliveryShardCodec.snapshot(input.shard),
|
|
341
|
+
});
|
|
342
|
+
DeliveryMessageCodec.encode(message);
|
|
343
|
+
return message;
|
|
344
|
+
},
|
|
345
|
+
freeze(value) {
|
|
346
|
+
return Object.freeze(value);
|
|
347
|
+
},
|
|
348
|
+
shardKey(value) {
|
|
349
|
+
return `${String(value.index)}/${String(value.ofTotal)}`;
|
|
350
|
+
},
|
|
351
|
+
pageAnchor(value) {
|
|
352
|
+
const milliseconds = value.getTime();
|
|
353
|
+
if (milliseconds <= -62_135_596_800_000)
|
|
354
|
+
throw new DeliveryPagingError();
|
|
355
|
+
return new Date(milliseconds - 1);
|
|
356
|
+
},
|
|
357
|
+
sameShard(left, right) {
|
|
358
|
+
return left.index === right.index && left.ofTotal === right.ofTotal;
|
|
359
|
+
},
|
|
360
|
+
sameWorker(left, right) {
|
|
361
|
+
return left.nodeId === right.nodeId && left.value === right.value;
|
|
362
|
+
},
|
|
363
|
+
exactAfter(page, after) {
|
|
364
|
+
const exact = page.findIndex((message) => message.id.value === after.messageId &&
|
|
365
|
+
message.whenReceived.getTime() === after.whenReceived.getTime() &&
|
|
366
|
+
message.version === after.version);
|
|
367
|
+
if (exact < 0)
|
|
368
|
+
throw new DeliveryPagingError();
|
|
369
|
+
return exact + 1;
|
|
370
|
+
},
|
|
371
|
+
sameMessage(left, right) {
|
|
372
|
+
return (left.id.value === right.id.value &&
|
|
373
|
+
RemoteValues.sameShard(left.id.shard, right.id.shard) &&
|
|
374
|
+
RemoteValues.sameShard(left.shard, right.shard) &&
|
|
375
|
+
RemoteValues.sameAny(left.inboxId.targetId, right.inboxId.targetId) &&
|
|
376
|
+
left.inboxId.targetTypeUrl === right.inboxId.targetTypeUrl &&
|
|
377
|
+
left.signalId === right.signalId &&
|
|
378
|
+
RemoteValues.sameAny(left.signal, right.signal) &&
|
|
379
|
+
left.label === right.label &&
|
|
380
|
+
left.status === right.status &&
|
|
381
|
+
left.version === right.version &&
|
|
382
|
+
left.whenReceived.getTime() === right.whenReceived.getTime() &&
|
|
383
|
+
RemoteValues.sameDate(left.keepUntil, right.keepUntil));
|
|
384
|
+
},
|
|
385
|
+
sameDate(left, right) {
|
|
386
|
+
return left === undefined ? right === undefined : left.getTime() === right?.getTime();
|
|
387
|
+
},
|
|
388
|
+
sameAny(left, right) {
|
|
389
|
+
return left === undefined || right === undefined
|
|
390
|
+
? left === right
|
|
391
|
+
: left.typeUrl === right.typeUrl &&
|
|
392
|
+
left.value.length === right.value.length &&
|
|
393
|
+
left.value.every((value, index) => value === right.value[index]);
|
|
394
|
+
},
|
|
395
|
+
worker(worker) {
|
|
396
|
+
const nodeId = worker.nodeId?.value;
|
|
397
|
+
if (typeof nodeId !== "string" ||
|
|
398
|
+
nodeId.trim().length === 0 ||
|
|
399
|
+
typeof worker.value !== "string" ||
|
|
400
|
+
worker.value.trim().length === 0)
|
|
401
|
+
throw new TypeError("Delivery worker ID is invalid.");
|
|
402
|
+
return RemoteValues.freeze({ nodeId, value: worker.value });
|
|
403
|
+
},
|
|
404
|
+
});
|
|
405
|
+
//# sourceMappingURL=adapters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapters.js","sourceRoot":"","sources":["../../src/remote/adapters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAczC,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAGxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wDAAwD,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EACL,mBAAmB,EACnB,qBAAqB,GAItB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAElG;;GAEG;AACH,MAAM,OAAO,WAAW;IAaO;IAZ7B,kBAAkB;IAElB;;OAEG;IACM,WAAW,GAAG,WAAoB,CAAC;IAE5C;;;;OAIG;IACH,YAA6B,MAAsB;QAAtB,WAAM,GAAN,MAAM,CAAgB;QACjD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,OAAO,CACX,KAAwB,EACxB,OAAkC;QAElC,MAAM,OAAO,GAAG,YAAY,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QACnD,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC7C,OAAO,YAAY,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,SAAkB,EAAE,OAAO,EAAE,CAAC,CAAC;IACvE,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,IAAI,CACR,UAAsB,EACtB,UAAuD,EAAE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AAC,gCAAgC,CAAC,CAAC;QACxD,OAAO,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IAC9D,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { type ServerEnvironmentDelivery, type DeliverySource } from "@spine-event-engine/server";
|
|
2
|
+
import type { DeliveryClientOptions } from "../client/types.js";
|
|
3
|
+
import { RemoteInbox, RemoteWorkRegistry } from "./adapters.js";
|
|
4
|
+
/**
|
|
5
|
+
* Configures one remote delivery facility owned by a server environment.
|
|
6
|
+
*/
|
|
7
|
+
export interface RemoteDeliveryConfig {
|
|
8
|
+
/**
|
|
9
|
+
* Supplies the HTTP(S) origin of the delivery server.
|
|
10
|
+
*/
|
|
11
|
+
readonly endpoint: string;
|
|
12
|
+
/**
|
|
13
|
+
* Optionally configures bounded client operations.
|
|
14
|
+
*/
|
|
15
|
+
readonly clientOptions?: DeliveryClientOptions;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Opens and closes one remote delivery facility for a server environment.
|
|
19
|
+
*
|
|
20
|
+
* Opening creates a fresh client and remote adapters, verifies the bounded
|
|
21
|
+
* Admin snapshot, then publishes them. Failed opening closes only that attempt
|
|
22
|
+
* and can be retried.
|
|
23
|
+
*/
|
|
24
|
+
export declare class RemoteDelivery implements ServerEnvironmentDelivery {
|
|
25
|
+
#private;
|
|
26
|
+
private constructor();
|
|
27
|
+
/**
|
|
28
|
+
* Creates an unopened remote delivery owner.
|
|
29
|
+
*
|
|
30
|
+
* @param config Supplies remote endpoint and optional client bounds.
|
|
31
|
+
* @returns The environment-owned remote delivery.
|
|
32
|
+
*/
|
|
33
|
+
static connectTo(config: RemoteDeliveryConfig): RemoteDelivery;
|
|
34
|
+
/**
|
|
35
|
+
* Opens the remote facility once, sharing concurrent callers.
|
|
36
|
+
*
|
|
37
|
+
* @returns A promise that settles after bounded Admin readiness succeeds.
|
|
38
|
+
*/
|
|
39
|
+
open(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Returns the ready remote inbox adapter.
|
|
42
|
+
*
|
|
43
|
+
* @returns The published inbox adapter after readiness succeeds.
|
|
44
|
+
*/
|
|
45
|
+
get inbox(): RemoteInbox;
|
|
46
|
+
/**
|
|
47
|
+
* Returns the ready remote shard work-registry adapter.
|
|
48
|
+
*
|
|
49
|
+
* @returns The published work registry after readiness succeeds.
|
|
50
|
+
*/
|
|
51
|
+
get workRegistry(): RemoteWorkRegistry;
|
|
52
|
+
/**
|
|
53
|
+
* Returns the ready Admin source used by environment delivery supervisors.
|
|
54
|
+
*
|
|
55
|
+
* @returns The source that supplies bounded snapshots and one-attempt shard updates.
|
|
56
|
+
*/
|
|
57
|
+
get source(): DeliverySource;
|
|
58
|
+
/**
|
|
59
|
+
* Closes the client-owned HTTP/2 session.
|
|
60
|
+
*
|
|
61
|
+
* @returns A promise that retries only unfinished close phases after a failure.
|
|
62
|
+
*/
|
|
63
|
+
close(): Promise<void>;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=remote-delivery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-delivery.d.ts","sourceRoot":"","sources":["../../src/remote/remote-delivery.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,KAAK,yBAAyB,EAAE,KAAK,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAGjG,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEhE;;GAEG;AACH,MAAM,WAAW,oBAAoB;IAGnC;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,qBAAqB,CAAC;CAChD;AAED;;;;;;GAMG;AACH,qBAAa,cAAe,YAAW,yBAAyB;;IAU9D,OAAO;IAKP;;;;;OAKG;IACH,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,oBAAoB,GAAG,cAAc;IAI9D;;;;OAIG;IACH,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAWrB;;;;OAIG;IACH,IAAI,KAAK,IAAI,WAAW,CAGvB;IAED;;;;OAIG;IACH,IAAI,YAAY,IAAI,kBAAkB,CAGrC;IAED;;;;OAIG;IACH,IAAI,MAAM,IAAI,cAAc,CAG3B;IAED;;;;OAIG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CA4EvB"}
|