@engine9-io/input-tools 1.3.9 → 1.4.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.
Files changed (3) hide show
  1. package/file/S3.js +1 -1
  2. package/index.js +74 -5
  3. package/package.json +1 -1
package/file/S3.js CHANGED
@@ -192,7 +192,7 @@ Worker.prototype.listAll = async function ({ directory }) {
192
192
  ContinuationToken,
193
193
  // Delimiter: '/',
194
194
  });
195
- debug(`Sending command with ContinuationToken ${ContinuationToken}`);
195
+ debug(`Sending List command with prefix ${Prefix} with ContinuationToken ${ContinuationToken}`);
196
196
  // eslint-disable-next-line no-await-in-loop
197
197
  const result = await s3Client.send(command);
198
198
  const newFiles = (result.Contents?.map((d) => `s3://${Bucket}/${d.Key}`) || []);
package/index.js CHANGED
@@ -58,6 +58,73 @@ function getStringArray(s, nonZeroLength) {
58
58
  return a;
59
59
  }
60
60
 
61
+ function isValidDate(d) {
62
+ // we WANT to use isNaN, not the Number.isNaN -- we're checking the date type
63
+ // eslint-disable-next-line no-restricted-globals
64
+ return d instanceof Date && !isNaN(d);
65
+ }
66
+
67
+ function relativeDate(s, _initialDate) {
68
+ let initialDate = _initialDate;
69
+ if (!s || s === 'none') return null;
70
+ if (typeof s.getMonth === 'function') return s;
71
+ // We actually want a double equals here to test strings as well
72
+ // eslint-disable-next-line eqeqeq
73
+ if (parseInt(s, 10) == s) {
74
+ const r = new Date(parseInt(s, 10));
75
+ if (!isValidDate(r)) throw new Error(`Invalid integer date:${s}`);
76
+ return r;
77
+ }
78
+
79
+ if (initialDate) {
80
+ initialDate = new Date(initialDate);
81
+ } else {
82
+ initialDate = new Date();
83
+ }
84
+
85
+ let r = s.match(/^([+-]{1})([0-9]+)([YyMwdhms]{1})([.a-z]*)$/);
86
+
87
+ if (r) {
88
+ let period = null;
89
+ switch (r[3]) {
90
+ case 'Y':
91
+ case 'y': period = 'years'; break;
92
+
93
+ case 'M': period = 'months'; break;
94
+ case 'w': period = 'weeks'; break;
95
+ case 'd': period = 'days'; break;
96
+ case 'h': period = 'hours'; break;
97
+ case 'm': period = 'minutes'; break;
98
+ case 's': period = 'seconds'; break;
99
+ default: period = 'minutes'; break;
100
+ }
101
+
102
+ let d = dayjs(initialDate);
103
+
104
+ if (r[1] === '+') {
105
+ d = d.add(parseInt(r[2], 10), period);
106
+ } else {
107
+ d = d.subtract(parseInt(r[2], 10), period);
108
+ }
109
+ if (!isValidDate(d.toDate())) throw new Error(`Invalid date configuration:${r}`);
110
+ if (r[4]) {
111
+ const opts = r[4].split('.').filter(Boolean);
112
+ if (opts[0] === 'start') d = d.startOf(opts[1] || 'day');
113
+ else if (opts[0] === 'end') d = d.endOf(opts[1] || 'day');
114
+ else throw new Error(`Invalid relative date,unknown options:${r[4]}`);
115
+ }
116
+
117
+ return d.toDate();
118
+ }
119
+ if (s === 'now') {
120
+ r = dayjs(new Date()).toDate();
121
+ return r;
122
+ }
123
+ r = dayjs(new Date(s)).toDate();
124
+ if (!isValidDate(r)) throw new Error(`Invalid Date: ${s}`);
125
+ return r;
126
+ }
127
+
61
128
  /*
62
129
  When comparing two objects, some may come from a file (thus strings), and some from
63
130
  a database or elsewhere (not strings), so for deduping make sure to make them all strings
@@ -322,6 +389,8 @@ module.exports = {
322
389
  list,
323
390
  downloadFile,
324
391
  extract,
392
+ ForEachEntry,
393
+ FileUtilities,
325
394
  getBatchTransform,
326
395
  getDebatchTransform,
327
396
  getManifest,
@@ -337,13 +406,13 @@ module.exports = {
337
406
  getUUIDTimestamp,
338
407
  getEntryTypeId,
339
408
  handlebars,
409
+ isValidDate,
410
+ makeStrings,
411
+ relativeDate,
412
+ streamPacket,
413
+ TIMELINE_ENTRY_TYPES,
340
414
  uuidIsValid,
341
415
  uuidv4,
342
416
  uuidv5,
343
417
  uuidv7,
344
- makeStrings,
345
- ForEachEntry,
346
- FileUtilities,
347
- streamPacket,
348
- TIMELINE_ENTRY_TYPES,
349
418
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@engine9-io/input-tools",
3
- "version": "1.3.9",
3
+ "version": "1.4.1",
4
4
  "description": "Tools for dealing with Engine9 inputs",
5
5
  "main": "index.js",
6
6
  "scripts": {