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.
Files changed (2) hide show
  1. package/README.md +214 -34
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,63 +1,243 @@
1
- # NgxFirestoreKit
1
+ # ngx-firestore-wrapper-kit — Integration Guide
2
2
 
3
- This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 20.3.0.
3
+ Steps to install, configure, and use this library in an Angular application.
4
4
 
5
- ## Code scaffolding
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
- Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
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
- ng generate component component-name
40
+ npm install ngx-firestore-wrapper-kit
11
41
  ```
12
42
 
13
- For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
43
+ ---
14
44
 
15
- ```bash
16
- ng generate --help
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
- ## Building
67
+ Get these values from [Firebase Console](https://console.firebase.google.com/) → **Project settings** → **Your apps** → Web app config.
20
68
 
21
- To build the library, run:
69
+ ---
22
70
 
23
- ```bash
24
- ng build ngx-firestore-kit
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
- This command will compile your project, and the build artifacts will be placed in the `dist/` directory.
89
+ ---
28
90
 
29
- ### Publishing the Library
91
+ <a id="4-usage"></a>
30
92
 
31
- Once the project is built, you can publish your library by following these steps:
93
+ ## 4. Usage
32
94
 
33
- 1. Navigate to the `dist` directory:
34
- ```bash
35
- cd dist/ngx-firestore-kit
36
- ```
95
+ Import from the package:
37
96
 
38
- 2. Run the `npm publish` command to publish your library to the npm registry:
39
- ```bash
40
- npm publish
41
- ```
97
+ ```typescript
98
+ import {
99
+ FirestoreDataService,
100
+ FirestorePaths,
101
+ FirestoreResponse
102
+ } from 'ngx-firestore-wrapper-kit';
103
+ ```
42
104
 
43
- ## Running unit tests
105
+ Inject `FirestoreDataService` where you need Firestore data. It is `providedIn: 'root'`, so no extra providers are required.
44
106
 
45
- To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
107
+ <a id="response-shape"></a>
46
108
 
47
- ```bash
48
- ng test
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
- ## Running end-to-end tests
121
+ Always check `success` before using `data`.
52
122
 
53
- For end-to-end (e2e) testing, run:
123
+ ---
54
124
 
55
- ```bash
56
- ng e2e
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
- Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
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
- ## Additional Resources
236
+ ## Exports reference
62
237
 
63
- For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
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 |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ngx-firestore-wrapper-kit",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "peerDependencies": {
5
5
  "@angular/common": "^20.3.0",
6
6
  "@angular/core": "^20.3.0"