@e22m4u/js-repository 0.3.3 → 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 +354 -277
- package/package.json +7 -7
- 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/definition-registry.js +12 -6
- package/src/definition/definition-registry.spec.js +173 -46
- 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 +5 -3
- package/src/repository/repository-registry.spec.js +39 -9
- package/src/utils/exclude-object-keys.js +1 -1
- package/src/utils/exclude-object-keys.spec.js +1 -1
- package/src/utils/index.d.ts +1 -0
- package/src/utils/index.js +1 -0
- package/src/utils/model-name-to-model-key.d.ts +6 -0
- package/src/utils/model-name-to-model-key.js +17 -0
- package/src/utils/model-name-to-model-key.spec.js +92 -0
- 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
|
@@ -317,7 +317,7 @@ export class ModelDefinitionUtils extends Service {
|
|
|
317
317
|
) {
|
|
318
318
|
throw new InvalidArgumentError(
|
|
319
319
|
'The argument "propDef" of the ModelDefinitionUtils.getDataTypeFromPropertyDefinition ' +
|
|
320
|
-
'should be an Object or the DataType enum, but %v given.',
|
|
320
|
+
'should be an Object or the DataType enum, but %v was given.',
|
|
321
321
|
propDef,
|
|
322
322
|
);
|
|
323
323
|
}
|
|
@@ -326,7 +326,7 @@ export class ModelDefinitionUtils extends Service {
|
|
|
326
326
|
if (!Object.values(DataType).includes(dataType))
|
|
327
327
|
throw new InvalidArgumentError(
|
|
328
328
|
'The given Object to the ModelDefinitionUtils.getDataTypeFromPropertyDefinition ' +
|
|
329
|
-
'should have the "type" property with one of values: %l, but %v given.',
|
|
329
|
+
'should have the "type" property with one of values: %l, but %v was given.',
|
|
330
330
|
Object.values(DataType),
|
|
331
331
|
propDef.type,
|
|
332
332
|
);
|
|
@@ -467,7 +467,7 @@ export class ModelDefinitionUtils extends Service {
|
|
|
467
467
|
if (!modelData || typeof modelData !== 'object' || Array.isArray(modelData))
|
|
468
468
|
throw new InvalidArgumentError(
|
|
469
469
|
'The second argument of ModelDefinitionUtils.excludeObjectKeysByRelationNames ' +
|
|
470
|
-
'should be an Object, but %v given.',
|
|
470
|
+
'should be an Object, but %v was given.',
|
|
471
471
|
modelData,
|
|
472
472
|
);
|
|
473
473
|
const relDefs = this.getRelationsDefinitionInBaseModelHierarchy(modelName);
|
|
@@ -487,14 +487,14 @@ export class ModelDefinitionUtils extends Service {
|
|
|
487
487
|
throw new InvalidArgumentError(
|
|
488
488
|
'Parameter "modelName" of ' +
|
|
489
489
|
'ModelDefinitionUtils.getModelNameOfPropertyValueIfDefined ' +
|
|
490
|
-
'requires a non-empty String, but %v given.',
|
|
490
|
+
'requires a non-empty String, but %v was given.',
|
|
491
491
|
modelName,
|
|
492
492
|
);
|
|
493
493
|
if (!propertyName || typeof propertyName !== 'string')
|
|
494
494
|
throw new InvalidArgumentError(
|
|
495
495
|
'Parameter "propertyName" of ' +
|
|
496
496
|
'ModelDefinitionUtils.getModelNameOfPropertyValueIfDefined ' +
|
|
497
|
-
'requires a non-empty String, but %v given.',
|
|
497
|
+
'requires a non-empty String, but %v was given.',
|
|
498
498
|
propertyName,
|
|
499
499
|
);
|
|
500
500
|
// если определение свойства не найдено,
|
|
@@ -1224,7 +1224,7 @@ describe('ModelDefinitionUtils', function () {
|
|
|
1224
1224
|
const error = v =>
|
|
1225
1225
|
format(
|
|
1226
1226
|
'The argument "propDef" of the ModelDefinitionUtils.getDataTypeFromPropertyDefinition ' +
|
|
1227
|
-
'should be an Object or the DataType enum, but %s given.',
|
|
1227
|
+
'should be an Object or the DataType enum, but %s was given.',
|
|
1228
1228
|
v,
|
|
1229
1229
|
);
|
|
1230
1230
|
expect(throwable('str')).to.throw(error('"str"'));
|
|
@@ -1247,7 +1247,7 @@ describe('ModelDefinitionUtils', function () {
|
|
|
1247
1247
|
const error = v =>
|
|
1248
1248
|
format(
|
|
1249
1249
|
'The given Object to the ModelDefinitionUtils.getDataTypeFromPropertyDefinition ' +
|
|
1250
|
-
'should have the "type" property with one of values: %l, but %s given.',
|
|
1250
|
+
'should have the "type" property with one of values: %l, but %s was given.',
|
|
1251
1251
|
Object.values(DataType),
|
|
1252
1252
|
v,
|
|
1253
1253
|
);
|
|
@@ -1927,7 +1927,7 @@ describe('ModelDefinitionUtils', function () {
|
|
|
1927
1927
|
const error = v =>
|
|
1928
1928
|
format(
|
|
1929
1929
|
'The second argument of ModelDefinitionUtils.excludeObjectKeysByRelationNames ' +
|
|
1930
|
-
'should be an Object, but %s given.',
|
|
1930
|
+
'should be an Object, but %s was given.',
|
|
1931
1931
|
v,
|
|
1932
1932
|
);
|
|
1933
1933
|
expect(throwable('')).to.throw(error('""'));
|
|
@@ -1968,7 +1968,7 @@ describe('ModelDefinitionUtils', function () {
|
|
|
1968
1968
|
format(
|
|
1969
1969
|
'Parameter "modelName" of ' +
|
|
1970
1970
|
'ModelDefinitionUtils.getModelNameOfPropertyValueIfDefined ' +
|
|
1971
|
-
'requires a non-empty String, but %s given.',
|
|
1971
|
+
'requires a non-empty String, but %s was given.',
|
|
1972
1972
|
v,
|
|
1973
1973
|
);
|
|
1974
1974
|
expect(throwable('')).to.throw(error('""'));
|
|
@@ -1997,7 +1997,7 @@ describe('ModelDefinitionUtils', function () {
|
|
|
1997
1997
|
format(
|
|
1998
1998
|
'Parameter "propertyName" of ' +
|
|
1999
1999
|
'ModelDefinitionUtils.getModelNameOfPropertyValueIfDefined ' +
|
|
2000
|
-
'requires a non-empty String, but %s given.',
|
|
2000
|
+
'requires a non-empty String, but %s was given.',
|
|
2001
2001
|
v,
|
|
2002
2002
|
);
|
|
2003
2003
|
expect(throwable('')).to.throw(error('""'));
|
|
@@ -2050,7 +2050,7 @@ describe('ModelDefinitionUtils', function () {
|
|
|
2050
2050
|
format(
|
|
2051
2051
|
'Parameter "modelName" of ' +
|
|
2052
2052
|
'ModelDefinitionUtils.getModelNameOfPropertyValueIfDefined ' +
|
|
2053
|
-
'requires a non-empty String, but %s given.',
|
|
2053
|
+
'requires a non-empty String, but %s was given.',
|
|
2054
2054
|
v,
|
|
2055
2055
|
);
|
|
2056
2056
|
expect(throwable('')).to.throw(error('""'));
|
|
@@ -2081,7 +2081,7 @@ describe('ModelDefinitionUtils', function () {
|
|
|
2081
2081
|
format(
|
|
2082
2082
|
'Parameter "propertyName" of ' +
|
|
2083
2083
|
'ModelDefinitionUtils.getModelNameOfPropertyValueIfDefined ' +
|
|
2084
|
-
'requires a non-empty String, but %s given.',
|
|
2084
|
+
'requires a non-empty String, but %s was given.',
|
|
2085
2085
|
v,
|
|
2086
2086
|
);
|
|
2087
2087
|
expect(throwable('')).to.throw(error('""'));
|
|
@@ -15,33 +15,33 @@ export class ModelDefinitionValidator extends Service {
|
|
|
15
15
|
validate(modelDef) {
|
|
16
16
|
if (!modelDef || typeof modelDef !== 'object' || Array.isArray(modelDef))
|
|
17
17
|
throw new InvalidArgumentError(
|
|
18
|
-
'The model definition should be an Object, but %v given.',
|
|
18
|
+
'The model definition should be an Object, but %v was given.',
|
|
19
19
|
modelDef,
|
|
20
20
|
);
|
|
21
21
|
if (!modelDef.name || typeof modelDef.name !== 'string')
|
|
22
22
|
throw new InvalidArgumentError(
|
|
23
23
|
'The model definition requires the option "name" ' +
|
|
24
|
-
'as a non-empty String, but %v given.',
|
|
24
|
+
'as a non-empty String, but %v was given.',
|
|
25
25
|
modelDef.name,
|
|
26
26
|
);
|
|
27
27
|
if (modelDef.datasource && typeof modelDef.datasource !== 'string')
|
|
28
28
|
throw new InvalidArgumentError(
|
|
29
29
|
'The provided option "datasource" of the model %v ' +
|
|
30
|
-
'should be a String, but %v given.',
|
|
30
|
+
'should be a String, but %v was given.',
|
|
31
31
|
modelDef.name,
|
|
32
32
|
modelDef.datasource,
|
|
33
33
|
);
|
|
34
34
|
if (modelDef.base && typeof modelDef.base !== 'string')
|
|
35
35
|
throw new InvalidArgumentError(
|
|
36
36
|
'The provided option "base" of the model %v ' +
|
|
37
|
-
'should be a String, but %v given.',
|
|
37
|
+
'should be a String, but %v was given.',
|
|
38
38
|
modelDef.name,
|
|
39
39
|
modelDef.base,
|
|
40
40
|
);
|
|
41
41
|
if (modelDef.tableName && typeof modelDef.tableName !== 'string')
|
|
42
42
|
throw new InvalidArgumentError(
|
|
43
43
|
'The provided option "tableName" of the model %v ' +
|
|
44
|
-
'should be a String, but %v given.',
|
|
44
|
+
'should be a String, but %v was given.',
|
|
45
45
|
modelDef.name,
|
|
46
46
|
modelDef.tableName,
|
|
47
47
|
);
|
|
@@ -52,7 +52,7 @@ export class ModelDefinitionValidator extends Service {
|
|
|
52
52
|
) {
|
|
53
53
|
throw new InvalidArgumentError(
|
|
54
54
|
'The provided option "properties" of the model %v ' +
|
|
55
|
-
'should be an Object, but %v given.',
|
|
55
|
+
'should be an Object, but %v was given.',
|
|
56
56
|
modelDef.name,
|
|
57
57
|
modelDef.properties,
|
|
58
58
|
);
|
|
@@ -69,7 +69,7 @@ export class ModelDefinitionValidator extends Service {
|
|
|
69
69
|
) {
|
|
70
70
|
throw new InvalidArgumentError(
|
|
71
71
|
'The provided option "relations" of the model %v ' +
|
|
72
|
-
'should be an Object, but %v given.',
|
|
72
|
+
'should be an Object, but %v was given.',
|
|
73
73
|
modelDef.name,
|
|
74
74
|
modelDef.relations,
|
|
75
75
|
);
|
|
@@ -17,7 +17,10 @@ describe('ModelDefinitionValidator', function () {
|
|
|
17
17
|
it('requires the given definition to be an object', function () {
|
|
18
18
|
const validate = v => () => S.validate(v);
|
|
19
19
|
const error = v =>
|
|
20
|
-
format(
|
|
20
|
+
format(
|
|
21
|
+
'The model definition should be an Object, but %s was given.',
|
|
22
|
+
v,
|
|
23
|
+
);
|
|
21
24
|
expect(validate('str')).to.throw(error('"str"'));
|
|
22
25
|
expect(validate(10)).to.throw(error('10'));
|
|
23
26
|
expect(validate(true)).to.throw(error('true'));
|
|
@@ -33,7 +36,7 @@ describe('ModelDefinitionValidator', function () {
|
|
|
33
36
|
const error = v =>
|
|
34
37
|
format(
|
|
35
38
|
'The model definition requires the option "name" ' +
|
|
36
|
-
'as a non-empty String, but %s given.',
|
|
39
|
+
'as a non-empty String, but %s was given.',
|
|
37
40
|
v,
|
|
38
41
|
);
|
|
39
42
|
expect(validate('')).to.throw(error('""'));
|
|
@@ -52,7 +55,7 @@ describe('ModelDefinitionValidator', function () {
|
|
|
52
55
|
const error = v =>
|
|
53
56
|
format(
|
|
54
57
|
'The provided option "datasource" of the model "model" ' +
|
|
55
|
-
'should be a String, but %s given.',
|
|
58
|
+
'should be a String, but %s was given.',
|
|
56
59
|
v,
|
|
57
60
|
);
|
|
58
61
|
expect(validate(10)).to.throw(error('10'));
|
|
@@ -67,7 +70,7 @@ describe('ModelDefinitionValidator', function () {
|
|
|
67
70
|
const error = v =>
|
|
68
71
|
format(
|
|
69
72
|
'The provided option "base" of the model "model" ' +
|
|
70
|
-
'should be a String, but %s given.',
|
|
73
|
+
'should be a String, but %s was given.',
|
|
71
74
|
v,
|
|
72
75
|
);
|
|
73
76
|
expect(validate(10)).to.throw(error('10'));
|
|
@@ -82,7 +85,7 @@ describe('ModelDefinitionValidator', function () {
|
|
|
82
85
|
const error = v =>
|
|
83
86
|
format(
|
|
84
87
|
'The provided option "tableName" of the model "model" ' +
|
|
85
|
-
'should be a String, but %s given.',
|
|
88
|
+
'should be a String, but %s was given.',
|
|
86
89
|
v,
|
|
87
90
|
);
|
|
88
91
|
expect(validate(10)).to.throw(error('10'));
|
|
@@ -97,7 +100,7 @@ describe('ModelDefinitionValidator', function () {
|
|
|
97
100
|
const error = v =>
|
|
98
101
|
format(
|
|
99
102
|
'The provided option "properties" of the model "model" ' +
|
|
100
|
-
'should be an Object, but %s given.',
|
|
103
|
+
'should be an Object, but %s was given.',
|
|
101
104
|
v,
|
|
102
105
|
);
|
|
103
106
|
expect(validate('str')).to.throw(error('"str"'));
|
|
@@ -112,7 +115,7 @@ describe('ModelDefinitionValidator', function () {
|
|
|
112
115
|
const error = v =>
|
|
113
116
|
format(
|
|
114
117
|
'The provided option "relations" of the model "model" ' +
|
|
115
|
-
'should be an Object, but %s given.',
|
|
118
|
+
'should be an Object, but %s was given.',
|
|
116
119
|
v,
|
|
117
120
|
);
|
|
118
121
|
expect(validate('str')).to.throw(error('"str"'));
|
|
@@ -21,13 +21,13 @@ export class PropertiesDefinitionValidator extends Service {
|
|
|
21
21
|
if (!modelName || typeof modelName !== 'string')
|
|
22
22
|
throw new InvalidArgumentError(
|
|
23
23
|
'The first argument of PropertiesDefinitionValidator.validate ' +
|
|
24
|
-
'should be a non-empty String, but %v given.',
|
|
24
|
+
'should be a non-empty String, but %v was given.',
|
|
25
25
|
modelName,
|
|
26
26
|
);
|
|
27
27
|
if (!propDefs || typeof propDefs !== 'object' || Array.isArray(propDefs)) {
|
|
28
28
|
throw new InvalidArgumentError(
|
|
29
29
|
'The provided option "properties" of the model %v ' +
|
|
30
|
-
'should be an Object, but %v given.',
|
|
30
|
+
'should be an Object, but %v was given.',
|
|
31
31
|
modelName,
|
|
32
32
|
propDefs,
|
|
33
33
|
);
|
|
@@ -54,20 +54,20 @@ export class PropertiesDefinitionValidator extends Service {
|
|
|
54
54
|
if (!modelName || typeof modelName !== 'string')
|
|
55
55
|
throw new InvalidArgumentError(
|
|
56
56
|
'The first argument of PropertiesDefinitionValidator._validateProperty ' +
|
|
57
|
-
'should be a non-empty String, but %v given.',
|
|
57
|
+
'should be a non-empty String, but %v was given.',
|
|
58
58
|
modelName,
|
|
59
59
|
);
|
|
60
60
|
if (!propName || typeof propName !== 'string')
|
|
61
61
|
throw new InvalidArgumentError(
|
|
62
62
|
'The property name of the model %v should be ' +
|
|
63
|
-
'a non-empty String, but %v given.',
|
|
63
|
+
'a non-empty String, but %v was given.',
|
|
64
64
|
modelName,
|
|
65
65
|
propName,
|
|
66
66
|
);
|
|
67
67
|
if (!propDef)
|
|
68
68
|
throw new InvalidArgumentError(
|
|
69
69
|
'The property %v of the model %v should have ' +
|
|
70
|
-
'a property definition, but %v given.',
|
|
70
|
+
'a property definition, but %v was given.',
|
|
71
71
|
propName,
|
|
72
72
|
modelName,
|
|
73
73
|
propDef,
|
|
@@ -76,7 +76,7 @@ export class PropertiesDefinitionValidator extends Service {
|
|
|
76
76
|
if (!Object.values(Type).includes(propDef))
|
|
77
77
|
throw new InvalidArgumentError(
|
|
78
78
|
'In case of a short property definition, the property %v ' +
|
|
79
|
-
'of the model %v should have one of data types: %l, but %v given.',
|
|
79
|
+
'of the model %v should have one of data types: %l, but %v was given.',
|
|
80
80
|
propName,
|
|
81
81
|
modelName,
|
|
82
82
|
Object.values(Type),
|
|
@@ -87,7 +87,7 @@ export class PropertiesDefinitionValidator extends Service {
|
|
|
87
87
|
if (!propDef || typeof propDef !== 'object' || Array.isArray(propDef)) {
|
|
88
88
|
throw new InvalidArgumentError(
|
|
89
89
|
'In case of a full property definition, the property %v ' +
|
|
90
|
-
'of the model %v should be an Object, but %v given.',
|
|
90
|
+
'of the model %v should be an Object, but %v was given.',
|
|
91
91
|
propName,
|
|
92
92
|
modelName,
|
|
93
93
|
propDef,
|
|
@@ -96,7 +96,7 @@ export class PropertiesDefinitionValidator extends Service {
|
|
|
96
96
|
if (!propDef.type || !Object.values(Type).includes(propDef.type))
|
|
97
97
|
throw new InvalidArgumentError(
|
|
98
98
|
'The property %v of the model %v requires the option "type" ' +
|
|
99
|
-
'to have one of data types: %l, but %v given.',
|
|
99
|
+
'to have one of data types: %l, but %v was given.',
|
|
100
100
|
propName,
|
|
101
101
|
modelName,
|
|
102
102
|
Object.values(Type),
|
|
@@ -105,7 +105,7 @@ export class PropertiesDefinitionValidator extends Service {
|
|
|
105
105
|
if (propDef.itemType && !Object.values(Type).includes(propDef.itemType)) {
|
|
106
106
|
throw new InvalidArgumentError(
|
|
107
107
|
'The provided option "itemType" of the property %v in the model %v ' +
|
|
108
|
-
'should have one of data types: %l, but %v given.',
|
|
108
|
+
'should have one of data types: %l, but %v was given.',
|
|
109
109
|
propName,
|
|
110
110
|
modelName,
|
|
111
111
|
Object.values(Type),
|
|
@@ -115,7 +115,7 @@ export class PropertiesDefinitionValidator extends Service {
|
|
|
115
115
|
if (propDef.itemModel && typeof propDef.itemModel !== 'string') {
|
|
116
116
|
throw new InvalidArgumentError(
|
|
117
117
|
'The provided option "itemModel" of the property %v in the model %v ' +
|
|
118
|
-
'should be a String, but %v given.',
|
|
118
|
+
'should be a String, but %v was given.',
|
|
119
119
|
propName,
|
|
120
120
|
modelName,
|
|
121
121
|
propDef.itemModel,
|
|
@@ -124,7 +124,7 @@ export class PropertiesDefinitionValidator extends Service {
|
|
|
124
124
|
if (propDef.model && typeof propDef.model !== 'string')
|
|
125
125
|
throw new InvalidArgumentError(
|
|
126
126
|
'The provided option "model" of the property %v in the model %v ' +
|
|
127
|
-
'should be a String, but %v given.',
|
|
127
|
+
'should be a String, but %v was given.',
|
|
128
128
|
propName,
|
|
129
129
|
modelName,
|
|
130
130
|
propDef.model,
|
|
@@ -132,7 +132,7 @@ export class PropertiesDefinitionValidator extends Service {
|
|
|
132
132
|
if (propDef.primaryKey && typeof propDef.primaryKey !== 'boolean')
|
|
133
133
|
throw new InvalidArgumentError(
|
|
134
134
|
'The provided option "primaryKey" of the property %v in the model %v ' +
|
|
135
|
-
'should be a Boolean, but %v given.',
|
|
135
|
+
'should be a Boolean, but %v was given.',
|
|
136
136
|
propName,
|
|
137
137
|
modelName,
|
|
138
138
|
propDef.primaryKey,
|
|
@@ -140,7 +140,7 @@ export class PropertiesDefinitionValidator extends Service {
|
|
|
140
140
|
if (propDef.columnName && typeof propDef.columnName !== 'string')
|
|
141
141
|
throw new InvalidArgumentError(
|
|
142
142
|
'The provided option "columnName" of the property %v in the model %v ' +
|
|
143
|
-
'should be a String, but %v given.',
|
|
143
|
+
'should be a String, but %v was given.',
|
|
144
144
|
propName,
|
|
145
145
|
modelName,
|
|
146
146
|
propDef.columnName,
|
|
@@ -148,7 +148,7 @@ export class PropertiesDefinitionValidator extends Service {
|
|
|
148
148
|
if (propDef.columnType && typeof propDef.columnType !== 'string')
|
|
149
149
|
throw new InvalidArgumentError(
|
|
150
150
|
'The provided option "columnType" of the property %v in the model %v ' +
|
|
151
|
-
'should be a String, but %v given.',
|
|
151
|
+
'should be a String, but %v was given.',
|
|
152
152
|
propName,
|
|
153
153
|
modelName,
|
|
154
154
|
propDef.columnType,
|
|
@@ -156,7 +156,7 @@ export class PropertiesDefinitionValidator extends Service {
|
|
|
156
156
|
if (propDef.required && typeof propDef.required !== 'boolean')
|
|
157
157
|
throw new InvalidArgumentError(
|
|
158
158
|
'The provided option "required" of the property %v in the model %v ' +
|
|
159
|
-
'should be a Boolean, but %v given.',
|
|
159
|
+
'should be a Boolean, but %v was given.',
|
|
160
160
|
propName,
|
|
161
161
|
modelName,
|
|
162
162
|
propDef.required,
|
|
@@ -228,92 +228,167 @@ export class PropertiesDefinitionValidator extends Service {
|
|
|
228
228
|
propName,
|
|
229
229
|
modelName,
|
|
230
230
|
);
|
|
231
|
+
// если определена опция "validate", то проверяется значение
|
|
232
|
+
// опции, которое может являться строкой, массивом или объектом
|
|
231
233
|
if (propDef.validate != null) {
|
|
232
234
|
const propertyValidatorRegistry = this.getService(
|
|
233
235
|
PropertyValidatorRegistry,
|
|
234
236
|
);
|
|
237
|
+
// если опция "validate" содержит строку, то проверяется
|
|
238
|
+
// наличие зарегистрированного валидатора по названию
|
|
235
239
|
if (propDef.validate && typeof propDef.validate === 'string') {
|
|
240
|
+
// если название валидатора не зарегистрировано,
|
|
241
|
+
// то выбрасывается ошибка
|
|
236
242
|
if (!propertyValidatorRegistry.hasValidator(propDef.validate))
|
|
237
243
|
throw new InvalidArgumentError(
|
|
238
244
|
'The property validator %v is not found.',
|
|
239
245
|
propDef.validate,
|
|
240
246
|
);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
247
|
+
}
|
|
248
|
+
// если опция "validate" содержит функцию, то данная функция
|
|
249
|
+
// воспринимается как пользовательский валидатор
|
|
250
|
+
else if (propDef.validate && typeof propDef.validate === 'function') {
|
|
251
|
+
// (допустимо)
|
|
252
|
+
}
|
|
253
|
+
// если опция "validate" содержит массив, то проверяется
|
|
254
|
+
// каждый элемент массива
|
|
255
|
+
else if (Array.isArray(propDef.validate)) {
|
|
256
|
+
for (const validatorOrName of propDef.validate) {
|
|
257
|
+
// если элемент массива является строкой, то проверяется
|
|
258
|
+
// наличие зарегистрированного валидатора по названию
|
|
259
|
+
if (validatorOrName && typeof validatorOrName === 'string') {
|
|
260
|
+
if (!propertyValidatorRegistry.hasValidator(validatorOrName))
|
|
261
|
+
throw new InvalidArgumentError(
|
|
262
|
+
'The property validator %v is not found.',
|
|
263
|
+
validatorOrName,
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
// если элемент массива является функцией, то данная функция
|
|
267
|
+
// воспринимается как пользовательский валидатор
|
|
268
|
+
else if (validatorOrName && typeof validatorOrName === 'function') {
|
|
269
|
+
// (допустимо)
|
|
270
|
+
}
|
|
271
|
+
// если элемент массива не является названием зарегистрированного
|
|
272
|
+
// валидатора или функцией-валидатором, то выбрасывается ошибка
|
|
273
|
+
else {
|
|
244
274
|
throw new InvalidArgumentError(
|
|
245
|
-
'The provided option "validate"
|
|
246
|
-
'has an Array value that should
|
|
247
|
-
'but %v given.',
|
|
275
|
+
'The provided option "validate" for the property %v in the model %v ' +
|
|
276
|
+
'has an Array value that should contain validator names or validator ' +
|
|
277
|
+
'functions, but %v was given.',
|
|
248
278
|
propName,
|
|
249
279
|
modelName,
|
|
250
|
-
|
|
251
|
-
);
|
|
252
|
-
if (!propertyValidatorRegistry.hasValidator(validatorName))
|
|
253
|
-
throw new InvalidArgumentError(
|
|
254
|
-
'The property validator %v is not found.',
|
|
255
|
-
validatorName,
|
|
280
|
+
validatorOrName,
|
|
256
281
|
);
|
|
282
|
+
}
|
|
257
283
|
}
|
|
258
|
-
}
|
|
259
|
-
|
|
284
|
+
}
|
|
285
|
+
// если опция "validate" содержит объект, то проверяются ключи данного
|
|
286
|
+
// объекта, которые должны являться названиями зарегистрированных
|
|
287
|
+
// валидаторов, а значения их аргументами
|
|
288
|
+
else if (typeof propDef.validate === 'object') {
|
|
289
|
+
Object.keys(propDef.validate).forEach(validatorName => {
|
|
290
|
+
// если ключ объекта не является названием зарегистрированного
|
|
291
|
+
// валидатора, то выбрасывается ошибка
|
|
260
292
|
if (!propertyValidatorRegistry.hasValidator(validatorName))
|
|
261
293
|
throw new InvalidArgumentError(
|
|
262
294
|
'The property validator %v is not found.',
|
|
263
295
|
validatorName,
|
|
264
296
|
);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
// если опция "validate" не является не пустой строкой, функцией,
|
|
300
|
+
// массивом и объектом, то выбрасывается ошибка
|
|
301
|
+
else {
|
|
267
302
|
throw new InvalidArgumentError(
|
|
268
|
-
'The provided option "validate"
|
|
269
|
-
'should be a
|
|
270
|
-
'
|
|
303
|
+
'The provided option "validate" for the property %v in the model %v ' +
|
|
304
|
+
'should be either a validator name, a validator function, an array ' +
|
|
305
|
+
'of validator names or functions, or an object mapping validator ' +
|
|
306
|
+
'names to their arguments, but %v was given.',
|
|
271
307
|
propName,
|
|
272
308
|
modelName,
|
|
273
309
|
propDef.validate,
|
|
274
310
|
);
|
|
275
311
|
}
|
|
276
312
|
}
|
|
313
|
+
// если определена опция "transform", то проверяется значение
|
|
314
|
+
// опции, которое может являться строкой, массивом или объектом
|
|
277
315
|
if (propDef.transform != null) {
|
|
278
316
|
const propertyTransformerRegistry = this.getService(
|
|
279
317
|
PropertyTransformerRegistry,
|
|
280
318
|
);
|
|
319
|
+
// если опция "transform" содержит строку, то проверяется
|
|
320
|
+
// наличие зарегистрированного трансформера по названию
|
|
281
321
|
if (propDef.transform && typeof propDef.transform === 'string') {
|
|
322
|
+
// если название трансформера не зарегистрировано,
|
|
323
|
+
// то выбрасывается ошибка
|
|
282
324
|
if (!propertyTransformerRegistry.hasTransformer(propDef.transform))
|
|
283
325
|
throw new InvalidArgumentError(
|
|
284
326
|
'The property transformer %v is not found.',
|
|
285
327
|
propDef.transform,
|
|
286
328
|
);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
|
|
329
|
+
}
|
|
330
|
+
// если опция "transform" содержит функцию, то данная функция
|
|
331
|
+
// воспринимается как пользовательский трансформер
|
|
332
|
+
else if (propDef.transform && typeof propDef.transform === 'function') {
|
|
333
|
+
// (допустимо)
|
|
334
|
+
}
|
|
335
|
+
// если опция "transform" содержит массив, то проверяется
|
|
336
|
+
// каждый элемент массива
|
|
337
|
+
else if (Array.isArray(propDef.transform)) {
|
|
338
|
+
for (const transformerOrName of propDef.transform) {
|
|
339
|
+
// если элемент массива является строкой, то проверяется
|
|
340
|
+
// наличие зарегистрированного трансформера по названию
|
|
341
|
+
if (transformerOrName && typeof transformerOrName === 'string') {
|
|
342
|
+
if (!propertyTransformerRegistry.hasTransformer(transformerOrName))
|
|
343
|
+
throw new InvalidArgumentError(
|
|
344
|
+
'The property transformer %v is not found.',
|
|
345
|
+
transformerOrName,
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
// если элемент массива является функцией, то данная функция
|
|
349
|
+
// воспринимается как пользовательский трансформер
|
|
350
|
+
else if (
|
|
351
|
+
transformerOrName &&
|
|
352
|
+
typeof transformerOrName === 'function'
|
|
353
|
+
) {
|
|
354
|
+
// (допустимо)
|
|
355
|
+
}
|
|
356
|
+
// если элемент массива не является названием зарегистрированного
|
|
357
|
+
// трансформера или функцией-трансформером, то выбрасывается ошибка
|
|
358
|
+
else {
|
|
290
359
|
throw new InvalidArgumentError(
|
|
291
|
-
'The provided option "transform"
|
|
292
|
-
'has an Array value that should
|
|
293
|
-
'but %v given.',
|
|
360
|
+
'The provided option "transform" for the property %v in the model %v ' +
|
|
361
|
+
'has an Array value that should contain transformer names or transformer ' +
|
|
362
|
+
'functions, but %v was given.',
|
|
294
363
|
propName,
|
|
295
364
|
modelName,
|
|
296
|
-
|
|
297
|
-
);
|
|
298
|
-
if (!propertyTransformerRegistry.hasTransformer(transformerName))
|
|
299
|
-
throw new InvalidArgumentError(
|
|
300
|
-
'The property transformer %v is not found.',
|
|
301
|
-
transformerName,
|
|
365
|
+
transformerOrName,
|
|
302
366
|
);
|
|
367
|
+
}
|
|
303
368
|
}
|
|
304
|
-
}
|
|
305
|
-
|
|
369
|
+
}
|
|
370
|
+
// если опция "transform" содержит объект, то проверяются ключи данного
|
|
371
|
+
// объекта, которые должны являться названиями зарегистрированных
|
|
372
|
+
// трансформеров, а значения их аргументами
|
|
373
|
+
else if (typeof propDef.transform === 'object') {
|
|
374
|
+
Object.keys(propDef.transform).forEach(transformerName => {
|
|
375
|
+
// если ключ объекта не является названием зарегистрированного
|
|
376
|
+
// валидатора, то выбрасывается ошибка
|
|
306
377
|
if (!propertyTransformerRegistry.hasTransformer(transformerName))
|
|
307
378
|
throw new InvalidArgumentError(
|
|
308
379
|
'The property transformer %v is not found.',
|
|
309
380
|
transformerName,
|
|
310
381
|
);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
// если опция "transform" не является не пустой строкой, функцией,
|
|
385
|
+
// массивом и объектом, то выбрасывается ошибка
|
|
386
|
+
else {
|
|
313
387
|
throw new InvalidArgumentError(
|
|
314
|
-
'The provided option "transform"
|
|
315
|
-
'should be a
|
|
316
|
-
'
|
|
388
|
+
'The provided option "transform" for the property %v in the model %v ' +
|
|
389
|
+
'should be either a transformer name, a transformer function, an array ' +
|
|
390
|
+
'of transformer names or functions, or an object mapping transformer ' +
|
|
391
|
+
'names to their arguments, but %v was given.',
|
|
317
392
|
propName,
|
|
318
393
|
modelName,
|
|
319
394
|
propDef.transform,
|
|
@@ -327,7 +402,7 @@ export class PropertiesDefinitionValidator extends Service {
|
|
|
327
402
|
) {
|
|
328
403
|
throw new InvalidArgumentError(
|
|
329
404
|
'The provided option "unique" of the property %v in the model %v ' +
|
|
330
|
-
'should be a Boolean or one of values: %l, but %v given.',
|
|
405
|
+
'should be a Boolean or one of values: %l, but %v was given.',
|
|
331
406
|
propName,
|
|
332
407
|
modelName,
|
|
333
408
|
Object.values(PropertyUniqueness),
|