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/Method.ts
CHANGED
|
@@ -6,17 +6,9 @@ export interface MethodDefinition<Payload extends S.Top, Success extends S.Top,
|
|
|
6
6
|
readonly failure: Failure
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export
|
|
10
|
-
export type Any = MethodDefinition<S.Top, S.Top, S.Top>
|
|
9
|
+
export type Any = MethodDefinition<S.Top, S.Top, S.Top>
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
? U
|
|
14
|
-
: {
|
|
15
|
-
[K in keyof T & keyof U]: T[K] extends U[K] ? (U[K] extends T[K] ? T[K] : never) : never
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const define = <Payload extends S.Top, Success extends S.Top, Failure extends S.Top>({
|
|
11
|
+
export const make = <Payload extends S.Top, Success extends S.Top, Failure extends S.Top>({
|
|
20
12
|
payload,
|
|
21
13
|
success,
|
|
22
14
|
failure,
|
|
@@ -26,12 +18,12 @@ export const define = <Payload extends S.Top, Success extends S.Top, Failure ext
|
|
|
26
18
|
readonly failure: Failure
|
|
27
19
|
}): MethodDefinition<Payload, Success, Failure> => ({ payload, success, failure })
|
|
28
20
|
|
|
29
|
-
export type Handler<MethodDefinition extends
|
|
21
|
+
export type Handler<MethodDefinition extends Any, R> = (
|
|
30
22
|
payload: MethodDefinition["payload"]["Type"],
|
|
31
23
|
) => Effect.Effect<MethodDefinition["success"]["Type"], MethodDefinition["failure"]["Type"], R>
|
|
32
24
|
|
|
33
|
-
export type Handlers<MethodDefinitions extends Record<string,
|
|
25
|
+
export type Handlers<MethodDefinitions extends Record<string, Any>, R> = {
|
|
34
26
|
[K in keyof MethodDefinitions]: Handler<MethodDefinitions[K], R>
|
|
35
27
|
}
|
|
36
28
|
|
|
37
|
-
export const handler = <M extends
|
|
29
|
+
export const handler = <M extends Any, R>(_method: M, f: Handler<M, R>): Handler<M, R> => f
|
package/Protocol.ts
CHANGED
|
@@ -1,120 +1,137 @@
|
|
|
1
|
-
import { Schema as S, Record } from "effect"
|
|
1
|
+
import { Schema as S, Record, Types } from "effect"
|
|
2
2
|
|
|
3
|
-
import type
|
|
3
|
+
import type * as Method from "./Method.ts"
|
|
4
4
|
|
|
5
|
-
export
|
|
5
|
+
export interface ProtocolDefinition<
|
|
6
|
+
Methods extends Record<string, Method.Any> = Record<string, Method.Any>,
|
|
7
|
+
Events extends Record<string, S.Struct.Fields> = Record<string, S.Struct.Fields>,
|
|
8
|
+
> {
|
|
9
|
+
readonly methods: Methods
|
|
6
10
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
routed: S.String,
|
|
10
|
-
})
|
|
11
|
+
readonly events: Events
|
|
12
|
+
}
|
|
11
13
|
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
export declare namespace ProtocolDefinition {
|
|
15
|
+
export type Merge<T extends ProtocolDefinition, U extends ProtocolDefinition> = ProtocolDefinition<
|
|
16
|
+
[T] extends [never]
|
|
17
|
+
? U["methods"]
|
|
18
|
+
: {
|
|
19
|
+
[K in keyof T["methods"] & keyof U["methods"] as Types.Equals<T["methods"][K], U["methods"][K]> extends true
|
|
20
|
+
? K
|
|
21
|
+
: never]: T["methods"][K]
|
|
22
|
+
},
|
|
23
|
+
[T] extends [never] ? U["events"] : T["events"] & U["events"]
|
|
24
|
+
>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface Protocol<D extends ProtocolDefinition> {
|
|
28
|
+
readonly Audition: {
|
|
29
|
+
readonly Payload: S.TaggedStruct<"Audition.Payload", { client: S.String }>
|
|
30
|
+
readonly Success: S.TaggedStruct<"Audition.Success", {}>
|
|
31
|
+
readonly Failure: S.TaggedStruct<
|
|
32
|
+
"Audition.Failure",
|
|
33
|
+
{
|
|
34
|
+
expected: S.String
|
|
35
|
+
actual: S.String
|
|
36
|
+
}
|
|
37
|
+
>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
readonly Event: S.TaggedStruct<
|
|
41
|
+
"Event",
|
|
42
|
+
{
|
|
43
|
+
readonly event: S.TaggedUnion<{
|
|
44
|
+
readonly [K in keyof D["events"] & string]: S.TaggedStruct<K, D["events"][K]>
|
|
45
|
+
}>
|
|
46
|
+
}
|
|
47
|
+
>
|
|
48
|
+
|
|
49
|
+
readonly F: {
|
|
50
|
+
readonly Payload: S.TaggedStruct<
|
|
51
|
+
"F.Payload",
|
|
19
52
|
{
|
|
20
53
|
readonly id: S.Int
|
|
21
54
|
readonly payload: S.TaggedUnion<{
|
|
22
|
-
readonly [K in keyof
|
|
23
|
-
K,
|
|
24
|
-
{ readonly value: MethodDefinitions[K]["payload"] }
|
|
25
|
-
>
|
|
55
|
+
readonly [K in keyof D["methods"] & string]: S.TaggedStruct<K, { readonly value: D["methods"][K]["payload"] }>
|
|
26
56
|
}>
|
|
27
57
|
}
|
|
28
58
|
>
|
|
29
59
|
|
|
30
|
-
readonly
|
|
31
|
-
"
|
|
60
|
+
readonly Success: S.TaggedStruct<
|
|
61
|
+
"F.Success",
|
|
32
62
|
{
|
|
33
63
|
readonly id: S.Int
|
|
34
64
|
readonly success: S.TaggedUnion<{
|
|
35
|
-
readonly [K in keyof
|
|
36
|
-
K,
|
|
37
|
-
{ readonly value: MethodDefinitions[K]["success"] }
|
|
38
|
-
>
|
|
65
|
+
readonly [K in keyof D["methods"] & string]: S.TaggedStruct<K, { readonly value: D["methods"][K]["success"] }>
|
|
39
66
|
}>
|
|
40
67
|
}
|
|
41
68
|
>
|
|
42
69
|
|
|
43
|
-
readonly
|
|
44
|
-
"
|
|
70
|
+
readonly Failure: S.TaggedStruct<
|
|
71
|
+
"F.Failure",
|
|
45
72
|
{
|
|
46
73
|
readonly id: S.Int
|
|
47
74
|
readonly failure: S.TaggedUnion<{
|
|
48
|
-
readonly [K in keyof
|
|
49
|
-
K,
|
|
50
|
-
{ readonly value: MethodDefinitions[K]["failure"] }
|
|
51
|
-
>
|
|
75
|
+
readonly [K in keyof D["methods"] & string]: S.TaggedStruct<K, { readonly value: D["methods"][K]["failure"] }>
|
|
52
76
|
}>
|
|
53
77
|
}
|
|
54
78
|
>
|
|
55
79
|
}
|
|
56
80
|
|
|
57
|
-
readonly
|
|
58
|
-
"Event",
|
|
59
|
-
{
|
|
60
|
-
readonly event: S.TaggedUnion<{
|
|
61
|
-
readonly [K in keyof EventDefinitions & string]: S.TaggedStruct<K, EventDefinitions[K]>
|
|
62
|
-
}>
|
|
63
|
-
}
|
|
64
|
-
>
|
|
81
|
+
readonly Disconnect: S.TaggedStruct<"Disconnect", {}>
|
|
65
82
|
|
|
66
|
-
readonly
|
|
83
|
+
readonly Client: S.Union<[this["Audition"]["Payload"], this["F"]["Payload"], this["Disconnect"]]>
|
|
84
|
+
|
|
85
|
+
readonly Actor: S.Union<
|
|
67
86
|
[
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this["
|
|
71
|
-
this["
|
|
72
|
-
this["
|
|
73
|
-
|
|
87
|
+
this["Audition"]["Success"],
|
|
88
|
+
this["Audition"]["Failure"],
|
|
89
|
+
this["F"]["Success"],
|
|
90
|
+
this["F"]["Failure"],
|
|
91
|
+
this["Event"],
|
|
92
|
+
this["Disconnect"],
|
|
74
93
|
]
|
|
75
94
|
>
|
|
76
95
|
}
|
|
77
96
|
|
|
78
97
|
export const Disconnect = S.TaggedStruct("Disconnect", {})
|
|
79
98
|
|
|
80
|
-
|
|
99
|
+
const Audition = {
|
|
100
|
+
Payload: S.TaggedStruct("Audition.Payload", {
|
|
101
|
+
client: S.String,
|
|
102
|
+
}),
|
|
103
|
+
Success: S.TaggedStruct("Audition.Success", {}),
|
|
104
|
+
Failure: S.TaggedStruct("Audition.Failure", {
|
|
105
|
+
expected: S.String,
|
|
106
|
+
actual: S.String,
|
|
107
|
+
}),
|
|
108
|
+
}
|
|
81
109
|
|
|
82
|
-
export const
|
|
83
|
-
|
|
84
|
-
EventDefinitions extends Record<string, S.Struct.Fields>,
|
|
85
|
-
>(
|
|
86
|
-
methods: MethodDefinitions,
|
|
87
|
-
events: EventDefinitions,
|
|
88
|
-
): ProtocolSchemas<MethodDefinitions, EventDefinitions> => {
|
|
89
|
-
type T = ProtocolSchemas<MethodDefinitions, EventDefinitions>
|
|
110
|
+
export const Protocol = <D extends ProtocolDefinition>({ events, methods }: D): Protocol<D> => {
|
|
111
|
+
type T = Protocol<D>
|
|
90
112
|
|
|
91
|
-
const
|
|
92
|
-
|
|
113
|
+
const F: T["F"] = {
|
|
114
|
+
Payload: S.TaggedStruct("F.Payload", {
|
|
93
115
|
id: S.Int,
|
|
94
116
|
payload: S.TaggedUnion(Record.map(methods, ({ payload: value }) => ({ value }))),
|
|
95
117
|
}) as never,
|
|
96
|
-
|
|
118
|
+
Success: S.TaggedStruct("F.Success", {
|
|
97
119
|
id: S.Int,
|
|
98
120
|
success: S.TaggedUnion(Record.map(methods, ({ success: value }) => ({ value }))),
|
|
99
121
|
}) as never,
|
|
100
|
-
|
|
122
|
+
Failure: S.TaggedStruct("F.Failure", {
|
|
101
123
|
id: S.Int,
|
|
102
124
|
failure: S.TaggedUnion(Record.map(methods, ({ failure: value }) => ({ value }))),
|
|
103
125
|
}) as never,
|
|
104
126
|
}
|
|
105
127
|
|
|
106
|
-
const
|
|
128
|
+
const Event: T["Event"] = S.TaggedStruct("Event", {
|
|
107
129
|
event: S.TaggedUnion(events),
|
|
108
130
|
}) as never
|
|
109
131
|
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
f.success,
|
|
114
|
-
f.failure,
|
|
115
|
-
event,
|
|
116
|
-
Disconnect,
|
|
117
|
-
]) as never
|
|
132
|
+
const Client: T["Client"] = S.Union([Audition.Payload, F.Payload, Disconnect])
|
|
133
|
+
|
|
134
|
+
const Actor: T["Actor"] = S.Union([Audition.Success, Audition.Failure, F.Success, F.Failure, Event, Disconnect])
|
|
118
135
|
|
|
119
|
-
return {
|
|
136
|
+
return { Audition, Event, F, Client, Actor, Disconnect }
|
|
120
137
|
}
|
package/Send.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { Schema as S, Effect } from "effect"
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
>(
|
|
3
|
+
import type { ProtocolDefinition } from "./Protocol.ts"
|
|
4
|
+
|
|
5
|
+
export type Send<ActorSelf, D extends ProtocolDefinition> = <K extends keyof D["events"]>(
|
|
6
6
|
tag: K,
|
|
7
|
-
payload: S.Struct<
|
|
8
|
-
) => Effect.Effect<
|
|
9
|
-
void,
|
|
10
|
-
S.SchemaError,
|
|
11
|
-
ActorSelf | ReturnType<typeof S.TaggedUnion<EventDefinitions>>["EncodingServices"]
|
|
12
|
-
>
|
|
7
|
+
payload: S.Struct<D["events"][K]>["Type"],
|
|
8
|
+
) => Effect.Effect<void, S.SchemaError, ActorSelf | ReturnType<typeof S.TaggedUnion<D["events"]>>["EncodingServices"]>
|
package/_util/schema.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Schema as S, flow } from "effect"
|
|
2
|
+
|
|
3
|
+
export type TopFromString = S.Codec<any, string, any, any>
|
|
4
|
+
|
|
5
|
+
const toJsonStringCodec = flow(S.toCodecJson, S.fromJsonString)
|
|
6
|
+
export const encodeJsonString = flow(toJsonStringCodec, S.encodeEffect)
|
|
7
|
+
export const decodeJsonString = flow(toJsonStringCodec, S.decodeUnknownEffect)
|
package/dist/Actor.d.ts
CHANGED
|
@@ -1,29 +1,27 @@
|
|
|
1
1
|
import { Context, Schema as S, Effect } from "effect";
|
|
2
|
+
import type { TopFromString } from "./_util/schema.ts";
|
|
2
3
|
import type * as ActorClient from "./Client.ts";
|
|
3
4
|
import type * as ClientHandle from "./ClientHandle.ts";
|
|
4
|
-
import type { MethodDefinition } from "./Method.ts";
|
|
5
5
|
import type { Send } from "./Send.ts";
|
|
6
6
|
import * as Method from "./Method.ts";
|
|
7
|
+
import { type ProtocolDefinition } from "./Protocol.ts";
|
|
7
8
|
export declare const TypeId: "~liminal/Actor";
|
|
8
|
-
export interface Service<ActorSelf,
|
|
9
|
-
readonly name:
|
|
10
|
-
readonly currentClient: ClientHandle.ClientHandle<ActorSelf, AttachmentFields,
|
|
11
|
-
readonly clients: ReadonlySet<ClientHandle.ClientHandle<ActorSelf, AttachmentFields,
|
|
9
|
+
export interface Service<ActorSelf, Name extends TopFromString, AttachmentFields extends S.Struct.Fields, D extends ProtocolDefinition> {
|
|
10
|
+
readonly name: Name["Type"];
|
|
11
|
+
readonly currentClient: ClientHandle.ClientHandle<ActorSelf, AttachmentFields, D>;
|
|
12
|
+
readonly clients: ReadonlySet<ClientHandle.ClientHandle<ActorSelf, AttachmentFields, D>>;
|
|
12
13
|
}
|
|
13
|
-
export interface ActorDefinition<
|
|
14
|
-
readonly name:
|
|
14
|
+
export interface ActorDefinition<Name extends TopFromString, AttachmentFields extends S.Struct.Fields, ClientSelf, ClientId extends string, D extends ProtocolDefinition> {
|
|
15
|
+
readonly name: Name;
|
|
15
16
|
readonly attachments: AttachmentFields;
|
|
16
|
-
readonly client: ActorClient.Client<ClientSelf, ClientId,
|
|
17
|
+
readonly client: ActorClient.Client<ClientSelf, ClientId, D>;
|
|
17
18
|
}
|
|
18
|
-
export interface Actor<ActorSelf, ActorId extends string,
|
|
19
|
-
new (_: never): Context.ServiceClass.Shape<ActorId, Service<ActorSelf,
|
|
19
|
+
export interface Actor<ActorSelf, ActorId extends string, Name extends TopFromString, AttachmentFields extends S.Struct.Fields, ActorClientSelf, ActorClientId extends string, D extends ProtocolDefinition> extends Context.Service<ActorSelf, Service<ActorSelf, Name, AttachmentFields, D>> {
|
|
20
|
+
new (_: never): Context.ServiceClass.Shape<ActorId, Service<ActorSelf, Name, AttachmentFields, D>>;
|
|
20
21
|
readonly [TypeId]: typeof TypeId;
|
|
21
|
-
readonly definition: ActorDefinition<
|
|
22
|
-
readonly
|
|
23
|
-
readonly attachments: S.Codec<S.Struct<AttachmentFields>["Type"], S.Struct<AttachmentFields>["Encoded"]>;
|
|
24
|
-
};
|
|
25
|
-
readonly sendAll: Send<ActorSelf, EventDefinitions>;
|
|
22
|
+
readonly definition: ActorDefinition<Name, AttachmentFields, ActorClientSelf, ActorClientId, D>;
|
|
23
|
+
readonly sendAll: Send<ActorSelf, D>;
|
|
26
24
|
readonly disconnectAll: Effect.Effect<void, never, ActorSelf>;
|
|
27
|
-
readonly handler: <K extends keyof
|
|
25
|
+
readonly handler: <K extends keyof D["methods"], R>(tag: K, f: Method.Handler<D["methods"][K], R>) => Method.Handler<D["methods"][K], R>;
|
|
28
26
|
}
|
|
29
|
-
export declare const Service: <ActorSelf>() => <ActorId extends string,
|
|
27
|
+
export declare const Service: <ActorSelf>() => <ActorId extends string, Name extends TopFromString, D extends ProtocolDefinition, AttachmentFields extends S.Struct.Fields, ClientSelf, ClientId extends string>(id: ActorId, definition: ActorDefinition<Name, AttachmentFields, ClientSelf, ClientId, D>) => Actor<ActorSelf, ActorId, Name, AttachmentFields, ClientSelf, ClientId, D>;
|
package/dist/Actor.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Context, Schema as S, Effect } from "effect";
|
|
2
2
|
import * as Diagnostic from "./_util/Diagnostic.js";
|
|
3
3
|
import * as Method from "./Method.js";
|
|
4
|
+
import {} from "./Protocol.js";
|
|
4
5
|
const { span } = Diagnostic.module("Actor");
|
|
5
6
|
export const TypeId = "~liminal/Actor";
|
|
6
7
|
export const Service = () => (id, definition) => {
|
|
@@ -11,9 +12,6 @@ export const Service = () => (id, definition) => {
|
|
|
11
12
|
return Object.assign(tag, {
|
|
12
13
|
[TypeId]: TypeId,
|
|
13
14
|
definition,
|
|
14
|
-
schema: {
|
|
15
|
-
attachments: S.Struct(definition.attachments),
|
|
16
|
-
},
|
|
17
15
|
sendAll,
|
|
18
16
|
disconnectAll,
|
|
19
17
|
handler,
|
package/dist/Actor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Actor.js","sourceRoot":"","sources":["../Actor.ts"],"names":[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AAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EACxF,IAAI,CAAC,eAAe,CAAC,CACtB,CAAA;IAED,MAAM,OAAO,GAAG,CACd,IAAO,EACP,CAAqC,EACD,EAAE,CAAC,CAAC,CAAA;IAE1C,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE;QACxB,CAAC,MAAM,CAAC,EAAE,MAAM;QAChB,UAAU;QACV,OAAO;QACP,aAAa;QACb,OAAO;KACR,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Effect, Schema as S } from "effect";
|
|
2
|
+
import type { Protocol, ProtocolDefinition } from "./Protocol.ts";
|
|
3
|
+
export interface ActorTransport<Raw, AttachmentFields extends S.Struct.Fields, D extends ProtocolDefinition> {
|
|
4
|
+
readonly send: (transport: Raw, event: Protocol<D>["Event"]["Type"]) => Effect.Effect<void, S.SchemaError, Protocol<D>["Event"]["EncodingServices"]>;
|
|
5
|
+
readonly close: (transport: Raw) => Effect.Effect<void>;
|
|
6
|
+
readonly snapshot: (transport: Raw, attachments: S.Struct<AttachmentFields>["Type"]) => Effect.Effect<void, S.SchemaError, S.Struct<AttachmentFields>["EncodingServices"]>;
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ActorTransport.js","sourceRoot":"","sources":["../ActorTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,QAAQ,CAAA"}
|
package/dist/Audition.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { Schema as S, Pipeable, Stream } from "effect";
|
|
2
2
|
import type { F } from "./F.ts";
|
|
3
|
-
import type
|
|
3
|
+
import type { ProtocolDefinition } from "./Protocol.ts";
|
|
4
4
|
import * as Client from "./Client.ts";
|
|
5
5
|
import { type ClientError } from "./errors.ts";
|
|
6
6
|
declare const TypeId: "~liminal/Audition";
|
|
7
|
-
export interface Audition<ClientSelf,
|
|
7
|
+
export interface Audition<ClientSelf, D extends ProtocolDefinition> extends Pipeable.Pipeable {
|
|
8
8
|
readonly [TypeId]: typeof TypeId;
|
|
9
|
-
readonly events: Stream.Stream<
|
|
10
|
-
readonly f: F<ClientSelf,
|
|
9
|
+
readonly events: Stream.Stream<ReturnType<typeof S.TaggedUnion<D["events"]>>["Type"], ClientError | S.SchemaError, ClientSelf>;
|
|
10
|
+
readonly f: F<ClientSelf, D>;
|
|
11
11
|
}
|
|
12
|
-
export declare const empty: Audition<never, never
|
|
12
|
+
export declare const empty: Audition<never, never>;
|
|
13
13
|
export declare const add: {
|
|
14
|
-
<ClientSelf, ClientId extends string,
|
|
15
|
-
<AuditionClientSelf,
|
|
14
|
+
<ClientSelf, ClientId extends string, ClientD extends ProtocolDefinition>(client: Client.Client<ClientSelf, ClientId, ClientD>): <AuditionSelf, AuditionD extends ProtocolDefinition>(audition: Audition<AuditionSelf, AuditionD>) => Audition<AuditionSelf | ClientSelf, ProtocolDefinition.Merge<AuditionD, ClientD>>;
|
|
15
|
+
<AuditionClientSelf, AuditionD extends ProtocolDefinition, ClientSelf, ClientId extends string, ClientD extends ProtocolDefinition>(audition: Audition<AuditionClientSelf, AuditionD>, client: Client.Client<ClientSelf, ClientId, ClientD>): Audition<AuditionClientSelf | ClientSelf, ProtocolDefinition.Merge<AuditionD, ClientD>>;
|
|
16
16
|
};
|
|
17
17
|
export {};
|
package/dist/Audition.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Audition.js","sourceRoot":"","sources":["../Audition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAA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AAO,EAAE,EAAE,CAC5G,QAAQ;SACL,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;SAClB,IAAI,CACH,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,EACjE,IAAI,CAAC,GAAG,CAAC,CACV,CAAA;IAEL,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CACjC,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE,CACpC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAChC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,gBAAgB,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,EACjE,MAAM,CAAC,MAAM,CACd,CACF,CACF,CAAA;IAED,OAAO;QACL,CAAC,MAAM,CAAC,EAAE,MAAM;QAChB,IAAI;YACF,OAAO,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;QAChD,CAAC;QACD,MAAM;QACN,CAAC;KACF,CAAA;AACH,CAAC,CACF,CAAA"}
|
package/dist/Client.d.ts
CHANGED
|
@@ -1,46 +1,41 @@
|
|
|
1
1
|
import { Context, Effect, Layer, RcRef, Scope, Stream, Schema as S } from "effect";
|
|
2
2
|
import { Socket } from "effect/unstable/socket";
|
|
3
3
|
import { Worker } from "effect/unstable/workers";
|
|
4
|
-
import type
|
|
5
|
-
import { type ClientError, ConnectionError } from "./errors.ts";
|
|
4
|
+
import { type ClientError } from "./errors.ts";
|
|
6
5
|
import { type F } from "./F.ts";
|
|
7
|
-
import
|
|
6
|
+
import { Protocol, type ProtocolDefinition } from "./Protocol.ts";
|
|
8
7
|
export declare const TypeId: "~liminal/Client";
|
|
9
|
-
export interface ClientDefinition<MethodDefinitions extends Record<string, MethodDefinition.Any>, EventDefinitions extends Record<string, S.Struct.Fields>> {
|
|
10
|
-
readonly methods: MethodDefinitions;
|
|
11
|
-
readonly events: EventDefinitions;
|
|
12
|
-
}
|
|
13
8
|
export interface ReplayConfig {
|
|
14
9
|
readonly mode: "startup" | "all-subscribers";
|
|
15
10
|
readonly limit?: number | undefined;
|
|
16
11
|
}
|
|
17
|
-
export interface Session<
|
|
18
|
-
readonly events: Stream.Stream<ReturnType<typeof S.TaggedUnion<
|
|
19
|
-
readonly f: F<
|
|
12
|
+
export interface Session<Self, D extends ProtocolDefinition> {
|
|
13
|
+
readonly events: Stream.Stream<ReturnType<typeof S.TaggedUnion<D["events"]>>["Type"], ClientError | S.SchemaError>;
|
|
14
|
+
readonly f: F<Self, D>;
|
|
20
15
|
readonly end: Effect.Effect<void>;
|
|
21
16
|
}
|
|
22
|
-
export type Service<ClientSelf,
|
|
23
|
-
export interface Client<
|
|
24
|
-
new (_: never): Context.ServiceClass.Shape<ClientId, Service<
|
|
17
|
+
export type Service<ClientSelf, D extends ProtocolDefinition> = RcRef.RcRef<Session<ClientSelf, D>, ClientError>;
|
|
18
|
+
export interface Client<Self, ClientId extends string, D extends ProtocolDefinition> extends Context.Service<Self, Service<Self, D>> {
|
|
19
|
+
new (_: never): Context.ServiceClass.Shape<ClientId, Service<Self, D>>;
|
|
25
20
|
readonly [TypeId]: typeof TypeId;
|
|
26
|
-
readonly definition:
|
|
27
|
-
readonly
|
|
28
|
-
readonly events: Stream.Stream<ReturnType<typeof S.TaggedUnion<
|
|
29
|
-
readonly f: F<
|
|
30
|
-
readonly invalidate: Effect.Effect<void, never,
|
|
21
|
+
readonly definition: D;
|
|
22
|
+
readonly protocol: Protocol<D>;
|
|
23
|
+
readonly events: Stream.Stream<ReturnType<typeof S.TaggedUnion<D["events"]>>["Type"], ClientError | S.SchemaError, Self>;
|
|
24
|
+
readonly f: F<Self, D>;
|
|
25
|
+
readonly invalidate: Effect.Effect<void, never, Self>;
|
|
31
26
|
}
|
|
32
|
-
export declare const Service: <
|
|
33
|
-
export interface
|
|
34
|
-
readonly listen: (publish: (message: Protocol
|
|
35
|
-
readonly send: (message: Protocol
|
|
27
|
+
export declare const Service: <Self>() => <Id extends string, D extends ProtocolDefinition>(id: Id, definition: D) => Client<Self, Id, D>;
|
|
28
|
+
export interface ClientTransport<D extends ProtocolDefinition> {
|
|
29
|
+
readonly listen: (publish: (message: Protocol<D>["Actor"]["Type"]) => Effect.Effect<void, ClientError>) => Effect.Effect<void, ClientError | S.SchemaError, Scope.Scope | Protocol<D>["Actor"]["DecodingServices"]>;
|
|
30
|
+
readonly send: (message: Protocol<D>["F"]["Payload"]["Type"]) => Effect.Effect<void, ClientError | S.SchemaError, Protocol<D>["F"]["Payload"]["EncodingServices"]>;
|
|
36
31
|
}
|
|
37
|
-
export declare const layerSocket: <
|
|
38
|
-
readonly client: Client<
|
|
32
|
+
export declare const layerSocket: <Self, Id extends string, D extends ProtocolDefinition>({ client, url, protocols, replay, }: {
|
|
33
|
+
readonly client: Client<Self, Id, D>;
|
|
39
34
|
readonly url?: string | undefined;
|
|
40
35
|
readonly protocols?: string | Array<string> | undefined;
|
|
41
36
|
readonly replay?: ReplayConfig | undefined;
|
|
42
|
-
}) => Layer.Layer<
|
|
43
|
-
export declare const layerWorker: <
|
|
44
|
-
readonly client: Client<
|
|
37
|
+
}) => Layer.Layer<Self, never, Socket.WebSocketConstructor | Protocol<D>["Actor"]["DecodingServices"] | Protocol<D>["F"]["Payload"]["EncodingServices"]>;
|
|
38
|
+
export declare const layerWorker: <Self, Id extends string, D extends ProtocolDefinition, T extends Protocol<D>>({ client, replay, }: {
|
|
39
|
+
readonly client: Client<Self, Id, D>;
|
|
45
40
|
readonly replay?: ReplayConfig | undefined;
|
|
46
|
-
}) => Layer.Layer<
|
|
41
|
+
}) => Layer.Layer<Self, never, Worker.WorkerPlatform | Worker.Spawner | T["Actor"]["DecodingServices"] | T["F"]["Payload"]["EncodingServices"]>;
|