@nymphjs/nymph 1.0.0-beta.40 → 1.0.0-beta.41
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 +7 -0
- package/README.md +8 -10
- package/dist/Entity.d.ts +22 -3
- package/dist/Entity.js +152 -79
- package/dist/Entity.js.map +1 -1
- package/dist/Entity.test.js +17 -2
- package/dist/Entity.test.js.map +1 -1
- package/dist/Nymph.types.d.ts +3 -3
- package/dist/driver/NymphDriver.d.ts +0 -22
- package/dist/driver/NymphDriver.js +0 -14
- package/dist/driver/NymphDriver.js.map +1 -1
- package/dist/driver/testArtifacts.js +6 -3
- 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/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 +4 -4
- package/dist/testArtifacts.js +10 -12
- package/dist/testArtifacts.js.map +1 -1
- package/dist/testMocks.d.ts +6 -6
- package/dist/testMocks.js +2 -2
- package/dist/testMocks.js.map +1 -1
- package/package.json +4 -4
- package/src/Entity.test.ts +17 -2
- package/src/Entity.ts +212 -99
- package/src/Nymph.types.ts +6 -3
- package/src/driver/NymphDriver.ts +0 -81
- package/src/driver/testArtifacts.ts +6 -8
- package/src/errors/InvalidStateError.ts +6 -0
- package/src/errors/index.ts +2 -0
- package/src/testArtifacts.ts +10 -12
- package/src/testMocks.ts +11 -11
|
@@ -64,14 +64,6 @@ These hats are absolutely fantastic.`;
|
|
|
64
64
|
entityReferenceTest.test = 'good';
|
|
65
65
|
expect(await entityReferenceTest.$save()).toEqual(true);
|
|
66
66
|
|
|
67
|
-
// Test synchronous getEntity.
|
|
68
|
-
testEntity = nymph.driver.getEntitySync(
|
|
69
|
-
{ class: TestModel },
|
|
70
|
-
testGuid
|
|
71
|
-
) as TestModelClass & TestModelData;
|
|
72
|
-
expect(testEntity).toBeInstanceOf(TestModel);
|
|
73
|
-
expect(testEntity.guid).toEqual(testGuid);
|
|
74
|
-
|
|
75
67
|
// Test asynchronous getEntity.
|
|
76
68
|
testEntity = (await nymph.getEntity(
|
|
77
69
|
{ class: TestModel },
|
|
@@ -1179,9 +1171,11 @@ These hats are absolutely fantastic.`;
|
|
|
1179
1171
|
await createTestEntities();
|
|
1180
1172
|
|
|
1181
1173
|
// Testing referenced entities...
|
|
1174
|
+
await testEntity.reference?.$wake();
|
|
1182
1175
|
expect(testEntity.reference?.test).toEqual('good');
|
|
1183
1176
|
|
|
1184
1177
|
// Testing referenced entity arrays...
|
|
1178
|
+
await Promise.all(testEntity.refArray?.map((e) => e.$wake()) || []);
|
|
1185
1179
|
expect(testEntity.refArray?.[0].test).toEqual('good');
|
|
1186
1180
|
});
|
|
1187
1181
|
|
|
@@ -1790,7 +1784,9 @@ These hats are absolutely fantastic.`;
|
|
|
1790
1784
|
await createTestEntities();
|
|
1791
1785
|
|
|
1792
1786
|
// Deleting referenced entities...
|
|
1787
|
+
await testEntity.reference?.$wake();
|
|
1793
1788
|
expect(await testEntity.reference?.$delete()).toEqual(true);
|
|
1789
|
+
await Promise.all(testEntity.refArray?.map((e) => e.$wake()) || []);
|
|
1794
1790
|
expect(testEntity.reference?.guid).toBeNull();
|
|
1795
1791
|
});
|
|
1796
1792
|
|
|
@@ -1900,9 +1896,11 @@ export function ExportImportTest(
|
|
|
1900
1896
|
expect(model.number).toEqual(30);
|
|
1901
1897
|
expect(model.timestamp).toBeGreaterThanOrEqual(strtotime('-2 minutes'));
|
|
1902
1898
|
|
|
1899
|
+
await model.reference?.$wake();
|
|
1903
1900
|
expect(model.reference?.guid).not.toBeNull();
|
|
1904
1901
|
expect(model.reference?.string).toEqual('another');
|
|
1905
1902
|
expect(model.reference?.index?.match(/^\d+b$/)).toBeTruthy();
|
|
1903
|
+
await Promise.all(model.refArray?.map((e) => e.$wake()) || []);
|
|
1906
1904
|
expect(model.refArray?.[0].guid).not.toBeNull();
|
|
1907
1905
|
expect(model.refArray?.[0].guid).toEqual(model.reference?.guid);
|
|
1908
1906
|
}
|
package/src/errors/index.ts
CHANGED
package/src/testArtifacts.ts
CHANGED
|
@@ -38,17 +38,15 @@ export class TestModel extends Entity<TestModelData> {
|
|
|
38
38
|
return (await super.factory(guid)) as TestModel & TestModelData;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
static factorySync(
|
|
42
|
-
return super.factorySync(
|
|
41
|
+
static factorySync(): TestModel & TestModelData {
|
|
42
|
+
return super.factorySync() as TestModel & TestModelData;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
constructor(
|
|
46
|
-
super(
|
|
45
|
+
constructor() {
|
|
46
|
+
super();
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
this.$data.boolean = true;
|
|
51
|
-
}
|
|
48
|
+
this.$addTag('test');
|
|
49
|
+
this.$data.boolean = true;
|
|
52
50
|
}
|
|
53
51
|
|
|
54
52
|
public $useProtectedData() {
|
|
@@ -82,8 +80,8 @@ export class TestBModel extends TestModel {
|
|
|
82
80
|
return (await super.factory(guid)) as TestBModel & TestModelData;
|
|
83
81
|
}
|
|
84
82
|
|
|
85
|
-
static factorySync(
|
|
86
|
-
return super.factorySync(
|
|
83
|
+
static factorySync(): TestBModel & TestModelData {
|
|
84
|
+
return super.factorySync() as TestBModel & TestModelData;
|
|
87
85
|
}
|
|
88
86
|
}
|
|
89
87
|
|
|
@@ -102,7 +100,7 @@ export class TestEmptyModel extends Entity<TestEmptyModelData> {
|
|
|
102
100
|
return (await super.factory(guid)) as TestEmptyModel & TestEmptyModelData;
|
|
103
101
|
}
|
|
104
102
|
|
|
105
|
-
static factorySync(
|
|
106
|
-
return super.factorySync(
|
|
103
|
+
static factorySync(): TestEmptyModel & TestEmptyModelData {
|
|
104
|
+
return super.factorySync() as TestEmptyModel & TestEmptyModelData;
|
|
107
105
|
}
|
|
108
106
|
}
|
package/src/testMocks.ts
CHANGED
|
@@ -15,26 +15,26 @@ export class MockNymphDriver {
|
|
|
15
15
|
this.nymph = nymph;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
public
|
|
18
|
+
public async getEntity<T extends EntityConstructor = EntityConstructor>(
|
|
19
19
|
options: Options<T> & { return: 'guid' },
|
|
20
20
|
...selectors: Selector[]
|
|
21
|
-
): string | null
|
|
22
|
-
public
|
|
21
|
+
): Promise<string | null>;
|
|
22
|
+
public async getEntity<T extends EntityConstructor = EntityConstructor>(
|
|
23
23
|
options: Options<T>,
|
|
24
24
|
...selectors: Selector[]
|
|
25
|
-
): ReturnType<T['factorySync']> | null
|
|
26
|
-
public
|
|
25
|
+
): Promise<ReturnType<T['factorySync']> | null>;
|
|
26
|
+
public async getEntity<T extends EntityConstructor = EntityConstructor>(
|
|
27
27
|
options: Options<T> & { return: 'guid' },
|
|
28
28
|
guid: string
|
|
29
|
-
): string | null
|
|
30
|
-
public
|
|
29
|
+
): Promise<string | null>;
|
|
30
|
+
public async getEntity<T extends EntityConstructor = EntityConstructor>(
|
|
31
31
|
options: Options<T>,
|
|
32
32
|
guid: string
|
|
33
|
-
): ReturnType<T['factorySync']> | null
|
|
34
|
-
public
|
|
33
|
+
): Promise<ReturnType<T['factorySync']> | null>;
|
|
34
|
+
public async getEntity<T extends EntityConstructor = EntityConstructor>(
|
|
35
35
|
options: Options<T> = {},
|
|
36
36
|
...selectors: Selector[] | string[]
|
|
37
|
-
): ReturnType<T['factorySync']> | string | null {
|
|
37
|
+
): Promise<ReturnType<T['factorySync']> | string | null> {
|
|
38
38
|
const guid =
|
|
39
39
|
typeof selectors[0] === 'string' ? selectors[0] : selectors[0].guid;
|
|
40
40
|
if (!options || !guid || typeof guid !== 'string' || !(guid in entities)) {
|
|
@@ -119,7 +119,7 @@ export class MockNymph {
|
|
|
119
119
|
...selectors: Selector[] | string[]
|
|
120
120
|
): Promise<ReturnType<T['factorySync']> | string | null> {
|
|
121
121
|
// @ts-ignore: The selector type is correct here.
|
|
122
|
-
return this.driver.
|
|
122
|
+
return await this.driver.getEntity(options, ...selectors);
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
public async saveEntity(entity: EntityInterface): Promise<boolean> {
|