ngx-firestore-wrapper-kit 0.0.1 → 0.0.3
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 +214 -34
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,63 +1,243 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ngx-firestore-wrapper-kit — Integration Guide
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Steps to install, configure, and use this library in an Angular application.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
<p style="font-size: 1.15rem; line-height: 1.6;"><strong>Requirements:</strong> Angular ^20.3.0, a Firebase project with Firestore enabled.</p>
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
<div style="background: #f6f8fa; border: 1px solid #d0d7de; border-left: 4px solid #0969da; border-radius: 8px; padding: 1rem 1.25rem; margin: 1rem 0; font-size: 1rem; line-height: 1.6;">
|
|
8
|
+
|
|
9
|
+
<p style="font-size: 1.05rem; font-weight: 600; margin: 0 0 0.75rem; padding-bottom: 0.5rem; border-bottom: 1px solid #d8dee4;">On this page</p>
|
|
10
|
+
|
|
11
|
+
<ul style="margin: 0; padding-left: 1.25rem;">
|
|
12
|
+
<li style="margin-bottom: 0.35rem;"><a href="#1-install" style="color: #0969da; text-decoration: none;">1. Install</a></li>
|
|
13
|
+
<li style="margin-bottom: 0.35rem;"><a href="#2-firebase-configuration" style="color: #0969da; text-decoration: none;">2. Firebase configuration</a></li>
|
|
14
|
+
<li style="margin-bottom: 0.35rem;"><a href="#3-register-the-library-in-your-app" style="color: #0969da; text-decoration: none;">3. Register the library in your app</a></li>
|
|
15
|
+
<li style="margin-bottom: 0.35rem;"><a href="#4-usage" style="color: #0969da; text-decoration: none;">4. Usage</a></li>
|
|
16
|
+
<li style="margin-bottom: 0.35rem;"><a href="#5-checklist" style="color: #0969da; text-decoration: none;">5. Checklist</a></li>
|
|
17
|
+
<li style="margin-bottom: 0.35rem;"><a href="#exports-reference" style="color: #0969da; text-decoration: none;">Exports reference</a></li>
|
|
18
|
+
</ul>
|
|
19
|
+
|
|
20
|
+
<p style="font-size: 0.95rem; font-weight: 600; margin: 1rem 0 0.5rem; color: #57606a;">Usage sections</p>
|
|
21
|
+
|
|
22
|
+
<ul style="margin: 0; padding-left: 1.25rem;">
|
|
23
|
+
<li style="margin-bottom: 0.35rem;"><a href="#response-shape" style="color: #0969da; text-decoration: none;">Response shape</a></li>
|
|
24
|
+
<li style="margin-bottom: 0.35rem;"><a href="#listen-to-a-document-real-time" style="color: #0969da; text-decoration: none;">Listen to a document (real-time)</a></li>
|
|
25
|
+
<li style="margin-bottom: 0.35rem;"><a href="#listen-to-a-collection-real-time" style="color: #0969da; text-decoration: none;">Listen to a collection (real-time)</a></li>
|
|
26
|
+
<li style="margin-bottom: 0.35rem;"><a href="#path-helpers" style="color: #0969da; text-decoration: none;">Path helpers</a></li>
|
|
27
|
+
</ul>
|
|
28
|
+
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
<a id="1-install"></a>
|
|
34
|
+
|
|
35
|
+
## 1. Install
|
|
36
|
+
|
|
37
|
+
### From npm
|
|
8
38
|
|
|
9
39
|
```bash
|
|
10
|
-
|
|
40
|
+
npm install ngx-firestore-wrapper-kit
|
|
11
41
|
```
|
|
12
42
|
|
|
13
|
-
|
|
43
|
+
---
|
|
14
44
|
|
|
15
|
-
|
|
16
|
-
|
|
45
|
+
<a id="2-firebase-configuration"></a>
|
|
46
|
+
|
|
47
|
+
## 2. Firebase configuration
|
|
48
|
+
|
|
49
|
+
Add the Firebase config to your environment file (`src/environments/environment.ts`):
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { FirebaseOptions } from '@angular/fire/app';
|
|
53
|
+
|
|
54
|
+
export const environment = {
|
|
55
|
+
production: false,
|
|
56
|
+
firebaseConfig: {
|
|
57
|
+
apiKey: 'YOUR_API_KEY',
|
|
58
|
+
authDomain: 'YOUR_PROJECT.firebaseapp.com',
|
|
59
|
+
projectId: 'YOUR_PROJECT_ID',
|
|
60
|
+
storageBucket: 'YOUR_PROJECT.appspot.com',
|
|
61
|
+
messagingSenderId: 'YOUR_SENDER_ID',
|
|
62
|
+
appId: 'YOUR_APP_ID'
|
|
63
|
+
} as FirebaseOptions
|
|
64
|
+
};
|
|
17
65
|
```
|
|
18
66
|
|
|
19
|
-
|
|
67
|
+
Get these values from [Firebase Console](https://console.firebase.google.com/) → **Project settings** → **Your apps** → Web app config.
|
|
20
68
|
|
|
21
|
-
|
|
69
|
+
---
|
|
22
70
|
|
|
23
|
-
|
|
24
|
-
|
|
71
|
+
<a id="3-register-the-library-in-your-app"></a>
|
|
72
|
+
|
|
73
|
+
## 3. Register the library in your app
|
|
74
|
+
|
|
75
|
+
**`app.config.ts`:**
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import { ApplicationConfig } from '@angular/core';
|
|
79
|
+
import { provideFirestoreKit } from 'ngx-firestore-wrapper-kit';
|
|
80
|
+
import { environment } from './environments/environment';
|
|
81
|
+
|
|
82
|
+
export const appConfig: ApplicationConfig = {
|
|
83
|
+
providers: [
|
|
84
|
+
provideFirestoreKit(environment.firebaseConfig)
|
|
85
|
+
]
|
|
86
|
+
};
|
|
25
87
|
```
|
|
26
88
|
|
|
27
|
-
|
|
89
|
+
---
|
|
28
90
|
|
|
29
|
-
|
|
91
|
+
<a id="4-usage"></a>
|
|
30
92
|
|
|
31
|
-
|
|
93
|
+
## 4. Usage
|
|
32
94
|
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
cd dist/ngx-firestore-kit
|
|
36
|
-
```
|
|
95
|
+
Import from the package:
|
|
37
96
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
97
|
+
```typescript
|
|
98
|
+
import {
|
|
99
|
+
FirestoreDataService,
|
|
100
|
+
FirestorePaths,
|
|
101
|
+
FirestoreResponse
|
|
102
|
+
} from 'ngx-firestore-wrapper-kit';
|
|
103
|
+
```
|
|
42
104
|
|
|
43
|
-
|
|
105
|
+
Inject `FirestoreDataService` where you need Firestore data. It is `providedIn: 'root'`, so no extra providers are required.
|
|
44
106
|
|
|
45
|
-
|
|
107
|
+
<a id="response-shape"></a>
|
|
46
108
|
|
|
47
|
-
|
|
48
|
-
|
|
109
|
+
### Response shape
|
|
110
|
+
|
|
111
|
+
All listener methods return `Observable<FirestoreResponse<T>>`:
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
interface FirestoreResponse<T> {
|
|
115
|
+
success: boolean;
|
|
116
|
+
data: any; // payload when success is true
|
|
117
|
+
error: unknown; // error when success is false
|
|
118
|
+
}
|
|
49
119
|
```
|
|
50
120
|
|
|
51
|
-
|
|
121
|
+
Always check `success` before using `data`.
|
|
52
122
|
|
|
53
|
-
|
|
123
|
+
---
|
|
54
124
|
|
|
55
|
-
|
|
56
|
-
|
|
125
|
+
<a id="listen-to-a-document-real-time"></a>
|
|
126
|
+
|
|
127
|
+
### Listen to a document (real-time)
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import { inject, OnDestroy, OnInit } from '@angular/core';
|
|
131
|
+
import { Subscription } from 'rxjs';
|
|
132
|
+
import { FirestoreDataService, FirestorePaths, FirestoreResponse } from 'ngx-firestore-wrapper-kit';
|
|
133
|
+
|
|
134
|
+
interface BatchJob {
|
|
135
|
+
status: string;
|
|
136
|
+
progress: number;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export class BatchJobComponent implements OnInit, OnDestroy {
|
|
140
|
+
private readonly firestoreData = inject(FirestoreDataService);
|
|
141
|
+
private sub?: Subscription;
|
|
142
|
+
|
|
143
|
+
response: FirestoreResponse<BatchJob> | null = null;
|
|
144
|
+
|
|
145
|
+
ngOnInit(): void {
|
|
146
|
+
const path = FirestorePaths.getBatchJobDocumentPath('client-001', 'job-001');
|
|
147
|
+
|
|
148
|
+
this.sub = this.firestoreData
|
|
149
|
+
.listenToDocument<BatchJob>(path)
|
|
150
|
+
.subscribe((res) => (this.response = res));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
ngOnDestroy(): void {
|
|
154
|
+
this.sub?.unsubscribe();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
57
157
|
```
|
|
58
158
|
|
|
59
|
-
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
<a id="listen-to-a-collection-real-time"></a>
|
|
162
|
+
|
|
163
|
+
### Listen to a collection (real-time)
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
import { inject, OnDestroy, OnInit } from '@angular/core';
|
|
167
|
+
import { Subscription } from 'rxjs';
|
|
168
|
+
import { FirestoreDataService, FirestorePaths, FirestoreResponse } from 'ngx-firestore-wrapper-kit';
|
|
169
|
+
|
|
170
|
+
interface BatchJob {
|
|
171
|
+
status: string;
|
|
172
|
+
progress: number;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export class BatchJobListComponent implements OnInit, OnDestroy {
|
|
176
|
+
private readonly firestoreData = inject(FirestoreDataService);
|
|
177
|
+
private sub?: Subscription;
|
|
178
|
+
|
|
179
|
+
response: FirestoreResponse<BatchJob[]> | null = null;
|
|
180
|
+
|
|
181
|
+
ngOnInit(): void {
|
|
182
|
+
const path = FirestorePaths.getBatchJobCollectionPath('client-001');
|
|
183
|
+
|
|
184
|
+
this.sub = this.firestoreData
|
|
185
|
+
.listenToCollection<BatchJob>(path)
|
|
186
|
+
.subscribe((res) => (this.response = res));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
ngOnDestroy(): void {
|
|
190
|
+
this.sub?.unsubscribe();
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
<a id="path-helpers"></a>
|
|
198
|
+
|
|
199
|
+
### Path helpers
|
|
200
|
+
|
|
201
|
+
Build paths as **string arrays** — alternating collection and document IDs:
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
// Document: collection/{collectionId}/childCollection/{childCollectionDocumentId}
|
|
205
|
+
const documentPath = ['collection', 'collection-001', 'childCollection', 'child-collection-001'];
|
|
206
|
+
|
|
207
|
+
// Collection: collection/{collectionId}/childCollection
|
|
208
|
+
const collectionPath = ['collection', 'collection-001', 'childCollection'];
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
**Example with the service:**
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
this.firestoreData
|
|
215
|
+
.listenToDocument<ChildDocument>(documentPath)
|
|
216
|
+
.subscribe((res) => { /* ... */ });
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
<a id="5-checklist"></a>
|
|
222
|
+
|
|
223
|
+
## 5. Checklist
|
|
224
|
+
|
|
225
|
+
- [ ] `ngx-firestore-wrapper-kit` installed
|
|
226
|
+
- [ ] Firebase config added to `environment.ts`
|
|
227
|
+
- [ ] `provideFirestoreKit(environment.firebaseConfig)` in root providers
|
|
228
|
+
- [ ] `FirestoreDataService` injected in components/services
|
|
229
|
+
- [ ] Paths passed as `string[]`
|
|
230
|
+
- [ ] Subscriptions unsubscribed in `ngOnDestroy` (or use `async` pipe)
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
<a id="exports-reference"></a>
|
|
60
235
|
|
|
61
|
-
##
|
|
236
|
+
## Exports reference
|
|
62
237
|
|
|
63
|
-
|
|
238
|
+
| Export | Use |
|
|
239
|
+
|--------|-----|
|
|
240
|
+
| `provideFirestoreKit(config)` | Bootstrap Firebase + Firestore in the app |
|
|
241
|
+
| `FirestoreDataService` | `listenToDocument()`, `listenToCollection()` |
|
|
242
|
+
| `FirestorePaths` | Static path segment helpers |
|
|
243
|
+
| `FirestoreResponse<T>` | Type for listener responses |
|