@jobsearch-works/firestore-models 1.0.33 → 1.1.0

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
@@ -1,332 +1,106 @@
1
1
  # firestore-models
2
2
 
3
- A shared library for standardizing Firestore document schemas and paths across multiple projects. This library provides:
3
+ A shared library for standardizing Firestore document schemas and paths across multiple projects.
4
4
 
5
- - Standardized document models and interfaces
6
- - Consistent path builders for Firestore collections and documents
7
- - Type-safe access to Firestore data
8
- - Shared validation and transformation utilities
5
+ This library provides:
9
6
 
10
- ## Purpose
7
+ - Type-safe Firestore document models
8
+ - Pure Firestore path string builders (SDK-free)
9
+ - Centralized schema definitions for use across apps
11
10
 
12
- This library serves as a single source of truth for Firestore data structures across different applications. By centralizing the schema definitions, it:
11
+ ---
13
12
 
14
- - Ensures consistency in data structure across projects
15
- - Reduces duplication of model definitions
16
- - Provides type safety when working with Firestore data
17
- - Makes it easier to maintain and update schemas across all applications
18
-
19
- ## Installation
20
-
21
- The package is published on npm as [@jobsearch-works/firestore-models](https://www.npmjs.com/package/@jobsearch-works/firestore-models).
22
-
23
- You can install it using npm:
13
+ ## đŸ“Ļ Installation
24
14
 
25
15
  ```bash
26
16
  npm install @jobsearch-works/firestore-models
27
17
  ```
28
18
 
29
- For development purposes, you can also install directly from GitHub:
19
+ For development:
30
20
 
31
21
  ```bash
32
- # Install from GitHub (for development only)
33
22
  npm install github:jobsearch-works/firestore-models
34
-
35
- # Or specify a particular commit/branch
36
- npm install github:jobsearch-works/firestore-models#commit-hash
37
- ```
38
-
39
- Note: Regular `npm update` won't update GitHub-hosted packages to the latest version. For production use, always use the npm package version.
40
-
41
- ## Project Structure
42
-
43
- ```
44
- firestore-models/
45
- ├── src/
46
- │ ├── models/ # All Firestore models
47
- │ │ ├── Application.ts
48
- │ │ ├── AuthUser.ts
49
- │ │ ├── Client.ts
50
- │ │ ├── ClientData.ts
51
- │ │ ├── ClientLogin.ts
52
- │ │ ├── Question.ts
53
- │ │ ├── UserQuestion.ts
54
- │ │ ├── Vacancy.ts
55
- │ │ └── VacancySuggestion.ts
56
- │ ├── BaseModel.ts # Base interface for all models
57
- │ └── index.ts # Main entry point
58
- ├── dist/ # Compiled output
59
- └── package.json
60
23
  ```
61
24
 
62
- ## Base Model
25
+ > â„šī¸ Prefer the npm version for production. GitHub installs don't update via `npm update`.
63
26
 
64
- All models extend from the BaseModel interface:
27
+ ---
65
28
 
66
- ```typescript
67
- interface BaseModel {
68
- id?: string; // Optional document ID
69
- createdAt?: Date | string; // Optional creation timestamp
70
- updatedAt?: Date | string; // Optional update timestamp
71
- }
72
- ```
73
-
74
- ## Models and Namespaces
75
-
76
- Each model is defined within its own namespace, which includes:
77
-
78
- - The model interface
79
- - Path builders for Firestore collections and documents
80
- - Utility functions for working with the model
81
-
82
- ### Client
29
+ ## đŸŽ¯ Purpose
83
30
 
84
- ```typescript
85
- namespace Client {
86
- interface Model extends BaseModel {
87
- name: string;
88
- email: string;
89
- status: "active" | "inactive";
90
- resume?: string;
91
- }
31
+ This package acts as a single source of truth for Firestore schema and paths, enabling:
92
32
 
93
- // Path builders
94
- const collection = () => "clients";
95
- const document = (clientId: string) => `clients/${clientId}`;
33
+ - Shared types across web apps, Node services, and Firebase functions
34
+ - Consistent Firestore path generation (no hardcoded strings)
35
+ - Cross-environment compatibility (e.g., CLI, testing, rules)
96
36
 
97
- // Utility functions
98
- const formatClient = (client: Client.Model): string;
99
- const createNew = (name: string, email: string): Client.Model;
100
- }
101
- ```
37
+ ---
102
38
 
103
- ### Application
104
-
105
- ```typescript
106
- namespace Application {
107
- interface Model extends BaseModel {
108
- vacancyId: string;
109
- clientId: string;
110
- status:
111
- | "new"
112
- | "submitted"
113
- | "interviewing"
114
- | "accepted"
115
- | "rejected"
116
- | "withdrawn"
117
- | "applying"
118
- | "suggested"
119
- | "approved";
120
- coverLetter?: string;
121
- resume?: string;
122
- // Denormalized fields from Vacancy
123
- company?: string;
124
- position?: string;
125
- location?: string;
126
- jobId?: string;
127
- advertisingUrl?: string;
128
- applicationUrl?: string;
129
- applicationDomain?: string;
130
- advertisingDomain?: string;
131
- description?: string;
132
- fullPageText?: string;
133
- }
134
-
135
- // Path builders
136
- const collection = (clientId: string) => `clients/${clientId}/applications`;
137
- const document = (clientId: string, applicationId: string) =>
138
- `clients/${clientId}/applications/${applicationId}`;
139
-
140
- // Utility functions
141
- const formatSummary = (application: Application.Model): string;
142
- const formatDate = (date: Date | string): string;
143
- const createNew = (
144
- clientId: string,
145
- vacancyId: string,
146
- vacancyData: Partial<Vacancy.Model>
147
- ): Application.Model;
148
- const updateStatus = (
149
- application: Application.Model,
150
- newStatus: Application.Model["status"]
151
- ): Application.Model;
152
- }
153
- ```
39
+ ## 🧱 Project Structure
154
40
 
155
- ### AuthUser
156
-
157
- ```typescript
158
- namespace AuthUser {
159
- interface Model extends BaseModel {
160
- email: string;
161
- displayName?: string;
162
- photoURL?: string;
163
- lastSignIn?: Date | string;
164
- emailVerified?: boolean;
165
- }
166
-
167
- // Path builders
168
- const collection = () => "users";
169
- const document = (userId: string) => `users/${userId}`;
170
-
171
- // Utility functions
172
- const fromFirebaseUser = (user: any): AuthUser.Model;
173
- const formatDates = (user: AuthUser.Model): Record<string, string>;
174
- const toFirestore = (user: AuthUser.Model): Record<string, any>;
175
- const fromFirestore = (data: Record<string, any>): AuthUser.Model;
176
- }
177
41
  ```
178
-
179
- ### Vacancy
180
-
181
- ```typescript
182
- namespace Vacancy {
183
- interface Model extends BaseModel {
184
- company: string;
185
- position: string;
186
- location: string;
187
- jobId: string;
188
- advertisingUrl: string;
189
- applicationUrl: string;
190
- applicationDomain: string;
191
- advertisingDomain: string;
192
- description: string;
193
- fullPageText: string;
194
- status: "active" | "inactive";
195
- }
196
-
197
- // Path builders
198
- const collection = () => "vacancies";
199
- const document = (vacancyId: string) => `vacancies/${vacancyId}`;
200
- }
201
- ```
202
-
203
- ### Question
204
-
205
- ```typescript
206
- namespace Question {
207
- interface Model extends BaseModel {
208
- text: string;
209
- type: "text" | "multiple_choice" | "single_choice";
210
- options?: string[];
211
- required: boolean;
212
- order: number;
213
- }
214
-
215
- // Path builders
216
- const collection = () => "questions";
217
- const document = (questionId: string) => `questions/${questionId}`;
218
- }
42
+ firestore-models/
43
+ ├── src/
44
+ │ ├── types/ # Pure Firestore interfaces (SDK-free)
45
+ │ ├── paths/ # Pure path string builders (SDK-free)
46
+ │ └── index.ts # Main exports (types + paths only)
47
+ ├── dist/ # Compiled output
48
+ └── package.json
219
49
  ```
220
50
 
221
- ### UserQuestion
222
-
223
- ```typescript
224
- namespace UserQuestion {
225
- interface Model extends BaseModel {
226
- clientId: string;
227
- questionId: string;
228
- answer: string;
229
- }
51
+ ---
230
52
 
231
- // Path builders
232
- const collection = (clientId: string) => `clients/${clientId}/questions`;
233
- const document = (clientId: string, questionId: string) =>
234
- `clients/${clientId}/questions/${questionId}`;
235
- }
236
- ```
53
+ ## ✅ Usage
237
54
 
238
- ### ClientData
55
+ ### Importing Models and Paths
239
56
 
240
- ```typescript
241
- namespace ClientData {
242
- interface Model extends BaseModel {
243
- clientId: string;
244
- key: string;
245
- value: any;
246
- }
57
+ ```ts
58
+ import { Client } from "@jobsearch-works/firestore-models/types/Client";
59
+ import { pathStrings } from "@jobsearch-works/firestore-models/paths/pathStrings";
247
60
 
248
- // Path builders
249
- const collection = (clientId: string) => `clients/${clientId}/data`;
250
- const document = (clientId: string, key: string) =>
251
- `clients/${clientId}/data/${key}`;
252
- }
61
+ const clientPath = pathStrings.client("abc123"); // → "clients/abc123"
253
62
  ```
254
63
 
255
- ### ClientLogin
64
+ ---
256
65
 
257
- ```typescript
258
- namespace ClientLogin {
259
- interface Model extends BaseModel {
260
- clientId: string;
261
- ipAddress: string;
262
- userAgent: string;
263
- }
66
+ ## 🔒 Type Definition Example
264
67
 
265
- // Path builders
266
- const collection = (clientId: string) => `clients/${clientId}/logins`;
267
- const document = (clientId: string, loginId: string) =>
268
- `clients/${clientId}/logins/${loginId}`;
68
+ ```ts
69
+ // types/Client.ts
70
+ export interface Client {
71
+ id?: string;
72
+ name: string;
73
+ email: string;
74
+ status: "active" | "inactive";
75
+ createdAt?: Date | string;
269
76
  }
270
77
  ```
271
78
 
272
- ### VacancySuggestion
79
+ ---
273
80
 
274
- ```typescript
275
- namespace VacancySuggestion {
276
- interface Model extends BaseModel {
277
- clientId: string;
278
- vacancyId: string;
279
- status: "pending" | "accepted" | "rejected";
280
- }
81
+ ## 🔗 Path Builder Example
281
82
 
282
- // Path builders
283
- const collection = (clientId: string) => `clients/${clientId}/suggestions`;
284
- const document = (clientId: string, suggestionId: string) =>
285
- `clients/${clientId}/suggestions/${suggestionId}`;
286
- }
83
+ ```ts
84
+ // paths/pathStrings.ts
85
+ export const pathStrings = {
86
+ clients: () => "clients",
87
+ client: (clientId: string) => `clients/${clientId}`,
88
+ } as const;
287
89
  ```
288
90
 
289
- ## Services
91
+ ---
290
92
 
291
- For data access, use the provided services instead of directly accessing Firestore. Services provide a consistent interface for data operations and handle error cases.
292
-
293
- ### ClientDataService
294
-
295
- ```typescript
296
- import { ClientDataService } from "@jobsearch-works/services";
297
-
298
- // Get client data
299
- const clientData = await ClientDataService.getData(userId);
300
- ```
301
-
302
- ## Usage
303
-
304
- Import the models and services in your application:
305
-
306
- ```typescript
307
- import { Client } from "@jsw/firestore-models";
308
- import { ClientDataService } from "@jobsearch-works/services";
309
-
310
- // Create a new client
311
- const newClient = Client.createNew("John Doe", "john@example.com");
312
-
313
- // Use services for data access
314
- const clientData = await ClientDataService.getData("123");
315
-
316
- // Use the utility functions
317
- const formattedClient = Client.formatClient(newClient);
318
- ```
93
+ ## 🧩 Contributing
319
94
 
320
- ## Contributing
95
+ When adding a new model:
321
96
 
322
- When adding new models or modifying existing ones:
97
+ 1. Add its interface under `src/types/`
98
+ 2. Add its path builder in `src/paths/pathStrings.ts`
99
+ 3. Update the documentation if needed
100
+ 4. Maintain backward compatibility
323
101
 
324
- 1. Update the TypeScript interfaces
325
- 2. Add corresponding path builders
326
- 3. Update any validation or transformation utilities
327
- 4. Update this documentation
328
- 5. Ensure backward compatibility when possible
102
+ ---
329
103
 
330
- ## License
104
+ ## 📄 License
331
105
 
332
106
  MIT