@e22m4u/js-repository 0.2.7 → 0.3.1
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 +80 -80
- package/dist/cjs/index.cjs +2472 -2472
- package/eslint.config.js +1 -1
- package/package.json +14 -14
- 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.spec.js +93 -93
- package/src/definition/model/model-data-validator.spec.js +514 -528
- package/src/definition/model/model-definition-utils.spec.js +343 -341
- package/src/definition/model/properties/property-transformer/property-transformer-registry.spec.js +36 -36
- package/src/definition/model/properties/property-uniqueness-validator.spec.js +410 -377
- 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/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 {ReferencesManyResolver} from './references-many-resolver.js';
|
|
7
7
|
import {DEFAULT_PRIMARY_KEY_PROPERTY_NAME as DEF_PK} from '../definition/index.js';
|
|
8
8
|
|
|
9
9
|
describe('ReferencesManyResolver', 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(ReferencesManyResolver);
|
|
14
14
|
const error = v =>
|
|
15
15
|
format(
|
|
16
16
|
'The parameter "entities" of ReferencesManyResolver.includeTo requires ' +
|
|
@@ -30,8 +30,8 @@ describe('ReferencesManyResolver', function () {
|
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
it('requires elements of the "entities" parameter to be an Object', async function () {
|
|
33
|
-
const
|
|
34
|
-
const R =
|
|
33
|
+
const dbs = new DatabaseSchema();
|
|
34
|
+
const R = dbs.getService(ReferencesManyResolver);
|
|
35
35
|
const error = v =>
|
|
36
36
|
format(
|
|
37
37
|
'The parameter "entities" of ReferencesManyResolver.includeTo requires ' +
|
|
@@ -51,8 +51,8 @@ describe('ReferencesManyResolver', function () {
|
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
it('requires the "sourceName" parameter to be a non-empty string', async function () {
|
|
54
|
-
const
|
|
55
|
-
const R =
|
|
54
|
+
const dbs = new DatabaseSchema();
|
|
55
|
+
const R = dbs.getService(ReferencesManyResolver);
|
|
56
56
|
const error = v =>
|
|
57
57
|
format(
|
|
58
58
|
'The parameter "sourceName" of ReferencesManyResolver.includeTo requires ' +
|
|
@@ -71,8 +71,8 @@ describe('ReferencesManyResolver', function () {
|
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
it('requires the "targetName" parameter to be a non-empty string', async function () {
|
|
74
|
-
const
|
|
75
|
-
const R =
|
|
74
|
+
const dbs = new DatabaseSchema();
|
|
75
|
+
const R = dbs.getService(ReferencesManyResolver);
|
|
76
76
|
const error = v =>
|
|
77
77
|
format(
|
|
78
78
|
'The parameter "targetName" of ReferencesManyResolver.includeTo requires ' +
|
|
@@ -91,8 +91,8 @@ describe('ReferencesManyResolver', function () {
|
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
it('requires the "relationName" parameter to be a non-empty string', async function () {
|
|
94
|
-
const
|
|
95
|
-
const R =
|
|
94
|
+
const dbs = new DatabaseSchema();
|
|
95
|
+
const R = dbs.getService(ReferencesManyResolver);
|
|
96
96
|
const error = v =>
|
|
97
97
|
format(
|
|
98
98
|
'The parameter "relationName" of ReferencesManyResolver.includeTo requires ' +
|
|
@@ -111,8 +111,8 @@ describe('ReferencesManyResolver', function () {
|
|
|
111
111
|
});
|
|
112
112
|
|
|
113
113
|
it('requires the provided parameter "foreignKey" to be a string', async function () {
|
|
114
|
-
const
|
|
115
|
-
const R =
|
|
114
|
+
const dbs = new DatabaseSchema();
|
|
115
|
+
const R = dbs.getService(ReferencesManyResolver);
|
|
116
116
|
const error = v =>
|
|
117
117
|
format(
|
|
118
118
|
'The provided parameter "foreignKey" of ReferencesManyResolver.includeTo ' +
|
|
@@ -128,8 +128,8 @@ describe('ReferencesManyResolver', function () {
|
|
|
128
128
|
});
|
|
129
129
|
|
|
130
130
|
it('requires the provided parameter "scope" to be an object', async function () {
|
|
131
|
-
const
|
|
132
|
-
const R =
|
|
131
|
+
const dbs = new DatabaseSchema();
|
|
132
|
+
const R = dbs.getService(ReferencesManyResolver);
|
|
133
133
|
const error = v =>
|
|
134
134
|
format(
|
|
135
135
|
'The provided parameter "scope" of ReferencesManyResolver.includeTo ' +
|
|
@@ -152,9 +152,9 @@ describe('ReferencesManyResolver', function () {
|
|
|
152
152
|
});
|
|
153
153
|
|
|
154
154
|
it('throws an error if the given target model is not found', async function () {
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
const R =
|
|
155
|
+
const dbs = new DatabaseSchema();
|
|
156
|
+
dbs.defineModel({name: 'source'});
|
|
157
|
+
const R = dbs.getService(ReferencesManyResolver);
|
|
158
158
|
const promise = R.includeTo([], 'source', 'target', 'relation');
|
|
159
159
|
await expect(promise).to.be.rejectedWith(
|
|
160
160
|
'The model "target" is not defined',
|
|
@@ -162,9 +162,9 @@ describe('ReferencesManyResolver', function () {
|
|
|
162
162
|
});
|
|
163
163
|
|
|
164
164
|
it('throws an error if the given target model does not have a datasource', async function () {
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
const R =
|
|
165
|
+
const dbs = new DatabaseSchema();
|
|
166
|
+
dbs.defineModel({name: 'target'});
|
|
167
|
+
const R = dbs.getService(ReferencesManyResolver);
|
|
168
168
|
const promise = R.includeTo([], 'source', 'target', 'relation');
|
|
169
169
|
await expect(promise).to.be.rejectedWith(
|
|
170
170
|
'The model "target" does not have a specified datasource.',
|
|
@@ -172,13 +172,13 @@ describe('ReferencesManyResolver', function () {
|
|
|
172
172
|
});
|
|
173
173
|
|
|
174
174
|
it('does not throw an error if a relation target is not found', async function () {
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const sourceRel =
|
|
175
|
+
const dbs = new DatabaseSchema();
|
|
176
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
177
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
178
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
179
|
+
const sourceRel = dbs.getRepository('source');
|
|
180
180
|
const source = await sourceRel.create({parentIds: [10, 20]});
|
|
181
|
-
const R =
|
|
181
|
+
const R = dbs.getService(ReferencesManyResolver);
|
|
182
182
|
await R.includeTo([source], 'source', 'target', 'parents');
|
|
183
183
|
expect(source).to.be.eql({
|
|
184
184
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -188,12 +188,12 @@ describe('ReferencesManyResolver', function () {
|
|
|
188
188
|
});
|
|
189
189
|
|
|
190
190
|
it('includes if a primary key is not defined in the target model', async function () {
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
const sourceRep =
|
|
196
|
-
const targetRep =
|
|
191
|
+
const dbs = new DatabaseSchema();
|
|
192
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
193
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
194
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
195
|
+
const sourceRep = dbs.getRepository('source');
|
|
196
|
+
const targetRep = dbs.getRepository('target');
|
|
197
197
|
const target1 = await targetRep.create({});
|
|
198
198
|
const target2 = await targetRep.create({});
|
|
199
199
|
const target3 = await targetRep.create({});
|
|
@@ -207,7 +207,7 @@ describe('ReferencesManyResolver', function () {
|
|
|
207
207
|
[DEF_PK]: source[DEF_PK],
|
|
208
208
|
parentIds: [target1[DEF_PK], target2[DEF_PK]],
|
|
209
209
|
});
|
|
210
|
-
const R =
|
|
210
|
+
const R = dbs.getService(ReferencesManyResolver);
|
|
211
211
|
await R.includeTo([source], 'source', 'target', 'parents');
|
|
212
212
|
expect(source).to.be.eql({
|
|
213
213
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -217,10 +217,10 @@ describe('ReferencesManyResolver', function () {
|
|
|
217
217
|
});
|
|
218
218
|
|
|
219
219
|
it('includes if the target model has a custom primary key', async function () {
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
220
|
+
const dbs = new DatabaseSchema();
|
|
221
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
222
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
223
|
+
dbs.defineModel({
|
|
224
224
|
name: 'target',
|
|
225
225
|
datasource: 'datasource',
|
|
226
226
|
properties: {
|
|
@@ -230,8 +230,8 @@ describe('ReferencesManyResolver', function () {
|
|
|
230
230
|
},
|
|
231
231
|
},
|
|
232
232
|
});
|
|
233
|
-
const sourceRep =
|
|
234
|
-
const targetRep =
|
|
233
|
+
const sourceRep = dbs.getRepository('source');
|
|
234
|
+
const targetRep = dbs.getRepository('target');
|
|
235
235
|
const target1 = await targetRep.create({});
|
|
236
236
|
const target2 = await targetRep.create({});
|
|
237
237
|
const target3 = await targetRep.create({});
|
|
@@ -245,7 +245,7 @@ describe('ReferencesManyResolver', function () {
|
|
|
245
245
|
[DEF_PK]: source[DEF_PK],
|
|
246
246
|
parentIds: [target1.myId, target2.myId],
|
|
247
247
|
});
|
|
248
|
-
const R =
|
|
248
|
+
const R = dbs.getService(ReferencesManyResolver);
|
|
249
249
|
await R.includeTo([source], 'source', 'target', 'parents');
|
|
250
250
|
expect(source).to.be.eql({
|
|
251
251
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -255,9 +255,9 @@ describe('ReferencesManyResolver', 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('ReferencesManyResolver', 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 target1 = await targetRep.create({});
|
|
274
274
|
const target2 = await targetRep.create({});
|
|
275
275
|
const target3 = await targetRep.create({});
|
|
@@ -283,7 +283,7 @@ describe('ReferencesManyResolver', function () {
|
|
|
283
283
|
myId: source.myId,
|
|
284
284
|
parentIds: [target1[DEF_PK], target2[DEF_PK]],
|
|
285
285
|
});
|
|
286
|
-
const R =
|
|
286
|
+
const R = dbs.getService(ReferencesManyResolver);
|
|
287
287
|
await R.includeTo([source], 'source', 'target', 'parents');
|
|
288
288
|
expect(source).to.be.eql({
|
|
289
289
|
myId: source.myId,
|
|
@@ -293,12 +293,12 @@ describe('ReferencesManyResolver', function () {
|
|
|
293
293
|
});
|
|
294
294
|
|
|
295
295
|
it('includes if the property "foreignKey" is specified', async function () {
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
const sourceRep =
|
|
301
|
-
const targetRep =
|
|
296
|
+
const dbs = new DatabaseSchema();
|
|
297
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
298
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
299
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
300
|
+
const sourceRep = dbs.getRepository('source');
|
|
301
|
+
const targetRep = dbs.getRepository('target');
|
|
302
302
|
const target1 = await targetRep.create({});
|
|
303
303
|
const target2 = await targetRep.create({});
|
|
304
304
|
const target3 = await targetRep.create({});
|
|
@@ -312,7 +312,7 @@ describe('ReferencesManyResolver', function () {
|
|
|
312
312
|
[DEF_PK]: source[DEF_PK],
|
|
313
313
|
parentIds: [target1[DEF_PK], target2[DEF_PK]],
|
|
314
314
|
});
|
|
315
|
-
const R =
|
|
315
|
+
const R = dbs.getService(ReferencesManyResolver);
|
|
316
316
|
await R.includeTo([source], 'source', 'target', 'relations', 'parentIds');
|
|
317
317
|
expect(source).to.be.eql({
|
|
318
318
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -322,12 +322,12 @@ describe('ReferencesManyResolver', function () {
|
|
|
322
322
|
});
|
|
323
323
|
|
|
324
324
|
it('uses a where clause of the given scope to filter the relation target', async function () {
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
const sourceRep =
|
|
330
|
-
const targetRep =
|
|
325
|
+
const dbs = new DatabaseSchema();
|
|
326
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
327
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
328
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
329
|
+
const sourceRep = dbs.getRepository('source');
|
|
330
|
+
const targetRep = dbs.getRepository('target');
|
|
331
331
|
const target1 = await targetRep.create({featured: false});
|
|
332
332
|
const target2 = await targetRep.create({featured: true});
|
|
333
333
|
const target3 = await targetRep.create({featured: true});
|
|
@@ -341,7 +341,7 @@ describe('ReferencesManyResolver', function () {
|
|
|
341
341
|
[DEF_PK]: source[DEF_PK],
|
|
342
342
|
parentIds: [target1[DEF_PK], target2[DEF_PK], target3[DEF_PK]],
|
|
343
343
|
});
|
|
344
|
-
const R =
|
|
344
|
+
const R = dbs.getService(ReferencesManyResolver);
|
|
345
345
|
await R.includeTo([source], 'source', 'target', 'parents', undefined, {
|
|
346
346
|
where: {featured: false},
|
|
347
347
|
});
|
|
@@ -362,12 +362,12 @@ describe('ReferencesManyResolver', function () {
|
|
|
362
362
|
});
|
|
363
363
|
|
|
364
364
|
it('uses a slice clause of the given scope to filter the relation target', async function () {
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
const sourceRep =
|
|
370
|
-
const targetRep =
|
|
365
|
+
const dbs = new DatabaseSchema();
|
|
366
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
367
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
368
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
369
|
+
const sourceRep = dbs.getRepository('source');
|
|
370
|
+
const targetRep = dbs.getRepository('target');
|
|
371
371
|
const target1 = await targetRep.create({});
|
|
372
372
|
const target2 = await targetRep.create({});
|
|
373
373
|
const target3 = await targetRep.create({});
|
|
@@ -393,7 +393,7 @@ describe('ReferencesManyResolver', function () {
|
|
|
393
393
|
target4[DEF_PK],
|
|
394
394
|
],
|
|
395
395
|
});
|
|
396
|
-
const R =
|
|
396
|
+
const R = dbs.getService(ReferencesManyResolver);
|
|
397
397
|
await R.includeTo([source], 'source', 'target', 'parents', undefined, {
|
|
398
398
|
skip: 1,
|
|
399
399
|
limit: 2,
|
|
@@ -406,12 +406,12 @@ describe('ReferencesManyResolver', function () {
|
|
|
406
406
|
});
|
|
407
407
|
|
|
408
408
|
it('uses a fields clause of the given scope to filter the relation target', async function () {
|
|
409
|
-
const
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
const sourceRep =
|
|
414
|
-
const targetRep =
|
|
409
|
+
const dbs = new DatabaseSchema();
|
|
410
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
411
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
412
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
413
|
+
const sourceRep = dbs.getRepository('source');
|
|
414
|
+
const targetRep = dbs.getRepository('target');
|
|
415
415
|
const target1 = await targetRep.create({
|
|
416
416
|
foo: 'fooVal1',
|
|
417
417
|
bar: 'barVal1',
|
|
@@ -446,7 +446,7 @@ describe('ReferencesManyResolver', function () {
|
|
|
446
446
|
[DEF_PK]: source[DEF_PK],
|
|
447
447
|
parentIds: [target1[DEF_PK], target2[DEF_PK]],
|
|
448
448
|
});
|
|
449
|
-
const R =
|
|
449
|
+
const R = dbs.getService(ReferencesManyResolver);
|
|
450
450
|
await R.includeTo([source], 'source', 'target', 'parents', undefined, {
|
|
451
451
|
fields: [DEF_PK, 'bar'],
|
|
452
452
|
});
|
|
@@ -467,12 +467,12 @@ describe('ReferencesManyResolver', function () {
|
|
|
467
467
|
});
|
|
468
468
|
|
|
469
469
|
it('uses an include clause of the given scope to resolve target relations', async function () {
|
|
470
|
-
const
|
|
471
|
-
|
|
470
|
+
const dbs = new DatabaseSchema();
|
|
471
|
+
dbs.defineDatasource({
|
|
472
472
|
name: 'datasource',
|
|
473
473
|
adapter: 'memory',
|
|
474
474
|
});
|
|
475
|
-
|
|
475
|
+
dbs.defineModel({
|
|
476
476
|
name: 'modelA',
|
|
477
477
|
datasource: 'datasource',
|
|
478
478
|
properties: {
|
|
@@ -486,7 +486,7 @@ describe('ReferencesManyResolver', function () {
|
|
|
486
486
|
},
|
|
487
487
|
},
|
|
488
488
|
});
|
|
489
|
-
|
|
489
|
+
dbs.defineModel({
|
|
490
490
|
name: 'modelB',
|
|
491
491
|
datasource: 'datasource',
|
|
492
492
|
properties: {
|
|
@@ -506,7 +506,7 @@ describe('ReferencesManyResolver', function () {
|
|
|
506
506
|
},
|
|
507
507
|
},
|
|
508
508
|
});
|
|
509
|
-
|
|
509
|
+
dbs.defineModel({
|
|
510
510
|
name: 'modelC',
|
|
511
511
|
datasource: 'datasource',
|
|
512
512
|
properties: {
|
|
@@ -526,9 +526,9 @@ describe('ReferencesManyResolver', function () {
|
|
|
526
526
|
},
|
|
527
527
|
},
|
|
528
528
|
});
|
|
529
|
-
const aRep =
|
|
530
|
-
const bRep =
|
|
531
|
-
const cRep =
|
|
529
|
+
const aRep = dbs.getRepository('modelA');
|
|
530
|
+
const bRep = dbs.getRepository('modelB');
|
|
531
|
+
const cRep = dbs.getRepository('modelC');
|
|
532
532
|
const a1 = await aRep.create({});
|
|
533
533
|
const a2 = await aRep.create({});
|
|
534
534
|
const b1 = await bRep.create({parentId: a1.id});
|
|
@@ -557,7 +557,7 @@ describe('ReferencesManyResolver', function () {
|
|
|
557
557
|
source: 'modelC',
|
|
558
558
|
parentIds: [b1.id, b2.id],
|
|
559
559
|
});
|
|
560
|
-
const R =
|
|
560
|
+
const R = dbs.getService(ReferencesManyResolver);
|
|
561
561
|
await R.includeTo([c], 'modelC', 'modelB', 'parents', undefined, {
|
|
562
562
|
include: 'parent',
|
|
563
563
|
});
|
|
@@ -589,12 +589,12 @@ describe('ReferencesManyResolver', function () {
|
|
|
589
589
|
});
|
|
590
590
|
|
|
591
591
|
it('does not break the "and" operator of the given "where" clause', async function () {
|
|
592
|
-
const
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
const sourceRep =
|
|
597
|
-
const targetRep =
|
|
592
|
+
const dbs = new DatabaseSchema();
|
|
593
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
594
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
595
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
596
|
+
const sourceRep = dbs.getRepository('source');
|
|
597
|
+
const targetRep = dbs.getRepository('target');
|
|
598
598
|
const target1 = await targetRep.create({featured: false});
|
|
599
599
|
const target2 = await targetRep.create({featured: true});
|
|
600
600
|
const target3 = await targetRep.create({featured: true});
|
|
@@ -608,7 +608,7 @@ describe('ReferencesManyResolver', function () {
|
|
|
608
608
|
[DEF_PK]: source[DEF_PK],
|
|
609
609
|
parentIds: [target1[DEF_PK], target2[DEF_PK], target3[DEF_PK]],
|
|
610
610
|
});
|
|
611
|
-
const R =
|
|
611
|
+
const R = dbs.getService(ReferencesManyResolver);
|
|
612
612
|
await R.includeTo([source], 'source', 'target', 'parents', undefined, {
|
|
613
613
|
where: {and: [{featured: false}]},
|
|
614
614
|
});
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {expect} from 'chai';
|
|
2
|
-
import {Schema} from '../schema.js';
|
|
3
2
|
import {Repository} from './repository.js';
|
|
3
|
+
import {DatabaseSchema} from '../database-schema.js';
|
|
4
4
|
import {RepositoryRegistry} from './repository-registry.js';
|
|
5
5
|
|
|
6
6
|
describe('RepositoryRegistry', function () {
|
|
7
7
|
describe('setRepositoryCtor', function () {
|
|
8
8
|
it('sets a given class as the repository constructor', function () {
|
|
9
9
|
class MyRepository extends Repository {}
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const registry =
|
|
10
|
+
const dbs = new DatabaseSchema();
|
|
11
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
12
|
+
dbs.defineModel({name: 'model', datasource: 'datasource'});
|
|
13
|
+
const registry = dbs.getService(RepositoryRegistry);
|
|
14
14
|
registry.setRepositoryCtor(MyRepository);
|
|
15
15
|
const rep = registry.getRepository('model');
|
|
16
16
|
expect(rep).to.be.instanceof(Repository);
|
|
@@ -20,11 +20,11 @@ describe('RepositoryRegistry', function () {
|
|
|
20
20
|
|
|
21
21
|
describe('getRepository', function () {
|
|
22
22
|
it('uses a given model name to return an existing repository or create the new', function () {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const registry =
|
|
23
|
+
const dbs = new DatabaseSchema();
|
|
24
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
25
|
+
dbs.defineModel({name: 'modelA', datasource: 'datasource'});
|
|
26
|
+
dbs.defineModel({name: 'modelB', datasource: 'datasource'});
|
|
27
|
+
const registry = dbs.getService(RepositoryRegistry);
|
|
28
28
|
const repA1 = registry.getRepository('modelA');
|
|
29
29
|
const repA2 = registry.getRepository('modelA');
|
|
30
30
|
const repB1 = registry.getRepository('modelB');
|