@nymphjs/nymph 1.0.0-beta.120 → 1.0.0-beta.121

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.
@@ -17,2125 +17,2201 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
17
17
 
18
18
  export function EntitiesTest(
19
19
  nymph: Nymph,
20
+ describe: (name: string, fn: () => void) => void,
20
21
  it: (name: string, fn: () => void) => void,
21
22
  ) {
22
- const TestModel = nymph.addEntityClass(TestModelClass);
23
- const TestBModel = nymph.addEntityClass(TestBModelClass);
24
- const TestEmptyModel = nymph.addEntityClass(TestEmptyModelClass);
25
-
26
- let testEntity: TestModelClass & TestModelData;
27
- let testGuid: string;
28
- let refGuid: string;
29
- let createdMultiple = false;
30
-
31
- // The entities created by this function are required by many of the tests.
32
- async function createTestEntities() {
33
- if (testGuid != null) {
34
- return;
35
- }
36
-
37
- // Creating entity...
38
- testEntity = await TestModel.factory();
39
-
40
- // Saving entity...
41
- testEntity.name = 'Entity Test ' + new Date().toLocaleString();
42
- testEntity.null = null;
43
- testEntity.string = 'test';
44
- testEntity.array = [
45
- 'full',
46
- 'of',
47
- 'values',
48
- 500,
49
- { test: true },
50
- { nullbyte: '\\\x00\u0000 \x00' },
51
- ];
52
- testEntity.match = matchValue;
53
- testEntity.search = searchValue;
54
- testEntity.number = 30;
55
- testEntity.numberString = '30';
56
- testEntity.timestamp = Date.now();
57
- expect(await testEntity.$save()).toEqual(true);
58
- expect(testEntity.guid).not.toBeNull();
59
- testGuid = testEntity.guid as string;
60
-
61
- const entityReferenceTest: TestModelClass & TestModelData = new TestModel();
62
- entityReferenceTest.string = 'wrong';
63
- entityReferenceTest.timestamp = (strtotime('-2 days') || 0) * 1000;
64
- expect(await entityReferenceTest.$save()).toEqual(true);
65
- refGuid = entityReferenceTest.guid as string;
66
- testEntity.reference = entityReferenceTest;
67
- testEntity.refArray = [entityReferenceTest];
68
- expect(await testEntity.$save()).toEqual(true);
69
-
70
- entityReferenceTest.test = 'good';
71
- expect(await entityReferenceTest.$save()).toEqual(true);
72
-
73
- // Test asynchronous getEntity.
74
- testEntity = (await nymph.getEntity(
75
- { class: TestModel },
76
- testGuid,
77
- )) as TestModelClass & TestModelData;
78
- expect(testEntity).toBeInstanceOf(TestModel);
79
- expect(testEntity.guid).toEqual(testGuid);
80
- }
81
-
82
- // The entities created by this function are required by many of the tests.
83
- async function createMultipleTestEntities() {
84
- if (!createdMultiple) {
85
- createdMultiple = true;
86
- // Creating 100 entities...
87
- for (let i = 0; i < 100; i++) {
88
- const testEntity = await TestModel.factory();
89
- testEntity.name = `Multi Test ${i}`;
90
- // Reverse the number for sort testing.
91
- testEntity.number = 100 - i;
92
- testEntity.$removeTag('test');
93
- testEntity.$addTag('multiTest');
94
- expect(await testEntity.$save()).toEqual(true);
95
- // Pause for a few milliseconds so the cdate and mdate can be sorted.
96
- await new Promise((res) => setTimeout(() => res(1), 5));
23
+ describe('Entity', () => {
24
+ const TestModel = nymph.addEntityClass(TestModelClass);
25
+ const TestBModel = nymph.addEntityClass(TestBModelClass);
26
+ const TestEmptyModel = nymph.addEntityClass(TestEmptyModelClass);
27
+
28
+ let testEntity: TestModelClass & TestModelData;
29
+ let testGuid: string;
30
+ let refGuid: string;
31
+ let createdMultiple = false;
32
+
33
+ // The entities created by this function are required by many of the tests.
34
+ async function createTestEntities() {
35
+ if (testGuid != null) {
36
+ return;
97
37
  }
98
- }
99
- }
100
38
 
101
- it('delete old test data', async () => {
102
- let amodels = await nymph.getEntities({ class: TestModel });
103
- expect(Array.isArray(amodels)).toEqual(true);
104
- for (const cur of amodels) {
105
- expect(await cur.$delete()).toEqual(true);
106
- }
39
+ // Creating entity...
40
+ testEntity = await TestModel.factory();
107
41
 
108
- amodels = await nymph.getEntities({ class: TestModel });
109
- expect(amodels.length).toEqual(0);
42
+ // Saving entity...
43
+ testEntity.name = 'Entity Test ' + new Date().toLocaleString();
44
+ testEntity.null = null;
45
+ testEntity.string = 'test';
46
+ testEntity.array = [
47
+ 'full',
48
+ 'of',
49
+ 'values',
50
+ 500,
51
+ { test: true },
52
+ { nullbyte: '\\\x00\u0000 \x00' },
53
+ ];
54
+ testEntity.match = matchValue;
55
+ testEntity.search = searchValue;
56
+ testEntity.number = 30;
57
+ testEntity.numberString = '30';
58
+ testEntity.timestamp = Date.now();
59
+ expect(await testEntity.$save()).toEqual(true);
60
+ expect(testEntity.guid).not.toBeNull();
61
+ testGuid = testEntity.guid as string;
110
62
 
111
- let bmodels = await nymph.getEntities({ class: TestBModel });
112
- expect(Array.isArray(bmodels)).toEqual(true);
113
- for (const cur of bmodels) {
114
- expect(await cur.$delete()).toEqual(true);
115
- }
63
+ const entityReferenceTest: TestModelClass & TestModelData =
64
+ new TestModel();
65
+ entityReferenceTest.string = 'wrong';
66
+ entityReferenceTest.timestamp = (strtotime('-2 days') || 0) * 1000;
67
+ expect(await entityReferenceTest.$save()).toEqual(true);
68
+ refGuid = entityReferenceTest.guid as string;
69
+ testEntity.reference = entityReferenceTest;
70
+ testEntity.refArray = [entityReferenceTest];
71
+ expect(await testEntity.$save()).toEqual(true);
116
72
 
117
- bmodels = await nymph.getEntities({ class: TestBModel });
118
- expect(bmodels.length).toEqual(0);
119
- });
73
+ entityReferenceTest.test = 'good';
74
+ expect(await entityReferenceTest.$save()).toEqual(true);
120
75
 
121
- it('create entity', async () => {
122
- await createTestEntities();
123
- });
76
+ // Test asynchronous getEntity.
77
+ testEntity = (await nymph.getEntity(
78
+ { class: TestModel },
79
+ testGuid,
80
+ )) as TestModelClass & TestModelData;
81
+ expect(testEntity).toBeInstanceOf(TestModel);
82
+ expect(testEntity.guid).toEqual(testGuid);
83
+ }
124
84
 
125
- it("doesn't create empty entity", async () => {
126
- const testEntity = await TestEmptyModel.factory();
85
+ // The entities created by this function are required by many of the tests.
86
+ async function createMultipleTestEntities() {
87
+ if (!createdMultiple) {
88
+ createdMultiple = true;
89
+ // Creating 100 entities...
90
+ for (let i = 0; i < 100; i++) {
91
+ const testEntity = await TestModel.factory();
92
+ testEntity.name = `Multi Test ${i}`;
93
+ // Reverse the number for sort testing.
94
+ testEntity.number = 100 - i;
95
+ testEntity.$removeTag('test');
96
+ testEntity.$addTag('multiTest');
97
+ expect(await testEntity.$save()).toEqual(true);
98
+ // Pause for a few milliseconds so the cdate and mdate can be sorted.
99
+ await new Promise((res) => setTimeout(() => res(1), 5));
100
+ }
101
+ }
102
+ }
127
103
 
128
- expect(await testEntity.$save()).toBeFalsy();
129
- expect(testEntity.guid).toBeNull();
130
- });
104
+ it('delete old test data', async () => {
105
+ let amodels = await nymph.getEntities({ class: TestModel });
106
+ expect(Array.isArray(amodels)).toEqual(true);
107
+ for (const cur of amodels) {
108
+ expect(await cur.$delete()).toEqual(true);
109
+ }
131
110
 
132
- it('update mdate on save', async () => {
133
- await createTestEntities();
111
+ amodels = await nymph.getEntities({ class: TestModel });
112
+ expect(amodels.length).toEqual(0);
134
113
 
135
- const oldMdate = testEntity.mdate ?? Infinity;
114
+ let bmodels = await nymph.getEntities({ class: TestBModel });
115
+ expect(Array.isArray(bmodels)).toEqual(true);
116
+ for (const cur of bmodels) {
117
+ expect(await cur.$delete()).toEqual(true);
118
+ }
136
119
 
137
- await new Promise((resolve) => setTimeout(() => resolve(true), 100));
138
- await testEntity.$save();
120
+ bmodels = await nymph.getEntities({ class: TestBModel });
121
+ expect(bmodels.length).toEqual(0);
122
+ });
139
123
 
140
- expect(testEntity.mdate).toBeGreaterThan(oldMdate);
141
- });
124
+ it('create entity', async () => {
125
+ await createTestEntities();
126
+ });
142
127
 
143
- it('create multiple entities', async () => {
144
- return createMultipleTestEntities();
145
- });
128
+ it("doesn't create empty entity", async () => {
129
+ const testEntity = await TestEmptyModel.factory();
146
130
 
147
- it('by guid', async () => {
148
- await createTestEntities();
131
+ expect(await testEntity.$save()).toBeFalsy();
132
+ expect(testEntity.guid).toBeNull();
133
+ });
149
134
 
150
- // Retrieving entity by GUID...
151
- let resultEntity = await nymph.getEntity({ class: TestModel }, testGuid);
152
- expect(testEntity.$is(resultEntity)).toEqual(true);
135
+ it('update mdate on save', async () => {
136
+ await createTestEntities();
153
137
 
154
- // Using class constructor...
155
- resultEntity = await TestModel.factory(testGuid);
156
- expect(testEntity.$is(resultEntity)).toEqual(true);
138
+ const oldMdate = testEntity.mdate ?? Infinity;
157
139
 
158
- // Testing wrong GUID...
159
- resultEntity = await nymph.getEntity({ class: TestModel }, guid());
160
- expect(testEntity.$is(resultEntity)).toEqual(false);
161
- });
140
+ await new Promise((resolve) => setTimeout(() => resolve(true), 100));
141
+ await testEntity.$save();
162
142
 
163
- it('guaranteed guid', async () => {
164
- // Creating entity...
165
- const testEntity = await TestModel.factory();
166
-
167
- // Saving entity...
168
- testEntity.name = 'Entity Test ' + new Date().toLocaleString();
169
- testEntity.null = null;
170
- testEntity.string = 'test';
171
- testEntity.array = [];
172
- testEntity.match = matchValue;
173
- testEntity.number = 30;
174
- testEntity.numberString = '30';
175
- testEntity.timestamp = Date.now();
176
-
177
- // Get the guaranteed GUID.
178
- const testGuid = testEntity.$getGuaranteedGUID();
179
-
180
- expect(await testEntity.$save()).toEqual(true);
181
- expect(testEntity.guid).not.toBeNull();
182
- expect(testEntity.guid).toEqual(testGuid);
183
-
184
- // Retrieving entity by GUID...
185
- let resultEntity = await nymph.getEntity({ class: TestModel }, testGuid);
186
- expect(testEntity.$is(resultEntity)).toEqual(true);
187
-
188
- // Delete the entity.
189
- expect(await testEntity.$delete()).toEqual(true);
190
- });
143
+ expect(testEntity.mdate).toBeGreaterThan(oldMdate);
144
+ });
191
145
 
192
- it('create, list, and delete indexes', async () => {
193
- // Delete existing indexes.
194
- const existingIndexes = await nymph.getIndexes(TestModel.ETYPE);
195
- for (let index of existingIndexes) {
196
- await nymph.deleteIndex(TestModel.ETYPE, index.scope, index.name);
197
- }
198
- const existingBIndexes = await nymph.getIndexes(TestBModel.ETYPE);
199
- for (let index of existingBIndexes) {
200
- await nymph.deleteIndex(TestBModel.ETYPE, index.scope, index.name);
201
- }
146
+ it('create multiple entities', async () => {
147
+ return createMultipleTestEntities();
148
+ });
202
149
 
203
- const sortByName = (arr: { name: string }[]) => {
204
- arr.sort((a, b) => a.name.localeCompare(b.name));
205
- return arr;
206
- };
207
-
208
- expect(
209
- await nymph.addIndex(TestModel.ETYPE, {
210
- scope: 'data',
211
- name: 'testindex',
212
- property: 'test',
213
- }),
214
- ).toEqual(true);
215
-
216
- expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
217
- { scope: 'data', name: 'testindex', property: 'test' },
218
- ]);
219
-
220
- expect(
221
- await nymph.addIndex(TestModel.ETYPE, {
222
- scope: 'data',
223
- name: 'secondone',
224
- property: 'match',
225
- }),
226
- ).toEqual(true);
227
-
228
- expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
229
- { scope: 'data', name: 'secondone', property: 'match' },
230
- { scope: 'data', name: 'testindex', property: 'test' },
231
- ]);
232
-
233
- expect(
234
- await nymph.addIndex(TestModel.ETYPE, {
235
- scope: 'references',
236
- name: 'refone',
237
- property: 'reference',
238
- }),
239
- ).toEqual(true);
240
-
241
- expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
242
- { scope: 'references', name: 'refone', property: 'reference' },
243
- { scope: 'data', name: 'secondone', property: 'match' },
244
- { scope: 'data', name: 'testindex', property: 'test' },
245
- ]);
246
-
247
- expect(
248
- await nymph.addIndex(TestModel.ETYPE, {
249
- scope: 'tokens',
250
- name: 'tokenone',
251
- property: 'search',
252
- }),
253
- ).toEqual(true);
254
-
255
- expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
256
- { scope: 'references', name: 'refone', property: 'reference' },
257
- { scope: 'data', name: 'secondone', property: 'match' },
258
- { scope: 'data', name: 'testindex', property: 'test' },
259
- { scope: 'tokens', name: 'tokenone', property: 'search' },
260
- ]);
261
-
262
- expect(
263
- await nymph.addIndex(TestBModel.ETYPE, {
264
- scope: 'data',
265
- name: 'flooflab',
266
- property: 'string',
267
- }),
268
- ).toEqual(true);
269
-
270
- expect(sortByName(await nymph.getIndexes(TestBModel.ETYPE))).toEqual([
271
- { scope: 'data', name: 'flooflab', property: 'string' },
272
- ]);
273
-
274
- expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
275
- { scope: 'references', name: 'refone', property: 'reference' },
276
- { scope: 'data', name: 'secondone', property: 'match' },
277
- { scope: 'data', name: 'testindex', property: 'test' },
278
- { scope: 'tokens', name: 'tokenone', property: 'search' },
279
- ]);
280
-
281
- expect(
282
- await nymph.deleteIndex(TestBModel.ETYPE, 'data', 'flooflab'),
283
- ).toEqual(true);
284
-
285
- expect(await nymph.getIndexes(TestBModel.ETYPE)).toEqual([]);
286
-
287
- expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
288
- { scope: 'references', name: 'refone', property: 'reference' },
289
- { scope: 'data', name: 'secondone', property: 'match' },
290
- { scope: 'data', name: 'testindex', property: 'test' },
291
- { scope: 'tokens', name: 'tokenone', property: 'search' },
292
- ]);
293
-
294
- expect(
295
- await nymph.deleteIndex(TestModel.ETYPE, 'data', 'testindex'),
296
- ).toEqual(true);
297
-
298
- expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
299
- { scope: 'references', name: 'refone', property: 'reference' },
300
- { scope: 'data', name: 'secondone', property: 'match' },
301
- { scope: 'tokens', name: 'tokenone', property: 'search' },
302
- ]);
303
- });
150
+ it('by guid', async () => {
151
+ await createTestEntities();
304
152
 
305
- it('transactions', async () => {
306
- await createTestEntities();
153
+ // Retrieving entity by GUID...
154
+ let resultEntity = await nymph.getEntity({ class: TestModel }, testGuid);
155
+ expect(testEntity.$is(resultEntity)).toEqual(true);
307
156
 
308
- // Verify not in a transaction.
309
- expect(await nymph.inTransaction()).toEqual(false);
157
+ // Using class constructor...
158
+ resultEntity = await TestModel.factory(testGuid);
159
+ expect(testEntity.$is(resultEntity)).toEqual(true);
310
160
 
311
- let transaction = await nymph.startTransaction('test');
312
- testEntity.$nymph = transaction;
161
+ // Testing wrong GUID...
162
+ resultEntity = await nymph.getEntity({ class: TestModel }, guid());
163
+ expect(testEntity.$is(resultEntity)).toEqual(false);
164
+ });
313
165
 
314
- if (!(await transaction.inTransaction())) {
315
- console.log(
316
- 'This Nymph driver or database seems to not support transactions. Skipping transaction tests.',
317
- );
318
- await transaction.rollback('test');
319
- return;
320
- }
166
+ it('guaranteed guid', async () => {
167
+ // Creating entity...
168
+ const testEntity = await TestModel.factory();
321
169
 
322
- // Change a value in the test entity.
323
- testEntity.string = 'bad value';
324
- expect(await testEntity.$save()).toEqual(true);
170
+ // Saving entity...
171
+ testEntity.name = 'Entity Test ' + new Date().toLocaleString();
172
+ testEntity.null = null;
173
+ testEntity.string = 'test';
174
+ testEntity.array = [];
175
+ testEntity.match = matchValue;
176
+ testEntity.number = 30;
177
+ testEntity.numberString = '30';
178
+ testEntity.timestamp = Date.now();
325
179
 
326
- // Rollback the transaction.
327
- await transaction.rollback('test');
180
+ // Get the guaranteed GUID.
181
+ const testGuid = testEntity.$getGuaranteedGUID();
328
182
 
329
- // Verify not in a transaction.
330
- expect(await transaction.inTransaction()).toEqual(false);
183
+ expect(await testEntity.$save()).toEqual(true);
184
+ expect(testEntity.guid).not.toBeNull();
185
+ expect(testEntity.guid).toEqual(testGuid);
331
186
 
332
- // Verify the value is correct.
333
- await testEntity.$refresh();
334
- expect(testEntity.string).toEqual('test');
187
+ // Retrieving entity by GUID...
188
+ let resultEntity = await nymph.getEntity({ class: TestModel }, testGuid);
189
+ expect(testEntity.$is(resultEntity)).toEqual(true);
335
190
 
336
- // Start a new transaction.
337
- transaction = await nymph.startTransaction('test');
338
- testEntity.$nymph = transaction;
191
+ // Delete the entity.
192
+ expect(await testEntity.$delete()).toEqual(true);
193
+ });
339
194
 
340
- // Verify in a transaction.
341
- expect(await transaction.inTransaction()).toEqual(true);
195
+ it('create, list, and delete indexes', async () => {
196
+ // Delete existing indexes.
197
+ const existingIndexes = await nymph.getIndexes(TestModel.ETYPE);
198
+ for (let index of existingIndexes) {
199
+ await nymph.deleteIndex(TestModel.ETYPE, index.scope, index.name);
200
+ }
201
+ const existingBIndexes = await nymph.getIndexes(TestBModel.ETYPE);
202
+ for (let index of existingBIndexes) {
203
+ await nymph.deleteIndex(TestBModel.ETYPE, index.scope, index.name);
204
+ }
342
205
 
343
- // Delete the entity.
344
- expect(await testEntity.$delete()).toEqual(true);
345
- const resultEntity = await transaction.getEntity(
346
- { class: TestModel },
347
- testGuid,
348
- );
349
- expect(resultEntity).toBeNull();
206
+ const sortByName = (arr: { name: string }[]) => {
207
+ arr.sort((a, b) => a.name.localeCompare(b.name));
208
+ return arr;
209
+ };
210
+
211
+ expect(
212
+ await nymph.addIndex(TestModel.ETYPE, {
213
+ scope: 'data',
214
+ name: 'testindex',
215
+ property: 'test',
216
+ }),
217
+ ).toEqual(true);
218
+
219
+ expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
220
+ { scope: 'data', name: 'testindex', property: 'test' },
221
+ ]);
350
222
 
351
- // Rollback the transaction.
352
- await transaction.rollback('test');
223
+ expect(
224
+ await nymph.addIndex(TestModel.ETYPE, {
225
+ scope: 'data',
226
+ name: 'secondone',
227
+ property: 'match',
228
+ }),
229
+ ).toEqual(true);
230
+
231
+ expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
232
+ { scope: 'data', name: 'secondone', property: 'match' },
233
+ { scope: 'data', name: 'testindex', property: 'test' },
234
+ ]);
353
235
 
354
- // Verify not in a transaction.
355
- expect(await transaction.inTransaction()).toEqual(false);
236
+ expect(
237
+ await nymph.addIndex(TestModel.ETYPE, {
238
+ scope: 'references',
239
+ name: 'refone',
240
+ property: 'reference',
241
+ }),
242
+ ).toEqual(true);
243
+
244
+ expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
245
+ { scope: 'references', name: 'refone', property: 'reference' },
246
+ { scope: 'data', name: 'secondone', property: 'match' },
247
+ { scope: 'data', name: 'testindex', property: 'test' },
248
+ ]);
356
249
 
357
- // Verify it's back.
358
- testEntity = (await transaction.getEntity(
359
- { class: TestModel },
360
- testGuid,
361
- )) as TestModelClass & TestModelData;
250
+ expect(
251
+ await nymph.addIndex(TestModel.ETYPE, {
252
+ scope: 'tokens',
253
+ name: 'tokenone',
254
+ property: 'search',
255
+ }),
256
+ ).toEqual(true);
257
+
258
+ expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
259
+ { scope: 'references', name: 'refone', property: 'reference' },
260
+ { scope: 'data', name: 'secondone', property: 'match' },
261
+ { scope: 'data', name: 'testindex', property: 'test' },
262
+ { scope: 'tokens', name: 'tokenone', property: 'search' },
263
+ ]);
362
264
 
363
- expect(testEntity.guid).toEqual(testGuid);
265
+ expect(
266
+ await nymph.addIndex(TestBModel.ETYPE, {
267
+ scope: 'data',
268
+ name: 'flooflab',
269
+ property: 'string',
270
+ }),
271
+ ).toEqual(true);
364
272
 
365
- // Start a new transaction with a dot in the name.
366
- transaction = await nymph.startTransaction('test.1');
367
- testEntity.$nymph = transaction;
273
+ expect(sortByName(await nymph.getIndexes(TestBModel.ETYPE))).toEqual([
274
+ { scope: 'data', name: 'flooflab', property: 'string' },
275
+ ]);
368
276
 
369
- // Verify in a transaction.
370
- expect(await transaction.inTransaction()).toEqual(true);
277
+ expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
278
+ { scope: 'references', name: 'refone', property: 'reference' },
279
+ { scope: 'data', name: 'secondone', property: 'match' },
280
+ { scope: 'data', name: 'testindex', property: 'test' },
281
+ { scope: 'tokens', name: 'tokenone', property: 'search' },
282
+ ]);
371
283
 
372
- // Make a change.
373
- testEntity.string = 'fish';
374
- expect(await testEntity.$save()).toEqual(true);
284
+ expect(
285
+ await nymph.deleteIndex(TestBModel.ETYPE, 'data', 'flooflab'),
286
+ ).toEqual(true);
375
287
 
376
- // Commit the transaction.
377
- await transaction.commit('test.1');
378
- testEntity.$nymph = nymph;
288
+ expect(await nymph.getIndexes(TestBModel.ETYPE)).toEqual([]);
379
289
 
380
- // Verify not in a transaction.
381
- expect(await transaction.inTransaction()).toEqual(false);
290
+ expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
291
+ { scope: 'references', name: 'refone', property: 'reference' },
292
+ { scope: 'data', name: 'secondone', property: 'match' },
293
+ { scope: 'data', name: 'testindex', property: 'test' },
294
+ { scope: 'tokens', name: 'tokenone', property: 'search' },
295
+ ]);
382
296
 
383
- // Verify the value is correct.
384
- await testEntity.$refresh();
385
- expect(testEntity.string).toEqual('fish');
297
+ expect(
298
+ await nymph.deleteIndex(TestModel.ETYPE, 'data', 'testindex'),
299
+ ).toEqual(true);
386
300
 
387
- // Finally, change it back.
388
- testEntity.string = 'test';
389
- expect(await testEntity.$save()).toEqual(true);
301
+ expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
302
+ { scope: 'references', name: 'refone', property: 'reference' },
303
+ { scope: 'data', name: 'secondone', property: 'match' },
304
+ { scope: 'tokens', name: 'tokenone', property: 'search' },
305
+ ]);
306
+ });
390
307
 
391
- // TODO: nested transactions
392
- });
308
+ it('transactions', async () => {
309
+ await createTestEntities();
393
310
 
394
- it('options', async () => {
395
- await createTestEntities();
311
+ // Verify not in a transaction.
312
+ expect(await nymph.inTransaction()).toEqual(false);
396
313
 
397
- // Testing entity order, offset, limit...
398
- let resultEntities = await nymph.getEntities(
399
- {
400
- class: TestModel,
401
- reverse: true,
402
- offset: 1,
403
- limit: 1,
404
- sort: 'cdate',
405
- },
406
- { type: '&', tag: 'test' },
407
- );
408
- expect(resultEntities.length).toEqual(1);
409
- expect(testEntity.$is(resultEntities[0])).toEqual(true);
410
-
411
- // Testing null sort...
412
- resultEntities = await nymph.getEntities(
413
- {
414
- class: TestModel,
415
- reverse: true,
416
- sort: null,
417
- },
418
- { type: '&', tag: 'test' },
419
- );
420
- expect(testEntity.$inArray(resultEntities)).toEqual(true);
421
- });
314
+ let transaction = await nymph.startTransaction('test');
315
+ testEntity.$nymph = transaction;
422
316
 
423
- it('guid and tags', async () => {
424
- await createTestEntities();
317
+ if (!(await transaction.inTransaction())) {
318
+ console.log(
319
+ 'This Nymph driver or database seems to not support transactions. Skipping transaction tests.',
320
+ );
321
+ await transaction.rollback('test');
322
+ return;
323
+ }
425
324
 
426
- // Retrieving entity by GUID and tags...
427
- const resultEntity = await nymph.getEntity(
428
- { class: TestModel },
429
- { type: '&', guid: testGuid, tag: 'test' },
430
- );
431
- expect(testEntity.$is(resultEntity)).toEqual(true);
432
- });
325
+ // Change a value in the test entity.
326
+ testEntity.string = 'bad value';
327
+ expect(await testEntity.$save()).toEqual(true);
433
328
 
434
- it('or selector', async () => {
435
- await createTestEntities();
329
+ // Rollback the transaction.
330
+ await transaction.rollback('test');
436
331
 
437
- // Retrieving entity by GUID and tags...
438
- const resultEntity = await nymph.getEntity(
439
- { class: TestModel },
440
- { type: '|', guid: [testGuid, guid()] },
441
- );
442
- expect(testEntity.$is(resultEntity)).toEqual(true);
443
- });
332
+ // Verify not in a transaction.
333
+ expect(await transaction.inTransaction()).toEqual(false);
444
334
 
445
- it('wrong or selector', async () => {
446
- await createTestEntities();
335
+ // Verify the value is correct.
336
+ await testEntity.$refresh();
337
+ expect(testEntity.string).toEqual('test');
447
338
 
448
- // Retrieving entity by GUID and tags...
449
- const resultEntity = await nymph.getEntity(
450
- { class: TestModel },
451
- { type: '|', guid: [guid(), guid()] },
452
- );
453
- expect(testEntity.$is(resultEntity)).toEqual(false);
454
- });
339
+ // Start a new transaction.
340
+ transaction = await nymph.startTransaction('test');
341
+ testEntity.$nymph = transaction;
455
342
 
456
- it('not guid', async () => {
457
- await createTestEntities();
343
+ // Verify in a transaction.
344
+ expect(await transaction.inTransaction()).toEqual(true);
458
345
 
459
- // Retrieving entity by !GUID...
460
- const resultEntity = await nymph.getEntities(
461
- { class: TestModel },
462
- { type: '&', '!guid': guid(), tag: 'test' },
463
- );
464
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
465
- });
346
+ // Delete the entity.
347
+ expect(await testEntity.$delete()).toEqual(true);
348
+ const resultEntity = await transaction.getEntity(
349
+ { class: TestModel },
350
+ testGuid,
351
+ );
352
+ expect(resultEntity).toBeNull();
466
353
 
467
- it('not tags', async () => {
468
- await createTestEntities();
354
+ // Rollback the transaction.
355
+ await transaction.rollback('test');
469
356
 
470
- // Retrieving entity by !tags...
471
- const resultEntity = await nymph.getEntities(
472
- { class: TestModel },
473
- { type: '&', guid: testGuid, '!tag': ['barbecue', 'pickles'] },
474
- );
475
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
476
- });
357
+ // Verify not in a transaction.
358
+ expect(await transaction.inTransaction()).toEqual(false);
477
359
 
478
- it('guid and wrong tags', async () => {
479
- await createTestEntities();
360
+ // Verify it's back.
361
+ testEntity = (await transaction.getEntity(
362
+ { class: TestModel },
363
+ testGuid,
364
+ )) as TestModelClass & TestModelData;
480
365
 
481
- // Testing GUID and wrong tags...
482
- const resultEntity = await nymph.getEntity(
483
- { class: TestModel },
484
- { type: '&', guid: testGuid, tag: ['pickles'] },
485
- );
486
- expect(resultEntity).toBeNull();
487
- });
366
+ expect(testEntity.guid).toEqual(testGuid);
488
367
 
489
- it('tags', async () => {
490
- await createTestEntities();
368
+ // Start a new transaction with a dot in the name.
369
+ transaction = await nymph.startTransaction('test.1');
370
+ testEntity.$nymph = transaction;
491
371
 
492
- // Retrieving entity by tags...
493
- const resultEntity = await nymph.getEntities(
494
- { class: TestModel },
495
- { type: '&', tag: 'test' },
496
- );
497
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
498
- });
372
+ // Verify in a transaction.
373
+ expect(await transaction.inTransaction()).toEqual(true);
499
374
 
500
- it('wrong tags', async () => {
501
- await createTestEntities();
375
+ // Make a change.
376
+ testEntity.string = 'fish';
377
+ expect(await testEntity.$save()).toEqual(true);
502
378
 
503
- // Testing wrong tags...
504
- const resultEntity = await nymph.getEntities(
505
- { class: TestModel },
506
- { type: '&', tag: 'pickles' },
507
- );
508
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
509
- });
379
+ // Commit the transaction.
380
+ await transaction.commit('test.1');
381
+ testEntity.$nymph = nymph;
510
382
 
511
- it('inclusive tags', async () => {
512
- await createTestEntities();
383
+ // Verify not in a transaction.
384
+ expect(await transaction.inTransaction()).toEqual(false);
513
385
 
514
- // Retrieving entity by tags inclusively...
515
- const resultEntity = await nymph.getEntities(
516
- { class: TestModel },
517
- { type: '|', tag: ['pickles', 'test', 'barbecue'] },
518
- );
519
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
520
- });
386
+ // Verify the value is correct.
387
+ await testEntity.$refresh();
388
+ expect(testEntity.string).toEqual('fish');
521
389
 
522
- it('wrong inclusive tags', async () => {
523
- await createTestEntities();
390
+ // Finally, change it back.
391
+ testEntity.string = 'test';
392
+ expect(await testEntity.$save()).toEqual(true);
524
393
 
525
- // Testing wrong inclusive tags...
526
- const resultEntity = await nymph.getEntities(
527
- { class: TestModel },
528
- { type: '|', tag: ['pickles', 'barbecue'] },
529
- );
530
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
531
- });
394
+ // TODO: nested transactions
395
+ });
532
396
 
533
- it('mixed tags', async () => {
534
- await createTestEntities();
397
+ it('options', async () => {
398
+ await createTestEntities();
399
+
400
+ // Testing entity order, offset, limit...
401
+ let resultEntities = await nymph.getEntities(
402
+ {
403
+ class: TestModel,
404
+ reverse: true,
405
+ offset: 1,
406
+ limit: 1,
407
+ sort: 'cdate',
408
+ },
409
+ { type: '&', tag: 'test' },
410
+ );
411
+ expect(resultEntities.length).toEqual(1);
412
+ expect(testEntity.$is(resultEntities[0])).toEqual(true);
535
413
 
536
- // Retrieving entity by mixed tags...
537
- const resultEntity = await nymph.getEntities(
538
- { class: TestModel },
539
- { type: '&', tag: 'test' },
540
- { type: '|', tag: ['pickles', 'test', 'barbecue'] },
541
- );
542
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
543
- });
414
+ // Testing null sort...
415
+ resultEntities = await nymph.getEntities(
416
+ {
417
+ class: TestModel,
418
+ reverse: true,
419
+ sort: null,
420
+ },
421
+ { type: '&', tag: 'test' },
422
+ );
423
+ expect(testEntity.$inArray(resultEntities)).toEqual(true);
424
+ });
544
425
 
545
- it('wrong inclusive mixed tags', async () => {
546
- await createTestEntities();
426
+ it('guid and tags', async () => {
427
+ await createTestEntities();
547
428
 
548
- // Testing wrong inclusive mixed tags...
549
- const resultEntity = await nymph.getEntities(
550
- { class: TestModel },
551
- { type: '&', tag: 'test' },
552
- { type: '|', tag: ['pickles', 'barbecue'] },
553
- );
554
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
555
- });
429
+ // Retrieving entity by GUID and tags...
430
+ const resultEntity = await nymph.getEntity(
431
+ { class: TestModel },
432
+ { type: '&', guid: testGuid, tag: 'test' },
433
+ );
434
+ expect(testEntity.$is(resultEntity)).toEqual(true);
435
+ });
556
436
 
557
- it('wrong exclusive mixed tags', async () => {
558
- await createTestEntities();
437
+ it('or selector', async () => {
438
+ await createTestEntities();
559
439
 
560
- // Testing wrong exclusive mixed tags...
561
- const resultEntity = await nymph.getEntities(
562
- { class: TestModel },
563
- { type: '&', tag: 'pickles' },
564
- { type: '|', tag: ['test', 'barbecue'] },
565
- );
566
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
567
- });
440
+ // Retrieving entity by GUID and tags...
441
+ const resultEntity = await nymph.getEntity(
442
+ { class: TestModel },
443
+ { type: '|', guid: [testGuid, guid()] },
444
+ );
445
+ expect(testEntity.$is(resultEntity)).toEqual(true);
446
+ });
568
447
 
569
- it('defined', async () => {
570
- await createTestEntities();
448
+ it('wrong or selector', async () => {
449
+ await createTestEntities();
571
450
 
572
- // Retrieving entity by defined...
573
- const resultEntity = await nymph.getEntities(
574
- { class: TestModel },
575
- { type: '&', defined: 'string' },
576
- );
577
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
578
- });
451
+ // Retrieving entity by GUID and tags...
452
+ const resultEntity = await nymph.getEntity(
453
+ { class: TestModel },
454
+ { type: '|', guid: [guid(), guid()] },
455
+ );
456
+ expect(testEntity.$is(resultEntity)).toEqual(false);
457
+ });
579
458
 
580
- it('not defined', async () => {
581
- await createTestEntities();
459
+ it('not guid', async () => {
460
+ await createTestEntities();
582
461
 
583
- // Retrieving entity by !defined...
584
- const resultEntity = await nymph.getEntities(
585
- { class: TestModel },
586
- { type: '&', tag: 'test', '!defined': 'pickles' },
587
- );
588
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
589
- });
462
+ // Retrieving entity by !GUID...
463
+ const resultEntity = await nymph.getEntities(
464
+ { class: TestModel },
465
+ { type: '&', '!guid': guid(), tag: 'test' },
466
+ );
467
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
468
+ });
590
469
 
591
- it('defined in a not and clause', async () => {
592
- await createTestEntities();
470
+ it('not tags', async () => {
471
+ await createTestEntities();
593
472
 
594
- // Retrieving entity by defined in not and clause...
595
- const resultEntity = await nymph.getEntities(
596
- { class: TestModel },
597
- { type: '!&', defined: 'pickles' },
598
- { type: '&', tag: 'test' },
599
- );
600
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
601
- });
473
+ // Retrieving entity by !tags...
474
+ const resultEntity = await nymph.getEntities(
475
+ { class: TestModel },
476
+ { type: '&', guid: testGuid, '!tag': ['barbecue', 'pickles'] },
477
+ );
478
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
479
+ });
602
480
 
603
- it('equal', async () => {
604
- await createTestEntities();
605
-
606
- // Retrieving entity by equal...
607
- let resultEntity = await nymph.getEntities(
608
- { class: TestModel },
609
- { type: '&', equal: ['string', 'test'] },
610
- );
611
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
612
-
613
- // Retrieving entity by equal...
614
- resultEntity = await nymph.getEntities(
615
- { class: TestModel },
616
- { type: '&', equal: ['null', null] },
617
- );
618
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
619
-
620
- // Retrieving entity by equal...
621
- resultEntity = await nymph.getEntities(
622
- { class: TestModel },
623
- { type: '&', equal: ['boolean', true] },
624
- );
625
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
626
-
627
- // Retrieving entity by equal...
628
- resultEntity = await nymph.getEntities(
629
- { class: TestModel },
630
- { type: '&', equal: ['number', 30] },
631
- );
632
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
633
-
634
- // Retrieving entity by equal...
635
- resultEntity = await nymph.getEntities(
636
- { class: TestModel },
637
- {
638
- type: '&',
639
- equal: [
640
- 'array',
641
- [
642
- 'full',
643
- 'of',
644
- 'values',
645
- 500,
646
- { test: true },
647
- { nullbyte: '\\\x00\u0000 \x00' },
648
- ],
649
- ],
650
- },
651
- );
652
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
653
-
654
- // Retrieving entity by equal...
655
- resultEntity = await nymph.getEntities(
656
- { class: TestModel },
657
- {
658
- type: '&',
659
- equal: ['match', matchValue],
660
- },
661
- );
662
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
663
- });
481
+ it('guid and wrong tags', async () => {
482
+ await createTestEntities();
664
483
 
665
- it('not equal', async () => {
666
- await createTestEntities();
484
+ // Testing GUID and wrong tags...
485
+ const resultEntity = await nymph.getEntity(
486
+ { class: TestModel },
487
+ { type: '&', guid: testGuid, tag: ['pickles'] },
488
+ );
489
+ expect(resultEntity).toBeNull();
490
+ });
667
491
 
668
- const referenceEntity = await TestModel.factory(refGuid);
669
- expect(referenceEntity.guid).toEqual(refGuid);
492
+ it('tags', async () => {
493
+ await createTestEntities();
670
494
 
671
- // Retrieving entity by !equal...
672
- const resultEntity = await nymph.getEntities(
673
- { class: TestModel },
674
- { type: '&', tag: 'test', '!equal': ['string', 'wrong'] },
675
- );
676
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
677
- expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
678
- });
495
+ // Retrieving entity by tags...
496
+ const resultEntity = await nymph.getEntities(
497
+ { class: TestModel },
498
+ { type: '&', tag: 'test' },
499
+ );
500
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
501
+ });
679
502
 
680
- it('like', async () => {
681
- await createTestEntities();
503
+ it('wrong tags', async () => {
504
+ await createTestEntities();
682
505
 
683
- // Retrieving entity by like...
684
- const resultEntity = await nymph.getEntities(
685
- { class: TestModel },
686
- { type: '&', like: ['string', 't_s%'] },
687
- );
688
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
689
- });
506
+ // Testing wrong tags...
507
+ const resultEntity = await nymph.getEntities(
508
+ { class: TestModel },
509
+ { type: '&', tag: 'pickles' },
510
+ );
511
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
512
+ });
690
513
 
691
- it('not like', async () => {
692
- await createTestEntities();
514
+ it('inclusive tags', async () => {
515
+ await createTestEntities();
693
516
 
694
- const referenceEntity = await TestModel.factory(refGuid);
695
- expect(referenceEntity.guid).toEqual(refGuid);
517
+ // Retrieving entity by tags inclusively...
518
+ const resultEntity = await nymph.getEntities(
519
+ { class: TestModel },
520
+ { type: '|', tag: ['pickles', 'test', 'barbecue'] },
521
+ );
522
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
523
+ });
696
524
 
697
- // Retrieving entity by !like...
698
- const resultEntity = await nymph.getEntities(
699
- { class: TestModel },
700
- { type: '&', tag: 'test', '!like': ['string', 'wr_n%'] },
701
- );
702
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
703
- expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
704
- });
525
+ it('wrong inclusive tags', async () => {
526
+ await createTestEntities();
705
527
 
706
- it('ilike', async () => {
707
- await createTestEntities();
528
+ // Testing wrong inclusive tags...
529
+ const resultEntity = await nymph.getEntities(
530
+ { class: TestModel },
531
+ { type: '|', tag: ['pickles', 'barbecue'] },
532
+ );
533
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
534
+ });
708
535
 
709
- // Retrieving entity by ilike...
710
- const resultEntity = await nymph.getEntities(
711
- { class: TestModel },
712
- { type: '&', ilike: ['string', 'T_s%'] },
713
- );
714
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
715
- });
536
+ it('mixed tags', async () => {
537
+ await createTestEntities();
716
538
 
717
- it('not ilike', async () => {
718
- await createTestEntities();
539
+ // Retrieving entity by mixed tags...
540
+ const resultEntity = await nymph.getEntities(
541
+ { class: TestModel },
542
+ { type: '&', tag: 'test' },
543
+ { type: '|', tag: ['pickles', 'test', 'barbecue'] },
544
+ );
545
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
546
+ });
719
547
 
720
- const referenceEntity = await TestModel.factory(refGuid);
721
- expect(referenceEntity.guid).toEqual(refGuid);
548
+ it('wrong inclusive mixed tags', async () => {
549
+ await createTestEntities();
722
550
 
723
- // Retrieving entity by !ilike...
724
- const resultEntity = await nymph.getEntities(
725
- { class: TestModel },
726
- { type: '&', tag: 'test', '!ilike': ['string', 'wr_n%'] },
727
- );
728
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
729
- expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
730
- });
551
+ // Testing wrong inclusive mixed tags...
552
+ const resultEntity = await nymph.getEntities(
553
+ { class: TestModel },
554
+ { type: '&', tag: 'test' },
555
+ { type: '|', tag: ['pickles', 'barbecue'] },
556
+ );
557
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
558
+ });
731
559
 
732
- it('like with wrong case', async () => {
733
- await createTestEntities();
560
+ it('wrong exclusive mixed tags', async () => {
561
+ await createTestEntities();
734
562
 
735
- // Retrieving entity by like...
736
- const resultEntity = await nymph.getEntities(
737
- { class: TestModel },
738
- { type: '&', like: ['string', 'T_s%'] },
739
- );
740
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
741
- });
563
+ // Testing wrong exclusive mixed tags...
564
+ const resultEntity = await nymph.getEntities(
565
+ { class: TestModel },
566
+ { type: '&', tag: 'pickles' },
567
+ { type: '|', tag: ['test', 'barbecue'] },
568
+ );
569
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
570
+ });
742
571
 
743
- it('tags and equal', async () => {
744
- await createTestEntities();
572
+ it('defined', async () => {
573
+ await createTestEntities();
745
574
 
746
- // Retrieving entity by tags and equal...
747
- const resultEntity = await nymph.getEntities(
748
- { class: TestModel },
749
- { type: '&', tag: 'test', equal: ['string', 'test'] },
750
- );
751
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
752
- });
575
+ // Retrieving entity by defined...
576
+ const resultEntity = await nymph.getEntities(
577
+ { class: TestModel },
578
+ { type: '&', defined: 'string' },
579
+ );
580
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
581
+ });
753
582
 
754
- it('wrong tags right equal', async () => {
755
- await createTestEntities();
583
+ it('not defined', async () => {
584
+ await createTestEntities();
756
585
 
757
- // Testing wrong tags and right equal...
758
- const resultEntity = await nymph.getEntities(
759
- { class: TestModel },
760
- { type: '&', tag: 'pickles', equal: ['string', 'test'] },
761
- );
762
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
763
- });
586
+ // Retrieving entity by !defined...
587
+ const resultEntity = await nymph.getEntities(
588
+ { class: TestModel },
589
+ { type: '&', tag: 'test', '!defined': 'pickles' },
590
+ );
591
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
592
+ });
764
593
 
765
- it('right tags wrong equal', async () => {
766
- await createTestEntities();
594
+ it('defined in a not and clause', async () => {
595
+ await createTestEntities();
767
596
 
768
- // Testing right tags and wrong equal...
769
- const resultEntity = await nymph.getEntities(
770
- { class: TestModel },
771
- { type: '&', tag: 'test', equal: ['string', 'pickles'] },
772
- );
773
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
774
- });
597
+ // Retrieving entity by defined in not and clause...
598
+ const resultEntity = await nymph.getEntities(
599
+ { class: TestModel },
600
+ { type: '!&', defined: 'pickles' },
601
+ { type: '&', tag: 'test' },
602
+ );
603
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
604
+ });
775
605
 
776
- it('wrong tags wrong equal', async () => {
777
- await createTestEntities();
606
+ it('equal', async () => {
607
+ await createTestEntities();
778
608
 
779
- // Testing wrong tags and wrong equal...
780
- const resultEntity = await nymph.getEntities(
781
- { class: TestModel },
782
- { type: '&', tag: 'pickles', equal: ['string', 'pickles'] },
783
- );
784
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
785
- });
609
+ // Retrieving entity by equal...
610
+ let resultEntity = await nymph.getEntities(
611
+ { class: TestModel },
612
+ { type: '&', equal: ['string', 'test'] },
613
+ );
614
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
786
615
 
787
- it('contain', async () => {
788
- await createTestEntities();
789
-
790
- // Retrieving entity by contain...
791
- let resultEntity = await nymph.getEntities(
792
- { class: TestModel },
793
- { type: '&', contain: ['array', 'values'] },
794
- );
795
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
796
-
797
- // Retrieving entity by contain...
798
- resultEntity = await nymph.getEntities(
799
- { class: TestModel },
800
- { type: '&', contain: ['array', 500] },
801
- );
802
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
803
-
804
- // Retrieving entity by contain...
805
- resultEntity = await nymph.getEntities(
806
- { class: TestModel },
807
- { type: '&', contain: ['array', { test: true }] },
808
- );
809
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
810
- });
616
+ // Retrieving entity by equal...
617
+ resultEntity = await nymph.getEntities(
618
+ { class: TestModel },
619
+ { type: '&', equal: ['null', null] },
620
+ );
621
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
811
622
 
812
- it('not contain', async () => {
813
- await createTestEntities();
623
+ // Retrieving entity by equal...
624
+ resultEntity = await nymph.getEntities(
625
+ { class: TestModel },
626
+ { type: '&', equal: ['boolean', true] },
627
+ );
628
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
814
629
 
815
- // Retrieving entity by !contain...
816
- const resultEntity = await nymph.getEntities(
817
- { class: TestModel },
818
- { type: '&', tag: 'test' },
819
- { type: '!&', contain: ['array', 'pickles'] },
820
- );
821
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
822
- });
630
+ // Retrieving entity by equal...
631
+ resultEntity = await nymph.getEntities(
632
+ { class: TestModel },
633
+ { type: '&', equal: ['number', 30] },
634
+ );
635
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
823
636
 
824
- it('wrong contain', async () => {
825
- await createTestEntities();
826
-
827
- // Testing wrong contain...
828
- let resultEntity = await nymph.getEntities(
829
- { class: TestModel },
830
- { type: '&', contain: ['array', 'pickles'] },
831
- );
832
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
833
-
834
- // Testing wrong contain...
835
- resultEntity = await nymph.getEntities(
836
- { class: TestModel },
837
- { type: '&', contain: ['string', 'pickles'] },
838
- );
839
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
840
- });
637
+ // Retrieving entity by equal...
638
+ resultEntity = await nymph.getEntities(
639
+ { class: TestModel },
640
+ {
641
+ type: '&',
642
+ equal: [
643
+ 'array',
644
+ [
645
+ 'full',
646
+ 'of',
647
+ 'values',
648
+ 500,
649
+ { test: true },
650
+ { nullbyte: '\\\x00\u0000 \x00' },
651
+ ],
652
+ ],
653
+ },
654
+ );
655
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
841
656
 
842
- it('match', async () => {
843
- await createTestEntities();
844
-
845
- // Retrieving entity by regex match...
846
- let resultEntity = await nymph.getEntities(
847
- { class: TestModel },
848
- { type: '&', match: ['match', '.*'] }, // anything
849
- );
850
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
851
- resultEntity = await nymph.getEntities(
852
- { class: TestModel },
853
- { type: '&', tag: 'test', match: ['match', 'Edward McCheese'] }, // a substring
854
- );
855
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
856
- resultEntity = await nymph.getEntities(
857
- { class: TestModel },
858
- { type: '&', tag: 'test' },
859
- {
860
- type: '|',
861
- match: [
862
- ['string', '[0-9]'],
863
- ['match', 'Edward McCheese'],
864
- ],
865
- }, // inclusive test
866
- );
867
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
868
- resultEntity = await nymph.getEntities(
869
- { class: TestModel },
870
- {
871
- type: '&',
872
- tag: 'test',
873
- match: ['match', '[-a-zA-Z0-9+_]+@[-a-zA-Z0-9_]+.[-a-zA-Z0-9_]{2,4}'],
874
- }, // a simple email
875
- );
876
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
877
- resultEntity = await nymph.getEntities(
878
- { class: TestModel },
879
- {
880
- type: '&',
881
- tag: 'test',
882
- match: ['match', '\\([0-9]{3}\\) [0-9]{3}-[0-9]{4}'],
883
- }, // a phone number
884
- );
885
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
886
- });
657
+ // Retrieving entity by equal...
658
+ resultEntity = await nymph.getEntities(
659
+ { class: TestModel },
660
+ {
661
+ type: '&',
662
+ equal: ['match', matchValue],
663
+ },
664
+ );
665
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
666
+ });
887
667
 
888
- it('imatch', async () => {
889
- await createTestEntities();
668
+ it('not equal', async () => {
669
+ await createTestEntities();
890
670
 
891
- // Retrieving entity by regex match...
892
- const resultEntity = await nymph.getEntities(
893
- { class: TestModel },
894
- { type: '&', tag: 'test', imatch: ['match', 'edward mccheese'] }, // a substring
895
- );
896
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
897
- });
671
+ const referenceEntity = await TestModel.factory(refGuid);
672
+ expect(referenceEntity.guid).toEqual(refGuid);
898
673
 
899
- it('wrong match', async () => {
900
- await createTestEntities();
901
-
902
- // Testing wrong regex match...
903
- let resultEntity = await nymph.getEntities(
904
- { class: TestModel },
905
- { type: '&', match: ['match', '='] },
906
- );
907
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
908
- resultEntity = await nymph.getEntities(
909
- { class: TestModel },
910
- { type: '&', tag: 'pickle', match: ['match', '.*'] },
911
- );
912
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
913
- resultEntity = await nymph.getEntities(
914
- { class: TestModel },
915
- {
916
- type: '|',
917
- match: [
918
- ['string', '[0-9]'],
919
- ['match', ',,'],
920
- ],
921
- },
922
- );
923
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
924
- });
674
+ // Retrieving entity by !equal...
675
+ const resultEntity = await nymph.getEntities(
676
+ { class: TestModel },
677
+ { type: '&', tag: 'test', '!equal': ['string', 'wrong'] },
678
+ );
679
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
680
+ expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
681
+ });
925
682
 
926
- it('match wrong case', async () => {
927
- await createTestEntities();
683
+ it('like', async () => {
684
+ await createTestEntities();
928
685
 
929
- // Retrieving entity by regex match...
930
- const resultEntity = await nymph.getEntities(
931
- { class: TestModel },
932
- { type: '&', tag: 'test', match: ['match', 'edward mccheese'] }, // a substring
933
- );
934
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
935
- });
686
+ // Retrieving entity by like...
687
+ const resultEntity = await nymph.getEntities(
688
+ { class: TestModel },
689
+ { type: '&', like: ['string', 't_s%'] },
690
+ );
691
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
692
+ });
936
693
 
937
- it('match and equal inclusive', async () => {
938
- await createTestEntities();
694
+ it('not like', async () => {
695
+ await createTestEntities();
939
696
 
940
- // Retrieving entity by regex + equal inclusively...
941
- const resultEntity = await nymph.getEntities(
942
- { class: TestModel },
943
- { type: '&', tag: 'test' },
944
- { type: '|', equal: ['string', 'pickles'], match: ['string', 'test'] },
945
- );
946
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
947
- });
697
+ const referenceEntity = await TestModel.factory(refGuid);
698
+ expect(referenceEntity.guid).toEqual(refGuid);
948
699
 
949
- it('basic search', async () => {
950
- await createTestEntities();
951
-
952
- // Retrieving entity by full text search...
953
- let resultEntity = await nymph.getEntities(
954
- { class: TestModel },
955
- {
956
- type: '&',
957
- tag: 'test',
958
- search: [
959
- 'search',
960
- 'Declaration of the thirteen united States of America',
961
- ],
962
- }, // a substring
963
- );
964
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
965
- resultEntity = await nymph.getEntities(
966
- { class: TestModel },
967
- { type: '&', tag: 'test' },
968
- {
969
- type: '|',
970
- search: [
971
- ['string', 'pickle'],
972
- ['search', 'Declaration of the thirteen united States of America'],
973
- ],
974
- }, // inclusive test
975
- );
976
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
977
- resultEntity = await nymph.getEntities(
978
- { class: TestModel },
979
- {
980
- type: '&',
981
- tag: 'test',
982
- search: ['search', 'July 4, 1776'],
983
- }, // a string with a number
984
- );
985
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
986
- });
700
+ // Retrieving entity by !like...
701
+ const resultEntity = await nymph.getEntities(
702
+ { class: TestModel },
703
+ { type: '&', tag: 'test', '!like': ['string', 'wr_n%'] },
704
+ );
705
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
706
+ expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
707
+ });
987
708
 
988
- it('or search', async () => {
989
- await createTestEntities();
990
-
991
- // Retrieving entity by full text search...
992
- let resultEntity = await nymph.getEntities(
993
- { class: TestModel },
994
- {
995
- type: '&',
996
- tag: 'test',
997
- search: ['search', 'Declaration or pickles'],
998
- }, // a string with an or
999
- );
1000
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1001
- });
709
+ it('ilike', async () => {
710
+ await createTestEntities();
1002
711
 
1003
- it('series search', async () => {
1004
- await createTestEntities();
1005
-
1006
- // Retrieving entity by full text search...
1007
- let resultEntity = await nymph.getEntities(
1008
- { class: TestModel },
1009
- {
1010
- type: '&',
1011
- tag: 'test',
1012
- search: ['search', '"excited domestic insurrections"'],
1013
- }, // double quoted substring
1014
- );
1015
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1016
- resultEntity = await nymph.getEntities(
1017
- { class: TestModel },
1018
- {
1019
- type: '&',
1020
- tag: 'test',
1021
- search: ['search', "'exciting domestic insurrected'"],
1022
- }, // single quoted substring
1023
- );
1024
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1025
- });
712
+ // Retrieving entity by ilike...
713
+ const resultEntity = await nymph.getEntities(
714
+ { class: TestModel },
715
+ { type: '&', ilike: ['string', 'T_s%'] },
716
+ );
717
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
718
+ });
1026
719
 
1027
- it('negated search', async () => {
1028
- await createTestEntities();
1029
-
1030
- // Retrieving entity by full text search...
1031
- let resultEntity = await nymph.getEntities(
1032
- { class: TestModel },
1033
- {
1034
- type: '&',
1035
- tag: 'test',
1036
- search: ['search', '-pickle'],
1037
- }, // negated term
1038
- );
1039
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1040
- });
720
+ it('not ilike', async () => {
721
+ await createTestEntities();
1041
722
 
1042
- it('combined search', async () => {
1043
- await createTestEntities();
1044
-
1045
- // Retrieving entity by full text search...
1046
- let resultEntity = await nymph.getEntities(
1047
- { class: TestModel },
1048
- {
1049
- type: '&',
1050
- tag: 'test',
1051
- search: ['search', 'Declaration -pickle'],
1052
- }, // negated term with positive term
1053
- );
1054
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1055
- resultEntity = await nymph.getEntities(
1056
- { class: TestModel },
1057
- {
1058
- type: '&',
1059
- tag: 'test',
1060
- search: ['search', 'Declaration "General Congress"'],
1061
- }, // terms found in separate areas
1062
- );
1063
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1064
- });
723
+ const referenceEntity = await TestModel.factory(refGuid);
724
+ expect(referenceEntity.guid).toEqual(refGuid);
1065
725
 
1066
- it('wrong search', async () => {
1067
- await createTestEntities();
1068
-
1069
- // Testing wrong search...
1070
- let resultEntity = await nymph.getEntities(
1071
- { class: TestModel },
1072
- { type: '&', search: ['search', 'pickles'] },
1073
- );
1074
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1075
- resultEntity = await nymph.getEntities(
1076
- { class: TestModel },
1077
- { type: '&', tag: 'pickle', search: ['search', 'Declaration'] },
1078
- );
1079
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1080
- resultEntity = await nymph.getEntities(
1081
- { class: TestModel },
1082
- {
1083
- type: '|',
1084
- search: [
1085
- ['string', 'pickle'],
1086
- ['search', 'Hawaii'],
1087
- ],
1088
- },
1089
- );
1090
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1091
- });
726
+ // Retrieving entity by !ilike...
727
+ const resultEntity = await nymph.getEntities(
728
+ { class: TestModel },
729
+ { type: '&', tag: 'test', '!ilike': ['string', 'wr_n%'] },
730
+ );
731
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
732
+ expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
733
+ });
1092
734
 
1093
- it('search with only stop words', async () => {
1094
- await createTestEntities();
735
+ it('like with wrong case', async () => {
736
+ await createTestEntities();
1095
737
 
1096
- // Testing wrong search...
1097
- let resultEntity = await nymph.getEntities(
1098
- { class: TestModel },
1099
- { type: '&', search: ['search', 'i am'] },
1100
- );
1101
- expect(resultEntity).toEqual([]);
1102
- });
738
+ // Retrieving entity by like...
739
+ const resultEntity = await nymph.getEntities(
740
+ { class: TestModel },
741
+ { type: '&', like: ['string', 'T_s%'] },
742
+ );
743
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
744
+ });
1103
745
 
1104
- it('search must be case insensitive', async () => {
1105
- await createTestEntities();
1106
-
1107
- // Retrieving entity by full text search...
1108
- const resultEntity = await nymph.getEntities(
1109
- { class: TestModel },
1110
- {
1111
- type: '&',
1112
- tag: 'test',
1113
- search: [
1114
- 'search',
1115
- 'DECLARATION OF THE THIRTEEN UNITED STATES OF AMERICA',
1116
- ],
1117
- }, // a substring
1118
- );
1119
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1120
- });
746
+ it('tags and equal', async () => {
747
+ await createTestEntities();
1121
748
 
1122
- it('search and equal inclusive', async () => {
1123
- await createTestEntities();
749
+ // Retrieving entity by tags and equal...
750
+ const resultEntity = await nymph.getEntities(
751
+ { class: TestModel },
752
+ { type: '&', tag: 'test', equal: ['string', 'test'] },
753
+ );
754
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
755
+ });
1124
756
 
1125
- // Retrieving entity by fts + equal inclusively...
1126
- const resultEntity = await nymph.getEntities(
1127
- { class: TestModel },
1128
- { type: '&', tag: 'test' },
1129
- { type: '|', equal: ['string', 'pickles'], search: ['string', 'test'] },
1130
- );
1131
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1132
- });
757
+ it('wrong tags right equal', async () => {
758
+ await createTestEntities();
1133
759
 
1134
- it('greater than', async () => {
1135
- await createTestEntities();
1136
-
1137
- // Retrieving entity by inequality...
1138
- let resultEntity = await nymph.getEntities(
1139
- { class: TestModel },
1140
- {
1141
- type: '|',
1142
- gt: [
1143
- ['number', 30],
1144
- ['pickles', 100],
1145
- ],
1146
- },
1147
- );
1148
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1149
-
1150
- // Retrieving entity by inequality...
1151
- resultEntity = await nymph.getEntities(
1152
- { class: TestModel },
1153
- {
1154
- type: '|',
1155
- gt: [
1156
- ['number', 31],
1157
- ['pickles', 100],
1158
- ],
1159
- },
1160
- );
1161
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1162
-
1163
- // Retrieving entity by inequality...
1164
- resultEntity = await nymph.getEntities(
1165
- { class: TestModel },
1166
- {
1167
- type: '|',
1168
- gt: [
1169
- ['number', 29],
1170
- ['pickles', 100],
1171
- ],
1172
- },
1173
- );
1174
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1175
-
1176
- // Retrieving entity by inequality...
1177
- resultEntity = await nymph.getEntities(
1178
- { class: TestModel },
1179
- {
1180
- type: '|',
1181
- gt: [
1182
- ['numberString', 30],
1183
- ['pickles', 100],
1184
- ],
1185
- },
1186
- );
1187
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1188
-
1189
- // Retrieving entity by inequality...
1190
- resultEntity = await nymph.getEntities(
1191
- { class: TestModel },
1192
- {
1193
- type: '|',
1194
- gt: [
1195
- ['numberString', 31],
1196
- ['pickles', 100],
1197
- ],
1198
- },
1199
- );
1200
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1201
-
1202
- // Retrieving entity by inequality...
1203
- resultEntity = await nymph.getEntities(
1204
- { class: TestModel },
1205
- {
1206
- type: '|',
1207
- gt: [
1208
- ['numberString', 29],
1209
- ['pickles', 100],
1210
- ],
1211
- },
1212
- );
1213
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1214
- });
760
+ // Testing wrong tags and right equal...
761
+ const resultEntity = await nymph.getEntities(
762
+ { class: TestModel },
763
+ { type: '&', tag: 'pickles', equal: ['string', 'test'] },
764
+ );
765
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
766
+ });
1215
767
 
1216
- it('greater than or equal', async () => {
1217
- await createTestEntities();
1218
-
1219
- // Retrieving entity by inequality...
1220
- let resultEntity = await nymph.getEntities(
1221
- { class: TestModel },
1222
- {
1223
- type: '|',
1224
- gte: [
1225
- ['number', 30],
1226
- ['pickles', 100],
1227
- ],
1228
- },
1229
- );
1230
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1231
-
1232
- // Retrieving entity by inequality...
1233
- resultEntity = await nymph.getEntities(
1234
- { class: TestModel },
1235
- {
1236
- type: '|',
1237
- gte: [
1238
- ['number', 31],
1239
- ['pickles', 100],
1240
- ],
1241
- },
1242
- );
1243
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1244
-
1245
- // Retrieving entity by inequality...
1246
- resultEntity = await nymph.getEntities(
1247
- { class: TestModel },
1248
- {
1249
- type: '|',
1250
- gte: [
1251
- ['number', 29],
1252
- ['pickles', 100],
1253
- ],
1254
- },
1255
- );
1256
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1257
-
1258
- // Retrieving entity by inequality...
1259
- resultEntity = await nymph.getEntities(
1260
- { class: TestModel },
1261
- {
1262
- type: '|',
1263
- gte: [
1264
- ['numberString', 30],
1265
- ['pickles', 100],
1266
- ],
1267
- },
1268
- );
1269
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1270
-
1271
- // Retrieving entity by inequality...
1272
- resultEntity = await nymph.getEntities(
1273
- { class: TestModel },
1274
- {
1275
- type: '|',
1276
- gte: [
1277
- ['numberString', 31],
1278
- ['pickles', 100],
1279
- ],
1280
- },
1281
- );
1282
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1283
-
1284
- // Retrieving entity by inequality...
1285
- resultEntity = await nymph.getEntities(
1286
- { class: TestModel },
1287
- {
1288
- type: '|',
1289
- gte: [
1290
- ['numberString', 29],
1291
- ['pickles', 100],
1292
- ],
1293
- },
1294
- );
1295
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1296
- });
768
+ it('right tags wrong equal', async () => {
769
+ await createTestEntities();
1297
770
 
1298
- it('less than', async () => {
1299
- await createTestEntities();
1300
-
1301
- // Retrieving entity by inequality...
1302
- let resultEntity = await nymph.getEntities(
1303
- { class: TestModel },
1304
- {
1305
- type: '|',
1306
- lt: [
1307
- ['number', 30],
1308
- ['pickles', 100],
1309
- ],
1310
- },
1311
- );
1312
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1313
-
1314
- // Retrieving entity by inequality...
1315
- resultEntity = await nymph.getEntities(
1316
- { class: TestModel },
1317
- {
1318
- type: '|',
1319
- lt: [
1320
- ['number', 31],
1321
- ['pickles', 100],
1322
- ],
1323
- },
1324
- );
1325
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1326
-
1327
- // Retrieving entity by inequality...
1328
- resultEntity = await nymph.getEntities(
1329
- { class: TestModel },
1330
- {
1331
- type: '|',
1332
- lt: [
1333
- ['number', 29],
1334
- ['pickles', 100],
1335
- ],
1336
- },
1337
- );
1338
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1339
-
1340
- // Retrieving entity by inequality...
1341
- resultEntity = await nymph.getEntities(
1342
- { class: TestModel },
1343
- {
1344
- type: '|',
1345
- lt: [
1346
- ['numberString', 30],
1347
- ['pickles', 100],
1348
- ],
1349
- },
1350
- );
1351
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1352
-
1353
- // Retrieving entity by inequality...
1354
- resultEntity = await nymph.getEntities(
1355
- { class: TestModel },
1356
- {
1357
- type: '|',
1358
- lt: [
1359
- ['numberString', 31],
1360
- ['pickles', 100],
1361
- ],
1362
- },
1363
- );
1364
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1365
-
1366
- // Retrieving entity by inequality...
1367
- resultEntity = await nymph.getEntities(
1368
- { class: TestModel },
1369
- {
1370
- type: '|',
1371
- lt: [
1372
- ['numberString', 29],
1373
- ['pickles', 100],
1374
- ],
1375
- },
1376
- );
1377
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1378
- });
771
+ // Testing right tags and wrong equal...
772
+ const resultEntity = await nymph.getEntities(
773
+ { class: TestModel },
774
+ { type: '&', tag: 'test', equal: ['string', 'pickles'] },
775
+ );
776
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
777
+ });
1379
778
 
1380
- it('less than or equal', async () => {
1381
- await createTestEntities();
1382
-
1383
- // Retrieving entity by inequality...
1384
- let resultEntity = await nymph.getEntities(
1385
- { class: TestModel },
1386
- {
1387
- type: '|',
1388
- lte: [
1389
- ['number', 30],
1390
- ['pickles', 100],
1391
- ],
1392
- },
1393
- );
1394
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1395
-
1396
- // Retrieving entity by inequality...
1397
- resultEntity = await nymph.getEntities(
1398
- { class: TestModel },
1399
- {
1400
- type: '|',
1401
- lte: [
1402
- ['number', 31],
1403
- ['pickles', 100],
1404
- ],
1405
- },
1406
- );
1407
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1408
-
1409
- // Retrieving entity by inequality...
1410
- resultEntity = await nymph.getEntities(
1411
- { class: TestModel },
1412
- {
1413
- type: '|',
1414
- lte: [
1415
- ['number', 29],
1416
- ['pickles', 100],
1417
- ],
1418
- },
1419
- );
1420
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1421
-
1422
- // Retrieving entity by inequality...
1423
- resultEntity = await nymph.getEntities(
1424
- { class: TestModel },
1425
- {
1426
- type: '|',
1427
- lte: [
1428
- ['numberString', 30],
1429
- ['pickles', 100],
1430
- ],
1431
- },
1432
- );
1433
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1434
-
1435
- // Retrieving entity by inequality...
1436
- resultEntity = await nymph.getEntities(
1437
- { class: TestModel },
1438
- {
1439
- type: '|',
1440
- lte: [
1441
- ['numberString', 31],
1442
- ['pickles', 100],
1443
- ],
1444
- },
1445
- );
1446
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1447
-
1448
- // Retrieving entity by inequality...
1449
- resultEntity = await nymph.getEntities(
1450
- { class: TestModel },
1451
- {
1452
- type: '|',
1453
- lte: [
1454
- ['numberString', 29],
1455
- ['pickles', 100],
1456
- ],
1457
- },
1458
- );
1459
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1460
- });
779
+ it('wrong tags wrong equal', async () => {
780
+ await createTestEntities();
1461
781
 
1462
- it('not inequality', async () => {
1463
- await createTestEntities();
782
+ // Testing wrong tags and wrong equal...
783
+ const resultEntity = await nymph.getEntities(
784
+ { class: TestModel },
785
+ { type: '&', tag: 'pickles', equal: ['string', 'pickles'] },
786
+ );
787
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
788
+ });
1464
789
 
1465
- // Retrieving entity by !inequality...
1466
- const resultEntity = await nymph.getEntities(
1467
- { class: TestModel },
1468
- { type: '&', tag: 'test' },
1469
- { type: '!&', gte: ['number', 60] },
1470
- );
1471
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1472
- });
790
+ it('contain', async () => {
791
+ await createTestEntities();
1473
792
 
1474
- it('wrong inequality', async () => {
1475
- await createTestEntities();
793
+ // Retrieving entity by contain...
794
+ let resultEntity = await nymph.getEntities(
795
+ { class: TestModel },
796
+ { type: '&', contain: ['array', 'values'] },
797
+ );
798
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1476
799
 
1477
- // Testing wrong inequality...
1478
- const resultEntity = await nymph.getEntities(
1479
- { class: TestModel },
1480
- { type: '&', lte: ['number', 29.99] },
1481
- );
1482
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1483
- });
800
+ // Retrieving entity by contain...
801
+ resultEntity = await nymph.getEntities(
802
+ { class: TestModel },
803
+ { type: '&', contain: ['array', 500] },
804
+ );
805
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1484
806
 
1485
- it('greater than cdate', async () => {
1486
- await createTestEntities();
807
+ // Retrieving entity by contain...
808
+ resultEntity = await nymph.getEntities(
809
+ { class: TestModel },
810
+ { type: '&', contain: ['array', { test: true }] },
811
+ );
812
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
813
+ });
1487
814
 
1488
- // Retrieving entity by time...
1489
- const resultEntity = await nymph.getEntities(
1490
- { class: TestModel },
1491
- { type: '&', tag: 'test', gt: ['cdate', (testEntity.cdate ?? 0) - 120] },
1492
- );
1493
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1494
- });
815
+ it('not contain', async () => {
816
+ await createTestEntities();
1495
817
 
1496
- it('wrong cdate', async () => {
1497
- await createTestEntities();
818
+ // Retrieving entity by !contain...
819
+ const resultEntity = await nymph.getEntities(
820
+ { class: TestModel },
821
+ { type: '&', tag: 'test' },
822
+ { type: '!&', contain: ['array', 'pickles'] },
823
+ );
824
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
825
+ });
1498
826
 
1499
- // Testing wrong time...
1500
- const resultEntity = await nymph.getEntities(
1501
- { class: TestModel },
1502
- { type: '&', tag: 'test', gte: ['cdate', (testEntity.cdate ?? 0) + 1] },
1503
- );
1504
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1505
- });
827
+ it('wrong contain', async () => {
828
+ await createTestEntities();
1506
829
 
1507
- it('time selector', async () => {
1508
- await createTestEntities();
1509
-
1510
- const referenceEntity = await TestModel.factory(refGuid);
1511
-
1512
- // Retrieving entity by relative time...
1513
- let resultEntity = await nymph.getEntities(
1514
- { class: TestModel },
1515
- { type: '&', gt: ['timestamp', null, '-1 day'] },
1516
- );
1517
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1518
- expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
1519
-
1520
- // Retrieving entity by relative time inclusively...
1521
- resultEntity = await nymph.getEntities(
1522
- { class: TestModel },
1523
- {
1524
- type: '|',
1525
- gt: [
1526
- ['timestamp', null, '-1 day'],
1527
- ['timestamp', null, '+5 days'],
1528
- ],
1529
- },
1530
- );
1531
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1532
- expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
1533
-
1534
- // Retrieving entity by relative time...
1535
- resultEntity = await nymph.getEntities(
1536
- { class: TestModel },
1537
- { type: '&', gt: ['timestamp', null, '-3 days'] },
1538
- );
1539
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1540
- expect(referenceEntity.$inArray(resultEntity)).toEqual(true);
1541
-
1542
- // Retrieving entity by relative time...
1543
- resultEntity = await nymph.getEntities(
1544
- { class: TestModel },
1545
- { type: '&', gt: ['cdate', null, '-1 day'] },
1546
- );
1547
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1548
- expect(referenceEntity.$inArray(resultEntity)).toEqual(true);
1549
- });
830
+ // Testing wrong contain...
831
+ let resultEntity = await nymph.getEntities(
832
+ { class: TestModel },
833
+ { type: '&', contain: ['array', 'pickles'] },
834
+ );
835
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1550
836
 
1551
- it('wrong time selector', async () => {
1552
- await createTestEntities();
1553
-
1554
- const referenceEntity = await TestModel.factory(refGuid);
1555
-
1556
- // Retrieving entity by relative time...
1557
- let resultEntity = await nymph.getEntities(
1558
- { class: TestModel },
1559
- { type: '&', tag: 'test', gt: ['timestamp', null, '+1 day'] },
1560
- );
1561
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1562
- expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
1563
-
1564
- // Retrieving entity by relative time...
1565
- resultEntity = await nymph.getEntities(
1566
- { class: TestModel },
1567
- { type: '&', tag: 'test', lt: ['timestamp', null, '-3 days'] },
1568
- );
1569
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1570
- expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
1571
-
1572
- // Retrieving entity by relative time...
1573
- resultEntity = await nymph.getEntities(
1574
- { class: TestModel },
1575
- { type: '&', tag: 'test', gt: ['cdate', null, '+1 day'] },
1576
- );
1577
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1578
- expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
1579
- });
837
+ // Testing wrong contain...
838
+ resultEntity = await nymph.getEntities(
839
+ { class: TestModel },
840
+ { type: '&', contain: ['string', 'pickles'] },
841
+ );
842
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
843
+ });
1580
844
 
1581
- it('references', async () => {
1582
- await createTestEntities();
845
+ it('match', async () => {
846
+ await createTestEntities();
1583
847
 
1584
- // Testing referenced entities...
1585
- await testEntity.reference?.$wake();
1586
- expect(testEntity.reference?.test).toEqual('good');
848
+ // Retrieving entity by regex match...
849
+ let resultEntity = await nymph.getEntities(
850
+ { class: TestModel },
851
+ { type: '&', match: ['match', '.*'] }, // anything
852
+ );
853
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
854
+ resultEntity = await nymph.getEntities(
855
+ { class: TestModel },
856
+ { type: '&', tag: 'test', match: ['match', 'Edward McCheese'] }, // a substring
857
+ );
858
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
859
+ resultEntity = await nymph.getEntities(
860
+ { class: TestModel },
861
+ { type: '&', tag: 'test' },
862
+ {
863
+ type: '|',
864
+ match: [
865
+ ['string', '[0-9]'],
866
+ ['match', 'Edward McCheese'],
867
+ ],
868
+ }, // inclusive test
869
+ );
870
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
871
+ resultEntity = await nymph.getEntities(
872
+ { class: TestModel },
873
+ {
874
+ type: '&',
875
+ tag: 'test',
876
+ match: ['match', '[-a-zA-Z0-9+_]+@[-a-zA-Z0-9_]+.[-a-zA-Z0-9_]{2,4}'],
877
+ }, // a simple email
878
+ );
879
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
880
+ resultEntity = await nymph.getEntities(
881
+ { class: TestModel },
882
+ {
883
+ type: '&',
884
+ tag: 'test',
885
+ match: ['match', '\\([0-9]{3}\\) [0-9]{3}-[0-9]{4}'],
886
+ }, // a phone number
887
+ );
888
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
889
+ });
1587
890
 
1588
- // Testing referenced entity arrays...
1589
- await Promise.all(testEntity.refArray?.map((e) => e.$wake()) || []);
1590
- expect(testEntity.refArray?.[0].test).toEqual('good');
1591
- });
891
+ it('imatch', async () => {
892
+ await createTestEntities();
1592
893
 
1593
- it('ref', async () => {
1594
- await createTestEntities();
894
+ // Retrieving entity by regex match...
895
+ const resultEntity = await nymph.getEntities(
896
+ { class: TestModel },
897
+ { type: '&', tag: 'test', imatch: ['match', 'edward mccheese'] }, // a substring
898
+ );
899
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
900
+ });
1595
901
 
1596
- // Retrieving entity by reference...
1597
- const resultEntity = await nymph.getEntities(
1598
- { class: TestModel },
1599
- { type: '&', ref: ['reference', refGuid] },
1600
- );
1601
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1602
- });
902
+ it('wrong match', async () => {
903
+ await createTestEntities();
1603
904
 
1604
- it('not ref', async () => {
1605
- await createTestEntities();
905
+ // Testing wrong regex match...
906
+ let resultEntity = await nymph.getEntities(
907
+ { class: TestModel },
908
+ { type: '&', match: ['match', '='] },
909
+ );
910
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
911
+ resultEntity = await nymph.getEntities(
912
+ { class: TestModel },
913
+ { type: '&', tag: 'pickle', match: ['match', '.*'] },
914
+ );
915
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
916
+ resultEntity = await nymph.getEntities(
917
+ { class: TestModel },
918
+ {
919
+ type: '|',
920
+ match: [
921
+ ['string', '[0-9]'],
922
+ ['match', ',,'],
923
+ ],
924
+ },
925
+ );
926
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
927
+ });
928
+
929
+ it('match wrong case', async () => {
930
+ await createTestEntities();
931
+
932
+ // Retrieving entity by regex match...
933
+ const resultEntity = await nymph.getEntities(
934
+ { class: TestModel },
935
+ { type: '&', tag: 'test', match: ['match', 'edward mccheese'] }, // a substring
936
+ );
937
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
938
+ });
939
+
940
+ it('match and equal inclusive', async () => {
941
+ await createTestEntities();
942
+
943
+ // Retrieving entity by regex + equal inclusively...
944
+ const resultEntity = await nymph.getEntities(
945
+ { class: TestModel },
946
+ { type: '&', tag: 'test' },
947
+ { type: '|', equal: ['string', 'pickles'], match: ['string', 'test'] },
948
+ );
949
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
950
+ });
951
+
952
+ it('basic search', async () => {
953
+ await createTestEntities();
954
+
955
+ // Retrieving entity by full text search...
956
+ let resultEntity = await nymph.getEntities(
957
+ { class: TestModel },
958
+ {
959
+ type: '&',
960
+ tag: 'test',
961
+ search: [
962
+ 'search',
963
+ 'Declaration of the thirteen united States of America',
964
+ ],
965
+ }, // a substring
966
+ );
967
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
968
+ resultEntity = await nymph.getEntities(
969
+ { class: TestModel },
970
+ { type: '&', tag: 'test' },
971
+ {
972
+ type: '|',
973
+ search: [
974
+ ['string', 'pickle'],
975
+ ['search', 'Declaration of the thirteen united States of America'],
976
+ ],
977
+ }, // inclusive test
978
+ );
979
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
980
+ resultEntity = await nymph.getEntities(
981
+ { class: TestModel },
982
+ {
983
+ type: '&',
984
+ tag: 'test',
985
+ search: ['search', 'July 4, 1776'],
986
+ }, // a string with a number
987
+ );
988
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
989
+ });
990
+
991
+ it('or search', async () => {
992
+ await createTestEntities();
993
+
994
+ // Retrieving entity by full text search...
995
+ let resultEntity = await nymph.getEntities(
996
+ { class: TestModel },
997
+ {
998
+ type: '&',
999
+ tag: 'test',
1000
+ search: ['search', 'Declaration or pickles'],
1001
+ }, // a string with an or
1002
+ );
1003
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1004
+ });
1005
+
1006
+ it('series search', async () => {
1007
+ await createTestEntities();
1008
+
1009
+ // Retrieving entity by full text search...
1010
+ let resultEntity = await nymph.getEntities(
1011
+ { class: TestModel },
1012
+ {
1013
+ type: '&',
1014
+ tag: 'test',
1015
+ search: ['search', '"excited domestic insurrections"'],
1016
+ }, // double quoted substring
1017
+ );
1018
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1019
+ resultEntity = await nymph.getEntities(
1020
+ { class: TestModel },
1021
+ {
1022
+ type: '&',
1023
+ tag: 'test',
1024
+ search: ['search', "'exciting domestic insurrected'"],
1025
+ }, // single quoted substring
1026
+ );
1027
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1028
+ });
1029
+
1030
+ it('negated search', async () => {
1031
+ await createTestEntities();
1032
+
1033
+ // Retrieving entity by full text search...
1034
+ let resultEntity = await nymph.getEntities(
1035
+ { class: TestModel },
1036
+ {
1037
+ type: '&',
1038
+ tag: 'test',
1039
+ search: ['search', '-pickle'],
1040
+ }, // negated term
1041
+ );
1042
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1043
+ });
1044
+
1045
+ it('combined search', async () => {
1046
+ await createTestEntities();
1047
+
1048
+ // Retrieving entity by full text search...
1049
+ let resultEntity = await nymph.getEntities(
1050
+ { class: TestModel },
1051
+ {
1052
+ type: '&',
1053
+ tag: 'test',
1054
+ search: ['search', 'Declaration -pickle'],
1055
+ }, // negated term with positive term
1056
+ );
1057
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1058
+ resultEntity = await nymph.getEntities(
1059
+ { class: TestModel },
1060
+ {
1061
+ type: '&',
1062
+ tag: 'test',
1063
+ search: ['search', 'Declaration "General Congress"'],
1064
+ }, // terms found in separate areas
1065
+ );
1066
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1067
+ });
1068
+
1069
+ it('wrong search', async () => {
1070
+ await createTestEntities();
1071
+
1072
+ // Testing wrong search...
1073
+ let resultEntity = await nymph.getEntities(
1074
+ { class: TestModel },
1075
+ { type: '&', search: ['search', 'pickles'] },
1076
+ );
1077
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1078
+ resultEntity = await nymph.getEntities(
1079
+ { class: TestModel },
1080
+ { type: '&', tag: 'pickle', search: ['search', 'Declaration'] },
1081
+ );
1082
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1083
+ resultEntity = await nymph.getEntities(
1084
+ { class: TestModel },
1085
+ {
1086
+ type: '|',
1087
+ search: [
1088
+ ['string', 'pickle'],
1089
+ ['search', 'Hawaii'],
1090
+ ],
1091
+ },
1092
+ );
1093
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1094
+ });
1095
+
1096
+ it('search with only stop words', async () => {
1097
+ await createTestEntities();
1098
+
1099
+ // Testing wrong search...
1100
+ let resultEntity = await nymph.getEntities(
1101
+ { class: TestModel },
1102
+ { type: '&', search: ['search', 'i am'] },
1103
+ );
1104
+ expect(resultEntity).toEqual([]);
1105
+ });
1106
+
1107
+ it('search must be case insensitive', async () => {
1108
+ await createTestEntities();
1109
+
1110
+ // Retrieving entity by full text search...
1111
+ const resultEntity = await nymph.getEntities(
1112
+ { class: TestModel },
1113
+ {
1114
+ type: '&',
1115
+ tag: 'test',
1116
+ search: [
1117
+ 'search',
1118
+ 'DECLARATION OF THE THIRTEEN UNITED STATES OF AMERICA',
1119
+ ],
1120
+ }, // a substring
1121
+ );
1122
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1123
+ });
1124
+
1125
+ it('search and equal inclusive', async () => {
1126
+ await createTestEntities();
1127
+
1128
+ // Retrieving entity by fts + equal inclusively...
1129
+ const resultEntity = await nymph.getEntities(
1130
+ { class: TestModel },
1131
+ { type: '&', tag: 'test' },
1132
+ { type: '|', equal: ['string', 'pickles'], search: ['string', 'test'] },
1133
+ );
1134
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1135
+ });
1136
+
1137
+ it('greater than', async () => {
1138
+ await createTestEntities();
1139
+
1140
+ // Retrieving entity by inequality...
1141
+ let resultEntity = await nymph.getEntities(
1142
+ { class: TestModel },
1143
+ {
1144
+ type: '|',
1145
+ gt: [
1146
+ ['number', 30],
1147
+ ['pickles', 100],
1148
+ ],
1149
+ },
1150
+ );
1151
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1152
+
1153
+ // Retrieving entity by inequality...
1154
+ resultEntity = await nymph.getEntities(
1155
+ { class: TestModel },
1156
+ {
1157
+ type: '|',
1158
+ gt: [
1159
+ ['number', 31],
1160
+ ['pickles', 100],
1161
+ ],
1162
+ },
1163
+ );
1164
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1165
+
1166
+ // Retrieving entity by inequality...
1167
+ resultEntity = await nymph.getEntities(
1168
+ { class: TestModel },
1169
+ {
1170
+ type: '|',
1171
+ gt: [
1172
+ ['number', 29],
1173
+ ['pickles', 100],
1174
+ ],
1175
+ },
1176
+ );
1177
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1178
+
1179
+ // Retrieving entity by inequality...
1180
+ resultEntity = await nymph.getEntities(
1181
+ { class: TestModel },
1182
+ {
1183
+ type: '|',
1184
+ gt: [
1185
+ ['numberString', 30],
1186
+ ['pickles', 100],
1187
+ ],
1188
+ },
1189
+ );
1190
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1191
+
1192
+ // Retrieving entity by inequality...
1193
+ resultEntity = await nymph.getEntities(
1194
+ { class: TestModel },
1195
+ {
1196
+ type: '|',
1197
+ gt: [
1198
+ ['numberString', 31],
1199
+ ['pickles', 100],
1200
+ ],
1201
+ },
1202
+ );
1203
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1204
+
1205
+ // Retrieving entity by inequality...
1206
+ resultEntity = await nymph.getEntities(
1207
+ { class: TestModel },
1208
+ {
1209
+ type: '|',
1210
+ gt: [
1211
+ ['numberString', 29],
1212
+ ['pickles', 100],
1213
+ ],
1214
+ },
1215
+ );
1216
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1217
+ });
1218
+
1219
+ it('greater than or equal', async () => {
1220
+ await createTestEntities();
1221
+
1222
+ // Retrieving entity by inequality...
1223
+ let resultEntity = await nymph.getEntities(
1224
+ { class: TestModel },
1225
+ {
1226
+ type: '|',
1227
+ gte: [
1228
+ ['number', 30],
1229
+ ['pickles', 100],
1230
+ ],
1231
+ },
1232
+ );
1233
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1234
+
1235
+ // Retrieving entity by inequality...
1236
+ resultEntity = await nymph.getEntities(
1237
+ { class: TestModel },
1238
+ {
1239
+ type: '|',
1240
+ gte: [
1241
+ ['number', 31],
1242
+ ['pickles', 100],
1243
+ ],
1244
+ },
1245
+ );
1246
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1247
+
1248
+ // Retrieving entity by inequality...
1249
+ resultEntity = await nymph.getEntities(
1250
+ { class: TestModel },
1251
+ {
1252
+ type: '|',
1253
+ gte: [
1254
+ ['number', 29],
1255
+ ['pickles', 100],
1256
+ ],
1257
+ },
1258
+ );
1259
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1260
+
1261
+ // Retrieving entity by inequality...
1262
+ resultEntity = await nymph.getEntities(
1263
+ { class: TestModel },
1264
+ {
1265
+ type: '|',
1266
+ gte: [
1267
+ ['numberString', 30],
1268
+ ['pickles', 100],
1269
+ ],
1270
+ },
1271
+ );
1272
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1273
+
1274
+ // Retrieving entity by inequality...
1275
+ resultEntity = await nymph.getEntities(
1276
+ { class: TestModel },
1277
+ {
1278
+ type: '|',
1279
+ gte: [
1280
+ ['numberString', 31],
1281
+ ['pickles', 100],
1282
+ ],
1283
+ },
1284
+ );
1285
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1286
+
1287
+ // Retrieving entity by inequality...
1288
+ resultEntity = await nymph.getEntities(
1289
+ { class: TestModel },
1290
+ {
1291
+ type: '|',
1292
+ gte: [
1293
+ ['numberString', 29],
1294
+ ['pickles', 100],
1295
+ ],
1296
+ },
1297
+ );
1298
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1299
+ });
1300
+
1301
+ it('less than', async () => {
1302
+ await createTestEntities();
1303
+
1304
+ // Retrieving entity by inequality...
1305
+ let resultEntity = await nymph.getEntities(
1306
+ { class: TestModel },
1307
+ {
1308
+ type: '|',
1309
+ lt: [
1310
+ ['number', 30],
1311
+ ['pickles', 100],
1312
+ ],
1313
+ },
1314
+ );
1315
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1316
+
1317
+ // Retrieving entity by inequality...
1318
+ resultEntity = await nymph.getEntities(
1319
+ { class: TestModel },
1320
+ {
1321
+ type: '|',
1322
+ lt: [
1323
+ ['number', 31],
1324
+ ['pickles', 100],
1325
+ ],
1326
+ },
1327
+ );
1328
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1329
+
1330
+ // Retrieving entity by inequality...
1331
+ resultEntity = await nymph.getEntities(
1332
+ { class: TestModel },
1333
+ {
1334
+ type: '|',
1335
+ lt: [
1336
+ ['number', 29],
1337
+ ['pickles', 100],
1338
+ ],
1339
+ },
1340
+ );
1341
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1342
+
1343
+ // Retrieving entity by inequality...
1344
+ resultEntity = await nymph.getEntities(
1345
+ { class: TestModel },
1346
+ {
1347
+ type: '|',
1348
+ lt: [
1349
+ ['numberString', 30],
1350
+ ['pickles', 100],
1351
+ ],
1352
+ },
1353
+ );
1354
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1355
+
1356
+ // Retrieving entity by inequality...
1357
+ resultEntity = await nymph.getEntities(
1358
+ { class: TestModel },
1359
+ {
1360
+ type: '|',
1361
+ lt: [
1362
+ ['numberString', 31],
1363
+ ['pickles', 100],
1364
+ ],
1365
+ },
1366
+ );
1367
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1368
+
1369
+ // Retrieving entity by inequality...
1370
+ resultEntity = await nymph.getEntities(
1371
+ { class: TestModel },
1372
+ {
1373
+ type: '|',
1374
+ lt: [
1375
+ ['numberString', 29],
1376
+ ['pickles', 100],
1377
+ ],
1378
+ },
1379
+ );
1380
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1381
+ });
1382
+
1383
+ it('less than or equal', async () => {
1384
+ await createTestEntities();
1385
+
1386
+ // Retrieving entity by inequality...
1387
+ let resultEntity = await nymph.getEntities(
1388
+ { class: TestModel },
1389
+ {
1390
+ type: '|',
1391
+ lte: [
1392
+ ['number', 30],
1393
+ ['pickles', 100],
1394
+ ],
1395
+ },
1396
+ );
1397
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1398
+
1399
+ // Retrieving entity by inequality...
1400
+ resultEntity = await nymph.getEntities(
1401
+ { class: TestModel },
1402
+ {
1403
+ type: '|',
1404
+ lte: [
1405
+ ['number', 31],
1406
+ ['pickles', 100],
1407
+ ],
1408
+ },
1409
+ );
1410
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1411
+
1412
+ // Retrieving entity by inequality...
1413
+ resultEntity = await nymph.getEntities(
1414
+ { class: TestModel },
1415
+ {
1416
+ type: '|',
1417
+ lte: [
1418
+ ['number', 29],
1419
+ ['pickles', 100],
1420
+ ],
1421
+ },
1422
+ );
1423
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1424
+
1425
+ // Retrieving entity by inequality...
1426
+ resultEntity = await nymph.getEntities(
1427
+ { class: TestModel },
1428
+ {
1429
+ type: '|',
1430
+ lte: [
1431
+ ['numberString', 30],
1432
+ ['pickles', 100],
1433
+ ],
1434
+ },
1435
+ );
1436
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1437
+
1438
+ // Retrieving entity by inequality...
1439
+ resultEntity = await nymph.getEntities(
1440
+ { class: TestModel },
1441
+ {
1442
+ type: '|',
1443
+ lte: [
1444
+ ['numberString', 31],
1445
+ ['pickles', 100],
1446
+ ],
1447
+ },
1448
+ );
1449
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1450
+
1451
+ // Retrieving entity by inequality...
1452
+ resultEntity = await nymph.getEntities(
1453
+ { class: TestModel },
1454
+ {
1455
+ type: '|',
1456
+ lte: [
1457
+ ['numberString', 29],
1458
+ ['pickles', 100],
1459
+ ],
1460
+ },
1461
+ );
1462
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1463
+ });
1464
+
1465
+ it('not inequality', async () => {
1466
+ await createTestEntities();
1467
+
1468
+ // Retrieving entity by !inequality...
1469
+ const resultEntity = await nymph.getEntities(
1470
+ { class: TestModel },
1471
+ { type: '&', tag: 'test' },
1472
+ { type: '!&', gte: ['number', 60] },
1473
+ );
1474
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1475
+ });
1476
+
1477
+ it('wrong inequality', async () => {
1478
+ await createTestEntities();
1479
+
1480
+ // Testing wrong inequality...
1481
+ const resultEntity = await nymph.getEntities(
1482
+ { class: TestModel },
1483
+ { type: '&', lte: ['number', 29.99] },
1484
+ );
1485
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1486
+ });
1487
+
1488
+ it('greater than cdate', async () => {
1489
+ await createTestEntities();
1490
+
1491
+ // Retrieving entity by time...
1492
+ const resultEntity = await nymph.getEntities(
1493
+ { class: TestModel },
1494
+ {
1495
+ type: '&',
1496
+ tag: 'test',
1497
+ gt: ['cdate', (testEntity.cdate ?? 0) - 120],
1498
+ },
1499
+ );
1500
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1501
+ });
1502
+
1503
+ it('wrong cdate', async () => {
1504
+ await createTestEntities();
1505
+
1506
+ // Testing wrong time...
1507
+ const resultEntity = await nymph.getEntities(
1508
+ { class: TestModel },
1509
+ { type: '&', tag: 'test', gte: ['cdate', (testEntity.cdate ?? 0) + 1] },
1510
+ );
1511
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1512
+ });
1513
+
1514
+ it('time selector', async () => {
1515
+ await createTestEntities();
1516
+
1517
+ const referenceEntity = await TestModel.factory(refGuid);
1518
+
1519
+ // Retrieving entity by relative time...
1520
+ let resultEntity = await nymph.getEntities(
1521
+ { class: TestModel },
1522
+ { type: '&', gt: ['timestamp', null, '-1 day'] },
1523
+ );
1524
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1525
+ expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
1526
+
1527
+ // Retrieving entity by relative time inclusively...
1528
+ resultEntity = await nymph.getEntities(
1529
+ { class: TestModel },
1530
+ {
1531
+ type: '|',
1532
+ gt: [
1533
+ ['timestamp', null, '-1 day'],
1534
+ ['timestamp', null, '+5 days'],
1535
+ ],
1536
+ },
1537
+ );
1538
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1539
+ expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
1540
+
1541
+ // Retrieving entity by relative time...
1542
+ resultEntity = await nymph.getEntities(
1543
+ { class: TestModel },
1544
+ { type: '&', gt: ['timestamp', null, '-3 days'] },
1545
+ );
1546
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1547
+ expect(referenceEntity.$inArray(resultEntity)).toEqual(true);
1548
+
1549
+ // Retrieving entity by relative time...
1550
+ resultEntity = await nymph.getEntities(
1551
+ { class: TestModel },
1552
+ { type: '&', gt: ['cdate', null, '-1 day'] },
1553
+ );
1554
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1555
+ expect(referenceEntity.$inArray(resultEntity)).toEqual(true);
1556
+ });
1557
+
1558
+ it('wrong time selector', async () => {
1559
+ await createTestEntities();
1560
+
1561
+ const referenceEntity = await TestModel.factory(refGuid);
1562
+
1563
+ // Retrieving entity by relative time...
1564
+ let resultEntity = await nymph.getEntities(
1565
+ { class: TestModel },
1566
+ { type: '&', tag: 'test', gt: ['timestamp', null, '+1 day'] },
1567
+ );
1568
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1569
+ expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
1570
+
1571
+ // Retrieving entity by relative time...
1572
+ resultEntity = await nymph.getEntities(
1573
+ { class: TestModel },
1574
+ { type: '&', tag: 'test', lt: ['timestamp', null, '-3 days'] },
1575
+ );
1576
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1577
+ expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
1578
+
1579
+ // Retrieving entity by relative time...
1580
+ resultEntity = await nymph.getEntities(
1581
+ { class: TestModel },
1582
+ { type: '&', tag: 'test', gt: ['cdate', null, '+1 day'] },
1583
+ );
1584
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1585
+ expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
1586
+ });
1587
+
1588
+ it('references', async () => {
1589
+ await createTestEntities();
1590
+
1591
+ // Testing referenced entities...
1592
+ await testEntity.reference?.$wake();
1593
+ expect(testEntity.reference?.test).toEqual('good');
1594
+
1595
+ // Testing referenced entity arrays...
1596
+ await Promise.all(testEntity.refArray?.map((e) => e.$wake()) || []);
1597
+ expect(testEntity.refArray?.[0].test).toEqual('good');
1598
+ });
1599
+
1600
+ it('ref', async () => {
1601
+ await createTestEntities();
1602
+
1603
+ // Retrieving entity by reference...
1604
+ const resultEntity = await nymph.getEntities(
1605
+ { class: TestModel },
1606
+ { type: '&', ref: ['reference', refGuid] },
1607
+ );
1608
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1609
+ });
1610
+
1611
+ it('not ref', async () => {
1612
+ await createTestEntities();
1613
+
1614
+ // Retrieving entity by !reference...
1615
+ const resultEntity = await nymph.getEntities(
1616
+ { class: TestModel },
1617
+ { type: '&', tag: 'test' },
1618
+ { type: '!&', ref: ['reference', guid()] },
1619
+ );
1620
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1621
+ });
1622
+
1623
+ it('wrong ref', async () => {
1624
+ await createTestEntities();
1625
+
1626
+ // Testing wrong reference...
1627
+ const resultEntity = await nymph.getEntities(
1628
+ { class: TestModel },
1629
+ { type: '&', ref: ['reference', guid()] },
1630
+ );
1631
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1632
+ });
1633
+
1634
+ it('nonexistent ref', async () => {
1635
+ await createTestEntities();
1636
+
1637
+ // Testing non-existent reference...
1638
+ const resultEntity = await nymph.getEntities(
1639
+ { class: TestModel },
1640
+ { type: '&', ref: ['pickle', refGuid] },
1641
+ );
1642
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1643
+ });
1644
+
1645
+ it('inclusive ref', async () => {
1646
+ await createTestEntities();
1647
+
1648
+ // Retrieving entity by inclusive reference...
1649
+ const resultEntity = await nymph.getEntities(
1650
+ { class: TestModel },
1651
+ {
1652
+ type: '|',
1653
+ ref: [
1654
+ ['reference', refGuid],
1655
+ ['reference', guid()],
1656
+ ],
1657
+ },
1658
+ );
1659
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1660
+ });
1661
+
1662
+ it('wrong inclusive ref', async () => {
1663
+ await createTestEntities();
1664
+
1665
+ // Testing wrong inclusive reference...
1666
+ const resultEntity = await nymph.getEntities(
1667
+ { class: TestModel },
1668
+ {
1669
+ type: '|',
1670
+ ref: [
1671
+ ['reference', guid()],
1672
+ ['reference', guid()],
1673
+ ],
1674
+ },
1675
+ );
1676
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1677
+ });
1678
+
1679
+ it('ref in an array', async () => {
1680
+ await createTestEntities();
1681
+
1682
+ // Retrieving entity by array reference...
1683
+ const resultEntity = await nymph.getEntities(
1684
+ { class: TestModel },
1685
+ { type: '&', ref: ['refArray', refGuid] },
1686
+ );
1687
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1688
+ });
1689
+
1690
+ it('wrong ref in an array', async () => {
1691
+ await createTestEntities();
1692
+
1693
+ // Testing wrong array reference...
1694
+ const resultEntity = await nymph.getEntities(
1695
+ { class: TestModel },
1696
+ {
1697
+ type: '&',
1698
+ ref: [
1699
+ ['refArray', refGuid],
1700
+ ['refArray', guid()],
1701
+ ],
1702
+ },
1703
+ );
1704
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1705
+ });
1706
+
1707
+ it('logic operations', async () => {
1708
+ await createTestEntities();
1709
+
1710
+ // Testing logic operations...
1711
+ const resultEntity = await nymph.getEntities(
1712
+ { class: TestModel },
1713
+ {
1714
+ type: '&',
1715
+ '!ref': [
1716
+ ['refArray', guid()],
1717
+ ['refArray', guid()],
1718
+ ],
1719
+ '!lte': ['number', 29.99],
1720
+ },
1721
+ {
1722
+ type: '|',
1723
+ '!lte': [
1724
+ ['number', 29.99],
1725
+ ['number', 30],
1726
+ ],
1727
+ },
1728
+ {
1729
+ type: '!&',
1730
+ '!equal': ['string', 'test'],
1731
+ '!contain': [
1732
+ ['array', 'full'],
1733
+ ['array', 'of'],
1734
+ ['array', 'values'],
1735
+ ['array', 500],
1736
+ ['array', { test: true }],
1737
+ ['array', { nullbyte: '\\\x00\u0000 \x00' }],
1738
+ ],
1739
+ },
1740
+ {
1741
+ type: '!|',
1742
+ '!equal': ['string', 'test'],
1743
+ contain: [
1744
+ ['array', 'full'],
1745
+ ['array', 'of'],
1746
+ ['array', 'values'],
1747
+ ['array', 500],
1748
+ ],
1749
+ },
1750
+ );
1751
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1752
+ });
1753
+
1754
+ it('count return', async () => {
1755
+ await createTestEntities();
1756
+
1757
+ const result = await nymph.getEntities({ class: TestModel });
1758
+
1759
+ // Testing count return...
1760
+ const resultCount = await nymph.getEntities({
1761
+ class: TestModel,
1762
+ return: 'count',
1763
+ });
1764
+ expect(resultCount).toBeGreaterThanOrEqual(1);
1765
+ expect(resultCount).toEqual(result.length);
1766
+
1767
+ const resultSelectors = await nymph.getEntities(
1768
+ { class: TestModel },
1769
+ { type: '&', ref: ['reference', refGuid] },
1770
+ );
1771
+
1772
+ // Testing count return with selectors...
1773
+ const resultSelectorsCount = await nymph.getEntities(
1774
+ { class: TestModel, return: 'count' },
1775
+ { type: '&', ref: ['reference', refGuid] },
1776
+ );
1777
+ expect(resultSelectorsCount).toBeGreaterThanOrEqual(1);
1778
+ expect(resultSelectorsCount).toEqual(resultSelectors.length);
1779
+
1780
+ // Testing count return with limit...
1781
+ const resultSelectorsLimit = await nymph.getEntities({
1782
+ class: TestModel,
1783
+ limit: 1,
1784
+ return: 'count',
1785
+ });
1786
+ expect(resultSelectorsLimit).toEqual(1);
1787
+
1788
+ // Testing count return with limit...
1789
+ const resultSelectorsSingle = await nymph.getEntity({
1790
+ class: TestModel,
1791
+ return: 'count',
1792
+ });
1793
+ expect(resultSelectorsSingle).toEqual(1);
1606
1794
 
1607
- // Retrieving entity by !reference...
1608
- const resultEntity = await nymph.getEntities(
1609
- { class: TestModel },
1610
- { type: '&', tag: 'test' },
1611
- { type: '!&', ref: ['reference', guid()] },
1612
- );
1613
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1614
- });
1795
+ // Testing empty count...
1796
+ const resultSelectorsEmpty = await nymph.getEntities(
1797
+ { class: TestModel, return: 'count' },
1798
+ { type: '&', ref: ['reference', guid()] },
1799
+ );
1800
+ expect(resultSelectorsEmpty).toEqual(0);
1801
+ });
1615
1802
 
1616
- it('wrong ref', async () => {
1617
- await createTestEntities();
1803
+ it('guid return', async () => {
1804
+ await createTestEntities();
1805
+
1806
+ // Testing guid return using logic operations...
1807
+ const resultGuid = await nymph.getEntities(
1808
+ { class: TestModel, return: 'guid' },
1809
+ {
1810
+ type: '&',
1811
+ '!ref': [
1812
+ ['refArray', guid()],
1813
+ ['refArray', guid()],
1814
+ ],
1815
+ '!lte': ['number', 29.99],
1816
+ },
1817
+ {
1818
+ type: '|',
1819
+ '!lte': [
1820
+ ['number', 29.99],
1821
+ ['number', 30],
1822
+ ],
1823
+ },
1824
+ {
1825
+ type: '!&',
1826
+ '!equal': ['string', 'test'],
1827
+ '!contain': [
1828
+ ['array', 'full'],
1829
+ ['array', 'of'],
1830
+ ['array', 'values'],
1831
+ ['array', 500],
1832
+ ['array', { test: true }],
1833
+ ['array', { nullbyte: '\\\x00\u0000 \x00' }],
1834
+ ],
1835
+ },
1836
+ {
1837
+ type: '!|',
1838
+ '!equal': ['string', 'test'],
1839
+ contain: [
1840
+ ['array', 'full'],
1841
+ ['array', 'of'],
1842
+ ['array', 'values'],
1843
+ ['array', 500],
1844
+ ],
1845
+ },
1846
+ );
1847
+ expect(resultGuid.indexOf(testEntity.guid ?? '')).toBeGreaterThan(-1);
1848
+ });
1618
1849
 
1619
- // Testing wrong reference...
1620
- const resultEntity = await nymph.getEntities(
1621
- { class: TestModel },
1622
- { type: '&', ref: ['reference', guid()] },
1623
- );
1624
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1625
- });
1850
+ it('object return', async () => {
1851
+ await createTestEntities();
1852
+
1853
+ // Testing object return using logic operations...
1854
+ const resultObjects = await nymph.getEntities(
1855
+ { class: TestModel, return: 'object' },
1856
+ {
1857
+ type: '&',
1858
+ '!ref': [
1859
+ ['refArray', guid()],
1860
+ ['refArray', guid()],
1861
+ ],
1862
+ '!lte': ['number', 29.99],
1863
+ },
1864
+ {
1865
+ type: '|',
1866
+ '!lte': [
1867
+ ['number', 29.99],
1868
+ ['number', 30],
1869
+ ],
1870
+ },
1871
+ {
1872
+ type: '!&',
1873
+ '!equal': ['string', 'test'],
1874
+ '!contain': [
1875
+ ['array', 'full'],
1876
+ ['array', 'of'],
1877
+ ['array', 'values'],
1878
+ ['array', 500],
1879
+ ['array', { test: true }],
1880
+ ['array', { nullbyte: '\\\x00\u0000 \x00' }],
1881
+ ],
1882
+ },
1883
+ {
1884
+ type: '!|',
1885
+ '!equal': ['string', 'test'],
1886
+ contain: [
1887
+ ['array', 'full'],
1888
+ ['array', 'of'],
1889
+ ['array', 'values'],
1890
+ ['array', 500],
1891
+ ],
1892
+ },
1893
+ );
1626
1894
 
1627
- it('nonexistent ref', async () => {
1628
- await createTestEntities();
1895
+ const resultObject = resultObjects.find(
1896
+ (entity) => entity.guid === testEntity.guid,
1897
+ );
1629
1898
 
1630
- // Testing non-existent reference...
1631
- const resultEntity = await nymph.getEntities(
1632
- { class: TestModel },
1633
- { type: '&', ref: ['pickle', refGuid] },
1634
- );
1635
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1636
- });
1899
+ expect(resultObject).toBeInstanceOf(Object);
1900
+ expect(resultObject).not.toBeInstanceOf(TestModel);
1901
+ expect(Array.isArray(resultObject?.tags)).toBeTruthy();
1902
+ expect(resultObject?.string).toEqual('test');
1903
+ });
1637
1904
 
1638
- it('inclusive ref', async () => {
1639
- await createTestEntities();
1640
-
1641
- // Retrieving entity by inclusive reference...
1642
- const resultEntity = await nymph.getEntities(
1643
- { class: TestModel },
1644
- {
1645
- type: '|',
1646
- ref: [
1647
- ['reference', refGuid],
1648
- ['reference', guid()],
1649
- ],
1650
- },
1651
- );
1652
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1653
- });
1905
+ it('deep selector', async () => {
1906
+ await createTestEntities();
1654
1907
 
1655
- it('wrong inclusive ref', async () => {
1656
- await createTestEntities();
1657
-
1658
- // Testing wrong inclusive reference...
1659
- const resultEntity = await nymph.getEntities(
1660
- { class: TestModel },
1661
- {
1662
- type: '|',
1663
- ref: [
1664
- ['reference', guid()],
1665
- ['reference', guid()],
1666
- ],
1667
- },
1668
- );
1669
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1670
- });
1908
+ // Testing deep selectors...
1909
+ const resultEntity = await nymph.getEntities(
1910
+ { class: TestModel },
1911
+ {
1912
+ type: '&',
1913
+ '!ref': [
1914
+ ['refArray', guid()],
1915
+ ['refArray', guid()],
1916
+ ],
1917
+ '!lte': ['number', 29.99],
1918
+ },
1919
+ {
1920
+ type: '&',
1921
+ selector: [
1922
+ {
1923
+ type: '|',
1924
+ '!lte': [
1925
+ ['number', 29.99],
1926
+ ['number', 30],
1927
+ ],
1928
+ },
1929
+ {
1930
+ type: '!&',
1931
+ '!equal': ['string', 'test'],
1932
+ '!contain': [
1933
+ ['array', 'full'],
1934
+ ['array', 'of'],
1935
+ ['array', 'values'],
1936
+ ['array', 500],
1937
+ ['array', { test: true }],
1938
+ ['array', { nullbyte: '\\\x00\u0000 \x00' }],
1939
+ ],
1940
+ },
1941
+ {
1942
+ type: '!|',
1943
+ '!equal': ['string', 'test'],
1944
+ contain: [
1945
+ ['array', 'full'],
1946
+ ['array', 'of'],
1947
+ ['array', 'values'],
1948
+ ['array', 500],
1949
+ ],
1950
+ },
1951
+ ],
1952
+ },
1953
+ );
1954
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1671
1955
 
1672
- it('ref in an array', async () => {
1673
- await createTestEntities();
1956
+ const resultEntity2 = await nymph.getEntities(
1957
+ { class: TestModel },
1958
+ {
1959
+ type: '&',
1960
+ '!ref': [
1961
+ ['refArray', guid()],
1962
+ ['refArray', guid()],
1963
+ ],
1964
+ '!lte': ['number', 29.99],
1965
+ },
1966
+ {
1967
+ type: '|',
1968
+ selector: [
1969
+ {
1970
+ type: '&',
1971
+ '!lte': [
1972
+ ['number', 29.99],
1973
+ ['number', 30],
1974
+ ],
1975
+ },
1976
+ {
1977
+ type: '!&',
1978
+ '!equal': ['string', 'test'],
1979
+ '!contain': [
1980
+ ['array', 'full'],
1981
+ ['array', 'of'],
1982
+ ['array', 'values'],
1983
+ ['array', 500],
1984
+ ['array', { test: true }],
1985
+ ['array', { nullbyte: '\\\x00\u0000 \x00' }],
1986
+ ],
1987
+ },
1988
+ {
1989
+ type: '&',
1990
+ '!equal': ['string', 'test'],
1991
+ contain: [
1992
+ ['array', 'full'],
1993
+ ['array', 'of'],
1994
+ ['array', 'values'],
1995
+ ['array', 500],
1996
+ ],
1997
+ },
1998
+ ],
1999
+ },
2000
+ );
2001
+ expect(testEntity.$inArray(resultEntity2)).toEqual(true);
1674
2002
 
1675
- // Retrieving entity by array reference...
1676
- const resultEntity = await nymph.getEntities(
1677
- { class: TestModel },
1678
- { type: '&', ref: ['refArray', refGuid] },
1679
- );
1680
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1681
- });
2003
+ const resultEntity3 = await nymph.getEntities(
2004
+ { class: TestModel },
2005
+ {
2006
+ type: '|',
2007
+ selector: [
2008
+ {
2009
+ type: '&',
2010
+ '!ref': ['refArray', guid()],
2011
+ '!lte': ['number', 29.99],
2012
+ },
2013
+ { type: '&', gte: ['number', 16000] },
2014
+ ],
2015
+ },
2016
+ );
2017
+ expect(testEntity.$inArray(resultEntity3)).toEqual(true);
1682
2018
 
1683
- it('wrong ref in an array', async () => {
1684
- await createTestEntities();
1685
-
1686
- // Testing wrong array reference...
1687
- const resultEntity = await nymph.getEntities(
1688
- { class: TestModel },
1689
- {
1690
- type: '&',
1691
- ref: [
1692
- ['refArray', refGuid],
1693
- ['refArray', guid()],
1694
- ],
1695
- },
1696
- );
1697
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1698
- });
2019
+ const resultEntity4 = await nymph.getEntities(
2020
+ { class: TestModel },
2021
+ {
2022
+ type: '|',
2023
+ selector: [
2024
+ {
2025
+ type: '&',
2026
+ '!ref': ['refArray', guid()],
2027
+ '!lte': ['number', 29.99],
2028
+ },
2029
+ {
2030
+ type: '&',
2031
+ selector: {
2032
+ type: '&',
2033
+ selector: { type: '&', gte: ['number', 16000] },
2034
+ },
2035
+ },
2036
+ ],
2037
+ },
2038
+ );
2039
+ expect(testEntity.$inArray(resultEntity4)).toEqual(true);
2040
+ });
1699
2041
 
1700
- it('logic operations', async () => {
1701
- await createTestEntities();
1702
-
1703
- // Testing logic operations...
1704
- const resultEntity = await nymph.getEntities(
1705
- { class: TestModel },
1706
- {
1707
- type: '&',
1708
- '!ref': [
1709
- ['refArray', guid()],
1710
- ['refArray', guid()],
1711
- ],
1712
- '!lte': ['number', 29.99],
1713
- },
1714
- {
1715
- type: '|',
1716
- '!lte': [
1717
- ['number', 29.99],
1718
- ['number', 30],
1719
- ],
1720
- },
1721
- {
1722
- type: '!&',
1723
- '!equal': ['string', 'test'],
1724
- '!contain': [
1725
- ['array', 'full'],
1726
- ['array', 'of'],
1727
- ['array', 'values'],
1728
- ['array', 500],
1729
- ['array', { test: true }],
1730
- ['array', { nullbyte: '\\\x00\u0000 \x00' }],
1731
- ],
1732
- },
1733
- {
1734
- type: '!|',
1735
- '!equal': ['string', 'test'],
1736
- contain: [
1737
- ['array', 'full'],
1738
- ['array', 'of'],
1739
- ['array', 'values'],
1740
- ['array', 500],
1741
- ],
1742
- },
1743
- );
1744
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1745
- });
2042
+ it('wrong deep selector', async () => {
2043
+ // Testing wrong deep selectors...
2044
+ const resultEntity = await nymph.getEntities(
2045
+ { class: TestModel },
2046
+ {
2047
+ type: '&',
2048
+ selector: [
2049
+ {
2050
+ type: '&',
2051
+ '!ref': ['refArray', guid()],
2052
+ '!lte': ['number', 29.99],
2053
+ },
2054
+ { type: '&', gte: ['number', 16000] },
2055
+ ],
2056
+ },
2057
+ );
2058
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
2059
+ });
1746
2060
 
1747
- it('count return', async () => {
1748
- await createTestEntities();
1749
-
1750
- const result = await nymph.getEntities({ class: TestModel });
1751
-
1752
- // Testing count return...
1753
- const resultCount = await nymph.getEntities({
1754
- class: TestModel,
1755
- return: 'count',
1756
- });
1757
- expect(resultCount).toBeGreaterThanOrEqual(1);
1758
- expect(resultCount).toEqual(result.length);
1759
-
1760
- const resultSelectors = await nymph.getEntities(
1761
- { class: TestModel },
1762
- { type: '&', ref: ['reference', refGuid] },
1763
- );
1764
-
1765
- // Testing count return with selectors...
1766
- const resultSelectorsCount = await nymph.getEntities(
1767
- { class: TestModel, return: 'count' },
1768
- { type: '&', ref: ['reference', refGuid] },
1769
- );
1770
- expect(resultSelectorsCount).toBeGreaterThanOrEqual(1);
1771
- expect(resultSelectorsCount).toEqual(resultSelectors.length);
1772
-
1773
- // Testing count return with limit...
1774
- const resultSelectorsLimit = await nymph.getEntities({
1775
- class: TestModel,
1776
- limit: 1,
1777
- return: 'count',
1778
- });
1779
- expect(resultSelectorsLimit).toEqual(1);
1780
-
1781
- // Testing count return with limit...
1782
- const resultSelectorsSingle = await nymph.getEntity({
1783
- class: TestModel,
1784
- return: 'count',
1785
- });
1786
- expect(resultSelectorsSingle).toEqual(1);
1787
-
1788
- // Testing empty count...
1789
- const resultSelectorsEmpty = await nymph.getEntities(
1790
- { class: TestModel, return: 'count' },
1791
- { type: '&', ref: ['reference', guid()] },
1792
- );
1793
- expect(resultSelectorsEmpty).toEqual(0);
1794
- });
2061
+ it('qref', async () => {
2062
+ await createTestEntities();
1795
2063
 
1796
- it('guid return', async () => {
1797
- await createTestEntities();
1798
-
1799
- // Testing guid return using logic operations...
1800
- const resultGuid = await nymph.getEntities(
1801
- { class: TestModel, return: 'guid' },
1802
- {
1803
- type: '&',
1804
- '!ref': [
1805
- ['refArray', guid()],
1806
- ['refArray', guid()],
1807
- ],
1808
- '!lte': ['number', 29.99],
1809
- },
1810
- {
1811
- type: '|',
1812
- '!lte': [
1813
- ['number', 29.99],
1814
- ['number', 30],
1815
- ],
1816
- },
1817
- {
1818
- type: '!&',
1819
- '!equal': ['string', 'test'],
1820
- '!contain': [
1821
- ['array', 'full'],
1822
- ['array', 'of'],
1823
- ['array', 'values'],
1824
- ['array', 500],
1825
- ['array', { test: true }],
1826
- ['array', { nullbyte: '\\\x00\u0000 \x00' }],
1827
- ],
1828
- },
1829
- {
1830
- type: '!|',
1831
- '!equal': ['string', 'test'],
1832
- contain: [
1833
- ['array', 'full'],
1834
- ['array', 'of'],
1835
- ['array', 'values'],
1836
- ['array', 500],
1837
- ],
1838
- },
1839
- );
1840
- expect(resultGuid.indexOf(testEntity.guid ?? '')).toBeGreaterThan(-1);
1841
- });
2064
+ // Retrieving entity by qref...
2065
+ const resultEntity = await nymph.getEntities(
2066
+ { class: TestModel },
2067
+ {
2068
+ type: '&',
2069
+ qref: [
2070
+ 'reference',
2071
+ [{ class: TestModel }, { type: '&', equal: ['test', 'good'] }],
2072
+ ],
2073
+ },
2074
+ );
2075
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
2076
+ });
1842
2077
 
1843
- it('object return', async () => {
1844
- await createTestEntities();
1845
-
1846
- // Testing object return using logic operations...
1847
- const resultObjects = await nymph.getEntities(
1848
- { class: TestModel, return: 'object' },
1849
- {
1850
- type: '&',
1851
- '!ref': [
1852
- ['refArray', guid()],
1853
- ['refArray', guid()],
1854
- ],
1855
- '!lte': ['number', 29.99],
1856
- },
1857
- {
1858
- type: '|',
1859
- '!lte': [
1860
- ['number', 29.99],
1861
- ['number', 30],
1862
- ],
1863
- },
1864
- {
1865
- type: '!&',
1866
- '!equal': ['string', 'test'],
1867
- '!contain': [
1868
- ['array', 'full'],
1869
- ['array', 'of'],
1870
- ['array', 'values'],
1871
- ['array', 500],
1872
- ['array', { test: true }],
1873
- ['array', { nullbyte: '\\\x00\u0000 \x00' }],
1874
- ],
1875
- },
1876
- {
1877
- type: '!|',
1878
- '!equal': ['string', 'test'],
1879
- contain: [
1880
- ['array', 'full'],
1881
- ['array', 'of'],
1882
- ['array', 'values'],
1883
- ['array', 500],
1884
- ],
1885
- },
1886
- );
1887
-
1888
- const resultObject = resultObjects.find(
1889
- (entity) => entity.guid === testEntity.guid,
1890
- );
1891
-
1892
- expect(resultObject).toBeInstanceOf(Object);
1893
- expect(resultObject).not.toBeInstanceOf(TestModel);
1894
- expect(Array.isArray(resultObject?.tags)).toBeTruthy();
1895
- expect(resultObject?.string).toEqual('test');
1896
- });
2078
+ it('not qref', async () => {
2079
+ await createTestEntities();
1897
2080
 
1898
- it('deep selector', async () => {
1899
- await createTestEntities();
1900
-
1901
- // Testing deep selectors...
1902
- const resultEntity = await nymph.getEntities(
1903
- { class: TestModel },
1904
- {
1905
- type: '&',
1906
- '!ref': [
1907
- ['refArray', guid()],
1908
- ['refArray', guid()],
1909
- ],
1910
- '!lte': ['number', 29.99],
1911
- },
1912
- {
1913
- type: '&',
1914
- selector: [
1915
- {
1916
- type: '|',
1917
- '!lte': [
1918
- ['number', 29.99],
1919
- ['number', 30],
1920
- ],
1921
- },
1922
- {
1923
- type: '!&',
1924
- '!equal': ['string', 'test'],
1925
- '!contain': [
1926
- ['array', 'full'],
1927
- ['array', 'of'],
1928
- ['array', 'values'],
1929
- ['array', 500],
1930
- ['array', { test: true }],
1931
- ['array', { nullbyte: '\\\x00\u0000 \x00' }],
1932
- ],
1933
- },
1934
- {
1935
- type: '!|',
1936
- '!equal': ['string', 'test'],
1937
- contain: [
1938
- ['array', 'full'],
1939
- ['array', 'of'],
1940
- ['array', 'values'],
1941
- ['array', 500],
1942
- ],
1943
- },
1944
- ],
1945
- },
1946
- );
1947
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1948
-
1949
- const resultEntity2 = await nymph.getEntities(
1950
- { class: TestModel },
1951
- {
1952
- type: '&',
1953
- '!ref': [
1954
- ['refArray', guid()],
1955
- ['refArray', guid()],
1956
- ],
1957
- '!lte': ['number', 29.99],
1958
- },
1959
- {
1960
- type: '|',
1961
- selector: [
1962
- {
1963
- type: '&',
1964
- '!lte': [
1965
- ['number', 29.99],
1966
- ['number', 30],
1967
- ],
1968
- },
1969
- {
1970
- type: '!&',
1971
- '!equal': ['string', 'test'],
1972
- '!contain': [
1973
- ['array', 'full'],
1974
- ['array', 'of'],
1975
- ['array', 'values'],
1976
- ['array', 500],
1977
- ['array', { test: true }],
1978
- ['array', { nullbyte: '\\\x00\u0000 \x00' }],
1979
- ],
1980
- },
1981
- {
1982
- type: '&',
1983
- '!equal': ['string', 'test'],
1984
- contain: [
1985
- ['array', 'full'],
1986
- ['array', 'of'],
1987
- ['array', 'values'],
1988
- ['array', 500],
1989
- ],
1990
- },
1991
- ],
1992
- },
1993
- );
1994
- expect(testEntity.$inArray(resultEntity2)).toEqual(true);
1995
-
1996
- const resultEntity3 = await nymph.getEntities(
1997
- { class: TestModel },
1998
- {
1999
- type: '|',
2000
- selector: [
2001
- {
2002
- type: '&',
2003
- '!ref': ['refArray', guid()],
2004
- '!lte': ['number', 29.99],
2005
- },
2006
- { type: '&', gte: ['number', 16000] },
2007
- ],
2008
- },
2009
- );
2010
- expect(testEntity.$inArray(resultEntity3)).toEqual(true);
2011
-
2012
- const resultEntity4 = await nymph.getEntities(
2013
- { class: TestModel },
2014
- {
2015
- type: '|',
2016
- selector: [
2017
- {
2018
- type: '&',
2019
- '!ref': ['refArray', guid()],
2020
- '!lte': ['number', 29.99],
2021
- },
2022
- {
2023
- type: '&',
2024
- selector: {
2025
- type: '&',
2026
- selector: { type: '&', gte: ['number', 16000] },
2027
- },
2028
- },
2029
- ],
2030
- },
2031
- );
2032
- expect(testEntity.$inArray(resultEntity4)).toEqual(true);
2033
- });
2081
+ // Retrieving entity by !qref...
2082
+ const resultEntity = await nymph.getEntities(
2083
+ { class: TestModel },
2084
+ {
2085
+ type: '&',
2086
+ '!qref': [
2087
+ 'reference',
2088
+ [{ class: TestModel }, { type: '&', equal: ['test', 'pickles'] }],
2089
+ ],
2090
+ },
2091
+ );
2092
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
2093
+ });
2034
2094
 
2035
- it('wrong deep selector', async () => {
2036
- // Testing wrong deep selectors...
2037
- const resultEntity = await nymph.getEntities(
2038
- { class: TestModel },
2039
- {
2040
- type: '&',
2041
- selector: [
2042
- {
2043
- type: '&',
2044
- '!ref': ['refArray', guid()],
2045
- '!lte': ['number', 29.99],
2046
- },
2047
- { type: '&', gte: ['number', 16000] },
2048
- ],
2049
- },
2050
- );
2051
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
2052
- });
2095
+ it('wrong qref class', async () => {
2096
+ await createTestEntities();
2053
2097
 
2054
- it('qref', async () => {
2055
- await createTestEntities();
2056
-
2057
- // Retrieving entity by qref...
2058
- const resultEntity = await nymph.getEntities(
2059
- { class: TestModel },
2060
- {
2061
- type: '&',
2062
- qref: [
2063
- 'reference',
2064
- [{ class: TestModel }, { type: '&', equal: ['test', 'good'] }],
2065
- ],
2066
- },
2067
- );
2068
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
2069
- });
2098
+ // Testing wrong qref...
2099
+ const resultEntity = await nymph.getEntities(
2100
+ { class: TestModel },
2101
+ {
2102
+ type: '&',
2103
+ qref: [
2104
+ 'reference',
2105
+ [{ class: TestBModel }, { type: '&', equal: ['test', 'good'] }],
2106
+ ],
2107
+ },
2108
+ );
2109
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
2110
+ });
2070
2111
 
2071
- it('not qref', async () => {
2072
- await createTestEntities();
2073
-
2074
- // Retrieving entity by !qref...
2075
- const resultEntity = await nymph.getEntities(
2076
- { class: TestModel },
2077
- {
2078
- type: '&',
2079
- '!qref': [
2080
- 'reference',
2081
- [{ class: TestModel }, { type: '&', equal: ['test', 'pickles'] }],
2082
- ],
2083
- },
2084
- );
2085
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
2086
- });
2112
+ it('wrong qref data', async () => {
2113
+ await createTestEntities();
2087
2114
 
2088
- it('wrong qref class', async () => {
2089
- await createTestEntities();
2090
-
2091
- // Testing wrong qref...
2092
- const resultEntity = await nymph.getEntities(
2093
- { class: TestModel },
2094
- {
2095
- type: '&',
2096
- qref: [
2097
- 'reference',
2098
- [{ class: TestBModel }, { type: '&', equal: ['test', 'good'] }],
2099
- ],
2100
- },
2101
- );
2102
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
2103
- });
2115
+ // Testing wrong qref...
2116
+ const resultEntity = await nymph.getEntities(
2117
+ { class: TestModel },
2118
+ {
2119
+ type: '&',
2120
+ qref: [
2121
+ 'reference',
2122
+ [{ class: TestModel }, { type: '&', equal: ['test', 'pickles'] }],
2123
+ ],
2124
+ },
2125
+ );
2126
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
2127
+ });
2104
2128
 
2105
- it('wrong qref data', async () => {
2106
- await createTestEntities();
2107
-
2108
- // Testing wrong qref...
2109
- const resultEntity = await nymph.getEntities(
2110
- { class: TestModel },
2111
- {
2112
- type: '&',
2113
- qref: [
2114
- 'reference',
2115
- [{ class: TestModel }, { type: '&', equal: ['test', 'pickles'] }],
2116
- ],
2117
- },
2118
- );
2119
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
2120
- });
2129
+ it('cdate and mdate sort option', async () => {
2130
+ await createMultipleTestEntities();
2131
+
2132
+ for (const sort of ['cdate', 'mdate'] as ('cdate' | 'mdate')[]) {
2133
+ // Retrieving entities sorted...
2134
+ let resultEntities = await nymph.getEntities({
2135
+ class: TestModel,
2136
+ sort,
2137
+ });
2138
+ expect(resultEntities.length).toBeGreaterThan(100);
2139
+ for (let i = 0; i < resultEntities.length - 1; i++) {
2140
+ expect(resultEntities[i + 1][sort]).toBeGreaterThan(
2141
+ resultEntities[i][sort] ?? 0,
2142
+ );
2143
+ }
2144
+
2145
+ // And test the same with guid return...
2146
+ let resultGuids = await nymph.getEntities({
2147
+ class: TestModel,
2148
+ sort,
2149
+ return: 'guid',
2150
+ });
2151
+ expect(resultGuids.length).toBeGreaterThan(100);
2152
+ for (let i = 0; i < resultGuids.length - 1; i++) {
2153
+ expect(resultGuids[i]).toEqual(resultEntities[i].guid);
2154
+ }
2155
+
2156
+ // Retrieving entities reverse sorted...
2157
+ resultEntities = await nymph.getEntities({
2158
+ class: TestModel,
2159
+ sort,
2160
+ reverse: true,
2161
+ });
2162
+ expect(resultEntities.length).toBeGreaterThan(100);
2163
+ for (let i = 0; i < resultEntities.length - 1; i++) {
2164
+ expect(resultEntities[i + 1][sort]).toBeLessThan(
2165
+ resultEntities[i][sort] ?? 0,
2166
+ );
2167
+ }
2168
+
2169
+ // And again with other selectors.
2170
+ // Retrieving entities sorted...
2171
+ resultEntities = await nymph.getEntities(
2172
+ { class: TestModel, sort },
2173
+ { type: '&', match: ['name', '^Multi Test '] },
2174
+ );
2175
+ expect(resultEntities.length).toEqual(100);
2176
+ for (let i = 0; i < resultEntities.length - 1; i++) {
2177
+ expect(resultEntities[i + 1][sort]).toBeGreaterThan(
2178
+ resultEntities[i][sort] ?? 0,
2179
+ );
2180
+ }
2181
+
2182
+ // Retrieving entities reverse sorted...
2183
+ resultEntities = await nymph.getEntities(
2184
+ { class: TestModel, sort, reverse: true },
2185
+ { type: '&', match: ['name', '^Multi Test '] },
2186
+ );
2187
+ expect(resultEntities.length).toEqual(100);
2188
+ for (let i = 0; i < resultEntities.length - 1; i++) {
2189
+ expect(resultEntities[i + 1][sort]).toBeLessThan(
2190
+ resultEntities[i][sort] ?? 0,
2191
+ );
2192
+ }
2193
+ }
2194
+ });
2121
2195
 
2122
- it('cdate and mdate sort option', async () => {
2123
- await createMultipleTestEntities();
2196
+ it('property sort option', async () => {
2197
+ await createMultipleTestEntities();
2124
2198
 
2125
- for (const sort of ['cdate', 'mdate'] as ('cdate' | 'mdate')[]) {
2126
2199
  // Retrieving entities sorted...
2127
- let resultEntities = await nymph.getEntities({ class: TestModel, sort });
2200
+ let resultEntities = await nymph.getEntities({
2201
+ class: TestModel,
2202
+ sort: 'number',
2203
+ });
2128
2204
  expect(resultEntities.length).toBeGreaterThan(100);
2129
2205
  for (let i = 0; i < resultEntities.length - 1; i++) {
2130
- expect(resultEntities[i + 1][sort]).toBeGreaterThan(
2131
- resultEntities[i][sort] ?? 0,
2206
+ expect(resultEntities[i + 1].number ?? Infinity).toBeGreaterThanOrEqual(
2207
+ resultEntities[i].number ?? 0,
2132
2208
  );
2133
2209
  }
2134
2210
 
2135
2211
  // And test the same with guid return...
2136
2212
  let resultGuids = await nymph.getEntities({
2137
2213
  class: TestModel,
2138
- sort,
2214
+ sort: 'number',
2139
2215
  return: 'guid',
2140
2216
  });
2141
2217
  expect(resultGuids.length).toBeGreaterThan(100);
@@ -2146,481 +2222,425 @@ export function EntitiesTest(
2146
2222
  // Retrieving entities reverse sorted...
2147
2223
  resultEntities = await nymph.getEntities({
2148
2224
  class: TestModel,
2149
- sort,
2225
+ sort: 'number',
2150
2226
  reverse: true,
2151
2227
  });
2152
2228
  expect(resultEntities.length).toBeGreaterThan(100);
2153
2229
  for (let i = 0; i < resultEntities.length - 1; i++) {
2154
- expect(resultEntities[i + 1][sort]).toBeLessThan(
2155
- resultEntities[i][sort] ?? 0,
2230
+ expect(resultEntities[i + 1].number ?? 0).toBeLessThanOrEqual(
2231
+ resultEntities[i].number ?? Infinity,
2156
2232
  );
2157
2233
  }
2158
2234
 
2159
2235
  // And again with other selectors.
2160
2236
  // Retrieving entities sorted...
2161
2237
  resultEntities = await nymph.getEntities(
2162
- { class: TestModel, sort },
2238
+ { class: TestModel, sort: 'number' },
2163
2239
  { type: '&', match: ['name', '^Multi Test '] },
2164
2240
  );
2165
2241
  expect(resultEntities.length).toEqual(100);
2166
2242
  for (let i = 0; i < resultEntities.length - 1; i++) {
2167
- expect(resultEntities[i + 1][sort]).toBeGreaterThan(
2168
- resultEntities[i][sort] ?? 0,
2243
+ expect(resultEntities[i + 1].number ?? Infinity).toBeGreaterThan(
2244
+ resultEntities[i].number ?? 0,
2245
+ );
2246
+ expect(resultEntities[i].name).toEqual(
2247
+ `Multi Test ${100 - (resultEntities[i].number ?? 0)}`,
2169
2248
  );
2170
2249
  }
2171
2250
 
2172
2251
  // Retrieving entities reverse sorted...
2173
2252
  resultEntities = await nymph.getEntities(
2174
- { class: TestModel, sort, reverse: true },
2253
+ { class: TestModel, sort: 'number', reverse: true },
2175
2254
  { type: '&', match: ['name', '^Multi Test '] },
2176
2255
  );
2177
2256
  expect(resultEntities.length).toEqual(100);
2178
2257
  for (let i = 0; i < resultEntities.length - 1; i++) {
2179
- expect(resultEntities[i + 1][sort]).toBeLessThan(
2180
- resultEntities[i][sort] ?? 0,
2258
+ expect(resultEntities[i + 1].number ?? 0).toBeLessThan(
2259
+ resultEntities[i].number ?? Infinity,
2260
+ );
2261
+ expect(resultEntities[i].name).toEqual(
2262
+ `Multi Test ${100 - (resultEntities[i].number ?? 0)}`,
2181
2263
  );
2182
2264
  }
2183
- }
2184
- });
2265
+ });
2185
2266
 
2186
- it('property sort option', async () => {
2187
- await createMultipleTestEntities();
2267
+ it('delete reference', async () => {
2268
+ await createTestEntities();
2188
2269
 
2189
- // Retrieving entities sorted...
2190
- let resultEntities = await nymph.getEntities({
2191
- class: TestModel,
2192
- sort: 'number',
2270
+ // Deleting referenced entities...
2271
+ await testEntity.reference?.$wake();
2272
+ expect(await testEntity.reference?.$delete()).toEqual(true);
2273
+ await Promise.all(testEntity.refArray?.map((e) => e.$wake()) || []);
2274
+ expect(testEntity.reference?.guid).toBeNull();
2193
2275
  });
2194
- expect(resultEntities.length).toBeGreaterThan(100);
2195
- for (let i = 0; i < resultEntities.length - 1; i++) {
2196
- expect(resultEntities[i + 1].number ?? Infinity).toBeGreaterThanOrEqual(
2197
- resultEntities[i].number ?? 0,
2276
+
2277
+ it('delete', async () => {
2278
+ await createTestEntities();
2279
+
2280
+ // Deleting entity...
2281
+ expect(await testEntity.$delete()).toEqual(true);
2282
+ expect(testEntity.guid).toBeNull();
2283
+
2284
+ const entity = await nymph.getEntity(
2285
+ { class: TestModel },
2286
+ { type: '&', guid: testGuid },
2198
2287
  );
2199
- }
2200
2288
 
2201
- // And test the same with guid return...
2202
- let resultGuids = await nymph.getEntities({
2203
- class: TestModel,
2204
- sort: 'number',
2205
- return: 'guid',
2289
+ expect(entity).toBeNull();
2206
2290
  });
2207
- expect(resultGuids.length).toBeGreaterThan(100);
2208
- for (let i = 0; i < resultGuids.length - 1; i++) {
2209
- expect(resultGuids[i]).toEqual(resultEntities[i].guid);
2210
- }
2211
2291
 
2212
- // Retrieving entities reverse sorted...
2213
- resultEntities = await nymph.getEntities({
2214
- class: TestModel,
2215
- sort: 'number',
2216
- reverse: true,
2217
- });
2218
- expect(resultEntities.length).toBeGreaterThan(100);
2219
- for (let i = 0; i < resultEntities.length - 1; i++) {
2220
- expect(resultEntities[i + 1].number ?? 0).toBeLessThanOrEqual(
2221
- resultEntities[i].number ?? Infinity,
2222
- );
2223
- }
2292
+ it('allows non-duplicate unique strings', async () => {
2293
+ // Creating entity...
2294
+ const uniqueEntityA = await TestModel.factory();
2295
+ uniqueEntityA.name = 'Entity Test ' + new Date().toLocaleString();
2296
+ uniqueEntityA.uniques = ['test a'];
2224
2297
 
2225
- // And again with other selectors.
2226
- // Retrieving entities sorted...
2227
- resultEntities = await nymph.getEntities(
2228
- { class: TestModel, sort: 'number' },
2229
- { type: '&', match: ['name', '^Multi Test '] },
2230
- );
2231
- expect(resultEntities.length).toEqual(100);
2232
- for (let i = 0; i < resultEntities.length - 1; i++) {
2233
- expect(resultEntities[i + 1].number ?? Infinity).toBeGreaterThan(
2234
- resultEntities[i].number ?? 0,
2235
- );
2236
- expect(resultEntities[i].name).toEqual(
2237
- `Multi Test ${100 - (resultEntities[i].number ?? 0)}`,
2238
- );
2239
- }
2298
+ // Saving entity...
2299
+ expect(await uniqueEntityA.$save()).toEqual(true);
2300
+ expect(uniqueEntityA.guid).not.toBeNull();
2240
2301
 
2241
- // Retrieving entities reverse sorted...
2242
- resultEntities = await nymph.getEntities(
2243
- { class: TestModel, sort: 'number', reverse: true },
2244
- { type: '&', match: ['name', '^Multi Test '] },
2245
- );
2246
- expect(resultEntities.length).toEqual(100);
2247
- for (let i = 0; i < resultEntities.length - 1; i++) {
2248
- expect(resultEntities[i + 1].number ?? 0).toBeLessThan(
2249
- resultEntities[i].number ?? Infinity,
2250
- );
2251
- expect(resultEntities[i].name).toEqual(
2252
- `Multi Test ${100 - (resultEntities[i].number ?? 0)}`,
2253
- );
2254
- }
2255
- });
2302
+ // Creating entity...
2303
+ const uniqueEntityB = await TestModel.factory();
2304
+ uniqueEntityB.name = 'Entity Test ' + new Date().toLocaleString();
2305
+ uniqueEntityB.uniques = ['test b'];
2256
2306
 
2257
- it('delete reference', async () => {
2258
- await createTestEntities();
2307
+ // Saving entity...
2308
+ expect(await uniqueEntityB.$save()).toEqual(true);
2309
+ expect(uniqueEntityB.guid).not.toBeNull();
2259
2310
 
2260
- // Deleting referenced entities...
2261
- await testEntity.reference?.$wake();
2262
- expect(await testEntity.reference?.$delete()).toEqual(true);
2263
- await Promise.all(testEntity.refArray?.map((e) => e.$wake()) || []);
2264
- expect(testEntity.reference?.guid).toBeNull();
2265
- });
2311
+ expect(uniqueEntityA.guid).not.toEqual(uniqueEntityB.guid);
2266
2312
 
2267
- it('delete', async () => {
2268
- await createTestEntities();
2313
+ expect(await uniqueEntityA.$delete()).toEqual(true);
2314
+ expect(await uniqueEntityB.$delete()).toEqual(true);
2315
+ });
2269
2316
 
2270
- // Deleting entity...
2271
- expect(await testEntity.$delete()).toEqual(true);
2272
- expect(testEntity.guid).toBeNull();
2317
+ it('throws on duplicate unique strings', async () => {
2318
+ // Creating entity...
2319
+ const uniqueEntityA = await TestModel.factory();
2320
+ uniqueEntityA.name = 'Entity Test ' + new Date().toLocaleString();
2321
+ uniqueEntityA.uniques = ['test a'];
2273
2322
 
2274
- const entity = await nymph.getEntity(
2275
- { class: TestModel },
2276
- { type: '&', guid: testGuid },
2277
- );
2323
+ // Saving entity...
2324
+ expect(await uniqueEntityA.$save()).toEqual(true);
2325
+ expect(uniqueEntityA.guid).not.toBeNull();
2278
2326
 
2279
- expect(entity).toBeNull();
2280
- });
2327
+ // Creating entity...
2328
+ const uniqueEntityB = await TestModel.factory();
2329
+ uniqueEntityB.name = 'Entity Test ' + new Date().toLocaleString();
2330
+ uniqueEntityB.uniques = ['test a'];
2281
2331
 
2282
- it('allows non-duplicate unique strings', async () => {
2283
- // Creating entity...
2284
- const uniqueEntityA = await TestModel.factory();
2285
- uniqueEntityA.name = 'Entity Test ' + new Date().toLocaleString();
2286
- uniqueEntityA.uniques = ['test a'];
2332
+ // Saving entity...
2333
+ try {
2334
+ await uniqueEntityB.$save();
2287
2335
 
2288
- // Saving entity...
2289
- expect(await uniqueEntityA.$save()).toEqual(true);
2290
- expect(uniqueEntityA.guid).not.toBeNull();
2336
+ throw Error("Shouldn't get past the uniqueness check.");
2337
+ } catch (e: any) {
2338
+ expect(e).toBeInstanceOf(EntityUniqueConstraintError);
2339
+ }
2340
+ expect(uniqueEntityB.guid).toBeNull();
2291
2341
 
2292
- // Creating entity...
2293
- const uniqueEntityB = await TestModel.factory();
2294
- uniqueEntityB.name = 'Entity Test ' + new Date().toLocaleString();
2295
- uniqueEntityB.uniques = ['test b'];
2342
+ expect(await uniqueEntityA.$delete()).toEqual(true);
2343
+ });
2296
2344
 
2297
- // Saving entity...
2298
- expect(await uniqueEntityB.$save()).toEqual(true);
2299
- expect(uniqueEntityB.guid).not.toBeNull();
2345
+ it('allows duplicate unique string if first transaction is rolled back', async () => {
2346
+ // Creating transaction entity...
2347
+ const tnymphA = await nymph.startTransaction('test-unique-a');
2348
+ const TestModelA = tnymphA.getEntityClass(TestModel);
2349
+ const uniqueEntityA = await TestModelA.factory();
2350
+ uniqueEntityA.name = 'Entity Test ' + new Date().toLocaleString();
2351
+ uniqueEntityA.uniques = ['test a'];
2300
2352
 
2301
- expect(uniqueEntityA.guid).not.toEqual(uniqueEntityB.guid);
2353
+ // Saving entity...
2354
+ expect(await uniqueEntityA.$save()).toEqual(true);
2355
+ expect(uniqueEntityA.guid).not.toBeNull();
2302
2356
 
2303
- expect(await uniqueEntityA.$delete()).toEqual(true);
2304
- expect(await uniqueEntityB.$delete()).toEqual(true);
2305
- });
2357
+ // Rolling back transaction...
2358
+ expect(await tnymphA.rollback('test-unique-a')).toEqual(true);
2306
2359
 
2307
- it('throws on duplicate unique strings', async () => {
2308
- // Creating entity...
2309
- const uniqueEntityA = await TestModel.factory();
2310
- uniqueEntityA.name = 'Entity Test ' + new Date().toLocaleString();
2311
- uniqueEntityA.uniques = ['test a'];
2360
+ // Creating transaction entity...
2361
+ const tnymphB = await nymph.startTransaction('test-unique-b');
2362
+ const TestModelB = tnymphB.getEntityClass(TestModel);
2363
+ const uniqueEntityB = await TestModelB.factory();
2364
+ uniqueEntityB.name = 'Entity Test ' + new Date().toLocaleString();
2365
+ uniqueEntityB.uniques = ['test a'];
2312
2366
 
2313
- // Saving entity...
2314
- expect(await uniqueEntityA.$save()).toEqual(true);
2315
- expect(uniqueEntityA.guid).not.toBeNull();
2367
+ // Saving entity...
2368
+ expect(await uniqueEntityB.$save()).toEqual(true);
2369
+ expect(uniqueEntityB.guid).not.toBeNull();
2316
2370
 
2317
- // Creating entity...
2318
- const uniqueEntityB = await TestModel.factory();
2319
- uniqueEntityB.name = 'Entity Test ' + new Date().toLocaleString();
2320
- uniqueEntityB.uniques = ['test a'];
2371
+ expect(uniqueEntityA.guid).not.toEqual(uniqueEntityB.guid);
2321
2372
 
2322
- // Saving entity...
2323
- try {
2324
- await uniqueEntityB.$save();
2373
+ expect(await tnymphB.commit('test-unique-b')).toEqual(true);
2325
2374
 
2326
- throw Error("Shouldn't get past the uniqueness check.");
2327
- } catch (e: any) {
2328
- expect(e).toBeInstanceOf(EntityUniqueConstraintError);
2329
- }
2330
- expect(uniqueEntityB.guid).toBeNull();
2375
+ const uniqueEntityACheck = await nymph.getEntity(
2376
+ { class: TestModel },
2377
+ { type: '&', guid: uniqueEntityA.guid ?? '' },
2378
+ );
2379
+ expect(uniqueEntityACheck).toBeNull();
2331
2380
 
2332
- expect(await uniqueEntityA.$delete()).toEqual(true);
2333
- });
2381
+ const uniqueEntityBCheck = await nymph.getEntity(
2382
+ { class: TestModel },
2383
+ { type: '&', guid: uniqueEntityB.guid ?? '' },
2384
+ );
2385
+ expect(uniqueEntityBCheck).not.toBeNull();
2334
2386
 
2335
- it('allows duplicate unique string if first transaction is rolled back', async () => {
2336
- // Creating transaction entity...
2337
- const tnymphA = await nymph.startTransaction('test-unique-a');
2338
- const TestModelA = tnymphA.getEntityClass(TestModel);
2339
- const uniqueEntityA = await TestModelA.factory();
2340
- uniqueEntityA.name = 'Entity Test ' + new Date().toLocaleString();
2341
- uniqueEntityA.uniques = ['test a'];
2342
-
2343
- // Saving entity...
2344
- expect(await uniqueEntityA.$save()).toEqual(true);
2345
- expect(uniqueEntityA.guid).not.toBeNull();
2346
-
2347
- // Rolling back transaction...
2348
- expect(await tnymphA.rollback('test-unique-a')).toEqual(true);
2349
-
2350
- // Creating transaction entity...
2351
- const tnymphB = await nymph.startTransaction('test-unique-b');
2352
- const TestModelB = tnymphB.getEntityClass(TestModel);
2353
- const uniqueEntityB = await TestModelB.factory();
2354
- uniqueEntityB.name = 'Entity Test ' + new Date().toLocaleString();
2355
- uniqueEntityB.uniques = ['test a'];
2356
-
2357
- // Saving entity...
2358
- expect(await uniqueEntityB.$save()).toEqual(true);
2359
- expect(uniqueEntityB.guid).not.toBeNull();
2360
-
2361
- expect(uniqueEntityA.guid).not.toEqual(uniqueEntityB.guid);
2362
-
2363
- expect(await tnymphB.commit('test-unique-b')).toEqual(true);
2364
-
2365
- const uniqueEntityACheck = await nymph.getEntity(
2366
- { class: TestModel },
2367
- { type: '&', guid: uniqueEntityA.guid ?? '' },
2368
- );
2369
- expect(uniqueEntityACheck).toBeNull();
2370
-
2371
- const uniqueEntityBCheck = await nymph.getEntity(
2372
- { class: TestModel },
2373
- { type: '&', guid: uniqueEntityB.guid ?? '' },
2374
- );
2375
- expect(uniqueEntityBCheck).not.toBeNull();
2376
-
2377
- if (uniqueEntityBCheck != null) {
2378
- expect(await uniqueEntityBCheck.$delete()).toEqual(true);
2379
- }
2387
+ if (uniqueEntityBCheck != null) {
2388
+ expect(await uniqueEntityBCheck.$delete()).toEqual(true);
2389
+ }
2390
+ });
2380
2391
  });
2381
2392
  }
2382
2393
 
2383
2394
  export function UIDTest(
2384
2395
  nymph: Nymph,
2396
+ describe: (name: string, fn: () => void) => void,
2385
2397
  it: (name: string, fn: () => void) => void,
2386
2398
  ) {
2387
- it('delete old test data', async () => {
2388
- expect(await nymph.deleteUID('TestUID')).toEqual(true);
2389
- expect(await nymph.deleteUID('NewUID')).toEqual(true);
2390
- });
2399
+ describe('UID', () => {
2400
+ it('delete old test data', async () => {
2401
+ expect(await nymph.deleteUID('TestUID')).toEqual(true);
2402
+ expect(await nymph.deleteUID('NewUID')).toEqual(true);
2403
+ });
2391
2404
 
2392
- it('new UID', async () => {
2393
- expect(await nymph.newUID('TestUID')).toEqual(1);
2394
- });
2405
+ it('new UID', async () => {
2406
+ expect(await nymph.newUID('TestUID')).toEqual(1);
2407
+ });
2395
2408
 
2396
- it('increment UID', async () => {
2397
- expect(await nymph.newUID('TestUID')).toEqual(2);
2398
- });
2409
+ it('increment UID', async () => {
2410
+ expect(await nymph.newUID('TestUID')).toEqual(2);
2411
+ });
2399
2412
 
2400
- it('retrieve UID', async () => {
2401
- expect(await nymph.getUID('TestUID')).toEqual(2);
2402
- });
2413
+ it('retrieve UID', async () => {
2414
+ expect(await nymph.getUID('TestUID')).toEqual(2);
2415
+ });
2403
2416
 
2404
- it('rename UID', async () => {
2405
- expect(await nymph.renameUID('TestUID', 'NewUID')).toEqual(true);
2406
- expect(await nymph.getUID('TestUID')).toBeNull();
2407
- expect(await nymph.getUID('NewUID')).toEqual(2);
2408
- expect(await nymph.renameUID('NewUID', 'TestUID')).toEqual(true);
2409
- expect(await nymph.getUID('NewUID')).toBeNull();
2410
- expect(await nymph.getUID('TestUID')).toEqual(2);
2411
- });
2417
+ it('rename UID', async () => {
2418
+ expect(await nymph.renameUID('TestUID', 'NewUID')).toEqual(true);
2419
+ expect(await nymph.getUID('TestUID')).toBeNull();
2420
+ expect(await nymph.getUID('NewUID')).toEqual(2);
2421
+ expect(await nymph.renameUID('NewUID', 'TestUID')).toEqual(true);
2422
+ expect(await nymph.getUID('NewUID')).toBeNull();
2423
+ expect(await nymph.getUID('TestUID')).toEqual(2);
2424
+ });
2412
2425
 
2413
- it('set UID', async () => {
2414
- expect(await nymph.setUID('TestUID', 5)).toEqual(true);
2415
- expect(await nymph.getUID('TestUID')).toEqual(5);
2416
- });
2426
+ it('set UID', async () => {
2427
+ expect(await nymph.setUID('TestUID', 5)).toEqual(true);
2428
+ expect(await nymph.getUID('TestUID')).toEqual(5);
2429
+ });
2417
2430
 
2418
- it('delete UID', async () => {
2419
- expect(await nymph.deleteUID('TestUID')).toEqual(true);
2420
- expect(await nymph.getUID('TestUID')).toBeNull();
2431
+ it('delete UID', async () => {
2432
+ expect(await nymph.deleteUID('TestUID')).toEqual(true);
2433
+ expect(await nymph.getUID('TestUID')).toBeNull();
2434
+ });
2421
2435
  });
2422
2436
  }
2423
2437
 
2424
2438
  export function ExportImportTest(
2425
2439
  nymph: Nymph,
2440
+ describe: (name: string, fn: () => void) => void,
2426
2441
  it: (name: string, fn: () => void) => void,
2427
2442
  ) {
2428
- const TestModel = nymph.addEntityClass(TestModelClass);
2429
- const TestBModel = nymph.addEntityClass(TestBModelClass);
2430
-
2431
- async function deleteTestData() {
2432
- let all = await nymph.getEntities({ class: TestModel });
2433
- expect(Array.isArray(all)).toEqual(true);
2434
- for (const cur of all) {
2435
- expect(await cur.$delete()).toEqual(true);
2436
- }
2437
-
2438
- all = await nymph.getEntities({ class: TestModel });
2439
- expect(all.length).toEqual(0);
2440
-
2441
- all = await nymph.getEntities({ class: TestBModel });
2442
- expect(Array.isArray(all)).toEqual(true);
2443
- for (const cur of all) {
2444
- expect(await cur.$delete()).toEqual(true);
2445
- }
2446
-
2447
- all = await nymph.getEntities({ class: TestBModel });
2448
- expect(all.length).toEqual(0);
2449
-
2450
- expect(await nymph.deleteUID('TestUID')).toEqual(true);
2451
- expect(await nymph.deleteUID('TestUID2')).toEqual(true);
2452
- }
2443
+ describe('Export/Import', () => {
2444
+ const TestModel = nymph.addEntityClass(TestModelClass);
2445
+ const TestBModel = nymph.addEntityClass(TestBModelClass);
2446
+
2447
+ async function deleteTestData() {
2448
+ let all = await nymph.getEntities({ class: TestModel });
2449
+ expect(Array.isArray(all)).toEqual(true);
2450
+ for (const cur of all) {
2451
+ expect(await cur.$delete()).toEqual(true);
2452
+ }
2453
2453
 
2454
- async function checkEntityDataAndCount() {
2455
- expect(await nymph.getUID('TestUID')).toEqual(2);
2456
- expect(await nymph.getUID('TestUID2')).toEqual(1);
2454
+ all = await nymph.getEntities({ class: TestModel });
2455
+ expect(all.length).toEqual(0);
2457
2456
 
2458
- const models = await nymph.getEntities({ class: TestModel });
2459
- const bmodels = await nymph.getEntities({ class: TestBModel });
2457
+ all = await nymph.getEntities({ class: TestBModel });
2458
+ expect(Array.isArray(all)).toEqual(true);
2459
+ for (const cur of all) {
2460
+ expect(await cur.$delete()).toEqual(true);
2461
+ }
2460
2462
 
2461
- expect(models.length).toEqual(30);
2462
- expect(bmodels.length).toEqual(30);
2463
+ all = await nymph.getEntities({ class: TestBModel });
2464
+ expect(all.length).toEqual(0);
2463
2465
 
2464
- for (const model of models) {
2465
- expect(model.name).toMatch(/^Entity Test /);
2466
- expect(model.null).toBeDefined();
2467
- expect(model.null).toBeNull();
2468
- expect(model.string).toEqual('test');
2469
- expect(model.array).toEqual([
2470
- 'full',
2471
- 'of',
2472
- 'values',
2473
- 500,
2474
- { test: true },
2475
- { nullbyte: '\\\x00\u0000 \x00' },
2476
- ]);
2477
- expect(model.match).toEqual(matchValue);
2478
- expect(model.number).toEqual(30);
2479
- expect(model.numberString).toEqual('30');
2480
- expect(model.timestamp).toBeGreaterThanOrEqual(
2481
- strtotime('-2 minutes') || 0,
2482
- );
2483
- expect(model.index).toMatch(/^\d+a$/);
2484
-
2485
- await model.reference?.$wake();
2486
- expect(model.reference?.guid).not.toBeNull();
2487
- expect(model.reference?.string).toEqual('another');
2488
- expect(model.reference?.index).toMatch(/^\d+b$/);
2489
- expect(model.index?.substring(0, -1)).toEqual(
2490
- model.reference?.index?.substring(0, -1),
2491
- );
2492
- expect(model.reference?.$inArray(bmodels)).toEqual(true);
2493
- await Promise.all(model.refArray?.map((e) => e.$wake()) || []);
2494
- expect(model.refArray?.[0].guid).not.toBeNull();
2495
- expect(model.refArray?.[0].guid).toEqual(model.reference?.guid);
2466
+ expect(await nymph.deleteUID('TestUID')).toEqual(true);
2467
+ expect(await nymph.deleteUID('TestUID2')).toEqual(true);
2496
2468
  }
2497
- }
2498
2469
 
2499
- it('delete old test data', async () => {
2500
- await deleteTestData();
2501
- });
2470
+ async function checkEntityDataAndCount() {
2471
+ expect(await nymph.getUID('TestUID')).toEqual(2);
2472
+ expect(await nymph.getUID('TestUID2')).toEqual(1);
2473
+
2474
+ const models = await nymph.getEntities({ class: TestModel });
2475
+ const bmodels = await nymph.getEntities({ class: TestBModel });
2476
+
2477
+ expect(models.length).toEqual(30);
2478
+ expect(bmodels.length).toEqual(30);
2479
+
2480
+ for (const model of models) {
2481
+ expect(model.name).toMatch(/^Entity Test /);
2482
+ expect(model.null).toBeDefined();
2483
+ expect(model.null).toBeNull();
2484
+ expect(model.string).toEqual('test');
2485
+ expect(model.array).toEqual([
2486
+ 'full',
2487
+ 'of',
2488
+ 'values',
2489
+ 500,
2490
+ { test: true },
2491
+ { nullbyte: '\\\x00\u0000 \x00' },
2492
+ ]);
2493
+ expect(model.match).toEqual(matchValue);
2494
+ expect(model.number).toEqual(30);
2495
+ expect(model.numberString).toEqual('30');
2496
+ expect(model.timestamp).toBeGreaterThanOrEqual(
2497
+ strtotime('-2 minutes') || 0,
2498
+ );
2499
+ expect(model.index).toMatch(/^\d+a$/);
2500
+
2501
+ await model.reference?.$wake();
2502
+ expect(model.reference?.guid).not.toBeNull();
2503
+ expect(model.reference?.string).toEqual('another');
2504
+ expect(model.reference?.index).toMatch(/^\d+b$/);
2505
+ expect(model.index?.substring(0, -1)).toEqual(
2506
+ model.reference?.index?.substring(0, -1),
2507
+ );
2508
+ expect(model.reference?.$inArray(bmodels)).toEqual(true);
2509
+ await Promise.all(model.refArray?.map((e) => e.$wake()) || []);
2510
+ expect(model.refArray?.[0].guid).not.toBeNull();
2511
+ expect(model.refArray?.[0].guid).toEqual(model.reference?.guid);
2512
+ }
2513
+ }
2502
2514
 
2503
- it('setup data', async () => {
2504
- expect(await nymph.newUID('TestUID')).toEqual(1);
2505
- expect(await nymph.newUID('TestUID')).toEqual(2);
2506
- expect(await nymph.newUID('TestUID2')).toEqual(1);
2515
+ it('delete old test data', async () => {
2516
+ await deleteTestData();
2517
+ });
2507
2518
 
2508
- for (let i = 0; i < 30; i++) {
2509
- // Creating entity...
2510
- const testEntity = await TestModel.factory();
2519
+ it('setup data', async () => {
2520
+ expect(await nymph.newUID('TestUID')).toEqual(1);
2521
+ expect(await nymph.newUID('TestUID')).toEqual(2);
2522
+ expect(await nymph.newUID('TestUID2')).toEqual(1);
2511
2523
 
2512
- // Saving entity...
2513
- testEntity.name = 'Entity Test ' + new Date().toLocaleString();
2514
- testEntity.null = null;
2515
- testEntity.string = 'test';
2516
- testEntity.array = [
2517
- 'full',
2518
- 'of',
2519
- 'values',
2520
- 500,
2521
- { test: true },
2522
- { nullbyte: '\\\x00\u0000 \x00' },
2523
- ];
2524
- testEntity.match = matchValue;
2525
- testEntity.number = 30;
2526
- testEntity.numberString = '30';
2527
- testEntity.timestamp = Date.now();
2528
- testEntity.index = i + 'a';
2524
+ for (let i = 0; i < 30; i++) {
2525
+ // Creating entity...
2526
+ const testEntity = await TestModel.factory();
2529
2527
 
2530
- const entityReferenceTest = await TestBModel.factory();
2531
- entityReferenceTest.string = 'another';
2532
- entityReferenceTest.index = i + 'b';
2528
+ // Saving entity...
2529
+ testEntity.name = 'Entity Test ' + new Date().toLocaleString();
2530
+ testEntity.null = null;
2531
+ testEntity.string = 'test';
2532
+ testEntity.array = [
2533
+ 'full',
2534
+ 'of',
2535
+ 'values',
2536
+ 500,
2537
+ { test: true },
2538
+ { nullbyte: '\\\x00\u0000 \x00' },
2539
+ ];
2540
+ testEntity.match = matchValue;
2541
+ testEntity.number = 30;
2542
+ testEntity.numberString = '30';
2543
+ testEntity.timestamp = Date.now();
2544
+ testEntity.index = i + 'a';
2545
+
2546
+ const entityReferenceTest = await TestBModel.factory();
2547
+ entityReferenceTest.string = 'another';
2548
+ entityReferenceTest.index = i + 'b';
2549
+
2550
+ expect(await entityReferenceTest.$save()).toEqual(true);
2551
+ testEntity.reference = entityReferenceTest;
2552
+ testEntity.refArray = [entityReferenceTest];
2533
2553
 
2534
- expect(await entityReferenceTest.$save()).toEqual(true);
2535
- testEntity.reference = entityReferenceTest;
2536
- testEntity.refArray = [entityReferenceTest];
2554
+ expect(await testEntity.$save()).toEqual(true);
2555
+ }
2537
2556
 
2538
- expect(await testEntity.$save()).toEqual(true);
2539
- }
2557
+ await checkEntityDataAndCount();
2558
+ });
2540
2559
 
2541
- await checkEntityDataAndCount();
2542
- });
2560
+ it('needs migration', async () => {
2561
+ expect(await nymph.needsMigration()).toEqual(false);
2562
+ });
2543
2563
 
2544
- it('needs migration', async () => {
2545
- expect(await nymph.needsMigration()).toEqual(false);
2546
- });
2564
+ it('export data', async () => {
2565
+ expect(await nymph.export(__dirname + '/testentityexport.nex')).toEqual(
2566
+ true,
2567
+ );
2568
+ });
2547
2569
 
2548
- it('export data', async () => {
2549
- expect(await nymph.export(__dirname + '/testentityexport.nex')).toEqual(
2550
- true,
2551
- );
2552
- });
2570
+ it('delete test data again', async () => {
2571
+ await deleteTestData();
2572
+ });
2553
2573
 
2554
- it('delete test data again', async () => {
2555
- await deleteTestData();
2556
- });
2574
+ it('import data', async () => {
2575
+ expect(await nymph.getUID('TestUID')).toBeNull();
2576
+ expect(await nymph.getUID('TestUID2')).toBeNull();
2577
+ const models = await nymph.getEntities({ class: TestModel });
2578
+ const bmodels = await nymph.getEntities({ class: TestBModel });
2579
+ expect(models.length).toEqual(0);
2580
+ expect(bmodels.length).toEqual(0);
2557
2581
 
2558
- it('import data', async () => {
2559
- expect(await nymph.getUID('TestUID')).toBeNull();
2560
- expect(await nymph.getUID('TestUID2')).toBeNull();
2561
- const models = await nymph.getEntities({ class: TestModel });
2562
- const bmodels = await nymph.getEntities({ class: TestBModel });
2563
- expect(models.length).toEqual(0);
2564
- expect(bmodels.length).toEqual(0);
2582
+ expect(
2583
+ await nymph.import(__dirname + '/testentityexport.nex', {
2584
+ ignoreUnknownETypes: true,
2585
+ }),
2586
+ ).toEqual(true);
2565
2587
 
2566
- expect(
2567
- await nymph.import(__dirname + '/testentityexport.nex', {
2568
- ignoreUnknownETypes: true,
2569
- }),
2570
- ).toEqual(true);
2588
+ await checkEntityDataAndCount();
2571
2589
 
2572
- await checkEntityDataAndCount();
2590
+ fs.unlinkSync(__dirname + '/testentityexport.nex');
2591
+ });
2573
2592
 
2574
- fs.unlinkSync(__dirname + '/testentityexport.nex');
2575
- });
2593
+ it('import tokens only', async () => {
2594
+ const model = await nymph.getEntity({ class: TestModel });
2576
2595
 
2577
- it('import tokens only', async () => {
2578
- const model = await nymph.getEntity({ class: TestModel });
2596
+ expect(model).not.toBeNull();
2579
2597
 
2580
- expect(model).not.toBeNull();
2598
+ if (model != null) {
2599
+ const data = model.$getData(true);
2600
+ // These should not actually be saved in the DB.
2601
+ data.number = 424242424242;
2602
+ // But this should become searchable.
2603
+ data.search = 'peanuts and pickles on a hot bun';
2581
2604
 
2582
- if (model != null) {
2583
- const data = model.$getData(true);
2584
- // These should not actually be saved in the DB.
2585
- data.number = 424242424242;
2586
- // But this should become searchable.
2587
- data.search = 'peanuts and pickles on a hot bun';
2605
+ const sdata = Object.fromEntries(
2606
+ Object.entries(data).map(([name, value]) => [
2607
+ name,
2608
+ JSON.stringify(value),
2609
+ ]),
2610
+ );
2588
2611
 
2589
- const sdata = Object.fromEntries(
2590
- Object.entries(data).map(([name, value]) => [
2591
- name,
2592
- JSON.stringify(value),
2593
- ]),
2594
- );
2612
+ if (model.guid == null || model.cdate == null || model.mdate == null) {
2613
+ throw new Error('Model data is wrong.');
2614
+ }
2615
+
2616
+ await nymph.importEntityTokens({
2617
+ guid: model.guid,
2618
+ // Again, these should not actually be changed in the DB.
2619
+ cdate: model.cdate + 1000,
2620
+ mdate: model.mdate + 1000,
2621
+ tags: [...model.tags, 'helicopter'],
2622
+ sdata,
2623
+ etype: TestModel.ETYPE,
2624
+ });
2625
+
2626
+ const modelCheck = await nymph.getEntity(
2627
+ { class: TestModel },
2628
+ {
2629
+ type: '&',
2630
+ search: ['search', '"peanuts and pickles on a hot bun"'],
2631
+ },
2632
+ );
2595
2633
 
2596
- if (model.guid == null || model.cdate == null || model.mdate == null) {
2597
- throw new Error('Model data is wrong.');
2634
+ expect(modelCheck?.guid).toEqual(model.guid);
2635
+ expect(modelCheck?.cdate).toEqual(model.cdate);
2636
+ expect(modelCheck?.mdate).toEqual(model.mdate);
2637
+ expect(modelCheck?.$hasTag('helicopter')).toEqual(false);
2638
+ expect(modelCheck?.number).not.toEqual(424242424242);
2639
+ expect(modelCheck?.search).not.toEqual(
2640
+ 'peanuts and pickles on a hot bun',
2641
+ );
2598
2642
  }
2599
-
2600
- await nymph.importEntityTokens({
2601
- guid: model.guid,
2602
- // Again, these should not actually be changed in the DB.
2603
- cdate: model.cdate + 1000,
2604
- mdate: model.mdate + 1000,
2605
- tags: [...model.tags, 'helicopter'],
2606
- sdata,
2607
- etype: TestModel.ETYPE,
2608
- });
2609
-
2610
- const modelCheck = await nymph.getEntity(
2611
- { class: TestModel },
2612
- { type: '&', search: ['search', '"peanuts and pickles on a hot bun"'] },
2613
- );
2614
-
2615
- expect(modelCheck?.guid).toEqual(model.guid);
2616
- expect(modelCheck?.cdate).toEqual(model.cdate);
2617
- expect(modelCheck?.mdate).toEqual(model.mdate);
2618
- expect(modelCheck?.$hasTag('helicopter')).toEqual(false);
2619
- expect(modelCheck?.number).not.toEqual(424242424242);
2620
- expect(modelCheck?.search).not.toEqual(
2621
- 'peanuts and pickles on a hot bun',
2622
- );
2623
- }
2643
+ });
2624
2644
  });
2625
2645
  }
2626
2646