@umituz/react-native-firebase 2.4.16 → 2.4.18

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": "2.4.16",
3
+ "version": "2.4.18",
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",
@@ -12,6 +12,7 @@ import type { Firestore, CollectionReference, DocumentReference, DocumentData }
12
12
  import { getFirestore, collection, doc } from 'firebase/firestore';
13
13
  import { isQuotaError as checkQuotaError } from '../../utils/quota-error-detector.util';
14
14
  import { ERROR_MESSAGES } from '../../../../shared/domain/utils/error-handlers/error-messages';
15
+ import { quotaTrackingMiddleware } from '../middleware/QuotaTrackingMiddleware';
15
16
 
16
17
  export enum RepositoryState {
17
18
  ACTIVE = 'active',
@@ -42,6 +43,21 @@ export abstract class BaseRepository implements IPathResolver {
42
43
  return getFirestore();
43
44
  }
44
45
 
46
+ /**
47
+ * Get the Firestore instance or throw error
48
+ * @throws Error if repository is destroyed or Firestore is not initialized
49
+ */
50
+ protected getDbOrThrow(): Firestore {
51
+ if (this.state === RepositoryState.DESTROYED) {
52
+ throw new Error(ERROR_MESSAGES.REPOSITORY.DESTROYED);
53
+ }
54
+ const db = getFirestore();
55
+ if (!db) {
56
+ throw new Error(ERROR_MESSAGES.FIRESTORE.NOT_INITIALIZED);
57
+ }
58
+ return db;
59
+ }
60
+
45
61
  getUserCollection(userId: string): CollectionReference<DocumentData> | null {
46
62
  const db = this.getDb();
47
63
  if (!db) return null;
@@ -86,6 +102,47 @@ export abstract class BaseRepository implements IPathResolver {
86
102
  }
87
103
  }
88
104
 
105
+ /**
106
+ * Track read operation for quota monitoring
107
+ *
108
+ * @param collection - Collection name
109
+ * @param count - Number of documents read
110
+ * @param cached - Whether the result is from cache
111
+ */
112
+ protected trackRead(
113
+ collection: string,
114
+ count: number = 1,
115
+ cached: boolean = false,
116
+ ): void {
117
+ quotaTrackingMiddleware.trackRead(collection, count, cached);
118
+ }
119
+
120
+ /**
121
+ * Track write operation for quota monitoring
122
+ *
123
+ * @param collection - Collection name
124
+ * @param count - Number of documents written
125
+ */
126
+ protected trackWrite(
127
+ collection: string,
128
+ count: number = 1,
129
+ ): void {
130
+ quotaTrackingMiddleware.trackWrite(collection, count);
131
+ }
132
+
133
+ /**
134
+ * Track delete operation for quota monitoring
135
+ *
136
+ * @param collection - Collection name
137
+ * @param count - Number of documents deleted
138
+ */
139
+ protected trackDelete(
140
+ collection: string,
141
+ count: number = 1,
142
+ ): void {
143
+ quotaTrackingMiddleware.trackDelete(collection, count);
144
+ }
145
+
89
146
  /**
90
147
  * Destroy the repository
91
148
  * Prevents further operations