@umituz/react-native-firebase 3.0.3 → 3.0.5

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.
Files changed (74) hide show
  1. package/package.json +7 -1
  2. package/src/domains/account-deletion/index.ts +15 -10
  3. package/src/domains/account-deletion/infrastructure/services/account-deletion.service.ts +226 -26
  4. package/src/domains/account-deletion/infrastructure/services/reauthentication.service.ts +160 -0
  5. package/src/domains/auth/domain/value-objects/FirebaseAuthConfig.ts +1 -1
  6. package/src/domains/auth/index.ts +156 -6
  7. package/src/domains/auth/infrastructure/config/FirebaseAuthClient.ts +60 -48
  8. package/src/domains/auth/infrastructure/config/initializers/FirebaseAuthInitializer.ts +41 -5
  9. package/src/domains/auth/presentation/hooks/useGoogleOAuth.ts +115 -20
  10. package/src/domains/firestore/domain/constants/QuotaLimits.ts +101 -0
  11. package/src/domains/firestore/domain/entities/QuotaMetrics.ts +26 -0
  12. package/src/domains/firestore/domain/entities/RequestLog.ts +28 -0
  13. package/src/domains/firestore/domain/services/QuotaCalculator.ts +71 -0
  14. package/src/domains/firestore/index.ts +86 -31
  15. package/src/domains/firestore/infrastructure/config/FirestoreClient.ts +82 -45
  16. package/src/domains/firestore/infrastructure/config/initializers/FirebaseFirestoreInitializer.ts +249 -4
  17. package/src/domains/firestore/infrastructure/middleware/QueryDeduplicationMiddleware.ts +312 -0
  18. package/src/domains/firestore/infrastructure/middleware/QuotaTrackingMiddleware.ts +95 -0
  19. package/src/domains/firestore/infrastructure/repositories/BasePaginatedRepository.ts +7 -1
  20. package/src/domains/firestore/infrastructure/repositories/BaseQueryRepository.ts +34 -8
  21. package/src/domains/firestore/infrastructure/repositories/BaseRepository.ts +48 -9
  22. package/src/domains/firestore/infrastructure/services/RequestLoggerService.ts +165 -0
  23. package/src/domains/firestore/presentation/hooks/index.ts +10 -0
  24. package/src/domains/firestore/presentation/hooks/useFirestoreMutation.ts +1 -1
  25. package/src/domains/firestore/presentation/hooks/useFirestoreQuery.ts +1 -1
  26. package/src/domains/firestore/presentation/hooks/useSmartFirestoreSnapshot.ts +361 -0
  27. package/src/domains/firestore/presentation/query-keys/createFirestoreKeys.ts +32 -0
  28. package/src/domains/firestore/presentation/query-keys/index.ts +1 -0
  29. package/src/domains/firestore/utils/deduplication/pending-query-manager.util.ts +119 -0
  30. package/src/domains/firestore/utils/deduplication/query-key-generator.util.ts +34 -0
  31. package/src/domains/firestore/utils/deduplication/timer-manager.util.ts +83 -0
  32. package/src/index.ts +2 -30
  33. package/src/shared/domain/utils/calculation.util.ts +305 -17
  34. package/src/shared/domain/utils/error-handlers/error-messages.ts +0 -11
  35. package/src/shared/domain/utils/index.ts +5 -0
  36. package/src/shared/infrastructure/config/base/ClientStateManager.ts +82 -0
  37. package/src/shared/infrastructure/config/base/ServiceClientSingleton.ts +136 -20
  38. package/src/shared/infrastructure/config/clients/FirebaseClientSingleton.ts +1 -1
  39. package/src/shared/infrastructure/config/initializers/FirebaseAppInitializer.ts +9 -0
  40. package/src/shared/infrastructure/config/services/FirebaseInitializationService.ts +1 -1
  41. package/src/shared/infrastructure/config/state/FirebaseClientState.ts +14 -36
  42. package/src/application/auth/index.ts +0 -10
  43. package/src/application/auth/use-cases/index.ts +0 -6
  44. package/src/domains/account-deletion/domain/index.ts +0 -8
  45. package/src/domains/account-deletion/infrastructure/services/AccountDeletionExecutor.ts +0 -79
  46. package/src/domains/account-deletion/infrastructure/services/AccountDeletionTypes.ts +0 -32
  47. package/src/domains/auth/domain.ts +0 -16
  48. package/src/domains/auth/infrastructure/config/index.ts +0 -2
  49. package/src/domains/auth/infrastructure/config/initializers/index.ts +0 -1
  50. package/src/domains/auth/infrastructure/services/index.ts +0 -16
  51. package/src/domains/auth/infrastructure/services/utils/index.ts +0 -1
  52. package/src/domains/auth/infrastructure/stores/index.ts +0 -1
  53. package/src/domains/auth/infrastructure/utils/index.ts +0 -1
  54. package/src/domains/auth/infrastructure.ts +0 -11
  55. package/src/domains/auth/presentation/hooks/useAppleAuth.ts +0 -82
  56. package/src/domains/auth/presentation.ts +0 -31
  57. package/src/domains/firestore/domain/entities/Collection.ts +0 -122
  58. package/src/domains/firestore/domain/entities/CollectionFactory.ts +0 -55
  59. package/src/domains/firestore/domain/entities/CollectionHelpers.ts +0 -143
  60. package/src/domains/firestore/domain/entities/CollectionUtils.ts +0 -72
  61. package/src/domains/firestore/domain/entities/CollectionValidation.ts +0 -138
  62. package/src/domains/firestore/domain/index.ts +0 -61
  63. package/src/domains/firestore/domain/value-objects/QueryOptions.ts +0 -143
  64. package/src/domains/firestore/domain/value-objects/QueryOptionsFactory.ts +0 -95
  65. package/src/domains/firestore/domain/value-objects/QueryOptionsHelpers.ts +0 -110
  66. package/src/domains/firestore/domain/value-objects/WhereClause.ts +0 -114
  67. package/src/domains/firestore/domain/value-objects/WhereClauseFactory.ts +0 -101
  68. package/src/domains/firestore/domain/value-objects/WhereClauseHelpers.ts +0 -123
  69. package/src/domains/firestore/domain/value-objects/WhereClauseValidation.ts +0 -83
  70. package/src/shared/infrastructure/base/ErrorHandler.ts +0 -81
  71. package/src/shared/infrastructure/base/ServiceBase.ts +0 -62
  72. package/src/shared/infrastructure/base/TypedGuard.ts +0 -131
  73. package/src/shared/infrastructure/base/index.ts +0 -34
  74. package/src/shared/types/firebase.types.ts +0 -274
@@ -1,122 +0,0 @@
1
- /**
2
- * Collection Entity (Main)
3
- * Single Responsibility: Represent a Firestore collection with metadata
4
- *
5
- * Domain entity that encapsulates collection information and metadata.
6
- * Provides business logic for collection operations.
7
- *
8
- * Max lines: 150 (enforced for maintainability)
9
- */
10
-
11
- import type { CollectionReference, Query } from 'firebase/firestore';
12
- import {
13
- isUserCollectionPath,
14
- extractUserIdFromPath,
15
- createSubCollectionPath as createSubCollectionPathUtil,
16
- } from './CollectionValidation';
17
- import {
18
- getCollectionDepth,
19
- collectionToObject,
20
- isQueryReference,
21
- isCollectionReference as isCollectionReferenceUtil,
22
- } from './CollectionUtils';
23
- import { fromReference, fromQuery } from './CollectionFactory';
24
-
25
- /**
26
- * Collection metadata
27
- */
28
- export interface CollectionMetadata {
29
- readonly name: string;
30
- readonly path: string;
31
- readonly parentPath?: string;
32
- }
33
-
34
- /**
35
- * Collection entity
36
- * Represents a Firestore collection with metadata
37
- */
38
- export class Collection<TDocument = unknown> {
39
- readonly name: string;
40
- readonly path: string;
41
- readonly parentPath: string | undefined;
42
- private readonly reference: CollectionReference<TDocument> | Query<TDocument>;
43
-
44
- constructor(
45
- reference: CollectionReference<TDocument> | Query<TDocument>,
46
- metadata: CollectionMetadata
47
- ) {
48
- this.reference = reference;
49
- this.name = metadata.name;
50
- this.path = metadata.path;
51
- this.parentPath = metadata.parentPath || undefined;
52
- }
53
-
54
- /**
55
- * Create collection from collection reference
56
- */
57
- static fromReference<TDocument = unknown>(
58
- reference: CollectionReference<TDocument>
59
- ): Collection<TDocument> {
60
- return fromReference(reference);
61
- }
62
-
63
- /**
64
- * Create collection from query
65
- */
66
- static fromQuery<TDocument = unknown>(query: Query<TDocument>, name: string, path: string): Collection<TDocument> {
67
- return fromQuery(query, name, path);
68
- }
69
-
70
- getName(): string {
71
- return this.name;
72
- }
73
-
74
- getPath(): string {
75
- return this.path;
76
- }
77
-
78
- getParentPath(): string | undefined {
79
- return this.parentPath;
80
- }
81
-
82
- isNested(): boolean {
83
- return this.parentPath !== undefined;
84
- }
85
-
86
- isRootLevel(): boolean {
87
- return this.parentPath === undefined;
88
- }
89
-
90
- getDepth(): number {
91
- return getCollectionDepth(this);
92
- }
93
-
94
- getReference(): CollectionReference<TDocument> | Query<TDocument> {
95
- return this.reference;
96
- }
97
-
98
- isQuery(): boolean {
99
- return isQueryReference(this.reference);
100
- }
101
-
102
- isCollectionReference(): boolean {
103
- return isCollectionReferenceUtil(this.reference);
104
- }
105
-
106
- toObject(): CollectionMetadata {
107
- return collectionToObject(this);
108
- }
109
-
110
- createSubCollectionPath(subCollectionName: string): string | null {
111
- return createSubCollectionPathUtil(this.path, subCollectionName);
112
- }
113
-
114
- isUserCollection(): boolean {
115
- return isUserCollectionPath(this.path);
116
- }
117
-
118
- extractUserId(): string | null {
119
- return extractUserIdFromPath(this.path);
120
- }
121
- }
122
-
@@ -1,55 +0,0 @@
1
- /**
2
- * Collection Factory
3
- * Single Responsibility: Create collection entities
4
- *
5
- * Max lines: 150 (enforced for maintainability)
6
- */
7
-
8
- import type { CollectionReference, Query } from 'firebase/firestore';
9
- import { Collection } from './Collection';
10
-
11
- /**
12
- * Create collection from collection reference
13
- */
14
- export function fromReference<TDocument = unknown>(
15
- reference: CollectionReference<TDocument>
16
- ): Collection<TDocument> {
17
- return new Collection(reference, {
18
- name: reference.id,
19
- path: reference.path,
20
- parentPath: reference.parent?.path || undefined,
21
- });
22
- }
23
-
24
- /**
25
- * Create collection from query
26
- */
27
- export function fromQuery<TDocument = unknown>(
28
- query: Query<TDocument>,
29
- name: string,
30
- path: string
31
- ): Collection<TDocument> {
32
- return new Collection(query, {
33
- name,
34
- path,
35
- parentPath: path.split('/').slice(0, -2).join('/') || undefined,
36
- });
37
- }
38
-
39
- /**
40
- * Factory function to create collection entity
41
- */
42
- export function createCollection<TDocument = unknown>(
43
- reference: CollectionReference<TDocument> | Query<TDocument>,
44
- name?: string,
45
- path?: string
46
- ): Collection<TDocument> {
47
- if ('type' in reference && reference.type === 'query') {
48
- if (!name || !path) {
49
- throw new Error('name and path are required for query collections');
50
- }
51
- return fromQuery(reference, name, path);
52
- }
53
-
54
- return fromReference(reference as CollectionReference<TDocument>);
55
- }
@@ -1,143 +0,0 @@
1
- /**
2
- * Collection Entity Helpers
3
- * Single Responsibility: Provide utility methods for collections
4
- *
5
- * Helper methods separated from main Collection entity.
6
- *
7
- * Max lines: 150 (enforced for maintainability)
8
- */
9
-
10
- import { Collection } from './Collection';
11
- import { isValidCollectionPath, isValidCollectionName } from './CollectionValidation';
12
-
13
- /**
14
- * Check if collection is parent of another
15
- */
16
- export function isParentOf(parent: Collection, child: Collection): boolean {
17
- const childPath = child.getPath();
18
- const parentPath = parent.getPath();
19
- return childPath.startsWith(parentPath + '/');
20
- }
21
-
22
- /**
23
- * Get collection ID (similar to name but more explicit)
24
- */
25
- export function getCollectionId(collection: Collection): string {
26
- return collection.getName();
27
- }
28
-
29
- /**
30
- * Check if collections are equal
31
- */
32
- export function collectionsEqual(col1: Collection, col2: Collection): boolean {
33
- return col1.getPath() === col2.getPath();
34
- }
35
-
36
- /**
37
- * Get collection size info (metadata)
38
- */
39
- export function getCollectionInfo(collection: Collection): {
40
- readonly name: string;
41
- readonly path: string;
42
- readonly depth: number;
43
- readonly isNested: boolean;
44
- readonly isRoot: boolean;
45
- readonly isUserCollection: boolean;
46
- } {
47
- return {
48
- name: collection.getName(),
49
- path: collection.getPath(),
50
- depth: collection.getDepth(),
51
- isNested: collection.isNested(),
52
- isRoot: collection.isRootLevel(),
53
- isUserCollection: collection.isUserCollection(),
54
- };
55
- }
56
-
57
- export function isValidCollection(collection: Collection): boolean {
58
- return isValidCollectionName(collection.getName()) &&
59
- isValidCollectionPath(collection.getPath());
60
- }
61
-
62
- export function collectionFromPath(db: any, path: string): Collection | null {
63
- if (!isValidCollectionPath(path)) {
64
- return null;
65
- }
66
-
67
- try {
68
- const ref = db.collection(path);
69
- return Collection.fromReference(ref as any);
70
- } catch {
71
- return null;
72
- }
73
- }
74
-
75
- export function getSubCollectionNames(path: string): string[] {
76
- if (!isValidCollectionPath(path)) {
77
- return [];
78
- }
79
-
80
- const segments = path.split('/');
81
- const collections: string[] = [];
82
-
83
- // Extract collection names (even indices)
84
- for (let i = 0; i < segments.length; i += 2) {
85
- const segment = segments[i];
86
- if (segment) {
87
- collections.push(segment);
88
- }
89
- }
90
-
91
- return collections;
92
- }
93
-
94
- export function buildCollectionPath(...parts: string[]): string {
95
- if (parts.length === 0 || parts.length % 2 !== 0) {
96
- throw new Error('Invalid collection path parts');
97
- }
98
-
99
- if (!parts.every(p => isValidCollectionName(p))) {
100
- throw new Error('Invalid collection name in parts');
101
- }
102
-
103
- return parts.join('/');
104
- }
105
-
106
- export function parseCollectionPath(path: string): {
107
- readonly collections: string[];
108
- readonly documents: string[];
109
- readonly segments: string[];
110
- } | null {
111
- if (!isValidCollectionPath(path)) {
112
- return null;
113
- }
114
-
115
- const segments = path.split('/');
116
- const collections: string[] = [];
117
- const documents: string[] = [];
118
-
119
- for (let i = 0; i < segments.length; i += 2) {
120
- const collectionSegment = segments[i];
121
- if (collectionSegment) {
122
- collections.push(collectionSegment);
123
- }
124
- if (i + 1 < segments.length) {
125
- const documentSegment = segments[i + 1];
126
- if (documentSegment) {
127
- documents.push(documentSegment);
128
- }
129
- }
130
- }
131
-
132
- return { collections, documents, segments };
133
- }
134
-
135
- export function isDocumentPath(path: string): boolean {
136
- const segments = path.split('/');
137
- return segments.length % 2 === 0 && segments.length >= 2;
138
- }
139
-
140
- export function isCollectionPath(path: string): boolean {
141
- const segments = path.split('/');
142
- return segments.length % 2 !== 0 && segments.length >= 1;
143
- }
@@ -1,72 +0,0 @@
1
- /**
2
- * Collection Utilities
3
- * Single Responsibility: Provide utility functions for collection operations
4
- *
5
- * Max lines: 150 (enforced for maintainability)
6
- */
7
-
8
- import type { CollectionReference, Query } from 'firebase/firestore';
9
- import type { Collection, CollectionMetadata } from './Collection';
10
-
11
- /**
12
- * Get collection depth in hierarchy
13
- * Root collections have depth 0
14
- */
15
- export function getCollectionDepth(collection: Collection): number {
16
- if (!collection.getParentPath()) return 0;
17
- const path = collection.getPath();
18
- return path.split('/').length / 2 - 1;
19
- }
20
-
21
- /**
22
- * Convert collection to plain object (for serialization)
23
- */
24
- export function collectionToObject(collection: Collection): CollectionMetadata {
25
- return {
26
- name: collection.getName(),
27
- path: collection.getPath(),
28
- parentPath: collection.getParentPath(),
29
- };
30
- }
31
-
32
- /**
33
- * Check if reference is a query (has filters/limits)
34
- */
35
- export function isQueryReference<TDocument>(
36
- reference: CollectionReference<TDocument> | Query<TDocument>
37
- ): boolean {
38
- return 'type' in reference && reference.type === 'query';
39
- }
40
-
41
- /**
42
- * Check if reference is a collection reference (no filters)
43
- */
44
- export function isCollectionReference<TDocument>(
45
- reference: CollectionReference<TDocument> | Query<TDocument>
46
- ): boolean {
47
- return !isQueryReference(reference);
48
- }
49
-
50
- /**
51
- * Get collection size info (metadata)
52
- */
53
- export function getCollectionInfo(collection: Collection): {
54
- readonly name: string;
55
- readonly path: string;
56
- readonly depth: number;
57
- readonly isNested: boolean;
58
- readonly isRoot: boolean;
59
- readonly isUserCollection: boolean;
60
- readonly isQuery: boolean;
61
- } {
62
- const reference = collection.getReference();
63
- return {
64
- name: collection.getName(),
65
- path: collection.getPath(),
66
- depth: getCollectionDepth(collection),
67
- isNested: collection.isNested(),
68
- isRoot: collection.isRootLevel(),
69
- isUserCollection: collection.isUserCollection(),
70
- isQuery: isQueryReference(reference),
71
- };
72
- }
@@ -1,138 +0,0 @@
1
- /**
2
- * Collection Validation Utilities
3
- * Single Responsibility: Validate collection names and paths
4
- *
5
- * Max lines: 150 (enforced for maintainability)
6
- */
7
-
8
- import type { Collection } from './Collection';
9
-
10
- /**
11
- * Validate collection name format
12
- */
13
- export function isValidCollectionName(name: string): boolean {
14
- if (!name || typeof name !== 'string' || name.trim() === '') {
15
- return false;
16
- }
17
-
18
- const invalidChars = /[\/\\.\s]/;
19
- if (invalidChars.test(name)) {
20
- return false;
21
- }
22
-
23
- if (name.startsWith('__') || name.endsWith('__')) {
24
- return false;
25
- }
26
-
27
- if (name.length > 100) {
28
- return false;
29
- }
30
-
31
- return true;
32
- }
33
-
34
- /**
35
- * Check if collection is valid
36
- */
37
- export function isValidCollection(collection: Collection): boolean {
38
- return isValidCollectionName(collection.getName()) &&
39
- isValidCollectionPath(collection.getPath());
40
- }
41
-
42
- /**
43
- * Validate collection path format
44
- */
45
- export function isValidCollectionPath(path: string): boolean {
46
- if (!path || typeof path !== 'string' || path.trim() === '') {
47
- return false;
48
- }
49
-
50
- const segments = path.split('/');
51
- if (segments.length < 1 || segments.length % 2 === 0) {
52
- return false;
53
- }
54
-
55
- return segments.every(segment => isValidCollectionName(segment));
56
- }
57
-
58
- /**
59
- * Extract collection name from path
60
- */
61
- export function extractCollectionNameFromPath(path: string): string | null {
62
- if (!isValidCollectionPath(path)) {
63
- return null;
64
- }
65
-
66
- const segments = path.split('/');
67
- return segments[segments.length - 1] || null;
68
- }
69
-
70
- /**
71
- * Extract parent path from collection path
72
- */
73
- export function extractParentCollectionPath(path: string): string | null {
74
- if (!isValidCollectionPath(path)) {
75
- return null;
76
- }
77
-
78
- const segments = path.split('/');
79
- if (segments.length <= 1) {
80
- return null;
81
- }
82
-
83
- const result = segments.slice(0, -1).join('/');
84
- return result || null;
85
- }
86
-
87
- /**
88
- * Check if path points to document
89
- */
90
- export function isDocumentPath(path: string): boolean {
91
- const segments = path.split('/');
92
- return segments.length % 2 === 0 && segments.length >= 2;
93
- }
94
-
95
- /**
96
- * Check if path points to collection
97
- */
98
- export function isCollectionPath(path: string): boolean {
99
- const segments = path.split('/');
100
- return segments.length % 2 !== 0 && segments.length >= 1;
101
- }
102
-
103
- /**
104
- * Check if collection is a user collection (users/{userId}/{collection})
105
- */
106
- export function isUserCollectionPath(path: string): boolean {
107
- return path.startsWith('users/');
108
- }
109
-
110
- /**
111
- * Extract user ID from user collection path
112
- */
113
- export function extractUserIdFromPath(path: string): string | null {
114
- if (!isUserCollectionPath(path)) return null;
115
-
116
- const segments = path.split('/');
117
- if (segments.length >= 3 && segments[0] === 'users') {
118
- const userId = segments[1];
119
- return userId || null;
120
- }
121
-
122
- return null;
123
- }
124
-
125
- /**
126
- * Create a sub-collection path
127
- */
128
- export function createSubCollectionPath(parentPath: string, subCollectionName: string): string | null {
129
- if (!isValidCollectionPath(parentPath)) {
130
- return null;
131
- }
132
-
133
- if (!isValidCollectionName(subCollectionName)) {
134
- return null;
135
- }
136
-
137
- return `${parentPath}/${subCollectionName}`;
138
- }
@@ -1,61 +0,0 @@
1
- /**
2
- * Firestore Domain Layer
3
- * Domain-Driven Design (DDD) - Domain Exports
4
- *
5
- * Pure domain logic without infrastructure concerns.
6
- * Exports entities, value objects, and domain services.
7
- */
8
-
9
- // Domain Errors
10
- export {
11
- FirebaseFirestoreError,
12
- FirebaseFirestoreInitializationError,
13
- FirebaseFirestoreQuotaError,
14
- } from './errors/FirebaseFirestoreError';
15
-
16
- // Domain Entities
17
- export { Collection } from './entities/Collection';
18
- export { fromReference, fromQuery, createCollection } from './entities/CollectionFactory';
19
- export type { CollectionMetadata } from './entities/Collection';
20
-
21
- // Collection Entity Helpers
22
- export {
23
- isParentOf,
24
- getCollectionId,
25
- collectionsEqual,
26
- getCollectionInfo,
27
- collectionFromPath,
28
- getSubCollectionNames,
29
- buildCollectionPath,
30
- parseCollectionPath,
31
- } from './entities/CollectionHelpers';
32
-
33
- // Collection Utilities
34
- export {
35
- getCollectionDepth,
36
- collectionToObject,
37
- isQueryReference,
38
- } from './entities/CollectionUtils';
39
-
40
- // Collection Validation
41
- export {
42
- isValidCollectionName,
43
- isValidCollectionPath,
44
- isValidCollection,
45
- extractCollectionNameFromPath,
46
- extractParentCollectionPath,
47
- isDocumentPath,
48
- isCollectionPath,
49
- isUserCollectionPath,
50
- extractUserIdFromPath,
51
- createSubCollectionPath,
52
- } from './entities/CollectionValidation';
53
-
54
- // Domain Value Objects
55
- export { QueryOptions, createQueryOptions } from './value-objects/QueryOptions';
56
- export type { SortOptions, DateRangeOptions, PaginationOptions } from './value-objects/QueryOptions';
57
-
58
- // Where Clause
59
- export { WhereClause } from './value-objects/WhereClause';
60
- export { equals, where, fromObject as createWhereClause } from './value-objects/WhereClauseFactory';
61
- export type { WhereOperator } from './value-objects/WhereClause';