@e22m4u/js-repository 0.1.5 → 0.1.7
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 +35 -4
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/Adapter.html +1 -1
- package/docs/classes/AdapterLoader.html +1 -1
- package/docs/classes/AdapterRegistry.html +1 -1
- package/docs/classes/BelongsToResolver.html +1 -1
- package/docs/classes/DatasourceDefinitionValidator.html +1 -1
- package/docs/classes/DefinitionRegistry.html +1 -1
- package/docs/classes/FieldsClauseTool.html +1 -1
- package/docs/classes/HasManyResolver.html +1 -1
- package/docs/classes/HasOneResolver.html +1 -1
- package/docs/classes/IncludeClauseTool.html +1 -1
- package/docs/classes/InvalidArgumentError.html +1 -1
- package/docs/classes/InvalidOperatorValueError.html +1 -1
- package/docs/classes/ModelDataSanitizer.html +1 -1
- package/docs/classes/ModelDataTransformer.html +16 -0
- package/docs/classes/ModelDataValidator.html +2 -2
- package/docs/classes/ModelDefinitionUtils.html +1 -1
- package/docs/classes/ModelDefinitionValidator.html +1 -1
- package/docs/classes/NotImplementedError.html +1 -1
- package/docs/classes/OperatorClauseTool.html +1 -1
- package/docs/classes/OrderClauseTool.html +1 -1
- package/docs/classes/PrimaryKeysDefinitionValidator.html +1 -1
- package/docs/classes/PropertiesDefinitionValidator.html +1 -1
- package/docs/classes/PropertyTransformerRegistry.html +20 -0
- package/docs/classes/PropertyValidatorRegistry.html +1 -1
- package/docs/classes/ReferencesManyResolver.html +1 -1
- package/docs/classes/RelationsDefinitionValidator.html +1 -1
- package/docs/classes/Repository.html +1 -1
- package/docs/classes/RepositoryRegistry.html +1 -1
- package/docs/classes/Schema.html +1 -1
- package/docs/classes/SliceClauseTool.html +1 -1
- package/docs/classes/WhereClauseTool.html +1 -1
- package/docs/enums/DataType.html +1 -1
- package/docs/enums/DecoratorTargetType.html +1 -1
- package/docs/enums/RelationType.html +1 -1
- package/docs/functions/capitalize.html +1 -1
- package/docs/functions/cloneDeep.html +1 -1
- package/docs/functions/excludeObjectKeys.html +1 -1
- package/docs/functions/getCtorName.html +1 -1
- package/docs/functions/getDecoratorTargetType.html +1 -1
- package/docs/functions/getValueByPath.html +1 -1
- package/docs/functions/isCtor.html +1 -1
- package/docs/functions/isPureObject.html +1 -1
- package/docs/functions/selectObjectKeys.html +1 -1
- package/docs/functions/singularize.html +1 -1
- package/docs/functions/stringToRegexp.html +1 -1
- package/docs/index.html +20 -5
- package/docs/interfaces/AndClause.html +1 -1
- package/docs/interfaces/Constructor.html +1 -1
- package/docs/interfaces/OrClause.html +1 -1
- package/docs/modules.html +6 -1
- package/docs/types/AnyObject.html +1 -1
- package/docs/types/BelongsToDefinition.html +1 -1
- package/docs/types/DEFAULT_PRIMARY_KEY_PROPERTY_NAME.html +1 -1
- package/docs/types/DatasourceDefinition.html +1 -1
- package/docs/types/FieldsClause.html +1 -1
- package/docs/types/FilterClause.html +1 -1
- package/docs/types/Flatten.html +1 -1
- package/docs/types/FullPropertyDefinition.html +1 -1
- package/docs/types/HasManyDefinition.html +1 -1
- package/docs/types/HasOneDefinition.html +1 -1
- package/docs/types/Identity.html +1 -1
- package/docs/types/IncludeClause.html +1 -1
- package/docs/types/ItemFilterClause.html +1 -1
- package/docs/types/ModelData.html +1 -1
- package/docs/types/ModelDefinition.html +1 -1
- package/docs/types/ModelId.html +1 -1
- package/docs/types/NestedIncludeClause.html +1 -1
- package/docs/types/NormalizedFieldsClause.html +1 -1
- package/docs/types/NormalizedIncludeClause.html +1 -1
- package/docs/types/OperatorClause.html +1 -1
- package/docs/types/OptionalUnlessRequiredId.html +1 -1
- package/docs/types/OrderClause.html +1 -1
- package/docs/types/PartialBy.html +1 -1
- package/docs/types/PartialWithoutId.html +1 -1
- package/docs/types/PolyBelongsToDefinition.html +1 -1
- package/docs/types/PolyHasManyDefinitionWithTargetKeys.html +1 -1
- package/docs/types/PolyHasManyDefinitionWithTargetRelationName.html +1 -1
- package/docs/types/PolyHasOneDefinitionWithTargetKeys.html +1 -1
- package/docs/types/PolyHasOneDefinitionWithTargetRelationName.html +1 -1
- package/docs/types/PropertiesClause.html +1 -1
- package/docs/types/PropertyDefinition.html +1 -1
- package/docs/types/PropertyDefinitionMap.html +1 -1
- package/docs/types/PropertyTransformOptions.html +2 -0
- package/docs/types/PropertyTransformer.html +2 -0
- package/docs/types/PropertyTransformerContext.html +2 -0
- package/docs/types/PropertyValidateOptions.html +1 -1
- package/docs/types/PropertyValidator.html +2 -2
- package/docs/types/PropertyValidatorContext.html +2 -2
- package/docs/types/ReferencesManyDefinition.html +1 -1
- package/docs/types/RelationDefinition.html +1 -1
- package/docs/types/RelationDefinitionMap.html +1 -1
- package/docs/types/WhereClause.html +1 -1
- package/docs/types/WithoutId.html +1 -1
- package/package.json +3 -3
- package/src/adapter/adapter.js +2 -0
- package/src/adapter/adapter.spec.js +9 -3
- package/src/adapter/decorator/data-transformation-decorator.d.ts +14 -0
- package/src/adapter/decorator/data-transformation-decorator.js +54 -0
- package/src/adapter/decorator/data-transformation-decorator.spec.js +95 -0
- package/src/adapter/decorator/data-validation-decorator.js +11 -18
- package/src/adapter/decorator/data-validation-decorator.spec.js +48 -60
- package/src/adapter/decorator/default-values-decorator.spec.js +89 -113
- package/src/adapter/decorator/index.d.ts +1 -0
- package/src/adapter/decorator/index.js +1 -0
- package/src/definition/model/index.d.ts +1 -0
- package/src/definition/model/index.js +1 -0
- package/src/definition/model/model-data-transformer.d.ts +15 -0
- package/src/definition/model/model-data-transformer.js +96 -0
- package/src/definition/model/model-data-transformer.spec.js +534 -0
- package/src/definition/model/model-data-validator.d.ts +1 -5
- package/src/definition/model/model-data-validator.js +51 -53
- package/src/definition/model/model-data-validator.spec.js +772 -719
- package/src/definition/model/properties/index.d.ts +1 -0
- package/src/definition/model/properties/index.js +1 -0
- package/src/definition/model/properties/properties-definition-validator.js +47 -0
- package/src/definition/model/properties/properties-definition-validator.spec.js +52 -0
- package/src/definition/model/properties/property-transformer/builtin/index.d.ts +1 -0
- package/src/definition/model/properties/property-transformer/builtin/index.js +1 -0
- package/src/definition/model/properties/property-transformer/builtin/trim-transformer.d.ts +6 -0
- package/src/definition/model/properties/property-transformer/builtin/trim-transformer.js +19 -0
- package/src/definition/model/properties/property-transformer/builtin/trim-transformer.spec.js +39 -0
- package/src/definition/model/properties/property-transformer/index.d.ts +2 -0
- package/src/definition/model/properties/property-transformer/index.js +2 -0
- package/src/definition/model/properties/property-transformer/property-transformer-registry.d.ts +29 -0
- package/src/definition/model/properties/property-transformer/property-transformer-registry.js +72 -0
- package/src/definition/model/properties/property-transformer/property-transformer-registry.spec.js +129 -0
- package/src/definition/model/properties/property-transformer/property-transformer.d.ts +25 -0
- package/src/definition/model/properties/property-transformer/property-transformer.js +1 -0
- package/src/definition/model/properties/property-validator/builtin/max-length-validator.js +1 -1
- package/src/definition/model/properties/property-validator/builtin/max-length-validator.spec.js +10 -3
- package/src/definition/model/properties/property-validator/builtin/min-length-validator.js +1 -1
- package/src/definition/model/properties/property-validator/builtin/min-length-validator.spec.js +10 -3
- package/src/definition/model/properties/property-validator/builtin/regexp-validator.js +1 -1
- package/src/definition/model/properties/property-validator/builtin/regexp-validator.spec.js +10 -3
- package/src/definition/model/properties/property-validator/property-validator-registry.spec.js +51 -39
- package/src/definition/model/properties/property-validator/property-validator.d.ts +1 -6
package/src/definition/model/properties/property-validator/property-validator-registry.spec.js
CHANGED
|
@@ -1,20 +1,32 @@
|
|
|
1
1
|
import {expect} from 'chai';
|
|
2
2
|
import {format} from '@e22m4u/js-format';
|
|
3
|
+
import {regexpValidator} from './builtin/index.js';
|
|
4
|
+
import {maxLengthValidator} from './builtin/index.js';
|
|
5
|
+
import {minLengthValidator} from './builtin/index.js';
|
|
3
6
|
import {PropertyValidatorRegistry} from './property-validator-registry.js';
|
|
4
7
|
|
|
5
8
|
describe('PropertyValidatorRegistry', function () {
|
|
9
|
+
it('has builtin validators', function () {
|
|
10
|
+
const S = new PropertyValidatorRegistry();
|
|
11
|
+
expect(S['_validators']).to.be.eql({
|
|
12
|
+
maxLength: maxLengthValidator,
|
|
13
|
+
minLength: minLengthValidator,
|
|
14
|
+
regexp: regexpValidator,
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
6
18
|
describe('addValidator', function () {
|
|
7
19
|
it('adds a given validator with the name', function () {
|
|
8
|
-
const
|
|
9
|
-
const myValidator = () =>
|
|
10
|
-
const res =
|
|
11
|
-
expect(res).to.be.eq(
|
|
12
|
-
expect(
|
|
20
|
+
const S = new PropertyValidatorRegistry();
|
|
21
|
+
const myValidator = () => undefined;
|
|
22
|
+
const res = S.addValidator('myValidator', myValidator);
|
|
23
|
+
expect(res).to.be.eq(S);
|
|
24
|
+
expect(S['_validators']['myValidator']).to.be.eq(myValidator);
|
|
13
25
|
});
|
|
14
26
|
|
|
15
27
|
it('requires the given name to be a non-empty string', function () {
|
|
16
|
-
const
|
|
17
|
-
const throwable = v => () =>
|
|
28
|
+
const S = new PropertyValidatorRegistry();
|
|
29
|
+
const throwable = v => () => S.addValidator(v, () => undefined);
|
|
18
30
|
const error = v =>
|
|
19
31
|
format(
|
|
20
32
|
'A name of the property validator must ' +
|
|
@@ -34,17 +46,17 @@ describe('PropertyValidatorRegistry', function () {
|
|
|
34
46
|
});
|
|
35
47
|
|
|
36
48
|
it('throws an error if the given name already exists', function () {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
const throwable = () =>
|
|
49
|
+
const S = new PropertyValidatorRegistry();
|
|
50
|
+
S.addValidator('test', () => undefined);
|
|
51
|
+
const throwable = () => S.addValidator('test', () => undefined);
|
|
40
52
|
expect(throwable).to.throw(
|
|
41
53
|
'The property validator "test" is already defined.',
|
|
42
54
|
);
|
|
43
55
|
});
|
|
44
56
|
|
|
45
57
|
it('requires the given validator to be a function', function () {
|
|
46
|
-
const
|
|
47
|
-
const throwable = v => () =>
|
|
58
|
+
const S = new PropertyValidatorRegistry();
|
|
59
|
+
const throwable = v => () => S.addValidator('test', v);
|
|
48
60
|
const error = v =>
|
|
49
61
|
format(
|
|
50
62
|
'The property validator "test" must be a Function, but %s given.',
|
|
@@ -65,44 +77,44 @@ describe('PropertyValidatorRegistry', function () {
|
|
|
65
77
|
|
|
66
78
|
describe('hasValidator', function () {
|
|
67
79
|
it('returns false for a not existing name', function () {
|
|
68
|
-
const
|
|
69
|
-
expect(
|
|
70
|
-
expect(
|
|
71
|
-
expect(
|
|
72
|
-
expect(
|
|
73
|
-
expect(
|
|
74
|
-
expect(
|
|
75
|
-
expect(
|
|
76
|
-
expect(
|
|
77
|
-
expect(
|
|
78
|
-
expect(
|
|
79
|
-
expect(
|
|
80
|
+
const S = new PropertyValidatorRegistry();
|
|
81
|
+
expect(S.hasValidator('str')).to.be.false;
|
|
82
|
+
expect(S.hasValidator('')).to.be.false;
|
|
83
|
+
expect(S.hasValidator(10)).to.be.false;
|
|
84
|
+
expect(S.hasValidator(0)).to.be.false;
|
|
85
|
+
expect(S.hasValidator(true)).to.be.false;
|
|
86
|
+
expect(S.hasValidator(false)).to.be.false;
|
|
87
|
+
expect(S.hasValidator(null)).to.be.false;
|
|
88
|
+
expect(S.hasValidator(undefined)).to.be.false;
|
|
89
|
+
expect(S.hasValidator({})).to.be.false;
|
|
90
|
+
expect(S.hasValidator([])).to.be.false;
|
|
91
|
+
expect(S.hasValidator(() => undefined)).to.be.false;
|
|
80
92
|
});
|
|
81
93
|
|
|
82
94
|
it('returns true for an existing name', function () {
|
|
83
|
-
const
|
|
84
|
-
expect(
|
|
85
|
-
|
|
86
|
-
expect(
|
|
95
|
+
const S = new PropertyValidatorRegistry();
|
|
96
|
+
expect(S.hasValidator('test')).to.be.false;
|
|
97
|
+
S.addValidator('test', () => undefined);
|
|
98
|
+
expect(S.hasValidator('test')).to.be.true;
|
|
87
99
|
});
|
|
88
100
|
});
|
|
89
101
|
|
|
90
102
|
describe('getValidator', function () {
|
|
91
103
|
it('returns validator by its name', function () {
|
|
92
|
-
const
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const res1 =
|
|
98
|
-
const res2 =
|
|
99
|
-
expect(res1).to.be.eq(
|
|
100
|
-
expect(res2).to.be.eq(
|
|
104
|
+
const S = new PropertyValidatorRegistry();
|
|
105
|
+
const myValidator1 = () => undefined;
|
|
106
|
+
const myValidator2 = () => undefined;
|
|
107
|
+
S.addValidator('foo', myValidator1);
|
|
108
|
+
S.addValidator('bar', myValidator2);
|
|
109
|
+
const res1 = S.getValidator('foo');
|
|
110
|
+
const res2 = S.getValidator('bar');
|
|
111
|
+
expect(res1).to.be.eq(myValidator1);
|
|
112
|
+
expect(res2).to.be.eq(myValidator2);
|
|
101
113
|
});
|
|
102
114
|
|
|
103
115
|
it('throws an error for a not existed name', function () {
|
|
104
|
-
const
|
|
105
|
-
const throwable = v => () =>
|
|
116
|
+
const S = new PropertyValidatorRegistry();
|
|
117
|
+
const throwable = v => () => S.getValidator(v);
|
|
106
118
|
const error = v => format('The property validator %s is not defined.', v);
|
|
107
119
|
expect(throwable('str')).to.throw(error('"str"'));
|
|
108
120
|
expect(throwable('')).to.throw(error('""'));
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {ServiceContainer} from '@e22m4u/js-service';
|
|
2
|
-
import {FullPropertyDefinition} from '../property-definition.js';
|
|
3
|
-
|
|
4
1
|
/**
|
|
5
2
|
* Property validator context.
|
|
6
3
|
*/
|
|
@@ -8,8 +5,6 @@ export type PropertyValidatorContext = {
|
|
|
8
5
|
validatorName: string,
|
|
9
6
|
modelName: string,
|
|
10
7
|
propName: string,
|
|
11
|
-
propDef: FullPropertyDefinition,
|
|
12
|
-
container: ServiceContainer,
|
|
13
8
|
}
|
|
14
9
|
|
|
15
10
|
/**
|
|
@@ -19,7 +14,7 @@ export type PropertyValidator = (
|
|
|
19
14
|
value: unknown,
|
|
20
15
|
options: unknown,
|
|
21
16
|
context: PropertyValidatorContext,
|
|
22
|
-
) =>
|
|
17
|
+
) => boolean;
|
|
23
18
|
|
|
24
19
|
/**
|
|
25
20
|
* Property validate options.
|