@effect/cluster 0.0.0-snapshot-d33d8b050b8e3c87dcde9587083e6c1cf733f72b
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/AtLeastOnce/package.json +6 -0
- package/AtLeastOnceStorage/package.json +6 -0
- package/Broadcaster/package.json +6 -0
- package/LICENSE +21 -0
- package/ManagerConfig/package.json +6 -0
- package/Message/package.json +6 -0
- package/MessageState/package.json +6 -0
- package/Messenger/package.json +6 -0
- package/Pod/package.json +6 -0
- package/PodAddress/package.json +6 -0
- package/Pods/package.json +6 -0
- package/PodsHealth/package.json +6 -0
- package/PoisonPill/package.json +6 -0
- package/README.md +3 -0
- package/RecipientAddress/package.json +6 -0
- package/RecipientBehaviour/package.json +6 -0
- package/RecipientBehaviourContext/package.json +6 -0
- package/RecipientType/package.json +6 -0
- package/Serialization/package.json +6 -0
- package/SerializedEnvelope/package.json +6 -0
- package/SerializedMessage/package.json +6 -0
- package/ShardId/package.json +6 -0
- package/ShardManager/package.json +6 -0
- package/ShardManagerClient/package.json +6 -0
- package/Sharding/package.json +6 -0
- package/ShardingConfig/package.json +6 -0
- package/ShardingEvent/package.json +6 -0
- package/ShardingException/package.json +6 -0
- package/ShardingRegistrationEvent/package.json +6 -0
- package/Storage/package.json +6 -0
- package/dist/cjs/AtLeastOnce.js +43 -0
- package/dist/cjs/AtLeastOnce.js.map +1 -0
- package/dist/cjs/AtLeastOnceStorage.js +48 -0
- package/dist/cjs/AtLeastOnceStorage.js.map +1 -0
- package/dist/cjs/Broadcaster.js +6 -0
- package/dist/cjs/Broadcaster.js.map +1 -0
- package/dist/cjs/ManagerConfig.js +57 -0
- package/dist/cjs/ManagerConfig.js.map +1 -0
- package/dist/cjs/Message.js +64 -0
- package/dist/cjs/Message.js.map +1 -0
- package/dist/cjs/MessageState.js +78 -0
- package/dist/cjs/MessageState.js.map +1 -0
- package/dist/cjs/Messenger.js +6 -0
- package/dist/cjs/Messenger.js.map +1 -0
- package/dist/cjs/Pod.js +101 -0
- package/dist/cjs/Pod.js.map +1 -0
- package/dist/cjs/PodAddress.js +100 -0
- package/dist/cjs/PodAddress.js.map +1 -0
- package/dist/cjs/Pods.js +58 -0
- package/dist/cjs/Pods.js.map +1 -0
- package/dist/cjs/PodsHealth.js +64 -0
- package/dist/cjs/PodsHealth.js.map +1 -0
- package/dist/cjs/PoisonPill.js +101 -0
- package/dist/cjs/PoisonPill.js.map +1 -0
- package/dist/cjs/RecipientAddress.js +102 -0
- package/dist/cjs/RecipientAddress.js.map +1 -0
- package/dist/cjs/RecipientBehaviour.js +61 -0
- package/dist/cjs/RecipientBehaviour.js.map +1 -0
- package/dist/cjs/RecipientBehaviourContext.js +87 -0
- package/dist/cjs/RecipientBehaviourContext.js.map +1 -0
- package/dist/cjs/RecipientType.js +142 -0
- package/dist/cjs/RecipientType.js.map +1 -0
- package/dist/cjs/Serialization.js +55 -0
- package/dist/cjs/Serialization.js.map +1 -0
- package/dist/cjs/SerializedEnvelope.js +111 -0
- package/dist/cjs/SerializedEnvelope.js.map +1 -0
- package/dist/cjs/SerializedMessage.js +87 -0
- package/dist/cjs/SerializedMessage.js.map +1 -0
- package/dist/cjs/ShardId.js +89 -0
- package/dist/cjs/ShardId.js.map +1 -0
- package/dist/cjs/ShardManager.js +48 -0
- package/dist/cjs/ShardManager.js.map +1 -0
- package/dist/cjs/ShardManagerClient.js +53 -0
- package/dist/cjs/ShardManagerClient.js.map +1 -0
- package/dist/cjs/Sharding.js +129 -0
- package/dist/cjs/Sharding.js.map +1 -0
- package/dist/cjs/ShardingConfig.js +64 -0
- package/dist/cjs/ShardingConfig.js.map +1 -0
- package/dist/cjs/ShardingEvent.js +72 -0
- package/dist/cjs/ShardingEvent.js.map +1 -0
- package/dist/cjs/ShardingException.js +130 -0
- package/dist/cjs/ShardingException.js.map +1 -0
- package/dist/cjs/ShardingRegistrationEvent.js +44 -0
- package/dist/cjs/ShardingRegistrationEvent.js.map +1 -0
- package/dist/cjs/Storage.js +63 -0
- package/dist/cjs/Storage.js.map +1 -0
- package/dist/cjs/index.js +88 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/internal/atLeastOnce.js +58 -0
- package/dist/cjs/internal/atLeastOnce.js.map +1 -0
- package/dist/cjs/internal/atLeastOnceStorage.js +186 -0
- package/dist/cjs/internal/atLeastOnceStorage.js.map +1 -0
- package/dist/cjs/internal/entityManager.js +191 -0
- package/dist/cjs/internal/entityManager.js.map +1 -0
- package/dist/cjs/internal/entityState.js +70 -0
- package/dist/cjs/internal/entityState.js.map +1 -0
- package/dist/cjs/internal/managerConfig.js +69 -0
- package/dist/cjs/internal/managerConfig.js.map +1 -0
- package/dist/cjs/internal/message.js +68 -0
- package/dist/cjs/internal/message.js.map +1 -0
- package/dist/cjs/internal/messageState.js +102 -0
- package/dist/cjs/internal/messageState.js.map +1 -0
- package/dist/cjs/internal/podWithMetadata.js +77 -0
- package/dist/cjs/internal/podWithMetadata.js.map +1 -0
- package/dist/cjs/internal/pods.js +58 -0
- package/dist/cjs/internal/pods.js.map +1 -0
- package/dist/cjs/internal/podsHealth.js +63 -0
- package/dist/cjs/internal/podsHealth.js.map +1 -0
- package/dist/cjs/internal/recipientBehaviour.js +75 -0
- package/dist/cjs/internal/recipientBehaviour.js.map +1 -0
- package/dist/cjs/internal/recipientBehaviourContext.js +59 -0
- package/dist/cjs/internal/recipientBehaviourContext.js.map +1 -0
- package/dist/cjs/internal/serialization.js +72 -0
- package/dist/cjs/internal/serialization.js.map +1 -0
- package/dist/cjs/internal/shardManager.js +291 -0
- package/dist/cjs/internal/shardManager.js.map +1 -0
- package/dist/cjs/internal/shardManagerClient.js +71 -0
- package/dist/cjs/internal/shardManagerClient.js.map +1 -0
- package/dist/cjs/internal/shardManagerState.js +67 -0
- package/dist/cjs/internal/shardManagerState.js.map +1 -0
- package/dist/cjs/internal/sharding.js +329 -0
- package/dist/cjs/internal/sharding.js.map +1 -0
- package/dist/cjs/internal/shardingConfig.js +79 -0
- package/dist/cjs/internal/shardingConfig.js.map +1 -0
- package/dist/cjs/internal/storage.js +75 -0
- package/dist/cjs/internal/storage.js.map +1 -0
- package/dist/cjs/internal/utils.js +92 -0
- package/dist/cjs/internal/utils.js.map +1 -0
- package/dist/dts/AtLeastOnce.d.ts +20 -0
- package/dist/dts/AtLeastOnce.d.ts.map +1 -0
- package/dist/dts/AtLeastOnceStorage.d.ts +75 -0
- package/dist/dts/AtLeastOnceStorage.d.ts.map +1 -0
- package/dist/dts/Broadcaster.d.ts +32 -0
- package/dist/dts/Broadcaster.d.ts.map +1 -0
- package/dist/dts/ManagerConfig.d.ts +61 -0
- package/dist/dts/ManagerConfig.d.ts.map +1 -0
- package/dist/dts/Message.d.ts +106 -0
- package/dist/dts/Message.d.ts.map +1 -0
- package/dist/dts/MessageState.d.ts +107 -0
- package/dist/dts/MessageState.d.ts.map +1 -0
- package/dist/dts/Messenger.d.ts +32 -0
- package/dist/dts/Messenger.d.ts.map +1 -0
- package/dist/dts/Pod.d.ts +81 -0
- package/dist/dts/Pod.d.ts.map +1 -0
- package/dist/dts/PodAddress.d.ts +80 -0
- package/dist/dts/PodAddress.d.ts.map +1 -0
- package/dist/dts/Pods.d.ts +78 -0
- package/dist/dts/Pods.d.ts.map +1 -0
- package/dist/dts/PodsHealth.d.ts +66 -0
- package/dist/dts/PodsHealth.d.ts.map +1 -0
- package/dist/dts/PoisonPill.d.ts +78 -0
- package/dist/dts/PoisonPill.d.ts.map +1 -0
- package/dist/dts/RecipientAddress.d.ts +57 -0
- package/dist/dts/RecipientAddress.d.ts.map +1 -0
- package/dist/dts/RecipientBehaviour.d.ts +72 -0
- package/dist/dts/RecipientBehaviour.d.ts.map +1 -0
- package/dist/dts/RecipientBehaviourContext.d.ts +83 -0
- package/dist/dts/RecipientBehaviourContext.d.ts.map +1 -0
- package/dist/dts/RecipientType.d.ts +96 -0
- package/dist/dts/RecipientType.d.ts.map +1 -0
- package/dist/dts/Serialization.d.ts +58 -0
- package/dist/dts/Serialization.d.ts.map +1 -0
- package/dist/dts/SerializedEnvelope.d.ts +87 -0
- package/dist/dts/SerializedEnvelope.d.ts.map +1 -0
- package/dist/dts/SerializedMessage.d.ts +66 -0
- package/dist/dts/SerializedMessage.d.ts.map +1 -0
- package/dist/dts/ShardId.d.ts +70 -0
- package/dist/dts/ShardId.d.ts.map +1 -0
- package/dist/dts/ShardManager.d.ts +44 -0
- package/dist/dts/ShardManager.d.ts.map +1 -0
- package/dist/dts/ShardManagerClient.d.ts +50 -0
- package/dist/dts/ShardManagerClient.d.ts.map +1 -0
- package/dist/dts/Sharding.d.ts +146 -0
- package/dist/dts/Sharding.d.ts.map +1 -0
- package/dist/dts/ShardingConfig.d.ts +69 -0
- package/dist/dts/ShardingConfig.d.ts.map +1 -0
- package/dist/dts/ShardingEvent.d.ts +90 -0
- package/dist/dts/ShardingEvent.d.ts.map +1 -0
- package/dist/dts/ShardingException.d.ts +125 -0
- package/dist/dts/ShardingException.d.ts.map +1 -0
- package/dist/dts/ShardingRegistrationEvent.d.ts +44 -0
- package/dist/dts/ShardingRegistrationEvent.d.ts.map +1 -0
- package/dist/dts/Storage.d.ts +78 -0
- package/dist/dts/Storage.d.ts.map +1 -0
- package/dist/dts/index.d.ts +113 -0
- package/dist/dts/index.d.ts.map +1 -0
- package/dist/dts/internal/atLeastOnce.d.ts +2 -0
- package/dist/dts/internal/atLeastOnce.d.ts.map +1 -0
- package/dist/dts/internal/atLeastOnceStorage.d.ts +2 -0
- package/dist/dts/internal/atLeastOnceStorage.d.ts.map +1 -0
- package/dist/dts/internal/entityManager.d.ts +2 -0
- package/dist/dts/internal/entityManager.d.ts.map +1 -0
- package/dist/dts/internal/entityState.d.ts +21 -0
- package/dist/dts/internal/entityState.d.ts.map +1 -0
- package/dist/dts/internal/managerConfig.d.ts +2 -0
- package/dist/dts/internal/managerConfig.d.ts.map +1 -0
- package/dist/dts/internal/message.d.ts +9 -0
- package/dist/dts/internal/message.d.ts.map +1 -0
- package/dist/dts/internal/messageState.d.ts +2 -0
- package/dist/dts/internal/messageState.d.ts.map +1 -0
- package/dist/dts/internal/podWithMetadata.d.ts +2 -0
- package/dist/dts/internal/podWithMetadata.d.ts.map +1 -0
- package/dist/dts/internal/pods.d.ts +2 -0
- package/dist/dts/internal/pods.d.ts.map +1 -0
- package/dist/dts/internal/podsHealth.d.ts +2 -0
- package/dist/dts/internal/podsHealth.d.ts.map +1 -0
- package/dist/dts/internal/recipientBehaviour.d.ts +2 -0
- package/dist/dts/internal/recipientBehaviour.d.ts.map +1 -0
- package/dist/dts/internal/recipientBehaviourContext.d.ts +2 -0
- package/dist/dts/internal/recipientBehaviourContext.d.ts.map +1 -0
- package/dist/dts/internal/serialization.d.ts +2 -0
- package/dist/dts/internal/serialization.d.ts.map +1 -0
- package/dist/dts/internal/shardManager.d.ts +12 -0
- package/dist/dts/internal/shardManager.d.ts.map +1 -0
- package/dist/dts/internal/shardManagerClient.d.ts +2 -0
- package/dist/dts/internal/shardManagerClient.d.ts.map +1 -0
- package/dist/dts/internal/shardManagerState.d.ts +26 -0
- package/dist/dts/internal/shardManagerState.d.ts.map +1 -0
- package/dist/dts/internal/sharding.d.ts +2 -0
- package/dist/dts/internal/sharding.d.ts.map +1 -0
- package/dist/dts/internal/shardingConfig.d.ts +2 -0
- package/dist/dts/internal/shardingConfig.d.ts.map +1 -0
- package/dist/dts/internal/storage.d.ts +2 -0
- package/dist/dts/internal/storage.d.ts.map +1 -0
- package/dist/dts/internal/utils.d.ts +2 -0
- package/dist/dts/internal/utils.d.ts.map +1 -0
- package/dist/esm/AtLeastOnce.js +12 -0
- package/dist/esm/AtLeastOnce.js.map +1 -0
- package/dist/esm/AtLeastOnceStorage.js +17 -0
- package/dist/esm/AtLeastOnceStorage.js.map +1 -0
- package/dist/esm/Broadcaster.js +2 -0
- package/dist/esm/Broadcaster.js.map +1 -0
- package/dist/esm/ManagerConfig.js +26 -0
- package/dist/esm/ManagerConfig.js.map +1 -0
- package/dist/esm/Message.js +33 -0
- package/dist/esm/Message.js.map +1 -0
- package/dist/esm/MessageState.js +47 -0
- package/dist/esm/MessageState.js.map +1 -0
- package/dist/esm/Messenger.js +2 -0
- package/dist/esm/Messenger.js.map +1 -0
- package/dist/esm/Pod.js +65 -0
- package/dist/esm/Pod.js.map +1 -0
- package/dist/esm/PodAddress.js +64 -0
- package/dist/esm/PodAddress.js.map +1 -0
- package/dist/esm/Pods.js +27 -0
- package/dist/esm/Pods.js.map +1 -0
- package/dist/esm/PodsHealth.js +33 -0
- package/dist/esm/PodsHealth.js.map +1 -0
- package/dist/esm/PoisonPill.js +65 -0
- package/dist/esm/PoisonPill.js.map +1 -0
- package/dist/esm/RecipientAddress.js +67 -0
- package/dist/esm/RecipientAddress.js.map +1 -0
- package/dist/esm/RecipientBehaviour.js +30 -0
- package/dist/esm/RecipientBehaviour.js.map +1 -0
- package/dist/esm/RecipientBehaviourContext.js +56 -0
- package/dist/esm/RecipientBehaviourContext.js.map +1 -0
- package/dist/esm/RecipientType.js +105 -0
- package/dist/esm/RecipientType.js.map +1 -0
- package/dist/esm/Serialization.js +24 -0
- package/dist/esm/Serialization.js.map +1 -0
- package/dist/esm/SerializedEnvelope.js +75 -0
- package/dist/esm/SerializedEnvelope.js.map +1 -0
- package/dist/esm/SerializedMessage.js +51 -0
- package/dist/esm/SerializedMessage.js.map +1 -0
- package/dist/esm/ShardId.js +54 -0
- package/dist/esm/ShardId.js.map +1 -0
- package/dist/esm/ShardManager.js +17 -0
- package/dist/esm/ShardManager.js.map +1 -0
- package/dist/esm/ShardManagerClient.js +22 -0
- package/dist/esm/ShardManagerClient.js.map +1 -0
- package/dist/esm/Sharding.js +98 -0
- package/dist/esm/Sharding.js.map +1 -0
- package/dist/esm/ShardingConfig.js +33 -0
- package/dist/esm/ShardingConfig.js.map +1 -0
- package/dist/esm/ShardingEvent.js +62 -0
- package/dist/esm/ShardingEvent.js.map +1 -0
- package/dist/esm/ShardingException.js +91 -0
- package/dist/esm/ShardingException.js.map +1 -0
- package/dist/esm/ShardingRegistrationEvent.js +36 -0
- package/dist/esm/ShardingRegistrationEvent.js.map +1 -0
- package/dist/esm/Storage.js +32 -0
- package/dist/esm/Storage.js.map +1 -0
- package/dist/esm/index.js +113 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal/atLeastOnce.js +26 -0
- package/dist/esm/internal/atLeastOnce.js.map +1 -0
- package/dist/esm/internal/atLeastOnceStorage.js +154 -0
- package/dist/esm/internal/atLeastOnceStorage.js.map +1 -0
- package/dist/esm/internal/entityManager.js +159 -0
- package/dist/esm/internal/entityManager.js.map +1 -0
- package/dist/esm/internal/entityState.js +35 -0
- package/dist/esm/internal/entityState.js.map +1 -0
- package/dist/esm/internal/managerConfig.js +38 -0
- package/dist/esm/internal/managerConfig.js.map +1 -0
- package/dist/esm/internal/message.js +32 -0
- package/dist/esm/internal/message.js.map +1 -0
- package/dist/esm/internal/messageState.js +66 -0
- package/dist/esm/internal/messageState.js.map +1 -0
- package/dist/esm/internal/podWithMetadata.js +41 -0
- package/dist/esm/internal/podWithMetadata.js.map +1 -0
- package/dist/esm/internal/pods.js +25 -0
- package/dist/esm/internal/pods.js.map +1 -0
- package/dist/esm/internal/podsHealth.js +30 -0
- package/dist/esm/internal/podsHealth.js.map +1 -0
- package/dist/esm/internal/recipientBehaviour.js +42 -0
- package/dist/esm/internal/recipientBehaviour.js.map +1 -0
- package/dist/esm/internal/recipientBehaviourContext.js +26 -0
- package/dist/esm/internal/recipientBehaviourContext.js.map +1 -0
- package/dist/esm/internal/serialization.js +39 -0
- package/dist/esm/internal/serialization.js.map +1 -0
- package/dist/esm/internal/shardManager.js +256 -0
- package/dist/esm/internal/shardManager.js.map +1 -0
- package/dist/esm/internal/shardManagerClient.js +38 -0
- package/dist/esm/internal/shardManagerClient.js.map +1 -0
- package/dist/esm/internal/shardManagerState.js +36 -0
- package/dist/esm/internal/shardManagerState.js.map +1 -0
- package/dist/esm/internal/sharding.js +288 -0
- package/dist/esm/internal/sharding.js.map +1 -0
- package/dist/esm/internal/shardingConfig.js +47 -0
- package/dist/esm/internal/shardingConfig.js.map +1 -0
- package/dist/esm/internal/storage.js +42 -0
- package/dist/esm/internal/storage.js.map +1 -0
- package/dist/esm/internal/utils.js +56 -0
- package/dist/esm/internal/utils.js.map +1 -0
- package/dist/esm/package.json +4 -0
- package/package.json +259 -0
- package/src/AtLeastOnce.ts +28 -0
- package/src/AtLeastOnceStorage.ts +96 -0
- package/src/Broadcaster.ts +48 -0
- package/src/ManagerConfig.ts +67 -0
- package/src/Message.ts +132 -0
- package/src/MessageState.ts +126 -0
- package/src/Messenger.ts +40 -0
- package/src/Pod.ts +95 -0
- package/src/PodAddress.ts +94 -0
- package/src/Pods.ts +100 -0
- package/src/PodsHealth.ts +74 -0
- package/src/PoisonPill.ts +105 -0
- package/src/RecipientAddress.ts +72 -0
- package/src/RecipientBehaviour.ts +108 -0
- package/src/RecipientBehaviourContext.ts +101 -0
- package/src/RecipientType.ts +134 -0
- package/src/Serialization.ts +72 -0
- package/src/SerializedEnvelope.ts +109 -0
- package/src/SerializedMessage.ts +82 -0
- package/src/ShardId.ts +79 -0
- package/src/ShardManager.ts +53 -0
- package/src/ShardManagerClient.ts +57 -0
- package/src/Sharding.ts +214 -0
- package/src/ShardingConfig.ts +76 -0
- package/src/ShardingEvent.ts +121 -0
- package/src/ShardingException.ts +151 -0
- package/src/ShardingRegistrationEvent.ts +62 -0
- package/src/Storage.ts +92 -0
- package/src/index.ts +139 -0
- package/src/internal/atLeastOnce.ts +59 -0
- package/src/internal/atLeastOnceStorage.ts +218 -0
- package/src/internal/entityManager.ts +404 -0
- package/src/internal/entityState.ts +64 -0
- package/src/internal/managerConfig.ts +84 -0
- package/src/internal/message.ts +64 -0
- package/src/internal/messageState.ts +98 -0
- package/src/internal/podWithMetadata.ts +72 -0
- package/src/internal/pods.ts +29 -0
- package/src/internal/podsHealth.ts +39 -0
- package/src/internal/recipientBehaviour.ts +133 -0
- package/src/internal/recipientBehaviourContext.ts +70 -0
- package/src/internal/serialization.ts +59 -0
- package/src/internal/shardManager.ts +593 -0
- package/src/internal/shardManagerClient.ts +49 -0
- package/src/internal/shardManagerState.ts +80 -0
- package/src/internal/sharding.ts +793 -0
- package/src/internal/shardingConfig.ts +97 -0
- package/src/internal/storage.ts +60 -0
- package/src/internal/utils.ts +54 -0
@@ -0,0 +1,108 @@
|
|
1
|
+
/**
|
2
|
+
* @since 1.0.0
|
3
|
+
*/
|
4
|
+
import type * as Message from "@effect/cluster/Message"
|
5
|
+
import type * as Duration from "effect/Duration"
|
6
|
+
import type * as Effect from "effect/Effect"
|
7
|
+
import type * as Option from "effect/Option"
|
8
|
+
import type * as Queue from "effect/Queue"
|
9
|
+
import type * as Ref from "effect/Ref"
|
10
|
+
import type * as Scope from "effect/Scope"
|
11
|
+
import * as internal from "./internal/recipientBehaviour.js"
|
12
|
+
import type * as MessageState from "./MessageState.js"
|
13
|
+
import type * as PoisonPill from "./PoisonPill.js"
|
14
|
+
import type * as RecipientBehaviourContext from "./RecipientBehaviourContext.js"
|
15
|
+
import type * as ShardingException from "./ShardingException.js"
|
16
|
+
|
17
|
+
/**
|
18
|
+
* A RecipientBehaviour describes how a specific RecipientType should behave.
|
19
|
+
* This is the actual implementation of what an entity should do upon receiving a Msg,
|
20
|
+
* this could require additional context.
|
21
|
+
*
|
22
|
+
* The scope provided in the context is controlled by the cluster EntityManager,
|
23
|
+
* and is used to request the shoutdown of the entity,
|
24
|
+
* so you can safely scope whatever resource you want to use for your behaviour
|
25
|
+
* and the EntityManager will close the scope for you when the entity is shoutdown.
|
26
|
+
*
|
27
|
+
* The function returned by the RecipientBehaviour effect is what we call "offer" effect.
|
28
|
+
* The offer effect is used by the EntityManager to give messages to the RecipientBehaviour.
|
29
|
+
*
|
30
|
+
* @since 1.0.0
|
31
|
+
* @category models
|
32
|
+
*/
|
33
|
+
export interface RecipientBehaviour<Msg, R> extends
|
34
|
+
Effect.Effect<
|
35
|
+
<A extends Msg>(
|
36
|
+
message: A
|
37
|
+
) => Effect.Effect<
|
38
|
+
MessageState.MessageState<Message.Message.Exit<A>>,
|
39
|
+
ShardingException.ExceptionWhileOfferingMessageException
|
40
|
+
>,
|
41
|
+
never,
|
42
|
+
R | RecipientBehaviourContext.RecipientBehaviourContext | Scope.Scope
|
43
|
+
>
|
44
|
+
{}
|
45
|
+
|
46
|
+
/**
|
47
|
+
* This are the options for an EntityBehaviour. This controls the entityMaxIdleTime,
|
48
|
+
* check out more on that over the ShardingConfig.
|
49
|
+
* This allows to override the setting for a specific entity.
|
50
|
+
*
|
51
|
+
* @since 1.0.0
|
52
|
+
* @category utils
|
53
|
+
*/
|
54
|
+
export type EntityBehaviourOptions = {
|
55
|
+
entityMaxIdleTime?: Option.Option<Duration.Duration>
|
56
|
+
}
|
57
|
+
|
58
|
+
/**
|
59
|
+
* This is the simplest behaviour you can have.
|
60
|
+
* You provide a function that given the entityId and the message, it will immediatly process it.
|
61
|
+
* You are then required to return a MessageState to tell the caller
|
62
|
+
* if the message has just arrived and will be later processed or it has been processed.
|
63
|
+
*
|
64
|
+
* @since 1.0.0
|
65
|
+
* @category utils
|
66
|
+
*/
|
67
|
+
export const fromFunctionEffect: <Msg extends Message.Message.Any, R>(
|
68
|
+
handler: (
|
69
|
+
entityId: string,
|
70
|
+
message: Msg
|
71
|
+
) => Effect.Effect<MessageState.MessageState<Message.Message.Exit<Msg>>, never, R>
|
72
|
+
) => RecipientBehaviour<Msg, R> = internal.fromFunctionEffect
|
73
|
+
|
74
|
+
/**
|
75
|
+
* This is a stateful version of fromFunctionEffect.
|
76
|
+
* You can provide a function to get the initialState, and then it will be passed as Ref.
|
77
|
+
* Everything here is just stored in memory, so eventual persistence of the state is up to you!
|
78
|
+
*
|
79
|
+
* @since 1.0.0
|
80
|
+
* @category utils
|
81
|
+
*/
|
82
|
+
export const fromFunctionEffectStateful: <S, R, Msg extends Message.Message.Any, R2>(
|
83
|
+
initialState: (entityId: string) => Effect.Effect<S, never, R>,
|
84
|
+
handler: (
|
85
|
+
entityId: string,
|
86
|
+
message: Msg,
|
87
|
+
stateRef: Ref.Ref<S>
|
88
|
+
) => Effect.Effect<MessageState.MessageState<Message.Message.Exit<Msg>>, never, R2>
|
89
|
+
) => RecipientBehaviour<Msg, R | R2> = internal.fromFunctionEffectStateful
|
90
|
+
|
91
|
+
/**
|
92
|
+
* This behaviour uses a Queue where the entity will accumulate messages to be processed,
|
93
|
+
* and then you can use the Dequeue to take messages and process them.
|
94
|
+
* A PoisonPill is provided to request interruption of the entity behaviour.
|
95
|
+
*
|
96
|
+
* @since 1.0.0
|
97
|
+
* @category utils
|
98
|
+
*/
|
99
|
+
export const fromInMemoryQueue: <Msg extends Message.Message.Any, R>(
|
100
|
+
handler: (
|
101
|
+
entityId: string,
|
102
|
+
dequeue: Queue.Dequeue<Msg | PoisonPill.PoisonPill>,
|
103
|
+
processed: <A extends Msg>(
|
104
|
+
message: A,
|
105
|
+
value: Option.Option<Message.Message.Exit<A>>
|
106
|
+
) => Effect.Effect<void, never, never>
|
107
|
+
) => Effect.Effect<void, never, R>
|
108
|
+
) => RecipientBehaviour<Msg, R> = internal.fromInMemoryQueue
|
@@ -0,0 +1,101 @@
|
|
1
|
+
/**
|
2
|
+
* @since 1.0.0
|
3
|
+
*/
|
4
|
+
import type * as Context from "effect/Context"
|
5
|
+
import type * as Effect from "effect/Effect"
|
6
|
+
import * as internal from "./internal/recipientBehaviourContext.js"
|
7
|
+
import type * as Message from "./Message.js"
|
8
|
+
import type * as RecipientAddress from "./RecipientAddress.js"
|
9
|
+
import type * as RecipientType from "./RecipientType.js"
|
10
|
+
import type * as ShardId from "./ShardId.js"
|
11
|
+
|
12
|
+
/**
|
13
|
+
* @since 1.0.0
|
14
|
+
* @category symbols
|
15
|
+
*/
|
16
|
+
export const RecipientBehaviourContextTypeId: unique symbol = internal.RecipientBehaviourContextTypeId
|
17
|
+
|
18
|
+
/**
|
19
|
+
* @since 1.0.0
|
20
|
+
* @category symbols
|
21
|
+
*/
|
22
|
+
export type RecipientBehaviourContextTypeId = typeof RecipientBehaviourContextTypeId
|
23
|
+
|
24
|
+
/**
|
25
|
+
* This is the context information that is available to the RecipientBehaviour and has general informations
|
26
|
+
* about this specific entity, like the entityId or the recipientType.
|
27
|
+
*
|
28
|
+
* @since 1.0.0
|
29
|
+
* @category models
|
30
|
+
*/
|
31
|
+
export interface RecipientBehaviourContext {
|
32
|
+
readonly [RecipientBehaviourContextTypeId]: RecipientBehaviourContextTypeId
|
33
|
+
readonly recipientAddress: RecipientAddress.RecipientAddress
|
34
|
+
readonly shardId: ShardId.ShardId
|
35
|
+
readonly recipientType: RecipientType.RecipientType<Message.Message.Any>
|
36
|
+
readonly forkShutdown: Effect.Effect<void>
|
37
|
+
}
|
38
|
+
|
39
|
+
/**
|
40
|
+
* A tag to access current RecipientBehaviourContext
|
41
|
+
*
|
42
|
+
* @since 1.0.0
|
43
|
+
* @category context
|
44
|
+
*/
|
45
|
+
export const RecipientBehaviourContext: Context.Tag<RecipientBehaviourContext, RecipientBehaviourContext> =
|
46
|
+
internal.recipientBehaviourContextTag
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Creates a new RecipientBehaviourContext
|
50
|
+
*
|
51
|
+
* @since 1.0.0
|
52
|
+
* @category constructors
|
53
|
+
*/
|
54
|
+
export const make: (
|
55
|
+
args: Omit<RecipientBehaviourContext, typeof RecipientBehaviourContextTypeId>
|
56
|
+
) => RecipientBehaviourContext = internal.make
|
57
|
+
|
58
|
+
/**
|
59
|
+
* Gets the current entityId
|
60
|
+
*
|
61
|
+
* @since 1.0.0
|
62
|
+
* @category utils
|
63
|
+
*/
|
64
|
+
export const entityId: Effect.Effect<string, never, RecipientBehaviourContext> = internal.entityId
|
65
|
+
|
66
|
+
/**
|
67
|
+
* Gets the current entityId
|
68
|
+
*
|
69
|
+
* @since 1.0.0
|
70
|
+
* @category utils
|
71
|
+
*/
|
72
|
+
export const recipientAddress: Effect.Effect<RecipientAddress.RecipientAddress, never, RecipientBehaviourContext> =
|
73
|
+
internal.recipientAddress
|
74
|
+
|
75
|
+
/**
|
76
|
+
* Gets the current shardId
|
77
|
+
*
|
78
|
+
* @since 1.0.0
|
79
|
+
* @category utils
|
80
|
+
*/
|
81
|
+
export const shardId: Effect.Effect<ShardId.ShardId, never, RecipientBehaviourContext> = internal.shardId
|
82
|
+
|
83
|
+
/**
|
84
|
+
* Gets the current recipientType
|
85
|
+
*
|
86
|
+
* @since 1.0.0
|
87
|
+
* @category utils
|
88
|
+
*/
|
89
|
+
export const recipientType: Effect.Effect<
|
90
|
+
RecipientType.RecipientType<Message.Message.Any>,
|
91
|
+
never,
|
92
|
+
RecipientBehaviourContext
|
93
|
+
> = internal.recipientType
|
94
|
+
|
95
|
+
/**
|
96
|
+
* Forks the shutdown of the current recipient behaviour as soon as possible.
|
97
|
+
*
|
98
|
+
* @since 1.0.0
|
99
|
+
* @category utils
|
100
|
+
*/
|
101
|
+
export const forkShutdown: Effect.Effect<void, never, RecipientBehaviourContext> = internal.forkShutdown
|
@@ -0,0 +1,134 @@
|
|
1
|
+
/**
|
2
|
+
* @since 1.0.0
|
3
|
+
*/
|
4
|
+
import type * as Schema from "@effect/schema/Schema"
|
5
|
+
import * as Data from "effect/Data"
|
6
|
+
import * as Equal from "effect/Equal"
|
7
|
+
import * as Hash from "effect/Hash"
|
8
|
+
import type * as Message from "./Message.js"
|
9
|
+
import * as ShardId from "./ShardId.js"
|
10
|
+
|
11
|
+
const RecipientTypeSymbolKey = "@effect/cluster/RecipientType"
|
12
|
+
|
13
|
+
/**
|
14
|
+
* @since 1.0.0
|
15
|
+
* @category symbols
|
16
|
+
*/
|
17
|
+
export const RecipientTypeTypeId: unique symbol = Symbol.for(RecipientTypeSymbolKey)
|
18
|
+
|
19
|
+
/**
|
20
|
+
* An EntityType is a RecipientType that is ensured to be alive only on a single Pod at a time.
|
21
|
+
*
|
22
|
+
* @since 1.0.0
|
23
|
+
* @category models
|
24
|
+
*/
|
25
|
+
export class EntityType<Msg extends Message.Message.Any> extends Data.TaggedClass("EntityType")<{
|
26
|
+
readonly name: string
|
27
|
+
readonly schema: Schema.Schema<Msg, unknown>
|
28
|
+
}> {
|
29
|
+
/**
|
30
|
+
* @since 1.0.0
|
31
|
+
*/
|
32
|
+
readonly [RecipientTypeTypeId] = RecipientTypeTypeId;
|
33
|
+
|
34
|
+
/**
|
35
|
+
* @since 1.0.0
|
36
|
+
*/
|
37
|
+
[Hash.symbol](): number {
|
38
|
+
return Hash.structure({ _tag: this._tag, name: this.name })
|
39
|
+
}
|
40
|
+
|
41
|
+
/**
|
42
|
+
* @since 1.0.0
|
43
|
+
*/
|
44
|
+
[Equal.symbol](this: TopicType<Msg>, that: Equal.Equal): boolean {
|
45
|
+
if (isRecipientType(that)) {
|
46
|
+
return this._tag === that._tag && this.name === that.name
|
47
|
+
}
|
48
|
+
return false
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
/**
|
53
|
+
* A TopicType can live on multiple Pods at the same time.
|
54
|
+
*
|
55
|
+
* @since 1.0.0
|
56
|
+
* @category models
|
57
|
+
*/
|
58
|
+
export class TopicType<Msg extends Message.Message.Any> extends Data.TaggedClass("TopicType")<{
|
59
|
+
readonly name: string
|
60
|
+
readonly schema: Schema.Schema<Msg, unknown>
|
61
|
+
}> {
|
62
|
+
/**
|
63
|
+
* @since 1.0.0
|
64
|
+
*/
|
65
|
+
readonly [RecipientTypeTypeId] = RecipientTypeTypeId;
|
66
|
+
|
67
|
+
/**
|
68
|
+
* @since 1.0.0
|
69
|
+
*/
|
70
|
+
[Hash.symbol](): number {
|
71
|
+
return Hash.structure({ _tag: this._tag, name: this.name })
|
72
|
+
}
|
73
|
+
|
74
|
+
/**
|
75
|
+
* @since 1.0.0
|
76
|
+
*/
|
77
|
+
[Equal.symbol](this: EntityType<Msg>, that: Equal.Equal): boolean {
|
78
|
+
if (isRecipientType(that)) {
|
79
|
+
return this._tag === that._tag && this.name === that.name
|
80
|
+
}
|
81
|
+
return false
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
/**
|
86
|
+
* A RecipientType is basically a pointer to a logical grouping of multiple enties having the same RecipientBehaviour.
|
87
|
+
* This value is required to be able to message with an entity/topic since it holds the Schema for the messages over the wire.
|
88
|
+
* Without the schema, you cannot ensure that the messages sent are what the receiver expects.
|
89
|
+
* Ideally, you can share this definition between the caller and the receiver.
|
90
|
+
*
|
91
|
+
* @since 1.0.0
|
92
|
+
* @category models
|
93
|
+
*/
|
94
|
+
export type RecipientType<Msg extends Message.Message.Any> = EntityType<Msg> | TopicType<Msg>
|
95
|
+
|
96
|
+
/**
|
97
|
+
* Ensure that given value is a RecipientType
|
98
|
+
* @since 1.0.0
|
99
|
+
* @category constructors
|
100
|
+
*/
|
101
|
+
export function isRecipientType<A extends Message.Message.Any>(value: unknown): value is RecipientType<A> {
|
102
|
+
return typeof value === "object" && value !== null && RecipientTypeTypeId in value &&
|
103
|
+
value[RecipientTypeTypeId] === RecipientTypeTypeId
|
104
|
+
}
|
105
|
+
|
106
|
+
/**
|
107
|
+
* Given a name and a schema for the protocol, constructs an EntityType.
|
108
|
+
*
|
109
|
+
* @since 1.0.0
|
110
|
+
* @category constructors
|
111
|
+
*/
|
112
|
+
export function makeEntityType<Msg extends Message.Message.Any, I>(
|
113
|
+
name: string,
|
114
|
+
schema: Schema.Schema<Msg, I>
|
115
|
+
): EntityType<Msg> {
|
116
|
+
return new EntityType({ name, schema: schema as any })
|
117
|
+
}
|
118
|
+
|
119
|
+
/**
|
120
|
+
* Given a name and a schema for the protocol, constructs an TopicType.
|
121
|
+
*
|
122
|
+
* @since 1.0.0
|
123
|
+
* @category constructors
|
124
|
+
*/
|
125
|
+
export function makeTopicType<Msg extends Message.Message.Any, I>(
|
126
|
+
name: string,
|
127
|
+
schema: Schema.Schema<Msg, I>
|
128
|
+
): TopicType<Msg> {
|
129
|
+
return new TopicType({ name, schema: schema as any })
|
130
|
+
}
|
131
|
+
|
132
|
+
/** @internal */
|
133
|
+
export const getShardId = (entityId: string, numberOfShards: number): ShardId.ShardId =>
|
134
|
+
ShardId.make(Math.abs(Hash.string(entityId) % numberOfShards) + 1)
|
@@ -0,0 +1,72 @@
|
|
1
|
+
/**
|
2
|
+
* @since 1.0.0
|
3
|
+
*/
|
4
|
+
import type * as Schema from "@effect/schema/Schema"
|
5
|
+
import type * as Context from "effect/Context"
|
6
|
+
import type * as Effect from "effect/Effect"
|
7
|
+
import type * as Layer from "effect/Layer"
|
8
|
+
import * as internal from "./internal/serialization.js"
|
9
|
+
import type * as SerializedMessage from "./SerializedMessage.js"
|
10
|
+
import type * as ShardingException from "./ShardingException.js"
|
11
|
+
|
12
|
+
/**
|
13
|
+
* @since 1.0.0
|
14
|
+
* @category symbols
|
15
|
+
*/
|
16
|
+
export const SerializationTypeId: unique symbol = internal.SerializationTypeId
|
17
|
+
|
18
|
+
/**
|
19
|
+
* @since 1.0.0
|
20
|
+
* @category symbols
|
21
|
+
*/
|
22
|
+
export type SerializationTypeId = typeof SerializationTypeId
|
23
|
+
|
24
|
+
/**
|
25
|
+
* An interface to serialize user messages that will be sent between pods.
|
26
|
+
* @since 1.0.0
|
27
|
+
* @category models
|
28
|
+
*/
|
29
|
+
export interface Serialization {
|
30
|
+
/**
|
31
|
+
* @since 1.0.0
|
32
|
+
*/
|
33
|
+
readonly [SerializationTypeId]: SerializationTypeId
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Transforms the given message into binary
|
37
|
+
* @since 1.0.0
|
38
|
+
*/
|
39
|
+
readonly encode: <A, I>(
|
40
|
+
schema: Schema.Schema<A, I>,
|
41
|
+
message: A
|
42
|
+
) => Effect.Effect<SerializedMessage.SerializedMessage, ShardingException.SerializationException>
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Transform binary back into the given type
|
46
|
+
* @since 1.0.0
|
47
|
+
*/
|
48
|
+
readonly decode: <A, I>(
|
49
|
+
schema: Schema.Schema<A, I>,
|
50
|
+
bytes: SerializedMessage.SerializedMessage
|
51
|
+
) => Effect.Effect<A, ShardingException.SerializationException>
|
52
|
+
}
|
53
|
+
|
54
|
+
/**
|
55
|
+
* @since 1.0.0
|
56
|
+
* @category context
|
57
|
+
*/
|
58
|
+
export const Serialization: Context.Tag<Serialization, Serialization> = internal.serializationTag
|
59
|
+
|
60
|
+
/**
|
61
|
+
* @since 1.0.0
|
62
|
+
* @category constructors
|
63
|
+
*/
|
64
|
+
export const make: (args: Omit<Serialization, typeof SerializationTypeId>) => Serialization = internal.make
|
65
|
+
|
66
|
+
/**
|
67
|
+
* A layer that uses JSON serialization for encoding and decoding messages.
|
68
|
+
* This is useful for testing and not recommended to use in production.
|
69
|
+
* @since 1.0.0
|
70
|
+
* @category layers
|
71
|
+
*/
|
72
|
+
export const json: Layer.Layer<Serialization> = internal.json
|
@@ -0,0 +1,109 @@
|
|
1
|
+
/**
|
2
|
+
* @since 1.0.0
|
3
|
+
*/
|
4
|
+
import * as Schema from "@effect/schema/Schema"
|
5
|
+
import * as Serializable from "@effect/schema/Serializable"
|
6
|
+
import * as PrimaryKey from "effect/PrimaryKey"
|
7
|
+
import { TypeIdSchema } from "./internal/utils.js"
|
8
|
+
import * as RecipientAddress from "./RecipientAddress.js"
|
9
|
+
import * as SerializedMessage from "./SerializedMessage.js"
|
10
|
+
|
11
|
+
/** @internal */
|
12
|
+
const SerializedEnvelopeSymbolKey = "@effect/cluster/SerializedEnvelope"
|
13
|
+
|
14
|
+
/**
|
15
|
+
* @since 1.0.0
|
16
|
+
* @category symbols
|
17
|
+
*/
|
18
|
+
export const SerializedEnvelopeTypeId: unique symbol = Symbol.for(SerializedEnvelopeSymbolKey)
|
19
|
+
|
20
|
+
/** @internal */
|
21
|
+
const SerializedEnvelopeTypeIdSchema = TypeIdSchema(SerializedEnvelopeSymbolKey, SerializedEnvelopeTypeId)
|
22
|
+
|
23
|
+
/**
|
24
|
+
* @since 1.0.0
|
25
|
+
* @category symbols
|
26
|
+
*/
|
27
|
+
export type SerializedEnvelopeTypeId = typeof SerializedEnvelopeTypeId
|
28
|
+
|
29
|
+
/**
|
30
|
+
* A SerializedEnvelope is the message that goes over the wire between pods.
|
31
|
+
* Inside the Envelope, you have the encoded messages, plus some informations on where it should be routed to.
|
32
|
+
*
|
33
|
+
* @since 1.0.0
|
34
|
+
* @category models
|
35
|
+
*/
|
36
|
+
export class SerializedEnvelope extends Schema.Class<SerializedEnvelope>(SerializedEnvelopeSymbolKey)({
|
37
|
+
[SerializedEnvelopeTypeId]: Schema.propertySignature(SerializedEnvelopeTypeIdSchema).pipe(
|
38
|
+
Schema.fromKey(SerializedEnvelopeSymbolKey)
|
39
|
+
),
|
40
|
+
recipientAddress: RecipientAddress.RecipientAddress,
|
41
|
+
messageId: Schema.String,
|
42
|
+
body: SerializedMessage.schema
|
43
|
+
}) {
|
44
|
+
get [Serializable.symbol]() {
|
45
|
+
return this.constructor
|
46
|
+
}
|
47
|
+
get [Serializable.symbolResult]() {
|
48
|
+
return { Success: Schema.Void, Failure: Schema.Never }
|
49
|
+
}
|
50
|
+
get [PrimaryKey.symbol]() {
|
51
|
+
return this.messageId + "@" + this.recipientAddress.recipientTypeName + "#" + this.recipientAddress.entityId
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
/**
|
56
|
+
* @since 1.0.0
|
57
|
+
* @category models
|
58
|
+
*/
|
59
|
+
export namespace SerializedEnvelope {
|
60
|
+
/**
|
61
|
+
* @since 1.0.0
|
62
|
+
* @category models
|
63
|
+
*/
|
64
|
+
export interface Encoded extends Schema.Schema.Encoded<typeof SerializedEnvelope> {}
|
65
|
+
}
|
66
|
+
|
67
|
+
/**
|
68
|
+
* Construct a new `SerializedEnvelope`
|
69
|
+
*
|
70
|
+
* @since 1.0.0
|
71
|
+
* @category constructors
|
72
|
+
*/
|
73
|
+
export function make(
|
74
|
+
recipientAddress: RecipientAddress.RecipientAddress,
|
75
|
+
messageId: string,
|
76
|
+
body: SerializedMessage.SerializedMessage
|
77
|
+
): SerializedEnvelope {
|
78
|
+
return new SerializedEnvelope({
|
79
|
+
[SerializedEnvelopeTypeId]: SerializedEnvelopeTypeId,
|
80
|
+
messageId,
|
81
|
+
recipientAddress,
|
82
|
+
body
|
83
|
+
})
|
84
|
+
}
|
85
|
+
|
86
|
+
/**
|
87
|
+
* Ensures that the given value is a SerializedEnvelope.
|
88
|
+
*
|
89
|
+
* @since 1.0.0
|
90
|
+
* @category utils
|
91
|
+
*/
|
92
|
+
export function isSerializedEnvelope(value: unknown): value is SerializedEnvelope {
|
93
|
+
return (
|
94
|
+
typeof value === "object" &&
|
95
|
+
value !== null &&
|
96
|
+
SerializedEnvelopeTypeId in value &&
|
97
|
+
value[SerializedEnvelopeTypeId] === SerializedEnvelopeTypeId
|
98
|
+
)
|
99
|
+
}
|
100
|
+
|
101
|
+
/**
|
102
|
+
* This is the schema for a value.
|
103
|
+
*
|
104
|
+
* @since 1.0.0
|
105
|
+
* @category schema
|
106
|
+
*/
|
107
|
+
export const schema: Schema.Schema<SerializedEnvelope, SerializedEnvelope.Encoded, never> = Schema.asSchema(
|
108
|
+
SerializedEnvelope
|
109
|
+
)
|
@@ -0,0 +1,82 @@
|
|
1
|
+
/**
|
2
|
+
* @since 1.0.0
|
3
|
+
*/
|
4
|
+
import * as Schema from "@effect/schema/Schema"
|
5
|
+
import { TypeIdSchema } from "./internal/utils.js"
|
6
|
+
|
7
|
+
/** @internal */
|
8
|
+
const SerializedMessageSymbolKey = "@effect/cluster/SerializedMessage"
|
9
|
+
|
10
|
+
/**
|
11
|
+
* @since 1.0.0
|
12
|
+
* @category symbols
|
13
|
+
*/
|
14
|
+
export const SerializedMessageTypeId: unique symbol = Symbol.for(SerializedMessageSymbolKey)
|
15
|
+
|
16
|
+
/**
|
17
|
+
* @since 1.0.0
|
18
|
+
* @category symbols
|
19
|
+
*/
|
20
|
+
export type SerializedMessageTypeId = typeof SerializedMessageTypeId
|
21
|
+
|
22
|
+
/** @internal */
|
23
|
+
const SerializedMessageTypeIdSchema = TypeIdSchema(SerializedMessageSymbolKey, SerializedMessageTypeId)
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Represents a Message that has been serialized.
|
27
|
+
*
|
28
|
+
* @since 1.0.0
|
29
|
+
* @category models
|
30
|
+
*/
|
31
|
+
export class SerializedMessage extends Schema.Class<SerializedMessage>(SerializedMessageSymbolKey)({
|
32
|
+
[SerializedMessageTypeId]: Schema.propertySignature(SerializedMessageTypeIdSchema).pipe(
|
33
|
+
Schema.fromKey(SerializedMessageSymbolKey)
|
34
|
+
),
|
35
|
+
value: Schema.String
|
36
|
+
}) {}
|
37
|
+
|
38
|
+
/**
|
39
|
+
* @since 1.0.0
|
40
|
+
* @category models
|
41
|
+
*/
|
42
|
+
export namespace SerializedMessage {
|
43
|
+
/**
|
44
|
+
* @since 1.0.0
|
45
|
+
* @category models
|
46
|
+
*/
|
47
|
+
export interface Encoded extends Schema.Schema.Encoded<typeof SerializedMessage> {}
|
48
|
+
}
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Construct a new `SerializedMessage` from its internal string value.
|
52
|
+
*
|
53
|
+
* @since 1.0.0
|
54
|
+
* @category constructors
|
55
|
+
*/
|
56
|
+
export function make(value: string): SerializedMessage {
|
57
|
+
return new SerializedMessage({ [SerializedMessageTypeId]: SerializedMessageTypeId, value })
|
58
|
+
}
|
59
|
+
|
60
|
+
/**
|
61
|
+
* @since 1.0.0
|
62
|
+
* @category utils
|
63
|
+
*/
|
64
|
+
export function isSerializedMessage(value: unknown): value is SerializedMessage {
|
65
|
+
return (
|
66
|
+
typeof value === "object" &&
|
67
|
+
value !== null &&
|
68
|
+
SerializedMessageTypeId in value &&
|
69
|
+
value[SerializedMessageTypeId] === SerializedMessageTypeId
|
70
|
+
)
|
71
|
+
}
|
72
|
+
|
73
|
+
/**
|
74
|
+
* This is the schema for a value.
|
75
|
+
*
|
76
|
+
* @since 1.0.0
|
77
|
+
* @category schema
|
78
|
+
*/
|
79
|
+
export const schema: Schema.Schema<
|
80
|
+
SerializedMessage,
|
81
|
+
SerializedMessage.Encoded
|
82
|
+
> = Schema.asSchema(SerializedMessage)
|
package/src/ShardId.ts
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
/**
|
2
|
+
* @since 1.0.0
|
3
|
+
*/
|
4
|
+
import * as Schema from "@effect/schema/Schema"
|
5
|
+
import { TypeIdSchema } from "./internal/utils.js"
|
6
|
+
|
7
|
+
/** @internal */
|
8
|
+
const ShardIdSymbolKey = "@effect/cluster/ShardId"
|
9
|
+
|
10
|
+
/**
|
11
|
+
* @since 1.0.0
|
12
|
+
* @category symbols
|
13
|
+
*/
|
14
|
+
export const ShardIdTypeId: unique symbol = Symbol.for(ShardIdSymbolKey)
|
15
|
+
|
16
|
+
/**
|
17
|
+
* @since 1.0.0
|
18
|
+
* @category symbols
|
19
|
+
*/
|
20
|
+
export type ShardIdTypeId = typeof ShardIdTypeId
|
21
|
+
|
22
|
+
/** @internal */
|
23
|
+
const ShardIdTypeIdSchema = TypeIdSchema(ShardIdSymbolKey, ShardIdTypeId)
|
24
|
+
|
25
|
+
/**
|
26
|
+
* A shard is a logical grouping of multiple entities. There could be thousands of entities in your system,
|
27
|
+
* so instead of managing every single entity id, the shard manager group them by shard id, and when they are assigned
|
28
|
+
* or moved around, we always move all the entities with the same shard id.
|
29
|
+
*
|
30
|
+
* @since 1.0.0
|
31
|
+
* @category models
|
32
|
+
*/
|
33
|
+
export class ShardId extends Schema.Class<ShardId>(ShardIdSymbolKey)({
|
34
|
+
[ShardIdTypeId]: Schema.propertySignature(ShardIdTypeIdSchema).pipe(Schema.fromKey(ShardIdSymbolKey)),
|
35
|
+
value: Schema.Number
|
36
|
+
}) {
|
37
|
+
/**
|
38
|
+
* @since 1.0.0
|
39
|
+
*/
|
40
|
+
toString() {
|
41
|
+
return `ShardId(${this.value})`
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
/**
|
46
|
+
* @since 1.0.0
|
47
|
+
* @category models
|
48
|
+
*/
|
49
|
+
export namespace ShardId {
|
50
|
+
/**
|
51
|
+
* This is the shape that a shard id has over the wire.
|
52
|
+
*
|
53
|
+
* @since 1.0.0
|
54
|
+
* @category models
|
55
|
+
*/
|
56
|
+
export interface Encoded extends Schema.Schema.Encoded<typeof ShardId> {}
|
57
|
+
}
|
58
|
+
|
59
|
+
/**
|
60
|
+
* Constructs a shard id from its numerical value.
|
61
|
+
* The shard id is currently built up by making the hash of the entity id, and then modulo the max amount of shards configured in ManagerConfig.
|
62
|
+
*
|
63
|
+
* @since 1.0.0
|
64
|
+
* @category constructors
|
65
|
+
*/
|
66
|
+
export function make(value: number): ShardId {
|
67
|
+
return new ShardId({ [ShardIdTypeId]: ShardIdTypeId, value })
|
68
|
+
}
|
69
|
+
|
70
|
+
/**
|
71
|
+
* This is the schema for a ShardId.
|
72
|
+
*
|
73
|
+
* @since 1.0.0
|
74
|
+
* @category schema
|
75
|
+
*/
|
76
|
+
export const schema: Schema.Schema<
|
77
|
+
ShardId,
|
78
|
+
ShardId.Encoded
|
79
|
+
> = Schema.asSchema(ShardId)
|