@spine-event-engine/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 +569 -0
- package/REFERENCE.md +488 -0
- package/dist/bus/command-bus.d.ts +61 -0
- package/dist/bus/command-bus.d.ts.map +1 -0
- package/dist/bus/command-bus.js +201 -0
- package/dist/bus/command-bus.js.map +1 -0
- package/dist/bus/command-dispatcher-registry.d.ts +33 -0
- package/dist/bus/command-dispatcher-registry.d.ts.map +1 -0
- package/dist/bus/command-dispatcher-registry.js +75 -0
- package/dist/bus/command-dispatcher-registry.js.map +1 -0
- package/dist/bus/command-dispatcher.d.ts +25 -0
- package/dist/bus/command-dispatcher.d.ts.map +1 -0
- package/dist/bus/command-dispatcher.js +15 -0
- package/dist/bus/command-dispatcher.js.map +1 -0
- package/dist/bus/command-errors.d.ts +23 -0
- package/dist/bus/command-errors.d.ts.map +1 -0
- package/dist/bus/command-errors.js +52 -0
- package/dist/bus/command-errors.js.map +1 -0
- package/dist/bus/event-bus.d.ts +113 -0
- package/dist/bus/event-bus.d.ts.map +1 -0
- package/dist/bus/event-bus.js +518 -0
- package/dist/bus/event-bus.js.map +1 -0
- package/dist/bus/event-dispatcher-origin-schemas.d.ts +17 -0
- package/dist/bus/event-dispatcher-origin-schemas.d.ts.map +1 -0
- package/dist/bus/event-dispatcher-origin-schemas.js +32 -0
- package/dist/bus/event-dispatcher-origin-schemas.js.map +1 -0
- package/dist/bus/event-dispatcher-registry.d.ts +48 -0
- package/dist/bus/event-dispatcher-registry.d.ts.map +1 -0
- package/dist/bus/event-dispatcher-registry.js +176 -0
- package/dist/bus/event-dispatcher-registry.js.map +1 -0
- package/dist/bus/event-dispatcher.d.ts +48 -0
- package/dist/bus/event-dispatcher.d.ts.map +1 -0
- package/dist/bus/event-dispatcher.js +15 -0
- package/dist/bus/event-dispatcher.js.map +1 -0
- package/dist/context/bounded-context.d.ts +606 -0
- package/dist/context/bounded-context.d.ts.map +1 -0
- package/dist/context/bounded-context.js +1780 -0
- package/dist/context/bounded-context.js.map +1 -0
- package/dist/context/entity-inbox.d.ts +63 -0
- package/dist/context/entity-inbox.d.ts.map +1 -0
- package/dist/context/entity-inbox.js +380 -0
- package/dist/context/entity-inbox.js.map +1 -0
- package/dist/context/local-inbox-handoff.d.ts +244 -0
- package/dist/context/local-inbox-handoff.d.ts.map +1 -0
- package/dist/context/local-inbox-handoff.js +334 -0
- package/dist/context/local-inbox-handoff.js.map +1 -0
- package/dist/context/projection-handoff.d.ts +46 -0
- package/dist/context/projection-handoff.d.ts.map +1 -0
- package/dist/context/projection-handoff.js +172 -0
- package/dist/context/projection-handoff.js.map +1 -0
- package/dist/context/tenant-index.d.ts +41 -0
- package/dist/context/tenant-index.d.ts.map +1 -0
- package/dist/context/tenant-index.js +92 -0
- package/dist/context/tenant-index.js.map +1 -0
- package/dist/delivery/conditional-pickup.d.ts +25 -0
- package/dist/delivery/conditional-pickup.d.ts.map +1 -0
- package/dist/delivery/conditional-pickup.js +26 -0
- package/dist/delivery/conditional-pickup.js.map +1 -0
- package/dist/delivery/delivery-builder.d.ts +216 -0
- package/dist/delivery/delivery-builder.d.ts.map +1 -0
- package/dist/delivery/delivery-builder.js +323 -0
- package/dist/delivery/delivery-builder.js.map +1 -0
- package/dist/delivery/delivery-lease.d.ts +15 -0
- package/dist/delivery/delivery-lease.d.ts.map +1 -0
- package/dist/delivery/delivery-lease.js +44 -0
- package/dist/delivery/delivery-lease.js.map +1 -0
- package/dist/delivery/delivery-loop.d.ts +113 -0
- package/dist/delivery/delivery-loop.d.ts.map +1 -0
- package/dist/delivery/delivery-loop.js +119 -0
- package/dist/delivery/delivery-loop.js.map +1 -0
- package/dist/delivery/delivery-monitor.d.ts +165 -0
- package/dist/delivery/delivery-monitor.d.ts.map +1 -0
- package/dist/delivery/delivery-monitor.js +168 -0
- package/dist/delivery/delivery-monitor.js.map +1 -0
- package/dist/delivery/delivery-ports.d.ts +141 -0
- package/dist/delivery/delivery-ports.d.ts.map +1 -0
- package/dist/delivery/delivery-ports.js +15 -0
- package/dist/delivery/delivery-ports.js.map +1 -0
- package/dist/delivery/delivery-run-control.d.ts +50 -0
- package/dist/delivery/delivery-run-control.d.ts.map +1 -0
- package/dist/delivery/delivery-run-control.js +66 -0
- package/dist/delivery/delivery-run-control.js.map +1 -0
- package/dist/delivery/delivery-run-coordinator.d.ts +218 -0
- package/dist/delivery/delivery-run-coordinator.d.ts.map +1 -0
- package/dist/delivery/delivery-run-coordinator.js +609 -0
- package/dist/delivery/delivery-run-coordinator.js.map +1 -0
- package/dist/delivery/delivery-storage-error.d.ts +13 -0
- package/dist/delivery/delivery-storage-error.d.ts.map +1 -0
- package/dist/delivery/delivery-storage-error.js +30 -0
- package/dist/delivery/delivery-storage-error.js.map +1 -0
- package/dist/delivery/delivery-supervisor.d.ts +175 -0
- package/dist/delivery/delivery-supervisor.d.ts.map +1 -0
- package/dist/delivery/delivery-supervisor.js +469 -0
- package/dist/delivery/delivery-supervisor.js.map +1 -0
- package/dist/delivery/delivery-worker.d.ts +180 -0
- package/dist/delivery/delivery-worker.d.ts.map +1 -0
- package/dist/delivery/delivery-worker.js +232 -0
- package/dist/delivery/delivery-worker.js.map +1 -0
- package/dist/delivery/delivery.d.ts +238 -0
- package/dist/delivery/delivery.d.ts.map +1 -0
- package/dist/delivery/delivery.js +400 -0
- package/dist/delivery/delivery.js.map +1 -0
- package/dist/delivery/inbox-records.d.ts +19 -0
- package/dist/delivery/inbox-records.d.ts.map +1 -0
- package/dist/delivery/inbox-records.js +291 -0
- package/dist/delivery/inbox-records.js.map +1 -0
- package/dist/delivery/inbox-storage.d.ts +81 -0
- package/dist/delivery/inbox-storage.d.ts.map +1 -0
- package/dist/delivery/inbox-storage.js +353 -0
- package/dist/delivery/inbox-storage.js.map +1 -0
- package/dist/delivery/inbox.d.ts +263 -0
- package/dist/delivery/inbox.d.ts.map +1 -0
- package/dist/delivery/inbox.js +172 -0
- package/dist/delivery/inbox.js.map +1 -0
- package/dist/delivery/parked-delivery-obligations.d.ts +182 -0
- package/dist/delivery/parked-delivery-obligations.d.ts.map +1 -0
- package/dist/delivery/parked-delivery-obligations.js +390 -0
- package/dist/delivery/parked-delivery-obligations.js.map +1 -0
- package/dist/delivery/shard-index.d.ts +41 -0
- package/dist/delivery/shard-index.d.ts.map +1 -0
- package/dist/delivery/shard-index.js +67 -0
- package/dist/delivery/shard-index.js.map +1 -0
- package/dist/delivery/sharded-work-registry.d.ts +114 -0
- package/dist/delivery/sharded-work-registry.d.ts.map +1 -0
- package/dist/delivery/sharded-work-registry.js +360 -0
- package/dist/delivery/sharded-work-registry.js.map +1 -0
- package/dist/entity/entity-metadata.d.ts +173 -0
- package/dist/entity/entity-metadata.d.ts.map +1 -0
- package/dist/entity/entity-metadata.js +187 -0
- package/dist/entity/entity-metadata.js.map +1 -0
- package/dist/entity/entity-storage-descriptor.d.ts +64 -0
- package/dist/entity/entity-storage-descriptor.d.ts.map +1 -0
- package/dist/entity/entity-storage-descriptor.js +227 -0
- package/dist/entity/entity-storage-descriptor.js.map +1 -0
- package/dist/entity/entity-transaction.d.ts +372 -0
- package/dist/entity/entity-transaction.d.ts.map +1 -0
- package/dist/entity/entity-transaction.js +413 -0
- package/dist/entity/entity-transaction.js.map +1 -0
- package/dist/entity/entity-transition-validation.d.ts +47 -0
- package/dist/entity/entity-transition-validation.d.ts.map +1 -0
- package/dist/entity/entity-transition-validation.js +327 -0
- package/dist/entity/entity-transition-validation.js.map +1 -0
- package/dist/entity/entity.d.ts +499 -0
- package/dist/entity/entity.d.ts.map +1 -0
- package/dist/entity/entity.js +829 -0
- package/dist/entity/entity.js.map +1 -0
- package/dist/entity/implicit-required-id.d.ts +15 -0
- package/dist/entity/implicit-required-id.d.ts.map +1 -0
- package/dist/entity/implicit-required-id.js +123 -0
- package/dist/entity/implicit-required-id.js.map +1 -0
- package/dist/entity/spec-scanner.d.ts +14 -0
- package/dist/entity/spec-scanner.d.ts.map +1 -0
- package/dist/entity/spec-scanner.js +37 -0
- package/dist/entity/spec-scanner.js.map +1 -0
- package/dist/handler/build-time-handler-analyzer.d.ts +150 -0
- package/dist/handler/build-time-handler-analyzer.d.ts.map +1 -0
- package/dist/handler/build-time-handler-analyzer.js +1101 -0
- package/dist/handler/build-time-handler-analyzer.js.map +1 -0
- package/dist/handler/command-registration-readiness.d.ts +99 -0
- package/dist/handler/command-registration-readiness.d.ts.map +1 -0
- package/dist/handler/command-registration-readiness.js +118 -0
- package/dist/handler/command-registration-readiness.js.map +1 -0
- package/dist/handler/event-handler-filter.d.ts +43 -0
- package/dist/handler/event-handler-filter.d.ts.map +1 -0
- package/dist/handler/event-handler-filter.js +128 -0
- package/dist/handler/event-handler-filter.js.map +1 -0
- package/dist/handler/event-registration-readiness.d.ts +196 -0
- package/dist/handler/event-registration-readiness.d.ts.map +1 -0
- package/dist/handler/event-registration-readiness.js +187 -0
- package/dist/handler/event-registration-readiness.js.map +1 -0
- package/dist/handler/external.d.ts +10 -0
- package/dist/handler/external.d.ts.map +1 -0
- package/dist/handler/external.js +15 -0
- package/dist/handler/external.js.map +1 -0
- package/dist/handler/generated-handler-registry.d.ts +154 -0
- package/dist/handler/generated-handler-registry.d.ts.map +1 -0
- package/dist/handler/generated-handler-registry.js +223 -0
- package/dist/handler/generated-handler-registry.js.map +1 -0
- package/dist/handler/generated-registry-discovery.d.ts +94 -0
- package/dist/handler/generated-registry-discovery.d.ts.map +1 -0
- package/dist/handler/generated-registry-discovery.js +228 -0
- package/dist/handler/generated-registry-discovery.js.map +1 -0
- package/dist/handler/generated-registry-writer.d.ts +58 -0
- package/dist/handler/generated-registry-writer.d.ts.map +1 -0
- package/dist/handler/generated-registry-writer.js +458 -0
- package/dist/handler/generated-registry-writer.js.map +1 -0
- package/dist/handler/handler-codegen.d.ts +48 -0
- package/dist/handler/handler-codegen.d.ts.map +1 -0
- package/dist/handler/handler-codegen.js +214 -0
- package/dist/handler/handler-codegen.js.map +1 -0
- package/dist/handler/handler-decorators.d.ts +134 -0
- package/dist/handler/handler-decorators.d.ts.map +1 -0
- package/dist/handler/handler-decorators.js +239 -0
- package/dist/handler/handler-decorators.js.map +1 -0
- package/dist/handler/handler-metadata.d.ts +510 -0
- package/dist/handler/handler-metadata.d.ts.map +1 -0
- package/dist/handler/handler-metadata.js +391 -0
- package/dist/handler/handler-metadata.js.map +1 -0
- package/dist/handler/registration-readiness-metadata.d.ts +68 -0
- package/dist/handler/registration-readiness-metadata.d.ts.map +1 -0
- package/dist/handler/registration-readiness-metadata.js +170 -0
- package/dist/handler/registration-readiness-metadata.js.map +1 -0
- package/dist/handler/rejection-source.d.ts +11 -0
- package/dist/handler/rejection-source.d.ts.map +1 -0
- package/dist/handler/rejection-source.js +25 -0
- package/dist/handler/rejection-source.js.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/dist/integration/external-messages.d.ts +49 -0
- package/dist/integration/external-messages.d.ts.map +1 -0
- package/dist/integration/external-messages.js +112 -0
- package/dist/integration/external-messages.js.map +1 -0
- package/dist/integration/integration-broker.d.ts +74 -0
- package/dist/integration/integration-broker.d.ts.map +1 -0
- package/dist/integration/integration-broker.js +444 -0
- package/dist/integration/integration-broker.js.map +1 -0
- package/dist/integration/third-party-context.d.ts +56 -0
- package/dist/integration/third-party-context.d.ts.map +1 -0
- package/dist/integration/third-party-context.js +130 -0
- package/dist/integration/third-party-context.js.map +1 -0
- package/dist/repository/command-errors.d.ts +25 -0
- package/dist/repository/command-errors.d.ts.map +1 -0
- package/dist/repository/command-errors.js +43 -0
- package/dist/repository/command-errors.js.map +1 -0
- package/dist/repository/command-routing.d.ts +72 -0
- package/dist/repository/command-routing.d.ts.map +1 -0
- package/dist/repository/command-routing.js +98 -0
- package/dist/repository/command-routing.js.map +1 -0
- package/dist/repository/commit-fence.d.ts +22 -0
- package/dist/repository/commit-fence.d.ts.map +1 -0
- package/dist/repository/commit-fence.js +37 -0
- package/dist/repository/commit-fence.js.map +1 -0
- package/dist/repository/event-routing.d.ts +71 -0
- package/dist/repository/event-routing.d.ts.map +1 -0
- package/dist/repository/event-routing.js +96 -0
- package/dist/repository/event-routing.js.map +1 -0
- package/dist/repository/primitive-id.d.ts +86 -0
- package/dist/repository/primitive-id.d.ts.map +1 -0
- package/dist/repository/primitive-id.js +110 -0
- package/dist/repository/primitive-id.js.map +1 -0
- package/dist/repository/repository.d.ts +670 -0
- package/dist/repository/repository.d.ts.map +1 -0
- package/dist/repository/repository.js +3298 -0
- package/dist/repository/repository.js.map +1 -0
- package/dist/repository/routing-declarations.d.ts +75 -0
- package/dist/repository/routing-declarations.d.ts.map +1 -0
- package/dist/repository/routing-declarations.js +101 -0
- package/dist/repository/routing-declarations.js.map +1 -0
- package/dist/repository/state-update-routing.d.ts +66 -0
- package/dist/repository/state-update-routing.d.ts.map +1 -0
- package/dist/repository/state-update-routing.js +91 -0
- package/dist/repository/state-update-routing.js.map +1 -0
- package/dist/runtime/runtime.d.ts +156 -0
- package/dist/runtime/runtime.d.ts.map +1 -0
- package/dist/runtime/runtime.js +215 -0
- package/dist/runtime/runtime.js.map +1 -0
- package/dist/runtime/signal-intake.d.ts +84 -0
- package/dist/runtime/signal-intake.d.ts.map +1 -0
- package/dist/runtime/signal-intake.js +94 -0
- package/dist/runtime/signal-intake.js.map +1 -0
- package/dist/runtime/signal-metadata.d.ts +242 -0
- package/dist/runtime/signal-metadata.d.ts.map +1 -0
- package/dist/runtime/signal-metadata.js +368 -0
- package/dist/runtime/signal-metadata.js.map +1 -0
- package/dist/server/browser-server.d.ts +49 -0
- package/dist/server/browser-server.d.ts.map +1 -0
- package/dist/server/browser-server.js +633 -0
- package/dist/server/browser-server.js.map +1 -0
- package/dist/server/durable-subscription-bindings.d.ts +122 -0
- package/dist/server/durable-subscription-bindings.d.ts.map +1 -0
- package/dist/server/durable-subscription-bindings.js +524 -0
- package/dist/server/durable-subscription-bindings.js.map +1 -0
- package/dist/server/environment-attachment.d.ts +356 -0
- package/dist/server/environment-attachment.d.ts.map +1 -0
- package/dist/server/environment-attachment.js +2061 -0
- package/dist/server/environment-attachment.js.map +1 -0
- package/dist/server/environment-delivery-records.d.ts +77 -0
- package/dist/server/environment-delivery-records.d.ts.map +1 -0
- package/dist/server/environment-delivery-records.js +282 -0
- package/dist/server/environment-delivery-records.js.map +1 -0
- package/dist/server/environment-delivery-worker.d.ts +161 -0
- package/dist/server/environment-delivery-worker.d.ts.map +1 -0
- package/dist/server/environment-delivery-worker.js +664 -0
- package/dist/server/environment-delivery-worker.js.map +1 -0
- package/dist/server/environment.d.ts +43 -0
- package/dist/server/environment.d.ts.map +1 -0
- package/dist/server/environment.js +90 -0
- package/dist/server/environment.js.map +1 -0
- package/dist/server/managed-child-subscription.d.ts +11 -0
- package/dist/server/managed-child-subscription.d.ts.map +1 -0
- package/dist/server/managed-child-subscription.js +44 -0
- package/dist/server/managed-child-subscription.js.map +1 -0
- package/dist/server/managed-server-application.d.ts +324 -0
- package/dist/server/managed-server-application.d.ts.map +1 -0
- package/dist/server/managed-server-application.js +937 -0
- package/dist/server/managed-server-application.js.map +1 -0
- package/dist/server/node-coordinator.d.ts +191 -0
- package/dist/server/node-coordinator.d.ts.map +1 -0
- package/dist/server/node-coordinator.js +552 -0
- package/dist/server/node-coordinator.js.map +1 -0
- package/dist/server/process-server-coordinator.d.ts +15 -0
- package/dist/server/process-server-coordinator.d.ts.map +1 -0
- package/dist/server/process-server-coordinator.js +112 -0
- package/dist/server/process-server-coordinator.js.map +1 -0
- package/dist/server/reserved-spine-rpc-paths.json +8 -0
- package/dist/server/retryable-close.d.ts +28 -0
- package/dist/server/retryable-close.d.ts.map +1 -0
- package/dist/server/retryable-close.js +129 -0
- package/dist/server/retryable-close.js.map +1 -0
- package/dist/server/server-environment.d.ts +180 -0
- package/dist/server/server-environment.d.ts.map +1 -0
- package/dist/server/server-environment.js +418 -0
- package/dist/server/server-environment.js.map +1 -0
- package/dist/server/server-log.d.ts +18 -0
- package/dist/server/server-log.d.ts.map +1 -0
- package/dist/server/server-log.js +96 -0
- package/dist/server/server-log.js.map +1 -0
- package/dist/server/server.d.ts +389 -0
- package/dist/server/server.d.ts.map +1 -0
- package/dist/server/server.js +752 -0
- package/dist/server/server.js.map +1 -0
- package/dist/services/spine-services.d.ts +88 -0
- package/dist/services/spine-services.d.ts.map +1 -0
- package/dist/services/spine-services.js +1586 -0
- package/dist/services/spine-services.js.map +1 -0
- package/dist/stand/stand.d.ts +294 -0
- package/dist/stand/stand.d.ts.map +1 -0
- package/dist/stand/stand.js +680 -0
- package/dist/stand/stand.js.map +1 -0
- package/dist/stand/subscription-observer.d.ts +53 -0
- package/dist/stand/subscription-observer.d.ts.map +1 -0
- package/dist/stand/subscription-observer.js +444 -0
- package/dist/stand/subscription-observer.js.map +1 -0
- package/dist/stand/subscription-records.d.ts +12 -0
- package/dist/stand/subscription-records.d.ts.map +1 -0
- package/dist/stand/subscription-records.js +99 -0
- package/dist/stand/subscription-records.js.map +1 -0
- package/dist/stand/subscription-registry.d.ts +285 -0
- package/dist/stand/subscription-registry.d.ts.map +1 -0
- package/dist/stand/subscription-registry.js +403 -0
- package/dist/stand/subscription-registry.js.map +1 -0
- package/dist/stand/subscription-runtime.d.ts +102 -0
- package/dist/stand/subscription-runtime.d.ts.map +1 -0
- package/dist/stand/subscription-runtime.js +380 -0
- package/dist/stand/subscription-runtime.js.map +1 -0
- package/dist/testing/index.d.ts +14 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +34 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +65 -0
|
@@ -0,0 +1,91 @@
|
|
|
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 {} from "@spine-event-engine/core";
|
|
15
|
+
import { RoutingDeclarations, } from "./routing-declarations.js";
|
|
16
|
+
const states = new WeakMap();
|
|
17
|
+
/**
|
|
18
|
+
* Mutable Entity-state route declarations snapshotted by repository construction.
|
|
19
|
+
*/
|
|
20
|
+
export class StateUpdateRouting {
|
|
21
|
+
constructor() {
|
|
22
|
+
states.set(this, RoutingDeclarations.create());
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Creates empty Entity-state route declarations.
|
|
26
|
+
*
|
|
27
|
+
* @returns Mutable declarations for one repository.
|
|
28
|
+
*/
|
|
29
|
+
static create() {
|
|
30
|
+
return new StateUpdateRouting();
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Registers an exact generated Entity-state schema route or a nominal message-interface route.
|
|
34
|
+
*
|
|
35
|
+
* A schema route receives its exact state shape. An interface route receives
|
|
36
|
+
* {@link InterfaceRouteMessage}, the member-state union intersected with the
|
|
37
|
+
* declared interface. Routing selects an exact schema route first, then the
|
|
38
|
+
* first matching interface token in registration order, then the
|
|
39
|
+
* replacement/default route.
|
|
40
|
+
*
|
|
41
|
+
* Copied or malformed tokens fail during declaration. Every token member must
|
|
42
|
+
* be registered by the repository, or construction fails. The selected route
|
|
43
|
+
* runs once for an accepted admission; durable replay uses stored targets and
|
|
44
|
+
* does not run routing again.
|
|
45
|
+
*
|
|
46
|
+
* @param schemaOrToken Generated Entity-state schema or nominal message-interface token.
|
|
47
|
+
* @param via Route function to invoke.
|
|
48
|
+
* @returns These mutable declarations.
|
|
49
|
+
*/
|
|
50
|
+
route(schemaOrToken, via) {
|
|
51
|
+
if (typeof via !== "function")
|
|
52
|
+
throw new TypeError("State-update routing requires a route function.");
|
|
53
|
+
const state = StateUpdateRoutingInternals.state(this);
|
|
54
|
+
if (RoutingDeclarations.isInterfaceTokenCandidate(schemaOrToken)) {
|
|
55
|
+
RoutingDeclarations.routeInterface(state, schemaOrToken, via, "State-update routing");
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
RoutingDeclarations.exact(state, schemaOrToken, via, "State-update routing has a duplicate exact state-update route.");
|
|
59
|
+
}
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Replaces the first-compatible-field default state route.
|
|
64
|
+
*
|
|
65
|
+
* @param via Replacement route function.
|
|
66
|
+
* @returns These mutable declarations.
|
|
67
|
+
*/
|
|
68
|
+
replaceDefault(via) {
|
|
69
|
+
if (typeof via !== "function")
|
|
70
|
+
throw new TypeError("State-update routing requires a route function.");
|
|
71
|
+
RoutingDeclarations.default(StateUpdateRoutingInternals.state(this), via);
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Internal access to state-routing declaration state.
|
|
77
|
+
*
|
|
78
|
+
* @internal Repository construction support.
|
|
79
|
+
*/
|
|
80
|
+
export const StateUpdateRoutingInternals = Object.freeze({
|
|
81
|
+
state(routing) {
|
|
82
|
+
return states.get(routing);
|
|
83
|
+
},
|
|
84
|
+
snapshot(routing) {
|
|
85
|
+
if (routing === undefined) {
|
|
86
|
+
return RoutingDeclarations.snapshot(RoutingDeclarations.create());
|
|
87
|
+
}
|
|
88
|
+
return RoutingDeclarations.snapshot(StateUpdateRoutingInternals.state(routing));
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
//# sourceMappingURL=state-update-routing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-update-routing.js","sourceRo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C;CACF;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAKnC,MAAM,CAAC,MAAM,CAAC;IACjB,KAAK,CAAK,OAA+B;QACvC,OAAO,MAAM,CAAC,GAAG,CAAC,OAAO,CAAc,CAAC;IAC1C,CAAC;IACD,QAAQ,CACN,OAA2C;QAE3C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO,mBAAmB,CAAC,QAAQ,CAAC,mBAAmB,CAAC,MAAM,EAAwB,CAAC,CAAC;QAC1F,CAAC;QACD,OAAO,mBAAmB,CAAC,QAAQ,CAAC,2BAA2B,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IAClF,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic lifecycle states for the single-process server runtime kernel.
|
|
3
|
+
*
|
|
4
|
+
* Transitions are:
|
|
5
|
+
*
|
|
6
|
+
* - `created -> running` when `start()` is accepted;
|
|
7
|
+
* - `created -> closed` when `close()` happens before start;
|
|
8
|
+
* - `running -> closing -> closed` when close drains already accepted work;
|
|
9
|
+
* - `closing -> closed` once accepted work settles.
|
|
10
|
+
*
|
|
11
|
+
* `running -> running` through repeated `start()` and `closing|closed -> closed`
|
|
12
|
+
* through repeated `close()` are idempotent no-ops. Starting after close is
|
|
13
|
+
* rejected.
|
|
14
|
+
*/
|
|
15
|
+
export type ServerRuntimeState = "created" | "running" | "closing" | "closed";
|
|
16
|
+
/**
|
|
17
|
+
* Explicit lifecycle contract for server-owned runtime parts.
|
|
18
|
+
*/
|
|
19
|
+
export interface ServerRuntimeLifecycle {
|
|
20
|
+
/**
|
|
21
|
+
* Current deterministic lifecycle state.
|
|
22
|
+
*/
|
|
23
|
+
readonly state: ServerRuntimeState;
|
|
24
|
+
/**
|
|
25
|
+
* Starts accepting runtime work.
|
|
26
|
+
*
|
|
27
|
+
* Calling `start()` on an already running runtime is a no-op. Calling it while
|
|
28
|
+
* closing or after close rejects with `ServerRuntimeStateError`.
|
|
29
|
+
*
|
|
30
|
+
* @returns A promise that resolves after runtime work admission starts.
|
|
31
|
+
*/
|
|
32
|
+
start(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Stops accepting new work and waits for already accepted work to settle.
|
|
35
|
+
*
|
|
36
|
+
* Closing is idempotent. The first close call owns the transition to
|
|
37
|
+
* `closed`; later calls return the same close outcome. Calling `close()` from
|
|
38
|
+
* active runtime work rejects with `ServerRuntimeStateError` and state
|
|
39
|
+
* `"running-work"`.
|
|
40
|
+
*
|
|
41
|
+
* @returns A promise that settles after accepted runtime work drains and closes.
|
|
42
|
+
*/
|
|
43
|
+
close(): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Executes one trusted runtime work item accepted by the single-process queue.
|
|
47
|
+
*
|
|
48
|
+
* The queue provides no timeout, cancellation, fairness, queue bound, or
|
|
49
|
+
* hostile-callback protection; non-settling work can keep `close()` pending.
|
|
50
|
+
* Same-runtime enqueue during active work is rejected to avoid self-deadlock.
|
|
51
|
+
* This is the first server intake boundary, not a durable job, transport
|
|
52
|
+
* message, command, event, dispatch outcome, or repository operation.
|
|
53
|
+
*
|
|
54
|
+
* @returns nothing or a promise fulfilled after the work completes.
|
|
55
|
+
*/
|
|
56
|
+
export type ServerRuntimeWork = () => void | Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Operation rejected by the runtime lifecycle state machine.
|
|
59
|
+
*/
|
|
60
|
+
export type ServerRuntimeStateOperation = "start" | "enqueue" | "close";
|
|
61
|
+
/**
|
|
62
|
+
* Runtime condition that rejected a lifecycle operation.
|
|
63
|
+
*/
|
|
64
|
+
export type ServerRuntimeRejectedState = ServerRuntimeState | "running-work";
|
|
65
|
+
/**
|
|
66
|
+
* Stable machine-readable code for runtime lifecycle state failures.
|
|
67
|
+
*/
|
|
68
|
+
export type RuntimeStateErrorCode = "INVALID_RUNTIME_STATE";
|
|
69
|
+
/**
|
|
70
|
+
* Error raised when a lifecycle operation is not valid in the current state.
|
|
71
|
+
*/
|
|
72
|
+
export declare class ServerRuntimeStateError extends Error {
|
|
73
|
+
/**
|
|
74
|
+
* Stable taxonomy for invalid runtime lifecycle operations.
|
|
75
|
+
*/
|
|
76
|
+
readonly code: RuntimeStateErrorCode;
|
|
77
|
+
/**
|
|
78
|
+
* Operation that was rejected.
|
|
79
|
+
*/
|
|
80
|
+
readonly operation: ServerRuntimeStateOperation;
|
|
81
|
+
/**
|
|
82
|
+
* State that rejected the operation.
|
|
83
|
+
*/
|
|
84
|
+
readonly state: ServerRuntimeRejectedState;
|
|
85
|
+
/**
|
|
86
|
+
* Creates an error for a rejected runtime operation.
|
|
87
|
+
*
|
|
88
|
+
* @param operation the rejected operation.
|
|
89
|
+
* @param state the state that rejected it.
|
|
90
|
+
*/
|
|
91
|
+
constructor(operation: ServerRuntimeStateOperation, state: ServerRuntimeRejectedState);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Small server-owned single-process async runtime queue.
|
|
95
|
+
*
|
|
96
|
+
* The runtime has no global singleton and performs no import-time
|
|
97
|
+
* registration. `enqueue()` is an intake boundary: accepted work runs in a
|
|
98
|
+
* later microtask and is processed in FIFO order. Closing prevents new intake
|
|
99
|
+
* and waits for previously accepted work to settle. Enqueued callbacks must be
|
|
100
|
+
* trusted server-owned work; this kernel intentionally does not add timeout,
|
|
101
|
+
* cancellation, fairness, queue bounds, or hostile-callback isolation.
|
|
102
|
+
* Same-runtime reentrant enqueue during active work is rejected to avoid queue
|
|
103
|
+
* self-deadlocks.
|
|
104
|
+
*/
|
|
105
|
+
export declare class SingleProcessServerRuntime implements ServerRuntimeLifecycle {
|
|
106
|
+
#private;
|
|
107
|
+
/**
|
|
108
|
+
* Creates an idle single-process runtime.
|
|
109
|
+
*
|
|
110
|
+
*/
|
|
111
|
+
constructor();
|
|
112
|
+
/**
|
|
113
|
+
* Returns the current lifecycle state.
|
|
114
|
+
*
|
|
115
|
+
* @returns the lifecycle state.
|
|
116
|
+
*/
|
|
117
|
+
get state(): ServerRuntimeState;
|
|
118
|
+
/**
|
|
119
|
+
* Starts accepting runtime work.
|
|
120
|
+
*
|
|
121
|
+
* @returns A promise that resolves after runtime work admission starts.
|
|
122
|
+
*/
|
|
123
|
+
start(): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Accepts one unit of server runtime work for later single-process execution.
|
|
126
|
+
*
|
|
127
|
+
* The returned promise represents this work item's completion. A rejected
|
|
128
|
+
* work item rejects only its own promise and does not stop later queued work.
|
|
129
|
+
* Work callbacks are trusted server-owned callbacks only. There is no
|
|
130
|
+
* timeout, cancellation, fairness, queue bound, or protection from hostile or
|
|
131
|
+
* non-settling work; such work can keep `close()` pending. Same-runtime
|
|
132
|
+
* reentrant enqueue during active work is rejected to avoid queue self-deadlocks.
|
|
133
|
+
*
|
|
134
|
+
* @param work the trusted work to enqueue.
|
|
135
|
+
* @returns A promise that settles after the queued work completes.
|
|
136
|
+
*/
|
|
137
|
+
enqueue(work: ServerRuntimeWork): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Closes the runtime after accepted work drains.
|
|
140
|
+
*
|
|
141
|
+
* @returns A promise that settles after the runtime closes.
|
|
142
|
+
*/
|
|
143
|
+
close(): Promise<void>;
|
|
144
|
+
}
|
|
145
|
+
interface RuntimeAccess {
|
|
146
|
+
enqueueFollowUp(runtime: SingleProcessServerRuntime, work: ServerRuntimeWork): Promise<void>;
|
|
147
|
+
drain(runtime: SingleProcessServerRuntime): Promise<void>;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Provides package-owned authority for framework follow-up work.
|
|
151
|
+
*
|
|
152
|
+
* @internal
|
|
153
|
+
*/
|
|
154
|
+
export declare const runtimeAccess: RuntimeAccess;
|
|
155
|
+
export {};
|
|
156
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts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,OAAO,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IA+B/C;;;;OAIG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAsCvB;AAED,UAAU,aAAa;IACrB,eAAe,CAAC,OAAO,EAAE,0BAA0B,EAAE,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7F,KAAK,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3D;AAQD;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,aAoB1B,CAAC"}
|
|
@@ -0,0 +1,215 @@
|
|
|
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 { AsyncLocalStorage } from "node:async_hooks";
|
|
15
|
+
/**
|
|
16
|
+
* Error raised when a lifecycle operation is not valid in the current state.
|
|
17
|
+
*/
|
|
18
|
+
export class ServerRuntimeStateError extends Error {
|
|
19
|
+
// prettier-ignore
|
|
20
|
+
/**
|
|
21
|
+
* Stable taxonomy for invalid runtime lifecycle operations.
|
|
22
|
+
*/
|
|
23
|
+
code = "INVALID_RUNTIME_STATE";
|
|
24
|
+
/**
|
|
25
|
+
* Operation that was rejected.
|
|
26
|
+
*/
|
|
27
|
+
operation;
|
|
28
|
+
/**
|
|
29
|
+
* State that rejected the operation.
|
|
30
|
+
*/
|
|
31
|
+
state;
|
|
32
|
+
/**
|
|
33
|
+
* Creates an error for a rejected runtime operation.
|
|
34
|
+
*
|
|
35
|
+
* @param operation the rejected operation.
|
|
36
|
+
* @param state the state that rejected it.
|
|
37
|
+
*/
|
|
38
|
+
constructor(operation, state) {
|
|
39
|
+
super(RuntimeValues.formatStateError(operation, state));
|
|
40
|
+
this.name = "ServerRuntimeStateError";
|
|
41
|
+
this.operation = operation;
|
|
42
|
+
this.state = state;
|
|
43
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Small server-owned single-process async runtime queue.
|
|
48
|
+
*
|
|
49
|
+
* The runtime has no global singleton and performs no import-time
|
|
50
|
+
* registration. `enqueue()` is an intake boundary: accepted work runs in a
|
|
51
|
+
* later microtask and is processed in FIFO order. Closing prevents new intake
|
|
52
|
+
* and waits for previously accepted work to settle. Enqueued callbacks must be
|
|
53
|
+
* trusted server-owned work; this kernel intentionally does not add timeout,
|
|
54
|
+
* cancellation, fairness, queue bounds, or hostile-callback isolation.
|
|
55
|
+
* Same-runtime reentrant enqueue during active work is rejected to avoid queue
|
|
56
|
+
* self-deadlocks.
|
|
57
|
+
*/
|
|
58
|
+
export class SingleProcessServerRuntime {
|
|
59
|
+
#state = "created";
|
|
60
|
+
#tail = Promise.resolve();
|
|
61
|
+
#closePromise;
|
|
62
|
+
/**
|
|
63
|
+
* Creates an idle single-process runtime.
|
|
64
|
+
*
|
|
65
|
+
*/
|
|
66
|
+
constructor() {
|
|
67
|
+
followUpEnqueuers.set(this, (work) => this.#enqueueFollowUp(work));
|
|
68
|
+
runtimeDrainers.set(this, () => this.#drain());
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Returns the current lifecycle state.
|
|
72
|
+
*
|
|
73
|
+
* @returns the lifecycle state.
|
|
74
|
+
*/
|
|
75
|
+
get state() {
|
|
76
|
+
return this.#state;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Starts accepting runtime work.
|
|
80
|
+
*
|
|
81
|
+
* @returns A promise that resolves after runtime work admission starts.
|
|
82
|
+
*/
|
|
83
|
+
start() {
|
|
84
|
+
if (this.#state === "running") {
|
|
85
|
+
return Promise.resolve();
|
|
86
|
+
}
|
|
87
|
+
if (this.#state === "closing" || this.#state === "closed") {
|
|
88
|
+
return Promise.reject(new ServerRuntimeStateError("start", this.#state));
|
|
89
|
+
}
|
|
90
|
+
this.#state = "running";
|
|
91
|
+
return Promise.resolve();
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Accepts one unit of server runtime work for later single-process execution.
|
|
95
|
+
*
|
|
96
|
+
* The returned promise represents this work item's completion. A rejected
|
|
97
|
+
* work item rejects only its own promise and does not stop later queued work.
|
|
98
|
+
* Work callbacks are trusted server-owned callbacks only. There is no
|
|
99
|
+
* timeout, cancellation, fairness, queue bound, or protection from hostile or
|
|
100
|
+
* non-settling work; such work can keep `close()` pending. Same-runtime
|
|
101
|
+
* reentrant enqueue during active work is rejected to avoid queue self-deadlocks.
|
|
102
|
+
*
|
|
103
|
+
* @param work the trusted work to enqueue.
|
|
104
|
+
* @returns A promise that settles after the queued work completes.
|
|
105
|
+
*/
|
|
106
|
+
enqueue(work) {
|
|
107
|
+
return this.#enqueue(work, false);
|
|
108
|
+
}
|
|
109
|
+
#enqueueFollowUp(work) {
|
|
110
|
+
return this.#enqueue(work, true);
|
|
111
|
+
}
|
|
112
|
+
#enqueue(work, allowRunningWork) {
|
|
113
|
+
const runningWork = RuntimeValues.isRunningWork(this);
|
|
114
|
+
const acceptsDrainFollowUp = allowRunningWork && runningWork && this.#state === "closing";
|
|
115
|
+
if (this.#state !== "running" && !acceptsDrainFollowUp) {
|
|
116
|
+
throw new ServerRuntimeStateError("enqueue", this.#state);
|
|
117
|
+
}
|
|
118
|
+
if (!allowRunningWork && runningWork) {
|
|
119
|
+
throw new ServerRuntimeStateError("enqueue", "running-work");
|
|
120
|
+
}
|
|
121
|
+
const completion = this.#tail.then(async () => {
|
|
122
|
+
const frame = { runtime: this, active: true };
|
|
123
|
+
try {
|
|
124
|
+
await runtimeWork.run(frame, work);
|
|
125
|
+
}
|
|
126
|
+
finally {
|
|
127
|
+
frame.active = false;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
this.#tail = completion.catch(() => undefined);
|
|
131
|
+
return completion;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Closes the runtime after accepted work drains.
|
|
135
|
+
*
|
|
136
|
+
* @returns A promise that settles after the runtime closes.
|
|
137
|
+
*/
|
|
138
|
+
close() {
|
|
139
|
+
if (RuntimeValues.isRunningWork(this)) {
|
|
140
|
+
return Promise.reject(new ServerRuntimeStateError("close", "running-work"));
|
|
141
|
+
}
|
|
142
|
+
if (this.#closePromise !== undefined) {
|
|
143
|
+
return this.#closePromise;
|
|
144
|
+
}
|
|
145
|
+
if (this.#state === "closed") {
|
|
146
|
+
this.#closePromise = Promise.resolve();
|
|
147
|
+
return this.#closePromise;
|
|
148
|
+
}
|
|
149
|
+
if (this.#state === "created") {
|
|
150
|
+
this.#state = "closed";
|
|
151
|
+
this.#closePromise = Promise.resolve();
|
|
152
|
+
return this.#closePromise;
|
|
153
|
+
}
|
|
154
|
+
this.#state = "closing";
|
|
155
|
+
this.#closePromise = this.#drainAndClose();
|
|
156
|
+
return this.#closePromise;
|
|
157
|
+
}
|
|
158
|
+
async #drainAndClose() {
|
|
159
|
+
await this.#drain();
|
|
160
|
+
this.#state = "closed";
|
|
161
|
+
}
|
|
162
|
+
async #drain() {
|
|
163
|
+
let observedTail;
|
|
164
|
+
do {
|
|
165
|
+
observedTail = this.#tail;
|
|
166
|
+
await observedTail;
|
|
167
|
+
} while (this.#tail !== observedTail);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const followUpEnqueuers = new WeakMap();
|
|
171
|
+
const runtimeDrainers = new WeakMap();
|
|
172
|
+
/**
|
|
173
|
+
* Provides package-owned authority for framework follow-up work.
|
|
174
|
+
*
|
|
175
|
+
* @internal
|
|
176
|
+
*/
|
|
177
|
+
export const runtimeAccess = Object.freeze({
|
|
178
|
+
enqueueFollowUp(runtime, work) {
|
|
179
|
+
const enqueueFollowUp = followUpEnqueuers.get(runtime);
|
|
180
|
+
if (enqueueFollowUp === undefined) {
|
|
181
|
+
throw new TypeError("Runtime follow-up work requires a SingleProcessServerRuntime instance.");
|
|
182
|
+
}
|
|
183
|
+
return enqueueFollowUp(work);
|
|
184
|
+
},
|
|
185
|
+
drain(runtime) {
|
|
186
|
+
const drain = runtimeDrainers.get(runtime);
|
|
187
|
+
if (drain === undefined) {
|
|
188
|
+
throw new TypeError("Runtime drain requires a SingleProcessServerRuntime instance.");
|
|
189
|
+
}
|
|
190
|
+
return drain();
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
const runtimeWork = new AsyncLocalStorage();
|
|
194
|
+
/**
|
|
195
|
+
* Private runtime state and execution helpers.
|
|
196
|
+
*/
|
|
197
|
+
const RuntimeValues = Object.freeze({
|
|
198
|
+
formatStateError(operation, state) {
|
|
199
|
+
if (operation === "start") {
|
|
200
|
+
return `Cannot start server runtime while it is ${state}.`;
|
|
201
|
+
}
|
|
202
|
+
if (state === "running-work" && operation === "close") {
|
|
203
|
+
return "Cannot close server runtime from an active runtime work item.";
|
|
204
|
+
}
|
|
205
|
+
if (state === "running-work") {
|
|
206
|
+
return "Cannot enqueue runtime work from an active runtime work item.";
|
|
207
|
+
}
|
|
208
|
+
return `Cannot enqueue runtime work while server runtime is ${state}.`;
|
|
209
|
+
},
|
|
210
|
+
isRunningWork(runtime) {
|
|
211
|
+
const frame = runtimeWork.getStore();
|
|
212
|
+
return frame?.runtime === runtime && frame.active;
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceR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C;YACtD,OAAO,+DAA+D,CAAC;QACzE,CAAC;QAED,IAAI,KAAK,KAAK,cAAc,EAAE,CAAC;YAC7B,OAAO,+DAA+D,CAAC;QACzE,CAAC;QAED,OAAO,uDAAuD,KAAK,GAAG,CAAC;IACzE,CAAC;IAED,aAAa,CAAC,OAAmC;QAC/C,MAAM,KAAK,GAAG,WAAW,CAAC,QAAQ,EAAE,CAAC;QACrC,OAAO,KAAK,EAAE,OAAO,KAAK,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC;IACpD,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write-side signal kinds accepted by the first intake-result seam.
|
|
3
|
+
*/
|
|
4
|
+
export type SignalKind = "command" | "event";
|
|
5
|
+
/**
|
|
6
|
+
* Marker for intake that accepted responsibility for later asynchronous work.
|
|
7
|
+
*/
|
|
8
|
+
export type SignalIntakeAcceptedFor = "async-work";
|
|
9
|
+
/**
|
|
10
|
+
* Stable machine-readable reason code for immediate signal intake failures.
|
|
11
|
+
*/
|
|
12
|
+
export type SignalIntakeFailureCode = "RUNTIME_NOT_ACCEPTING" | "MALFORMED_ENVELOPE" | "UNSUPPORTED_SIGNAL_KIND";
|
|
13
|
+
/**
|
|
14
|
+
* Sanitized scalar diagnostic metadata for immediate signal intake failures.
|
|
15
|
+
*/
|
|
16
|
+
export type SignalIntakeFailureDiagnostics = Readonly<Record<string, string | number | boolean | null>>;
|
|
17
|
+
/**
|
|
18
|
+
* Result returned when a write-side signal is accepted for later asynchronous work.
|
|
19
|
+
*/
|
|
20
|
+
export interface SignalIntakeAccepted<Kind extends SignalKind = SignalKind> {
|
|
21
|
+
/**
|
|
22
|
+
* Discriminant for accepted intake.
|
|
23
|
+
*/
|
|
24
|
+
readonly status: "accepted";
|
|
25
|
+
/**
|
|
26
|
+
* Whether the accepted signal is a command or event.
|
|
27
|
+
*/
|
|
28
|
+
readonly signalKind: Kind;
|
|
29
|
+
/**
|
|
30
|
+
* Accepted intake only promises future asynchronous work ownership.
|
|
31
|
+
*/
|
|
32
|
+
readonly acceptedFor: SignalIntakeAcceptedFor;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Structured immediate failure details with sanitized diagnostics only.
|
|
36
|
+
*/
|
|
37
|
+
export interface SignalIntakeFailureDetails {
|
|
38
|
+
/**
|
|
39
|
+
* Stable machine-readable intake failure reason.
|
|
40
|
+
*/
|
|
41
|
+
readonly code: SignalIntakeFailureCode;
|
|
42
|
+
/**
|
|
43
|
+
* Copy-safe scalar diagnostics; never a full signal, envelope, or message payload.
|
|
44
|
+
*/
|
|
45
|
+
readonly diagnostics: SignalIntakeFailureDiagnostics;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Result returned when a write-side signal fails immediately at intake.
|
|
49
|
+
*/
|
|
50
|
+
export interface SignalIntakeFailure<Kind extends SignalKind = SignalKind> {
|
|
51
|
+
/**
|
|
52
|
+
* Discriminant for immediate intake failure.
|
|
53
|
+
*/
|
|
54
|
+
readonly status: "failed";
|
|
55
|
+
/**
|
|
56
|
+
* Whether the rejected signal is a command or event.
|
|
57
|
+
*/
|
|
58
|
+
readonly signalKind: Kind;
|
|
59
|
+
/**
|
|
60
|
+
* Stable failure reason and sanitized diagnostics.
|
|
61
|
+
*/
|
|
62
|
+
readonly failure: SignalIntakeFailureDetails;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Write-side signal intake result value.
|
|
66
|
+
*/
|
|
67
|
+
export type SignalIntakeResult<Kind extends SignalKind = SignalKind> = SignalIntakeAccepted<Kind> | SignalIntakeFailure<Kind>;
|
|
68
|
+
/**
|
|
69
|
+
* Creates an immutable accepted-for-async-work signal intake result.
|
|
70
|
+
*
|
|
71
|
+
* @param signalKind the kind of accepted signal.
|
|
72
|
+
* @returns the accepted intake result.
|
|
73
|
+
*/
|
|
74
|
+
export declare function acceptSignalIntake<Kind extends SignalKind>(signalKind: Kind): SignalIntakeAccepted<Kind>;
|
|
75
|
+
/**
|
|
76
|
+
* Creates an immutable immediate signal intake failure result.
|
|
77
|
+
*
|
|
78
|
+
* @param signalKind the kind of rejected signal.
|
|
79
|
+
* @param code the stable intake failure code.
|
|
80
|
+
* @param diagnostics scalar diagnostic details to retain.
|
|
81
|
+
* @returns the failed intake result.
|
|
82
|
+
*/
|
|
83
|
+
export declare function failSignalIntake<Kind extends SignalKind>(signalKind: Kind, code: SignalIntakeFailureCode, diagnostics?: Readonly<Record<string, unknown>>): SignalIntakeFailure<Kind>;
|
|
84
|
+
//# sourceMappingURL=signal-intake.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signal-intake.d.ts","sourceRoot":"","sources":["../../src/runtime/signal-intake.ts"],"names":[],"mappings":"AAcA;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,OAAO,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,YAAY,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,uBAAuB,GACjC,uBAAuB,GAAG,oBAAoB,GAAG,yBAAyB,CAAC;AAE7E;;GAEG;AACH,MAAM,MAAM,8BAA8B,GAAG,QAAQ,CACnD,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,CACjD,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,oBAAoB,CAAC,IAAI,SAAS,UAAU,GAAG,UAAU;IAGxE;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAE5B;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC;IAE1B;;OAEG;IACH,QAAQ,CAAC,WAAW,EAAE,uBAAuB,CAAC;CAC/C;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IAGzC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAC;IAEvC;;OAEG;IACH,QAAQ,CAAC,WAAW,EAAE,8BAA8B,CAAC;CACtD;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB,CAAC,IAAI,SAAS,UAAU,GAAG,UAAU;IAGvE;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAE1B;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC;IAE1B;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,0BAA0B,CAAC;CAC9C;AAED;;GAEG;AACH,MAAM,MAAM,kBAAkB,CAAC,IAAI,SAAS,UAAU,GAAG,UAAU,IACjE,oBAAoB,CAAC,IAAI,CAAC,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC;AAqBzD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,SAAS,UAAU,EACxD,UAAU,EAAE,IAAI,GACf,oBAAoB,CAAC,IAAI,CAAC,CAM5B;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,SAAS,UAAU,EACtD,UAAU,EAAE,IAAI,EAChB,IAAI,EAAE,uBAAuB,EAC7B,WAAW,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM,GAClD,mBAAmB,CAAC,IAAI,CAAC,CAS3B"}
|
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
const isProxy = process.getBuiltinModule("node:util").types.isProxy;
|
|
15
|
+
const allowedDiagnosticKeys = new Set([
|
|
16
|
+
"attempt",
|
|
17
|
+
"boundedContext",
|
|
18
|
+
"messageType",
|
|
19
|
+
"reason",
|
|
20
|
+
"retryable",
|
|
21
|
+
"runtimeState",
|
|
22
|
+
]);
|
|
23
|
+
/**
|
|
24
|
+
* Creates an immutable accepted-for-async-work signal intake result.
|
|
25
|
+
*
|
|
26
|
+
* @param signalKind the kind of accepted signal.
|
|
27
|
+
* @returns the accepted intake result.
|
|
28
|
+
*/
|
|
29
|
+
export function acceptSignalIntake(signalKind) {
|
|
30
|
+
return Object.freeze({
|
|
31
|
+
status: "accepted",
|
|
32
|
+
signalKind,
|
|
33
|
+
acceptedFor: "async-work",
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Creates an immutable immediate signal intake failure result.
|
|
38
|
+
*
|
|
39
|
+
* @param signalKind the kind of rejected signal.
|
|
40
|
+
* @param code the stable intake failure code.
|
|
41
|
+
* @param diagnostics scalar diagnostic details to retain.
|
|
42
|
+
* @returns the failed intake result.
|
|
43
|
+
*/
|
|
44
|
+
export function failSignalIntake(signalKind, code, diagnostics = {}) {
|
|
45
|
+
return Object.freeze({
|
|
46
|
+
status: "failed",
|
|
47
|
+
signalKind,
|
|
48
|
+
failure: Object.freeze({
|
|
49
|
+
code,
|
|
50
|
+
diagnostics: SignalIntakeValues.sanitizeDiagnostics(diagnostics),
|
|
51
|
+
}),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Private signal-intake diagnostic helpers.
|
|
56
|
+
*/
|
|
57
|
+
const SignalIntakeValues = Object.freeze({
|
|
58
|
+
sanitizeDiagnostics(diagnostics) {
|
|
59
|
+
const sanitized = {};
|
|
60
|
+
const descriptors = SignalIntakeValues.getOwnDiagnosticDescriptors(diagnostics);
|
|
61
|
+
if (descriptors === undefined) {
|
|
62
|
+
return Object.freeze(sanitized);
|
|
63
|
+
}
|
|
64
|
+
for (const key of allowedDiagnosticKeys) {
|
|
65
|
+
const descriptor = descriptors[key];
|
|
66
|
+
if (descriptor === undefined || !descriptor.enumerable || !("value" in descriptor)) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const value = descriptor.value;
|
|
70
|
+
if (SignalIntakeValues.isDiagnosticScalar(value)) {
|
|
71
|
+
sanitized[key] = value;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return Object.freeze(sanitized);
|
|
75
|
+
},
|
|
76
|
+
getOwnDiagnosticDescriptors(diagnostics) {
|
|
77
|
+
if (isProxy(diagnostics)) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
return Object.getOwnPropertyDescriptors(diagnostics);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
isDiagnosticScalar(value) {
|
|
88
|
+
return (value === null ||
|
|
89
|
+
typeof value === "string" ||
|
|
90
|
+
typeof value === "number" ||
|
|
91
|
+
typeof value === "boolean");
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
//# sourceMappingURL=signal-intake.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signal-intake.js","sourceRoot":"","sources":["../../src/runtime/signal-intake.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAoGH,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;AAEpE,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACpC,SAAS;IACT,gBAAgB;IAChB,aAAa;IACb,QAAQ;IACR,WAAW;IACX,cAAc;CACf,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAChC,UAAgB;IAEhB,OAAO,M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