valtech-components 2.0.417 → 2.0.418
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/esm2022/public-api.mjs +4 -2
- package/fesm2022/valtech-components.mjs +4 -2607
- package/fesm2022/valtech-components.mjs.map +1 -1
- package/package.json +1 -1
- package/public-api.d.ts +0 -1
- package/esm2022/lib/services/firebase/config.mjs +0 -108
- package/esm2022/lib/services/firebase/firebase.service.mjs +0 -285
- package/esm2022/lib/services/firebase/firestore-collection.mjs +0 -266
- package/esm2022/lib/services/firebase/firestore.service.mjs +0 -508
- package/esm2022/lib/services/firebase/index.mjs +0 -46
- package/esm2022/lib/services/firebase/messaging.service.mjs +0 -503
- package/esm2022/lib/services/firebase/storage.service.mjs +0 -421
- package/esm2022/lib/services/firebase/types.mjs +0 -8
- package/esm2022/lib/services/firebase/utils/path-builder.mjs +0 -195
- package/esm2022/lib/services/firebase/utils/query-builder.mjs +0 -302
- package/lib/services/firebase/config.d.ts +0 -49
- package/lib/services/firebase/firebase.service.d.ts +0 -140
- package/lib/services/firebase/firestore-collection.d.ts +0 -195
- package/lib/services/firebase/firestore.service.d.ts +0 -303
- package/lib/services/firebase/index.d.ts +0 -38
- package/lib/services/firebase/messaging.service.d.ts +0 -254
- package/lib/services/firebase/storage.service.d.ts +0 -204
- package/lib/services/firebase/types.d.ts +0 -281
- package/lib/services/firebase/utils/path-builder.d.ts +0 -132
- package/lib/services/firebase/utils/query-builder.d.ts +0 -210
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { UserCredential } from '@angular/fire/auth';
|
|
2
|
-
import { Observable } from 'rxjs';
|
|
3
|
-
import { FirebaseUser, SessionState, ValtechFirebaseConfig } from './types';
|
|
4
|
-
import * as i0 from "@angular/core";
|
|
5
|
-
/**
|
|
6
|
-
* Servicio de autenticación de Firebase.
|
|
7
|
-
*
|
|
8
|
-
* Este servicio NO maneja el login de usuarios directamente.
|
|
9
|
-
* En su lugar, trabaja con Custom Tokens generados por tu backend.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* // Después de autenticarte con tu backend (ej: Cognito)
|
|
14
|
-
* @Component({...})
|
|
15
|
-
* export class LoginComponent {
|
|
16
|
-
* private authService = inject(AuthService); // Tu servicio de auth
|
|
17
|
-
* private firebase = inject(FirebaseService); // Este servicio
|
|
18
|
-
*
|
|
19
|
-
* async login(email: string, password: string) {
|
|
20
|
-
* // 1. Autenticar con tu backend
|
|
21
|
-
* const response = await this.authService.login(email, password);
|
|
22
|
-
*
|
|
23
|
-
* // 2. El backend devuelve un Firebase Custom Token
|
|
24
|
-
* if (response.firebaseToken) {
|
|
25
|
-
* await this.firebase.signInWithCustomToken(response.firebaseToken);
|
|
26
|
-
* }
|
|
27
|
-
*
|
|
28
|
-
* // Ahora el usuario puede acceder a Firestore, Storage, etc.
|
|
29
|
-
* }
|
|
30
|
-
*
|
|
31
|
-
* async logout() {
|
|
32
|
-
* await this.authService.logout();
|
|
33
|
-
* await this.firebase.signOut();
|
|
34
|
-
* }
|
|
35
|
-
* }
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export declare class FirebaseService {
|
|
39
|
-
private auth;
|
|
40
|
-
private config;
|
|
41
|
-
/** Estado interno de la sesión */
|
|
42
|
-
private sessionState;
|
|
43
|
-
/** Estado actual de la sesión como Observable */
|
|
44
|
-
readonly state$: Observable<SessionState>;
|
|
45
|
-
/** Usuario actual de Firebase como Observable */
|
|
46
|
-
readonly user$: Observable<FirebaseUser | null>;
|
|
47
|
-
/** Indica si el usuario está autenticado en Firebase */
|
|
48
|
-
readonly isAuthenticated$: Observable<boolean>;
|
|
49
|
-
constructor();
|
|
50
|
-
/**
|
|
51
|
-
* Autentica al usuario con un Custom Token generado por el backend.
|
|
52
|
-
*
|
|
53
|
-
* @param token - Firebase Custom Token generado por tu backend
|
|
54
|
-
* @returns UserCredential con la información del usuario
|
|
55
|
-
* @throws Error si el token es inválido o expiró
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* ```typescript
|
|
59
|
-
* // Después de login exitoso con tu backend
|
|
60
|
-
* const { firebaseToken } = await backendAuth.login(email, password);
|
|
61
|
-
* await firebaseService.signInWithCustomToken(firebaseToken);
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
signInWithCustomToken(token: string): Promise<UserCredential>;
|
|
65
|
-
/**
|
|
66
|
-
* Cierra la sesión de Firebase.
|
|
67
|
-
* Llamar junto con el logout de tu sistema de autenticación principal.
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```typescript
|
|
71
|
-
* async logout() {
|
|
72
|
-
* await this.backendAuth.logout(); // Tu auth
|
|
73
|
-
* await this.firebase.signOut(); // Firebase
|
|
74
|
-
* }
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
signOut(): Promise<void>;
|
|
78
|
-
/**
|
|
79
|
-
* Obtiene el usuario actual de Firebase (síncrono).
|
|
80
|
-
* Retorna null si no hay usuario autenticado.
|
|
81
|
-
*/
|
|
82
|
-
get currentUser(): FirebaseUser | null;
|
|
83
|
-
/**
|
|
84
|
-
* Obtiene el UID del usuario actual.
|
|
85
|
-
* Retorna null si no hay usuario autenticado.
|
|
86
|
-
*/
|
|
87
|
-
get uid(): string | null;
|
|
88
|
-
/**
|
|
89
|
-
* Indica si hay un usuario autenticado actualmente.
|
|
90
|
-
*/
|
|
91
|
-
get isAuthenticated(): boolean;
|
|
92
|
-
/**
|
|
93
|
-
* Obtiene el ID Token de Firebase para el usuario actual.
|
|
94
|
-
* Útil para validar el usuario en tu backend.
|
|
95
|
-
*
|
|
96
|
-
* @param forceRefresh - Si true, fuerza la renovación del token
|
|
97
|
-
* @returns ID Token o null si no hay usuario
|
|
98
|
-
*/
|
|
99
|
-
getIdToken(forceRefresh?: boolean): Promise<string | null>;
|
|
100
|
-
/**
|
|
101
|
-
* Obtiene los claims personalizados del token del usuario.
|
|
102
|
-
* Los claims son establecidos por tu backend al crear el Custom Token.
|
|
103
|
-
*
|
|
104
|
-
* @returns Objeto con los claims o vacío si no hay usuario
|
|
105
|
-
*/
|
|
106
|
-
getClaims(): Promise<Record<string, unknown>>;
|
|
107
|
-
/**
|
|
108
|
-
* Verifica si el usuario tiene un rol específico.
|
|
109
|
-
* El rol debe estar definido en los claims del Custom Token.
|
|
110
|
-
*
|
|
111
|
-
* @param role - Nombre del rol a verificar
|
|
112
|
-
* @returns true si el usuario tiene el rol
|
|
113
|
-
*/
|
|
114
|
-
hasRole(role: string): Promise<boolean>;
|
|
115
|
-
/**
|
|
116
|
-
* Espera a que el estado de autenticación esté determinado.
|
|
117
|
-
* Útil en guards o al inicializar la app.
|
|
118
|
-
*
|
|
119
|
-
* @returns Usuario actual o null
|
|
120
|
-
*/
|
|
121
|
-
waitForAuth(): Promise<FirebaseUser | null>;
|
|
122
|
-
/**
|
|
123
|
-
* Obtiene la configuración actual de Firebase.
|
|
124
|
-
*/
|
|
125
|
-
getConfig(): ValtechFirebaseConfig;
|
|
126
|
-
/**
|
|
127
|
-
* Indica si los emuladores están habilitados.
|
|
128
|
-
*/
|
|
129
|
-
isUsingEmulators(): boolean;
|
|
130
|
-
/**
|
|
131
|
-
* Mapea un User de Firebase a nuestra interface FirebaseUser
|
|
132
|
-
*/
|
|
133
|
-
private mapUser;
|
|
134
|
-
/**
|
|
135
|
-
* Convierte errores de Firebase a mensajes en español
|
|
136
|
-
*/
|
|
137
|
-
private getErrorMessage;
|
|
138
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<FirebaseService, never>;
|
|
139
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<FirebaseService>;
|
|
140
|
-
}
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Firestore Collection
|
|
3
|
-
*
|
|
4
|
-
* Clase base abstracta para crear servicios de colección tipados.
|
|
5
|
-
* Extiende esta clase para tener un servicio dedicado por entidad.
|
|
6
|
-
*/
|
|
7
|
-
import { Observable } from 'rxjs';
|
|
8
|
-
import { FirestoreService } from './firestore.service';
|
|
9
|
-
import { FirestoreDocument, PaginatedResult, QueryOptions } from './types';
|
|
10
|
-
/**
|
|
11
|
-
* Opciones de configuración para una colección.
|
|
12
|
-
*/
|
|
13
|
-
export interface CollectionOptions {
|
|
14
|
-
/**
|
|
15
|
-
* Si true, usa soft delete (marca deletedAt en lugar de eliminar).
|
|
16
|
-
* Default: false
|
|
17
|
-
*/
|
|
18
|
-
softDelete?: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* Si true, maneja automáticamente createdAt/updatedAt.
|
|
21
|
-
* Default: true
|
|
22
|
-
*/
|
|
23
|
-
timestamps?: boolean;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Referencia a una sub-colección tipada.
|
|
27
|
-
*/
|
|
28
|
-
export interface SubCollectionRef<T extends FirestoreDocument> {
|
|
29
|
-
getById(id: string): Promise<T | null>;
|
|
30
|
-
getAll(options?: QueryOptions): Promise<T[]>;
|
|
31
|
-
watch(id: string): Observable<T | null>;
|
|
32
|
-
watchAll(options?: QueryOptions): Observable<T[]>;
|
|
33
|
-
create(data: Omit<T, 'id' | 'createdAt' | 'updatedAt'>): Promise<T>;
|
|
34
|
-
update(id: string, data: Partial<T>): Promise<void>;
|
|
35
|
-
delete(id: string): Promise<void>;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Clase base para servicios de colección tipados.
|
|
39
|
-
*
|
|
40
|
-
* Extiende esta clase para crear un servicio dedicado para cada entidad,
|
|
41
|
-
* con métodos personalizados y tipado fuerte.
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```typescript
|
|
45
|
-
* // Definir el modelo
|
|
46
|
-
* interface User extends FirestoreDocument {
|
|
47
|
-
* name: string;
|
|
48
|
-
* email: string;
|
|
49
|
-
* role: 'admin' | 'user';
|
|
50
|
-
* active: boolean;
|
|
51
|
-
* }
|
|
52
|
-
*
|
|
53
|
-
* // Crear el servicio
|
|
54
|
-
* @Injectable({ providedIn: 'root' })
|
|
55
|
-
* export class UsersCollection extends FirestoreCollection<User> {
|
|
56
|
-
* constructor() {
|
|
57
|
-
* super('users');
|
|
58
|
-
* }
|
|
59
|
-
*
|
|
60
|
-
* // Métodos personalizados
|
|
61
|
-
* async getActiveUsers(): Promise<User[]> {
|
|
62
|
-
* return this.query({
|
|
63
|
-
* where: [{ field: 'active', operator: '==', value: true }]
|
|
64
|
-
* });
|
|
65
|
-
* }
|
|
66
|
-
*
|
|
67
|
-
* async getAdmins(): Promise<User[]> {
|
|
68
|
-
* return this.query({
|
|
69
|
-
* where: [{ field: 'role', operator: '==', value: 'admin' }]
|
|
70
|
-
* });
|
|
71
|
-
* }
|
|
72
|
-
*
|
|
73
|
-
* watchOnlineUsers(): Observable<User[]> {
|
|
74
|
-
* return this.watchQuery({
|
|
75
|
-
* where: [{ field: 'status', operator: '==', value: 'online' }]
|
|
76
|
-
* });
|
|
77
|
-
* }
|
|
78
|
-
* }
|
|
79
|
-
*
|
|
80
|
-
* // Usar en componentes
|
|
81
|
-
* @Component({...})
|
|
82
|
-
* export class UsersComponent {
|
|
83
|
-
* private users = inject(UsersCollection);
|
|
84
|
-
*
|
|
85
|
-
* admins$ = this.users.getAdmins();
|
|
86
|
-
* onlineUsers$ = this.users.watchOnlineUsers();
|
|
87
|
-
*
|
|
88
|
-
* async createUser(data: Omit<User, 'id'>) {
|
|
89
|
-
* const user = await this.users.create(data);
|
|
90
|
-
* }
|
|
91
|
-
* }
|
|
92
|
-
* ```
|
|
93
|
-
*/
|
|
94
|
-
export declare abstract class FirestoreCollection<T extends FirestoreDocument> {
|
|
95
|
-
protected firestore: FirestoreService;
|
|
96
|
-
protected readonly collectionPath: string;
|
|
97
|
-
protected readonly options: CollectionOptions;
|
|
98
|
-
/**
|
|
99
|
-
* @param collectionPath - Ruta de la colección en Firestore
|
|
100
|
-
* @param options - Opciones de configuración
|
|
101
|
-
*/
|
|
102
|
-
constructor(collectionPath: string, options?: CollectionOptions);
|
|
103
|
-
/**
|
|
104
|
-
* Obtiene un documento por ID.
|
|
105
|
-
*/
|
|
106
|
-
getById(id: string): Promise<T | null>;
|
|
107
|
-
/**
|
|
108
|
-
* Obtiene todos los documentos de la colección.
|
|
109
|
-
*/
|
|
110
|
-
getAll(options?: QueryOptions): Promise<T[]>;
|
|
111
|
-
/**
|
|
112
|
-
* Ejecuta una query personalizada.
|
|
113
|
-
*/
|
|
114
|
-
query(options: QueryOptions): Promise<T[]>;
|
|
115
|
-
/**
|
|
116
|
-
* Obtiene documentos con paginación.
|
|
117
|
-
*/
|
|
118
|
-
paginate(options: QueryOptions & {
|
|
119
|
-
limit: number;
|
|
120
|
-
}): Promise<PaginatedResult<T>>;
|
|
121
|
-
/**
|
|
122
|
-
* Obtiene el primer documento que coincida con la query.
|
|
123
|
-
*/
|
|
124
|
-
getFirst(options?: QueryOptions): Promise<T | null>;
|
|
125
|
-
/**
|
|
126
|
-
* Cuenta los documentos que coinciden con la query.
|
|
127
|
-
* Nota: Esto carga todos los documentos, usar con cuidado en colecciones grandes.
|
|
128
|
-
*/
|
|
129
|
-
count(options?: QueryOptions): Promise<number>;
|
|
130
|
-
/**
|
|
131
|
-
* Verifica si un documento existe.
|
|
132
|
-
*/
|
|
133
|
-
exists(id: string): Promise<boolean>;
|
|
134
|
-
/**
|
|
135
|
-
* Suscribe a cambios de un documento.
|
|
136
|
-
*/
|
|
137
|
-
watch(id: string): Observable<T | null>;
|
|
138
|
-
/**
|
|
139
|
-
* Suscribe a cambios de la colección.
|
|
140
|
-
*/
|
|
141
|
-
watchAll(options?: QueryOptions): Observable<T[]>;
|
|
142
|
-
/**
|
|
143
|
-
* Suscribe a una query personalizada.
|
|
144
|
-
*/
|
|
145
|
-
watchQuery(options: QueryOptions): Observable<T[]>;
|
|
146
|
-
/**
|
|
147
|
-
* Crea un nuevo documento con ID auto-generado.
|
|
148
|
-
*/
|
|
149
|
-
create(data: Omit<T, 'id' | 'createdAt' | 'updatedAt'>): Promise<T>;
|
|
150
|
-
/**
|
|
151
|
-
* Crea un documento con ID específico.
|
|
152
|
-
*/
|
|
153
|
-
createWithId(id: string, data: Omit<T, 'id'>): Promise<void>;
|
|
154
|
-
/**
|
|
155
|
-
* Actualiza campos de un documento.
|
|
156
|
-
*/
|
|
157
|
-
update(id: string, data: Partial<Omit<T, 'id' | 'createdAt'>>): Promise<void>;
|
|
158
|
-
/**
|
|
159
|
-
* Elimina un documento.
|
|
160
|
-
* Si softDelete está habilitado, marca como eliminado en lugar de borrar.
|
|
161
|
-
*/
|
|
162
|
-
delete(id: string): Promise<void>;
|
|
163
|
-
/**
|
|
164
|
-
* Restaura un documento soft-deleted.
|
|
165
|
-
*/
|
|
166
|
-
restore(id: string): Promise<void>;
|
|
167
|
-
/**
|
|
168
|
-
* Obtiene una referencia a una sub-colección.
|
|
169
|
-
*
|
|
170
|
-
* @example
|
|
171
|
-
* ```typescript
|
|
172
|
-
* // En UsersCollection
|
|
173
|
-
* getUserDocuments(userId: string) {
|
|
174
|
-
* return this.subcollection<Document>(userId, 'documents');
|
|
175
|
-
* }
|
|
176
|
-
*
|
|
177
|
-
* // Uso
|
|
178
|
-
* const docs = await users.getUserDocuments('user123').getAll();
|
|
179
|
-
* ```
|
|
180
|
-
*/
|
|
181
|
-
subcollection<S extends FirestoreDocument>(parentId: string, subcollectionName: string): SubCollectionRef<S>;
|
|
182
|
-
/**
|
|
183
|
-
* Aplica filtros por defecto a las queries.
|
|
184
|
-
* Override este método para agregar filtros globales (ej: excluir soft-deleted).
|
|
185
|
-
*/
|
|
186
|
-
protected applyDefaultFilters(options?: QueryOptions): QueryOptions;
|
|
187
|
-
/**
|
|
188
|
-
* Genera un nuevo ID sin crear el documento.
|
|
189
|
-
*/
|
|
190
|
-
generateId(): string;
|
|
191
|
-
/**
|
|
192
|
-
* Obtiene la ruta de la colección.
|
|
193
|
-
*/
|
|
194
|
-
getPath(): string;
|
|
195
|
-
}
|
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
import { FieldValue } from '@angular/fire/firestore';
|
|
2
|
-
import { Observable } from 'rxjs';
|
|
3
|
-
import { FirestoreDocument, PaginatedResult, QueryOptions } from './types';
|
|
4
|
-
import * as i0 from "@angular/core";
|
|
5
|
-
/**
|
|
6
|
-
* Servicio para operaciones CRUD en Firestore.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* interface User extends FirestoreDocument {
|
|
11
|
-
* name: string;
|
|
12
|
-
* email: string;
|
|
13
|
-
* role: 'admin' | 'user';
|
|
14
|
-
* }
|
|
15
|
-
*
|
|
16
|
-
* @Component({...})
|
|
17
|
-
* export class UsersComponent {
|
|
18
|
-
* private firestore = inject(FirestoreService);
|
|
19
|
-
*
|
|
20
|
-
* // Lectura one-time
|
|
21
|
-
* async loadUser(id: string) {
|
|
22
|
-
* const user = await this.firestore.getDoc<User>('users', id);
|
|
23
|
-
* }
|
|
24
|
-
*
|
|
25
|
-
* // Subscripción real-time
|
|
26
|
-
* users$ = this.firestore.collectionChanges<User>('users', {
|
|
27
|
-
* where: [{ field: 'role', operator: '==', value: 'admin' }],
|
|
28
|
-
* orderBy: [{ field: 'name', direction: 'asc' }]
|
|
29
|
-
* });
|
|
30
|
-
*
|
|
31
|
-
* // Crear documento
|
|
32
|
-
* async createUser(data: Omit<User, 'id'>) {
|
|
33
|
-
* const user = await this.firestore.addDoc<User>('users', data);
|
|
34
|
-
* }
|
|
35
|
-
* }
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export declare class FirestoreService {
|
|
39
|
-
private firestore;
|
|
40
|
-
/**
|
|
41
|
-
* Obtiene un documento por ID (lectura única).
|
|
42
|
-
*
|
|
43
|
-
* @param collectionPath - Ruta de la colección
|
|
44
|
-
* @param docId - ID del documento
|
|
45
|
-
* @returns Documento o null si no existe
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```typescript
|
|
49
|
-
* const user = await firestoreService.getDoc<User>('users', 'abc123');
|
|
50
|
-
* if (user) {
|
|
51
|
-
* console.log(user.name);
|
|
52
|
-
* }
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
getDoc<T extends FirestoreDocument>(collectionPath: string, docId: string): Promise<T | null>;
|
|
56
|
-
/**
|
|
57
|
-
* Obtiene múltiples documentos con opciones de query.
|
|
58
|
-
*
|
|
59
|
-
* @param collectionPath - Ruta de la colección
|
|
60
|
-
* @param options - Opciones de query (where, orderBy, limit)
|
|
61
|
-
* @returns Array de documentos
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* ```typescript
|
|
65
|
-
* // Todos los usuarios activos ordenados por nombre
|
|
66
|
-
* const users = await firestoreService.getDocs<User>('users', {
|
|
67
|
-
* where: [{ field: 'active', operator: '==', value: true }],
|
|
68
|
-
* orderBy: [{ field: 'name', direction: 'asc' }],
|
|
69
|
-
* limit: 50
|
|
70
|
-
* });
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
getDocs<T extends FirestoreDocument>(collectionPath: string, options?: QueryOptions): Promise<T[]>;
|
|
74
|
-
/**
|
|
75
|
-
* Obtiene documentos con paginación basada en cursores.
|
|
76
|
-
*
|
|
77
|
-
* @param collectionPath - Ruta de la colección
|
|
78
|
-
* @param options - Opciones de query (debe incluir limit)
|
|
79
|
-
* @returns Resultado paginado con cursor para la siguiente página
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* ```typescript
|
|
83
|
-
* // Primera página
|
|
84
|
-
* const page1 = await firestoreService.getPaginated<User>('users', {
|
|
85
|
-
* orderBy: [{ field: 'createdAt', direction: 'desc' }],
|
|
86
|
-
* limit: 10
|
|
87
|
-
* });
|
|
88
|
-
*
|
|
89
|
-
* // Siguiente página
|
|
90
|
-
* if (page1.hasMore) {
|
|
91
|
-
* const page2 = await firestoreService.getPaginated<User>('users', {
|
|
92
|
-
* orderBy: [{ field: 'createdAt', direction: 'desc' }],
|
|
93
|
-
* limit: 10,
|
|
94
|
-
* startAfter: page1.lastDoc
|
|
95
|
-
* });
|
|
96
|
-
* }
|
|
97
|
-
* ```
|
|
98
|
-
*/
|
|
99
|
-
getPaginated<T extends FirestoreDocument>(collectionPath: string, options: QueryOptions & {
|
|
100
|
-
limit: number;
|
|
101
|
-
}): Promise<PaginatedResult<T>>;
|
|
102
|
-
/**
|
|
103
|
-
* Verifica si un documento existe.
|
|
104
|
-
*
|
|
105
|
-
* @param collectionPath - Ruta de la colección
|
|
106
|
-
* @param docId - ID del documento
|
|
107
|
-
* @returns true si el documento existe
|
|
108
|
-
*/
|
|
109
|
-
exists(collectionPath: string, docId: string): Promise<boolean>;
|
|
110
|
-
/**
|
|
111
|
-
* Suscribe a cambios de un documento (real-time).
|
|
112
|
-
*
|
|
113
|
-
* @param collectionPath - Ruta de la colección
|
|
114
|
-
* @param docId - ID del documento
|
|
115
|
-
* @returns Observable que emite cuando el documento cambia
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* ```typescript
|
|
119
|
-
* // En el componente
|
|
120
|
-
* user$ = this.firestoreService.docChanges<User>('users', this.userId);
|
|
121
|
-
*
|
|
122
|
-
* // En el template
|
|
123
|
-
* @if (user$ | async; as user) {
|
|
124
|
-
* <p>{{ user.name }}</p>
|
|
125
|
-
* }
|
|
126
|
-
* ```
|
|
127
|
-
*/
|
|
128
|
-
docChanges<T extends FirestoreDocument>(collectionPath: string, docId: string): Observable<T | null>;
|
|
129
|
-
/**
|
|
130
|
-
* Suscribe a cambios de una colección (real-time).
|
|
131
|
-
*
|
|
132
|
-
* @param collectionPath - Ruta de la colección
|
|
133
|
-
* @param options - Opciones de query
|
|
134
|
-
* @returns Observable que emite cuando la colección cambia
|
|
135
|
-
*
|
|
136
|
-
* @example
|
|
137
|
-
* ```typescript
|
|
138
|
-
* // Usuarios activos en tiempo real
|
|
139
|
-
* activeUsers$ = this.firestoreService.collectionChanges<User>('users', {
|
|
140
|
-
* where: [{ field: 'status', operator: '==', value: 'online' }]
|
|
141
|
-
* });
|
|
142
|
-
* ```
|
|
143
|
-
*/
|
|
144
|
-
collectionChanges<T extends FirestoreDocument>(collectionPath: string, options?: QueryOptions): Observable<T[]>;
|
|
145
|
-
/**
|
|
146
|
-
* Agrega un documento con ID auto-generado.
|
|
147
|
-
*
|
|
148
|
-
* @param collectionPath - Ruta de la colección
|
|
149
|
-
* @param data - Datos del documento (sin id, createdAt, updatedAt)
|
|
150
|
-
* @returns Documento creado con su ID
|
|
151
|
-
*
|
|
152
|
-
* @example
|
|
153
|
-
* ```typescript
|
|
154
|
-
* const newUser = await firestoreService.addDoc<User>('users', {
|
|
155
|
-
* name: 'John Doe',
|
|
156
|
-
* email: 'john@example.com',
|
|
157
|
-
* role: 'user'
|
|
158
|
-
* });
|
|
159
|
-
* console.log('Created user with ID:', newUser.id);
|
|
160
|
-
* ```
|
|
161
|
-
*/
|
|
162
|
-
addDoc<T extends FirestoreDocument>(collectionPath: string, data: Omit<T, 'id' | 'createdAt' | 'updatedAt'>): Promise<T>;
|
|
163
|
-
/**
|
|
164
|
-
* Crea o sobrescribe un documento con ID específico.
|
|
165
|
-
*
|
|
166
|
-
* @param collectionPath - Ruta de la colección
|
|
167
|
-
* @param docId - ID del documento
|
|
168
|
-
* @param data - Datos del documento
|
|
169
|
-
* @param options - Opciones (merge: true para merge en lugar de sobrescribir)
|
|
170
|
-
*
|
|
171
|
-
* @example
|
|
172
|
-
* ```typescript
|
|
173
|
-
* // Sobrescribir completamente
|
|
174
|
-
* await firestoreService.setDoc<User>('users', 'user123', userData);
|
|
175
|
-
*
|
|
176
|
-
* // Merge con datos existentes
|
|
177
|
-
* await firestoreService.setDoc<User>('users', 'user123', { name: 'New Name' }, { merge: true });
|
|
178
|
-
* ```
|
|
179
|
-
*/
|
|
180
|
-
setDoc<T extends FirestoreDocument>(collectionPath: string, docId: string, data: Omit<T, 'id'>, options?: {
|
|
181
|
-
merge?: boolean;
|
|
182
|
-
}): Promise<void>;
|
|
183
|
-
/**
|
|
184
|
-
* Actualiza campos específicos de un documento.
|
|
185
|
-
*
|
|
186
|
-
* @param collectionPath - Ruta de la colección
|
|
187
|
-
* @param docId - ID del documento
|
|
188
|
-
* @param data - Campos a actualizar
|
|
189
|
-
*
|
|
190
|
-
* @example
|
|
191
|
-
* ```typescript
|
|
192
|
-
* await firestoreService.updateDoc<User>('users', 'user123', {
|
|
193
|
-
* name: 'Updated Name',
|
|
194
|
-
* lastLogin: new Date()
|
|
195
|
-
* });
|
|
196
|
-
* ```
|
|
197
|
-
*/
|
|
198
|
-
updateDoc<T extends FirestoreDocument>(collectionPath: string, docId: string, data: Partial<Omit<T, 'id' | 'createdAt'>>): Promise<void>;
|
|
199
|
-
/**
|
|
200
|
-
* Elimina un documento.
|
|
201
|
-
*
|
|
202
|
-
* @param collectionPath - Ruta de la colección
|
|
203
|
-
* @param docId - ID del documento
|
|
204
|
-
*
|
|
205
|
-
* @example
|
|
206
|
-
* ```typescript
|
|
207
|
-
* await firestoreService.deleteDoc('users', 'user123');
|
|
208
|
-
* ```
|
|
209
|
-
*/
|
|
210
|
-
deleteDoc(collectionPath: string, docId: string): Promise<void>;
|
|
211
|
-
/**
|
|
212
|
-
* Ejecuta múltiples operaciones de escritura de forma atómica.
|
|
213
|
-
*
|
|
214
|
-
* @param operations - Función que recibe el batch y agrega operaciones
|
|
215
|
-
*
|
|
216
|
-
* @example
|
|
217
|
-
* ```typescript
|
|
218
|
-
* await firestoreService.batch((batch) => {
|
|
219
|
-
* batch.set('users/user1', { name: 'User 1' });
|
|
220
|
-
* batch.update('users/user2', { status: 'inactive' });
|
|
221
|
-
* batch.delete('users/user3');
|
|
222
|
-
* });
|
|
223
|
-
* ```
|
|
224
|
-
*/
|
|
225
|
-
batch(operations: (batch: {
|
|
226
|
-
set: <T>(path: string, data: T) => void;
|
|
227
|
-
update: <T>(path: string, data: Partial<T>) => void;
|
|
228
|
-
delete: (path: string) => void;
|
|
229
|
-
}) => void): Promise<void>;
|
|
230
|
-
/**
|
|
231
|
-
* Construye una ruta a partir de un template.
|
|
232
|
-
*
|
|
233
|
-
* @param template - Template con placeholders {param}
|
|
234
|
-
* @param params - Valores para los placeholders
|
|
235
|
-
* @returns Ruta construida
|
|
236
|
-
*
|
|
237
|
-
* @example
|
|
238
|
-
* ```typescript
|
|
239
|
-
* const path = firestoreService.buildPath('users/{userId}/documents/{docId}', {
|
|
240
|
-
* userId: 'user123',
|
|
241
|
-
* docId: 'doc456'
|
|
242
|
-
* });
|
|
243
|
-
* // => 'users/user123/documents/doc456'
|
|
244
|
-
* ```
|
|
245
|
-
*/
|
|
246
|
-
buildPath(template: string, params: Record<string, string>): string;
|
|
247
|
-
/**
|
|
248
|
-
* Genera un ID único para un documento (sin crearlo).
|
|
249
|
-
*
|
|
250
|
-
* @param collectionPath - Ruta de la colección
|
|
251
|
-
* @returns ID único generado por Firestore
|
|
252
|
-
*/
|
|
253
|
-
generateId(collectionPath: string): string;
|
|
254
|
-
/**
|
|
255
|
-
* Retorna un valor de timestamp del servidor.
|
|
256
|
-
* Usar en campos de fecha para que Firestore asigne el timestamp.
|
|
257
|
-
*/
|
|
258
|
-
serverTimestamp(): FieldValue;
|
|
259
|
-
/**
|
|
260
|
-
* Retorna un valor para agregar elementos a un array.
|
|
261
|
-
*
|
|
262
|
-
* @example
|
|
263
|
-
* ```typescript
|
|
264
|
-
* await firestoreService.updateDoc('users', 'user123', {
|
|
265
|
-
* tags: firestoreService.arrayUnion('new-tag')
|
|
266
|
-
* });
|
|
267
|
-
* ```
|
|
268
|
-
*/
|
|
269
|
-
arrayUnion(...elements: unknown[]): FieldValue;
|
|
270
|
-
/**
|
|
271
|
-
* Retorna un valor para remover elementos de un array.
|
|
272
|
-
*/
|
|
273
|
-
arrayRemove(...elements: unknown[]): FieldValue;
|
|
274
|
-
/**
|
|
275
|
-
* Retorna un valor para incrementar un campo numérico.
|
|
276
|
-
*
|
|
277
|
-
* @example
|
|
278
|
-
* ```typescript
|
|
279
|
-
* await firestoreService.updateDoc('users', 'user123', {
|
|
280
|
-
* loginCount: firestoreService.increment(1)
|
|
281
|
-
* });
|
|
282
|
-
* ```
|
|
283
|
-
*/
|
|
284
|
-
increment(n: number): FieldValue;
|
|
285
|
-
/**
|
|
286
|
-
* Construye los QueryConstraints a partir de QueryOptions
|
|
287
|
-
*/
|
|
288
|
-
private buildQueryConstraints;
|
|
289
|
-
/**
|
|
290
|
-
* Mapea un DocumentSnapshot a nuestro tipo
|
|
291
|
-
*/
|
|
292
|
-
private mapDocument;
|
|
293
|
-
/**
|
|
294
|
-
* Convierte Timestamps de Firestore a Date de JavaScript
|
|
295
|
-
*/
|
|
296
|
-
private convertTimestamps;
|
|
297
|
-
/**
|
|
298
|
-
* Divide una ruta de documento en colección e ID
|
|
299
|
-
*/
|
|
300
|
-
private splitPath;
|
|
301
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<FirestoreService, never>;
|
|
302
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<FirestoreService>;
|
|
303
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Firebase Services
|
|
3
|
-
*
|
|
4
|
-
* Servicios reutilizables para integración con Firebase.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```typescript
|
|
8
|
-
* // En main.ts
|
|
9
|
-
* import { provideValtechFirebase } from 'valtech-components';
|
|
10
|
-
*
|
|
11
|
-
* bootstrapApplication(AppComponent, {
|
|
12
|
-
* providers: [
|
|
13
|
-
* provideValtechFirebase({
|
|
14
|
-
* firebase: environment.firebase,
|
|
15
|
-
* persistence: true,
|
|
16
|
-
* }),
|
|
17
|
-
* ],
|
|
18
|
-
* });
|
|
19
|
-
*
|
|
20
|
-
* // En componentes
|
|
21
|
-
* import { FirebaseService, FirestoreService } from 'valtech-components';
|
|
22
|
-
*
|
|
23
|
-
* @Component({...})
|
|
24
|
-
* export class MyComponent {
|
|
25
|
-
* private firebase = inject(FirebaseService);
|
|
26
|
-
* private firestore = inject(FirestoreService);
|
|
27
|
-
* }
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export * from './types';
|
|
31
|
-
export { VALTECH_FIREBASE_CONFIG, hasEmulators, provideValtechFirebase } from './config';
|
|
32
|
-
export { FirebaseService } from './firebase.service';
|
|
33
|
-
export { FirestoreService } from './firestore.service';
|
|
34
|
-
export { CollectionOptions, FirestoreCollection, SubCollectionRef } from './firestore-collection';
|
|
35
|
-
export { QueryBuilder, query } from './utils/query-builder';
|
|
36
|
-
export { buildPath, extractPathParams, getCollectionPath, getDocumentId, isCollectionPath, isDocumentPath, isValidPath, joinPath, } from './utils/path-builder';
|
|
37
|
-
export { StorageService } from './storage.service';
|
|
38
|
-
export { MessagingService } from './messaging.service';
|