@e22m4u/js-repository 0.8.5 → 0.8.7

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 (45) hide show
  1. package/README.md +27 -23
  2. package/build-cjs.js +1 -1
  3. package/dist/cjs/index.cjs +947 -516
  4. package/eslint.config.js +1 -0
  5. package/package.json +16 -15
  6. package/src/adapter/adapter-loader.js +9 -4
  7. package/src/adapter/adapter-registry.js +3 -1
  8. package/src/adapter/builtin/memory-adapter.js +29 -13
  9. package/src/adapter/decorator/data-sanitizing-decorator.js +2 -1
  10. package/src/adapter/decorator/default-values-decorator.js +2 -1
  11. package/src/adapter/decorator/fields-filtering-decorator.js +14 -7
  12. package/src/adapter/decorator/inclusion-decorator.js +14 -7
  13. package/src/adapter/decorator/property-uniqueness-decorator.js +2 -1
  14. package/src/adapter/decorator/required-property-decorator.js +2 -1
  15. package/src/definition/datasource/datasource-definition-validator.js +6 -3
  16. package/src/definition/definition-registry.js +8 -4
  17. package/src/definition/model/model-data-sanitizer.js +4 -2
  18. package/src/definition/model/model-definition-utils.js +68 -26
  19. package/src/definition/model/model-definition-validator.js +10 -5
  20. package/src/definition/model/properties/primary-keys-definition-validator.js +4 -2
  21. package/src/definition/model/properties/properties-definition-validator.js +36 -18
  22. package/src/definition/model/properties/property-uniqueness-validator.js +26 -10
  23. package/src/definition/model/properties/property-uniqueness-validator.spec.js +500 -38
  24. package/src/definition/model/relations/relations-definition-validator.js +70 -33
  25. package/src/filter/fields-clause-tool.js +31 -12
  26. package/src/filter/include-clause-tool.js +38 -15
  27. package/src/filter/operator-clause-tool.js +55 -23
  28. package/src/filter/order-clause-tool.js +36 -13
  29. package/src/filter/slice-clause-tool.js +16 -7
  30. package/src/filter/where-clause-tool.js +24 -10
  31. package/src/relations/belongs-to-resolver.js +44 -20
  32. package/src/relations/has-many-resolver.js +52 -25
  33. package/src/relations/has-one-resolver.js +58 -27
  34. package/src/relations/references-many-resolver.js +24 -11
  35. package/src/repository/repository-registry.js +3 -1
  36. package/src/repository/repository.js +2 -1
  37. package/src/utils/capitalize.js +3 -1
  38. package/src/utils/clone-deep.js +6 -2
  39. package/src/utils/exclude-object-keys.js +2 -1
  40. package/src/utils/get-value-by-path.js +6 -2
  41. package/src/utils/is-deep-equal.js +21 -7
  42. package/src/utils/is-promise.js +6 -2
  43. package/src/utils/model-name-to-model-key.js +2 -1
  44. package/src/utils/select-object-keys.js +9 -4
  45. package/src/utils/singularize.js +3 -1
@@ -7,8 +7,12 @@
7
7
  * @returns {*}
8
8
  */
9
9
  export function getValueByPath(obj, path, orElse = undefined) {
10
- if (!obj || typeof obj !== 'object') return orElse;
11
- if (!path || typeof path !== 'string') return orElse;
10
+ if (!obj || typeof obj !== 'object') {
11
+ return orElse;
12
+ }
13
+ if (!path || typeof path !== 'string') {
14
+ return orElse;
15
+ }
12
16
  const keys = path.split('.');
13
17
  let value = obj;
14
18
  for (const key of keys) {
@@ -13,23 +13,33 @@ export function isDeepEqual(firstValue, secondValue) {
13
13
  // operator; since the typeof primitive null is object, check
14
14
  // if one of the inputs is equal to null. If one of the two
15
15
  // inputs is primitive, then I can compare them by reference.
16
- if (a === null || b === null) return a === b;
17
- if (typeof a !== 'object' || typeof b !== 'object') return a === b;
16
+ if (a === null || b === null) {
17
+ return a === b;
18
+ }
19
+ if (typeof a !== 'object' || typeof b !== 'object') {
20
+ return a === b;
21
+ }
18
22
  // Check if the data type of the two inputs are the same,
19
23
  // both are arrays or objects. If they are not, return false.
20
24
  const dataTypeA = Array.isArray(a) ? 'array' : 'object';
21
25
  const dataTypeB = Array.isArray(b) ? 'array' : 'object';
22
- if (dataTypeA !== dataTypeB) return false;
26
+ if (dataTypeA !== dataTypeB) {
27
+ return false;
28
+ }
23
29
  // Use Object.keys and Object.getOwnPropertySymbols to get
24
30
  // all of enumerable and not-inherited properties of the two
25
31
  // inputs. Compare their size respectively, if one of them
26
32
  // is not equal, return false.
27
33
  const keysA = Object.keys(a);
28
34
  const keysB = Object.keys(b);
29
- if (keysA.length !== keysB.length) return false;
35
+ if (keysA.length !== keysB.length) {
36
+ return false;
37
+ }
30
38
  const symbolsA = Object.getOwnPropertySymbols(a);
31
39
  const symbolsB = Object.getOwnPropertySymbols(b);
32
- if (symbolsA.length !== symbolsB.length) return false;
40
+ if (symbolsA.length !== symbolsB.length) {
41
+ return false;
42
+ }
33
43
  // To handle the circular reference, initialize a WeakMap
34
44
  // that is going to keep track of the objects or arrays
35
45
  // that have been seen, in which each key is an object
@@ -58,10 +68,14 @@ export function isDeepEqual(firstValue, secondValue) {
58
68
  // the property value.
59
69
  const propertyNamesA = [...keysA, ...symbolsA];
60
70
  for (const propertyNameA of propertyNamesA) {
61
- if (!Object.prototype.hasOwnProperty.call(b, propertyNameA)) return false;
71
+ if (!Object.prototype.hasOwnProperty.call(b, propertyNameA)) {
72
+ return false;
73
+ }
62
74
  const propertyValueA = a[propertyNameA];
63
75
  const propertyValueB = b[propertyNameA];
64
- if (!compare(propertyValueA, propertyValueB)) return false;
76
+ if (!compare(propertyValueA, propertyValueB)) {
77
+ return false;
78
+ }
65
79
  }
66
80
  // If we get out of the loop without
67
81
  // returning false, return true.
@@ -7,7 +7,11 @@
7
7
  * @returns {boolean}
8
8
  */
9
9
  export function isPromise(value) {
10
- if (!value) return false;
11
- if (typeof value !== 'object') return false;
10
+ if (!value) {
11
+ return false;
12
+ }
13
+ if (typeof value !== 'object') {
14
+ return false;
15
+ }
12
16
  return typeof value.then === 'function';
13
17
  }
@@ -7,11 +7,12 @@ import {InvalidArgumentError} from '../errors/index.js';
7
7
  * @returns {string}
8
8
  */
9
9
  export function modelNameToModelKey(modelName) {
10
- if (!modelName || typeof modelName !== 'string' || /\s/.test(modelName))
10
+ if (!modelName || typeof modelName !== 'string' || /\s/.test(modelName)) {
11
11
  throw new InvalidArgumentError(
12
12
  'The model name should be a non-empty String ' +
13
13
  'without spaces, but %v was given.',
14
14
  modelName,
15
15
  );
16
+ }
16
17
  return modelName.toLowerCase().replace(/[-_]/g, '');
17
18
  }
@@ -8,30 +8,35 @@ import {InvalidArgumentError} from '../errors/index.js';
8
8
  * @returns {object}
9
9
  */
10
10
  export function selectObjectKeys(obj, keys) {
11
- if (!obj || typeof obj !== 'object' || Array.isArray(obj))
11
+ if (!obj || typeof obj !== 'object' || Array.isArray(obj)) {
12
12
  throw new InvalidArgumentError(
13
13
  'The first argument of selectObjectKeys ' +
14
14
  'should be an Object, but %v was given.',
15
15
  obj,
16
16
  );
17
- if (!Array.isArray(keys))
17
+ }
18
+ if (!Array.isArray(keys)) {
18
19
  throw new InvalidArgumentError(
19
20
  'The second argument of selectObjectKeys ' +
20
21
  'should be an Array of String, but %v was given.',
21
22
  keys,
22
23
  );
24
+ }
23
25
  keys.forEach(key => {
24
- if (typeof key !== 'string')
26
+ if (typeof key !== 'string') {
25
27
  throw new InvalidArgumentError(
26
28
  'The second argument of selectObjectKeys ' +
27
29
  'should be an Array of String, but %v was given.',
28
30
  key,
29
31
  );
32
+ }
30
33
  });
31
34
  const result = {};
32
35
  const allKeys = Object.keys(obj);
33
36
  allKeys.forEach(key => {
34
- if (keys.includes(key)) result[key] = obj[key];
37
+ if (keys.includes(key)) {
38
+ result[key] = obj[key];
39
+ }
35
40
  });
36
41
  return result;
37
42
  }
@@ -5,7 +5,9 @@
5
5
  * @returns {string}
6
6
  */
7
7
  export function singularize(noun) {
8
- if (!noun || typeof noun !== 'string') return noun;
8
+ if (!noun || typeof noun !== 'string') {
9
+ return noun;
10
+ }
9
11
  const endings = {
10
12
  ves: 'fe',
11
13
  ies: 'y',