@e22m4u/js-repository 0.4.0 → 0.5.0
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/README.md +479 -61
- package/dist/cjs/index.cjs +319 -270
- package/package.json +1 -1
- package/src/adapter/adapter-loader.js +1 -1
- package/src/adapter/adapter-loader.spec.js +1 -1
- package/src/adapter/decorator/data-sanitizing-decorator.js +1 -1
- package/src/adapter/decorator/data-transformation-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/adapter/decorator/property-uniqueness-decorator.js +1 -1
- package/src/definition/datasource/datasource-definition-validator.js +3 -3
- package/src/definition/datasource/datasource-definition-validator.spec.js +3 -3
- package/src/definition/model/model-data-sanitizer.js +2 -2
- package/src/definition/model/model-data-transformer.js +71 -13
- package/src/definition/model/model-data-transformer.spec.js +2073 -407
- package/src/definition/model/model-data-validator.js +125 -37
- package/src/definition/model/model-data-validator.spec.js +2138 -440
- package/src/definition/model/model-definition-utils.js +5 -5
- package/src/definition/model/model-definition-utils.spec.js +7 -7
- package/src/definition/model/model-definition-validator.js +7 -7
- package/src/definition/model/model-definition-validator.spec.js +10 -7
- package/src/definition/model/properties/properties-definition-validator.js +129 -54
- package/src/definition/model/properties/properties-definition-validator.spec.js +85 -25
- package/src/definition/model/properties/property-transformer/builtin/index.d.ts +0 -1
- package/src/definition/model/properties/property-transformer/builtin/index.js +0 -1
- package/src/definition/model/properties/property-transformer/builtin/to-lower-case-transformer.d.ts +1 -1
- package/src/definition/model/properties/property-transformer/builtin/to-lower-case-transformer.js +1 -1
- package/src/definition/model/properties/property-transformer/builtin/to-lower-case-transformer.spec.js +1 -1
- package/src/definition/model/properties/property-transformer/builtin/to-upper-case-transformer.d.ts +1 -1
- package/src/definition/model/properties/property-transformer/builtin/to-upper-case-transformer.js +1 -1
- package/src/definition/model/properties/property-transformer/builtin/to-upper-case-transformer.spec.js +1 -1
- package/src/definition/model/properties/property-transformer/builtin/trim-transformer.js +1 -1
- package/src/definition/model/properties/property-transformer/builtin/trim-transformer.spec.js +1 -1
- package/src/definition/model/properties/property-transformer/property-transformer-registry.js +2 -4
- package/src/definition/model/properties/property-transformer/property-transformer-registry.spec.js +2 -4
- package/src/definition/model/properties/property-transformer/property-transformer.d.ts +2 -2
- package/src/definition/model/properties/property-uniqueness-validator.js +4 -4
- package/src/definition/model/properties/property-uniqueness-validator.spec.js +4 -4
- package/src/definition/model/properties/property-validator/builtin/max-length-validator.d.ts +1 -1
- package/src/definition/model/properties/property-validator/builtin/max-length-validator.js +2 -2
- package/src/definition/model/properties/property-validator/builtin/max-length-validator.spec.js +2 -2
- package/src/definition/model/properties/property-validator/builtin/min-length-validator.d.ts +1 -1
- package/src/definition/model/properties/property-validator/builtin/min-length-validator.js +2 -2
- package/src/definition/model/properties/property-validator/builtin/min-length-validator.spec.js +2 -2
- package/src/definition/model/properties/property-validator/builtin/regexp-validator.d.ts +1 -1
- package/src/definition/model/properties/property-validator/builtin/regexp-validator.js +2 -2
- package/src/definition/model/properties/property-validator/builtin/regexp-validator.spec.js +2 -2
- package/src/definition/model/properties/property-validator/property-validator-registry.js +2 -2
- package/src/definition/model/properties/property-validator/property-validator-registry.spec.js +2 -2
- package/src/definition/model/properties/property-validator/property-validator.d.ts +2 -2
- package/src/definition/model/relations/relations-definition-validator.js +23 -23
- package/src/definition/model/relations/relations-definition-validator.spec.js +24 -24
- 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 +5 -5
- package/src/filter/fields-clause-tool.spec.js +16 -16
- package/src/filter/include-clause-tool.js +6 -6
- package/src/filter/include-clause-tool.spec.js +2 -2
- package/src/filter/operator-clause-tool.js +13 -13
- package/src/filter/operator-clause-tool.spec.js +13 -13
- package/src/filter/order-clause-tool.js +3 -3
- package/src/filter/order-clause-tool.spec.js +4 -4
- package/src/filter/slice-clause-tool.js +5 -5
- package/src/filter/slice-clause-tool.spec.js +5 -5
- package/src/filter/where-clause-tool.js +4 -4
- package/src/filter/where-clause-tool.spec.js +3 -3
- package/src/relations/belongs-to-resolver.js +14 -14
- package/src/relations/belongs-to-resolver.spec.js +14 -14
- package/src/relations/has-many-resolver.js +22 -22
- package/src/relations/has-many-resolver.spec.js +23 -23
- package/src/relations/has-one-resolver.js +22 -22
- package/src/relations/has-one-resolver.spec.js +23 -23
- package/src/relations/references-many-resolver.js +7 -7
- package/src/relations/references-many-resolver.spec.js +7 -7
- package/src/repository/repository-registry.js +1 -1
- package/src/utils/exclude-object-keys.js +1 -1
- package/src/utils/exclude-object-keys.spec.js +1 -1
- 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 +3 -3
- package/src/utils/select-object-keys.spec.js +3 -3
- package/src/definition/model/properties/property-transformer/builtin/to-title-case-transformer.d.ts +0 -6
- package/src/definition/model/properties/property-transformer/builtin/to-title-case-transformer.js +0 -22
- package/src/definition/model/properties/property-transformer/builtin/to-title-case-transformer.spec.js +0 -41
|
@@ -28,7 +28,7 @@ describe('PropertiesDefinitionValidator', function () {
|
|
|
28
28
|
const error = v =>
|
|
29
29
|
format(
|
|
30
30
|
'The first argument of PropertiesDefinitionValidator.validate ' +
|
|
31
|
-
'should be a non-empty String, but %s given.',
|
|
31
|
+
'should be a non-empty String, but %s was given.',
|
|
32
32
|
v,
|
|
33
33
|
);
|
|
34
34
|
expect(validate('')).to.throw(error('""'));
|
|
@@ -47,7 +47,7 @@ describe('PropertiesDefinitionValidator', function () {
|
|
|
47
47
|
const error = v =>
|
|
48
48
|
format(
|
|
49
49
|
'The provided option "properties" of the model "model" ' +
|
|
50
|
-
'should be an Object, but %s given.',
|
|
50
|
+
'should be an Object, but %s was given.',
|
|
51
51
|
v,
|
|
52
52
|
);
|
|
53
53
|
expect(validate('str')).to.throw(error('"str"'));
|
|
@@ -65,7 +65,7 @@ describe('PropertiesDefinitionValidator', function () {
|
|
|
65
65
|
const error = v =>
|
|
66
66
|
format(
|
|
67
67
|
'The property name of the model "model" should be ' +
|
|
68
|
-
'a non-empty String, but %s given.',
|
|
68
|
+
'a non-empty String, but %s was given.',
|
|
69
69
|
v,
|
|
70
70
|
);
|
|
71
71
|
expect(validate({['']: {}})).to.throw(error('""'));
|
|
@@ -77,7 +77,7 @@ describe('PropertiesDefinitionValidator', function () {
|
|
|
77
77
|
const error = v =>
|
|
78
78
|
format(
|
|
79
79
|
'The property "foo" of the model "model" should have ' +
|
|
80
|
-
'a property definition, but %s given.',
|
|
80
|
+
'a property definition, but %s was given.',
|
|
81
81
|
v,
|
|
82
82
|
);
|
|
83
83
|
expect(validate(undefined)).to.throw(error('undefined'));
|
|
@@ -91,7 +91,7 @@ describe('PropertiesDefinitionValidator', function () {
|
|
|
91
91
|
const error = v =>
|
|
92
92
|
format(
|
|
93
93
|
'In case of a short property definition, the property "foo" ' +
|
|
94
|
-
'of the model "model" should have one of data types: %l, but %s given.',
|
|
94
|
+
'of the model "model" should have one of data types: %l, but %s was given.',
|
|
95
95
|
Object.values(DataType),
|
|
96
96
|
v,
|
|
97
97
|
);
|
|
@@ -104,7 +104,7 @@ describe('PropertiesDefinitionValidator', function () {
|
|
|
104
104
|
const error = v =>
|
|
105
105
|
format(
|
|
106
106
|
'In case of a full property definition, the property "foo" ' +
|
|
107
|
-
'of the model "model" should be an Object, but %s given.',
|
|
107
|
+
'of the model "model" should be an Object, but %s was given.',
|
|
108
108
|
v,
|
|
109
109
|
);
|
|
110
110
|
expect(validate(10)).to.throw(error('10'));
|
|
@@ -118,7 +118,7 @@ describe('PropertiesDefinitionValidator', function () {
|
|
|
118
118
|
const error = v =>
|
|
119
119
|
format(
|
|
120
120
|
'The property "foo" of the model "model" requires the option "type" ' +
|
|
121
|
-
'to have one of data types: %l, but %s given.',
|
|
121
|
+
'to have one of data types: %l, but %s was given.',
|
|
122
122
|
Object.values(DataType),
|
|
123
123
|
v,
|
|
124
124
|
);
|
|
@@ -141,7 +141,7 @@ describe('PropertiesDefinitionValidator', function () {
|
|
|
141
141
|
const error = v =>
|
|
142
142
|
format(
|
|
143
143
|
'The provided option "itemType" of the property "foo" in the model "model" ' +
|
|
144
|
-
'should have one of data types: %l, but %s given.',
|
|
144
|
+
'should have one of data types: %l, but %s was given.',
|
|
145
145
|
Object.values(DataType),
|
|
146
146
|
v,
|
|
147
147
|
);
|
|
@@ -165,7 +165,7 @@ describe('PropertiesDefinitionValidator', function () {
|
|
|
165
165
|
const error = v =>
|
|
166
166
|
format(
|
|
167
167
|
'The provided option "itemModel" of the property "foo" ' +
|
|
168
|
-
'in the model "model" should be a String, but %s given.',
|
|
168
|
+
'in the model "model" should be a String, but %s was given.',
|
|
169
169
|
v,
|
|
170
170
|
);
|
|
171
171
|
expect(validate(10)).to.throw(error('10'));
|
|
@@ -186,7 +186,7 @@ describe('PropertiesDefinitionValidator', function () {
|
|
|
186
186
|
const error = v =>
|
|
187
187
|
format(
|
|
188
188
|
'The provided option "model" of the property "foo" in the model "model" ' +
|
|
189
|
-
'should be a String, but %s given.',
|
|
189
|
+
'should be a String, but %s was given.',
|
|
190
190
|
v,
|
|
191
191
|
);
|
|
192
192
|
expect(validate(10)).to.throw(error('10'));
|
|
@@ -207,7 +207,7 @@ describe('PropertiesDefinitionValidator', function () {
|
|
|
207
207
|
const error = v =>
|
|
208
208
|
format(
|
|
209
209
|
'The provided option "primaryKey" of the property "foo" in the model "model" ' +
|
|
210
|
-
'should be a Boolean, but %s given.',
|
|
210
|
+
'should be a Boolean, but %s was given.',
|
|
211
211
|
v,
|
|
212
212
|
);
|
|
213
213
|
expect(validate(10)).to.throw(error('10'));
|
|
@@ -228,7 +228,7 @@ describe('PropertiesDefinitionValidator', function () {
|
|
|
228
228
|
const error = v =>
|
|
229
229
|
format(
|
|
230
230
|
'The provided option "columnName" of the property "foo" in the model "model" ' +
|
|
231
|
-
'should be a String, but %s given.',
|
|
231
|
+
'should be a String, but %s was given.',
|
|
232
232
|
v,
|
|
233
233
|
);
|
|
234
234
|
expect(validate(10)).to.throw(error('10'));
|
|
@@ -249,7 +249,7 @@ describe('PropertiesDefinitionValidator', function () {
|
|
|
249
249
|
const error = v =>
|
|
250
250
|
format(
|
|
251
251
|
'The provided option "columnType" of the property "foo" in the model "model" ' +
|
|
252
|
-
'should be a String, but %s given.',
|
|
252
|
+
'should be a String, but %s was given.',
|
|
253
253
|
v,
|
|
254
254
|
);
|
|
255
255
|
expect(validate(10)).to.throw(error('10'));
|
|
@@ -270,7 +270,7 @@ describe('PropertiesDefinitionValidator', function () {
|
|
|
270
270
|
const error = v =>
|
|
271
271
|
format(
|
|
272
272
|
'The provided option "required" of the property "foo" in the model "model" ' +
|
|
273
|
-
'should be a Boolean, but %s given.',
|
|
273
|
+
'should be a Boolean, but %s was given.',
|
|
274
274
|
v,
|
|
275
275
|
);
|
|
276
276
|
expect(validate('str')).to.throw(error('"str"'));
|
|
@@ -426,7 +426,7 @@ describe('PropertiesDefinitionValidator', function () {
|
|
|
426
426
|
expect(V.validate).to.have.been.called.with.exactly('model', propDefs);
|
|
427
427
|
});
|
|
428
428
|
|
|
429
|
-
it('the option "validate" should have a non-empty String, an Array
|
|
429
|
+
it('the option "validate" should have a non-empty String, a Function, an Array or an Object', function () {
|
|
430
430
|
const validate = v => () => {
|
|
431
431
|
const foo = {
|
|
432
432
|
type: DataType.ANY,
|
|
@@ -436,9 +436,10 @@ describe('PropertiesDefinitionValidator', function () {
|
|
|
436
436
|
};
|
|
437
437
|
const error = v =>
|
|
438
438
|
format(
|
|
439
|
-
'The provided option "validate"
|
|
440
|
-
'should be a
|
|
441
|
-
'
|
|
439
|
+
'The provided option "validate" for the property "foo" in the model "model" ' +
|
|
440
|
+
'should be either a validator name, a validator function, an array ' +
|
|
441
|
+
'of validator names or functions, or an object mapping validator ' +
|
|
442
|
+
'names to their arguments, but %s was given.',
|
|
442
443
|
v,
|
|
443
444
|
);
|
|
444
445
|
expect(validate('')).to.throw(error('""'));
|
|
@@ -446,9 +447,10 @@ describe('PropertiesDefinitionValidator', function () {
|
|
|
446
447
|
expect(validate(0)).to.throw(error('0'));
|
|
447
448
|
expect(validate(true)).to.throw(error('true'));
|
|
448
449
|
expect(validate(false)).to.throw(error('false'));
|
|
449
|
-
expect(validate(() => undefined)).to.throw(error('Function'));
|
|
450
450
|
validate('myValidator')();
|
|
451
|
+
validate(() => true)();
|
|
451
452
|
validate(['myValidator'])();
|
|
453
|
+
validate([() => true])();
|
|
452
454
|
validate([])();
|
|
453
455
|
validate({myValidator: true})();
|
|
454
456
|
validate({})();
|
|
@@ -456,6 +458,34 @@ describe('PropertiesDefinitionValidator', function () {
|
|
|
456
458
|
validate(undefined)();
|
|
457
459
|
});
|
|
458
460
|
|
|
461
|
+
it('the option "validate" with an Array value requires elements to be a non-empty String or a Function', function () {
|
|
462
|
+
const validate = v => () => {
|
|
463
|
+
const foo = {
|
|
464
|
+
type: DataType.ANY,
|
|
465
|
+
validate: [v],
|
|
466
|
+
};
|
|
467
|
+
S.validate('model', {foo});
|
|
468
|
+
};
|
|
469
|
+
const error = v =>
|
|
470
|
+
format(
|
|
471
|
+
'The provided option "validate" for the property "foo" in the model "model" ' +
|
|
472
|
+
'has an Array value that should contain validator names or validator functions, ' +
|
|
473
|
+
'but %s was given.',
|
|
474
|
+
v,
|
|
475
|
+
);
|
|
476
|
+
expect(validate('')).to.throw(error('""'));
|
|
477
|
+
expect(validate(10)).to.throw(error('10'));
|
|
478
|
+
expect(validate(0)).to.throw(error('0'));
|
|
479
|
+
expect(validate(true)).to.throw(error('true'));
|
|
480
|
+
expect(validate(false)).to.throw(error('false'));
|
|
481
|
+
expect(validate([1, 2, 3])).to.throw(error('Array'));
|
|
482
|
+
expect(validate({foo: 'bar'})).to.throw(error('Object'));
|
|
483
|
+
expect(validate(null)).to.throw(error('null'));
|
|
484
|
+
expect(validate(undefined)).to.throw(error('undefined'));
|
|
485
|
+
validate('myValidator')();
|
|
486
|
+
validate(() => true)();
|
|
487
|
+
});
|
|
488
|
+
|
|
459
489
|
it('the option "validate" requires only existing validator names', function () {
|
|
460
490
|
const validate = v => () => {
|
|
461
491
|
const foo = {
|
|
@@ -473,7 +503,7 @@ describe('PropertiesDefinitionValidator', function () {
|
|
|
473
503
|
validate({myValidator: true})();
|
|
474
504
|
});
|
|
475
505
|
|
|
476
|
-
it('the option "transform" should have a non-empty String, an Array
|
|
506
|
+
it('the option "transform" should have a non-empty String, a Function, an Array or an Object', function () {
|
|
477
507
|
const validate = v => () => {
|
|
478
508
|
const foo = {
|
|
479
509
|
type: DataType.ANY,
|
|
@@ -483,9 +513,10 @@ describe('PropertiesDefinitionValidator', function () {
|
|
|
483
513
|
};
|
|
484
514
|
const error = v =>
|
|
485
515
|
format(
|
|
486
|
-
'The provided option "transform"
|
|
487
|
-
'should be a
|
|
488
|
-
'
|
|
516
|
+
'The provided option "transform" for the property "foo" in the model "model" ' +
|
|
517
|
+
'should be either a transformer name, a transformer function, an array ' +
|
|
518
|
+
'of transformer names or functions, or an object mapping transformer ' +
|
|
519
|
+
'names to their arguments, but %s was given.',
|
|
489
520
|
v,
|
|
490
521
|
);
|
|
491
522
|
expect(validate('')).to.throw(error('""'));
|
|
@@ -493,9 +524,10 @@ describe('PropertiesDefinitionValidator', function () {
|
|
|
493
524
|
expect(validate(0)).to.throw(error('0'));
|
|
494
525
|
expect(validate(true)).to.throw(error('true'));
|
|
495
526
|
expect(validate(false)).to.throw(error('false'));
|
|
496
|
-
expect(validate(() => undefined)).to.throw(error('Function'));
|
|
497
527
|
validate('myTransformer')();
|
|
528
|
+
validate(v => v)();
|
|
498
529
|
validate(['myTransformer'])();
|
|
530
|
+
validate([v => v])();
|
|
499
531
|
validate([])();
|
|
500
532
|
validate({myTransformer: true})();
|
|
501
533
|
validate({})();
|
|
@@ -503,6 +535,34 @@ describe('PropertiesDefinitionValidator', function () {
|
|
|
503
535
|
validate(undefined)();
|
|
504
536
|
});
|
|
505
537
|
|
|
538
|
+
it('the option "transform" with an Array value requires elements to be a non-empty String or a Function', function () {
|
|
539
|
+
const validate = v => () => {
|
|
540
|
+
const foo = {
|
|
541
|
+
type: DataType.ANY,
|
|
542
|
+
transform: [v],
|
|
543
|
+
};
|
|
544
|
+
S.validate('model', {foo});
|
|
545
|
+
};
|
|
546
|
+
const error = v =>
|
|
547
|
+
format(
|
|
548
|
+
'The provided option "transform" for the property "foo" in the model "model" ' +
|
|
549
|
+
'has an Array value that should contain transformer names or transformer functions, ' +
|
|
550
|
+
'but %s was given.',
|
|
551
|
+
v,
|
|
552
|
+
);
|
|
553
|
+
expect(validate('')).to.throw(error('""'));
|
|
554
|
+
expect(validate(10)).to.throw(error('10'));
|
|
555
|
+
expect(validate(0)).to.throw(error('0'));
|
|
556
|
+
expect(validate(true)).to.throw(error('true'));
|
|
557
|
+
expect(validate(false)).to.throw(error('false'));
|
|
558
|
+
expect(validate([1, 2, 3])).to.throw(error('Array'));
|
|
559
|
+
expect(validate({foo: 'bar'})).to.throw(error('Object'));
|
|
560
|
+
expect(validate(null)).to.throw(error('null'));
|
|
561
|
+
expect(validate(undefined)).to.throw(error('undefined'));
|
|
562
|
+
validate('myTransformer')();
|
|
563
|
+
validate(v => v)();
|
|
564
|
+
});
|
|
565
|
+
|
|
506
566
|
it('the option "transform" requires only existing transformer names', function () {
|
|
507
567
|
const validate = v => () => {
|
|
508
568
|
const foo = {
|
|
@@ -531,7 +591,7 @@ describe('PropertiesDefinitionValidator', function () {
|
|
|
531
591
|
const error = v =>
|
|
532
592
|
format(
|
|
533
593
|
'The provided option "unique" of the property "foo" in the model "model" ' +
|
|
534
|
-
'should be a Boolean or one of values: %l, but %s given.',
|
|
594
|
+
'should be a Boolean or one of values: %l, but %s was given.',
|
|
535
595
|
Object.values(PropertyUniqueness),
|
|
536
596
|
v,
|
|
537
597
|
);
|
package/src/definition/model/properties/property-transformer/builtin/to-lower-case-transformer.js
CHANGED
|
@@ -12,7 +12,7 @@ export function toLowerCaseTransformer(value, options, context) {
|
|
|
12
12
|
if (value == null) return value;
|
|
13
13
|
if (typeof value === 'string') return value.toLowerCase();
|
|
14
14
|
throw new InvalidArgumentError(
|
|
15
|
-
'The property transformer %v requires a String value, but %v given.',
|
|
15
|
+
'The property transformer %v requires a String value, but %v was given.',
|
|
16
16
|
context.transformerName,
|
|
17
17
|
value,
|
|
18
18
|
);
|
|
@@ -22,7 +22,7 @@ describe('toLowerCaseTransformer', function () {
|
|
|
22
22
|
});
|
|
23
23
|
const error = v =>
|
|
24
24
|
format(
|
|
25
|
-
'The property transformer "toLowerCase" requires a String value, but %s given.',
|
|
25
|
+
'The property transformer "toLowerCase" requires a String value, but %s was given.',
|
|
26
26
|
v,
|
|
27
27
|
);
|
|
28
28
|
expect(throwable(10)).to.throw(error('10'));
|
package/src/definition/model/properties/property-transformer/builtin/to-upper-case-transformer.js
CHANGED
|
@@ -12,7 +12,7 @@ export function toUpperCaseTransformer(value, options, context) {
|
|
|
12
12
|
if (value == null) return value;
|
|
13
13
|
if (typeof value === 'string') return value.toUpperCase();
|
|
14
14
|
throw new InvalidArgumentError(
|
|
15
|
-
'The property transformer %v requires a String value, but %v given.',
|
|
15
|
+
'The property transformer %v requires a String value, but %v was given.',
|
|
16
16
|
context.transformerName,
|
|
17
17
|
value,
|
|
18
18
|
);
|
|
@@ -22,7 +22,7 @@ describe('toUpperCaseTransformer', function () {
|
|
|
22
22
|
});
|
|
23
23
|
const error = v =>
|
|
24
24
|
format(
|
|
25
|
-
'The property transformer "toUpperCase" requires a String value, but %s given.',
|
|
25
|
+
'The property transformer "toUpperCase" requires a String value, but %s was given.',
|
|
26
26
|
v,
|
|
27
27
|
);
|
|
28
28
|
expect(throwable(10)).to.throw(error('10'));
|
|
@@ -12,7 +12,7 @@ export function trimTransformer(value, options, context) {
|
|
|
12
12
|
if (value == null) return value;
|
|
13
13
|
if (typeof value === 'string') return value.trim();
|
|
14
14
|
throw new InvalidArgumentError(
|
|
15
|
-
'The property transformer %v requires a String value, but %v given.',
|
|
15
|
+
'The property transformer %v requires a String value, but %v was given.',
|
|
16
16
|
context.transformerName,
|
|
17
17
|
value,
|
|
18
18
|
);
|
package/src/definition/model/properties/property-transformer/builtin/trim-transformer.spec.js
CHANGED
|
@@ -22,7 +22,7 @@ describe('trimTransformer', function () {
|
|
|
22
22
|
});
|
|
23
23
|
const error = v =>
|
|
24
24
|
format(
|
|
25
|
-
'The property transformer "trim" requires a String value, but %s given.',
|
|
25
|
+
'The property transformer "trim" requires a String value, but %s was given.',
|
|
26
26
|
v,
|
|
27
27
|
);
|
|
28
28
|
expect(throwable(10)).to.throw(error('10'));
|
package/src/definition/model/properties/property-transformer/property-transformer-registry.js
CHANGED
|
@@ -2,7 +2,6 @@ import {Service} from '@e22m4u/js-service';
|
|
|
2
2
|
import {trimTransformer} from './builtin/index.js';
|
|
3
3
|
import {toUpperCaseTransformer} from './builtin/index.js';
|
|
4
4
|
import {toLowerCaseTransformer} from './builtin/index.js';
|
|
5
|
-
import {toTitleCaseTransformer} from './builtin/index.js';
|
|
6
5
|
import {InvalidArgumentError} from '../../../../errors/index.js';
|
|
7
6
|
|
|
8
7
|
/**
|
|
@@ -18,7 +17,6 @@ export class PropertyTransformerRegistry extends Service {
|
|
|
18
17
|
trim: trimTransformer,
|
|
19
18
|
toUpperCase: toUpperCaseTransformer,
|
|
20
19
|
toLowerCase: toLowerCaseTransformer,
|
|
21
|
-
toTitleCase: toTitleCaseTransformer,
|
|
22
20
|
};
|
|
23
21
|
|
|
24
22
|
/**
|
|
@@ -32,7 +30,7 @@ export class PropertyTransformerRegistry extends Service {
|
|
|
32
30
|
if (!name || typeof name !== 'string')
|
|
33
31
|
throw new InvalidArgumentError(
|
|
34
32
|
'A name of the property transformer must ' +
|
|
35
|
-
'be a non-empty String, but %v given.',
|
|
33
|
+
'be a non-empty String, but %v was given.',
|
|
36
34
|
name,
|
|
37
35
|
);
|
|
38
36
|
if (name in this._transformers)
|
|
@@ -42,7 +40,7 @@ export class PropertyTransformerRegistry extends Service {
|
|
|
42
40
|
);
|
|
43
41
|
if (typeof transformer !== 'function')
|
|
44
42
|
throw new InvalidArgumentError(
|
|
45
|
-
'The property transformer %v must be a Function, but %v given.',
|
|
43
|
+
'The property transformer %v must be a Function, but %v was given.',
|
|
46
44
|
name,
|
|
47
45
|
transformer,
|
|
48
46
|
);
|
package/src/definition/model/properties/property-transformer/property-transformer-registry.spec.js
CHANGED
|
@@ -3,7 +3,6 @@ import {format} from '@e22m4u/js-format';
|
|
|
3
3
|
import {trimTransformer} from './builtin/index.js';
|
|
4
4
|
import {toUpperCaseTransformer} from './builtin/index.js';
|
|
5
5
|
import {toLowerCaseTransformer} from './builtin/index.js';
|
|
6
|
-
import {toTitleCaseTransformer} from './builtin/index.js';
|
|
7
6
|
import {PropertyTransformerRegistry} from './property-transformer-registry.js';
|
|
8
7
|
|
|
9
8
|
describe('PropertyTransformerRegistry', function () {
|
|
@@ -14,7 +13,6 @@ describe('PropertyTransformerRegistry', function () {
|
|
|
14
13
|
trim: trimTransformer,
|
|
15
14
|
toUpperCase: toUpperCaseTransformer,
|
|
16
15
|
toLowerCase: toLowerCaseTransformer,
|
|
17
|
-
toTitleCase: toTitleCaseTransformer,
|
|
18
16
|
});
|
|
19
17
|
});
|
|
20
18
|
|
|
@@ -32,7 +30,7 @@ describe('PropertyTransformerRegistry', function () {
|
|
|
32
30
|
const error = v =>
|
|
33
31
|
format(
|
|
34
32
|
'A name of the property transformer must ' +
|
|
35
|
-
'be a non-empty String, but %s given.',
|
|
33
|
+
'be a non-empty String, but %s was given.',
|
|
36
34
|
v,
|
|
37
35
|
);
|
|
38
36
|
expect(throwable('')).to.throw(error('""'));
|
|
@@ -61,7 +59,7 @@ describe('PropertyTransformerRegistry', function () {
|
|
|
61
59
|
const throwable = v => () => ptr.addTransformer('test', v);
|
|
62
60
|
const error = v =>
|
|
63
61
|
format(
|
|
64
|
-
'The property transformer "test" must be a Function, but %s given.',
|
|
62
|
+
'The property transformer "test" must be a Function, but %s was given.',
|
|
65
63
|
v,
|
|
66
64
|
);
|
|
67
65
|
expect(throwable('str')).to.throw(error('"str"'));
|
|
@@ -30,24 +30,24 @@ export class PropertyUniquenessValidator extends Service {
|
|
|
30
30
|
if (typeof countMethod !== 'function')
|
|
31
31
|
throw new InvalidArgumentError(
|
|
32
32
|
'The parameter "countMethod" of the PropertyUniquenessValidator ' +
|
|
33
|
-
'must be a Function, but %v given.',
|
|
33
|
+
'must be a Function, but %v was given.',
|
|
34
34
|
countMethod,
|
|
35
35
|
);
|
|
36
36
|
if (!methodName || typeof methodName !== 'string')
|
|
37
37
|
throw new InvalidArgumentError(
|
|
38
38
|
'The parameter "methodName" of the PropertyUniquenessValidator ' +
|
|
39
|
-
'must be a non-empty String, but %v given.',
|
|
39
|
+
'must be a non-empty String, but %v was given.',
|
|
40
40
|
methodName,
|
|
41
41
|
);
|
|
42
42
|
if (!modelName || typeof modelName !== 'string')
|
|
43
43
|
throw new InvalidArgumentError(
|
|
44
44
|
'The parameter "modelName" of the PropertyUniquenessValidator ' +
|
|
45
|
-
'must be a non-empty String, but %v given.',
|
|
45
|
+
'must be a non-empty String, but %v was given.',
|
|
46
46
|
modelName,
|
|
47
47
|
);
|
|
48
48
|
if (!isPureObject(modelData))
|
|
49
49
|
throw new InvalidArgumentError(
|
|
50
|
-
'The data of the model %v should be an Object, but %v given.',
|
|
50
|
+
'The data of the model %v should be an Object, but %v was given.',
|
|
51
51
|
modelName,
|
|
52
52
|
modelData,
|
|
53
53
|
);
|
|
@@ -25,7 +25,7 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
25
25
|
const error = v =>
|
|
26
26
|
format(
|
|
27
27
|
'The parameter "countMethod" of the PropertyUniquenessValidator ' +
|
|
28
|
-
'must be a Function, but %s given.',
|
|
28
|
+
'must be a Function, but %s was given.',
|
|
29
29
|
v,
|
|
30
30
|
);
|
|
31
31
|
await expect(throwable('str')).to.be.rejectedWith(error('"str"'));
|
|
@@ -60,7 +60,7 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
60
60
|
const error = v =>
|
|
61
61
|
format(
|
|
62
62
|
'The parameter "methodName" of the PropertyUniquenessValidator ' +
|
|
63
|
-
'must be a non-empty String, but %s given.',
|
|
63
|
+
'must be a non-empty String, but %s was given.',
|
|
64
64
|
v,
|
|
65
65
|
);
|
|
66
66
|
await expect(throwable('')).to.be.rejectedWith(error('""'));
|
|
@@ -95,7 +95,7 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
95
95
|
const error = v =>
|
|
96
96
|
format(
|
|
97
97
|
'The parameter "modelName" of the PropertyUniquenessValidator ' +
|
|
98
|
-
'must be a non-empty String, but %s given.',
|
|
98
|
+
'must be a non-empty String, but %s was given.',
|
|
99
99
|
v,
|
|
100
100
|
);
|
|
101
101
|
await expect(throwable('')).to.be.rejectedWith(error('""'));
|
|
@@ -129,7 +129,7 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
129
129
|
const throwable = v => puv.validate(() => 0, 'create', 'model', v);
|
|
130
130
|
const error = v =>
|
|
131
131
|
format(
|
|
132
|
-
'The data of the model "model" should be an Object, but %s given.',
|
|
132
|
+
'The data of the model "model" should be an Object, but %s was given.',
|
|
133
133
|
v,
|
|
134
134
|
);
|
|
135
135
|
await expect(throwable('str')).to.be.rejectedWith(error('"str"'));
|
|
@@ -13,7 +13,7 @@ export function maxLengthValidator(value, options, context) {
|
|
|
13
13
|
if (typeof options !== 'number')
|
|
14
14
|
throw new InvalidArgumentError(
|
|
15
15
|
'The validator %v requires the "options" argument ' +
|
|
16
|
-
'as a Number, but %v given.',
|
|
16
|
+
'as a Number, but %v was given.',
|
|
17
17
|
context.validatorName,
|
|
18
18
|
options,
|
|
19
19
|
);
|
|
@@ -21,7 +21,7 @@ export function maxLengthValidator(value, options, context) {
|
|
|
21
21
|
return value.length <= options;
|
|
22
22
|
throw new InvalidArgumentError(
|
|
23
23
|
'The property validator %v requires a String ' +
|
|
24
|
-
'or an Array value, but %v given.',
|
|
24
|
+
'or an Array value, but %v was given.',
|
|
25
25
|
context.validatorName,
|
|
26
26
|
value,
|
|
27
27
|
);
|
package/src/definition/model/properties/property-validator/builtin/max-length-validator.spec.js
CHANGED
|
@@ -23,7 +23,7 @@ describe('maxLengthValidator', function () {
|
|
|
23
23
|
const error = v =>
|
|
24
24
|
format(
|
|
25
25
|
'The property validator "myValidator" requires a String ' +
|
|
26
|
-
'or an Array value, but %s given.',
|
|
26
|
+
'or an Array value, but %s was given.',
|
|
27
27
|
v,
|
|
28
28
|
);
|
|
29
29
|
expect(throwable(10)).to.throw(error('10'));
|
|
@@ -48,7 +48,7 @@ describe('maxLengthValidator', function () {
|
|
|
48
48
|
const error = v =>
|
|
49
49
|
format(
|
|
50
50
|
'The validator "myValidator" requires the "options" argument ' +
|
|
51
|
-
'as a Number, but %s given.',
|
|
51
|
+
'as a Number, but %s was given.',
|
|
52
52
|
v,
|
|
53
53
|
);
|
|
54
54
|
expect(throwable('str')).to.throw(error('"str"'));
|
|
@@ -13,7 +13,7 @@ export function minLengthValidator(value, options, context) {
|
|
|
13
13
|
if (typeof options !== 'number')
|
|
14
14
|
throw new InvalidArgumentError(
|
|
15
15
|
'The validator %v requires the "options" argument ' +
|
|
16
|
-
'as a Number, but %v given.',
|
|
16
|
+
'as a Number, but %v was given.',
|
|
17
17
|
context.validatorName,
|
|
18
18
|
options,
|
|
19
19
|
);
|
|
@@ -21,7 +21,7 @@ export function minLengthValidator(value, options, context) {
|
|
|
21
21
|
return value.length >= options;
|
|
22
22
|
throw new InvalidArgumentError(
|
|
23
23
|
'The property validator %v requires a String ' +
|
|
24
|
-
'or an Array value, but %v given.',
|
|
24
|
+
'or an Array value, but %v was given.',
|
|
25
25
|
context.validatorName,
|
|
26
26
|
value,
|
|
27
27
|
);
|
package/src/definition/model/properties/property-validator/builtin/min-length-validator.spec.js
CHANGED
|
@@ -23,7 +23,7 @@ describe('minLengthValidator', function () {
|
|
|
23
23
|
const error = v =>
|
|
24
24
|
format(
|
|
25
25
|
'The property validator "myValidator" requires a String ' +
|
|
26
|
-
'or an Array value, but %s given.',
|
|
26
|
+
'or an Array value, but %s was given.',
|
|
27
27
|
v,
|
|
28
28
|
);
|
|
29
29
|
expect(throwable(10)).to.throw(error('10'));
|
|
@@ -48,7 +48,7 @@ describe('minLengthValidator', function () {
|
|
|
48
48
|
const error = v =>
|
|
49
49
|
format(
|
|
50
50
|
'The validator "myValidator" requires the "options" argument ' +
|
|
51
|
-
'as a Number, but %s given.',
|
|
51
|
+
'as a Number, but %s was given.',
|
|
52
52
|
v,
|
|
53
53
|
);
|
|
54
54
|
expect(throwable('str')).to.throw(error('"str"'));
|
|
@@ -14,7 +14,7 @@ export function regexpValidator(value, options, context) {
|
|
|
14
14
|
if (typeof options !== 'string' && !(options instanceof RegExp))
|
|
15
15
|
throw new InvalidArgumentError(
|
|
16
16
|
'The validator %v requires the "options" argument ' +
|
|
17
|
-
'as a String or RegExp, but %v given.',
|
|
17
|
+
'as a String or RegExp, but %v was given.',
|
|
18
18
|
context.validatorName,
|
|
19
19
|
options,
|
|
20
20
|
);
|
|
@@ -23,7 +23,7 @@ export function regexpValidator(value, options, context) {
|
|
|
23
23
|
return regexp.test(value);
|
|
24
24
|
}
|
|
25
25
|
throw new InvalidArgumentError(
|
|
26
|
-
'The property validator %v requires ' + 'a String value, but %v given.',
|
|
26
|
+
'The property validator %v requires ' + 'a String value, but %v was given.',
|
|
27
27
|
context.validatorName,
|
|
28
28
|
value,
|
|
29
29
|
);
|
|
@@ -23,7 +23,7 @@ describe('regexpValidator', function () {
|
|
|
23
23
|
const error = v =>
|
|
24
24
|
format(
|
|
25
25
|
'The property validator "myValidator" requires ' +
|
|
26
|
-
'a String value, but %s given.',
|
|
26
|
+
'a String value, but %s was given.',
|
|
27
27
|
v,
|
|
28
28
|
);
|
|
29
29
|
expect(throwable(true)).to.throw(error('true'));
|
|
@@ -45,7 +45,7 @@ describe('regexpValidator', function () {
|
|
|
45
45
|
const error = v =>
|
|
46
46
|
format(
|
|
47
47
|
'The validator "myValidator" requires the "options" argument ' +
|
|
48
|
-
'as a String or RegExp, but %s given.',
|
|
48
|
+
'as a String or RegExp, but %s was given.',
|
|
49
49
|
v,
|
|
50
50
|
);
|
|
51
51
|
expect(throwable(true)).to.throw(error('true'));
|