@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.
@@ -0,0 +1,178 @@
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
+ var _a;
15
+ import { DeliveryProtocolError, DeliveryShardObservationError, ShardObservationOverflowError, } from "./types.js";
16
+ /**
17
+ * Buffers one bounded, reconnecting remote shard-observation stream.
18
+ */
19
+ export class ShardObservationStream {
20
+ config;
21
+ #values = [];
22
+ #waiters = [];
23
+ #error;
24
+ #done = false;
25
+ /**
26
+ * Creates and begins an observation stream.
27
+ * @param config Supplies bounded transport, decoding, and cleanup operations.
28
+ */
29
+ constructor(config) {
30
+ this.config = config;
31
+ void this.#pump();
32
+ }
33
+ /**
34
+ * Cancels this stream and releases its local resources.
35
+ */
36
+ cancel() {
37
+ if (this.#done)
38
+ return;
39
+ this.config.cancel();
40
+ this.#finish();
41
+ }
42
+ /**
43
+ * Returns this stream's async iterator.
44
+ * @returns An iterator that yields detached observations.
45
+ */
46
+ [Symbol.asyncIterator]() {
47
+ return {
48
+ next: () => this.#next(),
49
+ return: () => {
50
+ this.cancel();
51
+ return Promise.resolve({ done: true, value: undefined });
52
+ },
53
+ };
54
+ }
55
+ async #pump() {
56
+ try {
57
+ for (let attempt = 0;; attempt++) {
58
+ try {
59
+ await this.#observeAttempt();
60
+ }
61
+ catch (error) {
62
+ if (this.config.signal.aborted)
63
+ return;
64
+ if (error instanceof DeliveryProtocolError ||
65
+ error instanceof ShardObservationOverflowError)
66
+ throw error;
67
+ if (attempt === this.config.reconnects)
68
+ throw new DeliveryShardObservationError();
69
+ await _a.#pause(this.config.reconnectBackoffMs, this.config.signal);
70
+ }
71
+ }
72
+ }
73
+ catch (error) {
74
+ if (!this.config.signal.aborted)
75
+ this.#error = error instanceof Error ? error : new DeliveryShardObservationError();
76
+ }
77
+ finally {
78
+ this.#finish();
79
+ }
80
+ }
81
+ async #observeAttempt() {
82
+ const setup = new AbortController();
83
+ const abort = () => {
84
+ setup.abort(this.config.signal.reason);
85
+ };
86
+ this.config.signal.addEventListener("abort", abort, { once: true });
87
+ const timeout = setTimeout(() => {
88
+ setup.abort(new DeliveryShardObservationError());
89
+ }, this.config.setupTimeoutMs);
90
+ try {
91
+ let acknowledged = false;
92
+ for await (const frame of this.config.open(setup.signal)) {
93
+ if (!acknowledged) {
94
+ if (!this.config.acknowledge(frame))
95
+ throw new DeliveryProtocolError();
96
+ acknowledged = true;
97
+ clearTimeout(timeout);
98
+ continue;
99
+ }
100
+ this.#push(this.config.decodeUpdate(frame));
101
+ }
102
+ throw new DeliveryShardObservationError();
103
+ }
104
+ finally {
105
+ clearTimeout(timeout);
106
+ this.config.signal.removeEventListener("abort", abort);
107
+ }
108
+ }
109
+ #push(value) {
110
+ if (this.#waiters.length > 0) {
111
+ const waiter = this.#waiters.shift();
112
+ if (waiter === undefined)
113
+ throw new DeliveryShardObservationError();
114
+ waiter({ done: false, value });
115
+ return;
116
+ }
117
+ if (this.#values.length >= this.config.capacity)
118
+ throw new ShardObservationOverflowError();
119
+ this.#values.push(value);
120
+ }
121
+ #next() {
122
+ if (this.#error !== undefined)
123
+ return Promise.reject(this.#error);
124
+ const value = this.#values.shift();
125
+ if (value !== undefined)
126
+ return Promise.resolve({ done: false, value });
127
+ if (this.#done)
128
+ return Promise.resolve({ done: true, value: undefined });
129
+ if (this.#waiters.length >= this.config.capacity) {
130
+ const error = new ShardObservationOverflowError();
131
+ this.#error = error;
132
+ this.config.cancel();
133
+ this.#finish();
134
+ return Promise.reject(error);
135
+ }
136
+ return new Promise((resolve) => this.#waiters.push(resolve)).then((result) => {
137
+ if (this.#error !== undefined)
138
+ throw this.#error;
139
+ return result;
140
+ });
141
+ }
142
+ #finish() {
143
+ if (this.#done)
144
+ return;
145
+ this.#done = true;
146
+ this.config.finish();
147
+ const result = { done: true, value: undefined };
148
+ for (const resolve of this.#waiters.splice(0))
149
+ resolve(result);
150
+ }
151
+ static #pause(delay, signal) {
152
+ if (delay === 0)
153
+ return signal.aborted
154
+ ? Promise.reject(signal.reason instanceof Error
155
+ ? signal.reason
156
+ : new Error("Delivery observation aborted."))
157
+ : Promise.resolve();
158
+ return new Promise((resolve, reject) => {
159
+ const finish = (reason) => {
160
+ signal.removeEventListener("abort", abort);
161
+ if (reason === undefined)
162
+ resolve();
163
+ else
164
+ reject(reason);
165
+ };
166
+ const timer = setTimeout(finish, delay);
167
+ const abort = () => {
168
+ clearTimeout(timer);
169
+ finish(signal.reason instanceof Error
170
+ ? signal.reason
171
+ : new Error("Delivery observation aborted."));
172
+ };
173
+ signal.addEventListener("abort", abort, { once: true });
174
+ });
175
+ }
176
+ }
177
+ _a = ShardObservationStream;
178
+ //# sourceMappingURL=shard-observation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shard-observation.js","sourceRoot":"","sources":["../../src/client/shard-observation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;;AAIH,OAAO,EACL,qBAAqB,EACrB,6BAA6B,EAC7B,6BAA6B,GAG9B,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,OAAO,sBAAsB;IAWd;IAVV,OAAO,GAA6B,EAAE,CAAC;IACvC,QAAQ,GAAiE,EAAE,CAAC;IACrF,MAAM,CAAoB;IAC1B,KAAK,GAAG,KAAK,CAAC;IAEd;;;OAGG;IACH,YACmB,MAWhB;QAXgB,WAAM,GAAN,MAAM,CAWtB;QAED,KAAK,IAAI,CA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AI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,MAAM,GAAG,CAAC,MAAc,EAAE,EAAE;gBAChC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;gBAC3C,IAAI,MAAM,KAAK,SAAS;oBAAE,OAAO,EAAE,CAAC;;oBAC/B,MAAM,CAAC,MAAM,CAAC,CAAC;YACtB,CAAC,CAAC;YACF,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YACxC,MAAM,KAAK,GAAG,GAAG,EAAE;gBACjB,YAAY,CAAC,KAAK,CAAC,CAAC;gBACpB,MAAM,CACJ,MAAM,CAAC,MAAM,YAAY,KAAK;oBAC5B,CAAC,CAAC,MAAM,CAAC,MAAM;oBACf,CAAC,CAAC,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAC/C,CAAC;YACJ,CAAC,CAAC;YACF,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,229 @@
1
+ import { ShardIndex } from "@spine-event-engine/server";
2
+ /**
3
+ * Stable public worker identity represented by the frozen `WorkerId` wire type.
4
+ * `nodeId` and `value` must be non-blank and together occupy at most 128 UTF-8 bytes.
5
+ */
6
+ export interface DeliveryWorkerId {
7
+ /**
8
+ * Identifies the application node that owns this worker.
9
+ */
10
+ readonly nodeId: string;
11
+ /**
12
+ * Identifies this worker within its application node.
13
+ */
14
+ readonly value: string;
15
+ }
16
+ /**
17
+ * A remote exclusive shard session that can be released by this client.
18
+ */
19
+ export interface RemoteShardSession {
20
+ /**
21
+ * Identifies the exclusive session kind accepted by the remote service.
22
+ */
23
+ readonly kind: "EXCLUSIVE";
24
+ /**
25
+ * Identifies the shard held by this session.
26
+ */
27
+ readonly shard: ShardIndex;
28
+ /**
29
+ * Identifies the worker that acquired this session.
30
+ */
31
+ readonly worker: DeliveryWorkerId;
32
+ /**
33
+ * Records when the remote service granted the session.
34
+ */
35
+ readonly whenPicked: Date;
36
+ }
37
+ /**
38
+ * A detached observation of a session released for inactivity.
39
+ */
40
+ export interface ReleasedShardSession extends RemoteShardSession {
41
+ /**
42
+ * Records when the remote service released the inactive session.
43
+ */
44
+ readonly whenReleased: Date;
45
+ }
46
+ /**
47
+ * A detached Admin observation of one remote delivery shard.
48
+ */
49
+ export interface RemoteShardObservation {
50
+ /**
51
+ * Identifies the observed shard.
52
+ */
53
+ readonly shard: ShardIndex;
54
+ /**
55
+ * Describes whether the shard is currently held.
56
+ */
57
+ readonly status: "PICKED" | "NOT_PICKED";
58
+ /**
59
+ * Records the most recent pickup when the server provides it.
60
+ */
61
+ readonly lastPicked?: Date;
62
+ /**
63
+ * Counts messages currently reported for the shard.
64
+ */
65
+ readonly messages: number;
66
+ }
67
+ /**
68
+ * Maximum serialized command or event envelope accepted from the delivery server.
69
+ */
70
+ export declare const MAX_INBOX_PAYLOAD_BYTES: 1048576;
71
+ /**
72
+ * Hard maximum number of messages accepted by one delivery batch mutation.
73
+ */
74
+ export declare const MAX_DELIVERY_BATCH_MESSAGES = 100;
75
+ /**
76
+ * Maximum serialized delivery RPC request or page response accepted by this client.
77
+ */
78
+ export declare const MAX_DELIVERY_RPC_BYTES: 4194304;
79
+ /**
80
+ * Maximum shard observations accepted from the in-memory delivery server.
81
+ */
82
+ export declare const MAX_DELIVERY_TRACKED_SHARDS = 1000;
83
+ /**
84
+ * Maximum combined UTF-8 bytes of one worker and node identity.
85
+ */
86
+ export declare const MAX_DELIVERY_WORKER_BYTES = 128;
87
+ /**
88
+ * Raised when a frozen delivery-server response cannot be represented safely.
89
+ */
90
+ export declare class DeliveryProtocolError extends Error {
91
+ /**
92
+ * Creates an error for an invalid delivery-server response.
93
+ */
94
+ constructor();
95
+ }
96
+ /**
97
+ * Raised when the timestamp-only delivery wire page cannot continue without loss.
98
+ */
99
+ export declare class DeliveryPagingError extends Error {
100
+ /**
101
+ * Creates an error for a page that cannot continue safely.
102
+ */
103
+ constructor();
104
+ }
105
+ /**
106
+ * Raised when a slow observer exceeds the bounded shard-update buffer.
107
+ */
108
+ export declare class ShardObservationOverflowError extends Error {
109
+ /**
110
+ * Creates an error for a full shard-observation buffer.
111
+ */
112
+ constructor();
113
+ }
114
+ /**
115
+ * Raised when a shard observation stream ends without a usable recovery.
116
+ */
117
+ export declare class DeliveryShardObservationError extends Error {
118
+ /**
119
+ * Creates an error for a failed shard-observation stream.
120
+ */
121
+ constructor();
122
+ }
123
+ /**
124
+ * Raised when a write may have reached the delivery server but its result was lost.
125
+ */
126
+ export declare class DeliveryOutcomeUnknownError extends Error {
127
+ /**
128
+ * Identifies the mutation whose remote outcome could not be established.
129
+ */
130
+ readonly operation: "WRITE_ONE" | "WRITE_MANY" | "REMOVE_ONE" | "REMOVE_MANY" | "PICK_UP_SHARD" | "RELEASE_SHARD" | "RELEASE_EXPIRED";
131
+ /**
132
+ * Identifies the observation required to reconcile the mutation outcome.
133
+ */
134
+ readonly reconciliation: Readonly<{
135
+ readonly kind: "FIND_MESSAGE";
136
+ readonly messageIds: readonly string[];
137
+ } | {
138
+ readonly kind: "OBSERVE_SHARD";
139
+ readonly shards: readonly ShardIndex[];
140
+ } | {
141
+ readonly kind: "OBSERVE_SHARD";
142
+ readonly scope: "ALL_SHARDS";
143
+ }>;
144
+ /**
145
+ * Creates an error with the safe observation required before further action.
146
+ *
147
+ * @param operation Identifies the mutation with an unknown outcome.
148
+ * @param reconciliation Identifies messages or shards that must be observed.
149
+ */
150
+ constructor(operation: DeliveryOutcomeUnknownError["operation"], reconciliation: readonly string[] | readonly ShardIndex[] | "ALL_SHARDS");
151
+ }
152
+ /**
153
+ * Options for constructing a delivery client.
154
+ */
155
+ export interface DeliveryClientOptions {
156
+ /**
157
+ * Limits messages requested in one read page.
158
+ */
159
+ readonly pageSize?: number;
160
+ /**
161
+ * Limits retries for safe read operations.
162
+ */
163
+ readonly readRetries?: number;
164
+ /**
165
+ * Delays each safe-read retry in milliseconds.
166
+ */
167
+ readonly retryBackoffMs?: number;
168
+ /**
169
+ * Limits reconnects for a shard-observation stream.
170
+ */
171
+ readonly observationReconnects?: number;
172
+ /**
173
+ * Delays each observation reconnect in milliseconds.
174
+ */
175
+ readonly observationReconnectBackoffMs?: number;
176
+ /**
177
+ * Limits queued observations and pending consumers.
178
+ */
179
+ readonly observationBufferSize?: number;
180
+ }
181
+ /**
182
+ * A cancellable, bounded stream of detached remote shard observations.
183
+ */
184
+ export interface DeliveryShardObservationStream extends AsyncIterable<RemoteShardObservation> {
185
+ /**
186
+ * Cancels the observation stream and releases its local listeners.
187
+ */
188
+ cancel(): void;
189
+ }
190
+ /**
191
+ * Options for one side-effect-free read operation.
192
+ */
193
+ export interface DeliveryFindOneOptions {
194
+ /**
195
+ * Cancels the operation when the caller no longer needs its result.
196
+ */
197
+ readonly signal?: AbortSignal;
198
+ /**
199
+ * Limits finite reads and stream setup in milliseconds; it never limits an acknowledged active stream.
200
+ */
201
+ readonly timeoutMs?: number;
202
+ }
203
+ /**
204
+ * A bounded read page request; the wire contract can continue only by timestamp.
205
+ */
206
+ export interface DeliveryReadPageOptions extends DeliveryFindOneOptions {
207
+ /**
208
+ * Continues a timestamp-ordered page after this received time.
209
+ */
210
+ readonly sinceWhen?: Date;
211
+ /**
212
+ * Limits messages requested for this page.
213
+ */
214
+ readonly pageSize?: number;
215
+ }
216
+ /**
217
+ * Options for one non-idempotent delivery mutation.
218
+ */
219
+ export interface DeliveryMutationOptions {
220
+ /**
221
+ * Cancels the mutation before its transport call completes.
222
+ */
223
+ readonly signal?: AbortSignal;
224
+ /**
225
+ * Limits the mutation duration in milliseconds.
226
+ */
227
+ readonly timeoutMs?: number;
228
+ }
229
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"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CAAC,6BAA6B,CAAC,EAAE,MAAM,CAAC;IAEhD;;OAEG;IACH,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,CAAC;CACzC;AAED;;GAEG;AACH,MAAM,WAAW,8BAA+B,SAAQ,aAAa,CAAC,sBAAsB,CAAC;IAG3F;;OAEG;IACH,MAAM,IAAI,IAAI,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IAGrC;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAE9B;;OAEG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,uBAAwB,SAAQ,sBAAsB;IAGrE;;OAEG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC;IAE1B;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IAGtC;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAE9B;;OAEG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B"}
@@ -0,0 +1,128 @@
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 { ShardIndex } from "@spine-event-engine/server";
15
+ /**
16
+ * Maximum serialized command or event envelope accepted from the delivery server.
17
+ */
18
+ export const MAX_INBOX_PAYLOAD_BYTES = 1_048_576;
19
+ /**
20
+ * Hard maximum number of messages accepted by one delivery batch mutation.
21
+ */
22
+ export const MAX_DELIVERY_BATCH_MESSAGES = 100;
23
+ /**
24
+ * Maximum serialized delivery RPC request or page response accepted by this client.
25
+ */
26
+ export const MAX_DELIVERY_RPC_BYTES = 4_194_304;
27
+ /**
28
+ * Maximum shard observations accepted from the in-memory delivery server.
29
+ */
30
+ export const MAX_DELIVERY_TRACKED_SHARDS = 1_000;
31
+ /**
32
+ * Maximum combined UTF-8 bytes of one worker and node identity.
33
+ */
34
+ export const MAX_DELIVERY_WORKER_BYTES = 128;
35
+ /**
36
+ * Raised when a frozen delivery-server response cannot be represented safely.
37
+ */
38
+ export class DeliveryProtocolError extends Error {
39
+ // prettier-ignore
40
+ /**
41
+ * Creates an error for an invalid delivery-server response.
42
+ */
43
+ constructor() {
44
+ super("Delivery server returned an invalid inbox message.");
45
+ this.name = "DeliveryProtocolError";
46
+ }
47
+ }
48
+ /**
49
+ * Raised when the timestamp-only delivery wire page cannot continue without loss.
50
+ */
51
+ export class DeliveryPagingError extends Error {
52
+ // prettier-ignore
53
+ /**
54
+ * Creates an error for a page that cannot continue safely.
55
+ */
56
+ constructor() {
57
+ super("Delivery server page cannot be continued safely.");
58
+ this.name = "DeliveryPagingError";
59
+ }
60
+ }
61
+ /**
62
+ * Raised when a slow observer exceeds the bounded shard-update buffer.
63
+ */
64
+ export class ShardObservationOverflowError extends Error {
65
+ // prettier-ignore
66
+ /**
67
+ * Creates an error for a full shard-observation buffer.
68
+ */
69
+ constructor() {
70
+ super("Delivery shard observation buffer overflowed.");
71
+ this.name = "ShardObservationOverflowError";
72
+ }
73
+ }
74
+ /**
75
+ * Raised when a shard observation stream ends without a usable recovery.
76
+ */
77
+ export class DeliveryShardObservationError extends Error {
78
+ // prettier-ignore
79
+ /**
80
+ * Creates an error for a failed shard-observation stream.
81
+ */
82
+ constructor() {
83
+ super("Delivery shard observation stream failed.");
84
+ this.name = "DeliveryShardObservationError";
85
+ }
86
+ }
87
+ /**
88
+ * Raised when a write may have reached the delivery server but its result was lost.
89
+ */
90
+ export class DeliveryOutcomeUnknownError extends Error {
91
+ // prettier-ignore
92
+ /**
93
+ * Identifies the mutation whose remote outcome could not be established.
94
+ */
95
+ operation;
96
+ /**
97
+ * Identifies the observation required to reconcile the mutation outcome.
98
+ */
99
+ reconciliation;
100
+ /**
101
+ * Creates an error with the safe observation required before further action.
102
+ *
103
+ * @param operation Identifies the mutation with an unknown outcome.
104
+ * @param reconciliation Identifies messages or shards that must be observed.
105
+ */
106
+ constructor(operation, reconciliation) {
107
+ super(operation === "WRITE_ONE" || operation === "WRITE_MANY"
108
+ ? "Delivery write outcome is unknown."
109
+ : operation === "REMOVE_ONE" || operation === "REMOVE_MANY"
110
+ ? "Delivery removal outcome is unknown."
111
+ : "Delivery shard operation outcome is unknown.");
112
+ this.name = "DeliveryOutcomeUnknownError";
113
+ this.operation = operation;
114
+ if (typeof reconciliation === "string")
115
+ this.reconciliation = Object.freeze({ kind: "OBSERVE_SHARD", scope: reconciliation });
116
+ else if (operation === "PICK_UP_SHARD" || operation === "RELEASE_SHARD")
117
+ this.reconciliation = Object.freeze({
118
+ kind: "OBSERVE_SHARD",
119
+ shards: Object.freeze(reconciliation.map((value) => new ShardIndex(value.index, value.ofTotal))),
120
+ });
121
+ else
122
+ this.reconciliation = Object.freeze({
123
+ kind: "FIND_MESSAGE",
124
+ messageIds: Object.freeze([...reconciliation]),
125
+ });
126
+ }
127
+ }
128
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAsFxD;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAY,SAAS,CAAC;AAE1D;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAE/C;;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,aAAa;gBACzD,CAAC,CAAC,sCAAsC;gBACxC,CAAC,CAAC,8CAA8C,CACrD,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;QAC1C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,OAAO,cAAc,KAAK,QAAQ;YACpC,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC;aACnF,IAAI,SAAS,KAAK,eAAe,IAAI,SAAS,KAAK,eAAe;YACrE,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC;gBAClC,IAAI,EAAE,eAAe;gBACrB,MAAM,EAAE,MAAM,CAAC,MAAM,CAClB,cAAwC,CAAC,GAAG,CAC3C,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CACtD,CACF;aACF,CAAC,CAAC;;YAEH,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC;gBAClC,IAAI,EAAE,cAAc;gBACpB,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAI,cAAoC,CAAC,CAAC;aACtE,CAAC,CAAC;IACP,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Public facade for the Node delivery-server client.
3
+ */
4
+ export { DeliveryClient, DeliveryOutcomeUnknownError, DeliveryPagingError, DeliveryProtocolError, DeliveryShardObservationError, ShardObservationOverflowError, MAX_DELIVERY_BATCH_MESSAGES, MAX_DELIVERY_RPC_BYTES, MAX_INBOX_PAYLOAD_BYTES, } from "./client/client.js";
5
+ export { RemoteInbox, RemoteWorkRegistry } from "./remote/adapters.js";
6
+ export { RemoteDelivery, type RemoteDeliveryConfig } from "./remote/remote-delivery.js";
7
+ export type { DeliveryClientOptions, DeliveryFindOneOptions, DeliveryMutationOptions, DeliveryReadPageOptions, DeliveryShardObservationStream, DeliveryWorkerId, ReleasedShardSession, RemoteShardObservation, RemoteShardSession, } from "./client/client.js";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA;;GAEG;AACH,OAAO,EACL,cAAc,EACd,2BAA2B,EAC3B,mBAAmB,EACnB,qBAAqB,EACrB,6BAA6B,EAC7B,6BAA6B,EAC7B,2BAA2B,EAC3B,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,KAAK,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAExF,YAAY,EACV,qBAAqB,EACrB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,8BAA8B,EAC9B,gBAAgB,EAChB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
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
+ /**
15
+ * Public facade for the Node delivery-server client.
16
+ */
17
+ export { DeliveryClient, DeliveryOutcomeUnknownError, DeliveryPagingError, DeliveryProtocolError, DeliveryShardObservationError, ShardObservationOverflowError, MAX_DELIVERY_BATCH_MESSAGES, MAX_DELIVERY_RPC_BYTES, MAX_INBOX_PAYLOAD_BYTES, } from "./client/client.js";
18
+ export { RemoteInbox, RemoteWorkRegistry } from "./remote/adapters.js";
19
+ export { RemoteDelivery } from "./remote/remote-delivery.js";
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;GAEG;AACH,OAAO,EACL,cAAc,EACd,2BAA2B,EAC3B,mBAAmB,EACnB,qBAAqB,EACrB,6BAA6B,EAC7B,6BAA6B,EAC7B,2BAA2B,EAC3B,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,cAAc,EAA6B,MAAM,6BAA6B,CAAC"}