@ellipticltd/aml-utils 0.15.20 → 0.15.22

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 (67) hide show
  1. package/lib/errors/errors.d.ts +9 -0
  2. package/lib/errors/errors.js +19 -30
  3. package/lib/errors/errors.js.map +1 -0
  4. package/lib/file-parser/errors.d.ts +3 -0
  5. package/lib/file-parser/errors.js +11 -0
  6. package/lib/file-parser/errors.js.map +1 -0
  7. package/lib/file-parser/file-parser.d.ts +6 -0
  8. package/lib/file-parser/file-parser.js +60 -0
  9. package/lib/file-parser/file-parser.js.map +1 -0
  10. package/lib/file-parser/parse-row.d.ts +2 -0
  11. package/lib/file-parser/parse-row.js +40 -0
  12. package/lib/file-parser/parse-row.js.map +1 -0
  13. package/lib/file-parser/sanitizeRows.d.ts +5 -0
  14. package/lib/file-parser/sanitizeRows.js +15 -0
  15. package/lib/file-parser/sanitizeRows.js.map +1 -0
  16. package/lib/formatting/formatting.d.ts +2 -0
  17. package/lib/formatting/formatting.js +11 -12
  18. package/lib/formatting/formatting.js.map +1 -0
  19. package/lib/{index.ts → index.d.ts} +0 -1
  20. package/lib/index.js +21 -0
  21. package/lib/index.js.map +1 -0
  22. package/lib/middleware/middleware.d.ts +4 -0
  23. package/lib/middleware/middleware.js +14 -17
  24. package/lib/middleware/middleware.js.map +1 -0
  25. package/lib/orm-helpers/ormHelpers.d.ts +1 -0
  26. package/lib/orm-helpers/ormHelpers.js +7 -9
  27. package/lib/orm-helpers/ormHelpers.js.map +1 -0
  28. package/lib/structured-file-parser/errors.d.ts +12 -0
  29. package/lib/structured-file-parser/errors.js +33 -0
  30. package/lib/structured-file-parser/errors.js.map +1 -0
  31. package/lib/structured-file-parser/parse-row.d.ts +2 -0
  32. package/lib/structured-file-parser/parse-row.js +40 -0
  33. package/lib/structured-file-parser/parse-row.js.map +1 -0
  34. package/lib/structured-file-parser/sanitize-rows.d.ts +2 -0
  35. package/lib/structured-file-parser/sanitize-rows.js +14 -0
  36. package/lib/structured-file-parser/sanitize-rows.js.map +1 -0
  37. package/lib/structured-file-parser/structured-file-parser.d.ts +10 -0
  38. package/lib/structured-file-parser/structured-file-parser.js +96 -0
  39. package/lib/structured-file-parser/structured-file-parser.js.map +1 -0
  40. package/lib/types/types.d.ts +11 -0
  41. package/lib/types/types.js +190 -200
  42. package/lib/types/types.js.map +1 -0
  43. package/lib/validations/validations.d.ts +163 -0
  44. package/lib/validations/validations.js +468 -465
  45. package/lib/validations/validations.js.map +1 -0
  46. package/package.json +15 -1
  47. package/.eslintrc.js +0 -22
  48. package/dist/libs/aml-utils/libs/aml-utils/README.md +0 -19
  49. package/jest.config.ts +0 -13
  50. package/lib/errors/errors.spec.js +0 -49
  51. package/lib/file-parser/__tests/parse-row.spec.js +0 -34
  52. package/lib/file-parser/__tests/sanitize-rows.spec.js +0 -85
  53. package/lib/file-parser/errors.ts +0 -6
  54. package/lib/file-parser/file-parser.ts +0 -67
  55. package/lib/file-parser/parse-row.ts +0 -46
  56. package/lib/file-parser/sanitizeRows.ts +0 -22
  57. package/lib/formatting/formatting.spec.js +0 -47
  58. package/lib/orm-helpers/ormHelpers.spec.js +0 -47
  59. package/lib/structured-file-parser/errors.ts +0 -25
  60. package/lib/structured-file-parser/parse-row.ts +0 -46
  61. package/lib/structured-file-parser/sanitize-rows.ts +0 -17
  62. package/lib/structured-file-parser/structured-file-parser.ts +0 -129
  63. package/lib/validations/validations.spec.js +0 -869
  64. package/project.json +0 -55
  65. package/tsconfig.json +0 -13
  66. package/tsconfig.lib.json +0 -13
  67. package/tsconfig.spec.json +0 -10
@@ -0,0 +1,9 @@
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;
@@ -1,53 +1,42 @@
1
1
  const create = require('create-error');
2
-
3
2
  const AppError = create('AppError');
4
-
5
3
  const RequestError = create(AppError, 'RequestError');
6
-
7
4
  RequestError.toJSON = () => ({
8
- message: this.message,
5
+ message: this.message,
9
6
  });
10
-
11
7
  const Forbidden = create(RequestError, 'ForbiddenError', {
12
- status: 403,
8
+ status: 403,
13
9
  });
14
-
15
10
  const Unauthorized = create(RequestError, 'UnauthorizedError', {
16
- status: 401,
11
+ status: 401,
17
12
  });
18
-
19
13
  const BadRequest = create(RequestError, 'BadRequestError', {
20
- status: 400,
14
+ status: 400,
21
15
  });
22
-
23
16
  const NotFound = create(RequestError, 'NotFoundError', {
24
- status: 404,
17
+ status: 404,
25
18
  });
26
-
27
19
  const ConflictError = create(RequestError, 'ConflictError', {
28
- status: 409,
20
+ status: 409,
29
21
  });
30
-
31
22
  const ServerError = create(RequestError, 'ServerError', {
32
- status: 500,
23
+ status: 500,
33
24
  });
34
-
35
25
  const InvalidArguments = create(RequestError, 'InvalidArgumentsError', {
36
- status: 500,
26
+ status: 500,
37
27
  });
38
-
39
28
  const ServerTimeout = create(RequestError, 'ServerTimeoutError', {
40
- status: 503,
29
+ status: 503,
41
30
  });
42
-
43
31
  module.exports = {
44
- RequestError,
45
- ServerError,
46
- Forbidden,
47
- Unauthorized,
48
- BadRequest,
49
- NotFound,
50
- ConflictError,
51
- InvalidArguments,
52
- ServerTimeout,
32
+ RequestError,
33
+ ServerError,
34
+ Forbidden,
35
+ Unauthorized,
36
+ BadRequest,
37
+ NotFound,
38
+ ConflictError,
39
+ InvalidArguments,
40
+ ServerTimeout,
53
41
  };
42
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../../libs/aml-utils/lib/errors/errors.js"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAEvC,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAEpC,MAAM,YAAY,GAAG,MAAM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+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TooManyRowsError = void 0;
4
+ class TooManyRowsError extends Error {
5
+ constructor() {
6
+ super('More than configured number of rows imported');
7
+ this.name = 'TooManyRowsError';
8
+ }
9
+ }
10
+ exports.TooManyRowsError = TooManyRowsError;
11
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../../libs/aml-utils/lib/file-parser/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,gBAAiB,SAAQ,KAAK;IACzC;QACE,KAAK,CAAC,8CAA8C,CAAC,CAAC;QACtD,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AALD,4CAKC"}
@@ -0,0 +1,6 @@
1
+ import { ProcessingEntry } from './sanitizeRows';
2
+ type Dependencies<T extends ProcessingEntry> = {
3
+ processRow: (cells: string[]) => T;
4
+ };
5
+ declare function parseFile<T extends ProcessingEntry>(fileContent: string, maxRows: number, dependencies: Dependencies<T>): Promise<T[]>;
6
+ export default parseFile;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const parse_row_1 = tslib_1.__importDefault(require("./parse-row"));
5
+ const errors_1 = require("./errors");
6
+ const sanitizeRows_1 = tslib_1.__importDefault(require("./sanitizeRows"));
7
+ function chunk(array, size) {
8
+ if (!array.length) {
9
+ return [];
10
+ }
11
+ const head = array.slice(0, size);
12
+ const tail = array.slice(size);
13
+ return [head, ...chunk(tail, size)];
14
+ }
15
+ function processChunk(parsedRows, dependencies) {
16
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
17
+ const { processRow } = dependencies;
18
+ return new Promise((resolve, reject) => {
19
+ setTimeout(() => {
20
+ try {
21
+ const processedRows = parsedRows.map(processRow);
22
+ resolve(processedRows);
23
+ }
24
+ catch (ex) {
25
+ if (ex instanceof Error) {
26
+ reject(ex);
27
+ }
28
+ }
29
+ }, 0);
30
+ });
31
+ });
32
+ }
33
+ function parseFile(fileContent, maxRows, dependencies) {
34
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
35
+ const { processRow } = dependencies;
36
+ if (fileContent === 'invalidFileType') {
37
+ throw Error('Invalid file type');
38
+ }
39
+ const rows = fileContent.split('\n');
40
+ const parsedRows = rows.map(parse_row_1.default);
41
+ const sanitizedRows = (0, sanitizeRows_1.default)(parsedRows, processRow);
42
+ if (sanitizedRows.length > maxRows) {
43
+ throw new errors_1.TooManyRowsError();
44
+ }
45
+ if (sanitizedRows.length === 0) {
46
+ throw new Error('No rows');
47
+ }
48
+ const parsedRowChunks = chunk(sanitizedRows, 30);
49
+ let results = [];
50
+ // eslint-disable-next-line no-restricted-syntax
51
+ for (const currentRowChunk of parsedRowChunks) {
52
+ // eslint-disable-next-line no-await-in-loop
53
+ const chunkResult = yield processChunk(currentRowChunk, dependencies);
54
+ results = results.concat(chunkResult);
55
+ }
56
+ return results;
57
+ });
58
+ }
59
+ exports.default = parseFile;
60
+ //# sourceMappingURL=file-parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-parser.js","sourceRoot":"","sources":["../../../../../libs/aml-utils/lib/file-parser/file-parser.ts"],"names":[],"mappings":";;;AAAA,oEAAmC;AACnC,qCAA4C;AAC5C,0EAA+D;AAM/D,SAAS,KAAK,CAAI,KAAU,EAAE,IAAY;IACxC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;QACjB,OAAO,EAAE,CAAC;KACX;IACD,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IAClC,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE/B,OAAO,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AACtC,CAAC;AAED,SAAe,YAAY,CAA4B,UAAsB,EAAE,Y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C,4CAA4C;YAC5C,MAAM,WAAW,GAAG,MAAM,YAAY,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;YACtE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;SACvC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CAAA;AAED,kBAAe,SAAS,CAAC"}
@@ -0,0 +1,2 @@
1
+ declare const parseRow: (row: string) => string[];
2
+ export default parseRow;
@@ -0,0 +1,40 @@
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 = (0, 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;
40
+ //# sourceMappingURL=parse-row.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-row.js","sourceRoot":"","sources":["../../../../../libs/aml-utils/lib/file-parser/parse-row.ts"],"names":[],"mappings":";;AAAA,kCAAiC;AAEjC,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAY,EAAE;IACzC,MAAM,aA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nH,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;IAE5B,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AAC5C,CAAC,CAAC;AAEF,kBAAe,QAAQ,CAAC"}
@@ -0,0 +1,5 @@
1
+ export type ProcessingEntry = {
2
+ isValid: boolean;
3
+ };
4
+ declare function sanitizeRows<T extends ProcessingEntry>(parsedRows: string[][], processRow: (row: string[]) => T): string[][];
5
+ export default sanitizeRows;
@@ -0,0 +1,15 @@
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.findIndex(sensicalRowCheck);
6
+ const lastSensicalRowIndex = [...parsedRows].reverse().findIndex(sensicalRowCheck);
7
+ const sanitizedRows = parsedRows.splice(firstSensicalRowIndex, parsedRows.length - firstSensicalRowIndex - lastSensicalRowIndex);
8
+ const firstRow = processRow(sanitizedRows[0]);
9
+ if (firstRow.isValid) {
10
+ return sanitizedRows;
11
+ }
12
+ return sanitizedRows.splice(1);
13
+ }
14
+ exports.default = sanitizeRows;
15
+ //# sourceMappingURL=sanitizeRows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitizeRows.js","sourceRoot":"","sources":["../../../../../libs/aml-utils/lib/file-parser/sanitizeRows.ts"],"names":[],"mappings":";;AAIA,MAAM,gBAAgB,GAAG,CAAC,KAAe,EAAW,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAE5F,SAAS,YAAY,CAA4B,UAAsB,EAAE,UAAgC;IACvG,MAAM,qBAAqB,GAAG,UAAU,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;IAErE,MAAM,oBAAoB,GAAG,CAAC,GAAG,UAAU,CAAC,CAAC,OAAO,EAAE,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;IAEnF,MAAM,aAAa,GAAG,UAAU,CAAC,MAAM,CAAC,qBAAqB,EAAE,UAAU,CAAC,MAAM,GAAG,qBAAqB,GAAG,oBAAoB,CAAC,CAAC;IAEjI,MAAM,QAAQ,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IAE9C,IAAI,QAAQ,CAAC,OAAO,EAAE;QACpB,OAAO,aAAa,CAAC;KACtB;IACD,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACjC,CAAC;AAED,kBAAe,YAAY,CAAC"}
@@ -0,0 +1,2 @@
1
+ export function rethrowError(fnName: any, e: any): string;
2
+ export function sqlEscapeWildcard(str: any): any;
@@ -1,18 +1,17 @@
1
1
  const _ = require('lodash');
2
-
3
2
  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
- } else {
8
- formattedError = e.error;
9
- }
10
- return `${fnName} - ${e.name}: ${e.statusCode} - ${formattedError}`;
3
+ let formattedError;
4
+ if (_.isPlainObject(e.error) || _.isArray(e.error)) {
5
+ formattedError = `\n${JSON.stringify(e.error, null, 2)}`;
6
+ }
7
+ else {
8
+ formattedError = e.error;
9
+ }
10
+ return `${fnName} - ${e.name}: ${e.statusCode} - ${formattedError}`;
11
11
  };
12
-
13
12
  const sqlEscapeWildcard = (str) => str.replace(/_|%|\\/g, (x) => `\\${x}`);
14
-
15
13
  module.exports = {
16
- rethrowError,
17
- sqlEscapeWildcard,
14
+ rethrowError,
15
+ sqlEscapeWildcard,
18
16
  };
17
+ //# sourceMappingURL=formatting.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatting.js","sourceRoot":"","sources":["../../../../../libs/aml-utils/lib/formatting/formatting.js"],"names":[],"mappings":"AAAA,MAAM,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE5B,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;IACjC,IAAI,cAAc,CAAC;IACnB,IAAI,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE;QAClD,cAAc,GAAG,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;KAC1D;SAAM;QACL,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC;KAC1B;IACD,OAAO,GAAG,MAAM,MAAM,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,UAAU,MAAM,cAAc,EAAE,CAAC;AACtE,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAE3E,MAAM,CAAC,OAAO,GAAG;IACf,YAAY;IACZ,iBAAiB;CAClB,CAAC"}
@@ -6,5 +6,4 @@ import middleware from './middleware/middleware';
6
6
  import ormHelpers from './orm-helpers/ormHelpers';
7
7
  import fileParser from './file-parser/file-parser';
8
8
  import structuredFileParser from './structured-file-parser/structured-file-parser';
9
-
10
9
  export { types, validations, errors, formatting, fileParser, structuredFileParser, middleware, ormHelpers };
package/lib/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ormHelpers = exports.middleware = exports.structuredFileParser = exports.fileParser = exports.formatting = exports.errors = exports.validations = exports.types = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const types_1 = tslib_1.__importDefault(require("./types/types"));
6
+ exports.types = types_1.default;
7
+ const validations_1 = tslib_1.__importDefault(require("./validations/validations"));
8
+ exports.validations = validations_1.default;
9
+ const errors_1 = tslib_1.__importDefault(require("./errors/errors"));
10
+ exports.errors = errors_1.default;
11
+ const formatting_1 = tslib_1.__importDefault(require("./formatting/formatting"));
12
+ exports.formatting = formatting_1.default;
13
+ const middleware_1 = tslib_1.__importDefault(require("./middleware/middleware"));
14
+ exports.middleware = middleware_1.default;
15
+ const ormHelpers_1 = tslib_1.__importDefault(require("./orm-helpers/ormHelpers"));
16
+ exports.ormHelpers = ormHelpers_1.default;
17
+ const file_parser_1 = tslib_1.__importDefault(require("./file-parser/file-parser"));
18
+ exports.fileParser = file_parser_1.default;
19
+ const structured_file_parser_1 = tslib_1.__importDefault(require("./structured-file-parser/structured-file-parser"));
20
+ exports.structuredFileParser = structured_file_parser_1.default;
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/aml-utils/lib/index.ts"],"names":[],"mappings":";;;;AAAA,kEAAkC;AASzB,gBATF,eAAK,CASE;AARd,oFAAoD;AAQpC,sBART,qBAAW,CAQS;AAP3B,qEAAqC;AAOR,iBAPtB,gBAAM,CAOsB;AANnC,iFAAiD;AAMZ,qBAN9B,oBAAU,CAM8B;AAL/C,iFAAiD;AAKkC,qBAL5E,oBAAU,CAK4E;AAJ7F,kFAAkD;AAI6C,qBAJxF,oBAAU,CAIwF;AAHzG,oFAAmD;AAGF,qBAH1C,qBAAU,CAG0C;AAF3D,qHAAmF;AAEtB,+BAFtD,gCAAoB,CAEsD"}
@@ -0,0 +1,4 @@
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,25 +1,22 @@
1
1
  const T = require('../types/types');
2
-
3
2
  const ensureType = (type) => (req, res, next, id, name) => {
4
- let error;
5
- try {
6
- T.ensureType(type, id, `Invalid ${name}`);
7
- return next();
8
- } catch (error1) {
9
- error = error1;
10
- return next(error);
11
- }
3
+ let error;
4
+ try {
5
+ T.ensureType(type, id, `Invalid ${name}`);
6
+ return next();
7
+ }
8
+ catch (error1) {
9
+ error = error1;
10
+ return next(error);
11
+ }
12
12
  };
13
-
14
13
  const ensureUUID = ensureType('UUID');
15
-
16
14
  const ensureHex32 = ensureType('Hex32');
17
-
18
15
  const ensureInteger = ensureType('IntString');
19
-
20
16
  module.exports = {
21
- ensureType,
22
- ensureUUID,
23
- ensureHex32,
24
- ensureInteger,
17
+ ensureType,
18
+ ensureUUID,
19
+ ensureHex32,
20
+ ensureInteger,
25
21
  };
22
+ //# sourceMappingURL=middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../../../libs/aml-utils/lib/middleware/middleware.js"],"names":[],"mappings":"AAAA,MAAM,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAEpC,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE;IACxD,IAAI,KAAK,CAAC;IACV,IAAI;QACF,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,EAAE,WAAW,IAAI,EAAE,CAAC,CAAC;QAC1C,OAAO,IAAI,EAAE,CAAC;KACf;IAAC,OAAO,MAAM,EAAE;QACf,KAAK,GAAG,MAAM,CAAC;QACf,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;KACpB;AACH,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;AAEtC,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;AAExC,MAAM,aAAa,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;AAE9C,MAAM,CAAC,OAAO,GAAG;IACf,UAAU;IACV,UAAU;IACV,WAAW;IACX,aAAa;CACd,CAAC"}
@@ -0,0 +1 @@
1
+ export function includeNested(orm: any, models: any): any;
@@ -1,19 +1,17 @@
1
1
  const _ = require('lodash');
2
-
3
- const includeNested = (orm, models) =>
4
- _.map(_.toPairs(models), (arg) => {
2
+ const includeNested = (orm, models) => _.map(_.toPairs(models), (arg) => {
5
3
  const [modelName, inclusion] = arg;
6
4
  const include = includeNested(orm, inclusion);
7
5
  const model = orm[modelName];
8
6
  if (_.isEmpty(include)) {
9
- return model;
7
+ return model;
10
8
  }
11
9
  return {
12
- model,
13
- include,
10
+ model,
11
+ include,
14
12
  };
15
- });
16
-
13
+ });
17
14
  module.exports = {
18
- includeNested,
15
+ includeNested,
19
16
  };
17
+ //# sourceMappingURL=ormHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ormHelpers.js","sourceRoot":"","sources":["../../../../../libs/aml-utils/lib/orm-helpers/ormHelpers.js"],"names":[],"mappings":"AAAA,MAAM,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE5B,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,CACpC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE;IAC/B,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,GAAG,GAAG,CAAC;IACnC,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC;IAC7B,IAAI,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QACtB,OAAO,KAAK,CAAC;KACd;IACD,OAAO;QACL,KAAK;QACL,OAAO;KACR,CAAC;AACJ,CAAC,CAAC,CAAC;AAEL,MAAM,CAAC,OAAO,GAAG;IACf,aAAa;CACd,CAAC"}
@@ -0,0 +1,12 @@
1
+ export declare class InvalidFileError extends Error {
2
+ constructor();
3
+ }
4
+ export declare class TooManyRowsError extends Error {
5
+ constructor();
6
+ }
7
+ export declare class NoRowsError extends Error {
8
+ constructor();
9
+ }
10
+ export declare class InvalidHeadersError extends Error {
11
+ constructor();
12
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidHeadersError = exports.NoRowsError = exports.TooManyRowsError = exports.InvalidFileError = void 0;
4
+ /* eslint-disable max-classes-per-file */
5
+ class InvalidFileError extends Error {
6
+ constructor() {
7
+ super('Invalid file type');
8
+ this.name = 'InvalidFileError';
9
+ }
10
+ }
11
+ exports.InvalidFileError = InvalidFileError;
12
+ class TooManyRowsError extends Error {
13
+ constructor() {
14
+ super('More than configured number of rows imported');
15
+ this.name = 'TooManyRowsError';
16
+ }
17
+ }
18
+ exports.TooManyRowsError = TooManyRowsError;
19
+ class NoRowsError extends Error {
20
+ constructor() {
21
+ super('No rows');
22
+ this.name = 'NoRowsError';
23
+ }
24
+ }
25
+ exports.NoRowsError = NoRowsError;
26
+ class InvalidHeadersError extends Error {
27
+ constructor() {
28
+ super('Invalid or incomplete headers list');
29
+ this.name = 'InvalidHeadersError';
30
+ }
31
+ }
32
+ exports.InvalidHeadersError = InvalidHeadersError;
33
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../../libs/aml-utils/lib/structured-file-parser/errors.ts"],"names":[],"mappings":";;;AAAA,yCAAyC;AACzC,MAAa,gBAAiB,SAAQ,KAAK;IACzC;QACE,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AALD,4CAKC;AACD,MAAa,gBAAiB,SAAQ,KAAK;IACzC;QACE,KAAK,CAAC,8CAA8C,CAAC,CAAC;QACtD,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AALD,4CAKC;AACD,MAAa,WAAY,SAAQ,KAAK;IACpC;QACE,KAAK,CAAC,SAAS,CAAC,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AALD,kCAKC;AACD,MAAa,mBAAoB,SAAQ,KAAK;IAC5C;QACE,KAAK,CAAC,oCAAoC,CAAC,CAAC;QAC5C,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AALD,kDAKC"}
@@ -0,0 +1,2 @@
1
+ declare const parseRow: (row: string) => string[];
2
+ export default parseRow;
@@ -0,0 +1,40 @@
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 = (0, 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;
40
+ //# sourceMappingURL=parse-row.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-row.js","sourceRoot":"","s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AC;IACd,CAAC,CAAC;IAEF,MAAM,QAAQ,GAAG,IAAA,SAAI,EAAC,aAAa,EAAE,cAAc,EAAE,wBAAwB,EAAE,eAAe,EAAE,iBAAiB,CAAC,CAAC;IAEnH,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;IAE5B,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AAC5C,CAAC,CAAC;AAEF,kBAAe,QAAQ,CAAC"}
@@ -0,0 +1,2 @@
1
+ declare function sanitizeRows(parsedRows: string[][]): string[][];
2
+ export default sanitizeRows;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const sensicalRowCheck = (cells) => cells.some((cell) => !!cell);
4
+ function sanitizeRows(parsedRows) {
5
+ const firstSensicalRowIndex = parsedRows.findIndex(sensicalRowCheck);
6
+ const lastSensicalRowIndex = [...parsedRows].reverse().findIndex(sensicalRowCheck);
7
+ if (firstSensicalRowIndex < 0) {
8
+ return [];
9
+ }
10
+ const sanitizedRows = [...parsedRows].splice(firstSensicalRowIndex, parsedRows.length - firstSensicalRowIndex - lastSensicalRowIndex);
11
+ return sanitizedRows;
12
+ }
13
+ exports.default = sanitizeRows;
14
+ //# sourceMappingURL=sanitize-rows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize-rows.js","sourceRoot":"","sources":["../../../../../libs/aml-utils/lib/structured-file-parser/sanitize-rows.ts"],"names":[],"mappings":";;AAAA,MAAM,gBAAgB,GAAG,CAAC,KAAe,EAAW,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAE5F,SAAS,YAAY,CAAC,UAAsB;IAC1C,MAAM,qBAAqB,GAAG,UAAU,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;IAErE,MAAM,oBAAoB,GAAG,CAAC,GAAG,UAAU,CAAC,CAAC,OAAO,EAAE,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;IAEnF,IAAI,qBAAqB,GAAG,CAAC,EAAE;QAC7B,OAAO,EAAE,CAAC;KACX;IAED,MAAM,aAAa,GAAG,CAAC,GAAG,UAAU,CAAC,CAAC,MAAM,CAAC,qBAAqB,EAAE,UAAU,CAAC,MAAM,GAAG,qBAAqB,GAAG,oBAAoB,CAAC,CAAC;IAEtI,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,kBAAe,YAAY,CAAC"}
@@ -0,0 +1,10 @@
1
+ export type ProcessingEntry = {
2
+ isValid: boolean;
3
+ };
4
+ type Dependencies<T extends ProcessingEntry> = {
5
+ processRow: (cells: string[], headers: string[]) => T;
6
+ };
7
+ export declare const hasHeaderRow: (rows: string[][], requiredHeaderNames: string[]) => boolean;
8
+ export declare const isHeaderRowValid: (rows: string[][], requiredHeaderNames: string[]) => boolean;
9
+ declare function parseFile<T extends ProcessingEntry>(fileContent: string, maxRows: number, requiredHeaderNames: string[], dependencies: Dependencies<T>): Promise<T[]>;
10
+ export default parseFile;