ngx-firestore-wrapper-kit 0.0.3 → 0.0.5
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/README.md
CHANGED
|
@@ -97,7 +97,6 @@ Import from the package:
|
|
|
97
97
|
```typescript
|
|
98
98
|
import {
|
|
99
99
|
FirestoreDataService,
|
|
100
|
-
FirestorePaths,
|
|
101
100
|
FirestoreResponse
|
|
102
101
|
} from 'ngx-firestore-wrapper-kit';
|
|
103
102
|
```
|
|
@@ -129,7 +128,7 @@ Always check `success` before using `data`.
|
|
|
129
128
|
```typescript
|
|
130
129
|
import { inject, OnDestroy, OnInit } from '@angular/core';
|
|
131
130
|
import { Subscription } from 'rxjs';
|
|
132
|
-
import { FirestoreDataService,
|
|
131
|
+
import { FirestoreDataService, FirestoreResponse } from 'ngx-firestore-wrapper-kit';
|
|
133
132
|
|
|
134
133
|
interface BatchJob {
|
|
135
134
|
status: string;
|
|
@@ -143,7 +142,8 @@ export class BatchJobComponent implements OnInit, OnDestroy {
|
|
|
143
142
|
response: FirestoreResponse<BatchJob> | null = null;
|
|
144
143
|
|
|
145
144
|
ngOnInit(): void {
|
|
146
|
-
|
|
145
|
+
// collection / collection-001 (document) / subCollection / sub-collection-001 (document)
|
|
146
|
+
const path = ['collection', 'collection-001', 'subCollection', 'sub-collection-001'];
|
|
147
147
|
|
|
148
148
|
this.sub = this.firestoreData
|
|
149
149
|
.listenToDocument<BatchJob>(path)
|
|
@@ -165,7 +165,7 @@ export class BatchJobComponent implements OnInit, OnDestroy {
|
|
|
165
165
|
```typescript
|
|
166
166
|
import { inject, OnDestroy, OnInit } from '@angular/core';
|
|
167
167
|
import { Subscription } from 'rxjs';
|
|
168
|
-
import { FirestoreDataService,
|
|
168
|
+
import { FirestoreDataService, FirestoreResponse } from 'ngx-firestore-wrapper-kit';
|
|
169
169
|
|
|
170
170
|
interface BatchJob {
|
|
171
171
|
status: string;
|
|
@@ -179,7 +179,8 @@ export class BatchJobListComponent implements OnInit, OnDestroy {
|
|
|
179
179
|
response: FirestoreResponse<BatchJob[]> | null = null;
|
|
180
180
|
|
|
181
181
|
ngOnInit(): void {
|
|
182
|
-
|
|
182
|
+
// collection / collection-001 (document) / subCollection
|
|
183
|
+
const path = ['collection', 'collection-001', 'subCollection'];
|
|
183
184
|
|
|
184
185
|
this.sub = this.firestoreData
|
|
185
186
|
.listenToCollection<BatchJob>(path)
|
|
@@ -201,11 +202,11 @@ export class BatchJobListComponent implements OnInit, OnDestroy {
|
|
|
201
202
|
Build paths as **string arrays** — alternating collection and document IDs:
|
|
202
203
|
|
|
203
204
|
```typescript
|
|
204
|
-
// Document: collection/{collectionId}/
|
|
205
|
-
const documentPath = ['collection', 'collection-001', '
|
|
205
|
+
// Document: collection / {collectionId} (document) / subCollection / {subCollectionId} (document)
|
|
206
|
+
const documentPath = ['collection', 'collection-001', 'subCollection', 'sub-collection-001'];
|
|
206
207
|
|
|
207
|
-
// Collection: collection/{collectionId}/
|
|
208
|
-
const collectionPath = ['collection', 'collection-001', '
|
|
208
|
+
// Collection: collection / {collectionId} (document) / subCollection
|
|
209
|
+
const collectionPath = ['collection', 'collection-001', 'subCollection'];
|
|
209
210
|
```
|
|
210
211
|
|
|
211
212
|
**Example with the service:**
|
|
@@ -239,5 +240,4 @@ this.firestoreData
|
|
|
239
240
|
|--------|-----|
|
|
240
241
|
| `provideFirestoreKit(config)` | Bootstrap Firebase + Firestore in the app |
|
|
241
242
|
| `FirestoreDataService` | `listenToDocument()`, `listenToCollection()` |
|
|
242
|
-
| `FirestorePaths` | Static path segment helpers |
|
|
243
243
|
| `FirestoreResponse<T>` | Type for listener responses |
|
|
@@ -29,8 +29,10 @@ class FirestoreDataService {
|
|
|
29
29
|
* Listen realtime document changes
|
|
30
30
|
*/
|
|
31
31
|
listenToDocument(pathSegments) {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
return runInInjectionContext(this.injector, () => {
|
|
33
|
+
const documentRef = doc(this.firestore, pathSegments[0], ...pathSegments.slice(1));
|
|
34
|
+
return docData(documentRef);
|
|
35
|
+
}).pipe(
|
|
34
36
|
// Cast the response to the expected type
|
|
35
37
|
filter((response) => response != null),
|
|
36
38
|
// Return the response
|
|
@@ -45,8 +47,10 @@ class FirestoreDataService {
|
|
|
45
47
|
* Listen realtime collection changes
|
|
46
48
|
*/
|
|
47
49
|
listenToCollection(collectionPath) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
return runInInjectionContext(this.injector, () => {
|
|
51
|
+
const collectionRef = collection(this.firestore, collectionPath[0], ...collectionPath.slice(1));
|
|
52
|
+
return collectionChanges(collectionRef);
|
|
53
|
+
}).pipe(
|
|
50
54
|
// Cast the response to the expected type
|
|
51
55
|
map((response) => ({ success: true, data: response, error: null })),
|
|
52
56
|
// Handle errors
|
|
@@ -65,26 +69,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.23", ngImpo
|
|
|
65
69
|
}]
|
|
66
70
|
}] });
|
|
67
71
|
|
|
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
72
|
/**
|
|
89
73
|
* Custom library provider that configures and initializes Firebase and Firestore
|
|
90
74
|
* behind the scenes for the consuming application.
|
|
@@ -105,5 +89,5 @@ function provideFirestoreKit(firebaseConfig) {
|
|
|
105
89
|
* Generated bundle index. Do not edit.
|
|
106
90
|
*/
|
|
107
91
|
|
|
108
|
-
export { FirestoreDataService,
|
|
92
|
+
export { FirestoreDataService, NgxFirestoreKit, provideFirestoreKit };
|
|
109
93
|
//# sourceMappingURL=ngx-firestore-wrapper-kit.mjs.map
|
|
@@ -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-
|
|
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\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HjB,MAAM,EAAA,CAAA;;4FAGT,oBAAoB,EAAA,UAAA,EAAA,CAAA;kBAJhC,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,UAAU,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
|
@@ -27,18 +27,11 @@ declare class FirestoreDataService {
|
|
|
27
27
|
static ɵprov: i0.ɵɵInjectableDeclaration<FirestoreDataService>;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
declare class FirestorePaths {
|
|
31
|
-
static readonly CLIENTS_COLLECTION = "clients";
|
|
32
|
-
static readonly BATCH_JOBS_COLLECTION = "batchJobs";
|
|
33
|
-
static getBatchJobDocumentPath(clientId: string, batchJobDocumentId: string): string[];
|
|
34
|
-
static getBatchJobCollectionPath(clientId: string): string[];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
30
|
/**
|
|
38
31
|
* Custom library provider that configures and initializes Firebase and Firestore
|
|
39
32
|
* behind the scenes for the consuming application.
|
|
40
33
|
*/
|
|
41
34
|
declare function provideFirestoreKit(firebaseConfig: any): EnvironmentProviders;
|
|
42
35
|
|
|
43
|
-
export { FirestoreDataService,
|
|
36
|
+
export { FirestoreDataService, NgxFirestoreKit, provideFirestoreKit };
|
|
44
37
|
export type { FirestoreResponse };
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ngx-firestore-wrapper-kit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@angular/common": "^20.3.0",
|
|
6
|
-
"@angular/core": "^20.3.0"
|
|
6
|
+
"@angular/core": "^20.3.0",
|
|
7
|
+
"@angular/fire": "^20.0.1",
|
|
8
|
+
"firebase": "^11.10.0"
|
|
7
9
|
},
|
|
8
10
|
"dependencies": {
|
|
9
11
|
"tslib": "^2.3.0"
|