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/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 declare namespace MethodDefinition {
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
- export type Merge<T, U> = [T] extends [never]
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 MethodDefinition.Any, R> = (
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, MethodDefinition.Any>, R> = {
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 MethodDefinition.Any, R>(_method: M, f: Handler<M, R>): Handler<M, R> => f
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 { MethodDefinition } from "./Method.ts"
3
+ import type * as Method from "./Method.ts"
4
4
 
5
- export const AuditionSuccess = S.TaggedStruct("AuditionSuccess", {})
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
- export const AuditionFailure = S.TaggedStruct("AuditionFailure", {
8
- client: S.String,
9
- routed: S.String,
10
- })
11
+ readonly events: Events
12
+ }
11
13
 
12
- export interface ProtocolSchemas<
13
- MethodDefinitions extends Record<string, MethodDefinition.Any>,
14
- EventDefinitions extends Record<string, S.Struct.Fields>,
15
- > {
16
- readonly f: {
17
- readonly payload: S.TaggedStruct<
18
- "FPayload",
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 MethodDefinitions & string]: S.TaggedStruct<
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 success: S.TaggedStruct<
31
- "FSuccess",
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 MethodDefinitions & string]: S.TaggedStruct<
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 failure: S.TaggedStruct<
44
- "FFailure",
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 MethodDefinitions & string]: S.TaggedStruct<
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 event: S.TaggedStruct<
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 actor: S.Union<
83
+ readonly Client: S.Union<[this["Audition"]["Payload"], this["F"]["Payload"], this["Disconnect"]]>
84
+
85
+ readonly Actor: S.Union<
67
86
  [
68
- typeof AuditionSuccess,
69
- typeof AuditionFailure,
70
- this["f"]["success"],
71
- this["f"]["failure"],
72
- this["event"],
73
- typeof Disconnect,
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
- export const TransportFailure = S.TaggedStruct("TransportFailure", { cause: S.Unknown })
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 ProtocolSchemas = <
83
- MethodDefinitions extends Record<string, MethodDefinition.Any>,
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 f: T["f"] = {
92
- payload: S.TaggedStruct("FPayload", {
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
- success: S.TaggedStruct("FSuccess", {
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
- failure: S.TaggedStruct("FFailure", {
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 event: T["event"] = S.TaggedStruct("Event", {
128
+ const Event: T["Event"] = S.TaggedStruct("Event", {
107
129
  event: S.TaggedUnion(events),
108
130
  }) as never
109
131
 
110
- const actor: T["actor"] = S.Union([
111
- AuditionSuccess,
112
- AuditionFailure,
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 { f, event, actor }
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
- export type Send<ActorSelf, EventDefinitions extends Record<string, S.Struct.Fields>> = <
4
- K extends keyof EventDefinitions,
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<EventDefinitions[K]>["Type"],
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"]>
@@ -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, NameA, AttachmentFields extends S.Struct.Fields, EventDefinitions extends Record<string, S.Struct.Fields>> {
9
- readonly name: NameA;
10
- readonly currentClient: ClientHandle.ClientHandle<ActorSelf, AttachmentFields, EventDefinitions>;
11
- readonly clients: ReadonlySet<ClientHandle.ClientHandle<ActorSelf, AttachmentFields, EventDefinitions>>;
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<NameA, AttachmentFields extends S.Struct.Fields, ClientSelf, ClientId extends string, MethodDefinitions extends Record<string, MethodDefinition.Any>, EventDefinitions extends Record<string, S.Struct.Fields>> {
14
- readonly name: S.Codec<NameA, string>;
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, MethodDefinitions, EventDefinitions>;
17
+ readonly client: ActorClient.Client<ClientSelf, ClientId, D>;
17
18
  }
18
- export interface Actor<ActorSelf, ActorId extends string, NameA, AttachmentFields extends S.Struct.Fields, ActorClientSelf, ActorClientId extends string, MethodDefinitions extends Record<string, MethodDefinition.Any>, EventDefinitions extends Record<string, S.Struct.Fields>> extends Context.Service<ActorSelf, Service<ActorSelf, NameA, AttachmentFields, EventDefinitions>> {
19
- new (_: never): Context.ServiceClass.Shape<ActorId, Service<ActorSelf, NameA, AttachmentFields, EventDefinitions>>;
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<NameA, AttachmentFields, ActorClientSelf, ActorClientId, MethodDefinitions, EventDefinitions>;
22
- readonly schema: {
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 MethodDefinitions, R>(tag: K, f: Method.Handler<MethodDefinitions[K], R>) => Method.Handler<MethodDefinitions[K], R>;
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, NameA, AttachmentFields extends S.Struct.Fields, ClientSelf, ClientId extends string, MethodDefinitions extends Record<string, MethodDefinition.Any>, EventDefinitions extends Record<string, S.Struct.Fields>>(id: ActorId, definition: ActorDefinition<NameA, AttachmentFields, ClientSelf, ClientId, MethodDefinitions, EventDefinitions>) => Actor<ActorSelf, ActorId, NameA, AttachmentFields, ClientSelf, ClientId, MethodDefinitions, EventDefinitions>;
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":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAOrD,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAA;AACnD,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;AAE3C,MAAM,CAAC,MAAM,MAAM,GAAG,gBAAyB,CAAA;AAmE/C,MAAM,CAAC,MAAM,OAAO,GAClB,GAAc,EAAE,CAChB,CASE,EAAW,EACX,UAA+G,EACA,EAAE;IACjH,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,EAA4E,CAAC,EAAE,CAAC,CAAA;IAE3G,MAAM,OAAO,GAAsC,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAClE,GAAG,CAAC,QAAQ,E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Transport<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,2 @@
1
+ import { Effect, Schema as S } from "effect";
2
+ //# sourceMappingURL=ActorTransport.js.map
@@ -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"}
@@ -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 * as Method from "./Method.ts";
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, MethodDefinitions extends Record<string, Method.MethodDefinition.Any>, Event> extends Pipeable.Pipeable {
7
+ export interface Audition<ClientSelf, D extends ProtocolDefinition> extends Pipeable.Pipeable {
8
8
  readonly [TypeId]: typeof TypeId;
9
- readonly events: Stream.Stream<Event, ClientError, ClientSelf>;
10
- readonly f: F<ClientSelf, MethodDefinitions>;
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, never>;
12
+ export declare const empty: Audition<never, never>;
13
13
  export declare const add: {
14
- <ClientSelf, ClientId extends string, ClientMethodDefinitions extends Record<string, Method.MethodDefinition.Any>, ClientEventDefinitions extends Record<string, S.Struct.Fields>>(client: Client.Client<ClientSelf, ClientId, ClientMethodDefinitions, ClientEventDefinitions>): <AuditionSelf, AuditionMethodDefinitions extends Record<string, Method.MethodDefinition.Any>, AuditionEvent>(audition: Audition<AuditionSelf, AuditionMethodDefinitions, AuditionEvent>) => Audition<AuditionSelf | ClientSelf, Method.MethodDefinition.Merge<AuditionMethodDefinitions, ClientMethodDefinitions>, AuditionEvent | ReturnType<typeof S.TaggedUnion<ClientEventDefinitions>>["Type"]>;
15
- <AuditionClientSelf, AuditionMethodDefinitions extends Record<string, Method.MethodDefinition.Any>, AuditionEvent, ClientSelf, ClientId extends string, ClientMethodDefinitions extends Record<string, Method.MethodDefinition.Any>, ClientEventDefinitions extends Record<string, S.Struct.Fields>>(audition: Audition<AuditionClientSelf, AuditionMethodDefinitions, AuditionEvent>, client: Client.Client<ClientSelf, ClientId, ClientMethodDefinitions, ClientEventDefinitions>): Audition<AuditionClientSelf | ClientSelf, Method.MethodDefinition.Merge<AuditionMethodDefinitions, ClientMethodDefinitions>, AuditionEvent | ReturnType<typeof S.TaggedUnion<ClientEventDefinitions>>["Type"]>;
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 {};
@@ -1 +1 @@
1
- {"version":3,"file":"Audition.js","sourceRoot":"","sources":["../Audition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,I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GAgBZ,QAAQ,CAAC,IAAI,CACf,CAAC,EACD,CAOE,QAA2C,EAC3C,MAAoD,EAC+B,EAAE;IACrF,MAAM,CAAC,GAA+E,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,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 { MethodDefinition } from "./Method.ts";
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 * as Protocol from "./Protocol.ts";
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<ClientSelf, MethodDefinitions extends Record<string, MethodDefinition.Any>, EventDefinitions extends Record<string, S.Struct.Fields>> {
18
- readonly events: Stream.Stream<ReturnType<typeof S.TaggedUnion<EventDefinitions>>["Type"], ClientError>;
19
- readonly f: F<ClientSelf, MethodDefinitions>;
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, MethodDefinitions extends Record<string, MethodDefinition.Any>, EventDefinitions extends Record<string, S.Struct.Fields>> = RcRef.RcRef<Session<ClientSelf, MethodDefinitions, EventDefinitions>, ClientError>;
23
- export interface Client<ClientSelf, ClientId extends string, MethodDefinitions extends Record<string, MethodDefinition.Any>, EventDefinitions extends Record<string, S.Struct.Fields>> extends Context.Service<ClientSelf, Service<ClientSelf, MethodDefinitions, EventDefinitions>> {
24
- new (_: never): Context.ServiceClass.Shape<ClientId, Service<ClientSelf, MethodDefinitions, EventDefinitions>>;
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: ClientDefinition<MethodDefinitions, EventDefinitions>;
27
- readonly schema: Protocol.ProtocolSchemas<MethodDefinitions, EventDefinitions>;
28
- readonly events: Stream.Stream<ReturnType<typeof S.TaggedUnion<EventDefinitions>>["Type"], ClientError, ClientSelf>;
29
- readonly f: F<ClientSelf, MethodDefinitions>;
30
- readonly invalidate: Effect.Effect<void, never, ClientSelf>;
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: <ClientSelf>() => <ClientId extends string, MethodDefinitions extends Record<string, MethodDefinition.Any>, EventDefinitions extends Record<string, S.Struct.Fields>>(id: ClientId, definition: ClientDefinition<MethodDefinitions, EventDefinitions>) => Client<ClientSelf, ClientId, MethodDefinitions, EventDefinitions>;
33
- export interface Transport<MethodDefinitions extends Record<string, MethodDefinition.Any>, EventDefinitions extends Record<string, S.Struct.Fields>> {
34
- readonly listen: (publish: (message: Protocol.ProtocolSchemas<MethodDefinitions, EventDefinitions>["actor"]["Type"] | typeof Protocol.TransportFailure.Type) => Effect.Effect<void, ClientError>) => Effect.Effect<void, ClientError, Scope.Scope | Protocol.ProtocolSchemas<MethodDefinitions, EventDefinitions>["actor"]["DecodingServices"]>;
35
- readonly send: (message: Protocol.ProtocolSchemas<MethodDefinitions, EventDefinitions>["f"]["payload"]["Type"]) => Effect.Effect<void, ConnectionError, Protocol.ProtocolSchemas<MethodDefinitions, EventDefinitions>["f"]["payload"]["EncodingServices"]>;
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: <ClientSelf, ClientId extends string, MethodDefinitions extends Record<string, MethodDefinition.Any>, EventDefinitions extends Record<string, S.Struct.Fields>>({ client, url, protocols, replay, }: {
38
- readonly client: Client<ClientSelf, ClientId, MethodDefinitions, EventDefinitions>;
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<ClientSelf, never, Socket.WebSocketConstructor | Protocol.ProtocolSchemas<MethodDefinitions, EventDefinitions>["actor"]["DecodingServices"] | Protocol.ProtocolSchemas<MethodDefinitions, EventDefinitions>["f"]["payload"]["EncodingServices"]>;
43
- export declare const layerWorker: <ClientSelf, ClientId extends string, MethodDefinitions extends Record<string, MethodDefinition.Any>, EventDefinitions extends Record<string, S.Struct.Fields>>({ client, replay, }: {
44
- readonly client: Client<ClientSelf, ClientId, MethodDefinitions, EventDefinitions>;
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<ClientSelf, never, Worker.WorkerPlatform | Worker.Spawner | Protocol.ProtocolSchemas<MethodDefinitions, EventDefinitions>["actor"]["DecodingServices"] | Protocol.ProtocolSchemas<MethodDefinitions, EventDefinitions>["f"]["payload"]["EncodingServices"]>;
41
+ }) => Layer.Layer<Self, never, Worker.WorkerPlatform | Worker.Spawner | T["Actor"]["DecodingServices"] | T["F"]["Payload"]["EncodingServices"]>;