@nymphjs/nymph 1.0.0-beta.13 → 1.0.0-beta.130
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 +644 -0
- package/README.md +34 -24
- package/dist/Entity.d.ts +304 -15
- package/dist/Entity.js +609 -154
- package/dist/Entity.js.map +1 -1
- package/dist/Entity.test.js +75 -29
- package/dist/Entity.test.js.map +1 -1
- package/dist/Entity.types.d.ts +275 -28
- package/dist/Entity.types.js +1 -2
- package/dist/Nymph.d.ts +575 -11
- package/dist/Nymph.js +825 -288
- package/dist/Nymph.js.map +1 -1
- package/dist/Nymph.types.d.ts +117 -7
- package/dist/Nymph.types.js +47 -5
- package/dist/Nymph.types.js.map +1 -1
- package/dist/conf/defaults.d.ts +1 -1
- package/dist/conf/defaults.js +26 -3
- package/dist/conf/defaults.js.map +1 -1
- package/dist/conf/index.d.ts +50 -2
- package/dist/conf/index.js +2 -8
- package/dist/conf/index.js.map +1 -1
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +2 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/transactional.d.ts +12 -0
- package/dist/decorators/transactional.js +45 -0
- package/dist/decorators/transactional.js.map +1 -0
- package/dist/driver/NymphDriver.d.ts +209 -41
- package/dist/driver/NymphDriver.js +737 -242
- package/dist/driver/NymphDriver.js.map +1 -1
- package/dist/driver/index.d.ts +1 -2
- package/dist/driver/index.js +2 -23
- package/dist/driver/index.js.map +1 -1
- package/dist/driver/testArtifacts.d.ts +4 -4
- package/dist/driver/testArtifacts.js +2016 -1086
- package/dist/driver/testArtifacts.js.map +1 -1
- package/dist/errors/ClassNotAvailableError.js +1 -5
- package/dist/errors/ClassNotAvailableError.js.map +1 -1
- package/dist/errors/EntityConflictError.js +1 -5
- package/dist/errors/EntityConflictError.js.map +1 -1
- package/dist/errors/EntityInvalidDataError.d.ts +6 -0
- package/dist/errors/EntityInvalidDataError.js +8 -6
- package/dist/errors/EntityInvalidDataError.js.map +1 -1
- package/dist/errors/EntityIsSleepingReferenceError.js +1 -5
- package/dist/errors/EntityIsSleepingReferenceError.js.map +1 -1
- package/dist/errors/EntityUniqueConstraintError.d.ts +3 -0
- package/dist/errors/EntityUniqueConstraintError.js +7 -0
- package/dist/errors/EntityUniqueConstraintError.js.map +1 -0
- package/dist/errors/HttpError.d.ts +5 -0
- package/dist/errors/HttpError.js +11 -0
- package/dist/errors/HttpError.js.map +1 -0
- package/dist/errors/InvalidParametersError.js +1 -5
- package/dist/errors/InvalidParametersError.js.map +1 -1
- package/dist/errors/InvalidStateError.d.ts +3 -0
- package/dist/errors/InvalidStateError.js +7 -0
- package/dist/errors/InvalidStateError.js.map +1 -0
- package/dist/errors/MethodFailedError.d.ts +3 -0
- package/dist/errors/MethodFailedError.js +7 -0
- package/dist/errors/MethodFailedError.js.map +1 -0
- package/dist/errors/NotConfiguredError.js +1 -5
- package/dist/errors/NotConfiguredError.js.map +1 -1
- package/dist/errors/QueryFailedError.d.ts +2 -1
- package/dist/errors/QueryFailedError.js +5 -6
- package/dist/errors/QueryFailedError.js.map +1 -1
- package/dist/errors/UnableToConnectError.js +1 -5
- package/dist/errors/UnableToConnectError.js.map +1 -1
- package/dist/errors/index.d.ts +12 -8
- package/dist/errors/index.js +12 -24
- package/dist/errors/index.js.map +1 -1
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.js +2 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/transaction.d.ts +15 -0
- package/dist/helpers/transaction.js +47 -0
- package/dist/helpers/transaction.js.map +1 -0
- package/dist/index.d.ts +13 -11
- package/dist/index.js +16 -34
- package/dist/index.js.map +1 -1
- package/dist/nymphJoiProps.d.ts +1 -1
- package/dist/nymphJoiProps.js +10 -15
- package/dist/nymphJoiProps.js.map +1 -1
- package/dist/testArtifacts.d.ts +21 -6
- package/dist/testArtifacts.js +124 -50
- package/dist/testArtifacts.js.map +1 -1
- package/dist/testMocks.d.ts +27 -12
- package/dist/testMocks.js +44 -33
- package/dist/testMocks.js.map +1 -1
- package/dist/utils.d.ts +5 -5
- package/dist/utils.js +106 -68
- package/dist/utils.js.map +1 -1
- package/jest.config.js +31 -5
- package/package.json +43 -24
- package/src/Entity.test.ts +73 -23
- package/src/Entity.ts +555 -169
- package/src/Entity.types.ts +102 -90
- package/src/Nymph.ts +930 -517
- package/src/Nymph.types.ts +145 -39
- package/src/conf/defaults.ts +34 -1
- package/src/conf/index.ts +50 -2
- package/src/decorators/index.ts +1 -0
- package/src/decorators/transactional.ts +63 -0
- package/src/driver/NymphDriver.ts +987 -417
- package/src/driver/index.ts +1 -3
- package/src/driver/testArtifacts.ts +2699 -1628
- package/src/errors/EntityUniqueConstraintError.ts +6 -0
- package/src/errors/HttpError.ts +12 -0
- package/src/errors/InvalidStateError.ts +6 -0
- package/src/errors/MethodFailedError.ts +6 -0
- package/src/errors/QueryFailedError.ts +3 -1
- package/src/errors/index.ts +16 -8
- package/src/helpers/index.ts +1 -0
- package/src/helpers/transaction.ts +65 -0
- package/src/index.ts +13 -11
- package/src/nymphJoiProps.ts +2 -2
- package/src/testArtifacts.ts +69 -20
- package/src/testMocks.ts +107 -41
- package/src/utils.ts +102 -67
- package/tsconfig.json +6 -3
- package/typedoc.json +4 -0
- package/dist/conf/d.d.ts +0 -6
- package/dist/conf/d.js +0 -3
- package/dist/conf/d.js.map +0 -1
- package/src/conf/d.ts +0 -24
package/src/Entity.test.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jest } from '@jest/globals';
|
|
2
|
+
|
|
3
|
+
import { cloneDeep } from 'lodash-es';
|
|
4
|
+
|
|
5
|
+
import { EntityConflictError } from './errors/index.js';
|
|
6
|
+
import { MockNymph } from './testMocks.js';
|
|
2
7
|
import {
|
|
3
8
|
TestBModel as TestBModelClass,
|
|
4
9
|
TestModel as TestModelClass,
|
|
5
10
|
TestModelData,
|
|
6
|
-
} from './testArtifacts';
|
|
7
|
-
import { cloneDeep } from 'lodash';
|
|
11
|
+
} from './testArtifacts.js';
|
|
8
12
|
|
|
9
13
|
const nymph = new MockNymph();
|
|
10
14
|
|
|
@@ -41,22 +45,22 @@ describe('Entity', () => {
|
|
|
41
45
|
expect(testEntity.array).toEqual(['full', 'of', 'values', 500]);
|
|
42
46
|
expect(testEntity.number).toEqual(30);
|
|
43
47
|
|
|
44
|
-
|
|
48
|
+
await testEntity.$save();
|
|
45
49
|
expect(typeof testEntity.guid).toEqual('string');
|
|
46
50
|
|
|
47
51
|
entityReferenceTest = await TestModel.factory();
|
|
48
52
|
entityReferenceTest.string = 'wrong';
|
|
49
|
-
|
|
53
|
+
await entityReferenceTest.$save();
|
|
50
54
|
entityReferenceGuid = entityReferenceTest.guid as string;
|
|
51
55
|
testEntity.reference = entityReferenceTest;
|
|
52
56
|
testEntity.refArray = [entityReferenceTest];
|
|
53
57
|
testEntity.refObject = {
|
|
54
58
|
entity: entityReferenceTest,
|
|
55
59
|
};
|
|
56
|
-
|
|
60
|
+
await testEntity.$save();
|
|
57
61
|
|
|
58
62
|
entityReferenceTest.test = 'good';
|
|
59
|
-
|
|
63
|
+
await entityReferenceTest.$save();
|
|
60
64
|
});
|
|
61
65
|
|
|
62
66
|
it('comparisons work', async () => {
|
|
@@ -115,14 +119,14 @@ describe('Entity', () => {
|
|
|
115
119
|
it('refresh updates', async () => {
|
|
116
120
|
expect(testEntity.string).toEqual('test');
|
|
117
121
|
testEntity.string = 'updated';
|
|
118
|
-
|
|
122
|
+
await testEntity.$save();
|
|
119
123
|
await testEntity.$refresh();
|
|
120
|
-
|
|
124
|
+
await testEntity.$save();
|
|
121
125
|
|
|
122
126
|
const retrieve = await TestModel.factory(testEntity.guid as string);
|
|
123
127
|
expect(retrieve.string).toEqual('updated');
|
|
124
128
|
retrieve.string = 'test';
|
|
125
|
-
|
|
129
|
+
await retrieve.$save();
|
|
126
130
|
|
|
127
131
|
await testEntity.$refresh();
|
|
128
132
|
expect(testEntity.string).toEqual('test');
|
|
@@ -132,17 +136,23 @@ describe('Entity', () => {
|
|
|
132
136
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
133
137
|
|
|
134
138
|
const testEntityCopy = await TestModel.factory(testEntity.guid as string);
|
|
135
|
-
|
|
139
|
+
await testEntityCopy.$save();
|
|
136
140
|
expect(testEntityCopy.mdate ?? 0).toBeGreaterThan(testEntity.mdate ?? 0);
|
|
137
141
|
|
|
138
142
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
139
143
|
|
|
140
|
-
|
|
144
|
+
try {
|
|
145
|
+
await testEntity.$save();
|
|
146
|
+
|
|
147
|
+
throw new Error('Should have thrown.');
|
|
148
|
+
} catch (e: any) {
|
|
149
|
+
expect(e).toBeInstanceOf(EntityConflictError);
|
|
150
|
+
}
|
|
141
151
|
|
|
142
152
|
await testEntity.$refresh();
|
|
143
153
|
|
|
144
154
|
expect(testEntityCopy.mdate ?? Infinity).toBeLessThanOrEqual(
|
|
145
|
-
testEntity.mdate ?? 0
|
|
155
|
+
testEntity.mdate ?? 0,
|
|
146
156
|
);
|
|
147
157
|
});
|
|
148
158
|
|
|
@@ -156,13 +166,25 @@ describe('Entity', () => {
|
|
|
156
166
|
]);
|
|
157
167
|
});
|
|
158
168
|
|
|
169
|
+
it('toReference works even on an unsaved entity', () => {
|
|
170
|
+
const unsavedEntity = TestModel.factorySync();
|
|
171
|
+
const reference = unsavedEntity.$toReference();
|
|
172
|
+
|
|
173
|
+
expect(unsavedEntity.guid).toBeNull();
|
|
174
|
+
expect(reference).toEqual([
|
|
175
|
+
'nymph_entity_reference',
|
|
176
|
+
unsavedEntity.$getGuaranteedGUID(),
|
|
177
|
+
'TestModel',
|
|
178
|
+
]);
|
|
179
|
+
});
|
|
180
|
+
|
|
159
181
|
it('tags work', async () => {
|
|
160
182
|
expect(testEntity.$hasTag('test')).toEqual(true);
|
|
161
183
|
testEntity.$addTag('test', 'test2');
|
|
162
184
|
expect(testEntity.$hasTag('test', 'test2')).toEqual(true);
|
|
163
185
|
testEntity.$addTag('test', 'test3', 'test4', 'test5', 'test6');
|
|
164
186
|
expect(
|
|
165
|
-
testEntity.$hasTag('test', 'test3', 'test4', 'test5', 'test6')
|
|
187
|
+
testEntity.$hasTag('test', 'test3', 'test4', 'test5', 'test6'),
|
|
166
188
|
).toEqual(true);
|
|
167
189
|
testEntity.$removeTag('test2');
|
|
168
190
|
expect(testEntity.$hasTag('test2')).toEqual(false);
|
|
@@ -174,36 +196,43 @@ describe('Entity', () => {
|
|
|
174
196
|
|
|
175
197
|
// Remove all tags.
|
|
176
198
|
testEntity.$removeTag('test');
|
|
177
|
-
|
|
199
|
+
await testEntity.$save();
|
|
178
200
|
expect(await testEntity.$refresh()).toEqual(true);
|
|
179
201
|
expect(testEntity.$hasTag('test')).toEqual(false);
|
|
180
202
|
expect(testEntity.$getTags()).toEqual([]);
|
|
181
203
|
testEntity.$addTag('test');
|
|
182
|
-
|
|
204
|
+
await testEntity.$save();
|
|
183
205
|
expect(testEntity.$hasTag('test')).toEqual(true);
|
|
184
206
|
});
|
|
185
207
|
|
|
186
|
-
it('references
|
|
208
|
+
it('references work', async () => {
|
|
187
209
|
await testEntity.$refresh();
|
|
188
210
|
|
|
211
|
+
await testEntity.reference?.$wake();
|
|
189
212
|
expect(testEntity.reference?.guid).toEqual(entityReferenceGuid);
|
|
213
|
+
await Promise.all(testEntity.refArray?.map((e) => e.$wake()) || []);
|
|
190
214
|
expect(testEntity.refArray?.[0].guid).toEqual(entityReferenceGuid);
|
|
215
|
+
await testEntity.refObject?.entity.$wake();
|
|
191
216
|
expect(testEntity.refObject?.entity.guid).toEqual(entityReferenceGuid);
|
|
192
217
|
|
|
193
218
|
const entity = await TestModel.factory(testEntity.guid as string);
|
|
194
219
|
|
|
220
|
+
await entity.reference?.$wake();
|
|
195
221
|
expect(entity.reference?.guid).toEqual(entityReferenceGuid);
|
|
222
|
+
await Promise.all(entity.refArray?.map((e) => e.$wake()) || []);
|
|
196
223
|
expect(entity.refArray?.[0].guid).toEqual(entityReferenceGuid);
|
|
224
|
+
await entity.refObject?.entity.$wake();
|
|
197
225
|
expect(entity.refObject?.entity.guid).toEqual(entityReferenceGuid);
|
|
198
226
|
});
|
|
199
227
|
|
|
200
|
-
it('sleeping references wake up', () => {
|
|
228
|
+
it('sleeping references wake up', async () => {
|
|
201
229
|
const entity = TestModel.factoryReference([
|
|
202
230
|
'nymph_entity_reference',
|
|
203
231
|
testEntity.guid as string,
|
|
204
232
|
'TestModel',
|
|
205
233
|
]) as TestModelClass & TestModelData;
|
|
206
234
|
|
|
235
|
+
await entity.$wake();
|
|
207
236
|
expect(entity.guid).toEqual(testEntity.guid);
|
|
208
237
|
expect(entity.cdate).toEqual(testEntity.cdate);
|
|
209
238
|
expect(entity.mdate).toEqual(testEntity.mdate);
|
|
@@ -213,8 +242,11 @@ describe('Entity', () => {
|
|
|
213
242
|
expect(entity.string).toEqual('test');
|
|
214
243
|
expect(entity.array).toEqual(['full', 'of', 'values', 500]);
|
|
215
244
|
expect(entity.number).toEqual(30);
|
|
245
|
+
await entity.reference?.$wake();
|
|
216
246
|
expect(entity.reference?.guid).toEqual(entityReferenceGuid);
|
|
247
|
+
await Promise.all(entity.refArray?.map((e) => e.$wake()) || []);
|
|
217
248
|
expect(entity.refArray?.[0].guid).toEqual(entityReferenceGuid);
|
|
249
|
+
await entity.refObject?.entity.$wake();
|
|
218
250
|
expect(entity.refObject?.entity.guid).toEqual(entityReferenceGuid);
|
|
219
251
|
});
|
|
220
252
|
|
|
@@ -239,8 +271,9 @@ describe('Entity', () => {
|
|
|
239
271
|
array: ['full', 'of', 'values', 500],
|
|
240
272
|
string: 'test',
|
|
241
273
|
null: null,
|
|
274
|
+
uniques: [],
|
|
242
275
|
},
|
|
243
|
-
class: 'TestModel',
|
|
276
|
+
class: ['nymph_class_reference', 'TestModel'],
|
|
244
277
|
});
|
|
245
278
|
});
|
|
246
279
|
|
|
@@ -288,8 +321,11 @@ describe('Entity', () => {
|
|
|
288
321
|
expect(testEntity.string).toEqual('good');
|
|
289
322
|
expect(testEntity.array).toEqual(['imanarray']);
|
|
290
323
|
expect(testEntity.number).toEqual(30);
|
|
324
|
+
await testEntity.reference?.$wake();
|
|
291
325
|
expect(testEntity.reference?.guid).toEqual(entityReferenceGuid);
|
|
326
|
+
await Promise.all(testEntity.refArray?.map((e) => e.$wake()) || []);
|
|
292
327
|
expect(testEntity.refArray?.[0].guid).toEqual(entityReferenceGuid);
|
|
328
|
+
await testEntity.refObject?.entity.$wake();
|
|
293
329
|
expect(testEntity.refObject?.entity.guid).toEqual(entityReferenceGuid);
|
|
294
330
|
|
|
295
331
|
expect(await testEntity.$refresh()).toEqual(true);
|
|
@@ -297,7 +333,7 @@ describe('Entity', () => {
|
|
|
297
333
|
testEntity.cdate = 13;
|
|
298
334
|
testEntity.mdate = 14;
|
|
299
335
|
testEntity.$jsonAcceptPatch({
|
|
300
|
-
class: TestModel
|
|
336
|
+
class: TestModel,
|
|
301
337
|
guid: testEntity.guid as string,
|
|
302
338
|
mdate: 15,
|
|
303
339
|
set: {
|
|
@@ -311,7 +347,9 @@ describe('Entity', () => {
|
|
|
311
347
|
expect(testEntity.$hasTag('notag')).toEqual(false);
|
|
312
348
|
expect(testEntity.$hasTag('test')).toEqual(true);
|
|
313
349
|
expect(testEntity.$hasTag('newtag')).toEqual(true);
|
|
350
|
+
await testEntity.reference?.$wake();
|
|
314
351
|
expect(testEntity.reference?.guid).toEqual(entityReferenceGuid);
|
|
352
|
+
await Promise.all(testEntity.refArray?.map((e) => e.$wake()) || []);
|
|
315
353
|
expect(testEntity.refArray?.[0].guid).toEqual(entityReferenceGuid);
|
|
316
354
|
|
|
317
355
|
expect(await testEntity.$refresh()).toEqual(true);
|
|
@@ -341,7 +379,7 @@ describe('Entity', () => {
|
|
|
341
379
|
testEntity.cdate = 13;
|
|
342
380
|
testEntity.mdate = 14;
|
|
343
381
|
testEntity.$jsonAcceptPatch({
|
|
344
|
-
class: TestModel
|
|
382
|
+
class: TestModel,
|
|
345
383
|
guid: testEntity.guid as string,
|
|
346
384
|
mdate: 15,
|
|
347
385
|
set: {
|
|
@@ -365,7 +403,7 @@ describe('Entity', () => {
|
|
|
365
403
|
// Test that an old JSON payload causes a conflict.
|
|
366
404
|
const json = JSON.stringify(testEntity);
|
|
367
405
|
|
|
368
|
-
|
|
406
|
+
await testEntity.$save();
|
|
369
407
|
|
|
370
408
|
let thrown = false;
|
|
371
409
|
let thrownName: string = '';
|
|
@@ -386,7 +424,7 @@ describe('Entity', () => {
|
|
|
386
424
|
|
|
387
425
|
try {
|
|
388
426
|
testEntity.$jsonAcceptPatch({
|
|
389
|
-
class: TestModel
|
|
427
|
+
class: TestModel,
|
|
390
428
|
guid: data.guid,
|
|
391
429
|
mdate: data.mdate,
|
|
392
430
|
set: {
|
|
@@ -403,4 +441,16 @@ describe('Entity', () => {
|
|
|
403
441
|
|
|
404
442
|
expect(thrown).toEqual(true);
|
|
405
443
|
});
|
|
444
|
+
|
|
445
|
+
it('JSON with new entities works', async () => {
|
|
446
|
+
testEntity.reference = await TestModel.factory();
|
|
447
|
+
|
|
448
|
+
// Test that an old JSON payload causes a conflict.
|
|
449
|
+
const json = JSON.stringify(testEntity);
|
|
450
|
+
const data = JSON.parse(json);
|
|
451
|
+
|
|
452
|
+
testEntity.$jsonAcceptData(data);
|
|
453
|
+
|
|
454
|
+
expect(testEntity.reference.guid).toBeNull();
|
|
455
|
+
});
|
|
406
456
|
});
|