@jobsearch-works/firestore-models 1.0.28 → 1.0.30
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/dist/index.d.mts +39 -26
- package/dist/index.d.ts +39 -26
- package/dist/index.js +78 -50
- package/dist/index.mjs +75 -46
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
@@ -61,35 +61,35 @@ declare namespace Application {
|
|
61
61
|
const updateStatus: (application: Application.Model, newStatus: Application.Model["status"]) => Application.Model;
|
62
62
|
}
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
interface
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
fromFirebaseUser: (user: any) => AuthUser;
|
85
|
-
formatDates: (user: AuthUser) => {
|
64
|
+
declare namespace AuthUser {
|
65
|
+
export interface Model extends BaseModel {
|
66
|
+
email: string;
|
67
|
+
displayName?: string;
|
68
|
+
photoURL?: string;
|
69
|
+
lastSignIn?: string;
|
70
|
+
emailVerified?: boolean;
|
71
|
+
}
|
72
|
+
interface FirestoreTimestamp {
|
73
|
+
seconds: number;
|
74
|
+
nanoseconds: number;
|
75
|
+
_firestore_timestamp?: boolean;
|
76
|
+
}
|
77
|
+
export const collection: () => string;
|
78
|
+
export const document: (userId: string) => string;
|
79
|
+
export const getTimestampFields: () => (keyof Model)[];
|
80
|
+
export const isFirestoreTimestamp: (value: any) => value is FirestoreTimestamp;
|
81
|
+
export const fromFirebaseUser: (user: any) => Model;
|
82
|
+
export const format: (user: Model) => string;
|
83
|
+
export const formatDates: (user: Model) => {
|
86
84
|
lastSignIn: string;
|
87
85
|
createdAt: string;
|
88
86
|
updatedAt?: string;
|
89
87
|
};
|
90
|
-
toFirestore: (user:
|
91
|
-
fromFirestore: (data: Record<string, any>) =>
|
92
|
-
|
88
|
+
export const toFirestore: (user: Model) => Record<string, any>;
|
89
|
+
export const fromFirestore: (data: Record<string, any>) => Model;
|
90
|
+
export const createNew: (email: string, displayName?: string, photoURL?: string) => Model;
|
91
|
+
export {};
|
92
|
+
}
|
93
93
|
|
94
94
|
declare namespace Client {
|
95
95
|
interface Model extends BaseModel {
|
@@ -288,4 +288,17 @@ declare namespace ApplicationQuestion {
|
|
288
288
|
const createNew: (questionText: string, type: Type, answerText?: string) => ApplicationQuestion.Model;
|
289
289
|
}
|
290
290
|
|
291
|
-
|
291
|
+
declare namespace Agent {
|
292
|
+
interface Model extends BaseModel {
|
293
|
+
name: string;
|
294
|
+
email: string;
|
295
|
+
status: "active" | "inactive";
|
296
|
+
profilePicture?: string;
|
297
|
+
}
|
298
|
+
const collection: () => string;
|
299
|
+
const document: (agentId: string) => string;
|
300
|
+
const formatAgent: (agent: Agent.Model) => string;
|
301
|
+
const createNew: (name: string, email: string) => Agent.Model;
|
302
|
+
}
|
303
|
+
|
304
|
+
export { Agent, Application, ApplicationQuestion, AuthUser, Client, ClientData, ClientLogin, ClientQuestion, Vacancy, VacancySuggestion };
|
package/dist/index.d.ts
CHANGED
@@ -61,35 +61,35 @@ declare namespace Application {
|
|
61
61
|
const updateStatus: (application: Application.Model, newStatus: Application.Model["status"]) => Application.Model;
|
62
62
|
}
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
interface
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
fromFirebaseUser: (user: any) => AuthUser;
|
85
|
-
formatDates: (user: AuthUser) => {
|
64
|
+
declare namespace AuthUser {
|
65
|
+
export interface Model extends BaseModel {
|
66
|
+
email: string;
|
67
|
+
displayName?: string;
|
68
|
+
photoURL?: string;
|
69
|
+
lastSignIn?: string;
|
70
|
+
emailVerified?: boolean;
|
71
|
+
}
|
72
|
+
interface FirestoreTimestamp {
|
73
|
+
seconds: number;
|
74
|
+
nanoseconds: number;
|
75
|
+
_firestore_timestamp?: boolean;
|
76
|
+
}
|
77
|
+
export const collection: () => string;
|
78
|
+
export const document: (userId: string) => string;
|
79
|
+
export const getTimestampFields: () => (keyof Model)[];
|
80
|
+
export const isFirestoreTimestamp: (value: any) => value is FirestoreTimestamp;
|
81
|
+
export const fromFirebaseUser: (user: any) => Model;
|
82
|
+
export const format: (user: Model) => string;
|
83
|
+
export const formatDates: (user: Model) => {
|
86
84
|
lastSignIn: string;
|
87
85
|
createdAt: string;
|
88
86
|
updatedAt?: string;
|
89
87
|
};
|
90
|
-
toFirestore: (user:
|
91
|
-
fromFirestore: (data: Record<string, any>) =>
|
92
|
-
|
88
|
+
export const toFirestore: (user: Model) => Record<string, any>;
|
89
|
+
export const fromFirestore: (data: Record<string, any>) => Model;
|
90
|
+
export const createNew: (email: string, displayName?: string, photoURL?: string) => Model;
|
91
|
+
export {};
|
92
|
+
}
|
93
93
|
|
94
94
|
declare namespace Client {
|
95
95
|
interface Model extends BaseModel {
|
@@ -288,4 +288,17 @@ declare namespace ApplicationQuestion {
|
|
288
288
|
const createNew: (questionText: string, type: Type, answerText?: string) => ApplicationQuestion.Model;
|
289
289
|
}
|
290
290
|
|
291
|
-
|
291
|
+
declare namespace Agent {
|
292
|
+
interface Model extends BaseModel {
|
293
|
+
name: string;
|
294
|
+
email: string;
|
295
|
+
status: "active" | "inactive";
|
296
|
+
profilePicture?: string;
|
297
|
+
}
|
298
|
+
const collection: () => string;
|
299
|
+
const document: (agentId: string) => string;
|
300
|
+
const formatAgent: (agent: Agent.Model) => string;
|
301
|
+
const createNew: (name: string, email: string) => Agent.Model;
|
302
|
+
}
|
303
|
+
|
304
|
+
export { Agent, Application, ApplicationQuestion, AuthUser, Client, ClientData, ClientLogin, ClientQuestion, Vacancy, VacancySuggestion };
|
package/dist/index.js
CHANGED
@@ -20,17 +20,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
20
20
|
// src/index.ts
|
21
21
|
var src_exports = {};
|
22
22
|
__export(src_exports, {
|
23
|
+
Agent: () => Agent,
|
23
24
|
Application: () => Application,
|
24
25
|
ApplicationQuestion: () => ApplicationQuestion,
|
25
|
-
|
26
|
-
AuthUserUtils: () => AuthUserUtils,
|
26
|
+
AuthUser: () => AuthUser,
|
27
27
|
Client: () => Client,
|
28
28
|
ClientData: () => ClientData,
|
29
29
|
ClientLogin: () => ClientLogin,
|
30
30
|
ClientQuestion: () => ClientQuestion,
|
31
31
|
Vacancy: () => Vacancy,
|
32
|
-
VacancySuggestion: () => VacancySuggestion
|
33
|
-
getAuthUserDocumentPath: () => getAuthUserDocumentPath
|
32
|
+
VacancySuggestion: () => VacancySuggestion
|
34
33
|
});
|
35
34
|
module.exports = __toCommonJS(src_exports);
|
36
35
|
|
@@ -86,17 +85,19 @@ var Application;
|
|
86
85
|
})(Application || (Application = {}));
|
87
86
|
|
88
87
|
// src/models/AuthUser.ts
|
89
|
-
var
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
getTimestampFields
|
94
|
-
|
95
|
-
|
88
|
+
var AuthUser;
|
89
|
+
((AuthUser2) => {
|
90
|
+
AuthUser2.collection = () => "users";
|
91
|
+
AuthUser2.document = (userId) => `users/${userId}`;
|
92
|
+
AuthUser2.getTimestampFields = () => [
|
93
|
+
"lastSignIn",
|
94
|
+
"createdAt",
|
95
|
+
"updatedAt"
|
96
|
+
];
|
97
|
+
AuthUser2.isFirestoreTimestamp = (value) => {
|
96
98
|
return typeof value === "object" && value !== null && ("seconds" in value || "_firestore_timestamp" in value);
|
97
|
-
}
|
98
|
-
|
99
|
-
fromFirebaseUser: (user) => {
|
99
|
+
};
|
100
|
+
AuthUser2.fromFirebaseUser = (user) => {
|
100
101
|
return {
|
101
102
|
id: user.uid,
|
102
103
|
email: user.email,
|
@@ -104,16 +105,18 @@ var AuthUserUtils = {
|
|
104
105
|
photoURL: user.photoURL,
|
105
106
|
emailVerified: user.emailVerified,
|
106
107
|
lastSignIn: (/* @__PURE__ */ new Date()).toISOString(),
|
107
|
-
|
108
|
-
|
108
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
109
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
109
110
|
};
|
110
|
-
}
|
111
|
-
|
112
|
-
|
111
|
+
};
|
112
|
+
AuthUser2.format = (user) => {
|
113
|
+
return `${user.email}${user.displayName ? " (" + user.displayName + ")" : ""}`;
|
114
|
+
};
|
115
|
+
AuthUser2.formatDates = (user) => {
|
113
116
|
const formatDate = (dateValue) => {
|
114
117
|
if (!dateValue)
|
115
118
|
return "N/A";
|
116
|
-
const date =
|
119
|
+
const date = dateValue instanceof Date ? dateValue : new Date(dateValue);
|
117
120
|
return date.toLocaleString();
|
118
121
|
};
|
119
122
|
return {
|
@@ -121,41 +124,49 @@ var AuthUserUtils = {
|
|
121
124
|
createdAt: formatDate(user.createdAt),
|
122
125
|
updatedAt: user.updatedAt ? formatDate(user.updatedAt) : void 0
|
123
126
|
};
|
124
|
-
}
|
125
|
-
|
126
|
-
toFirestore: (user) => {
|
127
|
+
};
|
128
|
+
AuthUser2.toFirestore = (user) => {
|
127
129
|
const { id, ...data } = user;
|
128
|
-
|
129
|
-
data
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
}
|
137
|
-
data.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
138
|
-
}
|
130
|
+
(0, AuthUser2.getTimestampFields)().forEach((field) => {
|
131
|
+
if (data[field] instanceof Date) {
|
132
|
+
data[field] = data[field].toISOString();
|
133
|
+
} else if (!data[field]) {
|
134
|
+
if (field === "updatedAt") {
|
135
|
+
data.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
136
|
+
}
|
137
|
+
}
|
138
|
+
});
|
139
139
|
return data;
|
140
|
-
}
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
const timestampFields = [];
|
145
|
-
timestampFields.forEach((field) => {
|
140
|
+
};
|
141
|
+
AuthUser2.fromFirestore = (data) => {
|
142
|
+
const processed = { ...data };
|
143
|
+
(0, AuthUser2.getTimestampFields)().forEach((field) => {
|
146
144
|
if (data[field]) {
|
147
|
-
if (
|
148
|
-
|
145
|
+
if ((0, AuthUser2.isFirestoreTimestamp)(data[field])) {
|
146
|
+
processed[field] = new Date(
|
149
147
|
data[field].seconds * 1e3
|
150
148
|
).toISOString();
|
151
149
|
} else if (typeof data[field] === "string") {
|
152
|
-
|
150
|
+
processed[field] = data[field];
|
153
151
|
}
|
154
152
|
}
|
155
153
|
});
|
156
|
-
return
|
157
|
-
}
|
158
|
-
|
154
|
+
return processed;
|
155
|
+
};
|
156
|
+
AuthUser2.createNew = (email, displayName, photoURL) => {
|
157
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
158
|
+
return {
|
159
|
+
id: void 0,
|
160
|
+
email,
|
161
|
+
displayName,
|
162
|
+
photoURL,
|
163
|
+
emailVerified: false,
|
164
|
+
lastSignIn: now,
|
165
|
+
createdAt: now,
|
166
|
+
updatedAt: now
|
167
|
+
};
|
168
|
+
};
|
169
|
+
})(AuthUser || (AuthUser = {}));
|
159
170
|
|
160
171
|
// src/models/Client.ts
|
161
172
|
var Client;
|
@@ -346,17 +357,34 @@ var ApplicationQuestion;
|
|
346
357
|
};
|
347
358
|
};
|
348
359
|
})(ApplicationQuestion || (ApplicationQuestion = {}));
|
360
|
+
|
361
|
+
// src/models/Agent.ts
|
362
|
+
var Agent;
|
363
|
+
((Agent2) => {
|
364
|
+
Agent2.collection = () => "agents";
|
365
|
+
Agent2.document = (agentId) => `agents/${agentId}`;
|
366
|
+
Agent2.formatAgent = (agent) => {
|
367
|
+
return `${agent.name} (${agent.email}) - ${agent.status}`;
|
368
|
+
};
|
369
|
+
Agent2.createNew = (name, email) => {
|
370
|
+
return {
|
371
|
+
name,
|
372
|
+
email,
|
373
|
+
status: "active",
|
374
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
375
|
+
};
|
376
|
+
};
|
377
|
+
})(Agent || (Agent = {}));
|
349
378
|
// Annotate the CommonJS export names for ESM import in node:
|
350
379
|
0 && (module.exports = {
|
380
|
+
Agent,
|
351
381
|
Application,
|
352
382
|
ApplicationQuestion,
|
353
|
-
|
354
|
-
AuthUserUtils,
|
383
|
+
AuthUser,
|
355
384
|
Client,
|
356
385
|
ClientData,
|
357
386
|
ClientLogin,
|
358
387
|
ClientQuestion,
|
359
388
|
Vacancy,
|
360
|
-
VacancySuggestion
|
361
|
-
getAuthUserDocumentPath
|
389
|
+
VacancySuggestion
|
362
390
|
});
|
package/dist/index.mjs
CHANGED
@@ -50,17 +50,19 @@ var Application;
|
|
50
50
|
})(Application || (Application = {}));
|
51
51
|
|
52
52
|
// src/models/AuthUser.ts
|
53
|
-
var
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
getTimestampFields
|
58
|
-
|
59
|
-
|
53
|
+
var AuthUser;
|
54
|
+
((AuthUser2) => {
|
55
|
+
AuthUser2.collection = () => "users";
|
56
|
+
AuthUser2.document = (userId) => `users/${userId}`;
|
57
|
+
AuthUser2.getTimestampFields = () => [
|
58
|
+
"lastSignIn",
|
59
|
+
"createdAt",
|
60
|
+
"updatedAt"
|
61
|
+
];
|
62
|
+
AuthUser2.isFirestoreTimestamp = (value) => {
|
60
63
|
return typeof value === "object" && value !== null && ("seconds" in value || "_firestore_timestamp" in value);
|
61
|
-
}
|
62
|
-
|
63
|
-
fromFirebaseUser: (user) => {
|
64
|
+
};
|
65
|
+
AuthUser2.fromFirebaseUser = (user) => {
|
64
66
|
return {
|
65
67
|
id: user.uid,
|
66
68
|
email: user.email,
|
@@ -68,16 +70,18 @@ var AuthUserUtils = {
|
|
68
70
|
photoURL: user.photoURL,
|
69
71
|
emailVerified: user.emailVerified,
|
70
72
|
lastSignIn: (/* @__PURE__ */ new Date()).toISOString(),
|
71
|
-
|
72
|
-
|
73
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
74
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
73
75
|
};
|
74
|
-
}
|
75
|
-
|
76
|
-
|
76
|
+
};
|
77
|
+
AuthUser2.format = (user) => {
|
78
|
+
return `${user.email}${user.displayName ? " (" + user.displayName + ")" : ""}`;
|
79
|
+
};
|
80
|
+
AuthUser2.formatDates = (user) => {
|
77
81
|
const formatDate = (dateValue) => {
|
78
82
|
if (!dateValue)
|
79
83
|
return "N/A";
|
80
|
-
const date =
|
84
|
+
const date = dateValue instanceof Date ? dateValue : new Date(dateValue);
|
81
85
|
return date.toLocaleString();
|
82
86
|
};
|
83
87
|
return {
|
@@ -85,41 +89,49 @@ var AuthUserUtils = {
|
|
85
89
|
createdAt: formatDate(user.createdAt),
|
86
90
|
updatedAt: user.updatedAt ? formatDate(user.updatedAt) : void 0
|
87
91
|
};
|
88
|
-
}
|
89
|
-
|
90
|
-
toFirestore: (user) => {
|
92
|
+
};
|
93
|
+
AuthUser2.toFirestore = (user) => {
|
91
94
|
const { id, ...data } = user;
|
92
|
-
|
93
|
-
data
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
}
|
101
|
-
data.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
102
|
-
}
|
95
|
+
(0, AuthUser2.getTimestampFields)().forEach((field) => {
|
96
|
+
if (data[field] instanceof Date) {
|
97
|
+
data[field] = data[field].toISOString();
|
98
|
+
} else if (!data[field]) {
|
99
|
+
if (field === "updatedAt") {
|
100
|
+
data.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
101
|
+
}
|
102
|
+
}
|
103
|
+
});
|
103
104
|
return data;
|
104
|
-
}
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
const timestampFields = [];
|
109
|
-
timestampFields.forEach((field) => {
|
105
|
+
};
|
106
|
+
AuthUser2.fromFirestore = (data) => {
|
107
|
+
const processed = { ...data };
|
108
|
+
(0, AuthUser2.getTimestampFields)().forEach((field) => {
|
110
109
|
if (data[field]) {
|
111
|
-
if (
|
112
|
-
|
110
|
+
if ((0, AuthUser2.isFirestoreTimestamp)(data[field])) {
|
111
|
+
processed[field] = new Date(
|
113
112
|
data[field].seconds * 1e3
|
114
113
|
).toISOString();
|
115
114
|
} else if (typeof data[field] === "string") {
|
116
|
-
|
115
|
+
processed[field] = data[field];
|
117
116
|
}
|
118
117
|
}
|
119
118
|
});
|
120
|
-
return
|
121
|
-
}
|
122
|
-
|
119
|
+
return processed;
|
120
|
+
};
|
121
|
+
AuthUser2.createNew = (email, displayName, photoURL) => {
|
122
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
123
|
+
return {
|
124
|
+
id: void 0,
|
125
|
+
email,
|
126
|
+
displayName,
|
127
|
+
photoURL,
|
128
|
+
emailVerified: false,
|
129
|
+
lastSignIn: now,
|
130
|
+
createdAt: now,
|
131
|
+
updatedAt: now
|
132
|
+
};
|
133
|
+
};
|
134
|
+
})(AuthUser || (AuthUser = {}));
|
123
135
|
|
124
136
|
// src/models/Client.ts
|
125
137
|
var Client;
|
@@ -310,16 +322,33 @@ var ApplicationQuestion;
|
|
310
322
|
};
|
311
323
|
};
|
312
324
|
})(ApplicationQuestion || (ApplicationQuestion = {}));
|
325
|
+
|
326
|
+
// src/models/Agent.ts
|
327
|
+
var Agent;
|
328
|
+
((Agent2) => {
|
329
|
+
Agent2.collection = () => "agents";
|
330
|
+
Agent2.document = (agentId) => `agents/${agentId}`;
|
331
|
+
Agent2.formatAgent = (agent) => {
|
332
|
+
return `${agent.name} (${agent.email}) - ${agent.status}`;
|
333
|
+
};
|
334
|
+
Agent2.createNew = (name, email) => {
|
335
|
+
return {
|
336
|
+
name,
|
337
|
+
email,
|
338
|
+
status: "active",
|
339
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
340
|
+
};
|
341
|
+
};
|
342
|
+
})(Agent || (Agent = {}));
|
313
343
|
export {
|
344
|
+
Agent,
|
314
345
|
Application,
|
315
346
|
ApplicationQuestion,
|
316
|
-
|
317
|
-
AuthUserUtils,
|
347
|
+
AuthUser,
|
318
348
|
Client,
|
319
349
|
ClientData,
|
320
350
|
ClientLogin,
|
321
351
|
ClientQuestion,
|
322
352
|
Vacancy,
|
323
|
-
VacancySuggestion
|
324
|
-
getAuthUserDocumentPath
|
353
|
+
VacancySuggestion
|
325
354
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@jobsearch-works/firestore-models",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.30",
|
4
4
|
"description": "A shared library for standardizing Firestore document schemas and paths across multiple projects",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|