@nymphjs/nymph 1.0.0-beta.9 → 1.0.0-beta.91
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 +436 -0
- package/README.md +10 -20
- package/dist/Entity.d.ts +277 -10
- package/dist/Entity.js +543 -148
- package/dist/Entity.js.map +1 -1
- package/dist/Entity.test.js +53 -13
- package/dist/Entity.test.js.map +1 -1
- package/dist/Entity.types.d.ts +249 -23
- package/dist/Entity.types.js +1 -2
- package/dist/Nymph.d.ts +431 -12
- package/dist/Nymph.js +692 -180
- package/dist/Nymph.js.map +1 -1
- package/dist/Nymph.types.d.ts +65 -7
- package/dist/Nymph.types.js +3 -5
- package/dist/Nymph.types.js.map +1 -1
- package/dist/conf/d.d.ts +43 -0
- package/dist/conf/d.js +1 -2
- 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 +2 -2
- package/dist/conf/index.js +2 -8
- package/dist/conf/index.js.map +1 -1
- package/dist/driver/NymphDriver.d.ts +137 -39
- package/dist/driver/NymphDriver.js +344 -194
- package/dist/driver/NymphDriver.js.map +1 -1
- package/dist/driver/index.d.ts +2 -2
- package/dist/driver/index.js +3 -23
- package/dist/driver/index.js.map +1 -1
- package/dist/driver/testArtifacts.d.ts +2 -2
- package/dist/driver/testArtifacts.js +557 -92
- 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/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/NotConfiguredError.js +1 -5
- package/dist/errors/NotConfiguredError.js.map +1 -1
- package/dist/errors/QueryFailedError.js +2 -5
- 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 +10 -8
- package/dist/errors/index.js +10 -24
- package/dist/errors/index.js.map +1 -1
- package/dist/index.d.ts +11 -11
- package/dist/index.js +14 -34
- package/dist/index.js.map +1 -1
- package/dist/nymphJoiProps.js +10 -15
- package/dist/nymphJoiProps.js.map +1 -1
- package/dist/testArtifacts.d.ts +18 -6
- package/dist/testArtifacts.js +32 -37
- package/dist/testArtifacts.js.map +1 -1
- package/dist/testMocks.d.ts +15 -12
- package/dist/testMocks.js +40 -29
- package/dist/testMocks.js.map +1 -1
- package/dist/utils.d.ts +4 -4
- package/dist/utils.js +40 -29
- package/dist/utils.js.map +1 -1
- package/jest.config.js +11 -2
- package/package.json +22 -19
- package/src/Entity.test.ts +52 -7
- package/src/Entity.ts +458 -147
- package/src/Entity.types.ts +64 -74
- package/src/Nymph.ts +754 -321
- package/src/Nymph.types.ts +131 -26
- package/src/conf/d.ts +25 -0
- package/src/conf/defaults.ts +34 -1
- package/src/conf/index.ts +2 -2
- package/src/driver/NymphDriver.ts +362 -359
- package/src/driver/index.ts +2 -2
- package/src/driver/testArtifacts.ts +609 -185
- package/src/errors/EntityUniqueConstraintError.ts +6 -0
- package/src/errors/InvalidStateError.ts +6 -0
- package/src/errors/index.ts +12 -8
- package/src/index.ts +11 -11
- package/src/nymphJoiProps.ts +2 -2
- package/src/testArtifacts.ts +19 -20
- package/src/testMocks.ts +60 -35
- package/src/type/locutus.d.ts +3 -0
- package/src/utils.ts +39 -18
- package/tsconfig.json +5 -3
- package/typedoc.json +4 -0
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nymphjs/nymph",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
4
|
-
"description": "
|
|
5
|
-
"type": "
|
|
3
|
+
"version": "1.0.0-beta.91",
|
|
4
|
+
"description": "Nymph.js - Nymph ORM",
|
|
5
|
+
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"keywords": [
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"clean": "test -d dist && rm -r dist || true",
|
|
15
15
|
"build": "tsc",
|
|
16
16
|
"watch": "tsc --watch",
|
|
17
|
-
"
|
|
18
|
-
"test": "jest",
|
|
19
|
-
"test:watch": "jest --watch"
|
|
17
|
+
"prepublish": "npm run clean && npm run build",
|
|
18
|
+
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest",
|
|
19
|
+
"test:watch": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --watch"
|
|
20
20
|
},
|
|
21
21
|
"publishConfig": {
|
|
22
22
|
"access": "public"
|
|
@@ -31,21 +31,24 @@
|
|
|
31
31
|
},
|
|
32
32
|
"license": "Apache-2.0",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@nymphjs/guid": "^1.0.0-beta.
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
34
|
+
"@nymphjs/guid": "^1.0.0-beta.91",
|
|
35
|
+
"debug": "^4.4.0",
|
|
36
|
+
"joi": "^17.13.3",
|
|
37
|
+
"locutus": "^2.0.32",
|
|
38
|
+
"lodash-es": "^4.17.21",
|
|
38
39
|
"n-readlines": "^1.0.3"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
|
-
"@tsconfig/recommended": "^1.0.
|
|
42
|
-
"@types/
|
|
43
|
-
"@types/
|
|
44
|
-
"@types/
|
|
45
|
-
"@types/
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
42
|
+
"@tsconfig/recommended": "^1.0.8",
|
|
43
|
+
"@types/debug": "^4.1.12",
|
|
44
|
+
"@types/jest": "^29.5.14",
|
|
45
|
+
"@types/locutus": "^0.0.8",
|
|
46
|
+
"@types/lodash-es": "^4.17.12",
|
|
47
|
+
"@types/n-readlines": "^1.0.6",
|
|
48
|
+
"jest": "^29.7.0",
|
|
49
|
+
"ts-jest": "^29.2.5",
|
|
50
|
+
"ts-node": "^10.9.2",
|
|
51
|
+
"typescript": "^5.7.2"
|
|
49
52
|
},
|
|
50
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "45074e1da0e7879625382a3d35134cde45793f24"
|
|
51
54
|
}
|
package/src/Entity.test.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jest } from '@jest/globals';
|
|
2
|
+
|
|
3
|
+
import { cloneDeep } from 'lodash-es';
|
|
4
|
+
|
|
5
|
+
import { MockNymph } from './testMocks.js';
|
|
2
6
|
import {
|
|
3
7
|
TestBModel as TestBModelClass,
|
|
4
8
|
TestModel as TestModelClass,
|
|
5
9
|
TestModelData,
|
|
6
|
-
} from './testArtifacts';
|
|
7
|
-
import { cloneDeep } from 'lodash';
|
|
10
|
+
} from './testArtifacts.js';
|
|
8
11
|
|
|
9
12
|
const nymph = new MockNymph();
|
|
10
13
|
|
|
@@ -142,7 +145,7 @@ describe('Entity', () => {
|
|
|
142
145
|
await testEntity.$refresh();
|
|
143
146
|
|
|
144
147
|
expect(testEntityCopy.mdate ?? Infinity).toBeLessThanOrEqual(
|
|
145
|
-
testEntity.mdate ?? 0
|
|
148
|
+
testEntity.mdate ?? 0,
|
|
146
149
|
);
|
|
147
150
|
});
|
|
148
151
|
|
|
@@ -156,13 +159,25 @@ describe('Entity', () => {
|
|
|
156
159
|
]);
|
|
157
160
|
});
|
|
158
161
|
|
|
162
|
+
it('toReference works even on an unsaved entity', () => {
|
|
163
|
+
const unsavedEntity = TestModel.factorySync();
|
|
164
|
+
const reference = unsavedEntity.$toReference();
|
|
165
|
+
|
|
166
|
+
expect(unsavedEntity.guid).toBeNull();
|
|
167
|
+
expect(reference).toEqual([
|
|
168
|
+
'nymph_entity_reference',
|
|
169
|
+
unsavedEntity.$getGuaranteedGUID(),
|
|
170
|
+
'TestModel',
|
|
171
|
+
]);
|
|
172
|
+
});
|
|
173
|
+
|
|
159
174
|
it('tags work', async () => {
|
|
160
175
|
expect(testEntity.$hasTag('test')).toEqual(true);
|
|
161
176
|
testEntity.$addTag('test', 'test2');
|
|
162
177
|
expect(testEntity.$hasTag('test', 'test2')).toEqual(true);
|
|
163
178
|
testEntity.$addTag('test', 'test3', 'test4', 'test5', 'test6');
|
|
164
179
|
expect(
|
|
165
|
-
testEntity.$hasTag('test', 'test3', 'test4', 'test5', 'test6')
|
|
180
|
+
testEntity.$hasTag('test', 'test3', 'test4', 'test5', 'test6'),
|
|
166
181
|
).toEqual(true);
|
|
167
182
|
testEntity.$removeTag('test2');
|
|
168
183
|
expect(testEntity.$hasTag('test2')).toEqual(false);
|
|
@@ -183,27 +198,34 @@ describe('Entity', () => {
|
|
|
183
198
|
expect(testEntity.$hasTag('test')).toEqual(true);
|
|
184
199
|
});
|
|
185
200
|
|
|
186
|
-
it('references
|
|
201
|
+
it('references work', async () => {
|
|
187
202
|
await testEntity.$refresh();
|
|
188
203
|
|
|
204
|
+
await testEntity.reference?.$wake();
|
|
189
205
|
expect(testEntity.reference?.guid).toEqual(entityReferenceGuid);
|
|
206
|
+
await Promise.all(testEntity.refArray?.map((e) => e.$wake()) || []);
|
|
190
207
|
expect(testEntity.refArray?.[0].guid).toEqual(entityReferenceGuid);
|
|
208
|
+
await testEntity.refObject?.entity.$wake();
|
|
191
209
|
expect(testEntity.refObject?.entity.guid).toEqual(entityReferenceGuid);
|
|
192
210
|
|
|
193
211
|
const entity = await TestModel.factory(testEntity.guid as string);
|
|
194
212
|
|
|
213
|
+
await entity.reference?.$wake();
|
|
195
214
|
expect(entity.reference?.guid).toEqual(entityReferenceGuid);
|
|
215
|
+
await Promise.all(entity.refArray?.map((e) => e.$wake()) || []);
|
|
196
216
|
expect(entity.refArray?.[0].guid).toEqual(entityReferenceGuid);
|
|
217
|
+
await entity.refObject?.entity.$wake();
|
|
197
218
|
expect(entity.refObject?.entity.guid).toEqual(entityReferenceGuid);
|
|
198
219
|
});
|
|
199
220
|
|
|
200
|
-
it('sleeping references wake up', () => {
|
|
221
|
+
it('sleeping references wake up', async () => {
|
|
201
222
|
const entity = TestModel.factoryReference([
|
|
202
223
|
'nymph_entity_reference',
|
|
203
224
|
testEntity.guid as string,
|
|
204
225
|
'TestModel',
|
|
205
226
|
]) as TestModelClass & TestModelData;
|
|
206
227
|
|
|
228
|
+
await entity.$wake();
|
|
207
229
|
expect(entity.guid).toEqual(testEntity.guid);
|
|
208
230
|
expect(entity.cdate).toEqual(testEntity.cdate);
|
|
209
231
|
expect(entity.mdate).toEqual(testEntity.mdate);
|
|
@@ -213,8 +235,11 @@ describe('Entity', () => {
|
|
|
213
235
|
expect(entity.string).toEqual('test');
|
|
214
236
|
expect(entity.array).toEqual(['full', 'of', 'values', 500]);
|
|
215
237
|
expect(entity.number).toEqual(30);
|
|
238
|
+
await entity.reference?.$wake();
|
|
216
239
|
expect(entity.reference?.guid).toEqual(entityReferenceGuid);
|
|
240
|
+
await Promise.all(entity.refArray?.map((e) => e.$wake()) || []);
|
|
217
241
|
expect(entity.refArray?.[0].guid).toEqual(entityReferenceGuid);
|
|
242
|
+
await entity.refObject?.entity.$wake();
|
|
218
243
|
expect(entity.refObject?.entity.guid).toEqual(entityReferenceGuid);
|
|
219
244
|
});
|
|
220
245
|
|
|
@@ -239,6 +264,7 @@ describe('Entity', () => {
|
|
|
239
264
|
array: ['full', 'of', 'values', 500],
|
|
240
265
|
string: 'test',
|
|
241
266
|
null: null,
|
|
267
|
+
uniques: [],
|
|
242
268
|
},
|
|
243
269
|
class: 'TestModel',
|
|
244
270
|
});
|
|
@@ -288,8 +314,11 @@ describe('Entity', () => {
|
|
|
288
314
|
expect(testEntity.string).toEqual('good');
|
|
289
315
|
expect(testEntity.array).toEqual(['imanarray']);
|
|
290
316
|
expect(testEntity.number).toEqual(30);
|
|
317
|
+
await testEntity.reference?.$wake();
|
|
291
318
|
expect(testEntity.reference?.guid).toEqual(entityReferenceGuid);
|
|
319
|
+
await Promise.all(testEntity.refArray?.map((e) => e.$wake()) || []);
|
|
292
320
|
expect(testEntity.refArray?.[0].guid).toEqual(entityReferenceGuid);
|
|
321
|
+
await testEntity.refObject?.entity.$wake();
|
|
293
322
|
expect(testEntity.refObject?.entity.guid).toEqual(entityReferenceGuid);
|
|
294
323
|
|
|
295
324
|
expect(await testEntity.$refresh()).toEqual(true);
|
|
@@ -311,7 +340,9 @@ describe('Entity', () => {
|
|
|
311
340
|
expect(testEntity.$hasTag('notag')).toEqual(false);
|
|
312
341
|
expect(testEntity.$hasTag('test')).toEqual(true);
|
|
313
342
|
expect(testEntity.$hasTag('newtag')).toEqual(true);
|
|
343
|
+
await testEntity.reference?.$wake();
|
|
314
344
|
expect(testEntity.reference?.guid).toEqual(entityReferenceGuid);
|
|
345
|
+
await Promise.all(testEntity.refArray?.map((e) => e.$wake()) || []);
|
|
315
346
|
expect(testEntity.refArray?.[0].guid).toEqual(entityReferenceGuid);
|
|
316
347
|
|
|
317
348
|
expect(await testEntity.$refresh()).toEqual(true);
|
|
@@ -403,4 +434,18 @@ describe('Entity', () => {
|
|
|
403
434
|
|
|
404
435
|
expect(thrown).toEqual(true);
|
|
405
436
|
});
|
|
437
|
+
|
|
438
|
+
it('JSON with new entities works', async () => {
|
|
439
|
+
testEntity.reference = await TestModel.factory();
|
|
440
|
+
|
|
441
|
+
// Test that an old JSON payload causes a conflict.
|
|
442
|
+
const json = JSON.stringify(testEntity);
|
|
443
|
+
const data = JSON.parse(json);
|
|
444
|
+
|
|
445
|
+
console.log(data.data.reference);
|
|
446
|
+
|
|
447
|
+
testEntity.$jsonAcceptData(data);
|
|
448
|
+
|
|
449
|
+
expect(testEntity.reference.guid).toBeNull();
|
|
450
|
+
});
|
|
406
451
|
});
|