From 7700b28a1146de1e5b7d7e6a304f722f7b2d688f Mon Sep 17 00:00:00 2001 From: Alexander Mart Date: Fri, 1 Dec 2023 23:12:29 +0700 Subject: [PATCH 1/2] doc: syntax highlight of js example --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index fe7b071..c63d34e 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ Nextract is a [Extract Transform Load (ETL)](https://en.wikipedia.org/wiki/Extra ## Example Transform +```javascript /** * Example: JSON input and sort... */ @@ -83,6 +84,7 @@ Nextract is a [Extract Transform Load (ETL)](https://en.wikipedia.org/wiki/Extra .catch((err) => { transform.Plugins.Core.Logger.error('Transform failed: ', err); }); +``` ## Development The source code for this project lives under the `src` directory. Grunt is used to build the project and generate API docs when the source is updated. When developing, simply run `grunt watch` from the project's root directory. As the source is updated Grunt will automatically generate new builds in the `build` directory. From 961188542a39bc7e1323e9a57fd6dc79a6560987 Mon Sep 17 00:00:00 2001 From: Alexander Mart Date: Fri, 1 Dec 2023 23:14:32 +0700 Subject: [PATCH 2/2] doc: style: indentation --- README.md | 94 +++++++++++++++++++++++++++---------------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index c63d34e..9206964 100644 --- a/README.md +++ b/README.md @@ -34,56 +34,56 @@ Nextract is a [Extract Transform Load (ETL)](https://en.wikipedia.org/wiki/Extra ## Example Transform ```javascript - /** - * Example: JSON input and sort... - */ - - const path = require('path'), - Nextract = require(path.resolve(__dirname, '../nextract')); - - //Define our input and output files - const sampleEmployeesInputFilePath = path.resolve(process.cwd(), 'data/employees.json'), - sampleEmployeesOutputFilePath = path.resolve(process.cwd(), 'data/employees_output.json'); - - //Tranforms always start with instance of the Nextract base class and a tranform name - const transform = new Nextract('jsonAndSort'); - - //We load the core plugin and then an additional plugins our transform requires - transform.loadPlugins('Core', ['Input', 'Output', 'Sort', 'Logger']) - .then(() => { - return new Promise((resolve) => { - //STEP 1: Read data in from a JSON file (we specify the object path we care about) - transform.Plugins.Core.Input.readJsonFile(sampleEmployeesInputFilePath, 'data.employees.*') - //STEP 2: Pass data in to be sorted (1 element is pushed back and it is the expected input - //for a new stream read call to sortOut) - .pipe(transform.Plugins.Core.Sort.sortIn(['last_name'], ['asc'])) - .on('data', (sortInDbInfo) => { - if (sortInDbInfo !== undefined) { - resolve(sortInDbInfo); - } - }); +/** + * Example: JSON input and sort... + */ + +const path = require('path'), + Nextract = require(path.resolve(__dirname, '../nextract')); + +//Define our input and output files +const sampleEmployeesInputFilePath = path.resolve(process.cwd(), 'data/employees.json'), + sampleEmployeesOutputFilePath = path.resolve(process.cwd(), 'data/employees_output.json'); + +//Tranforms always start with instance of the Nextract base class and a tranform name +const transform = new Nextract('jsonAndSort'); + +//We load the core plugin and then an additional plugins our transform requires +transform.loadPlugins('Core', ['Input', 'Output', 'Sort', 'Logger']) + .then(() => { + return new Promise((resolve) => { + //STEP 1: Read data in from a JSON file (we specify the object path we care about) + transform.Plugins.Core.Input.readJsonFile(sampleEmployeesInputFilePath, 'data.employees.*') + //STEP 2: Pass data in to be sorted (1 element is pushed back and it is the expected input + //for a new stream read call to sortOut) + .pipe(transform.Plugins.Core.Sort.sortIn(['last_name'], ['asc'])) + .on('data', (sortInDbInfo) => { + if (sortInDbInfo !== undefined) { + resolve(sortInDbInfo); + } }); + }); + }) + .then((sortInDbInfo) => { + transform.Plugins.Core.Sort.sortOut(sortInDbInfo) + //STEP 3: We want to write the sorted data back out to a new JSON file so first we use + //toJsonString to stringify the stream. + .pipe(transform.Plugins.Core.Output.toJsonString(true)) + //STEP 4: Write out the new file + .pipe(transform.Plugins.Core.Output.toFile(sampleEmployeesOutputFilePath)) + .on('finish', () => { + //Just logging some information back to the console + transform.Plugins.Core.Logger.info('Transform finished!'); + transform.Plugins.Core.Logger.info(sampleEmployeesOutputFilePath, 'has been written'); }) - .then((sortInDbInfo) => { - transform.Plugins.Core.Sort.sortOut(sortInDbInfo) - //STEP 3: We want to write the sorted data back out to a new JSON file so first we use - //toJsonString to stringify the stream. - .pipe(transform.Plugins.Core.Output.toJsonString(true)) - //STEP 4: Write out the new file - .pipe(transform.Plugins.Core.Output.toFile(sampleEmployeesOutputFilePath)) - .on('finish', () => { - //Just logging some information back to the console - transform.Plugins.Core.Logger.info('Transform finished!'); - transform.Plugins.Core.Logger.info(sampleEmployeesOutputFilePath, 'has been written'); - }) - .on('end', () => { - transform.Plugins.Core.Logger.info('Transform ended!'); - process.exit(); - }); - }) - .catch((err) => { - transform.Plugins.Core.Logger.error('Transform failed: ', err); + .on('end', () => { + transform.Plugins.Core.Logger.info('Transform ended!'); + process.exit(); }); + }) + .catch((err) => { + transform.Plugins.Core.Logger.error('Transform failed: ', err); + }); ``` ## Development