@shivaedev/contract 0.42.0 → 0.43.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 +11 -0
- package/README.md +27 -177
- package/dist/AutomaticQueryOptions.d.ts +0 -5
- package/dist/AutomaticQueryOptions.d.ts.map +1 -1
- package/dist/HostVersion.d.ts +1 -19
- package/dist/HostVersion.d.ts.map +1 -1
- package/dist/adapters/activityState.d.ts.map +1 -1
- package/dist/adapters/activityState.js +0 -1
- package/dist/adapters/activityState.js.map +1 -1
- package/dist/adapters/liveHintStream.d.ts +0 -1
- package/dist/adapters/liveHintStream.d.ts.map +1 -1
- package/dist/adapters/openLiveHints.d.ts +0 -1
- package/dist/adapters/openLiveHints.d.ts.map +1 -1
- package/dist/adapters/standaloneLiveServer.d.ts +1 -7
- package/dist/adapters/standaloneLiveServer.d.ts.map +1 -1
- package/dist/adapters/standaloneLiveServer.js.map +1 -1
- package/dist/automaticLive.d.ts +2 -4
- package/dist/automaticLive.d.ts.map +1 -1
- package/dist/automaticLive.js +5 -14
- package/dist/automaticLive.js.map +1 -1
- package/dist/automaticQuery.d.ts +1 -1
- package/dist/automaticQuery.d.ts.map +1 -1
- package/dist/automaticQuery.js +20 -26
- package/dist/automaticQuery.js.map +1 -1
- package/dist/changesSuccess.d.ts +2 -3
- package/dist/changesSuccess.d.ts.map +1 -1
- package/dist/changesSuccess.js +1 -3
- package/dist/changesSuccess.js.map +1 -1
- package/dist/clientActivities.d.ts +0 -2
- package/dist/clientActivities.d.ts.map +1 -1
- package/dist/clientActivities.js +0 -4
- package/dist/clientActivities.js.map +1 -1
- package/dist/clientActivity.d.ts +0 -1
- package/dist/clientActivity.d.ts.map +1 -1
- package/dist/clientActivity.js +1 -1
- package/dist/clientActivity.js.map +1 -1
- package/dist/clientOperations.d.ts.map +1 -1
- package/dist/clientOperations.js +1 -3
- package/dist/clientOperations.js.map +1 -1
- package/dist/compareQueries.d.ts +2 -19
- package/dist/compareQueries.d.ts.map +1 -1
- package/dist/compareQueries.js +6 -33
- package/dist/compareQueries.js.map +1 -1
- package/dist/live-server/register.d.ts +0 -1
- package/dist/live-server/register.d.ts.map +1 -1
- package/dist/live-server/service.d.ts +0 -2
- package/dist/live-server/service.d.ts.map +1 -1
- package/dist/live-server/stream.d.ts +0 -1
- package/dist/live-server/stream.d.ts.map +1 -1
- package/dist/live-server/subscribe.d.ts +2 -2
- package/dist/live-server/subscribe.d.ts.map +1 -1
- package/dist/live-server/subscribe.js.map +1 -1
- package/dist/live.d.ts +5 -12
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +15 -85
- package/dist/live.js.map +1 -1
- package/dist/liveAttempt.d.ts +3 -6
- package/dist/liveAttempt.d.ts.map +1 -1
- package/dist/liveAttempt.js +11 -30
- package/dist/liveAttempt.js.map +1 -1
- package/dist/liveHintQueue.d.ts +0 -1
- package/dist/liveHintQueue.d.ts.map +1 -1
- package/dist/liveHintQueue.js +9 -12
- package/dist/liveHintQueue.js.map +1 -1
- package/dist/makeLiveServer.d.ts +1 -5
- package/dist/makeLiveServer.d.ts.map +1 -1
- package/dist/operation.d.ts +2 -4
- package/dist/operation.d.ts.map +1 -1
- package/dist/operation.js +0 -1
- package/dist/operation.js.map +1 -1
- package/dist/operationDeclaration.d.ts +1 -2
- package/dist/operationDeclaration.d.ts.map +1 -1
- package/dist/operationDeclaration.js.map +1 -1
- package/dist/publicConfig.d.ts +6 -21
- package/dist/publicConfig.d.ts.map +1 -1
- package/dist/queryDelivery.d.ts +4 -5
- package/dist/queryDelivery.d.ts.map +1 -1
- package/dist/queryDelivery.js +4 -15
- package/dist/queryDelivery.js.map +1 -1
- package/dist/queryProgress.d.ts.map +1 -1
- package/dist/queryProgress.js +0 -3
- package/dist/queryProgress.js.map +1 -1
- package/dist/querySubscription.d.ts +1 -1
- package/dist/querySubscription.d.ts.map +1 -1
- package/dist/queryUpdate.d.ts +15 -4
- package/dist/queryUpdate.d.ts.map +1 -1
- package/dist/queryUpdate.js +7 -1
- package/dist/queryUpdate.js.map +1 -1
- package/dist/retainQuery.d.ts.map +1 -1
- package/dist/retainQuery.js +0 -3
- package/dist/retainQuery.js.map +1 -1
- package/package.json +8 -8
- package/src/AutomaticQueryOptions.ts +0 -5
- package/src/adapters/activityState.ts +0 -1
- package/src/adapters/standaloneLiveServer.ts +1 -5
- package/src/automaticLive.ts +4 -16
- package/src/automaticQuery.ts +28 -42
- package/src/changesSuccess.ts +3 -5
- package/src/clientActivities.ts +1 -5
- package/src/clientActivity.ts +1 -2
- package/src/clientOperations.ts +1 -4
- package/src/compareQueries.ts +12 -38
- package/src/live-server/subscribe.ts +5 -9
- package/src/live.ts +19 -97
- package/src/liveAttempt.ts +17 -41
- package/src/liveHintQueue.ts +9 -12
- package/src/operation.ts +3 -17
- package/src/operationDeclaration.ts +0 -2
- package/src/queryDelivery.ts +6 -26
- package/src/queryProgress.ts +0 -3
- package/src/querySubscription.ts +1 -1
- package/src/queryUpdate.ts +10 -4
- package/src/retainQuery.ts +0 -3
- package/dist/liveInvalidation.d.ts +0 -12
- package/dist/liveInvalidation.d.ts.map +0 -1
- package/dist/liveInvalidation.js +0 -14
- package/dist/liveInvalidation.js.map +0 -1
- package/dist/livePending.d.ts +0 -7
- package/dist/livePending.d.ts.map +0 -1
- package/dist/livePending.js +0 -27
- package/dist/livePending.js.map +0 -1
- package/dist/queryCoalesceWindow.d.ts +0 -4
- package/dist/queryCoalesceWindow.d.ts.map +0 -1
- package/dist/queryCoalesceWindow.js +0 -11
- package/dist/queryCoalesceWindow.js.map +0 -1
- package/dist/queryFailure.d.ts +0 -4
- package/dist/queryFailure.d.ts.map +0 -1
- package/dist/queryFailure.js +0 -12
- package/dist/queryFailure.js.map +0 -1
- package/dist/queryHints.d.ts +0 -9
- package/dist/queryHints.d.ts.map +0 -1
- package/dist/queryHints.js +0 -34
- package/dist/queryHints.js.map +0 -1
- package/dist/queryReactivity.d.ts +0 -5
- package/dist/queryReactivity.d.ts.map +0 -1
- package/dist/queryReactivity.js +0 -109
- package/dist/queryReactivity.js.map +0 -1
- package/src/liveInvalidation.ts +0 -21
- package/src/livePending.ts +0 -28
- package/src/queryCoalesceWindow.ts +0 -13
- package/src/queryFailure.ts +0 -13
- package/src/queryHints.ts +0 -39
- package/src/queryReactivity.ts +0 -127
package/src/compareQueries.ts
CHANGED
|
@@ -2,45 +2,23 @@ import { Effect, Schema } from "effect";
|
|
|
2
2
|
import { Digest } from "effect/crypto";
|
|
3
3
|
import type { Key } from "@shivaedev/changes/keys.ts";
|
|
4
4
|
import type { LiveHint } from "#live.ts";
|
|
5
|
-
import { changedHint } from "#queryHints.ts";
|
|
6
5
|
import type { QueryRerun, QuerySubscription } from "#querySubscription.ts";
|
|
7
6
|
import type { QueryResult, QueryUnchanged, QueryUpdate } from "#queryUpdate.ts";
|
|
8
7
|
import type { QueryRequest } from "#serverMetadata.ts";
|
|
9
8
|
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
const scopes = subscription.scopes.map((scope, index) => (queries[index]?.query.live === "rerun-and-compare" ? [] : scope));
|
|
19
|
-
if (queries.every(({ query }) => query.live === "rerun-and-compare")) {
|
|
20
|
-
return [];
|
|
21
|
-
}
|
|
22
|
-
if (hint._tag === "Resync") {
|
|
23
|
-
return [hint];
|
|
24
|
-
}
|
|
25
|
-
const keys = new Set(scopes.flatMap((scope) => scope.map((key) => JSON.stringify(key))));
|
|
26
|
-
const visible: readonly Key[] = hint.keys.filter((key) => keys.has(JSON.stringify(key)));
|
|
27
|
-
return visible.length === 0 ? [] : [changedHint(visible, scopes)];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function compareQueries<E, R>(subscription: QuerySubscription<unknown, unknown>, read?: QueryRerun<E, R>, initialRead = true) {
|
|
31
|
-
const queries = subscription.queries ?? [];
|
|
9
|
+
export function compareQueries<E, R>(
|
|
10
|
+
subscription: QuerySubscription<unknown, unknown>,
|
|
11
|
+
read: QueryRerun<E, R>,
|
|
12
|
+
initialRead?: boolean,
|
|
13
|
+
): (hint: LiveHint, scopes?: readonly (readonly Key[])[]) => Effect.Effect<readonly QueryUpdate[], E, R>;
|
|
14
|
+
export function compareQueries<E, R>(subscription: QuerySubscription<unknown, unknown>, read: QueryRerun<E, R>, initialRead = true) {
|
|
15
|
+
const queries = subscription.queries;
|
|
32
16
|
const hashes = new Map<number, string>();
|
|
33
|
-
let initial = initialRead &&
|
|
17
|
+
let initial = initialRead && queries.length > 0;
|
|
34
18
|
const resultFor = Effect.fnUntraced(function* (request: QueryRequest, index: number) {
|
|
35
|
-
if (read === undefined) {
|
|
36
|
-
return yield* Effect.die(new Error("Result subscriptions require an authorized query runner"));
|
|
37
|
-
}
|
|
38
19
|
const value = yield* read(request);
|
|
39
|
-
if (request.query.live !== "rerun-and-compare") {
|
|
40
|
-
return { _tag: "Result", query: request.query.name, queryIndex: index, value } satisfies QueryResult;
|
|
41
|
-
}
|
|
42
20
|
const encoded = yield* Schema.encodeUnknownEffect(Schema.toCodecJson(request.query.success))(value).pipe(Effect.orDie);
|
|
43
|
-
const digest = yield* Digest.Digest;
|
|
21
|
+
const digest = yield* Digest.Digest.pipe(Effect.provide(Digest.layerWebCrypto));
|
|
44
22
|
const hash = yield* digest.digestHex(Digest.sha256, new TextEncoder().encode(JSON.stringify(encoded)));
|
|
45
23
|
if (hash === hashes.get(index)) {
|
|
46
24
|
return { _tag: "Unchanged", queryIndex: index } satisfies QueryUnchanged;
|
|
@@ -50,19 +28,15 @@ export function compareQueries<E, R>(subscription: QuerySubscription<unknown, un
|
|
|
50
28
|
});
|
|
51
29
|
return Effect.fnUntraced(function* (hint: LiveHint, scopes: readonly (readonly Key[])[] = subscription.scopes) {
|
|
52
30
|
const updates: QueryUpdate[] = [];
|
|
53
|
-
const
|
|
31
|
+
const changed = new Set(hint._tag === "Changed" ? hint.keys.map((key) => JSON.stringify(key)) : []);
|
|
54
32
|
const matching = queries
|
|
55
33
|
.map((request, index) => ({ index, request }))
|
|
56
|
-
.filter(
|
|
57
|
-
({ index, request }) =>
|
|
58
|
-
initial || (request.query.live === "rerun-and-compare" && (affected?._tag !== "Changed" || affected.queryIndexes?.includes(index))),
|
|
59
|
-
);
|
|
34
|
+
.filter(({ index }) => initial || hint._tag === "Resync" || scopes[index]?.some((key) => changed.has(JSON.stringify(key))));
|
|
60
35
|
for (const { index, request } of matching) {
|
|
61
36
|
const result = yield* resultFor(request, index);
|
|
62
37
|
updates.push(result);
|
|
63
38
|
}
|
|
64
|
-
const hints = initial ? [] : hintsFor(hint, { ...subscription, scopes });
|
|
65
39
|
initial = false;
|
|
66
|
-
return
|
|
40
|
+
return updates;
|
|
67
41
|
});
|
|
68
42
|
}
|
|
@@ -3,19 +3,15 @@ import { refreshSubscription } from "#adapters/refreshSubscription.ts";
|
|
|
3
3
|
import { compareQueries } from "#compareQueries.ts";
|
|
4
4
|
import type { LiveHint } from "#live.ts";
|
|
5
5
|
import type { QueryRerun, QuerySubscription } from "#querySubscription.ts";
|
|
6
|
-
import type { QueryUpdate
|
|
6
|
+
import type { QueryUpdate } from "#queryUpdate.ts";
|
|
7
7
|
import { QueryReadDenied } from "#readPolicyErrors.ts";
|
|
8
8
|
import { LiveServer } from "./service.ts";
|
|
9
9
|
|
|
10
|
-
function subscribeQueries<E, R
|
|
10
|
+
function subscribeQueries<E, R>(
|
|
11
11
|
subscription: QuerySubscription<E, R>,
|
|
12
|
-
read
|
|
13
|
-
): Effect.Effect<
|
|
14
|
-
|
|
15
|
-
never,
|
|
16
|
-
typeof LiveServer.Identifier
|
|
17
|
-
>;
|
|
18
|
-
function subscribeQueries<E, R>(subscription: QuerySubscription<E, R>, read?: QueryRerun<E, R>) {
|
|
12
|
+
read: QueryRerun<E, R>,
|
|
13
|
+
): Effect.Effect<Stream.Stream<QueryUpdate, E | QueryReadDenied, R>, never, typeof LiveServer.Identifier>;
|
|
14
|
+
function subscribeQueries<E, R>(subscription: QuerySubscription<E, R>, read: QueryRerun<E, R>) {
|
|
19
15
|
return Effect.fnUntraced(function* () {
|
|
20
16
|
const server = yield* LiveServer;
|
|
21
17
|
const hints = yield* server.register(subscription.keys);
|
package/src/live.ts
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import { Cause,
|
|
1
|
+
import { Cause, Effect, Option, Queue, Schema, type Stream } from "effect";
|
|
2
2
|
import * as Atom from "effect/reactivity/Atom";
|
|
3
|
-
import type * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
4
|
-
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
5
3
|
import { Key } from "@shivaedev/changes/keys.ts";
|
|
6
|
-
import {
|
|
4
|
+
import { clientReadKeys, type KeyContext } from "#clientKeys.ts";
|
|
7
5
|
import { liveAttempt } from "#liveAttempt.ts";
|
|
8
|
-
import { invalidateLive } from "#liveInvalidation.ts";
|
|
9
|
-
import { livePending } from "#livePending.ts";
|
|
10
6
|
import { liveRetry } from "#liveRetry.ts";
|
|
11
|
-
import type {
|
|
7
|
+
import type { SubscriptionEvent } from "#queryUpdate.ts";
|
|
12
8
|
import type { QueryReadDenied } from "#readPolicyErrors.ts";
|
|
13
9
|
import { retryOnChange } from "#retryOnChange.ts";
|
|
14
10
|
|
|
15
11
|
export const LiveHint = Schema.Union([
|
|
16
|
-
Schema.Struct({ _tag: Schema.Literal("Changed"), keys: Schema.Array(Key)
|
|
12
|
+
Schema.Struct({ _tag: Schema.Literal("Changed"), keys: Schema.Array(Key) }),
|
|
17
13
|
Schema.Struct({ _tag: Schema.Literal("Resync") }),
|
|
18
14
|
]);
|
|
19
15
|
export type LiveHint = typeof LiveHint.Type;
|
|
@@ -24,127 +20,53 @@ export interface LiveStatus<E> {
|
|
|
24
20
|
readonly pending: number;
|
|
25
21
|
}
|
|
26
22
|
export interface LiveOptions<E, R> {
|
|
27
|
-
readonly coalesceWindow?: Duration.Input;
|
|
28
|
-
readonly initialResync?: boolean;
|
|
29
23
|
readonly keyContext?: KeyContext | undefined;
|
|
30
|
-
readonly reopenOnResume?: boolean;
|
|
31
24
|
readonly resume?: Atom.Atom<unknown>;
|
|
32
|
-
readonly
|
|
33
|
-
readonly
|
|
34
|
-
readonly
|
|
35
|
-
readonly stream: Stream.Stream<SubscriptionHint, E, R>;
|
|
25
|
+
readonly retryDelay?: import("effect").Duration.Input;
|
|
26
|
+
readonly retryKeys?: readonly (typeof Key.Type)[];
|
|
27
|
+
readonly stream: Stream.Stream<SubscriptionEvent, E, R>;
|
|
36
28
|
}
|
|
37
29
|
|
|
38
|
-
const MAX_PENDING = 256;
|
|
39
|
-
|
|
40
30
|
export function live<R, E, TRuntimeError>(runtime: Atom.AtomRuntime<R, TRuntimeError>, options: LiveOptions<E, R>) {
|
|
41
|
-
const coalesceWindow = Atom.keepAlive(Atom.make<Duration.Input>(options.coalesceWindow ?? "20 millis"));
|
|
42
31
|
const paused = Atom.make(false);
|
|
43
32
|
const status = Atom.make<LiveStatus<E>>({ connection: "connecting", failure: Option.none(), needsResync: true, pending: 0 });
|
|
44
33
|
const connection = runtime
|
|
45
34
|
.atom((get) =>
|
|
46
35
|
Effect.gen(function* () {
|
|
47
36
|
get.mount(status);
|
|
37
|
+
get.mount(paused);
|
|
48
38
|
const resumed = yield* Queue.unbounded<void>();
|
|
49
|
-
|
|
50
|
-
const retryKeys = options.retryKeys ?? (typeof options.resyncKeys === "function" ? options.resyncKeys(get.registry) : options.resyncKeys);
|
|
51
|
-
yield* retryOnChange(status, clientReadKeys(retryKeys, options.keyContext), () => get.refreshSelf());
|
|
39
|
+
yield* retryOnChange(status, clientReadKeys(options.retryKeys ?? [], options.keyContext), () => get.refreshSelf());
|
|
52
40
|
function update(value: Partial<LiveStatus<E>>) {
|
|
53
41
|
get.set(status, { ...get.once(status), ...value });
|
|
54
42
|
}
|
|
55
|
-
function flush() {
|
|
56
|
-
const queued = pending.take();
|
|
57
|
-
if (!get.once(paused)) {
|
|
58
|
-
invalidateLive(reactivity, queued, () => active && !get.once(paused));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
const timer = runtime.fn((delay: Duration.Input) => Effect.andThen(Effect.sleep(delay), Effect.sync(flush)));
|
|
62
|
-
get.mount(timer);
|
|
63
|
-
const pending = livePending(
|
|
64
|
-
(window) => get.set(timer, window),
|
|
65
|
-
() => get.set(timer, Atom.Interrupt),
|
|
66
|
-
);
|
|
67
|
-
let active = true;
|
|
68
43
|
get.addFinalizer(() => {
|
|
69
|
-
active = false;
|
|
70
|
-
pending.clear();
|
|
71
44
|
if (get.registry.getNodes().has(status)) {
|
|
72
45
|
update({ connection: "connecting", failure: Option.none(), needsResync: true, pending: 0 });
|
|
73
46
|
}
|
|
74
47
|
});
|
|
75
|
-
function changed(changedKeys: readonly Key[]) {
|
|
76
|
-
const window = get.once(coalesceWindow);
|
|
77
|
-
const keys = clientInvalidationKeys(changedKeys, options.keyContext);
|
|
78
|
-
invalidateLive(reactivity, keys, () => active && !get.once(paused), window);
|
|
79
|
-
const delay = Duration.toMillis(Duration.fromInputUnsafe(window));
|
|
80
|
-
if (delay === 0) {
|
|
81
|
-
invalidateLive(reactivity, keys, () => active && !get.once(paused));
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
pending.add(keys, window);
|
|
85
|
-
}
|
|
86
|
-
function resync() {
|
|
87
|
-
if (get.once(status).connection === "failed") {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
pending.clear();
|
|
91
|
-
if (get.once(paused)) {
|
|
92
|
-
update({ needsResync: true });
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
const keys = typeof options.resyncKeys === "function" ? options.resyncKeys(get.registry) : options.resyncKeys;
|
|
96
|
-
reactivity.invalidateUnsafe(keys.map((key) => clientReadKeys([key], options.keyContext)[0] ?? ""));
|
|
97
|
-
update({ needsResync: false, pending: 0 });
|
|
98
|
-
}
|
|
99
|
-
// A subscription alone does not build the flag, so its first read would otherwise announce a change.
|
|
100
|
-
get.once(paused);
|
|
101
|
-
get.subscribe(paused, (value) => {
|
|
102
|
-
if (!value) {
|
|
103
|
-
resync();
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
function resume() {
|
|
107
|
-
const current = get.once(status).connection;
|
|
108
|
-
if (current === "failed") {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
resync();
|
|
112
|
-
if (options.reopenOnResume === true || current === "reconnecting") {
|
|
113
|
-
Queue.offerUnsafe(resumed, undefined);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
48
|
if (options.resume !== undefined) {
|
|
117
|
-
// A subscription alone does not initialize a derived signal's dependencies.
|
|
118
49
|
get.once(options.resume);
|
|
119
|
-
get.subscribe(options.resume,
|
|
50
|
+
get.subscribe(options.resume, () => {
|
|
51
|
+
if (!get.once(paused) && get.once(status).connection !== "failed") {
|
|
52
|
+
Queue.offerUnsafe(resumed, undefined);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
120
55
|
}
|
|
121
56
|
const attempt = liveAttempt(options.stream, {
|
|
122
|
-
|
|
123
|
-
denied: (denial) => {
|
|
124
|
-
pending.clear();
|
|
125
|
-
update({ connection: "failed", failure: Option.some(Cause.fail(denial)), needsResync: true, pending: 0 });
|
|
126
|
-
},
|
|
127
|
-
live: () => update({ connection: "live", failure: Option.none() }),
|
|
57
|
+
delivered: () => update({ connection: "live", failure: Option.none(), needsResync: false, pending: 0 }),
|
|
58
|
+
denied: (denial) => update({ connection: "failed", failure: Option.some(Cause.fail(denial)), needsResync: true, pending: 0 }),
|
|
128
59
|
paused: () => get.once(paused),
|
|
129
|
-
queued: () => update({ needsResync: true, pending: Math.min(
|
|
130
|
-
reconcile: (connected) => {
|
|
131
|
-
if (connected || options.initialResync !== false) {
|
|
132
|
-
resync();
|
|
133
|
-
} else {
|
|
134
|
-
update({ needsResync: false });
|
|
135
|
-
}
|
|
136
|
-
},
|
|
60
|
+
queued: () => update({ connection: "live", needsResync: true, pending: Math.min(256, get.once(status).pending + 1) }),
|
|
137
61
|
});
|
|
138
62
|
yield* liveRetry(
|
|
139
63
|
attempt,
|
|
140
|
-
(failure, retry) => {
|
|
141
|
-
update({ connection: retry ? "reconnecting" : "failed", failure, needsResync: true });
|
|
142
|
-
},
|
|
64
|
+
(failure, retry) => update({ connection: retry ? "reconnecting" : "failed", failure, needsResync: true }),
|
|
143
65
|
options.retryDelay,
|
|
144
66
|
resumed,
|
|
145
67
|
);
|
|
146
68
|
}),
|
|
147
69
|
)
|
|
148
70
|
.pipe(Atom.setIdleTTL(0));
|
|
149
|
-
return {
|
|
71
|
+
return { connection, paused, status };
|
|
150
72
|
}
|
package/src/liveAttempt.ts
CHANGED
|
@@ -1,52 +1,28 @@
|
|
|
1
1
|
import { Effect, Stream } from "effect";
|
|
2
|
-
import type {
|
|
3
|
-
import type { SubscriptionHint } from "#queryUpdate.ts";
|
|
2
|
+
import type { SubscriptionEvent } from "#queryUpdate.ts";
|
|
4
3
|
import type { QueryReadDenied } from "#readPolicyErrors.ts";
|
|
5
4
|
|
|
6
|
-
function deliveredResult(hint: SubscriptionHint): boolean {
|
|
7
|
-
return hint._tag === "Changed" && hint.keys.length === 0 && hint.queryIndexes?.length === 0;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function needsRead(hint: SubscriptionHint, connected: boolean): boolean {
|
|
11
|
-
return connected && !deliveredResult(hint);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
5
|
export function liveAttempt<E, R>(
|
|
15
|
-
stream: Stream.Stream<
|
|
6
|
+
stream: Stream.Stream<SubscriptionEvent, E, R>,
|
|
16
7
|
observe: {
|
|
17
|
-
readonly changed: (keys: readonly Key[]) => void;
|
|
18
8
|
readonly denied: (denial: QueryReadDenied) => void;
|
|
19
|
-
readonly
|
|
9
|
+
readonly delivered: () => void;
|
|
20
10
|
readonly paused: () => boolean;
|
|
21
11
|
readonly queued: () => void;
|
|
22
|
-
readonly reconcile: (connected: boolean) => void;
|
|
23
12
|
},
|
|
24
13
|
) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
observe.queued();
|
|
40
|
-
} else if (first || hint._tag === "Resync" || deliveredResult(hint)) {
|
|
41
|
-
observe.reconcile(needsRead(hint, connected));
|
|
42
|
-
} else {
|
|
43
|
-
observe.changed(hint.keys);
|
|
44
|
-
}
|
|
45
|
-
connected = true;
|
|
46
|
-
first = false;
|
|
47
|
-
}),
|
|
48
|
-
),
|
|
49
|
-
Effect.scoped,
|
|
50
|
-
);
|
|
51
|
-
});
|
|
14
|
+
return stream.pipe(
|
|
15
|
+
Stream.runForEach((event) =>
|
|
16
|
+
Effect.sync(() => {
|
|
17
|
+
if (event._tag === "QueryReadDenied") {
|
|
18
|
+
observe.denied(event);
|
|
19
|
+
} else if (observe.paused()) {
|
|
20
|
+
observe.queued();
|
|
21
|
+
} else {
|
|
22
|
+
observe.delivered();
|
|
23
|
+
}
|
|
24
|
+
}),
|
|
25
|
+
),
|
|
26
|
+
Effect.scoped,
|
|
27
|
+
);
|
|
52
28
|
}
|
package/src/liveHintQueue.ts
CHANGED
|
@@ -2,21 +2,18 @@ import { Effect, Queue } from "effect";
|
|
|
2
2
|
import type { LiveHint } from "#live.ts";
|
|
3
3
|
|
|
4
4
|
export const liveHintQueue = Effect.gen(function* () {
|
|
5
|
-
const queue = yield* Queue.bounded<LiveHint>(
|
|
6
|
-
let
|
|
5
|
+
const queue = yield* Queue.bounded<LiveHint>(1);
|
|
6
|
+
let count = 0;
|
|
7
7
|
function offer(hint: LiveHint) {
|
|
8
|
-
|
|
8
|
+
const queued = Queue.takeUnsafe(queue);
|
|
9
|
+
const pending = queued?._tag === "Success" ? queued.value : undefined;
|
|
10
|
+
count = pending === undefined ? 1 : count + 1;
|
|
11
|
+
if (pending?._tag === "Resync" || hint._tag === "Resync" || count > 256) {
|
|
12
|
+
Queue.offerUnsafe(queue, { _tag: "Resync" });
|
|
9
13
|
return;
|
|
10
14
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
while (Queue.takeUnsafe(queue) !== undefined) {
|
|
16
|
-
// Overflow discards targeted hints because the resync covers every subscribed read.
|
|
17
|
-
}
|
|
18
|
-
overflowed = true;
|
|
19
|
-
Queue.offerUnsafe(queue, { _tag: "Resync" });
|
|
15
|
+
const keys = new Map([...(pending?.keys ?? []), ...hint.keys].map((key) => [JSON.stringify(key), key]));
|
|
16
|
+
Queue.offerUnsafe(queue, { _tag: "Changed", keys: [...keys.values()] });
|
|
20
17
|
}
|
|
21
18
|
return { offer, queue };
|
|
22
19
|
});
|
package/src/operation.ts
CHANGED
|
@@ -25,7 +25,6 @@ export interface OperationShape {
|
|
|
25
25
|
|
|
26
26
|
export interface QueryShape<E = unknown, R = unknown> extends OperationShape {
|
|
27
27
|
readonly kind: "query";
|
|
28
|
-
readonly live?: "rerun-and-compare" | undefined;
|
|
29
28
|
readonly readPolicy: Bivariant<QueryReadPolicy<unknown, E, R>>;
|
|
30
29
|
reads: Bivariant<(payload: unknown, viewer: Option.Option<Viewer>) => readonly Key[]>;
|
|
31
30
|
readonly readsCollections?: readonly { readonly name: string }[] | undefined;
|
|
@@ -53,16 +52,9 @@ interface Operation<TName extends string, TPayload extends Schema.Top, TSuccess
|
|
|
53
52
|
readonly success: TSuccess;
|
|
54
53
|
}
|
|
55
54
|
|
|
56
|
-
export interface Query<
|
|
57
|
-
TName
|
|
58
|
-
TPayload extends Schema.Top,
|
|
59
|
-
TSuccess extends Schema.Top,
|
|
60
|
-
TSpecs extends RejectionSpecs,
|
|
61
|
-
R = never,
|
|
62
|
-
TLive extends "rerun-and-compare" | undefined = undefined,
|
|
63
|
-
> extends Operation<TName, TPayload, TSuccess, TSpecs> {
|
|
55
|
+
export interface Query<TName extends string, TPayload extends Schema.Top, TSuccess extends Schema.Top, TSpecs extends RejectionSpecs, R = never>
|
|
56
|
+
extends Operation<TName, TPayload, TSuccess, TSpecs> {
|
|
64
57
|
readonly kind: "query";
|
|
65
|
-
readonly live?: TLive;
|
|
66
58
|
readonly readPolicy: QueryReadPolicy<TPayload["Type"], RejectedBy<TSpecs>, R>;
|
|
67
59
|
reads: (payload: TPayload["Type"], viewer: Option.Option<Viewer>) => readonly Key[];
|
|
68
60
|
readonly readsCollections?: readonly { readonly name: string }[] | undefined;
|
|
@@ -87,15 +79,10 @@ export function query<
|
|
|
87
79
|
TSuccess extends Schema.Top = Schema.Void,
|
|
88
80
|
const TSpecs extends RejectionSpecs = NoRejections,
|
|
89
81
|
R = never,
|
|
90
|
-
|
|
91
|
-
>(
|
|
92
|
-
name: TName,
|
|
93
|
-
declaration: QueryDeclaration<TPayload, TSuccess, TSpecs, R, TLive>,
|
|
94
|
-
): NoInfer<Query<TName, PayloadSchema<TPayload>, TSuccess, TSpecs, R, TLive>>;
|
|
82
|
+
>(name: TName, declaration: QueryDeclaration<TPayload, TSuccess, TSpecs, R>): NoInfer<Query<TName, PayloadSchema<TPayload>, TSuccess, TSpecs, R>>;
|
|
95
83
|
export function query(
|
|
96
84
|
name: string,
|
|
97
85
|
declaration: Loose & {
|
|
98
|
-
readonly live?: "rerun-and-compare" | undefined;
|
|
99
86
|
readonly reads: (payload: unknown, viewer: Option.Option<Viewer>) => readonly Key[];
|
|
100
87
|
readonly readPolicy: QueryReadPolicy<unknown, unknown, unknown>;
|
|
101
88
|
readonly readsCollections?: readonly { readonly name: string }[];
|
|
@@ -105,7 +92,6 @@ export function query(
|
|
|
105
92
|
const collections: readonly Key[] = declaration.readsCollections?.map((collection) => ({ _tag: "List", collection: collection.name })) ?? [];
|
|
106
93
|
return {
|
|
107
94
|
...operation("query", name, declaration),
|
|
108
|
-
live: declaration.live,
|
|
109
95
|
readPolicy: declaration.readPolicy,
|
|
110
96
|
reads: (payload, viewer) => [...declaration.reads(payload, viewer), ...collections],
|
|
111
97
|
readsCollections: declaration.readsCollections,
|
|
@@ -17,10 +17,8 @@ export type QueryDeclaration<
|
|
|
17
17
|
TSuccess extends Schema.Top,
|
|
18
18
|
TSpecs extends RejectionSpecs,
|
|
19
19
|
R,
|
|
20
|
-
TLive extends "rerun-and-compare" | undefined,
|
|
21
20
|
> = Declaration<TPayload, TSuccess, TSpecs> &
|
|
22
21
|
CollectionReads<PayloadSchema<TPayload>["Type"], NoInfer<RejectedBy<TSpecs>>, R> & {
|
|
23
|
-
readonly live?: TLive;
|
|
24
22
|
readonly reads: (payload: PayloadSchema<TPayload>["Type"], viewer: Option.Option<Viewer>) => readonly Key[];
|
|
25
23
|
readonly serverReads?: QueryServerReads<PayloadSchema<TPayload>["Type"], NoInfer<RejectedBy<TSpecs>>, R>;
|
|
26
24
|
};
|
package/src/queryDelivery.ts
CHANGED
|
@@ -3,51 +3,31 @@ import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
|
3
3
|
import * as Atom from "effect/reactivity/Atom";
|
|
4
4
|
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
5
5
|
import type { QuerySignals } from "#querySignals.ts";
|
|
6
|
-
import type { QueryUpdate,
|
|
6
|
+
import type { QueryUpdate, SubscriptionEvent } from "#queryUpdate.ts";
|
|
7
7
|
|
|
8
|
-
export function queryDelivery<A, E>(
|
|
9
|
-
atom: Atom.Atom<AsyncResult.AsyncResult<A, E>>,
|
|
10
|
-
decode: (value: unknown) => A,
|
|
11
|
-
compared: boolean,
|
|
12
|
-
paused: Atom.Atom<boolean>,
|
|
13
|
-
signals: Atom.Writable<QuerySignals>,
|
|
14
|
-
) {
|
|
15
|
-
const version = Atom.make(0);
|
|
8
|
+
export function queryDelivery<A, E>(decode: (value: unknown) => A, paused: Atom.Atom<boolean>, signals: Atom.Writable<QuerySignals>) {
|
|
16
9
|
const updates = Atom.make(0);
|
|
17
10
|
const pushed = Atom.make<AsyncResult.AsyncResult<A, E>>(AsyncResult.initial());
|
|
18
|
-
const deliver = Effect.fnUntraced(function* (update: QueryUpdate): Effect.fn.Return<
|
|
11
|
+
const deliver = Effect.fnUntraced(function* (update: QueryUpdate): Effect.fn.Return<SubscriptionEvent, never, AtomRegistry.AtomRegistry> {
|
|
19
12
|
const registry = yield* AtomRegistry.AtomRegistry;
|
|
20
13
|
registry.update(updates, (current) => current + 1);
|
|
21
14
|
if (update._tag === "Unchanged") {
|
|
22
15
|
if (!registry.get(paused)) {
|
|
23
16
|
registry.update(signals, (current) => ({ ...current, completed: current.completed + 1, pending: false }));
|
|
24
17
|
}
|
|
25
|
-
return { _tag: "
|
|
18
|
+
return { _tag: "Delivered" };
|
|
26
19
|
}
|
|
27
20
|
if (update._tag !== "Result") {
|
|
28
21
|
return update;
|
|
29
22
|
}
|
|
30
23
|
if (!registry.get(paused)) {
|
|
31
24
|
registry.set(pushed, AsyncResult.success(decode(update.value)));
|
|
32
|
-
registry.update(version, (current) => current + 1);
|
|
33
25
|
}
|
|
34
|
-
return { _tag: "
|
|
26
|
+
return { _tag: "Delivered" };
|
|
35
27
|
});
|
|
36
28
|
return {
|
|
37
|
-
atom:
|
|
38
|
-
? pushed
|
|
39
|
-
: Atom.readable(
|
|
40
|
-
(get) => {
|
|
41
|
-
const initial = get(pushed);
|
|
42
|
-
return AsyncResult.isInitial(initial) ? get(atom) : initial;
|
|
43
|
-
},
|
|
44
|
-
(refresh) => {
|
|
45
|
-
refresh(atom);
|
|
46
|
-
refresh(pushed);
|
|
47
|
-
},
|
|
48
|
-
),
|
|
29
|
+
atom: pushed,
|
|
49
30
|
stream: <TError, R>(stream: Stream.Stream<QueryUpdate, TError, R>) => Stream.mapEffect(stream, deliver),
|
|
50
31
|
updates,
|
|
51
|
-
version,
|
|
52
32
|
};
|
|
53
33
|
}
|
package/src/queryProgress.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
2
2
|
import type * as Atom from "effect/reactivity/Atom";
|
|
3
3
|
import type { LiveStatus } from "#live.ts";
|
|
4
|
-
import { queryCoalesceWindow } from "#queryCoalesceWindow.ts";
|
|
5
4
|
import { type QuerySignals, querySignals, shareQuerySignals } from "#querySignals.ts";
|
|
6
5
|
import { wrapAtom } from "./wrapAtom.ts";
|
|
7
6
|
|
|
@@ -9,8 +8,6 @@ export function queryProgress<A, E>(atom: Atom.Atom<AsyncResult.AsyncResult<A, E
|
|
|
9
8
|
const signals = querySignals(atom);
|
|
10
9
|
const tracked = wrapAtom(atom, (get) => {
|
|
11
10
|
get.mount(signals);
|
|
12
|
-
get.once(queryCoalesceWindow(tracked));
|
|
13
|
-
get.subscribe(queryCoalesceWindow(tracked), (duration) => get.set(queryCoalesceWindow(atom), duration), { immediate: true });
|
|
14
11
|
let published = false;
|
|
15
12
|
function publish(result: AsyncResult.AsyncResult<A, E>) {
|
|
16
13
|
published = true;
|
package/src/querySubscription.ts
CHANGED
|
@@ -12,7 +12,7 @@ export type QueryRerun<E = unknown, R = never> = (request: QueryRequest) => Effe
|
|
|
12
12
|
export interface QuerySubscription<E = never, R = never> {
|
|
13
13
|
readonly authorized: Effect.Effect<boolean, E, R>;
|
|
14
14
|
readonly keys: readonly Key[];
|
|
15
|
-
readonly queries
|
|
15
|
+
readonly queries: readonly QueryRequest[];
|
|
16
16
|
readonly readScopes?: Effect.Effect<readonly (readonly Key[])[], E, R>;
|
|
17
17
|
readonly refresh?: Effect.Effect<Context.Context<never>, E, R>;
|
|
18
18
|
readonly scopes: readonly (readonly Key[])[];
|
package/src/queryUpdate.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { QueryReadDenied } from "#readPolicyErrors.ts";
|
|
3
3
|
|
|
4
4
|
export interface QueryResult {
|
|
5
5
|
readonly _tag: "Result";
|
|
@@ -11,5 +11,11 @@ export interface QueryUnchanged {
|
|
|
11
11
|
readonly _tag: "Unchanged";
|
|
12
12
|
readonly queryIndex: number;
|
|
13
13
|
}
|
|
14
|
-
export type
|
|
15
|
-
export type QueryUpdate =
|
|
14
|
+
export type SubscriptionEvent = { readonly _tag: "Delivered" } | QueryReadDenied;
|
|
15
|
+
export type QueryUpdate = QueryReadDenied | QueryResult | QueryUnchanged;
|
|
16
|
+
|
|
17
|
+
export const QueryUpdate = Schema.Union([
|
|
18
|
+
Schema.Struct({ _tag: Schema.Literal("Result"), query: Schema.String, queryIndex: Schema.Number, value: Schema.Unknown }),
|
|
19
|
+
Schema.Struct({ _tag: Schema.Literal("Unchanged"), queryIndex: Schema.Number }),
|
|
20
|
+
QueryReadDenied,
|
|
21
|
+
]);
|
package/src/retainQuery.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { Option } from "effect";
|
|
|
2
2
|
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
3
3
|
import * as Atom from "effect/reactivity/Atom";
|
|
4
4
|
import { retainedQueries } from "#adapters/retainedQueries.ts";
|
|
5
|
-
import { queryCoalesceWindow } from "#queryCoalesceWindow.ts";
|
|
6
5
|
import { querySignals, shareQuerySignals } from "#querySignals.ts";
|
|
7
6
|
import { wrapAtom } from "#wrapAtom.ts";
|
|
8
7
|
|
|
@@ -13,8 +12,6 @@ export function retainQuery<A, E>(runtime: Atom.AtomRuntime<unknown, unknown>, a
|
|
|
13
12
|
get.mount(snapshot);
|
|
14
13
|
const owner = get.once(retainedQueries);
|
|
15
14
|
owner.take(retained);
|
|
16
|
-
get.once(queryCoalesceWindow(retained));
|
|
17
|
-
get.subscribe(queryCoalesceWindow(retained), (value) => get.set(queryCoalesceWindow(atom), value), { immediate: true });
|
|
18
15
|
get.addFinalizer(() => {
|
|
19
16
|
if (get.registry.getNodes().has(snapshot) && Option.isSome(get.registry.get(snapshot))) {
|
|
20
17
|
owner.keep(retained, snapshot, runtime);
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Duration } from "effect";
|
|
2
|
-
import type * as Reactivity from "effect/reactivity/Reactivity";
|
|
3
|
-
interface Batch {
|
|
4
|
-
readonly active: () => boolean;
|
|
5
|
-
readonly seen: Set<() => void>;
|
|
6
|
-
readonly window: Duration.Input | undefined;
|
|
7
|
-
}
|
|
8
|
-
export declare const liveBatches: WeakMap<Reactivity.Reactivity, Batch>;
|
|
9
|
-
export declare function liveKeys(keys: readonly string[]): string[];
|
|
10
|
-
export declare function invalidateLive(reactivity: Reactivity.Reactivity, keys: readonly string[], active: () => boolean, window?: Duration.Input): void;
|
|
11
|
-
export {};
|
|
12
|
-
//# sourceMappingURL=liveInvalidation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"liveInvalidation.d.ts","sourceRoot":"","sources":["../src/liveInvalidation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAEhE,UAAU,KAAK;IACd,QAAQ,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,GAAG,SAAS,CAAC;CAC5C;AACD,eAAO,MAAM,WAAW,uCAA8C,CAAC;AACvE,wBAAgB,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,YAE/C;AAED,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,OAAO,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,KAAK,QAOxI"}
|
package/dist/liveInvalidation.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export const liveBatches = new WeakMap();
|
|
2
|
-
export function liveKeys(keys) {
|
|
3
|
-
return keys.map((key) => `@shivaedev/live:${key}`);
|
|
4
|
-
}
|
|
5
|
-
export function invalidateLive(reactivity, keys, active, window) {
|
|
6
|
-
liveBatches.set(reactivity, { active, seen: new Set(), window });
|
|
7
|
-
try {
|
|
8
|
-
reactivity.invalidateUnsafe(window === undefined ? keys : liveKeys(keys));
|
|
9
|
-
}
|
|
10
|
-
finally {
|
|
11
|
-
liveBatches.delete(reactivity);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=liveInvalidation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"liveInvalidation.js","sourceRoot":"","sources":["../src/liveInvalidation.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,OAAO,EAAgC,CAAC;AACvE,MAAM,UAAU,QAAQ,CAAC,IAAuB;IAC/C,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,mBAAmB,GAAG,EAAE,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,UAAiC,EAAE,IAAuB,EAAE,MAAqB,EAAE,MAAuB;IACxI,WAAW,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IACjE,IAAI,CAAC;QACJ,UAAU,CAAC,gBAAgB,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3E,CAAC;YAAS,CAAC;QACV,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAChC,CAAC;AACF,CAAC"}
|
package/dist/livePending.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Duration } from "effect";
|
|
2
|
-
export declare function livePending(start: (window: Duration.Input) => void, stop: () => void): {
|
|
3
|
-
add(keys: readonly string[], window: Duration.Input): void;
|
|
4
|
-
clear(): void;
|
|
5
|
-
take(): string[];
|
|
6
|
-
};
|
|
7
|
-
//# sourceMappingURL=livePending.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"livePending.d.ts","sourceRoot":"","sources":["../src/livePending.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAEvC,wBAAgB,WAAW,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,KAAK,IAAI,EAAE,IAAI,EAAE,MAAM,IAAI;IAInF,GAAG,OAAO,SAAS,MAAM,EAAE,UAAU,QAAQ,CAAC,KAAK;IASnD,KAAK;IAKL,IAAI;EAOL"}
|
package/dist/livePending.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export function livePending(start, stop) {
|
|
2
|
-
const pending = new Set();
|
|
3
|
-
let scheduled = false;
|
|
4
|
-
return {
|
|
5
|
-
add(keys, window) {
|
|
6
|
-
for (const key of keys) {
|
|
7
|
-
pending.add(key);
|
|
8
|
-
}
|
|
9
|
-
if (!scheduled) {
|
|
10
|
-
scheduled = true;
|
|
11
|
-
start(window);
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
clear() {
|
|
15
|
-
stop();
|
|
16
|
-
scheduled = false;
|
|
17
|
-
pending.clear();
|
|
18
|
-
},
|
|
19
|
-
take() {
|
|
20
|
-
const queued = [...pending];
|
|
21
|
-
scheduled = false;
|
|
22
|
-
pending.clear();
|
|
23
|
-
return queued;
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=livePending.js.map
|
package/dist/livePending.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"livePending.js","sourceRoot":"","sources":["../src/livePending.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,WAAW,CAAC,KAAuC,EAAE,IAAgB;IACpF,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,IAAI,SAAS,GAAG,KAAK,CAAC;IACtB,OAAO;QACN,GAAG,CAAC,IAAuB,EAAE,MAAsB;YAClD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;gBACxB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAClB,CAAC;YACD,IAAI,CAAC,SAAS,EAAE,CAAC;gBAChB,SAAS,GAAG,IAAI,CAAC;gBACjB,KAAK,CAAC,MAAM,CAAC,CAAC;YACf,CAAC;QACF,CAAC;QACD,KAAK;YACJ,IAAI,EAAE,CAAC;YACP,SAAS,GAAG,KAAK,CAAC;YAClB,OAAO,CAAC,KAAK,EAAE,CAAC;QACjB,CAAC;QACD,IAAI;YACH,MAAM,MAAM,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC;YAC5B,SAAS,GAAG,KAAK,CAAC;YAClB,OAAO,CAAC,KAAK,EAAE,CAAC;YAChB,OAAO,MAAM,CAAC;QACf,CAAC;KACD,CAAC;AACH,CAAC"}
|