shelving 1.76.2 → 1.77.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/constraint/Constraints.d.ts +1 -1
- package/constraint/FilterConstraint.d.ts +6 -6
- package/constraint/FilterConstraint.js +1 -1
- package/constraint/FilterConstraints.d.ts +5 -5
- package/constraint/QueryConstraints.d.ts +4 -4
- package/constraint/QueryConstraints.js +2 -2
- package/constraint/SortConstraint.d.ts +4 -3
- package/constraint/SortConstraint.js +2 -3
- package/constraint/SortConstraints.d.ts +5 -5
- package/db/Change.d.ts +2 -2
- package/db/Collection.d.ts +3 -3
- package/db/Database.d.ts +3 -3
- package/db/Query.d.ts +2 -2
- package/package.json +1 -1
- package/react/useItem.d.ts +7 -7
- package/react/useQuery.d.ts +10 -10
|
@@ -2,7 +2,7 @@ import type { Data } from "../util/data.js";
|
|
|
2
2
|
import { ImmutableArray } from "../util/array.js";
|
|
3
3
|
import { Constraint } from "./Constraint.js";
|
|
4
4
|
/** Type of Rule that is powered by several sub-constraints (e.g. `Filters` and `Sorts` and `Query` itself extend this). */
|
|
5
|
-
export declare abstract class Constraints<T extends Data, C extends Constraint<T
|
|
5
|
+
export declare abstract class Constraints<T extends Data, C extends Constraint<Partial<T>>> extends Constraint<T> implements Iterable<C> {
|
|
6
6
|
protected readonly _constraints: ImmutableArray<C>;
|
|
7
7
|
/** Get the first constraint. */
|
|
8
8
|
get first(): C | undefined;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { Data, Key } from "../util/data.js";
|
|
2
|
+
import type { Nullish } from "../util/null.js";
|
|
3
|
+
import { ImmutableArray } from "../util/array.js";
|
|
3
4
|
import { Matchable } from "../util/match.js";
|
|
4
|
-
import {
|
|
5
|
-
import { Constraint } from "./Constraint.js";
|
|
5
|
+
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` */
|
|
@@ -11,12 +11,12 @@ export declare type FilterKey<T extends Data> = Key<T> | `${Key<T>}` | `!${Key<T
|
|
|
11
11
|
export declare type FilterProps<T extends Data> = {
|
|
12
12
|
[K in Key<T> as `${K}` | `!${K}`]?: T[K] | ImmutableArray<T[K]>;
|
|
13
13
|
} & {
|
|
14
|
-
[K in Key<T> as `${K}[]`]?: T[K] extends
|
|
14
|
+
[K in Key<T> as `${K}[]`]?: Required<T>[K] extends ReadonlyArray<infer X> ? X : never;
|
|
15
15
|
} & {
|
|
16
16
|
[K in Key<T> as `${K}<` | `${K}<=` | `${K}>` | `${K}>=`]?: T[K];
|
|
17
17
|
};
|
|
18
18
|
/** List of filters in a flexible format. */
|
|
19
|
-
export declare type FilterList<T extends Data> = FilterProps<T> | FilterConstraint<T
|
|
19
|
+
export declare type FilterList<T extends Data> = Nullish<FilterProps<T> | FilterConstraint<T>> | Iterable<FilterList<T>>;
|
|
20
20
|
/**
|
|
21
21
|
* Filter: filters a list of data.
|
|
22
22
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Data } from "../util/data.js";
|
|
2
2
|
import type { Matchable } from "../util/match.js";
|
|
3
|
-
import { FilterList,
|
|
3
|
+
import { FilterList, FilterConstraint } from "./FilterConstraint.js";
|
|
4
4
|
import { Constraints } from "./Constraints.js";
|
|
5
5
|
/**
|
|
6
6
|
* Interface to make sure an object implements all matchers.
|
|
@@ -8,14 +8,14 @@ import { Constraints } from "./Constraints.js";
|
|
|
8
8
|
*/
|
|
9
9
|
export interface Filterable<T extends Data> extends Matchable<T, void> {
|
|
10
10
|
/** Add a filter to this filterable. */
|
|
11
|
-
filter(
|
|
11
|
+
filter(...filters: FilterList<Partial<T>>[]): this;
|
|
12
12
|
/** Match an item against the filters specified for this object. */
|
|
13
13
|
match(item: T): boolean;
|
|
14
14
|
}
|
|
15
15
|
/** A set of filters. */
|
|
16
|
-
export declare class FilterConstraints<T extends Data = Data> extends Constraints<T, FilterConstraint<T
|
|
17
|
-
constructor(...filters: FilterList<T
|
|
18
|
-
filter(...filters: FilterList<T
|
|
16
|
+
export declare class FilterConstraints<T extends Data = Data> extends Constraints<T, FilterConstraint<Partial<T>>> implements Filterable<T> {
|
|
17
|
+
constructor(...filters: FilterList<Partial<T>>[]);
|
|
18
|
+
filter(...filters: FilterList<Partial<T>>[]): this;
|
|
19
19
|
match(item: T): boolean;
|
|
20
20
|
transform(items: Iterable<T>): Iterable<T>;
|
|
21
21
|
toString(): string;
|
|
@@ -3,7 +3,7 @@ import { Filterable, FilterConstraints } from "./FilterConstraints.js";
|
|
|
3
3
|
import { Sortable, SortConstraints } from "./SortConstraints.js";
|
|
4
4
|
import { Constraint } from "./Constraint.js";
|
|
5
5
|
import { FilterList } from "./FilterConstraint.js";
|
|
6
|
-
import {
|
|
6
|
+
import { SortList } from "./SortConstraint.js";
|
|
7
7
|
/** Interface that combines Filterable, Sortable, Sliceable. */
|
|
8
8
|
export interface Queryable<T extends Data> extends Filterable<T>, Sortable<T> {
|
|
9
9
|
/**
|
|
@@ -31,11 +31,11 @@ export declare class QueryConstraints<T extends Data = Data> extends Constraint<
|
|
|
31
31
|
readonly filters: FilterConstraints<T>;
|
|
32
32
|
readonly sorts: SortConstraints<T>;
|
|
33
33
|
readonly limit: number | null;
|
|
34
|
-
constructor(filters?: FilterList<T
|
|
35
|
-
filter(...filters: FilterList<T
|
|
34
|
+
constructor(filters?: FilterList<Partial<T>>, sorts?: SortList<Partial<T>>, limit?: number | null);
|
|
35
|
+
filter(...filters: FilterList<Partial<T>>[]): this;
|
|
36
36
|
get unfilter(): this;
|
|
37
37
|
match(item: T): boolean;
|
|
38
|
-
sort(...
|
|
38
|
+
sort(...sorts: SortList<Partial<T>>[]): this;
|
|
39
39
|
get unsort(): this;
|
|
40
40
|
rank(left: T, right: T): number;
|
|
41
41
|
after(item: T): this;
|
|
@@ -37,11 +37,11 @@ export class QueryConstraints extends Constraint {
|
|
|
37
37
|
return this.filters.match(item);
|
|
38
38
|
}
|
|
39
39
|
// Implement `Sortable`
|
|
40
|
-
sort(...
|
|
40
|
+
sort(...sorts) {
|
|
41
41
|
return {
|
|
42
42
|
__proto__: Object.getPrototypeOf(this),
|
|
43
43
|
...this,
|
|
44
|
-
sorts: this.sorts.sort(...
|
|
44
|
+
sorts: this.sorts.sort(...sorts),
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
get unsort() {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ImmutableArray } from "../util/array.js";
|
|
2
|
-
import { Data, Key } from "../util/data.js";
|
|
2
|
+
import type { Data, Key } from "../util/data.js";
|
|
3
|
+
import type { Nullish } from "../util/null.js";
|
|
3
4
|
import { Rankable } from "../util/sort.js";
|
|
4
|
-
import { Constraint } from "./Constraint.js";
|
|
5
|
+
import type { Constraint } from "./Constraint.js";
|
|
5
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. */
|
|
6
7
|
export declare type SortKey<T extends Data> = Key<T> | `${Key<T>}` | `!${Key<T>}`;
|
|
7
8
|
/** One or more sort keys. */
|
|
@@ -9,7 +10,7 @@ export declare type SortKeys<T extends Data> = SortKey<T> | ImmutableArray<SortK
|
|
|
9
10
|
/** Possible operator references. */
|
|
10
11
|
export declare type SortDirection = "ASC" | "DESC";
|
|
11
12
|
/** List of sorts in a flexible format. */
|
|
12
|
-
export declare type SortList<T extends Data> = SortKeys<T> | SortConstraint<T> | Iterable<SortList<T
|
|
13
|
+
export declare type SortList<T extends Data> = Nullish<SortKeys<T> | SortConstraint<T> | Iterable<SortList<T>>>;
|
|
13
14
|
/** Sort a list of values. */
|
|
14
15
|
export declare class SortConstraint<T extends Data = Data> implements Constraint<T>, Rankable<T> {
|
|
15
16
|
readonly key: string;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getProp } from "../util/data.js";
|
|
2
1
|
import { rank, rankAsc, rankDesc, sortItems } from "../util/sort.js";
|
|
3
2
|
/** Sort a list of values. */
|
|
4
3
|
export class SortConstraint {
|
|
@@ -16,7 +15,7 @@ export class SortConstraint {
|
|
|
16
15
|
return `"${this.direction === "DESC" ? "!" : ""}${this.key}"`;
|
|
17
16
|
}
|
|
18
17
|
rank(left, right) {
|
|
19
|
-
return rank(
|
|
18
|
+
return rank(left[this.key], this.direction === "ASC" ? rankAsc : rankDesc, right[this.key]);
|
|
20
19
|
}
|
|
21
20
|
transform(items) {
|
|
22
21
|
return sortItems(items, this);
|
|
@@ -33,7 +32,7 @@ export function* getSorts(sorts) {
|
|
|
33
32
|
else if (sorts instanceof SortConstraint) {
|
|
34
33
|
yield sorts;
|
|
35
34
|
}
|
|
36
|
-
else {
|
|
35
|
+
else if (sorts) {
|
|
37
36
|
for (const sort of sorts)
|
|
38
37
|
yield* getSorts(sort);
|
|
39
38
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { Data } from "../util/data.js";
|
|
2
2
|
import { Rankable } from "../util/sort.js";
|
|
3
3
|
import { Constraints } from "./Constraints.js";
|
|
4
|
-
import { SortConstraint,
|
|
4
|
+
import { SortConstraint, SortList } from "./SortConstraint.js";
|
|
5
5
|
/**
|
|
6
6
|
* Interface to make sure an object implements all directions.
|
|
7
7
|
* - Extends `Rankable` so this object itself can be directly be used with `filterItems()` and `filterEntries()`
|
|
8
8
|
*/
|
|
9
9
|
export interface Sortable<T extends Data> extends Rankable<T> {
|
|
10
10
|
/** Add one or more sorts to this sortable. */
|
|
11
|
-
sort(...keys:
|
|
11
|
+
sort(...keys: SortList<Partial<T>>[]): this;
|
|
12
12
|
}
|
|
13
13
|
/** A set of sorts. */
|
|
14
|
-
export declare class SortConstraints<T extends Data = Data> extends Constraints<T, SortConstraint<T
|
|
15
|
-
constructor(...sorts: SortList<T
|
|
16
|
-
sort(...sorts: SortList<T
|
|
14
|
+
export declare class SortConstraints<T extends Data = Data> extends Constraints<T, SortConstraint<Partial<T>>> implements Sortable<T> {
|
|
15
|
+
constructor(...sorts: SortList<Partial<T>>[]);
|
|
16
|
+
sort(...sorts: SortList<Partial<T>>[]): this;
|
|
17
17
|
rank(left: T, right: T): number;
|
|
18
18
|
transform(items: Iterable<T>): Iterable<T>;
|
|
19
19
|
toString(): string;
|
package/db/Change.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Data, Datas, Key
|
|
1
|
+
import type { Data, Datas, Key } 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 { DataUpdate } from "../update/DataUpdate.js";
|
|
@@ -27,7 +27,7 @@ export interface UpdateChange<T extends Datas, K extends Key<T> = Key<T>> extend
|
|
|
27
27
|
readonly action: "UPDATE";
|
|
28
28
|
readonly collection: K;
|
|
29
29
|
readonly id: string;
|
|
30
|
-
readonly update: DataUpdate<
|
|
30
|
+
readonly update: DataUpdate<T[K]>;
|
|
31
31
|
}
|
|
32
32
|
/** Delete change on an item. */
|
|
33
33
|
export interface DeleteChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T> {
|
package/db/Collection.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ declare abstract class BaseCollection<T extends Datas = Datas, K extends Key<T>
|
|
|
12
12
|
abstract readonly db: Database<T> | AsyncDatabase<T>;
|
|
13
13
|
abstract readonly collection: K;
|
|
14
14
|
/** Create a query on this item's collection. */
|
|
15
|
-
abstract query(filters?: FilterList<ItemData<T[K]
|
|
15
|
+
abstract query(filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): Query<T, K> | AsyncQuery<T, K>;
|
|
16
16
|
/** Create a query on this item's collection. */
|
|
17
17
|
abstract item(id: string): Item<T, K> | AsyncItem<T, K>;
|
|
18
18
|
/** Add an item to this collection. */
|
|
@@ -28,7 +28,7 @@ export declare class Collection<T extends Datas = Datas, K extends Key<T> = Key<
|
|
|
28
28
|
readonly db: Database<T>;
|
|
29
29
|
readonly collection: K;
|
|
30
30
|
constructor(db: Database<T>, collection: K);
|
|
31
|
-
query(filters?: FilterList<ItemData<T[K]
|
|
31
|
+
query(filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): Query<T, K>;
|
|
32
32
|
item(id: string): Item<T, K>;
|
|
33
33
|
add(data: T[K]): string;
|
|
34
34
|
change(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): ItemChanges<T, K>;
|
|
@@ -38,7 +38,7 @@ export declare class AsyncCollection<T extends Datas = Datas, K extends Key<T> =
|
|
|
38
38
|
readonly db: AsyncDatabase<T>;
|
|
39
39
|
readonly collection: K;
|
|
40
40
|
constructor(db: AsyncDatabase<T>, collection: K);
|
|
41
|
-
query(filters?: FilterList<ItemData<T[K]
|
|
41
|
+
query(filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): AsyncQuery<T, K>;
|
|
42
42
|
item(id: string): AsyncItem<T, K>;
|
|
43
43
|
add(data: T[K]): Promise<string>;
|
|
44
44
|
change(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): Promise<ItemChanges<T, K>>;
|
package/db/Database.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ declare abstract class BaseDatabase<T extends Datas> {
|
|
|
15
15
|
/** Create a query on a collection in this database. */
|
|
16
16
|
abstract collection<K extends Key<T>>(collection: K): Collection<T, K> | AsyncCollection<T, K>;
|
|
17
17
|
/** Create a query on a collection in this database. */
|
|
18
|
-
abstract query<K extends Key<T>>(collection: K, filters?: FilterList<ItemData<T[K]
|
|
18
|
+
abstract query<K extends Key<T>>(collection: K, filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): Query<T, K> | AsyncQuery<T, K>;
|
|
19
19
|
/** Reference an item in a collection in this database. */
|
|
20
20
|
abstract item<K extends Key<T>>(collection: K, id: string): Item<T, K> | AsyncItem<T, K>;
|
|
21
21
|
/** Run a set of changes on this database. */
|
|
@@ -26,7 +26,7 @@ export declare class Database<T extends Datas = Datas> implements BaseDatabase<T
|
|
|
26
26
|
readonly provider: Provider<T>;
|
|
27
27
|
constructor(provider: Provider<T>);
|
|
28
28
|
collection<K extends Key<T>>(collection: K): Collection<T, K>;
|
|
29
|
-
query<K extends Key<T>>(collection: K, filters?: FilterList<ItemData<T[K]
|
|
29
|
+
query<K extends Key<T>>(collection: K, filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): Query<T, K>;
|
|
30
30
|
item<K extends Key<T>>(collection: K, id: string): Item<T, K>;
|
|
31
31
|
change<K extends Key<T>>(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): ItemChanges<T, K>;
|
|
32
32
|
}
|
|
@@ -35,7 +35,7 @@ export declare class AsyncDatabase<T extends Datas = Datas> implements BaseDatab
|
|
|
35
35
|
readonly provider: AsyncProvider<T>;
|
|
36
36
|
constructor(provider: AsyncProvider<T>);
|
|
37
37
|
collection<K extends Key<T>>(collection: K): AsyncCollection<T, K>;
|
|
38
|
-
query<K extends Key<T>>(collection: K, filters?: FilterList<ItemData<T[K]
|
|
38
|
+
query<K extends Key<T>>(collection: K, filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): AsyncQuery<T, K>;
|
|
39
39
|
item<K extends Key<T>>(collection: K, id: string): AsyncItem<T, K>;
|
|
40
40
|
change<K extends Key<T>>(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): Promise<ItemChanges<T, K>>;
|
|
41
41
|
}
|
package/db/Query.d.ts
CHANGED
|
@@ -80,7 +80,7 @@ declare abstract class BaseQuery<T extends Datas = Datas, K extends Key<T> = Key
|
|
|
80
80
|
export declare class Query<T extends Datas = Datas, K extends Key<T> = Key<T>> extends BaseQuery<T, K> implements BaseQuery<T, K> {
|
|
81
81
|
readonly db: Database<T>;
|
|
82
82
|
readonly collection: K;
|
|
83
|
-
constructor(db: Database<T>, collection: K, filters?: FilterList<ItemData<T[K]
|
|
83
|
+
constructor(db: Database<T>, collection: K, filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null);
|
|
84
84
|
get value(): ItemArray<T[K]>;
|
|
85
85
|
get count(): number;
|
|
86
86
|
get exists(): boolean;
|
|
@@ -96,7 +96,7 @@ export declare class Query<T extends Datas = Datas, K extends Key<T> = Key<T>> e
|
|
|
96
96
|
export declare class AsyncQuery<T extends Datas = Datas, K extends Key<T> = Key<T>> extends BaseQuery<T, K> implements BaseQuery<T, K> {
|
|
97
97
|
readonly db: AsyncDatabase<T>;
|
|
98
98
|
readonly collection: K;
|
|
99
|
-
constructor(db: AsyncDatabase<T>, collection: K, filters?: FilterList<ItemData<T[K]
|
|
99
|
+
constructor(db: AsyncDatabase<T>, collection: K, filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null);
|
|
100
100
|
get value(): Promise<ItemArray<T[K]>>;
|
|
101
101
|
get count(): Promise<number>;
|
|
102
102
|
get exists(): Promise<boolean>;
|
package/package.json
CHANGED
package/react/useItem.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { Unsubscribe } from "../observe/Observable.js";
|
|
2
|
-
import { Datas,
|
|
2
|
+
import { Datas, Key } from "../util/data.js";
|
|
3
3
|
import { ItemValue, ItemData, AsyncItem, Item } from "../db/Item.js";
|
|
4
4
|
import { State } from "../state/State.js";
|
|
5
5
|
import { BooleanState } from "../state/BooleanState.js";
|
|
6
6
|
/** Hold the current state of a item. */
|
|
7
|
-
export declare class ItemState<T extends Datas> extends State<ItemValue<
|
|
8
|
-
readonly ref: Item<T> | AsyncItem<T>;
|
|
7
|
+
export declare class ItemState<T extends Datas, K extends Key<T> = Key<T>> extends State<ItemValue<T[K]>> {
|
|
8
|
+
readonly ref: Item<T, K> | AsyncItem<T, K>;
|
|
9
9
|
readonly busy: BooleanState;
|
|
10
10
|
/** Get the data of the item (throws `RequiredError` if item doesn't exist). */
|
|
11
|
-
get data(): ItemData<
|
|
11
|
+
get data(): ItemData<T[K]>;
|
|
12
12
|
/** Does the item exist (i.e. its value isn't `null`)? */
|
|
13
13
|
get exists(): boolean;
|
|
14
|
-
constructor(ref: Item<T> | AsyncItem<T>);
|
|
14
|
+
constructor(ref: Item<T, K> | AsyncItem<T, K>);
|
|
15
15
|
/** Refresh this state from the source provider. */
|
|
16
16
|
readonly refresh: () => void;
|
|
17
17
|
_refresh(): Promise<void>;
|
|
@@ -28,5 +28,5 @@ export declare class ItemState<T extends Datas> extends State<ItemValue<Value<T>
|
|
|
28
28
|
* Use an item in a React component.
|
|
29
29
|
* - Uses the default cache, so will error if not used inside `<Cache>`
|
|
30
30
|
*/
|
|
31
|
-
export declare function useItem<T extends Datas
|
|
32
|
-
export declare function useItem<T extends Datas
|
|
31
|
+
export declare function useItem<T extends Datas, K extends Key<T>>(ref: Item<T, K> | AsyncItem<T, K>): ItemState<T, K>;
|
|
32
|
+
export declare function useItem<T extends Datas, K extends Key<T>>(ref?: Item<T, K> | AsyncItem<T, K>): ItemState<T, K> | undefined;
|
package/react/useQuery.d.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import type { Unsubscribe } from "../observe/Observable.js";
|
|
2
|
-
import type { Datas,
|
|
2
|
+
import type { Datas, Key } from "../util/data.js";
|
|
3
3
|
import type { ItemArray, ItemValue, ItemData } from "../db/Item.js";
|
|
4
4
|
import { 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 Datas> extends State<ItemArray<
|
|
9
|
-
readonly ref: Query<T> | AsyncQuery<T>;
|
|
8
|
+
export declare class QueryState<T extends Datas, K extends Key<T> = Key<T>> extends State<ItemArray<T[K]>> {
|
|
9
|
+
readonly ref: Query<T, K> | AsyncQuery<T, K>;
|
|
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<
|
|
16
|
+
get firstValue(): ItemValue<T[K]>;
|
|
17
17
|
/** Get the first document matched by this query. */
|
|
18
|
-
get firstData(): ItemData<
|
|
18
|
+
get firstData(): ItemData<T[K]>;
|
|
19
19
|
/** Get the last document matched by this query or `null` if this query has no items. */
|
|
20
|
-
get lastValue(): ItemValue<
|
|
20
|
+
get lastValue(): ItemValue<T[K]>;
|
|
21
21
|
/** Get the last document matched by this query. */
|
|
22
|
-
get lastData(): ItemData<
|
|
22
|
+
get lastData(): ItemData<T[K]>;
|
|
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> | AsyncQuery<T>);
|
|
27
|
+
constructor(ref: Query<T, K> | AsyncQuery<T, K>);
|
|
28
28
|
/** Refresh this state from the source provider. */
|
|
29
29
|
readonly refresh: () => void;
|
|
30
30
|
_refresh(): Promise<void>;
|
|
@@ -47,5 +47,5 @@ export declare class QueryState<T extends Datas> extends State<ItemArray<Value<T
|
|
|
47
47
|
* Use a query in a React component.
|
|
48
48
|
* - Uses the default cache, so will error if not used inside `<Cache>`
|
|
49
49
|
*/
|
|
50
|
-
export declare function useQuery<T extends Datas
|
|
51
|
-
export declare function useQuery<T extends Datas
|
|
50
|
+
export declare function useQuery<T extends Datas, K extends Key<T>>(ref: Query<T, K> | AsyncQuery<T, K>): QueryState<T, K>;
|
|
51
|
+
export declare function useQuery<T extends Datas, K extends Key<T>>(ref?: Query<T, K> | AsyncQuery<T, K>): QueryState<T, K> | undefined;
|