firestore-batch-updater 1.18.0 → 1.19.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 +20 -0
- package/README.md +20 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +19 -0
- package/dist/index.mjs +19 -0
- package/package.json +1 -1
package/README.ko.md
CHANGED
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
- 통합 통계 - `fieldStats()`로 sum/avg/min/max/count 한 번에 조회
|
|
25
25
|
- 커서 페이지네이션 - `paginate()`로 메모리 효율적인 페이지 단위 조회
|
|
26
26
|
- ID 직접 조회 - `getOne()`으로 문서 ID로 빠른 조회
|
|
27
|
+
- 문서 ID 존재 확인 - `has(id)`로 데이터 읽기 없이 특정 문서 ID 존재 여부 확인
|
|
27
28
|
- 벌크 작업 - `bulkCreate()`, `bulkUpdate()`, `bulkDelete()`로 여러 문서에 각기 다른 데이터로 효율적 처리
|
|
28
29
|
- 문서 변환 - `transform()`으로 각 문서에 커스텀 로직 적용 (가격 인상, 데이터 마이그레이션 등)
|
|
29
30
|
- 복사 & 이동 - `copyTo()`로 컬렉션 간 문서 복사/이동 (데이터 변환 옵션 포함)
|
|
@@ -109,6 +110,7 @@ console.log(`${result.successCount}개 문서 업데이트 완료`);
|
|
|
109
110
|
| `isEmpty()` | 매칭되는 문서가 없는지 확인 | `boolean` |
|
|
110
111
|
| `findOne()` | 첫 번째 매칭 문서 조회 | `{ id, data } \| null` |
|
|
111
112
|
| `getOne(id)` | ID로 문서 직접 조회 | `{ id, data } \| null` |
|
|
113
|
+
| `has(id)` | 문서 ID 존재 여부 확인 | `boolean` |
|
|
112
114
|
| `getAll()` | 모든 매칭 문서 조회 | `{ id, data }[]` |
|
|
113
115
|
| `preview(data)` | 업데이트 전 미리보기 | `PreviewResult` |
|
|
114
116
|
| `update(data, options?)` | 매칭되는 문서 업데이트 | `UpdateResult` |
|
|
@@ -646,6 +648,24 @@ const order = await updater
|
|
|
646
648
|
.getOne("order-456");
|
|
647
649
|
```
|
|
648
650
|
|
|
651
|
+
### 문서 ID 존재 확인
|
|
652
|
+
|
|
653
|
+
```typescript
|
|
654
|
+
// 특정 문서 ID가 존재하는지 확인 (데이터 읽기 없이 효율적)
|
|
655
|
+
const exists = await updater.collection("users").has("user-123");
|
|
656
|
+
|
|
657
|
+
if (exists) {
|
|
658
|
+
console.log("사용자가 존재합니다!");
|
|
659
|
+
} else {
|
|
660
|
+
console.log("사용자를 찾을 수 없음");
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
// 가드 절에 유용
|
|
664
|
+
if (!(await updater.collection("users").has(userId))) {
|
|
665
|
+
throw new Error("사용자를 찾을 수 없습니다");
|
|
666
|
+
}
|
|
667
|
+
```
|
|
668
|
+
|
|
649
669
|
### 벌크 업데이트
|
|
650
670
|
|
|
651
671
|
```typescript
|
package/README.md
CHANGED
|
@@ -24,6 +24,7 @@ English | [한국어](./README.ko.md)
|
|
|
24
24
|
- Combined stats - Use `fieldStats()` to get sum/avg/min/max/count in one call
|
|
25
25
|
- Cursor pagination - Use `paginate()` for memory-efficient page-by-page iteration
|
|
26
26
|
- Direct ID lookup - Use `getOne()` for fast document retrieval by ID
|
|
27
|
+
- Document ID check - Use `has(id)` to check if a specific document ID exists without reading data
|
|
27
28
|
- Bulk operations - Use `bulkCreate()`, `bulkUpdate()`, `bulkDelete()` for efficient multi-document operations with different data each
|
|
28
29
|
- Transform - Use `transform()` to apply custom logic to each document (e.g., price increase, data migration)
|
|
29
30
|
- Copy & Move - Use `copyTo()` to copy/move documents between collections with optional data transformation
|
|
@@ -109,6 +110,7 @@ console.log(`Updated ${result.successCount} documents`);
|
|
|
109
110
|
| `isEmpty()` | Check if no matching documents exist | `boolean` |
|
|
110
111
|
| `findOne()` | Find first matching document | `{ id, data } \| null` |
|
|
111
112
|
| `getOne(id)` | Get document by ID directly | `{ id, data } \| null` |
|
|
113
|
+
| `has(id)` | Check if document ID exists | `boolean` |
|
|
112
114
|
| `getAll()` | Get all matching documents | `{ id, data }[]` |
|
|
113
115
|
| `preview(data)` | Preview changes before update | `PreviewResult` |
|
|
114
116
|
| `update(data, options?)` | Update matching documents | `UpdateResult` |
|
|
@@ -665,6 +667,24 @@ const profile = await updater
|
|
|
665
667
|
.getOne("user-123");
|
|
666
668
|
```
|
|
667
669
|
|
|
670
|
+
### Check Document Exists by ID
|
|
671
|
+
|
|
672
|
+
```typescript
|
|
673
|
+
// Check if a specific document ID exists (without reading data)
|
|
674
|
+
const exists = await updater.collection("users").has("user-123");
|
|
675
|
+
|
|
676
|
+
if (exists) {
|
|
677
|
+
console.log("User exists!");
|
|
678
|
+
} else {
|
|
679
|
+
console.log("User not found");
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
// Useful for guard clauses before operations
|
|
683
|
+
if (!(await updater.collection("users").has(userId))) {
|
|
684
|
+
throw new Error("User not found");
|
|
685
|
+
}
|
|
686
|
+
```
|
|
687
|
+
|
|
668
688
|
### Bulk Update with Different Data
|
|
669
689
|
|
|
670
690
|
```typescript
|
package/dist/index.d.mts
CHANGED
|
@@ -629,6 +629,12 @@ declare class BatchUpdater {
|
|
|
629
629
|
id: string;
|
|
630
630
|
data: Record<string, any>;
|
|
631
631
|
} | null>;
|
|
632
|
+
/**
|
|
633
|
+
* Check if a document with the given ID exists in the collection
|
|
634
|
+
* @param id - Document ID to check
|
|
635
|
+
* @returns true if the document exists, false otherwise
|
|
636
|
+
*/
|
|
637
|
+
has(id: string): Promise<boolean>;
|
|
632
638
|
/**
|
|
633
639
|
* Update the first document matching the query conditions
|
|
634
640
|
* @param updateData - Data to update
|
package/dist/index.d.ts
CHANGED
|
@@ -629,6 +629,12 @@ declare class BatchUpdater {
|
|
|
629
629
|
id: string;
|
|
630
630
|
data: Record<string, any>;
|
|
631
631
|
} | null>;
|
|
632
|
+
/**
|
|
633
|
+
* Check if a document with the given ID exists in the collection
|
|
634
|
+
* @param id - Document ID to check
|
|
635
|
+
* @returns true if the document exists, false otherwise
|
|
636
|
+
*/
|
|
637
|
+
has(id: string): Promise<boolean>;
|
|
632
638
|
/**
|
|
633
639
|
* Update the first document matching the query conditions
|
|
634
640
|
* @param updateData - Data to update
|
package/dist/index.js
CHANGED
|
@@ -373,6 +373,25 @@ var BatchUpdater = class {
|
|
|
373
373
|
data: docSnapshot.data()
|
|
374
374
|
};
|
|
375
375
|
}
|
|
376
|
+
/**
|
|
377
|
+
* Check if a document with the given ID exists in the collection
|
|
378
|
+
* @param id - Document ID to check
|
|
379
|
+
* @returns true if the document exists, false otherwise
|
|
380
|
+
*/
|
|
381
|
+
async has(id) {
|
|
382
|
+
this.validateSetup();
|
|
383
|
+
if (!id || typeof id !== "string") {
|
|
384
|
+
throw new Error("Document ID is required");
|
|
385
|
+
}
|
|
386
|
+
if (this.isCollectionGroup) {
|
|
387
|
+
throw new Error(
|
|
388
|
+
"has() cannot be used with collectionGroup(). Use exists() with where conditions instead."
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
const docRef = this.firestore.collection(this.collectionPath).doc(id);
|
|
392
|
+
const docSnapshot = await docRef.get();
|
|
393
|
+
return docSnapshot.exists;
|
|
394
|
+
}
|
|
376
395
|
/**
|
|
377
396
|
* Update the first document matching the query conditions
|
|
378
397
|
* @param updateData - Data to update
|
package/dist/index.mjs
CHANGED
|
@@ -328,6 +328,25 @@ var BatchUpdater = class {
|
|
|
328
328
|
data: docSnapshot.data()
|
|
329
329
|
};
|
|
330
330
|
}
|
|
331
|
+
/**
|
|
332
|
+
* Check if a document with the given ID exists in the collection
|
|
333
|
+
* @param id - Document ID to check
|
|
334
|
+
* @returns true if the document exists, false otherwise
|
|
335
|
+
*/
|
|
336
|
+
async has(id) {
|
|
337
|
+
this.validateSetup();
|
|
338
|
+
if (!id || typeof id !== "string") {
|
|
339
|
+
throw new Error("Document ID is required");
|
|
340
|
+
}
|
|
341
|
+
if (this.isCollectionGroup) {
|
|
342
|
+
throw new Error(
|
|
343
|
+
"has() cannot be used with collectionGroup(). Use exists() with where conditions instead."
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
const docRef = this.firestore.collection(this.collectionPath).doc(id);
|
|
347
|
+
const docSnapshot = await docRef.get();
|
|
348
|
+
return docSnapshot.exists;
|
|
349
|
+
}
|
|
331
350
|
/**
|
|
332
351
|
* Update the first document matching the query conditions
|
|
333
352
|
* @param updateData - Data to update
|