j-templates 9.0.1 → 10.0.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/SYNTAX_PRIMER.md +181 -101
- package/Store/Diff/channelClient.d.ts +104 -0
- package/Store/Diff/channelClient.js +225 -0
- package/Store/Diff/defaultDiffTreeWorker.js +3 -4
- package/Store/Diff/diffTree.d.ts +56 -0
- package/Store/Diff/diffTree.js +110 -4
- package/Store/Diff/diffTree.types.d.ts +186 -21
- package/Store/Diff/diffTree.types.js +2 -10
- package/Store/Diff/diffTreeEndpoint.d.ts +101 -0
- package/Store/Diff/diffTreeEndpoint.js +173 -0
- package/Store/Diff/diffTreeEndpoint.types.d.ts +71 -0
- package/Store/Diff/diffTreeEndpoint.types.js +1 -0
- package/Store/Diff/diffTreeHub.d.ts +139 -0
- package/Store/Diff/diffTreeHub.js +346 -0
- package/Store/Diff/hostPublisher.d.ts +38 -0
- package/Store/Diff/hostPublisher.js +147 -0
- package/Store/Diff/index.d.ts +3 -0
- package/Store/Diff/index.js +3 -0
- package/Store/Diff/observableDiffTree.d.ts +93 -0
- package/Store/Diff/observableDiffTree.js +200 -0
- package/Store/Diff/onConnect.d.ts +33 -0
- package/Store/Diff/onConnect.js +83 -0
- package/Store/Diff/utils/diffTree.types.d.ts +9 -0
- package/Store/Diff/utils/homes.d.ts +12 -0
- package/Store/Diff/utils/homes.js +40 -0
- package/Store/Diff/utils/paths.d.ts +2 -1
- package/Store/Diff/utils/paths.js +3 -2
- package/Store/Diff/utils/routes.d.ts +18 -0
- package/Store/Diff/utils/routes.js +33 -2
- package/Store/Diff/utils/state.js +4 -3
- package/Store/Store/store.d.ts +41 -4
- package/Store/Store/store.js +62 -7
- package/Store/Store/storeAsync.d.ts +134 -25
- package/Store/Store/storeAsync.js +235 -33
- package/Store/Store/storeSync.d.ts +91 -11
- package/Store/Store/storeSync.js +107 -12
- package/Store/Tree/observableNode.d.ts +3 -0
- package/Store/Tree/observableNode.js +87 -13
- package/Store/Tree/observableScope.d.ts +3 -1
- package/Store/Tree/observableScope.js +12 -0
- package/Store/Tree/opaque.d.ts +30 -0
- package/Store/Tree/opaque.js +35 -0
- package/Store/Tree/snapshot.js +5 -4
- package/Store/index.d.ts +4 -1
- package/Store/index.js +1 -1
- package/Utils/decorators.d.ts +0 -98
- package/Utils/decorators.js +0 -156
- package/Utils/emitter.d.ts +11 -4
- package/Utils/emitter.js +25 -2
- package/Utils/index.d.ts +2 -0
- package/Utils/index.js +1 -0
- package/Utils/pattern.d.ts +14 -0
- package/Utils/pattern.js +20 -0
- package/Utils/subscriptionManager.d.ts +78 -0
- package/Utils/subscriptionManager.js +159 -0
- package/package.json +1 -1
- package/Store/Diff/diffTreeWorker.d.ts +0 -6
- package/Store/Diff/diffTreeWorker.js +0 -22
- package/Store/Diff/diffTreeWriter.d.ts +0 -92
- package/Store/Diff/diffTreeWriter.js +0 -137
- package/Store/Diff/workerQueue.d.ts +0 -7
- package/Store/Diff/workerQueue.js +0 -29
- package/Store/Store/pushStore.d.ts +0 -53
- package/Store/Store/pushStore.js +0 -77
package/Store/Store/store.d.ts
CHANGED
|
@@ -1,22 +1,50 @@
|
|
|
1
1
|
import { JsonDiffResult } from "../../Utils/json";
|
|
2
|
+
import type { IKeyFunc } from "../Diff/utils/diffTree.types";
|
|
3
|
+
import { EmitterEvent } from "../../Utils/emitter";
|
|
4
|
+
/** Options shared by `StoreSync` and `StoreAsync` */
|
|
5
|
+
export interface IStoreOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Gives a value its key, so the store resolves an object written with an id to its own root. For a
|
|
8
|
+
* store whose tree has none to give: a `StoreAsync` over a plain channel (pass the worker tree's
|
|
9
|
+
* key logic), or a `StoreSync` with a tree of its own. A lease's keyFunc is the endpoint's, and a
|
|
10
|
+
* tree's its own; giving one there too throws.
|
|
11
|
+
*/
|
|
12
|
+
keyFunc?: IKeyFunc;
|
|
13
|
+
/**
|
|
14
|
+
* Root keys the store holds whole, as an `Opaque`: a written root or a projection's
|
|
15
|
+
* `$projection_<key>`. `Get` returns such a root's raw value, never proxied, the same reference
|
|
16
|
+
* until the root is written again, and only that write updates its readers. Treat the value as
|
|
17
|
+
* read-only: a change made inside it notifies no one. An opaque root can't be read through a
|
|
18
|
+
* key (`keyFunc`). Its tree must write each one whole instead of diffing inside it
|
|
19
|
+
* (`DiffTree.MarkOpaque`): a store with a tree of its own marks it; any other tree, a hub's or a
|
|
20
|
+
* worker's, takes the same keys in its config (`IObservableDiffTreeConfig.opaque`), from a file
|
|
21
|
+
* both import. A store never marks a tree: opaque is local. Write the raw
|
|
22
|
+
* value: the store boxes it, and an `Opaque` written to a store isn't opened.
|
|
23
|
+
*/
|
|
24
|
+
opaque?: readonly string[];
|
|
25
|
+
}
|
|
2
26
|
/**
|
|
3
27
|
* Base class for reading observable data: holds root objects as ObservableNode instances
|
|
4
|
-
* and applies diff results to them. Subclasses decide where the diffs come from: `
|
|
5
|
-
*
|
|
28
|
+
* and applies diff results to them. Subclasses decide where the diffs come from: `StoreSync`
|
|
29
|
+
* and `StoreAsync` apply what an `ObservableDiffTree` delivers to them.
|
|
6
30
|
*
|
|
7
31
|
* @see Store
|
|
8
|
-
* @see PushStore
|
|
9
32
|
*/
|
|
10
33
|
export declare abstract class ReadStore {
|
|
11
34
|
protected keyFunc?: (value: any) => string | undefined;
|
|
12
35
|
private rootMap;
|
|
13
36
|
private createNode;
|
|
37
|
+
/** Root keys held whole, see `IStoreOptions.opaque` */
|
|
38
|
+
protected readonly opaque: ReadonlySet<string | number>;
|
|
39
|
+
protected readonly watch: readonly string[];
|
|
40
|
+
protected readonly watchCallback?: (rootProperty: string, event: EmitterEvent) => void;
|
|
14
41
|
/**
|
|
15
42
|
* Creates an instance of ReadStore.
|
|
16
43
|
* @param keyFunc Optional function to generate a key for a given data value.
|
|
17
44
|
* When provided, enables alias functionality where values can reference other root objects.
|
|
45
|
+
* @param opaque Root keys held whole, see `IStoreOptions.opaque`.
|
|
18
46
|
*/
|
|
19
|
-
constructor(keyFunc?: (value: any) => string | undefined);
|
|
47
|
+
constructor(keyFunc?: (value: any) => string | undefined, opaque?: readonly string[], watch?: readonly string[], watchCallback?: (rootKey: string, event: EmitterEvent) => void);
|
|
20
48
|
/**
|
|
21
49
|
* Retrieves a value from the store by id.
|
|
22
50
|
* @template O - The type of the value to retrieve
|
|
@@ -45,6 +73,14 @@ export declare abstract class ReadStore {
|
|
|
45
73
|
* @protected
|
|
46
74
|
*/
|
|
47
75
|
protected UpdateRootMap(results: JsonDiffResult): void;
|
|
76
|
+
/**
|
|
77
|
+
* Applies whole-root writes by diffing each one into the root the store already holds, so
|
|
78
|
+
* readers of an unchanged part aren't notified and keep its objects. Anything else, an opaque
|
|
79
|
+
* root, or a root the store doesn't hold, is applied as it is.
|
|
80
|
+
* @param results - Diff results, e.g. a tree's first state after reconnecting
|
|
81
|
+
* @protected
|
|
82
|
+
*/
|
|
83
|
+
protected UpdateRootMapInPlace(results: JsonDiffResult): void;
|
|
48
84
|
/**
|
|
49
85
|
* Updates a specific root object with diff results.
|
|
50
86
|
* Creates the root object if it doesn't exist.
|
|
@@ -54,6 +90,7 @@ export declare abstract class ReadStore {
|
|
|
54
90
|
* @private
|
|
55
91
|
*/
|
|
56
92
|
private UpdateRootObject;
|
|
93
|
+
private CreateRootNode;
|
|
57
94
|
}
|
|
58
95
|
/**
|
|
59
96
|
* Base class for observable data store management.
|
package/Store/Store/store.js
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
|
-
import { JsonDeepClone } from "../../Utils/json";
|
|
1
|
+
import { JsonDeepClone, JsonDiff, JsonType } from "../../Utils/json";
|
|
2
2
|
import { ObservableNode } from "../Tree/observableNode";
|
|
3
|
+
import { Opaque } from "../Tree/opaque";
|
|
4
|
+
import { PatternMatches } from "../../Utils/pattern";
|
|
3
5
|
/**
|
|
4
6
|
* Base class for reading observable data: holds root objects as ObservableNode instances
|
|
5
|
-
* and applies diff results to them. Subclasses decide where the diffs come from: `
|
|
6
|
-
*
|
|
7
|
+
* and applies diff results to them. Subclasses decide where the diffs come from: `StoreSync`
|
|
8
|
+
* and `StoreAsync` apply what an `ObservableDiffTree` delivers to them.
|
|
7
9
|
*
|
|
8
10
|
* @see Store
|
|
9
|
-
* @see PushStore
|
|
10
11
|
*/
|
|
11
12
|
export class ReadStore {
|
|
12
13
|
/**
|
|
13
14
|
* Creates an instance of ReadStore.
|
|
14
15
|
* @param keyFunc Optional function to generate a key for a given data value.
|
|
15
16
|
* When provided, enables alias functionality where values can reference other root objects.
|
|
17
|
+
* @param opaque Root keys held whole, see `IStoreOptions.opaque`.
|
|
16
18
|
*/
|
|
17
|
-
constructor(keyFunc) {
|
|
19
|
+
constructor(keyFunc, opaque = [], watch = [], watchCallback) {
|
|
18
20
|
this.keyFunc = keyFunc;
|
|
19
21
|
this.rootMap = new Map();
|
|
22
|
+
this.opaque = new Set(opaque);
|
|
23
|
+
this.watch = watch;
|
|
24
|
+
if (this.watch.length > 0 && !watchCallback)
|
|
25
|
+
throw new Error("watchCallback must be provided when passing watch properties");
|
|
26
|
+
this.watchCallback = watchCallback;
|
|
20
27
|
const aliasFunc = keyFunc &&
|
|
21
28
|
((value, reactive = true) => {
|
|
22
29
|
const key = keyFunc(value);
|
|
@@ -24,6 +31,8 @@ export class ReadStore {
|
|
|
24
31
|
// store: read the embedded copy
|
|
25
32
|
if (key === undefined || key.startsWith("/"))
|
|
26
33
|
return undefined;
|
|
34
|
+
if (this.opaque.has(key))
|
|
35
|
+
throw `Opaque root ${key} can't be read through a key`;
|
|
27
36
|
const rootObject = this.rootMap.get(key);
|
|
28
37
|
if (rootObject === undefined)
|
|
29
38
|
throw `No root object found for key: ${key}`;
|
|
@@ -39,7 +48,7 @@ export class ReadStore {
|
|
|
39
48
|
Get(id, defaultValue) {
|
|
40
49
|
let result = this.rootMap.get(id);
|
|
41
50
|
if (result === undefined) {
|
|
42
|
-
result = this.
|
|
51
|
+
result = this.CreateRootNode(id, defaultValue);
|
|
43
52
|
this.rootMap.set(id, result);
|
|
44
53
|
}
|
|
45
54
|
return result[id];
|
|
@@ -70,6 +79,25 @@ export class ReadStore {
|
|
|
70
79
|
this.UpdateRootObject(rootGroup[0].path[0], rootGroup);
|
|
71
80
|
}
|
|
72
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Applies whole-root writes by diffing each one into the root the store already holds, so
|
|
84
|
+
* readers of an unchanged part aren't notified and keep its objects. Anything else, an opaque
|
|
85
|
+
* root, or a root the store doesn't hold, is applied as it is.
|
|
86
|
+
* @param results - Diff results, e.g. a tree's first state after reconnecting
|
|
87
|
+
* @protected
|
|
88
|
+
*/
|
|
89
|
+
UpdateRootMapInPlace(results) {
|
|
90
|
+
const applied = [];
|
|
91
|
+
for (const result of results) {
|
|
92
|
+
const key = result.path[0];
|
|
93
|
+
const rootObject = this.rootMap.get(key);
|
|
94
|
+
if (result.type !== "write" || result.path.length > 1 || rootObject === undefined || this.opaque.has(key))
|
|
95
|
+
applied.push(result);
|
|
96
|
+
else
|
|
97
|
+
JsonDiff({ [key]: result.value }, ObservableNode.Unwrap(rootObject)).forEach(record => applied.push(record));
|
|
98
|
+
}
|
|
99
|
+
applied.length > 0 && this.UpdateRootMap(applied);
|
|
100
|
+
}
|
|
73
101
|
/**
|
|
74
102
|
* Updates a specific root object with diff results.
|
|
75
103
|
* Creates the root object if it doesn't exist.
|
|
@@ -79,12 +107,14 @@ export class ReadStore {
|
|
|
79
107
|
* @private
|
|
80
108
|
*/
|
|
81
109
|
UpdateRootObject(rootPath, results) {
|
|
110
|
+
if (this.opaque.has(rootPath))
|
|
111
|
+
results = OpaqueResults(rootPath, results);
|
|
82
112
|
const rootObject = this.rootMap.get(rootPath);
|
|
83
113
|
if (rootObject === undefined) {
|
|
84
114
|
if (results[0].type !== "write" || results[0].path.length > 1)
|
|
85
115
|
throw `Unable to initialize root path ${rootPath} with initial path ${results[0].path}`;
|
|
86
116
|
const rootData = JsonDeepClone(results[0].value);
|
|
87
|
-
const newRootObject = this.
|
|
117
|
+
const newRootObject = this.CreateRootNode(rootPath, rootData, false);
|
|
88
118
|
this.rootMap.set(rootPath, newRootObject);
|
|
89
119
|
// Later entries for the same root (e.g. route summaries written one instance at a time)
|
|
90
120
|
// apply to the root just created
|
|
@@ -94,6 +124,15 @@ export class ReadStore {
|
|
|
94
124
|
}
|
|
95
125
|
ObservableNode.ApplyDiff(rootObject, results);
|
|
96
126
|
}
|
|
127
|
+
CreateRootNode(rootPath, data, unwrap) {
|
|
128
|
+
const result = this.createNode({ [rootPath]: this.opaque.has(rootPath) ? Box(data) : data }, unwrap);
|
|
129
|
+
const rootPathStr = rootPath.toString();
|
|
130
|
+
if (this.watch.some(pattern => PatternMatches(pattern, rootPathStr)))
|
|
131
|
+
ObservableNode.WatchProperty(result, rootPath, (event) => {
|
|
132
|
+
this.watchCallback(rootPathStr, event);
|
|
133
|
+
});
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
97
136
|
}
|
|
98
137
|
/**
|
|
99
138
|
* Base class for observable data store management.
|
|
@@ -104,6 +143,22 @@ export class ReadStore {
|
|
|
104
143
|
*/
|
|
105
144
|
export class Store extends ReadStore {
|
|
106
145
|
}
|
|
146
|
+
/** An opaque root's value as the store holds it: an object or array boxed, anything else as it is */
|
|
147
|
+
function Box(value) {
|
|
148
|
+
return JsonType(value) === "value" ? value : new Opaque(value);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* An opaque root's diff, each value boxed. A DiffTree that marks the root opaque writes it whole or
|
|
152
|
+
* deletes it, so any other change means it wasn't told.
|
|
153
|
+
* @throws When the diff writes inside the root
|
|
154
|
+
*/
|
|
155
|
+
function OpaqueResults(rootPath, results) {
|
|
156
|
+
return results.map(result => {
|
|
157
|
+
if (result.path.length > 1 || (result.type !== "write" && result.type !== "delete"))
|
|
158
|
+
throw `Opaque root ${rootPath} was changed at ${result.path.join(".")}: mark it opaque in the DiffTree too (DiffTree.MarkOpaque)`;
|
|
159
|
+
return result.type === "write" ? { ...result, value: Box(result.value) } : result;
|
|
160
|
+
});
|
|
161
|
+
}
|
|
107
162
|
/** The root key a path is in: its text before the first `.` */
|
|
108
163
|
export function RootOf(path) {
|
|
109
164
|
const dot = path.indexOf(".");
|
|
@@ -1,12 +1,53 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IChannel, IWorkerLease } from "../Diff/diffTree.types";
|
|
2
|
+
import { IStoreOptions, Store } from "./store";
|
|
3
|
+
/** Options for a `StoreAsync` */
|
|
4
|
+
export interface IStoreAsyncOptions extends IStoreOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The root keys the store receives: exact keys and patterns ending in `*`. Omitted, every root.
|
|
7
|
+
* A root the store writes but doesn't receive is written but never read back. With a
|
|
8
|
+
* `keyFunc`, include the entity roots the received roots refer to.
|
|
9
|
+
*/
|
|
10
|
+
roots?: readonly string[];
|
|
11
|
+
/**
|
|
12
|
+
* Root keys the store receives only while something reads them: exact keys and patterns ending
|
|
13
|
+
* in `*`. A demand root is subscribed on its own once a reactive scope reads it with `Get` (or
|
|
14
|
+
* `Hold` holds it), and released `demandDebounce` ms after its last reader goes: unsubscribed and
|
|
15
|
+
* deleted from the store. Until its first post arrives it reads as its default. Needs `roots`:
|
|
16
|
+
* a store that receives every root has none left to demand. A key `roots` names is a `roots` root.
|
|
17
|
+
*/
|
|
18
|
+
demand?: readonly string[];
|
|
19
|
+
/** How long a demand root no one reads stays subscribed, in ms; default 1000 */
|
|
20
|
+
demandDebounce?: number;
|
|
21
|
+
}
|
|
2
22
|
/**
|
|
3
23
|
* StoreAsync class extends the base Store class to provide asynchronous data management operations.
|
|
4
24
|
* This class handles writing, patching, pushing, and splicing data in an asynchronous manner.
|
|
5
25
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
26
|
+
* The tree lives in a worker, served by a `HostPublisher`. The store subscribes on construction and
|
|
27
|
+
* applies every commit the tree posts, whatever caused it: its own batches, other writers, or the
|
|
28
|
+
* worker's own work. A store created after the tree has committed starts from its committed state.
|
|
29
|
+
* Without writes it's a read-only view of the tree.
|
|
30
|
+
*
|
|
31
|
+
* - Changes made in one tick are sent as one batch, and at most one batch waits behind the one in
|
|
32
|
+
* flight. A change's promise resolves on its batch's `jt-ack`, which arrives after the commit's
|
|
33
|
+
* posts, so the change has been applied when it resolves.
|
|
34
|
+
* - A failed batch rejects only its own changes; later batches carry on.
|
|
35
|
+
*
|
|
36
|
+
* **Demand roots** (`IStoreAsyncOptions.demand`) are received while they're read: the first reactive
|
|
37
|
+
* read of one subscribes to it alone, and its first post brings the tree's state of it; a grace
|
|
38
|
+
* period after the last reader goes, it's unsubscribed and deleted from the store. A read outside
|
|
39
|
+
* a scope neither subscribes nor keeps one; `Hold` does, for code that reads it that way.
|
|
40
|
+
*
|
|
41
|
+
* **Over a lease** (`DiffTreeHub.Open`), the store takes its keyFunc from the lease's endpoint, owns
|
|
42
|
+
* the lease, and releases it when it's destroyed. When the hub restarts the worker,
|
|
43
|
+
* the store starts over with the new tree, as when it first subscribed: the tree is the source of
|
|
44
|
+
* truth, nothing the store wrote is written back, and changes the old tree hadn't acknowledged are
|
|
45
|
+
* rejected.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* // A store over a hub's lease: it lives as long as the component that holds it
|
|
49
|
+
* @Inject(DiffTreeHub) hub!: DiffTreeHub;
|
|
50
|
+
* @Destroy() totals = new StoreAsync(this.hub.Open("totals"));
|
|
10
51
|
*
|
|
11
52
|
* @example
|
|
12
53
|
* // Creating a StoreAsync instance from a bundler-built worker entry file
|
|
@@ -26,28 +67,94 @@ import { Store } from "./store";
|
|
|
26
67
|
* // Splicing an array asynchronously
|
|
27
68
|
* await store.Splice("users", 0, 1, { id: 3 });
|
|
28
69
|
*
|
|
29
|
-
* // Cleaning up resources
|
|
70
|
+
* // Cleaning up resources: the store stops listening; the worker is its creator's to terminate
|
|
30
71
|
* store.Destroy();
|
|
72
|
+
* worker.terminate();
|
|
31
73
|
*
|
|
32
74
|
* @see Store
|
|
33
75
|
* @see StoreSync
|
|
34
76
|
*/
|
|
35
77
|
export declare class StoreAsync extends Store {
|
|
36
78
|
private writeKeySet;
|
|
37
|
-
private
|
|
79
|
+
private client;
|
|
80
|
+
private options;
|
|
81
|
+
/**
|
|
82
|
+
* The store's subscription, kept across a restart of the lease's worker: a new tree's first state
|
|
83
|
+
* deletes the roots the old one posted that it doesn't hold
|
|
84
|
+
*/
|
|
85
|
+
private subscription;
|
|
86
|
+
/** The lease the store owns, when it was given one */
|
|
87
|
+
private lease?;
|
|
88
|
+
private stopLease?;
|
|
38
89
|
private asyncQueue;
|
|
39
90
|
private currentBatch;
|
|
40
91
|
private currentBatchPromise;
|
|
92
|
+
/** Batches not yet acknowledged, for `Flush` */
|
|
93
|
+
private inFlight;
|
|
94
|
+
/** Demand roots a reactive scope reads now, from their watchers */
|
|
95
|
+
private readonly demandRead;
|
|
96
|
+
/** `Hold`s, by demand root */
|
|
97
|
+
private readonly demandHolds;
|
|
98
|
+
/** A subscription for each demand root the store holds */
|
|
99
|
+
private readonly demandSubscriptions;
|
|
100
|
+
/** The release timers of demand roots no one reads, by key */
|
|
101
|
+
private readonly demandReleasing;
|
|
102
|
+
/** Demand roots whose readers or holds changed since the last flush */
|
|
103
|
+
private readonly demandChanged;
|
|
104
|
+
private demandFlushQueued;
|
|
105
|
+
private destroyed;
|
|
106
|
+
/**
|
|
107
|
+
* Creates an instance of StoreAsync and subscribes to the tree.
|
|
108
|
+
* @param channel A channel to an `ObservableDiffTree` served by `HostPublisher`: a `Worker` (e.g. a
|
|
109
|
+
* bundled `defaultDiffTreeWorker` entry), a `MessagePort`, or a lease from `DiffTreeHub.Open`. Other
|
|
110
|
+
* messages may share the channel. Given a lease, the store owns it from then on and releases it
|
|
111
|
+
* when it's destroyed, and follows the worker across restarts. A lease on a tree on this thread
|
|
112
|
+
* (`DiffTreeHub.OpenLocal`) is for a `StoreSync`, and doesn't compile here.
|
|
113
|
+
* @param options `keyFunc`, `roots` and `opaque` (`IStoreAsyncOptions`). `keyFunc` is for a plain
|
|
114
|
+
* channel: pass the key logic the worker's tree was built with. A lease's is the endpoint's.
|
|
115
|
+
* `opaque` is the store's own: the tree must write those keys whole too, from its config
|
|
116
|
+
* (`IObservableDiffTreeConfig.opaque`), so share them from a file both import.
|
|
117
|
+
* @throws When `keyFunc` is given with a lease, whose endpoint has its own.
|
|
118
|
+
*/
|
|
119
|
+
constructor(channel: IChannel | IWorkerLease, options?: IStoreAsyncOptions);
|
|
120
|
+
/**
|
|
121
|
+
* The hub restarted the lease's worker: the store moves to the new tree's port, keeping its
|
|
122
|
+
* readers, and starts over as when it first subscribed. The changes the old tree hadn't
|
|
123
|
+
* acknowledged are rejected, not sent again, and nothing is written back: the new tree's first
|
|
124
|
+
* state is diffed into the store's roots in place, with the roots the old tree posted that the
|
|
125
|
+
* new one lacks deleted (`ChannelSubscription`).
|
|
126
|
+
*/
|
|
127
|
+
private Restarted;
|
|
128
|
+
private Connect;
|
|
129
|
+
/**
|
|
130
|
+
* Holds a demand root without reading it reactively, for code that reads it outside a scope: the
|
|
131
|
+
* store subscribes to it as for a reader, and keeps it until every hold is released. Its first
|
|
132
|
+
* post arrives later; until then it reads as its default.
|
|
133
|
+
* @returns What releases this hold; calling it again does nothing.
|
|
134
|
+
* @throws When the key is neither a demand root nor one of the store's `roots`. A `roots` root is
|
|
135
|
+
* always received: its hold does nothing.
|
|
136
|
+
*/
|
|
137
|
+
Hold(key: string): () => void;
|
|
138
|
+
private IsRootsKey;
|
|
139
|
+
private IsDemandKey;
|
|
140
|
+
/**
|
|
141
|
+
* A demand root's watcher: it gained its first reactive reader or lost its last. This runs inside
|
|
142
|
+
* a scope's update, so it only records the change for the next flush.
|
|
143
|
+
*/
|
|
144
|
+
private DemandWatched;
|
|
145
|
+
private DemandChanged;
|
|
41
146
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* (e.g. a bundled `defaultDiffTreeWorker` entry). Any `keyFunc`/routes the diff needs
|
|
45
|
-
* must be baked into that worker's own entry file.
|
|
46
|
-
* @param keyFunc Optional function to generate a key for a given data value, used locally by
|
|
47
|
-
* this store to resolve root objects. Pass the same key logic the worker's `DiffTree` was
|
|
48
|
-
* constructed with, if any.
|
|
147
|
+
* Subscribes the demand roots read or held now and not yet subscribed, and starts the release of
|
|
148
|
+
* the ones no one reads or holds. A root read and dropped since the last flush is never subscribed.
|
|
49
149
|
*/
|
|
50
|
-
|
|
150
|
+
private FlushDemand;
|
|
151
|
+
private IsDemanded;
|
|
152
|
+
private SubscribeDemand;
|
|
153
|
+
private ReleaseLater;
|
|
154
|
+
/** Unsubscribes a demand root and deletes it from the store, so no later reader sees it stale */
|
|
155
|
+
private ReleaseDemand;
|
|
156
|
+
/** Applies a post. A tree's first state is diffed into the roots in place, its deletes with it. */
|
|
157
|
+
private Apply;
|
|
51
158
|
private Schedule;
|
|
52
159
|
/**
|
|
53
160
|
* Writes data to the store asynchronously.
|
|
@@ -57,8 +164,8 @@ export declare class StoreAsync extends Store {
|
|
|
57
164
|
* @param data The data to be written. Can be of any type.
|
|
58
165
|
* @param key Optional key for the data. If not provided, the keyFunc will be used to generate a key.
|
|
59
166
|
* @returns A promise that resolves once the write has been applied to the store.
|
|
60
|
-
* @throws Will throw an error if no key is provided for the data, or reject with the
|
|
61
|
-
*
|
|
167
|
+
* @throws Will throw an error if no key is provided for the data, or reject with the error of
|
|
168
|
+
* the batch it was sent in.
|
|
62
169
|
*/
|
|
63
170
|
Write(data: unknown, key?: string): Promise<void>;
|
|
64
171
|
/**
|
|
@@ -69,7 +176,7 @@ export declare class StoreAsync extends Store {
|
|
|
69
176
|
* @param patch The patch data to be merged with the existing value.
|
|
70
177
|
* @returns A promise that resolves once the patch has been applied to the store.
|
|
71
178
|
* @throws Will throw if the key isn't in the store and has no pending Write, or reject with
|
|
72
|
-
* the
|
|
179
|
+
* the error of the batch it was sent in.
|
|
73
180
|
*/
|
|
74
181
|
Patch(key: string, patch: unknown): Promise<void>;
|
|
75
182
|
/**
|
|
@@ -78,7 +185,7 @@ export declare class StoreAsync extends Store {
|
|
|
78
185
|
* @param data The data items to be pushed into the array.
|
|
79
186
|
* @returns A promise that resolves once the items have been applied to the store.
|
|
80
187
|
* @throws Will throw if the key isn't in the store and has no pending Write, or reject with
|
|
81
|
-
* the
|
|
188
|
+
* the error of the batch it was sent in.
|
|
82
189
|
*/
|
|
83
190
|
Push(key: string, ...data: unknown[]): Promise<void>;
|
|
84
191
|
/**
|
|
@@ -90,19 +197,21 @@ export declare class StoreAsync extends Store {
|
|
|
90
197
|
* @param items Optional elements to insert into the array.
|
|
91
198
|
* @returns A promise that resolves once the splice has been applied to the store.
|
|
92
199
|
* @throws Will throw if the key isn't in the store and has no pending Write, or reject with
|
|
93
|
-
* the
|
|
200
|
+
* the error of the batch it was sent in.
|
|
94
201
|
*/
|
|
95
202
|
Splice(key: string, start: number, deleteCount?: number, ...items: unknown[]): Promise<void>;
|
|
96
203
|
/**
|
|
97
204
|
* Returns a promise that resolves once every change made before this call has been applied
|
|
98
|
-
* to the store
|
|
99
|
-
*
|
|
100
|
-
*
|
|
205
|
+
* to the store: when the last batch sent before it is acknowledged, and at once when none is in
|
|
206
|
+
* flight. Changes made after this call are sent in a later batch, so they aren't waited for and
|
|
207
|
+
* haven't been applied when the promise resolves.
|
|
208
|
+
* @throws Rejects with the first error of the batches it waited for.
|
|
101
209
|
*/
|
|
102
210
|
Flush(): Promise<void>;
|
|
103
211
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
212
|
+
* Unsubscribes and stops listening to the channel. Changes not yet acknowledged never settle.
|
|
213
|
+
* Over a lease, the store then releases it: the last lease on a worker ends it. Over a channel, the
|
|
214
|
+
* channel stays open: whoever created the worker terminates it.
|
|
106
215
|
*/
|
|
107
216
|
Destroy(): void;
|
|
108
217
|
}
|