@e22m4u/js-repository 0.0.31

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 (183) hide show
  1. package/.c8rc +9 -0
  2. package/.commitlintrc +5 -0
  3. package/.editorconfig +13 -0
  4. package/.eslintignore +1 -0
  5. package/.eslintrc.cjs +27 -0
  6. package/.husky/commit-msg +4 -0
  7. package/.husky/pre-commit +9 -0
  8. package/.mocharc.cjs +7 -0
  9. package/.prettierrc +7 -0
  10. package/LICENSE +21 -0
  11. package/README.md +523 -0
  12. package/mocha.setup.js +10 -0
  13. package/package.json +57 -0
  14. package/src/adapter/adapter-loader.d.ts +16 -0
  15. package/src/adapter/adapter-loader.js +63 -0
  16. package/src/adapter/adapter-loader.spec.js +31 -0
  17. package/src/adapter/adapter-registry.d.ts +14 -0
  18. package/src/adapter/adapter-registry.js +36 -0
  19. package/src/adapter/adapter-registry.spec.js +36 -0
  20. package/src/adapter/adapter.d.ts +118 -0
  21. package/src/adapter/adapter.js +181 -0
  22. package/src/adapter/adapter.spec.js +144 -0
  23. package/src/adapter/builtin/memory-adapter.d.ts +118 -0
  24. package/src/adapter/builtin/memory-adapter.js +342 -0
  25. package/src/adapter/builtin/memory-adapter.spec.js +2925 -0
  26. package/src/adapter/decorator/data-sanitizing-decorator.d.ts +13 -0
  27. package/src/adapter/decorator/data-sanitizing-decorator.js +44 -0
  28. package/src/adapter/decorator/data-sanitizing-decorator.spec.js +59 -0
  29. package/src/adapter/decorator/data-validation-decorator.d.ts +13 -0
  30. package/src/adapter/decorator/data-validation-decorator.js +41 -0
  31. package/src/adapter/decorator/data-validation-decorator.spec.js +59 -0
  32. package/src/adapter/decorator/default-values-decorator.d.ts +13 -0
  33. package/src/adapter/decorator/default-values-decorator.js +57 -0
  34. package/src/adapter/decorator/default-values-decorator.spec.js +141 -0
  35. package/src/adapter/decorator/fields-filtering-decorator.d.ts +13 -0
  36. package/src/adapter/decorator/fields-filtering-decorator.js +72 -0
  37. package/src/adapter/decorator/fields-filtering-decorator.spec.js +119 -0
  38. package/src/adapter/decorator/inclusion-decorator.d.ts +13 -0
  39. package/src/adapter/decorator/inclusion-decorator.js +78 -0
  40. package/src/adapter/decorator/inclusion-decorator.spec.js +117 -0
  41. package/src/adapter/decorator/index.d.ts +5 -0
  42. package/src/adapter/decorator/index.js +5 -0
  43. package/src/adapter/index.d.ts +3 -0
  44. package/src/adapter/index.js +3 -0
  45. package/src/definition/datasource/datasource-definition-validator.d.ts +14 -0
  46. package/src/definition/datasource/datasource-definition-validator.js +33 -0
  47. package/src/definition/datasource/datasource-definition-validator.spec.js +63 -0
  48. package/src/definition/datasource/datasource-definition.d.ts +7 -0
  49. package/src/definition/datasource/index.d.ts +2 -0
  50. package/src/definition/datasource/index.js +1 -0
  51. package/src/definition/definition-registry.d.ts +50 -0
  52. package/src/definition/definition-registry.js +98 -0
  53. package/src/definition/definition-registry.spec.js +78 -0
  54. package/src/definition/index.d.ts +3 -0
  55. package/src/definition/index.js +3 -0
  56. package/src/definition/model/index.d.ts +7 -0
  57. package/src/definition/model/index.js +6 -0
  58. package/src/definition/model/model-data-sanitizer.d.ts +15 -0
  59. package/src/definition/model/model-data-sanitizer.js +33 -0
  60. package/src/definition/model/model-data-validator.d.ts +32 -0
  61. package/src/definition/model/model-data-validator.js +144 -0
  62. package/src/definition/model/model-data-validator.spec.js +1889 -0
  63. package/src/definition/model/model-definition-utils.d.ts +161 -0
  64. package/src/definition/model/model-definition-utils.js +371 -0
  65. package/src/definition/model/model-definition-utils.spec.js +1474 -0
  66. package/src/definition/model/model-definition-validator.d.ts +14 -0
  67. package/src/definition/model/model-definition-validator.js +83 -0
  68. package/src/definition/model/model-definition-validator.spec.js +143 -0
  69. package/src/definition/model/model-definition.d.ts +28 -0
  70. package/src/definition/model/properties/data-type.d.ts +11 -0
  71. package/src/definition/model/properties/data-type.js +11 -0
  72. package/src/definition/model/properties/default-values-definition-validator.d.ts +15 -0
  73. package/src/definition/model/properties/default-values-definition-validator.js +53 -0
  74. package/src/definition/model/properties/default-values-definition-validator.spec.js +136 -0
  75. package/src/definition/model/properties/index.d.ts +5 -0
  76. package/src/definition/model/properties/index.js +4 -0
  77. package/src/definition/model/properties/primary-keys-definition-validator.d.ts +15 -0
  78. package/src/definition/model/properties/primary-keys-definition-validator.js +55 -0
  79. package/src/definition/model/properties/primary-keys-definition-validator.spec.js +145 -0
  80. package/src/definition/model/properties/properties-definition-validator.d.ts +15 -0
  81. package/src/definition/model/properties/properties-definition-validator.js +194 -0
  82. package/src/definition/model/properties/properties-definition-validator.spec.js +373 -0
  83. package/src/definition/model/properties/property-definition.d.ts +20 -0
  84. package/src/definition/model/relations/index.d.ts +3 -0
  85. package/src/definition/model/relations/index.js +2 -0
  86. package/src/definition/model/relations/relation-definition.d.ts +254 -0
  87. package/src/definition/model/relations/relation-type.d.ts +9 -0
  88. package/src/definition/model/relations/relation-type.js +9 -0
  89. package/src/definition/model/relations/relations-definition-validator.d.ts +15 -0
  90. package/src/definition/model/relations/relations-definition-validator.js +449 -0
  91. package/src/definition/model/relations/relations-definition-validator.spec.js +772 -0
  92. package/src/errors/index.d.ts +3 -0
  93. package/src/errors/index.js +3 -0
  94. package/src/errors/invalid-argument-error.d.ts +6 -0
  95. package/src/errors/invalid-argument-error.js +6 -0
  96. package/src/errors/invalid-argument-error.spec.js +33 -0
  97. package/src/errors/invalid-operator-value-error.d.ts +13 -0
  98. package/src/errors/invalid-operator-value-error.js +24 -0
  99. package/src/errors/invalid-operator-value-error.spec.js +11 -0
  100. package/src/errors/not-implemented-error.d.ts +6 -0
  101. package/src/errors/not-implemented-error.js +6 -0
  102. package/src/errors/not-implemented-error.spec.js +33 -0
  103. package/src/filter/fields-clause-tool.d.ts +38 -0
  104. package/src/filter/fields-clause-tool.js +88 -0
  105. package/src/filter/fields-clause-tool.spec.js +133 -0
  106. package/src/filter/filter.d.ts +335 -0
  107. package/src/filter/include-clause-tool.d.ts +53 -0
  108. package/src/filter/include-clause-tool.js +364 -0
  109. package/src/filter/include-clause-tool.spec.js +653 -0
  110. package/src/filter/index.d.ts +7 -0
  111. package/src/filter/index.js +6 -0
  112. package/src/filter/operator-clause-tool.d.ts +223 -0
  113. package/src/filter/operator-clause-tool.js +515 -0
  114. package/src/filter/operator-clause-tool.spec.js +1064 -0
  115. package/src/filter/order-clause-tool.d.ts +32 -0
  116. package/src/filter/order-clause-tool.js +97 -0
  117. package/src/filter/order-clause-tool.spec.js +438 -0
  118. package/src/filter/slice-clause-tool.d.ts +30 -0
  119. package/src/filter/slice-clause-tool.js +65 -0
  120. package/src/filter/slice-clause-tool.spec.js +117 -0
  121. package/src/filter/where-clause-tool.d.ts +23 -0
  122. package/src/filter/where-clause-tool.js +165 -0
  123. package/src/filter/where-clause-tool.spec.js +280 -0
  124. package/src/index.d.ts +9 -0
  125. package/src/index.js +8 -0
  126. package/src/relations/belongs-to-resolver.d.ts +46 -0
  127. package/src/relations/belongs-to-resolver.js +242 -0
  128. package/src/relations/belongs-to-resolver.spec.js +1047 -0
  129. package/src/relations/has-many-resolver.d.ts +67 -0
  130. package/src/relations/has-many-resolver.js +317 -0
  131. package/src/relations/has-many-resolver.spec.js +2911 -0
  132. package/src/relations/has-one-resolver.d.ts +67 -0
  133. package/src/relations/has-one-resolver.js +311 -0
  134. package/src/relations/has-one-resolver.spec.js +2274 -0
  135. package/src/relations/index.d.ts +4 -0
  136. package/src/relations/index.js +4 -0
  137. package/src/relations/references-many-resolver.d.ts +27 -0
  138. package/src/relations/references-many-resolver.js +113 -0
  139. package/src/relations/references-many-resolver.spec.js +631 -0
  140. package/src/repository/index.d.ts +2 -0
  141. package/src/repository/index.js +2 -0
  142. package/src/repository/repository-registry.d.ts +29 -0
  143. package/src/repository/repository-registry.js +57 -0
  144. package/src/repository/repository-registry.spec.js +38 -0
  145. package/src/repository/repository.d.ts +164 -0
  146. package/src/repository/repository.js +207 -0
  147. package/src/repository/repository.spec.js +202 -0
  148. package/src/schema.d.ts +37 -0
  149. package/src/schema.js +41 -0
  150. package/src/types.d.ts +30 -0
  151. package/src/utils/capitalize.d.ts +6 -0
  152. package/src/utils/capitalize.js +10 -0
  153. package/src/utils/capitalize.spec.js +14 -0
  154. package/src/utils/clone-deep.d.ts +6 -0
  155. package/src/utils/clone-deep.js +61 -0
  156. package/src/utils/clone-deep.spec.js +28 -0
  157. package/src/utils/exclude-object-keys.d.ts +10 -0
  158. package/src/utils/exclude-object-keys.js +20 -0
  159. package/src/utils/exclude-object-keys.spec.js +49 -0
  160. package/src/utils/get-ctor-name.d.ts +6 -0
  161. package/src/utils/get-ctor-name.js +11 -0
  162. package/src/utils/get-ctor-name.spec.js +17 -0
  163. package/src/utils/get-value-by-path.d.ts +12 -0
  164. package/src/utils/get-value-by-path.js +23 -0
  165. package/src/utils/get-value-by-path.spec.js +36 -0
  166. package/src/utils/index.d.ts +10 -0
  167. package/src/utils/index.js +10 -0
  168. package/src/utils/is-ctor.d.ts +7 -0
  169. package/src/utils/is-ctor.js +10 -0
  170. package/src/utils/is-ctor.spec.js +26 -0
  171. package/src/utils/is-pure-object.d.ts +6 -0
  172. package/src/utils/is-pure-object.js +15 -0
  173. package/src/utils/is-pure-object.spec.js +25 -0
  174. package/src/utils/select-object-keys.d.ts +10 -0
  175. package/src/utils/select-object-keys.js +37 -0
  176. package/src/utils/select-object-keys.spec.js +40 -0
  177. package/src/utils/singularize.d.ts +6 -0
  178. package/src/utils/singularize.js +22 -0
  179. package/src/utils/singularize.spec.js +23 -0
  180. package/src/utils/string-to-regexp.d.ts +10 -0
  181. package/src/utils/string-to-regexp.js +22 -0
  182. package/src/utils/string-to-regexp.spec.js +35 -0
  183. package/tsconfig.json +9 -0
@@ -0,0 +1,1889 @@
1
+ import {expect} from 'chai';
2
+ import {Schema} from '../../schema.js';
3
+ import {format} from '@e22m4u/js-format';
4
+ import {DataType} from './properties/index.js';
5
+ import {ModelDataValidator} from './model-data-validator.js';
6
+
7
+ describe('ModelDataValidator', function () {
8
+ describe('validate', function () {
9
+ it('does not throw an error if a model does not have a property of a given data', function () {
10
+ const schema = new Schema();
11
+ schema.defineModel({name: 'model'});
12
+ schema.getService(ModelDataValidator).validate('model', {foo: 'bar'});
13
+ });
14
+
15
+ it('throws an error if a given data is not a pure object', function () {
16
+ const throwable = modelData => {
17
+ const schema = new Schema();
18
+ schema.defineModel({
19
+ name: 'model',
20
+ datasource: 'datasource',
21
+ });
22
+ return () =>
23
+ schema.getService(ModelDataValidator).validate('model', modelData);
24
+ };
25
+ const error = given =>
26
+ format(
27
+ 'The data of the model "model" must be an Object, but %s given.',
28
+ given,
29
+ );
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'));
37
+ });
38
+
39
+ it('uses a base model hierarchy to validate a given data', function () {
40
+ const schema = new Schema();
41
+ schema.defineModel({
42
+ name: 'modelA',
43
+ properties: {
44
+ foo: DataType.STRING,
45
+ },
46
+ });
47
+ schema.defineModel({
48
+ name: 'modelB',
49
+ base: 'modelA',
50
+ });
51
+ const throwable = () =>
52
+ schema.getService(ModelDataValidator).validate('modelB', {foo: 10});
53
+ expect(throwable).to.throw(
54
+ 'The property "foo" of the model "modelB" must ' +
55
+ 'have a String, but Number given.',
56
+ );
57
+ });
58
+
59
+ it('throws an error if a given data does not have a required property', function () {
60
+ const schema = new Schema();
61
+ schema.defineModel({
62
+ name: 'model',
63
+ properties: {
64
+ foo: {
65
+ type: DataType.STRING,
66
+ required: true,
67
+ },
68
+ },
69
+ });
70
+ const throwable = () =>
71
+ schema.getService(ModelDataValidator).validate('model', {});
72
+ expect(throwable).to.throw(
73
+ 'The property "foo" of the model "model" ' +
74
+ 'is required, but undefined given.',
75
+ );
76
+ });
77
+
78
+ it('throws an error if a required property is undefined', function () {
79
+ const schema = new Schema();
80
+ schema.defineModel({
81
+ name: 'model',
82
+ properties: {
83
+ foo: {
84
+ type: DataType.STRING,
85
+ required: true,
86
+ },
87
+ },
88
+ });
89
+ const throwable = () =>
90
+ schema
91
+ .getService(ModelDataValidator)
92
+ .validate('model', {foo: undefined});
93
+ expect(throwable).to.throw(
94
+ 'The property "foo" of the model "model" is required, but undefined given.',
95
+ );
96
+ });
97
+
98
+ it('throws an error if a required property is null', function () {
99
+ const schema = new Schema();
100
+ schema.defineModel({
101
+ name: 'model',
102
+ properties: {
103
+ foo: {
104
+ type: DataType.STRING,
105
+ required: true,
106
+ },
107
+ },
108
+ });
109
+ const throwable = () =>
110
+ schema.getService(ModelDataValidator).validate('model', {foo: null});
111
+ expect(throwable).to.throw(
112
+ 'The property "foo" of the model "model" is required, but null given.',
113
+ );
114
+ });
115
+
116
+ 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 () {
118
+ const schema = new Schema();
119
+ schema.defineModel({
120
+ name: 'model',
121
+ properties: {
122
+ foo: {
123
+ type: DataType.STRING,
124
+ required: true,
125
+ },
126
+ },
127
+ });
128
+ schema.getService(ModelDataValidator).validate('model', {}, true);
129
+ });
130
+
131
+ it('throws an error if a required property is undefined', function () {
132
+ const schema = new Schema();
133
+ schema.defineModel({
134
+ name: 'model',
135
+ properties: {
136
+ foo: {
137
+ type: DataType.STRING,
138
+ required: true,
139
+ },
140
+ },
141
+ });
142
+ const throwable = () =>
143
+ schema
144
+ .getService(ModelDataValidator)
145
+ .validate('model', {foo: undefined}, true);
146
+ expect(throwable).to.throw(
147
+ 'The property "foo" of the model "model" ' +
148
+ 'is required, but undefined given.',
149
+ );
150
+ });
151
+
152
+ it('throws an error if a required property is null', function () {
153
+ const schema = new Schema();
154
+ schema.defineModel({
155
+ name: 'model',
156
+ properties: {
157
+ foo: {
158
+ type: DataType.STRING,
159
+ required: true,
160
+ },
161
+ },
162
+ });
163
+ const throwable = () =>
164
+ schema
165
+ .getService(ModelDataValidator)
166
+ .validate('model', {foo: null}, true);
167
+ expect(throwable).to.throw(
168
+ 'The property "foo" of the model "model" is required, but null given.',
169
+ );
170
+ });
171
+ });
172
+
173
+ describe('DataType.ANY', function () {
174
+ describe('ShortPropertyDefinition', function () {
175
+ it('does not throw an error if an undefined given', function () {
176
+ const S = new Schema();
177
+ S.defineModel({
178
+ name: 'model',
179
+ datasource: 'datasource',
180
+ properties: {
181
+ foo: DataType.ANY,
182
+ },
183
+ });
184
+ S.getService(ModelDataValidator).validate('model', {
185
+ foo: undefined,
186
+ });
187
+ });
188
+
189
+ it('does not throw an error if a null given', function () {
190
+ const S = new Schema();
191
+ S.defineModel({
192
+ name: 'model',
193
+ datasource: 'datasource',
194
+ properties: {
195
+ foo: DataType.ANY,
196
+ },
197
+ });
198
+ S.getService(ModelDataValidator).validate('model', {
199
+ foo: null,
200
+ });
201
+ });
202
+
203
+ it('does not throw an error if a string given', function () {
204
+ const S = new Schema();
205
+ S.defineModel({
206
+ name: 'model',
207
+ datasource: 'datasource',
208
+ properties: {
209
+ foo: DataType.ANY,
210
+ },
211
+ });
212
+ S.getService(ModelDataValidator).validate('model', {
213
+ foo: 'bar',
214
+ });
215
+ });
216
+
217
+ it('does not throw an error if a number given', function () {
218
+ const S = new Schema();
219
+ S.defineModel({
220
+ name: 'model',
221
+ datasource: 'datasource',
222
+ properties: {
223
+ foo: DataType.ANY,
224
+ },
225
+ });
226
+ S.getService(ModelDataValidator).validate('model', {
227
+ foo: 10,
228
+ });
229
+ });
230
+
231
+ it('does not throw an error if true given', function () {
232
+ const S = new Schema();
233
+ S.defineModel({
234
+ name: 'model',
235
+ datasource: 'datasource',
236
+ properties: {
237
+ foo: DataType.ANY,
238
+ },
239
+ });
240
+ S.getService(ModelDataValidator).validate('model', {
241
+ foo: true,
242
+ });
243
+ });
244
+
245
+ it('does not throw an error if false given', function () {
246
+ const S = new Schema();
247
+ S.defineModel({
248
+ name: 'model',
249
+ datasource: 'datasource',
250
+ properties: {
251
+ foo: DataType.ANY,
252
+ },
253
+ });
254
+ S.getService(ModelDataValidator).validate('model', {
255
+ foo: false,
256
+ });
257
+ });
258
+
259
+ it('does not throw an error if an array given', function () {
260
+ const S = new Schema();
261
+ S.defineModel({
262
+ name: 'model',
263
+ datasource: 'datasource',
264
+ properties: {
265
+ foo: DataType.ANY,
266
+ },
267
+ });
268
+ S.getService(ModelDataValidator).validate('model', {
269
+ foo: [],
270
+ });
271
+ });
272
+
273
+ it('does not throw an error if an object given', function () {
274
+ const S = new Schema();
275
+ S.defineModel({
276
+ name: 'model',
277
+ datasource: 'datasource',
278
+ properties: {
279
+ foo: DataType.ANY,
280
+ },
281
+ });
282
+ S.getService(ModelDataValidator).validate('model', {
283
+ foo: {},
284
+ });
285
+ });
286
+ });
287
+
288
+ describe('FullPropertyDefinition', function () {
289
+ it('does not throw an error if an undefined given', function () {
290
+ const S = new Schema();
291
+ S.defineModel({
292
+ name: 'model',
293
+ datasource: 'datasource',
294
+ properties: {
295
+ foo: {
296
+ type: DataType.ANY,
297
+ },
298
+ },
299
+ });
300
+ S.getService(ModelDataValidator).validate('model', {
301
+ foo: undefined,
302
+ });
303
+ });
304
+
305
+ it('does not throw an error if a null given', function () {
306
+ const S = new Schema();
307
+ S.defineModel({
308
+ name: 'model',
309
+ datasource: 'datasource',
310
+ properties: {
311
+ foo: {
312
+ type: DataType.ANY,
313
+ },
314
+ },
315
+ });
316
+ S.getService(ModelDataValidator).validate('model', {
317
+ foo: null,
318
+ });
319
+ });
320
+
321
+ it('does not throw an error if a string given', function () {
322
+ const S = new Schema();
323
+ S.defineModel({
324
+ name: 'model',
325
+ datasource: 'datasource',
326
+ properties: {
327
+ foo: {
328
+ type: DataType.ANY,
329
+ },
330
+ },
331
+ });
332
+ S.getService(ModelDataValidator).validate('model', {
333
+ foo: 'bar',
334
+ });
335
+ });
336
+
337
+ it('does not throw an error if a number given', function () {
338
+ const S = new Schema();
339
+ S.defineModel({
340
+ name: 'model',
341
+ datasource: 'datasource',
342
+ properties: {
343
+ foo: {
344
+ type: DataType.ANY,
345
+ },
346
+ },
347
+ });
348
+ S.getService(ModelDataValidator).validate('model', {
349
+ foo: 10,
350
+ });
351
+ });
352
+
353
+ it('does not throw an error if true given', function () {
354
+ const S = new Schema();
355
+ S.defineModel({
356
+ name: 'model',
357
+ datasource: 'datasource',
358
+ properties: {
359
+ foo: {
360
+ type: DataType.ANY,
361
+ },
362
+ },
363
+ });
364
+ S.getService(ModelDataValidator).validate('model', {
365
+ foo: true,
366
+ });
367
+ });
368
+
369
+ it('does not throw an error if false given', function () {
370
+ const S = new Schema();
371
+ S.defineModel({
372
+ name: 'model',
373
+ datasource: 'datasource',
374
+ properties: {
375
+ foo: {
376
+ type: DataType.ANY,
377
+ },
378
+ },
379
+ });
380
+ S.getService(ModelDataValidator).validate('model', {
381
+ foo: false,
382
+ });
383
+ });
384
+
385
+ it('does not throw an error if an array given', function () {
386
+ const S = new Schema();
387
+ S.defineModel({
388
+ name: 'model',
389
+ datasource: 'datasource',
390
+ properties: {
391
+ foo: {
392
+ type: DataType.ANY,
393
+ },
394
+ },
395
+ });
396
+ S.getService(ModelDataValidator).validate('model', {
397
+ foo: [],
398
+ });
399
+ });
400
+
401
+ it('does not throw an error if an object given', function () {
402
+ const S = new Schema();
403
+ S.defineModel({
404
+ name: 'model',
405
+ datasource: 'datasource',
406
+ properties: {
407
+ foo: {
408
+ type: DataType.ANY,
409
+ },
410
+ },
411
+ });
412
+ S.getService(ModelDataValidator).validate('model', {
413
+ foo: {},
414
+ });
415
+ });
416
+ });
417
+ });
418
+
419
+ describe('DataType.STRING', function () {
420
+ describe('ShortPropertyDefinition', function () {
421
+ it('does not throw an error if an undefined given', function () {
422
+ const S = new Schema();
423
+ S.defineModel({
424
+ name: 'model',
425
+ datasource: 'datasource',
426
+ properties: {
427
+ foo: DataType.STRING,
428
+ },
429
+ });
430
+ S.getService(ModelDataValidator).validate('model', {
431
+ foo: undefined,
432
+ });
433
+ });
434
+
435
+ it('does not throw an error if a null given', function () {
436
+ const S = new Schema();
437
+ S.defineModel({
438
+ name: 'model',
439
+ datasource: 'datasource',
440
+ properties: {
441
+ foo: DataType.STRING,
442
+ },
443
+ });
444
+ S.getService(ModelDataValidator).validate('model', {
445
+ foo: null,
446
+ });
447
+ });
448
+
449
+ it('does not throw an error if a string given', function () {
450
+ const S = new Schema();
451
+ S.defineModel({
452
+ name: 'model',
453
+ datasource: 'datasource',
454
+ properties: {
455
+ foo: DataType.STRING,
456
+ },
457
+ });
458
+ S.getService(ModelDataValidator).validate('model', {
459
+ foo: 'bar',
460
+ });
461
+ });
462
+
463
+ it('throws an error if a number given', function () {
464
+ const S = new Schema();
465
+ S.defineModel({
466
+ name: 'model',
467
+ datasource: 'datasource',
468
+ properties: {
469
+ foo: DataType.STRING,
470
+ },
471
+ });
472
+ const throwable = () =>
473
+ S.getService(ModelDataValidator).validate('model', {
474
+ foo: 10,
475
+ });
476
+ expect(throwable).to.throw(
477
+ 'The property "foo" of the model "model" must have ' +
478
+ 'a String, but Number given.',
479
+ );
480
+ });
481
+
482
+ it('throws an error if true given', function () {
483
+ const S = new Schema();
484
+ S.defineModel({
485
+ name: 'model',
486
+ datasource: 'datasource',
487
+ properties: {
488
+ foo: DataType.STRING,
489
+ },
490
+ });
491
+ const throwable = () =>
492
+ S.getService(ModelDataValidator).validate('model', {
493
+ foo: true,
494
+ });
495
+ expect(throwable).to.throw(
496
+ 'The property "foo" of the model "model" must have ' +
497
+ 'a String, but Boolean given.',
498
+ );
499
+ });
500
+
501
+ it('throws an error if false given', function () {
502
+ const S = new Schema();
503
+ S.defineModel({
504
+ name: 'model',
505
+ datasource: 'datasource',
506
+ properties: {
507
+ foo: DataType.STRING,
508
+ },
509
+ });
510
+ const throwable = () =>
511
+ S.getService(ModelDataValidator).validate('model', {
512
+ foo: false,
513
+ });
514
+ expect(throwable).to.throw(
515
+ 'The property "foo" of the model "model" must have ' +
516
+ 'a String, but Boolean given.',
517
+ );
518
+ });
519
+
520
+ it('throws an error if an array given', function () {
521
+ const S = new Schema();
522
+ S.defineModel({
523
+ name: 'model',
524
+ datasource: 'datasource',
525
+ properties: {
526
+ foo: DataType.STRING,
527
+ },
528
+ });
529
+ const throwable = () =>
530
+ S.getService(ModelDataValidator).validate('model', {
531
+ foo: [],
532
+ });
533
+ expect(throwable).to.throw(
534
+ 'The property "foo" of the model "model" must have ' +
535
+ 'a String, but Array given.',
536
+ );
537
+ });
538
+
539
+ it('throws an error if an object given', function () {
540
+ const S = new Schema();
541
+ S.defineModel({
542
+ name: 'model',
543
+ datasource: 'datasource',
544
+ properties: {
545
+ foo: DataType.STRING,
546
+ },
547
+ });
548
+ const throwable = () =>
549
+ S.getService(ModelDataValidator).validate('model', {
550
+ foo: {},
551
+ });
552
+ expect(throwable).to.throw(
553
+ 'The property "foo" of the model "model" must have ' +
554
+ 'a String, but Object given.',
555
+ );
556
+ });
557
+ });
558
+
559
+ describe('FullPropertyDefinition', function () {
560
+ it('does not throw an error if an undefined given', function () {
561
+ const S = new Schema();
562
+ S.defineModel({
563
+ name: 'model',
564
+ datasource: 'datasource',
565
+ properties: {
566
+ foo: {
567
+ type: DataType.STRING,
568
+ },
569
+ },
570
+ });
571
+ S.getService(ModelDataValidator).validate('model', {
572
+ foo: undefined,
573
+ });
574
+ });
575
+
576
+ it('does not throw an error if a null given', function () {
577
+ const S = new Schema();
578
+ S.defineModel({
579
+ name: 'model',
580
+ datasource: 'datasource',
581
+ properties: {
582
+ foo: {
583
+ type: DataType.STRING,
584
+ },
585
+ },
586
+ });
587
+ S.getService(ModelDataValidator).validate('model', {
588
+ foo: null,
589
+ });
590
+ });
591
+
592
+ it('does not throw an error if a string given', function () {
593
+ const S = new Schema();
594
+ S.defineModel({
595
+ name: 'model',
596
+ datasource: 'datasource',
597
+ properties: {
598
+ foo: {
599
+ type: DataType.STRING,
600
+ },
601
+ },
602
+ });
603
+ S.getService(ModelDataValidator).validate('model', {
604
+ foo: 'bar',
605
+ });
606
+ });
607
+
608
+ it('throws an error if a number given', function () {
609
+ const S = new Schema();
610
+ S.defineModel({
611
+ name: 'model',
612
+ datasource: 'datasource',
613
+ properties: {
614
+ foo: {
615
+ type: DataType.STRING,
616
+ },
617
+ },
618
+ });
619
+ const throwable = () =>
620
+ S.getService(ModelDataValidator).validate('model', {
621
+ foo: 10,
622
+ });
623
+ expect(throwable).to.throw(
624
+ 'The property "foo" of the model "model" must have ' +
625
+ 'a String, but Number given.',
626
+ );
627
+ });
628
+
629
+ it('throws an error if true given', function () {
630
+ const S = new Schema();
631
+ S.defineModel({
632
+ name: 'model',
633
+ datasource: 'datasource',
634
+ properties: {
635
+ foo: {
636
+ type: DataType.STRING,
637
+ },
638
+ },
639
+ });
640
+ const throwable = () =>
641
+ S.getService(ModelDataValidator).validate('model', {
642
+ foo: true,
643
+ });
644
+ expect(throwable).to.throw(
645
+ 'The property "foo" of the model "model" must have ' +
646
+ 'a String, but Boolean given.',
647
+ );
648
+ });
649
+
650
+ it('throws an error if false given', function () {
651
+ const S = new Schema();
652
+ S.defineModel({
653
+ name: 'model',
654
+ datasource: 'datasource',
655
+ properties: {
656
+ foo: {
657
+ type: DataType.STRING,
658
+ },
659
+ },
660
+ });
661
+ const throwable = () =>
662
+ S.getService(ModelDataValidator).validate('model', {
663
+ foo: false,
664
+ });
665
+ expect(throwable).to.throw(
666
+ 'The property "foo" of the model "model" must have ' +
667
+ 'a String, but Boolean given.',
668
+ );
669
+ });
670
+
671
+ it('throws an error if an array given', function () {
672
+ const S = new Schema();
673
+ S.defineModel({
674
+ name: 'model',
675
+ datasource: 'datasource',
676
+ properties: {
677
+ foo: {
678
+ type: DataType.STRING,
679
+ },
680
+ },
681
+ });
682
+ const throwable = () =>
683
+ S.getService(ModelDataValidator).validate('model', {
684
+ foo: [],
685
+ });
686
+ expect(throwable).to.throw(
687
+ 'The property "foo" of the model "model" must have ' +
688
+ 'a String, but Array given.',
689
+ );
690
+ });
691
+
692
+ it('throws an error if an object given', function () {
693
+ const S = new Schema();
694
+ S.defineModel({
695
+ name: 'model',
696
+ datasource: 'datasource',
697
+ properties: {
698
+ foo: {
699
+ type: DataType.STRING,
700
+ },
701
+ },
702
+ });
703
+ const throwable = () =>
704
+ S.getService(ModelDataValidator).validate('model', {
705
+ foo: {},
706
+ });
707
+ expect(throwable).to.throw(
708
+ 'The property "foo" of the model "model" must have ' +
709
+ 'a String, but Object given.',
710
+ );
711
+ });
712
+ });
713
+ });
714
+
715
+ describe('DataType.NUMBER', function () {
716
+ describe('ShortPropertyDefinition', function () {
717
+ it('does not throw an error if an undefined given', function () {
718
+ const S = new Schema();
719
+ S.defineModel({
720
+ name: 'model',
721
+ datasource: 'datasource',
722
+ properties: {
723
+ foo: DataType.NUMBER,
724
+ },
725
+ });
726
+ S.getService(ModelDataValidator).validate('model', {
727
+ foo: undefined,
728
+ });
729
+ });
730
+
731
+ it('does not throw an error if a null given', function () {
732
+ const S = new Schema();
733
+ S.defineModel({
734
+ name: 'model',
735
+ datasource: 'datasource',
736
+ properties: {
737
+ foo: DataType.NUMBER,
738
+ },
739
+ });
740
+ S.getService(ModelDataValidator).validate('model', {
741
+ foo: null,
742
+ });
743
+ });
744
+
745
+ it('throws an error if a string given', function () {
746
+ const S = new Schema();
747
+ S.defineModel({
748
+ name: 'model',
749
+ datasource: 'datasource',
750
+ properties: {
751
+ foo: DataType.NUMBER,
752
+ },
753
+ });
754
+ const throwable = () =>
755
+ S.getService(ModelDataValidator).validate('model', {
756
+ foo: 'bar',
757
+ });
758
+ expect(throwable).to.throw(
759
+ 'The property "foo" of the model "model" must have ' +
760
+ 'a Number, but String given.',
761
+ );
762
+ });
763
+
764
+ it('does not throw an error if a number given', function () {
765
+ const S = new Schema();
766
+ S.defineModel({
767
+ name: 'model',
768
+ datasource: 'datasource',
769
+ properties: {
770
+ foo: DataType.NUMBER,
771
+ },
772
+ });
773
+ S.getService(ModelDataValidator).validate('model', {
774
+ foo: 10,
775
+ });
776
+ });
777
+
778
+ it('throws an error if true given', function () {
779
+ const S = new Schema();
780
+ S.defineModel({
781
+ name: 'model',
782
+ datasource: 'datasource',
783
+ properties: {
784
+ foo: DataType.NUMBER,
785
+ },
786
+ });
787
+ const throwable = () =>
788
+ S.getService(ModelDataValidator).validate('model', {
789
+ foo: true,
790
+ });
791
+ expect(throwable).to.throw(
792
+ 'The property "foo" of the model "model" must have ' +
793
+ 'a Number, but Boolean given.',
794
+ );
795
+ });
796
+
797
+ it('throws an error if false given', function () {
798
+ const S = new Schema();
799
+ S.defineModel({
800
+ name: 'model',
801
+ datasource: 'datasource',
802
+ properties: {
803
+ foo: DataType.NUMBER,
804
+ },
805
+ });
806
+ const throwable = () =>
807
+ S.getService(ModelDataValidator).validate('model', {
808
+ foo: false,
809
+ });
810
+ expect(throwable).to.throw(
811
+ 'The property "foo" of the model "model" must have ' +
812
+ 'a Number, but Boolean given.',
813
+ );
814
+ });
815
+
816
+ it('throws an error if an array given', function () {
817
+ const S = new Schema();
818
+ S.defineModel({
819
+ name: 'model',
820
+ datasource: 'datasource',
821
+ properties: {
822
+ foo: DataType.NUMBER,
823
+ },
824
+ });
825
+ const throwable = () =>
826
+ S.getService(ModelDataValidator).validate('model', {
827
+ foo: [],
828
+ });
829
+ expect(throwable).to.throw(
830
+ 'The property "foo" of the model "model" must have ' +
831
+ 'a Number, but Array given.',
832
+ );
833
+ });
834
+
835
+ it('throws an error if an object given', function () {
836
+ const S = new Schema();
837
+ S.defineModel({
838
+ name: 'model',
839
+ datasource: 'datasource',
840
+ properties: {
841
+ foo: DataType.NUMBER,
842
+ },
843
+ });
844
+ const throwable = () =>
845
+ S.getService(ModelDataValidator).validate('model', {
846
+ foo: {},
847
+ });
848
+ expect(throwable).to.throw(
849
+ 'The property "foo" of the model "model" must have ' +
850
+ 'a Number, but Object given.',
851
+ );
852
+ });
853
+ });
854
+
855
+ describe('FullPropertyDefinition', function () {
856
+ it('does not throw an error if an undefined given', function () {
857
+ const S = new Schema();
858
+ S.defineModel({
859
+ name: 'model',
860
+ datasource: 'datasource',
861
+ properties: {
862
+ foo: {
863
+ type: DataType.NUMBER,
864
+ },
865
+ },
866
+ });
867
+ S.getService(ModelDataValidator).validate('model', {
868
+ foo: undefined,
869
+ });
870
+ });
871
+
872
+ it('does not throw an error if a null given', function () {
873
+ const S = new Schema();
874
+ S.defineModel({
875
+ name: 'model',
876
+ datasource: 'datasource',
877
+ properties: {
878
+ foo: {
879
+ type: DataType.NUMBER,
880
+ },
881
+ },
882
+ });
883
+ S.getService(ModelDataValidator).validate('model', {
884
+ foo: null,
885
+ });
886
+ });
887
+
888
+ it('throws an error if a string given', function () {
889
+ const S = new Schema();
890
+ S.defineModel({
891
+ name: 'model',
892
+ datasource: 'datasource',
893
+ properties: {
894
+ foo: {
895
+ type: DataType.NUMBER,
896
+ },
897
+ },
898
+ });
899
+ const throwable = () =>
900
+ S.getService(ModelDataValidator).validate('model', {
901
+ foo: 'bar',
902
+ });
903
+ expect(throwable).to.throw(
904
+ 'The property "foo" of the model "model" must have ' +
905
+ 'a Number, but String given.',
906
+ );
907
+ });
908
+
909
+ it('does not throw an error if a number given', function () {
910
+ const S = new Schema();
911
+ S.defineModel({
912
+ name: 'model',
913
+ datasource: 'datasource',
914
+ properties: {
915
+ foo: {
916
+ type: DataType.NUMBER,
917
+ },
918
+ },
919
+ });
920
+ S.getService(ModelDataValidator).validate('model', {
921
+ foo: 10,
922
+ });
923
+ });
924
+
925
+ it('throws an error if true given', function () {
926
+ const S = new Schema();
927
+ S.defineModel({
928
+ name: 'model',
929
+ datasource: 'datasource',
930
+ properties: {
931
+ foo: {
932
+ type: DataType.NUMBER,
933
+ },
934
+ },
935
+ });
936
+ const throwable = () =>
937
+ S.getService(ModelDataValidator).validate('model', {
938
+ foo: true,
939
+ });
940
+ expect(throwable).to.throw(
941
+ 'The property "foo" of the model "model" must have ' +
942
+ 'a Number, but Boolean given.',
943
+ );
944
+ });
945
+
946
+ it('throws an error if false given', function () {
947
+ const S = new Schema();
948
+ S.defineModel({
949
+ name: 'model',
950
+ datasource: 'datasource',
951
+ properties: {
952
+ foo: {
953
+ type: DataType.NUMBER,
954
+ },
955
+ },
956
+ });
957
+ const throwable = () =>
958
+ S.getService(ModelDataValidator).validate('model', {
959
+ foo: false,
960
+ });
961
+ expect(throwable).to.throw(
962
+ 'The property "foo" of the model "model" must have ' +
963
+ 'a Number, but Boolean given.',
964
+ );
965
+ });
966
+
967
+ it('throws an error if an array given', function () {
968
+ const S = new Schema();
969
+ S.defineModel({
970
+ name: 'model',
971
+ datasource: 'datasource',
972
+ properties: {
973
+ foo: {
974
+ type: DataType.NUMBER,
975
+ },
976
+ },
977
+ });
978
+ const throwable = () =>
979
+ S.getService(ModelDataValidator).validate('model', {
980
+ foo: [],
981
+ });
982
+ expect(throwable).to.throw(
983
+ 'The property "foo" of the model "model" must have ' +
984
+ 'a Number, but Array given.',
985
+ );
986
+ });
987
+
988
+ it('throws an error if an object given', function () {
989
+ const S = new Schema();
990
+ S.defineModel({
991
+ name: 'model',
992
+ datasource: 'datasource',
993
+ properties: {
994
+ foo: {
995
+ type: DataType.NUMBER,
996
+ },
997
+ },
998
+ });
999
+ const throwable = () =>
1000
+ S.getService(ModelDataValidator).validate('model', {
1001
+ foo: {},
1002
+ });
1003
+ expect(throwable).to.throw(
1004
+ 'The property "foo" of the model "model" must have ' +
1005
+ 'a Number, but Object given.',
1006
+ );
1007
+ });
1008
+ });
1009
+ });
1010
+
1011
+ describe('DataType.BOOLEAN', function () {
1012
+ describe('ShortPropertyDefinition', function () {
1013
+ it('does not throw an error if an undefined given', function () {
1014
+ const S = new Schema();
1015
+ S.defineModel({
1016
+ name: 'model',
1017
+ datasource: 'datasource',
1018
+ properties: {
1019
+ foo: DataType.BOOLEAN,
1020
+ },
1021
+ });
1022
+ S.getService(ModelDataValidator).validate('model', {
1023
+ foo: undefined,
1024
+ });
1025
+ });
1026
+
1027
+ it('does not throw an error if a null given', function () {
1028
+ const S = new Schema();
1029
+ S.defineModel({
1030
+ name: 'model',
1031
+ datasource: 'datasource',
1032
+ properties: {
1033
+ foo: DataType.BOOLEAN,
1034
+ },
1035
+ });
1036
+ S.getService(ModelDataValidator).validate('model', {
1037
+ foo: null,
1038
+ });
1039
+ });
1040
+
1041
+ it('throws an error if a string given', function () {
1042
+ const S = new Schema();
1043
+ S.defineModel({
1044
+ name: 'model',
1045
+ datasource: 'datasource',
1046
+ properties: {
1047
+ foo: DataType.BOOLEAN,
1048
+ },
1049
+ });
1050
+ const throwable = () =>
1051
+ S.getService(ModelDataValidator).validate('model', {
1052
+ foo: 'bar',
1053
+ });
1054
+ expect(throwable).to.throw(
1055
+ 'The property "foo" of the model "model" must have ' +
1056
+ 'a Boolean, but String given.',
1057
+ );
1058
+ });
1059
+
1060
+ it('throws an error if a number given', function () {
1061
+ const S = new Schema();
1062
+ S.defineModel({
1063
+ name: 'model',
1064
+ datasource: 'datasource',
1065
+ properties: {
1066
+ foo: DataType.BOOLEAN,
1067
+ },
1068
+ });
1069
+ const throwable = () =>
1070
+ S.getService(ModelDataValidator).validate('model', {
1071
+ foo: 10,
1072
+ });
1073
+ expect(throwable).to.throw(
1074
+ 'The property "foo" of the model "model" must have ' +
1075
+ 'a Boolean, but Number given.',
1076
+ );
1077
+ });
1078
+
1079
+ it('does not throw an error if true given', function () {
1080
+ const S = new Schema();
1081
+ S.defineModel({
1082
+ name: 'model',
1083
+ datasource: 'datasource',
1084
+ properties: {
1085
+ foo: DataType.BOOLEAN,
1086
+ },
1087
+ });
1088
+ S.getService(ModelDataValidator).validate('model', {
1089
+ foo: true,
1090
+ });
1091
+ });
1092
+
1093
+ it('does not throw an error if false given', function () {
1094
+ const S = new Schema();
1095
+ S.defineModel({
1096
+ name: 'model',
1097
+ datasource: 'datasource',
1098
+ properties: {
1099
+ foo: DataType.BOOLEAN,
1100
+ },
1101
+ });
1102
+ S.getService(ModelDataValidator).validate('model', {
1103
+ foo: false,
1104
+ });
1105
+ });
1106
+
1107
+ it('throws an error if an array given', function () {
1108
+ const S = new Schema();
1109
+ S.defineModel({
1110
+ name: 'model',
1111
+ datasource: 'datasource',
1112
+ properties: {
1113
+ foo: DataType.BOOLEAN,
1114
+ },
1115
+ });
1116
+ const throwable = () =>
1117
+ S.getService(ModelDataValidator).validate('model', {
1118
+ foo: [],
1119
+ });
1120
+ expect(throwable).to.throw(
1121
+ 'The property "foo" of the model "model" must have ' +
1122
+ 'a Boolean, but Array given.',
1123
+ );
1124
+ });
1125
+
1126
+ it('throws an error if an object given', function () {
1127
+ const S = new Schema();
1128
+ S.defineModel({
1129
+ name: 'model',
1130
+ datasource: 'datasource',
1131
+ properties: {
1132
+ foo: DataType.BOOLEAN,
1133
+ },
1134
+ });
1135
+ const throwable = () =>
1136
+ S.getService(ModelDataValidator).validate('model', {
1137
+ foo: {},
1138
+ });
1139
+ expect(throwable).to.throw(
1140
+ 'The property "foo" of the model "model" must have ' +
1141
+ 'a Boolean, but Object given.',
1142
+ );
1143
+ });
1144
+ });
1145
+
1146
+ describe('FullPropertyDefinition', function () {
1147
+ it('does not throw an error if an undefined given', function () {
1148
+ const S = new Schema();
1149
+ S.defineModel({
1150
+ name: 'model',
1151
+ datasource: 'datasource',
1152
+ properties: {
1153
+ foo: {
1154
+ type: DataType.BOOLEAN,
1155
+ },
1156
+ },
1157
+ });
1158
+ S.getService(ModelDataValidator).validate('model', {
1159
+ foo: undefined,
1160
+ });
1161
+ });
1162
+
1163
+ it('does not throw an error if a null given', function () {
1164
+ const S = new Schema();
1165
+ S.defineModel({
1166
+ name: 'model',
1167
+ datasource: 'datasource',
1168
+ properties: {
1169
+ foo: {
1170
+ type: DataType.BOOLEAN,
1171
+ },
1172
+ },
1173
+ });
1174
+ S.getService(ModelDataValidator).validate('model', {
1175
+ foo: null,
1176
+ });
1177
+ });
1178
+
1179
+ it('throws an error if a string given', function () {
1180
+ const S = new Schema();
1181
+ S.defineModel({
1182
+ name: 'model',
1183
+ datasource: 'datasource',
1184
+ properties: {
1185
+ foo: {
1186
+ type: DataType.BOOLEAN,
1187
+ },
1188
+ },
1189
+ });
1190
+ const throwable = () =>
1191
+ S.getService(ModelDataValidator).validate('model', {
1192
+ foo: 'bar',
1193
+ });
1194
+ expect(throwable).to.throw(
1195
+ 'The property "foo" of the model "model" must have ' +
1196
+ 'a Boolean, but String given.',
1197
+ );
1198
+ });
1199
+
1200
+ it('throws an error if a number given', function () {
1201
+ const S = new Schema();
1202
+ S.defineModel({
1203
+ name: 'model',
1204
+ datasource: 'datasource',
1205
+ properties: {
1206
+ foo: {
1207
+ type: DataType.BOOLEAN,
1208
+ },
1209
+ },
1210
+ });
1211
+ const throwable = () =>
1212
+ S.getService(ModelDataValidator).validate('model', {
1213
+ foo: 10,
1214
+ });
1215
+ expect(throwable).to.throw(
1216
+ 'The property "foo" of the model "model" must have ' +
1217
+ 'a Boolean, but Number given.',
1218
+ );
1219
+ });
1220
+
1221
+ it('does not throw an error if true given', function () {
1222
+ const S = new Schema();
1223
+ S.defineModel({
1224
+ name: 'model',
1225
+ datasource: 'datasource',
1226
+ properties: {
1227
+ foo: {
1228
+ type: DataType.BOOLEAN,
1229
+ },
1230
+ },
1231
+ });
1232
+ S.getService(ModelDataValidator).validate('model', {
1233
+ foo: true,
1234
+ });
1235
+ });
1236
+
1237
+ it('does not throw an error if false given', function () {
1238
+ const S = new Schema();
1239
+ S.defineModel({
1240
+ name: 'model',
1241
+ datasource: 'datasource',
1242
+ properties: {
1243
+ foo: {
1244
+ type: DataType.BOOLEAN,
1245
+ },
1246
+ },
1247
+ });
1248
+ S.getService(ModelDataValidator).validate('model', {
1249
+ foo: false,
1250
+ });
1251
+ });
1252
+
1253
+ it('throws an error if an array given', function () {
1254
+ const S = new Schema();
1255
+ S.defineModel({
1256
+ name: 'model',
1257
+ datasource: 'datasource',
1258
+ properties: {
1259
+ foo: {
1260
+ type: DataType.BOOLEAN,
1261
+ },
1262
+ },
1263
+ });
1264
+ const throwable = () =>
1265
+ S.getService(ModelDataValidator).validate('model', {
1266
+ foo: [],
1267
+ });
1268
+ expect(throwable).to.throw(
1269
+ 'The property "foo" of the model "model" must have ' +
1270
+ 'a Boolean, but Array given.',
1271
+ );
1272
+ });
1273
+
1274
+ it('throws an error if an object given', function () {
1275
+ const S = new Schema();
1276
+ S.defineModel({
1277
+ name: 'model',
1278
+ datasource: 'datasource',
1279
+ properties: {
1280
+ foo: {
1281
+ type: DataType.BOOLEAN,
1282
+ },
1283
+ },
1284
+ });
1285
+ const throwable = () =>
1286
+ S.getService(ModelDataValidator).validate('model', {
1287
+ foo: {},
1288
+ });
1289
+ expect(throwable).to.throw(
1290
+ 'The property "foo" of the model "model" must have ' +
1291
+ 'a Boolean, but Object given.',
1292
+ );
1293
+ });
1294
+ });
1295
+ });
1296
+
1297
+ describe('DataType.ARRAY', function () {
1298
+ describe('ShortPropertyDefinition', function () {
1299
+ it('does not throw an error if an undefined given', function () {
1300
+ const S = new Schema();
1301
+ S.defineModel({
1302
+ name: 'model',
1303
+ datasource: 'datasource',
1304
+ properties: {
1305
+ foo: DataType.ARRAY,
1306
+ },
1307
+ });
1308
+ S.getService(ModelDataValidator).validate('model', {
1309
+ foo: undefined,
1310
+ });
1311
+ });
1312
+
1313
+ it('does not throw an error if a null given', function () {
1314
+ const S = new Schema();
1315
+ S.defineModel({
1316
+ name: 'model',
1317
+ datasource: 'datasource',
1318
+ properties: {
1319
+ foo: DataType.ARRAY,
1320
+ },
1321
+ });
1322
+ S.getService(ModelDataValidator).validate('model', {
1323
+ foo: null,
1324
+ });
1325
+ });
1326
+
1327
+ it('throws an error if a string given', function () {
1328
+ const S = new Schema();
1329
+ S.defineModel({
1330
+ name: 'model',
1331
+ datasource: 'datasource',
1332
+ properties: {
1333
+ foo: DataType.ARRAY,
1334
+ },
1335
+ });
1336
+ const throwable = () =>
1337
+ S.getService(ModelDataValidator).validate('model', {
1338
+ foo: 'bar',
1339
+ });
1340
+ expect(throwable).to.throw(
1341
+ 'The property "foo" of the model "model" must have ' +
1342
+ 'an Array, but String given.',
1343
+ );
1344
+ });
1345
+
1346
+ it('throws an error if a number given', function () {
1347
+ const S = new Schema();
1348
+ S.defineModel({
1349
+ name: 'model',
1350
+ datasource: 'datasource',
1351
+ properties: {
1352
+ foo: DataType.ARRAY,
1353
+ },
1354
+ });
1355
+ const throwable = () =>
1356
+ S.getService(ModelDataValidator).validate('model', {
1357
+ foo: 10,
1358
+ });
1359
+ expect(throwable).to.throw(
1360
+ 'The property "foo" of the model "model" must have ' +
1361
+ 'an Array, but Number given.',
1362
+ );
1363
+ });
1364
+
1365
+ it('throws an error if true given', function () {
1366
+ const S = new Schema();
1367
+ S.defineModel({
1368
+ name: 'model',
1369
+ datasource: 'datasource',
1370
+ properties: {
1371
+ foo: DataType.ARRAY,
1372
+ },
1373
+ });
1374
+ const throwable = () =>
1375
+ S.getService(ModelDataValidator).validate('model', {
1376
+ foo: true,
1377
+ });
1378
+ expect(throwable).to.throw(
1379
+ 'The property "foo" of the model "model" must have ' +
1380
+ 'an Array, but Boolean given.',
1381
+ );
1382
+ });
1383
+
1384
+ it('throws an error if false given', function () {
1385
+ const S = new Schema();
1386
+ S.defineModel({
1387
+ name: 'model',
1388
+ datasource: 'datasource',
1389
+ properties: {
1390
+ foo: DataType.ARRAY,
1391
+ },
1392
+ });
1393
+ const throwable = () =>
1394
+ S.getService(ModelDataValidator).validate('model', {
1395
+ foo: false,
1396
+ });
1397
+ expect(throwable).to.throw(
1398
+ 'The property "foo" of the model "model" must have ' +
1399
+ 'an Array, but Boolean given.',
1400
+ );
1401
+ });
1402
+
1403
+ it('does not throw an error if an array given', function () {
1404
+ const S = new Schema();
1405
+ S.defineModel({
1406
+ name: 'model',
1407
+ datasource: 'datasource',
1408
+ properties: {
1409
+ foo: DataType.ARRAY,
1410
+ },
1411
+ });
1412
+ S.getService(ModelDataValidator).validate('model', {
1413
+ foo: [],
1414
+ });
1415
+ });
1416
+
1417
+ it('throws an error if an object given', function () {
1418
+ const S = new Schema();
1419
+ S.defineModel({
1420
+ name: 'model',
1421
+ datasource: 'datasource',
1422
+ properties: {
1423
+ foo: DataType.ARRAY,
1424
+ },
1425
+ });
1426
+ const throwable = () =>
1427
+ S.getService(ModelDataValidator).validate('model', {
1428
+ foo: {},
1429
+ });
1430
+ expect(throwable).to.throw(
1431
+ 'The property "foo" of the model "model" must have ' +
1432
+ 'an Array, but Object given.',
1433
+ );
1434
+ });
1435
+ });
1436
+
1437
+ describe('FullPropertyDefinition', function () {
1438
+ it('does not throw an error if an undefined given', function () {
1439
+ const S = new Schema();
1440
+ S.defineModel({
1441
+ name: 'model',
1442
+ datasource: 'datasource',
1443
+ properties: {
1444
+ foo: {
1445
+ type: DataType.ARRAY,
1446
+ },
1447
+ },
1448
+ });
1449
+ S.getService(ModelDataValidator).validate('model', {
1450
+ foo: undefined,
1451
+ });
1452
+ });
1453
+
1454
+ it('does not throw an error if a null given', function () {
1455
+ const S = new Schema();
1456
+ S.defineModel({
1457
+ name: 'model',
1458
+ datasource: 'datasource',
1459
+ properties: {
1460
+ foo: {
1461
+ type: DataType.ARRAY,
1462
+ },
1463
+ },
1464
+ });
1465
+ S.getService(ModelDataValidator).validate('model', {
1466
+ foo: null,
1467
+ });
1468
+ });
1469
+
1470
+ it('throws an error if a string given', function () {
1471
+ const S = new Schema();
1472
+ S.defineModel({
1473
+ name: 'model',
1474
+ datasource: 'datasource',
1475
+ properties: {
1476
+ foo: {
1477
+ type: DataType.ARRAY,
1478
+ },
1479
+ },
1480
+ });
1481
+ const throwable = () =>
1482
+ S.getService(ModelDataValidator).validate('model', {
1483
+ foo: 'bar',
1484
+ });
1485
+ expect(throwable).to.throw(
1486
+ 'The property "foo" of the model "model" must have ' +
1487
+ 'an Array, but String given.',
1488
+ );
1489
+ });
1490
+
1491
+ it('throws an error if a number given', function () {
1492
+ const S = new Schema();
1493
+ S.defineModel({
1494
+ name: 'model',
1495
+ datasource: 'datasource',
1496
+ properties: {
1497
+ foo: {
1498
+ type: DataType.ARRAY,
1499
+ },
1500
+ },
1501
+ });
1502
+ const throwable = () =>
1503
+ S.getService(ModelDataValidator).validate('model', {
1504
+ foo: 10,
1505
+ });
1506
+ expect(throwable).to.throw(
1507
+ 'The property "foo" of the model "model" must have ' +
1508
+ 'an Array, but Number given.',
1509
+ );
1510
+ });
1511
+
1512
+ it('throws an error if true given', function () {
1513
+ const S = new Schema();
1514
+ S.defineModel({
1515
+ name: 'model',
1516
+ datasource: 'datasource',
1517
+ properties: {
1518
+ foo: {
1519
+ type: DataType.ARRAY,
1520
+ },
1521
+ },
1522
+ });
1523
+ const throwable = () =>
1524
+ S.getService(ModelDataValidator).validate('model', {
1525
+ foo: true,
1526
+ });
1527
+ expect(throwable).to.throw(
1528
+ 'The property "foo" of the model "model" must have ' +
1529
+ 'an Array, but Boolean given.',
1530
+ );
1531
+ });
1532
+
1533
+ it('throws an error if false given', function () {
1534
+ const S = new Schema();
1535
+ S.defineModel({
1536
+ name: 'model',
1537
+ datasource: 'datasource',
1538
+ properties: {
1539
+ foo: {
1540
+ type: DataType.ARRAY,
1541
+ },
1542
+ },
1543
+ });
1544
+ const throwable = () =>
1545
+ S.getService(ModelDataValidator).validate('model', {
1546
+ foo: false,
1547
+ });
1548
+ expect(throwable).to.throw(
1549
+ 'The property "foo" of the model "model" must have ' +
1550
+ 'an Array, but Boolean given.',
1551
+ );
1552
+ });
1553
+
1554
+ it('does not throw an error if an array given', function () {
1555
+ const S = new Schema();
1556
+ S.defineModel({
1557
+ name: 'model',
1558
+ datasource: 'datasource',
1559
+ properties: {
1560
+ foo: {
1561
+ type: DataType.ARRAY,
1562
+ },
1563
+ },
1564
+ });
1565
+ S.getService(ModelDataValidator).validate('model', {
1566
+ foo: [],
1567
+ });
1568
+ });
1569
+
1570
+ it('throws an error if an object given', function () {
1571
+ const S = new Schema();
1572
+ S.defineModel({
1573
+ name: 'model',
1574
+ datasource: 'datasource',
1575
+ properties: {
1576
+ foo: {
1577
+ type: DataType.ARRAY,
1578
+ },
1579
+ },
1580
+ });
1581
+ const throwable = () =>
1582
+ S.getService(ModelDataValidator).validate('model', {
1583
+ foo: {},
1584
+ });
1585
+ expect(throwable).to.throw(
1586
+ 'The property "foo" of the model "model" must have ' +
1587
+ 'an Array, but Object given.',
1588
+ );
1589
+ });
1590
+ });
1591
+ });
1592
+
1593
+ describe('DataType.OBJECT', function () {
1594
+ describe('ShortPropertyDefinition', function () {
1595
+ it('does not throw an error if an undefined given', function () {
1596
+ const S = new Schema();
1597
+ S.defineModel({
1598
+ name: 'model',
1599
+ datasource: 'datasource',
1600
+ properties: {
1601
+ foo: DataType.OBJECT,
1602
+ },
1603
+ });
1604
+ S.getService(ModelDataValidator).validate('model', {
1605
+ foo: undefined,
1606
+ });
1607
+ });
1608
+
1609
+ it('does not throw an error if a null given', function () {
1610
+ const S = new Schema();
1611
+ S.defineModel({
1612
+ name: 'model',
1613
+ datasource: 'datasource',
1614
+ properties: {
1615
+ foo: DataType.OBJECT,
1616
+ },
1617
+ });
1618
+ S.getService(ModelDataValidator).validate('model', {
1619
+ foo: null,
1620
+ });
1621
+ });
1622
+
1623
+ it('throws an error if a string given', function () {
1624
+ const S = new Schema();
1625
+ S.defineModel({
1626
+ name: 'model',
1627
+ datasource: 'datasource',
1628
+ properties: {
1629
+ foo: DataType.OBJECT,
1630
+ },
1631
+ });
1632
+ const throwable = () =>
1633
+ S.getService(ModelDataValidator).validate('model', {
1634
+ foo: 'bar',
1635
+ });
1636
+ expect(throwable).to.throw(
1637
+ 'The property "foo" of the model "model" must have ' +
1638
+ 'an Object, but String given.',
1639
+ );
1640
+ });
1641
+
1642
+ it('throws an error if a number given', function () {
1643
+ const S = new Schema();
1644
+ S.defineModel({
1645
+ name: 'model',
1646
+ datasource: 'datasource',
1647
+ properties: {
1648
+ foo: DataType.OBJECT,
1649
+ },
1650
+ });
1651
+ const throwable = () =>
1652
+ S.getService(ModelDataValidator).validate('model', {
1653
+ foo: 10,
1654
+ });
1655
+ expect(throwable).to.throw(
1656
+ 'The property "foo" of the model "model" must have ' +
1657
+ 'an Object, but Number given.',
1658
+ );
1659
+ });
1660
+
1661
+ it('throws an error if true given', function () {
1662
+ const S = new Schema();
1663
+ S.defineModel({
1664
+ name: 'model',
1665
+ datasource: 'datasource',
1666
+ properties: {
1667
+ foo: DataType.OBJECT,
1668
+ },
1669
+ });
1670
+ const throwable = () =>
1671
+ S.getService(ModelDataValidator).validate('model', {
1672
+ foo: true,
1673
+ });
1674
+ expect(throwable).to.throw(
1675
+ 'The property "foo" of the model "model" must have ' +
1676
+ 'an Object, but Boolean given.',
1677
+ );
1678
+ });
1679
+
1680
+ it('throws an error if false given', function () {
1681
+ const S = new Schema();
1682
+ S.defineModel({
1683
+ name: 'model',
1684
+ datasource: 'datasource',
1685
+ properties: {
1686
+ foo: DataType.OBJECT,
1687
+ },
1688
+ });
1689
+ const throwable = () =>
1690
+ S.getService(ModelDataValidator).validate('model', {
1691
+ foo: false,
1692
+ });
1693
+ expect(throwable).to.throw(
1694
+ 'The property "foo" of the model "model" must have ' +
1695
+ 'an Object, but Boolean given.',
1696
+ );
1697
+ });
1698
+
1699
+ it('throws an error if an array given', function () {
1700
+ const S = new Schema();
1701
+ S.defineModel({
1702
+ name: 'model',
1703
+ datasource: 'datasource',
1704
+ properties: {
1705
+ foo: DataType.OBJECT,
1706
+ },
1707
+ });
1708
+ const throwable = () =>
1709
+ S.getService(ModelDataValidator).validate('model', {
1710
+ foo: [],
1711
+ });
1712
+ expect(throwable).to.throw(
1713
+ 'The property "foo" of the model "model" must have ' +
1714
+ 'an Object, but Array given.',
1715
+ );
1716
+ });
1717
+
1718
+ it('does not throw an error if an object given', function () {
1719
+ const S = new Schema();
1720
+ S.defineModel({
1721
+ name: 'model',
1722
+ datasource: 'datasource',
1723
+ properties: {
1724
+ foo: DataType.OBJECT,
1725
+ },
1726
+ });
1727
+ S.getService(ModelDataValidator).validate('model', {
1728
+ foo: {},
1729
+ });
1730
+ });
1731
+ });
1732
+
1733
+ describe('FullPropertyDefinition', function () {
1734
+ it('does not throw an error if an undefined given', function () {
1735
+ const S = new Schema();
1736
+ S.defineModel({
1737
+ name: 'model',
1738
+ datasource: 'datasource',
1739
+ properties: {
1740
+ foo: {
1741
+ type: DataType.OBJECT,
1742
+ },
1743
+ },
1744
+ });
1745
+ S.getService(ModelDataValidator).validate('model', {
1746
+ foo: undefined,
1747
+ });
1748
+ });
1749
+
1750
+ it('does not throw an error if a null given', function () {
1751
+ const S = new Schema();
1752
+ S.defineModel({
1753
+ name: 'model',
1754
+ datasource: 'datasource',
1755
+ properties: {
1756
+ foo: {
1757
+ type: DataType.OBJECT,
1758
+ },
1759
+ },
1760
+ });
1761
+ S.getService(ModelDataValidator).validate('model', {
1762
+ foo: null,
1763
+ });
1764
+ });
1765
+
1766
+ it('throws an error if a string given', function () {
1767
+ const S = new Schema();
1768
+ S.defineModel({
1769
+ name: 'model',
1770
+ datasource: 'datasource',
1771
+ properties: {
1772
+ foo: {
1773
+ type: DataType.OBJECT,
1774
+ },
1775
+ },
1776
+ });
1777
+ const throwable = () =>
1778
+ S.getService(ModelDataValidator).validate('model', {
1779
+ foo: 'bar',
1780
+ });
1781
+ expect(throwable).to.throw(
1782
+ 'The property "foo" of the model "model" must have ' +
1783
+ 'an Object, but String given.',
1784
+ );
1785
+ });
1786
+
1787
+ it('throws an error if a number given', function () {
1788
+ const S = new Schema();
1789
+ S.defineModel({
1790
+ name: 'model',
1791
+ datasource: 'datasource',
1792
+ properties: {
1793
+ foo: {
1794
+ type: DataType.OBJECT,
1795
+ },
1796
+ },
1797
+ });
1798
+ const throwable = () =>
1799
+ S.getService(ModelDataValidator).validate('model', {
1800
+ foo: 10,
1801
+ });
1802
+ expect(throwable).to.throw(
1803
+ 'The property "foo" of the model "model" must have ' +
1804
+ 'an Object, but Number given.',
1805
+ );
1806
+ });
1807
+
1808
+ it('throws an error if true given', function () {
1809
+ const S = new Schema();
1810
+ S.defineModel({
1811
+ name: 'model',
1812
+ datasource: 'datasource',
1813
+ properties: {
1814
+ foo: {
1815
+ type: DataType.OBJECT,
1816
+ },
1817
+ },
1818
+ });
1819
+ const throwable = () =>
1820
+ S.getService(ModelDataValidator).validate('model', {
1821
+ foo: true,
1822
+ });
1823
+ expect(throwable).to.throw(
1824
+ 'The property "foo" of the model "model" must have ' +
1825
+ 'an Object, but Boolean given.',
1826
+ );
1827
+ });
1828
+
1829
+ it('throws an error if false given', function () {
1830
+ const S = new Schema();
1831
+ S.defineModel({
1832
+ name: 'model',
1833
+ datasource: 'datasource',
1834
+ properties: {
1835
+ foo: {
1836
+ type: DataType.OBJECT,
1837
+ },
1838
+ },
1839
+ });
1840
+ const throwable = () =>
1841
+ S.getService(ModelDataValidator).validate('model', {
1842
+ foo: false,
1843
+ });
1844
+ expect(throwable).to.throw(
1845
+ 'The property "foo" of the model "model" must have ' +
1846
+ 'an Object, but Boolean given.',
1847
+ );
1848
+ });
1849
+
1850
+ it('throws an error if an array given', function () {
1851
+ const S = new Schema();
1852
+ S.defineModel({
1853
+ name: 'model',
1854
+ datasource: 'datasource',
1855
+ properties: {
1856
+ foo: {
1857
+ type: DataType.OBJECT,
1858
+ },
1859
+ },
1860
+ });
1861
+ const throwable = () =>
1862
+ S.getService(ModelDataValidator).validate('model', {
1863
+ foo: [],
1864
+ });
1865
+ expect(throwable).to.throw(
1866
+ 'The property "foo" of the model "model" must have ' +
1867
+ 'an Object, but Array given.',
1868
+ );
1869
+ });
1870
+
1871
+ it('does not throw an error if an object given', function () {
1872
+ const S = new Schema();
1873
+ S.defineModel({
1874
+ name: 'model',
1875
+ datasource: 'datasource',
1876
+ properties: {
1877
+ foo: {
1878
+ type: DataType.OBJECT,
1879
+ },
1880
+ },
1881
+ });
1882
+ S.getService(ModelDataValidator).validate('model', {
1883
+ foo: {},
1884
+ });
1885
+ });
1886
+ });
1887
+ });
1888
+ });
1889
+ });