@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.
Files changed (139) hide show
  1. package/README.md +35 -4
  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 +2 -2
  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 +20 -5
  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 +2 -2
  91. package/docs/types/PropertyValidatorContext.html +2 -2
  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 +11 -18
  104. package/src/adapter/decorator/data-validation-decorator.spec.js +48 -60
  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.d.ts +1 -5
  114. package/src/definition/model/model-data-validator.js +51 -53
  115. package/src/definition/model/model-data-validator.spec.js +772 -719
  116. package/src/definition/model/properties/index.d.ts +1 -0
  117. package/src/definition/model/properties/index.js +1 -0
  118. package/src/definition/model/properties/properties-definition-validator.js +47 -0
  119. package/src/definition/model/properties/properties-definition-validator.spec.js +52 -0
  120. package/src/definition/model/properties/property-transformer/builtin/index.d.ts +1 -0
  121. package/src/definition/model/properties/property-transformer/builtin/index.js +1 -0
  122. package/src/definition/model/properties/property-transformer/builtin/trim-transformer.d.ts +6 -0
  123. package/src/definition/model/properties/property-transformer/builtin/trim-transformer.js +19 -0
  124. package/src/definition/model/properties/property-transformer/builtin/trim-transformer.spec.js +39 -0
  125. package/src/definition/model/properties/property-transformer/index.d.ts +2 -0
  126. package/src/definition/model/properties/property-transformer/index.js +2 -0
  127. package/src/definition/model/properties/property-transformer/property-transformer-registry.d.ts +29 -0
  128. package/src/definition/model/properties/property-transformer/property-transformer-registry.js +72 -0
  129. package/src/definition/model/properties/property-transformer/property-transformer-registry.spec.js +129 -0
  130. package/src/definition/model/properties/property-transformer/property-transformer.d.ts +25 -0
  131. package/src/definition/model/properties/property-transformer/property-transformer.js +1 -0
  132. package/src/definition/model/properties/property-validator/builtin/max-length-validator.js +1 -1
  133. package/src/definition/model/properties/property-validator/builtin/max-length-validator.spec.js +10 -3
  134. package/src/definition/model/properties/property-validator/builtin/min-length-validator.js +1 -1
  135. package/src/definition/model/properties/property-validator/builtin/min-length-validator.spec.js +10 -3
  136. package/src/definition/model/properties/property-validator/builtin/regexp-validator.js +1 -1
  137. package/src/definition/model/properties/property-validator/builtin/regexp-validator.spec.js +10 -3
  138. package/src/definition/model/properties/property-validator/property-validator-registry.spec.js +51 -39
  139. package/src/definition/model/properties/property-validator/property-validator.d.ts +1 -6
@@ -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('""'));
@@ -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
- ) => Promise<boolean> | boolean;
17
+ ) => boolean;
23
18
 
24
19
  /**
25
20
  * Property validate options.