@e22m4u/js-repository 0.1.1 → 0.1.3

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 (141) hide show
  1. package/.eslintrc.cjs +41 -17
  2. package/.husky/commit-msg +1 -4
  3. package/.husky/pre-commit +0 -3
  4. package/.mocharc.cjs +2 -2
  5. package/README.md +2 -2
  6. package/docs/assets/main.js +2 -2
  7. package/docs/assets/navigation.js +1 -1
  8. package/docs/assets/search.js +1 -1
  9. package/docs/assets/style.css +35 -15
  10. package/docs/classes/Adapter.html +19 -19
  11. package/docs/classes/AdapterLoader.html +8 -8
  12. package/docs/classes/AdapterRegistry.html +8 -8
  13. package/docs/classes/BelongsToResolver.html +9 -9
  14. package/docs/classes/DatasourceDefinitionValidator.html +8 -8
  15. package/docs/classes/DefinitionRegistry.html +12 -12
  16. package/docs/classes/FieldsClauseTool.html +10 -10
  17. package/docs/classes/HasManyResolver.html +10 -10
  18. package/docs/classes/HasOneResolver.html +10 -10
  19. package/docs/classes/IncludeClauseTool.html +12 -12
  20. package/docs/classes/InvalidArgumentError.html +7 -5
  21. package/docs/classes/InvalidOperatorValueError.html +7 -5
  22. package/docs/classes/ModelDataSanitizer.html +8 -8
  23. package/docs/classes/ModelDataValidator.html +9 -9
  24. package/docs/classes/ModelDefinitionUtils.html +23 -23
  25. package/docs/classes/ModelDefinitionValidator.html +8 -8
  26. package/docs/classes/NotImplementedError.html +7 -5
  27. package/docs/classes/OperatorClauseTool.html +32 -32
  28. package/docs/classes/OrderClauseTool.html +10 -10
  29. package/docs/classes/PrimaryKeysDefinitionValidator.html +8 -8
  30. package/docs/classes/PropertiesDefinitionValidator.html +8 -8
  31. package/docs/classes/ReferencesManyResolver.html +8 -8
  32. package/docs/classes/RelationsDefinitionValidator.html +8 -8
  33. package/docs/classes/Repository.html +28 -24
  34. package/docs/classes/RepositoryRegistry.html +9 -9
  35. package/docs/classes/Schema.html +10 -10
  36. package/docs/classes/SliceClauseTool.html +10 -10
  37. package/docs/classes/WhereClauseTool.html +9 -9
  38. package/docs/enums/DataType.html +2 -2
  39. package/docs/enums/DecoratorTargetType.html +11 -0
  40. package/docs/enums/RelationType.html +2 -2
  41. package/docs/functions/capitalize.html +1 -1
  42. package/docs/functions/cloneDeep.html +2 -2
  43. package/docs/functions/excludeObjectKeys.html +2 -2
  44. package/docs/functions/getCtorName.html +1 -1
  45. package/docs/functions/getDecoratorTargetType.html +2 -0
  46. package/docs/functions/getValueByPath.html +1 -1
  47. package/docs/functions/isCtor.html +3 -2
  48. package/docs/functions/isPureObject.html +1 -1
  49. package/docs/functions/selectObjectKeys.html +2 -2
  50. package/docs/functions/singularize.html +1 -1
  51. package/docs/functions/stringToRegexp.html +2 -2
  52. package/docs/index.html +3 -3
  53. package/docs/interfaces/AndClause.html +2 -2
  54. package/docs/interfaces/Constructor.html +4 -0
  55. package/docs/interfaces/OrClause.html +2 -2
  56. package/docs/modules.html +4 -1
  57. package/docs/types/AnyObject.html +1 -1
  58. package/docs/types/BelongsToDefinition.html +1 -1
  59. package/docs/types/DEFAULT_PRIMARY_KEY_PROPERTY_NAME.html +1 -1
  60. package/docs/types/DatasourceDefinition.html +1 -1
  61. package/docs/types/FieldsClause.html +1 -1
  62. package/docs/types/FilterClause.html +1 -1
  63. package/docs/types/Flatten.html +1 -1
  64. package/docs/types/FullPropertyDefinition.html +1 -1
  65. package/docs/types/HasManyDefinition.html +1 -1
  66. package/docs/types/HasOneDefinition.html +1 -1
  67. package/docs/types/Identity.html +2 -2
  68. package/docs/types/IncludeClause.html +1 -1
  69. package/docs/types/ItemFilterClause.html +2 -2
  70. package/docs/types/ModelData.html +1 -1
  71. package/docs/types/ModelDefinition.html +1 -1
  72. package/docs/types/ModelId.html +1 -1
  73. package/docs/types/NestedIncludeClause.html +1 -1
  74. package/docs/types/NormalizedFieldsClause.html +1 -1
  75. package/docs/types/NormalizedIncludeClause.html +1 -1
  76. package/docs/types/OperatorClause.html +3 -3
  77. package/docs/types/OptionalUnlessRequiredId.html +2 -2
  78. package/docs/types/OrderClause.html +1 -1
  79. package/docs/types/PartialBy.html +2 -2
  80. package/docs/types/PartialWithoutId.html +2 -2
  81. package/docs/types/PolyBelongsToDefinition.html +1 -1
  82. package/docs/types/PolyHasManyDefinitionWithTargetKeys.html +1 -1
  83. package/docs/types/PolyHasManyDefinitionWithTargetRelationName.html +1 -1
  84. package/docs/types/PolyHasOneDefinitionWithTargetKeys.html +1 -1
  85. package/docs/types/PolyHasOneDefinitionWithTargetRelationName.html +1 -1
  86. package/docs/types/PropertiesClause.html +3 -3
  87. package/docs/types/PropertyDefinition.html +1 -1
  88. package/docs/types/PropertyDefinitionMap.html +1 -1
  89. package/docs/types/ReferencesManyDefinition.html +1 -1
  90. package/docs/types/RelationDefinition.html +1 -1
  91. package/docs/types/RelationDefinitionMap.html +1 -1
  92. package/docs/types/WhereClause.html +2 -2
  93. package/docs/types/WithoutId.html +2 -2
  94. package/mocha.setup.js +8 -3
  95. package/package.json +23 -19
  96. package/src/adapter/decorator/data-sanitizing-decorator.d.ts +2 -1
  97. package/src/adapter/decorator/data-validation-decorator.d.ts +2 -1
  98. package/src/adapter/decorator/data-validation-decorator.js +18 -10
  99. package/src/adapter/decorator/data-validation-decorator.spec.js +40 -0
  100. package/src/adapter/decorator/default-values-decorator.d.ts +2 -1
  101. package/src/adapter/decorator/fields-filtering-decorator.d.ts +2 -1
  102. package/src/adapter/decorator/inclusion-decorator.d.ts +2 -1
  103. package/src/definition/model/index.js +1 -0
  104. package/src/definition/model/model-data-validator.d.ts +4 -16
  105. package/src/definition/model/model-data-validator.js +92 -11
  106. package/src/definition/model/model-data-validator.spec.js +1140 -442
  107. package/src/definition/model/model-definition.js +1 -0
  108. package/src/definition/model/properties/index.d.ts +1 -0
  109. package/src/definition/model/properties/index.js +2 -0
  110. package/src/definition/model/properties/properties-definition-validator.js +47 -0
  111. package/src/definition/model/properties/properties-definition-validator.spec.js +50 -0
  112. package/src/definition/model/properties/property-definition.d.ts +2 -0
  113. package/src/definition/model/properties/property-definition.js +1 -0
  114. package/src/definition/model/properties/property-validator/index.d.ts +2 -0
  115. package/src/definition/model/properties/property-validator/index.js +2 -0
  116. package/src/definition/model/properties/property-validator/property-validator-registry.d.ts +29 -0
  117. package/src/definition/model/properties/property-validator/property-validator-registry.js +69 -0
  118. package/src/definition/model/properties/property-validator/property-validator-registry.spec.js +120 -0
  119. package/src/definition/model/properties/property-validator/property-validator.d.ts +30 -0
  120. package/src/definition/model/properties/property-validator/property-validator.js +1 -0
  121. package/src/definition/model/relations/index.js +1 -0
  122. package/src/definition/model/relations/relation-definition.js +1 -0
  123. package/src/filter/filter-clause.d.ts +4 -4
  124. package/src/index.d.ts +1 -1
  125. package/src/index.js +1 -0
  126. package/src/repository/repository.d.ts +9 -3
  127. package/src/repository/repository.js +0 -1
  128. package/src/schema.d.ts +10 -1
  129. package/src/schema.js +13 -0
  130. package/src/schema.spec.ts +115 -0
  131. package/src/types.d.ts +8 -0
  132. package/src/types.js +1 -0
  133. package/src/utils/get-decorator-target-type.d.ts +27 -0
  134. package/src/utils/get-decorator-target-type.js +63 -0
  135. package/src/utils/get-decorator-target-type.spec.js +77 -0
  136. package/src/utils/index.d.ts +1 -0
  137. package/src/utils/index.js +1 -0
  138. package/src/utils/is-ctor.d.ts +2 -1
  139. package/src/utils/is-ctor.js +2 -1
  140. package/src/utils/is-ctor.spec.js +1 -1
  141. package/tsconfig.json +3 -1
@@ -3,40 +3,44 @@ import {Schema} from '../../schema.js';
3
3
  import {format} from '@e22m4u/js-format';
4
4
  import {DataType} from './properties/index.js';
5
5
  import {ModelDataValidator} from './model-data-validator.js';
6
+ import {PropertyValidatorRegistry} from './properties/index.js';
6
7
 
7
8
  describe('ModelDataValidator', function () {
8
9
  describe('validate', function () {
9
- it('does not throw an error if a model does not have a property of a given data', function () {
10
+ it('does not throw an error if a model does not have a property of a given data', async function () {
10
11
  const schema = new Schema();
11
12
  schema.defineModel({name: 'model'});
12
- schema.getService(ModelDataValidator).validate('model', {foo: 'bar'});
13
+ await schema
14
+ .getService(ModelDataValidator)
15
+ .validate('model', {foo: 'bar'});
13
16
  });
14
17
 
15
- it('throws an error if a given data is not a pure object', function () {
18
+ it('throws an error if a given data is not a pure object', async function () {
16
19
  const throwable = modelData => {
17
20
  const schema = new Schema();
18
21
  schema.defineModel({
19
22
  name: 'model',
20
23
  datasource: 'datasource',
21
24
  });
22
- return () =>
23
- schema.getService(ModelDataValidator).validate('model', modelData);
25
+ return schema
26
+ .getService(ModelDataValidator)
27
+ .validate('model', modelData);
24
28
  };
25
29
  const error = given =>
26
30
  format(
27
31
  'The data of the model "model" should be an Object, but %s given.',
28
32
  given,
29
33
  );
30
- expect(throwable('str')).to.throw(error('"str"'));
31
- expect(throwable(10)).to.throw(error('10'));
32
- expect(throwable(true)).to.throw(error('true'));
33
- expect(throwable(false)).to.throw(error('false'));
34
- expect(throwable([])).to.throw(error('Array'));
35
- expect(throwable(null)).to.throw(error('null'));
36
- expect(throwable(undefined)).to.throw(error('undefined'));
34
+ await expect(throwable('str')).to.be.rejectedWith(error('"str"'));
35
+ await expect(throwable(10)).to.be.rejectedWith(error('10'));
36
+ await expect(throwable(true)).to.be.rejectedWith(error('true'));
37
+ await expect(throwable(false)).to.be.rejectedWith(error('false'));
38
+ await expect(throwable([])).to.be.rejectedWith(error('Array'));
39
+ await expect(throwable(null)).to.be.rejectedWith(error('null'));
40
+ await expect(throwable(undefined)).to.be.rejectedWith(error('undefined'));
37
41
  });
38
42
 
39
- it('uses a base model hierarchy to validate a given data', function () {
43
+ it('uses a base model hierarchy to validate a given data', async function () {
40
44
  const schema = new Schema();
41
45
  schema.defineModel({
42
46
  name: 'modelA',
@@ -48,15 +52,16 @@ describe('ModelDataValidator', function () {
48
52
  name: 'modelB',
49
53
  base: 'modelA',
50
54
  });
51
- const throwable = () =>
52
- schema.getService(ModelDataValidator).validate('modelB', {foo: 10});
53
- expect(throwable).to.throw(
55
+ const promise = schema
56
+ .getService(ModelDataValidator)
57
+ .validate('modelB', {foo: 10});
58
+ await expect(promise).to.be.rejectedWith(
54
59
  'The property "foo" of the model "modelB" must ' +
55
60
  'have a String, but Number given.',
56
61
  );
57
62
  });
58
63
 
59
- it('throws an error if a given data does not have a required property', function () {
64
+ it('throws an error if a given data does not have a required property', async function () {
60
65
  const schema = new Schema();
61
66
  schema.defineModel({
62
67
  name: 'model',
@@ -67,15 +72,16 @@ describe('ModelDataValidator', function () {
67
72
  },
68
73
  },
69
74
  });
70
- const throwable = () =>
71
- schema.getService(ModelDataValidator).validate('model', {});
72
- expect(throwable).to.throw(
75
+ const promise = schema
76
+ .getService(ModelDataValidator)
77
+ .validate('model', {});
78
+ await expect(promise).to.be.rejectedWith(
73
79
  'The property "foo" of the model "model" ' +
74
80
  'is required, but undefined given.',
75
81
  );
76
82
  });
77
83
 
78
- it('throws an error if a required property is undefined', function () {
84
+ it('throws an error if a required property is undefined', async function () {
79
85
  const schema = new Schema();
80
86
  schema.defineModel({
81
87
  name: 'model',
@@ -86,16 +92,15 @@ describe('ModelDataValidator', function () {
86
92
  },
87
93
  },
88
94
  });
89
- const throwable = () =>
90
- schema
91
- .getService(ModelDataValidator)
92
- .validate('model', {foo: undefined});
93
- expect(throwable).to.throw(
95
+ const promise = schema
96
+ .getService(ModelDataValidator)
97
+ .validate('model', {foo: undefined});
98
+ await expect(promise).to.be.rejectedWith(
94
99
  'The property "foo" of the model "model" is required, but undefined given.',
95
100
  );
96
101
  });
97
102
 
98
- it('throws an error if a required property is null', function () {
103
+ it('throws an error if a required property is null', async function () {
99
104
  const schema = new Schema();
100
105
  schema.defineModel({
101
106
  name: 'model',
@@ -106,15 +111,16 @@ describe('ModelDataValidator', function () {
106
111
  },
107
112
  },
108
113
  });
109
- const throwable = () =>
110
- schema.getService(ModelDataValidator).validate('model', {foo: null});
111
- expect(throwable).to.throw(
114
+ const promise = schema
115
+ .getService(ModelDataValidator)
116
+ .validate('model', {foo: null});
117
+ await expect(promise).to.be.rejectedWith(
112
118
  'The property "foo" of the model "model" is required, but null given.',
113
119
  );
114
120
  });
115
121
 
116
122
  describe('an option "isPartial" is true', function () {
117
- it('does not throw an error if a given data does not have a required property', function () {
123
+ it('does not throw an error if a given data does not have a required property', async function () {
118
124
  const schema = new Schema();
119
125
  schema.defineModel({
120
126
  name: 'model',
@@ -125,10 +131,10 @@ describe('ModelDataValidator', function () {
125
131
  },
126
132
  },
127
133
  });
128
- schema.getService(ModelDataValidator).validate('model', {}, true);
134
+ await schema.getService(ModelDataValidator).validate('model', {}, true);
129
135
  });
130
136
 
131
- it('throws an error if a required property is undefined', function () {
137
+ it('throws an error if a required property is undefined', async function () {
132
138
  const schema = new Schema();
133
139
  schema.defineModel({
134
140
  name: 'model',
@@ -139,17 +145,16 @@ describe('ModelDataValidator', function () {
139
145
  },
140
146
  },
141
147
  });
142
- const throwable = () =>
143
- schema
144
- .getService(ModelDataValidator)
145
- .validate('model', {foo: undefined}, true);
146
- expect(throwable).to.throw(
148
+ const promise = schema
149
+ .getService(ModelDataValidator)
150
+ .validate('model', {foo: undefined}, true);
151
+ await expect(promise).to.be.rejectedWith(
147
152
  'The property "foo" of the model "model" ' +
148
153
  'is required, but undefined given.',
149
154
  );
150
155
  });
151
156
 
152
- it('throws an error if a required property is null', function () {
157
+ it('throws an error if a required property is null', async function () {
153
158
  const schema = new Schema();
154
159
  schema.defineModel({
155
160
  name: 'model',
@@ -160,11 +165,10 @@ describe('ModelDataValidator', function () {
160
165
  },
161
166
  },
162
167
  });
163
- const throwable = () =>
164
- schema
165
- .getService(ModelDataValidator)
166
- .validate('model', {foo: null}, true);
167
- expect(throwable).to.throw(
168
+ const promise = schema
169
+ .getService(ModelDataValidator)
170
+ .validate('model', {foo: null}, true);
171
+ await expect(promise).to.be.rejectedWith(
168
172
  'The property "foo" of the model "model" is required, but null given.',
169
173
  );
170
174
  });
@@ -172,7 +176,7 @@ describe('ModelDataValidator', function () {
172
176
 
173
177
  describe('DataType.ANY', function () {
174
178
  describe('ShortPropertyDefinition', function () {
175
- it('does not throw an error if an undefined given', function () {
179
+ it('does not throw an error if an undefined given', async function () {
176
180
  const S = new Schema();
177
181
  S.defineModel({
178
182
  name: 'model',
@@ -181,12 +185,12 @@ describe('ModelDataValidator', function () {
181
185
  foo: DataType.ANY,
182
186
  },
183
187
  });
184
- S.getService(ModelDataValidator).validate('model', {
188
+ await S.getService(ModelDataValidator).validate('model', {
185
189
  foo: undefined,
186
190
  });
187
191
  });
188
192
 
189
- it('does not throw an error if a null given', function () {
193
+ it('does not throw an error if a null given', async function () {
190
194
  const S = new Schema();
191
195
  S.defineModel({
192
196
  name: 'model',
@@ -195,12 +199,12 @@ describe('ModelDataValidator', function () {
195
199
  foo: DataType.ANY,
196
200
  },
197
201
  });
198
- S.getService(ModelDataValidator).validate('model', {
202
+ await S.getService(ModelDataValidator).validate('model', {
199
203
  foo: null,
200
204
  });
201
205
  });
202
206
 
203
- it('does not throw an error if a string given', function () {
207
+ it('does not throw an error if a string given', async function () {
204
208
  const S = new Schema();
205
209
  S.defineModel({
206
210
  name: 'model',
@@ -209,12 +213,12 @@ describe('ModelDataValidator', function () {
209
213
  foo: DataType.ANY,
210
214
  },
211
215
  });
212
- S.getService(ModelDataValidator).validate('model', {
216
+ await S.getService(ModelDataValidator).validate('model', {
213
217
  foo: 'bar',
214
218
  });
215
219
  });
216
220
 
217
- it('does not throw an error if a number given', function () {
221
+ it('does not throw an error if a number given', async function () {
218
222
  const S = new Schema();
219
223
  S.defineModel({
220
224
  name: 'model',
@@ -223,12 +227,12 @@ describe('ModelDataValidator', function () {
223
227
  foo: DataType.ANY,
224
228
  },
225
229
  });
226
- S.getService(ModelDataValidator).validate('model', {
230
+ await S.getService(ModelDataValidator).validate('model', {
227
231
  foo: 10,
228
232
  });
229
233
  });
230
234
 
231
- it('does not throw an error if true given', function () {
235
+ it('does not throw an error if true given', async function () {
232
236
  const S = new Schema();
233
237
  S.defineModel({
234
238
  name: 'model',
@@ -237,12 +241,12 @@ describe('ModelDataValidator', function () {
237
241
  foo: DataType.ANY,
238
242
  },
239
243
  });
240
- S.getService(ModelDataValidator).validate('model', {
244
+ await S.getService(ModelDataValidator).validate('model', {
241
245
  foo: true,
242
246
  });
243
247
  });
244
248
 
245
- it('does not throw an error if false given', function () {
249
+ it('does not throw an error if false given', async function () {
246
250
  const S = new Schema();
247
251
  S.defineModel({
248
252
  name: 'model',
@@ -251,12 +255,12 @@ describe('ModelDataValidator', function () {
251
255
  foo: DataType.ANY,
252
256
  },
253
257
  });
254
- S.getService(ModelDataValidator).validate('model', {
258
+ await S.getService(ModelDataValidator).validate('model', {
255
259
  foo: false,
256
260
  });
257
261
  });
258
262
 
259
- it('does not throw an error if an array given', function () {
263
+ it('does not throw an error if an array given', async function () {
260
264
  const S = new Schema();
261
265
  S.defineModel({
262
266
  name: 'model',
@@ -265,12 +269,12 @@ describe('ModelDataValidator', function () {
265
269
  foo: DataType.ANY,
266
270
  },
267
271
  });
268
- S.getService(ModelDataValidator).validate('model', {
272
+ await S.getService(ModelDataValidator).validate('model', {
269
273
  foo: [],
270
274
  });
271
275
  });
272
276
 
273
- it('does not throw an error if an object given', function () {
277
+ it('does not throw an error if an object given', async function () {
274
278
  const S = new Schema();
275
279
  S.defineModel({
276
280
  name: 'model',
@@ -279,14 +283,14 @@ describe('ModelDataValidator', function () {
279
283
  foo: DataType.ANY,
280
284
  },
281
285
  });
282
- S.getService(ModelDataValidator).validate('model', {
286
+ await S.getService(ModelDataValidator).validate('model', {
283
287
  foo: {},
284
288
  });
285
289
  });
286
290
  });
287
291
 
288
292
  describe('FullPropertyDefinition', function () {
289
- it('does not throw an error if an undefined given', function () {
293
+ it('does not throw an error if an undefined given', async function () {
290
294
  const S = new Schema();
291
295
  S.defineModel({
292
296
  name: 'model',
@@ -297,12 +301,12 @@ describe('ModelDataValidator', function () {
297
301
  },
298
302
  },
299
303
  });
300
- S.getService(ModelDataValidator).validate('model', {
304
+ await S.getService(ModelDataValidator).validate('model', {
301
305
  foo: undefined,
302
306
  });
303
307
  });
304
308
 
305
- it('does not throw an error if a null given', function () {
309
+ it('does not throw an error if a null given', async function () {
306
310
  const S = new Schema();
307
311
  S.defineModel({
308
312
  name: 'model',
@@ -313,12 +317,12 @@ describe('ModelDataValidator', function () {
313
317
  },
314
318
  },
315
319
  });
316
- S.getService(ModelDataValidator).validate('model', {
320
+ await S.getService(ModelDataValidator).validate('model', {
317
321
  foo: null,
318
322
  });
319
323
  });
320
324
 
321
- it('does not throw an error if a string given', function () {
325
+ it('does not throw an error if a string given', async function () {
322
326
  const S = new Schema();
323
327
  S.defineModel({
324
328
  name: 'model',
@@ -329,12 +333,12 @@ describe('ModelDataValidator', function () {
329
333
  },
330
334
  },
331
335
  });
332
- S.getService(ModelDataValidator).validate('model', {
336
+ await S.getService(ModelDataValidator).validate('model', {
333
337
  foo: 'bar',
334
338
  });
335
339
  });
336
340
 
337
- it('does not throw an error if a number given', function () {
341
+ it('does not throw an error if a number given', async function () {
338
342
  const S = new Schema();
339
343
  S.defineModel({
340
344
  name: 'model',
@@ -345,12 +349,12 @@ describe('ModelDataValidator', function () {
345
349
  },
346
350
  },
347
351
  });
348
- S.getService(ModelDataValidator).validate('model', {
352
+ await S.getService(ModelDataValidator).validate('model', {
349
353
  foo: 10,
350
354
  });
351
355
  });
352
356
 
353
- it('does not throw an error if true given', function () {
357
+ it('does not throw an error if true given', async function () {
354
358
  const S = new Schema();
355
359
  S.defineModel({
356
360
  name: 'model',
@@ -361,12 +365,12 @@ describe('ModelDataValidator', function () {
361
365
  },
362
366
  },
363
367
  });
364
- S.getService(ModelDataValidator).validate('model', {
368
+ await S.getService(ModelDataValidator).validate('model', {
365
369
  foo: true,
366
370
  });
367
371
  });
368
372
 
369
- it('does not throw an error if false given', function () {
373
+ it('does not throw an error if false given', async function () {
370
374
  const S = new Schema();
371
375
  S.defineModel({
372
376
  name: 'model',
@@ -377,12 +381,12 @@ describe('ModelDataValidator', function () {
377
381
  },
378
382
  },
379
383
  });
380
- S.getService(ModelDataValidator).validate('model', {
384
+ await S.getService(ModelDataValidator).validate('model', {
381
385
  foo: false,
382
386
  });
383
387
  });
384
388
 
385
- it('does not throw an error if an array given', function () {
389
+ it('does not throw an error if an array given', async function () {
386
390
  const S = new Schema();
387
391
  S.defineModel({
388
392
  name: 'model',
@@ -393,12 +397,12 @@ describe('ModelDataValidator', function () {
393
397
  },
394
398
  },
395
399
  });
396
- S.getService(ModelDataValidator).validate('model', {
400
+ await S.getService(ModelDataValidator).validate('model', {
397
401
  foo: [],
398
402
  });
399
403
  });
400
404
 
401
- it('does not throw an error if an object given', function () {
405
+ it('does not throw an error if an object given', async function () {
402
406
  const S = new Schema();
403
407
  S.defineModel({
404
408
  name: 'model',
@@ -409,7 +413,7 @@ describe('ModelDataValidator', function () {
409
413
  },
410
414
  },
411
415
  });
412
- S.getService(ModelDataValidator).validate('model', {
416
+ await S.getService(ModelDataValidator).validate('model', {
413
417
  foo: {},
414
418
  });
415
419
  });
@@ -418,7 +422,7 @@ describe('ModelDataValidator', function () {
418
422
 
419
423
  describe('DataType.STRING', function () {
420
424
  describe('ShortPropertyDefinition', function () {
421
- it('does not throw an error if an undefined given', function () {
425
+ it('does not throw an error if an undefined given', async function () {
422
426
  const S = new Schema();
423
427
  S.defineModel({
424
428
  name: 'model',
@@ -427,12 +431,12 @@ describe('ModelDataValidator', function () {
427
431
  foo: DataType.STRING,
428
432
  },
429
433
  });
430
- S.getService(ModelDataValidator).validate('model', {
434
+ await S.getService(ModelDataValidator).validate('model', {
431
435
  foo: undefined,
432
436
  });
433
437
  });
434
438
 
435
- it('does not throw an error if a null given', function () {
439
+ it('does not throw an error if a null given', async function () {
436
440
  const S = new Schema();
437
441
  S.defineModel({
438
442
  name: 'model',
@@ -441,12 +445,12 @@ describe('ModelDataValidator', function () {
441
445
  foo: DataType.STRING,
442
446
  },
443
447
  });
444
- S.getService(ModelDataValidator).validate('model', {
448
+ await S.getService(ModelDataValidator).validate('model', {
445
449
  foo: null,
446
450
  });
447
451
  });
448
452
 
449
- it('does not throw an error if a string given', function () {
453
+ it('does not throw an error if a string given', async function () {
450
454
  const S = new Schema();
451
455
  S.defineModel({
452
456
  name: 'model',
@@ -455,12 +459,12 @@ describe('ModelDataValidator', function () {
455
459
  foo: DataType.STRING,
456
460
  },
457
461
  });
458
- S.getService(ModelDataValidator).validate('model', {
462
+ await S.getService(ModelDataValidator).validate('model', {
459
463
  foo: 'bar',
460
464
  });
461
465
  });
462
466
 
463
- it('throws an error if a number given', function () {
467
+ it('throws an error if a number given', async function () {
464
468
  const S = new Schema();
465
469
  S.defineModel({
466
470
  name: 'model',
@@ -469,17 +473,16 @@ describe('ModelDataValidator', function () {
469
473
  foo: DataType.STRING,
470
474
  },
471
475
  });
472
- const throwable = () =>
473
- S.getService(ModelDataValidator).validate('model', {
474
- foo: 10,
475
- });
476
- expect(throwable).to.throw(
476
+ const promise = S.getService(ModelDataValidator).validate('model', {
477
+ foo: 10,
478
+ });
479
+ await expect(promise).to.be.rejectedWith(
477
480
  'The property "foo" of the model "model" must have ' +
478
481
  'a String, but Number given.',
479
482
  );
480
483
  });
481
484
 
482
- it('throws an error if true given', function () {
485
+ it('throws an error if true given', async function () {
483
486
  const S = new Schema();
484
487
  S.defineModel({
485
488
  name: 'model',
@@ -488,17 +491,16 @@ describe('ModelDataValidator', function () {
488
491
  foo: DataType.STRING,
489
492
  },
490
493
  });
491
- const throwable = () =>
492
- S.getService(ModelDataValidator).validate('model', {
493
- foo: true,
494
- });
495
- expect(throwable).to.throw(
494
+ const promise = S.getService(ModelDataValidator).validate('model', {
495
+ foo: true,
496
+ });
497
+ await expect(promise).to.be.rejectedWith(
496
498
  'The property "foo" of the model "model" must have ' +
497
499
  'a String, but Boolean given.',
498
500
  );
499
501
  });
500
502
 
501
- it('throws an error if false given', function () {
503
+ it('throws an error if false given', async function () {
502
504
  const S = new Schema();
503
505
  S.defineModel({
504
506
  name: 'model',
@@ -507,17 +509,16 @@ describe('ModelDataValidator', function () {
507
509
  foo: DataType.STRING,
508
510
  },
509
511
  });
510
- const throwable = () =>
511
- S.getService(ModelDataValidator).validate('model', {
512
- foo: false,
513
- });
514
- expect(throwable).to.throw(
512
+ const promise = S.getService(ModelDataValidator).validate('model', {
513
+ foo: false,
514
+ });
515
+ await expect(promise).to.be.rejectedWith(
515
516
  'The property "foo" of the model "model" must have ' +
516
517
  'a String, but Boolean given.',
517
518
  );
518
519
  });
519
520
 
520
- it('throws an error if an array given', function () {
521
+ it('throws an error if an array given', async function () {
521
522
  const S = new Schema();
522
523
  S.defineModel({
523
524
  name: 'model',
@@ -526,17 +527,16 @@ describe('ModelDataValidator', function () {
526
527
  foo: DataType.STRING,
527
528
  },
528
529
  });
529
- const throwable = () =>
530
- S.getService(ModelDataValidator).validate('model', {
531
- foo: [],
532
- });
533
- expect(throwable).to.throw(
530
+ const promise = S.getService(ModelDataValidator).validate('model', {
531
+ foo: [],
532
+ });
533
+ await expect(promise).to.be.rejectedWith(
534
534
  'The property "foo" of the model "model" must have ' +
535
535
  'a String, but Array given.',
536
536
  );
537
537
  });
538
538
 
539
- it('throws an error if an object given', function () {
539
+ it('throws an error if an object given', async function () {
540
540
  const S = new Schema();
541
541
  S.defineModel({
542
542
  name: 'model',
@@ -545,11 +545,10 @@ describe('ModelDataValidator', function () {
545
545
  foo: DataType.STRING,
546
546
  },
547
547
  });
548
- const throwable = () =>
549
- S.getService(ModelDataValidator).validate('model', {
550
- foo: {},
551
- });
552
- expect(throwable).to.throw(
548
+ const promise = S.getService(ModelDataValidator).validate('model', {
549
+ foo: {},
550
+ });
551
+ await expect(promise).to.be.rejectedWith(
553
552
  'The property "foo" of the model "model" must have ' +
554
553
  'a String, but Object given.',
555
554
  );
@@ -557,7 +556,7 @@ describe('ModelDataValidator', function () {
557
556
  });
558
557
 
559
558
  describe('FullPropertyDefinition', function () {
560
- it('does not throw an error if an undefined given', function () {
559
+ it('does not throw an error if an undefined given', async function () {
561
560
  const S = new Schema();
562
561
  S.defineModel({
563
562
  name: 'model',
@@ -568,12 +567,12 @@ describe('ModelDataValidator', function () {
568
567
  },
569
568
  },
570
569
  });
571
- S.getService(ModelDataValidator).validate('model', {
570
+ await S.getService(ModelDataValidator).validate('model', {
572
571
  foo: undefined,
573
572
  });
574
573
  });
575
574
 
576
- it('does not throw an error if a null given', function () {
575
+ it('does not throw an error if a null given', async function () {
577
576
  const S = new Schema();
578
577
  S.defineModel({
579
578
  name: 'model',
@@ -584,12 +583,12 @@ describe('ModelDataValidator', function () {
584
583
  },
585
584
  },
586
585
  });
587
- S.getService(ModelDataValidator).validate('model', {
586
+ await S.getService(ModelDataValidator).validate('model', {
588
587
  foo: null,
589
588
  });
590
589
  });
591
590
 
592
- it('does not throw an error if a string given', function () {
591
+ it('does not throw an error if a string given', async function () {
593
592
  const S = new Schema();
594
593
  S.defineModel({
595
594
  name: 'model',
@@ -600,12 +599,12 @@ describe('ModelDataValidator', function () {
600
599
  },
601
600
  },
602
601
  });
603
- S.getService(ModelDataValidator).validate('model', {
602
+ await S.getService(ModelDataValidator).validate('model', {
604
603
  foo: 'bar',
605
604
  });
606
605
  });
607
606
 
608
- it('throws an error if a number given', function () {
607
+ it('throws an error if a number given', async function () {
609
608
  const S = new Schema();
610
609
  S.defineModel({
611
610
  name: 'model',
@@ -616,17 +615,16 @@ describe('ModelDataValidator', function () {
616
615
  },
617
616
  },
618
617
  });
619
- const throwable = () =>
620
- S.getService(ModelDataValidator).validate('model', {
621
- foo: 10,
622
- });
623
- expect(throwable).to.throw(
618
+ const promise = S.getService(ModelDataValidator).validate('model', {
619
+ foo: 10,
620
+ });
621
+ await expect(promise).to.be.rejectedWith(
624
622
  'The property "foo" of the model "model" must have ' +
625
623
  'a String, but Number given.',
626
624
  );
627
625
  });
628
626
 
629
- it('throws an error if true given', function () {
627
+ it('throws an error if true given', async function () {
630
628
  const S = new Schema();
631
629
  S.defineModel({
632
630
  name: 'model',
@@ -637,17 +635,16 @@ describe('ModelDataValidator', function () {
637
635
  },
638
636
  },
639
637
  });
640
- const throwable = () =>
641
- S.getService(ModelDataValidator).validate('model', {
642
- foo: true,
643
- });
644
- expect(throwable).to.throw(
638
+ const promise = S.getService(ModelDataValidator).validate('model', {
639
+ foo: true,
640
+ });
641
+ await expect(promise).to.be.rejectedWith(
645
642
  'The property "foo" of the model "model" must have ' +
646
643
  'a String, but Boolean given.',
647
644
  );
648
645
  });
649
646
 
650
- it('throws an error if false given', function () {
647
+ it('throws an error if false given', async function () {
651
648
  const S = new Schema();
652
649
  S.defineModel({
653
650
  name: 'model',
@@ -658,17 +655,16 @@ describe('ModelDataValidator', function () {
658
655
  },
659
656
  },
660
657
  });
661
- const throwable = () =>
662
- S.getService(ModelDataValidator).validate('model', {
663
- foo: false,
664
- });
665
- expect(throwable).to.throw(
658
+ const promise = S.getService(ModelDataValidator).validate('model', {
659
+ foo: false,
660
+ });
661
+ await expect(promise).to.be.rejectedWith(
666
662
  'The property "foo" of the model "model" must have ' +
667
663
  'a String, but Boolean given.',
668
664
  );
669
665
  });
670
666
 
671
- it('throws an error if an array given', function () {
667
+ it('throws an error if an array given', async function () {
672
668
  const S = new Schema();
673
669
  S.defineModel({
674
670
  name: 'model',
@@ -679,17 +675,16 @@ describe('ModelDataValidator', function () {
679
675
  },
680
676
  },
681
677
  });
682
- const throwable = () =>
683
- S.getService(ModelDataValidator).validate('model', {
684
- foo: [],
685
- });
686
- expect(throwable).to.throw(
678
+ const promise = S.getService(ModelDataValidator).validate('model', {
679
+ foo: [],
680
+ });
681
+ await expect(promise).to.be.rejectedWith(
687
682
  'The property "foo" of the model "model" must have ' +
688
683
  'a String, but Array given.',
689
684
  );
690
685
  });
691
686
 
692
- it('throws an error if an object given', function () {
687
+ it('throws an error if an object given', async function () {
693
688
  const S = new Schema();
694
689
  S.defineModel({
695
690
  name: 'model',
@@ -700,11 +695,10 @@ describe('ModelDataValidator', function () {
700
695
  },
701
696
  },
702
697
  });
703
- const throwable = () =>
704
- S.getService(ModelDataValidator).validate('model', {
705
- foo: {},
706
- });
707
- expect(throwable).to.throw(
698
+ const promise = S.getService(ModelDataValidator).validate('model', {
699
+ foo: {},
700
+ });
701
+ await expect(promise).to.be.rejectedWith(
708
702
  'The property "foo" of the model "model" must have ' +
709
703
  'a String, but Object given.',
710
704
  );
@@ -714,7 +708,7 @@ describe('ModelDataValidator', function () {
714
708
 
715
709
  describe('DataType.NUMBER', function () {
716
710
  describe('ShortPropertyDefinition', function () {
717
- it('does not throw an error if an undefined given', function () {
711
+ it('does not throw an error if an undefined given', async function () {
718
712
  const S = new Schema();
719
713
  S.defineModel({
720
714
  name: 'model',
@@ -723,12 +717,12 @@ describe('ModelDataValidator', function () {
723
717
  foo: DataType.NUMBER,
724
718
  },
725
719
  });
726
- S.getService(ModelDataValidator).validate('model', {
720
+ await S.getService(ModelDataValidator).validate('model', {
727
721
  foo: undefined,
728
722
  });
729
723
  });
730
724
 
731
- it('does not throw an error if a null given', function () {
725
+ it('does not throw an error if a null given', async function () {
732
726
  const S = new Schema();
733
727
  S.defineModel({
734
728
  name: 'model',
@@ -737,12 +731,12 @@ describe('ModelDataValidator', function () {
737
731
  foo: DataType.NUMBER,
738
732
  },
739
733
  });
740
- S.getService(ModelDataValidator).validate('model', {
734
+ await S.getService(ModelDataValidator).validate('model', {
741
735
  foo: null,
742
736
  });
743
737
  });
744
738
 
745
- it('throws an error if a string given', function () {
739
+ it('throws an error if a string given', async function () {
746
740
  const S = new Schema();
747
741
  S.defineModel({
748
742
  name: 'model',
@@ -751,17 +745,16 @@ describe('ModelDataValidator', function () {
751
745
  foo: DataType.NUMBER,
752
746
  },
753
747
  });
754
- const throwable = () =>
755
- S.getService(ModelDataValidator).validate('model', {
756
- foo: 'bar',
757
- });
758
- expect(throwable).to.throw(
748
+ const promise = S.getService(ModelDataValidator).validate('model', {
749
+ foo: 'bar',
750
+ });
751
+ await expect(promise).to.be.rejectedWith(
759
752
  'The property "foo" of the model "model" must have ' +
760
753
  'a Number, but String given.',
761
754
  );
762
755
  });
763
756
 
764
- it('does not throw an error if a number given', function () {
757
+ it('does not throw an error if a number given', async function () {
765
758
  const S = new Schema();
766
759
  S.defineModel({
767
760
  name: 'model',
@@ -770,12 +763,12 @@ describe('ModelDataValidator', function () {
770
763
  foo: DataType.NUMBER,
771
764
  },
772
765
  });
773
- S.getService(ModelDataValidator).validate('model', {
766
+ await S.getService(ModelDataValidator).validate('model', {
774
767
  foo: 10,
775
768
  });
776
769
  });
777
770
 
778
- it('throws an error if true given', function () {
771
+ it('throws an error if true given', async function () {
779
772
  const S = new Schema();
780
773
  S.defineModel({
781
774
  name: 'model',
@@ -784,17 +777,16 @@ describe('ModelDataValidator', function () {
784
777
  foo: DataType.NUMBER,
785
778
  },
786
779
  });
787
- const throwable = () =>
788
- S.getService(ModelDataValidator).validate('model', {
789
- foo: true,
790
- });
791
- expect(throwable).to.throw(
780
+ const promise = S.getService(ModelDataValidator).validate('model', {
781
+ foo: true,
782
+ });
783
+ await expect(promise).to.be.rejectedWith(
792
784
  'The property "foo" of the model "model" must have ' +
793
785
  'a Number, but Boolean given.',
794
786
  );
795
787
  });
796
788
 
797
- it('throws an error if false given', function () {
789
+ it('throws an error if false given', async function () {
798
790
  const S = new Schema();
799
791
  S.defineModel({
800
792
  name: 'model',
@@ -803,17 +795,16 @@ describe('ModelDataValidator', function () {
803
795
  foo: DataType.NUMBER,
804
796
  },
805
797
  });
806
- const throwable = () =>
807
- S.getService(ModelDataValidator).validate('model', {
808
- foo: false,
809
- });
810
- expect(throwable).to.throw(
798
+ const promise = S.getService(ModelDataValidator).validate('model', {
799
+ foo: false,
800
+ });
801
+ await expect(promise).to.be.rejectedWith(
811
802
  'The property "foo" of the model "model" must have ' +
812
803
  'a Number, but Boolean given.',
813
804
  );
814
805
  });
815
806
 
816
- it('throws an error if an array given', function () {
807
+ it('throws an error if an array given', async function () {
817
808
  const S = new Schema();
818
809
  S.defineModel({
819
810
  name: 'model',
@@ -822,17 +813,16 @@ describe('ModelDataValidator', function () {
822
813
  foo: DataType.NUMBER,
823
814
  },
824
815
  });
825
- const throwable = () =>
826
- S.getService(ModelDataValidator).validate('model', {
827
- foo: [],
828
- });
829
- expect(throwable).to.throw(
816
+ const promise = S.getService(ModelDataValidator).validate('model', {
817
+ foo: [],
818
+ });
819
+ await expect(promise).to.be.rejectedWith(
830
820
  'The property "foo" of the model "model" must have ' +
831
821
  'a Number, but Array given.',
832
822
  );
833
823
  });
834
824
 
835
- it('throws an error if an object given', function () {
825
+ it('throws an error if an object given', async function () {
836
826
  const S = new Schema();
837
827
  S.defineModel({
838
828
  name: 'model',
@@ -841,11 +831,10 @@ describe('ModelDataValidator', function () {
841
831
  foo: DataType.NUMBER,
842
832
  },
843
833
  });
844
- const throwable = () =>
845
- S.getService(ModelDataValidator).validate('model', {
846
- foo: {},
847
- });
848
- expect(throwable).to.throw(
834
+ const promise = S.getService(ModelDataValidator).validate('model', {
835
+ foo: {},
836
+ });
837
+ await expect(promise).to.be.rejectedWith(
849
838
  'The property "foo" of the model "model" must have ' +
850
839
  'a Number, but Object given.',
851
840
  );
@@ -853,7 +842,7 @@ describe('ModelDataValidator', function () {
853
842
  });
854
843
 
855
844
  describe('FullPropertyDefinition', function () {
856
- it('does not throw an error if an undefined given', function () {
845
+ it('does not throw an error if an undefined given', async function () {
857
846
  const S = new Schema();
858
847
  S.defineModel({
859
848
  name: 'model',
@@ -864,12 +853,12 @@ describe('ModelDataValidator', function () {
864
853
  },
865
854
  },
866
855
  });
867
- S.getService(ModelDataValidator).validate('model', {
856
+ await S.getService(ModelDataValidator).validate('model', {
868
857
  foo: undefined,
869
858
  });
870
859
  });
871
860
 
872
- it('does not throw an error if a null given', function () {
861
+ it('does not throw an error if a null given', async function () {
873
862
  const S = new Schema();
874
863
  S.defineModel({
875
864
  name: 'model',
@@ -880,12 +869,12 @@ describe('ModelDataValidator', function () {
880
869
  },
881
870
  },
882
871
  });
883
- S.getService(ModelDataValidator).validate('model', {
872
+ await S.getService(ModelDataValidator).validate('model', {
884
873
  foo: null,
885
874
  });
886
875
  });
887
876
 
888
- it('throws an error if a string given', function () {
877
+ it('throws an error if a string given', async function () {
889
878
  const S = new Schema();
890
879
  S.defineModel({
891
880
  name: 'model',
@@ -896,17 +885,16 @@ describe('ModelDataValidator', function () {
896
885
  },
897
886
  },
898
887
  });
899
- const throwable = () =>
900
- S.getService(ModelDataValidator).validate('model', {
901
- foo: 'bar',
902
- });
903
- expect(throwable).to.throw(
888
+ const promise = S.getService(ModelDataValidator).validate('model', {
889
+ foo: 'bar',
890
+ });
891
+ await expect(promise).to.be.rejectedWith(
904
892
  'The property "foo" of the model "model" must have ' +
905
893
  'a Number, but String given.',
906
894
  );
907
895
  });
908
896
 
909
- it('does not throw an error if a number given', function () {
897
+ it('does not throw an error if a number given', async function () {
910
898
  const S = new Schema();
911
899
  S.defineModel({
912
900
  name: 'model',
@@ -917,12 +905,12 @@ describe('ModelDataValidator', function () {
917
905
  },
918
906
  },
919
907
  });
920
- S.getService(ModelDataValidator).validate('model', {
908
+ await S.getService(ModelDataValidator).validate('model', {
921
909
  foo: 10,
922
910
  });
923
911
  });
924
912
 
925
- it('throws an error if true given', function () {
913
+ it('throws an error if true given', async function () {
926
914
  const S = new Schema();
927
915
  S.defineModel({
928
916
  name: 'model',
@@ -933,17 +921,16 @@ describe('ModelDataValidator', function () {
933
921
  },
934
922
  },
935
923
  });
936
- const throwable = () =>
937
- S.getService(ModelDataValidator).validate('model', {
938
- foo: true,
939
- });
940
- expect(throwable).to.throw(
924
+ const promise = S.getService(ModelDataValidator).validate('model', {
925
+ foo: true,
926
+ });
927
+ await expect(promise).to.be.rejectedWith(
941
928
  'The property "foo" of the model "model" must have ' +
942
929
  'a Number, but Boolean given.',
943
930
  );
944
931
  });
945
932
 
946
- it('throws an error if false given', function () {
933
+ it('throws an error if false given', async function () {
947
934
  const S = new Schema();
948
935
  S.defineModel({
949
936
  name: 'model',
@@ -954,17 +941,16 @@ describe('ModelDataValidator', function () {
954
941
  },
955
942
  },
956
943
  });
957
- const throwable = () =>
958
- S.getService(ModelDataValidator).validate('model', {
959
- foo: false,
960
- });
961
- expect(throwable).to.throw(
944
+ const promise = S.getService(ModelDataValidator).validate('model', {
945
+ foo: false,
946
+ });
947
+ await expect(promise).to.be.rejectedWith(
962
948
  'The property "foo" of the model "model" must have ' +
963
949
  'a Number, but Boolean given.',
964
950
  );
965
951
  });
966
952
 
967
- it('throws an error if an array given', function () {
953
+ it('throws an error if an array given', async function () {
968
954
  const S = new Schema();
969
955
  S.defineModel({
970
956
  name: 'model',
@@ -975,17 +961,16 @@ describe('ModelDataValidator', function () {
975
961
  },
976
962
  },
977
963
  });
978
- const throwable = () =>
979
- S.getService(ModelDataValidator).validate('model', {
980
- foo: [],
981
- });
982
- expect(throwable).to.throw(
964
+ const promise = S.getService(ModelDataValidator).validate('model', {
965
+ foo: [],
966
+ });
967
+ await expect(promise).to.be.rejectedWith(
983
968
  'The property "foo" of the model "model" must have ' +
984
969
  'a Number, but Array given.',
985
970
  );
986
971
  });
987
972
 
988
- it('throws an error if an object given', function () {
973
+ it('throws an error if an object given', async function () {
989
974
  const S = new Schema();
990
975
  S.defineModel({
991
976
  name: 'model',
@@ -996,11 +981,10 @@ describe('ModelDataValidator', function () {
996
981
  },
997
982
  },
998
983
  });
999
- const throwable = () =>
1000
- S.getService(ModelDataValidator).validate('model', {
1001
- foo: {},
1002
- });
1003
- expect(throwable).to.throw(
984
+ const promise = S.getService(ModelDataValidator).validate('model', {
985
+ foo: {},
986
+ });
987
+ await expect(promise).to.be.rejectedWith(
1004
988
  'The property "foo" of the model "model" must have ' +
1005
989
  'a Number, but Object given.',
1006
990
  );
@@ -1010,7 +994,7 @@ describe('ModelDataValidator', function () {
1010
994
 
1011
995
  describe('DataType.BOOLEAN', function () {
1012
996
  describe('ShortPropertyDefinition', function () {
1013
- it('does not throw an error if an undefined given', function () {
997
+ it('does not throw an error if an undefined given', async function () {
1014
998
  const S = new Schema();
1015
999
  S.defineModel({
1016
1000
  name: 'model',
@@ -1019,12 +1003,12 @@ describe('ModelDataValidator', function () {
1019
1003
  foo: DataType.BOOLEAN,
1020
1004
  },
1021
1005
  });
1022
- S.getService(ModelDataValidator).validate('model', {
1006
+ await S.getService(ModelDataValidator).validate('model', {
1023
1007
  foo: undefined,
1024
1008
  });
1025
1009
  });
1026
1010
 
1027
- it('does not throw an error if a null given', function () {
1011
+ it('does not throw an error if a null given', async function () {
1028
1012
  const S = new Schema();
1029
1013
  S.defineModel({
1030
1014
  name: 'model',
@@ -1033,12 +1017,12 @@ describe('ModelDataValidator', function () {
1033
1017
  foo: DataType.BOOLEAN,
1034
1018
  },
1035
1019
  });
1036
- S.getService(ModelDataValidator).validate('model', {
1020
+ await S.getService(ModelDataValidator).validate('model', {
1037
1021
  foo: null,
1038
1022
  });
1039
1023
  });
1040
1024
 
1041
- it('throws an error if a string given', function () {
1025
+ it('throws an error if a string given', async function () {
1042
1026
  const S = new Schema();
1043
1027
  S.defineModel({
1044
1028
  name: 'model',
@@ -1047,17 +1031,16 @@ describe('ModelDataValidator', function () {
1047
1031
  foo: DataType.BOOLEAN,
1048
1032
  },
1049
1033
  });
1050
- const throwable = () =>
1051
- S.getService(ModelDataValidator).validate('model', {
1052
- foo: 'bar',
1053
- });
1054
- expect(throwable).to.throw(
1034
+ const promise = S.getService(ModelDataValidator).validate('model', {
1035
+ foo: 'bar',
1036
+ });
1037
+ await expect(promise).to.be.rejectedWith(
1055
1038
  'The property "foo" of the model "model" must have ' +
1056
1039
  'a Boolean, but String given.',
1057
1040
  );
1058
1041
  });
1059
1042
 
1060
- it('throws an error if a number given', function () {
1043
+ it('throws an error if a number given', async function () {
1061
1044
  const S = new Schema();
1062
1045
  S.defineModel({
1063
1046
  name: 'model',
@@ -1066,17 +1049,16 @@ describe('ModelDataValidator', function () {
1066
1049
  foo: DataType.BOOLEAN,
1067
1050
  },
1068
1051
  });
1069
- const throwable = () =>
1070
- S.getService(ModelDataValidator).validate('model', {
1071
- foo: 10,
1072
- });
1073
- expect(throwable).to.throw(
1052
+ const promise = S.getService(ModelDataValidator).validate('model', {
1053
+ foo: 10,
1054
+ });
1055
+ await expect(promise).to.be.rejectedWith(
1074
1056
  'The property "foo" of the model "model" must have ' +
1075
1057
  'a Boolean, but Number given.',
1076
1058
  );
1077
1059
  });
1078
1060
 
1079
- it('does not throw an error if true given', function () {
1061
+ it('does not throw an error if true given', async function () {
1080
1062
  const S = new Schema();
1081
1063
  S.defineModel({
1082
1064
  name: 'model',
@@ -1085,12 +1067,12 @@ describe('ModelDataValidator', function () {
1085
1067
  foo: DataType.BOOLEAN,
1086
1068
  },
1087
1069
  });
1088
- S.getService(ModelDataValidator).validate('model', {
1070
+ await S.getService(ModelDataValidator).validate('model', {
1089
1071
  foo: true,
1090
1072
  });
1091
1073
  });
1092
1074
 
1093
- it('does not throw an error if false given', function () {
1075
+ it('does not throw an error if false given', async function () {
1094
1076
  const S = new Schema();
1095
1077
  S.defineModel({
1096
1078
  name: 'model',
@@ -1099,12 +1081,12 @@ describe('ModelDataValidator', function () {
1099
1081
  foo: DataType.BOOLEAN,
1100
1082
  },
1101
1083
  });
1102
- S.getService(ModelDataValidator).validate('model', {
1084
+ await S.getService(ModelDataValidator).validate('model', {
1103
1085
  foo: false,
1104
1086
  });
1105
1087
  });
1106
1088
 
1107
- it('throws an error if an array given', function () {
1089
+ it('throws an error if an array given', async function () {
1108
1090
  const S = new Schema();
1109
1091
  S.defineModel({
1110
1092
  name: 'model',
@@ -1113,17 +1095,16 @@ describe('ModelDataValidator', function () {
1113
1095
  foo: DataType.BOOLEAN,
1114
1096
  },
1115
1097
  });
1116
- const throwable = () =>
1117
- S.getService(ModelDataValidator).validate('model', {
1118
- foo: [],
1119
- });
1120
- expect(throwable).to.throw(
1098
+ const promise = S.getService(ModelDataValidator).validate('model', {
1099
+ foo: [],
1100
+ });
1101
+ await expect(promise).to.be.rejectedWith(
1121
1102
  'The property "foo" of the model "model" must have ' +
1122
1103
  'a Boolean, but Array given.',
1123
1104
  );
1124
1105
  });
1125
1106
 
1126
- it('throws an error if an object given', function () {
1107
+ it('throws an error if an object given', async function () {
1127
1108
  const S = new Schema();
1128
1109
  S.defineModel({
1129
1110
  name: 'model',
@@ -1132,11 +1113,10 @@ describe('ModelDataValidator', function () {
1132
1113
  foo: DataType.BOOLEAN,
1133
1114
  },
1134
1115
  });
1135
- const throwable = () =>
1136
- S.getService(ModelDataValidator).validate('model', {
1137
- foo: {},
1138
- });
1139
- expect(throwable).to.throw(
1116
+ const promise = S.getService(ModelDataValidator).validate('model', {
1117
+ foo: {},
1118
+ });
1119
+ await expect(promise).to.be.rejectedWith(
1140
1120
  'The property "foo" of the model "model" must have ' +
1141
1121
  'a Boolean, but Object given.',
1142
1122
  );
@@ -1144,7 +1124,7 @@ describe('ModelDataValidator', function () {
1144
1124
  });
1145
1125
 
1146
1126
  describe('FullPropertyDefinition', function () {
1147
- it('does not throw an error if an undefined given', function () {
1127
+ it('does not throw an error if an undefined given', async function () {
1148
1128
  const S = new Schema();
1149
1129
  S.defineModel({
1150
1130
  name: 'model',
@@ -1155,12 +1135,12 @@ describe('ModelDataValidator', function () {
1155
1135
  },
1156
1136
  },
1157
1137
  });
1158
- S.getService(ModelDataValidator).validate('model', {
1138
+ await S.getService(ModelDataValidator).validate('model', {
1159
1139
  foo: undefined,
1160
1140
  });
1161
1141
  });
1162
1142
 
1163
- it('does not throw an error if a null given', function () {
1143
+ it('does not throw an error if a null given', async function () {
1164
1144
  const S = new Schema();
1165
1145
  S.defineModel({
1166
1146
  name: 'model',
@@ -1171,12 +1151,12 @@ describe('ModelDataValidator', function () {
1171
1151
  },
1172
1152
  },
1173
1153
  });
1174
- S.getService(ModelDataValidator).validate('model', {
1154
+ await S.getService(ModelDataValidator).validate('model', {
1175
1155
  foo: null,
1176
1156
  });
1177
1157
  });
1178
1158
 
1179
- it('throws an error if a string given', function () {
1159
+ it('throws an error if a string given', async function () {
1180
1160
  const S = new Schema();
1181
1161
  S.defineModel({
1182
1162
  name: 'model',
@@ -1187,17 +1167,16 @@ describe('ModelDataValidator', function () {
1187
1167
  },
1188
1168
  },
1189
1169
  });
1190
- const throwable = () =>
1191
- S.getService(ModelDataValidator).validate('model', {
1192
- foo: 'bar',
1193
- });
1194
- expect(throwable).to.throw(
1170
+ const promise = S.getService(ModelDataValidator).validate('model', {
1171
+ foo: 'bar',
1172
+ });
1173
+ await expect(promise).to.be.rejectedWith(
1195
1174
  'The property "foo" of the model "model" must have ' +
1196
1175
  'a Boolean, but String given.',
1197
1176
  );
1198
1177
  });
1199
1178
 
1200
- it('throws an error if a number given', function () {
1179
+ it('throws an error if a number given', async function () {
1201
1180
  const S = new Schema();
1202
1181
  S.defineModel({
1203
1182
  name: 'model',
@@ -1208,17 +1187,16 @@ describe('ModelDataValidator', function () {
1208
1187
  },
1209
1188
  },
1210
1189
  });
1211
- const throwable = () =>
1212
- S.getService(ModelDataValidator).validate('model', {
1213
- foo: 10,
1214
- });
1215
- expect(throwable).to.throw(
1190
+ const promise = S.getService(ModelDataValidator).validate('model', {
1191
+ foo: 10,
1192
+ });
1193
+ await expect(promise).to.be.rejectedWith(
1216
1194
  'The property "foo" of the model "model" must have ' +
1217
1195
  'a Boolean, but Number given.',
1218
1196
  );
1219
1197
  });
1220
1198
 
1221
- it('does not throw an error if true given', function () {
1199
+ it('does not throw an error if true given', async function () {
1222
1200
  const S = new Schema();
1223
1201
  S.defineModel({
1224
1202
  name: 'model',
@@ -1229,12 +1207,12 @@ describe('ModelDataValidator', function () {
1229
1207
  },
1230
1208
  },
1231
1209
  });
1232
- S.getService(ModelDataValidator).validate('model', {
1210
+ await S.getService(ModelDataValidator).validate('model', {
1233
1211
  foo: true,
1234
1212
  });
1235
1213
  });
1236
1214
 
1237
- it('does not throw an error if false given', function () {
1215
+ it('does not throw an error if false given', async function () {
1238
1216
  const S = new Schema();
1239
1217
  S.defineModel({
1240
1218
  name: 'model',
@@ -1245,12 +1223,12 @@ describe('ModelDataValidator', function () {
1245
1223
  },
1246
1224
  },
1247
1225
  });
1248
- S.getService(ModelDataValidator).validate('model', {
1226
+ await S.getService(ModelDataValidator).validate('model', {
1249
1227
  foo: false,
1250
1228
  });
1251
1229
  });
1252
1230
 
1253
- it('throws an error if an array given', function () {
1231
+ it('throws an error if an array given', async function () {
1254
1232
  const S = new Schema();
1255
1233
  S.defineModel({
1256
1234
  name: 'model',
@@ -1261,17 +1239,16 @@ describe('ModelDataValidator', function () {
1261
1239
  },
1262
1240
  },
1263
1241
  });
1264
- const throwable = () =>
1265
- S.getService(ModelDataValidator).validate('model', {
1266
- foo: [],
1267
- });
1268
- expect(throwable).to.throw(
1242
+ const promise = S.getService(ModelDataValidator).validate('model', {
1243
+ foo: [],
1244
+ });
1245
+ await expect(promise).to.be.rejectedWith(
1269
1246
  'The property "foo" of the model "model" must have ' +
1270
1247
  'a Boolean, but Array given.',
1271
1248
  );
1272
1249
  });
1273
1250
 
1274
- it('throws an error if an object given', function () {
1251
+ it('throws an error if an object given', async function () {
1275
1252
  const S = new Schema();
1276
1253
  S.defineModel({
1277
1254
  name: 'model',
@@ -1282,11 +1259,10 @@ describe('ModelDataValidator', function () {
1282
1259
  },
1283
1260
  },
1284
1261
  });
1285
- const throwable = () =>
1286
- S.getService(ModelDataValidator).validate('model', {
1287
- foo: {},
1288
- });
1289
- expect(throwable).to.throw(
1262
+ const promise = S.getService(ModelDataValidator).validate('model', {
1263
+ foo: {},
1264
+ });
1265
+ await expect(promise).to.be.rejectedWith(
1290
1266
  'The property "foo" of the model "model" must have ' +
1291
1267
  'a Boolean, but Object given.',
1292
1268
  );
@@ -1296,7 +1272,7 @@ describe('ModelDataValidator', function () {
1296
1272
 
1297
1273
  describe('DataType.ARRAY', function () {
1298
1274
  describe('ShortPropertyDefinition', function () {
1299
- it('does not throw an error if an undefined given', function () {
1275
+ it('does not throw an error if an undefined given', async function () {
1300
1276
  const S = new Schema();
1301
1277
  S.defineModel({
1302
1278
  name: 'model',
@@ -1305,12 +1281,12 @@ describe('ModelDataValidator', function () {
1305
1281
  foo: DataType.ARRAY,
1306
1282
  },
1307
1283
  });
1308
- S.getService(ModelDataValidator).validate('model', {
1284
+ await S.getService(ModelDataValidator).validate('model', {
1309
1285
  foo: undefined,
1310
1286
  });
1311
1287
  });
1312
1288
 
1313
- it('does not throw an error if a null given', function () {
1289
+ it('does not throw an error if a null given', async function () {
1314
1290
  const S = new Schema();
1315
1291
  S.defineModel({
1316
1292
  name: 'model',
@@ -1319,12 +1295,12 @@ describe('ModelDataValidator', function () {
1319
1295
  foo: DataType.ARRAY,
1320
1296
  },
1321
1297
  });
1322
- S.getService(ModelDataValidator).validate('model', {
1298
+ await S.getService(ModelDataValidator).validate('model', {
1323
1299
  foo: null,
1324
1300
  });
1325
1301
  });
1326
1302
 
1327
- it('throws an error if a string given', function () {
1303
+ it('throws an error if a string given', async function () {
1328
1304
  const S = new Schema();
1329
1305
  S.defineModel({
1330
1306
  name: 'model',
@@ -1333,17 +1309,16 @@ describe('ModelDataValidator', function () {
1333
1309
  foo: DataType.ARRAY,
1334
1310
  },
1335
1311
  });
1336
- const throwable = () =>
1337
- S.getService(ModelDataValidator).validate('model', {
1338
- foo: 'bar',
1339
- });
1340
- expect(throwable).to.throw(
1312
+ const promise = S.getService(ModelDataValidator).validate('model', {
1313
+ foo: 'bar',
1314
+ });
1315
+ await expect(promise).to.be.rejectedWith(
1341
1316
  'The property "foo" of the model "model" must have ' +
1342
1317
  'an Array, but String given.',
1343
1318
  );
1344
1319
  });
1345
1320
 
1346
- it('throws an error if a number given', function () {
1321
+ it('throws an error if a number given', async function () {
1347
1322
  const S = new Schema();
1348
1323
  S.defineModel({
1349
1324
  name: 'model',
@@ -1352,17 +1327,16 @@ describe('ModelDataValidator', function () {
1352
1327
  foo: DataType.ARRAY,
1353
1328
  },
1354
1329
  });
1355
- const throwable = () =>
1356
- S.getService(ModelDataValidator).validate('model', {
1357
- foo: 10,
1358
- });
1359
- expect(throwable).to.throw(
1330
+ const promise = S.getService(ModelDataValidator).validate('model', {
1331
+ foo: 10,
1332
+ });
1333
+ await expect(promise).to.be.rejectedWith(
1360
1334
  'The property "foo" of the model "model" must have ' +
1361
1335
  'an Array, but Number given.',
1362
1336
  );
1363
1337
  });
1364
1338
 
1365
- it('throws an error if true given', function () {
1339
+ it('throws an error if true given', async function () {
1366
1340
  const S = new Schema();
1367
1341
  S.defineModel({
1368
1342
  name: 'model',
@@ -1371,17 +1345,16 @@ describe('ModelDataValidator', function () {
1371
1345
  foo: DataType.ARRAY,
1372
1346
  },
1373
1347
  });
1374
- const throwable = () =>
1375
- S.getService(ModelDataValidator).validate('model', {
1376
- foo: true,
1377
- });
1378
- expect(throwable).to.throw(
1348
+ const promise = S.getService(ModelDataValidator).validate('model', {
1349
+ foo: true,
1350
+ });
1351
+ await expect(promise).to.be.rejectedWith(
1379
1352
  'The property "foo" of the model "model" must have ' +
1380
1353
  'an Array, but Boolean given.',
1381
1354
  );
1382
1355
  });
1383
1356
 
1384
- it('throws an error if false given', function () {
1357
+ it('throws an error if false given', async function () {
1385
1358
  const S = new Schema();
1386
1359
  S.defineModel({
1387
1360
  name: 'model',
@@ -1390,17 +1363,16 @@ describe('ModelDataValidator', function () {
1390
1363
  foo: DataType.ARRAY,
1391
1364
  },
1392
1365
  });
1393
- const throwable = () =>
1394
- S.getService(ModelDataValidator).validate('model', {
1395
- foo: false,
1396
- });
1397
- expect(throwable).to.throw(
1366
+ const promise = S.getService(ModelDataValidator).validate('model', {
1367
+ foo: false,
1368
+ });
1369
+ await expect(promise).to.be.rejectedWith(
1398
1370
  'The property "foo" of the model "model" must have ' +
1399
1371
  'an Array, but Boolean given.',
1400
1372
  );
1401
1373
  });
1402
1374
 
1403
- it('does not throw an error if an array given', function () {
1375
+ it('does not throw an error if an array given', async function () {
1404
1376
  const S = new Schema();
1405
1377
  S.defineModel({
1406
1378
  name: 'model',
@@ -1409,12 +1381,12 @@ describe('ModelDataValidator', function () {
1409
1381
  foo: DataType.ARRAY,
1410
1382
  },
1411
1383
  });
1412
- S.getService(ModelDataValidator).validate('model', {
1384
+ await S.getService(ModelDataValidator).validate('model', {
1413
1385
  foo: [],
1414
1386
  });
1415
1387
  });
1416
1388
 
1417
- it('throws an error if an object given', function () {
1389
+ it('throws an error if an object given', async function () {
1418
1390
  const S = new Schema();
1419
1391
  S.defineModel({
1420
1392
  name: 'model',
@@ -1423,11 +1395,10 @@ describe('ModelDataValidator', function () {
1423
1395
  foo: DataType.ARRAY,
1424
1396
  },
1425
1397
  });
1426
- const throwable = () =>
1427
- S.getService(ModelDataValidator).validate('model', {
1428
- foo: {},
1429
- });
1430
- expect(throwable).to.throw(
1398
+ const promise = S.getService(ModelDataValidator).validate('model', {
1399
+ foo: {},
1400
+ });
1401
+ await expect(promise).to.be.rejectedWith(
1431
1402
  'The property "foo" of the model "model" must have ' +
1432
1403
  'an Array, but Object given.',
1433
1404
  );
@@ -1435,7 +1406,7 @@ describe('ModelDataValidator', function () {
1435
1406
  });
1436
1407
 
1437
1408
  describe('FullPropertyDefinition', function () {
1438
- it('does not throw an error if an undefined given', function () {
1409
+ it('does not throw an error if an undefined given', async function () {
1439
1410
  const S = new Schema();
1440
1411
  S.defineModel({
1441
1412
  name: 'model',
@@ -1446,12 +1417,12 @@ describe('ModelDataValidator', function () {
1446
1417
  },
1447
1418
  },
1448
1419
  });
1449
- S.getService(ModelDataValidator).validate('model', {
1420
+ await S.getService(ModelDataValidator).validate('model', {
1450
1421
  foo: undefined,
1451
1422
  });
1452
1423
  });
1453
1424
 
1454
- it('does not throw an error if a null given', function () {
1425
+ it('does not throw an error if a null given', async function () {
1455
1426
  const S = new Schema();
1456
1427
  S.defineModel({
1457
1428
  name: 'model',
@@ -1462,12 +1433,12 @@ describe('ModelDataValidator', function () {
1462
1433
  },
1463
1434
  },
1464
1435
  });
1465
- S.getService(ModelDataValidator).validate('model', {
1436
+ await S.getService(ModelDataValidator).validate('model', {
1466
1437
  foo: null,
1467
1438
  });
1468
1439
  });
1469
1440
 
1470
- it('throws an error if a string given', function () {
1441
+ it('throws an error if a string given', async function () {
1471
1442
  const S = new Schema();
1472
1443
  S.defineModel({
1473
1444
  name: 'model',
@@ -1478,17 +1449,16 @@ describe('ModelDataValidator', function () {
1478
1449
  },
1479
1450
  },
1480
1451
  });
1481
- const throwable = () =>
1482
- S.getService(ModelDataValidator).validate('model', {
1483
- foo: 'bar',
1484
- });
1485
- expect(throwable).to.throw(
1452
+ const promise = S.getService(ModelDataValidator).validate('model', {
1453
+ foo: 'bar',
1454
+ });
1455
+ await expect(promise).to.be.rejectedWith(
1486
1456
  'The property "foo" of the model "model" must have ' +
1487
1457
  'an Array, but String given.',
1488
1458
  );
1489
1459
  });
1490
1460
 
1491
- it('throws an error if a number given', function () {
1461
+ it('throws an error if a number given', async function () {
1492
1462
  const S = new Schema();
1493
1463
  S.defineModel({
1494
1464
  name: 'model',
@@ -1499,17 +1469,16 @@ describe('ModelDataValidator', function () {
1499
1469
  },
1500
1470
  },
1501
1471
  });
1502
- const throwable = () =>
1503
- S.getService(ModelDataValidator).validate('model', {
1504
- foo: 10,
1505
- });
1506
- expect(throwable).to.throw(
1472
+ const promise = S.getService(ModelDataValidator).validate('model', {
1473
+ foo: 10,
1474
+ });
1475
+ await expect(promise).to.be.rejectedWith(
1507
1476
  'The property "foo" of the model "model" must have ' +
1508
1477
  'an Array, but Number given.',
1509
1478
  );
1510
1479
  });
1511
1480
 
1512
- it('throws an error if true given', function () {
1481
+ it('throws an error if true given', async function () {
1513
1482
  const S = new Schema();
1514
1483
  S.defineModel({
1515
1484
  name: 'model',
@@ -1520,17 +1489,16 @@ describe('ModelDataValidator', function () {
1520
1489
  },
1521
1490
  },
1522
1491
  });
1523
- const throwable = () =>
1524
- S.getService(ModelDataValidator).validate('model', {
1525
- foo: true,
1526
- });
1527
- expect(throwable).to.throw(
1492
+ const promise = S.getService(ModelDataValidator).validate('model', {
1493
+ foo: true,
1494
+ });
1495
+ await expect(promise).to.be.rejectedWith(
1528
1496
  'The property "foo" of the model "model" must have ' +
1529
1497
  'an Array, but Boolean given.',
1530
1498
  );
1531
1499
  });
1532
1500
 
1533
- it('throws an error if false given', function () {
1501
+ it('throws an error if false given', async function () {
1534
1502
  const S = new Schema();
1535
1503
  S.defineModel({
1536
1504
  name: 'model',
@@ -1541,17 +1509,16 @@ describe('ModelDataValidator', function () {
1541
1509
  },
1542
1510
  },
1543
1511
  });
1544
- const throwable = () =>
1545
- S.getService(ModelDataValidator).validate('model', {
1546
- foo: false,
1547
- });
1548
- expect(throwable).to.throw(
1512
+ const promise = S.getService(ModelDataValidator).validate('model', {
1513
+ foo: false,
1514
+ });
1515
+ await expect(promise).to.be.rejectedWith(
1549
1516
  'The property "foo" of the model "model" must have ' +
1550
1517
  'an Array, but Boolean given.',
1551
1518
  );
1552
1519
  });
1553
1520
 
1554
- it('does not throw an error if an array given', function () {
1521
+ it('does not throw an error if an array given', async function () {
1555
1522
  const S = new Schema();
1556
1523
  S.defineModel({
1557
1524
  name: 'model',
@@ -1562,12 +1529,12 @@ describe('ModelDataValidator', function () {
1562
1529
  },
1563
1530
  },
1564
1531
  });
1565
- S.getService(ModelDataValidator).validate('model', {
1532
+ await S.getService(ModelDataValidator).validate('model', {
1566
1533
  foo: [],
1567
1534
  });
1568
1535
  });
1569
1536
 
1570
- it('throws an error if an object given', function () {
1537
+ it('throws an error if an object given', async function () {
1571
1538
  const S = new Schema();
1572
1539
  S.defineModel({
1573
1540
  name: 'model',
@@ -1578,18 +1545,17 @@ describe('ModelDataValidator', function () {
1578
1545
  },
1579
1546
  },
1580
1547
  });
1581
- const throwable = () =>
1582
- S.getService(ModelDataValidator).validate('model', {
1583
- foo: {},
1584
- });
1585
- expect(throwable).to.throw(
1548
+ const promise = S.getService(ModelDataValidator).validate('model', {
1549
+ foo: {},
1550
+ });
1551
+ await expect(promise).to.be.rejectedWith(
1586
1552
  'The property "foo" of the model "model" must have ' +
1587
1553
  'an Array, but Object given.',
1588
1554
  );
1589
1555
  });
1590
1556
 
1591
1557
  describe('the "model" option', function () {
1592
- it('throws an error when the given object element has an invalid model', function () {
1558
+ it('throws an error when the given object element has an invalid model', async function () {
1593
1559
  const S = new Schema();
1594
1560
  S.defineModel({
1595
1561
  name: 'modelA',
@@ -1608,17 +1574,19 @@ describe('ModelDataValidator', function () {
1608
1574
  },
1609
1575
  },
1610
1576
  });
1611
- const throwable = () =>
1612
- S.getService(ModelDataValidator).validate('modelB', {
1577
+ const promise = S.getService(ModelDataValidator).validate(
1578
+ 'modelB',
1579
+ {
1613
1580
  bar: [{foo: 10}],
1614
- });
1615
- expect(throwable).to.throw(
1581
+ },
1582
+ );
1583
+ await expect(promise).to.be.rejectedWith(
1616
1584
  'The property "foo" of the model "modelA" must have ' +
1617
1585
  'a String, but Number given.',
1618
1586
  );
1619
1587
  });
1620
1588
 
1621
- it('does not throw an error when the given object element has a valid model', function () {
1589
+ it('does not throw an error when the given object element has a valid model', async function () {
1622
1590
  const S = new Schema();
1623
1591
  S.defineModel({
1624
1592
  name: 'modelA',
@@ -1637,7 +1605,7 @@ describe('ModelDataValidator', function () {
1637
1605
  },
1638
1606
  },
1639
1607
  });
1640
- S.getService(ModelDataValidator).validate('modelB', {
1608
+ await S.getService(ModelDataValidator).validate('modelB', {
1641
1609
  bar: [{foo: '10'}],
1642
1610
  });
1643
1611
  });
@@ -1647,7 +1615,7 @@ describe('ModelDataValidator', function () {
1647
1615
 
1648
1616
  describe('DataType.OBJECT', function () {
1649
1617
  describe('ShortPropertyDefinition', function () {
1650
- it('does not throw an error if an undefined given', function () {
1618
+ it('does not throw an error if an undefined given', async function () {
1651
1619
  const S = new Schema();
1652
1620
  S.defineModel({
1653
1621
  name: 'model',
@@ -1656,12 +1624,12 @@ describe('ModelDataValidator', function () {
1656
1624
  foo: DataType.OBJECT,
1657
1625
  },
1658
1626
  });
1659
- S.getService(ModelDataValidator).validate('model', {
1627
+ await S.getService(ModelDataValidator).validate('model', {
1660
1628
  foo: undefined,
1661
1629
  });
1662
1630
  });
1663
1631
 
1664
- it('does not throw an error if a null given', function () {
1632
+ it('does not throw an error if a null given', async function () {
1665
1633
  const S = new Schema();
1666
1634
  S.defineModel({
1667
1635
  name: 'model',
@@ -1670,12 +1638,12 @@ describe('ModelDataValidator', function () {
1670
1638
  foo: DataType.OBJECT,
1671
1639
  },
1672
1640
  });
1673
- S.getService(ModelDataValidator).validate('model', {
1641
+ await S.getService(ModelDataValidator).validate('model', {
1674
1642
  foo: null,
1675
1643
  });
1676
1644
  });
1677
1645
 
1678
- it('throws an error if a string given', function () {
1646
+ it('throws an error if a string given', async function () {
1679
1647
  const S = new Schema();
1680
1648
  S.defineModel({
1681
1649
  name: 'model',
@@ -1684,17 +1652,16 @@ describe('ModelDataValidator', function () {
1684
1652
  foo: DataType.OBJECT,
1685
1653
  },
1686
1654
  });
1687
- const throwable = () =>
1688
- S.getService(ModelDataValidator).validate('model', {
1689
- foo: 'bar',
1690
- });
1691
- expect(throwable).to.throw(
1655
+ const promise = S.getService(ModelDataValidator).validate('model', {
1656
+ foo: 'bar',
1657
+ });
1658
+ await expect(promise).to.be.rejectedWith(
1692
1659
  'The property "foo" of the model "model" must have ' +
1693
1660
  'an Object, but String given.',
1694
1661
  );
1695
1662
  });
1696
1663
 
1697
- it('throws an error if a number given', function () {
1664
+ it('throws an error if a number given', async function () {
1698
1665
  const S = new Schema();
1699
1666
  S.defineModel({
1700
1667
  name: 'model',
@@ -1703,17 +1670,16 @@ describe('ModelDataValidator', function () {
1703
1670
  foo: DataType.OBJECT,
1704
1671
  },
1705
1672
  });
1706
- const throwable = () =>
1707
- S.getService(ModelDataValidator).validate('model', {
1708
- foo: 10,
1709
- });
1710
- expect(throwable).to.throw(
1673
+ const promise = S.getService(ModelDataValidator).validate('model', {
1674
+ foo: 10,
1675
+ });
1676
+ await expect(promise).to.be.rejectedWith(
1711
1677
  'The property "foo" of the model "model" must have ' +
1712
1678
  'an Object, but Number given.',
1713
1679
  );
1714
1680
  });
1715
1681
 
1716
- it('throws an error if true given', function () {
1682
+ it('throws an error if true given', async function () {
1717
1683
  const S = new Schema();
1718
1684
  S.defineModel({
1719
1685
  name: 'model',
@@ -1722,17 +1688,16 @@ describe('ModelDataValidator', function () {
1722
1688
  foo: DataType.OBJECT,
1723
1689
  },
1724
1690
  });
1725
- const throwable = () =>
1726
- S.getService(ModelDataValidator).validate('model', {
1727
- foo: true,
1728
- });
1729
- expect(throwable).to.throw(
1691
+ const promise = S.getService(ModelDataValidator).validate('model', {
1692
+ foo: true,
1693
+ });
1694
+ await expect(promise).to.be.rejectedWith(
1730
1695
  'The property "foo" of the model "model" must have ' +
1731
1696
  'an Object, but Boolean given.',
1732
1697
  );
1733
1698
  });
1734
1699
 
1735
- it('throws an error if false given', function () {
1700
+ it('throws an error if false given', async function () {
1736
1701
  const S = new Schema();
1737
1702
  S.defineModel({
1738
1703
  name: 'model',
@@ -1741,17 +1706,16 @@ describe('ModelDataValidator', function () {
1741
1706
  foo: DataType.OBJECT,
1742
1707
  },
1743
1708
  });
1744
- const throwable = () =>
1745
- S.getService(ModelDataValidator).validate('model', {
1746
- foo: false,
1747
- });
1748
- expect(throwable).to.throw(
1709
+ const promise = S.getService(ModelDataValidator).validate('model', {
1710
+ foo: false,
1711
+ });
1712
+ await expect(promise).to.be.rejectedWith(
1749
1713
  'The property "foo" of the model "model" must have ' +
1750
1714
  'an Object, but Boolean given.',
1751
1715
  );
1752
1716
  });
1753
1717
 
1754
- it('throws an error if an array given', function () {
1718
+ it('throws an error if an array given', async function () {
1755
1719
  const S = new Schema();
1756
1720
  S.defineModel({
1757
1721
  name: 'model',
@@ -1760,17 +1724,16 @@ describe('ModelDataValidator', function () {
1760
1724
  foo: DataType.OBJECT,
1761
1725
  },
1762
1726
  });
1763
- const throwable = () =>
1764
- S.getService(ModelDataValidator).validate('model', {
1765
- foo: [],
1766
- });
1767
- expect(throwable).to.throw(
1727
+ const promise = S.getService(ModelDataValidator).validate('model', {
1728
+ foo: [],
1729
+ });
1730
+ await expect(promise).to.be.rejectedWith(
1768
1731
  'The property "foo" of the model "model" must have ' +
1769
1732
  'an Object, but Array given.',
1770
1733
  );
1771
1734
  });
1772
1735
 
1773
- it('does not throw an error if an object given', function () {
1736
+ it('does not throw an error if an object given', async function () {
1774
1737
  const S = new Schema();
1775
1738
  S.defineModel({
1776
1739
  name: 'model',
@@ -1779,14 +1742,14 @@ describe('ModelDataValidator', function () {
1779
1742
  foo: DataType.OBJECT,
1780
1743
  },
1781
1744
  });
1782
- S.getService(ModelDataValidator).validate('model', {
1745
+ await S.getService(ModelDataValidator).validate('model', {
1783
1746
  foo: {},
1784
1747
  });
1785
1748
  });
1786
1749
  });
1787
1750
 
1788
1751
  describe('FullPropertyDefinition', function () {
1789
- it('does not throw an error if an undefined given', function () {
1752
+ it('does not throw an error if an undefined given', async function () {
1790
1753
  const S = new Schema();
1791
1754
  S.defineModel({
1792
1755
  name: 'model',
@@ -1797,12 +1760,12 @@ describe('ModelDataValidator', function () {
1797
1760
  },
1798
1761
  },
1799
1762
  });
1800
- S.getService(ModelDataValidator).validate('model', {
1763
+ await S.getService(ModelDataValidator).validate('model', {
1801
1764
  foo: undefined,
1802
1765
  });
1803
1766
  });
1804
1767
 
1805
- it('does not throw an error if a null given', function () {
1768
+ it('does not throw an error if a null given', async function () {
1806
1769
  const S = new Schema();
1807
1770
  S.defineModel({
1808
1771
  name: 'model',
@@ -1813,12 +1776,12 @@ describe('ModelDataValidator', function () {
1813
1776
  },
1814
1777
  },
1815
1778
  });
1816
- S.getService(ModelDataValidator).validate('model', {
1779
+ await S.getService(ModelDataValidator).validate('model', {
1817
1780
  foo: null,
1818
1781
  });
1819
1782
  });
1820
1783
 
1821
- it('throws an error if a string given', function () {
1784
+ it('throws an error if a string given', async function () {
1822
1785
  const S = new Schema();
1823
1786
  S.defineModel({
1824
1787
  name: 'model',
@@ -1829,17 +1792,16 @@ describe('ModelDataValidator', function () {
1829
1792
  },
1830
1793
  },
1831
1794
  });
1832
- const throwable = () =>
1833
- S.getService(ModelDataValidator).validate('model', {
1834
- foo: 'bar',
1835
- });
1836
- expect(throwable).to.throw(
1795
+ const promise = S.getService(ModelDataValidator).validate('model', {
1796
+ foo: 'bar',
1797
+ });
1798
+ await expect(promise).to.be.rejectedWith(
1837
1799
  'The property "foo" of the model "model" must have ' +
1838
1800
  'an Object, but String given.',
1839
1801
  );
1840
1802
  });
1841
1803
 
1842
- it('throws an error if a number given', function () {
1804
+ it('throws an error if a number given', async function () {
1843
1805
  const S = new Schema();
1844
1806
  S.defineModel({
1845
1807
  name: 'model',
@@ -1850,17 +1812,16 @@ describe('ModelDataValidator', function () {
1850
1812
  },
1851
1813
  },
1852
1814
  });
1853
- const throwable = () =>
1854
- S.getService(ModelDataValidator).validate('model', {
1855
- foo: 10,
1856
- });
1857
- expect(throwable).to.throw(
1815
+ const promise = S.getService(ModelDataValidator).validate('model', {
1816
+ foo: 10,
1817
+ });
1818
+ await expect(promise).to.be.rejectedWith(
1858
1819
  'The property "foo" of the model "model" must have ' +
1859
1820
  'an Object, but Number given.',
1860
1821
  );
1861
1822
  });
1862
1823
 
1863
- it('throws an error if true given', function () {
1824
+ it('throws an error if true given', async function () {
1864
1825
  const S = new Schema();
1865
1826
  S.defineModel({
1866
1827
  name: 'model',
@@ -1871,17 +1832,16 @@ describe('ModelDataValidator', function () {
1871
1832
  },
1872
1833
  },
1873
1834
  });
1874
- const throwable = () =>
1875
- S.getService(ModelDataValidator).validate('model', {
1876
- foo: true,
1877
- });
1878
- expect(throwable).to.throw(
1835
+ const promise = S.getService(ModelDataValidator).validate('model', {
1836
+ foo: true,
1837
+ });
1838
+ await expect(promise).to.be.rejectedWith(
1879
1839
  'The property "foo" of the model "model" must have ' +
1880
1840
  'an Object, but Boolean given.',
1881
1841
  );
1882
1842
  });
1883
1843
 
1884
- it('throws an error if false given', function () {
1844
+ it('throws an error if false given', async function () {
1885
1845
  const S = new Schema();
1886
1846
  S.defineModel({
1887
1847
  name: 'model',
@@ -1892,17 +1852,16 @@ describe('ModelDataValidator', function () {
1892
1852
  },
1893
1853
  },
1894
1854
  });
1895
- const throwable = () =>
1896
- S.getService(ModelDataValidator).validate('model', {
1897
- foo: false,
1898
- });
1899
- expect(throwable).to.throw(
1855
+ const promise = S.getService(ModelDataValidator).validate('model', {
1856
+ foo: false,
1857
+ });
1858
+ await expect(promise).to.be.rejectedWith(
1900
1859
  'The property "foo" of the model "model" must have ' +
1901
1860
  'an Object, but Boolean given.',
1902
1861
  );
1903
1862
  });
1904
1863
 
1905
- it('throws an error if an array given', function () {
1864
+ it('throws an error if an array given', async function () {
1906
1865
  const S = new Schema();
1907
1866
  S.defineModel({
1908
1867
  name: 'model',
@@ -1913,17 +1872,16 @@ describe('ModelDataValidator', function () {
1913
1872
  },
1914
1873
  },
1915
1874
  });
1916
- const throwable = () =>
1917
- S.getService(ModelDataValidator).validate('model', {
1918
- foo: [],
1919
- });
1920
- expect(throwable).to.throw(
1875
+ const promise = S.getService(ModelDataValidator).validate('model', {
1876
+ foo: [],
1877
+ });
1878
+ await expect(promise).to.be.rejectedWith(
1921
1879
  'The property "foo" of the model "model" must have ' +
1922
1880
  'an Object, but Array given.',
1923
1881
  );
1924
1882
  });
1925
1883
 
1926
- it('does not throw an error if an object given', function () {
1884
+ it('does not throw an error if an object given', async function () {
1927
1885
  const S = new Schema();
1928
1886
  S.defineModel({
1929
1887
  name: 'model',
@@ -1934,13 +1892,13 @@ describe('ModelDataValidator', function () {
1934
1892
  },
1935
1893
  },
1936
1894
  });
1937
- S.getService(ModelDataValidator).validate('model', {
1895
+ await S.getService(ModelDataValidator).validate('model', {
1938
1896
  foo: {},
1939
1897
  });
1940
1898
  });
1941
1899
 
1942
1900
  describe('the "model" option', function () {
1943
- it('throws an error when the given object has an invalid model', function () {
1901
+ it('throws an error when the given object has an invalid model', async function () {
1944
1902
  const S = new Schema();
1945
1903
  S.defineModel({
1946
1904
  name: 'modelA',
@@ -1958,17 +1916,19 @@ describe('ModelDataValidator', function () {
1958
1916
  },
1959
1917
  },
1960
1918
  });
1961
- const throwable = () =>
1962
- S.getService(ModelDataValidator).validate('modelB', {
1919
+ const promise = S.getService(ModelDataValidator).validate(
1920
+ 'modelB',
1921
+ {
1963
1922
  bar: {foo: 10},
1964
- });
1965
- expect(throwable).to.throw(
1923
+ },
1924
+ );
1925
+ await expect(promise).to.be.rejectedWith(
1966
1926
  'The property "foo" of the model "modelA" must have ' +
1967
1927
  'a String, but Number given.',
1968
1928
  );
1969
1929
  });
1970
1930
 
1971
- it('does not throw an error when the given object has a valid model', function () {
1931
+ it('does not throw an error when the given object has a valid model', async function () {
1972
1932
  const S = new Schema();
1973
1933
  S.defineModel({
1974
1934
  name: 'modelA',
@@ -1986,12 +1946,750 @@ describe('ModelDataValidator', function () {
1986
1946
  },
1987
1947
  },
1988
1948
  });
1989
- S.getService(ModelDataValidator).validate('modelB', {
1949
+ await S.getService(ModelDataValidator).validate('modelB', {
1990
1950
  bar: {foo: '10'},
1991
1951
  });
1992
1952
  });
1993
1953
  });
1994
1954
  });
1995
1955
  });
1956
+
1957
+ describe('validate by property validators', function () {
1958
+ describe('the option "validate" with the string value', function () {
1959
+ it('do not validate null and undefined values', async function () {
1960
+ const S = new Schema();
1961
+ S.getService(PropertyValidatorRegistry)
1962
+ .addValidator('validator', () => false);
1963
+ S.defineModel({
1964
+ name: 'model',
1965
+ properties: {
1966
+ foo: {
1967
+ type: DataType.ANY,
1968
+ validate: 'validator',
1969
+ },
1970
+ bar: {
1971
+ type: DataType.ANY,
1972
+ validate: 'validator',
1973
+ },
1974
+ baz: {
1975
+ type: DataType.ANY,
1976
+ validate: 'validator',
1977
+ },
1978
+ },
1979
+ });
1980
+ await S.getService(ModelDataValidator).validate('model', {
1981
+ foo: null,
1982
+ bar: undefined,
1983
+ });
1984
+ });
1985
+
1986
+ it('throws an error from the validator', async function () {
1987
+ const validator = function () {
1988
+ throw Error('My error');
1989
+ }
1990
+ const S = new Schema();
1991
+ S.getService(PropertyValidatorRegistry)
1992
+ .addValidator('validator', validator);
1993
+ S.defineModel({
1994
+ name: 'model',
1995
+ properties: {
1996
+ foo: {
1997
+ type: DataType.ANY,
1998
+ validate: 'validator',
1999
+ },
2000
+ },
2001
+ });
2002
+ const promise = S.getService(ModelDataValidator).validate('model', {
2003
+ foo: 'test',
2004
+ });
2005
+ await expect(promise).to.be.rejectedWith('My error');
2006
+ });
2007
+
2008
+ it('allows the given value if the validator returns true', async function () {
2009
+ const S = new Schema();
2010
+ S.getService(PropertyValidatorRegistry)
2011
+ .addValidator('validator', () => true);
2012
+ S.defineModel({
2013
+ name: 'model',
2014
+ properties: {
2015
+ foo: {
2016
+ type: DataType.ANY,
2017
+ validate: 'validator',
2018
+ },
2019
+ },
2020
+ });
2021
+ await S.getService(ModelDataValidator).validate('model', {
2022
+ foo: 'test',
2023
+ });
2024
+ });
2025
+
2026
+ it('allows the given value if the validator returns a promise of true', async function () {
2027
+ const S = new Schema();
2028
+ S.getService(PropertyValidatorRegistry)
2029
+ .addValidator('validator', () => Promise.resolve(true));
2030
+ S.defineModel({
2031
+ name: 'model',
2032
+ properties: {
2033
+ foo: {
2034
+ type: DataType.ANY,
2035
+ validate: 'validator',
2036
+ },
2037
+ },
2038
+ });
2039
+ await S.getService(ModelDataValidator).validate('model', {
2040
+ foo: 'test',
2041
+ });
2042
+ });
2043
+
2044
+ it('throws an error for non-true result from the validator', async function () {
2045
+ const testFn = async (v) => {
2046
+ const S = new Schema();
2047
+ S.getService(PropertyValidatorRegistry)
2048
+ .addValidator('validator', () => v);
2049
+ S.defineModel({
2050
+ name: 'model',
2051
+ properties: {
2052
+ foo: {
2053
+ type: DataType.ANY,
2054
+ validate: 'validator',
2055
+ },
2056
+ },
2057
+ });
2058
+ const promise = S.getService(ModelDataValidator)
2059
+ .validate('model', {foo: 'test'});
2060
+ return expect(promise).to.be.rejectedWith(
2061
+ 'The property "foo" of the model "model" has an invalid value "test" ' +
2062
+ 'that caught by the validator "validator".',
2063
+ );
2064
+ }
2065
+ await testFn('str');
2066
+ await testFn('');
2067
+ await testFn(10);
2068
+ await testFn(0);
2069
+ await testFn(false);
2070
+ await testFn(undefined);
2071
+ await testFn(null);
2072
+ await testFn({});
2073
+ await testFn([]);
2074
+ await testFn(() => undefined);
2075
+ });
2076
+
2077
+ it('passes arguments to the validator', async function () {
2078
+ let validated = false;
2079
+ const S = new Schema();
2080
+ const validator = function (value, options, context) {
2081
+ expect(value).to.be.eq('test');
2082
+ expect(options).to.be.undefined;
2083
+ expect(context).to.be.eql({
2084
+ validatorName: 'validator',
2085
+ modelName: 'model',
2086
+ propName: 'foo',
2087
+ propDef: {
2088
+ type: DataType.ANY,
2089
+ validate: 'validator',
2090
+ },
2091
+ container: S.container,
2092
+ });
2093
+ validated = true;
2094
+ return true;
2095
+ }
2096
+ S.getService(PropertyValidatorRegistry)
2097
+ .addValidator('validator', validator);
2098
+ S.defineModel({
2099
+ name: 'model',
2100
+ properties: {
2101
+ foo: {
2102
+ type: DataType.ANY,
2103
+ validate: 'validator',
2104
+ },
2105
+ },
2106
+ });
2107
+ await S.getService(ModelDataValidator).validate('model', {
2108
+ foo: 'test',
2109
+ });
2110
+ expect(validated).to.be.true;
2111
+ });
2112
+
2113
+ it('invokes the validator only once per value', async function () {
2114
+ let invoked = 0;
2115
+ const validator = function () {
2116
+ invoked++;
2117
+ return true;
2118
+ }
2119
+ const S = new Schema();
2120
+ S.getService(PropertyValidatorRegistry)
2121
+ .addValidator('validator', validator);
2122
+ S.defineModel({
2123
+ name: 'model',
2124
+ properties: {
2125
+ foo: {
2126
+ type: DataType.ANY,
2127
+ validate: 'validator',
2128
+ },
2129
+ },
2130
+ });
2131
+ await S.getService(ModelDataValidator).validate('model', {
2132
+ foo: 'test',
2133
+ });
2134
+ expect(invoked).to.be.eq(1);
2135
+ });
2136
+
2137
+ it('waits rejection from an async validator', async function () {
2138
+ const error = new Error('My error');
2139
+ const validator = function () {
2140
+ return new Promise((resolve, reject) => {
2141
+ setTimeout(() => reject(error), 5);
2142
+ });
2143
+ }
2144
+ const S = new Schema();
2145
+ S.getService(PropertyValidatorRegistry)
2146
+ .addValidator('validator', validator);
2147
+ S.defineModel({
2148
+ name: 'model',
2149
+ properties: {
2150
+ foo: {
2151
+ type: DataType.ANY,
2152
+ validate: 'validator',
2153
+ },
2154
+ },
2155
+ });
2156
+ const promise = S.getService(ModelDataValidator).validate('model', {
2157
+ foo: 'test',
2158
+ });
2159
+ await expect(promise).to.be.rejectedWith(error);
2160
+ });
2161
+ });
2162
+
2163
+ describe('the option "validate" with an array value', function () {
2164
+ it('does nothing for an empty array validators', async function () {
2165
+ const S = new Schema();
2166
+ S.defineModel({
2167
+ name: 'model',
2168
+ properties: {
2169
+ foo: {
2170
+ type: DataType.ANY,
2171
+ validate: [],
2172
+ },
2173
+ },
2174
+ });
2175
+ await S.getService(ModelDataValidator).validate('model', {
2176
+ foo: 'test',
2177
+ });
2178
+ });
2179
+
2180
+ it('do not validate null and undefined values', async function () {
2181
+ const S = new Schema();
2182
+ S.getService(PropertyValidatorRegistry)
2183
+ .addValidator('validator', () => false);
2184
+ S.defineModel({
2185
+ name: 'model',
2186
+ properties: {
2187
+ foo: {
2188
+ type: DataType.ANY,
2189
+ validate: ['validator'],
2190
+ },
2191
+ bar: {
2192
+ type: DataType.ANY,
2193
+ validate: ['validator'],
2194
+ },
2195
+ baz: {
2196
+ type: DataType.ANY,
2197
+ validate: ['validator'],
2198
+ },
2199
+ },
2200
+ });
2201
+ await S.getService(ModelDataValidator).validate('model', {
2202
+ foo: null,
2203
+ bar: undefined,
2204
+ });
2205
+ });
2206
+
2207
+ it('throws an error from the validator', async function () {
2208
+ const validator = function () {
2209
+ throw Error('My error');
2210
+ }
2211
+ const S = new Schema();
2212
+ S.getService(PropertyValidatorRegistry)
2213
+ .addValidator('validator', validator);
2214
+ S.defineModel({
2215
+ name: 'model',
2216
+ properties: {
2217
+ foo: {
2218
+ type: DataType.ANY,
2219
+ validate: ['validator'],
2220
+ },
2221
+ },
2222
+ });
2223
+ const promise = S.getService(ModelDataValidator).validate('model', {
2224
+ foo: 'test',
2225
+ });
2226
+ await expect(promise).to.be.rejectedWith('My error');
2227
+ });
2228
+
2229
+ it('allows the given value if validators returns true', async function () {
2230
+ const S = new Schema();
2231
+ S.getService(PropertyValidatorRegistry)
2232
+ .addValidator('validator1', () => true)
2233
+ .addValidator('validator2', () => true);
2234
+ S.defineModel({
2235
+ name: 'model',
2236
+ properties: {
2237
+ foo: {
2238
+ type: DataType.ANY,
2239
+ validate: ['validator1', 'validator2'],
2240
+ },
2241
+ },
2242
+ });
2243
+ await S.getService(ModelDataValidator).validate('model', {
2244
+ foo: 'test',
2245
+ });
2246
+ });
2247
+
2248
+ it('allows the given value if validators returns a promise of true', async function () {
2249
+ const S = new Schema();
2250
+ S.getService(PropertyValidatorRegistry)
2251
+ .addValidator('validator1', () => Promise.resolve(true))
2252
+ .addValidator('validator2', () => Promise.resolve(true));
2253
+ S.defineModel({
2254
+ name: 'model',
2255
+ properties: {
2256
+ foo: {
2257
+ type: DataType.ANY,
2258
+ validate: ['validator1', 'validator2'],
2259
+ },
2260
+ },
2261
+ });
2262
+ await S.getService(ModelDataValidator).validate('model', {
2263
+ foo: 'test',
2264
+ });
2265
+ });
2266
+
2267
+ it('throws an error by non-true result from one of validators', async function () {
2268
+ const testFn = v => {
2269
+ const S = new Schema();
2270
+ S.getService(PropertyValidatorRegistry)
2271
+ .addValidator('validator1', () => true)
2272
+ .addValidator('validator2', () => v);
2273
+ S.defineModel({
2274
+ name: 'model',
2275
+ properties: {
2276
+ foo: {
2277
+ type: DataType.ANY,
2278
+ validate: ['validator1', 'validator2'],
2279
+ },
2280
+ },
2281
+ });
2282
+ const promise = S.getService(ModelDataValidator).validate('model', {
2283
+ foo: 'test',
2284
+ });
2285
+ return expect(promise).to.be.rejectedWith(
2286
+ 'The property "foo" of the model "model" has an invalid value "test" ' +
2287
+ 'that caught by the validator "validator2".',
2288
+ );
2289
+ }
2290
+ await testFn('str');
2291
+ await testFn('');
2292
+ await testFn(10);
2293
+ await testFn(0);
2294
+ await testFn(false);
2295
+ await testFn(undefined);
2296
+ await testFn(null);
2297
+ await testFn({});
2298
+ await testFn([]);
2299
+ await testFn(() => undefined);
2300
+ });
2301
+
2302
+ it('passes arguments to the validator', async function () {
2303
+ let validated = false;
2304
+ const S = new Schema();
2305
+ const validator = function (value, options, context) {
2306
+ expect(value).to.be.eq('test');
2307
+ expect(options).to.be.undefined;
2308
+ expect(context).to.be.eql({
2309
+ validatorName: 'validator',
2310
+ modelName: 'model',
2311
+ propName: 'foo',
2312
+ propDef: {
2313
+ type: DataType.ANY,
2314
+ validate: ['validator'],
2315
+ },
2316
+ container: S.container,
2317
+ });
2318
+ validated = true;
2319
+ return true;
2320
+ }
2321
+ S.getService(PropertyValidatorRegistry)
2322
+ .addValidator('validator', validator);
2323
+ S.defineModel({
2324
+ name: 'model',
2325
+ properties: {
2326
+ foo: {
2327
+ type: DataType.ANY,
2328
+ validate: ['validator'],
2329
+ },
2330
+ },
2331
+ });
2332
+ await S.getService(ModelDataValidator).validate('model', {
2333
+ foo: 'test',
2334
+ });
2335
+ expect(validated).to.be.true;
2336
+ });
2337
+
2338
+ it('invokes validators by the given order', async function () {
2339
+ const invocation = [];
2340
+ const validator1 = function () {
2341
+ invocation.push('validator1');
2342
+ return true;
2343
+ }
2344
+ const validator2 = function () {
2345
+ invocation.push('validator2');
2346
+ return true;
2347
+ }
2348
+ const S = new Schema();
2349
+ S.getService(PropertyValidatorRegistry)
2350
+ .addValidator('validator1', validator1)
2351
+ .addValidator('validator2', validator2);
2352
+ S.defineModel({
2353
+ name: 'model',
2354
+ properties: {
2355
+ foo: {
2356
+ type: DataType.ANY,
2357
+ validate: ['validator1', 'validator2'],
2358
+ },
2359
+ },
2360
+ });
2361
+ await S.getService(ModelDataValidator).validate('model', {
2362
+ foo: 'test',
2363
+ });
2364
+ expect(invocation).to.be.eql(['validator1', 'validator2']);
2365
+ });
2366
+
2367
+ it('waits rejection from one of async validators', async function () {
2368
+ const error1 = new Error('Occurs after 15 ms');
2369
+ const error2 = new Error('Occurs after 5 ms');
2370
+ const validator1 = () => new Promise((res, rej) => {
2371
+ setTimeout(() => rej(error1), 15);
2372
+ });
2373
+ const validator2 = () => new Promise((res, rej) => {
2374
+ setTimeout(() => rej(error2), 5);
2375
+ });
2376
+ const S = new Schema();
2377
+ S.getService(PropertyValidatorRegistry)
2378
+ .addValidator('validator1', validator1)
2379
+ .addValidator('validator2', validator2);
2380
+ S.defineModel({
2381
+ name: 'model',
2382
+ properties: {
2383
+ foo: {
2384
+ type: DataType.ANY,
2385
+ validate: [
2386
+ 'validator1',
2387
+ 'validator2',
2388
+ ],
2389
+ },
2390
+ },
2391
+ });
2392
+ const promise = S.getService(ModelDataValidator).validate('model', {
2393
+ foo: 'test',
2394
+ });
2395
+ await expect(promise).to.be.rejectedWith(error2);
2396
+ });
2397
+ });
2398
+
2399
+ describe('the option "validate" with an object value', function () {
2400
+ it('does nothing for an empty validators object', async function () {
2401
+ const S = new Schema();
2402
+ S.defineModel({
2403
+ name: 'model',
2404
+ properties: {
2405
+ foo: {
2406
+ type: DataType.ANY,
2407
+ validate: {},
2408
+ },
2409
+ },
2410
+ });
2411
+ await S.getService(ModelDataValidator).validate('model', {
2412
+ foo: 'test',
2413
+ });
2414
+ });
2415
+
2416
+ it('do not validate null and undefined values', async function () {
2417
+ const S = new Schema();
2418
+ S.getService(PropertyValidatorRegistry)
2419
+ .addValidator('validator', () => false);
2420
+ S.defineModel({
2421
+ name: 'model',
2422
+ properties: {
2423
+ foo: {
2424
+ type: DataType.ANY,
2425
+ validate: {
2426
+ validator: true,
2427
+ },
2428
+ },
2429
+ bar: {
2430
+ type: DataType.ANY,
2431
+ validate: {
2432
+ validator: true,
2433
+ },
2434
+ },
2435
+ baz: {
2436
+ type: DataType.ANY,
2437
+ validate: {
2438
+ validator: true,
2439
+ },
2440
+ },
2441
+ },
2442
+ });
2443
+ await S.getService(ModelDataValidator).validate('model', {
2444
+ foo: null,
2445
+ bar: undefined,
2446
+ });
2447
+ });
2448
+
2449
+ it('throws an error from the validator', async function () {
2450
+ const validator = function () {
2451
+ throw Error('My error');
2452
+ }
2453
+ const S = new Schema();
2454
+ S.getService(PropertyValidatorRegistry)
2455
+ .addValidator('validator', validator);
2456
+ S.defineModel({
2457
+ name: 'model',
2458
+ properties: {
2459
+ foo: {
2460
+ type: DataType.ANY,
2461
+ validate: {
2462
+ validator: true,
2463
+ },
2464
+ },
2465
+ },
2466
+ });
2467
+ const promise = S.getService(ModelDataValidator).validate('model', {
2468
+ foo: 'test',
2469
+ });
2470
+ await expect(promise).to.be.rejectedWith('My error');
2471
+ });
2472
+
2473
+ it('allows the given value if validators returns true', async function () {
2474
+ const S = new Schema();
2475
+ S.getService(PropertyValidatorRegistry)
2476
+ .addValidator('validator1', () => true)
2477
+ .addValidator('validator2', () => true);
2478
+ S.defineModel({
2479
+ name: 'model',
2480
+ properties: {
2481
+ foo: {
2482
+ type: DataType.ANY,
2483
+ validate: {
2484
+ validator1: true,
2485
+ validator2: true,
2486
+ },
2487
+ },
2488
+ },
2489
+ });
2490
+ await S.getService(ModelDataValidator).validate('model', {
2491
+ foo: 'test',
2492
+ });
2493
+ });
2494
+
2495
+ it('allows the given value if validators returns a promise of true', async function () {
2496
+ const S = new Schema();
2497
+ S.getService(PropertyValidatorRegistry)
2498
+ .addValidator('validator1', () => Promise.resolve(true))
2499
+ .addValidator('validator2', () => Promise.resolve(true));
2500
+ S.defineModel({
2501
+ name: 'model',
2502
+ properties: {
2503
+ foo: {
2504
+ type: DataType.ANY,
2505
+ validate: {
2506
+ validator1: true,
2507
+ validator2: true,
2508
+ },
2509
+ },
2510
+ },
2511
+ });
2512
+ await S.getService(ModelDataValidator).validate('model', {
2513
+ foo: 'test',
2514
+ });
2515
+ });
2516
+
2517
+ it('throws an error by non-true result from one of validators', async function () {
2518
+ const testFn = v => {
2519
+ const S = new Schema();
2520
+ S.getService(PropertyValidatorRegistry)
2521
+ .addValidator('validator1', () => true)
2522
+ .addValidator('validator2', () => v);
2523
+ S.defineModel({
2524
+ name: 'model',
2525
+ properties: {
2526
+ foo: {
2527
+ type: DataType.ANY,
2528
+ validate: {
2529
+ validator1: true,
2530
+ validator2: true,
2531
+ },
2532
+ },
2533
+ },
2534
+ });
2535
+ const promise = S.getService(ModelDataValidator).validate('model', {
2536
+ foo: 'test',
2537
+ });
2538
+ return expect(promise).to.be.rejectedWith(
2539
+ 'The property "foo" of the model "model" has an invalid value "test" ' +
2540
+ 'that caught by the validator "validator2".',
2541
+ );
2542
+ }
2543
+ await testFn('str');
2544
+ await testFn('');
2545
+ await testFn(10);
2546
+ await testFn(0);
2547
+ await testFn(false);
2548
+ await testFn(undefined);
2549
+ await testFn(null);
2550
+ await testFn({});
2551
+ await testFn([]);
2552
+ await testFn(() => undefined);
2553
+ });
2554
+
2555
+ it('passes arguments to the validator', async function () {
2556
+ let validated = false;
2557
+ const S = new Schema();
2558
+ const validator = function (value, options, context) {
2559
+ expect(value).to.be.eq('test');
2560
+ expect(options).to.be.eql({
2561
+ option1: 'value1',
2562
+ option2: 'value2',
2563
+ });
2564
+ expect(context).to.be.eql({
2565
+ validatorName: 'validator',
2566
+ modelName: 'model',
2567
+ propName: 'foo',
2568
+ propDef: {
2569
+ type: DataType.ANY,
2570
+ validate: {
2571
+ validator: {
2572
+ option1: 'value1',
2573
+ option2: 'value2',
2574
+ },
2575
+ },
2576
+ },
2577
+ container: S.container,
2578
+ });
2579
+ validated = true;
2580
+ return true;
2581
+ }
2582
+ S.getService(PropertyValidatorRegistry)
2583
+ .addValidator('validator', validator);
2584
+ S.defineModel({
2585
+ name: 'model',
2586
+ properties: {
2587
+ foo: {
2588
+ type: DataType.ANY,
2589
+ validate: {
2590
+ validator: {
2591
+ option1: 'value1',
2592
+ option2: 'value2',
2593
+ },
2594
+ },
2595
+ },
2596
+ },
2597
+ });
2598
+ await S.getService(ModelDataValidator).validate('model', {
2599
+ foo: 'test',
2600
+ });
2601
+ expect(validated).to.be.true;
2602
+ });
2603
+
2604
+ it('invokes validators by the given order', async function () {
2605
+ const invocation = [];
2606
+ const validator1 = function () {
2607
+ invocation.push('validator1');
2608
+ return true;
2609
+ }
2610
+ const validator2 = function () {
2611
+ invocation.push('validator2');
2612
+ return true;
2613
+ }
2614
+ const S = new Schema();
2615
+ S.getService(PropertyValidatorRegistry)
2616
+ .addValidator('validator1', validator1)
2617
+ .addValidator('validator2', validator2);
2618
+ S.defineModel({
2619
+ name: 'model',
2620
+ properties: {
2621
+ foo: {
2622
+ type: DataType.ANY,
2623
+ validate: {
2624
+ validator1: true,
2625
+ validator2: true,
2626
+ },
2627
+ },
2628
+ },
2629
+ });
2630
+ await S.getService(ModelDataValidator).validate('model', {
2631
+ foo: 'test',
2632
+ });
2633
+ expect(invocation).to.be.eql(['validator1', 'validator2']);
2634
+ });
2635
+
2636
+ it('validates even the validator options is false', async function () {
2637
+ let validated = false;
2638
+ const validator = function () {
2639
+ validated = true;
2640
+ return true;
2641
+ }
2642
+ const S = new Schema();
2643
+ S.getService(PropertyValidatorRegistry)
2644
+ .addValidator('validator', validator);
2645
+ S.defineModel({
2646
+ name: 'model',
2647
+ properties: {
2648
+ foo: {
2649
+ type: DataType.ANY,
2650
+ validate: {
2651
+ validator: false,
2652
+ },
2653
+ },
2654
+ },
2655
+ });
2656
+ await S.getService(ModelDataValidator).validate('model', {
2657
+ foo: 'test',
2658
+ });
2659
+ expect(validated).to.be.true;
2660
+ });
2661
+
2662
+ it('waits rejection from one of async validators', async function () {
2663
+ const error1 = new Error('Occurs after 15 ms');
2664
+ const error2 = new Error('Occurs after 5 ms');
2665
+ const validator1 = () => new Promise((res, rej) => {
2666
+ setTimeout(() => rej(error1), 15);
2667
+ });
2668
+ const validator2 = () => new Promise((res, rej) => {
2669
+ setTimeout(() => rej(error2), 5);
2670
+ });
2671
+ const S = new Schema();
2672
+ S.getService(PropertyValidatorRegistry)
2673
+ .addValidator('validator1', validator1)
2674
+ .addValidator('validator2', validator2);
2675
+ S.defineModel({
2676
+ name: 'model',
2677
+ properties: {
2678
+ foo: {
2679
+ type: DataType.ANY,
2680
+ validate: {
2681
+ validator1: true,
2682
+ validator2: true,
2683
+ }
2684
+ },
2685
+ },
2686
+ });
2687
+ const promise = S.getService(ModelDataValidator).validate('model', {
2688
+ foo: 'test',
2689
+ });
2690
+ await expect(promise).to.be.rejectedWith(error2);
2691
+ });
2692
+ });
2693
+ });
1996
2694
  });
1997
2695
  });