@e22m4u/js-repository 0.0.33 → 0.0.34

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.
@@ -13,14 +13,15 @@ export class OrderClauseTool extends Service {
13
13
  * @param {string|string[]|undefined} clause
14
14
  */
15
15
  sort(entities, clause) {
16
- if (!clause) return;
17
- if (!Array.isArray(clause)) clause = [clause];
16
+ if (clause == null) return;
17
+ if (Array.isArray(clause) === false) clause = [clause];
18
+ if (!clause.length) return;
18
19
  const mapping = [];
19
20
  clause.forEach((key, index) => {
20
- if (typeof key !== 'string')
21
+ if (!key || typeof key !== 'string')
21
22
  throw new InvalidArgumentError(
22
- 'The provided option "order" should be a String ' +
23
- 'or an Array of String, but %v given.',
23
+ 'The provided option "order" should be a non-empty String ' +
24
+ 'or an Array of non-empty String, but %v given.',
24
25
  key,
25
26
  );
26
27
  let reverse = 1;
@@ -40,14 +41,15 @@ export class OrderClauseTool extends Service {
40
41
  * @param {string|string[]|undefined} clause
41
42
  */
42
43
  static validateOrderClause(clause) {
43
- if (!clause) return;
44
- const tempClause = Array.isArray(clause) ? clause : [clause];
45
- tempClause.forEach(key => {
46
- if (!key || typeof key !== 'string')
44
+ if (clause == null) return;
45
+ if (Array.isArray(clause) === false) clause = [clause];
46
+ if (!clause.length) return;
47
+ clause.forEach(field => {
48
+ if (!field || typeof field !== 'string')
47
49
  throw new InvalidArgumentError(
48
50
  'The provided option "order" should be a non-empty String ' +
49
- 'or an Array of String, but %v given.',
50
- key,
51
+ 'or an Array of non-empty String, but %v given.',
52
+ field,
51
53
  );
52
54
  });
53
55
  }
@@ -59,14 +61,15 @@ export class OrderClauseTool extends Service {
59
61
  * @returns {string[]|undefined}
60
62
  */
61
63
  static normalizeOrderClause(clause) {
62
- if (!clause) return;
63
- clause = Array.isArray(clause) ? clause : [clause];
64
- clause.forEach(key => {
65
- if (!key || typeof key !== 'string')
64
+ if (clause == null) return;
65
+ if (Array.isArray(clause) === false) clause = [clause];
66
+ if (!clause.length) return;
67
+ clause.forEach(field => {
68
+ if (!field || typeof field !== 'string')
66
69
  throw new InvalidArgumentError(
67
70
  'The provided option "order" should be a non-empty String ' +
68
- 'or an Array of String, but %v given.',
69
- key,
71
+ 'or an Array of non-empty String, but %v given.',
72
+ field,
70
73
  );
71
74
  });
72
75
  return clause;