ngx-firestore-wrapper-kit 0.0.5 → 0.0.7
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/fesm2022/ngx-firestore-wrapper-kit.mjs +50 -1
- package/fesm2022/ngx-firestore-wrapper-kit.mjs.map +1 -1
- package/index.d.ts +21 -0
- package/package.json +1 -1
- package/fesm2022/goc-ngx-firestore-kit.mjs +0 -109
- package/fesm2022/goc-ngx-firestore-kit.mjs.map +0 -1
- package/fesm2022/goc-ngx-firestore-wrapper-kit.mjs +0 -109
- package/fesm2022/goc-ngx-firestore-wrapper-kit.mjs.map +0 -1
- package/fesm2022/ngx-firestore-kit.mjs +0 -109
- package/fesm2022/ngx-firestore-kit.mjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { Component, inject, Injector, runInInjectionContext, Injectable, makeEnvironmentProviders } from '@angular/core';
|
|
3
|
-
import { Firestore, doc, docData, collection, collectionChanges, provideFirestore, getFirestore } from '@angular/fire/firestore';
|
|
3
|
+
import { Firestore, doc, getDoc, docData, collection, collectionChanges, provideFirestore, getFirestore } from '@angular/fire/firestore';
|
|
4
4
|
import { of } from 'rxjs';
|
|
5
5
|
import { filter, map, catchError } from 'rxjs/operators';
|
|
6
6
|
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
|
|
@@ -25,6 +25,55 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.23", ngImpo
|
|
|
25
25
|
class FirestoreDataService {
|
|
26
26
|
firestore = inject(Firestore);
|
|
27
27
|
injector = inject(Injector);
|
|
28
|
+
/**
|
|
29
|
+
* Fetch document once — same path as {@link listenToDocument}.
|
|
30
|
+
*
|
|
31
|
+
* await:
|
|
32
|
+
* const res = await firestoreData.getDocument<Job>(path);
|
|
33
|
+
*
|
|
34
|
+
* .then:
|
|
35
|
+
* firestoreData.getDocument<Job>(path).then(res => { ... });
|
|
36
|
+
*/
|
|
37
|
+
/** Promise API: use with `.then()` or `await`. */
|
|
38
|
+
getDocument(pathSegments) {
|
|
39
|
+
return runInInjectionContext(this.injector, () => {
|
|
40
|
+
const ref = doc(this.firestore, pathSegments[0], ...pathSegments.slice(1));
|
|
41
|
+
return getDoc(ref);
|
|
42
|
+
}).then((snapshot) => ({
|
|
43
|
+
success: true,
|
|
44
|
+
data: snapshot.exists() ? snapshot.data() : null,
|
|
45
|
+
error: null,
|
|
46
|
+
})).catch((error) => {
|
|
47
|
+
console.error('[Firestore Document Get Error]', error);
|
|
48
|
+
return { success: false, data: null, error };
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Fetch document once — same path as {@link listenToDocument}.
|
|
53
|
+
*
|
|
54
|
+
* await:
|
|
55
|
+
* const res = await firestoreData.getDocument<Job>(path);
|
|
56
|
+
*
|
|
57
|
+
* .then:
|
|
58
|
+
* firestoreData.getDocument<Job>(path).then(res => { ... });
|
|
59
|
+
*/
|
|
60
|
+
async getDocument$(pathSegments) {
|
|
61
|
+
try {
|
|
62
|
+
const snapshot = await runInInjectionContext(this.injector, () => {
|
|
63
|
+
const ref = doc(this.firestore, pathSegments[0], ...pathSegments.slice(1));
|
|
64
|
+
return getDoc(ref);
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
success: true,
|
|
68
|
+
data: snapshot.exists() ? snapshot.data() : null,
|
|
69
|
+
error: null,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
console.error('[Firestore Document Get Error]', error);
|
|
74
|
+
return { success: false, data: null, error };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
28
77
|
/**
|
|
29
78
|
* Listen realtime document changes
|
|
30
79
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngx-firestore-wrapper-kit.mjs","sources":["../../../projects/ngx-firestore-kit/src/lib/ngx-firestore-kit.ts","../../../projects/ngx-firestore-kit/src/lib/service/firestore-data.service.ts","../../../projects/ngx-firestore-kit/src/lib/service/firestore-providers.ts","../../../projects/ngx-firestore-kit/src/public-api.ts","../../../projects/ngx-firestore-kit/src/ngx-firestore-wrapper-kit.ts"],"sourcesContent":["import { Component } from '@angular/core';\r\n\r\n@Component({\r\n selector: 'lib-ngx-firestore-kit',\r\n imports: [],\r\n template: `\r\n <p>\r\n ngx-firestore-kit works!\r\n </p>\r\n `,\r\n styles: ``,\r\n})\r\nexport class NgxFirestoreKit {\r\n\r\n}\r\n","import { Injectable, Injector, inject, runInInjectionContext } from '@angular/core';\r\nimport { Firestore, collection, collectionChanges, doc, docData } from '@angular/fire/firestore';\r\nimport { Observable, of } from 'rxjs';\r\nimport { catchError, filter, map } from 'rxjs/operators';\r\n\r\nexport interface FirestoreResponse<T> {\r\n success: boolean;\r\n data: any;\r\n error: unknown;\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root'\r\n})\r\n\r\nexport class FirestoreDataService {\r\n\r\n private readonly firestore = inject(Firestore);\r\n private readonly injector = inject(Injector);\r\n\r\n /**\r\n * Listen realtime document changes\r\n */\r\n public listenToDocument<T>(pathSegments: string[]): Observable<FirestoreResponse<T>> {\r\n return runInInjectionContext(this.injector, () => {\r\n const documentRef = doc(this.firestore, pathSegments[0], ...pathSegments.slice(1));\r\n return docData(documentRef);\r\n }).pipe(\r\n // Cast the response to the expected type\r\n filter((response) => response != null),\r\n // Return the response\r\n map((response) => ({ success: true, data: response, error: null })),\r\n // Handle errors\r\n catchError((error: unknown) => {\r\n console.error('[Firestore Document Listener Error]', error);\r\n return of({ success: false, data: null, error });\r\n })\r\n\r\n );\r\n }\r\n\r\n /**\r\n * Listen realtime collection changes\r\n */\r\n public listenToCollection<T>(collectionPath: string[]): Observable<FirestoreResponse<T[]>> {\r\n return runInInjectionContext(this.injector, () => {\r\n const collectionRef = collection(this.firestore, collectionPath[0], ...collectionPath.slice(1));\r\n return collectionChanges(collectionRef);\r\n }).pipe(\r\n // Cast the response to the expected type\r\n map((response) => ({ success: true, data: response, error: null })),\r\n // Handle errors\r\n catchError((error: unknown) => {\r\n console.error('[Firestore Collection Listener Error]', error);\r\n return of({ success: false, data: null, error });\r\n })\r\n );\r\n }\r\n}","import { EnvironmentProviders, makeEnvironmentProviders } from '@angular/core';\r\nimport { initializeApp, provideFirebaseApp } from '@angular/fire/app';\r\nimport { getFirestore, provideFirestore } from '@angular/fire/firestore';\r\n\r\n/**\r\n * Custom library provider that configures and initializes Firebase and Firestore \r\n * behind the scenes for the consuming application.\r\n */\r\nexport function provideFirestoreKit(firebaseConfig: any): EnvironmentProviders {\r\n return makeEnvironmentProviders([\r\n // The library handles the Angular Fire initialization boilerplate internally\r\n provideFirebaseApp(() => initializeApp(firebaseConfig)),\r\n provideFirestore(() => getFirestore())\r\n ]);\r\n}","/*\r\n * Public API Surface of ngx-firestore-kit\r\n */\r\n\r\nexport * from './lib/ngx-firestore-kit';\r\nexport * from './lib/service/firestore-data.service';\r\nexport * from './lib/service/firestore-providers';","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;MAYa,eAAe,CAAA;wGAAf,eAAe,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA;AAAf,IAAA,OAAA,IAAA,GAAA,EAAA,CAAA,oBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,IAAA,EAAA,eAAe,EAAA,YAAA,EAAA,IAAA,EAAA,QAAA,EAAA,uBAAA,EAAA,QAAA,EAAA,EAAA,EAAA,QAAA,EAPhB,CAAA;;;;AAIT,EAAA,CAAA,EAAA,QAAA,EAAA,IAAA,EAAA,MAAA,EAAA,CAAA,EAAA,CAAA,EAAA,CAAA;;4FAGU,eAAe,EAAA,UAAA,EAAA,CAAA;kBAV3B,SAAS;+BACE,uBAAuB,EAAA,OAAA,EACxB,EAA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aAAa,CAAC;QAC3C,CAAC,CAAC,CAAC,IAAI;;QAEH,GAAG,CAAC,CAAC,QAAQ,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;;AAEnE,QAAA,UAAU,CAAC,CAAC,KAAc,KAAI;AAC1B,YAAA,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,KAAK,CAAC;AAC7D,YAAA,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;QACpD,CAAC,CAAC,CACL;IACL;
|
|
1
|
+
{"version":3,"file":"ngx-firestore-wrapper-kit.mjs","sources":["../../../projects/ngx-firestore-kit/src/lib/ngx-firestore-kit.ts","../../../projects/ngx-firestore-kit/src/lib/service/firestore-data.service.ts","../../../projects/ngx-firestore-kit/src/lib/service/firestore-providers.ts","../../../projects/ngx-firestore-kit/src/public-api.ts","../../../projects/ngx-firestore-kit/src/ngx-firestore-wrapper-kit.ts"],"sourcesContent":["import { Component } from '@angular/core';\r\n\r\n@Component({\r\n selector: 'lib-ngx-firestore-kit',\r\n imports: [],\r\n template: `\r\n <p>\r\n ngx-firestore-kit works!\r\n </p>\r\n `,\r\n styles: ``,\r\n})\r\nexport class NgxFirestoreKit {\r\n\r\n}\r\n","import { Injectable, Injector, inject, runInInjectionContext } from '@angular/core';\r\nimport { Firestore, collection, collectionChanges, doc, docData, getDoc } from '@angular/fire/firestore';\r\nimport { Observable, of } from 'rxjs';\r\nimport { catchError, filter, map } from 'rxjs/operators';\r\n\r\nexport interface FirestoreResponse<T> {\r\n success: boolean;\r\n data: any;\r\n error: unknown;\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root'\r\n})\r\n\r\nexport class FirestoreDataService {\r\n\r\n private readonly firestore = inject(Firestore);\r\n private readonly injector = inject(Injector);\r\n\r\n /**\r\n * Fetch document once — same path as {@link listenToDocument}.\r\n *\r\n * await:\r\n * const res = await firestoreData.getDocument<Job>(path);\r\n *\r\n * .then:\r\n * firestoreData.getDocument<Job>(path).then(res => { ... });\r\n */\r\n /** Promise API: use with `.then()` or `await`. */\r\n public getDocument<T>(pathSegments: string[]): Promise<FirestoreResponse<T | null>> {\r\n return runInInjectionContext(this.injector, () => {\r\n const ref = doc(this.firestore, pathSegments[0], ...pathSegments.slice(1));\r\n return getDoc(ref);\r\n }).then((snapshot) => ({\r\n success: true,\r\n data: snapshot.exists() ? (snapshot.data() as T) : null,\r\n error: null,\r\n })).catch((error: unknown) => {\r\n console.error('[Firestore Document Get Error]', error);\r\n return { success: false, data: null, error };\r\n });\r\n }\r\n\r\n /**\r\n * Fetch document once — same path as {@link listenToDocument}.\r\n *\r\n * await:\r\n * const res = await firestoreData.getDocument<Job>(path);\r\n *\r\n * .then:\r\n * firestoreData.getDocument<Job>(path).then(res => { ... });\r\n */\r\n public async getDocument$<T>(pathSegments: string[]): Promise<FirestoreResponse<T | null>> {\r\n try {\r\n const snapshot = await runInInjectionContext(this.injector, () => {\r\n const ref = doc(this.firestore, pathSegments[0], ...pathSegments.slice(1));\r\n return getDoc(ref);\r\n });\r\n return {\r\n success: true,\r\n data: snapshot.exists() ? (snapshot.data() as T) : null,\r\n error: null,\r\n };\r\n } catch (error: unknown) {\r\n console.error('[Firestore Document Get Error]', error);\r\n return { success: false, data: null, error };\r\n }\r\n }\r\n\r\n /**\r\n * Listen realtime document changes\r\n */\r\n public listenToDocument<T>(pathSegments: string[]): Observable<FirestoreResponse<T>> {\r\n return runInInjectionContext(this.injector, () => {\r\n const documentRef = doc(this.firestore, pathSegments[0], ...pathSegments.slice(1));\r\n return docData(documentRef);\r\n }).pipe(\r\n // Cast the response to the expected type\r\n filter((response) => response != null),\r\n // Return the response\r\n map((response) => ({ success: true, data: response, error: null })),\r\n // Handle errors\r\n catchError((error: unknown) => {\r\n console.error('[Firestore Document Listener Error]', error);\r\n return of({ success: false, data: null, error });\r\n })\r\n\r\n );\r\n }\r\n\r\n /**\r\n * Listen realtime collection changes\r\n */\r\n public listenToCollection<T>(collectionPath: string[]): Observable<FirestoreResponse<T[]>> {\r\n return runInInjectionContext(this.injector, () => {\r\n const collectionRef = collection(this.firestore, collectionPath[0], ...collectionPath.slice(1));\r\n return collectionChanges(collectionRef);\r\n }).pipe(\r\n // Cast the response to the expected type\r\n map((response) => ({ success: true, data: response, error: null })),\r\n // Handle errors\r\n catchError((error: unknown) => {\r\n console.error('[Firestore Collection Listener Error]', error);\r\n return of({ success: false, data: null, error });\r\n })\r\n );\r\n }\r\n}","import { EnvironmentProviders, makeEnvironmentProviders } from '@angular/core';\r\nimport { initializeApp, provideFirebaseApp } from '@angular/fire/app';\r\nimport { getFirestore, provideFirestore } from '@angular/fire/firestore';\r\n\r\n/**\r\n * Custom library provider that configures and initializes Firebase and Firestore \r\n * behind the scenes for the consuming application.\r\n */\r\nexport function provideFirestoreKit(firebaseConfig: any): EnvironmentProviders {\r\n return makeEnvironmentProviders([\r\n // The library handles the Angular Fire initialization boilerplate internally\r\n provideFirebaseApp(() => initializeApp(firebaseConfig)),\r\n provideFirestore(() => getFirestore())\r\n ]);\r\n}","/*\r\n * Public API Surface of ngx-firestore-kit\r\n */\r\n\r\nexport * from './lib/ngx-firestore-kit';\r\nexport * from './lib/service/firestore-data.service';\r\nexport * from './lib/service/firestore-providers';","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;MAYa,eAAe,CAAA;wGAAf,eAAe,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA;AAAf,IAAA,OAAA,IAAA,GAAA,EAAA,CAAA,oBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,IAAA,EAAA,eAAe,EAAA,YAAA,EAAA,IAAA,EAAA,QAAA,EAAA,uBAAA,EAAA,QAAA,EAAA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AU,EAAE;AACf,iBAAA;;;ACTD;;;AAGG;AACG,SAAU,mBAAmB,CAAC,cAAmB,EAAA;AACnD,IAAA,OAAO,wBAAwB,CAAC;;QAE5B,kBAAkB,CAAC,MAAM,aAAa,CAAC,cAAc,CAAC,CAAC;AACvD,QAAA,gBAAgB,CAAC,MAAM,YAAY,EAAE;AACxC,KAAA,CAAC;AACN;;ACdA;;AAEG;;ACFH;;AAEG;;;;"}
|
package/index.d.ts
CHANGED
|
@@ -15,6 +15,27 @@ interface FirestoreResponse<T> {
|
|
|
15
15
|
declare class FirestoreDataService {
|
|
16
16
|
private readonly firestore;
|
|
17
17
|
private readonly injector;
|
|
18
|
+
/**
|
|
19
|
+
* Fetch document once — same path as {@link listenToDocument}.
|
|
20
|
+
*
|
|
21
|
+
* await:
|
|
22
|
+
* const res = await firestoreData.getDocument<Job>(path);
|
|
23
|
+
*
|
|
24
|
+
* .then:
|
|
25
|
+
* firestoreData.getDocument<Job>(path).then(res => { ... });
|
|
26
|
+
*/
|
|
27
|
+
/** Promise API: use with `.then()` or `await`. */
|
|
28
|
+
getDocument<T>(pathSegments: string[]): Promise<FirestoreResponse<T | null>>;
|
|
29
|
+
/**
|
|
30
|
+
* Fetch document once — same path as {@link listenToDocument}.
|
|
31
|
+
*
|
|
32
|
+
* await:
|
|
33
|
+
* const res = await firestoreData.getDocument<Job>(path);
|
|
34
|
+
*
|
|
35
|
+
* .then:
|
|
36
|
+
* firestoreData.getDocument<Job>(path).then(res => { ... });
|
|
37
|
+
*/
|
|
38
|
+
getDocument$<T>(pathSegments: string[]): Promise<FirestoreResponse<T | null>>;
|
|
18
39
|
/**
|
|
19
40
|
* Listen realtime document changes
|
|
20
41
|
*/
|
package/package.json
CHANGED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import * as i0 from '@angular/core';
|
|
2
|
-
import { Component, inject, Injector, runInInjectionContext, Injectable, makeEnvironmentProviders } from '@angular/core';
|
|
3
|
-
import { Firestore, doc, docData, collection, collectionChanges, provideFirestore, getFirestore } from '@angular/fire/firestore';
|
|
4
|
-
import { of } from 'rxjs';
|
|
5
|
-
import { filter, map, catchError } from 'rxjs/operators';
|
|
6
|
-
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
|
|
7
|
-
|
|
8
|
-
class NgxFirestoreKit {
|
|
9
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.23", ngImport: i0, type: NgxFirestoreKit, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
10
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.23", type: NgxFirestoreKit, isStandalone: true, selector: "lib-ngx-firestore-kit", ngImport: i0, template: `
|
|
11
|
-
<p>
|
|
12
|
-
ngx-firestore-kit works!
|
|
13
|
-
</p>
|
|
14
|
-
`, isInline: true, styles: [""] });
|
|
15
|
-
}
|
|
16
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.23", ngImport: i0, type: NgxFirestoreKit, decorators: [{
|
|
17
|
-
type: Component,
|
|
18
|
-
args: [{ selector: 'lib-ngx-firestore-kit', imports: [], template: `
|
|
19
|
-
<p>
|
|
20
|
-
ngx-firestore-kit works!
|
|
21
|
-
</p>
|
|
22
|
-
` }]
|
|
23
|
-
}] });
|
|
24
|
-
|
|
25
|
-
class FirestoreDataService {
|
|
26
|
-
firestore = inject(Firestore);
|
|
27
|
-
injector = inject(Injector);
|
|
28
|
-
/**
|
|
29
|
-
* Listen realtime document changes
|
|
30
|
-
*/
|
|
31
|
-
listenToDocument(pathSegments) {
|
|
32
|
-
const documentRef = doc(this.firestore, pathSegments[0], ...pathSegments.slice(1));
|
|
33
|
-
return runInInjectionContext(this.injector, () => docData(documentRef)).pipe(
|
|
34
|
-
// Cast the response to the expected type
|
|
35
|
-
filter((response) => response != null),
|
|
36
|
-
// Return the response
|
|
37
|
-
map((response) => ({ success: true, data: response, error: null })),
|
|
38
|
-
// Handle errors
|
|
39
|
-
catchError((error) => {
|
|
40
|
-
console.error('[Firestore Document Listener Error]', error);
|
|
41
|
-
return of({ success: false, data: null, error });
|
|
42
|
-
}));
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Listen realtime collection changes
|
|
46
|
-
*/
|
|
47
|
-
listenToCollection(collectionPath) {
|
|
48
|
-
const collectionRef = collection(this.firestore, collectionPath[0], ...collectionPath.slice(1));
|
|
49
|
-
return runInInjectionContext(this.injector, () => collectionChanges(collectionRef)).pipe(
|
|
50
|
-
// Cast the response to the expected type
|
|
51
|
-
map((response) => ({ success: true, data: response, error: null })),
|
|
52
|
-
// Handle errors
|
|
53
|
-
catchError((error) => {
|
|
54
|
-
console.error('[Firestore Collection Listener Error]', error);
|
|
55
|
-
return of({ success: false, data: null, error });
|
|
56
|
-
}));
|
|
57
|
-
}
|
|
58
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.23", ngImport: i0, type: FirestoreDataService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
59
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.23", ngImport: i0, type: FirestoreDataService, providedIn: 'root' });
|
|
60
|
-
}
|
|
61
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.23", ngImport: i0, type: FirestoreDataService, decorators: [{
|
|
62
|
-
type: Injectable,
|
|
63
|
-
args: [{
|
|
64
|
-
providedIn: 'root'
|
|
65
|
-
}]
|
|
66
|
-
}] });
|
|
67
|
-
|
|
68
|
-
class FirestorePaths {
|
|
69
|
-
static CLIENTS_COLLECTION = 'clients';
|
|
70
|
-
static BATCH_JOBS_COLLECTION = 'batchJobs';
|
|
71
|
-
static getBatchJobDocumentPath(clientId, batchJobDocumentId) {
|
|
72
|
-
return [
|
|
73
|
-
FirestorePaths.CLIENTS_COLLECTION,
|
|
74
|
-
clientId,
|
|
75
|
-
FirestorePaths.BATCH_JOBS_COLLECTION,
|
|
76
|
-
batchJobDocumentId
|
|
77
|
-
];
|
|
78
|
-
}
|
|
79
|
-
static getBatchJobCollectionPath(clientId) {
|
|
80
|
-
return [
|
|
81
|
-
FirestorePaths.CLIENTS_COLLECTION,
|
|
82
|
-
clientId,
|
|
83
|
-
FirestorePaths.BATCH_JOBS_COLLECTION
|
|
84
|
-
];
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Custom library provider that configures and initializes Firebase and Firestore
|
|
90
|
-
* behind the scenes for the consuming application.
|
|
91
|
-
*/
|
|
92
|
-
function provideFirestoreKit(firebaseConfig) {
|
|
93
|
-
return makeEnvironmentProviders([
|
|
94
|
-
// The library handles the Angular Fire initialization boilerplate internally
|
|
95
|
-
provideFirebaseApp(() => initializeApp(firebaseConfig)),
|
|
96
|
-
provideFirestore(() => getFirestore())
|
|
97
|
-
]);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/*
|
|
101
|
-
* Public API Surface of ngx-firestore-kit
|
|
102
|
-
*/
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Generated bundle index. Do not edit.
|
|
106
|
-
*/
|
|
107
|
-
|
|
108
|
-
export { FirestoreDataService, FirestorePaths, NgxFirestoreKit, provideFirestoreKit };
|
|
109
|
-
//# sourceMappingURL=goc-ngx-firestore-kit.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"goc-ngx-firestore-kit.mjs","sources":["../../../projects/ngx-firestore-kit/src/lib/ngx-firestore-kit.ts","../../../projects/ngx-firestore-kit/src/lib/service/firestore-data.service.ts","../../../projects/ngx-firestore-kit/src/lib/service/firestore-paths.ts","../../../projects/ngx-firestore-kit/src/lib/service/firestore-providers.ts","../../../projects/ngx-firestore-kit/src/public-api.ts","../../../projects/ngx-firestore-kit/src/goc-ngx-firestore-kit.ts"],"sourcesContent":["import { Component } from '@angular/core';\r\n\r\n@Component({\r\n selector: 'lib-ngx-firestore-kit',\r\n imports: [],\r\n template: `\r\n <p>\r\n ngx-firestore-kit works!\r\n </p>\r\n `,\r\n styles: ``,\r\n})\r\nexport class NgxFirestoreKit {\r\n\r\n}\r\n","import { Injectable, Injector, inject, runInInjectionContext } from '@angular/core';\r\nimport { Firestore, collection, collectionChanges, doc, docData } from '@angular/fire/firestore';\r\nimport { Observable, of } from 'rxjs';\r\nimport { catchError, filter, map } from 'rxjs/operators';\r\n\r\nexport interface FirestoreResponse<T> {\r\n success: boolean;\r\n data: any;\r\n error: unknown;\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root'\r\n})\r\n\r\nexport class FirestoreDataService {\r\n\r\n private readonly firestore = inject(Firestore);\r\n private readonly injector = inject(Injector);\r\n\r\n /**\r\n * Listen realtime document changes\r\n */\r\n public listenToDocument<T>(pathSegments: string[]): Observable<FirestoreResponse<T>> {\r\n const documentRef = doc(this.firestore, pathSegments[0], ...pathSegments.slice(1));\r\n return runInInjectionContext(this.injector, () => docData(documentRef)).pipe(\r\n // Cast the response to the expected type\r\n filter((response) => response != null),\r\n // Return the response\r\n map((response) => ({ success: true, data: response, error: null })),\r\n // Handle errors\r\n catchError((error: unknown) => {\r\n console.error('[Firestore Document Listener Error]', error);\r\n return of({ success: false, data: null, error });\r\n })\r\n\r\n );\r\n }\r\n\r\n /**\r\n * Listen realtime collection changes\r\n */\r\n public listenToCollection<T>(collectionPath: string[]): Observable<FirestoreResponse<T[]>> {\r\n const collectionRef = collection(this.firestore, collectionPath[0], ...collectionPath.slice(1));\r\n return runInInjectionContext(this.injector, () => collectionChanges(collectionRef)).pipe(\r\n // Cast the response to the expected type\r\n map((response) => ({ success: true, data: response, error: null })),\r\n // Handle errors\r\n catchError((error: unknown) => {\r\n console.error('[Firestore Collection Listener Error]', error);\r\n return of({ success: false, data: null, error });\r\n })\r\n );\r\n }\r\n}","export class FirestorePaths {\r\n\r\n public static readonly CLIENTS_COLLECTION = 'clients';\r\n public static readonly BATCH_JOBS_COLLECTION = 'batchJobs';\r\n\r\n public static getBatchJobDocumentPath(clientId: string, batchJobDocumentId: string): string[] {\r\n return [\r\n FirestorePaths.CLIENTS_COLLECTION,\r\n clientId,\r\n FirestorePaths.BATCH_JOBS_COLLECTION,\r\n batchJobDocumentId\r\n ];\r\n }\r\n\r\n public static getBatchJobCollectionPath(clientId: string): string[] {\r\n return [\r\n FirestorePaths.CLIENTS_COLLECTION,\r\n clientId,\r\n FirestorePaths.BATCH_JOBS_COLLECTION\r\n ];\r\n }\r\n\r\n}\r\n","import { EnvironmentProviders, makeEnvironmentProviders } from '@angular/core';\r\nimport { initializeApp, provideFirebaseApp } from '@angular/fire/app';\r\nimport { getFirestore, provideFirestore } from '@angular/fire/firestore';\r\n\r\n/**\r\n * Custom library provider that configures and initializes Firebase and Firestore \r\n * behind the scenes for the consuming application.\r\n */\r\nexport function provideFirestoreKit(firebaseConfig: any): EnvironmentProviders {\r\n return makeEnvironmentProviders([\r\n // The library handles the Angular Fire initialization boilerplate internally\r\n provideFirebaseApp(() => initializeApp(firebaseConfig)),\r\n provideFirestore(() => getFirestore())\r\n ]);\r\n}","/*\r\n * Public API Surface of ngx-firestore-kit\r\n */\r\n\r\nexport * from './lib/ngx-firestore-kit';\r\nexport * from './lib/service/firestore-data.service';\r\nexport * from './lib/service/firestore-paths';\r\nexport * from './lib/service/firestore-providers';","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;MAYa,eAAe,CAAA;wGAAf,eAAe,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA;AAAf,IAAA,OAAA,IAAA,GAAA,EAAA,CAAA,oBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,IAAA,EAAA,eAAe,EAAA,YAAA,EAAA,IAAA,EAAA,QAAA,EAAA,uBAAA,EAAA,QAAA,EAAA,EAAA,EAAA,Q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yBAAyB,CAAC,QAAgB,EAAA;QACpD,OAAO;AACH,YAAA,cAAc,CAAC,kBAAkB;YACjC,QAAQ;AACR,YAAA,cAAc,CAAC;SAClB;IACL;;;AChBJ;;;AAGG;AACG,SAAU,mBAAmB,CAAC,cAAmB,EAAA;AACnD,IAAA,OAAO,wBAAwB,CAAC;;QAE5B,kBAAkB,CAAC,MAAM,aAAa,CAAC,cAAc,CAAC,CAAC;AACvD,QAAA,gBAAgB,CAAC,MAAM,YAAY,EAAE;AACxC,KAAA,CAAC;AACN;;ACdA;;AAEG;;ACFH;;AAEG;;;;"}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import * as i0 from '@angular/core';
|
|
2
|
-
import { Component, inject, Injector, runInInjectionContext, Injectable, makeEnvironmentProviders } from '@angular/core';
|
|
3
|
-
import { Firestore, doc, docData, collection, collectionChanges, provideFirestore, getFirestore } from '@angular/fire/firestore';
|
|
4
|
-
import { of } from 'rxjs';
|
|
5
|
-
import { filter, map, catchError } from 'rxjs/operators';
|
|
6
|
-
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
|
|
7
|
-
|
|
8
|
-
class NgxFirestoreKit {
|
|
9
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.23", ngImport: i0, type: NgxFirestoreKit, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
10
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.23", type: NgxFirestoreKit, isStandalone: true, selector: "lib-ngx-firestore-kit", ngImport: i0, template: `
|
|
11
|
-
<p>
|
|
12
|
-
ngx-firestore-kit works!
|
|
13
|
-
</p>
|
|
14
|
-
`, isInline: true, styles: [""] });
|
|
15
|
-
}
|
|
16
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.23", ngImport: i0, type: NgxFirestoreKit, decorators: [{
|
|
17
|
-
type: Component,
|
|
18
|
-
args: [{ selector: 'lib-ngx-firestore-kit', imports: [], template: `
|
|
19
|
-
<p>
|
|
20
|
-
ngx-firestore-kit works!
|
|
21
|
-
</p>
|
|
22
|
-
` }]
|
|
23
|
-
}] });
|
|
24
|
-
|
|
25
|
-
class FirestoreDataService {
|
|
26
|
-
firestore = inject(Firestore);
|
|
27
|
-
injector = inject(Injector);
|
|
28
|
-
/**
|
|
29
|
-
* Listen realtime document changes
|
|
30
|
-
*/
|
|
31
|
-
listenToDocument(pathSegments) {
|
|
32
|
-
const documentRef = doc(this.firestore, pathSegments[0], ...pathSegments.slice(1));
|
|
33
|
-
return runInInjectionContext(this.injector, () => docData(documentRef)).pipe(
|
|
34
|
-
// Cast the response to the expected type
|
|
35
|
-
filter((response) => response != null),
|
|
36
|
-
// Return the response
|
|
37
|
-
map((response) => ({ success: true, data: response, error: null })),
|
|
38
|
-
// Handle errors
|
|
39
|
-
catchError((error) => {
|
|
40
|
-
console.error('[Firestore Document Listener Error]', error);
|
|
41
|
-
return of({ success: false, data: null, error });
|
|
42
|
-
}));
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Listen realtime collection changes
|
|
46
|
-
*/
|
|
47
|
-
listenToCollection(collectionPath) {
|
|
48
|
-
const collectionRef = collection(this.firestore, collectionPath[0], ...collectionPath.slice(1));
|
|
49
|
-
return runInInjectionContext(this.injector, () => collectionChanges(collectionRef)).pipe(
|
|
50
|
-
// Cast the response to the expected type
|
|
51
|
-
map((response) => ({ success: true, data: response, error: null })),
|
|
52
|
-
// Handle errors
|
|
53
|
-
catchError((error) => {
|
|
54
|
-
console.error('[Firestore Collection Listener Error]', error);
|
|
55
|
-
return of({ success: false, data: null, error });
|
|
56
|
-
}));
|
|
57
|
-
}
|
|
58
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.23", ngImport: i0, type: FirestoreDataService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
59
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.23", ngImport: i0, type: FirestoreDataService, providedIn: 'root' });
|
|
60
|
-
}
|
|
61
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.23", ngImport: i0, type: FirestoreDataService, decorators: [{
|
|
62
|
-
type: Injectable,
|
|
63
|
-
args: [{
|
|
64
|
-
providedIn: 'root'
|
|
65
|
-
}]
|
|
66
|
-
}] });
|
|
67
|
-
|
|
68
|
-
class FirestorePaths {
|
|
69
|
-
static CLIENTS_COLLECTION = 'clients';
|
|
70
|
-
static BATCH_JOBS_COLLECTION = 'batchJobs';
|
|
71
|
-
static getBatchJobDocumentPath(clientId, batchJobDocumentId) {
|
|
72
|
-
return [
|
|
73
|
-
FirestorePaths.CLIENTS_COLLECTION,
|
|
74
|
-
clientId,
|
|
75
|
-
FirestorePaths.BATCH_JOBS_COLLECTION,
|
|
76
|
-
batchJobDocumentId
|
|
77
|
-
];
|
|
78
|
-
}
|
|
79
|
-
static getBatchJobCollectionPath(clientId) {
|
|
80
|
-
return [
|
|
81
|
-
FirestorePaths.CLIENTS_COLLECTION,
|
|
82
|
-
clientId,
|
|
83
|
-
FirestorePaths.BATCH_JOBS_COLLECTION
|
|
84
|
-
];
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Custom library provider that configures and initializes Firebase and Firestore
|
|
90
|
-
* behind the scenes for the consuming application.
|
|
91
|
-
*/
|
|
92
|
-
function provideFirestoreKit(firebaseConfig) {
|
|
93
|
-
return makeEnvironmentProviders([
|
|
94
|
-
// The library handles the Angular Fire initialization boilerplate internally
|
|
95
|
-
provideFirebaseApp(() => initializeApp(firebaseConfig)),
|
|
96
|
-
provideFirestore(() => getFirestore())
|
|
97
|
-
]);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/*
|
|
101
|
-
* Public API Surface of ngx-firestore-kit
|
|
102
|
-
*/
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Generated bundle index. Do not edit.
|
|
106
|
-
*/
|
|
107
|
-
|
|
108
|
-
export { FirestoreDataService, FirestorePaths, NgxFirestoreKit, provideFirestoreKit };
|
|
109
|
-
//# sourceMappingURL=goc-ngx-firestore-wrapper-kit.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"goc-ngx-firestore-wrapper-kit.mjs","sources":["../../../projects/ngx-firestore-kit/src/lib/ngx-firestore-kit.ts","../../../projects/ngx-firestore-kit/src/lib/service/firestore-data.service.ts","../../../projects/ngx-firestore-kit/src/lib/service/firestore-paths.ts","../../../projects/ngx-firestore-kit/src/lib/service/firestore-providers.ts","../../../projects/ngx-firestore-kit/src/public-api.ts","../../../projects/ngx-firestore-kit/src/goc-ngx-firestore-wrapper-kit.ts"],"sourcesContent":["import { Component } from '@angular/core';\r\n\r\n@Component({\r\n selector: 'lib-ngx-firestore-kit',\r\n imports: [],\r\n template: `\r\n <p>\r\n ngx-firestore-kit works!\r\n </p>\r\n `,\r\n styles: ``,\r\n})\r\nexport class NgxFirestoreKit {\r\n\r\n}\r\n","import { Injectable, Injector, inject, runInInjectionContext } from '@angular/core';\r\nimport { Firestore, collection, collectionChanges, doc, docData } from '@angular/fire/firestore';\r\nimport { Observable, of } from 'rxjs';\r\nimport { catchError, filter, map } from 'rxjs/operators';\r\n\r\nexport interface FirestoreResponse<T> {\r\n success: boolean;\r\n data: any;\r\n error: unknown;\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root'\r\n})\r\n\r\nexport class FirestoreDataService {\r\n\r\n private readonly firestore = inject(Firestore);\r\n private readonly injector = inject(Injector);\r\n\r\n /**\r\n * Listen realtime document changes\r\n */\r\n public listenToDocument<T>(pathSegments: string[]): Observable<FirestoreResponse<T>> {\r\n const documentRef = doc(this.firestore, pathSegments[0], ...pathSegments.slice(1));\r\n return runInInjectionContext(this.injector, () => docData(documentRef)).pipe(\r\n // Cast the response to the expected type\r\n filter((response) => response != null),\r\n // Return the response\r\n map((response) => ({ success: true, data: response, error: null })),\r\n // Handle errors\r\n catchError((error: unknown) => {\r\n console.error('[Firestore Document Listener Error]', error);\r\n return of({ success: false, data: null, error });\r\n })\r\n\r\n );\r\n }\r\n\r\n /**\r\n * Listen realtime collection changes\r\n */\r\n public listenToCollection<T>(collectionPath: string[]): Observable<FirestoreResponse<T[]>> {\r\n const collectionRef = collection(this.firestore, collectionPath[0], ...collectionPath.slice(1));\r\n return runInInjectionContext(this.injector, () => collectionChanges(collectionRef)).pipe(\r\n // Cast the response to the expected type\r\n map((response) => ({ success: true, data: response, error: null })),\r\n // Handle errors\r\n catchError((error: unknown) => {\r\n console.error('[Firestore Collection Listener Error]', error);\r\n return of({ success: false, data: null, error });\r\n })\r\n );\r\n }\r\n}","export class FirestorePaths {\r\n\r\n public static readonly CLIENTS_COLLECTION = 'clients';\r\n public static readonly BATCH_JOBS_COLLECTION = 'batchJobs';\r\n\r\n public static getBatchJobDocumentPath(clientId: string, batchJobDocumentId: string): string[] {\r\n return [\r\n FirestorePaths.CLIENTS_COLLECTION,\r\n clientId,\r\n FirestorePaths.BATCH_JOBS_COLLECTION,\r\n batchJobDocumentId\r\n ];\r\n }\r\n\r\n public static getBatchJobCollectionPath(clientId: string): string[] {\r\n return [\r\n FirestorePaths.CLIENTS_COLLECTION,\r\n clientId,\r\n FirestorePaths.BATCH_JOBS_COLLECTION\r\n ];\r\n }\r\n\r\n}\r\n","import { EnvironmentProviders, makeEnvironmentProviders } from '@angular/core';\r\nimport { initializeApp, provideFirebaseApp } from '@angular/fire/app';\r\nimport { getFirestore, provideFirestore } from '@angular/fire/firestore';\r\n\r\n/**\r\n * Custom library provider that configures and initializes Firebase and Firestore \r\n * behind the scenes for the consuming application.\r\n */\r\nexport function provideFirestoreKit(firebaseConfig: any): EnvironmentProviders {\r\n return makeEnvironmentProviders([\r\n // The library handles the Angular Fire initialization boilerplate internally\r\n provideFirebaseApp(() => initializeApp(firebaseConfig)),\r\n provideFirestore(() => getFirestore())\r\n ]);\r\n}","/*\r\n * Public API Surface of ngx-firestore-kit\r\n */\r\n\r\nexport * from './lib/ngx-firestore-kit';\r\nexport * from './lib/service/firestore-data.service';\r\nexport * from './lib/service/firestore-paths';\r\nexport * from './lib/service/firestore-providers';","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;MAYa,eAAe,CAAA;wGAAf,eAAe,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA;AAAf,IAAA,OAAA,IAAA,GAAA,EAAA,CAAA,oBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,IAAA,EAAA,eAAe,EAAA,YAAA,EAAA,IAAA,EAAA,QAAA,EAAA,uBAAA,EAAA,QAAA,EAAA,EAAA,EAAA,QAAA,EAPhB,CAAA;;;;AAIT,EAAA,CAAA,EAAA,QAAA,EAAA,IAAA,EAAA,MAAA,EAAA,CAAA,EAAA,CAAA,EAAA,CAAA;;4FAGU,eAAe,EAAA,UAAA,EAAA,CAAA;kBAV3B,SAAS;+BACE,uBAAuB,EAAA,OAAA,EACxB,EAAE,EAAA,QAAA,EACD,CAAA;;;;AAIT,EAAA,CAAA,EAAA;;;MCMU,oBAAoB,CAAA;AAEZ,IAAA,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;AAC7B,IAAA,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;AAE5C;;AAEG;AACI,IAAA,gBAAgB,CAAI,YAAsB,EAAA;QAC7C,MAAM,WAAW,GAAG,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAClF,QAAA,OAAO,qBAAqB,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI;;QAExE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AAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,oBAAoB,cAHjB,MAAM,EAAA,CAAA;;4FAGT,oBAAoB,EAAA,UAAA,EAAA,CAAA;kBAJhC,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,UAAU,EAAE;AACf,iBAAA;;;MCbY,cAAc,CAAA;AAEhB,IAAA,OAAgB,kBAAkB,GAAG,SAAS;AAC9C,IAAA,OAAgB,qBAAqB,GAAG,WAAW;AAEnD,IAAA,OAAO,uBAAuB,CAAC,QAAgB,EAAE,kBAA0B,EAAA;QAC9E,OAAO;AACH,YAAA,cAAc,CAAC,kBAAkB;YACjC,QAAQ;AACR,YAAA,cAAc,CAAC,qBAAqB;YACpC;SACH;IACL;IAEO,OAAO,yBAAyB,CAAC,QAAgB,EAAA;QACpD,OAAO;AACH,YAAA,cAAc,CAAC,kBAAkB;YACjC,QAAQ;AACR,YAAA,cAAc,CAAC;SAClB;IACL;;;AChBJ;;;AAGG;AACG,SAAU,mBAAmB,CAAC,cAAmB,EAAA;AACnD,IAAA,OAAO,wBAAwB,CAAC;;QAE5B,kBAAkB,CAAC,MAAM,aAAa,CAAC,cAAc,CAAC,CAAC;AACvD,QAAA,gBAAgB,CAAC,MAAM,YAAY,EAAE;AACxC,KAAA,CAAC;AACN;;ACdA;;AAEG;;ACFH;;AAEG;;;;"}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import * as i0 from '@angular/core';
|
|
2
|
-
import { Component, inject, Injector, runInInjectionContext, Injectable, makeEnvironmentProviders } from '@angular/core';
|
|
3
|
-
import { Firestore, doc, docData, collection, collectionChanges, provideFirestore, getFirestore } from '@angular/fire/firestore';
|
|
4
|
-
import { of } from 'rxjs';
|
|
5
|
-
import { filter, map, catchError } from 'rxjs/operators';
|
|
6
|
-
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
|
|
7
|
-
|
|
8
|
-
class NgxFirestoreKit {
|
|
9
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.23", ngImport: i0, type: NgxFirestoreKit, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
10
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.23", type: NgxFirestoreKit, isStandalone: true, selector: "lib-ngx-firestore-kit", ngImport: i0, template: `
|
|
11
|
-
<p>
|
|
12
|
-
ngx-firestore-kit works!
|
|
13
|
-
</p>
|
|
14
|
-
`, isInline: true, styles: [""] });
|
|
15
|
-
}
|
|
16
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.23", ngImport: i0, type: NgxFirestoreKit, decorators: [{
|
|
17
|
-
type: Component,
|
|
18
|
-
args: [{ selector: 'lib-ngx-firestore-kit', imports: [], template: `
|
|
19
|
-
<p>
|
|
20
|
-
ngx-firestore-kit works!
|
|
21
|
-
</p>
|
|
22
|
-
` }]
|
|
23
|
-
}] });
|
|
24
|
-
|
|
25
|
-
class FirestoreDataService {
|
|
26
|
-
firestore = inject(Firestore);
|
|
27
|
-
injector = inject(Injector);
|
|
28
|
-
/**
|
|
29
|
-
* Listen realtime document changes
|
|
30
|
-
*/
|
|
31
|
-
listenToDocument(pathSegments) {
|
|
32
|
-
const documentRef = doc(this.firestore, pathSegments[0], ...pathSegments.slice(1));
|
|
33
|
-
return runInInjectionContext(this.injector, () => docData(documentRef)).pipe(
|
|
34
|
-
// Cast the response to the expected type
|
|
35
|
-
filter((response) => response != null),
|
|
36
|
-
// Return the response
|
|
37
|
-
map((response) => ({ success: true, data: response, error: null })),
|
|
38
|
-
// Handle errors
|
|
39
|
-
catchError((error) => {
|
|
40
|
-
console.error('[Firestore Document Listener Error]', error);
|
|
41
|
-
return of({ success: false, data: null, error });
|
|
42
|
-
}));
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Listen realtime collection changes
|
|
46
|
-
*/
|
|
47
|
-
listenToCollection(collectionPath) {
|
|
48
|
-
const collectionRef = collection(this.firestore, collectionPath[0], ...collectionPath.slice(1));
|
|
49
|
-
return runInInjectionContext(this.injector, () => collectionChanges(collectionRef)).pipe(
|
|
50
|
-
// Cast the response to the expected type
|
|
51
|
-
map((response) => ({ success: true, data: response, error: null })),
|
|
52
|
-
// Handle errors
|
|
53
|
-
catchError((error) => {
|
|
54
|
-
console.error('[Firestore Collection Listener Error]', error);
|
|
55
|
-
return of({ success: false, data: null, error });
|
|
56
|
-
}));
|
|
57
|
-
}
|
|
58
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.23", ngImport: i0, type: FirestoreDataService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
59
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.23", ngImport: i0, type: FirestoreDataService, providedIn: 'root' });
|
|
60
|
-
}
|
|
61
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.23", ngImport: i0, type: FirestoreDataService, decorators: [{
|
|
62
|
-
type: Injectable,
|
|
63
|
-
args: [{
|
|
64
|
-
providedIn: 'root'
|
|
65
|
-
}]
|
|
66
|
-
}] });
|
|
67
|
-
|
|
68
|
-
class FirestorePaths {
|
|
69
|
-
static CLIENTS_COLLECTION = 'clients';
|
|
70
|
-
static BATCH_JOBS_COLLECTION = 'batchJobs';
|
|
71
|
-
static getBatchJobDocumentPath(clientId, batchJobDocumentId) {
|
|
72
|
-
return [
|
|
73
|
-
FirestorePaths.CLIENTS_COLLECTION,
|
|
74
|
-
clientId,
|
|
75
|
-
FirestorePaths.BATCH_JOBS_COLLECTION,
|
|
76
|
-
batchJobDocumentId
|
|
77
|
-
];
|
|
78
|
-
}
|
|
79
|
-
static getBatchJobCollectionPath(clientId) {
|
|
80
|
-
return [
|
|
81
|
-
FirestorePaths.CLIENTS_COLLECTION,
|
|
82
|
-
clientId,
|
|
83
|
-
FirestorePaths.BATCH_JOBS_COLLECTION
|
|
84
|
-
];
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Custom library provider that configures and initializes Firebase and Firestore
|
|
90
|
-
* behind the scenes for the consuming application.
|
|
91
|
-
*/
|
|
92
|
-
function provideFirestoreKit(firebaseConfig) {
|
|
93
|
-
return makeEnvironmentProviders([
|
|
94
|
-
// The library handles the Angular Fire initialization boilerplate internally
|
|
95
|
-
provideFirebaseApp(() => initializeApp(firebaseConfig)),
|
|
96
|
-
provideFirestore(() => getFirestore())
|
|
97
|
-
]);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/*
|
|
101
|
-
* Public API Surface of ngx-firestore-kit
|
|
102
|
-
*/
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Generated bundle index. Do not edit.
|
|
106
|
-
*/
|
|
107
|
-
|
|
108
|
-
export { FirestoreDataService, FirestorePaths, NgxFirestoreKit, provideFirestoreKit };
|
|
109
|
-
//# sourceMappingURL=ngx-firestore-kit.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ngx-firestore-kit.mjs","sources":["../../../projects/ngx-firestore-kit/src/lib/ngx-firestore-kit.ts","../../../projects/ngx-firestore-kit/src/lib/service/firestore-data.service.ts","../../../projects/ngx-firestore-kit/src/lib/service/firestore-paths.ts","../../../projects/ngx-firestore-kit/src/lib/service/firestore-providers.ts","../../../projects/ngx-firestore-kit/src/public-api.ts","../../../projects/ngx-firestore-kit/src/ngx-firestore-kit.ts"],"sourcesContent":["import { Component } from '@angular/core';\r\n\r\n@Component({\r\n selector: 'lib-ngx-firestore-kit',\r\n imports: [],\r\n template: `\r\n <p>\r\n ngx-firestore-kit works!\r\n </p>\r\n `,\r\n styles: ``,\r\n})\r\nexport class NgxFirestoreKit {\r\n\r\n}\r\n","import { Injectable, Injector, inject, runInInjectionContext } from '@angular/core';\r\nimport { Firestore, collection, collectionChanges, doc, docData } from '@angular/fire/firestore';\r\nimport { Observable, of } from 'rxjs';\r\nimport { catchError, filter, map } from 'rxjs/operators';\r\n\r\nexport interface FirestoreResponse<T> {\r\n success: boolean;\r\n data: any;\r\n error: unknown;\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root'\r\n})\r\n\r\nexport class FirestoreDataService {\r\n\r\n private readonly firestore = inject(Firestore);\r\n private readonly injector = inject(Injector);\r\n\r\n /**\r\n * Listen realtime document changes\r\n */\r\n public listenToDocument<T>(pathSegments: string[]): Observable<FirestoreResponse<T>> {\r\n const documentRef = doc(this.firestore, pathSegments[0], ...pathSegments.slice(1));\r\n return runInInjectionContext(this.injector, () => docData(documentRef)).pipe(\r\n // Cast the response to the expected type\r\n filter((response) => response != null),\r\n // Return the response\r\n map((response) => ({ success: true, data: response, error: null })),\r\n // Handle errors\r\n catchError((error: unknown) => {\r\n console.error('[Firestore Document Listener Error]', error);\r\n return of({ success: false, data: null, error });\r\n })\r\n\r\n );\r\n }\r\n\r\n /**\r\n * Listen realtime collection changes\r\n */\r\n public listenToCollection<T>(collectionPath: string[]): Observable<FirestoreResponse<T[]>> {\r\n const collectionRef = collection(this.firestore, collectionPath[0], ...collectionPath.slice(1));\r\n return runInInjectionContext(this.injector, () => collectionChanges(collectionRef)).pipe(\r\n // Cast the response to the expected type\r\n map((response) => ({ success: true, data: response, error: null })),\r\n // Handle errors\r\n catchError((error: unknown) => {\r\n console.error('[Firestore Collection Listener Error]', error);\r\n return of({ success: false, data: null, error });\r\n })\r\n );\r\n }\r\n}","export class FirestorePaths {\r\n\r\n public static readonly CLIENTS_COLLECTION = 'clients';\r\n public static readonly BATCH_JOBS_COLLECTION = 'batchJobs';\r\n\r\n public static getBatchJobDocumentPath(clientId: string, batchJobDocumentId: string): string[] {\r\n return [\r\n FirestorePaths.CLIENTS_COLLECTION,\r\n clientId,\r\n FirestorePaths.BATCH_JOBS_COLLECTION,\r\n batchJobDocumentId\r\n ];\r\n }\r\n\r\n public static getBatchJobCollectionPath(clientId: string): string[] {\r\n return [\r\n FirestorePaths.CLIENTS_COLLECTION,\r\n clientId,\r\n FirestorePaths.BATCH_JOBS_COLLECTION\r\n ];\r\n }\r\n\r\n}\r\n","import { EnvironmentProviders, makeEnvironmentProviders } from '@angular/core';\r\nimport { initializeApp, provideFirebaseApp } from '@angular/fire/app';\r\nimport { getFirestore, provideFirestore } from '@angular/fire/firestore';\r\n\r\n/**\r\n * Custom library provider that configures and initializes Firebase and Firestore \r\n * behind the scenes for the consuming application.\r\n */\r\nexport function provideFirestoreKit(firebaseConfig: any): EnvironmentProviders {\r\n return makeEnvironmentProviders([\r\n // The library handles the Angular Fire initialization boilerplate internally\r\n provideFirebaseApp(() => initializeApp(firebaseConfig)),\r\n provideFirestore(() => getFirestore())\r\n ]);\r\n}","/*\r\n * Public API Surface of ngx-firestore-kit\r\n */\r\n\r\nexport * from './lib/ngx-firestore-kit';\r\nexport * from './lib/service/firestore-data.service';\r\nexport * from './lib/service/firestore-paths';\r\nexport * from './lib/service/firestore-providers';","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;MAYa,eAAe,CAAA;wGAAf,eAAe,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA;AAAf,IAAA,OAAA,IAAA,GAAA,EAAA,CAAA,oBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,IAAA,EAAA,eAAe,EAAA,YAAA,EAAA,IAAA,EAAA,QAAA,EAAA,uBAAA,EAAA,QAAA,EAAA,EAAA,EAAA,QAAA,EAPhB,CAAA;;;;AAIT,EAAA,CAAA,EAAA,QAAA,EAAA,IAAA,EAAA,MAAA,EAAA,CAAA,EAAA,CAAA,EAAA,CAAA;;4FAGU,eAAe,EAAA,UAAA,EAAA,CAAA;kBAV3B,SA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