shelving 1.39.0 → 1.40.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/db/Database.d.ts +10 -10
- package/db/Database.js +7 -7
- package/db/Pagination.d.ts +3 -3
- package/db/Write.d.ts +10 -6
- package/db/Write.js +14 -3
- package/db/errors.d.ts +9 -9
- package/firestore/client/FirestoreClientProvider.d.ts +12 -12
- package/firestore/lite/FirestoreLiteProvider.d.ts +10 -10
- package/firestore/server/FirestoreServerProvider.d.ts +12 -12
- package/package.json +1 -1
- package/provider/BatchProvider.d.ts +5 -5
- package/provider/CacheProvider.d.ts +14 -14
- package/provider/MemoryProvider.d.ts +12 -12
- package/provider/Provider.d.ts +30 -30
- package/provider/ThroughProvider.d.ts +12 -12
- package/provider/ValidationProvider.d.ts +10 -10
- package/react/useDocument.d.ts +9 -9
- package/react/usePagination.d.ts +2 -2
- package/react/useQuery.d.ts +13 -13
- package/update/DataUpdate.d.ts +3 -3
- package/update/DataUpdate.js +7 -7
- package/update/ObjectUpdate.d.ts +3 -3
- package/update/ObjectUpdate.js +2 -2
- package/update/Update.d.ts +1 -1
- package/update/Update.js +1 -1
- package/update/util.d.ts +2 -4
- package/update/util.js +3 -3
package/db/Database.d.ts
CHANGED
|
@@ -15,22 +15,22 @@ export declare class Database<V extends Validators<Datas> = Validators<Datas>> {
|
|
|
15
15
|
readonly provider: Provider;
|
|
16
16
|
constructor(validators: V, provider: Provider);
|
|
17
17
|
/** Create a query on a collection in this model. */
|
|
18
|
-
query<K extends Key<V>>(collection: K, filters?: Filters<ValidatorType<V[K]>>, sorts?: Sorts<ValidatorType<V[K]>>, limit?: number | null):
|
|
18
|
+
query<K extends Key<V>>(collection: K, filters?: Filters<ValidatorType<V[K]>>, sorts?: Sorts<ValidatorType<V[K]>>, limit?: number | null): DatabaseQuery<ValidatorType<V[K]>>;
|
|
19
19
|
/** Reference a document in a collection in this model. */
|
|
20
|
-
doc<K extends Key<V>>(collection: K, id: string):
|
|
20
|
+
doc<K extends Key<V>>(collection: K, id: string): DatabaseDocument<ValidatorType<V[K]>>;
|
|
21
21
|
/** Create a writer for this database from a set of separate writes. */
|
|
22
22
|
writer(...writes: Nullish<Write>[]): Write;
|
|
23
23
|
/** Perform one or more writes on this database and return the `Writes` instance representing the combined changes. */
|
|
24
24
|
write(...writes: Nullish<Write>[]): Promise<Write>;
|
|
25
25
|
}
|
|
26
26
|
/** A documents reference within a specific database. */
|
|
27
|
-
export declare class
|
|
27
|
+
export declare class DatabaseQuery<T extends Data = Data> extends Query<T> implements Observable<Results<T>>, Validatable<Entries<T>>, Iterable<Entry<T>> {
|
|
28
28
|
readonly provider: Provider;
|
|
29
29
|
readonly validator: Validator<T>;
|
|
30
30
|
readonly collection: string;
|
|
31
31
|
constructor(provider: Provider, validator: Validator<T>, collection: string, filters?: Filters<T>, sorts?: Sorts<T>, limit?: number | null);
|
|
32
32
|
/** Reference a document in this query's collection. */
|
|
33
|
-
doc(id: string):
|
|
33
|
+
doc(id: string): DatabaseDocument<T>;
|
|
34
34
|
/**
|
|
35
35
|
* Create a new document with a random ID.
|
|
36
36
|
* - Created document is guaranteed to have a unique ID.
|
|
@@ -107,18 +107,18 @@ export declare class DataQuery<T extends Data = Data> extends Query<T> implement
|
|
|
107
107
|
toString(): string;
|
|
108
108
|
}
|
|
109
109
|
/** Get the data for a document from a result for that document. */
|
|
110
|
-
export declare function getQueryData<T extends Data>(entries: Entries<T>, ref:
|
|
110
|
+
export declare function getQueryData<T extends Data>(entries: Entries<T>, ref: DatabaseQuery<T>): Entry<T>;
|
|
111
111
|
/** A document reference within a specific database. */
|
|
112
|
-
export declare class
|
|
112
|
+
export declare class DatabaseDocument<T extends Data = Data> implements Observable<Result<T>>, Validatable<T> {
|
|
113
113
|
readonly provider: Provider;
|
|
114
114
|
readonly validator: Validator<T>;
|
|
115
115
|
readonly collection: string;
|
|
116
116
|
readonly id: string;
|
|
117
117
|
constructor(provider: Provider, validator: Validator<T>, collection: string, id: string);
|
|
118
118
|
/** Create a query on this document's collection. */
|
|
119
|
-
query(filters?: Filters<T>, sorts?: Sorts<T>, limit?: number | null):
|
|
119
|
+
query(filters?: Filters<T>, sorts?: Sorts<T>, limit?: number | null): DatabaseQuery<T>;
|
|
120
120
|
/** Get an 'optional' reference to this document (uses a `ModelQuery` with an `id` filter). */
|
|
121
|
-
get optional():
|
|
121
|
+
get optional(): DatabaseQuery<T>;
|
|
122
122
|
/**
|
|
123
123
|
* Does this document exist?
|
|
124
124
|
* @return `true` if a document exists or `false` otherwise (possibly promised).
|
|
@@ -154,7 +154,7 @@ export declare class DataDocument<T extends Data = Data> implements Observable<R
|
|
|
154
154
|
/** Represent a write that sets the complete data of this document in a database. */
|
|
155
155
|
setter(data: T): DocumentSet<T>;
|
|
156
156
|
/** Represent a write that updates this document in a database. */
|
|
157
|
-
updater(updates:
|
|
157
|
+
updater(updates: PropUpdates<T>): DocumentUpdate<T>;
|
|
158
158
|
/** Represent a write that deletes this document in a database. */
|
|
159
159
|
deleter(): DocumentDelete<T>;
|
|
160
160
|
/** Validate data for this query reference. */
|
|
@@ -162,4 +162,4 @@ export declare class DataDocument<T extends Data = Data> implements Observable<R
|
|
|
162
162
|
toString(): string;
|
|
163
163
|
}
|
|
164
164
|
/** Get the data for a document from a result for that document. */
|
|
165
|
-
export declare function getDocumentData<T extends Data>(result: Result<T>, ref:
|
|
165
|
+
export declare function getDocumentData<T extends Data>(result: Result<T>, ref: DatabaseDocument<T>): T;
|
package/db/Database.js
CHANGED
|
@@ -19,11 +19,11 @@ export class Database {
|
|
|
19
19
|
}
|
|
20
20
|
/** Create a query on a collection in this model. */
|
|
21
21
|
query(collection, filters, sorts, limit) {
|
|
22
|
-
return new
|
|
22
|
+
return new DatabaseQuery(this.provider, this.validators[collection], collection, filters, sorts, limit);
|
|
23
23
|
}
|
|
24
24
|
/** Reference a document in a collection in this model. */
|
|
25
25
|
doc(collection, id) {
|
|
26
|
-
return new
|
|
26
|
+
return new DatabaseDocument(this.provider, this.validators[collection], collection, id);
|
|
27
27
|
}
|
|
28
28
|
/** Create a writer for this database from a set of separate writes. */
|
|
29
29
|
writer(...writes) {
|
|
@@ -37,7 +37,7 @@ export class Database {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
/** A documents reference within a specific database. */
|
|
40
|
-
export class
|
|
40
|
+
export class DatabaseQuery extends Query {
|
|
41
41
|
constructor(provider, validator, collection, filters, sorts, limit) {
|
|
42
42
|
super(filters, sorts, limit);
|
|
43
43
|
this.provider = provider;
|
|
@@ -46,7 +46,7 @@ export class DataQuery extends Query {
|
|
|
46
46
|
}
|
|
47
47
|
/** Reference a document in this query's collection. */
|
|
48
48
|
doc(id) {
|
|
49
|
-
return new
|
|
49
|
+
return new DatabaseDocument(this.provider, this.validator, this.collection, id);
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* Create a new document with a random ID.
|
|
@@ -174,7 +174,7 @@ export function getQueryData(entries, ref) {
|
|
|
174
174
|
throw new QueryRequiredError(ref);
|
|
175
175
|
}
|
|
176
176
|
/** A document reference within a specific database. */
|
|
177
|
-
export class
|
|
177
|
+
export class DatabaseDocument {
|
|
178
178
|
constructor(provider, validator, collection, id) {
|
|
179
179
|
this.provider = provider;
|
|
180
180
|
this.validator = validator;
|
|
@@ -183,11 +183,11 @@ export class DataDocument {
|
|
|
183
183
|
}
|
|
184
184
|
/** Create a query on this document's collection. */
|
|
185
185
|
query(filters, sorts, limit) {
|
|
186
|
-
return new
|
|
186
|
+
return new DatabaseQuery(this.provider, this.validator, this.collection, filters, sorts, limit);
|
|
187
187
|
}
|
|
188
188
|
/** Get an 'optional' reference to this document (uses a `ModelQuery` with an `id` filter). */
|
|
189
189
|
get optional() {
|
|
190
|
-
return new
|
|
190
|
+
return new DatabaseQuery(this.provider, this.validator, this.collection, new Filters(new EqualFilter("id", this.id)));
|
|
191
191
|
}
|
|
192
192
|
/**
|
|
193
193
|
* Does this document exist?
|
package/db/Pagination.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Results, Entry, Entries, Data } from "../util/index.js";
|
|
2
2
|
import { State } from "../stream/index.js";
|
|
3
|
-
import {
|
|
3
|
+
import { DatabaseQuery } from "./Database.js";
|
|
4
4
|
/**
|
|
5
5
|
* State that wraps a `Documents` reference to enable pagination.
|
|
6
6
|
* - If you pass in initial values, it will use that as the first page.
|
|
@@ -8,9 +8,9 @@ import { DataQuery } from "./Database.js";
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class Pagination<T extends Data> extends State<Results<T>> implements Iterable<Entry<T>> {
|
|
10
10
|
protected _pending: boolean;
|
|
11
|
-
readonly ref:
|
|
11
|
+
readonly ref: DatabaseQuery<T>;
|
|
12
12
|
readonly limit: number;
|
|
13
|
-
constructor(ref:
|
|
13
|
+
constructor(ref: DatabaseQuery<T>);
|
|
14
14
|
/**
|
|
15
15
|
* Load more results after the end.
|
|
16
16
|
* - Promise that needs to be handled.
|
package/db/Write.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PropUpdates, Update } from "../update/index.js";
|
|
2
|
-
import { ImmutableArray, Data, Transformable } from "../util/index.js";
|
|
3
|
-
import type { Database,
|
|
2
|
+
import { ImmutableArray, Data, Transformable, Key, Nullish } from "../util/index.js";
|
|
3
|
+
import type { Database, DatabaseDocument } from "./Database.js";
|
|
4
4
|
/** Represent a write made to a database. */
|
|
5
5
|
export declare abstract class Write implements Transformable<Database, void | PromiseLike<void>> {
|
|
6
6
|
abstract transform(db: Database): void | PromiseLike<void>;
|
|
@@ -19,19 +19,23 @@ export declare class Writes extends Write {
|
|
|
19
19
|
export declare abstract class DocumentWrite<T extends Data> extends Write {
|
|
20
20
|
readonly collection: string;
|
|
21
21
|
readonly id: string;
|
|
22
|
-
constructor({ collection, id }:
|
|
22
|
+
constructor({ collection, id }: DatabaseDocument<T>);
|
|
23
23
|
}
|
|
24
24
|
/** Represent a set operation made to a single document in a database. */
|
|
25
25
|
export declare class DocumentSet<T extends Data> extends DocumentWrite<T> {
|
|
26
26
|
readonly data: T;
|
|
27
|
-
constructor(ref:
|
|
27
|
+
constructor(ref: DatabaseDocument<T>, data: T);
|
|
28
28
|
transform(db: Database): Promise<void>;
|
|
29
|
+
/** Set one of the props on this set operation to a different value. */
|
|
30
|
+
set<K extends Key<T>>(key: Nullish<K>, value: T[K]): this;
|
|
29
31
|
}
|
|
30
32
|
/** Represent an update operation made to a single document in a database. */
|
|
31
33
|
export declare class DocumentUpdate<T extends Data> extends DocumentWrite<T> {
|
|
32
|
-
readonly updates:
|
|
33
|
-
constructor(ref:
|
|
34
|
+
readonly updates: PropUpdates<T>;
|
|
35
|
+
constructor(ref: DatabaseDocument<T>, updates: PropUpdates<T>);
|
|
34
36
|
transform(db: Database): Promise<void>;
|
|
37
|
+
/** update one of the props on this set operation to a different value. */
|
|
38
|
+
update<K extends Key<T>>(key: Nullish<K>, value: T[K] | Update<T[K]>): this;
|
|
35
39
|
}
|
|
36
40
|
/** Represent a delete operation made to a single document in a database. */
|
|
37
41
|
export declare class DocumentDelete<T extends Data> extends DocumentWrite<T> {
|
package/db/Write.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { transform } from "../util/index.js";
|
|
1
|
+
import { transform, isNullish } from "../util/index.js";
|
|
3
2
|
/** Represent a write made to a database. */
|
|
4
3
|
export class Write {
|
|
5
4
|
}
|
|
@@ -35,16 +34,28 @@ export class DocumentSet extends DocumentWrite {
|
|
|
35
34
|
async transform(db) {
|
|
36
35
|
await db.doc(this.collection, this.id).set(this.data);
|
|
37
36
|
}
|
|
37
|
+
/** Set one of the props on this set operation to a different value. */
|
|
38
|
+
set(key, value) {
|
|
39
|
+
if (isNullish(key))
|
|
40
|
+
return this;
|
|
41
|
+
return { __proto__: Object.getPrototypeOf(this), ...this, data: { ...this.data, [key]: value } };
|
|
42
|
+
}
|
|
38
43
|
}
|
|
39
44
|
/** Represent an update operation made to a single document in a database. */
|
|
40
45
|
export class DocumentUpdate extends DocumentWrite {
|
|
41
46
|
constructor(ref, updates) {
|
|
42
47
|
super(ref);
|
|
43
|
-
this.updates = updates
|
|
48
|
+
this.updates = updates;
|
|
44
49
|
}
|
|
45
50
|
async transform(db) {
|
|
46
51
|
await db.doc(this.collection, this.id).update(this.updates);
|
|
47
52
|
}
|
|
53
|
+
/** update one of the props on this set operation to a different value. */
|
|
54
|
+
update(key, value) {
|
|
55
|
+
if (isNullish(key))
|
|
56
|
+
return this;
|
|
57
|
+
return { __proto__: Object.getPrototypeOf(this), ...this, updates: { ...this.updates, [key]: value } };
|
|
58
|
+
}
|
|
48
59
|
}
|
|
49
60
|
/** Represent a delete operation made to a single document in a database. */
|
|
50
61
|
export class DocumentDelete extends DocumentWrite {
|
package/db/errors.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import type { Data } from "../util/index.js";
|
|
2
2
|
import { RequiredError, ValidationError } from "../error/index.js";
|
|
3
3
|
import type { Feedback } from "../feedback/index.js";
|
|
4
|
-
import type {
|
|
4
|
+
import type { DatabaseDocument, DatabaseQuery } from "./Database.js";
|
|
5
5
|
/** Thrown if a document doesn't exist. */
|
|
6
6
|
export declare class DocumentRequiredError<T extends Data> extends RequiredError {
|
|
7
|
-
ref:
|
|
8
|
-
constructor(ref:
|
|
7
|
+
ref: DatabaseDocument<T>;
|
|
8
|
+
constructor(ref: DatabaseDocument<T>);
|
|
9
9
|
}
|
|
10
10
|
/** Thrown if a query doesn't exist. */
|
|
11
11
|
export declare class QueryRequiredError<T extends Data> extends RequiredError {
|
|
12
|
-
ref:
|
|
13
|
-
constructor(ref:
|
|
12
|
+
ref: DatabaseQuery<T>;
|
|
13
|
+
constructor(ref: DatabaseQuery<T>);
|
|
14
14
|
}
|
|
15
15
|
/** Thrown if a document can't validate. */
|
|
16
16
|
export declare class DocumentValidationError<T extends Data> extends ValidationError {
|
|
17
|
-
ref:
|
|
18
|
-
constructor(ref:
|
|
17
|
+
ref: DatabaseDocument<T>;
|
|
18
|
+
constructor(ref: DatabaseDocument<T>, feedback: Feedback);
|
|
19
19
|
}
|
|
20
20
|
/** Thrown if a query can't validate a set of results. */
|
|
21
21
|
export declare class QueryValidationError<T extends Data> extends ValidationError {
|
|
22
|
-
ref:
|
|
23
|
-
constructor(ref:
|
|
22
|
+
ref: DatabaseQuery<T>;
|
|
23
|
+
constructor(ref: DatabaseQuery<T>, feedback: Feedback);
|
|
24
24
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Firestore } from "firebase/firestore";
|
|
2
|
-
import { Entries, Provider,
|
|
2
|
+
import { Entries, Provider, DatabaseDocument, DatabaseQuery, Result, Observer, Update, AsynchronousProvider, Data, Unsubscriber } from "../../index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Firestore client database provider.
|
|
5
5
|
* - Works with the Firebase JS SDK.
|
|
@@ -9,15 +9,15 @@ import { Entries, Provider, DataDocument, DataQuery, Result, Observer, Update, A
|
|
|
9
9
|
export declare class FirestoreClientProvider extends Provider implements AsynchronousProvider {
|
|
10
10
|
readonly firestore: Firestore;
|
|
11
11
|
constructor(firestore: Firestore);
|
|
12
|
-
get<T extends Data>(ref:
|
|
13
|
-
subscribe<T extends Data>(ref:
|
|
14
|
-
add<T extends Data>(ref:
|
|
15
|
-
set<T extends Data>(ref:
|
|
16
|
-
update<T extends Data>(ref:
|
|
17
|
-
delete<T extends Data>(ref:
|
|
18
|
-
getQuery<T extends Data>(ref:
|
|
19
|
-
subscribeQuery<T extends Data>(ref:
|
|
20
|
-
setQuery<T extends Data>(ref:
|
|
21
|
-
updateQuery<T extends Data>(ref:
|
|
22
|
-
deleteQuery<T extends Data>(ref:
|
|
12
|
+
get<T extends Data>(ref: DatabaseDocument<T>): Promise<Result<T>>;
|
|
13
|
+
subscribe<T extends Data>(ref: DatabaseDocument<T>, observer: Observer<Result<T>>): Unsubscriber;
|
|
14
|
+
add<T extends Data>(ref: DatabaseQuery<T>, data: T): Promise<string>;
|
|
15
|
+
set<T extends Data>(ref: DatabaseDocument<T>, data: T): Promise<void>;
|
|
16
|
+
update<T extends Data>(ref: DatabaseDocument<T>, updates: Update<T>): Promise<void>;
|
|
17
|
+
delete<T extends Data>(ref: DatabaseDocument<T>): Promise<void>;
|
|
18
|
+
getQuery<T extends Data>(ref: DatabaseQuery<T>): Promise<Entries<T>>;
|
|
19
|
+
subscribeQuery<T extends Data>(ref: DatabaseQuery<T>, observer: Observer<Entries<T>>): Unsubscriber;
|
|
20
|
+
setQuery<T extends Data>(ref: DatabaseQuery<T>, data: T): Promise<number>;
|
|
21
|
+
updateQuery<T extends Data>(ref: DatabaseQuery<T>, updates: Update<T>): Promise<number>;
|
|
22
|
+
deleteQuery<T extends Data>(ref: DatabaseQuery<T>): Promise<number>;
|
|
23
23
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Firestore } from "firebase/firestore/lite";
|
|
2
|
-
import { Provider,
|
|
2
|
+
import { Provider, DatabaseDocument, DatabaseQuery, Result, Update, AsynchronousProvider, Data, Entries, Unsubscriber } from "../../index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Firestore Lite client database provider.
|
|
5
5
|
* - Works with the Firebase JS SDK.
|
|
@@ -9,15 +9,15 @@ import { Provider, DataDocument, DataQuery, Result, Update, AsynchronousProvider
|
|
|
9
9
|
export declare class FirestoreClientProvider extends Provider implements AsynchronousProvider {
|
|
10
10
|
readonly firestore: Firestore;
|
|
11
11
|
constructor(firestore: Firestore);
|
|
12
|
-
get<T extends Data>(ref:
|
|
12
|
+
get<T extends Data>(ref: DatabaseDocument<T>): Promise<Result<T>>;
|
|
13
13
|
subscribe(): Unsubscriber;
|
|
14
|
-
add<T extends Data>(ref:
|
|
15
|
-
set<T extends Data>(ref:
|
|
16
|
-
update<T extends Data>(ref:
|
|
17
|
-
delete<T extends Data>(ref:
|
|
18
|
-
getQuery<T extends Data>(ref:
|
|
14
|
+
add<T extends Data>(ref: DatabaseQuery<T>, data: T): Promise<string>;
|
|
15
|
+
set<T extends Data>(ref: DatabaseDocument<T>, data: T): Promise<void>;
|
|
16
|
+
update<T extends Data>(ref: DatabaseDocument<T>, updates: Update<T>): Promise<void>;
|
|
17
|
+
delete<T extends Data>(ref: DatabaseDocument<T>): Promise<void>;
|
|
18
|
+
getQuery<T extends Data>(ref: DatabaseQuery<T>): Promise<Entries<T>>;
|
|
19
19
|
subscribeQuery(): Unsubscriber;
|
|
20
|
-
setQuery<T extends Data>(ref:
|
|
21
|
-
updateQuery<T extends Data>(ref:
|
|
22
|
-
deleteQuery<T extends Data>(ref:
|
|
20
|
+
setQuery<T extends Data>(ref: DatabaseQuery<T>, data: T | Update<T> | undefined): Promise<number>;
|
|
21
|
+
updateQuery<T extends Data>(ref: DatabaseQuery<T>, updates: Update<T>): Promise<number>;
|
|
22
|
+
deleteQuery<T extends Data>(ref: DatabaseQuery<T>): Promise<number>;
|
|
23
23
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Firestore } from "@google-cloud/firestore";
|
|
2
|
-
import { Provider,
|
|
2
|
+
import { Provider, DatabaseDocument, DatabaseQuery, Observer, Result, Update, Data, AsynchronousProvider, Entry, Entries, Unsubscriber } from "../../index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Firestore server database provider.
|
|
5
5
|
* - Works with the Firebase Admin SDK for Node.JS
|
|
@@ -7,15 +7,15 @@ import { Provider, DataDocument, DataQuery, Observer, Result, Update, Data, Asyn
|
|
|
7
7
|
export declare class FirestoreServerProvider extends Provider implements AsynchronousProvider {
|
|
8
8
|
readonly firestore: Firestore;
|
|
9
9
|
constructor(firestore?: Firestore);
|
|
10
|
-
get<T extends Data>(ref:
|
|
11
|
-
subscribe<T extends Data>(ref:
|
|
12
|
-
add<T extends Data>(ref:
|
|
13
|
-
set<T extends Data>(ref:
|
|
14
|
-
update<T extends Data>(ref:
|
|
15
|
-
delete<T extends Data>(ref:
|
|
16
|
-
getQuery<T extends Data>(ref:
|
|
17
|
-
subscribeQuery<T extends Data>(ref:
|
|
18
|
-
setQuery<T extends Data>(ref:
|
|
19
|
-
updateQuery<T extends Data>(ref:
|
|
20
|
-
deleteQuery<T extends Data>(ref:
|
|
10
|
+
get<T extends Data>(ref: DatabaseDocument<T>): Promise<Result<T>>;
|
|
11
|
+
subscribe<T extends Data>(ref: DatabaseDocument<T>, observer: Observer<Result<T>>): Unsubscriber;
|
|
12
|
+
add<T extends Data>(ref: DatabaseQuery<T>, data: T): Promise<string>;
|
|
13
|
+
set<T extends Data>(ref: DatabaseDocument<T>, data: T): Promise<void>;
|
|
14
|
+
update<T extends Data>(ref: DatabaseDocument<T>, updates: Update<T>): Promise<void>;
|
|
15
|
+
delete<T extends Data>(ref: DatabaseDocument<T>): Promise<void>;
|
|
16
|
+
getQuery<T extends Data>(ref: DatabaseQuery<T>): Promise<Iterable<Entry<T>>>;
|
|
17
|
+
subscribeQuery<T extends Data>(ref: DatabaseQuery<T>, observer: Observer<Entries<T>>): Unsubscriber;
|
|
18
|
+
setQuery<T extends Data>(ref: DatabaseQuery<T>, data: T | Update<T> | undefined): Promise<number>;
|
|
19
|
+
updateQuery<T extends Data>(ref: DatabaseQuery<T>, updates: Update<T>): Promise<number>;
|
|
20
|
+
deleteQuery<T extends Data>(ref: DatabaseQuery<T>): Promise<number>;
|
|
21
21
|
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MutableObject, Result, Observer, Unsubscriber, Observable, Entries, Results, Data } from "../util/index.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { DatabaseDocument, DatabaseQuery } from "../db/index.js";
|
|
3
3
|
import { ThroughProvider } from "./ThroughProvider.js";
|
|
4
4
|
/**
|
|
5
5
|
* Provider that batches multiple database reads from a source provider together, for efficiency.
|
|
@@ -15,12 +15,12 @@ export declare class BatchProvider extends ThroughProvider {
|
|
|
15
15
|
protected readonly _gets: MutableObject<Promise<any>>;
|
|
16
16
|
/** List of currently ongoing subscription streams. */
|
|
17
17
|
protected readonly _subs: MutableObject<Observable<any>>;
|
|
18
|
-
get<T extends Data>(ref:
|
|
18
|
+
get<T extends Data>(ref: DatabaseDocument<T>): Result<T> | Promise<Result<T>>;
|
|
19
19
|
/** Await a result and delete it from get requests when done. */
|
|
20
20
|
private _awaitDocument;
|
|
21
|
-
subscribe<T extends Data>(ref:
|
|
22
|
-
getQuery<T extends Data>(ref:
|
|
21
|
+
subscribe<T extends Data>(ref: DatabaseDocument<T>, observer: Observer<Result<T>>): Unsubscriber;
|
|
22
|
+
getQuery<T extends Data>(ref: DatabaseQuery<T>): Entries<T> | Promise<Entries<T>>;
|
|
23
23
|
/** Await a set of results and delete from get requests when done. */
|
|
24
24
|
private _awaitDocuments;
|
|
25
|
-
subscribeQuery<T extends Data>(ref:
|
|
25
|
+
subscribeQuery<T extends Data>(ref: DatabaseQuery<T>, observer: Observer<Results<T>>): Unsubscriber;
|
|
26
26
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DatabaseDocument, DatabaseQuery } from "../db/index.js";
|
|
2
2
|
import { Update } from "../update/index.js";
|
|
3
3
|
import { Result, Unsubscriber, Observer, Entries, Data } from "../util/index.js";
|
|
4
4
|
import type { Provider, AsynchronousProvider } from "./Provider.js";
|
|
@@ -12,24 +12,24 @@ export declare class CacheProvider extends ThroughProvider implements Asynchrono
|
|
|
12
12
|
private _times;
|
|
13
13
|
constructor(source: Provider, cache?: MemoryProvider);
|
|
14
14
|
/** Is a given document or query in the cache? */
|
|
15
|
-
isCached<T extends Data>(ref:
|
|
15
|
+
isCached<T extends Data>(ref: DatabaseDocument<T> | DatabaseQuery<T>): boolean;
|
|
16
16
|
/** Get the cache age for a given document or query reference. */
|
|
17
|
-
getCachedAge<T extends Data>(ref:
|
|
17
|
+
getCachedAge<T extends Data>(ref: DatabaseDocument<T> | DatabaseQuery<T>): number;
|
|
18
18
|
/** Cache an individual document result. */
|
|
19
19
|
private _cacheResult;
|
|
20
|
-
get<T extends Data>(ref:
|
|
21
|
-
subscribe<T extends Data>(ref:
|
|
22
|
-
add<T extends Data>(ref:
|
|
23
|
-
set<T extends Data>(ref:
|
|
24
|
-
update<T extends Data>(ref:
|
|
25
|
-
delete<T extends Data>(ref:
|
|
20
|
+
get<T extends Data>(ref: DatabaseDocument<T>): Promise<Result<T>>;
|
|
21
|
+
subscribe<T extends Data>(ref: DatabaseDocument<T>, observer: Observer<Result<T>>): Unsubscriber;
|
|
22
|
+
add<T extends Data>(ref: DatabaseQuery<T>, data: T): Promise<string>;
|
|
23
|
+
set<T extends Data>(ref: DatabaseDocument<T>, data: T): Promise<void>;
|
|
24
|
+
update<T extends Data>(ref: DatabaseDocument<T>, updates: Update<T>): Promise<void>;
|
|
25
|
+
delete<T extends Data>(ref: DatabaseDocument<T>): Promise<void>;
|
|
26
26
|
/** Cache a set of document entries. */
|
|
27
27
|
private _cacheEntries;
|
|
28
|
-
getQuery<T extends Data>(ref:
|
|
29
|
-
subscribeQuery<T extends Data>(ref:
|
|
30
|
-
setQuery<T extends Data>(ref:
|
|
31
|
-
updateQuery<T extends Data>(ref:
|
|
32
|
-
deleteQuery<T extends Data>(ref:
|
|
28
|
+
getQuery<T extends Data>(ref: DatabaseQuery<T>): Promise<Entries<T>>;
|
|
29
|
+
subscribeQuery<T extends Data>(ref: DatabaseQuery<T>, observer: Observer<Entries<T>>): Unsubscriber;
|
|
30
|
+
setQuery<T extends Data>(ref: DatabaseQuery<T>, data: T): Promise<number>;
|
|
31
|
+
updateQuery<T extends Data>(ref: DatabaseQuery<T>, updates: Update<T>): Promise<number>;
|
|
32
|
+
deleteQuery<T extends Data>(ref: DatabaseQuery<T>): Promise<number>;
|
|
33
33
|
/** Reset this provider and clear all data. */
|
|
34
34
|
reset(): void;
|
|
35
35
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Data, Result, Entries, Unsubscriber, Observer } from "../util/index.js";
|
|
2
2
|
import { Update } from "../update/index.js";
|
|
3
|
-
import {
|
|
3
|
+
import { DatabaseQuery, DatabaseDocument } from "../db/index.js";
|
|
4
4
|
import { Provider, SynchronousProvider } from "./Provider.js";
|
|
5
5
|
/**
|
|
6
6
|
* Fast in-memory store for data.
|
|
@@ -11,17 +11,17 @@ export declare class MemoryProvider extends Provider implements SynchronousProvi
|
|
|
11
11
|
/** List of tables in `{ path: Table }` format. */
|
|
12
12
|
private _tables;
|
|
13
13
|
private _table;
|
|
14
|
-
get<T extends Data>(ref:
|
|
15
|
-
subscribe<T extends Data>(ref:
|
|
16
|
-
add<T extends Data>(ref:
|
|
17
|
-
set<T extends Data>(ref:
|
|
18
|
-
update<T extends Data>(ref:
|
|
19
|
-
delete<T extends Data>(ref:
|
|
20
|
-
getQuery<T extends Data>(ref:
|
|
21
|
-
subscribeQuery<T extends Data>(ref:
|
|
22
|
-
setQuery<T extends Data>(ref:
|
|
23
|
-
updateQuery<T extends Data>(ref:
|
|
24
|
-
deleteQuery<T extends Data>(ref:
|
|
14
|
+
get<T extends Data>(ref: DatabaseDocument<T>): Result<T>;
|
|
15
|
+
subscribe<T extends Data>(ref: DatabaseDocument<T>, observer: Observer<Result<T>>): Unsubscriber;
|
|
16
|
+
add<T extends Data>(ref: DatabaseQuery<T>, data: T): string;
|
|
17
|
+
set<T extends Data>(ref: DatabaseDocument<T>, data: T): void;
|
|
18
|
+
update<T extends Data>(ref: DatabaseDocument<T>, updates: Update<T>): void;
|
|
19
|
+
delete<T extends Data>(ref: DatabaseDocument<T>): void;
|
|
20
|
+
getQuery<T extends Data>(ref: DatabaseQuery<T>): Entries<T>;
|
|
21
|
+
subscribeQuery<T extends Data>(ref: DatabaseQuery<T>, observer: Observer<Entries<T>>): Unsubscriber;
|
|
22
|
+
setQuery<T extends Data>(ref: DatabaseQuery<T>, data: T): number;
|
|
23
|
+
updateQuery<T extends Data>(ref: DatabaseQuery<T>, updates: Update<T>): number;
|
|
24
|
+
deleteQuery<T extends Data>(ref: DatabaseQuery<T>): number;
|
|
25
25
|
/** Reset this provider and clear all data. */
|
|
26
26
|
reset(): void;
|
|
27
27
|
}
|
package/provider/Provider.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Observer, Unsubscriber, Result, Entries, Data } from "../util/index.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { DatabaseDocument, DatabaseQuery } from "../db/Database.js";
|
|
3
3
|
import type { Update } from "../update/index.js";
|
|
4
4
|
/** Provides access to data (e.g. IndexedDB, Firebase, or in-memory cache providers). */
|
|
5
5
|
export declare abstract class Provider {
|
|
@@ -9,7 +9,7 @@ export declare abstract class Provider {
|
|
|
9
9
|
* @param ref Document reference specifying which document to get.
|
|
10
10
|
* @return The document object, or `undefined` if it doesn't exist.
|
|
11
11
|
*/
|
|
12
|
-
abstract get<T extends Data>(ref:
|
|
12
|
+
abstract get<T extends Data>(ref: DatabaseDocument<T>): Result<T> | PromiseLike<Result<T>>;
|
|
13
13
|
/**
|
|
14
14
|
* Subscribe to the result of a document.
|
|
15
15
|
* - `next()` is called once with the initial result, and again any time the result changes.
|
|
@@ -19,7 +19,7 @@ export declare abstract class Provider {
|
|
|
19
19
|
*
|
|
20
20
|
* @return Function that ends the subscription.
|
|
21
21
|
*/
|
|
22
|
-
abstract subscribe<T extends Data>(ref:
|
|
22
|
+
abstract subscribe<T extends Data>(ref: DatabaseDocument<T>, observer: Observer<Result<T>>): Unsubscriber;
|
|
23
23
|
/**
|
|
24
24
|
* Create a new document with a random ID.
|
|
25
25
|
* - Created document is guaranteed to have a unique ID.
|
|
@@ -29,7 +29,7 @@ export declare abstract class Provider {
|
|
|
29
29
|
*
|
|
30
30
|
* @return String ID for the created document (possibly promised).
|
|
31
31
|
*/
|
|
32
|
-
abstract add<T extends Data>(ref:
|
|
32
|
+
abstract add<T extends Data>(ref: DatabaseQuery<T>, data: T): string | PromiseLike<string>;
|
|
33
33
|
/**
|
|
34
34
|
* Set the data a document.
|
|
35
35
|
* - If the document exists, set the value of it.
|
|
@@ -40,7 +40,7 @@ export declare abstract class Provider {
|
|
|
40
40
|
*
|
|
41
41
|
* @throws Error If a `Update` was provided but the document does not exist (ideally a `RequiredError` but may be provider-specific).
|
|
42
42
|
*/
|
|
43
|
-
abstract set<T extends Data>(ref:
|
|
43
|
+
abstract set<T extends Data>(ref: DatabaseDocument<T>, value: T): void | PromiseLike<void>;
|
|
44
44
|
/**
|
|
45
45
|
* Update the data an existing document.
|
|
46
46
|
*
|
|
@@ -49,19 +49,19 @@ export declare abstract class Provider {
|
|
|
49
49
|
*
|
|
50
50
|
* @throws Error If the document does not exist (ideally a `RequiredError` but may be provider-specific).
|
|
51
51
|
*/
|
|
52
|
-
abstract update<T extends Data>(ref:
|
|
52
|
+
abstract update<T extends Data>(ref: DatabaseDocument<T>, updates: Update<T>): void | PromiseLike<void>;
|
|
53
53
|
/**
|
|
54
54
|
* Delete a specified document.
|
|
55
55
|
* @param ref Document reference specifying which document to delete.
|
|
56
56
|
*/
|
|
57
|
-
abstract delete<T extends Data>(ref:
|
|
57
|
+
abstract delete<T extends Data>(ref: DatabaseDocument<T>): void | PromiseLike<void>;
|
|
58
58
|
/**
|
|
59
59
|
* Get all matching documents.
|
|
60
60
|
*
|
|
61
61
|
* @param ref Documents reference specifying which collection to get documents from.
|
|
62
62
|
* @return Set of results in `id: data` format.
|
|
63
63
|
*/
|
|
64
|
-
abstract getQuery<T extends Data>(ref:
|
|
64
|
+
abstract getQuery<T extends Data>(ref: DatabaseQuery<T>): Entries<T> | PromiseLike<Entries<T>>;
|
|
65
65
|
/**
|
|
66
66
|
* Subscribe to all matching documents.
|
|
67
67
|
* - `next()` is called once with the initial results, and again any time the results change.
|
|
@@ -71,7 +71,7 @@ export declare abstract class Provider {
|
|
|
71
71
|
*
|
|
72
72
|
* @return Function that ends the subscription.
|
|
73
73
|
*/
|
|
74
|
-
abstract subscribeQuery<T extends Data>(ref:
|
|
74
|
+
abstract subscribeQuery<T extends Data>(ref: DatabaseQuery<T>, observer: Observer<Entries<T>>): Unsubscriber;
|
|
75
75
|
/**
|
|
76
76
|
* Set the data of all matching documents.
|
|
77
77
|
*
|
|
@@ -79,7 +79,7 @@ export declare abstract class Provider {
|
|
|
79
79
|
* @param value Value to set the document to.
|
|
80
80
|
* @return Number of documents that were set.
|
|
81
81
|
*/
|
|
82
|
-
abstract setQuery<T extends Data>(ref:
|
|
82
|
+
abstract setQuery<T extends Data>(ref: DatabaseQuery<T>, data: T): number | PromiseLike<number>;
|
|
83
83
|
/**
|
|
84
84
|
* Update the data of all matching documents.
|
|
85
85
|
*
|
|
@@ -87,35 +87,35 @@ export declare abstract class Provider {
|
|
|
87
87
|
* @param updates Update instance to set the document to.
|
|
88
88
|
* @return Number of documents that were updated.
|
|
89
89
|
*/
|
|
90
|
-
abstract updateQuery<T extends Data>(ref:
|
|
90
|
+
abstract updateQuery<T extends Data>(ref: DatabaseQuery<T>, updates: Update<T>): number | PromiseLike<number>;
|
|
91
91
|
/**
|
|
92
92
|
* Delete all matching documents.
|
|
93
93
|
* @param ref Document reference specifying which document to delete.
|
|
94
94
|
* @return Number of documents that were deleted.
|
|
95
95
|
*/
|
|
96
|
-
abstract deleteQuery<T extends Data>(ref:
|
|
96
|
+
abstract deleteQuery<T extends Data>(ref: DatabaseQuery<T>): number | PromiseLike<number>;
|
|
97
97
|
}
|
|
98
98
|
/** Provider with a fully synchronous interface */
|
|
99
99
|
export interface SynchronousProvider extends Provider {
|
|
100
|
-
get<T extends Data>(ref:
|
|
101
|
-
add<T extends Data>(ref:
|
|
102
|
-
set<T extends Data>(ref:
|
|
103
|
-
update<T extends Data>(ref:
|
|
104
|
-
delete<T extends Data>(ref:
|
|
105
|
-
getQuery<T extends Data>(ref:
|
|
106
|
-
setQuery<T extends Data>(ref:
|
|
107
|
-
updateQuery<T extends Data>(ref:
|
|
108
|
-
deleteQuery<T extends Data>(ref:
|
|
100
|
+
get<T extends Data>(ref: DatabaseDocument<T>): Result<T>;
|
|
101
|
+
add<T extends Data>(ref: DatabaseQuery<T>, data: T): string;
|
|
102
|
+
set<T extends Data>(ref: DatabaseDocument<T>, value: T): void;
|
|
103
|
+
update<T extends Data>(ref: DatabaseDocument<T>, value: Update<T>): void;
|
|
104
|
+
delete<T extends Data>(ref: DatabaseDocument<T>): void;
|
|
105
|
+
getQuery<T extends Data>(ref: DatabaseQuery<T>): Entries<T>;
|
|
106
|
+
setQuery<T extends Data>(ref: DatabaseQuery<T>, value: T): number;
|
|
107
|
+
updateQuery<T extends Data>(ref: DatabaseQuery<T>, updates: Update<T>): number;
|
|
108
|
+
deleteQuery<T extends Data>(ref: DatabaseQuery<T>): number;
|
|
109
109
|
}
|
|
110
110
|
/** Provider with a fully asynchronous interface */
|
|
111
111
|
export interface AsynchronousProvider extends Provider {
|
|
112
|
-
get<T extends Data>(ref:
|
|
113
|
-
add<T extends Data>(ref:
|
|
114
|
-
set<T extends Data>(ref:
|
|
115
|
-
update<T extends Data>(ref:
|
|
116
|
-
delete<T extends Data>(ref:
|
|
117
|
-
getQuery<T extends Data>(ref:
|
|
118
|
-
setQuery<T extends Data>(ref:
|
|
119
|
-
updateQuery<T extends Data>(ref:
|
|
120
|
-
deleteQuery<T extends Data>(ref:
|
|
112
|
+
get<T extends Data>(ref: DatabaseDocument<T>): PromiseLike<Result<T>>;
|
|
113
|
+
add<T extends Data>(ref: DatabaseQuery<T>, data: T): PromiseLike<string>;
|
|
114
|
+
set<T extends Data>(ref: DatabaseDocument<T>, value: T): PromiseLike<void>;
|
|
115
|
+
update<T extends Data>(ref: DatabaseDocument<T>, updates: Update<T>): PromiseLike<void>;
|
|
116
|
+
delete<T extends Data>(ref: DatabaseDocument<T>): PromiseLike<void>;
|
|
117
|
+
getQuery<T extends Data>(ref: DatabaseQuery<T>): PromiseLike<Entries<T>>;
|
|
118
|
+
setQuery<T extends Data>(ref: DatabaseQuery<T>, value: T): PromiseLike<number>;
|
|
119
|
+
updateQuery<T extends Data>(ref: DatabaseQuery<T>, updates: Update<T>): PromiseLike<number>;
|
|
120
|
+
deleteQuery<T extends Data>(ref: DatabaseQuery<T>): PromiseLike<number>;
|
|
121
121
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Result, Entries, Unsubscriber, Observer, Class, Data } from "../util/index.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { DatabaseDocument, DatabaseQuery } from "../db/index.js";
|
|
3
3
|
import type { Update } from "../update/index.js";
|
|
4
4
|
import { Provider } from "./Provider.js";
|
|
5
5
|
/**
|
|
@@ -8,17 +8,17 @@ import { Provider } from "./Provider.js";
|
|
|
8
8
|
export declare class ThroughProvider extends Provider {
|
|
9
9
|
readonly source: Provider;
|
|
10
10
|
constructor(source: Provider);
|
|
11
|
-
get<T extends Data>(ref:
|
|
12
|
-
subscribe<T extends Data>(ref:
|
|
13
|
-
add<T extends Data>(ref:
|
|
14
|
-
set<T extends Data>(ref:
|
|
15
|
-
update<T extends Data>(ref:
|
|
16
|
-
delete<T extends Data>(ref:
|
|
17
|
-
getQuery<T extends Data>(ref:
|
|
18
|
-
subscribeQuery<T extends Data>(ref:
|
|
19
|
-
setQuery<T extends Data>(ref:
|
|
20
|
-
updateQuery<T extends Data>(ref:
|
|
21
|
-
deleteQuery<T extends Data>(ref:
|
|
11
|
+
get<T extends Data>(ref: DatabaseDocument<T>): Result<T> | PromiseLike<Result<T>>;
|
|
12
|
+
subscribe<T extends Data>(ref: DatabaseDocument<T>, observer: Observer<Result<T>>): Unsubscriber;
|
|
13
|
+
add<T extends Data>(ref: DatabaseQuery<T>, data: T): string | PromiseLike<string>;
|
|
14
|
+
set<T extends Data>(ref: DatabaseDocument<T>, data: T): void | PromiseLike<void>;
|
|
15
|
+
update<T extends Data>(ref: DatabaseDocument<T>, updates: Update<T>): void | PromiseLike<void>;
|
|
16
|
+
delete<T extends Data>(ref: DatabaseDocument<T>): void | PromiseLike<void>;
|
|
17
|
+
getQuery<T extends Data>(ref: DatabaseQuery<T>): Entries<T> | PromiseLike<Entries<T>>;
|
|
18
|
+
subscribeQuery<T extends Data>(ref: DatabaseQuery<T>, observer: Observer<Entries<T>>): Unsubscriber;
|
|
19
|
+
setQuery<T extends Data>(ref: DatabaseQuery<T>, data: T): number | PromiseLike<number>;
|
|
20
|
+
updateQuery<T extends Data>(ref: DatabaseQuery<T>, updates: Update<T>): number | PromiseLike<number>;
|
|
21
|
+
deleteQuery<T extends Data>(ref: DatabaseQuery<T>): number | PromiseLike<number>;
|
|
22
22
|
}
|
|
23
23
|
/** Find a specific source provider in a database's provider stack. */
|
|
24
24
|
export declare function findSourceProvider<P extends Provider>(provider: Provider, type: Class<P>): P;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DatabaseDocument, DatabaseQuery } from "../db/index.js";
|
|
2
2
|
import { Data, Result, Unsubscriber, Observer, Entries } from "../util/index.js";
|
|
3
3
|
import { Update } from "../update/index.js";
|
|
4
4
|
import { ThroughProvider } from "./ThroughProvider.js";
|
|
5
5
|
/** Validates any values that are read from or written to a source provider. */
|
|
6
6
|
export declare class ValidationProvider extends ThroughProvider {
|
|
7
|
-
get<T extends Data>(ref:
|
|
8
|
-
subscribe<T extends Data>(ref:
|
|
9
|
-
add<T extends Data>(ref:
|
|
10
|
-
set<T extends Data>(ref:
|
|
11
|
-
update<T extends Data>(ref:
|
|
12
|
-
getQuery<T extends Data>(ref:
|
|
13
|
-
subscribeQuery<T extends Data>(ref:
|
|
14
|
-
setQuery<T extends Data>(ref:
|
|
15
|
-
updateQuery<T extends Data>(ref:
|
|
7
|
+
get<T extends Data>(ref: DatabaseDocument<T>): Result<T> | PromiseLike<Result<T>>;
|
|
8
|
+
subscribe<T extends Data>(ref: DatabaseDocument<T>, observer: Observer<Result>): Unsubscriber;
|
|
9
|
+
add<T extends Data>(ref: DatabaseQuery<T>, data: T): string | PromiseLike<string>;
|
|
10
|
+
set<T extends Data>(ref: DatabaseDocument<T>, value: T): void | PromiseLike<void>;
|
|
11
|
+
update<T extends Data>(ref: DatabaseDocument<T>, updates: Update<T>): void | PromiseLike<void>;
|
|
12
|
+
getQuery<T extends Data>(ref: DatabaseQuery<T>): Entries<T> | PromiseLike<Entries<T>>;
|
|
13
|
+
subscribeQuery<T extends Data>(ref: DatabaseQuery<T>, observer: Observer<Entries<T>>): Unsubscriber;
|
|
14
|
+
setQuery<T extends Data>(ref: DatabaseQuery<T>, value: T): number | PromiseLike<number>;
|
|
15
|
+
updateQuery<T extends Data>(ref: DatabaseQuery<T>, updates: Update<T>): number | PromiseLike<number>;
|
|
16
16
|
}
|
package/react/useDocument.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DatabaseDocument, Result, Data } from "../index.js";
|
|
2
2
|
/**
|
|
3
3
|
* Use the cached result of a document in a React component (or a `Promise` to indicate the result is still loading).
|
|
4
4
|
* - Requires database to use `CacheProvider` and will error if this does not exist.
|
|
@@ -13,8 +13,8 @@ import { DataDocument, Result, Data } from "../index.js";
|
|
|
13
13
|
* @trhows `Error` if a `CacheProvider` is not part of the database's provider chain.
|
|
14
14
|
* @throws `Error` if there was a problem retrieving the result.
|
|
15
15
|
*/
|
|
16
|
-
export declare function useAsyncDocument<T extends Data>(ref:
|
|
17
|
-
export declare function useAsyncDocument<T extends Data>(ref:
|
|
16
|
+
export declare function useAsyncDocument<T extends Data>(ref: DatabaseDocument<T>, maxAge?: number | true): Result<T> | PromiseLike<Result<T>>;
|
|
17
|
+
export declare function useAsyncDocument<T extends Data>(ref: DatabaseDocument<T> | undefined, maxAge?: number | true): Result<T> | PromiseLike<Result<T>> | undefined;
|
|
18
18
|
/**
|
|
19
19
|
* Use the cached data of a document in a React component.
|
|
20
20
|
* - Requires database to use `CacheProvider` and will error if this does not exist.
|
|
@@ -30,11 +30,11 @@ export declare function useAsyncDocument<T extends Data>(ref: DataDocument<T> |
|
|
|
30
30
|
* @trhows `Error` if a `CacheProvider` is not part of the database's provider chain.
|
|
31
31
|
* @throws `Error` if there was a problem retrieving the result.
|
|
32
32
|
*/
|
|
33
|
-
export declare function useDocument<T extends Data>(ref:
|
|
34
|
-
export declare function useDocument<T extends Data>(ref:
|
|
33
|
+
export declare function useDocument<T extends Data>(ref: DatabaseDocument<T>, maxAge?: number | true): Result<T>;
|
|
34
|
+
export declare function useDocument<T extends Data>(ref: DatabaseDocument<T> | undefined, maxAge?: number | true): Result<T> | undefined;
|
|
35
35
|
/** Use the data of a document or `undefined` if the query has no matching results (or a promise indicating the result is loading). */
|
|
36
|
-
export declare function useAsyncDocumentData<T extends Data>(ref:
|
|
37
|
-
export declare function useAsyncDocumentData<T extends Data>(ref:
|
|
36
|
+
export declare function useAsyncDocumentData<T extends Data>(ref: DatabaseDocument<T>, maxAge?: number | true): T | PromiseLike<T>;
|
|
37
|
+
export declare function useAsyncDocumentData<T extends Data>(ref: DatabaseDocument<T> | undefined, maxAge?: number | true): T | PromiseLike<T> | undefined;
|
|
38
38
|
/** Use the data of a document or `undefined` if the query has no matching results. */
|
|
39
|
-
export declare function useDocumentData<T extends Data>(ref:
|
|
40
|
-
export declare function useDocumentData<T extends Data>(ref:
|
|
39
|
+
export declare function useDocumentData<T extends Data>(ref: DatabaseDocument<T>, maxAge?: number | true): T;
|
|
40
|
+
export declare function useDocumentData<T extends Data>(ref: DatabaseDocument<T> | undefined, maxAge?: number | true): T | undefined;
|
package/react/usePagination.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DatabaseQuery, Results, Pagination, Data } from "../index.js";
|
|
2
2
|
/**
|
|
3
3
|
* Use a `Pagination` for a collection.
|
|
4
4
|
* - Doesn't persist the state, so if the component or anything beneath it throws the currently paginated results will be lost.
|
|
5
5
|
*/
|
|
6
|
-
export declare function usePagination<T extends Data>(ref:
|
|
6
|
+
export declare function usePagination<T extends Data>(ref: DatabaseQuery<T>, initial?: Results<T>): Pagination<T>;
|
package/react/useQuery.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Results,
|
|
1
|
+
import { Results, DatabaseQuery, Data, Entry } from "../index.js";
|
|
2
2
|
/**
|
|
3
3
|
* Use the cached result of a document in a React component (or a `Promise` to indicate the result is still loading).
|
|
4
4
|
* - Requires database to use `CacheProvider` and will error if this does not exist.
|
|
@@ -14,8 +14,8 @@ import { Results, DataQuery, Data, Entry } from "../index.js";
|
|
|
14
14
|
* @trhows `Error` if a `CacheProvider` is not part of the database's provider chain.
|
|
15
15
|
* @throws `Error` if there was a problem retrieving the results.
|
|
16
16
|
*/
|
|
17
|
-
export declare function useAsyncQuery<T extends Data>(ref:
|
|
18
|
-
export declare function useAsyncQuery<T extends Data>(ref:
|
|
17
|
+
export declare function useAsyncQuery<T extends Data>(ref: DatabaseQuery<T>, maxAge?: number | true): Results<T> | PromiseLike<Results<T>>;
|
|
18
|
+
export declare function useAsyncQuery<T extends Data>(ref: DatabaseQuery<T> | undefined, maxAge?: number | true): Results<T> | PromiseLike<Results<T>> | undefined;
|
|
19
19
|
/**
|
|
20
20
|
* Use the cached results of a set of documents in a React component.
|
|
21
21
|
* - Requires database to use `CacheProvider` and will error if this does not exist.
|
|
@@ -31,17 +31,17 @@ export declare function useAsyncQuery<T extends Data>(ref: DataQuery<T> | undefi
|
|
|
31
31
|
* @trhows `Error` if a `CacheProvider` is not part of the database's provider chain.
|
|
32
32
|
* @throws `Error` if there was a problem retrieving the results.
|
|
33
33
|
*/
|
|
34
|
-
export declare function useQuery<T extends Data>(ref:
|
|
35
|
-
export declare function useQuery<T extends Data>(ref:
|
|
34
|
+
export declare function useQuery<T extends Data>(ref: DatabaseQuery<T>, maxAge?: number | true): Results<T>;
|
|
35
|
+
export declare function useQuery<T extends Data>(ref: DatabaseQuery<T> | undefined, maxAge?: number | true): Results<T> | undefined;
|
|
36
36
|
/** Use the first result of a query or `undefined` if the query has no matching results (or a promise indicating the result is loading). */
|
|
37
|
-
export declare function useAsyncQueryResult<T extends Data>(ref:
|
|
38
|
-
export declare function useAsyncQueryResult<T extends Data>(ref:
|
|
37
|
+
export declare function useAsyncQueryResult<T extends Data>(ref: DatabaseQuery<T>, maxAge?: number | true): Entry<T> | undefined | PromiseLike<Entry<T> | undefined>;
|
|
38
|
+
export declare function useAsyncQueryResult<T extends Data>(ref: DatabaseQuery<T> | undefined, maxAge?: number | true): Entry<T> | undefined | PromiseLike<Entry<T> | undefined>;
|
|
39
39
|
/** Use the first result of a query or `undefined` if the query has no matching results */
|
|
40
|
-
export declare function useQueryResult<T extends Data>(ref:
|
|
41
|
-
export declare function useQueryResult<T extends Data>(ref:
|
|
40
|
+
export declare function useQueryResult<T extends Data>(ref: DatabaseQuery<T>, maxAge?: number | true): Entry<T> | undefined;
|
|
41
|
+
export declare function useQueryResult<T extends Data>(ref: DatabaseQuery<T> | undefined, maxAge?: number | true): Entry<T> | undefined;
|
|
42
42
|
/** Use the first result of a query (or a promise indicating the result is loading). */
|
|
43
|
-
export declare function useAsyncQueryData<T extends Data>(ref:
|
|
44
|
-
export declare function useAsyncQueryData<T extends Data>(ref:
|
|
43
|
+
export declare function useAsyncQueryData<T extends Data>(ref: DatabaseQuery<T>, maxAge?: number | true): Entry<T> | PromiseLike<Entry<T>>;
|
|
44
|
+
export declare function useAsyncQueryData<T extends Data>(ref: DatabaseQuery<T> | undefined, maxAge?: number | true): Entry<T> | PromiseLike<Entry<T>> | undefined;
|
|
45
45
|
/** Use the first result of a query. */
|
|
46
|
-
export declare function useQueryData<T extends Data>(ref:
|
|
47
|
-
export declare function useQueryData<T extends Data>(ref:
|
|
46
|
+
export declare function useQueryData<T extends Data>(ref: DatabaseQuery<T>, maxAge?: number | true): Entry<T>;
|
|
47
|
+
export declare function useQueryData<T extends Data>(ref: DatabaseQuery<T> | undefined, maxAge?: number | true): Entry<T> | undefined;
|
package/update/DataUpdate.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Data, Prop, Key, Transformable } from "../util/index.js";
|
|
1
|
+
import { Data, Prop, Key, Transformable, Nullish } from "../util/index.js";
|
|
2
2
|
import { Update } from "./Update.js";
|
|
3
3
|
/**
|
|
4
4
|
* Set of named transforms for the props of a data object.
|
|
@@ -12,11 +12,11 @@ export declare type PropUpdates<T extends Data> = {
|
|
|
12
12
|
};
|
|
13
13
|
/** Update that can be applied to a data object to update its props. */
|
|
14
14
|
export declare class DataUpdate<T extends Data> extends Update<T> implements Iterable<Prop<PropUpdates<T>>>, Transformable<T, T> {
|
|
15
|
-
readonly
|
|
15
|
+
readonly updates: PropUpdates<T>;
|
|
16
16
|
constructor(props: PropUpdates<T>);
|
|
17
17
|
transform(existing: T): T;
|
|
18
18
|
/** Return a new object with the specified additional transform for a prop. */
|
|
19
|
-
|
|
19
|
+
update<K extends Key<T>>(key: Nullish<K>, value: T[K] | Update<T[K]>): this;
|
|
20
20
|
/** Iterate over the transforms in this object. */
|
|
21
21
|
[Symbol.iterator](): Iterator<Prop<PropUpdates<T>>, void>;
|
|
22
22
|
}
|
package/update/DataUpdate.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { transformProps } from "../util/index.js";
|
|
1
|
+
import { transformProps, isNullish } from "../util/index.js";
|
|
2
2
|
import { Update } from "./Update.js";
|
|
3
3
|
/** Update that can be applied to a data object to update its props. */
|
|
4
4
|
export class DataUpdate extends Update {
|
|
5
5
|
constructor(props) {
|
|
6
6
|
super();
|
|
7
|
-
this.
|
|
7
|
+
this.updates = props;
|
|
8
8
|
}
|
|
9
9
|
transform(existing) {
|
|
10
|
-
return transformProps(existing, this.
|
|
10
|
+
return transformProps(existing, this.updates);
|
|
11
11
|
}
|
|
12
12
|
/** Return a new object with the specified additional transform for a prop. */
|
|
13
|
-
|
|
14
|
-
if (key
|
|
13
|
+
update(key, value) {
|
|
14
|
+
if (isNullish(key))
|
|
15
15
|
return this;
|
|
16
|
-
return { __proto__: Object.getPrototypeOf(this), ...this,
|
|
16
|
+
return { __proto__: Object.getPrototypeOf(this), ...this, updates: { ...this.updates, [key]: value } };
|
|
17
17
|
}
|
|
18
18
|
/** Iterate over the transforms in this object. */
|
|
19
19
|
[Symbol.iterator]() {
|
|
20
|
-
return Object.entries(this.
|
|
20
|
+
return Object.entries(this.updates).values();
|
|
21
21
|
}
|
|
22
22
|
}
|
package/update/ObjectUpdate.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Entry, ImmutableArray, ImmutableObject } from "../util/index.js";
|
|
1
|
+
import { Entry, ImmutableArray, ImmutableObject, Nullish } from "../util/index.js";
|
|
2
2
|
import { Update } from "./Update.js";
|
|
3
3
|
/** Set of named transforms for the entries of a map-like object. */
|
|
4
4
|
export declare type EntryUpdates<T> = ImmutableObject<T | Update<T>>;
|
|
@@ -13,9 +13,9 @@ export declare class ObjectUpdate<T> extends Update<ImmutableObject<T>> implemen
|
|
|
13
13
|
constructor(updates?: EntryUpdates<T>, deletes?: ImmutableArray<string>);
|
|
14
14
|
transform(existing: unknown): ImmutableObject<T>;
|
|
15
15
|
/** Return an object update with a specific entry marked for update. */
|
|
16
|
-
update(key: string
|
|
16
|
+
update(key: Nullish<string>, value: T | Update<T>): this;
|
|
17
17
|
/** Return an object update with a specific entry marked for deletion. */
|
|
18
|
-
delete(key: string
|
|
18
|
+
delete(key: Nullish<string>): this;
|
|
19
19
|
/**
|
|
20
20
|
* Iterate over the changes in this object.
|
|
21
21
|
* - Updates are yielded first, then deletes.
|
package/update/ObjectUpdate.js
CHANGED
|
@@ -21,13 +21,13 @@ export class ObjectUpdate extends Update {
|
|
|
21
21
|
}
|
|
22
22
|
/** Return an object update with a specific entry marked for update. */
|
|
23
23
|
update(key, value) {
|
|
24
|
-
if (key
|
|
24
|
+
if (isNullish(key))
|
|
25
25
|
return this;
|
|
26
26
|
return { __proto__: Object.getPrototypeOf(this), ...this, sets: { ...this.updates, [key]: value } };
|
|
27
27
|
}
|
|
28
28
|
/** Return an object update with a specific entry marked for deletion. */
|
|
29
29
|
delete(key) {
|
|
30
|
-
if (key
|
|
30
|
+
if (isNullish(key))
|
|
31
31
|
return this;
|
|
32
32
|
return { __proto__: Object.getPrototypeOf(this), ...this, deletes: [...this.deletes, key] };
|
|
33
33
|
}
|
package/update/Update.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Transformable } from "../util/index.js";
|
|
2
2
|
/**
|
|
3
|
-
* An object that represents an update of an existing value
|
|
3
|
+
* An object that represents an update of an existing value.
|
|
4
4
|
* - Implements `Transformable` for applying that update with its `transform()` method.
|
|
5
5
|
*/
|
|
6
6
|
export declare abstract class Update<T> implements Transformable<T, T> {
|
package/update/Update.js
CHANGED
package/update/util.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { DataSchema } from "../schema/DataSchema.js";
|
|
2
|
-
import { Validator,
|
|
3
|
-
import { DataUpdate, Update
|
|
2
|
+
import { Validator, Data } from "../util/index.js";
|
|
3
|
+
import { DataUpdate, Update } from "./index.js";
|
|
4
4
|
/** Validate an update against a validator. */
|
|
5
5
|
export declare function validateUpdate<T>(unsafeUpdate: Update<T> | DataUpdate<T & Data>, validator: Validator<T> | DataSchema<T & Data>): Update<T>;
|
|
6
|
-
/** Validate a set of transforms against a set of validators. */
|
|
7
|
-
export declare function validateUpdates<T extends Data>(unsafeUpdates: PropUpdates<T>, validators: Validators<T>): PropUpdates<T>;
|
package/update/util.js
CHANGED
|
@@ -6,8 +6,8 @@ import { DataUpdate, Update } from "./index.js";
|
|
|
6
6
|
/** Validate an update against a validator. */
|
|
7
7
|
export function validateUpdate(unsafeUpdate, validator) {
|
|
8
8
|
if (validator instanceof DataSchema && unsafeUpdate instanceof DataUpdate) {
|
|
9
|
-
const unsafeUpdates = unsafeUpdate.
|
|
10
|
-
const safeUpdates =
|
|
9
|
+
const unsafeUpdates = unsafeUpdate.updates;
|
|
10
|
+
const safeUpdates = validatePropUpdates(unsafeUpdates, validator.props);
|
|
11
11
|
return safeUpdates === unsafeUpdates ? unsafeUpdate : new DataUpdate(safeUpdates);
|
|
12
12
|
}
|
|
13
13
|
else {
|
|
@@ -16,7 +16,7 @@ export function validateUpdate(unsafeUpdate, validator) {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
/** Validate a set of transforms against a set of validators. */
|
|
19
|
-
|
|
19
|
+
function validatePropUpdates(unsafeUpdates, validators) {
|
|
20
20
|
let invalid = false;
|
|
21
21
|
const safeUpdates = {};
|
|
22
22
|
const details = {};
|