shelving 1.36.0 → 1.40.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 (83) hide show
  1. package/api/Resource.js +2 -2
  2. package/db/Database.d.ts +21 -26
  3. package/db/Database.js +29 -34
  4. package/db/Pagination.d.ts +6 -6
  5. package/db/Pagination.js +5 -5
  6. package/db/Write.d.ts +10 -6
  7. package/db/Write.js +14 -3
  8. package/db/errors.d.ts +9 -9
  9. package/firestore/client/FirestoreClientProvider.d.ts +12 -12
  10. package/firestore/lite/FirestoreLiteProvider.d.ts +10 -10
  11. package/firestore/server/FirestoreServerProvider.d.ts +12 -12
  12. package/package.json +6 -6
  13. package/provider/BatchProvider.d.ts +6 -6
  14. package/provider/BatchProvider.js +3 -3
  15. package/provider/CacheProvider.d.ts +17 -17
  16. package/provider/CacheProvider.js +6 -6
  17. package/provider/MemoryProvider.d.ts +13 -13
  18. package/provider/Provider.d.ts +31 -31
  19. package/provider/ThroughProvider.d.ts +13 -13
  20. package/provider/ValidationProvider.d.ts +11 -11
  21. package/query/Filter.d.ts +8 -9
  22. package/query/Filter.js +17 -18
  23. package/query/Filters.d.ts +2 -2
  24. package/query/Filters.js +6 -6
  25. package/query/Query.d.ts +2 -2
  26. package/query/Query.js +3 -3
  27. package/query/Rule.d.ts +3 -3
  28. package/query/Sort.d.ts +2 -2
  29. package/query/Sort.js +3 -3
  30. package/query/Sorts.d.ts +2 -2
  31. package/react/useDocument.d.ts +9 -9
  32. package/react/usePagination.d.ts +2 -2
  33. package/react/useQuery.d.ts +13 -13
  34. package/react/useQuery.js +7 -7
  35. package/schema/ArraySchema.js +2 -2
  36. package/stream/ArrayState.d.ts +2 -2
  37. package/stream/ArrayState.js +4 -4
  38. package/stream/LazyState.d.ts +1 -1
  39. package/stream/LazyState.js +2 -2
  40. package/stream/LazyStream.d.ts +1 -1
  41. package/stream/LazyStream.js +2 -2
  42. package/stream/State.d.ts +1 -1
  43. package/stream/State.js +2 -2
  44. package/stream/Stream.d.ts +2 -2
  45. package/stream/Stream.js +4 -4
  46. package/test/util.js +3 -3
  47. package/update/DataUpdate.d.ts +3 -3
  48. package/update/DataUpdate.js +7 -7
  49. package/update/ObjectUpdate.d.ts +3 -3
  50. package/update/ObjectUpdate.js +5 -5
  51. package/update/Update.d.ts +1 -1
  52. package/update/Update.js +1 -1
  53. package/update/util.d.ts +2 -4
  54. package/update/util.js +3 -3
  55. package/util/array.d.ts +14 -12
  56. package/util/array.js +3 -3
  57. package/util/assert.d.ts +10 -10
  58. package/util/assert.js +10 -10
  59. package/util/data.d.ts +10 -12
  60. package/util/data.js +6 -6
  61. package/util/date.d.ts +3 -3
  62. package/util/date.js +3 -3
  63. package/util/entry.d.ts +23 -11
  64. package/util/entry.js +9 -6
  65. package/util/filter.d.ts +22 -22
  66. package/util/filter.js +24 -24
  67. package/util/iterate.d.ts +10 -5
  68. package/util/iterate.js +19 -9
  69. package/util/map.d.ts +4 -2
  70. package/util/map.js +1 -1
  71. package/util/null.d.ts +7 -7
  72. package/util/null.js +6 -6
  73. package/util/number.d.ts +6 -2
  74. package/util/number.js +17 -2
  75. package/util/observable.d.ts +6 -0
  76. package/util/observable.js +10 -0
  77. package/util/sort.d.ts +6 -6
  78. package/util/sort.js +12 -12
  79. package/util/string.d.ts +1 -1
  80. package/util/string.js +1 -1
  81. package/util/transform.js +2 -2
  82. package/util/undefined.d.ts +3 -4
  83. package/util/undefined.js +3 -4
package/api/Resource.js CHANGED
@@ -1,4 +1,4 @@
1
- import { GET_UNDEFINED, validate } from "../util/index.js";
1
+ import { UNDEFINED, validate } from "../util/index.js";
2
2
  import { Feedback } from "../feedback/index.js";
3
3
  import { ResourceValidationError } from "./errors.js";
4
4
  /**
@@ -37,6 +37,6 @@ export class Resource {
37
37
  }
38
38
  }
39
39
  }
40
- export function RESOURCE(payload = GET_UNDEFINED, result = GET_UNDEFINED) {
40
+ export function RESOURCE(payload = UNDEFINED, result = UNDEFINED) {
41
41
  return new Resource(payload, result);
42
42
  }
package/db/Database.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Entry, Observable, Observer, Result, Unsubscriber, ResultsMap, Validatable, Validator, Key, Data, Results, Datas, Validators, ValidatorType, Dispatcher, Nullish } from "../util/index.js";
1
+ import { Entry, Observable, Observer, Result, Unsubscriber, Results, Validatable, Validator, Key, Data, Entries, Datas, Validators, ValidatorType, Dispatcher, Nullish } from "../util/index.js";
2
2
  import { PropUpdates, Update } from "../update/index.js";
3
3
  import type { Provider } from "../provider/Provider.js";
4
4
  import { Filters, Sorts, Query } from "../query/index.js";
@@ -15,22 +15,22 @@ export declare class Database<V extends Validators<Datas> = Validators<Datas>> {
15
15
  readonly provider: Provider;
16
16
  constructor(validators: V, provider: Provider);
17
17
  /** Create a query on a collection in this model. */
18
- query<K extends Key<V>>(collection: K, filters?: Filters<ValidatorType<V[K]>>, sorts?: Sorts<ValidatorType<V[K]>>, limit?: number | null): DataQuery<ValidatorType<V[K]>>;
18
+ query<K extends Key<V>>(collection: K, filters?: Filters<ValidatorType<V[K]>>, sorts?: Sorts<ValidatorType<V[K]>>, limit?: number | null): DatabaseQuery<ValidatorType<V[K]>>;
19
19
  /** Reference a document in a collection in this model. */
20
- doc<K extends Key<V>>(collection: K, id: string): DataDocument<ValidatorType<V[K]>>;
20
+ doc<K extends Key<V>>(collection: K, id: string): DatabaseDocument<ValidatorType<V[K]>>;
21
21
  /** Create a writer for this database from a set of separate writes. */
22
22
  writer(...writes: Nullish<Write>[]): Write;
23
23
  /** Perform one or more writes on this database and return the `Writes` instance representing the combined changes. */
24
24
  write(...writes: Nullish<Write>[]): Promise<Write>;
25
25
  }
26
26
  /** A documents reference within a specific database. */
27
- export declare class DataQuery<T extends Data = Data> extends Query<T> implements Observable<Results<T>>, Validatable<Results<T>>, Iterable<Entry<T>> {
27
+ export declare class DatabaseQuery<T extends Data = Data> extends Query<T> implements Observable<Results<T>>, Validatable<Entries<T>>, Iterable<Entry<T>> {
28
28
  readonly provider: Provider;
29
29
  readonly validator: Validator<T>;
30
30
  readonly collection: string;
31
31
  constructor(provider: Provider, validator: Validator<T>, collection: string, filters?: Filters<T>, sorts?: Sorts<T>, limit?: number | null);
32
32
  /** Reference a document in this query's collection. */
33
- doc(id: string): DataDocument<T>;
33
+ doc(id: string): DatabaseDocument<T>;
34
34
  /**
35
35
  * Create a new document with a random ID.
36
36
  * - Created document is guaranteed to have a unique ID.
@@ -43,17 +43,22 @@ export declare class DataQuery<T extends Data = Data> extends Query<T> implement
43
43
  * Get an iterable that yields the results of this entry.
44
44
  * @return Map containing the results.
45
45
  */
46
- get results(): Results<T> | PromiseLike<Results<T>>;
46
+ get entries(): Entries<T> | PromiseLike<Entries<T>>;
47
47
  /**
48
48
  * Get an iterable that yields the results of this entry.
49
49
  * @return Map containing the results.
50
50
  */
51
- get resultsMap(): ResultsMap<T> | PromiseLike<ResultsMap<T>>;
51
+ get results(): Results<T> | PromiseLike<Results<T>>;
52
52
  /**
53
53
  * Count the number of results of this set of documents.
54
- * @return Number of documents in the collection (possibly promised).
54
+ * @return Number of documents matching the query (possibly promised).
55
55
  */
56
56
  get count(): number | PromiseLike<number>;
57
+ /**
58
+ * Does at least one document exist for this query?
59
+ * @return `true` if a document exists or `false` otherwise (possibly promised).
60
+ */
61
+ get exists(): boolean | PromiseLike<boolean>;
57
62
  /**
58
63
  * Get an entry for the first document matched by this query or `undefined` if this query has no results.
59
64
  *
@@ -76,14 +81,6 @@ export declare class DataQuery<T extends Data = Data> extends Query<T> implement
76
81
  * @return Function that ends the subscription.
77
82
  */
78
83
  subscribe(next: Observer<Results<T>> | Dispatcher<[Results<T>]>): Unsubscriber;
79
- /**
80
- * Subscribe to all matching documents.
81
- * - `next()` is called once with the initial results, and again any time the results change.
82
- *
83
- * @param next Observer with `next`, `error`, or `complete` methods or a `next()` dispatcher.
84
- * @return Function that ends the subscription.
85
- */
86
- subscribeMap(next: Observer<ResultsMap<T>> | Dispatcher<[ResultsMap<T>]>): Unsubscriber;
87
84
  /**
88
85
  * Set all matching documents to the same exact value.
89
86
  *
@@ -106,31 +103,29 @@ export declare class DataQuery<T extends Data = Data> extends Query<T> implement
106
103
  /** Iterate over the resuls (will throw `Promise` if the results are asynchronous). */
107
104
  [Symbol.iterator](): Iterator<Entry<T>, void>;
108
105
  /** Validate a set of results for this query reference. */
109
- validate(unsafeEntries: Results): Results<T>;
106
+ validate(unsafeEntries: Entries): Entries<T>;
110
107
  toString(): string;
111
108
  }
112
109
  /** Get the data for a document from a result for that document. */
113
- export declare function getQueryData<T extends Data>(results: Results<T>, ref: DataQuery<T>): Entry<T>;
110
+ export declare function getQueryData<T extends Data>(entries: Entries<T>, ref: DatabaseQuery<T>): Entry<T>;
114
111
  /** A document reference within a specific database. */
115
- export declare class DataDocument<T extends Data = Data> implements Observable<Result<T>>, Validatable<T> {
112
+ export declare class DatabaseDocument<T extends Data = Data> implements Observable<Result<T>>, Validatable<T> {
116
113
  readonly provider: Provider;
117
114
  readonly validator: Validator<T>;
118
115
  readonly collection: string;
119
116
  readonly id: string;
120
117
  constructor(provider: Provider, validator: Validator<T>, collection: string, id: string);
121
118
  /** Create a query on this document's collection. */
122
- query(filters?: Filters<T>, sorts?: Sorts<T>, limit?: number | null): DataQuery<T>;
119
+ query(filters?: Filters<T>, sorts?: Sorts<T>, limit?: number | null): DatabaseQuery<T>;
123
120
  /** Get an 'optional' reference to this document (uses a `ModelQuery` with an `id` filter). */
124
- get optional(): DataQuery<T>;
121
+ get optional(): DatabaseQuery<T>;
125
122
  /**
126
123
  * Does this document exist?
127
- *
128
- * @return Document's data, or `undefined` if the document doesn't exist (possibly promised).
124
+ * @return `true` if a document exists or `false` otherwise (possibly promised).
129
125
  */
130
126
  get exists(): boolean | PromiseLike<boolean>;
131
127
  /**
132
128
  * Get the result of this document.
133
- *
134
129
  * @return Document's data, or `undefined` if the document doesn't exist (possibly promised).
135
130
  */
136
131
  get result(): Result<T> | PromiseLike<Result<T>>;
@@ -159,7 +154,7 @@ export declare class DataDocument<T extends Data = Data> implements Observable<R
159
154
  /** Represent a write that sets the complete data of this document in a database. */
160
155
  setter(data: T): DocumentSet<T>;
161
156
  /** Represent a write that updates this document in a database. */
162
- updater(updates: Update<T> | PropUpdates<T>): DocumentUpdate<T>;
157
+ updater(updates: PropUpdates<T>): DocumentUpdate<T>;
163
158
  /** Represent a write that deletes this document in a database. */
164
159
  deleter(): DocumentDelete<T>;
165
160
  /** Validate data for this query reference. */
@@ -167,4 +162,4 @@ export declare class DataDocument<T extends Data = Data> implements Observable<R
167
162
  toString(): string;
168
163
  }
169
164
  /** Get the data for a document from a result for that document. */
170
- export declare function getDocumentData<T extends Data>(result: Result<T>, ref: DataDocument<T>): T;
165
+ export declare function getDocumentData<T extends Data>(result: Result<T>, ref: DatabaseDocument<T>): T;
package/db/Database.js CHANGED
@@ -1,4 +1,4 @@
1
- import { callAsync, getFirstItem, throwAsync, validate, toMap, countItems, TransformObserver, NOT_NULLISH, } from "../util/index.js";
1
+ import { callAsync, getFirstItem, throwAsync, validate, getMap, countItems, isNotNullish, hasItems, ResultsObserver, } from "../util/index.js";
2
2
  import { DataUpdate, Update } from "../update/index.js";
3
3
  import { Feedback, InvalidFeedback } from "../feedback/index.js";
4
4
  import { Filters, Query, EqualFilter } from "../query/index.js";
@@ -19,25 +19,25 @@ export class Database {
19
19
  }
20
20
  /** Create a query on a collection in this model. */
21
21
  query(collection, filters, sorts, limit) {
22
- return new DataQuery(this.provider, this.validators[collection], collection, filters, sorts, limit);
22
+ return new DatabaseQuery(this.provider, this.validators[collection], collection, filters, sorts, limit);
23
23
  }
24
24
  /** Reference a document in a collection in this model. */
25
25
  doc(collection, id) {
26
- return new DataDocument(this.provider, this.validators[collection], collection, id);
26
+ return new DatabaseDocument(this.provider, this.validators[collection], collection, id);
27
27
  }
28
28
  /** Create a writer for this database from a set of separate writes. */
29
29
  writer(...writes) {
30
- return new Writes(...writes.filter(NOT_NULLISH));
30
+ return new Writes(...writes.filter(isNotNullish));
31
31
  }
32
32
  /** Perform one or more writes on this database and return the `Writes` instance representing the combined changes. */
33
33
  async write(...writes) {
34
- const write = new Writes(...writes.filter(NOT_NULLISH));
34
+ const write = new Writes(...writes.filter(isNotNullish));
35
35
  await write.transform(this);
36
36
  return write;
37
37
  }
38
38
  }
39
39
  /** A documents reference within a specific database. */
40
- export class DataQuery extends Query {
40
+ export class DatabaseQuery extends Query {
41
41
  constructor(provider, validator, collection, filters, sorts, limit) {
42
42
  super(filters, sorts, limit);
43
43
  this.provider = provider;
@@ -46,7 +46,7 @@ export class DataQuery extends Query {
46
46
  }
47
47
  /** Reference a document in this query's collection. */
48
48
  doc(id) {
49
- return new DataDocument(this.provider, this.validator, this.collection, id);
49
+ return new DatabaseDocument(this.provider, this.validator, this.collection, id);
50
50
  }
51
51
  /**
52
52
  * Create a new document with a random ID.
@@ -62,22 +62,29 @@ export class DataQuery extends Query {
62
62
  * Get an iterable that yields the results of this entry.
63
63
  * @return Map containing the results.
64
64
  */
65
- get results() {
65
+ get entries() {
66
66
  return this.provider.getQuery(this);
67
67
  }
68
68
  /**
69
69
  * Get an iterable that yields the results of this entry.
70
70
  * @return Map containing the results.
71
71
  */
72
- get resultsMap() {
73
- return callAsync(toMap, this.provider.getQuery(this));
72
+ get results() {
73
+ return callAsync(getMap, this.provider.getQuery(this));
74
74
  }
75
75
  /**
76
76
  * Count the number of results of this set of documents.
77
- * @return Number of documents in the collection (possibly promised).
77
+ * @return Number of documents matching the query (possibly promised).
78
78
  */
79
79
  get count() {
80
- return callAsync(countItems, this.results);
80
+ return callAsync(countItems, this.entries);
81
+ }
82
+ /**
83
+ * Does at least one document exist for this query?
84
+ * @return `true` if a document exists or `false` otherwise (possibly promised).
85
+ */
86
+ get exists() {
87
+ return callAsync(hasItems, this.provider.getQuery(this.max(1)));
81
88
  }
82
89
  /**
83
90
  * Get an entry for the first document matched by this query or `undefined` if this query has no results.
@@ -86,7 +93,7 @@ export class DataQuery extends Query {
86
93
  * @throws RequiredError if there were no results for this query.
87
94
  */
88
95
  get result() {
89
- return callAsync(getFirstItem, this.max(1).results);
96
+ return callAsync(getFirstItem, this.provider.getQuery(this.max(1)));
90
97
  }
91
98
  /**
92
99
  * Get an entry for the first document matched by this query.
@@ -95,7 +102,7 @@ export class DataQuery extends Query {
95
102
  * @throws RequiredError if there were no results for this query.
96
103
  */
97
104
  get data() {
98
- return callAsync(getQueryData, this.max(1).results, this);
105
+ return callAsync(getQueryData, this.provider.getQuery(this.max(1)), this);
99
106
  }
100
107
  /**
101
108
  * Subscribe to all matching documents.
@@ -105,17 +112,7 @@ export class DataQuery extends Query {
105
112
  * @return Function that ends the subscription.
106
113
  */
107
114
  subscribe(next) {
108
- return this.provider.subscribeQuery(this, typeof next === "function" ? { next } : next);
109
- }
110
- /**
111
- * Subscribe to all matching documents.
112
- * - `next()` is called once with the initial results, and again any time the results change.
113
- *
114
- * @param next Observer with `next`, `error`, or `complete` methods or a `next()` dispatcher.
115
- * @return Function that ends the subscription.
116
- */
117
- subscribeMap(next) {
118
- return this.provider.subscribeQuery(this, new TransformObserver(toMap, typeof next === "function" ? { next } : next));
115
+ return this.provider.subscribeQuery(this, new ResultsObserver(typeof next === "function" ? { next } : next));
119
116
  }
120
117
  /**
121
118
  * Set all matching documents to the same exact value.
@@ -144,7 +141,7 @@ export class DataQuery extends Query {
144
141
  }
145
142
  /** Iterate over the resuls (will throw `Promise` if the results are asynchronous). */
146
143
  [Symbol.iterator]() {
147
- return throwAsync(this.results)[Symbol.iterator]();
144
+ return throwAsync(this.entries)[Symbol.iterator]();
148
145
  }
149
146
  /** Validate a set of results for this query reference. */
150
147
  *validate(unsafeEntries) {
@@ -170,14 +167,14 @@ export class DataQuery extends Query {
170
167
  }
171
168
  }
172
169
  /** Get the data for a document from a result for that document. */
173
- export function getQueryData(results, ref) {
174
- const first = getFirstItem(results);
170
+ export function getQueryData(entries, ref) {
171
+ const first = getFirstItem(entries);
175
172
  if (first)
176
173
  return first;
177
174
  throw new QueryRequiredError(ref);
178
175
  }
179
176
  /** A document reference within a specific database. */
180
- export class DataDocument {
177
+ export class DatabaseDocument {
181
178
  constructor(provider, validator, collection, id) {
182
179
  this.provider = provider;
183
180
  this.validator = validator;
@@ -186,23 +183,21 @@ export class DataDocument {
186
183
  }
187
184
  /** Create a query on this document's collection. */
188
185
  query(filters, sorts, limit) {
189
- return new DataQuery(this.provider, this.validator, this.collection, filters, sorts, limit);
186
+ return new DatabaseQuery(this.provider, this.validator, this.collection, filters, sorts, limit);
190
187
  }
191
188
  /** Get an 'optional' reference to this document (uses a `ModelQuery` with an `id` filter). */
192
189
  get optional() {
193
- return new DataQuery(this.provider, this.validator, this.collection, new Filters(new EqualFilter("id", this.id)));
190
+ return new DatabaseQuery(this.provider, this.validator, this.collection, new Filters(new EqualFilter("id", this.id)));
194
191
  }
195
192
  /**
196
193
  * Does this document exist?
197
- *
198
- * @return Document's data, or `undefined` if the document doesn't exist (possibly promised).
194
+ * @return `true` if a document exists or `false` otherwise (possibly promised).
199
195
  */
200
196
  get exists() {
201
197
  return callAsync(Boolean, this.provider.get(this));
202
198
  }
203
199
  /**
204
200
  * Get the result of this document.
205
- *
206
201
  * @return Document's data, or `undefined` if the document doesn't exist (possibly promised).
207
202
  */
208
203
  get result() {
@@ -1,16 +1,16 @@
1
- import { ResultsMap, Entry, Results, Data } from "../util/index.js";
1
+ import { Results, Entry, Entries, Data } from "../util/index.js";
2
2
  import { State } from "../stream/index.js";
3
- import { DataQuery } from "./Database.js";
3
+ import { DatabaseQuery } from "./Database.js";
4
4
  /**
5
5
  * State that wraps a `Documents` reference to enable pagination.
6
6
  * - If you pass in initial values, it will use that as the first page.
7
7
  * - If you don't pass in initial values, it will autoload the first page.
8
8
  */
9
- export declare class Pagination<T extends Data> extends State<ResultsMap<T>> implements Iterable<Entry<T>> {
9
+ export declare class Pagination<T extends Data> extends State<Results<T>> implements Iterable<Entry<T>> {
10
10
  protected _pending: boolean;
11
- readonly ref: DataQuery<T>;
11
+ readonly ref: DatabaseQuery<T>;
12
12
  readonly limit: number;
13
- constructor(ref: DataQuery<T>);
13
+ constructor(ref: DatabaseQuery<T>);
14
14
  /**
15
15
  * Load more results after the end.
16
16
  * - Promise that needs to be handled.
@@ -20,7 +20,7 @@ export declare class Pagination<T extends Data> extends State<ResultsMap<T>> imp
20
20
  * Merge more results into this pagination.
21
21
  * @return The change in the number of results.
22
22
  */
23
- merge(more: Results<T>): void;
23
+ merge(more: Entries<T>): void;
24
24
  /** Iterate over the entries of the values currently in the pagination. */
25
25
  [Symbol.iterator](): Iterator<Entry<T>>;
26
26
  }
package/db/Pagination.js CHANGED
@@ -1,4 +1,4 @@
1
- import { getLastItem, assertNumber, yieldMerged, toMap, LOADING, assertMaximum } from "../util/index.js";
1
+ import { getLastItem, assertNumber, yieldMerged, getMap, LOADING, assertMax } from "../util/index.js";
2
2
  import { State } from "../stream/index.js";
3
3
  import { ConditionError } from "../index.js";
4
4
  /**
@@ -22,7 +22,7 @@ export class Pagination extends State {
22
22
  if (!this.loading) {
23
23
  const lastItem = getLastItem(this.value);
24
24
  if (lastItem) {
25
- const next = await this.ref.after(lastItem[0], lastItem[1]).resultsMap;
25
+ const next = await this.ref.after(lastItem[0], lastItem[1]).results;
26
26
  this.merge(next);
27
27
  if (next.size < this.limit)
28
28
  this.complete();
@@ -31,7 +31,7 @@ export class Pagination extends State {
31
31
  }
32
32
  }
33
33
  this._value === LOADING;
34
- const next = await this.ref.resultsMap;
34
+ const next = await this.ref.results;
35
35
  this.next(next);
36
36
  if (next.size < this.limit)
37
37
  this.complete();
@@ -40,7 +40,7 @@ export class Pagination extends State {
40
40
  };
41
41
  this.ref = ref;
42
42
  assertNumber(ref.limit); // Collection must have a numeric limit to paginate (otherwise you'd be retrieving the entire set of documents).
43
- assertMaximum(ref.sorts.size, 1); // Collection must have at least one sort order to paginate.
43
+ assertMax(ref.sorts.size, 1); // Collection must have at least one sort order to paginate.
44
44
  this.limit = ref.limit;
45
45
  }
46
46
  /**
@@ -48,7 +48,7 @@ export class Pagination extends State {
48
48
  * @return The change in the number of results.
49
49
  */
50
50
  merge(more) {
51
- this.next(toMap(this.ref.sorts.transform(yieldMerged(more, this.value))));
51
+ this.next(getMap(this.ref.sorts.transform(yieldMerged(more, this.value))));
52
52
  }
53
53
  /** Iterate over the entries of the values currently in the pagination. */
54
54
  [Symbol.iterator]() {
package/db/Write.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { PropUpdates, Update } from "../update/index.js";
2
- import { ImmutableArray, Data, Transformable } from "../util/index.js";
3
- import type { Database, DataDocument } from "./Database.js";
2
+ import { ImmutableArray, Data, Transformable, Key, Nullish } from "../util/index.js";
3
+ import type { Database, DatabaseDocument } from "./Database.js";
4
4
  /** Represent a write made to a database. */
5
5
  export declare abstract class Write implements Transformable<Database, void | PromiseLike<void>> {
6
6
  abstract transform(db: Database): void | PromiseLike<void>;
@@ -19,19 +19,23 @@ export declare class Writes extends Write {
19
19
  export declare abstract class DocumentWrite<T extends Data> extends Write {
20
20
  readonly collection: string;
21
21
  readonly id: string;
22
- constructor({ collection, id }: DataDocument<T>);
22
+ constructor({ collection, id }: DatabaseDocument<T>);
23
23
  }
24
24
  /** Represent a set operation made to a single document in a database. */
25
25
  export declare class DocumentSet<T extends Data> extends DocumentWrite<T> {
26
26
  readonly data: T;
27
- constructor(ref: DataDocument<T>, data: T);
27
+ constructor(ref: DatabaseDocument<T>, data: T);
28
28
  transform(db: Database): Promise<void>;
29
+ /** Set one of the props on this set operation to a different value. */
30
+ set<K extends Key<T>>(key: Nullish<K>, value: T[K]): this;
29
31
  }
30
32
  /** Represent an update operation made to a single document in a database. */
31
33
  export declare class DocumentUpdate<T extends Data> extends DocumentWrite<T> {
32
- readonly updates: Update<T>;
33
- constructor(ref: DataDocument<T>, updates: Update<T> | PropUpdates<T>);
34
+ readonly updates: PropUpdates<T>;
35
+ constructor(ref: DatabaseDocument<T>, updates: PropUpdates<T>);
34
36
  transform(db: Database): Promise<void>;
37
+ /** update one of the props on this set operation to a different value. */
38
+ update<K extends Key<T>>(key: Nullish<K>, value: T[K] | Update<T[K]>): this;
35
39
  }
36
40
  /** Represent a delete operation made to a single document in a database. */
37
41
  export declare class DocumentDelete<T extends Data> extends DocumentWrite<T> {
package/db/Write.js CHANGED
@@ -1,5 +1,4 @@
1
- import { DataUpdate, Update } from "../update/index.js";
2
- import { transform } from "../util/index.js";
1
+ import { transform, isNullish } from "../util/index.js";
3
2
  /** Represent a write made to a database. */
4
3
  export class Write {
5
4
  }
@@ -35,16 +34,28 @@ export class DocumentSet extends DocumentWrite {
35
34
  async transform(db) {
36
35
  await db.doc(this.collection, this.id).set(this.data);
37
36
  }
37
+ /** Set one of the props on this set operation to a different value. */
38
+ set(key, value) {
39
+ if (isNullish(key))
40
+ return this;
41
+ return { __proto__: Object.getPrototypeOf(this), ...this, data: { ...this.data, [key]: value } };
42
+ }
38
43
  }
39
44
  /** Represent an update operation made to a single document in a database. */
40
45
  export class DocumentUpdate extends DocumentWrite {
41
46
  constructor(ref, updates) {
42
47
  super(ref);
43
- this.updates = updates instanceof Update ? updates : new DataUpdate(updates);
48
+ this.updates = updates;
44
49
  }
45
50
  async transform(db) {
46
51
  await db.doc(this.collection, this.id).update(this.updates);
47
52
  }
53
+ /** update one of the props on this set operation to a different value. */
54
+ update(key, value) {
55
+ if (isNullish(key))
56
+ return this;
57
+ return { __proto__: Object.getPrototypeOf(this), ...this, updates: { ...this.updates, [key]: value } };
58
+ }
48
59
  }
49
60
  /** Represent a delete operation made to a single document in a database. */
50
61
  export class DocumentDelete extends DocumentWrite {
package/db/errors.d.ts CHANGED
@@ -1,24 +1,24 @@
1
1
  import type { Data } from "../util/index.js";
2
2
  import { RequiredError, ValidationError } from "../error/index.js";
3
3
  import type { Feedback } from "../feedback/index.js";
4
- import type { DataDocument, DataQuery } from "./Database.js";
4
+ import type { DatabaseDocument, DatabaseQuery } from "./Database.js";
5
5
  /** Thrown if a document doesn't exist. */
6
6
  export declare class DocumentRequiredError<T extends Data> extends RequiredError {
7
- ref: DataDocument<T>;
8
- constructor(ref: DataDocument<T>);
7
+ ref: DatabaseDocument<T>;
8
+ constructor(ref: DatabaseDocument<T>);
9
9
  }
10
10
  /** Thrown if a query doesn't exist. */
11
11
  export declare class QueryRequiredError<T extends Data> extends RequiredError {
12
- ref: DataQuery<T>;
13
- constructor(ref: DataQuery<T>);
12
+ ref: DatabaseQuery<T>;
13
+ constructor(ref: DatabaseQuery<T>);
14
14
  }
15
15
  /** Thrown if a document can't validate. */
16
16
  export declare class DocumentValidationError<T extends Data> extends ValidationError {
17
- ref: DataDocument<T>;
18
- constructor(ref: DataDocument<T>, feedback: Feedback);
17
+ ref: DatabaseDocument<T>;
18
+ constructor(ref: DatabaseDocument<T>, feedback: Feedback);
19
19
  }
20
20
  /** Thrown if a query can't validate a set of results. */
21
21
  export declare class QueryValidationError<T extends Data> extends ValidationError {
22
- ref: DataQuery<T>;
23
- constructor(ref: DataQuery<T>, feedback: Feedback);
22
+ ref: DatabaseQuery<T>;
23
+ constructor(ref: DatabaseQuery<T>, feedback: Feedback);
24
24
  }
@@ -1,5 +1,5 @@
1
1
  import type { Firestore } from "firebase/firestore";
2
- import { Results, Provider, DataDocument, DataQuery, Result, Observer, Update, AsynchronousProvider, Data, Unsubscriber } from "../../index.js";
2
+ import { Entries, Provider, DatabaseDocument, DatabaseQuery, Result, Observer, Update, AsynchronousProvider, Data, Unsubscriber } from "../../index.js";
3
3
  /**
4
4
  * Firestore client database provider.
5
5
  * - Works with the Firebase JS SDK.
@@ -9,15 +9,15 @@ import { Results, Provider, DataDocument, DataQuery, Result, Observer, Update, A
9
9
  export declare class FirestoreClientProvider extends Provider implements AsynchronousProvider {
10
10
  readonly firestore: Firestore;
11
11
  constructor(firestore: Firestore);
12
- get<T extends Data>(ref: DataDocument<T>): Promise<Result<T>>;
13
- subscribe<T extends Data>(ref: DataDocument<T>, observer: Observer<Result<T>>): Unsubscriber;
14
- add<T extends Data>(ref: DataQuery<T>, data: T): Promise<string>;
15
- set<T extends Data>(ref: DataDocument<T>, data: T): Promise<void>;
16
- update<T extends Data>(ref: DataDocument<T>, updates: Update<T>): Promise<void>;
17
- delete<T extends Data>(ref: DataDocument<T>): Promise<void>;
18
- getQuery<T extends Data>(ref: DataQuery<T>): Promise<Results<T>>;
19
- subscribeQuery<T extends Data>(ref: DataQuery<T>, observer: Observer<Results<T>>): Unsubscriber;
20
- setQuery<T extends Data>(ref: DataQuery<T>, data: T): Promise<number>;
21
- updateQuery<T extends Data>(ref: DataQuery<T>, updates: Update<T>): Promise<number>;
22
- deleteQuery<T extends Data>(ref: DataQuery<T>): Promise<number>;
12
+ get<T extends Data>(ref: DatabaseDocument<T>): Promise<Result<T>>;
13
+ subscribe<T extends Data>(ref: DatabaseDocument<T>, observer: Observer<Result<T>>): Unsubscriber;
14
+ add<T extends Data>(ref: DatabaseQuery<T>, data: T): Promise<string>;
15
+ set<T extends Data>(ref: DatabaseDocument<T>, data: T): Promise<void>;
16
+ update<T extends Data>(ref: DatabaseDocument<T>, updates: Update<T>): Promise<void>;
17
+ delete<T extends Data>(ref: DatabaseDocument<T>): Promise<void>;
18
+ getQuery<T extends Data>(ref: DatabaseQuery<T>): Promise<Entries<T>>;
19
+ subscribeQuery<T extends Data>(ref: DatabaseQuery<T>, observer: Observer<Entries<T>>): Unsubscriber;
20
+ setQuery<T extends Data>(ref: DatabaseQuery<T>, data: T): Promise<number>;
21
+ updateQuery<T extends Data>(ref: DatabaseQuery<T>, updates: Update<T>): Promise<number>;
22
+ deleteQuery<T extends Data>(ref: DatabaseQuery<T>): Promise<number>;
23
23
  }
@@ -1,5 +1,5 @@
1
1
  import type { Firestore } from "firebase/firestore/lite";
2
- import { Provider, DataDocument, DataQuery, Result, Update, AsynchronousProvider, Data, Results, Unsubscriber } from "../../index.js";
2
+ import { Provider, DatabaseDocument, DatabaseQuery, Result, Update, AsynchronousProvider, Data, Entries, Unsubscriber } from "../../index.js";
3
3
  /**
4
4
  * Firestore Lite client database provider.
5
5
  * - Works with the Firebase JS SDK.
@@ -9,15 +9,15 @@ import { Provider, DataDocument, DataQuery, Result, Update, AsynchronousProvider
9
9
  export declare class FirestoreClientProvider extends Provider implements AsynchronousProvider {
10
10
  readonly firestore: Firestore;
11
11
  constructor(firestore: Firestore);
12
- get<T extends Data>(ref: DataDocument<T>): Promise<Result<T>>;
12
+ get<T extends Data>(ref: DatabaseDocument<T>): Promise<Result<T>>;
13
13
  subscribe(): Unsubscriber;
14
- add<T extends Data>(ref: DataQuery<T>, data: T): Promise<string>;
15
- set<T extends Data>(ref: DataDocument<T>, data: T): Promise<void>;
16
- update<T extends Data>(ref: DataDocument<T>, updates: Update<T>): Promise<void>;
17
- delete<T extends Data>(ref: DataDocument<T>): Promise<void>;
18
- getQuery<T extends Data>(ref: DataQuery<T>): Promise<Results<T>>;
14
+ add<T extends Data>(ref: DatabaseQuery<T>, data: T): Promise<string>;
15
+ set<T extends Data>(ref: DatabaseDocument<T>, data: T): Promise<void>;
16
+ update<T extends Data>(ref: DatabaseDocument<T>, updates: Update<T>): Promise<void>;
17
+ delete<T extends Data>(ref: DatabaseDocument<T>): Promise<void>;
18
+ getQuery<T extends Data>(ref: DatabaseQuery<T>): Promise<Entries<T>>;
19
19
  subscribeQuery(): Unsubscriber;
20
- setQuery<T extends Data>(ref: DataQuery<T>, data: T | Update<T> | undefined): Promise<number>;
21
- updateQuery<T extends Data>(ref: DataQuery<T>, updates: Update<T>): Promise<number>;
22
- deleteQuery<T extends Data>(ref: DataQuery<T>): Promise<number>;
20
+ setQuery<T extends Data>(ref: DatabaseQuery<T>, data: T | Update<T> | undefined): Promise<number>;
21
+ updateQuery<T extends Data>(ref: DatabaseQuery<T>, updates: Update<T>): Promise<number>;
22
+ deleteQuery<T extends Data>(ref: DatabaseQuery<T>): Promise<number>;
23
23
  }
@@ -1,5 +1,5 @@
1
1
  import { Firestore } from "@google-cloud/firestore";
2
- import { Provider, DataDocument, DataQuery, Observer, Result, Update, Data, AsynchronousProvider, Entry, Results, Unsubscriber } from "../../index.js";
2
+ import { Provider, DatabaseDocument, DatabaseQuery, Observer, Result, Update, Data, AsynchronousProvider, Entry, Entries, Unsubscriber } from "../../index.js";
3
3
  /**
4
4
  * Firestore server database provider.
5
5
  * - Works with the Firebase Admin SDK for Node.JS
@@ -7,15 +7,15 @@ import { Provider, DataDocument, DataQuery, Observer, Result, Update, Data, Asyn
7
7
  export declare class FirestoreServerProvider extends Provider implements AsynchronousProvider {
8
8
  readonly firestore: Firestore;
9
9
  constructor(firestore?: Firestore);
10
- get<T extends Data>(ref: DataDocument<T>): Promise<Result<T>>;
11
- subscribe<T extends Data>(ref: DataDocument<T>, observer: Observer<Result<T>>): Unsubscriber;
12
- add<T extends Data>(ref: DataQuery<T>, data: T): Promise<string>;
13
- set<T extends Data>(ref: DataDocument<T>, data: T): Promise<void>;
14
- update<T extends Data>(ref: DataDocument<T>, updates: Update<T>): Promise<void>;
15
- delete<T extends Data>(ref: DataDocument<T>): Promise<void>;
16
- getQuery<T extends Data>(ref: DataQuery<T>): Promise<Iterable<Entry<T>>>;
17
- subscribeQuery<T extends Data>(ref: DataQuery<T>, observer: Observer<Results<T>>): Unsubscriber;
18
- setQuery<T extends Data>(ref: DataQuery<T>, data: T | Update<T> | undefined): Promise<number>;
19
- updateQuery<T extends Data>(ref: DataQuery<T>, updates: Update<T>): Promise<number>;
20
- deleteQuery<T extends Data>(ref: DataQuery<T>): Promise<number>;
10
+ get<T extends Data>(ref: DatabaseDocument<T>): Promise<Result<T>>;
11
+ subscribe<T extends Data>(ref: DatabaseDocument<T>, observer: Observer<Result<T>>): Unsubscriber;
12
+ add<T extends Data>(ref: DatabaseQuery<T>, data: T): Promise<string>;
13
+ set<T extends Data>(ref: DatabaseDocument<T>, data: T): Promise<void>;
14
+ update<T extends Data>(ref: DatabaseDocument<T>, updates: Update<T>): Promise<void>;
15
+ delete<T extends Data>(ref: DatabaseDocument<T>): Promise<void>;
16
+ getQuery<T extends Data>(ref: DatabaseQuery<T>): Promise<Iterable<Entry<T>>>;
17
+ subscribeQuery<T extends Data>(ref: DatabaseQuery<T>, observer: Observer<Entries<T>>): Unsubscriber;
18
+ setQuery<T extends Data>(ref: DatabaseQuery<T>, data: T | Update<T> | undefined): Promise<number>;
19
+ updateQuery<T extends Data>(ref: DatabaseQuery<T>, updates: Update<T>): Promise<number>;
20
+ deleteQuery<T extends Data>(ref: DatabaseQuery<T>): Promise<number>;
21
21
  }
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "state-management",
12
12
  "query-builder"
13
13
  ],
14
- "version": "1.36.0",
14
+ "version": "1.40.0",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -60,12 +60,12 @@
60
60
  },
61
61
  "devDependencies": {
62
62
  "@google-cloud/firestore": "^4.15.1",
63
- "@types/jest": "^27.0.3",
64
- "@types/react": "^17.0.37",
63
+ "@types/jest": "^27.4.0",
64
+ "@types/react": "^17.0.38",
65
65
  "@types/react-dom": "^17.0.11",
66
- "@typescript-eslint/eslint-plugin": "^5.7.0",
67
- "@typescript-eslint/parser": "^5.7.0",
68
- "eslint": "^8.5.0",
66
+ "@typescript-eslint/eslint-plugin": "^5.8.1",
67
+ "@typescript-eslint/parser": "^5.8.1",
68
+ "eslint": "^8.6.0",
69
69
  "eslint-config-prettier": "^8.3.0",
70
70
  "eslint-plugin-import": "^2.25.3",
71
71
  "eslint-plugin-prettier": "^4.0.0",