shelving 1.21.0 → 1.23.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/api/Resource.d.ts +13 -7
- package/api/Resource.js +9 -9
- package/db/Database.d.ts +20 -46
- package/db/Database.js +31 -49
- package/db/Pagination.js +1 -1
- package/db/Write.d.ts +28 -0
- package/db/Write.js +32 -0
- package/db/index.d.ts +1 -1
- package/db/index.js +1 -1
- package/feedback/index.d.ts +0 -1
- package/feedback/index.js +0 -1
- package/firestore/client/FirestoreClientProvider.d.ts +3 -3
- package/firestore/client/FirestoreClientProvider.js +2 -2
- package/firestore/lite/FirestoreLiteProvider.d.ts +3 -3
- package/firestore/server/FirestoreServerProvider.d.ts +3 -3
- package/firestore/server/FirestoreServerProvider.js +2 -2
- package/package.json +1 -1
- package/provider/BatchProvider.js +2 -2
- package/provider/CacheProvider.js +3 -3
- package/provider/MemoryProvider.js +20 -20
- package/provider/ValidationProvider.js +2 -3
- package/query/Filter.d.ts +1 -1
- package/query/Filter.js +1 -1
- package/query/Filters.d.ts +1 -1
- package/query/Filters.js +1 -1
- package/query/Query.d.ts +1 -1
- package/query/Query.js +2 -2
- package/query/Rule.d.ts +3 -3
- package/query/Sort.d.ts +1 -1
- package/query/Sort.js +1 -1
- package/query/Sorts.d.ts +1 -1
- package/query/Sorts.js +1 -1
- package/react/useDocument.js +3 -3
- package/react/useFetch.js +2 -2
- package/react/usePureState.d.ts +4 -4
- package/react/useQuery.js +4 -4
- package/react/useSubscribe.js +1 -1
- package/stream/DataState.d.ts +2 -2
- package/stream/DataState.js +2 -2
- package/stream/LastStream.js +1 -1
- package/stream/LazyState.d.ts +1 -1
- package/stream/LazyState.js +4 -4
- package/stream/LazyStream.d.ts +1 -1
- package/stream/LazyStream.js +5 -5
- package/stream/State.d.ts +5 -5
- package/stream/State.js +6 -6
- package/stream/Stream.d.ts +13 -13
- package/stream/Stream.js +25 -25
- package/transform/AddEntriesTransform.d.ts +1 -1
- package/transform/AddEntriesTransform.js +1 -1
- package/transform/AddItemsTransform.d.ts +1 -1
- package/transform/AddItemsTransform.js +1 -1
- package/transform/DataTransform.d.ts +1 -1
- package/transform/DataTransform.js +3 -3
- package/transform/IncrementTransform.d.ts +1 -1
- package/transform/IncrementTransform.js +1 -1
- package/transform/RemoveEntriesTransform.d.ts +1 -1
- package/transform/RemoveEntriesTransform.js +1 -1
- package/transform/RemoveItemsTransform.d.ts +1 -1
- package/transform/RemoveItemsTransform.js +1 -1
- package/transform/Transform.d.ts +3 -3
- package/transform/hydrations.d.ts +1 -1
- package/transform/hydrations.js +1 -1
- package/transform/util.js +2 -2
- package/util/async.d.ts +6 -6
- package/util/clone.js +3 -3
- package/util/error.js +1 -1
- package/util/filter.d.ts +4 -4
- package/util/filter.js +5 -5
- package/util/function.d.ts +8 -0
- package/util/function.js +19 -0
- package/util/hydrate.d.ts +7 -7
- package/util/hydrate.js +13 -13
- package/util/index.d.ts +2 -3
- package/util/index.js +2 -3
- package/util/observable.d.ts +15 -19
- package/util/observable.js +22 -28
- package/util/sort.d.ts +4 -4
- package/util/sort.js +5 -6
- package/util/transform.d.ts +88 -0
- package/util/transform.js +48 -0
- package/db/Change.d.ts +0 -37
- package/db/Change.js +0 -60
- package/feedback/util.d.ts +0 -3
- package/feedback/util.js +0 -7
- package/util/derive.d.ts +0 -88
- package/util/derive.js +0 -48
- package/util/dispatch.d.ts +0 -29
- package/util/dispatch.js +0 -43
package/api/Resource.d.ts
CHANGED
|
@@ -6,24 +6,22 @@ import { Validator, Validatable } from "../util/index.js";
|
|
|
6
6
|
* @param returns The `Validator` the function's returned value must conform to (defaults to `undefined` if not specified).
|
|
7
7
|
*/
|
|
8
8
|
export declare class Resource<P = unknown, R = void> implements Validatable<R> {
|
|
9
|
-
static create<X, Y>(payload: Validator<X>, result: Validator<Y>): Resource<X, Y>;
|
|
10
|
-
static create<Y>(payload: undefined, result: Y): Resource<undefined, Y>;
|
|
11
|
-
static create<X>(payload: Validator<X>, result?: undefined): Resource<X, void>;
|
|
12
|
-
static create(payload?: undefined, result?: undefined): Resource<undefined, void>;
|
|
13
9
|
/** Payload validator. */
|
|
14
10
|
readonly payload: Validator<P>;
|
|
15
11
|
/** Result validator. */
|
|
16
12
|
readonly result: Validator<R>;
|
|
17
|
-
|
|
13
|
+
constructor(payload: Validator<P>, result: Validator<R>);
|
|
18
14
|
/**
|
|
19
15
|
* Validate a payload for this resource.
|
|
20
16
|
*
|
|
17
|
+
* @returns The validated payload for this resource.
|
|
18
|
+
* @throws InvalidFeedback if the payload could not be validated.
|
|
21
19
|
*/
|
|
22
|
-
|
|
20
|
+
prepare(unsafePayload: unknown): P;
|
|
23
21
|
/**
|
|
24
22
|
* Validate a result for this resource.
|
|
25
23
|
*
|
|
26
|
-
* @returns The validated
|
|
24
|
+
* @returns The validated result for this resource.
|
|
27
25
|
* @throws ValidationError if the result could not be validated.
|
|
28
26
|
*/
|
|
29
27
|
validate(unsafeResult: unknown): R;
|
|
@@ -32,3 +30,11 @@ export declare class Resource<P = unknown, R = void> implements Validatable<R> {
|
|
|
32
30
|
export declare type PayloadType<X extends Resource> = X extends Resource<infer Y, unknown> ? Y : never;
|
|
33
31
|
/** Extract the result type from a `Resource`. */
|
|
34
32
|
export declare type ResourceType<X extends Resource> = X extends Resource<unknown, infer Y> ? Y : never;
|
|
33
|
+
/**
|
|
34
|
+
* Shortcut to create a new `Resource` (consistent with `Schema` shortcuts.
|
|
35
|
+
* - Sets `undefined` as the default type for payload and result.
|
|
36
|
+
*/
|
|
37
|
+
export declare function RESOURCE<X, Y>(payload: Validator<X>, result: Validator<Y>): Resource<X, Y>;
|
|
38
|
+
export declare function RESOURCE<Y>(payload: undefined, result: Y): Resource<undefined, Y>;
|
|
39
|
+
export declare function RESOURCE<X>(payload: Validator<X>, result?: undefined): Resource<X, void>;
|
|
40
|
+
export declare function RESOURCE(payload?: undefined, result?: undefined): Resource<undefined, void>;
|
package/api/Resource.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { UNDEFINED, validate } from "../util/index.js";
|
|
2
|
-
import { Feedback
|
|
2
|
+
import { Feedback } from "../feedback/index.js";
|
|
3
3
|
import { ResourceValidationError } from "./errors.js";
|
|
4
|
-
/** Validator that always returns void/undefined. */
|
|
5
|
-
const UNDEFINED_VALIDATOR = UNDEFINED;
|
|
6
4
|
/**
|
|
7
5
|
* An abstract API resource definition, used to specify types for e.g. serverless functions..
|
|
8
6
|
*
|
|
@@ -15,20 +13,19 @@ export class Resource {
|
|
|
15
13
|
this.payload = payload;
|
|
16
14
|
this.result = result;
|
|
17
15
|
}
|
|
18
|
-
static create(payload = UNDEFINED_VALIDATOR, result = UNDEFINED_VALIDATOR) {
|
|
19
|
-
return new Resource(payload, result);
|
|
20
|
-
}
|
|
21
16
|
/**
|
|
22
17
|
* Validate a payload for this resource.
|
|
23
18
|
*
|
|
19
|
+
* @returns The validated payload for this resource.
|
|
20
|
+
* @throws InvalidFeedback if the payload could not be validated.
|
|
24
21
|
*/
|
|
25
|
-
|
|
26
|
-
return
|
|
22
|
+
prepare(unsafePayload) {
|
|
23
|
+
return validate(unsafePayload, this.payload);
|
|
27
24
|
}
|
|
28
25
|
/**
|
|
29
26
|
* Validate a result for this resource.
|
|
30
27
|
*
|
|
31
|
-
* @returns The validated
|
|
28
|
+
* @returns The validated result for this resource.
|
|
32
29
|
* @throws ValidationError if the result could not be validated.
|
|
33
30
|
*/
|
|
34
31
|
validate(unsafeResult) {
|
|
@@ -40,3 +37,6 @@ export class Resource {
|
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
39
|
}
|
|
40
|
+
export function RESOURCE(payload = UNDEFINED, result = UNDEFINED) {
|
|
41
|
+
return new Resource(payload, result);
|
|
42
|
+
}
|
package/db/Database.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Entry, Observable, Observer, Result, Unsubscriber, ResultsMap, Validatable, Validator, Key, Data, Results, Datas, Validators, ValidatorType, Dispatcher } from "../util/index.js";
|
|
2
2
|
import { Transform, Transforms } from "../transform/index.js";
|
|
3
3
|
import type { Provider } from "../provider/Provider.js";
|
|
4
4
|
import { Filters, Sorts, Query } from "../query/index.js";
|
|
5
|
+
import { Write } from "./Write.js";
|
|
5
6
|
/**
|
|
6
7
|
* Combines a database model and a provider.
|
|
7
8
|
*
|
|
@@ -58,26 +59,18 @@ export declare class DataQuery<T extends Data = Data> extends Query<T> implement
|
|
|
58
59
|
* Subscribe to all matching documents.
|
|
59
60
|
* - `next()` is called once with the initial results, and again any time the results change.
|
|
60
61
|
*
|
|
61
|
-
* @param
|
|
62
|
-
* @param next Callback that is called once initially and again whenever the results change.
|
|
63
|
-
* @param error Callback that is called if an error occurs.
|
|
64
|
-
* @param complete Callback that is called when the subscription is done.
|
|
65
|
-
*
|
|
62
|
+
* @param next Observer with `next`, `error`, or `complete` methods or a `next()` dispatcher.
|
|
66
63
|
* @return Function that ends the subscription.
|
|
67
64
|
*/
|
|
68
|
-
subscribe(next: Observer<Results<T>> | Dispatcher<Results<T
|
|
65
|
+
subscribe(next: Observer<Results<T>> | Dispatcher<[Results<T>]>): Unsubscriber;
|
|
69
66
|
/**
|
|
70
67
|
* Subscribe to all matching documents.
|
|
71
68
|
* - `next()` is called once with the initial results, and again any time the results change.
|
|
72
69
|
*
|
|
73
|
-
* @param
|
|
74
|
-
* @param next Callback that is called once initially and again whenever the results change.
|
|
75
|
-
* @param error Callback that is called if an error occurs.
|
|
76
|
-
* @param complete Callback that is called when the subscription is done.
|
|
77
|
-
*
|
|
70
|
+
* @param next Observer with `next`, `error`, or `complete` methods or a `next()` dispatcher.
|
|
78
71
|
* @return Function that ends the subscription.
|
|
79
72
|
*/
|
|
80
|
-
subscribeMap(next: Observer<ResultsMap<T>> | Dispatcher<ResultsMap<T
|
|
73
|
+
subscribeMap(next: Observer<ResultsMap<T>> | Dispatcher<[ResultsMap<T>]>): Unsubscriber;
|
|
81
74
|
/**
|
|
82
75
|
* Set all matching documents to the same exact value.
|
|
83
76
|
*
|
|
@@ -145,45 +138,26 @@ export declare class DataDocument<T extends Data = Data> implements Observable<R
|
|
|
145
138
|
* Subscribe to the result of this document (indefinitely).
|
|
146
139
|
* - `next()` is called once with the initial result, and again any time the result changes.
|
|
147
140
|
*
|
|
148
|
-
* @param
|
|
149
|
-
* @param next Callback that is called once initially and again whenever the result changes.
|
|
150
|
-
* @param error Callback that is called if an error occurs.
|
|
151
|
-
* @param complete Callback that is called when the subscription is done.
|
|
152
|
-
*
|
|
141
|
+
* @param next Observer with `next`, `error`, or `complete` methods or a `next()` dispatcher.
|
|
153
142
|
* @return Function that ends the subscription.
|
|
154
143
|
*/
|
|
155
|
-
subscribe(next: Observer<Result<T>> | Dispatcher<Result<T
|
|
156
|
-
/**
|
|
157
|
-
* Set the complete data of this document.
|
|
158
|
-
*
|
|
159
|
-
* @param data Complete data to set the document to.
|
|
160
|
-
*
|
|
161
|
-
* @return Nothing (possibly promised).
|
|
162
|
-
*/
|
|
144
|
+
subscribe(next: Observer<Result<T>> | Dispatcher<[Result<T>]>): Unsubscriber;
|
|
145
|
+
/** Set the complete data of this document. */
|
|
163
146
|
set(data: T): void | PromiseLike<void>;
|
|
164
|
-
/**
|
|
165
|
-
* Update this document with partial data.
|
|
166
|
-
* - If the document exists, merge the partial data into it.
|
|
167
|
-
* - If the document doesn't exist, throw an error.
|
|
168
|
-
*
|
|
169
|
-
* @param transforms `Transform` instance or set of transforms to apply to the existing document.
|
|
170
|
-
* - Not all transforms may be supported by all providers.
|
|
171
|
-
*
|
|
172
|
-
* @return Nothing (possibly promised).
|
|
173
|
-
* @throws Error If the document does not exist (ideally a `RequiredError` but may be provider-specific).
|
|
174
|
-
*/
|
|
147
|
+
/** Update this document. */
|
|
175
148
|
update(transforms: Transform<T> | Transforms<T>): void | PromiseLike<void>;
|
|
176
|
-
/**
|
|
177
|
-
* Delete this document.
|
|
178
|
-
* - Will not throw an error if the document doesn't exist.
|
|
179
|
-
*
|
|
180
|
-
* @return Nothing (possibly promised).
|
|
181
|
-
*/
|
|
149
|
+
/** Delete this document. */
|
|
182
150
|
delete(): void | PromiseLike<void>;
|
|
183
|
-
/**
|
|
184
|
-
* Combine `set()`, `update()`, `delete()` into a single method.
|
|
185
|
-
*/
|
|
151
|
+
/** Set, update, or delete this document. */
|
|
186
152
|
write(value: Result<T> | Transform<T>): void | PromiseLike<void>;
|
|
153
|
+
/** Represent a write that sets the complete data of this document in a database. */
|
|
154
|
+
setter(data: T): Write<T>;
|
|
155
|
+
/** Represent a write that updates this document in a database. */
|
|
156
|
+
updater(transforms: Transform<T> | Transforms<T>): Write<T>;
|
|
157
|
+
/** Represent a write that deletes this document in a database. */
|
|
158
|
+
deleter(): Write<T>;
|
|
159
|
+
/** Represent a write that sets, updates, or deletes this document in a database. */
|
|
160
|
+
writer(value: Result<T> | Transform<T>): Write<T>;
|
|
187
161
|
/** Validate data for this query reference. */
|
|
188
162
|
validate(unsafeData: Data): T;
|
|
189
163
|
toString(): string;
|
package/db/Database.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { callAsync,
|
|
1
|
+
import { callAsync, getFirstItem, throwAsync, validate, toMap, countItems, TransformObserver, } from "../util/index.js";
|
|
2
2
|
import { DataTransform, Transform } from "../transform/index.js";
|
|
3
3
|
import { Feedback, InvalidFeedback } from "../feedback/index.js";
|
|
4
4
|
import { Filters, Query, EqualFilter } from "../query/index.js";
|
|
5
5
|
import { DocumentRequiredError, DocumentValidationError, QueryValidationError } from "./errors.js";
|
|
6
|
+
import { Write } from "./Write.js";
|
|
6
7
|
/**
|
|
7
8
|
* Combines a database model and a provider.
|
|
8
9
|
*
|
|
@@ -79,29 +80,21 @@ export class DataQuery extends Query {
|
|
|
79
80
|
* Subscribe to all matching documents.
|
|
80
81
|
* - `next()` is called once with the initial results, and again any time the results change.
|
|
81
82
|
*
|
|
82
|
-
* @param
|
|
83
|
-
* @param next Callback that is called once initially and again whenever the results change.
|
|
84
|
-
* @param error Callback that is called if an error occurs.
|
|
85
|
-
* @param complete Callback that is called when the subscription is done.
|
|
86
|
-
*
|
|
83
|
+
* @param next Observer with `next`, `error`, or `complete` methods or a `next()` dispatcher.
|
|
87
84
|
* @return Function that ends the subscription.
|
|
88
85
|
*/
|
|
89
|
-
subscribe(next
|
|
90
|
-
return this.provider.subscribeQuery(this,
|
|
86
|
+
subscribe(next) {
|
|
87
|
+
return this.provider.subscribeQuery(this, typeof next === "function" ? { next } : next);
|
|
91
88
|
}
|
|
92
89
|
/**
|
|
93
90
|
* Subscribe to all matching documents.
|
|
94
91
|
* - `next()` is called once with the initial results, and again any time the results change.
|
|
95
92
|
*
|
|
96
|
-
* @param
|
|
97
|
-
* @param next Callback that is called once initially and again whenever the results change.
|
|
98
|
-
* @param error Callback that is called if an error occurs.
|
|
99
|
-
* @param complete Callback that is called when the subscription is done.
|
|
100
|
-
*
|
|
93
|
+
* @param next Observer with `next`, `error`, or `complete` methods or a `next()` dispatcher.
|
|
101
94
|
* @return Function that ends the subscription.
|
|
102
95
|
*/
|
|
103
|
-
subscribeMap(next
|
|
104
|
-
return this.provider.subscribeQuery(this, new
|
|
96
|
+
subscribeMap(next) {
|
|
97
|
+
return this.provider.subscribeQuery(this, new TransformObserver(toMap, typeof next === "function" ? { next } : next));
|
|
105
98
|
}
|
|
106
99
|
/**
|
|
107
100
|
* Set all matching documents to the same exact value.
|
|
@@ -210,55 +203,44 @@ export class DataDocument {
|
|
|
210
203
|
* Subscribe to the result of this document (indefinitely).
|
|
211
204
|
* - `next()` is called once with the initial result, and again any time the result changes.
|
|
212
205
|
*
|
|
213
|
-
* @param
|
|
214
|
-
* @param next Callback that is called once initially and again whenever the result changes.
|
|
215
|
-
* @param error Callback that is called if an error occurs.
|
|
216
|
-
* @param complete Callback that is called when the subscription is done.
|
|
217
|
-
*
|
|
206
|
+
* @param next Observer with `next`, `error`, or `complete` methods or a `next()` dispatcher.
|
|
218
207
|
* @return Function that ends the subscription.
|
|
219
208
|
*/
|
|
220
|
-
subscribe(next
|
|
221
|
-
return this.provider.subscribe(this,
|
|
209
|
+
subscribe(next) {
|
|
210
|
+
return this.provider.subscribe(this, typeof next === "function" ? { next } : next);
|
|
222
211
|
}
|
|
223
|
-
/**
|
|
224
|
-
* Set the complete data of this document.
|
|
225
|
-
*
|
|
226
|
-
* @param data Complete data to set the document to.
|
|
227
|
-
*
|
|
228
|
-
* @return Nothing (possibly promised).
|
|
229
|
-
*/
|
|
212
|
+
/** Set the complete data of this document. */
|
|
230
213
|
set(data) {
|
|
231
214
|
return this.write(data);
|
|
232
215
|
}
|
|
233
|
-
/**
|
|
234
|
-
* Update this document with partial data.
|
|
235
|
-
* - If the document exists, merge the partial data into it.
|
|
236
|
-
* - If the document doesn't exist, throw an error.
|
|
237
|
-
*
|
|
238
|
-
* @param transforms `Transform` instance or set of transforms to apply to the existing document.
|
|
239
|
-
* - Not all transforms may be supported by all providers.
|
|
240
|
-
*
|
|
241
|
-
* @return Nothing (possibly promised).
|
|
242
|
-
* @throws Error If the document does not exist (ideally a `RequiredError` but may be provider-specific).
|
|
243
|
-
*/
|
|
216
|
+
/** Update this document. */
|
|
244
217
|
update(transforms) {
|
|
245
218
|
return this.write(transforms instanceof Transform ? transforms : new DataTransform(transforms));
|
|
246
219
|
}
|
|
247
|
-
/**
|
|
248
|
-
* Delete this document.
|
|
249
|
-
* - Will not throw an error if the document doesn't exist.
|
|
250
|
-
*
|
|
251
|
-
* @return Nothing (possibly promised).
|
|
252
|
-
*/
|
|
220
|
+
/** Delete this document. */
|
|
253
221
|
delete() {
|
|
254
222
|
return this.write(undefined);
|
|
255
223
|
}
|
|
256
|
-
/**
|
|
257
|
-
* Combine `set()`, `update()`, `delete()` into a single method.
|
|
258
|
-
*/
|
|
224
|
+
/** Set, update, or delete this document. */
|
|
259
225
|
write(value) {
|
|
260
226
|
return this.provider.write(this, value);
|
|
261
227
|
}
|
|
228
|
+
/** Represent a write that sets the complete data of this document in a database. */
|
|
229
|
+
setter(data) {
|
|
230
|
+
return this.writer(data);
|
|
231
|
+
}
|
|
232
|
+
/** Represent a write that updates this document in a database. */
|
|
233
|
+
updater(transforms) {
|
|
234
|
+
return this.writer(transforms instanceof Transform ? transforms : new DataTransform(transforms));
|
|
235
|
+
}
|
|
236
|
+
/** Represent a write that deletes this document in a database. */
|
|
237
|
+
deleter() {
|
|
238
|
+
return this.writer(undefined);
|
|
239
|
+
}
|
|
240
|
+
/** Represent a write that sets, updates, or deletes this document in a database. */
|
|
241
|
+
writer(value) {
|
|
242
|
+
return new Write(this, value);
|
|
243
|
+
}
|
|
262
244
|
/** Validate data for this query reference. */
|
|
263
245
|
validate(unsafeData) {
|
|
264
246
|
try {
|
package/db/Pagination.js
CHANGED
|
@@ -71,7 +71,7 @@ export class Pagination extends State {
|
|
|
71
71
|
* @return The change in the number of results.
|
|
72
72
|
*/
|
|
73
73
|
merge(more) {
|
|
74
|
-
this.next(toMap(this.ref.sorts.
|
|
74
|
+
this.next(toMap(this.ref.sorts.transform(yieldMerged(more, this.value))));
|
|
75
75
|
}
|
|
76
76
|
/** Iterate over the entries of the values currently in the pagination. */
|
|
77
77
|
[Symbol.iterator]() {
|
package/db/Write.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Transform } from "../transform/index.js";
|
|
2
|
+
import { ImmutableArray, Data, Transformable } from "../util/index.js";
|
|
3
|
+
import type { Database, DataDocument } from "./Database.js";
|
|
4
|
+
/** Change transformable. */
|
|
5
|
+
export declare type DatabaseTransformable = Transformable<Database, void | PromiseLike<void>>;
|
|
6
|
+
/** Represent a write made to a single document in a database. */
|
|
7
|
+
export declare class Write<T extends Data> implements Transformable<Database, void | PromiseLike<void>> {
|
|
8
|
+
readonly collection: string;
|
|
9
|
+
readonly id: string;
|
|
10
|
+
readonly value: Data | Transform<Data> | undefined;
|
|
11
|
+
constructor({ collection, id }: DataDocument<T>, value: T | Transform<T> | undefined);
|
|
12
|
+
transform(db: Database): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Represent a list of writes made to a set of documents in a database.
|
|
16
|
+
* - Sets of writes are predictable and repeatable, so unpredictable operations like `create()` and query operations are not supported.
|
|
17
|
+
* - Every write must be applied to a specific database document in a specific collection and are applied in the specified order.
|
|
18
|
+
*/
|
|
19
|
+
export declare class Writes implements Transformable<Database, void | PromiseLike<void>> {
|
|
20
|
+
readonly writes: ImmutableArray<Write<Data>>;
|
|
21
|
+
constructor(...writes: Write<Data>[]);
|
|
22
|
+
transform(db: Database): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
/** Set of hydrations for all change classes. */
|
|
25
|
+
export declare const DATABASE_HYDRATIONS: {
|
|
26
|
+
changes: typeof Writes;
|
|
27
|
+
change: typeof Write;
|
|
28
|
+
};
|
package/db/Write.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { transform } from "../util/index.js";
|
|
2
|
+
/** Represent a write made to a single document in a database. */
|
|
3
|
+
export class Write {
|
|
4
|
+
constructor({ collection, id }, value) {
|
|
5
|
+
this.collection = collection;
|
|
6
|
+
this.id = id;
|
|
7
|
+
this.value = value;
|
|
8
|
+
}
|
|
9
|
+
async transform(db) {
|
|
10
|
+
await db.doc(this.collection, this.id).write(this.value);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Represent a list of writes made to a set of documents in a database.
|
|
15
|
+
* - Sets of writes are predictable and repeatable, so unpredictable operations like `create()` and query operations are not supported.
|
|
16
|
+
* - Every write must be applied to a specific database document in a specific collection and are applied in the specified order.
|
|
17
|
+
*/
|
|
18
|
+
export class Writes {
|
|
19
|
+
constructor(...writes) {
|
|
20
|
+
this.writes = writes;
|
|
21
|
+
}
|
|
22
|
+
async transform(db) {
|
|
23
|
+
for (const writes of this.writes)
|
|
24
|
+
await transform(db, writes);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Set of hydrations for all change classes. */
|
|
28
|
+
export const DATABASE_HYDRATIONS = {
|
|
29
|
+
changes: Writes,
|
|
30
|
+
change: Write,
|
|
31
|
+
};
|
|
32
|
+
DATABASE_HYDRATIONS;
|
package/db/index.d.ts
CHANGED
package/db/index.js
CHANGED
package/feedback/index.d.ts
CHANGED
package/feedback/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Firestore } from "firebase/firestore";
|
|
2
|
-
import { Results, Provider, DataDocument, DataQuery, Result, Observer, Transform, AsynchronousProvider, Data } from "../../index.js";
|
|
2
|
+
import { Results, Provider, DataDocument, DataQuery, Result, Observer, Transform, AsynchronousProvider, Data, Unsubscriber } from "../../index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Firestore client database provider.
|
|
5
5
|
* - Works with the Firebase JS SDK.
|
|
@@ -10,10 +10,10 @@ export declare class FirestoreClientProvider extends Provider implements Asynchr
|
|
|
10
10
|
readonly firestore: Firestore;
|
|
11
11
|
constructor(firestore: Firestore);
|
|
12
12
|
get<T extends Data>(ref: DataDocument<T>): Promise<Result<T>>;
|
|
13
|
-
subscribe<T extends Data>(ref: DataDocument<T>, observer: Observer<Result<T>>):
|
|
13
|
+
subscribe<T extends Data>(ref: DataDocument<T>, observer: Observer<Result<T>>): Unsubscriber;
|
|
14
14
|
add<T extends Data>(ref: DataQuery<T>, data: T): Promise<string>;
|
|
15
15
|
write<T extends Data>(ref: DataDocument<T>, value: T | Transform<T> | undefined): Promise<void>;
|
|
16
16
|
getQuery<T extends Data>(ref: DataQuery<T>): Promise<Results<T>>;
|
|
17
|
-
subscribeQuery<T extends Data>(ref: DataQuery<T>, observer: Observer<Results<T>>):
|
|
17
|
+
subscribeQuery<T extends Data>(ref: DataQuery<T>, observer: Observer<Results<T>>): Unsubscriber;
|
|
18
18
|
writeQuery<T extends Data>(ref: DataQuery<T>, value: T | Transform<T> | undefined): Promise<void>;
|
|
19
19
|
}
|
|
@@ -88,7 +88,7 @@ export class FirestoreClientProvider extends Provider {
|
|
|
88
88
|
return snapshot.data();
|
|
89
89
|
}
|
|
90
90
|
subscribe(ref, observer) {
|
|
91
|
-
return onSnapshot(getDocument(this.firestore, ref), snapshot => dispatchNext(snapshot.data()
|
|
91
|
+
return onSnapshot(getDocument(this.firestore, ref), snapshot => dispatchNext(observer, snapshot.data()), thrown => dispatchError(observer, thrown));
|
|
92
92
|
}
|
|
93
93
|
async add(ref, data) {
|
|
94
94
|
const reference = await addDoc(getCollection(this.firestore, ref), data); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
@@ -106,7 +106,7 @@ export class FirestoreClientProvider extends Provider {
|
|
|
106
106
|
return getResults(await getDocs(getQuery(this.firestore, ref)));
|
|
107
107
|
}
|
|
108
108
|
subscribeQuery(ref, observer) {
|
|
109
|
-
return onSnapshot(getQuery(this.firestore, ref), snapshot => dispatchNext(getResults(snapshot)
|
|
109
|
+
return onSnapshot(getQuery(this.firestore, ref), snapshot => dispatchNext(observer, getResults(snapshot)), thrown => dispatchError(observer, thrown));
|
|
110
110
|
}
|
|
111
111
|
async writeQuery(ref, value) {
|
|
112
112
|
const snapshot = await getDocs(getQuery(this.firestore, ref));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Firestore } from "firebase/firestore/lite";
|
|
2
|
-
import { Provider, DataDocument, DataQuery, Result, Transform, AsynchronousProvider, Data, Results } from "../../index.js";
|
|
2
|
+
import { Provider, DataDocument, DataQuery, Result, Transform, AsynchronousProvider, Data, Results, Unsubscriber } from "../../index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Firestore Lite client database provider.
|
|
5
5
|
* - Works with the Firebase JS SDK.
|
|
@@ -10,10 +10,10 @@ export declare class FirestoreClientProvider extends Provider implements Asynchr
|
|
|
10
10
|
readonly firestore: Firestore;
|
|
11
11
|
constructor(firestore: Firestore);
|
|
12
12
|
get<T extends Data>(ref: DataDocument<T>): Promise<Result<T>>;
|
|
13
|
-
subscribe():
|
|
13
|
+
subscribe(): Unsubscriber;
|
|
14
14
|
add<T extends Data>(ref: DataQuery<T>, data: T): Promise<string>;
|
|
15
15
|
write<T extends Data>(ref: DataDocument<T>, value: T | Transform<T> | undefined): Promise<void>;
|
|
16
16
|
getQuery<T extends Data>(ref: DataQuery<T>): Promise<Results<T>>;
|
|
17
|
-
subscribeQuery():
|
|
17
|
+
subscribeQuery(): Unsubscriber;
|
|
18
18
|
writeQuery<T extends Data>(ref: DataQuery<T>, value: T | Transform<T> | undefined): Promise<void>;
|
|
19
19
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Firestore } from "@google-cloud/firestore";
|
|
2
|
-
import { Provider, DataDocument, DataQuery, Observer, Result, Transform, Data, AsynchronousProvider, Entry, Results } from "../../index.js";
|
|
2
|
+
import { Provider, DataDocument, DataQuery, Observer, Result, Transform, Data, AsynchronousProvider, Entry, Results, Unsubscriber } from "../../index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Firestore server database provider.
|
|
5
5
|
* - Works with the Firebase Admin SDK for Node.JS
|
|
@@ -8,10 +8,10 @@ export declare class FirestoreServerProvider extends Provider implements Asynchr
|
|
|
8
8
|
readonly firestore: Firestore;
|
|
9
9
|
constructor(firestore?: Firestore);
|
|
10
10
|
get<T extends Data>(ref: DataDocument<T>): Promise<Result<T>>;
|
|
11
|
-
subscribe<T extends Data>(ref: DataDocument<T>, observer: Observer<Result<T>>):
|
|
11
|
+
subscribe<T extends Data>(ref: DataDocument<T>, observer: Observer<Result<T>>): Unsubscriber;
|
|
12
12
|
add<T extends Data>(ref: DataQuery<T>, data: T): Promise<string>;
|
|
13
13
|
write<T extends Data>(ref: DataDocument<T>, value: T | Transform<T> | undefined): Promise<void>;
|
|
14
14
|
getQuery<T extends Data>(ref: DataQuery<T>): Promise<Iterable<Entry<T>>>;
|
|
15
|
-
subscribeQuery<T extends Data>(ref: DataQuery<T>, observer: Observer<Results<T>>):
|
|
15
|
+
subscribeQuery<T extends Data>(ref: DataQuery<T>, observer: Observer<Results<T>>): Unsubscriber;
|
|
16
16
|
writeQuery<T extends Data>(ref: DataQuery<T>, value: T | Transform<T> | undefined): Promise<void>;
|
|
17
17
|
}
|
|
@@ -85,7 +85,7 @@ export class FirestoreServerProvider extends Provider {
|
|
|
85
85
|
return (await getDocument(this.firestore, ref).get()).data();
|
|
86
86
|
}
|
|
87
87
|
subscribe(ref, observer) {
|
|
88
|
-
return getDocument(this.firestore, ref).onSnapshot(snapshot => dispatchNext(snapshot.data()
|
|
88
|
+
return getDocument(this.firestore, ref).onSnapshot(snapshot => dispatchNext(observer, snapshot.data()), thrown => dispatchError(observer, thrown));
|
|
89
89
|
}
|
|
90
90
|
async add(ref, data) {
|
|
91
91
|
return (await getCollection(this.firestore, ref).add(data)).id;
|
|
@@ -102,7 +102,7 @@ export class FirestoreServerProvider extends Provider {
|
|
|
102
102
|
return getResults(await getQuery(this.firestore, ref).get());
|
|
103
103
|
}
|
|
104
104
|
subscribeQuery(ref, observer) {
|
|
105
|
-
return getQuery(this.firestore, ref).onSnapshot(snapshot => dispatchNext(getResults(snapshot)
|
|
105
|
+
return getQuery(this.firestore, ref).onSnapshot(snapshot => dispatchNext(observer, getResults(snapshot)), thrown => dispatchError(observer, thrown));
|
|
106
106
|
}
|
|
107
107
|
async writeQuery(ref, value) {
|
|
108
108
|
const writer = this.firestore.bulkWriter();
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isAsync, toMap,
|
|
1
|
+
import { isAsync, toMap, TransformObserver, awaitNext, } from "../util/index.js";
|
|
2
2
|
import { LazyState } from "../stream/index.js";
|
|
3
3
|
import { ThroughProvider } from "./ThroughProvider.js";
|
|
4
4
|
/** How long to wait after all subscriptions have ended to close the source subscription. */
|
|
@@ -80,7 +80,7 @@ export class BatchProvider extends ThroughProvider {
|
|
|
80
80
|
const sub = ((_a = this._subs)[key] || (_a[key] = new LazyState(STOP_DELAY).from(o => {
|
|
81
81
|
var _a;
|
|
82
82
|
// Convert the iterable to a map because it might be read multiple times.
|
|
83
|
-
const stop = super.subscribeQuery(ref, new
|
|
83
|
+
const stop = super.subscribeQuery(ref, new TransformObserver(toMap, o));
|
|
84
84
|
// The first value from the subscription can be reused for any concurrent get requests.
|
|
85
85
|
(_a = this._gets)[key] || (_a[key] = this._awaitDocuments(ref, awaitNext(sub)));
|
|
86
86
|
return () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Transform } from "../transform/index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { TransformObserver } from "../util/index.js";
|
|
3
3
|
import { MemoryProvider } from "./MemoryProvider.js";
|
|
4
4
|
import { ThroughProvider } from "./ThroughProvider.js";
|
|
5
5
|
/** Keep a copy of received data in a local cache. */
|
|
@@ -33,7 +33,7 @@ export class CacheProvider extends ThroughProvider {
|
|
|
33
33
|
}
|
|
34
34
|
// Override to cache any got results.
|
|
35
35
|
subscribe(ref, observer) {
|
|
36
|
-
return super.subscribe(ref, new
|
|
36
|
+
return super.subscribe(ref, new TransformObserver(result => this._cacheResult(ref, result), observer));
|
|
37
37
|
}
|
|
38
38
|
async add(ref, data) {
|
|
39
39
|
const id = await super.add(ref, data);
|
|
@@ -72,7 +72,7 @@ export class CacheProvider extends ThroughProvider {
|
|
|
72
72
|
}
|
|
73
73
|
// Override to cache any got results.
|
|
74
74
|
subscribeQuery(ref, observer) {
|
|
75
|
-
return super.subscribeQuery(ref, new
|
|
75
|
+
return super.subscribeQuery(ref, new TransformObserver(results => this._cacheResults(ref, results), observer));
|
|
76
76
|
}
|
|
77
77
|
async writeQuery(ref, value) {
|
|
78
78
|
await super.writeQuery(ref, value);
|