shelving 1.96.1 → 1.97.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/db/ItemReference.d.ts +4 -3
- package/db/ItemState.js +5 -5
- package/db/QueryReference.d.ts +3 -2
- package/db/QueryState.d.ts +1 -1
- package/db/QueryState.js +5 -4
- package/firestore/client/FirestoreClientProvider.js +2 -1
- package/firestore/lite/FirestoreLiteProvider.js +2 -1
- package/firestore/server/FirestoreServerProvider.js +2 -1
- package/package.json +1 -1
- package/provider/CacheProvider.js +2 -2
- package/provider/DebugProvider.js +53 -75
- package/provider/MemoryProvider.d.ts +16 -17
- package/provider/MemoryProvider.js +54 -93
- package/provider/ValidationProvider.js +11 -11
- package/react/useInstance.d.ts +1 -1
- package/react/useLazy.d.ts +2 -2
- package/react/useReduce.js +2 -2
- package/react/useState.js +4 -9
- package/sequence/DeferredSequence.d.ts +3 -2
- package/sequence/DeferredSequence.js +2 -2
- package/sequence/LazyDeferredSequence.d.ts +2 -2
- package/state/ArrayState.d.ts +2 -1
- package/state/ArrayState.js +2 -2
- package/state/BooleanState.d.ts +2 -1
- package/state/BooleanState.js +2 -2
- package/state/DataState.d.ts +2 -2
- package/state/DataState.js +2 -2
- package/state/DictionaryState.d.ts +2 -1
- package/state/DictionaryState.js +2 -2
- package/state/State.d.ts +21 -11
- package/state/State.js +33 -20
- package/util/activity.d.ts +13 -17
- package/util/activity.js +3 -17
- package/util/array.d.ts +6 -6
- package/util/array.js +9 -10
- package/util/async.d.ts +14 -22
- package/util/async.js +16 -33
- package/util/constants.d.ts +4 -2
- package/util/constants.js +4 -2
- package/util/data.d.ts +0 -2
- package/util/function.d.ts +8 -10
- package/util/function.js +5 -6
- package/util/map.d.ts +2 -2
- package/util/map.js +2 -2
- package/util/match.d.ts +2 -0
- package/util/match.js +6 -0
- package/util/null.d.ts +2 -2
- package/util/random.d.ts +3 -1
- package/util/random.js +9 -1
- package/util/sequence.d.ts +6 -5
- package/util/sequence.js +14 -14
- package/util/undefined.d.ts +5 -5
package/db/ItemReference.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { DeleteChange, SetChange, UpdateChange } from "./Change.js";
|
|
2
2
|
import type { AsyncProvider, Provider } from "../provider/Provider.js";
|
|
3
|
+
import type { Stop } from "../util/activity.js";
|
|
3
4
|
import type { ImmutableArray } from "../util/array.js";
|
|
4
5
|
import type { Data } from "../util/data.js";
|
|
5
|
-
import type { Dispatch, Handler
|
|
6
|
+
import type { Dispatch, Handler } from "../util/function.js";
|
|
6
7
|
import type { Query } from "../util/query.js";
|
|
7
8
|
import type { Updates } from "../util/update.js";
|
|
8
9
|
/** Item data with a string ID that uniquely identifies it. */
|
|
@@ -10,7 +11,7 @@ export type ItemData<T extends Data = Data> = T & {
|
|
|
10
11
|
id: string;
|
|
11
12
|
};
|
|
12
13
|
/** Entity or `null` to indicate the item doesn't exist. */
|
|
13
|
-
export type ItemValue<T extends Data = Data> = ItemData<T> |
|
|
14
|
+
export type ItemValue<T extends Data = Data> = ItemData<T> | undefined;
|
|
14
15
|
/** Get the ID from item data. */
|
|
15
16
|
export declare const getID: <T extends Data>({ id }: ItemData<T>) => string;
|
|
16
17
|
/** Get the IDs of an iterable set item data. */
|
|
@@ -61,7 +62,7 @@ declare abstract class AbstractItemReference<T extends Data = Data> implements A
|
|
|
61
62
|
getDelete(): DeleteChange;
|
|
62
63
|
toString(): string;
|
|
63
64
|
/** Subscribe to this item. */
|
|
64
|
-
subscribe(onNext?: Dispatch<
|
|
65
|
+
subscribe(onNext?: Dispatch<ItemValue<T>>, onError?: Handler): Stop;
|
|
65
66
|
[Symbol.asyncIterator](): AsyncIterator<ItemValue<T>>;
|
|
66
67
|
}
|
|
67
68
|
/** Reference to an item in a synchronous database. */
|
package/db/ItemState.js
CHANGED
|
@@ -18,16 +18,15 @@ export class ItemState extends State {
|
|
|
18
18
|
var _a;
|
|
19
19
|
const { provider, collection, id } = ref;
|
|
20
20
|
const table = (_a = getOptionalSource(CacheProvider, provider)) === null || _a === void 0 ? void 0 : _a.memory.getTable(collection);
|
|
21
|
-
const time = table ? table.
|
|
22
|
-
const
|
|
23
|
-
super(table &&
|
|
21
|
+
const time = table ? table.getQueryTime(ref) : null;
|
|
22
|
+
const next = table ? new LazyDeferredSequence(() => this.from(table.getCachedItemSequence(id), () => typeof table.getItemTime(id) === "number")) : undefined;
|
|
23
|
+
super(table && typeof time === "number" ? { value: table.getItem(id), time, next } : { next });
|
|
24
24
|
this.busy = new BooleanState();
|
|
25
25
|
/** Refresh this state from the source provider. */
|
|
26
26
|
this.refresh = () => {
|
|
27
27
|
if (!this.busy.value)
|
|
28
28
|
void this._refresh();
|
|
29
29
|
};
|
|
30
|
-
this._time = time;
|
|
31
30
|
this.ref = ref;
|
|
32
31
|
// Queue a request to refresh the value if it doesn't exist.
|
|
33
32
|
if (this.loading)
|
|
@@ -35,11 +34,12 @@ export class ItemState extends State {
|
|
|
35
34
|
}
|
|
36
35
|
async _refresh() {
|
|
37
36
|
this.busy.set(true);
|
|
37
|
+
this.error(undefined); // Optimistically clear the error.
|
|
38
38
|
try {
|
|
39
39
|
this.set(await this.ref.value);
|
|
40
40
|
}
|
|
41
41
|
catch (thrown) {
|
|
42
|
-
this.
|
|
42
|
+
this.error(thrown);
|
|
43
43
|
}
|
|
44
44
|
finally {
|
|
45
45
|
this.busy.set(false);
|
package/db/QueryReference.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ItemArray, ItemData, ItemQuery, ItemValue } from "./ItemReference.js";
|
|
2
2
|
import type { AsyncProvider, Provider } from "../provider/Provider.js";
|
|
3
|
+
import type { Stop } from "../util/activity.js";
|
|
3
4
|
import type { Data } from "../util/data.js";
|
|
4
|
-
import type { Dispatch, Handler
|
|
5
|
+
import type { Dispatch, Handler } from "../util/function.js";
|
|
5
6
|
import type { Updates } from "../util/update.js";
|
|
6
7
|
/** Reference to a set of items in a sync or async provider. */
|
|
7
8
|
declare abstract class AbstractQueryReference<T extends Data = Data> implements AsyncIterable<ItemArray<T>> {
|
|
@@ -62,7 +63,7 @@ declare abstract class AbstractQueryReference<T extends Data = Data> implements
|
|
|
62
63
|
abstract delete(): number | PromiseLike<number>;
|
|
63
64
|
toString(): string;
|
|
64
65
|
/** Subscribe to this item. */
|
|
65
|
-
subscribe(onNext?: Dispatch<
|
|
66
|
+
subscribe(onNext?: Dispatch<ItemArray<T>>, onError?: Handler): Stop;
|
|
66
67
|
[Symbol.asyncIterator](): AsyncIterator<ItemArray<T>>;
|
|
67
68
|
}
|
|
68
69
|
/** Reference to a set of items in a provider. */
|
package/db/QueryState.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ItemArray, ItemData, ItemValue } from "./ItemReference.js";
|
|
2
2
|
import type { AsyncQueryReference, QueryReference } from "./QueryReference.js";
|
|
3
|
+
import type { Stop } from "../util/activity.js";
|
|
3
4
|
import type { Data } from "../util/data.js";
|
|
4
|
-
import type { Stop } from "../util/function.js";
|
|
5
5
|
import { BooleanState } from "../state/BooleanState.js";
|
|
6
6
|
import { State } from "../state/State.js";
|
|
7
7
|
/** Hold the current state of a query. */
|
package/db/QueryState.js
CHANGED
|
@@ -41,8 +41,8 @@ export class QueryState extends State {
|
|
|
41
41
|
const { provider, collection, query } = ref;
|
|
42
42
|
const table = (_a = getOptionalSource(CacheProvider, provider)) === null || _a === void 0 ? void 0 : _a.memory.getTable(collection);
|
|
43
43
|
const time = table ? table.getQueryTime(ref) : null;
|
|
44
|
-
const
|
|
45
|
-
super(table &&
|
|
44
|
+
const next = table ? new LazyDeferredSequence(() => this.from(table.getCachedQuerySequence(ref))) : undefined;
|
|
45
|
+
super(table && typeof time === "number" ? { value: table.getQuery(ref), time, next } : { next });
|
|
46
46
|
this.busy = new BooleanState();
|
|
47
47
|
this._hasMore = false;
|
|
48
48
|
/** Refresh this state from the source provider. */
|
|
@@ -58,7 +58,6 @@ export class QueryState extends State {
|
|
|
58
58
|
if (!this.busy.value)
|
|
59
59
|
void this._loadMore();
|
|
60
60
|
};
|
|
61
|
-
this._time = time;
|
|
62
61
|
this.ref = ref;
|
|
63
62
|
this.limit = (_b = getLimit(query)) !== null && _b !== void 0 ? _b : Infinity;
|
|
64
63
|
// Queue a request to refresh the value if it doesn't exist.
|
|
@@ -67,6 +66,7 @@ export class QueryState extends State {
|
|
|
67
66
|
}
|
|
68
67
|
async _refresh() {
|
|
69
68
|
this.busy.set(true);
|
|
69
|
+
this.error(undefined); // Optimistically clear the error.
|
|
70
70
|
try {
|
|
71
71
|
const items = await this.ref.items;
|
|
72
72
|
this._hasMore = items.length >= this.limit; // If the query returned {limit} or more items, we can assume there are more items waiting to be queried.
|
|
@@ -90,6 +90,7 @@ export class QueryState extends State {
|
|
|
90
90
|
}
|
|
91
91
|
async _loadMore() {
|
|
92
92
|
this.busy.set(true);
|
|
93
|
+
this.error(undefined); // Optimistically clear the error.
|
|
93
94
|
try {
|
|
94
95
|
const last = this.last;
|
|
95
96
|
const ref = last ? this.ref.with(getAfterQuery(this.ref.query, last)) : this.ref;
|
|
@@ -98,7 +99,7 @@ export class QueryState extends State {
|
|
|
98
99
|
this._hasMore = items.length >= this.limit; // If the query returned {limit} or more items, we can assume there are more items waiting to be queried.
|
|
99
100
|
}
|
|
100
101
|
catch (thrown) {
|
|
101
|
-
this.
|
|
102
|
+
this.error(thrown);
|
|
102
103
|
}
|
|
103
104
|
finally {
|
|
104
105
|
this.busy.set(false);
|
|
@@ -40,7 +40,8 @@ function _getItemData(snapshot) {
|
|
|
40
40
|
}
|
|
41
41
|
function _getItemValue(snapshot) {
|
|
42
42
|
const data = snapshot.data();
|
|
43
|
-
|
|
43
|
+
if (data)
|
|
44
|
+
return { ...data, id: snapshot.id };
|
|
44
45
|
}
|
|
45
46
|
/** Convert `Updates` object into corresponding Firestore `FieldValue` instances. */
|
|
46
47
|
const _getFieldValues = (updates) => getObject(mapItems(getUpdates(updates), _getFieldValue));
|
|
@@ -37,7 +37,8 @@ function _getItemData(snapshot) {
|
|
|
37
37
|
}
|
|
38
38
|
function _getItemValue(snapshot) {
|
|
39
39
|
const data = snapshot.data();
|
|
40
|
-
|
|
40
|
+
if (data)
|
|
41
|
+
return { ...data, id: snapshot.id };
|
|
41
42
|
}
|
|
42
43
|
/** Convert `Updates` object into corresponding Firestore `FieldValue` instances. */
|
|
43
44
|
const _getFieldValues = (updates) => getObject(mapItems(getUpdates(updates), _getFieldValue));
|
|
@@ -39,7 +39,8 @@ function _getItemData(snapshot) {
|
|
|
39
39
|
}
|
|
40
40
|
function _getItemValue(snapshot) {
|
|
41
41
|
const data = snapshot.data();
|
|
42
|
-
|
|
42
|
+
if (data)
|
|
43
|
+
return { ...data, id: snapshot.id };
|
|
43
44
|
}
|
|
44
45
|
/** Convert `Update` instances into corresponding Firestore `FieldValue` instances. */
|
|
45
46
|
const _getFieldValues = (updates) => getObject(mapItems(getUpdates(updates), _getFieldValue));
|
package/package.json
CHANGED
|
@@ -37,12 +37,12 @@ export class CacheProvider {
|
|
|
37
37
|
async getQuery(collection, query) {
|
|
38
38
|
const items = await this.source.getQuery(collection, query);
|
|
39
39
|
const table = this.memory.getTable(collection);
|
|
40
|
-
table.
|
|
40
|
+
table.setQueryArray(query, items);
|
|
41
41
|
return items;
|
|
42
42
|
}
|
|
43
43
|
async *getQuerySequence(collection, query) {
|
|
44
44
|
const table = this.memory.getTable(collection);
|
|
45
|
-
yield* table.
|
|
45
|
+
yield* table.setQueryArraySequence(query, this.source.getQuerySequence(collection, query));
|
|
46
46
|
}
|
|
47
47
|
async setQuery(collection, query, data) {
|
|
48
48
|
const count = await this.source.setQuery(collection, query, data);
|
|
@@ -2,31 +2,29 @@
|
|
|
2
2
|
/** Provider that logs operations to a source provider to the console. */
|
|
3
3
|
class AbstractDebugProvider {
|
|
4
4
|
async *getItemSequence(collection, id) {
|
|
5
|
-
const key = _getItemKey(collection, id);
|
|
6
5
|
try {
|
|
7
|
-
console.
|
|
6
|
+
console.debug("✔ ITERATE", collection, id);
|
|
8
7
|
for await (const item of this.source.getItemSequence(collection, id)) {
|
|
9
|
-
console.
|
|
8
|
+
console.debug("✔ ITERATE", collection, id, "GOT", item);
|
|
10
9
|
yield item;
|
|
11
10
|
}
|
|
12
|
-
console.
|
|
11
|
+
console.debug("✔ ITERATE", collection, id);
|
|
13
12
|
}
|
|
14
13
|
catch (thrown) {
|
|
15
|
-
console.error("ITERATE",
|
|
14
|
+
console.error("✘ ITERATE", collection, id, thrown);
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
17
|
async *getQuerySequence(collection, query) {
|
|
19
|
-
const key = _getQueryKey(collection, query);
|
|
20
18
|
try {
|
|
21
|
-
console.
|
|
19
|
+
console.debug("✔ ITERATE", collection, query);
|
|
22
20
|
for await (const items of this.source.getQuerySequence(collection, query)) {
|
|
23
|
-
console.
|
|
21
|
+
console.debug("✔ ITERATE", collection, query, items);
|
|
24
22
|
yield items;
|
|
25
23
|
}
|
|
26
|
-
console.
|
|
24
|
+
console.debug("✔ ITERATE", collection, query);
|
|
27
25
|
}
|
|
28
26
|
catch (thrown) {
|
|
29
|
-
console.error("ITERATE",
|
|
27
|
+
console.error("✘ ITERATE", collection, query, thrown);
|
|
30
28
|
}
|
|
31
29
|
}
|
|
32
30
|
}
|
|
@@ -37,107 +35,98 @@ export class DebugProvider extends AbstractDebugProvider {
|
|
|
37
35
|
this.source = source;
|
|
38
36
|
}
|
|
39
37
|
getItem(collection, id) {
|
|
40
|
-
const key = _getItemKey(collection, id);
|
|
41
38
|
try {
|
|
42
39
|
const item = this.source.getItem(collection, id);
|
|
43
|
-
console.
|
|
40
|
+
console.debug("✔ GET", collection, id, "ITEM", item);
|
|
44
41
|
return item;
|
|
45
42
|
}
|
|
46
43
|
catch (reason) {
|
|
47
|
-
console.error("GET
|
|
44
|
+
console.error("✘ GET", collection, id, reason);
|
|
48
45
|
throw reason;
|
|
49
46
|
}
|
|
50
47
|
}
|
|
51
48
|
addItem(collection, data) {
|
|
52
|
-
const key = collection;
|
|
53
49
|
try {
|
|
54
50
|
const id = this.source.addItem(collection, data);
|
|
55
|
-
console.
|
|
51
|
+
console.debug("✔ ADD", collection, data, "ID", id);
|
|
56
52
|
return id;
|
|
57
53
|
}
|
|
58
54
|
catch (reason) {
|
|
59
|
-
console.error("ADD",
|
|
55
|
+
console.error("✘ ADD", collection, data, reason);
|
|
60
56
|
throw reason;
|
|
61
57
|
}
|
|
62
58
|
}
|
|
63
59
|
setItem(collection, id, data) {
|
|
64
|
-
const key = _getItemKey(collection, id);
|
|
65
60
|
try {
|
|
66
61
|
this.source.setItem(collection, id, data);
|
|
67
|
-
console.
|
|
62
|
+
console.debug("✔ SET", collection, id, data);
|
|
68
63
|
}
|
|
69
64
|
catch (reason) {
|
|
70
|
-
console.error("SET
|
|
65
|
+
console.error("✘ SET", collection, id, data, reason);
|
|
71
66
|
throw reason;
|
|
72
67
|
}
|
|
73
68
|
}
|
|
74
69
|
updateItem(collection, id, updates) {
|
|
75
|
-
const key = _getItemKey(collection, id);
|
|
76
70
|
try {
|
|
77
|
-
console.
|
|
71
|
+
console.debug("✔ UPDATE", collection, id, updates);
|
|
78
72
|
return this.source.updateItem(collection, id, updates);
|
|
79
73
|
}
|
|
80
74
|
catch (reason) {
|
|
81
|
-
console.error("UPDATE
|
|
75
|
+
console.error("✘ UPDATE", collection, id, updates, reason);
|
|
82
76
|
throw reason;
|
|
83
77
|
}
|
|
84
78
|
}
|
|
85
79
|
deleteItem(collection, id) {
|
|
86
|
-
const key = _getItemKey(collection, id);
|
|
87
80
|
try {
|
|
88
81
|
this.source.deleteItem(collection, id);
|
|
89
|
-
console.
|
|
82
|
+
console.debug("✔ DELETE", collection, id);
|
|
90
83
|
}
|
|
91
84
|
catch (reason) {
|
|
92
|
-
console.error("DELETE
|
|
85
|
+
console.error("✘ DELETE", collection, id, reason);
|
|
93
86
|
throw reason;
|
|
94
87
|
}
|
|
95
88
|
}
|
|
96
89
|
getQuery(collection, query) {
|
|
97
|
-
const key = _getQueryKey(collection, query);
|
|
98
90
|
try {
|
|
99
91
|
const items = this.source.getQuery(collection, query);
|
|
100
|
-
console.
|
|
92
|
+
console.debug("✔ ✅ GET", collection, query, "ITEMS", items);
|
|
101
93
|
return items;
|
|
102
94
|
}
|
|
103
95
|
catch (reason) {
|
|
104
|
-
console.error("GET
|
|
96
|
+
console.error("✘ GET", collection, query, reason);
|
|
105
97
|
throw reason;
|
|
106
98
|
}
|
|
107
99
|
}
|
|
108
100
|
setQuery(collection, query, data) {
|
|
109
|
-
const key = _getQueryKey(collection, query);
|
|
110
101
|
try {
|
|
111
102
|
const num = this.source.setQuery(collection, query, data);
|
|
112
|
-
console.
|
|
103
|
+
console.debug("✔ SET", collection, query, data, num);
|
|
113
104
|
return num;
|
|
114
105
|
}
|
|
115
106
|
catch (reason) {
|
|
116
|
-
console.error("SET
|
|
107
|
+
console.error("✘ SET", collection, query, data, reason);
|
|
117
108
|
throw reason;
|
|
118
109
|
}
|
|
119
110
|
}
|
|
120
111
|
updateQuery(collection, query, updates) {
|
|
121
|
-
const key = _getQueryKey(collection, query);
|
|
122
112
|
try {
|
|
123
113
|
const num = this.source.updateQuery(collection, query, updates);
|
|
124
|
-
console.
|
|
114
|
+
console.debug("✔ UPDATE", collection, query, updates, num);
|
|
125
115
|
return num;
|
|
126
116
|
}
|
|
127
117
|
catch (reason) {
|
|
128
|
-
console.error("UPDATE
|
|
118
|
+
console.error("✘ UPDATE", collection, query, updates, reason);
|
|
129
119
|
throw reason;
|
|
130
120
|
}
|
|
131
121
|
}
|
|
132
122
|
deleteQuery(collection, query) {
|
|
133
|
-
const key = _getQueryKey(collection, query);
|
|
134
123
|
try {
|
|
135
124
|
const num = this.source.deleteQuery(collection, query);
|
|
136
|
-
console.
|
|
125
|
+
console.debug("✔ DELETE", collection, query, num);
|
|
137
126
|
return num;
|
|
138
127
|
}
|
|
139
128
|
catch (reason) {
|
|
140
|
-
console.error("DELETE
|
|
129
|
+
console.error("✘ DELETE", collection, query, reason);
|
|
141
130
|
throw reason;
|
|
142
131
|
}
|
|
143
132
|
}
|
|
@@ -149,119 +138,108 @@ export class AsyncDebugProvider extends AbstractDebugProvider {
|
|
|
149
138
|
this.source = source;
|
|
150
139
|
}
|
|
151
140
|
async getItem(collection, id) {
|
|
152
|
-
const key = _getItemKey(collection, id);
|
|
153
141
|
try {
|
|
154
|
-
console.
|
|
142
|
+
console.debug("⋯ GET", collection, id);
|
|
155
143
|
const item = await this.source.getItem(collection, id);
|
|
156
|
-
console.
|
|
144
|
+
console.debug("✔ GET", collection, id, "ITEM", item);
|
|
157
145
|
return item;
|
|
158
146
|
}
|
|
159
147
|
catch (reason) {
|
|
160
|
-
console.error("GET
|
|
148
|
+
console.error("✘ GET", collection, id, reason);
|
|
161
149
|
throw reason;
|
|
162
150
|
}
|
|
163
151
|
}
|
|
164
152
|
async addItem(collection, data) {
|
|
165
|
-
const key = collection;
|
|
166
153
|
try {
|
|
167
|
-
console.
|
|
154
|
+
console.debug("⋯ ADD", collection, data);
|
|
168
155
|
const id = await this.source.addItem(collection, data);
|
|
169
|
-
console.
|
|
156
|
+
console.debug("✔ ADD", collection, id, data);
|
|
170
157
|
return id;
|
|
171
158
|
}
|
|
172
159
|
catch (reason) {
|
|
173
|
-
console.error("ADD",
|
|
160
|
+
console.error("✘ ADD", collection, data, reason);
|
|
174
161
|
throw reason;
|
|
175
162
|
}
|
|
176
163
|
}
|
|
177
164
|
async setItem(collection, id, data) {
|
|
178
|
-
const key = _getItemKey(collection, id);
|
|
179
165
|
try {
|
|
180
|
-
console.
|
|
166
|
+
console.debug("⋯ SET", collection, id, data);
|
|
181
167
|
await this.source.setItem(collection, id, data);
|
|
182
|
-
console.
|
|
168
|
+
console.debug("✔ SET", collection, id, data, 1);
|
|
183
169
|
}
|
|
184
170
|
catch (reason) {
|
|
185
|
-
console.error("SET
|
|
171
|
+
console.error("✘ SET", collection, id, data, reason);
|
|
186
172
|
throw reason;
|
|
187
173
|
}
|
|
188
174
|
}
|
|
189
175
|
async updateItem(collection, id, updates) {
|
|
190
|
-
const key = _getItemKey(collection, id);
|
|
191
176
|
try {
|
|
192
|
-
console.
|
|
177
|
+
console.debug("⋯ UPDATE", collection, id, updates);
|
|
193
178
|
await this.source.updateItem(collection, id, updates);
|
|
194
|
-
console.
|
|
179
|
+
console.debug("✔ UPDATE", collection, id, updates, 1);
|
|
195
180
|
}
|
|
196
181
|
catch (reason) {
|
|
197
|
-
console.error("UPDATE
|
|
182
|
+
console.error("✘ UPDATE", collection, id, updates, reason);
|
|
198
183
|
throw reason;
|
|
199
184
|
}
|
|
200
185
|
}
|
|
201
186
|
async deleteItem(collection, id) {
|
|
202
|
-
const key = _getItemKey(collection, id);
|
|
203
187
|
try {
|
|
204
|
-
console.
|
|
188
|
+
console.debug("⋯ DELETE", collection, id);
|
|
205
189
|
await this.source.deleteItem(collection, id);
|
|
206
|
-
console.
|
|
190
|
+
console.debug("✔ DELETE", collection, id, 1);
|
|
207
191
|
}
|
|
208
192
|
catch (reason) {
|
|
209
|
-
console.error("DELETE
|
|
193
|
+
console.error("✘ DELETE", collection, id, reason);
|
|
210
194
|
throw reason;
|
|
211
195
|
}
|
|
212
196
|
}
|
|
213
197
|
async getQuery(collection, query) {
|
|
214
|
-
const key = _getQueryKey(collection, query);
|
|
215
198
|
try {
|
|
216
|
-
console.
|
|
199
|
+
console.debug("⋯ GET", collection, query);
|
|
217
200
|
const items = await this.source.getQuery(collection, query);
|
|
218
|
-
console.
|
|
201
|
+
console.debug("✔ GET", collection, query, "ITEMS", items);
|
|
219
202
|
return items;
|
|
220
203
|
}
|
|
221
204
|
catch (reason) {
|
|
222
|
-
console.error("GET
|
|
205
|
+
console.error("✘ GET", collection, query, reason);
|
|
223
206
|
throw reason;
|
|
224
207
|
}
|
|
225
208
|
}
|
|
226
209
|
async setQuery(collection, query, data) {
|
|
227
|
-
const key = _getQueryKey(collection, query);
|
|
228
210
|
try {
|
|
229
|
-
console.
|
|
211
|
+
console.debug("⋯ SET", collection, query, data);
|
|
230
212
|
const num = await this.source.setQuery(collection, query, data);
|
|
231
|
-
console.
|
|
213
|
+
console.debug("✔ SET", collection, query, data, num);
|
|
232
214
|
return num;
|
|
233
215
|
}
|
|
234
216
|
catch (reason) {
|
|
235
|
-
console.error("SET
|
|
217
|
+
console.error("✘ SET", collection, query, data, reason);
|
|
236
218
|
throw reason;
|
|
237
219
|
}
|
|
238
220
|
}
|
|
239
221
|
async updateQuery(collection, query, updates) {
|
|
240
|
-
const key = _getQueryKey(collection, query);
|
|
241
222
|
try {
|
|
242
|
-
console.
|
|
223
|
+
console.debug("⋯ UPDATE", collection, query, updates);
|
|
243
224
|
const num = await this.source.updateQuery(collection, query, updates);
|
|
244
|
-
console.
|
|
225
|
+
console.debug("✔ UPDATE", collection, query, updates, num);
|
|
245
226
|
return num;
|
|
246
227
|
}
|
|
247
228
|
catch (reason) {
|
|
248
|
-
console.error("UPDATE
|
|
229
|
+
console.error("✘ UPDATE", collection, query, updates, reason);
|
|
249
230
|
throw reason;
|
|
250
231
|
}
|
|
251
232
|
}
|
|
252
233
|
async deleteQuery(collection, query) {
|
|
253
|
-
const key = _getQueryKey(collection, query);
|
|
254
234
|
try {
|
|
255
|
-
console.
|
|
235
|
+
console.debug("⋯ DELETE", collection, query);
|
|
256
236
|
const num = await this.source.deleteQuery(collection, query);
|
|
257
|
-
console.
|
|
237
|
+
console.debug("✔ DELETE", collection, query, num);
|
|
258
238
|
return num;
|
|
259
239
|
}
|
|
260
240
|
catch (reason) {
|
|
261
|
-
console.error("DELETE
|
|
241
|
+
console.error("✘ DELETE", collection, query, reason);
|
|
262
242
|
throw reason;
|
|
263
243
|
}
|
|
264
244
|
}
|
|
265
245
|
}
|
|
266
|
-
const _getItemKey = (collection, id) => `${collection}/${id}`;
|
|
267
|
-
const _getQueryKey = (collection, query) => `${collection}?${JSON.stringify(query)}`;
|
|
@@ -13,14 +13,14 @@ export declare class MemoryProvider implements Provider {
|
|
|
13
13
|
private _tables;
|
|
14
14
|
/** Get a table for a collection. */
|
|
15
15
|
getTable(collection: string): MemoryTable;
|
|
16
|
-
|
|
16
|
+
getItemTime(collection: string, id: string): number | undefined;
|
|
17
17
|
getItem(collection: string, id: string): ItemValue;
|
|
18
18
|
getItemSequence(collection: string, id: string): AsyncIterable<ItemValue>;
|
|
19
19
|
addItem(collection: string, data: Data): string;
|
|
20
|
-
setItem(collection: string, id: string, data: Data):
|
|
21
|
-
updateItem(collection: string, id: string, updates: Updates):
|
|
22
|
-
deleteItem(collection: string, id: string):
|
|
23
|
-
getQueryTime(collection: string, query: ItemQuery): number |
|
|
20
|
+
setItem(collection: string, id: string, data: Data): boolean;
|
|
21
|
+
updateItem(collection: string, id: string, updates: Updates): boolean;
|
|
22
|
+
deleteItem(collection: string, id: string): boolean;
|
|
23
|
+
getQueryTime(collection: string, query: ItemQuery): number | undefined;
|
|
24
24
|
getQuery(collection: string, query: ItemQuery): ItemArray;
|
|
25
25
|
getQuerySequence(collection: string, query: ItemQuery): AsyncIterable<ItemArray>;
|
|
26
26
|
setQuery(collection: string, query: ItemQuery, data: Data): number;
|
|
@@ -35,28 +35,27 @@ export declare class MemoryTable<T extends Data = Data> {
|
|
|
35
35
|
protected readonly _times: Map<string, number>;
|
|
36
36
|
/** Deferred sequence of next values. */
|
|
37
37
|
readonly _changed: DeferredSequence<void, void>;
|
|
38
|
-
getItemTime(id: string): number |
|
|
38
|
+
getItemTime(id: string): number | undefined;
|
|
39
39
|
getItem(id: string): ItemValue<T>;
|
|
40
40
|
getItemSequence(id: string): AsyncIterable<ItemValue<T>>;
|
|
41
41
|
/** Subscribe to a query in this table, but only if the query has been explicitly set (i.e. has a time). */
|
|
42
42
|
getCachedItemSequence(id: string): AsyncIterable<ItemValue<T>>;
|
|
43
43
|
addItem(data: T): string;
|
|
44
|
-
|
|
45
|
-
setItem(id: string, item: ItemData<T> | T):
|
|
46
|
-
setItemValue(id: string, value: ItemData<T> | T |
|
|
44
|
+
setItemData(item: ItemData<T>): boolean;
|
|
45
|
+
setItem(id: string, item: ItemData<T> | T): boolean;
|
|
46
|
+
setItemValue(id: string, value: ItemData<T> | T | undefined): boolean;
|
|
47
47
|
setItemValueSequence(id: string, sequence: AsyncIterable<ItemValue<T>>): AsyncIterable<ItemValue>;
|
|
48
|
-
updateItem(id: string, updates: Updates<T>):
|
|
49
|
-
deleteItem(id: string):
|
|
50
|
-
getQueryTime(query: ItemQuery<T>): number |
|
|
48
|
+
updateItem(id: string, updates: Updates<T>): boolean;
|
|
49
|
+
deleteItem(id: string): boolean;
|
|
50
|
+
getQueryTime(query: ItemQuery<T>): number | undefined;
|
|
51
51
|
getQuery(query: ItemQuery<T>): ItemArray<T>;
|
|
52
52
|
getQuerySequence(query: ItemQuery<T>): AsyncIterable<ItemArray<T>>;
|
|
53
53
|
/** Subscribe to a query in this table, but only if the query has been explicitly set (i.e. has a time). */
|
|
54
54
|
getCachedQuerySequence(query: ItemQuery<T>): AsyncIterable<ItemArray<T>>;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
setQueryItemsSequence(query: ItemQuery<T>, sequence: AsyncIterable<ItemArray<T>>): AsyncIterable<ItemArray<T>>;
|
|
55
|
+
setItemArray(items: ItemArray<T>): number;
|
|
56
|
+
setItemArraySequence(sequence: AsyncIterable<ItemArray<T>>): AsyncIterable<ItemArray<T>>;
|
|
57
|
+
setQueryArray(query: ItemQuery<T>, items: ItemArray<T>): void;
|
|
58
|
+
setQueryArraySequence(query: ItemQuery<T>, sequence: AsyncIterable<ItemArray<T>>): AsyncIterable<ItemArray<T>>;
|
|
60
59
|
setQuery(query: ItemQuery<T>, data: T): number;
|
|
61
60
|
updateQuery(query: ItemQuery<T>, updates: Updates<T>): number;
|
|
62
61
|
deleteQuery(query: ItemQuery<T>): number;
|