@ellipticltd/aml-utils 0.15.9 → 0.15.10-SCR-1297
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/README.md +6 -46
- package/{dist → lib}/file-parser/errors.js +1 -0
- package/lib/file-parser/errors.js.map +1 -0
- package/{dist → lib}/file-parser/file-parser.d.ts +1 -3
- package/{dist → lib}/file-parser/file-parser.js +10 -18
- package/lib/file-parser/file-parser.js.map +1 -0
- package/{dist/structured-file-parser → lib/file-parser}/parse-row.js +2 -1
- package/lib/file-parser/parse-row.js.map +1 -0
- package/{dist → lib}/file-parser/sanitzeRows.d.ts +3 -1
- package/lib/file-parser/sanitzeRows.js +15 -0
- package/lib/file-parser/sanitzeRows.js.map +1 -0
- package/{dist → lib}/index.d.ts +1 -1
- package/lib/index.js +21 -0
- package/lib/index.js.map +1 -0
- package/{dist → lib}/structured-file-parser/errors.js +1 -0
- package/lib/structured-file-parser/errors.js.map +1 -0
- package/{dist/file-parser → lib/structured-file-parser}/parse-row.js +2 -1
- package/lib/structured-file-parser/parse-row.js.map +1 -0
- package/{dist → lib}/structured-file-parser/sanitize-rows.js +3 -4
- package/lib/structured-file-parser/sanitize-rows.js.map +1 -0
- package/{dist → lib}/structured-file-parser/structured-file-parser.js +18 -26
- package/lib/structured-file-parser/structured-file-parser.js.map +1 -0
- package/package.json +10 -61
- package/.circleci/config.yml +0 -87
- package/.eslintrc +0 -44
- package/.huskyrc +0 -5
- package/.mocharc.json +0 -3
- package/.nvmrc +0 -1
- package/.nyc_output/6b68ea83-db7a-45cb-b572-16338a5cea4b.json +0 -1
- package/.nyc_output/a74c6648-3619-4b08-bc8c-ac8cb4959f43.json +0 -1
- package/.nyc_output/c9b6c4ce-fddf-403b-aa2e-aac05145213c.json +0 -1
- package/.nyc_output/d9967655-96b8-471a-9686-a4585437f85a.json +0 -1
- package/.nyc_output/processinfo/6b68ea83-db7a-45cb-b572-16338a5cea4b.json +0 -1
- package/.nyc_output/processinfo/a74c6648-3619-4b08-bc8c-ac8cb4959f43.json +0 -1
- package/.nyc_output/processinfo/c9b6c4ce-fddf-403b-aa2e-aac05145213c.json +0 -1
- package/.nyc_output/processinfo/d9967655-96b8-471a-9686-a4585437f85a.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/.nycrc.json +0 -11
- package/.releaserc.json +0 -18
- package/.snyk +0 -12
- package/codecov.yml +0 -29
- package/commitlint.config.js +0 -1
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -79
- package/coverage/errors/errors.js.html +0 -228
- package/coverage/errors/errors.spec.js.html +0 -180
- package/coverage/errors/index.html +0 -110
- package/coverage/file-parser/__tests/file-parser.spec.js.html +0 -390
- package/coverage/file-parser/__tests/index.html +0 -123
- package/coverage/file-parser/__tests/parse-row.spec.js.html +0 -174
- package/coverage/file-parser/__tests/sanitize-rows.spec.js.html +0 -333
- package/coverage/formatting/formatting.js.html +0 -123
- package/coverage/formatting/formatting.spec.js.html +0 -204
- package/coverage/formatting/index.html +0 -110
- package/coverage/index.html +0 -175
- package/coverage/middleware/index.html +0 -97
- package/coverage/middleware/middleware.js.html +0 -144
- package/coverage/orm-helpers/index.html +0 -110
- package/coverage/orm-helpers/ormHelpers.js.html +0 -123
- package/coverage/orm-helpers/ormHelpers.spec.js.html +0 -192
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -170
- package/coverage/types/index.html +0 -97
- package/coverage/types/types.js.html +0 -708
- package/coverage/validations/index.html +0 -110
- package/coverage/validations/validations.js.html +0 -1419
- package/coverage/validations/validations.spec.js.html +0 -1800
- 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 -118
- 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/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.js +0 -22
- 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 -232
- package/dist/validations/validations.js +0 -459
- package/dist/validations/validations.spec.d.ts +0 -1
- package/dist/validations/validations.spec.js +0 -463
- package/lib/errors/errors.js +0 -53
- package/lib/errors/errors.spec.js +0 -37
- package/lib/file-parser/__tests/file-parser.spec.js +0 -107
- 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.js +0 -18
- package/lib/formatting/formatting.spec.js +0 -45
- package/lib/index.ts +0 -19
- package/lib/middleware/middleware.js +0 -25
- package/lib/orm-helpers/ormHelpers.js +0 -18
- package/lib/orm-helpers/ormHelpers.spec.js +0 -41
- package/lib/structured-file-parser/errors.ts +0 -25
- package/lib/structured-file-parser/parse-row.ts +0 -52
- package/lib/structured-file-parser/sanitize-rows.ts +0 -24
- package/lib/structured-file-parser/structured-file-parser.ts +0 -155
- package/lib/types/types.js +0 -213
- package/lib/validations/validations.js +0 -466
- package/lib/validations/validations.spec.js +0 -603
- package/tsconfig.json +0 -26
- /package/{dist → lib}/file-parser/errors.d.ts +0 -0
- /package/{dist → lib}/file-parser/parse-row.d.ts +0 -0
- /package/{dist → lib}/structured-file-parser/errors.d.ts +0 -0
- /package/{dist → lib}/structured-file-parser/parse-row.d.ts +0 -0
- /package/{dist → lib}/structured-file-parser/sanitize-rows.d.ts +0 -0
- /package/{dist → lib}/structured-file-parser/structured-file-parser.d.ts +0 -0
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,118 +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
|
-
let mockParseRow;
|
|
45
|
-
let mockSanitizeRows;
|
|
46
|
-
let mockSetTimeout;
|
|
47
|
-
before(() => {
|
|
48
|
-
mockParseRow = sinon_1.default.stub(parseRow, 'default').returns(parsedRows);
|
|
49
|
-
mockSanitizeRows = sinon_1.default.stub(sanitizeRows, 'default').returns([{}]);
|
|
50
|
-
mockSetTimeout = sinon_1.default.stub(global, 'setTimeout').callsFake((callback) => callback());
|
|
51
|
-
});
|
|
52
|
-
beforeEach(() => {
|
|
53
|
-
sinon_1.default.resetHistory();
|
|
54
|
-
});
|
|
55
|
-
after(() => {
|
|
56
|
-
sinon_1.default.restore();
|
|
57
|
-
});
|
|
58
|
-
it('should call parseRow once per input new line', () => __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(mockParseRow).to.be.calledTwice;
|
|
62
|
-
}));
|
|
63
|
-
it('should call pass parseRow result into sanitizeRows', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
-
const input = '\n';
|
|
65
|
-
yield file_parser_1.default(input, 50, dependencies);
|
|
66
|
-
chai_1.expect(mockSanitizeRows).to.be.calledOnce;
|
|
67
|
-
chai_1.expect(mockSanitizeRows).to.be.deep.calledWith([[], []], dependencies.processRow);
|
|
68
|
-
}));
|
|
69
|
-
it('should throw error when number of rows is more than max rows', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
-
const input = '\n';
|
|
71
|
-
mockSanitizeRows.returns(new Array(20));
|
|
72
|
-
try {
|
|
73
|
-
yield file_parser_1.default(input, 10, dependencies);
|
|
74
|
-
chai_1.expect(1).to.equal(2);
|
|
75
|
-
}
|
|
76
|
-
catch (ex) {
|
|
77
|
-
chai_1.expect(ex.name).to.equal('TooManyRowsError');
|
|
78
|
-
}
|
|
79
|
-
}));
|
|
80
|
-
it('should throw error when no rows returned from sanitizeRows', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
|
-
const input = '\n';
|
|
82
|
-
mockSanitizeRows.returns([]);
|
|
83
|
-
try {
|
|
84
|
-
yield file_parser_1.default(input, 10, dependencies);
|
|
85
|
-
chai_1.expect(1).to.equal(2);
|
|
86
|
-
}
|
|
87
|
-
catch (ex) {
|
|
88
|
-
chai_1.expect(ex.name).to.equal('Error');
|
|
89
|
-
}
|
|
90
|
-
}));
|
|
91
|
-
it('should throw error an error when content is "invalidFileType"', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
92
|
-
const input = 'invalidFileType';
|
|
93
|
-
mockSanitizeRows.returns([]);
|
|
94
|
-
try {
|
|
95
|
-
yield file_parser_1.default(input, 10, dependencies);
|
|
96
|
-
chai_1.expect(1).to.equal(2);
|
|
97
|
-
}
|
|
98
|
-
catch (ex) {
|
|
99
|
-
chai_1.expect(ex.message).to.equal('Invalid file type');
|
|
100
|
-
}
|
|
101
|
-
}));
|
|
102
|
-
it('should call process row once per row in single timeout', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
103
|
-
const input = '\n';
|
|
104
|
-
const fakeRows = (new Array(30)).fill({});
|
|
105
|
-
mockSanitizeRows.returns(fakeRows);
|
|
106
|
-
yield file_parser_1.default(input, 70, dependencies);
|
|
107
|
-
chai_1.expect(dependencies.processRow).to.be.callCount(30);
|
|
108
|
-
chai_1.expect(mockSetTimeout).to.be.calledOnce;
|
|
109
|
-
}));
|
|
110
|
-
it('should call process row once per row in two timeouts when more than 30 rows', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
111
|
-
const input = '\n';
|
|
112
|
-
const fakeRows = (new Array(50)).fill({});
|
|
113
|
-
mockSanitizeRows.returns(fakeRows);
|
|
114
|
-
yield file_parser_1.default(input, 70, dependencies);
|
|
115
|
-
chai_1.expect(dependencies.processRow).to.be.callCount(50);
|
|
116
|
-
chai_1.expect(mockSetTimeout).to.be.calledTwice;
|
|
117
|
-
}));
|
|
118
|
-
});
|
|
@@ -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,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.js
DELETED
|
@@ -1,22 +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
|
-
exports.ormHelpers = exports.middleware = exports.structuredFileParser = exports.fileParser = exports.formatting = exports.errors = exports.validations = exports.types = void 0;
|
|
7
|
-
const types_1 = __importDefault(require("./types/types"));
|
|
8
|
-
exports.types = types_1.default;
|
|
9
|
-
const validations_1 = __importDefault(require("./validations/validations"));
|
|
10
|
-
exports.validations = validations_1.default;
|
|
11
|
-
const errors_1 = __importDefault(require("./errors/errors"));
|
|
12
|
-
exports.errors = errors_1.default;
|
|
13
|
-
const formatting_1 = __importDefault(require("./formatting/formatting"));
|
|
14
|
-
exports.formatting = formatting_1.default;
|
|
15
|
-
const middleware_1 = __importDefault(require("./middleware/middleware"));
|
|
16
|
-
exports.middleware = middleware_1.default;
|
|
17
|
-
const ormHelpers_1 = __importDefault(require("./orm-helpers/ormHelpers"));
|
|
18
|
-
exports.ormHelpers = ormHelpers_1.default;
|
|
19
|
-
const file_parser_1 = __importDefault(require("./file-parser/file-parser"));
|
|
20
|
-
exports.fileParser = file_parser_1.default;
|
|
21
|
-
const structured_file_parser_1 = __importDefault(require("./structured-file-parser/structured-file-parser"));
|
|
22
|
-
exports.structuredFileParser = structured_file_parser_1.default;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export function ensureType(type: any): (req: any, res: any, next: any, id: any, name: any) => any;
|
|
2
|
-
export function ensureUUID(req: any, res: any, next: any, id: any, name: any): any;
|
|
3
|
-
export function ensureHex32(req: any, res: any, next: any, id: any, name: any): any;
|
|
4
|
-
export function ensureInteger(req: any, res: any, next: any, id: any, name: any): any;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const T = require('../types/types');
|
|
3
|
-
const ensureType = (type) => (req, res, next, id, name) => {
|
|
4
|
-
let error;
|
|
5
|
-
try {
|
|
6
|
-
T.ensureType(type, id, `Invalid ${name}`);
|
|
7
|
-
return next();
|
|
8
|
-
}
|
|
9
|
-
catch (error1) {
|
|
10
|
-
error = error1;
|
|
11
|
-
return next(error);
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
const ensureUUID = ensureType('UUID');
|
|
15
|
-
const ensureHex32 = ensureType('Hex32');
|
|
16
|
-
const ensureInteger = ensureType('IntString');
|
|
17
|
-
module.exports = {
|
|
18
|
-
ensureType,
|
|
19
|
-
ensureUUID,
|
|
20
|
-
ensureHex32,
|
|
21
|
-
ensureInteger,
|
|
22
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export function includeNested(orm: any, models: any): any;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const _ = require('lodash');
|
|
3
|
-
const includeNested = (orm, models) => _.map(_.toPairs(models), (arg) => {
|
|
4
|
-
const [modelName, inclusion] = arg;
|
|
5
|
-
const include = includeNested(orm, inclusion);
|
|
6
|
-
const model = orm[modelName];
|
|
7
|
-
if (_.isEmpty(include)) {
|
|
8
|
-
return model;
|
|
9
|
-
}
|
|
10
|
-
return {
|
|
11
|
-
model,
|
|
12
|
-
include,
|
|
13
|
-
};
|
|
14
|
-
});
|
|
15
|
-
module.exports = {
|
|
16
|
-
includeNested,
|
|
17
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const { includeNested } = require('./ormHelpers');
|
|
3
|
-
describe('ormIncludeNested', () => {
|
|
4
|
-
const orm = {
|
|
5
|
-
a: 'a',
|
|
6
|
-
b: 'b',
|
|
7
|
-
c: 'c',
|
|
8
|
-
d: 'd',
|
|
9
|
-
};
|
|
10
|
-
describe('when passed an empty object', () => {
|
|
11
|
-
it('returns an empty array', () => includeNested(orm, {}).should.deep.equal([]));
|
|
12
|
-
});
|
|
13
|
-
describe('when passed an object with no inclusions', () => {
|
|
14
|
-
it('returns an array of just the key', () => includeNested(orm, {
|
|
15
|
-
a: {},
|
|
16
|
-
}).should.deep.equal(['a']));
|
|
17
|
-
});
|
|
18
|
-
describe('when passed a hierarchy of inclusions', () => {
|
|
19
|
-
it('should nest them in sequelize style', () => includeNested(orm, {
|
|
20
|
-
a: {
|
|
21
|
-
b: {
|
|
22
|
-
c: {},
|
|
23
|
-
d: {},
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
}).should.deep.equal([
|
|
27
|
-
{
|
|
28
|
-
model: 'a',
|
|
29
|
-
include: [
|
|
30
|
-
{
|
|
31
|
-
model: 'b',
|
|
32
|
-
include: ['c', 'd'],
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
},
|
|
36
|
-
]));
|
|
37
|
-
});
|
|
38
|
-
});
|
package/dist/types/types.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
declare const withNullable: {};
|
|
2
|
-
export function parseType(str: any): any;
|
|
3
|
-
export function parseType(str: any): any;
|
|
4
|
-
export function parsedTypeCheck(type: any, obj: any): any;
|
|
5
|
-
export function parsedTypeCheck(type: any, obj: any): any;
|
|
6
|
-
export function typeCheck(type: any, obj: any): any;
|
|
7
|
-
export function typeCheck(type: any, obj: any): any;
|
|
8
|
-
export namespace opts {
|
|
9
|
-
export { withNullable as customTypes };
|
|
10
|
-
}
|
|
11
|
-
export function ensureType(type: any, obj: any, msg: any): boolean;
|
|
12
|
-
export function ensureType(type: any, obj: any, msg: any): boolean;
|
|
13
|
-
export function checkArg(obj: any, prop: any, type: any, msg: any): any;
|
|
14
|
-
export function checkArg(obj: any, prop: any, type: any, msg: any): any;
|
|
15
|
-
export function checkArgs(input: any, types: any): void;
|
|
16
|
-
export function checkArgs(input: any, types: any): void;
|
|
17
|
-
export {};
|