@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 +58 -284
- package/dist/index.d.mts +225 -313
- package/dist/index.d.ts +225 -313
- package/dist/index.js +97 -378
- package/dist/index.mjs +92 -367
- package/package.json +1 -1
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.
|
3
|
+
A shared library for standardizing Firestore document schemas and paths across multiple projects.
|
4
4
|
|
5
|
-
|
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
|
-
|
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
|
-
|
11
|
+
---
|
13
12
|
|
14
|
-
|
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
|
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
|
-
|
25
|
+
> âšī¸ Prefer the npm version for production. GitHub installs don't update via `npm update`.
|
63
26
|
|
64
|
-
|
27
|
+
---
|
65
28
|
|
66
|
-
|
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
|
-
|
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
|
-
|
94
|
-
|
95
|
-
|
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
|
-
|
98
|
-
const formatClient = (client: Client.Model): string;
|
99
|
-
const createNew = (name: string, email: string): Client.Model;
|
100
|
-
}
|
101
|
-
```
|
37
|
+
---
|
102
38
|
|
103
|
-
|
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
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
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
|
-
|
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
|
-
|
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
|
-
###
|
55
|
+
### Importing Models and Paths
|
239
56
|
|
240
|
-
```
|
241
|
-
|
242
|
-
|
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
|
-
|
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
|
-
|
64
|
+
---
|
256
65
|
|
257
|
-
|
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
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
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
|
-
|
79
|
+
---
|
273
80
|
|
274
|
-
|
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
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
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
|
-
|
91
|
+
---
|
290
92
|
|
291
|
-
|
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
|
-
|
95
|
+
When adding a new model:
|
321
96
|
|
322
|
-
|
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
|
-
|
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
|