ngx-firestore-wrapper-kit 0.0.1 → 0.0.2
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 +317 -34
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,63 +1,346 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ngx-firestore-wrapper-kit — Integration Guide
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<style>
|
|
4
|
+
.guide-header {
|
|
5
|
+
max-width: 960px;
|
|
6
|
+
margin: 0 auto 1.5rem;
|
|
7
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
8
|
+
line-height: 1.6;
|
|
9
|
+
color: #24292f;
|
|
10
|
+
}
|
|
4
11
|
|
|
5
|
-
|
|
12
|
+
.guide-intro {
|
|
13
|
+
margin: 0 0 1rem;
|
|
14
|
+
color: #57606a;
|
|
15
|
+
}
|
|
6
16
|
|
|
7
|
-
|
|
17
|
+
.guide-requirements {
|
|
18
|
+
background: #fff8e6;
|
|
19
|
+
border-left: 4px solid #d4a72c;
|
|
20
|
+
border-radius: 0 6px 6px 0;
|
|
21
|
+
padding: 0.75rem 1rem;
|
|
22
|
+
margin: 0 0 1.25rem;
|
|
23
|
+
font-size: 0.95rem;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.guide-nav {
|
|
27
|
+
background: #f6f8fa;
|
|
28
|
+
border: 1px solid #d0d7de;
|
|
29
|
+
border-left: 4px solid #0969da;
|
|
30
|
+
border-radius: 8px;
|
|
31
|
+
padding: 1rem 1.25rem;
|
|
32
|
+
margin: 0 0 1.5rem;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.guide-nav-title {
|
|
36
|
+
margin: 0 0 0.85rem;
|
|
37
|
+
padding-bottom: 0.65rem;
|
|
38
|
+
border-bottom: 1px solid #d8dee4;
|
|
39
|
+
font-size: 0.95rem;
|
|
40
|
+
font-weight: 600;
|
|
41
|
+
color: #24292f;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.guide-nav-grid {
|
|
45
|
+
display: grid;
|
|
46
|
+
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
|
47
|
+
gap: 0.25rem 1rem;
|
|
48
|
+
margin: 0;
|
|
49
|
+
padding: 0;
|
|
50
|
+
list-style: none;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.guide-nav-grid li {
|
|
54
|
+
margin: 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.guide-nav-grid a {
|
|
58
|
+
display: block;
|
|
59
|
+
padding: 0.4rem 0.5rem;
|
|
60
|
+
color: #0969da;
|
|
61
|
+
text-decoration: none;
|
|
62
|
+
font-size: 0.9rem;
|
|
63
|
+
border-radius: 4px;
|
|
64
|
+
transition: background 0.15s ease, color 0.15s ease;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.guide-nav-grid a:hover {
|
|
68
|
+
color: #0550ae;
|
|
69
|
+
background: #eef6ff;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.guide-nav-sub {
|
|
73
|
+
display: grid;
|
|
74
|
+
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
|
75
|
+
gap: 0.2rem 1rem;
|
|
76
|
+
margin: 0.75rem 0 0;
|
|
77
|
+
padding: 0.75rem 0 0;
|
|
78
|
+
border-top: 1px solid #d8dee4;
|
|
79
|
+
list-style: none;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.guide-nav-sub li {
|
|
83
|
+
margin: 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.guide-nav-sub a {
|
|
87
|
+
display: block;
|
|
88
|
+
padding: 0.35rem 0.5rem;
|
|
89
|
+
font-size: 0.85rem;
|
|
90
|
+
color: #57606a;
|
|
91
|
+
text-decoration: none;
|
|
92
|
+
border-radius: 4px;
|
|
93
|
+
transition: background 0.15s ease, color 0.15s ease;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.guide-nav-sub a:hover {
|
|
97
|
+
color: #0969da;
|
|
98
|
+
background: #eef6ff;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.guide-section {
|
|
102
|
+
scroll-margin-top: 1.5rem;
|
|
103
|
+
}
|
|
104
|
+
</style>
|
|
105
|
+
|
|
106
|
+
<div class="guide-header">
|
|
107
|
+
|
|
108
|
+
<p class="guide-intro">Steps to install, configure, and use this library in an Angular application.</p>
|
|
109
|
+
|
|
110
|
+
<div class="guide-requirements">
|
|
111
|
+
<strong>Requirements:</strong> Angular ^20.3.0, a Firebase project with Firestore enabled.
|
|
112
|
+
</div>
|
|
113
|
+
|
|
114
|
+
<nav class="guide-nav" aria-label="Table of contents">
|
|
115
|
+
<p class="guide-nav-title">On this page</p>
|
|
116
|
+
<ul class="guide-nav-grid">
|
|
117
|
+
<li><a href="#install">1. Install</a></li>
|
|
118
|
+
<li><a href="#firebase-configuration">2. Firebase configuration</a></li>
|
|
119
|
+
<li><a href="#register-the-library">3. Register the library</a></li>
|
|
120
|
+
<li><a href="#usage">4. Usage</a></li>
|
|
121
|
+
<li><a href="#checklist">5. Checklist</a></li>
|
|
122
|
+
<li><a href="#exports-reference">Exports reference</a></li>
|
|
123
|
+
</ul>
|
|
124
|
+
<ul class="guide-nav-sub">
|
|
125
|
+
<li><a href="#response-shape">↳ Response shape</a></li>
|
|
126
|
+
<li><a href="#listen-to-a-document">↳ Listen to a document</a></li>
|
|
127
|
+
<li><a href="#listen-to-a-collection">↳ Listen to a collection</a></li>
|
|
128
|
+
<li><a href="#path-helpers">↳ Path helpers</a></li>
|
|
129
|
+
</ul>
|
|
130
|
+
</nav>
|
|
131
|
+
|
|
132
|
+
</div>
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
<a id="install" class="guide-section"></a>
|
|
137
|
+
|
|
138
|
+
## 1. Install
|
|
139
|
+
|
|
140
|
+
### From npm
|
|
8
141
|
|
|
9
142
|
```bash
|
|
10
|
-
|
|
143
|
+
npm install ngx-firestore-wrapper-kit
|
|
11
144
|
```
|
|
12
145
|
|
|
13
|
-
|
|
146
|
+
---
|
|
14
147
|
|
|
15
|
-
|
|
16
|
-
|
|
148
|
+
<a id="firebase-configuration" class="guide-section"></a>
|
|
149
|
+
|
|
150
|
+
## 2. Firebase configuration
|
|
151
|
+
|
|
152
|
+
Add the Firebase config to your environment file (`src/environments/environment.ts`):
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
import { FirebaseOptions } from '@angular/fire/app';
|
|
156
|
+
|
|
157
|
+
export const environment = {
|
|
158
|
+
production: false,
|
|
159
|
+
firebaseConfig: {
|
|
160
|
+
apiKey: 'YOUR_API_KEY',
|
|
161
|
+
authDomain: 'YOUR_PROJECT.firebaseapp.com',
|
|
162
|
+
projectId: 'YOUR_PROJECT_ID',
|
|
163
|
+
storageBucket: 'YOUR_PROJECT.appspot.com',
|
|
164
|
+
messagingSenderId: 'YOUR_SENDER_ID',
|
|
165
|
+
appId: 'YOUR_APP_ID'
|
|
166
|
+
} as FirebaseOptions
|
|
167
|
+
};
|
|
17
168
|
```
|
|
18
169
|
|
|
19
|
-
|
|
170
|
+
Get these values from [Firebase Console](https://console.firebase.google.com/) → **Project settings** → **Your apps** → Web app config.
|
|
20
171
|
|
|
21
|
-
|
|
172
|
+
---
|
|
22
173
|
|
|
23
|
-
|
|
24
|
-
|
|
174
|
+
<a id="register-the-library" class="guide-section"></a>
|
|
175
|
+
|
|
176
|
+
## 3. Register the library in your app
|
|
177
|
+
|
|
178
|
+
**`app.config.ts`:**
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
import { ApplicationConfig } from '@angular/core';
|
|
182
|
+
import { provideFirestoreKit } from 'ngx-firestore-wrapper-kit';
|
|
183
|
+
import { environment } from './environments/environment';
|
|
184
|
+
|
|
185
|
+
export const appConfig: ApplicationConfig = {
|
|
186
|
+
providers: [
|
|
187
|
+
provideFirestoreKit(environment.firebaseConfig)
|
|
188
|
+
]
|
|
189
|
+
};
|
|
25
190
|
```
|
|
26
191
|
|
|
27
|
-
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
<a id="usage" class="guide-section"></a>
|
|
28
195
|
|
|
29
|
-
|
|
196
|
+
## 4. Usage
|
|
30
197
|
|
|
31
|
-
|
|
198
|
+
Import from the package:
|
|
32
199
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
200
|
+
```typescript
|
|
201
|
+
import {
|
|
202
|
+
FirestoreDataService,
|
|
203
|
+
FirestorePaths,
|
|
204
|
+
FirestoreResponse
|
|
205
|
+
} from 'ngx-firestore-wrapper-kit';
|
|
206
|
+
```
|
|
37
207
|
|
|
38
|
-
|
|
39
|
-
```bash
|
|
40
|
-
npm publish
|
|
41
|
-
```
|
|
208
|
+
Inject `FirestoreDataService` where you need Firestore data. It is `providedIn: 'root'`, so no extra providers are required.
|
|
42
209
|
|
|
43
|
-
|
|
210
|
+
<a id="response-shape" class="guide-section"></a>
|
|
44
211
|
|
|
45
|
-
|
|
212
|
+
### Response shape
|
|
46
213
|
|
|
47
|
-
|
|
48
|
-
|
|
214
|
+
All listener methods return `Observable<FirestoreResponse<T>>`:
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
interface FirestoreResponse<T> {
|
|
218
|
+
success: boolean;
|
|
219
|
+
data: any; // payload when success is true
|
|
220
|
+
error: unknown; // error when success is false
|
|
221
|
+
}
|
|
49
222
|
```
|
|
50
223
|
|
|
51
|
-
|
|
224
|
+
Always check `success` before using `data`.
|
|
52
225
|
|
|
53
|
-
|
|
226
|
+
---
|
|
54
227
|
|
|
55
|
-
|
|
56
|
-
|
|
228
|
+
<a id="listen-to-a-document" class="guide-section"></a>
|
|
229
|
+
|
|
230
|
+
### Listen to a document (real-time)
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
import { inject, OnDestroy, OnInit } from '@angular/core';
|
|
234
|
+
import { Subscription } from 'rxjs';
|
|
235
|
+
import { FirestoreDataService, FirestorePaths, FirestoreResponse } from 'ngx-firestore-wrapper-kit';
|
|
236
|
+
|
|
237
|
+
interface BatchJob {
|
|
238
|
+
status: string;
|
|
239
|
+
progress: number;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export class BatchJobComponent implements OnInit, OnDestroy {
|
|
243
|
+
private readonly firestoreData = inject(FirestoreDataService);
|
|
244
|
+
private sub?: Subscription;
|
|
245
|
+
|
|
246
|
+
response: FirestoreResponse<BatchJob> | null = null;
|
|
247
|
+
|
|
248
|
+
ngOnInit(): void {
|
|
249
|
+
const path = FirestorePaths.getBatchJobDocumentPath('client-001', 'job-001');
|
|
250
|
+
|
|
251
|
+
this.sub = this.firestoreData
|
|
252
|
+
.listenToDocument<BatchJob>(path)
|
|
253
|
+
.subscribe((res) => (this.response = res));
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
ngOnDestroy(): void {
|
|
257
|
+
this.sub?.unsubscribe();
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
<a id="listen-to-a-collection" class="guide-section"></a>
|
|
265
|
+
|
|
266
|
+
### Listen to a collection (real-time)
|
|
267
|
+
|
|
268
|
+
```typescript
|
|
269
|
+
import { inject, OnDestroy, OnInit } from '@angular/core';
|
|
270
|
+
import { Subscription } from 'rxjs';
|
|
271
|
+
import { FirestoreDataService, FirestorePaths, FirestoreResponse } from 'ngx-firestore-wrapper-kit';
|
|
272
|
+
|
|
273
|
+
interface BatchJob {
|
|
274
|
+
status: string;
|
|
275
|
+
progress: number;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export class BatchJobListComponent implements OnInit, OnDestroy {
|
|
279
|
+
private readonly firestoreData = inject(FirestoreDataService);
|
|
280
|
+
private sub?: Subscription;
|
|
281
|
+
|
|
282
|
+
response: FirestoreResponse<BatchJob[]> | null = null;
|
|
283
|
+
|
|
284
|
+
ngOnInit(): void {
|
|
285
|
+
const path = FirestorePaths.getBatchJobCollectionPath('client-001');
|
|
286
|
+
|
|
287
|
+
this.sub = this.firestoreData
|
|
288
|
+
.listenToCollection<BatchJob>(path)
|
|
289
|
+
.subscribe((res) => (this.response = res));
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
ngOnDestroy(): void {
|
|
293
|
+
this.sub?.unsubscribe();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
<a id="path-helpers" class="guide-section"></a>
|
|
301
|
+
|
|
302
|
+
### Path helpers
|
|
303
|
+
|
|
304
|
+
Build paths as **string arrays** — alternating collection and document IDs:
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
// Document: collection/{collectionId}/childCollection/{childCollectionDocumentId}
|
|
308
|
+
const documentPath = ['collection', 'collection-001', 'childCollection', 'child-collection-001'];
|
|
309
|
+
|
|
310
|
+
// Collection: collection/{collectionId}/childCollection
|
|
311
|
+
const collectionPath = ['collection', 'collection-001', 'childCollection'];
|
|
57
312
|
```
|
|
58
313
|
|
|
59
|
-
|
|
314
|
+
**Example with the service:**
|
|
315
|
+
|
|
316
|
+
```typescript
|
|
317
|
+
this.firestoreData
|
|
318
|
+
.listenToDocument<ChildDocument>(documentPath)
|
|
319
|
+
.subscribe((res) => { /* ... */ });
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
<a id="checklist" class="guide-section"></a>
|
|
325
|
+
|
|
326
|
+
## 5. Checklist
|
|
327
|
+
|
|
328
|
+
- [ ] `ngx-firestore-wrapper-kit` installed
|
|
329
|
+
- [ ] Firebase config added to `environment.ts`
|
|
330
|
+
- [ ] `provideFirestoreKit(environment.firebaseConfig)` in root providers
|
|
331
|
+
- [ ] `FirestoreDataService` injected in components/services
|
|
332
|
+
- [ ] Paths passed as `string[]`
|
|
333
|
+
- [ ] Subscriptions unsubscribed in `ngOnDestroy` (or use `async` pipe)
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
<a id="exports-reference" class="guide-section"></a>
|
|
60
338
|
|
|
61
|
-
##
|
|
339
|
+
## Exports reference
|
|
62
340
|
|
|
63
|
-
|
|
341
|
+
| Export | Use |
|
|
342
|
+
|--------|-----|
|
|
343
|
+
| `provideFirestoreKit(config)` | Bootstrap Firebase + Firestore in the app |
|
|
344
|
+
| `FirestoreDataService` | `listenToDocument()`, `listenToCollection()` |
|
|
345
|
+
| `FirestorePaths` | Static path segment helpers |
|
|
346
|
+
| `FirestoreResponse<T>` | Type for listener responses |
|