shelving 1.77.0 → 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.
@@ -11,7 +11,7 @@ export declare type FilterKey<T extends Data> = Key<T> | `${Key<T>}` | `!${Key<T
11
11
  export declare type FilterProps<T extends Data> = {
12
12
  [K in Key<T> as `${K}` | `!${K}`]?: T[K] | ImmutableArray<T[K]>;
13
13
  } & {
14
- [K in Key<T> as `${K}[]`]?: Required<T>[K] extends ReadonlyArray<infer X> ? X : never;
14
+ [K in Key<T> as `${K}[]`]?: Required<T>[K] extends ImmutableArray<infer X> ? X : never;
15
15
  } & {
16
16
  [K in Key<T> as `${K}<` | `${K}<=` | `${K}>` | `${K}>=`]?: T[K];
17
17
  };
package/db/Change.d.ts CHANGED
@@ -1,38 +1,35 @@
1
1
  import type { Data, Datas, Key } from "../util/data.js";
2
2
  import type { ImmutableArray } from "../util/array.js";
3
3
  import type { Provider, AsyncProvider } from "../provider/Provider.js";
4
- import { DataUpdate } from "../update/DataUpdate.js";
4
+ import { Updates } from "../update/DataUpdate.js";
5
5
  import { Nullish } from "../util/null.js";
6
6
  import { DeepIterable } from "../util/iterate.js";
7
7
  import type { ItemConstraints, ItemData } from "./Item.js";
8
- export interface Change<T extends Datas> {
8
+ /** Change on a collection. */
9
+ export interface Change<T extends Datas, K extends Key<T> = Key<T>> {
9
10
  readonly action: string;
10
- readonly collection: Key<T>;
11
+ readonly collection: K;
11
12
  }
12
13
  /** Add on an item. */
13
- export interface AddChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T> {
14
+ export interface AddChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T, K> {
14
15
  readonly action: "ADD";
15
- readonly collection: K;
16
16
  readonly data: T[K];
17
17
  }
18
18
  /** Set on an item. */
19
- export interface SetChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T> {
19
+ export interface SetChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T, K> {
20
20
  readonly action: "SET";
21
- readonly collection: K;
22
21
  readonly id: string;
23
22
  readonly data: T[K];
24
23
  }
25
24
  /** Update change on an item. */
26
- export interface UpdateChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T> {
25
+ export interface UpdateChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T, K> {
27
26
  readonly action: "UPDATE";
28
- readonly collection: K;
29
27
  readonly id: string;
30
- readonly update: DataUpdate<T[K]>;
28
+ readonly updates: Updates<T[K]>;
31
29
  }
32
30
  /** Delete change on an item. */
33
- export interface DeleteChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T> {
31
+ export interface DeleteChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T, K> {
34
32
  readonly action: "DELETE";
35
- readonly collection: K;
36
33
  readonly id: string;
37
34
  }
38
35
  /** Set, update, or delete change on an item. */
package/db/Change.js CHANGED
@@ -13,7 +13,7 @@ function _changeItem(change) {
13
13
  else if (action === "SET")
14
14
  this.setItem(collection, change.id, change.data);
15
15
  else if (action === "UPDATE")
16
- this.updateQuery(collection, _getItemConstraint(change.id), change.update);
16
+ this.updateQuery(collection, _getItemConstraint(change.id), change.updates);
17
17
  else if (action === "DELETE")
18
18
  this.deleteItem(collection, change.id);
19
19
  return change;
@@ -29,7 +29,7 @@ async function _changeAsyncItem(change) {
29
29
  else if (action === "SET")
30
30
  await this.setItem(collection, change.id, change.data);
31
31
  else if (action === "UPDATE")
32
- await this.updateQuery(collection, _getItemConstraint(change.id), change.update);
32
+ await this.updateQuery(collection, _getItemConstraint(change.id), change.updates);
33
33
  else if (action === "DELETE")
34
34
  await this.deleteItem(collection, change.id);
35
35
  return change;
package/db/Database.d.ts CHANGED
@@ -19,7 +19,7 @@ declare abstract class BaseDatabase<T extends Datas> {
19
19
  /** Reference an item in a collection in this database. */
20
20
  abstract item<K extends Key<T>>(collection: K, id: string): Item<T, K> | AsyncItem<T, K>;
21
21
  /** Run a set of changes on this database. */
22
- abstract change<K extends Key<T>>(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): ItemChanges<T, K> | Promise<ItemChanges<T, K>>;
22
+ abstract change(...changes: DeepIterable<Nullish<WriteChange<T>>>[]): ItemChanges<T> | Promise<ItemChanges<T>>;
23
23
  }
24
24
  /** Database with a synchronous provider. */
25
25
  export declare class Database<T extends Datas = Datas> implements BaseDatabase<T> {
@@ -28,7 +28,7 @@ export declare class Database<T extends Datas = Datas> implements BaseDatabase<T
28
28
  collection<K extends Key<T>>(collection: K): Collection<T, K>;
29
29
  query<K extends Key<T>>(collection: K, filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): Query<T, K>;
30
30
  item<K extends Key<T>>(collection: K, id: string): Item<T, K>;
31
- change<K extends Key<T>>(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): ItemChanges<T, K>;
31
+ change(...changes: DeepIterable<Nullish<WriteChange<T>>>[]): ItemChanges<T>;
32
32
  }
33
33
  /** Database with a synchronous provider. */
34
34
  export declare class AsyncDatabase<T extends Datas = Datas> implements BaseDatabase<T> {
@@ -37,6 +37,6 @@ export declare class AsyncDatabase<T extends Datas = Datas> implements BaseDatab
37
37
  collection<K extends Key<T>>(collection: K): AsyncCollection<T, K>;
38
38
  query<K extends Key<T>>(collection: K, filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): AsyncQuery<T, K>;
39
39
  item<K extends Key<T>>(collection: K, id: string): AsyncItem<T, K>;
40
- change<K extends Key<T>>(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): Promise<ItemChanges<T, K>>;
40
+ change(...changes: DeepIterable<Nullish<WriteChange<T>>>[]): Promise<ItemChanges<T>>;
41
41
  }
42
42
  export {};
package/db/Item.d.ts CHANGED
@@ -3,7 +3,7 @@ import type { Dispatch } from "../util/function.js";
3
3
  import type { PartialObserver } from "../observe/Observer.js";
4
4
  import type { ImmutableArray } from "../util/array.js";
5
5
  import type { Observable, Unsubscribe } from "../observe/Observable.js";
6
- import { DataUpdate, PropUpdates } from "../update/DataUpdate.js";
6
+ import { DataUpdate, Updates } from "../update/DataUpdate.js";
7
7
  import type { QueryConstraints } from "../constraint/QueryConstraints.js";
8
8
  import type { AsyncDatabase, Database } from "./Database.js";
9
9
  import type { AsyncQuery, Query } from "./Query.js";
@@ -54,13 +54,13 @@ declare abstract class BaseItem<T extends Datas = Datas, K extends Key<T> = Key<
54
54
  /** Set the complete data of this item. */
55
55
  abstract set(data: T[K]): void | PromiseLike<void>;
56
56
  /** Update this item. */
57
- abstract update(updates: DataUpdate<T[K]> | PropUpdates<T[K]>): void | PromiseLike<void>;
57
+ abstract update(updates: DataUpdate<T[K]> | Updates<T[K]>): void | PromiseLike<void>;
58
58
  /** Delete this item. */
59
59
  abstract delete(): void | PromiseLike<void>;
60
60
  /** Get a set change for this item. */
61
61
  getSet(data: T[K]): SetChange<T, K>;
62
62
  /** Get an update change for this item. */
63
- getUpdate(updates: DataUpdate<T[K]> | PropUpdates<T[K]>): UpdateChange<T, K>;
63
+ getUpdate(updates: Updates<T[K]>): UpdateChange<T, K>;
64
64
  /** Get a delete change for this item. */
65
65
  getDelete(): DeleteChange<T, K>;
66
66
  toString(): `${K}/${string}`;
@@ -76,7 +76,7 @@ export declare class Item<T extends Datas = Datas, K extends Key<T> = Key<T>> ex
76
76
  get value(): ItemValue<T[K]>;
77
77
  get data(): ItemData<T[K]>;
78
78
  set(data: T[K]): void;
79
- update(updates: DataUpdate<T[K]> | PropUpdates<T[K]>): void;
79
+ update(updates: Updates<T[K]>): void;
80
80
  delete(): void;
81
81
  }
82
82
  /** Reference to an item in an asynchronous provider. */
@@ -90,7 +90,7 @@ export declare class AsyncItem<T extends Datas = Datas, K extends Key<T> = Key<T
90
90
  get value(): Promise<ItemValue<T[K]>>;
91
91
  get data(): Promise<ItemData<T[K]>>;
92
92
  set(data: T[K]): Promise<void>;
93
- update(updates: DataUpdate<T[K]> | PropUpdates<T[K]>): Promise<void>;
93
+ update(updates: Updates<T[K]>): Promise<void>;
94
94
  delete(): Promise<void>;
95
95
  }
96
96
  /** Get the ID from item data. */
package/db/Item.js CHANGED
@@ -1,7 +1,5 @@
1
1
  import { getData } from "../util/data.js";
2
2
  import { FilterConstraint } from "../constraint/FilterConstraint.js";
3
- import { DataUpdate } from "../update/DataUpdate.js";
4
- import { isTransformable } from "../util/transform.js";
5
3
  /** Reference to an item in a synchronous or asynchronous provider. */
6
4
  class BaseItem {
7
5
  /**
@@ -20,7 +18,7 @@ class BaseItem {
20
18
  }
21
19
  /** Get an update change for this item. */
22
20
  getUpdate(updates) {
23
- return { action: "UPDATE", collection: this.collection, id: this.id, update: updates instanceof DataUpdate ? updates : new DataUpdate(updates) };
21
+ return { action: "UPDATE", collection: this.collection, id: this.id, updates };
24
22
  }
25
23
  /** Get a delete change for this item. */
26
24
  getDelete() {
@@ -55,7 +53,7 @@ export class Item extends BaseItem {
55
53
  return this.db.provider.setItem(this.collection, this.id, data);
56
54
  }
57
55
  update(updates) {
58
- return this.db.provider.updateItem(this.collection, this.id, isTransformable(updates) ? updates : new DataUpdate(updates));
56
+ return this.db.provider.updateItem(this.collection, this.id, updates);
59
57
  }
60
58
  delete() {
61
59
  return this.db.provider.deleteItem(this.collection, this.id);
@@ -85,7 +83,7 @@ export class AsyncItem extends BaseItem {
85
83
  return this.db.provider.setItem(this.collection, this.id, data);
86
84
  }
87
85
  update(updates) {
88
- return this.db.provider.updateItem(this.collection, this.id, isTransformable(updates) ? updates : new DataUpdate(updates));
86
+ return this.db.provider.updateItem(this.collection, this.id, updates);
89
87
  }
90
88
  delete() {
91
89
  return this.db.provider.deleteItem(this.collection, this.id);
package/db/Query.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import type { Dispatch } from "../util/function.js";
2
2
  import type { Key, Datas } from "../util/data.js";
3
+ import type { Updates } from "../update/DataUpdate.js";
3
4
  import type { PartialObserver } from "../observe/Observer.js";
4
5
  import type { Observable, Unsubscribe } from "../observe/Observable.js";
5
6
  import type { FilterList } from "../constraint/FilterConstraint.js";
6
7
  import type { SortList } from "../constraint/SortConstraint.js";
7
8
  import { QueryConstraints } from "../constraint/QueryConstraints.js";
8
- import { DataUpdate, PropUpdates } from "../update/DataUpdate.js";
9
9
  import type { ItemArray, ItemValue, ItemData } from "./Item.js";
10
10
  import type { AsyncDatabase, Database } from "./Database.js";
11
11
  /** Reference to a set of items in a sync or async provider. */
@@ -68,7 +68,7 @@ declare abstract class BaseQuery<T extends Datas = Datas, K extends Key<T> = Key
68
68
  * @param updates `Update` instance or set of updates to apply to every matching item.
69
69
  * @return Nothing (possibly promised).
70
70
  */
71
- abstract update(updates: DataUpdate<T[K]> | PropUpdates<T[K]>): number | PromiseLike<number>;
71
+ abstract update(updates: Updates<T[K]>): number | PromiseLike<number>;
72
72
  /**
73
73
  * Delete all matching items.
74
74
  * @return Nothing (possibly promised).
@@ -89,7 +89,7 @@ export declare class Query<T extends Datas = Datas, K extends Key<T> = Key<T>> e
89
89
  get lastValue(): ItemValue<T[K]>;
90
90
  get lastData(): ItemData<T[K]>;
91
91
  set(data: T[K]): number;
92
- update(updates: DataUpdate<T[K]> | PropUpdates<T[K]>): number;
92
+ update(updates: Updates<T[K]>): number;
93
93
  delete(): number;
94
94
  }
95
95
  /** Reference to a set of items in a provider. */
@@ -105,7 +105,7 @@ export declare class AsyncQuery<T extends Datas = Datas, K extends Key<T> = Key<
105
105
  get lastValue(): Promise<ItemValue<T[K]>>;
106
106
  get lastData(): Promise<ItemData<T[K]>>;
107
107
  set(data: T[K]): Promise<number>;
108
- update(updates: DataUpdate<T[K]> | PropUpdates<T[K]>): PromiseLike<number>;
108
+ update(updates: Updates<T[K]>): PromiseLike<number>;
109
109
  delete(): PromiseLike<number>;
110
110
  }
111
111
  export {};
package/db/Query.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { getFirstItem, getLastItem, getOptionalFirstItem, getOptionalLastItem } from "../util/array.js";
2
2
  import { QueryConstraints } from "../constraint/QueryConstraints.js";
3
3
  import { countItems, hasItems } from "../util/iterate.js";
4
- import { DataUpdate } from "../update/DataUpdate.js";
5
4
  /** Reference to a set of items in a sync or async provider. */
6
5
  class BaseQuery extends QueryConstraints {
7
6
  /**
@@ -51,7 +50,7 @@ export class Query extends BaseQuery {
51
50
  return this.db.provider.setQuery(this.collection, this, data);
52
51
  }
53
52
  update(updates) {
54
- return this.db.provider.updateQuery(this.collection, this, updates instanceof DataUpdate ? updates : new DataUpdate(updates));
53
+ return this.db.provider.updateQuery(this.collection, this, updates);
55
54
  }
56
55
  delete() {
57
56
  return this.db.provider.deleteQuery(this.collection, this);
@@ -89,7 +88,7 @@ export class AsyncQuery extends BaseQuery {
89
88
  return this.db.provider.setQuery(this.collection, this, data);
90
89
  }
91
90
  update(updates) {
92
- return this.db.provider.updateQuery(this.collection, this, updates instanceof DataUpdate ? updates : new DataUpdate(updates));
91
+ return this.db.provider.updateQuery(this.collection, this, updates);
93
92
  }
94
93
  delete() {
95
94
  return this.db.provider.deleteQuery(this.collection, this);
@@ -4,7 +4,7 @@ import type { Unsubscribe } from "../../observe/Observable.js";
4
4
  import type { AsyncProvider } from "../../provider/Provider.js";
5
5
  import type { ItemArray, ItemValue, ItemConstraints } from "../../db/Item.js";
6
6
  import { Observer, PartialObserver } from "../../observe/Observer.js";
7
- import { DataUpdate } from "../../update/DataUpdate.js";
7
+ import { Updates } from "../../update/DataUpdate.js";
8
8
  /**
9
9
  * Firestore client database provider.
10
10
  * - Works with the Firebase JS SDK.
@@ -18,11 +18,11 @@ export declare class FirestoreClientProvider implements AsyncProvider {
18
18
  subscribeItem(collection: string, id: string, observer: PartialObserver<ItemValue>): Unsubscribe;
19
19
  addItem(collection: string, data: Data): Promise<string>;
20
20
  setItem(collection: string, id: string, data: Data): Promise<void>;
21
- updateItem(collection: string, id: string, update: DataUpdate): Promise<void>;
21
+ updateItem(collection: string, id: string, updates: Updates): Promise<void>;
22
22
  deleteItem(collection: string, id: string): Promise<void>;
23
23
  getQuery(collection: string, constraints: ItemConstraints): Promise<ItemArray>;
24
24
  subscribeQuery(collection: string, constraints: ItemConstraints, observer: Observer<ItemArray>): Unsubscribe;
25
25
  setQuery(collection: string, constraints: ItemConstraints, data: Data): Promise<number>;
26
- updateQuery(collection: string, constraints: ItemConstraints, update: DataUpdate): Promise<number>;
26
+ updateQuery(collection: string, constraints: ItemConstraints, updates: Updates): Promise<number>;
27
27
  deleteQuery(collection: string, constraints: ItemConstraints): Promise<number>;
28
28
  }
@@ -101,8 +101,8 @@ export class FirestoreClientProvider {
101
101
  async setItem(collection, id, data) {
102
102
  await setDoc(firestoreDocument(this._firestore, collection, id), data);
103
103
  }
104
- async updateItem(collection, id, update) {
105
- await updateDoc(firestoreDocument(this._firestore, collection, id), ..._getFieldValues(update));
104
+ async updateItem(collection, id, updates) {
105
+ await updateDoc(firestoreDocument(this._firestore, collection, id), ..._getFieldValues(Object.entries(updates)));
106
106
  }
107
107
  async deleteItem(collection, id) {
108
108
  await deleteDoc(firestoreDocument(this._firestore, collection, id));
@@ -118,9 +118,9 @@ export class FirestoreClientProvider {
118
118
  await Promise.all(snapshot.docs.map(s => setDoc(s.ref, data)));
119
119
  return snapshot.size;
120
120
  }
121
- async updateQuery(collection, constraints, update) {
121
+ async updateQuery(collection, constraints, updates) {
122
122
  const snapshot = await getDocs(_getQuery(this._firestore, collection, constraints));
123
- const fieldValues = Array.from(_getFieldValues(update));
123
+ const fieldValues = Array.from(_getFieldValues(Object.entries(updates)));
124
124
  await Promise.all(snapshot.docs.map(s => updateDoc(s.ref, ...fieldValues)));
125
125
  return snapshot.size;
126
126
  }
@@ -3,7 +3,7 @@ import type { Data } from "../../util/data.js";
3
3
  import type { Unsubscribe } from "../../observe/Observable.js";
4
4
  import type { AsyncProvider } from "../../provider/Provider.js";
5
5
  import type { ItemArray, ItemValue, ItemConstraints } from "../../db/Item.js";
6
- import { DataUpdate } from "../../update/DataUpdate.js";
6
+ import { Updates } from "../../update/DataUpdate.js";
7
7
  /**
8
8
  * Firestore Lite client database provider.
9
9
  * - Works with the Firebase JS SDK.
@@ -17,11 +17,11 @@ export declare class FirestoreLiteProvider implements AsyncProvider {
17
17
  subscribeItem(): Unsubscribe;
18
18
  addItem(collection: string, data: Data): Promise<string>;
19
19
  setItem(collection: string, id: string, data: Data): Promise<void>;
20
- updateItem(collection: string, id: string, update: DataUpdate): Promise<void>;
20
+ updateItem(collection: string, id: string, updates: Updates): Promise<void>;
21
21
  deleteItem(collection: string, id: string): Promise<void>;
22
22
  getQuery(collection: string, constraints: ItemConstraints): Promise<ItemArray>;
23
23
  subscribeQuery(): Unsubscribe;
24
24
  setQuery(collection: string, constraints: ItemConstraints, data: Data): Promise<number>;
25
- updateQuery(collection: string, constraints: ItemConstraints, update: DataUpdate): Promise<number>;
25
+ updateQuery(collection: string, constraints: ItemConstraints, updates: Updates): Promise<number>;
26
26
  deleteQuery(collection: string, constraints: ItemConstraints): Promise<number>;
27
27
  }
@@ -101,8 +101,8 @@ export class FirestoreLiteProvider {
101
101
  async setItem(collection, id, data) {
102
102
  await setDoc(firestoreDocument(this._firestore, collection, id), data);
103
103
  }
104
- async updateItem(collection, id, update) {
105
- await updateDoc(firestoreDocument(this._firestore, collection, id), ..._getFieldValues(update));
104
+ async updateItem(collection, id, updates) {
105
+ await updateDoc(firestoreDocument(this._firestore, collection, id), ..._getFieldValues(Object.entries(updates)));
106
106
  }
107
107
  async deleteItem(collection, id) {
108
108
  await deleteDoc(firestoreDocument(this._firestore, collection, id));
@@ -118,9 +118,9 @@ export class FirestoreLiteProvider {
118
118
  await Promise.all(snapshot.docs.map(s => setDoc(s.ref, data)));
119
119
  return snapshot.size;
120
120
  }
121
- async updateQuery(collection, constraints, update) {
121
+ async updateQuery(collection, constraints, updates) {
122
122
  const snapshot = await getDocs(_getQuery(this._firestore, collection, constraints));
123
- const fieldValues = Array.from(_getFieldValues(update));
123
+ const fieldValues = Array.from(_getFieldValues(Object.entries(updates)));
124
124
  await Promise.all(snapshot.docs.map(s => updateDoc(s.ref, ...fieldValues)));
125
125
  return snapshot.size;
126
126
  }
@@ -3,7 +3,7 @@ import type { Unsubscribe } from "../../observe/Observable.js";
3
3
  import type { AsyncProvider } from "../../provider/Provider.js";
4
4
  import type { ItemArray, ItemValue, ItemConstraints } from "../../db/Item.js";
5
5
  import { Observer } from "../../observe/Observer.js";
6
- import { DataUpdate } from "../../update/DataUpdate.js";
6
+ import { Updates } from "../../update/DataUpdate.js";
7
7
  import { Data } from "../../util/data.js";
8
8
  /**
9
9
  * Firestore server database provider.
@@ -16,11 +16,11 @@ export declare class FirestoreServerProvider implements AsyncProvider {
16
16
  subscribeItem(collection: string, id: string, observer: Observer<ItemValue>): Unsubscribe;
17
17
  addItem(collection: string, data: Data): Promise<string>;
18
18
  setItem(collection: string, id: string, data: Data): Promise<void>;
19
- updateItem(collection: string, id: string, update: DataUpdate): Promise<void>;
19
+ updateItem(collection: string, id: string, updates: Updates): Promise<void>;
20
20
  deleteItem(collection: string, id: string): Promise<void>;
21
21
  getQuery(collection: string, constraints: ItemConstraints): Promise<ItemArray>;
22
22
  subscribeQuery(collection: string, constraints: ItemConstraints, observer: Observer<ItemArray>): Unsubscribe;
23
23
  setQuery(collection: string, constraints: ItemConstraints, data: Data): Promise<number>;
24
- updateQuery(collection: string, constraints: ItemConstraints, update: DataUpdate): Promise<number>;
24
+ updateQuery(collection: string, constraints: ItemConstraints, updates: Updates): Promise<number>;
25
25
  deleteQuery(collection: string, constraints: ItemConstraints): Promise<number>;
26
26
  }
@@ -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.77.0",
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);
@@ -1,4 +1,4 @@
1
- import type { Data } from "../util/data.js";
1
+ import type { Data, Datas } from "../util/data.js";
2
2
  import { Validators } from "../util/validate.js";
3
3
  import { OptionalSchema } from "./OptionalSchema.js";
4
4
  import { Schema } from "./Schema.js";
@@ -12,6 +12,10 @@ export declare class DataSchema<T extends Data> extends Schema<T> {
12
12
  });
13
13
  validate(unsafeValue?: unknown): T;
14
14
  }
15
+ /** Set of named data schemas. */
16
+ export declare type DataSchemas<T extends Datas> = {
17
+ [K in keyof T]: DataSchema<T[K]>;
18
+ };
15
19
  /** Valid data object with specifed properties. */
16
20
  export declare const DATA: <T extends Data>(props: Validators<T>) => DataSchema<T>;
17
21
  /** Valid data object with specifed properties, or `null` */
@@ -1,5 +1,5 @@
1
1
  import { Data, Key, OptionalData } from "../util/data.js";
2
- import { PropTransformers } from "../util/transform.js";
2
+ import { Transformers } from "../util/transform.js";
3
3
  import { State } from "./State.js";
4
4
  /** State that stores a data object and has additional methods to help with that. */
5
5
  export declare class DataState<T extends Data> extends State<T> {
@@ -8,7 +8,7 @@ export declare class DataState<T extends Data> extends State<T> {
8
8
  /** Set a prop in this object to a new value. */
9
9
  set<K extends Key<T>>(key: K, value: T[K]): void;
10
10
  /** Update several props in this object. */
11
- update(updates: PropTransformers<T>): void;
11
+ update(updates: Transformers<T>): void;
12
12
  }
13
13
  /** State that stores an optional data object and has additional methods to help with that. */
14
14
  export declare class OptionalDataState<T extends Data> extends State<OptionalData<T>> {
@@ -19,7 +19,7 @@ export declare class OptionalDataState<T extends Data> extends State<OptionalDat
19
19
  /** Set a prop in this object to a new value. */
20
20
  set<K extends Key<T>>(key: K, value: T[K]): void;
21
21
  /** Update several props in this object. */
22
- update(updates: PropTransformers<T>): void;
22
+ update(updates: Transformers<T>): void;
23
23
  /** Delete this result. */
24
24
  delete(): void;
25
25
  }
@@ -1,7 +1,7 @@
1
1
  import { Data, Key, Prop } from "../util/data.js";
2
2
  import { Nullish } from "../util/null.js";
3
3
  import { Transformable } from "../util/transform.js";
4
- import { Validator } from "../util/validate.js";
4
+ import { Validator, Validators } from "../util/validate.js";
5
5
  import { Update } from "./Update.js";
6
6
  /**
7
7
  * Set of named transforms for the props of a data object.
@@ -10,19 +10,27 @@ import { Update } from "./Update.js";
10
10
  * - If a prop contains a transform, the existing value is transformed.
11
11
  * - This is a subset of `Dispatchers`
12
12
  */
13
- export declare type PropUpdates<T extends Data> = {
13
+ export declare type Updates<T extends Data = Data> = {
14
14
  readonly [K in keyof T]?: T[K] | Update<T[K]>;
15
15
  };
16
- /** Update that can be applied to a data object to update its props. */
17
- export declare class DataUpdate<T extends Data = Data> extends Update<T> implements Iterable<Prop<PropUpdates<T>>>, Transformable<T, T> {
16
+ /**
17
+ * Validate a set of updates against a set of validators.
18
+ */
19
+ export declare function validateUpdates<T extends Data>(unsafeUpdates: Updates<T>, validators: Validators<T>): {
20
+ [k: string]: import("../util/data.js").Value<Updates<T>>;
21
+ };
22
+ /**
23
+ * Update that can be applied to a data object to update its props.
24
+ */
25
+ export declare class DataUpdate<T extends Data = Data> extends Update<T> implements Iterable<Prop<Updates<T>>>, Transformable<T, T> {
18
26
  /** Return a data update with a specific prop marked for update. */
19
27
  static with<X extends Data, K extends Key<X>>(key: Nullish<K>, value: X[K] | Update<X[K]>): DataUpdate<X>;
20
- readonly updates: PropUpdates<T>;
21
- constructor(props: PropUpdates<T>);
28
+ readonly updates: Updates<T>;
29
+ constructor(props: Updates<T>);
22
30
  transform(data: T): T;
23
31
  validate(validator: Validator<T>): this;
24
32
  /** Return a data update with a specific prop marked for update. */
25
33
  with<K extends Key<T>>(key: Nullish<K>, value: T[K] | Update<T[K]>): this;
26
34
  /** Iterate over the transforms in this object. */
27
- [Symbol.iterator](): Iterator<Prop<PropUpdates<T>>, void>;
35
+ [Symbol.iterator](): Iterator<Prop<Updates<T>>, void>;
28
36
  }
@@ -6,7 +6,33 @@ import { isNullish } from "../util/null.js";
6
6
  import { transformData } from "../util/transform.js";
7
7
  import { validate } from "../util/validate.js";
8
8
  import { Update } from "./Update.js";
9
- /** Update that can be applied to a data object to update its props. */
9
+ /**
10
+ * Validate a set of updates against a set of validators.
11
+ */
12
+ export function validateUpdates(unsafeUpdates, validators) {
13
+ return Object.fromEntries(_validateUpdates(unsafeUpdates, validators));
14
+ }
15
+ function* _validateUpdates(unsafeUpdates, validators) {
16
+ const feedbacks = new Map();
17
+ for (const [key, validator] of getProps(validators)) {
18
+ const unsafeUpdate = unsafeUpdates[key];
19
+ if (unsafeUpdate !== undefined) {
20
+ try {
21
+ yield [key, unsafeUpdate instanceof Update ? unsafeUpdate.validate(validator) : validate(unsafeUpdate, validator)];
22
+ }
23
+ catch (thrown) {
24
+ if (!isFeedback(thrown))
25
+ throw thrown;
26
+ feedbacks.set(key, thrown);
27
+ }
28
+ }
29
+ }
30
+ if (feedbacks.size)
31
+ throw new InvalidFeedback("Invalid updates", feedbacks);
32
+ }
33
+ /**
34
+ * Update that can be applied to a data object to update its props.
35
+ */
10
36
  export class DataUpdate extends Update {
11
37
  constructor(props) {
12
38
  super();
@@ -25,7 +51,7 @@ export class DataUpdate extends Update {
25
51
  return {
26
52
  __proto__: Object.getPrototypeOf(this),
27
53
  ...this,
28
- updates: Object.fromEntries(_validateUpdates(this.updates, validator.props)),
54
+ updates: validateUpdates(this.updates, validator.props),
29
55
  };
30
56
  }
31
57
  /** Return a data update with a specific prop marked for update. */
@@ -43,22 +69,3 @@ export class DataUpdate extends Update {
43
69
  return Object.entries(this.updates).values();
44
70
  }
45
71
  }
46
- /** Validate a set of transforms against a set of validators. */
47
- function* _validateUpdates(unsafeUpdates, validators) {
48
- const feedbacks = new Map();
49
- for (const [key, validator] of getProps(validators)) {
50
- const unsafeUpdate = unsafeUpdates[key];
51
- if (unsafeUpdate !== undefined) {
52
- try {
53
- yield [key, unsafeUpdate instanceof Update ? unsafeUpdate.validate(validator) : validate(unsafeUpdate, validator)];
54
- }
55
- catch (thrown) {
56
- if (!isFeedback(thrown))
57
- throw thrown;
58
- feedbacks.set(key, thrown);
59
- }
60
- }
61
- }
62
- if (feedbacks.size)
63
- throw new InvalidFeedback("Invalid updates", feedbacks);
64
- }
@@ -16,19 +16,19 @@ export declare type Transformer<I, O> = Transformable<I, O> | Transform<I, O> |
16
16
  export declare function transform<I, O>(input: I, transformer: (v: I) => O): O;
17
17
  export declare function transform<I, O>(input: I, transformer: Transformer<I, O>): O;
18
18
  /** Set of named transformers for a data object. */
19
- export declare type PropTransformers<T extends Data> = {
19
+ export declare type Transformers<T extends Data> = {
20
20
  readonly [K in keyof T]?: Transformer<T[K], T[K]>;
21
21
  };
22
22
  /**
23
23
  * Transform the props of a data object using a set of transformers for its props.
24
24
  * @returns New object with changed props (or the same object if no changes were made).
25
25
  */
26
- export declare function transformData<T extends Data>(data: T, transforms: PropTransformers<T>): T;
26
+ export declare function transformData<T extends Data>(data: T, transforms: Transformers<T>): T;
27
27
  /**
28
28
  * Transform the props of a data object using a set of prop transformers.
29
29
  * @yield Transformed prop entry after calling the corresponding prop transformer.
30
30
  */
31
- export declare function transformProps<T extends Data>(data: T, transforms: PropTransformers<T>): Iterable<Prop<T>>;
31
+ export declare function transformProps<T extends Data>(data: T, transforms: Transformers<T>): Iterable<Prop<T>>;
32
32
  /**
33
33
  * Transform the _values_ of an iterable set of entries using a transformer.
34
34
  * @yield Transformed entry after calling transforming the new value for each entry.