@effect/cluster 0.40.0 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/cjs/ClusterWorkflowEngine.js.map +1 -1
  2. package/dist/cjs/Entity.js.map +1 -1
  3. package/dist/cjs/EntityProxy.js +2 -3
  4. package/dist/cjs/EntityProxy.js.map +1 -1
  5. package/dist/cjs/EntityProxyServer.js +2 -3
  6. package/dist/cjs/EntityProxyServer.js.map +1 -1
  7. package/dist/cjs/Sharding.js +16 -8
  8. package/dist/cjs/Sharding.js.map +1 -1
  9. package/dist/cjs/internal/entityManager.js.map +1 -1
  10. package/dist/dts/ClusterWorkflowEngine.d.ts.map +1 -1
  11. package/dist/dts/Entity.d.ts +15 -15
  12. package/dist/dts/Entity.d.ts.map +1 -1
  13. package/dist/dts/EntityProxy.d.ts +3 -5
  14. package/dist/dts/EntityProxy.d.ts.map +1 -1
  15. package/dist/dts/EntityProxyServer.d.ts +3 -5
  16. package/dist/dts/EntityProxyServer.d.ts.map +1 -1
  17. package/dist/dts/Sharding.d.ts +2 -2
  18. package/dist/dts/Sharding.d.ts.map +1 -1
  19. package/dist/dts/ShardingRegistrationEvent.d.ts +1 -1
  20. package/dist/dts/ShardingRegistrationEvent.d.ts.map +1 -1
  21. package/dist/esm/ClusterWorkflowEngine.js.map +1 -1
  22. package/dist/esm/Entity.js.map +1 -1
  23. package/dist/esm/EntityProxy.js +2 -3
  24. package/dist/esm/EntityProxy.js.map +1 -1
  25. package/dist/esm/EntityProxyServer.js +2 -3
  26. package/dist/esm/EntityProxyServer.js.map +1 -1
  27. package/dist/esm/Sharding.js +16 -8
  28. package/dist/esm/Sharding.js.map +1 -1
  29. package/dist/esm/internal/entityManager.js.map +1 -1
  30. package/package.json +5 -5
  31. package/src/ClusterWorkflowEngine.ts +1 -0
  32. package/src/Entity.ts +30 -26
  33. package/src/EntityProxy.ts +8 -12
  34. package/src/EntityProxyServer.ts +7 -9
  35. package/src/Sharding.ts +30 -22
  36. package/src/ShardingRegistrationEvent.ts +1 -1
  37. package/src/internal/entityManager.ts +3 -2
package/src/Sharding.ts CHANGED
@@ -40,7 +40,6 @@ import { Persisted, Uninterruptible } from "./ClusterSchema.js"
40
40
  import type { CurrentAddress, CurrentRunnerAddress, Entity, HandlersFrom } from "./Entity.js"
41
41
  import { EntityAddress } from "./EntityAddress.js"
42
42
  import { EntityId } from "./EntityId.js"
43
- import type { EntityType } from "./EntityType.js"
44
43
  import * as Envelope from "./Envelope.js"
45
44
  import * as EntityManager from "./internal/entityManager.js"
46
45
  import { EntityReaper } from "./internal/entityReaper.js"
@@ -86,8 +85,8 @@ export class Sharding extends Context.Tag("@effect/cluster/Sharding")<Sharding,
86
85
  * Constructs a `RpcClient` which can be used to send messages to the
87
86
  * specified `Entity`.
88
87
  */
89
- readonly makeClient: <Rpcs extends Rpc.Any>(
90
- entity: Entity<Rpcs>
88
+ readonly makeClient: <Type extends string, Rpcs extends Rpc.Any>(
89
+ entity: Entity<Type, Rpcs>
91
90
  ) => Effect.Effect<
92
91
  (
93
92
  entityId: string
@@ -97,8 +96,8 @@ export class Sharding extends Context.Tag("@effect/cluster/Sharding")<Sharding,
97
96
  /**
98
97
  * Registers a new entity with the runner.
99
98
  */
100
- readonly registerEntity: <Rpcs extends Rpc.Any, Handlers extends HandlersFrom<Rpcs>, RX>(
101
- entity: Entity<Rpcs>,
99
+ readonly registerEntity: <Type extends string, Rpcs extends Rpc.Any, Handlers extends HandlersFrom<Rpcs>, RX>(
100
+ entity: Entity<Type, Rpcs>,
102
101
  handlers: Effect.Effect<Handlers, never, RX>,
103
102
  options?: {
104
103
  readonly maxIdleTime?: DurationInput | undefined
@@ -173,7 +172,7 @@ export class Sharding extends Context.Tag("@effect/cluster/Sharding")<Sharding,
173
172
  // -----------------------------------------------------------------------------
174
173
 
175
174
  interface EntityManagerState {
176
- readonly entity: Entity<any>
175
+ readonly entity: Entity<any, any>
177
176
  readonly scope: Scope.CloseableScope
178
177
  readonly manager: EntityManager.EntityManager
179
178
  }
@@ -191,7 +190,7 @@ const make = Effect.gen(function*() {
191
190
  const storageEnabled = storage !== MessageStorage.noop
192
191
  const shardStorage = yield* ShardStorage
193
192
 
194
- const entityManagers = new Map<EntityType, EntityManagerState>()
193
+ const entityManagers = new Map<string, EntityManagerState>()
195
194
 
196
195
  const shardAssignments = MutableHashMap.empty<ShardId, RunnerAddress>()
197
196
  const selfShards = MutableHashSet.empty<ShardId>()
@@ -939,13 +938,13 @@ const make = Effect.gen(function*() {
939
938
  const clientRequests = new Map<Snowflake.Snowflake, ClientRequestEntry>()
940
939
 
941
940
  const clients: ResourceMap<
942
- Entity<any>,
941
+ Entity<any, any>,
943
942
  (entityId: string) => RpcClient.RpcClient<
944
943
  any,
945
944
  MailboxFull | AlreadyProcessingMessage | EntityNotManagedByRunner
946
945
  >,
947
946
  never
948
- > = yield* ResourceMap.make(Effect.fnUntraced(function*(entity: Entity<any>) {
947
+ > = yield* ResourceMap.make(Effect.fnUntraced(function*(entity: Entity<string, any>) {
949
948
  const client = yield* RpcClient.makeNoSerialization(entity.protocol, {
950
949
  spanPrefix: `${entity.type}.client`,
951
950
  supportsAck: true,
@@ -1041,20 +1040,29 @@ const make = Effect.gen(function*() {
1041
1040
  }
1042
1041
  })
1043
1042
 
1044
- const wrappedClient: any = {}
1045
- for (const method of Object.keys(client.client)) {
1046
- wrappedClient[method] = function(this: any, payload: any, options?: {
1047
- readonly context?: Context.Context<never>
1048
- }) {
1049
- return (client as any).client[method](payload, {
1050
- ...options,
1051
- context: options?.context
1052
- ? Context.merge(options.context, this[currentClientAddress])
1053
- : this[currentClientAddress]
1054
- })
1043
+ function patchClient(client: any): any {
1044
+ const wrappedClient: any = {}
1045
+ for (const method of Object.keys(client.client)) {
1046
+ if (typeof client.client[method] === "object") {
1047
+ wrappedClient[method] = patchClient(client.client[method])
1048
+ continue
1049
+ }
1050
+ wrappedClient[method] = function(this: any, payload: any, options?: {
1051
+ readonly context?: Context.Context<never>
1052
+ }) {
1053
+ return (client as any).client[method](payload, {
1054
+ ...options,
1055
+ context: options?.context
1056
+ ? Context.merge(options.context, this[currentClientAddress])
1057
+ : this[currentClientAddress]
1058
+ })
1059
+ }
1055
1060
  }
1061
+ return wrappedClient
1056
1062
  }
1057
1063
 
1064
+ const wrappedClient = patchClient(client)
1065
+
1058
1066
  yield* Scope.addFinalizer(
1059
1067
  yield* Effect.scope,
1060
1068
  Effect.withFiberRuntime((fiber) => {
@@ -1076,9 +1084,9 @@ const make = Effect.gen(function*() {
1076
1084
  }
1077
1085
  }))
1078
1086
 
1079
- const makeClient = <Rpcs extends Rpc.Any>(entity: Entity<Rpcs>): Effect.Effect<
1087
+ const makeClient = <Type extends string, Rpcs extends Rpc.Any>(entity: Entity<Type, Rpcs>): Effect.Effect<
1080
1088
  (entityId: string) => RpcClient.RpcClient<Rpcs, MailboxFull | AlreadyProcessingMessage | EntityNotManagedByRunner>
1081
- > => clients.get(entity)
1089
+ > => clients.get(entity) as any
1082
1090
 
1083
1091
  const clientRespondDiscard = (_reply: Reply.Reply<any>) => Effect.void
1084
1092
 
@@ -23,7 +23,7 @@ export type ShardingRegistrationEvent =
23
23
  */
24
24
  export interface EntityRegistered {
25
25
  readonly _tag: "EntityRegistered"
26
- readonly entity: Entity<any>
26
+ readonly entity: Entity<any, any>
27
27
  }
28
28
 
29
29
  /**
@@ -75,11 +75,12 @@ export type EntityState = {
75
75
 
76
76
  /** @internal */
77
77
  export const make = Effect.fnUntraced(function*<
78
+ Type extends string,
78
79
  Rpcs extends Rpc.Any,
79
80
  Handlers extends HandlersFrom<Rpcs>,
80
81
  RX
81
82
  >(
82
- entity: Entity<Rpcs>,
83
+ entity: Entity<Type, Rpcs>,
83
84
  buildHandlers: Effect.Effect<Handlers, never, RX>,
84
85
  options: {
85
86
  readonly sharding: Sharding["Type"]
@@ -501,7 +502,7 @@ const defaultRetryPolicy = Schedule.exponential(500, 1.5).pipe(
501
502
  Schedule.union(Schedule.spaced("10 seconds"))
502
503
  )
503
504
 
504
- const makeMessageSchema = <Rpcs extends Rpc.Any>(entity: Entity<Rpcs>): Schema.Schema<
505
+ const makeMessageSchema = <Type extends string, Rpcs extends Rpc.Any>(entity: Entity<Type, Rpcs>): Schema.Schema<
505
506
  {
506
507
  readonly _tag: "IncomingRequest"
507
508
  readonly envelope: Envelope.Request.Any