@umituz/react-native-firebase 1.13.18 → 1.13.20
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-firebase",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.20",
|
|
4
4
|
"description": "Unified Firebase package for React Native apps - Auth and Firestore services using Firebase JS SDK (no native modules).",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
package/src/firestore/index.ts
CHANGED
|
@@ -112,12 +112,7 @@ export {
|
|
|
112
112
|
// UTILS - Path Resolver
|
|
113
113
|
// =============================================================================
|
|
114
114
|
|
|
115
|
-
export {
|
|
116
|
-
FirestorePathResolver,
|
|
117
|
-
createDefaultPathBuilder,
|
|
118
|
-
} from './utils/path-resolver';
|
|
119
|
-
|
|
120
|
-
export type { PathBuilder } from './utils/path-resolver';
|
|
115
|
+
export { FirestorePathResolver } from './utils/path-resolver';
|
|
121
116
|
|
|
122
117
|
// =============================================================================
|
|
123
118
|
// DOMAIN LAYER - Constants
|
|
@@ -1,67 +1,41 @@
|
|
|
1
|
-
import type { Firestore } from "firebase/firestore";
|
|
1
|
+
import type { Firestore, CollectionReference, DocumentReference, DocumentData } from "firebase/firestore";
|
|
2
2
|
import { collection, doc } from "firebase/firestore";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* // Default: users/{userId}/creations
|
|
10
|
-
* (userId) => ["users", userId, "creations"]
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* // Alternative: creations/{userId}/items
|
|
14
|
-
* (userId) => ["creations", userId, "items"]
|
|
15
|
-
*/
|
|
16
|
-
export type PathBuilder = (userId: string) => string[];
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Resolves Firestore paths dynamically
|
|
20
|
-
* Single Responsibility: Path resolution and reference creation
|
|
5
|
+
* Resolves Firestore paths for user collections
|
|
6
|
+
* Standard pattern: users/{userId}/{collectionName}
|
|
21
7
|
*
|
|
22
8
|
* This class is designed to be used across hundreds of apps.
|
|
23
|
-
*
|
|
9
|
+
* All user data MUST be under users/{userId}/ for consistency.
|
|
24
10
|
*/
|
|
25
11
|
export class FirestorePathResolver {
|
|
26
12
|
constructor(
|
|
27
|
-
private readonly
|
|
13
|
+
private readonly collectionName: string,
|
|
28
14
|
private readonly db: Firestore | null,
|
|
29
15
|
) { }
|
|
30
16
|
|
|
31
17
|
/**
|
|
32
18
|
* Get collection reference for a user
|
|
19
|
+
* Pattern: users/{userId}/{collectionName}
|
|
20
|
+
*
|
|
33
21
|
* @param userId User identifier
|
|
34
22
|
* @returns CollectionReference or null if db not initialized
|
|
35
23
|
*/
|
|
36
|
-
getUserCollection(userId: string) {
|
|
24
|
+
getUserCollection(userId: string): CollectionReference<DocumentData> | null {
|
|
37
25
|
if (!this.db) return null;
|
|
38
|
-
|
|
39
|
-
const [first, ...rest] = pathSegments;
|
|
40
|
-
if (!first) return null;
|
|
41
|
-
return collection(this.db, first, ...rest);
|
|
26
|
+
return collection(this.db, "users", userId, this.collectionName);
|
|
42
27
|
}
|
|
43
28
|
|
|
44
29
|
/**
|
|
45
30
|
* Get document reference for a specific item
|
|
31
|
+
* Pattern: users/{userId}/{collectionName}/{documentId}
|
|
32
|
+
*
|
|
46
33
|
* @param userId User identifier
|
|
47
34
|
* @param documentId Document identifier
|
|
48
35
|
* @returns DocumentReference or null if db not initialized
|
|
49
36
|
*/
|
|
50
|
-
getDocRef(userId: string, documentId: string) {
|
|
37
|
+
getDocRef(userId: string, documentId: string): DocumentReference<DocumentData> | null {
|
|
51
38
|
if (!this.db) return null;
|
|
52
|
-
|
|
53
|
-
const [first, ...rest] = pathSegments;
|
|
54
|
-
if (!first) return null;
|
|
55
|
-
return doc(this.db, first, ...rest, documentId);
|
|
39
|
+
return doc(this.db, "users", userId, this.collectionName, documentId);
|
|
56
40
|
}
|
|
57
41
|
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Creates a default path builder for standard user collections
|
|
61
|
-
* Pattern: users/{userId}/{collectionName}
|
|
62
|
-
*
|
|
63
|
-
* @param collectionName Name of the collection
|
|
64
|
-
* @returns PathBuilder function
|
|
65
|
-
*/
|
|
66
|
-
export const createDefaultPathBuilder = (collectionName: string): PathBuilder =>
|
|
67
|
-
(userId: string) => ["users", userId, collectionName];
|