@umituz/react-native-firebase 2.6.1 → 2.6.3

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 (94) hide show
  1. package/package.json +1 -1
  2. package/src/application/auth/ports/AuthPort_part_aa +150 -0
  3. package/src/application/auth/ports/AuthPort_part_ab +14 -0
  4. package/src/application/auth/use-cases/SignInUseCaseHelpers.ts +0 -0
  5. package/src/application/auth/use-cases/SignInUseCaseMain.ts +0 -0
  6. package/src/application/auth/use-cases/SignInUseCase_part_aa +150 -0
  7. package/src/application/auth/use-cases/SignInUseCase_part_ab +103 -0
  8. package/src/application/auth/use-cases/SignOutUseCaseCleanup.ts +0 -0
  9. package/src/application/auth/use-cases/SignOutUseCaseMain.ts +0 -0
  10. package/src/application/auth/use-cases/SignOutUseCase_part_aa +150 -0
  11. package/src/application/auth/use-cases/SignOutUseCase_part_ab +138 -0
  12. package/src/domains/account-deletion/domain/services/UserValidationHelpers.ts.bak +181 -0
  13. package/src/domains/account-deletion/domain/services/UserValidationHelpers_part_aa +150 -0
  14. package/src/domains/account-deletion/domain/services/UserValidationHelpers_part_ab +31 -0
  15. package/src/domains/account-deletion/domain/services/{UserValidationService.ts → UserValidationService.ts.bak} +1 -10
  16. package/src/domains/account-deletion/domain/services/UserValidationService_part_aa +150 -0
  17. package/src/domains/account-deletion/domain/services/UserValidationService_part_ab +136 -0
  18. package/src/domains/account-deletion/infrastructure/services/AccountDeletionExecutor_part_aa +150 -0
  19. package/src/domains/account-deletion/infrastructure/services/AccountDeletionExecutor_part_ab +80 -0
  20. package/src/domains/account-deletion/infrastructure/services/AccountDeletionReauthHandler_part_aa +150 -0
  21. package/src/domains/account-deletion/infrastructure/services/AccountDeletionReauthHandler_part_ab +24 -0
  22. package/src/domains/account-deletion/infrastructure/services/AccountDeletionRepository_part_aa +150 -0
  23. package/src/domains/account-deletion/infrastructure/services/AccountDeletionRepository_part_ab +116 -0
  24. package/src/domains/account-deletion/infrastructure/services/reauthentication.service_part_aa +150 -0
  25. package/src/domains/account-deletion/infrastructure/services/reauthentication.service_part_ab +10 -0
  26. package/src/domains/auth/infrastructure_part_aa +150 -0
  27. package/src/domains/auth/infrastructure_part_ab +6 -0
  28. package/src/domains/auth/presentation/hooks/GoogleOAuthHelpers.ts +0 -0
  29. package/src/domains/auth/presentation/hooks/GoogleOAuthHookService_part_aa +150 -0
  30. package/src/domains/auth/presentation/hooks/GoogleOAuthHookService_part_ab +97 -0
  31. package/src/domains/auth/presentation/hooks/GoogleOAuthService.ts +0 -0
  32. package/src/domains/firestore/domain/entities/Collection.ts +31 -191
  33. package/src/domains/firestore/domain/entities/Collection.ts.bak +288 -0
  34. package/src/domains/firestore/domain/entities/CollectionFactory.ts +55 -0
  35. package/src/domains/firestore/domain/entities/CollectionHelpers.ts +143 -0
  36. package/src/domains/firestore/domain/entities/CollectionUtils.ts +72 -0
  37. package/src/domains/firestore/domain/entities/CollectionValidation.ts +138 -0
  38. package/src/domains/firestore/domain/entities/Collection_part_aa +150 -0
  39. package/src/domains/firestore/domain/entities/Collection_part_ab +138 -0
  40. package/src/domains/firestore/domain/entities/DocumentHelpers.ts +0 -0
  41. package/src/domains/firestore/domain/entities/DocumentMain.ts +0 -0
  42. package/src/domains/firestore/domain/entities/Document_part_aa +150 -0
  43. package/src/domains/firestore/domain/entities/Document_part_ab +83 -0
  44. package/src/domains/firestore/domain/index.ts +35 -8
  45. package/src/domains/firestore/domain/services/QueryServiceAnalysis_part_aa +150 -0
  46. package/src/domains/firestore/domain/services/QueryServiceAnalysis_part_ab +19 -0
  47. package/src/domains/firestore/domain/services/QueryServiceHelpers_part_aa +150 -0
  48. package/src/domains/firestore/domain/services/QueryServiceHelpers_part_ab +1 -0
  49. package/src/domains/firestore/domain/services/QueryService_part_aa +150 -0
  50. package/src/domains/firestore/domain/services/QueryService_part_ab +32 -0
  51. package/src/domains/firestore/domain/value-objects/QueryOptions.ts +20 -68
  52. package/src/domains/firestore/domain/value-objects/QueryOptions.ts.bak +6 -135
  53. package/src/domains/firestore/domain/value-objects/QueryOptionsFactory.ts +95 -0
  54. package/src/domains/firestore/domain/value-objects/QueryOptionsHelpers.ts +110 -0
  55. package/src/domains/firestore/domain/value-objects/QueryOptionsSerialization_part_aa +150 -0
  56. package/src/domains/firestore/domain/value-objects/QueryOptionsSerialization_part_ab +57 -0
  57. package/src/domains/firestore/domain/value-objects/QueryOptionsValidation_part_aa +150 -0
  58. package/src/domains/firestore/domain/value-objects/QueryOptionsValidation_part_ab +32 -0
  59. package/src/domains/firestore/domain/value-objects/QueryOptions_part_aa +150 -0
  60. package/src/domains/firestore/domain/value-objects/QueryOptions_part_ab +41 -0
  61. package/src/domains/firestore/domain/value-objects/WhereClause.ts +35 -205
  62. package/src/domains/firestore/domain/value-objects/WhereClause.ts.bak +299 -0
  63. package/src/domains/firestore/domain/value-objects/WhereClauseFactory.ts +44 -150
  64. package/src/domains/firestore/domain/value-objects/WhereClauseFactory.ts.bak +207 -0
  65. package/src/domains/firestore/domain/value-objects/WhereClauseFactory_part_aa +150 -0
  66. package/src/domains/firestore/domain/value-objects/WhereClauseFactory_part_ab +57 -0
  67. package/src/domains/firestore/domain/value-objects/WhereClauseHelpers.ts +123 -0
  68. package/src/domains/firestore/domain/value-objects/WhereClauseValidation.ts +83 -0
  69. package/src/domains/firestore/domain/value-objects/WhereClause_part_aa +150 -0
  70. package/src/domains/firestore/domain/value-objects/WhereClause_part_ab +149 -0
  71. package/src/shared/infrastructure/base/ErrorHandler_part_aa +150 -0
  72. package/src/shared/infrastructure/base/ErrorHandler_part_ab +39 -0
  73. package/src/shared/infrastructure/base/ServiceBase_part_aa +150 -0
  74. package/src/shared/infrastructure/base/ServiceBase_part_ab +70 -0
  75. package/src/shared/infrastructure/config/base/ServiceClientSingleton_part_aa +150 -0
  76. package/src/shared/infrastructure/config/base/ServiceClientSingleton_part_ab +5 -0
  77. /package/src/application/auth/ports/{AuthPort.ts → AuthPort.ts.bak} +0 -0
  78. /package/src/application/auth/use-cases/{SignInUseCase.ts → SignInUseCase.ts.bak} +0 -0
  79. /package/src/application/auth/use-cases/{SignOutUseCase.ts → SignOutUseCase.ts.bak} +0 -0
  80. /package/src/domains/account-deletion/infrastructure/services/{AccountDeletionExecutor.ts → AccountDeletionExecutor.ts.bak} +0 -0
  81. /package/src/domains/account-deletion/infrastructure/services/{AccountDeletionReauthHandler.ts → AccountDeletionReauthHandler.ts.bak} +0 -0
  82. /package/src/domains/account-deletion/infrastructure/services/{AccountDeletionRepository.ts → AccountDeletionRepository.ts.bak} +0 -0
  83. /package/src/domains/account-deletion/infrastructure/services/{reauthentication.service.ts → reauthentication.service.ts.bak} +0 -0
  84. /package/src/domains/auth/{infrastructure.ts → infrastructure.ts.bak} +0 -0
  85. /package/src/domains/auth/presentation/hooks/{GoogleOAuthHookService.ts → GoogleOAuthHookService.ts.bak} +0 -0
  86. /package/src/domains/firestore/domain/entities/{Document.ts → Document.ts.bak} +0 -0
  87. /package/src/domains/firestore/domain/services/{QueryService.ts → QueryService.ts.bak} +0 -0
  88. /package/src/domains/firestore/domain/services/{QueryServiceAnalysis.ts → QueryServiceAnalysis.ts.bak} +0 -0
  89. /package/src/domains/firestore/domain/services/{QueryServiceHelpers.ts → QueryServiceHelpers.ts.bak} +0 -0
  90. /package/src/domains/firestore/domain/value-objects/{QueryOptionsSerialization.ts → QueryOptionsSerialization.ts.bak} +0 -0
  91. /package/src/domains/firestore/domain/value-objects/{QueryOptionsValidation.ts → QueryOptionsValidation.ts.bak} +0 -0
  92. /package/src/shared/infrastructure/base/{ErrorHandler.ts → ErrorHandler.ts.bak} +0 -0
  93. /package/src/shared/infrastructure/base/{ServiceBase.ts → ServiceBase.ts.bak} +0 -0
  94. /package/src/shared/infrastructure/config/base/{ServiceClientSingleton.ts → ServiceClientSingleton.ts.bak} +0 -0
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Where Clause Helper Utilities
3
+ * Single Responsibility: Provide helper functions for where clauses
4
+ *
5
+ * Max lines: 150 (enforced for maintainability)
6
+ */
7
+
8
+ import type { WhereFilterOp } from 'firebase/firestore';
9
+ import type { WhereClause } from './WhereClause';
10
+ import {
11
+ isEqualityOperator,
12
+ isInequalityOperator,
13
+ isComparisonOperator,
14
+ isArrayOperator,
15
+ isMembershipOperator,
16
+ } from './WhereClauseValidation';
17
+
18
+ /**
19
+ * Get field path as array
20
+ */
21
+ export function getFieldPath(clause: WhereClause): string[] {
22
+ return clause.field.split('.');
23
+ }
24
+
25
+ /**
26
+ * Check if field is nested
27
+ */
28
+ export function isNestedField(clause: WhereClause): boolean {
29
+ return clause.field.includes('.');
30
+ }
31
+
32
+ /**
33
+ * Get top-level field name
34
+ */
35
+ export function getTopLevelField(clause: WhereClause): string {
36
+ const parts = clause.field.split('.');
37
+ return parts[0] || '';
38
+ }
39
+
40
+ /**
41
+ * Get description of where clause
42
+ */
43
+ export function getDescription(clause: WhereClause): string {
44
+ return `${clause.field} ${clause.operator} ${JSON.stringify(clause.value)}`;
45
+ }
46
+
47
+ /**
48
+ * Convert where clause to object
49
+ */
50
+ export function toObject(clause: WhereClause): {
51
+ field: string;
52
+ operator: WhereFilterOp;
53
+ value: unknown;
54
+ } {
55
+ return {
56
+ field: clause.field,
57
+ operator: clause.operator,
58
+ value: clause.value,
59
+ };
60
+ }
61
+
62
+ /**
63
+ * Check if two where clauses are equal
64
+ */
65
+ export function whereClausesEqual(a: WhereClause, b: WhereClause): boolean {
66
+ return (
67
+ a.field === b.field &&
68
+ a.operator === b.operator &&
69
+ JSON.stringify(a.value) === JSON.stringify(b.value)
70
+ );
71
+ }
72
+
73
+ /**
74
+ * Check if where clauses are compatible (can be used together)
75
+ */
76
+ export function areClausesCompatible(a: WhereClause, b: WhereClause): boolean {
77
+ // Same field with different operators is not allowed
78
+ if (a.field === b.field && a.operator !== b.operator) {
79
+ return false;
80
+ }
81
+
82
+ // Inequality operators cannot be combined with other inequality operators on same field
83
+ if (a.field === b.field && isInequalityOperator(a.operator) && isInequalityOperator(b.operator)) {
84
+ return false;
85
+ }
86
+
87
+ return true;
88
+ }
89
+
90
+ /**
91
+ * Check if clause is equality type
92
+ */
93
+ export function isEqualityClause(clause: WhereClause): boolean {
94
+ return isEqualityOperator(clause.operator);
95
+ }
96
+
97
+ /**
98
+ * Check if clause is inequality type
99
+ */
100
+ export function isInequalityClause(clause: WhereClause): boolean {
101
+ return isInequalityOperator(clause.operator);
102
+ }
103
+
104
+ /**
105
+ * Check if clause is comparison type
106
+ */
107
+ export function isComparisonClause(clause: WhereClause): boolean {
108
+ return isComparisonOperator(clause.operator);
109
+ }
110
+
111
+ /**
112
+ * Check if clause is array type
113
+ */
114
+ export function isArrayClause(clause: WhereClause): boolean {
115
+ return isArrayOperator(clause.operator);
116
+ }
117
+
118
+ /**
119
+ * Check if clause is membership type
120
+ */
121
+ export function isMembershipClause(clause: WhereClause): boolean {
122
+ return isMembershipOperator(clause.operator);
123
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Where Clause Validation Utilities
3
+ * Single Responsibility: Validate where clauses
4
+ *
5
+ * Max lines: 150 (enforced for maintainability)
6
+ */
7
+
8
+ import type { WhereFilterOp } from 'firebase/firestore';
9
+ import type { WhereClause } from './WhereClause';
10
+
11
+ /**
12
+ * Validate where clause
13
+ */
14
+ export function validateWhereClause(clause: WhereClause): {
15
+ valid: boolean;
16
+ errors: string[];
17
+ } {
18
+ const errors: string[] = [];
19
+
20
+ // Field validation
21
+ if (!clause.field || clause.field.trim() === '') {
22
+ errors.push('Field cannot be empty');
23
+ }
24
+
25
+ // Value validation
26
+ if (clause.value === undefined) {
27
+ errors.push('Value cannot be undefined');
28
+ }
29
+
30
+ // Operator-specific validation
31
+ if (requiresArrayValue(clause.operator)) {
32
+ if (!Array.isArray(clause.value)) {
33
+ errors.push(`Operator '${clause.operator}' requires an array value`);
34
+ }
35
+ }
36
+
37
+ return {
38
+ valid: errors.length === 0,
39
+ errors,
40
+ };
41
+ }
42
+
43
+ /**
44
+ * Check if operator requires array value
45
+ */
46
+ export function requiresArrayValue(operator: WhereFilterOp): boolean {
47
+ return operator === 'in' || operator === 'not-in' || operator === 'array-contains-any';
48
+ }
49
+
50
+ /**
51
+ * Check if operator is equality type
52
+ */
53
+ export function isEqualityOperator(operator: WhereFilterOp): boolean {
54
+ return operator === '==';
55
+ }
56
+
57
+ /**
58
+ * Check if operator is inequality type
59
+ */
60
+ export function isInequalityOperator(operator: WhereFilterOp): boolean {
61
+ return operator === '!=';
62
+ }
63
+
64
+ /**
65
+ * Check if operator is comparison type
66
+ */
67
+ export function isComparisonOperator(operator: WhereFilterOp): boolean {
68
+ return ['<', '<=', '>', '>='].includes(operator);
69
+ }
70
+
71
+ /**
72
+ * Check if operator is array type
73
+ */
74
+ export function isArrayOperator(operator: WhereFilterOp): boolean {
75
+ return operator === 'array-contains' || operator === 'array-contains-any';
76
+ }
77
+
78
+ /**
79
+ * Check if operator is membership type
80
+ */
81
+ export function isMembershipOperator(operator: WhereFilterOp): boolean {
82
+ return operator === 'in' || operator === 'not-in';
83
+ }
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Where Clause Value Object
3
+ * Single Responsibility: Encapsulate where clause conditions
4
+ *
5
+ * Value object that represents a single where clause condition.
6
+ * Provides validation and business logic for query filtering.
7
+ *
8
+ * Max lines: 150 (enforced for maintainability)
9
+ */
10
+
11
+ import type { WhereFilterOp } from 'firebase/firestore';
12
+
13
+ /**
14
+ * Valid where operators for Firestore queries
15
+ */
16
+ export type WhereOperator =
17
+ | '=='
18
+ | '!='
19
+ | '<'
20
+ | '<='
21
+ | '>'
22
+ | '>='
23
+ | 'array-contains'
24
+ | 'array-contains-any'
25
+ | 'in'
26
+ | 'not-in';
27
+
28
+ /**
29
+ * Where clause value object
30
+ * Immutable representation of a single query condition
31
+ */
32
+ export class WhereClause {
33
+ readonly field: string;
34
+ readonly operator: WhereFilterOp;
35
+ readonly value: unknown;
36
+
37
+ private constructor(field: string, operator: WhereFilterOp, value: unknown) {
38
+ this.field = field;
39
+ this.operator = operator;
40
+ this.value = Object.freeze(value);
41
+ }
42
+
43
+ /**
44
+ * Create a where clause
45
+ */
46
+ static create(field: string, operator: WhereFilterOp, value: unknown): WhereClause {
47
+ return new WhereClause(field, operator, value);
48
+ }
49
+
50
+ /**
51
+ * Create equality clause (==)
52
+ */
53
+ static equals(field: string, value: unknown): WhereClause {
54
+ return new WhereClause(field, '==', value);
55
+ }
56
+
57
+ /**
58
+ * Create inequality clause (!=)
59
+ */
60
+ static notEquals(field: string, value: unknown): WhereClause {
61
+ return new WhereClause(field, '!=', value);
62
+ }
63
+
64
+ /**
65
+ * Create less than clause (<)
66
+ */
67
+ static lessThan(field: string, value: unknown): WhereClause {
68
+ return new WhereClause(field, '<', value);
69
+ }
70
+
71
+ /**
72
+ * Create less than or equal clause (<=)
73
+ */
74
+ static lessThanOrEqual(field: string, value: unknown): WhereClause {
75
+ return new WhereClause(field, '<=', value);
76
+ }
77
+
78
+ /**
79
+ * Create greater than clause (>)
80
+ */
81
+ static greaterThan(field: string, value: unknown): WhereClause {
82
+ return new WhereClause(field, '>', value);
83
+ }
84
+
85
+ /**
86
+ * Create greater than or equal clause (>=)
87
+ */
88
+ static greaterThanOrEqual(field: string, value: unknown): WhereClause {
89
+ return new WhereClause(field, '>=', value);
90
+ }
91
+
92
+ /**
93
+ * Create array contains clause
94
+ */
95
+ static arrayContains(field: string, value: unknown): WhereClause {
96
+ return new WhereClause(field, 'array-contains', value);
97
+ }
98
+
99
+ /**
100
+ * Create array contains any clause
101
+ */
102
+ static arrayContainsAny(field: string, values: unknown[]): WhereClause {
103
+ return new WhereClause(field, 'array-contains-any', values);
104
+ }
105
+
106
+ /**
107
+ * Create in clause
108
+ */
109
+ static in(field: string, values: unknown[]): WhereClause {
110
+ return new WhereClause(field, 'in', values);
111
+ }
112
+
113
+ /**
114
+ * Create not-in clause
115
+ */
116
+ static notIn(field: string, values: unknown[]): WhereClause {
117
+ return new WhereClause(field, 'not-in', values);
118
+ }
119
+
120
+ /**
121
+ * Validate where clause
122
+ */
123
+ validate(): { valid: boolean; errors: string[] } {
124
+ const errors: string[] = [];
125
+
126
+ // Validate field name
127
+ if (!this.field || typeof this.field !== 'string' || this.field.trim() === '') {
128
+ errors.push('Field name must be a non-empty string');
129
+ }
130
+
131
+ // Validate operator
132
+ const validOperators: WhereFilterOp[] = [
133
+ '==', '!=', '<', '<=', '>', '>=',
134
+ 'array-contains', 'array-contains-any', 'in', 'not-in'
135
+ ];
136
+ if (!validOperators.includes(this.operator)) {
137
+ errors.push(`Invalid operator: ${this.operator}`);
138
+ }
139
+
140
+ // Validate value based on operator
141
+ if (this.operator === 'array-contains-any' || this.operator === 'in' || this.operator === 'not-in') {
142
+ if (!Array.isArray(this.value)) {
143
+ errors.push(`Operator ${this.operator} requires an array value`);
144
+ } else if (this.value.length === 0) {
145
+ errors.push(`Operator ${this.operator} requires a non-empty array`);
146
+ } else if (this.value.length > 10) {
147
+ errors.push(`Operator ${this.operator} supports maximum 10 elements`);
148
+ }
149
+ }
150
+
@@ -0,0 +1,149 @@
1
+ return {
2
+ valid: errors.length === 0,
3
+ errors,
4
+ };
5
+ }
6
+
7
+ /**
8
+ * Check if equals another where clause
9
+ */
10
+ equals(other: WhereClause): boolean {
11
+ return (
12
+ this.field === other.field &&
13
+ this.operator === other.operator &&
14
+ JSON.stringify(this.value) === JSON.stringify(other.value)
15
+ );
16
+ }
17
+
18
+ /**
19
+ * Check if compatible for compound queries
20
+ * Some operator combinations are not allowed in Firestore
21
+ */
22
+ isCompatibleWith(other: WhereClause): boolean {
23
+ // Equality and inequality operators can be combined
24
+ // Array operators and membership operators have restrictions
25
+ if (
26
+ (this.isArrayOperator() || this.isMembership()) &&
27
+ (other.isArrayOperator() || other.isMembership())
28
+ ) {
29
+ // Only one array/membership clause per query
30
+ return false;
31
+ }
32
+
33
+ return true;
34
+ }
35
+
36
+ /**
37
+ * Get field path components
38
+ * Returns array of field path segments (for nested fields)
39
+ */
40
+ getFieldPath(): string[] {
41
+ return this.field.split('.');
42
+ }
43
+
44
+ /**
45
+ * Check if field is nested (contains dots)
46
+ */
47
+ isNestedField(): boolean {
48
+ return this.field.includes('.');
49
+ }
50
+
51
+ /**
52
+ * Get top-level field name
53
+ */
54
+ getTopLevelField(): string {
55
+ return this.getFieldPath()[0];
56
+ }
57
+
58
+ /**
59
+ * Get human-readable description
60
+ */
61
+ getDescription(): string {
62
+ const valueStr = Array.isArray(this.value)
63
+ ? `[${this.value.map(v => JSON.stringify(v)).join(', ')}]`
64
+ : JSON.stringify(this.value);
65
+
66
+ return `${this.field} ${this.operator} ${valueStr}`;
67
+ }
68
+
69
+ /**
70
+ * Convert to plain object (for serialization)
71
+ */
72
+ toObject(): { field: string; operator: WhereFilterOp; value: unknown } {
73
+ return {
74
+ field: this.field,
75
+ operator: this.operator,
76
+ value: this.value,
77
+ };
78
+ }
79
+
80
+ /**
81
+ * Create from plain object
82
+ */
83
+ static fromObject(obj: { field: string; operator: WhereFilterOp; value: unknown }): WhereClause {
84
+ return WhereClause.create(obj.field, obj.operator, obj.value);
85
+ }
86
+
87
+ /**
88
+ * Clone with new value
89
+ */
90
+ withValue(newValue: unknown): WhereClause {
91
+ return new WhereClause(this.field, this.operator, newValue);
92
+ }
93
+
94
+ /**
95
+ * Clone with new field
96
+ */
97
+ withField(newField: string): WhereClause {
98
+ return new WhereClause(newField, this.operator, this.value);
99
+ }
100
+
101
+ /**
102
+ * Clone with new operator
103
+ */
104
+ withOperator(newOperator: WhereFilterOp): WhereClause {
105
+ return new WhereClause(this.field, newOperator, this.value);
106
+ }
107
+
108
+ /**
109
+ * Check if is equality operator
110
+ */
111
+ isEquality(): boolean {
112
+ return this.operator === '==';
113
+ }
114
+
115
+ /**
116
+ * Check if is inequality operator
117
+ */
118
+ isInequality(): boolean {
119
+ return this.operator === '!=';
120
+ }
121
+
122
+ /**
123
+ * Check if is comparison operator (<, <=, >, >=)
124
+ */
125
+ isComparison(): boolean {
126
+ return ['<', '<=', '>', '>='].includes(this.operator);
127
+ }
128
+
129
+ /**
130
+ * Check if is array operator
131
+ */
132
+ isArrayOperator(): boolean {
133
+ return ['array-contains', 'array-contains-any'].includes(this.operator);
134
+ }
135
+
136
+ /**
137
+ * Check if is membership operator (in, not-in)
138
+ */
139
+ isMembership(): boolean {
140
+ return ['in', 'not-in'].includes(this.operator);
141
+ }
142
+
143
+ /**
144
+ * Check if operator requires array value
145
+ */
146
+ requiresArrayValue(): boolean {
147
+ return ['array-contains-any', 'in', 'not-in'].includes(this.operator);
148
+ }
149
+ }
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Error Handler Base Class
3
+ * Single Responsibility: Centralized error handling and conversion
4
+ *
5
+ * Eliminates try-catch duplication across 9+ files.
6
+ * Provides standardized error-to-ErrorInfo conversion.
7
+ * Integrates with existing Result pattern.
8
+ *
9
+ * Max lines: 150 (enforced for maintainability)
10
+ */
11
+
12
+ import type { ErrorInfo } from '../../domain/utils';
13
+ import { toErrorInfo, successResult, type Result } from '../../domain/utils';
14
+ import { isCancelledError, isQuotaError, isRetryableError } from '../../domain/utils/error-handlers/error-checkers';
15
+ import { ERROR_MESSAGES } from '../../domain/utils/error-handlers/error-messages';
16
+
17
+ /**
18
+ * Error handler options
19
+ */
20
+ export interface ErrorHandlerOptions {
21
+ /** Default error code if none can be extracted */
22
+ defaultErrorCode?: string;
23
+ /** Custom error message mapper */
24
+ errorMapper?: (error: unknown) => string | null;
25
+ /** Enable detailed logging in development */
26
+ enableDevLogging?: boolean;
27
+ }
28
+
29
+ /**
30
+ * Base class for error handling
31
+ * Provides centralized error conversion and handling
32
+ */
33
+ export class ErrorHandler {
34
+ private readonly options: ErrorHandlerOptions;
35
+
36
+ constructor(options: ErrorHandlerOptions = {}) {
37
+ this.options = {
38
+ defaultErrorCode: 'unknown/error',
39
+ enableDevLogging: __DEV__,
40
+ ...options,
41
+ };
42
+ }
43
+
44
+ /**
45
+ * Wrap an async operation with standardized error handling
46
+ * Eliminates try-catch duplication across services
47
+ */
48
+ async handleAsync<T>(
49
+ operation: () => Promise<T>,
50
+ errorCode: string = this.options.defaultErrorCode || 'unknown/error'
51
+ ): Promise<Result<T>> {
52
+ try {
53
+ const result = await operation();
54
+ return successResult(result);
55
+ } catch (error) {
56
+ if (this.options.enableDevLogging) {
57
+ console.error(`[ErrorHandler] Operation failed: ${errorCode}`, error);
58
+ }
59
+ return { success: false, error: toErrorInfo(error, errorCode) };
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Wrap a synchronous operation with standardized error handling
65
+ */
66
+ handle<T>(
67
+ operation: () => T,
68
+ errorCode: string = this.options.defaultErrorCode || 'unknown/error'
69
+ ): Result<T> {
70
+ try {
71
+ const result = operation();
72
+ return successResult(result);
73
+ } catch (error) {
74
+ if (this.options.enableDevLogging) {
75
+ console.error(`[ErrorHandler] Operation failed: ${errorCode}`, error);
76
+ }
77
+ return { success: false, error: toErrorInfo(error, errorCode) };
78
+ }
79
+ }
80
+
81
+ /**
82
+ * Convert error to ErrorInfo with optional custom code
83
+ */
84
+ toErrorInfo(error: unknown, code?: string): ErrorInfo {
85
+ // Try custom error mapper first
86
+ if (this.options.errorMapper) {
87
+ const customMessage = this.options.errorMapper(error);
88
+ if (customMessage) {
89
+ return {
90
+ code: code || this.options.defaultErrorCode || 'unknown/error',
91
+ message: customMessage,
92
+ };
93
+ }
94
+ }
95
+
96
+ // Use standard conversion
97
+ return toErrorInfo(error, code || this.options.defaultErrorCode);
98
+ }
99
+
100
+ /**
101
+ * Check if error is a cancelled operation
102
+ */
103
+ isCancelledError(error: unknown): boolean {
104
+ return isCancelledError(error);
105
+ }
106
+
107
+ /**
108
+ * Check if error is a quota error
109
+ */
110
+ isQuotaError(error: unknown): boolean {
111
+ return isQuotaError(error);
112
+ }
113
+
114
+ /**
115
+ * Check if error is retryable
116
+ */
117
+ isRetryableError(error: unknown): boolean {
118
+ return isRetryableError(error);
119
+ }
120
+
121
+ /**
122
+ * Get user-friendly error message
123
+ * Maps error codes to user-friendly messages
124
+ */
125
+ getUserMessage(error: ErrorInfo): string {
126
+ // Check if it's a known error category
127
+ if (error.code.startsWith('auth/')) {
128
+ return this.getAuthUserMessage(error.code);
129
+ }
130
+ if (error.code.startsWith('firestore/')) {
131
+ return this.getFirestoreUserMessage(error.code);
132
+ }
133
+ if (error.code.startsWith('storage/')) {
134
+ return ERROR_MESSAGES.STORAGE.GENERIC_ERROR;
135
+ }
136
+
137
+ return error.message || ERROR_MESSAGES.GENERAL.UNKNOWN;
138
+ }
139
+
140
+ /**
141
+ * Get user-friendly auth error message
142
+ */
143
+ private getAuthUserMessage(code: string): string {
144
+ // Map common auth error codes to user-friendly messages
145
+ const authMessages: Record<string, string> = {
146
+ 'auth/user-not-found': ERROR_MESSAGES.AUTH.USER_NOT_FOUND,
147
+ 'auth/wrong-password': ERROR_MESSAGES.AUTH.INVALID_CREDENTIALS,
148
+ 'auth/email-already-in-use': ERROR_MESSAGES.AUTH.EMAIL_ALREADY_IN_USE,
149
+ 'auth/invalid-email': ERROR_MESSAGES.AUTH.INVALID_EMAIL,
150
+ 'auth/weak-password': ERROR_MESSAGES.AUTH.WEAK_PASSWORD,
@@ -0,0 +1,39 @@
1
+ 'auth/too-many-requests': ERROR_MESSAGES.AUTH.TOO_MANY_REQUESTS,
2
+ 'auth/user-disabled': ERROR_MESSAGES.AUTH.USER_DISABLED,
3
+ };
4
+
5
+ return authMessages[code] || ERROR_MESSAGES.AUTH.GENERIC_ERROR;
6
+ }
7
+
8
+ /**
9
+ * Get user-friendly firestore error message
10
+ */
11
+ private getFirestoreUserMessage(code: string): string {
12
+ const firestoreMessages: Record<string, string> = {
13
+ 'firestore/permission-denied': ERROR_MESSAGES.FIRESTORE.PERMISSION_DENIED,
14
+ 'firestore/not-found': ERROR_MESSAGES.FIRESTORE.NOT_FOUND,
15
+ 'firestore/unavailable': ERROR_MESSAGES.FIRESTORE.UNAVAILABLE,
16
+ };
17
+
18
+ return firestoreMessages[code] || ERROR_MESSAGES.FIRESTORE.GENERIC_ERROR;
19
+ }
20
+
21
+ /**
22
+ * Create a failure result from error code
23
+ */
24
+ failureFrom(code: string, message?: string): Result {
25
+ return {
26
+ success: false,
27
+ error: {
28
+ code,
29
+ message: message || ERROR_MESSAGES.GENERAL.UNKNOWN,
30
+ },
31
+ };
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Default error handler instance
37
+ * Can be used across the application
38
+ */
39
+ export const defaultErrorHandler = new ErrorHandler();