@e22m4u/js-repository 0.8.6 → 0.8.8

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/build-cjs.js +1 -1
  2. package/dist/cjs/index.cjs +560 -491
  3. package/package.json +8 -8
  4. package/src/adapter/adapter-loader.js +2 -5
  5. package/src/adapter/adapter-loader.spec.js +2 -2
  6. package/src/adapter/adapter-registry.spec.js +2 -2
  7. package/src/adapter/builtin/memory-adapter.js +5 -5
  8. package/src/adapter/builtin/memory-adapter.spec.js +12 -12
  9. package/src/adapter/decorator/data-sanitizing-decorator.js +1 -2
  10. package/src/adapter/decorator/default-values-decorator.js +1 -2
  11. package/src/adapter/decorator/fields-filtering-decorator.js +1 -2
  12. package/src/adapter/decorator/inclusion-decorator.js +1 -2
  13. package/src/adapter/decorator/property-uniqueness-decorator.js +1 -2
  14. package/src/adapter/decorator/required-property-decorator.js +1 -2
  15. package/src/database-schema.spec.js +3 -5
  16. package/src/definition/datasource/datasource-definition-validator.js +3 -3
  17. package/src/definition/datasource/datasource-definition-validator.spec.js +3 -6
  18. package/src/definition/definition-registry.js +4 -7
  19. package/src/definition/definition-registry.spec.js +4 -6
  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 +2 -2
  58. package/src/repository/repository.js +1 -1
  59. package/src/utils/exclude-object-keys.js +2 -2
  60. package/src/utils/exclude-object-keys.spec.js +2 -2
  61. package/src/utils/like-to-regexp.js +1 -2
  62. package/src/utils/like-to-regexp.spec.js +5 -5
  63. package/src/utils/model-name-to-model-key.js +1 -1
  64. package/src/utils/model-name-to-model-key.spec.js +7 -7
  65. package/src/utils/select-object-keys.js +6 -7
  66. package/src/utils/select-object-keys.spec.js +3 -6
@@ -151,7 +151,7 @@ export class IncludeClauseTool extends Service {
151
151
  break;
152
152
  default:
153
153
  throw new InvalidArgumentError(
154
- 'The relation type %v does not have an inclusion resolver.',
154
+ 'Relation type %v does not have an inclusion resolver.',
155
155
  relDef.type,
156
156
  );
157
157
  }
@@ -190,7 +190,7 @@ export class IncludeClauseTool extends Service {
190
190
  );
191
191
  if (duplicateNames.length) {
192
192
  throw new InvalidArgumentError(
193
- 'The provided option "include" has duplicates of %v.',
193
+ 'Option "include" has duplicates of %v.',
194
194
  duplicateNames[0],
195
195
  );
196
196
  }
@@ -200,7 +200,7 @@ export class IncludeClauseTool extends Service {
200
200
  // {relation: 'name', scope: {}}
201
201
  if (!clause.relation || typeof clause.relation !== 'string') {
202
202
  throw new InvalidArgumentError(
203
- 'The provided option "relation" should be ' +
203
+ 'Option "relation" must be ' +
204
204
  'a non-empty String, but %v was given.',
205
205
  clause.relation,
206
206
  );
@@ -221,7 +221,7 @@ export class IncludeClauseTool extends Service {
221
221
  } else {
222
222
  // unsupported
223
223
  throw new InvalidArgumentError(
224
- 'The provided option "include" should have a non-empty String, ' +
224
+ 'Option "include" must have a non-empty String, ' +
225
225
  'an Object or an Array, but %v was given.',
226
226
  clause,
227
227
  );
@@ -239,7 +239,7 @@ export class IncludeClauseTool extends Service {
239
239
  }
240
240
  if (typeof clause !== 'object' || Array.isArray(clause)) {
241
241
  throw new InvalidArgumentError(
242
- 'The provided option "scope" should be an Object, but %v was given.',
242
+ 'Option "scope" must be an Object, but %v was given.',
243
243
  clause,
244
244
  );
245
245
  }
@@ -296,7 +296,7 @@ export class IncludeClauseTool extends Service {
296
296
  );
297
297
  if (duplicateNames.length) {
298
298
  throw new InvalidArgumentError(
299
- 'The provided option "include" has duplicates of %v.',
299
+ 'Option "include" has duplicates of %v.',
300
300
  duplicateNames[0],
301
301
  );
302
302
  }
@@ -306,7 +306,7 @@ export class IncludeClauseTool extends Service {
306
306
  // {relation: 'name', scope: {...}}
307
307
  if (!clause.relation || typeof clause.relation !== 'string') {
308
308
  throw new InvalidArgumentError(
309
- 'The provided option "relation" should be ' +
309
+ 'Option "relation" must be ' +
310
310
  'a non-empty String, but %v was given.',
311
311
  clause.relation,
312
312
  );
@@ -335,7 +335,7 @@ export class IncludeClauseTool extends Service {
335
335
  } else {
336
336
  // unsupported
337
337
  throw new InvalidArgumentError(
338
- 'The provided option "include" should have a non-empty String, ' +
338
+ 'Option "include" must have a non-empty String, ' +
339
339
  'an Object or an Array, but %v was given.',
340
340
  clause,
341
341
  );
@@ -355,7 +355,7 @@ export class IncludeClauseTool extends Service {
355
355
  }
356
356
  if (typeof clause !== 'object' || Array.isArray(clause)) {
357
357
  throw new InvalidArgumentError(
358
- 'The provided option "scope" should be an Object, but %v was given.',
358
+ 'Option "scope" must be an Object, but %v was given.',
359
359
  clause,
360
360
  );
361
361
  }
@@ -40,7 +40,7 @@ describe('IncludeClauseTool', function () {
40
40
  const throwable = v => () => IncludeClauseTool.validateIncludeClause(v);
41
41
  const createError = v =>
42
42
  format(
43
- 'The provided option "include" should have a non-empty String, ' +
43
+ 'Option "include" must have a non-empty String, ' +
44
44
  'an Object or an Array, but %v was given.',
45
45
  v,
46
46
  );
@@ -80,7 +80,7 @@ describe('IncludeClauseTool', function () {
80
80
 
81
81
  it('throws an error for duplicates', function () {
82
82
  const validate = v => () => IncludeClauseTool.validateIncludeClause(v);
83
- const error = 'The provided option "include" has duplicates of "foo".';
83
+ const error = 'Option "include" has duplicates of "foo".';
84
84
  const clauses = [
85
85
  ['foo', 'foo'],
86
86
  [['foo'], 'foo'],
@@ -104,7 +104,7 @@ describe('IncludeClauseTool', function () {
104
104
  const throwable = v => () => IncludeClauseTool.normalizeIncludeClause(v);
105
105
  const createError = v =>
106
106
  format(
107
- 'The provided option "include" should have a non-empty String, ' +
107
+ 'Option "include" must have a non-empty String, ' +
108
108
  'an Object or an Array, but %v was given.',
109
109
  v,
110
110
  );
@@ -144,7 +144,7 @@ describe('IncludeClauseTool', function () {
144
144
 
145
145
  it('throws an error for duplicates', function () {
146
146
  const validate = v => () => IncludeClauseTool.normalizeIncludeClause(v);
147
- const error = 'The provided option "include" has duplicates of "foo".';
147
+ const error = 'Option "include" has duplicates of "foo".';
148
148
  const clauses = [
149
149
  ['foo', 'foo'],
150
150
  [['foo'], 'foo'],
@@ -68,8 +68,7 @@ export class OperatorClauseTool extends Service {
68
68
  testAll(clause, value) {
69
69
  if (!clause || typeof clause !== 'object' || Array.isArray(clause)) {
70
70
  throw new InvalidArgumentError(
71
- 'The first argument of OperatorUtils.testAll ' +
72
- 'should be an Object, but %v was given.',
71
+ 'Parameter "clause" must be an Object, but %v was given.',
73
72
  clause,
74
73
  );
75
74
  }
@@ -135,10 +134,9 @@ export class OperatorClauseTool extends Service {
135
134
  * @returns {boolean|undefined}
136
135
  */
137
136
  testEqNeq(clause, value) {
138
- if (!clause || typeof clause !== 'object') {
137
+ if (!clause || typeof clause !== 'object' || Array.isArray(clause)) {
139
138
  throw new InvalidArgumentError(
140
- 'The first argument of OperatorUtils.testEqNeq ' +
141
- 'should be an Object, but %v was given.',
139
+ 'Parameter "clause" must be an Object, but %v was given.',
142
140
  clause,
143
141
  );
144
142
  }
@@ -186,10 +184,9 @@ export class OperatorClauseTool extends Service {
186
184
  * @returns {boolean|undefined}
187
185
  */
188
186
  testGtLt(clause, value) {
189
- if (!clause || typeof clause !== 'object') {
187
+ if (!clause || typeof clause !== 'object' || Array.isArray(clause)) {
190
188
  throw new InvalidArgumentError(
191
- 'The first argument of OperatorUtils.testGtLt ' +
192
- 'should be an Object, but %v was given.',
189
+ 'Parameter "clause" must be an Object, but %v was given.',
193
190
  clause,
194
191
  );
195
192
  }
@@ -222,10 +219,9 @@ export class OperatorClauseTool extends Service {
222
219
  * @returns {boolean|undefined}
223
220
  */
224
221
  testInq(clause, value) {
225
- if (!clause || typeof clause !== 'object') {
222
+ if (!clause || typeof clause !== 'object' || Array.isArray(clause)) {
226
223
  throw new InvalidArgumentError(
227
- 'The first argument of OperatorUtils.testInq ' +
228
- 'should be an Object, but %v was given.',
224
+ 'Parameter "clause" must be an Object, but %v was given.',
229
225
  clause,
230
226
  );
231
227
  }
@@ -261,10 +257,9 @@ export class OperatorClauseTool extends Service {
261
257
  * @returns {boolean|undefined}
262
258
  */
263
259
  testNin(clause, value) {
264
- if (!clause || typeof clause !== 'object') {
260
+ if (!clause || typeof clause !== 'object' || Array.isArray(clause)) {
265
261
  throw new InvalidArgumentError(
266
- 'The first argument of OperatorUtils.testNin ' +
267
- 'should be an Object, but %v was given.',
262
+ 'Parameter "clause" must be an Object, but %v was given.',
268
263
  clause,
269
264
  );
270
265
  }
@@ -297,10 +292,9 @@ export class OperatorClauseTool extends Service {
297
292
  * @returns {boolean|undefined}
298
293
  */
299
294
  testBetween(clause, value) {
300
- if (!clause || typeof clause !== 'object') {
295
+ if (!clause || typeof clause !== 'object' || Array.isArray(clause)) {
301
296
  throw new InvalidArgumentError(
302
- 'The first argument of OperatorUtils.testBetween ' +
303
- 'should be an Object, but %v was given.',
297
+ 'Parameter "clause" must be an Object, but %v was given.',
304
298
  clause,
305
299
  );
306
300
  }
@@ -334,10 +328,9 @@ export class OperatorClauseTool extends Service {
334
328
  * @returns {boolean|undefined}
335
329
  */
336
330
  testExists(clause, value) {
337
- if (!clause || typeof clause !== 'object') {
331
+ if (!clause || typeof clause !== 'object' || Array.isArray(clause)) {
338
332
  throw new InvalidArgumentError(
339
- 'The first argument of OperatorUtils.testExists ' +
340
- 'should be an Object, but %v was given.',
333
+ 'Parameter "clause" must be an Object, but %v was given.',
341
334
  clause,
342
335
  );
343
336
  }
@@ -370,8 +363,7 @@ export class OperatorClauseTool extends Service {
370
363
  testLike(clause, value) {
371
364
  if (!clause || typeof clause !== 'object' || Array.isArray(clause)) {
372
365
  throw new InvalidArgumentError(
373
- 'The first argument of OperatorUtils.testLike ' +
374
- 'should be an Object, but %v was given.',
366
+ 'Parameter "clause" must be an Object, but %v was given.',
375
367
  clause,
376
368
  );
377
369
  }
@@ -400,8 +392,7 @@ export class OperatorClauseTool extends Service {
400
392
  testNlike(clause, value) {
401
393
  if (!clause || typeof clause !== 'object' || Array.isArray(clause)) {
402
394
  throw new InvalidArgumentError(
403
- 'The first argument of OperatorUtils.testNlike ' +
404
- 'should be an Object, but %v was given.',
395
+ 'Parameter "clause" must be an Object, but %v was given.',
405
396
  clause,
406
397
  );
407
398
  }
@@ -430,8 +421,7 @@ export class OperatorClauseTool extends Service {
430
421
  testIlike(clause, value) {
431
422
  if (!clause || typeof clause !== 'object' || Array.isArray(clause)) {
432
423
  throw new InvalidArgumentError(
433
- 'The first argument of OperatorUtils.testIlike ' +
434
- 'should be an Object, but %v was given.',
424
+ 'Parameter "clause" must be an Object, but %v was given.',
435
425
  clause,
436
426
  );
437
427
  }
@@ -460,8 +450,7 @@ export class OperatorClauseTool extends Service {
460
450
  testNilike(clause, value) {
461
451
  if (!clause || typeof clause !== 'object' || Array.isArray(clause)) {
462
452
  throw new InvalidArgumentError(
463
- 'The first argument of OperatorUtils.testNilike ' +
464
- 'should be an Object, but %v was given.',
453
+ 'Parameter "clause" must be an Object, but %v was given.',
465
454
  clause,
466
455
  );
467
456
  }
@@ -500,10 +489,9 @@ export class OperatorClauseTool extends Service {
500
489
  * @returns {boolean|undefined}
501
490
  */
502
491
  testRegexp(clause, value) {
503
- if (!clause || typeof clause !== 'object') {
492
+ if (!clause || typeof clause !== 'object' || Array.isArray(clause)) {
504
493
  throw new InvalidArgumentError(
505
- 'The first argument of OperatorUtils.testRegexp ' +
506
- 'should be an Object, but %v was given.',
494
+ 'Parameter "clause" must be an Object, but %v was given.',
507
495
  clause,
508
496
  );
509
497
  }
@@ -521,7 +509,7 @@ export class OperatorClauseTool extends Service {
521
509
  const flags = clause.flags || undefined;
522
510
  if (flags && typeof flags !== 'string') {
523
511
  throw new InvalidArgumentError(
524
- 'RegExp flags should be a String, but %v was given.',
512
+ 'RegExp flags must be a String, but %v was given.',
525
513
  clause.flags,
526
514
  );
527
515
  }
@@ -203,11 +203,10 @@ describe('OperatorClauseTool', function () {
203
203
  expect(S.testAll({foo: 'bar'}, 'value')).to.be.undefined;
204
204
  });
205
205
 
206
- it('should throws an error if a first argument is not an object', function () {
206
+ it('should throws an error if the parameter "clause" is not an object', function () {
207
207
  const throwable = () => S.testAll(10);
208
208
  expect(throwable).to.throw(
209
- 'The first argument of OperatorUtils.testAll ' +
210
- 'should be an Object, but 10 was given.',
209
+ 'Parameter "clause" must be an Object, but 10 was given.',
211
210
  );
212
211
  });
213
212
  });
@@ -218,11 +217,10 @@ describe('OperatorClauseTool', function () {
218
217
  expect(result).to.be.undefined;
219
218
  });
220
219
 
221
- it('throws an error if a first argument is not an object', function () {
220
+ it('throws an error if the parameter "clause" is not an object', function () {
222
221
  const throwable = () => S.testEqNeq(10);
223
222
  expect(throwable).to.throw(
224
- 'The first argument of OperatorUtils.testEqNeq ' +
225
- 'should be an Object, but 10 was given.',
223
+ 'Parameter "clause" must be an Object, but 10 was given.',
226
224
  );
227
225
  });
228
226
 
@@ -353,11 +351,10 @@ describe('OperatorClauseTool', function () {
353
351
  expect(result).to.be.undefined;
354
352
  });
355
353
 
356
- it('throws an error if a first argument is not an object', function () {
354
+ it('throws an error if the parameter "clause" is not an object', function () {
357
355
  const throwable = () => S.testGtLt(10);
358
356
  expect(throwable).to.throw(
359
- 'The first argument of OperatorUtils.testGtLt ' +
360
- 'should be an Object, but 10 was given.',
357
+ 'Parameter "clause" must be an Object, but 10 was given.',
361
358
  );
362
359
  });
363
360
 
@@ -550,11 +547,10 @@ describe('OperatorClauseTool', function () {
550
547
  expect(S.testInq(clause, [5, 6])).to.be.false;
551
548
  });
552
549
 
553
- it('throws an error if a first argument is not an object', function () {
550
+ it('throws an error if the parameter "clause" is not an object', function () {
554
551
  const throwable = () => S.testInq(10);
555
552
  expect(throwable).to.throw(
556
- 'The first argument of OperatorUtils.testInq ' +
557
- 'should be an Object, but 10 was given.',
553
+ 'Parameter "clause" must be an Object, but 10 was given.',
558
554
  );
559
555
  });
560
556
 
@@ -628,11 +624,10 @@ describe('OperatorClauseTool', function () {
628
624
  expect(S.testNin(clause, [5, 6])).to.be.true;
629
625
  });
630
626
 
631
- it('throws an error if a first argument is not an object', function () {
627
+ it('throws an error if the parameter "clause" is not an object', function () {
632
628
  const throwable = () => S.testNin(10);
633
629
  expect(throwable).to.throw(
634
- 'The first argument of OperatorUtils.testNin ' +
635
- 'should be an Object, but 10 was given.',
630
+ 'Parameter "clause" must be an Object, but 10 was given.',
636
631
  );
637
632
  });
638
633
 
@@ -697,11 +692,10 @@ describe('OperatorClauseTool', function () {
697
692
  expect(S.testBetween({between: [-2, 2]}, {})).to.be.false;
698
693
  });
699
694
 
700
- it('throws an error if a first argument is not an object', function () {
695
+ it('throws an error if the parameter "clause" is not an object', function () {
701
696
  const throwable = () => S.testBetween(10);
702
697
  expect(throwable).to.throw(
703
- 'The first argument of OperatorUtils.testBetween ' +
704
- 'should be an Object, but 10 was given.',
698
+ 'Parameter "clause" must be an Object, but 10 was given.',
705
699
  );
706
700
  });
707
701
 
@@ -754,11 +748,10 @@ describe('OperatorClauseTool', function () {
754
748
  expect(result).to.be.undefined;
755
749
  });
756
750
 
757
- it('throws an error if a first argument is not an object', function () {
751
+ it('throws an error if the parameter "clause" is not an object', function () {
758
752
  const throwable = () => S.testExists(10);
759
753
  expect(throwable).to.throw(
760
- 'The first argument of OperatorUtils.testExists ' +
761
- 'should be an Object, but 10 was given.',
754
+ 'Parameter "clause" must be an Object, but 10 was given.',
762
755
  );
763
756
  });
764
757
 
@@ -874,11 +867,7 @@ describe('OperatorClauseTool', function () {
874
867
  S.testLike(v);
875
868
  };
876
869
  const error = s =>
877
- format(
878
- 'The first argument of OperatorUtils.testLike ' +
879
- 'should be an Object, but %s was given.',
880
- s,
881
- );
870
+ format('Parameter "clause" must be an Object, but %s was given.', s);
882
871
  expect(throwable('str')).to.throw(error('"str"'));
883
872
  expect(throwable('')).to.throw(error('""'));
884
873
  expect(throwable(10)).to.throw(error('10'));
@@ -897,7 +886,7 @@ describe('OperatorClauseTool', function () {
897
886
  };
898
887
  const error = s =>
899
888
  format(
900
- 'Condition of {like: ...} should have a String, but %s was given.',
889
+ 'Condition of {like: ...} must have a String, but %s was given.',
901
890
  s,
902
891
  );
903
892
  expect(throwable(10)).to.throw(error('10'));
@@ -969,11 +958,7 @@ describe('OperatorClauseTool', function () {
969
958
  S.testNlike(v);
970
959
  };
971
960
  const error = s =>
972
- format(
973
- 'The first argument of OperatorUtils.testNlike ' +
974
- 'should be an Object, but %s was given.',
975
- s,
976
- );
961
+ format('Parameter "clause" must be an Object, but %s was given.', s);
977
962
  expect(throwable('str')).to.throw(error('"str"'));
978
963
  expect(throwable('')).to.throw(error('""'));
979
964
  expect(throwable(10)).to.throw(error('10'));
@@ -992,7 +977,7 @@ describe('OperatorClauseTool', function () {
992
977
  };
993
978
  const error = s =>
994
979
  format(
995
- 'Condition of {nlike: ...} should have a String, but %s was given.',
980
+ 'Condition of {nlike: ...} must have a String, but %s was given.',
996
981
  s,
997
982
  );
998
983
  expect(throwable(10)).to.throw(error('10'));
@@ -1062,11 +1047,7 @@ describe('OperatorClauseTool', function () {
1062
1047
  S.testIlike(v);
1063
1048
  };
1064
1049
  const error = s =>
1065
- format(
1066
- 'The first argument of OperatorUtils.testIlike ' +
1067
- 'should be an Object, but %s was given.',
1068
- s,
1069
- );
1050
+ format('Parameter "clause" must be an Object, but %s was given.', s);
1070
1051
  expect(throwable('str')).to.throw(error('"str"'));
1071
1052
  expect(throwable('')).to.throw(error('""'));
1072
1053
  expect(throwable(10)).to.throw(error('10'));
@@ -1085,7 +1066,7 @@ describe('OperatorClauseTool', function () {
1085
1066
  };
1086
1067
  const error = s =>
1087
1068
  format(
1088
- 'Condition of {ilike: ...} should have a String, but %s was given.',
1069
+ 'Condition of {ilike: ...} must have a String, but %s was given.',
1089
1070
  s,
1090
1071
  );
1091
1072
  expect(throwable(10)).to.throw(error('10'));
@@ -1158,11 +1139,7 @@ describe('OperatorClauseTool', function () {
1158
1139
  S.testNilike(v);
1159
1140
  };
1160
1141
  const error = s =>
1161
- format(
1162
- 'The first argument of OperatorUtils.testNilike ' +
1163
- 'should be an Object, but %s was given.',
1164
- s,
1165
- );
1142
+ format('Parameter "clause" must be an Object, but %s was given.', s);
1166
1143
  expect(throwable('str')).to.throw(error('"str"'));
1167
1144
  expect(throwable('')).to.throw(error('""'));
1168
1145
  expect(throwable(10)).to.throw(error('10'));
@@ -1181,7 +1158,7 @@ describe('OperatorClauseTool', function () {
1181
1158
  };
1182
1159
  const error = s =>
1183
1160
  format(
1184
- 'Condition of {nilike: ...} should have a String, but %s was given.',
1161
+ 'Condition of {nilike: ...} must have a String, but %s was given.',
1185
1162
  s,
1186
1163
  );
1187
1164
  expect(throwable(10)).to.throw(error('10'));
@@ -1264,11 +1241,10 @@ describe('OperatorClauseTool', function () {
1264
1241
  expect(S.testRegexp({regexp: 'Val.+', flags: 'i'}, 'value')).to.be.true;
1265
1242
  });
1266
1243
 
1267
- it('throws an error if a first argument is not an object', function () {
1244
+ it('throws an error if the parameter "clause" is not an object', function () {
1268
1245
  const throwable = () => S.testRegexp(10);
1269
1246
  expect(throwable).to.throw(
1270
- 'The first argument of OperatorUtils.testRegexp ' +
1271
- 'should be an Object, but 10 was given.',
1247
+ 'Parameter "clause" must be an Object, but 10 was given.',
1272
1248
  );
1273
1249
  });
1274
1250
 
@@ -1294,7 +1270,7 @@ describe('OperatorClauseTool', function () {
1294
1270
  const throwable = v => () =>
1295
1271
  S.testRegexp({regexp: 'Val.+', flags: v}, 'val');
1296
1272
  const error = v =>
1297
- format('RegExp flags should be a String, but %s was given.', v);
1273
+ format('RegExp flags must be a String, but %s was given.', v);
1298
1274
  expect(throwable(10)).to.throw(error('10'));
1299
1275
  expect(throwable(true)).to.throw(error('true'));
1300
1276
  expect(throwable([])).to.throw(error('Array'));
@@ -13,33 +13,47 @@ export class OrderClauseTool extends Service {
13
13
  * @param {string|string[]|undefined} clause
14
14
  */
15
15
  sort(entities, clause) {
16
+ if (!Array.isArray(entities)) {
17
+ throw new InvalidArgumentError(
18
+ 'Parameter "entities" must be an Array, but %v was given.',
19
+ entities,
20
+ );
21
+ }
16
22
  if (clause == null) {
17
23
  return;
18
24
  }
19
- if (Array.isArray(clause) === false) {
20
- clause = [clause];
25
+ const isArrayClause = Array.isArray(clause);
26
+ if (!clause || (typeof clause !== 'string' && !isArrayClause)) {
27
+ throw new InvalidArgumentError(
28
+ 'Option "order" must be a non-empty String or an Array ' +
29
+ 'of non-empty String, but %v was given.',
30
+ clause,
31
+ );
21
32
  }
22
- if (!clause.length) {
33
+ if (!isArrayClause) {
34
+ clause = [clause];
35
+ } else if (!clause.length) {
23
36
  return;
24
37
  }
25
38
  const mapping = [];
26
- clause.forEach((key, index) => {
27
- if (!key || typeof key !== 'string') {
39
+ clause.forEach((element, index) => {
40
+ if (!element || typeof element !== 'string') {
28
41
  throw new InvalidArgumentError(
29
- 'The provided option "order" should be a non-empty String ' +
30
- 'or an Array of non-empty String, but %v was given.',
31
- key,
42
+ 'Element %d of the option "order" must be a non-empty String, ' +
43
+ 'but %v was given.',
44
+ index,
45
+ element,
32
46
  );
33
47
  }
34
48
  let reverse = 1;
35
- const matches = key.match(/\s+(A|DE)SC$/i);
49
+ const matches = element.match(/\s+(A|DE)SC$/i);
36
50
  if (matches) {
37
- key = key.replace(/\s+(A|DE)SC/i, '');
51
+ element = element.replace(/\s+(A|DE)SC/i, '');
38
52
  if (matches[1].toLowerCase() === 'de') {
39
53
  reverse = -1;
40
54
  }
41
55
  }
42
- mapping[index] = {key: key, reverse};
56
+ mapping[index] = {key: element, reverse};
43
57
  });
44
58
  entities.sort(compareFn.bind(mapping));
45
59
  }
@@ -53,18 +67,24 @@ export class OrderClauseTool extends Service {
53
67
  if (clause == null) {
54
68
  return;
55
69
  }
56
- if (Array.isArray(clause) === false) {
57
- clause = [clause];
70
+ const isArrayClause = Array.isArray(clause);
71
+ if (!clause || (typeof clause !== 'string' && !isArrayClause)) {
72
+ throw new InvalidArgumentError(
73
+ 'Option "order" must be a non-empty String or an Array ' +
74
+ 'of non-empty String, but %v was given.',
75
+ clause,
76
+ );
58
77
  }
59
- if (!clause.length) {
78
+ if (!isArrayClause || !clause.length) {
60
79
  return;
61
80
  }
62
- clause.forEach(field => {
63
- if (!field || typeof field !== 'string') {
81
+ clause.forEach((element, index) => {
82
+ if (!element || typeof element !== 'string') {
64
83
  throw new InvalidArgumentError(
65
- 'The provided option "order" should be a non-empty String ' +
66
- 'or an Array of non-empty String, but %v was given.',
67
- field,
84
+ 'Element %d of the option "order" must be a non-empty String, ' +
85
+ 'but %v was given.',
86
+ index,
87
+ element,
68
88
  );
69
89
  }
70
90
  });
@@ -80,18 +100,26 @@ export class OrderClauseTool extends Service {
80
100
  if (clause == null) {
81
101
  return;
82
102
  }
83
- if (Array.isArray(clause) === false) {
84
- clause = [clause];
103
+ const isArrayClause = Array.isArray(clause);
104
+ if (!clause || (typeof clause !== 'string' && !isArrayClause)) {
105
+ throw new InvalidArgumentError(
106
+ 'Option "order" must be a non-empty String or an Array ' +
107
+ 'of non-empty String, but %v was given.',
108
+ clause,
109
+ );
85
110
  }
86
- if (!clause.length) {
111
+ if (!isArrayClause) {
112
+ return [clause];
113
+ } else if (!clause.length) {
87
114
  return;
88
115
  }
89
- clause.forEach(field => {
90
- if (!field || typeof field !== 'string') {
116
+ clause.forEach((element, index) => {
117
+ if (!element || typeof element !== 'string') {
91
118
  throw new InvalidArgumentError(
92
- 'The provided option "order" should be a non-empty String ' +
93
- 'or an Array of non-empty String, but %v was given.',
94
- field,
119
+ 'Element %d of the option "order" must be a non-empty String, ' +
120
+ 'but %v was given.',
121
+ index,
122
+ element,
95
123
  );
96
124
  }
97
125
  });