@engine9-io/input-tools 1.7.0 → 1.7.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/ForEachEntry.js +21 -9
- package/package.json +1 -1
- package/test/packet/forEach.js +2 -2
package/ForEachEntry.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const fs = require('node:fs');
|
|
2
2
|
|
|
3
|
-
const { Writable } = require('node:stream');
|
|
3
|
+
const { Transform, Writable } = require('node:stream');
|
|
4
4
|
const { pipeline } = require('node:stream/promises');
|
|
5
5
|
const { throttle } = require('throttle-debounce');
|
|
6
6
|
const parallelTransform = require('parallel-transform');
|
|
@@ -35,15 +35,19 @@ class ForEachEntry {
|
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
return this.outputStreams[name].mutex.runExclusive(async () => {
|
|
38
|
-
const
|
|
39
|
-
|
|
38
|
+
const fileInfo = {
|
|
39
|
+
filename: await getTempFilename({ postfix }),
|
|
40
|
+
records: 0,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
debug(`Output file requested, writing output to to: ${fileInfo.filename}`);
|
|
40
44
|
const outputStream = new ValidatingReadable({
|
|
41
45
|
objectMode: true,
|
|
42
46
|
}, validatorFunction);
|
|
43
47
|
// eslint-disable-next-line no-underscore-dangle
|
|
44
48
|
outputStream._read = () => {};
|
|
45
49
|
|
|
46
|
-
const writeStream = fs.createWriteStream(
|
|
50
|
+
const writeStream = fs.createWriteStream(fileInfo.filename);
|
|
47
51
|
const finishWritingOutputPromise = new Promise((resolve, reject) => {
|
|
48
52
|
writeStream.on('finish', () => {
|
|
49
53
|
resolve();
|
|
@@ -52,15 +56,23 @@ class ForEachEntry {
|
|
|
52
56
|
});
|
|
53
57
|
});
|
|
54
58
|
|
|
55
|
-
outputStream
|
|
56
|
-
.pipe(csv.stringify({ header: true }))
|
|
57
|
-
.pipe(writeStream);
|
|
58
|
-
|
|
59
59
|
this.outputStreams[name].items = {
|
|
60
60
|
stream: outputStream,
|
|
61
61
|
promises: [finishWritingOutputPromise],
|
|
62
|
-
files: [
|
|
62
|
+
files: [fileInfo],
|
|
63
63
|
};
|
|
64
|
+
|
|
65
|
+
outputStream
|
|
66
|
+
.pipe(new Transform({
|
|
67
|
+
objectMode: true,
|
|
68
|
+
transform(o, enc, cb) {
|
|
69
|
+
fileInfo.records += 1;
|
|
70
|
+
cb();
|
|
71
|
+
},
|
|
72
|
+
}))
|
|
73
|
+
.pipe(csv.stringify({ header: true }))
|
|
74
|
+
.pipe(writeStream);
|
|
75
|
+
|
|
64
76
|
return this.outputStreams[name].items;
|
|
65
77
|
});
|
|
66
78
|
}
|
package/package.json
CHANGED
package/test/packet/forEach.js
CHANGED
|
@@ -55,8 +55,8 @@ describe('Test Person Packet For Each', async () => {
|
|
|
55
55
|
},
|
|
56
56
|
},
|
|
57
57
|
);
|
|
58
|
-
assert(result.outputFiles?.timelineOutputFileStream?.
|
|
59
|
-
assert(result.outputFiles?.sampleOutputFileStream?.
|
|
58
|
+
assert(result.outputFiles?.timelineOutputFileStream?.[0]?.records);
|
|
59
|
+
assert(result.outputFiles?.sampleOutputFileStream?.[0]?.records);
|
|
60
60
|
assert.equal(counter, 1000, `Expected to loop through 1000 people, actual:${counter}`);
|
|
61
61
|
});
|
|
62
62
|
debug('Completed tests');
|