@ellipticltd/aml-utils 0.15.32-FLOW-431 → 0.15.32

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 (66) hide show
  1. package/.eslintrc.js +22 -0
  2. package/jest.config.ts +13 -0
  3. package/lib/errors/errors.js +30 -19
  4. package/lib/errors/errors.spec.js +49 -0
  5. package/lib/file-parser/__tests/parse-row.spec.js +34 -0
  6. package/lib/file-parser/__tests/sanitize-rows.spec.js +85 -0
  7. package/lib/file-parser/errors.ts +6 -0
  8. package/lib/file-parser/file-parser.ts +67 -0
  9. package/lib/file-parser/parse-row.ts +46 -0
  10. package/lib/file-parser/sanitizeRows.ts +22 -0
  11. package/lib/formatting/formatting.js +12 -11
  12. package/lib/formatting/formatting.spec.js +47 -0
  13. package/lib/{index.d.ts → index.ts} +1 -0
  14. package/lib/middleware/middleware.js +17 -14
  15. package/lib/orm-helpers/ormHelpers.js +9 -7
  16. package/lib/orm-helpers/ormHelpers.spec.js +47 -0
  17. package/lib/structured-file-parser/errors.ts +25 -0
  18. package/lib/structured-file-parser/parse-row.ts +46 -0
  19. package/lib/structured-file-parser/sanitize-rows.ts +17 -0
  20. package/lib/structured-file-parser/structured-file-parser.ts +129 -0
  21. package/lib/types/types.js +200 -190
  22. package/lib/validations/validations.js +505 -495
  23. package/lib/validations/validations.spec.js +973 -0
  24. package/package.json +1 -15
  25. package/project.json +55 -0
  26. package/tsconfig.json +13 -0
  27. package/tsconfig.lib.json +14 -0
  28. package/tsconfig.spec.json +10 -0
  29. package/lib/errors/errors.d.ts +0 -9
  30. package/lib/errors/errors.js.map +0 -1
  31. package/lib/file-parser/errors.d.ts +0 -3
  32. package/lib/file-parser/errors.js +0 -11
  33. package/lib/file-parser/errors.js.map +0 -1
  34. package/lib/file-parser/file-parser.d.ts +0 -6
  35. package/lib/file-parser/file-parser.js +0 -60
  36. package/lib/file-parser/file-parser.js.map +0 -1
  37. package/lib/file-parser/parse-row.d.ts +0 -2
  38. package/lib/file-parser/parse-row.js +0 -40
  39. package/lib/file-parser/parse-row.js.map +0 -1
  40. package/lib/file-parser/sanitizeRows.d.ts +0 -5
  41. package/lib/file-parser/sanitizeRows.js +0 -15
  42. package/lib/file-parser/sanitizeRows.js.map +0 -1
  43. package/lib/formatting/formatting.d.ts +0 -2
  44. package/lib/formatting/formatting.js.map +0 -1
  45. package/lib/index.js +0 -21
  46. package/lib/index.js.map +0 -1
  47. package/lib/middleware/middleware.d.ts +0 -4
  48. package/lib/middleware/middleware.js.map +0 -1
  49. package/lib/orm-helpers/ormHelpers.d.ts +0 -1
  50. package/lib/orm-helpers/ormHelpers.js.map +0 -1
  51. package/lib/structured-file-parser/errors.d.ts +0 -12
  52. package/lib/structured-file-parser/errors.js +0 -33
  53. package/lib/structured-file-parser/errors.js.map +0 -1
  54. package/lib/structured-file-parser/parse-row.d.ts +0 -2
  55. package/lib/structured-file-parser/parse-row.js +0 -40
  56. package/lib/structured-file-parser/parse-row.js.map +0 -1
  57. package/lib/structured-file-parser/sanitize-rows.d.ts +0 -2
  58. package/lib/structured-file-parser/sanitize-rows.js +0 -14
  59. package/lib/structured-file-parser/sanitize-rows.js.map +0 -1
  60. package/lib/structured-file-parser/structured-file-parser.d.ts +0 -10
  61. package/lib/structured-file-parser/structured-file-parser.js +0 -96
  62. package/lib/structured-file-parser/structured-file-parser.js.map +0 -1
  63. package/lib/types/types.d.ts +0 -11
  64. package/lib/types/types.js.map +0 -1
  65. package/lib/validations/validations.d.ts +0 -175
  66. package/lib/validations/validations.js.map +0 -1
package/.eslintrc.js ADDED
@@ -0,0 +1,22 @@
1
+ const path = require('path');
2
+
3
+ module.exports = {
4
+ extends: ['../../.eslintrc.js'],
5
+ ignorePatterns: ['!**/*'],
6
+ overrides: [
7
+ {
8
+ files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
9
+ rules: {
10
+ 'import/no-extraneous-dependencies': ['error', { packageDir: path.resolve(__dirname, '../../') }],
11
+ },
12
+ },
13
+ {
14
+ files: ['*.ts', '*.tsx'],
15
+ rules: {},
16
+ },
17
+ {
18
+ files: ['*.js', '*.jsx'],
19
+ rules: {},
20
+ },
21
+ ],
22
+ };
package/jest.config.ts ADDED
@@ -0,0 +1,13 @@
1
+ export default {
2
+ displayName: 'aml-utils',
3
+ preset: '../../jest.preset.js',
4
+ globals: {
5
+ '@swc/jest': {
6
+ tsconfig: '<rootDir>/tsconfig.spec.json',
7
+ },
8
+ },
9
+ transform: {
10
+ '^.+\\.[tj]s$': '@swc/jest',
11
+ },
12
+ coverageDirectory: '../../coverage/libs/aml-utils',
13
+ };
@@ -1,42 +1,53 @@
1
1
  const create = require('create-error');
2
+
2
3
  const AppError = create('AppError');
4
+
3
5
  const RequestError = create(AppError, 'RequestError');
6
+
4
7
  RequestError.toJSON = () => ({
5
- message: this.message,
8
+ message: this.message,
6
9
  });
10
+
7
11
  const Forbidden = create(RequestError, 'ForbiddenError', {
8
- status: 403,
12
+ status: 403,
9
13
  });
14
+
10
15
  const Unauthorized = create(RequestError, 'UnauthorizedError', {
11
- status: 401,
16
+ status: 401,
12
17
  });
18
+
13
19
  const BadRequest = create(RequestError, 'BadRequestError', {
14
- status: 400,
20
+ status: 400,
15
21
  });
22
+
16
23
  const NotFound = create(RequestError, 'NotFoundError', {
17
- status: 404,
24
+ status: 404,
18
25
  });
26
+
19
27
  const ConflictError = create(RequestError, 'ConflictError', {
20
- status: 409,
28
+ status: 409,
21
29
  });
30
+
22
31
  const ServerError = create(RequestError, 'ServerError', {
23
- status: 500,
32
+ status: 500,
24
33
  });
34
+
25
35
  const InvalidArguments = create(RequestError, 'InvalidArgumentsError', {
26
- status: 500,
36
+ status: 500,
27
37
  });
38
+
28
39
  const ServerTimeout = create(RequestError, 'ServerTimeoutError', {
29
- status: 503,
40
+ status: 503,
30
41
  });
42
+
31
43
  module.exports = {
32
- RequestError,
33
- ServerError,
34
- Forbidden,
35
- Unauthorized,
36
- BadRequest,
37
- NotFound,
38
- ConflictError,
39
- InvalidArguments,
40
- ServerTimeout,
44
+ RequestError,
45
+ ServerError,
46
+ Forbidden,
47
+ Unauthorized,
48
+ BadRequest,
49
+ NotFound,
50
+ ConflictError,
51
+ InvalidArguments,
52
+ ServerTimeout,
41
53
  };
42
- //# sourceMappingURL=errors.js.map
@@ -0,0 +1,49 @@
1
+ const { RequestError, Forbidden, Unauthorized, BadRequest, NotFound } = require('./errors');
2
+
3
+ describe('lib/error', () => {
4
+ describe('RequestError', () => {
5
+ it('should inherit from Error', () => {
6
+ expect(new RequestError() instanceof Error).toEqual(true);
7
+ });
8
+
9
+ describe('Forbidden Error', () => {
10
+ it('should inherit from Error', () => {
11
+ expect(new Forbidden() instanceof Error).toEqual(true);
12
+ });
13
+
14
+ it('should inherit from RequestError', () => {
15
+ expect(new Forbidden() instanceof RequestError).toEqual(true);
16
+ });
17
+ });
18
+
19
+ describe('Unauthorized Error', () => {
20
+ it('should inherit from Error', () => {
21
+ expect(new Unauthorized() instanceof Error).toEqual(true);
22
+ });
23
+
24
+ it('should inherit from RequestError', () => {
25
+ expect(new Unauthorized() instanceof RequestError).toEqual(true);
26
+ });
27
+ });
28
+
29
+ describe('BadRequest Error', () => {
30
+ it('should inherit from Error', () => {
31
+ expect(new BadRequest() instanceof Error).toEqual(true);
32
+ });
33
+
34
+ it('should inherit from RequestError', () => {
35
+ expect(new BadRequest() instanceof RequestError).toEqual(true);
36
+ });
37
+ });
38
+
39
+ describe('NotFound Error', () => {
40
+ it('should inherit from Error', () => {
41
+ expect(new NotFound() instanceof Error).toEqual(true);
42
+ });
43
+
44
+ it('should inherit from RequestError', () => {
45
+ expect(new NotFound() instanceof RequestError).toEqual(true);
46
+ });
47
+ });
48
+ });
49
+ });
@@ -0,0 +1,34 @@
1
+ import parseRow from '../parse-row';
2
+
3
+ describe('parse-row', () => {
4
+ it('should handle tabs', () => {
5
+ const input = 'asdas \t asdar \t aaaaa \t bbb bb';
6
+
7
+ const result = parseRow(input);
8
+ expect(result).toHaveLength(4);
9
+ });
10
+
11
+ it('should handle comas', () => {
12
+ const input = 'asdas, asdar, aaaaa, bbb bb';
13
+
14
+ const result = parseRow(input);
15
+
16
+ expect(result).toHaveLength(4);
17
+ });
18
+
19
+ it('should handle spaces', () => {
20
+ const input = 'asdas asdar aaaaa bbb bb';
21
+
22
+ const result = parseRow(input);
23
+
24
+ expect(result).toHaveLength(4);
25
+ });
26
+
27
+ it('should handle spaces', () => {
28
+ const input = 'asdas asdar aaaaa bbb bb';
29
+
30
+ const result = parseRow(input);
31
+
32
+ expect(result).toHaveLength(5);
33
+ });
34
+ });
@@ -0,0 +1,85 @@
1
+ import sanitizeRows from '../sanitizeRows';
2
+
3
+ describe('sanitize-rows', () => {
4
+ it('should remove empty rows at the start of the array', () => {
5
+ const input = [
6
+ ['', '', ''],
7
+ ['this', 'is', 'valid'],
8
+ ['this', 'is', 'valid'],
9
+ ];
10
+
11
+ const result = sanitizeRows(input, () => ({
12
+ isValid: true,
13
+ }));
14
+
15
+ expect(result).toHaveLength(2);
16
+ });
17
+
18
+ it('should remove empty rows at the end of the array', () => {
19
+ const input = [
20
+ ['this', 'is', 'valid'],
21
+ ['this', 'is', 'valid'],
22
+ ['', '', ''],
23
+ ];
24
+
25
+ const result = sanitizeRows(input, () => ({
26
+ isValid: true,
27
+ }));
28
+
29
+ expect(result).toHaveLength(2);
30
+ });
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
+
44
+ const result = sanitizeRows(input, () => ({
45
+ isValid: true,
46
+ }));
47
+
48
+ expect(result).toHaveLength(2);
49
+ });
50
+
51
+ it('should remove the first row if it is not empty and not valid', () => {
52
+ const input = [
53
+ ['', '', ''],
54
+ ['this', 'is', 'invalid'],
55
+ ['this', 'is', 'valid'],
56
+ ['this', 'is', 'valid'],
57
+ ['', '', ''],
58
+ ['', '', ''],
59
+ ['', '', ''],
60
+ ];
61
+
62
+ const returnsFalseOnce = jest.fn();
63
+ returnsFalseOnce.mockReturnValueOnce(false).mockReturnValue(true);
64
+
65
+ const result = sanitizeRows(input, returnsFalseOnce);
66
+ expect(result).toHaveLength(2);
67
+ });
68
+
69
+ it('should allow rows with some empty values', () => {
70
+ const input = [
71
+ ['this', 'is', 'invalid'],
72
+ ['this', 'is', 'valid'],
73
+ ['this', 'is', 'valid'],
74
+ ['valid', '', ''],
75
+ ['', '', ''],
76
+ ['', '', ''],
77
+ ];
78
+
79
+ const result = sanitizeRows(input, () => ({
80
+ isValid: true,
81
+ }));
82
+
83
+ expect(result).toHaveLength(4);
84
+ });
85
+ });
@@ -0,0 +1,6 @@
1
+ export class TooManyRowsError extends Error {
2
+ constructor() {
3
+ super('More than configured number of rows imported');
4
+ this.name = 'TooManyRowsError';
5
+ }
6
+ }
@@ -0,0 +1,67 @@
1
+ import parseRow from './parse-row';
2
+ import { TooManyRowsError } from './errors';
3
+ import sanitizeRows, { ProcessingEntry } from './sanitizeRows';
4
+
5
+ type Dependencies<T extends ProcessingEntry> = {
6
+ processRow: (cells: string[]) => T;
7
+ };
8
+
9
+ function chunk<T>(array: T[], size: number): T[][] {
10
+ if (!array.length) {
11
+ return [];
12
+ }
13
+ const head = array.slice(0, size);
14
+ const tail = array.slice(size);
15
+
16
+ return [head, ...chunk(tail, size)];
17
+ }
18
+
19
+ async function processChunk<T extends ProcessingEntry>(parsedRows: string[][], dependencies: Dependencies<T>): Promise<T[]> {
20
+ const { processRow } = dependencies;
21
+ return new Promise((resolve: (value: T[]) => void, reject: (error: Error) => void): void => {
22
+ setTimeout(() => {
23
+ try {
24
+ const processedRows = parsedRows.map(processRow);
25
+ resolve(processedRows);
26
+ } catch (ex) {
27
+ if (ex instanceof Error) {
28
+ reject(ex);
29
+ }
30
+ }
31
+ }, 0);
32
+ });
33
+ }
34
+
35
+ async function parseFile<T extends ProcessingEntry>(fileContent: string, maxRows: number, dependencies: Dependencies<T>): Promise<T[]> {
36
+ const { processRow } = dependencies;
37
+
38
+ if (fileContent === 'invalidFileType') {
39
+ throw Error('Invalid file type');
40
+ }
41
+
42
+ const rows = fileContent.split('\n');
43
+ const parsedRows = rows.map(parseRow);
44
+
45
+ const sanitizedRows = sanitizeRows(parsedRows, processRow);
46
+
47
+ if (sanitizedRows.length > maxRows) {
48
+ throw new TooManyRowsError();
49
+ }
50
+
51
+ if (sanitizedRows.length === 0) {
52
+ throw new Error('No rows');
53
+ }
54
+
55
+ const parsedRowChunks = chunk(sanitizedRows, 30);
56
+ let results: T[] = [];
57
+ // eslint-disable-next-line no-restricted-syntax
58
+ for (const currentRowChunk of parsedRowChunks) {
59
+ // eslint-disable-next-line no-await-in-loop
60
+ const chunkResult = await processChunk(currentRowChunk, dependencies);
61
+ results = results.concat(chunkResult);
62
+ }
63
+
64
+ return results;
65
+ }
66
+
67
+ export default parseFile;
@@ -0,0 +1,46 @@
1
+ import { pipe } from 'lodash/fp';
2
+
3
+ const parseRow = (row: string): string[] => {
4
+ const trySplitByTab = (line: string | string[]): string | string[] => {
5
+ if (typeof line === 'string' && line.match('\t')) {
6
+ return line.split('\t');
7
+ }
8
+ return line;
9
+ };
10
+
11
+ const trySplitByComa = (line: string | string[]): string | string[] => {
12
+ if (typeof line === 'string' && line.match(',')) {
13
+ return line.split(',');
14
+ }
15
+ return line;
16
+ };
17
+
18
+ const trySplitByMultipleSpaces = (line: string | string[]): string | string[] => {
19
+ if (typeof line === 'string' && line.match(/ {3,}/)) {
20
+ return line.split(/ {3,}/);
21
+ }
22
+ return line;
23
+ };
24
+
25
+ const trySplitBySpace = (line: string | string[]): string | string[] => {
26
+ if (typeof line === 'string' && line.match(' ')) {
27
+ return line.split(' ');
28
+ }
29
+ return line;
30
+ };
31
+
32
+ const trySplitByNothing = (line: string | string[]): string[] => {
33
+ if (typeof line === 'string') {
34
+ return [line];
35
+ }
36
+ return line;
37
+ };
38
+
39
+ const splitRow = pipe(trySplitByTab, trySplitByComa, trySplitByMultipleSpaces, trySplitBySpace, trySplitByNothing);
40
+
41
+ const cells = splitRow(row);
42
+
43
+ return cells.map((c: string) => c.trim());
44
+ };
45
+
46
+ export default parseRow;
@@ -0,0 +1,22 @@
1
+ export type ProcessingEntry = {
2
+ isValid: boolean;
3
+ };
4
+
5
+ const sensicalRowCheck = (cells: string[]): boolean => cells.some((cell: string) => !!cell);
6
+
7
+ function sanitizeRows<T extends ProcessingEntry>(parsedRows: string[][], processRow: (row: string[]) => T): string[][] {
8
+ const firstSensicalRowIndex = parsedRows.findIndex(sensicalRowCheck);
9
+
10
+ const lastSensicalRowIndex = [...parsedRows].reverse().findIndex(sensicalRowCheck);
11
+
12
+ const sanitizedRows = parsedRows.splice(firstSensicalRowIndex, parsedRows.length - firstSensicalRowIndex - lastSensicalRowIndex);
13
+
14
+ const firstRow = processRow(sanitizedRows[0]);
15
+
16
+ if (firstRow.isValid) {
17
+ return sanitizedRows;
18
+ }
19
+ return sanitizedRows.splice(1);
20
+ }
21
+
22
+ export default sanitizeRows;
@@ -1,17 +1,18 @@
1
1
  const _ = require('lodash');
2
+
2
3
  const rethrowError = (fnName, e) => {
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}`;
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}`;
11
11
  };
12
+
12
13
  const sqlEscapeWildcard = (str) => str.replace(/_|%|\\/g, (x) => `\\${x}`);
14
+
13
15
  module.exports = {
14
- rethrowError,
15
- sqlEscapeWildcard,
16
+ rethrowError,
17
+ sqlEscapeWildcard,
16
18
  };
17
- //# sourceMappingURL=formatting.js.map
@@ -0,0 +1,47 @@
1
+ const { sqlEscapeWildcard, rethrowError } = require('./formatting');
2
+
3
+ describe('formatting.sqlEscapeWildcard', () => {
4
+ describe('when passed an empty string', () => {
5
+ it('returns an empty string', () => expect(sqlEscapeWildcard('')).toEqual(''));
6
+ });
7
+ describe('when passed a string with no sql wildcards', () => {
8
+ it('returns the same string', () => {
9
+ const str = 'foo bar';
10
+ expect(sqlEscapeWildcard(str)).toEqual(str);
11
+ });
12
+ });
13
+ describe('when passed a string with sql wildcards', () => {
14
+ it('returns the string with \\ % _ escaped', () => {
15
+ const str = 'foo\\dfs_erwr%rewr';
16
+ expect(sqlEscapeWildcard(str)).toEqual('foo\\\\dfs\\_erwr\\%rewr');
17
+ });
18
+ });
19
+ });
20
+
21
+ describe('rethrowError', () => {
22
+ it('returns an error when given a string', () =>
23
+ expect(rethrowError('myFunc', { error: 'Oh dear, myFunc is broken' })).toEqual(
24
+ 'myFunc - undefined: undefined - Oh dear, myFunc is broken'
25
+ ));
26
+
27
+ it('returns an error when passed an error object', () =>
28
+ expect(
29
+ rethrowError('myFunc', {
30
+ name: "I'm a teapot",
31
+ statusCode: 418,
32
+ error: "I'm a little teapot, short and stout",
33
+ })
34
+ ).toEqual("myFunc - I'm a teapot: 418 - I'm a little teapot, short and stout"));
35
+
36
+ it('accepts an array containing an error', () => {
37
+ const thrownError = rethrowError('myFunc', {
38
+ error: ["I'm a teapot", 418, "I'm a little teapot, short and stout"],
39
+ });
40
+
41
+ const expected = JSON.stringify(
42
+ 'myFunc - undefined: undefined - \n[\n "I\'m a teapot",\n 418,\n "I\'m a little teapot, short and stout"\n]'
43
+ );
44
+
45
+ expect(JSON.stringify(thrownError)).toEqual(expected);
46
+ });
47
+ });
@@ -6,4 +6,5 @@ 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
+
9
10
  export { types, validations, errors, formatting, fileParser, structuredFileParser, middleware, ormHelpers };
@@ -1,22 +1,25 @@
1
1
  const T = require('../types/types');
2
+
2
3
  const ensureType = (type) => (req, res, next, id, name) => {
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
- }
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
+ }
12
12
  };
13
+
13
14
  const ensureUUID = ensureType('UUID');
15
+
14
16
  const ensureHex32 = ensureType('Hex32');
17
+
15
18
  const ensureInteger = ensureType('IntString');
19
+
16
20
  module.exports = {
17
- ensureType,
18
- ensureUUID,
19
- ensureHex32,
20
- ensureInteger,
21
+ ensureType,
22
+ ensureUUID,
23
+ ensureHex32,
24
+ ensureInteger,
21
25
  };
22
- //# sourceMappingURL=middleware.js.map
@@ -1,17 +1,19 @@
1
1
  const _ = require('lodash');
2
- const includeNested = (orm, models) => _.map(_.toPairs(models), (arg) => {
2
+
3
+ const includeNested = (orm, models) =>
4
+ _.map(_.toPairs(models), (arg) => {
3
5
  const [modelName, inclusion] = arg;
4
6
  const include = includeNested(orm, inclusion);
5
7
  const model = orm[modelName];
6
8
  if (_.isEmpty(include)) {
7
- return model;
9
+ return model;
8
10
  }
9
11
  return {
10
- model,
11
- include,
12
+ model,
13
+ include,
12
14
  };
13
- });
15
+ });
16
+
14
17
  module.exports = {
15
- includeNested,
18
+ includeNested,
16
19
  };
17
- //# sourceMappingURL=ormHelpers.js.map
@@ -0,0 +1,47 @@
1
+ const { includeNested } = require('./ormHelpers');
2
+
3
+ describe('ormIncludeNested', () => {
4
+ const orm = {
5
+ a: 'a',
6
+ b: 'b',
7
+ c: 'c',
8
+ d: 'd',
9
+ };
10
+
11
+ describe('when passed an empty object', () => {
12
+ it('returns an empty array', () => expect(includeNested(orm, {})).toEqual([]));
13
+ });
14
+
15
+ describe('when passed an object with no inclusions', () => {
16
+ it('returns an array of just the key', () =>
17
+ expect(
18
+ includeNested(orm, {
19
+ a: {},
20
+ })
21
+ ).toEqual(['a']));
22
+ });
23
+
24
+ describe('when passed a hierarchy of inclusions', () => {
25
+ it('should nest them in sequelize style', () =>
26
+ expect(
27
+ includeNested(orm, {
28
+ a: {
29
+ b: {
30
+ c: {},
31
+ d: {},
32
+ },
33
+ },
34
+ })
35
+ ).toEqual([
36
+ {
37
+ model: 'a',
38
+ include: [
39
+ {
40
+ model: 'b',
41
+ include: ['c', 'd'],
42
+ },
43
+ ],
44
+ },
45
+ ]));
46
+ });
47
+ });
@@ -0,0 +1,25 @@
1
+ /* eslint-disable max-classes-per-file */
2
+ export class InvalidFileError extends Error {
3
+ constructor() {
4
+ super('Invalid file type');
5
+ this.name = 'InvalidFileError';
6
+ }
7
+ }
8
+ export class TooManyRowsError extends Error {
9
+ constructor() {
10
+ super('More than configured number of rows imported');
11
+ this.name = 'TooManyRowsError';
12
+ }
13
+ }
14
+ export class NoRowsError extends Error {
15
+ constructor() {
16
+ super('No rows');
17
+ this.name = 'NoRowsError';
18
+ }
19
+ }
20
+ export class InvalidHeadersError extends Error {
21
+ constructor() {
22
+ super('Invalid or incomplete headers list');
23
+ this.name = 'InvalidHeadersError';
24
+ }
25
+ }