@critical-path/core 0.7.0 → 0.8.1
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/CHANGELOG.md +12 -0
- package/dist/domain/entities.d.ts +4 -0
- package/dist/domain/entities.d.ts.map +1 -1
- package/dist/domain/entities.js +14 -0
- package/dist/domain/entities.js.map +1 -1
- package/dist/engine/index.d.ts.map +1 -1
- package/dist/engine/index.js +2 -0
- package/dist/engine/index.js.map +1 -1
- package/dist/index.test.js +26 -0
- package/dist/index.test.js.map +1 -1
- package/dist/storage/firebase-storage.d.ts +1 -0
- package/dist/storage/firebase-storage.d.ts.map +1 -1
- package/dist/storage/firebase-storage.js +36 -10
- package/dist/storage/firebase-storage.js.map +1 -1
- package/dist/store/firebase.d.ts +1 -0
- package/dist/store/firebase.d.ts.map +1 -1
- package/dist/store/firebase.js +34 -19
- package/dist/store/firebase.js.map +1 -1
- package/dist/store/firebase.test.js +12 -0
- package/dist/store/firebase.test.js.map +1 -1
- package/package.json +1 -1
- package/src/domain/entities.ts +19 -0
- package/src/engine/index.ts +2 -0
- package/src/index.test.ts +32 -0
- package/src/storage/firebase-storage.ts +37 -11
- package/src/store/firebase.test.ts +15 -0
- package/src/store/firebase.ts +35 -19
package/src/store/firebase.ts
CHANGED
|
@@ -102,6 +102,22 @@ export interface FirebaseStoreConfig {
|
|
|
102
102
|
db: FirestoreDBInterface;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
export function sanitizeFirestoreData<T>(obj: T): T {
|
|
106
|
+
if (obj === null || typeof obj !== 'object') {
|
|
107
|
+
return obj;
|
|
108
|
+
}
|
|
109
|
+
if (Array.isArray(obj)) {
|
|
110
|
+
return obj.map(sanitizeFirestoreData) as unknown as T;
|
|
111
|
+
}
|
|
112
|
+
const clean: Record<string, any> = {};
|
|
113
|
+
for (const [key, value] of Object.entries(obj as Record<string, any>)) {
|
|
114
|
+
if (value !== undefined) {
|
|
115
|
+
clean[key] = sanitizeFirestoreData(value);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return clean as T;
|
|
119
|
+
}
|
|
120
|
+
|
|
105
121
|
export class FirebaseStore implements StorageAdapter {
|
|
106
122
|
private db: FirestoreDBInterface;
|
|
107
123
|
|
|
@@ -131,7 +147,7 @@ export class FirebaseStore implements StorageAdapter {
|
|
|
131
147
|
const now = new Date().toISOString();
|
|
132
148
|
const key = project.key || generateProjectKey(project.name);
|
|
133
149
|
const newProj: Project = { ...project, key, id: docRef.id, createdAt: now, updatedAt: now };
|
|
134
|
-
await docRef.set(newProj);
|
|
150
|
+
await docRef.set(sanitizeFirestoreData(newProj));
|
|
135
151
|
return newProj;
|
|
136
152
|
}
|
|
137
153
|
|
|
@@ -144,7 +160,7 @@ export class FirebaseStore implements StorageAdapter {
|
|
|
144
160
|
...updates,
|
|
145
161
|
updatedAt: new Date().toISOString()
|
|
146
162
|
};
|
|
147
|
-
await this.db.collection('projects').doc(id).set(updated, { merge: true });
|
|
163
|
+
await this.db.collection('projects').doc(id).set(sanitizeFirestoreData(updated), { merge: true });
|
|
148
164
|
return updated;
|
|
149
165
|
}
|
|
150
166
|
|
|
@@ -171,7 +187,7 @@ export class FirebaseStore implements StorageAdapter {
|
|
|
171
187
|
const docRef = this.db.collection('workflows').doc();
|
|
172
188
|
const now = new Date().toISOString();
|
|
173
189
|
const newWf: Workflow = { ...workflow, id: docRef.id, createdAt: now, updatedAt: now };
|
|
174
|
-
await docRef.set(newWf);
|
|
190
|
+
await docRef.set(sanitizeFirestoreData(newWf));
|
|
175
191
|
return newWf;
|
|
176
192
|
}
|
|
177
193
|
|
|
@@ -184,7 +200,7 @@ export class FirebaseStore implements StorageAdapter {
|
|
|
184
200
|
...updates,
|
|
185
201
|
updatedAt: new Date().toISOString()
|
|
186
202
|
};
|
|
187
|
-
await this.db.collection('workflows').doc(id).set(updated, { merge: true });
|
|
203
|
+
await this.db.collection('workflows').doc(id).set(sanitizeFirestoreData(updated), { merge: true });
|
|
188
204
|
return updated;
|
|
189
205
|
}
|
|
190
206
|
|
|
@@ -211,7 +227,7 @@ export class FirebaseStore implements StorageAdapter {
|
|
|
211
227
|
const docRef = this.db.collection('teams').doc();
|
|
212
228
|
const now = new Date().toISOString();
|
|
213
229
|
const newTeam: Team = { ...team, id: docRef.id, createdAt: now, updatedAt: now };
|
|
214
|
-
await docRef.set(newTeam);
|
|
230
|
+
await docRef.set(sanitizeFirestoreData(newTeam));
|
|
215
231
|
return newTeam;
|
|
216
232
|
}
|
|
217
233
|
|
|
@@ -220,7 +236,7 @@ export class FirebaseStore implements StorageAdapter {
|
|
|
220
236
|
if (!existing) return null;
|
|
221
237
|
|
|
222
238
|
const updated: Team = { ...existing, ...updates, updatedAt: new Date().toISOString() };
|
|
223
|
-
await this.db.collection('teams').doc(id).set(updated, { merge: true });
|
|
239
|
+
await this.db.collection('teams').doc(id).set(sanitizeFirestoreData(updated), { merge: true });
|
|
224
240
|
return updated;
|
|
225
241
|
}
|
|
226
242
|
|
|
@@ -247,7 +263,7 @@ export class FirebaseStore implements StorageAdapter {
|
|
|
247
263
|
const docRef = this.db.collection('containers').doc();
|
|
248
264
|
const now = new Date().toISOString();
|
|
249
265
|
const newContainer: TaskContainer = { ...container, id: docRef.id, createdAt: now, updatedAt: now };
|
|
250
|
-
await docRef.set(newContainer);
|
|
266
|
+
await docRef.set(sanitizeFirestoreData(newContainer));
|
|
251
267
|
return newContainer;
|
|
252
268
|
}
|
|
253
269
|
|
|
@@ -256,7 +272,7 @@ export class FirebaseStore implements StorageAdapter {
|
|
|
256
272
|
if (!existing) return null;
|
|
257
273
|
|
|
258
274
|
const updated: TaskContainer = { ...existing, ...updates, updatedAt: new Date().toISOString() };
|
|
259
|
-
await this.db.collection('containers').doc(id).set(updated, { merge: true });
|
|
275
|
+
await this.db.collection('containers').doc(id).set(sanitizeFirestoreData(updated), { merge: true });
|
|
260
276
|
return updated;
|
|
261
277
|
}
|
|
262
278
|
|
|
@@ -288,7 +304,7 @@ export class FirebaseStore implements StorageAdapter {
|
|
|
288
304
|
const docRef = this.db.collection('tasks').doc();
|
|
289
305
|
const now = new Date().toISOString();
|
|
290
306
|
const newTask: Task = { ...task, id: docRef.id, createdAt: now, updatedAt: now };
|
|
291
|
-
await docRef.set(newTask);
|
|
307
|
+
await docRef.set(sanitizeFirestoreData(newTask));
|
|
292
308
|
return newTask;
|
|
293
309
|
}
|
|
294
310
|
|
|
@@ -301,7 +317,7 @@ export class FirebaseStore implements StorageAdapter {
|
|
|
301
317
|
...updates,
|
|
302
318
|
updatedAt: new Date().toISOString()
|
|
303
319
|
};
|
|
304
|
-
await this.db.collection('tasks').doc(id).set(updated, { merge: true });
|
|
320
|
+
await this.db.collection('tasks').doc(id).set(sanitizeFirestoreData(updated), { merge: true });
|
|
305
321
|
return updated;
|
|
306
322
|
}
|
|
307
323
|
|
|
@@ -328,7 +344,7 @@ export class FirebaseStore implements StorageAdapter {
|
|
|
328
344
|
const docRef = this.db.collection('iterations').doc();
|
|
329
345
|
const now = new Date().toISOString();
|
|
330
346
|
const newIteration: Iteration = { ...iteration, id: docRef.id, createdAt: now };
|
|
331
|
-
await docRef.set(newIteration);
|
|
347
|
+
await docRef.set(sanitizeFirestoreData(newIteration));
|
|
332
348
|
return newIteration;
|
|
333
349
|
}
|
|
334
350
|
|
|
@@ -337,7 +353,7 @@ export class FirebaseStore implements StorageAdapter {
|
|
|
337
353
|
if (!snap.exists) return null;
|
|
338
354
|
|
|
339
355
|
const updated: Iteration = { ...snap.data(), id, ...updates };
|
|
340
|
-
await this.db.collection('iterations').doc(id).set(updated, { merge: true });
|
|
356
|
+
await this.db.collection('iterations').doc(id).set(sanitizeFirestoreData(updated), { merge: true });
|
|
341
357
|
return updated;
|
|
342
358
|
}
|
|
343
359
|
|
|
@@ -364,7 +380,7 @@ export class FirebaseStore implements StorageAdapter {
|
|
|
364
380
|
const docRef = this.db.collection('comments').doc();
|
|
365
381
|
const now = new Date().toISOString();
|
|
366
382
|
const newComment: Comment = { ...comment, id: docRef.id, createdAt: now, updatedAt: now };
|
|
367
|
-
await docRef.set(newComment);
|
|
383
|
+
await docRef.set(sanitizeFirestoreData(newComment));
|
|
368
384
|
return newComment;
|
|
369
385
|
}
|
|
370
386
|
|
|
@@ -377,7 +393,7 @@ export class FirebaseStore implements StorageAdapter {
|
|
|
377
393
|
...updates,
|
|
378
394
|
updatedAt: new Date().toISOString()
|
|
379
395
|
};
|
|
380
|
-
await this.db.collection('comments').doc(id).set(updated, { merge: true });
|
|
396
|
+
await this.db.collection('comments').doc(id).set(sanitizeFirestoreData(updated), { merge: true });
|
|
381
397
|
return updated;
|
|
382
398
|
}
|
|
383
399
|
|
|
@@ -413,7 +429,7 @@ export class FirebaseStore implements StorageAdapter {
|
|
|
413
429
|
const docRef = this.db.collection('attachments').doc();
|
|
414
430
|
const now = new Date().toISOString();
|
|
415
431
|
const newAtt: Attachment = { ...attachment, id: docRef.id, createdAt: now, updatedAt: now };
|
|
416
|
-
await docRef.set(newAtt);
|
|
432
|
+
await docRef.set(sanitizeFirestoreData(newAtt));
|
|
417
433
|
return newAtt;
|
|
418
434
|
}
|
|
419
435
|
|
|
@@ -440,7 +456,7 @@ export class FirebaseStore implements StorageAdapter {
|
|
|
440
456
|
const docRef = this.db.collection('activities').doc();
|
|
441
457
|
const now = new Date().toISOString();
|
|
442
458
|
const newAct: Activity = { ...activity, id: docRef.id, createdAt: now };
|
|
443
|
-
await docRef.set(newAct);
|
|
459
|
+
await docRef.set(sanitizeFirestoreData(newAct));
|
|
444
460
|
return newAct;
|
|
445
461
|
}
|
|
446
462
|
|
|
@@ -454,7 +470,7 @@ export class FirebaseStore implements StorageAdapter {
|
|
|
454
470
|
const docRef = this.db.collection('time_entries').doc();
|
|
455
471
|
const now = new Date().toISOString();
|
|
456
472
|
const newEntry: TimeEntry = { ...entry, id: docRef.id, loggedAt: now };
|
|
457
|
-
await docRef.set(newEntry);
|
|
473
|
+
await docRef.set(sanitizeFirestoreData(newEntry));
|
|
458
474
|
return newEntry;
|
|
459
475
|
}
|
|
460
476
|
|
|
@@ -467,7 +483,7 @@ export class FirebaseStore implements StorageAdapter {
|
|
|
467
483
|
async addDependency(dep: Omit<TaskDependency, 'id'>): Promise<TaskDependency> {
|
|
468
484
|
const docRef = this.db.collection('dependencies').doc();
|
|
469
485
|
const newDep: TaskDependency = { ...dep, id: docRef.id };
|
|
470
|
-
await docRef.set(newDep);
|
|
486
|
+
await docRef.set(sanitizeFirestoreData(newDep));
|
|
471
487
|
return newDep;
|
|
472
488
|
}
|
|
473
489
|
|
|
@@ -481,7 +497,7 @@ export class FirebaseStore implements StorageAdapter {
|
|
|
481
497
|
const docRef = this.db.collection('webhooks').doc();
|
|
482
498
|
const now = new Date().toISOString();
|
|
483
499
|
const newWh: Webhook = { ...webhook, id: docRef.id, createdAt: now };
|
|
484
|
-
await docRef.set(newWh);
|
|
500
|
+
await docRef.set(sanitizeFirestoreData(newWh));
|
|
485
501
|
return newWh;
|
|
486
502
|
}
|
|
487
503
|
}
|