@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
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
263
|
-
const
|
|
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(
|
|
270
|
-
expect(
|
|
271
|
-
expect(
|
|
272
|
-
expect(
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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
|
-
'
|
|
36
|
+
'The second argument of selectObjectKeys ' +
|
|
37
37
|
'should be an Array of String, but 10 given.',
|
|
38
38
|
);
|
|
39
39
|
});
|