@nymphjs/nymph 1.0.0-beta.6 → 1.0.0-beta.60

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 (64) hide show
  1. package/CHANGELOG.md +273 -0
  2. package/README.md +13 -21
  3. package/dist/Entity.d.ts +269 -7
  4. package/dist/Entity.js +431 -89
  5. package/dist/Entity.js.map +1 -1
  6. package/dist/Entity.test.js +38 -16
  7. package/dist/Entity.test.js.map +1 -1
  8. package/dist/Entity.types.d.ts +225 -19
  9. package/dist/Nymph.d.ts +423 -11
  10. package/dist/Nymph.js +649 -156
  11. package/dist/Nymph.js.map +1 -1
  12. package/dist/Nymph.types.d.ts +31 -7
  13. package/dist/Nymph.types.js +2 -1
  14. package/dist/Nymph.types.js.map +1 -1
  15. package/dist/conf/d.d.ts +26 -0
  16. package/dist/conf/defaults.js +22 -0
  17. package/dist/conf/defaults.js.map +1 -1
  18. package/dist/driver/NymphDriver.d.ts +111 -36
  19. package/dist/driver/NymphDriver.js +169 -68
  20. package/dist/driver/NymphDriver.js.map +1 -1
  21. package/dist/driver/testArtifacts.d.ts +1 -1
  22. package/dist/driver/testArtifacts.js +285 -18
  23. package/dist/driver/testArtifacts.js.map +1 -1
  24. package/dist/errors/EntityInvalidDataError.d.ts +6 -0
  25. package/dist/errors/EntityInvalidDataError.js +6 -0
  26. package/dist/errors/EntityInvalidDataError.js.map +1 -1
  27. package/dist/errors/EntityUniqueConstraintError.d.ts +3 -0
  28. package/dist/errors/EntityUniqueConstraintError.js +11 -0
  29. package/dist/errors/EntityUniqueConstraintError.js.map +1 -0
  30. package/dist/errors/InvalidStateError.d.ts +3 -0
  31. package/dist/errors/InvalidStateError.js +11 -0
  32. package/dist/errors/InvalidStateError.js.map +1 -0
  33. package/dist/errors/QueryFailedError.js.map +1 -1
  34. package/dist/errors/index.d.ts +2 -0
  35. package/dist/errors/index.js +2 -0
  36. package/dist/errors/index.js.map +1 -1
  37. package/dist/testArtifacts.d.ts +17 -5
  38. package/dist/testArtifacts.js +23 -19
  39. package/dist/testArtifacts.js.map +1 -1
  40. package/dist/testMocks.d.ts +15 -10
  41. package/dist/testMocks.js +34 -11
  42. package/dist/testMocks.js.map +1 -1
  43. package/dist/utils.d.ts +1 -1
  44. package/dist/utils.js +21 -5
  45. package/dist/utils.js.map +1 -1
  46. package/package.json +16 -14
  47. package/src/Entity.test.ts +30 -10
  48. package/src/Entity.ts +406 -135
  49. package/src/Entity.types.ts +32 -66
  50. package/src/Nymph.ts +626 -196
  51. package/src/Nymph.types.ts +97 -26
  52. package/src/conf/d.ts +8 -0
  53. package/src/conf/defaults.ts +24 -0
  54. package/src/driver/NymphDriver.ts +187 -243
  55. package/src/driver/testArtifacts.ts +327 -146
  56. package/src/errors/EntityUniqueConstraintError.ts +6 -0
  57. package/src/errors/InvalidStateError.ts +6 -0
  58. package/src/errors/index.ts +4 -0
  59. package/src/nymphJoiProps.ts +2 -2
  60. package/src/testArtifacts.ts +18 -19
  61. package/src/testMocks.ts +64 -32
  62. package/src/utils.ts +22 -8
  63. package/tsconfig.json +1 -1
  64. package/typedoc.json +4 -0
@@ -3,18 +3,21 @@ import strtotime from 'locutus/php/datetime/strtotime';
3
3
  import { guid } from '@nymphjs/guid';
4
4
 
5
5
  import type Nymph from '../Nymph';
6
+ import { EntityUniqueConstraintError } from '../errors';
6
7
  import {
7
8
  TestBModel as TestBModelClass,
8
9
  TestModel as TestModelClass,
9
10
  TestModelData,
11
+ TestEmptyModel as TestEmptyModelClass,
10
12
  } from '../testArtifacts';
11
13
 
12
- export function QueriesTest(
14
+ export function EntitiesTest(
13
15
  nymph: Nymph,
14
- it: (name: string, fn: () => void) => void
16
+ it: (name: string, fn: () => void) => void,
15
17
  ) {
16
18
  const TestModel = nymph.addEntityClass(TestModelClass);
17
19
  const TestBModel = nymph.addEntityClass(TestBModelClass);
20
+ const TestEmptyModel = nymph.addEntityClass(TestEmptyModelClass);
18
21
 
19
22
  let testEntity: TestModelClass & TestModelData;
20
23
  let testGuid: string;
@@ -39,7 +42,10 @@ export function QueriesTest(
39
42
 
40
43
  This one's email address is nice_hat-wednesday+newyork@im-a-hat.hat.
41
44
  This one's phone number is (555) 555-1818.
42
- This one's zip code is 92064.`;
45
+ This one's zip code is 92064.
46
+ This one's favorite emojis are 🔥❤️😊😂⭐🤔
47
+
48
+ These hats are absolutely fantastic.`;
43
49
  testEntity.number = 30;
44
50
  testEntity.numberString = '30';
45
51
  testEntity.timestamp = Date.now();
@@ -59,18 +65,10 @@ This one's zip code is 92064.`;
59
65
  entityReferenceTest.test = 'good';
60
66
  expect(await entityReferenceTest.$save()).toEqual(true);
61
67
 
62
- // Test synchronous getEntity.
63
- testEntity = nymph.driver.getEntitySync(
64
- { class: TestModel },
65
- testGuid
66
- ) as TestModelClass & TestModelData;
67
- expect(testEntity).toBeInstanceOf(TestModel);
68
- expect(testEntity.guid).toEqual(testGuid);
69
-
70
68
  // Test asynchronous getEntity.
71
69
  testEntity = (await nymph.getEntity(
72
70
  { class: TestModel },
73
- testGuid
71
+ testGuid,
74
72
  )) as TestModelClass & TestModelData;
75
73
  expect(testEntity).toBeInstanceOf(TestModel);
76
74
  expect(testEntity.guid).toEqual(testGuid);
@@ -84,6 +82,8 @@ This one's zip code is 92064.`;
84
82
  for (let i = 0; i < 100; i++) {
85
83
  const testEntity = await TestModel.factory();
86
84
  testEntity.name = `Multi Test ${i}`;
85
+ // Reverse the number for sort testing.
86
+ testEntity.number = 100 - i;
87
87
  testEntity.$removeTag('test');
88
88
  testEntity.$addTag('multiTest');
89
89
  expect(await testEntity.$save()).toEqual(true);
@@ -108,6 +108,13 @@ This one's zip code is 92064.`;
108
108
  await createTestEntities();
109
109
  });
110
110
 
111
+ it("doesn't create empty entity", async () => {
112
+ const testEntity = await TestEmptyModel.factory();
113
+
114
+ expect(await testEntity.$save()).toBeFalsy();
115
+ expect(testEntity.guid).toBeNull();
116
+ });
117
+
111
118
  it('update mdate on save', async () => {
112
119
  await createTestEntities();
113
120
 
@@ -150,7 +157,7 @@ This one's zip code is 92064.`;
150
157
 
151
158
  if (!(await transaction.inTransaction())) {
152
159
  console.log(
153
- 'This Nymph driver or database seems to not support transactions. Skipping transaction tests.'
160
+ 'This Nymph driver or database seems to not support transactions. Skipping transaction tests.',
154
161
  );
155
162
  await transaction.rollback('test');
156
163
  return;
@@ -181,7 +188,7 @@ This one's zip code is 92064.`;
181
188
  expect(await testEntity.$delete()).toEqual(true);
182
189
  const resultEntity = await transaction.getEntity(
183
190
  { class: TestModel },
184
- testGuid
191
+ testGuid,
185
192
  );
186
193
  expect(resultEntity).toBeNull();
187
194
 
@@ -194,13 +201,13 @@ This one's zip code is 92064.`;
194
201
  // Verify it's back.
195
202
  testEntity = (await transaction.getEntity(
196
203
  { class: TestModel },
197
- testGuid
204
+ testGuid,
198
205
  )) as TestModelClass & TestModelData;
199
206
 
200
207
  expect(testEntity.guid).toEqual(testGuid);
201
208
 
202
- // Start a new transaction.
203
- transaction = await nymph.startTransaction('test');
209
+ // Start a new transaction with a dot in the name.
210
+ transaction = await nymph.startTransaction('test.1');
204
211
  testEntity.$nymph = transaction;
205
212
 
206
213
  // Verify in a transaction.
@@ -211,7 +218,7 @@ This one's zip code is 92064.`;
211
218
  expect(await testEntity.$save()).toEqual(true);
212
219
 
213
220
  // Commit the transaction.
214
- await transaction.commit('test');
221
+ await transaction.commit('test.1');
215
222
  testEntity.$nymph = nymph;
216
223
 
217
224
  // Verify not in a transaction.
@@ -240,7 +247,7 @@ This one's zip code is 92064.`;
240
247
  limit: 1,
241
248
  sort: 'cdate',
242
249
  },
243
- { type: '&', tag: 'test' }
250
+ { type: '&', tag: 'test' },
244
251
  );
245
252
  expect(resultEntities.length).toEqual(1);
246
253
  expect(testEntity.$is(resultEntities[0])).toEqual(true);
@@ -252,7 +259,7 @@ This one's zip code is 92064.`;
252
259
  // Retrieving entity by GUID and tags...
253
260
  const resultEntity = await nymph.getEntity(
254
261
  { class: TestModel },
255
- { type: '&', guid: testGuid, tag: 'test' }
262
+ { type: '&', guid: testGuid, tag: 'test' },
256
263
  );
257
264
  expect(testEntity.$is(resultEntity)).toEqual(true);
258
265
  });
@@ -263,7 +270,7 @@ This one's zip code is 92064.`;
263
270
  // Retrieving entity by GUID and tags...
264
271
  const resultEntity = await nymph.getEntity(
265
272
  { class: TestModel },
266
- { type: '|', guid: [testGuid, guid()] }
273
+ { type: '|', guid: [testGuid, guid()] },
267
274
  );
268
275
  expect(testEntity.$is(resultEntity)).toEqual(true);
269
276
  });
@@ -274,7 +281,7 @@ This one's zip code is 92064.`;
274
281
  // Retrieving entity by GUID and tags...
275
282
  const resultEntity = await nymph.getEntity(
276
283
  { class: TestModel },
277
- { type: '|', guid: [guid(), guid()] }
284
+ { type: '|', guid: [guid(), guid()] },
278
285
  );
279
286
  expect(testEntity.$is(resultEntity)).toEqual(false);
280
287
  });
@@ -285,7 +292,7 @@ This one's zip code is 92064.`;
285
292
  // Retrieving entity by !GUID...
286
293
  const resultEntity = await nymph.getEntities(
287
294
  { class: TestModel },
288
- { type: '&', '!guid': guid(), tag: 'test' }
295
+ { type: '&', '!guid': guid(), tag: 'test' },
289
296
  );
290
297
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
291
298
  });
@@ -296,7 +303,7 @@ This one's zip code is 92064.`;
296
303
  // Retrieving entity by !tags...
297
304
  const resultEntity = await nymph.getEntities(
298
305
  { class: TestModel },
299
- { type: '&', guid: testGuid, '!tag': ['barbecue', 'pickles'] }
306
+ { type: '&', guid: testGuid, '!tag': ['barbecue', 'pickles'] },
300
307
  );
301
308
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
302
309
  });
@@ -307,7 +314,7 @@ This one's zip code is 92064.`;
307
314
  // Testing GUID and wrong tags...
308
315
  const resultEntity = await nymph.getEntity(
309
316
  { class: TestModel },
310
- { type: '&', guid: testGuid, tag: ['pickles'] }
317
+ { type: '&', guid: testGuid, tag: ['pickles'] },
311
318
  );
312
319
  expect(resultEntity).toBeNull();
313
320
  });
@@ -318,7 +325,7 @@ This one's zip code is 92064.`;
318
325
  // Retrieving entity by tags...
319
326
  const resultEntity = await nymph.getEntities(
320
327
  { class: TestModel },
321
- { type: '&', tag: 'test' }
328
+ { type: '&', tag: 'test' },
322
329
  );
323
330
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
324
331
  });
@@ -329,7 +336,7 @@ This one's zip code is 92064.`;
329
336
  // Testing wrong tags...
330
337
  const resultEntity = await nymph.getEntities(
331
338
  { class: TestModel },
332
- { type: '&', tag: 'pickles' }
339
+ { type: '&', tag: 'pickles' },
333
340
  );
334
341
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
335
342
  });
@@ -340,7 +347,7 @@ This one's zip code is 92064.`;
340
347
  // Retrieving entity by tags inclusively...
341
348
  const resultEntity = await nymph.getEntities(
342
349
  { class: TestModel },
343
- { type: '|', tag: ['pickles', 'test', 'barbecue'] }
350
+ { type: '|', tag: ['pickles', 'test', 'barbecue'] },
344
351
  );
345
352
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
346
353
  });
@@ -351,7 +358,7 @@ This one's zip code is 92064.`;
351
358
  // Testing wrong inclusive tags...
352
359
  const resultEntity = await nymph.getEntities(
353
360
  { class: TestModel },
354
- { type: '|', tag: ['pickles', 'barbecue'] }
361
+ { type: '|', tag: ['pickles', 'barbecue'] },
355
362
  );
356
363
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
357
364
  });
@@ -363,7 +370,7 @@ This one's zip code is 92064.`;
363
370
  const resultEntity = await nymph.getEntities(
364
371
  { class: TestModel },
365
372
  { type: '&', tag: 'test' },
366
- { type: '|', tag: ['pickles', 'test', 'barbecue'] }
373
+ { type: '|', tag: ['pickles', 'test', 'barbecue'] },
367
374
  );
368
375
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
369
376
  });
@@ -375,7 +382,7 @@ This one's zip code is 92064.`;
375
382
  const resultEntity = await nymph.getEntities(
376
383
  { class: TestModel },
377
384
  { type: '&', tag: 'test' },
378
- { type: '|', tag: ['pickles', 'barbecue'] }
385
+ { type: '|', tag: ['pickles', 'barbecue'] },
379
386
  );
380
387
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
381
388
  });
@@ -387,7 +394,7 @@ This one's zip code is 92064.`;
387
394
  const resultEntity = await nymph.getEntities(
388
395
  { class: TestModel },
389
396
  { type: '&', tag: 'pickles' },
390
- { type: '|', tag: ['test', 'barbecue'] }
397
+ { type: '|', tag: ['test', 'barbecue'] },
391
398
  );
392
399
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
393
400
  });
@@ -398,7 +405,7 @@ This one's zip code is 92064.`;
398
405
  // Retrieving entity by defined...
399
406
  const resultEntity = await nymph.getEntities(
400
407
  { class: TestModel },
401
- { type: '&', defined: 'string' }
408
+ { type: '&', defined: 'string' },
402
409
  );
403
410
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
404
411
  });
@@ -409,7 +416,7 @@ This one's zip code is 92064.`;
409
416
  // Retrieving entity by !defined...
410
417
  const resultEntity = await nymph.getEntities(
411
418
  { class: TestModel },
412
- { type: '&', tag: 'test', '!defined': 'pickles' }
419
+ { type: '&', tag: 'test', '!defined': 'pickles' },
413
420
  );
414
421
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
415
422
  });
@@ -421,7 +428,7 @@ This one's zip code is 92064.`;
421
428
  const resultEntity = await nymph.getEntities(
422
429
  { class: TestModel },
423
430
  { type: '!&', defined: 'pickles' },
424
- { type: '&', tag: 'test' }
431
+ { type: '&', tag: 'test' },
425
432
  );
426
433
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
427
434
  });
@@ -432,7 +439,7 @@ This one's zip code is 92064.`;
432
439
  // Retrieving entity by equal...
433
440
  const resultEntity = await nymph.getEntities(
434
441
  { class: TestModel },
435
- { type: '&', equal: ['string', 'test'] }
442
+ { type: '&', equal: ['string', 'test'] },
436
443
  );
437
444
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
438
445
  });
@@ -446,7 +453,7 @@ This one's zip code is 92064.`;
446
453
  // Retrieving entity by !equal...
447
454
  const resultEntity = await nymph.getEntities(
448
455
  { class: TestModel },
449
- { type: '&', tag: 'test', '!equal': ['string', 'wrong'] }
456
+ { type: '&', tag: 'test', '!equal': ['string', 'wrong'] },
450
457
  );
451
458
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
452
459
  expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
@@ -458,7 +465,7 @@ This one's zip code is 92064.`;
458
465
  // Retrieving entity by like...
459
466
  const resultEntity = await nymph.getEntities(
460
467
  { class: TestModel },
461
- { type: '&', like: ['string', 't_s%'] }
468
+ { type: '&', like: ['string', 't_s%'] },
462
469
  );
463
470
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
464
471
  });
@@ -472,7 +479,7 @@ This one's zip code is 92064.`;
472
479
  // Retrieving entity by !like...
473
480
  const resultEntity = await nymph.getEntities(
474
481
  { class: TestModel },
475
- { type: '&', tag: 'test', '!like': ['string', 'wr_n%'] }
482
+ { type: '&', tag: 'test', '!like': ['string', 'wr_n%'] },
476
483
  );
477
484
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
478
485
  expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
@@ -484,7 +491,7 @@ This one's zip code is 92064.`;
484
491
  // Retrieving entity by ilike...
485
492
  const resultEntity = await nymph.getEntities(
486
493
  { class: TestModel },
487
- { type: '&', ilike: ['string', 'T_s%'] }
494
+ { type: '&', ilike: ['string', 'T_s%'] },
488
495
  );
489
496
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
490
497
  });
@@ -498,7 +505,7 @@ This one's zip code is 92064.`;
498
505
  // Retrieving entity by !ilike...
499
506
  const resultEntity = await nymph.getEntities(
500
507
  { class: TestModel },
501
- { type: '&', tag: 'test', '!ilike': ['string', 'wr_n%'] }
508
+ { type: '&', tag: 'test', '!ilike': ['string', 'wr_n%'] },
502
509
  );
503
510
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
504
511
  expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
@@ -510,7 +517,7 @@ This one's zip code is 92064.`;
510
517
  // Retrieving entity by like...
511
518
  const resultEntity = await nymph.getEntities(
512
519
  { class: TestModel },
513
- { type: '&', like: ['string', 'T_s%'] }
520
+ { type: '&', like: ['string', 'T_s%'] },
514
521
  );
515
522
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
516
523
  });
@@ -521,7 +528,7 @@ This one's zip code is 92064.`;
521
528
  // Retrieving entity by tags and equal...
522
529
  const resultEntity = await nymph.getEntities(
523
530
  { class: TestModel },
524
- { type: '&', tag: 'test', equal: ['string', 'test'] }
531
+ { type: '&', tag: 'test', equal: ['string', 'test'] },
525
532
  );
526
533
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
527
534
  });
@@ -532,7 +539,7 @@ This one's zip code is 92064.`;
532
539
  // Testing wrong tags and right equal...
533
540
  const resultEntity = await nymph.getEntities(
534
541
  { class: TestModel },
535
- { type: '&', tag: 'pickles', equal: ['string', 'test'] }
542
+ { type: '&', tag: 'pickles', equal: ['string', 'test'] },
536
543
  );
537
544
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
538
545
  });
@@ -543,7 +550,7 @@ This one's zip code is 92064.`;
543
550
  // Testing right tags and wrong equal...
544
551
  const resultEntity = await nymph.getEntities(
545
552
  { class: TestModel },
546
- { type: '&', tag: 'test', equal: ['string', 'pickles'] }
553
+ { type: '&', tag: 'test', equal: ['string', 'pickles'] },
547
554
  );
548
555
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
549
556
  });
@@ -554,7 +561,7 @@ This one's zip code is 92064.`;
554
561
  // Testing wrong tags and wrong equal...
555
562
  const resultEntity = await nymph.getEntities(
556
563
  { class: TestModel },
557
- { type: '&', tag: 'pickles', equal: ['string', 'pickles'] }
564
+ { type: '&', tag: 'pickles', equal: ['string', 'pickles'] },
558
565
  );
559
566
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
560
567
  });
@@ -565,14 +572,14 @@ This one's zip code is 92064.`;
565
572
  // Retrieving entity by contain...
566
573
  let resultEntity = await nymph.getEntities(
567
574
  { class: TestModel },
568
- { type: '&', contain: ['array', 'values'] }
575
+ { type: '&', contain: ['array', 'values'] },
569
576
  );
570
577
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
571
578
 
572
579
  // Retrieving entity by contain with full match...
573
580
  resultEntity = await nymph.getEntities(
574
581
  { class: TestModel },
575
- { type: '&', contain: ['string', 'test'] }
582
+ { type: '&', contain: ['string', 'test'] },
576
583
  );
577
584
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
578
585
  });
@@ -584,7 +591,7 @@ This one's zip code is 92064.`;
584
591
  const resultEntity = await nymph.getEntities(
585
592
  { class: TestModel },
586
593
  { type: '&', tag: 'test' },
587
- { type: '!&', contain: ['array', 'pickles'] }
594
+ { type: '!&', contain: ['array', 'pickles'] },
588
595
  );
589
596
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
590
597
  });
@@ -595,14 +602,14 @@ This one's zip code is 92064.`;
595
602
  // Testing wrong contain...
596
603
  let resultEntity = await nymph.getEntities(
597
604
  { class: TestModel },
598
- { type: '&', contain: ['array', 'pickles'] }
605
+ { type: '&', contain: ['array', 'pickles'] },
599
606
  );
600
607
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
601
608
 
602
609
  // Testing wrong contain...
603
610
  resultEntity = await nymph.getEntities(
604
611
  { class: TestModel },
605
- { type: '&', contain: ['string', 'pickles'] }
612
+ { type: '&', contain: ['string', 'pickles'] },
606
613
  );
607
614
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
608
615
  });
@@ -613,12 +620,12 @@ This one's zip code is 92064.`;
613
620
  // Retrieving entity by regex match...
614
621
  let resultEntity = await nymph.getEntities(
615
622
  { class: TestModel },
616
- { type: '&', match: ['match', '.*'] } // anything
623
+ { type: '&', match: ['match', '.*'] }, // anything
617
624
  );
618
625
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
619
626
  resultEntity = await nymph.getEntities(
620
627
  { class: TestModel },
621
- { type: '&', tag: 'test', match: ['match', 'Edward McCheese'] } // a substring
628
+ { type: '&', tag: 'test', match: ['match', 'Edward McCheese'] }, // a substring
622
629
  );
623
630
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
624
631
  resultEntity = await nymph.getEntities(
@@ -630,7 +637,7 @@ This one's zip code is 92064.`;
630
637
  ['string', '[0-9]'],
631
638
  ['match', 'Edward McCheese'],
632
639
  ],
633
- } // inclusive test
640
+ }, // inclusive test
634
641
  );
635
642
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
636
643
  resultEntity = await nymph.getEntities(
@@ -639,7 +646,7 @@ This one's zip code is 92064.`;
639
646
  type: '&',
640
647
  tag: 'test',
641
648
  match: ['match', '[-a-zA-Z0-9+_]+@[-a-zA-Z0-9_]+.[-a-zA-Z0-9_]{2,4}'],
642
- } // a simple email
649
+ }, // a simple email
643
650
  );
644
651
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
645
652
  resultEntity = await nymph.getEntities(
@@ -648,7 +655,7 @@ This one's zip code is 92064.`;
648
655
  type: '&',
649
656
  tag: 'test',
650
657
  match: ['match', '\\([0-9]{3}\\) [0-9]{3}-[0-9]{4}'],
651
- } // a phone number
658
+ }, // a phone number
652
659
  );
653
660
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
654
661
  });
@@ -659,7 +666,7 @@ This one's zip code is 92064.`;
659
666
  // Retrieving entity by regex match...
660
667
  const resultEntity = await nymph.getEntities(
661
668
  { class: TestModel },
662
- { type: '&', tag: 'test', imatch: ['match', 'edward mccheese'] } // a substring
669
+ { type: '&', tag: 'test', imatch: ['match', 'edward mccheese'] }, // a substring
663
670
  );
664
671
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
665
672
  });
@@ -670,12 +677,12 @@ This one's zip code is 92064.`;
670
677
  // Testing wrong regex match...
671
678
  let resultEntity = await nymph.getEntities(
672
679
  { class: TestModel },
673
- { type: '&', match: ['match', 'Q'] }
680
+ { type: '&', match: ['match', 'Q'] },
674
681
  );
675
682
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
676
683
  resultEntity = await nymph.getEntities(
677
684
  { class: TestModel },
678
- { type: '&', tag: 'pickle', match: ['match', '.*'] }
685
+ { type: '&', tag: 'pickle', match: ['match', '.*'] },
679
686
  );
680
687
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
681
688
  resultEntity = await nymph.getEntities(
@@ -686,7 +693,7 @@ This one's zip code is 92064.`;
686
693
  ['string', '[0-9]'],
687
694
  ['match', ',,'],
688
695
  ],
689
- }
696
+ },
690
697
  );
691
698
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
692
699
  });
@@ -697,7 +704,7 @@ This one's zip code is 92064.`;
697
704
  // Retrieving entity by regex match...
698
705
  const resultEntity = await nymph.getEntities(
699
706
  { class: TestModel },
700
- { type: '&', tag: 'test', match: ['match', 'edward mccheese'] } // a substring
707
+ { type: '&', tag: 'test', match: ['match', 'edward mccheese'] }, // a substring
701
708
  );
702
709
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
703
710
  });
@@ -709,7 +716,7 @@ This one's zip code is 92064.`;
709
716
  const resultEntity = await nymph.getEntities(
710
717
  { class: TestModel },
711
718
  { type: '&', tag: 'test' },
712
- { type: '|', equal: ['string', 'pickles'], match: ['string', 'test'] }
719
+ { type: '|', equal: ['string', 'pickles'], match: ['string', 'test'] },
713
720
  );
714
721
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
715
722
  });
@@ -726,7 +733,7 @@ This one's zip code is 92064.`;
726
733
  ['number', 30],
727
734
  ['pickles', 100],
728
735
  ],
729
- }
736
+ },
730
737
  );
731
738
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
732
739
 
@@ -739,7 +746,7 @@ This one's zip code is 92064.`;
739
746
  ['number', 31],
740
747
  ['pickles', 100],
741
748
  ],
742
- }
749
+ },
743
750
  );
744
751
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
745
752
 
@@ -752,7 +759,7 @@ This one's zip code is 92064.`;
752
759
  ['number', 29],
753
760
  ['pickles', 100],
754
761
  ],
755
- }
762
+ },
756
763
  );
757
764
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
758
765
 
@@ -765,7 +772,7 @@ This one's zip code is 92064.`;
765
772
  ['numberString', 30],
766
773
  ['pickles', 100],
767
774
  ],
768
- }
775
+ },
769
776
  );
770
777
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
771
778
 
@@ -778,7 +785,7 @@ This one's zip code is 92064.`;
778
785
  ['numberString', 31],
779
786
  ['pickles', 100],
780
787
  ],
781
- }
788
+ },
782
789
  );
783
790
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
784
791
 
@@ -791,7 +798,7 @@ This one's zip code is 92064.`;
791
798
  ['numberString', 29],
792
799
  ['pickles', 100],
793
800
  ],
794
- }
801
+ },
795
802
  );
796
803
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
797
804
  });
@@ -808,7 +815,7 @@ This one's zip code is 92064.`;
808
815
  ['number', 30],
809
816
  ['pickles', 100],
810
817
  ],
811
- }
818
+ },
812
819
  );
813
820
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
814
821
 
@@ -821,7 +828,7 @@ This one's zip code is 92064.`;
821
828
  ['number', 31],
822
829
  ['pickles', 100],
823
830
  ],
824
- }
831
+ },
825
832
  );
826
833
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
827
834
 
@@ -834,7 +841,7 @@ This one's zip code is 92064.`;
834
841
  ['number', 29],
835
842
  ['pickles', 100],
836
843
  ],
837
- }
844
+ },
838
845
  );
839
846
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
840
847
 
@@ -847,7 +854,7 @@ This one's zip code is 92064.`;
847
854
  ['numberString', 30],
848
855
  ['pickles', 100],
849
856
  ],
850
- }
857
+ },
851
858
  );
852
859
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
853
860
 
@@ -860,7 +867,7 @@ This one's zip code is 92064.`;
860
867
  ['numberString', 31],
861
868
  ['pickles', 100],
862
869
  ],
863
- }
870
+ },
864
871
  );
865
872
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
866
873
 
@@ -873,7 +880,7 @@ This one's zip code is 92064.`;
873
880
  ['numberString', 29],
874
881
  ['pickles', 100],
875
882
  ],
876
- }
883
+ },
877
884
  );
878
885
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
879
886
  });
@@ -890,7 +897,7 @@ This one's zip code is 92064.`;
890
897
  ['number', 30],
891
898
  ['pickles', 100],
892
899
  ],
893
- }
900
+ },
894
901
  );
895
902
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
896
903
 
@@ -903,7 +910,7 @@ This one's zip code is 92064.`;
903
910
  ['number', 31],
904
911
  ['pickles', 100],
905
912
  ],
906
- }
913
+ },
907
914
  );
908
915
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
909
916
 
@@ -916,7 +923,7 @@ This one's zip code is 92064.`;
916
923
  ['number', 29],
917
924
  ['pickles', 100],
918
925
  ],
919
- }
926
+ },
920
927
  );
921
928
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
922
929
 
@@ -929,7 +936,7 @@ This one's zip code is 92064.`;
929
936
  ['numberString', 30],
930
937
  ['pickles', 100],
931
938
  ],
932
- }
939
+ },
933
940
  );
934
941
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
935
942
 
@@ -942,7 +949,7 @@ This one's zip code is 92064.`;
942
949
  ['numberString', 31],
943
950
  ['pickles', 100],
944
951
  ],
945
- }
952
+ },
946
953
  );
947
954
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
948
955
 
@@ -955,7 +962,7 @@ This one's zip code is 92064.`;
955
962
  ['numberString', 29],
956
963
  ['pickles', 100],
957
964
  ],
958
- }
965
+ },
959
966
  );
960
967
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
961
968
  });
@@ -972,7 +979,7 @@ This one's zip code is 92064.`;
972
979
  ['number', 30],
973
980
  ['pickles', 100],
974
981
  ],
975
- }
982
+ },
976
983
  );
977
984
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
978
985
 
@@ -985,7 +992,7 @@ This one's zip code is 92064.`;
985
992
  ['number', 31],
986
993
  ['pickles', 100],
987
994
  ],
988
- }
995
+ },
989
996
  );
990
997
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
991
998
 
@@ -998,7 +1005,7 @@ This one's zip code is 92064.`;
998
1005
  ['number', 29],
999
1006
  ['pickles', 100],
1000
1007
  ],
1001
- }
1008
+ },
1002
1009
  );
1003
1010
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
1004
1011
 
@@ -1011,7 +1018,7 @@ This one's zip code is 92064.`;
1011
1018
  ['numberString', 30],
1012
1019
  ['pickles', 100],
1013
1020
  ],
1014
- }
1021
+ },
1015
1022
  );
1016
1023
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
1017
1024
 
@@ -1024,7 +1031,7 @@ This one's zip code is 92064.`;
1024
1031
  ['numberString', 31],
1025
1032
  ['pickles', 100],
1026
1033
  ],
1027
- }
1034
+ },
1028
1035
  );
1029
1036
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
1030
1037
 
@@ -1037,7 +1044,7 @@ This one's zip code is 92064.`;
1037
1044
  ['numberString', 29],
1038
1045
  ['pickles', 100],
1039
1046
  ],
1040
- }
1047
+ },
1041
1048
  );
1042
1049
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
1043
1050
  });
@@ -1049,7 +1056,7 @@ This one's zip code is 92064.`;
1049
1056
  const resultEntity = await nymph.getEntities(
1050
1057
  { class: TestModel },
1051
1058
  { type: '&', tag: 'test' },
1052
- { type: '!&', gte: ['number', 60] }
1059
+ { type: '!&', gte: ['number', 60] },
1053
1060
  );
1054
1061
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
1055
1062
  });
@@ -1060,7 +1067,7 @@ This one's zip code is 92064.`;
1060
1067
  // Testing wrong inequality...
1061
1068
  const resultEntity = await nymph.getEntities(
1062
1069
  { class: TestModel },
1063
- { type: '&', lte: ['number', 29.99] }
1070
+ { type: '&', lte: ['number', 29.99] },
1064
1071
  );
1065
1072
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
1066
1073
  });
@@ -1071,7 +1078,7 @@ This one's zip code is 92064.`;
1071
1078
  // Retrieving entity by time...
1072
1079
  const resultEntity = await nymph.getEntities(
1073
1080
  { class: TestModel },
1074
- { type: '&', tag: 'test', gt: ['cdate', (testEntity.cdate ?? 0) - 120] }
1081
+ { type: '&', tag: 'test', gt: ['cdate', (testEntity.cdate ?? 0) - 120] },
1075
1082
  );
1076
1083
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
1077
1084
  });
@@ -1082,7 +1089,7 @@ This one's zip code is 92064.`;
1082
1089
  // Testing wrong time...
1083
1090
  const resultEntity = await nymph.getEntities(
1084
1091
  { class: TestModel },
1085
- { type: '&', tag: 'test', gte: ['cdate', (testEntity.cdate ?? 0) + 1] }
1092
+ { type: '&', tag: 'test', gte: ['cdate', (testEntity.cdate ?? 0) + 1] },
1086
1093
  );
1087
1094
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
1088
1095
  });
@@ -1095,7 +1102,7 @@ This one's zip code is 92064.`;
1095
1102
  // Retrieving entity by relative time...
1096
1103
  let resultEntity = await nymph.getEntities(
1097
1104
  { class: TestModel },
1098
- { type: '&', gt: ['timestamp', null, '-1 day'] }
1105
+ { type: '&', gt: ['timestamp', null, '-1 day'] },
1099
1106
  );
1100
1107
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
1101
1108
  expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
@@ -1109,7 +1116,7 @@ This one's zip code is 92064.`;
1109
1116
  ['timestamp', null, '-1 day'],
1110
1117
  ['timestamp', null, '+5 days'],
1111
1118
  ],
1112
- }
1119
+ },
1113
1120
  );
1114
1121
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
1115
1122
  expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
@@ -1117,7 +1124,7 @@ This one's zip code is 92064.`;
1117
1124
  // Retrieving entity by relative time...
1118
1125
  resultEntity = await nymph.getEntities(
1119
1126
  { class: TestModel },
1120
- { type: '&', gt: ['timestamp', null, '-3 days'] }
1127
+ { type: '&', gt: ['timestamp', null, '-3 days'] },
1121
1128
  );
1122
1129
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
1123
1130
  expect(referenceEntity.$inArray(resultEntity)).toEqual(true);
@@ -1125,7 +1132,7 @@ This one's zip code is 92064.`;
1125
1132
  // Retrieving entity by relative time...
1126
1133
  resultEntity = await nymph.getEntities(
1127
1134
  { class: TestModel },
1128
- { type: '&', gt: ['cdate', null, '-1 day'] }
1135
+ { type: '&', gt: ['cdate', null, '-1 day'] },
1129
1136
  );
1130
1137
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
1131
1138
  expect(referenceEntity.$inArray(resultEntity)).toEqual(true);
@@ -1139,7 +1146,7 @@ This one's zip code is 92064.`;
1139
1146
  // Retrieving entity by relative time...
1140
1147
  let resultEntity = await nymph.getEntities(
1141
1148
  { class: TestModel },
1142
- { type: '&', tag: 'test', gt: ['timestamp', null, '+1 day'] }
1149
+ { type: '&', tag: 'test', gt: ['timestamp', null, '+1 day'] },
1143
1150
  );
1144
1151
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
1145
1152
  expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
@@ -1147,7 +1154,7 @@ This one's zip code is 92064.`;
1147
1154
  // Retrieving entity by relative time...
1148
1155
  resultEntity = await nymph.getEntities(
1149
1156
  { class: TestModel },
1150
- { type: '&', tag: 'test', lt: ['timestamp', null, '-3 days'] }
1157
+ { type: '&', tag: 'test', lt: ['timestamp', null, '-3 days'] },
1151
1158
  );
1152
1159
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
1153
1160
  expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
@@ -1155,7 +1162,7 @@ This one's zip code is 92064.`;
1155
1162
  // Retrieving entity by relative time...
1156
1163
  resultEntity = await nymph.getEntities(
1157
1164
  { class: TestModel },
1158
- { type: '&', tag: 'test', gt: ['cdate', null, '+1 day'] }
1165
+ { type: '&', tag: 'test', gt: ['cdate', null, '+1 day'] },
1159
1166
  );
1160
1167
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
1161
1168
  expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
@@ -1165,9 +1172,11 @@ This one's zip code is 92064.`;
1165
1172
  await createTestEntities();
1166
1173
 
1167
1174
  // Testing referenced entities...
1175
+ await testEntity.reference?.$wake();
1168
1176
  expect(testEntity.reference?.test).toEqual('good');
1169
1177
 
1170
1178
  // Testing referenced entity arrays...
1179
+ await Promise.all(testEntity.refArray?.map((e) => e.$wake()) || []);
1171
1180
  expect(testEntity.refArray?.[0].test).toEqual('good');
1172
1181
  });
1173
1182
 
@@ -1177,7 +1186,7 @@ This one's zip code is 92064.`;
1177
1186
  // Retrieving entity by reference...
1178
1187
  const resultEntity = await nymph.getEntities(
1179
1188
  { class: TestModel },
1180
- { type: '&', ref: ['reference', refGuid] }
1189
+ { type: '&', ref: ['reference', refGuid] },
1181
1190
  );
1182
1191
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
1183
1192
  });
@@ -1189,7 +1198,7 @@ This one's zip code is 92064.`;
1189
1198
  const resultEntity = await nymph.getEntities(
1190
1199
  { class: TestModel },
1191
1200
  { type: '&', tag: 'test' },
1192
- { type: '!&', ref: ['reference', guid()] }
1201
+ { type: '!&', ref: ['reference', guid()] },
1193
1202
  );
1194
1203
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
1195
1204
  });
@@ -1200,7 +1209,7 @@ This one's zip code is 92064.`;
1200
1209
  // Testing wrong reference...
1201
1210
  const resultEntity = await nymph.getEntities(
1202
1211
  { class: TestModel },
1203
- { type: '&', ref: ['reference', guid()] }
1212
+ { type: '&', ref: ['reference', guid()] },
1204
1213
  );
1205
1214
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
1206
1215
  });
@@ -1211,7 +1220,7 @@ This one's zip code is 92064.`;
1211
1220
  // Testing non-existent reference...
1212
1221
  const resultEntity = await nymph.getEntities(
1213
1222
  { class: TestModel },
1214
- { type: '&', ref: ['pickle', refGuid] }
1223
+ { type: '&', ref: ['pickle', refGuid] },
1215
1224
  );
1216
1225
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
1217
1226
  });
@@ -1228,7 +1237,7 @@ This one's zip code is 92064.`;
1228
1237
  ['reference', refGuid],
1229
1238
  ['reference', guid()],
1230
1239
  ],
1231
- }
1240
+ },
1232
1241
  );
1233
1242
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
1234
1243
  });
@@ -1245,7 +1254,7 @@ This one's zip code is 92064.`;
1245
1254
  ['reference', guid()],
1246
1255
  ['reference', guid()],
1247
1256
  ],
1248
- }
1257
+ },
1249
1258
  );
1250
1259
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
1251
1260
  });
@@ -1256,7 +1265,7 @@ This one's zip code is 92064.`;
1256
1265
  // Retrieving entity by array reference...
1257
1266
  const resultEntity = await nymph.getEntities(
1258
1267
  { class: TestModel },
1259
- { type: '&', ref: ['refArray', refGuid] }
1268
+ { type: '&', ref: ['refArray', refGuid] },
1260
1269
  );
1261
1270
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
1262
1271
  });
@@ -1273,7 +1282,7 @@ This one's zip code is 92064.`;
1273
1282
  ['refArray', refGuid],
1274
1283
  ['refArray', guid()],
1275
1284
  ],
1276
- }
1285
+ },
1277
1286
  );
1278
1287
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
1279
1288
  });
@@ -1318,7 +1327,7 @@ This one's zip code is 92064.`;
1318
1327
  ['array', 'values'],
1319
1328
  ['array', 500],
1320
1329
  ],
1321
- }
1330
+ },
1322
1331
  );
1323
1332
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
1324
1333
  });
@@ -1338,13 +1347,13 @@ This one's zip code is 92064.`;
1338
1347
 
1339
1348
  const resultSelectors = await nymph.getEntities(
1340
1349
  { class: TestModel },
1341
- { type: '&', ref: ['reference', refGuid] }
1350
+ { type: '&', ref: ['reference', refGuid] },
1342
1351
  );
1343
1352
 
1344
1353
  // Testing count return with selectors...
1345
1354
  const resultSelectorsCount = await nymph.getEntities(
1346
1355
  { class: TestModel, return: 'count' },
1347
- { type: '&', ref: ['reference', refGuid] }
1356
+ { type: '&', ref: ['reference', refGuid] },
1348
1357
  );
1349
1358
  expect(resultSelectorsCount).toBeGreaterThanOrEqual(1);
1350
1359
  expect(resultSelectorsCount).toEqual(resultSelectors.length);
@@ -1367,7 +1376,7 @@ This one's zip code is 92064.`;
1367
1376
  // Testing empty count...
1368
1377
  const resultSelectorsEmpty = await nymph.getEntities(
1369
1378
  { class: TestModel, return: 'count' },
1370
- { type: '&', ref: ['reference', guid()] }
1379
+ { type: '&', ref: ['reference', guid()] },
1371
1380
  );
1372
1381
  expect(resultSelectorsEmpty).toEqual(0);
1373
1382
  });
@@ -1412,7 +1421,7 @@ This one's zip code is 92064.`;
1412
1421
  ['array', 'values'],
1413
1422
  ['array', 500],
1414
1423
  ],
1415
- }
1424
+ },
1416
1425
  );
1417
1426
  expect(resultGuid.indexOf(testEntity.guid ?? '')).toBeGreaterThan(-1);
1418
1427
  });
@@ -1462,7 +1471,7 @@ This one's zip code is 92064.`;
1462
1471
  ],
1463
1472
  },
1464
1473
  ],
1465
- }
1474
+ },
1466
1475
  );
1467
1476
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
1468
1477
 
@@ -1507,7 +1516,7 @@ This one's zip code is 92064.`;
1507
1516
  ],
1508
1517
  },
1509
1518
  ],
1510
- }
1519
+ },
1511
1520
  );
1512
1521
  expect(testEntity.$inArray(resultEntity2)).toEqual(true);
1513
1522
 
@@ -1523,7 +1532,7 @@ This one's zip code is 92064.`;
1523
1532
  },
1524
1533
  { type: '&', gte: ['number', 16000] },
1525
1534
  ],
1526
- }
1535
+ },
1527
1536
  );
1528
1537
  expect(testEntity.$inArray(resultEntity3)).toEqual(true);
1529
1538
 
@@ -1545,7 +1554,7 @@ This one's zip code is 92064.`;
1545
1554
  },
1546
1555
  },
1547
1556
  ],
1548
- }
1557
+ },
1549
1558
  );
1550
1559
  expect(testEntity.$inArray(resultEntity4)).toEqual(true);
1551
1560
  });
@@ -1564,7 +1573,7 @@ This one's zip code is 92064.`;
1564
1573
  },
1565
1574
  { type: '&', gte: ['number', 16000] },
1566
1575
  ],
1567
- }
1576
+ },
1568
1577
  );
1569
1578
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
1570
1579
  });
@@ -1581,7 +1590,7 @@ This one's zip code is 92064.`;
1581
1590
  'reference',
1582
1591
  [{ class: TestModel }, { type: '&', equal: ['test', 'good'] }],
1583
1592
  ],
1584
- }
1593
+ },
1585
1594
  );
1586
1595
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
1587
1596
  });
@@ -1598,7 +1607,7 @@ This one's zip code is 92064.`;
1598
1607
  'reference',
1599
1608
  [{ class: TestModel }, { type: '&', equal: ['test', 'pickles'] }],
1600
1609
  ],
1601
- }
1610
+ },
1602
1611
  );
1603
1612
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
1604
1613
  });
@@ -1615,7 +1624,7 @@ This one's zip code is 92064.`;
1615
1624
  'reference',
1616
1625
  [{ class: TestBModel }, { type: '&', equal: ['test', 'good'] }],
1617
1626
  ],
1618
- }
1627
+ },
1619
1628
  );
1620
1629
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
1621
1630
  });
@@ -1632,31 +1641,28 @@ This one's zip code is 92064.`;
1632
1641
  'reference',
1633
1642
  [{ class: TestModel }, { type: '&', equal: ['test', 'pickles'] }],
1634
1643
  ],
1635
- }
1644
+ },
1636
1645
  );
1637
1646
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
1638
1647
  });
1639
1648
 
1640
- it('sort option', async () => {
1649
+ it('cdate and mdate sort option', async () => {
1641
1650
  await createMultipleTestEntities();
1642
1651
 
1643
- for (const sort of ['cdate', 'mdate']) {
1652
+ for (const sort of ['cdate', 'mdate'] as ('cdate' | 'mdate')[]) {
1644
1653
  // Retrieving entities sorted...
1645
- let resultEntities = await nymph.getEntities({
1646
- class: TestModel,
1647
- sort: sort as 'cdate' | 'mdate',
1648
- });
1654
+ let resultEntities = await nymph.getEntities({ class: TestModel, sort });
1649
1655
  expect(resultEntities.length).toBeGreaterThan(100);
1650
1656
  for (let i = 0; i < resultEntities.length - 1; i++) {
1651
- expect(
1652
- resultEntities[i + 1][sort as 'cdate' | 'mdate']
1653
- ).toBeGreaterThan(resultEntities[i][sort as 'cdate' | 'mdate'] ?? 0);
1657
+ expect(resultEntities[i + 1][sort]).toBeGreaterThan(
1658
+ resultEntities[i][sort] ?? 0,
1659
+ );
1654
1660
  }
1655
1661
 
1656
1662
  // And test the same with guid return...
1657
1663
  let resultGuids = await nymph.getEntities({
1658
1664
  class: TestModel,
1659
- sort: sort as 'cdate' | 'mdate',
1665
+ sort,
1660
1666
  return: 'guid',
1661
1667
  });
1662
1668
  expect(resultGuids.length).toBeGreaterThan(100);
@@ -1667,48 +1673,121 @@ This one's zip code is 92064.`;
1667
1673
  // Retrieving entities reverse sorted...
1668
1674
  resultEntities = await nymph.getEntities({
1669
1675
  class: TestModel,
1670
- sort: sort as 'cdate' | 'mdate',
1676
+ sort,
1671
1677
  reverse: true,
1672
1678
  });
1673
1679
  expect(resultEntities.length).toBeGreaterThan(100);
1674
1680
  for (let i = 0; i < resultEntities.length - 1; i++) {
1675
- expect(resultEntities[i + 1][sort as 'cdate' | 'mdate']).toBeLessThan(
1676
- resultEntities[i][sort as 'cdate' | 'mdate'] ?? 0
1681
+ expect(resultEntities[i + 1][sort]).toBeLessThan(
1682
+ resultEntities[i][sort] ?? 0,
1677
1683
  );
1678
1684
  }
1679
1685
 
1680
1686
  // And again with other selectors.
1681
1687
  // Retrieving entities sorted...
1682
1688
  resultEntities = await nymph.getEntities(
1683
- { class: TestModel, sort: sort as 'cdate' | 'mdate' },
1684
- { type: '&', match: ['name', '^Multi Test '] }
1689
+ { class: TestModel, sort },
1690
+ { type: '&', match: ['name', '^Multi Test '] },
1685
1691
  );
1686
1692
  expect(resultEntities.length).toEqual(100);
1687
1693
  for (let i = 0; i < resultEntities.length - 1; i++) {
1688
- expect(
1689
- resultEntities[i + 1][sort as 'cdate' | 'mdate']
1690
- ).toBeGreaterThan(resultEntities[i][sort as 'cdate' | 'mdate'] ?? 0);
1694
+ expect(resultEntities[i + 1][sort]).toBeGreaterThan(
1695
+ resultEntities[i][sort] ?? 0,
1696
+ );
1691
1697
  }
1692
1698
 
1693
1699
  // Retrieving entities reverse sorted...
1694
1700
  resultEntities = await nymph.getEntities(
1695
- { class: TestModel, sort: sort as 'cdate' | 'mdate', reverse: true },
1696
- { type: '&', match: ['name', '^Multi Test '] }
1701
+ { class: TestModel, sort, reverse: true },
1702
+ { type: '&', match: ['name', '^Multi Test '] },
1697
1703
  );
1698
1704
  expect(resultEntities.length).toEqual(100);
1699
1705
  for (let i = 0; i < resultEntities.length - 1; i++) {
1700
- expect(resultEntities[i + 1][sort as 'cdate' | 'mdate']).toBeLessThan(
1701
- resultEntities[i][sort as 'cdate' | 'mdate'] ?? 0
1706
+ expect(resultEntities[i + 1][sort]).toBeLessThan(
1707
+ resultEntities[i][sort] ?? 0,
1702
1708
  );
1703
1709
  }
1704
1710
  }
1705
1711
  });
1706
1712
 
1713
+ it('property sort option', async () => {
1714
+ await createMultipleTestEntities();
1715
+
1716
+ // Retrieving entities sorted...
1717
+ let resultEntities = await nymph.getEntities({
1718
+ class: TestModel,
1719
+ sort: 'number',
1720
+ });
1721
+ expect(resultEntities.length).toBeGreaterThan(100);
1722
+ for (let i = 0; i < resultEntities.length - 1; i++) {
1723
+ expect(resultEntities[i + 1].number ?? Infinity).toBeGreaterThanOrEqual(
1724
+ resultEntities[i].number ?? 0,
1725
+ );
1726
+ }
1727
+
1728
+ // And test the same with guid return...
1729
+ let resultGuids = await nymph.getEntities({
1730
+ class: TestModel,
1731
+ sort: 'number',
1732
+ return: 'guid',
1733
+ });
1734
+ expect(resultGuids.length).toBeGreaterThan(100);
1735
+ for (let i = 0; i < resultGuids.length - 1; i++) {
1736
+ expect(resultGuids[i]).toEqual(resultEntities[i].guid);
1737
+ }
1738
+
1739
+ // Retrieving entities reverse sorted...
1740
+ resultEntities = await nymph.getEntities({
1741
+ class: TestModel,
1742
+ sort: 'number',
1743
+ reverse: true,
1744
+ });
1745
+ expect(resultEntities.length).toBeGreaterThan(100);
1746
+ for (let i = 0; i < resultEntities.length - 1; i++) {
1747
+ expect(resultEntities[i + 1].number ?? 0).toBeLessThanOrEqual(
1748
+ resultEntities[i].number ?? Infinity,
1749
+ );
1750
+ }
1751
+
1752
+ // And again with other selectors.
1753
+ // Retrieving entities sorted...
1754
+ resultEntities = await nymph.getEntities(
1755
+ { class: TestModel, sort: 'number' },
1756
+ { type: '&', match: ['name', '^Multi Test '] },
1757
+ );
1758
+ expect(resultEntities.length).toEqual(100);
1759
+ for (let i = 0; i < resultEntities.length - 1; i++) {
1760
+ expect(resultEntities[i + 1].number ?? Infinity).toBeGreaterThan(
1761
+ resultEntities[i].number ?? 0,
1762
+ );
1763
+ expect(resultEntities[i].name).toEqual(
1764
+ `Multi Test ${100 - (resultEntities[i].number ?? 0)}`,
1765
+ );
1766
+ }
1767
+
1768
+ // Retrieving entities reverse sorted...
1769
+ resultEntities = await nymph.getEntities(
1770
+ { class: TestModel, sort: 'number', reverse: true },
1771
+ { type: '&', match: ['name', '^Multi Test '] },
1772
+ );
1773
+ expect(resultEntities.length).toEqual(100);
1774
+ for (let i = 0; i < resultEntities.length - 1; i++) {
1775
+ expect(resultEntities[i + 1].number ?? 0).toBeLessThan(
1776
+ resultEntities[i].number ?? Infinity,
1777
+ );
1778
+ expect(resultEntities[i].name).toEqual(
1779
+ `Multi Test ${100 - (resultEntities[i].number ?? 0)}`,
1780
+ );
1781
+ }
1782
+ });
1783
+
1707
1784
  it('delete reference', async () => {
1708
1785
  await createTestEntities();
1709
1786
 
1710
1787
  // Deleting referenced entities...
1788
+ await testEntity.reference?.$wake();
1711
1789
  expect(await testEntity.reference?.$delete()).toEqual(true);
1790
+ await Promise.all(testEntity.refArray?.map((e) => e.$wake()) || []);
1712
1791
  expect(testEntity.reference?.guid).toBeNull();
1713
1792
  });
1714
1793
 
@@ -1721,16 +1800,116 @@ This one's zip code is 92064.`;
1721
1800
 
1722
1801
  const entity = await nymph.getEntity(
1723
1802
  { class: TestModel },
1724
- { type: '&', guid: testGuid }
1803
+ { type: '&', guid: testGuid },
1725
1804
  );
1726
1805
 
1727
1806
  expect(entity).toBeNull();
1728
1807
  });
1808
+
1809
+ it('allows non-duplicate unique strings', async () => {
1810
+ // Creating entity...
1811
+ const uniqueEntityA = await TestModel.factory();
1812
+ uniqueEntityA.name = 'Entity Test ' + new Date().toLocaleString();
1813
+ uniqueEntityA.uniques = ['test a'];
1814
+
1815
+ // Saving entity...
1816
+ expect(await uniqueEntityA.$save()).toEqual(true);
1817
+ expect(uniqueEntityA.guid).not.toBeNull();
1818
+
1819
+ // Creating entity...
1820
+ const uniqueEntityB = await TestModel.factory();
1821
+ uniqueEntityB.name = 'Entity Test ' + new Date().toLocaleString();
1822
+ uniqueEntityB.uniques = ['test b'];
1823
+
1824
+ // Saving entity...
1825
+ expect(await uniqueEntityB.$save()).toEqual(true);
1826
+ expect(uniqueEntityB.guid).not.toBeNull();
1827
+
1828
+ expect(uniqueEntityA.guid).not.toEqual(uniqueEntityB.guid);
1829
+
1830
+ expect(await uniqueEntityA.$delete()).toEqual(true);
1831
+ expect(await uniqueEntityB.$delete()).toEqual(true);
1832
+ });
1833
+
1834
+ it('throws on duplicate unique strings', async () => {
1835
+ // Creating entity...
1836
+ const uniqueEntityA = await TestModel.factory();
1837
+ uniqueEntityA.name = 'Entity Test ' + new Date().toLocaleString();
1838
+ uniqueEntityA.uniques = ['test a'];
1839
+
1840
+ // Saving entity...
1841
+ expect(await uniqueEntityA.$save()).toEqual(true);
1842
+ expect(uniqueEntityA.guid).not.toBeNull();
1843
+
1844
+ // Creating entity...
1845
+ const uniqueEntityB = await TestModel.factory();
1846
+ uniqueEntityB.name = 'Entity Test ' + new Date().toLocaleString();
1847
+ uniqueEntityB.uniques = ['test a'];
1848
+
1849
+ // Saving entity...
1850
+ try {
1851
+ await uniqueEntityB.$save();
1852
+
1853
+ throw Error("Shouldn't get past the uniqueness check.");
1854
+ } catch (e: any) {
1855
+ expect(e).toBeInstanceOf(EntityUniqueConstraintError);
1856
+ }
1857
+ expect(uniqueEntityB.guid).toBeNull();
1858
+
1859
+ expect(await uniqueEntityA.$delete()).toEqual(true);
1860
+ });
1861
+
1862
+ it('allows duplicate unique string if first transaction is rolled back', async () => {
1863
+ // Creating transaction entity...
1864
+ const tnymphA = await nymph.startTransaction('test-unique-a');
1865
+ const TestModelA = tnymphA.getEntityClass(TestModel);
1866
+ const uniqueEntityA = await TestModelA.factory();
1867
+ uniqueEntityA.name = 'Entity Test ' + new Date().toLocaleString();
1868
+ uniqueEntityA.uniques = ['test a'];
1869
+
1870
+ // Saving entity...
1871
+ expect(await uniqueEntityA.$save()).toEqual(true);
1872
+ expect(uniqueEntityA.guid).not.toBeNull();
1873
+
1874
+ // Rolling back transaction...
1875
+ expect(await tnymphA.rollback('test-unique-a')).toEqual(true);
1876
+
1877
+ // Creating transaction entity...
1878
+ const tnymphB = await nymph.startTransaction('test-unique-b');
1879
+ const TestModelB = tnymphB.getEntityClass(TestModel);
1880
+ const uniqueEntityB = await TestModelB.factory();
1881
+ uniqueEntityB.name = 'Entity Test ' + new Date().toLocaleString();
1882
+ uniqueEntityB.uniques = ['test a'];
1883
+
1884
+ // Saving entity...
1885
+ expect(await uniqueEntityB.$save()).toEqual(true);
1886
+ expect(uniqueEntityB.guid).not.toBeNull();
1887
+
1888
+ expect(uniqueEntityA.guid).not.toEqual(uniqueEntityB.guid);
1889
+
1890
+ expect(await tnymphB.commit('test-unique-b')).toEqual(true);
1891
+
1892
+ const uniqueEntityACheck = await nymph.getEntity(
1893
+ { class: TestModel },
1894
+ { type: '&', guid: uniqueEntityA.guid ?? '' },
1895
+ );
1896
+ expect(uniqueEntityACheck).toBeNull();
1897
+
1898
+ const uniqueEntityBCheck = await nymph.getEntity(
1899
+ { class: TestModel },
1900
+ { type: '&', guid: uniqueEntityB.guid ?? '' },
1901
+ );
1902
+ expect(uniqueEntityBCheck).not.toBeNull();
1903
+
1904
+ if (uniqueEntityBCheck != null) {
1905
+ expect(await uniqueEntityBCheck.$delete()).toEqual(true);
1906
+ }
1907
+ });
1729
1908
  }
1730
1909
 
1731
1910
  export function UIDTest(
1732
1911
  nymph: Nymph,
1733
- it: (name: string, fn: () => void) => void
1912
+ it: (name: string, fn: () => void) => void,
1734
1913
  ) {
1735
1914
  it('delete old test data', async () => {
1736
1915
  expect(await nymph.deleteUID('TestUID')).toEqual(true);
@@ -1771,7 +1950,7 @@ export function UIDTest(
1771
1950
 
1772
1951
  export function ExportImportTest(
1773
1952
  nymph: Nymph,
1774
- it: (name: string, fn: () => void) => void
1953
+ it: (name: string, fn: () => void) => void,
1775
1954
  ) {
1776
1955
  const TestModel = nymph.addEntityClass(TestModelClass);
1777
1956
  const TestBModel = nymph.addEntityClass(TestBModelClass);
@@ -1818,9 +1997,11 @@ export function ExportImportTest(
1818
1997
  expect(model.number).toEqual(30);
1819
1998
  expect(model.timestamp).toBeGreaterThanOrEqual(strtotime('-2 minutes'));
1820
1999
 
2000
+ await model.reference?.$wake();
1821
2001
  expect(model.reference?.guid).not.toBeNull();
1822
2002
  expect(model.reference?.string).toEqual('another');
1823
2003
  expect(model.reference?.index?.match(/^\d+b$/)).toBeTruthy();
2004
+ await Promise.all(model.refArray?.map((e) => e.$wake()) || []);
1824
2005
  expect(model.refArray?.[0].guid).not.toBeNull();
1825
2006
  expect(model.refArray?.[0].guid).toEqual(model.reference?.guid);
1826
2007
  }
@@ -1867,7 +2048,7 @@ export function ExportImportTest(
1867
2048
 
1868
2049
  it('export data', async () => {
1869
2050
  expect(await nymph.export(__dirname + '/testentityexport.nex')).toEqual(
1870
- true
2051
+ true,
1871
2052
  );
1872
2053
  });
1873
2054
 
@@ -1884,7 +2065,7 @@ export function ExportImportTest(
1884
2065
  expect(bmodels.length).toEqual(0);
1885
2066
 
1886
2067
  expect(await nymph.import(__dirname + '/testentityexport.nex')).toEqual(
1887
- true
2068
+ true,
1888
2069
  );
1889
2070
 
1890
2071
  await checkEntityDataAndCount();