shelving 1.76.1 → 1.78.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/constraint/Constraints.d.ts +1 -1
- package/constraint/FilterConstraint.d.ts +6 -6
- package/constraint/FilterConstraint.js +1 -1
- package/constraint/FilterConstraints.d.ts +5 -5
- package/constraint/QueryConstraints.d.ts +4 -4
- package/constraint/QueryConstraints.js +2 -2
- package/constraint/SortConstraint.d.ts +4 -3
- package/constraint/SortConstraint.js +2 -3
- package/constraint/SortConstraints.d.ts +5 -5
- package/db/Change.d.ts +10 -13
- package/db/Change.js +2 -2
- package/db/Collection.d.ts +3 -3
- package/db/Database.d.ts +12 -12
- package/db/Item.d.ts +5 -5
- package/db/Item.js +3 -5
- package/db/Query.d.ts +6 -6
- package/db/Query.js +2 -3
- package/firestore/client/FirestoreClientProvider.d.ts +3 -3
- package/firestore/client/FirestoreClientProvider.js +4 -4
- package/firestore/lite/FirestoreLiteProvider.d.ts +3 -3
- package/firestore/lite/FirestoreLiteProvider.js +4 -4
- package/firestore/server/FirestoreServerProvider.d.ts +3 -3
- package/firestore/server/FirestoreServerProvider.js +4 -4
- package/package.json +5 -5
- package/provider/CacheProvider.d.ts +3 -3
- package/provider/CacheProvider.js +6 -6
- package/provider/DebugProvider.d.ts +5 -5
- package/provider/DebugProvider.js +12 -12
- package/provider/MemoryProvider.d.ts +5 -5
- package/provider/MemoryProvider.js +9 -8
- package/provider/Provider.d.ts +7 -7
- package/provider/ThroughProvider.d.ts +5 -5
- package/provider/ThroughProvider.js +4 -4
- package/provider/ValidationProvider.d.ts +11 -11
- package/provider/ValidationProvider.js +29 -28
- package/react/useItem.d.ts +7 -7
- package/react/useQuery.d.ts +10 -10
- package/schema/DataSchema.d.ts +5 -1
- package/state/DataState.d.ts +3 -3
- package/update/DataUpdate.d.ts +15 -7
- package/update/DataUpdate.js +28 -21
- package/util/transform.d.ts +3 -3
package/react/useItem.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { Unsubscribe } from "../observe/Observable.js";
|
|
2
|
-
import { Datas,
|
|
2
|
+
import { Datas, Key } from "../util/data.js";
|
|
3
3
|
import { ItemValue, ItemData, AsyncItem, Item } from "../db/Item.js";
|
|
4
4
|
import { State } from "../state/State.js";
|
|
5
5
|
import { BooleanState } from "../state/BooleanState.js";
|
|
6
6
|
/** Hold the current state of a item. */
|
|
7
|
-
export declare class ItemState<T extends Datas> extends State<ItemValue<
|
|
8
|
-
readonly ref: Item<T> | AsyncItem<T>;
|
|
7
|
+
export declare class ItemState<T extends Datas, K extends Key<T> = Key<T>> extends State<ItemValue<T[K]>> {
|
|
8
|
+
readonly ref: Item<T, K> | AsyncItem<T, K>;
|
|
9
9
|
readonly busy: BooleanState;
|
|
10
10
|
/** Get the data of the item (throws `RequiredError` if item doesn't exist). */
|
|
11
|
-
get data(): ItemData<
|
|
11
|
+
get data(): ItemData<T[K]>;
|
|
12
12
|
/** Does the item exist (i.e. its value isn't `null`)? */
|
|
13
13
|
get exists(): boolean;
|
|
14
|
-
constructor(ref: Item<T> | AsyncItem<T>);
|
|
14
|
+
constructor(ref: Item<T, K> | AsyncItem<T, K>);
|
|
15
15
|
/** Refresh this state from the source provider. */
|
|
16
16
|
readonly refresh: () => void;
|
|
17
17
|
_refresh(): Promise<void>;
|
|
@@ -28,5 +28,5 @@ export declare class ItemState<T extends Datas> extends State<ItemValue<Value<T>
|
|
|
28
28
|
* Use an item in a React component.
|
|
29
29
|
* - Uses the default cache, so will error if not used inside `<Cache>`
|
|
30
30
|
*/
|
|
31
|
-
export declare function useItem<T extends Datas
|
|
32
|
-
export declare function useItem<T extends Datas
|
|
31
|
+
export declare function useItem<T extends Datas, K extends Key<T>>(ref: Item<T, K> | AsyncItem<T, K>): ItemState<T, K>;
|
|
32
|
+
export declare function useItem<T extends Datas, K extends Key<T>>(ref?: Item<T, K> | AsyncItem<T, K>): ItemState<T, K> | undefined;
|
package/react/useQuery.d.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import type { Unsubscribe } from "../observe/Observable.js";
|
|
2
|
-
import type { Datas,
|
|
2
|
+
import type { Datas, Key } from "../util/data.js";
|
|
3
3
|
import type { ItemArray, ItemValue, ItemData } from "../db/Item.js";
|
|
4
4
|
import { AsyncQuery, Query } from "../db/Query.js";
|
|
5
5
|
import { State } from "../state/State.js";
|
|
6
6
|
import { BooleanState } from "../state/BooleanState.js";
|
|
7
7
|
/** Hold the current state of a query. */
|
|
8
|
-
export declare class QueryState<T extends Datas> extends State<ItemArray<
|
|
9
|
-
readonly ref: Query<T> | AsyncQuery<T>;
|
|
8
|
+
export declare class QueryState<T extends Datas, K extends Key<T> = Key<T>> extends State<ItemArray<T[K]>> {
|
|
9
|
+
readonly ref: Query<T, K> | AsyncQuery<T, K>;
|
|
10
10
|
readonly busy: BooleanState;
|
|
11
11
|
readonly limit: number;
|
|
12
12
|
/** Can more items be loaded after the current result. */
|
|
13
13
|
get hasMore(): boolean;
|
|
14
14
|
private _hasMore;
|
|
15
15
|
/** Get the first document matched by this query or `null` if this query has no items. */
|
|
16
|
-
get firstValue(): ItemValue<
|
|
16
|
+
get firstValue(): ItemValue<T[K]>;
|
|
17
17
|
/** Get the first document matched by this query. */
|
|
18
|
-
get firstData(): ItemData<
|
|
18
|
+
get firstData(): ItemData<T[K]>;
|
|
19
19
|
/** Get the last document matched by this query or `null` if this query has no items. */
|
|
20
|
-
get lastValue(): ItemValue<
|
|
20
|
+
get lastValue(): ItemValue<T[K]>;
|
|
21
21
|
/** Get the last document matched by this query. */
|
|
22
|
-
get lastData(): ItemData<
|
|
22
|
+
get lastData(): ItemData<T[K]>;
|
|
23
23
|
/** Does the document have at least one result. */
|
|
24
24
|
get exists(): boolean;
|
|
25
25
|
/** Get the number of items matching this query. */
|
|
26
26
|
get count(): number;
|
|
27
|
-
constructor(ref: Query<T> | AsyncQuery<T>);
|
|
27
|
+
constructor(ref: Query<T, K> | AsyncQuery<T, K>);
|
|
28
28
|
/** Refresh this state from the source provider. */
|
|
29
29
|
readonly refresh: () => void;
|
|
30
30
|
_refresh(): Promise<void>;
|
|
@@ -47,5 +47,5 @@ export declare class QueryState<T extends Datas> extends State<ItemArray<Value<T
|
|
|
47
47
|
* Use a query in a React component.
|
|
48
48
|
* - Uses the default cache, so will error if not used inside `<Cache>`
|
|
49
49
|
*/
|
|
50
|
-
export declare function useQuery<T extends Datas
|
|
51
|
-
export declare function useQuery<T extends Datas
|
|
50
|
+
export declare function useQuery<T extends Datas, K extends Key<T>>(ref: Query<T, K> | AsyncQuery<T, K>): QueryState<T, K>;
|
|
51
|
+
export declare function useQuery<T extends Datas, K extends Key<T>>(ref?: Query<T, K> | AsyncQuery<T, K>): QueryState<T, K> | undefined;
|
package/schema/DataSchema.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Data } from "../util/data.js";
|
|
1
|
+
import type { Data, Datas } from "../util/data.js";
|
|
2
2
|
import { Validators } from "../util/validate.js";
|
|
3
3
|
import { OptionalSchema } from "./OptionalSchema.js";
|
|
4
4
|
import { Schema } from "./Schema.js";
|
|
@@ -12,6 +12,10 @@ export declare class DataSchema<T extends Data> extends Schema<T> {
|
|
|
12
12
|
});
|
|
13
13
|
validate(unsafeValue?: unknown): T;
|
|
14
14
|
}
|
|
15
|
+
/** Set of named data schemas. */
|
|
16
|
+
export declare type DataSchemas<T extends Datas> = {
|
|
17
|
+
[K in keyof T]: DataSchema<T[K]>;
|
|
18
|
+
};
|
|
15
19
|
/** Valid data object with specifed properties. */
|
|
16
20
|
export declare const DATA: <T extends Data>(props: Validators<T>) => DataSchema<T>;
|
|
17
21
|
/** Valid data object with specifed properties, or `null` */
|
package/state/DataState.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Data, Key, OptionalData } from "../util/data.js";
|
|
2
|
-
import {
|
|
2
|
+
import { Transformers } from "../util/transform.js";
|
|
3
3
|
import { State } from "./State.js";
|
|
4
4
|
/** State that stores a data object and has additional methods to help with that. */
|
|
5
5
|
export declare class DataState<T extends Data> extends State<T> {
|
|
@@ -8,7 +8,7 @@ export declare class DataState<T extends Data> extends State<T> {
|
|
|
8
8
|
/** Set a prop in this object to a new value. */
|
|
9
9
|
set<K extends Key<T>>(key: K, value: T[K]): void;
|
|
10
10
|
/** Update several props in this object. */
|
|
11
|
-
update(updates:
|
|
11
|
+
update(updates: Transformers<T>): void;
|
|
12
12
|
}
|
|
13
13
|
/** State that stores an optional data object and has additional methods to help with that. */
|
|
14
14
|
export declare class OptionalDataState<T extends Data> extends State<OptionalData<T>> {
|
|
@@ -19,7 +19,7 @@ export declare class OptionalDataState<T extends Data> extends State<OptionalDat
|
|
|
19
19
|
/** Set a prop in this object to a new value. */
|
|
20
20
|
set<K extends Key<T>>(key: K, value: T[K]): void;
|
|
21
21
|
/** Update several props in this object. */
|
|
22
|
-
update(updates:
|
|
22
|
+
update(updates: Transformers<T>): void;
|
|
23
23
|
/** Delete this result. */
|
|
24
24
|
delete(): void;
|
|
25
25
|
}
|
package/update/DataUpdate.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Data, Key, Prop } from "../util/data.js";
|
|
2
2
|
import { Nullish } from "../util/null.js";
|
|
3
3
|
import { Transformable } from "../util/transform.js";
|
|
4
|
-
import { Validator } from "../util/validate.js";
|
|
4
|
+
import { Validator, Validators } from "../util/validate.js";
|
|
5
5
|
import { Update } from "./Update.js";
|
|
6
6
|
/**
|
|
7
7
|
* Set of named transforms for the props of a data object.
|
|
@@ -10,19 +10,27 @@ import { Update } from "./Update.js";
|
|
|
10
10
|
* - If a prop contains a transform, the existing value is transformed.
|
|
11
11
|
* - This is a subset of `Dispatchers`
|
|
12
12
|
*/
|
|
13
|
-
export declare type
|
|
13
|
+
export declare type Updates<T extends Data = Data> = {
|
|
14
14
|
readonly [K in keyof T]?: T[K] | Update<T[K]>;
|
|
15
15
|
};
|
|
16
|
-
/**
|
|
17
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Validate a set of updates against a set of validators.
|
|
18
|
+
*/
|
|
19
|
+
export declare function validateUpdates<T extends Data>(unsafeUpdates: Updates<T>, validators: Validators<T>): {
|
|
20
|
+
[k: string]: import("../util/data.js").Value<Updates<T>>;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Update that can be applied to a data object to update its props.
|
|
24
|
+
*/
|
|
25
|
+
export declare class DataUpdate<T extends Data = Data> extends Update<T> implements Iterable<Prop<Updates<T>>>, Transformable<T, T> {
|
|
18
26
|
/** Return a data update with a specific prop marked for update. */
|
|
19
27
|
static with<X extends Data, K extends Key<X>>(key: Nullish<K>, value: X[K] | Update<X[K]>): DataUpdate<X>;
|
|
20
|
-
readonly updates:
|
|
21
|
-
constructor(props:
|
|
28
|
+
readonly updates: Updates<T>;
|
|
29
|
+
constructor(props: Updates<T>);
|
|
22
30
|
transform(data: T): T;
|
|
23
31
|
validate(validator: Validator<T>): this;
|
|
24
32
|
/** Return a data update with a specific prop marked for update. */
|
|
25
33
|
with<K extends Key<T>>(key: Nullish<K>, value: T[K] | Update<T[K]>): this;
|
|
26
34
|
/** Iterate over the transforms in this object. */
|
|
27
|
-
[Symbol.iterator](): Iterator<Prop<
|
|
35
|
+
[Symbol.iterator](): Iterator<Prop<Updates<T>>, void>;
|
|
28
36
|
}
|
package/update/DataUpdate.js
CHANGED
|
@@ -6,7 +6,33 @@ import { isNullish } from "../util/null.js";
|
|
|
6
6
|
import { transformData } from "../util/transform.js";
|
|
7
7
|
import { validate } from "../util/validate.js";
|
|
8
8
|
import { Update } from "./Update.js";
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Validate a set of updates against a set of validators.
|
|
11
|
+
*/
|
|
12
|
+
export function validateUpdates(unsafeUpdates, validators) {
|
|
13
|
+
return Object.fromEntries(_validateUpdates(unsafeUpdates, validators));
|
|
14
|
+
}
|
|
15
|
+
function* _validateUpdates(unsafeUpdates, validators) {
|
|
16
|
+
const feedbacks = new Map();
|
|
17
|
+
for (const [key, validator] of getProps(validators)) {
|
|
18
|
+
const unsafeUpdate = unsafeUpdates[key];
|
|
19
|
+
if (unsafeUpdate !== undefined) {
|
|
20
|
+
try {
|
|
21
|
+
yield [key, unsafeUpdate instanceof Update ? unsafeUpdate.validate(validator) : validate(unsafeUpdate, validator)];
|
|
22
|
+
}
|
|
23
|
+
catch (thrown) {
|
|
24
|
+
if (!isFeedback(thrown))
|
|
25
|
+
throw thrown;
|
|
26
|
+
feedbacks.set(key, thrown);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (feedbacks.size)
|
|
31
|
+
throw new InvalidFeedback("Invalid updates", feedbacks);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Update that can be applied to a data object to update its props.
|
|
35
|
+
*/
|
|
10
36
|
export class DataUpdate extends Update {
|
|
11
37
|
constructor(props) {
|
|
12
38
|
super();
|
|
@@ -25,7 +51,7 @@ export class DataUpdate extends Update {
|
|
|
25
51
|
return {
|
|
26
52
|
__proto__: Object.getPrototypeOf(this),
|
|
27
53
|
...this,
|
|
28
|
-
updates:
|
|
54
|
+
updates: validateUpdates(this.updates, validator.props),
|
|
29
55
|
};
|
|
30
56
|
}
|
|
31
57
|
/** Return a data update with a specific prop marked for update. */
|
|
@@ -43,22 +69,3 @@ export class DataUpdate extends Update {
|
|
|
43
69
|
return Object.entries(this.updates).values();
|
|
44
70
|
}
|
|
45
71
|
}
|
|
46
|
-
/** Validate a set of transforms against a set of validators. */
|
|
47
|
-
function* _validateUpdates(unsafeUpdates, validators) {
|
|
48
|
-
const feedbacks = new Map();
|
|
49
|
-
for (const [key, validator] of getProps(validators)) {
|
|
50
|
-
const unsafeUpdate = unsafeUpdates[key];
|
|
51
|
-
if (unsafeUpdate !== undefined) {
|
|
52
|
-
try {
|
|
53
|
-
yield [key, unsafeUpdate instanceof Update ? unsafeUpdate.validate(validator) : validate(unsafeUpdate, validator)];
|
|
54
|
-
}
|
|
55
|
-
catch (thrown) {
|
|
56
|
-
if (!isFeedback(thrown))
|
|
57
|
-
throw thrown;
|
|
58
|
-
feedbacks.set(key, thrown);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
if (feedbacks.size)
|
|
63
|
-
throw new InvalidFeedback("Invalid updates", feedbacks);
|
|
64
|
-
}
|
package/util/transform.d.ts
CHANGED
|
@@ -16,19 +16,19 @@ export declare type Transformer<I, O> = Transformable<I, O> | Transform<I, O> |
|
|
|
16
16
|
export declare function transform<I, O>(input: I, transformer: (v: I) => O): O;
|
|
17
17
|
export declare function transform<I, O>(input: I, transformer: Transformer<I, O>): O;
|
|
18
18
|
/** Set of named transformers for a data object. */
|
|
19
|
-
export declare type
|
|
19
|
+
export declare type Transformers<T extends Data> = {
|
|
20
20
|
readonly [K in keyof T]?: Transformer<T[K], T[K]>;
|
|
21
21
|
};
|
|
22
22
|
/**
|
|
23
23
|
* Transform the props of a data object using a set of transformers for its props.
|
|
24
24
|
* @returns New object with changed props (or the same object if no changes were made).
|
|
25
25
|
*/
|
|
26
|
-
export declare function transformData<T extends Data>(data: T, transforms:
|
|
26
|
+
export declare function transformData<T extends Data>(data: T, transforms: Transformers<T>): T;
|
|
27
27
|
/**
|
|
28
28
|
* Transform the props of a data object using a set of prop transformers.
|
|
29
29
|
* @yield Transformed prop entry after calling the corresponding prop transformer.
|
|
30
30
|
*/
|
|
31
|
-
export declare function transformProps<T extends Data>(data: T, transforms:
|
|
31
|
+
export declare function transformProps<T extends Data>(data: T, transforms: Transformers<T>): Iterable<Prop<T>>;
|
|
32
32
|
/**
|
|
33
33
|
* Transform the _values_ of an iterable set of entries using a transformer.
|
|
34
34
|
* @yield Transformed entry after calling transforming the new value for each entry.
|