shelving 1.17.3 → 1.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/Resource.d.ts +10 -5
- package/api/Resource.js +13 -5
- package/api/errors.d.ts +2 -1
- package/api/errors.js +1 -1
- package/db/Change.d.ts +24 -40
- package/db/Change.js +33 -49
- package/db/Database.d.ts +180 -18
- package/db/Database.js +265 -15
- package/db/Pagination.d.ts +34 -0
- package/db/Pagination.js +80 -0
- package/db/errors.d.ts +17 -11
- package/db/errors.js +17 -9
- package/db/index.d.ts +1 -10
- package/db/index.js +1 -13
- package/error/AssertionError.d.ts +9 -0
- package/error/AssertionError.js +13 -0
- package/error/ConditionError.d.ts +7 -0
- package/error/ConditionError.js +10 -0
- package/error/PermissionError.d.ts +4 -0
- package/error/PermissionError.js +7 -0
- package/error/RequiredError.d.ts +4 -0
- package/error/RequiredError.js +7 -0
- package/error/UnsupportedError.d.ts +4 -0
- package/error/UnsupportedError.js +7 -0
- package/error/ValidationError.d.ts +6 -0
- package/error/ValidationError.js +8 -0
- package/error/index.d.ts +6 -0
- package/error/index.js +6 -0
- package/feedback/ErrorFeedback.d.ts +4 -0
- package/feedback/ErrorFeedback.js +4 -0
- package/{util/feedback.d.ts → feedback/Feedback.d.ts} +1 -30
- package/{util/feedback.js → feedback/Feedback.js} +2 -30
- package/feedback/InvalidFeedback.d.ts +4 -0
- package/feedback/InvalidFeedback.js +4 -0
- package/feedback/SuccessFeedback.d.ts +4 -0
- package/feedback/SuccessFeedback.js +4 -0
- package/feedback/WarningFeedback.d.ts +4 -0
- package/feedback/WarningFeedback.js +4 -0
- package/feedback/hydrations.d.ts +13 -0
- package/feedback/hydrations.js +14 -0
- package/feedback/index.d.ts +7 -0
- package/feedback/index.js +7 -0
- package/feedback/util.d.ts +3 -0
- package/feedback/util.js +7 -0
- package/firestore/client/FirestoreClientProvider.d.ts +19 -0
- package/firestore/client/FirestoreClientProvider.js +121 -0
- package/{firestore-client → firestore/client}/index.d.ts +0 -0
- package/{firestore-client → firestore/client}/index.js +0 -0
- package/firestore/lite/FirestoreLiteProvider.d.ts +19 -0
- package/firestore/lite/FirestoreLiteProvider.js +121 -0
- package/{firestore-lite → firestore/lite}/index.d.ts +0 -0
- package/{firestore-lite → firestore/lite}/index.js +0 -0
- package/firestore/server/FirestoreServerProvider.d.ts +17 -0
- package/firestore/server/FirestoreServerProvider.js +129 -0
- package/{firestore-server → firestore/server}/index.d.ts +0 -0
- package/{firestore-server → firestore/server}/index.js +0 -0
- package/index.d.ts +4 -0
- package/index.js +4 -3
- package/markup/helpers.d.ts +1 -1
- package/markup/helpers.js +3 -3
- package/markup/render.js +2 -2
- package/markup/rules.d.ts +2 -59
- package/markup/rules.js +17 -27
- package/markup/types.d.ts +3 -3
- package/package.json +23 -18
- package/{db → provider}/BatchProvider.d.ts +7 -9
- package/{db → provider}/BatchProvider.js +27 -23
- package/provider/CacheProvider.d.ts +31 -0
- package/provider/CacheProvider.js +86 -0
- package/provider/MemoryProvider.d.ts +23 -0
- package/provider/MemoryProvider.js +135 -0
- package/provider/Provider.d.ts +93 -0
- package/provider/Provider.js +3 -0
- package/provider/ThroughProvider.d.ts +20 -0
- package/provider/ThroughProvider.js +40 -0
- package/provider/ValidationProvider.d.ts +14 -0
- package/provider/ValidationProvider.js +32 -0
- package/provider/index.d.ts +6 -0
- package/provider/index.js +6 -0
- package/query/Filter.d.ts +35 -11
- package/query/Filter.js +38 -40
- package/query/Filters.d.ts +12 -19
- package/query/Filters.js +17 -47
- package/query/Query.d.ts +20 -57
- package/query/Query.js +55 -101
- package/query/Rule.d.ts +3 -12
- package/query/Rule.js +0 -10
- package/query/Rules.d.ts +11 -17
- package/query/Rules.js +14 -34
- package/query/Sort.d.ts +18 -16
- package/query/Sort.js +15 -38
- package/query/Sorts.d.ts +6 -9
- package/query/Sorts.js +9 -33
- package/query/helpers.d.ts +3 -2
- package/query/index.d.ts +0 -1
- package/query/index.js +0 -1
- package/query/types.d.ts +46 -19
- package/react/index.d.ts +3 -2
- package/react/index.js +3 -2
- package/react/useDocument.d.ts +5 -40
- package/react/useDocument.js +14 -23
- package/react/useDocumentData.d.ts +36 -0
- package/react/useDocumentData.js +9 -0
- package/react/useFetch.d.ts +2 -2
- package/react/useFetch.js +20 -12
- package/react/usePagination.d.ts +2 -2
- package/react/usePagination.js +11 -7
- package/react/{useDocuments.d.ts → useQuery.d.ts} +11 -10
- package/react/{useDocuments.js → useQuery.js} +18 -19
- package/react/useState.d.ts +3 -8
- package/react/useState.js +12 -30
- package/react/useSubscribe.d.ts +10 -0
- package/react/useSubscribe.js +17 -0
- package/schema/AllowSchema.d.ts +29 -0
- package/schema/AllowSchema.js +39 -0
- package/schema/ArraySchema.d.ts +12 -19
- package/schema/ArraySchema.js +17 -62
- package/schema/BooleanSchema.d.ts +9 -16
- package/schema/BooleanSchema.js +6 -18
- package/schema/ColorSchema.d.ts +7 -16
- package/schema/ColorSchema.js +9 -13
- package/schema/DataSchema.d.ts +17 -0
- package/schema/DataSchema.js +21 -0
- package/schema/DateSchema.d.ts +17 -23
- package/schema/DateSchema.js +18 -33
- package/schema/EmailSchema.d.ts +8 -11
- package/schema/EmailSchema.js +10 -9
- package/schema/KeySchema.d.ts +7 -12
- package/schema/KeySchema.js +7 -6
- package/schema/MapSchema.d.ts +14 -27
- package/schema/MapSchema.js +16 -61
- package/schema/NullableSchema.d.ts +13 -0
- package/schema/NullableSchema.js +16 -0
- package/schema/NumberSchema.d.ts +14 -35
- package/schema/NumberSchema.js +18 -53
- package/schema/ObjectSchema.d.ts +17 -26
- package/schema/ObjectSchema.js +21 -63
- package/schema/PhoneSchema.d.ts +5 -13
- package/schema/PhoneSchema.js +5 -9
- package/schema/RequiredSchema.d.ts +8 -0
- package/schema/RequiredSchema.js +13 -0
- package/schema/Schema.d.ts +11 -32
- package/schema/Schema.js +1 -17
- package/schema/StringSchema.d.ts +17 -34
- package/schema/StringSchema.js +20 -55
- package/schema/ThroughSchema.d.ts +11 -0
- package/schema/ThroughSchema.js +19 -0
- package/schema/UrlSchema.d.ts +10 -13
- package/schema/UrlSchema.js +16 -36
- package/schema/index.d.ts +5 -0
- package/schema/index.js +5 -0
- package/stream/ArrayState.d.ts +4 -3
- package/stream/ArrayState.js +7 -6
- package/stream/DataState.d.ts +9 -0
- package/stream/DataState.js +13 -0
- package/stream/LastStream.d.ts +5 -0
- package/stream/LastStream.js +11 -0
- package/stream/LazyState.d.ts +2 -2
- package/stream/LazyState.js +4 -4
- package/stream/LazyStream.js +6 -7
- package/stream/State.d.ts +31 -59
- package/stream/State.js +41 -85
- package/stream/Stream.d.ts +31 -49
- package/stream/Stream.js +60 -78
- package/stream/index.d.ts +2 -6
- package/stream/index.js +2 -6
- package/test/basics.d.ts +23 -0
- package/test/basics.js +27 -0
- package/test/index.d.ts +18 -1
- package/test/index.js +9 -1
- package/test/people.d.ts +22 -0
- package/test/people.js +17 -0
- package/test/util.d.ts +7 -0
- package/test/util.js +49 -0
- package/transform/AddEntriesTransform.d.ts +10 -0
- package/transform/AddEntriesTransform.js +16 -0
- package/transform/AddItemsTransform.d.ts +10 -0
- package/transform/AddItemsTransform.js +16 -0
- package/transform/DataTransform.d.ts +24 -0
- package/transform/DataTransform.js +24 -0
- package/transform/IncrementTransform.d.ts +12 -0
- package/transform/IncrementTransform.js +16 -0
- package/transform/RemoveEntriesTransform.d.ts +10 -0
- package/transform/RemoveEntriesTransform.js +16 -0
- package/transform/RemoveItemsTransform.d.ts +10 -0
- package/transform/RemoveItemsTransform.js +16 -0
- package/transform/Transform.d.ts +9 -0
- package/transform/Transform.js +6 -0
- package/transform/hydrations.d.ts +15 -0
- package/transform/hydrations.js +16 -0
- package/transform/index.d.ts +9 -0
- package/transform/index.js +9 -0
- package/transform/util.d.ts +7 -0
- package/transform/util.js +42 -0
- package/util/array.d.ts +20 -94
- package/util/array.js +45 -117
- package/util/assert.d.ts +21 -5
- package/util/assert.js +43 -7
- package/util/async.d.ts +41 -0
- package/util/async.js +71 -0
- package/util/class.d.ts +15 -20
- package/util/class.js +20 -20
- package/util/clone.d.ts +6 -4
- package/util/clone.js +20 -11
- package/util/constants.d.ts +5 -5
- package/util/constants.js +5 -5
- package/util/data.d.ts +130 -16
- package/util/data.js +74 -9
- package/util/date.d.ts +22 -27
- package/util/date.js +56 -57
- package/util/derive.d.ts +88 -0
- package/util/derive.js +48 -0
- package/util/diff.d.ts +12 -11
- package/util/diff.js +11 -11
- package/util/dispatch.d.ts +17 -109
- package/util/dispatch.js +31 -105
- package/util/entry.d.ts +24 -51
- package/util/entry.js +10 -10
- package/util/equal.d.ts +7 -1
- package/util/equal.js +23 -6
- package/util/error.d.ts +4 -27
- package/util/error.js +3 -42
- package/util/filter.d.ts +59 -28
- package/util/filter.js +61 -21
- package/util/function.d.ts +4 -34
- package/util/function.js +0 -4
- package/util/{hydration.d.ts → hydrate.d.ts} +17 -5
- package/util/hydrate.js +68 -0
- package/util/index.d.ts +6 -6
- package/util/index.js +6 -6
- package/util/iterate.d.ts +104 -0
- package/util/iterate.js +200 -0
- package/util/lazy.d.ts +21 -0
- package/util/lazy.js +5 -0
- package/util/map.d.ts +20 -0
- package/util/map.js +10 -0
- package/util/merge.d.ts +9 -6
- package/util/merge.js +7 -5
- package/util/null.d.ts +4 -2
- package/util/null.js +4 -2
- package/util/number.d.ts +1 -1
- package/util/number.js +2 -2
- package/util/object.d.ts +27 -266
- package/util/object.js +27 -210
- package/util/observable.d.ts +73 -18
- package/util/observable.js +147 -12
- package/util/search.d.ts +58 -8
- package/util/search.js +73 -57
- package/util/serialise.js +1 -1
- package/util/sort.d.ts +55 -22
- package/util/sort.js +135 -27
- package/util/string.d.ts +17 -19
- package/util/string.js +42 -33
- package/util/template.d.ts +1 -1
- package/util/template.js +1 -1
- package/util/undefined.d.ts +7 -2
- package/util/undefined.js +7 -2
- package/util/url.d.ts +8 -2
- package/util/url.js +22 -4
- package/util/validate.d.ts +56 -11
- package/util/validate.js +95 -2
- package/db/CacheProvider.d.ts +0 -37
- package/db/CacheProvider.js +0 -112
- package/db/Document.d.ts +0 -100
- package/db/Document.js +0 -121
- package/db/Documents.d.ts +0 -148
- package/db/Documents.js +0 -215
- package/db/MemoryProvider.d.ts +0 -30
- package/db/MemoryProvider.js +0 -164
- package/db/MemoryProvider.test.d.ts +0 -1
- package/db/MemoryProvider.test.js +0 -306
- package/db/PaginationState.d.ts +0 -33
- package/db/PaginationState.js +0 -94
- package/db/Provider.d.ts +0 -134
- package/db/Provider.js +0 -1
- package/db/Reference.d.ts +0 -17
- package/db/Reference.js +0 -34
- package/db/ThroughProvider.d.ts +0 -24
- package/db/ThroughProvider.js +0 -52
- package/db/ValidationProvider.d.ts +0 -21
- package/db/ValidationProvider.js +0 -129
- package/firestore-client/FirestoreClientProvider.d.ts +0 -23
- package/firestore-client/FirestoreClientProvider.js +0 -129
- package/firestore-lite/FirestoreLiteProvider.d.ts +0 -23
- package/firestore-lite/FirestoreLiteProvider.js +0 -129
- package/firestore-server/FirestoreServerProvider.d.ts +0 -21
- package/firestore-server/FirestoreServerProvider.js +0 -156
- package/markup/helpers.test.d.ts +0 -1
- package/markup/helpers.test.js +0 -42
- package/markup/render.test.d.ts +0 -1
- package/markup/render.test.js +0 -544
- package/markup/types.test.d.ts +0 -1
- package/markup/types.test.js +0 -8
- package/query/Filter.test.d.ts +0 -1
- package/query/Filter.test.js +0 -69
- package/query/Filters.test.d.ts +0 -1
- package/query/Filters.test.js +0 -6
- package/query/Query.test.d.ts +0 -1
- package/query/Query.test.js +0 -100
- package/query/Slice.d.ts +0 -8
- package/query/Slice.js +0 -18
- package/query/Slice.test.d.ts +0 -1
- package/query/Slice.test.js +0 -15
- package/query/Sort.test.d.ts +0 -1
- package/query/Sort.test.js +0 -39
- package/query/Sorts.test.d.ts +0 -1
- package/query/Sorts.test.js +0 -28
- package/react/useObserve.d.ts +0 -8
- package/react/useObserve.js +0 -15
- package/schema/ArraySchema.test.d.ts +0 -1
- package/schema/ArraySchema.test.js +0 -168
- package/schema/BooleanSchema.test.d.ts +0 -1
- package/schema/BooleanSchema.test.js +0 -99
- package/schema/ColorSchema.test.d.ts +0 -1
- package/schema/ColorSchema.test.js +0 -105
- package/schema/DateSchema.test.d.ts +0 -1
- package/schema/DateSchema.test.js +0 -138
- package/schema/EmailSchema.test.d.ts +0 -1
- package/schema/EmailSchema.test.js +0 -153
- package/schema/KeySchema.test.d.ts +0 -1
- package/schema/KeySchema.test.js +0 -96
- package/schema/MapSchema.test.d.ts +0 -1
- package/schema/MapSchema.test.js +0 -141
- package/schema/NumberSchema.test.d.ts +0 -1
- package/schema/NumberSchema.test.js +0 -229
- package/schema/ObjectSchema.test.d.ts +0 -1
- package/schema/ObjectSchema.test.js +0 -194
- package/schema/PhoneSchema.test.d.ts +0 -1
- package/schema/PhoneSchema.test.js +0 -105
- package/schema/StringSchema.test.d.ts +0 -1
- package/schema/StringSchema.test.js +0 -189
- package/schema/UrlSchema.test.d.ts +0 -1
- package/schema/UrlSchema.test.js +0 -270
- package/stream/ArrayState.test.d.ts +0 -1
- package/stream/ArrayState.test.js +0 -31
- package/stream/DeriveStream.d.ts +0 -20
- package/stream/DeriveStream.js +0 -43
- package/stream/LimitStream.d.ts +0 -7
- package/stream/LimitStream.js +0 -15
- package/stream/MapState.d.ts +0 -13
- package/stream/MapState.js +0 -25
- package/stream/SliceStream.d.ts +0 -8
- package/stream/SliceStream.js +0 -15
- package/stream/State.test.d.ts +0 -1
- package/stream/State.test.js +0 -162
- package/stream/Stream.test.d.ts +0 -1
- package/stream/Stream.test.js +0 -124
- package/stream/errors.d.ts +0 -16
- package/stream/errors.js +0 -20
- package/stream/util.d.ts +0 -6
- package/stream/util.js +0 -10
- package/test/db.d.ts +0 -128
- package/test/db.js +0 -39
- package/tsconfig.build.tsbuildinfo +0 -1
- package/util/array.test.d.ts +0 -1
- package/util/array.test.js +0 -139
- package/util/class.test.d.ts +0 -1
- package/util/class.test.js +0 -15
- package/util/compare.d.ts +0 -11
- package/util/compare.js +0 -76
- package/util/compare.test.d.ts +0 -1
- package/util/compare.test.js +0 -59
- package/util/console.d.ts +0 -5
- package/util/console.js +0 -4
- package/util/date.test.d.ts +0 -1
- package/util/date.test.js +0 -80
- package/util/diff.test.d.ts +0 -1
- package/util/diff.test.js +0 -160
- package/util/equal.test.d.ts +0 -1
- package/util/equal.test.js +0 -208
- package/util/feedback.test.d.ts +0 -1
- package/util/feedback.test.js +0 -33
- package/util/filter.test.d.ts +0 -1
- package/util/filter.test.js +0 -45
- package/util/hydration.js +0 -49
- package/util/hydration.test.d.ts +0 -1
- package/util/hydration.test.js +0 -93
- package/util/merge.test.d.ts +0 -1
- package/util/merge.test.js +0 -183
- package/util/number.test.d.ts +0 -1
- package/util/number.test.js +0 -86
- package/util/object.test.d.ts +0 -1
- package/util/object.test.js +0 -154
- package/util/promise.d.ts +0 -15
- package/util/promise.js +0 -27
- package/util/promise.test.d.ts +0 -1
- package/util/promise.test.js +0 -11
- package/util/random.test.d.ts +0 -1
- package/util/random.test.js +0 -20
- package/util/search.test.d.ts +0 -1
- package/util/search.test.js +0 -87
- package/util/serialise.test.d.ts +0 -1
- package/util/serialise.test.js +0 -32
- package/util/sort.test.d.ts +0 -1
- package/util/sort.test.js +0 -101
- package/util/string.test.d.ts +0 -1
- package/util/string.test.js +0 -88
- package/util/template.test.d.ts +0 -1
- package/util/template.test.js +0 -125
- package/util/transform.d.ts +0 -87
- package/util/transform.js +0 -109
- package/util/units.test.d.ts +0 -1
- package/util/units.test.js +0 -67
package/api/Resource.d.ts
CHANGED
|
@@ -1,27 +1,32 @@
|
|
|
1
|
-
import { Validator } from "../util/index.js";
|
|
1
|
+
import { Validator, Validatable } from "../util/index.js";
|
|
2
2
|
/**
|
|
3
3
|
* An abstract API resource definition, used to specify types for e.g. serverless functions..
|
|
4
4
|
*
|
|
5
5
|
* @param payload The `Validator` the payload must conform to (defaults to `undefined` if not specified).
|
|
6
6
|
* @param returns The `Validator` the function's returned value must conform to (defaults to `undefined` if not specified).
|
|
7
7
|
*/
|
|
8
|
-
export declare class Resource<P = unknown, R =
|
|
8
|
+
export declare class Resource<P = unknown, R = void> implements Validatable<R> {
|
|
9
9
|
static create<X, Y>(payload: Validator<X>, result: Validator<Y>): Resource<X, Y>;
|
|
10
10
|
static create<Y>(payload: undefined, result: Y): Resource<undefined, Y>;
|
|
11
|
-
static create<X>(payload: Validator<X>, result?: undefined): Resource<X,
|
|
12
|
-
static create(payload?: undefined, result?: undefined): Resource<undefined,
|
|
11
|
+
static create<X>(payload: Validator<X>, result?: undefined): Resource<X, void>;
|
|
12
|
+
static create(payload?: undefined, result?: undefined): Resource<undefined, void>;
|
|
13
13
|
/** Payload validator. */
|
|
14
14
|
readonly payload: Validator<P>;
|
|
15
15
|
/** Result validator. */
|
|
16
16
|
readonly result: Validator<R>;
|
|
17
17
|
protected constructor(payload: Validator<P>, result: Validator<R>);
|
|
18
|
+
/**
|
|
19
|
+
* Validate a payload for this resource.
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
validatePayload(unsafePayload: unknown): P;
|
|
18
23
|
/**
|
|
19
24
|
* Validate a result for this resource.
|
|
20
25
|
*
|
|
21
26
|
* @returns The validated payload for this resource.
|
|
22
27
|
* @throws ValidationError if the result could not be validated.
|
|
23
28
|
*/
|
|
24
|
-
validate(
|
|
29
|
+
validate(unsafeResult: unknown): R;
|
|
25
30
|
}
|
|
26
31
|
/** Extract the payload type from a `Resource`. */
|
|
27
32
|
export declare type PayloadType<X extends Resource> = X extends Resource<infer Y, unknown> ? Y : never;
|
package/api/Resource.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UNDEFINED, validate } from "../util/index.js";
|
|
2
|
+
import { Feedback, throwFeedback } from "../feedback/index.js";
|
|
2
3
|
import { ResourceValidationError } from "./errors.js";
|
|
3
|
-
/** Validator that always returns undefined. */
|
|
4
|
-
const UNDEFINED_VALIDATOR =
|
|
4
|
+
/** Validator that always returns void/undefined. */
|
|
5
|
+
const UNDEFINED_VALIDATOR = UNDEFINED;
|
|
5
6
|
/**
|
|
6
7
|
* An abstract API resource definition, used to specify types for e.g. serverless functions..
|
|
7
8
|
*
|
|
@@ -17,15 +18,22 @@ export class Resource {
|
|
|
17
18
|
static create(payload = UNDEFINED_VALIDATOR, result = UNDEFINED_VALIDATOR) {
|
|
18
19
|
return new Resource(payload, result);
|
|
19
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Validate a payload for this resource.
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
validatePayload(unsafePayload) {
|
|
26
|
+
return throwFeedback(validate(unsafePayload, this.payload));
|
|
27
|
+
}
|
|
20
28
|
/**
|
|
21
29
|
* Validate a result for this resource.
|
|
22
30
|
*
|
|
23
31
|
* @returns The validated payload for this resource.
|
|
24
32
|
* @throws ValidationError if the result could not be validated.
|
|
25
33
|
*/
|
|
26
|
-
validate(
|
|
34
|
+
validate(unsafeResult) {
|
|
27
35
|
try {
|
|
28
|
-
return this.result
|
|
36
|
+
return validate(unsafeResult, this.result);
|
|
29
37
|
}
|
|
30
38
|
catch (thrown) {
|
|
31
39
|
throw thrown instanceof Feedback ? new ResourceValidationError(this, thrown) : thrown;
|
package/api/errors.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Feedback
|
|
1
|
+
import { Feedback } from "../feedback/index.js";
|
|
2
|
+
import { ValidationError } from "../error/index.js";
|
|
2
3
|
import type { Resource } from "./Resource.js";
|
|
3
4
|
/** Thrown if an API `Resource` can't validate. */
|
|
4
5
|
export declare class ResourceValidationError<P, R> extends ValidationError {
|
package/api/errors.js
CHANGED
package/db/Change.d.ts
CHANGED
|
@@ -1,53 +1,37 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { Transforms, Transform } from "../transform/index.js";
|
|
2
|
+
import { ImmutableArray, Data } from "../util/index.js";
|
|
3
|
+
import type { Database, DataDocument } from "./Database.js";
|
|
3
4
|
/** A single change that can be made to a database. */
|
|
4
|
-
export declare abstract class Change
|
|
5
|
+
export declare abstract class Change {
|
|
5
6
|
/** Apply this change to a database. */
|
|
6
|
-
abstract apply(db: Database
|
|
7
|
+
abstract apply(db: Database): void | PromiseLike<void>;
|
|
7
8
|
}
|
|
8
|
-
/** A change that
|
|
9
|
-
export declare class
|
|
10
|
-
readonly collection:
|
|
9
|
+
/** A change that writes a document in a database. */
|
|
10
|
+
export declare class Write<T extends Data> extends Change {
|
|
11
|
+
readonly collection: string;
|
|
11
12
|
readonly id: string;
|
|
12
|
-
readonly
|
|
13
|
-
constructor(collection
|
|
14
|
-
apply(db: Database
|
|
15
|
-
}
|
|
16
|
-
/** A change that updates the value of a document in a database. */
|
|
17
|
-
export declare class UpdateChange<T extends Datas, K extends keyof T & string> extends Change<T> {
|
|
18
|
-
readonly collection: K;
|
|
19
|
-
readonly id: string;
|
|
20
|
-
readonly transforms: Transforms<T[K]>;
|
|
21
|
-
constructor(collection: K, id: string, transforms: Transforms<T[K]>);
|
|
22
|
-
apply(db: Database<T>): void | Promise<void>;
|
|
23
|
-
}
|
|
24
|
-
/** A change that deletes a document from a database. */
|
|
25
|
-
export declare class DeleteChange<T extends Datas, K extends keyof T & string> extends Change<T> {
|
|
26
|
-
readonly collection: K;
|
|
27
|
-
readonly id: string;
|
|
28
|
-
constructor(collection: K, id: string);
|
|
29
|
-
apply(db: Database<T>): void | Promise<void>;
|
|
13
|
+
readonly value: Data | Transform<Data> | undefined;
|
|
14
|
+
constructor({ collection, id }: DataDocument<T>, value: T | Transform<T> | undefined);
|
|
15
|
+
apply(db: Database): void | PromiseLike<void>;
|
|
30
16
|
}
|
|
31
17
|
/**
|
|
32
|
-
* Set of
|
|
18
|
+
* Set of writes that can be applied to documents in a database.
|
|
33
19
|
* - Sets of changes are predictable and repeatable, so unpredictable operations like `create()` and query operations are not supported.
|
|
34
20
|
* - Every change must be applied to a specific database document in a specific collection.
|
|
35
21
|
*/
|
|
36
|
-
export declare class
|
|
37
|
-
readonly changes: ImmutableArray<Change
|
|
38
|
-
constructor(...changes:
|
|
39
|
-
/** Return a new `Changes` instance with an additional `
|
|
40
|
-
set<
|
|
41
|
-
/** Return a new `Changes` instance with an additional `
|
|
42
|
-
|
|
43
|
-
/** Return a new `Changes` instance with an additional `
|
|
44
|
-
|
|
45
|
-
apply(db: Database
|
|
22
|
+
export declare class Writes extends Change {
|
|
23
|
+
readonly changes: ImmutableArray<Change>;
|
|
24
|
+
constructor(...changes: Change[]);
|
|
25
|
+
/** Return a new `Changes` instance with an additional `Write` instance in its changes list. */
|
|
26
|
+
set<T extends Data>(ref: DataDocument<T>, data: T): this;
|
|
27
|
+
/** Return a new `Changes` instance with an additional `Write` instance in its changes list. */
|
|
28
|
+
delete<T extends Data>(ref: DataDocument<T>): this;
|
|
29
|
+
/** Return a new `Changes` instance with an additional `Write` instance in its changes list. */
|
|
30
|
+
update<T extends Data>(ref: DataDocument<T>, transforms: Transforms<T> | Transform<T>): this;
|
|
31
|
+
apply(db: Database): Promise<void> | undefined;
|
|
46
32
|
}
|
|
47
33
|
/** Set of hydrations for all change classes. */
|
|
48
34
|
export declare const CHANGE_HYDRATIONS: {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
update: typeof UpdateChange;
|
|
52
|
-
delete: typeof DeleteChange;
|
|
35
|
+
writes: typeof Writes;
|
|
36
|
+
write: typeof Write;
|
|
53
37
|
};
|
package/db/Change.js
CHANGED
|
@@ -1,76 +1,60 @@
|
|
|
1
|
+
import { DataTransform, Transform } from "../transform/index.js";
|
|
2
|
+
import { VOID, isAsync } from "../util/index.js";
|
|
1
3
|
/** A single change that can be made to a database. */
|
|
2
4
|
export class Change {
|
|
3
5
|
}
|
|
4
|
-
/** A change that
|
|
5
|
-
export class
|
|
6
|
-
constructor(collection, id,
|
|
6
|
+
/** A change that writes a document in a database. */
|
|
7
|
+
export class Write extends Change {
|
|
8
|
+
constructor({ collection, id }, value) {
|
|
7
9
|
super();
|
|
8
10
|
this.collection = collection;
|
|
9
11
|
this.id = id;
|
|
10
|
-
this.
|
|
12
|
+
this.value = value;
|
|
11
13
|
}
|
|
12
14
|
apply(db) {
|
|
13
|
-
|
|
14
|
-
return db.docs(this.collection).is("id", this.id).set(this.data);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
/** A change that updates the value of a document in a database. */
|
|
18
|
-
export class UpdateChange extends Change {
|
|
19
|
-
constructor(collection, id, transforms) {
|
|
20
|
-
super();
|
|
21
|
-
this.collection = collection;
|
|
22
|
-
this.id = id;
|
|
23
|
-
this.transforms = transforms;
|
|
24
|
-
}
|
|
25
|
-
apply(db) {
|
|
26
|
-
return db.doc(this.collection, this.id).update(this.transforms);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
/** A change that deletes a document from a database. */
|
|
30
|
-
export class DeleteChange extends Change {
|
|
31
|
-
constructor(collection, id) {
|
|
32
|
-
super();
|
|
33
|
-
this.collection = collection;
|
|
34
|
-
this.id = id;
|
|
35
|
-
}
|
|
36
|
-
apply(db) {
|
|
37
|
-
return db.doc(this.collection, this.id).delete();
|
|
15
|
+
return db.doc(this.collection, this.id).write(this.value);
|
|
38
16
|
}
|
|
39
17
|
}
|
|
40
18
|
/**
|
|
41
|
-
* Set of
|
|
19
|
+
* Set of writes that can be applied to documents in a database.
|
|
42
20
|
* - Sets of changes are predictable and repeatable, so unpredictable operations like `create()` and query operations are not supported.
|
|
43
21
|
* - Every change must be applied to a specific database document in a specific collection.
|
|
44
22
|
*/
|
|
45
|
-
export class
|
|
23
|
+
export class Writes extends Change {
|
|
46
24
|
constructor(...changes) {
|
|
47
25
|
super();
|
|
48
26
|
this.changes = changes;
|
|
49
27
|
}
|
|
50
|
-
/** Return a new `Changes` instance with an additional `
|
|
51
|
-
set(
|
|
52
|
-
return { __proto__:
|
|
28
|
+
/** Return a new `Changes` instance with an additional `Write` instance in its changes list. */
|
|
29
|
+
set(ref, data) {
|
|
30
|
+
return { __proto__: Object.getPrototypeOf(this), ...this, changes: [...this.changes, new Write(ref, data)] };
|
|
53
31
|
}
|
|
54
|
-
/** Return a new `Changes` instance with an additional `
|
|
55
|
-
|
|
56
|
-
return { __proto__:
|
|
32
|
+
/** Return a new `Changes` instance with an additional `Write` instance in its changes list. */
|
|
33
|
+
delete(ref) {
|
|
34
|
+
return { __proto__: Object.getPrototypeOf(this), ...this, changes: [...this.changes, new Write(ref, undefined)] };
|
|
57
35
|
}
|
|
58
|
-
/** Return a new `Changes` instance with an additional `
|
|
59
|
-
|
|
60
|
-
return {
|
|
36
|
+
/** Return a new `Changes` instance with an additional `Write` instance in its changes list. */
|
|
37
|
+
update(ref, transforms) {
|
|
38
|
+
return {
|
|
39
|
+
__proto__: Object.getPrototypeOf(this),
|
|
40
|
+
...this,
|
|
41
|
+
changes: [...this.changes, new Write(ref, transforms instanceof Transform ? transforms : new DataTransform(transforms))],
|
|
42
|
+
};
|
|
61
43
|
}
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
for (const change of this.changes)
|
|
65
|
-
|
|
66
|
-
|
|
44
|
+
apply(db) {
|
|
45
|
+
const promises = [];
|
|
46
|
+
for (const change of this.changes) {
|
|
47
|
+
const applied = change.apply(db);
|
|
48
|
+
if (isAsync(applied))
|
|
49
|
+
promises.push(applied);
|
|
50
|
+
}
|
|
51
|
+
if (promises.length)
|
|
52
|
+
return Promise.all(promises).then(VOID);
|
|
67
53
|
}
|
|
68
54
|
}
|
|
69
55
|
/** Set of hydrations for all change classes. */
|
|
70
56
|
export const CHANGE_HYDRATIONS = {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
update: UpdateChange,
|
|
74
|
-
delete: DeleteChange,
|
|
57
|
+
writes: Writes,
|
|
58
|
+
write: Write,
|
|
75
59
|
};
|
|
76
60
|
CHANGE_HYDRATIONS;
|
package/db/Database.d.ts
CHANGED
|
@@ -1,30 +1,192 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { Dispatcher, Entry, Observable, Observer, Result, Unsubscriber, ResultsMap, Validatable, Validator, Key, Data, Results, Datas, Validators, ValidatorType } from "../util/index.js";
|
|
2
|
+
import { Transform, Transforms } from "../transform/index.js";
|
|
3
|
+
import type { Provider } from "../provider/Provider.js";
|
|
4
|
+
import { Filters, Sorts, Query } from "../query/index.js";
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Combines a database model and a provider.
|
|
7
7
|
*
|
|
8
8
|
* @param documents Set of loci describing named documents at the root level of the database.
|
|
9
9
|
* @param collections Set of loci describing collections at the root level of the database.
|
|
10
10
|
* @param provider Provider that allows data to be read/written.
|
|
11
11
|
*/
|
|
12
|
-
export declare class Database<
|
|
13
|
-
|
|
14
|
-
readonly schemas: Validators<T>;
|
|
15
|
-
/** The provider that powers this database. */
|
|
12
|
+
export declare class Database<V extends Validators<Datas> = Validators<Datas>> {
|
|
13
|
+
readonly validators: V;
|
|
16
14
|
readonly provider: Provider;
|
|
17
|
-
constructor(
|
|
15
|
+
constructor(validators: V, provider: Provider);
|
|
16
|
+
/** Create a query on a collection in this model. */
|
|
17
|
+
query<K extends Key<V>>(collection: K, filters?: Filters<ValidatorType<V[K]>>, sorts?: Sorts<ValidatorType<V[K]>>, limit?: number | null): DataQuery<ValidatorType<V[K]>>;
|
|
18
|
+
/** Reference a document in a collection in this model. */
|
|
19
|
+
doc<K extends Key<V>>(collection: K, id: string): DataDocument<ValidatorType<V[K]>>;
|
|
20
|
+
}
|
|
21
|
+
/** A documents reference within a specific database. */
|
|
22
|
+
export declare class DataQuery<T extends Data = Data> extends Query<T> implements Observable<Results<T>>, Validatable<Results<T>>, Iterable<Entry<T>> {
|
|
23
|
+
readonly provider: Provider;
|
|
24
|
+
readonly validator: Validator<T>;
|
|
25
|
+
readonly collection: string;
|
|
26
|
+
constructor(provider: Provider, validator: Validator<T>, collection: string, filters?: Filters<T>, sorts?: Sorts<T>, limit?: number | null);
|
|
27
|
+
/** Reference a document in this query's collection. */
|
|
28
|
+
doc(id: string): DataDocument<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Create a new document with a random ID.
|
|
31
|
+
* - Created document is guaranteed to have a unique ID.
|
|
32
|
+
*
|
|
33
|
+
* @param data Complete data to set the document to.
|
|
34
|
+
* @return String ID for the created document (possibly promised).
|
|
35
|
+
*/
|
|
36
|
+
add(data: T): string | PromiseLike<string>;
|
|
37
|
+
/**
|
|
38
|
+
* Get an iterable that yields the results of this entry.
|
|
39
|
+
* @return Map containing the results.
|
|
40
|
+
*/
|
|
41
|
+
get results(): Results<T> | PromiseLike<Results<T>>;
|
|
42
|
+
/**
|
|
43
|
+
* Get an iterable that yields the results of this entry.
|
|
44
|
+
* @return Map containing the results.
|
|
45
|
+
*/
|
|
46
|
+
get resultsMap(): ResultsMap<T> | PromiseLike<ResultsMap<T>>;
|
|
47
|
+
/**
|
|
48
|
+
* Count the number of results of this set of documents.
|
|
49
|
+
* @return Number of documents in the collection (possibly promised).
|
|
50
|
+
*/
|
|
51
|
+
get count(): number | PromiseLike<number>;
|
|
52
|
+
/**
|
|
53
|
+
* Get an entry for the first document matching this query.
|
|
54
|
+
* @return Entry in `[id, data]` format for the first document, or `undefined` if there are no matching documents (possibly promised).
|
|
55
|
+
*/
|
|
56
|
+
get first(): Entry<T> | undefined | PromiseLike<Entry<T> | undefined>;
|
|
57
|
+
/**
|
|
58
|
+
* Subscribe to all matching documents.
|
|
59
|
+
* - `next()` is called once with the initial results, and again any time the results change.
|
|
60
|
+
*
|
|
61
|
+
* @param observer Observer with `next`, `error`, or `complete` methods that the document results are reported back to.
|
|
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
|
+
*
|
|
66
|
+
* @return Function that ends the subscription.
|
|
67
|
+
*/
|
|
68
|
+
subscribe(next: Observer<Results<T>> | Dispatcher<Results<T>>, error?: Dispatcher<Error | unknown>, complete?: Dispatcher<void>): Unsubscriber;
|
|
69
|
+
/**
|
|
70
|
+
* Subscribe to all matching documents.
|
|
71
|
+
* - `next()` is called once with the initial results, and again any time the results change.
|
|
72
|
+
*
|
|
73
|
+
* @param observer Observer with `next`, `error`, or `complete` methods that the document results are reported back to.
|
|
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
|
+
*
|
|
78
|
+
* @return Function that ends the subscription.
|
|
79
|
+
*/
|
|
80
|
+
subscribeMap(next: Observer<ResultsMap<T>> | Dispatcher<ResultsMap<T>>, error?: Dispatcher<Error | unknown>, complete?: Dispatcher<void>): Unsubscriber;
|
|
81
|
+
/**
|
|
82
|
+
* Set all matching documents to the same exact value.
|
|
83
|
+
*
|
|
84
|
+
* @param data Complete data to set the document to.
|
|
85
|
+
* @return Nothing (possibly promised).
|
|
86
|
+
*/
|
|
87
|
+
set(data: T): void | PromiseLike<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Update all matching documents with the same partial value.
|
|
90
|
+
*
|
|
91
|
+
* @param transform `Transform` instance or set of transforms to apply to every matching document.
|
|
92
|
+
* - Not all transforms may be supported by all providers.
|
|
93
|
+
*
|
|
94
|
+
* @return Nothing (possibly promised).
|
|
95
|
+
*/
|
|
96
|
+
update(transform: Transform<T> | Transforms<T>): void | PromiseLike<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Delete all matching documents.
|
|
99
|
+
* @return Nothing (possibly promised).
|
|
100
|
+
*/
|
|
101
|
+
delete(): void | PromiseLike<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Combine `set()`, `update()`, `delete()` into a single method.
|
|
104
|
+
* @return Nothing (possibly promised).
|
|
105
|
+
*/
|
|
106
|
+
write(value: Result<T> | Transform<T>): void | PromiseLike<void>;
|
|
107
|
+
/** Iterate over the resuls (will throw `Promise` if the results are asynchronous). */
|
|
108
|
+
[Symbol.iterator](): Iterator<Entry<T>, void>;
|
|
109
|
+
/** Validate a set of results for this query reference. */
|
|
110
|
+
validate(unsafeEntries: Results): Results<T>;
|
|
111
|
+
toString(): string;
|
|
112
|
+
}
|
|
113
|
+
/** A document reference within a specific database. */
|
|
114
|
+
export declare class DataDocument<T extends Data = Data> implements Observable<Result<T>>, Validatable<T> {
|
|
115
|
+
readonly provider: Provider;
|
|
116
|
+
readonly validator: Validator<T>;
|
|
117
|
+
readonly collection: string;
|
|
118
|
+
readonly id: string;
|
|
119
|
+
constructor(provider: Provider, validator: Validator<T>, collection: string, id: string);
|
|
120
|
+
/** Create a query on this document's collection. */
|
|
121
|
+
query(filters?: Filters<T>, sorts?: Sorts<T>, limit?: number | null): DataQuery<T>;
|
|
122
|
+
/** Get an 'optional' reference to this document (uses a `ModelQuery` with an `id` filter). */
|
|
123
|
+
get optional(): DataQuery<T>;
|
|
124
|
+
/**
|
|
125
|
+
* Does this document exist?
|
|
126
|
+
*
|
|
127
|
+
* @return Document's data, or `undefined` if the document doesn't exist (possibly promised).
|
|
128
|
+
*/
|
|
129
|
+
get exists(): boolean | PromiseLike<boolean>;
|
|
130
|
+
/**
|
|
131
|
+
* Get the result of this document.
|
|
132
|
+
*
|
|
133
|
+
* @return Document's data, or `undefined` if the document doesn't exist (possibly promised).
|
|
134
|
+
*/
|
|
135
|
+
get result(): Result<T> | PromiseLike<Result<T>>;
|
|
136
|
+
/**
|
|
137
|
+
* Get the data of this document.
|
|
138
|
+
* - Useful for destructuring, e.g. `{ name, title } = await documentThatMustExist.asyncData`
|
|
139
|
+
*
|
|
140
|
+
* @return Document's data (possibly promised).
|
|
141
|
+
* @throws RequiredError if the document's result was undefined.
|
|
142
|
+
*/
|
|
143
|
+
get data(): T | PromiseLike<T>;
|
|
144
|
+
/**
|
|
145
|
+
* Subscribe to the result of this document (indefinitely).
|
|
146
|
+
* - `next()` is called once with the initial result, and again any time the result changes.
|
|
147
|
+
*
|
|
148
|
+
* @param observer Observer with `next`, `error`, or `complete` methods.
|
|
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
|
+
*
|
|
153
|
+
* @return Function that ends the subscription.
|
|
154
|
+
*/
|
|
155
|
+
subscribe(next: Observer<Result<T>> | Dispatcher<Result<T>>, error?: Dispatcher<Error | unknown>, complete?: Dispatcher<void>): Unsubscriber;
|
|
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
|
+
*/
|
|
163
|
+
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
|
+
*/
|
|
175
|
+
update(transforms: Transform<T> | Transforms<T>): void | PromiseLike<void>;
|
|
18
176
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
177
|
+
* Delete this document.
|
|
178
|
+
* - Will not throw an error if the document doesn't exist.
|
|
179
|
+
*
|
|
180
|
+
* @return Nothing (possibly promised).
|
|
22
181
|
*/
|
|
23
|
-
|
|
182
|
+
delete(): void | PromiseLike<void>;
|
|
24
183
|
/**
|
|
25
|
-
*
|
|
26
|
-
* @param name Document name, e.g. `fido`
|
|
27
|
-
* @example `db.doc("dogs", "fido").get()`
|
|
184
|
+
* Combine `set()`, `update()`, `delete()` into a single method.
|
|
28
185
|
*/
|
|
29
|
-
|
|
186
|
+
write(value: Result<T> | Transform<T>): void | PromiseLike<void>;
|
|
187
|
+
/** Validate data for this query reference. */
|
|
188
|
+
validate(unsafeData: Data): T;
|
|
189
|
+
toString(): string;
|
|
30
190
|
}
|
|
191
|
+
/** Get the data for a document from a result for that document. */
|
|
192
|
+
export declare function getDocumentData<T extends Data>(result: Result<T>, ref: DataDocument<T>): T;
|