ffc-pay-etl-framework 1.4.2-alpha.6 → 1.4.3-alpha.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.
Files changed (87) hide show
  1. package/.all-contributorsrc +43 -0
  2. package/.devcontainer/devcontainer.json +43 -0
  3. package/.devcontainer/docker-compose.yaml +15 -0
  4. package/.devcontainer/postgres_init.sql +5 -0
  5. package/.dockerignore +10 -0
  6. package/.github/workflows/main.yaml +77 -0
  7. package/.snyk +5 -0
  8. package/CODE_OF_CONDUCT.md +51 -0
  9. package/CONTRIBUTING.md +45 -0
  10. package/ISSUE_TEMPLATE.md +39 -0
  11. package/Jenkinsfile +3 -0
  12. package/PULL_REQUEST_TEMPLATE.md +32 -0
  13. package/__mocks__/fs.js +21 -0
  14. package/app/database_connections/index.js +7 -0
  15. package/app/database_connections/postgresDatabaseConnection.js +47 -0
  16. package/app/database_connections/providedConnection.js +19 -0
  17. package/app/destinations/README.md +107 -0
  18. package/app/destinations/consoleDestination.js +38 -0
  19. package/app/destinations/csvFileDestination.js +75 -0
  20. package/app/destinations/index.js +12 -0
  21. package/app/destinations/postgresDestination.js +139 -0
  22. package/app/destinations/sqlFileDestination.js +81 -0
  23. package/app/lib/index.js +106 -0
  24. package/app/lib/rowMetaData.js +24 -0
  25. package/app/loaders/csvloader.js +58 -0
  26. package/app/loaders/index.js +5 -0
  27. package/app/misc/README.md +55 -0
  28. package/app/misc/index.js +0 -0
  29. package/app/misc/postgresSQLTask.js +71 -0
  30. package/app/transformers/README.md +102 -0
  31. package/app/transformers/fakerTransformer.js +48 -0
  32. package/app/transformers/index.js +9 -0
  33. package/app/transformers/stringReplaceTransformer.js +35 -0
  34. package/app/transformers/toUpperCaseTransformer.js +27 -0
  35. package/app/validators/README.md +81 -0
  36. package/app/validators/index.js +9 -0
  37. package/app/validators/multiToolValidator.js +49 -0
  38. package/app/validators/requiredValidator.js +35 -0
  39. package/app/validators/uniqueValidator.js +41 -0
  40. package/eslint.config.js +3 -0
  41. package/examples/additional-tasks.js +127 -0
  42. package/examples/csv-faker.js +30 -0
  43. package/examples/csv-find-replace.js +97 -0
  44. package/examples/csv-multi-tool-validator.js +38 -0
  45. package/examples/csv-required-validator.js +27 -0
  46. package/examples/csv-to-csv.js +24 -0
  47. package/examples/csv-to-postgres.js +36 -0
  48. package/examples/csv-to-sqlfile.js +31 -0
  49. package/examples/csv-to-upper-case.js +25 -0
  50. package/examples/csv-unique-validator.js +27 -0
  51. package/examples/index.js +26 -0
  52. package/examples/sql-return-values.js +37 -0
  53. package/jest/setEnvVars.js +1 -0
  54. package/package.json +2 -15
  55. package/snyk-cli/snyk-result.json +109 -0
  56. package/snyk-error.log +0 -0
  57. package/snyk-monitor-result.json +102 -0
  58. package/snyk-result.json +108 -0
  59. package/snyk_report.html +493 -0
  60. package/sonar-project.properties +3 -0
  61. package/test/database_connections/postgresDatabaseConnection.test.js +89 -0
  62. package/test/database_connections/providedConnection.test.js +36 -0
  63. package/test/destinations/consoleDestination.test.js +80 -0
  64. package/test/destinations/csvFileDestination.test.js +97 -0
  65. package/test/destinations/postgresDestination.test.js +311 -0
  66. package/test/destinations/sqlFileDestination.test.js +150 -0
  67. package/test/etl/etl.test.js +186 -0
  68. package/test/fixtures/Avg_Rainfall_30yrs.csv +314 -0
  69. package/test/fixtures/Crop_growing_period.csv +314 -0
  70. package/test/fixtures/Crops.csv +2485 -0
  71. package/test/fixtures/Farmer_Wages.csv +1899 -0
  72. package/test/fixtures/Fertilizer_Consumption.csv +2482 -0
  73. package/test/fixtures/GDP.csv +2150 -0
  74. package/test/fixtures/Harvest_prices.csv +1933 -0
  75. package/test/fixtures/Irrigation.csv +2045 -0
  76. package/test/fixtures/LandUse.csv +2382 -0
  77. package/test/fixtures/Livestock_Milk_Production.csv +1446 -0
  78. package/test/fixtures/Monthly_Rainfall.csv +1704 -0
  79. package/test/fixtures/SoilType.csv +314 -0
  80. package/test/loaders/csvLoader.test.js +280 -0
  81. package/test/misc/postgresSQLTask.test.js +82 -0
  82. package/test/transformers/fakerTransformer.test.js +63 -0
  83. package/test/transformers/stringReplaceTransformer.test.js +55 -0
  84. package/test/transformers/toUpperCaseTransformer.test.js +26 -0
  85. package/test/validators/multiToolValidator.test.js +51 -0
  86. package/test/validators/requiredValidator.test.js +63 -0
  87. package/test/validators/uniqueValidator.test.js +84 -0
@@ -0,0 +1,43 @@
1
+ {
2
+ "projectName": "ffc-pay-etl-framework",
3
+ "projectOwner": "DEFRA",
4
+ "repoType": "github",
5
+ "repoHost": "https://github.com",
6
+ "files": [
7
+ "README.md"
8
+ ],
9
+ "imageSize": 100,
10
+ "commit": true,
11
+ "commitConvention": "angular",
12
+ "contributors": [
13
+ {
14
+ "login": "suityou01",
15
+ "name": "Charlie Benger-Stevenson",
16
+ "avatar_url": "https://avatars.githubusercontent.com/u/7422644?v=4",
17
+ "profile": "https://github.com/suityou01",
18
+ "contributions": [
19
+ "code"
20
+ ]
21
+ },
22
+ {
23
+ "login": "GodsonLeigh",
24
+ "name": "Leigh Godson",
25
+ "avatar_url": "https://avatars.githubusercontent.com/u/139965284?v=4",
26
+ "profile": "https://github.com/GodsonLeigh",
27
+ "contributions": [
28
+ "code"
29
+ ]
30
+ },
31
+ {
32
+ "login": "samplackett",
33
+ "name": "Sam Plackett",
34
+ "avatar_url": "https://avatars.githubusercontent.com/u/60177449?v=4",
35
+ "profile": "https://github.com/samplackett",
36
+ "contributions": [
37
+ "code"
38
+ ]
39
+ }
40
+ ],
41
+ "contributorsPerLine": 7,
42
+ "linkToUsage": true
43
+ }
@@ -0,0 +1,43 @@
1
+ // For format details, see https://aka.ms/devcontainer.json. For config options, see the
2
+ // README at: https://github.com/devcontainers/templates/tree/main/src/universal
3
+ {
4
+ "name": "Default Linux Universal",
5
+ // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6
+ // "image": "mcr.microsoft.com/devcontainers/universal:2-linux",
7
+ "dockerComposeFile": "./docker-compose.yaml",
8
+ "service": "etl",
9
+ "workspaceFolder": "/workspace",
10
+ // Features to add to the dev container. More info: https://containers.dev/features.
11
+ // "features": {},
12
+
13
+ // Use 'forwardPorts' to make a list of ports inside the container available locally.
14
+ // "forwardPorts": [],
15
+
16
+ // Use 'postCreateCommand' to run commands after the container is created.
17
+ // "postCreateCommand": "uname -a",
18
+
19
+ // Configure tool-specific properties.
20
+ "customizations": {
21
+ "vscode": {
22
+ "extensions": [
23
+ "ms-azuretools.vscode-docker",
24
+ "orta.vscode-jest",
25
+ "andys8.jest-snippets",
26
+ "chris-noring.node-snippets",
27
+ "cweijan.vscode-postgresql-client2",
28
+ "mechatroner.rainbow-csv",
29
+ "esbenp.prettier-vscode",
30
+ "sonarsource.sonarlint-vscode"
31
+ ],
32
+ "settings": {
33
+ "jest.runMode": {
34
+ "type": "on-demand",
35
+ "coverage": false
36
+ }
37
+ }
38
+ }
39
+ },
40
+ // "overrideCommand": true
41
+ // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
42
+ // "remoteUser": "root"
43
+ }
@@ -0,0 +1,15 @@
1
+ services:
2
+ etl:
3
+ image: mcr.microsoft.com/devcontainers/universal:2-linux
4
+ volumes:
5
+ - ../:/workspace:cached
6
+ postgres:
7
+ image: postgres:latest
8
+ ports:
9
+ - 5432:5432
10
+ volumes:
11
+ - ./databases/postgres:/var/lib/postgresql
12
+ - ./postgres_init.sql:/docker-entrypoint-initdb.d/init.sql
13
+ environment:
14
+ - POSTGRES_PASSWORD=ppp
15
+ - POSTGRES_DB=etl_db
@@ -0,0 +1,5 @@
1
+ CREATE TABLE target (
2
+ target_column1 VARCHAR(100),
3
+ target_column2 VARCHAR(100),
4
+ target_column3 VARCHAR(100)
5
+ );
package/.dockerignore ADDED
@@ -0,0 +1,10 @@
1
+ .gitignore
2
+ .pre-commit-config.yaml
3
+ CODE_OF_CONDUCT.md
4
+ CONTRIBUTING.md
5
+ ISSUE_TEMPLATE.md
6
+ LICENSE.md
7
+ PULL_REQUEST_TEMPLATE.md
8
+ README.md
9
+ Jenkinsfile
10
+
@@ -0,0 +1,77 @@
1
+ name: Version Bump
2
+
3
+ on:
4
+ pull_request:
5
+ types: [opened, reopened]
6
+
7
+ jobs:
8
+ version-bump:
9
+ runs-on: ubuntu-latest
10
+
11
+ steps:
12
+ - name: Checkout code
13
+ uses: actions/checkout@v3
14
+ with:
15
+ ref: ${{ github.head_ref }}
16
+ fetch-depth: 0
17
+
18
+ - name: Set up Node.js
19
+ uses: actions/setup-node@v3
20
+ with:
21
+ node-version: '20'
22
+
23
+ - name: Install dependencies
24
+ run: npm install
25
+
26
+ - name: Set up GPG keys for signing
27
+ run: |
28
+ echo "$GPG_PRIVATE_KEY" | gpg --batch --import
29
+ git config --global user.signingkey ${{ secrets.GPG_KEY_ID }}
30
+ git config --global commit.gpgsign true
31
+ git config --global user.email ${{ secrets.GPG_EMAIL }}
32
+ git config --global user.name ${{ secrets.GPG_NAME }}
33
+ env:
34
+ GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
35
+ GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }}
36
+ GPG_EMAIL: ${{ secrets.GPG_EMAIL }}
37
+ GPG_NAME: ${{ secrets.GPG_NAME }}
38
+
39
+ - name: Commit dependency updates with GPG sign
40
+ run: |
41
+ git add package-lock.json
42
+ git commit -S -m "update package-lock.json" || echo "No changes to commit"
43
+
44
+ - name: Fetch main branch
45
+ run: git fetch origin main
46
+
47
+ - name: Merge main into feature branch
48
+ run: |
49
+ git merge origin/main --no-commit
50
+ continue-on-error: true
51
+
52
+ - name: Check for merge conflicts
53
+ run: |
54
+ if [[ $(git ls-files -u | wc -l) -gt 0 ]]; then
55
+ echo "Merge conflicts detected. Exiting without version bump."
56
+ exit 0
57
+ else
58
+ echo "Merge successful. Proceeding with version bump."
59
+ fi
60
+ shell: bash
61
+
62
+ - name: Commit merged changes
63
+ run: |
64
+ git commit -S -m "merge main into feature branch" || echo "No changes to commit"
65
+
66
+ - name: Bump version number
67
+ run: |
68
+ npm version patch
69
+
70
+ - name: Ensure branch is checked out
71
+ run: |
72
+ git checkout ${{ github.head_ref }}
73
+
74
+ - name: Push version bump and commit with GPG sign
75
+ run: |
76
+ git push --set-upstream origin ${{ github.head_ref }} --force
77
+ git push --tags
package/.snyk ADDED
@@ -0,0 +1,5 @@
1
+ # Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
2
+
3
+ version: v1.25.0
4
+ ignore: {}
5
+ patch: {}
@@ -0,0 +1,51 @@
1
+ # Contributor Code of Conduct
2
+
3
+ Our [values](https://www.gov.uk/government/organisations/department-for-environment-food-rural-affairs/about#:~:text=We%20are%20responsible%20for%20improving,food%2C%20farming%20and%20fishing%20industries.) guide us in our day-to-day interactions and decision-making. Our open source projects are no exception. Trust, respect, collaboration and transparency are core values we believe should live and breathe within our projects. Our community welcomes participants from around the world with different experiences, unique perspectives, and great ideas to share.
4
+
5
+ ## Our Pledge
6
+
7
+ In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to creating a positive environment include:
12
+
13
+ - Using welcoming and inclusive language
14
+ - Being respectful of differing viewpoints and experiences
15
+ - Gracefully accepting constructive criticism
16
+ - Attempting collaboration before conflict
17
+ - Focusing on what is best for the community
18
+ - Showing empathy towards other community members
19
+
20
+ Examples of unacceptable behavior by participants include:
21
+
22
+ - Violence, threats of violence, or inciting others to commit self-harm
23
+ - The use of sexualized language or imagery and unwelcome sexual attention or advances
24
+ - Trolling, intentionally spreading misinformation, insulting/derogatory comments, and personal or political attacks
25
+ - Public or private harassment
26
+ - Publishing others' private information, such as a physical or electronic address, without explicit permission
27
+ - Abuse of the reporting process to intentionally harass or exclude others
28
+ - Advocating for, or encouraging, any of the above behavior
29
+ - Other conduct which could reasonably be considered inappropriate in a professional setting
30
+
31
+ ## Our Responsibilities
32
+
33
+ Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
34
+
35
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
36
+
37
+ ## Scope
38
+
39
+ This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
40
+
41
+ ## Enforcement
42
+
43
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting us anonymously through [this form](https://www.gov.uk/government/organisations/department-for-environment-food-rural-affairs/about/complaints-procedure). All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident.
44
+
45
+ Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
46
+
47
+ If you are unsure whether an incident is a violation, or whether the space where the incident took place is covered by our Code of Conduct, **we encourage you to still report it**. We would prefer to have a few extra reports where we decide to take no action, than to leave an incident go unnoticed and unresolved that may result in an individual or group to feel like they can no longer participate in the community. Reports deemed as not a violation will also allow us to improve our Code of Conduct and processes surrounding it. If you witness a dangerous situation or someone in distress, we encourage you to report even if you are only an observer.
48
+
49
+ ## Attribution
50
+
51
+ This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org/), [version 1.4](https://www.contributor-covenant.org/version/1/4/code-of-conduct.html).
@@ -0,0 +1,45 @@
1
+ This is still a fairly new package. While it delivers some basic ETL functionality there is still a lot of work to be done.
2
+
3
+ There are still a lot of things to be done, so all contributions are welcome!
4
+
5
+ ## Code of Conduct
6
+
7
+ We take our open source community seriously and hold ourselves and other contributors to high standards of communication. By participating and contributing to this project, you agree to uphold our [Code of Conduct](https://github.com/ffc-pay-etl-framework/CODE-OF-CONDUCT.md).
8
+
9
+ ## Getting Started
10
+
11
+ Contributions are made to this repo via Issues and Pull Requests (PRs). A few general guidelines that cover both:
12
+
13
+ - Search for existing Issues and PRs before creating your own.
14
+ - We work hard to makes sure issues are handled in a timely manner but, depending on the impact, it could take a while to investigate the root cause. A friendly ping in the comment thread to the submitter or a contributor can help draw attention if your issue is blocking.
15
+
16
+ ### Issues
17
+
18
+ Issues should be used to report problems with the library, request a new feature, or to discuss potential changes before a PR is created. When you create a new Issue, a template will be loaded that will guide you through collecting and providing the information we need to investigate.
19
+
20
+ If you find an Issue that addresses the problem you're having, please add your own reproduction information to the existing issue rather than creating a new one. Adding a [reaction](https://github.blog/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) can also help be indicating to our maintainers that a particular problem is affecting more than just the reporter.
21
+
22
+ ### Pull Requests
23
+
24
+ PRs to our libraries are always welcome and can be a quick way to get your fix or improvement slated for the next release. In general, PRs should:
25
+
26
+ - Only fix/add the functionality in question **OR** address wide-spread whitespace/style issues, not both.
27
+ - Add unit or integration tests for fixed or changed functionality (if a test suite already exists).
28
+ - Address a single concern in the least number of changed lines as possible.
29
+ - Include documentation in the repo or on our [docs site](https://auth0.com/docs).
30
+ - Be accompanied by a complete Pull Request template (loaded automatically when a PR is created).
31
+
32
+ For changes that address core functionality or would require breaking changes (e.g. a major release), it's best to open an Issue to discuss your proposal first. This is not required but can save time creating and reviewing changes.
33
+
34
+ In general, we follow the ["fork-and-pull" Git workflow](https://github.com/susam/gitpr)
35
+
36
+ 1. Fork the repository to your own Github account
37
+ 2. Clone the project to your machine
38
+ 3. Create a branch locally with a succinct but descriptive name
39
+ 4. Commit changes to the branch
40
+ 5. Following any formatting and testing guidelines specific to this repo
41
+ 6. Push changes to your fork
42
+ 7. Open a PR in our repository and follow the PR template so that we can efficiently review the changes.
43
+
44
+
45
+
@@ -0,0 +1,39 @@
1
+ # Prerequisites
2
+
3
+ Please answer the following questions for yourself before submitting an issue.
4
+
5
+ - [ ] I am running the latest version
6
+ - [ ] I checked the documentation and found no answer
7
+ - [ ] I checked to make sure that this issue has not already been filed
8
+
9
+ # Expected Behavior
10
+
11
+ Please describe the behavior you are expecting
12
+
13
+ # Current Behavior
14
+
15
+ What is the current behavior?
16
+
17
+ # Failure Information (for bugs)
18
+
19
+ Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.
20
+
21
+ ## Steps to Reproduce
22
+
23
+ Please provide detailed steps for reproducing the issue.
24
+
25
+ 1. step 1
26
+ 2. step 2
27
+ 3. you get it...
28
+
29
+ ## Context
30
+
31
+ Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
32
+
33
+ * Operating System:
34
+ * NPM version:
35
+ * Node version:
36
+
37
+ ## Failure Logs
38
+
39
+ Please include any relevant log snippets or files here.
package/Jenkinsfile ADDED
@@ -0,0 +1,3 @@
1
+ @Library('defra-library@v-9') _
2
+
3
+ buildNpm()
@@ -0,0 +1,32 @@
1
+ # Description
2
+
3
+ Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
4
+
5
+ Fixes # (issue)
6
+
7
+ ## Type of change
8
+
9
+ Please delete options that are not relevant.
10
+
11
+ - [ ] Bug fix (non-breaking change which fixes an issue)
12
+ - [ ] New feature (non-breaking change which adds functionality)
13
+ - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
14
+ - [ ] This change requires a documentation update
15
+
16
+ # How Has This Been Tested?
17
+
18
+ Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
19
+
20
+ - [ ] Test A
21
+ - [ ] Test B
22
+
23
+ # Checklist:
24
+
25
+ - [ ] My code follows the style guidelines of this project
26
+ - [ ] I have performed a self-review of my own code
27
+ - [ ] I have commented my code, particularly in hard-to-understand areas
28
+ - [ ] I have made corresponding changes to the documentation
29
+ - [ ] My changes generate no new warnings
30
+ - [ ] I have added tests that prove my fix is effective or that my feature works
31
+ - [ ] New and existing unit tests pass locally with my changes
32
+ - [ ] Any dependent changes have been merged and published in downstream modules
@@ -0,0 +1,21 @@
1
+ 'use strict'
2
+ const { Readable } = require('node:stream')
3
+
4
+ const fs = jest.createMockFromModule('fs')
5
+
6
+ const mockContent = []
7
+
8
+ function __setMockFileContent (mockPath, mockFileContent) {
9
+ mockContent[mockPath] = mockFileContent
10
+ }
11
+
12
+ function createReadStream (path) {
13
+ return Readable.from(mockContent[path])
14
+ }
15
+
16
+ const writeFileSync = jest.fn()
17
+
18
+ fs.createReadStream = createReadStream
19
+ fs.writeFileSync = writeFileSync
20
+ fs.__setMockFileContent = __setMockFileContent
21
+ module.exports = fs
@@ -0,0 +1,7 @@
1
+ const { PostgresDatabaseConnection } = require('./postgresDatabaseConnection')
2
+ const { ProvidedConnection } = require('./providedConnection')
3
+
4
+ module.exports = {
5
+ PostgresDatabaseConnection,
6
+ ProvidedConnection
7
+ }
@@ -0,0 +1,47 @@
1
+ const DEFAULT_PORT = 5432
2
+ const { Sequelize } = require('sequelize')
3
+ const debug = require('debug')('connection')
4
+
5
+ /**
6
+ *
7
+ * @param {Object} options
8
+ * @param {Object} options.connectionname
9
+ * @param {Object} options.username
10
+ * @param {Object} options.password
11
+ * @param {Object} options.database
12
+ * @param {Object} options.host
13
+ * @param {Object} options.port
14
+ * @returns Connection
15
+ */
16
+ async function PostgresDatabaseConnection (options) {
17
+ const connectionname = options.connectionname
18
+ const username = options.username
19
+ const password = options.password
20
+ const database = options.database
21
+ const host = options.host
22
+ const port = options.port || DEFAULT_PORT
23
+
24
+ const sequelize = new Sequelize(database, username, password, {
25
+ host,
26
+ port,
27
+ dialect: 'postgres',
28
+ logging: false
29
+ })
30
+
31
+ try {
32
+ await sequelize.authenticate()
33
+ debug('sequelize.authenticate succeeded')
34
+ return {
35
+ name: connectionname,
36
+ db: sequelize
37
+ }
38
+ } catch (e) {
39
+ debug('sequelize.authenticate failed')
40
+ debug(e)
41
+ throw e
42
+ }
43
+ }
44
+
45
+ module.exports = {
46
+ PostgresDatabaseConnection
47
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ *
3
+ * @param {Object} options
4
+ * @param {Object} options.connectionname
5
+ * @param {Object} options.sequelize
6
+ * @returns Connection
7
+ */
8
+ async function ProvidedConnection (options) {
9
+ const connectionname = options.connectionname
10
+ const sequelize = options.sequelize
11
+ return {
12
+ name: connectionname,
13
+ db: sequelize
14
+ }
15
+ }
16
+
17
+ module.exports = {
18
+ ProvidedConnection
19
+ }
@@ -0,0 +1,107 @@
1
+ # Destinations
2
+
3
+ Destinations are expected to write out to an output. This could be a file, a database, an endpoint, whatever.
4
+
5
+ Currently supported destinations are :
6
+
7
+ - CSVFileDestination
8
+ - PostgresDestination
9
+ - SQLFileDestination
10
+
11
+ ## CSVFileDestination
12
+
13
+ ### Options
14
+
15
+ | option | description |
16
+ | -------------- | ------------------------------------------------------------- |
17
+ | fileName | absolute path to the csv file to be written |
18
+ | headers | treat the first line of the file as column header information |
19
+ | includeErrors | write out any rows that contain errors |
20
+ | quotationMarks | wrap values in quotation marks |
21
+
22
+ ### Usage
23
+
24
+ ```js
25
+ CSVFileDestination({
26
+ fileName: "...",
27
+ headers: true,
28
+ includeErrors: false,
29
+ quotationMarks: true,
30
+ })
31
+ ```
32
+
33
+ ### Example
34
+
35
+ examples/csv-to-csv.js
36
+
37
+ ## PostgresDestination
38
+
39
+ ### Options
40
+
41
+ | option | description |
42
+ | ------------- | ------------------------------------------------------ |
43
+ | table | the name of the table to be inserted into |
44
+ | username | the username for the database connection |
45
+ | password | the password for the database connection |
46
+ | database | the name of the database for the connection |
47
+ | host | the host name for the database connection |
48
+ | port | the port for the database connection. Defaults to 5432 |
49
+ | includeErrors | write out any rows that contain errors |
50
+ | mapping | field mappings from source to target |
51
+
52
+ ### Usage
53
+
54
+ ```js
55
+ PostgresDestination({
56
+ username: "postgres",
57
+ password: "ppp",
58
+ database: "etl_db",
59
+ host: "postgres",
60
+ table: "target",
61
+ includeErrors: false,
62
+ mapping: [
63
+ {
64
+ column: "column1",
65
+ targetColumn: "target_column1",
66
+ targetType: "varchar",
67
+ },
68
+ ],
69
+ })
70
+ ```
71
+
72
+ ### Example
73
+
74
+ examples/csv-to-postgres.js
75
+
76
+ ## SQLFileDestination
77
+
78
+ ### options
79
+
80
+ | option | description |
81
+ | -------- | ------------------------------------------- |
82
+ | fileName | absolute path to the sql file to be written |
83
+ | mode | insert or update mode |
84
+ | table | the table for the statements |
85
+ | mapping | field mappings from source to target |
86
+
87
+ ### Usage
88
+
89
+ ```js
90
+ SQLFileDestination({
91
+ filename: "...",
92
+ mode: SQL_MODE.INSERT_MODE,
93
+ table: "target",
94
+ includeErrors: false,
95
+ mapping: [
96
+ {
97
+ column: "column1",
98
+ targetColumn: "target_column1",
99
+ targetType: "varchar",
100
+ },
101
+ ],
102
+ })
103
+ ```
104
+
105
+ ### Example
106
+
107
+ examples/csv-to-sqlfile.js
@@ -0,0 +1,38 @@
1
+ const { Writable } = require('node:stream')
2
+
3
+ /**
4
+ *
5
+ * @param {Object} options
6
+ * @param {String} options.includeErrors
7
+ * @returns Writable
8
+ */
9
+ function ConsoleDestination (options) {
10
+ const includeErrors = options.includeErrors
11
+ const writable = new Writable({
12
+ objectMode: true,
13
+ write (chunk, _, callback) {
14
+ if (chunk.errors.length === 0 || includeErrors) { console.log(chunk) }
15
+ // @ts-ignore
16
+ this.tasks?.forEach(task => task.write(chunk))
17
+ callback()
18
+ }
19
+ })
20
+
21
+ Object.assign(writable, {
22
+ setConnection: function (connection) {
23
+ this.connection = connection
24
+ }.bind(writable),
25
+ getConnectionName: function () {
26
+ return this.connection?.name
27
+ }.bind(writable),
28
+ setTasks: function (tasks) {
29
+ this.tasks = tasks
30
+ }.bind(writable)
31
+ })
32
+
33
+ return writable
34
+ }
35
+
36
+ module.exports = {
37
+ ConsoleDestination
38
+ }