shelving 1.37.0 → 1.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/db/Database.d.ts CHANGED
@@ -51,9 +51,14 @@ export declare class DataQuery<T extends Data = Data> extends Query<T> implement
51
51
  get resultsMap(): ResultsMap<T> | PromiseLike<ResultsMap<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
  *
@@ -124,13 +129,11 @@ export declare class DataDocument<T extends Data = Data> implements Observable<R
124
129
  get optional(): DataQuery<T>;
125
130
  /**
126
131
  * Does this document exist?
127
- *
128
- * @return Document's data, or `undefined` if the document doesn't exist (possibly promised).
132
+ * @return `true` if a document exists or `false` otherwise (possibly promised).
129
133
  */
130
134
  get exists(): boolean | PromiseLike<boolean>;
131
135
  /**
132
136
  * Get the result of this document.
133
- *
134
137
  * @return Document's data, or `undefined` if the document doesn't exist (possibly promised).
135
138
  */
136
139
  get result(): Result<T> | PromiseLike<Result<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, toMap, countItems, TransformObserver, NOT_NULLISH, hasItems, } 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";
@@ -74,11 +74,18 @@ export class DataQuery extends Query {
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
80
  return callAsync(countItems, this.results);
81
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.max(1).results);
88
+ }
82
89
  /**
83
90
  * Get an entry for the first document matched by this query or `undefined` if this query has no results.
84
91
  *
@@ -194,15 +201,13 @@ export class DataDocument {
194
201
  }
195
202
  /**
196
203
  * Does this document exist?
197
- *
198
- * @return Document's data, or `undefined` if the document doesn't exist (possibly promised).
204
+ * @return `true` if a document exists or `false` otherwise (possibly promised).
199
205
  */
200
206
  get exists() {
201
207
  return callAsync(Boolean, this.provider.get(this));
202
208
  }
203
209
  /**
204
210
  * Get the result of this document.
205
- *
206
211
  * @return Document's data, or `undefined` if the document doesn't exist (possibly promised).
207
212
  */
208
213
  get result() {
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "state-management",
12
12
  "query-builder"
13
13
  ],
14
- "version": "1.37.0",
14
+ "version": "1.38.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",
package/util/iterate.d.ts CHANGED
@@ -32,6 +32,16 @@ export declare function countItems(items: Iterable<unknown>): number;
32
32
  * - Note: this consumes the iterable so you won't be able to use it again.
33
33
  */
34
34
  export declare function countIterations(items: Iterable<unknown>): number;
35
+ /**
36
+ * Does an iterable have one or more items.
37
+ * - Checks `items.size` or `items.length` first, or consumes the iterable and counts its iterations.
38
+ */
39
+ export declare function hasItems(items: Iterable<unknown>): boolean;
40
+ /**
41
+ * Does an iterable have one or more items.
42
+ * - Checks `items.size` or `items.length` first, or consumes the iterable and counts its iterations.
43
+ */
44
+ export declare function hasIterations(items: Iterable<unknown>): boolean;
35
45
  /**
36
46
  * Yield a range of numbers from `start` to `end`
37
47
  * - Yields in descending order if `end` is lower than `start`
package/util/iterate.js CHANGED
@@ -32,6 +32,23 @@ export function countIterations(items) {
32
32
  count++; // eslint-disable-line @typescript-eslint/no-unused-vars
33
33
  return count;
34
34
  }
35
+ /**
36
+ * Does an iterable have one or more items.
37
+ * - Checks `items.size` or `items.length` first, or consumes the iterable and counts its iterations.
38
+ */
39
+ export function hasItems(items) {
40
+ var _a;
41
+ return !!((_a = getKnownSize(items)) !== null && _a !== void 0 ? _a : hasIterations(items));
42
+ }
43
+ /**
44
+ * Does an iterable have one or more items.
45
+ * - Checks `items.size` or `items.length` first, or consumes the iterable and counts its iterations.
46
+ */
47
+ export function hasIterations(items) {
48
+ for (const unused of items)
49
+ return true; // eslint-disable-line @typescript-eslint/no-unused-vars
50
+ return false;
51
+ }
35
52
  /**
36
53
  * Yield a range of numbers from `start` to `end`
37
54
  * - Yields in descending order if `end` is lower than `start`