@spine-event-engine/delivery-server 2.0.0-snapshot.31 → 2.0.0-snapshot.33

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.
Files changed (75) hide show
  1. package/README.md +63 -26
  2. package/REFERENCE.md +112 -53
  3. package/dist/admin/admin-service.d.ts +0 -7
  4. package/dist/admin/admin-service.d.ts.map +1 -1
  5. package/dist/admin/admin-service.js +231 -82
  6. package/dist/admin/admin-service.js.map +1 -1
  7. package/dist/core/in-memory-delivery-core.d.ts +19 -18
  8. package/dist/core/in-memory-delivery-core.d.ts.map +1 -1
  9. package/dist/core/in-memory-delivery-core.js +14 -14
  10. package/dist/core/in-memory-delivery-core.js.map +1 -1
  11. package/dist/core/in-memory-delivery-state.d.ts +61 -12
  12. package/dist/core/in-memory-delivery-state.d.ts.map +1 -1
  13. package/dist/core/in-memory-delivery-state.js +186 -100
  14. package/dist/core/in-memory-delivery-state.js.map +1 -1
  15. package/dist/core/inbox-service.d.ts +66 -3
  16. package/dist/core/inbox-service.d.ts.map +1 -1
  17. package/dist/core/inbox-service.js +84 -143
  18. package/dist/core/inbox-service.js.map +1 -1
  19. package/dist/core/mutation-admission.d.ts +3 -1
  20. package/dist/core/mutation-admission.d.ts.map +1 -1
  21. package/dist/core/mutation-admission.js +14 -3
  22. package/dist/core/mutation-admission.js.map +1 -1
  23. package/dist/core/shard-observing-service.d.ts +37 -0
  24. package/dist/core/shard-observing-service.d.ts.map +1 -0
  25. package/dist/core/shard-observing-service.js +267 -0
  26. package/dist/core/shard-observing-service.js.map +1 -0
  27. package/dist/core/shard-service.d.ts +29 -11
  28. package/dist/core/shard-service.d.ts.map +1 -1
  29. package/dist/core/shard-service.js +239 -154
  30. package/dist/core/shard-service.js.map +1 -1
  31. package/dist/core/wire-values.d.ts +10 -0
  32. package/dist/core/wire-values.d.ts.map +1 -1
  33. package/dist/core/wire-values.js +10 -0
  34. package/dist/core/wire-values.js.map +1 -1
  35. package/dist/health/health-service.d.ts.map +1 -1
  36. package/dist/health/health-service.js +1 -0
  37. package/dist/health/health-service.js.map +1 -1
  38. package/dist/server/assembly.d.ts +35 -2
  39. package/dist/server/assembly.d.ts.map +1 -1
  40. package/dist/server/assembly.js +62 -20
  41. package/dist/server/assembly.js.map +1 -1
  42. package/dist/server/config.d.ts +10 -3
  43. package/dist/server/config.d.ts.map +1 -1
  44. package/dist/server/config.js +22 -8
  45. package/dist/server/config.js.map +1 -1
  46. package/dist/server/delivery-child-pool.d.ts +83 -0
  47. package/dist/server/delivery-child-pool.d.ts.map +1 -0
  48. package/dist/server/delivery-child-pool.js +344 -0
  49. package/dist/server/delivery-child-pool.js.map +1 -0
  50. package/dist/server/delivery-parent-proxy.d.ts +45 -0
  51. package/dist/server/delivery-parent-proxy.d.ts.map +1 -0
  52. package/dist/server/delivery-parent-proxy.js +309 -0
  53. package/dist/server/delivery-parent-proxy.js.map +1 -0
  54. package/dist/server/delivery-server.d.ts +20 -20
  55. package/dist/server/delivery-server.d.ts.map +1 -1
  56. package/dist/server/delivery-server.js +59 -16
  57. package/dist/server/delivery-server.js.map +1 -1
  58. package/dist/server/delivery-stream-fan-in.d.ts +37 -0
  59. package/dist/server/delivery-stream-fan-in.d.ts.map +1 -0
  60. package/dist/server/delivery-stream-fan-in.js +334 -0
  61. package/dist/server/delivery-stream-fan-in.js.map +1 -0
  62. package/dist/server/private-delivery-child-process.d.ts +2 -0
  63. package/dist/server/private-delivery-child-process.d.ts.map +1 -0
  64. package/dist/server/private-delivery-child-process.js +71 -0
  65. package/dist/server/private-delivery-child-process.js.map +1 -0
  66. package/dist/server/private-delivery-child.d.ts +46 -0
  67. package/dist/server/private-delivery-child.d.ts.map +1 -0
  68. package/dist/server/private-delivery-child.js +145 -0
  69. package/dist/server/private-delivery-child.js.map +1 -0
  70. package/dist/tsconfig.tsbuildinfo +1 -1
  71. package/package.json +4 -3
  72. package/dist/core/limits.d.ts +0 -64
  73. package/dist/core/limits.d.ts.map +0 -1
  74. package/dist/core/limits.js +0 -73
  75. package/dist/core/limits.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"assembly.d.ts","sourceRoot":"","sources":["../../src/server/assembly.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,YAAY,EACb,MAAM,2CAA2C,CAAC;AAQnD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAG/B;;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;IAElD;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,OAAO,YAAY,CAAC,CAAC;IAEjD;;OAEG;IACH,cAAc,IAAI,IAAI,CAAC;IAEvB;;OAEG;IACH,UAAU,IAAI,IAAI,CAAC;CACpB;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC;IAGtC;;;;;OAKG;IACH,MAAM,EAAE,CACN,aAAa,CAAC,EAAE,IAAI,CAClB,qBAAqB,EACrB,qBAAqB,GAAG,qBAAqB,GAAG,kBAAkB,GAAG,kBAAkB,CACxF,KACE,gBAAgB,CAAC;CACvB,CAmCC,CAAC"}
1
+ {"version":3,"file":"assembly.d.ts","sourceRoot":"","sources":["../../src/server/assembly.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExD,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,qBAAqB,EACrB,YAAY,EACb,MAAM,2CAA2C,CAAC;AAGnD,OAAO,EAAE,qBA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  */
14
14
  import { Time } from "@spine-event-engine/core/time";
15
- import { AdminService, InboxService, ShardService, } from "@spine-event-engine/proto/delivery-server";
15
+ import { AdminService, InboxService, ShardObservingService, ShardService, } from "@spine-event-engine/proto/delivery-server";
16
16
  import { AdminPublisher } from "../admin/admin-service.js";
17
17
  import { InMemoryDeliveryState } from "../core/in-memory-delivery-state.js";
18
18
  import { InboxHandlers } from "../core/inbox-service.js";
19
19
  import { MutationAdmission } from "../core/mutation-admission.js";
20
- import { ShardHandlers } from "../core/shard-service.js";
21
- import { DEFAULT_DELIVERY_STATE_LIMITS } from "../core/limits.js";
20
+ import { ShardSessionRuntime } from "../core/shard-service.js";
21
+ import { ShardObserving } from "../core/shard-observing-service.js";
22
22
  /**
23
23
  * Provides assembly construction for the delivery RPC handlers.
24
24
  */
25
25
  export const DeliveryAssembly = Object.freeze({
26
- create: (configuration = {
27
- processingTimeoutMs: 0,
28
- ...DEFAULT_DELIVERY_STATE_LIMITS,
29
- }) => {
30
- const state = new InMemoryDeliveryState(configuration);
26
+ create: (configuration = DEFAULT_ASSEMBLY_CONFIGURATION) => {
27
+ const state = new InMemoryDeliveryState();
31
28
  const admission = new MutationAdmission();
32
29
  const admin = AdminPublisher.create(state);
30
+ const observing = ShardObserving.create(state, configuration.reminderIntervalMs ?? 10_000);
31
+ const sessions = DeliverySessionAssembly.create(state, admission, configuration, (shard) => {
32
+ admin.publish(shard);
33
+ observing.changed(shard);
34
+ });
35
+ return DeliveryAssemblyWiring.create(state, admission, admin, observing, sessions);
36
+ },
37
+ });
38
+ /**
39
+ * Connects the shared storage, session, observation, and close handlers.
40
+ */
41
+ const DeliveryAssemblyWiring = Object.freeze({
42
+ /**
43
+ * Builds the complete in-process service assembly.
44
+ *
45
+ * @param state Stores retained rows and sessions.
46
+ * @param admission Serializes local mutations.
47
+ * @param admin Publishes stored shard changes.
48
+ * @param observing Publishes available work.
49
+ * @param sessions Serves shard session calls.
50
+ * @returns The complete in-process service assembly.
51
+ */
52
+ create(state, admission, admin, observing, sessions) {
33
53
  return Object.freeze({
34
- inbox: InboxHandlers.create(state, admission, (shard, delta) => {
35
- admin.recordMessageTransition(shard, delta);
36
- }),
37
- shards: ShardHandlers.create(state, admission, () => Time.currentTimeMillis(), configuration.processingTimeoutMs, (shard) => {
38
- admin.publish(shard);
39
- }),
54
+ state,
55
+ inbox: InboxHandlers.create(state, admission, admin.publish.bind(admin), observing.changed.bind(observing)),
56
+ shards: sessions.service,
57
+ sessionRuntime: sessions,
40
58
  admin: admin.service,
41
- closeAdmission: () => {
42
- admission.close();
43
- },
44
- closeAdmin: () => {
45
- admin.close();
46
- },
59
+ observing: observing.service,
60
+ closeAdmission: admission.close.bind(admission),
61
+ closeAdmin: admin.close.bind(admin),
62
+ closeObserving: observing.close.bind(observing),
47
63
  });
48
64
  },
49
65
  });
66
+ /**
67
+ * Constructs session and inbox work handlers over one admission queue.
68
+ */
69
+ const DeliverySessionAssembly = Object.freeze({
70
+ /**
71
+ * Creates coupled session and inbox work handlers.
72
+ *
73
+ * @param state Stores canonical rows and sessions.
74
+ * @param admission Serializes mutations.
75
+ * @param configuration Supplies the session lifetime.
76
+ * @param onShardTransition Publishes session changes.
77
+ * @returns The shard session handler.
78
+ */
79
+ create(state, admission, configuration, onShardTransition) {
80
+ const now = configuration.now ?? (() => Time.currentTime());
81
+ const sessions = new ShardSessionRuntime(state, admission, now, configuration.processingTimeoutMs ?? 0, onShardTransition);
82
+ return sessions;
83
+ },
84
+ });
85
+ /**
86
+ * Default settings for listener-free assembly tests and callers.
87
+ */
88
+ const DEFAULT_ASSEMBLY_CONFIGURATION = Object.freeze({
89
+ processingTimeoutMs: 0,
90
+ reminderIntervalMs: 10_000,
91
+ });
50
92
  //# sourceMappingURL=assembly.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"assembly.js","sourceRoot":"","sources":["../../src/server/assembly.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,+B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GAAG,GAAG,aAAa,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;QAC5D,MAAM,QAAQ,GAAG,IAAI,mBAAmB,CACtC,KAAK,EACL,SAAS,EACT,GAAG,EACH,aAAa,CAAC,mBAAmB,IAAI,CAAC,EACtC,iBAAiB,CAClB,CAAC;QACF,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC,CAAC;AAmBH;;GAEG;AACH,MAAM,8BAA8B,GAAkC,MAAM,CAAC,MAAM,CAAC;IAClF,mBAAmB,EAAE,CAAC;IACtB,kBAAkB,EAAE,MAAM;CAC3B,CAAC,CAAC"}
@@ -1,9 +1,8 @@
1
- import { type DeliveryStateLimits } from "../core/limits.js";
2
1
  import type { DeliveryServerOptions } from "./delivery-server.js";
3
2
  /**
4
- * Describes the resolved delivery listener and retained-state configuration.
3
+ * Describes the resolved delivery listener and session configuration.
5
4
  */
6
- export interface DeliveryConfiguration extends DeliveryStateLimits {
5
+ export interface DeliveryConfiguration {
7
6
  /**
8
7
  * Holds the validated listener host.
9
8
  */
@@ -16,10 +15,18 @@ export interface DeliveryConfiguration extends DeliveryStateLimits {
16
15
  * Holds the maximum inbound RPC message size in bytes.
17
16
  */
18
17
  readonly maxInboundMessageBytes: number;
18
+ /**
19
+ * Holds the maximum outbound RPC message size in bytes.
20
+ */
21
+ readonly maxOutboundMessageBytes: number;
19
22
  /**
20
23
  * Holds the automatic Shard processing timeout in milliseconds.
21
24
  */
22
25
  readonly processingTimeoutMs: number;
26
+ /**
27
+ * Interval between notices while work remains free and pending.
28
+ */
29
+ readonly reminderIntervalMs: number;
23
30
  }
24
31
  /**
25
32
  * Provides delivery listener configuration resolution.
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/server/config.ts"],"names":[],"mappings":"AAcA,OAAO,EAML,KAAK,mBAAmB,EACzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAA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B,EAAE,MAAM,CAAC;IAEzC;;OAEG;IACH,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IAErC;;OAEG;IACH,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;CACrC;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC;IAGpC;;;;;OAKG;IACH,OAAO,EAAE,CAAC,OAAO,CAAC,EAAE,qBAAqB,KAAK,qBAAqB,CAAC;IAEpE;;;;;;;;;;OAUG;IACH,MAAM,EAAE,CACN,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,KACT,MAAM,CAAC;IAEZ;;;;;;;OAOG;IACH,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CAC1F,CA0DC,CAAC"}
@@ -11,7 +11,10 @@
11
11
  * or implied. See the License for the specific language governing permissions and limitations under
12
12
  * the License.
13
13
  */
14
- import { DEFAULT_DELIVERY_STATE_LIMITS, MAX_DELIVERY_LIMIT, MAX_DELIVERY_RESPONSE_SHARDS, MAX_DELIVERY_RPC_BYTES, DeliveryLimits, } from "../core/limits.js";
14
+ /**
15
+ * Maximum message length in protobuf's 32-bit framing and Connect 2.1.2.
16
+ */
17
+ const PROTOBUF_FRAME_MAX_BYTES = 0xffff_ffff;
15
18
  /**
16
19
  * Provides delivery listener configuration resolution.
17
20
  */
@@ -23,13 +26,10 @@ export const DeliveryConfig = Object.freeze({
23
26
  return Object.freeze({
24
27
  host,
25
28
  port: DeliveryConfig.number(options.port, "PORT", 8484, 0, 65_535, "port"),
26
- maxInboundMessageBytes: DeliveryConfig.number(options.maxInboundMessageBytes, "MAX_INBOUND_MESSAGE_SIZE", MAX_DELIVERY_RPC_BYTES, 1, MAX_DELIVERY_LIMIT, "inbound message size"),
27
- processingTimeoutMs: DeliveryConfig.number(options.processingTimeoutSeconds, "SHARD_PROCESSING_TIMEOUT", 0, 0, MAX_DELIVERY_LIMIT, "processing timeout") * 1_000,
28
- ...DeliveryLimits.resolve({
29
- maxRetainedMessages: DeliveryConfig.number(options.maxRetainedMessages, "MAX_RETAINED_MESSAGES", DEFAULT_DELIVERY_STATE_LIMITS.maxRetainedMessages, 1, MAX_DELIVERY_LIMIT, "retained message limit"),
30
- maxRetainedBytes: DeliveryConfig.number(options.maxRetainedBytes, "MAX_RETAINED_BYTES", DEFAULT_DELIVERY_STATE_LIMITS.maxRetainedBytes, 1, MAX_DELIVERY_LIMIT, "retained byte limit"),
31
- maxTrackedShards: DeliveryConfig.number(options.maxTrackedShards, "MAX_TRACKED_SHARDS", DEFAULT_DELIVERY_STATE_LIMITS.maxTrackedShards, 1, MAX_DELIVERY_RESPONSE_SHARDS, "tracked shard limit"),
32
- }),
29
+ maxInboundMessageBytes: DeliveryConfig.number(options.maxInboundMessageBytes, "MAX_INBOUND_MESSAGE_SIZE", PROTOBUF_FRAME_MAX_BYTES, 1, PROTOBUF_FRAME_MAX_BYTES, "inbound message size"),
30
+ maxOutboundMessageBytes: DeliveryConfig.number(options.maxOutboundMessageBytes, "MAX_OUTBOUND_MESSAGE_SIZE", PROTOBUF_FRAME_MAX_BYTES, 1, PROTOBUF_FRAME_MAX_BYTES, "outbound message size"),
31
+ processingTimeoutMs: DeliveryConfig.number(options.processingTimeoutSeconds, "SHARD_PROCESSING_TIMEOUT", 0, 0, 315_576_000_000, "processing timeout") * 1_000,
32
+ reminderIntervalMs: DeliveryConfigSupport.reminderInterval(options),
33
33
  });
34
34
  },
35
35
  number: (explicit, environment, fallback, minimum, maximum, name) => {
@@ -49,4 +49,18 @@ export const DeliveryConfig = Object.freeze({
49
49
  return number;
50
50
  },
51
51
  });
52
+ /**
53
+ * Resolves supporting delivery server configuration values.
54
+ */
55
+ const DeliveryConfigSupport = Object.freeze({
56
+ /**
57
+ * Resolves the work-reminder interval without a feature-specific cap.
58
+ *
59
+ * @param options Supplies the explicit seconds override.
60
+ * @returns The positive interval in safe integer milliseconds.
61
+ */
62
+ reminderInterval(options) {
63
+ return (DeliveryConfig.number(options.workReminderSeconds, "WORK_REMINDER_SECONDS", 10, 1, Math.floor(Number.MAX_SAFE_INTEGER / 1_000), "work reminder interval") * 1_000);
64
+ },
65
+ });
52
66
  //# sourceMappingURL=config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/server/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,6BAA6B,EAC7B,kBAAkB,EAClB,4BAA4B,EAC5B,sBAAsB,EACtB,cAAc,GAEf,MAAM,mBAAmB,CAAC;AA8B3B;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAwCtB,MAAM,CAAC,MAAM,CAAC;IACjB,OAAO,EAAE,CAAC,UAAiC,EAAE,EAAyB,EAAE;QACtE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,WAAW,CAAC;QAC7D,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;YACtD,MAAM,IAAI,UAAU,CAAC,kCAAkC,CAAC,CAAC;QAC3D,OAAO,MAAM,CAAC,MAAM,CAAC;YACnB,IAAI;YACJ,IAAI,EAAE,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC;YAC1E,sBAAsB,EAAE,cAAc,CAAC,MAAM,CAC3C,OAAO,CAAC,sBAAsB,EAC9B,0BAA0B,EAC1B,sBAAsB,EACtB,CAAC,EACD,kBAAkB,EAClB,sBAAsB,CACvB;YACD,mBAAmB,EACj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F,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC1C;;;;;OAKG;IACH,gBAAgB,CAAC,OAA8B;QAC7C,OAAO,CACL,cAAc,CAAC,MAAM,CACnB,OAAO,CAAC,mBAAmB,EAC3B,uBAAuB,EACvB,EAAE,EACF,CAAC,EACD,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,gBAAgB,GAAG,KAAK,CAAC,EAC3C,wBAAwB,CACzB,GAAG,KAAK,CACV,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,83 @@
1
+ import { type ChildProcess, type ForkOptions } from "node:child_process";
2
+ import type { DeliveryConfiguration } from "./config.js";
3
+ /**
4
+ * Identifies one ready private child process and its authenticated endpoint.
5
+ */
6
+ export interface DeliveryChildEndpoint {
7
+ /**
8
+ * Identifies the fixed route slot.
9
+ */
10
+ readonly slot: number;
11
+ /**
12
+ * Distinguishes this process from replacements.
13
+ */
14
+ readonly generation: string;
15
+ /**
16
+ * Authenticates parent calls on this private child listener.
17
+ */
18
+ readonly credential: string;
19
+ /**
20
+ * Identifies the private loopback gRPC listener.
21
+ */
22
+ readonly baseUrl: string;
23
+ /**
24
+ * Identifies the live Node child process.
25
+ */
26
+ readonly pid: number;
27
+ }
28
+ /**
29
+ * Starts a child with the same arguments as the production Node fork.
30
+ */
31
+ type ChildFork = (entry: string, args: readonly string[], options: ForkOptions) => ChildProcess;
32
+ /**
33
+ * Keeps a fixed set of volatile child slots alive.
34
+ */
35
+ export declare class DeliveryChildPool {
36
+ #private;
37
+ readonly processCount: number;
38
+ readonly configuration: DeliveryConfiguration;
39
+ private readonly forkChild;
40
+ /**
41
+ * Creates a fixed number of child slots without binding or forking.
42
+ *
43
+ * @param processCount Selects the explicit positive child count.
44
+ * @param configuration Supplies each child's local retained-state and session settings.
45
+ * @param forkChild Starts child processes through Node's fork operation.
46
+ */
47
+ constructor(processCount: number, configuration: DeliveryConfiguration, forkChild?: ChildFork);
48
+ /**
49
+ * Starts one child in every fixed slot.
50
+ *
51
+ * @returns Completion after each initial child starts or reports failure.
52
+ */
53
+ start(): Promise<void>;
54
+ /**
55
+ * Reads a ready child endpoint without waiting for a recovering slot.
56
+ *
57
+ * @param slot Identifies the fixed route slot.
58
+ * @returns The live child endpoint and process generation.
59
+ */
60
+ endpoint(slot: number): DeliveryChildEndpoint;
61
+ /**
62
+ * Checks that an asynchronous response still came from the live generation.
63
+ *
64
+ * @param endpoint Identifies the child that started the request.
65
+ * @returns Whether the same process remains ready.
66
+ */
67
+ current(endpoint: DeliveryChildEndpoint): boolean;
68
+ /**
69
+ * Registers child readiness, replacement, and terminal closure notifications.
70
+ *
71
+ * @param onChange Receives the changed fixed slot.
72
+ * @returns A function that detaches the listener.
73
+ */
74
+ onChange(onChange: (slot: number) => void): () => void;
75
+ /**
76
+ * Stops restarts and asks every child to close.
77
+ *
78
+ * @returns Completion after all children exit.
79
+ */
80
+ close(): Promise<void>;
81
+ }
82
+ export {};
83
+ //# sourceMappingURL=delivery-child-pool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delivery-child-pool.d.ts","sourceRoot":"","sources":["../../src/server/delivery-child-pool.ts"],"names":[],"mappings":"AAeA,OAAO,EAAQ,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAO/E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGzD;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AA0CD;;GAEG;AACH,KAAK,SAAS,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,WAAW,KAAK,YAAY,CAAC;AAEhG;;GAEG;AACH,qBAAa,iBAAiB;;IAuB1B,QAAQ,CAAC,YAAY,EAAE,MAAM;IAC7B,QAAQ,CAAC,aAAa,EAAE,qBAAqB;IAC7C,OAAO,CAAC,QAAQ,CAAC,SAAS;IAV5B;;;;;;OAMG;gBAEQ,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,qBAAqB,EAC5B,SAAS,GAAE,SAAgB;IAM9C;;;;OAIG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAOtB;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,qBAAqB;IAa7C;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,EAAE,qBAAqB,GAAG,OAAO;IAKjD;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI;IAOtD;;;;OAIG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAgPvB"}
@@ -0,0 +1,344 @@
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 { randomUUID } from "node:crypto";
16
+ import { fork } from "node:child_process";
17
+ import { existsSync } from "node:fs";
18
+ import { fileURLToPath } from "node:url";
19
+ import { Code, ConnectError } from "@connectrpc/connect";
20
+ import { Time } from "@spine-event-engine/core/time";
21
+ /**
22
+ * Keeps a fixed set of volatile child slots alive.
23
+ */
24
+ export class DeliveryChildPool {
25
+ processCount;
26
+ configuration;
27
+ forkChild;
28
+ #slots = new Map();
29
+ #children = new Set();
30
+ #restartTimers = new Map();
31
+ #retryDelay = new Map();
32
+ #changes = new Set();
33
+ #start;
34
+ #close;
35
+ /**
36
+ * Creates a fixed number of child slots without binding or forking.
37
+ *
38
+ * @param processCount Selects the explicit positive child count.
39
+ * @param configuration Supplies each child's local retained-state and session settings.
40
+ * @param forkChild Starts child processes through Node's fork operation.
41
+ */
42
+ constructor(processCount, configuration, forkChild = fork) {
43
+ this.processCount = processCount;
44
+ this.configuration = configuration;
45
+ this.forkChild = forkChild;
46
+ if (!Number.isSafeInteger(processCount) || processCount < 1)
47
+ throw new RangeError("Delivery child process count is invalid.");
48
+ }
49
+ /**
50
+ * Starts one child in every fixed slot.
51
+ *
52
+ * @returns Completion after each initial child starts or reports failure.
53
+ */
54
+ start() {
55
+ if (this.#close !== undefined)
56
+ return Promise.reject(new Error("Delivery child pool is closed."));
57
+ this.#start ??= this.#startOnce();
58
+ return this.#start;
59
+ }
60
+ /**
61
+ * Reads a ready child endpoint without waiting for a recovering slot.
62
+ *
63
+ * @param slot Identifies the fixed route slot.
64
+ * @returns The live child endpoint and process generation.
65
+ */
66
+ endpoint(slot) {
67
+ const current = this.#slots.get(slot);
68
+ if (current?.baseUrl === undefined || current.process.pid === undefined)
69
+ throw new ConnectError("Delivery child slot is unavailable.", Code.Unavailable);
70
+ return {
71
+ slot,
72
+ generation: current.generation,
73
+ credential: current.credential,
74
+ baseUrl: current.baseUrl,
75
+ pid: current.process.pid,
76
+ };
77
+ }
78
+ /**
79
+ * Checks that an asynchronous response still came from the live generation.
80
+ *
81
+ * @param endpoint Identifies the child that started the request.
82
+ * @returns Whether the same process remains ready.
83
+ */
84
+ current(endpoint) {
85
+ const slot = this.#slots.get(endpoint.slot);
86
+ return slot?.generation === endpoint.generation && slot.baseUrl !== undefined;
87
+ }
88
+ /**
89
+ * Registers child readiness, replacement, and terminal closure notifications.
90
+ *
91
+ * @param onChange Receives the changed fixed slot.
92
+ * @returns A function that detaches the listener.
93
+ */
94
+ onChange(onChange) {
95
+ this.#changes.add(onChange);
96
+ return () => {
97
+ this.#changes.delete(onChange);
98
+ };
99
+ }
100
+ /**
101
+ * Stops restarts and asks every child to close.
102
+ *
103
+ * @returns Completion after all children exit.
104
+ */
105
+ close() {
106
+ this.#close ??= this.#closeOnce();
107
+ return this.#close;
108
+ }
109
+ /**
110
+ * Launches every child slot.
111
+ */
112
+ async #startOnce() {
113
+ await Promise.all(Array.from({ length: this.processCount }, (_, slot) => this.#spawn(slot)));
114
+ }
115
+ /**
116
+ * Launches one new generation and retries a failed fork in the same slot.
117
+ *
118
+ * @param slot Identifies the fixed route slot.
119
+ */
120
+ async #spawn(slot) {
121
+ if (this.#close !== undefined)
122
+ return;
123
+ const current = this.#fork(slot);
124
+ if (current === undefined)
125
+ return;
126
+ this.#slots.set(slot, current);
127
+ await this.#awaitReady(current, {
128
+ credential: current.credential,
129
+ configuration: this.configuration,
130
+ });
131
+ }
132
+ /**
133
+ * Creates one private credential and a Node fork for a slot.
134
+ *
135
+ * @param slot Identifies the fixed route slot.
136
+ * @returns The launched process, or undefined after a failed fork.
137
+ */
138
+ #fork(slot) {
139
+ const generation = randomUUID();
140
+ const credential = `Bearer ${randomUUID()}`;
141
+ let child;
142
+ try {
143
+ child = this.forkChild(_a.#entry(), [], {
144
+ stdio: ["ignore", "ignore", "ignore", "ipc"],
145
+ execArgv: _a.#childExecArgv(process.execArgv),
146
+ });
147
+ }
148
+ catch {
149
+ this.#scheduleFailedStart(slot, 1);
150
+ return undefined;
151
+ }
152
+ this.#children.add(child);
153
+ child.once("exit", () => {
154
+ this.#children.delete(child);
155
+ });
156
+ return {
157
+ slot,
158
+ generation,
159
+ credential,
160
+ process: child,
161
+ started: Time.monotonicTime(),
162
+ ready: false,
163
+ baseUrl: undefined,
164
+ };
165
+ }
166
+ /**
167
+ * Removes flags that describe the parent's stdin or evaluation entry point.
168
+ *
169
+ * @param args Supplies the parent Node execution flags.
170
+ * @returns Compatible flags, including instrumentation, for a file-backed child.
171
+ */
172
+ static #childExecArgv(args) {
173
+ const compatible = [];
174
+ for (let index = 0; index < args.length; index++) {
175
+ const arg = args[index];
176
+ if (arg === undefined)
177
+ continue;
178
+ if (["--input-type", "--eval", "--print", "-e", "-p"].includes(arg)) {
179
+ index++;
180
+ continue;
181
+ }
182
+ if (arg.startsWith("--input-type=") ||
183
+ arg.startsWith("--eval=") ||
184
+ arg.startsWith("--print=") ||
185
+ /^-[ep].+/.test(arg) ||
186
+ ["--check", "-c", "--interactive", "-i", "--test"].includes(arg))
187
+ continue;
188
+ compatible.push(arg);
189
+ }
190
+ return compatible;
191
+ }
192
+ /**
193
+ * Waits for one fork's ready, failed, or exit lifecycle event.
194
+ */
195
+ #awaitReady(current, options) {
196
+ const child = current.process;
197
+ return new Promise((resolve) => {
198
+ const message = (value) => {
199
+ if (value.kind === "ready" && typeof value.baseUrl === "string") {
200
+ current.baseUrl = value.baseUrl;
201
+ current.ready = true;
202
+ for (const listener of this.#changes)
203
+ listener(current.slot);
204
+ child.off("message", message);
205
+ this.#retryDelay.delete(current.slot);
206
+ resolve();
207
+ }
208
+ else if (value.kind === "failed") {
209
+ child.off("message", message);
210
+ this.#retire(current);
211
+ resolve();
212
+ }
213
+ };
214
+ child.on("message", message);
215
+ child.once("exit", () => {
216
+ child.off("message", message);
217
+ this.#retire(current);
218
+ resolve();
219
+ });
220
+ child.once("error", () => {
221
+ child.off("message", message);
222
+ this.#retire(current);
223
+ resolve();
224
+ });
225
+ this.#sendStart(current, options, resolve);
226
+ });
227
+ }
228
+ /**
229
+ * Retires a fork when its IPC startup message cannot be delivered.
230
+ */
231
+ #sendStart(current, options, onFailure) {
232
+ try {
233
+ current.process.send({ kind: "start", options }, (error) => {
234
+ if (error !== null) {
235
+ this.#retire(current);
236
+ onFailure();
237
+ }
238
+ });
239
+ }
240
+ catch {
241
+ this.#retire(current);
242
+ onFailure();
243
+ }
244
+ }
245
+ /**
246
+ * Invalidates a departed generation.
247
+ *
248
+ * @param current Identifies the process whose exit was observed.
249
+ */
250
+ #retire(current) {
251
+ if (this.#slots.get(current.slot) !== current)
252
+ return;
253
+ this.#slots.delete(current.slot);
254
+ if (current.process.pid === undefined)
255
+ this.#children.delete(current.process);
256
+ for (const listener of this.#changes)
257
+ listener(current.slot);
258
+ if (this.#close !== undefined)
259
+ return;
260
+ if (current.ready) {
261
+ this.#retryDelay.delete(current.slot);
262
+ this.#scheduleRestart(current.slot, 0);
263
+ }
264
+ else {
265
+ this.#scheduleFailedStart(current.slot, Math.max(1, Math.ceil(Time.monotonicTime() - current.started)));
266
+ }
267
+ }
268
+ /**
269
+ * Paces repeated startup failures using their observed duration.
270
+ *
271
+ * @param slot Identifies the failed fixed slot.
272
+ * @param observed Measures this failed attempt in milliseconds.
273
+ */
274
+ #scheduleFailedStart(slot, observed) {
275
+ const previous = this.#retryDelay.get(slot) ?? 0;
276
+ const delay = previous === 0 ? observed : Math.min(previous * 2, Number.MAX_SAFE_INTEGER);
277
+ this.#retryDelay.set(slot, delay);
278
+ this.#scheduleRestart(slot, delay);
279
+ }
280
+ /**
281
+ * Waits for the full adaptive restart delay using representable Node timers.
282
+ */
283
+ #scheduleRestart(slot, remaining) {
284
+ if (this.#close !== undefined)
285
+ return;
286
+ const slice = Math.min(remaining, 2_147_483_647);
287
+ const timer = setTimeout(() => {
288
+ this.#restartTimers.delete(slot);
289
+ if (remaining > slice)
290
+ this.#scheduleRestart(slot, remaining - slice);
291
+ else
292
+ void this.#spawn(slot);
293
+ }, slice);
294
+ this.#restartTimers.set(slot, timer);
295
+ }
296
+ /**
297
+ * Stops replacement and waits for every reached child to close.
298
+ */
299
+ async #closeOnce() {
300
+ for (let slot = 0; slot < this.processCount; slot++)
301
+ for (const listener of this.#changes)
302
+ listener(slot);
303
+ for (const timer of this.#restartTimers.values())
304
+ clearTimeout(timer);
305
+ this.#restartTimers.clear();
306
+ await Promise.all([...this.#children].map((child) => this.#stopChild(child)));
307
+ await this.#start?.catch(() => undefined);
308
+ }
309
+ /**
310
+ * Waits for each reached fork, including a retired child that reported startup failure.
311
+ */
312
+ #stopChild(child) {
313
+ return new Promise((resolve) => {
314
+ if (child.exitCode !== null || child.signalCode !== null || child.pid === undefined) {
315
+ resolve();
316
+ return;
317
+ }
318
+ child.once("exit", () => {
319
+ resolve();
320
+ });
321
+ const ready = [...this.#slots.values()].some((slot) => slot.process === child);
322
+ if (!ready || !child.connected)
323
+ child.kill("SIGTERM");
324
+ else
325
+ child.send({ kind: "close" }, (error) => {
326
+ if (error !== null)
327
+ child.kill("SIGTERM");
328
+ });
329
+ });
330
+ }
331
+ /**
332
+ * Finds the compiled child entry for source and built-package test runs.
333
+ *
334
+ * @returns The Node child entry path.
335
+ */
336
+ static #entry() {
337
+ const adjacent = fileURLToPath(new URL("./private-delivery-child-process.js", import.meta.url));
338
+ if (existsSync(adjacent))
339
+ return adjacent;
340
+ return fileURLToPath(new URL("../../dist/server/private-delivery-child-process.js", import.meta.url));
341
+ }
342
+ }
343
+ _a = DeliveryChildPool;
344
+ //# sourceMappingURL=delivery-child-pool.js.map