diff --git a/packages/transformers/src/dollar-array.spec.js b/packages/transformers/src/dollar-array.spec.js new file mode 100644 index 00000000..7dc7cc4b --- /dev/null +++ b/packages/transformers/src/dollar-array.spec.js @@ -0,0 +1,40 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$ARRAY', () => { + test('with valid parameter', (done) => { + const script = ` + [$ARRAY] + field = b + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: 1, b: 'un deux', c: true }, + { a: 2, b: 'un trois', c: true }, + { a: 3, b: 'un quatre', c: false }, + { a: 4, b: 'un cinq', c: true }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].b[0]).toEqual('un deux'); + expect(output[1].b[0]).toEqual('un trois'); + expect(output[2].b[0]).toEqual('un quatre'); + expect(output[3].b[0]).toEqual('un cinq'); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-autogenerate-uri.js b/packages/transformers/src/dollar-autogenerate-uri.js index b2a9cb7e..70946309 100644 --- a/packages/transformers/src/dollar-autogenerate-uri.js +++ b/packages/transformers/src/dollar-autogenerate-uri.js @@ -9,5 +9,5 @@ import dollar from './dollar'; * @returns {Object} */ export default function $AUTOGENERATE_URI(data, feed) { - return dollar(this, data, feed, transformer); + return dollar(this, data, feed, transformer, data); } diff --git a/packages/transformers/src/dollar-autogenerate-uri.spec.js b/packages/transformers/src/dollar-autogenerate-uri.spec.js new file mode 100644 index 00000000..6a6ea7e7 --- /dev/null +++ b/packages/transformers/src/dollar-autogenerate-uri.spec.js @@ -0,0 +1,43 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$AUTOGENERATE_URI', () => { + test('with valid parameter', (done) => { + const script = ` + [$AUTOGENERATE_URI] + field = d + naan = 12345 + subpublisher = WXZ + uriSize = 8 + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: '1', b: 'un', c: true }, + { a: '2', b: 'deux', c: true }, + { a: '3', b: 'trois', c: false }, + { a: '4', b: 'quatre', c: true }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].d).not.toBeNull(); + expect(output[1].d).not.toEqual(); + expect(output[2].d).not.toEqual(); + expect(output[3].d).not.toEqual(); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-boolean.spec.js b/packages/transformers/src/dollar-boolean.spec.js new file mode 100644 index 00000000..7e24748c --- /dev/null +++ b/packages/transformers/src/dollar-boolean.spec.js @@ -0,0 +1,40 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$BOOLEAN', () => { + test('with valid parameter', (done) => { + const script = ` + [$BOOLEAN] + field = c + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: 1, b: 'un deux', c: 'true' }, + { a: 2, b: 'un trois', c: true }, + { a: 3, b: 'un quatre', c: 1 }, + { a: 4, b: 'un cinq', c: 'OK' }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].c).toEqual(true); + expect(output[1].c).toEqual(true); + expect(output[2].c).toEqual(true); + expect(output[3].c).toEqual(true); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-capitalize.spec.js b/packages/transformers/src/dollar-capitalize.spec.js new file mode 100644 index 00000000..3de01c1b --- /dev/null +++ b/packages/transformers/src/dollar-capitalize.spec.js @@ -0,0 +1,40 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$CAPITALIZE', () => { + test('with valid parameter', (done) => { + const script = ` + [$CAPITALIZE] + field= b + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: 1, b: 'un deux', c: true }, + { a: 2, b: 'un trois', c: true }, + { a: 3, b: 'un quatre', c: false }, + { a: 4, b: 'un cinq', c: true }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].b).toEqual('Un deux'); + expect(output[1].b).toEqual('Un trois'); + expect(output[2].b).toEqual('Un quatre'); + expect(output[3].b).toEqual('Un cinq'); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-column.js b/packages/transformers/src/dollar-column.js index 94c1bb56..2c0fae18 100644 --- a/packages/transformers/src/dollar-column.js +++ b/packages/transformers/src/dollar-column.js @@ -9,5 +9,5 @@ import dollar from './dollar'; * @returns {Object} */ export default function $COLUMN(data, feed) { - return dollar(this, data, feed, transformer); + return dollar(this, data, feed, transformer, data); } diff --git a/packages/transformers/src/dollar-column.spec.js b/packages/transformers/src/dollar-column.spec.js new file mode 100644 index 00000000..6ead96de --- /dev/null +++ b/packages/transformers/src/dollar-column.spec.js @@ -0,0 +1,41 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$COLUMN', () => { + test('with valid parameter', (done) => { + const script = ` + [$COLUMN] + field = d + column = b + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: '1', b: 'un', c: true }, + { a: '2', b: 'deux', c: true }, + { a: '3', b: 'trois', c: false }, + { a: '4', b: 'quatre', c: true }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].d).toEqual('un'); + expect(output[1].d).toEqual('deux'); + expect(output[2].d).toEqual('trois'); + expect(output[3].d).toEqual('quatre'); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-concat-uri.js b/packages/transformers/src/dollar-concat-uri.js index e8506432..74c3641b 100644 --- a/packages/transformers/src/dollar-concat-uri.js +++ b/packages/transformers/src/dollar-concat-uri.js @@ -9,5 +9,5 @@ import dollar from './dollar'; * @returns {Object} */ export default function $CONCAT_URI(data, feed) { - return dollar(this, data, feed, transformer); + return dollar(this, data, feed, transformer, data); } diff --git a/packages/transformers/src/dollar-concat-uri.spec.js b/packages/transformers/src/dollar-concat-uri.spec.js new file mode 100644 index 00000000..3d647321 --- /dev/null +++ b/packages/transformers/src/dollar-concat-uri.spec.js @@ -0,0 +1,43 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$CONCAT_URI', () => { + test('with valid parameter', (done) => { + const script = ` + [$CONCAT_URI] + field = d + column = a + column = b + separator = % + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: '1', b: 'un', c: true }, + { a: '2', b: 'deux', c: true }, + { a: '3', b: 'trois', c: false }, + { a: '4', b: 'quatre', c: true }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].d).toEqual('1%un'); + expect(output[1].d).toEqual('2%deux'); + expect(output[2].d).toEqual('3%trois'); + expect(output[3].d).toEqual('4%quatre'); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-concat.js b/packages/transformers/src/dollar-concat.js index ec004d1a..b2bd8881 100644 --- a/packages/transformers/src/dollar-concat.js +++ b/packages/transformers/src/dollar-concat.js @@ -9,5 +9,5 @@ import dollar from './dollar'; * @returns {Object} */ export default function $CONCAT(data, feed) { - return dollar(this, data, feed, transformer); + return dollar(this, data, feed, transformer, data); } diff --git a/packages/transformers/src/dollar-concat.spec.js b/packages/transformers/src/dollar-concat.spec.js new file mode 100644 index 00000000..2c368b38 --- /dev/null +++ b/packages/transformers/src/dollar-concat.spec.js @@ -0,0 +1,46 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$CONCAT', () => { + test('with valid parameter', (done) => { + const script = ` + [$CONCAT] + field = d + columns = a + columns = b + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: '1', b: 'un', c: true }, + { a: '2', b: 'deux', c: true }, + { a: '3', b: 'trois', c: false }, + { a: '4', b: 'quatre', c: true }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].d[0]).toEqual('1'); + expect(output[0].d[1]).toEqual('un'); + expect(output[1].d[0]).toEqual('2'); + expect(output[1].d[1]).toEqual('deux'); + expect(output[2].d[0]).toEqual('3'); + expect(output[2].d[1]).toEqual('trois'); + expect(output[3].d[0]).toEqual('4'); + expect(output[3].d[1]).toEqual('quatre'); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-default.spec.js b/packages/transformers/src/dollar-default.spec.js new file mode 100644 index 00000000..2a9c6958 --- /dev/null +++ b/packages/transformers/src/dollar-default.spec.js @@ -0,0 +1,41 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$DEFAULT', () => { + test('with valid parameter', (done) => { + const script = ` + [$DEFAULT] + field = b + alternative = un quatre + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: 1, b: 'un deux', c: true }, + { a: 2, b: 'un trois', c: true }, + { a: 3, b: null, c: false }, + { a: 4, b: 'un cinq', c: true }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].b).toEqual('un deux'); + expect(output[1].b).toEqual('un trois'); + expect(output[2].b).toEqual('un quatre'); + expect(output[3].b).toEqual('un cinq'); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-format.spec.js b/packages/transformers/src/dollar-format.spec.js new file mode 100644 index 00000000..02e04876 --- /dev/null +++ b/packages/transformers/src/dollar-format.spec.js @@ -0,0 +1,42 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$FORMAT', () => { + test('with valid parameter', (done) => { + const script = ` + [$FORMAT] + field = b + with = (%s:%s) + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: 1, b: ['un', 'trois'] }, + { a: 2, b: ['un', 'quatre'] }, + { a: 3, b: ['un', 'cinq'] }, + { a: 4, b: ['un', 'six'] }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].b).toEqual('(un:trois)'); + expect(output[1].b).toEqual('(un:quatre)'); + expect(output[2].b).toEqual('(un:cinq)'); + expect(output[3].b).toEqual('(un:six)'); + + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-get.spec.js b/packages/transformers/src/dollar-get.spec.js new file mode 100644 index 00000000..7c31b48f --- /dev/null +++ b/packages/transformers/src/dollar-get.spec.js @@ -0,0 +1,41 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$GET', () => { + test('with valid parameter', (done) => { + const script = ` + [$GET] + field = c + path = d + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: 1, b: 'un deux', c: { d: 'OK' } }, + { a: 2, b: 'un trois', c: { d: 'OK' } }, + { a: 3, b: 'un quatre', c: { d: 'OK' } }, + { a: 4, b: 'un cinq', c: { d: 'OK' } }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].c).toEqual('OK'); + expect(output[1].c).toEqual('OK'); + expect(output[2].c).toEqual('OK'); + expect(output[3].c).toEqual('OK'); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-join.spec.js b/packages/transformers/src/dollar-join.spec.js new file mode 100644 index 00000000..28ac8979 --- /dev/null +++ b/packages/transformers/src/dollar-join.spec.js @@ -0,0 +1,41 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$JOIN', () => { + test('with valid parameter', (done) => { + const script = ` + [$JOIN] + field = b + separator = fix(' ') + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: 1, b: ['un', 'deux', 'trois'] }, + { a: 2, b: ['un', 'deux', 'quatre'] }, + { a: 3, b: ['un', 'deux', 'cinq'] }, + { a: 4, b: ['un', 'deux', 'six'] }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].b).toEqual('un deux trois'); + expect(output[1].b).toEqual('un deux quatre'); + expect(output[2].b).toEqual('un deux cinq'); + expect(output[3].b).toEqual('un deux six'); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-lowercase.spec.js b/packages/transformers/src/dollar-lowercase.spec.js new file mode 100644 index 00000000..5da2c7ba --- /dev/null +++ b/packages/transformers/src/dollar-lowercase.spec.js @@ -0,0 +1,40 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$LOWERCASE', () => { + test('with valid parameter', (done) => { + const script = ` + [$LOWERCASE] + field = b + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: 1, b: 'UN DEUX', c: true }, + { a: 2, b: 'UN TROIS', c: true }, + { a: 3, b: 'UN QUATRE', c: false }, + { a: 4, b: 'UN CINQ', c: true }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].b).toEqual('un deux'); + expect(output[1].b).toEqual('un trois'); + expect(output[2].b).toEqual('un quatre'); + expect(output[3].b).toEqual('un cinq'); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-mask.spec.js b/packages/transformers/src/dollar-mask.spec.js new file mode 100644 index 00000000..1aaee2db --- /dev/null +++ b/packages/transformers/src/dollar-mask.spec.js @@ -0,0 +1,41 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$MASK', () => { + test('with valid parameter', (done) => { + const script = ` + [$MASK] + field = b + with = ^[a-z]+$ + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: 1, b: 'deux', c: true }, + { a: 2, b: 'trois', c: true }, + { a: 3, b: 'un quatre', c: false }, + { a: 4, b: 'cinq', c: true }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].b).toEqual('deux'); + expect(output[1].b).toEqual('trois'); + expect(output[2].b).toBeNull(); + expect(output[3].b).toEqual('cinq'); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-number.spec.js b/packages/transformers/src/dollar-number.spec.js new file mode 100644 index 00000000..917f824e --- /dev/null +++ b/packages/transformers/src/dollar-number.spec.js @@ -0,0 +1,40 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$NUMBER', () => { + test('with valid parameter', (done) => { + const script = ` + [$NUMBER] + field = a + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: '1', b: 'un deux', c: true }, + { a: '2', b: 'un trois', c: true }, + { a: '3', b: 'un quatre', c: false }, + { a: '4', b: 'un cinq', c: true }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].a).toEqual(1); + expect(output[1].a).toEqual(2); + expect(output[2].a).toEqual(3); + expect(output[3].a).toEqual(4); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-parse.spec.js b/packages/transformers/src/dollar-parse.spec.js new file mode 100644 index 00000000..6ecba4e7 --- /dev/null +++ b/packages/transformers/src/dollar-parse.spec.js @@ -0,0 +1,40 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$PARSE', () => { + test('with valid parameter', (done) => { + const script = ` + [$PARSE] + field = b + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: 1, b: '"un deux"', c: true }, + { a: 2, b: '"un trois"', c: true }, + { a: 3, b: '"un quatre"', c: false }, + { a: 4, b: '"un cinq"', c: true }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].b).toEqual('un deux'); + expect(output[1].b).toEqual('un trois'); + expect(output[2].b).toEqual('un quatre'); + expect(output[3].b).toEqual('un cinq'); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-prefix.spec.js b/packages/transformers/src/dollar-prefix.spec.js new file mode 100644 index 00000000..0fd9a86b --- /dev/null +++ b/packages/transformers/src/dollar-prefix.spec.js @@ -0,0 +1,41 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$PREFIX', () => { + test('with valid parameter', (done) => { + const script = ` + [$PREFIX] + field = b + with = > + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: 1, b: 'un deux', c: true }, + { a: 2, b: 'un trois', c: true }, + { a: 3, b: 'un quatre', c: false }, + { a: 4, b: 'un cinq', c: true }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].b).toEqual('>un deux'); + expect(output[1].b).toEqual('>un trois'); + expect(output[2].b).toEqual('>un quatre'); + expect(output[3].b).toEqual('>un cinq'); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-remove.spec.js b/packages/transformers/src/dollar-remove.spec.js new file mode 100644 index 00000000..846b2bc8 --- /dev/null +++ b/packages/transformers/src/dollar-remove.spec.js @@ -0,0 +1,45 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$REMOVE', () => { + test('with valid parameter', (done) => { + const script = ` + [$REMOVE] + field = b + the = un + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: 1, b: ['un', 'deux', 'trois'] }, + { a: 2, b: ['un', 'deux', 'quatre'] }, + { a: 3, b: ['un', 'deux', 'cinq'] }, + { a: 4, b: ['un', 'deux', 'six'] }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].b.length).toEqual(2); + expect(output[0].b[1]).toEqual('trois'); + expect(output[1].b.length).toEqual(2); + expect(output[1].b[1]).toEqual('quatre'); + expect(output[2].b.length).toEqual(2); + expect(output[2].b[1]).toEqual('cinq'); + expect(output[3].b.length).toEqual(2); + expect(output[3].b[1]).toEqual('six'); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-replace.spec.js b/packages/transformers/src/dollar-replace.spec.js index 8119fd3c..24f7b097 100644 --- a/packages/transformers/src/dollar-replace.spec.js +++ b/packages/transformers/src/dollar-replace.spec.js @@ -8,7 +8,7 @@ describe('$REPLACE', () => { test('with valid parameter', (done) => { const script = ` [$REPLACE] - path = b + field = b searchValue = un replaceValue = 1 @@ -30,7 +30,7 @@ describe('$REPLACE', () => { res.push(chunk); }) .on('end', () => { - expect(res.length).toBe(4) + expect(res.length).toBe(4); expect(res[0].b).toEqual('1 deux'); expect(res[1].b).toEqual('1 trois'); expect(res[2].b).toEqual('1 quatre'); diff --git a/packages/transformers/src/dollar-select.spec.js b/packages/transformers/src/dollar-select.spec.js new file mode 100644 index 00000000..b58ab550 --- /dev/null +++ b/packages/transformers/src/dollar-select.spec.js @@ -0,0 +1,41 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$SELECT', () => { + test('with valid parameter', (done) => { + const script = ` + [$SELECT] + field = c + path = d + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: 1, b: 'un deux', c: { d: 'OK' } }, + { a: 2, b: 'un trois', c: { d: 'OK' } }, + { a: 3, b: 'un quatre', c: { d: 'OK' } }, + { a: 4, b: 'un cinq', c: { d: 'OK' } }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].c).toEqual('OK'); + expect(output[1].c).toEqual('OK'); + expect(output[2].c).toEqual('OK'); + expect(output[3].c).toEqual('OK'); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-shift.spec.js b/packages/transformers/src/dollar-shift.spec.js new file mode 100644 index 00000000..327ea4e3 --- /dev/null +++ b/packages/transformers/src/dollar-shift.spec.js @@ -0,0 +1,45 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$SHIFT', () => { + test('with valid parameter', (done) => { + const script = ` + [$SHIFT] + field = b + gap = 2 + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: 1, b: ['un', 'deux', 'trois'] }, + { a: 2, b: ['un', 'deux', 'quatre'] }, + { a: 3, b: ['un', 'deux', 'cinq'] }, + { a: 4, b: ['un', 'deux', 'six'] }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].b.length).toEqual(1); + expect(output[0].b[0]).toEqual('trois'); + expect(output[1].b.length).toEqual(1); + expect(output[1].b[0]).toEqual('quatre'); + expect(output[2].b.length).toEqual(1); + expect(output[2].b[0]).toEqual('cinq'); + expect(output[3].b.length).toEqual(1); + expect(output[3].b[0]).toEqual('six'); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-split.spec.js b/packages/transformers/src/dollar-split.spec.js new file mode 100644 index 00000000..813b72c8 --- /dev/null +++ b/packages/transformers/src/dollar-split.spec.js @@ -0,0 +1,41 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$SPLIT', () => { + test('with valid parameter', (done) => { + const script = ` + [$SPLIT] + field = b + separator = fix(' ') + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: 1, b: 'un deux', c: true }, + { a: 2, b: 'un trois', c: true }, + { a: 3, b: 'un quatre', c: false }, + { a: 4, b: 'un cinq', c: true }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].b[1]).toEqual('deux'); + expect(output[1].b[1]).toEqual('trois'); + expect(output[2].b[1]).toEqual('quatre'); + expect(output[3].b[1]).toEqual('cinq'); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-string.spec.js b/packages/transformers/src/dollar-string.spec.js new file mode 100644 index 00000000..7ea81e3d --- /dev/null +++ b/packages/transformers/src/dollar-string.spec.js @@ -0,0 +1,40 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$STRING', () => { + test('with valid parameter', (done) => { + const script = ` + [$STRING] + field = a + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: 1, b: 'un deux', c: true }, + { a: 2, b: 'un trois', c: true }, + { a: 3, b: 'un quatre', c: false }, + { a: 4, b: 'un cinq', c: true }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].a).toEqual('1'); + expect(output[1].a).toEqual('2'); + expect(output[2].a).toEqual('3'); + expect(output[3].a).toEqual('4'); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-suffix.spec.js b/packages/transformers/src/dollar-suffix.spec.js new file mode 100644 index 00000000..5f18cf1c --- /dev/null +++ b/packages/transformers/src/dollar-suffix.spec.js @@ -0,0 +1,41 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$SUFFIX', () => { + test('with valid parameter', (done) => { + const script = ` + [$SUFFIX] + field = b + with = ! + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: 1, b: 'un deux', c: true }, + { a: 2, b: 'un trois', c: true }, + { a: 3, b: 'un quatre', c: false }, + { a: 4, b: 'un cinq', c: true }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].b).toEqual('un deux!'); + expect(output[1].b).toEqual('un trois!'); + expect(output[2].b).toEqual('un quatre!'); + expect(output[3].b).toEqual('un cinq!'); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-trim.spec.js b/packages/transformers/src/dollar-trim.spec.js new file mode 100644 index 00000000..85820d39 --- /dev/null +++ b/packages/transformers/src/dollar-trim.spec.js @@ -0,0 +1,41 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$TRIM', () => { + test('with valid parameter', (done) => { + const script = ` + [$TRIM] + field = b + gap = 3 + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: 1, b: ' un deux', c: true }, + { a: 2, b: ' un trois ', c: true }, + { a: 3, b: 'un quatre ', c: false }, + { a: 4, b: 'un cinq', c: true }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].b).toEqual('un deux'); + expect(output[1].b).toEqual('un trois'); + expect(output[2].b).toEqual('un quatre'); + expect(output[3].b).toEqual('un cinq'); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-truncate.spec.js b/packages/transformers/src/dollar-truncate.spec.js new file mode 100644 index 00000000..e26dbf97 --- /dev/null +++ b/packages/transformers/src/dollar-truncate.spec.js @@ -0,0 +1,41 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$TRUNCATE', () => { + test('with valid parameter', (done) => { + const script = ` + [$TRUNCATE] + field = b + gap = 2 + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: 1, b: 'un deux', c: true }, + { a: 2, b: 'un trois', c: true }, + { a: 3, b: 'un quatre', c: false }, + { a: 4, b: 'un cinq', c: true }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].b).toEqual('un'); + expect(output[1].b).toEqual('un'); + expect(output[2].b).toEqual('un'); + expect(output[3].b).toEqual('un'); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-uniq.spec.js b/packages/transformers/src/dollar-uniq.spec.js new file mode 100644 index 00000000..28c958bb --- /dev/null +++ b/packages/transformers/src/dollar-uniq.spec.js @@ -0,0 +1,40 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$UNIQ', () => { + test('with valid parameter', (done) => { + const script = ` + [$UNIQ] + field = b + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: 1, b: ['un', 'deux', 'trois', 'un'] }, + { a: 2, b: ['un', 'deux', 'quatre', 'deux'] }, + { a: 3, b: ['un', 'deux', 'cinq', 'cinq'] }, + { a: 4, b: ['un', 'deux', 'six'] }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].b.length).toEqual(3); + expect(output[1].b.length).toEqual(3); + expect(output[2].b.length).toEqual(3); + expect(output[3].b.length).toEqual(3); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-uppercase.spec.js b/packages/transformers/src/dollar-uppercase.spec.js new file mode 100644 index 00000000..0ea1b2d8 --- /dev/null +++ b/packages/transformers/src/dollar-uppercase.spec.js @@ -0,0 +1,41 @@ +import from from 'from'; +import ezs from '../../core/src'; +import statements from '.'; + +ezs.use(statements); + +describe('$UPPERCASE', () => { + test('with valid parameter', (done) => { + const script = ` + [$UPPERCASE] + field = b + gap = 3 + + [exchange] + value = omit('$origin') + `; + const input = [ + { a: 1, b: 'un deux', c: true }, + { a: 2, b: 'un trois', c: true }, + { a: 3, b: 'un quatre', c: false }, + { a: 4, b: 'un cinq', c: true }, + ]; + const output = []; + from(input) + .pipe(ezs('delegate', { script })) + .pipe(ezs.catch()) + .on('error', done) + .on('data', (chunk) => { + expect(chunk).toEqual(expect.any(Object)); + output.push(chunk); + }) + .on('end', () => { + expect(output.length).toBe(4); + expect(output[0].b).toEqual('UN DEUX'); + expect(output[1].b).toEqual('UN TROIS'); + expect(output[2].b).toEqual('UN QUATRE'); + expect(output[3].b).toEqual('UN CINQ'); + done(); + }); + }); +}); diff --git a/packages/transformers/src/dollar-urlencode.spec.js b/packages/transformers/src/dollar-urlencode.spec.js index 9ec50638..12f0e0c3 100644 --- a/packages/transformers/src/dollar-urlencode.spec.js +++ b/packages/transformers/src/dollar-urlencode.spec.js @@ -8,7 +8,7 @@ describe('$URLENCODE', () => { test('with valid parameter', (done) => { const script = ` [$URLENCODE] - path = b + field = b [exchange] value = omit('$origin') diff --git a/packages/transformers/src/dollar-value.spec.js b/packages/transformers/src/dollar-value.spec.js index 64b3a928..a017dc25 100644 --- a/packages/transformers/src/dollar-value.spec.js +++ b/packages/transformers/src/dollar-value.spec.js @@ -8,7 +8,7 @@ describe('$VALUE', () => { test('with valid parameter', (done) => { const script = ` [$VALUE] - path = aaa + field = aaa value = toto [exchange] diff --git a/packages/transformers/src/dollar.js b/packages/transformers/src/dollar.js index b232a595..ad76a4a5 100644 --- a/packages/transformers/src/dollar.js +++ b/packages/transformers/src/dollar.js @@ -1,14 +1,27 @@ import _ from 'lodash'; -export default async function dollar(statement, data, feed, transformer) { +export default async function dollar(statement, data, feed, transformer, doc) { if (statement.isLast()) { return feed.close(); } - const paths = statement.getParam('path'); - const path = Array.isArray(paths) ? paths.shift() : paths; + const fields = statement.getParam('field'); + const field = Array.isArray(fields) ? fields.shift() : fields; const { args } = transformer.getMetas(); - - const values = args.map((arg) => ({ ...arg, value: statement.getParam(arg.name) })); + let index = -1; + const values = args.map((arg) => { + const vals = statement.getParam(arg.name); + if (Array.isArray(vals)) { + index += 1; + return { + ...arg, + value: vals[index], + }; + } + return { + ...arg, + value: vals, + }; + }); let newData; if (data.$origin) { newData = { ...data }; @@ -17,11 +30,11 @@ export default async function dollar(statement, data, feed, transformer) { $origin: { ...data }, }; } - const input = _.get(data, path, data); + const input = doc || _.get(data, field, null); const output = await transformer(input, values)(input); - _.set(newData, path, output); + _.set(newData, field, output); return feed.send(newData); } diff --git a/packages/transformers/src/operations/AUTOGENERATE_URI.js b/packages/transformers/src/operations/AUTOGENERATE_URI.js index ef428a5a..c4b246f5 100644 --- a/packages/transformers/src/operations/AUTOGENERATE_URI.js +++ b/packages/transformers/src/operations/AUTOGENERATE_URI.js @@ -1,10 +1,13 @@ import InistArk from 'inist-ark'; -const ARBITRARY_SUBPUBLISHER = '39D'; - -export const autoGenerateUri = ({ naan, subpublisher, uriSize }) => () => +export const autoGenerateUri = (globalConfig) => (statementParamters) => () => new Promise((resolve, reject) => { try { + const config = globalConfig || {}; + const args = statementParamters || {}; + const naan = config.naan || args.naan || '00000'; + const subpublisher = config.subpublisher || args.subpublisher || '000'; + const uriSize = config.uriSize || args.uriSize || false; if (naan && subpublisher) { const ark = new InistArk({ naan, @@ -15,7 +18,7 @@ export const autoGenerateUri = ({ naan, subpublisher, uriSize }) => () => } const ark = new InistArk({ - subpublisher: ARBITRARY_SUBPUBLISHER, + subpublisher, }); const { identifier } = ark.parse(ark.generate()); @@ -28,7 +31,7 @@ export const autoGenerateUri = ({ naan, subpublisher, uriSize }) => () => } }); -const transformation = autoGenerateUri; +const transformation = autoGenerateUri(); transformation.getMetas = () => ({ name: 'AUTOGENERATE_URI', diff --git a/packages/transformers/src/operations/CONCAT.js b/packages/transformers/src/operations/CONCAT.js index 34942f1f..936bcddd 100644 --- a/packages/transformers/src/operations/CONCAT.js +++ b/packages/transformers/src/operations/CONCAT.js @@ -1,6 +1,6 @@ const transformation = (_, args) => { const sourceFields = args - .filter(a => a.name === 'column') + .filter(a => a.name.slice(0, 6) === 'column') .map(({ value }) => value); if (!sourceFields) { diff --git a/packages/transformers/test/transformers.js b/packages/transformers/test/transformers.js deleted file mode 100644 index 1e5ffbdc..00000000 --- a/packages/transformers/test/transformers.js +++ /dev/null @@ -1,108 +0,0 @@ -import from from 'from'; -import ezs from '../../core/src'; -import statements from '../src'; - -ezs.use(statements); - -describe('$VALUE', () => { - test('with valid parameter', (done) => { - const script = ` - [$VALUE] - path = aaa - value = toto - - [exchange] - value = omit('$origin') - `; - const res = []; - from([ - { a: 1, b: 'deux', c: true }, - { a: 2, b: 'trois', c: true }, - { a: 3, b: 'quatre', c: false }, - { a: 4, b: 'cinq', c: true }, - ]) - .pipe(ezs('delegate', { script })) - .pipe(ezs.catch()) - .on('error', done) - .on('data', (chunk) => { - expect(chunk).toEqual(expect.any(Object)); - res.push(chunk); - }) - .on('end', () => { - expect(res.length).toBe(4); - expect(res[0].aaa).toEqual('toto'); - expect(res[1].aaa).toEqual('toto'); - expect(res[2].aaa).toEqual('toto'); - expect(res[3].aaa).toEqual('toto'); - done(); - }); - }); -}); -describe('$URLENCODE', () => { - test('with valid parameter', (done) => { - const script = ` - [$URLENCODE] - path = b - - [exchange] - value = omit('$origin') - `; - const res = []; - from([ - { a: 1, b: 'é deux', c: true }, - { a: 2, b: 'é trois', c: true }, - { a: 3, b: 'é quatre', c: false }, - { a: 4, b: 'é cinq', c: true }, - ]) - .pipe(ezs('delegate', { script })) - .pipe(ezs.catch()) - .on('error', done) - .on('data', (chunk) => { - expect(chunk).toEqual(expect.any(Object)); - res.push(chunk); - }) - .on('end', () => { - expect(res.length).toBe(4); - expect(res[0].b).toEqual('%C3%A9%20deux'); - expect(res[1].b).toEqual('%C3%A9%20trois'); - expect(res[2].b).toEqual('%C3%A9%20quatre'); - expect(res[3].b).toEqual('%C3%A9%20cinq'); - done(); - }); - }); -}); -describe('$REPLACE', () => { - test('with valid parameter', (done) => { - const script = ` - [$REPLACE] - path = b - value = un - value = 1 - - [exchange] - value = omit('$origin') - `; - const res = []; - from([ - { a: 1, b: 'un deux', c: true }, - { a: 2, b: 'un trois', c: true }, - { a: 3, b: 'un quatre', c: false }, - { a: 4, b: 'un cinq', c: true }, - ]) - .pipe(ezs('delegate', { script })) - .pipe(ezs.catch()) - .on('error', done) - .on('data', (chunk) => { - expect(chunk).toEqual(expect.any(Object)); - res.push(chunk); - }) - .on('end', () => { - expect(res.length).toBe(4) - expect(res[0].b).toEqual('1 deux'); - expect(res[1].b).toEqual('1 trois'); - expect(res[2].b).toEqual('1 quatre'); - expect(res[3].b).toEqual('1 cinq'); - done(); - }); - }); -});