@engine9-io/input-tools 1.9.9 → 1.9.11
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/index.js +23 -21
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -249,6 +249,28 @@ function getUUIDTimestamp(uuid) {
|
|
|
249
249
|
return new Date(ts);
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
+
function getEntryTypeId(o, { defaults = {} } = {}) {
|
|
253
|
+
let id = o.entry_type_id || defaults.entry_type_id;
|
|
254
|
+
if (id) return id;
|
|
255
|
+
const etype = o.entry_type || defaults.entry_type;
|
|
256
|
+
if (!etype) {
|
|
257
|
+
throw new Error('No entry_type, nor entry_type_id specified, specify one to generate a timeline suitable ID');
|
|
258
|
+
}
|
|
259
|
+
id = TIMELINE_ENTRY_TYPES[etype];
|
|
260
|
+
if (id === undefined) throw new Error(`Invalid entry_type: ${etype}`);
|
|
261
|
+
return id;
|
|
262
|
+
}
|
|
263
|
+
function getEntryType(o, defaults = {}) {
|
|
264
|
+
let etype = o.entry_type || defaults.entry_type;
|
|
265
|
+
if (etype) return etype;
|
|
266
|
+
|
|
267
|
+
const id = o.entry_type_id || defaults.entry_type_id;
|
|
268
|
+
|
|
269
|
+
etype = TIMELINE_ENTRY_TYPES[id];
|
|
270
|
+
if (etype === undefined) throw new Error(`Invalid entry_type: ${etype}`);
|
|
271
|
+
return etype;
|
|
272
|
+
}
|
|
273
|
+
|
|
252
274
|
const requiredTimelineEntryFields = ['ts', 'entry_type_id', 'input_id', 'person_id'];
|
|
253
275
|
|
|
254
276
|
function getTimelineEntryUUID(inputObject, { defaults = {} } = {}) {
|
|
@@ -277,6 +299,7 @@ function getTimelineEntryUUID(inputObject, { defaults = {} } = {}) {
|
|
|
277
299
|
// may not match this standard, uuid sorting isn't guaranteed
|
|
278
300
|
return getUUIDv7(o.ts, uuid);
|
|
279
301
|
}
|
|
302
|
+
o.entry_type_id = getEntryTypeId(o);
|
|
280
303
|
|
|
281
304
|
const missing = requiredTimelineEntryFields.filter((d) => o[d] === undefined); // 0 could be an entry type value
|
|
282
305
|
|
|
@@ -298,27 +321,6 @@ function getTimelineEntryUUID(inputObject, { defaults = {} } = {}) {
|
|
|
298
321
|
// may not match this standard, uuid sorting isn't guaranteed
|
|
299
322
|
return getUUIDv7(ts, uuid);
|
|
300
323
|
}
|
|
301
|
-
function getEntryTypeId(o, { defaults = {} } = {}) {
|
|
302
|
-
let id = o.entry_type_id || defaults.entry_type_id;
|
|
303
|
-
if (id) return id;
|
|
304
|
-
const etype = o.entry_type || defaults.entry_type;
|
|
305
|
-
if (!etype) {
|
|
306
|
-
throw new Error('No entry_type, nor entry_type_id specified, specify a defaultEntryType');
|
|
307
|
-
}
|
|
308
|
-
id = TIMELINE_ENTRY_TYPES[etype];
|
|
309
|
-
if (id === undefined) throw new Error(`Invalid entry_type: ${etype}`);
|
|
310
|
-
return id;
|
|
311
|
-
}
|
|
312
|
-
function getEntryType(o, defaults = {}) {
|
|
313
|
-
let etype = o.entry_type || defaults.entry_type;
|
|
314
|
-
if (etype) return etype;
|
|
315
|
-
|
|
316
|
-
const id = o.entry_type_id || defaults.entry_type_id;
|
|
317
|
-
|
|
318
|
-
etype = TIMELINE_ENTRY_TYPES[id];
|
|
319
|
-
if (etype === undefined) throw new Error(`Invalid entry_type: ${etype}`);
|
|
320
|
-
return etype;
|
|
321
|
-
}
|
|
322
324
|
|
|
323
325
|
function getDateRangeArray(startDate, endDate) {
|
|
324
326
|
const start = new Date(startDate);
|