shelving 1.91.2 → 1.92.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/Change.d.ts +19 -20
- package/db/Change.js +22 -21
- package/db/CollectionReference.d.ts +103 -0
- package/db/CollectionReference.js +127 -0
- package/db/Database.d.ts +21 -23
- package/db/Database.js +18 -18
- package/db/{Item.d.ts → ItemReference.d.ts} +13 -14
- package/db/{Item.js → ItemReference.js} +14 -17
- package/db/ItemState.d.ts +3 -3
- package/db/{Query.d.ts → QueryReference.d.ts} +25 -33
- package/db/QueryReference.js +101 -0
- package/db/QueryState.d.ts +10 -10
- package/db/QueryState.js +20 -18
- package/db/index.d.ts +3 -3
- package/db/index.js +3 -3
- package/firestore/client/FirestoreClientProvider.d.ts +13 -13
- package/firestore/client/FirestoreClientProvider.js +55 -84
- package/firestore/lite/FirestoreLiteProvider.d.ts +11 -11
- package/firestore/lite/FirestoreLiteProvider.js +52 -83
- package/firestore/server/FirestoreServerProvider.d.ts +13 -13
- package/firestore/server/FirestoreServerProvider.js +51 -84
- package/index.d.ts +0 -2
- package/index.js +0 -2
- package/package.json +1 -3
- package/provider/CacheProvider.d.ts +7 -7
- package/provider/CacheProvider.js +14 -14
- package/provider/DebugProvider.d.ts +11 -11
- package/provider/DebugProvider.js +28 -29
- package/provider/MemoryProvider.d.ts +17 -17
- package/provider/MemoryProvider.js +41 -43
- package/provider/Provider.d.ts +15 -15
- package/provider/ThroughProvider.d.ts +12 -12
- package/provider/ThroughProvider.js +20 -20
- package/provider/ValidationProvider.d.ts +11 -11
- package/provider/ValidationProvider.js +16 -12
- package/react/useData.d.ts +5 -5
- package/react/useData.js +2 -2
- package/state/DataState.d.ts +4 -8
- package/state/DataState.js +6 -16
- package/state/DictionaryState.d.ts +4 -6
- package/state/DictionaryState.js +4 -9
- package/test/basics.d.ts +1 -1
- package/test/people.d.ts +1 -1
- package/test/util.d.ts +1 -1
- package/test/util.js +1 -1
- package/util/data.d.ts +2 -2
- package/util/equal.js +5 -5
- package/util/hydrate.d.ts +13 -26
- package/util/hydrate.js +44 -60
- package/util/index.d.ts +2 -0
- package/util/index.js +2 -0
- package/util/iterate.d.ts +2 -0
- package/util/match.d.ts +2 -10
- package/util/match.js +4 -8
- package/util/query.d.ts +83 -0
- package/util/query.js +129 -0
- package/util/sort.d.ts +8 -15
- package/util/sort.js +15 -19
- package/util/transform.d.ts +26 -45
- package/util/transform.js +24 -29
- package/util/update.d.ts +22 -0
- package/util/update.js +42 -0
- package/util/validate.js +2 -2
- package/constraint/Constraint.d.ts +0 -7
- package/constraint/Constraint.js +0 -3
- package/constraint/Constraints.d.ts +0 -20
- package/constraint/Constraints.js +0 -34
- package/constraint/Filter.d.ts +0 -34
- package/constraint/Filter.js +0 -89
- package/constraint/Filters.d.ts +0 -27
- package/constraint/Filters.js +0 -41
- package/constraint/Sort.d.ts +0 -18
- package/constraint/Sort.js +0 -33
- package/constraint/Sorts.d.ts +0 -26
- package/constraint/Sorts.js +0 -47
- package/constraint/Statement.d.ts +0 -45
- package/constraint/Statement.js +0 -79
- package/constraint/index.d.ts +0 -7
- package/constraint/index.js +0 -7
- package/db/Collection.d.ts +0 -64
- package/db/Collection.js +0 -83
- package/db/Query.js +0 -94
- package/update/ArrayUpdate.d.ts +0 -17
- package/update/ArrayUpdate.js +0 -31
- package/update/DataUpdate.d.ts +0 -37
- package/update/DataUpdate.js +0 -44
- package/update/Delete.d.ts +0 -10
- package/update/Delete.js +0 -12
- package/update/DictionaryUpdate.d.ts +0 -31
- package/update/DictionaryUpdate.js +0 -62
- package/update/Increment.d.ts +0 -18
- package/update/Increment.js +0 -22
- package/update/Update.d.ts +0 -8
- package/update/Update.js +0 -6
- package/update/hydrations.d.ts +0 -3
- package/update/hydrations.js +0 -13
- package/update/index.d.ts +0 -7
- package/update/index.js +0 -7
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
|
-
import { Statement } from "../constraint/Statement.js";
|
|
3
2
|
/** Provider that logs operations to a source provider to the console. */
|
|
4
3
|
class AbstractDebugProvider {
|
|
5
4
|
async *getItemSequence(collection, id) {
|
|
@@ -16,11 +15,11 @@ class AbstractDebugProvider {
|
|
|
16
15
|
console.error("ITERATE", key, thrown);
|
|
17
16
|
}
|
|
18
17
|
}
|
|
19
|
-
async *getQuerySequence(collection,
|
|
20
|
-
const key = _getQueryKey(collection,
|
|
18
|
+
async *getQuerySequence(collection, query) {
|
|
19
|
+
const key = _getQueryKey(collection, query);
|
|
21
20
|
try {
|
|
22
21
|
console.log("ITERATE", key, "DATA:");
|
|
23
|
-
for await (const items of this.source.getQuerySequence(collection,
|
|
22
|
+
for await (const items of this.source.getQuerySequence(collection, query)) {
|
|
24
23
|
console.log("ITERATE", key, "ITEMS:", items);
|
|
25
24
|
yield items;
|
|
26
25
|
}
|
|
@@ -94,10 +93,10 @@ export class DebugProvider extends AbstractDebugProvider {
|
|
|
94
93
|
throw reason;
|
|
95
94
|
}
|
|
96
95
|
}
|
|
97
|
-
getQuery(collection,
|
|
98
|
-
const key = _getQueryKey(collection,
|
|
96
|
+
getQuery(collection, query) {
|
|
97
|
+
const key = _getQueryKey(collection, query);
|
|
99
98
|
try {
|
|
100
|
-
const items = this.source.getQuery(collection,
|
|
99
|
+
const items = this.source.getQuery(collection, query);
|
|
101
100
|
console.log("GET:", key, "ITEMS:", items);
|
|
102
101
|
return items;
|
|
103
102
|
}
|
|
@@ -106,10 +105,10 @@ export class DebugProvider extends AbstractDebugProvider {
|
|
|
106
105
|
throw reason;
|
|
107
106
|
}
|
|
108
107
|
}
|
|
109
|
-
setQuery(collection,
|
|
110
|
-
const key = _getQueryKey(collection,
|
|
108
|
+
setQuery(collection, query, data) {
|
|
109
|
+
const key = _getQueryKey(collection, query);
|
|
111
110
|
try {
|
|
112
|
-
const num = this.source.setQuery(collection,
|
|
111
|
+
const num = this.source.setQuery(collection, query, data);
|
|
113
112
|
console.log("SET:", key, "DATA:", data, "DONE:", num);
|
|
114
113
|
return num;
|
|
115
114
|
}
|
|
@@ -118,10 +117,10 @@ export class DebugProvider extends AbstractDebugProvider {
|
|
|
118
117
|
throw reason;
|
|
119
118
|
}
|
|
120
119
|
}
|
|
121
|
-
updateQuery(collection,
|
|
122
|
-
const key = _getQueryKey(collection,
|
|
120
|
+
updateQuery(collection, query, updates) {
|
|
121
|
+
const key = _getQueryKey(collection, query);
|
|
123
122
|
try {
|
|
124
|
-
const num = this.source.updateQuery(collection,
|
|
123
|
+
const num = this.source.updateQuery(collection, query, updates);
|
|
125
124
|
console.log("UPDATE:", key, "UPDATES:", updates, "DONE:", num);
|
|
126
125
|
return num;
|
|
127
126
|
}
|
|
@@ -130,10 +129,10 @@ export class DebugProvider extends AbstractDebugProvider {
|
|
|
130
129
|
throw reason;
|
|
131
130
|
}
|
|
132
131
|
}
|
|
133
|
-
deleteQuery(collection,
|
|
134
|
-
const key = _getQueryKey(collection,
|
|
132
|
+
deleteQuery(collection, query) {
|
|
133
|
+
const key = _getQueryKey(collection, query);
|
|
135
134
|
try {
|
|
136
|
-
const num = this.source.deleteQuery(collection,
|
|
135
|
+
const num = this.source.deleteQuery(collection, query);
|
|
137
136
|
console.log("DELETE:", key, "DONE:", num);
|
|
138
137
|
return num;
|
|
139
138
|
}
|
|
@@ -211,11 +210,11 @@ export class AsyncDebugProvider extends AbstractDebugProvider {
|
|
|
211
210
|
throw reason;
|
|
212
211
|
}
|
|
213
212
|
}
|
|
214
|
-
async getQuery(collection,
|
|
215
|
-
const key = _getQueryKey(collection,
|
|
213
|
+
async getQuery(collection, query) {
|
|
214
|
+
const key = _getQueryKey(collection, query);
|
|
216
215
|
try {
|
|
217
216
|
console.log("GET:", key);
|
|
218
|
-
const items = await this.source.getQuery(collection,
|
|
217
|
+
const items = await this.source.getQuery(collection, query);
|
|
219
218
|
console.log("GET:", key, "ITEMS:", items);
|
|
220
219
|
return items;
|
|
221
220
|
}
|
|
@@ -224,11 +223,11 @@ export class AsyncDebugProvider extends AbstractDebugProvider {
|
|
|
224
223
|
throw reason;
|
|
225
224
|
}
|
|
226
225
|
}
|
|
227
|
-
async setQuery(collection,
|
|
228
|
-
const key = _getQueryKey(collection,
|
|
226
|
+
async setQuery(collection, query, data) {
|
|
227
|
+
const key = _getQueryKey(collection, query);
|
|
229
228
|
try {
|
|
230
229
|
console.log("SET:", key, "DATA:", data);
|
|
231
|
-
const num = await this.source.setQuery(collection,
|
|
230
|
+
const num = await this.source.setQuery(collection, query, data);
|
|
232
231
|
console.log("SET:", key, "DATA:", data, "DONE:", num);
|
|
233
232
|
return num;
|
|
234
233
|
}
|
|
@@ -237,11 +236,11 @@ export class AsyncDebugProvider extends AbstractDebugProvider {
|
|
|
237
236
|
throw reason;
|
|
238
237
|
}
|
|
239
238
|
}
|
|
240
|
-
async updateQuery(collection,
|
|
241
|
-
const key = _getQueryKey(collection,
|
|
239
|
+
async updateQuery(collection, query, updates) {
|
|
240
|
+
const key = _getQueryKey(collection, query);
|
|
242
241
|
try {
|
|
243
242
|
console.log("UPDATE:", key, "UPDATES:", updates);
|
|
244
|
-
const num = await this.source.updateQuery(collection,
|
|
243
|
+
const num = await this.source.updateQuery(collection, query, updates);
|
|
245
244
|
console.log("UPDATE:", key, "UPDATES:", updates, "DONE:", num);
|
|
246
245
|
return num;
|
|
247
246
|
}
|
|
@@ -250,11 +249,11 @@ export class AsyncDebugProvider extends AbstractDebugProvider {
|
|
|
250
249
|
throw reason;
|
|
251
250
|
}
|
|
252
251
|
}
|
|
253
|
-
async deleteQuery(collection,
|
|
254
|
-
const key = _getQueryKey(collection,
|
|
252
|
+
async deleteQuery(collection, query) {
|
|
253
|
+
const key = _getQueryKey(collection, query);
|
|
255
254
|
try {
|
|
256
255
|
console.log("DELETE:", key);
|
|
257
|
-
const num = await this.source.deleteQuery(collection,
|
|
256
|
+
const num = await this.source.deleteQuery(collection, query);
|
|
258
257
|
console.log("DELETE:", key, "DONE:", num);
|
|
259
258
|
return num;
|
|
260
259
|
}
|
|
@@ -265,4 +264,4 @@ export class AsyncDebugProvider extends AbstractDebugProvider {
|
|
|
265
264
|
}
|
|
266
265
|
}
|
|
267
266
|
const _getItemKey = (collection, id) => `${collection}/${id}`;
|
|
268
|
-
const _getQueryKey = (collection,
|
|
267
|
+
const _getQueryKey = (collection, query) => `${collection}?${JSON.stringify(query)}`;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Provider } from "./Provider.js";
|
|
2
|
-
import type { ItemArray, ItemData,
|
|
3
|
-
import type { Updates } from "../update/DataUpdate.js";
|
|
2
|
+
import type { ItemArray, ItemData, ItemQuery, ItemValue } from "../db/ItemReference.js";
|
|
4
3
|
import type { Data } from "../util/data.js";
|
|
4
|
+
import type { Updates } from "../util/update.js";
|
|
5
5
|
import { DeferredSequence } from "../sequence/DeferredSequence.js";
|
|
6
6
|
/**
|
|
7
7
|
* Fast in-memory store for data.
|
|
@@ -20,12 +20,12 @@ export declare class MemoryProvider implements Provider {
|
|
|
20
20
|
setItem(collection: string, id: string, data: Data): void;
|
|
21
21
|
updateItem(collection: string, id: string, updates: Updates): void;
|
|
22
22
|
deleteItem(collection: string, id: string): void;
|
|
23
|
-
getQueryTime(collection: string,
|
|
24
|
-
getQuery(collection: string,
|
|
25
|
-
getQuerySequence(collection: string,
|
|
26
|
-
setQuery(collection: string,
|
|
27
|
-
updateQuery(collection: string,
|
|
28
|
-
deleteQuery(collection: string,
|
|
23
|
+
getQueryTime(collection: string, query: ItemQuery): number | null;
|
|
24
|
+
getQuery(collection: string, query: ItemQuery): ItemArray;
|
|
25
|
+
getQuerySequence(collection: string, query: ItemQuery): AsyncIterable<ItemArray>;
|
|
26
|
+
setQuery(collection: string, query: ItemQuery, data: Data): number;
|
|
27
|
+
updateQuery(collection: string, query: ItemQuery, updates: Updates): number;
|
|
28
|
+
deleteQuery(collection: string, query: ItemQuery): number;
|
|
29
29
|
}
|
|
30
30
|
/** An individual table of data. */
|
|
31
31
|
export declare class MemoryTable<T extends Data = Data> {
|
|
@@ -47,17 +47,17 @@ export declare class MemoryTable<T extends Data = Data> {
|
|
|
47
47
|
setItemValueSequence(id: string, sequence: AsyncIterable<ItemValue<T>>): AsyncIterable<ItemValue>;
|
|
48
48
|
updateItem(id: string, updates: Updates<T>): void;
|
|
49
49
|
deleteItem(id: string): void;
|
|
50
|
-
getQueryTime(
|
|
51
|
-
getQuery(
|
|
52
|
-
getQuerySequence(
|
|
50
|
+
getQueryTime(query: ItemQuery<T>): number | null;
|
|
51
|
+
getQuery(query: ItemQuery<T>): ItemArray<T>;
|
|
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
|
-
getCachedQuerySequence(
|
|
54
|
+
getCachedQuerySequence(query: ItemQuery<T>): AsyncIterable<ItemArray<T>>;
|
|
55
55
|
private _setItems;
|
|
56
56
|
setItems(items: ItemArray<T>): void;
|
|
57
57
|
setItemsSequence(sequence: AsyncIterable<ItemArray<T>>): AsyncIterable<ItemArray<T>>;
|
|
58
|
-
setQueryItems(
|
|
59
|
-
setQueryItemsSequence(
|
|
60
|
-
setQuery(
|
|
61
|
-
updateQuery(
|
|
62
|
-
deleteQuery(
|
|
58
|
+
setQueryItems(query: ItemQuery<T>, items: ItemArray<T>): void;
|
|
59
|
+
setQueryItemsSequence(query: ItemQuery<T>, sequence: AsyncIterable<ItemArray<T>>): AsyncIterable<ItemArray<T>>;
|
|
60
|
+
setQuery(query: ItemQuery<T>, data: T): number;
|
|
61
|
+
updateQuery(query: ItemQuery<T>, updates: Updates<T>): number;
|
|
62
|
+
deleteQuery(query: ItemQuery<T>): number;
|
|
63
63
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Statement } from "../constraint/Statement.js";
|
|
2
1
|
import { RequiredError } from "../error/RequiredError.js";
|
|
3
2
|
import { DeferredSequence } from "../sequence/DeferredSequence.js";
|
|
4
3
|
import { getArray } from "../util/array.js";
|
|
5
4
|
import { isArrayEqual } from "../util/equal.js";
|
|
5
|
+
import { queryItems, queryWritableItems } from "../util/query.js";
|
|
6
6
|
import { getRandomKey } from "../util/random.js";
|
|
7
|
-
import {
|
|
7
|
+
import { updateData } from "../util/update.js";
|
|
8
8
|
/**
|
|
9
9
|
* Fast in-memory store for data.
|
|
10
10
|
* - Extremely fast (ideal for caching!), but does not persist data after the browser window is closed.
|
|
@@ -40,23 +40,23 @@ export class MemoryProvider {
|
|
|
40
40
|
deleteItem(collection, id) {
|
|
41
41
|
return this.getTable(collection).deleteItem(id);
|
|
42
42
|
}
|
|
43
|
-
getQueryTime(collection,
|
|
44
|
-
return this.getTable(collection).getQueryTime(
|
|
43
|
+
getQueryTime(collection, query) {
|
|
44
|
+
return this.getTable(collection).getQueryTime(query);
|
|
45
45
|
}
|
|
46
|
-
getQuery(collection,
|
|
47
|
-
return this.getTable(collection).getQuery(
|
|
46
|
+
getQuery(collection, query) {
|
|
47
|
+
return this.getTable(collection).getQuery(query);
|
|
48
48
|
}
|
|
49
|
-
getQuerySequence(collection,
|
|
50
|
-
return this.getTable(collection).getQuerySequence(
|
|
49
|
+
getQuerySequence(collection, query) {
|
|
50
|
+
return this.getTable(collection).getQuerySequence(query);
|
|
51
51
|
}
|
|
52
|
-
setQuery(collection,
|
|
53
|
-
return this.getTable(collection).setQuery(
|
|
52
|
+
setQuery(collection, query, data) {
|
|
53
|
+
return this.getTable(collection).setQuery(query, data);
|
|
54
54
|
}
|
|
55
|
-
updateQuery(collection,
|
|
56
|
-
return this.getTable(collection).updateQuery(
|
|
55
|
+
updateQuery(collection, query, updates) {
|
|
56
|
+
return this.getTable(collection).updateQuery(query, updates);
|
|
57
57
|
}
|
|
58
|
-
deleteQuery(collection,
|
|
59
|
-
return this.getTable(collection).deleteQuery(
|
|
58
|
+
deleteQuery(collection, query) {
|
|
59
|
+
return this.getTable(collection).deleteQuery(query);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
/** An individual table of data. */
|
|
@@ -132,7 +132,7 @@ export class MemoryTable {
|
|
|
132
132
|
const oldItem = this._data.get(id);
|
|
133
133
|
if (!oldItem)
|
|
134
134
|
throw new RequiredError(`Document "${id}" does not exist`);
|
|
135
|
-
const newItem =
|
|
135
|
+
const newItem = updateData(oldItem, updates);
|
|
136
136
|
if (oldItem !== newItem) {
|
|
137
137
|
this._data.set(id, newItem);
|
|
138
138
|
this._times.set(id, Date.now());
|
|
@@ -146,34 +146,34 @@ export class MemoryTable {
|
|
|
146
146
|
this._changed.resolve();
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
-
getQueryTime(
|
|
150
|
-
return this._times.get(_getQueryKey(
|
|
149
|
+
getQueryTime(query) {
|
|
150
|
+
return this._times.get(_getQueryKey(query)) || null;
|
|
151
151
|
}
|
|
152
|
-
getQuery(
|
|
153
|
-
return getArray(
|
|
152
|
+
getQuery(query) {
|
|
153
|
+
return getArray(queryItems(this._data.values(), query));
|
|
154
154
|
}
|
|
155
|
-
async *getQuerySequence(
|
|
156
|
-
let last = this.getQuery(
|
|
155
|
+
async *getQuerySequence(query) {
|
|
156
|
+
let last = this.getQuery(query);
|
|
157
157
|
yield last;
|
|
158
158
|
while (true) {
|
|
159
159
|
await this._changed;
|
|
160
|
-
const next = this.getQuery(
|
|
160
|
+
const next = this.getQuery(query);
|
|
161
161
|
if (!isArrayEqual(last, next))
|
|
162
162
|
yield (last = next);
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
/** Subscribe to a query in this table, but only if the query has been explicitly set (i.e. has a time). */
|
|
166
|
-
async *getCachedQuerySequence(
|
|
167
|
-
const key = _getQueryKey(
|
|
166
|
+
async *getCachedQuerySequence(query) {
|
|
167
|
+
const key = _getQueryKey(query);
|
|
168
168
|
let last = undefined;
|
|
169
169
|
if (this._times.has(key)) {
|
|
170
|
-
last = this.getQuery(
|
|
170
|
+
last = this.getQuery(query);
|
|
171
171
|
yield last;
|
|
172
172
|
}
|
|
173
173
|
while (true) {
|
|
174
174
|
await this._changed;
|
|
175
175
|
if (this._times.has(key)) {
|
|
176
|
-
const next = this.getQuery(
|
|
176
|
+
const next = this.getQuery(query);
|
|
177
177
|
if (!last || !isArrayEqual(last, next))
|
|
178
178
|
yield (last = next);
|
|
179
179
|
}
|
|
@@ -194,15 +194,15 @@ export class MemoryTable {
|
|
|
194
194
|
yield items;
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
|
-
setQueryItems(
|
|
198
|
-
const key = _getQueryKey(
|
|
197
|
+
setQueryItems(query, items) {
|
|
198
|
+
const key = _getQueryKey(query);
|
|
199
199
|
const now = Date.now();
|
|
200
200
|
this._times.set(key, now);
|
|
201
201
|
this._setItems(items, now);
|
|
202
202
|
this._changed.resolve();
|
|
203
203
|
}
|
|
204
|
-
async *setQueryItemsSequence(
|
|
205
|
-
const key = _getQueryKey(
|
|
204
|
+
async *setQueryItemsSequence(query, sequence) {
|
|
205
|
+
const key = _getQueryKey(query);
|
|
206
206
|
for await (const items of sequence) {
|
|
207
207
|
const now = Date.now();
|
|
208
208
|
this._times.set(key, now);
|
|
@@ -211,26 +211,26 @@ export class MemoryTable {
|
|
|
211
211
|
yield items;
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
|
-
setQuery(
|
|
214
|
+
setQuery(query, data) {
|
|
215
215
|
const now = Date.now();
|
|
216
216
|
let count = 0;
|
|
217
|
-
for (const { id } of
|
|
217
|
+
for (const { id } of queryWritableItems(this._data.values(), query)) {
|
|
218
218
|
this._data.set(id, { ...data, id });
|
|
219
219
|
this._times.set(id, now);
|
|
220
220
|
count++;
|
|
221
221
|
}
|
|
222
222
|
if (count) {
|
|
223
|
-
const key = _getQueryKey(
|
|
223
|
+
const key = _getQueryKey(query);
|
|
224
224
|
this._times.set(key, now);
|
|
225
225
|
this._changed.resolve();
|
|
226
226
|
}
|
|
227
227
|
return count;
|
|
228
228
|
}
|
|
229
|
-
updateQuery(
|
|
229
|
+
updateQuery(query, updates) {
|
|
230
230
|
const now = Date.now();
|
|
231
231
|
let count = 0;
|
|
232
|
-
for (const oldItem of
|
|
233
|
-
const newItem =
|
|
232
|
+
for (const oldItem of queryWritableItems(this._data.values(), query)) {
|
|
233
|
+
const newItem = updateData(oldItem, updates);
|
|
234
234
|
if (oldItem !== newItem) {
|
|
235
235
|
const id = oldItem.id;
|
|
236
236
|
this._data.set(id, newItem);
|
|
@@ -239,29 +239,27 @@ export class MemoryTable {
|
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
241
|
if (count) {
|
|
242
|
-
const key = _getQueryKey(
|
|
242
|
+
const key = _getQueryKey(query);
|
|
243
243
|
this._times.set(key, now);
|
|
244
244
|
this._changed.resolve();
|
|
245
245
|
}
|
|
246
246
|
return count;
|
|
247
247
|
}
|
|
248
|
-
deleteQuery(
|
|
248
|
+
deleteQuery(query) {
|
|
249
249
|
const now = Date.now();
|
|
250
250
|
let count = 0;
|
|
251
|
-
for (const { id } of
|
|
251
|
+
for (const { id } of queryWritableItems(this._data.values(), query)) {
|
|
252
252
|
this._data.delete(id);
|
|
253
253
|
this._times.set(id, now);
|
|
254
254
|
count++;
|
|
255
255
|
}
|
|
256
256
|
if (count) {
|
|
257
|
-
const key = _getQueryKey(
|
|
257
|
+
const key = _getQueryKey(query);
|
|
258
258
|
this._times.set(key, now);
|
|
259
259
|
this._changed.resolve();
|
|
260
260
|
}
|
|
261
261
|
return count;
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
|
-
// When we're writing data, if there's no limit set the results don't need to be sorted (for performance).
|
|
265
|
-
const _getWriteConstraints = (statement) => (statement.limit ? statement : statement.filters);
|
|
266
264
|
// Queries that have no limit don't care about sorting either.
|
|
267
|
-
const _getQueryKey = (
|
|
265
|
+
const _getQueryKey = (query) => JSON.stringify(query);
|
package/provider/Provider.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ItemArray,
|
|
2
|
-
import type { Updates } from "../update/DataUpdate.js";
|
|
1
|
+
import type { ItemArray, ItemQuery, ItemValue } from "../db/ItemReference.js";
|
|
3
2
|
import type { Data } from "../util/data.js";
|
|
3
|
+
import type { Updates } from "../util/update.js";
|
|
4
4
|
/** Provides access to data (e.g. IndexedDB, Firebase, or in-memory cache providers). */
|
|
5
5
|
declare abstract class AbstractProvider {
|
|
6
6
|
/**
|
|
@@ -42,30 +42,30 @@ declare abstract class AbstractProvider {
|
|
|
42
42
|
*
|
|
43
43
|
* @return Set of values in `id: data` format.
|
|
44
44
|
*/
|
|
45
|
-
abstract getQuery(collection: string,
|
|
45
|
+
abstract getQuery(collection: string, query: ItemQuery): ItemArray | PromiseLike<ItemArray>;
|
|
46
46
|
/**
|
|
47
47
|
* Subscribe to all matching items with an async iterator.
|
|
48
48
|
*/
|
|
49
|
-
abstract getQuerySequence(collection: string,
|
|
49
|
+
abstract getQuerySequence(collection: string, query: ItemQuery): AsyncIterable<ItemArray>;
|
|
50
50
|
/**
|
|
51
51
|
* Set the data of all matching items.
|
|
52
52
|
*
|
|
53
53
|
* @param data Data to set matching items to.
|
|
54
54
|
* @return Number of items that were set.
|
|
55
55
|
*/
|
|
56
|
-
abstract setQuery(collection: string,
|
|
56
|
+
abstract setQuery(collection: string, query: ItemQuery, data: Data): number | PromiseLike<number>;
|
|
57
57
|
/**
|
|
58
58
|
* Update the data of all matching items.
|
|
59
59
|
*
|
|
60
60
|
* @param updates Set of property updates to apply to matching items.
|
|
61
61
|
* @return Number of items that were updated.
|
|
62
62
|
*/
|
|
63
|
-
abstract updateQuery(collection: string,
|
|
63
|
+
abstract updateQuery(collection: string, query: ItemQuery, updates: Updates): number | PromiseLike<number>;
|
|
64
64
|
/**
|
|
65
65
|
* Delete all matching items.
|
|
66
66
|
* @return Number of items that were deleted.
|
|
67
67
|
*/
|
|
68
|
-
abstract deleteQuery(collection: string,
|
|
68
|
+
abstract deleteQuery(collection: string, query: ItemQuery): number | PromiseLike<number>;
|
|
69
69
|
}
|
|
70
70
|
/** Provider with a fully synchronous interface */
|
|
71
71
|
export declare abstract class Provider extends AbstractProvider {
|
|
@@ -74,10 +74,10 @@ export declare abstract class Provider extends AbstractProvider {
|
|
|
74
74
|
abstract setItem(collection: string, id: string, data: Data): void;
|
|
75
75
|
abstract updateItem(collection: string, id: string, updates: Updates): void;
|
|
76
76
|
abstract deleteItem(collection: string, id: string): void;
|
|
77
|
-
abstract getQuery(collection: string,
|
|
78
|
-
abstract setQuery(collection: string,
|
|
79
|
-
abstract updateQuery(collection: string,
|
|
80
|
-
abstract deleteQuery(collection: string,
|
|
77
|
+
abstract getQuery(collection: string, query: ItemQuery): ItemArray;
|
|
78
|
+
abstract setQuery(collection: string, query: ItemQuery, data: Data): number;
|
|
79
|
+
abstract updateQuery(collection: string, query: ItemQuery, updates: Updates): number;
|
|
80
|
+
abstract deleteQuery(collection: string, query: ItemQuery): number;
|
|
81
81
|
}
|
|
82
82
|
/** Provider with a fully asynchronous interface */
|
|
83
83
|
export declare abstract class AsyncProvider extends AbstractProvider {
|
|
@@ -86,9 +86,9 @@ export declare abstract class AsyncProvider extends AbstractProvider {
|
|
|
86
86
|
abstract setItem(collection: string, id: string, data: Data): Promise<void>;
|
|
87
87
|
abstract updateItem(collection: string, id: string, updates: Updates): Promise<void>;
|
|
88
88
|
abstract deleteItem(collection: string, id: string): Promise<void>;
|
|
89
|
-
abstract getQuery(collection: string,
|
|
90
|
-
abstract setQuery(collection: string,
|
|
91
|
-
abstract updateQuery(collection: string,
|
|
92
|
-
abstract deleteQuery(collection: string,
|
|
89
|
+
abstract getQuery(collection: string, query: ItemQuery): Promise<ItemArray>;
|
|
90
|
+
abstract setQuery(collection: string, query: ItemQuery, data: Data): Promise<number>;
|
|
91
|
+
abstract updateQuery(collection: string, query: ItemQuery, updates: Updates): Promise<number>;
|
|
92
|
+
abstract deleteQuery(collection: string, query: ItemQuery): Promise<number>;
|
|
93
93
|
}
|
|
94
94
|
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { AsyncProvider, Provider } from "./Provider.js";
|
|
2
|
-
import type { ItemArray,
|
|
3
|
-
import type { Updates } from "../update/DataUpdate.js";
|
|
2
|
+
import type { ItemArray, ItemQuery, ItemValue } from "../db/ItemReference.js";
|
|
4
3
|
import type { Data } from "../util/data.js";
|
|
5
4
|
import type { Sourceable } from "../util/source.js";
|
|
5
|
+
import type { Updates } from "../util/update.js";
|
|
6
6
|
/** A provider that passes through to a synchronous source. */
|
|
7
7
|
export declare class ThroughProvider implements Provider, Sourceable<Provider> {
|
|
8
8
|
readonly source: Provider;
|
|
@@ -13,11 +13,11 @@ export declare class ThroughProvider implements Provider, Sourceable<Provider> {
|
|
|
13
13
|
setItem(collection: string, id: string, data: Data): void;
|
|
14
14
|
updateItem(collection: string, id: string, update: Updates): void;
|
|
15
15
|
deleteItem(collection: string, id: string): void;
|
|
16
|
-
getQuery(collection: string,
|
|
17
|
-
getQuerySequence(collection: string,
|
|
18
|
-
setQuery(collection: string,
|
|
19
|
-
updateQuery(collection: string,
|
|
20
|
-
deleteQuery(collection: string,
|
|
16
|
+
getQuery(collection: string, query: ItemQuery): ItemArray;
|
|
17
|
+
getQuerySequence(collection: string, query: ItemQuery): AsyncIterable<ItemArray>;
|
|
18
|
+
setQuery(collection: string, query: ItemQuery, data: Data): number;
|
|
19
|
+
updateQuery(collection: string, query: ItemQuery, update: Updates): number;
|
|
20
|
+
deleteQuery(collection: string, query: ItemQuery): number;
|
|
21
21
|
}
|
|
22
22
|
/** A provider that passes through to an asynchronous source. */
|
|
23
23
|
export declare class AsyncThroughProvider implements AsyncProvider, Sourceable<AsyncProvider> {
|
|
@@ -29,9 +29,9 @@ export declare class AsyncThroughProvider implements AsyncProvider, Sourceable<A
|
|
|
29
29
|
setItem(collection: string, id: string, data: Data): Promise<void>;
|
|
30
30
|
updateItem(collection: string, id: string, updates: Updates): Promise<void>;
|
|
31
31
|
deleteItem(collection: string, id: string): Promise<void>;
|
|
32
|
-
getQuery(collection: string,
|
|
33
|
-
getQuerySequence(collection: string,
|
|
34
|
-
setQuery(collection: string,
|
|
35
|
-
updateQuery(collection: string,
|
|
36
|
-
deleteQuery(collection: string,
|
|
32
|
+
getQuery(collection: string, query: ItemQuery): Promise<ItemArray>;
|
|
33
|
+
getQuerySequence(collection: string, query: ItemQuery): AsyncIterable<ItemArray>;
|
|
34
|
+
setQuery(collection: string, query: ItemQuery, data: Data): Promise<number>;
|
|
35
|
+
updateQuery(collection: string, query: ItemQuery, updates: Updates): Promise<number>;
|
|
36
|
+
deleteQuery(collection: string, query: ItemQuery): Promise<number>;
|
|
37
37
|
}
|
|
@@ -21,20 +21,20 @@ export class ThroughProvider {
|
|
|
21
21
|
deleteItem(collection, id) {
|
|
22
22
|
return this.source.deleteItem(collection, id);
|
|
23
23
|
}
|
|
24
|
-
getQuery(collection,
|
|
25
|
-
return this.source.getQuery(collection,
|
|
24
|
+
getQuery(collection, query) {
|
|
25
|
+
return this.source.getQuery(collection, query);
|
|
26
26
|
}
|
|
27
|
-
getQuerySequence(collection,
|
|
28
|
-
return this.source.getQuerySequence(collection,
|
|
27
|
+
getQuerySequence(collection, query) {
|
|
28
|
+
return this.source.getQuerySequence(collection, query);
|
|
29
29
|
}
|
|
30
|
-
setQuery(collection,
|
|
31
|
-
return this.source.setQuery(collection,
|
|
30
|
+
setQuery(collection, query, data) {
|
|
31
|
+
return this.source.setQuery(collection, query, data);
|
|
32
32
|
}
|
|
33
|
-
updateQuery(collection,
|
|
34
|
-
return this.source.updateQuery(collection,
|
|
33
|
+
updateQuery(collection, query, update) {
|
|
34
|
+
return this.source.updateQuery(collection, query, update);
|
|
35
35
|
}
|
|
36
|
-
deleteQuery(collection,
|
|
37
|
-
return this.source.deleteQuery(collection,
|
|
36
|
+
deleteQuery(collection, query) {
|
|
37
|
+
return this.source.deleteQuery(collection, query);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
/** A provider that passes through to an asynchronous source. */
|
|
@@ -60,19 +60,19 @@ export class AsyncThroughProvider {
|
|
|
60
60
|
deleteItem(collection, id) {
|
|
61
61
|
return this.source.deleteItem(collection, id);
|
|
62
62
|
}
|
|
63
|
-
getQuery(collection,
|
|
64
|
-
return this.source.getQuery(collection,
|
|
63
|
+
getQuery(collection, query) {
|
|
64
|
+
return this.source.getQuery(collection, query);
|
|
65
65
|
}
|
|
66
|
-
getQuerySequence(collection,
|
|
67
|
-
return this.source.getQuerySequence(collection,
|
|
66
|
+
getQuerySequence(collection, query) {
|
|
67
|
+
return this.source.getQuerySequence(collection, query);
|
|
68
68
|
}
|
|
69
|
-
setQuery(collection,
|
|
70
|
-
return this.source.setQuery(collection,
|
|
69
|
+
setQuery(collection, query, data) {
|
|
70
|
+
return this.source.setQuery(collection, query, data);
|
|
71
71
|
}
|
|
72
|
-
updateQuery(collection,
|
|
73
|
-
return this.source.updateQuery(collection,
|
|
72
|
+
updateQuery(collection, query, updates) {
|
|
73
|
+
return this.source.updateQuery(collection, query, updates);
|
|
74
74
|
}
|
|
75
|
-
deleteQuery(collection,
|
|
76
|
-
return this.source.deleteQuery(collection,
|
|
75
|
+
deleteQuery(collection, query) {
|
|
76
|
+
return this.source.deleteQuery(collection, query);
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { AsyncProvider, Provider } from "./Provider.js";
|
|
2
|
-
import type { ItemArray,
|
|
2
|
+
import type { ItemArray, ItemQuery, ItemValue } from "../db/ItemReference.js";
|
|
3
3
|
import type { DataSchema, DataSchemas } from "../schema/DataSchema.js";
|
|
4
|
-
import type { Updates } from "../update/DataUpdate.js";
|
|
5
4
|
import type { DataKey, Datas } from "../util/data.js";
|
|
6
5
|
import type { Sourceable } from "../util/source.js";
|
|
6
|
+
import type { Updates } from "../util/update.js";
|
|
7
7
|
/** Validate a source provider (source can have any type because validation guarantees the type). */
|
|
8
8
|
declare abstract class BaseValidationProvider<T extends Datas> {
|
|
9
9
|
abstract source: Provider | AsyncProvider;
|
|
@@ -11,7 +11,7 @@ declare abstract class BaseValidationProvider<T extends Datas> {
|
|
|
11
11
|
constructor(schemas: DataSchemas<T>);
|
|
12
12
|
getSchema<K extends DataKey<T>>(collection: K): DataSchema<T[K]>;
|
|
13
13
|
getItemSequence<K extends DataKey<T>>(collection: K, id: string): AsyncIterable<ItemValue<T[K]>>;
|
|
14
|
-
getQuerySequence<K extends DataKey<T>>(collection: K, constraints:
|
|
14
|
+
getQuerySequence<K extends DataKey<T>>(collection: K, constraints: ItemQuery<T[K]>): AsyncIterable<ItemArray<T[K]>>;
|
|
15
15
|
}
|
|
16
16
|
/** Validate a synchronous source provider (source can have any type because validation guarantees the type). */
|
|
17
17
|
export declare class ValidationProvider<T extends Datas> extends BaseValidationProvider<T> implements Provider, Sourceable<Provider> {
|
|
@@ -22,10 +22,10 @@ export declare class ValidationProvider<T extends Datas> extends BaseValidationP
|
|
|
22
22
|
setItem<K extends DataKey<T>>(collection: K, id: string, value: T[K]): void;
|
|
23
23
|
updateItem<K extends DataKey<T>>(collection: K, id: string, updates: Updates<T[K]>): void;
|
|
24
24
|
deleteItem<K extends DataKey<T>>(collection: K, id: string): void;
|
|
25
|
-
getQuery<K extends DataKey<T>>(collection: K, constraints:
|
|
26
|
-
setQuery<K extends DataKey<T>>(collection: K, constraints:
|
|
27
|
-
updateQuery<K extends DataKey<T>>(collection: K, constraints:
|
|
28
|
-
deleteQuery<K extends DataKey<T>>(collection: K, constraints:
|
|
25
|
+
getQuery<K extends DataKey<T>>(collection: K, constraints: ItemQuery<T[K]>): ItemArray<T[K]>;
|
|
26
|
+
setQuery<K extends DataKey<T>>(collection: K, constraints: ItemQuery<T[K]>, value: T[K]): number;
|
|
27
|
+
updateQuery<K extends DataKey<T>>(collection: K, constraints: ItemQuery<T[K]>, updates: Updates<T[K]>): number;
|
|
28
|
+
deleteQuery<K extends DataKey<T>>(collection: K, constraints: ItemQuery<T[K]>): number;
|
|
29
29
|
}
|
|
30
30
|
/** Validate an asynchronous source provider (source can have any type because validation guarantees the type). */
|
|
31
31
|
export declare class AsyncValidationProvider<T extends Datas> extends BaseValidationProvider<T> implements AsyncProvider, Sourceable<AsyncProvider> {
|
|
@@ -36,9 +36,9 @@ export declare class AsyncValidationProvider<T extends Datas> extends BaseValida
|
|
|
36
36
|
setItem<K extends DataKey<T>>(collection: K, id: string, value: T[K]): Promise<void>;
|
|
37
37
|
updateItem<K extends DataKey<T>>(collection: K, id: string, updates: Updates<T[K]>): Promise<void>;
|
|
38
38
|
deleteItem<K extends DataKey<T>>(collection: K, id: string): Promise<void>;
|
|
39
|
-
getQuery<K extends DataKey<T>>(collection: K, constraints:
|
|
40
|
-
setQuery<K extends DataKey<T>>(collection: K, constraints:
|
|
41
|
-
updateQuery<K extends DataKey<T>>(collection: K, constraints:
|
|
42
|
-
deleteQuery<K extends DataKey<T>>(collection: K, constraints:
|
|
39
|
+
getQuery<K extends DataKey<T>>(collection: K, constraints: ItemQuery<T[K]>): Promise<ItemArray<T[K]>>;
|
|
40
|
+
setQuery<K extends DataKey<T>>(collection: K, constraints: ItemQuery<T[K]>, value: T[K]): Promise<number>;
|
|
41
|
+
updateQuery<K extends DataKey<T>>(collection: K, constraints: ItemQuery<T[K]>, updates: Updates<T[K]>): Promise<number>;
|
|
42
|
+
deleteQuery<K extends DataKey<T>>(collection: K, constraints: ItemQuery<T[K]>): Promise<number>;
|
|
43
43
|
}
|
|
44
44
|
export {};
|