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
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { Data,
|
|
1
|
+
import { Data, FlatDataKey } from "../util/data.js";
|
|
2
2
|
import type { Nullish } from "../util/null.js";
|
|
3
3
|
import { ImmutableArray } from "../util/array.js";
|
|
4
4
|
import type { Matchable } from "../util/match.js";
|
|
5
5
|
import type { Constraint } from "./Constraint.js";
|
|
6
6
|
/** Possible operator references. */
|
|
7
7
|
export type FilterOperator = "IS" | "NOT" | "IN" | "OUT" | "CONTAINS" | "LT" | "LTE" | "GT" | "GTE";
|
|
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 type FilterKey<T extends Data> = DataKey<FilterProps<T>>;
|
|
10
8
|
/** Format that allows multiple filters to be specified as a plain object. */
|
|
11
9
|
export type FilterProps<T extends Data> = {
|
|
12
10
|
[K in FlatDataKey<T> as `${K}` | `!${K}`]?: T[K] | ImmutableArray<T[K]>;
|
|
@@ -15,6 +13,8 @@ export type FilterProps<T extends Data> = {
|
|
|
15
13
|
} & {
|
|
16
14
|
[K in FlatDataKey<T> as `${K}[]`]?: Required<T>[K] extends ImmutableArray<infer X> ? X : never;
|
|
17
15
|
};
|
|
16
|
+
/** 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` */
|
|
17
|
+
export type FilterKey<T extends Data> = keyof FilterProps<T>;
|
|
18
18
|
/** List of filters in a flexible format. */
|
|
19
19
|
export type FilterList<T extends Data> = FilterProps<T> | FilterConstraint<T> | Iterable<Nullish<FilterProps<T> | FilterConstraint<T>>>;
|
|
20
20
|
/**
|
package/db/Change.d.ts
CHANGED
|
@@ -1,45 +1,44 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Data } 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";
|
|
5
5
|
import { Nullish } from "../util/null.js";
|
|
6
|
-
import { DeepIterable } from "../util/iterate.js";
|
|
7
6
|
/** Change on a collection. */
|
|
8
|
-
export interface Change
|
|
7
|
+
export interface Change {
|
|
9
8
|
readonly action: string;
|
|
10
|
-
readonly collection:
|
|
9
|
+
readonly collection: string;
|
|
11
10
|
}
|
|
12
11
|
/** Add on an item. */
|
|
13
|
-
export interface AddChange<T extends
|
|
12
|
+
export interface AddChange<T extends Data> extends Change {
|
|
14
13
|
readonly action: "ADD";
|
|
15
|
-
readonly data: T
|
|
14
|
+
readonly data: T;
|
|
16
15
|
}
|
|
17
16
|
/** Set on an item. */
|
|
18
|
-
export interface SetChange<T extends
|
|
17
|
+
export interface SetChange<T extends Data = Data> extends Change {
|
|
19
18
|
readonly action: "SET";
|
|
20
19
|
readonly id: string;
|
|
21
|
-
readonly data: T
|
|
20
|
+
readonly data: T;
|
|
22
21
|
}
|
|
23
22
|
/** Update change on an item. */
|
|
24
|
-
export interface UpdateChange<T extends
|
|
23
|
+
export interface UpdateChange<T extends Data = Data> extends Change {
|
|
25
24
|
readonly action: "UPDATE";
|
|
26
25
|
readonly id: string;
|
|
27
|
-
readonly updates: Updates<T
|
|
26
|
+
readonly updates: Updates<T>;
|
|
28
27
|
}
|
|
29
28
|
/** Delete change on an item. */
|
|
30
|
-
export interface DeleteChange
|
|
29
|
+
export interface DeleteChange extends Change {
|
|
31
30
|
readonly action: "DELETE";
|
|
32
31
|
readonly id: string;
|
|
33
32
|
}
|
|
34
33
|
/** Set, update, or delete change on an item. */
|
|
35
|
-
export type ItemChange<T extends
|
|
34
|
+
export type ItemChange<T extends Data = Data> = SetChange<T> | UpdateChange<T> | DeleteChange;
|
|
36
35
|
/** Array of item changes. */
|
|
37
|
-
export type ItemChanges
|
|
36
|
+
export type ItemChanges = ImmutableArray<ItemChange>;
|
|
38
37
|
/** Write change on an item. */
|
|
39
|
-
export type WriteChange<T extends
|
|
38
|
+
export type WriteChange<T extends Data = Data> = ItemChange<T> | AddChange<T>;
|
|
40
39
|
/** Array of write changes. */
|
|
41
|
-
export type WriteChanges
|
|
40
|
+
export type WriteChanges = ImmutableArray<WriteChange>;
|
|
42
41
|
/** Apply a set of changes to a synchronous provider. */
|
|
43
|
-
export declare function changeProvider
|
|
42
|
+
export declare function changeProvider(provider: Provider, ...changes: Nullish<WriteChange>[]): ItemChanges;
|
|
44
43
|
/** Apply a set of changes to an asynchronous provider. */
|
|
45
|
-
export declare function changeAsyncProvider
|
|
44
|
+
export declare function changeAsyncProvider(provider: AsyncProvider, ...changes: Nullish<WriteChange>[]): Promise<ItemChanges>;
|
package/db/Change.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { QueryConstraints } from "../constraint/QueryConstraints.js";
|
|
2
1
|
import { notNullish } from "../util/null.js";
|
|
3
|
-
import {
|
|
4
|
-
import { getItemFilterConstraints } from "./Item.js";
|
|
2
|
+
import { getItemConstraints } from "./Item.js";
|
|
5
3
|
/** Apply a set of changes to a synchronous provider. */
|
|
6
4
|
export function changeProvider(provider, ...changes) {
|
|
7
|
-
return
|
|
5
|
+
return changes.filter(notNullish).map(_changeItem, provider);
|
|
8
6
|
}
|
|
9
7
|
function _changeItem(change) {
|
|
10
8
|
const { action, collection } = change;
|
|
@@ -13,14 +11,14 @@ function _changeItem(change) {
|
|
|
13
11
|
else if (action === "SET")
|
|
14
12
|
this.setItem(collection, change.id, change.data);
|
|
15
13
|
else if (action === "UPDATE")
|
|
16
|
-
this.updateQuery(collection,
|
|
14
|
+
this.updateQuery(collection, getItemConstraints(change.id), change.updates);
|
|
17
15
|
else if (action === "DELETE")
|
|
18
16
|
this.deleteItem(collection, change.id);
|
|
19
17
|
return change;
|
|
20
18
|
}
|
|
21
19
|
/** Apply a set of changes to an asynchronous provider. */
|
|
22
20
|
export function changeAsyncProvider(provider, ...changes) {
|
|
23
|
-
return Promise.all(
|
|
21
|
+
return Promise.all(changes.filter(notNullish).map(_changeAsyncItem, provider));
|
|
24
22
|
}
|
|
25
23
|
async function _changeAsyncItem(change) {
|
|
26
24
|
const { collection, action } = change;
|
|
@@ -29,7 +27,7 @@ async function _changeAsyncItem(change) {
|
|
|
29
27
|
else if (action === "SET")
|
|
30
28
|
await this.setItem(collection, change.id, change.data);
|
|
31
29
|
else if (action === "UPDATE")
|
|
32
|
-
await this.updateQuery(collection,
|
|
30
|
+
await this.updateQuery(collection, getItemConstraints(change.id), change.updates);
|
|
33
31
|
else if (action === "DELETE")
|
|
34
32
|
await this.deleteItem(collection, change.id);
|
|
35
33
|
return change;
|
package/db/Collection.d.ts
CHANGED
|
@@ -1,69 +1,63 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Nullish } from "../util/null.js";
|
|
1
|
+
import type { Data } from "../util/data.js";
|
|
3
2
|
import type { FilterList } from "../constraint/FilterConstraint.js";
|
|
4
3
|
import type { SortList } from "../constraint/SortConstraint.js";
|
|
5
|
-
import type { DeepIterable } from "../util/iterate.js";
|
|
6
4
|
import type { Updates } from "../update/DataUpdate.js";
|
|
7
|
-
import type {
|
|
5
|
+
import type { Provider, AsyncProvider } from "../provider/Provider.js";
|
|
8
6
|
import { ItemData, AsyncItem, Item, ItemValue } from "./Item.js";
|
|
9
7
|
import { AsyncQuery, Query } from "./Query.js";
|
|
10
|
-
import { AddChange,
|
|
8
|
+
import { AddChange, UpdateChange, DeleteChange, SetChange } from "./Change.js";
|
|
11
9
|
/** Reference to a collection in a synchronous or asynchronous provider. */
|
|
12
|
-
declare abstract class BaseCollection<T extends
|
|
13
|
-
abstract readonly
|
|
14
|
-
abstract readonly collection:
|
|
10
|
+
declare abstract class BaseCollection<T extends Data = Data> {
|
|
11
|
+
abstract readonly provider: Provider | AsyncProvider;
|
|
12
|
+
abstract readonly collection: string;
|
|
15
13
|
/** Create a query on this item's collection. */
|
|
16
|
-
abstract query(filters?: FilterList<Partial<ItemData<T
|
|
14
|
+
abstract query(filters?: FilterList<Partial<ItemData<T>>>, sorts?: SortList<Partial<ItemData<T>>>, limit?: number | null): Query<T> | AsyncQuery<T>;
|
|
17
15
|
/** Create a query on this item's collection. */
|
|
18
|
-
abstract item(id: string): Item<T
|
|
19
|
-
/** Run a set of changes on this database. */
|
|
20
|
-
abstract change(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): ItemChanges<T, K> | Promise<ItemChanges<T, K>>;
|
|
16
|
+
abstract item(id: string): Item<T> | AsyncItem<T>;
|
|
21
17
|
/** Get an item from this collection. */
|
|
22
|
-
abstract get(id: string): ItemValue<T
|
|
18
|
+
abstract get(id: string): ItemValue<T> | Promise<ItemValue<T>>;
|
|
23
19
|
/** Add an item to this collection. */
|
|
24
|
-
abstract add(data: T
|
|
20
|
+
abstract add(data: T): string | Promise<string>;
|
|
25
21
|
/** Set a document in this collection. */
|
|
26
|
-
abstract set(id: string, data: T
|
|
22
|
+
abstract set(id: string, data: T): void | Promise<void>;
|
|
27
23
|
/** Update a document in this collection. */
|
|
28
|
-
abstract update(id: string, updates: Updates<T
|
|
24
|
+
abstract update(id: string, updates: Updates<T>): void | Promise<void>;
|
|
29
25
|
/** Delete a document in this collection. */
|
|
30
26
|
abstract delete(id: string): void | Promise<void>;
|
|
31
27
|
/** Get an add change for this collection. */
|
|
32
|
-
getAdd(data: T
|
|
28
|
+
getAdd(data: T): AddChange<T>;
|
|
33
29
|
/** Get a set change for this collection. */
|
|
34
|
-
getSet(id: string, data: T
|
|
30
|
+
getSet(id: string, data: T): SetChange<T>;
|
|
35
31
|
/** Get an update change for this collection. */
|
|
36
|
-
getUpdate(id: string, updates: Updates<T
|
|
32
|
+
getUpdate(id: string, updates: Updates<T>): UpdateChange<T>;
|
|
37
33
|
/** Get a delete change for this collection. */
|
|
38
|
-
getDelete(id: string): DeleteChange
|
|
39
|
-
toString():
|
|
34
|
+
getDelete(id: string): DeleteChange;
|
|
35
|
+
toString(): string;
|
|
40
36
|
}
|
|
41
37
|
/** Reference to a collection in a synchronous provider. */
|
|
42
|
-
export declare class Collection<T extends
|
|
43
|
-
readonly
|
|
44
|
-
readonly collection:
|
|
45
|
-
constructor(
|
|
46
|
-
query(filters?: FilterList<ItemData<T
|
|
47
|
-
item(id: string): Item<T
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
update(id: string, updates: Updates<T[K]>): void;
|
|
38
|
+
export declare class Collection<T extends Data = Data> extends BaseCollection<T> {
|
|
39
|
+
readonly provider: Provider;
|
|
40
|
+
readonly collection: string;
|
|
41
|
+
constructor(provider: Provider, collection: string);
|
|
42
|
+
query(filters?: FilterList<ItemData<T>>, sorts?: SortList<ItemData<T>>, limit?: number | null): Query<T>;
|
|
43
|
+
item(id: string): Item<T>;
|
|
44
|
+
get(id: string): ItemValue<T>;
|
|
45
|
+
add(data: T): string;
|
|
46
|
+
set(id: string, data: T): void;
|
|
47
|
+
update(id: string, updates: Updates<T>): void;
|
|
53
48
|
delete(id: string): void;
|
|
54
49
|
}
|
|
55
50
|
/** Reference to a collection in an asynchronous provider. */
|
|
56
|
-
export declare class AsyncCollection<T extends
|
|
57
|
-
readonly
|
|
58
|
-
readonly collection:
|
|
59
|
-
constructor(
|
|
60
|
-
query(filters?: FilterList<ItemData<T
|
|
61
|
-
item(id: string): AsyncItem<T
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
update(id: string, updates: Updates<T[K]>): Promise<void>;
|
|
51
|
+
export declare class AsyncCollection<T extends Data = Data> extends BaseCollection<T> {
|
|
52
|
+
readonly provider: AsyncProvider;
|
|
53
|
+
readonly collection: string;
|
|
54
|
+
constructor(provider: AsyncProvider, collection: string);
|
|
55
|
+
query(filters?: FilterList<ItemData<T>>, sorts?: SortList<ItemData<T>>, limit?: number | null): AsyncQuery<T>;
|
|
56
|
+
item(id: string): AsyncItem<T>;
|
|
57
|
+
get(id: string): Promise<ItemValue<T>>;
|
|
58
|
+
add(data: T): Promise<string>;
|
|
59
|
+
set(id: string, data: T): Promise<void>;
|
|
60
|
+
update(id: string, updates: Updates<T>): Promise<void>;
|
|
67
61
|
delete(id: string): Promise<void>;
|
|
68
62
|
}
|
|
69
63
|
export {};
|
package/db/Collection.js
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
import { AsyncItem, Item } from "./Item.js";
|
|
2
2
|
import { AsyncQuery, Query } from "./Query.js";
|
|
3
|
-
import { changeAsyncProvider, changeProvider } from "./Change.js";
|
|
4
3
|
/** Reference to a collection in a synchronous or asynchronous provider. */
|
|
5
4
|
class BaseCollection {
|
|
6
5
|
/** Get an add change for this collection. */
|
|
7
6
|
getAdd(data) {
|
|
8
|
-
return this.
|
|
7
|
+
return { action: "ADD", collection: this.collection, data };
|
|
9
8
|
}
|
|
10
9
|
/** Get a set change for this collection. */
|
|
11
10
|
getSet(id, data) {
|
|
12
|
-
return this.
|
|
11
|
+
return { action: "SET", collection: this.collection, id, data };
|
|
13
12
|
}
|
|
14
13
|
/** Get an update change for this collection. */
|
|
15
14
|
getUpdate(id, updates) {
|
|
16
|
-
return this.
|
|
15
|
+
return { action: "UPDATE", collection: this.collection, id, updates };
|
|
17
16
|
}
|
|
18
17
|
/** Get a delete change for this collection. */
|
|
19
18
|
getDelete(id) {
|
|
20
|
-
return this.
|
|
19
|
+
return { action: "DELETE", collection: this.collection, id };
|
|
21
20
|
}
|
|
22
21
|
// Implement toString()
|
|
23
22
|
toString() {
|
|
@@ -26,65 +25,59 @@ class BaseCollection {
|
|
|
26
25
|
}
|
|
27
26
|
/** Reference to a collection in a synchronous provider. */
|
|
28
27
|
export class Collection extends BaseCollection {
|
|
29
|
-
constructor(
|
|
28
|
+
constructor(provider, collection) {
|
|
30
29
|
super();
|
|
31
|
-
this.
|
|
30
|
+
this.provider = provider;
|
|
32
31
|
this.collection = collection;
|
|
33
32
|
}
|
|
34
33
|
query(filters, sorts, limit) {
|
|
35
|
-
return new Query(this.
|
|
34
|
+
return new Query(this.provider, this.collection, filters, sorts, limit);
|
|
36
35
|
}
|
|
37
36
|
item(id) {
|
|
38
|
-
return new Item(this.
|
|
39
|
-
}
|
|
40
|
-
change(...changes) {
|
|
41
|
-
return changeProvider(this.db.provider, changes);
|
|
37
|
+
return new Item(this.provider, this.collection, id);
|
|
42
38
|
}
|
|
43
39
|
get(id) {
|
|
44
|
-
return this.
|
|
40
|
+
return this.provider.getItem(this.collection, id);
|
|
45
41
|
}
|
|
46
42
|
add(data) {
|
|
47
|
-
return this.
|
|
43
|
+
return this.provider.addItem(this.collection, data);
|
|
48
44
|
}
|
|
49
45
|
set(id, data) {
|
|
50
|
-
return this.
|
|
46
|
+
return this.provider.setItem(this.collection, id, data);
|
|
51
47
|
}
|
|
52
48
|
update(id, updates) {
|
|
53
|
-
return this.
|
|
49
|
+
return this.provider.updateItem(this.collection, id, updates);
|
|
54
50
|
}
|
|
55
51
|
delete(id) {
|
|
56
|
-
return this.
|
|
52
|
+
return this.provider.deleteItem(this.collection, id);
|
|
57
53
|
}
|
|
58
54
|
}
|
|
59
55
|
/** Reference to a collection in an asynchronous provider. */
|
|
60
56
|
export class AsyncCollection extends BaseCollection {
|
|
61
|
-
constructor(
|
|
57
|
+
constructor(provider, collection) {
|
|
62
58
|
super();
|
|
63
|
-
this.
|
|
59
|
+
this.provider = provider;
|
|
64
60
|
this.collection = collection;
|
|
65
61
|
}
|
|
66
62
|
query(filters, sorts, limit) {
|
|
67
|
-
return new AsyncQuery(this.
|
|
63
|
+
return new AsyncQuery(this.provider, this.collection, filters, sorts, limit);
|
|
68
64
|
}
|
|
69
65
|
item(id) {
|
|
70
|
-
return new AsyncItem(this.
|
|
71
|
-
}
|
|
72
|
-
change(...changes) {
|
|
73
|
-
return changeAsyncProvider(this.db.provider, changes);
|
|
66
|
+
return new AsyncItem(this.provider, this.collection, id);
|
|
74
67
|
}
|
|
75
68
|
get(id) {
|
|
76
|
-
return this.
|
|
69
|
+
return this.provider.getItem(this.collection, id);
|
|
77
70
|
}
|
|
78
71
|
add(data) {
|
|
79
|
-
return this.
|
|
72
|
+
return this.provider.addItem(this.collection, data);
|
|
80
73
|
}
|
|
81
74
|
set(id, data) {
|
|
82
|
-
return this.
|
|
75
|
+
return this.provider.setItem(this.collection, id, data);
|
|
83
76
|
}
|
|
84
77
|
update(id, updates) {
|
|
85
|
-
return this.
|
|
78
|
+
return this.provider.updateItem(this.collection, id, updates);
|
|
86
79
|
}
|
|
87
80
|
delete(id) {
|
|
88
|
-
return this.
|
|
81
|
+
return this.provider.deleteItem(this.collection, id);
|
|
89
82
|
}
|
|
90
83
|
}
|
package/db/Database.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { DataKey, Datas } from "../util/data.js";
|
|
2
2
|
import type { Nullish } from "../util/null.js";
|
|
3
|
-
import type { DeepIterable } from "../util/iterate.js";
|
|
4
3
|
import type { AsyncProvider, Provider } from "../provider/Provider.js";
|
|
5
4
|
import type { FilterList } from "../constraint/FilterConstraint.js";
|
|
6
5
|
import type { SortList } from "../constraint/SortConstraint.js";
|
|
@@ -12,15 +11,15 @@ import { Collection, AsyncCollection } from "./Collection.js";
|
|
|
12
11
|
import { AddChange, DeleteChange, ItemChanges, SetChange, UpdateChange, WriteChange } from "./Change.js";
|
|
13
12
|
/** Database with a synchronous or asynchronous provider. */
|
|
14
13
|
declare abstract class BaseDatabase<T extends Datas> {
|
|
15
|
-
abstract readonly provider: Provider
|
|
14
|
+
abstract readonly provider: Provider | AsyncProvider;
|
|
16
15
|
/** Create a query on a collection in this database. */
|
|
17
|
-
abstract collection<K extends DataKey<T>>(collection: K): Collection<T
|
|
16
|
+
abstract collection<K extends DataKey<T>>(collection: K): Collection<T[K]> | AsyncCollection<T[K]>;
|
|
18
17
|
/** Create a query on a collection in this database. */
|
|
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
|
|
18
|
+
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]>;
|
|
20
19
|
/** Reference an item in a collection in this database. */
|
|
21
|
-
abstract item<K extends DataKey<T>>(collection: K, id: string): Item<T
|
|
20
|
+
abstract item<K extends DataKey<T>>(collection: K, id: string): Item<T[K]> | AsyncItem<T[K]>;
|
|
22
21
|
/** Run a set of changes in this database. */
|
|
23
|
-
abstract change(...changes:
|
|
22
|
+
abstract change(...changes: Nullish<WriteChange>[]): ItemChanges | Promise<ItemChanges>;
|
|
24
23
|
/** Get a document from a collection in this database. */
|
|
25
24
|
abstract get<K extends DataKey<T>>(collection: K, id: string): ItemValue<T[K]> | Promise<ItemValue<T[K]>>;
|
|
26
25
|
/** Add a document to a collection in this database. */
|
|
@@ -32,22 +31,22 @@ declare abstract class BaseDatabase<T extends Datas> {
|
|
|
32
31
|
/** Delete a document from a collection in this database. */
|
|
33
32
|
abstract delete<K extends DataKey<T>>(collection: K, id: string): void | Promise<void>;
|
|
34
33
|
/** Get an add change for a collection in this database. */
|
|
35
|
-
getAdd<K extends DataKey<T>>(collection: K, data: T[K]): AddChange<T
|
|
34
|
+
getAdd<K extends DataKey<T>>(collection: K, data: T[K]): AddChange<T[K]>;
|
|
36
35
|
/** Get a set change for a collection in this database. */
|
|
37
|
-
getSet<K extends DataKey<T>>(collection: K, id: string, data: T[K]): SetChange<T
|
|
36
|
+
getSet<K extends DataKey<T>>(collection: K, id: string, data: T[K]): SetChange<T[K]>;
|
|
38
37
|
/** Get an update change for a collection in this database. */
|
|
39
|
-
getUpdate<K extends DataKey<T>>(collection: K, id: string, updates: Updates<T[K]>): UpdateChange<T
|
|
38
|
+
getUpdate<K extends DataKey<T>>(collection: K, id: string, updates: Updates<T[K]>): UpdateChange<T[K]>;
|
|
40
39
|
/** Get a delete change for a collection in this database. */
|
|
41
|
-
getDelete<K extends DataKey<T>>(collection: K, id: string): DeleteChange
|
|
40
|
+
getDelete<K extends DataKey<T>>(collection: K, id: string): DeleteChange;
|
|
42
41
|
}
|
|
43
42
|
/** Database with a synchronous provider. */
|
|
44
43
|
export declare class Database<T extends Datas = Datas> extends BaseDatabase<T> {
|
|
45
|
-
readonly provider: Provider
|
|
46
|
-
constructor(provider: Provider
|
|
47
|
-
collection<K extends DataKey<T>>(collection: K): Collection<T
|
|
48
|
-
query<K extends DataKey<T>>(collection: K, filters?: FilterList<ItemData<T[K]>>, sorts?: SortList<ItemData<T[K]>>, limit?: number | null): Query<T
|
|
49
|
-
item<K extends DataKey<T>>(collection: K, id: string): Item<T
|
|
50
|
-
change(...changes:
|
|
44
|
+
readonly provider: Provider;
|
|
45
|
+
constructor(provider: Provider);
|
|
46
|
+
collection<K extends DataKey<T>>(collection: K): Collection<T[K]>;
|
|
47
|
+
query<K extends DataKey<T>>(collection: K, filters?: FilterList<ItemData<T[K]>>, sorts?: SortList<ItemData<T[K]>>, limit?: number | null): Query<T[K]>;
|
|
48
|
+
item<K extends DataKey<T>>(collection: K, id: string): Item<T[K]>;
|
|
49
|
+
change(...changes: Nullish<WriteChange>[]): ItemChanges;
|
|
51
50
|
get<K extends DataKey<T>>(collection: K, id: string): ItemValue<T[K]>;
|
|
52
51
|
add<K extends DataKey<T>>(collection: K, data: T[K]): string;
|
|
53
52
|
set<K extends DataKey<T>>(collection: K, id: string, data: T[K]): void;
|
|
@@ -56,12 +55,12 @@ export declare class Database<T extends Datas = Datas> extends BaseDatabase<T> {
|
|
|
56
55
|
}
|
|
57
56
|
/** Database with a synchronous provider. */
|
|
58
57
|
export declare class AsyncDatabase<T extends Datas = Datas> extends BaseDatabase<T> {
|
|
59
|
-
readonly provider: AsyncProvider
|
|
60
|
-
constructor(provider: AsyncProvider
|
|
61
|
-
collection<K extends DataKey<T>>(collection: K): AsyncCollection<T
|
|
62
|
-
query<K extends DataKey<T>>(collection: K, filters?: FilterList<ItemData<T[K]>>, sorts?: SortList<ItemData<T[K]>>, limit?: number | null): AsyncQuery<T
|
|
63
|
-
item<K extends DataKey<T>>(collection: K, id: string): AsyncItem<T
|
|
64
|
-
change(...changes:
|
|
58
|
+
readonly provider: AsyncProvider;
|
|
59
|
+
constructor(provider: AsyncProvider);
|
|
60
|
+
collection<K extends DataKey<T>>(collection: K): AsyncCollection<T[K]>;
|
|
61
|
+
query<K extends DataKey<T>>(collection: K, filters?: FilterList<ItemData<T[K]>>, sorts?: SortList<ItemData<T[K]>>, limit?: number | null): AsyncQuery<T[K]>;
|
|
62
|
+
item<K extends DataKey<T>>(collection: K, id: string): AsyncItem<T[K]>;
|
|
63
|
+
change(...changes: Nullish<WriteChange>[]): Promise<ItemChanges>;
|
|
65
64
|
get<K extends DataKey<T>>(collection: K, id: string): Promise<ItemValue<T[K]>>;
|
|
66
65
|
add<K extends DataKey<T>>(collection: K, data: T[K]): Promise<string>;
|
|
67
66
|
set<K extends DataKey<T>>(collection: K, id: string, data: T[K]): Promise<void>;
|
package/db/Database.js
CHANGED
|
@@ -28,16 +28,16 @@ export class Database extends BaseDatabase {
|
|
|
28
28
|
this.provider = provider;
|
|
29
29
|
}
|
|
30
30
|
collection(collection) {
|
|
31
|
-
return new Collection(this, collection);
|
|
31
|
+
return new Collection(this.provider, collection);
|
|
32
32
|
}
|
|
33
33
|
query(collection, filters, sorts, limit) {
|
|
34
|
-
return new Query(this, collection, filters, sorts, limit);
|
|
34
|
+
return new Query(this.provider, collection, filters, sorts, limit);
|
|
35
35
|
}
|
|
36
36
|
item(collection, id) {
|
|
37
|
-
return new Item(this, collection, id);
|
|
37
|
+
return new Item(this.provider, collection, id);
|
|
38
38
|
}
|
|
39
39
|
change(...changes) {
|
|
40
|
-
return changeProvider(this.provider, changes);
|
|
40
|
+
return changeProvider(this.provider, ...changes);
|
|
41
41
|
}
|
|
42
42
|
get(collection, id) {
|
|
43
43
|
return this.provider.getItem(collection, id);
|
|
@@ -62,16 +62,16 @@ export class AsyncDatabase extends BaseDatabase {
|
|
|
62
62
|
this.provider = provider;
|
|
63
63
|
}
|
|
64
64
|
collection(collection) {
|
|
65
|
-
return new AsyncCollection(this, collection);
|
|
65
|
+
return new AsyncCollection(this.provider, collection);
|
|
66
66
|
}
|
|
67
67
|
query(collection, filters, sorts, limit) {
|
|
68
|
-
return new AsyncQuery(this, collection, filters, sorts, limit);
|
|
68
|
+
return new AsyncQuery(this.provider, collection, filters, sorts, limit);
|
|
69
69
|
}
|
|
70
70
|
item(collection, id) {
|
|
71
|
-
return new AsyncItem(this, collection, id);
|
|
71
|
+
return new AsyncItem(this.provider, collection, id);
|
|
72
72
|
}
|
|
73
73
|
change(...changes) {
|
|
74
|
-
return changeAsyncProvider(this.provider, changes);
|
|
74
|
+
return changeAsyncProvider(this.provider, ...changes);
|
|
75
75
|
}
|
|
76
76
|
get(collection, id) {
|
|
77
77
|
return this.provider.getItem(collection, id);
|
package/db/Item.d.ts
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
import type { ImmutableArray } from "../util/array.js";
|
|
2
2
|
import type { Stop, Handler, Dispatch } from "../util/function.js";
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
3
|
+
import type { Provider, AsyncProvider } from "../provider/Provider.js";
|
|
4
|
+
import { QueryConstraints } from "../constraint/QueryConstraints.js";
|
|
5
|
+
import { Data } from "../util/data.js";
|
|
5
6
|
import { DataUpdate, Updates } from "../update/DataUpdate.js";
|
|
6
|
-
import { FilterConstraints } from "../constraint/FilterConstraints.js";
|
|
7
7
|
import type { DeleteChange, SetChange, UpdateChange } from "./Change.js";
|
|
8
|
-
import type { AsyncQuery, Query } from "./Query.js";
|
|
9
|
-
import type { AsyncDatabase, Database } from "./Database.js";
|
|
10
8
|
/** Item data with a string ID that uniquely identifies it. */
|
|
11
9
|
export type ItemData<T extends Data = Data> = T & {
|
|
12
10
|
id: string;
|
|
13
11
|
};
|
|
14
12
|
/** Entity or `null` to indicate the item doesn't exist. */
|
|
15
13
|
export type ItemValue<T extends Data = Data> = ItemData<T> | null;
|
|
14
|
+
/** Get the ID from item data. */
|
|
15
|
+
export declare const getID: <T extends Data>({ id }: ItemData<T>) => string;
|
|
16
|
+
/** Get the IDs of an iterable set item data. */
|
|
17
|
+
export declare function getIDs<T extends Data>(entities: Iterable<ItemData<T>>): Iterable<string>;
|
|
16
18
|
/** An array of item data. */
|
|
17
19
|
export type ItemArray<T extends Data = Data> = ImmutableArray<ItemData<T>>;
|
|
18
20
|
/** A set of query constraints for item data. */
|
|
19
21
|
export type ItemConstraints<T extends Data = Data> = QueryConstraints<ItemData<T>>;
|
|
22
|
+
/** Get a `FilterConstraints` instance that targets a single item by its ID. */
|
|
23
|
+
export declare const getItemConstraints: <T extends Data>(id: string) => QueryConstraints<ItemData<T>>;
|
|
20
24
|
/** Reference to an item in a synchronous or asynchronous database. */
|
|
21
|
-
declare abstract class BaseItem<T extends
|
|
22
|
-
abstract readonly
|
|
23
|
-
abstract readonly collection:
|
|
25
|
+
declare abstract class BaseItem<T extends Data = Data> implements AsyncIterable<ItemValue<T>> {
|
|
26
|
+
abstract readonly provider: Provider | AsyncProvider;
|
|
27
|
+
abstract readonly collection: string;
|
|
24
28
|
abstract readonly id: string;
|
|
25
|
-
/** Get an 'optional' reference to this item (uses a `ModelQuery` with an `id` filter). */
|
|
26
|
-
abstract optional: Query<T, K> | AsyncQuery<T, K>;
|
|
27
29
|
/**
|
|
28
30
|
* Does this item exist?
|
|
29
31
|
* @return `true` if an item exists or `false` otherwise (possibly promised).
|
|
@@ -33,7 +35,7 @@ declare abstract class BaseItem<T extends Datas = Datas, K extends DataKey<T> =
|
|
|
33
35
|
* Get the optional data of this item.
|
|
34
36
|
* @return Document's data, or `null` if the item doesn't exist (possibly promised).
|
|
35
37
|
*/
|
|
36
|
-
abstract value: ItemValue<T
|
|
38
|
+
abstract value: ItemValue<T> | PromiseLike<ItemValue<T>>;
|
|
37
39
|
/**
|
|
38
40
|
* Get the data of this item.
|
|
39
41
|
* - Useful for destructuring, e.g. `{ name, title } = await itemThatMustExist.asyncData`
|
|
@@ -41,56 +43,48 @@ declare abstract class BaseItem<T extends Datas = Datas, K extends DataKey<T> =
|
|
|
41
43
|
* @return Document's data (possibly promised).
|
|
42
44
|
* @throws RequiredError if the item does not exist.
|
|
43
45
|
*/
|
|
44
|
-
abstract data: ItemData<T
|
|
46
|
+
abstract data: ItemData<T> | PromiseLike<ItemData<T>>;
|
|
45
47
|
/** Set the complete data of this item. */
|
|
46
|
-
abstract set(data: T
|
|
48
|
+
abstract set(data: T): void | PromiseLike<void>;
|
|
47
49
|
/** Update this item. */
|
|
48
|
-
abstract update(updates: DataUpdate<T
|
|
50
|
+
abstract update(updates: DataUpdate<T> | Updates<T>): void | PromiseLike<void>;
|
|
49
51
|
/** Delete this item. */
|
|
50
52
|
abstract delete(): void | PromiseLike<void>;
|
|
51
53
|
/** Get a set change for this item. */
|
|
52
|
-
getSet(data: T
|
|
54
|
+
getSet(data: T): SetChange<T>;
|
|
53
55
|
/** Get an update change for this item. */
|
|
54
|
-
getUpdate(updates: Updates<T
|
|
56
|
+
getUpdate(updates: Updates<T>): UpdateChange<T>;
|
|
55
57
|
/** Get a delete change for this item. */
|
|
56
|
-
getDelete(): DeleteChange
|
|
57
|
-
toString():
|
|
58
|
+
getDelete(): DeleteChange;
|
|
59
|
+
toString(): string;
|
|
58
60
|
/** Subscribe to this item. */
|
|
59
|
-
subscribe(onNext?: Dispatch<[ItemValue<T
|
|
60
|
-
[Symbol.asyncIterator](): AsyncIterator<ItemValue<T
|
|
61
|
+
subscribe(onNext?: Dispatch<[ItemValue<T>]>, onError?: Handler): Stop;
|
|
62
|
+
[Symbol.asyncIterator](): AsyncIterator<ItemValue<T>>;
|
|
61
63
|
}
|
|
62
64
|
/** Reference to an item in a synchronous database. */
|
|
63
|
-
export declare class Item<T extends
|
|
64
|
-
readonly
|
|
65
|
-
readonly collection:
|
|
65
|
+
export declare class Item<T extends Data = Data> extends BaseItem<T> {
|
|
66
|
+
readonly provider: Provider;
|
|
67
|
+
readonly collection: string;
|
|
66
68
|
readonly id: string;
|
|
67
|
-
constructor(
|
|
68
|
-
get optional(): Query<T, K>;
|
|
69
|
+
constructor(provider: Provider, collection: string, id: string);
|
|
69
70
|
get exists(): boolean;
|
|
70
|
-
get value(): ItemValue<T
|
|
71
|
-
get data(): ItemData<T
|
|
72
|
-
set(data: T
|
|
73
|
-
update(updates: Updates<T
|
|
71
|
+
get value(): ItemValue<T>;
|
|
72
|
+
get data(): ItemData<T>;
|
|
73
|
+
set(data: T): void;
|
|
74
|
+
update(updates: Updates<T>): void;
|
|
74
75
|
delete(): void;
|
|
75
76
|
}
|
|
76
77
|
/** Reference to an item in an asynchronous database. */
|
|
77
|
-
export declare class AsyncItem<T extends
|
|
78
|
-
readonly
|
|
79
|
-
readonly collection:
|
|
78
|
+
export declare class AsyncItem<T extends Data = Data> extends BaseItem<T> {
|
|
79
|
+
readonly provider: AsyncProvider;
|
|
80
|
+
readonly collection: string;
|
|
80
81
|
readonly id: string;
|
|
81
|
-
constructor(
|
|
82
|
-
get optional(): AsyncQuery<T, K>;
|
|
82
|
+
constructor(provider: AsyncProvider, collection: string, id: string);
|
|
83
83
|
get exists(): Promise<boolean>;
|
|
84
|
-
get value(): Promise<ItemValue<T
|
|
85
|
-
get data(): Promise<ItemData<T
|
|
86
|
-
set(data: T
|
|
87
|
-
update(updates: Updates<T
|
|
84
|
+
get value(): Promise<ItemValue<T>>;
|
|
85
|
+
get data(): Promise<ItemData<T>>;
|
|
86
|
+
set(data: T): Promise<void>;
|
|
87
|
+
update(updates: Updates<T>): Promise<void>;
|
|
88
88
|
delete(): Promise<void>;
|
|
89
89
|
}
|
|
90
|
-
/** Get the ID from item data. */
|
|
91
|
-
export declare const getID: <T extends Data>({ id }: ItemData<T>) => string;
|
|
92
|
-
/** Get the IDs of an iterable set item data. */
|
|
93
|
-
export declare function getIDs<T extends Data>(entities: Iterable<ItemData<T>>): Iterable<string>;
|
|
94
|
-
/** Get a `FilterConstraints` instance that targets a single item by its ID. */
|
|
95
|
-
export declare function getItemFilterConstraints<T extends Data>(id: string): FilterConstraints<ItemData<T>>;
|
|
96
90
|
export {};
|