@umituz/react-native-firebase 3.0.3 → 3.0.6
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 +7 -1
- package/src/domains/account-deletion/index.ts +15 -10
- package/src/domains/account-deletion/infrastructure/services/account-deletion.service.ts +235 -26
- package/src/domains/account-deletion/infrastructure/services/reauthentication.service.ts +160 -0
- package/src/domains/auth/domain/value-objects/FirebaseAuthConfig.ts +1 -1
- package/src/domains/auth/index.ts +156 -6
- package/src/domains/auth/infrastructure/config/FirebaseAuthClient.ts +60 -48
- package/src/domains/auth/infrastructure/config/initializers/FirebaseAuthInitializer.ts +41 -5
- package/src/domains/auth/infrastructure/stores/auth.store.ts +4 -1
- package/src/domains/auth/presentation/hooks/useAnonymousAuth.ts +3 -1
- package/src/domains/auth/presentation/hooks/useGoogleOAuth.ts +115 -20
- package/src/domains/auth/presentation/hooks/utils/auth-state-change.handler.ts +5 -11
- package/src/domains/firestore/domain/constants/QuotaLimits.ts +101 -0
- package/src/domains/firestore/domain/entities/QuotaMetrics.ts +26 -0
- package/src/domains/firestore/domain/entities/RequestLog.ts +28 -0
- package/src/domains/firestore/domain/services/QuotaCalculator.ts +71 -0
- package/src/domains/firestore/index.ts +85 -31
- package/src/domains/firestore/infrastructure/config/FirestoreClient.ts +82 -45
- package/src/domains/firestore/infrastructure/config/initializers/FirebaseFirestoreInitializer.ts +249 -4
- package/src/domains/firestore/infrastructure/middleware/QueryDeduplicationMiddleware.ts +306 -0
- package/src/domains/firestore/infrastructure/middleware/QuotaTrackingMiddleware.ts +92 -0
- package/src/domains/firestore/infrastructure/repositories/BasePaginatedRepository.ts +9 -1
- package/src/domains/firestore/infrastructure/repositories/BaseQueryRepository.ts +34 -8
- package/src/domains/firestore/infrastructure/repositories/BaseRepository.ts +48 -9
- package/src/domains/firestore/infrastructure/services/RequestLoggerService.ts +168 -0
- package/src/domains/firestore/presentation/hooks/index.ts +10 -0
- package/src/domains/firestore/presentation/hooks/useFirestoreMutation.ts +1 -1
- package/src/domains/firestore/presentation/hooks/useFirestoreQuery.ts +1 -1
- package/src/domains/firestore/presentation/hooks/useFirestoreSnapshot.ts +2 -1
- package/src/domains/firestore/presentation/hooks/useSmartFirestoreSnapshot.ts +362 -0
- package/src/domains/firestore/presentation/query-keys/createFirestoreKeys.ts +32 -0
- package/src/domains/firestore/presentation/query-keys/index.ts +1 -0
- package/src/domains/firestore/utils/deduplication/pending-query-manager.util.ts +126 -0
- package/src/domains/firestore/utils/deduplication/query-key-generator.util.ts +41 -0
- package/src/domains/firestore/utils/deduplication/timer-manager.util.ts +83 -0
- package/src/domains/firestore/utils/pagination.helper.ts +5 -2
- package/src/domains/firestore/utils/transaction/transaction.util.ts +8 -2
- package/src/index.ts +324 -32
- package/src/shared/domain/utils/calculation.util.ts +305 -17
- package/src/shared/domain/utils/error-handlers/error-messages.ts +0 -15
- package/src/shared/domain/utils/index.ts +5 -0
- package/src/shared/infrastructure/config/base/ClientStateManager.ts +82 -0
- package/src/shared/infrastructure/config/base/ServiceClientSingleton.ts +136 -20
- package/src/shared/infrastructure/config/clients/FirebaseClientSingleton.ts +1 -1
- package/src/shared/infrastructure/config/initializers/FirebaseAppInitializer.ts +9 -0
- package/src/shared/infrastructure/config/services/FirebaseInitializationService.ts +1 -1
- package/src/shared/infrastructure/config/state/FirebaseClientState.ts +14 -36
- package/src/application/auth/index.ts +0 -10
- package/src/application/auth/use-cases/index.ts +0 -6
- package/src/domains/account-deletion/domain/index.ts +0 -8
- package/src/domains/account-deletion/infrastructure/services/AccountDeletionExecutor.ts +0 -79
- package/src/domains/account-deletion/infrastructure/services/AccountDeletionTypes.ts +0 -32
- package/src/domains/auth/domain.ts +0 -16
- package/src/domains/auth/infrastructure/config/index.ts +0 -2
- package/src/domains/auth/infrastructure/config/initializers/index.ts +0 -1
- package/src/domains/auth/infrastructure/services/index.ts +0 -16
- package/src/domains/auth/infrastructure/services/utils/index.ts +0 -1
- package/src/domains/auth/infrastructure/stores/index.ts +0 -1
- package/src/domains/auth/infrastructure/utils/index.ts +0 -1
- package/src/domains/auth/infrastructure.ts +0 -11
- package/src/domains/auth/presentation/hooks/useAppleAuth.ts +0 -82
- package/src/domains/auth/presentation.ts +0 -31
- package/src/domains/firestore/domain/entities/Collection.ts +0 -122
- package/src/domains/firestore/domain/entities/CollectionFactory.ts +0 -55
- package/src/domains/firestore/domain/entities/CollectionHelpers.ts +0 -143
- package/src/domains/firestore/domain/entities/CollectionUtils.ts +0 -72
- package/src/domains/firestore/domain/entities/CollectionValidation.ts +0 -138
- package/src/domains/firestore/domain/index.ts +0 -61
- package/src/domains/firestore/domain/value-objects/QueryOptions.ts +0 -143
- package/src/domains/firestore/domain/value-objects/QueryOptionsFactory.ts +0 -95
- package/src/domains/firestore/domain/value-objects/QueryOptionsHelpers.ts +0 -110
- package/src/domains/firestore/domain/value-objects/WhereClause.ts +0 -114
- package/src/domains/firestore/domain/value-objects/WhereClauseFactory.ts +0 -101
- package/src/domains/firestore/domain/value-objects/WhereClauseHelpers.ts +0 -123
- package/src/domains/firestore/domain/value-objects/WhereClauseValidation.ts +0 -83
- package/src/shared/infrastructure/base/ErrorHandler.ts +0 -81
- package/src/shared/infrastructure/base/ServiceBase.ts +0 -62
- package/src/shared/infrastructure/base/TypedGuard.ts +0 -131
- package/src/shared/infrastructure/base/index.ts +0 -34
- package/src/shared/types/firebase.types.ts +0 -274
|
@@ -1,42 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Firebase Client State Manager
|
|
3
|
+
* Manages the state of Firebase initialization
|
|
4
|
+
*
|
|
5
|
+
* Single Responsibility: Only manages initialization state
|
|
6
|
+
* Uses generic ClientStateManager for shared functionality
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { FirebaseApp } from '../initializers/FirebaseAppInitializer';
|
|
10
|
+
import { ClientStateManager } from '../base/ClientStateManager';
|
|
11
|
+
|
|
12
|
+
export class FirebaseClientState extends ClientStateManager<FirebaseApp> {
|
|
8
13
|
getApp(): FirebaseApp | null {
|
|
9
|
-
return this.
|
|
14
|
+
return this.getInstance();
|
|
10
15
|
}
|
|
11
16
|
|
|
12
17
|
setApp(app: FirebaseApp | null): void {
|
|
13
|
-
this.app
|
|
14
|
-
this.isInitializedFlag = app !== null;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
setInstance(app: FirebaseApp | null): void {
|
|
18
|
-
this.setApp(app);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
getInstance(): FirebaseApp | null {
|
|
22
|
-
return this.getApp();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
isInitialized(): boolean {
|
|
26
|
-
return this.isInitializedFlag;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
getInitializationError(): string | null {
|
|
30
|
-
return this.initializationError;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
setInitializationError(error: string | null): void {
|
|
34
|
-
this.initializationError = error;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
reset(): void {
|
|
38
|
-
this.app = null;
|
|
39
|
-
this.initializationError = null;
|
|
40
|
-
this.isInitializedFlag = false;
|
|
18
|
+
this.setInstance(app);
|
|
41
19
|
}
|
|
42
20
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auth Application Layer
|
|
3
|
-
* Domain-Driven Design (DDD) - Application Exports
|
|
4
|
-
*
|
|
5
|
-
* Application use cases and ports for authentication.
|
|
6
|
-
* Coordinates domain services and infrastructure.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// Export types when files are available
|
|
10
|
-
// TODO: Implement AuthPort and UseCases
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Account Deletion Executor
|
|
3
|
-
* Handles Firebase account deletion with reauthentication support
|
|
4
|
-
*
|
|
5
|
-
* Max lines: 150 (enforced for maintainability)
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { User } from 'firebase/auth';
|
|
9
|
-
import type { AccountDeletionOptions } from '../../application/ports/reauthentication.types';
|
|
10
|
-
import type { AccountDeletionResult } from './AccountDeletionTypes';
|
|
11
|
-
|
|
12
|
-
export class AccountDeletionExecutor {
|
|
13
|
-
private deletionInProgress = false;
|
|
14
|
-
|
|
15
|
-
async deleteCurrentUser(_options: AccountDeletionOptions): Promise<AccountDeletionResult> {
|
|
16
|
-
if (this.deletionInProgress) {
|
|
17
|
-
return {
|
|
18
|
-
success: false,
|
|
19
|
-
error: {
|
|
20
|
-
code: 'deletion-in-progress',
|
|
21
|
-
message: 'Account deletion is already in progress',
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
this.deletionInProgress = true;
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
// TODO: Implement actual deletion logic
|
|
30
|
-
return {
|
|
31
|
-
success: true,
|
|
32
|
-
};
|
|
33
|
-
} catch (error) {
|
|
34
|
-
return {
|
|
35
|
-
success: false,
|
|
36
|
-
error: {
|
|
37
|
-
code: 'deletion-failed',
|
|
38
|
-
message: error instanceof Error ? error.message : 'Unknown error',
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
} finally {
|
|
42
|
-
this.deletionInProgress = false;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async deleteUserAccount(user: User | null): Promise<AccountDeletionResult> {
|
|
47
|
-
if (!user) {
|
|
48
|
-
return {
|
|
49
|
-
success: false,
|
|
50
|
-
error: {
|
|
51
|
-
code: 'no-user',
|
|
52
|
-
message: 'No user provided',
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
try {
|
|
58
|
-
await user.delete();
|
|
59
|
-
return {
|
|
60
|
-
success: true,
|
|
61
|
-
};
|
|
62
|
-
} catch (error) {
|
|
63
|
-
return {
|
|
64
|
-
success: false,
|
|
65
|
-
error: {
|
|
66
|
-
code: 'deletion-failed',
|
|
67
|
-
message: error instanceof Error ? error.message : 'Unknown error',
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
isDeletionInProgress(): boolean {
|
|
74
|
-
return this.deletionInProgress;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export const accountDeletionExecutor = new AccountDeletionExecutor();
|
|
79
|
-
export const createAccountDeletionExecutor = () => new AccountDeletionExecutor();
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Account Deletion Types
|
|
3
|
-
* Single Responsibility: Define account deletion types
|
|
4
|
-
*
|
|
5
|
-
* Max lines: 150 (enforced for maintainability)
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { Result } from '../../../../shared/domain/utils';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Account deletion result
|
|
12
|
-
*/
|
|
13
|
-
export interface AccountDeletionResult extends Result<void> {
|
|
14
|
-
readonly requiresReauth?: boolean;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Reauthentication context
|
|
19
|
-
*/
|
|
20
|
-
export interface ReauthenticationContext {
|
|
21
|
-
readonly user: import('firebase/auth').User;
|
|
22
|
-
readonly options: import('../../application/ports/reauthentication.types').AccountDeletionOptions;
|
|
23
|
-
readonly originalUserId?: string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Reauthentication result
|
|
28
|
-
*/
|
|
29
|
-
export interface ReauthenticationResult {
|
|
30
|
-
readonly success: boolean;
|
|
31
|
-
readonly error?: { code?: string; message?: string };
|
|
32
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Firebase Auth Domain Layer
|
|
3
|
-
* Domain-Driven Design (DDD) - Domain Exports
|
|
4
|
-
*
|
|
5
|
-
* Pure domain logic without infrastructure concerns.
|
|
6
|
-
* Exports domain entities, value objects, and domain services.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// Domain Value Objects
|
|
10
|
-
export type { FirebaseAuthConfig } from './domain/value-objects/FirebaseAuthConfig';
|
|
11
|
-
|
|
12
|
-
// Domain Entities
|
|
13
|
-
export {
|
|
14
|
-
isAnonymousUser,
|
|
15
|
-
} from './domain/entities/AnonymousUser';
|
|
16
|
-
export type { AnonymousUser } from './domain/entities/AnonymousUser';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './FirebaseAuthInitializer';
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export * from './anonymous-auth.service';
|
|
2
|
-
export * from './apple-auth.service';
|
|
3
|
-
export * from './apple-auth.types';
|
|
4
|
-
export * from './auth-listener.service';
|
|
5
|
-
export * from './auth-utils.service';
|
|
6
|
-
export * from './email-auth.service';
|
|
7
|
-
export * from './google-auth.service';
|
|
8
|
-
export * from './google-auth.types';
|
|
9
|
-
export * from './google-oauth.service';
|
|
10
|
-
export * from './password.service';
|
|
11
|
-
export * from './user-document-builder.util';
|
|
12
|
-
export * from './user-document.service';
|
|
13
|
-
export * from './user-document.types';
|
|
14
|
-
export * from './crypto.util';
|
|
15
|
-
export * from './firestore-utils.service';
|
|
16
|
-
export * from './utils';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './auth-result-converter.util';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './auth.store';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './auth-guard.util';
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auth Infrastructure Layer
|
|
3
|
-
* Domain-Driven Design (DDD) - Infrastructure Exports
|
|
4
|
-
*
|
|
5
|
-
* Infrastructure implementations for authentication.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export * from './infrastructure/config';
|
|
9
|
-
export * from './infrastructure/services';
|
|
10
|
-
export * from './infrastructure/stores';
|
|
11
|
-
export * from './infrastructure/utils';
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* useAppleAuth Hook
|
|
3
|
-
* Handles Apple Sign-In using Firebase auth
|
|
4
|
-
*
|
|
5
|
-
* Max lines: 150 (enforced for maintainability)
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { useState, useCallback } from 'react';
|
|
9
|
-
import { Platform } from 'react-native';
|
|
10
|
-
|
|
11
|
-
export interface UseAppleAuthResult {
|
|
12
|
-
signInWithApple: () => Promise<AppleAuthSignInResult>;
|
|
13
|
-
appleLoading: boolean;
|
|
14
|
-
appleAvailable: boolean;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface AppleAuthSignInResult {
|
|
18
|
-
success: boolean;
|
|
19
|
-
isNewUser?: boolean;
|
|
20
|
-
error?: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Check if Apple Sign-In is available
|
|
25
|
-
*/
|
|
26
|
-
function isAppleAuthAvailable(): boolean {
|
|
27
|
-
if (Platform.OS !== 'ios') {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Check if expo-apple-authentication is available
|
|
32
|
-
try {
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
34
|
-
const AppleAuthentication = require('expo-apple-authentication');
|
|
35
|
-
return !!AppleAuthentication;
|
|
36
|
-
} catch {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Hook for Apple authentication
|
|
43
|
-
*/
|
|
44
|
-
export function useAppleAuth(): UseAppleAuthResult {
|
|
45
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
46
|
-
|
|
47
|
-
const appleAvailable = isAppleAuthAvailable();
|
|
48
|
-
|
|
49
|
-
const signInWithApple = useCallback(async (): Promise<AppleAuthSignInResult> => {
|
|
50
|
-
if (!appleAvailable) {
|
|
51
|
-
return {
|
|
52
|
-
success: false,
|
|
53
|
-
error: 'Apple Sign-In is not available',
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
setIsLoading(true);
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
// TODO: Implement actual Apple Sign-In logic
|
|
61
|
-
// This requires expo-apple-authentication
|
|
62
|
-
return {
|
|
63
|
-
success: true,
|
|
64
|
-
isNewUser: false,
|
|
65
|
-
};
|
|
66
|
-
} catch (error) {
|
|
67
|
-
const errorMessage = error instanceof Error ? error.message : 'Apple Sign-In failed';
|
|
68
|
-
return {
|
|
69
|
-
success: false,
|
|
70
|
-
error: errorMessage,
|
|
71
|
-
};
|
|
72
|
-
} finally {
|
|
73
|
-
setIsLoading(false);
|
|
74
|
-
}
|
|
75
|
-
}, [appleAvailable]);
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
signInWithApple,
|
|
79
|
-
appleLoading: isLoading,
|
|
80
|
-
appleAvailable,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Firebase Auth Presentation Layer
|
|
3
|
-
* Domain-Driven Design (DDD) - Presentation Exports
|
|
4
|
-
*
|
|
5
|
-
* React hooks for Firebase authentication.
|
|
6
|
-
* Provides clean interface for UI components.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export { useFirebaseAuth } from './presentation/hooks/useFirebaseAuth';
|
|
10
|
-
export type { UseFirebaseAuthResult } from './presentation/hooks/useFirebaseAuth';
|
|
11
|
-
|
|
12
|
-
export { useAnonymousAuth } from './presentation/hooks/useAnonymousAuth';
|
|
13
|
-
export type { UseAnonymousAuthResult } from './presentation/hooks/useAnonymousAuth';
|
|
14
|
-
|
|
15
|
-
export { useSocialAuth } from './presentation/hooks/useSocialAuth';
|
|
16
|
-
export type {
|
|
17
|
-
SocialAuthConfig,
|
|
18
|
-
SocialAuthResult,
|
|
19
|
-
UseSocialAuthResult,
|
|
20
|
-
} from './presentation/hooks/useSocialAuth';
|
|
21
|
-
|
|
22
|
-
export { useGoogleOAuth } from './presentation/hooks/useGoogleOAuth';
|
|
23
|
-
export type {
|
|
24
|
-
UseGoogleOAuthResult,
|
|
25
|
-
} from './presentation/hooks/useGoogleOAuth';
|
|
26
|
-
|
|
27
|
-
export { useAppleAuth } from './presentation/hooks/useAppleAuth';
|
|
28
|
-
export type {
|
|
29
|
-
UseAppleAuthResult,
|
|
30
|
-
AppleAuthSignInResult,
|
|
31
|
-
} from './presentation/hooks/useAppleAuth';
|
|
@@ -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
|
-
}
|