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.
Files changed (91) hide show
  1. package/constraint/Constraints.js +3 -3
  2. package/constraint/FilterConstraint.d.ts +5 -5
  3. package/constraint/SortConstraint.d.ts +2 -2
  4. package/db/Change.d.ts +12 -12
  5. package/db/Collection.d.ts +4 -4
  6. package/db/Database.d.ts +29 -29
  7. package/db/Item.d.ts +4 -4
  8. package/db/Query.d.ts +4 -4
  9. package/feedback/Feedback.d.ts +2 -2
  10. package/feedback/Feedback.js +3 -2
  11. package/firestore/client/FirestoreClientProvider.js +2 -2
  12. package/firestore/lite/FirestoreLiteProvider.js +2 -2
  13. package/firestore/server/FirestoreServerProvider.js +2 -2
  14. package/package.json +1 -1
  15. package/provider/CacheProvider.d.ts +12 -12
  16. package/provider/DebugProvider.d.ts +21 -21
  17. package/provider/MemoryProvider.d.ts +16 -16
  18. package/provider/MemoryProvider.js +3 -3
  19. package/provider/Provider.d.ts +30 -30
  20. package/provider/ThroughProvider.d.ts +23 -23
  21. package/provider/ValidationProvider.d.ts +22 -22
  22. package/provider/ValidationProvider.js +2 -2
  23. package/react/useItem.d.ts +4 -4
  24. package/react/useQuery.d.ts +4 -4
  25. package/schema/AllowSchema.d.ts +25 -24
  26. package/schema/AllowSchema.js +25 -29
  27. package/schema/ArraySchema.d.ts +2 -2
  28. package/schema/BooleanSchema.d.ts +2 -2
  29. package/schema/DataSchema.d.ts +2 -2
  30. package/schema/DataSchema.js +2 -2
  31. package/schema/DateSchema.d.ts +2 -2
  32. package/schema/DictionarySchema.d.ts +19 -0
  33. package/schema/{ObjectSchema.js → DictionarySchema.js} +6 -6
  34. package/schema/LinkSchema.d.ts +2 -2
  35. package/schema/NumberSchema.d.ts +2 -2
  36. package/schema/Schema.d.ts +10 -8
  37. package/schema/Schema.js +1 -1
  38. package/schema/StringSchema.d.ts +12 -10
  39. package/schema/index.d.ts +1 -1
  40. package/schema/index.js +1 -1
  41. package/state/ArrayState.js +4 -4
  42. package/state/DataState.js +3 -3
  43. package/state/DictionaryState.d.ts +15 -0
  44. package/state/{ObjectState.js → DictionaryState.js} +6 -6
  45. package/state/index.d.ts +2 -2
  46. package/state/index.js +2 -2
  47. package/test/basics.js +1 -1
  48. package/update/ArrayUpdate.js +2 -2
  49. package/update/DataUpdate.d.ts +10 -9
  50. package/update/DataUpdate.js +6 -4
  51. package/update/DictionaryUpdate.d.ts +29 -0
  52. package/update/{ObjectUpdate.js → DictionaryUpdate.js} +14 -14
  53. package/update/hydrations.js +2 -2
  54. package/update/index.d.ts +1 -1
  55. package/update/index.js +1 -1
  56. package/util/array.d.ts +40 -111
  57. package/util/array.js +50 -114
  58. package/util/clone.d.ts +2 -2
  59. package/util/clone.js +5 -5
  60. package/util/data.d.ts +20 -53
  61. package/util/data.js +11 -1
  62. package/util/dictionary.d.ts +39 -0
  63. package/util/dictionary.js +33 -0
  64. package/util/diff.d.ts +3 -3
  65. package/util/entry.d.ts +7 -5
  66. package/util/entry.js +8 -6
  67. package/util/filter.d.ts +0 -5
  68. package/util/filter.js +0 -3
  69. package/util/hydrate.d.ts +2 -2
  70. package/util/hydrate.js +7 -8
  71. package/util/index.d.ts +1 -0
  72. package/util/index.js +1 -0
  73. package/util/map.d.ts +28 -6
  74. package/util/map.js +22 -6
  75. package/util/merge.d.ts +3 -6
  76. package/util/merge.js +4 -6
  77. package/util/object.d.ts +77 -90
  78. package/util/object.js +23 -76
  79. package/util/set.d.ts +10 -0
  80. package/util/set.js +17 -0
  81. package/util/template.d.ts +3 -3
  82. package/util/template.js +3 -3
  83. package/util/transform.d.ts +22 -45
  84. package/util/transform.js +20 -37
  85. package/util/units.d.ts +6 -12
  86. package/util/units.js +8 -4
  87. package/util/validate.d.ts +6 -5
  88. package/util/validate.js +5 -4
  89. package/schema/ObjectSchema.d.ts +0 -19
  90. package/state/ObjectState.d.ts +0 -16
  91. package/update/ObjectUpdate.d.ts +0 -29
@@ -1,5 +1,5 @@
1
1
  import type { Updates } from "../update/DataUpdate.js";
2
- import type { Datas, Key } from "../util/data.js";
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 Key<T>>(collection: K, id: string): ItemValue<T[K]> | PromiseLike<ItemValue<T[K]>>;
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 Key<T>>(collection: K, id: string): AsyncIterable<ItemValue<T[K]>>;
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 Key<T>>(collection: K, data: T[K]): string | PromiseLike<string>;
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 Key<T>>(collection: K, id: string, data: T[K]): void | PromiseLike<void>;
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 Key<T>>(collection: K, id: string, updates: Updates<T[K]>): void | PromiseLike<void>;
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 Key<T>>(collection: K, id: string): void | PromiseLike<void>;
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 Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): ItemArray<T[K]> | PromiseLike<ItemArray<T[K]>>;
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 Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): AsyncIterable<ItemArray<T[K]>>;
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 Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, data: T[K]): number | PromiseLike<number>;
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 Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): number | PromiseLike<number>;
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 Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): number | PromiseLike<number>;
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 Key<T>>(collection: K, id: string): ItemValue<T[K]>;
73
- abstract addItem<K extends Key<T>>(collection: K, data: T[K]): string;
74
- abstract setItem<K extends Key<T>>(collection: K, id: string, data: T[K]): void;
75
- abstract updateItem<K extends Key<T>>(collection: K, id: string, updates: Updates<T[K]>): void;
76
- abstract deleteItem<K extends Key<T>>(collection: K, id: string): void;
77
- abstract getQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): ItemArray<T[K]>;
78
- abstract setQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, data: T[K]): number;
79
- abstract updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): number;
80
- abstract deleteQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): number;
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 Key<T>>(collection: K, id: string): Promise<ItemValue<T[K]>>;
85
- abstract addItem<K extends Key<T>>(collection: K, data: T[K]): Promise<string>;
86
- abstract setItem<K extends Key<T>>(collection: K, id: string, data: T[K]): Promise<void>;
87
- abstract updateItem<K extends Key<T>>(collection: K, id: string, updates: Updates<T[K]>): Promise<void>;
88
- abstract deleteItem<K extends Key<T>>(collection: K, id: string): Promise<void>;
89
- abstract getQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<ItemArray<T[K]>>;
90
- abstract setQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, data: T[K]): Promise<number>;
91
- abstract updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): Promise<number>;
92
- abstract deleteQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<number>;
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, Key } from "../util/data.js";
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 Key<T>>(collection: K, id: string): ItemValue<T[K]>;
11
- getItemSequence<K extends Key<T>>(collection: K, id: string): AsyncIterable<ItemValue<T[K]>>;
12
- addItem<K extends Key<T>>(collection: K, data: T[K]): string;
13
- setItem<K extends Key<T>>(collection: K, id: string, data: T[K]): void;
14
- updateItem<K extends Key<T>>(collection: K, id: string, update: Updates<T[K]>): void;
15
- deleteItem<K extends Key<T>>(collection: K, id: string): void;
16
- getQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): ItemArray<T[K]>;
17
- getQuerySequence<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): AsyncIterable<ItemArray<T[K]>>;
18
- setQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, data: T[K]): number;
19
- updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, update: Updates<T[K]>): number;
20
- deleteQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): number;
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 Key<T>>(collection: K, id: string): Promise<ItemValue<T[K]>>;
27
- getItemSequence<K extends Key<T>>(collection: K, id: string): AsyncIterable<ItemValue<T[K]>>;
28
- addItem<K extends Key<T>>(collection: K, data: T[K]): Promise<string>;
29
- setItem<K extends Key<T>>(collection: K, id: string, data: T[K]): Promise<void>;
30
- updateItem<K extends Key<T>>(collection: K, id: string, updates: Updates<T[K]>): Promise<void>;
31
- deleteItem<K extends Key<T>>(collection: K, id: string): Promise<void>;
32
- getQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<ItemArray<T[K]>>;
33
- getQuerySequence<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): AsyncIterable<ItemArray<T[K]>>;
34
- setQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, data: T[K]): Promise<number>;
35
- updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): Promise<number>;
36
- deleteQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<number>;
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 { Key, Datas } from "../util/data.js";
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 Key<T>>(collection: K): DataSchema<T[K]>;
13
- getItemSequence<K extends Key<T>>(collection: K, id: string): AsyncIterable<ItemValue<T[K]>>;
14
- getQuerySequence<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): AsyncIterable<ItemArray<T[K]>>;
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 Key<T>>(collection: K, id: string): ItemValue<T[K]>;
21
- addItem<K extends Key<T>>(collection: K, data: T[K]): string;
22
- setItem<K extends Key<T>>(collection: K, id: string, value: T[K]): void;
23
- updateItem<K extends Key<T>>(collection: K, id: string, updates: Updates<T[K]>): void;
24
- deleteItem<K extends Key<T>>(collection: K, id: string): void;
25
- getQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): ItemArray<T[K]>;
26
- setQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, value: T[K]): number;
27
- updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): number;
28
- deleteQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): number;
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 Key<T>>(collection: K, id: string): Promise<ItemValue<T[K]>>;
35
- addItem<K extends Key<T>>(collection: K, data: T[K]): Promise<string>;
36
- setItem<K extends Key<T>>(collection: K, id: string, value: T[K]): Promise<void>;
37
- updateItem<K extends Key<T>>(collection: K, id: string, updates: Updates<T[K]>): Promise<void>;
38
- deleteItem<K extends Key<T>>(collection: K, id: string): Promise<void>;
39
- getQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<ItemArray<T[K]>>;
40
- setQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, value: T[K]): Promise<number>;
41
- updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): Promise<number>;
42
- deleteQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<number>;
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(_yieldItems(collection, unsafeEntities, schema));
106
+ return Array.from(_yieldValidItems(collection, unsafeEntities, schema));
107
107
  }
108
- function* _yieldItems(collection, unsafeEntities, schema) {
108
+ function* _yieldValidItems(collection, unsafeEntities, schema) {
109
109
  let invalid = false;
110
110
  const details = {};
111
111
  for (const unsafeEntity of unsafeEntities) {
@@ -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, Key } from "../util/data.js";
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 Key<T> = Key<T>> extends State<ItemValue<T[K]>> {
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 Key<T>>(ref: Item<T, K> | AsyncItem<T, K>): ItemState<T, K>;
28
- export declare function useItem<T extends Datas, K extends Key<T>>(ref?: Item<T, K> | AsyncItem<T, K>): ItemState<T, K> | undefined;
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;
@@ -1,11 +1,11 @@
1
- import type { Datas, Key } from "../util/data.js";
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 Key<T> = Key<T>> extends State<ItemArray<T[K]>> implements Iterable<ItemData<T[K]>> {
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 Key<T>>(ref: Query<T, K> | AsyncQuery<T, K>): QueryState<T, K>;
49
- export declare function useQuery<T extends Datas, K extends Key<T>>(ref?: Query<T, K> | AsyncQuery<T, K>): QueryState<T, K> | undefined;
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;
@@ -1,28 +1,29 @@
1
- import { Schema } from "./Schema.js";
2
- /** Specify a specific list of allowed values. */
3
- export declare type Allowed<T extends string | number> = ReadonlyArray<T> | {
4
- readonly [K in T]: unknown;
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 abstract class AllowSchema<T extends string | number> extends Schema<T> {
10
- readonly value: T | null;
11
- readonly allow: Allowed<T>;
12
- constructor({ allow, value, ...options }: ConstructorParameters<typeof Schema>[0] & {
13
- allow: Allowed<T>;
14
- value?: T | null;
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 number from an allowed set of numbers. */
22
- export declare class AllowNumberSchema<T extends number> extends AllowSchema<T> {
23
- validate(unsafeValue?: unknown): T;
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 string from an allowed set of strings. */
26
- export declare const ALLOW_STRING: <T extends string>(allow: Allowed<T>) => AllowStringSchema<T>;
27
- /** Valid string from an allowed set of numbers. */
28
- export declare const ALLOW_NUMBER: <T extends number>(allow: Allowed<T>) => AllowNumberSchema<T>;
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 {};
@@ -1,42 +1,38 @@
1
- import { InvalidFeedback } from "../feedback/InvalidFeedback.js";
2
1
  import { getString } from "../util/string.js";
3
- import { isArray, isItem } from "../util/array.js";
4
- import { getOptionalNumber } from "../util/number.js";
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 strings. */
22
+ /** Define a valid string value from an allowed set of values. */
28
23
  export class AllowStringSchema extends AllowSchema {
29
- validate(unsafeValue = this.value) {
30
- return validateAllowed(getString(unsafeValue), this.allow);
24
+ constructor({ allow, ...options }) {
25
+ super({ allow: getRequiredMap(allow), ...options });
31
26
  }
32
- }
33
- /** Define a valid number from an allowed set of numbers. */
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 string from an allowed set of strings. */
40
- export const ALLOW_STRING = (allow) => new AllowStringSchema({ allow });
41
- /** Valid string from an allowed set of numbers. */
42
- export const ALLOW_NUMBER = (allow) => new AllowNumberSchema({ allow });
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
+ }
@@ -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 }: ConstructorParameters<typeof Schema>[0] & {
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 }: ConstructorParameters<typeof Schema>[0] & {
5
+ constructor({ value, ...options }: SchemaOptions & {
6
6
  readonly value?: boolean;
7
7
  });
8
8
  validate(unsafeValue?: unknown): boolean;
@@ -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 }: ConstructorParameters<typeof Schema>[0] & {
9
+ constructor({ value, props, ...options }: SchemaOptions & {
10
10
  readonly props: Validators<T>;
11
11
  readonly value?: Partial<T>;
12
12
  });
@@ -1,6 +1,6 @@
1
1
  import { InvalidFeedback } from "../feedback/InvalidFeedback.js";
2
2
  import { validateData } from "../util/validate.js";
3
- import { isObject } from "../util/object.js";
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 (!isObject(unsafeValue))
14
+ if (!isData(unsafeValue))
15
15
  throw new InvalidFeedback("Must be object", { value: unsafeValue });
16
16
  return validateData(unsafeValue, this.props);
17
17
  }
@@ -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 }: ConstructorParameters<typeof Schema>[0] & {
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 { isObject } from "../util/object.js";
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 map-like object (whose props are all the same). */
6
- export class ObjectSchema extends Schema {
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 (!isObject(unsafeValue))
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 map-like object with specifed items. */
29
- export const OBJECT = (items) => new ObjectSchema({ items });
28
+ /** Valid dictionary object with specifed items. */
29
+ export const DICTIONARY = (items) => new DictionarySchema({ items });
@@ -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 }: ConstructorParameters<typeof StringSchema>[0] & {
14
+ constructor({ schemes, hosts, ...rest }: StringSchemaOptions & {
15
15
  readonly schemes?: string[];
16
16
  readonly hosts?: string[] | null;
17
17
  });
@@ -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 }: ConstructorParameters<typeof Schema>[0] & {
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;