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,44 +1,38 @@
|
|
|
1
|
-
import { addDoc,
|
|
1
|
+
import { addDoc, collection, deleteDoc, doc, documentId, getDoc, getDocs, increment, limit, orderBy, query, setDoc, updateDoc, where } from "firebase/firestore/lite";
|
|
2
2
|
import { UnsupportedError } from "../../error/UnsupportedError.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { Increment } from "../../update/Increment.js";
|
|
8
|
-
import { Update } from "../../update/Update.js";
|
|
3
|
+
import { getObject } from "../../util/object.js";
|
|
4
|
+
import { getFilters, getSorts } from "../../util/query.js";
|
|
5
|
+
import { mapItems } from "../../util/transform.js";
|
|
6
|
+
import { getUpdates } from "../../util/update.js";
|
|
9
7
|
// Constants.
|
|
10
|
-
const ID =
|
|
8
|
+
const ID = documentId();
|
|
11
9
|
// Map `Filter.types` to `WhereFilterOp`
|
|
12
10
|
const OPERATORS = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
// Map `Filter.types` to `OrderByDirection`
|
|
24
|
-
const DIRECTIONS = {
|
|
25
|
-
ASC: "asc",
|
|
26
|
-
DESC: "desc",
|
|
11
|
+
is: "==",
|
|
12
|
+
not: "!=",
|
|
13
|
+
in: "in",
|
|
14
|
+
out: "not-in",
|
|
15
|
+
contains: "array-contains",
|
|
16
|
+
gt: ">",
|
|
17
|
+
gte: ">=",
|
|
18
|
+
lt: "<",
|
|
19
|
+
lte: "<=",
|
|
27
20
|
};
|
|
28
21
|
/** Create a corresponding `QueryReference` from a Query. */
|
|
29
|
-
function _getQuery(firestore,
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
function* _yieldConstraints({ sorts, filters, limit }) {
|
|
33
|
-
for (const { key, direction } of sorts)
|
|
34
|
-
yield firestoreOrderBy(key === "id" ? ID : key, DIRECTIONS[direction]);
|
|
35
|
-
for (const { operator, key, value } of filters)
|
|
36
|
-
yield firestoreWhere(key === "id" ? ID : key, OPERATORS[operator], value);
|
|
37
|
-
if (typeof limit === "number")
|
|
38
|
-
yield firestoreLimit(limit);
|
|
22
|
+
function _getQuery(firestore, c, q) {
|
|
23
|
+
return query(collection(firestore, c), ..._getConstraints(q));
|
|
39
24
|
}
|
|
40
|
-
function
|
|
41
|
-
|
|
25
|
+
function* _getConstraints(q) {
|
|
26
|
+
for (const { keys, direction } of getSorts(q)) {
|
|
27
|
+
const key = keys.join(".");
|
|
28
|
+
yield orderBy(key === "id" ? ID : key, direction);
|
|
29
|
+
}
|
|
30
|
+
for (const { keys, operator, value } of getFilters(q)) {
|
|
31
|
+
const key = keys.join(".");
|
|
32
|
+
yield where(key === "id" ? ID : key, OPERATORS[operator], value);
|
|
33
|
+
}
|
|
34
|
+
if (typeof q.$limit === "number")
|
|
35
|
+
yield limit(q.$limit);
|
|
42
36
|
}
|
|
43
37
|
function _getItemData(snapshot) {
|
|
44
38
|
const data = snapshot.data();
|
|
@@ -48,35 +42,9 @@ function _getItemValue(snapshot) {
|
|
|
48
42
|
const data = snapshot.data();
|
|
49
43
|
return data ? { ...data, id: snapshot.id } : null;
|
|
50
44
|
}
|
|
51
|
-
/** Convert `
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (update instanceof DataUpdate || update instanceof DictionaryUpdate) {
|
|
55
|
-
yield* _getFieldValues(update, `${prefix}${key}.`);
|
|
56
|
-
}
|
|
57
|
-
else if (update instanceof ArrayUpdate) {
|
|
58
|
-
if (update.adds.length) {
|
|
59
|
-
yield `${prefix}${key}`;
|
|
60
|
-
yield firestoreArrayUnion(...update.adds);
|
|
61
|
-
}
|
|
62
|
-
if (update.deletes.length) {
|
|
63
|
-
yield `${prefix}${key}`;
|
|
64
|
-
yield firestoreArrayRemove(...update.deletes);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
yield `${prefix}${key}`;
|
|
69
|
-
if (!(update instanceof Update))
|
|
70
|
-
yield update;
|
|
71
|
-
else if (update instanceof Delete)
|
|
72
|
-
yield firestoreDeleteField();
|
|
73
|
-
else if (update instanceof Increment)
|
|
74
|
-
yield firestoreIncrement(update.amount);
|
|
75
|
-
else
|
|
76
|
-
yield update.transform();
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
45
|
+
/** Convert `Updates` object into corresponding Firestore `FieldValue` instances. */
|
|
46
|
+
const _getFieldValues = (updates) => getObject(mapItems(getUpdates(updates), _getFieldValue));
|
|
47
|
+
const _getFieldValue = ({ keys, action, value }) => [keys.join("."), action === "sum" ? increment(value) : action === "set" ? value : action];
|
|
80
48
|
/**
|
|
81
49
|
* Firestore Lite client database provider.
|
|
82
50
|
* - Works with the Firebase JS SDK.
|
|
@@ -87,44 +55,45 @@ export class FirestoreLiteProvider {
|
|
|
87
55
|
constructor(firestore) {
|
|
88
56
|
this._firestore = firestore;
|
|
89
57
|
}
|
|
90
|
-
async getItem(
|
|
91
|
-
return _getItemValue(await getDoc(
|
|
58
|
+
async getItem(c, id) {
|
|
59
|
+
return _getItemValue(await getDoc(doc(this._firestore, c, id)));
|
|
92
60
|
}
|
|
93
61
|
getItemSequence() {
|
|
94
62
|
throw new UnsupportedError("FirestoreLiteProvider does not support realtime subscriptions");
|
|
95
63
|
}
|
|
96
|
-
async addItem(
|
|
97
|
-
const reference = await addDoc(
|
|
64
|
+
async addItem(c, data) {
|
|
65
|
+
const reference = await addDoc(collection(this._firestore, c), data);
|
|
98
66
|
return reference.id;
|
|
99
67
|
}
|
|
100
|
-
async setItem(
|
|
101
|
-
await setDoc(
|
|
68
|
+
async setItem(c, id, data) {
|
|
69
|
+
await setDoc(doc(this._firestore, c, id), data);
|
|
102
70
|
}
|
|
103
|
-
async updateItem(
|
|
104
|
-
await updateDoc(
|
|
71
|
+
async updateItem(c, id, updates) {
|
|
72
|
+
await updateDoc(doc(this._firestore, c, id), _getFieldValues(updates));
|
|
105
73
|
}
|
|
106
|
-
async deleteItem(
|
|
107
|
-
await deleteDoc(
|
|
74
|
+
async deleteItem(c, id) {
|
|
75
|
+
await deleteDoc(doc(this._firestore, c, id));
|
|
108
76
|
}
|
|
109
|
-
async getQuery(
|
|
110
|
-
|
|
77
|
+
async getQuery(c, q) {
|
|
78
|
+
const snapshot = await getDocs(_getQuery(this._firestore, c, q));
|
|
79
|
+
return snapshot.docs.map(_getItemData);
|
|
111
80
|
}
|
|
112
81
|
getQuerySequence() {
|
|
113
82
|
throw new UnsupportedError("FirestoreLiteProvider does not support realtime subscriptions");
|
|
114
83
|
}
|
|
115
|
-
async setQuery(
|
|
116
|
-
const snapshot = await getDocs(_getQuery(this._firestore,
|
|
84
|
+
async setQuery(c, q, data) {
|
|
85
|
+
const snapshot = await getDocs(_getQuery(this._firestore, c, q));
|
|
117
86
|
await Promise.all(snapshot.docs.map(s => setDoc(s.ref, data)));
|
|
118
87
|
return snapshot.size;
|
|
119
88
|
}
|
|
120
|
-
async updateQuery(
|
|
121
|
-
const snapshot = await getDocs(_getQuery(this._firestore,
|
|
122
|
-
const fieldValues =
|
|
123
|
-
await Promise.all(snapshot.docs.map(s => updateDoc(s.ref,
|
|
89
|
+
async updateQuery(c, q, updates) {
|
|
90
|
+
const snapshot = await getDocs(_getQuery(this._firestore, c, q));
|
|
91
|
+
const fieldValues = _getFieldValues(updates);
|
|
92
|
+
await Promise.all(snapshot.docs.map(s => updateDoc(s.ref, fieldValues)));
|
|
124
93
|
return snapshot.size;
|
|
125
94
|
}
|
|
126
|
-
async deleteQuery(
|
|
127
|
-
const snapshot = await getDocs(_getQuery(this._firestore,
|
|
95
|
+
async deleteQuery(c, q) {
|
|
96
|
+
const snapshot = await getDocs(_getQuery(this._firestore, c, q));
|
|
128
97
|
await Promise.all(snapshot.docs.map(s => deleteDoc(s.ref)));
|
|
129
98
|
return snapshot.size;
|
|
130
99
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ItemArray,
|
|
1
|
+
import type { ItemArray, ItemQuery, ItemValue } from "../../db/ItemReference.js";
|
|
2
2
|
import type { AsyncProvider } from "../../provider/Provider.js";
|
|
3
|
-
import type { Updates } from "../../update/DataUpdate.js";
|
|
4
3
|
import type { Data } from "../../util/data.js";
|
|
4
|
+
import type { Updates } from "../../util/update.js";
|
|
5
5
|
import { Firestore } from "@google-cloud/firestore";
|
|
6
6
|
/**
|
|
7
7
|
* Firestore server database provider.
|
|
@@ -10,15 +10,15 @@ import { Firestore } from "@google-cloud/firestore";
|
|
|
10
10
|
export declare class FirestoreServerProvider implements AsyncProvider {
|
|
11
11
|
private readonly _firestore;
|
|
12
12
|
constructor(firestore?: Firestore);
|
|
13
|
-
getItem(
|
|
14
|
-
getItemSequence(
|
|
15
|
-
addItem(
|
|
16
|
-
setItem(
|
|
17
|
-
updateItem(
|
|
18
|
-
deleteItem(
|
|
19
|
-
getQuery(
|
|
20
|
-
getQuerySequence<K extends string>(
|
|
21
|
-
setQuery(
|
|
22
|
-
updateQuery(
|
|
23
|
-
deleteQuery(
|
|
13
|
+
getItem(c: string, id: string): Promise<ItemValue>;
|
|
14
|
+
getItemSequence(c: string, id: string): AsyncIterable<ItemValue>;
|
|
15
|
+
addItem(c: string, data: Data): Promise<string>;
|
|
16
|
+
setItem(c: string, id: string, data: Data): Promise<void>;
|
|
17
|
+
updateItem(c: string, id: string, updates: Updates): Promise<void>;
|
|
18
|
+
deleteItem(c: string, id: string): Promise<void>;
|
|
19
|
+
getQuery(c: string, q: ItemQuery): Promise<ItemArray>;
|
|
20
|
+
getQuerySequence<K extends string>(c: K, q: ItemQuery): AsyncIterable<ItemArray>;
|
|
21
|
+
setQuery(c: string, q: ItemQuery, data: Data): Promise<number>;
|
|
22
|
+
updateQuery(c: string, q: ItemQuery, updates: Updates): Promise<number>;
|
|
23
|
+
deleteQuery(c: string, q: ItemQuery): Promise<number>;
|
|
24
24
|
}
|
|
@@ -1,40 +1,36 @@
|
|
|
1
1
|
import { FieldPath, FieldValue, Firestore } from "@google-cloud/firestore";
|
|
2
2
|
import { LazyDeferredSequence } from "../../sequence/LazyDeferredSequence.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { Increment } from "../../update/Increment.js";
|
|
8
|
-
import { Update } from "../../update/Update.js";
|
|
3
|
+
import { getObject } from "../../util/object.js";
|
|
4
|
+
import { getFilters, getSorts } from "../../util/query.js";
|
|
5
|
+
import { mapItems } from "../../util/transform.js";
|
|
6
|
+
import { getUpdates } from "../../util/update.js";
|
|
9
7
|
// Constants.
|
|
10
8
|
const ID = FieldPath.documentId();
|
|
11
9
|
// Map `Filter.types` to `WhereFilterOp`
|
|
12
10
|
const OPERATORS = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
// Map `Filter.types` to `OrderByDirection`
|
|
24
|
-
const DIRECTIONS = {
|
|
25
|
-
ASC: "asc",
|
|
26
|
-
DESC: "desc",
|
|
11
|
+
is: "==",
|
|
12
|
+
not: "!=",
|
|
13
|
+
in: "in",
|
|
14
|
+
out: "not-in",
|
|
15
|
+
contains: "array-contains",
|
|
16
|
+
gt: ">",
|
|
17
|
+
gte: ">=",
|
|
18
|
+
lt: "<",
|
|
19
|
+
lte: "<=",
|
|
27
20
|
};
|
|
28
21
|
/** Create a corresponding `QueryReference` from a Query. */
|
|
29
|
-
function _getQuery(firestore,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
query = query.orderBy(key === "id" ? ID : key,
|
|
34
|
-
|
|
22
|
+
function _getQuery(firestore, c, q) {
|
|
23
|
+
let query = firestore.collection(c);
|
|
24
|
+
for (const { keys, direction } of getSorts(q)) {
|
|
25
|
+
const key = keys.join(".");
|
|
26
|
+
query = query.orderBy(key === "id" ? ID : key, direction);
|
|
27
|
+
}
|
|
28
|
+
for (const { keys, operator, value } of getFilters(q)) {
|
|
29
|
+
const key = keys.join(".");
|
|
35
30
|
query = query.where(key === "id" ? ID : key, OPERATORS[operator], value);
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
}
|
|
32
|
+
if (typeof q.$limit === "number")
|
|
33
|
+
query = query.limit(q.$limit);
|
|
38
34
|
return query;
|
|
39
35
|
}
|
|
40
36
|
function _getItemArray(snapshot) {
|
|
@@ -49,34 +45,8 @@ function _getItemValue(snapshot) {
|
|
|
49
45
|
return data ? { ...data, id: snapshot.id } : null;
|
|
50
46
|
}
|
|
51
47
|
/** Convert `Update` instances into corresponding Firestore `FieldValue` instances. */
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (update instanceof DataUpdate || update instanceof DictionaryUpdate) {
|
|
55
|
-
yield* _getFieldValues(update, `${prefix}${key}.`);
|
|
56
|
-
}
|
|
57
|
-
else if (update instanceof ArrayUpdate) {
|
|
58
|
-
if (update.adds.length) {
|
|
59
|
-
yield `${prefix}${key}`;
|
|
60
|
-
yield FieldValue.arrayUnion(...update.adds);
|
|
61
|
-
}
|
|
62
|
-
if (update.deletes.length) {
|
|
63
|
-
yield `${prefix}${key}`;
|
|
64
|
-
yield FieldValue.arrayRemove(...update.deletes);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
yield `${prefix}${key}`;
|
|
69
|
-
if (!(update instanceof Update))
|
|
70
|
-
yield update;
|
|
71
|
-
else if (update instanceof Delete)
|
|
72
|
-
yield FieldValue.delete();
|
|
73
|
-
else if (update instanceof Increment)
|
|
74
|
-
yield FieldValue.increment(update.amount);
|
|
75
|
-
else
|
|
76
|
-
yield update.transform();
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
48
|
+
const _getFieldValues = (updates) => getObject(mapItems(getUpdates(updates), _getFieldValue));
|
|
49
|
+
const _getFieldValue = ({ keys, action, value }) => [keys.join("."), action === "sum" ? FieldValue.increment(value) : action === "set" ? value : action];
|
|
80
50
|
/**
|
|
81
51
|
* Firestore server database provider.
|
|
82
52
|
* - Works with the Firebase Admin SDK for Node.JS
|
|
@@ -85,53 +55,50 @@ export class FirestoreServerProvider {
|
|
|
85
55
|
constructor(firestore = new Firestore()) {
|
|
86
56
|
this._firestore = firestore;
|
|
87
57
|
}
|
|
88
|
-
async getItem(
|
|
89
|
-
return _getItemValue(await this._firestore.collection(
|
|
58
|
+
async getItem(c, id) {
|
|
59
|
+
return _getItemValue(await this._firestore.collection(c).doc(id).get());
|
|
90
60
|
}
|
|
91
|
-
getItemSequence(
|
|
92
|
-
const ref = this._firestore.collection(
|
|
61
|
+
getItemSequence(c, id) {
|
|
62
|
+
const ref = this._firestore.collection(c).doc(id);
|
|
93
63
|
return new LazyDeferredSequence(({ resolve, reject }) => ref.onSnapshot(snapshot => resolve(_getItemValue(snapshot)), //
|
|
94
64
|
reject));
|
|
95
65
|
}
|
|
96
|
-
async addItem(
|
|
97
|
-
return (await this._firestore.collection(
|
|
66
|
+
async addItem(c, data) {
|
|
67
|
+
return (await this._firestore.collection(c).add(data)).id;
|
|
98
68
|
}
|
|
99
|
-
async setItem(
|
|
100
|
-
await this._firestore.collection(
|
|
69
|
+
async setItem(c, id, data) {
|
|
70
|
+
await this._firestore.collection(c).doc(id).set(data);
|
|
101
71
|
}
|
|
102
|
-
async updateItem(
|
|
103
|
-
await this._firestore
|
|
104
|
-
.collection(collection)
|
|
105
|
-
.doc(id)
|
|
106
|
-
.update(..._getFieldValues(Object.entries(updates)));
|
|
72
|
+
async updateItem(c, id, updates) {
|
|
73
|
+
await this._firestore.collection(c).doc(id).update(_getFieldValues(updates));
|
|
107
74
|
}
|
|
108
|
-
async deleteItem(
|
|
109
|
-
await this._firestore.collection(
|
|
75
|
+
async deleteItem(c, id) {
|
|
76
|
+
await this._firestore.collection(c).doc(id).delete();
|
|
110
77
|
}
|
|
111
|
-
async getQuery(
|
|
112
|
-
return _getItemArray(await _getQuery(this._firestore,
|
|
78
|
+
async getQuery(c, q) {
|
|
79
|
+
return _getItemArray(await _getQuery(this._firestore, c, q).get());
|
|
113
80
|
}
|
|
114
|
-
getQuerySequence(
|
|
115
|
-
const ref = _getQuery(this._firestore,
|
|
81
|
+
getQuerySequence(c, q) {
|
|
82
|
+
const ref = _getQuery(this._firestore, c, q);
|
|
116
83
|
return new LazyDeferredSequence(({ resolve, reject }) => ref.onSnapshot(snapshot => resolve(_getItemArray(snapshot)), //
|
|
117
84
|
reject));
|
|
118
85
|
}
|
|
119
|
-
async setQuery(
|
|
120
|
-
return await bulkWrite(this._firestore,
|
|
86
|
+
async setQuery(c, q, data) {
|
|
87
|
+
return await bulkWrite(this._firestore, c, q, (w, s) => void w.set(s.ref, data));
|
|
121
88
|
}
|
|
122
|
-
async updateQuery(
|
|
123
|
-
const fieldValues = _getFieldValues(
|
|
124
|
-
return await bulkWrite(this._firestore,
|
|
89
|
+
async updateQuery(c, q, updates) {
|
|
90
|
+
const fieldValues = _getFieldValues(updates);
|
|
91
|
+
return await bulkWrite(this._firestore, c, q, (w, s) => void w.update(s.ref, fieldValues));
|
|
125
92
|
}
|
|
126
|
-
async deleteQuery(
|
|
127
|
-
return await bulkWrite(this._firestore,
|
|
93
|
+
async deleteQuery(c, q) {
|
|
94
|
+
return await bulkWrite(this._firestore, c, q, (w, s) => void w.delete(s.ref));
|
|
128
95
|
}
|
|
129
96
|
}
|
|
130
97
|
/** Perform a bulk update on a set of documents using a `BulkWriter` */
|
|
131
|
-
async function bulkWrite(firestore,
|
|
98
|
+
async function bulkWrite(firestore, c, q, callback) {
|
|
132
99
|
let count = 0;
|
|
133
100
|
const writer = firestore.bulkWriter();
|
|
134
|
-
const query = _getQuery(firestore,
|
|
101
|
+
const query = _getQuery(firestore, c, q).limit(BATCH_SIZE).select(); // `select()` turs the query into a field mask query (with no field masks) which saves data transfer and memory.
|
|
135
102
|
let current = query;
|
|
136
103
|
while (current) {
|
|
137
104
|
const { docs, size } = await current.get();
|
package/index.d.ts
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* - Modules that are for internal use, like `shelving/test`
|
|
5
5
|
*/
|
|
6
6
|
export * from "./api/index.js";
|
|
7
|
-
export * from "./constraint/index.js";
|
|
8
7
|
export * from "./db/index.js";
|
|
9
8
|
export * from "./error/index.js";
|
|
10
9
|
export * from "./feedback/index.js";
|
|
@@ -14,5 +13,4 @@ export * from "./provider/index.js";
|
|
|
14
13
|
export * from "./schema/index.js";
|
|
15
14
|
export * from "./sequence/index.js";
|
|
16
15
|
export * from "./state/index.js";
|
|
17
|
-
export * from "./update/index.js";
|
|
18
16
|
export * from "./util/index.js";
|
package/index.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* - Modules that are for internal use, like `shelving/test`
|
|
5
5
|
*/
|
|
6
6
|
export * from "./api/index.js";
|
|
7
|
-
export * from "./constraint/index.js";
|
|
8
7
|
export * from "./db/index.js";
|
|
9
8
|
export * from "./error/index.js";
|
|
10
9
|
export * from "./feedback/index.js";
|
|
@@ -19,5 +18,4 @@ export * from "./schema/index.js";
|
|
|
19
18
|
export * from "./sequence/index.js";
|
|
20
19
|
export * from "./state/index.js";
|
|
21
20
|
// export * from "./test/index.js"; // Not exported.
|
|
22
|
-
export * from "./update/index.js";
|
|
23
21
|
export * from "./util/index.js";
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"state-management",
|
|
12
12
|
"query-builder"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.92.0",
|
|
15
15
|
"repository": "https://github.com/dhoulb/shelving",
|
|
16
16
|
"author": "Dave Houlbrooke <dave@shax.com>",
|
|
17
17
|
"license": "0BSD",
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
"exports": {
|
|
23
23
|
".": "./index.js",
|
|
24
24
|
"./api": "./api/index.js",
|
|
25
|
-
"./constraint": "./constraint/index.js",
|
|
26
25
|
"./db": "./db/index.js",
|
|
27
26
|
"./error": "./error/index.js",
|
|
28
27
|
"./feedback": "./feedback/index.js",
|
|
@@ -37,7 +36,6 @@
|
|
|
37
36
|
"./sequence": "./sequence/index.js",
|
|
38
37
|
"./state": "./state/index.js",
|
|
39
38
|
"./test": "./test/index.js",
|
|
40
|
-
"./update": "./update/index.js",
|
|
41
39
|
"./util": "./util/index.js"
|
|
42
40
|
},
|
|
43
41
|
"sideEffects": false,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { AsyncProvider } from "./Provider.js";
|
|
2
2
|
import type { AsyncThroughProvider } from "./ThroughProvider.js";
|
|
3
|
-
import type { ItemArray,
|
|
4
|
-
import type { Updates } from "../update/DataUpdate.js";
|
|
3
|
+
import type { ItemArray, ItemQuery, ItemValue } from "../db/ItemReference.js";
|
|
5
4
|
import type { Data } from "../util/data.js";
|
|
5
|
+
import type { Updates } from "../util/update.js";
|
|
6
6
|
import { MemoryProvider } from "./MemoryProvider.js";
|
|
7
7
|
/** Keep a copy of asynchronous remote data in a local synchronous cache. */
|
|
8
8
|
export declare class CacheProvider implements AsyncThroughProvider {
|
|
@@ -15,9 +15,9 @@ export declare class CacheProvider implements AsyncThroughProvider {
|
|
|
15
15
|
setItem(collection: string, id: string, data: Data): Promise<void>;
|
|
16
16
|
updateItem(collection: string, id: string, updates: Updates): Promise<void>;
|
|
17
17
|
deleteItem(collection: string, id: string): Promise<void>;
|
|
18
|
-
getQuery(collection: string,
|
|
19
|
-
getQuerySequence(collection: string,
|
|
20
|
-
setQuery(collection: string,
|
|
21
|
-
updateQuery(collection: string,
|
|
22
|
-
deleteQuery(collection: string,
|
|
18
|
+
getQuery(collection: string, query: ItemQuery): Promise<ItemArray>;
|
|
19
|
+
getQuerySequence(collection: string, query: ItemQuery): AsyncIterableIterator<ItemArray>;
|
|
20
|
+
setQuery(collection: string, query: ItemQuery, data: Data): Promise<number>;
|
|
21
|
+
updateQuery(collection: string, query: ItemQuery, updates: Updates): Promise<number>;
|
|
22
|
+
deleteQuery(collection: string, query: ItemQuery): Promise<number>;
|
|
23
23
|
}
|
|
@@ -34,29 +34,29 @@ export class CacheProvider {
|
|
|
34
34
|
await this.source.deleteItem(collection, id);
|
|
35
35
|
this.memory.getTable(collection).deleteItem(id);
|
|
36
36
|
}
|
|
37
|
-
async getQuery(collection,
|
|
38
|
-
const items = await this.source.getQuery(collection,
|
|
37
|
+
async getQuery(collection, query) {
|
|
38
|
+
const items = await this.source.getQuery(collection, query);
|
|
39
39
|
const table = this.memory.getTable(collection);
|
|
40
|
-
table.setQueryItems(
|
|
40
|
+
table.setQueryItems(query, items);
|
|
41
41
|
return items;
|
|
42
42
|
}
|
|
43
|
-
async *getQuerySequence(collection,
|
|
43
|
+
async *getQuerySequence(collection, query) {
|
|
44
44
|
const table = this.memory.getTable(collection);
|
|
45
|
-
yield* table.setQueryItemsSequence(
|
|
45
|
+
yield* table.setQueryItemsSequence(query, this.source.getQuerySequence(collection, query));
|
|
46
46
|
}
|
|
47
|
-
async setQuery(collection,
|
|
48
|
-
const count = await this.source.setQuery(collection,
|
|
49
|
-
this.memory.getTable(collection).setQuery(
|
|
47
|
+
async setQuery(collection, query, data) {
|
|
48
|
+
const count = await this.source.setQuery(collection, query, data);
|
|
49
|
+
this.memory.getTable(collection).setQuery(query, data);
|
|
50
50
|
return count;
|
|
51
51
|
}
|
|
52
|
-
async updateQuery(collection,
|
|
53
|
-
const count = await this.source.updateQuery(collection,
|
|
54
|
-
this.memory.getTable(collection).updateQuery(
|
|
52
|
+
async updateQuery(collection, query, updates) {
|
|
53
|
+
const count = await this.source.updateQuery(collection, query, updates);
|
|
54
|
+
this.memory.getTable(collection).updateQuery(query, updates);
|
|
55
55
|
return count;
|
|
56
56
|
}
|
|
57
|
-
async deleteQuery(collection,
|
|
58
|
-
const count = await this.source.deleteQuery(collection,
|
|
59
|
-
this.memory.getTable(collection).deleteQuery(
|
|
57
|
+
async deleteQuery(collection, query) {
|
|
58
|
+
const count = await this.source.deleteQuery(collection, query);
|
|
59
|
+
this.memory.getTable(collection).deleteQuery(query);
|
|
60
60
|
return count;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { AsyncProvider, Provider } from "./Provider.js";
|
|
2
2
|
import type { AsyncThroughProvider, ThroughProvider } from "./ThroughProvider.js";
|
|
3
|
-
import type { ItemArray,
|
|
4
|
-
import type { Updates } from "../update/DataUpdate.js";
|
|
3
|
+
import type { ItemArray, ItemQuery, ItemValue } from "../db/ItemReference.js";
|
|
5
4
|
import type { Data } from "../util/data.js";
|
|
5
|
+
import type { Updates } from "../util/update.js";
|
|
6
6
|
/** Provider that logs operations to a source provider to the console. */
|
|
7
7
|
declare abstract class AbstractDebugProvider {
|
|
8
8
|
abstract readonly source: Provider | AsyncProvider;
|
|
9
9
|
getItemSequence(collection: string, id: string): AsyncIterableIterator<ItemValue>;
|
|
10
|
-
getQuerySequence(collection: string,
|
|
10
|
+
getQuerySequence(collection: string, query: ItemQuery): AsyncIterableIterator<ItemArray>;
|
|
11
11
|
}
|
|
12
12
|
/** Provider that logs operations to a synchronous source provider to the console. */
|
|
13
13
|
export declare class DebugProvider extends AbstractDebugProvider implements ThroughProvider {
|
|
@@ -18,10 +18,10 @@ export declare class DebugProvider extends AbstractDebugProvider implements Thro
|
|
|
18
18
|
setItem(collection: string, id: string, data: Data): void;
|
|
19
19
|
updateItem(collection: string, id: string, updates: Updates): void;
|
|
20
20
|
deleteItem(collection: string, id: string): void;
|
|
21
|
-
getQuery(collection: string,
|
|
22
|
-
setQuery(collection: string,
|
|
23
|
-
updateQuery(collection: string,
|
|
24
|
-
deleteQuery(collection: string,
|
|
21
|
+
getQuery(collection: string, query: ItemQuery): ItemArray;
|
|
22
|
+
setQuery(collection: string, query: ItemQuery, data: Data): number;
|
|
23
|
+
updateQuery(collection: string, query: ItemQuery, updates: Updates): number;
|
|
24
|
+
deleteQuery(collection: string, query: ItemQuery): number;
|
|
25
25
|
}
|
|
26
26
|
/** Provider that logs operations to a synchronous source provider to the console. */
|
|
27
27
|
export declare class AsyncDebugProvider extends AbstractDebugProvider implements AsyncThroughProvider {
|
|
@@ -32,9 +32,9 @@ export declare class AsyncDebugProvider extends AbstractDebugProvider implements
|
|
|
32
32
|
setItem(collection: string, id: string, data: Data): Promise<void>;
|
|
33
33
|
updateItem(collection: string, id: string, updates: Updates): Promise<void>;
|
|
34
34
|
deleteItem(collection: string, id: string): Promise<void>;
|
|
35
|
-
getQuery(collection: string,
|
|
36
|
-
setQuery(collection: string,
|
|
37
|
-
updateQuery(collection: string,
|
|
38
|
-
deleteQuery(collection: string,
|
|
35
|
+
getQuery(collection: string, query: ItemQuery): Promise<ItemArray>;
|
|
36
|
+
setQuery(collection: string, query: ItemQuery, data: Data): Promise<number>;
|
|
37
|
+
updateQuery(collection: string, query: ItemQuery, updates: Updates): Promise<number>;
|
|
38
|
+
deleteQuery(collection: string, query: ItemQuery): Promise<number>;
|
|
39
39
|
}
|
|
40
40
|
export {};
|