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 +27 -42
- package/Audition.ts +27 -48
- package/CHANGELOG.md +6 -0
- package/Client.ts +86 -164
- package/ClientHandle.ts +6 -13
- package/F.ts +5 -7
- package/Method.ts +5 -13
- package/Protocol.ts +110 -69
- package/Send.ts +5 -9
- package/dist/Actor.d.ts +14 -14
- package/dist/Actor.js +2 -2
- package/dist/Actor.js.map +1 -1
- package/dist/Audition.d.ts +7 -7
- package/dist/Audition.js.map +1 -1
- package/dist/Client.d.ts +23 -28
- package/dist/Client.js +33 -51
- package/dist/Client.js.map +1 -1
- package/dist/ClientHandle.d.ts +6 -5
- package/dist/ClientHandle.js.map +1 -1
- package/dist/F.d.ts +2 -2
- package/dist/F.js +1 -1
- package/dist/F.js.map +1 -1
- package/dist/Method.d.ts +5 -10
- package/dist/Method.js +1 -1
- package/dist/Method.js.map +1 -1
- package/dist/Protocol.d.ts +50 -35
- package/dist/Protocol.js +31 -22
- package/dist/Protocol.js.map +1 -1
- package/dist/Send.d.ts +2 -1
- package/dist/errors.d.ts +3 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/errors.ts +3 -3
- package/package.json +1 -1
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 {
|
|
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,
|
|
18
|
+
readonly currentClient: ClientHandle.ClientHandle<ActorSelf, AttachmentFields, D>
|
|
24
19
|
|
|
25
|
-
readonly clients: ReadonlySet<ClientHandle.ClientHandle<ActorSelf, AttachmentFields,
|
|
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
|
-
|
|
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,
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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,
|
|
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
|
|
60
|
+
readonly handler: <K extends keyof D["methods"], R>(
|
|
75
61
|
tag: K,
|
|
76
|
-
f: Method.Handler<
|
|
77
|
-
) => Method.Handler<
|
|
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,
|
|
93
|
-
): Actor<ActorSelf, ActorId, NameA, AttachmentFields, ClientSelf, ClientId,
|
|
94
|
-
const tag = Context.Service<ActorSelf, Service<ActorSelf, NameA, AttachmentFields,
|
|
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,
|
|
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
|
|
94
|
+
const handler = <K extends keyof D["methods"], R>(
|
|
110
95
|
_tag: K,
|
|
111
|
-
f: Method.Handler<
|
|
112
|
-
): Method.Handler<
|
|
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
|
-
|
|
118
|
-
|
|
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
|
|
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,
|
|
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<
|
|
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,
|
|
23
|
+
readonly f: F<ClientSelf, D>
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
export const empty: Audition<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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
50
|
-
AuditionEvent,
|
|
43
|
+
AuditionD extends ProtocolDefinition,
|
|
51
44
|
ClientSelf,
|
|
52
45
|
ClientId extends string,
|
|
53
|
-
|
|
54
|
-
ClientEventDefinitions extends Record<string, S.Struct.Fields>,
|
|
46
|
+
ClientD extends ProtocolDefinition,
|
|
55
47
|
>(
|
|
56
|
-
audition: Audition<AuditionClientSelf,
|
|
57
|
-
client: Client.Client<ClientSelf, ClientId,
|
|
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
|
-
|
|
68
|
-
AuditionEvent,
|
|
55
|
+
AuditionD extends ProtocolDefinition,
|
|
69
56
|
ClientSelf,
|
|
70
57
|
ClientId extends string,
|
|
71
|
-
|
|
72
|
-
ClientEventDefinitions extends Record<string, S.Struct.Fields>,
|
|
58
|
+
ClientD extends ProtocolDefinition,
|
|
73
59
|
>(
|
|
74
|
-
audition: Audition<AuditionSelf,
|
|
75
|
-
client: Client.Client<ClientSelf, ClientId,
|
|
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
|
|
65
|
+
.f(method)(payload)
|
|
87
66
|
.pipe(
|
|
88
|
-
Effect.catchTag("AuditionError", () => client.f(method
|
|
67
|
+
Effect.catchTag("AuditionError", () => client.f(method)(payload)),
|
|
89
68
|
span("f"),
|
|
90
69
|
)
|
|
91
70
|
|