@e22m4u/js-repository 0.8.7 → 0.8.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +359 -300
- package/package.json +3 -3
- package/src/adapter/adapter-loader.js +2 -5
- package/src/adapter/adapter-loader.spec.js +2 -2
- package/src/adapter/adapter-registry.spec.js +2 -2
- package/src/adapter/builtin/memory-adapter.js +5 -5
- package/src/adapter/builtin/memory-adapter.spec.js +12 -12
- package/src/adapter/decorator/data-sanitizing-decorator.js +1 -2
- package/src/adapter/decorator/default-values-decorator.js +1 -2
- package/src/adapter/decorator/fields-filtering-decorator.js +1 -2
- package/src/adapter/decorator/inclusion-decorator.js +1 -2
- package/src/adapter/decorator/property-uniqueness-decorator.js +1 -2
- package/src/adapter/decorator/required-property-decorator.js +1 -2
- package/src/database-schema.spec.js +3 -5
- package/src/definition/datasource/datasource-definition-validator.js +3 -3
- package/src/definition/datasource/datasource-definition-validator.spec.js +3 -6
- package/src/definition/definition-registry.js +4 -7
- package/src/definition/definition-registry.spec.js +4 -6
- package/src/definition/model/model-data-sanitizer.js +2 -4
- package/src/definition/model/model-definition-utils.js +12 -14
- package/src/definition/model/model-definition-utils.spec.js +12 -21
- package/src/definition/model/model-definition-validator.js +12 -12
- package/src/definition/model/model-definition-validator.spec.js +12 -15
- package/src/definition/model/properties/primary-keys-definition-validator.js +4 -4
- package/src/definition/model/properties/primary-keys-definition-validator.spec.js +8 -8
- package/src/definition/model/properties/properties-definition-validator.js +42 -43
- package/src/definition/model/properties/properties-definition-validator.spec.js +45 -45
- package/src/definition/model/properties/property-uniqueness-validator.js +7 -11
- package/src/definition/model/properties/property-uniqueness-validator.spec.js +57 -60
- package/src/definition/model/properties/required-property-validator.js +1 -1
- package/src/definition/model/properties/required-property-validator.spec.js +1 -1
- package/src/definition/model/relations/relations-definition-validator.js +40 -42
- package/src/definition/model/relations/relations-definition-validator.spec.js +44 -45
- package/src/errors/invalid-operator-value-error.js +1 -1
- package/src/errors/invalid-operator-value-error.spec.js +1 -1
- package/src/filter/fields-clause-tool.js +95 -53
- package/src/filter/fields-clause-tool.spec.js +210 -387
- package/src/filter/include-clause-tool.js +9 -9
- package/src/filter/include-clause-tool.spec.js +4 -4
- package/src/filter/operator-clause-tool.js +20 -32
- package/src/filter/operator-clause-tool.spec.js +25 -49
- package/src/filter/order-clause-tool.js +55 -27
- package/src/filter/order-clause-tool.spec.js +151 -90
- package/src/filter/slice-clause-tool.js +5 -6
- package/src/filter/slice-clause-tool.spec.js +8 -24
- package/src/filter/where-clause-tool.js +18 -11
- package/src/filter/where-clause-tool.spec.js +27 -17
- package/src/relations/belongs-to-resolver.js +18 -30
- package/src/relations/belongs-to-resolver.spec.js +21 -44
- package/src/relations/has-many-resolver.js +28 -44
- package/src/relations/has-many-resolver.spec.js +44 -68
- package/src/relations/has-one-resolver.js +28 -44
- package/src/relations/has-one-resolver.spec.js +44 -68
- package/src/relations/references-many-resolver.js +8 -14
- package/src/relations/references-many-resolver.spec.js +12 -24
- package/src/repository/repository-registry.js +2 -2
- package/src/repository/repository.js +1 -1
- package/src/utils/exclude-object-keys.js +2 -2
- package/src/utils/exclude-object-keys.spec.js +2 -2
- package/src/utils/like-to-regexp.js +1 -2
- package/src/utils/like-to-regexp.spec.js +5 -5
- package/src/utils/model-name-to-model-key.js +1 -1
- package/src/utils/model-name-to-model-key.spec.js +7 -7
- package/src/utils/select-object-keys.js +6 -7
- package/src/utils/select-object-keys.spec.js +3 -6
|
@@ -15,15 +15,14 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
15
15
|
validate(modelName, relDefs) {
|
|
16
16
|
if (!modelName || typeof modelName !== 'string') {
|
|
17
17
|
throw new InvalidArgumentError(
|
|
18
|
-
'
|
|
19
|
-
'should be a non-empty String, but %v was given.',
|
|
18
|
+
'Parameter "modelName" must be a non-empty String, but %v was given.',
|
|
20
19
|
modelName,
|
|
21
20
|
);
|
|
22
21
|
}
|
|
23
22
|
if (!relDefs || typeof relDefs !== 'object' || Array.isArray(relDefs)) {
|
|
24
23
|
throw new InvalidArgumentError(
|
|
25
|
-
'
|
|
26
|
-
'
|
|
24
|
+
'Option "relations" of the model %v ' +
|
|
25
|
+
'must be an Object, but %v was given.',
|
|
27
26
|
modelName,
|
|
28
27
|
relDefs,
|
|
29
28
|
);
|
|
@@ -45,14 +44,13 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
45
44
|
_validateRelation(modelName, relName, relDef) {
|
|
46
45
|
if (!modelName || typeof modelName !== 'string') {
|
|
47
46
|
throw new InvalidArgumentError(
|
|
48
|
-
'
|
|
49
|
-
'should be a non-empty String, but %v was given.',
|
|
47
|
+
'Parameter "modelName" must be a non-empty String, but %v was given.',
|
|
50
48
|
modelName,
|
|
51
49
|
);
|
|
52
50
|
}
|
|
53
51
|
if (!relName || typeof relName !== 'string') {
|
|
54
52
|
throw new InvalidArgumentError(
|
|
55
|
-
'
|
|
53
|
+
'Relation name of the model %v must be ' +
|
|
56
54
|
'a non-empty String, but %v was given.',
|
|
57
55
|
modelName,
|
|
58
56
|
relName,
|
|
@@ -60,7 +58,7 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
60
58
|
}
|
|
61
59
|
if (!relDef || typeof relDef !== 'object' || Array.isArray(relDef)) {
|
|
62
60
|
throw new InvalidArgumentError(
|
|
63
|
-
'
|
|
61
|
+
'Relation %v of the model %v must be an Object, but %v was given.',
|
|
64
62
|
relName,
|
|
65
63
|
modelName,
|
|
66
64
|
relDef,
|
|
@@ -68,7 +66,7 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
68
66
|
}
|
|
69
67
|
if (!relDef.type || !Object.values(RelationType).includes(relDef.type)) {
|
|
70
68
|
throw new InvalidArgumentError(
|
|
71
|
-
'
|
|
69
|
+
'Relation %v of the model %v requires the option "type" ' +
|
|
72
70
|
'to have one of relation types: %l, but %v was given.',
|
|
73
71
|
relName,
|
|
74
72
|
modelName,
|
|
@@ -117,7 +115,7 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
117
115
|
// A polymorphic "belongsTo" relation.
|
|
118
116
|
if (typeof relDef.polymorphic !== 'boolean') {
|
|
119
117
|
throw new InvalidArgumentError(
|
|
120
|
-
'
|
|
118
|
+
'Relation %v of the model %v has the type "belongsTo", ' +
|
|
121
119
|
'so it expects the option "polymorphic" to be a Boolean, ' +
|
|
122
120
|
'but %v was given.',
|
|
123
121
|
relName,
|
|
@@ -127,7 +125,7 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
127
125
|
}
|
|
128
126
|
if (relDef.foreignKey && typeof relDef.foreignKey !== 'string') {
|
|
129
127
|
throw new InvalidArgumentError(
|
|
130
|
-
'
|
|
128
|
+
'Relation %v of the model %v is a polymorphic "belongsTo" relation, ' +
|
|
131
129
|
'so it expects the provided option "foreignKey" to be a String, ' +
|
|
132
130
|
'but %v was given.',
|
|
133
131
|
relName,
|
|
@@ -137,7 +135,7 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
137
135
|
}
|
|
138
136
|
if (relDef.discriminator && typeof relDef.discriminator !== 'string') {
|
|
139
137
|
throw new InvalidArgumentError(
|
|
140
|
-
'
|
|
138
|
+
'Relation %v of the model %v is a polymorphic "belongsTo" relation, ' +
|
|
141
139
|
'so it expects the provided option "discriminator" to be a String, ' +
|
|
142
140
|
'but %v was given.',
|
|
143
141
|
relName,
|
|
@@ -149,7 +147,7 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
149
147
|
// A regular "belongsTo" relation.
|
|
150
148
|
if (!relDef.model || typeof relDef.model !== 'string') {
|
|
151
149
|
throw new InvalidArgumentError(
|
|
152
|
-
'
|
|
150
|
+
'Relation %v of the model %v has the type "belongsTo", ' +
|
|
153
151
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
154
152
|
'but %v was given.',
|
|
155
153
|
relName,
|
|
@@ -159,7 +157,7 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
159
157
|
}
|
|
160
158
|
if (relDef.foreignKey && typeof relDef.foreignKey !== 'string') {
|
|
161
159
|
throw new InvalidArgumentError(
|
|
162
|
-
'
|
|
160
|
+
'Relation %v of the model %v has the type "belongsTo", ' +
|
|
163
161
|
'so it expects the provided option "foreignKey" to be a String, ' +
|
|
164
162
|
'but %v was given.',
|
|
165
163
|
relName,
|
|
@@ -169,8 +167,8 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
169
167
|
}
|
|
170
168
|
if (relDef.discriminator) {
|
|
171
169
|
throw new InvalidArgumentError(
|
|
172
|
-
'
|
|
173
|
-
'so it
|
|
170
|
+
'Relation %v of the model %v is a non-polymorphic "belongsTo" relation, ' +
|
|
171
|
+
'so it must not have the option "discriminator" to be provided.',
|
|
174
172
|
relName,
|
|
175
173
|
modelName,
|
|
176
174
|
);
|
|
@@ -221,7 +219,7 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
221
219
|
}
|
|
222
220
|
if (!relDef.model || typeof relDef.model !== 'string') {
|
|
223
221
|
throw new InvalidArgumentError(
|
|
224
|
-
'
|
|
222
|
+
'Relation %v of the model %v has the type "hasOne", ' +
|
|
225
223
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
226
224
|
'but %v was given.',
|
|
227
225
|
relName,
|
|
@@ -234,8 +232,8 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
234
232
|
// A polymorphic "hasOne" relation with a target relation name.
|
|
235
233
|
if (relDef.foreignKey) {
|
|
236
234
|
throw new InvalidArgumentError(
|
|
237
|
-
'
|
|
238
|
-
'a String value, so it
|
|
235
|
+
'Relation %v of the model %v has the option "polymorphic" with ' +
|
|
236
|
+
'a String value, so it must not have the option "foreignKey" ' +
|
|
239
237
|
'to be provided.',
|
|
240
238
|
relName,
|
|
241
239
|
modelName,
|
|
@@ -243,8 +241,8 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
243
241
|
}
|
|
244
242
|
if (relDef.discriminator) {
|
|
245
243
|
throw new InvalidArgumentError(
|
|
246
|
-
'
|
|
247
|
-
'a String value, so it
|
|
244
|
+
'Relation %v of the model %v has the option "polymorphic" with ' +
|
|
245
|
+
'a String value, so it must not have the option "discriminator" ' +
|
|
248
246
|
'to be provided.',
|
|
249
247
|
relName,
|
|
250
248
|
modelName,
|
|
@@ -254,7 +252,7 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
254
252
|
// A polymorphic "hasOne" relation with target relation keys.
|
|
255
253
|
if (!relDef.foreignKey || typeof relDef.foreignKey !== 'string') {
|
|
256
254
|
throw new InvalidArgumentError(
|
|
257
|
-
'
|
|
255
|
+
'Relation %v of the model %v has the option "polymorphic" ' +
|
|
258
256
|
'with "true" value, so it requires the option "foreignKey" ' +
|
|
259
257
|
'to be a non-empty String, but %v was given.',
|
|
260
258
|
relName,
|
|
@@ -264,7 +262,7 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
264
262
|
}
|
|
265
263
|
if (!relDef.discriminator || typeof relDef.discriminator !== 'string') {
|
|
266
264
|
throw new InvalidArgumentError(
|
|
267
|
-
'
|
|
265
|
+
'Relation %v of the model %v has the option "polymorphic" ' +
|
|
268
266
|
'with "true" value, so it requires the option "discriminator" ' +
|
|
269
267
|
'to be a non-empty String, but %v was given.',
|
|
270
268
|
relName,
|
|
@@ -274,7 +272,7 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
274
272
|
}
|
|
275
273
|
} else {
|
|
276
274
|
throw new InvalidArgumentError(
|
|
277
|
-
'
|
|
275
|
+
'Relation %v of the model %v has the type "hasOne", ' +
|
|
278
276
|
'so it expects the provided option "polymorphic" to be ' +
|
|
279
277
|
'a String or a Boolean, but %v was given.',
|
|
280
278
|
relName,
|
|
@@ -286,7 +284,7 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
286
284
|
// A regular "hasOne" relation.
|
|
287
285
|
if (!relDef.foreignKey || typeof relDef.foreignKey !== 'string') {
|
|
288
286
|
throw new InvalidArgumentError(
|
|
289
|
-
'
|
|
287
|
+
'Relation %v of the model %v has the type "hasOne", ' +
|
|
290
288
|
'so it requires the option "foreignKey" to be a non-empty String, ' +
|
|
291
289
|
'but %v was given.',
|
|
292
290
|
relName,
|
|
@@ -296,8 +294,8 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
296
294
|
}
|
|
297
295
|
if (relDef.discriminator) {
|
|
298
296
|
throw new InvalidArgumentError(
|
|
299
|
-
'
|
|
300
|
-
'so it
|
|
297
|
+
'Relation %v of the model %v is a non-polymorphic "hasOne" relation, ' +
|
|
298
|
+
'so it must not have the option "discriminator" to be provided.',
|
|
301
299
|
relName,
|
|
302
300
|
modelName,
|
|
303
301
|
);
|
|
@@ -348,7 +346,7 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
348
346
|
}
|
|
349
347
|
if (!relDef.model || typeof relDef.model !== 'string') {
|
|
350
348
|
throw new InvalidArgumentError(
|
|
351
|
-
'
|
|
349
|
+
'Relation %v of the model %v has the type "hasMany", ' +
|
|
352
350
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
353
351
|
'but %v was given.',
|
|
354
352
|
relName,
|
|
@@ -361,8 +359,8 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
361
359
|
// A polymorphic "hasMany" relation with a target relation name.
|
|
362
360
|
if (relDef.foreignKey) {
|
|
363
361
|
throw new InvalidArgumentError(
|
|
364
|
-
'
|
|
365
|
-
'a String value, so it
|
|
362
|
+
'Relation %v of the model %v has the option "polymorphic" with ' +
|
|
363
|
+
'a String value, so it must not have the option "foreignKey" ' +
|
|
366
364
|
'to be provided.',
|
|
367
365
|
relName,
|
|
368
366
|
modelName,
|
|
@@ -370,8 +368,8 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
370
368
|
}
|
|
371
369
|
if (relDef.discriminator) {
|
|
372
370
|
throw new InvalidArgumentError(
|
|
373
|
-
'
|
|
374
|
-
'a String value, so it
|
|
371
|
+
'Relation %v of the model %v has the option "polymorphic" with ' +
|
|
372
|
+
'a String value, so it must not have the option "discriminator" ' +
|
|
375
373
|
'to be provided.',
|
|
376
374
|
relName,
|
|
377
375
|
modelName,
|
|
@@ -381,7 +379,7 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
381
379
|
// A polymorphic "hasMany" relation with target relation keys.
|
|
382
380
|
if (!relDef.foreignKey || typeof relDef.foreignKey !== 'string') {
|
|
383
381
|
throw new InvalidArgumentError(
|
|
384
|
-
'
|
|
382
|
+
'Relation %v of the model %v has the option "polymorphic" ' +
|
|
385
383
|
'with "true" value, so it requires the option "foreignKey" ' +
|
|
386
384
|
'to be a non-empty String, but %v was given.',
|
|
387
385
|
relName,
|
|
@@ -391,7 +389,7 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
391
389
|
}
|
|
392
390
|
if (!relDef.discriminator || typeof relDef.discriminator !== 'string') {
|
|
393
391
|
throw new InvalidArgumentError(
|
|
394
|
-
'
|
|
392
|
+
'Relation %v of the model %v has the option "polymorphic" ' +
|
|
395
393
|
'with "true" value, so it requires the option "discriminator" ' +
|
|
396
394
|
'to be a non-empty String, but %v was given.',
|
|
397
395
|
relName,
|
|
@@ -401,7 +399,7 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
401
399
|
}
|
|
402
400
|
} else {
|
|
403
401
|
throw new InvalidArgumentError(
|
|
404
|
-
'
|
|
402
|
+
'Relation %v of the model %v has the type "hasMany", ' +
|
|
405
403
|
'so it expects the provided option "polymorphic" to be ' +
|
|
406
404
|
'a String or a Boolean, but %v was given.',
|
|
407
405
|
relName,
|
|
@@ -413,7 +411,7 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
413
411
|
// A regular "hasMany" relation.
|
|
414
412
|
if (!relDef.foreignKey || typeof relDef.foreignKey !== 'string') {
|
|
415
413
|
throw new InvalidArgumentError(
|
|
416
|
-
'
|
|
414
|
+
'Relation %v of the model %v has the type "hasMany", ' +
|
|
417
415
|
'so it requires the option "foreignKey" to be a non-empty String, ' +
|
|
418
416
|
'but %v was given.',
|
|
419
417
|
relName,
|
|
@@ -423,8 +421,8 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
423
421
|
}
|
|
424
422
|
if (relDef.discriminator) {
|
|
425
423
|
throw new InvalidArgumentError(
|
|
426
|
-
'
|
|
427
|
-
'so it
|
|
424
|
+
'Relation %v of the model %v is a non-polymorphic "hasMany" relation, ' +
|
|
425
|
+
'so it must not have the option "discriminator" to be provided.',
|
|
428
426
|
relName,
|
|
429
427
|
modelName,
|
|
430
428
|
);
|
|
@@ -455,7 +453,7 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
455
453
|
}
|
|
456
454
|
if (!relDef.model || typeof relDef.model !== 'string') {
|
|
457
455
|
throw new InvalidArgumentError(
|
|
458
|
-
'
|
|
456
|
+
'Relation %v of the model %v has the type "referencesMany", ' +
|
|
459
457
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
460
458
|
'but %v was given.',
|
|
461
459
|
relName,
|
|
@@ -465,7 +463,7 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
465
463
|
}
|
|
466
464
|
if (relDef.foreignKey && typeof relDef.foreignKey !== 'string') {
|
|
467
465
|
throw new InvalidArgumentError(
|
|
468
|
-
'
|
|
466
|
+
'Relation %v of the model %v has the type "referencesMany", ' +
|
|
469
467
|
'so it expects the provided option "foreignKey" to be a String, ' +
|
|
470
468
|
'but %v was given.',
|
|
471
469
|
relName,
|
|
@@ -475,8 +473,8 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
475
473
|
}
|
|
476
474
|
if (relDef.discriminator) {
|
|
477
475
|
throw new InvalidArgumentError(
|
|
478
|
-
'
|
|
479
|
-
'so it
|
|
476
|
+
'Relation %v of the model %v has the type "referencesMany", ' +
|
|
477
|
+
'so it must not have the option "discriminator" to be provided.',
|
|
480
478
|
relName,
|
|
481
479
|
modelName,
|
|
482
480
|
);
|
|
@@ -7,12 +7,11 @@ const S = new RelationsDefinitionValidator();
|
|
|
7
7
|
|
|
8
8
|
describe('RelationsDefinitionValidator', function () {
|
|
9
9
|
describe('validate', function () {
|
|
10
|
-
it('requires
|
|
10
|
+
it('requires the parameter "modelName" to be a non-empty string', function () {
|
|
11
11
|
const validate = v => () => S.validate(v, {});
|
|
12
12
|
const error = v =>
|
|
13
13
|
format(
|
|
14
|
-
'
|
|
15
|
-
'should be a non-empty String, but %s was given.',
|
|
14
|
+
'Parameter "modelName" must be a non-empty String, but %s was given.',
|
|
16
15
|
v,
|
|
17
16
|
);
|
|
18
17
|
expect(validate('')).to.throw(error('""'));
|
|
@@ -26,12 +25,12 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
26
25
|
validate('model')();
|
|
27
26
|
});
|
|
28
27
|
|
|
29
|
-
it('requires
|
|
28
|
+
it('requires the parameter "relDefs" to be an object', function () {
|
|
30
29
|
const validate = v => () => S.validate('model', v);
|
|
31
30
|
const error = v =>
|
|
32
31
|
format(
|
|
33
|
-
'
|
|
34
|
-
'
|
|
32
|
+
'Option "relations" of the model "model" ' +
|
|
33
|
+
'must be an Object, but %s was given.',
|
|
35
34
|
v,
|
|
36
35
|
);
|
|
37
36
|
expect(validate('str')).to.throw(error('"str"'));
|
|
@@ -48,7 +47,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
48
47
|
const validate = v => () => S.validate('model', v);
|
|
49
48
|
const error = v =>
|
|
50
49
|
format(
|
|
51
|
-
'
|
|
50
|
+
'Relation name of the model "model" must be ' +
|
|
52
51
|
'a non-empty String, but %s was given.',
|
|
53
52
|
v,
|
|
54
53
|
);
|
|
@@ -60,8 +59,8 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
60
59
|
const validate = v => () => S.validate('model', {foo: v});
|
|
61
60
|
const error = v =>
|
|
62
61
|
format(
|
|
63
|
-
'
|
|
64
|
-
'
|
|
62
|
+
'Relation "foo" of the model "model" must be an Object, ' +
|
|
63
|
+
'but %s was given.',
|
|
65
64
|
v,
|
|
66
65
|
);
|
|
67
66
|
expect(validate('str')).to.throw(error('"str"'));
|
|
@@ -81,7 +80,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
81
80
|
};
|
|
82
81
|
const error = v =>
|
|
83
82
|
format(
|
|
84
|
-
'
|
|
83
|
+
'Relation "foo" of the model "model" requires the option "type" ' +
|
|
85
84
|
'to have one of relation types: %l, but %s was given.',
|
|
86
85
|
Object.values(RelationType),
|
|
87
86
|
v,
|
|
@@ -109,7 +108,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
109
108
|
};
|
|
110
109
|
const error = v =>
|
|
111
110
|
format(
|
|
112
|
-
'
|
|
111
|
+
'Relation "foo" of the model "model" has the type "belongsTo", ' +
|
|
113
112
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
114
113
|
'but %s was given.',
|
|
115
114
|
v,
|
|
@@ -136,7 +135,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
136
135
|
};
|
|
137
136
|
const error = v =>
|
|
138
137
|
format(
|
|
139
|
-
'
|
|
138
|
+
'Relation "foo" of the model "model" has the type "belongsTo", ' +
|
|
140
139
|
'so it expects the provided option "foreignKey" to be a String, ' +
|
|
141
140
|
'but %s was given.',
|
|
142
141
|
v,
|
|
@@ -162,8 +161,8 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
162
161
|
},
|
|
163
162
|
});
|
|
164
163
|
expect(throwable).to.throw(
|
|
165
|
-
'
|
|
166
|
-
'so it
|
|
164
|
+
'Relation "foo" of the model "model" is a non-polymorphic "belongsTo" relation, ' +
|
|
165
|
+
'so it must not have the option "discriminator" to be provided.',
|
|
167
166
|
);
|
|
168
167
|
});
|
|
169
168
|
});
|
|
@@ -179,7 +178,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
179
178
|
};
|
|
180
179
|
const error = v =>
|
|
181
180
|
format(
|
|
182
|
-
'
|
|
181
|
+
'Relation "foo" of the model "model" has the type "belongsTo", ' +
|
|
183
182
|
'so it expects the option "polymorphic" to be a Boolean, ' +
|
|
184
183
|
'but %s was given.',
|
|
185
184
|
v,
|
|
@@ -202,7 +201,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
202
201
|
};
|
|
203
202
|
const error = v =>
|
|
204
203
|
format(
|
|
205
|
-
'
|
|
204
|
+
'Relation "foo" of the model "model" is a polymorphic "belongsTo" relation, ' +
|
|
206
205
|
'so it expects the provided option "foreignKey" to be a String, ' +
|
|
207
206
|
'but %s was given.',
|
|
208
207
|
v,
|
|
@@ -229,7 +228,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
229
228
|
};
|
|
230
229
|
const error = v =>
|
|
231
230
|
format(
|
|
232
|
-
'
|
|
231
|
+
'Relation "foo" of the model "model" is a polymorphic "belongsTo" relation, ' +
|
|
233
232
|
'so it expects the provided option "discriminator" to be a String, ' +
|
|
234
233
|
'but %s was given.',
|
|
235
234
|
v,
|
|
@@ -260,7 +259,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
260
259
|
};
|
|
261
260
|
const error = v =>
|
|
262
261
|
format(
|
|
263
|
-
'
|
|
262
|
+
'Relation "foo" of the model "model" has the type "hasOne", ' +
|
|
264
263
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
265
264
|
'but %s was given.',
|
|
266
265
|
v,
|
|
@@ -287,7 +286,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
287
286
|
};
|
|
288
287
|
const error = v =>
|
|
289
288
|
format(
|
|
290
|
-
'
|
|
289
|
+
'Relation "foo" of the model "model" has the type "hasOne", ' +
|
|
291
290
|
'so it requires the option "foreignKey" to be a non-empty String, ' +
|
|
292
291
|
'but %s was given.',
|
|
293
292
|
v,
|
|
@@ -314,8 +313,8 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
314
313
|
},
|
|
315
314
|
});
|
|
316
315
|
expect(throwable).to.throw(
|
|
317
|
-
'
|
|
318
|
-
'so it
|
|
316
|
+
'Relation "foo" of the model "model" is a non-polymorphic "hasOne" relation, ' +
|
|
317
|
+
'so it must not have the option "discriminator" to be provided.',
|
|
319
318
|
);
|
|
320
319
|
});
|
|
321
320
|
});
|
|
@@ -332,7 +331,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
332
331
|
};
|
|
333
332
|
const error = v =>
|
|
334
333
|
format(
|
|
335
|
-
'
|
|
334
|
+
'Relation "foo" of the model "model" has the type "hasOne", ' +
|
|
336
335
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
337
336
|
'but %s was given.',
|
|
338
337
|
v,
|
|
@@ -359,8 +358,8 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
359
358
|
},
|
|
360
359
|
});
|
|
361
360
|
expect(throwable).to.throw(
|
|
362
|
-
'
|
|
363
|
-
'a String value, so it
|
|
361
|
+
'Relation "foo" of the model "model" has the option "polymorphic" with ' +
|
|
362
|
+
'a String value, so it must not have the option "foreignKey" ' +
|
|
364
363
|
'to be provided.',
|
|
365
364
|
);
|
|
366
365
|
});
|
|
@@ -376,8 +375,8 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
376
375
|
},
|
|
377
376
|
});
|
|
378
377
|
expect(throwable).to.throw(
|
|
379
|
-
'
|
|
380
|
-
'a String value, so it
|
|
378
|
+
'Relation "foo" of the model "model" has the option "polymorphic" with ' +
|
|
379
|
+
'a String value, so it must not have the option "discriminator" ' +
|
|
381
380
|
'to be provided.',
|
|
382
381
|
);
|
|
383
382
|
});
|
|
@@ -397,7 +396,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
397
396
|
};
|
|
398
397
|
const error = v =>
|
|
399
398
|
format(
|
|
400
|
-
'
|
|
399
|
+
'Relation "foo" of the model "model" has the type "hasOne", ' +
|
|
401
400
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
402
401
|
'but %s was given.',
|
|
403
402
|
v,
|
|
@@ -426,7 +425,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
426
425
|
};
|
|
427
426
|
const error = v =>
|
|
428
427
|
format(
|
|
429
|
-
'
|
|
428
|
+
'Relation "foo" of the model "model" has the option "polymorphic" ' +
|
|
430
429
|
'with "true" value, so it requires the option "foreignKey" ' +
|
|
431
430
|
'to be a non-empty String, but %s was given.',
|
|
432
431
|
v,
|
|
@@ -455,7 +454,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
455
454
|
};
|
|
456
455
|
const error = v =>
|
|
457
456
|
format(
|
|
458
|
-
'
|
|
457
|
+
'Relation "foo" of the model "model" has the option "polymorphic" ' +
|
|
459
458
|
'with "true" value, so it requires the option "discriminator" ' +
|
|
460
459
|
'to be a non-empty String, but %s was given.',
|
|
461
460
|
v,
|
|
@@ -486,7 +485,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
486
485
|
};
|
|
487
486
|
const error = v =>
|
|
488
487
|
format(
|
|
489
|
-
'
|
|
488
|
+
'Relation "foo" of the model "model" has the type "hasMany", ' +
|
|
490
489
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
491
490
|
'but %s was given.',
|
|
492
491
|
v,
|
|
@@ -513,7 +512,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
513
512
|
};
|
|
514
513
|
const error = v =>
|
|
515
514
|
format(
|
|
516
|
-
'
|
|
515
|
+
'Relation "foo" of the model "model" has the type "hasMany", ' +
|
|
517
516
|
'so it requires the option "foreignKey" to be a non-empty String, ' +
|
|
518
517
|
'but %s was given.',
|
|
519
518
|
v,
|
|
@@ -540,8 +539,8 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
540
539
|
},
|
|
541
540
|
});
|
|
542
541
|
expect(throwable).to.throw(
|
|
543
|
-
'
|
|
544
|
-
'relation, so it
|
|
542
|
+
'Relation "foo" of the model "model" is a non-polymorphic "hasMany" ' +
|
|
543
|
+
'relation, so it must not have the option "discriminator" to be provided.',
|
|
545
544
|
);
|
|
546
545
|
});
|
|
547
546
|
});
|
|
@@ -558,7 +557,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
558
557
|
};
|
|
559
558
|
const error = v =>
|
|
560
559
|
format(
|
|
561
|
-
'
|
|
560
|
+
'Relation "foo" of the model "model" has the type "hasMany", ' +
|
|
562
561
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
563
562
|
'but %s was given.',
|
|
564
563
|
v,
|
|
@@ -585,8 +584,8 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
585
584
|
},
|
|
586
585
|
});
|
|
587
586
|
expect(throwable).to.throw(
|
|
588
|
-
'
|
|
589
|
-
'with a String value, so it
|
|
587
|
+
'Relation "foo" of the model "model" has the option "polymorphic" ' +
|
|
588
|
+
'with a String value, so it must not have the option "foreignKey" ' +
|
|
590
589
|
'to be provided.',
|
|
591
590
|
);
|
|
592
591
|
});
|
|
@@ -602,8 +601,8 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
602
601
|
},
|
|
603
602
|
});
|
|
604
603
|
expect(throwable).to.throw(
|
|
605
|
-
'
|
|
606
|
-
'a String value, so it
|
|
604
|
+
'Relation "foo" of the model "model" has the option "polymorphic" with ' +
|
|
605
|
+
'a String value, so it must not have the option "discriminator" ' +
|
|
607
606
|
'to be provided.',
|
|
608
607
|
);
|
|
609
608
|
});
|
|
@@ -623,7 +622,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
623
622
|
};
|
|
624
623
|
const error = v =>
|
|
625
624
|
format(
|
|
626
|
-
'
|
|
625
|
+
'Relation "foo" of the model "model" has the type "hasMany", ' +
|
|
627
626
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
628
627
|
'but %s was given.',
|
|
629
628
|
v,
|
|
@@ -652,7 +651,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
652
651
|
};
|
|
653
652
|
const error = v =>
|
|
654
653
|
format(
|
|
655
|
-
'
|
|
654
|
+
'Relation "foo" of the model "model" has the option "polymorphic" ' +
|
|
656
655
|
'with "true" value, so it requires the option "foreignKey" ' +
|
|
657
656
|
'to be a non-empty String, but %s was given.',
|
|
658
657
|
v,
|
|
@@ -681,7 +680,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
681
680
|
};
|
|
682
681
|
const error = v =>
|
|
683
682
|
format(
|
|
684
|
-
'
|
|
683
|
+
'Relation "foo" of the model "model" has the option "polymorphic" ' +
|
|
685
684
|
'with "true" value, so it requires the option "discriminator" ' +
|
|
686
685
|
'to be a non-empty String, but %s was given.',
|
|
687
686
|
v,
|
|
@@ -710,7 +709,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
710
709
|
};
|
|
711
710
|
const error = v =>
|
|
712
711
|
format(
|
|
713
|
-
'
|
|
712
|
+
'Relation "foo" of the model "model" has the type "referencesMany", ' +
|
|
714
713
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
715
714
|
'but %s was given.',
|
|
716
715
|
v,
|
|
@@ -737,7 +736,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
737
736
|
};
|
|
738
737
|
const error = v =>
|
|
739
738
|
format(
|
|
740
|
-
'
|
|
739
|
+
'Relation "foo" of the model "model" has the type "referencesMany", ' +
|
|
741
740
|
'so it expects the provided option "foreignKey" to be a String, ' +
|
|
742
741
|
'but %s was given.',
|
|
743
742
|
v,
|
|
@@ -763,8 +762,8 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
763
762
|
},
|
|
764
763
|
});
|
|
765
764
|
expect(throwable).to.throw(
|
|
766
|
-
'
|
|
767
|
-
'so it
|
|
765
|
+
'Relation "foo" of the model "model" has the type "referencesMany", ' +
|
|
766
|
+
'so it must not have the option "discriminator" to be provided.',
|
|
768
767
|
);
|
|
769
768
|
});
|
|
770
769
|
});
|
|
@@ -14,7 +14,7 @@ export class InvalidOperatorValueError extends Error {
|
|
|
14
14
|
constructor(operator, expected, value) {
|
|
15
15
|
super(
|
|
16
16
|
format(
|
|
17
|
-
'Condition of {%s: ...}
|
|
17
|
+
'Condition of {%s: ...} must have %s, but %v was given.',
|
|
18
18
|
operator,
|
|
19
19
|
expected,
|
|
20
20
|
value,
|
|
@@ -5,7 +5,7 @@ describe('InvalidOperatorValueError', function () {
|
|
|
5
5
|
it('sets specific message', function () {
|
|
6
6
|
const error = new InvalidOperatorValueError('exists', 'a boolean', '');
|
|
7
7
|
const message =
|
|
8
|
-
'Condition of {exists: ...}
|
|
8
|
+
'Condition of {exists: ...} must have a boolean, but "" was given.';
|
|
9
9
|
expect(error.message).to.be.eq(message);
|
|
10
10
|
});
|
|
11
11
|
});
|