@spine-event-engine/delivery-server 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 +97 -0
- package/REFERENCE.md +69 -0
- package/dist/admin/admin-service.d.ts +47 -0
- package/dist/admin/admin-service.d.ts.map +1 -0
- package/dist/admin/admin-service.js +188 -0
- package/dist/admin/admin-service.js.map +1 -0
- package/dist/bin/spine-delivery-server.d.ts +3 -0
- package/dist/bin/spine-delivery-server.d.ts.map +1 -0
- package/dist/bin/spine-delivery-server.js +54 -0
- package/dist/bin/spine-delivery-server.js.map +1 -0
- package/dist/core/in-memory-delivery-core.d.ts +56 -0
- package/dist/core/in-memory-delivery-core.d.ts.map +1 -0
- package/dist/core/in-memory-delivery-core.js +44 -0
- package/dist/core/in-memory-delivery-core.js.map +1 -0
- package/dist/core/in-memory-delivery-state.d.ts +86 -0
- package/dist/core/in-memory-delivery-state.d.ts.map +1 -0
- package/dist/core/in-memory-delivery-state.js +214 -0
- package/dist/core/in-memory-delivery-state.js.map +1 -0
- package/dist/core/inbox-service.d.ts +20 -0
- package/dist/core/inbox-service.d.ts.map +1 -0
- package/dist/core/inbox-service.js +212 -0
- package/dist/core/inbox-service.js.map +1 -0
- package/dist/core/limits.d.ts +64 -0
- package/dist/core/limits.d.ts.map +1 -0
- package/dist/core/limits.js +73 -0
- package/dist/core/limits.js.map +1 -0
- package/dist/core/mutation-admission.d.ts +18 -0
- package/dist/core/mutation-admission.d.ts.map +1 -0
- package/dist/core/mutation-admission.js +78 -0
- package/dist/core/mutation-admission.js.map +1 -0
- package/dist/core/shard-service.d.ts +22 -0
- package/dist/core/shard-service.d.ts.map +1 -0
- package/dist/core/shard-service.js +189 -0
- package/dist/core/shard-service.js.map +1 -0
- package/dist/core/wire-values.d.ts +22 -0
- package/dist/core/wire-values.d.ts.map +1 -0
- package/dist/core/wire-values.js +66 -0
- package/dist/core/wire-values.js.map +1 -0
- package/dist/health/health-service.d.ts +9 -0
- package/dist/health/health-service.d.ts.map +1 -0
- package/dist/health/health-service.js +47 -0
- package/dist/health/health-service.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/server/assembly.d.ts +41 -0
- package/dist/server/assembly.d.ts.map +1 -0
- package/dist/server/assembly.js +49 -0
- package/dist/server/assembly.js.map +1 -0
- package/dist/server/config.d.ts +57 -0
- package/dist/server/config.d.ts.map +1 -0
- package/dist/server/config.js +52 -0
- package/dist/server/config.js.map +1 -0
- package/dist/server/delivery-server-log.d.ts +11 -0
- package/dist/server/delivery-server-log.d.ts.map +1 -0
- package/dist/server/delivery-server-log.js +44 -0
- package/dist/server/delivery-server-log.js.map +1 -0
- package/dist/server/delivery-server.d.ts +103 -0
- package/dist/server/delivery-server.d.ts.map +1 -0
- package/dist/server/delivery-server.js +201 -0
- package/dist/server/delivery-server.js.map +1 -0
- package/dist/server/shutdown.d.ts +36 -0
- package/dist/server/shutdown.d.ts.map +1 -0
- package/dist/server/shutdown.js +25 -0
- package/dist/server/shutdown.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +38 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2026, CodeMatters. All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
|
6
|
+
* in compliance with the License. You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
11
|
+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
12
|
+
* or implied. See the License for the specific language governing permissions and limitations under
|
|
13
|
+
* the License.
|
|
14
|
+
*/
|
|
15
|
+
import { DeliveryServer } from "../server/delivery-server.js";
|
|
16
|
+
/**
|
|
17
|
+
* Provides process lifecycle handling for the delivery server executable.
|
|
18
|
+
*/
|
|
19
|
+
const DeliveryProcess = Object.freeze({
|
|
20
|
+
run: (server) => {
|
|
21
|
+
let stopping;
|
|
22
|
+
const removeSignalHandlers = () => {
|
|
23
|
+
process.off("SIGINT", stop);
|
|
24
|
+
process.off("SIGTERM", stop);
|
|
25
|
+
};
|
|
26
|
+
const stop = () => {
|
|
27
|
+
stopping ??= server
|
|
28
|
+
.close()
|
|
29
|
+
.catch((error) => {
|
|
30
|
+
process.exitCode = 1;
|
|
31
|
+
process.stderr.write(`Delivery server shutdown failed: ${DeliveryProcess.errorMessage(error)}\n`);
|
|
32
|
+
})
|
|
33
|
+
.finally(removeSignalHandlers);
|
|
34
|
+
};
|
|
35
|
+
process.on("SIGINT", stop);
|
|
36
|
+
process.on("SIGTERM", stop);
|
|
37
|
+
server.start().then((running) => {
|
|
38
|
+
process.stdout.write(`Delivery server listening at ${running.baseUrl}\n`);
|
|
39
|
+
}, (error) => {
|
|
40
|
+
process.exitCode = 1;
|
|
41
|
+
process.stderr.write(`Delivery server startup failed: ${DeliveryProcess.errorMessage(error)}\n`);
|
|
42
|
+
removeSignalHandlers();
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
errorMessage: (error) => error instanceof Error ? error.message : "unknown error",
|
|
46
|
+
});
|
|
47
|
+
try {
|
|
48
|
+
DeliveryProcess.run(new DeliveryServer());
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
process.exitCode = 1;
|
|
52
|
+
process.stderr.write(`Delivery server startup failed: ${DeliveryProcess.errorMessage(error)}\n`);
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=spine-delivery-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spine-delivery-server.js","sourceRoot":"","sources":["../../src/bin/spine-deliv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YACF,oBAAoB,EAAE,CAAC;QACzB,CAAC,CACF,CAAC;IACJ,CAAC;IACD,YAAY,EAAE,CAAC,KAAc,EAAU,EAAE,CACvC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;CAC3D,CAAC,CAAC;AAEH,IAAI,CAAC;IACH,eAAe,CAAC,GAAG,CAAC,IAAI,cAAc,EAAE,CAAC,CAAC;AAC5C,CAAC;AAAC,OAAO,KAAK,EAAE,CAAC;IACf,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACrB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,mCAAmC,eAAe,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACnG,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { ServiceImpl } from "@connectrpc/connect";
|
|
2
|
+
import { InboxService, ShardService } from "@spine-event-engine/proto/delivery-server";
|
|
3
|
+
/**
|
|
4
|
+
* Configures the listener-free in-memory delivery core.
|
|
5
|
+
*/
|
|
6
|
+
export interface DeliveryCoreOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Automatic pickup expiry; zero disables automatic stale takeover.
|
|
9
|
+
*/
|
|
10
|
+
readonly processingTimeoutMs?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Returns a deterministic wall-clock value in Unix milliseconds.
|
|
13
|
+
*
|
|
14
|
+
* @returns Provides the current Unix time in milliseconds.
|
|
15
|
+
*/
|
|
16
|
+
readonly now?: () => number;
|
|
17
|
+
/**
|
|
18
|
+
* Maximum retained records; integer from 1 through 2,147,483,647.
|
|
19
|
+
*/
|
|
20
|
+
readonly maxRetainedMessages?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Maximum retained serialized record bytes; integer from 1 through 2,147,483,647.
|
|
23
|
+
*/
|
|
24
|
+
readonly maxRetainedBytes?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Maximum tracked shards; integer from 1 through 1,000.
|
|
27
|
+
*/
|
|
28
|
+
readonly maxTrackedShards?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Provides handler implementations for caller-owned Connect router registration.
|
|
32
|
+
*/
|
|
33
|
+
export interface DeliveryCore {
|
|
34
|
+
/**
|
|
35
|
+
* Serves Inbox RPCs.
|
|
36
|
+
*/
|
|
37
|
+
readonly inbox: ServiceImpl<typeof InboxService>;
|
|
38
|
+
/**
|
|
39
|
+
* Serves Shard RPCs.
|
|
40
|
+
*/
|
|
41
|
+
readonly shards: ServiceImpl<typeof ShardService>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates listener-free in-memory delivery cores.
|
|
45
|
+
*/
|
|
46
|
+
export declare const InMemoryDelivery: Readonly<{
|
|
47
|
+
/**
|
|
48
|
+
* Creates an empty Inbox and Shard core.
|
|
49
|
+
*
|
|
50
|
+
* @param options Configures state limits and stale pickup expiry.
|
|
51
|
+
* @returns Provides the handlers without owning a listener or process lifecycle.
|
|
52
|
+
* @throws {RangeError} When the processing timeout is not a finite non-negative number.
|
|
53
|
+
*/
|
|
54
|
+
create(options?: DeliveryCoreOptions): DeliveryCore;
|
|
55
|
+
}>;
|
|
56
|
+
//# sourceMappingURL=in-memory-delivery-core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory-delivery-core.d.ts","sourceRoot":"","sources":["../../src/core/in-memory-delivery-core.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AAOvF;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAGlC;;OAEG;IACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAEtC;;;;OAIG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IAE5B;;OAEG;IACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAEtC;;OAEG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAEnC;;OAEG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAG3B;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,OAAO,YAAY,CAAC,CAAC;IAEjD;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,YAAY,CAAC,CAAC;CACnD;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC;IAGtC;;;;;;OAMG;IACH,MAAM,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,YAAY,CAAC;CACrD,CAsBC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
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 { InboxService, ShardService } from "@spine-event-engine/proto/delivery-server";
|
|
15
|
+
import { InboxHandlers } from "./inbox-service.js";
|
|
16
|
+
import { InMemoryDeliveryState } from "./in-memory-delivery-state.js";
|
|
17
|
+
import { MutationAdmission } from "./mutation-admission.js";
|
|
18
|
+
import { ShardHandlers } from "./shard-service.js";
|
|
19
|
+
/**
|
|
20
|
+
* Creates listener-free in-memory delivery cores.
|
|
21
|
+
*/
|
|
22
|
+
export const InMemoryDelivery = Object.freeze({
|
|
23
|
+
// prettier-ignore
|
|
24
|
+
/**
|
|
25
|
+
* Creates an empty Inbox and Shard core.
|
|
26
|
+
*
|
|
27
|
+
* @param options Configures state limits and stale pickup expiry.
|
|
28
|
+
* @returns Provides the handlers without owning a listener or process lifecycle.
|
|
29
|
+
* @throws {RangeError} When the processing timeout is not a finite non-negative number.
|
|
30
|
+
*/
|
|
31
|
+
create(options = {}) {
|
|
32
|
+
const timeout = options.processingTimeoutMs ?? 0;
|
|
33
|
+
if (!Number.isFinite(timeout) || timeout < 0)
|
|
34
|
+
throw new RangeError("Processing timeout is invalid.");
|
|
35
|
+
const state = new InMemoryDeliveryState(options);
|
|
36
|
+
const admission = new MutationAdmission();
|
|
37
|
+
const now = options.now ?? Date.now;
|
|
38
|
+
return Object.freeze({
|
|
39
|
+
inbox: InboxHandlers.create(state, admission),
|
|
40
|
+
shards: ShardHandlers.create(state, admission, now, timeout),
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=in-memory-delivery-core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory-delivery-core.js","sourceRoot":"","sources":["../../src/core/in-memory-delivery-core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AAEvF,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAqDnD;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAWxB,MAAM,CAAC,MAAM,CAAC;IACjB,kBAAkB;IAElB;;;;;;OAMG;IACH,MAAM,CAAC,UAA+B,EAAE;QACtC,MAAM,OAAO,GAAG,OAAO,CAAC,mBAAmB,IAAI,CAAC,CAAC;QACjD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,CAAC;YAC1C,MAAM,IAAI,UAAU,CAAC,gCAAgC,CAAC,CAAC;QACzD,MAAM,KAAK,GAAG,IAAI,qBAAqB,CAAC,OAAO,CAAC,CAAC;QACjD,MAAM,SAAS,GAAG,IAAI,iBAAiB,EAAE,CAAC;QAC1C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC;QACpC,OAAO,MAAM,CAAC,MAAM,CAAC;YACnB,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC;YAC7C,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,CAAC;SAC7D,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { type InboxMessage, type ShardIndex, type WorkerId } from "@spine-event-engine/proto/delivery";
|
|
2
|
+
import { type DeliveryStateLimits } from "./limits.js";
|
|
3
|
+
/**
|
|
4
|
+
* Represents retained pickup state for one delivery shard.
|
|
5
|
+
*/
|
|
6
|
+
export interface ShardRecord {
|
|
7
|
+
/**
|
|
8
|
+
* Identifies the tracked shard.
|
|
9
|
+
*/
|
|
10
|
+
readonly shard: ShardIndex;
|
|
11
|
+
/**
|
|
12
|
+
* Identifies the current worker when picked.
|
|
13
|
+
*/
|
|
14
|
+
readonly worker: WorkerId | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Records the pickup time in milliseconds.
|
|
17
|
+
*/
|
|
18
|
+
readonly whenLastPicked: number | undefined;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Package-private canonical detached state; a new instance deliberately starts empty.
|
|
22
|
+
*/
|
|
23
|
+
export declare class InMemoryDeliveryState {
|
|
24
|
+
#private;
|
|
25
|
+
/**
|
|
26
|
+
* Stores messages by stable identity.
|
|
27
|
+
*/
|
|
28
|
+
readonly messages: Map<string, InboxMessage>;
|
|
29
|
+
/**
|
|
30
|
+
* Stores sessions by stable shard identity.
|
|
31
|
+
*/
|
|
32
|
+
readonly shards: Map<string, ShardRecord>;
|
|
33
|
+
/**
|
|
34
|
+
* Creates empty state.
|
|
35
|
+
*
|
|
36
|
+
* @param limits Configures retained-state limits.
|
|
37
|
+
*/
|
|
38
|
+
constructor(limits?: Partial<DeliveryStateLimits>);
|
|
39
|
+
/**
|
|
40
|
+
* Stores a validated batch atomically.
|
|
41
|
+
*
|
|
42
|
+
* @param messages Supplies encoded messages.
|
|
43
|
+
* @returns Lists newly inserted messages.
|
|
44
|
+
*/
|
|
45
|
+
putAll(messages: readonly {
|
|
46
|
+
readonly message: InboxMessage;
|
|
47
|
+
readonly bytes: number;
|
|
48
|
+
}[]): InboxMessage[];
|
|
49
|
+
/**
|
|
50
|
+
* Deletes a message.
|
|
51
|
+
*
|
|
52
|
+
* @param message Identifies the message.
|
|
53
|
+
* @returns Reports whether the message existed.
|
|
54
|
+
*/
|
|
55
|
+
delete(message: InboxMessage): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Finds an active shard session.
|
|
58
|
+
*
|
|
59
|
+
* @param shard Identifies the shard.
|
|
60
|
+
* @returns Provides the session when active.
|
|
61
|
+
*/
|
|
62
|
+
session(shard: ShardIndex): ShardRecord | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Determines whether a shard has a retained `TO_DELIVER` message awaiting delivery.
|
|
65
|
+
*
|
|
66
|
+
* @param shard Identifies the shard to inspect.
|
|
67
|
+
* @returns Whether the shard has at least one retained `TO_DELIVER` message.
|
|
68
|
+
*/
|
|
69
|
+
hasPending(shard: ShardIndex): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Stores a shard pickup session.
|
|
72
|
+
*
|
|
73
|
+
* @param shard Identifies the shard.
|
|
74
|
+
* @param worker Identifies the worker.
|
|
75
|
+
* @param whenPicked Records the pickup time.
|
|
76
|
+
*/
|
|
77
|
+
setSession(shard: ShardIndex, worker: WorkerId, whenPicked: number): void;
|
|
78
|
+
/**
|
|
79
|
+
* Removes an active shard session.
|
|
80
|
+
*
|
|
81
|
+
* @param shard Identifies the shard.
|
|
82
|
+
* @returns Provides the former session when active.
|
|
83
|
+
*/
|
|
84
|
+
release(shard: ShardIndex): ShardRecord | undefined;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=in-memory-delivery-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory-delivery-state.d.ts","sourceRoot":"","sources":["../../src/core/in-memory-delivery-state.ts"],"names":[],"mappings":"AAeA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,QAAQ,EACd,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAkB,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGvE;;GAEG;AACH,MAAM,WAAW,WAAW;IAG1B;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,CAAC;IAEtC;;OAEG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7C;AAED;;GAEG;AACH,qBAAa,qBAAqB;;IAGhC;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAmC;IAE/E;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAkC;IAO3E;;;;OAIG;gBACS,MAAM,GAAE,OAAO,CAAC,mBAAmB,CAAM;IAIrD;;;;;OAKG;IACH,MAAM,CACJ,QAAQ,EAAE,SAAS;QAAE,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,GAC9E,YAAY,EAAE;IAgBjB;;;;;OAKG;IACH,MAAM,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO;IAatC;;;;;OAKG;IACH,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,GAAG,SAAS;IAKnD;;;;;OAKG;IACH,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO;IAItC;;;;;;OAMG;IACH,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;IASzE;;;;;OAKG;IACH,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,GAAG,SAAS;CAuFpD"}
|
|
@@ -0,0 +1,214 @@
|
|
|
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 { Code, ConnectError } from "@connectrpc/connect";
|
|
15
|
+
import { InboxMessageStatus, } from "@spine-event-engine/proto/delivery";
|
|
16
|
+
import { DeliveryLimits } from "./limits.js";
|
|
17
|
+
import { DeliveryMessages, DeliveryShards, DeliveryWorkers } from "./wire-values.js";
|
|
18
|
+
/**
|
|
19
|
+
* Package-private canonical detached state; a new instance deliberately starts empty.
|
|
20
|
+
*/
|
|
21
|
+
export class InMemoryDeliveryState {
|
|
22
|
+
// prettier-ignore
|
|
23
|
+
/**
|
|
24
|
+
* Stores messages by stable identity.
|
|
25
|
+
*/
|
|
26
|
+
messages = new Map();
|
|
27
|
+
/**
|
|
28
|
+
* Stores sessions by stable shard identity.
|
|
29
|
+
*/
|
|
30
|
+
shards = new Map();
|
|
31
|
+
#messageBytes = new Map();
|
|
32
|
+
#messageShards = new Map();
|
|
33
|
+
#deliverableShards = new Map();
|
|
34
|
+
#limits;
|
|
35
|
+
#retainedBytes = 0;
|
|
36
|
+
/**
|
|
37
|
+
* Creates empty state.
|
|
38
|
+
*
|
|
39
|
+
* @param limits Configures retained-state limits.
|
|
40
|
+
*/
|
|
41
|
+
constructor(limits = {}) {
|
|
42
|
+
this.#limits = DeliveryLimits.resolve(limits);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Stores a validated batch atomically.
|
|
46
|
+
*
|
|
47
|
+
* @param messages Supplies encoded messages.
|
|
48
|
+
* @returns Lists newly inserted messages.
|
|
49
|
+
*/
|
|
50
|
+
putAll(messages) {
|
|
51
|
+
this.#ensureCapacity(messages);
|
|
52
|
+
const initial = new Set(this.messages.keys());
|
|
53
|
+
const inserted = [];
|
|
54
|
+
const seen = new Set();
|
|
55
|
+
const final = new Map();
|
|
56
|
+
for (const candidate of messages) {
|
|
57
|
+
const key = DeliveryMessages.key(candidate.message);
|
|
58
|
+
if (!initial.has(key) && !seen.has(key))
|
|
59
|
+
inserted.push(candidate.message);
|
|
60
|
+
seen.add(key);
|
|
61
|
+
final.set(key, candidate);
|
|
62
|
+
}
|
|
63
|
+
for (const [key, candidate] of final)
|
|
64
|
+
this.#replace(key, candidate.message, candidate.bytes);
|
|
65
|
+
return inserted;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Deletes a message.
|
|
69
|
+
*
|
|
70
|
+
* @param message Identifies the message.
|
|
71
|
+
* @returns Reports whether the message existed.
|
|
72
|
+
*/
|
|
73
|
+
delete(message) {
|
|
74
|
+
const key = DeliveryMessages.key(message);
|
|
75
|
+
const current = this.messages.get(key);
|
|
76
|
+
if (current === undefined)
|
|
77
|
+
return false;
|
|
78
|
+
this.messages.delete(key);
|
|
79
|
+
this.#retainedBytes -= this.#messageBytes.get(key) ?? 0;
|
|
80
|
+
this.#messageBytes.delete(key);
|
|
81
|
+
this.#decrementMessageShard(current);
|
|
82
|
+
this.#decrementDeliverableShard(current);
|
|
83
|
+
this.#pruneReleasedShard(DeliveryShards.key(this.#requiredShard(current)));
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Finds an active shard session.
|
|
88
|
+
*
|
|
89
|
+
* @param shard Identifies the shard.
|
|
90
|
+
* @returns Provides the session when active.
|
|
91
|
+
*/
|
|
92
|
+
session(shard) {
|
|
93
|
+
const record = this.shards.get(DeliveryShards.key(shard));
|
|
94
|
+
return record?.worker === undefined ? undefined : record;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Determines whether a shard has a retained `TO_DELIVER` message awaiting delivery.
|
|
98
|
+
*
|
|
99
|
+
* @param shard Identifies the shard to inspect.
|
|
100
|
+
* @returns Whether the shard has at least one retained `TO_DELIVER` message.
|
|
101
|
+
*/
|
|
102
|
+
hasPending(shard) {
|
|
103
|
+
return this.#deliverableShards.has(DeliveryShards.key(shard));
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Stores a shard pickup session.
|
|
107
|
+
*
|
|
108
|
+
* @param shard Identifies the shard.
|
|
109
|
+
* @param worker Identifies the worker.
|
|
110
|
+
* @param whenPicked Records the pickup time.
|
|
111
|
+
*/
|
|
112
|
+
setSession(shard, worker, whenPicked) {
|
|
113
|
+
this.#ensureShardCapacity(shard);
|
|
114
|
+
this.shards.set(DeliveryShards.key(shard), {
|
|
115
|
+
shard: DeliveryShards.copy(shard),
|
|
116
|
+
worker: DeliveryWorkers.copy(worker),
|
|
117
|
+
whenLastPicked: whenPicked,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Removes an active shard session.
|
|
122
|
+
*
|
|
123
|
+
* @param shard Identifies the shard.
|
|
124
|
+
* @returns Provides the former session when active.
|
|
125
|
+
*/
|
|
126
|
+
release(shard) {
|
|
127
|
+
const key = DeliveryShards.key(shard);
|
|
128
|
+
const record = this.shards.get(key);
|
|
129
|
+
if (record?.worker === undefined)
|
|
130
|
+
return undefined;
|
|
131
|
+
if (this.#messageShards.has(key))
|
|
132
|
+
this.shards.set(key, { ...record, worker: undefined });
|
|
133
|
+
else
|
|
134
|
+
this.shards.delete(key);
|
|
135
|
+
return record;
|
|
136
|
+
}
|
|
137
|
+
#ensureCapacity(candidates) {
|
|
138
|
+
const final = new Map();
|
|
139
|
+
for (const candidate of candidates)
|
|
140
|
+
final.set(DeliveryMessages.key(candidate.message), candidate);
|
|
141
|
+
let count = this.messages.size;
|
|
142
|
+
let bytes = this.#retainedBytes;
|
|
143
|
+
const tracked = new Set([...this.shards.keys(), ...this.#messageShards.keys()]);
|
|
144
|
+
for (const [key, candidate] of final) {
|
|
145
|
+
const prior = this.messages.get(key);
|
|
146
|
+
if (prior === undefined)
|
|
147
|
+
count++;
|
|
148
|
+
else
|
|
149
|
+
bytes -= this.#messageBytes.get(key) ?? 0;
|
|
150
|
+
bytes += candidate.bytes;
|
|
151
|
+
tracked.add(DeliveryShards.key(this.#requiredShard(candidate.message)));
|
|
152
|
+
}
|
|
153
|
+
if (count > this.#limits.maxRetainedMessages ||
|
|
154
|
+
bytes > this.#limits.maxRetainedBytes ||
|
|
155
|
+
tracked.size > this.#limits.maxTrackedShards) {
|
|
156
|
+
throw new ConnectError("Delivery retained-state capacity is full.", Code.ResourceExhausted);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
#replace(key, message, bytes) {
|
|
160
|
+
const prior = this.messages.get(key);
|
|
161
|
+
if (prior !== undefined) {
|
|
162
|
+
this.#retainedBytes -= this.#messageBytes.get(key) ?? 0;
|
|
163
|
+
this.#decrementMessageShard(prior);
|
|
164
|
+
this.#decrementDeliverableShard(prior);
|
|
165
|
+
}
|
|
166
|
+
this.messages.set(key, DeliveryMessages.copy(message));
|
|
167
|
+
this.#messageBytes.set(key, bytes);
|
|
168
|
+
this.#retainedBytes += bytes;
|
|
169
|
+
const shard = DeliveryShards.key(this.#requiredShard(message));
|
|
170
|
+
this.#messageShards.set(shard, (this.#messageShards.get(shard) ?? 0) + 1);
|
|
171
|
+
if (message.status === InboxMessageStatus.TO_DELIVER)
|
|
172
|
+
this.#deliverableShards.set(shard, (this.#deliverableShards.get(shard) ?? 0) + 1);
|
|
173
|
+
}
|
|
174
|
+
#decrementMessageShard(message) {
|
|
175
|
+
const key = DeliveryShards.key(this.#requiredShard(message));
|
|
176
|
+
const count = this.#messageShards.get(key);
|
|
177
|
+
if (count === undefined || count < 1)
|
|
178
|
+
throw new TypeError("Delivery message shard count is invalid.");
|
|
179
|
+
if (count === 1)
|
|
180
|
+
this.#messageShards.delete(key);
|
|
181
|
+
else
|
|
182
|
+
this.#messageShards.set(key, count - 1);
|
|
183
|
+
}
|
|
184
|
+
#decrementDeliverableShard(message) {
|
|
185
|
+
if (message.status !== InboxMessageStatus.TO_DELIVER)
|
|
186
|
+
return;
|
|
187
|
+
const key = DeliveryShards.key(this.#requiredShard(message));
|
|
188
|
+
const count = this.#deliverableShards.get(key);
|
|
189
|
+
if (count === undefined || count < 1)
|
|
190
|
+
throw new TypeError("Delivery deliverable shard count is invalid.");
|
|
191
|
+
if (count === 1)
|
|
192
|
+
this.#deliverableShards.delete(key);
|
|
193
|
+
else
|
|
194
|
+
this.#deliverableShards.set(key, count - 1);
|
|
195
|
+
}
|
|
196
|
+
#ensureShardCapacity(shard) {
|
|
197
|
+
const key = DeliveryShards.key(shard);
|
|
198
|
+
if (this.shards.has(key) || this.#messageShards.has(key))
|
|
199
|
+
return;
|
|
200
|
+
const tracked = new Set([...this.shards.keys(), ...this.#messageShards.keys()]);
|
|
201
|
+
if (tracked.size >= this.#limits.maxTrackedShards)
|
|
202
|
+
throw new ConnectError("Delivery tracked-shard capacity is full.", Code.ResourceExhausted);
|
|
203
|
+
}
|
|
204
|
+
#pruneReleasedShard(key) {
|
|
205
|
+
if (!this.#messageShards.has(key) && this.shards.get(key)?.worker === undefined)
|
|
206
|
+
this.shards.delete(key);
|
|
207
|
+
}
|
|
208
|
+
#requiredShard(message) {
|
|
209
|
+
if (message.id?.index === undefined)
|
|
210
|
+
throw new TypeError("Delivery message identity is missing.");
|
|
211
|
+
return message.id.index;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=in-memory-delivery-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory-delivery-state.js","sourceRoot":"","sources":["../../src/core/in-memory-delivery-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EACL,kBAAkB,GAInB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,cAAc,EAA4B,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAwBrF;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAChC,kBAAkB;IAElB;;OAEG;IACM,QAAQ,GAA8B,IAAI,GAAG,EAAwB,CAAC;IAE/E;;OAEG;IACM,MAAM,GAA6B,IAAI,GAAG,EAAuB,CAAC;IAClE,aAAa,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC1C,cAAc,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC3C,kBAAkB,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC/C,OAAO,CAAsB;IACtC,cAAc,GAAG,CAAC,CAAC;IAEnB;;;;OAIG;IACH,YA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CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ServiceImpl } from "@connectrpc/connect";
|
|
2
|
+
import { InboxService } from "@spine-event-engine/proto/delivery-server";
|
|
3
|
+
import { type ShardIndex } from "@spine-event-engine/proto/delivery";
|
|
4
|
+
import { InMemoryDeliveryState } from "./in-memory-delivery-state.js";
|
|
5
|
+
import { MutationAdmission } from "./mutation-admission.js";
|
|
6
|
+
/**
|
|
7
|
+
* Provides Inbox RPC handler implementations.
|
|
8
|
+
*/
|
|
9
|
+
export declare const InboxHandlers: Readonly<{
|
|
10
|
+
/**
|
|
11
|
+
* Creates Inbox RPC handlers.
|
|
12
|
+
*
|
|
13
|
+
* @param state Stores Inbox messages served by the handlers.
|
|
14
|
+
* @param admission Controls write admission and cancellation.
|
|
15
|
+
* @param onMessageTransition Observes retained-message count transitions.
|
|
16
|
+
* @returns The Inbox service implementation.
|
|
17
|
+
*/
|
|
18
|
+
create: (state: InMemoryDeliveryState, admission: MutationAdmission, onMessageTransition?: (shard: ShardIndex, delta: 1 | -1) => void) => ServiceImpl<typeof InboxService>;
|
|
19
|
+
}>;
|
|
20
|
+
//# sourceMappingURL=inbox-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inbox-service.d.ts","sourceRoot":"","sources":["../../src/core/inbox-service.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAsB,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAE3E,OAAO,EACL,YAAY,EAGb,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAKL,KAAK,UAAU,EAChB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAOtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAG5D;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC;IAGnC;;;;;;;OAOG;IACH,MAAM,EAAE,CACN,KAAK,EAAE,qBAAqB,EAC5B,SAAS,EAAE,iBAAiB,EAC5B,mBAAmB,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,KAC7D,WAAW,CAAC,OAAO,YAAY,CAAC,CAAC;CACvC,CAuGC,CAAC"}
|