@nymphjs/nymph 1.0.0-beta.7 → 1.0.0-beta.71

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 (65) hide show
  1. package/CHANGELOG.md +324 -0
  2. package/README.md +13 -21
  3. package/dist/Entity.d.ts +269 -7
  4. package/dist/Entity.js +491 -105
  5. package/dist/Entity.js.map +1 -1
  6. package/dist/Entity.test.js +39 -17
  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 +685 -176
  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 +129 -38
  19. package/dist/driver/NymphDriver.js +264 -131
  20. package/dist/driver/NymphDriver.js.map +1 -1
  21. package/dist/driver/testArtifacts.d.ts +1 -1
  22. package/dist/driver/testArtifacts.js +336 -42
  23. package/dist/driver/testArtifacts.js.map +1 -1
  24. package/dist/errors/EntityInvalidDataError.d.ts +6 -0
  25. package/dist/errors/EntityInvalidDataError.js +7 -1
  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 +1 -0
  34. package/dist/errors/QueryFailedError.js.map +1 -1
  35. package/dist/errors/index.d.ts +2 -0
  36. package/dist/errors/index.js +2 -0
  37. package/dist/errors/index.js.map +1 -1
  38. package/dist/testArtifacts.d.ts +17 -5
  39. package/dist/testArtifacts.js +31 -27
  40. package/dist/testArtifacts.js.map +1 -1
  41. package/dist/testMocks.d.ts +15 -10
  42. package/dist/testMocks.js +37 -13
  43. package/dist/testMocks.js.map +1 -1
  44. package/dist/utils.d.ts +1 -1
  45. package/dist/utils.js +21 -5
  46. package/dist/utils.js.map +1 -1
  47. package/package.json +16 -14
  48. package/src/Entity.test.ts +32 -11
  49. package/src/Entity.ts +423 -134
  50. package/src/Entity.types.ts +32 -66
  51. package/src/Nymph.ts +618 -195
  52. package/src/Nymph.types.ts +97 -26
  53. package/src/conf/d.ts +8 -0
  54. package/src/conf/defaults.ts +24 -0
  55. package/src/driver/NymphDriver.ts +281 -311
  56. package/src/driver/testArtifacts.ts +384 -173
  57. package/src/errors/EntityUniqueConstraintError.ts +6 -0
  58. package/src/errors/InvalidStateError.ts +6 -0
  59. package/src/errors/index.ts +4 -0
  60. package/src/nymphJoiProps.ts +2 -2
  61. package/src/testArtifacts.ts +18 -19
  62. package/src/testMocks.ts +64 -32
  63. package/src/utils.ts +22 -8
  64. package/tsconfig.json +3 -3
  65. package/typedoc.json +4 -0
@@ -3,23 +3,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ExportImportTest = exports.UIDTest = exports.QueriesTest = void 0;
6
+ exports.ExportImportTest = exports.UIDTest = exports.EntitiesTest = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const strtotime_1 = __importDefault(require("locutus/php/datetime/strtotime"));
9
9
  const guid_1 = require("@nymphjs/guid");
10
+ const errors_1 = require("../errors");
10
11
  const testArtifacts_1 = require("../testArtifacts");
11
- function QueriesTest(nymph, it) {
12
+ function EntitiesTest(nymph, it) {
12
13
  const TestModel = nymph.addEntityClass(testArtifacts_1.TestModel);
13
14
  const TestBModel = nymph.addEntityClass(testArtifacts_1.TestBModel);
15
+ const TestEmptyModel = nymph.addEntityClass(testArtifacts_1.TestEmptyModel);
14
16
  let testEntity;
15
17
  let testGuid;
16
18
  let refGuid;
17
19
  let createdMultiple = false;
20
+ // The entities created by this function are required by many of the tests.
18
21
  async function createTestEntities() {
19
22
  if (testGuid != null) {
20
23
  return;
21
24
  }
25
+ // Creating entity...
22
26
  testEntity = await TestModel.factory();
27
+ // Saving entity...
23
28
  testEntity.name = 'Entity Test ' + new Date().toLocaleString();
24
29
  testEntity.null = null;
25
30
  testEntity.string = 'test';
@@ -28,7 +33,10 @@ function QueriesTest(nymph, it) {
28
33
 
29
34
  This one's email address is nice_hat-wednesday+newyork@im-a-hat.hat.
30
35
  This one's phone number is (555) 555-1818.
31
- This one's zip code is 92064.`;
36
+ This one's zip code is 92064.
37
+ This one's favorite emojis are 🔥❤️😊😂⭐🤔
38
+
39
+ These hats are absolutely fantastic.`;
32
40
  testEntity.number = 30;
33
41
  testEntity.numberString = '30';
34
42
  testEntity.timestamp = Date.now();
@@ -45,38 +53,53 @@ This one's zip code is 92064.`;
45
53
  expect(await testEntity.$save()).toEqual(true);
46
54
  entityReferenceTest.test = 'good';
47
55
  expect(await entityReferenceTest.$save()).toEqual(true);
48
- testEntity = nymph.driver.getEntitySync({ class: TestModel }, testGuid);
49
- expect(testEntity).toBeInstanceOf(TestModel);
50
- expect(testEntity.guid).toEqual(testGuid);
56
+ // Test asynchronous getEntity.
51
57
  testEntity = (await nymph.getEntity({ class: TestModel }, testGuid));
52
58
  expect(testEntity).toBeInstanceOf(TestModel);
53
59
  expect(testEntity.guid).toEqual(testGuid);
54
60
  }
61
+ // The entities created by this function are required by many of the tests.
55
62
  async function createMultipleTestEntities() {
56
63
  if (!createdMultiple) {
57
64
  createdMultiple = true;
65
+ // Creating 100 entities...
58
66
  for (let i = 0; i < 100; i++) {
59
67
  const testEntity = await TestModel.factory();
60
68
  testEntity.name = `Multi Test ${i}`;
69
+ // Reverse the number for sort testing.
70
+ testEntity.number = 100 - i;
61
71
  testEntity.$removeTag('test');
62
72
  testEntity.$addTag('multiTest');
63
73
  expect(await testEntity.$save()).toEqual(true);
74
+ // Pause for a few milliseconds so the cdate and mdate can be sorted.
64
75
  await new Promise((res) => setTimeout(() => res(1), 5));
65
76
  }
66
77
  }
67
78
  }
68
79
  it('delete old test data', async () => {
69
- let all = await nymph.getEntities({ class: TestModel });
70
- expect(Array.isArray(all)).toEqual(true);
71
- for (const cur of all) {
80
+ let amodels = await nymph.getEntities({ class: TestModel });
81
+ expect(Array.isArray(amodels)).toEqual(true);
82
+ for (const cur of amodels) {
72
83
  expect(await cur.$delete()).toEqual(true);
73
84
  }
74
- all = await nymph.getEntities({ class: TestModel });
75
- expect(all.length).toEqual(0);
85
+ amodels = await nymph.getEntities({ class: TestModel });
86
+ expect(amodels.length).toEqual(0);
87
+ let bmodels = await nymph.getEntities({ class: TestBModel });
88
+ expect(Array.isArray(bmodels)).toEqual(true);
89
+ for (const cur of bmodels) {
90
+ expect(await cur.$delete()).toEqual(true);
91
+ }
92
+ bmodels = await nymph.getEntities({ class: TestBModel });
93
+ expect(bmodels.length).toEqual(0);
76
94
  });
77
95
  it('create entity', async () => {
78
96
  await createTestEntities();
79
97
  });
98
+ it("doesn't create empty entity", async () => {
99
+ const testEntity = await TestEmptyModel.factory();
100
+ expect(await testEntity.$save()).toBeFalsy();
101
+ expect(testEntity.guid).toBeNull();
102
+ });
80
103
  it('update mdate on save', async () => {
81
104
  await createTestEntities();
82
105
  const oldMdate = testEntity.mdate ?? Infinity;
@@ -89,15 +112,19 @@ This one's zip code is 92064.`;
89
112
  });
90
113
  it('by guid', async () => {
91
114
  await createTestEntities();
115
+ // Retrieving entity by GUID...
92
116
  let resultEntity = await nymph.getEntity({ class: TestModel }, testGuid);
93
117
  expect(testEntity.$is(resultEntity)).toEqual(true);
118
+ // Using class constructor...
94
119
  resultEntity = await TestModel.factory(testGuid);
95
120
  expect(testEntity.$is(resultEntity)).toEqual(true);
121
+ // Testing wrong GUID...
96
122
  resultEntity = await nymph.getEntity({ class: TestModel }, (0, guid_1.guid)());
97
123
  expect(testEntity.$is(resultEntity)).toEqual(false);
98
124
  });
99
125
  it('transactions', async () => {
100
126
  await createTestEntities();
127
+ // Verify not in a transaction.
101
128
  expect(await nymph.inTransaction()).toEqual(false);
102
129
  let transaction = await nymph.startTransaction('test');
103
130
  testEntity.$nymph = transaction;
@@ -106,37 +133,56 @@ This one's zip code is 92064.`;
106
133
  await transaction.rollback('test');
107
134
  return;
108
135
  }
136
+ // Change a value in the test entity.
109
137
  testEntity.string = 'bad value';
110
138
  expect(await testEntity.$save()).toEqual(true);
139
+ // Rollback the transaction.
111
140
  await transaction.rollback('test');
141
+ // Verify not in a transaction.
112
142
  expect(await transaction.inTransaction()).toEqual(false);
143
+ // Verify the value is correct.
113
144
  await testEntity.$refresh();
114
145
  expect(testEntity.string).toEqual('test');
146
+ // Start a new transaction.
115
147
  transaction = await nymph.startTransaction('test');
116
148
  testEntity.$nymph = transaction;
149
+ // Verify in a transaction.
117
150
  expect(await transaction.inTransaction()).toEqual(true);
151
+ // Delete the entity.
118
152
  expect(await testEntity.$delete()).toEqual(true);
119
153
  const resultEntity = await transaction.getEntity({ class: TestModel }, testGuid);
120
154
  expect(resultEntity).toBeNull();
155
+ // Rollback the transaction.
121
156
  await transaction.rollback('test');
157
+ // Verify not in a transaction.
122
158
  expect(await transaction.inTransaction()).toEqual(false);
159
+ // Verify it's back.
123
160
  testEntity = (await transaction.getEntity({ class: TestModel }, testGuid));
124
161
  expect(testEntity.guid).toEqual(testGuid);
125
- transaction = await nymph.startTransaction('test');
162
+ // Start a new transaction with a dot in the name.
163
+ transaction = await nymph.startTransaction('test.1');
126
164
  testEntity.$nymph = transaction;
165
+ // Verify in a transaction.
127
166
  expect(await transaction.inTransaction()).toEqual(true);
167
+ // Make a change.
128
168
  testEntity.string = 'fish';
129
169
  expect(await testEntity.$save()).toEqual(true);
130
- await transaction.commit('test');
170
+ // Commit the transaction.
171
+ await transaction.commit('test.1');
131
172
  testEntity.$nymph = nymph;
173
+ // Verify not in a transaction.
132
174
  expect(await transaction.inTransaction()).toEqual(false);
175
+ // Verify the value is correct.
133
176
  await testEntity.$refresh();
134
177
  expect(testEntity.string).toEqual('fish');
178
+ // Finally, change it back.
135
179
  testEntity.string = 'test';
136
180
  expect(await testEntity.$save()).toEqual(true);
181
+ // TODO: nested transactions
137
182
  });
138
183
  it('options', async () => {
139
184
  await createTestEntities();
185
+ // Testing entity order, offset, limit...
140
186
  const resultEntities = await nymph.getEntities({
141
187
  class: TestModel,
142
188
  reverse: true,
@@ -149,86 +195,103 @@ This one's zip code is 92064.`;
149
195
  });
150
196
  it('guid and tags', async () => {
151
197
  await createTestEntities();
198
+ // Retrieving entity by GUID and tags...
152
199
  const resultEntity = await nymph.getEntity({ class: TestModel }, { type: '&', guid: testGuid, tag: 'test' });
153
200
  expect(testEntity.$is(resultEntity)).toEqual(true);
154
201
  });
155
202
  it('or selector', async () => {
156
203
  await createTestEntities();
204
+ // Retrieving entity by GUID and tags...
157
205
  const resultEntity = await nymph.getEntity({ class: TestModel }, { type: '|', guid: [testGuid, (0, guid_1.guid)()] });
158
206
  expect(testEntity.$is(resultEntity)).toEqual(true);
159
207
  });
160
208
  it('wrong or selector', async () => {
161
209
  await createTestEntities();
210
+ // Retrieving entity by GUID and tags...
162
211
  const resultEntity = await nymph.getEntity({ class: TestModel }, { type: '|', guid: [(0, guid_1.guid)(), (0, guid_1.guid)()] });
163
212
  expect(testEntity.$is(resultEntity)).toEqual(false);
164
213
  });
165
214
  it('not guid', async () => {
166
215
  await createTestEntities();
216
+ // Retrieving entity by !GUID...
167
217
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', '!guid': (0, guid_1.guid)(), tag: 'test' });
168
218
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
169
219
  });
170
220
  it('not tags', async () => {
171
221
  await createTestEntities();
222
+ // Retrieving entity by !tags...
172
223
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', guid: testGuid, '!tag': ['barbecue', 'pickles'] });
173
224
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
174
225
  });
175
226
  it('guid and wrong tags', async () => {
176
227
  await createTestEntities();
228
+ // Testing GUID and wrong tags...
177
229
  const resultEntity = await nymph.getEntity({ class: TestModel }, { type: '&', guid: testGuid, tag: ['pickles'] });
178
230
  expect(resultEntity).toBeNull();
179
231
  });
180
232
  it('tags', async () => {
181
233
  await createTestEntities();
234
+ // Retrieving entity by tags...
182
235
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' });
183
236
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
184
237
  });
185
238
  it('wrong tags', async () => {
186
239
  await createTestEntities();
240
+ // Testing wrong tags...
187
241
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'pickles' });
188
242
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
189
243
  });
190
244
  it('inclusive tags', async () => {
191
245
  await createTestEntities();
246
+ // Retrieving entity by tags inclusively...
192
247
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '|', tag: ['pickles', 'test', 'barbecue'] });
193
248
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
194
249
  });
195
250
  it('wrong inclusive tags', async () => {
196
251
  await createTestEntities();
252
+ // Testing wrong inclusive tags...
197
253
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '|', tag: ['pickles', 'barbecue'] });
198
254
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
199
255
  });
200
256
  it('mixed tags', async () => {
201
257
  await createTestEntities();
258
+ // Retrieving entity by mixed tags...
202
259
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' }, { type: '|', tag: ['pickles', 'test', 'barbecue'] });
203
260
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
204
261
  });
205
262
  it('wrong inclusive mixed tags', async () => {
206
263
  await createTestEntities();
264
+ // Testing wrong inclusive mixed tags...
207
265
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' }, { type: '|', tag: ['pickles', 'barbecue'] });
208
266
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
209
267
  });
210
268
  it('wrong exclusive mixed tags', async () => {
211
269
  await createTestEntities();
270
+ // Testing wrong exclusive mixed tags...
212
271
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'pickles' }, { type: '|', tag: ['test', 'barbecue'] });
213
272
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
214
273
  });
215
274
  it('defined', async () => {
216
275
  await createTestEntities();
276
+ // Retrieving entity by defined...
217
277
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', defined: 'string' });
218
278
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
219
279
  });
220
280
  it('not defined', async () => {
221
281
  await createTestEntities();
282
+ // Retrieving entity by !defined...
222
283
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', '!defined': 'pickles' });
223
284
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
224
285
  });
225
286
  it('defined in a not and clause', async () => {
226
287
  await createTestEntities();
288
+ // Retrieving entity by defined in not and clause...
227
289
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '!&', defined: 'pickles' }, { type: '&', tag: 'test' });
228
290
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
229
291
  });
230
292
  it('equal', async () => {
231
293
  await createTestEntities();
294
+ // Retrieving entity by equal...
232
295
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', equal: ['string', 'test'] });
233
296
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
234
297
  });
@@ -236,12 +299,14 @@ This one's zip code is 92064.`;
236
299
  await createTestEntities();
237
300
  const referenceEntity = await TestModel.factory(refGuid);
238
301
  expect(referenceEntity.guid).toEqual(refGuid);
302
+ // Retrieving entity by !equal...
239
303
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', '!equal': ['string', 'wrong'] });
240
304
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
241
305
  expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
242
306
  });
243
307
  it('like', async () => {
244
308
  await createTestEntities();
309
+ // Retrieving entity by like...
245
310
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', like: ['string', 't_s%'] });
246
311
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
247
312
  });
@@ -249,12 +314,14 @@ This one's zip code is 92064.`;
249
314
  await createTestEntities();
250
315
  const referenceEntity = await TestModel.factory(refGuid);
251
316
  expect(referenceEntity.guid).toEqual(refGuid);
317
+ // Retrieving entity by !like...
252
318
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', '!like': ['string', 'wr_n%'] });
253
319
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
254
320
  expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
255
321
  });
256
322
  it('ilike', async () => {
257
323
  await createTestEntities();
324
+ // Retrieving entity by ilike...
258
325
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', ilike: ['string', 'T_s%'] });
259
326
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
260
327
  });
@@ -262,56 +329,68 @@ This one's zip code is 92064.`;
262
329
  await createTestEntities();
263
330
  const referenceEntity = await TestModel.factory(refGuid);
264
331
  expect(referenceEntity.guid).toEqual(refGuid);
332
+ // Retrieving entity by !ilike...
265
333
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', '!ilike': ['string', 'wr_n%'] });
266
334
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
267
335
  expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
268
336
  });
269
337
  it('like with wrong case', async () => {
270
338
  await createTestEntities();
339
+ // Retrieving entity by like...
271
340
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', like: ['string', 'T_s%'] });
272
341
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
273
342
  });
274
343
  it('tags and equal', async () => {
275
344
  await createTestEntities();
345
+ // Retrieving entity by tags and equal...
276
346
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', equal: ['string', 'test'] });
277
347
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
278
348
  });
279
349
  it('wrong tags right equal', async () => {
280
350
  await createTestEntities();
351
+ // Testing wrong tags and right equal...
281
352
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'pickles', equal: ['string', 'test'] });
282
353
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
283
354
  });
284
355
  it('right tags wrong equal', async () => {
285
356
  await createTestEntities();
357
+ // Testing right tags and wrong equal...
286
358
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', equal: ['string', 'pickles'] });
287
359
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
288
360
  });
289
361
  it('wrong tags wrong equal', async () => {
290
362
  await createTestEntities();
363
+ // Testing wrong tags and wrong equal...
291
364
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'pickles', equal: ['string', 'pickles'] });
292
365
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
293
366
  });
294
367
  it('contain', async () => {
295
368
  await createTestEntities();
369
+ // Retrieving entity by contain...
296
370
  let resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', contain: ['array', 'values'] });
297
371
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
372
+ // Retrieving entity by contain with full match...
298
373
  resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', contain: ['string', 'test'] });
299
374
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
300
375
  });
301
376
  it('not contain', async () => {
302
377
  await createTestEntities();
378
+ // Retrieving entity by !contain...
303
379
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' }, { type: '!&', contain: ['array', 'pickles'] });
304
380
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
305
381
  });
306
382
  it('wrong contain', async () => {
307
383
  await createTestEntities();
384
+ // Testing wrong contain...
308
385
  let resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', contain: ['array', 'pickles'] });
309
386
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
387
+ // Testing wrong contain...
310
388
  resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', contain: ['string', 'pickles'] });
311
389
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
312
390
  });
313
391
  it('match', async () => {
314
392
  await createTestEntities();
393
+ // Retrieving entity by regex match...
315
394
  let resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', match: ['match', '.*'] });
316
395
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
317
396
  resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', match: ['match', 'Edward McCheese'] });
@@ -339,11 +418,13 @@ This one's zip code is 92064.`;
339
418
  });
340
419
  it('imatch', async () => {
341
420
  await createTestEntities();
421
+ // Retrieving entity by regex match...
342
422
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', imatch: ['match', 'edward mccheese'] });
343
423
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
344
424
  });
345
425
  it('wrong match', async () => {
346
426
  await createTestEntities();
427
+ // Testing wrong regex match...
347
428
  let resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', match: ['match', 'Q'] });
348
429
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
349
430
  resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'pickle', match: ['match', '.*'] });
@@ -359,16 +440,19 @@ This one's zip code is 92064.`;
359
440
  });
360
441
  it('match wrong case', async () => {
361
442
  await createTestEntities();
443
+ // Retrieving entity by regex match...
362
444
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', match: ['match', 'edward mccheese'] });
363
445
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
364
446
  });
365
447
  it('match and equal inclusive', async () => {
366
448
  await createTestEntities();
449
+ // Retrieving entity by regex + equal inclusively...
367
450
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' }, { type: '|', equal: ['string', 'pickles'], match: ['string', 'test'] });
368
451
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
369
452
  });
370
453
  it('greater than', async () => {
371
454
  await createTestEntities();
455
+ // Retrieving entity by inequality...
372
456
  let resultEntity = await nymph.getEntities({ class: TestModel }, {
373
457
  type: '|',
374
458
  gt: [
@@ -377,6 +461,7 @@ This one's zip code is 92064.`;
377
461
  ],
378
462
  });
379
463
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
464
+ // Retrieving entity by inequality...
380
465
  resultEntity = await nymph.getEntities({ class: TestModel }, {
381
466
  type: '|',
382
467
  gt: [
@@ -385,6 +470,7 @@ This one's zip code is 92064.`;
385
470
  ],
386
471
  });
387
472
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
473
+ // Retrieving entity by inequality...
388
474
  resultEntity = await nymph.getEntities({ class: TestModel }, {
389
475
  type: '|',
390
476
  gt: [
@@ -393,6 +479,7 @@ This one's zip code is 92064.`;
393
479
  ],
394
480
  });
395
481
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
482
+ // Retrieving entity by inequality...
396
483
  resultEntity = await nymph.getEntities({ class: TestModel }, {
397
484
  type: '|',
398
485
  gt: [
@@ -401,6 +488,7 @@ This one's zip code is 92064.`;
401
488
  ],
402
489
  });
403
490
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
491
+ // Retrieving entity by inequality...
404
492
  resultEntity = await nymph.getEntities({ class: TestModel }, {
405
493
  type: '|',
406
494
  gt: [
@@ -409,6 +497,7 @@ This one's zip code is 92064.`;
409
497
  ],
410
498
  });
411
499
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
500
+ // Retrieving entity by inequality...
412
501
  resultEntity = await nymph.getEntities({ class: TestModel }, {
413
502
  type: '|',
414
503
  gt: [
@@ -420,6 +509,7 @@ This one's zip code is 92064.`;
420
509
  });
421
510
  it('greater than or equal', async () => {
422
511
  await createTestEntities();
512
+ // Retrieving entity by inequality...
423
513
  let resultEntity = await nymph.getEntities({ class: TestModel }, {
424
514
  type: '|',
425
515
  gte: [
@@ -428,6 +518,7 @@ This one's zip code is 92064.`;
428
518
  ],
429
519
  });
430
520
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
521
+ // Retrieving entity by inequality...
431
522
  resultEntity = await nymph.getEntities({ class: TestModel }, {
432
523
  type: '|',
433
524
  gte: [
@@ -436,6 +527,7 @@ This one's zip code is 92064.`;
436
527
  ],
437
528
  });
438
529
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
530
+ // Retrieving entity by inequality...
439
531
  resultEntity = await nymph.getEntities({ class: TestModel }, {
440
532
  type: '|',
441
533
  gte: [
@@ -444,6 +536,7 @@ This one's zip code is 92064.`;
444
536
  ],
445
537
  });
446
538
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
539
+ // Retrieving entity by inequality...
447
540
  resultEntity = await nymph.getEntities({ class: TestModel }, {
448
541
  type: '|',
449
542
  gte: [
@@ -452,6 +545,7 @@ This one's zip code is 92064.`;
452
545
  ],
453
546
  });
454
547
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
548
+ // Retrieving entity by inequality...
455
549
  resultEntity = await nymph.getEntities({ class: TestModel }, {
456
550
  type: '|',
457
551
  gte: [
@@ -460,6 +554,7 @@ This one's zip code is 92064.`;
460
554
  ],
461
555
  });
462
556
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
557
+ // Retrieving entity by inequality...
463
558
  resultEntity = await nymph.getEntities({ class: TestModel }, {
464
559
  type: '|',
465
560
  gte: [
@@ -471,6 +566,7 @@ This one's zip code is 92064.`;
471
566
  });
472
567
  it('less than', async () => {
473
568
  await createTestEntities();
569
+ // Retrieving entity by inequality...
474
570
  let resultEntity = await nymph.getEntities({ class: TestModel }, {
475
571
  type: '|',
476
572
  lt: [
@@ -479,6 +575,7 @@ This one's zip code is 92064.`;
479
575
  ],
480
576
  });
481
577
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
578
+ // Retrieving entity by inequality...
482
579
  resultEntity = await nymph.getEntities({ class: TestModel }, {
483
580
  type: '|',
484
581
  lt: [
@@ -487,6 +584,7 @@ This one's zip code is 92064.`;
487
584
  ],
488
585
  });
489
586
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
587
+ // Retrieving entity by inequality...
490
588
  resultEntity = await nymph.getEntities({ class: TestModel }, {
491
589
  type: '|',
492
590
  lt: [
@@ -495,6 +593,7 @@ This one's zip code is 92064.`;
495
593
  ],
496
594
  });
497
595
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
596
+ // Retrieving entity by inequality...
498
597
  resultEntity = await nymph.getEntities({ class: TestModel }, {
499
598
  type: '|',
500
599
  lt: [
@@ -503,6 +602,7 @@ This one's zip code is 92064.`;
503
602
  ],
504
603
  });
505
604
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
605
+ // Retrieving entity by inequality...
506
606
  resultEntity = await nymph.getEntities({ class: TestModel }, {
507
607
  type: '|',
508
608
  lt: [
@@ -511,6 +611,7 @@ This one's zip code is 92064.`;
511
611
  ],
512
612
  });
513
613
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
614
+ // Retrieving entity by inequality...
514
615
  resultEntity = await nymph.getEntities({ class: TestModel }, {
515
616
  type: '|',
516
617
  lt: [
@@ -522,6 +623,7 @@ This one's zip code is 92064.`;
522
623
  });
523
624
  it('less than or equal', async () => {
524
625
  await createTestEntities();
626
+ // Retrieving entity by inequality...
525
627
  let resultEntity = await nymph.getEntities({ class: TestModel }, {
526
628
  type: '|',
527
629
  lte: [
@@ -530,6 +632,7 @@ This one's zip code is 92064.`;
530
632
  ],
531
633
  });
532
634
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
635
+ // Retrieving entity by inequality...
533
636
  resultEntity = await nymph.getEntities({ class: TestModel }, {
534
637
  type: '|',
535
638
  lte: [
@@ -538,6 +641,7 @@ This one's zip code is 92064.`;
538
641
  ],
539
642
  });
540
643
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
644
+ // Retrieving entity by inequality...
541
645
  resultEntity = await nymph.getEntities({ class: TestModel }, {
542
646
  type: '|',
543
647
  lte: [
@@ -546,6 +650,7 @@ This one's zip code is 92064.`;
546
650
  ],
547
651
  });
548
652
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
653
+ // Retrieving entity by inequality...
549
654
  resultEntity = await nymph.getEntities({ class: TestModel }, {
550
655
  type: '|',
551
656
  lte: [
@@ -554,6 +659,7 @@ This one's zip code is 92064.`;
554
659
  ],
555
660
  });
556
661
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
662
+ // Retrieving entity by inequality...
557
663
  resultEntity = await nymph.getEntities({ class: TestModel }, {
558
664
  type: '|',
559
665
  lte: [
@@ -562,6 +668,7 @@ This one's zip code is 92064.`;
562
668
  ],
563
669
  });
564
670
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
671
+ // Retrieving entity by inequality...
565
672
  resultEntity = await nymph.getEntities({ class: TestModel }, {
566
673
  type: '|',
567
674
  lte: [
@@ -573,30 +680,36 @@ This one's zip code is 92064.`;
573
680
  });
574
681
  it('not inequality', async () => {
575
682
  await createTestEntities();
683
+ // Retrieving entity by !inequality...
576
684
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' }, { type: '!&', gte: ['number', 60] });
577
685
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
578
686
  });
579
687
  it('wrong inequality', async () => {
580
688
  await createTestEntities();
689
+ // Testing wrong inequality...
581
690
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', lte: ['number', 29.99] });
582
691
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
583
692
  });
584
693
  it('greater than cdate', async () => {
585
694
  await createTestEntities();
695
+ // Retrieving entity by time...
586
696
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', gt: ['cdate', (testEntity.cdate ?? 0) - 120] });
587
697
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
588
698
  });
589
699
  it('wrong cdate', async () => {
590
700
  await createTestEntities();
701
+ // Testing wrong time...
591
702
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', gte: ['cdate', (testEntity.cdate ?? 0) + 1] });
592
703
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
593
704
  });
594
705
  it('time selector', async () => {
595
706
  await createTestEntities();
596
707
  const referenceEntity = await TestModel.factory(refGuid);
708
+ // Retrieving entity by relative time...
597
709
  let resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', gt: ['timestamp', null, '-1 day'] });
598
710
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
599
711
  expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
712
+ // Retrieving entity by relative time inclusively...
600
713
  resultEntity = await nymph.getEntities({ class: TestModel }, {
601
714
  type: '|',
602
715
  gt: [
@@ -606,9 +719,11 @@ This one's zip code is 92064.`;
606
719
  });
607
720
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
608
721
  expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
722
+ // Retrieving entity by relative time...
609
723
  resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', gt: ['timestamp', null, '-3 days'] });
610
724
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
611
725
  expect(referenceEntity.$inArray(resultEntity)).toEqual(true);
726
+ // Retrieving entity by relative time...
612
727
  resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', gt: ['cdate', null, '-1 day'] });
613
728
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
614
729
  expect(referenceEntity.$inArray(resultEntity)).toEqual(true);
@@ -616,43 +731,55 @@ This one's zip code is 92064.`;
616
731
  it('wrong time selector', async () => {
617
732
  await createTestEntities();
618
733
  const referenceEntity = await TestModel.factory(refGuid);
734
+ // Retrieving entity by relative time...
619
735
  let resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', gt: ['timestamp', null, '+1 day'] });
620
736
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
621
737
  expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
738
+ // Retrieving entity by relative time...
622
739
  resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', lt: ['timestamp', null, '-3 days'] });
623
740
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
624
741
  expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
742
+ // Retrieving entity by relative time...
625
743
  resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', gt: ['cdate', null, '+1 day'] });
626
744
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
627
745
  expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
628
746
  });
629
747
  it('references', async () => {
630
748
  await createTestEntities();
749
+ // Testing referenced entities...
750
+ await testEntity.reference?.$wake();
631
751
  expect(testEntity.reference?.test).toEqual('good');
752
+ // Testing referenced entity arrays...
753
+ await Promise.all(testEntity.refArray?.map((e) => e.$wake()) || []);
632
754
  expect(testEntity.refArray?.[0].test).toEqual('good');
633
755
  });
634
756
  it('ref', async () => {
635
757
  await createTestEntities();
758
+ // Retrieving entity by reference...
636
759
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', ref: ['reference', refGuid] });
637
760
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
638
761
  });
639
762
  it('not ref', async () => {
640
763
  await createTestEntities();
764
+ // Retrieving entity by !reference...
641
765
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' }, { type: '!&', ref: ['reference', (0, guid_1.guid)()] });
642
766
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
643
767
  });
644
768
  it('wrong ref', async () => {
645
769
  await createTestEntities();
770
+ // Testing wrong reference...
646
771
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', ref: ['reference', (0, guid_1.guid)()] });
647
772
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
648
773
  });
649
774
  it('nonexistent ref', async () => {
650
775
  await createTestEntities();
776
+ // Testing non-existent reference...
651
777
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', ref: ['pickle', refGuid] });
652
778
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
653
779
  });
654
780
  it('inclusive ref', async () => {
655
781
  await createTestEntities();
782
+ // Retrieving entity by inclusive reference...
656
783
  const resultEntity = await nymph.getEntities({ class: TestModel }, {
657
784
  type: '|',
658
785
  ref: [
@@ -664,6 +791,7 @@ This one's zip code is 92064.`;
664
791
  });
665
792
  it('wrong inclusive ref', async () => {
666
793
  await createTestEntities();
794
+ // Testing wrong inclusive reference...
667
795
  const resultEntity = await nymph.getEntities({ class: TestModel }, {
668
796
  type: '|',
669
797
  ref: [
@@ -675,11 +803,13 @@ This one's zip code is 92064.`;
675
803
  });
676
804
  it('ref in an array', async () => {
677
805
  await createTestEntities();
806
+ // Retrieving entity by array reference...
678
807
  const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', ref: ['refArray', refGuid] });
679
808
  expect(testEntity.$inArray(resultEntity)).toEqual(true);
680
809
  });
681
810
  it('wrong ref in an array', async () => {
682
811
  await createTestEntities();
812
+ // Testing wrong array reference...
683
813
  const resultEntity = await nymph.getEntities({ class: TestModel }, {
684
814
  type: '&',
685
815
  ref: [
@@ -691,6 +821,7 @@ This one's zip code is 92064.`;
691
821
  });
692
822
  it('logic operations', async () => {
693
823
  await createTestEntities();
824
+ // Testing logic operations...
694
825
  const resultEntity = await nymph.getEntities({ class: TestModel }, {
695
826
  type: '&',
696
827
  '!ref': [
@@ -728,6 +859,7 @@ This one's zip code is 92064.`;
728
859
  it('count return', async () => {
729
860
  await createTestEntities();
730
861
  const result = await nymph.getEntities({ class: TestModel });
862
+ // Testing count return...
731
863
  const resultCount = await nymph.getEntities({
732
864
  class: TestModel,
733
865
  return: 'count',
@@ -735,25 +867,30 @@ This one's zip code is 92064.`;
735
867
  expect(resultCount).toBeGreaterThanOrEqual(1);
736
868
  expect(resultCount).toEqual(result.length);
737
869
  const resultSelectors = await nymph.getEntities({ class: TestModel }, { type: '&', ref: ['reference', refGuid] });
870
+ // Testing count return with selectors...
738
871
  const resultSelectorsCount = await nymph.getEntities({ class: TestModel, return: 'count' }, { type: '&', ref: ['reference', refGuid] });
739
872
  expect(resultSelectorsCount).toBeGreaterThanOrEqual(1);
740
873
  expect(resultSelectorsCount).toEqual(resultSelectors.length);
874
+ // Testing count return with limit...
741
875
  const resultSelectorsLimit = await nymph.getEntities({
742
876
  class: TestModel,
743
877
  limit: 1,
744
878
  return: 'count',
745
879
  });
746
880
  expect(resultSelectorsLimit).toEqual(1);
881
+ // Testing count return with limit...
747
882
  const resultSelectorsSingle = await nymph.getEntity({
748
883
  class: TestModel,
749
884
  return: 'count',
750
885
  });
751
886
  expect(resultSelectorsSingle).toEqual(1);
887
+ // Testing empty count...
752
888
  const resultSelectorsEmpty = await nymph.getEntities({ class: TestModel, return: 'count' }, { type: '&', ref: ['reference', (0, guid_1.guid)()] });
753
889
  expect(resultSelectorsEmpty).toEqual(0);
754
890
  });
755
891
  it('guid return', async () => {
756
892
  await createTestEntities();
893
+ // Testing guid return using logic operations...
757
894
  const resultGuid = await nymph.getEntities({ class: TestModel, return: 'guid' }, {
758
895
  type: '&',
759
896
  '!ref': [
@@ -790,6 +927,7 @@ This one's zip code is 92064.`;
790
927
  });
791
928
  it('deep selector', async () => {
792
929
  await createTestEntities();
930
+ // Testing deep selectors...
793
931
  const resultEntity = await nymph.getEntities({ class: TestModel }, {
794
932
  type: '&',
795
933
  '!ref': [
@@ -902,6 +1040,7 @@ This one's zip code is 92064.`;
902
1040
  expect(testEntity.$inArray(resultEntity4)).toEqual(true);
903
1041
  });
904
1042
  it('wrong deep selector', async () => {
1043
+ // Testing wrong deep selectors...
905
1044
  const resultEntity = await nymph.getEntities({ class: TestModel }, {
906
1045
  type: '&',
907
1046
  selector: [
@@ -917,6 +1056,7 @@ This one's zip code is 92064.`;
917
1056
  });
918
1057
  it('qref', async () => {
919
1058
  await createTestEntities();
1059
+ // Retrieving entity by qref...
920
1060
  const resultEntity = await nymph.getEntities({ class: TestModel }, {
921
1061
  type: '&',
922
1062
  qref: [
@@ -928,6 +1068,7 @@ This one's zip code is 92064.`;
928
1068
  });
929
1069
  it('not qref', async () => {
930
1070
  await createTestEntities();
1071
+ // Retrieving entity by !qref...
931
1072
  const resultEntity = await nymph.getEntities({ class: TestModel }, {
932
1073
  type: '&',
933
1074
  '!qref': [
@@ -939,6 +1080,7 @@ This one's zip code is 92064.`;
939
1080
  });
940
1081
  it('wrong qref class', async () => {
941
1082
  await createTestEntities();
1083
+ // Testing wrong qref...
942
1084
  const resultEntity = await nymph.getEntities({ class: TestModel }, {
943
1085
  type: '&',
944
1086
  qref: [
@@ -950,6 +1092,7 @@ This one's zip code is 92064.`;
950
1092
  });
951
1093
  it('wrong qref data', async () => {
952
1094
  await createTestEntities();
1095
+ // Testing wrong qref...
953
1096
  const resultEntity = await nymph.getEntities({ class: TestModel }, {
954
1097
  type: '&',
955
1098
  qref: [
@@ -959,61 +1102,188 @@ This one's zip code is 92064.`;
959
1102
  });
960
1103
  expect(testEntity.$inArray(resultEntity)).toEqual(false);
961
1104
  });
962
- it('sort option', async () => {
1105
+ it('cdate and mdate sort option', async () => {
963
1106
  await createMultipleTestEntities();
964
1107
  for (const sort of ['cdate', 'mdate']) {
965
- let resultEntities = await nymph.getEntities({
966
- class: TestModel,
967
- sort: sort,
968
- });
1108
+ // Retrieving entities sorted...
1109
+ let resultEntities = await nymph.getEntities({ class: TestModel, sort });
969
1110
  expect(resultEntities.length).toBeGreaterThan(100);
970
1111
  for (let i = 0; i < resultEntities.length - 1; i++) {
971
1112
  expect(resultEntities[i + 1][sort]).toBeGreaterThan(resultEntities[i][sort] ?? 0);
972
1113
  }
1114
+ // And test the same with guid return...
973
1115
  let resultGuids = await nymph.getEntities({
974
1116
  class: TestModel,
975
- sort: sort,
1117
+ sort,
976
1118
  return: 'guid',
977
1119
  });
978
1120
  expect(resultGuids.length).toBeGreaterThan(100);
979
1121
  for (let i = 0; i < resultGuids.length - 1; i++) {
980
1122
  expect(resultGuids[i]).toEqual(resultEntities[i].guid);
981
1123
  }
1124
+ // Retrieving entities reverse sorted...
982
1125
  resultEntities = await nymph.getEntities({
983
1126
  class: TestModel,
984
- sort: sort,
1127
+ sort,
985
1128
  reverse: true,
986
1129
  });
987
1130
  expect(resultEntities.length).toBeGreaterThan(100);
988
1131
  for (let i = 0; i < resultEntities.length - 1; i++) {
989
1132
  expect(resultEntities[i + 1][sort]).toBeLessThan(resultEntities[i][sort] ?? 0);
990
1133
  }
991
- resultEntities = await nymph.getEntities({ class: TestModel, sort: sort }, { type: '&', match: ['name', '^Multi Test '] });
1134
+ // And again with other selectors.
1135
+ // Retrieving entities sorted...
1136
+ resultEntities = await nymph.getEntities({ class: TestModel, sort }, { type: '&', match: ['name', '^Multi Test '] });
992
1137
  expect(resultEntities.length).toEqual(100);
993
1138
  for (let i = 0; i < resultEntities.length - 1; i++) {
994
1139
  expect(resultEntities[i + 1][sort]).toBeGreaterThan(resultEntities[i][sort] ?? 0);
995
1140
  }
996
- resultEntities = await nymph.getEntities({ class: TestModel, sort: sort, reverse: true }, { type: '&', match: ['name', '^Multi Test '] });
1141
+ // Retrieving entities reverse sorted...
1142
+ resultEntities = await nymph.getEntities({ class: TestModel, sort, reverse: true }, { type: '&', match: ['name', '^Multi Test '] });
997
1143
  expect(resultEntities.length).toEqual(100);
998
1144
  for (let i = 0; i < resultEntities.length - 1; i++) {
999
1145
  expect(resultEntities[i + 1][sort]).toBeLessThan(resultEntities[i][sort] ?? 0);
1000
1146
  }
1001
1147
  }
1002
1148
  });
1149
+ it('property sort option', async () => {
1150
+ await createMultipleTestEntities();
1151
+ // Retrieving entities sorted...
1152
+ let resultEntities = await nymph.getEntities({
1153
+ class: TestModel,
1154
+ sort: 'number',
1155
+ });
1156
+ expect(resultEntities.length).toBeGreaterThan(100);
1157
+ for (let i = 0; i < resultEntities.length - 1; i++) {
1158
+ expect(resultEntities[i + 1].number ?? Infinity).toBeGreaterThanOrEqual(resultEntities[i].number ?? 0);
1159
+ }
1160
+ // And test the same with guid return...
1161
+ let resultGuids = await nymph.getEntities({
1162
+ class: TestModel,
1163
+ sort: 'number',
1164
+ return: 'guid',
1165
+ });
1166
+ expect(resultGuids.length).toBeGreaterThan(100);
1167
+ for (let i = 0; i < resultGuids.length - 1; i++) {
1168
+ expect(resultGuids[i]).toEqual(resultEntities[i].guid);
1169
+ }
1170
+ // Retrieving entities reverse sorted...
1171
+ resultEntities = await nymph.getEntities({
1172
+ class: TestModel,
1173
+ sort: 'number',
1174
+ reverse: true,
1175
+ });
1176
+ expect(resultEntities.length).toBeGreaterThan(100);
1177
+ for (let i = 0; i < resultEntities.length - 1; i++) {
1178
+ expect(resultEntities[i + 1].number ?? 0).toBeLessThanOrEqual(resultEntities[i].number ?? Infinity);
1179
+ }
1180
+ // And again with other selectors.
1181
+ // Retrieving entities sorted...
1182
+ resultEntities = await nymph.getEntities({ class: TestModel, sort: 'number' }, { type: '&', match: ['name', '^Multi Test '] });
1183
+ expect(resultEntities.length).toEqual(100);
1184
+ for (let i = 0; i < resultEntities.length - 1; i++) {
1185
+ expect(resultEntities[i + 1].number ?? Infinity).toBeGreaterThan(resultEntities[i].number ?? 0);
1186
+ expect(resultEntities[i].name).toEqual(`Multi Test ${100 - (resultEntities[i].number ?? 0)}`);
1187
+ }
1188
+ // Retrieving entities reverse sorted...
1189
+ resultEntities = await nymph.getEntities({ class: TestModel, sort: 'number', reverse: true }, { type: '&', match: ['name', '^Multi Test '] });
1190
+ expect(resultEntities.length).toEqual(100);
1191
+ for (let i = 0; i < resultEntities.length - 1; i++) {
1192
+ expect(resultEntities[i + 1].number ?? 0).toBeLessThan(resultEntities[i].number ?? Infinity);
1193
+ expect(resultEntities[i].name).toEqual(`Multi Test ${100 - (resultEntities[i].number ?? 0)}`);
1194
+ }
1195
+ });
1003
1196
  it('delete reference', async () => {
1004
1197
  await createTestEntities();
1198
+ // Deleting referenced entities...
1199
+ await testEntity.reference?.$wake();
1005
1200
  expect(await testEntity.reference?.$delete()).toEqual(true);
1201
+ await Promise.all(testEntity.refArray?.map((e) => e.$wake()) || []);
1006
1202
  expect(testEntity.reference?.guid).toBeNull();
1007
1203
  });
1008
1204
  it('delete', async () => {
1009
1205
  await createTestEntities();
1206
+ // Deleting entity...
1010
1207
  expect(await testEntity.$delete()).toEqual(true);
1011
1208
  expect(testEntity.guid).toBeNull();
1012
1209
  const entity = await nymph.getEntity({ class: TestModel }, { type: '&', guid: testGuid });
1013
1210
  expect(entity).toBeNull();
1014
1211
  });
1212
+ it('allows non-duplicate unique strings', async () => {
1213
+ // Creating entity...
1214
+ const uniqueEntityA = await TestModel.factory();
1215
+ uniqueEntityA.name = 'Entity Test ' + new Date().toLocaleString();
1216
+ uniqueEntityA.uniques = ['test a'];
1217
+ // Saving entity...
1218
+ expect(await uniqueEntityA.$save()).toEqual(true);
1219
+ expect(uniqueEntityA.guid).not.toBeNull();
1220
+ // Creating entity...
1221
+ const uniqueEntityB = await TestModel.factory();
1222
+ uniqueEntityB.name = 'Entity Test ' + new Date().toLocaleString();
1223
+ uniqueEntityB.uniques = ['test b'];
1224
+ // Saving entity...
1225
+ expect(await uniqueEntityB.$save()).toEqual(true);
1226
+ expect(uniqueEntityB.guid).not.toBeNull();
1227
+ expect(uniqueEntityA.guid).not.toEqual(uniqueEntityB.guid);
1228
+ expect(await uniqueEntityA.$delete()).toEqual(true);
1229
+ expect(await uniqueEntityB.$delete()).toEqual(true);
1230
+ });
1231
+ it('throws on duplicate unique strings', async () => {
1232
+ // Creating entity...
1233
+ const uniqueEntityA = await TestModel.factory();
1234
+ uniqueEntityA.name = 'Entity Test ' + new Date().toLocaleString();
1235
+ uniqueEntityA.uniques = ['test a'];
1236
+ // Saving entity...
1237
+ expect(await uniqueEntityA.$save()).toEqual(true);
1238
+ expect(uniqueEntityA.guid).not.toBeNull();
1239
+ // Creating entity...
1240
+ const uniqueEntityB = await TestModel.factory();
1241
+ uniqueEntityB.name = 'Entity Test ' + new Date().toLocaleString();
1242
+ uniqueEntityB.uniques = ['test a'];
1243
+ // Saving entity...
1244
+ try {
1245
+ await uniqueEntityB.$save();
1246
+ throw Error("Shouldn't get past the uniqueness check.");
1247
+ }
1248
+ catch (e) {
1249
+ expect(e).toBeInstanceOf(errors_1.EntityUniqueConstraintError);
1250
+ }
1251
+ expect(uniqueEntityB.guid).toBeNull();
1252
+ expect(await uniqueEntityA.$delete()).toEqual(true);
1253
+ });
1254
+ it('allows duplicate unique string if first transaction is rolled back', async () => {
1255
+ // Creating transaction entity...
1256
+ const tnymphA = await nymph.startTransaction('test-unique-a');
1257
+ const TestModelA = tnymphA.getEntityClass(TestModel);
1258
+ const uniqueEntityA = await TestModelA.factory();
1259
+ uniqueEntityA.name = 'Entity Test ' + new Date().toLocaleString();
1260
+ uniqueEntityA.uniques = ['test a'];
1261
+ // Saving entity...
1262
+ expect(await uniqueEntityA.$save()).toEqual(true);
1263
+ expect(uniqueEntityA.guid).not.toBeNull();
1264
+ // Rolling back transaction...
1265
+ expect(await tnymphA.rollback('test-unique-a')).toEqual(true);
1266
+ // Creating transaction entity...
1267
+ const tnymphB = await nymph.startTransaction('test-unique-b');
1268
+ const TestModelB = tnymphB.getEntityClass(TestModel);
1269
+ const uniqueEntityB = await TestModelB.factory();
1270
+ uniqueEntityB.name = 'Entity Test ' + new Date().toLocaleString();
1271
+ uniqueEntityB.uniques = ['test a'];
1272
+ // Saving entity...
1273
+ expect(await uniqueEntityB.$save()).toEqual(true);
1274
+ expect(uniqueEntityB.guid).not.toBeNull();
1275
+ expect(uniqueEntityA.guid).not.toEqual(uniqueEntityB.guid);
1276
+ expect(await tnymphB.commit('test-unique-b')).toEqual(true);
1277
+ const uniqueEntityACheck = await nymph.getEntity({ class: TestModel }, { type: '&', guid: uniqueEntityA.guid ?? '' });
1278
+ expect(uniqueEntityACheck).toBeNull();
1279
+ const uniqueEntityBCheck = await nymph.getEntity({ class: TestModel }, { type: '&', guid: uniqueEntityB.guid ?? '' });
1280
+ expect(uniqueEntityBCheck).not.toBeNull();
1281
+ if (uniqueEntityBCheck != null) {
1282
+ expect(await uniqueEntityBCheck.$delete()).toEqual(true);
1283
+ }
1284
+ });
1015
1285
  }
1016
- exports.QueriesTest = QueriesTest;
1286
+ exports.EntitiesTest = EntitiesTest;
1017
1287
  function UIDTest(nymph, it) {
1018
1288
  it('delete old test data', async () => {
1019
1289
  expect(await nymph.deleteUID('TestUID')).toEqual(true);
@@ -1073,21 +1343,35 @@ function ExportImportTest(nymph, it) {
1073
1343
  const models = await nymph.getEntities({ class: TestModel });
1074
1344
  const bmodels = await nymph.getEntities({ class: TestBModel });
1075
1345
  expect(models.length).toEqual(30);
1076
- expect(bmodels.length).toEqual(10);
1077
- const all = [...models, ...bmodels];
1078
- for (const model of all) {
1079
- if (model.index?.match(/^\d+a$/)) {
1080
- expect(model.null).toBeNull();
1081
- expect(model.string).toEqual('test');
1082
- expect(model.array).toEqual(['full', 'of', 'values', 500]);
1083
- expect(model.number).toEqual(30);
1084
- expect(model.timestamp).toBeGreaterThanOrEqual((0, strtotime_1.default)('-2 minutes'));
1085
- expect(model.reference?.guid).not.toBeNull();
1086
- expect(model.reference?.string).toEqual('another');
1087
- expect(model.reference?.index?.match(/^\d+b$/)).toBeTruthy();
1088
- expect(model.refArray?.[0].guid).not.toBeNull();
1089
- expect(model.refArray?.[0].guid).toEqual(model.reference?.guid);
1090
- }
1346
+ expect(bmodels.length).toEqual(30);
1347
+ for (const model of models) {
1348
+ expect(model.name).toMatch(/^Entity Test /);
1349
+ expect(model.null).toBeDefined();
1350
+ expect(model.null).toBeNull();
1351
+ expect(model.string).toEqual('test');
1352
+ expect(model.array).toEqual(['full', 'of', 'values', 500]);
1353
+ expect(model.match)
1354
+ .toEqual(`Hello, my name is Edward McCheese. It is a pleasure to meet you. As you can see, I have several hats of the most pleasant nature.
1355
+
1356
+ This one's email address is nice_hat-wednesday+newyork@im-a-hat.hat.
1357
+ This one's phone number is (555) 555-1818.
1358
+ This one's zip code is 92064.
1359
+ This one's favorite emojis are 🔥❤️😊😂⭐🤔
1360
+
1361
+ These hats are absolutely fantastic.`);
1362
+ expect(model.number).toEqual(30);
1363
+ expect(model.numberString).toEqual('30');
1364
+ expect(model.timestamp).toBeGreaterThanOrEqual((0, strtotime_1.default)('-2 minutes'));
1365
+ expect(model.index).toMatch(/^\d+a$/);
1366
+ await model.reference?.$wake();
1367
+ expect(model.reference?.guid).not.toBeNull();
1368
+ expect(model.reference?.string).toEqual('another');
1369
+ expect(model.reference?.index).toMatch(/^\d+b$/);
1370
+ expect(model.index?.substring(0, -1)).toEqual(model.reference?.index?.substring(0, -1));
1371
+ expect(model.reference?.$inArray(bmodels)).toEqual(true);
1372
+ await Promise.all(model.refArray?.map((e) => e.$wake()) || []);
1373
+ expect(model.refArray?.[0].guid).not.toBeNull();
1374
+ expect(model.refArray?.[0].guid).toEqual(model.reference?.guid);
1091
1375
  }
1092
1376
  }
1093
1377
  it('delete old test data', async () => {
@@ -1097,17 +1381,27 @@ function ExportImportTest(nymph, it) {
1097
1381
  expect(await nymph.newUID('TestUID')).toEqual(1);
1098
1382
  expect(await nymph.newUID('TestUID')).toEqual(2);
1099
1383
  expect(await nymph.newUID('TestUID2')).toEqual(1);
1100
- for (let i = 0; i < 20; i++) {
1101
- const EntityClass = i < 15 ? TestModel : TestBModel;
1102
- const testEntity = await EntityClass.factory();
1384
+ for (let i = 0; i < 30; i++) {
1385
+ // Creating entity...
1386
+ const testEntity = await TestModel.factory();
1387
+ // Saving entity...
1103
1388
  testEntity.name = 'Entity Test ' + new Date().toLocaleString();
1104
1389
  testEntity.null = null;
1105
1390
  testEntity.string = 'test';
1106
1391
  testEntity.array = ['full', 'of', 'values', 500];
1392
+ testEntity.match = `Hello, my name is Edward McCheese. It is a pleasure to meet you. As you can see, I have several hats of the most pleasant nature.
1393
+
1394
+ This one's email address is nice_hat-wednesday+newyork@im-a-hat.hat.
1395
+ This one's phone number is (555) 555-1818.
1396
+ This one's zip code is 92064.
1397
+ This one's favorite emojis are 🔥❤️😊😂⭐🤔
1398
+
1399
+ These hats are absolutely fantastic.`;
1107
1400
  testEntity.number = 30;
1401
+ testEntity.numberString = '30';
1108
1402
  testEntity.timestamp = Date.now();
1109
1403
  testEntity.index = i + 'a';
1110
- const entityReferenceTest = await EntityClass.factory();
1404
+ const entityReferenceTest = await TestBModel.factory();
1111
1405
  entityReferenceTest.string = 'another';
1112
1406
  entityReferenceTest.index = i + 'b';
1113
1407
  expect(await entityReferenceTest.$save()).toEqual(true);