@engine9-io/input-tools 1.4.0 → 1.4.2

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.
@@ -489,9 +489,9 @@ Worker.prototype.stream = async function (
489
489
  } else if (filename) {
490
490
  if (filename.startsWith('engine9-accounts/')) {
491
491
  filename = `${process.env.ENGINE9_ACCOUNT_DIR}/${filename.slice('engine9-accounts/'.length)}`;
492
- debug(`Prepending file with ${process.env.ENGINE9_ACCOUNT_DIR}, filename=${filename}`);
492
+ // debug(`Prepending file with ${process.env.ENGINE9_ACCOUNT_DIR}, filename=${filename}`);
493
493
  } else {
494
- debug(`Not prepending filename:${filename}`);
494
+ // debug(`Not prepending filename:${filename}`);
495
495
  }
496
496
  let encoding; let stream;
497
497
  if (filename.slice(-8) === '.parquet') {
@@ -649,9 +649,16 @@ Worker.prototype.empty.metadata = {
649
649
  };
650
650
 
651
651
  Worker.prototype.move = async function ({ filename, target }) {
652
- if (!target) throw new Error('directory is required');
652
+ if (!target) throw new Error('target is required');
653
653
  if (target.indexOf('s3://') === 0) {
654
654
  const s3Worker = new S3Worker(this);
655
+
656
+ if (filename.indexOf('s3://') === 0) {
657
+ // We need to copy and delete
658
+ const output = await s3Worker.copy({ filename, target });
659
+ await s3Worker.remove({ filename });
660
+ return output;
661
+ }
655
662
  const parts = target.split('/');
656
663
  return s3Worker.put({ filename, directory: parts.slice(0, -1).join('/'), file: parts.slice(-1)[0] });
657
664
  }
package/file/S3.js CHANGED
@@ -1,9 +1,11 @@
1
- const debug = require('debug')('S3Worker');
1
+ const debug = require('debug')('@engine9-io/input/S3');
2
2
  const fs = require('node:fs');
3
3
  // eslint-disable-next-line import/no-unresolved
4
4
  const { mimeType: mime } = require('mime-type/with-db');
5
5
  const {
6
6
  S3Client,
7
+ CopyObjectCommand,
8
+ DeleteObjectCommand,
7
9
  GetObjectCommand,
8
10
  HeadObjectCommand,
9
11
  GetObjectAttributesCommand, PutObjectCommand,
@@ -44,7 +46,7 @@ Worker.prototype.getMetadata.metadata = {
44
46
  };
45
47
 
46
48
  Worker.prototype.stream = async function ({ filename }) {
47
- const s3Client = new S3Client({});
49
+ const s3Client = this.getClient();
48
50
  const { Bucket, Key } = getParts(filename);
49
51
  const command = new GetObjectCommand({ Bucket, Key });
50
52
  try {
@@ -62,6 +64,41 @@ Worker.prototype.stream.metadata = {
62
64
  },
63
65
  };
64
66
 
67
+ Worker.prototype.copy = async function ({ filename, target }) {
68
+ if (!filename.startsWith('s3://')) throw new Error('Cowardly not copying a file not from s3 -- use put instead');
69
+ const s3Client = this.getClient();
70
+ const { Bucket, Key } = getParts(target);
71
+
72
+ debug(`Copying ${filename} to ${JSON.stringify({ Bucket, Key })}}`);
73
+
74
+ const command = new CopyObjectCommand({
75
+ CopySource: filename.slice(4), // remove the s3:/
76
+ Bucket,
77
+ Key,
78
+ });
79
+
80
+ return s3Client.send(command);
81
+ };
82
+
83
+ Worker.prototype.copy.metadata = {
84
+ options: {
85
+ filename: {},
86
+ target: {},
87
+ },
88
+ };
89
+
90
+ Worker.prototype.remove = async function ({ filename }) {
91
+ const s3Client = this.getClient();
92
+ const { Bucket, Key } = getParts(filename);
93
+ const command = new DeleteObjectCommand({ Bucket, Key });
94
+ return s3Client.send(command);
95
+ };
96
+ Worker.prototype.remove.metadata = {
97
+ options: {
98
+ filename: {},
99
+ },
100
+ };
101
+
65
102
  Worker.prototype.download = async function ({ filename }) {
66
103
  const file = filename.split('/').pop();
67
104
  const localPath = await getTempFilename({ targetFilename: file });
@@ -182,7 +219,7 @@ Worker.prototype.listAll = async function ({ directory }) {
182
219
  let dir = directory;
183
220
  while (dir.slice(-1) === '/') dir = dir.slice(0, -1);
184
221
  const { Bucket, Key: Prefix } = getParts(dir);
185
- const s3Client = new S3Client({});
222
+ const s3Client = this.getClient();
186
223
  const files = [];
187
224
  let ContinuationToken = null;
188
225
  do {
@@ -192,7 +229,7 @@ Worker.prototype.listAll = async function ({ directory }) {
192
229
  ContinuationToken,
193
230
  // Delimiter: '/',
194
231
  });
195
- debug(`Sending command with ContinuationToken ${ContinuationToken}`);
232
+ debug(`Sending List command with prefix ${Prefix} with ContinuationToken ${ContinuationToken}`);
196
233
  // eslint-disable-next-line no-await-in-loop
197
234
  const result = await s3Client.send(command);
198
235
  const newFiles = (result.Contents?.map((d) => `s3://${Bucket}/${d.Key}`) || []);
package/index.js CHANGED
@@ -364,6 +364,10 @@ function getTimelineEntryUUID(inputObject, { defaults = {} } = {}) {
364
364
  // eslint-disable-next-line no-restricted-globals
365
365
  if (isNaN(ts)) throw new Error(`getTimelineEntryUUID got an invalid date:${o.ts || '<blank>'}`);
366
366
  const idString = `${ts.toISOString()}-${o.person_id}-${o.entry_type_id}-${o.source_code_id || 0}`;
367
+
368
+ if (!uuidIsValid(o.input_id)) {
369
+ throw new Error(`Invalid input_id:'${o.input_id}', type ${typeof o.input_id} -- should be a uuid`);
370
+ }
367
371
  // get a temp ID
368
372
  const uuid = uuidv5(idString, o.input_id);
369
373
  // Change out the ts to match the v7 sorting.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@engine9-io/input-tools",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Tools for dealing with Engine9 inputs",
5
5
  "main": "index.js",
6
6
  "scripts": {