@shivaedev/contract 0.42.0 → 0.43.1
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 +17 -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/bindingOwner.d.ts.map +1 -1
- package/dist/adapters/bindingOwner.js +1 -1
- package/dist/adapters/bindingOwner.js.map +1 -1
- package/dist/adapters/liveHintStream.d.ts +1 -2
- package/dist/adapters/liveHintStream.d.ts.map +1 -1
- package/dist/adapters/liveHintStream.js +2 -2
- package/dist/adapters/liveHintStream.js.map +1 -1
- package/dist/adapters/openLiveHints.d.ts +1 -2
- package/dist/adapters/openLiveHints.d.ts.map +1 -1
- package/dist/adapters/openLiveHints.js +1 -1
- package/dist/adapters/openLiveHints.js.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 +1 -5
- 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/connectionProtocol.d.ts +1 -1
- package/dist/connectionProtocol.d.ts.map +1 -1
- package/dist/connectionProtocol.js +1 -1
- package/dist/connectionProtocol.js.map +1 -1
- package/dist/live-server/layer.js +1 -1
- package/dist/live-server/layer.js.map +1 -1
- package/dist/live-server/register.d.ts +1 -2
- package/dist/live-server/register.d.ts.map +1 -1
- package/dist/live-server/resync.d.ts +1 -1
- package/dist/live-server/resync.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/service.js +4 -4
- package/dist/live-server/service.js.map +1 -1
- package/dist/live-server/stream.d.ts +1 -2
- 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 +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 +1 -4
- 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/dist/rpcClient.d.ts.map +1 -1
- package/dist/rpcClient.js +4 -4
- package/dist/rpcClient.js.map +1 -1
- package/dist/socketProtocol.js +1 -1
- package/dist/socketProtocol.js.map +1 -1
- package/package.json +15 -15
- package/src/AutomaticQueryOptions.ts +0 -5
- package/src/adapters/activityState.ts +0 -1
- package/src/adapters/bindingOwner.ts +1 -1
- package/src/adapters/liveHintStream.ts +2 -2
- package/src/adapters/openLiveHints.ts +1 -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 +2 -6
- package/src/clientActivity.ts +1 -2
- package/src/clientOperations.ts +1 -4
- package/src/compareQueries.ts +12 -38
- package/src/connectionProtocol.ts +1 -1
- package/src/live-server/layer.ts +1 -1
- package/src/live-server/register.ts +1 -1
- package/src/live-server/resync.ts +1 -1
- package/src/live-server/service.ts +4 -4
- package/src/live-server/stream.ts +1 -1
- package/src/live-server/subscribe.ts +6 -10
- 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 +1 -4
- package/src/querySubscription.ts +1 -1
- package/src/queryUpdate.ts +10 -4
- package/src/retainQuery.ts +0 -3
- package/src/rpcClient.ts +4 -4
- package/src/socketProtocol.ts +1 -1
- 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/dist/queryHints.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"queryHints.d.ts","sourceRoot":"","sources":["../src/queryHints.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,GAAG,EAAY,MAAM,4BAA4B,CAAC;AAClF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,SAElD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,SAAS;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,CAAA;CAAE,EAAE,GAAG,gBAAgB,CAmBzH;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,SAAS,GAAG,EAAE,CAAC,EAAE,GAAG,QAAQ,CAShG"}
|
package/dist/queryHints.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { invalidationKeys, readKeys } from "@shivaedev/changes/keys.ts";
|
|
2
|
-
export function localQueryKeys(keys) {
|
|
3
|
-
return keys.filter((key) => key.collection.startsWith("@query/"));
|
|
4
|
-
}
|
|
5
|
-
export function queryHint(hint, tracked) {
|
|
6
|
-
if (hint._tag !== "Changed") {
|
|
7
|
-
return hint;
|
|
8
|
-
}
|
|
9
|
-
const invalidated = invalidationKeys(hint.keys);
|
|
10
|
-
return {
|
|
11
|
-
...hint,
|
|
12
|
-
keys: [
|
|
13
|
-
...hint.keys,
|
|
14
|
-
...tracked.flatMap(({ keys }, index) => {
|
|
15
|
-
const local = keys.filter((key) => !key.collection.startsWith("@query/"));
|
|
16
|
-
const affected = hint.queryIndexes === undefined
|
|
17
|
-
? local.length === 0 || hint.keys.some((key) => key._tag === "Bucket") || readKeys(local).some((key) => invalidated.includes(key))
|
|
18
|
-
: hint.queryIndexes.includes(index);
|
|
19
|
-
return affected ? localQueryKeys(keys) : [];
|
|
20
|
-
}),
|
|
21
|
-
],
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
export function changedHint(keys, scopes) {
|
|
25
|
-
const changed = new Set(keys.map((key) => JSON.stringify(key)));
|
|
26
|
-
return {
|
|
27
|
-
_tag: "Changed",
|
|
28
|
-
keys,
|
|
29
|
-
...(scopes === undefined
|
|
30
|
-
? {}
|
|
31
|
-
: { queryIndexes: scopes.flatMap((scope, index) => (scope.some((key) => changed.has(JSON.stringify(key))) ? [index] : [])) }),
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=queryHints.js.map
|
package/dist/queryHints.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"queryHints.js","sourceRoot":"","sources":["../src/queryHints.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAY,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAIlF,MAAM,UAAU,cAAc,CAAC,IAAoB;IAClD,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;AACnE,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,IAAsB,EAAE,OAAqD;IACtG,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACb,CAAC;IACD,MAAM,WAAW,GAAG,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChD,OAAO;QACN,GAAG,IAAI;QACP,IAAI,EAAE;YACL,GAAG,IAAI,CAAC,IAAI;YACZ,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE;gBACtC,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC,CAA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@@
|
|
|
1
|
-
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
2
|
-
import * as Atom from "effect/reactivity/Atom";
|
|
3
|
-
import type * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
4
|
-
export declare function queryReactivity<R, E>(runtime: Atom.AtomRuntime<R, E>, queue?: () => () => void): (atom: Atom.Atom<AsyncResult.AsyncResult<unknown, unknown>>, keys: readonly string[], owner?: AtomRegistry.AtomRegistry) => Atom.Atom<AsyncResult.AsyncResult<unknown, unknown>>;
|
|
5
|
-
//# sourceMappingURL=queryReactivity.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"queryReactivity.d.ts","sourceRoot":"","sources":["../src/queryReactivity.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAC7D,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,KAAK,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAMpE,wBAAgB,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,MAAM,IAAI,sEAInE,SAAS,MAAM,EAAE,UAAU,YAAY,CAAC,YAAY,0DAiH/E"}
|
package/dist/queryReactivity.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { Cause, Duration, Effect, Option, Predicate } from "effect";
|
|
2
|
-
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
3
|
-
import * as Atom from "effect/reactivity/Atom";
|
|
4
|
-
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
5
|
-
import { queryCoalesceWindow } from "#queryCoalesceWindow.ts";
|
|
6
|
-
import { liveBatches, liveKeys } from "./liveInvalidation.js";
|
|
7
|
-
import { wrapAtom } from "./wrapAtom.js";
|
|
8
|
-
export function queryReactivity(runtime, queue) {
|
|
9
|
-
const service = runtime.atom(Effect.service(Reactivity.Reactivity));
|
|
10
|
-
const cached = new WeakMap();
|
|
11
|
-
return (atom, keys, owner) => {
|
|
12
|
-
const existing = cached.get(atom);
|
|
13
|
-
if (existing !== undefined) {
|
|
14
|
-
return existing;
|
|
15
|
-
}
|
|
16
|
-
const source = Atom.setIdleTTL(Atom.readable((get) => atom.read(get), atom.refresh), 0);
|
|
17
|
-
const wrapped = wrapAtom(atom, (get) => {
|
|
18
|
-
if (owner !== undefined && owner !== get.registry) {
|
|
19
|
-
throw new Error("A session-scoped query belongs to its binding registry");
|
|
20
|
-
}
|
|
21
|
-
const context = get(service);
|
|
22
|
-
if (!AsyncResult.isSuccess(context)) {
|
|
23
|
-
return get(source);
|
|
24
|
-
}
|
|
25
|
-
const reactivity = context.value;
|
|
26
|
-
let pending;
|
|
27
|
-
let queued;
|
|
28
|
-
function dequeue() {
|
|
29
|
-
if (!scheduled && pending === undefined) {
|
|
30
|
-
queued?.();
|
|
31
|
-
queued = undefined;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
let scheduled = false;
|
|
35
|
-
const timer = runtime.fn(({ delay, active }) => Effect.andThen(Effect.sleep(delay), Effect.sync(() => {
|
|
36
|
-
scheduled = false;
|
|
37
|
-
refresh(active);
|
|
38
|
-
})));
|
|
39
|
-
get.mount(timer);
|
|
40
|
-
function clear() {
|
|
41
|
-
get.set(timer, Atom.Interrupt);
|
|
42
|
-
scheduled = false;
|
|
43
|
-
pending = undefined;
|
|
44
|
-
dequeue();
|
|
45
|
-
}
|
|
46
|
-
function reread() {
|
|
47
|
-
if (!Option.exists(AsyncResult.cause(get.once(source)), (cause) => Option.exists(Cause.findErrorOption(cause), Predicate.isTagged("QueryReadDenied")))) {
|
|
48
|
-
get.refresh(source);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
function refresh(active) {
|
|
52
|
-
if (!active()) {
|
|
53
|
-
dequeue();
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
if (get.once(source).waiting) {
|
|
57
|
-
pending = active;
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
pending = undefined;
|
|
61
|
-
reread();
|
|
62
|
-
dequeue();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
function changed() {
|
|
66
|
-
const batch = liveBatches.get(reactivity);
|
|
67
|
-
if (batch === undefined || batch.seen.has(changed)) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
batch.seen.add(changed);
|
|
71
|
-
const delay = Duration.toMillis(Duration.fromInputUnsafe(get.once(queryCoalesceWindow(wrapped)) ?? batch.window ?? 0));
|
|
72
|
-
if (delay === 0) {
|
|
73
|
-
clear();
|
|
74
|
-
reread();
|
|
75
|
-
}
|
|
76
|
-
else if (!scheduled) {
|
|
77
|
-
queued ??= queue?.();
|
|
78
|
-
scheduled = true;
|
|
79
|
-
get.set(timer, { active: batch.active, delay });
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
get.addFinalizer(clear);
|
|
83
|
-
get.addFinalizer(reactivity.registerUnsafe(liveKeys(keys), changed));
|
|
84
|
-
get.addFinalizer(reactivity.registerUnsafe(keys, () => {
|
|
85
|
-
if (!liveBatches.has(reactivity)) {
|
|
86
|
-
clear();
|
|
87
|
-
reread();
|
|
88
|
-
}
|
|
89
|
-
}));
|
|
90
|
-
get.subscribe(source, (value) => {
|
|
91
|
-
get.setSelf(value);
|
|
92
|
-
if (pending !== undefined && !value.waiting) {
|
|
93
|
-
const active = pending;
|
|
94
|
-
pending = undefined;
|
|
95
|
-
if (active()) {
|
|
96
|
-
get.set(timer, Atom.Interrupt);
|
|
97
|
-
scheduled = false;
|
|
98
|
-
reread();
|
|
99
|
-
}
|
|
100
|
-
dequeue();
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
return get.once(source);
|
|
104
|
-
}, source);
|
|
105
|
-
cached.set(atom, wrapped);
|
|
106
|
-
return wrapped;
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109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AAO,CAAC,CAAC;QAC1B,OAAO,OAAO,CAAC;IAChB,CAAC,CAAC;AACH,CAAC"}
|
package/src/liveInvalidation.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Duration } from "effect";
|
|
2
|
-
import type * as Reactivity from "effect/reactivity/Reactivity";
|
|
3
|
-
|
|
4
|
-
interface Batch {
|
|
5
|
-
readonly active: () => boolean;
|
|
6
|
-
readonly seen: Set<() => void>;
|
|
7
|
-
readonly window: Duration.Input | undefined;
|
|
8
|
-
}
|
|
9
|
-
export const liveBatches = new WeakMap<Reactivity.Reactivity, Batch>();
|
|
10
|
-
export function liveKeys(keys: readonly string[]) {
|
|
11
|
-
return keys.map((key) => `@shivaedev/live:${key}`);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function invalidateLive(reactivity: Reactivity.Reactivity, keys: readonly string[], active: () => boolean, window?: Duration.Input) {
|
|
15
|
-
liveBatches.set(reactivity, { active, seen: new Set(), window });
|
|
16
|
-
try {
|
|
17
|
-
reactivity.invalidateUnsafe(window === undefined ? keys : liveKeys(keys));
|
|
18
|
-
} finally {
|
|
19
|
-
liveBatches.delete(reactivity);
|
|
20
|
-
}
|
|
21
|
-
}
|
package/src/livePending.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { Duration } from "effect";
|
|
2
|
-
|
|
3
|
-
export function livePending(start: (window: Duration.Input) => void, stop: () => void) {
|
|
4
|
-
const pending = new Set<string>();
|
|
5
|
-
let scheduled = false;
|
|
6
|
-
return {
|
|
7
|
-
add(keys: readonly string[], window: Duration.Input) {
|
|
8
|
-
for (const key of keys) {
|
|
9
|
-
pending.add(key);
|
|
10
|
-
}
|
|
11
|
-
if (!scheduled) {
|
|
12
|
-
scheduled = true;
|
|
13
|
-
start(window);
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
clear() {
|
|
17
|
-
stop();
|
|
18
|
-
scheduled = false;
|
|
19
|
-
pending.clear();
|
|
20
|
-
},
|
|
21
|
-
take() {
|
|
22
|
-
const queued = [...pending];
|
|
23
|
-
scheduled = false;
|
|
24
|
-
pending.clear();
|
|
25
|
-
return queued;
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Duration } from "effect";
|
|
2
|
-
import * as Atom from "effect/reactivity/Atom";
|
|
3
|
-
|
|
4
|
-
const windows = new WeakMap<Atom.Atom<unknown>, Atom.Writable<Duration.Input | undefined>>();
|
|
5
|
-
|
|
6
|
-
export function queryCoalesceWindow<A>(query: Atom.Atom<A>): Atom.Writable<Duration.Input | undefined> {
|
|
7
|
-
let window = windows.get(query);
|
|
8
|
-
if (window === undefined) {
|
|
9
|
-
window = Atom.keepAlive(Atom.make<Duration.Input | undefined>(undefined));
|
|
10
|
-
windows.set(query, window);
|
|
11
|
-
}
|
|
12
|
-
return window;
|
|
13
|
-
}
|
package/src/queryFailure.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { type Cause, Option } from "effect";
|
|
2
|
-
import type { LiveStatus } from "#live.ts";
|
|
3
|
-
|
|
4
|
-
export function queryFailure(started: () => boolean, publish: (cause: Cause.Cause<unknown>) => void) {
|
|
5
|
-
return ({ connection, failure }: LiveStatus<unknown>) => {
|
|
6
|
-
if (Option.isNone(failure)) {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (!started() || connection === "failed") {
|
|
10
|
-
publish(failure.value);
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
}
|
package/src/queryHints.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { invalidationKeys, type Key, readKeys } from "@shivaedev/changes/keys.ts";
|
|
2
|
-
import type { LiveHint } from "#live.ts";
|
|
3
|
-
import type { SubscriptionHint } from "#queryUpdate.ts";
|
|
4
|
-
|
|
5
|
-
export function localQueryKeys(keys: readonly Key[]) {
|
|
6
|
-
return keys.filter((key) => key.collection.startsWith("@query/"));
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function queryHint(hint: SubscriptionHint, tracked: readonly { readonly keys: readonly Key[] }[]): SubscriptionHint {
|
|
10
|
-
if (hint._tag !== "Changed") {
|
|
11
|
-
return hint;
|
|
12
|
-
}
|
|
13
|
-
const invalidated = invalidationKeys(hint.keys);
|
|
14
|
-
return {
|
|
15
|
-
...hint,
|
|
16
|
-
keys: [
|
|
17
|
-
...hint.keys,
|
|
18
|
-
...tracked.flatMap(({ keys }, index) => {
|
|
19
|
-
const local = keys.filter((key) => !key.collection.startsWith("@query/"));
|
|
20
|
-
const affected =
|
|
21
|
-
hint.queryIndexes === undefined
|
|
22
|
-
? local.length === 0 || hint.keys.some((key) => key._tag === "Bucket") || readKeys(local).some((key) => invalidated.includes(key))
|
|
23
|
-
: hint.queryIndexes.includes(index);
|
|
24
|
-
return affected ? localQueryKeys(keys) : [];
|
|
25
|
-
}),
|
|
26
|
-
],
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function changedHint(keys: readonly Key[], scopes?: readonly (readonly Key[])[]): LiveHint {
|
|
31
|
-
const changed = new Set(keys.map((key) => JSON.stringify(key)));
|
|
32
|
-
return {
|
|
33
|
-
_tag: "Changed",
|
|
34
|
-
keys,
|
|
35
|
-
...(scopes === undefined
|
|
36
|
-
? {}
|
|
37
|
-
: { queryIndexes: scopes.flatMap((scope, index) => (scope.some((key) => changed.has(JSON.stringify(key))) ? [index] : [])) }),
|
|
38
|
-
};
|
|
39
|
-
}
|
package/src/queryReactivity.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { Cause, Duration, Effect, Option, Predicate } from "effect";
|
|
2
|
-
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
3
|
-
import * as Atom from "effect/reactivity/Atom";
|
|
4
|
-
import type * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
5
|
-
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
6
|
-
import { queryCoalesceWindow } from "#queryCoalesceWindow.ts";
|
|
7
|
-
import { liveBatches, liveKeys } from "./liveInvalidation.ts";
|
|
8
|
-
import { wrapAtom } from "./wrapAtom.ts";
|
|
9
|
-
|
|
10
|
-
export function queryReactivity<R, E>(runtime: Atom.AtomRuntime<R, E>, queue?: () => () => void) {
|
|
11
|
-
const service = runtime.atom(Effect.service(Reactivity.Reactivity));
|
|
12
|
-
type Query = Atom.Atom<AsyncResult.AsyncResult<unknown, unknown>>;
|
|
13
|
-
const cached = new WeakMap<Query, Query>();
|
|
14
|
-
return (atom: Query, keys: readonly string[], owner?: AtomRegistry.AtomRegistry): Query => {
|
|
15
|
-
const existing = cached.get(atom);
|
|
16
|
-
if (existing !== undefined) {
|
|
17
|
-
return existing;
|
|
18
|
-
}
|
|
19
|
-
const source = Atom.setIdleTTL(
|
|
20
|
-
Atom.readable((get) => atom.read(get), atom.refresh),
|
|
21
|
-
0,
|
|
22
|
-
);
|
|
23
|
-
const wrapped = wrapAtom(
|
|
24
|
-
atom,
|
|
25
|
-
(get) => {
|
|
26
|
-
if (owner !== undefined && owner !== get.registry) {
|
|
27
|
-
throw new Error("A session-scoped query belongs to its binding registry");
|
|
28
|
-
}
|
|
29
|
-
const context = get(service);
|
|
30
|
-
if (!AsyncResult.isSuccess(context)) {
|
|
31
|
-
return get(source);
|
|
32
|
-
}
|
|
33
|
-
const reactivity = context.value;
|
|
34
|
-
let pending: (() => boolean) | undefined;
|
|
35
|
-
let queued: (() => void) | undefined;
|
|
36
|
-
function dequeue() {
|
|
37
|
-
if (!scheduled && pending === undefined) {
|
|
38
|
-
queued?.();
|
|
39
|
-
queued = undefined;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
let scheduled = false;
|
|
43
|
-
const timer = runtime.fn(({ delay, active }: { readonly delay: number; readonly active: () => boolean }) =>
|
|
44
|
-
Effect.andThen(
|
|
45
|
-
Effect.sleep(delay),
|
|
46
|
-
Effect.sync(() => {
|
|
47
|
-
scheduled = false;
|
|
48
|
-
refresh(active);
|
|
49
|
-
}),
|
|
50
|
-
),
|
|
51
|
-
);
|
|
52
|
-
get.mount(timer);
|
|
53
|
-
function clear() {
|
|
54
|
-
get.set(timer, Atom.Interrupt);
|
|
55
|
-
scheduled = false;
|
|
56
|
-
pending = undefined;
|
|
57
|
-
dequeue();
|
|
58
|
-
}
|
|
59
|
-
function reread() {
|
|
60
|
-
if (
|
|
61
|
-
!Option.exists(AsyncResult.cause(get.once(source)), (cause) =>
|
|
62
|
-
Option.exists(Cause.findErrorOption(cause), Predicate.isTagged("QueryReadDenied")),
|
|
63
|
-
)
|
|
64
|
-
) {
|
|
65
|
-
get.refresh(source);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
function refresh(active: () => boolean) {
|
|
69
|
-
if (!active()) {
|
|
70
|
-
dequeue();
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
if (get.once(source).waiting) {
|
|
74
|
-
pending = active;
|
|
75
|
-
} else {
|
|
76
|
-
pending = undefined;
|
|
77
|
-
reread();
|
|
78
|
-
dequeue();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function changed() {
|
|
82
|
-
const batch = liveBatches.get(reactivity);
|
|
83
|
-
if (batch === undefined || batch.seen.has(changed)) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
batch.seen.add(changed);
|
|
87
|
-
const delay = Duration.toMillis(Duration.fromInputUnsafe(get.once(queryCoalesceWindow(wrapped)) ?? batch.window ?? 0));
|
|
88
|
-
if (delay === 0) {
|
|
89
|
-
clear();
|
|
90
|
-
reread();
|
|
91
|
-
} else if (!scheduled) {
|
|
92
|
-
queued ??= queue?.();
|
|
93
|
-
scheduled = true;
|
|
94
|
-
get.set(timer, { active: batch.active, delay });
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
get.addFinalizer(clear);
|
|
98
|
-
get.addFinalizer(reactivity.registerUnsafe(liveKeys(keys), changed));
|
|
99
|
-
get.addFinalizer(
|
|
100
|
-
reactivity.registerUnsafe(keys, () => {
|
|
101
|
-
if (!liveBatches.has(reactivity)) {
|
|
102
|
-
clear();
|
|
103
|
-
reread();
|
|
104
|
-
}
|
|
105
|
-
}),
|
|
106
|
-
);
|
|
107
|
-
get.subscribe(source, (value) => {
|
|
108
|
-
get.setSelf(value);
|
|
109
|
-
if (pending !== undefined && !value.waiting) {
|
|
110
|
-
const active = pending;
|
|
111
|
-
pending = undefined;
|
|
112
|
-
if (active()) {
|
|
113
|
-
get.set(timer, Atom.Interrupt);
|
|
114
|
-
scheduled = false;
|
|
115
|
-
reread();
|
|
116
|
-
}
|
|
117
|
-
dequeue();
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
return get.once(source);
|
|
121
|
-
},
|
|
122
|
-
source,
|
|
123
|
-
);
|
|
124
|
-
cached.set(atom, wrapped);
|
|
125
|
-
return wrapped;
|
|
126
|
-
};
|
|
127
|
-
}
|