@spine-event-engine/server 2.0.0-snapshot.11
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 +209 -0
- package/REFERENCE.md +760 -0
- package/dist/browser/browser-server.d.ts +95 -0
- package/dist/browser/browser-server.d.ts.map +1 -0
- package/dist/browser/browser-server.js +719 -0
- package/dist/browser/browser-server.js.map +1 -0
- package/dist/browser/durable-subscription-bindings.d.ts +122 -0
- package/dist/browser/durable-subscription-bindings.d.ts.map +1 -0
- package/dist/browser/durable-subscription-bindings.js +524 -0
- package/dist/browser/durable-subscription-bindings.js.map +1 -0
- package/dist/browser/index.d.ts +12 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +24 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/options.d.ts +183 -0
- package/dist/browser/options.d.ts.map +1 -0
- package/dist/browser/options.js +15 -0
- package/dist/browser/options.js.map +1 -0
- package/dist/bus/command-bus.d.ts +63 -0
- package/dist/bus/command-bus.d.ts.map +1 -0
- package/dist/bus/command-bus.js +236 -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 +592 -0
- package/dist/context/bounded-context.d.ts.map +1 -0
- package/dist/context/bounded-context.js +1897 -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 +387 -0
- package/dist/context/entity-inbox.js.map +1 -0
- package/dist/context/local-inbox-handoff.d.ts +248 -0
- package/dist/context/local-inbox-handoff.d.ts.map +1 -0
- package/dist/context/local-inbox-handoff.js +340 -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 +177 -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 +93 -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 +151 -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 +236 -0
- package/dist/delivery/delivery.d.ts.map +1 -0
- package/dist/delivery/delivery.js +539 -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 +83 -0
- package/dist/delivery/inbox-storage.d.ts.map +1 -0
- package/dist/delivery/inbox-storage.js +336 -0
- package/dist/delivery/inbox-storage.js.map +1 -0
- package/dist/delivery/inbox.d.ts +272 -0
- package/dist/delivery/inbox.d.ts.map +1 -0
- package/dist/delivery/inbox.js +183 -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 +361 -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 +605 -0
- package/dist/entity/entity.d.ts.map +1 -0
- package/dist/entity/entity.js +981 -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/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 +120 -0
- package/dist/handler/command-registration-readiness.js.map +1 -0
- package/dist/handler/declared-rejections.d.ts +11 -0
- package/dist/handler/declared-rejections.d.ts.map +1 -0
- package/dist/handler/declared-rejections.js +34 -0
- package/dist/handler/declared-rejections.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 +185 -0
- package/dist/handler/generated-handler-registry.d.ts.map +1 -0
- package/dist/handler/generated-handler-registry.js +439 -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 +226 -0
- package/dist/handler/generated-registry-discovery.js.map +1 -0
- package/dist/handler/handler-decorators.d.ts +151 -0
- package/dist/handler/handler-decorators.d.ts.map +1 -0
- package/dist/handler/handler-decorators.js +275 -0
- package/dist/handler/handler-decorators.js.map +1 -0
- package/dist/handler/handler-metadata.d.ts +553 -0
- package/dist/handler/handler-metadata.d.ts.map +1 -0
- package/dist/handler/handler-metadata.js +437 -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 +171 -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/handler/standalone.d.ts +25 -0
- package/dist/handler/standalone.d.ts.map +1 -0
- package/dist/handler/standalone.js +38 -0
- package/dist/handler/standalone.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 +75 -0
- package/dist/repository/primitive-id.d.ts.map +1 -0
- package/dist/repository/primitive-id.js +85 -0
- package/dist/repository/primitive-id.js.map +1 -0
- package/dist/repository/repository.d.ts +667 -0
- package/dist/repository/repository.d.ts.map +1 -0
- package/dist/repository/repository.js +3510 -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 +217 -0
- package/dist/runtime/signal-metadata.d.ts.map +1 -0
- package/dist/runtime/signal-metadata.js +333 -0
- package/dist/runtime/signal-metadata.js.map +1 -0
- package/dist/runtime/signal-publisher.d.ts +144 -0
- package/dist/runtime/signal-publisher.d.ts.map +1 -0
- package/dist/runtime/signal-publisher.js +248 -0
- package/dist/runtime/signal-publisher.js.map +1 -0
- package/dist/runtime/standalone-handler-runtime.d.ts +114 -0
- package/dist/runtime/standalone-handler-runtime.d.ts.map +1 -0
- package/dist/runtime/standalone-handler-runtime.js +307 -0
- package/dist/runtime/standalone-handler-runtime.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 +2062 -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 +673 -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 +327 -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 +100 -0
- package/dist/server/server-log.js.map +1 -0
- package/dist/server/server.d.ts +221 -0
- package/dist/server/server.d.ts.map +1 -0
- package/dist/server/server.js +704 -0
- package/dist/server/server.js.map +1 -0
- package/dist/services/query-reader.d.ts +19 -0
- package/dist/services/query-reader.d.ts.map +1 -0
- package/dist/services/query-reader.js +43 -0
- package/dist/services/query-reader.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 +1582 -0
- package/dist/services/spine-services.js.map +1 -0
- package/dist/spi/delivery.d.ts +5 -0
- package/dist/spi/delivery.d.ts.map +1 -0
- package/dist/spi/delivery.js +18 -0
- package/dist/spi/delivery.js.map +1 -0
- package/dist/spi/handler-registry.d.ts +8 -0
- package/dist/spi/handler-registry.d.ts.map +1 -0
- package/dist/spi/handler-registry.js +15 -0
- package/dist/spi/handler-registry.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 +681 -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 +36 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +54 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1,130 @@
|
|
|
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 { create, toBinary } from "@bufbuild/protobuf";
|
|
15
|
+
import { TimestampSchema } from "@bufbuild/protobuf/wkt";
|
|
16
|
+
import { AnyMessages, TypeUrls } from "@spine-event-engine/core";
|
|
17
|
+
import { ActorContextSchema, BoundedContextNameSchema, EventContextSchema, EventIdSchema, EventSchema, UserIdSchema, } from "@spine-event-engine/proto";
|
|
18
|
+
import { BoundedContext, boundedContextIntegrationAccess } from "../context/bounded-context.js";
|
|
19
|
+
import { ServerEnvironment } from "../server/server-environment.js";
|
|
20
|
+
/**
|
|
21
|
+
* Represents a hidden bounded context that imports third-party events through its private broker.
|
|
22
|
+
*
|
|
23
|
+
* The JVM-owned integration lifecycle remains private: this facade only creates the context,
|
|
24
|
+
* publishes generated events, observes availability, and closes it.
|
|
25
|
+
*/
|
|
26
|
+
export class ThirdPartyContext {
|
|
27
|
+
#context;
|
|
28
|
+
#multitenant;
|
|
29
|
+
#closed = false;
|
|
30
|
+
constructor(context, multitenant) {
|
|
31
|
+
this.#context = context;
|
|
32
|
+
this.#multitenant = multitenant;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Creates a third-party context that forbids actor tenants.
|
|
36
|
+
*
|
|
37
|
+
* @param name Identifies the hidden bounded context.
|
|
38
|
+
* @returns Resolves to an open single-tenant context.
|
|
39
|
+
*/
|
|
40
|
+
static async singleTenant(name) {
|
|
41
|
+
return new ThirdPartyContext(await BoundedContext.singleTenant(name).buildAsync(), false);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates a third-party context that requires actor tenants.
|
|
45
|
+
*
|
|
46
|
+
* @param name Identifies the hidden bounded context.
|
|
47
|
+
* @returns Resolves to an open multitenant context.
|
|
48
|
+
*/
|
|
49
|
+
static async multitenant(name) {
|
|
50
|
+
return new ThirdPartyContext(await BoundedContext.multitenant(name).buildAsync(), true);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Publishes one generated event with its importing actor identity.
|
|
54
|
+
*
|
|
55
|
+
* @param event Supplies the generated event message to import unchanged.
|
|
56
|
+
* @param actor Supplies a user or actor context that satisfies this context's tenancy policy.
|
|
57
|
+
* @returns Completes when the private broker accepts the imported event.
|
|
58
|
+
*/
|
|
59
|
+
async emittedEvent(event, actor) {
|
|
60
|
+
if (this.#closed)
|
|
61
|
+
throw new Error("ThirdPartyContext is closed.");
|
|
62
|
+
const actorContext = this.#actorContext(actor);
|
|
63
|
+
const typeName = event.$typeName;
|
|
64
|
+
if (typeof typeName !== "string" || typeName.length === 0) {
|
|
65
|
+
throw new TypeError("ThirdPartyContext requires a generated event message.");
|
|
66
|
+
}
|
|
67
|
+
const envelope = create(EventSchema, {
|
|
68
|
+
id: create(EventIdSchema, { value: crypto.randomUUID() }),
|
|
69
|
+
message: {
|
|
70
|
+
typeUrl: this.#schema(typeName).typeUrl,
|
|
71
|
+
value: toBinary(this.#schema(typeName).schema, event),
|
|
72
|
+
},
|
|
73
|
+
context: create(EventContextSchema, {
|
|
74
|
+
timestamp: actorContext.timestamp ?? create(TimestampSchema),
|
|
75
|
+
origin: { case: "importContext", value: actorContext },
|
|
76
|
+
producerId: AnyMessages.pack(BoundedContextNameSchema, create(BoundedContextNameSchema, { value: this.#context.name.value })),
|
|
77
|
+
}),
|
|
78
|
+
});
|
|
79
|
+
await boundedContextIntegrationAccess.publishImported(this.#context, envelope);
|
|
80
|
+
}
|
|
81
|
+
/* eslint-enable @typescript-eslint/unified-signatures */
|
|
82
|
+
/**
|
|
83
|
+
* Returns whether the hidden bounded context remains available for imports.
|
|
84
|
+
*
|
|
85
|
+
* @returns `true` until a successful close; `false` after it closes.
|
|
86
|
+
*/
|
|
87
|
+
isOpen() {
|
|
88
|
+
return !this.#closed;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Closes the hidden bounded context and its private broker resources.
|
|
92
|
+
*
|
|
93
|
+
* @returns Completes after shutdown; repeated calls after a successful close do nothing.
|
|
94
|
+
*/
|
|
95
|
+
async close() {
|
|
96
|
+
if (this.#closed)
|
|
97
|
+
return;
|
|
98
|
+
await this.#context.close();
|
|
99
|
+
this.#closed = true;
|
|
100
|
+
}
|
|
101
|
+
#actorContext(actor) {
|
|
102
|
+
const isUser = actor.$typeName === UserIdSchema.typeName;
|
|
103
|
+
if (isUser) {
|
|
104
|
+
if (this.#multitenant)
|
|
105
|
+
throw new Error("Multitenant ThirdPartyContext requires ActorContext.");
|
|
106
|
+
const now = Date.now();
|
|
107
|
+
return create(ActorContextSchema, {
|
|
108
|
+
actor,
|
|
109
|
+
timestamp: create(TimestampSchema, {
|
|
110
|
+
seconds: BigInt(Math.floor(now / 1_000)),
|
|
111
|
+
nanos: (now % 1_000) * 1_000_000,
|
|
112
|
+
}),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
const hasTenant = actor.tenantId?.kind.case !== undefined;
|
|
116
|
+
if (this.#multitenant !== hasTenant) {
|
|
117
|
+
throw new Error(this.#multitenant
|
|
118
|
+
? "Multitenant ThirdPartyContext requires actor tenantId."
|
|
119
|
+
: "Single-tenant ThirdPartyContext forbids actor tenantId.");
|
|
120
|
+
}
|
|
121
|
+
return actor;
|
|
122
|
+
}
|
|
123
|
+
#schema(typeName) {
|
|
124
|
+
const metadata = ServerEnvironment.instance().typeRegistry.findByFullName(typeName);
|
|
125
|
+
if (metadata === undefined)
|
|
126
|
+
throw new TypeError(`ThirdPartyContext does not know ${typeName}.`);
|
|
127
|
+
return { schema: metadata.schema, typeUrl: TypeUrls.derive(metadata.schema) };
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=third-party-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"third-party-context.js","sourceRoot":"","sources":["../../src/integration/third-party-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAgB,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,kBAAkB,EAClB,aAAa,EACb,WAAW,EACX,YAAY,GAGb,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,cAAc,EAAE,+BAA+B,EAAE,MAAM,+BAA+B,CAAC;AAChG,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,C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BACL,SAAS,EAAE,MAAM,CAAC,eAAe,EAAE;oBACjC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC;oBACxC,KAAK,EAAE,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,SAAS;iBACjC,CAAC;aACH,CAAC,CAAC;QACL,CAAC;QACD,MAAM,SAAS,GAAG,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC;QAC1D,IAAI,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CACb,IAAI,CAAC,YAAY;gBACf,CAAC,CAAC,wDAAwD;gBAC1D,CAAC,CAAC,yDAAyD,CAC9D,CAAC;QACJ,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,CAAC,QAAgB;QACtB,MAAM,QAAQ,GAAG,iBAAiB,CAAC,QAAQ,EAAE,CAAC,YAAY,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QACpF,IAAI,QAAQ,KAAK,SAAS;YAAE,MAAM,IAAI,SAAS,CAAC,mCAAmC,QAAQ,GAAG,CAAC,CAAC;QAChG,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;IAChF,CAAC;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ValidationError } from "@spine-event-engine/proto";
|
|
2
|
+
/**
|
|
3
|
+
* Error raised when aggregate command execution rejects a state transition.
|
|
4
|
+
*/
|
|
5
|
+
export declare class TransitionValidationError extends Error {
|
|
6
|
+
/**
|
|
7
|
+
* Stable client-visible error type returned in `Ack.status.error.type`.
|
|
8
|
+
*/
|
|
9
|
+
readonly type = "COMMAND_STATE_TRANSITION_VALIDATION_FAILED";
|
|
10
|
+
/**
|
|
11
|
+
* Stable client-visible error message returned in `Ack.status.error.message`.
|
|
12
|
+
*/
|
|
13
|
+
readonly clientMessage = "Command state transition validation failed.";
|
|
14
|
+
/**
|
|
15
|
+
* Structured transition validation details from the entity transaction boundary.
|
|
16
|
+
*/
|
|
17
|
+
readonly validationError: ValidationError;
|
|
18
|
+
/**
|
|
19
|
+
* Creates an aggregate transition validation error.
|
|
20
|
+
*
|
|
21
|
+
* @param validationError Structured details explaining the rejected transition.
|
|
22
|
+
*/
|
|
23
|
+
constructor(validationError: ValidationError);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=command-errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-errors.d.ts","sourceRoot":"","sources":["../../src/repository/command-errors.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAEjE;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,KAAK;IAGlD;;OAEG;IACH,QAAQ,CAAC,IAAI,gDAAgD;IAE7D;;OAEG;IACH,QAAQ,CAAC,aAAa,iDAAiD;IAEvE;;OAEG;IACH,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;IAE1C;;;;OAIG;gBACS,eAAe,EAAE,eAAe;CAM7C"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026, CodeMatters. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
|
5
|
+
* in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
10
|
+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
11
|
+
* or implied. See the License for the specific language governing permissions and limitations under
|
|
12
|
+
* the License.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Error raised when aggregate command execution rejects a state transition.
|
|
16
|
+
*/
|
|
17
|
+
export class TransitionValidationError extends Error {
|
|
18
|
+
// prettier-ignore
|
|
19
|
+
/**
|
|
20
|
+
* Stable client-visible error type returned in `Ack.status.error.type`.
|
|
21
|
+
*/
|
|
22
|
+
type = "COMMAND_STATE_TRANSITION_VALIDATION_FAILED";
|
|
23
|
+
/**
|
|
24
|
+
* Stable client-visible error message returned in `Ack.status.error.message`.
|
|
25
|
+
*/
|
|
26
|
+
clientMessage = "Command state transition validation failed.";
|
|
27
|
+
/**
|
|
28
|
+
* Structured transition validation details from the entity transaction boundary.
|
|
29
|
+
*/
|
|
30
|
+
validationError;
|
|
31
|
+
/**
|
|
32
|
+
* Creates an aggregate transition validation error.
|
|
33
|
+
*
|
|
34
|
+
* @param validationError Structured details explaining the rejected transition.
|
|
35
|
+
*/
|
|
36
|
+
constructor(validationError) {
|
|
37
|
+
super("Command state transition validation failed.");
|
|
38
|
+
this.name = "TransitionValidationError";
|
|
39
|
+
this.validationError = validationError;
|
|
40
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=command-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-errors.js","sourceRoot":"","sources":["../../src/repository/command-errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH;;GAEG;AACH,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAClD,kBAAkB;IAElB;;OAEG;IACM,IAAI,GAAG,4CAA4C,CAAC;IAE7D;;OAEG;IACM,aAAa,GAAG,6CAA6C,CAAC;IAEvE;;OAEG;IACM,eAAe,CAAkB;IAE1C;;;;OAIG;IACH,YAAY,eAAgC;QAC1C,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACrD,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;QACxC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { MessageShape } from "@bufbuild/protobuf";
|
|
2
|
+
import { type MessageInterface, type MessageSchema } from "@spine-event-engine/core";
|
|
3
|
+
import type { CommandContext } from "@spine-event-engine/proto";
|
|
4
|
+
import { type InterfaceRouteSchemas, type InterfaceRouteMessage, type RoutingDeclarationSnapshot, type RoutingDeclarationState } from "./routing-declarations.js";
|
|
5
|
+
/**
|
|
6
|
+
* Calculates one Entity ID for a Command message.
|
|
7
|
+
*
|
|
8
|
+
* @typeParam Id Entity ID type owned by the receiving repository.
|
|
9
|
+
* @typeParam Schema Generated Command message schema.
|
|
10
|
+
* @param message Unpacked Command message.
|
|
11
|
+
* @param context Normalized Command context. When the signal omits its context,
|
|
12
|
+
* the framework supplies the default generated `CommandContext` value.
|
|
13
|
+
* The route must be deterministic and side-effect-free. The framework invokes
|
|
14
|
+
* it once for each accepted admission, and durable replay uses the stored
|
|
15
|
+
* target instead of invoking it again.
|
|
16
|
+
*
|
|
17
|
+
* @returns Target Entity ID.
|
|
18
|
+
*/
|
|
19
|
+
export type CommandRoute<Id, Schema extends MessageSchema = MessageSchema> = (message: MessageShape<Schema>, context: CommandContext) => Id;
|
|
20
|
+
type CommandRoutingState<Id> = RoutingDeclarationState<CommandRoute<Id>>;
|
|
21
|
+
/**
|
|
22
|
+
* Mutable Command route declarations that repositories snapshot at construction.
|
|
23
|
+
*
|
|
24
|
+
* @typeParam Id Entity ID type owned by the receiving repository.
|
|
25
|
+
*/
|
|
26
|
+
export declare class CommandRouting<Id> {
|
|
27
|
+
/**
|
|
28
|
+
* Creates empty mutable Command route declarations.
|
|
29
|
+
*/
|
|
30
|
+
private constructor();
|
|
31
|
+
/**
|
|
32
|
+
* Creates empty Command route declarations.
|
|
33
|
+
*
|
|
34
|
+
* @typeParam Id Entity ID type owned by the receiving repository.
|
|
35
|
+
* @returns Mutable Command route declarations.
|
|
36
|
+
*/
|
|
37
|
+
static create<Id>(): CommandRouting<Id>;
|
|
38
|
+
/**
|
|
39
|
+
* Registers a route for one exact generated Command schema.
|
|
40
|
+
*
|
|
41
|
+
* @param schemaOrToken Generated Command schema.
|
|
42
|
+
* @param via Route that calculates the target Entity ID.
|
|
43
|
+
* @returns These mutable route declarations.
|
|
44
|
+
*/
|
|
45
|
+
route<Schema extends MessageSchema>(schemaOrToken: Schema, via: CommandRoute<Id, Schema>): this;
|
|
46
|
+
/**
|
|
47
|
+
* Registers a route for a nominal Command message-interface token.
|
|
48
|
+
*
|
|
49
|
+
* @param schemaOrToken Generated Command message-interface token.
|
|
50
|
+
* @param via Route that calculates the target Entity ID.
|
|
51
|
+
* @returns These mutable route declarations.
|
|
52
|
+
*/
|
|
53
|
+
route<TInterface extends object, Schemas extends InterfaceRouteSchemas>(schemaOrToken: MessageInterface<TInterface, Schemas>, via: (message: InterfaceRouteMessage<TInterface, Schemas>, context: CommandContext) => Id): this;
|
|
54
|
+
/**
|
|
55
|
+
* Replaces the declaration-first default Command route.
|
|
56
|
+
*
|
|
57
|
+
* @param via Route that calculates the target Entity ID.
|
|
58
|
+
* @returns These mutable route declarations.
|
|
59
|
+
*/
|
|
60
|
+
replaceDefault(via: CommandRoute<Id>): this;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Internal access to Command-routing declaration state.
|
|
64
|
+
*
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
export declare const CommandRoutingInternals: Readonly<{
|
|
68
|
+
state<Id>(routing: CommandRouting<Id>): CommandRoutingState<Id>;
|
|
69
|
+
snapshot<Id>(routing: CommandRouting<Id> | undefined): RoutingDeclarationSnapshot<CommandRoute<Id>>;
|
|
70
|
+
}>;
|
|
71
|
+
export {};
|
|
72
|
+
//# sourceMappingURL=command-routing.d.ts.map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cAAc,KAAK,EAAE,GACxF,IAAI;IAwCP;;;;;OAKG;IACH,cAAc,CAAC,GAAG,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,IAAI;CAM5C;AAED;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,EAAE,QAAQ,CAAC;IAC7C,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,cAAc,CAAC,EAAE,CAAC,GAAG,mBAAmB,CAAC,EAAE,CAAC,CAAC;IAChE,QAAQ,CAAC,EAAE,EACT,OAAO,EAAE,cAAc,CAAC,EAAE,CAAC,GAAG,SAAS,GACtC,0BAA0B,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC;CACjD,CAYC,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
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 routingStates = new WeakMap();
|
|
17
|
+
/**
|
|
18
|
+
* Mutable Command route declarations that repositories snapshot at construction.
|
|
19
|
+
*
|
|
20
|
+
* @typeParam Id Entity ID type owned by the receiving repository.
|
|
21
|
+
*/
|
|
22
|
+
export class CommandRouting {
|
|
23
|
+
// prettier-ignore
|
|
24
|
+
/**
|
|
25
|
+
* Creates empty mutable Command route declarations.
|
|
26
|
+
*/
|
|
27
|
+
constructor() {
|
|
28
|
+
routingStates.set(this, RoutingDeclarations.create());
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates empty Command route declarations.
|
|
32
|
+
*
|
|
33
|
+
* @typeParam Id Entity ID type owned by the receiving repository.
|
|
34
|
+
* @returns Mutable Command route declarations.
|
|
35
|
+
*/
|
|
36
|
+
static create() {
|
|
37
|
+
return new CommandRouting();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Registers an exact generated Command-schema route or a nominal message-interface route.
|
|
41
|
+
*
|
|
42
|
+
* A schema route receives its exact message shape. An interface route receives
|
|
43
|
+
* {@link InterfaceRouteMessage}, the member-message union intersected with
|
|
44
|
+
* the declared interface. Routing selects an exact schema route first, then
|
|
45
|
+
* the first matching interface token in registration order, then the
|
|
46
|
+
* replacement/default route.
|
|
47
|
+
*
|
|
48
|
+
* Copied or malformed tokens fail during declaration. Every token member must
|
|
49
|
+
* be registered by the repository, or construction fails. The selected route
|
|
50
|
+
* runs once for an accepted admission; durable replay uses stored targets and
|
|
51
|
+
* does not run routing again.
|
|
52
|
+
*
|
|
53
|
+
* @param schemaOrToken Generated Command schema or nominal message-interface token.
|
|
54
|
+
* @param via Route that calculates the target Entity ID.
|
|
55
|
+
* @returns These mutable route declarations.
|
|
56
|
+
*/
|
|
57
|
+
route(schemaOrToken, via) {
|
|
58
|
+
if (typeof via !== "function")
|
|
59
|
+
throw new TypeError("Command routing requires a route function.");
|
|
60
|
+
const state = CommandRoutingInternals.state(this);
|
|
61
|
+
if (RoutingDeclarations.isInterfaceTokenCandidate(schemaOrToken)) {
|
|
62
|
+
RoutingDeclarations.routeInterface(state, schemaOrToken, via, "Command routing");
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
RoutingDeclarations.exact(state, schemaOrToken, via, "Command routing has a duplicate exact command route.");
|
|
66
|
+
}
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Replaces the declaration-first default Command route.
|
|
71
|
+
*
|
|
72
|
+
* @param via Route that calculates the target Entity ID.
|
|
73
|
+
* @returns These mutable route declarations.
|
|
74
|
+
*/
|
|
75
|
+
replaceDefault(via) {
|
|
76
|
+
if (typeof via !== "function")
|
|
77
|
+
throw new TypeError("Command routing requires a route function.");
|
|
78
|
+
RoutingDeclarations.default(CommandRoutingInternals.state(this), via);
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Internal access to Command-routing declaration state.
|
|
84
|
+
*
|
|
85
|
+
* @internal
|
|
86
|
+
*/
|
|
87
|
+
export const CommandRoutingInternals = Object.freeze({
|
|
88
|
+
state(routing) {
|
|
89
|
+
return routingStates.get(routing);
|
|
90
|
+
},
|
|
91
|
+
snapshot(routing) {
|
|
92
|
+
if (routing === undefined) {
|
|
93
|
+
return RoutingDeclarations.snapshot(RoutingDeclarations.create());
|
|
94
|
+
}
|
|
95
|
+
return RoutingDeclarations.snapshot(CommandRoutingInternals.state(routing));
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
//# sourceMappingURL=command-routing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-routing.js","sourceRoot":"","sources":["../../src/repository/command-routing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAA6C,MAAM,0BAA0B,CAAC;AAErF,OAAO,EACL,mBAAmB,GAKpB,MAAM,2BAA2B,CAAC;AAuBnC,MAAM,aAAa,GAAG,IAAI,OAAO,EAAwC,CAAC;AAE1E;;;;GAIG;AACH,MAAM,OAAO,cAAc;IACzB,kBAAkB;IAElB;;OAEG;IACH;QACE,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,mBAAmB,CAAC,MAAM,EAAoB,CAAC,CAAC;IAC1E,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,MAAM;QACX,OAAO,IAAI,cAAc,EAAM,CAAC;IACl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,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
interface Commit {
|
|
2
|
+
readonly status: string;
|
|
3
|
+
}
|
|
4
|
+
type Guard = () => Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* Executes a delivery callback with a commit-time ownership guard.
|
|
7
|
+
*
|
|
8
|
+
* @param guard Verifies that the delivery worker still owns its shard.
|
|
9
|
+
* @param callback Performs the delivery work within the guarded scope.
|
|
10
|
+
* @returns The value produced by the delivery callback.
|
|
11
|
+
*/
|
|
12
|
+
export declare function withDeliveryCommitFence<T>(guard: Guard, callback: () => Promise<T>): Promise<T>;
|
|
13
|
+
/**
|
|
14
|
+
* Verifies delivery ownership immediately before committing an Entity.
|
|
15
|
+
*
|
|
16
|
+
* @param entity Supplies the Entity whose transaction is committed.
|
|
17
|
+
* @param commit Commits the active Entity transaction synchronously.
|
|
18
|
+
* @returns The result produced by the Entity transaction commit.
|
|
19
|
+
*/
|
|
20
|
+
export declare function commitFenced<T extends Commit>(entity: object, commit: (entity: object) => T): Promise<T>;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=commit-fence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit-fence.d.ts","sourceRoot":"","sources":["../../src/repository/commit-fence.ts"],"names":[],"mappings":"AAgBA,UAAU,MAAM;IACd,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AACD,KAAK,KAAK,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;AAIjC;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAAC,CAAC,EAC7C,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACzB,OAAO,CAAC,CAAC,CAAC,CAEZ;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,CAAC,SAAS,MAAM,EACjD,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,CAAC,GAC5B,OAAO,CAAC,CAAC,CAAC,CAGZ"}
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
const fences = new AsyncLocalStorage();
|
|
16
|
+
/**
|
|
17
|
+
* Executes a delivery callback with a commit-time ownership guard.
|
|
18
|
+
*
|
|
19
|
+
* @param guard Verifies that the delivery worker still owns its shard.
|
|
20
|
+
* @param callback Performs the delivery work within the guarded scope.
|
|
21
|
+
* @returns The value produced by the delivery callback.
|
|
22
|
+
*/
|
|
23
|
+
export async function withDeliveryCommitFence(guard, callback) {
|
|
24
|
+
return fences.run(guard, callback);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Verifies delivery ownership immediately before committing an Entity.
|
|
28
|
+
*
|
|
29
|
+
* @param entity Supplies the Entity whose transaction is committed.
|
|
30
|
+
* @param commit Commits the active Entity transaction synchronously.
|
|
31
|
+
* @returns The result produced by the Entity transaction commit.
|
|
32
|
+
*/
|
|
33
|
+
export async function commitFenced(entity, commit) {
|
|
34
|
+
await fences.getStore()?.();
|
|
35
|
+
return commit(entity);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=commit-fence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit-fence.js","sourceRoot":"","sources":["../../src/repository/commit-fence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAOrD,MAAM,MAAM,GAAG,IAAI,iBAAiB,EAAS,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,KAAY,EACZ,QAA0B;IAE1B,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAc,EACd,MAA6B;IAE7B,MAAM,MAAM,CAAC,QAAQ,EAAE,EAAE,EAAE,CAAC;IAC5B,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { MessageShape } from "@bufbuild/protobuf";
|
|
2
|
+
import { type MessageInterface, type MessageSchema } from "@spine-event-engine/core";
|
|
3
|
+
import type { EventContext } from "@spine-event-engine/proto";
|
|
4
|
+
import { type InterfaceRouteSchemas, type InterfaceRouteMessage, type RoutingDeclarationSnapshot, type RoutingDeclarationState } from "./routing-declarations.js";
|
|
5
|
+
/**
|
|
6
|
+
* Calculates target Entity IDs for one Event admission.
|
|
7
|
+
*
|
|
8
|
+
* The route must be deterministic and side-effect-free. It runs once for an
|
|
9
|
+
* accepted admission; durable replay uses stored targets instead.
|
|
10
|
+
*
|
|
11
|
+
* @typeParam Id Entity ID type used by the receiving repository.
|
|
12
|
+
* @typeParam Schema Generated Event message schema.
|
|
13
|
+
* @param message Unpacked Event message.
|
|
14
|
+
* @param context Normalized Event context. When the signal omits its context,
|
|
15
|
+
* the framework supplies the default generated `EventContext` value.
|
|
16
|
+
* @returns Up to 1,000 target Entity IDs. The framework validates the complete
|
|
17
|
+
* result, copies and stable-deduplicates its IDs, and freezes the accepted
|
|
18
|
+
* plan. An empty array deliberately suppresses delivery to this repository.
|
|
19
|
+
*/
|
|
20
|
+
export type EventRoute<Id, Schema extends MessageSchema = MessageSchema> = (message: MessageShape<Schema>, context: EventContext) => readonly Id[];
|
|
21
|
+
type State<Id> = RoutingDeclarationState<EventRoute<Id>>;
|
|
22
|
+
/**
|
|
23
|
+
* Mutable Event route declarations snapshotted by repository construction.
|
|
24
|
+
*/
|
|
25
|
+
export declare class EventRouting<Id> {
|
|
26
|
+
/**
|
|
27
|
+
* Creates empty mutable Event route declarations.
|
|
28
|
+
*/
|
|
29
|
+
private constructor();
|
|
30
|
+
/**
|
|
31
|
+
* Creates empty Event route declarations.
|
|
32
|
+
*
|
|
33
|
+
* @typeParam Id Entity ID type used by the receiving repository.
|
|
34
|
+
* @returns Mutable Event route declarations.
|
|
35
|
+
*/
|
|
36
|
+
static create<Id>(): EventRouting<Id>;
|
|
37
|
+
/**
|
|
38
|
+
* Registers a route for one exact generated Event schema.
|
|
39
|
+
*
|
|
40
|
+
* @param schemaOrToken Generated Event schema.
|
|
41
|
+
* @param via Route that calculates target Entity IDs.
|
|
42
|
+
* @returns These mutable route declarations.
|
|
43
|
+
*/
|
|
44
|
+
route<Schema extends MessageSchema>(schemaOrToken: Schema, via: EventRoute<Id, Schema>): this;
|
|
45
|
+
/**
|
|
46
|
+
* Registers a route for a nominal Event message-interface token.
|
|
47
|
+
*
|
|
48
|
+
* @param schemaOrToken Generated Event message-interface token.
|
|
49
|
+
* @param via Route that calculates target Entity IDs.
|
|
50
|
+
* @returns These mutable route declarations.
|
|
51
|
+
*/
|
|
52
|
+
route<TInterface extends object, Schemas extends InterfaceRouteSchemas>(schemaOrToken: MessageInterface<TInterface, Schemas>, via: (message: InterfaceRouteMessage<TInterface, Schemas>, context: EventContext) => readonly Id[]): this;
|
|
53
|
+
/**
|
|
54
|
+
* Replaces the producer-aware default Event route.
|
|
55
|
+
*
|
|
56
|
+
* @param via Route that calculates target Entity IDs.
|
|
57
|
+
* @returns These mutable route declarations.
|
|
58
|
+
*/
|
|
59
|
+
replaceDefault(via: EventRoute<Id>): this;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Internal access to Event-routing declaration state.
|
|
63
|
+
*
|
|
64
|
+
* @internal
|
|
65
|
+
*/
|
|
66
|
+
export declare const EventRoutingInternals: Readonly<{
|
|
67
|
+
state<Id>(routing: EventRouting<Id>): State<Id>;
|
|
68
|
+
snapshot<Id>(routing: EventRouting<Id> | undefined): RoutingDeclarationSnapshot<EventRoute<Id>>;
|
|
69
|
+
}>;
|
|
70
|
+
export {};
|
|
71
|
+
//# sourceMappingURL=event-routing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-routing.d.ts","sourceRoot":"","sources":["../../src/repository/event-routing.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACrF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAC7B,MAAM,2BAA2B,CAAC;AAEnC;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,UAAU,CAAC,EAAE,EAAE,MAAM,SAAS,aAAa,GAAG,aAAa,IAAI,CACzE,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,EAC7B,OAAO,EAAE,YAAY,KAClB,SAAS,EAAE,EAAE,CAAC;AAEnB,KAAK,KAAK,CAAC,EAAE,IAAI,uBAAuB,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;AAGzD;;GAEG;AACH,qBAAa,YAAY,CAAC,EAAE;IAG1B;;OAEG;IACH,OAAO;IAIP;;;;;OAKG;IACH,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,YAAY,CAAC,EAAE,CAAC;IAIrC;;;;;;OAMG;IACH,KAAK,CAAC,MAAM,SAAS,aAAa,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,CAAC,EAAE,EAAE,MAAM,CAAC,GAAG,IAAI;IAE7F;;;;;;OAMG;IACH,KAAK,CAAC,UAAU,SAAS,MAAM,EAAE,OAAO,SAAS,qBAAqB,EACpE,aAAa,EAAE,gBAAgB,CAAC,UAAU,EAAE,OAAO,CAAC,EACpD,GAAG,EAAE,CACH,OAAO,EAAE,qBAAqB,CAAC,UAAU,EAAE,OAAO,CAAC,EACnD,OAAO,EAAE,YAAY,KAClB,SAAS,EAAE,EAAE,GACjB,IAAI;IAuCP;;;;;OAKG;IACH,cAAc,CAAC,GAAG,EAAE,UAAU,CAAC,EAAE,CAAC,GAAG,IAAI;CAK1C;AAED;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,EAAE,QAAQ,CAAC;IAC3C,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC;IAChD,QAAQ,CAAC,EAAE,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,SAAS,GAAG,0BAA0B,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;CACjG,CAUC,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
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 Event route declarations snapshotted by repository construction.
|
|
19
|
+
*/
|
|
20
|
+
export class EventRouting {
|
|
21
|
+
// prettier-ignore
|
|
22
|
+
/**
|
|
23
|
+
* Creates empty mutable Event route declarations.
|
|
24
|
+
*/
|
|
25
|
+
constructor() {
|
|
26
|
+
states.set(this, RoutingDeclarations.create());
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Creates empty Event route declarations.
|
|
30
|
+
*
|
|
31
|
+
* @typeParam Id Entity ID type used by the receiving repository.
|
|
32
|
+
* @returns Mutable Event route declarations.
|
|
33
|
+
*/
|
|
34
|
+
static create() {
|
|
35
|
+
return new EventRouting();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Registers an exact generated Event-schema route or a nominal message-interface route.
|
|
39
|
+
*
|
|
40
|
+
* A schema route receives its exact message shape. An interface route receives
|
|
41
|
+
* {@link InterfaceRouteMessage}, the member-message union intersected with
|
|
42
|
+
* the declared interface. Routing selects an exact schema route first, then
|
|
43
|
+
* the first matching interface token in registration order, then the
|
|
44
|
+
* replacement/default route.
|
|
45
|
+
*
|
|
46
|
+
* Copied or malformed tokens fail during declaration. Every token member must
|
|
47
|
+
* be registered by the repository, or construction fails. The selected route
|
|
48
|
+
* runs once for an accepted admission; durable replay uses stored targets and
|
|
49
|
+
* does not run routing again.
|
|
50
|
+
*
|
|
51
|
+
* @param schemaOrToken Generated Event schema or nominal message-interface token.
|
|
52
|
+
* @param via Route that calculates target Entity IDs.
|
|
53
|
+
* @returns These mutable route declarations.
|
|
54
|
+
*/
|
|
55
|
+
route(schemaOrToken, via) {
|
|
56
|
+
if (typeof via !== "function")
|
|
57
|
+
throw new TypeError("Event routing requires a route function.");
|
|
58
|
+
const state = EventRoutingInternals.state(this);
|
|
59
|
+
if (RoutingDeclarations.isInterfaceTokenCandidate(schemaOrToken)) {
|
|
60
|
+
RoutingDeclarations.routeInterface(state, schemaOrToken, via, "Event routing");
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
RoutingDeclarations.exact(state, schemaOrToken, via, "Event routing has a duplicate exact event route.");
|
|
64
|
+
}
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Replaces the producer-aware default Event route.
|
|
69
|
+
*
|
|
70
|
+
* @param via Route that calculates target Entity IDs.
|
|
71
|
+
* @returns These mutable route declarations.
|
|
72
|
+
*/
|
|
73
|
+
replaceDefault(via) {
|
|
74
|
+
if (typeof via !== "function")
|
|
75
|
+
throw new TypeError("Event routing requires a route function.");
|
|
76
|
+
RoutingDeclarations.default(EventRoutingInternals.state(this), via);
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Internal access to Event-routing declaration state.
|
|
82
|
+
*
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
export const EventRoutingInternals = Object.freeze({
|
|
86
|
+
state(routing) {
|
|
87
|
+
return states.get(routing);
|
|
88
|
+
},
|
|
89
|
+
snapshot(routing) {
|
|
90
|
+
if (routing === undefined) {
|
|
91
|
+
return RoutingDeclarations.snapshot(RoutingDeclarations.create());
|
|
92
|
+
}
|
|
93
|
+
return RoutingDeclarations.snapshot(EventRoutingInternals.state(routing));
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
//# sourceMappingURL=event-routing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-routing.js","sourceRoot":"","sources":["../../src/repository/event-routing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,E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