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