firestore-batch-updater 1.17.0 → 1.18.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
@@ -30,6 +30,7 @@
30
30
  - 고유값 조회 - `distinct()`로 특정 필드의 중복 없는 값 목록 조회
31
31
  - JSON 내보내기/가져오기 - `toJSON()` / `fromJSON()`으로 문서 JSON 파일 내보내기/가져오기
32
32
  - 그룹별 개수 조회 - `countBy()`로 특정 필드 값별 문서 수 집계
33
+ - 그룹별 문서 조회 - `groupBy()`로 필드 값별로 문서 그룹핑
33
34
  - 랜덤 샘플링 - `sample()`로 쿼리 결과에서 랜덤 문서 추출
34
35
  - 필드 값 추출 - `pluck()`로 특정 필드 값만 간단하게 배열로 추출
35
36
  - 문서 ID 추출 - `pluckIds()`로 매칭 문서의 ID만 배열로 추출
@@ -136,6 +137,7 @@ console.log(`${result.successCount}개 문서 업데이트 완료`);
136
137
  | `toJSON(path, options?)` | 문서를 JSON 파일로 내보내기 | `ToJSONResult` |
137
138
  | `fromJSON(path, options?)` | JSON 파일에서 문서 가져오기 | `FromJSONResult` |
138
139
  | `countBy(field)` | 필드 값별 문서 수 집계 | `CountByResult` |
140
+ | `groupBy(field)` | 필드 값별 문서 그룹핑 | `GroupByResult` |
139
141
  | `getFields(field)` | 특정 필드 값 조회 | `FieldValueResult[]` |
140
142
 
141
143
  ### 옵션
@@ -194,6 +196,7 @@ console.log(`${result.successCount}개 문서 업데이트 완료`);
194
196
  | `ToJSONResult` | `filePath`, `documentCount` |
195
197
  | `FromJSONResult` | `successCount`, `failureCount`, `totalCount`, `createdIds[]`, `failedDocIds?`, `logFilePath?` |
196
198
  | `CountByResult` | `{ [value]: number }` |
199
+ | `GroupByResult` | `{ [value]: { id, data }[] }` |
197
200
  | `FieldValueResult` | `id`, `value` |
198
201
 
199
202
  ## 사용 예시
@@ -812,6 +815,33 @@ const countryCounts = await updater.collection("users").countBy("address.country
812
815
  console.log(countryCounts); // { US: 80, KR: 45, JP: 25 }
813
816
  ```
814
817
 
818
+ ### 필드 값별 문서 그룹핑
819
+
820
+ ```typescript
821
+ // 필드 값별로 문서를 그룹핑 (전체 문서 데이터 포함)
822
+ const usersByRole = await updater.collection("users").groupBy("role");
823
+
824
+ console.log(`관리자: ${usersByRole.admin.length}명`);
825
+ usersByRole.admin.forEach(user => {
826
+ console.log(`- ${user.id}: ${user.data.name}`);
827
+ });
828
+
829
+ // where 필터와 함께 사용
830
+ const activeProducts = await updater
831
+ .collection("products")
832
+ .where("status", "==", "active")
833
+ .groupBy("category");
834
+
835
+ for (const [category, products] of Object.entries(activeProducts)) {
836
+ console.log(`${category}: ${products.length}개`);
837
+ }
838
+
839
+ // 중첩 필드 지원
840
+ const usersByCountry = await updater
841
+ .collection("users")
842
+ .groupBy("address.country");
843
+ ```
844
+
815
845
  ### JSON 가져오기
816
846
 
817
847
  ```typescript
package/README.md CHANGED
@@ -30,6 +30,7 @@ English | [한국어](./README.ko.md)
30
30
  - Distinct values - Use `distinct()` to get unique field values from matching documents
31
31
  - JSON export/import - Use `toJSON()` / `fromJSON()` to export/import documents as JSON
32
32
  - Group counting - Use `countBy()` to count documents grouped by field value
33
+ - Group documents - Use `groupBy()` to group matching documents by a field value
33
34
  - Random sampling - Use `sample()` to get random documents from query results
34
35
  - Field value extraction - Use `pluck()` to get a simple array of field values
35
36
  - Document ID extraction - Use `pluckIds()` to get an array of matching document IDs
@@ -136,6 +137,7 @@ console.log(`Updated ${result.successCount} documents`);
136
137
  | `toJSON(path, options?)` | Export documents to JSON file | `ToJSONResult` |
137
138
  | `fromJSON(path, options?)` | Import documents from JSON file | `FromJSONResult` |
138
139
  | `countBy(field)` | Count documents grouped by field value | `CountByResult` |
140
+ | `groupBy(field)` | Group documents by field value | `GroupByResult` |
139
141
  | `getFields(field)` | Get specific field values | `FieldValueResult[]` |
140
142
 
141
143
  ### Options
@@ -194,6 +196,7 @@ All write operations support an optional `options` parameter:
194
196
  | `ToJSONResult` | `filePath`, `documentCount` |
195
197
  | `FromJSONResult` | `successCount`, `failureCount`, `totalCount`, `createdIds[]`, `failedDocIds?`, `logFilePath?` |
196
198
  | `CountByResult` | `{ [value]: number }` |
199
+ | `GroupByResult` | `{ [value]: { id, data }[] }` |
197
200
  | `FieldValueResult` | `id`, `value` |
198
201
 
199
202
  ## Usage Examples
@@ -825,6 +828,33 @@ const countryCounts = await updater.collection("users").countBy("address.country
825
828
  console.log(countryCounts); // { US: 80, KR: 45, JP: 25 }
826
829
  ```
827
830
 
831
+ ### Group Documents by Field Value
832
+
833
+ ```typescript
834
+ // Group documents by a field value (with full document data)
835
+ const usersByRole = await updater.collection("users").groupBy("role");
836
+
837
+ console.log(`Admins: ${usersByRole.admin.length}`);
838
+ usersByRole.admin.forEach(user => {
839
+ console.log(`- ${user.id}: ${user.data.name}`);
840
+ });
841
+
842
+ // With where filter
843
+ const activeProducts = await updater
844
+ .collection("products")
845
+ .where("status", "==", "active")
846
+ .groupBy("category");
847
+
848
+ for (const [category, products] of Object.entries(activeProducts)) {
849
+ console.log(`${category}: ${products.length} products`);
850
+ }
851
+
852
+ // Nested field support
853
+ const usersByCountry = await updater
854
+ .collection("users")
855
+ .groupBy("address.country");
856
+ ```
857
+
828
858
  ### Import from JSON
829
859
 
830
860
  ```typescript
package/dist/index.d.mts CHANGED
@@ -472,6 +472,16 @@ interface FieldStatsResult {
472
472
  interface CountByResult {
473
473
  [value: string]: number;
474
474
  }
475
+ /**
476
+ * Result of groupBy operation
477
+ * Field value → array of matching documents
478
+ */
479
+ interface GroupByResult {
480
+ [value: string]: {
481
+ id: string;
482
+ data: Record<string, any>;
483
+ }[];
484
+ }
475
485
  /**
476
486
  * Options for fromJSON operation
477
487
  */
@@ -811,6 +821,12 @@ declare class BatchUpdater {
811
821
  * @returns Object mapping field values to their document counts
812
822
  */
813
823
  countBy(field: string): Promise<CountByResult>;
824
+ /**
825
+ * Group matching documents by a specific field value
826
+ * @param field - Field path to group by
827
+ * @returns Object mapping field values to arrays of matching documents { id, data }
828
+ */
829
+ groupBy(field: string): Promise<GroupByResult>;
814
830
  /**
815
831
  * Import documents from a JSON file into Firestore
816
832
  * @param filePath - Path to the JSON file to import
@@ -915,4 +931,4 @@ declare function isValidUpdateData(value: any): value is Record<string, any>;
915
931
  */
916
932
  declare function formatError(error: unknown, context?: string): string;
917
933
 
918
- export { type AggregateResult, type AggregateSpec, BatchUpdater, type BulkCreateInput, type BulkCreateOptions, type BulkCreateResult, type BulkDeleteOptions, type BulkDeleteResult, type BulkUpdateInput, type BulkUpdateOptions, type BulkUpdateResult, type CopyToOptions, type CopyToResult, type CountByResult, type CountResult, type CreateDocumentInput, type CreateOneResult, type CreateOptions, type CreateResult, type DeleteOptions, type DeleteResult, type DocumentSnapshot, type DryRunResult, type FieldStatsResult, type FieldValueResult, type FromJSONOptions, type FromJSONResult, type LogEntry, type LogOptions, type OperationLog, type OrderByCondition, type PaginateOptions, type PaginateResult, type PreviewResult, type ProgressInfo, type ToJSONOptions, type ToJSONResult, type TransformFn, type TransformOptions, type TransformResult, type UpdateOptions, type UpdateResult, type UpsertOptions, type UpsertResult, type WhereCondition, calculateProgress, createLogCollector, formatError, formatOperationLog, getAffectedFields, isValidUpdateData, mergeUpdateData, writeOperationLog };
934
+ export { type AggregateResult, type AggregateSpec, BatchUpdater, type BulkCreateInput, type BulkCreateOptions, type BulkCreateResult, type BulkDeleteOptions, type BulkDeleteResult, type BulkUpdateInput, type BulkUpdateOptions, type BulkUpdateResult, type CopyToOptions, type CopyToResult, type CountByResult, type CountResult, type CreateDocumentInput, type CreateOneResult, type CreateOptions, type CreateResult, type DeleteOptions, type DeleteResult, type DocumentSnapshot, type DryRunResult, type FieldStatsResult, type FieldValueResult, type FromJSONOptions, type FromJSONResult, type GroupByResult, type LogEntry, type LogOptions, type OperationLog, type OrderByCondition, type PaginateOptions, type PaginateResult, type PreviewResult, type ProgressInfo, type ToJSONOptions, type ToJSONResult, type TransformFn, type TransformOptions, type TransformResult, type UpdateOptions, type UpdateResult, type UpsertOptions, type UpsertResult, type WhereCondition, calculateProgress, createLogCollector, formatError, formatOperationLog, getAffectedFields, isValidUpdateData, mergeUpdateData, writeOperationLog };
package/dist/index.d.ts CHANGED
@@ -472,6 +472,16 @@ interface FieldStatsResult {
472
472
  interface CountByResult {
473
473
  [value: string]: number;
474
474
  }
475
+ /**
476
+ * Result of groupBy operation
477
+ * Field value → array of matching documents
478
+ */
479
+ interface GroupByResult {
480
+ [value: string]: {
481
+ id: string;
482
+ data: Record<string, any>;
483
+ }[];
484
+ }
475
485
  /**
476
486
  * Options for fromJSON operation
477
487
  */
@@ -811,6 +821,12 @@ declare class BatchUpdater {
811
821
  * @returns Object mapping field values to their document counts
812
822
  */
813
823
  countBy(field: string): Promise<CountByResult>;
824
+ /**
825
+ * Group matching documents by a specific field value
826
+ * @param field - Field path to group by
827
+ * @returns Object mapping field values to arrays of matching documents { id, data }
828
+ */
829
+ groupBy(field: string): Promise<GroupByResult>;
814
830
  /**
815
831
  * Import documents from a JSON file into Firestore
816
832
  * @param filePath - Path to the JSON file to import
@@ -915,4 +931,4 @@ declare function isValidUpdateData(value: any): value is Record<string, any>;
915
931
  */
916
932
  declare function formatError(error: unknown, context?: string): string;
917
933
 
918
- export { type AggregateResult, type AggregateSpec, BatchUpdater, type BulkCreateInput, type BulkCreateOptions, type BulkCreateResult, type BulkDeleteOptions, type BulkDeleteResult, type BulkUpdateInput, type BulkUpdateOptions, type BulkUpdateResult, type CopyToOptions, type CopyToResult, type CountByResult, type CountResult, type CreateDocumentInput, type CreateOneResult, type CreateOptions, type CreateResult, type DeleteOptions, type DeleteResult, type DocumentSnapshot, type DryRunResult, type FieldStatsResult, type FieldValueResult, type FromJSONOptions, type FromJSONResult, type LogEntry, type LogOptions, type OperationLog, type OrderByCondition, type PaginateOptions, type PaginateResult, type PreviewResult, type ProgressInfo, type ToJSONOptions, type ToJSONResult, type TransformFn, type TransformOptions, type TransformResult, type UpdateOptions, type UpdateResult, type UpsertOptions, type UpsertResult, type WhereCondition, calculateProgress, createLogCollector, formatError, formatOperationLog, getAffectedFields, isValidUpdateData, mergeUpdateData, writeOperationLog };
934
+ export { type AggregateResult, type AggregateSpec, BatchUpdater, type BulkCreateInput, type BulkCreateOptions, type BulkCreateResult, type BulkDeleteOptions, type BulkDeleteResult, type BulkUpdateInput, type BulkUpdateOptions, type BulkUpdateResult, type CopyToOptions, type CopyToResult, type CountByResult, type CountResult, type CreateDocumentInput, type CreateOneResult, type CreateOptions, type CreateResult, type DeleteOptions, type DeleteResult, type DocumentSnapshot, type DryRunResult, type FieldStatsResult, type FieldValueResult, type FromJSONOptions, type FromJSONResult, type GroupByResult, type LogEntry, type LogOptions, type OperationLog, type OrderByCondition, type PaginateOptions, type PaginateResult, type PreviewResult, type ProgressInfo, type ToJSONOptions, type ToJSONResult, type TransformFn, type TransformOptions, type TransformResult, type UpdateOptions, type UpdateResult, type UpsertOptions, type UpsertResult, type WhereCondition, calculateProgress, createLogCollector, formatError, formatOperationLog, getAffectedFields, isValidUpdateData, mergeUpdateData, writeOperationLog };
package/dist/index.js CHANGED
@@ -1450,6 +1450,31 @@ var BatchUpdater = class {
1450
1450
  }
1451
1451
  return counts;
1452
1452
  }
1453
+ /**
1454
+ * Group matching documents by a specific field value
1455
+ * @param field - Field path to group by
1456
+ * @returns Object mapping field values to arrays of matching documents { id, data }
1457
+ */
1458
+ async groupBy(field) {
1459
+ this.validateSetup();
1460
+ if (!field || typeof field !== "string") {
1461
+ throw new Error("Field path is required");
1462
+ }
1463
+ const query = this.buildQuery();
1464
+ const snapshot = await query.get();
1465
+ const groups = {};
1466
+ for (const doc of snapshot.docs) {
1467
+ const data = doc.data();
1468
+ const value = this.getNestedValue(data, field);
1469
+ if (value === void 0 || value === null) continue;
1470
+ const key = String(value);
1471
+ if (!groups[key]) {
1472
+ groups[key] = [];
1473
+ }
1474
+ groups[key].push({ id: doc.id, data });
1475
+ }
1476
+ return groups;
1477
+ }
1453
1478
  /**
1454
1479
  * Import documents from a JSON file into Firestore
1455
1480
  * @param filePath - Path to the JSON file to import
package/dist/index.mjs CHANGED
@@ -1405,6 +1405,31 @@ var BatchUpdater = class {
1405
1405
  }
1406
1406
  return counts;
1407
1407
  }
1408
+ /**
1409
+ * Group matching documents by a specific field value
1410
+ * @param field - Field path to group by
1411
+ * @returns Object mapping field values to arrays of matching documents { id, data }
1412
+ */
1413
+ async groupBy(field) {
1414
+ this.validateSetup();
1415
+ if (!field || typeof field !== "string") {
1416
+ throw new Error("Field path is required");
1417
+ }
1418
+ const query = this.buildQuery();
1419
+ const snapshot = await query.get();
1420
+ const groups = {};
1421
+ for (const doc of snapshot.docs) {
1422
+ const data = doc.data();
1423
+ const value = this.getNestedValue(data, field);
1424
+ if (value === void 0 || value === null) continue;
1425
+ const key = String(value);
1426
+ if (!groups[key]) {
1427
+ groups[key] = [];
1428
+ }
1429
+ groups[key].push({ id: doc.id, data });
1430
+ }
1431
+ return groups;
1432
+ }
1408
1433
  /**
1409
1434
  * Import documents from a JSON file into Firestore
1410
1435
  * @param filePath - Path to the JSON file to import
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firestore-batch-updater",
3
- "version": "1.17.0",
3
+ "version": "1.18.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",