liminal 0.17.1 → 0.17.3
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/Accumulator.ts +16 -10
- package/Actor.ts +35 -29
- package/Audition.ts +17 -12
- package/CHANGELOG.md +12 -0
- package/Client.ts +260 -295
- package/ClientHandle.ts +17 -6
- package/F.ts +3 -9
- package/LICENSE +202 -0
- package/Method.ts +11 -13
- package/Protocol.ts +104 -126
- package/Send.ts +9 -5
- package/_util/Diagnostic.ts +16 -0
- package/_util/Mutex.ts +5 -5
- package/dist/Accumulator.d.ts +2 -2
- package/dist/Accumulator.js +12 -8
- package/dist/Accumulator.js.map +1 -1
- package/dist/Actor.d.ts +9 -10
- package/dist/Actor.js +6 -15
- package/dist/Actor.js.map +1 -1
- package/dist/Audition.d.ts +3 -4
- package/dist/Audition.js +7 -5
- package/dist/Audition.js.map +1 -1
- package/dist/Client.d.ts +20 -39
- package/dist/Client.js +119 -139
- package/dist/Client.js.map +1 -1
- package/dist/ClientHandle.d.ts +5 -6
- package/dist/ClientHandle.js +1 -1
- package/dist/ClientHandle.js.map +1 -1
- package/dist/F.d.ts +3 -12
- package/dist/F.js +1 -3
- package/dist/F.js.map +1 -1
- package/dist/Method.d.ts +11 -12
- package/dist/Method.js.map +1 -1
- package/dist/Protocol.d.ts +46 -89
- package/dist/Protocol.js +35 -11
- package/dist/Protocol.js.map +1 -1
- package/dist/Send.d.ts +2 -3
- package/dist/Send.js +1 -1
- package/dist/Send.js.map +1 -1
- package/dist/_util/Diagnostic.d.ts +5 -0
- package/dist/_util/Diagnostic.js +10 -0
- package/dist/_util/Diagnostic.js.map +1 -0
- package/dist/_util/Mutex.d.ts +2 -2
- package/dist/_util/Mutex.js +4 -4
- package/dist/_util/Mutex.js.map +1 -1
- package/dist/errors.d.ts +15 -12
- package/dist/errors.js +6 -4
- package/dist/errors.js.map +1 -1
- package/dist/experimental/BranchLive.d.ts +1 -1
- package/dist/experimental/BranchLive.js +1 -1
- package/dist/experimental/BranchLive.js.map +1 -1
- package/dist/experimental/L/append.d.ts +1 -1
- package/dist/experimental/L/append.js +2 -2
- package/dist/experimental/L/append.js.map +1 -1
- package/dist/experimental/L/assistant.d.ts +2 -2
- package/dist/experimental/L/assistant.js +1 -1
- package/dist/experimental/L/assistant.js.map +1 -1
- package/dist/experimental/L/assistantSchema.d.ts +2 -2
- package/dist/experimental/L/assistantSchema.js +1 -1
- package/dist/experimental/L/assistantSchema.js.map +1 -1
- package/dist/experimental/L/assistantStream.d.ts +2 -2
- package/dist/experimental/L/assistantStream.js +1 -1
- package/dist/experimental/L/assistantStream.js.map +1 -1
- package/dist/experimental/L/branch.d.ts +1 -1
- package/dist/experimental/L/clear.d.ts +1 -1
- package/dist/experimental/L/clear.js +1 -1
- package/dist/experimental/L/clear.js.map +1 -1
- package/dist/experimental/L/history.d.ts +2 -2
- package/dist/experimental/L/history.js +2 -2
- package/dist/experimental/L/history.js.map +1 -1
- package/dist/experimental/L/init.d.ts +1 -1
- package/dist/experimental/L/init.js +1 -1
- package/dist/experimental/L/init.js.map +1 -1
- package/dist/experimental/L/matrix.d.ts +2 -2
- package/dist/experimental/L/system.d.ts +1 -1
- package/dist/experimental/L/system.js +1 -1
- package/dist/experimental/L/system.js.map +1 -1
- package/dist/experimental/L/user.d.ts +1 -1
- package/dist/experimental/L/user.js +1 -1
- package/dist/experimental/L/user.js.map +1 -1
- package/dist/experimental/Loader.d.ts +3 -3
- package/dist/experimental/Loader.js +2 -2
- package/dist/experimental/Loader.js.map +1 -1
- package/dist/experimental/TaggedTemplateFunction.d.ts +2 -2
- package/dist/experimental/Template.d.ts +8 -12
- package/dist/experimental/Template.js +53 -51
- package/dist/experimental/Template.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/errors.ts +12 -4
- package/experimental/BranchLive.ts +1 -1
- package/experimental/L/append.ts +2 -2
- package/experimental/L/assistant.ts +1 -1
- package/experimental/L/assistantSchema.ts +3 -3
- package/experimental/L/assistantStream.ts +1 -1
- package/experimental/L/clear.ts +1 -1
- package/experimental/L/history.ts +2 -2
- package/experimental/L/init.ts +1 -1
- package/experimental/L/matrix.ts +3 -3
- package/experimental/L/system.ts +1 -1
- package/experimental/L/user.ts +1 -1
- package/experimental/Loader.ts +3 -3
- package/experimental/TaggedTemplateFunction.ts +2 -2
- package/experimental/Template.ts +62 -70
- package/package.json +2 -6
- package/tsconfig.json +1 -1
- package/_types.ts +0 -27
- package/dist/_types.d.ts +0 -22
- package/dist/_types.js +0 -2
- package/dist/_types.js.map +0 -1
package/dist/Accumulator.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { Deferred, Types, Option, Ref, PubSub, Stream, Effect, Context, Layer } from "effect";
|
|
1
|
+
import { Deferred, Types, Option, Ref, PubSub, Stream, Effect, Context, Layer, Semaphore } from "effect";
|
|
2
|
+
import * as Diagnostic from "./_util/Diagnostic.js";
|
|
3
|
+
const { debug } = Diagnostic.module("Accumulator");
|
|
2
4
|
const TypeId = "~liminal/Accumulator";
|
|
3
5
|
export const Service = () => (id) => {
|
|
4
|
-
const tag = Context.
|
|
5
|
-
const get = tag.pipe(Effect.map(({ ref }) => ref), Effect.flatMap(Ref.get));
|
|
6
|
-
const stream = tag.pipe(Effect.map(({ pubsub }) => Stream.fromPubSub(pubsub)), Stream.unwrap);
|
|
6
|
+
const tag = Context.Service()(id);
|
|
7
|
+
const get = tag.asEffect().pipe(Effect.map(({ ref }) => ref), Effect.flatMap(Ref.get));
|
|
8
|
+
const stream = tag.asEffect().pipe(Effect.map(({ pubsub }) => Stream.fromPubSub(pubsub)), Stream.unwrap);
|
|
7
9
|
const reducer = () => (_tag, f) => f;
|
|
8
10
|
const layer = ({ source, initial, reduce, }) => Effect.gen(function* () {
|
|
9
|
-
const semaphore = yield*
|
|
11
|
+
const semaphore = yield* Semaphore.make(1);
|
|
10
12
|
const deferred = yield* Deferred.make();
|
|
11
13
|
const pubsub = yield* PubSub.unbounded({ replay: 1 });
|
|
12
14
|
yield* source.pipe(Stream.runForEach(Effect.fn(function* (item) {
|
|
@@ -15,19 +17,21 @@ export const Service = () => (id) => {
|
|
|
15
17
|
if (Option.isSome(match)) {
|
|
16
18
|
const { value } = match;
|
|
17
19
|
yield* Deferred.succeed(deferred, value);
|
|
20
|
+
yield* debug("InitializedState", { state: value });
|
|
18
21
|
}
|
|
19
22
|
return;
|
|
20
23
|
}
|
|
21
24
|
const current = yield* Ref.get(ref);
|
|
22
25
|
const reduced = yield* reduce(item)(current);
|
|
23
26
|
yield* Ref.set(ref, reduced);
|
|
24
|
-
yield*
|
|
27
|
+
yield* PubSub.publish(pubsub, reduced);
|
|
28
|
+
yield* debug("ReducedState", { item, previous: current, current: reduced });
|
|
25
29
|
}, semaphore.withPermits(1))), Effect.forkScoped);
|
|
26
30
|
const initial_ = yield* Deferred.await(deferred);
|
|
27
31
|
const ref = yield* Ref.make(initial_);
|
|
28
|
-
yield*
|
|
32
|
+
yield* PubSub.publish(pubsub, initial_);
|
|
29
33
|
return { ref, pubsub };
|
|
30
|
-
}).pipe(Layer.
|
|
34
|
+
}).pipe(Layer.effect(tag));
|
|
31
35
|
return Object.assign(tag, { [TypeId]: TypeId, get, stream, reducer, layer });
|
|
32
36
|
};
|
|
33
37
|
//# sourceMappingURL=Accumulator.js.map
|
package/dist/Accumulator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Accumulator.js","sourceRoot":"","sources":["../Accumulator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"Accumulator.js","sourceRoot":"","sources":["../Accumulator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,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,CAAC,CAC7B,EACD,MAAM,CAAC,UAAU,CAClB,CAAA;QACD,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;QAChD,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACrC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;QACvC,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,CAAA;IACxB,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;IAE5B,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAA;AAC9E,CAAC,CAAA"}
|
package/dist/Actor.d.ts
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
1
1
|
import { Context, Schema as S, Effect } from "effect";
|
|
2
|
-
import type { FieldsRecord, Fields } from "./_types.ts";
|
|
3
2
|
import type * as ActorClient from "./Client.ts";
|
|
4
3
|
import type * as ClientHandle from "./ClientHandle.ts";
|
|
5
4
|
import type { MethodDefinition } from "./Method.ts";
|
|
6
|
-
import * as Method from "./Method.ts";
|
|
7
5
|
import type { Send } from "./Send.ts";
|
|
6
|
+
import * as Method from "./Method.ts";
|
|
8
7
|
export declare const TypeId: "~liminal/Actor";
|
|
9
|
-
export interface Service<ActorSelf, NameA, AttachmentFields extends Fields, EventDefinitions extends
|
|
8
|
+
export interface Service<ActorSelf, NameA, AttachmentFields extends S.Struct.Fields, EventDefinitions extends Record<string, S.Struct.Fields>> {
|
|
10
9
|
readonly name: NameA;
|
|
11
10
|
readonly currentClient: ClientHandle.ClientHandle<ActorSelf, AttachmentFields, EventDefinitions>;
|
|
12
11
|
readonly clients: ReadonlySet<ClientHandle.ClientHandle<ActorSelf, AttachmentFields, EventDefinitions>>;
|
|
13
12
|
}
|
|
14
|
-
export interface ActorDefinition<NameA, AttachmentFields extends Fields, ClientSelf, ClientId extends string, MethodDefinitions extends Record<string, MethodDefinition.Any>, EventDefinitions extends
|
|
15
|
-
readonly name: S.
|
|
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>;
|
|
16
15
|
readonly attachments: AttachmentFields;
|
|
17
16
|
readonly client: ActorClient.Client<ClientSelf, ClientId, MethodDefinitions, EventDefinitions>;
|
|
18
17
|
}
|
|
19
|
-
export interface Actor<ActorSelf, ActorId extends string, NameA, AttachmentFields extends Fields, ActorClientSelf, ActorClientId extends string, MethodDefinitions extends Record<string, MethodDefinition.Any>, EventDefinitions extends
|
|
20
|
-
new (_: never): Context.
|
|
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>>;
|
|
21
20
|
readonly [TypeId]: typeof TypeId;
|
|
22
21
|
readonly definition: ActorDefinition<NameA, AttachmentFields, ActorClientSelf, ActorClientId, MethodDefinitions, EventDefinitions>;
|
|
23
22
|
readonly schema: {
|
|
24
|
-
readonly attachments: S.
|
|
23
|
+
readonly attachments: S.Codec<S.Struct<AttachmentFields>["Type"], S.Struct<AttachmentFields>["Encoded"]>;
|
|
25
24
|
};
|
|
26
25
|
readonly sendAll: Send<ActorSelf, EventDefinitions>;
|
|
27
|
-
readonly
|
|
26
|
+
readonly disconnectAll: Effect.Effect<void, never, ActorSelf>;
|
|
28
27
|
readonly handler: <K extends keyof MethodDefinitions, R>(tag: K, f: Method.Handler<MethodDefinitions[K], R>) => Method.Handler<MethodDefinitions[K], R>;
|
|
29
28
|
}
|
|
30
|
-
export declare const Service: <ActorSelf>() => <ActorId extends string, NameA, AttachmentFields extends Fields, ClientSelf, ClientId extends string, MethodDefinitions extends Record<string, MethodDefinition.Any>, EventDefinitions extends
|
|
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>;
|
package/dist/Actor.js
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
import { Context, Schema as S, Effect } from "effect";
|
|
2
|
+
import * as Diagnostic from "./_util/Diagnostic.js";
|
|
2
3
|
import * as Method from "./Method.js";
|
|
4
|
+
const { span } = Diagnostic.module("Actor");
|
|
3
5
|
export const TypeId = "~liminal/Actor";
|
|
4
6
|
export const Service = () => (id, definition) => {
|
|
5
|
-
const tag = Context.
|
|
6
|
-
const sendAll = Effect.
|
|
7
|
-
|
|
8
|
-
yield* Effect.forEach(clients, (client) => client.send(key, payload), {
|
|
9
|
-
concurrency: "unbounded",
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
// TODO: more eviction
|
|
13
|
-
const evict = Effect.gen(function* () {
|
|
14
|
-
const { clients } = yield* tag;
|
|
15
|
-
for (const client of clients) {
|
|
16
|
-
yield* client.disconnect;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
7
|
+
const tag = Context.Service()(id);
|
|
8
|
+
const sendAll = (key, payload) => tag.asEffect().pipe(Effect.flatMap(({ clients }) => Effect.forEach(clients, (client) => client.send(key, payload), { concurrency: "unbounded" })), span("sendAll"));
|
|
9
|
+
const disconnectAll = tag.asEffect().pipe(Effect.flatMap(({ clients }) => Effect.forEach(clients, ({ disconnect }) => disconnect)), span("disconnectAll"));
|
|
19
10
|
const handler = (_tag, f) => f;
|
|
20
11
|
return Object.assign(tag, {
|
|
21
12
|
[TypeId]: TypeId,
|
|
@@ -24,7 +15,7 @@ export const Service = () => (id, definition) => {
|
|
|
24
15
|
attachments: S.Struct(definition.attachments),
|
|
25
16
|
},
|
|
26
17
|
sendAll,
|
|
27
|
-
|
|
18
|
+
disconnectAll,
|
|
28
19
|
handler,
|
|
29
20
|
});
|
|
30
21
|
};
|
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;
|
|
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,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,CAA0C,EACD,EAAE,CAAC,CAAC,CAAA;IAE/C,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE;QACxB,CAAC,MAAM,CAAC,EAAE,MAAM;QAChB,UAAU;QACV,MAAM,EAAE;YACN,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAU;SACvD;QACD,OAAO;QACP,aAAa;QACb,OAAO;KACR,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
package/dist/Audition.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Pipeable, Stream } from "effect";
|
|
2
|
-
import type { FieldsRecord } from "./_types.ts";
|
|
1
|
+
import { Schema as S, Pipeable, Stream } from "effect";
|
|
3
2
|
import type { F } from "./F.ts";
|
|
4
3
|
import type * as Method from "./Method.ts";
|
|
5
4
|
import * as Client from "./Client.ts";
|
|
@@ -12,7 +11,7 @@ export interface Audition<ClientSelf, MethodDefinitions extends Record<string, M
|
|
|
12
11
|
}
|
|
13
12
|
export declare const empty: Audition<never, never, never>;
|
|
14
13
|
export declare const add: {
|
|
15
|
-
<ClientSelf, ClientId extends string, ClientMethodDefinitions extends Record<string, Method.MethodDefinition.Any>, ClientEventDefinitions extends
|
|
16
|
-
<AuditionClientSelf, AuditionMethodDefinitions extends Record<string, Method.MethodDefinition.Any>, AuditionEvent, ClientSelf, ClientId extends string, ClientMethodDefinitions extends Record<string, Method.MethodDefinition.Any>, ClientEventDefinitions extends
|
|
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"]>;
|
|
17
16
|
};
|
|
18
17
|
export {};
|
package/dist/Audition.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import { Pipeable, Stream, Effect, Function
|
|
1
|
+
import { Schema as S, Pipeable, Stream, Effect, Function } from "effect";
|
|
2
|
+
import * as Diagnostic from "./_util/Diagnostic.js";
|
|
2
3
|
import * as Client from "./Client.js";
|
|
3
4
|
import { AuditionError } from "./errors.js";
|
|
5
|
+
const { debug, span } = Diagnostic.module("Audition");
|
|
4
6
|
const TypeId = "~liminal/Audition";
|
|
5
7
|
export const empty = {
|
|
6
8
|
[TypeId]: TypeId,
|
|
7
9
|
pipe() {
|
|
8
10
|
return Pipeable.pipeArguments(this, arguments);
|
|
9
11
|
},
|
|
10
|
-
events: Stream.fail(AuditionError
|
|
11
|
-
f: () => () => AuditionError.
|
|
12
|
+
events: Stream.fail(new AuditionError()),
|
|
13
|
+
f: () => () => new AuditionError().asEffect(),
|
|
12
14
|
};
|
|
13
15
|
export const add = Function.dual(2, (audition, client) => {
|
|
14
16
|
const f = (method) => (payload) => audition
|
|
15
17
|
.f(method)(payload)
|
|
16
|
-
.pipe(Effect.catchTag("AuditionError", () => client.f(method)(payload)));
|
|
17
|
-
const events = audition.events.pipe(Stream.catchTag("AuditionError", () => Effect.succeed(client.events).pipe(Effect.tap(() =>
|
|
18
|
+
.pipe(Effect.catchTag("AuditionError", () => client.f(method)(payload)), span("f"));
|
|
19
|
+
const events = audition.events.pipe(Stream.catchTag("AuditionError", () => Effect.succeed(client.events).pipe(Effect.tap(() => debug("AuditionStaged", { client: client.key })), Stream.unwrap)));
|
|
18
20
|
return {
|
|
19
21
|
[TypeId]: TypeId,
|
|
20
22
|
pipe() {
|
package/dist/Audition.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Audition.js","sourceRoot":"","sources":["../Audition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"Audition.js","sourceRoot":"","sources":["../Audition.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AQ,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,12 +1,12 @@
|
|
|
1
|
-
import { Socket, Worker } from "@effect/platform";
|
|
2
1
|
import { Context, Effect, Layer, RcRef, Scope, Stream, Schema as S } from "effect";
|
|
3
|
-
import
|
|
2
|
+
import { Socket } from "effect/unstable/socket";
|
|
3
|
+
import { Worker } from "effect/unstable/workers";
|
|
4
|
+
import type { MethodDefinition } from "./Method.ts";
|
|
4
5
|
import { type ClientError, ConnectionError } from "./errors.ts";
|
|
5
6
|
import { type F } from "./F.ts";
|
|
6
|
-
import type { MethodDefinition } from "./Method.ts";
|
|
7
7
|
import * as Protocol from "./Protocol.ts";
|
|
8
8
|
export declare const TypeId: "~liminal/Client";
|
|
9
|
-
export interface ClientDefinition<MethodDefinitions extends Record<string, MethodDefinition.Any>, EventDefinitions extends
|
|
9
|
+
export interface ClientDefinition<MethodDefinitions extends Record<string, MethodDefinition.Any>, EventDefinitions extends Record<string, S.Struct.Fields>> {
|
|
10
10
|
readonly methods: MethodDefinitions;
|
|
11
11
|
readonly events: EventDefinitions;
|
|
12
12
|
}
|
|
@@ -14,52 +14,33 @@ export interface ReplayConfig {
|
|
|
14
14
|
readonly mode: "startup" | "all-subscribers";
|
|
15
15
|
readonly limit?: number | undefined;
|
|
16
16
|
}
|
|
17
|
-
export interface
|
|
18
|
-
readonly events: Stream.Stream<
|
|
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
19
|
readonly f: F<ClientSelf, MethodDefinitions>;
|
|
20
|
-
readonly
|
|
21
|
-
}
|
|
22
|
-
export type Service<ClientSelf, MethodDefinitions extends Record<string, MethodDefinition.Any>, EventDefinitions extends FieldsRecord> = RcRef.RcRef<TransportSession<ClientSelf, MethodDefinitions, EventDefinitions>, ClientError>;
|
|
23
|
-
export interface Spec<MethodDefinitions extends Record<string, MethodDefinition.Any>, EventDefinitions extends FieldsRecord> {
|
|
24
|
-
Call: {
|
|
25
|
-
Payload: Protocol.Call.Payload.Type<MethodDefinitions>;
|
|
26
|
-
Success: Protocol.Call.Success.Type<MethodDefinitions>;
|
|
27
|
-
Failure: Protocol.Call.Failure.Type<MethodDefinitions>;
|
|
28
|
-
};
|
|
29
|
-
Event: FieldsRecord.TaggedMember.Type<EventDefinitions>;
|
|
30
|
-
Actor: Protocol.Actor.Type<MethodDefinitions, EventDefinitions>;
|
|
31
|
-
}
|
|
32
|
-
export interface ClientSchema<MethodDefinitions extends Record<string, MethodDefinition.Any>, EventDefinitions extends FieldsRecord> {
|
|
33
|
-
readonly call: {
|
|
34
|
-
readonly payload: S.Schema<Protocol.Call.Payload.Type<MethodDefinitions>, Protocol.Call.Payload.Encoded<MethodDefinitions>>;
|
|
35
|
-
readonly success: S.Schema<Protocol.Call.Success.Type<MethodDefinitions>, Protocol.Call.Success.Encoded<MethodDefinitions>>;
|
|
36
|
-
readonly failure: S.Schema<Protocol.Call.Failure.Type<MethodDefinitions>, Protocol.Call.Failure.Encoded<MethodDefinitions>>;
|
|
37
|
-
};
|
|
38
|
-
readonly event: S.Schema<Protocol.Event.Type<EventDefinitions>, Protocol.Event.Encoded<EventDefinitions>>;
|
|
39
|
-
readonly actor: S.Schema<Protocol.Actor.Type<MethodDefinitions, EventDefinitions>, Protocol.Actor.Encoded<MethodDefinitions, EventDefinitions>>;
|
|
20
|
+
readonly end: Effect.Effect<void>;
|
|
40
21
|
}
|
|
41
|
-
export
|
|
42
|
-
|
|
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>>;
|
|
43
25
|
readonly [TypeId]: typeof TypeId;
|
|
44
26
|
readonly definition: ClientDefinition<MethodDefinitions, EventDefinitions>;
|
|
45
|
-
readonly schema:
|
|
46
|
-
readonly events: Stream.Stream<
|
|
47
|
-
readonly endEvents: Effect.Effect<void, never, ClientSelf>;
|
|
27
|
+
readonly schema: Protocol.ProtocolSchemas<MethodDefinitions, EventDefinitions>;
|
|
28
|
+
readonly events: Stream.Stream<ReturnType<typeof S.TaggedUnion<EventDefinitions>>["Type"], ClientError, ClientSelf>;
|
|
48
29
|
readonly f: F<ClientSelf, MethodDefinitions>;
|
|
49
30
|
readonly invalidate: Effect.Effect<void, never, ClientSelf>;
|
|
50
31
|
}
|
|
51
|
-
export declare const Service: <ClientSelf>() => <ClientId extends string, MethodDefinitions extends Record<string, MethodDefinition.Any>, EventDefinitions extends
|
|
52
|
-
export interface Transport<MethodDefinitions extends Record<string, MethodDefinition.Any>, EventDefinitions extends
|
|
53
|
-
readonly listen: (publish: (message: Protocol.
|
|
54
|
-
readonly send: (
|
|
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"]>;
|
|
55
36
|
}
|
|
56
|
-
export declare const layerSocket: <ClientSelf, ClientId extends string, MethodDefinitions extends Record<string, MethodDefinition.Any>, EventDefinitions extends
|
|
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, }: {
|
|
57
38
|
readonly client: Client<ClientSelf, ClientId, MethodDefinitions, EventDefinitions>;
|
|
58
39
|
readonly url?: string | undefined;
|
|
59
40
|
readonly protocols?: string | Array<string> | undefined;
|
|
60
41
|
readonly replay?: ReplayConfig | undefined;
|
|
61
|
-
}) => Layer.Layer<ClientSelf, never, Socket.WebSocketConstructor>;
|
|
62
|
-
export declare const layerWorker: <ClientSelf, ClientId extends string, MethodDefinitions extends Record<string, MethodDefinition.Any>, EventDefinitions extends
|
|
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, }: {
|
|
63
44
|
readonly client: Client<ClientSelf, ClientId, MethodDefinitions, EventDefinitions>;
|
|
64
45
|
readonly replay?: ReplayConfig | undefined;
|
|
65
|
-
}) => Layer.Layer<ClientSelf, never, Worker.
|
|
46
|
+
}) => Layer.Layer<ClientSelf, never, Worker.WorkerPlatform | Worker.Spawner | Protocol.ProtocolSchemas<MethodDefinitions, EventDefinitions>["actor"]["DecodingServices"] | Protocol.ProtocolSchemas<MethodDefinitions, EventDefinitions>["f"]["payload"]["EncodingServices"]>;
|