@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.
@@ -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
  }
@@ -0,0 +1,6 @@
1
+ export class InvalidStateError extends Error {
2
+ constructor(message: string) {
3
+ super(message);
4
+ this.name = 'InvalidStateError';
5
+ }
6
+ }
@@ -8,6 +8,8 @@ export * from './EntityIsSleepingReferenceError';
8
8
 
9
9
  export * from './InvalidParametersError';
10
10
 
11
+ export * from './InvalidStateError';
12
+
11
13
  export * from './NotConfiguredError';
12
14
 
13
15
  export * from './QueryFailedError';
@@ -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(guid?: string): TestModel & TestModelData {
42
- return super.factorySync(guid) as TestModel & TestModelData;
41
+ static factorySync(): TestModel & TestModelData {
42
+ return super.factorySync() as TestModel & TestModelData;
43
43
  }
44
44
 
45
- constructor(guid?: string) {
46
- super(guid);
45
+ constructor() {
46
+ super();
47
47
 
48
- if (this.guid == null) {
49
- this.$addTag('test');
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(guid?: string): TestBModel & TestModelData {
86
- return super.factorySync(guid) as TestBModel & TestModelData;
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(guid?: string): TestEmptyModel & TestEmptyModelData {
106
- return super.factorySync(guid) as TestEmptyModel & TestEmptyModelData;
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 getEntitySync<T extends EntityConstructor = EntityConstructor>(
18
+ public async getEntity<T extends EntityConstructor = EntityConstructor>(
19
19
  options: Options<T> & { return: 'guid' },
20
20
  ...selectors: Selector[]
21
- ): string | null;
22
- public getEntitySync<T extends EntityConstructor = EntityConstructor>(
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 getEntitySync<T extends EntityConstructor = EntityConstructor>(
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 getEntitySync<T extends EntityConstructor = EntityConstructor>(
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 getEntitySync<T extends EntityConstructor = EntityConstructor>(
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.getEntitySync(options, ...selectors);
122
+ return await this.driver.getEntity(options, ...selectors);
123
123
  }
124
124
 
125
125
  public async saveEntity(entity: EntityInterface): Promise<boolean> {