@umituz/react-native-firebase 2.4.100 → 2.5.1

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.100",
3
+ "version": "2.5.1",
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",
@@ -59,61 +59,6 @@ export type {
59
59
  } from './types/pagination.types';
60
60
  export { EMPTY_PAGINATED_RESULT } from './types/pagination.types';
61
61
 
62
- // Domain Constants
63
- export {
64
- FREE_TIER_LIMITS,
65
- QUOTA_THRESHOLDS,
66
- calculateQuotaUsage,
67
- isQuotaThresholdReached,
68
- getRemainingQuota,
69
- } from './domain/constants/QuotaLimits';
70
-
71
- // Domain Entities
72
- export type {
73
- QuotaMetrics,
74
- QuotaLimits,
75
- QuotaStatus,
76
- } from './domain/entities/QuotaMetrics';
77
- export type {
78
- RequestLog,
79
- RequestStats,
80
- RequestType,
81
- } from './domain/entities/RequestLog';
82
-
83
- // Domain Services
84
- export { QuotaCalculator } from './domain/services/QuotaCalculator';
85
-
86
- // Quota Error Detection
87
- export {
88
- isQuotaError,
89
- isRetryableError,
90
- } from '../../shared/domain/utils/error-handlers/error-checkers';
91
- export {
92
- getQuotaErrorMessage,
93
- } from '../../shared/domain/utils/error-handlers/error-messages';
94
-
95
- // Middleware
96
- export {
97
- QueryDeduplicationMiddleware,
98
- queryDeduplicationMiddleware,
99
- syncDeduplicationWithQuota,
100
- useDeduplicationWithQuota,
101
- } from './infrastructure/middleware/QueryDeduplicationMiddleware';
102
- export type {
103
- QueryDeduplicationConfig,
104
- DeduplicationStatistics,
105
- } from './infrastructure/middleware/QueryDeduplicationMiddleware';
106
- export {
107
- QuotaTrackingMiddleware,
108
- quotaTrackingMiddleware,
109
- } from './infrastructure/middleware/QuotaTrackingMiddleware';
110
-
111
- // Services
112
- export {
113
- RequestLoggerService,
114
- requestLoggerService,
115
- } from './infrastructure/services/RequestLoggerService';
116
-
117
62
  // Firestore Helper Utilities
118
63
  export {
119
64
  withFirestore,
@@ -150,13 +95,10 @@ export {
150
95
  export { useFirestoreQuery } from './presentation/hooks/useFirestoreQuery';
151
96
  export { useFirestoreMutation } from './presentation/hooks/useFirestoreMutation';
152
97
  export { useFirestoreSnapshot } from './presentation/hooks/useFirestoreSnapshot';
153
- export { useSmartFirestoreSnapshot, useSmartListenerControl } from './presentation/hooks/useSmartFirestoreSnapshot';
154
- export { createFirestoreKeys } from './presentation/query-keys/createFirestoreKeys';
155
98
 
156
99
  export type { UseFirestoreQueryOptions } from './presentation/hooks/useFirestoreQuery';
157
100
  export type { UseFirestoreMutationOptions } from './presentation/hooks/useFirestoreMutation';
158
101
  export type { UseFirestoreSnapshotOptions } from './presentation/hooks/useFirestoreSnapshot';
159
- export type { UseSmartFirestoreSnapshotOptions, BackgroundStrategy } from './presentation/hooks/useSmartFirestoreSnapshot';
160
102
 
161
103
  // Firebase types are available from the 'firebase' package directly
162
104
  // Import them in your app: import { Timestamp } from 'firebase/firestore';
@@ -43,11 +43,9 @@ export abstract class BasePaginatedRepository extends BaseQueryRepository {
43
43
 
44
44
  const collectionRef = collection(db, collectionName);
45
45
  let q: import("firebase/firestore").Query<DocumentData>;
46
- let cursorKey = 'start';
47
46
 
48
47
  // Handle cursor-based pagination
49
48
  if (helper.hasCursor(params) && params?.cursor) {
50
- cursorKey = params.cursor;
51
49
 
52
50
  // FIX: Validate cursor and throw error instead of silent failure
53
51
  validateCursorOrThrow(params.cursor);
@@ -77,17 +75,13 @@ export abstract class BasePaginatedRepository extends BaseQueryRepository {
77
75
  );
78
76
  }
79
77
 
80
- // Generate a unique key for deduplication (after cursor is resolved)
81
- const uniqueKey = `${collectionName}_list_${orderByField}_${orderDirection}_${fetchLimit}_${cursorKey}`;
82
-
83
78
  return this.executeQuery(
84
79
  collectionName,
85
80
  async () => {
86
81
  const snapshot = await getDocs(q);
87
82
  return snapshot.docs;
88
83
  },
89
- false,
90
- uniqueKey
84
+ false
91
85
  );
92
86
  }
93
87
 
@@ -1,44 +1,18 @@
1
- /**
2
- * Base Repository - Query Operations
3
- *
4
- * Provides query and tracking operations for Firestore repositories.
5
- * Extends BaseRepository with query-specific functionality.
6
- */
7
-
8
- import { queryDeduplicationMiddleware } from "../middleware/QueryDeduplicationMiddleware";
9
- import { BaseRepository } from "./BaseRepository";
1
+ import { BaseRepository } from './BaseRepository';
10
2
 
11
3
  export abstract class BaseQueryRepository extends BaseRepository {
12
- /**
13
- * Execute query with deduplication and quota tracking
14
- * Prevents duplicate queries and tracks quota usage
15
- */
16
4
  protected async executeQuery<T>(
17
5
  collection: string,
18
6
  queryFn: () => Promise<T>,
19
- cached: boolean = false,
20
- uniqueKey?: string
7
+ cached: boolean = false
21
8
  ): Promise<T> {
22
- const safeKey = uniqueKey || `${collection}_query`;
23
-
24
- const queryKey = {
25
- collection,
26
- filters: safeKey,
27
- limit: undefined,
28
- orderBy: undefined,
29
- };
30
-
31
- return queryDeduplicationMiddleware.deduplicate(queryKey, async () => {
32
- const result = await queryFn();
9
+ const result = await queryFn();
33
10
 
34
- // Optimize: Only calculate count if tracking is needed
35
- // Check if quota tracking is enabled before computing array length
36
- if (!cached) {
37
- const count = Array.isArray(result) ? result.length : 1;
38
- this.trackRead(collection, count, cached);
39
- }
11
+ if (!cached) {
12
+ const count = Array.isArray(result) ? result.length : 1;
13
+ this.trackRead(collection, count, cached);
14
+ }
40
15
 
41
- return result;
42
- });
16
+ return result;
43
17
  }
44
18
  }
@@ -10,9 +10,6 @@
10
10
 
11
11
  import type { Firestore, CollectionReference, DocumentReference, DocumentData } from 'firebase/firestore';
12
12
  import { getFirestore, collection, doc } from 'firebase/firestore';
13
- import { isQuotaError as checkQuotaError } from '../../../../shared/domain/utils/error-handlers/error-checkers';
14
- import { ERROR_MESSAGES } from '../../../../shared/domain/utils/error-handlers/error-messages';
15
- import { quotaTrackingMiddleware } from '../middleware/QuotaTrackingMiddleware';
16
13
 
17
14
  enum RepositoryState {
18
15
  ACTIVE = 'active',
@@ -49,11 +46,11 @@ export abstract class BaseRepository implements IPathResolver {
49
46
  */
50
47
  protected getDbOrThrow(): Firestore {
51
48
  if (this.state === RepositoryState.DESTROYED) {
52
- throw new Error(ERROR_MESSAGES.REPOSITORY.DESTROYED);
49
+ throw new Error('Repository is destroyed');
53
50
  }
54
51
  const db = getFirestore();
55
52
  if (!db) {
56
- throw new Error(ERROR_MESSAGES.FIRESTORE.NOT_INITIALIZED);
53
+ throw new Error('Firestore is not initialized');
57
54
  }
58
55
  return db;
59
56
  }
@@ -107,55 +104,19 @@ export abstract class BaseRepository implements IPathResolver {
107
104
  protected async executeOperation<T>(
108
105
  operation: () => Promise<T>
109
106
  ): Promise<T> {
110
- try {
111
- return await operation();
112
- } catch (error) {
113
- if (checkQuotaError(error)) {
114
- throw new Error(ERROR_MESSAGES.FIRESTORE.QUOTA_EXCEEDED);
115
- }
116
- throw error;
117
- }
107
+ return await operation();
118
108
  }
119
109
 
120
- /**
121
- * Track read operation for quota monitoring
122
- *
123
- * @param collection - Collection name
124
- * @param count - Number of documents read
125
- * @param cached - Whether the result is from cache
126
- */
127
- protected trackRead(
128
- collection: string,
129
- count: number = 1,
130
- cached: boolean = false,
131
- ): void {
132
- quotaTrackingMiddleware.trackRead(collection, count, cached);
110
+ protected trackRead(_collection: string, _count: number = 1, _cached: boolean = false): void {
111
+ // Quota tracking removed - use Firebase console for monitoring
133
112
  }
134
113
 
135
- /**
136
- * Track write operation for quota monitoring
137
- *
138
- * @param collection - Collection name
139
- * @param count - Number of documents written
140
- */
141
- protected trackWrite(
142
- collection: string,
143
- count: number = 1,
144
- ): void {
145
- quotaTrackingMiddleware.trackWrite(collection, count);
114
+ protected trackWrite(_collection: string, _count: number = 1): void {
115
+ // Quota tracking removed - use Firebase console for monitoring
146
116
  }
147
117
 
148
- /**
149
- * Track delete operation for quota monitoring
150
- *
151
- * @param collection - Collection name
152
- * @param count - Number of documents deleted
153
- */
154
- protected trackDelete(
155
- collection: string,
156
- count: number = 1,
157
- ): void {
158
- quotaTrackingMiddleware.trackDelete(collection, count);
118
+ protected trackDelete(_collection: string, _count: number = 1): void {
119
+ // Quota tracking removed - use Firebase console for monitoring
159
120
  }
160
121
 
161
122
  /**
@@ -12,13 +12,3 @@ export {
12
12
  useFirestoreSnapshot,
13
13
  type UseFirestoreSnapshotOptions,
14
14
  } from './useFirestoreSnapshot';
15
-
16
- export {
17
- useSmartFirestoreSnapshot,
18
- useSmartListenerControl,
19
- } from './useSmartFirestoreSnapshot';
20
-
21
- export type {
22
- UseSmartFirestoreSnapshotOptions,
23
- BackgroundStrategy,
24
- } from './useSmartFirestoreSnapshot';
@@ -1,101 +0,0 @@
1
- /**
2
- * Quota Limit Constants
3
- * Domain layer - Default Firestore quota limits
4
- *
5
- * General-purpose constants for any app using Firestore
6
- * Based on Firestore free tier and pricing documentation
7
- */
8
-
9
- import { calculatePercentage, calculateRemaining } from '../../../../shared/domain/utils/calculation.util';
10
-
11
- /**
12
- * Firestore free tier daily limits
13
- * https://firebase.google.com/docs/firestore/quotas
14
- */
15
- export const FREE_TIER_LIMITS = {
16
- /**
17
- * Daily read operations (documents)
18
- * Free tier: 50,000 reads/day
19
- */
20
- DAILY_READS: 50_000,
21
-
22
- /**
23
- * Daily write operations (documents)
24
- * Free tier: 20,000 writes/day
25
- */
26
- DAILY_WRITES: 20_000,
27
-
28
- /**
29
- * Daily delete operations (documents)
30
- * Free tier: 20,000 deletes/day
31
- */
32
- DAILY_DELETES: 20_000,
33
-
34
- /**
35
- * Stored data (GB)
36
- * Free tier: 1 GB
37
- */
38
- STORAGE_GB: 1,
39
- } as const;
40
-
41
- /**
42
- * Quota warning thresholds (percentage of limit)
43
- * Apps can use these to show warnings before hitting limits
44
- */
45
- export const QUOTA_THRESHOLDS = {
46
- /**
47
- * Warning threshold (80% of limit)
48
- * Show warning to user
49
- */
50
- WARNING: 0.8,
51
-
52
- /**
53
- * Critical threshold (95% of limit)
54
- * Show critical alert, consider disabling features
55
- */
56
- CRITICAL: 0.95,
57
-
58
- /**
59
- * Emergency threshold (98% of limit)
60
- * Disable non-essential features
61
- */
62
- EMERGENCY: 0.98,
63
- } as const;
64
-
65
- /**
66
- * Calculate quota usage percentage
67
- * Optimized: Uses centralized calculation utility
68
- * @param current - Current usage count
69
- * @param limit - Total limit
70
- * @returns Percentage (0-1)
71
- */
72
- export function calculateQuotaUsage(current: number, limit: number): number {
73
- return calculatePercentage(current, limit);
74
- }
75
-
76
- /**
77
- * Check if quota threshold is reached
78
- * @param current - Current usage count
79
- * @param limit - Total limit
80
- * @param threshold - Threshold to check (0-1)
81
- * @returns true if threshold is reached
82
- */
83
- export function isQuotaThresholdReached(
84
- current: number,
85
- limit: number,
86
- threshold: number,
87
- ): boolean {
88
- const usage = calculateQuotaUsage(current, limit);
89
- return usage >= threshold;
90
- }
91
-
92
- /**
93
- * Get remaining quota
94
- * Optimized: Uses centralized calculation utility
95
- * @param current - Current usage count
96
- * @param limit - Total limit
97
- * @returns Remaining quota count
98
- */
99
- export function getRemainingQuota(current: number, limit: number): number {
100
- return calculateRemaining(current, limit);
101
- }
@@ -1,26 +0,0 @@
1
- /**
2
- * Quota Metrics Types
3
- */
4
-
5
- export interface QuotaMetrics {
6
- readCount: number;
7
- writeCount: number;
8
- deleteCount: number;
9
- lastResetDate: string;
10
- }
11
-
12
- export interface QuotaLimits {
13
- dailyReadLimit: number;
14
- dailyWriteLimit: number;
15
- dailyDeleteLimit: number;
16
- }
17
-
18
- export interface QuotaStatus {
19
- metrics: QuotaMetrics;
20
- limits: QuotaLimits;
21
- readPercentage: number;
22
- writePercentage: number;
23
- deletePercentage: number;
24
- isNearLimit: boolean;
25
- isOverLimit: boolean;
26
- }
@@ -1,28 +0,0 @@
1
- /**
2
- * Request Log Types
3
- */
4
-
5
- export type RequestType = 'read' | 'write' | 'delete' | 'listener';
6
-
7
- export interface RequestLog {
8
- id: string;
9
- type: RequestType;
10
- collection: string;
11
- documentId?: string;
12
- cached: boolean;
13
- success: boolean;
14
- error?: string;
15
- duration?: number;
16
- timestamp: number;
17
- }
18
-
19
- export interface RequestStats {
20
- totalRequests: number;
21
- readRequests: number;
22
- writeRequests: number;
23
- deleteRequests: number;
24
- listenerRequests: number;
25
- cachedRequests: number;
26
- failedRequests: number;
27
- averageDuration: number;
28
- }
@@ -1,71 +0,0 @@
1
- /**
2
- * Quota Calculator Service
3
- * Domain service for calculating quota usage and status
4
- */
5
-
6
- import type { QuotaMetrics, QuotaLimits, QuotaStatus } from '../entities/QuotaMetrics';
7
- import { FREE_TIER_LIMITS, QUOTA_THRESHOLDS, calculateQuotaUsage } from '../constants/QuotaLimits';
8
-
9
- /**
10
- * Default quota limits (Firebase Spark Plan)
11
- * Can be overridden via configuration
12
- */
13
- const DEFAULT_QUOTA_LIMITS: QuotaLimits = {
14
- dailyReadLimit: FREE_TIER_LIMITS.DAILY_READS,
15
- dailyWriteLimit: FREE_TIER_LIMITS.DAILY_WRITES,
16
- dailyDeleteLimit: FREE_TIER_LIMITS.DAILY_DELETES,
17
- };
18
-
19
- export class QuotaCalculator {
20
- /**
21
- * Calculate quota status from metrics and limits
22
- */
23
- static calculateStatus(
24
- metrics: QuotaMetrics,
25
- limits: QuotaLimits = DEFAULT_QUOTA_LIMITS,
26
- ): QuotaStatus {
27
- const readPercentage = calculateQuotaUsage(metrics.readCount, limits.dailyReadLimit) * 100;
28
- const writePercentage = calculateQuotaUsage(metrics.writeCount, limits.dailyWriteLimit) * 100;
29
- const deletePercentage = calculateQuotaUsage(metrics.deleteCount, limits.dailyDeleteLimit) * 100;
30
-
31
- const warningThreshold = QUOTA_THRESHOLDS.WARNING * 100;
32
- const isNearLimit =
33
- readPercentage >= warningThreshold ||
34
- writePercentage >= warningThreshold ||
35
- deletePercentage >= warningThreshold;
36
-
37
- const isOverLimit =
38
- readPercentage >= 100 ||
39
- writePercentage >= 100 ||
40
- deletePercentage >= 100;
41
-
42
- return {
43
- metrics,
44
- limits,
45
- readPercentage,
46
- writePercentage,
47
- deletePercentage,
48
- isNearLimit,
49
- isOverLimit,
50
- };
51
- }
52
-
53
- /**
54
- * Get default quota limits
55
- */
56
- static getDefaultLimits(): QuotaLimits {
57
- return { ...DEFAULT_QUOTA_LIMITS };
58
- }
59
-
60
- /**
61
- * Check if metrics are within limits
62
- */
63
- static isWithinLimits(
64
- metrics: QuotaMetrics,
65
- limits: QuotaLimits = DEFAULT_QUOTA_LIMITS,
66
- ): boolean {
67
- const status = this.calculateStatus(metrics, limits);
68
- return !status.isOverLimit;
69
- }
70
- }
71
-