firestore-batch-updater 1.10.0 → 1.11.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/README.ko.md CHANGED
@@ -17,6 +17,7 @@
17
17
  - 필드 선택 - `select()`로 필요한 필드만 로드 (메모리 및 비용 절약)
18
18
  - 단일 문서 작업 - `findOne()`, `createOne()`, `updateOne()`, `deleteOne()`으로 효율적인 단일 문서 처리
19
19
  - 존재 여부 확인 - `exists()`로 매칭 문서 존재 여부 빠르게 확인
20
+ - 비어있는지 확인 - `isEmpty()`로 매칭 문서가 없는지 확인 (`exists()`의 반대)
20
21
  - 전체 문서 조회 - `getAll()`로 매칭되는 모든 문서 데이터 조회
21
22
  - 집계 쿼리 - `aggregate()`로 서버 사이드 `sum`, `average`, `count` 연산
22
23
  - 커서 페이지네이션 - `paginate()`로 메모리 효율적인 페이지 단위 조회
@@ -99,6 +100,7 @@ console.log(`${result.successCount}개 문서 업데이트 완료`);
99
100
  | `select(...fields)` | 특정 필드만 조회 (체이닝 가능) | `this` |
100
101
  | `count()` | 매칭되는 문서 개수 조회 | `CountResult` |
101
102
  | `exists()` | 매칭되는 문서 존재 여부 확인 | `boolean` |
103
+ | `isEmpty()` | 매칭되는 문서가 없는지 확인 | `boolean` |
102
104
  | `findOne()` | 첫 번째 매칭 문서 조회 | `{ id, data } \| null` |
103
105
  | `getOne(id)` | ID로 문서 직접 조회 | `{ id, data } \| null` |
104
106
  | `getAll()` | 모든 매칭 문서 조회 | `{ id, data }[]` |
package/README.md CHANGED
@@ -17,6 +17,7 @@ English | [한국어](./README.ko.md)
17
17
  - Field selection - Use `select()` to load only needed fields (saves memory and costs)
18
18
  - Single document operations - Use `findOne()`, `createOne()`, `updateOne()`, `deleteOne()` for efficient single-doc ops
19
19
  - Existence check - Use `exists()` to quickly check if matching documents exist
20
+ - Empty check - Use `isEmpty()` to check if no matching documents exist (opposite of `exists()`)
20
21
  - Get all documents - Use `getAll()` to retrieve all matching documents with data
21
22
  - Aggregation - Use `aggregate()` for server-side `sum`, `average`, and `count` operations
22
23
  - Cursor pagination - Use `paginate()` for memory-efficient page-by-page iteration
@@ -99,6 +100,7 @@ console.log(`Updated ${result.successCount} documents`);
99
100
  | `select(...fields)` | Select specific fields to retrieve (chainable) | `this` |
100
101
  | `count()` | Count matching documents | `CountResult` |
101
102
  | `exists()` | Check if matching documents exist | `boolean` |
103
+ | `isEmpty()` | Check if no matching documents exist | `boolean` |
102
104
  | `findOne()` | Find first matching document | `{ id, data } \| null` |
103
105
  | `getOne(id)` | Get document by ID directly | `{ id, data } \| null` |
104
106
  | `getAll()` | Get all matching documents | `{ id, data }[]` |
@@ -425,6 +427,31 @@ if (hasOldLogs) {
425
427
  }
426
428
  ```
427
429
 
430
+ ### Check if Collection is Empty
431
+
432
+ ```typescript
433
+ // Check if there are no pending orders
434
+ const noPending = await updater
435
+ .collection("orders")
436
+ .where("status", "==", "pending")
437
+ .isEmpty();
438
+
439
+ if (noPending) {
440
+ console.log("No pending orders - all caught up!");
441
+ }
442
+
443
+ // Opposite of exists() - useful for guard clauses
444
+ const noAdmins = await updater
445
+ .collection("users")
446
+ .where("role", "==", "admin")
447
+ .isEmpty();
448
+
449
+ if (noAdmins) {
450
+ console.log("Warning: No admin users found - creating default admin");
451
+ await updater.collection("users").createOne({ role: "admin", name: "Default Admin" });
452
+ }
453
+ ```
454
+
428
455
  ### Get All Documents
429
456
 
430
457
  ```typescript
package/dist/index.d.mts CHANGED
@@ -585,6 +585,12 @@ declare class BatchUpdater {
585
585
  * @returns True if at least one document exists, false otherwise
586
586
  */
587
587
  exists(): Promise<boolean>;
588
+ /**
589
+ * Check if no documents match the query conditions
590
+ * Opposite of exists() - returns true when the collection/query has no matching documents
591
+ * @returns true if no documents match, false otherwise
592
+ */
593
+ isEmpty(): Promise<boolean>;
588
594
  /**
589
595
  * Get all documents matching the query conditions
590
596
  * @returns Array of documents with id and data
package/dist/index.d.ts CHANGED
@@ -585,6 +585,12 @@ declare class BatchUpdater {
585
585
  * @returns True if at least one document exists, false otherwise
586
586
  */
587
587
  exists(): Promise<boolean>;
588
+ /**
589
+ * Check if no documents match the query conditions
590
+ * Opposite of exists() - returns true when the collection/query has no matching documents
591
+ * @returns true if no documents match, false otherwise
592
+ */
593
+ isEmpty(): Promise<boolean>;
588
594
  /**
589
595
  * Get all documents matching the query conditions
590
596
  * @returns Array of documents with id and data
package/dist/index.js CHANGED
@@ -319,6 +319,15 @@ var BatchUpdater = class {
319
319
  const snapshot = await query.count().get();
320
320
  return snapshot.data().count > 0;
321
321
  }
322
+ /**
323
+ * Check if no documents match the query conditions
324
+ * Opposite of exists() - returns true when the collection/query has no matching documents
325
+ * @returns true if no documents match, false otherwise
326
+ */
327
+ async isEmpty() {
328
+ const result = await this.exists();
329
+ return !result;
330
+ }
322
331
  /**
323
332
  * Get all documents matching the query conditions
324
333
  * @returns Array of documents with id and data
package/dist/index.mjs CHANGED
@@ -274,6 +274,15 @@ var BatchUpdater = class {
274
274
  const snapshot = await query.count().get();
275
275
  return snapshot.data().count > 0;
276
276
  }
277
+ /**
278
+ * Check if no documents match the query conditions
279
+ * Opposite of exists() - returns true when the collection/query has no matching documents
280
+ * @returns true if no documents match, false otherwise
281
+ */
282
+ async isEmpty() {
283
+ const result = await this.exists();
284
+ return !result;
285
+ }
277
286
  /**
278
287
  * Get all documents matching the query conditions
279
288
  * @returns Array of documents with id and data
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firestore-batch-updater",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "Batch update Firestore documents with query-based filtering and preview",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",