liminal 0.17.4 → 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/Protocol.ts CHANGED
@@ -1,120 +1,161 @@
1
- import { Schema as S, Record } from "effect"
1
+ import { flow, Schema as S, Record, Types, Effect, SchemaAST } 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
+ const parseJson = flow(S.toCodecJson, S.fromJsonString)
28
+ const decode = flow(parseJson, S.decodeUnknownEffect)
29
+ const encode = flow(parseJson, S.encodeEffect)
30
+
31
+ export interface Protocol<D extends ProtocolDefinition> {
32
+ readonly Audition: {
33
+ readonly Success: S.TaggedStruct<"Audition.Success", {}>
34
+ readonly Failure: S.TaggedStruct<
35
+ "Audition.Failure",
36
+ {
37
+ client: S.String
38
+ routed: S.String
39
+ }
40
+ >
41
+ }
42
+
43
+ readonly Event: S.TaggedStruct<
44
+ "Event",
45
+ {
46
+ readonly event: S.TaggedUnion<{
47
+ readonly [K in keyof D["events"] & string]: S.TaggedStruct<K, D["events"][K]>
48
+ }>
49
+ }
50
+ >
51
+
52
+ readonly F: {
53
+ readonly Payload: S.TaggedStruct<
54
+ "F.Payload",
19
55
  {
20
56
  readonly id: S.Int
21
57
  readonly payload: S.TaggedUnion<{
22
- readonly [K in keyof MethodDefinitions & string]: S.TaggedStruct<
23
- K,
24
- { readonly value: MethodDefinitions[K]["payload"] }
25
- >
58
+ readonly [K in keyof D["methods"] & string]: S.TaggedStruct<K, { readonly value: D["methods"][K]["payload"] }>
26
59
  }>
27
60
  }
28
61
  >
29
62
 
30
- readonly success: S.TaggedStruct<
31
- "FSuccess",
63
+ readonly Success: S.TaggedStruct<
64
+ "F.Success",
32
65
  {
33
66
  readonly id: S.Int
34
67
  readonly success: S.TaggedUnion<{
35
- readonly [K in keyof MethodDefinitions & string]: S.TaggedStruct<
36
- K,
37
- { readonly value: MethodDefinitions[K]["success"] }
38
- >
68
+ readonly [K in keyof D["methods"] & string]: S.TaggedStruct<K, { readonly value: D["methods"][K]["success"] }>
39
69
  }>
40
70
  }
41
71
  >
42
72
 
43
- readonly failure: S.TaggedStruct<
44
- "FFailure",
73
+ readonly Failure: S.TaggedStruct<
74
+ "F.Failure",
45
75
  {
46
76
  readonly id: S.Int
47
77
  readonly failure: S.TaggedUnion<{
48
- readonly [K in keyof MethodDefinitions & string]: S.TaggedStruct<
49
- K,
50
- { readonly value: MethodDefinitions[K]["failure"] }
51
- >
78
+ readonly [K in keyof D["methods"] & string]: S.TaggedStruct<K, { readonly value: D["methods"][K]["failure"] }>
52
79
  }>
53
80
  }
54
81
  >
55
82
  }
56
83
 
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
- >
84
+ readonly Disconnect: S.TaggedStruct<"Disconnect", {}>
65
85
 
66
- readonly actor: S.Union<
86
+ readonly Actor: S.Union<
67
87
  [
68
- typeof AuditionSuccess,
69
- typeof AuditionFailure,
70
- this["f"]["success"],
71
- this["f"]["failure"],
72
- this["event"],
73
- typeof Disconnect,
88
+ this["Audition"]["Success"],
89
+ this["Audition"]["Failure"],
90
+ this["F"]["Success"],
91
+ this["F"]["Failure"],
92
+ this["Event"],
93
+ this["Disconnect"],
74
94
  ]
75
95
  >
96
+
97
+ readonly encodeFPayload: (
98
+ input: this["F"]["Payload"]["Type"],
99
+ options?: SchemaAST.ParseOptions,
100
+ ) => Effect.Effect<string, S.SchemaError, this["F"]["Payload"]["EncodingServices"]>
101
+
102
+ readonly decodeEvent: (
103
+ input: unknown,
104
+ options?: SchemaAST.ParseOptions,
105
+ ) => Effect.Effect<this["Event"]["Type"], S.SchemaError, this["Event"]["DecodingServices"]>
106
+
107
+ readonly decodeActor: (
108
+ input: unknown,
109
+ options?: SchemaAST.ParseOptions,
110
+ ) => Effect.Effect<this["Actor"]["Type"], S.SchemaError, this["Actor"]["DecodingServices"]>
76
111
  }
77
112
 
78
- export const Disconnect = S.TaggedStruct("Disconnect", {})
113
+ const Disconnect = S.TaggedStruct("Disconnect", {})
79
114
 
80
- export const TransportFailure = S.TaggedStruct("TransportFailure", { cause: S.Unknown })
115
+ const Audition = {
116
+ Success: S.TaggedStruct("Audition.Success", {}),
117
+ Failure: S.TaggedStruct("Audition.Failure", {
118
+ client: S.String,
119
+ routed: S.String,
120
+ }),
121
+ }
81
122
 
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>
123
+ export const Protocol = <D extends ProtocolDefinition>({ events, methods }: D): Protocol<D> => {
124
+ type T = Protocol<D>
90
125
 
91
- const f: T["f"] = {
92
- payload: S.TaggedStruct("FPayload", {
126
+ const F: T["F"] = {
127
+ Payload: S.TaggedStruct("F.Payload", {
93
128
  id: S.Int,
94
129
  payload: S.TaggedUnion(Record.map(methods, ({ payload: value }) => ({ value }))),
95
130
  }) as never,
96
- success: S.TaggedStruct("FSuccess", {
131
+ Success: S.TaggedStruct("F.Success", {
97
132
  id: S.Int,
98
133
  success: S.TaggedUnion(Record.map(methods, ({ success: value }) => ({ value }))),
99
134
  }) as never,
100
- failure: S.TaggedStruct("FFailure", {
135
+ Failure: S.TaggedStruct("F.Failure", {
101
136
  id: S.Int,
102
137
  failure: S.TaggedUnion(Record.map(methods, ({ failure: value }) => ({ value }))),
103
138
  }) as never,
104
139
  }
105
140
 
106
- const event: T["event"] = S.TaggedStruct("Event", {
141
+ const Event: T["Event"] = S.TaggedStruct("Event", {
107
142
  event: S.TaggedUnion(events),
108
143
  }) as never
109
144
 
110
- const actor: T["actor"] = S.Union([
111
- AuditionSuccess,
112
- AuditionFailure,
113
- f.success,
114
- f.failure,
115
- event,
116
- Disconnect,
117
- ]) as never
145
+ const Actor: T["Actor"] = S.Union([Audition.Success, Audition.Failure, F.Success, F.Failure, Event, Disconnect])
146
+
147
+ const encodeFPayload = encode(F.Payload)
148
+ const decodeEvent = decode(Event)
149
+ const decodeActor = decode(Actor)
118
150
 
119
- return { f, event, actor }
151
+ return {
152
+ Audition,
153
+ Event,
154
+ F,
155
+ Actor,
156
+ Disconnect,
157
+ encodeFPayload,
158
+ decodeEvent,
159
+ decodeActor,
160
+ }
120
161
  }
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,11 @@
1
+ import { References, Effect, Layer } from "effect"
2
+
3
+ import { logCause } from "./logCause.ts"
4
+
5
+ export const boundLayer = (boundary: string) =>
6
+ Layer.provideMerge(
7
+ Layer.effect(
8
+ References.CurrentLogAnnotations,
9
+ Effect.map(References.CurrentLogAnnotations.asEffect(), (existing) => ({ ...existing, _boundary: boundary })),
10
+ ).pipe(Layer.tapCause(logCause), Layer.provideMerge(Layer.succeed(References.MinimumLogLevel, "All"))),
11
+ )
@@ -0,0 +1,8 @@
1
+ import { Cause, Effect, Schema as S, flow } from "effect"
2
+
3
+ const formatReason = <E>(reason: Cause.Reason<E>): unknown => {
4
+ const value = Cause.isFailReason(reason) ? reason.error : Cause.isDieReason(reason) ? reason.defect : reason
5
+ return S.isSchemaError(value) ? value.toString() : value
6
+ }
7
+
8
+ export const logCause = <E>(cause: Cause.Cause<E>) => Effect.forEach(cause.reasons, flow(formatReason, Effect.logError))
package/dist/Actor.d.ts CHANGED
@@ -1,29 +1,29 @@
1
1
  import { Context, Schema as S, Effect } from "effect";
2
2
  import type * as ActorClient from "./Client.ts";
3
3
  import type * as ClientHandle from "./ClientHandle.ts";
4
- import type { MethodDefinition } from "./Method.ts";
4
+ import type { ProtocolDefinition } from "./Protocol.ts";
5
5
  import type { Send } from "./Send.ts";
6
6
  import * as Method from "./Method.ts";
7
7
  export declare const TypeId: "~liminal/Actor";
8
- export interface Service<ActorSelf, NameA, AttachmentFields extends S.Struct.Fields, EventDefinitions extends Record<string, S.Struct.Fields>> {
8
+ export interface Service<ActorSelf, NameA, AttachmentFields extends S.Struct.Fields, D extends ProtocolDefinition> {
9
9
  readonly name: NameA;
10
- readonly currentClient: ClientHandle.ClientHandle<ActorSelf, AttachmentFields, EventDefinitions>;
11
- readonly clients: ReadonlySet<ClientHandle.ClientHandle<ActorSelf, AttachmentFields, EventDefinitions>>;
10
+ readonly currentClient: ClientHandle.ClientHandle<ActorSelf, AttachmentFields, D>;
11
+ readonly clients: ReadonlySet<ClientHandle.ClientHandle<ActorSelf, AttachmentFields, D>>;
12
12
  }
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>> {
13
+ export interface ActorDefinition<NameA, AttachmentFields extends S.Struct.Fields, ClientSelf, ClientId extends string, D extends ProtocolDefinition> {
14
14
  readonly name: S.Codec<NameA, string>;
15
15
  readonly attachments: AttachmentFields;
16
- readonly client: ActorClient.Client<ClientSelf, ClientId, MethodDefinitions, EventDefinitions>;
16
+ readonly client: ActorClient.Client<ClientSelf, ClientId, D>;
17
17
  }
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>>;
18
+ export interface Actor<ActorSelf, ActorId extends string, NameA, AttachmentFields extends S.Struct.Fields, ActorClientSelf, ActorClientId extends string, D extends ProtocolDefinition> extends Context.Service<ActorSelf, Service<ActorSelf, NameA, AttachmentFields, D>> {
19
+ new (_: never): Context.ServiceClass.Shape<ActorId, Service<ActorSelf, NameA, AttachmentFields, D>>;
20
20
  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"]>;
21
+ readonly definition: ActorDefinition<NameA, AttachmentFields, ActorClientSelf, ActorClientId, D>;
22
+ readonly protocol: {
23
+ readonly Attachments: S.Struct<AttachmentFields>;
24
24
  };
25
- readonly sendAll: Send<ActorSelf, EventDefinitions>;
25
+ readonly sendAll: Send<ActorSelf, D>;
26
26
  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>;
27
+ readonly handler: <K extends keyof D["methods"], R>(tag: K, f: Method.Handler<D["methods"][K], R>) => Method.Handler<D["methods"][K], R>;
28
28
  }
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>;
29
+ export declare const Service: <ActorSelf>() => <ActorId extends string, NameA, D extends ProtocolDefinition, AttachmentFields extends S.Struct.Fields, ClientSelf, ClientId extends string>(id: ActorId, definition: ActorDefinition<NameA, AttachmentFields, ClientSelf, ClientId, D>) => Actor<ActorSelf, ActorId, NameA, AttachmentFields, ClientSelf, ClientId, D>;
package/dist/Actor.js CHANGED
@@ -11,8 +11,8 @@ export const Service = () => (id, definition) => {
11
11
  return Object.assign(tag, {
12
12
  [TypeId]: TypeId,
13
13
  definition,
14
- schema: {
15
- attachments: S.Struct(definition.attachments),
14
+ protocol: {
15
+ Attachments: S.Struct(definition.attachments),
16
16
  },
17
17
  sendAll,
18
18
  disconnectAll,
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,EAAE,CAAC,IAAI,CACjB,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAC7B,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,CAC7F,EACD,IAAI,CAAC,SAAS,CAAC,CAChB,CAAA;IAEH,MAAM,aAAa,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC,IAAI,CACvC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC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AC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,CAC7F,EACD,IAAI,CAAC,SAAS,CAAC,CAChB,CAAA;IAEH,MAAM,aAAa,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC,IAAI,CACvC,MAAM,CAAC,OAAO,CAAC,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,QAAQ,EAAE;YACR,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC;SAC9C;QACD,OAAO;QACP,aAAa;QACb,OAAO;KACR,CAAC,CAAA;AACJ,CAAC,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,IAAI,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAKxE,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAA;AACnD,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,EAAoB,aAAa,EAAE,MAAM,aAAa,CAAA;AAE7D,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;AAErD,MAAM,MAAM,GAAG,mBAA4B,CAAA;AAW3C,MAAM,CAAC,MAAM,KAAK,GAAkC;IAClD,CAAC,MAAM,CAAC,EAAE,MAAM;IAChB,IAAI;QACF,OAAO,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;IAChD,CAAC;IACD,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,aAAa,EAAE,CAAC;IACxC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,aAAa,EAAE,CAAC,QAAQ,EAAE;CAC9C,CAAA;AAED,MAAM,CAAC,MAAM,GAAG,GA+BZ,QAAQ,CAAC,IAAI,CACf,CAAC,EACD,CASE,QAA0E,EAC1E,MAA4F,EAK5F,EAAE;IACF,MAAM,CAAC,GAGH,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,CAC1B,QAAQ;SACL,CAAC,CAAC,MAAe,CAAC,CAAC,OAAO,CAAC;SAC3B,IAAI,CACH,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,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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>({ 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 | Protocol<D>["Actor"]["DecodingServices"] | Protocol<D>["F"]["Payload"]["EncodingServices"]>;