shelving 1.89.2 → 1.89.4
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/constraint/FilterConstraint.d.ts +3 -3
- package/db/Change.d.ts +16 -17
- package/db/Change.js +5 -7
- package/db/Collection.d.ts +37 -43
- package/db/Collection.js +22 -29
- package/db/Database.d.ts +21 -22
- package/db/Database.js +8 -8
- package/db/Item.d.ts +38 -44
- package/db/Item.js +30 -37
- package/db/ItemState.d.ts +5 -5
- package/db/ItemState.js +3 -3
- package/db/Query.d.ts +36 -36
- package/db/Query.js +13 -13
- package/db/QueryState.d.ts +9 -9
- package/db/QueryState.js +3 -3
- package/firestore/client/FirestoreClientProvider.d.ts +2 -2
- package/package.json +1 -1
- package/provider/CacheProvider.d.ts +16 -16
- package/provider/DebugProvider.d.ts +29 -29
- package/provider/MemoryProvider.d.ts +19 -22
- package/provider/MemoryProvider.js +1 -4
- package/provider/Provider.d.ts +33 -33
- package/provider/ThroughProvider.d.ts +29 -29
- package/provider/ValidationProvider.d.ts +2 -2
- package/react/useData.d.ts +3 -4
package/db/Item.js
CHANGED
|
@@ -1,20 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { runSequence } from "../util/sequence.js";
|
|
1
|
+
import { QueryConstraints } from "../constraint/QueryConstraints.js";
|
|
3
2
|
import { FilterConstraint } from "../constraint/FilterConstraint.js";
|
|
4
3
|
import { FilterConstraints } from "../constraint/FilterConstraints.js";
|
|
4
|
+
import { getData } from "../util/data.js";
|
|
5
|
+
import { runSequence } from "../util/sequence.js";
|
|
6
|
+
/** Get the ID from item data. */
|
|
7
|
+
export const getID = ({ id }) => id;
|
|
8
|
+
/** Get the IDs of an iterable set item data. */
|
|
9
|
+
export function* getIDs(entities) {
|
|
10
|
+
for (const { id } of entities)
|
|
11
|
+
yield id;
|
|
12
|
+
}
|
|
13
|
+
/** Get a `FilterConstraints` instance that targets a single item by its ID. */
|
|
14
|
+
export const getItemConstraints = (id) => new QueryConstraints(new FilterConstraints(new FilterConstraint("id", id)), undefined, 1);
|
|
5
15
|
/** Reference to an item in a synchronous or asynchronous database. */
|
|
6
16
|
class BaseItem {
|
|
7
17
|
/** Get a set change for this item. */
|
|
8
18
|
getSet(data) {
|
|
9
|
-
return this.
|
|
19
|
+
return { action: "SET", collection: this.collection, id: this.id, data };
|
|
10
20
|
}
|
|
11
21
|
/** Get an update change for this item. */
|
|
12
22
|
getUpdate(updates) {
|
|
13
|
-
return this.
|
|
23
|
+
return { action: "UPDATE", collection: this.collection, id: this.id, updates };
|
|
14
24
|
}
|
|
15
25
|
/** Get a delete change for this item. */
|
|
16
26
|
getDelete() {
|
|
17
|
-
return this.
|
|
27
|
+
return { action: "DELETE", collection: this.collection, id: this.id };
|
|
18
28
|
}
|
|
19
29
|
// Implement toString()
|
|
20
30
|
toString() {
|
|
@@ -26,77 +36,60 @@ class BaseItem {
|
|
|
26
36
|
}
|
|
27
37
|
// Implement AsyncIterable
|
|
28
38
|
[Symbol.asyncIterator]() {
|
|
29
|
-
return this.
|
|
39
|
+
return this.provider.getItemSequence(this.collection, this.id)[Symbol.asyncIterator]();
|
|
30
40
|
}
|
|
31
41
|
}
|
|
32
42
|
/** Reference to an item in a synchronous database. */
|
|
33
43
|
export class Item extends BaseItem {
|
|
34
|
-
constructor(
|
|
44
|
+
constructor(provider, collection, id) {
|
|
35
45
|
super();
|
|
36
|
-
this.
|
|
46
|
+
this.provider = provider;
|
|
37
47
|
this.collection = collection;
|
|
38
48
|
this.id = id;
|
|
39
49
|
}
|
|
40
|
-
get optional() {
|
|
41
|
-
return this.db.query(this.collection, getItemFilterConstraints(this.id), undefined, 1);
|
|
42
|
-
}
|
|
43
50
|
get exists() {
|
|
44
|
-
return !!this.
|
|
51
|
+
return !!this.provider.getItem(this.collection, this.id);
|
|
45
52
|
}
|
|
46
53
|
get value() {
|
|
47
|
-
return this.
|
|
54
|
+
return this.provider.getItem(this.collection, this.id);
|
|
48
55
|
}
|
|
49
56
|
get data() {
|
|
50
57
|
return getData(this.value);
|
|
51
58
|
}
|
|
52
59
|
set(data) {
|
|
53
|
-
return this.
|
|
60
|
+
return this.provider.setItem(this.collection, this.id, data);
|
|
54
61
|
}
|
|
55
62
|
update(updates) {
|
|
56
|
-
return this.
|
|
63
|
+
return this.provider.updateItem(this.collection, this.id, updates);
|
|
57
64
|
}
|
|
58
65
|
delete() {
|
|
59
|
-
return this.
|
|
66
|
+
return this.provider.deleteItem(this.collection, this.id);
|
|
60
67
|
}
|
|
61
68
|
}
|
|
62
69
|
/** Reference to an item in an asynchronous database. */
|
|
63
70
|
export class AsyncItem extends BaseItem {
|
|
64
|
-
constructor(
|
|
71
|
+
constructor(provider, collection, id) {
|
|
65
72
|
super();
|
|
66
|
-
this.
|
|
73
|
+
this.provider = provider;
|
|
67
74
|
this.collection = collection;
|
|
68
75
|
this.id = id;
|
|
69
76
|
}
|
|
70
|
-
get optional() {
|
|
71
|
-
return this.db.query(this.collection, { id: this.id }, undefined, 1);
|
|
72
|
-
}
|
|
73
77
|
get exists() {
|
|
74
|
-
return this.
|
|
78
|
+
return this.provider.getItem(this.collection, this.id).then(Boolean);
|
|
75
79
|
}
|
|
76
80
|
get value() {
|
|
77
|
-
return this.
|
|
81
|
+
return this.provider.getItem(this.collection, this.id);
|
|
78
82
|
}
|
|
79
83
|
get data() {
|
|
80
84
|
return this.value.then(getData);
|
|
81
85
|
}
|
|
82
86
|
set(data) {
|
|
83
|
-
return this.
|
|
87
|
+
return this.provider.setItem(this.collection, this.id, data);
|
|
84
88
|
}
|
|
85
89
|
update(updates) {
|
|
86
|
-
return this.
|
|
90
|
+
return this.provider.updateItem(this.collection, this.id, updates);
|
|
87
91
|
}
|
|
88
92
|
delete() {
|
|
89
|
-
return this.
|
|
93
|
+
return this.provider.deleteItem(this.collection, this.id);
|
|
90
94
|
}
|
|
91
95
|
}
|
|
92
|
-
/** Get the ID from item data. */
|
|
93
|
-
export const getID = ({ id }) => id;
|
|
94
|
-
/** Get the IDs of an iterable set item data. */
|
|
95
|
-
export function* getIDs(entities) {
|
|
96
|
-
for (const { id } of entities)
|
|
97
|
-
yield id;
|
|
98
|
-
}
|
|
99
|
-
/** Get a `FilterConstraints` instance that targets a single item by its ID. */
|
|
100
|
-
export function getItemFilterConstraints(id) {
|
|
101
|
-
return new FilterConstraints(new FilterConstraint("id", id));
|
|
102
|
-
}
|
package/db/ItemState.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Data } from "../util/data.js";
|
|
2
2
|
import { Dispatch } from "../util/function.js";
|
|
3
3
|
import { State } from "../state/State.js";
|
|
4
4
|
import { BooleanState } from "../state/BooleanState.js";
|
|
5
5
|
import { ItemValue, Item, AsyncItem, ItemData } from "./Item.js";
|
|
6
6
|
/** Hold the current state of a item. */
|
|
7
|
-
export declare class ItemState<T extends
|
|
8
|
-
readonly ref: Item<T
|
|
7
|
+
export declare class ItemState<T extends Data = Data> extends State<ItemValue<T>> {
|
|
8
|
+
readonly ref: Item<T> | AsyncItem<T>;
|
|
9
9
|
readonly busy: BooleanState;
|
|
10
10
|
/** Get the data of the item (throws `RequiredError` if item doesn't exist). */
|
|
11
|
-
get data(): ItemData<T
|
|
11
|
+
get data(): ItemData<T>;
|
|
12
12
|
/** Does the item exist (i.e. its value isn't `null`)? */
|
|
13
13
|
get exists(): boolean;
|
|
14
|
-
constructor(ref: Item<T
|
|
14
|
+
constructor(ref: Item<T> | AsyncItem<T>);
|
|
15
15
|
/** Refresh this state from the source provider. */
|
|
16
16
|
readonly refresh: () => void;
|
|
17
17
|
private _refresh;
|
package/db/ItemState.js
CHANGED
|
@@ -15,9 +15,9 @@ export class ItemState extends State {
|
|
|
15
15
|
return !!this.value;
|
|
16
16
|
}
|
|
17
17
|
constructor(ref) {
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const table =
|
|
18
|
+
var _a;
|
|
19
|
+
const { provider, collection, id } = ref;
|
|
20
|
+
const table = (_a = getOptionalSource(CacheProvider, provider)) === null || _a === void 0 ? void 0 : _a.memory.getTable(collection);
|
|
21
21
|
const time = table ? table.getItemTime(id) : null;
|
|
22
22
|
const isCached = typeof time === "number";
|
|
23
23
|
super(table && isCached ? table.getItem(id) : State.NOVALUE, table ? new LazyDeferredSequence(() => this.from(table.getCachedItemSequence(id))) : undefined);
|
package/db/Query.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Data } from "../util/data.js";
|
|
2
2
|
import type { Dispatch, Handler, Stop } from "../util/function.js";
|
|
3
3
|
import type { Updates } from "../update/DataUpdate.js";
|
|
4
4
|
import type { FilterList } from "../constraint/FilterConstraint.js";
|
|
5
5
|
import type { SortList } from "../constraint/SortConstraint.js";
|
|
6
|
+
import type { Provider, AsyncProvider } from "../provider/Provider.js";
|
|
6
7
|
import { QueryConstraints } from "../constraint/QueryConstraints.js";
|
|
7
8
|
import type { ItemArray, ItemValue, ItemData } from "./Item.js";
|
|
8
|
-
import type { AsyncDatabase, Database } from "./Database.js";
|
|
9
9
|
/** Reference to a set of items in a sync or async provider. */
|
|
10
|
-
declare abstract class BaseQuery<T extends
|
|
11
|
-
abstract readonly
|
|
12
|
-
abstract readonly collection:
|
|
10
|
+
declare abstract class BaseQuery<T extends Data = Data> extends QueryConstraints<ItemData<T>> implements AsyncIterable<ItemArray<T>> {
|
|
11
|
+
abstract readonly provider: Provider | AsyncProvider;
|
|
12
|
+
abstract readonly collection: string;
|
|
13
13
|
/**
|
|
14
14
|
* Get array of entities for this query.
|
|
15
15
|
* @return Array of entities.
|
|
16
16
|
*/
|
|
17
|
-
abstract value: ItemArray<T
|
|
17
|
+
abstract value: ItemArray<T> | PromiseLike<ItemArray<T>>;
|
|
18
18
|
/**
|
|
19
19
|
* Count the number of results of this set of items.
|
|
20
20
|
* @return Number of items matching the query (possibly promised).
|
|
@@ -29,36 +29,36 @@ declare abstract class BaseQuery<T extends Datas = Datas, K extends DataKey<T> =
|
|
|
29
29
|
* Get the first item matched by this query or `null` if this query has no results.
|
|
30
30
|
* @throws RequiredError if there were no results for this query.
|
|
31
31
|
*/
|
|
32
|
-
abstract firstValue: ItemValue<T
|
|
32
|
+
abstract firstValue: ItemValue<T> | PromiseLike<ItemValue<T>>;
|
|
33
33
|
/**
|
|
34
34
|
* Get the first item matched by this query.
|
|
35
35
|
* @throws RequiredError if there were no results for this query.
|
|
36
36
|
*/
|
|
37
|
-
abstract firstData: ItemData<T
|
|
37
|
+
abstract firstData: ItemData<T> | PromiseLike<ItemData<T>>;
|
|
38
38
|
/**
|
|
39
39
|
* Get the last item matched by this query or `null` if this query has no results.
|
|
40
40
|
* @throws RequiredError if there were no results for this query.
|
|
41
41
|
*/
|
|
42
|
-
abstract lastValue: ItemValue<T
|
|
42
|
+
abstract lastValue: ItemValue<T> | PromiseLike<ItemValue<T>>;
|
|
43
43
|
/**
|
|
44
44
|
* Get the last item matched by this query.
|
|
45
45
|
* @throws RequiredError if there were no results for this query.
|
|
46
46
|
*/
|
|
47
|
-
abstract lastData: ItemData<T
|
|
47
|
+
abstract lastData: ItemData<T> | PromiseLike<ItemData<T>>;
|
|
48
48
|
/**
|
|
49
49
|
* Set all matching items to the same exact value.
|
|
50
50
|
*
|
|
51
51
|
* @param data Complete data to set the item to.
|
|
52
52
|
* @return Nothing (possibly promised).
|
|
53
53
|
*/
|
|
54
|
-
abstract set(data: T
|
|
54
|
+
abstract set(data: T): number | PromiseLike<number>;
|
|
55
55
|
/**
|
|
56
56
|
* Update all matching items with the same partial value.
|
|
57
57
|
*
|
|
58
58
|
* @param updates `Update` instance or set of updates to apply to every matching item.
|
|
59
59
|
* @return Nothing (possibly promised).
|
|
60
60
|
*/
|
|
61
|
-
abstract update(updates: Updates<T
|
|
61
|
+
abstract update(updates: Updates<T>): number | PromiseLike<number>;
|
|
62
62
|
/**
|
|
63
63
|
* Delete all matching items.
|
|
64
64
|
* @return Nothing (possibly promised).
|
|
@@ -66,39 +66,39 @@ declare abstract class BaseQuery<T extends Datas = Datas, K extends DataKey<T> =
|
|
|
66
66
|
abstract delete(): number | PromiseLike<number>;
|
|
67
67
|
toString(): string;
|
|
68
68
|
/** Subscribe to this item. */
|
|
69
|
-
subscribe(onNext?: Dispatch<[ItemArray<T
|
|
70
|
-
[Symbol.asyncIterator](): AsyncIterator<ItemArray<T
|
|
69
|
+
subscribe(onNext?: Dispatch<[ItemArray<T>]>, onError?: Handler): Stop;
|
|
70
|
+
[Symbol.asyncIterator](): AsyncIterator<ItemArray<T>>;
|
|
71
71
|
}
|
|
72
72
|
/** Reference to a set of items in a provider. */
|
|
73
|
-
export declare class Query<T extends
|
|
74
|
-
readonly
|
|
75
|
-
readonly collection:
|
|
76
|
-
constructor(
|
|
77
|
-
get value(): ItemArray<T
|
|
73
|
+
export declare class Query<T extends Data = Data> extends BaseQuery<T> {
|
|
74
|
+
readonly provider: Provider;
|
|
75
|
+
readonly collection: string;
|
|
76
|
+
constructor(provider: Provider, collection: string, filters?: FilterList<ItemData<T>>, sorts?: SortList<ItemData<T>>, limit?: number | null);
|
|
77
|
+
get value(): ItemArray<T>;
|
|
78
78
|
get count(): number;
|
|
79
79
|
get exists(): boolean;
|
|
80
|
-
get firstValue(): ItemValue<T
|
|
81
|
-
get firstData(): ItemData<T
|
|
82
|
-
get lastValue(): ItemValue<T
|
|
83
|
-
get lastData(): ItemData<T
|
|
84
|
-
set(data: T
|
|
85
|
-
update(updates: Updates<T
|
|
80
|
+
get firstValue(): ItemValue<T>;
|
|
81
|
+
get firstData(): ItemData<T>;
|
|
82
|
+
get lastValue(): ItemValue<T>;
|
|
83
|
+
get lastData(): ItemData<T>;
|
|
84
|
+
set(data: T): number;
|
|
85
|
+
update(updates: Updates<T>): number;
|
|
86
86
|
delete(): number;
|
|
87
87
|
}
|
|
88
88
|
/** Reference to a set of items in a provider. */
|
|
89
|
-
export declare class AsyncQuery<T extends
|
|
90
|
-
readonly
|
|
91
|
-
readonly collection:
|
|
92
|
-
constructor(
|
|
93
|
-
get value(): Promise<ItemArray<T
|
|
89
|
+
export declare class AsyncQuery<T extends Data = Data> extends BaseQuery<T> {
|
|
90
|
+
readonly provider: AsyncProvider;
|
|
91
|
+
readonly collection: string;
|
|
92
|
+
constructor(provider: AsyncProvider, collection: string, filters?: FilterList<ItemData<T>>, sorts?: SortList<ItemData<T>>, limit?: number | null);
|
|
93
|
+
get value(): Promise<ItemArray<T>>;
|
|
94
94
|
get count(): Promise<number>;
|
|
95
95
|
get exists(): Promise<boolean>;
|
|
96
|
-
get firstValue(): Promise<ItemValue<T
|
|
97
|
-
get firstData(): Promise<ItemData<T
|
|
98
|
-
get lastValue(): Promise<ItemValue<T
|
|
99
|
-
get lastData(): Promise<ItemData<T
|
|
100
|
-
set(data: T
|
|
101
|
-
update(updates: Updates<T
|
|
96
|
+
get firstValue(): Promise<ItemValue<T>>;
|
|
97
|
+
get firstData(): Promise<ItemData<T>>;
|
|
98
|
+
get lastValue(): Promise<ItemValue<T>>;
|
|
99
|
+
get lastData(): Promise<ItemData<T>>;
|
|
100
|
+
set(data: T): Promise<number>;
|
|
101
|
+
update(updates: Updates<T>): PromiseLike<number>;
|
|
102
102
|
delete(): PromiseLike<number>;
|
|
103
103
|
}
|
|
104
104
|
export {};
|
package/db/Query.js
CHANGED
|
@@ -13,18 +13,18 @@ class BaseQuery extends QueryConstraints {
|
|
|
13
13
|
}
|
|
14
14
|
// Implement AsyncIterable
|
|
15
15
|
[Symbol.asyncIterator]() {
|
|
16
|
-
return this.
|
|
16
|
+
return this.provider.getQuerySequence(this.collection, this)[Symbol.asyncIterator]();
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
/** Reference to a set of items in a provider. */
|
|
20
20
|
export class Query extends BaseQuery {
|
|
21
|
-
constructor(
|
|
21
|
+
constructor(provider, collection, filters, sorts, limit) {
|
|
22
22
|
super(filters, sorts, limit);
|
|
23
|
-
this.
|
|
23
|
+
this.provider = provider;
|
|
24
24
|
this.collection = collection;
|
|
25
25
|
}
|
|
26
26
|
get value() {
|
|
27
|
-
return this.
|
|
27
|
+
return this.provider.getQuery(this.collection, this);
|
|
28
28
|
}
|
|
29
29
|
get count() {
|
|
30
30
|
return this.value.length;
|
|
@@ -45,24 +45,24 @@ export class Query extends BaseQuery {
|
|
|
45
45
|
return getLastItem(this.value);
|
|
46
46
|
}
|
|
47
47
|
set(data) {
|
|
48
|
-
return this.
|
|
48
|
+
return this.provider.setQuery(this.collection, this, data);
|
|
49
49
|
}
|
|
50
50
|
update(updates) {
|
|
51
|
-
return this.
|
|
51
|
+
return this.provider.updateQuery(this.collection, this, updates);
|
|
52
52
|
}
|
|
53
53
|
delete() {
|
|
54
|
-
return this.
|
|
54
|
+
return this.provider.deleteQuery(this.collection, this);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
/** Reference to a set of items in a provider. */
|
|
58
58
|
export class AsyncQuery extends BaseQuery {
|
|
59
|
-
constructor(
|
|
59
|
+
constructor(provider, collection, filters, sorts, limit) {
|
|
60
60
|
super(filters, sorts, limit);
|
|
61
|
-
this.
|
|
61
|
+
this.provider = provider;
|
|
62
62
|
this.collection = collection;
|
|
63
63
|
}
|
|
64
64
|
get value() {
|
|
65
|
-
return this.
|
|
65
|
+
return this.provider.getQuery(this.collection, this);
|
|
66
66
|
}
|
|
67
67
|
get count() {
|
|
68
68
|
return this.value.then(countArray);
|
|
@@ -83,12 +83,12 @@ export class AsyncQuery extends BaseQuery {
|
|
|
83
83
|
return this.value.then(getLastItem);
|
|
84
84
|
}
|
|
85
85
|
set(data) {
|
|
86
|
-
return this.
|
|
86
|
+
return this.provider.setQuery(this.collection, this, data);
|
|
87
87
|
}
|
|
88
88
|
update(updates) {
|
|
89
|
-
return this.
|
|
89
|
+
return this.provider.updateQuery(this.collection, this, updates);
|
|
90
90
|
}
|
|
91
91
|
delete() {
|
|
92
|
-
return this.
|
|
92
|
+
return this.provider.deleteQuery(this.collection, this);
|
|
93
93
|
}
|
|
94
94
|
}
|
package/db/QueryState.d.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Data } from "../util/data.js";
|
|
2
2
|
import type { Stop } from "../util/function.js";
|
|
3
3
|
import type { ItemArray, ItemValue, ItemData } from "../db/Item.js";
|
|
4
4
|
import type { AsyncQuery, Query } from "../db/Query.js";
|
|
5
5
|
import { State } from "../state/State.js";
|
|
6
6
|
import { BooleanState } from "../state/BooleanState.js";
|
|
7
7
|
/** Hold the current state of a query. */
|
|
8
|
-
export declare class QueryState<T extends
|
|
9
|
-
readonly ref: Query<T
|
|
8
|
+
export declare class QueryState<T extends Data = Data> extends State<ItemArray<T>> implements Iterable<ItemData<T>> {
|
|
9
|
+
readonly ref: Query<T> | AsyncQuery<T>;
|
|
10
10
|
readonly busy: BooleanState;
|
|
11
11
|
readonly limit: number;
|
|
12
12
|
/** Can more items be loaded after the current result. */
|
|
13
13
|
get hasMore(): boolean;
|
|
14
14
|
private _hasMore;
|
|
15
15
|
/** Get the first document matched by this query or `null` if this query has no items. */
|
|
16
|
-
get firstValue(): ItemValue<T
|
|
16
|
+
get firstValue(): ItemValue<T>;
|
|
17
17
|
/** Get the first document matched by this query. */
|
|
18
|
-
get firstData(): ItemData<T
|
|
18
|
+
get firstData(): ItemData<T>;
|
|
19
19
|
/** Get the last document matched by this query or `null` if this query has no items. */
|
|
20
|
-
get lastValue(): ItemValue<T
|
|
20
|
+
get lastValue(): ItemValue<T>;
|
|
21
21
|
/** Get the last document matched by this query. */
|
|
22
|
-
get lastData(): ItemData<T
|
|
22
|
+
get lastData(): ItemData<T>;
|
|
23
23
|
/** Does the document have at least one result. */
|
|
24
24
|
get exists(): boolean;
|
|
25
25
|
/** Get the number of items matching this query. */
|
|
26
26
|
get count(): number;
|
|
27
|
-
constructor(ref: Query<T
|
|
27
|
+
constructor(ref: Query<T> | AsyncQuery<T>);
|
|
28
28
|
/** Refresh this state from the source provider. */
|
|
29
29
|
readonly refresh: () => void;
|
|
30
30
|
private _refresh;
|
|
@@ -39,5 +39,5 @@ export declare class QueryState<T extends Datas, K extends DataKey<T> = DataKey<
|
|
|
39
39
|
readonly loadMore: () => void;
|
|
40
40
|
private _loadMore;
|
|
41
41
|
/** Iterate over the items. */
|
|
42
|
-
[Symbol.iterator](): Iterator<ItemData<T
|
|
42
|
+
[Symbol.iterator](): Iterator<ItemData<T>>;
|
|
43
43
|
}
|
package/db/QueryState.js
CHANGED
|
@@ -35,9 +35,9 @@ export class QueryState extends State {
|
|
|
35
35
|
return this.value.length;
|
|
36
36
|
}
|
|
37
37
|
constructor(ref) {
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
const table =
|
|
38
|
+
var _a;
|
|
39
|
+
const { provider, collection, limit } = ref;
|
|
40
|
+
const table = (_a = getOptionalSource(CacheProvider, provider)) === null || _a === void 0 ? void 0 : _a.memory.getTable(collection);
|
|
41
41
|
const time = table ? table.getQueryTime(ref) : null;
|
|
42
42
|
const isCached = typeof time === "number";
|
|
43
43
|
super(table && isCached ? table.getQuery(ref) : State.NOVALUE, table ? new LazyDeferredSequence(() => this.from(table.getCachedQuerySequence(ref))) : undefined);
|
|
@@ -13,13 +13,13 @@ export declare class FirestoreClientProvider implements AsyncProvider {
|
|
|
13
13
|
private readonly _firestore;
|
|
14
14
|
constructor(firestore: Firestore);
|
|
15
15
|
getItem(collection: string, id: string): Promise<ItemValue>;
|
|
16
|
-
getItemSequence
|
|
16
|
+
getItemSequence(collection: string, id: string): AsyncIterable<ItemValue>;
|
|
17
17
|
addItem(collection: string, data: Data): Promise<string>;
|
|
18
18
|
setItem(collection: string, id: string, data: Data): Promise<void>;
|
|
19
19
|
updateItem(collection: string, id: string, updates: Updates): Promise<void>;
|
|
20
20
|
deleteItem(collection: string, id: string): Promise<void>;
|
|
21
21
|
getQuery(collection: string, constraints: ItemConstraints): Promise<ItemArray>;
|
|
22
|
-
getQuerySequence
|
|
22
|
+
getQuerySequence(collection: string, constraints: ItemConstraints): AsyncIterable<ItemArray>;
|
|
23
23
|
setQuery(collection: string, constraints: ItemConstraints, data: Data): Promise<number>;
|
|
24
24
|
updateQuery(collection: string, constraints: ItemConstraints, updates: Updates): Promise<number>;
|
|
25
25
|
deleteQuery(collection: string, constraints: ItemConstraints): Promise<number>;
|
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Data } from "../util/data.js";
|
|
2
2
|
import type { ItemArray, ItemValue, ItemConstraints } from "../db/Item.js";
|
|
3
3
|
import type { Updates } from "../update/DataUpdate.js";
|
|
4
4
|
import type { AsyncProvider } from "./Provider.js";
|
|
5
5
|
import type { AsyncThroughProvider } from "./ThroughProvider.js";
|
|
6
6
|
import { MemoryProvider } from "./MemoryProvider.js";
|
|
7
7
|
/** Keep a copy of asynchronous remote data in a local synchronous cache. */
|
|
8
|
-
export declare class CacheProvider
|
|
9
|
-
readonly source: AsyncProvider
|
|
10
|
-
readonly memory: MemoryProvider
|
|
11
|
-
constructor(source: AsyncProvider
|
|
12
|
-
getItem
|
|
13
|
-
getItemSequence
|
|
14
|
-
addItem
|
|
15
|
-
setItem
|
|
16
|
-
updateItem
|
|
17
|
-
deleteItem
|
|
18
|
-
getQuery
|
|
19
|
-
getQuerySequence
|
|
20
|
-
setQuery
|
|
21
|
-
updateQuery
|
|
22
|
-
deleteQuery
|
|
8
|
+
export declare class CacheProvider implements AsyncThroughProvider {
|
|
9
|
+
readonly source: AsyncProvider;
|
|
10
|
+
readonly memory: MemoryProvider;
|
|
11
|
+
constructor(source: AsyncProvider, cache?: MemoryProvider);
|
|
12
|
+
getItem(collection: string, id: string): Promise<ItemValue>;
|
|
13
|
+
getItemSequence(collection: string, id: string): AsyncIterableIterator<ItemValue>;
|
|
14
|
+
addItem(collection: string, data: Data): Promise<string>;
|
|
15
|
+
setItem(collection: string, id: string, data: Data): Promise<void>;
|
|
16
|
+
updateItem(collection: string, id: string, updates: Updates): Promise<void>;
|
|
17
|
+
deleteItem(collection: string, id: string): Promise<void>;
|
|
18
|
+
getQuery(collection: string, constraints: ItemConstraints): Promise<ItemArray>;
|
|
19
|
+
getQuerySequence(collection: string, constraints: ItemConstraints): AsyncIterableIterator<ItemArray>;
|
|
20
|
+
setQuery(collection: string, constraints: ItemConstraints, data: Data): Promise<number>;
|
|
21
|
+
updateQuery(collection: string, constraints: ItemConstraints, updates: Updates): Promise<number>;
|
|
22
|
+
deleteQuery(collection: string, constraints: ItemConstraints): Promise<number>;
|
|
23
23
|
}
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Data } from "../util/data.js";
|
|
2
2
|
import type { ItemArray, ItemConstraints, ItemValue } from "../db/Item.js";
|
|
3
3
|
import type { Updates } from "../update/DataUpdate.js";
|
|
4
4
|
import { Provider, AsyncProvider } from "./Provider.js";
|
|
5
5
|
import type { ThroughProvider, AsyncThroughProvider } from "./ThroughProvider.js";
|
|
6
6
|
/** Provider that logs operations to a source provider to the console. */
|
|
7
|
-
declare abstract class AbstractDebugProvider
|
|
8
|
-
abstract readonly source: Provider
|
|
9
|
-
getItemSequence
|
|
10
|
-
getQuerySequence
|
|
7
|
+
declare abstract class AbstractDebugProvider {
|
|
8
|
+
abstract readonly source: Provider | AsyncProvider;
|
|
9
|
+
getItemSequence(collection: string, id: string): AsyncIterableIterator<ItemValue>;
|
|
10
|
+
getQuerySequence(collection: string, constraints: ItemConstraints): AsyncIterableIterator<ItemArray>;
|
|
11
11
|
}
|
|
12
12
|
/** Provider that logs operations to a synchronous source provider to the console. */
|
|
13
|
-
export declare class DebugProvider
|
|
14
|
-
readonly source: Provider
|
|
15
|
-
constructor(source: Provider
|
|
16
|
-
getItem
|
|
17
|
-
addItem
|
|
18
|
-
setItem
|
|
19
|
-
updateItem
|
|
20
|
-
deleteItem
|
|
21
|
-
getQuery
|
|
22
|
-
setQuery
|
|
23
|
-
updateQuery
|
|
24
|
-
deleteQuery
|
|
13
|
+
export declare class DebugProvider extends AbstractDebugProvider implements ThroughProvider {
|
|
14
|
+
readonly source: Provider;
|
|
15
|
+
constructor(source: Provider);
|
|
16
|
+
getItem(collection: string, id: string): ItemValue;
|
|
17
|
+
addItem(collection: string, data: Data): string;
|
|
18
|
+
setItem(collection: string, id: string, data: Data): void;
|
|
19
|
+
updateItem(collection: string, id: string, updates: Updates): void;
|
|
20
|
+
deleteItem(collection: string, id: string): void;
|
|
21
|
+
getQuery(collection: string, constraints: ItemConstraints): ItemArray;
|
|
22
|
+
setQuery(collection: string, constraints: ItemConstraints, data: Data): number;
|
|
23
|
+
updateQuery(collection: string, constraints: ItemConstraints, updates: Updates): number;
|
|
24
|
+
deleteQuery(collection: string, constraints: ItemConstraints): number;
|
|
25
25
|
}
|
|
26
26
|
/** Provider that logs operations to a synchronous source provider to the console. */
|
|
27
|
-
export declare class AsyncDebugProvider
|
|
28
|
-
readonly source: AsyncProvider
|
|
29
|
-
constructor(source: AsyncProvider
|
|
30
|
-
getItem
|
|
31
|
-
addItem
|
|
32
|
-
setItem
|
|
33
|
-
updateItem
|
|
34
|
-
deleteItem
|
|
35
|
-
getQuery
|
|
36
|
-
setQuery
|
|
37
|
-
updateQuery
|
|
38
|
-
deleteQuery
|
|
27
|
+
export declare class AsyncDebugProvider extends AbstractDebugProvider implements AsyncThroughProvider {
|
|
28
|
+
readonly source: AsyncProvider;
|
|
29
|
+
constructor(source: AsyncProvider);
|
|
30
|
+
getItem(collection: string, id: string): Promise<ItemValue>;
|
|
31
|
+
addItem(collection: string, data: Data): Promise<string>;
|
|
32
|
+
setItem(collection: string, id: string, data: Data): Promise<void>;
|
|
33
|
+
updateItem(collection: string, id: string, updates: Updates): Promise<void>;
|
|
34
|
+
deleteItem(collection: string, id: string): Promise<void>;
|
|
35
|
+
getQuery(collection: string, constraints: ItemConstraints): Promise<ItemArray>;
|
|
36
|
+
setQuery(collection: string, constraints: ItemConstraints, data: Data): Promise<number>;
|
|
37
|
+
updateQuery(collection: string, constraints: ItemConstraints, updates: Updates): Promise<number>;
|
|
38
|
+
deleteQuery(collection: string, constraints: ItemConstraints): Promise<number>;
|
|
39
39
|
}
|
|
40
40
|
export {};
|