shelving 1.128.0 → 1.128.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/db/ItemStore.js +5 -2
- package/db/QueryStore.d.ts +4 -0
- package/db/QueryStore.js +16 -0
- package/package.json +1 -1
package/db/ItemStore.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { RequiredError } from "../error/RequiredError.js";
|
|
1
2
|
import { BooleanStore } from "../store/BooleanStore.js";
|
|
2
3
|
import { OptionalDataStore } from "../store/DataStore.js";
|
|
3
4
|
import { NONE } from "../util/constants.js";
|
|
4
5
|
import { getItem } from "../util/item.js";
|
|
5
|
-
import { getRequired } from "../util/optional.js";
|
|
6
6
|
import { runSequence } from "../util/sequence.js";
|
|
7
7
|
/** Store a single item. */
|
|
8
8
|
export class ItemStore extends OptionalDataStore {
|
|
@@ -12,7 +12,10 @@ export class ItemStore extends OptionalDataStore {
|
|
|
12
12
|
busy = new BooleanStore();
|
|
13
13
|
/** Get the data of this store (throws `RequiredError` if item doesn't exist). */
|
|
14
14
|
get data() {
|
|
15
|
-
|
|
15
|
+
const item = this.value;
|
|
16
|
+
if (!item)
|
|
17
|
+
throw new RequiredError(`Item must exist in "${this.collection}"`, this.id);
|
|
18
|
+
return item;
|
|
16
19
|
}
|
|
17
20
|
/** Set the data of this store. */
|
|
18
21
|
set data(data) {
|
package/db/QueryStore.d.ts
CHANGED
|
@@ -15,6 +15,10 @@ export declare class QueryStore<T extends Database, K extends DataKey<T>> extend
|
|
|
15
15
|
/** Can more items be loaded after the current result. */
|
|
16
16
|
get hasMore(): boolean;
|
|
17
17
|
private _hasMore;
|
|
18
|
+
/** Get the first item in this store. */
|
|
19
|
+
get first(): Item<T[K]>;
|
|
20
|
+
/** Get the last item in this store. */
|
|
21
|
+
get last(): Item<T[K]>;
|
|
18
22
|
constructor(collection: K, query: ItemQuery<T[K]>, provider: AbstractProvider<T>, memory?: MemoryProvider<T>);
|
|
19
23
|
/** Refresh this store from the source provider. */
|
|
20
24
|
refresh(provider?: AbstractProvider<T>): void;
|
package/db/QueryStore.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { collection, query } from "firebase/firestore";
|
|
2
|
+
import { RequiredError } from "../error/RequiredError.js";
|
|
1
3
|
import { ArrayStore } from "../store/ArrayStore.js";
|
|
2
4
|
import { BooleanStore } from "../store/BooleanStore.js";
|
|
3
5
|
import { NONE } from "../util/constants.js";
|
|
@@ -15,6 +17,20 @@ export class QueryStore extends ArrayStore {
|
|
|
15
17
|
return this._hasMore;
|
|
16
18
|
}
|
|
17
19
|
_hasMore = false;
|
|
20
|
+
/** Get the first item in this store. */
|
|
21
|
+
get first() {
|
|
22
|
+
const first = this.optionalFirst;
|
|
23
|
+
if (!first)
|
|
24
|
+
throw new RequiredError(`First item must exist in "${collection}"`, query);
|
|
25
|
+
return first;
|
|
26
|
+
}
|
|
27
|
+
/** Get the last item in this store. */
|
|
28
|
+
get last() {
|
|
29
|
+
const last = this.optionalLast;
|
|
30
|
+
if (!last)
|
|
31
|
+
throw new RequiredError(`Last item must exist in "${collection}"`, query);
|
|
32
|
+
return last;
|
|
33
|
+
}
|
|
18
34
|
constructor(collection, query, provider, memory) {
|
|
19
35
|
const time = memory?.getQueryTime(collection, query);
|
|
20
36
|
const items = memory?.getQuery(collection, query) || [];
|