@shivaedev/contract 0.39.0 → 0.40.0
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/CHANGELOG.md +10 -0
- package/README.md +29 -28
- package/dist/adapters/LiveDispatcher.d.ts +9 -0
- package/dist/adapters/LiveDispatcher.d.ts.map +1 -0
- package/dist/adapters/LiveDispatcher.js +5 -0
- package/dist/adapters/LiveDispatcher.js.map +1 -0
- package/dist/adapters/liveHintStream.d.ts +30 -0
- package/dist/adapters/liveHintStream.d.ts.map +1 -0
- package/dist/adapters/liveHintStream.js +10 -0
- package/dist/adapters/liveHintStream.js.map +1 -0
- package/dist/adapters/openLiveHints.d.ts +30 -0
- package/dist/adapters/openLiveHints.d.ts.map +1 -0
- package/dist/adapters/openLiveHints.js +59 -0
- package/dist/adapters/openLiveHints.js.map +1 -0
- package/dist/adapters/refreshSubscription.d.ts +4 -0
- package/dist/adapters/refreshSubscription.d.ts.map +1 -0
- package/dist/adapters/refreshSubscription.js +5 -0
- package/dist/adapters/refreshSubscription.js.map +1 -0
- package/dist/adapters/standaloneLiveServer.d.ts +32 -0
- package/dist/adapters/standaloneLiveServer.d.ts.map +1 -0
- package/dist/adapters/standaloneLiveServer.js +13 -0
- package/dist/adapters/standaloneLiveServer.js.map +1 -0
- package/dist/adapters/withClientProtocol.d.ts +4 -0
- package/dist/adapters/withClientProtocol.d.ts.map +1 -0
- package/dist/adapters/withClientProtocol.js +6 -0
- package/dist/adapters/withClientProtocol.js.map +1 -0
- package/dist/adapters/withPolicyContext.d.ts +4 -0
- package/dist/adapters/withPolicyContext.d.ts.map +1 -0
- package/dist/adapters/withPolicyContext.js +7 -0
- package/dist/adapters/withPolicyContext.js.map +1 -0
- package/dist/live-server/initialize.d.ts +6 -0
- package/dist/live-server/initialize.d.ts.map +1 -0
- package/dist/live-server/initialize.js +7 -0
- package/dist/live-server/initialize.js.map +1 -0
- package/dist/live-server/layer.d.ts +3 -0
- package/dist/live-server/layer.d.ts.map +1 -0
- package/dist/live-server/layer.js +5 -0
- package/dist/live-server/layer.js.map +1 -0
- package/dist/live-server/register.d.ts +26 -0
- package/dist/live-server/register.d.ts.map +1 -0
- package/dist/live-server/register.js +8 -0
- package/dist/live-server/register.js.map +1 -0
- package/dist/live-server/resync.d.ts +4 -3
- package/dist/live-server/resync.d.ts.map +1 -1
- package/dist/live-server/resync.js +8 -2
- package/dist/live-server/resync.js.map +1 -1
- package/dist/live-server/service.d.ts +49 -0
- package/dist/live-server/service.d.ts.map +1 -0
- package/dist/live-server/service.js +19 -0
- package/dist/live-server/service.js.map +1 -0
- package/dist/live-server/stream.d.ts +4 -4
- package/dist/live-server/stream.d.ts.map +1 -1
- package/dist/live-server/stream.js +6 -3
- package/dist/live-server/stream.js.map +1 -1
- package/dist/live-server/subscribe.d.ts +3 -4
- package/dist/live-server/subscribe.d.ts.map +1 -1
- package/dist/live-server/subscribe.js +28 -6
- package/dist/live-server/subscribe.js.map +1 -1
- package/dist/makeLiveServer.d.ts +5 -10
- package/dist/makeLiveServer.d.ts.map +1 -1
- package/dist/makeLiveServer.js +3 -90
- package/dist/makeLiveServer.js.map +1 -1
- package/dist/querySubscription.js +5 -11
- package/dist/querySubscription.js.map +1 -1
- package/dist/readPolicy.d.ts.map +1 -1
- package/dist/readPolicy.js +2 -3
- package/dist/readPolicy.js.map +1 -1
- package/dist/rpcClient.d.ts.map +1 -1
- package/dist/rpcClient.js +2 -1
- package/dist/rpcClient.js.map +1 -1
- package/package.json +8 -8
- package/src/adapters/LiveDispatcher.ts +10 -0
- package/src/adapters/liveHintStream.ts +15 -0
- package/src/adapters/openLiveHints.ts +62 -0
- package/src/adapters/refreshSubscription.ts +6 -0
- package/src/adapters/standaloneLiveServer.ts +19 -0
- package/src/adapters/withClientProtocol.ts +10 -0
- package/src/adapters/withPolicyContext.ts +8 -0
- package/src/live-server/initialize.ts +7 -0
- package/src/live-server/layer.ts +5 -0
- package/src/live-server/register.ts +10 -0
- package/src/live-server/resync.ts +9 -4
- package/src/live-server/service.ts +19 -0
- package/src/live-server/stream.ts +7 -4
- package/src/live-server/subscribe.ts +43 -12
- package/src/makeLiveServer.ts +3 -104
- package/src/querySubscription.ts +8 -11
- package/src/readPolicy.ts +2 -3
- package/src/rpcClient.ts +4 -6
- package/dist/LiveServer.d.ts +0 -27
- package/dist/LiveServer.d.ts.map +0 -1
- package/dist/LiveServer.js +0 -18
- package/dist/LiveServer.js.map +0 -1
- package/src/LiveServer.ts +0 -18
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Effect, Layer } from "effect";
|
|
2
|
+
import type { RpcClient } from "effect/rpc";
|
|
3
|
+
|
|
4
|
+
export const withClientProtocol = Effect.fn("RpcClient.withClientProtocol")(function* <A, E, R, TMakeError, TMakeRequirements>(
|
|
5
|
+
protocol: Layer.Layer<RpcClient.Protocol, E, R>,
|
|
6
|
+
make: Effect.Effect<A, TMakeError, TMakeRequirements>,
|
|
7
|
+
) {
|
|
8
|
+
const context = yield* Layer.build(protocol);
|
|
9
|
+
return yield* Effect.provideContext(make, context);
|
|
10
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { Rpc } from "effect/rpc";
|
|
3
|
+
import { policyContext } from "#policyContext.ts";
|
|
4
|
+
|
|
5
|
+
export const withPolicyContext = Effect.fn("ReadPolicy.withPolicyContext")(function* <A, E, R>(rpc: Rpc.Any, effect: Effect.Effect<A, E, R>) {
|
|
6
|
+
const context = yield* policyContext(rpc);
|
|
7
|
+
return yield* Effect.provideContext(effect, context);
|
|
8
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { Key } from "@shivaedev/changes/keys.ts";
|
|
3
|
+
import { liveHintStream } from "#adapters/liveHintStream.ts";
|
|
4
|
+
import type { initialize } from "./initialize.ts";
|
|
5
|
+
|
|
6
|
+
export function register(state: Effect.Success<typeof initialize>) {
|
|
7
|
+
return Effect.fn("LiveServer.register")(function* (keys: readonly Key[]) {
|
|
8
|
+
return yield* liveHintStream(state, keys);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { Effect, Ref } from "effect";
|
|
2
|
+
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
3
|
+
import type { initialize } from "./initialize.ts";
|
|
3
4
|
|
|
4
|
-
export function resync(
|
|
5
|
-
return ()
|
|
5
|
+
export function resync(state: Effect.Success<typeof initialize>) {
|
|
6
|
+
return Effect.fn("LiveServer.resync")(function* () {
|
|
7
|
+
const reactivity = yield* Reactivity.Reactivity;
|
|
8
|
+
yield* Effect.sync(() => reactivity.invalidateUnsafe([state.resyncKey]));
|
|
9
|
+
return yield* Ref.get(state.openStreams);
|
|
10
|
+
});
|
|
6
11
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Random } from "effect";
|
|
2
|
+
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
3
|
+
import { defineService } from "@shivaedev/service/defineService.ts";
|
|
4
|
+
import { LiveDispatcher } from "#adapters/LiveDispatcher.ts";
|
|
5
|
+
import { initialize } from "./initialize.ts";
|
|
6
|
+
import { register } from "./register.ts";
|
|
7
|
+
import { resync } from "./resync.ts";
|
|
8
|
+
import { stream } from "./stream.ts";
|
|
9
|
+
|
|
10
|
+
export const LiveServer = defineService({
|
|
11
|
+
id: "@shivaedev/contract/LiveServer",
|
|
12
|
+
initialize,
|
|
13
|
+
methods: (state) => ({
|
|
14
|
+
register: register(state),
|
|
15
|
+
resync: resync(state),
|
|
16
|
+
stream: stream(state),
|
|
17
|
+
}),
|
|
18
|
+
requires: [Reactivity.Reactivity, LiveDispatcher, Random.Random],
|
|
19
|
+
});
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
1
|
+
import { Effect, Stream } from "effect";
|
|
2
2
|
import type { Key } from "@shivaedev/changes/keys.ts";
|
|
3
|
-
import
|
|
3
|
+
import { liveHintStream } from "#adapters/liveHintStream.ts";
|
|
4
|
+
import type { initialize } from "./initialize.ts";
|
|
4
5
|
|
|
5
|
-
export function stream(
|
|
6
|
-
return (keys: readonly Key[])
|
|
6
|
+
export function stream(state: Effect.Success<typeof initialize>) {
|
|
7
|
+
return Effect.fn("LiveServer.stream")(function* (keys: readonly Key[]) {
|
|
8
|
+
return (yield* liveHintStream(state, keys)).pipe(Stream.flatMap((registration) => registration.stream));
|
|
9
|
+
});
|
|
7
10
|
}
|
|
@@ -1,16 +1,47 @@
|
|
|
1
|
-
import { Effect,
|
|
2
|
-
import
|
|
1
|
+
import { Effect, Stream } from "effect";
|
|
2
|
+
import { refreshSubscription } from "#adapters/refreshSubscription.ts";
|
|
3
|
+
import { compareQueries } from "#compareQueries.ts";
|
|
4
|
+
import type { LiveHint } from "#live.ts";
|
|
3
5
|
import type { QueryRerun, QuerySubscription } from "#querySubscription.ts";
|
|
4
6
|
import type { QueryUpdate, SubscriptionHint } from "#queryUpdate.ts";
|
|
5
|
-
import
|
|
7
|
+
import { QueryReadDenied } from "#readPolicyErrors.ts";
|
|
8
|
+
import { LiveServer } from "./service.ts";
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
function subscribeQueries<E, R, TRead extends QueryRerun<unknown, unknown> | undefined = undefined>(
|
|
11
|
+
subscription: QuerySubscription<E, R>,
|
|
12
|
+
read?: TRead & (QueryRerun<E, R> | undefined),
|
|
13
|
+
): Effect.Effect<
|
|
14
|
+
Stream.Stream<TRead extends undefined ? SubscriptionHint : QueryUpdate, E | QueryReadDenied, R>,
|
|
15
|
+
never,
|
|
16
|
+
typeof LiveServer.Identifier
|
|
17
|
+
>;
|
|
18
|
+
function subscribeQueries<E, R>(subscription: QuerySubscription<E, R>, read?: QueryRerun<E, R>) {
|
|
19
|
+
return Effect.fnUntraced(function* () {
|
|
20
|
+
const server = yield* LiveServer;
|
|
21
|
+
const hints = yield* server.register(subscription.keys);
|
|
22
|
+
return hints.pipe(
|
|
23
|
+
Stream.flatMap((registration) => {
|
|
24
|
+
let scopes = subscription.scopes;
|
|
25
|
+
let compare = compareQueries(subscription, read);
|
|
26
|
+
const next = Effect.fnUntraced(function* (hint: LiveHint) {
|
|
27
|
+
if (!(yield* subscription.authorized)) {
|
|
28
|
+
compare = compareQueries(subscription, read);
|
|
29
|
+
return [new QueryReadDenied({ message: "Read no longer allowed for subscribed queries" })];
|
|
30
|
+
}
|
|
31
|
+
const updates = yield* compare(hint, scopes);
|
|
32
|
+
if (subscription.readScopes !== undefined) {
|
|
33
|
+
scopes = yield* subscription.readScopes;
|
|
34
|
+
registration.replaceKeys(scopes.flat());
|
|
35
|
+
}
|
|
36
|
+
return updates;
|
|
37
|
+
});
|
|
38
|
+
return registration.stream.pipe(
|
|
39
|
+
Stream.mapEffect((hint) => refreshSubscription(subscription, next(hint))),
|
|
40
|
+
Stream.flatMap(Stream.fromIterable),
|
|
41
|
+
);
|
|
42
|
+
}),
|
|
43
|
+
);
|
|
44
|
+
})();
|
|
16
45
|
}
|
|
46
|
+
|
|
47
|
+
export const subscribe = Effect.fn("LiveServer.subscribe")(subscribeQueries);
|
package/src/makeLiveServer.ts
CHANGED
|
@@ -1,105 +1,4 @@
|
|
|
1
|
-
import { Effect
|
|
2
|
-
import
|
|
3
|
-
import { type Key, readKeys } from "@shivaedev/changes/keys.ts";
|
|
4
|
-
import { compareQueries } from "#compareQueries.ts";
|
|
5
|
-
import type { LiveHint } from "#live.ts";
|
|
6
|
-
import { liveHintQueue } from "#liveHintQueue.ts";
|
|
7
|
-
import type { QueryRerun, QuerySubscription } from "#querySubscription.ts";
|
|
8
|
-
import type { QueryUpdate, SubscriptionHint } from "#queryUpdate.ts";
|
|
9
|
-
import { QueryReadDenied } from "#readPolicyErrors.ts";
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { standaloneLiveServer } from "#adapters/standaloneLiveServer.ts";
|
|
10
3
|
|
|
11
|
-
export const makeLiveServer = Effect.
|
|
12
|
-
const reactivity = yield* Reactivity.Reactivity;
|
|
13
|
-
const dispatcher = (yield* Scheduler.Scheduler).makeDispatcher();
|
|
14
|
-
let openStreams = 0;
|
|
15
|
-
const resyncKey = `@shivaedev/contract/resync/${yield* Random.nextInt}`;
|
|
16
|
-
function open(keys: readonly Key[]) {
|
|
17
|
-
return Effect.gen(function* () {
|
|
18
|
-
const { offer, queue } = yield* liveHintQueue;
|
|
19
|
-
const pending = new Map<string, Key>();
|
|
20
|
-
let scheduled = false;
|
|
21
|
-
let resync = false;
|
|
22
|
-
let active = true;
|
|
23
|
-
function flush() {
|
|
24
|
-
if (scheduled) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
scheduled = true;
|
|
28
|
-
dispatcher.scheduleTask(() => {
|
|
29
|
-
scheduled = false;
|
|
30
|
-
if (active) {
|
|
31
|
-
offer(resync ? { _tag: "Resync" } : { _tag: "Changed", keys: [...pending.values()] });
|
|
32
|
-
}
|
|
33
|
-
pending.clear();
|
|
34
|
-
resync = false;
|
|
35
|
-
}, 0);
|
|
36
|
-
}
|
|
37
|
-
let cancelKeys: (() => void)[] = [];
|
|
38
|
-
function replaceKeys(current: readonly Key[]) {
|
|
39
|
-
for (const stop of cancelKeys) {
|
|
40
|
-
stop();
|
|
41
|
-
}
|
|
42
|
-
cancelKeys = current.map((key) => {
|
|
43
|
-
const own = readKeys([key]);
|
|
44
|
-
return reactivity.registerUnsafe(own, () => {
|
|
45
|
-
pending.set(own[0] ?? "", key);
|
|
46
|
-
flush();
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
replaceKeys(keys);
|
|
51
|
-
const cancel = [
|
|
52
|
-
reactivity.registerUnsafe([resyncKey], () => {
|
|
53
|
-
resync = true;
|
|
54
|
-
flush();
|
|
55
|
-
}),
|
|
56
|
-
];
|
|
57
|
-
openStreams += 1;
|
|
58
|
-
yield* Effect.addFinalizer(() =>
|
|
59
|
-
Effect.sync(() => {
|
|
60
|
-
active = false;
|
|
61
|
-
openStreams -= 1;
|
|
62
|
-
for (const stop of [...cancelKeys, ...cancel]) {
|
|
63
|
-
stop();
|
|
64
|
-
}
|
|
65
|
-
}),
|
|
66
|
-
);
|
|
67
|
-
yield* Queue.offer(queue, { _tag: "Resync" });
|
|
68
|
-
return { replaceKeys, stream: Stream.fromQueue(queue) };
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
const resync = Effect.sync(() => {
|
|
72
|
-
reactivity.invalidateUnsafe([resyncKey]);
|
|
73
|
-
return openStreams;
|
|
74
|
-
});
|
|
75
|
-
function subscribe<E, R>(subscription: QuerySubscription<E, R>): Stream.Stream<SubscriptionHint, E | QueryReadDenied, R>;
|
|
76
|
-
function subscribe<E, R>(subscription: QuerySubscription<E, R>, read: QueryRerun<E, R>): Stream.Stream<QueryUpdate, E | QueryReadDenied, R>;
|
|
77
|
-
function subscribe<E, R>(subscription: QuerySubscription<E, R>, read?: QueryRerun<E, R>) {
|
|
78
|
-
return Stream.unwrap(
|
|
79
|
-
Effect.gen(function* () {
|
|
80
|
-
const registration = yield* open(subscription.keys);
|
|
81
|
-
let scopes = subscription.scopes;
|
|
82
|
-
let compare = compareQueries(subscription, read);
|
|
83
|
-
const next = Effect.fnUntraced(function* (hint: LiveHint) {
|
|
84
|
-
if (!(yield* subscription.authorized)) {
|
|
85
|
-
compare = compareQueries(subscription, read);
|
|
86
|
-
return [new QueryReadDenied({ message: "Read no longer allowed for subscribed queries" })];
|
|
87
|
-
}
|
|
88
|
-
const updates = yield* compare(hint, scopes);
|
|
89
|
-
if (subscription.readScopes !== undefined) {
|
|
90
|
-
scopes = yield* subscription.readScopes;
|
|
91
|
-
registration.replaceKeys(scopes.flat());
|
|
92
|
-
}
|
|
93
|
-
return updates;
|
|
94
|
-
});
|
|
95
|
-
return registration.stream.pipe(
|
|
96
|
-
Stream.mapEffect((hint) =>
|
|
97
|
-
Effect.flatMap(subscription.refresh ?? Effect.context<never>(), (current) => Effect.provideContext(next(hint), current)),
|
|
98
|
-
),
|
|
99
|
-
Stream.flatMap(Stream.fromIterable),
|
|
100
|
-
);
|
|
101
|
-
}),
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
return { resync, stream: (keys: readonly Key[]) => Stream.unwrap(Effect.map(open(keys), ({ stream }) => stream)), subscribe };
|
|
105
|
-
});
|
|
4
|
+
export const makeLiveServer = Effect.fn("LiveServer.makeLiveServer")(() => standaloneLiveServer)();
|
package/src/querySubscription.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Context, Effect, type Option } from "effect";
|
|
2
2
|
import { Rpc } from "effect/rpc";
|
|
3
3
|
import type { Key } from "@shivaedev/changes/keys.ts";
|
|
4
|
-
import {
|
|
4
|
+
import { withPolicyContext } from "#adapters/withPolicyContext.ts";
|
|
5
5
|
import { queryReadKeys } from "#queryReadKeys.ts";
|
|
6
6
|
import { checkQuery, type PolicyChannels, type Viewer } from "#readPolicy.ts";
|
|
7
7
|
import type { MissingReadPolicy, QueryReadDenied } from "#readPolicyErrors.ts";
|
|
@@ -34,17 +34,14 @@ export function querySubscription(rpc: Rpc.Any, references: readonly QueryRefere
|
|
|
34
34
|
const policies = yield* Effect.forEach(
|
|
35
35
|
queries,
|
|
36
36
|
Effect.fnUntraced(function* ({ query, payload }) {
|
|
37
|
-
const
|
|
37
|
+
const policyRpc = Rpc.make(`${prefix}${query.name}`);
|
|
38
38
|
return {
|
|
39
|
-
check:
|
|
40
|
-
keys:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const current = yield* policyContext(Rpc.make(`${prefix}${query.name}`));
|
|
46
|
-
return yield* Effect.suspend(() => query.readPolicy?.(payload, viewer) ?? Effect.succeed(false)).pipe(Effect.provideContext(current));
|
|
47
|
-
}),
|
|
39
|
+
check: withPolicyContext(policyRpc, checkQuery(query, payload, viewer)),
|
|
40
|
+
keys: withPolicyContext(policyRpc, queryReadKeys(query, payload, viewer)),
|
|
41
|
+
permitted: withPolicyContext(
|
|
42
|
+
policyRpc,
|
|
43
|
+
Effect.suspend(() => query.readPolicy?.(payload, viewer) ?? Effect.succeed(false)),
|
|
44
|
+
),
|
|
48
45
|
};
|
|
49
46
|
}),
|
|
50
47
|
);
|
package/src/readPolicy.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Context, Effect, Option, type Stream, type Types } from "effect";
|
|
2
2
|
import type { Rpc } from "effect/rpc";
|
|
3
|
+
import { withPolicyContext } from "#adapters/withPolicyContext.ts";
|
|
3
4
|
import type { QueryShape } from "#operation.ts";
|
|
4
5
|
import { isPermissionReadPolicy } from "#permissionReadPolicy.ts";
|
|
5
|
-
import { policyContext } from "#policyContext.ts";
|
|
6
6
|
import { MissingReadPolicy, QueryReadDenied } from "#readPolicyErrors.ts";
|
|
7
7
|
import { QueryDefinition } from "#serverMetadata.ts";
|
|
8
8
|
|
|
@@ -49,8 +49,7 @@ export function authorizeReads(
|
|
|
49
49
|
return Effect.fnUntraced(function* () {
|
|
50
50
|
const definition = Context.getOption(request.rpc.annotations, QueryDefinition);
|
|
51
51
|
if (Option.isSome(definition)) {
|
|
52
|
-
|
|
53
|
-
yield* checkQuery(definition.value.definition, request.payload, viewer).pipe(Effect.provideContext(context));
|
|
52
|
+
yield* withPolicyContext(request.rpc, checkQuery(definition.value.definition, request.payload, viewer));
|
|
54
53
|
}
|
|
55
54
|
return yield* Effect.provideService(effect, CurrentViewer, viewer);
|
|
56
55
|
})();
|
package/src/rpcClient.ts
CHANGED
|
@@ -3,6 +3,7 @@ import * as Atom from "effect/reactivity/Atom";
|
|
|
3
3
|
import * as AtomRpc from "effect/reactivity/AtomRpc";
|
|
4
4
|
import { type Rpc, RpcClient, RpcGroup } from "effect/rpc";
|
|
5
5
|
import type { RpcClientError } from "effect/rpc/RpcClientError";
|
|
6
|
+
import { withClientProtocol } from "#adapters/withClientProtocol.ts";
|
|
6
7
|
import { Activity } from "#clientActivity.ts";
|
|
7
8
|
import type { ClientOptions } from "#clientOptions.ts";
|
|
8
9
|
import type { ResumeWindow } from "#resume.ts";
|
|
@@ -75,12 +76,9 @@ export function rpcClient(name: string, source: RpcSource, options: ClientOption
|
|
|
75
76
|
runtime: options.runtime,
|
|
76
77
|
});
|
|
77
78
|
clientActivities.set(Client, activity);
|
|
78
|
-
const directClient =
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
Object.fromEntries([...group.requests.keys()].map((tag) => [tag, (payload: never, callOptions: never) => flat(tag, payload, callOptions)])),
|
|
82
|
-
),
|
|
83
|
-
Effect.provideContext(context),
|
|
79
|
+
const directClient = withClientProtocol(protocol, make).pipe(
|
|
80
|
+
Effect.map((flat) =>
|
|
81
|
+
Object.fromEntries([...group.requests.keys()].map((tag) => [tag, (payload: never, callOptions: never) => flat(tag, payload, callOptions)])),
|
|
84
82
|
),
|
|
85
83
|
);
|
|
86
84
|
const layer = Layer.effect(Client, make).pipe(Layer.provide(protocol));
|
package/dist/LiveServer.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
2
|
-
export declare const LiveServer: import("effect/Context").Service<"@shivaedev/contract/LiveServer", Readonly<{
|
|
3
|
-
readonly resync: () => import("effect/Effect").Effect<number, never, never>;
|
|
4
|
-
readonly stream: (keys: readonly import("@shivaedev/changes/keys.ts").Key[]) => import("effect/Effect").Effect<import("effect/Stream").Stream<{
|
|
5
|
-
readonly _tag: "Changed";
|
|
6
|
-
readonly keys: readonly ({
|
|
7
|
-
readonly _tag: "Bucket";
|
|
8
|
-
readonly collection: string;
|
|
9
|
-
readonly field: string;
|
|
10
|
-
readonly value: string | number;
|
|
11
|
-
} | {
|
|
12
|
-
readonly _tag: "List";
|
|
13
|
-
readonly collection: string;
|
|
14
|
-
} | {
|
|
15
|
-
readonly _tag: "Item";
|
|
16
|
-
readonly collection: string;
|
|
17
|
-
readonly id: string | number;
|
|
18
|
-
})[];
|
|
19
|
-
readonly queryIndexes?: readonly number[] | undefined;
|
|
20
|
-
} | {
|
|
21
|
-
readonly _tag: "Resync";
|
|
22
|
-
}, never, never>, never, never>;
|
|
23
|
-
readonly subscribe: <E, R, TRead extends import("./querySubscription.ts").QueryRerun<unknown, unknown> | undefined = undefined>(subscription: import("./querySubscription.ts").QuerySubscription<E, R>, read?: (TRead & (import("./querySubscription.ts").QueryRerun<E, R> | undefined)) | undefined) => import("effect/Effect").Effect<import("effect/Stream").Stream<TRead extends undefined ? import("./queryUpdate.ts").SubscriptionHint : import("./queryUpdate.ts").QueryUpdate, E | import("./readPolicyErrors.ts").QueryReadDenied, R>>;
|
|
24
|
-
}>> & {
|
|
25
|
-
readonly layer: import("effect/Layer").Layer<"@shivaedev/contract/LiveServer", never, Reactivity.Reactivity>;
|
|
26
|
-
};
|
|
27
|
-
//# sourceMappingURL=LiveServer.d.ts.map
|
package/dist/LiveServer.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LiveServer.d.ts","sourceRoot":"","sources":["../src/LiveServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAQ3D,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;CASrB,CAAC"}
|
package/dist/LiveServer.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
2
|
-
import { defineService } from "@shivaedev/service/defineService.ts";
|
|
3
|
-
import { genericMethod } from "@shivaedev/service/genericMethod.ts";
|
|
4
|
-
import { resync } from "#live-server/resync.ts";
|
|
5
|
-
import { stream } from "#live-server/stream.ts";
|
|
6
|
-
import { subscribe } from "#live-server/subscribe.ts";
|
|
7
|
-
import { makeLiveServer } from "#makeLiveServer.ts";
|
|
8
|
-
export const LiveServer = defineService({
|
|
9
|
-
id: "@shivaedev/contract/LiveServer",
|
|
10
|
-
initialize: makeLiveServer,
|
|
11
|
-
methods: (server) => ({
|
|
12
|
-
resync: resync(server),
|
|
13
|
-
stream: stream(server),
|
|
14
|
-
subscribe: genericMethod(subscribe(server)),
|
|
15
|
-
}),
|
|
16
|
-
requires: [Reactivity.Reactivity],
|
|
17
|
-
});
|
|
18
|
-
//# sourceMappingURL=LiveServer.js.map
|
package/dist/LiveServer.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LiveServer.js","sourceRoot":"","sources":["../src/LiveServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CAAC;IACvC,EAAE,EAAE,gCAAgC;IACpC,UAAU,EAAE,cAAc;IAC1B,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACrB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;QACtB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;QACtB,SAAS,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;KAC3C,CAAC;IACF,QAAQ,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC;CACjC,CAAC,CAAC"}
|
package/src/LiveServer.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
2
|
-
import { defineService } from "@shivaedev/service/defineService.ts";
|
|
3
|
-
import { genericMethod } from "@shivaedev/service/genericMethod.ts";
|
|
4
|
-
import { resync } from "#live-server/resync.ts";
|
|
5
|
-
import { stream } from "#live-server/stream.ts";
|
|
6
|
-
import { subscribe } from "#live-server/subscribe.ts";
|
|
7
|
-
import { makeLiveServer } from "#makeLiveServer.ts";
|
|
8
|
-
|
|
9
|
-
export const LiveServer = defineService({
|
|
10
|
-
id: "@shivaedev/contract/LiveServer",
|
|
11
|
-
initialize: makeLiveServer,
|
|
12
|
-
methods: (server) => ({
|
|
13
|
-
resync: resync(server),
|
|
14
|
-
stream: stream(server),
|
|
15
|
-
subscribe: genericMethod(subscribe(server)),
|
|
16
|
-
}),
|
|
17
|
-
requires: [Reactivity.Reactivity],
|
|
18
|
-
});
|