@ellipticltd/aml-utils 0.8.0-EN-2570.4 → 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.js → validations.js} +8 -8
- 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 -116
- package/dist/validations/validations.js +0 -296
- 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
|
@@ -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, };
|
package/dist/index.js
DELETED
|
@@ -1,20 +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.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;
|
|
@@ -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 {};
|