firestore-batch-updater 1.19.0 → 1.20.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 +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +24 -0
- package/dist/index.mjs +24 -0
- package/package.json +1 -1
package/README.ko.md
CHANGED
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
- 커서 페이지네이션 - `paginate()`로 메모리 효율적인 페이지 단위 조회
|
|
26
26
|
- ID 직접 조회 - `getOne()`으로 문서 ID로 빠른 조회
|
|
27
27
|
- 문서 ID 존재 확인 - `has(id)`로 데이터 읽기 없이 특정 문서 ID 존재 여부 확인
|
|
28
|
+
- 다중 ID 조회 - `pick(ids)`로 여러 문서 ID를 한 번에 효율적으로 조회
|
|
28
29
|
- 벌크 작업 - `bulkCreate()`, `bulkUpdate()`, `bulkDelete()`로 여러 문서에 각기 다른 데이터로 효율적 처리
|
|
29
30
|
- 문서 변환 - `transform()`으로 각 문서에 커스텀 로직 적용 (가격 인상, 데이터 마이그레이션 등)
|
|
30
31
|
- 복사 & 이동 - `copyTo()`로 컬렉션 간 문서 복사/이동 (데이터 변환 옵션 포함)
|
|
@@ -111,6 +112,7 @@ console.log(`${result.successCount}개 문서 업데이트 완료`);
|
|
|
111
112
|
| `findOne()` | 첫 번째 매칭 문서 조회 | `{ id, data } \| null` |
|
|
112
113
|
| `getOne(id)` | ID로 문서 직접 조회 | `{ id, data } \| null` |
|
|
113
114
|
| `has(id)` | 문서 ID 존재 여부 확인 | `boolean` |
|
|
115
|
+
| `pick(ids)` | 여러 문서 ID로 한 번에 조회 | `{ id, data }[]` |
|
|
114
116
|
| `getAll()` | 모든 매칭 문서 조회 | `{ id, data }[]` |
|
|
115
117
|
| `preview(data)` | 업데이트 전 미리보기 | `PreviewResult` |
|
|
116
118
|
| `update(data, options?)` | 매칭되는 문서 업데이트 | `UpdateResult` |
|
|
@@ -666,6 +668,24 @@ if (!(await updater.collection("users").has(userId))) {
|
|
|
666
668
|
}
|
|
667
669
|
```
|
|
668
670
|
|
|
671
|
+
### 여러 문서 ID로 조회
|
|
672
|
+
|
|
673
|
+
```typescript
|
|
674
|
+
// 여러 문서를 한 번에 조회 (getOne() 여러 번 호출보다 효율적)
|
|
675
|
+
const users = await updater
|
|
676
|
+
.collection("users")
|
|
677
|
+
.pick(["user-1", "user-2", "user-3"]);
|
|
678
|
+
|
|
679
|
+
console.log(`${users.length}명 조회됨`);
|
|
680
|
+
users.forEach((u) => console.log(`${u.id}: ${u.data.name}`));
|
|
681
|
+
|
|
682
|
+
// 존재하지 않는 ID는 자동으로 건너뜀
|
|
683
|
+
const docs = await updater
|
|
684
|
+
.collection("products")
|
|
685
|
+
.pick(["prod-1", "non-existent", "prod-3"]);
|
|
686
|
+
// prod-1, prod-3만 반환 (존재하는 경우)
|
|
687
|
+
```
|
|
688
|
+
|
|
669
689
|
### 벌크 업데이트
|
|
670
690
|
|
|
671
691
|
```typescript
|
package/README.md
CHANGED
|
@@ -25,6 +25,7 @@ English | [한국어](./README.ko.md)
|
|
|
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
27
|
- Document ID check - Use `has(id)` to check if a specific document ID exists without reading data
|
|
28
|
+
- Multi-ID lookup - Use `pick(ids)` to get multiple documents by IDs in a single efficient call
|
|
28
29
|
- Bulk operations - Use `bulkCreate()`, `bulkUpdate()`, `bulkDelete()` for efficient multi-document operations with different data each
|
|
29
30
|
- Transform - Use `transform()` to apply custom logic to each document (e.g., price increase, data migration)
|
|
30
31
|
- Copy & Move - Use `copyTo()` to copy/move documents between collections with optional data transformation
|
|
@@ -111,6 +112,7 @@ console.log(`Updated ${result.successCount} documents`);
|
|
|
111
112
|
| `findOne()` | Find first matching document | `{ id, data } \| null` |
|
|
112
113
|
| `getOne(id)` | Get document by ID directly | `{ id, data } \| null` |
|
|
113
114
|
| `has(id)` | Check if document ID exists | `boolean` |
|
|
115
|
+
| `pick(ids)` | Get multiple documents by IDs | `{ id, data }[]` |
|
|
114
116
|
| `getAll()` | Get all matching documents | `{ id, data }[]` |
|
|
115
117
|
| `preview(data)` | Preview changes before update | `PreviewResult` |
|
|
116
118
|
| `update(data, options?)` | Update matching documents | `UpdateResult` |
|
|
@@ -685,6 +687,24 @@ if (!(await updater.collection("users").has(userId))) {
|
|
|
685
687
|
}
|
|
686
688
|
```
|
|
687
689
|
|
|
690
|
+
### Get Multiple Documents by IDs
|
|
691
|
+
|
|
692
|
+
```typescript
|
|
693
|
+
// Get multiple documents in a single call (more efficient than multiple getOne)
|
|
694
|
+
const users = await updater
|
|
695
|
+
.collection("users")
|
|
696
|
+
.pick(["user-1", "user-2", "user-3"]);
|
|
697
|
+
|
|
698
|
+
console.log(`Found ${users.length} users`);
|
|
699
|
+
users.forEach((u) => console.log(`${u.id}: ${u.data.name}`));
|
|
700
|
+
|
|
701
|
+
// Non-existent IDs are silently skipped
|
|
702
|
+
const docs = await updater
|
|
703
|
+
.collection("products")
|
|
704
|
+
.pick(["prod-1", "non-existent", "prod-3"]);
|
|
705
|
+
// Returns only prod-1 and prod-3 (if they exist)
|
|
706
|
+
```
|
|
707
|
+
|
|
688
708
|
### Bulk Update with Different Data
|
|
689
709
|
|
|
690
710
|
```typescript
|
package/dist/index.d.mts
CHANGED
|
@@ -635,6 +635,15 @@ declare class BatchUpdater {
|
|
|
635
635
|
* @returns true if the document exists, false otherwise
|
|
636
636
|
*/
|
|
637
637
|
has(id: string): Promise<boolean>;
|
|
638
|
+
/**
|
|
639
|
+
* Get multiple documents by their IDs in a single call
|
|
640
|
+
* @param ids - Array of document IDs to retrieve
|
|
641
|
+
* @returns Array of documents with id and data (skips non-existent documents)
|
|
642
|
+
*/
|
|
643
|
+
pick(ids: string[]): Promise<{
|
|
644
|
+
id: string;
|
|
645
|
+
data: Record<string, any>;
|
|
646
|
+
}[]>;
|
|
638
647
|
/**
|
|
639
648
|
* Update the first document matching the query conditions
|
|
640
649
|
* @param updateData - Data to update
|
package/dist/index.d.ts
CHANGED
|
@@ -635,6 +635,15 @@ declare class BatchUpdater {
|
|
|
635
635
|
* @returns true if the document exists, false otherwise
|
|
636
636
|
*/
|
|
637
637
|
has(id: string): Promise<boolean>;
|
|
638
|
+
/**
|
|
639
|
+
* Get multiple documents by their IDs in a single call
|
|
640
|
+
* @param ids - Array of document IDs to retrieve
|
|
641
|
+
* @returns Array of documents with id and data (skips non-existent documents)
|
|
642
|
+
*/
|
|
643
|
+
pick(ids: string[]): Promise<{
|
|
644
|
+
id: string;
|
|
645
|
+
data: Record<string, any>;
|
|
646
|
+
}[]>;
|
|
638
647
|
/**
|
|
639
648
|
* Update the first document matching the query conditions
|
|
640
649
|
* @param updateData - Data to update
|
package/dist/index.js
CHANGED
|
@@ -392,6 +392,30 @@ var BatchUpdater = class {
|
|
|
392
392
|
const docSnapshot = await docRef.get();
|
|
393
393
|
return docSnapshot.exists;
|
|
394
394
|
}
|
|
395
|
+
/**
|
|
396
|
+
* Get multiple documents by their IDs in a single call
|
|
397
|
+
* @param ids - Array of document IDs to retrieve
|
|
398
|
+
* @returns Array of documents with id and data (skips non-existent documents)
|
|
399
|
+
*/
|
|
400
|
+
async pick(ids) {
|
|
401
|
+
this.validateSetup();
|
|
402
|
+
if (!Array.isArray(ids) || ids.length === 0) {
|
|
403
|
+
throw new Error("Document IDs array is required and must not be empty");
|
|
404
|
+
}
|
|
405
|
+
if (this.isCollectionGroup) {
|
|
406
|
+
throw new Error(
|
|
407
|
+
"pick() cannot be used with collectionGroup(). Use getAll() with where conditions instead."
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
const docRefs = ids.map(
|
|
411
|
+
(id) => this.firestore.collection(this.collectionPath).doc(id)
|
|
412
|
+
);
|
|
413
|
+
const snapshots = await this.firestore.getAll(...docRefs);
|
|
414
|
+
return snapshots.filter((snap) => snap.exists).map((snap) => ({
|
|
415
|
+
id: snap.id,
|
|
416
|
+
data: snap.data()
|
|
417
|
+
}));
|
|
418
|
+
}
|
|
395
419
|
/**
|
|
396
420
|
* Update the first document matching the query conditions
|
|
397
421
|
* @param updateData - Data to update
|
package/dist/index.mjs
CHANGED
|
@@ -347,6 +347,30 @@ var BatchUpdater = class {
|
|
|
347
347
|
const docSnapshot = await docRef.get();
|
|
348
348
|
return docSnapshot.exists;
|
|
349
349
|
}
|
|
350
|
+
/**
|
|
351
|
+
* Get multiple documents by their IDs in a single call
|
|
352
|
+
* @param ids - Array of document IDs to retrieve
|
|
353
|
+
* @returns Array of documents with id and data (skips non-existent documents)
|
|
354
|
+
*/
|
|
355
|
+
async pick(ids) {
|
|
356
|
+
this.validateSetup();
|
|
357
|
+
if (!Array.isArray(ids) || ids.length === 0) {
|
|
358
|
+
throw new Error("Document IDs array is required and must not be empty");
|
|
359
|
+
}
|
|
360
|
+
if (this.isCollectionGroup) {
|
|
361
|
+
throw new Error(
|
|
362
|
+
"pick() cannot be used with collectionGroup(). Use getAll() with where conditions instead."
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
const docRefs = ids.map(
|
|
366
|
+
(id) => this.firestore.collection(this.collectionPath).doc(id)
|
|
367
|
+
);
|
|
368
|
+
const snapshots = await this.firestore.getAll(...docRefs);
|
|
369
|
+
return snapshots.filter((snap) => snap.exists).map((snap) => ({
|
|
370
|
+
id: snap.id,
|
|
371
|
+
data: snap.data()
|
|
372
|
+
}));
|
|
373
|
+
}
|
|
350
374
|
/**
|
|
351
375
|
* Update the first document matching the query conditions
|
|
352
376
|
* @param updateData - Data to update
|