shelving 1.82.0 → 1.83.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.js +3 -3
- package/constraint/FilterConstraint.d.ts +5 -5
- package/constraint/SortConstraint.d.ts +2 -2
- package/db/Change.d.ts +12 -12
- package/db/Collection.d.ts +4 -4
- package/db/Database.d.ts +29 -29
- package/db/Item.d.ts +4 -4
- package/db/Query.d.ts +4 -4
- package/feedback/Feedback.d.ts +2 -2
- package/feedback/Feedback.js +3 -2
- package/firestore/client/FirestoreClientProvider.js +2 -2
- package/firestore/lite/FirestoreLiteProvider.js +2 -2
- package/firestore/server/FirestoreServerProvider.js +2 -2
- package/package.json +1 -1
- package/provider/CacheProvider.d.ts +12 -12
- package/provider/DebugProvider.d.ts +21 -21
- package/provider/MemoryProvider.d.ts +16 -16
- package/provider/MemoryProvider.js +3 -3
- package/provider/Provider.d.ts +30 -30
- package/provider/ThroughProvider.d.ts +23 -23
- package/provider/ValidationProvider.d.ts +22 -22
- package/provider/ValidationProvider.js +2 -2
- package/react/useItem.d.ts +4 -4
- package/react/useQuery.d.ts +4 -4
- package/schema/AllowSchema.d.ts +25 -24
- package/schema/AllowSchema.js +25 -29
- package/schema/ArraySchema.d.ts +2 -2
- package/schema/BooleanSchema.d.ts +2 -2
- package/schema/DataSchema.d.ts +2 -2
- package/schema/DataSchema.js +2 -2
- package/schema/DateSchema.d.ts +2 -2
- package/schema/DictionarySchema.d.ts +19 -0
- package/schema/{ObjectSchema.js → DictionarySchema.js} +6 -6
- package/schema/LinkSchema.d.ts +2 -2
- package/schema/NumberSchema.d.ts +2 -2
- package/schema/Schema.d.ts +10 -8
- package/schema/Schema.js +1 -1
- package/schema/StringSchema.d.ts +12 -10
- package/schema/index.d.ts +1 -1
- package/schema/index.js +1 -1
- package/state/ArrayState.js +4 -4
- package/state/DataState.js +3 -3
- package/state/DictionaryState.d.ts +15 -0
- package/state/{ObjectState.js → DictionaryState.js} +6 -6
- package/state/index.d.ts +2 -2
- package/state/index.js +2 -2
- package/test/basics.js +1 -1
- package/update/ArrayUpdate.js +2 -2
- package/update/DataUpdate.d.ts +10 -9
- package/update/DataUpdate.js +6 -4
- package/update/DictionaryUpdate.d.ts +29 -0
- package/update/{ObjectUpdate.js → DictionaryUpdate.js} +14 -14
- package/update/hydrations.js +2 -2
- package/update/index.d.ts +1 -1
- package/update/index.js +1 -1
- package/util/array.d.ts +40 -111
- package/util/array.js +50 -114
- package/util/clone.d.ts +2 -2
- package/util/clone.js +5 -5
- package/util/data.d.ts +20 -53
- package/util/data.js +11 -1
- package/util/dictionary.d.ts +39 -0
- package/util/dictionary.js +33 -0
- package/util/diff.d.ts +3 -3
- package/util/entry.d.ts +7 -5
- package/util/entry.js +8 -6
- package/util/filter.d.ts +0 -5
- package/util/filter.js +0 -3
- package/util/hydrate.d.ts +2 -2
- package/util/hydrate.js +7 -8
- package/util/index.d.ts +1 -0
- package/util/index.js +1 -0
- package/util/map.d.ts +28 -6
- package/util/map.js +22 -6
- package/util/merge.d.ts +3 -6
- package/util/merge.js +4 -6
- package/util/object.d.ts +77 -90
- package/util/object.js +23 -76
- package/util/set.d.ts +10 -0
- package/util/set.js +17 -0
- package/util/template.d.ts +3 -3
- package/util/template.js +3 -3
- package/util/transform.d.ts +22 -45
- package/util/transform.js +20 -37
- package/util/units.d.ts +6 -12
- package/util/units.js +8 -4
- package/util/validate.d.ts +6 -5
- package/util/validate.js +5 -4
- package/schema/ObjectSchema.d.ts +0 -19
- package/state/ObjectState.d.ts +0 -16
- package/update/ObjectUpdate.d.ts +0 -29
package/provider/Provider.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Updates } from "../update/DataUpdate.js";
|
|
2
|
-
import type { Datas,
|
|
2
|
+
import type { Datas, DataKey } from "../util/data.js";
|
|
3
3
|
import type { ItemArray, ItemConstraints, ItemValue } from "../db/Item.js";
|
|
4
4
|
/** Provides access to data (e.g. IndexedDB, Firebase, or in-memory cache providers). */
|
|
5
5
|
declare abstract class AbstractProvider<T extends Datas = Datas> {
|
|
@@ -8,11 +8,11 @@ declare abstract class AbstractProvider<T extends Datas = Datas> {
|
|
|
8
8
|
*
|
|
9
9
|
* @return The item value, or `null` if it doesn't exist.
|
|
10
10
|
*/
|
|
11
|
-
abstract getItem<K extends
|
|
11
|
+
abstract getItem<K extends DataKey<T>>(collection: K, id: string): ItemValue<T[K]> | PromiseLike<ItemValue<T[K]>>;
|
|
12
12
|
/**
|
|
13
13
|
* Subscribe to the value of this item with an async iterator.
|
|
14
14
|
*/
|
|
15
|
-
abstract getItemSequence<K extends
|
|
15
|
+
abstract getItemSequence<K extends DataKey<T>>(collection: K, id: string): AsyncIterable<ItemValue<T[K]>>;
|
|
16
16
|
/**
|
|
17
17
|
* Create a new item with a random ID.
|
|
18
18
|
* - Created item is guaranteed to have a unique ID.
|
|
@@ -20,75 +20,75 @@ declare abstract class AbstractProvider<T extends Datas = Datas> {
|
|
|
20
20
|
* @param data Complete data to set the item to.
|
|
21
21
|
* @return String ID for the created item (possibly promised).
|
|
22
22
|
*/
|
|
23
|
-
abstract addItem<K extends
|
|
23
|
+
abstract addItem<K extends DataKey<T>>(collection: K, data: T[K]): string | PromiseLike<string>;
|
|
24
24
|
/**
|
|
25
25
|
* Set the data a item (whether it exists or not).
|
|
26
26
|
* @param data Data to set the item to.
|
|
27
27
|
*/
|
|
28
|
-
abstract setItem<K extends
|
|
28
|
+
abstract setItem<K extends DataKey<T>>(collection: K, id: string, data: T[K]): void | PromiseLike<void>;
|
|
29
29
|
/**
|
|
30
30
|
* Update the data an existing item.
|
|
31
31
|
*
|
|
32
32
|
* @param updates Set of property updates to apply to the item.
|
|
33
33
|
* @throws Error If the item does not exist (ideally a `RequiredError` but may be provider-specific).
|
|
34
34
|
*/
|
|
35
|
-
abstract updateItem<K extends
|
|
35
|
+
abstract updateItem<K extends DataKey<T>>(collection: K, id: string, updates: Updates<T[K]>): void | PromiseLike<void>;
|
|
36
36
|
/**
|
|
37
37
|
* Delete a specified item.
|
|
38
38
|
*/
|
|
39
|
-
abstract deleteItem<K extends
|
|
39
|
+
abstract deleteItem<K extends DataKey<T>>(collection: K, id: string): void | PromiseLike<void>;
|
|
40
40
|
/**
|
|
41
41
|
* Get all matching items.
|
|
42
42
|
*
|
|
43
43
|
* @return Set of values in `id: data` format.
|
|
44
44
|
*/
|
|
45
|
-
abstract getQuery<K extends
|
|
45
|
+
abstract getQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): ItemArray<T[K]> | PromiseLike<ItemArray<T[K]>>;
|
|
46
46
|
/**
|
|
47
47
|
* Subscribe to all matching items with an async iterator.
|
|
48
48
|
*/
|
|
49
|
-
abstract getQuerySequence<K extends
|
|
49
|
+
abstract getQuerySequence<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): AsyncIterable<ItemArray<T[K]>>;
|
|
50
50
|
/**
|
|
51
51
|
* Set the data of all matching items.
|
|
52
52
|
*
|
|
53
53
|
* @param data Data to set matching items to.
|
|
54
54
|
* @return Number of items that were set.
|
|
55
55
|
*/
|
|
56
|
-
abstract setQuery<K extends
|
|
56
|
+
abstract setQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, data: T[K]): number | PromiseLike<number>;
|
|
57
57
|
/**
|
|
58
58
|
* Update the data of all matching items.
|
|
59
59
|
*
|
|
60
60
|
* @param updates Set of property updates to apply to matching items.
|
|
61
61
|
* @return Number of items that were updated.
|
|
62
62
|
*/
|
|
63
|
-
abstract updateQuery<K extends
|
|
63
|
+
abstract updateQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): number | PromiseLike<number>;
|
|
64
64
|
/**
|
|
65
65
|
* Delete all matching items.
|
|
66
66
|
* @return Number of items that were deleted.
|
|
67
67
|
*/
|
|
68
|
-
abstract deleteQuery<K extends
|
|
68
|
+
abstract deleteQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): number | PromiseLike<number>;
|
|
69
69
|
}
|
|
70
70
|
/** Provider with a fully synchronous interface */
|
|
71
71
|
export declare abstract class Provider<T extends Datas = Datas> extends AbstractProvider<T> {
|
|
72
|
-
abstract getItem<K extends
|
|
73
|
-
abstract addItem<K extends
|
|
74
|
-
abstract setItem<K extends
|
|
75
|
-
abstract updateItem<K extends
|
|
76
|
-
abstract deleteItem<K extends
|
|
77
|
-
abstract getQuery<K extends
|
|
78
|
-
abstract setQuery<K extends
|
|
79
|
-
abstract updateQuery<K extends
|
|
80
|
-
abstract deleteQuery<K extends
|
|
72
|
+
abstract getItem<K extends DataKey<T>>(collection: K, id: string): ItemValue<T[K]>;
|
|
73
|
+
abstract addItem<K extends DataKey<T>>(collection: K, data: T[K]): string;
|
|
74
|
+
abstract setItem<K extends DataKey<T>>(collection: K, id: string, data: T[K]): void;
|
|
75
|
+
abstract updateItem<K extends DataKey<T>>(collection: K, id: string, updates: Updates<T[K]>): void;
|
|
76
|
+
abstract deleteItem<K extends DataKey<T>>(collection: K, id: string): void;
|
|
77
|
+
abstract getQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): ItemArray<T[K]>;
|
|
78
|
+
abstract setQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, data: T[K]): number;
|
|
79
|
+
abstract updateQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): number;
|
|
80
|
+
abstract deleteQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): number;
|
|
81
81
|
}
|
|
82
82
|
/** Provider with a fully asynchronous interface */
|
|
83
83
|
export declare abstract class AsyncProvider<T extends Datas = Datas> extends AbstractProvider<T> {
|
|
84
|
-
abstract getItem<K extends
|
|
85
|
-
abstract addItem<K extends
|
|
86
|
-
abstract setItem<K extends
|
|
87
|
-
abstract updateItem<K extends
|
|
88
|
-
abstract deleteItem<K extends
|
|
89
|
-
abstract getQuery<K extends
|
|
90
|
-
abstract setQuery<K extends
|
|
91
|
-
abstract updateQuery<K extends
|
|
92
|
-
abstract deleteQuery<K extends
|
|
84
|
+
abstract getItem<K extends DataKey<T>>(collection: K, id: string): Promise<ItemValue<T[K]>>;
|
|
85
|
+
abstract addItem<K extends DataKey<T>>(collection: K, data: T[K]): Promise<string>;
|
|
86
|
+
abstract setItem<K extends DataKey<T>>(collection: K, id: string, data: T[K]): Promise<void>;
|
|
87
|
+
abstract updateItem<K extends DataKey<T>>(collection: K, id: string, updates: Updates<T[K]>): Promise<void>;
|
|
88
|
+
abstract deleteItem<K extends DataKey<T>>(collection: K, id: string): Promise<void>;
|
|
89
|
+
abstract getQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<ItemArray<T[K]>>;
|
|
90
|
+
abstract setQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, data: T[K]): Promise<number>;
|
|
91
|
+
abstract updateQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): Promise<number>;
|
|
92
|
+
abstract deleteQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<number>;
|
|
93
93
|
}
|
|
94
94
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Datas,
|
|
1
|
+
import type { Datas, DataKey } from "../util/data.js";
|
|
2
2
|
import type { Sourceable } from "../util/source.js";
|
|
3
3
|
import type { ItemArray, ItemConstraints, ItemValue } from "../db/Item.js";
|
|
4
4
|
import type { Updates } from "../update/DataUpdate.js";
|
|
@@ -7,31 +7,31 @@ import type { Provider, AsyncProvider } from "./Provider.js";
|
|
|
7
7
|
export declare class ThroughProvider<T extends Datas = Datas> implements Provider<T>, Sourceable<Provider<T>> {
|
|
8
8
|
readonly source: Provider<T>;
|
|
9
9
|
constructor(source: Provider<T>);
|
|
10
|
-
getItem<K extends
|
|
11
|
-
getItemSequence<K extends
|
|
12
|
-
addItem<K extends
|
|
13
|
-
setItem<K extends
|
|
14
|
-
updateItem<K extends
|
|
15
|
-
deleteItem<K extends
|
|
16
|
-
getQuery<K extends
|
|
17
|
-
getQuerySequence<K extends
|
|
18
|
-
setQuery<K extends
|
|
19
|
-
updateQuery<K extends
|
|
20
|
-
deleteQuery<K extends
|
|
10
|
+
getItem<K extends DataKey<T>>(collection: K, id: string): ItemValue<T[K]>;
|
|
11
|
+
getItemSequence<K extends DataKey<T>>(collection: K, id: string): AsyncIterable<ItemValue<T[K]>>;
|
|
12
|
+
addItem<K extends DataKey<T>>(collection: K, data: T[K]): string;
|
|
13
|
+
setItem<K extends DataKey<T>>(collection: K, id: string, data: T[K]): void;
|
|
14
|
+
updateItem<K extends DataKey<T>>(collection: K, id: string, update: Updates<T[K]>): void;
|
|
15
|
+
deleteItem<K extends DataKey<T>>(collection: K, id: string): void;
|
|
16
|
+
getQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): ItemArray<T[K]>;
|
|
17
|
+
getQuerySequence<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): AsyncIterable<ItemArray<T[K]>>;
|
|
18
|
+
setQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, data: T[K]): number;
|
|
19
|
+
updateQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, update: Updates<T[K]>): number;
|
|
20
|
+
deleteQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): number;
|
|
21
21
|
}
|
|
22
22
|
/** A provider that passes through to an asynchronous source. */
|
|
23
23
|
export declare class AsyncThroughProvider<T extends Datas = Datas> implements AsyncProvider<T>, Sourceable<AsyncProvider<T>> {
|
|
24
24
|
readonly source: AsyncProvider<T>;
|
|
25
25
|
constructor(source: AsyncProvider<T>);
|
|
26
|
-
getItem<K extends
|
|
27
|
-
getItemSequence<K extends
|
|
28
|
-
addItem<K extends
|
|
29
|
-
setItem<K extends
|
|
30
|
-
updateItem<K extends
|
|
31
|
-
deleteItem<K extends
|
|
32
|
-
getQuery<K extends
|
|
33
|
-
getQuerySequence<K extends
|
|
34
|
-
setQuery<K extends
|
|
35
|
-
updateQuery<K extends
|
|
36
|
-
deleteQuery<K extends
|
|
26
|
+
getItem<K extends DataKey<T>>(collection: K, id: string): Promise<ItemValue<T[K]>>;
|
|
27
|
+
getItemSequence<K extends DataKey<T>>(collection: K, id: string): AsyncIterable<ItemValue<T[K]>>;
|
|
28
|
+
addItem<K extends DataKey<T>>(collection: K, data: T[K]): Promise<string>;
|
|
29
|
+
setItem<K extends DataKey<T>>(collection: K, id: string, data: T[K]): Promise<void>;
|
|
30
|
+
updateItem<K extends DataKey<T>>(collection: K, id: string, updates: Updates<T[K]>): Promise<void>;
|
|
31
|
+
deleteItem<K extends DataKey<T>>(collection: K, id: string): Promise<void>;
|
|
32
|
+
getQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<ItemArray<T[K]>>;
|
|
33
|
+
getQuerySequence<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): AsyncIterable<ItemArray<T[K]>>;
|
|
34
|
+
setQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, data: T[K]): Promise<number>;
|
|
35
|
+
updateQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): Promise<number>;
|
|
36
|
+
deleteQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<number>;
|
|
37
37
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DataKey, Datas } from "../util/data.js";
|
|
2
2
|
import type { ItemArray, ItemValue, ItemConstraints } from "../db/Item.js";
|
|
3
3
|
import type { DataSchemas, DataSchema } from "../schema/DataSchema.js";
|
|
4
4
|
import { Updates } from "../update/DataUpdate.js";
|
|
@@ -9,36 +9,36 @@ declare abstract class BaseValidationProvider<T extends Datas> {
|
|
|
9
9
|
abstract source: Provider | AsyncProvider;
|
|
10
10
|
readonly schemas: DataSchemas<T>;
|
|
11
11
|
constructor(schemas: DataSchemas<T>);
|
|
12
|
-
getSchema<K extends
|
|
13
|
-
getItemSequence<K extends
|
|
14
|
-
getQuerySequence<K extends
|
|
12
|
+
getSchema<K extends DataKey<T>>(collection: K): DataSchema<T[K]>;
|
|
13
|
+
getItemSequence<K extends DataKey<T>>(collection: K, id: string): AsyncIterable<ItemValue<T[K]>>;
|
|
14
|
+
getQuerySequence<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): AsyncIterable<ItemArray<T[K]>>;
|
|
15
15
|
}
|
|
16
16
|
/** Validate a synchronous source provider (source can have any type because validation guarantees the type). */
|
|
17
17
|
export declare class ValidationProvider<T extends Datas> extends BaseValidationProvider<T> implements Provider<T>, Sourceable<Provider> {
|
|
18
18
|
readonly source: Provider;
|
|
19
19
|
constructor(source: Provider, schemas: DataSchemas<T>);
|
|
20
|
-
getItem<K extends
|
|
21
|
-
addItem<K extends
|
|
22
|
-
setItem<K extends
|
|
23
|
-
updateItem<K extends
|
|
24
|
-
deleteItem<K extends
|
|
25
|
-
getQuery<K extends
|
|
26
|
-
setQuery<K extends
|
|
27
|
-
updateQuery<K extends
|
|
28
|
-
deleteQuery<K extends
|
|
20
|
+
getItem<K extends DataKey<T>>(collection: K, id: string): ItemValue<T[K]>;
|
|
21
|
+
addItem<K extends DataKey<T>>(collection: K, data: T[K]): string;
|
|
22
|
+
setItem<K extends DataKey<T>>(collection: K, id: string, value: T[K]): void;
|
|
23
|
+
updateItem<K extends DataKey<T>>(collection: K, id: string, updates: Updates<T[K]>): void;
|
|
24
|
+
deleteItem<K extends DataKey<T>>(collection: K, id: string): void;
|
|
25
|
+
getQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): ItemArray<T[K]>;
|
|
26
|
+
setQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, value: T[K]): number;
|
|
27
|
+
updateQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): number;
|
|
28
|
+
deleteQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): number;
|
|
29
29
|
}
|
|
30
30
|
/** Validate an asynchronous source provider (source can have any type because validation guarantees the type). */
|
|
31
31
|
export declare class AsyncValidationProvider<T extends Datas> extends BaseValidationProvider<T> implements AsyncProvider<T>, Sourceable<AsyncProvider> {
|
|
32
32
|
readonly source: AsyncProvider;
|
|
33
33
|
constructor(source: AsyncProvider, schemas: DataSchemas<T>);
|
|
34
|
-
getItem<K extends
|
|
35
|
-
addItem<K extends
|
|
36
|
-
setItem<K extends
|
|
37
|
-
updateItem<K extends
|
|
38
|
-
deleteItem<K extends
|
|
39
|
-
getQuery<K extends
|
|
40
|
-
setQuery<K extends
|
|
41
|
-
updateQuery<K extends
|
|
42
|
-
deleteQuery<K extends
|
|
34
|
+
getItem<K extends DataKey<T>>(collection: K, id: string): Promise<ItemValue<T[K]>>;
|
|
35
|
+
addItem<K extends DataKey<T>>(collection: K, data: T[K]): Promise<string>;
|
|
36
|
+
setItem<K extends DataKey<T>>(collection: K, id: string, value: T[K]): Promise<void>;
|
|
37
|
+
updateItem<K extends DataKey<T>>(collection: K, id: string, updates: Updates<T[K]>): Promise<void>;
|
|
38
|
+
deleteItem<K extends DataKey<T>>(collection: K, id: string): Promise<void>;
|
|
39
|
+
getQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<ItemArray<T[K]>>;
|
|
40
|
+
setQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, value: T[K]): Promise<number>;
|
|
41
|
+
updateQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): Promise<number>;
|
|
42
|
+
deleteQuery<K extends DataKey<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<number>;
|
|
43
43
|
}
|
|
44
44
|
export {};
|
|
@@ -103,9 +103,9 @@ function _validateItem(collection, unsafeEntity, schema) {
|
|
|
103
103
|
}
|
|
104
104
|
/** Validate a set of entities for this query reference. */
|
|
105
105
|
function _validateItems(collection, unsafeEntities, schema) {
|
|
106
|
-
return Array.from(
|
|
106
|
+
return Array.from(_yieldValidItems(collection, unsafeEntities, schema));
|
|
107
107
|
}
|
|
108
|
-
function*
|
|
108
|
+
function* _yieldValidItems(collection, unsafeEntities, schema) {
|
|
109
109
|
let invalid = false;
|
|
110
110
|
const details = {};
|
|
111
111
|
for (const unsafeEntity of unsafeEntities) {
|
package/react/useItem.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { ItemValue, ItemData, AsyncItem, Item } from "../db/Item.js";
|
|
2
2
|
import type { Dispatch } from "../util/function.js";
|
|
3
|
-
import { Datas,
|
|
3
|
+
import { Datas, DataKey } from "../util/data.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, K extends
|
|
7
|
+
export declare class ItemState<T extends Datas, K extends DataKey<T> = DataKey<T>> extends State<ItemValue<T[K]>> {
|
|
8
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). */
|
|
@@ -24,5 +24,5 @@ export declare class ItemState<T extends Datas, K extends Key<T> = Key<T>> exten
|
|
|
24
24
|
* Use an item in a React component.
|
|
25
25
|
* - Uses the default cache, so will error if not used inside `<Cache>`
|
|
26
26
|
*/
|
|
27
|
-
export declare function useItem<T extends Datas, K extends
|
|
28
|
-
export declare function useItem<T extends Datas, K extends
|
|
27
|
+
export declare function useItem<T extends Datas, K extends DataKey<T>>(ref: Item<T, K> | AsyncItem<T, K>): ItemState<T, K>;
|
|
28
|
+
export declare function useItem<T extends Datas, K extends DataKey<T>>(ref?: Item<T, K> | AsyncItem<T, K>): ItemState<T, K> | undefined;
|
package/react/useQuery.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { Datas,
|
|
1
|
+
import type { Datas, DataKey } from "../util/data.js";
|
|
2
2
|
import type { Stop } from "../util/function.js";
|
|
3
3
|
import type { ItemArray, ItemValue, ItemData } from "../db/Item.js";
|
|
4
4
|
import type { 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, K extends
|
|
8
|
+
export declare class QueryState<T extends Datas, K extends DataKey<T> = DataKey<T>> extends State<ItemArray<T[K]>> implements Iterable<ItemData<T[K]>> {
|
|
9
9
|
readonly ref: Query<T, K> | AsyncQuery<T, K>;
|
|
10
10
|
readonly busy: BooleanState;
|
|
11
11
|
readonly limit: number;
|
|
@@ -45,5 +45,5 @@ export declare class QueryState<T extends Datas, K extends Key<T> = Key<T>> exte
|
|
|
45
45
|
* Use a query in a React component.
|
|
46
46
|
* - Uses the default cache, so will error if not used inside `<Cache>`
|
|
47
47
|
*/
|
|
48
|
-
export declare function useQuery<T extends Datas, K extends
|
|
49
|
-
export declare function useQuery<T extends Datas, K extends
|
|
48
|
+
export declare function useQuery<T extends Datas, K extends DataKey<T>>(ref: Query<T, K> | AsyncQuery<T, K>): QueryState<T, K>;
|
|
49
|
+
export declare function useQuery<T extends Datas, K extends DataKey<T>>(ref?: Query<T, K> | AsyncQuery<T, K>): QueryState<T, K> | undefined;
|
package/schema/AllowSchema.d.ts
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { Entry } from "../util/entry.js";
|
|
2
|
+
import { ImmutableRequiredMap, PossibleMap, PossibleStringMap } from "../util/map.js";
|
|
3
|
+
import { Schema, SchemaOptions } from "./Schema.js";
|
|
4
|
+
/** Options for an `AllowSchema` instance. */
|
|
5
|
+
declare type AllowSchemaOptions<K, T> = SchemaOptions & {
|
|
6
|
+
allow: PossibleMap<K, T>;
|
|
7
|
+
value?: K | null;
|
|
5
8
|
};
|
|
6
|
-
/** Validate a value against a specific set of allowed values. */
|
|
7
|
-
export declare function validateAllowed<T extends string | number>(value: unknown, allowed: Allowed<T>): T;
|
|
8
9
|
/** Define a valid value from an allowed set of values. */
|
|
9
|
-
export declare
|
|
10
|
-
readonly value:
|
|
11
|
-
readonly allow:
|
|
12
|
-
constructor({ allow, value, ...options }:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
/** Define a valid string from an allowed set of strings. */
|
|
18
|
-
export declare class AllowStringSchema<T extends string> extends AllowSchema<T> {
|
|
19
|
-
validate(unsafeValue?: unknown): T;
|
|
10
|
+
export declare class AllowSchema<K, T> extends Schema<K> implements Iterable<Entry<K, T>> {
|
|
11
|
+
readonly value: K | null;
|
|
12
|
+
readonly allow: ImmutableRequiredMap<K, T>;
|
|
13
|
+
constructor({ allow, value, ...options }: AllowSchemaOptions<K, T>);
|
|
14
|
+
validate(value?: unknown): K;
|
|
15
|
+
/** Iterate over the the allowed options in `[key, value]` format. */
|
|
16
|
+
[Symbol.iterator](): Iterator<Entry<K, T>>;
|
|
20
17
|
}
|
|
21
|
-
/** Define a valid
|
|
22
|
-
export declare class
|
|
23
|
-
|
|
18
|
+
/** Define a valid string value from an allowed set of values. */
|
|
19
|
+
export declare class AllowStringSchema<K extends string, T> extends AllowSchema<K, T> {
|
|
20
|
+
constructor({ allow, ...options }: SchemaOptions & {
|
|
21
|
+
allow: PossibleStringMap<K, T>;
|
|
22
|
+
});
|
|
23
|
+
validator(value?: unknown): K;
|
|
24
24
|
}
|
|
25
|
-
/** Valid
|
|
26
|
-
export declare
|
|
27
|
-
/** Valid string from an allowed set of
|
|
28
|
-
export declare
|
|
25
|
+
/** Valid value from an allowed set of values. */
|
|
26
|
+
export declare function ALLOW<K, T>(allow: PossibleMap<K, T>): AllowSchema<K, T>;
|
|
27
|
+
/** Valid string from an allowed set of values. */
|
|
28
|
+
export declare function ALLOW_STRING<K extends string, T>(allow: PossibleStringMap<K, T>): AllowSchema<K, T>;
|
|
29
|
+
export {};
|
package/schema/AllowSchema.js
CHANGED
|
@@ -1,42 +1,38 @@
|
|
|
1
|
-
import { InvalidFeedback } from "../feedback/InvalidFeedback.js";
|
|
2
1
|
import { getString } from "../util/string.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { isProp } from "../util/object.js";
|
|
2
|
+
import { getRequiredMap, isMapKey } from "../util/map.js";
|
|
3
|
+
import { InvalidFeedback } from "../feedback/InvalidFeedback.js";
|
|
6
4
|
import { Schema } from "./Schema.js";
|
|
7
|
-
/** Validate a value against a specific set of allowed values. */
|
|
8
|
-
export function validateAllowed(value, allowed) {
|
|
9
|
-
if (isArray(allowed)) {
|
|
10
|
-
if (isItem(allowed, value))
|
|
11
|
-
return value;
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
if (isProp(allowed, value))
|
|
15
|
-
return value;
|
|
16
|
-
}
|
|
17
|
-
throw new InvalidFeedback("Unknown value", { value });
|
|
18
|
-
}
|
|
19
5
|
/** Define a valid value from an allowed set of values. */
|
|
20
6
|
export class AllowSchema extends Schema {
|
|
21
7
|
constructor({ allow, value = null, ...options }) {
|
|
22
8
|
super(options);
|
|
23
|
-
this.allow = allow;
|
|
9
|
+
this.allow = getRequiredMap(allow);
|
|
24
10
|
this.value = value;
|
|
25
11
|
}
|
|
12
|
+
validate(value = this.value) {
|
|
13
|
+
if (isMapKey(this.allow, value))
|
|
14
|
+
return value;
|
|
15
|
+
throw new InvalidFeedback("Unknown value", { value });
|
|
16
|
+
}
|
|
17
|
+
/** Iterate over the the allowed options in `[key, value]` format. */
|
|
18
|
+
[Symbol.iterator]() {
|
|
19
|
+
return this.allow[Symbol.iterator]();
|
|
20
|
+
}
|
|
26
21
|
}
|
|
27
|
-
/** Define a valid string from an allowed set of
|
|
22
|
+
/** Define a valid string value from an allowed set of values. */
|
|
28
23
|
export class AllowStringSchema extends AllowSchema {
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
constructor({ allow, ...options }) {
|
|
25
|
+
super({ allow: getRequiredMap(allow), ...options });
|
|
31
26
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
export class AllowNumberSchema extends AllowSchema {
|
|
35
|
-
validate(unsafeValue = this.value) {
|
|
36
|
-
return validateAllowed(getOptionalNumber(unsafeValue), this.allow);
|
|
27
|
+
validator(value = this.value) {
|
|
28
|
+
return super.validate(getString(value));
|
|
37
29
|
}
|
|
38
30
|
}
|
|
39
|
-
/** Valid
|
|
40
|
-
export
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
/** Valid value from an allowed set of values. */
|
|
32
|
+
export function ALLOW(allow) {
|
|
33
|
+
return new AllowSchema({ allow });
|
|
34
|
+
}
|
|
35
|
+
/** Valid string from an allowed set of values. */
|
|
36
|
+
export function ALLOW_STRING(allow) {
|
|
37
|
+
return new AllowStringSchema({ allow });
|
|
38
|
+
}
|
package/schema/ArraySchema.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ImmutableArray } from "../util/array.js";
|
|
2
2
|
import { Validator } from "../util/validate.js";
|
|
3
|
-
import { Schema } from "./Schema.js";
|
|
3
|
+
import { Schema, SchemaOptions } from "./Schema.js";
|
|
4
4
|
/**
|
|
5
5
|
* Define a valid array.
|
|
6
6
|
*
|
|
@@ -34,7 +34,7 @@ export declare class ArraySchema<T> extends Schema<ImmutableArray<T>> {
|
|
|
34
34
|
readonly unique: boolean;
|
|
35
35
|
readonly min: number;
|
|
36
36
|
readonly max: number | null;
|
|
37
|
-
constructor({ value, items, unique, min, max, ...options }:
|
|
37
|
+
constructor({ value, items, unique, min, max, ...options }: SchemaOptions & {
|
|
38
38
|
readonly value?: ImmutableArray;
|
|
39
39
|
readonly items: Validator<T>;
|
|
40
40
|
readonly min?: number;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Schema } from "./Schema.js";
|
|
1
|
+
import { Schema, SchemaOptions } from "./Schema.js";
|
|
2
2
|
/** Define a valid boolean. */
|
|
3
3
|
export declare class BooleanSchema extends Schema<boolean> {
|
|
4
4
|
readonly value: boolean;
|
|
5
|
-
constructor({ value, ...options }:
|
|
5
|
+
constructor({ value, ...options }: SchemaOptions & {
|
|
6
6
|
readonly value?: boolean;
|
|
7
7
|
});
|
|
8
8
|
validate(unsafeValue?: unknown): boolean;
|
package/schema/DataSchema.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
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
|
-
import { Schema } from "./Schema.js";
|
|
4
|
+
import { Schema, SchemaOptions } from "./Schema.js";
|
|
5
5
|
/** Validate a data object. */
|
|
6
6
|
export declare class DataSchema<T extends Data> extends Schema<T> {
|
|
7
7
|
readonly value: Partial<T>;
|
|
8
8
|
readonly props: Validators<T>;
|
|
9
|
-
constructor({ value, props, ...options }:
|
|
9
|
+
constructor({ value, props, ...options }: SchemaOptions & {
|
|
10
10
|
readonly props: Validators<T>;
|
|
11
11
|
readonly value?: Partial<T>;
|
|
12
12
|
});
|
package/schema/DataSchema.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { InvalidFeedback } from "../feedback/InvalidFeedback.js";
|
|
2
2
|
import { validateData } from "../util/validate.js";
|
|
3
|
-
import {
|
|
3
|
+
import { isData } from "../util/data.js";
|
|
4
4
|
import { OPTIONAL } from "./OptionalSchema.js";
|
|
5
5
|
import { Schema } from "./Schema.js";
|
|
6
6
|
/** Validate a data object. */
|
|
@@ -11,7 +11,7 @@ export class DataSchema extends Schema {
|
|
|
11
11
|
this.value = value;
|
|
12
12
|
}
|
|
13
13
|
validate(unsafeValue = this.value) {
|
|
14
|
-
if (!
|
|
14
|
+
if (!isData(unsafeValue))
|
|
15
15
|
throw new InvalidFeedback("Must be object", { value: unsafeValue });
|
|
16
16
|
return validateData(unsafeValue, this.props);
|
|
17
17
|
}
|
package/schema/DateSchema.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { PossibleDate } from "../util/date.js";
|
|
2
|
-
import { Schema } from "./Schema.js";
|
|
2
|
+
import { Schema, SchemaOptions } from "./Schema.js";
|
|
3
3
|
/** Define a valid date, e.g. `2005-09-12` */
|
|
4
4
|
export declare class DateSchema extends Schema<string> {
|
|
5
5
|
readonly value: PossibleDate;
|
|
6
6
|
readonly min: PossibleDate | null;
|
|
7
7
|
readonly max: PossibleDate | null;
|
|
8
|
-
constructor({ value, min, max, ...options }:
|
|
8
|
+
constructor({ value, min, max, ...options }: SchemaOptions & {
|
|
9
9
|
readonly value?: PossibleDate;
|
|
10
10
|
readonly min?: PossibleDate | null;
|
|
11
11
|
readonly max?: PossibleDate | null;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ImmutableDictionary } from "../util/dictionary.js";
|
|
2
|
+
import { Validator } from "../util/validate.js";
|
|
3
|
+
import { Schema, SchemaOptions } from "./Schema.js";
|
|
4
|
+
/** Validate a dictionary object (whose props are all the same with string keys). */
|
|
5
|
+
export declare class DictionarySchema<T> extends Schema<ImmutableDictionary<T>> {
|
|
6
|
+
readonly value: ImmutableDictionary;
|
|
7
|
+
readonly items: Validator<T>;
|
|
8
|
+
readonly min: number | null;
|
|
9
|
+
readonly max: number | null;
|
|
10
|
+
constructor({ value, items, min, max, ...rest }: SchemaOptions & {
|
|
11
|
+
readonly items: Validator<T>;
|
|
12
|
+
readonly value?: ImmutableDictionary;
|
|
13
|
+
readonly min?: number | null;
|
|
14
|
+
readonly max?: number | null;
|
|
15
|
+
});
|
|
16
|
+
validate(unsafeValue?: unknown): ImmutableDictionary<T>;
|
|
17
|
+
}
|
|
18
|
+
/** Valid dictionary object with specifed items. */
|
|
19
|
+
export declare const DICTIONARY: <T>(items: Validator<T>) => DictionarySchema<T>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isDictionary } from "../util/dictionary.js";
|
|
2
2
|
import { validateEntries } from "../util/validate.js";
|
|
3
3
|
import { InvalidFeedback } from "../feedback/InvalidFeedback.js";
|
|
4
4
|
import { Schema } from "./Schema.js";
|
|
5
|
-
/** Validate a
|
|
6
|
-
export class
|
|
5
|
+
/** Validate a dictionary object (whose props are all the same with string keys). */
|
|
6
|
+
export class DictionarySchema extends Schema {
|
|
7
7
|
constructor({ value = {}, items, min = null, max = null, ...rest }) {
|
|
8
8
|
super(rest);
|
|
9
9
|
this.min = null;
|
|
@@ -14,7 +14,7 @@ export class ObjectSchema extends Schema {
|
|
|
14
14
|
this.max = max;
|
|
15
15
|
}
|
|
16
16
|
validate(unsafeValue = this.value) {
|
|
17
|
-
if (!
|
|
17
|
+
if (!isDictionary(unsafeValue))
|
|
18
18
|
throw new InvalidFeedback("Must be object", { value: unsafeValue });
|
|
19
19
|
const unsafeEntries = Object.entries(unsafeValue);
|
|
20
20
|
const safeObject = Object.fromEntries(validateEntries(unsafeEntries, this.items));
|
|
@@ -25,5 +25,5 @@ export class ObjectSchema extends Schema {
|
|
|
25
25
|
return safeObject;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
/** Valid
|
|
29
|
-
export const
|
|
28
|
+
/** Valid dictionary object with specifed items. */
|
|
29
|
+
export const DICTIONARY = (items) => new DictionarySchema({ items });
|
package/schema/LinkSchema.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StringSchema } from "./StringSchema.js";
|
|
1
|
+
import { StringSchema, StringSchemaOptions } from "./StringSchema.js";
|
|
2
2
|
/**
|
|
3
3
|
* Type of `StringSchema` that defines a valid URL.
|
|
4
4
|
* - Checks URL scheme against a whitelist (always), and checks URL domain against a whitelist (optional).
|
|
@@ -11,7 +11,7 @@ export declare class LinkSchema extends StringSchema {
|
|
|
11
11
|
readonly max = 512;
|
|
12
12
|
readonly schemes: string[];
|
|
13
13
|
readonly hosts: string[] | null;
|
|
14
|
-
constructor({ schemes, hosts, ...rest }:
|
|
14
|
+
constructor({ schemes, hosts, ...rest }: StringSchemaOptions & {
|
|
15
15
|
readonly schemes?: string[];
|
|
16
16
|
readonly hosts?: string[] | null;
|
|
17
17
|
});
|
package/schema/NumberSchema.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Schema } from "./Schema.js";
|
|
1
|
+
import { Schema, SchemaOptions } from "./Schema.js";
|
|
2
2
|
/** Schema that defines a valid number. */
|
|
3
3
|
export declare class NumberSchema extends Schema<number> {
|
|
4
4
|
readonly value: number | null;
|
|
5
5
|
readonly min: number | null;
|
|
6
6
|
readonly max: number | null;
|
|
7
7
|
readonly step: number | null;
|
|
8
|
-
constructor({ value, min, max, step, ...rest }:
|
|
8
|
+
constructor({ value, min, max, step, ...rest }: SchemaOptions & {
|
|
9
9
|
readonly value?: number | null;
|
|
10
10
|
readonly min?: number | null;
|
|
11
11
|
readonly max?: number | null;
|