@ellipticltd/aml-utils 0.8.0-EN-2570.3 → 0.8.0
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/.circleci/config.yml +4 -37
- package/.eslintrc +6 -30
- package/.idea/aml-utils.iml +8 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/workspace.xml +52 -0
- package/README.md +0 -39
- package/index.d.ts +1 -0
- package/index.js +8 -0
- package/lib/{middleware/middleware.js → middleware.js} +1 -1
- package/lib/{types/types.js → types.js} +2 -2
- package/lib/{validations/validations.ts → validations.js} +55 -75
- package/package.json +13 -28
- package/.huskyrc +0 -5
- package/.mocharc.json +0 -3
- package/.releaserc.json +0 -18
- package/commitlint.config.js +0 -1
- package/dist/errors/errors.d.ts +0 -9
- package/dist/errors/errors.js +0 -42
- package/dist/errors/errors.spec.d.ts +0 -1
- package/dist/errors/errors.spec.js +0 -23
- package/dist/file-parser/__tests/file-parser.spec.d.ts +0 -1
- package/dist/file-parser/__tests/file-parser.spec.js +0 -113
- package/dist/file-parser/__tests/parse-row.spec.d.ts +0 -1
- package/dist/file-parser/__tests/parse-row.spec.js +0 -29
- package/dist/file-parser/__tests/sanitize-rows.spec.d.ts +0 -1
- package/dist/file-parser/__tests/sanitize-rows.spec.js +0 -78
- package/dist/file-parser/errors.d.ts +0 -3
- package/dist/file-parser/errors.js +0 -11
- package/dist/file-parser/file-parser.d.ts +0 -8
- package/dist/file-parser/file-parser.js +0 -68
- package/dist/file-parser/parse-row.d.ts +0 -2
- package/dist/file-parser/parse-row.js +0 -39
- package/dist/file-parser/sanitzeRows.d.ts +0 -3
- package/dist/file-parser/sanitzeRows.js +0 -18
- package/dist/formatting/formatting.d.ts +0 -2
- package/dist/formatting/formatting.js +0 -17
- package/dist/formatting/formatting.spec.d.ts +0 -1
- package/dist/formatting/formatting.spec.js +0 -37
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -20
- package/dist/middleware/middleware.d.ts +0 -4
- package/dist/middleware/middleware.js +0 -22
- package/dist/orm-helpers/ormHelpers.d.ts +0 -1
- package/dist/orm-helpers/ormHelpers.js +0 -17
- package/dist/orm-helpers/ormHelpers.spec.d.ts +0 -1
- package/dist/orm-helpers/ormHelpers.spec.js +0 -38
- package/dist/types/types.d.ts +0 -17
- package/dist/types/types.js +0 -203
- package/dist/validations/validations.d.ts +0 -5
- package/dist/validations/validations.js +0 -303
- package/dist/validations/validations.spec.d.ts +0 -1
- package/dist/validations/validations.spec.js +0 -276
- package/lib/errors/errors.spec.js +0 -37
- package/lib/file-parser/__tests/file-parser.spec.js +0 -101
- package/lib/file-parser/__tests/parse-row.spec.js +0 -35
- package/lib/file-parser/__tests/sanitize-rows.spec.js +0 -88
- package/lib/file-parser/errors.ts +0 -7
- package/lib/file-parser/file-parser.ts +0 -84
- package/lib/file-parser/parse-row.ts +0 -52
- package/lib/file-parser/sanitzeRows.ts +0 -32
- package/lib/formatting/formatting.spec.js +0 -45
- package/lib/index.ts +0 -17
- package/lib/orm-helpers/ormHelpers.spec.js +0 -41
- package/lib/validations/validations.spec.js +0 -355
- package/tsconfig.json +0 -26
- /package/lib/{errors/errors.js → errors.js} +0 -0
- /package/lib/{formatting/formatting.js → formatting.js} +0 -0
- /package/lib/{orm-helpers/ormHelpers.js → ormHelpers.js} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ellipticltd/aml-utils",
|
|
3
|
-
"version": "0.8.0
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Utilities, helpers, validations, type-checking, etc",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": "10.1.0",
|
|
@@ -11,13 +11,12 @@
|
|
|
11
11
|
"url": "git+ssh://git@bitbucket.org/elliptic/aml-utils.git"
|
|
12
12
|
},
|
|
13
13
|
"homepage": "https://bitbucket.org/elliptic/aml-utils#readme",
|
|
14
|
-
"main": "
|
|
14
|
+
"main": "index.js",
|
|
15
15
|
"scripts": {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"lint": "./node_modules/.bin/eslint --color 'lib/**/*.{js,ts}' 'test/**/*.js' ",
|
|
16
|
+
"test:unit": "./node_modules/.bin/mocha --reporter spec --compilers coffee:coffee-script/register --require 'test/index.coffee'",
|
|
17
|
+
"compile": "./node_modules/coffee-script/bin/coffee -c index.coffee **/*.coffee",
|
|
18
|
+
"preprocess": "npm run compile",
|
|
19
|
+
"lint": "./node_modules/.bin/eslint --color 'lib/**/*.js' 'test/**/*.js' ",
|
|
21
20
|
"test": "nyc npm run test:unit && nyc report --reporter=html",
|
|
22
21
|
"coverage": "nyc npm run test:unit && nyc report --reporter=lcov --reporter=text-lcov | codecov --pipe"
|
|
23
22
|
},
|
|
@@ -35,32 +34,18 @@
|
|
|
35
34
|
"web3-utils": "1.0.0"
|
|
36
35
|
},
|
|
37
36
|
"devDependencies": {
|
|
38
|
-
"
|
|
39
|
-
"@commitlint/config-angular": "^11.0.0",
|
|
40
|
-
"@commitlint/config-conventional": "^11.0.0",
|
|
41
|
-
"@semantic-release/git": "^9.0.0",
|
|
42
|
-
"@types/chai": "^4.2.14",
|
|
43
|
-
"@types/lodash": "^4.14.164",
|
|
44
|
-
"@types/mocha": "^8.0.3",
|
|
45
|
-
"@typescript-eslint/parser": "^4.6.1",
|
|
46
|
-
"chai": "^4.2.0",
|
|
37
|
+
"chai": "4.1.1",
|
|
47
38
|
"codecov": "^3.6.1",
|
|
39
|
+
"coffee-script": "1.12.7",
|
|
48
40
|
"eslint": "^6.6.0",
|
|
49
|
-
"eslint-config-airbnb
|
|
50
|
-
"eslint-
|
|
41
|
+
"eslint-config-airbnb": "^18.0.1",
|
|
42
|
+
"eslint-config-airbnb-base": "^14.0.0",
|
|
51
43
|
"eslint-plugin-coffeescript": "^1.0.0",
|
|
52
44
|
"eslint-plugin-import": "^2.18.2",
|
|
53
45
|
"eslint-plugin-jsx-a11y": "^6.2.3",
|
|
54
|
-
"eslint-plugin-
|
|
55
|
-
"
|
|
56
|
-
"mocha": "^8.2.1",
|
|
46
|
+
"eslint-plugin-react": "^7.16.0",
|
|
47
|
+
"mocha": "3.5.0",
|
|
57
48
|
"mocha-lcov-reporter": "^1.3.0",
|
|
58
|
-
"nyc": "^14.1.1"
|
|
59
|
-
"semantic-release": "^17.2.2",
|
|
60
|
-
"sinon": "^9.2.1",
|
|
61
|
-
"sinon-chai": "^3.5.0",
|
|
62
|
-
"ts-mocha": "^8.0.0",
|
|
63
|
-
"ts-node": "^9.0.0",
|
|
64
|
-
"typescript": "^4.0.5"
|
|
49
|
+
"nyc": "^14.1.1"
|
|
65
50
|
}
|
|
66
51
|
}
|
package/.huskyrc
DELETED
package/.mocharc.json
DELETED
package/.releaserc.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"branches": [
|
|
3
|
-
"master",
|
|
4
|
-
{
|
|
5
|
-
"name": "*",
|
|
6
|
-
"prerelease": "${name.substring(0,7)}"
|
|
7
|
-
}
|
|
8
|
-
],
|
|
9
|
-
"plugins": [
|
|
10
|
-
"@semantic-release/commit-analyzer",
|
|
11
|
-
"@semantic-release/npm",
|
|
12
|
-
[ "@semantic-release/git", {
|
|
13
|
-
"assets": ["package.json"],
|
|
14
|
-
"message": "chore(release): ${nextRelease.version} [skip ci]"
|
|
15
|
-
}]
|
|
16
|
-
],
|
|
17
|
-
"repositoryUrl": "git@bitbucket.org:elliptic/aml-utils.git"
|
|
18
|
-
}
|
package/commitlint.config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = { extends: ['@commitlint/config-angular'] };
|
package/dist/errors/errors.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export const RequestError: any;
|
|
2
|
-
export const ServerError: any;
|
|
3
|
-
export const Forbidden: any;
|
|
4
|
-
export const Unauthorized: any;
|
|
5
|
-
export const BadRequest: any;
|
|
6
|
-
export const NotFound: any;
|
|
7
|
-
export const ConflictError: any;
|
|
8
|
-
export const InvalidArguments: any;
|
|
9
|
-
export const ServerTimeout: any;
|
package/dist/errors/errors.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const create = require('create-error');
|
|
3
|
-
const AppError = create('AppError');
|
|
4
|
-
const RequestError = create(AppError, 'RequestError');
|
|
5
|
-
RequestError.toJSON = () => ({
|
|
6
|
-
message: this.message,
|
|
7
|
-
});
|
|
8
|
-
const Forbidden = create(RequestError, 'ForbiddenError', {
|
|
9
|
-
status: 403,
|
|
10
|
-
});
|
|
11
|
-
const Unauthorized = create(RequestError, 'UnauthorizedError', {
|
|
12
|
-
status: 401,
|
|
13
|
-
});
|
|
14
|
-
const BadRequest = create(RequestError, 'BadRequestError', {
|
|
15
|
-
status: 400,
|
|
16
|
-
});
|
|
17
|
-
const NotFound = create(RequestError, 'NotFoundError', {
|
|
18
|
-
status: 404,
|
|
19
|
-
});
|
|
20
|
-
const ConflictError = create(RequestError, 'ConflictError', {
|
|
21
|
-
status: 409,
|
|
22
|
-
});
|
|
23
|
-
const ServerError = create(RequestError, 'ServerError', {
|
|
24
|
-
status: 500,
|
|
25
|
-
});
|
|
26
|
-
const InvalidArguments = create(RequestError, 'InvalidArgumentsError', {
|
|
27
|
-
status: 500,
|
|
28
|
-
});
|
|
29
|
-
const ServerTimeout = create(RequestError, 'ServerTimeoutError', {
|
|
30
|
-
status: 503,
|
|
31
|
-
});
|
|
32
|
-
module.exports = {
|
|
33
|
-
RequestError,
|
|
34
|
-
ServerError,
|
|
35
|
-
Forbidden,
|
|
36
|
-
Unauthorized,
|
|
37
|
-
BadRequest,
|
|
38
|
-
NotFound,
|
|
39
|
-
ConflictError,
|
|
40
|
-
InvalidArguments,
|
|
41
|
-
ServerTimeout,
|
|
42
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const { RequestError, Forbidden, Unauthorized, BadRequest, NotFound, } = require('./errors');
|
|
3
|
-
describe('lib/error', () => {
|
|
4
|
-
describe('RequestError', () => {
|
|
5
|
-
it('should inherit from Error', () => (new RequestError instanceof Error).should.be.true);
|
|
6
|
-
describe('Forbidden Error', () => {
|
|
7
|
-
it('should inherit from Error', () => new Forbidden instanceof Error);
|
|
8
|
-
return it('should inherit from RequestError', () => new Forbidden instanceof RequestError);
|
|
9
|
-
});
|
|
10
|
-
describe('Unauthorized Error', () => {
|
|
11
|
-
it('should inherit from Error', () => new Unauthorized instanceof Error);
|
|
12
|
-
return it('should inherit from RequestError', () => new Unauthorized instanceof RequestError);
|
|
13
|
-
});
|
|
14
|
-
describe('BadRequest Error', () => {
|
|
15
|
-
it('should inherit from Error', () => new BadRequest instanceof Error);
|
|
16
|
-
return it('should inherit from RequestError', () => new BadRequest instanceof RequestError);
|
|
17
|
-
});
|
|
18
|
-
return describe('NotFound Error', () => {
|
|
19
|
-
it('should inherit from Error', () => new NotFound instanceof Error);
|
|
20
|
-
return it('should inherit from RequestError', () => new NotFound instanceof RequestError);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
|
-
};
|
|
33
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
const sinon_1 = __importDefault(require("sinon"));
|
|
35
|
-
const chai_1 = require("chai");
|
|
36
|
-
const file_parser_1 = __importDefault(require("../file-parser"));
|
|
37
|
-
const sanitizeRows = __importStar(require("../sanitzeRows"));
|
|
38
|
-
const parseRow = __importStar(require("../parse-row"));
|
|
39
|
-
describe('file-parser', () => {
|
|
40
|
-
const dependencies = {
|
|
41
|
-
processRow: sinon_1.default.spy(),
|
|
42
|
-
};
|
|
43
|
-
const parsedRows = [];
|
|
44
|
-
const mockParseRow = sinon_1.default.stub(parseRow, 'default').returns(parsedRows);
|
|
45
|
-
const mockSanitizeRows = sinon_1.default.stub(sanitizeRows, 'default').returns([{}]);
|
|
46
|
-
const mockSetTimeout = sinon_1.default.stub(global, 'setTimeout').callsFake((callback) => callback());
|
|
47
|
-
beforeEach(() => {
|
|
48
|
-
sinon_1.default.resetHistory();
|
|
49
|
-
});
|
|
50
|
-
after(() => {
|
|
51
|
-
sinon_1.default.restore();
|
|
52
|
-
});
|
|
53
|
-
it('should call parseRow once per input new line', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
-
const input = '\n';
|
|
55
|
-
yield file_parser_1.default(input, 50, dependencies);
|
|
56
|
-
chai_1.expect(mockParseRow).to.be.calledTwice;
|
|
57
|
-
}));
|
|
58
|
-
it('should call pass parseRow result into sanitizeRows', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
-
const input = '\n';
|
|
60
|
-
yield file_parser_1.default(input, 50, dependencies);
|
|
61
|
-
chai_1.expect(mockSanitizeRows).to.be.calledOnce;
|
|
62
|
-
chai_1.expect(mockSanitizeRows).to.be.deep.calledWith([[], []], dependencies.processRow);
|
|
63
|
-
}));
|
|
64
|
-
it('should throw error when number of rows is more than max rows', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
-
const input = '\n';
|
|
66
|
-
mockSanitizeRows.returns(new Array(20));
|
|
67
|
-
try {
|
|
68
|
-
yield file_parser_1.default(input, 10, dependencies);
|
|
69
|
-
chai_1.expect(1).to.equal(2);
|
|
70
|
-
}
|
|
71
|
-
catch (ex) {
|
|
72
|
-
chai_1.expect(ex.name).to.equal('TooManyRowsError');
|
|
73
|
-
}
|
|
74
|
-
}));
|
|
75
|
-
it('should throw error when no rows returned from sanitizeRows', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
76
|
-
const input = '\n';
|
|
77
|
-
mockSanitizeRows.returns([]);
|
|
78
|
-
try {
|
|
79
|
-
yield file_parser_1.default(input, 10, dependencies);
|
|
80
|
-
chai_1.expect(1).to.equal(2);
|
|
81
|
-
}
|
|
82
|
-
catch (ex) {
|
|
83
|
-
chai_1.expect(ex.name).to.equal('Error');
|
|
84
|
-
}
|
|
85
|
-
}));
|
|
86
|
-
it('should throw error an error when content is "invalidFileType"', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
87
|
-
const input = 'invalidFileType';
|
|
88
|
-
mockSanitizeRows.returns([]);
|
|
89
|
-
try {
|
|
90
|
-
yield file_parser_1.default(input, 10, dependencies);
|
|
91
|
-
chai_1.expect(1).to.equal(2);
|
|
92
|
-
}
|
|
93
|
-
catch (ex) {
|
|
94
|
-
chai_1.expect(ex.message).to.equal('Invalid file type');
|
|
95
|
-
}
|
|
96
|
-
}));
|
|
97
|
-
it('should call process row once per row in single timeout', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
98
|
-
const input = '\n';
|
|
99
|
-
const fakeRows = (new Array(30)).fill({});
|
|
100
|
-
mockSanitizeRows.returns(fakeRows);
|
|
101
|
-
yield file_parser_1.default(input, 70, dependencies);
|
|
102
|
-
chai_1.expect(dependencies.processRow).to.be.callCount(30);
|
|
103
|
-
chai_1.expect(mockSetTimeout).to.be.calledOnce;
|
|
104
|
-
}));
|
|
105
|
-
it('should call process row once per row in two timeouts when more than 30 rows', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
106
|
-
const input = '\n';
|
|
107
|
-
const fakeRows = (new Array(50)).fill({});
|
|
108
|
-
mockSanitizeRows.returns(fakeRows);
|
|
109
|
-
yield file_parser_1.default(input, 70, dependencies);
|
|
110
|
-
chai_1.expect(dependencies.processRow).to.be.callCount(50);
|
|
111
|
-
chai_1.expect(mockSetTimeout).to.be.calledTwice;
|
|
112
|
-
}));
|
|
113
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const chai_1 = require("chai");
|
|
7
|
-
const parse_row_1 = __importDefault(require("../parse-row"));
|
|
8
|
-
describe('parse-row', () => {
|
|
9
|
-
it('should handle tabs', () => {
|
|
10
|
-
const input = 'asdas \t asdar \t aaaaa \t bbb bb';
|
|
11
|
-
const result = parse_row_1.default(input);
|
|
12
|
-
chai_1.expect(result).to.have.length(4);
|
|
13
|
-
});
|
|
14
|
-
it('should handle comas', () => {
|
|
15
|
-
const input = 'asdas, asdar, aaaaa, bbb bb';
|
|
16
|
-
const result = parse_row_1.default(input);
|
|
17
|
-
chai_1.expect(result).to.have.length(4);
|
|
18
|
-
});
|
|
19
|
-
it('should handle spaces', () => {
|
|
20
|
-
const input = 'asdas asdar aaaaa bbb bb';
|
|
21
|
-
const result = parse_row_1.default(input);
|
|
22
|
-
chai_1.expect(result).to.have.length(4);
|
|
23
|
-
});
|
|
24
|
-
it('should handle spaces', () => {
|
|
25
|
-
const input = 'asdas asdar aaaaa bbb bb';
|
|
26
|
-
const result = parse_row_1.default(input);
|
|
27
|
-
chai_1.expect(result).to.have.length(5);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const chai_1 = require("chai");
|
|
7
|
-
const sinon_1 = __importDefault(require("sinon"));
|
|
8
|
-
const sanitzeRows_1 = __importDefault(require("../sanitzeRows"));
|
|
9
|
-
describe('sanitize-rows', () => {
|
|
10
|
-
it('should remove empty rows at the start of the array', () => {
|
|
11
|
-
const input = [
|
|
12
|
-
['', '', ''],
|
|
13
|
-
['this', 'is', 'valid'],
|
|
14
|
-
['this', 'is', 'valid'],
|
|
15
|
-
];
|
|
16
|
-
const result = sanitzeRows_1.default(input, () => ({
|
|
17
|
-
isValid: true,
|
|
18
|
-
}));
|
|
19
|
-
chai_1.expect(result).to.have.length(2);
|
|
20
|
-
});
|
|
21
|
-
it('should remove empty rows at the end of the array', () => {
|
|
22
|
-
const input = [
|
|
23
|
-
['this', 'is', 'valid'],
|
|
24
|
-
['this', 'is', 'valid'],
|
|
25
|
-
['', '', ''],
|
|
26
|
-
];
|
|
27
|
-
const result = sanitzeRows_1.default(input, () => ({
|
|
28
|
-
isValid: true,
|
|
29
|
-
}));
|
|
30
|
-
chai_1.expect(result).to.have.length(2);
|
|
31
|
-
});
|
|
32
|
-
it('should remove empty rows at the start and end of the array', () => {
|
|
33
|
-
const input = [
|
|
34
|
-
['', '', ''],
|
|
35
|
-
['', '', ''],
|
|
36
|
-
['', '', ''],
|
|
37
|
-
['this', 'is', 'valid'],
|
|
38
|
-
['this', 'is', 'valid'],
|
|
39
|
-
['', '', ''],
|
|
40
|
-
['', '', ''],
|
|
41
|
-
['', '', ''],
|
|
42
|
-
];
|
|
43
|
-
const result = sanitzeRows_1.default(input, () => ({
|
|
44
|
-
isValid: true,
|
|
45
|
-
}));
|
|
46
|
-
chai_1.expect(result).to.have.length(2);
|
|
47
|
-
});
|
|
48
|
-
it('should remove the first row if it is not empty and not valid', () => {
|
|
49
|
-
const input = [
|
|
50
|
-
['', '', ''],
|
|
51
|
-
['this', 'is', 'invalid'],
|
|
52
|
-
['this', 'is', 'valid'],
|
|
53
|
-
['this', 'is', 'valid'],
|
|
54
|
-
['', '', ''],
|
|
55
|
-
['', '', ''],
|
|
56
|
-
['', '', ''],
|
|
57
|
-
];
|
|
58
|
-
const returnsFalseOnce = sinon_1.default.stub();
|
|
59
|
-
returnsFalseOnce.returns(true);
|
|
60
|
-
returnsFalseOnce.onFirstCall().returns(false);
|
|
61
|
-
const result = sanitzeRows_1.default(input, returnsFalseOnce);
|
|
62
|
-
chai_1.expect(result).to.have.length(2);
|
|
63
|
-
});
|
|
64
|
-
it('should allow rows with some empty values', () => {
|
|
65
|
-
const input = [
|
|
66
|
-
['this', 'is', 'invalid'],
|
|
67
|
-
['this', 'is', 'valid'],
|
|
68
|
-
['this', 'is', 'valid'],
|
|
69
|
-
['valid', '', ''],
|
|
70
|
-
['', '', ''],
|
|
71
|
-
['', '', ''],
|
|
72
|
-
];
|
|
73
|
-
const result = sanitzeRows_1.default(input, () => ({
|
|
74
|
-
isValid: true,
|
|
75
|
-
}));
|
|
76
|
-
chai_1.expect(result).to.have.length(4);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TooManyRowsError = void 0;
|
|
4
|
-
// eslint-disable-next-line import/prefer-default-export
|
|
5
|
-
class TooManyRowsError extends Error {
|
|
6
|
-
constructor() {
|
|
7
|
-
super('More than configured number of rows imported');
|
|
8
|
-
this.name = 'TooManyRowsError';
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
exports.TooManyRowsError = TooManyRowsError;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export declare type ProcessingEntry = {
|
|
2
|
-
isValid: boolean;
|
|
3
|
-
};
|
|
4
|
-
declare type Dependencies<T extends ProcessingEntry> = {
|
|
5
|
-
processRow: (cells: string[]) => T;
|
|
6
|
-
};
|
|
7
|
-
declare function parseFile<T extends ProcessingEntry>(fileContent: string, maxRows: number, dependencies: Dependencies<T>): Promise<T[]>;
|
|
8
|
-
export default parseFile;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const parse_row_1 = __importDefault(require("./parse-row"));
|
|
16
|
-
const errors_1 = require("./errors");
|
|
17
|
-
const sanitzeRows_1 = __importDefault(require("./sanitzeRows"));
|
|
18
|
-
function chunk(array, size) {
|
|
19
|
-
if (!array.length) {
|
|
20
|
-
return [];
|
|
21
|
-
}
|
|
22
|
-
const head = array.slice(0, size);
|
|
23
|
-
const tail = array.slice(size);
|
|
24
|
-
return [head, ...chunk(tail, size)];
|
|
25
|
-
}
|
|
26
|
-
function processChunk(parsedRows, dependencies) {
|
|
27
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
const { processRow } = dependencies;
|
|
29
|
-
return new Promise((resolve, reject) => {
|
|
30
|
-
setTimeout(() => {
|
|
31
|
-
try {
|
|
32
|
-
const processedRows = parsedRows.map(processRow);
|
|
33
|
-
resolve(processedRows);
|
|
34
|
-
}
|
|
35
|
-
catch (ex) {
|
|
36
|
-
reject(ex);
|
|
37
|
-
}
|
|
38
|
-
}, 0);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
function parseFile(fileContent, maxRows, dependencies) {
|
|
43
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
const { processRow } = dependencies;
|
|
45
|
-
if (fileContent === 'invalidFileType') {
|
|
46
|
-
throw Error('Invalid file type');
|
|
47
|
-
}
|
|
48
|
-
const rows = fileContent.split('\n');
|
|
49
|
-
const parsedRows = rows.map(parse_row_1.default);
|
|
50
|
-
const sanitizedRows = sanitzeRows_1.default(parsedRows, processRow);
|
|
51
|
-
if (sanitizedRows.length > maxRows) {
|
|
52
|
-
throw new errors_1.TooManyRowsError();
|
|
53
|
-
}
|
|
54
|
-
if (sanitizedRows.length === 0) {
|
|
55
|
-
throw new Error('No rows');
|
|
56
|
-
}
|
|
57
|
-
const parsedRowChunks = chunk(sanitizedRows, 30);
|
|
58
|
-
let results = [];
|
|
59
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
60
|
-
for (const currentRowChunk of parsedRowChunks) {
|
|
61
|
-
// eslint-disable-next-line no-await-in-loop
|
|
62
|
-
const chunkResult = yield processChunk(currentRowChunk, dependencies);
|
|
63
|
-
results = results.concat(chunkResult);
|
|
64
|
-
}
|
|
65
|
-
return results;
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
exports.default = parseFile;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const fp_1 = require("lodash/fp");
|
|
4
|
-
const parseRow = (row) => {
|
|
5
|
-
const trySplitByTab = (line) => {
|
|
6
|
-
if (typeof line === 'string' && line.match('\t')) {
|
|
7
|
-
return line.split('\t');
|
|
8
|
-
}
|
|
9
|
-
return line;
|
|
10
|
-
};
|
|
11
|
-
const trySplitByComa = (line) => {
|
|
12
|
-
if (typeof line === 'string' && line.match(',')) {
|
|
13
|
-
return line.split(',');
|
|
14
|
-
}
|
|
15
|
-
return line;
|
|
16
|
-
};
|
|
17
|
-
const trySplitByMultipleSpaces = (line) => {
|
|
18
|
-
if (typeof line === 'string' && line.match(/ {3,}/)) {
|
|
19
|
-
return line.split(/ {3,}/);
|
|
20
|
-
}
|
|
21
|
-
return line;
|
|
22
|
-
};
|
|
23
|
-
const trySplitBySpace = (line) => {
|
|
24
|
-
if (typeof line === 'string' && line.match(' ')) {
|
|
25
|
-
return line.split(' ');
|
|
26
|
-
}
|
|
27
|
-
return line;
|
|
28
|
-
};
|
|
29
|
-
const trySplitByNothing = (line) => {
|
|
30
|
-
if (typeof line === 'string') {
|
|
31
|
-
return [line];
|
|
32
|
-
}
|
|
33
|
-
return line;
|
|
34
|
-
};
|
|
35
|
-
const splitRow = fp_1.pipe(trySplitByTab, trySplitByComa, trySplitByMultipleSpaces, trySplitBySpace, trySplitByNothing);
|
|
36
|
-
const cells = splitRow(row);
|
|
37
|
-
return cells.map((c) => c.trim());
|
|
38
|
-
};
|
|
39
|
-
exports.default = parseRow;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const sensicalRowCheck = (cells) => (cells.some((cell) => !!cell));
|
|
4
|
-
function sanitizeRows(parsedRows, processRow) {
|
|
5
|
-
const firstSensicalRowIndex = parsedRows
|
|
6
|
-
.findIndex(sensicalRowCheck);
|
|
7
|
-
const lastSensicalRowIndex = [...parsedRows]
|
|
8
|
-
.reverse()
|
|
9
|
-
.findIndex(sensicalRowCheck);
|
|
10
|
-
const sanitizedRows = parsedRows
|
|
11
|
-
.splice(firstSensicalRowIndex, parsedRows.length - firstSensicalRowIndex - lastSensicalRowIndex);
|
|
12
|
-
const firstRow = processRow(sanitizedRows[0]);
|
|
13
|
-
if (firstRow.isValid) {
|
|
14
|
-
return sanitizedRows;
|
|
15
|
-
}
|
|
16
|
-
return sanitizedRows.splice(1);
|
|
17
|
-
}
|
|
18
|
-
exports.default = sanitizeRows;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const _ = require('lodash');
|
|
3
|
-
const rethrowError = (fnName, e) => {
|
|
4
|
-
let formattedError;
|
|
5
|
-
if (_.isPlainObject(e.error) || _.isArray(e.error)) {
|
|
6
|
-
formattedError = `\n${JSON.stringify(e.error, null, 2)}`;
|
|
7
|
-
}
|
|
8
|
-
else {
|
|
9
|
-
formattedError = e.error;
|
|
10
|
-
}
|
|
11
|
-
return `${fnName} - ${e.name}: ${e.statusCode} - ${formattedError}`;
|
|
12
|
-
};
|
|
13
|
-
const sqlEscapeWildcard = (str) => str.replace(/_|%|\\/g, (x) => `\\${x}`);
|
|
14
|
-
module.exports = {
|
|
15
|
-
rethrowError,
|
|
16
|
-
sqlEscapeWildcard,
|
|
17
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const chai = require('chai');
|
|
3
|
-
const { sqlEscapeWildcard, rethrowError } = require('./formatting');
|
|
4
|
-
const { expect } = chai;
|
|
5
|
-
describe('formatting.sqlEscapeWildcard', () => {
|
|
6
|
-
describe('when passed an empty string', () => {
|
|
7
|
-
it('returns an empty string', () => sqlEscapeWildcard('').should.equal(''));
|
|
8
|
-
});
|
|
9
|
-
describe('when passed a string with no sql wildcards', () => {
|
|
10
|
-
it('returns the same string', () => {
|
|
11
|
-
const str = 'foo bar';
|
|
12
|
-
return sqlEscapeWildcard(str).should.equal(str);
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
return describe('when passed a string with sql wildcards', () => {
|
|
16
|
-
it('returns the string with \\ % _ escaped', () => {
|
|
17
|
-
const str = 'foo\\dfs_erwr%rewr';
|
|
18
|
-
return sqlEscapeWildcard(str).should.equal('foo\\\\dfs\\_erwr\\%rewr');
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
describe('rethrowError', () => {
|
|
23
|
-
it('returns an error when given a string', () => rethrowError('myFunc', { error: 'Oh dear, myFunc is broken' })
|
|
24
|
-
.should.equal('myFunc - undefined: undefined - Oh dear, myFunc is broken'));
|
|
25
|
-
it('returns an error when passed an error object', () => rethrowError('myFunc', {
|
|
26
|
-
name: "I'm a teapot",
|
|
27
|
-
statusCode: 418,
|
|
28
|
-
error: "I'm a little teapot, short and stout",
|
|
29
|
-
}).should.equal("myFunc - I'm a teapot: 418 - I'm a little teapot, short and stout"));
|
|
30
|
-
it('accepts an array containing an error', () => {
|
|
31
|
-
const thrownError = rethrowError('myFunc', {
|
|
32
|
-
error: ["I'm a teapot", 418, "I'm a little teapot, short and stout"],
|
|
33
|
-
});
|
|
34
|
-
const expected = JSON.stringify('myFunc - undefined: undefined - \n[\n "I\'m a teapot",\n 418,\n "I\'m a little teapot, short and stout"\n]');
|
|
35
|
-
expect(JSON.stringify(thrownError)).to.equal(expected);
|
|
36
|
-
});
|
|
37
|
-
});
|
package/dist/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import types from './types/types';
|
|
2
|
-
import validations from './validations/validations';
|
|
3
|
-
import errors from './errors/errors';
|
|
4
|
-
import formatting from './formatting/formatting';
|
|
5
|
-
import middleware from './middleware/middleware';
|
|
6
|
-
import ormHelpers from './orm-helpers/ormHelpers';
|
|
7
|
-
import fileParser from './file-parser/file-parser';
|
|
8
|
-
export { types, validations, errors, formatting, fileParser, middleware, ormHelpers, };
|