@engine9/input-tools 2.0.7

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/test/file.js ADDED
@@ -0,0 +1,23 @@
1
+ import nodetest from 'node:test';
2
+ import assert from 'node:assert';
3
+ import * as debug$0 from 'debug';
4
+ import { FileUtilities } from '../index.js';
5
+ const { it } = nodetest;
6
+ const debug = debug$0('files');
7
+ it('Should list a directory', async () => {
8
+ const futil = new FileUtilities({ accountId: 'test' });
9
+ let files = await futil.list({ directory: '.' });
10
+ assert(files.length, 'Should have some files');
11
+ debug(files);
12
+ let startTest = await futil.list({ directory: '.', start: '2040-01-01' });
13
+ assert(startTest.length === 0, 'Should NOT have any files before future start date');
14
+ let endTest = await futil.list({ directory: '.', end: '1900-01-01' });
15
+ assert(endTest.length === 0, 'Should NOT have any files before past end date');
16
+ });
17
+ it('Should be able to analyze CSV files with and without header lines', async () => {
18
+ const futil = new FileUtilities({ accountId: 'test' });
19
+ const f1 = await futil.columns({ filename: import.meta.dirname + '/sample/fileWithHead.csv' });
20
+ assert.equal(f1.likelyHeaderLines, 1, 'Number of header lines should be 1');
21
+ const f2 = await futil.columns({ filename: import.meta.dirname + '/sample/fileWithoutHead.csv' });
22
+ assert.equal(f2.likelyHeaderLines, 0, 'Number of header lines should be 1');
23
+ });
@@ -0,0 +1,52 @@
1
+ import nodetest from 'node:test';
2
+ import assert from 'node:assert';
3
+ import * as debug$0 from 'debug';
4
+ import promises from 'node:timers/promises';
5
+ import { ForEachEntry } from '../../index.js';
6
+ const { describe, it } = nodetest;
7
+ const debug = debug$0('test:big-data');
8
+ const { setTimeout } = promises;
9
+ describe('big-data message: forEachPerson', async () => {
10
+ it('message: forEachPerson should loop through 1000000 sample people', async () => {
11
+ const messageContent = [];
12
+ let counter = 0;
13
+ const forEach = new ForEachEntry();
14
+ const output = await forEach.process({
15
+ // packet: '../1000000_person_message.packet.zip',
16
+ filename: '../1000000_person_message.packet/person/1000000_fake_people.csv',
17
+ batchSize: 10000,
18
+ concurrency: 1000,
19
+ progress: debug,
20
+ bindings: {
21
+ timelineOutputStream: { path: 'output.timeline' },
22
+ message: { path: 'file', filename: '../1000000_person_message.packet/message/message.json5' },
23
+ handlebars: { path: 'handlebars' }
24
+ },
25
+ async transform({ batch, message, handlebars, timelineOutputStream }) {
26
+ //const id = uuidv7();
27
+ //debug(`Processing batch of ${batch.length} - ${id}`);
28
+ if (!message?.content?.text) throw new Error(`Sample message has no content.text:${JSON.stringify(message)}`);
29
+ const template = handlebars.compile(message.content.text);
30
+ batch.forEach((person) => {
31
+ messageContent.push(template(person));
32
+ });
33
+ batch.forEach((p) => {
34
+ const o = {
35
+ person_id: p.person_id,
36
+ email: p.email,
37
+ entry_type: 'EMAIL_DELIVERED'
38
+ };
39
+ counter += 1;
40
+ //if (counter % 10000 === 0) debug(`*** Processed ${counter} items, last person_id=${p.person_id}`, o);
41
+ timelineOutputStream.push(o);
42
+ });
43
+ // debug(`Processed batch of size ${batch.length}`);
44
+ await setTimeout(Math.random() * 3000);
45
+ //debug(`Completed processing ${id}`);
46
+ }
47
+ });
48
+ debug(output);
49
+ assert.equal(counter, 1000000, `Expected to loop through 1000000 people, actual:${counter}`);
50
+ });
51
+ debug('Completed all tests');
52
+ });
@@ -0,0 +1,53 @@
1
+ import nodetest from 'node:test';
2
+ import assert from 'node:assert';
3
+ import * as debug$0 from 'debug';
4
+ import { ForEachEntry } from '../../index.js';
5
+ const { describe, it } = nodetest;
6
+ const debug = debug$0('test/forEach');
7
+ describe('Test Person File For Each', async () => {
8
+ it('forEachPerson Should loop through 1000 sample people', async () => {
9
+ let counter = 0;
10
+ const forEach = new ForEachEntry();
11
+ const result = await forEach.process({
12
+ packet: 'test/sample/1000_message.packet.zip',
13
+ batchSize: 50,
14
+ bindings: {
15
+ timelineOutputFileStream: {
16
+ path: 'output.timeline',
17
+ options: {
18
+ entry_type: 'ENTRY_OPTION'
19
+ }
20
+ },
21
+ sampleOutputFileStream: {
22
+ path: 'output.stream'
23
+ }
24
+ },
25
+ async transform(props) {
26
+ const { batch, timelineOutputFileStream, sampleOutputFileStream } = props;
27
+ batch.forEach((p) => {
28
+ if (Math.random() > 0.9) {
29
+ sampleOutputFileStream.push({
30
+ // for testing we don't need real person_ids
31
+ person_id: p.person_id || Math.floor(Math.random() * 1000000),
32
+ email: p.email,
33
+ entry_type: 'SAMPLE_OUTPUT'
34
+ });
35
+ }
36
+ timelineOutputFileStream.push({
37
+ // for testing we don't need real person_ids
38
+ person_id: p.person_id || Math.floor(Math.random() * 1000000),
39
+ email: p.email,
40
+ entry_type: 'EMAIL_DELIVERED'
41
+ });
42
+ });
43
+ batch.forEach(() => {
44
+ counter += 1;
45
+ });
46
+ }
47
+ });
48
+ assert(result.outputFiles?.timelineOutputFileStream?.[0]?.records);
49
+ assert(result.outputFiles?.sampleOutputFileStream?.[0]?.records);
50
+ assert.equal(counter, 1000, `Expected to loop through 1000 people, actual:${counter}`);
51
+ });
52
+ debug('Completed tests');
53
+ });
@@ -0,0 +1,54 @@
1
+ import nodetest from 'node:test';
2
+ import assert from 'node:assert';
3
+ import * as debug$0 from 'debug';
4
+ import { ForEachEntry } from '../../index.js';
5
+ const { describe, it } = nodetest;
6
+ const debug = debug$0('test/forEach');
7
+ describe('Test Person File For Each', async () => {
8
+ it('forEachPerson Should loop through 1000 sample people', async () => {
9
+ let counter = 0;
10
+ const forEach = new ForEachEntry();
11
+ const result = await forEach.process({
12
+ packet: 'test/sample/1000_message.packet.zip',
13
+ batchSize: 50,
14
+ bindings: {
15
+ timelineOutputFileStream: {
16
+ path: 'output.timeline',
17
+ options: {
18
+ entry_type: 'ENTRY_OPTION'
19
+ }
20
+ },
21
+ sampleOutputFileStream: {
22
+ path: 'output.stream'
23
+ }
24
+ },
25
+ async transform(props) {
26
+ const { batch, timelineOutputFileStream, sampleOutputFileStream } = props;
27
+ batch.forEach((p) => {
28
+ if (Math.random() > 0.9) {
29
+ sampleOutputFileStream.push({
30
+ // for testing we don't need real person_ids
31
+ person_id: p.person_id || Math.floor(Math.random() * 1000000),
32
+ email: p.email,
33
+ entry_type: 'SAMPLE_OUTPUT'
34
+ });
35
+ }
36
+ timelineOutputFileStream.push({
37
+ // for testing we don't need real person_ids
38
+ person_id: p.person_id || Math.floor(Math.random() * 1000000),
39
+ email: p.email,
40
+ entry_type: 'EMAIL_DELIVERED'
41
+ });
42
+ });
43
+ batch.forEach(() => {
44
+ counter += 1;
45
+ });
46
+ }
47
+ });
48
+ assert(result.outputFiles?.timelineOutputFileStream?.[0]?.records);
49
+ assert(result.outputFiles?.sampleOutputFileStream?.[0]?.records);
50
+ debug(result);
51
+ assert.equal(counter, 1000, `Expected to loop through 1000 people, actual:${counter}`);
52
+ });
53
+ debug('Completed tests');
54
+ });
@@ -0,0 +1,40 @@
1
+ import nodetest from 'node:test';
2
+ import assert from 'node:assert';
3
+ import * as debug$0 from 'debug';
4
+ import index from '../../index.js';
5
+ const { describe, it } = nodetest;
6
+ const debug = debug$0('message');
7
+ const { forEachPerson } = index;
8
+ describe('Test Person Packet Message For Each', async () => {
9
+ it('message: forEachPerson should loop through 1000 sample people', async () => {
10
+ const messageContent = [];
11
+ let counter = 0;
12
+ const results = await forEachPerson({
13
+ packet: 'test/sample/1000_message.packet.zip',
14
+ batchSize: 50,
15
+ bindings: {
16
+ timelineOutputStream: { type: 'output.timeline' },
17
+ message: { type: 'packet.message' },
18
+ handlebars: { type: 'handlebars' }
19
+ },
20
+ async transform({ batch, message, handlebars, timelineOutputStream }) {
21
+ const template = handlebars.compile(message.content.text);
22
+ batch.forEach((person) => {
23
+ messageContent.push(template(person));
24
+ });
25
+ batch.forEach(() => {
26
+ counter += 1;
27
+ });
28
+ batch.forEach((p) => {
29
+ timelineOutputStream.push({
30
+ person_id: p.person_id,
31
+ email: p.email,
32
+ entry_type: 'EMAIL_DELIVERED'
33
+ });
34
+ });
35
+ }
36
+ });
37
+ debug(results);
38
+ assert.equal(counter, 1000, `Expected to loop through 1000 people, actual:${counter}`);
39
+ });
40
+ });
@@ -0,0 +1,21 @@
1
+ import nodetest from 'node:test';
2
+ import assert from 'node:assert';
3
+ import * as debug from 'debug';
4
+ import { create, getManifest } from '../../index.js';
5
+ const { describe, it } = nodetest;
6
+ describe('Test Person Packet Creator', async () => {
7
+ const pfile = './test/sample/message/5_fake_people.csv';
8
+ it(`should create a zip file from directory ${process.cwd()} with path ${pfile}`, async () => {
9
+ const out = await create({
10
+ personFiles: [pfile],
11
+ messageFiles: 'test/sample/message/message.json5'
12
+ });
13
+ debug('Successfully created:', out);
14
+ return out;
15
+ });
16
+ it('should retrieve a manifest', async () => {
17
+ const manifest = await getManifest({ packet: './test/sample/5_message.packet.zip' });
18
+ assert.equal(typeof manifest, 'object', 'Manifest is not an object');
19
+ assert.equal(manifest.accountId, 'engine9', 'Manifest does not have an accountId=engine9');
20
+ });
21
+ });
Binary file
@@ -0,0 +1,3 @@
1
+ first,last,email,phone
2
+ Bob,Smith,test@test.com,(703) 555-5555
3
+ Jane,Doe,test2@test.com,(703) 555-5432
@@ -0,0 +1,2 @@
1
+ Bob,Smith,test@test.com,(703) 555-5555
2
+ Jane,Doe,test2@test.com,(703) 555-5432