liminal 0.17.5 → 0.17.6

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/Actor.ts CHANGED
@@ -2,7 +2,7 @@ import { Context, Schema as S, Effect } from "effect"
2
2
 
3
3
  import type * as ActorClient from "./Client.ts"
4
4
  import type * as ClientHandle from "./ClientHandle.ts"
5
- import type { MethodDefinition } from "./Method.ts"
5
+ import type { ProtocolDefinition } from "./Protocol.ts"
6
6
  import type { Send } from "./Send.ts"
7
7
 
8
8
  import * as Diagnostic from "./_util/Diagnostic.ts"
@@ -12,17 +12,12 @@ const { span } = Diagnostic.module("Actor")
12
12
 
13
13
  export const TypeId = "~liminal/Actor" as const
14
14
 
15
- export interface Service<
16
- ActorSelf,
17
- NameA,
18
- AttachmentFields extends S.Struct.Fields,
19
- EventDefinitions extends Record<string, S.Struct.Fields>,
20
- > {
15
+ export interface Service<ActorSelf, NameA, AttachmentFields extends S.Struct.Fields, D extends ProtocolDefinition> {
21
16
  readonly name: NameA
22
17
 
23
- readonly currentClient: ClientHandle.ClientHandle<ActorSelf, AttachmentFields, EventDefinitions>
18
+ readonly currentClient: ClientHandle.ClientHandle<ActorSelf, AttachmentFields, D>
24
19
 
25
- readonly clients: ReadonlySet<ClientHandle.ClientHandle<ActorSelf, AttachmentFields, EventDefinitions>>
20
+ readonly clients: ReadonlySet<ClientHandle.ClientHandle<ActorSelf, AttachmentFields, D>>
26
21
  }
27
22
 
28
23
  export interface ActorDefinition<
@@ -30,14 +25,13 @@ export interface ActorDefinition<
30
25
  AttachmentFields extends S.Struct.Fields,
31
26
  ClientSelf,
32
27
  ClientId extends string,
33
- MethodDefinitions extends Record<string, MethodDefinition.Any>,
34
- EventDefinitions extends Record<string, S.Struct.Fields>,
28
+ D extends ProtocolDefinition,
35
29
  > {
36
30
  readonly name: S.Codec<NameA, string>
37
31
 
38
32
  readonly attachments: AttachmentFields
39
33
 
40
- readonly client: ActorClient.Client<ClientSelf, ClientId, MethodDefinitions, EventDefinitions>
34
+ readonly client: ActorClient.Client<ClientSelf, ClientId, D>
41
35
  }
42
36
 
43
37
  export interface Actor<
@@ -47,34 +41,26 @@ export interface Actor<
47
41
  AttachmentFields extends S.Struct.Fields,
48
42
  ActorClientSelf,
49
43
  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>>
44
+ D extends ProtocolDefinition,
45
+ > extends Context.Service<ActorSelf, Service<ActorSelf, NameA, AttachmentFields, D>> {
46
+ new (_: never): Context.ServiceClass.Shape<ActorId, Service<ActorSelf, NameA, AttachmentFields, D>>
54
47
 
55
48
  readonly [TypeId]: typeof TypeId
56
49
 
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"]>
50
+ readonly definition: ActorDefinition<NameA, AttachmentFields, ActorClientSelf, ActorClientId, D>
51
+
52
+ readonly protocol: {
53
+ readonly Attachments: S.Struct<AttachmentFields>
68
54
  }
69
55
 
70
- readonly sendAll: Send<ActorSelf, EventDefinitions>
56
+ readonly sendAll: Send<ActorSelf, D>
71
57
 
72
58
  readonly disconnectAll: Effect.Effect<void, never, ActorSelf>
73
59
 
74
- readonly handler: <K extends keyof MethodDefinitions, R>(
60
+ readonly handler: <K extends keyof D["methods"], R>(
75
61
  tag: K,
76
- f: Method.Handler<MethodDefinitions[K], R>,
77
- ) => Method.Handler<MethodDefinitions[K], R>
62
+ f: Method.Handler<D["methods"][K], R>,
63
+ ) => Method.Handler<D["methods"][K], R>
78
64
  }
79
65
 
80
66
  export const Service =
@@ -82,18 +68,17 @@ export const Service =
82
68
  <
83
69
  ActorId extends string,
84
70
  NameA,
71
+ D extends ProtocolDefinition,
85
72
  AttachmentFields extends S.Struct.Fields,
86
73
  ClientSelf,
87
74
  ClientId extends string,
88
- MethodDefinitions extends Record<string, MethodDefinition.Any>,
89
- EventDefinitions extends Record<string, S.Struct.Fields>,
90
75
  >(
91
76
  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)
77
+ definition: ActorDefinition<NameA, AttachmentFields, ClientSelf, ClientId, D>,
78
+ ): Actor<ActorSelf, ActorId, NameA, AttachmentFields, ClientSelf, ClientId, D> => {
79
+ const tag = Context.Service<ActorSelf, Service<ActorSelf, NameA, AttachmentFields, D>>()(id)
95
80
 
96
- const sendAll: Send<ActorSelf, EventDefinitions> = (key, payload) =>
81
+ const sendAll: Send<ActorSelf, D> = (key, payload) =>
97
82
  tag.asEffect().pipe(
98
83
  Effect.flatMap(({ clients }) =>
99
84
  Effect.forEach(clients, (client) => client.send(key, payload), { concurrency: "unbounded" }),
@@ -106,16 +91,16 @@ export const Service =
106
91
  span("disconnectAll"),
107
92
  )
108
93
 
109
- const handler = <K extends keyof MethodDefinitions, R>(
94
+ const handler = <K extends keyof D["methods"], R>(
110
95
  _tag: K,
111
- f: Method.Handler<MethodDefinitions[K], R>,
112
- ): Method.Handler<MethodDefinitions[K], R> => f
96
+ f: Method.Handler<D["methods"][K], R>,
97
+ ): Method.Handler<D["methods"][K], R> => f
113
98
 
114
99
  return Object.assign(tag, {
115
100
  [TypeId]: TypeId,
116
101
  definition,
117
- schema: {
118
- attachments: S.Struct(definition.attachments) as never,
102
+ protocol: {
103
+ Attachments: S.Struct(definition.attachments),
119
104
  },
120
105
  sendAll,
121
106
  disconnectAll,
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,11 @@
1
1
  # liminal
2
2
 
3
+ ## 0.17.6
4
+
5
+ ### Patch Changes
6
+
7
+ - d7b1da3: Simplify type-level representation of client protocol.
8
+
3
9
  ## 0.17.5
4
10
 
5
11
  ### Patch Changes