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.
Files changed (42) hide show
  1. package/constraint/Constraints.d.ts +1 -1
  2. package/constraint/FilterConstraint.d.ts +6 -6
  3. package/constraint/FilterConstraint.js +1 -1
  4. package/constraint/FilterConstraints.d.ts +5 -5
  5. package/constraint/QueryConstraints.d.ts +4 -4
  6. package/constraint/QueryConstraints.js +2 -2
  7. package/constraint/SortConstraint.d.ts +4 -3
  8. package/constraint/SortConstraint.js +2 -3
  9. package/constraint/SortConstraints.d.ts +5 -5
  10. package/db/Change.d.ts +10 -13
  11. package/db/Change.js +2 -2
  12. package/db/Collection.d.ts +3 -3
  13. package/db/Database.d.ts +12 -12
  14. package/db/Item.d.ts +5 -5
  15. package/db/Item.js +3 -5
  16. package/db/Query.d.ts +6 -6
  17. package/db/Query.js +2 -3
  18. package/firestore/client/FirestoreClientProvider.d.ts +3 -3
  19. package/firestore/client/FirestoreClientProvider.js +4 -4
  20. package/firestore/lite/FirestoreLiteProvider.d.ts +3 -3
  21. package/firestore/lite/FirestoreLiteProvider.js +4 -4
  22. package/firestore/server/FirestoreServerProvider.d.ts +3 -3
  23. package/firestore/server/FirestoreServerProvider.js +4 -4
  24. package/package.json +5 -5
  25. package/provider/CacheProvider.d.ts +3 -3
  26. package/provider/CacheProvider.js +6 -6
  27. package/provider/DebugProvider.d.ts +5 -5
  28. package/provider/DebugProvider.js +12 -12
  29. package/provider/MemoryProvider.d.ts +5 -5
  30. package/provider/MemoryProvider.js +9 -8
  31. package/provider/Provider.d.ts +7 -7
  32. package/provider/ThroughProvider.d.ts +5 -5
  33. package/provider/ThroughProvider.js +4 -4
  34. package/provider/ValidationProvider.d.ts +11 -11
  35. package/provider/ValidationProvider.js +29 -28
  36. package/react/useItem.d.ts +7 -7
  37. package/react/useQuery.d.ts +10 -10
  38. package/schema/DataSchema.d.ts +5 -1
  39. package/state/DataState.d.ts +3 -3
  40. package/update/DataUpdate.d.ts +15 -7
  41. package/update/DataUpdate.js +28 -21
  42. package/util/transform.d.ts +3 -3
@@ -101,11 +101,11 @@ export class FirestoreServerProvider {
101
101
  async setItem(collection, id, data) {
102
102
  await this._firestore.collection(collection).doc(id).set(data);
103
103
  }
104
- async updateItem(collection, id, update) {
104
+ async updateItem(collection, id, updates) {
105
105
  await this._firestore
106
106
  .collection(collection)
107
107
  .doc(id)
108
- .update(..._getFieldValues(update));
108
+ .update(..._getFieldValues(Object.entries(updates)));
109
109
  }
110
110
  async deleteItem(collection, id) {
111
111
  await this._firestore.collection(collection).doc(id).delete();
@@ -119,8 +119,8 @@ export class FirestoreServerProvider {
119
119
  async setQuery(collection, constraints, data) {
120
120
  return await bulkWrite(this._firestore, collection, constraints, (w, s) => void w.set(s.ref, data));
121
121
  }
122
- async updateQuery(collection, constraints, update) {
123
- const fieldValues = _getFieldValues(update);
122
+ async updateQuery(collection, constraints, updates) {
123
+ const fieldValues = _getFieldValues(Object.entries(updates));
124
124
  return await bulkWrite(this._firestore, collection, constraints, (w, s) => void w.update(s.ref, ...fieldValues));
125
125
  }
126
126
  async deleteQuery(collection, constraints) {
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "state-management",
12
12
  "query-builder"
13
13
  ],
14
- "version": "1.76.1",
14
+ "version": "1.78.0",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -63,12 +63,12 @@
63
63
  "devDependencies": {
64
64
  "@google-cloud/firestore": "^5.0.2",
65
65
  "@types/jest": "^28.1.6",
66
- "@types/react": "^18.0.9",
66
+ "@types/react": "^18.0.17",
67
67
  "@types/react-dom": "^18.0.4",
68
- "@typescript-eslint/eslint-plugin": "^5.32.0",
69
- "@typescript-eslint/parser": "^5.32.0",
68
+ "@typescript-eslint/eslint-plugin": "^5.33.0",
69
+ "@typescript-eslint/parser": "^5.33.0",
70
70
  "dpdm": "^3.9.0",
71
- "eslint": "^8.21.0",
71
+ "eslint": "^8.22.0",
72
72
  "eslint-config-prettier": "^8.5.0",
73
73
  "eslint-plugin-import": "^2.26.0",
74
74
  "eslint-plugin-prettier": "^4.0.0",
@@ -2,7 +2,7 @@ import type { Datas, Key } from "../util/data.js";
2
2
  import type { ItemArray, ItemValue, ItemConstraints } from "../db/Item.js";
3
3
  import type { PartialObserver } from "../observe/Observer.js";
4
4
  import type { Unsubscribe } from "../observe/Observable.js";
5
- import type { DataUpdate } from "../update/DataUpdate.js";
5
+ import type { Updates } from "../update/DataUpdate.js";
6
6
  import type { AsyncProvider } from "./Provider.js";
7
7
  import type { AsyncThroughProvider } from "./ThroughProvider.js";
8
8
  import { MemoryProvider } from "./MemoryProvider.js";
@@ -15,11 +15,11 @@ export declare class CacheProvider<T extends Datas> implements AsyncThroughProvi
15
15
  subscribeItem<K extends Key<T>>(collection: K, id: string, observer: PartialObserver<ItemValue<T[K]>>): Unsubscribe;
16
16
  addItem<K extends Key<T>>(collection: K, data: T[K]): Promise<string>;
17
17
  setItem<K extends Key<T>>(collection: K, id: string, data: T[K]): Promise<void>;
18
- updateItem<K extends Key<T>>(collection: K, id: string, update: DataUpdate<T[K]>): Promise<void>;
18
+ updateItem<K extends Key<T>>(collection: K, id: string, updates: Updates<T[K]>): Promise<void>;
19
19
  deleteItem<K extends Key<T>>(collection: K, id: string): Promise<void>;
20
20
  getQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<ItemArray<T[K]>>;
21
21
  subscribeQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, observer: PartialObserver<ItemArray<T[K]>>): Unsubscribe;
22
22
  setQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, data: T[K]): Promise<number>;
23
- updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, update: DataUpdate<T[K]>): Promise<number>;
23
+ updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): Promise<number>;
24
24
  deleteQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<number>;
25
25
  }
@@ -24,11 +24,11 @@ export class CacheProvider {
24
24
  await this.source.setItem(collection, id, data);
25
25
  this.memory.getTable(collection).setItem(id, data);
26
26
  }
27
- async updateItem(collection, id, update) {
28
- await this.source.updateItem(collection, id, update);
27
+ async updateItem(collection, id, updates) {
28
+ await this.source.updateItem(collection, id, updates);
29
29
  const table = this.memory.getTable(collection);
30
30
  if (table.getItem(id))
31
- table.updateItem(id, update);
31
+ table.updateItem(id, updates);
32
32
  }
33
33
  async deleteItem(collection, id) {
34
34
  await this.source.deleteItem(collection, id);
@@ -49,9 +49,9 @@ export class CacheProvider {
49
49
  this.memory.getTable(collection).setQuery(constraints, data);
50
50
  return count;
51
51
  }
52
- async updateQuery(collection, constraints, update) {
53
- const count = await this.source.updateQuery(collection, constraints, update);
54
- this.memory.getTable(collection).updateQuery(constraints, update);
52
+ async updateQuery(collection, constraints, updates) {
53
+ const count = await this.source.updateQuery(collection, constraints, updates);
54
+ this.memory.getTable(collection).updateQuery(constraints, updates);
55
55
  return count;
56
56
  }
57
57
  async deleteQuery(collection, constraints) {
@@ -1,6 +1,6 @@
1
1
  import type { Datas, Key } from "../util/data.js";
2
2
  import type { ItemArray, ItemConstraints, ItemValue } from "../db/Item.js";
3
- import type { DataUpdate } from "../update/DataUpdate.js";
3
+ import type { Updates } from "../update/DataUpdate.js";
4
4
  import type { PartialObserver } from "../observe/Observer.js";
5
5
  import type { Unsubscribe } from "../observe/Observable.js";
6
6
  import { Provider, AsyncProvider } from "./Provider.js";
@@ -18,11 +18,11 @@ export declare class DebugProvider<T extends Datas> extends AbstractDebugProvide
18
18
  getItem<K extends Key<T>>(collection: K, id: string): ItemValue<T[K]>;
19
19
  addItem<K extends Key<T>>(collection: K, data: T[K]): string;
20
20
  setItem<K extends Key<T>>(collection: K, id: string, data: T[K]): void;
21
- updateItem<K extends Key<T>>(collection: K, id: string, update: DataUpdate<T[K]>): void;
21
+ updateItem<K extends Key<T>>(collection: K, id: string, updates: Updates<T[K]>): void;
22
22
  deleteItem<K extends Key<T>>(collection: K, id: string): void;
23
23
  getQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): ItemArray<T[K]>;
24
24
  setQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, data: T[K]): number;
25
- updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, update: DataUpdate<T[K]>): number;
25
+ updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): number;
26
26
  deleteQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): number;
27
27
  }
28
28
  /** Provider that logs operations to a synchronous source provider to the console. */
@@ -32,11 +32,11 @@ export declare class AsyncDebugProvider<T extends Datas> extends AbstractDebugPr
32
32
  getItem<K extends Key<T>>(collection: K, id: string): Promise<ItemValue<T[K]>>;
33
33
  addItem<K extends Key<T>>(collection: K, data: T[K]): Promise<string>;
34
34
  setItem<K extends Key<T>>(collection: K, id: string, data: T[K]): Promise<void>;
35
- updateItem<K extends Key<T>>(collection: K, id: string, update: DataUpdate<T[K]>): Promise<void>;
35
+ updateItem<K extends Key<T>>(collection: K, id: string, updates: Updates<T[K]>): Promise<void>;
36
36
  deleteItem<K extends Key<T>>(collection: K, id: string): Promise<void>;
37
37
  getQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<ItemArray<T[K]>>;
38
38
  setQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, data: T[K]): Promise<number>;
39
- updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, update: DataUpdate<T[K]>): Promise<number>;
39
+ updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): Promise<number>;
40
40
  deleteQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<number>;
41
41
  }
42
42
  export {};
@@ -64,11 +64,11 @@ export class DebugProvider extends AbstractDebugProvider {
64
64
  throw reason;
65
65
  }
66
66
  }
67
- updateItem(collection, id, update) {
67
+ updateItem(collection, id, updates) {
68
68
  const key = _getItemKey(collection, id);
69
- console.log(`Update: ${key}:`, update.updates);
69
+ console.log(`Update: ${key}:`, updates.updates);
70
70
  try {
71
- return this.source.updateItem(collection, id, update);
71
+ return this.source.updateItem(collection, id, updates);
72
72
  }
73
73
  catch (reason) {
74
74
  console.error(`Error: Update: ${key}:`, reason);
@@ -108,11 +108,11 @@ export class DebugProvider extends AbstractDebugProvider {
108
108
  throw reason;
109
109
  }
110
110
  }
111
- updateQuery(collection, constraints, update) {
111
+ updateQuery(collection, constraints, updates) {
112
112
  const key = _getQueryKey(collection, constraints);
113
- console.log(`Update: ${key}:`, update.updates);
113
+ console.log(`Update: ${key}:`, updates.updates);
114
114
  try {
115
- return this.source.updateQuery(collection, constraints, update);
115
+ return this.source.updateQuery(collection, constraints, updates);
116
116
  }
117
117
  catch (reason) {
118
118
  console.error(`Error: Update: ${key}:`, reason);
@@ -170,11 +170,11 @@ export class AsyncDebugProvider extends AbstractDebugProvider {
170
170
  throw reason;
171
171
  }
172
172
  }
173
- async updateItem(collection, id, update) {
173
+ async updateItem(collection, id, updates) {
174
174
  const key = _getItemKey(collection, id);
175
- console.log(`Update: ${key}:`, update.updates);
175
+ console.log(`Update: ${key}:`, updates.updates);
176
176
  try {
177
- return await this.source.updateItem(collection, id, update);
177
+ return await this.source.updateItem(collection, id, updates);
178
178
  }
179
179
  catch (reason) {
180
180
  console.error(`Error: Update: ${key}:`, reason);
@@ -214,11 +214,11 @@ export class AsyncDebugProvider extends AbstractDebugProvider {
214
214
  throw reason;
215
215
  }
216
216
  }
217
- async updateQuery(collection, constraints, update) {
217
+ async updateQuery(collection, constraints, updates) {
218
218
  const key = _getQueryKey(collection, constraints);
219
- console.log(`Update: ${key}:`, update.updates);
219
+ console.log(`Update: ${key}:`, updates.updates);
220
220
  try {
221
- return await this.source.updateQuery(collection, constraints, update);
221
+ return await this.source.updateQuery(collection, constraints, updates);
222
222
  }
223
223
  catch (reason) {
224
224
  console.error(`Error: Update: ${key}:`, reason);
@@ -1,6 +1,6 @@
1
1
  import type { Data, Datas, Key } from "../util/data.js";
2
2
  import type { ItemArray, ItemValue, ItemData, ItemConstraints } from "../db/Item.js";
3
- import type { DataUpdate } from "../update/DataUpdate.js";
3
+ import type { Updates } from "../update/DataUpdate.js";
4
4
  import type { Dispatch } from "../util/function.js";
5
5
  import type { Unsubscribe } from "../observe/Observable.js";
6
6
  import { Subject } from "../observe/Subject.js";
@@ -21,13 +21,13 @@ export declare class MemoryProvider<T extends Datas> implements Provider<T> {
21
21
  subscribeItem<K extends Key<T>>(collection: K, id: string, observer: PartialObserver<ItemValue<T[K]>>): Unsubscribe;
22
22
  addItem<K extends Key<T>>(collection: K, data: T[K]): string;
23
23
  setItem<K extends Key<T>>(collection: K, id: string, data: T[K]): void;
24
- updateItem<K extends Key<T>>(collection: K, id: string, update: DataUpdate<T[K]>): void;
24
+ updateItem<K extends Key<T>>(collection: K, id: string, updates: Updates<T[K]>): void;
25
25
  deleteItem<K extends Key<T>>(collection: K, id: string): void;
26
26
  getQueryTime<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): number | null;
27
27
  getQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): ItemArray<T[K]>;
28
28
  subscribeQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, observer: PartialObserver<ItemArray<T[K]>>): Unsubscribe;
29
29
  setQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, data: T[K]): number;
30
- updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, update: DataUpdate<T[K]>): number;
30
+ updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): number;
31
31
  deleteQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): number;
32
32
  }
33
33
  /**
@@ -48,7 +48,7 @@ export declare class MemoryTable<T extends Data> extends Subject<void> {
48
48
  addItem(data: T): string;
49
49
  setItemData(data: ItemData<T>): void;
50
50
  setItem(id: string, data: T): void;
51
- updateItem(id: string, update: DataUpdate<T>): void;
51
+ updateItem(id: string, updates: Updates<T>): void;
52
52
  deleteItem(id: string): void;
53
53
  getQueryTime(query: ItemConstraints<T>): number | null;
54
54
  setQueryTime(query: ItemConstraints<T>): void;
@@ -58,6 +58,6 @@ export declare class MemoryTable<T extends Data> extends Subject<void> {
58
58
  subscribeCachedQuery(query: ItemConstraints<T>, observer: PartialObserver<ItemArray<T>>): Unsubscribe;
59
59
  setItems(items: ItemArray<T>): number;
60
60
  setQuery(constraints: ItemConstraints<T>, data: T): number;
61
- updateQuery(constraints: ItemConstraints<T>, update: DataUpdate<T>): number;
61
+ updateQuery(constraints: ItemConstraints<T>, updates: Updates<T>): number;
62
62
  deleteQuery(constraints: ItemConstraints<T>): number;
63
63
  }
@@ -5,6 +5,7 @@ import { RequiredError } from "../error/RequiredError.js";
5
5
  import { Subject } from "../observe/Subject.js";
6
6
  import { dispatchNext } from "../observe/Observer.js";
7
7
  import { getArray } from "../util/array.js";
8
+ import { transformData } from "../util/transform.js";
8
9
  /**
9
10
  * Fast in-memory store for data.
10
11
  * - Extremely fast (ideal for caching!), but does not persist data after the browser window is closed.
@@ -34,8 +35,8 @@ export class MemoryProvider {
34
35
  setItem(collection, id, data) {
35
36
  return this.getTable(collection).setItem(id, data);
36
37
  }
37
- updateItem(collection, id, update) {
38
- return this.getTable(collection).updateItem(id, update);
38
+ updateItem(collection, id, updates) {
39
+ return this.getTable(collection).updateItem(id, updates);
39
40
  }
40
41
  deleteItem(collection, id) {
41
42
  return this.getTable(collection).deleteItem(id);
@@ -52,8 +53,8 @@ export class MemoryProvider {
52
53
  setQuery(collection, constraints, data) {
53
54
  return this.getTable(collection).setQuery(constraints, data);
54
55
  }
55
- updateQuery(collection, constraints, update) {
56
- return this.getTable(collection).updateQuery(constraints, update);
56
+ updateQuery(collection, constraints, updates) {
57
+ return this.getTable(collection).updateQuery(constraints, updates);
57
58
  }
58
59
  deleteQuery(collection, constraints) {
59
60
  return this.getTable(collection).deleteQuery(constraints);
@@ -126,11 +127,11 @@ export class MemoryTable extends Subject {
126
127
  setItem(id, data) {
127
128
  this.setItemData({ ...data, id });
128
129
  }
129
- updateItem(id, update) {
130
+ updateItem(id, updates) {
130
131
  const item = this._data.get(id);
131
132
  if (!item)
132
133
  throw new RequiredError(`Document "${id}" does not exist`);
133
- this.setItemData({ ...update.transform(item), id });
134
+ this.setItemData({ ...transformData(item, updates), id });
134
135
  }
135
136
  deleteItem(id) {
136
137
  this._data.delete(id);
@@ -197,11 +198,11 @@ export class MemoryTable extends Subject {
197
198
  this.next();
198
199
  return count;
199
200
  }
200
- updateQuery(constraints, update) {
201
+ updateQuery(constraints, updates) {
201
202
  const now = Date.now();
202
203
  let count = 0;
203
204
  for (const item of _getWriteConstraints(constraints).transform(this._data.values())) {
204
- this.setItemData({ ...update.transform(item), id: item.id });
205
+ this.setItemData({ ...transformData(item, updates), id: item.id });
205
206
  count++;
206
207
  }
207
208
  this._times.set(_getQueryKey(constraints), now);
@@ -1,6 +1,6 @@
1
1
  import type { Unsubscribe } from "../observe/Observable.js";
2
2
  import type { PartialObserver } from "../observe/Observer.js";
3
- import type { DataUpdate } from "../update/DataUpdate.js";
3
+ import type { Updates } from "../update/DataUpdate.js";
4
4
  import type { Datas, Key } from "../util/data.js";
5
5
  import type { ItemArray, ItemConstraints, ItemValue } from "../db/Item.js";
6
6
  /** Provides access to data (e.g. IndexedDB, Firebase, or in-memory cache providers). */
@@ -43,7 +43,7 @@ declare abstract class AbstractProvider<T extends Datas = Datas> {
43
43
  * @param update Update instance to set the document to.
44
44
  * @throws Error If the document does not exist (ideally a `RequiredError` but may be provider-specific).
45
45
  */
46
- abstract updateItem<K extends Key<T>>(collection: K, id: string, update: DataUpdate<T[K]>): void | PromiseLike<void>;
46
+ abstract updateItem<K extends Key<T>>(collection: K, id: string, updates: Updates<T[K]>): void | PromiseLike<void>;
47
47
  /**
48
48
  * Delete a specified document.
49
49
  */
@@ -75,7 +75,7 @@ declare abstract class AbstractProvider<T extends Datas = Datas> {
75
75
  * @param update Update instance to set the document to.
76
76
  * @return Number of documents that were updated.
77
77
  */
78
- abstract updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, update: DataUpdate<T[K]>): number | PromiseLike<number>;
78
+ abstract updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): number | PromiseLike<number>;
79
79
  /**
80
80
  * Delete all matching documents.
81
81
  * @return Number of documents that were deleted.
@@ -88,12 +88,12 @@ export declare abstract class Provider<T extends Datas = Datas> extends Abstract
88
88
  abstract subscribeItem<K extends Key<T>>(collection: K, id: string, observer: PartialObserver<ItemValue<T[K]>>): Unsubscribe;
89
89
  abstract addItem<K extends Key<T>>(collection: K, data: T[K]): string;
90
90
  abstract setItem<K extends Key<T>>(collection: K, id: string, data: T[K]): void;
91
- abstract updateItem<K extends Key<T>>(collection: K, id: string, update: DataUpdate<T[K]>): void;
91
+ abstract updateItem<K extends Key<T>>(collection: K, id: string, updates: Updates<T[K]>): void;
92
92
  abstract deleteItem<K extends Key<T>>(collection: K, id: string): void;
93
93
  abstract getQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): ItemArray<T[K]>;
94
94
  abstract subscribeQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, observer: PartialObserver<ItemArray<T[K]>>): Unsubscribe;
95
95
  abstract setQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, data: T[K]): number;
96
- abstract updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, update: DataUpdate<T[K]>): number;
96
+ abstract updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): number;
97
97
  abstract deleteQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): number;
98
98
  }
99
99
  /** Provider with a fully asynchronous interface */
@@ -102,12 +102,12 @@ export declare abstract class AsyncProvider<T extends Datas = Datas> extends Abs
102
102
  abstract subscribeItem<K extends Key<T>>(collection: K, id: string, observer: PartialObserver<ItemValue<T[K]>>): Unsubscribe;
103
103
  abstract addItem<K extends Key<T>>(collection: K, data: T[K]): Promise<string>;
104
104
  abstract setItem<K extends Key<T>>(collection: K, id: string, data: T[K]): Promise<void>;
105
- abstract updateItem<K extends Key<T>>(collection: K, id: string, update: DataUpdate<T[K]>): Promise<void>;
105
+ abstract updateItem<K extends Key<T>>(collection: K, id: string, updates: Updates<T[K]>): Promise<void>;
106
106
  abstract deleteItem<K extends Key<T>>(collection: K, id: string): Promise<void>;
107
107
  abstract getQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<ItemArray<T[K]>>;
108
108
  abstract subscribeQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, observer: PartialObserver<ItemArray<T[K]>>): Unsubscribe;
109
109
  abstract setQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, data: T[K]): Promise<number>;
110
- abstract updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, update: DataUpdate<T[K]>): Promise<number>;
110
+ abstract updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): Promise<number>;
111
111
  abstract deleteQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<number>;
112
112
  }
113
113
  export {};
@@ -1,7 +1,7 @@
1
1
  import type { Datas, Key } 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
- import type { DataUpdate } from "../update/DataUpdate.js";
4
+ import type { Updates } from "../update/DataUpdate.js";
5
5
  import type { PartialObserver } from "../observe/Observer.js";
6
6
  import type { Unsubscribe } from "../observe/Observable.js";
7
7
  import type { Provider, AsyncProvider } from "./Provider.js";
@@ -13,12 +13,12 @@ export declare class ThroughProvider<T extends Datas = Datas> implements Provide
13
13
  subscribeItem<K extends Key<T>>(collection: K, id: string, observer: PartialObserver<ItemValue<T[K]>>): Unsubscribe;
14
14
  addItem<K extends Key<T>>(collection: K, data: T[K]): string;
15
15
  setItem<K extends Key<T>>(collection: K, id: string, data: T[K]): void;
16
- updateItem<K extends Key<T>>(collection: K, id: string, update: DataUpdate<T[K]>): void;
16
+ updateItem<K extends Key<T>>(collection: K, id: string, update: Updates<T[K]>): void;
17
17
  deleteItem<K extends Key<T>>(collection: K, id: string): void;
18
18
  getQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): ItemArray<T[K]>;
19
19
  subscribeQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, observer: PartialObserver<ItemArray<T[K]>>): Unsubscribe;
20
20
  setQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, data: T[K]): number;
21
- updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, update: DataUpdate<T[K]>): number;
21
+ updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, update: Updates<T[K]>): number;
22
22
  deleteQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): number;
23
23
  }
24
24
  /** A provider that passes through to an asynchronous source. */
@@ -29,11 +29,11 @@ export declare class AsyncThroughProvider<T extends Datas = Datas> implements As
29
29
  subscribeItem<K extends Key<T>>(collection: K, id: string, observer: PartialObserver<ItemValue<T[K]>>): Unsubscribe;
30
30
  addItem<K extends Key<T>>(collection: K, data: T[K]): Promise<string>;
31
31
  setItem<K extends Key<T>>(collection: K, id: string, data: T[K]): Promise<void>;
32
- updateItem<K extends Key<T>>(collection: K, id: string, update: DataUpdate<T[K]>): Promise<void>;
32
+ updateItem<K extends Key<T>>(collection: K, id: string, updates: Updates<T[K]>): Promise<void>;
33
33
  deleteItem<K extends Key<T>>(collection: K, id: string): Promise<void>;
34
34
  getQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<ItemArray<T[K]>>;
35
35
  subscribeQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, observer: PartialObserver<ItemArray<T[K]>>): Unsubscribe;
36
36
  setQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, data: T[K]): Promise<number>;
37
- updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, update: DataUpdate<T[K]>): Promise<number>;
37
+ updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): Promise<number>;
38
38
  deleteQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<number>;
39
39
  }
@@ -54,8 +54,8 @@ export class AsyncThroughProvider {
54
54
  setItem(collection, id, data) {
55
55
  return this.source.setItem(collection, id, data);
56
56
  }
57
- updateItem(collection, id, update) {
58
- return this.source.updateItem(collection, id, update);
57
+ updateItem(collection, id, updates) {
58
+ return this.source.updateItem(collection, id, updates);
59
59
  }
60
60
  deleteItem(collection, id) {
61
61
  return this.source.deleteItem(collection, id);
@@ -69,8 +69,8 @@ export class AsyncThroughProvider {
69
69
  setQuery(collection, constraints, data) {
70
70
  return this.source.setQuery(collection, constraints, data);
71
71
  }
72
- updateQuery(collection, constraints, update) {
73
- return this.source.updateQuery(collection, constraints, update);
72
+ updateQuery(collection, constraints, updates) {
73
+ return this.source.updateQuery(collection, constraints, updates);
74
74
  }
75
75
  deleteQuery(collection, constraints) {
76
76
  return this.source.deleteQuery(collection, constraints);
@@ -1,46 +1,46 @@
1
1
  import type { Key, Datas } from "../util/data.js";
2
2
  import type { ItemArray, ItemValue, ItemConstraints } from "../db/Item.js";
3
- import type { DataUpdate } from "../update/DataUpdate.js";
3
+ import type { DataSchemas, DataSchema } from "../schema/DataSchema.js";
4
4
  import type { PartialObserver } from "../observe/Observer.js";
5
5
  import type { Unsubscribe } from "../observe/Observable.js";
6
- import { Validator, Validators } from "../util/validate.js";
6
+ import { Updates } from "../update/DataUpdate.js";
7
7
  import { Sourceable } from "../util/source.js";
8
8
  import { Provider, AsyncProvider } from "./Provider.js";
9
9
  /** Validate a source provider (source can have any type because validation guarantees the type). */
10
10
  declare abstract class BaseValidationProvider<T extends Datas> {
11
11
  abstract source: Provider | AsyncProvider;
12
- readonly validators: Validators<T>;
13
- constructor(validators: Validators<T>);
14
- getValidator<K extends Key<T>>(collection: K): Validator<T[K]>;
12
+ readonly schemas: DataSchemas<T>;
13
+ constructor(schemas: DataSchemas<T>);
14
+ getSchema<K extends Key<T>>(collection: K): DataSchema<T[K]>;
15
15
  subscribeItem<K extends Key<T>>(collection: K, id: string, observer: PartialObserver<ItemValue<T[K]>>): Unsubscribe;
16
16
  subscribeQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, observer: PartialObserver<ItemArray<T[K]>>): Unsubscribe;
17
17
  }
18
18
  /** Validate a synchronous source provider (source can have any type because validation guarantees the type). */
19
19
  export declare class ValidationProvider<T extends Datas> extends BaseValidationProvider<T> implements Provider<T>, Sourceable<Provider> {
20
20
  readonly source: Provider;
21
- constructor(source: Provider, validators: Validators<T>);
21
+ constructor(source: Provider, schemas: DataSchemas<T>);
22
22
  getItem<K extends Key<T>>(collection: K, id: string): ItemValue<T[K]>;
23
23
  addItem<K extends Key<T>>(collection: K, data: T[K]): string;
24
24
  setItem<K extends Key<T>>(collection: K, id: string, value: T[K]): void;
25
- updateItem<K extends Key<T>>(collection: K, id: string, update: DataUpdate<T[K]>): void;
25
+ updateItem<K extends Key<T>>(collection: K, id: string, updates: Updates<T[K]>): void;
26
26
  deleteItem<K extends Key<T>>(collection: K, id: string): void;
27
27
  getQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): ItemArray<T[K]>;
28
28
  setQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, value: T[K]): number;
29
- updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, update: DataUpdate<T[K]>): number;
29
+ updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): number;
30
30
  deleteQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): number;
31
31
  }
32
32
  /** Validate an asynchronous source provider (source can have any type because validation guarantees the type). */
33
33
  export declare class AsyncValidationProvider<T extends Datas> extends BaseValidationProvider<T> implements AsyncProvider<T>, Sourceable<AsyncProvider> {
34
34
  readonly source: AsyncProvider;
35
- constructor(source: AsyncProvider, validators: Validators<T>);
35
+ constructor(source: AsyncProvider, schemas: DataSchemas<T>);
36
36
  getItem<K extends Key<T>>(collection: K, id: string): Promise<ItemValue<T[K]>>;
37
37
  addItem<K extends Key<T>>(collection: K, data: T[K]): Promise<string>;
38
38
  setItem<K extends Key<T>>(collection: K, id: string, value: T[K]): Promise<void>;
39
- updateItem<K extends Key<T>>(collection: K, id: string, update: DataUpdate<T[K]>): Promise<void>;
39
+ updateItem<K extends Key<T>>(collection: K, id: string, updates: Updates<T[K]>): Promise<void>;
40
40
  deleteItem<K extends Key<T>>(collection: K, id: string): Promise<void>;
41
41
  getQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<ItemArray<T[K]>>;
42
42
  setQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, value: T[K]): Promise<number>;
43
- updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, update: DataUpdate<T[K]>): Promise<number>;
43
+ updateQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>, updates: Updates<T[K]>): Promise<number>;
44
44
  deleteQuery<K extends Key<T>>(collection: K, constraints: ItemConstraints<T[K]>): Promise<number>;
45
45
  }
46
46
  export {};
@@ -1,3 +1,4 @@
1
+ import { validateUpdates } from "../update/DataUpdate.js";
1
2
  import { validate } from "../util/validate.js";
2
3
  import { Feedback } from "../feedback/Feedback.js";
3
4
  import { ValidationError } from "../error/ValidationError.js";
@@ -5,48 +6,48 @@ import { InvalidFeedback } from "../feedback/InvalidFeedback.js";
5
6
  import { TransformableObserver } from "../observe/TransformableObserver.js";
6
7
  /** Validate a source provider (source can have any type because validation guarantees the type). */
7
8
  class BaseValidationProvider {
8
- constructor(validators) {
9
- this.validators = validators;
9
+ constructor(schemas) {
10
+ this.schemas = schemas;
10
11
  }
11
- getValidator(collection) {
12
- return this.validators[collection];
12
+ getSchema(collection) {
13
+ return this.schemas[collection];
13
14
  }
14
15
  subscribeItem(collection, id, observer) {
15
- return this.source.subscribeItem(collection, id, new _ValidateEntityObserver(collection, this.getValidator(collection), observer));
16
+ return this.source.subscribeItem(collection, id, new _ValidateEntityObserver(collection, this.getSchema(collection), observer));
16
17
  }
17
18
  subscribeQuery(collection, constraints, observer) {
18
- return this.source.subscribeQuery(collection, constraints, new _ValidateEntitiesObserver(collection, this.getValidator(collection), observer));
19
+ return this.source.subscribeQuery(collection, constraints, new _ValidateEntitiesObserver(collection, this.getSchema(collection), observer));
19
20
  }
20
21
  }
21
22
  /** Validate a synchronous source provider (source can have any type because validation guarantees the type). */
22
23
  export class ValidationProvider extends BaseValidationProvider {
23
- constructor(source, validators) {
24
- super(validators);
24
+ constructor(source, schemas) {
25
+ super(schemas);
25
26
  this.source = source;
26
27
  }
27
28
  getItem(collection, id) {
28
- return _validateEntity(collection, this.source.getItem(collection, id), this.getValidator(collection));
29
+ return _validateEntity(collection, this.source.getItem(collection, id), this.getSchema(collection));
29
30
  }
30
31
  addItem(collection, data) {
31
- return this.source.addItem(collection, validate(data, this.getValidator(collection)));
32
+ return this.source.addItem(collection, validate(data, this.getSchema(collection)));
32
33
  }
33
34
  setItem(collection, id, value) {
34
- return this.source.setItem(collection, id, validate(value, this.getValidator(collection)));
35
+ return this.source.setItem(collection, id, validate(value, this.getSchema(collection)));
35
36
  }
36
- updateItem(collection, id, update) {
37
- return this.source.updateItem(collection, id, update.validate(this.getValidator(collection)));
37
+ updateItem(collection, id, updates) {
38
+ return this.source.updateItem(collection, id, validateUpdates(updates, this.getSchema(collection).props));
38
39
  }
39
40
  deleteItem(collection, id) {
40
41
  return this.source.deleteItem(collection, id);
41
42
  }
42
43
  getQuery(collection, constraints) {
43
- return _validateEntities(collection, this.source.getQuery(collection, constraints), this.getValidator(collection));
44
+ return _validateEntities(collection, this.source.getQuery(collection, constraints), this.getSchema(collection));
44
45
  }
45
46
  setQuery(collection, constraints, value) {
46
- return this.source.setQuery(collection, constraints, validate(value, this.getValidator(collection)));
47
+ return this.source.setQuery(collection, constraints, validate(value, this.getSchema(collection)));
47
48
  }
48
- updateQuery(collection, constraints, update) {
49
- return this.source.updateQuery(collection, constraints, update.validate(this.getValidator(collection)));
49
+ updateQuery(collection, constraints, updates) {
50
+ return this.source.updateQuery(collection, constraints, validateUpdates(updates, this.getSchema(collection).props));
50
51
  }
51
52
  deleteQuery(collection, constraints) {
52
53
  return this.source.deleteQuery(collection, constraints);
@@ -54,33 +55,33 @@ export class ValidationProvider extends BaseValidationProvider {
54
55
  }
55
56
  /** Validate an asynchronous source provider (source can have any type because validation guarantees the type). */
56
57
  export class AsyncValidationProvider extends BaseValidationProvider {
57
- constructor(source, validators) {
58
- super(validators);
58
+ constructor(source, schemas) {
59
+ super(schemas);
59
60
  this.source = source;
60
61
  }
61
62
  async getItem(collection, id) {
62
- return _validateEntity(collection, await this.source.getItem(collection, id), this.getValidator(collection));
63
+ return _validateEntity(collection, await this.source.getItem(collection, id), this.getSchema(collection));
63
64
  }
64
65
  addItem(collection, data) {
65
- return this.source.addItem(collection, validate(data, this.getValidator(collection)));
66
+ return this.source.addItem(collection, validate(data, this.getSchema(collection)));
66
67
  }
67
68
  setItem(collection, id, value) {
68
- return this.source.setItem(collection, id, validate(value, this.getValidator(collection)));
69
+ return this.source.setItem(collection, id, validate(value, this.getSchema(collection)));
69
70
  }
70
- updateItem(collection, id, update) {
71
- return this.source.updateItem(collection, id, update.validate(this.getValidator(collection)));
71
+ updateItem(collection, id, updates) {
72
+ return this.source.updateItem(collection, id, validateUpdates(updates, this.getSchema(collection).props));
72
73
  }
73
74
  deleteItem(collection, id) {
74
75
  return this.source.deleteItem(collection, id);
75
76
  }
76
77
  async getQuery(collection, constraints) {
77
- return _validateEntities(collection, await this.source.getQuery(collection, constraints), this.getValidator(collection));
78
+ return _validateEntities(collection, await this.source.getQuery(collection, constraints), this.getSchema(collection));
78
79
  }
79
80
  setQuery(collection, constraints, value) {
80
- return this.source.setQuery(collection, constraints, validate(value, this.getValidator(collection)));
81
+ return this.source.setQuery(collection, constraints, validate(value, this.getSchema(collection)));
81
82
  }
82
- updateQuery(collection, constraints, update) {
83
- return this.source.updateQuery(collection, constraints, update.validate(this.getValidator(collection)));
83
+ updateQuery(collection, constraints, updates) {
84
+ return this.source.updateQuery(collection, constraints, validateUpdates(updates, this.getSchema(collection).props));
84
85
  }
85
86
  deleteQuery(collection, constraints) {
86
87
  return this.source.deleteQuery(collection, constraints);