@umituz/react-native-firebase 2.6.2 → 2.6.4

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 (101) hide show
  1. package/package.json +1 -1
  2. package/src/application/auth/index.ts +2 -34
  3. package/src/application/auth/use-cases/index.ts +1 -21
  4. package/src/domains/account-deletion/domain/index.ts +1 -8
  5. package/src/domains/account-deletion/index.ts +0 -42
  6. package/src/domains/account-deletion/infrastructure/services/AccountDeletionExecutor.ts +79 -0
  7. package/src/domains/account-deletion/infrastructure/services/AccountDeletionTypes.ts +0 -1
  8. package/src/domains/account-deletion/infrastructure/services/account-deletion.service.ts +2 -14
  9. package/src/domains/auth/index.ts +3 -12
  10. package/src/domains/auth/infrastructure.ts +11 -0
  11. package/src/domains/firestore/domain/entities/Collection.ts +0 -2
  12. package/src/domains/firestore/domain/index.ts +8 -12
  13. package/src/domains/firestore/domain/value-objects/{QueryOptions.ts.bak → QueryOptions.ts} +20 -68
  14. package/src/domains/firestore/domain/value-objects/QueryOptionsFactory.ts +95 -0
  15. package/src/domains/firestore/domain/value-objects/QueryOptionsHelpers.ts +110 -0
  16. package/src/domains/firestore/domain/value-objects/WhereClause.ts +115 -0
  17. package/src/domains/firestore/domain/value-objects/WhereClauseFactory.ts +101 -0
  18. package/src/domains/firestore/domain/value-objects/WhereClauseHelpers.ts +123 -0
  19. package/src/domains/firestore/domain/value-objects/WhereClauseValidation.ts +83 -0
  20. package/src/domains/firestore/presentation/hooks/useFirestoreMutation.ts +1 -1
  21. package/src/domains/firestore/presentation/hooks/useFirestoreQuery.ts +1 -1
  22. package/src/shared/infrastructure/config/base/ServiceClientSingleton.ts +29 -0
  23. package/src/application/auth/ports/AuthPort.ts.bak +0 -164
  24. package/src/application/auth/ports/AuthPort_part_aa +0 -150
  25. package/src/application/auth/ports/AuthPort_part_ab +0 -14
  26. package/src/application/auth/use-cases/SignInUseCase.ts.bak +0 -253
  27. package/src/application/auth/use-cases/SignInUseCaseHelpers.ts +0 -0
  28. package/src/application/auth/use-cases/SignInUseCaseMain.ts +0 -0
  29. package/src/application/auth/use-cases/SignInUseCase_part_aa +0 -150
  30. package/src/application/auth/use-cases/SignInUseCase_part_ab +0 -103
  31. package/src/application/auth/use-cases/SignOutUseCase.ts.bak +0 -288
  32. package/src/application/auth/use-cases/SignOutUseCaseCleanup.ts +0 -0
  33. package/src/application/auth/use-cases/SignOutUseCaseMain.ts +0 -0
  34. package/src/application/auth/use-cases/SignOutUseCase_part_aa +0 -150
  35. package/src/application/auth/use-cases/SignOutUseCase_part_ab +0 -138
  36. package/src/domains/account-deletion/domain/services/UserValidationHelpers.ts.bak +0 -181
  37. package/src/domains/account-deletion/domain/services/UserValidationHelpers_part_aa +0 -150
  38. package/src/domains/account-deletion/domain/services/UserValidationHelpers_part_ab +0 -31
  39. package/src/domains/account-deletion/domain/services/UserValidationService.ts.bak +0 -286
  40. package/src/domains/account-deletion/domain/services/UserValidationService_part_aa +0 -150
  41. package/src/domains/account-deletion/domain/services/UserValidationService_part_ab +0 -136
  42. package/src/domains/account-deletion/infrastructure/services/AccountDeletionExecutor.ts.bak +0 -230
  43. package/src/domains/account-deletion/infrastructure/services/AccountDeletionExecutor_part_aa +0 -150
  44. package/src/domains/account-deletion/infrastructure/services/AccountDeletionExecutor_part_ab +0 -80
  45. package/src/domains/account-deletion/infrastructure/services/AccountDeletionReauthHandler.ts.bak +0 -174
  46. package/src/domains/account-deletion/infrastructure/services/AccountDeletionReauthHandler_part_aa +0 -150
  47. package/src/domains/account-deletion/infrastructure/services/AccountDeletionReauthHandler_part_ab +0 -24
  48. package/src/domains/account-deletion/infrastructure/services/AccountDeletionRepository.ts.bak +0 -266
  49. package/src/domains/account-deletion/infrastructure/services/AccountDeletionRepository_part_aa +0 -150
  50. package/src/domains/account-deletion/infrastructure/services/AccountDeletionRepository_part_ab +0 -116
  51. package/src/domains/account-deletion/infrastructure/services/reauthentication.service.ts.bak +0 -160
  52. package/src/domains/account-deletion/infrastructure/services/reauthentication.service_part_aa +0 -150
  53. package/src/domains/account-deletion/infrastructure/services/reauthentication.service_part_ab +0 -10
  54. package/src/domains/auth/infrastructure.ts.bak +0 -156
  55. package/src/domains/auth/infrastructure_part_aa +0 -150
  56. package/src/domains/auth/infrastructure_part_ab +0 -6
  57. package/src/domains/auth/presentation/hooks/GoogleOAuthHelpers.ts +0 -0
  58. package/src/domains/auth/presentation/hooks/GoogleOAuthHookService.ts.bak +0 -247
  59. package/src/domains/auth/presentation/hooks/GoogleOAuthHookService_part_aa +0 -150
  60. package/src/domains/auth/presentation/hooks/GoogleOAuthHookService_part_ab +0 -97
  61. package/src/domains/auth/presentation/hooks/GoogleOAuthService.ts +0 -0
  62. package/src/domains/firestore/domain/entities/Collection.ts.bak +0 -288
  63. package/src/domains/firestore/domain/entities/Collection_part_aa +0 -150
  64. package/src/domains/firestore/domain/entities/Collection_part_ab +0 -138
  65. package/src/domains/firestore/domain/entities/Document.ts.bak +0 -233
  66. package/src/domains/firestore/domain/entities/DocumentHelpers.ts +0 -0
  67. package/src/domains/firestore/domain/entities/DocumentMain.ts +0 -0
  68. package/src/domains/firestore/domain/entities/Document_part_aa +0 -150
  69. package/src/domains/firestore/domain/entities/Document_part_ab +0 -83
  70. package/src/domains/firestore/domain/services/QueryService.ts.bak +0 -182
  71. package/src/domains/firestore/domain/services/QueryServiceAnalysis.ts.bak +0 -169
  72. package/src/domains/firestore/domain/services/QueryServiceAnalysis_part_aa +0 -150
  73. package/src/domains/firestore/domain/services/QueryServiceAnalysis_part_ab +0 -19
  74. package/src/domains/firestore/domain/services/QueryServiceHelpers.ts.bak +0 -151
  75. package/src/domains/firestore/domain/services/QueryServiceHelpers_part_aa +0 -150
  76. package/src/domains/firestore/domain/services/QueryServiceHelpers_part_ab +0 -1
  77. package/src/domains/firestore/domain/services/QueryService_part_aa +0 -150
  78. package/src/domains/firestore/domain/services/QueryService_part_ab +0 -32
  79. package/src/domains/firestore/domain/value-objects/QueryOptionsSerialization.ts.bak +0 -207
  80. package/src/domains/firestore/domain/value-objects/QueryOptionsSerialization_part_aa +0 -150
  81. package/src/domains/firestore/domain/value-objects/QueryOptionsSerialization_part_ab +0 -57
  82. package/src/domains/firestore/domain/value-objects/QueryOptionsValidation.ts.bak +0 -182
  83. package/src/domains/firestore/domain/value-objects/QueryOptionsValidation_part_aa +0 -150
  84. package/src/domains/firestore/domain/value-objects/QueryOptionsValidation_part_ab +0 -32
  85. package/src/domains/firestore/domain/value-objects/QueryOptions_part_aa +0 -150
  86. package/src/domains/firestore/domain/value-objects/QueryOptions_part_ab +0 -41
  87. package/src/domains/firestore/domain/value-objects/WhereClause.ts.bak +0 -299
  88. package/src/domains/firestore/domain/value-objects/WhereClauseFactory.ts.bak +0 -207
  89. package/src/domains/firestore/domain/value-objects/WhereClauseFactory_part_aa +0 -150
  90. package/src/domains/firestore/domain/value-objects/WhereClauseFactory_part_ab +0 -57
  91. package/src/domains/firestore/domain/value-objects/WhereClause_part_aa +0 -150
  92. package/src/domains/firestore/domain/value-objects/WhereClause_part_ab +0 -149
  93. package/src/shared/infrastructure/base/ErrorHandler.ts.bak +0 -189
  94. package/src/shared/infrastructure/base/ErrorHandler_part_aa +0 -150
  95. package/src/shared/infrastructure/base/ErrorHandler_part_ab +0 -39
  96. package/src/shared/infrastructure/base/ServiceBase.ts.bak +0 -220
  97. package/src/shared/infrastructure/base/ServiceBase_part_aa +0 -150
  98. package/src/shared/infrastructure/base/ServiceBase_part_ab +0 -70
  99. package/src/shared/infrastructure/config/base/ServiceClientSingleton.ts.bak +0 -155
  100. package/src/shared/infrastructure/config/base/ServiceClientSingleton_part_aa +0 -150
  101. package/src/shared/infrastructure/config/base/ServiceClientSingleton_part_ab +0 -5
@@ -1,169 +0,0 @@
1
- /**
2
- * Query Service Analysis
3
- * Single Responsibility: Analyze query complexity and metadata
4
- *
5
- * Provides analysis functionality for query options.
6
- * Extracts field information and calculates complexity scores.
7
- *
8
- * Max lines: 150 (enforced for maintainability)
9
- */
10
-
11
- import { QueryOptions } from '../value-objects/QueryOptions';
12
-
13
- /**
14
- * Extract field names from query options
15
- */
16
- export function extractFields(options: QueryOptions): string[] {
17
- const fields = new Set<string>();
18
-
19
- for (const clause of options.whereClauses) {
20
- fields.add(clause.field);
21
- }
22
-
23
- for (const sort of options.sortOptions) {
24
- fields.add(sort.field);
25
- }
26
-
27
- if (options.dateRange) {
28
- fields.add(options.dateRange.field);
29
- }
30
-
31
- return Array.from(fields);
32
- }
33
-
34
- /**
35
- * Check if query uses array operators
36
- */
37
- export function hasArrayOperators(options: QueryOptions): boolean {
38
- return options.whereClauses.some(clause => clause.isArrayOperator());
39
- }
40
-
41
- /**
42
- * Check if query uses membership operators
43
- */
44
- export function hasMembershipOperators(options: QueryOptions): boolean {
45
- return options.whereClauses.some(clause => clause.isMembership());
46
- }
47
-
48
- /**
49
- * Get query complexity score
50
- * Higher score = more complex query
51
- */
52
- export function getComplexityScore(options: QueryOptions): number {
53
- let score = 0;
54
-
55
- score += options.whereClauses.length * 1;
56
- score += options.sortOptions.length * 2;
57
- score += options.dateRange ? 3 : 0;
58
- score += options.pagination?.limit ? 1 : 0;
59
-
60
- // Array and membership operators add complexity
61
- if (hasArrayOperators(options)) score += 5;
62
- if (hasMembershipOperators(options)) score += 5;
63
-
64
- return score;
65
- }
66
-
67
- /**
68
- * Check if query is too complex
69
- */
70
- export function isTooComplex(options: QueryOptions, maxScore: number = 20): boolean {
71
- return getComplexityScore(options) > maxScore;
72
- }
73
-
74
- /**
75
- * Get query statistics
76
- */
77
- export function getQueryStats(options: QueryOptions): {
78
- readonly whereClauseCount: number;
79
- readonly sortOptionCount: number;
80
- readonly hasDateRange: boolean;
81
- readonly hasPagination: boolean;
82
- readonly complexityScore: number;
83
- readonly fieldCount: number;
84
- } {
85
- return {
86
- whereClauseCount: options.whereClauses.length,
87
- sortOptionCount: options.sortOptions.length,
88
- hasDateRange: options.hasDateRange(),
89
- hasPagination: options.hasPagination(),
90
- complexityScore: getComplexityScore(options),
91
- fieldCount: extractFields(options).length,
92
- };
93
- }
94
-
95
- /**
96
- * Check if query is simple (low complexity)
97
- */
98
- export function isSimpleQuery(options: QueryOptions, maxScore: number = 5): boolean {
99
- return getComplexityScore(options) <= maxScore;
100
- }
101
-
102
- /**
103
- * Check if query is moderate complexity
104
- */
105
- export function isModerateQuery(options: QueryOptions): boolean {
106
- const score = getComplexityScore(options);
107
- return score > 5 && score <= 15;
108
- }
109
-
110
- /**
111
- * Check if query is high complexity
112
- */
113
- export function isComplexQuery(options: QueryOptions): boolean {
114
- return getComplexityScore(options) > 15;
115
- }
116
-
117
- /**
118
- * Get query complexity level
119
- */
120
- export function getComplexityLevel(options: QueryOptions): 'simple' | 'moderate' | 'complex' {
121
- if (isSimpleQuery(options)) {
122
- return 'simple';
123
- }
124
-
125
- if (isModerateQuery(options)) {
126
- return 'moderate';
127
- }
128
-
129
- return 'complex';
130
- }
131
-
132
- /**
133
- * Compare two queries by complexity
134
- */
135
- export function compareComplexity(options1: QueryOptions, options2: QueryOptions): number {
136
- const score1 = getComplexityScore(options1);
137
- const score2 = getComplexityScore(options2);
138
-
139
- return score1 - score2;
140
- }
141
-
142
- /**
143
- * Get query performance hints
144
- */
145
- export function getPerformanceHints(options: QueryOptions): string[] {
146
- const hints: string[] = [];
147
-
148
- if (hasArrayOperators(options)) {
149
- hints.push('Array operators can impact performance');
150
- }
151
-
152
- if (hasMembershipOperators(options)) {
153
- hints.push('Membership operators (in, not-in) are limited to 10 values');
154
- }
155
-
156
- if (options.whereClauses.length > 5) {
157
- hints.push('Consider reducing number of where clauses');
158
- }
159
-
160
- if (!options.pagination?.limit && options.sortOptions.length > 0) {
161
- hints.push('Add limit to prevent full collection scans');
162
- }
163
-
164
- if (options.dateRange && !options.sortOptions.some(s => s.field === options.dateRange?.field)) {
165
- hints.push('Add sort on date range field for better performance');
166
- }
167
-
168
- return hints;
169
- }
@@ -1,150 +0,0 @@
1
- /**
2
- * Query Service Analysis
3
- * Single Responsibility: Analyze query complexity and metadata
4
- *
5
- * Provides analysis functionality for query options.
6
- * Extracts field information and calculates complexity scores.
7
- *
8
- * Max lines: 150 (enforced for maintainability)
9
- */
10
-
11
- import { QueryOptions } from '../value-objects/QueryOptions';
12
-
13
- /**
14
- * Extract field names from query options
15
- */
16
- export function extractFields(options: QueryOptions): string[] {
17
- const fields = new Set<string>();
18
-
19
- for (const clause of options.whereClauses) {
20
- fields.add(clause.field);
21
- }
22
-
23
- for (const sort of options.sortOptions) {
24
- fields.add(sort.field);
25
- }
26
-
27
- if (options.dateRange) {
28
- fields.add(options.dateRange.field);
29
- }
30
-
31
- return Array.from(fields);
32
- }
33
-
34
- /**
35
- * Check if query uses array operators
36
- */
37
- export function hasArrayOperators(options: QueryOptions): boolean {
38
- return options.whereClauses.some(clause => clause.isArrayOperator());
39
- }
40
-
41
- /**
42
- * Check if query uses membership operators
43
- */
44
- export function hasMembershipOperators(options: QueryOptions): boolean {
45
- return options.whereClauses.some(clause => clause.isMembership());
46
- }
47
-
48
- /**
49
- * Get query complexity score
50
- * Higher score = more complex query
51
- */
52
- export function getComplexityScore(options: QueryOptions): number {
53
- let score = 0;
54
-
55
- score += options.whereClauses.length * 1;
56
- score += options.sortOptions.length * 2;
57
- score += options.dateRange ? 3 : 0;
58
- score += options.pagination?.limit ? 1 : 0;
59
-
60
- // Array and membership operators add complexity
61
- if (hasArrayOperators(options)) score += 5;
62
- if (hasMembershipOperators(options)) score += 5;
63
-
64
- return score;
65
- }
66
-
67
- /**
68
- * Check if query is too complex
69
- */
70
- export function isTooComplex(options: QueryOptions, maxScore: number = 20): boolean {
71
- return getComplexityScore(options) > maxScore;
72
- }
73
-
74
- /**
75
- * Get query statistics
76
- */
77
- export function getQueryStats(options: QueryOptions): {
78
- readonly whereClauseCount: number;
79
- readonly sortOptionCount: number;
80
- readonly hasDateRange: boolean;
81
- readonly hasPagination: boolean;
82
- readonly complexityScore: number;
83
- readonly fieldCount: number;
84
- } {
85
- return {
86
- whereClauseCount: options.whereClauses.length,
87
- sortOptionCount: options.sortOptions.length,
88
- hasDateRange: options.hasDateRange(),
89
- hasPagination: options.hasPagination(),
90
- complexityScore: getComplexityScore(options),
91
- fieldCount: extractFields(options).length,
92
- };
93
- }
94
-
95
- /**
96
- * Check if query is simple (low complexity)
97
- */
98
- export function isSimpleQuery(options: QueryOptions, maxScore: number = 5): boolean {
99
- return getComplexityScore(options) <= maxScore;
100
- }
101
-
102
- /**
103
- * Check if query is moderate complexity
104
- */
105
- export function isModerateQuery(options: QueryOptions): boolean {
106
- const score = getComplexityScore(options);
107
- return score > 5 && score <= 15;
108
- }
109
-
110
- /**
111
- * Check if query is high complexity
112
- */
113
- export function isComplexQuery(options: QueryOptions): boolean {
114
- return getComplexityScore(options) > 15;
115
- }
116
-
117
- /**
118
- * Get query complexity level
119
- */
120
- export function getComplexityLevel(options: QueryOptions): 'simple' | 'moderate' | 'complex' {
121
- if (isSimpleQuery(options)) {
122
- return 'simple';
123
- }
124
-
125
- if (isModerateQuery(options)) {
126
- return 'moderate';
127
- }
128
-
129
- return 'complex';
130
- }
131
-
132
- /**
133
- * Compare two queries by complexity
134
- */
135
- export function compareComplexity(options1: QueryOptions, options2: QueryOptions): number {
136
- const score1 = getComplexityScore(options1);
137
- const score2 = getComplexityScore(options2);
138
-
139
- return score1 - score2;
140
- }
141
-
142
- /**
143
- * Get query performance hints
144
- */
145
- export function getPerformanceHints(options: QueryOptions): string[] {
146
- const hints: string[] = [];
147
-
148
- if (hasArrayOperators(options)) {
149
- hints.push('Array operators can impact performance');
150
- }
@@ -1,19 +0,0 @@
1
-
2
- if (hasMembershipOperators(options)) {
3
- hints.push('Membership operators (in, not-in) are limited to 10 values');
4
- }
5
-
6
- if (options.whereClauses.length > 5) {
7
- hints.push('Consider reducing number of where clauses');
8
- }
9
-
10
- if (!options.pagination?.limit && options.sortOptions.length > 0) {
11
- hints.push('Add limit to prevent full collection scans');
12
- }
13
-
14
- if (options.dateRange && !options.sortOptions.some(s => s.field === options.dateRange?.field)) {
15
- hints.push('Add sort on date range field for better performance');
16
- }
17
-
18
- return hints;
19
- }
@@ -1,151 +0,0 @@
1
- /**
2
- * Query Service Helpers
3
- * Single Responsibility: Provide helper methods for query operations
4
- *
5
- * Helper methods for query options manipulation and creation.
6
- * Separated from main QueryService for better maintainability.
7
- *
8
- * Max lines: 150 (enforced for maintainability)
9
- */
10
-
11
- import type { Query } from 'firebase/firestore';
12
- import { QueryOptions, createQueryOptions } from '../value-objects/QueryOptions';
13
- import { WhereClause } from '../value-objects/WhereClause';
14
- import type { Collection } from '../entities/Collection';
15
- import type { QueryBuilderResult } from './QueryService';
16
-
17
- /**
18
- * Create query options from filters object
19
- */
20
- export function createOptionsFromFilters(filters: Record<string, unknown>): QueryOptions {
21
- const whereClauses = Object.entries(filters).map(([field, value]) =>
22
- WhereClause.equals(field, value)
23
- );
24
-
25
- return createQueryOptions({ where: whereClauses });
26
- }
27
-
28
- /**
29
- * Merge multiple query options
30
- * Later options override earlier ones for conflicting settings
31
- */
32
- export function mergeOptions(...options: QueryOptions[]): QueryOptions {
33
- if (options.length === 0) {
34
- return createQueryOptions();
35
- }
36
-
37
- if (options.length === 1) {
38
- return options[0];
39
- }
40
-
41
- const merged = options.reduce((acc, opt) => {
42
- return QueryOptions.create({
43
- where: [...acc.whereClauses, ...opt.whereClauses] as WhereClause[],
44
- sort: opt.sortOptions.length > 0 ? [...opt.sortOptions] as any[] : [...acc.sortOptions] as any[],
45
- dateRange: opt.dateRange ?? acc.dateRange,
46
- pagination: opt.pagination ?? acc.pagination,
47
- });
48
- });
49
-
50
- return merged ?? createQueryOptions();
51
- }
52
-
53
- /**
54
- * Create paginated query options
55
- */
56
- export function createPaginatedOptions(limit: number, cursor?: number): QueryOptions {
57
- return createQueryOptions({
58
- pagination: { limit, cursor },
59
- });
60
- }
61
-
62
- /**
63
- * Create sorted query options
64
- */
65
- export function createSortedOptions(
66
- field: string,
67
- direction: 'asc' | 'desc' = 'asc'
68
- ): QueryOptions {
69
- return createQueryOptions({
70
- sort: [{ field, direction }],
71
- });
72
- }
73
-
74
- /**
75
- * Optimize query options
76
- * Removes redundant clauses and sorts
77
- */
78
- export function optimizeOptions(options: QueryOptions): QueryOptions {
79
- // Remove duplicate where clauses
80
- const uniqueWheres = options.whereClauses.filter((clause, index, self) =>
81
- index === self.findIndex(c => c.equals(clause))
82
- );
83
-
84
- // Remove duplicate sorts
85
- const uniqueSorts = options.sortOptions.filter((sort, index, self) =>
86
- index === self.findIndex(s => s.field === sort.field && s.direction === sort.direction)
87
- );
88
-
89
- return QueryOptions.create({
90
- where: uniqueWheres,
91
- sort: uniqueSorts,
92
- dateRange: options.dateRange,
93
- pagination: options.pagination,
94
- });
95
- }
96
-
97
- /**
98
- * Build query from collection entity
99
- */
100
- export function buildQueryFromCollection(
101
- collection: Collection,
102
- options: QueryOptions,
103
- queryService: any
104
- ): QueryBuilderResult {
105
- return queryService.buildQuery(collection.getPath(), options);
106
- }
107
-
108
- /**
109
- * Get query description for logging
110
- */
111
- export function describeQuery(options: QueryOptions): string {
112
- const parts: string[] = [];
113
-
114
- if (options.hasWhereClauses()) {
115
- parts.push(`where: ${options.whereClauses.length} clause(s)`);
116
- }
117
-
118
- if (options.hasSort()) {
119
- parts.push(`sort: ${options.sortOptions.length} field(s)`);
120
- }
121
-
122
- if (options.hasDateRange()) {
123
- parts.push('date range: yes');
124
- }
125
-
126
- if (options.hasPagination()) {
127
- parts.push(`limit: ${options.pagination?.limit || 'none'}`);
128
- }
129
-
130
- return parts.length > 0 ? parts.join(', ') : 'no filters';
131
- }
132
-
133
- /**
134
- * Clone query options with modifications
135
- */
136
- export function cloneOptions(
137
- base: QueryOptions,
138
- modifications: {
139
- where?: WhereClause[];
140
- sort?: Array<{ field: string; direction: 'asc' | 'desc' }>;
141
- dateRange?: { field: string; startDate?: Date; endDate?: Date };
142
- pagination?: { limit?: number; cursor?: number };
143
- }
144
- ): QueryOptions {
145
- return QueryOptions.create({
146
- where: modifications.where ?? [...base.whereClauses] as WhereClause[],
147
- sort: modifications.sort ?? [...base.sortOptions] as any[],
148
- dateRange: modifications.dateRange ?? base.dateRange ?? undefined,
149
- pagination: modifications.pagination ?? base.pagination ?? undefined,
150
- });
151
- }
@@ -1,150 +0,0 @@
1
- /**
2
- * Query Service Helpers
3
- * Single Responsibility: Provide helper methods for query operations
4
- *
5
- * Helper methods for query options manipulation and creation.
6
- * Separated from main QueryService for better maintainability.
7
- *
8
- * Max lines: 150 (enforced for maintainability)
9
- */
10
-
11
- import type { Query } from 'firebase/firestore';
12
- import { QueryOptions, createQueryOptions } from '../value-objects/QueryOptions';
13
- import { WhereClause } from '../value-objects/WhereClause';
14
- import type { Collection } from '../entities/Collection';
15
- import type { QueryBuilderResult } from './QueryService';
16
-
17
- /**
18
- * Create query options from filters object
19
- */
20
- export function createOptionsFromFilters(filters: Record<string, unknown>): QueryOptions {
21
- const whereClauses = Object.entries(filters).map(([field, value]) =>
22
- WhereClause.equals(field, value)
23
- );
24
-
25
- return createQueryOptions({ where: whereClauses });
26
- }
27
-
28
- /**
29
- * Merge multiple query options
30
- * Later options override earlier ones for conflicting settings
31
- */
32
- export function mergeOptions(...options: QueryOptions[]): QueryOptions {
33
- if (options.length === 0) {
34
- return createQueryOptions();
35
- }
36
-
37
- if (options.length === 1) {
38
- return options[0];
39
- }
40
-
41
- const merged = options.reduce((acc, opt) => {
42
- return QueryOptions.create({
43
- where: [...acc.whereClauses, ...opt.whereClauses] as WhereClause[],
44
- sort: opt.sortOptions.length > 0 ? [...opt.sortOptions] as any[] : [...acc.sortOptions] as any[],
45
- dateRange: opt.dateRange ?? acc.dateRange,
46
- pagination: opt.pagination ?? acc.pagination,
47
- });
48
- });
49
-
50
- return merged ?? createQueryOptions();
51
- }
52
-
53
- /**
54
- * Create paginated query options
55
- */
56
- export function createPaginatedOptions(limit: number, cursor?: number): QueryOptions {
57
- return createQueryOptions({
58
- pagination: { limit, cursor },
59
- });
60
- }
61
-
62
- /**
63
- * Create sorted query options
64
- */
65
- export function createSortedOptions(
66
- field: string,
67
- direction: 'asc' | 'desc' = 'asc'
68
- ): QueryOptions {
69
- return createQueryOptions({
70
- sort: [{ field, direction }],
71
- });
72
- }
73
-
74
- /**
75
- * Optimize query options
76
- * Removes redundant clauses and sorts
77
- */
78
- export function optimizeOptions(options: QueryOptions): QueryOptions {
79
- // Remove duplicate where clauses
80
- const uniqueWheres = options.whereClauses.filter((clause, index, self) =>
81
- index === self.findIndex(c => c.equals(clause))
82
- );
83
-
84
- // Remove duplicate sorts
85
- const uniqueSorts = options.sortOptions.filter((sort, index, self) =>
86
- index === self.findIndex(s => s.field === sort.field && s.direction === sort.direction)
87
- );
88
-
89
- return QueryOptions.create({
90
- where: uniqueWheres,
91
- sort: uniqueSorts,
92
- dateRange: options.dateRange,
93
- pagination: options.pagination,
94
- });
95
- }
96
-
97
- /**
98
- * Build query from collection entity
99
- */
100
- export function buildQueryFromCollection(
101
- collection: Collection,
102
- options: QueryOptions,
103
- queryService: any
104
- ): QueryBuilderResult {
105
- return queryService.buildQuery(collection.getPath(), options);
106
- }
107
-
108
- /**
109
- * Get query description for logging
110
- */
111
- export function describeQuery(options: QueryOptions): string {
112
- const parts: string[] = [];
113
-
114
- if (options.hasWhereClauses()) {
115
- parts.push(`where: ${options.whereClauses.length} clause(s)`);
116
- }
117
-
118
- if (options.hasSort()) {
119
- parts.push(`sort: ${options.sortOptions.length} field(s)`);
120
- }
121
-
122
- if (options.hasDateRange()) {
123
- parts.push('date range: yes');
124
- }
125
-
126
- if (options.hasPagination()) {
127
- parts.push(`limit: ${options.pagination?.limit || 'none'}`);
128
- }
129
-
130
- return parts.length > 0 ? parts.join(', ') : 'no filters';
131
- }
132
-
133
- /**
134
- * Clone query options with modifications
135
- */
136
- export function cloneOptions(
137
- base: QueryOptions,
138
- modifications: {
139
- where?: WhereClause[];
140
- sort?: Array<{ field: string; direction: 'asc' | 'desc' }>;
141
- dateRange?: { field: string; startDate?: Date; endDate?: Date };
142
- pagination?: { limit?: number; cursor?: number };
143
- }
144
- ): QueryOptions {
145
- return QueryOptions.create({
146
- where: modifications.where ?? [...base.whereClauses] as WhereClause[],
147
- sort: modifications.sort ?? [...base.sortOptions] as any[],
148
- dateRange: modifications.dateRange ?? base.dateRange ?? undefined,
149
- pagination: modifications.pagination ?? base.pagination ?? undefined,
150
- });