@nymphjs/nymph 1.0.0-beta.5 → 1.0.0-beta.50
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 +231 -0
- package/README.md +15 -15
- package/dist/Entity.d.ts +24 -3
- package/dist/Entity.js +194 -86
- package/dist/Entity.js.map +1 -1
- package/dist/Entity.test.js +34 -17
- package/dist/Entity.test.js.map +1 -1
- package/dist/Entity.types.d.ts +3 -1
- package/dist/Nymph.d.ts +22 -7
- package/dist/Nymph.js +214 -68
- package/dist/Nymph.js.map +1 -1
- package/dist/Nymph.types.d.ts +18 -5
- package/dist/Nymph.types.js +1 -1
- package/dist/Nymph.types.js.map +1 -1
- package/dist/driver/NymphDriver.d.ts +1 -22
- package/dist/driver/NymphDriver.js +85 -105
- package/dist/driver/NymphDriver.js.map +1 -1
- package/dist/driver/testArtifacts.js +208 -159
- package/dist/driver/testArtifacts.js.map +1 -1
- 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 +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/errors/index.js.map +1 -1
- package/dist/testArtifacts.d.ts +10 -3
- package/dist/testArtifacts.js +20 -11
- package/dist/testArtifacts.js.map +1 -1
- package/dist/testMocks.d.ts +10 -7
- package/dist/testMocks.js +22 -10
- package/dist/testMocks.js.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +11 -5
- package/dist/utils.js.map +1 -1
- package/package.json +15 -15
- package/src/Entity.test.ts +33 -11
- package/src/Entity.ts +303 -127
- package/src/Entity.types.ts +13 -1
- package/src/Nymph.ts +392 -88
- package/src/Nymph.types.ts +95 -24
- package/src/driver/NymphDriver.ts +203 -282
- package/src/driver/testArtifacts.ts +238 -157
- package/src/errors/InvalidStateError.ts +6 -0
- package/src/errors/index.ts +2 -0
- package/src/nymphJoiProps.ts +2 -2
- package/src/testArtifacts.ts +28 -10
- package/src/testMocks.ts +42 -25
- package/src/utils.ts +22 -8
- package/typedoc.json +4 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nymphjs/nymph",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.0-beta.50",
|
|
4
|
+
"description": "Nymph.js - Nymph ORM",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"clean": "test -d dist && rm -r dist || true",
|
|
15
15
|
"build": "tsc",
|
|
16
16
|
"watch": "tsc --watch",
|
|
17
|
-
"
|
|
17
|
+
"prepublish": "npm run clean && npm run build",
|
|
18
18
|
"test": "jest",
|
|
19
19
|
"test:watch": "jest --watch"
|
|
20
20
|
},
|
|
@@ -31,21 +31,21 @@
|
|
|
31
31
|
},
|
|
32
32
|
"license": "Apache-2.0",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@nymphjs/guid": "^1.0.0-beta.
|
|
35
|
-
"joi": "^17.
|
|
34
|
+
"@nymphjs/guid": "^1.0.0-beta.50",
|
|
35
|
+
"joi": "^17.12.2",
|
|
36
36
|
"locutus": "^2.0.16",
|
|
37
37
|
"lodash": "^4.17.21",
|
|
38
|
-
"n-readlines": "^1.0.
|
|
38
|
+
"n-readlines": "^1.0.3"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@tsconfig/recommended": "^1.0.
|
|
42
|
-
"@types/jest": "^29.
|
|
43
|
-
"@types/locutus": "^0.0.
|
|
44
|
-
"@types/lodash": "^4.14.
|
|
45
|
-
"@types/n-readlines": "^1.0.
|
|
46
|
-
"jest": "^29.
|
|
47
|
-
"ts-jest": "^29.
|
|
48
|
-
"typescript": "^
|
|
41
|
+
"@tsconfig/recommended": "^1.0.3",
|
|
42
|
+
"@types/jest": "^29.5.12",
|
|
43
|
+
"@types/locutus": "^0.0.8",
|
|
44
|
+
"@types/lodash": "^4.14.202",
|
|
45
|
+
"@types/n-readlines": "^1.0.6",
|
|
46
|
+
"jest": "^29.7.0",
|
|
47
|
+
"ts-jest": "^29.1.2",
|
|
48
|
+
"typescript": "^5.3.3"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "d8fb386f19a1868565dd900e3e48fc586977a3f8"
|
|
51
51
|
}
|
package/src/Entity.test.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { MockNymph } from './testMocks';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
TestBModel as TestBModelClass,
|
|
4
|
+
TestModel as TestModelClass,
|
|
5
|
+
TestModelData,
|
|
6
|
+
} from './testArtifacts';
|
|
3
7
|
import { cloneDeep } from 'lodash';
|
|
4
8
|
|
|
5
9
|
const nymph = new MockNymph();
|
|
@@ -9,11 +13,11 @@ jest.mock('./Nymph', () => ({
|
|
|
9
13
|
default: nymph,
|
|
10
14
|
}));
|
|
11
15
|
|
|
12
|
-
nymph.addEntityClass(
|
|
13
|
-
nymph.addEntityClass(
|
|
16
|
+
const TestModel = nymph.addEntityClass(TestModelClass);
|
|
17
|
+
const TestBModel = nymph.addEntityClass(TestBModelClass);
|
|
14
18
|
|
|
15
19
|
let testEntity = TestModel.factorySync();
|
|
16
|
-
let entityReferenceTest:
|
|
20
|
+
let entityReferenceTest: TestModelClass & TestModelData;
|
|
17
21
|
let entityReferenceGuid: string;
|
|
18
22
|
|
|
19
23
|
describe('Entity', () => {
|
|
@@ -71,7 +75,7 @@ describe('Entity', () => {
|
|
|
71
75
|
|
|
72
76
|
it('array searching work', async () => {
|
|
73
77
|
const testInArray = await TestModel.factory(testEntity.guid as string);
|
|
74
|
-
const array: (string | (
|
|
78
|
+
const array: (string | (TestModelClass & TestModelData))[] = [
|
|
75
79
|
'thing',
|
|
76
80
|
testInArray,
|
|
77
81
|
];
|
|
@@ -125,17 +129,20 @@ describe('Entity', () => {
|
|
|
125
129
|
});
|
|
126
130
|
|
|
127
131
|
it('conflict fails to save', async () => {
|
|
132
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
133
|
+
|
|
128
134
|
const testEntityCopy = await TestModel.factory(testEntity.guid as string);
|
|
129
135
|
expect(await testEntityCopy.$save()).toEqual(true);
|
|
136
|
+
expect(testEntityCopy.mdate ?? 0).toBeGreaterThan(testEntity.mdate ?? 0);
|
|
130
137
|
|
|
131
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
138
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
132
139
|
|
|
133
140
|
expect(await testEntity.$save()).toEqual(false);
|
|
134
141
|
|
|
135
142
|
await testEntity.$refresh();
|
|
136
143
|
|
|
137
144
|
expect(testEntityCopy.mdate ?? Infinity).toBeLessThanOrEqual(
|
|
138
|
-
testEntity.mdate ?? 0
|
|
145
|
+
testEntity.mdate ?? 0,
|
|
139
146
|
);
|
|
140
147
|
});
|
|
141
148
|
|
|
@@ -155,7 +162,7 @@ describe('Entity', () => {
|
|
|
155
162
|
expect(testEntity.$hasTag('test', 'test2')).toEqual(true);
|
|
156
163
|
testEntity.$addTag('test', 'test3', 'test4', 'test5', 'test6');
|
|
157
164
|
expect(
|
|
158
|
-
testEntity.$hasTag('test', 'test3', 'test4', 'test5', 'test6')
|
|
165
|
+
testEntity.$hasTag('test', 'test3', 'test4', 'test5', 'test6'),
|
|
159
166
|
).toEqual(true);
|
|
160
167
|
testEntity.$removeTag('test2');
|
|
161
168
|
expect(testEntity.$hasTag('test2')).toEqual(false);
|
|
@@ -176,27 +183,34 @@ describe('Entity', () => {
|
|
|
176
183
|
expect(testEntity.$hasTag('test')).toEqual(true);
|
|
177
184
|
});
|
|
178
185
|
|
|
179
|
-
it('references
|
|
186
|
+
it('references work', async () => {
|
|
180
187
|
await testEntity.$refresh();
|
|
181
188
|
|
|
189
|
+
await testEntity.reference?.$wake();
|
|
182
190
|
expect(testEntity.reference?.guid).toEqual(entityReferenceGuid);
|
|
191
|
+
await Promise.all(testEntity.refArray?.map((e) => e.$wake()) || []);
|
|
183
192
|
expect(testEntity.refArray?.[0].guid).toEqual(entityReferenceGuid);
|
|
193
|
+
await testEntity.refObject?.entity.$wake();
|
|
184
194
|
expect(testEntity.refObject?.entity.guid).toEqual(entityReferenceGuid);
|
|
185
195
|
|
|
186
196
|
const entity = await TestModel.factory(testEntity.guid as string);
|
|
187
197
|
|
|
198
|
+
await entity.reference?.$wake();
|
|
188
199
|
expect(entity.reference?.guid).toEqual(entityReferenceGuid);
|
|
200
|
+
await Promise.all(entity.refArray?.map((e) => e.$wake()) || []);
|
|
189
201
|
expect(entity.refArray?.[0].guid).toEqual(entityReferenceGuid);
|
|
202
|
+
await entity.refObject?.entity.$wake();
|
|
190
203
|
expect(entity.refObject?.entity.guid).toEqual(entityReferenceGuid);
|
|
191
204
|
});
|
|
192
205
|
|
|
193
|
-
it('sleeping references wake up', () => {
|
|
206
|
+
it('sleeping references wake up', async () => {
|
|
194
207
|
const entity = TestModel.factoryReference([
|
|
195
208
|
'nymph_entity_reference',
|
|
196
209
|
testEntity.guid as string,
|
|
197
210
|
'TestModel',
|
|
198
|
-
]) as
|
|
211
|
+
]) as TestModelClass & TestModelData;
|
|
199
212
|
|
|
213
|
+
await entity.$wake();
|
|
200
214
|
expect(entity.guid).toEqual(testEntity.guid);
|
|
201
215
|
expect(entity.cdate).toEqual(testEntity.cdate);
|
|
202
216
|
expect(entity.mdate).toEqual(testEntity.mdate);
|
|
@@ -206,8 +220,11 @@ describe('Entity', () => {
|
|
|
206
220
|
expect(entity.string).toEqual('test');
|
|
207
221
|
expect(entity.array).toEqual(['full', 'of', 'values', 500]);
|
|
208
222
|
expect(entity.number).toEqual(30);
|
|
223
|
+
await entity.reference?.$wake();
|
|
209
224
|
expect(entity.reference?.guid).toEqual(entityReferenceGuid);
|
|
225
|
+
await Promise.all(entity.refArray?.map((e) => e.$wake()) || []);
|
|
210
226
|
expect(entity.refArray?.[0].guid).toEqual(entityReferenceGuid);
|
|
227
|
+
await entity.refObject?.entity.$wake();
|
|
211
228
|
expect(entity.refObject?.entity.guid).toEqual(entityReferenceGuid);
|
|
212
229
|
});
|
|
213
230
|
|
|
@@ -281,8 +298,11 @@ describe('Entity', () => {
|
|
|
281
298
|
expect(testEntity.string).toEqual('good');
|
|
282
299
|
expect(testEntity.array).toEqual(['imanarray']);
|
|
283
300
|
expect(testEntity.number).toEqual(30);
|
|
301
|
+
await testEntity.reference?.$wake();
|
|
284
302
|
expect(testEntity.reference?.guid).toEqual(entityReferenceGuid);
|
|
303
|
+
await Promise.all(testEntity.refArray?.map((e) => e.$wake()) || []);
|
|
285
304
|
expect(testEntity.refArray?.[0].guid).toEqual(entityReferenceGuid);
|
|
305
|
+
await testEntity.refObject?.entity.$wake();
|
|
286
306
|
expect(testEntity.refObject?.entity.guid).toEqual(entityReferenceGuid);
|
|
287
307
|
|
|
288
308
|
expect(await testEntity.$refresh()).toEqual(true);
|
|
@@ -304,7 +324,9 @@ describe('Entity', () => {
|
|
|
304
324
|
expect(testEntity.$hasTag('notag')).toEqual(false);
|
|
305
325
|
expect(testEntity.$hasTag('test')).toEqual(true);
|
|
306
326
|
expect(testEntity.$hasTag('newtag')).toEqual(true);
|
|
327
|
+
await testEntity.reference?.$wake();
|
|
307
328
|
expect(testEntity.reference?.guid).toEqual(entityReferenceGuid);
|
|
329
|
+
await Promise.all(testEntity.refArray?.map((e) => e.$wake()) || []);
|
|
308
330
|
expect(testEntity.refArray?.[0].guid).toEqual(entityReferenceGuid);
|
|
309
331
|
|
|
310
332
|
expect(await testEntity.$refresh()).toEqual(true);
|