shelving 1.80.1 → 1.82.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/constraint/Constraints.js +3 -3
- package/constraint/FilterConstraint.d.ts +5 -5
- package/constraint/FilterConstraints.js +1 -1
- package/constraint/QueryConstraints.js +4 -4
- package/constraint/SortConstraint.d.ts +2 -2
- package/constraint/SortConstraints.js +1 -1
- package/db/Change.d.ts +12 -12
- package/db/Change.js +3 -3
- package/db/Collection.d.ts +4 -9
- package/db/Collection.js +0 -4
- package/db/Database.d.ts +29 -34
- package/db/Database.js +0 -4
- package/db/Item.d.ts +11 -18
- package/db/Item.js +9 -10
- package/db/Query.d.ts +8 -15
- package/db/Query.js +11 -12
- package/firestore/client/FirestoreClientProvider.d.ts +3 -5
- package/firestore/client/FirestoreClientProvider.js +10 -11
- package/firestore/lite/FirestoreLiteProvider.d.ts +3 -4
- package/firestore/lite/FirestoreLiteProvider.js +3 -8
- package/firestore/server/FirestoreServerProvider.d.ts +4 -6
- package/firestore/server/FirestoreServerProvider.js +12 -16
- package/index.d.ts +8 -7
- package/index.js +13 -16
- package/iterate/AbstractGenerator.d.ts +8 -0
- package/iterate/AbstractGenerator.js +26 -0
- package/iterate/InspectGenerator.d.ts +31 -0
- package/iterate/InspectGenerator.js +68 -0
- package/iterate/ThroughGenerator.d.ts +9 -0
- package/iterate/ThroughGenerator.js +18 -0
- package/iterate/index.d.ts +3 -0
- package/iterate/index.js +3 -0
- package/package.json +5 -3
- package/provider/CacheProvider.d.ts +12 -14
- package/provider/CacheProvider.js +12 -38
- package/provider/DebugProvider.d.ts +21 -23
- package/provider/DebugProvider.js +98 -71
- package/provider/MemoryProvider.d.ts +40 -37
- package/provider/MemoryProvider.js +138 -101
- package/provider/Provider.d.ts +54 -73
- package/provider/ThroughProvider.d.ts +23 -25
- package/provider/ThroughProvider.js +8 -8
- package/provider/ValidationProvider.d.ts +22 -24
- package/provider/ValidationProvider.js +18 -37
- package/provider/index.d.ts +0 -1
- package/provider/index.js +0 -1
- package/react/index.d.ts +2 -1
- package/react/index.js +3 -3
- package/react/useCache.d.ts +1 -1
- package/react/useItem.d.ts +7 -11
- package/react/useItem.js +12 -30
- package/react/useQuery.d.ts +9 -11
- package/react/useQuery.js +23 -39
- package/react/useSequence.d.ts +9 -0
- package/react/useSequence.js +19 -0
- package/react/useState.d.ts +11 -0
- package/react/useState.js +12 -0
- package/schema/AllowSchema.d.ts +1 -1
- package/schema/AllowSchema.js +4 -4
- package/schema/DataSchema.d.ts +1 -1
- package/schema/ObjectSchema.d.ts +1 -1
- package/schema/Schema.d.ts +2 -0
- package/sequence/AbstractSequence.d.ts +8 -0
- package/sequence/AbstractSequence.js +26 -0
- package/sequence/DeferredSequence.d.ts +30 -0
- package/sequence/DeferredSequence.js +64 -0
- package/sequence/InspectSequence.d.ts +31 -0
- package/sequence/InspectSequence.js +68 -0
- package/sequence/LazyDeferredSequence.d.ts +9 -0
- package/sequence/LazyDeferredSequence.js +14 -0
- package/sequence/RegisteringSequence.d.ts +9 -0
- package/sequence/RegisteringSequence.js +51 -0
- package/sequence/ThroughSequence.d.ts +9 -0
- package/sequence/ThroughSequence.js +20 -0
- package/sequence/index.d.ts +6 -0
- package/sequence/index.js +6 -0
- package/state/ArrayState.js +4 -4
- package/state/BooleanState.js +1 -1
- package/state/DataState.d.ts +5 -9
- package/state/DataState.js +7 -16
- package/state/ObjectState.d.ts +5 -4
- package/state/ObjectState.js +8 -7
- package/state/State.d.ts +12 -16
- package/state/State.js +27 -49
- package/state/index.d.ts +0 -1
- package/state/index.js +0 -1
- package/test/util.d.ts +12 -2
- package/test/util.js +26 -7
- package/update/ArrayUpdate.js +2 -2
- package/update/DataUpdate.d.ts +8 -9
- package/update/DataUpdate.js +2 -2
- package/util/activity.d.ts +38 -0
- package/util/activity.js +64 -0
- package/util/array.d.ts +40 -111
- package/util/array.js +50 -114
- package/util/async.d.ts +18 -16
- package/util/async.js +21 -33
- package/util/class.d.ts +1 -1
- package/util/constants.d.ts +34 -0
- package/util/constants.js +34 -0
- package/util/data.d.ts +12 -6
- package/util/data.js +5 -0
- package/util/error.d.ts +1 -2
- package/util/error.js +0 -1
- package/util/function.d.ts +6 -0
- package/util/index.d.ts +3 -0
- package/util/index.js +3 -0
- package/util/iterate.d.ts +2 -53
- package/util/iterate.js +3 -90
- package/util/map.d.ts +16 -0
- package/util/map.js +22 -0
- package/util/number.d.ts +2 -5
- package/util/number.js +3 -6
- package/util/object.d.ts +33 -74
- package/util/object.js +19 -63
- package/util/sequence.d.ts +22 -0
- package/util/sequence.js +76 -0
- package/util/set.d.ts +10 -0
- package/util/set.js +17 -0
- package/util/string.d.ts +0 -6
- package/util/string.js +0 -6
- package/util/transform.d.ts +6 -6
- package/util/transform.js +3 -2
- package/util/units.d.ts +105 -92
- package/util/units.js +244 -141
- package/util/validate.d.ts +3 -3
- package/util/validate.js +2 -2
- package/observe/AbstractObserver.d.ts +0 -15
- package/observe/AbstractObserver.js +0 -42
- package/observe/AsyncObserver.d.ts +0 -5
- package/observe/AsyncObserver.js +0 -8
- package/observe/LastSubject.d.ts +0 -5
- package/observe/LastSubject.js +0 -12
- package/observe/MatchObserver.d.ts +0 -9
- package/observe/MatchObserver.js +0 -12
- package/observe/MatchableObserver.d.ts +0 -7
- package/observe/MatchableObserver.js +0 -10
- package/observe/Observable.d.ts +0 -24
- package/observe/Observable.js +0 -4
- package/observe/Observer.d.ts +0 -31
- package/observe/Observer.js +0 -48
- package/observe/OnceObserver.d.ts +0 -5
- package/observe/OnceObserver.js +0 -8
- package/observe/Subject.d.ts +0 -46
- package/observe/Subject.js +0 -116
- package/observe/ThroughObserver.d.ts +0 -5
- package/observe/ThroughObserver.js +0 -8
- package/observe/TransformObserver.d.ts +0 -9
- package/observe/TransformObserver.js +0 -12
- package/observe/TransformableObserver.d.ts +0 -7
- package/observe/TransformableObserver.js +0 -8
- package/observe/index.d.ts +0 -13
- package/observe/index.js +0 -13
- package/observe/util.d.ts +0 -24
- package/observe/util.js +0 -34
- package/provider/BatchProvider.d.ts +0 -26
- package/provider/BatchProvider.js +0 -75
- package/react/useSubscribe.d.ts +0 -9
- package/react/useSubscribe.js +0 -22
- package/state/SelfClosingState.d.ts +0 -18
- package/state/SelfClosingState.js +0 -34
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { withArrayItems, withoutArrayItems } from "../util/array.js";
|
|
2
2
|
import { Constraint } from "./Constraint.js";
|
|
3
3
|
/** Type of Rule that is powered by several sub-constraints (e.g. `Filters` and `Sorts` and `Query` itself extend this). */
|
|
4
4
|
export class Constraints extends Constraint {
|
|
@@ -20,12 +20,12 @@ export class Constraints extends Constraint {
|
|
|
20
20
|
}
|
|
21
21
|
/** Clone this set of constraints but add additional constraints. */
|
|
22
22
|
with(...constraints) {
|
|
23
|
-
const _constraints =
|
|
23
|
+
const _constraints = withArrayItems(this._constraints, ...constraints);
|
|
24
24
|
return _constraints !== this._constraints ? { __proto__: Object.getPrototypeOf(this), ...this, _constraints: _constraints } : this;
|
|
25
25
|
}
|
|
26
26
|
/** Clone this set of constraints but remove specific constraints. */
|
|
27
27
|
without(...constraints) {
|
|
28
|
-
const _constraints =
|
|
28
|
+
const _constraints = withoutArrayItems(this._constraints, ...constraints);
|
|
29
29
|
return _constraints !== this._constraints ? { __proto__: Object.getPrototypeOf(this), ...this, _constraints: _constraints } : this;
|
|
30
30
|
}
|
|
31
31
|
/** Iterate over the constraints. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Data,
|
|
1
|
+
import type { Data, DataKey } from "../util/data.js";
|
|
2
2
|
import type { Nullish } from "../util/null.js";
|
|
3
3
|
import { ImmutableArray } from "../util/array.js";
|
|
4
4
|
import { Matchable } from "../util/match.js";
|
|
@@ -6,14 +6,14 @@ import type { Constraint } from "./Constraint.js";
|
|
|
6
6
|
/** Possible operator references. */
|
|
7
7
|
export declare type FilterOperator = "IS" | "NOT" | "IN" | "OUT" | "CONTAINS" | "LT" | "LTE" | "GT" | "GTE";
|
|
8
8
|
/** Format that allows filters to be specified as a string, e.g. `!name` means `name is not` and `age>` means `age is more than` and `tags[]` means `tags array contains` */
|
|
9
|
-
export declare type FilterKey<T extends Data> =
|
|
9
|
+
export declare type FilterKey<T extends Data> = DataKey<T> | `${DataKey<T>}` | `!${DataKey<T>}` | `${DataKey<T>}[]` | `${DataKey<T>}<` | `${DataKey<T>}<=` | `${DataKey<T>}>` | `${DataKey<T>}>=`;
|
|
10
10
|
/** Format that allows multiple filters to be specified as a plain object. */
|
|
11
11
|
export declare type FilterProps<T extends Data> = {
|
|
12
|
-
[K in
|
|
12
|
+
[K in DataKey<T> as `${K}` | `!${K}`]?: T[K] | ImmutableArray<T[K]>;
|
|
13
13
|
} & {
|
|
14
|
-
[K in
|
|
14
|
+
[K in DataKey<T> as `${K}[]`]?: Required<T>[K] extends ImmutableArray<infer X> ? X : never;
|
|
15
15
|
} & {
|
|
16
|
-
[K in
|
|
16
|
+
[K in DataKey<T> as `${K}<` | `${K}<=` | `${K}>` | `${K}>=`]?: T[K];
|
|
17
17
|
};
|
|
18
18
|
/** List of filters in a flexible format. */
|
|
19
19
|
export declare type FilterList<T extends Data> = Nullish<FilterProps<T> | FilterConstraint<T>> | Iterable<FilterList<T>>;
|
|
@@ -22,6 +22,6 @@ export class FilterConstraints extends Constraints {
|
|
|
22
22
|
}
|
|
23
23
|
// Stringify as object syntax.
|
|
24
24
|
toString() {
|
|
25
|
-
return `{${this._constraints.map(String).join(",")}
|
|
25
|
+
return this._constraints.length ? `"filters":{${this._constraints.map(String).join(",")}}` : "";
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getObjectProp } from "../util/object.js";
|
|
2
2
|
import { assert } from "../util/assert.js";
|
|
3
3
|
import { limitItems } from "../util/iterate.js";
|
|
4
4
|
import { FilterConstraints } from "./FilterConstraints.js";
|
|
@@ -87,7 +87,7 @@ export class QueryConstraints extends Constraint {
|
|
|
87
87
|
}
|
|
88
88
|
// Implement toString()
|
|
89
89
|
toString() {
|
|
90
|
-
return
|
|
90
|
+
return [this.filters.toString(), this.sorts.toString(), typeof this.limit === "number" ? `"limit":${this.limit}` : null].filter(Boolean).join(",");
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
function* _getAfterFilters(sorts, item) {
|
|
@@ -96,7 +96,7 @@ function* _getAfterFilters(sorts, item) {
|
|
|
96
96
|
for (const sort of sorts) {
|
|
97
97
|
const { key, direction } = sort;
|
|
98
98
|
const filterKey = direction === "ASC" ? (sort === lastSort ? `${key}>` : `${key}>=`) : sort === lastSort ? `${key}<` : `${key}<=`;
|
|
99
|
-
yield new FilterConstraint(filterKey,
|
|
99
|
+
yield new FilterConstraint(filterKey, getObjectProp(item, key));
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
function* _getBeforeFilters(sorts, item) {
|
|
@@ -105,6 +105,6 @@ function* _getBeforeFilters(sorts, item) {
|
|
|
105
105
|
for (const sort of sorts) {
|
|
106
106
|
const { key, direction } = sort;
|
|
107
107
|
const filterKey = direction === "ASC" ? (sort === lastSort ? `${key}<` : `${key}<=`) : sort === lastSort ? `${key}>` : `${key}>=`;
|
|
108
|
-
yield new FilterConstraint(filterKey,
|
|
108
|
+
yield new FilterConstraint(filterKey, getObjectProp(item, key));
|
|
109
109
|
}
|
|
110
110
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { ImmutableArray } from "../util/array.js";
|
|
2
|
-
import type { Data,
|
|
2
|
+
import type { Data, DataKey } from "../util/data.js";
|
|
3
3
|
import type { Nullish } from "../util/null.js";
|
|
4
4
|
import { Rankable } from "../util/sort.js";
|
|
5
5
|
import type { Constraint } from "./Constraint.js";
|
|
6
6
|
/** Format that allows sorts to be set as a plain string, e.g. `name` sorts by name in ascending order and `!date` sorts by date in descending order. */
|
|
7
|
-
export declare type SortKey<T extends Data> =
|
|
7
|
+
export declare type SortKey<T extends Data> = DataKey<T> | `${DataKey<T>}` | `!${DataKey<T>}`;
|
|
8
8
|
/** One or more sort keys. */
|
|
9
9
|
export declare type SortKeys<T extends Data> = SortKey<T> | ImmutableArray<SortKey<T>>;
|
|
10
10
|
/** Possible operator references. */
|
|
@@ -24,6 +24,6 @@ export class SortConstraints extends Constraints {
|
|
|
24
24
|
}
|
|
25
25
|
// Stringify as array syntax.
|
|
26
26
|
toString() {
|
|
27
|
-
return `[${this._constraints.map(String).join(",")}]
|
|
27
|
+
return this._constraints.length ? `"sorts":[${this._constraints.map(String).join(",")}]` : "";
|
|
28
28
|
}
|
|
29
29
|
}
|
package/db/Change.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Data, Datas,
|
|
1
|
+
import type { Data, Datas, DataKey } from "../util/data.js";
|
|
2
2
|
import type { ImmutableArray } from "../util/array.js";
|
|
3
3
|
import type { Provider, AsyncProvider } from "../provider/Provider.js";
|
|
4
4
|
import { Updates } from "../update/DataUpdate.js";
|
|
@@ -6,42 +6,42 @@ import { Nullish } from "../util/null.js";
|
|
|
6
6
|
import { DeepIterable } from "../util/iterate.js";
|
|
7
7
|
import type { ItemConstraints, ItemData } from "./Item.js";
|
|
8
8
|
/** Change on a collection. */
|
|
9
|
-
export interface Change<T extends Datas, K extends
|
|
9
|
+
export interface Change<T extends Datas, K extends DataKey<T> = DataKey<T>> {
|
|
10
10
|
readonly action: string;
|
|
11
11
|
readonly collection: K;
|
|
12
12
|
}
|
|
13
13
|
/** Add on an item. */
|
|
14
|
-
export interface AddChange<T extends Datas, K extends
|
|
14
|
+
export interface AddChange<T extends Datas, K extends DataKey<T> = DataKey<T>> extends Change<T, K> {
|
|
15
15
|
readonly action: "ADD";
|
|
16
16
|
readonly data: T[K];
|
|
17
17
|
}
|
|
18
18
|
/** Set on an item. */
|
|
19
|
-
export interface SetChange<T extends Datas, K extends
|
|
19
|
+
export interface SetChange<T extends Datas, K extends DataKey<T> = DataKey<T>> extends Change<T, K> {
|
|
20
20
|
readonly action: "SET";
|
|
21
21
|
readonly id: string;
|
|
22
22
|
readonly data: T[K];
|
|
23
23
|
}
|
|
24
24
|
/** Update change on an item. */
|
|
25
|
-
export interface UpdateChange<T extends Datas, K extends
|
|
25
|
+
export interface UpdateChange<T extends Datas, K extends DataKey<T> = DataKey<T>> extends Change<T, K> {
|
|
26
26
|
readonly action: "UPDATE";
|
|
27
27
|
readonly id: string;
|
|
28
28
|
readonly updates: Updates<T[K]>;
|
|
29
29
|
}
|
|
30
30
|
/** Delete change on an item. */
|
|
31
|
-
export interface DeleteChange<T extends Datas, K extends
|
|
31
|
+
export interface DeleteChange<T extends Datas, K extends DataKey<T> = DataKey<T>> extends Change<T, K> {
|
|
32
32
|
readonly action: "DELETE";
|
|
33
33
|
readonly id: string;
|
|
34
34
|
}
|
|
35
35
|
/** Set, update, or delete change on an item. */
|
|
36
|
-
export declare type ItemChange<T extends Datas, K extends
|
|
36
|
+
export declare type ItemChange<T extends Datas, K extends DataKey<T> = DataKey<T>> = SetChange<T, K> | UpdateChange<T, K> | DeleteChange<T, K>;
|
|
37
37
|
/** Array of item changes. */
|
|
38
|
-
export declare type ItemChanges<T extends Datas, K extends
|
|
38
|
+
export declare type ItemChanges<T extends Datas, K extends DataKey<T> = DataKey<T>> = ImmutableArray<ItemChange<T, K>>;
|
|
39
39
|
/** Write change on an item. */
|
|
40
|
-
export declare type WriteChange<T extends Datas, K extends
|
|
40
|
+
export declare type WriteChange<T extends Datas, K extends DataKey<T> = DataKey<T>> = ItemChange<T, K> | AddChange<T, K>;
|
|
41
41
|
/** Array of write changes. */
|
|
42
|
-
export declare type WriteChanges<T extends Datas, K extends
|
|
42
|
+
export declare type WriteChanges<T extends Datas, K extends DataKey<T> = DataKey<T>> = ImmutableArray<WriteChange<T, K>>;
|
|
43
43
|
/** Apply a set of changes to a synchronous provider. */
|
|
44
|
-
export declare function changeProvider<T extends Datas, K extends
|
|
44
|
+
export declare function changeProvider<T extends Datas, K extends DataKey<T>>(provider: Provider<T>, ...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): ItemChanges<T, K>;
|
|
45
45
|
/** Apply a set of changes to an asynchronous provider. */
|
|
46
|
-
export declare function changeAsyncProvider<T extends Datas, K extends
|
|
46
|
+
export declare function changeAsyncProvider<T extends Datas, K extends DataKey<T>>(provider: AsyncProvider<T>, ...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): Promise<ItemChanges<T, K>>;
|
|
47
47
|
export declare function _getItemConstraint<T extends Data>(id: string): ItemConstraints<ItemData<T>>;
|
package/db/Change.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { QueryConstraints } from "../constraint/QueryConstraints.js";
|
|
2
2
|
import { FilterConstraint } from "../constraint/FilterConstraint.js";
|
|
3
3
|
import { notNullish } from "../util/null.js";
|
|
4
|
-
import {
|
|
4
|
+
import { flattenItems } from "../util/iterate.js";
|
|
5
5
|
/** Apply a set of changes to a synchronous provider. */
|
|
6
6
|
export function changeProvider(provider, ...changes) {
|
|
7
|
-
return Array.from(
|
|
7
|
+
return Array.from(flattenItems(changes)).filter(notNullish).map(_changeItem, provider);
|
|
8
8
|
}
|
|
9
9
|
function _changeItem(change) {
|
|
10
10
|
const { action, collection } = change;
|
|
@@ -20,7 +20,7 @@ function _changeItem(change) {
|
|
|
20
20
|
}
|
|
21
21
|
/** Apply a set of changes to an asynchronous provider. */
|
|
22
22
|
export function changeAsyncProvider(provider, ...changes) {
|
|
23
|
-
return Promise.all(Array.from(
|
|
23
|
+
return Promise.all(Array.from(flattenItems(changes)).filter(notNullish).map(_changeAsyncItem, provider));
|
|
24
24
|
}
|
|
25
25
|
async function _changeAsyncItem(change) {
|
|
26
26
|
const { collection, action } = change;
|
package/db/Collection.d.ts
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import type { Datas,
|
|
1
|
+
import type { Datas, DataKey } from "../util/data.js";
|
|
2
2
|
import type { Nullish } from "../util/null.js";
|
|
3
3
|
import type { FilterList } from "../constraint/FilterConstraint.js";
|
|
4
4
|
import type { SortList } from "../constraint/SortConstraint.js";
|
|
5
5
|
import type { DeepIterable } from "../util/iterate.js";
|
|
6
6
|
import type { Updates } from "../update/DataUpdate.js";
|
|
7
|
-
import type { PartialObserver } from "../observe/Observer.js";
|
|
8
|
-
import type { Dispatch } from "../util/function.js";
|
|
9
|
-
import type { Unsubscribe } from "../observe/Observable.js";
|
|
10
7
|
import type { AsyncDatabase, Database } from "./Database.js";
|
|
11
8
|
import { ItemData, AsyncItem, Item, ItemValue } from "./Item.js";
|
|
12
9
|
import { AsyncQuery, Query } from "./Query.js";
|
|
13
10
|
import { AddChange, ItemChanges, WriteChange, UpdateChange, DeleteChange, SetChange } from "./Change.js";
|
|
14
11
|
/** Reference to a collection in a synchronous or asynchronous provider. */
|
|
15
|
-
declare abstract class BaseCollection<T extends Datas = Datas, K extends
|
|
12
|
+
declare abstract class BaseCollection<T extends Datas = Datas, K extends DataKey<T> = DataKey<T>> {
|
|
16
13
|
abstract readonly db: Database<T> | AsyncDatabase<T>;
|
|
17
14
|
abstract readonly collection: K;
|
|
18
15
|
/** Create a query on this item's collection. */
|
|
@@ -23,8 +20,6 @@ declare abstract class BaseCollection<T extends Datas = Datas, K extends Key<T>
|
|
|
23
20
|
abstract change(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): ItemChanges<T, K> | Promise<ItemChanges<T, K>>;
|
|
24
21
|
/** Get an item from this collection. */
|
|
25
22
|
abstract get(id: string): ItemValue<T[K]> | Promise<ItemValue<T[K]>>;
|
|
26
|
-
/** Subscribe a document from a collection in this database. */
|
|
27
|
-
subscribe(id: string, next: PartialObserver<ItemValue<T[K]>> | Dispatch<[ItemValue<T[K]>]>): Unsubscribe;
|
|
28
23
|
/** Add an item to this collection. */
|
|
29
24
|
abstract add(data: T[K]): string | Promise<string>;
|
|
30
25
|
/** Set a document in this collection. */
|
|
@@ -44,7 +39,7 @@ declare abstract class BaseCollection<T extends Datas = Datas, K extends Key<T>
|
|
|
44
39
|
toString(): K;
|
|
45
40
|
}
|
|
46
41
|
/** Reference to a collection in a synchronous provider. */
|
|
47
|
-
export declare class Collection<T extends Datas = Datas, K extends
|
|
42
|
+
export declare class Collection<T extends Datas = Datas, K extends DataKey<T> = DataKey<T>> extends BaseCollection<T, K> {
|
|
48
43
|
readonly db: Database<T>;
|
|
49
44
|
readonly collection: K;
|
|
50
45
|
constructor(db: Database<T>, collection: K);
|
|
@@ -58,7 +53,7 @@ export declare class Collection<T extends Datas = Datas, K extends Key<T> = Key<
|
|
|
58
53
|
delete(id: string): void;
|
|
59
54
|
}
|
|
60
55
|
/** Reference to a collection in an asynchronous provider. */
|
|
61
|
-
export declare class AsyncCollection<T extends Datas = Datas, K extends
|
|
56
|
+
export declare class AsyncCollection<T extends Datas = Datas, K extends DataKey<T> = DataKey<T>> extends BaseCollection<T, K> {
|
|
62
57
|
readonly db: AsyncDatabase<T>;
|
|
63
58
|
readonly collection: K;
|
|
64
59
|
constructor(db: AsyncDatabase<T>, collection: K);
|
package/db/Collection.js
CHANGED
|
@@ -3,10 +3,6 @@ import { AsyncQuery, Query } from "./Query.js";
|
|
|
3
3
|
import { changeAsyncProvider, changeProvider } from "./Change.js";
|
|
4
4
|
/** Reference to a collection in a synchronous or asynchronous provider. */
|
|
5
5
|
class BaseCollection {
|
|
6
|
-
/** Subscribe a document from a collection in this database. */
|
|
7
|
-
subscribe(id, next) {
|
|
8
|
-
return this.db.subscribe(this.collection, id, typeof next === "function" ? { next } : next);
|
|
9
|
-
}
|
|
10
6
|
/** Get an add change for this collection. */
|
|
11
7
|
getAdd(data) {
|
|
12
8
|
return this.db.getAdd(this.collection, data);
|
package/db/Database.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DataKey, Datas } from "../util/data.js";
|
|
2
2
|
import type { Nullish } from "../util/null.js";
|
|
3
3
|
import type { DeepIterable } from "../util/iterate.js";
|
|
4
4
|
import type { AsyncProvider, Provider } from "../provider/Provider.js";
|
|
@@ -6,9 +6,6 @@ import type { FilterList } from "../constraint/FilterConstraint.js";
|
|
|
6
6
|
import type { SortList } from "../constraint/SortConstraint.js";
|
|
7
7
|
import type { ItemData, ItemValue } from "../db/Item.js";
|
|
8
8
|
import type { Updates } from "../update/DataUpdate.js";
|
|
9
|
-
import type { PartialObserver } from "../observe/Observer.js";
|
|
10
|
-
import type { Dispatch } from "../util/function.js";
|
|
11
|
-
import type { Unsubscribe } from "../observe/Observable.js";
|
|
12
9
|
import { Item, AsyncItem } from "./Item.js";
|
|
13
10
|
import { Query, AsyncQuery } from "./Query.js";
|
|
14
11
|
import { Collection, AsyncCollection } from "./Collection.js";
|
|
@@ -17,60 +14,58 @@ import { AddChange, DeleteChange, ItemChanges, SetChange, UpdateChange, WriteCha
|
|
|
17
14
|
declare abstract class BaseDatabase<T extends Datas> {
|
|
18
15
|
abstract readonly provider: Provider<T> | AsyncProvider<T>;
|
|
19
16
|
/** Create a query on a collection in this database. */
|
|
20
|
-
abstract collection<K extends
|
|
17
|
+
abstract collection<K extends DataKey<T>>(collection: K): Collection<T, K> | AsyncCollection<T, K>;
|
|
21
18
|
/** Create a query on a collection in this database. */
|
|
22
|
-
abstract query<K extends
|
|
19
|
+
abstract query<K extends DataKey<T>>(collection: K, filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): Query<T, K> | AsyncQuery<T, K>;
|
|
23
20
|
/** Reference an item in a collection in this database. */
|
|
24
|
-
abstract item<K extends
|
|
21
|
+
abstract item<K extends DataKey<T>>(collection: K, id: string): Item<T, K> | AsyncItem<T, K>;
|
|
25
22
|
/** Run a set of changes in this database. */
|
|
26
23
|
abstract change(...changes: DeepIterable<Nullish<WriteChange<T>>>[]): ItemChanges<T> | Promise<ItemChanges<T>>;
|
|
27
24
|
/** Get a document from a collection in this database. */
|
|
28
|
-
abstract get<K extends
|
|
29
|
-
/** Subscribe a document from a collection in this database. */
|
|
30
|
-
subscribe<K extends Key<T>>(collection: K, id: string, next: PartialObserver<ItemValue<T[K]>> | Dispatch<[ItemValue<T[K]>]>): Unsubscribe;
|
|
25
|
+
abstract get<K extends DataKey<T>>(collection: K, id: string): ItemValue<T[K]> | Promise<ItemValue<T[K]>>;
|
|
31
26
|
/** Add a document to a collection in this database. */
|
|
32
|
-
abstract add<K extends
|
|
27
|
+
abstract add<K extends DataKey<T>>(collection: K, data: T[K]): string | Promise<string>;
|
|
33
28
|
/** Set a document in a collection in this database. */
|
|
34
|
-
abstract set<K extends
|
|
29
|
+
abstract set<K extends DataKey<T>>(collection: K, id: string, data: T[K]): void | Promise<void>;
|
|
35
30
|
/** Update a document in a collection in this database. */
|
|
36
|
-
abstract update<K extends
|
|
31
|
+
abstract update<K extends DataKey<T>>(collection: K, id: string, updates: Updates<T[K]>): void | Promise<void>;
|
|
37
32
|
/** Delete a document from a collection in this database. */
|
|
38
|
-
abstract delete<K extends
|
|
33
|
+
abstract delete<K extends DataKey<T>>(collection: K, id: string): void | Promise<void>;
|
|
39
34
|
/** Get an add change for a collection in this database. */
|
|
40
|
-
getAdd<K extends
|
|
35
|
+
getAdd<K extends DataKey<T>>(collection: K, data: T[K]): AddChange<T, K>;
|
|
41
36
|
/** Get a set change for a collection in this database. */
|
|
42
|
-
getSet<K extends
|
|
37
|
+
getSet<K extends DataKey<T>>(collection: K, id: string, data: T[K]): SetChange<T, K>;
|
|
43
38
|
/** Get an update change for a collection in this database. */
|
|
44
|
-
getUpdate<K extends
|
|
39
|
+
getUpdate<K extends DataKey<T>>(collection: K, id: string, updates: Updates<T[K]>): UpdateChange<T, K>;
|
|
45
40
|
/** Get a delete change for a collection in this database. */
|
|
46
|
-
getDelete<K extends
|
|
41
|
+
getDelete<K extends DataKey<T>>(collection: K, id: string): DeleteChange<T, K>;
|
|
47
42
|
}
|
|
48
43
|
/** Database with a synchronous provider. */
|
|
49
44
|
export declare class Database<T extends Datas = Datas> extends BaseDatabase<T> {
|
|
50
45
|
readonly provider: Provider<T>;
|
|
51
46
|
constructor(provider: Provider<T>);
|
|
52
|
-
collection<K extends
|
|
53
|
-
query<K extends
|
|
54
|
-
item<K extends
|
|
47
|
+
collection<K extends DataKey<T>>(collection: K): Collection<T, K>;
|
|
48
|
+
query<K extends DataKey<T>>(collection: K, filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): Query<T, K>;
|
|
49
|
+
item<K extends DataKey<T>>(collection: K, id: string): Item<T, K>;
|
|
55
50
|
change(...changes: DeepIterable<Nullish<WriteChange<T>>>[]): ItemChanges<T>;
|
|
56
|
-
get<K extends
|
|
57
|
-
add<K extends
|
|
58
|
-
set<K extends
|
|
59
|
-
update<K extends
|
|
60
|
-
delete<K extends
|
|
51
|
+
get<K extends DataKey<T>>(collection: K, id: string): ItemValue<T[K]>;
|
|
52
|
+
add<K extends DataKey<T>>(collection: K, data: T[K]): string;
|
|
53
|
+
set<K extends DataKey<T>>(collection: K, id: string, data: T[K]): void;
|
|
54
|
+
update<K extends DataKey<T>>(collection: K, id: string, updates: Updates<T[K]>): void;
|
|
55
|
+
delete<K extends DataKey<T>>(collection: K, id: string): void;
|
|
61
56
|
}
|
|
62
57
|
/** Database with a synchronous provider. */
|
|
63
58
|
export declare class AsyncDatabase<T extends Datas = Datas> extends BaseDatabase<T> {
|
|
64
59
|
readonly provider: AsyncProvider<T>;
|
|
65
60
|
constructor(provider: AsyncProvider<T>);
|
|
66
|
-
collection<K extends
|
|
67
|
-
query<K extends
|
|
68
|
-
item<K extends
|
|
61
|
+
collection<K extends DataKey<T>>(collection: K): AsyncCollection<T, K>;
|
|
62
|
+
query<K extends DataKey<T>>(collection: K, filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): AsyncQuery<T, K>;
|
|
63
|
+
item<K extends DataKey<T>>(collection: K, id: string): AsyncItem<T, K>;
|
|
69
64
|
change(...changes: DeepIterable<Nullish<WriteChange<T>>>[]): Promise<ItemChanges<T>>;
|
|
70
|
-
get<K extends
|
|
71
|
-
add<K extends
|
|
72
|
-
set<K extends
|
|
73
|
-
update<K extends
|
|
74
|
-
delete<K extends
|
|
65
|
+
get<K extends DataKey<T>>(collection: K, id: string): Promise<ItemValue<T[K]>>;
|
|
66
|
+
add<K extends DataKey<T>>(collection: K, data: T[K]): Promise<string>;
|
|
67
|
+
set<K extends DataKey<T>>(collection: K, id: string, data: T[K]): Promise<void>;
|
|
68
|
+
update<K extends DataKey<T>>(collection: K, id: string, updates: Updates<T[K]>): Promise<void>;
|
|
69
|
+
delete<K extends DataKey<T>>(collection: K, id: string): Promise<void>;
|
|
75
70
|
}
|
|
76
71
|
export {};
|
package/db/Database.js
CHANGED
|
@@ -4,10 +4,6 @@ import { Collection, AsyncCollection } from "./Collection.js";
|
|
|
4
4
|
import { changeAsyncProvider, changeProvider } from "./Change.js";
|
|
5
5
|
/** Database with a synchronous or asynchronous provider. */
|
|
6
6
|
class BaseDatabase {
|
|
7
|
-
/** Subscribe a document from a collection in this database. */
|
|
8
|
-
subscribe(collection, id, next) {
|
|
9
|
-
return this.provider.subscribeItem(collection, id, typeof next === "function" ? { next } : next);
|
|
10
|
-
}
|
|
11
7
|
/** Get an add change for a collection in this database. */
|
|
12
8
|
getAdd(collection, data) {
|
|
13
9
|
return { action: "ADD", collection, data };
|
package/db/Item.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { Data, Datas, Key } from "../util/data.js";
|
|
2
|
-
import type { Dispatch } from "../util/function.js";
|
|
3
|
-
import type { PartialObserver } from "../observe/Observer.js";
|
|
4
1
|
import type { ImmutableArray } from "../util/array.js";
|
|
5
|
-
import type {
|
|
6
|
-
import { DataUpdate, Updates } from "../update/DataUpdate.js";
|
|
2
|
+
import type { Stop, Handler, Dispatch } from "../util/function.js";
|
|
7
3
|
import type { QueryConstraints } from "../constraint/QueryConstraints.js";
|
|
8
|
-
import
|
|
9
|
-
import
|
|
4
|
+
import { Data, Datas, DataKey } from "../util/data.js";
|
|
5
|
+
import { DataUpdate, Updates } from "../update/DataUpdate.js";
|
|
10
6
|
import type { DeleteChange, SetChange, UpdateChange } from "./Change.js";
|
|
7
|
+
import type { AsyncQuery, Query } from "./Query.js";
|
|
8
|
+
import type { AsyncDatabase, Database } from "./Database.js";
|
|
11
9
|
/** Item data with a string ID that uniquely identifies it. */
|
|
12
10
|
export declare type ItemData<T extends Data = Data> = T & {
|
|
13
11
|
id: string;
|
|
@@ -19,7 +17,7 @@ export declare type ItemArray<T extends Data = Data> = ImmutableArray<ItemData<T
|
|
|
19
17
|
/** A set of query constraints for item data. */
|
|
20
18
|
export declare type ItemConstraints<T extends Data = Data> = QueryConstraints<ItemData<T>>;
|
|
21
19
|
/** Reference to an item in a synchronous or asynchronous database. */
|
|
22
|
-
declare abstract class BaseItem<T extends Datas = Datas, K extends
|
|
20
|
+
declare abstract class BaseItem<T extends Datas = Datas, K extends DataKey<T> = DataKey<T>> implements AsyncIterable<ItemValue<T[K]>> {
|
|
23
21
|
abstract readonly db: Database<T> | AsyncDatabase<T>;
|
|
24
22
|
abstract readonly collection: K;
|
|
25
23
|
abstract readonly id: string;
|
|
@@ -43,14 +41,6 @@ declare abstract class BaseItem<T extends Datas = Datas, K extends Key<T> = Key<
|
|
|
43
41
|
* @throws RequiredError if the item does not exist.
|
|
44
42
|
*/
|
|
45
43
|
abstract data: ItemData<T[K]> | PromiseLike<ItemData<T[K]>>;
|
|
46
|
-
/**
|
|
47
|
-
* Subscribe to the result of this item (indefinitely).
|
|
48
|
-
* - `next()` is called once with the initial result, and again any time the result changes.
|
|
49
|
-
*
|
|
50
|
-
* @param next Observer with `next`, `error`, or `complete` methods or a `next()` dispatcher.
|
|
51
|
-
* @return Function that ends the subscription.
|
|
52
|
-
*/
|
|
53
|
-
subscribe(next: PartialObserver<ItemValue<T[K]>> | Dispatch<[ItemValue<T[K]>]>): Unsubscribe;
|
|
54
44
|
/** Set the complete data of this item. */
|
|
55
45
|
abstract set(data: T[K]): void | PromiseLike<void>;
|
|
56
46
|
/** Update this item. */
|
|
@@ -64,9 +54,12 @@ declare abstract class BaseItem<T extends Datas = Datas, K extends Key<T> = Key<
|
|
|
64
54
|
/** Get a delete change for this item. */
|
|
65
55
|
getDelete(): DeleteChange<T, K>;
|
|
66
56
|
toString(): `${K}/${string}`;
|
|
57
|
+
/** Subscribe to this item. */
|
|
58
|
+
subscribe(onNext?: Dispatch<[ItemValue<T[K]>]>, onError?: Handler): Stop;
|
|
59
|
+
[Symbol.asyncIterator](): AsyncIterator<ItemValue<T[K]>>;
|
|
67
60
|
}
|
|
68
61
|
/** Reference to an item in a synchronous database. */
|
|
69
|
-
export declare class Item<T extends Datas = Datas, K extends
|
|
62
|
+
export declare class Item<T extends Datas = Datas, K extends DataKey<T> = DataKey<T>> extends BaseItem<T, K> {
|
|
70
63
|
readonly db: Database<T>;
|
|
71
64
|
readonly collection: K;
|
|
72
65
|
readonly id: string;
|
|
@@ -80,7 +73,7 @@ export declare class Item<T extends Datas = Datas, K extends Key<T> = Key<T>> ex
|
|
|
80
73
|
delete(): void;
|
|
81
74
|
}
|
|
82
75
|
/** Reference to an item in an asynchronous database. */
|
|
83
|
-
export declare class AsyncItem<T extends Datas = Datas, K extends
|
|
76
|
+
export declare class AsyncItem<T extends Datas = Datas, K extends DataKey<T> = DataKey<T>> extends BaseItem<T, K> {
|
|
84
77
|
readonly db: AsyncDatabase<T>;
|
|
85
78
|
readonly collection: K;
|
|
86
79
|
readonly id: string;
|
package/db/Item.js
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
import { getData } from "../util/data.js";
|
|
2
2
|
import { FilterConstraint } from "../constraint/FilterConstraint.js";
|
|
3
|
+
import { runSequence } from "../util/sequence.js";
|
|
3
4
|
/** Reference to an item in a synchronous or asynchronous database. */
|
|
4
5
|
class BaseItem {
|
|
5
|
-
/**
|
|
6
|
-
* Subscribe to the result of this item (indefinitely).
|
|
7
|
-
* - `next()` is called once with the initial result, and again any time the result changes.
|
|
8
|
-
*
|
|
9
|
-
* @param next Observer with `next`, `error`, or `complete` methods or a `next()` dispatcher.
|
|
10
|
-
* @return Function that ends the subscription.
|
|
11
|
-
*/
|
|
12
|
-
subscribe(next) {
|
|
13
|
-
return this.db.subscribe(this.collection, this.id, next);
|
|
14
|
-
}
|
|
15
6
|
/** Get a set change for this item. */
|
|
16
7
|
getSet(data) {
|
|
17
8
|
return this.db.getSet(this.collection, this.id, data);
|
|
@@ -28,6 +19,14 @@ class BaseItem {
|
|
|
28
19
|
toString() {
|
|
29
20
|
return `${this.collection}/${this.id}`;
|
|
30
21
|
}
|
|
22
|
+
/** Subscribe to this item. */
|
|
23
|
+
subscribe(onNext, onError) {
|
|
24
|
+
return runSequence(this, onNext, onError);
|
|
25
|
+
}
|
|
26
|
+
// Implement AsyncIterable
|
|
27
|
+
[Symbol.asyncIterator]() {
|
|
28
|
+
return this.db.provider.getItemSequence(this.collection, this.id)[Symbol.asyncIterator]();
|
|
29
|
+
}
|
|
31
30
|
}
|
|
32
31
|
/** Reference to an item in a synchronous database. */
|
|
33
32
|
export class Item extends BaseItem {
|
package/db/Query.d.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { DataKey, Datas } from "../util/data.js";
|
|
2
|
+
import type { Dispatch, Handler, Stop } from "../util/function.js";
|
|
3
3
|
import type { Updates } from "../update/DataUpdate.js";
|
|
4
|
-
import type { PartialObserver } from "../observe/Observer.js";
|
|
5
|
-
import type { Observable, Unsubscribe } from "../observe/Observable.js";
|
|
6
4
|
import type { FilterList } from "../constraint/FilterConstraint.js";
|
|
7
5
|
import type { SortList } from "../constraint/SortConstraint.js";
|
|
8
6
|
import { QueryConstraints } from "../constraint/QueryConstraints.js";
|
|
9
7
|
import type { ItemArray, ItemValue, ItemData } from "./Item.js";
|
|
10
8
|
import type { AsyncDatabase, Database } from "./Database.js";
|
|
11
9
|
/** Reference to a set of items in a sync or async provider. */
|
|
12
|
-
declare abstract class BaseQuery<T extends Datas = Datas, K extends
|
|
10
|
+
declare abstract class BaseQuery<T extends Datas = Datas, K extends DataKey<T> = DataKey<T>> extends QueryConstraints<ItemData<T[K]>> implements AsyncIterable<ItemArray<T[K]>> {
|
|
13
11
|
abstract readonly db: Database<T> | AsyncDatabase<T>;
|
|
14
12
|
abstract readonly collection: K;
|
|
15
13
|
/**
|
|
@@ -47,14 +45,6 @@ declare abstract class BaseQuery<T extends Datas = Datas, K extends Key<T> = Key
|
|
|
47
45
|
* @throws RequiredError if there were no results for this query.
|
|
48
46
|
*/
|
|
49
47
|
abstract lastData: ItemData<T[K]> | PromiseLike<ItemData<T[K]>>;
|
|
50
|
-
/**
|
|
51
|
-
* Subscribe to all matching items.
|
|
52
|
-
* - `next()` is called once with the initial results, and again any time the results change.
|
|
53
|
-
*
|
|
54
|
-
* @param next Observer with `next`, `error`, or `complete` methods or a `next()` dispatcher.
|
|
55
|
-
* @return Function that ends the subscription.
|
|
56
|
-
*/
|
|
57
|
-
subscribe(next: PartialObserver<ItemArray<T[K]>> | Dispatch<[ItemArray<T[K]>]>): Unsubscribe;
|
|
58
48
|
/**
|
|
59
49
|
* Set all matching items to the same exact value.
|
|
60
50
|
*
|
|
@@ -75,9 +65,12 @@ declare abstract class BaseQuery<T extends Datas = Datas, K extends Key<T> = Key
|
|
|
75
65
|
*/
|
|
76
66
|
abstract delete(): number | PromiseLike<number>;
|
|
77
67
|
toString(): string;
|
|
68
|
+
/** Subscribe to this item. */
|
|
69
|
+
subscribe(onNext?: Dispatch<[ItemArray<T[K]>]>, onError?: Handler): Stop;
|
|
70
|
+
[Symbol.asyncIterator](): AsyncIterator<ItemArray<T[K]>>;
|
|
78
71
|
}
|
|
79
72
|
/** Reference to a set of items in a provider. */
|
|
80
|
-
export declare class Query<T extends Datas = Datas, K extends
|
|
73
|
+
export declare class Query<T extends Datas = Datas, K extends DataKey<T> = DataKey<T>> extends BaseQuery<T, K> {
|
|
81
74
|
readonly db: Database<T>;
|
|
82
75
|
readonly collection: K;
|
|
83
76
|
constructor(db: Database<T>, collection: K, filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null);
|
|
@@ -93,7 +86,7 @@ export declare class Query<T extends Datas = Datas, K extends Key<T> = Key<T>> e
|
|
|
93
86
|
delete(): number;
|
|
94
87
|
}
|
|
95
88
|
/** Reference to a set of items in a provider. */
|
|
96
|
-
export declare class AsyncQuery<T extends Datas = Datas, K extends
|
|
89
|
+
export declare class AsyncQuery<T extends Datas = Datas, K extends DataKey<T> = DataKey<T>> extends BaseQuery<T, K> {
|
|
97
90
|
readonly db: AsyncDatabase<T>;
|
|
98
91
|
readonly collection: K;
|
|
99
92
|
constructor(db: AsyncDatabase<T>, collection: K, filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null);
|
package/db/Query.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { getFirstItem, getLastItem, getOptionalFirstItem, getOptionalLastItem } from "../util/array.js";
|
|
2
|
-
import { QueryConstraints } from "../constraint/QueryConstraints.js";
|
|
3
2
|
import { countItems, hasItems } from "../util/iterate.js";
|
|
3
|
+
import { runSequence } from "../util/sequence.js";
|
|
4
|
+
import { QueryConstraints } from "../constraint/QueryConstraints.js";
|
|
4
5
|
/** Reference to a set of items in a sync or async provider. */
|
|
5
6
|
class BaseQuery extends QueryConstraints {
|
|
6
|
-
/**
|
|
7
|
-
* Subscribe to all matching items.
|
|
8
|
-
* - `next()` is called once with the initial results, and again any time the results change.
|
|
9
|
-
*
|
|
10
|
-
* @param next Observer with `next`, `error`, or `complete` methods or a `next()` dispatcher.
|
|
11
|
-
* @return Function that ends the subscription.
|
|
12
|
-
*/
|
|
13
|
-
subscribe(next) {
|
|
14
|
-
return this.db.provider.subscribeQuery(this.collection, this, typeof next === "function" ? { next } : next);
|
|
15
|
-
}
|
|
16
7
|
// Override to include the collection name.
|
|
17
8
|
toString() {
|
|
18
|
-
return `${this.collection}
|
|
9
|
+
return `${this.collection}?{${super.toString()}`;
|
|
10
|
+
}
|
|
11
|
+
/** Subscribe to this item. */
|
|
12
|
+
subscribe(onNext, onError) {
|
|
13
|
+
return runSequence(this, onNext, onError);
|
|
14
|
+
}
|
|
15
|
+
// Implement AsyncIterable
|
|
16
|
+
[Symbol.asyncIterator]() {
|
|
17
|
+
return this.db.provider.getQuerySequence(this.collection, this)[Symbol.asyncIterator]();
|
|
19
18
|
}
|
|
20
19
|
}
|
|
21
20
|
/** Reference to a set of items in a provider. */
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import type { Firestore } from "firebase/firestore";
|
|
2
2
|
import type { Data } from "../../util/data.js";
|
|
3
|
-
import type { Unsubscribe } from "../../observe/Observable.js";
|
|
4
3
|
import type { AsyncProvider } from "../../provider/Provider.js";
|
|
5
4
|
import type { ItemArray, ItemValue, ItemConstraints } from "../../db/Item.js";
|
|
6
|
-
import {
|
|
7
|
-
import { Updates } from "../../update/DataUpdate.js";
|
|
5
|
+
import { Updates } from "../../update/index.js";
|
|
8
6
|
/**
|
|
9
7
|
* Firestore client database provider.
|
|
10
8
|
* - Works with the Firebase JS SDK.
|
|
@@ -15,13 +13,13 @@ export declare class FirestoreClientProvider implements AsyncProvider {
|
|
|
15
13
|
private readonly _firestore;
|
|
16
14
|
constructor(firestore: Firestore);
|
|
17
15
|
getItem(collection: string, id: string): Promise<ItemValue>;
|
|
18
|
-
|
|
16
|
+
getItemSequence<K extends string>(collection: K, id: string): AsyncIterable<ItemValue>;
|
|
19
17
|
addItem(collection: string, data: Data): Promise<string>;
|
|
20
18
|
setItem(collection: string, id: string, data: Data): Promise<void>;
|
|
21
19
|
updateItem(collection: string, id: string, updates: Updates): Promise<void>;
|
|
22
20
|
deleteItem(collection: string, id: string): Promise<void>;
|
|
23
21
|
getQuery(collection: string, constraints: ItemConstraints): Promise<ItemArray>;
|
|
24
|
-
|
|
22
|
+
getQuerySequence<K extends string>(collection: K, constraints: ItemConstraints): AsyncIterable<ItemArray>;
|
|
25
23
|
setQuery(collection: string, constraints: ItemConstraints, data: Data): Promise<number>;
|
|
26
24
|
updateQuery(collection: string, constraints: ItemConstraints, updates: Updates): Promise<number>;
|
|
27
25
|
deleteQuery(collection: string, constraints: ItemConstraints): Promise<number>;
|