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.
- package/Actor.ts +29 -45
- package/ActorTransport.ts +17 -0
- package/Audition.ts +27 -48
- package/CHANGELOG.md +12 -0
- package/Client.ts +104 -173
- package/ClientDirectory.ts +104 -0
- package/ClientHandle.ts +6 -13
- package/F.ts +5 -7
- package/Method.ts +5 -13
- package/Protocol.ts +85 -68
- package/Send.ts +5 -9
- package/_util/schema.ts +7 -0
- package/dist/Actor.d.ts +15 -17
- package/dist/Actor.js +1 -3
- package/dist/Actor.js.map +1 -1
- package/dist/ActorTransport.d.ts +7 -0
- package/dist/ActorTransport.js +2 -0
- package/dist/ActorTransport.js.map +1 -0
- 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 +63 -67
- package/dist/Client.js.map +1 -1
- package/dist/ClientDirectory.d.ts +21 -0
- package/dist/ClientDirectory.js +41 -0
- package/dist/ClientDirectory.js.map +1 -0
- 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 +51 -34
- package/dist/Protocol.js +20 -22
- package/dist/Protocol.js.map +1 -1
- package/dist/Send.d.ts +2 -1
- package/dist/_util/schema.d.ts +4 -0
- package/dist/_util/schema.js +5 -0
- package/dist/_util/schema.js.map +1 -0
- package/dist/errors.d.ts +5 -5
- package/dist/errors.js +2 -2
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/errors.ts +5 -5
- package/index.ts +2 -0
- 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
|
-
|
|
18
|
+
Name extends TopFromString,
|
|
18
19
|
AttachmentFields extends S.Struct.Fields,
|
|
19
|
-
|
|
20
|
+
D extends ProtocolDefinition,
|
|
20
21
|
> {
|
|
21
|
-
readonly name:
|
|
22
|
+
readonly name: Name["Type"]
|
|
22
23
|
|
|
23
|
-
readonly currentClient: ClientHandle.ClientHandle<ActorSelf, AttachmentFields,
|
|
24
|
+
readonly currentClient: ClientHandle.ClientHandle<ActorSelf, AttachmentFields, D>
|
|
24
25
|
|
|
25
|
-
readonly clients: ReadonlySet<ClientHandle.ClientHandle<ActorSelf, AttachmentFields,
|
|
26
|
+
readonly clients: ReadonlySet<ClientHandle.ClientHandle<ActorSelf, AttachmentFields, D>>
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
export interface ActorDefinition<
|
|
29
|
-
|
|
30
|
+
Name extends TopFromString,
|
|
30
31
|
AttachmentFields extends S.Struct.Fields,
|
|
31
32
|
ClientSelf,
|
|
32
33
|
ClientId extends string,
|
|
33
|
-
|
|
34
|
-
EventDefinitions extends Record<string, S.Struct.Fields>,
|
|
34
|
+
D extends ProtocolDefinition,
|
|
35
35
|
> {
|
|
36
|
-
readonly name:
|
|
36
|
+
readonly name: Name
|
|
37
37
|
|
|
38
38
|
readonly attachments: AttachmentFields
|
|
39
39
|
|
|
40
|
-
readonly client: ActorClient.Client<ClientSelf, ClientId,
|
|
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
|
-
|
|
46
|
+
Name extends TopFromString,
|
|
47
47
|
AttachmentFields extends S.Struct.Fields,
|
|
48
48
|
ActorClientSelf,
|
|
49
49
|
ActorClientId extends string,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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,
|
|
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
|
|
62
|
+
readonly handler: <K extends keyof D["methods"], R>(
|
|
75
63
|
tag: K,
|
|
76
|
-
f: Method.Handler<
|
|
77
|
-
) => Method.Handler<
|
|
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
|
-
|
|
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<
|
|
93
|
-
): Actor<ActorSelf, ActorId,
|
|
94
|
-
const tag = Context.Service<ActorSelf, Service<ActorSelf,
|
|
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,
|
|
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
|
|
96
|
+
const handler = <K extends keyof D["methods"], R>(
|
|
110
97
|
_tag: K,
|
|
111
|
-
f: Method.Handler<
|
|
112
|
-
): Method.Handler<
|
|
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
|
|
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
|
|
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
|