@e22m4u/js-repository 0.8.6 → 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/build-cjs.js +1 -1
- package/dist/cjs/index.cjs +560 -491
- package/package.json +8 -8
- 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
|
@@ -16,8 +16,7 @@ describe('HasOneResolver', function () {
|
|
|
16
16
|
const R = dbs.getService(HasOneResolver);
|
|
17
17
|
const error = v =>
|
|
18
18
|
format(
|
|
19
|
-
'
|
|
20
|
-
'an Array of Object, but %s was given.',
|
|
19
|
+
'Parameter "entities" must be an Array of Object, but %s was given.',
|
|
21
20
|
v,
|
|
22
21
|
);
|
|
23
22
|
const throwable = v =>
|
|
@@ -44,8 +43,7 @@ describe('HasOneResolver', function () {
|
|
|
44
43
|
const R = dbs.getService(HasOneResolver);
|
|
45
44
|
const error = v =>
|
|
46
45
|
format(
|
|
47
|
-
'
|
|
48
|
-
'an Array of Object, but %s was given.',
|
|
46
|
+
'Parameter "entities" must be an Array of Object, but %s was given.',
|
|
49
47
|
v,
|
|
50
48
|
);
|
|
51
49
|
const throwable = v =>
|
|
@@ -65,8 +63,8 @@ describe('HasOneResolver', function () {
|
|
|
65
63
|
const R = dbs.getService(HasOneResolver);
|
|
66
64
|
const error = v =>
|
|
67
65
|
format(
|
|
68
|
-
'
|
|
69
|
-
'
|
|
66
|
+
'Parameter "sourceName" must be a non-empty String, ' +
|
|
67
|
+
'but %s was given.',
|
|
70
68
|
v,
|
|
71
69
|
);
|
|
72
70
|
const throwable = v =>
|
|
@@ -86,8 +84,8 @@ describe('HasOneResolver', function () {
|
|
|
86
84
|
const R = dbs.getService(HasOneResolver);
|
|
87
85
|
const error = v =>
|
|
88
86
|
format(
|
|
89
|
-
'
|
|
90
|
-
'
|
|
87
|
+
'Parameter "targetName" must be a non-empty String, ' +
|
|
88
|
+
'but %s was given.',
|
|
91
89
|
v,
|
|
92
90
|
);
|
|
93
91
|
const throwable = v =>
|
|
@@ -107,8 +105,8 @@ describe('HasOneResolver', function () {
|
|
|
107
105
|
const R = dbs.getService(HasOneResolver);
|
|
108
106
|
const error = v =>
|
|
109
107
|
format(
|
|
110
|
-
'
|
|
111
|
-
'
|
|
108
|
+
'Parameter "relationName" must be a non-empty String, ' +
|
|
109
|
+
'but %s was given.',
|
|
112
110
|
v,
|
|
113
111
|
);
|
|
114
112
|
const throwable = v =>
|
|
@@ -128,8 +126,8 @@ describe('HasOneResolver', function () {
|
|
|
128
126
|
const R = dbs.getService(HasOneResolver);
|
|
129
127
|
const error = v =>
|
|
130
128
|
format(
|
|
131
|
-
'
|
|
132
|
-
'
|
|
129
|
+
'Parameter "foreignKey" must be a non-empty String, ' +
|
|
130
|
+
'but %s was given.',
|
|
133
131
|
v,
|
|
134
132
|
);
|
|
135
133
|
const throwable = v =>
|
|
@@ -148,11 +146,7 @@ describe('HasOneResolver', function () {
|
|
|
148
146
|
const dbs = new DatabaseSchema();
|
|
149
147
|
const R = dbs.getService(HasOneResolver);
|
|
150
148
|
const error = v =>
|
|
151
|
-
format(
|
|
152
|
-
'The provided parameter "scope" of HasOneResolver.includeTo ' +
|
|
153
|
-
'should be an Object, but %s was given.',
|
|
154
|
-
v,
|
|
155
|
-
);
|
|
149
|
+
format('Parameter "scope" must be an Object, but %s was given.', v);
|
|
156
150
|
const throwable = v =>
|
|
157
151
|
R.includeTo(
|
|
158
152
|
[],
|
|
@@ -179,9 +173,7 @@ describe('HasOneResolver', function () {
|
|
|
179
173
|
'relationName',
|
|
180
174
|
'foreignKey',
|
|
181
175
|
);
|
|
182
|
-
await expect(promise).to.be.rejectedWith(
|
|
183
|
-
'The model "target" is not defined',
|
|
184
|
-
);
|
|
176
|
+
await expect(promise).to.be.rejectedWith('Model "target" is not defined');
|
|
185
177
|
});
|
|
186
178
|
|
|
187
179
|
it('throws an error if a target model does not have datasource', async function () {
|
|
@@ -197,7 +189,7 @@ describe('HasOneResolver', function () {
|
|
|
197
189
|
'foreignKey',
|
|
198
190
|
);
|
|
199
191
|
await expect(promise).to.be.rejectedWith(
|
|
200
|
-
'
|
|
192
|
+
'Model "target" does not have a specified datasource.',
|
|
201
193
|
);
|
|
202
194
|
});
|
|
203
195
|
|
|
@@ -559,8 +551,7 @@ describe('HasOneResolver', function () {
|
|
|
559
551
|
const R = dbs.getService(HasOneResolver);
|
|
560
552
|
const error = v =>
|
|
561
553
|
format(
|
|
562
|
-
'
|
|
563
|
-
'an Array of Object, but %s was given.',
|
|
554
|
+
'Parameter "entities" must be an Array of Object, but %s was given.',
|
|
564
555
|
v,
|
|
565
556
|
);
|
|
566
557
|
const throwable = v =>
|
|
@@ -588,8 +579,7 @@ describe('HasOneResolver', function () {
|
|
|
588
579
|
const R = dbs.getService(HasOneResolver);
|
|
589
580
|
const error = v =>
|
|
590
581
|
format(
|
|
591
|
-
'
|
|
592
|
-
'an Array of Object, but %s was given.',
|
|
582
|
+
'Parameter "entities" must be an Array of Object, but %s was given.',
|
|
593
583
|
v,
|
|
594
584
|
);
|
|
595
585
|
const throwable = v =>
|
|
@@ -616,8 +606,8 @@ describe('HasOneResolver', function () {
|
|
|
616
606
|
const R = dbs.getService(HasOneResolver);
|
|
617
607
|
const error = v =>
|
|
618
608
|
format(
|
|
619
|
-
'
|
|
620
|
-
'
|
|
609
|
+
'Parameter "sourceName" must be a non-empty String, ' +
|
|
610
|
+
'but %s was given.',
|
|
621
611
|
v,
|
|
622
612
|
);
|
|
623
613
|
const throwable = v =>
|
|
@@ -644,8 +634,8 @@ describe('HasOneResolver', function () {
|
|
|
644
634
|
const R = dbs.getService(HasOneResolver);
|
|
645
635
|
const error = v =>
|
|
646
636
|
format(
|
|
647
|
-
'
|
|
648
|
-
'
|
|
637
|
+
'Parameter "targetName" must be a non-empty String, ' +
|
|
638
|
+
'but %s was given.',
|
|
649
639
|
v,
|
|
650
640
|
);
|
|
651
641
|
const throwable = v =>
|
|
@@ -672,8 +662,8 @@ describe('HasOneResolver', function () {
|
|
|
672
662
|
const R = dbs.getService(HasOneResolver);
|
|
673
663
|
const error = v =>
|
|
674
664
|
format(
|
|
675
|
-
'
|
|
676
|
-
'
|
|
665
|
+
'Parameter "relationName" must be a non-empty String, ' +
|
|
666
|
+
'but %s was given.',
|
|
677
667
|
v,
|
|
678
668
|
);
|
|
679
669
|
const throwable = v =>
|
|
@@ -700,8 +690,8 @@ describe('HasOneResolver', function () {
|
|
|
700
690
|
const R = dbs.getService(HasOneResolver);
|
|
701
691
|
const error = v =>
|
|
702
692
|
format(
|
|
703
|
-
'
|
|
704
|
-
'
|
|
693
|
+
'Parameter "foreignKey" must be a non-empty String, ' +
|
|
694
|
+
'but %s was given.',
|
|
705
695
|
v,
|
|
706
696
|
);
|
|
707
697
|
const throwable = v =>
|
|
@@ -728,8 +718,8 @@ describe('HasOneResolver', function () {
|
|
|
728
718
|
const R = dbs.getService(HasOneResolver);
|
|
729
719
|
const error = v =>
|
|
730
720
|
format(
|
|
731
|
-
'
|
|
732
|
-
'
|
|
721
|
+
'Parameter "discriminator" must be a non-empty String, ' +
|
|
722
|
+
'but %s was given.',
|
|
733
723
|
v,
|
|
734
724
|
);
|
|
735
725
|
const throwable = v =>
|
|
@@ -755,11 +745,7 @@ describe('HasOneResolver', function () {
|
|
|
755
745
|
const dbs = new DatabaseSchema();
|
|
756
746
|
const R = dbs.getService(HasOneResolver);
|
|
757
747
|
const error = v =>
|
|
758
|
-
format(
|
|
759
|
-
'The provided parameter "scope" of HasOneResolver.includePolymorphicTo ' +
|
|
760
|
-
'should be an Object, but %s was given.',
|
|
761
|
-
v,
|
|
762
|
-
);
|
|
748
|
+
format('Parameter "scope" must be an Object, but %s was given.', v);
|
|
763
749
|
const throwable = v =>
|
|
764
750
|
R.includePolymorphicTo(
|
|
765
751
|
[],
|
|
@@ -789,9 +775,7 @@ describe('HasOneResolver', function () {
|
|
|
789
775
|
'parentId',
|
|
790
776
|
'parentType',
|
|
791
777
|
);
|
|
792
|
-
await expect(promise).to.be.rejectedWith(
|
|
793
|
-
'The model "target" is not defined',
|
|
794
|
-
);
|
|
778
|
+
await expect(promise).to.be.rejectedWith('Model "target" is not defined');
|
|
795
779
|
});
|
|
796
780
|
|
|
797
781
|
it('throws an error if the given target model does not have a datasource', async function () {
|
|
@@ -809,7 +793,7 @@ describe('HasOneResolver', function () {
|
|
|
809
793
|
'parentType',
|
|
810
794
|
);
|
|
811
795
|
await expect(promise).to.be.rejectedWith(
|
|
812
|
-
'
|
|
796
|
+
'Model "target" does not have a specified datasource.',
|
|
813
797
|
);
|
|
814
798
|
});
|
|
815
799
|
|
|
@@ -1309,8 +1293,7 @@ describe('HasOneResolver', function () {
|
|
|
1309
1293
|
const R = dbs.getService(HasOneResolver);
|
|
1310
1294
|
const error = v =>
|
|
1311
1295
|
format(
|
|
1312
|
-
'
|
|
1313
|
-
'an Array of Object, but %s was given.',
|
|
1296
|
+
'Parameter "entities" must be an Array of Object, but %s was given.',
|
|
1314
1297
|
v,
|
|
1315
1298
|
);
|
|
1316
1299
|
const throwable = v =>
|
|
@@ -1346,8 +1329,7 @@ describe('HasOneResolver', function () {
|
|
|
1346
1329
|
const R = dbs.getService(HasOneResolver);
|
|
1347
1330
|
const error = v =>
|
|
1348
1331
|
format(
|
|
1349
|
-
'
|
|
1350
|
-
'an Array of Object, but %s was given.',
|
|
1332
|
+
'Parameter "entities" must be an Array of Object, but %s was given.',
|
|
1351
1333
|
v,
|
|
1352
1334
|
);
|
|
1353
1335
|
const throwable = v =>
|
|
@@ -1373,8 +1355,8 @@ describe('HasOneResolver', function () {
|
|
|
1373
1355
|
const R = dbs.getService(HasOneResolver);
|
|
1374
1356
|
const error = v =>
|
|
1375
1357
|
format(
|
|
1376
|
-
'
|
|
1377
|
-
'
|
|
1358
|
+
'Parameter "sourceName" must be a non-empty String, ' +
|
|
1359
|
+
'but %s was given.',
|
|
1378
1360
|
v,
|
|
1379
1361
|
);
|
|
1380
1362
|
const throwable = v =>
|
|
@@ -1400,8 +1382,8 @@ describe('HasOneResolver', function () {
|
|
|
1400
1382
|
const R = dbs.getService(HasOneResolver);
|
|
1401
1383
|
const error = v =>
|
|
1402
1384
|
format(
|
|
1403
|
-
'
|
|
1404
|
-
'
|
|
1385
|
+
'Parameter "targetName" must be a non-empty String, ' +
|
|
1386
|
+
'but %s was given.',
|
|
1405
1387
|
v,
|
|
1406
1388
|
);
|
|
1407
1389
|
const throwable = v =>
|
|
@@ -1427,8 +1409,8 @@ describe('HasOneResolver', function () {
|
|
|
1427
1409
|
const R = dbs.getService(HasOneResolver);
|
|
1428
1410
|
const error = v =>
|
|
1429
1411
|
format(
|
|
1430
|
-
'
|
|
1431
|
-
'
|
|
1412
|
+
'Parameter "relationName" must be a non-empty String, ' +
|
|
1413
|
+
'but %s was given.',
|
|
1432
1414
|
v,
|
|
1433
1415
|
);
|
|
1434
1416
|
const throwable = v =>
|
|
@@ -1454,8 +1436,8 @@ describe('HasOneResolver', function () {
|
|
|
1454
1436
|
const R = dbs.getService(HasOneResolver);
|
|
1455
1437
|
const error = v =>
|
|
1456
1438
|
format(
|
|
1457
|
-
'
|
|
1458
|
-
'
|
|
1439
|
+
'Parameter "targetRelationName" must be a non-empty String, ' +
|
|
1440
|
+
'but %s was given.',
|
|
1459
1441
|
v,
|
|
1460
1442
|
);
|
|
1461
1443
|
const throwable = v =>
|
|
@@ -1480,11 +1462,7 @@ describe('HasOneResolver', function () {
|
|
|
1480
1462
|
const dbs = new DatabaseSchema();
|
|
1481
1463
|
const R = dbs.getService(HasOneResolver);
|
|
1482
1464
|
const error = v =>
|
|
1483
|
-
format(
|
|
1484
|
-
'The provided parameter "scope" of HasOneResolver.includePolymorphicByRelationName ' +
|
|
1485
|
-
'should be an Object, but %s was given.',
|
|
1486
|
-
v,
|
|
1487
|
-
);
|
|
1465
|
+
format('Parameter "scope" must be an Object, but %s was given.', v);
|
|
1488
1466
|
const throwable = v =>
|
|
1489
1467
|
R.includePolymorphicByRelationName(
|
|
1490
1468
|
[],
|
|
@@ -1512,9 +1490,7 @@ describe('HasOneResolver', function () {
|
|
|
1512
1490
|
'child',
|
|
1513
1491
|
'parent',
|
|
1514
1492
|
);
|
|
1515
|
-
await expect(promise).to.be.rejectedWith(
|
|
1516
|
-
'The model "target" is not defined',
|
|
1517
|
-
);
|
|
1493
|
+
await expect(promise).to.be.rejectedWith('Model "target" is not defined');
|
|
1518
1494
|
});
|
|
1519
1495
|
|
|
1520
1496
|
it('throws an error if the given target model does not have the given relation name', async function () {
|
|
@@ -1531,7 +1507,7 @@ describe('HasOneResolver', function () {
|
|
|
1531
1507
|
'parent',
|
|
1532
1508
|
);
|
|
1533
1509
|
await expect(promise).to.be.rejectedWith(
|
|
1534
|
-
'
|
|
1510
|
+
'Model "target" does not have relation name "parent".',
|
|
1535
1511
|
);
|
|
1536
1512
|
});
|
|
1537
1513
|
|
|
@@ -1557,7 +1533,7 @@ describe('HasOneResolver', function () {
|
|
|
1557
1533
|
'parent',
|
|
1558
1534
|
);
|
|
1559
1535
|
await expect(promise).to.be.rejectedWith(
|
|
1560
|
-
'
|
|
1536
|
+
'Relation "child" of the model "source" is a polymorphic "hasOne" relation, ' +
|
|
1561
1537
|
'so it requires the target relation "parent" to be a polymorphic "belongsTo", ' +
|
|
1562
1538
|
'but "referencesMany" type was given.',
|
|
1563
1539
|
);
|
|
@@ -1585,7 +1561,7 @@ describe('HasOneResolver', function () {
|
|
|
1585
1561
|
'parent',
|
|
1586
1562
|
);
|
|
1587
1563
|
await expect(promise).to.be.rejectedWith(
|
|
1588
|
-
'
|
|
1564
|
+
'Relation "child" of the model "source" is a polymorphic ' +
|
|
1589
1565
|
'"hasOne" relation, so it requires the target relation "parent" ' +
|
|
1590
1566
|
'to be a polymorphic too.',
|
|
1591
1567
|
);
|
|
@@ -1613,7 +1589,7 @@ describe('HasOneResolver', function () {
|
|
|
1613
1589
|
'parent',
|
|
1614
1590
|
);
|
|
1615
1591
|
await expect(promise).to.be.rejectedWith(
|
|
1616
|
-
'
|
|
1592
|
+
'Model "target" does not have a specified datasource.',
|
|
1617
1593
|
);
|
|
1618
1594
|
});
|
|
1619
1595
|
|
|
@@ -29,43 +29,38 @@ export class ReferencesManyResolver extends Service {
|
|
|
29
29
|
) {
|
|
30
30
|
if (!entities || !Array.isArray(entities)) {
|
|
31
31
|
throw new InvalidArgumentError(
|
|
32
|
-
'
|
|
33
|
-
'an Array of Object, but %v was given.',
|
|
32
|
+
'Parameter "entities" must be an Array of Object, but %v was given.',
|
|
34
33
|
entities,
|
|
35
34
|
);
|
|
36
35
|
}
|
|
37
36
|
if (!sourceName || typeof sourceName !== 'string') {
|
|
38
37
|
throw new InvalidArgumentError(
|
|
39
|
-
'
|
|
40
|
-
'a non-empty String, but %v was given.',
|
|
38
|
+
'Parameter "sourceName" must be a non-empty String, but %v was given.',
|
|
41
39
|
sourceName,
|
|
42
40
|
);
|
|
43
41
|
}
|
|
44
42
|
if (!targetName || typeof targetName !== 'string') {
|
|
45
43
|
throw new InvalidArgumentError(
|
|
46
|
-
'
|
|
47
|
-
'a non-empty String, but %v was given.',
|
|
44
|
+
'Parameter "targetName" must be a non-empty String, but %v was given.',
|
|
48
45
|
targetName,
|
|
49
46
|
);
|
|
50
47
|
}
|
|
51
48
|
if (!relationName || typeof relationName !== 'string') {
|
|
52
49
|
throw new InvalidArgumentError(
|
|
53
|
-
'
|
|
54
|
-
'
|
|
50
|
+
'Parameter "relationName" must be a non-empty String, ' +
|
|
51
|
+
'but %v was given.',
|
|
55
52
|
relationName,
|
|
56
53
|
);
|
|
57
54
|
}
|
|
58
55
|
if (foreignKey && typeof foreignKey !== 'string') {
|
|
59
56
|
throw new InvalidArgumentError(
|
|
60
|
-
'
|
|
61
|
-
'should be a String, but %v was given.',
|
|
57
|
+
'Parameter "foreignKey" must be a String, but %v was given.',
|
|
62
58
|
foreignKey,
|
|
63
59
|
);
|
|
64
60
|
}
|
|
65
61
|
if (scope && (typeof scope !== 'object' || Array.isArray(scope))) {
|
|
66
62
|
throw new InvalidArgumentError(
|
|
67
|
-
'
|
|
68
|
-
'should be an Object, but %v was given.',
|
|
63
|
+
'Parameter "scope" must be an Object, but %v was given.',
|
|
69
64
|
scope,
|
|
70
65
|
);
|
|
71
66
|
}
|
|
@@ -76,8 +71,7 @@ export class ReferencesManyResolver extends Service {
|
|
|
76
71
|
const targetIds = entities.reduce((acc, entity) => {
|
|
77
72
|
if (!entity || typeof entity !== 'object' || Array.isArray(entity)) {
|
|
78
73
|
throw new InvalidArgumentError(
|
|
79
|
-
'
|
|
80
|
-
'an Array of Object, but %v was given.',
|
|
74
|
+
'Parameter "entities" must be an Array of Object, but %v was given.',
|
|
81
75
|
entity,
|
|
82
76
|
);
|
|
83
77
|
}
|
|
@@ -16,8 +16,7 @@ describe('ReferencesManyResolver', function () {
|
|
|
16
16
|
const R = dbs.getService(ReferencesManyResolver);
|
|
17
17
|
const error = v =>
|
|
18
18
|
format(
|
|
19
|
-
'
|
|
20
|
-
'an Array of Object, but %s was given.',
|
|
19
|
+
'Parameter "entities" must be an Array of Object, but %s was given.',
|
|
21
20
|
v,
|
|
22
21
|
);
|
|
23
22
|
const throwable = v =>
|
|
@@ -37,8 +36,7 @@ describe('ReferencesManyResolver', function () {
|
|
|
37
36
|
const R = dbs.getService(ReferencesManyResolver);
|
|
38
37
|
const error = v =>
|
|
39
38
|
format(
|
|
40
|
-
'
|
|
41
|
-
'an Array of Object, but %s was given.',
|
|
39
|
+
'Parameter "entities" must be an Array of Object, but %s was given.',
|
|
42
40
|
v,
|
|
43
41
|
);
|
|
44
42
|
const throwable = v =>
|
|
@@ -58,8 +56,8 @@ describe('ReferencesManyResolver', function () {
|
|
|
58
56
|
const R = dbs.getService(ReferencesManyResolver);
|
|
59
57
|
const error = v =>
|
|
60
58
|
format(
|
|
61
|
-
'
|
|
62
|
-
'
|
|
59
|
+
'Parameter "sourceName" must be a non-empty String, ' +
|
|
60
|
+
'but %s was given.',
|
|
63
61
|
v,
|
|
64
62
|
);
|
|
65
63
|
const throwable = v => R.includeTo([], v, 'targetName', 'relationName');
|
|
@@ -78,8 +76,8 @@ describe('ReferencesManyResolver', function () {
|
|
|
78
76
|
const R = dbs.getService(ReferencesManyResolver);
|
|
79
77
|
const error = v =>
|
|
80
78
|
format(
|
|
81
|
-
'
|
|
82
|
-
'
|
|
79
|
+
'Parameter "targetName" must be a non-empty String, ' +
|
|
80
|
+
'but %s was given.',
|
|
83
81
|
v,
|
|
84
82
|
);
|
|
85
83
|
const throwable = v => R.includeTo([], 'sourceName', v, 'relationName');
|
|
@@ -98,8 +96,8 @@ describe('ReferencesManyResolver', function () {
|
|
|
98
96
|
const R = dbs.getService(ReferencesManyResolver);
|
|
99
97
|
const error = v =>
|
|
100
98
|
format(
|
|
101
|
-
'
|
|
102
|
-
'
|
|
99
|
+
'Parameter "relationName" must be a non-empty String, ' +
|
|
100
|
+
'but %s was given.',
|
|
103
101
|
v,
|
|
104
102
|
);
|
|
105
103
|
const throwable = v => R.includeTo([], 'sourceName', 'targetName', v);
|
|
@@ -117,11 +115,7 @@ describe('ReferencesManyResolver', function () {
|
|
|
117
115
|
const dbs = new DatabaseSchema();
|
|
118
116
|
const R = dbs.getService(ReferencesManyResolver);
|
|
119
117
|
const error = v =>
|
|
120
|
-
format(
|
|
121
|
-
'The provided parameter "foreignKey" of ReferencesManyResolver.includeTo ' +
|
|
122
|
-
'should be a String, but %s was given.',
|
|
123
|
-
v,
|
|
124
|
-
);
|
|
118
|
+
format('Parameter "foreignKey" must be a String, but %s was given.', v);
|
|
125
119
|
const throwable = v =>
|
|
126
120
|
R.includeTo([], 'sourceName', 'targetName', 'relationName', v);
|
|
127
121
|
await expect(throwable(10)).to.be.rejectedWith(error('10'));
|
|
@@ -134,11 +128,7 @@ describe('ReferencesManyResolver', function () {
|
|
|
134
128
|
const dbs = new DatabaseSchema();
|
|
135
129
|
const R = dbs.getService(ReferencesManyResolver);
|
|
136
130
|
const error = v =>
|
|
137
|
-
format(
|
|
138
|
-
'The provided parameter "scope" of ReferencesManyResolver.includeTo ' +
|
|
139
|
-
'should be an Object, but %s was given.',
|
|
140
|
-
v,
|
|
141
|
-
);
|
|
131
|
+
format('Parameter "scope" must be an Object, but %s was given.', v);
|
|
142
132
|
const throwable = v =>
|
|
143
133
|
R.includeTo(
|
|
144
134
|
[],
|
|
@@ -159,9 +149,7 @@ describe('ReferencesManyResolver', function () {
|
|
|
159
149
|
dbs.defineModel({name: 'source'});
|
|
160
150
|
const R = dbs.getService(ReferencesManyResolver);
|
|
161
151
|
const promise = R.includeTo([], 'source', 'target', 'relation');
|
|
162
|
-
await expect(promise).to.be.rejectedWith(
|
|
163
|
-
'The model "target" is not defined',
|
|
164
|
-
);
|
|
152
|
+
await expect(promise).to.be.rejectedWith('Model "target" is not defined');
|
|
165
153
|
});
|
|
166
154
|
|
|
167
155
|
it('throws an error if the given target model does not have a datasource', async function () {
|
|
@@ -170,7 +158,7 @@ describe('ReferencesManyResolver', function () {
|
|
|
170
158
|
const R = dbs.getService(ReferencesManyResolver);
|
|
171
159
|
const promise = R.includeTo([], 'source', 'target', 'relation');
|
|
172
160
|
await expect(promise).to.be.rejectedWith(
|
|
173
|
-
'
|
|
161
|
+
'Model "target" does not have a specified datasource.',
|
|
174
162
|
);
|
|
175
163
|
});
|
|
176
164
|
|
|
@@ -34,8 +34,8 @@ export class RepositoryRegistry extends Service {
|
|
|
34
34
|
!(ctor.prototype instanceof Repository)
|
|
35
35
|
) {
|
|
36
36
|
throw new InvalidArgumentError(
|
|
37
|
-
'
|
|
38
|
-
'
|
|
37
|
+
'Parameter "ctor" must inherit from Repository class, ' +
|
|
38
|
+
'but %v was given.',
|
|
39
39
|
ctor,
|
|
40
40
|
);
|
|
41
41
|
}
|
|
@@ -53,7 +53,7 @@ export class Repository extends Service {
|
|
|
53
53
|
const datasourceName = modelDef.datasource;
|
|
54
54
|
if (!datasourceName) {
|
|
55
55
|
throw new InvalidArgumentError(
|
|
56
|
-
'
|
|
56
|
+
'Model %v does not have a specified datasource.',
|
|
57
57
|
modelName,
|
|
58
58
|
);
|
|
59
59
|
}
|
|
@@ -8,9 +8,9 @@ import {InvalidArgumentError} from '../errors/index.js';
|
|
|
8
8
|
* @returns {object}
|
|
9
9
|
*/
|
|
10
10
|
export function excludeObjectKeys(obj, keys) {
|
|
11
|
-
if (typeof obj !== 'object' ||
|
|
11
|
+
if (!obj || typeof obj !== 'object' || Array.isArray(obj)) {
|
|
12
12
|
throw new InvalidArgumentError(
|
|
13
|
-
'
|
|
13
|
+
'Parameter "obj" must be an Object, but %v was given.',
|
|
14
14
|
obj,
|
|
15
15
|
);
|
|
16
16
|
}
|
|
@@ -36,8 +36,8 @@ describe('excludeObjectKeys', function () {
|
|
|
36
36
|
|
|
37
37
|
it('throws an error for a non-object values', function () {
|
|
38
38
|
const throwable = v => () => excludeObjectKeys(v, 'key');
|
|
39
|
-
const error =
|
|
40
|
-
format('
|
|
39
|
+
const error = s =>
|
|
40
|
+
format('Parameter "obj" must be an Object, but %s was given.', s);
|
|
41
41
|
expect(throwable('str')).to.throw(error('"str"'));
|
|
42
42
|
expect(throwable(10)).to.throw(error('10'));
|
|
43
43
|
expect(throwable(true)).to.throw(error('true'));
|
|
@@ -14,8 +14,7 @@ import {InvalidArgumentError} from '../errors/index.js';
|
|
|
14
14
|
export function likeToRegexp(pattern, isCaseInsensitive = false) {
|
|
15
15
|
if (typeof pattern !== 'string') {
|
|
16
16
|
throw new InvalidArgumentError(
|
|
17
|
-
'
|
|
18
|
-
'should be a String, but %v was given.',
|
|
17
|
+
'Parameter "pattern" must be a String, but %v was given.',
|
|
19
18
|
pattern,
|
|
20
19
|
);
|
|
21
20
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {expect} from 'chai';
|
|
2
|
+
import {format} from '@e22m4u/js-format';
|
|
2
3
|
import {likeToRegexp} from './like-to-regexp.js';
|
|
3
4
|
|
|
4
5
|
describe('likeToRegexp', function () {
|
|
5
6
|
it('throws an error if the pattern is not a string', function () {
|
|
6
|
-
const error =
|
|
7
|
-
'
|
|
8
|
-
`should be a String, but ${v} was given.`;
|
|
7
|
+
const error = s =>
|
|
8
|
+
format('Parameter "pattern" must be a String, but %s was given.', s);
|
|
9
9
|
expect(() => likeToRegexp(123)).to.throw(error('123'));
|
|
10
10
|
expect(() => likeToRegexp(null)).to.throw(error('null'));
|
|
11
11
|
expect(() => likeToRegexp({})).to.throw(error('Object'));
|
|
@@ -39,13 +39,13 @@ describe('likeToRegexp', function () {
|
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
describe('case sensitivity', function () {
|
|
42
|
-
it('
|
|
42
|
+
it('must be case-sensitive by default', function () {
|
|
43
43
|
const re = likeToRegexp('Hello%');
|
|
44
44
|
expect(re.test('Hello World')).to.be.true;
|
|
45
45
|
expect(re.test('hello World')).to.be.false;
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
it('
|
|
48
|
+
it('must be case-insensitive when specified', function () {
|
|
49
49
|
const re = likeToRegexp('Hello%', true);
|
|
50
50
|
expect(re.test('Hello World')).to.be.true;
|
|
51
51
|
expect(re.test('hello World')).to.be.true;
|
|
@@ -9,7 +9,7 @@ import {InvalidArgumentError} from '../errors/index.js';
|
|
|
9
9
|
export function modelNameToModelKey(modelName) {
|
|
10
10
|
if (!modelName || typeof modelName !== 'string' || /\s/.test(modelName)) {
|
|
11
11
|
throw new InvalidArgumentError(
|
|
12
|
-
'
|
|
12
|
+
'Model name must be a non-empty String ' +
|
|
13
13
|
'without spaces, but %v was given.',
|
|
14
14
|
modelName,
|
|
15
15
|
);
|
|
@@ -39,7 +39,7 @@ describe('modelNameToModelKey', function () {
|
|
|
39
39
|
it('should throw an error for an empty string', function () {
|
|
40
40
|
const throwable = () => modelNameToModelKey('');
|
|
41
41
|
expect(throwable).to.throw(
|
|
42
|
-
'
|
|
42
|
+
'Model name must be a non-empty String ' +
|
|
43
43
|
'without spaces, but "" was given.',
|
|
44
44
|
);
|
|
45
45
|
});
|
|
@@ -47,7 +47,7 @@ describe('modelNameToModelKey', function () {
|
|
|
47
47
|
it('should throw an error for a string with spaces', function () {
|
|
48
48
|
const throwable = () => modelNameToModelKey('user profile');
|
|
49
49
|
expect(throwable).to.throw(
|
|
50
|
-
'
|
|
50
|
+
'Model name must be a non-empty String ' +
|
|
51
51
|
'without spaces, but "user profile" was given.',
|
|
52
52
|
);
|
|
53
53
|
});
|
|
@@ -55,7 +55,7 @@ describe('modelNameToModelKey', function () {
|
|
|
55
55
|
it('should throw an error for null', function () {
|
|
56
56
|
const throwable = () => modelNameToModelKey(null);
|
|
57
57
|
expect(throwable).to.throw(
|
|
58
|
-
'
|
|
58
|
+
'Model name must be a non-empty String ' +
|
|
59
59
|
'without spaces, but null was given.',
|
|
60
60
|
);
|
|
61
61
|
});
|
|
@@ -63,7 +63,7 @@ describe('modelNameToModelKey', function () {
|
|
|
63
63
|
it('should throw an error for undefined', function () {
|
|
64
64
|
const throwable = () => modelNameToModelKey(undefined);
|
|
65
65
|
expect(throwable).to.throw(
|
|
66
|
-
'
|
|
66
|
+
'Model name must be a non-empty String ' +
|
|
67
67
|
'without spaces, but undefined was given.',
|
|
68
68
|
);
|
|
69
69
|
});
|
|
@@ -71,7 +71,7 @@ describe('modelNameToModelKey', function () {
|
|
|
71
71
|
it('should throw an error for a number', function () {
|
|
72
72
|
const throwable = () => modelNameToModelKey(123);
|
|
73
73
|
expect(throwable).to.throw(
|
|
74
|
-
'
|
|
74
|
+
'Model name must be a non-empty String ' +
|
|
75
75
|
'without spaces, but 123 was given.',
|
|
76
76
|
);
|
|
77
77
|
});
|
|
@@ -79,7 +79,7 @@ describe('modelNameToModelKey', function () {
|
|
|
79
79
|
it('should throw an error for an object', function () {
|
|
80
80
|
const throwable = () => modelNameToModelKey({name: 'test'});
|
|
81
81
|
expect(throwable).to.throw(
|
|
82
|
-
'
|
|
82
|
+
'Model name must be a non-empty String ' +
|
|
83
83
|
'without spaces, but Object was given.',
|
|
84
84
|
);
|
|
85
85
|
});
|
|
@@ -87,7 +87,7 @@ describe('modelNameToModelKey', function () {
|
|
|
87
87
|
it('should throw an error for an array', function () {
|
|
88
88
|
const throwable = () => modelNameToModelKey(['test']);
|
|
89
89
|
expect(throwable).to.throw(
|
|
90
|
-
'
|
|
90
|
+
'Model name must be a non-empty String ' +
|
|
91
91
|
'without spaces, but Array was given.',
|
|
92
92
|
);
|
|
93
93
|
});
|