@e22m4u/js-repository 0.0.34 → 0.0.35
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.
- package/package.json +1 -1
- package/src/adapter/decorator/data-sanitizing-decorator.js +1 -1
- package/src/adapter/decorator/data-validation-decorator.js +1 -1
- package/src/adapter/decorator/default-values-decorator.js +1 -1
- package/src/adapter/decorator/fields-filtering-decorator.js +1 -1
- package/src/adapter/decorator/inclusion-decorator.js +1 -1
- package/src/definition/model/properties/default-values-definition-validator.js +1 -1
- package/src/definition/model/properties/default-values-definition-validator.spec.js +1 -1
- package/src/definition/model/properties/properties-definition-validator.js +2 -2
- package/src/definition/model/properties/properties-definition-validator.spec.js +1 -1
- package/src/definition/model/relations/relations-definition-validator.js +2 -2
- package/src/definition/model/relations/relations-definition-validator.spec.js +1 -1
- package/src/filter/include-clause-tool.js +50 -42
- package/src/filter/include-clause-tool.spec.js +4391 -291
- package/src/filter/operator-clause-tool.js +12 -12
- package/src/filter/operator-clause-tool.spec.js +12 -12
- package/src/filter/slice-clause-tool.js +5 -5
- package/src/filter/slice-clause-tool.spec.js +92 -51
- package/src/filter/where-clause-tool.js +7 -7
- package/src/filter/where-clause-tool.spec.js +79 -55
- package/src/utils/select-object-keys.js +3 -3
- package/src/utils/select-object-keys.spec.js +3 -3
|
@@ -58,7 +58,7 @@ export class OperatorClauseTool extends Service {
|
|
|
58
58
|
testAll(clause, value) {
|
|
59
59
|
if (!clause || typeof clause !== 'object' || Array.isArray(clause))
|
|
60
60
|
throw new InvalidArgumentError(
|
|
61
|
-
'
|
|
61
|
+
'The first argument of OperatorUtils.testAll ' +
|
|
62
62
|
'should be an Object, but %v given.',
|
|
63
63
|
clause,
|
|
64
64
|
);
|
|
@@ -136,7 +136,7 @@ export class OperatorClauseTool extends Service {
|
|
|
136
136
|
testEqNeq(clause, value) {
|
|
137
137
|
if (!clause || typeof clause !== 'object')
|
|
138
138
|
throw new InvalidArgumentError(
|
|
139
|
-
'
|
|
139
|
+
'The first argument of OperatorUtils.testEqNeq ' +
|
|
140
140
|
'should be an Object, but %v given.',
|
|
141
141
|
clause,
|
|
142
142
|
);
|
|
@@ -182,7 +182,7 @@ export class OperatorClauseTool extends Service {
|
|
|
182
182
|
testGtLt(clause, value) {
|
|
183
183
|
if (!clause || typeof clause !== 'object')
|
|
184
184
|
throw new InvalidArgumentError(
|
|
185
|
-
'
|
|
185
|
+
'The first argument of OperatorUtils.testGtLt ' +
|
|
186
186
|
'should be an Object, but %v given.',
|
|
187
187
|
clause,
|
|
188
188
|
);
|
|
@@ -209,7 +209,7 @@ export class OperatorClauseTool extends Service {
|
|
|
209
209
|
testInq(clause, value) {
|
|
210
210
|
if (!clause || typeof clause !== 'object')
|
|
211
211
|
throw new InvalidArgumentError(
|
|
212
|
-
'
|
|
212
|
+
'The first argument of OperatorUtils.testInq ' +
|
|
213
213
|
'should be an Object, but %v given.',
|
|
214
214
|
clause,
|
|
215
215
|
);
|
|
@@ -245,7 +245,7 @@ export class OperatorClauseTool extends Service {
|
|
|
245
245
|
testNin(clause, value) {
|
|
246
246
|
if (!clause || typeof clause !== 'object')
|
|
247
247
|
throw new InvalidArgumentError(
|
|
248
|
-
'
|
|
248
|
+
'The first argument of OperatorUtils.testNin ' +
|
|
249
249
|
'should be an Object, but %v given.',
|
|
250
250
|
clause,
|
|
251
251
|
);
|
|
@@ -281,7 +281,7 @@ export class OperatorClauseTool extends Service {
|
|
|
281
281
|
testBetween(clause, value) {
|
|
282
282
|
if (!clause || typeof clause !== 'object')
|
|
283
283
|
throw new InvalidArgumentError(
|
|
284
|
-
'
|
|
284
|
+
'The first argument of OperatorUtils.testBetween ' +
|
|
285
285
|
'should be an Object, but %v given.',
|
|
286
286
|
clause,
|
|
287
287
|
);
|
|
@@ -317,7 +317,7 @@ export class OperatorClauseTool extends Service {
|
|
|
317
317
|
testExists(clause, value) {
|
|
318
318
|
if (!clause || typeof clause !== 'object')
|
|
319
319
|
throw new InvalidArgumentError(
|
|
320
|
-
'
|
|
320
|
+
'The first argument of OperatorUtils.testExists ' +
|
|
321
321
|
'should be an Object, but %v given.',
|
|
322
322
|
clause,
|
|
323
323
|
);
|
|
@@ -350,7 +350,7 @@ export class OperatorClauseTool extends Service {
|
|
|
350
350
|
testLike(clause, value) {
|
|
351
351
|
if (!clause || typeof clause !== 'object')
|
|
352
352
|
throw new InvalidArgumentError(
|
|
353
|
-
'
|
|
353
|
+
'The first argument of OperatorUtils.testLike ' +
|
|
354
354
|
'should be an Object, but %v given.',
|
|
355
355
|
clause,
|
|
356
356
|
);
|
|
@@ -378,7 +378,7 @@ export class OperatorClauseTool extends Service {
|
|
|
378
378
|
testNlike(clause, value) {
|
|
379
379
|
if (!clause || typeof clause !== 'object')
|
|
380
380
|
throw new InvalidArgumentError(
|
|
381
|
-
'
|
|
381
|
+
'The first argument of OperatorUtils.testNlike ' +
|
|
382
382
|
'should be an Object, but %v given.',
|
|
383
383
|
clause,
|
|
384
384
|
);
|
|
@@ -410,7 +410,7 @@ export class OperatorClauseTool extends Service {
|
|
|
410
410
|
testIlike(clause, value) {
|
|
411
411
|
if (!clause || typeof clause !== 'object')
|
|
412
412
|
throw new InvalidArgumentError(
|
|
413
|
-
'
|
|
413
|
+
'The first argument of OperatorUtils.testIlike ' +
|
|
414
414
|
'should be an Object, but %v given.',
|
|
415
415
|
clause,
|
|
416
416
|
);
|
|
@@ -442,7 +442,7 @@ export class OperatorClauseTool extends Service {
|
|
|
442
442
|
testNilike(clause, value) {
|
|
443
443
|
if (!clause || typeof clause !== 'object')
|
|
444
444
|
throw new InvalidArgumentError(
|
|
445
|
-
'
|
|
445
|
+
'The first argument of OperatorUtils.testNilike ' +
|
|
446
446
|
'should be an Object, but %v given.',
|
|
447
447
|
clause,
|
|
448
448
|
);
|
|
@@ -486,7 +486,7 @@ export class OperatorClauseTool extends Service {
|
|
|
486
486
|
testRegexp(clause, value) {
|
|
487
487
|
if (!clause || typeof clause !== 'object')
|
|
488
488
|
throw new InvalidArgumentError(
|
|
489
|
-
'
|
|
489
|
+
'The first argument of OperatorUtils.testRegexp ' +
|
|
490
490
|
'should be an Object, but %v given.',
|
|
491
491
|
clause,
|
|
492
492
|
);
|
|
@@ -115,7 +115,7 @@ describe('OperatorClauseTool', function () {
|
|
|
115
115
|
it('throws an error if a first argument is not an object', function () {
|
|
116
116
|
const throwable = () => S.testAll(10);
|
|
117
117
|
expect(throwable).to.throw(
|
|
118
|
-
'
|
|
118
|
+
'The first argument of OperatorUtils.testAll ' +
|
|
119
119
|
'should be an Object, but 10 given.',
|
|
120
120
|
);
|
|
121
121
|
});
|
|
@@ -130,7 +130,7 @@ describe('OperatorClauseTool', function () {
|
|
|
130
130
|
it('throws an error if a first argument is not an object', function () {
|
|
131
131
|
const throwable = () => S.testEqNeq(10);
|
|
132
132
|
expect(throwable).to.throw(
|
|
133
|
-
'
|
|
133
|
+
'The first argument of OperatorUtils.testEqNeq ' +
|
|
134
134
|
'should be an Object, but 10 given.',
|
|
135
135
|
);
|
|
136
136
|
});
|
|
@@ -215,7 +215,7 @@ describe('OperatorClauseTool', function () {
|
|
|
215
215
|
it('throws an error if a first argument is not an object', function () {
|
|
216
216
|
const throwable = () => S.testGtLt(10);
|
|
217
217
|
expect(throwable).to.throw(
|
|
218
|
-
'
|
|
218
|
+
'The first argument of OperatorUtils.testGtLt ' +
|
|
219
219
|
'should be an Object, but 10 given.',
|
|
220
220
|
);
|
|
221
221
|
});
|
|
@@ -390,7 +390,7 @@ describe('OperatorClauseTool', function () {
|
|
|
390
390
|
it('throws an error if a first argument is not an object', function () {
|
|
391
391
|
const throwable = () => S.testInq(10);
|
|
392
392
|
expect(throwable).to.throw(
|
|
393
|
-
'
|
|
393
|
+
'The first argument of OperatorUtils.testInq ' +
|
|
394
394
|
'should be an Object, but 10 given.',
|
|
395
395
|
);
|
|
396
396
|
});
|
|
@@ -445,7 +445,7 @@ describe('OperatorClauseTool', function () {
|
|
|
445
445
|
it('throws an error if a first argument is not an object', function () {
|
|
446
446
|
const throwable = () => S.testNin(10);
|
|
447
447
|
expect(throwable).to.throw(
|
|
448
|
-
'
|
|
448
|
+
'The first argument of OperatorUtils.testNin ' +
|
|
449
449
|
'should be an Object, but 10 given.',
|
|
450
450
|
);
|
|
451
451
|
});
|
|
@@ -514,7 +514,7 @@ describe('OperatorClauseTool', function () {
|
|
|
514
514
|
it('throws an error if a first argument is not an object', function () {
|
|
515
515
|
const throwable = () => S.testBetween(10);
|
|
516
516
|
expect(throwable).to.throw(
|
|
517
|
-
'
|
|
517
|
+
'The first argument of OperatorUtils.testBetween ' +
|
|
518
518
|
'should be an Object, but 10 given.',
|
|
519
519
|
);
|
|
520
520
|
});
|
|
@@ -571,7 +571,7 @@ describe('OperatorClauseTool', function () {
|
|
|
571
571
|
it('throws an error if a first argument is not an object', function () {
|
|
572
572
|
const throwable = () => S.testExists(10);
|
|
573
573
|
expect(throwable).to.throw(
|
|
574
|
-
'
|
|
574
|
+
'The first argument of OperatorUtils.testExists ' +
|
|
575
575
|
'should be an Object, but 10 given.',
|
|
576
576
|
);
|
|
577
577
|
});
|
|
@@ -694,7 +694,7 @@ describe('OperatorClauseTool', function () {
|
|
|
694
694
|
it('throws an error if a first argument is not an object', function () {
|
|
695
695
|
const throwable = () => S.testLike(10);
|
|
696
696
|
expect(throwable).to.throw(
|
|
697
|
-
'
|
|
697
|
+
'The first argument of OperatorUtils.testLike ' +
|
|
698
698
|
'should be an Object, but 10 given.',
|
|
699
699
|
);
|
|
700
700
|
});
|
|
@@ -773,7 +773,7 @@ describe('OperatorClauseTool', function () {
|
|
|
773
773
|
it('throws an error if a first argument is not an object', function () {
|
|
774
774
|
const throwable = () => S.testNlike(10);
|
|
775
775
|
expect(throwable).to.throw(
|
|
776
|
-
'
|
|
776
|
+
'The first argument of OperatorUtils.testNlike ' +
|
|
777
777
|
'should be an Object, but 10 given.',
|
|
778
778
|
);
|
|
779
779
|
});
|
|
@@ -852,7 +852,7 @@ describe('OperatorClauseTool', function () {
|
|
|
852
852
|
it('throws an error if a first argument is not an object', function () {
|
|
853
853
|
const throwable = () => S.testIlike(10);
|
|
854
854
|
expect(throwable).to.throw(
|
|
855
|
-
'
|
|
855
|
+
'The first argument of OperatorUtils.testIlike ' +
|
|
856
856
|
'should be an Object, but 10 given.',
|
|
857
857
|
);
|
|
858
858
|
});
|
|
@@ -931,7 +931,7 @@ describe('OperatorClauseTool', function () {
|
|
|
931
931
|
it('throws an error if a first argument is not an object', function () {
|
|
932
932
|
const throwable = () => S.testNilike(10);
|
|
933
933
|
expect(throwable).to.throw(
|
|
934
|
-
'
|
|
934
|
+
'The first argument of OperatorUtils.testNilike ' +
|
|
935
935
|
'should be an Object, but 10 given.',
|
|
936
936
|
);
|
|
937
937
|
});
|
|
@@ -1022,7 +1022,7 @@ describe('OperatorClauseTool', function () {
|
|
|
1022
1022
|
it('throws an error if a first argument is not an object', function () {
|
|
1023
1023
|
const throwable = () => S.testRegexp(10);
|
|
1024
1024
|
expect(throwable).to.throw(
|
|
1025
|
-
'
|
|
1025
|
+
'The first argument of OperatorUtils.testRegexp ' +
|
|
1026
1026
|
'should be an Object, but 10 given.',
|
|
1027
1027
|
);
|
|
1028
1028
|
});
|
|
@@ -16,16 +16,16 @@ export class SliceClauseTool extends Service {
|
|
|
16
16
|
slice(entities, skip = undefined, limit = undefined) {
|
|
17
17
|
if (!Array.isArray(entities))
|
|
18
18
|
throw new InvalidArgumentError(
|
|
19
|
-
'
|
|
19
|
+
'The first argument of SliceClauseTool.slice ' +
|
|
20
20
|
'should be an Array, but %v given.',
|
|
21
21
|
entities,
|
|
22
22
|
);
|
|
23
|
-
if (skip && typeof skip !== 'number')
|
|
23
|
+
if (skip != null && typeof skip !== 'number')
|
|
24
24
|
throw new InvalidArgumentError(
|
|
25
25
|
'The provided option "skip" should be a Number, but %v given.',
|
|
26
26
|
skip,
|
|
27
27
|
);
|
|
28
|
-
if (limit && typeof limit !== 'number')
|
|
28
|
+
if (limit != null && typeof limit !== 'number')
|
|
29
29
|
throw new InvalidArgumentError(
|
|
30
30
|
'The provided option "limit" should be a Number, but %v given.',
|
|
31
31
|
limit,
|
|
@@ -41,7 +41,7 @@ export class SliceClauseTool extends Service {
|
|
|
41
41
|
* @param {number|undefined} skip
|
|
42
42
|
*/
|
|
43
43
|
static validateSkipClause(skip) {
|
|
44
|
-
if (
|
|
44
|
+
if (skip == null) return;
|
|
45
45
|
if (typeof skip !== 'number')
|
|
46
46
|
throw new InvalidArgumentError(
|
|
47
47
|
'The provided option "skip" should be a Number, but %v given.',
|
|
@@ -55,7 +55,7 @@ export class SliceClauseTool extends Service {
|
|
|
55
55
|
* @param {number|undefined} limit
|
|
56
56
|
*/
|
|
57
57
|
static validateLimitClause(limit) {
|
|
58
|
-
if (
|
|
58
|
+
if (limit == null) return;
|
|
59
59
|
if (typeof limit !== 'number')
|
|
60
60
|
throw new InvalidArgumentError(
|
|
61
61
|
'The provided option "limit" should be a Number, but %v given.',
|
|
@@ -5,39 +5,100 @@ import {SliceClauseTool} from './slice-clause-tool.js';
|
|
|
5
5
|
const S = new SliceClauseTool();
|
|
6
6
|
|
|
7
7
|
describe('SliceClauseTool', function () {
|
|
8
|
-
describe('
|
|
9
|
-
it('
|
|
8
|
+
describe('slice', function () {
|
|
9
|
+
it('requires the first argument to be an array', function () {
|
|
10
|
+
const throwable = v => () => S.slice(v);
|
|
11
|
+
const error = v =>
|
|
12
|
+
format(
|
|
13
|
+
'The first argument of SliceClauseTool.slice ' +
|
|
14
|
+
'should be an Array, but %s given.',
|
|
15
|
+
v,
|
|
16
|
+
);
|
|
17
|
+
expect(throwable('str')).to.throw(error('"str"'));
|
|
18
|
+
expect(throwable('')).to.throw(error('""'));
|
|
19
|
+
expect(throwable(10)).to.throw(error('10'));
|
|
20
|
+
expect(throwable(0)).to.throw(error('0'));
|
|
21
|
+
expect(throwable(true)).to.throw(error('true'));
|
|
22
|
+
expect(throwable(false)).to.throw(error('false'));
|
|
23
|
+
expect(throwable({})).to.throw(error('Object'));
|
|
24
|
+
expect(throwable(undefined)).to.throw(error('undefined'));
|
|
25
|
+
expect(throwable(null)).to.throw(error('null'));
|
|
26
|
+
expect(throwable([{foo: 'bar'}])()).to.be.eql([{foo: 'bar'}]);
|
|
27
|
+
expect(throwable([])()).to.be.eql([]);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('requires the provided second argument to be a number', function () {
|
|
31
|
+
const items = [{foo: 'bar'}];
|
|
32
|
+
const throwable = v => () => S.slice(items, v);
|
|
33
|
+
const error = v =>
|
|
34
|
+
format(
|
|
35
|
+
'The provided option "skip" should be a Number, but %s given.',
|
|
36
|
+
v,
|
|
37
|
+
);
|
|
38
|
+
expect(throwable('str')).to.throw(error('"str"'));
|
|
39
|
+
expect(throwable('')).to.throw(error('""'));
|
|
40
|
+
expect(throwable(true)).to.throw(error('true'));
|
|
41
|
+
expect(throwable(false)).to.throw(error('false'));
|
|
42
|
+
expect(throwable({})).to.throw(error('Object'));
|
|
43
|
+
expect(throwable([])).to.throw(error('Array'));
|
|
44
|
+
expect(throwable(10)()).to.be.eql([]);
|
|
45
|
+
expect(throwable(0)()).to.be.eql(items);
|
|
46
|
+
expect(throwable(undefined)()).to.be.eql(items);
|
|
47
|
+
expect(throwable(null)()).to.be.eql(items);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('requires the provided third argument to be a number', function () {
|
|
51
|
+
const items = [{foo: 'bar'}];
|
|
52
|
+
const throwable = v => () => S.slice(items, undefined, v);
|
|
53
|
+
const error = v =>
|
|
54
|
+
format(
|
|
55
|
+
'The provided option "limit" should be a Number, but %s given.',
|
|
56
|
+
v,
|
|
57
|
+
);
|
|
58
|
+
expect(throwable('str')).to.throw(error('"str"'));
|
|
59
|
+
expect(throwable('')).to.throw(error('""'));
|
|
60
|
+
expect(throwable(true)).to.throw(error('true'));
|
|
61
|
+
expect(throwable(false)).to.throw(error('false'));
|
|
62
|
+
expect(throwable({})).to.throw(error('Object'));
|
|
63
|
+
expect(throwable([])).to.throw(error('Array'));
|
|
64
|
+
expect(throwable(10)()).to.be.eql(items);
|
|
65
|
+
expect(throwable(0)()).to.be.eql(items);
|
|
66
|
+
expect(throwable(undefined)()).to.be.eql(items);
|
|
67
|
+
expect(throwable(null)()).to.be.eql(items);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('does nothing if no "skip" and "limit" options provided', function () {
|
|
10
71
|
const objects = [{id: 1}, {id: 2}, {id: 3}];
|
|
11
72
|
const result = S.slice(objects);
|
|
12
73
|
expect(result).to.be.eql(objects);
|
|
13
74
|
});
|
|
14
75
|
|
|
15
|
-
it('does nothing if
|
|
76
|
+
it('does nothing if the given "skip" option is zero', function () {
|
|
16
77
|
const objects = [{id: 1}, {id: 2}, {id: 3}];
|
|
17
78
|
const result = S.slice(objects, 0);
|
|
18
79
|
expect(result).to.be.eql(objects);
|
|
19
80
|
});
|
|
20
81
|
|
|
21
|
-
it('uses
|
|
82
|
+
it('uses the given "skip" option to exclude array elements from start', function () {
|
|
22
83
|
const objects = [{id: 1}, {id: 2}, {id: 3}];
|
|
23
84
|
const result = S.slice(objects, 2);
|
|
24
85
|
expect(result).to.have.length(1);
|
|
25
86
|
expect(result[0]).to.be.eql(objects[2]);
|
|
26
87
|
});
|
|
27
88
|
|
|
28
|
-
it('returns an empty array
|
|
89
|
+
it('returns an empty array when "skip" option overflows a size of the given array ', function () {
|
|
29
90
|
const objects = [{id: 1}, {id: 2}, {id: 3}];
|
|
30
91
|
const result = S.slice(objects, 10);
|
|
31
92
|
expect(result).to.have.length(0);
|
|
32
93
|
});
|
|
33
94
|
|
|
34
|
-
it('does nothing if
|
|
95
|
+
it('does nothing if the given "limit" option is zero', function () {
|
|
35
96
|
const objects = [{id: 1}, {id: 2}, {id: 3}];
|
|
36
97
|
const result = S.slice(objects, undefined, 0);
|
|
37
98
|
expect(result).to.be.eql(objects);
|
|
38
99
|
});
|
|
39
100
|
|
|
40
|
-
it('uses
|
|
101
|
+
it('uses the given "limit" option to trim the given array', function () {
|
|
41
102
|
const objects = [{id: 1}, {id: 2}, {id: 3}];
|
|
42
103
|
const result = S.slice(objects, undefined, 2);
|
|
43
104
|
expect(result).to.have.length(2);
|
|
@@ -45,73 +106,53 @@ describe('SliceClauseTool', function () {
|
|
|
45
106
|
expect(result[1]).to.be.eql(objects[1]);
|
|
46
107
|
});
|
|
47
108
|
|
|
48
|
-
it('
|
|
109
|
+
it('uses the "skip" and "limit" options to slice the given array', function () {
|
|
49
110
|
const objects = [{id: 1}, {id: 2}, {id: 3}];
|
|
50
111
|
const result = S.slice(objects, 1, 1);
|
|
51
112
|
expect(result).to.have.length(1);
|
|
52
113
|
expect(result[0]).to.be.eql(objects[1]);
|
|
53
114
|
});
|
|
54
|
-
|
|
55
|
-
it('throws an error if a first argument is not an array', function () {
|
|
56
|
-
const throwable = () => S.slice(10);
|
|
57
|
-
expect(throwable).to.throw(
|
|
58
|
-
'A first argument of SliceClauseTool.slice ' +
|
|
59
|
-
'should be an Array, but 10 given.',
|
|
60
|
-
);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('throws an error if the given "skip" option is not a number', function () {
|
|
64
|
-
const throwable = () => S.slice([], 'invalid');
|
|
65
|
-
expect(throwable).to.throw(
|
|
66
|
-
'The provided option "skip" should be a Number, but "invalid" given.',
|
|
67
|
-
);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('throws an error if the given "limit" option is not a number', function () {
|
|
71
|
-
const throwable = () => S.slice([], undefined, 'invalid');
|
|
72
|
-
expect(throwable).to.throw(
|
|
73
|
-
'The provided option "limit" should be a Number, but "invalid" given.',
|
|
74
|
-
);
|
|
75
|
-
});
|
|
76
115
|
});
|
|
77
116
|
|
|
78
117
|
describe('validateSkipClause', function () {
|
|
79
|
-
it('requires a number value
|
|
80
|
-
const
|
|
118
|
+
it('requires a number value', function () {
|
|
119
|
+
const throwable = v => () => SliceClauseTool.validateSkipClause(v);
|
|
81
120
|
const error = v =>
|
|
82
121
|
format(
|
|
83
122
|
'The provided option "skip" should be a Number, but %s given.',
|
|
84
123
|
v,
|
|
85
124
|
);
|
|
86
|
-
expect(
|
|
87
|
-
expect(
|
|
88
|
-
expect(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
125
|
+
expect(throwable('str')).to.throw(error('"str"'));
|
|
126
|
+
expect(throwable('')).to.throw(error('""'));
|
|
127
|
+
expect(throwable(true)).to.throw(error('true'));
|
|
128
|
+
expect(throwable(false)).to.throw(error('false'));
|
|
129
|
+
expect(throwable({})).to.throw(error('Object'));
|
|
130
|
+
expect(throwable([])).to.throw(error('Array'));
|
|
131
|
+
throwable(10)();
|
|
132
|
+
throwable(0)();
|
|
133
|
+
throwable(undefined)();
|
|
134
|
+
throwable(null)();
|
|
95
135
|
});
|
|
96
136
|
});
|
|
97
137
|
|
|
98
138
|
describe('validateLimitClause', function () {
|
|
99
139
|
it('requires a number value or a falsy value', function () {
|
|
100
|
-
const
|
|
140
|
+
const throwable = v => () => SliceClauseTool.validateLimitClause(v);
|
|
101
141
|
const error = v =>
|
|
102
142
|
format(
|
|
103
143
|
'The provided option "limit" should be a Number, but %s given.',
|
|
104
144
|
v,
|
|
105
145
|
);
|
|
106
|
-
expect(
|
|
107
|
-
expect(
|
|
108
|
-
expect(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
146
|
+
expect(throwable('str')).to.throw(error('"str"'));
|
|
147
|
+
expect(throwable('')).to.throw(error('""'));
|
|
148
|
+
expect(throwable(true)).to.throw(error('true'));
|
|
149
|
+
expect(throwable(false)).to.throw(error('false'));
|
|
150
|
+
expect(throwable({})).to.throw(error('Object'));
|
|
151
|
+
expect(throwable([])).to.throw(error('Array'));
|
|
152
|
+
throwable(10)();
|
|
153
|
+
throwable(0)();
|
|
154
|
+
throwable(undefined)();
|
|
155
|
+
throwable(null)();
|
|
115
156
|
});
|
|
116
157
|
});
|
|
117
158
|
});
|
|
@@ -41,11 +41,11 @@ export class WhereClauseTool extends Service {
|
|
|
41
41
|
filter(entities, where = undefined) {
|
|
42
42
|
if (!Array.isArray(entities))
|
|
43
43
|
throw new InvalidArgumentError(
|
|
44
|
-
'
|
|
45
|
-
'
|
|
44
|
+
'The first argument of WhereClauseTool.filter should be ' +
|
|
45
|
+
'an Array of Object, but %v given.',
|
|
46
46
|
entities,
|
|
47
47
|
);
|
|
48
|
-
if (
|
|
48
|
+
if (where == null) return entities;
|
|
49
49
|
return entities.filter(this._createFilter(where));
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -57,7 +57,7 @@ export class WhereClauseTool extends Service {
|
|
|
57
57
|
*/
|
|
58
58
|
_createFilter(whereClause) {
|
|
59
59
|
if (typeof whereClause === 'function') return whereClause;
|
|
60
|
-
if (typeof whereClause !== 'object')
|
|
60
|
+
if (typeof whereClause !== 'object' || Array.isArray(whereClause))
|
|
61
61
|
throw new InvalidArgumentError(
|
|
62
62
|
'The provided option "where" should be an Object, but %v given.',
|
|
63
63
|
whereClause,
|
|
@@ -66,8 +66,8 @@ export class WhereClauseTool extends Service {
|
|
|
66
66
|
return data => {
|
|
67
67
|
if (typeof data !== 'object')
|
|
68
68
|
throw new InvalidArgumentError(
|
|
69
|
-
'
|
|
70
|
-
'
|
|
69
|
+
'The first argument of WhereClauseTool.filter should be ' +
|
|
70
|
+
'an Array of Object, but %v given.',
|
|
71
71
|
data,
|
|
72
72
|
);
|
|
73
73
|
return keys.every(key => {
|
|
@@ -155,7 +155,7 @@ export class WhereClauseTool extends Service {
|
|
|
155
155
|
* @param {WhereClause|undefined} clause
|
|
156
156
|
*/
|
|
157
157
|
static validateWhereClause(clause) {
|
|
158
|
-
if (
|
|
158
|
+
if (clause == null || typeof clause === 'function') return;
|
|
159
159
|
if (typeof clause !== 'object' || Array.isArray(clause))
|
|
160
160
|
throw new InvalidArgumentError(
|
|
161
161
|
'The provided option "where" should be an Object, but %v given.',
|