@e22m4u/js-repository 0.2.6 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +79 -80
  2. package/dist/cjs/index.cjs +2023 -2093
  3. package/eslint.config.js +1 -1
  4. package/package.json +15 -12
  5. package/src/adapter/adapter-registry.spec.js +7 -7
  6. package/src/adapter/adapter.spec.js +11 -11
  7. package/src/adapter/builtin/memory-adapter.spec.js +537 -537
  8. package/src/adapter/decorator/data-sanitizing-decorator.spec.js +5 -5
  9. package/src/adapter/decorator/data-transformation-decorator.spec.js +5 -5
  10. package/src/adapter/decorator/data-validation-decorator.spec.js +5 -5
  11. package/src/adapter/decorator/default-values-decorator.spec.js +5 -5
  12. package/src/adapter/decorator/fields-filtering-decorator.spec.js +5 -5
  13. package/src/adapter/decorator/inclusion-decorator.spec.js +5 -5
  14. package/src/adapter/decorator/property-uniqueness-decorator.spec.js +5 -5
  15. package/src/{schema.d.ts → database-schema.d.ts} +2 -2
  16. package/src/{schema.js → database-schema.js} +2 -2
  17. package/src/database-schema.spec.ts +86 -0
  18. package/src/definition/model/model-data-transformer.js +3 -3
  19. package/src/definition/model/model-data-transformer.spec.js +93 -93
  20. package/src/definition/model/model-data-validator.js +2 -2
  21. package/src/definition/model/model-data-validator.spec.js +517 -531
  22. package/src/definition/model/model-definition-utils.js +3 -3
  23. package/src/definition/model/model-definition-utils.spec.js +345 -343
  24. package/src/definition/model/properties/index.d.ts +0 -1
  25. package/src/definition/model/properties/index.js +0 -1
  26. package/src/definition/model/properties/property-transformer/property-transformer-registry.spec.js +36 -36
  27. package/src/definition/model/properties/property-uniqueness-validator.js +3 -3
  28. package/src/definition/model/properties/property-uniqueness-validator.spec.js +417 -384
  29. package/src/definition/model/properties/property-validator/property-validator-registry.spec.js +36 -36
  30. package/src/filter/fields-clause-tool.spec.js +4 -4
  31. package/src/index.d.ts +1 -1
  32. package/src/index.js +1 -1
  33. package/src/relations/belongs-to-resolver.spec.js +166 -166
  34. package/src/relations/has-many-resolver.spec.js +281 -281
  35. package/src/relations/has-one-resolver.spec.js +281 -281
  36. package/src/relations/references-many-resolver.spec.js +92 -92
  37. package/src/repository/repository-registry.spec.js +10 -10
  38. package/src/repository/repository.spec.js +73 -73
  39. package/src/utils/is-promise.spec.js +1 -2
  40. package/src/utils/transform-promise.spec.js +0 -1
  41. package/src/definition/model/properties/empty-values-definer.d.ts +0 -23
  42. package/src/definition/model/properties/empty-values-definer.js +0 -66
  43. package/src/definition/model/properties/empty-values-definer.spec.js +0 -96
  44. package/src/schema.spec.ts +0 -86
@@ -1,17 +1,17 @@
1
1
  import {expect} from 'chai';
2
2
  import {DataType} from './data-type.js';
3
3
  import {format} from '@e22m4u/js-format';
4
- import {Schema} from '../../../schema.js';
4
+ import {DatabaseSchema} from '../../../database-schema.js';
5
+ import {EmptyValuesService} from '@e22m4u/js-empty-values';
5
6
  import {PropertyUniqueness} from './property-uniqueness.js';
6
- import {EmptyValuesDefiner} from './empty-values-definer.js';
7
7
  import {PropertyUniquenessValidator} from './property-uniqueness-validator.js';
8
8
  import {DEFAULT_PRIMARY_KEY_PROPERTY_NAME as DEF_PK} from '../model-definition-utils.js';
9
9
 
10
10
  describe('PropertyUniquenessValidator', function () {
11
11
  describe('validate', function () {
12
12
  it('requires the parameter "countMethod" to be a Function', async function () {
13
- const schema = new Schema();
14
- schema.defineModel({
13
+ const dbs = new DatabaseSchema();
14
+ dbs.defineModel({
15
15
  name: 'model',
16
16
  properties: {
17
17
  foo: {
@@ -20,8 +20,8 @@ describe('PropertyUniquenessValidator', function () {
20
20
  },
21
21
  },
22
22
  });
23
- const S = schema.getService(PropertyUniquenessValidator);
24
- const throwable = v => S.validate(v, 'create', 'model', {});
23
+ const puv = dbs.getService(PropertyUniquenessValidator);
24
+ const throwable = v => puv.validate(v, 'create', 'model', {});
25
25
  const error = v =>
26
26
  format(
27
27
  'The parameter "countMethod" of the PropertyUniquenessValidator ' +
@@ -45,8 +45,8 @@ describe('PropertyUniquenessValidator', function () {
45
45
  });
46
46
 
47
47
  it('requires the parameter "methodName" to be a non-empty String', async function () {
48
- const schema = new Schema();
49
- schema.defineModel({
48
+ const dbs = new DatabaseSchema();
49
+ dbs.defineModel({
50
50
  name: 'model',
51
51
  properties: {
52
52
  foo: {
@@ -55,8 +55,8 @@ describe('PropertyUniquenessValidator', function () {
55
55
  },
56
56
  },
57
57
  });
58
- const S = schema.getService(PropertyUniquenessValidator);
59
- const throwable = v => S.validate(() => 0, v, 'model', {});
58
+ const puv = dbs.getService(PropertyUniquenessValidator);
59
+ const throwable = v => puv.validate(() => 0, v, 'model', {});
60
60
  const error = v =>
61
61
  format(
62
62
  'The parameter "methodName" of the PropertyUniquenessValidator ' +
@@ -80,8 +80,8 @@ describe('PropertyUniquenessValidator', function () {
80
80
  });
81
81
 
82
82
  it('requires the parameter "modelName" to be a non-empty String', async function () {
83
- const schema = new Schema();
84
- schema.defineModel({
83
+ const dbs = new DatabaseSchema();
84
+ dbs.defineModel({
85
85
  name: 'model',
86
86
  properties: {
87
87
  foo: {
@@ -90,8 +90,8 @@ describe('PropertyUniquenessValidator', function () {
90
90
  },
91
91
  },
92
92
  });
93
- const S = schema.getService(PropertyUniquenessValidator);
94
- const throwable = v => S.validate(() => 0, 'create', v, {});
93
+ const puv = dbs.getService(PropertyUniquenessValidator);
94
+ const throwable = v => puv.validate(() => 0, 'create', v, {});
95
95
  const error = v =>
96
96
  format(
97
97
  'The parameter "modelName" of the PropertyUniquenessValidator ' +
@@ -115,8 +115,8 @@ describe('PropertyUniquenessValidator', function () {
115
115
  });
116
116
 
117
117
  it('requires the parameter "modelData" to be a pure Object', async function () {
118
- const schema = new Schema();
119
- schema.defineModel({
118
+ const dbs = new DatabaseSchema();
119
+ dbs.defineModel({
120
120
  name: 'model',
121
121
  properties: {
122
122
  foo: {
@@ -125,8 +125,8 @@ describe('PropertyUniquenessValidator', function () {
125
125
  },
126
126
  },
127
127
  });
128
- const S = schema.getService(PropertyUniquenessValidator);
129
- const throwable = v => S.validate(() => 0, 'create', 'model', v);
128
+ const puv = dbs.getService(PropertyUniquenessValidator);
129
+ const throwable = v => puv.validate(() => 0, 'create', 'model', v);
130
130
  const error = v =>
131
131
  format(
132
132
  'The data of the model "model" should be an Object, but %s given.',
@@ -149,8 +149,8 @@ describe('PropertyUniquenessValidator', function () {
149
149
  });
150
150
 
151
151
  it('skips checking if the option "unique" is not provided', async function () {
152
- const schema = new Schema();
153
- schema.defineModel({
152
+ const dbs = new DatabaseSchema();
153
+ dbs.defineModel({
154
154
  name: 'model',
155
155
  properties: {
156
156
  foo: DataType.ANY,
@@ -159,14 +159,14 @@ describe('PropertyUniquenessValidator', function () {
159
159
  },
160
160
  },
161
161
  });
162
- const S = schema.getService(PropertyUniquenessValidator);
163
- const promise = S.validate(() => 1, 'create', 'model', {});
162
+ const puv = dbs.getService(PropertyUniquenessValidator);
163
+ const promise = puv.validate(() => 1, 'create', 'model', {});
164
164
  await expect(promise).not.to.be.rejected;
165
165
  });
166
166
 
167
167
  it('skips checking if the option "unique" is undefined', async function () {
168
- const schema = new Schema();
169
- schema.defineModel({
168
+ const dbs = new DatabaseSchema();
169
+ dbs.defineModel({
170
170
  name: 'model',
171
171
  properties: {
172
172
  foo: {
@@ -175,14 +175,14 @@ describe('PropertyUniquenessValidator', function () {
175
175
  },
176
176
  },
177
177
  });
178
- const S = schema.getService(PropertyUniquenessValidator);
179
- const promise = S.validate(() => 1, 'create', 'model', {});
178
+ const puv = dbs.getService(PropertyUniquenessValidator);
179
+ const promise = puv.validate(() => 1, 'create', 'model', {});
180
180
  await expect(promise).not.to.be.rejected;
181
181
  });
182
182
 
183
183
  it('skips checking if the option "unique" is null', async function () {
184
- const schema = new Schema();
185
- schema.defineModel({
184
+ const dbs = new DatabaseSchema();
185
+ dbs.defineModel({
186
186
  name: 'model',
187
187
  properties: {
188
188
  foo: {
@@ -191,14 +191,14 @@ describe('PropertyUniquenessValidator', function () {
191
191
  },
192
192
  },
193
193
  });
194
- const S = schema.getService(PropertyUniquenessValidator);
195
- const promise = S.validate(() => 1, 'create', 'model', {});
194
+ const puv = dbs.getService(PropertyUniquenessValidator);
195
+ const promise = puv.validate(() => 1, 'create', 'model', {});
196
196
  await expect(promise).not.to.be.rejected;
197
197
  });
198
198
 
199
199
  it('skips checking if the option "unique" is false', async function () {
200
- const schema = new Schema();
201
- schema.defineModel({
200
+ const dbs = new DatabaseSchema();
201
+ dbs.defineModel({
202
202
  name: 'model',
203
203
  properties: {
204
204
  foo: {
@@ -207,14 +207,14 @@ describe('PropertyUniquenessValidator', function () {
207
207
  },
208
208
  },
209
209
  });
210
- const S = schema.getService(PropertyUniquenessValidator);
211
- const promise = S.validate(() => 1, 'create', 'model', {});
210
+ const puv = dbs.getService(PropertyUniquenessValidator);
211
+ const promise = puv.validate(() => 1, 'create', 'model', {});
212
212
  await expect(promise).not.to.be.rejected;
213
213
  });
214
214
 
215
215
  it('skips checking if the option "unique" is "nonUnique"', async function () {
216
- const schema = new Schema();
217
- schema.defineModel({
216
+ const dbs = new DatabaseSchema();
217
+ dbs.defineModel({
218
218
  name: 'model',
219
219
  properties: {
220
220
  foo: {
@@ -223,14 +223,14 @@ describe('PropertyUniquenessValidator', function () {
223
223
  },
224
224
  },
225
225
  });
226
- const S = schema.getService(PropertyUniquenessValidator);
227
- const promise = S.validate(() => 1, 'create', 'model', {});
226
+ const puv = dbs.getService(PropertyUniquenessValidator);
227
+ const promise = puv.validate(() => 1, 'create', 'model', {});
228
228
  await expect(promise).not.to.be.rejected;
229
229
  });
230
230
 
231
231
  it('throws an error for unsupported method', async function () {
232
- const schema = new Schema();
233
- schema.defineModel({
232
+ const dbs = new DatabaseSchema();
233
+ dbs.defineModel({
234
234
  name: 'model',
235
235
  properties: {
236
236
  foo: {
@@ -239,8 +239,8 @@ describe('PropertyUniquenessValidator', function () {
239
239
  },
240
240
  },
241
241
  });
242
- const S = schema.getService(PropertyUniquenessValidator);
243
- const promise = S.validate(() => 1, 'unsupported', 'model', {});
242
+ const puv = dbs.getService(PropertyUniquenessValidator);
243
+ const promise = puv.validate(() => 1, 'unsupported', 'model', {});
244
244
  await expect(promise).to.be.rejectedWith(
245
245
  'The PropertyUniquenessValidator does not ' +
246
246
  'support the adapter method "unsupported".',
@@ -250,8 +250,8 @@ describe('PropertyUniquenessValidator', function () {
250
250
  describe('the "unique" option is true', function () {
251
251
  describe('create', function () {
252
252
  it('throws an error if the "countMethod" returns a positive number', async function () {
253
- const schema = new Schema();
254
- schema.defineModel({
253
+ const dbs = new DatabaseSchema();
254
+ dbs.defineModel({
255
255
  name: 'model',
256
256
  properties: {
257
257
  foo: {
@@ -260,8 +260,10 @@ describe('PropertyUniquenessValidator', function () {
260
260
  },
261
261
  },
262
262
  });
263
- const S = schema.getService(PropertyUniquenessValidator);
264
- const promise = S.validate(() => 1, 'create', 'model', {foo: 'bar'});
263
+ const puv = dbs.getService(PropertyUniquenessValidator);
264
+ const promise = puv.validate(() => 1, 'create', 'model', {
265
+ foo: 'bar',
266
+ });
265
267
  await expect(promise).to.be.rejectedWith(
266
268
  'An existing document of the model "model" already has ' +
267
269
  'the property "foo" with the value "bar" and should be unique.',
@@ -269,8 +271,8 @@ describe('PropertyUniquenessValidator', function () {
269
271
  });
270
272
 
271
273
  it('passes validation if the "countMethod" returns zero', async function () {
272
- const schema = new Schema();
273
- schema.defineModel({
274
+ const dbs = new DatabaseSchema();
275
+ dbs.defineModel({
274
276
  name: 'model',
275
277
  properties: {
276
278
  foo: {
@@ -279,13 +281,13 @@ describe('PropertyUniquenessValidator', function () {
279
281
  },
280
282
  },
281
283
  });
282
- const S = schema.getService(PropertyUniquenessValidator);
283
- await S.validate(() => 0, 'create', 'model', {foo: 'bar'});
284
+ const puv = dbs.getService(PropertyUniquenessValidator);
285
+ await puv.validate(() => 0, 'create', 'model', {foo: 'bar'});
284
286
  });
285
287
 
286
288
  it('invokes the "countMethod" for each unique property of the model', async function () {
287
- const schema = new Schema();
288
- schema.defineModel({
289
+ const dbs = new DatabaseSchema();
290
+ dbs.defineModel({
289
291
  name: 'model',
290
292
  properties: {
291
293
  foo: {
@@ -302,7 +304,7 @@ describe('PropertyUniquenessValidator', function () {
302
304
  },
303
305
  },
304
306
  });
305
- const S = schema.getService(PropertyUniquenessValidator);
307
+ const puv = dbs.getService(PropertyUniquenessValidator);
306
308
  let invoked = 0;
307
309
  const modelData = {foo: 'val1', bar: 'val2'};
308
310
  const countMethod = where => {
@@ -314,15 +316,15 @@ describe('PropertyUniquenessValidator', function () {
314
316
  invoked++;
315
317
  return 0;
316
318
  };
317
- await S.validate(countMethod, 'create', 'model', modelData);
319
+ await puv.validate(countMethod, 'create', 'model', modelData);
318
320
  expect(invoked).to.be.eq(2);
319
321
  });
320
322
  });
321
323
 
322
324
  describe('replaceById', function () {
323
325
  it('throws an error if the "countMethod" returns a positive number', async function () {
324
- const schema = new Schema();
325
- schema.defineModel({
326
+ const dbs = new DatabaseSchema();
327
+ dbs.defineModel({
326
328
  name: 'model',
327
329
  properties: {
328
330
  foo: {
@@ -331,8 +333,8 @@ describe('PropertyUniquenessValidator', function () {
331
333
  },
332
334
  },
333
335
  });
334
- const S = schema.getService(PropertyUniquenessValidator);
335
- const promise = S.validate(
336
+ const puv = dbs.getService(PropertyUniquenessValidator);
337
+ const promise = puv.validate(
336
338
  () => 1,
337
339
  'replaceById',
338
340
  'model',
@@ -346,8 +348,8 @@ describe('PropertyUniquenessValidator', function () {
346
348
  });
347
349
 
348
350
  it('passes validation if the "countMethod" returns zero', async function () {
349
- const schema = new Schema();
350
- schema.defineModel({
351
+ const dbs = new DatabaseSchema();
352
+ dbs.defineModel({
351
353
  name: 'model',
352
354
  properties: {
353
355
  foo: {
@@ -356,13 +358,13 @@ describe('PropertyUniquenessValidator', function () {
356
358
  },
357
359
  },
358
360
  });
359
- const S = schema.getService(PropertyUniquenessValidator);
360
- await S.validate(() => 0, 'replaceById', 'model', {foo: 'bar'}, 1);
361
+ const puv = dbs.getService(PropertyUniquenessValidator);
362
+ await puv.validate(() => 0, 'replaceById', 'model', {foo: 'bar'}, 1);
361
363
  });
362
364
 
363
365
  it('invokes the "countMethod" for each unique property of the model', async function () {
364
- const schema = new Schema();
365
- schema.defineModel({
366
+ const dbs = new DatabaseSchema();
367
+ dbs.defineModel({
366
368
  name: 'model',
367
369
  properties: {
368
370
  foo: {
@@ -379,7 +381,7 @@ describe('PropertyUniquenessValidator', function () {
379
381
  },
380
382
  },
381
383
  });
382
- const S = schema.getService(PropertyUniquenessValidator);
384
+ const puv = dbs.getService(PropertyUniquenessValidator);
383
385
  let invoked = 0;
384
386
  const idValue = 1;
385
387
  const modelData = {foo: 'val1', bar: 'val2'};
@@ -398,7 +400,7 @@ describe('PropertyUniquenessValidator', function () {
398
400
  invoked++;
399
401
  return 0;
400
402
  };
401
- await S.validate(
403
+ await puv.validate(
402
404
  countMethod,
403
405
  'replaceById',
404
406
  'model',
@@ -409,8 +411,8 @@ describe('PropertyUniquenessValidator', function () {
409
411
  });
410
412
 
411
413
  it('can use a custom primary key', async function () {
412
- const schema = new Schema();
413
- schema.defineModel({
414
+ const dbs = new DatabaseSchema();
415
+ dbs.defineModel({
414
416
  name: 'model',
415
417
  properties: {
416
418
  myId: {
@@ -423,7 +425,7 @@ describe('PropertyUniquenessValidator', function () {
423
425
  },
424
426
  },
425
427
  });
426
- const S = schema.getService(PropertyUniquenessValidator);
428
+ const puv = dbs.getService(PropertyUniquenessValidator);
427
429
  let invoked = 0;
428
430
  const idValue = 1;
429
431
  const modelData = {foo: 'bar'};
@@ -436,7 +438,7 @@ describe('PropertyUniquenessValidator', function () {
436
438
  invoked++;
437
439
  return 0;
438
440
  };
439
- await S.validate(
441
+ await puv.validate(
440
442
  countMethod,
441
443
  'replaceById',
442
444
  'model',
@@ -449,8 +451,8 @@ describe('PropertyUniquenessValidator', function () {
449
451
 
450
452
  describe('replaceOrCreate', function () {
451
453
  it('throws an error if the "countMethod" returns a positive number', async function () {
452
- const schema = new Schema();
453
- schema.defineModel({
454
+ const dbs = new DatabaseSchema();
455
+ dbs.defineModel({
454
456
  name: 'model',
455
457
  properties: {
456
458
  foo: {
@@ -459,8 +461,8 @@ describe('PropertyUniquenessValidator', function () {
459
461
  },
460
462
  },
461
463
  });
462
- const S = schema.getService(PropertyUniquenessValidator);
463
- const promise = S.validate(() => 1, 'replaceOrCreate', 'model', {
464
+ const puv = dbs.getService(PropertyUniquenessValidator);
465
+ const promise = puv.validate(() => 1, 'replaceOrCreate', 'model', {
464
466
  foo: 'bar',
465
467
  });
466
468
  await expect(promise).to.be.rejectedWith(
@@ -470,8 +472,8 @@ describe('PropertyUniquenessValidator', function () {
470
472
  });
471
473
 
472
474
  it('passes validation if the "countMethod" returns zero', async function () {
473
- const schema = new Schema();
474
- schema.defineModel({
475
+ const dbs = new DatabaseSchema();
476
+ dbs.defineModel({
475
477
  name: 'model',
476
478
  properties: {
477
479
  foo: {
@@ -480,13 +482,13 @@ describe('PropertyUniquenessValidator', function () {
480
482
  },
481
483
  },
482
484
  });
483
- const S = schema.getService(PropertyUniquenessValidator);
484
- await S.validate(() => 0, 'replaceOrCreate', 'model', {foo: 'bar'});
485
+ const puv = dbs.getService(PropertyUniquenessValidator);
486
+ await puv.validate(() => 0, 'replaceOrCreate', 'model', {foo: 'bar'});
485
487
  });
486
488
 
487
489
  it('invokes the "countMethod" for each unique property of the model', async function () {
488
- const schema = new Schema();
489
- schema.defineModel({
490
+ const dbs = new DatabaseSchema();
491
+ dbs.defineModel({
490
492
  name: 'model',
491
493
  properties: {
492
494
  foo: {
@@ -503,7 +505,7 @@ describe('PropertyUniquenessValidator', function () {
503
505
  },
504
506
  },
505
507
  });
506
- const S = schema.getService(PropertyUniquenessValidator);
508
+ const puv = dbs.getService(PropertyUniquenessValidator);
507
509
  let invoked = 0;
508
510
  const modelData = {foo: 'val1', bar: 'val2'};
509
511
  const countMethod = where => {
@@ -515,15 +517,20 @@ describe('PropertyUniquenessValidator', function () {
515
517
  invoked++;
516
518
  return 0;
517
519
  };
518
- await S.validate(countMethod, 'replaceOrCreate', 'model', modelData);
520
+ await puv.validate(
521
+ countMethod,
522
+ 'replaceOrCreate',
523
+ 'model',
524
+ modelData,
525
+ );
519
526
  expect(invoked).to.be.eq(2);
520
527
  });
521
528
 
522
529
  describe('in case that the given model has a document identifier', function () {
523
530
  describe('a document of the given identifier does not exist', function () {
524
531
  it('uses the default primary key to check existence of the given identifier', async function () {
525
- const schema = new Schema();
526
- schema.defineModel({
532
+ const dbs = new DatabaseSchema();
533
+ dbs.defineModel({
527
534
  name: 'model',
528
535
  properties: {
529
536
  foo: {
@@ -532,7 +539,7 @@ describe('PropertyUniquenessValidator', function () {
532
539
  },
533
540
  },
534
541
  });
535
- const S = schema.getService(PropertyUniquenessValidator);
542
+ const puv = dbs.getService(PropertyUniquenessValidator);
536
543
  let invoked = 0;
537
544
  const idValue = 1;
538
545
  const modelData = {[DEF_PK]: idValue, foo: 'bar'};
@@ -545,7 +552,7 @@ describe('PropertyUniquenessValidator', function () {
545
552
  invoked++;
546
553
  return 0;
547
554
  };
548
- await S.validate(
555
+ await puv.validate(
549
556
  countMethod,
550
557
  'replaceOrCreate',
551
558
  'model',
@@ -555,8 +562,8 @@ describe('PropertyUniquenessValidator', function () {
555
562
  });
556
563
 
557
564
  it('uses a custom primary key to check existence of the given identifier', async function () {
558
- const schema = new Schema();
559
- schema.defineModel({
565
+ const dbs = new DatabaseSchema();
566
+ dbs.defineModel({
560
567
  name: 'model',
561
568
  properties: {
562
569
  myId: {
@@ -569,7 +576,7 @@ describe('PropertyUniquenessValidator', function () {
569
576
  },
570
577
  },
571
578
  });
572
- const S = schema.getService(PropertyUniquenessValidator);
579
+ const puv = dbs.getService(PropertyUniquenessValidator);
573
580
  let invoked = 0;
574
581
  const idValue = 1;
575
582
  const modelData = {myId: idValue, foo: 'bar'};
@@ -582,7 +589,7 @@ describe('PropertyUniquenessValidator', function () {
582
589
  invoked++;
583
590
  return 0;
584
591
  };
585
- await S.validate(
592
+ await puv.validate(
586
593
  countMethod,
587
594
  'replaceOrCreate',
588
595
  'model',
@@ -593,8 +600,8 @@ describe('PropertyUniquenessValidator', function () {
593
600
  });
594
601
 
595
602
  it('checks the given identifier only once', async function () {
596
- const schema = new Schema();
597
- schema.defineModel({
603
+ const dbs = new DatabaseSchema();
604
+ dbs.defineModel({
598
605
  name: 'model',
599
606
  properties: {
600
607
  foo: {
@@ -607,7 +614,7 @@ describe('PropertyUniquenessValidator', function () {
607
614
  },
608
615
  },
609
616
  });
610
- const S = schema.getService(PropertyUniquenessValidator);
617
+ const puv = dbs.getService(PropertyUniquenessValidator);
611
618
  let invoked = 0;
612
619
  const idValue = 1;
613
620
  const modelData = {[DEF_PK]: idValue, foo: 'val1', bar: 'val2'};
@@ -622,7 +629,7 @@ describe('PropertyUniquenessValidator', function () {
622
629
  invoked++;
623
630
  return 0;
624
631
  };
625
- await S.validate(
632
+ await puv.validate(
626
633
  countMethod,
627
634
  'replaceOrCreate',
628
635
  'model',
@@ -634,8 +641,8 @@ describe('PropertyUniquenessValidator', function () {
634
641
 
635
642
  describe('a document of the given identifier already exist', function () {
636
643
  it('uses the default primary key to check existence of the given identifier', async function () {
637
- const schema = new Schema();
638
- schema.defineModel({
644
+ const dbs = new DatabaseSchema();
645
+ dbs.defineModel({
639
646
  name: 'model',
640
647
  properties: {
641
648
  foo: {
@@ -644,7 +651,7 @@ describe('PropertyUniquenessValidator', function () {
644
651
  },
645
652
  },
646
653
  });
647
- const S = schema.getService(PropertyUniquenessValidator);
654
+ const puv = dbs.getService(PropertyUniquenessValidator);
648
655
  let invoked = 0;
649
656
  const idValue = 1;
650
657
  const modelData = {
@@ -666,7 +673,7 @@ describe('PropertyUniquenessValidator', function () {
666
673
  return 0;
667
674
  }
668
675
  };
669
- await S.validate(
676
+ await puv.validate(
670
677
  countMethod,
671
678
  'replaceOrCreate',
672
679
  'model',
@@ -676,8 +683,8 @@ describe('PropertyUniquenessValidator', function () {
676
683
  });
677
684
 
678
685
  it('uses a custom primary key to check existence of the given identifier', async function () {
679
- const schema = new Schema();
680
- schema.defineModel({
686
+ const dbs = new DatabaseSchema();
687
+ dbs.defineModel({
681
688
  name: 'model',
682
689
  properties: {
683
690
  myId: {
@@ -690,7 +697,7 @@ describe('PropertyUniquenessValidator', function () {
690
697
  },
691
698
  },
692
699
  });
693
- const S = schema.getService(PropertyUniquenessValidator);
700
+ const puv = dbs.getService(PropertyUniquenessValidator);
694
701
  let invoked = 0;
695
702
  const idValue = 1;
696
703
  const modelData = {myId: idValue, foo: 'bar'};
@@ -709,7 +716,7 @@ describe('PropertyUniquenessValidator', function () {
709
716
  return 0;
710
717
  }
711
718
  };
712
- await S.validate(
719
+ await puv.validate(
713
720
  countMethod,
714
721
  'replaceOrCreate',
715
722
  'model',
@@ -720,8 +727,8 @@ describe('PropertyUniquenessValidator', function () {
720
727
  });
721
728
 
722
729
  it('checks the given identifier only once', async function () {
723
- const schema = new Schema();
724
- schema.defineModel({
730
+ const dbs = new DatabaseSchema();
731
+ dbs.defineModel({
725
732
  name: 'model',
726
733
  properties: {
727
734
  foo: {
@@ -734,7 +741,7 @@ describe('PropertyUniquenessValidator', function () {
734
741
  },
735
742
  },
736
743
  });
737
- const S = schema.getService(PropertyUniquenessValidator);
744
+ const puv = dbs.getService(PropertyUniquenessValidator);
738
745
  let invoked = 0;
739
746
  const idValue = 1;
740
747
  const modelData = {
@@ -761,7 +768,7 @@ describe('PropertyUniquenessValidator', function () {
761
768
  return 0;
762
769
  }
763
770
  };
764
- await S.validate(
771
+ await puv.validate(
765
772
  countMethod,
766
773
  'replaceOrCreate',
767
774
  'model',
@@ -775,8 +782,8 @@ describe('PropertyUniquenessValidator', function () {
775
782
 
776
783
  describe('patch', function () {
777
784
  it('throws an error if the "countMethod" returns a positive number', async function () {
778
- const schema = new Schema();
779
- schema.defineModel({
785
+ const dbs = new DatabaseSchema();
786
+ dbs.defineModel({
780
787
  name: 'model',
781
788
  properties: {
782
789
  foo: {
@@ -785,8 +792,8 @@ describe('PropertyUniquenessValidator', function () {
785
792
  },
786
793
  },
787
794
  });
788
- const S = schema.getService(PropertyUniquenessValidator);
789
- const promise = S.validate(() => 1, 'patch', 'model', {foo: 'bar'});
795
+ const puv = dbs.getService(PropertyUniquenessValidator);
796
+ const promise = puv.validate(() => 1, 'patch', 'model', {foo: 'bar'});
790
797
  await expect(promise).to.be.rejectedWith(
791
798
  'An existing document of the model "model" already has ' +
792
799
  'the property "foo" with the value "bar" and should be unique.',
@@ -794,8 +801,8 @@ describe('PropertyUniquenessValidator', function () {
794
801
  });
795
802
 
796
803
  it('passes validation if the "countMethod" returns zero', async function () {
797
- const schema = new Schema();
798
- schema.defineModel({
804
+ const dbs = new DatabaseSchema();
805
+ dbs.defineModel({
799
806
  name: 'model',
800
807
  properties: {
801
808
  foo: {
@@ -804,13 +811,13 @@ describe('PropertyUniquenessValidator', function () {
804
811
  },
805
812
  },
806
813
  });
807
- const S = schema.getService(PropertyUniquenessValidator);
808
- await S.validate(() => 0, 'patch', 'model', {foo: 'bar'});
814
+ const puv = dbs.getService(PropertyUniquenessValidator);
815
+ await puv.validate(() => 0, 'patch', 'model', {foo: 'bar'});
809
816
  });
810
817
 
811
818
  it('invokes the "countMethod" for given properties which should be unique', async function () {
812
- const schema = new Schema();
813
- schema.defineModel({
819
+ const dbs = new DatabaseSchema();
820
+ dbs.defineModel({
814
821
  name: 'model',
815
822
  properties: {
816
823
  foo: {
@@ -827,7 +834,7 @@ describe('PropertyUniquenessValidator', function () {
827
834
  },
828
835
  },
829
836
  });
830
- const S = schema.getService(PropertyUniquenessValidator);
837
+ const puv = dbs.getService(PropertyUniquenessValidator);
831
838
  let invoked = 0;
832
839
  const modelData = {foo: 'val1', bar: 'val2'};
833
840
  const countMethod = where => {
@@ -835,13 +842,13 @@ describe('PropertyUniquenessValidator', function () {
835
842
  invoked++;
836
843
  return 0;
837
844
  };
838
- await S.validate(countMethod, 'patch', 'model', modelData);
845
+ await puv.validate(countMethod, 'patch', 'model', modelData);
839
846
  expect(invoked).to.be.eq(1);
840
847
  });
841
848
 
842
849
  it('skips uniqueness checking for non-provided fields', async function () {
843
- const schema = new Schema();
844
- schema.defineModel({
850
+ const dbs = new DatabaseSchema();
851
+ dbs.defineModel({
845
852
  name: 'model',
846
853
  properties: {
847
854
  foo: {
@@ -850,9 +857,13 @@ describe('PropertyUniquenessValidator', function () {
850
857
  },
851
858
  },
852
859
  });
853
- const S = schema.getService(PropertyUniquenessValidator);
854
- const promise1 = S.validate(() => 1, 'patch', 'model', {foo: 'bar'});
855
- const promise2 = S.validate(() => 1, 'patch', 'model', {baz: 'qux'});
860
+ const puv = dbs.getService(PropertyUniquenessValidator);
861
+ const promise1 = puv.validate(() => 1, 'patch', 'model', {
862
+ foo: 'bar',
863
+ });
864
+ const promise2 = puv.validate(() => 1, 'patch', 'model', {
865
+ baz: 'qux',
866
+ });
856
867
  await expect(promise1).to.be.rejectedWith(
857
868
  'An existing document of the model "model" already has ' +
858
869
  'the property "foo" with the value "bar" and should be unique.',
@@ -863,8 +874,8 @@ describe('PropertyUniquenessValidator', function () {
863
874
 
864
875
  describe('patchById', function () {
865
876
  it('throws an error if the "countMethod" returns a positive number', async function () {
866
- const schema = new Schema();
867
- schema.defineModel({
877
+ const dbs = new DatabaseSchema();
878
+ dbs.defineModel({
868
879
  name: 'model',
869
880
  properties: {
870
881
  foo: {
@@ -873,8 +884,8 @@ describe('PropertyUniquenessValidator', function () {
873
884
  },
874
885
  },
875
886
  });
876
- const S = schema.getService(PropertyUniquenessValidator);
877
- const promise = S.validate(
887
+ const puv = dbs.getService(PropertyUniquenessValidator);
888
+ const promise = puv.validate(
878
889
  () => 1,
879
890
  'patchById',
880
891
  'model',
@@ -888,8 +899,8 @@ describe('PropertyUniquenessValidator', function () {
888
899
  });
889
900
 
890
901
  it('passes validation if the "countMethod" returns zero', async function () {
891
- const schema = new Schema();
892
- schema.defineModel({
902
+ const dbs = new DatabaseSchema();
903
+ dbs.defineModel({
893
904
  name: 'model',
894
905
  properties: {
895
906
  foo: {
@@ -898,13 +909,13 @@ describe('PropertyUniquenessValidator', function () {
898
909
  },
899
910
  },
900
911
  });
901
- const S = schema.getService(PropertyUniquenessValidator);
902
- await S.validate(() => 0, 'patchById', 'model', {foo: 'bar'}, 1);
912
+ const puv = dbs.getService(PropertyUniquenessValidator);
913
+ await puv.validate(() => 0, 'patchById', 'model', {foo: 'bar'}, 1);
903
914
  });
904
915
 
905
916
  it('invokes the "countMethod" for given properties which should be unique', async function () {
906
- const schema = new Schema();
907
- schema.defineModel({
917
+ const dbs = new DatabaseSchema();
918
+ dbs.defineModel({
908
919
  name: 'model',
909
920
  properties: {
910
921
  foo: {
@@ -921,7 +932,7 @@ describe('PropertyUniquenessValidator', function () {
921
932
  },
922
933
  },
923
934
  });
924
- const S = schema.getService(PropertyUniquenessValidator);
935
+ const puv = dbs.getService(PropertyUniquenessValidator);
925
936
  let invoked = 0;
926
937
  const idValue = 1;
927
938
  const modelData = {foo: 'val1', bar: 'val2'};
@@ -934,7 +945,7 @@ describe('PropertyUniquenessValidator', function () {
934
945
  invoked++;
935
946
  return 0;
936
947
  };
937
- await S.validate(
948
+ await puv.validate(
938
949
  countMethod,
939
950
  'patchById',
940
951
  'model',
@@ -945,8 +956,8 @@ describe('PropertyUniquenessValidator', function () {
945
956
  });
946
957
 
947
958
  it('skips uniqueness checking for non-provided fields', async function () {
948
- const schema = new Schema();
949
- schema.defineModel({
959
+ const dbs = new DatabaseSchema();
960
+ dbs.defineModel({
950
961
  name: 'model',
951
962
  properties: {
952
963
  foo: {
@@ -955,11 +966,11 @@ describe('PropertyUniquenessValidator', function () {
955
966
  },
956
967
  },
957
968
  });
958
- const S = schema.getService(PropertyUniquenessValidator);
959
- const promise1 = S.validate(() => 1, 'patchById', 'model', {
969
+ const puv = dbs.getService(PropertyUniquenessValidator);
970
+ const promise1 = puv.validate(() => 1, 'patchById', 'model', {
960
971
  foo: 'bar',
961
972
  });
962
- const promise2 = S.validate(() => 1, 'patchById', 'model', {
973
+ const promise2 = puv.validate(() => 1, 'patchById', 'model', {
963
974
  baz: 'qux',
964
975
  });
965
976
  await expect(promise1).to.be.rejectedWith(
@@ -970,8 +981,8 @@ describe('PropertyUniquenessValidator', function () {
970
981
  });
971
982
 
972
983
  it('uses a custom primary key to check existence of the given identifier', async function () {
973
- const schema = new Schema();
974
- schema.defineModel({
984
+ const dbs = new DatabaseSchema();
985
+ dbs.defineModel({
975
986
  name: 'model',
976
987
  properties: {
977
988
  myId: {
@@ -984,7 +995,7 @@ describe('PropertyUniquenessValidator', function () {
984
995
  },
985
996
  },
986
997
  });
987
- const S = schema.getService(PropertyUniquenessValidator);
998
+ const puv = dbs.getService(PropertyUniquenessValidator);
988
999
  let invoked = 0;
989
1000
  const idValue = 1;
990
1001
  const modelData = {foo: 'bar'};
@@ -997,7 +1008,7 @@ describe('PropertyUniquenessValidator', function () {
997
1008
  invoked++;
998
1009
  return 0;
999
1010
  };
1000
- await S.validate(
1011
+ await puv.validate(
1001
1012
  countMethod,
1002
1013
  'patchById',
1003
1014
  'model',
@@ -1012,8 +1023,8 @@ describe('PropertyUniquenessValidator', function () {
1012
1023
  describe('the "unique" option is "strict"', function () {
1013
1024
  describe('create', function () {
1014
1025
  it('throws an error if the "countMethod" returns a positive number', async function () {
1015
- const schema = new Schema();
1016
- schema.defineModel({
1026
+ const dbs = new DatabaseSchema();
1027
+ dbs.defineModel({
1017
1028
  name: 'model',
1018
1029
  properties: {
1019
1030
  foo: {
@@ -1022,8 +1033,10 @@ describe('PropertyUniquenessValidator', function () {
1022
1033
  },
1023
1034
  },
1024
1035
  });
1025
- const S = schema.getService(PropertyUniquenessValidator);
1026
- const promise = S.validate(() => 1, 'create', 'model', {foo: 'bar'});
1036
+ const puv = dbs.getService(PropertyUniquenessValidator);
1037
+ const promise = puv.validate(() => 1, 'create', 'model', {
1038
+ foo: 'bar',
1039
+ });
1027
1040
  await expect(promise).to.be.rejectedWith(
1028
1041
  'An existing document of the model "model" already has ' +
1029
1042
  'the property "foo" with the value "bar" and should be unique.',
@@ -1031,8 +1044,8 @@ describe('PropertyUniquenessValidator', function () {
1031
1044
  });
1032
1045
 
1033
1046
  it('passes validation if the "countMethod" returns zero', async function () {
1034
- const schema = new Schema();
1035
- schema.defineModel({
1047
+ const dbs = new DatabaseSchema();
1048
+ dbs.defineModel({
1036
1049
  name: 'model',
1037
1050
  properties: {
1038
1051
  foo: {
@@ -1041,13 +1054,13 @@ describe('PropertyUniquenessValidator', function () {
1041
1054
  },
1042
1055
  },
1043
1056
  });
1044
- const S = schema.getService(PropertyUniquenessValidator);
1045
- await S.validate(() => 0, 'create', 'model', {foo: 'bar'});
1057
+ const puv = dbs.getService(PropertyUniquenessValidator);
1058
+ await puv.validate(() => 0, 'create', 'model', {foo: 'bar'});
1046
1059
  });
1047
1060
 
1048
1061
  it('invokes the "countMethod" for each unique property of the model', async function () {
1049
- const schema = new Schema();
1050
- schema.defineModel({
1062
+ const dbs = new DatabaseSchema();
1063
+ dbs.defineModel({
1051
1064
  name: 'model',
1052
1065
  properties: {
1053
1066
  foo: {
@@ -1064,7 +1077,7 @@ describe('PropertyUniquenessValidator', function () {
1064
1077
  },
1065
1078
  },
1066
1079
  });
1067
- const S = schema.getService(PropertyUniquenessValidator);
1080
+ const puv = dbs.getService(PropertyUniquenessValidator);
1068
1081
  let invoked = 0;
1069
1082
  const modelData = {foo: 'val1', bar: 'val2'};
1070
1083
  const countMethod = where => {
@@ -1076,15 +1089,15 @@ describe('PropertyUniquenessValidator', function () {
1076
1089
  invoked++;
1077
1090
  return 0;
1078
1091
  };
1079
- await S.validate(countMethod, 'create', 'model', modelData);
1092
+ await puv.validate(countMethod, 'create', 'model', modelData);
1080
1093
  expect(invoked).to.be.eq(2);
1081
1094
  });
1082
1095
  });
1083
1096
 
1084
1097
  describe('replaceById', function () {
1085
1098
  it('throws an error if the "countMethod" returns a positive number', async function () {
1086
- const schema = new Schema();
1087
- schema.defineModel({
1099
+ const dbs = new DatabaseSchema();
1100
+ dbs.defineModel({
1088
1101
  name: 'model',
1089
1102
  properties: {
1090
1103
  foo: {
@@ -1093,8 +1106,8 @@ describe('PropertyUniquenessValidator', function () {
1093
1106
  },
1094
1107
  },
1095
1108
  });
1096
- const S = schema.getService(PropertyUniquenessValidator);
1097
- const promise = S.validate(
1109
+ const puv = dbs.getService(PropertyUniquenessValidator);
1110
+ const promise = puv.validate(
1098
1111
  () => 1,
1099
1112
  'replaceById',
1100
1113
  'model',
@@ -1108,8 +1121,8 @@ describe('PropertyUniquenessValidator', function () {
1108
1121
  });
1109
1122
 
1110
1123
  it('passes validation if the "countMethod" returns zero', async function () {
1111
- const schema = new Schema();
1112
- schema.defineModel({
1124
+ const dbs = new DatabaseSchema();
1125
+ dbs.defineModel({
1113
1126
  name: 'model',
1114
1127
  properties: {
1115
1128
  foo: {
@@ -1118,13 +1131,13 @@ describe('PropertyUniquenessValidator', function () {
1118
1131
  },
1119
1132
  },
1120
1133
  });
1121
- const S = schema.getService(PropertyUniquenessValidator);
1122
- await S.validate(() => 0, 'replaceById', 'model', {foo: 'bar'}, 1);
1134
+ const puv = dbs.getService(PropertyUniquenessValidator);
1135
+ await puv.validate(() => 0, 'replaceById', 'model', {foo: 'bar'}, 1);
1123
1136
  });
1124
1137
 
1125
1138
  it('invokes the "countMethod" for each unique property of the model', async function () {
1126
- const schema = new Schema();
1127
- schema.defineModel({
1139
+ const dbs = new DatabaseSchema();
1140
+ dbs.defineModel({
1128
1141
  name: 'model',
1129
1142
  properties: {
1130
1143
  foo: {
@@ -1141,7 +1154,7 @@ describe('PropertyUniquenessValidator', function () {
1141
1154
  },
1142
1155
  },
1143
1156
  });
1144
- const S = schema.getService(PropertyUniquenessValidator);
1157
+ const puv = dbs.getService(PropertyUniquenessValidator);
1145
1158
  let invoked = 0;
1146
1159
  const idValue = 1;
1147
1160
  const modelData = {foo: 'val1', bar: 'val2'};
@@ -1160,7 +1173,7 @@ describe('PropertyUniquenessValidator', function () {
1160
1173
  invoked++;
1161
1174
  return 0;
1162
1175
  };
1163
- await S.validate(
1176
+ await puv.validate(
1164
1177
  countMethod,
1165
1178
  'replaceById',
1166
1179
  'model',
@@ -1171,8 +1184,8 @@ describe('PropertyUniquenessValidator', function () {
1171
1184
  });
1172
1185
 
1173
1186
  it('can use a custom primary key', async function () {
1174
- const schema = new Schema();
1175
- schema.defineModel({
1187
+ const dbs = new DatabaseSchema();
1188
+ dbs.defineModel({
1176
1189
  name: 'model',
1177
1190
  properties: {
1178
1191
  myId: {
@@ -1185,7 +1198,7 @@ describe('PropertyUniquenessValidator', function () {
1185
1198
  },
1186
1199
  },
1187
1200
  });
1188
- const S = schema.getService(PropertyUniquenessValidator);
1201
+ const puv = dbs.getService(PropertyUniquenessValidator);
1189
1202
  let invoked = 0;
1190
1203
  const idValue = 1;
1191
1204
  const modelData = {foo: 'bar'};
@@ -1198,7 +1211,7 @@ describe('PropertyUniquenessValidator', function () {
1198
1211
  invoked++;
1199
1212
  return 0;
1200
1213
  };
1201
- await S.validate(
1214
+ await puv.validate(
1202
1215
  countMethod,
1203
1216
  'replaceById',
1204
1217
  'model',
@@ -1211,8 +1224,8 @@ describe('PropertyUniquenessValidator', function () {
1211
1224
 
1212
1225
  describe('replaceOrCreate', function () {
1213
1226
  it('throws an error if the "countMethod" returns a positive number', async function () {
1214
- const schema = new Schema();
1215
- schema.defineModel({
1227
+ const dbs = new DatabaseSchema();
1228
+ dbs.defineModel({
1216
1229
  name: 'model',
1217
1230
  properties: {
1218
1231
  foo: {
@@ -1221,8 +1234,8 @@ describe('PropertyUniquenessValidator', function () {
1221
1234
  },
1222
1235
  },
1223
1236
  });
1224
- const S = schema.getService(PropertyUniquenessValidator);
1225
- const promise = S.validate(() => 1, 'replaceOrCreate', 'model', {
1237
+ const puv = dbs.getService(PropertyUniquenessValidator);
1238
+ const promise = puv.validate(() => 1, 'replaceOrCreate', 'model', {
1226
1239
  foo: 'bar',
1227
1240
  });
1228
1241
  await expect(promise).to.be.rejectedWith(
@@ -1232,8 +1245,8 @@ describe('PropertyUniquenessValidator', function () {
1232
1245
  });
1233
1246
 
1234
1247
  it('passes validation if the "countMethod" returns zero', async function () {
1235
- const schema = new Schema();
1236
- schema.defineModel({
1248
+ const dbs = new DatabaseSchema();
1249
+ dbs.defineModel({
1237
1250
  name: 'model',
1238
1251
  properties: {
1239
1252
  foo: {
@@ -1242,13 +1255,13 @@ describe('PropertyUniquenessValidator', function () {
1242
1255
  },
1243
1256
  },
1244
1257
  });
1245
- const S = schema.getService(PropertyUniquenessValidator);
1246
- await S.validate(() => 0, 'replaceOrCreate', 'model', {foo: 'bar'});
1258
+ const puv = dbs.getService(PropertyUniquenessValidator);
1259
+ await puv.validate(() => 0, 'replaceOrCreate', 'model', {foo: 'bar'});
1247
1260
  });
1248
1261
 
1249
1262
  it('invokes the "countMethod" for each unique property of the model', async function () {
1250
- const schema = new Schema();
1251
- schema.defineModel({
1263
+ const dbs = new DatabaseSchema();
1264
+ dbs.defineModel({
1252
1265
  name: 'model',
1253
1266
  properties: {
1254
1267
  foo: {
@@ -1265,7 +1278,7 @@ describe('PropertyUniquenessValidator', function () {
1265
1278
  },
1266
1279
  },
1267
1280
  });
1268
- const S = schema.getService(PropertyUniquenessValidator);
1281
+ const puv = dbs.getService(PropertyUniquenessValidator);
1269
1282
  let invoked = 0;
1270
1283
  const modelData = {foo: 'val1', bar: 'val2'};
1271
1284
  const countMethod = where => {
@@ -1277,15 +1290,20 @@ describe('PropertyUniquenessValidator', function () {
1277
1290
  invoked++;
1278
1291
  return 0;
1279
1292
  };
1280
- await S.validate(countMethod, 'replaceOrCreate', 'model', modelData);
1293
+ await puv.validate(
1294
+ countMethod,
1295
+ 'replaceOrCreate',
1296
+ 'model',
1297
+ modelData,
1298
+ );
1281
1299
  expect(invoked).to.be.eq(2);
1282
1300
  });
1283
1301
 
1284
1302
  describe('in case that the given model has a document identifier', function () {
1285
1303
  describe('a document of the given identifier does not exist', function () {
1286
1304
  it('uses the default primary key to check existence of the given identifier', async function () {
1287
- const schema = new Schema();
1288
- schema.defineModel({
1305
+ const dbs = new DatabaseSchema();
1306
+ dbs.defineModel({
1289
1307
  name: 'model',
1290
1308
  properties: {
1291
1309
  foo: {
@@ -1294,7 +1312,7 @@ describe('PropertyUniquenessValidator', function () {
1294
1312
  },
1295
1313
  },
1296
1314
  });
1297
- const S = schema.getService(PropertyUniquenessValidator);
1315
+ const puv = dbs.getService(PropertyUniquenessValidator);
1298
1316
  let invoked = 0;
1299
1317
  const idValue = 1;
1300
1318
  const modelData = {[DEF_PK]: idValue, foo: 'bar'};
@@ -1307,7 +1325,7 @@ describe('PropertyUniquenessValidator', function () {
1307
1325
  invoked++;
1308
1326
  return 0;
1309
1327
  };
1310
- await S.validate(
1328
+ await puv.validate(
1311
1329
  countMethod,
1312
1330
  'replaceOrCreate',
1313
1331
  'model',
@@ -1317,8 +1335,8 @@ describe('PropertyUniquenessValidator', function () {
1317
1335
  });
1318
1336
 
1319
1337
  it('uses a custom primary key to check existence of the given identifier', async function () {
1320
- const schema = new Schema();
1321
- schema.defineModel({
1338
+ const dbs = new DatabaseSchema();
1339
+ dbs.defineModel({
1322
1340
  name: 'model',
1323
1341
  properties: {
1324
1342
  myId: {
@@ -1331,7 +1349,7 @@ describe('PropertyUniquenessValidator', function () {
1331
1349
  },
1332
1350
  },
1333
1351
  });
1334
- const S = schema.getService(PropertyUniquenessValidator);
1352
+ const puv = dbs.getService(PropertyUniquenessValidator);
1335
1353
  let invoked = 0;
1336
1354
  const idValue = 1;
1337
1355
  const modelData = {myId: idValue, foo: 'bar'};
@@ -1344,7 +1362,7 @@ describe('PropertyUniquenessValidator', function () {
1344
1362
  invoked++;
1345
1363
  return 0;
1346
1364
  };
1347
- await S.validate(
1365
+ await puv.validate(
1348
1366
  countMethod,
1349
1367
  'replaceOrCreate',
1350
1368
  'model',
@@ -1355,8 +1373,8 @@ describe('PropertyUniquenessValidator', function () {
1355
1373
  });
1356
1374
 
1357
1375
  it('checks the given identifier only once', async function () {
1358
- const schema = new Schema();
1359
- schema.defineModel({
1376
+ const dbs = new DatabaseSchema();
1377
+ dbs.defineModel({
1360
1378
  name: 'model',
1361
1379
  properties: {
1362
1380
  foo: {
@@ -1369,7 +1387,7 @@ describe('PropertyUniquenessValidator', function () {
1369
1387
  },
1370
1388
  },
1371
1389
  });
1372
- const S = schema.getService(PropertyUniquenessValidator);
1390
+ const puv = dbs.getService(PropertyUniquenessValidator);
1373
1391
  let invoked = 0;
1374
1392
  const idValue = 1;
1375
1393
  const modelData = {[DEF_PK]: idValue, foo: 'val1', bar: 'val2'};
@@ -1384,7 +1402,7 @@ describe('PropertyUniquenessValidator', function () {
1384
1402
  invoked++;
1385
1403
  return 0;
1386
1404
  };
1387
- await S.validate(
1405
+ await puv.validate(
1388
1406
  countMethod,
1389
1407
  'replaceOrCreate',
1390
1408
  'model',
@@ -1396,8 +1414,8 @@ describe('PropertyUniquenessValidator', function () {
1396
1414
 
1397
1415
  describe('a document of the given identifier already exist', function () {
1398
1416
  it('uses the default primary key to check existence of the given identifier', async function () {
1399
- const schema = new Schema();
1400
- schema.defineModel({
1417
+ const dbs = new DatabaseSchema();
1418
+ dbs.defineModel({
1401
1419
  name: 'model',
1402
1420
  properties: {
1403
1421
  foo: {
@@ -1406,7 +1424,7 @@ describe('PropertyUniquenessValidator', function () {
1406
1424
  },
1407
1425
  },
1408
1426
  });
1409
- const S = schema.getService(PropertyUniquenessValidator);
1427
+ const puv = dbs.getService(PropertyUniquenessValidator);
1410
1428
  let invoked = 0;
1411
1429
  const idValue = 1;
1412
1430
  const modelData = {
@@ -1428,7 +1446,7 @@ describe('PropertyUniquenessValidator', function () {
1428
1446
  return 0;
1429
1447
  }
1430
1448
  };
1431
- await S.validate(
1449
+ await puv.validate(
1432
1450
  countMethod,
1433
1451
  'replaceOrCreate',
1434
1452
  'model',
@@ -1438,8 +1456,8 @@ describe('PropertyUniquenessValidator', function () {
1438
1456
  });
1439
1457
 
1440
1458
  it('uses a custom primary key to check existence of the given identifier', async function () {
1441
- const schema = new Schema();
1442
- schema.defineModel({
1459
+ const dbs = new DatabaseSchema();
1460
+ dbs.defineModel({
1443
1461
  name: 'model',
1444
1462
  properties: {
1445
1463
  myId: {
@@ -1452,7 +1470,7 @@ describe('PropertyUniquenessValidator', function () {
1452
1470
  },
1453
1471
  },
1454
1472
  });
1455
- const S = schema.getService(PropertyUniquenessValidator);
1473
+ const puv = dbs.getService(PropertyUniquenessValidator);
1456
1474
  let invoked = 0;
1457
1475
  const idValue = 1;
1458
1476
  const modelData = {myId: idValue, foo: 'bar'};
@@ -1471,7 +1489,7 @@ describe('PropertyUniquenessValidator', function () {
1471
1489
  return 0;
1472
1490
  }
1473
1491
  };
1474
- await S.validate(
1492
+ await puv.validate(
1475
1493
  countMethod,
1476
1494
  'replaceOrCreate',
1477
1495
  'model',
@@ -1482,8 +1500,8 @@ describe('PropertyUniquenessValidator', function () {
1482
1500
  });
1483
1501
 
1484
1502
  it('checks the given identifier only once', async function () {
1485
- const schema = new Schema();
1486
- schema.defineModel({
1503
+ const dbs = new DatabaseSchema();
1504
+ dbs.defineModel({
1487
1505
  name: 'model',
1488
1506
  properties: {
1489
1507
  foo: {
@@ -1496,7 +1514,7 @@ describe('PropertyUniquenessValidator', function () {
1496
1514
  },
1497
1515
  },
1498
1516
  });
1499
- const S = schema.getService(PropertyUniquenessValidator);
1517
+ const puv = dbs.getService(PropertyUniquenessValidator);
1500
1518
  let invoked = 0;
1501
1519
  const idValue = 1;
1502
1520
  const modelData = {
@@ -1523,7 +1541,7 @@ describe('PropertyUniquenessValidator', function () {
1523
1541
  return 0;
1524
1542
  }
1525
1543
  };
1526
- await S.validate(
1544
+ await puv.validate(
1527
1545
  countMethod,
1528
1546
  'replaceOrCreate',
1529
1547
  'model',
@@ -1537,8 +1555,8 @@ describe('PropertyUniquenessValidator', function () {
1537
1555
 
1538
1556
  describe('patch', function () {
1539
1557
  it('throws an error if the "countMethod" returns a positive number', async function () {
1540
- const schema = new Schema();
1541
- schema.defineModel({
1558
+ const dbs = new DatabaseSchema();
1559
+ dbs.defineModel({
1542
1560
  name: 'model',
1543
1561
  properties: {
1544
1562
  foo: {
@@ -1547,8 +1565,8 @@ describe('PropertyUniquenessValidator', function () {
1547
1565
  },
1548
1566
  },
1549
1567
  });
1550
- const S = schema.getService(PropertyUniquenessValidator);
1551
- const promise = S.validate(() => 1, 'patch', 'model', {foo: 'bar'});
1568
+ const puv = dbs.getService(PropertyUniquenessValidator);
1569
+ const promise = puv.validate(() => 1, 'patch', 'model', {foo: 'bar'});
1552
1570
  await expect(promise).to.be.rejectedWith(
1553
1571
  'An existing document of the model "model" already has ' +
1554
1572
  'the property "foo" with the value "bar" and should be unique.',
@@ -1556,8 +1574,8 @@ describe('PropertyUniquenessValidator', function () {
1556
1574
  });
1557
1575
 
1558
1576
  it('passes validation if the "countMethod" returns zero', async function () {
1559
- const schema = new Schema();
1560
- schema.defineModel({
1577
+ const dbs = new DatabaseSchema();
1578
+ dbs.defineModel({
1561
1579
  name: 'model',
1562
1580
  properties: {
1563
1581
  foo: {
@@ -1566,13 +1584,13 @@ describe('PropertyUniquenessValidator', function () {
1566
1584
  },
1567
1585
  },
1568
1586
  });
1569
- const S = schema.getService(PropertyUniquenessValidator);
1570
- await S.validate(() => 0, 'patch', 'model', {foo: 'bar'});
1587
+ const puv = dbs.getService(PropertyUniquenessValidator);
1588
+ await puv.validate(() => 0, 'patch', 'model', {foo: 'bar'});
1571
1589
  });
1572
1590
 
1573
1591
  it('invokes the "countMethod" for given properties which should be unique', async function () {
1574
- const schema = new Schema();
1575
- schema.defineModel({
1592
+ const dbs = new DatabaseSchema();
1593
+ dbs.defineModel({
1576
1594
  name: 'model',
1577
1595
  properties: {
1578
1596
  foo: {
@@ -1589,7 +1607,7 @@ describe('PropertyUniquenessValidator', function () {
1589
1607
  },
1590
1608
  },
1591
1609
  });
1592
- const S = schema.getService(PropertyUniquenessValidator);
1610
+ const puv = dbs.getService(PropertyUniquenessValidator);
1593
1611
  let invoked = 0;
1594
1612
  const modelData = {foo: 'val1', bar: 'val2'};
1595
1613
  const countMethod = where => {
@@ -1597,13 +1615,13 @@ describe('PropertyUniquenessValidator', function () {
1597
1615
  invoked++;
1598
1616
  return 0;
1599
1617
  };
1600
- await S.validate(countMethod, 'patch', 'model', modelData);
1618
+ await puv.validate(countMethod, 'patch', 'model', modelData);
1601
1619
  expect(invoked).to.be.eq(1);
1602
1620
  });
1603
1621
 
1604
1622
  it('skips uniqueness checking for non-provided fields', async function () {
1605
- const schema = new Schema();
1606
- schema.defineModel({
1623
+ const dbs = new DatabaseSchema();
1624
+ dbs.defineModel({
1607
1625
  name: 'model',
1608
1626
  properties: {
1609
1627
  foo: {
@@ -1612,9 +1630,13 @@ describe('PropertyUniquenessValidator', function () {
1612
1630
  },
1613
1631
  },
1614
1632
  });
1615
- const S = schema.getService(PropertyUniquenessValidator);
1616
- const promise1 = S.validate(() => 1, 'patch', 'model', {foo: 'bar'});
1617
- const promise2 = S.validate(() => 1, 'patch', 'model', {baz: 'qux'});
1633
+ const puv = dbs.getService(PropertyUniquenessValidator);
1634
+ const promise1 = puv.validate(() => 1, 'patch', 'model', {
1635
+ foo: 'bar',
1636
+ });
1637
+ const promise2 = puv.validate(() => 1, 'patch', 'model', {
1638
+ baz: 'qux',
1639
+ });
1618
1640
  await expect(promise1).to.be.rejectedWith(
1619
1641
  'An existing document of the model "model" already has ' +
1620
1642
  'the property "foo" with the value "bar" and should be unique.',
@@ -1625,8 +1647,8 @@ describe('PropertyUniquenessValidator', function () {
1625
1647
 
1626
1648
  describe('patchById', function () {
1627
1649
  it('throws an error if the "countMethod" returns a positive number', async function () {
1628
- const schema = new Schema();
1629
- schema.defineModel({
1650
+ const dbs = new DatabaseSchema();
1651
+ dbs.defineModel({
1630
1652
  name: 'model',
1631
1653
  properties: {
1632
1654
  foo: {
@@ -1635,8 +1657,8 @@ describe('PropertyUniquenessValidator', function () {
1635
1657
  },
1636
1658
  },
1637
1659
  });
1638
- const S = schema.getService(PropertyUniquenessValidator);
1639
- const promise = S.validate(
1660
+ const puv = dbs.getService(PropertyUniquenessValidator);
1661
+ const promise = puv.validate(
1640
1662
  () => 1,
1641
1663
  'patchById',
1642
1664
  'model',
@@ -1650,8 +1672,8 @@ describe('PropertyUniquenessValidator', function () {
1650
1672
  });
1651
1673
 
1652
1674
  it('passes validation if the "countMethod" returns zero', async function () {
1653
- const schema = new Schema();
1654
- schema.defineModel({
1675
+ const dbs = new DatabaseSchema();
1676
+ dbs.defineModel({
1655
1677
  name: 'model',
1656
1678
  properties: {
1657
1679
  foo: {
@@ -1660,13 +1682,13 @@ describe('PropertyUniquenessValidator', function () {
1660
1682
  },
1661
1683
  },
1662
1684
  });
1663
- const S = schema.getService(PropertyUniquenessValidator);
1664
- await S.validate(() => 0, 'patchById', 'model', {foo: 'bar'}, 1);
1685
+ const puv = dbs.getService(PropertyUniquenessValidator);
1686
+ await puv.validate(() => 0, 'patchById', 'model', {foo: 'bar'}, 1);
1665
1687
  });
1666
1688
 
1667
1689
  it('invokes the "countMethod" for given properties which should be unique', async function () {
1668
- const schema = new Schema();
1669
- schema.defineModel({
1690
+ const dbs = new DatabaseSchema();
1691
+ dbs.defineModel({
1670
1692
  name: 'model',
1671
1693
  properties: {
1672
1694
  foo: {
@@ -1683,7 +1705,7 @@ describe('PropertyUniquenessValidator', function () {
1683
1705
  },
1684
1706
  },
1685
1707
  });
1686
- const S = schema.getService(PropertyUniquenessValidator);
1708
+ const puv = dbs.getService(PropertyUniquenessValidator);
1687
1709
  let invoked = 0;
1688
1710
  const idValue = 1;
1689
1711
  const modelData = {foo: 'val1', bar: 'val2'};
@@ -1696,7 +1718,7 @@ describe('PropertyUniquenessValidator', function () {
1696
1718
  invoked++;
1697
1719
  return 0;
1698
1720
  };
1699
- await S.validate(
1721
+ await puv.validate(
1700
1722
  countMethod,
1701
1723
  'patchById',
1702
1724
  'model',
@@ -1707,8 +1729,8 @@ describe('PropertyUniquenessValidator', function () {
1707
1729
  });
1708
1730
 
1709
1731
  it('skips uniqueness checking for non-provided fields', async function () {
1710
- const schema = new Schema();
1711
- schema.defineModel({
1732
+ const dbs = new DatabaseSchema();
1733
+ dbs.defineModel({
1712
1734
  name: 'model',
1713
1735
  properties: {
1714
1736
  foo: {
@@ -1717,11 +1739,11 @@ describe('PropertyUniquenessValidator', function () {
1717
1739
  },
1718
1740
  },
1719
1741
  });
1720
- const S = schema.getService(PropertyUniquenessValidator);
1721
- const promise1 = S.validate(() => 1, 'patchById', 'model', {
1742
+ const puv = dbs.getService(PropertyUniquenessValidator);
1743
+ const promise1 = puv.validate(() => 1, 'patchById', 'model', {
1722
1744
  foo: 'bar',
1723
1745
  });
1724
- const promise2 = S.validate(() => 1, 'patchById', 'model', {
1746
+ const promise2 = puv.validate(() => 1, 'patchById', 'model', {
1725
1747
  baz: 'qux',
1726
1748
  });
1727
1749
  await expect(promise1).to.be.rejectedWith(
@@ -1732,8 +1754,8 @@ describe('PropertyUniquenessValidator', function () {
1732
1754
  });
1733
1755
 
1734
1756
  it('uses a custom primary key to check existence of the given identifier', async function () {
1735
- const schema = new Schema();
1736
- schema.defineModel({
1757
+ const dbs = new DatabaseSchema();
1758
+ dbs.defineModel({
1737
1759
  name: 'model',
1738
1760
  properties: {
1739
1761
  myId: {
@@ -1746,7 +1768,7 @@ describe('PropertyUniquenessValidator', function () {
1746
1768
  },
1747
1769
  },
1748
1770
  });
1749
- const S = schema.getService(PropertyUniquenessValidator);
1771
+ const puv = dbs.getService(PropertyUniquenessValidator);
1750
1772
  let invoked = 0;
1751
1773
  const idValue = 1;
1752
1774
  const modelData = {foo: 'bar'};
@@ -1759,7 +1781,7 @@ describe('PropertyUniquenessValidator', function () {
1759
1781
  invoked++;
1760
1782
  return 0;
1761
1783
  };
1762
- await S.validate(
1784
+ await puv.validate(
1763
1785
  countMethod,
1764
1786
  'patchById',
1765
1787
  'model',
@@ -1774,8 +1796,8 @@ describe('PropertyUniquenessValidator', function () {
1774
1796
  describe('the "unique" option is "sparse"', function () {
1775
1797
  describe('create', function () {
1776
1798
  it('throws an error if the "countMethod" returns a positive number', async function () {
1777
- const schema = new Schema();
1778
- schema.defineModel({
1799
+ const dbs = new DatabaseSchema();
1800
+ dbs.defineModel({
1779
1801
  name: 'model',
1780
1802
  properties: {
1781
1803
  foo: {
@@ -1784,8 +1806,10 @@ describe('PropertyUniquenessValidator', function () {
1784
1806
  },
1785
1807
  },
1786
1808
  });
1787
- const S = schema.getService(PropertyUniquenessValidator);
1788
- const promise = S.validate(() => 1, 'create', 'model', {foo: 'bar'});
1809
+ const puv = dbs.getService(PropertyUniquenessValidator);
1810
+ const promise = puv.validate(() => 1, 'create', 'model', {
1811
+ foo: 'bar',
1812
+ });
1789
1813
  await expect(promise).to.be.rejectedWith(
1790
1814
  'An existing document of the model "model" already has ' +
1791
1815
  'the property "foo" with the value "bar" and should be unique.',
@@ -1793,8 +1817,8 @@ describe('PropertyUniquenessValidator', function () {
1793
1817
  });
1794
1818
 
1795
1819
  it('passes validation if the "countMethod" returns zero', async function () {
1796
- const schema = new Schema();
1797
- schema.defineModel({
1820
+ const dbs = new DatabaseSchema();
1821
+ dbs.defineModel({
1798
1822
  name: 'model',
1799
1823
  properties: {
1800
1824
  foo: {
@@ -1803,13 +1827,13 @@ describe('PropertyUniquenessValidator', function () {
1803
1827
  },
1804
1828
  },
1805
1829
  });
1806
- const S = schema.getService(PropertyUniquenessValidator);
1807
- await S.validate(() => 0, 'create', 'model', {foo: 'bar'});
1830
+ const puv = dbs.getService(PropertyUniquenessValidator);
1831
+ await puv.validate(() => 0, 'create', 'model', {foo: 'bar'});
1808
1832
  });
1809
1833
 
1810
1834
  it('invokes the "countMethod" for given properties which should be unique', async function () {
1811
- const schema = new Schema();
1812
- schema.defineModel({
1835
+ const dbs = new DatabaseSchema();
1836
+ dbs.defineModel({
1813
1837
  name: 'model',
1814
1838
  properties: {
1815
1839
  foo: {
@@ -1826,7 +1850,7 @@ describe('PropertyUniquenessValidator', function () {
1826
1850
  },
1827
1851
  },
1828
1852
  });
1829
- const S = schema.getService(PropertyUniquenessValidator);
1853
+ const puv = dbs.getService(PropertyUniquenessValidator);
1830
1854
  let invoked = 0;
1831
1855
  const modelData = {foo: 'val1', bar: 'val2'};
1832
1856
  const countMethod = where => {
@@ -1834,13 +1858,13 @@ describe('PropertyUniquenessValidator', function () {
1834
1858
  invoked++;
1835
1859
  return 0;
1836
1860
  };
1837
- await S.validate(countMethod, 'create', 'model', modelData);
1861
+ await puv.validate(countMethod, 'create', 'model', modelData);
1838
1862
  expect(invoked).to.be.eq(1);
1839
1863
  });
1840
1864
 
1841
1865
  it('skips uniqueness checking for empty values', async function () {
1842
- const schema = new Schema();
1843
- schema.defineModel({
1866
+ const dbs = new DatabaseSchema();
1867
+ dbs.defineModel({
1844
1868
  name: 'model',
1845
1869
  properties: {
1846
1870
  foo: {
@@ -1853,10 +1877,10 @@ describe('PropertyUniquenessValidator', function () {
1853
1877
  },
1854
1878
  },
1855
1879
  });
1856
- const S = schema.getService(PropertyUniquenessValidator);
1880
+ const puv = dbs.getService(PropertyUniquenessValidator);
1857
1881
  let invoked = 0;
1858
- schema
1859
- .getService(EmptyValuesDefiner)
1882
+ dbs
1883
+ .getService(EmptyValuesService)
1860
1884
  .setEmptyValuesOf(DataType.STRING, ['val2']);
1861
1885
  const modelData = {foo: 'val1', bar: 'val2'};
1862
1886
  const countMethod = where => {
@@ -1864,15 +1888,15 @@ describe('PropertyUniquenessValidator', function () {
1864
1888
  invoked++;
1865
1889
  return 0;
1866
1890
  };
1867
- await S.validate(countMethod, 'create', 'model', modelData);
1891
+ await puv.validate(countMethod, 'create', 'model', modelData);
1868
1892
  expect(invoked).to.be.eql(1);
1869
1893
  });
1870
1894
  });
1871
1895
 
1872
1896
  describe('replaceById', function () {
1873
1897
  it('throws an error if the "countMethod" returns a positive number', async function () {
1874
- const schema = new Schema();
1875
- schema.defineModel({
1898
+ const dbs = new DatabaseSchema();
1899
+ dbs.defineModel({
1876
1900
  name: 'model',
1877
1901
  properties: {
1878
1902
  foo: {
@@ -1881,8 +1905,8 @@ describe('PropertyUniquenessValidator', function () {
1881
1905
  },
1882
1906
  },
1883
1907
  });
1884
- const S = schema.getService(PropertyUniquenessValidator);
1885
- const promise = S.validate(
1908
+ const puv = dbs.getService(PropertyUniquenessValidator);
1909
+ const promise = puv.validate(
1886
1910
  () => 1,
1887
1911
  'replaceById',
1888
1912
  'model',
@@ -1896,8 +1920,8 @@ describe('PropertyUniquenessValidator', function () {
1896
1920
  });
1897
1921
 
1898
1922
  it('passes validation if the "countMethod" returns zero', async function () {
1899
- const schema = new Schema();
1900
- schema.defineModel({
1923
+ const dbs = new DatabaseSchema();
1924
+ dbs.defineModel({
1901
1925
  name: 'model',
1902
1926
  properties: {
1903
1927
  foo: {
@@ -1906,13 +1930,13 @@ describe('PropertyUniquenessValidator', function () {
1906
1930
  },
1907
1931
  },
1908
1932
  });
1909
- const S = schema.getService(PropertyUniquenessValidator);
1910
- await S.validate(() => 0, 'replaceById', 'model', {foo: 'bar'}, 1);
1933
+ const puv = dbs.getService(PropertyUniquenessValidator);
1934
+ await puv.validate(() => 0, 'replaceById', 'model', {foo: 'bar'}, 1);
1911
1935
  });
1912
1936
 
1913
1937
  it('invokes the "countMethod" for given properties which should be unique', async function () {
1914
- const schema = new Schema();
1915
- schema.defineModel({
1938
+ const dbs = new DatabaseSchema();
1939
+ dbs.defineModel({
1916
1940
  name: 'model',
1917
1941
  properties: {
1918
1942
  foo: {
@@ -1929,7 +1953,7 @@ describe('PropertyUniquenessValidator', function () {
1929
1953
  },
1930
1954
  },
1931
1955
  });
1932
- const S = schema.getService(PropertyUniquenessValidator);
1956
+ const puv = dbs.getService(PropertyUniquenessValidator);
1933
1957
  let invoked = 0;
1934
1958
  const idValue = 1;
1935
1959
  const modelData = {foo: 'val1', bar: 'val2'};
@@ -1942,7 +1966,7 @@ describe('PropertyUniquenessValidator', function () {
1942
1966
  invoked++;
1943
1967
  return 0;
1944
1968
  };
1945
- await S.validate(
1969
+ await puv.validate(
1946
1970
  countMethod,
1947
1971
  'replaceById',
1948
1972
  'model',
@@ -1953,8 +1977,8 @@ describe('PropertyUniquenessValidator', function () {
1953
1977
  });
1954
1978
 
1955
1979
  it('skips uniqueness checking for empty values', async function () {
1956
- const schema = new Schema();
1957
- schema.defineModel({
1980
+ const dbs = new DatabaseSchema();
1981
+ dbs.defineModel({
1958
1982
  name: 'model',
1959
1983
  properties: {
1960
1984
  foo: {
@@ -1967,10 +1991,10 @@ describe('PropertyUniquenessValidator', function () {
1967
1991
  },
1968
1992
  },
1969
1993
  });
1970
- const S = schema.getService(PropertyUniquenessValidator);
1994
+ const puv = dbs.getService(PropertyUniquenessValidator);
1971
1995
  let invoked = 0;
1972
- schema
1973
- .getService(EmptyValuesDefiner)
1996
+ dbs
1997
+ .getService(EmptyValuesService)
1974
1998
  .setEmptyValuesOf(DataType.STRING, ['val2']);
1975
1999
  const idValue = 1;
1976
2000
  const modelData = {foo: 'val1', bar: 'val2'};
@@ -1983,7 +2007,7 @@ describe('PropertyUniquenessValidator', function () {
1983
2007
  invoked++;
1984
2008
  return 0;
1985
2009
  };
1986
- await S.validate(
2010
+ await puv.validate(
1987
2011
  countMethod,
1988
2012
  'replaceById',
1989
2013
  'model',
@@ -1994,8 +2018,8 @@ describe('PropertyUniquenessValidator', function () {
1994
2018
  });
1995
2019
 
1996
2020
  it('uses a custom primary key to check existence of the given identifier', async function () {
1997
- const schema = new Schema();
1998
- schema.defineModel({
2021
+ const dbs = new DatabaseSchema();
2022
+ dbs.defineModel({
1999
2023
  name: 'model',
2000
2024
  properties: {
2001
2025
  myId: {
@@ -2008,7 +2032,7 @@ describe('PropertyUniquenessValidator', function () {
2008
2032
  },
2009
2033
  },
2010
2034
  });
2011
- const S = schema.getService(PropertyUniquenessValidator);
2035
+ const puv = dbs.getService(PropertyUniquenessValidator);
2012
2036
  let invoked = 0;
2013
2037
  const idValue = 1;
2014
2038
  const modelData = {foo: 'bar'};
@@ -2021,7 +2045,7 @@ describe('PropertyUniquenessValidator', function () {
2021
2045
  invoked++;
2022
2046
  return 0;
2023
2047
  };
2024
- await S.validate(
2048
+ await puv.validate(
2025
2049
  countMethod,
2026
2050
  'replaceById',
2027
2051
  'model',
@@ -2034,8 +2058,8 @@ describe('PropertyUniquenessValidator', function () {
2034
2058
 
2035
2059
  describe('replaceOrCreate', function () {
2036
2060
  it('throws an error if the "countMethod" returns a positive number', async function () {
2037
- const schema = new Schema();
2038
- schema.defineModel({
2061
+ const dbs = new DatabaseSchema();
2062
+ dbs.defineModel({
2039
2063
  name: 'model',
2040
2064
  properties: {
2041
2065
  foo: {
@@ -2044,8 +2068,8 @@ describe('PropertyUniquenessValidator', function () {
2044
2068
  },
2045
2069
  },
2046
2070
  });
2047
- const S = schema.getService(PropertyUniquenessValidator);
2048
- const promise = S.validate(() => 1, 'replaceOrCreate', 'model', {
2071
+ const puv = dbs.getService(PropertyUniquenessValidator);
2072
+ const promise = puv.validate(() => 1, 'replaceOrCreate', 'model', {
2049
2073
  foo: 'bar',
2050
2074
  });
2051
2075
  await expect(promise).to.be.rejectedWith(
@@ -2055,8 +2079,8 @@ describe('PropertyUniquenessValidator', function () {
2055
2079
  });
2056
2080
 
2057
2081
  it('passes validation if the "countMethod" returns zero', async function () {
2058
- const schema = new Schema();
2059
- schema.defineModel({
2082
+ const dbs = new DatabaseSchema();
2083
+ dbs.defineModel({
2060
2084
  name: 'model',
2061
2085
  properties: {
2062
2086
  foo: {
@@ -2065,13 +2089,13 @@ describe('PropertyUniquenessValidator', function () {
2065
2089
  },
2066
2090
  },
2067
2091
  });
2068
- const S = schema.getService(PropertyUniquenessValidator);
2069
- await S.validate(() => 0, 'replaceOrCreate', 'model', {foo: 'bar'});
2092
+ const puv = dbs.getService(PropertyUniquenessValidator);
2093
+ await puv.validate(() => 0, 'replaceOrCreate', 'model', {foo: 'bar'});
2070
2094
  });
2071
2095
 
2072
2096
  it('invokes the "countMethod" for given properties which should be unique', async function () {
2073
- const schema = new Schema();
2074
- schema.defineModel({
2097
+ const dbs = new DatabaseSchema();
2098
+ dbs.defineModel({
2075
2099
  name: 'model',
2076
2100
  properties: {
2077
2101
  foo: {
@@ -2088,7 +2112,7 @@ describe('PropertyUniquenessValidator', function () {
2088
2112
  },
2089
2113
  },
2090
2114
  });
2091
- const S = schema.getService(PropertyUniquenessValidator);
2115
+ const puv = dbs.getService(PropertyUniquenessValidator);
2092
2116
  let invoked = 0;
2093
2117
  const modelData = {foo: 'val1', bar: 'val2'};
2094
2118
  const countMethod = where => {
@@ -2096,15 +2120,20 @@ describe('PropertyUniquenessValidator', function () {
2096
2120
  invoked++;
2097
2121
  return 0;
2098
2122
  };
2099
- await S.validate(countMethod, 'replaceOrCreate', 'model', modelData);
2123
+ await puv.validate(
2124
+ countMethod,
2125
+ 'replaceOrCreate',
2126
+ 'model',
2127
+ modelData,
2128
+ );
2100
2129
  expect(invoked).to.be.eq(1);
2101
2130
  });
2102
2131
 
2103
2132
  describe('in case that the given model has a document identifier', function () {
2104
2133
  describe('a document of the given identifier does not exist', function () {
2105
2134
  it('uses the default primary key to check existence of the given identifier', async function () {
2106
- const schema = new Schema();
2107
- schema.defineModel({
2135
+ const dbs = new DatabaseSchema();
2136
+ dbs.defineModel({
2108
2137
  name: 'model',
2109
2138
  properties: {
2110
2139
  foo: {
@@ -2113,7 +2142,7 @@ describe('PropertyUniquenessValidator', function () {
2113
2142
  },
2114
2143
  },
2115
2144
  });
2116
- const S = schema.getService(PropertyUniquenessValidator);
2145
+ const puv = dbs.getService(PropertyUniquenessValidator);
2117
2146
  let invoked = 0;
2118
2147
  const idValue = 1;
2119
2148
  const modelData = {[DEF_PK]: idValue, foo: 'bar'};
@@ -2126,7 +2155,7 @@ describe('PropertyUniquenessValidator', function () {
2126
2155
  invoked++;
2127
2156
  return 0;
2128
2157
  };
2129
- await S.validate(
2158
+ await puv.validate(
2130
2159
  countMethod,
2131
2160
  'replaceOrCreate',
2132
2161
  'model',
@@ -2136,8 +2165,8 @@ describe('PropertyUniquenessValidator', function () {
2136
2165
  });
2137
2166
 
2138
2167
  it('uses a custom primary key to check existence of the given identifier', async function () {
2139
- const schema = new Schema();
2140
- schema.defineModel({
2168
+ const dbs = new DatabaseSchema();
2169
+ dbs.defineModel({
2141
2170
  name: 'model',
2142
2171
  properties: {
2143
2172
  myId: {
@@ -2150,7 +2179,7 @@ describe('PropertyUniquenessValidator', function () {
2150
2179
  },
2151
2180
  },
2152
2181
  });
2153
- const S = schema.getService(PropertyUniquenessValidator);
2182
+ const puv = dbs.getService(PropertyUniquenessValidator);
2154
2183
  let invoked = 0;
2155
2184
  const idValue = 1;
2156
2185
  const modelData = {myId: idValue, foo: 'bar'};
@@ -2163,7 +2192,7 @@ describe('PropertyUniquenessValidator', function () {
2163
2192
  invoked++;
2164
2193
  return 0;
2165
2194
  };
2166
- await S.validate(
2195
+ await puv.validate(
2167
2196
  countMethod,
2168
2197
  'replaceOrCreate',
2169
2198
  'model',
@@ -2174,8 +2203,8 @@ describe('PropertyUniquenessValidator', function () {
2174
2203
  });
2175
2204
 
2176
2205
  it('checks the given identifier only once', async function () {
2177
- const schema = new Schema();
2178
- schema.defineModel({
2206
+ const dbs = new DatabaseSchema();
2207
+ dbs.defineModel({
2179
2208
  name: 'model',
2180
2209
  properties: {
2181
2210
  foo: {
@@ -2188,7 +2217,7 @@ describe('PropertyUniquenessValidator', function () {
2188
2217
  },
2189
2218
  },
2190
2219
  });
2191
- const S = schema.getService(PropertyUniquenessValidator);
2220
+ const puv = dbs.getService(PropertyUniquenessValidator);
2192
2221
  let invoked = 0;
2193
2222
  const idValue = 1;
2194
2223
  const modelData = {[DEF_PK]: idValue, foo: 'val1', bar: 'val2'};
@@ -2203,7 +2232,7 @@ describe('PropertyUniquenessValidator', function () {
2203
2232
  invoked++;
2204
2233
  return 0;
2205
2234
  };
2206
- await S.validate(
2235
+ await puv.validate(
2207
2236
  countMethod,
2208
2237
  'replaceOrCreate',
2209
2238
  'model',
@@ -2213,8 +2242,8 @@ describe('PropertyUniquenessValidator', function () {
2213
2242
  });
2214
2243
 
2215
2244
  it('skips uniqueness checking for empty values', async function () {
2216
- const schema = new Schema();
2217
- schema.defineModel({
2245
+ const dbs = new DatabaseSchema();
2246
+ dbs.defineModel({
2218
2247
  name: 'model',
2219
2248
  properties: {
2220
2249
  foo: {
@@ -2227,9 +2256,9 @@ describe('PropertyUniquenessValidator', function () {
2227
2256
  },
2228
2257
  },
2229
2258
  });
2230
- const S = schema.getService(PropertyUniquenessValidator);
2231
- schema
2232
- .getService(EmptyValuesDefiner)
2259
+ const puv = dbs.getService(PropertyUniquenessValidator);
2260
+ dbs
2261
+ .getService(EmptyValuesService)
2233
2262
  .setEmptyValuesOf(DataType.STRING, ['val2']);
2234
2263
  let invoked = 0;
2235
2264
  const idValue = 1;
@@ -2243,7 +2272,7 @@ describe('PropertyUniquenessValidator', function () {
2243
2272
  invoked++;
2244
2273
  return 0;
2245
2274
  };
2246
- await S.validate(
2275
+ await puv.validate(
2247
2276
  countMethod,
2248
2277
  'replaceOrCreate',
2249
2278
  'model',
@@ -2255,8 +2284,8 @@ describe('PropertyUniquenessValidator', function () {
2255
2284
 
2256
2285
  describe('a document of the given identifier already exist', function () {
2257
2286
  it('uses the default primary key to check existence of the given identifier', async function () {
2258
- const schema = new Schema();
2259
- schema.defineModel({
2287
+ const dbs = new DatabaseSchema();
2288
+ dbs.defineModel({
2260
2289
  name: 'model',
2261
2290
  properties: {
2262
2291
  foo: {
@@ -2265,7 +2294,7 @@ describe('PropertyUniquenessValidator', function () {
2265
2294
  },
2266
2295
  },
2267
2296
  });
2268
- const S = schema.getService(PropertyUniquenessValidator);
2297
+ const puv = dbs.getService(PropertyUniquenessValidator);
2269
2298
  let invoked = 0;
2270
2299
  const idValue = 1;
2271
2300
  const modelData = {
@@ -2287,7 +2316,7 @@ describe('PropertyUniquenessValidator', function () {
2287
2316
  return 0;
2288
2317
  }
2289
2318
  };
2290
- await S.validate(
2319
+ await puv.validate(
2291
2320
  countMethod,
2292
2321
  'replaceOrCreate',
2293
2322
  'model',
@@ -2297,8 +2326,8 @@ describe('PropertyUniquenessValidator', function () {
2297
2326
  });
2298
2327
 
2299
2328
  it('uses a custom primary key to check existence of the given identifier', async function () {
2300
- const schema = new Schema();
2301
- schema.defineModel({
2329
+ const dbs = new DatabaseSchema();
2330
+ dbs.defineModel({
2302
2331
  name: 'model',
2303
2332
  properties: {
2304
2333
  myId: {
@@ -2311,7 +2340,7 @@ describe('PropertyUniquenessValidator', function () {
2311
2340
  },
2312
2341
  },
2313
2342
  });
2314
- const S = schema.getService(PropertyUniquenessValidator);
2343
+ const puv = dbs.getService(PropertyUniquenessValidator);
2315
2344
  let invoked = 0;
2316
2345
  const idValue = 1;
2317
2346
  const modelData = {myId: idValue, foo: 'bar'};
@@ -2330,7 +2359,7 @@ describe('PropertyUniquenessValidator', function () {
2330
2359
  return 0;
2331
2360
  }
2332
2361
  };
2333
- await S.validate(
2362
+ await puv.validate(
2334
2363
  countMethod,
2335
2364
  'replaceOrCreate',
2336
2365
  'model',
@@ -2341,8 +2370,8 @@ describe('PropertyUniquenessValidator', function () {
2341
2370
  });
2342
2371
 
2343
2372
  it('checks the given identifier only once', async function () {
2344
- const schema = new Schema();
2345
- schema.defineModel({
2373
+ const dbs = new DatabaseSchema();
2374
+ dbs.defineModel({
2346
2375
  name: 'model',
2347
2376
  properties: {
2348
2377
  foo: {
@@ -2355,7 +2384,7 @@ describe('PropertyUniquenessValidator', function () {
2355
2384
  },
2356
2385
  },
2357
2386
  });
2358
- const S = schema.getService(PropertyUniquenessValidator);
2387
+ const puv = dbs.getService(PropertyUniquenessValidator);
2359
2388
  let invoked = 0;
2360
2389
  const idValue = 1;
2361
2390
  const modelData = {
@@ -2382,7 +2411,7 @@ describe('PropertyUniquenessValidator', function () {
2382
2411
  return 0;
2383
2412
  }
2384
2413
  };
2385
- await S.validate(
2414
+ await puv.validate(
2386
2415
  countMethod,
2387
2416
  'replaceOrCreate',
2388
2417
  'model',
@@ -2392,8 +2421,8 @@ describe('PropertyUniquenessValidator', function () {
2392
2421
  });
2393
2422
 
2394
2423
  it('skips uniqueness checking for empty values', async function () {
2395
- const schema = new Schema();
2396
- schema.defineModel({
2424
+ const dbs = new DatabaseSchema();
2425
+ dbs.defineModel({
2397
2426
  name: 'model',
2398
2427
  properties: {
2399
2428
  foo: {
@@ -2406,9 +2435,9 @@ describe('PropertyUniquenessValidator', function () {
2406
2435
  },
2407
2436
  },
2408
2437
  });
2409
- const S = schema.getService(PropertyUniquenessValidator);
2410
- schema
2411
- .getService(EmptyValuesDefiner)
2438
+ const puv = dbs.getService(PropertyUniquenessValidator);
2439
+ dbs
2440
+ .getService(EmptyValuesService)
2412
2441
  .setEmptyValuesOf(DataType.STRING, ['val2']);
2413
2442
  let invoked = 0;
2414
2443
  const idValue = 1;
@@ -2426,7 +2455,7 @@ describe('PropertyUniquenessValidator', function () {
2426
2455
  return 0;
2427
2456
  }
2428
2457
  };
2429
- await S.validate(
2458
+ await puv.validate(
2430
2459
  countMethod,
2431
2460
  'replaceOrCreate',
2432
2461
  'model',
@@ -2440,8 +2469,8 @@ describe('PropertyUniquenessValidator', function () {
2440
2469
 
2441
2470
  describe('patch', function () {
2442
2471
  it('throws an error if the "countMethod" returns a positive number', async function () {
2443
- const schema = new Schema();
2444
- schema.defineModel({
2472
+ const dbs = new DatabaseSchema();
2473
+ dbs.defineModel({
2445
2474
  name: 'model',
2446
2475
  properties: {
2447
2476
  foo: {
@@ -2450,8 +2479,8 @@ describe('PropertyUniquenessValidator', function () {
2450
2479
  },
2451
2480
  },
2452
2481
  });
2453
- const S = schema.getService(PropertyUniquenessValidator);
2454
- const promise = S.validate(() => 1, 'patch', 'model', {foo: 'bar'});
2482
+ const puv = dbs.getService(PropertyUniquenessValidator);
2483
+ const promise = puv.validate(() => 1, 'patch', 'model', {foo: 'bar'});
2455
2484
  await expect(promise).to.be.rejectedWith(
2456
2485
  'An existing document of the model "model" already has ' +
2457
2486
  'the property "foo" with the value "bar" and should be unique.',
@@ -2459,8 +2488,8 @@ describe('PropertyUniquenessValidator', function () {
2459
2488
  });
2460
2489
 
2461
2490
  it('passes validation if the "countMethod" returns zero', async function () {
2462
- const schema = new Schema();
2463
- schema.defineModel({
2491
+ const dbs = new DatabaseSchema();
2492
+ dbs.defineModel({
2464
2493
  name: 'model',
2465
2494
  properties: {
2466
2495
  foo: {
@@ -2469,13 +2498,13 @@ describe('PropertyUniquenessValidator', function () {
2469
2498
  },
2470
2499
  },
2471
2500
  });
2472
- const S = schema.getService(PropertyUniquenessValidator);
2473
- await S.validate(() => 0, 'patch', 'model', {foo: 'bar'});
2501
+ const puv = dbs.getService(PropertyUniquenessValidator);
2502
+ await puv.validate(() => 0, 'patch', 'model', {foo: 'bar'});
2474
2503
  });
2475
2504
 
2476
2505
  it('invokes the "countMethod" for given properties which should be unique', async function () {
2477
- const schema = new Schema();
2478
- schema.defineModel({
2506
+ const dbs = new DatabaseSchema();
2507
+ dbs.defineModel({
2479
2508
  name: 'model',
2480
2509
  properties: {
2481
2510
  foo: {
@@ -2492,7 +2521,7 @@ describe('PropertyUniquenessValidator', function () {
2492
2521
  },
2493
2522
  },
2494
2523
  });
2495
- const S = schema.getService(PropertyUniquenessValidator);
2524
+ const puv = dbs.getService(PropertyUniquenessValidator);
2496
2525
  let invoked = 0;
2497
2526
  const modelData = {foo: 'val1', bar: 'val2'};
2498
2527
  const countMethod = where => {
@@ -2500,13 +2529,13 @@ describe('PropertyUniquenessValidator', function () {
2500
2529
  invoked++;
2501
2530
  return 0;
2502
2531
  };
2503
- await S.validate(countMethod, 'patch', 'model', modelData);
2532
+ await puv.validate(countMethod, 'patch', 'model', modelData);
2504
2533
  expect(invoked).to.be.eq(1);
2505
2534
  });
2506
2535
 
2507
2536
  it('skips uniqueness checking for non-provided fields', async function () {
2508
- const schema = new Schema();
2509
- schema.defineModel({
2537
+ const dbs = new DatabaseSchema();
2538
+ dbs.defineModel({
2510
2539
  name: 'model',
2511
2540
  properties: {
2512
2541
  foo: {
@@ -2515,9 +2544,13 @@ describe('PropertyUniquenessValidator', function () {
2515
2544
  },
2516
2545
  },
2517
2546
  });
2518
- const S = schema.getService(PropertyUniquenessValidator);
2519
- const promise1 = S.validate(() => 1, 'patch', 'model', {foo: 'bar'});
2520
- const promise2 = S.validate(() => 1, 'patch', 'model', {baz: 'qux'});
2547
+ const puv = dbs.getService(PropertyUniquenessValidator);
2548
+ const promise1 = puv.validate(() => 1, 'patch', 'model', {
2549
+ foo: 'bar',
2550
+ });
2551
+ const promise2 = puv.validate(() => 1, 'patch', 'model', {
2552
+ baz: 'qux',
2553
+ });
2521
2554
  await expect(promise1).to.be.rejectedWith(
2522
2555
  'An existing document of the model "model" already has ' +
2523
2556
  'the property "foo" with the value "bar" and should be unique.',
@@ -2526,8 +2559,8 @@ describe('PropertyUniquenessValidator', function () {
2526
2559
  });
2527
2560
 
2528
2561
  it('skips uniqueness checking for empty values', async function () {
2529
- const schema = new Schema();
2530
- schema.defineModel({
2562
+ const dbs = new DatabaseSchema();
2563
+ dbs.defineModel({
2531
2564
  name: 'model',
2532
2565
  properties: {
2533
2566
  foo: {
@@ -2540,9 +2573,9 @@ describe('PropertyUniquenessValidator', function () {
2540
2573
  },
2541
2574
  },
2542
2575
  });
2543
- const S = schema.getService(PropertyUniquenessValidator);
2544
- schema
2545
- .getService(EmptyValuesDefiner)
2576
+ const puv = dbs.getService(PropertyUniquenessValidator);
2577
+ dbs
2578
+ .getService(EmptyValuesService)
2546
2579
  .setEmptyValuesOf(DataType.STRING, ['val2']);
2547
2580
  let invoked = 0;
2548
2581
  const modelData = {foo: 'val1', bar: 'val2'};
@@ -2551,15 +2584,15 @@ describe('PropertyUniquenessValidator', function () {
2551
2584
  invoked++;
2552
2585
  return 0;
2553
2586
  };
2554
- await S.validate(countMethod, 'patch', 'model', modelData);
2587
+ await puv.validate(countMethod, 'patch', 'model', modelData);
2555
2588
  expect(invoked).to.be.eql(1);
2556
2589
  });
2557
2590
  });
2558
2591
 
2559
2592
  describe('patchById', function () {
2560
2593
  it('throws an error if the "countMethod" returns a positive number', async function () {
2561
- const schema = new Schema();
2562
- schema.defineModel({
2594
+ const dbs = new DatabaseSchema();
2595
+ dbs.defineModel({
2563
2596
  name: 'model',
2564
2597
  properties: {
2565
2598
  foo: {
@@ -2568,8 +2601,8 @@ describe('PropertyUniquenessValidator', function () {
2568
2601
  },
2569
2602
  },
2570
2603
  });
2571
- const S = schema.getService(PropertyUniquenessValidator);
2572
- const promise = S.validate(
2604
+ const puv = dbs.getService(PropertyUniquenessValidator);
2605
+ const promise = puv.validate(
2573
2606
  () => 1,
2574
2607
  'patchById',
2575
2608
  'model',
@@ -2583,8 +2616,8 @@ describe('PropertyUniquenessValidator', function () {
2583
2616
  });
2584
2617
 
2585
2618
  it('passes validation if the "countMethod" returns zero', async function () {
2586
- const schema = new Schema();
2587
- schema.defineModel({
2619
+ const dbs = new DatabaseSchema();
2620
+ dbs.defineModel({
2588
2621
  name: 'model',
2589
2622
  properties: {
2590
2623
  foo: {
@@ -2593,13 +2626,13 @@ describe('PropertyUniquenessValidator', function () {
2593
2626
  },
2594
2627
  },
2595
2628
  });
2596
- const S = schema.getService(PropertyUniquenessValidator);
2597
- await S.validate(() => 0, 'patchById', 'model', {foo: 'bar'}, 1);
2629
+ const puv = dbs.getService(PropertyUniquenessValidator);
2630
+ await puv.validate(() => 0, 'patchById', 'model', {foo: 'bar'}, 1);
2598
2631
  });
2599
2632
 
2600
2633
  it('invokes the "countMethod" for given properties which should be unique', async function () {
2601
- const schema = new Schema();
2602
- schema.defineModel({
2634
+ const dbs = new DatabaseSchema();
2635
+ dbs.defineModel({
2603
2636
  name: 'model',
2604
2637
  properties: {
2605
2638
  foo: {
@@ -2616,7 +2649,7 @@ describe('PropertyUniquenessValidator', function () {
2616
2649
  },
2617
2650
  },
2618
2651
  });
2619
- const S = schema.getService(PropertyUniquenessValidator);
2652
+ const puv = dbs.getService(PropertyUniquenessValidator);
2620
2653
  let invoked = 0;
2621
2654
  const idValue = 1;
2622
2655
  const modelData = {foo: 'val1', bar: 'val2'};
@@ -2629,7 +2662,7 @@ describe('PropertyUniquenessValidator', function () {
2629
2662
  invoked++;
2630
2663
  return 0;
2631
2664
  };
2632
- await S.validate(
2665
+ await puv.validate(
2633
2666
  countMethod,
2634
2667
  'patchById',
2635
2668
  'model',
@@ -2640,8 +2673,8 @@ describe('PropertyUniquenessValidator', function () {
2640
2673
  });
2641
2674
 
2642
2675
  it('skips uniqueness checking for non-provided fields', async function () {
2643
- const schema = new Schema();
2644
- schema.defineModel({
2676
+ const dbs = new DatabaseSchema();
2677
+ dbs.defineModel({
2645
2678
  name: 'model',
2646
2679
  properties: {
2647
2680
  foo: {
@@ -2650,11 +2683,11 @@ describe('PropertyUniquenessValidator', function () {
2650
2683
  },
2651
2684
  },
2652
2685
  });
2653
- const S = schema.getService(PropertyUniquenessValidator);
2654
- const promise1 = S.validate(() => 1, 'patchById', 'model', {
2686
+ const puv = dbs.getService(PropertyUniquenessValidator);
2687
+ const promise1 = puv.validate(() => 1, 'patchById', 'model', {
2655
2688
  foo: 'bar',
2656
2689
  });
2657
- const promise2 = S.validate(() => 1, 'patchById', 'model', {
2690
+ const promise2 = puv.validate(() => 1, 'patchById', 'model', {
2658
2691
  baz: 'qux',
2659
2692
  });
2660
2693
  await expect(promise1).to.be.rejectedWith(
@@ -2665,8 +2698,8 @@ describe('PropertyUniquenessValidator', function () {
2665
2698
  });
2666
2699
 
2667
2700
  it('skips uniqueness checking for empty values', async function () {
2668
- const schema = new Schema();
2669
- schema.defineModel({
2701
+ const dbs = new DatabaseSchema();
2702
+ dbs.defineModel({
2670
2703
  name: 'model',
2671
2704
  properties: {
2672
2705
  foo: {
@@ -2679,10 +2712,10 @@ describe('PropertyUniquenessValidator', function () {
2679
2712
  },
2680
2713
  },
2681
2714
  });
2682
- const S = schema.getService(PropertyUniquenessValidator);
2715
+ const puv = dbs.getService(PropertyUniquenessValidator);
2683
2716
  let invoked = 0;
2684
- schema
2685
- .getService(EmptyValuesDefiner)
2717
+ dbs
2718
+ .getService(EmptyValuesService)
2686
2719
  .setEmptyValuesOf(DataType.STRING, ['val2']);
2687
2720
  const modelData = {foo: 'val1', bar: 'val2'};
2688
2721
  const countMethod = where => {
@@ -2694,13 +2727,13 @@ describe('PropertyUniquenessValidator', function () {
2694
2727
  invoked++;
2695
2728
  return 0;
2696
2729
  };
2697
- await S.validate(countMethod, 'patchById', 'model', modelData, 1);
2730
+ await puv.validate(countMethod, 'patchById', 'model', modelData, 1);
2698
2731
  expect(invoked).to.be.eql(1);
2699
2732
  });
2700
2733
 
2701
2734
  it('uses a custom primary key to check existence of the given identifier', async function () {
2702
- const schema = new Schema();
2703
- schema.defineModel({
2735
+ const dbs = new DatabaseSchema();
2736
+ dbs.defineModel({
2704
2737
  name: 'model',
2705
2738
  properties: {
2706
2739
  myId: {
@@ -2713,7 +2746,7 @@ describe('PropertyUniquenessValidator', function () {
2713
2746
  },
2714
2747
  },
2715
2748
  });
2716
- const S = schema.getService(PropertyUniquenessValidator);
2749
+ const puv = dbs.getService(PropertyUniquenessValidator);
2717
2750
  let invoked = 0;
2718
2751
  const idValue = 1;
2719
2752
  const modelData = {foo: 'bar'};
@@ -2726,7 +2759,7 @@ describe('PropertyUniquenessValidator', function () {
2726
2759
  invoked++;
2727
2760
  return 0;
2728
2761
  };
2729
- await S.validate(
2762
+ await puv.validate(
2730
2763
  countMethod,
2731
2764
  'patchById',
2732
2765
  'model',