@engine9-io/input-tools 1.9.8 → 1.9.10
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/file/FileUtilities.js +1 -1
- package/file/S3.js +15 -3
- package/index.js +24 -22
- package/package.json +1 -1
package/file/FileUtilities.js
CHANGED
|
@@ -734,7 +734,7 @@ Worker.prototype.listAll = async function ({ directory, start: s, end: e }) {
|
|
|
734
734
|
if (e) end = relativeDate(e).getTime();
|
|
735
735
|
if (directory.startsWith('s3://') || directory.startsWith('r2://')) {
|
|
736
736
|
const worker = new (directory.startsWith('r2://') ? R2Worker : S3Worker)(this);
|
|
737
|
-
return worker.listAll({ directory });
|
|
737
|
+
return worker.listAll({ directory, start, end });
|
|
738
738
|
}
|
|
739
739
|
const a = await fsp.readdir(directory, { recursive: true });
|
|
740
740
|
|
package/file/S3.js
CHANGED
|
@@ -11,7 +11,7 @@ const {
|
|
|
11
11
|
PutObjectCommand,
|
|
12
12
|
ListObjectsV2Command
|
|
13
13
|
} = require('@aws-sdk/client-s3');
|
|
14
|
-
const { getTempFilename } = require('./tools');
|
|
14
|
+
const { getTempFilename, relativeDate } = require('./tools');
|
|
15
15
|
|
|
16
16
|
function Worker() {
|
|
17
17
|
this.prefix = 's3';
|
|
@@ -261,9 +261,12 @@ Worker.prototype.list.metadata = {
|
|
|
261
261
|
}
|
|
262
262
|
};
|
|
263
263
|
/* List everything with the prefix */
|
|
264
|
-
Worker.prototype.listAll = async function (
|
|
264
|
+
Worker.prototype.listAll = async function (options) {
|
|
265
|
+
const { directory } = options;
|
|
265
266
|
if (!directory) throw new Error('directory is required');
|
|
266
267
|
let dir = directory;
|
|
268
|
+
const start = options.start && relativeDate(options.start);
|
|
269
|
+
const end = options.end && relativeDate(options.end);
|
|
267
270
|
while (dir.slice(-1) === '/') dir = dir.slice(0, -1);
|
|
268
271
|
const { Bucket, Key } = getParts(dir);
|
|
269
272
|
const s3Client = this.getClient();
|
|
@@ -281,7 +284,16 @@ Worker.prototype.listAll = async function ({ directory }) {
|
|
|
281
284
|
debug(`Sending List command with prefix ${Prefix} with ContinuationToken ${ContinuationToken}`);
|
|
282
285
|
|
|
283
286
|
const result = await s3Client.send(command);
|
|
284
|
-
const newFiles =
|
|
287
|
+
const newFiles =
|
|
288
|
+
result.Contents?.filter(({ LastModified }) => {
|
|
289
|
+
if (start && new Date(LastModified) < start) {
|
|
290
|
+
return false;
|
|
291
|
+
} else if (end && new Date(LastModified) > end) {
|
|
292
|
+
return false;
|
|
293
|
+
} else {
|
|
294
|
+
return true;
|
|
295
|
+
}
|
|
296
|
+
})?.map((d) => `${this.prefix}://${Bucket}/${d.Key}`) || [];
|
|
285
297
|
debug(`Retrieved ${newFiles.length} new files, total ${files.length},sample ${newFiles.slice(0, 3).join(',')}`);
|
|
286
298
|
files.push(...newFiles);
|
|
287
299
|
ContinuationToken = result.NextContinuationToken;
|
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 a defaultEntryType');
|
|
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
|
+
const 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
|
|
|
@@ -286,7 +309,7 @@ function getTimelineEntryUUID(inputObject, { defaults = {} } = {}) {
|
|
|
286
309
|
// attempted conversion here
|
|
287
310
|
|
|
288
311
|
if (isNaN(ts)) throw new Error(`getTimelineEntryUUID got an invalid date:${o.ts || '<blank>'}`);
|
|
289
|
-
const idString = `${ts.toISOString()}-${o.person_id}-${
|
|
312
|
+
const idString = `${ts.toISOString()}-${o.person_id}-${entry_type_id}-${o.source_code_id || 0}`;
|
|
290
313
|
|
|
291
314
|
if (!uuidIsValid(o.input_id)) {
|
|
292
315
|
throw new Error(`Invalid input_id:'${o.input_id}', type ${typeof o.input_id} -- should be a uuid`);
|
|
@@ -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);
|