@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.
- package/build-cjs.js +1 -1
- package/dist/cjs/index.cjs +560 -491
- package/package.json +8 -8
- package/src/adapter/adapter-loader.js +2 -5
- package/src/adapter/adapter-loader.spec.js +2 -2
- package/src/adapter/adapter-registry.spec.js +2 -2
- package/src/adapter/builtin/memory-adapter.js +5 -5
- package/src/adapter/builtin/memory-adapter.spec.js +12 -12
- package/src/adapter/decorator/data-sanitizing-decorator.js +1 -2
- package/src/adapter/decorator/default-values-decorator.js +1 -2
- package/src/adapter/decorator/fields-filtering-decorator.js +1 -2
- package/src/adapter/decorator/inclusion-decorator.js +1 -2
- package/src/adapter/decorator/property-uniqueness-decorator.js +1 -2
- package/src/adapter/decorator/required-property-decorator.js +1 -2
- package/src/database-schema.spec.js +3 -5
- package/src/definition/datasource/datasource-definition-validator.js +3 -3
- package/src/definition/datasource/datasource-definition-validator.spec.js +3 -6
- package/src/definition/definition-registry.js +4 -7
- package/src/definition/definition-registry.spec.js +4 -6
- package/src/definition/model/model-data-sanitizer.js +2 -4
- package/src/definition/model/model-definition-utils.js +12 -14
- package/src/definition/model/model-definition-utils.spec.js +12 -21
- package/src/definition/model/model-definition-validator.js +12 -12
- package/src/definition/model/model-definition-validator.spec.js +12 -15
- package/src/definition/model/properties/primary-keys-definition-validator.js +4 -4
- package/src/definition/model/properties/primary-keys-definition-validator.spec.js +8 -8
- package/src/definition/model/properties/properties-definition-validator.js +42 -43
- package/src/definition/model/properties/properties-definition-validator.spec.js +45 -45
- package/src/definition/model/properties/property-uniqueness-validator.js +7 -11
- package/src/definition/model/properties/property-uniqueness-validator.spec.js +57 -60
- package/src/definition/model/properties/required-property-validator.js +1 -1
- package/src/definition/model/properties/required-property-validator.spec.js +1 -1
- package/src/definition/model/relations/relations-definition-validator.js +40 -42
- package/src/definition/model/relations/relations-definition-validator.spec.js +44 -45
- package/src/errors/invalid-operator-value-error.js +1 -1
- package/src/errors/invalid-operator-value-error.spec.js +1 -1
- package/src/filter/fields-clause-tool.js +95 -53
- package/src/filter/fields-clause-tool.spec.js +210 -387
- package/src/filter/include-clause-tool.js +9 -9
- package/src/filter/include-clause-tool.spec.js +4 -4
- package/src/filter/operator-clause-tool.js +20 -32
- package/src/filter/operator-clause-tool.spec.js +25 -49
- package/src/filter/order-clause-tool.js +55 -27
- package/src/filter/order-clause-tool.spec.js +151 -90
- package/src/filter/slice-clause-tool.js +5 -6
- package/src/filter/slice-clause-tool.spec.js +8 -24
- package/src/filter/where-clause-tool.js +18 -11
- package/src/filter/where-clause-tool.spec.js +27 -17
- package/src/relations/belongs-to-resolver.js +18 -30
- package/src/relations/belongs-to-resolver.spec.js +21 -44
- package/src/relations/has-many-resolver.js +28 -44
- package/src/relations/has-many-resolver.spec.js +44 -68
- package/src/relations/has-one-resolver.js +28 -44
- package/src/relations/has-one-resolver.spec.js +44 -68
- package/src/relations/references-many-resolver.js +8 -14
- package/src/relations/references-many-resolver.spec.js +12 -24
- package/src/repository/repository-registry.js +2 -2
- package/src/repository/repository.js +1 -1
- package/src/utils/exclude-object-keys.js +2 -2
- package/src/utils/exclude-object-keys.spec.js +2 -2
- package/src/utils/like-to-regexp.js +1 -2
- package/src/utils/like-to-regexp.spec.js +5 -5
- package/src/utils/model-name-to-model-key.js +1 -1
- package/src/utils/model-name-to-model-key.spec.js +7 -7
- package/src/utils/select-object-keys.js +6 -7
- 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
|
-
'
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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 = '
|
|
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
|
-
'
|
|
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 = '
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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
|
|
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
|
|
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
|
-
'
|
|
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
|
|
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
|
-
'
|
|
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
|
|
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
|
-
'
|
|
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
|
|
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
|
-
'
|
|
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
|
|
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
|
-
'
|
|
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
|
|
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
|
-
'
|
|
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
|
|
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
|
-
'
|
|
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: ...}
|
|
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: ...}
|
|
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: ...}
|
|
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: ...}
|
|
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
|
|
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
|
-
'
|
|
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
|
|
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
|
-
|
|
20
|
-
|
|
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 (!
|
|
33
|
+
if (!isArrayClause) {
|
|
34
|
+
clause = [clause];
|
|
35
|
+
} else if (!clause.length) {
|
|
23
36
|
return;
|
|
24
37
|
}
|
|
25
38
|
const mapping = [];
|
|
26
|
-
clause.forEach((
|
|
27
|
-
if (!
|
|
39
|
+
clause.forEach((element, index) => {
|
|
40
|
+
if (!element || typeof element !== 'string') {
|
|
28
41
|
throw new InvalidArgumentError(
|
|
29
|
-
'
|
|
30
|
-
'
|
|
31
|
-
|
|
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 =
|
|
49
|
+
const matches = element.match(/\s+(A|DE)SC$/i);
|
|
36
50
|
if (matches) {
|
|
37
|
-
|
|
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:
|
|
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
|
-
|
|
57
|
-
|
|
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(
|
|
63
|
-
if (!
|
|
81
|
+
clause.forEach((element, index) => {
|
|
82
|
+
if (!element || typeof element !== 'string') {
|
|
64
83
|
throw new InvalidArgumentError(
|
|
65
|
-
'
|
|
66
|
-
'
|
|
67
|
-
|
|
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
|
-
|
|
84
|
-
|
|
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 (!
|
|
111
|
+
if (!isArrayClause) {
|
|
112
|
+
return [clause];
|
|
113
|
+
} else if (!clause.length) {
|
|
87
114
|
return;
|
|
88
115
|
}
|
|
89
|
-
clause.forEach(
|
|
90
|
-
if (!
|
|
116
|
+
clause.forEach((element, index) => {
|
|
117
|
+
if (!element || typeof element !== 'string') {
|
|
91
118
|
throw new InvalidArgumentError(
|
|
92
|
-
'
|
|
93
|
-
'
|
|
94
|
-
|
|
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
|
});
|