@jobsearch-works/firestore-models 1.0.3 → 1.0.8

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
@@ -45,165 +45,249 @@ firestore-models/
45
45
  └── package.json
46
46
  ```
47
47
 
48
- ## Models
48
+ ## Base Model
49
+
50
+ All models extend from the BaseModel interface:
51
+
52
+ ```typescript
53
+ interface BaseModel {
54
+ id?: string; // Optional document ID
55
+ createdAt?: Date | string; // Optional creation timestamp
56
+ updatedAt?: Date | string; // Optional update timestamp
57
+ }
58
+ ```
59
+
60
+ ## Models and Namespaces
61
+
62
+ Each model is defined within its own namespace, which includes:
63
+
64
+ - The model interface
65
+ - Path builders for Firestore collections and documents
66
+ - Utility functions for working with the model
49
67
 
50
68
  ### Client
51
69
 
52
70
  ```typescript
53
- interface Client {
54
- name: string;
55
- email: string;
56
- status: "active" | "inactive";
57
- resume?: string;
58
- createdAt: string;
59
- updatedAt?: string;
71
+ namespace Client {
72
+ interface Model extends BaseModel {
73
+ name: string;
74
+ email: string;
75
+ status: "active" | "inactive";
76
+ resume?: string;
77
+ }
78
+
79
+ // Path builders
80
+ const collection = () => "clients";
81
+ const document = (clientId: string) => `clients/${clientId}`;
82
+
83
+ // Utility functions
84
+ const formatClient = (client: Client.Model): string;
85
+ const createNew = (name: string, email: string): Client.Model;
60
86
  }
61
87
  ```
62
88
 
63
89
  ### Application
64
90
 
65
91
  ```typescript
66
- interface Application {
67
- vacancyId: string;
68
- clientId: string;
69
- status:
70
- | "new"
71
- | "submitted"
72
- | "interviewing"
73
- | "accepted"
74
- | "rejected"
75
- | "withdrawn"
76
- | "applying"
77
- | "suggested"
78
- | "approved";
79
- coverLetter?: string;
80
- resume?: string;
81
- // Denormalized fields from Vacancy
82
- company?: string;
83
- position?: string;
84
- location?: string;
85
- jobId?: string;
86
- advertisingUrl?: string;
87
- applicationUrl?: string;
88
- applicationDomain?: string;
89
- advertisingDomain?: string;
90
- description?: string;
91
- fullPageText?: string;
92
- createdAt: string;
93
- updatedAt?: string;
92
+ namespace Application {
93
+ interface Model extends BaseModel {
94
+ vacancyId: string;
95
+ clientId: string;
96
+ status:
97
+ | "new"
98
+ | "submitted"
99
+ | "interviewing"
100
+ | "accepted"
101
+ | "rejected"
102
+ | "withdrawn"
103
+ | "applying"
104
+ | "suggested"
105
+ | "approved";
106
+ coverLetter?: string;
107
+ resume?: string;
108
+ // Denormalized fields from Vacancy
109
+ company?: string;
110
+ position?: string;
111
+ location?: string;
112
+ jobId?: string;
113
+ advertisingUrl?: string;
114
+ applicationUrl?: string;
115
+ applicationDomain?: string;
116
+ advertisingDomain?: string;
117
+ description?: string;
118
+ fullPageText?: string;
119
+ }
120
+
121
+ // Path builders
122
+ const collection = (clientId: string) => `clients/${clientId}/applications`;
123
+ const document = (clientId: string, applicationId: string) =>
124
+ `clients/${clientId}/applications/${applicationId}`;
125
+
126
+ // Utility functions
127
+ const formatSummary = (application: Application.Model): string;
128
+ const formatDate = (date: Date | string): string;
129
+ const createNew = (
130
+ clientId: string,
131
+ vacancyId: string,
132
+ vacancyData: Partial<Vacancy.Model>
133
+ ): Application.Model;
134
+ const updateStatus = (
135
+ application: Application.Model,
136
+ newStatus: Application.Model["status"]
137
+ ): Application.Model;
94
138
  }
95
139
  ```
96
140
 
97
141
  ### AuthUser
98
142
 
99
143
  ```typescript
100
- interface AuthUser {
101
- email: string;
102
- role: "admin" | "client";
103
- clientId?: string; // Required if role is "client"
104
- createdAt: string;
105
- updatedAt?: string;
144
+ namespace AuthUser {
145
+ interface Model extends BaseModel {
146
+ email: string;
147
+ displayName?: string;
148
+ photoURL?: string;
149
+ lastSignIn?: Date | string;
150
+ emailVerified?: boolean;
151
+ }
152
+
153
+ // Path builders
154
+ const collection = () => "users";
155
+ const document = (userId: string) => `users/${userId}`;
156
+
157
+ // Utility functions
158
+ const fromFirebaseUser = (user: any): AuthUser.Model;
159
+ const formatDates = (user: AuthUser.Model): Record<string, string>;
160
+ const toFirestore = (user: AuthUser.Model): Record<string, any>;
161
+ const fromFirestore = (data: Record<string, any>): AuthUser.Model;
106
162
  }
107
163
  ```
108
164
 
109
165
  ### Vacancy
110
166
 
111
167
  ```typescript
112
- interface Vacancy {
113
- company: string;
114
- position: string;
115
- location: string;
116
- jobId: string;
117
- advertisingUrl: string;
118
- applicationUrl: string;
119
- applicationDomain: string;
120
- advertisingDomain: string;
121
- description: string;
122
- fullPageText: string;
123
- status: "active" | "inactive";
124
- createdAt: string;
125
- updatedAt?: string;
168
+ namespace Vacancy {
169
+ interface Model extends BaseModel {
170
+ company: string;
171
+ position: string;
172
+ location: string;
173
+ jobId: string;
174
+ advertisingUrl: string;
175
+ applicationUrl: string;
176
+ applicationDomain: string;
177
+ advertisingDomain: string;
178
+ description: string;
179
+ fullPageText: string;
180
+ status: "active" | "inactive";
181
+ }
182
+
183
+ // Path builders
184
+ const collection = () => "vacancies";
185
+ const document = (vacancyId: string) => `vacancies/${vacancyId}`;
126
186
  }
127
187
  ```
128
188
 
129
189
  ### Question
130
190
 
131
191
  ```typescript
132
- interface Question {
133
- text: string;
134
- type: "text" | "multiple_choice" | "single_choice";
135
- options?: string[];
136
- required: boolean;
137
- order: number;
138
- createdAt: string;
139
- updatedAt?: string;
192
+ namespace Question {
193
+ interface Model extends BaseModel {
194
+ text: string;
195
+ type: "text" | "multiple_choice" | "single_choice";
196
+ options?: string[];
197
+ required: boolean;
198
+ order: number;
199
+ }
200
+
201
+ // Path builders
202
+ const collection = () => "questions";
203
+ const document = (questionId: string) => `questions/${questionId}`;
140
204
  }
141
205
  ```
142
206
 
143
207
  ### UserQuestion
144
208
 
145
209
  ```typescript
146
- interface UserQuestion {
147
- clientId: string;
148
- questionId: string;
149
- answer: string;
150
- createdAt: string;
151
- updatedAt?: string;
210
+ namespace UserQuestion {
211
+ interface Model extends BaseModel {
212
+ clientId: string;
213
+ questionId: string;
214
+ answer: string;
215
+ }
216
+
217
+ // Path builders
218
+ const collection = (clientId: string) => `clients/${clientId}/questions`;
219
+ const document = (clientId: string, questionId: string) =>
220
+ `clients/${clientId}/questions/${questionId}`;
152
221
  }
153
222
  ```
154
223
 
155
224
  ### ClientData
156
225
 
157
226
  ```typescript
158
- interface ClientData {
159
- clientId: string;
160
- key: string;
161
- value: any;
162
- createdAt: string;
163
- updatedAt?: string;
227
+ namespace ClientData {
228
+ interface Model extends BaseModel {
229
+ clientId: string;
230
+ key: string;
231
+ value: any;
232
+ }
233
+
234
+ // Path builders
235
+ const collection = (clientId: string) => `clients/${clientId}/data`;
236
+ const document = (clientId: string, key: string) =>
237
+ `clients/${clientId}/data/${key}`;
164
238
  }
165
239
  ```
166
240
 
167
241
  ### ClientLogin
168
242
 
169
243
  ```typescript
170
- interface ClientLogin {
171
- clientId: string;
172
- ipAddress: string;
173
- userAgent: string;
174
- createdAt: string;
244
+ namespace ClientLogin {
245
+ interface Model extends BaseModel {
246
+ clientId: string;
247
+ ipAddress: string;
248
+ userAgent: string;
249
+ }
250
+
251
+ // Path builders
252
+ const collection = (clientId: string) => `clients/${clientId}/logins`;
253
+ const document = (clientId: string, loginId: string) =>
254
+ `clients/${clientId}/logins/${loginId}`;
175
255
  }
176
256
  ```
177
257
 
178
258
  ### VacancySuggestion
179
259
 
180
260
  ```typescript
181
- interface VacancySuggestion {
182
- clientId: string;
183
- vacancyId: string;
184
- status: "pending" | "accepted" | "rejected";
185
- createdAt: string;
186
- updatedAt?: string;
261
+ namespace VacancySuggestion {
262
+ interface Model extends BaseModel {
263
+ clientId: string;
264
+ vacancyId: string;
265
+ status: "pending" | "accepted" | "rejected";
266
+ }
267
+
268
+ // Path builders
269
+ const collection = (clientId: string) => `clients/${clientId}/suggestions`;
270
+ const document = (clientId: string, suggestionId: string) =>
271
+ `clients/${clientId}/suggestions/${suggestionId}`;
187
272
  }
188
273
  ```
189
274
 
190
275
  ## Usage
191
276
 
192
- Import the models and path builders in your application:
277
+ Import the models and their utilities in your application:
193
278
 
194
279
  ```typescript
195
- import { Client, clientPath } from "@jsw/firestore-models";
196
-
197
- // Use the type-safe model
198
- const client: Client.Model = {
199
- id: "123",
200
- name: "John Doe",
201
- email: "john@example.com",
202
- status: "active",
203
- };
204
-
205
- // Use the path builder
206
- const clientDocPath = clientPath("123"); // returns 'clients/123'
280
+ import { Client } from "@jsw/firestore-models";
281
+
282
+ // Create a new client
283
+ const newClient = Client.createNew("John Doe", "john@example.com");
284
+
285
+ // Use the path builders
286
+ const clientDocPath = Client.document("123"); // returns 'clients/123'
287
+ const clientCollectionPath = Client.collection(); // returns 'clients'
288
+
289
+ // Use the utility functions
290
+ const formattedClient = Client.formatClient(newClient);
207
291
  ```
208
292
 
209
293
  ## Contributing
@@ -0,0 +1,308 @@
1
+ /**
2
+ * Generic type for all model interfaces
3
+ */
4
+ interface BaseModel {
5
+ id?: string;
6
+ createdAt?: Date | string;
7
+ updatedAt?: Date | string;
8
+ }
9
+
10
+ declare namespace Application {
11
+ /**
12
+ * Represents a job application
13
+ */
14
+ interface Model extends BaseModel {
15
+ vacancyId: string;
16
+ clientId: string;
17
+ status: "new" | "submitted" | "interviewing" | "accepted" | "rejected" | "withdrawn" | "applying" | "suggested" | "approved";
18
+ coverLetter?: string;
19
+ resume?: string;
20
+ company?: string;
21
+ position?: string;
22
+ location?: string;
23
+ jobId?: string;
24
+ advertisingUrl?: string;
25
+ applicationUrl?: string;
26
+ applicationDomain?: string;
27
+ advertisingDomain?: string;
28
+ description?: string;
29
+ fullPageText?: string;
30
+ }
31
+ const collection: (clientId: string) => string;
32
+ const document: (clientId: string, applicationId: string) => string;
33
+ const formatSummary: (application: Application.Model) => string;
34
+ const formatDate: (date: Date | string) => string;
35
+ const createNew: (clientId: string, vacancyId: string, vacancyData?: {
36
+ company?: string;
37
+ position?: string;
38
+ location?: string;
39
+ jobId?: string;
40
+ advertisingUrl?: string;
41
+ applicationUrl?: string;
42
+ applicationDomain?: string;
43
+ advertisingDomain?: string;
44
+ description?: string;
45
+ fullPageText?: string;
46
+ }) => Application.Model;
47
+ const updateStatus: (application: Application.Model, newStatus: Application.Model["status"]) => Application.Model;
48
+ }
49
+
50
+ declare const Application$1_Application: typeof Application;
51
+ declare namespace Application$1 {
52
+ export {
53
+ Application$1_Application as Application,
54
+ };
55
+ }
56
+
57
+ interface FirestoreTimestamp {
58
+ seconds: number;
59
+ nanoseconds: number;
60
+ _firestore_timestamp?: boolean;
61
+ }
62
+ /**
63
+ * AuthUser interface - replaces the old class-based model
64
+ */
65
+ interface AuthUser extends BaseModel {
66
+ email: string;
67
+ displayName?: string;
68
+ photoURL?: string;
69
+ lastSignIn?: Date | string;
70
+ emailVerified?: boolean;
71
+ }
72
+ declare const AuthUserCollectionPath = "users";
73
+ declare const getAuthUserDocumentPath: (userId: string) => string;
74
+ declare const AuthUserUtils: {
75
+ getTimestampFields: () => string[];
76
+ isFirestoreTimestamp: (value: any) => value is FirestoreTimestamp;
77
+ fromFirebaseUser: (user: any) => AuthUser;
78
+ formatDates: (user: AuthUser) => {
79
+ lastSignIn: string;
80
+ createdAt: string;
81
+ updatedAt?: string;
82
+ };
83
+ toFirestore: (user: AuthUser) => Record<string, any>;
84
+ fromFirestore: (data: Record<string, any>) => AuthUser;
85
+ };
86
+
87
+ type AuthUser$1_AuthUser = AuthUser;
88
+ declare const AuthUser$1_AuthUserCollectionPath: typeof AuthUserCollectionPath;
89
+ declare const AuthUser$1_AuthUserUtils: typeof AuthUserUtils;
90
+ declare const AuthUser$1_getAuthUserDocumentPath: typeof getAuthUserDocumentPath;
91
+ declare namespace AuthUser$1 {
92
+ export {
93
+ AuthUser$1_AuthUser as AuthUser,
94
+ AuthUser$1_AuthUserCollectionPath as AuthUserCollectionPath,
95
+ AuthUser$1_AuthUserUtils as AuthUserUtils,
96
+ AuthUser$1_getAuthUserDocumentPath as getAuthUserDocumentPath,
97
+ };
98
+ }
99
+
100
+ declare namespace Client {
101
+ interface Model extends BaseModel {
102
+ name: string;
103
+ email: string;
104
+ status: "active" | "inactive";
105
+ resume?: string;
106
+ }
107
+ const collection: () => string;
108
+ const document: (clientId: string) => string;
109
+ const formatClient: (client: Client.Model) => string;
110
+ const createNew: (name: string, email: string) => Client.Model;
111
+ }
112
+
113
+ declare const Client$1_Client: typeof Client;
114
+ declare namespace Client$1 {
115
+ export {
116
+ Client$1_Client as Client,
117
+ };
118
+ }
119
+
120
+ declare namespace ClientData {
121
+ /**
122
+ * Represents a user's personal data.
123
+ */
124
+ interface Model extends BaseModel {
125
+ firstName: string;
126
+ lastName: string;
127
+ middleName: string;
128
+ preferredName: string;
129
+ email: string;
130
+ phone: string;
131
+ address: string;
132
+ city: string;
133
+ suburb: string;
134
+ state: string;
135
+ zip: string;
136
+ country: string;
137
+ linkedIn?: string;
138
+ countryPhoneCode: string;
139
+ }
140
+ const collection: () => string;
141
+ const document: (clientDataId: string) => string;
142
+ const formatClientData: (clientData: ClientData.Model) => string;
143
+ const createNew: (firstName: string, lastName: string, email: string, phone: string, address: string, city: string, state: string, zip: string, country: string, countryPhoneCode: string, suburb: string) => ClientData.Model;
144
+ }
145
+
146
+ declare const ClientData$1_ClientData: typeof ClientData;
147
+ declare namespace ClientData$1 {
148
+ export {
149
+ ClientData$1_ClientData as ClientData,
150
+ };
151
+ }
152
+
153
+ declare namespace ClientLogin {
154
+ /**
155
+ * Represents login credentials for a client website
156
+ */
157
+ interface Model extends BaseModel {
158
+ userId: string;
159
+ url: string;
160
+ domain: string;
161
+ username?: string;
162
+ password: string;
163
+ email?: string;
164
+ }
165
+ const collection: (userId: string) => string;
166
+ const document: (userId: string, domain: string) => string;
167
+ const formatClientLogin: (clientLogin: ClientLogin.Model) => string;
168
+ const createNew: (userId: string, url: string, domain: string, password: string, username?: string, email?: string) => ClientLogin.Model;
169
+ }
170
+
171
+ declare const ClientLogin$1_ClientLogin: typeof ClientLogin;
172
+ declare namespace ClientLogin$1 {
173
+ export {
174
+ ClientLogin$1_ClientLogin as ClientLogin,
175
+ };
176
+ }
177
+
178
+ /**
179
+ * QuestionData interface defines the core data fields for a generic question.
180
+ */
181
+ interface QuestionData {
182
+ question: string;
183
+ options: string[];
184
+ }
185
+ /**
186
+ * Question interface - extends BaseModelInterface and includes QuestionData
187
+ */
188
+ interface Question extends BaseModel, QuestionData {
189
+ }
190
+ interface ApplicationQuestion {
191
+ questionText: string;
192
+ type: "text";
193
+ answer?: string;
194
+ }
195
+ /**
196
+ * Represents ApplicationQuestion data including its Firestore document ID.
197
+ */
198
+ type ApplicationQuestionDocument = ApplicationQuestion & {
199
+ id: string;
200
+ };
201
+ /**
202
+ * Represents a question-answer pair stored centrally for a client.
203
+ * Assumes structure in clients/{clientId}/questions collection.
204
+ */
205
+ interface ClientQuestionAnswerPair {
206
+ id?: string;
207
+ questionText: string;
208
+ answer: string;
209
+ createdAt?: Date;
210
+ }
211
+
212
+ type Question$1_ApplicationQuestion = ApplicationQuestion;
213
+ type Question$1_ApplicationQuestionDocument = ApplicationQuestionDocument;
214
+ type Question$1_ClientQuestionAnswerPair = ClientQuestionAnswerPair;
215
+ type Question$1_Question = Question;
216
+ type Question$1_QuestionData = QuestionData;
217
+ declare namespace Question$1 {
218
+ export {
219
+ Question$1_ApplicationQuestion as ApplicationQuestion,
220
+ Question$1_ApplicationQuestionDocument as ApplicationQuestionDocument,
221
+ Question$1_ClientQuestionAnswerPair as ClientQuestionAnswerPair,
222
+ Question$1_Question as Question,
223
+ Question$1_QuestionData as QuestionData,
224
+ };
225
+ }
226
+
227
+ /**
228
+ * UserQuestionData interface defines the core data fields for a user question.
229
+ */
230
+ interface UserQuestionData {
231
+ userId: string;
232
+ question: string;
233
+ answer: string;
234
+ options: string[];
235
+ }
236
+ /**
237
+ * UserQuestion interface - extends BaseModel and includes UserQuestionData
238
+ */
239
+ interface UserQuestion extends BaseModel, UserQuestionData {
240
+ }
241
+
242
+ type UserQuestion$1_UserQuestion = UserQuestion;
243
+ type UserQuestion$1_UserQuestionData = UserQuestionData;
244
+ declare namespace UserQuestion$1 {
245
+ export {
246
+ UserQuestion$1_UserQuestion as UserQuestion,
247
+ UserQuestion$1_UserQuestionData as UserQuestionData,
248
+ };
249
+ }
250
+
251
+ declare namespace Vacancy {
252
+ /**
253
+ * Represents a job vacancy
254
+ */
255
+ interface Model extends BaseModel {
256
+ company: string;
257
+ position: string;
258
+ location: string;
259
+ description: string;
260
+ advertisingUrl: string;
261
+ applicationUrl: string;
262
+ applicationDomain: string;
263
+ advertisingDomain: string;
264
+ fullPageText: string;
265
+ jobId: string;
266
+ suggestedTo?: string[];
267
+ }
268
+ const collection: () => string;
269
+ const document: (vacancyId: string) => string;
270
+ const formatSummary: (vacancy: Vacancy.Model) => string;
271
+ const formatDate: (date: Date | string) => string;
272
+ const createNew: (company: string, position: string, location: string, description: string, advertisingUrl: string, applicationUrl: string, applicationDomain: string, advertisingDomain: string, fullPageText: string, jobId: string) => Vacancy.Model;
273
+ }
274
+
275
+ declare const Vacancy$1_Vacancy: typeof Vacancy;
276
+ declare namespace Vacancy$1 {
277
+ export {
278
+ Vacancy$1_Vacancy as Vacancy,
279
+ };
280
+ }
281
+
282
+ declare namespace VacancySuggestion {
283
+ /**
284
+ * Represents a job vacancy suggestion for a client
285
+ */
286
+ interface Model extends BaseModel {
287
+ clientId: string;
288
+ vacancyId: string;
289
+ vacancyCompany: string;
290
+ vacancyPosition: string;
291
+ status: string;
292
+ createdAt: Date | string;
293
+ updatedAt?: Date | string;
294
+ }
295
+ const collection: (clientId: string) => string;
296
+ const document: (clientId: string, suggestionId: string) => string;
297
+ const formatSummary: (suggestion: VacancySuggestion.Model) => string;
298
+ const createNew: (clientId: string, vacancyId: string, vacancyCompany: string, vacancyPosition: string, status?: string) => VacancySuggestion.Model;
299
+ }
300
+
301
+ declare const VacancySuggestion$1_VacancySuggestion: typeof VacancySuggestion;
302
+ declare namespace VacancySuggestion$1 {
303
+ export {
304
+ VacancySuggestion$1_VacancySuggestion as VacancySuggestion,
305
+ };
306
+ }
307
+
308
+ export { Application$1 as Application, AuthUser$1 as AuthUser, BaseModel, Client$1 as Client, ClientData$1 as ClientData, ClientLogin$1 as ClientLogin, Question$1 as Question, UserQuestion$1 as UserQuestion, Vacancy$1 as Vacancy, VacancySuggestion$1 as VacancySuggestion };