liminal 0.17.5 → 0.17.7

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 (51) hide show
  1. package/Actor.ts +29 -45
  2. package/ActorTransport.ts +17 -0
  3. package/Audition.ts +27 -48
  4. package/CHANGELOG.md +12 -0
  5. package/Client.ts +104 -173
  6. package/ClientDirectory.ts +104 -0
  7. package/ClientHandle.ts +6 -13
  8. package/F.ts +5 -7
  9. package/Method.ts +5 -13
  10. package/Protocol.ts +85 -68
  11. package/Send.ts +5 -9
  12. package/_util/schema.ts +7 -0
  13. package/dist/Actor.d.ts +15 -17
  14. package/dist/Actor.js +1 -3
  15. package/dist/Actor.js.map +1 -1
  16. package/dist/ActorTransport.d.ts +7 -0
  17. package/dist/ActorTransport.js +2 -0
  18. package/dist/ActorTransport.js.map +1 -0
  19. package/dist/Audition.d.ts +7 -7
  20. package/dist/Audition.js.map +1 -1
  21. package/dist/Client.d.ts +23 -28
  22. package/dist/Client.js +63 -67
  23. package/dist/Client.js.map +1 -1
  24. package/dist/ClientDirectory.d.ts +21 -0
  25. package/dist/ClientDirectory.js +41 -0
  26. package/dist/ClientDirectory.js.map +1 -0
  27. package/dist/ClientHandle.d.ts +6 -5
  28. package/dist/ClientHandle.js.map +1 -1
  29. package/dist/F.d.ts +2 -2
  30. package/dist/F.js +1 -1
  31. package/dist/F.js.map +1 -1
  32. package/dist/Method.d.ts +5 -10
  33. package/dist/Method.js +1 -1
  34. package/dist/Method.js.map +1 -1
  35. package/dist/Protocol.d.ts +51 -34
  36. package/dist/Protocol.js +20 -22
  37. package/dist/Protocol.js.map +1 -1
  38. package/dist/Send.d.ts +2 -1
  39. package/dist/_util/schema.d.ts +4 -0
  40. package/dist/_util/schema.js +5 -0
  41. package/dist/_util/schema.js.map +1 -0
  42. package/dist/errors.d.ts +5 -5
  43. package/dist/errors.js +2 -2
  44. package/dist/errors.js.map +1 -1
  45. package/dist/index.d.ts +2 -0
  46. package/dist/index.js +2 -0
  47. package/dist/index.js.map +1 -1
  48. package/dist/tsconfig.tsbuildinfo +1 -1
  49. package/errors.ts +5 -5
  50. package/index.ts +2 -0
  51. package/package.json +1 -1
package/Actor.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  import { Context, Schema as S, Effect } from "effect"
2
2
 
3
+ import type { TopFromString } from "./_util/schema.ts"
3
4
  import type * as ActorClient from "./Client.ts"
4
5
  import type * as ClientHandle from "./ClientHandle.ts"
5
- import type { MethodDefinition } from "./Method.ts"
6
6
  import type { Send } from "./Send.ts"
7
7
 
8
8
  import * as Diagnostic from "./_util/Diagnostic.ts"
9
9
  import * as Method from "./Method.ts"
10
+ import { type ProtocolDefinition } from "./Protocol.ts"
10
11
 
11
12
  const { span } = Diagnostic.module("Actor")
12
13
 
@@ -14,86 +15,72 @@ export const TypeId = "~liminal/Actor" as const
14
15
 
15
16
  export interface Service<
16
17
  ActorSelf,
17
- NameA,
18
+ Name extends TopFromString,
18
19
  AttachmentFields extends S.Struct.Fields,
19
- EventDefinitions extends Record<string, S.Struct.Fields>,
20
+ D extends ProtocolDefinition,
20
21
  > {
21
- readonly name: NameA
22
+ readonly name: Name["Type"]
22
23
 
23
- readonly currentClient: ClientHandle.ClientHandle<ActorSelf, AttachmentFields, EventDefinitions>
24
+ readonly currentClient: ClientHandle.ClientHandle<ActorSelf, AttachmentFields, D>
24
25
 
25
- readonly clients: ReadonlySet<ClientHandle.ClientHandle<ActorSelf, AttachmentFields, EventDefinitions>>
26
+ readonly clients: ReadonlySet<ClientHandle.ClientHandle<ActorSelf, AttachmentFields, D>>
26
27
  }
27
28
 
28
29
  export interface ActorDefinition<
29
- NameA,
30
+ Name extends TopFromString,
30
31
  AttachmentFields extends S.Struct.Fields,
31
32
  ClientSelf,
32
33
  ClientId extends string,
33
- MethodDefinitions extends Record<string, MethodDefinition.Any>,
34
- EventDefinitions extends Record<string, S.Struct.Fields>,
34
+ D extends ProtocolDefinition,
35
35
  > {
36
- readonly name: S.Codec<NameA, string>
36
+ readonly name: Name
37
37
 
38
38
  readonly attachments: AttachmentFields
39
39
 
40
- readonly client: ActorClient.Client<ClientSelf, ClientId, MethodDefinitions, EventDefinitions>
40
+ readonly client: ActorClient.Client<ClientSelf, ClientId, D>
41
41
  }
42
42
 
43
43
  export interface Actor<
44
44
  ActorSelf,
45
45
  ActorId extends string,
46
- NameA,
46
+ Name extends TopFromString,
47
47
  AttachmentFields extends S.Struct.Fields,
48
48
  ActorClientSelf,
49
49
  ActorClientId extends string,
50
- MethodDefinitions extends Record<string, MethodDefinition.Any>,
51
- EventDefinitions extends Record<string, S.Struct.Fields>,
52
- > extends Context.Service<ActorSelf, Service<ActorSelf, NameA, AttachmentFields, EventDefinitions>> {
53
- new (_: never): Context.ServiceClass.Shape<ActorId, Service<ActorSelf, NameA, AttachmentFields, EventDefinitions>>
50
+ D extends ProtocolDefinition,
51
+ > extends Context.Service<ActorSelf, Service<ActorSelf, Name, AttachmentFields, D>> {
52
+ new (_: never): Context.ServiceClass.Shape<ActorId, Service<ActorSelf, Name, AttachmentFields, D>>
54
53
 
55
54
  readonly [TypeId]: typeof TypeId
56
55
 
57
- readonly definition: ActorDefinition<
58
- NameA,
59
- AttachmentFields,
60
- ActorClientSelf,
61
- ActorClientId,
62
- MethodDefinitions,
63
- EventDefinitions
64
- >
65
-
66
- readonly schema: {
67
- readonly attachments: S.Codec<S.Struct<AttachmentFields>["Type"], S.Struct<AttachmentFields>["Encoded"]>
68
- }
56
+ readonly definition: ActorDefinition<Name, AttachmentFields, ActorClientSelf, ActorClientId, D>
69
57
 
70
- readonly sendAll: Send<ActorSelf, EventDefinitions>
58
+ readonly sendAll: Send<ActorSelf, D>
71
59
 
72
60
  readonly disconnectAll: Effect.Effect<void, never, ActorSelf>
73
61
 
74
- readonly handler: <K extends keyof MethodDefinitions, R>(
62
+ readonly handler: <K extends keyof D["methods"], R>(
75
63
  tag: K,
76
- f: Method.Handler<MethodDefinitions[K], R>,
77
- ) => Method.Handler<MethodDefinitions[K], R>
64
+ f: Method.Handler<D["methods"][K], R>,
65
+ ) => Method.Handler<D["methods"][K], R>
78
66
  }
79
67
 
80
68
  export const Service =
81
69
  <ActorSelf>() =>
82
70
  <
83
71
  ActorId extends string,
84
- NameA,
72
+ Name extends TopFromString,
73
+ D extends ProtocolDefinition,
85
74
  AttachmentFields extends S.Struct.Fields,
86
75
  ClientSelf,
87
76
  ClientId extends string,
88
- MethodDefinitions extends Record<string, MethodDefinition.Any>,
89
- EventDefinitions extends Record<string, S.Struct.Fields>,
90
77
  >(
91
78
  id: ActorId,
92
- definition: ActorDefinition<NameA, AttachmentFields, ClientSelf, ClientId, MethodDefinitions, EventDefinitions>,
93
- ): Actor<ActorSelf, ActorId, NameA, AttachmentFields, ClientSelf, ClientId, MethodDefinitions, EventDefinitions> => {
94
- const tag = Context.Service<ActorSelf, Service<ActorSelf, NameA, AttachmentFields, EventDefinitions>>()(id)
79
+ definition: ActorDefinition<Name, AttachmentFields, ClientSelf, ClientId, D>,
80
+ ): Actor<ActorSelf, ActorId, Name, AttachmentFields, ClientSelf, ClientId, D> => {
81
+ const tag = Context.Service<ActorSelf, Service<ActorSelf, Name, AttachmentFields, D>>()(id)
95
82
 
96
- const sendAll: Send<ActorSelf, EventDefinitions> = (key, payload) =>
83
+ const sendAll: Send<ActorSelf, D> = (key, payload) =>
97
84
  tag.asEffect().pipe(
98
85
  Effect.flatMap(({ clients }) =>
99
86
  Effect.forEach(clients, (client) => client.send(key, payload), { concurrency: "unbounded" }),
@@ -106,17 +93,14 @@ export const Service =
106
93
  span("disconnectAll"),
107
94
  )
108
95
 
109
- const handler = <K extends keyof MethodDefinitions, R>(
96
+ const handler = <K extends keyof D["methods"], R>(
110
97
  _tag: K,
111
- f: Method.Handler<MethodDefinitions[K], R>,
112
- ): Method.Handler<MethodDefinitions[K], R> => f
98
+ f: Method.Handler<D["methods"][K], R>,
99
+ ): Method.Handler<D["methods"][K], R> => f
113
100
 
114
101
  return Object.assign(tag, {
115
102
  [TypeId]: TypeId,
116
103
  definition,
117
- schema: {
118
- attachments: S.Struct(definition.attachments) as never,
119
- },
120
104
  sendAll,
121
105
  disconnectAll,
122
106
  handler,
@@ -0,0 +1,17 @@
1
+ import { Effect, Schema as S } from "effect"
2
+
3
+ import type { Protocol, ProtocolDefinition } from "./Protocol.ts"
4
+
5
+ export interface ActorTransport<Raw, AttachmentFields extends S.Struct.Fields, D extends ProtocolDefinition> {
6
+ readonly send: (
7
+ transport: Raw,
8
+ event: Protocol<D>["Event"]["Type"],
9
+ ) => Effect.Effect<void, S.SchemaError, Protocol<D>["Event"]["EncodingServices"]>
10
+
11
+ readonly close: (transport: Raw) => Effect.Effect<void>
12
+
13
+ readonly snapshot: (
14
+ transport: Raw,
15
+ attachments: S.Struct<AttachmentFields>["Type"],
16
+ ) => Effect.Effect<void, S.SchemaError, S.Struct<AttachmentFields>["EncodingServices"]>
17
+ }
package/Audition.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Schema as S, Pipeable, Stream, Effect, Function } from "effect"
2
2
 
3
3
  import type { F } from "./F.ts"
4
- import type * as Method from "./Method.ts"
4
+ import type { ProtocolDefinition } from "./Protocol.ts"
5
5
 
6
6
  import * as Diagnostic from "./_util/Diagnostic.ts"
7
7
  import * as Client from "./Client.ts"
@@ -11,16 +11,19 @@ const { debug, span } = Diagnostic.module("Audition")
11
11
 
12
12
  const TypeId = "~liminal/Audition" as const
13
13
 
14
- export interface Audition<ClientSelf, MethodDefinitions extends Record<string, Method.MethodDefinition.Any>, Event>
15
- extends Pipeable.Pipeable {
14
+ export interface Audition<ClientSelf, D extends ProtocolDefinition> extends Pipeable.Pipeable {
16
15
  readonly [TypeId]: typeof TypeId
17
16
 
18
- readonly events: Stream.Stream<Event, ClientError, ClientSelf>
17
+ readonly events: Stream.Stream<
18
+ ReturnType<typeof S.TaggedUnion<D["events"]>>["Type"],
19
+ ClientError | S.SchemaError,
20
+ ClientSelf
21
+ >
19
22
 
20
- readonly f: F<ClientSelf, MethodDefinitions>
23
+ readonly f: F<ClientSelf, D>
21
24
  }
22
25
 
23
- export const empty: Audition<never, never, never> = {
26
+ export const empty: Audition<never, never> = {
24
27
  [TypeId]: TypeId,
25
28
  pipe() {
26
29
  return Pipeable.pipeArguments(this, arguments)
@@ -30,62 +33,38 @@ export const empty: Audition<never, never, never> = {
30
33
  }
31
34
 
32
35
  export const add: {
33
- <
34
- ClientSelf,
35
- ClientId extends string,
36
- ClientMethodDefinitions extends Record<string, Method.MethodDefinition.Any>,
37
- ClientEventDefinitions extends Record<string, S.Struct.Fields>,
38
- >(
39
- client: Client.Client<ClientSelf, ClientId, ClientMethodDefinitions, ClientEventDefinitions>,
40
- ): <AuditionSelf, AuditionMethodDefinitions extends Record<string, Method.MethodDefinition.Any>, AuditionEvent>(
41
- audition: Audition<AuditionSelf, AuditionMethodDefinitions, AuditionEvent>,
42
- ) => Audition<
43
- AuditionSelf | ClientSelf,
44
- Method.MethodDefinition.Merge<AuditionMethodDefinitions, ClientMethodDefinitions>,
45
- AuditionEvent | ReturnType<typeof S.TaggedUnion<ClientEventDefinitions>>["Type"]
46
- >
36
+ <ClientSelf, ClientId extends string, ClientD extends ProtocolDefinition>(
37
+ client: Client.Client<ClientSelf, ClientId, ClientD>,
38
+ ): <AuditionSelf, AuditionD extends ProtocolDefinition>(
39
+ audition: Audition<AuditionSelf, AuditionD>,
40
+ ) => Audition<AuditionSelf | ClientSelf, ProtocolDefinition.Merge<AuditionD, ClientD>>
47
41
  <
48
42
  AuditionClientSelf,
49
- AuditionMethodDefinitions extends Record<string, Method.MethodDefinition.Any>,
50
- AuditionEvent,
43
+ AuditionD extends ProtocolDefinition,
51
44
  ClientSelf,
52
45
  ClientId extends string,
53
- ClientMethodDefinitions extends Record<string, Method.MethodDefinition.Any>,
54
- ClientEventDefinitions extends Record<string, S.Struct.Fields>,
46
+ ClientD extends ProtocolDefinition,
55
47
  >(
56
- audition: Audition<AuditionClientSelf, AuditionMethodDefinitions, AuditionEvent>,
57
- client: Client.Client<ClientSelf, ClientId, ClientMethodDefinitions, ClientEventDefinitions>,
58
- ): Audition<
59
- AuditionClientSelf | ClientSelf,
60
- Method.MethodDefinition.Merge<AuditionMethodDefinitions, ClientMethodDefinitions>,
61
- AuditionEvent | ReturnType<typeof S.TaggedUnion<ClientEventDefinitions>>["Type"]
62
- >
48
+ audition: Audition<AuditionClientSelf, AuditionD>,
49
+ client: Client.Client<ClientSelf, ClientId, ClientD>,
50
+ ): Audition<AuditionClientSelf | ClientSelf, ProtocolDefinition.Merge<AuditionD, ClientD>>
63
51
  } = Function.dual(
64
52
  2,
65
53
  <
66
54
  AuditionSelf,
67
- AuditionMethodDefinitions extends Record<string, Method.MethodDefinition.Any>,
68
- AuditionEvent,
55
+ AuditionD extends ProtocolDefinition,
69
56
  ClientSelf,
70
57
  ClientId extends string,
71
- ClientMethodDefinitions extends Record<string, Method.MethodDefinition.Any>,
72
- ClientEventDefinitions extends Record<string, S.Struct.Fields>,
58
+ ClientD extends ProtocolDefinition,
73
59
  >(
74
- audition: Audition<AuditionSelf, AuditionMethodDefinitions, AuditionEvent>,
75
- client: Client.Client<ClientSelf, ClientId, ClientMethodDefinitions, ClientEventDefinitions>,
76
- ): Audition<
77
- AuditionSelf | ClientSelf,
78
- Method.MethodDefinition.Merge<AuditionMethodDefinitions, ClientMethodDefinitions>,
79
- AuditionEvent | ReturnType<typeof S.TaggedUnion<ClientEventDefinitions>>["Type"]
80
- > => {
81
- const f: F<
82
- AuditionSelf | ClientSelf,
83
- Method.MethodDefinition.Merge<AuditionMethodDefinitions, ClientMethodDefinitions>
84
- > = (method) => (payload) =>
60
+ audition: Audition<AuditionSelf, AuditionD>,
61
+ client: Client.Client<ClientSelf, ClientId, ClientD>,
62
+ ): Audition<AuditionSelf | ClientSelf, ProtocolDefinition.Merge<AuditionD, ClientD>> => {
63
+ const f: F<AuditionSelf | ClientSelf, ProtocolDefinition.Merge<AuditionD, ClientD>> = (method) => (payload) =>
85
64
  audition
86
- .f(method as never)(payload)
65
+ .f(method)(payload)
87
66
  .pipe(
88
- Effect.catchTag("AuditionError", () => client.f(method as never)(payload)),
67
+ Effect.catchTag("AuditionError", () => client.f(method)(payload)),
89
68
  span("f"),
90
69
  )
91
70
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # liminal
2
2
 
3
+ ## 0.17.7
4
+
5
+ ### Patch Changes
6
+
7
+ - e5c54be: Decouple actor transport. Implement proper multi-actor instance browser registry.
8
+
9
+ ## 0.17.6
10
+
11
+ ### Patch Changes
12
+
13
+ - d7b1da3: Simplify type-level representation of client protocol.
14
+
3
15
  ## 0.17.5
4
16
 
5
17
  ### Patch Changes