@umituz/react-native-firebase 1.13.100 → 1.13.101

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.100",
3
+ "version": "1.13.101",
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",
@@ -112,5 +112,16 @@ export {
112
112
  requestLoggerService,
113
113
  } from './infrastructure/services/RequestLoggerService';
114
114
 
115
+ // Firestore Helper Utilities
116
+ export {
117
+ getDb,
118
+ withFirestore,
119
+ withFirestoreVoid,
120
+ withFirestoreBool,
121
+ createErrorResult,
122
+ createSuccessResult,
123
+ } from './utils/firestore-helper';
124
+ export type { FirestoreResult, NoDbResult } from './utils/firestore-helper';
125
+
115
126
  // Re-export Firestore types
116
127
  export type { Timestamp } from 'firebase/firestore';
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Firestore Helper - Centralized Firestore access utilities
3
+ * Provides common patterns for Firestore operations with error handling
4
+ */
5
+ declare const __DEV__: boolean;
6
+
7
+ import { getFirestore } from "../infrastructure/config/FirestoreClient";
8
+ import type { Firestore } from "../infrastructure/config/FirestoreClient";
9
+
10
+ export interface FirestoreResult<T> {
11
+ success: boolean;
12
+ data?: T;
13
+ error?: { message: string; code: string };
14
+ }
15
+
16
+ export type NoDbResult = FirestoreResult<never>;
17
+
18
+ const NO_DB_ERROR: NoDbResult = {
19
+ success: false,
20
+ error: { message: "No DB", code: "DB_ERR" },
21
+ };
22
+
23
+ /**
24
+ * Get Firestore instance with null check
25
+ */
26
+ export function getDb(): Firestore | null {
27
+ return getFirestore();
28
+ }
29
+
30
+ /**
31
+ * Execute a Firestore operation with automatic null check
32
+ * Returns error result if db is not available
33
+ */
34
+ export async function withFirestore<T>(
35
+ operation: (db: Firestore) => Promise<FirestoreResult<T>>,
36
+ logTag?: string
37
+ ): Promise<FirestoreResult<T>> {
38
+ const db = getDb();
39
+ if (!db) {
40
+ if (__DEV__ && logTag) {
41
+ console.log(`[${logTag}] No Firestore instance`);
42
+ }
43
+ return NO_DB_ERROR as FirestoreResult<T>;
44
+ }
45
+ return operation(db);
46
+ }
47
+
48
+ /**
49
+ * Execute a Firestore operation that returns void
50
+ */
51
+ export async function withFirestoreVoid(
52
+ operation: (db: Firestore) => Promise<void>,
53
+ logTag?: string
54
+ ): Promise<void> {
55
+ const db = getDb();
56
+ if (!db) {
57
+ if (__DEV__ && logTag) {
58
+ console.log(`[${logTag}] No Firestore instance`);
59
+ }
60
+ return;
61
+ }
62
+ return operation(db);
63
+ }
64
+
65
+ /**
66
+ * Execute a Firestore operation that returns boolean
67
+ */
68
+ export async function withFirestoreBool(
69
+ operation: (db: Firestore) => Promise<boolean>,
70
+ logTag?: string
71
+ ): Promise<boolean> {
72
+ const db = getDb();
73
+ if (!db) {
74
+ if (__DEV__ && logTag) {
75
+ console.log(`[${logTag}] No Firestore instance`);
76
+ }
77
+ return false;
78
+ }
79
+ return operation(db);
80
+ }
81
+
82
+ /**
83
+ * Create a standard error result
84
+ */
85
+ export function createErrorResult<T>(message: string, code: string): FirestoreResult<T> {
86
+ return { success: false, error: { message, code } };
87
+ }
88
+
89
+ /**
90
+ * Create a standard success result
91
+ */
92
+ export function createSuccessResult<T>(data?: T): FirestoreResult<T> {
93
+ return { success: true, data };
94
+ }
package/src/index.ts CHANGED
@@ -88,6 +88,17 @@ export { FirestorePathResolver } from "./firestore/utils/path-resolver";
88
88
  export { PaginationHelper } from "./firestore/utils/pagination.helper";
89
89
  export type { Timestamp } from "firebase/firestore";
90
90
 
91
+ // Firestore Helper Utilities
92
+ export {
93
+ getDb,
94
+ withFirestore,
95
+ withFirestoreVoid,
96
+ withFirestoreBool,
97
+ createErrorResult,
98
+ createSuccessResult,
99
+ } from "./firestore/utils/firestore-helper";
100
+ export type { FirestoreResult, NoDbResult } from "./firestore/utils/firestore-helper";
101
+
91
102
  // Auth Hooks (commonly used)
92
103
  export { useSocialAuth } from "./auth/presentation/hooks/useSocialAuth";
93
104
  export type {