@e22m4u/js-repository 0.0.33 → 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.
Files changed (34) hide show
  1. package/package.json +1 -1
  2. package/src/adapter/adapter-loader.js +1 -1
  3. package/src/adapter/adapter-loader.spec.js +1 -1
  4. package/src/adapter/decorator/data-sanitizing-decorator.js +1 -1
  5. package/src/adapter/decorator/data-validation-decorator.js +1 -1
  6. package/src/adapter/decorator/default-values-decorator.js +1 -1
  7. package/src/adapter/decorator/fields-filtering-decorator.js +1 -1
  8. package/src/adapter/decorator/inclusion-decorator.js +1 -1
  9. package/src/definition/model/model-data-sanitizer.js +2 -2
  10. package/src/definition/model/model-data-validator.js +1 -1
  11. package/src/definition/model/model-data-validator.spec.js +1 -1
  12. package/src/definition/model/model-definition-utils.js +1 -1
  13. package/src/definition/model/model-definition-utils.spec.js +1 -1
  14. package/src/definition/model/properties/default-values-definition-validator.js +1 -1
  15. package/src/definition/model/properties/default-values-definition-validator.spec.js +1 -1
  16. package/src/definition/model/properties/properties-definition-validator.js +2 -2
  17. package/src/definition/model/properties/properties-definition-validator.spec.js +1 -1
  18. package/src/definition/model/relations/relations-definition-validator.js +2 -2
  19. package/src/definition/model/relations/relations-definition-validator.spec.js +1 -1
  20. package/src/filter/fields-clause-tool.d.ts +2 -2
  21. package/src/filter/fields-clause-tool.js +32 -21
  22. package/src/filter/fields-clause-tool.spec.js +479 -100
  23. package/src/filter/include-clause-tool.js +50 -42
  24. package/src/filter/include-clause-tool.spec.js +4391 -291
  25. package/src/filter/operator-clause-tool.js +13 -13
  26. package/src/filter/operator-clause-tool.spec.js +13 -13
  27. package/src/filter/order-clause-tool.js +20 -17
  28. package/src/filter/order-clause-tool.spec.js +621 -362
  29. package/src/filter/slice-clause-tool.js +5 -5
  30. package/src/filter/slice-clause-tool.spec.js +92 -51
  31. package/src/filter/where-clause-tool.js +7 -7
  32. package/src/filter/where-clause-tool.spec.js +79 -55
  33. package/src/utils/select-object-keys.js +3 -3
  34. package/src/utils/select-object-keys.spec.js +3 -3
@@ -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
- 'A first argument of SliceClauseTool.slice ' +
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 (!skip) return;
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 (!limit) return;
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('filter', function () {
9
- it('does nothing if no clauses provided', function () {
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 a given skip is zero', function () {
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 a given skip to exclude array elements from start', function () {
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 if skipping too much', function () {
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 a given limit is zero', function () {
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 a given limit to trim a given array', function () {
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('able to combine a skip and a limit option together', function () {
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 or a falsy value', function () {
80
- const validate = v => () => SliceClauseTool.validateSkipClause(v);
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(validate('str')).to.throw(error('"str"'));
87
- expect(validate(true)).to.throw(error('true'));
88
- expect(validate([])).to.throw(error('Array'));
89
- validate('')();
90
- validate(false)();
91
- validate(undefined)();
92
- validate(null)();
93
- validate(10)();
94
- validate(0)();
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 validate = v => () => SliceClauseTool.validateLimitClause(v);
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(validate('str')).to.throw(error('"str"'));
107
- expect(validate(true)).to.throw(error('true'));
108
- expect(validate([])).to.throw(error('Array'));
109
- validate('')();
110
- validate(false)();
111
- validate(undefined)();
112
- validate(null)();
113
- validate(10)();
114
- validate(0)();
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
- 'A first argument of WhereUtils.filter ' +
45
- 'should be an Array of Objects, but %v given.',
44
+ 'The first argument of WhereClauseTool.filter should be ' +
45
+ 'an Array of Object, but %v given.',
46
46
  entities,
47
47
  );
48
- if (!where) return entities;
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
- 'A first argument of WhereUtils.filter ' +
70
- 'should be an Array of Objects, but %v given.',
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 (!clause) return;
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.',
@@ -44,11 +44,56 @@ const OBJECTS = [
44
44
 
45
45
  describe('WhereClauseTool', function () {
46
46
  describe('filter', function () {
47
+ it('requires the first argument to be an array of objects', function () {
48
+ const throwable = v => () => S.filter(v, {});
49
+ const error = v =>
50
+ format(
51
+ 'The first argument of WhereClauseTool.filter should be ' +
52
+ 'an Array of Object, but %s given.',
53
+ v,
54
+ );
55
+ expect(throwable('str')).to.throw(error('"str"'));
56
+ expect(throwable('')).to.throw(error('""'));
57
+ expect(throwable(10)).to.throw(error('10'));
58
+ expect(throwable(0)).to.throw(error('0'));
59
+ expect(throwable(true)).to.throw(error('true'));
60
+ expect(throwable(false)).to.throw(error('false'));
61
+ expect(throwable({})).to.throw(error('Object'));
62
+ expect(throwable(undefined)).to.throw(error('undefined'));
63
+ expect(throwable(null)).to.throw(error('null'));
64
+ expect(throwable([{foo: 'bar'}])()).to.be.eql([{foo: 'bar'}]);
65
+ expect(throwable([])()).to.be.eql([]);
66
+ });
67
+
68
+ it('requires the second argument to be an object', function () {
69
+ const throwable = v => () => S.filter(OBJECTS, v);
70
+ const error = v =>
71
+ format(
72
+ 'The provided option "where" should be an Object, but %s given.',
73
+ v,
74
+ );
75
+ expect(throwable('str')).to.throw(error('"str"'));
76
+ expect(throwable('')).to.throw(error('""'));
77
+ expect(throwable(10)).to.throw(error('10'));
78
+ expect(throwable(0)).to.throw(error('0'));
79
+ expect(throwable(true)).to.throw(error('true'));
80
+ expect(throwable(false)).to.throw(error('false'));
81
+ expect(throwable([])).to.throw(error('Array'));
82
+ expect(throwable({})()).to.be.eql(OBJECTS);
83
+ expect(throwable(undefined)()).to.be.eql(OBJECTS);
84
+ expect(throwable(null)()).to.be.eql(OBJECTS);
85
+ });
86
+
47
87
  it('returns the same array if no given condition', function () {
48
88
  const result = S.filter(OBJECTS);
49
89
  expect(result).to.be.eql(OBJECTS);
50
90
  });
51
91
 
92
+ it('returns the same array if the given clause object is empty', function () {
93
+ const result = S.filter(OBJECTS, {});
94
+ expect(result).to.be.eql(OBJECTS);
95
+ });
96
+
52
97
  it('returns a filtered array by matched properties', function () {
53
98
  const result = S.filter(OBJECTS, {surname: 'Smith', age: 21});
54
99
  expect(result).to.have.length(2);
@@ -56,7 +101,7 @@ describe('WhereClauseTool', function () {
56
101
  expect(result[1]).to.be.eql(OBJECTS[2]);
57
102
  });
58
103
 
59
- it('the and operator requires each given condition to be met', function () {
104
+ it('the "and" operator requires each given condition to be met', function () {
60
105
  const result = S.filter(OBJECTS, {
61
106
  and: [{name: 'James'}, {age: 21}],
62
107
  });
@@ -64,7 +109,7 @@ describe('WhereClauseTool', function () {
64
109
  expect(result[0]).to.be.eql(OBJECTS[2]);
65
110
  });
66
111
 
67
- it('the or operator requires one of a given condition to be met', function () {
112
+ it('the "or" operator requires one of a given condition to be met', function () {
68
113
  const result = S.filter(OBJECTS, {
69
114
  or: [{name: 'James'}, {age: 21}],
70
115
  });
@@ -101,13 +146,13 @@ describe('WhereClauseTool', function () {
101
146
  expect(result).to.be.empty;
102
147
  });
103
148
 
104
- it('uses an "eq" operator to match equality', function () {
149
+ it('uses the "eq" operator to match equality', function () {
105
150
  const result = S.filter(OBJECTS, {name: {eq: 'John'}});
106
151
  expect(result).to.have.length(1);
107
152
  expect(result[0]).to.be.eql(OBJECTS[0]);
108
153
  });
109
154
 
110
- it('uses a "neq" operator to match non-equality', function () {
155
+ it('uses the "neq" operator to match non-equality', function () {
111
156
  const result = S.filter(OBJECTS, {name: {neq: 'John'}});
112
157
  expect(result).to.have.length(3);
113
158
  expect(result[0]).to.be.eql(OBJECTS[1]);
@@ -115,21 +160,21 @@ describe('WhereClauseTool', function () {
115
160
  expect(result[2]).to.be.eql(OBJECTS[3]);
116
161
  });
117
162
 
118
- it('uses a "neq" operator to match an empty array', function () {
163
+ it('uses the "neq" operator to match an empty array', function () {
119
164
  const result = S.filter(OBJECTS, {hobbies: {neq: 'bicycle'}});
120
165
  expect(result).to.have.length(2);
121
166
  expect(result[0]).to.be.eql(OBJECTS[1]);
122
167
  expect(result[1]).to.be.eql(OBJECTS[2]);
123
168
  });
124
169
 
125
- it('uses a "gt" operator to compare values', function () {
170
+ it('uses the "gt" operator to compare values', function () {
126
171
  const result = S.filter(OBJECTS, {id: {gt: 2}});
127
172
  expect(result).to.have.length(2);
128
173
  expect(result[0]).to.be.eql(OBJECTS[2]);
129
174
  expect(result[1]).to.be.eql(OBJECTS[3]);
130
175
  });
131
176
 
132
- it('uses a "gte" operator to compare values', function () {
177
+ it('uses the "gte" operator to compare values', function () {
133
178
  const result = S.filter(OBJECTS, {id: {gte: 2}});
134
179
  expect(result).to.have.length(3);
135
180
  expect(result[0]).to.be.eql(OBJECTS[1]);
@@ -137,14 +182,14 @@ describe('WhereClauseTool', function () {
137
182
  expect(result[2]).to.be.eql(OBJECTS[3]);
138
183
  });
139
184
 
140
- it('uses a "lt" operator to compare values', function () {
185
+ it('uses the "lt" operator to compare values', function () {
141
186
  const result = S.filter(OBJECTS, {id: {lt: 3}});
142
187
  expect(result).to.have.length(2);
143
188
  expect(result[0]).to.be.eql(OBJECTS[0]);
144
189
  expect(result[1]).to.be.eql(OBJECTS[1]);
145
190
  });
146
191
 
147
- it('uses a "lte" operator to compare values', function () {
192
+ it('uses the "lte" operator to compare values', function () {
148
193
  const result = S.filter(OBJECTS, {id: {lte: 3}});
149
194
  expect(result).to.have.length(3);
150
195
  expect(result[0]).to.be.eql(OBJECTS[0]);
@@ -152,28 +197,28 @@ describe('WhereClauseTool', function () {
152
197
  expect(result[2]).to.be.eql(OBJECTS[2]);
153
198
  });
154
199
 
155
- it('uses a "inq" operator to compare values', function () {
200
+ it('uses the "inq" operator to compare values', function () {
156
201
  const result = S.filter(OBJECTS, {id: {inq: [2, 3]}});
157
202
  expect(result).to.have.length(2);
158
203
  expect(result[0]).to.be.eql(OBJECTS[1]);
159
204
  expect(result[1]).to.be.eql(OBJECTS[2]);
160
205
  });
161
206
 
162
- it('uses a "nin" operator to compare values', function () {
207
+ it('uses the "nin" operator to compare values', function () {
163
208
  const result = S.filter(OBJECTS, {id: {nin: [2, 3]}});
164
209
  expect(result).to.have.length(2);
165
210
  expect(result[0]).to.be.eql(OBJECTS[0]);
166
211
  expect(result[1]).to.be.eql(OBJECTS[3]);
167
212
  });
168
213
 
169
- it('uses a "between" operator to compare values', function () {
214
+ it('uses the "between" operator to compare values', function () {
170
215
  const result = S.filter(OBJECTS, {id: {between: [2, 3]}});
171
216
  expect(result).to.have.length(2);
172
217
  expect(result[0]).to.be.eql(OBJECTS[1]);
173
218
  expect(result[1]).to.be.eql(OBJECTS[2]);
174
219
  });
175
220
 
176
- it('uses an "exists" operator to check existence', function () {
221
+ it('uses the "exists" operator to check existence', function () {
177
222
  const result = S.filter(OBJECTS, {nickname: {exists: true}});
178
223
  expect(result).to.have.length(3);
179
224
  expect(result[0]).to.be.eql(OBJECTS[0]);
@@ -181,19 +226,19 @@ describe('WhereClauseTool', function () {
181
226
  expect(result[2]).to.be.eql(OBJECTS[2]);
182
227
  });
183
228
 
184
- it('uses an "exists" operator to check non-existence', function () {
229
+ it('uses the "exists" operator to check non-existence', function () {
185
230
  const result = S.filter(OBJECTS, {nickname: {exists: false}});
186
231
  expect(result).to.have.length(1);
187
232
  expect(result[0]).to.be.eql(OBJECTS[3]);
188
233
  });
189
234
 
190
- it('uses a "like" operator to match by a substring', function () {
235
+ it('uses the "like" operator to match by a substring', function () {
191
236
  const result = S.filter(OBJECTS, {name: {like: 'liv'}});
192
237
  expect(result).to.have.length(1);
193
238
  expect(result[0]).to.be.eql(OBJECTS[3]);
194
239
  });
195
240
 
196
- it('uses a "nlike" operator to exclude by a substring', function () {
241
+ it('uses the "nlike" operator to exclude by a substring', function () {
197
242
  const result = S.filter(OBJECTS, {name: {nlike: 'liv'}});
198
243
  expect(result).to.have.length(3);
199
244
  expect(result[0]).to.be.eql(OBJECTS[0]);
@@ -201,13 +246,13 @@ describe('WhereClauseTool', function () {
201
246
  expect(result[2]).to.be.eql(OBJECTS[2]);
202
247
  });
203
248
 
204
- it('uses a "ilike" operator to case-insensitively matching by a substring', function () {
249
+ it('uses the "ilike" operator to case-insensitively matching by a substring', function () {
205
250
  const result = S.filter(OBJECTS, {name: {ilike: 'LIV'}});
206
251
  expect(result).to.have.length(1);
207
252
  expect(result[0]).to.be.eql(OBJECTS[3]);
208
253
  });
209
254
 
210
- it('uses a "nilike" operator to exclude case-insensitively by a substring', function () {
255
+ it('uses the "nilike" operator to exclude case-insensitively by a substring', function () {
211
256
  const result = S.filter(OBJECTS, {name: {nilike: 'LIV'}});
212
257
  expect(result).to.have.length(3);
213
258
  expect(result[0]).to.be.eql(OBJECTS[0]);
@@ -215,66 +260,45 @@ describe('WhereClauseTool', function () {
215
260
  expect(result[2]).to.be.eql(OBJECTS[2]);
216
261
  });
217
262
 
218
- it('uses a "regexp" operator to compare values', function () {
263
+ it('uses the "regexp" operator to compare values', function () {
219
264
  const result = S.filter(OBJECTS, {name: {regexp: '^Jam.*'}});
220
265
  expect(result).to.have.length(1);
221
266
  expect(result[0]).to.be.eql(OBJECTS[2]);
222
267
  });
223
268
 
224
- it('uses a null to match an undefined and null value', function () {
269
+ it('uses null to match an undefined and null value', function () {
225
270
  const result = S.filter(OBJECTS, {nickname: null});
226
271
  expect(result).to.have.length(2);
227
272
  expect(result[0]).to.be.eql(OBJECTS[2]);
228
273
  expect(result[1]).to.be.eql(OBJECTS[3]);
229
274
  });
230
275
 
231
- it('uses a given function to filter values', function () {
276
+ it('uses the given function to filter values', function () {
232
277
  const result = S.filter(OBJECTS, v => v.nickname === 'Flower');
233
278
  expect(result).to.have.length(1);
234
279
  expect(result[0]).to.be.eql(OBJECTS[1]);
235
280
  });
236
-
237
- it('throws an error if a first argument is not an Array', function () {
238
- const throwable = () => S.filter(10, {});
239
- expect(throwable).to.throw(
240
- 'A first argument of WhereUtils.filter ' +
241
- 'should be an Array of Objects, but 10 given.',
242
- );
243
- });
244
-
245
- it('throws an error if elements of a first argument is not an Object', function () {
246
- const throwable = () => S.filter([10], {});
247
- expect(throwable).to.throw(
248
- 'A first argument of WhereUtils.filter ' +
249
- 'should be an Array of Objects, but 10 given.',
250
- );
251
- });
252
-
253
- it('throws an error if a provided second argument is not an Object', function () {
254
- const throwable = () => S.filter([], 10);
255
- expect(throwable).to.throw(
256
- 'The provided option "where" should be an Object, but 10 given.',
257
- );
258
- });
259
281
  });
260
282
 
261
283
  describe('validateWhereClause', function () {
262
- it('requires an object value or a falsy value', function () {
263
- const validate = v => () => WhereClauseTool.validateWhereClause(v);
284
+ it('requires the first argument to be an object or a function', function () {
285
+ const throwable = v => () => WhereClauseTool.validateWhereClause(v);
264
286
  const error = v =>
265
287
  format(
266
288
  'The provided option "where" should be an Object, but %s given.',
267
289
  v,
268
290
  );
269
- expect(validate('str')).to.throw(error('"str"'));
270
- expect(validate(10)).to.throw(error('10'));
271
- expect(validate(true)).to.throw(error('true'));
272
- expect(validate([])).to.throw(error('Array'));
273
- validate('')();
274
- validate(false)();
275
- validate(undefined)();
276
- validate(null)();
277
- validate({})();
291
+ expect(throwable('str')).to.throw(error('"str"'));
292
+ expect(throwable('')).to.throw(error('""'));
293
+ expect(throwable(10)).to.throw(error('10'));
294
+ expect(throwable(0)).to.throw(error('0'));
295
+ expect(throwable(true)).to.throw(error('true'));
296
+ expect(throwable(false)).to.throw(error('false'));
297
+ expect(throwable([])).to.throw(error('Array'));
298
+ throwable({foo: 'bar'})();
299
+ throwable({})();
300
+ throwable(undefined)();
301
+ throwable(null)();
278
302
  });
279
303
  });
280
304
  });
@@ -10,20 +10,20 @@ 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
- 'A first argument of selectObjectKeys ' +
13
+ 'The first argument of selectObjectKeys ' +
14
14
  'should be an Object, but %v given.',
15
15
  obj,
16
16
  );
17
17
  if (!Array.isArray(keys))
18
18
  throw new InvalidArgumentError(
19
- 'A second argument of selectObjectKeys ' +
19
+ 'The second argument of selectObjectKeys ' +
20
20
  'should be an Array of String, but %v given.',
21
21
  keys,
22
22
  );
23
23
  keys.forEach(key => {
24
24
  if (typeof key !== 'string')
25
25
  throw new InvalidArgumentError(
26
- 'A second argument of selectObjectKeys ' +
26
+ 'The second argument of selectObjectKeys ' +
27
27
  'should be an Array of String, but %v given.',
28
28
  key,
29
29
  );
@@ -17,7 +17,7 @@ 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
- 'A first argument of selectObjectKeys ' +
20
+ 'The first argument of selectObjectKeys ' +
21
21
  'should be an Object, but 10 given.',
22
22
  );
23
23
  });
@@ -25,7 +25,7 @@ describe('selectObjectKeys', function () {
25
25
  it('throws an error if a given keys is not an Array', function () {
26
26
  const throwable = () => selectObjectKeys({});
27
27
  expect(throwable).to.throw(
28
- 'A second argument of selectObjectKeys ' +
28
+ 'The second argument of selectObjectKeys ' +
29
29
  'should be an Array of String, but undefined given.',
30
30
  );
31
31
  });
@@ -33,7 +33,7 @@ describe('selectObjectKeys', function () {
33
33
  it('throws an error if a given keys is not an String', function () {
34
34
  const throwable = () => selectObjectKeys({}, [10]);
35
35
  expect(throwable).to.throw(
36
- 'A second argument of selectObjectKeys ' +
36
+ 'The second argument of selectObjectKeys ' +
37
37
  'should be an Array of String, but 10 given.',
38
38
  );
39
39
  });