@e22m4u/js-repository 0.2.6 → 0.3.0
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/README.md +79 -80
- package/dist/cjs/index.cjs +2023 -2093
- package/eslint.config.js +1 -1
- package/package.json +15 -12
- package/src/adapter/adapter-registry.spec.js +7 -7
- package/src/adapter/adapter.spec.js +11 -11
- package/src/adapter/builtin/memory-adapter.spec.js +537 -537
- package/src/adapter/decorator/data-sanitizing-decorator.spec.js +5 -5
- package/src/adapter/decorator/data-transformation-decorator.spec.js +5 -5
- package/src/adapter/decorator/data-validation-decorator.spec.js +5 -5
- package/src/adapter/decorator/default-values-decorator.spec.js +5 -5
- package/src/adapter/decorator/fields-filtering-decorator.spec.js +5 -5
- package/src/adapter/decorator/inclusion-decorator.spec.js +5 -5
- package/src/adapter/decorator/property-uniqueness-decorator.spec.js +5 -5
- package/src/{schema.d.ts → database-schema.d.ts} +2 -2
- package/src/{schema.js → database-schema.js} +2 -2
- package/src/database-schema.spec.ts +86 -0
- package/src/definition/model/model-data-transformer.js +3 -3
- package/src/definition/model/model-data-transformer.spec.js +93 -93
- package/src/definition/model/model-data-validator.js +2 -2
- package/src/definition/model/model-data-validator.spec.js +517 -531
- package/src/definition/model/model-definition-utils.js +3 -3
- package/src/definition/model/model-definition-utils.spec.js +345 -343
- package/src/definition/model/properties/index.d.ts +0 -1
- package/src/definition/model/properties/index.js +0 -1
- package/src/definition/model/properties/property-transformer/property-transformer-registry.spec.js +36 -36
- package/src/definition/model/properties/property-uniqueness-validator.js +3 -3
- package/src/definition/model/properties/property-uniqueness-validator.spec.js +417 -384
- package/src/definition/model/properties/property-validator/property-validator-registry.spec.js +36 -36
- package/src/filter/fields-clause-tool.spec.js +4 -4
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -1
- package/src/relations/belongs-to-resolver.spec.js +166 -166
- package/src/relations/has-many-resolver.spec.js +281 -281
- package/src/relations/has-one-resolver.spec.js +281 -281
- package/src/relations/references-many-resolver.spec.js +92 -92
- package/src/repository/repository-registry.spec.js +10 -10
- package/src/repository/repository.spec.js +73 -73
- package/src/utils/is-promise.spec.js +1 -2
- package/src/utils/transform-promise.spec.js +0 -1
- package/src/definition/model/properties/empty-values-definer.d.ts +0 -23
- package/src/definition/model/properties/empty-values-definer.js +0 -66
- package/src/definition/model/properties/empty-values-definer.spec.js +0 -96
- package/src/schema.spec.ts +0 -86
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {expect} from 'chai';
|
|
2
|
-
import {Schema} from '../schema.js';
|
|
3
2
|
import {format} from '@e22m4u/js-format';
|
|
4
3
|
import {DataType} from '../definition/index.js';
|
|
5
4
|
import {RelationType} from '../definition/index.js';
|
|
5
|
+
import {DatabaseSchema} from '../database-schema.js';
|
|
6
6
|
import {HasManyResolver} from './has-many-resolver.js';
|
|
7
7
|
import {DEFAULT_PRIMARY_KEY_PROPERTY_NAME as DEF_PK} from '../definition/index.js';
|
|
8
8
|
|
|
9
9
|
describe('HasManyResolver', function () {
|
|
10
10
|
describe('includeTo', function () {
|
|
11
11
|
it('requires the "entities" parameter to be an array', async function () {
|
|
12
|
-
const
|
|
13
|
-
const R =
|
|
12
|
+
const dbs = new DatabaseSchema();
|
|
13
|
+
const R = dbs.getService(HasManyResolver);
|
|
14
14
|
const error = v =>
|
|
15
15
|
format(
|
|
16
16
|
'The parameter "entities" of HasManyResolver.includeTo requires ' +
|
|
@@ -36,9 +36,9 @@ describe('HasManyResolver', function () {
|
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
it('requires elements of the "entities" parameter to be an Object', async function () {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
const R =
|
|
39
|
+
const dbs = new DatabaseSchema();
|
|
40
|
+
dbs.defineModel({name: 'source'});
|
|
41
|
+
const R = dbs.getService(HasManyResolver);
|
|
42
42
|
const error = v =>
|
|
43
43
|
format(
|
|
44
44
|
'The parameter "entities" of HasManyResolver.includeTo requires ' +
|
|
@@ -58,8 +58,8 @@ describe('HasManyResolver', function () {
|
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
it('requires the "sourceName" parameter to be a non-empty string', async function () {
|
|
61
|
-
const
|
|
62
|
-
const R =
|
|
61
|
+
const dbs = new DatabaseSchema();
|
|
62
|
+
const R = dbs.getService(HasManyResolver);
|
|
63
63
|
const error = v =>
|
|
64
64
|
format(
|
|
65
65
|
'The parameter "sourceName" of HasManyResolver.includeTo requires ' +
|
|
@@ -79,8 +79,8 @@ describe('HasManyResolver', function () {
|
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
it('requires the "targetName" parameter to be a non-empty string', async function () {
|
|
82
|
-
const
|
|
83
|
-
const R =
|
|
82
|
+
const dbs = new DatabaseSchema();
|
|
83
|
+
const R = dbs.getService(HasManyResolver);
|
|
84
84
|
const error = v =>
|
|
85
85
|
format(
|
|
86
86
|
'The parameter "targetName" of HasManyResolver.includeTo requires ' +
|
|
@@ -100,8 +100,8 @@ describe('HasManyResolver', function () {
|
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
it('requires the "relationName" parameter to be a non-empty string', async function () {
|
|
103
|
-
const
|
|
104
|
-
const R =
|
|
103
|
+
const dbs = new DatabaseSchema();
|
|
104
|
+
const R = dbs.getService(HasManyResolver);
|
|
105
105
|
const error = v =>
|
|
106
106
|
format(
|
|
107
107
|
'The parameter "relationName" of HasManyResolver.includeTo requires ' +
|
|
@@ -121,8 +121,8 @@ describe('HasManyResolver', function () {
|
|
|
121
121
|
});
|
|
122
122
|
|
|
123
123
|
it('requires the "foreignKey" parameter to be a non-empty string', async function () {
|
|
124
|
-
const
|
|
125
|
-
const R =
|
|
124
|
+
const dbs = new DatabaseSchema();
|
|
125
|
+
const R = dbs.getService(HasManyResolver);
|
|
126
126
|
const error = v =>
|
|
127
127
|
format(
|
|
128
128
|
'The parameter "foreignKey" of HasManyResolver.includeTo requires ' +
|
|
@@ -142,8 +142,8 @@ describe('HasManyResolver', function () {
|
|
|
142
142
|
});
|
|
143
143
|
|
|
144
144
|
it('requires the provided parameter "scope" to be an object', async function () {
|
|
145
|
-
const
|
|
146
|
-
const R =
|
|
145
|
+
const dbs = new DatabaseSchema();
|
|
146
|
+
const R = dbs.getService(HasManyResolver);
|
|
147
147
|
const error = v =>
|
|
148
148
|
format(
|
|
149
149
|
'The provided parameter "scope" of HasManyResolver.includeTo ' +
|
|
@@ -166,9 +166,9 @@ describe('HasManyResolver', function () {
|
|
|
166
166
|
});
|
|
167
167
|
|
|
168
168
|
it('throws an error if a target model is not found', async function () {
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
const R =
|
|
169
|
+
const dbs = new DatabaseSchema();
|
|
170
|
+
dbs.defineModel({name: 'source'});
|
|
171
|
+
const R = dbs.getService(HasManyResolver);
|
|
172
172
|
const promise = R.includeTo(
|
|
173
173
|
[],
|
|
174
174
|
'source',
|
|
@@ -182,10 +182,10 @@ describe('HasManyResolver', function () {
|
|
|
182
182
|
});
|
|
183
183
|
|
|
184
184
|
it('throws an error if a target model does not have datasource', async function () {
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const R =
|
|
185
|
+
const dbs = new DatabaseSchema();
|
|
186
|
+
dbs.defineModel({name: 'source'});
|
|
187
|
+
dbs.defineModel({name: 'target'});
|
|
188
|
+
const R = dbs.getService(HasManyResolver);
|
|
189
189
|
const promise = R.includeTo(
|
|
190
190
|
[],
|
|
191
191
|
'source',
|
|
@@ -199,13 +199,13 @@ describe('HasManyResolver', function () {
|
|
|
199
199
|
});
|
|
200
200
|
|
|
201
201
|
it('does not throw an error if a relation target is not exist', async function () {
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
const sourceRel =
|
|
202
|
+
const dbs = new DatabaseSchema();
|
|
203
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
204
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
205
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
206
|
+
const sourceRel = dbs.getRepository('source');
|
|
207
207
|
const source = await sourceRel.create({});
|
|
208
|
-
const R =
|
|
208
|
+
const R = dbs.getService(HasManyResolver);
|
|
209
209
|
await R.includeTo([source], 'source', 'target', 'children', 'parentId');
|
|
210
210
|
expect(source).to.be.eql({
|
|
211
211
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -214,12 +214,12 @@ describe('HasManyResolver', function () {
|
|
|
214
214
|
});
|
|
215
215
|
|
|
216
216
|
it('includes if a primary key is not defined in the source model', async function () {
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
const sourceRep =
|
|
222
|
-
const targetRep =
|
|
217
|
+
const dbs = new DatabaseSchema();
|
|
218
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
219
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
220
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
221
|
+
const sourceRep = dbs.getRepository('source');
|
|
222
|
+
const targetRep = dbs.getRepository('target');
|
|
223
223
|
const source = await sourceRep.create({});
|
|
224
224
|
expect(source).to.be.eql({[DEF_PK]: source[DEF_PK]});
|
|
225
225
|
const target1 = await targetRep.create({parentId: source[DEF_PK]});
|
|
@@ -237,7 +237,7 @@ describe('HasManyResolver', function () {
|
|
|
237
237
|
[DEF_PK]: target3[DEF_PK],
|
|
238
238
|
parentId: -1,
|
|
239
239
|
});
|
|
240
|
-
const R =
|
|
240
|
+
const R = dbs.getService(HasManyResolver);
|
|
241
241
|
await R.includeTo([source], 'source', 'target', 'children', 'parentId');
|
|
242
242
|
expect(source).to.be.eql({
|
|
243
243
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -255,9 +255,9 @@ describe('HasManyResolver', function () {
|
|
|
255
255
|
});
|
|
256
256
|
|
|
257
257
|
it('includes if the source model has a custom primary key', async function () {
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
258
|
+
const dbs = new DatabaseSchema();
|
|
259
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
260
|
+
dbs.defineModel({
|
|
261
261
|
name: 'source',
|
|
262
262
|
datasource: 'datasource',
|
|
263
263
|
properties: {
|
|
@@ -267,9 +267,9 @@ describe('HasManyResolver', function () {
|
|
|
267
267
|
},
|
|
268
268
|
},
|
|
269
269
|
});
|
|
270
|
-
|
|
271
|
-
const sourceRep =
|
|
272
|
-
const targetRep =
|
|
270
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
271
|
+
const sourceRep = dbs.getRepository('source');
|
|
272
|
+
const targetRep = dbs.getRepository('target');
|
|
273
273
|
const source = await sourceRep.create({});
|
|
274
274
|
expect(source).to.be.eql({myId: source.myId});
|
|
275
275
|
const target1 = await targetRep.create({parentId: source.myId});
|
|
@@ -287,7 +287,7 @@ describe('HasManyResolver', function () {
|
|
|
287
287
|
[DEF_PK]: target3[DEF_PK],
|
|
288
288
|
parentId: -1,
|
|
289
289
|
});
|
|
290
|
-
const R =
|
|
290
|
+
const R = dbs.getService(HasManyResolver);
|
|
291
291
|
await R.includeTo([source], 'source', 'target', 'children', 'parentId');
|
|
292
292
|
expect(source).to.be.eql({
|
|
293
293
|
myId: source.myId,
|
|
@@ -305,10 +305,10 @@ describe('HasManyResolver', function () {
|
|
|
305
305
|
});
|
|
306
306
|
|
|
307
307
|
it('includes if the target model has a custom primary key', async function () {
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
308
|
+
const dbs = new DatabaseSchema();
|
|
309
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
310
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
311
|
+
dbs.defineModel({
|
|
312
312
|
name: 'target',
|
|
313
313
|
datasource: 'datasource',
|
|
314
314
|
properties: {
|
|
@@ -318,8 +318,8 @@ describe('HasManyResolver', function () {
|
|
|
318
318
|
},
|
|
319
319
|
},
|
|
320
320
|
});
|
|
321
|
-
const sourceRep =
|
|
322
|
-
const targetRep =
|
|
321
|
+
const sourceRep = dbs.getRepository('source');
|
|
322
|
+
const targetRep = dbs.getRepository('target');
|
|
323
323
|
const source = await sourceRep.create({});
|
|
324
324
|
expect(source).to.be.eql({[DEF_PK]: source[DEF_PK]});
|
|
325
325
|
const target1 = await targetRep.create({parentId: source[DEF_PK]});
|
|
@@ -337,7 +337,7 @@ describe('HasManyResolver', function () {
|
|
|
337
337
|
myId: target3.myId,
|
|
338
338
|
parentId: -1,
|
|
339
339
|
});
|
|
340
|
-
const R =
|
|
340
|
+
const R = dbs.getService(HasManyResolver);
|
|
341
341
|
await R.includeTo([source], 'source', 'target', 'children', 'parentId');
|
|
342
342
|
expect(source).to.be.eql({
|
|
343
343
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -355,12 +355,12 @@ describe('HasManyResolver', function () {
|
|
|
355
355
|
});
|
|
356
356
|
|
|
357
357
|
it('uses a where clause of the given scope to filter the relation target', async function () {
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
const sourceRep =
|
|
363
|
-
const targetRep =
|
|
358
|
+
const dbs = new DatabaseSchema();
|
|
359
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
360
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
361
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
362
|
+
const sourceRep = dbs.getRepository('source');
|
|
363
|
+
const targetRep = dbs.getRepository('target');
|
|
364
364
|
const source = await sourceRep.create({});
|
|
365
365
|
expect(source).to.be.eql({[DEF_PK]: source[DEF_PK]});
|
|
366
366
|
const target1 = await targetRep.create({
|
|
@@ -390,7 +390,7 @@ describe('HasManyResolver', function () {
|
|
|
390
390
|
featured: true,
|
|
391
391
|
parentId: source[DEF_PK],
|
|
392
392
|
});
|
|
393
|
-
const R =
|
|
393
|
+
const R = dbs.getService(HasManyResolver);
|
|
394
394
|
await R.includeTo([source], 'source', 'target', 'children', 'parentId', {
|
|
395
395
|
where: {featured: false},
|
|
396
396
|
});
|
|
@@ -425,12 +425,12 @@ describe('HasManyResolver', function () {
|
|
|
425
425
|
});
|
|
426
426
|
|
|
427
427
|
it('uses a fields clause of the given scope to filter the relation target', async function () {
|
|
428
|
-
const
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
const sourceRep =
|
|
433
|
-
const targetRep =
|
|
428
|
+
const dbs = new DatabaseSchema();
|
|
429
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
430
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
431
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
432
|
+
const sourceRep = dbs.getRepository('source');
|
|
433
|
+
const targetRep = dbs.getRepository('target');
|
|
434
434
|
const source = await sourceRep.create({});
|
|
435
435
|
expect(source).to.be.eql({
|
|
436
436
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -468,7 +468,7 @@ describe('HasManyResolver', function () {
|
|
|
468
468
|
bar: 'barVal3',
|
|
469
469
|
parentId: -1,
|
|
470
470
|
});
|
|
471
|
-
const R =
|
|
471
|
+
const R = dbs.getService(HasManyResolver);
|
|
472
472
|
await R.includeTo([source], 'source', 'target', 'children', 'parentId', {
|
|
473
473
|
fields: [DEF_PK, 'bar'],
|
|
474
474
|
});
|
|
@@ -488,12 +488,12 @@ describe('HasManyResolver', function () {
|
|
|
488
488
|
});
|
|
489
489
|
|
|
490
490
|
it('uses an include clause of the given scope to resolve target relations', async function () {
|
|
491
|
-
const
|
|
492
|
-
|
|
491
|
+
const dbs = new DatabaseSchema();
|
|
492
|
+
dbs.defineDatasource({
|
|
493
493
|
name: 'datasource',
|
|
494
494
|
adapter: 'memory',
|
|
495
495
|
});
|
|
496
|
-
|
|
496
|
+
dbs.defineModel({
|
|
497
497
|
name: 'modelA',
|
|
498
498
|
datasource: 'datasource',
|
|
499
499
|
properties: {
|
|
@@ -514,7 +514,7 @@ describe('HasManyResolver', function () {
|
|
|
514
514
|
},
|
|
515
515
|
},
|
|
516
516
|
});
|
|
517
|
-
|
|
517
|
+
dbs.defineModel({
|
|
518
518
|
name: 'modelB',
|
|
519
519
|
datasource: 'datasource',
|
|
520
520
|
properties: {
|
|
@@ -535,7 +535,7 @@ describe('HasManyResolver', function () {
|
|
|
535
535
|
},
|
|
536
536
|
},
|
|
537
537
|
});
|
|
538
|
-
|
|
538
|
+
dbs.defineModel({
|
|
539
539
|
name: 'modelC',
|
|
540
540
|
datasource: 'datasource',
|
|
541
541
|
properties: {
|
|
@@ -549,9 +549,9 @@ describe('HasManyResolver', function () {
|
|
|
549
549
|
},
|
|
550
550
|
},
|
|
551
551
|
});
|
|
552
|
-
const aRep =
|
|
553
|
-
const bRep =
|
|
554
|
-
const cRep =
|
|
552
|
+
const aRep = dbs.getRepository('modelA');
|
|
553
|
+
const bRep = dbs.getRepository('modelB');
|
|
554
|
+
const cRep = dbs.getRepository('modelC');
|
|
555
555
|
const a = await aRep.create({});
|
|
556
556
|
const b1 = await bRep.create({parentId: a.id});
|
|
557
557
|
const b2 = await bRep.create({parentId: a.id});
|
|
@@ -599,7 +599,7 @@ describe('HasManyResolver', function () {
|
|
|
599
599
|
source: 'modelC',
|
|
600
600
|
parentId: b2.id,
|
|
601
601
|
});
|
|
602
|
-
const R =
|
|
602
|
+
const R = dbs.getService(HasManyResolver);
|
|
603
603
|
await R.includeTo([a], 'modelA', 'modelB', 'children', 'parentId', {
|
|
604
604
|
include: 'children',
|
|
605
605
|
});
|
|
@@ -646,12 +646,12 @@ describe('HasManyResolver', function () {
|
|
|
646
646
|
});
|
|
647
647
|
|
|
648
648
|
it('does not break the "and" operator of the given "where" clause', async function () {
|
|
649
|
-
const
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
const sourceRep =
|
|
654
|
-
const targetRep =
|
|
649
|
+
const dbs = new DatabaseSchema();
|
|
650
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
651
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
652
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
653
|
+
const sourceRep = dbs.getRepository('source');
|
|
654
|
+
const targetRep = dbs.getRepository('target');
|
|
655
655
|
const source = await sourceRep.create({});
|
|
656
656
|
expect(source).to.be.eql({
|
|
657
657
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -683,7 +683,7 @@ describe('HasManyResolver', function () {
|
|
|
683
683
|
featured: true,
|
|
684
684
|
parentId: source[DEF_PK],
|
|
685
685
|
});
|
|
686
|
-
const R =
|
|
686
|
+
const R = dbs.getService(HasManyResolver);
|
|
687
687
|
await R.includeTo([source], 'source', 'target', 'children', 'parentId', {
|
|
688
688
|
where: {and: [{featured: false}]},
|
|
689
689
|
});
|
|
@@ -721,8 +721,8 @@ describe('HasManyResolver', function () {
|
|
|
721
721
|
|
|
722
722
|
describe('includePolymorphicTo', function () {
|
|
723
723
|
it('requires the "entities" parameter to be an array', async function () {
|
|
724
|
-
const
|
|
725
|
-
const R =
|
|
724
|
+
const dbs = new DatabaseSchema();
|
|
725
|
+
const R = dbs.getService(HasManyResolver);
|
|
726
726
|
const error = v =>
|
|
727
727
|
format(
|
|
728
728
|
'The parameter "entities" of HasManyResolver.includePolymorphicTo requires ' +
|
|
@@ -749,9 +749,9 @@ describe('HasManyResolver', function () {
|
|
|
749
749
|
});
|
|
750
750
|
|
|
751
751
|
it('requires elements of the "entities" parameter to be an Object', async function () {
|
|
752
|
-
const
|
|
753
|
-
|
|
754
|
-
const R =
|
|
752
|
+
const dbs = new DatabaseSchema();
|
|
753
|
+
dbs.defineModel({name: 'source'});
|
|
754
|
+
const R = dbs.getService(HasManyResolver);
|
|
755
755
|
const error = v =>
|
|
756
756
|
format(
|
|
757
757
|
'The parameter "entities" of HasManyResolver.includePolymorphicTo requires ' +
|
|
@@ -778,8 +778,8 @@ describe('HasManyResolver', function () {
|
|
|
778
778
|
});
|
|
779
779
|
|
|
780
780
|
it('requires the "sourceName" parameter to be a non-empty string', async function () {
|
|
781
|
-
const
|
|
782
|
-
const R =
|
|
781
|
+
const dbs = new DatabaseSchema();
|
|
782
|
+
const R = dbs.getService(HasManyResolver);
|
|
783
783
|
const error = v =>
|
|
784
784
|
format(
|
|
785
785
|
'The parameter "sourceName" of HasManyResolver.includePolymorphicTo requires ' +
|
|
@@ -806,8 +806,8 @@ describe('HasManyResolver', function () {
|
|
|
806
806
|
});
|
|
807
807
|
|
|
808
808
|
it('requires the "targetName" parameter to be a non-empty string', async function () {
|
|
809
|
-
const
|
|
810
|
-
const R =
|
|
809
|
+
const dbs = new DatabaseSchema();
|
|
810
|
+
const R = dbs.getService(HasManyResolver);
|
|
811
811
|
const error = v =>
|
|
812
812
|
format(
|
|
813
813
|
'The parameter "targetName" of HasManyResolver.includePolymorphicTo requires ' +
|
|
@@ -834,8 +834,8 @@ describe('HasManyResolver', function () {
|
|
|
834
834
|
});
|
|
835
835
|
|
|
836
836
|
it('requires the "relationName" parameter to be a non-empty string', async function () {
|
|
837
|
-
const
|
|
838
|
-
const R =
|
|
837
|
+
const dbs = new DatabaseSchema();
|
|
838
|
+
const R = dbs.getService(HasManyResolver);
|
|
839
839
|
const error = v =>
|
|
840
840
|
format(
|
|
841
841
|
'The parameter "relationName" of HasManyResolver.includePolymorphicTo requires ' +
|
|
@@ -862,8 +862,8 @@ describe('HasManyResolver', function () {
|
|
|
862
862
|
});
|
|
863
863
|
|
|
864
864
|
it('requires the "foreignKey" parameter to be a non-empty string', async function () {
|
|
865
|
-
const
|
|
866
|
-
const R =
|
|
865
|
+
const dbs = new DatabaseSchema();
|
|
866
|
+
const R = dbs.getService(HasManyResolver);
|
|
867
867
|
const error = v =>
|
|
868
868
|
format(
|
|
869
869
|
'The parameter "foreignKey" of HasManyResolver.includePolymorphicTo requires ' +
|
|
@@ -890,8 +890,8 @@ describe('HasManyResolver', function () {
|
|
|
890
890
|
});
|
|
891
891
|
|
|
892
892
|
it('requires the "discriminator" parameter to be a non-empty string', async function () {
|
|
893
|
-
const
|
|
894
|
-
const R =
|
|
893
|
+
const dbs = new DatabaseSchema();
|
|
894
|
+
const R = dbs.getService(HasManyResolver);
|
|
895
895
|
const error = v =>
|
|
896
896
|
format(
|
|
897
897
|
'The parameter "discriminator" of HasManyResolver.includePolymorphicTo requires ' +
|
|
@@ -918,8 +918,8 @@ describe('HasManyResolver', function () {
|
|
|
918
918
|
});
|
|
919
919
|
|
|
920
920
|
it('requires the provided parameter "scope" to be an object', async function () {
|
|
921
|
-
const
|
|
922
|
-
const R =
|
|
921
|
+
const dbs = new DatabaseSchema();
|
|
922
|
+
const R = dbs.getService(HasManyResolver);
|
|
923
923
|
const error = v =>
|
|
924
924
|
format(
|
|
925
925
|
'The provided parameter "scope" of HasManyResolver.includePolymorphicTo ' +
|
|
@@ -943,9 +943,9 @@ describe('HasManyResolver', function () {
|
|
|
943
943
|
});
|
|
944
944
|
|
|
945
945
|
it('throws an error if the given target model is not found', async function () {
|
|
946
|
-
const
|
|
947
|
-
|
|
948
|
-
const R =
|
|
946
|
+
const dbs = new DatabaseSchema();
|
|
947
|
+
dbs.defineModel({name: 'source'});
|
|
948
|
+
const R = dbs.getService(HasManyResolver);
|
|
949
949
|
const entity = {[DEF_PK]: 1};
|
|
950
950
|
const promise = R.includePolymorphicTo(
|
|
951
951
|
[entity],
|
|
@@ -961,10 +961,10 @@ describe('HasManyResolver', function () {
|
|
|
961
961
|
});
|
|
962
962
|
|
|
963
963
|
it('throws an error if the given target model does not have a datasource', async function () {
|
|
964
|
-
const
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
const R =
|
|
964
|
+
const dbs = new DatabaseSchema();
|
|
965
|
+
dbs.defineModel({name: 'source'});
|
|
966
|
+
dbs.defineModel({name: 'target'});
|
|
967
|
+
const R = dbs.getService(HasManyResolver);
|
|
968
968
|
const entity = {[DEF_PK]: 1};
|
|
969
969
|
const promise = R.includePolymorphicTo(
|
|
970
970
|
[entity],
|
|
@@ -980,16 +980,16 @@ describe('HasManyResolver', function () {
|
|
|
980
980
|
});
|
|
981
981
|
|
|
982
982
|
it('does not throw an error if a relation target is not found', async function () {
|
|
983
|
-
const
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
const sourceRel =
|
|
983
|
+
const dbs = new DatabaseSchema();
|
|
984
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
985
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
986
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
987
|
+
const sourceRel = dbs.getRepository('source');
|
|
988
988
|
const source = await sourceRel.create({});
|
|
989
989
|
expect(source).to.be.eql({
|
|
990
990
|
[DEF_PK]: source[DEF_PK],
|
|
991
991
|
});
|
|
992
|
-
const R =
|
|
992
|
+
const R = dbs.getService(HasManyResolver);
|
|
993
993
|
await R.includePolymorphicTo(
|
|
994
994
|
[source],
|
|
995
995
|
'source',
|
|
@@ -1005,12 +1005,12 @@ describe('HasManyResolver', function () {
|
|
|
1005
1005
|
});
|
|
1006
1006
|
|
|
1007
1007
|
it('does not include an entity with a not matched discriminator value', async function () {
|
|
1008
|
-
const
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
const sourceRel =
|
|
1013
|
-
const targetRel =
|
|
1008
|
+
const dbs = new DatabaseSchema();
|
|
1009
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
1010
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
1011
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
1012
|
+
const sourceRel = dbs.getRepository('source');
|
|
1013
|
+
const targetRel = dbs.getRepository('target');
|
|
1014
1014
|
const source = await sourceRel.create({});
|
|
1015
1015
|
expect(source).to.be.eql({
|
|
1016
1016
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -1024,7 +1024,7 @@ describe('HasManyResolver', function () {
|
|
|
1024
1024
|
parentId: source[DEF_PK],
|
|
1025
1025
|
parentType: 'unknown',
|
|
1026
1026
|
});
|
|
1027
|
-
const R =
|
|
1027
|
+
const R = dbs.getService(HasManyResolver);
|
|
1028
1028
|
await R.includePolymorphicTo(
|
|
1029
1029
|
[source],
|
|
1030
1030
|
'source',
|
|
@@ -1040,12 +1040,12 @@ describe('HasManyResolver', function () {
|
|
|
1040
1040
|
});
|
|
1041
1041
|
|
|
1042
1042
|
it('includes if a primary key is not defined in the source model', async function () {
|
|
1043
|
-
const
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
const sourceRep =
|
|
1048
|
-
const targetRep =
|
|
1043
|
+
const dbs = new DatabaseSchema();
|
|
1044
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
1045
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
1046
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
1047
|
+
const sourceRep = dbs.getRepository('source');
|
|
1048
|
+
const targetRep = dbs.getRepository('target');
|
|
1049
1049
|
const source = await sourceRep.create({});
|
|
1050
1050
|
expect(source).to.be.eql({[DEF_PK]: source[DEF_PK]});
|
|
1051
1051
|
const target1 = await targetRep.create({
|
|
@@ -1075,7 +1075,7 @@ describe('HasManyResolver', function () {
|
|
|
1075
1075
|
parentId: -1,
|
|
1076
1076
|
parentType: 'source',
|
|
1077
1077
|
});
|
|
1078
|
-
const R =
|
|
1078
|
+
const R = dbs.getService(HasManyResolver);
|
|
1079
1079
|
await R.includePolymorphicTo(
|
|
1080
1080
|
[source],
|
|
1081
1081
|
'source',
|
|
@@ -1102,9 +1102,9 @@ describe('HasManyResolver', function () {
|
|
|
1102
1102
|
});
|
|
1103
1103
|
|
|
1104
1104
|
it('includes if the source model has a custom primary key', async function () {
|
|
1105
|
-
const
|
|
1106
|
-
|
|
1107
|
-
|
|
1105
|
+
const dbs = new DatabaseSchema();
|
|
1106
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
1107
|
+
dbs.defineModel({
|
|
1108
1108
|
name: 'source',
|
|
1109
1109
|
datasource: 'datasource',
|
|
1110
1110
|
properties: {
|
|
@@ -1114,9 +1114,9 @@ describe('HasManyResolver', function () {
|
|
|
1114
1114
|
},
|
|
1115
1115
|
},
|
|
1116
1116
|
});
|
|
1117
|
-
|
|
1118
|
-
const sourceRep =
|
|
1119
|
-
const targetRep =
|
|
1117
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
1118
|
+
const sourceRep = dbs.getRepository('source');
|
|
1119
|
+
const targetRep = dbs.getRepository('target');
|
|
1120
1120
|
const source = await sourceRep.create({});
|
|
1121
1121
|
expect(source).to.be.eql({myId: source.myId});
|
|
1122
1122
|
const target1 = await targetRep.create({
|
|
@@ -1146,7 +1146,7 @@ describe('HasManyResolver', function () {
|
|
|
1146
1146
|
parentId: -1,
|
|
1147
1147
|
parentType: 'source',
|
|
1148
1148
|
});
|
|
1149
|
-
const R =
|
|
1149
|
+
const R = dbs.getService(HasManyResolver);
|
|
1150
1150
|
await R.includePolymorphicTo(
|
|
1151
1151
|
[source],
|
|
1152
1152
|
'source',
|
|
@@ -1173,10 +1173,10 @@ describe('HasManyResolver', function () {
|
|
|
1173
1173
|
});
|
|
1174
1174
|
|
|
1175
1175
|
it('includes if the target model has a custom primary key', async function () {
|
|
1176
|
-
const
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1176
|
+
const dbs = new DatabaseSchema();
|
|
1177
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
1178
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
1179
|
+
dbs.defineModel({
|
|
1180
1180
|
name: 'target',
|
|
1181
1181
|
datasource: 'datasource',
|
|
1182
1182
|
properties: {
|
|
@@ -1186,8 +1186,8 @@ describe('HasManyResolver', function () {
|
|
|
1186
1186
|
},
|
|
1187
1187
|
},
|
|
1188
1188
|
});
|
|
1189
|
-
const sourceRep =
|
|
1190
|
-
const targetRep =
|
|
1189
|
+
const sourceRep = dbs.getRepository('source');
|
|
1190
|
+
const targetRep = dbs.getRepository('target');
|
|
1191
1191
|
const source = await sourceRep.create({});
|
|
1192
1192
|
expect(source).to.be.eql({[DEF_PK]: source[DEF_PK]});
|
|
1193
1193
|
const target1 = await targetRep.create({
|
|
@@ -1217,7 +1217,7 @@ describe('HasManyResolver', function () {
|
|
|
1217
1217
|
parentId: -1,
|
|
1218
1218
|
parentType: 'source',
|
|
1219
1219
|
});
|
|
1220
|
-
const R =
|
|
1220
|
+
const R = dbs.getService(HasManyResolver);
|
|
1221
1221
|
await R.includePolymorphicTo(
|
|
1222
1222
|
[source],
|
|
1223
1223
|
'source',
|
|
@@ -1244,12 +1244,12 @@ describe('HasManyResolver', function () {
|
|
|
1244
1244
|
});
|
|
1245
1245
|
|
|
1246
1246
|
it('uses a where clause of the given scope to filter the relation target', async function () {
|
|
1247
|
-
const
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
const sourceRep =
|
|
1252
|
-
const targetRep =
|
|
1247
|
+
const dbs = new DatabaseSchema();
|
|
1248
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
1249
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
1250
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
1251
|
+
const sourceRep = dbs.getRepository('source');
|
|
1252
|
+
const targetRep = dbs.getRepository('target');
|
|
1253
1253
|
const source = await sourceRep.create({});
|
|
1254
1254
|
expect(source).to.be.eql({[DEF_PK]: source[DEF_PK]});
|
|
1255
1255
|
const target1 = await targetRep.create({
|
|
@@ -1285,7 +1285,7 @@ describe('HasManyResolver', function () {
|
|
|
1285
1285
|
parentId: source[DEF_PK],
|
|
1286
1286
|
parentType: 'source',
|
|
1287
1287
|
});
|
|
1288
|
-
const R =
|
|
1288
|
+
const R = dbs.getService(HasManyResolver);
|
|
1289
1289
|
await R.includePolymorphicTo(
|
|
1290
1290
|
[source],
|
|
1291
1291
|
'source',
|
|
@@ -1335,12 +1335,12 @@ describe('HasManyResolver', function () {
|
|
|
1335
1335
|
});
|
|
1336
1336
|
|
|
1337
1337
|
it('uses a fields clause of the given scope to filter the relation target', async function () {
|
|
1338
|
-
const
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
const sourceRep =
|
|
1343
|
-
const targetRep =
|
|
1338
|
+
const dbs = new DatabaseSchema();
|
|
1339
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
1340
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
1341
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
1342
|
+
const sourceRep = dbs.getRepository('source');
|
|
1343
|
+
const targetRep = dbs.getRepository('target');
|
|
1344
1344
|
const source = await sourceRep.create({});
|
|
1345
1345
|
expect(source).to.be.eql({
|
|
1346
1346
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -1384,7 +1384,7 @@ describe('HasManyResolver', function () {
|
|
|
1384
1384
|
parentId: -1,
|
|
1385
1385
|
parentType: 'source',
|
|
1386
1386
|
});
|
|
1387
|
-
const R =
|
|
1387
|
+
const R = dbs.getService(HasManyResolver);
|
|
1388
1388
|
await R.includePolymorphicTo(
|
|
1389
1389
|
[source],
|
|
1390
1390
|
'source',
|
|
@@ -1410,12 +1410,12 @@ describe('HasManyResolver', function () {
|
|
|
1410
1410
|
});
|
|
1411
1411
|
|
|
1412
1412
|
it('uses an include clause of the given scope to resolve target relations', async function () {
|
|
1413
|
-
const
|
|
1414
|
-
|
|
1413
|
+
const dbs = new DatabaseSchema();
|
|
1414
|
+
dbs.defineDatasource({
|
|
1415
1415
|
name: 'datasource',
|
|
1416
1416
|
adapter: 'memory',
|
|
1417
1417
|
});
|
|
1418
|
-
|
|
1418
|
+
dbs.defineModel({
|
|
1419
1419
|
name: 'modelA',
|
|
1420
1420
|
datasource: 'datasource',
|
|
1421
1421
|
properties: {
|
|
@@ -1438,7 +1438,7 @@ describe('HasManyResolver', function () {
|
|
|
1438
1438
|
},
|
|
1439
1439
|
},
|
|
1440
1440
|
});
|
|
1441
|
-
|
|
1441
|
+
dbs.defineModel({
|
|
1442
1442
|
name: 'modelB',
|
|
1443
1443
|
datasource: 'datasource',
|
|
1444
1444
|
properties: {
|
|
@@ -1461,7 +1461,7 @@ describe('HasManyResolver', function () {
|
|
|
1461
1461
|
},
|
|
1462
1462
|
},
|
|
1463
1463
|
});
|
|
1464
|
-
|
|
1464
|
+
dbs.defineModel({
|
|
1465
1465
|
name: 'modelC',
|
|
1466
1466
|
datasource: 'datasource',
|
|
1467
1467
|
properties: {
|
|
@@ -1475,9 +1475,9 @@ describe('HasManyResolver', function () {
|
|
|
1475
1475
|
},
|
|
1476
1476
|
},
|
|
1477
1477
|
});
|
|
1478
|
-
const aRep =
|
|
1479
|
-
const bRep =
|
|
1480
|
-
const cRep =
|
|
1478
|
+
const aRep = dbs.getRepository('modelA');
|
|
1479
|
+
const bRep = dbs.getRepository('modelB');
|
|
1480
|
+
const cRep = dbs.getRepository('modelC');
|
|
1481
1481
|
const a = await aRep.create({});
|
|
1482
1482
|
const b1 = await bRep.create({parentId: a.id, parentType: 'modelA'});
|
|
1483
1483
|
const b2 = await bRep.create({parentId: a.id, parentType: 'modelA'});
|
|
@@ -1525,7 +1525,7 @@ describe('HasManyResolver', function () {
|
|
|
1525
1525
|
parentId: b2.id,
|
|
1526
1526
|
parentType: 'modelB',
|
|
1527
1527
|
});
|
|
1528
|
-
const R =
|
|
1528
|
+
const R = dbs.getService(HasManyResolver);
|
|
1529
1529
|
await R.includePolymorphicTo(
|
|
1530
1530
|
[a],
|
|
1531
1531
|
'modelA',
|
|
@@ -1584,12 +1584,12 @@ describe('HasManyResolver', function () {
|
|
|
1584
1584
|
});
|
|
1585
1585
|
|
|
1586
1586
|
it('does not break the "and" operator of the given "where" clause', async function () {
|
|
1587
|
-
const
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
const sourceRep =
|
|
1592
|
-
const targetRep =
|
|
1587
|
+
const dbs = new DatabaseSchema();
|
|
1588
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
1589
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
1590
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
1591
|
+
const sourceRep = dbs.getRepository('source');
|
|
1592
|
+
const targetRep = dbs.getRepository('target');
|
|
1593
1593
|
const source = await sourceRep.create({});
|
|
1594
1594
|
expect(source).to.be.eql({
|
|
1595
1595
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -1627,7 +1627,7 @@ describe('HasManyResolver', function () {
|
|
|
1627
1627
|
parentId: source[DEF_PK],
|
|
1628
1628
|
parentType: 'source',
|
|
1629
1629
|
});
|
|
1630
|
-
const R =
|
|
1630
|
+
const R = dbs.getService(HasManyResolver);
|
|
1631
1631
|
await R.includePolymorphicTo(
|
|
1632
1632
|
[source],
|
|
1633
1633
|
'source',
|
|
@@ -1680,8 +1680,8 @@ describe('HasManyResolver', function () {
|
|
|
1680
1680
|
|
|
1681
1681
|
describe('includePolymorphicByRelationName', function () {
|
|
1682
1682
|
it('requires the "entities" parameter to be an array', async function () {
|
|
1683
|
-
const
|
|
1684
|
-
const R =
|
|
1683
|
+
const dbs = new DatabaseSchema();
|
|
1684
|
+
const R = dbs.getService(HasManyResolver);
|
|
1685
1685
|
const error = v =>
|
|
1686
1686
|
format(
|
|
1687
1687
|
'The parameter "entities" of HasManyResolver.includePolymorphicByRelationName requires ' +
|
|
@@ -1707,9 +1707,9 @@ describe('HasManyResolver', function () {
|
|
|
1707
1707
|
});
|
|
1708
1708
|
|
|
1709
1709
|
it('requires elements of the "entities" parameter to be an Object', async function () {
|
|
1710
|
-
const
|
|
1711
|
-
|
|
1712
|
-
|
|
1710
|
+
const dbs = new DatabaseSchema();
|
|
1711
|
+
dbs.defineModel({name: 'source'});
|
|
1712
|
+
dbs.defineModel({
|
|
1713
1713
|
name: 'target',
|
|
1714
1714
|
relations: {
|
|
1715
1715
|
parent: {
|
|
@@ -1718,7 +1718,7 @@ describe('HasManyResolver', function () {
|
|
|
1718
1718
|
},
|
|
1719
1719
|
},
|
|
1720
1720
|
});
|
|
1721
|
-
const R =
|
|
1721
|
+
const R = dbs.getService(HasManyResolver);
|
|
1722
1722
|
const error = v =>
|
|
1723
1723
|
format(
|
|
1724
1724
|
'The parameter "entities" of HasManyResolver.includePolymorphicTo requires ' +
|
|
@@ -1744,8 +1744,8 @@ describe('HasManyResolver', function () {
|
|
|
1744
1744
|
});
|
|
1745
1745
|
|
|
1746
1746
|
it('requires the "sourceName" parameter to be a non-empty string', async function () {
|
|
1747
|
-
const
|
|
1748
|
-
const R =
|
|
1747
|
+
const dbs = new DatabaseSchema();
|
|
1748
|
+
const R = dbs.getService(HasManyResolver);
|
|
1749
1749
|
const error = v =>
|
|
1750
1750
|
format(
|
|
1751
1751
|
'The parameter "sourceName" of HasManyResolver.includePolymorphicByRelationName requires ' +
|
|
@@ -1771,8 +1771,8 @@ describe('HasManyResolver', function () {
|
|
|
1771
1771
|
});
|
|
1772
1772
|
|
|
1773
1773
|
it('requires the "targetName" parameter to be a non-empty string', async function () {
|
|
1774
|
-
const
|
|
1775
|
-
const R =
|
|
1774
|
+
const dbs = new DatabaseSchema();
|
|
1775
|
+
const R = dbs.getService(HasManyResolver);
|
|
1776
1776
|
const error = v =>
|
|
1777
1777
|
format(
|
|
1778
1778
|
'The parameter "targetName" of HasManyResolver.includePolymorphicByRelationName requires ' +
|
|
@@ -1798,8 +1798,8 @@ describe('HasManyResolver', function () {
|
|
|
1798
1798
|
});
|
|
1799
1799
|
|
|
1800
1800
|
it('requires the "relationName" parameter to be a non-empty string', async function () {
|
|
1801
|
-
const
|
|
1802
|
-
const R =
|
|
1801
|
+
const dbs = new DatabaseSchema();
|
|
1802
|
+
const R = dbs.getService(HasManyResolver);
|
|
1803
1803
|
const error = v =>
|
|
1804
1804
|
format(
|
|
1805
1805
|
'The parameter "relationName" of HasManyResolver.includePolymorphicByRelationName requires ' +
|
|
@@ -1825,8 +1825,8 @@ describe('HasManyResolver', function () {
|
|
|
1825
1825
|
});
|
|
1826
1826
|
|
|
1827
1827
|
it('requires the "targetRelationName" parameter to be a non-empty string', async function () {
|
|
1828
|
-
const
|
|
1829
|
-
const R =
|
|
1828
|
+
const dbs = new DatabaseSchema();
|
|
1829
|
+
const R = dbs.getService(HasManyResolver);
|
|
1830
1830
|
const error = v =>
|
|
1831
1831
|
format(
|
|
1832
1832
|
'The parameter "targetRelationName" of HasManyResolver.includePolymorphicByRelationName requires ' +
|
|
@@ -1852,8 +1852,8 @@ describe('HasManyResolver', function () {
|
|
|
1852
1852
|
});
|
|
1853
1853
|
|
|
1854
1854
|
it('requires the provided parameter "scope" to be an object', async function () {
|
|
1855
|
-
const
|
|
1856
|
-
const R =
|
|
1855
|
+
const dbs = new DatabaseSchema();
|
|
1856
|
+
const R = dbs.getService(HasManyResolver);
|
|
1857
1857
|
const error = v =>
|
|
1858
1858
|
format(
|
|
1859
1859
|
'The provided parameter "scope" of HasManyResolver.includePolymorphicByRelationName ' +
|
|
@@ -1876,9 +1876,9 @@ describe('HasManyResolver', function () {
|
|
|
1876
1876
|
});
|
|
1877
1877
|
|
|
1878
1878
|
it('throws an error if the given target model is not found', async function () {
|
|
1879
|
-
const
|
|
1880
|
-
|
|
1881
|
-
const R =
|
|
1879
|
+
const dbs = new DatabaseSchema();
|
|
1880
|
+
dbs.defineModel({name: 'source'});
|
|
1881
|
+
const R = dbs.getService(HasManyResolver);
|
|
1882
1882
|
const entity = {[DEF_PK]: 1};
|
|
1883
1883
|
const promise = R.includePolymorphicByRelationName(
|
|
1884
1884
|
[entity],
|
|
@@ -1893,10 +1893,10 @@ describe('HasManyResolver', function () {
|
|
|
1893
1893
|
});
|
|
1894
1894
|
|
|
1895
1895
|
it('throws an error if the given target model does not have the given relation name', async function () {
|
|
1896
|
-
const
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
const R =
|
|
1896
|
+
const dbs = new DatabaseSchema();
|
|
1897
|
+
dbs.defineModel({name: 'source'});
|
|
1898
|
+
dbs.defineModel({name: 'target'});
|
|
1899
|
+
const R = dbs.getService(HasManyResolver);
|
|
1900
1900
|
const entity = {[DEF_PK]: 1};
|
|
1901
1901
|
const promise = R.includePolymorphicByRelationName(
|
|
1902
1902
|
[entity],
|
|
@@ -1911,9 +1911,9 @@ describe('HasManyResolver', function () {
|
|
|
1911
1911
|
});
|
|
1912
1912
|
|
|
1913
1913
|
it('throws an error if the target relation is not "belongsTo"', async function () {
|
|
1914
|
-
const
|
|
1915
|
-
|
|
1916
|
-
|
|
1914
|
+
const dbs = new DatabaseSchema();
|
|
1915
|
+
dbs.defineModel({name: 'source'});
|
|
1916
|
+
dbs.defineModel({
|
|
1917
1917
|
name: 'target',
|
|
1918
1918
|
relations: {
|
|
1919
1919
|
parent: {
|
|
@@ -1922,7 +1922,7 @@ describe('HasManyResolver', function () {
|
|
|
1922
1922
|
},
|
|
1923
1923
|
},
|
|
1924
1924
|
});
|
|
1925
|
-
const R =
|
|
1925
|
+
const R = dbs.getService(HasManyResolver);
|
|
1926
1926
|
const entity = {[DEF_PK]: 1};
|
|
1927
1927
|
const promise = R.includePolymorphicByRelationName(
|
|
1928
1928
|
[entity],
|
|
@@ -1939,9 +1939,9 @@ describe('HasManyResolver', function () {
|
|
|
1939
1939
|
});
|
|
1940
1940
|
|
|
1941
1941
|
it('throws an error if the target relation is not polymorphic', async function () {
|
|
1942
|
-
const
|
|
1943
|
-
|
|
1944
|
-
|
|
1942
|
+
const dbs = new DatabaseSchema();
|
|
1943
|
+
dbs.defineModel({name: 'source'});
|
|
1944
|
+
dbs.defineModel({
|
|
1945
1945
|
name: 'target',
|
|
1946
1946
|
relations: {
|
|
1947
1947
|
parent: {
|
|
@@ -1950,7 +1950,7 @@ describe('HasManyResolver', function () {
|
|
|
1950
1950
|
},
|
|
1951
1951
|
},
|
|
1952
1952
|
});
|
|
1953
|
-
const R =
|
|
1953
|
+
const R = dbs.getService(HasManyResolver);
|
|
1954
1954
|
const entity = {[DEF_PK]: 1};
|
|
1955
1955
|
const promise = R.includePolymorphicByRelationName(
|
|
1956
1956
|
[entity],
|
|
@@ -1967,9 +1967,9 @@ describe('HasManyResolver', function () {
|
|
|
1967
1967
|
});
|
|
1968
1968
|
|
|
1969
1969
|
it('throws an error if the given target model does not have a datasource', async function () {
|
|
1970
|
-
const
|
|
1971
|
-
|
|
1972
|
-
|
|
1970
|
+
const dbs = new DatabaseSchema();
|
|
1971
|
+
dbs.defineModel({name: 'source'});
|
|
1972
|
+
dbs.defineModel({
|
|
1973
1973
|
name: 'target',
|
|
1974
1974
|
relations: {
|
|
1975
1975
|
parent: {
|
|
@@ -1978,7 +1978,7 @@ describe('HasManyResolver', function () {
|
|
|
1978
1978
|
},
|
|
1979
1979
|
},
|
|
1980
1980
|
});
|
|
1981
|
-
const R =
|
|
1981
|
+
const R = dbs.getService(HasManyResolver);
|
|
1982
1982
|
const entity = {[DEF_PK]: 1};
|
|
1983
1983
|
const promise = R.includePolymorphicByRelationName(
|
|
1984
1984
|
[entity],
|
|
@@ -1993,10 +1993,10 @@ describe('HasManyResolver', function () {
|
|
|
1993
1993
|
});
|
|
1994
1994
|
|
|
1995
1995
|
it('does not throw an error if a relation target is not found', async function () {
|
|
1996
|
-
const
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
1996
|
+
const dbs = new DatabaseSchema();
|
|
1997
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
1998
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
1999
|
+
dbs.defineModel({
|
|
2000
2000
|
name: 'target',
|
|
2001
2001
|
datasource: 'datasource',
|
|
2002
2002
|
relations: {
|
|
@@ -2006,12 +2006,12 @@ describe('HasManyResolver', function () {
|
|
|
2006
2006
|
},
|
|
2007
2007
|
},
|
|
2008
2008
|
});
|
|
2009
|
-
const sourceRel =
|
|
2009
|
+
const sourceRel = dbs.getRepository('source');
|
|
2010
2010
|
const source = await sourceRel.create({});
|
|
2011
2011
|
expect(source).to.be.eql({
|
|
2012
2012
|
[DEF_PK]: source[DEF_PK],
|
|
2013
2013
|
});
|
|
2014
|
-
const R =
|
|
2014
|
+
const R = dbs.getService(HasManyResolver);
|
|
2015
2015
|
await R.includePolymorphicByRelationName(
|
|
2016
2016
|
[source],
|
|
2017
2017
|
'source',
|
|
@@ -2026,10 +2026,10 @@ describe('HasManyResolver', function () {
|
|
|
2026
2026
|
});
|
|
2027
2027
|
|
|
2028
2028
|
it('does not include an entity with a not matched discriminator value', async function () {
|
|
2029
|
-
const
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2029
|
+
const dbs = new DatabaseSchema();
|
|
2030
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
2031
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
2032
|
+
dbs.defineModel({
|
|
2033
2033
|
name: 'target',
|
|
2034
2034
|
datasource: 'datasource',
|
|
2035
2035
|
relations: {
|
|
@@ -2039,8 +2039,8 @@ describe('HasManyResolver', function () {
|
|
|
2039
2039
|
},
|
|
2040
2040
|
},
|
|
2041
2041
|
});
|
|
2042
|
-
const sourceRel =
|
|
2043
|
-
const targetRel =
|
|
2042
|
+
const sourceRel = dbs.getRepository('source');
|
|
2043
|
+
const targetRel = dbs.getRepository('target');
|
|
2044
2044
|
const source = await sourceRel.create({});
|
|
2045
2045
|
expect(source).to.be.eql({
|
|
2046
2046
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -2054,7 +2054,7 @@ describe('HasManyResolver', function () {
|
|
|
2054
2054
|
parentId: source[DEF_PK],
|
|
2055
2055
|
parentType: 'unknown',
|
|
2056
2056
|
});
|
|
2057
|
-
const R =
|
|
2057
|
+
const R = dbs.getService(HasManyResolver);
|
|
2058
2058
|
await R.includePolymorphicByRelationName(
|
|
2059
2059
|
[source],
|
|
2060
2060
|
'source',
|
|
@@ -2069,10 +2069,10 @@ describe('HasManyResolver', function () {
|
|
|
2069
2069
|
});
|
|
2070
2070
|
|
|
2071
2071
|
it('includes if a primary key is not defined in the source model', async function () {
|
|
2072
|
-
const
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2072
|
+
const dbs = new DatabaseSchema();
|
|
2073
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
2074
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
2075
|
+
dbs.defineModel({
|
|
2076
2076
|
name: 'target',
|
|
2077
2077
|
datasource: 'datasource',
|
|
2078
2078
|
relations: {
|
|
@@ -2082,8 +2082,8 @@ describe('HasManyResolver', function () {
|
|
|
2082
2082
|
},
|
|
2083
2083
|
},
|
|
2084
2084
|
});
|
|
2085
|
-
const sourceRep =
|
|
2086
|
-
const targetRep =
|
|
2085
|
+
const sourceRep = dbs.getRepository('source');
|
|
2086
|
+
const targetRep = dbs.getRepository('target');
|
|
2087
2087
|
const source = await sourceRep.create({});
|
|
2088
2088
|
expect(source).to.be.eql({[DEF_PK]: source[DEF_PK]});
|
|
2089
2089
|
const target1 = await targetRep.create({
|
|
@@ -2113,7 +2113,7 @@ describe('HasManyResolver', function () {
|
|
|
2113
2113
|
parentId: -1,
|
|
2114
2114
|
parentType: 'source',
|
|
2115
2115
|
});
|
|
2116
|
-
const R =
|
|
2116
|
+
const R = dbs.getService(HasManyResolver);
|
|
2117
2117
|
await R.includePolymorphicByRelationName(
|
|
2118
2118
|
[source],
|
|
2119
2119
|
'source',
|
|
@@ -2139,9 +2139,9 @@ describe('HasManyResolver', function () {
|
|
|
2139
2139
|
});
|
|
2140
2140
|
|
|
2141
2141
|
it('includes if the source model has a custom primary key', async function () {
|
|
2142
|
-
const
|
|
2143
|
-
|
|
2144
|
-
|
|
2142
|
+
const dbs = new DatabaseSchema();
|
|
2143
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
2144
|
+
dbs.defineModel({
|
|
2145
2145
|
name: 'source',
|
|
2146
2146
|
datasource: 'datasource',
|
|
2147
2147
|
properties: {
|
|
@@ -2151,7 +2151,7 @@ describe('HasManyResolver', function () {
|
|
|
2151
2151
|
},
|
|
2152
2152
|
},
|
|
2153
2153
|
});
|
|
2154
|
-
|
|
2154
|
+
dbs.defineModel({
|
|
2155
2155
|
name: 'target',
|
|
2156
2156
|
datasource: 'datasource',
|
|
2157
2157
|
relations: {
|
|
@@ -2161,8 +2161,8 @@ describe('HasManyResolver', function () {
|
|
|
2161
2161
|
},
|
|
2162
2162
|
},
|
|
2163
2163
|
});
|
|
2164
|
-
const sourceRep =
|
|
2165
|
-
const targetRep =
|
|
2164
|
+
const sourceRep = dbs.getRepository('source');
|
|
2165
|
+
const targetRep = dbs.getRepository('target');
|
|
2166
2166
|
const source = await sourceRep.create({});
|
|
2167
2167
|
expect(source).to.be.eql({myId: source.myId});
|
|
2168
2168
|
const target1 = await targetRep.create({
|
|
@@ -2192,7 +2192,7 @@ describe('HasManyResolver', function () {
|
|
|
2192
2192
|
parentId: -1,
|
|
2193
2193
|
parentType: 'source',
|
|
2194
2194
|
});
|
|
2195
|
-
const R =
|
|
2195
|
+
const R = dbs.getService(HasManyResolver);
|
|
2196
2196
|
await R.includePolymorphicByRelationName(
|
|
2197
2197
|
[source],
|
|
2198
2198
|
'source',
|
|
@@ -2218,10 +2218,10 @@ describe('HasManyResolver', function () {
|
|
|
2218
2218
|
});
|
|
2219
2219
|
|
|
2220
2220
|
it('includes if the target model has a custom primary key', async function () {
|
|
2221
|
-
const
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2221
|
+
const dbs = new DatabaseSchema();
|
|
2222
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
2223
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
2224
|
+
dbs.defineModel({
|
|
2225
2225
|
name: 'target',
|
|
2226
2226
|
datasource: 'datasource',
|
|
2227
2227
|
properties: {
|
|
@@ -2237,8 +2237,8 @@ describe('HasManyResolver', function () {
|
|
|
2237
2237
|
},
|
|
2238
2238
|
},
|
|
2239
2239
|
});
|
|
2240
|
-
const sourceRep =
|
|
2241
|
-
const targetRep =
|
|
2240
|
+
const sourceRep = dbs.getRepository('source');
|
|
2241
|
+
const targetRep = dbs.getRepository('target');
|
|
2242
2242
|
const source = await sourceRep.create({});
|
|
2243
2243
|
expect(source).to.be.eql({[DEF_PK]: source[DEF_PK]});
|
|
2244
2244
|
const target1 = await targetRep.create({
|
|
@@ -2268,7 +2268,7 @@ describe('HasManyResolver', function () {
|
|
|
2268
2268
|
parentId: -1,
|
|
2269
2269
|
parentType: 'source',
|
|
2270
2270
|
});
|
|
2271
|
-
const R =
|
|
2271
|
+
const R = dbs.getService(HasManyResolver);
|
|
2272
2272
|
await R.includePolymorphicByRelationName(
|
|
2273
2273
|
[source],
|
|
2274
2274
|
'source',
|
|
@@ -2294,10 +2294,10 @@ describe('HasManyResolver', function () {
|
|
|
2294
2294
|
});
|
|
2295
2295
|
|
|
2296
2296
|
it('includes if the target model has a custom "foreignKey"', async function () {
|
|
2297
|
-
const
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2297
|
+
const dbs = new DatabaseSchema();
|
|
2298
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
2299
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
2300
|
+
dbs.defineModel({
|
|
2301
2301
|
name: 'target',
|
|
2302
2302
|
datasource: 'datasource',
|
|
2303
2303
|
properties: {
|
|
@@ -2314,8 +2314,8 @@ describe('HasManyResolver', function () {
|
|
|
2314
2314
|
},
|
|
2315
2315
|
},
|
|
2316
2316
|
});
|
|
2317
|
-
const sourceRep =
|
|
2318
|
-
const targetRep =
|
|
2317
|
+
const sourceRep = dbs.getRepository('source');
|
|
2318
|
+
const targetRep = dbs.getRepository('target');
|
|
2319
2319
|
const source = await sourceRep.create({});
|
|
2320
2320
|
expect(source).to.be.eql({[DEF_PK]: source[DEF_PK]});
|
|
2321
2321
|
const target1 = await targetRep.create({
|
|
@@ -2345,7 +2345,7 @@ describe('HasManyResolver', function () {
|
|
|
2345
2345
|
relationId: -1,
|
|
2346
2346
|
parentType: 'source',
|
|
2347
2347
|
});
|
|
2348
|
-
const R =
|
|
2348
|
+
const R = dbs.getService(HasManyResolver);
|
|
2349
2349
|
await R.includePolymorphicByRelationName(
|
|
2350
2350
|
[source],
|
|
2351
2351
|
'source',
|
|
@@ -2371,10 +2371,10 @@ describe('HasManyResolver', function () {
|
|
|
2371
2371
|
});
|
|
2372
2372
|
|
|
2373
2373
|
it('includes if the target model has a custom "discriminator"', async function () {
|
|
2374
|
-
const
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2374
|
+
const dbs = new DatabaseSchema();
|
|
2375
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
2376
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
2377
|
+
dbs.defineModel({
|
|
2378
2378
|
name: 'target',
|
|
2379
2379
|
datasource: 'datasource',
|
|
2380
2380
|
properties: {
|
|
@@ -2391,8 +2391,8 @@ describe('HasManyResolver', function () {
|
|
|
2391
2391
|
},
|
|
2392
2392
|
},
|
|
2393
2393
|
});
|
|
2394
|
-
const sourceRep =
|
|
2395
|
-
const targetRep =
|
|
2394
|
+
const sourceRep = dbs.getRepository('source');
|
|
2395
|
+
const targetRep = dbs.getRepository('target');
|
|
2396
2396
|
const source = await sourceRep.create({});
|
|
2397
2397
|
expect(source).to.be.eql({[DEF_PK]: source[DEF_PK]});
|
|
2398
2398
|
const target1 = await targetRep.create({
|
|
@@ -2422,7 +2422,7 @@ describe('HasManyResolver', function () {
|
|
|
2422
2422
|
parentId: -1,
|
|
2423
2423
|
relationType: 'source',
|
|
2424
2424
|
});
|
|
2425
|
-
const R =
|
|
2425
|
+
const R = dbs.getService(HasManyResolver);
|
|
2426
2426
|
await R.includePolymorphicByRelationName(
|
|
2427
2427
|
[source],
|
|
2428
2428
|
'source',
|
|
@@ -2448,10 +2448,10 @@ describe('HasManyResolver', function () {
|
|
|
2448
2448
|
});
|
|
2449
2449
|
|
|
2450
2450
|
it('uses a where clause of the given scope to filter the relation target', async function () {
|
|
2451
|
-
const
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2451
|
+
const dbs = new DatabaseSchema();
|
|
2452
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
2453
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
2454
|
+
dbs.defineModel({
|
|
2455
2455
|
name: 'target',
|
|
2456
2456
|
datasource: 'datasource',
|
|
2457
2457
|
relations: {
|
|
@@ -2461,8 +2461,8 @@ describe('HasManyResolver', function () {
|
|
|
2461
2461
|
},
|
|
2462
2462
|
},
|
|
2463
2463
|
});
|
|
2464
|
-
const sourceRep =
|
|
2465
|
-
const targetRep =
|
|
2464
|
+
const sourceRep = dbs.getRepository('source');
|
|
2465
|
+
const targetRep = dbs.getRepository('target');
|
|
2466
2466
|
const source = await sourceRep.create({});
|
|
2467
2467
|
expect(source).to.be.eql({[DEF_PK]: source[DEF_PK]});
|
|
2468
2468
|
const target1 = await targetRep.create({
|
|
@@ -2498,7 +2498,7 @@ describe('HasManyResolver', function () {
|
|
|
2498
2498
|
parentId: source[DEF_PK],
|
|
2499
2499
|
parentType: 'source',
|
|
2500
2500
|
});
|
|
2501
|
-
const R =
|
|
2501
|
+
const R = dbs.getService(HasManyResolver);
|
|
2502
2502
|
await R.includePolymorphicByRelationName(
|
|
2503
2503
|
[source],
|
|
2504
2504
|
'source',
|
|
@@ -2546,10 +2546,10 @@ describe('HasManyResolver', function () {
|
|
|
2546
2546
|
});
|
|
2547
2547
|
|
|
2548
2548
|
it('uses a fields clause of the given scope to filter the relation target', async function () {
|
|
2549
|
-
const
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2549
|
+
const dbs = new DatabaseSchema();
|
|
2550
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
2551
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
2552
|
+
dbs.defineModel({
|
|
2553
2553
|
name: 'target',
|
|
2554
2554
|
datasource: 'datasource',
|
|
2555
2555
|
relations: {
|
|
@@ -2559,8 +2559,8 @@ describe('HasManyResolver', function () {
|
|
|
2559
2559
|
},
|
|
2560
2560
|
},
|
|
2561
2561
|
});
|
|
2562
|
-
const sourceRep =
|
|
2563
|
-
const targetRep =
|
|
2562
|
+
const sourceRep = dbs.getRepository('source');
|
|
2563
|
+
const targetRep = dbs.getRepository('target');
|
|
2564
2564
|
const source = await sourceRep.create({});
|
|
2565
2565
|
expect(source).to.be.eql({
|
|
2566
2566
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -2604,7 +2604,7 @@ describe('HasManyResolver', function () {
|
|
|
2604
2604
|
parentId: -1,
|
|
2605
2605
|
parentType: 'source',
|
|
2606
2606
|
});
|
|
2607
|
-
const R =
|
|
2607
|
+
const R = dbs.getService(HasManyResolver);
|
|
2608
2608
|
await R.includePolymorphicByRelationName(
|
|
2609
2609
|
[source],
|
|
2610
2610
|
'source',
|
|
@@ -2629,12 +2629,12 @@ describe('HasManyResolver', function () {
|
|
|
2629
2629
|
});
|
|
2630
2630
|
|
|
2631
2631
|
it('uses an include clause of the given scope to resolve target relations', async function () {
|
|
2632
|
-
const
|
|
2633
|
-
|
|
2632
|
+
const dbs = new DatabaseSchema();
|
|
2633
|
+
dbs.defineDatasource({
|
|
2634
2634
|
name: 'datasource',
|
|
2635
2635
|
adapter: 'memory',
|
|
2636
2636
|
});
|
|
2637
|
-
|
|
2637
|
+
dbs.defineModel({
|
|
2638
2638
|
name: 'modelA',
|
|
2639
2639
|
datasource: 'datasource',
|
|
2640
2640
|
properties: {
|
|
@@ -2655,7 +2655,7 @@ describe('HasManyResolver', function () {
|
|
|
2655
2655
|
},
|
|
2656
2656
|
},
|
|
2657
2657
|
});
|
|
2658
|
-
|
|
2658
|
+
dbs.defineModel({
|
|
2659
2659
|
name: 'modelB',
|
|
2660
2660
|
datasource: 'datasource',
|
|
2661
2661
|
properties: {
|
|
@@ -2680,7 +2680,7 @@ describe('HasManyResolver', function () {
|
|
|
2680
2680
|
},
|
|
2681
2681
|
},
|
|
2682
2682
|
});
|
|
2683
|
-
|
|
2683
|
+
dbs.defineModel({
|
|
2684
2684
|
name: 'modelC',
|
|
2685
2685
|
datasource: 'datasource',
|
|
2686
2686
|
properties: {
|
|
@@ -2700,9 +2700,9 @@ describe('HasManyResolver', function () {
|
|
|
2700
2700
|
},
|
|
2701
2701
|
},
|
|
2702
2702
|
});
|
|
2703
|
-
const aRep =
|
|
2704
|
-
const bRep =
|
|
2705
|
-
const cRep =
|
|
2703
|
+
const aRep = dbs.getRepository('modelA');
|
|
2704
|
+
const bRep = dbs.getRepository('modelB');
|
|
2705
|
+
const cRep = dbs.getRepository('modelC');
|
|
2706
2706
|
const a = await aRep.create({});
|
|
2707
2707
|
const b1 = await bRep.create({parentId: a.id, parentType: 'modelA'});
|
|
2708
2708
|
const b2 = await bRep.create({parentId: a.id, parentType: 'modelA'});
|
|
@@ -2750,7 +2750,7 @@ describe('HasManyResolver', function () {
|
|
|
2750
2750
|
parentId: b2.id,
|
|
2751
2751
|
parentType: 'modelB',
|
|
2752
2752
|
});
|
|
2753
|
-
const R =
|
|
2753
|
+
const R = dbs.getService(HasManyResolver);
|
|
2754
2754
|
await R.includePolymorphicByRelationName(
|
|
2755
2755
|
[a],
|
|
2756
2756
|
'modelA',
|
|
@@ -2808,10 +2808,10 @@ describe('HasManyResolver', function () {
|
|
|
2808
2808
|
});
|
|
2809
2809
|
|
|
2810
2810
|
it('does not break the "and" operator of the given "where" clause', async function () {
|
|
2811
|
-
const
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2811
|
+
const dbs = new DatabaseSchema();
|
|
2812
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
2813
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
2814
|
+
dbs.defineModel({
|
|
2815
2815
|
name: 'target',
|
|
2816
2816
|
datasource: 'datasource',
|
|
2817
2817
|
relations: {
|
|
@@ -2821,8 +2821,8 @@ describe('HasManyResolver', function () {
|
|
|
2821
2821
|
},
|
|
2822
2822
|
},
|
|
2823
2823
|
});
|
|
2824
|
-
const sourceRep =
|
|
2825
|
-
const targetRep =
|
|
2824
|
+
const sourceRep = dbs.getRepository('source');
|
|
2825
|
+
const targetRep = dbs.getRepository('target');
|
|
2826
2826
|
const source = await sourceRep.create({});
|
|
2827
2827
|
expect(source).to.be.eql({
|
|
2828
2828
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -2860,7 +2860,7 @@ describe('HasManyResolver', function () {
|
|
|
2860
2860
|
parentId: source[DEF_PK],
|
|
2861
2861
|
parentType: 'source',
|
|
2862
2862
|
});
|
|
2863
|
-
const R =
|
|
2863
|
+
const R = dbs.getService(HasManyResolver);
|
|
2864
2864
|
await R.includePolymorphicByRelationName(
|
|
2865
2865
|
[source],
|
|
2866
2866
|
'source',
|