@e22m4u/js-repository 0.0.33 → 0.0.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/package.json +1 -1
  2. package/src/adapter/adapter-loader.js +1 -1
  3. package/src/adapter/adapter-loader.spec.js +1 -1
  4. package/src/adapter/decorator/data-sanitizing-decorator.js +1 -1
  5. package/src/adapter/decorator/data-validation-decorator.js +1 -1
  6. package/src/adapter/decorator/default-values-decorator.js +1 -1
  7. package/src/adapter/decorator/fields-filtering-decorator.js +1 -1
  8. package/src/adapter/decorator/inclusion-decorator.js +1 -1
  9. package/src/definition/model/model-data-sanitizer.js +2 -2
  10. package/src/definition/model/model-data-validator.js +1 -1
  11. package/src/definition/model/model-data-validator.spec.js +1 -1
  12. package/src/definition/model/model-definition-utils.js +1 -1
  13. package/src/definition/model/model-definition-utils.spec.js +1 -1
  14. package/src/definition/model/properties/default-values-definition-validator.js +1 -1
  15. package/src/definition/model/properties/default-values-definition-validator.spec.js +1 -1
  16. package/src/definition/model/properties/properties-definition-validator.js +2 -2
  17. package/src/definition/model/properties/properties-definition-validator.spec.js +1 -1
  18. package/src/definition/model/relations/relations-definition-validator.js +2 -2
  19. package/src/definition/model/relations/relations-definition-validator.spec.js +1 -1
  20. package/src/filter/fields-clause-tool.d.ts +2 -2
  21. package/src/filter/fields-clause-tool.js +32 -21
  22. package/src/filter/fields-clause-tool.spec.js +479 -100
  23. package/src/filter/include-clause-tool.js +50 -42
  24. package/src/filter/include-clause-tool.spec.js +4391 -291
  25. package/src/filter/operator-clause-tool.js +13 -13
  26. package/src/filter/operator-clause-tool.spec.js +13 -13
  27. package/src/filter/order-clause-tool.js +20 -17
  28. package/src/filter/order-clause-tool.spec.js +621 -362
  29. package/src/filter/slice-clause-tool.js +5 -5
  30. package/src/filter/slice-clause-tool.spec.js +92 -51
  31. package/src/filter/where-clause-tool.js +7 -7
  32. package/src/filter/where-clause-tool.spec.js +79 -55
  33. package/src/utils/select-object-keys.js +3 -3
  34. package/src/utils/select-object-keys.spec.js +3 -3
@@ -6,14 +6,12 @@ describe('IncludeClauseTool', function () {
6
6
  describe('validateIncludeClause', function () {
7
7
  it('does not throw for valid values', function () {
8
8
  const validate = v => IncludeClauseTool.validateIncludeClause(v);
9
- // empty
10
- validate(0);
11
- validate('');
12
- validate(null);
9
+ // undefined and null
13
10
  validate(undefined);
14
- // strings
11
+ validate(null);
12
+ // a non-empty string
15
13
  validate('foo');
16
- // arrays
14
+ // an array
17
15
  validate(['foo']);
18
16
  validate([['foo']]);
19
17
  validate([{foo: 'bar'}]);
@@ -25,7 +23,7 @@ describe('IncludeClauseTool', function () {
25
23
  validate([{relation: 'foo', scope: {include: ['bar']}}]);
26
24
  validate([{relation: 'foo', scope: {include: {bar: 'baz'}}}]);
27
25
  validate([{relation: 'foo', scope: {include: [{bar: 'baz'}]}}]);
28
- // objects
26
+ // an object
29
27
  validate({foo: 'bar'});
30
28
  validate({foo: ['bar']});
31
29
  validate({foo: {bar: 'baz'}});
@@ -39,14 +37,14 @@ describe('IncludeClauseTool', function () {
39
37
  });
40
38
 
41
39
  it('throws an error for unsupported values', function () {
42
- const validate = v => () => IncludeClauseTool.validateIncludeClause(v);
40
+ const throwable = v => () => IncludeClauseTool.validateIncludeClause(v);
43
41
  const createError = v =>
44
42
  format(
45
- 'The provided option "include" should have a value of ' +
46
- 'following types: String, Object or Array, but %v given.',
43
+ 'The provided option "include" should have a non-empty String, ' +
44
+ 'an Object or an Array, but %v given.',
47
45
  v,
48
46
  );
49
- const testFor = v => {
47
+ const testOf = v => {
50
48
  const error = createError(v);
51
49
  const clauses = [
52
50
  v,
@@ -70,11 +68,14 @@ describe('IncludeClauseTool', function () {
70
68
  {relation: 'foo', scope: {include: v}},
71
69
  {relation: 'foo', scope: {include: {bar: v}}},
72
70
  ];
73
- clauses.forEach(c => expect(validate(c)).to.throw(error));
71
+ clauses.forEach(c => expect(throwable(c)).to.throw(error));
74
72
  };
75
- testFor(10);
76
- testFor(true);
77
- testFor(() => undefined);
73
+ testOf('');
74
+ testOf(10);
75
+ testOf(0);
76
+ testOf(true);
77
+ testOf(false);
78
+ testOf(() => undefined);
78
79
  });
79
80
 
80
81
  it('throws an error for duplicates', function () {
@@ -99,13 +100,78 @@ describe('IncludeClauseTool', function () {
99
100
  });
100
101
 
101
102
  describe('normalizeClause', function () {
102
- it('normalizes a given string', function () {
103
+ it('throws an error for unsupported values', function () {
104
+ const throwable = v => () => IncludeClauseTool.normalizeIncludeClause(v);
105
+ const createError = v =>
106
+ format(
107
+ 'The provided option "include" should have a non-empty String, ' +
108
+ 'an Object or an Array, but %v given.',
109
+ v,
110
+ );
111
+ const testOf = v => {
112
+ const error = createError(v);
113
+ const clauses = [
114
+ v,
115
+ // arrays
116
+ [v],
117
+ [{foo: v}],
118
+ [{foo: [v]}],
119
+ [{foo: {bar: v}}],
120
+ [{foo: {bar: [v]}}],
121
+ [{foo: [{bar: v}]}],
122
+ [{foo: [{bar: [v]}]}],
123
+ [{relation: 'foo', scope: {include: v}}],
124
+ [{relation: 'foo', scope: {include: {bar: v}}}],
125
+ // objects
126
+ {foo: v},
127
+ {foo: [v]},
128
+ {foo: {bar: v}},
129
+ {foo: {bar: [v]}},
130
+ {foo: [{bar: v}]},
131
+ {foo: [{bar: [v]}]},
132
+ {relation: 'foo', scope: {include: v}},
133
+ {relation: 'foo', scope: {include: {bar: v}}},
134
+ ];
135
+ clauses.forEach(c => expect(throwable(c)).to.throw(error));
136
+ };
137
+ testOf('');
138
+ testOf(10);
139
+ testOf(0);
140
+ testOf(true);
141
+ testOf(false);
142
+ testOf(() => undefined);
143
+ });
144
+
145
+ it('throws an error for duplicates', function () {
146
+ const validate = v => () => IncludeClauseTool.normalizeIncludeClause(v);
147
+ const error = 'The provided option "include" has duplicates of "foo".';
148
+ const clauses = [
149
+ ['foo', 'foo'],
150
+ [['foo'], 'foo'],
151
+ ['foo', ['foo']],
152
+ [['foo'], ['foo']],
153
+ ['foo', {foo: 'bar'}],
154
+ [{foo: 'bar'}, 'foo'],
155
+ [{foo: 'bar'}, {foo: 'bar'}],
156
+ [[{foo: 'bar'}], 'foo'],
157
+ ['foo', [{foo: 'bar'}]],
158
+ [[{foo: 'bar'}], [{foo: 'bar'}]],
159
+ ];
160
+ clauses.forEach(c => expect(validate(c)).to.throw(error));
161
+ validate({foo: 'foo'})();
162
+ validate([{foo: 'foo'}])();
163
+ });
164
+
165
+ it('normalizes the given string', function () {
103
166
  const result = IncludeClauseTool.normalizeIncludeClause('test');
104
167
  expect(result).to.be.eql([{relation: 'test'}]);
105
168
  });
106
169
 
107
- it('normalizes a free-form object', function () {
108
- const result = IncludeClauseTool.normalizeIncludeClause({foo: 'bar'});
170
+ it('normalizes the given key-value object with string', function () {
171
+ const result = IncludeClauseTool.normalizeIncludeClause({
172
+ foo: 'bar',
173
+ baz: 'qux',
174
+ });
109
175
  expect(result).to.be.eql([
110
176
  {
111
177
  relation: 'foo',
@@ -117,18 +183,12 @@ describe('IncludeClauseTool', function () {
117
183
  ],
118
184
  },
119
185
  },
120
- ]);
121
- });
122
-
123
- it('normalizes a free-form object with a nested array', function () {
124
- const result = IncludeClauseTool.normalizeIncludeClause({foo: ['bar']});
125
- expect(result).to.be.eql([
126
186
  {
127
- relation: 'foo',
187
+ relation: 'baz',
128
188
  scope: {
129
189
  include: [
130
190
  {
131
- relation: 'bar',
191
+ relation: 'qux',
132
192
  },
133
193
  ],
134
194
  },
@@ -136,9 +196,40 @@ describe('IncludeClauseTool', function () {
136
196
  ]);
137
197
  });
138
198
 
139
- it('normalizes a free-form object with a nested free-form object', function () {
199
+ it('normalizes the given key-value object with undefined', function () {
200
+ const result = IncludeClauseTool.normalizeIncludeClause({
201
+ foo: undefined,
202
+ baz: undefined,
203
+ });
204
+ expect(result).to.be.eql([
205
+ {
206
+ relation: 'foo',
207
+ },
208
+ {
209
+ relation: 'baz',
210
+ },
211
+ ]);
212
+ });
213
+
214
+ it('normalizes the given key-value object with null', function () {
215
+ const result = IncludeClauseTool.normalizeIncludeClause({
216
+ foo: null,
217
+ baz: null,
218
+ });
219
+ expect(result).to.be.eql([
220
+ {
221
+ relation: 'foo',
222
+ },
223
+ {
224
+ relation: 'baz',
225
+ },
226
+ ]);
227
+ });
228
+
229
+ it('normalizes the given key-value object with a key-value object with string', function () {
140
230
  const result = IncludeClauseTool.normalizeIncludeClause({
141
231
  foo: {bar: 'baz'},
232
+ qwe: {asd: 'zxc'},
142
233
  });
143
234
  expect(result).to.be.eql([
144
235
  {
@@ -158,31 +249,16 @@ describe('IncludeClauseTool', function () {
158
249
  ],
159
250
  },
160
251
  },
161
- ]);
162
- });
163
-
164
- it('normalizes a free-form object with a nested inclusion object', function () {
165
- const result = IncludeClauseTool.normalizeIncludeClause({
166
- foo: {
167
- relation: 'bar',
168
- scope: {
169
- where: {baz: 'qux'},
170
- include: 'baz',
171
- },
172
- },
173
- });
174
- expect(result).to.be.eql([
175
252
  {
176
- relation: 'foo',
253
+ relation: 'qwe',
177
254
  scope: {
178
255
  include: [
179
256
  {
180
- relation: 'bar',
257
+ relation: 'asd',
181
258
  scope: {
182
- where: {baz: 'qux'},
183
259
  include: [
184
260
  {
185
- relation: 'baz',
261
+ relation: 'zxc',
186
262
  },
187
263
  ],
188
264
  },
@@ -193,27 +269,15 @@ describe('IncludeClauseTool', function () {
193
269
  ]);
194
270
  });
195
271
 
196
- it('normalizes an inclusion object', function () {
272
+ it('normalizes the given key-value object with a key-value object with undefined', function () {
197
273
  const result = IncludeClauseTool.normalizeIncludeClause({
198
- relation: 'foo',
199
- scope: {
200
- where: {featured: true},
201
- order: 'id',
202
- skip: 5,
203
- limit: 10,
204
- fields: 'id',
205
- include: 'bar',
206
- },
274
+ foo: {bar: undefined},
275
+ qwe: {asd: undefined},
207
276
  });
208
277
  expect(result).to.be.eql([
209
278
  {
210
279
  relation: 'foo',
211
280
  scope: {
212
- where: {featured: true},
213
- order: 'id',
214
- skip: 5,
215
- limit: 10,
216
- fields: 'id',
217
281
  include: [
218
282
  {
219
283
  relation: 'bar',
@@ -221,30 +285,28 @@ describe('IncludeClauseTool', function () {
221
285
  ],
222
286
  },
223
287
  },
288
+ {
289
+ relation: 'qwe',
290
+ scope: {
291
+ include: [
292
+ {
293
+ relation: 'asd',
294
+ },
295
+ ],
296
+ },
297
+ },
224
298
  ]);
225
299
  });
226
300
 
227
- it('normalizes an inclusion object with a nested array', function () {
301
+ it('normalizes the given key-value object with a key-value object with null', function () {
228
302
  const result = IncludeClauseTool.normalizeIncludeClause({
229
- relation: 'foo',
230
- scope: {
231
- where: {featured: true},
232
- order: 'id',
233
- skip: 5,
234
- limit: 10,
235
- fields: 'id',
236
- include: ['bar'],
237
- },
303
+ foo: {bar: null},
304
+ qwe: {asd: null},
238
305
  });
239
306
  expect(result).to.be.eql([
240
307
  {
241
308
  relation: 'foo',
242
309
  scope: {
243
- where: {featured: true},
244
- order: 'id',
245
- skip: 5,
246
- limit: 10,
247
- fields: 'id',
248
310
  include: [
249
311
  {
250
312
  relation: 'bar',
@@ -252,40 +314,47 @@ describe('IncludeClauseTool', function () {
252
314
  ],
253
315
  },
254
316
  },
317
+ {
318
+ relation: 'qwe',
319
+ scope: {
320
+ include: [
321
+ {
322
+ relation: 'asd',
323
+ },
324
+ ],
325
+ },
326
+ },
255
327
  ]);
256
328
  });
257
329
 
258
- it('normalizes an inclusion object with a nested free-form object', function () {
330
+ it('normalizes the given key-value object with an array of strings', function () {
259
331
  const result = IncludeClauseTool.normalizeIncludeClause({
260
- relation: 'foo',
261
- scope: {
262
- where: {featured: true},
263
- order: 'id',
264
- skip: 5,
265
- limit: 10,
266
- fields: 'id',
267
- include: {bar: 'baz'},
268
- },
332
+ foo: ['bar', 'baz'],
333
+ qwe: ['asd', 'zxc'],
269
334
  });
270
335
  expect(result).to.be.eql([
271
336
  {
272
337
  relation: 'foo',
273
338
  scope: {
274
- where: {featured: true},
275
- order: 'id',
276
- skip: 5,
277
- limit: 10,
278
- fields: 'id',
279
339
  include: [
280
340
  {
281
341
  relation: 'bar',
282
- scope: {
283
- include: [
284
- {
285
- relation: 'baz',
286
- },
287
- ],
288
- },
342
+ },
343
+ {
344
+ relation: 'baz',
345
+ },
346
+ ],
347
+ },
348
+ },
349
+ {
350
+ relation: 'qwe',
351
+ scope: {
352
+ include: [
353
+ {
354
+ relation: 'asd',
355
+ },
356
+ {
357
+ relation: 'zxc',
289
358
  },
290
359
  ],
291
360
  },
@@ -293,51 +362,32 @@ describe('IncludeClauseTool', function () {
293
362
  ]);
294
363
  });
295
364
 
296
- it('normalizes an inclusion object with a nested inclusion object', function () {
365
+ it('normalizes the given key-value object with an array of key-value objects with string', function () {
297
366
  const result = IncludeClauseTool.normalizeIncludeClause({
298
- relation: 'foo',
299
- scope: {
300
- where: {featured: true},
301
- order: 'id',
302
- skip: 5,
303
- limit: 10,
304
- fields: 'id',
305
- include: [
306
- {
307
- relation: 'bar',
308
- scope: {
309
- where: {removed: false},
310
- order: 'myId',
311
- skip: 10,
312
- limit: 5,
313
- fields: ['id', 'removed'],
314
- include: 'qwe',
315
- },
316
- },
317
- ],
318
- },
367
+ foo: [{bar: 'baz'}, {qwe: 'asd'}],
368
+ ewq: [{dsa: 'cxz'}, {rty: 'fgh'}],
319
369
  });
320
370
  expect(result).to.be.eql([
321
371
  {
322
372
  relation: 'foo',
323
373
  scope: {
324
- where: {featured: true},
325
- order: 'id',
326
- skip: 5,
327
- limit: 10,
328
- fields: 'id',
329
374
  include: [
330
375
  {
331
376
  relation: 'bar',
332
377
  scope: {
333
- where: {removed: false},
334
- order: 'myId',
335
- skip: 10,
336
- limit: 5,
337
- fields: ['id', 'removed'],
338
378
  include: [
339
379
  {
340
- relation: 'qwe',
380
+ relation: 'baz',
381
+ },
382
+ ],
383
+ },
384
+ },
385
+ {
386
+ relation: 'qwe',
387
+ scope: {
388
+ include: [
389
+ {
390
+ relation: 'asd',
341
391
  },
342
392
  ],
343
393
  },
@@ -345,26 +395,41 @@ describe('IncludeClauseTool', function () {
345
395
  ],
346
396
  },
347
397
  },
348
- ]);
349
- });
350
-
351
- it('normalizes an array of strings', function () {
352
- const result = IncludeClauseTool.normalizeIncludeClause(['foo', 'bar']);
353
- expect(result).to.be.eql([
354
- {
355
- relation: 'foo',
356
- },
357
398
  {
358
- relation: 'bar',
399
+ relation: 'ewq',
400
+ scope: {
401
+ include: [
402
+ {
403
+ relation: 'dsa',
404
+ scope: {
405
+ include: [
406
+ {
407
+ relation: 'cxz',
408
+ },
409
+ ],
410
+ },
411
+ },
412
+ {
413
+ relation: 'rty',
414
+ scope: {
415
+ include: [
416
+ {
417
+ relation: 'fgh',
418
+ },
419
+ ],
420
+ },
421
+ },
422
+ ],
423
+ },
359
424
  },
360
425
  ]);
361
426
  });
362
427
 
363
- it('normalizes an array of nested free-form objects', function () {
364
- const result = IncludeClauseTool.normalizeIncludeClause([
365
- {foo: 'bar'},
366
- {baz: 'qux'},
367
- ]);
428
+ it('normalizes the given key-value object with an array of key-value objects with undefined', function () {
429
+ const result = IncludeClauseTool.normalizeIncludeClause({
430
+ foo: [{bar: undefined}, {qwe: undefined}],
431
+ ewq: [{dsa: undefined}, {rty: undefined}],
432
+ });
368
433
  expect(result).to.be.eql([
369
434
  {
370
435
  relation: 'foo',
@@ -373,15 +438,21 @@ describe('IncludeClauseTool', function () {
373
438
  {
374
439
  relation: 'bar',
375
440
  },
441
+ {
442
+ relation: 'qwe',
443
+ },
376
444
  ],
377
445
  },
378
446
  },
379
447
  {
380
- relation: 'baz',
448
+ relation: 'ewq',
381
449
  scope: {
382
450
  include: [
383
451
  {
384
- relation: 'qux',
452
+ relation: 'dsa',
453
+ },
454
+ {
455
+ relation: 'rty',
385
456
  },
386
457
  ],
387
458
  },
@@ -389,113 +460,253 @@ describe('IncludeClauseTool', function () {
389
460
  ]);
390
461
  });
391
462
 
392
- it('normalizes an array of nested inclusion objects', function () {
393
- const result = IncludeClauseTool.normalizeIncludeClause([
463
+ it('normalizes the given key-value object with an array of key-value objects with null', function () {
464
+ const result = IncludeClauseTool.normalizeIncludeClause({
465
+ foo: [{bar: null}, {qwe: null}],
466
+ ewq: [{dsa: null}, {rty: null}],
467
+ });
468
+ expect(result).to.be.eql([
394
469
  {
395
470
  relation: 'foo',
396
471
  scope: {
397
- where: {featured: true},
398
- order: 'id',
399
- skip: 5,
400
- limit: 10,
401
- fields: 'id',
402
- include: 'bar',
472
+ include: [
473
+ {
474
+ relation: 'bar',
475
+ },
476
+ {
477
+ relation: 'qwe',
478
+ },
479
+ ],
403
480
  },
404
481
  },
405
482
  {
406
- relation: 'baz',
407
- },
408
- ]);
409
- expect(result).to.be.eql([
410
- {
411
- relation: 'foo',
483
+ relation: 'ewq',
412
484
  scope: {
413
- where: {featured: true},
414
- order: 'id',
415
- skip: 5,
416
- limit: 10,
417
- fields: 'id',
418
485
  include: [
419
486
  {
420
- relation: 'bar',
487
+ relation: 'dsa',
488
+ },
489
+ {
490
+ relation: 'rty',
421
491
  },
422
492
  ],
423
493
  },
424
494
  },
425
- {
426
- relation: 'baz',
427
- },
428
495
  ]);
429
496
  });
430
497
 
431
- it('normalizes an array of nested arrays', function () {
432
- const result = IncludeClauseTool.normalizeIncludeClause([
433
- ['foo'],
434
- ['bar', ['baz']],
435
- ]);
498
+ it('normalizes the given key-value object with an array of key-value objects with an array of strings', function () {
499
+ const result = IncludeClauseTool.normalizeIncludeClause({
500
+ foo: [{bar: ['baz', 'qux']}, {qwe: ['asd', 'zxc']}],
501
+ ewq: [{dsa: ['cxz', 'rty']}, {fgh: ['vbn', 'uio']}],
502
+ });
436
503
  expect(result).to.be.eql([
437
504
  {
438
505
  relation: 'foo',
506
+ scope: {
507
+ include: [
508
+ {
509
+ relation: 'bar',
510
+ scope: {
511
+ include: [
512
+ {
513
+ relation: 'baz',
514
+ },
515
+ {
516
+ relation: 'qux',
517
+ },
518
+ ],
519
+ },
520
+ },
521
+ {
522
+ relation: 'qwe',
523
+ scope: {
524
+ include: [
525
+ {
526
+ relation: 'asd',
527
+ },
528
+ {
529
+ relation: 'zxc',
530
+ },
531
+ ],
532
+ },
533
+ },
534
+ ],
535
+ },
439
536
  },
440
537
  {
441
- relation: 'bar',
442
- },
443
- {
444
- relation: 'baz',
538
+ relation: 'ewq',
539
+ scope: {
540
+ include: [
541
+ {
542
+ relation: 'dsa',
543
+ scope: {
544
+ include: [
545
+ {
546
+ relation: 'cxz',
547
+ },
548
+ {
549
+ relation: 'rty',
550
+ },
551
+ ],
552
+ },
553
+ },
554
+ {
555
+ relation: 'fgh',
556
+ scope: {
557
+ include: [
558
+ {
559
+ relation: 'vbn',
560
+ },
561
+ {
562
+ relation: 'uio',
563
+ },
564
+ ],
565
+ },
566
+ },
567
+ ],
568
+ },
445
569
  },
446
570
  ]);
447
571
  });
448
572
 
449
- it('normalizes a free-form object with mixed inclusions', function () {
573
+ it('normalizes the given key-value object with an inclusion object with string', function () {
450
574
  const result = IncludeClauseTool.normalizeIncludeClause({
451
- // a string
452
- foo: 'bar',
453
- // an array
454
- baz: ['qux'],
455
- // a free-form object
456
- bat: {qwe: 'asd'},
457
- // an inclusion object
458
- zxc: {
459
- relation: 'rty',
575
+ foo: {
576
+ relation: 'bar',
577
+ scope: {
578
+ where: {featured: true},
579
+ order: 'id DESC',
580
+ skip: 0,
581
+ limit: 10,
582
+ fields: 'barId',
583
+ include: 'baz',
584
+ },
585
+ },
586
+ qwe: {
587
+ relation: 'asd',
460
588
  scope: {
461
- fields: ['id', 'featured'],
589
+ where: {removed: false},
590
+ order: 'createdAt DESC',
591
+ skip: 10,
592
+ limit: 0,
593
+ fields: 'asdId',
594
+ include: 'zxc',
462
595
  },
463
596
  },
464
597
  });
465
598
  expect(result).to.be.eql([
466
- // a string
467
599
  {
468
600
  relation: 'foo',
469
601
  scope: {
470
602
  include: [
471
603
  {
472
604
  relation: 'bar',
605
+ scope: {
606
+ where: {featured: true},
607
+ order: 'id DESC',
608
+ skip: 0,
609
+ limit: 10,
610
+ fields: 'barId',
611
+ include: [
612
+ {
613
+ relation: 'baz',
614
+ },
615
+ ],
616
+ },
473
617
  },
474
618
  ],
475
619
  },
476
620
  },
477
- // an array
478
621
  {
479
- relation: 'baz',
622
+ relation: 'qwe',
480
623
  scope: {
481
624
  include: [
482
625
  {
483
- relation: 'qux',
626
+ relation: 'asd',
627
+ scope: {
628
+ where: {removed: false},
629
+ order: 'createdAt DESC',
630
+ skip: 10,
631
+ limit: 0,
632
+ fields: 'asdId',
633
+ include: [
634
+ {
635
+ relation: 'zxc',
636
+ },
637
+ ],
638
+ },
484
639
  },
485
640
  ],
486
641
  },
487
642
  },
488
- // a free-form object
643
+ ]);
644
+ });
645
+
646
+ it('normalizes the given key-value object with an inclusion object with a key-value object with string', function () {
647
+ const result = IncludeClauseTool.normalizeIncludeClause({
648
+ foo: {
649
+ relation: 'bar',
650
+ scope: {
651
+ where: {featured: true},
652
+ order: 'id DESC',
653
+ skip: 0,
654
+ limit: 10,
655
+ fields: 'barId',
656
+ include: {
657
+ baz: 'qux',
658
+ ewq: 'dsa',
659
+ },
660
+ },
661
+ },
662
+ qwe: {
663
+ relation: 'asd',
664
+ scope: {
665
+ where: {removed: false},
666
+ order: 'createdAt DESC',
667
+ skip: 10,
668
+ limit: 0,
669
+ fields: 'asdId',
670
+ include: {
671
+ zxc: 'rty',
672
+ fgh: 'vbn',
673
+ },
674
+ },
675
+ },
676
+ });
677
+ expect(result).to.be.eql([
489
678
  {
490
- relation: 'bat',
679
+ relation: 'foo',
491
680
  scope: {
492
681
  include: [
493
682
  {
494
- relation: 'qwe',
683
+ relation: 'bar',
495
684
  scope: {
685
+ where: {featured: true},
686
+ order: 'id DESC',
687
+ skip: 0,
688
+ limit: 10,
689
+ fields: 'barId',
496
690
  include: [
497
691
  {
498
- relation: 'asd',
692
+ relation: 'baz',
693
+ scope: {
694
+ include: [
695
+ {
696
+ relation: 'qux',
697
+ },
698
+ ],
699
+ },
700
+ },
701
+ {
702
+ relation: 'ewq',
703
+ scope: {
704
+ include: [
705
+ {
706
+ relation: 'dsa',
707
+ },
708
+ ],
709
+ },
499
710
  },
500
711
  ],
501
712
  },
@@ -503,15 +714,40 @@ describe('IncludeClauseTool', function () {
503
714
  ],
504
715
  },
505
716
  },
506
- // an inclusion object
507
717
  {
508
- relation: 'zxc',
718
+ relation: 'qwe',
509
719
  scope: {
510
720
  include: [
511
721
  {
512
- relation: 'rty',
722
+ relation: 'asd',
513
723
  scope: {
514
- fields: ['id', 'featured'],
724
+ where: {removed: false},
725
+ order: 'createdAt DESC',
726
+ skip: 10,
727
+ limit: 0,
728
+ fields: 'asdId',
729
+ include: [
730
+ {
731
+ relation: 'zxc',
732
+ scope: {
733
+ include: [
734
+ {
735
+ relation: 'rty',
736
+ },
737
+ ],
738
+ },
739
+ },
740
+ {
741
+ relation: 'fgh',
742
+ scope: {
743
+ include: [
744
+ {
745
+ relation: 'vbn',
746
+ },
747
+ ],
748
+ },
749
+ },
750
+ ],
515
751
  },
516
752
  },
517
753
  ],
@@ -520,134 +756,3998 @@ describe('IncludeClauseTool', function () {
520
756
  ]);
521
757
  });
522
758
 
523
- it('normalizes an array with mixed inclusions', function () {
524
- const result = IncludeClauseTool.normalizeIncludeClause([
525
- // a string
526
- 'foo',
527
- // a free-form object
528
- {
529
- bar: 'baz',
530
- qux: {
531
- relation: 'qwe',
759
+ it('normalizes the given key-value object with an inclusion object with a key-value object with undefined', function () {
760
+ const result = IncludeClauseTool.normalizeIncludeClause({
761
+ foo: {
762
+ relation: 'bar',
763
+ scope: {
764
+ where: {featured: true},
765
+ order: 'id DESC',
766
+ skip: 0,
767
+ limit: 10,
768
+ fields: 'barId',
769
+ include: {
770
+ baz: undefined,
771
+ ewq: undefined,
772
+ },
532
773
  },
533
774
  },
534
- // an inclusion object
535
- {
775
+ qwe: {
536
776
  relation: 'asd',
537
777
  scope: {
538
- include: 'zxc',
778
+ where: {removed: false},
779
+ order: 'createdAt DESC',
780
+ skip: 10,
781
+ limit: 0,
782
+ fields: 'asdId',
783
+ include: {
784
+ zxc: undefined,
785
+ fgh: undefined,
786
+ },
539
787
  },
540
788
  },
541
- // a nested array
542
- ['rty', 'fgh', ['vbn']],
543
- ]);
789
+ });
544
790
  expect(result).to.be.eql([
545
- // a string
546
791
  {
547
792
  relation: 'foo',
548
- },
549
- // a free-form object
550
- {
551
- relation: 'bar',
552
793
  scope: {
553
794
  include: [
554
795
  {
555
- relation: 'baz',
796
+ relation: 'bar',
797
+ scope: {
798
+ where: {featured: true},
799
+ order: 'id DESC',
800
+ skip: 0,
801
+ limit: 10,
802
+ fields: 'barId',
803
+ include: [
804
+ {
805
+ relation: 'baz',
806
+ },
807
+ {
808
+ relation: 'ewq',
809
+ },
810
+ ],
811
+ },
556
812
  },
557
813
  ],
558
814
  },
559
815
  },
560
816
  {
561
- relation: 'qux',
817
+ relation: 'qwe',
562
818
  scope: {
563
819
  include: [
564
820
  {
565
- relation: 'qwe',
821
+ relation: 'asd',
822
+ scope: {
823
+ where: {removed: false},
824
+ order: 'createdAt DESC',
825
+ skip: 10,
826
+ limit: 0,
827
+ fields: 'asdId',
828
+ include: [
829
+ {
830
+ relation: 'zxc',
831
+ },
832
+ {
833
+ relation: 'fgh',
834
+ },
835
+ ],
836
+ },
566
837
  },
567
838
  ],
568
839
  },
569
840
  },
570
- // an inclusion object
571
- {
841
+ ]);
842
+ });
843
+
844
+ it('normalizes the given key-value object with an inclusion object with a key-value object with null', function () {
845
+ const result = IncludeClauseTool.normalizeIncludeClause({
846
+ foo: {
847
+ relation: 'bar',
848
+ scope: {
849
+ where: {featured: true},
850
+ order: 'id DESC',
851
+ skip: 0,
852
+ limit: 10,
853
+ fields: 'barId',
854
+ include: {
855
+ baz: null,
856
+ ewq: null,
857
+ },
858
+ },
859
+ },
860
+ qwe: {
572
861
  relation: 'asd',
862
+ scope: {
863
+ where: {removed: false},
864
+ order: 'createdAt DESC',
865
+ skip: 10,
866
+ limit: 0,
867
+ fields: 'asdId',
868
+ include: {
869
+ zxc: null,
870
+ fgh: null,
871
+ },
872
+ },
873
+ },
874
+ });
875
+ expect(result).to.be.eql([
876
+ {
877
+ relation: 'foo',
573
878
  scope: {
574
879
  include: [
575
880
  {
576
- relation: 'zxc',
881
+ relation: 'bar',
882
+ scope: {
883
+ where: {featured: true},
884
+ order: 'id DESC',
885
+ skip: 0,
886
+ limit: 10,
887
+ fields: 'barId',
888
+ include: [
889
+ {
890
+ relation: 'baz',
891
+ },
892
+ {
893
+ relation: 'ewq',
894
+ },
895
+ ],
896
+ },
577
897
  },
578
898
  ],
579
899
  },
580
900
  },
581
- // a nested array
582
- {
583
- relation: 'rty',
584
- },
585
- {
586
- relation: 'fgh',
587
- },
588
901
  {
589
- relation: 'vbn',
902
+ relation: 'qwe',
903
+ scope: {
904
+ include: [
905
+ {
906
+ relation: 'asd',
907
+ scope: {
908
+ where: {removed: false},
909
+ order: 'createdAt DESC',
910
+ skip: 10,
911
+ limit: 0,
912
+ fields: 'asdId',
913
+ include: [
914
+ {
915
+ relation: 'zxc',
916
+ },
917
+ {
918
+ relation: 'fgh',
919
+ },
920
+ ],
921
+ },
922
+ },
923
+ ],
924
+ },
590
925
  },
591
926
  ]);
592
927
  });
593
928
 
594
- it('throws an error for unsupported values', function () {
595
- const validate = v => () => IncludeClauseTool.normalizeIncludeClause(v);
596
- const createError = v =>
597
- format(
598
- 'The provided option "include" should have a value of ' +
599
- 'following types: String, Object or Array, but %v given.',
600
- v,
601
- );
602
- const testFor = v => {
603
- const error = createError(v);
604
- const clauses = [
605
- v,
606
- // arrays
607
- [v],
608
- [{foo: v}],
609
- [{foo: [v]}],
610
- [{foo: {bar: v}}],
611
- [{foo: {bar: [v]}}],
612
- [{foo: [{bar: v}]}],
613
- [{foo: [{bar: [v]}]}],
614
- [{relation: 'foo', scope: {include: v}}],
615
- [{relation: 'foo', scope: {include: {bar: v}}}],
616
- // objects
617
- {foo: v},
618
- {foo: [v]},
619
- {foo: {bar: v}},
620
- {foo: {bar: [v]}},
621
- {foo: [{bar: v}]},
622
- {foo: [{bar: [v]}]},
623
- {relation: 'foo', scope: {include: v}},
624
- {relation: 'foo', scope: {include: {bar: v}}},
625
- ];
626
- clauses.forEach(c => expect(validate(c)).to.throw(error));
627
- };
628
- testFor(10);
629
- testFor(true);
630
- testFor(() => undefined);
929
+ it('normalizes the given key-value object with an inclusion object with an array of strings', function () {
930
+ const result = IncludeClauseTool.normalizeIncludeClause({
931
+ foo: {
932
+ relation: 'bar',
933
+ scope: {
934
+ where: {featured: true},
935
+ order: 'id DESC',
936
+ skip: 0,
937
+ limit: 10,
938
+ fields: 'barId',
939
+ include: ['baz', 'qux'],
940
+ },
941
+ },
942
+ qwe: {
943
+ relation: 'asd',
944
+ scope: {
945
+ where: {removed: false},
946
+ order: 'createdAt DESC',
947
+ skip: 10,
948
+ limit: 0,
949
+ fields: 'asdId',
950
+ include: ['zxc', 'rty'],
951
+ },
952
+ },
953
+ });
954
+ expect(result).to.be.eql([
955
+ {
956
+ relation: 'foo',
957
+ scope: {
958
+ include: [
959
+ {
960
+ relation: 'bar',
961
+ scope: {
962
+ where: {featured: true},
963
+ order: 'id DESC',
964
+ skip: 0,
965
+ limit: 10,
966
+ fields: 'barId',
967
+ include: [
968
+ {
969
+ relation: 'baz',
970
+ },
971
+ {
972
+ relation: 'qux',
973
+ },
974
+ ],
975
+ },
976
+ },
977
+ ],
978
+ },
979
+ },
980
+ {
981
+ relation: 'qwe',
982
+ scope: {
983
+ include: [
984
+ {
985
+ relation: 'asd',
986
+ scope: {
987
+ where: {removed: false},
988
+ order: 'createdAt DESC',
989
+ skip: 10,
990
+ limit: 0,
991
+ fields: 'asdId',
992
+ include: [
993
+ {
994
+ relation: 'zxc',
995
+ },
996
+ {
997
+ relation: 'rty',
998
+ },
999
+ ],
1000
+ },
1001
+ },
1002
+ ],
1003
+ },
1004
+ },
1005
+ ]);
1006
+ });
1007
+
1008
+ it('normalizes the given key-value object with an inclusion object with an array of key-value objects with string', function () {
1009
+ const result = IncludeClauseTool.normalizeIncludeClause({
1010
+ foo: {
1011
+ relation: 'bar',
1012
+ scope: {
1013
+ where: {featured: true},
1014
+ order: 'id DESC',
1015
+ skip: 0,
1016
+ limit: 10,
1017
+ fields: 'barId',
1018
+ include: {
1019
+ baz: 'qux',
1020
+ ewq: 'dsa',
1021
+ },
1022
+ },
1023
+ },
1024
+ qwe: {
1025
+ relation: 'asd',
1026
+ scope: {
1027
+ where: {removed: false},
1028
+ order: 'createdAt DESC',
1029
+ skip: 10,
1030
+ limit: 0,
1031
+ fields: 'asdId',
1032
+ include: {
1033
+ zxc: 'rty',
1034
+ fgh: 'vbn',
1035
+ },
1036
+ },
1037
+ },
1038
+ });
1039
+ expect(result).to.be.eql([
1040
+ {
1041
+ relation: 'foo',
1042
+ scope: {
1043
+ include: [
1044
+ {
1045
+ relation: 'bar',
1046
+ scope: {
1047
+ where: {featured: true},
1048
+ order: 'id DESC',
1049
+ skip: 0,
1050
+ limit: 10,
1051
+ fields: 'barId',
1052
+ include: [
1053
+ {
1054
+ relation: 'baz',
1055
+ scope: {
1056
+ include: [
1057
+ {
1058
+ relation: 'qux',
1059
+ },
1060
+ ],
1061
+ },
1062
+ },
1063
+ {
1064
+ relation: 'ewq',
1065
+ scope: {
1066
+ include: [
1067
+ {
1068
+ relation: 'dsa',
1069
+ },
1070
+ ],
1071
+ },
1072
+ },
1073
+ ],
1074
+ },
1075
+ },
1076
+ ],
1077
+ },
1078
+ },
1079
+ {
1080
+ relation: 'qwe',
1081
+ scope: {
1082
+ include: [
1083
+ {
1084
+ relation: 'asd',
1085
+ scope: {
1086
+ where: {removed: false},
1087
+ order: 'createdAt DESC',
1088
+ skip: 10,
1089
+ limit: 0,
1090
+ fields: 'asdId',
1091
+ include: [
1092
+ {
1093
+ relation: 'zxc',
1094
+ scope: {
1095
+ include: [
1096
+ {
1097
+ relation: 'rty',
1098
+ },
1099
+ ],
1100
+ },
1101
+ },
1102
+ {
1103
+ relation: 'fgh',
1104
+ scope: {
1105
+ include: [
1106
+ {
1107
+ relation: 'vbn',
1108
+ },
1109
+ ],
1110
+ },
1111
+ },
1112
+ ],
1113
+ },
1114
+ },
1115
+ ],
1116
+ },
1117
+ },
1118
+ ]);
1119
+ });
1120
+
1121
+ it('normalizes the given key-value object with an inclusion object with an array of key-value objects with undefined', function () {
1122
+ const result = IncludeClauseTool.normalizeIncludeClause({
1123
+ foo: {
1124
+ relation: 'bar',
1125
+ scope: {
1126
+ where: {featured: true},
1127
+ order: 'id DESC',
1128
+ skip: 0,
1129
+ limit: 10,
1130
+ fields: 'barId',
1131
+ include: {
1132
+ baz: undefined,
1133
+ ewq: undefined,
1134
+ },
1135
+ },
1136
+ },
1137
+ qwe: {
1138
+ relation: 'asd',
1139
+ scope: {
1140
+ where: {removed: false},
1141
+ order: 'createdAt DESC',
1142
+ skip: 10,
1143
+ limit: 0,
1144
+ fields: 'asdId',
1145
+ include: {
1146
+ zxc: undefined,
1147
+ fgh: undefined,
1148
+ },
1149
+ },
1150
+ },
1151
+ });
1152
+ expect(result).to.be.eql([
1153
+ {
1154
+ relation: 'foo',
1155
+ scope: {
1156
+ include: [
1157
+ {
1158
+ relation: 'bar',
1159
+ scope: {
1160
+ where: {featured: true},
1161
+ order: 'id DESC',
1162
+ skip: 0,
1163
+ limit: 10,
1164
+ fields: 'barId',
1165
+ include: [
1166
+ {
1167
+ relation: 'baz',
1168
+ },
1169
+ {
1170
+ relation: 'ewq',
1171
+ },
1172
+ ],
1173
+ },
1174
+ },
1175
+ ],
1176
+ },
1177
+ },
1178
+ {
1179
+ relation: 'qwe',
1180
+ scope: {
1181
+ include: [
1182
+ {
1183
+ relation: 'asd',
1184
+ scope: {
1185
+ where: {removed: false},
1186
+ order: 'createdAt DESC',
1187
+ skip: 10,
1188
+ limit: 0,
1189
+ fields: 'asdId',
1190
+ include: [
1191
+ {
1192
+ relation: 'zxc',
1193
+ },
1194
+ {
1195
+ relation: 'fgh',
1196
+ },
1197
+ ],
1198
+ },
1199
+ },
1200
+ ],
1201
+ },
1202
+ },
1203
+ ]);
1204
+ });
1205
+
1206
+ it('normalizes the given key-value object with an inclusion object with an array of key-value objects with null', function () {
1207
+ const result = IncludeClauseTool.normalizeIncludeClause({
1208
+ foo: {
1209
+ relation: 'bar',
1210
+ scope: {
1211
+ where: {featured: true},
1212
+ order: 'id DESC',
1213
+ skip: 0,
1214
+ limit: 10,
1215
+ fields: 'barId',
1216
+ include: {
1217
+ baz: null,
1218
+ ewq: null,
1219
+ },
1220
+ },
1221
+ },
1222
+ qwe: {
1223
+ relation: 'asd',
1224
+ scope: {
1225
+ where: {removed: false},
1226
+ order: 'createdAt DESC',
1227
+ skip: 10,
1228
+ limit: 0,
1229
+ fields: 'asdId',
1230
+ include: {
1231
+ zxc: null,
1232
+ fgh: null,
1233
+ },
1234
+ },
1235
+ },
1236
+ });
1237
+ expect(result).to.be.eql([
1238
+ {
1239
+ relation: 'foo',
1240
+ scope: {
1241
+ include: [
1242
+ {
1243
+ relation: 'bar',
1244
+ scope: {
1245
+ where: {featured: true},
1246
+ order: 'id DESC',
1247
+ skip: 0,
1248
+ limit: 10,
1249
+ fields: 'barId',
1250
+ include: [
1251
+ {
1252
+ relation: 'baz',
1253
+ },
1254
+ {
1255
+ relation: 'ewq',
1256
+ },
1257
+ ],
1258
+ },
1259
+ },
1260
+ ],
1261
+ },
1262
+ },
1263
+ {
1264
+ relation: 'qwe',
1265
+ scope: {
1266
+ include: [
1267
+ {
1268
+ relation: 'asd',
1269
+ scope: {
1270
+ where: {removed: false},
1271
+ order: 'createdAt DESC',
1272
+ skip: 10,
1273
+ limit: 0,
1274
+ fields: 'asdId',
1275
+ include: [
1276
+ {
1277
+ relation: 'zxc',
1278
+ },
1279
+ {
1280
+ relation: 'fgh',
1281
+ },
1282
+ ],
1283
+ },
1284
+ },
1285
+ ],
1286
+ },
1287
+ },
1288
+ ]);
1289
+ });
1290
+
1291
+ it('normalizes the given key-value object with an inclusion object with an array of key-value objects with an array of strings', function () {
1292
+ const result = IncludeClauseTool.normalizeIncludeClause({
1293
+ foo: {
1294
+ relation: 'bar',
1295
+ scope: {
1296
+ where: {featured: true},
1297
+ order: 'id DESC',
1298
+ skip: 0,
1299
+ limit: 10,
1300
+ fields: 'barId',
1301
+ include: {
1302
+ baz: ['qux', 'xuq'],
1303
+ ewq: ['dsa', 'asd'],
1304
+ },
1305
+ },
1306
+ },
1307
+ qwe: {
1308
+ relation: 'asd',
1309
+ scope: {
1310
+ where: {removed: false},
1311
+ order: 'createdAt DESC',
1312
+ skip: 10,
1313
+ limit: 0,
1314
+ fields: 'asdId',
1315
+ include: {
1316
+ zxc: ['rty', 'ytr'],
1317
+ fgh: ['vbn', 'nbv'],
1318
+ },
1319
+ },
1320
+ },
1321
+ });
1322
+ expect(result).to.be.eql([
1323
+ {
1324
+ relation: 'foo',
1325
+ scope: {
1326
+ include: [
1327
+ {
1328
+ relation: 'bar',
1329
+ scope: {
1330
+ where: {featured: true},
1331
+ order: 'id DESC',
1332
+ skip: 0,
1333
+ limit: 10,
1334
+ fields: 'barId',
1335
+ include: [
1336
+ {
1337
+ relation: 'baz',
1338
+ scope: {
1339
+ include: [
1340
+ {
1341
+ relation: 'qux',
1342
+ },
1343
+ {
1344
+ relation: 'xuq',
1345
+ },
1346
+ ],
1347
+ },
1348
+ },
1349
+ {
1350
+ relation: 'ewq',
1351
+ scope: {
1352
+ include: [
1353
+ {
1354
+ relation: 'dsa',
1355
+ },
1356
+ {
1357
+ relation: 'asd',
1358
+ },
1359
+ ],
1360
+ },
1361
+ },
1362
+ ],
1363
+ },
1364
+ },
1365
+ ],
1366
+ },
1367
+ },
1368
+ {
1369
+ relation: 'qwe',
1370
+ scope: {
1371
+ include: [
1372
+ {
1373
+ relation: 'asd',
1374
+ scope: {
1375
+ where: {removed: false},
1376
+ order: 'createdAt DESC',
1377
+ skip: 10,
1378
+ limit: 0,
1379
+ fields: 'asdId',
1380
+ include: [
1381
+ {
1382
+ relation: 'zxc',
1383
+ scope: {
1384
+ include: [
1385
+ {
1386
+ relation: 'rty',
1387
+ },
1388
+ {
1389
+ relation: 'ytr',
1390
+ },
1391
+ ],
1392
+ },
1393
+ },
1394
+ {
1395
+ relation: 'fgh',
1396
+ scope: {
1397
+ include: [
1398
+ {
1399
+ relation: 'vbn',
1400
+ },
1401
+ {
1402
+ relation: 'nbv',
1403
+ },
1404
+ ],
1405
+ },
1406
+ },
1407
+ ],
1408
+ },
1409
+ },
1410
+ ],
1411
+ },
1412
+ },
1413
+ ]);
1414
+ });
1415
+
1416
+ it('normalizes the given inclusion object with string', function () {
1417
+ const result = IncludeClauseTool.normalizeIncludeClause({
1418
+ relation: 'foo',
1419
+ scope: {
1420
+ where: {featured: true},
1421
+ order: 'id',
1422
+ skip: 5,
1423
+ limit: 10,
1424
+ fields: 'id',
1425
+ include: 'bar',
1426
+ },
1427
+ });
1428
+ expect(result).to.be.eql([
1429
+ {
1430
+ relation: 'foo',
1431
+ scope: {
1432
+ where: {featured: true},
1433
+ order: 'id',
1434
+ skip: 5,
1435
+ limit: 10,
1436
+ fields: 'id',
1437
+ include: [
1438
+ {
1439
+ relation: 'bar',
1440
+ },
1441
+ ],
1442
+ },
1443
+ },
1444
+ ]);
1445
+ });
1446
+
1447
+ it('normalizes the given inclusion object with a key-value object with string', function () {
1448
+ const result = IncludeClauseTool.normalizeIncludeClause({
1449
+ relation: 'foo',
1450
+ scope: {
1451
+ where: {featured: true},
1452
+ order: 'id',
1453
+ skip: 5,
1454
+ limit: 10,
1455
+ fields: 'id',
1456
+ include: {
1457
+ bar: 'baz',
1458
+ qwe: 'asd',
1459
+ },
1460
+ },
1461
+ });
1462
+ expect(result).to.be.eql([
1463
+ {
1464
+ relation: 'foo',
1465
+ scope: {
1466
+ where: {featured: true},
1467
+ order: 'id',
1468
+ skip: 5,
1469
+ limit: 10,
1470
+ fields: 'id',
1471
+ include: [
1472
+ {
1473
+ relation: 'bar',
1474
+ scope: {
1475
+ include: [
1476
+ {
1477
+ relation: 'baz',
1478
+ },
1479
+ ],
1480
+ },
1481
+ },
1482
+ {
1483
+ relation: 'qwe',
1484
+ scope: {
1485
+ include: [
1486
+ {
1487
+ relation: 'asd',
1488
+ },
1489
+ ],
1490
+ },
1491
+ },
1492
+ ],
1493
+ },
1494
+ },
1495
+ ]);
1496
+ });
1497
+
1498
+ it('normalizes the given inclusion object with a key-value object with undefined', function () {
1499
+ const result = IncludeClauseTool.normalizeIncludeClause({
1500
+ relation: 'foo',
1501
+ scope: {
1502
+ where: {featured: true},
1503
+ order: 'id',
1504
+ skip: 5,
1505
+ limit: 10,
1506
+ fields: 'id',
1507
+ include: {
1508
+ bar: undefined,
1509
+ qwe: undefined,
1510
+ },
1511
+ },
1512
+ });
1513
+ expect(result).to.be.eql([
1514
+ {
1515
+ relation: 'foo',
1516
+ scope: {
1517
+ where: {featured: true},
1518
+ order: 'id',
1519
+ skip: 5,
1520
+ limit: 10,
1521
+ fields: 'id',
1522
+ include: [
1523
+ {
1524
+ relation: 'bar',
1525
+ },
1526
+ {
1527
+ relation: 'qwe',
1528
+ },
1529
+ ],
1530
+ },
1531
+ },
1532
+ ]);
1533
+ });
1534
+
1535
+ it('normalizes the given inclusion object with a key-value object with null', function () {
1536
+ const result = IncludeClauseTool.normalizeIncludeClause({
1537
+ relation: 'foo',
1538
+ scope: {
1539
+ where: {featured: true},
1540
+ order: 'id',
1541
+ skip: 5,
1542
+ limit: 10,
1543
+ fields: 'id',
1544
+ include: {
1545
+ bar: null,
1546
+ qwe: null,
1547
+ },
1548
+ },
1549
+ });
1550
+ expect(result).to.be.eql([
1551
+ {
1552
+ relation: 'foo',
1553
+ scope: {
1554
+ where: {featured: true},
1555
+ order: 'id',
1556
+ skip: 5,
1557
+ limit: 10,
1558
+ fields: 'id',
1559
+ include: [
1560
+ {
1561
+ relation: 'bar',
1562
+ },
1563
+ {
1564
+ relation: 'qwe',
1565
+ },
1566
+ ],
1567
+ },
1568
+ },
1569
+ ]);
1570
+ });
1571
+
1572
+ it('normalizes the given inclusion object with an array of strings', function () {
1573
+ const result = IncludeClauseTool.normalizeIncludeClause({
1574
+ relation: 'foo',
1575
+ scope: {
1576
+ where: {featured: true},
1577
+ order: 'id',
1578
+ skip: 5,
1579
+ limit: 10,
1580
+ fields: 'id',
1581
+ include: ['bar', 'baz'],
1582
+ },
1583
+ });
1584
+ expect(result).to.be.eql([
1585
+ {
1586
+ relation: 'foo',
1587
+ scope: {
1588
+ where: {featured: true},
1589
+ order: 'id',
1590
+ skip: 5,
1591
+ limit: 10,
1592
+ fields: 'id',
1593
+ include: [
1594
+ {
1595
+ relation: 'bar',
1596
+ },
1597
+ {
1598
+ relation: 'baz',
1599
+ },
1600
+ ],
1601
+ },
1602
+ },
1603
+ ]);
1604
+ });
1605
+
1606
+ it('normalizes the given inclusion object with an array of key-value objects with string', function () {
1607
+ const result = IncludeClauseTool.normalizeIncludeClause({
1608
+ relation: 'foo',
1609
+ scope: {
1610
+ where: {featured: true},
1611
+ order: 'id',
1612
+ skip: 5,
1613
+ limit: 10,
1614
+ fields: 'id',
1615
+ include: [{bar: 'baz'}, {qwe: 'asd'}],
1616
+ },
1617
+ });
1618
+ expect(result).to.be.eql([
1619
+ {
1620
+ relation: 'foo',
1621
+ scope: {
1622
+ where: {featured: true},
1623
+ order: 'id',
1624
+ skip: 5,
1625
+ limit: 10,
1626
+ fields: 'id',
1627
+ include: [
1628
+ {
1629
+ relation: 'bar',
1630
+ scope: {
1631
+ include: [
1632
+ {
1633
+ relation: 'baz',
1634
+ },
1635
+ ],
1636
+ },
1637
+ },
1638
+ {
1639
+ relation: 'qwe',
1640
+ scope: {
1641
+ include: [
1642
+ {
1643
+ relation: 'asd',
1644
+ },
1645
+ ],
1646
+ },
1647
+ },
1648
+ ],
1649
+ },
1650
+ },
1651
+ ]);
1652
+ });
1653
+
1654
+ it('normalizes the given inclusion object with an array of key-value objects with undefined', function () {
1655
+ const result = IncludeClauseTool.normalizeIncludeClause({
1656
+ relation: 'foo',
1657
+ scope: {
1658
+ where: {featured: true},
1659
+ order: 'id',
1660
+ skip: 5,
1661
+ limit: 10,
1662
+ fields: 'id',
1663
+ include: [{bar: undefined}, {qwe: undefined}],
1664
+ },
1665
+ });
1666
+ expect(result).to.be.eql([
1667
+ {
1668
+ relation: 'foo',
1669
+ scope: {
1670
+ where: {featured: true},
1671
+ order: 'id',
1672
+ skip: 5,
1673
+ limit: 10,
1674
+ fields: 'id',
1675
+ include: [
1676
+ {
1677
+ relation: 'bar',
1678
+ },
1679
+ {
1680
+ relation: 'qwe',
1681
+ },
1682
+ ],
1683
+ },
1684
+ },
1685
+ ]);
1686
+ });
1687
+
1688
+ it('normalizes the given inclusion object with an array of key-value objects with null', function () {
1689
+ const result = IncludeClauseTool.normalizeIncludeClause({
1690
+ relation: 'foo',
1691
+ scope: {
1692
+ where: {featured: true},
1693
+ order: 'id',
1694
+ skip: 5,
1695
+ limit: 10,
1696
+ fields: 'id',
1697
+ include: [{bar: null}, {qwe: null}],
1698
+ },
1699
+ });
1700
+ expect(result).to.be.eql([
1701
+ {
1702
+ relation: 'foo',
1703
+ scope: {
1704
+ where: {featured: true},
1705
+ order: 'id',
1706
+ skip: 5,
1707
+ limit: 10,
1708
+ fields: 'id',
1709
+ include: [
1710
+ {
1711
+ relation: 'bar',
1712
+ },
1713
+ {
1714
+ relation: 'qwe',
1715
+ },
1716
+ ],
1717
+ },
1718
+ },
1719
+ ]);
1720
+ });
1721
+
1722
+ it('normalizes the given inclusion object with an array of key-value objects with an array of strings', function () {
1723
+ const result = IncludeClauseTool.normalizeIncludeClause({
1724
+ relation: 'foo',
1725
+ scope: {
1726
+ where: {featured: true},
1727
+ order: 'id',
1728
+ skip: 5,
1729
+ limit: 10,
1730
+ fields: 'id',
1731
+ include: [{bar: ['baz', 'qux']}, {qwe: ['asd', 'zxc']}],
1732
+ },
1733
+ });
1734
+ expect(result).to.be.eql([
1735
+ {
1736
+ relation: 'foo',
1737
+ scope: {
1738
+ where: {featured: true},
1739
+ order: 'id',
1740
+ skip: 5,
1741
+ limit: 10,
1742
+ fields: 'id',
1743
+ include: [
1744
+ {
1745
+ relation: 'bar',
1746
+ scope: {
1747
+ include: [
1748
+ {
1749
+ relation: 'baz',
1750
+ },
1751
+ {
1752
+ relation: 'qux',
1753
+ },
1754
+ ],
1755
+ },
1756
+ },
1757
+ {
1758
+ relation: 'qwe',
1759
+ scope: {
1760
+ include: [
1761
+ {
1762
+ relation: 'asd',
1763
+ },
1764
+ {
1765
+ relation: 'zxc',
1766
+ },
1767
+ ],
1768
+ },
1769
+ },
1770
+ ],
1771
+ },
1772
+ },
1773
+ ]);
1774
+ });
1775
+
1776
+ it('normalizes the given inclusion object with an inclusion object with string', function () {
1777
+ const result = IncludeClauseTool.normalizeIncludeClause({
1778
+ relation: 'foo',
1779
+ scope: {
1780
+ where: {featured: true},
1781
+ order: 'id',
1782
+ skip: 5,
1783
+ limit: 10,
1784
+ fields: 'fooId',
1785
+ include: {
1786
+ relation: 'bar',
1787
+ scope: {
1788
+ where: {removed: false},
1789
+ order: 'createdAt DESC',
1790
+ skip: 0,
1791
+ limit: 0,
1792
+ fields: ['id', 'createdAt'],
1793
+ include: 'baz',
1794
+ },
1795
+ },
1796
+ },
1797
+ });
1798
+ expect(result).to.be.eql([
1799
+ {
1800
+ relation: 'foo',
1801
+ scope: {
1802
+ where: {featured: true},
1803
+ order: 'id',
1804
+ skip: 5,
1805
+ limit: 10,
1806
+ fields: 'fooId',
1807
+ include: [
1808
+ {
1809
+ relation: 'bar',
1810
+ scope: {
1811
+ where: {removed: false},
1812
+ order: 'createdAt DESC',
1813
+ skip: 0,
1814
+ limit: 0,
1815
+ fields: ['id', 'createdAt'],
1816
+ include: [
1817
+ {
1818
+ relation: 'baz',
1819
+ },
1820
+ ],
1821
+ },
1822
+ },
1823
+ ],
1824
+ },
1825
+ },
1826
+ ]);
1827
+ });
1828
+
1829
+ it('normalizes the given inclusion object with an inclusion object with a key-value object with string', function () {
1830
+ const result = IncludeClauseTool.normalizeIncludeClause({
1831
+ relation: 'foo',
1832
+ scope: {
1833
+ where: {featured: true},
1834
+ order: 'id',
1835
+ skip: 5,
1836
+ limit: 10,
1837
+ fields: 'fooId',
1838
+ include: {
1839
+ relation: 'bar',
1840
+ scope: {
1841
+ where: {removed: false},
1842
+ order: 'createdAt DESC',
1843
+ skip: 0,
1844
+ limit: 0,
1845
+ fields: ['id', 'createdAt'],
1846
+ include: {
1847
+ baz: 'qux',
1848
+ ewq: 'dsa',
1849
+ },
1850
+ },
1851
+ },
1852
+ },
1853
+ });
1854
+ expect(result).to.be.eql([
1855
+ {
1856
+ relation: 'foo',
1857
+ scope: {
1858
+ where: {featured: true},
1859
+ order: 'id',
1860
+ skip: 5,
1861
+ limit: 10,
1862
+ fields: 'fooId',
1863
+ include: [
1864
+ {
1865
+ relation: 'bar',
1866
+ scope: {
1867
+ where: {removed: false},
1868
+ order: 'createdAt DESC',
1869
+ skip: 0,
1870
+ limit: 0,
1871
+ fields: ['id', 'createdAt'],
1872
+ include: [
1873
+ {
1874
+ relation: 'baz',
1875
+ scope: {
1876
+ include: [
1877
+ {
1878
+ relation: 'qux',
1879
+ },
1880
+ ],
1881
+ },
1882
+ },
1883
+ {
1884
+ relation: 'ewq',
1885
+ scope: {
1886
+ include: [
1887
+ {
1888
+ relation: 'dsa',
1889
+ },
1890
+ ],
1891
+ },
1892
+ },
1893
+ ],
1894
+ },
1895
+ },
1896
+ ],
1897
+ },
1898
+ },
1899
+ ]);
1900
+ });
1901
+
1902
+ it('normalizes the given inclusion object with an inclusion object with a key-value object with undefined', function () {
1903
+ const result = IncludeClauseTool.normalizeIncludeClause({
1904
+ relation: 'foo',
1905
+ scope: {
1906
+ where: {featured: true},
1907
+ order: 'id',
1908
+ skip: 5,
1909
+ limit: 10,
1910
+ fields: 'fooId',
1911
+ include: {
1912
+ relation: 'bar',
1913
+ scope: {
1914
+ where: {removed: false},
1915
+ order: 'createdAt DESC',
1916
+ skip: 0,
1917
+ limit: 0,
1918
+ fields: ['id', 'createdAt'],
1919
+ include: {
1920
+ baz: undefined,
1921
+ ewq: undefined,
1922
+ },
1923
+ },
1924
+ },
1925
+ },
1926
+ });
1927
+ expect(result).to.be.eql([
1928
+ {
1929
+ relation: 'foo',
1930
+ scope: {
1931
+ where: {featured: true},
1932
+ order: 'id',
1933
+ skip: 5,
1934
+ limit: 10,
1935
+ fields: 'fooId',
1936
+ include: [
1937
+ {
1938
+ relation: 'bar',
1939
+ scope: {
1940
+ where: {removed: false},
1941
+ order: 'createdAt DESC',
1942
+ skip: 0,
1943
+ limit: 0,
1944
+ fields: ['id', 'createdAt'],
1945
+ include: [
1946
+ {
1947
+ relation: 'baz',
1948
+ },
1949
+ {
1950
+ relation: 'ewq',
1951
+ },
1952
+ ],
1953
+ },
1954
+ },
1955
+ ],
1956
+ },
1957
+ },
1958
+ ]);
1959
+ });
1960
+
1961
+ it('normalizes the given inclusion object with an inclusion object with a key-value object with null', function () {
1962
+ const result = IncludeClauseTool.normalizeIncludeClause({
1963
+ relation: 'foo',
1964
+ scope: {
1965
+ where: {featured: true},
1966
+ order: 'id',
1967
+ skip: 5,
1968
+ limit: 10,
1969
+ fields: 'fooId',
1970
+ include: {
1971
+ relation: 'bar',
1972
+ scope: {
1973
+ where: {removed: false},
1974
+ order: 'createdAt DESC',
1975
+ skip: 0,
1976
+ limit: 0,
1977
+ fields: ['id', 'createdAt'],
1978
+ include: {
1979
+ baz: null,
1980
+ ewq: null,
1981
+ },
1982
+ },
1983
+ },
1984
+ },
1985
+ });
1986
+ expect(result).to.be.eql([
1987
+ {
1988
+ relation: 'foo',
1989
+ scope: {
1990
+ where: {featured: true},
1991
+ order: 'id',
1992
+ skip: 5,
1993
+ limit: 10,
1994
+ fields: 'fooId',
1995
+ include: [
1996
+ {
1997
+ relation: 'bar',
1998
+ scope: {
1999
+ where: {removed: false},
2000
+ order: 'createdAt DESC',
2001
+ skip: 0,
2002
+ limit: 0,
2003
+ fields: ['id', 'createdAt'],
2004
+ include: [
2005
+ {
2006
+ relation: 'baz',
2007
+ },
2008
+ {
2009
+ relation: 'ewq',
2010
+ },
2011
+ ],
2012
+ },
2013
+ },
2014
+ ],
2015
+ },
2016
+ },
2017
+ ]);
2018
+ });
2019
+
2020
+ it('normalizes the given inclusion object with an inclusion object with an array of strings', function () {
2021
+ const result = IncludeClauseTool.normalizeIncludeClause({
2022
+ relation: 'foo',
2023
+ scope: {
2024
+ where: {featured: true},
2025
+ order: 'id',
2026
+ skip: 5,
2027
+ limit: 10,
2028
+ fields: 'fooId',
2029
+ include: {
2030
+ relation: 'bar',
2031
+ scope: {
2032
+ where: {removed: false},
2033
+ order: 'createdAt DESC',
2034
+ skip: 0,
2035
+ limit: 0,
2036
+ fields: ['id', 'createdAt'],
2037
+ include: ['baz', 'qux'],
2038
+ },
2039
+ },
2040
+ },
2041
+ });
2042
+ expect(result).to.be.eql([
2043
+ {
2044
+ relation: 'foo',
2045
+ scope: {
2046
+ where: {featured: true},
2047
+ order: 'id',
2048
+ skip: 5,
2049
+ limit: 10,
2050
+ fields: 'fooId',
2051
+ include: [
2052
+ {
2053
+ relation: 'bar',
2054
+ scope: {
2055
+ where: {removed: false},
2056
+ order: 'createdAt DESC',
2057
+ skip: 0,
2058
+ limit: 0,
2059
+ fields: ['id', 'createdAt'],
2060
+ include: [
2061
+ {
2062
+ relation: 'baz',
2063
+ },
2064
+ {
2065
+ relation: 'qux',
2066
+ },
2067
+ ],
2068
+ },
2069
+ },
2070
+ ],
2071
+ },
2072
+ },
2073
+ ]);
2074
+ });
2075
+
2076
+ it('normalizes the given inclusion object with an inclusion object with an array of key-value objects with string', function () {
2077
+ const result = IncludeClauseTool.normalizeIncludeClause({
2078
+ relation: 'foo',
2079
+ scope: {
2080
+ where: {featured: true},
2081
+ order: 'id',
2082
+ skip: 5,
2083
+ limit: 10,
2084
+ fields: 'fooId',
2085
+ include: {
2086
+ relation: 'bar',
2087
+ scope: {
2088
+ where: {removed: false},
2089
+ order: 'createdAt DESC',
2090
+ skip: 0,
2091
+ limit: 0,
2092
+ fields: ['id', 'createdAt'],
2093
+ include: [{baz: 'qux'}, {ewq: 'dsa'}],
2094
+ },
2095
+ },
2096
+ },
2097
+ });
2098
+ expect(result).to.be.eql([
2099
+ {
2100
+ relation: 'foo',
2101
+ scope: {
2102
+ where: {featured: true},
2103
+ order: 'id',
2104
+ skip: 5,
2105
+ limit: 10,
2106
+ fields: 'fooId',
2107
+ include: [
2108
+ {
2109
+ relation: 'bar',
2110
+ scope: {
2111
+ where: {removed: false},
2112
+ order: 'createdAt DESC',
2113
+ skip: 0,
2114
+ limit: 0,
2115
+ fields: ['id', 'createdAt'],
2116
+ include: [
2117
+ {
2118
+ relation: 'baz',
2119
+ scope: {
2120
+ include: [
2121
+ {
2122
+ relation: 'qux',
2123
+ },
2124
+ ],
2125
+ },
2126
+ },
2127
+ {
2128
+ relation: 'ewq',
2129
+ scope: {
2130
+ include: [
2131
+ {
2132
+ relation: 'dsa',
2133
+ },
2134
+ ],
2135
+ },
2136
+ },
2137
+ ],
2138
+ },
2139
+ },
2140
+ ],
2141
+ },
2142
+ },
2143
+ ]);
2144
+ });
2145
+
2146
+ it('normalizes the given inclusion object with an inclusion object with an array of key-value objects with undefined', function () {
2147
+ const result = IncludeClauseTool.normalizeIncludeClause({
2148
+ relation: 'foo',
2149
+ scope: {
2150
+ where: {featured: true},
2151
+ order: 'id',
2152
+ skip: 5,
2153
+ limit: 10,
2154
+ fields: 'fooId',
2155
+ include: {
2156
+ relation: 'bar',
2157
+ scope: {
2158
+ where: {removed: false},
2159
+ order: 'createdAt DESC',
2160
+ skip: 0,
2161
+ limit: 0,
2162
+ fields: ['id', 'createdAt'],
2163
+ include: [{baz: undefined}, {ewq: undefined}],
2164
+ },
2165
+ },
2166
+ },
2167
+ });
2168
+ expect(result).to.be.eql([
2169
+ {
2170
+ relation: 'foo',
2171
+ scope: {
2172
+ where: {featured: true},
2173
+ order: 'id',
2174
+ skip: 5,
2175
+ limit: 10,
2176
+ fields: 'fooId',
2177
+ include: [
2178
+ {
2179
+ relation: 'bar',
2180
+ scope: {
2181
+ where: {removed: false},
2182
+ order: 'createdAt DESC',
2183
+ skip: 0,
2184
+ limit: 0,
2185
+ fields: ['id', 'createdAt'],
2186
+ include: [
2187
+ {
2188
+ relation: 'baz',
2189
+ },
2190
+ {
2191
+ relation: 'ewq',
2192
+ },
2193
+ ],
2194
+ },
2195
+ },
2196
+ ],
2197
+ },
2198
+ },
2199
+ ]);
2200
+ });
2201
+
2202
+ it('normalizes the given inclusion object with an inclusion object with an array of key-value objects with null', function () {
2203
+ const result = IncludeClauseTool.normalizeIncludeClause({
2204
+ relation: 'foo',
2205
+ scope: {
2206
+ where: {featured: true},
2207
+ order: 'id',
2208
+ skip: 5,
2209
+ limit: 10,
2210
+ fields: 'fooId',
2211
+ include: {
2212
+ relation: 'bar',
2213
+ scope: {
2214
+ where: {removed: false},
2215
+ order: 'createdAt DESC',
2216
+ skip: 0,
2217
+ limit: 0,
2218
+ fields: ['id', 'createdAt'],
2219
+ include: [{baz: null}, {ewq: null}],
2220
+ },
2221
+ },
2222
+ },
2223
+ });
2224
+ expect(result).to.be.eql([
2225
+ {
2226
+ relation: 'foo',
2227
+ scope: {
2228
+ where: {featured: true},
2229
+ order: 'id',
2230
+ skip: 5,
2231
+ limit: 10,
2232
+ fields: 'fooId',
2233
+ include: [
2234
+ {
2235
+ relation: 'bar',
2236
+ scope: {
2237
+ where: {removed: false},
2238
+ order: 'createdAt DESC',
2239
+ skip: 0,
2240
+ limit: 0,
2241
+ fields: ['id', 'createdAt'],
2242
+ include: [
2243
+ {
2244
+ relation: 'baz',
2245
+ },
2246
+ {
2247
+ relation: 'ewq',
2248
+ },
2249
+ ],
2250
+ },
2251
+ },
2252
+ ],
2253
+ },
2254
+ },
2255
+ ]);
2256
+ });
2257
+
2258
+ it('normalizes the given inclusion object with an inclusion object with an array of key-value objects with an array of strings', function () {
2259
+ const result = IncludeClauseTool.normalizeIncludeClause({
2260
+ relation: 'foo',
2261
+ scope: {
2262
+ where: {featured: true},
2263
+ order: 'id',
2264
+ skip: 5,
2265
+ limit: 10,
2266
+ fields: 'fooId',
2267
+ include: {
2268
+ relation: 'bar',
2269
+ scope: {
2270
+ where: {removed: false},
2271
+ order: 'createdAt DESC',
2272
+ skip: 0,
2273
+ limit: 0,
2274
+ fields: ['id', 'createdAt'],
2275
+ include: [{baz: ['qux', 'xuq']}, {ewq: ['dsa', 'asd']}],
2276
+ },
2277
+ },
2278
+ },
2279
+ });
2280
+ expect(result).to.be.eql([
2281
+ {
2282
+ relation: 'foo',
2283
+ scope: {
2284
+ where: {featured: true},
2285
+ order: 'id',
2286
+ skip: 5,
2287
+ limit: 10,
2288
+ fields: 'fooId',
2289
+ include: [
2290
+ {
2291
+ relation: 'bar',
2292
+ scope: {
2293
+ where: {removed: false},
2294
+ order: 'createdAt DESC',
2295
+ skip: 0,
2296
+ limit: 0,
2297
+ fields: ['id', 'createdAt'],
2298
+ include: [
2299
+ {
2300
+ relation: 'baz',
2301
+ scope: {
2302
+ include: [
2303
+ {
2304
+ relation: 'qux',
2305
+ },
2306
+ {
2307
+ relation: 'xuq',
2308
+ },
2309
+ ],
2310
+ },
2311
+ },
2312
+ {
2313
+ relation: 'ewq',
2314
+ scope: {
2315
+ include: [
2316
+ {
2317
+ relation: 'dsa',
2318
+ },
2319
+ {
2320
+ relation: 'asd',
2321
+ },
2322
+ ],
2323
+ },
2324
+ },
2325
+ ],
2326
+ },
2327
+ },
2328
+ ],
2329
+ },
2330
+ },
2331
+ ]);
2332
+ });
2333
+
2334
+ it('normalizes the given array of strings', function () {
2335
+ const result = IncludeClauseTool.normalizeIncludeClause(['foo', 'bar']);
2336
+ expect(result).to.be.eql([{relation: 'foo'}, {relation: 'bar'}]);
2337
+ });
2338
+
2339
+ it('normalizes the given array of key-value objects with string', function () {
2340
+ const result = IncludeClauseTool.normalizeIncludeClause([
2341
+ {foo: 'bar', baz: 'qux'},
2342
+ {qwe: 'asd', zxc: 'rty'},
2343
+ ]);
2344
+ expect(result).to.be.eql([
2345
+ {
2346
+ relation: 'foo',
2347
+ scope: {
2348
+ include: [
2349
+ {
2350
+ relation: 'bar',
2351
+ },
2352
+ ],
2353
+ },
2354
+ },
2355
+ {
2356
+ relation: 'baz',
2357
+ scope: {
2358
+ include: [
2359
+ {
2360
+ relation: 'qux',
2361
+ },
2362
+ ],
2363
+ },
2364
+ },
2365
+ {
2366
+ relation: 'qwe',
2367
+ scope: {
2368
+ include: [
2369
+ {
2370
+ relation: 'asd',
2371
+ },
2372
+ ],
2373
+ },
2374
+ },
2375
+ {
2376
+ relation: 'zxc',
2377
+ scope: {
2378
+ include: [
2379
+ {
2380
+ relation: 'rty',
2381
+ },
2382
+ ],
2383
+ },
2384
+ },
2385
+ ]);
2386
+ });
2387
+
2388
+ it('normalizes the given array of key-value objects with undefined', function () {
2389
+ const result = IncludeClauseTool.normalizeIncludeClause([
2390
+ {foo: undefined, bar: undefined},
2391
+ {baz: undefined, qux: undefined},
2392
+ ]);
2393
+ expect(result).to.be.eql([
2394
+ {
2395
+ relation: 'foo',
2396
+ },
2397
+ {
2398
+ relation: 'bar',
2399
+ },
2400
+ {
2401
+ relation: 'baz',
2402
+ },
2403
+ {
2404
+ relation: 'qux',
2405
+ },
2406
+ ]);
2407
+ });
2408
+
2409
+ it('normalizes the given array of key-value objects with null', function () {
2410
+ const result = IncludeClauseTool.normalizeIncludeClause([
2411
+ {foo: null, bar: null},
2412
+ {baz: null, qux: null},
2413
+ ]);
2414
+ expect(result).to.be.eql([
2415
+ {
2416
+ relation: 'foo',
2417
+ },
2418
+ {
2419
+ relation: 'bar',
2420
+ },
2421
+ {
2422
+ relation: 'baz',
2423
+ },
2424
+ {
2425
+ relation: 'qux',
2426
+ },
2427
+ ]);
2428
+ });
2429
+
2430
+ it('normalizes the given array of key-value objects with a key-value object with string', function () {
2431
+ const result = IncludeClauseTool.normalizeIncludeClause([
2432
+ {
2433
+ foo: {bar: 'baz'},
2434
+ qwe: {asd: 'zxc'},
2435
+ },
2436
+ {
2437
+ ewq: {dsa: 'cxz'},
2438
+ rty: {fgh: 'vbn'},
2439
+ },
2440
+ ]);
2441
+ expect(result).to.be.eql([
2442
+ {
2443
+ relation: 'foo',
2444
+ scope: {
2445
+ include: [
2446
+ {
2447
+ relation: 'bar',
2448
+ scope: {
2449
+ include: [
2450
+ {
2451
+ relation: 'baz',
2452
+ },
2453
+ ],
2454
+ },
2455
+ },
2456
+ ],
2457
+ },
2458
+ },
2459
+ {
2460
+ relation: 'qwe',
2461
+ scope: {
2462
+ include: [
2463
+ {
2464
+ relation: 'asd',
2465
+ scope: {
2466
+ include: [
2467
+ {
2468
+ relation: 'zxc',
2469
+ },
2470
+ ],
2471
+ },
2472
+ },
2473
+ ],
2474
+ },
2475
+ },
2476
+ {
2477
+ relation: 'ewq',
2478
+ scope: {
2479
+ include: [
2480
+ {
2481
+ relation: 'dsa',
2482
+ scope: {
2483
+ include: [
2484
+ {
2485
+ relation: 'cxz',
2486
+ },
2487
+ ],
2488
+ },
2489
+ },
2490
+ ],
2491
+ },
2492
+ },
2493
+ {
2494
+ relation: 'rty',
2495
+ scope: {
2496
+ include: [
2497
+ {
2498
+ relation: 'fgh',
2499
+ scope: {
2500
+ include: [
2501
+ {
2502
+ relation: 'vbn',
2503
+ },
2504
+ ],
2505
+ },
2506
+ },
2507
+ ],
2508
+ },
2509
+ },
2510
+ ]);
2511
+ });
2512
+
2513
+ it('normalizes the given array of key-value objects with a key-value object with undefined', function () {
2514
+ const result = IncludeClauseTool.normalizeIncludeClause([
2515
+ {
2516
+ foo: {bar: undefined},
2517
+ qwe: {asd: undefined},
2518
+ },
2519
+ {
2520
+ ewq: {dsa: undefined},
2521
+ cxz: {rty: undefined},
2522
+ },
2523
+ ]);
2524
+ expect(result).to.be.eql([
2525
+ {
2526
+ relation: 'foo',
2527
+ scope: {
2528
+ include: [
2529
+ {
2530
+ relation: 'bar',
2531
+ },
2532
+ ],
2533
+ },
2534
+ },
2535
+ {
2536
+ relation: 'qwe',
2537
+ scope: {
2538
+ include: [
2539
+ {
2540
+ relation: 'asd',
2541
+ },
2542
+ ],
2543
+ },
2544
+ },
2545
+ {
2546
+ relation: 'ewq',
2547
+ scope: {
2548
+ include: [
2549
+ {
2550
+ relation: 'dsa',
2551
+ },
2552
+ ],
2553
+ },
2554
+ },
2555
+ {
2556
+ relation: 'cxz',
2557
+ scope: {
2558
+ include: [
2559
+ {
2560
+ relation: 'rty',
2561
+ },
2562
+ ],
2563
+ },
2564
+ },
2565
+ ]);
2566
+ });
2567
+
2568
+ it('normalizes the given array of key-value objects with a key-value object with null', function () {
2569
+ const result = IncludeClauseTool.normalizeIncludeClause([
2570
+ {
2571
+ foo: {bar: null},
2572
+ qwe: {asd: null},
2573
+ },
2574
+ {
2575
+ ewq: {dsa: null},
2576
+ cxz: {rty: null},
2577
+ },
2578
+ ]);
2579
+ expect(result).to.be.eql([
2580
+ {
2581
+ relation: 'foo',
2582
+ scope: {
2583
+ include: [
2584
+ {
2585
+ relation: 'bar',
2586
+ },
2587
+ ],
2588
+ },
2589
+ },
2590
+ {
2591
+ relation: 'qwe',
2592
+ scope: {
2593
+ include: [
2594
+ {
2595
+ relation: 'asd',
2596
+ },
2597
+ ],
2598
+ },
2599
+ },
2600
+ {
2601
+ relation: 'ewq',
2602
+ scope: {
2603
+ include: [
2604
+ {
2605
+ relation: 'dsa',
2606
+ },
2607
+ ],
2608
+ },
2609
+ },
2610
+ {
2611
+ relation: 'cxz',
2612
+ scope: {
2613
+ include: [
2614
+ {
2615
+ relation: 'rty',
2616
+ },
2617
+ ],
2618
+ },
2619
+ },
2620
+ ]);
2621
+ });
2622
+
2623
+ it('normalizes the given array of key-value objects with an array of strings', function () {
2624
+ const result = IncludeClauseTool.normalizeIncludeClause([
2625
+ {
2626
+ foo: ['bar', 'baz'],
2627
+ qwe: ['asd', 'zxc'],
2628
+ },
2629
+ {
2630
+ ewq: ['dsa', 'cxz'],
2631
+ rty: ['fgh', 'vbn'],
2632
+ },
2633
+ ]);
2634
+ expect(result).to.be.eql([
2635
+ {
2636
+ relation: 'foo',
2637
+ scope: {
2638
+ include: [
2639
+ {
2640
+ relation: 'bar',
2641
+ },
2642
+ {
2643
+ relation: 'baz',
2644
+ },
2645
+ ],
2646
+ },
2647
+ },
2648
+ {
2649
+ relation: 'qwe',
2650
+ scope: {
2651
+ include: [
2652
+ {
2653
+ relation: 'asd',
2654
+ },
2655
+ {
2656
+ relation: 'zxc',
2657
+ },
2658
+ ],
2659
+ },
2660
+ },
2661
+ {
2662
+ relation: 'ewq',
2663
+ scope: {
2664
+ include: [
2665
+ {
2666
+ relation: 'dsa',
2667
+ },
2668
+ {
2669
+ relation: 'cxz',
2670
+ },
2671
+ ],
2672
+ },
2673
+ },
2674
+ {
2675
+ relation: 'rty',
2676
+ scope: {
2677
+ include: [
2678
+ {
2679
+ relation: 'fgh',
2680
+ },
2681
+ {
2682
+ relation: 'vbn',
2683
+ },
2684
+ ],
2685
+ },
2686
+ },
2687
+ ]);
2688
+ });
2689
+
2690
+ it('normalizes the given array of key-value objects with an array of key-value objects with string', function () {
2691
+ const result = IncludeClauseTool.normalizeIncludeClause([
2692
+ {
2693
+ foo: [{bar: 'baz'}, {qwe: 'asd'}],
2694
+ ewq: [{dsa: 'cxz'}, {rty: 'fgh'}],
2695
+ },
2696
+ {
2697
+ qwe: [{asd: 'zxc'}, {rty: 'fgh'}],
2698
+ vbn: [{ewq: 'dsa'}, {cxz: 'rty'}],
2699
+ },
2700
+ ]);
2701
+ expect(result).to.be.eql([
2702
+ {
2703
+ relation: 'foo',
2704
+ scope: {
2705
+ include: [
2706
+ {
2707
+ relation: 'bar',
2708
+ scope: {
2709
+ include: [
2710
+ {
2711
+ relation: 'baz',
2712
+ },
2713
+ ],
2714
+ },
2715
+ },
2716
+ {
2717
+ relation: 'qwe',
2718
+ scope: {
2719
+ include: [
2720
+ {
2721
+ relation: 'asd',
2722
+ },
2723
+ ],
2724
+ },
2725
+ },
2726
+ ],
2727
+ },
2728
+ },
2729
+ {
2730
+ relation: 'ewq',
2731
+ scope: {
2732
+ include: [
2733
+ {
2734
+ relation: 'dsa',
2735
+ scope: {
2736
+ include: [
2737
+ {
2738
+ relation: 'cxz',
2739
+ },
2740
+ ],
2741
+ },
2742
+ },
2743
+ {
2744
+ relation: 'rty',
2745
+ scope: {
2746
+ include: [
2747
+ {
2748
+ relation: 'fgh',
2749
+ },
2750
+ ],
2751
+ },
2752
+ },
2753
+ ],
2754
+ },
2755
+ },
2756
+ {
2757
+ relation: 'qwe',
2758
+ scope: {
2759
+ include: [
2760
+ {
2761
+ relation: 'asd',
2762
+ scope: {
2763
+ include: [
2764
+ {
2765
+ relation: 'zxc',
2766
+ },
2767
+ ],
2768
+ },
2769
+ },
2770
+ {
2771
+ relation: 'rty',
2772
+ scope: {
2773
+ include: [
2774
+ {
2775
+ relation: 'fgh',
2776
+ },
2777
+ ],
2778
+ },
2779
+ },
2780
+ ],
2781
+ },
2782
+ },
2783
+ {
2784
+ relation: 'vbn',
2785
+ scope: {
2786
+ include: [
2787
+ {
2788
+ relation: 'ewq',
2789
+ scope: {
2790
+ include: [
2791
+ {
2792
+ relation: 'dsa',
2793
+ },
2794
+ ],
2795
+ },
2796
+ },
2797
+ {
2798
+ relation: 'cxz',
2799
+ scope: {
2800
+ include: [
2801
+ {
2802
+ relation: 'rty',
2803
+ },
2804
+ ],
2805
+ },
2806
+ },
2807
+ ],
2808
+ },
2809
+ },
2810
+ ]);
2811
+ });
2812
+
2813
+ it('normalizes the given array of key-value objects with an array of key-value objects with undefined', function () {
2814
+ const result = IncludeClauseTool.normalizeIncludeClause([
2815
+ {
2816
+ foo: [{bar: undefined}, {qwe: undefined}],
2817
+ ewq: [{dsa: undefined}, {rty: undefined}],
2818
+ },
2819
+ {
2820
+ qwe: [{asd: undefined}, {zxc: undefined}],
2821
+ rty: [{fgh: undefined}, {vbn: undefined}],
2822
+ },
2823
+ ]);
2824
+ expect(result).to.be.eql([
2825
+ {
2826
+ relation: 'foo',
2827
+ scope: {
2828
+ include: [
2829
+ {
2830
+ relation: 'bar',
2831
+ },
2832
+ {
2833
+ relation: 'qwe',
2834
+ },
2835
+ ],
2836
+ },
2837
+ },
2838
+ {
2839
+ relation: 'ewq',
2840
+ scope: {
2841
+ include: [
2842
+ {
2843
+ relation: 'dsa',
2844
+ },
2845
+ {
2846
+ relation: 'rty',
2847
+ },
2848
+ ],
2849
+ },
2850
+ },
2851
+ {
2852
+ relation: 'qwe',
2853
+ scope: {
2854
+ include: [
2855
+ {
2856
+ relation: 'asd',
2857
+ },
2858
+ {
2859
+ relation: 'zxc',
2860
+ },
2861
+ ],
2862
+ },
2863
+ },
2864
+ {
2865
+ relation: 'rty',
2866
+ scope: {
2867
+ include: [
2868
+ {
2869
+ relation: 'fgh',
2870
+ },
2871
+ {
2872
+ relation: 'vbn',
2873
+ },
2874
+ ],
2875
+ },
2876
+ },
2877
+ ]);
2878
+ });
2879
+
2880
+ it('normalizes the given array of key-value objects with an array of key-value objects with null', function () {
2881
+ const result = IncludeClauseTool.normalizeIncludeClause([
2882
+ {
2883
+ foo: [{bar: null}, {qwe: null}],
2884
+ ewq: [{dsa: null}, {rty: null}],
2885
+ },
2886
+ {
2887
+ ytr: [{hgf: null}, {nbv: null}],
2888
+ qwe: [{asd: null}, {zxc: null}],
2889
+ },
2890
+ ]);
2891
+ expect(result).to.be.eql([
2892
+ {
2893
+ relation: 'foo',
2894
+ scope: {
2895
+ include: [
2896
+ {
2897
+ relation: 'bar',
2898
+ },
2899
+ {
2900
+ relation: 'qwe',
2901
+ },
2902
+ ],
2903
+ },
2904
+ },
2905
+ {
2906
+ relation: 'ewq',
2907
+ scope: {
2908
+ include: [
2909
+ {
2910
+ relation: 'dsa',
2911
+ },
2912
+ {
2913
+ relation: 'rty',
2914
+ },
2915
+ ],
2916
+ },
2917
+ },
2918
+ {
2919
+ relation: 'ytr',
2920
+ scope: {
2921
+ include: [
2922
+ {
2923
+ relation: 'hgf',
2924
+ },
2925
+ {
2926
+ relation: 'nbv',
2927
+ },
2928
+ ],
2929
+ },
2930
+ },
2931
+ {
2932
+ relation: 'qwe',
2933
+ scope: {
2934
+ include: [
2935
+ {
2936
+ relation: 'asd',
2937
+ },
2938
+ {
2939
+ relation: 'zxc',
2940
+ },
2941
+ ],
2942
+ },
2943
+ },
2944
+ ]);
2945
+ });
2946
+
2947
+ it('normalizes the given array of key-value objects with an array of key-value objects with an array of strings', function () {
2948
+ const result = IncludeClauseTool.normalizeIncludeClause([
2949
+ {
2950
+ foo: [{bar: ['baz', 'qux']}, {qwe: ['asd', 'zxc']}],
2951
+ ewq: [{dsa: ['cxz', 'rty']}, {fgh: ['vbn', 'uio']}],
2952
+ },
2953
+ {
2954
+ qwe: [{asd: ['zxc', 'rty']}, {fgh: ['vbn', 'ewq']}],
2955
+ dsa: [{cxz: ['rty', 'vbn']}, {ewq: ['dsa', 'cxz']}],
2956
+ },
2957
+ ]);
2958
+ expect(result).to.be.eql([
2959
+ {
2960
+ relation: 'foo',
2961
+ scope: {
2962
+ include: [
2963
+ {
2964
+ relation: 'bar',
2965
+ scope: {
2966
+ include: [
2967
+ {
2968
+ relation: 'baz',
2969
+ },
2970
+ {
2971
+ relation: 'qux',
2972
+ },
2973
+ ],
2974
+ },
2975
+ },
2976
+ {
2977
+ relation: 'qwe',
2978
+ scope: {
2979
+ include: [
2980
+ {
2981
+ relation: 'asd',
2982
+ },
2983
+ {
2984
+ relation: 'zxc',
2985
+ },
2986
+ ],
2987
+ },
2988
+ },
2989
+ ],
2990
+ },
2991
+ },
2992
+ {
2993
+ relation: 'ewq',
2994
+ scope: {
2995
+ include: [
2996
+ {
2997
+ relation: 'dsa',
2998
+ scope: {
2999
+ include: [
3000
+ {
3001
+ relation: 'cxz',
3002
+ },
3003
+ {
3004
+ relation: 'rty',
3005
+ },
3006
+ ],
3007
+ },
3008
+ },
3009
+ {
3010
+ relation: 'fgh',
3011
+ scope: {
3012
+ include: [
3013
+ {
3014
+ relation: 'vbn',
3015
+ },
3016
+ {
3017
+ relation: 'uio',
3018
+ },
3019
+ ],
3020
+ },
3021
+ },
3022
+ ],
3023
+ },
3024
+ },
3025
+ {
3026
+ relation: 'qwe',
3027
+ scope: {
3028
+ include: [
3029
+ {
3030
+ relation: 'asd',
3031
+ scope: {
3032
+ include: [
3033
+ {
3034
+ relation: 'zxc',
3035
+ },
3036
+ {
3037
+ relation: 'rty',
3038
+ },
3039
+ ],
3040
+ },
3041
+ },
3042
+ {
3043
+ relation: 'fgh',
3044
+ scope: {
3045
+ include: [
3046
+ {
3047
+ relation: 'vbn',
3048
+ },
3049
+ {
3050
+ relation: 'ewq',
3051
+ },
3052
+ ],
3053
+ },
3054
+ },
3055
+ ],
3056
+ },
3057
+ },
3058
+ {
3059
+ relation: 'dsa',
3060
+ scope: {
3061
+ include: [
3062
+ {
3063
+ relation: 'cxz',
3064
+ scope: {
3065
+ include: [
3066
+ {
3067
+ relation: 'rty',
3068
+ },
3069
+ {
3070
+ relation: 'vbn',
3071
+ },
3072
+ ],
3073
+ },
3074
+ },
3075
+ {
3076
+ relation: 'ewq',
3077
+ scope: {
3078
+ include: [
3079
+ {
3080
+ relation: 'dsa',
3081
+ },
3082
+ {
3083
+ relation: 'cxz',
3084
+ },
3085
+ ],
3086
+ },
3087
+ },
3088
+ ],
3089
+ },
3090
+ },
3091
+ ]);
3092
+ });
3093
+
3094
+ it('normalizes the given array of key-value objects with an inclusion object with string', function () {
3095
+ const result = IncludeClauseTool.normalizeIncludeClause([
3096
+ {
3097
+ foo: {
3098
+ relation: 'bar',
3099
+ scope: {
3100
+ where: {featured: true},
3101
+ order: 'id DESC',
3102
+ skip: 0,
3103
+ limit: 10,
3104
+ fields: 'barId',
3105
+ include: 'baz',
3106
+ },
3107
+ },
3108
+ qwe: {
3109
+ relation: 'asd',
3110
+ scope: {
3111
+ where: {removed: false},
3112
+ order: 'createdAt DESC',
3113
+ skip: 10,
3114
+ limit: 0,
3115
+ fields: 'asdId',
3116
+ include: 'zxc',
3117
+ },
3118
+ },
3119
+ },
3120
+ {
3121
+ ewq: {
3122
+ relation: 'dsa',
3123
+ scope: {
3124
+ where: {featured: true},
3125
+ order: 'id DESC',
3126
+ skip: 0,
3127
+ limit: 10,
3128
+ fields: 'barId',
3129
+ include: 'cxz',
3130
+ },
3131
+ },
3132
+ ytr: {
3133
+ relation: 'hgf',
3134
+ scope: {
3135
+ where: {removed: false},
3136
+ order: 'createdAt DESC',
3137
+ skip: 10,
3138
+ limit: 0,
3139
+ fields: 'asdId',
3140
+ include: 'nbv',
3141
+ },
3142
+ },
3143
+ },
3144
+ ]);
3145
+ expect(result).to.be.eql([
3146
+ {
3147
+ relation: 'foo',
3148
+ scope: {
3149
+ include: [
3150
+ {
3151
+ relation: 'bar',
3152
+ scope: {
3153
+ where: {featured: true},
3154
+ order: 'id DESC',
3155
+ skip: 0,
3156
+ limit: 10,
3157
+ fields: 'barId',
3158
+ include: [
3159
+ {
3160
+ relation: 'baz',
3161
+ },
3162
+ ],
3163
+ },
3164
+ },
3165
+ ],
3166
+ },
3167
+ },
3168
+ {
3169
+ relation: 'qwe',
3170
+ scope: {
3171
+ include: [
3172
+ {
3173
+ relation: 'asd',
3174
+ scope: {
3175
+ where: {removed: false},
3176
+ order: 'createdAt DESC',
3177
+ skip: 10,
3178
+ limit: 0,
3179
+ fields: 'asdId',
3180
+ include: [
3181
+ {
3182
+ relation: 'zxc',
3183
+ },
3184
+ ],
3185
+ },
3186
+ },
3187
+ ],
3188
+ },
3189
+ },
3190
+ {
3191
+ relation: 'ewq',
3192
+ scope: {
3193
+ include: [
3194
+ {
3195
+ relation: 'dsa',
3196
+ scope: {
3197
+ where: {featured: true},
3198
+ order: 'id DESC',
3199
+ skip: 0,
3200
+ limit: 10,
3201
+ fields: 'barId',
3202
+ include: [
3203
+ {
3204
+ relation: 'cxz',
3205
+ },
3206
+ ],
3207
+ },
3208
+ },
3209
+ ],
3210
+ },
3211
+ },
3212
+ {
3213
+ relation: 'ytr',
3214
+ scope: {
3215
+ include: [
3216
+ {
3217
+ relation: 'hgf',
3218
+ scope: {
3219
+ where: {removed: false},
3220
+ order: 'createdAt DESC',
3221
+ skip: 10,
3222
+ limit: 0,
3223
+ fields: 'asdId',
3224
+ include: [
3225
+ {
3226
+ relation: 'nbv',
3227
+ },
3228
+ ],
3229
+ },
3230
+ },
3231
+ ],
3232
+ },
3233
+ },
3234
+ ]);
3235
+ });
3236
+
3237
+ it('normalizes the given array of key-value objects with an inclusion object with a key-value object with string', function () {
3238
+ const result = IncludeClauseTool.normalizeIncludeClause([
3239
+ {
3240
+ foo: {
3241
+ relation: 'bar',
3242
+ scope: {
3243
+ where: {featured: true},
3244
+ order: 'id DESC',
3245
+ skip: 0,
3246
+ limit: 10,
3247
+ fields: 'barId',
3248
+ include: {
3249
+ baz: 'qux',
3250
+ ewq: 'dsa',
3251
+ },
3252
+ },
3253
+ },
3254
+ qwe: {
3255
+ relation: 'asd',
3256
+ scope: {
3257
+ where: {removed: false},
3258
+ order: 'createdAt DESC',
3259
+ skip: 10,
3260
+ limit: 0,
3261
+ fields: 'asdId',
3262
+ include: {
3263
+ zxc: 'rty',
3264
+ fgh: 'vbn',
3265
+ },
3266
+ },
3267
+ },
3268
+ },
3269
+ {
3270
+ ytr: {
3271
+ relation: 'hgf',
3272
+ scope: {
3273
+ where: {featured: true},
3274
+ order: 'id DESC',
3275
+ skip: 0,
3276
+ limit: 10,
3277
+ fields: 'barId',
3278
+ include: {
3279
+ nbv: 'ewq',
3280
+ dsa: 'cxz',
3281
+ },
3282
+ },
3283
+ },
3284
+ rty: {
3285
+ relation: 'fgh',
3286
+ scope: {
3287
+ where: {removed: false},
3288
+ order: 'createdAt DESC',
3289
+ skip: 10,
3290
+ limit: 0,
3291
+ fields: 'asdId',
3292
+ include: {
3293
+ vbn: 'qwe',
3294
+ asd: 'zxc',
3295
+ },
3296
+ },
3297
+ },
3298
+ },
3299
+ ]);
3300
+ expect(result).to.be.eql([
3301
+ {
3302
+ relation: 'foo',
3303
+ scope: {
3304
+ include: [
3305
+ {
3306
+ relation: 'bar',
3307
+ scope: {
3308
+ where: {featured: true},
3309
+ order: 'id DESC',
3310
+ skip: 0,
3311
+ limit: 10,
3312
+ fields: 'barId',
3313
+ include: [
3314
+ {
3315
+ relation: 'baz',
3316
+ scope: {
3317
+ include: [
3318
+ {
3319
+ relation: 'qux',
3320
+ },
3321
+ ],
3322
+ },
3323
+ },
3324
+ {
3325
+ relation: 'ewq',
3326
+ scope: {
3327
+ include: [
3328
+ {
3329
+ relation: 'dsa',
3330
+ },
3331
+ ],
3332
+ },
3333
+ },
3334
+ ],
3335
+ },
3336
+ },
3337
+ ],
3338
+ },
3339
+ },
3340
+ {
3341
+ relation: 'qwe',
3342
+ scope: {
3343
+ include: [
3344
+ {
3345
+ relation: 'asd',
3346
+ scope: {
3347
+ where: {removed: false},
3348
+ order: 'createdAt DESC',
3349
+ skip: 10,
3350
+ limit: 0,
3351
+ fields: 'asdId',
3352
+ include: [
3353
+ {
3354
+ relation: 'zxc',
3355
+ scope: {
3356
+ include: [
3357
+ {
3358
+ relation: 'rty',
3359
+ },
3360
+ ],
3361
+ },
3362
+ },
3363
+ {
3364
+ relation: 'fgh',
3365
+ scope: {
3366
+ include: [
3367
+ {
3368
+ relation: 'vbn',
3369
+ },
3370
+ ],
3371
+ },
3372
+ },
3373
+ ],
3374
+ },
3375
+ },
3376
+ ],
3377
+ },
3378
+ },
3379
+ {
3380
+ relation: 'ytr',
3381
+ scope: {
3382
+ include: [
3383
+ {
3384
+ relation: 'hgf',
3385
+ scope: {
3386
+ where: {featured: true},
3387
+ order: 'id DESC',
3388
+ skip: 0,
3389
+ limit: 10,
3390
+ fields: 'barId',
3391
+ include: [
3392
+ {
3393
+ relation: 'nbv',
3394
+ scope: {
3395
+ include: [
3396
+ {
3397
+ relation: 'ewq',
3398
+ },
3399
+ ],
3400
+ },
3401
+ },
3402
+ {
3403
+ relation: 'dsa',
3404
+ scope: {
3405
+ include: [
3406
+ {
3407
+ relation: 'cxz',
3408
+ },
3409
+ ],
3410
+ },
3411
+ },
3412
+ ],
3413
+ },
3414
+ },
3415
+ ],
3416
+ },
3417
+ },
3418
+ {
3419
+ relation: 'rty',
3420
+ scope: {
3421
+ include: [
3422
+ {
3423
+ relation: 'fgh',
3424
+ scope: {
3425
+ where: {removed: false},
3426
+ order: 'createdAt DESC',
3427
+ skip: 10,
3428
+ limit: 0,
3429
+ fields: 'asdId',
3430
+ include: [
3431
+ {
3432
+ relation: 'vbn',
3433
+ scope: {
3434
+ include: [
3435
+ {
3436
+ relation: 'qwe',
3437
+ },
3438
+ ],
3439
+ },
3440
+ },
3441
+ {
3442
+ relation: 'asd',
3443
+ scope: {
3444
+ include: [
3445
+ {
3446
+ relation: 'zxc',
3447
+ },
3448
+ ],
3449
+ },
3450
+ },
3451
+ ],
3452
+ },
3453
+ },
3454
+ ],
3455
+ },
3456
+ },
3457
+ ]);
3458
+ });
3459
+
3460
+ it('normalizes the given array of key-value objects with an inclusion object with a key-value object with undefined', function () {
3461
+ const result = IncludeClauseTool.normalizeIncludeClause([
3462
+ {
3463
+ foo: {
3464
+ relation: 'bar',
3465
+ scope: {
3466
+ where: {featured: true},
3467
+ order: 'id DESC',
3468
+ skip: 0,
3469
+ limit: 10,
3470
+ fields: 'barId',
3471
+ include: {
3472
+ baz: undefined,
3473
+ ewq: undefined,
3474
+ },
3475
+ },
3476
+ },
3477
+ qwe: {
3478
+ relation: 'asd',
3479
+ scope: {
3480
+ where: {removed: false},
3481
+ order: 'createdAt DESC',
3482
+ skip: 10,
3483
+ limit: 0,
3484
+ fields: 'asdId',
3485
+ include: {
3486
+ zxc: undefined,
3487
+ fgh: undefined,
3488
+ },
3489
+ },
3490
+ },
3491
+ },
3492
+ {
3493
+ ytr: {
3494
+ relation: 'hgf',
3495
+ scope: {
3496
+ where: {featured: true},
3497
+ order: 'id DESC',
3498
+ skip: 0,
3499
+ limit: 10,
3500
+ fields: 'barId',
3501
+ include: {
3502
+ nbv: undefined,
3503
+ ewq: undefined,
3504
+ },
3505
+ },
3506
+ },
3507
+ dsa: {
3508
+ relation: 'cxz',
3509
+ scope: {
3510
+ where: {removed: false},
3511
+ order: 'createdAt DESC',
3512
+ skip: 10,
3513
+ limit: 0,
3514
+ fields: 'asdId',
3515
+ include: {
3516
+ rty: undefined,
3517
+ fgh: undefined,
3518
+ },
3519
+ },
3520
+ },
3521
+ },
3522
+ ]);
3523
+ expect(result).to.be.eql([
3524
+ {
3525
+ relation: 'foo',
3526
+ scope: {
3527
+ include: [
3528
+ {
3529
+ relation: 'bar',
3530
+ scope: {
3531
+ where: {featured: true},
3532
+ order: 'id DESC',
3533
+ skip: 0,
3534
+ limit: 10,
3535
+ fields: 'barId',
3536
+ include: [
3537
+ {
3538
+ relation: 'baz',
3539
+ },
3540
+ {
3541
+ relation: 'ewq',
3542
+ },
3543
+ ],
3544
+ },
3545
+ },
3546
+ ],
3547
+ },
3548
+ },
3549
+ {
3550
+ relation: 'qwe',
3551
+ scope: {
3552
+ include: [
3553
+ {
3554
+ relation: 'asd',
3555
+ scope: {
3556
+ where: {removed: false},
3557
+ order: 'createdAt DESC',
3558
+ skip: 10,
3559
+ limit: 0,
3560
+ fields: 'asdId',
3561
+ include: [
3562
+ {
3563
+ relation: 'zxc',
3564
+ },
3565
+ {
3566
+ relation: 'fgh',
3567
+ },
3568
+ ],
3569
+ },
3570
+ },
3571
+ ],
3572
+ },
3573
+ },
3574
+ {
3575
+ relation: 'ytr',
3576
+ scope: {
3577
+ include: [
3578
+ {
3579
+ relation: 'hgf',
3580
+ scope: {
3581
+ where: {featured: true},
3582
+ order: 'id DESC',
3583
+ skip: 0,
3584
+ limit: 10,
3585
+ fields: 'barId',
3586
+ include: [
3587
+ {
3588
+ relation: 'nbv',
3589
+ },
3590
+ {
3591
+ relation: 'ewq',
3592
+ },
3593
+ ],
3594
+ },
3595
+ },
3596
+ ],
3597
+ },
3598
+ },
3599
+ {
3600
+ relation: 'dsa',
3601
+ scope: {
3602
+ include: [
3603
+ {
3604
+ relation: 'cxz',
3605
+ scope: {
3606
+ where: {removed: false},
3607
+ order: 'createdAt DESC',
3608
+ skip: 10,
3609
+ limit: 0,
3610
+ fields: 'asdId',
3611
+ include: [
3612
+ {
3613
+ relation: 'rty',
3614
+ },
3615
+ {
3616
+ relation: 'fgh',
3617
+ },
3618
+ ],
3619
+ },
3620
+ },
3621
+ ],
3622
+ },
3623
+ },
3624
+ ]);
3625
+ });
3626
+
3627
+ it('normalizes the given array of key-value objects with an inclusion object with a key-value object with null', function () {
3628
+ const result = IncludeClauseTool.normalizeIncludeClause([
3629
+ {
3630
+ foo: {
3631
+ relation: 'bar',
3632
+ scope: {
3633
+ where: {featured: true},
3634
+ order: 'id DESC',
3635
+ skip: 0,
3636
+ limit: 10,
3637
+ fields: 'barId',
3638
+ include: {
3639
+ baz: null,
3640
+ ewq: null,
3641
+ },
3642
+ },
3643
+ },
3644
+ qwe: {
3645
+ relation: 'asd',
3646
+ scope: {
3647
+ where: {removed: false},
3648
+ order: 'createdAt DESC',
3649
+ skip: 10,
3650
+ limit: 0,
3651
+ fields: 'asdId',
3652
+ include: {
3653
+ zxc: null,
3654
+ fgh: null,
3655
+ },
3656
+ },
3657
+ },
3658
+ },
3659
+ {
3660
+ ytr: {
3661
+ relation: 'hgf',
3662
+ scope: {
3663
+ where: {featured: true},
3664
+ order: 'id DESC',
3665
+ skip: 0,
3666
+ limit: 10,
3667
+ fields: 'barId',
3668
+ include: {
3669
+ nbv: null,
3670
+ ewq: null,
3671
+ },
3672
+ },
3673
+ },
3674
+ dsa: {
3675
+ relation: 'cxz',
3676
+ scope: {
3677
+ where: {removed: false},
3678
+ order: 'createdAt DESC',
3679
+ skip: 10,
3680
+ limit: 0,
3681
+ fields: 'asdId',
3682
+ include: {
3683
+ rty: null,
3684
+ fgh: null,
3685
+ },
3686
+ },
3687
+ },
3688
+ },
3689
+ ]);
3690
+ expect(result).to.be.eql([
3691
+ {
3692
+ relation: 'foo',
3693
+ scope: {
3694
+ include: [
3695
+ {
3696
+ relation: 'bar',
3697
+ scope: {
3698
+ where: {featured: true},
3699
+ order: 'id DESC',
3700
+ skip: 0,
3701
+ limit: 10,
3702
+ fields: 'barId',
3703
+ include: [
3704
+ {
3705
+ relation: 'baz',
3706
+ },
3707
+ {
3708
+ relation: 'ewq',
3709
+ },
3710
+ ],
3711
+ },
3712
+ },
3713
+ ],
3714
+ },
3715
+ },
3716
+ {
3717
+ relation: 'qwe',
3718
+ scope: {
3719
+ include: [
3720
+ {
3721
+ relation: 'asd',
3722
+ scope: {
3723
+ where: {removed: false},
3724
+ order: 'createdAt DESC',
3725
+ skip: 10,
3726
+ limit: 0,
3727
+ fields: 'asdId',
3728
+ include: [
3729
+ {
3730
+ relation: 'zxc',
3731
+ },
3732
+ {
3733
+ relation: 'fgh',
3734
+ },
3735
+ ],
3736
+ },
3737
+ },
3738
+ ],
3739
+ },
3740
+ },
3741
+ {
3742
+ relation: 'ytr',
3743
+ scope: {
3744
+ include: [
3745
+ {
3746
+ relation: 'hgf',
3747
+ scope: {
3748
+ where: {featured: true},
3749
+ order: 'id DESC',
3750
+ skip: 0,
3751
+ limit: 10,
3752
+ fields: 'barId',
3753
+ include: [
3754
+ {
3755
+ relation: 'nbv',
3756
+ },
3757
+ {
3758
+ relation: 'ewq',
3759
+ },
3760
+ ],
3761
+ },
3762
+ },
3763
+ ],
3764
+ },
3765
+ },
3766
+ {
3767
+ relation: 'dsa',
3768
+ scope: {
3769
+ include: [
3770
+ {
3771
+ relation: 'cxz',
3772
+ scope: {
3773
+ where: {removed: false},
3774
+ order: 'createdAt DESC',
3775
+ skip: 10,
3776
+ limit: 0,
3777
+ fields: 'asdId',
3778
+ include: [
3779
+ {
3780
+ relation: 'rty',
3781
+ },
3782
+ {
3783
+ relation: 'fgh',
3784
+ },
3785
+ ],
3786
+ },
3787
+ },
3788
+ ],
3789
+ },
3790
+ },
3791
+ ]);
3792
+ });
3793
+
3794
+ it('normalizes the given array of key-value objects with an inclusion object with an array of strings', function () {
3795
+ const result = IncludeClauseTool.normalizeIncludeClause([
3796
+ {
3797
+ foo: {
3798
+ relation: 'bar',
3799
+ scope: {
3800
+ where: {featured: true},
3801
+ order: 'id DESC',
3802
+ skip: 0,
3803
+ limit: 10,
3804
+ fields: 'barId',
3805
+ include: ['baz', 'qux'],
3806
+ },
3807
+ },
3808
+ qwe: {
3809
+ relation: 'asd',
3810
+ scope: {
3811
+ where: {removed: false},
3812
+ order: 'createdAt DESC',
3813
+ skip: 10,
3814
+ limit: 0,
3815
+ fields: 'asdId',
3816
+ include: ['zxc', 'rty'],
3817
+ },
3818
+ },
3819
+ },
3820
+ {
3821
+ ytr: {
3822
+ relation: 'hgf',
3823
+ scope: {
3824
+ where: {featured: true},
3825
+ order: 'id DESC',
3826
+ skip: 0,
3827
+ limit: 10,
3828
+ fields: 'barId',
3829
+ include: ['nbv', 'ewq'],
3830
+ },
3831
+ },
3832
+ dsa: {
3833
+ relation: 'cxz',
3834
+ scope: {
3835
+ where: {removed: false},
3836
+ order: 'createdAt DESC',
3837
+ skip: 10,
3838
+ limit: 0,
3839
+ fields: 'asdId',
3840
+ include: ['ytr', 'hgf'],
3841
+ },
3842
+ },
3843
+ },
3844
+ ]);
3845
+ expect(result).to.be.eql([
3846
+ {
3847
+ relation: 'foo',
3848
+ scope: {
3849
+ include: [
3850
+ {
3851
+ relation: 'bar',
3852
+ scope: {
3853
+ where: {featured: true},
3854
+ order: 'id DESC',
3855
+ skip: 0,
3856
+ limit: 10,
3857
+ fields: 'barId',
3858
+ include: [
3859
+ {
3860
+ relation: 'baz',
3861
+ },
3862
+ {
3863
+ relation: 'qux',
3864
+ },
3865
+ ],
3866
+ },
3867
+ },
3868
+ ],
3869
+ },
3870
+ },
3871
+ {
3872
+ relation: 'qwe',
3873
+ scope: {
3874
+ include: [
3875
+ {
3876
+ relation: 'asd',
3877
+ scope: {
3878
+ where: {removed: false},
3879
+ order: 'createdAt DESC',
3880
+ skip: 10,
3881
+ limit: 0,
3882
+ fields: 'asdId',
3883
+ include: [
3884
+ {
3885
+ relation: 'zxc',
3886
+ },
3887
+ {
3888
+ relation: 'rty',
3889
+ },
3890
+ ],
3891
+ },
3892
+ },
3893
+ ],
3894
+ },
3895
+ },
3896
+ {
3897
+ relation: 'ytr',
3898
+ scope: {
3899
+ include: [
3900
+ {
3901
+ relation: 'hgf',
3902
+ scope: {
3903
+ where: {featured: true},
3904
+ order: 'id DESC',
3905
+ skip: 0,
3906
+ limit: 10,
3907
+ fields: 'barId',
3908
+ include: [
3909
+ {
3910
+ relation: 'nbv',
3911
+ },
3912
+ {
3913
+ relation: 'ewq',
3914
+ },
3915
+ ],
3916
+ },
3917
+ },
3918
+ ],
3919
+ },
3920
+ },
3921
+ {
3922
+ relation: 'dsa',
3923
+ scope: {
3924
+ include: [
3925
+ {
3926
+ relation: 'cxz',
3927
+ scope: {
3928
+ where: {removed: false},
3929
+ order: 'createdAt DESC',
3930
+ skip: 10,
3931
+ limit: 0,
3932
+ fields: 'asdId',
3933
+ include: [
3934
+ {
3935
+ relation: 'ytr',
3936
+ },
3937
+ {
3938
+ relation: 'hgf',
3939
+ },
3940
+ ],
3941
+ },
3942
+ },
3943
+ ],
3944
+ },
3945
+ },
3946
+ ]);
3947
+ });
3948
+
3949
+ it('normalizes the given array of key-value objects with an inclusion object with an array of key-value objects with string', function () {
3950
+ const result = IncludeClauseTool.normalizeIncludeClause([
3951
+ {
3952
+ foo: {
3953
+ relation: 'bar',
3954
+ scope: {
3955
+ where: {featured: true},
3956
+ order: 'id DESC',
3957
+ skip: 0,
3958
+ limit: 10,
3959
+ fields: 'barId',
3960
+ include: {
3961
+ baz: 'qux',
3962
+ ewq: 'dsa',
3963
+ },
3964
+ },
3965
+ },
3966
+ qwe: {
3967
+ relation: 'asd',
3968
+ scope: {
3969
+ where: {removed: false},
3970
+ order: 'createdAt DESC',
3971
+ skip: 10,
3972
+ limit: 0,
3973
+ fields: 'asdId',
3974
+ include: {
3975
+ zxc: 'rty',
3976
+ fgh: 'vbn',
3977
+ },
3978
+ },
3979
+ },
3980
+ },
3981
+ {
3982
+ ytr: {
3983
+ relation: 'hgf',
3984
+ scope: {
3985
+ where: {featured: true},
3986
+ order: 'id DESC',
3987
+ skip: 0,
3988
+ limit: 10,
3989
+ fields: 'barId',
3990
+ include: {
3991
+ nbv: 'ewq',
3992
+ dsa: 'cxz',
3993
+ },
3994
+ },
3995
+ },
3996
+ rty: {
3997
+ relation: 'fgh',
3998
+ scope: {
3999
+ where: {removed: false},
4000
+ order: 'createdAt DESC',
4001
+ skip: 10,
4002
+ limit: 0,
4003
+ fields: 'asdId',
4004
+ include: {
4005
+ vbn: 'qwe',
4006
+ asd: 'zxc',
4007
+ },
4008
+ },
4009
+ },
4010
+ },
4011
+ ]);
4012
+ expect(result).to.be.eql([
4013
+ {
4014
+ relation: 'foo',
4015
+ scope: {
4016
+ include: [
4017
+ {
4018
+ relation: 'bar',
4019
+ scope: {
4020
+ where: {featured: true},
4021
+ order: 'id DESC',
4022
+ skip: 0,
4023
+ limit: 10,
4024
+ fields: 'barId',
4025
+ include: [
4026
+ {
4027
+ relation: 'baz',
4028
+ scope: {
4029
+ include: [
4030
+ {
4031
+ relation: 'qux',
4032
+ },
4033
+ ],
4034
+ },
4035
+ },
4036
+ {
4037
+ relation: 'ewq',
4038
+ scope: {
4039
+ include: [
4040
+ {
4041
+ relation: 'dsa',
4042
+ },
4043
+ ],
4044
+ },
4045
+ },
4046
+ ],
4047
+ },
4048
+ },
4049
+ ],
4050
+ },
4051
+ },
4052
+ {
4053
+ relation: 'qwe',
4054
+ scope: {
4055
+ include: [
4056
+ {
4057
+ relation: 'asd',
4058
+ scope: {
4059
+ where: {removed: false},
4060
+ order: 'createdAt DESC',
4061
+ skip: 10,
4062
+ limit: 0,
4063
+ fields: 'asdId',
4064
+ include: [
4065
+ {
4066
+ relation: 'zxc',
4067
+ scope: {
4068
+ include: [
4069
+ {
4070
+ relation: 'rty',
4071
+ },
4072
+ ],
4073
+ },
4074
+ },
4075
+ {
4076
+ relation: 'fgh',
4077
+ scope: {
4078
+ include: [
4079
+ {
4080
+ relation: 'vbn',
4081
+ },
4082
+ ],
4083
+ },
4084
+ },
4085
+ ],
4086
+ },
4087
+ },
4088
+ ],
4089
+ },
4090
+ },
4091
+ {
4092
+ relation: 'ytr',
4093
+ scope: {
4094
+ include: [
4095
+ {
4096
+ relation: 'hgf',
4097
+ scope: {
4098
+ where: {featured: true},
4099
+ order: 'id DESC',
4100
+ skip: 0,
4101
+ limit: 10,
4102
+ fields: 'barId',
4103
+ include: [
4104
+ {
4105
+ relation: 'nbv',
4106
+ scope: {
4107
+ include: [
4108
+ {
4109
+ relation: 'ewq',
4110
+ },
4111
+ ],
4112
+ },
4113
+ },
4114
+ {
4115
+ relation: 'dsa',
4116
+ scope: {
4117
+ include: [
4118
+ {
4119
+ relation: 'cxz',
4120
+ },
4121
+ ],
4122
+ },
4123
+ },
4124
+ ],
4125
+ },
4126
+ },
4127
+ ],
4128
+ },
4129
+ },
4130
+ {
4131
+ relation: 'rty',
4132
+ scope: {
4133
+ include: [
4134
+ {
4135
+ relation: 'fgh',
4136
+ scope: {
4137
+ where: {removed: false},
4138
+ order: 'createdAt DESC',
4139
+ skip: 10,
4140
+ limit: 0,
4141
+ fields: 'asdId',
4142
+ include: [
4143
+ {
4144
+ relation: 'vbn',
4145
+ scope: {
4146
+ include: [
4147
+ {
4148
+ relation: 'qwe',
4149
+ },
4150
+ ],
4151
+ },
4152
+ },
4153
+ {
4154
+ relation: 'asd',
4155
+ scope: {
4156
+ include: [
4157
+ {
4158
+ relation: 'zxc',
4159
+ },
4160
+ ],
4161
+ },
4162
+ },
4163
+ ],
4164
+ },
4165
+ },
4166
+ ],
4167
+ },
4168
+ },
4169
+ ]);
4170
+ });
4171
+
4172
+ it('normalizes the given array of key-value objects with an inclusion object with an array of key-value objects with undefined', function () {
4173
+ const result = IncludeClauseTool.normalizeIncludeClause([
4174
+ {
4175
+ foo: {
4176
+ relation: 'bar',
4177
+ scope: {
4178
+ where: {featured: true},
4179
+ order: 'id DESC',
4180
+ skip: 0,
4181
+ limit: 10,
4182
+ fields: 'barId',
4183
+ include: {
4184
+ baz: undefined,
4185
+ ewq: undefined,
4186
+ },
4187
+ },
4188
+ },
4189
+ qwe: {
4190
+ relation: 'asd',
4191
+ scope: {
4192
+ where: {removed: false},
4193
+ order: 'createdAt DESC',
4194
+ skip: 10,
4195
+ limit: 0,
4196
+ fields: 'asdId',
4197
+ include: {
4198
+ zxc: undefined,
4199
+ fgh: undefined,
4200
+ },
4201
+ },
4202
+ },
4203
+ },
4204
+ {
4205
+ ytr: {
4206
+ relation: 'hgf',
4207
+ scope: {
4208
+ where: {featured: true},
4209
+ order: 'id DESC',
4210
+ skip: 0,
4211
+ limit: 10,
4212
+ fields: 'barId',
4213
+ include: {
4214
+ nbv: undefined,
4215
+ ewq: undefined,
4216
+ },
4217
+ },
4218
+ },
4219
+ dsa: {
4220
+ relation: 'cxz',
4221
+ scope: {
4222
+ where: {removed: false},
4223
+ order: 'createdAt DESC',
4224
+ skip: 10,
4225
+ limit: 0,
4226
+ fields: 'asdId',
4227
+ include: {
4228
+ ytr: undefined,
4229
+ hgf: undefined,
4230
+ },
4231
+ },
4232
+ },
4233
+ },
4234
+ ]);
4235
+ expect(result).to.be.eql([
4236
+ {
4237
+ relation: 'foo',
4238
+ scope: {
4239
+ include: [
4240
+ {
4241
+ relation: 'bar',
4242
+ scope: {
4243
+ where: {featured: true},
4244
+ order: 'id DESC',
4245
+ skip: 0,
4246
+ limit: 10,
4247
+ fields: 'barId',
4248
+ include: [
4249
+ {
4250
+ relation: 'baz',
4251
+ },
4252
+ {
4253
+ relation: 'ewq',
4254
+ },
4255
+ ],
4256
+ },
4257
+ },
4258
+ ],
4259
+ },
4260
+ },
4261
+ {
4262
+ relation: 'qwe',
4263
+ scope: {
4264
+ include: [
4265
+ {
4266
+ relation: 'asd',
4267
+ scope: {
4268
+ where: {removed: false},
4269
+ order: 'createdAt DESC',
4270
+ skip: 10,
4271
+ limit: 0,
4272
+ fields: 'asdId',
4273
+ include: [
4274
+ {
4275
+ relation: 'zxc',
4276
+ },
4277
+ {
4278
+ relation: 'fgh',
4279
+ },
4280
+ ],
4281
+ },
4282
+ },
4283
+ ],
4284
+ },
4285
+ },
4286
+ {
4287
+ relation: 'ytr',
4288
+ scope: {
4289
+ include: [
4290
+ {
4291
+ relation: 'hgf',
4292
+ scope: {
4293
+ where: {featured: true},
4294
+ order: 'id DESC',
4295
+ skip: 0,
4296
+ limit: 10,
4297
+ fields: 'barId',
4298
+ include: [
4299
+ {
4300
+ relation: 'nbv',
4301
+ },
4302
+ {
4303
+ relation: 'ewq',
4304
+ },
4305
+ ],
4306
+ },
4307
+ },
4308
+ ],
4309
+ },
4310
+ },
4311
+ {
4312
+ relation: 'dsa',
4313
+ scope: {
4314
+ include: [
4315
+ {
4316
+ relation: 'cxz',
4317
+ scope: {
4318
+ where: {removed: false},
4319
+ order: 'createdAt DESC',
4320
+ skip: 10,
4321
+ limit: 0,
4322
+ fields: 'asdId',
4323
+ include: [
4324
+ {
4325
+ relation: 'ytr',
4326
+ },
4327
+ {
4328
+ relation: 'hgf',
4329
+ },
4330
+ ],
4331
+ },
4332
+ },
4333
+ ],
4334
+ },
4335
+ },
4336
+ ]);
631
4337
  });
632
4338
 
633
- it('throws an error for duplicates', function () {
634
- const validate = v => () => IncludeClauseTool.normalizeIncludeClause(v);
635
- const error = 'The provided option "include" has duplicates of "foo".';
636
- const clauses = [
637
- ['foo', 'foo'],
638
- [['foo'], 'foo'],
639
- ['foo', ['foo']],
640
- [['foo'], ['foo']],
641
- ['foo', {foo: 'bar'}],
642
- [{foo: 'bar'}, 'foo'],
643
- [{foo: 'bar'}, {foo: 'bar'}],
644
- [[{foo: 'bar'}], 'foo'],
645
- ['foo', [{foo: 'bar'}]],
646
- [[{foo: 'bar'}], [{foo: 'bar'}]],
647
- ];
648
- clauses.forEach(c => expect(validate(c)).to.throw(error));
649
- validate({foo: 'foo'})();
650
- validate([{foo: 'foo'}])();
4339
+ it('normalizes the given array of key-value objects with an inclusion object with an array of key-value objects with null', function () {
4340
+ const result = IncludeClauseTool.normalizeIncludeClause([
4341
+ {
4342
+ foo: {
4343
+ relation: 'bar',
4344
+ scope: {
4345
+ where: {featured: true},
4346
+ order: 'id DESC',
4347
+ skip: 0,
4348
+ limit: 10,
4349
+ fields: 'barId',
4350
+ include: {
4351
+ baz: null,
4352
+ ewq: null,
4353
+ },
4354
+ },
4355
+ },
4356
+ qwe: {
4357
+ relation: 'asd',
4358
+ scope: {
4359
+ where: {removed: false},
4360
+ order: 'createdAt DESC',
4361
+ skip: 10,
4362
+ limit: 0,
4363
+ fields: 'asdId',
4364
+ include: {
4365
+ zxc: null,
4366
+ fgh: null,
4367
+ },
4368
+ },
4369
+ },
4370
+ },
4371
+ {
4372
+ ytr: {
4373
+ relation: 'hgf',
4374
+ scope: {
4375
+ where: {featured: true},
4376
+ order: 'id DESC',
4377
+ skip: 0,
4378
+ limit: 10,
4379
+ fields: 'barId',
4380
+ include: {
4381
+ nbv: null,
4382
+ ewq: null,
4383
+ },
4384
+ },
4385
+ },
4386
+ dsa: {
4387
+ relation: 'cxz',
4388
+ scope: {
4389
+ where: {removed: false},
4390
+ order: 'createdAt DESC',
4391
+ skip: 10,
4392
+ limit: 0,
4393
+ fields: 'asdId',
4394
+ include: {
4395
+ ytr: null,
4396
+ hgf: null,
4397
+ },
4398
+ },
4399
+ },
4400
+ },
4401
+ ]);
4402
+ expect(result).to.be.eql([
4403
+ {
4404
+ relation: 'foo',
4405
+ scope: {
4406
+ include: [
4407
+ {
4408
+ relation: 'bar',
4409
+ scope: {
4410
+ where: {featured: true},
4411
+ order: 'id DESC',
4412
+ skip: 0,
4413
+ limit: 10,
4414
+ fields: 'barId',
4415
+ include: [
4416
+ {
4417
+ relation: 'baz',
4418
+ },
4419
+ {
4420
+ relation: 'ewq',
4421
+ },
4422
+ ],
4423
+ },
4424
+ },
4425
+ ],
4426
+ },
4427
+ },
4428
+ {
4429
+ relation: 'qwe',
4430
+ scope: {
4431
+ include: [
4432
+ {
4433
+ relation: 'asd',
4434
+ scope: {
4435
+ where: {removed: false},
4436
+ order: 'createdAt DESC',
4437
+ skip: 10,
4438
+ limit: 0,
4439
+ fields: 'asdId',
4440
+ include: [
4441
+ {
4442
+ relation: 'zxc',
4443
+ },
4444
+ {
4445
+ relation: 'fgh',
4446
+ },
4447
+ ],
4448
+ },
4449
+ },
4450
+ ],
4451
+ },
4452
+ },
4453
+ {
4454
+ relation: 'ytr',
4455
+ scope: {
4456
+ include: [
4457
+ {
4458
+ relation: 'hgf',
4459
+ scope: {
4460
+ where: {featured: true},
4461
+ order: 'id DESC',
4462
+ skip: 0,
4463
+ limit: 10,
4464
+ fields: 'barId',
4465
+ include: [
4466
+ {
4467
+ relation: 'nbv',
4468
+ },
4469
+ {
4470
+ relation: 'ewq',
4471
+ },
4472
+ ],
4473
+ },
4474
+ },
4475
+ ],
4476
+ },
4477
+ },
4478
+ {
4479
+ relation: 'dsa',
4480
+ scope: {
4481
+ include: [
4482
+ {
4483
+ relation: 'cxz',
4484
+ scope: {
4485
+ where: {removed: false},
4486
+ order: 'createdAt DESC',
4487
+ skip: 10,
4488
+ limit: 0,
4489
+ fields: 'asdId',
4490
+ include: [
4491
+ {
4492
+ relation: 'ytr',
4493
+ },
4494
+ {
4495
+ relation: 'hgf',
4496
+ },
4497
+ ],
4498
+ },
4499
+ },
4500
+ ],
4501
+ },
4502
+ },
4503
+ ]);
4504
+ });
4505
+
4506
+ it('normalizes the given array of key-value objects with an inclusion object with an array of key-value objects with an array of strings', function () {
4507
+ const result = IncludeClauseTool.normalizeIncludeClause([
4508
+ {
4509
+ foo: {
4510
+ relation: 'bar',
4511
+ scope: {
4512
+ where: {featured: true},
4513
+ order: 'id DESC',
4514
+ skip: 0,
4515
+ limit: 10,
4516
+ fields: 'barId',
4517
+ include: {
4518
+ baz: ['qux', 'xuq'],
4519
+ ewq: ['dsa', 'asd'],
4520
+ },
4521
+ },
4522
+ },
4523
+ qwe: {
4524
+ relation: 'asd',
4525
+ scope: {
4526
+ where: {removed: false},
4527
+ order: 'createdAt DESC',
4528
+ skip: 10,
4529
+ limit: 0,
4530
+ fields: 'asdId',
4531
+ include: {
4532
+ zxc: ['rty', 'ytr'],
4533
+ fgh: ['vbn', 'nbv'],
4534
+ },
4535
+ },
4536
+ },
4537
+ },
4538
+ {
4539
+ ytr: {
4540
+ relation: 'hgf',
4541
+ scope: {
4542
+ where: {featured: true},
4543
+ order: 'id DESC',
4544
+ skip: 0,
4545
+ limit: 10,
4546
+ fields: 'barId',
4547
+ include: {
4548
+ nbv: ['ewq', 'dsa'],
4549
+ cxz: ['rty', 'fgh'],
4550
+ },
4551
+ },
4552
+ },
4553
+ ewq: {
4554
+ relation: 'dsa',
4555
+ scope: {
4556
+ where: {removed: false},
4557
+ order: 'createdAt DESC',
4558
+ skip: 10,
4559
+ limit: 0,
4560
+ fields: 'asdId',
4561
+ include: {
4562
+ cxz: ['ytr', 'hgf'],
4563
+ nbv: ['qwe', 'asd'],
4564
+ },
4565
+ },
4566
+ },
4567
+ },
4568
+ ]);
4569
+ expect(result).to.be.eql([
4570
+ {
4571
+ relation: 'foo',
4572
+ scope: {
4573
+ include: [
4574
+ {
4575
+ relation: 'bar',
4576
+ scope: {
4577
+ where: {featured: true},
4578
+ order: 'id DESC',
4579
+ skip: 0,
4580
+ limit: 10,
4581
+ fields: 'barId',
4582
+ include: [
4583
+ {
4584
+ relation: 'baz',
4585
+ scope: {
4586
+ include: [
4587
+ {
4588
+ relation: 'qux',
4589
+ },
4590
+ {
4591
+ relation: 'xuq',
4592
+ },
4593
+ ],
4594
+ },
4595
+ },
4596
+ {
4597
+ relation: 'ewq',
4598
+ scope: {
4599
+ include: [
4600
+ {
4601
+ relation: 'dsa',
4602
+ },
4603
+ {
4604
+ relation: 'asd',
4605
+ },
4606
+ ],
4607
+ },
4608
+ },
4609
+ ],
4610
+ },
4611
+ },
4612
+ ],
4613
+ },
4614
+ },
4615
+ {
4616
+ relation: 'qwe',
4617
+ scope: {
4618
+ include: [
4619
+ {
4620
+ relation: 'asd',
4621
+ scope: {
4622
+ where: {removed: false},
4623
+ order: 'createdAt DESC',
4624
+ skip: 10,
4625
+ limit: 0,
4626
+ fields: 'asdId',
4627
+ include: [
4628
+ {
4629
+ relation: 'zxc',
4630
+ scope: {
4631
+ include: [
4632
+ {
4633
+ relation: 'rty',
4634
+ },
4635
+ {
4636
+ relation: 'ytr',
4637
+ },
4638
+ ],
4639
+ },
4640
+ },
4641
+ {
4642
+ relation: 'fgh',
4643
+ scope: {
4644
+ include: [
4645
+ {
4646
+ relation: 'vbn',
4647
+ },
4648
+ {
4649
+ relation: 'nbv',
4650
+ },
4651
+ ],
4652
+ },
4653
+ },
4654
+ ],
4655
+ },
4656
+ },
4657
+ ],
4658
+ },
4659
+ },
4660
+ {
4661
+ relation: 'ytr',
4662
+ scope: {
4663
+ include: [
4664
+ {
4665
+ relation: 'hgf',
4666
+ scope: {
4667
+ where: {featured: true},
4668
+ order: 'id DESC',
4669
+ skip: 0,
4670
+ limit: 10,
4671
+ fields: 'barId',
4672
+ include: [
4673
+ {
4674
+ relation: 'nbv',
4675
+ scope: {
4676
+ include: [
4677
+ {
4678
+ relation: 'ewq',
4679
+ },
4680
+ {
4681
+ relation: 'dsa',
4682
+ },
4683
+ ],
4684
+ },
4685
+ },
4686
+ {
4687
+ relation: 'cxz',
4688
+ scope: {
4689
+ include: [
4690
+ {
4691
+ relation: 'rty',
4692
+ },
4693
+ {
4694
+ relation: 'fgh',
4695
+ },
4696
+ ],
4697
+ },
4698
+ },
4699
+ ],
4700
+ },
4701
+ },
4702
+ ],
4703
+ },
4704
+ },
4705
+ {
4706
+ relation: 'ewq',
4707
+ scope: {
4708
+ include: [
4709
+ {
4710
+ relation: 'dsa',
4711
+ scope: {
4712
+ where: {removed: false},
4713
+ order: 'createdAt DESC',
4714
+ skip: 10,
4715
+ limit: 0,
4716
+ fields: 'asdId',
4717
+ include: [
4718
+ {
4719
+ relation: 'cxz',
4720
+ scope: {
4721
+ include: [
4722
+ {
4723
+ relation: 'ytr',
4724
+ },
4725
+ {
4726
+ relation: 'hgf',
4727
+ },
4728
+ ],
4729
+ },
4730
+ },
4731
+ {
4732
+ relation: 'nbv',
4733
+ scope: {
4734
+ include: [
4735
+ {
4736
+ relation: 'qwe',
4737
+ },
4738
+ {
4739
+ relation: 'asd',
4740
+ },
4741
+ ],
4742
+ },
4743
+ },
4744
+ ],
4745
+ },
4746
+ },
4747
+ ],
4748
+ },
4749
+ },
4750
+ ]);
651
4751
  });
652
4752
  });
653
4753
  });