@e22m4u/js-repository 0.8.7 → 0.8.9

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 (70) hide show
  1. package/dist/cjs/index.cjs +452 -406
  2. package/package.json +7 -7
  3. package/src/adapter/adapter-loader.js +2 -5
  4. package/src/adapter/adapter-loader.spec.js +2 -2
  5. package/src/adapter/adapter-registry.spec.js +2 -2
  6. package/src/adapter/builtin/memory-adapter.js +5 -5
  7. package/src/adapter/builtin/memory-adapter.spec.js +12 -12
  8. package/src/adapter/decorator/data-sanitizing-decorator.js +1 -2
  9. package/src/adapter/decorator/default-values-decorator.js +1 -2
  10. package/src/adapter/decorator/fields-filtering-decorator.js +1 -2
  11. package/src/adapter/decorator/inclusion-decorator.js +1 -2
  12. package/src/adapter/decorator/property-uniqueness-decorator.js +1 -2
  13. package/src/adapter/decorator/required-property-decorator.js +1 -2
  14. package/src/database-schema.spec.js +3 -5
  15. package/src/definition/datasource/datasource-definition-validator.js +3 -3
  16. package/src/definition/datasource/datasource-definition-validator.spec.js +3 -6
  17. package/src/definition/definition-registry.d.ts +10 -0
  18. package/src/definition/definition-registry.js +28 -19
  19. package/src/definition/definition-registry.spec.js +64 -117
  20. package/src/definition/model/model-data-sanitizer.js +2 -4
  21. package/src/definition/model/model-definition-utils.js +12 -14
  22. package/src/definition/model/model-definition-utils.spec.js +12 -21
  23. package/src/definition/model/model-definition-validator.js +12 -12
  24. package/src/definition/model/model-definition-validator.spec.js +12 -15
  25. package/src/definition/model/properties/primary-keys-definition-validator.js +4 -4
  26. package/src/definition/model/properties/primary-keys-definition-validator.spec.js +8 -8
  27. package/src/definition/model/properties/properties-definition-validator.js +42 -43
  28. package/src/definition/model/properties/properties-definition-validator.spec.js +45 -45
  29. package/src/definition/model/properties/property-uniqueness-validator.js +7 -11
  30. package/src/definition/model/properties/property-uniqueness-validator.spec.js +57 -60
  31. package/src/definition/model/properties/required-property-validator.js +1 -1
  32. package/src/definition/model/properties/required-property-validator.spec.js +1 -1
  33. package/src/definition/model/relations/relations-definition-validator.js +40 -42
  34. package/src/definition/model/relations/relations-definition-validator.spec.js +44 -45
  35. package/src/errors/invalid-operator-value-error.js +1 -1
  36. package/src/errors/invalid-operator-value-error.spec.js +1 -1
  37. package/src/filter/fields-clause-tool.js +95 -53
  38. package/src/filter/fields-clause-tool.spec.js +210 -387
  39. package/src/filter/include-clause-tool.js +9 -9
  40. package/src/filter/include-clause-tool.spec.js +4 -4
  41. package/src/filter/operator-clause-tool.js +20 -32
  42. package/src/filter/operator-clause-tool.spec.js +25 -49
  43. package/src/filter/order-clause-tool.js +55 -27
  44. package/src/filter/order-clause-tool.spec.js +151 -90
  45. package/src/filter/slice-clause-tool.js +5 -6
  46. package/src/filter/slice-clause-tool.spec.js +8 -24
  47. package/src/filter/where-clause-tool.js +18 -11
  48. package/src/filter/where-clause-tool.spec.js +27 -17
  49. package/src/relations/belongs-to-resolver.js +18 -30
  50. package/src/relations/belongs-to-resolver.spec.js +21 -44
  51. package/src/relations/has-many-resolver.js +28 -44
  52. package/src/relations/has-many-resolver.spec.js +44 -68
  53. package/src/relations/has-one-resolver.js +28 -44
  54. package/src/relations/has-one-resolver.spec.js +44 -68
  55. package/src/relations/references-many-resolver.js +8 -14
  56. package/src/relations/references-many-resolver.spec.js +12 -24
  57. package/src/repository/repository-registry.js +4 -6
  58. package/src/repository/repository-registry.spec.js +0 -19
  59. package/src/repository/repository.js +1 -1
  60. package/src/utils/exclude-object-keys.js +2 -2
  61. package/src/utils/exclude-object-keys.spec.js +2 -2
  62. package/src/utils/index.d.ts +0 -1
  63. package/src/utils/index.js +0 -1
  64. package/src/utils/like-to-regexp.js +1 -2
  65. package/src/utils/like-to-regexp.spec.js +5 -5
  66. package/src/utils/select-object-keys.js +6 -7
  67. package/src/utils/select-object-keys.spec.js +3 -6
  68. package/src/utils/model-name-to-model-key.d.ts +0 -6
  69. package/src/utils/model-name-to-model-key.js +0 -18
  70. package/src/utils/model-name-to-model-key.spec.js +0 -94
@@ -10,23 +10,22 @@ import {InvalidArgumentError} from '../errors/index.js';
10
10
  export function selectObjectKeys(obj, keys) {
11
11
  if (!obj || typeof obj !== 'object' || Array.isArray(obj)) {
12
12
  throw new InvalidArgumentError(
13
- 'The first argument of selectObjectKeys ' +
14
- 'should be an Object, but %v was given.',
13
+ 'Parameter "obj" must be an Object, but %v was given.',
15
14
  obj,
16
15
  );
17
16
  }
18
17
  if (!Array.isArray(keys)) {
19
18
  throw new InvalidArgumentError(
20
- 'The second argument of selectObjectKeys ' +
21
- 'should be an Array of String, but %v was given.',
19
+ 'Parameter "keys" must be an Array, but %v was given.',
22
20
  keys,
23
21
  );
24
22
  }
25
- keys.forEach(key => {
23
+ keys.forEach((key, index) => {
26
24
  if (typeof key !== 'string') {
27
25
  throw new InvalidArgumentError(
28
- 'The second argument of selectObjectKeys ' +
29
- 'should be an Array of String, but %v was given.',
26
+ 'Element %d of the parameter "keys" must be a String, ' +
27
+ 'but %v was given.',
28
+ index,
30
29
  key,
31
30
  );
32
31
  }
@@ -17,24 +17,21 @@ describe('selectObjectKeys', function () {
17
17
  it('throws an error if a given value is not an Object', function () {
18
18
  const throwable = () => selectObjectKeys(10, ['key']);
19
19
  expect(throwable).to.throw(
20
- 'The first argument of selectObjectKeys ' +
21
- 'should be an Object, but 10 was given.',
20
+ 'Parameter "obj" must be an Object, but 10 was given.',
22
21
  );
23
22
  });
24
23
 
25
24
  it('throws an error if a given keys is not an Array', function () {
26
25
  const throwable = () => selectObjectKeys({});
27
26
  expect(throwable).to.throw(
28
- 'The second argument of selectObjectKeys ' +
29
- 'should be an Array of String, but undefined was given.',
27
+ 'Parameter "keys" must be an Array, but undefined was given.',
30
28
  );
31
29
  });
32
30
 
33
31
  it('throws an error if a given keys is not an String', function () {
34
32
  const throwable = () => selectObjectKeys({}, [10]);
35
33
  expect(throwable).to.throw(
36
- 'The second argument of selectObjectKeys ' +
37
- 'should be an Array of String, but 10 was given.',
34
+ 'Element 0 of the parameter "keys" must be a String, but 10 was given.',
38
35
  );
39
36
  });
40
37
  });
@@ -1,6 +0,0 @@
1
- /**
2
- * Model name to model key.
3
- *
4
- * @param modelName
5
- */
6
- export function modelNameToModelKey(modelName: string): string;
@@ -1,18 +0,0 @@
1
- import {InvalidArgumentError} from '../errors/index.js';
2
-
3
- /**
4
- * Model name to model key.
5
- *
6
- * @param {string} modelName
7
- * @returns {string}
8
- */
9
- export function modelNameToModelKey(modelName) {
10
- if (!modelName || typeof modelName !== 'string' || /\s/.test(modelName)) {
11
- throw new InvalidArgumentError(
12
- 'The model name should be a non-empty String ' +
13
- 'without spaces, but %v was given.',
14
- modelName,
15
- );
16
- }
17
- return modelName.toLowerCase().replace(/[-_]/g, '');
18
- }
@@ -1,94 +0,0 @@
1
- import {expect} from 'chai';
2
- import {modelNameToModelKey} from './model-name-to-model-key.js';
3
-
4
- describe('modelNameToModelKey', function () {
5
- it('should return a simple lowercase string as is', function () {
6
- expect(modelNameToModelKey('user')).to.be.eq('user');
7
- });
8
-
9
- it('should convert to lowercase and remove hyphens and underscores', function () {
10
- const modelNames = [
11
- 'userProfileDetails',
12
- 'UserProfileDetails',
13
- 'user-profile-details',
14
- 'user_profile_details',
15
- 'User-Profile-Details',
16
- 'User_Profile_Details',
17
- 'USER-PROFILE-DETAILS',
18
- 'USER_PROFILE_DETAILS',
19
- 'USERPROFILEDETAILS',
20
- 'userprofiledetails',
21
- ];
22
- modelNames.forEach(v =>
23
- expect(modelNameToModelKey(v)).to.be.eq('userprofiledetails'),
24
- );
25
- });
26
-
27
- it('should handle a mixed string with uppercase, hyphens and underscores', function () {
28
- const modelName = 'User_Profile-Details';
29
- const expected = 'userprofiledetails';
30
- expect(modelNameToModelKey(modelName)).to.be.eq(expected);
31
- });
32
-
33
- it('should not remove numbers from the string', function () {
34
- const modelName = 'Type1-Model_2';
35
- const expected = 'type1model2';
36
- expect(modelNameToModelKey(modelName)).to.be.eq(expected);
37
- });
38
-
39
- it('should throw an error for an empty string', function () {
40
- const throwable = () => modelNameToModelKey('');
41
- expect(throwable).to.throw(
42
- 'The model name should be a non-empty String ' +
43
- 'without spaces, but "" was given.',
44
- );
45
- });
46
-
47
- it('should throw an error for a string with spaces', function () {
48
- const throwable = () => modelNameToModelKey('user profile');
49
- expect(throwable).to.throw(
50
- 'The model name should be a non-empty String ' +
51
- 'without spaces, but "user profile" was given.',
52
- );
53
- });
54
-
55
- it('should throw an error for null', function () {
56
- const throwable = () => modelNameToModelKey(null);
57
- expect(throwable).to.throw(
58
- 'The model name should be a non-empty String ' +
59
- 'without spaces, but null was given.',
60
- );
61
- });
62
-
63
- it('should throw an error for undefined', function () {
64
- const throwable = () => modelNameToModelKey(undefined);
65
- expect(throwable).to.throw(
66
- 'The model name should be a non-empty String ' +
67
- 'without spaces, but undefined was given.',
68
- );
69
- });
70
-
71
- it('should throw an error for a number', function () {
72
- const throwable = () => modelNameToModelKey(123);
73
- expect(throwable).to.throw(
74
- 'The model name should be a non-empty String ' +
75
- 'without spaces, but 123 was given.',
76
- );
77
- });
78
-
79
- it('should throw an error for an object', function () {
80
- const throwable = () => modelNameToModelKey({name: 'test'});
81
- expect(throwable).to.throw(
82
- 'The model name should be a non-empty String ' +
83
- 'without spaces, but Object was given.',
84
- );
85
- });
86
-
87
- it('should throw an error for an array', function () {
88
- const throwable = () => modelNameToModelKey(['test']);
89
- expect(throwable).to.throw(
90
- 'The model name should be a non-empty String ' +
91
- 'without spaces, but Array was given.',
92
- );
93
- });
94
- });