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