@umituz/react-native-firebase 1.13.49 → 1.13.51
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/dist/scripts/cli-handlers.d.ts +27 -0
- package/dist/scripts/cli-handlers.d.ts.map +1 -0
- package/dist/scripts/cli-handlers.js +125 -0
- package/dist/scripts/cli-handlers.js.map +1 -0
- package/dist/scripts/cli-parser.d.ts +25 -0
- package/dist/scripts/cli-parser.d.ts.map +1 -0
- package/dist/scripts/cli-parser.js +101 -0
- package/dist/scripts/cli-parser.js.map +1 -0
- package/dist/scripts/cli.js +20 -155
- package/dist/scripts/cli.js.map +1 -1
- package/dist/scripts/firestore-operations.d.ts +18 -0
- package/dist/scripts/firestore-operations.d.ts.map +1 -0
- package/dist/scripts/firestore-operations.js +88 -0
- package/dist/scripts/firestore-operations.js.map +1 -0
- package/dist/scripts/firestore-queries.d.ts +27 -0
- package/dist/scripts/firestore-queries.d.ts.map +1 -0
- package/dist/scripts/firestore-queries.js +77 -0
- package/dist/scripts/firestore-queries.js.map +1 -0
- package/dist/scripts/firestore-seeding.d.ts +21 -0
- package/dist/scripts/firestore-seeding.d.ts.map +1 -0
- package/dist/scripts/firestore-seeding.js +67 -0
- package/dist/scripts/firestore-seeding.js.map +1 -0
- package/dist/scripts/firestore.d.ts +3 -48
- package/dist/scripts/firestore.d.ts.map +1 -1
- package/dist/scripts/firestore.js +16 -210
- package/dist/scripts/firestore.js.map +1 -1
- package/dist/scripts/user-commands.d.ts +33 -0
- package/dist/scripts/user-commands.d.ts.map +1 -0
- package/dist/scripts/user-commands.js +113 -0
- package/dist/scripts/user-commands.js.map +1 -0
- package/dist/scripts/user-formatters.d.ts +10 -0
- package/dist/scripts/user-formatters.d.ts.map +1 -0
- package/dist/scripts/user-formatters.js +55 -0
- package/dist/scripts/user-formatters.js.map +1 -0
- package/dist/scripts/user-queries.d.ts +42 -0
- package/dist/scripts/user-queries.d.ts.map +1 -0
- package/dist/scripts/user-queries.js +125 -0
- package/dist/scripts/user-queries.js.map +1 -0
- package/dist/scripts/user.d.ts +3 -67
- package/dist/scripts/user.d.ts.map +1 -1
- package/dist/scripts/user.js +15 -272
- package/dist/scripts/user.js.map +1 -1
- package/package.json +1 -1
- package/scripts/cli-handlers.ts +170 -0
- package/scripts/cli-parser.ts +82 -0
- package/scripts/cli.ts +27 -193
- package/scripts/firestore-operations.ts +111 -0
- package/scripts/firestore-queries.ts +97 -0
- package/scripts/firestore-seeding.ts +87 -0
- package/scripts/firestore.ts +20 -275
- package/scripts/user-commands.ts +104 -0
- package/scripts/user-formatters.ts +55 -0
- package/scripts/user-queries.ts +185 -0
- package/scripts/user.ts +19 -326
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firebase Admin Firestore Queries
|
|
3
|
+
* Query functions for reading Firestore data
|
|
4
|
+
*/
|
|
5
|
+
import * as admin from "firebase-admin";
|
|
6
|
+
import type { CollectionInfo } from "./types";
|
|
7
|
+
/**
|
|
8
|
+
* List all root-level collections
|
|
9
|
+
*/
|
|
10
|
+
export declare function listCollections(db: admin.firestore.Firestore): Promise<CollectionInfo[]>;
|
|
11
|
+
/**
|
|
12
|
+
* List subcollections for a user document
|
|
13
|
+
*/
|
|
14
|
+
export declare function listUserSubcollections(db: admin.firestore.Firestore, userId: string): Promise<CollectionInfo[]>;
|
|
15
|
+
/**
|
|
16
|
+
* Count documents in collection
|
|
17
|
+
*/
|
|
18
|
+
export declare function countDocuments(db: admin.firestore.Firestore, collectionPath: string): Promise<number>;
|
|
19
|
+
/**
|
|
20
|
+
* Get user document count statistics
|
|
21
|
+
*/
|
|
22
|
+
export declare function getUserStats(db: admin.firestore.Firestore): Promise<{
|
|
23
|
+
total: number;
|
|
24
|
+
anonymous: number;
|
|
25
|
+
authenticated: number;
|
|
26
|
+
}>;
|
|
27
|
+
//# sourceMappingURL=firestore-queries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firestore-queries.d.ts","sourceRoot":"","sources":["../../scripts/firestore-queries.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C;;GAEG;AACH,wBAAsB,eAAe,CACnC,EAAE,EAAE,KAAK,CAAC,SAAS,CAAC,SAAS,GAC5B,OAAO,CAAC,cAAc,EAAE,CAAC,CAqB3B;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,EAAE,EAAE,KAAK,CAAC,SAAS,CAAC,SAAS,EAC7B,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,cAAc,EAAE,CAAC,CAc3B;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,EAAE,EAAE,KAAK,CAAC,SAAS,CAAC,SAAS,EAC7B,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,MAAM,CAAC,CAGjB;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,EAAE,EAAE,KAAK,CAAC,SAAS,CAAC,SAAS,GAAG,OAAO,CAAC;IACzE,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC,CAoBD"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Firebase Admin Firestore Queries
|
|
4
|
+
* Query functions for reading Firestore data
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.listCollections = listCollections;
|
|
8
|
+
exports.listUserSubcollections = listUserSubcollections;
|
|
9
|
+
exports.countDocuments = countDocuments;
|
|
10
|
+
exports.getUserStats = getUserStats;
|
|
11
|
+
/**
|
|
12
|
+
* List all root-level collections
|
|
13
|
+
*/
|
|
14
|
+
async function listCollections(db) {
|
|
15
|
+
const collections = await db.listCollections();
|
|
16
|
+
const result = [];
|
|
17
|
+
for (const collection of collections) {
|
|
18
|
+
const snapshot = await collection.limit(1000).get();
|
|
19
|
+
const info = {
|
|
20
|
+
name: collection.id,
|
|
21
|
+
documentCount: snapshot.docs.length,
|
|
22
|
+
sampleDocumentId: snapshot.docs[0]?.id,
|
|
23
|
+
};
|
|
24
|
+
if (!snapshot.empty) {
|
|
25
|
+
const subcollections = await snapshot.docs[0].ref.listCollections();
|
|
26
|
+
info.hasSubcollections = subcollections.length > 0;
|
|
27
|
+
}
|
|
28
|
+
result.push(info);
|
|
29
|
+
}
|
|
30
|
+
return result.sort((a, b) => b.documentCount - a.documentCount);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* List subcollections for a user document
|
|
34
|
+
*/
|
|
35
|
+
async function listUserSubcollections(db, userId) {
|
|
36
|
+
const userRef = db.collection("users").doc(userId);
|
|
37
|
+
const subcollections = await userRef.listCollections();
|
|
38
|
+
const result = [];
|
|
39
|
+
for (const subcollection of subcollections) {
|
|
40
|
+
const count = await subcollection.count().get();
|
|
41
|
+
result.push({
|
|
42
|
+
name: subcollection.id,
|
|
43
|
+
documentCount: count.data().count,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Count documents in collection
|
|
50
|
+
*/
|
|
51
|
+
async function countDocuments(db, collectionPath) {
|
|
52
|
+
const count = await db.collection(collectionPath).count().get();
|
|
53
|
+
return count.data().count;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get user document count statistics
|
|
57
|
+
*/
|
|
58
|
+
async function getUserStats(db) {
|
|
59
|
+
const usersSnapshot = await db.collection("users").get();
|
|
60
|
+
let anonymous = 0;
|
|
61
|
+
let authenticated = 0;
|
|
62
|
+
usersSnapshot.docs.forEach((doc) => {
|
|
63
|
+
const data = doc.data();
|
|
64
|
+
if (data.isAnonymous) {
|
|
65
|
+
anonymous++;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
authenticated++;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return {
|
|
72
|
+
total: usersSnapshot.docs.length,
|
|
73
|
+
anonymous,
|
|
74
|
+
authenticated,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=firestore-queries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firestore-queries.js","sourceRoot":"","sources":["../../scripts/firestore-queries.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAQH,0CAuBC;AAKD,wDAiBC;AAKD,wCAMC;AAKD,oCAwBC;AAxFD;;GAEG;AACI,KAAK,UAAU,eAAe,CACnC,EAA6B;IAE7B,MAAM,WAAW,GAAG,MAAM,EAAE,CAAC,eAAe,EAAE,CAAC;IAC/C,MAAM,MAAM,GAAqB,EAAE,CAAC;IAEpC,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACrC,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC;QACpD,MAAM,IAAI,GAAmB;YAC3B,IAAI,EAAE,UAAU,CAAC,EAAE;YACnB,aAAa,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM;YACnC,gBAAgB,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;SACvC,CAAC;QAEF,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;YACpB,MAAM,cAAc,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC;YACpE,IAAI,CAAC,iBAAiB,GAAG,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC;QACrD,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAA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AAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,SAAS,EAAE,CAAC;QACd,CAAC;aAAM,CAAC;YACN,aAAa,EAAE,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,MAAM;QAChC,SAAS;QACT,aAAa;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firebase Admin Firestore Seeding
|
|
3
|
+
* Seed operations for Firestore data
|
|
4
|
+
*/
|
|
5
|
+
import * as admin from "firebase-admin";
|
|
6
|
+
import type { BatchResult } from "./types";
|
|
7
|
+
/**
|
|
8
|
+
* Seed documents in batches
|
|
9
|
+
*/
|
|
10
|
+
export declare function seedBatch(db: admin.firestore.Firestore, collectionPath: string, docs: Array<{
|
|
11
|
+
id: string;
|
|
12
|
+
data: Record<string, unknown>;
|
|
13
|
+
}>): Promise<BatchResult>;
|
|
14
|
+
/**
|
|
15
|
+
* Seed user subcollection
|
|
16
|
+
*/
|
|
17
|
+
export declare function seedUserSubcollection(db: admin.firestore.Firestore, userId: string, subcollectionName: string, docs: Array<{
|
|
18
|
+
id: string;
|
|
19
|
+
data: Record<string, unknown>;
|
|
20
|
+
}>): Promise<BatchResult>;
|
|
21
|
+
//# sourceMappingURL=firestore-seeding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firestore-seeding.d.ts","sourceRoot":"","sources":["../../scripts/firestore-seeding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAI3C;;GAEG;AACH,wBAAsB,SAAS,CAC7B,EAAE,EAAE,KAAK,CAAC,SAAS,CAAC,SAAS,EAC7B,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,CAAC,GACzD,OAAO,CAAC,WAAW,CAAC,CA6BtB;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,EAAE,EAAE,KAAK,CAAC,SAAS,CAAC,SAAS,EAC7B,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,MAAM,EACzB,IAAI,EAAE,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,CAAC,GACzD,OAAO,CAAC,WAAW,CAAC,CA8BtB"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Firebase Admin Firestore Seeding
|
|
4
|
+
* Seed operations for Firestore data
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.seedBatch = seedBatch;
|
|
8
|
+
exports.seedUserSubcollection = seedUserSubcollection;
|
|
9
|
+
const BATCH_SIZE = 500;
|
|
10
|
+
/**
|
|
11
|
+
* Seed documents in batches
|
|
12
|
+
*/
|
|
13
|
+
async function seedBatch(db, collectionPath, docs) {
|
|
14
|
+
const result = {
|
|
15
|
+
success: true,
|
|
16
|
+
processed: 0,
|
|
17
|
+
errors: [],
|
|
18
|
+
};
|
|
19
|
+
for (let i = 0; i < docs.length; i += BATCH_SIZE) {
|
|
20
|
+
const batch = db.batch();
|
|
21
|
+
const slice = docs.slice(i, i + BATCH_SIZE);
|
|
22
|
+
for (const { id, data } of slice) {
|
|
23
|
+
const ref = db.collection(collectionPath).doc(id);
|
|
24
|
+
const clean = Object.fromEntries(Object.entries(data).filter(([, v]) => v !== undefined));
|
|
25
|
+
batch.set(ref, clean);
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
await batch.commit();
|
|
29
|
+
result.processed += slice.length;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
result.success = false;
|
|
33
|
+
result.errors.push(`Batch failed at index ${i}: ${error}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Seed user subcollection
|
|
40
|
+
*/
|
|
41
|
+
async function seedUserSubcollection(db, userId, subcollectionName, docs) {
|
|
42
|
+
const result = {
|
|
43
|
+
success: true,
|
|
44
|
+
processed: 0,
|
|
45
|
+
errors: [],
|
|
46
|
+
};
|
|
47
|
+
const batch = db.batch();
|
|
48
|
+
for (const { id, data } of docs) {
|
|
49
|
+
const ref = db
|
|
50
|
+
.collection("users")
|
|
51
|
+
.doc(userId)
|
|
52
|
+
.collection(subcollectionName)
|
|
53
|
+
.doc(id);
|
|
54
|
+
const clean = Object.fromEntries(Object.entries(data).filter(([, v]) => v !== undefined));
|
|
55
|
+
batch.set(ref, clean);
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
await batch.commit();
|
|
59
|
+
result.processed = docs.length;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
result.success = false;
|
|
63
|
+
result.errors.push(`Failed to seed subcollection: ${error}`);
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=firestore-seeding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firestore-seeding.js","sourceRoot":"","sources":["../../scripts/firestore-seeding.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAUH,8BAiCC;AAKD,sDAmCC;AA9ED,MAAM,UAAU,GAAG,GAAG,CAAC;AAEvB;;GAEG;AACI,KAAK,UAAU,SAAS,CAC7B,EAA6B,EAC7B,cAAsB,EACtB,IAA0D;IAE1D,MAAM,MAAM,GAAgB;QAC1B,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,CAAC;QACZ,MAAM,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;KACX,CAAC;IAEF,MAAM,KAAK,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC;IAEzB,KAAK,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC;QAChC,MAAM,GAAG,GAAG,EAAE;aACX,UAAU,CAAC,OAAO,CAAC;aACnB,GAAG,CAAC,MAAM,CAAC;aACX,UAAU,CAAC,iBAAiB,CAAC;aAC7B,GAAG,CAAC,EAAE,CAAC,CAAC;QACX,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAC9B,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CACxD,CAAC;QACF,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACxB,CAAC;IAED,IAAI,CAAC;QACH,MAAM,KAAK,CAAC,MAAM,EAAE,CAAC;QACrB,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC;IACjC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC;QACvB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,iCAAiC,KAAK,EAAE,CAAC,CAAC;IAC/D,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -2,52 +2,7 @@
|
|
|
2
2
|
* Firebase Admin Firestore Utilities
|
|
3
3
|
* Generic Firestore operations for admin scripts
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* List all root-level collections
|
|
9
|
-
*/
|
|
10
|
-
export declare function listCollections(db: admin.firestore.Firestore): Promise<CollectionInfo[]>;
|
|
11
|
-
/**
|
|
12
|
-
* List subcollections for a user document
|
|
13
|
-
*/
|
|
14
|
-
export declare function listUserSubcollections(db: admin.firestore.Firestore, userId: string): Promise<CollectionInfo[]>;
|
|
15
|
-
/**
|
|
16
|
-
* Delete collection in batches
|
|
17
|
-
*/
|
|
18
|
-
export declare function deleteCollection(db: admin.firestore.Firestore, collectionPath: string, onProgress?: (deleted: number) => void): Promise<number>;
|
|
19
|
-
/**
|
|
20
|
-
* Delete user subcollection for all users
|
|
21
|
-
*/
|
|
22
|
-
export declare function deleteUserSubcollection(db: admin.firestore.Firestore, subcollectionName: string, onProgress?: (deleted: number) => void): Promise<number>;
|
|
23
|
-
/**
|
|
24
|
-
* Delete all Firestore data
|
|
25
|
-
*/
|
|
26
|
-
export declare function deleteAllData(db: admin.firestore.Firestore, onProgress?: (collection: string, deleted: number) => void): Promise<number>;
|
|
27
|
-
/**
|
|
28
|
-
* Seed documents in batches
|
|
29
|
-
*/
|
|
30
|
-
export declare function seedBatch(db: admin.firestore.Firestore, collectionPath: string, docs: Array<{
|
|
31
|
-
id: string;
|
|
32
|
-
data: Record<string, unknown>;
|
|
33
|
-
}>): Promise<BatchResult>;
|
|
34
|
-
/**
|
|
35
|
-
* Seed user subcollection
|
|
36
|
-
*/
|
|
37
|
-
export declare function seedUserSubcollection(db: admin.firestore.Firestore, userId: string, subcollectionName: string, docs: Array<{
|
|
38
|
-
id: string;
|
|
39
|
-
data: Record<string, unknown>;
|
|
40
|
-
}>): Promise<BatchResult>;
|
|
41
|
-
/**
|
|
42
|
-
* Count documents in collection
|
|
43
|
-
*/
|
|
44
|
-
export declare function countDocuments(db: admin.firestore.Firestore, collectionPath: string): Promise<number>;
|
|
45
|
-
/**
|
|
46
|
-
* Get user document count statistics
|
|
47
|
-
*/
|
|
48
|
-
export declare function getUserStats(db: admin.firestore.Firestore): Promise<{
|
|
49
|
-
total: number;
|
|
50
|
-
anonymous: number;
|
|
51
|
-
authenticated: number;
|
|
52
|
-
}>;
|
|
5
|
+
export { listCollections, listUserSubcollections, countDocuments, getUserStats, } from "./firestore-queries";
|
|
6
|
+
export { deleteCollection, deleteUserSubcollection, deleteAllData, } from "./firestore-operations";
|
|
7
|
+
export { seedBatch, seedUserSubcollection, } from "./firestore-seeding";
|
|
53
8
|
//# sourceMappingURL=firestore.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firestore.d.ts","sourceRoot":"","sources":["../../scripts/firestore.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"firestore.d.ts","sourceRoot":"","sources":["../../scripts/firestore.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,cAAc,EACd,YAAY,GACb,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,aAAa,GACd,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACL,SAAS,EACT,qBAAqB,GACtB,MAAM,qBAAqB,CAAC"}
|
|
@@ -4,214 +4,20 @@
|
|
|
4
4
|
* Generic Firestore operations for admin scripts
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.listCollections =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
exports.
|
|
11
|
-
exports.
|
|
12
|
-
exports.
|
|
13
|
-
exports.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
for (const collection of collections) {
|
|
24
|
-
const snapshot = await collection.limit(1000).get();
|
|
25
|
-
const info = {
|
|
26
|
-
name: collection.id,
|
|
27
|
-
documentCount: snapshot.docs.length,
|
|
28
|
-
sampleDocumentId: snapshot.docs[0]?.id,
|
|
29
|
-
};
|
|
30
|
-
if (!snapshot.empty) {
|
|
31
|
-
const subcollections = await snapshot.docs[0].ref.listCollections();
|
|
32
|
-
info.hasSubcollections = subcollections.length > 0;
|
|
33
|
-
}
|
|
34
|
-
result.push(info);
|
|
35
|
-
}
|
|
36
|
-
return result.sort((a, b) => b.documentCount - a.documentCount);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* List subcollections for a user document
|
|
40
|
-
*/
|
|
41
|
-
async function listUserSubcollections(db, userId) {
|
|
42
|
-
const userRef = db.collection("users").doc(userId);
|
|
43
|
-
const subcollections = await userRef.listCollections();
|
|
44
|
-
const result = [];
|
|
45
|
-
for (const subcollection of subcollections) {
|
|
46
|
-
const count = await subcollection.count().get();
|
|
47
|
-
result.push({
|
|
48
|
-
name: subcollection.id,
|
|
49
|
-
documentCount: count.data().count,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
return result;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Delete collection in batches
|
|
56
|
-
*/
|
|
57
|
-
async function deleteCollection(db, collectionPath, onProgress) {
|
|
58
|
-
let totalDeleted = 0;
|
|
59
|
-
let hasMore = true;
|
|
60
|
-
while (hasMore) {
|
|
61
|
-
const snapshot = await db
|
|
62
|
-
.collection(collectionPath)
|
|
63
|
-
.orderBy("__name__")
|
|
64
|
-
.limit(BATCH_SIZE)
|
|
65
|
-
.get();
|
|
66
|
-
if (snapshot.empty) {
|
|
67
|
-
hasMore = false;
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
const batch = db.batch();
|
|
71
|
-
snapshot.docs.forEach((doc) => batch.delete(doc.ref));
|
|
72
|
-
await batch.commit();
|
|
73
|
-
totalDeleted += snapshot.docs.length;
|
|
74
|
-
onProgress?.(totalDeleted);
|
|
75
|
-
}
|
|
76
|
-
return totalDeleted;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Delete user subcollection for all users
|
|
80
|
-
*/
|
|
81
|
-
async function deleteUserSubcollection(db, subcollectionName, onProgress) {
|
|
82
|
-
let totalDeleted = 0;
|
|
83
|
-
const usersSnapshot = await db.collection("users").get();
|
|
84
|
-
for (const userDoc of usersSnapshot.docs) {
|
|
85
|
-
const subcollectionRef = userDoc.ref.collection(subcollectionName);
|
|
86
|
-
const subcollectionSnapshot = await subcollectionRef.get();
|
|
87
|
-
if (!subcollectionSnapshot.empty) {
|
|
88
|
-
const batch = db.batch();
|
|
89
|
-
subcollectionSnapshot.docs.forEach((doc) => batch.delete(doc.ref));
|
|
90
|
-
await batch.commit();
|
|
91
|
-
totalDeleted += subcollectionSnapshot.docs.length;
|
|
92
|
-
onProgress?.(totalDeleted);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return totalDeleted;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Delete all Firestore data
|
|
99
|
-
*/
|
|
100
|
-
async function deleteAllData(db, onProgress) {
|
|
101
|
-
let totalDeleted = 0;
|
|
102
|
-
const collections = await db.listCollections();
|
|
103
|
-
for (const collection of collections) {
|
|
104
|
-
const snapshot = await collection.get();
|
|
105
|
-
// Delete subcollections first for users collection
|
|
106
|
-
if (collection.id === "users") {
|
|
107
|
-
for (const doc of snapshot.docs) {
|
|
108
|
-
const subcollections = await doc.ref.listCollections();
|
|
109
|
-
for (const subcollection of subcollections) {
|
|
110
|
-
const subSnapshot = await subcollection.get();
|
|
111
|
-
if (!subSnapshot.empty) {
|
|
112
|
-
const batch = db.batch();
|
|
113
|
-
subSnapshot.docs.forEach((subDoc) => batch.delete(subDoc.ref));
|
|
114
|
-
await batch.commit();
|
|
115
|
-
totalDeleted += subSnapshot.docs.length;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
// Delete main collection documents
|
|
121
|
-
if (!snapshot.empty) {
|
|
122
|
-
const batch = db.batch();
|
|
123
|
-
snapshot.docs.forEach((doc) => batch.delete(doc.ref));
|
|
124
|
-
await batch.commit();
|
|
125
|
-
totalDeleted += snapshot.docs.length;
|
|
126
|
-
onProgress?.(collection.id, totalDeleted);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return totalDeleted;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Seed documents in batches
|
|
133
|
-
*/
|
|
134
|
-
async function seedBatch(db, collectionPath, docs) {
|
|
135
|
-
const result = {
|
|
136
|
-
success: true,
|
|
137
|
-
processed: 0,
|
|
138
|
-
errors: [],
|
|
139
|
-
};
|
|
140
|
-
for (let i = 0; i < docs.length; i += BATCH_SIZE) {
|
|
141
|
-
const batch = db.batch();
|
|
142
|
-
const slice = docs.slice(i, i + BATCH_SIZE);
|
|
143
|
-
for (const { id, data } of slice) {
|
|
144
|
-
const ref = db.collection(collectionPath).doc(id);
|
|
145
|
-
const clean = Object.fromEntries(Object.entries(data).filter(([, v]) => v !== undefined));
|
|
146
|
-
batch.set(ref, clean);
|
|
147
|
-
}
|
|
148
|
-
try {
|
|
149
|
-
await batch.commit();
|
|
150
|
-
result.processed += slice.length;
|
|
151
|
-
}
|
|
152
|
-
catch (error) {
|
|
153
|
-
result.success = false;
|
|
154
|
-
result.errors.push(`Batch failed at index ${i}: ${error}`);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return result;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Seed user subcollection
|
|
161
|
-
*/
|
|
162
|
-
async function seedUserSubcollection(db, userId, subcollectionName, docs) {
|
|
163
|
-
const result = {
|
|
164
|
-
success: true,
|
|
165
|
-
processed: 0,
|
|
166
|
-
errors: [],
|
|
167
|
-
};
|
|
168
|
-
const batch = db.batch();
|
|
169
|
-
for (const { id, data } of docs) {
|
|
170
|
-
const ref = db
|
|
171
|
-
.collection("users")
|
|
172
|
-
.doc(userId)
|
|
173
|
-
.collection(subcollectionName)
|
|
174
|
-
.doc(id);
|
|
175
|
-
const clean = Object.fromEntries(Object.entries(data).filter(([, v]) => v !== undefined));
|
|
176
|
-
batch.set(ref, clean);
|
|
177
|
-
}
|
|
178
|
-
try {
|
|
179
|
-
await batch.commit();
|
|
180
|
-
result.processed = docs.length;
|
|
181
|
-
}
|
|
182
|
-
catch (error) {
|
|
183
|
-
result.success = false;
|
|
184
|
-
result.errors.push(`Failed to seed subcollection: ${error}`);
|
|
185
|
-
}
|
|
186
|
-
return result;
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Count documents in collection
|
|
190
|
-
*/
|
|
191
|
-
async function countDocuments(db, collectionPath) {
|
|
192
|
-
const count = await db.collection(collectionPath).count().get();
|
|
193
|
-
return count.data().count;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Get user document count statistics
|
|
197
|
-
*/
|
|
198
|
-
async function getUserStats(db) {
|
|
199
|
-
const usersSnapshot = await db.collection("users").get();
|
|
200
|
-
let anonymous = 0;
|
|
201
|
-
let authenticated = 0;
|
|
202
|
-
usersSnapshot.docs.forEach((doc) => {
|
|
203
|
-
const data = doc.data();
|
|
204
|
-
if (data.isAnonymous) {
|
|
205
|
-
anonymous++;
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
authenticated++;
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
return {
|
|
212
|
-
total: usersSnapshot.docs.length,
|
|
213
|
-
anonymous,
|
|
214
|
-
authenticated,
|
|
215
|
-
};
|
|
216
|
-
}
|
|
7
|
+
exports.seedUserSubcollection = exports.seedBatch = exports.deleteAllData = exports.deleteUserSubcollection = exports.deleteCollection = exports.getUserStats = exports.countDocuments = exports.listUserSubcollections = exports.listCollections = void 0;
|
|
8
|
+
// Query functions
|
|
9
|
+
var firestore_queries_1 = require("./firestore-queries");
|
|
10
|
+
Object.defineProperty(exports, "listCollections", { enumerable: true, get: function () { return firestore_queries_1.listCollections; } });
|
|
11
|
+
Object.defineProperty(exports, "listUserSubcollections", { enumerable: true, get: function () { return firestore_queries_1.listUserSubcollections; } });
|
|
12
|
+
Object.defineProperty(exports, "countDocuments", { enumerable: true, get: function () { return firestore_queries_1.countDocuments; } });
|
|
13
|
+
Object.defineProperty(exports, "getUserStats", { enumerable: true, get: function () { return firestore_queries_1.getUserStats; } });
|
|
14
|
+
// Delete operations
|
|
15
|
+
var firestore_operations_1 = require("./firestore-operations");
|
|
16
|
+
Object.defineProperty(exports, "deleteCollection", { enumerable: true, get: function () { return firestore_operations_1.deleteCollection; } });
|
|
17
|
+
Object.defineProperty(exports, "deleteUserSubcollection", { enumerable: true, get: function () { return firestore_operations_1.deleteUserSubcollection; } });
|
|
18
|
+
Object.defineProperty(exports, "deleteAllData", { enumerable: true, get: function () { return firestore_operations_1.deleteAllData; } });
|
|
19
|
+
// Seed operations
|
|
20
|
+
var firestore_seeding_1 = require("./firestore-seeding");
|
|
21
|
+
Object.defineProperty(exports, "seedBatch", { enumerable: true, get: function () { return firestore_seeding_1.seedBatch; } });
|
|
22
|
+
Object.defineProperty(exports, "seedUserSubcollection", { enumerable: true, get: function () { return firestore_seeding_1.seedUserSubcollection; } });
|
|
217
23
|
//# sourceMappingURL=firestore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firestore.js","sourceRoot":"","sources":["../../scripts/firestore.ts"],"names":[],"mappings":";AAAA;;;GAGG
|
|
1
|
+
{"version":3,"file":"firestore.js","sourceRoot":"","sources":["../../scripts/firestore.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kBAAkB;AAClB,yDAK6B;AAJ3B,oHAAA,eAAe,OAAA;AACf,2HAAA,sBAAsB,OAAA;AACtB,mHAAA,cAAc,OAAA;AACd,iHAAA,YAAY,OAAA;AAGd,oBAAoB;AACpB,+DAIgC;AAH9B,wHAAA,gBAAgB,OAAA;AAChB,+HAAA,uBAAuB,OAAA;AACvB,qHAAA,aAAa,OAAA;AAGf,kBAAkB;AAClB,yDAG6B;AAF3B,8GAAA,SAAS,OAAA;AACT,0HAAA,qBAAqB,OAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firebase Admin User Commands
|
|
3
|
+
* Command functions for modifying user data
|
|
4
|
+
*/
|
|
5
|
+
import * as admin from "firebase-admin";
|
|
6
|
+
import type { UserCredits, CreditsConfig } from "./types";
|
|
7
|
+
/**
|
|
8
|
+
* Initialize credits for a user
|
|
9
|
+
*/
|
|
10
|
+
export declare function initializeUserCredits(db: admin.firestore.Firestore, userId: string, config: CreditsConfig): Promise<UserCredits>;
|
|
11
|
+
/**
|
|
12
|
+
* Add credits to a user
|
|
13
|
+
*/
|
|
14
|
+
export declare function addUserCredits(db: admin.firestore.Firestore, userId: string, credits: {
|
|
15
|
+
text?: number;
|
|
16
|
+
image?: number;
|
|
17
|
+
video?: number;
|
|
18
|
+
audio?: number;
|
|
19
|
+
}, collectionName?: string): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Set credits for a user (overwrite)
|
|
22
|
+
*/
|
|
23
|
+
export declare function setUserCredits(db: admin.firestore.Firestore, userId: string, credits: {
|
|
24
|
+
text?: number;
|
|
25
|
+
image?: number;
|
|
26
|
+
video?: number;
|
|
27
|
+
audio?: number;
|
|
28
|
+
}, collectionName?: string): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Delete user credits document
|
|
31
|
+
*/
|
|
32
|
+
export declare function deleteUserCredits(db: admin.firestore.Firestore, userId: string, collectionName?: string): Promise<void>;
|
|
33
|
+
//# sourceMappingURL=user-commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-commands.d.ts","sourceRoot":"","sources":["../../scripts/user-commands.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE1D;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,EAAE,EAAE,KAAK,CAAC,SAAS,CAAC,SAAS,EAC7B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,WAAW,CAAC,CA2BtB;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,EAAE,EAAE,KAAK,CAAC,SAAS,CAAC,SAAS,EAC7B,MA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