@nymphjs/nymph 1.0.0-beta.4 → 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.
Files changed (48) hide show
  1. package/CHANGELOG.md +195 -0
  2. package/README.md +12 -12
  3. package/dist/Entity.d.ts +24 -3
  4. package/dist/Entity.js +194 -86
  5. package/dist/Entity.js.map +1 -1
  6. package/dist/Entity.test.js +34 -17
  7. package/dist/Entity.test.js.map +1 -1
  8. package/dist/Entity.types.d.ts +3 -1
  9. package/dist/Nymph.d.ts +22 -7
  10. package/dist/Nymph.js +214 -68
  11. package/dist/Nymph.js.map +1 -1
  12. package/dist/Nymph.types.d.ts +18 -5
  13. package/dist/Nymph.types.js +1 -1
  14. package/dist/Nymph.types.js.map +1 -1
  15. package/dist/driver/NymphDriver.d.ts +1 -22
  16. package/dist/driver/NymphDriver.js +2 -16
  17. package/dist/driver/NymphDriver.js.map +1 -1
  18. package/dist/driver/testArtifacts.js +208 -159
  19. package/dist/driver/testArtifacts.js.map +1 -1
  20. package/dist/errors/InvalidStateError.d.ts +3 -0
  21. package/dist/errors/InvalidStateError.js +11 -0
  22. package/dist/errors/InvalidStateError.js.map +1 -0
  23. package/dist/errors/index.d.ts +1 -0
  24. package/dist/errors/index.js +1 -0
  25. package/dist/errors/index.js.map +1 -1
  26. package/dist/testArtifacts.d.ts +10 -3
  27. package/dist/testArtifacts.js +20 -11
  28. package/dist/testArtifacts.js.map +1 -1
  29. package/dist/testMocks.d.ts +10 -7
  30. package/dist/testMocks.js +22 -10
  31. package/dist/testMocks.js.map +1 -1
  32. package/dist/utils.d.ts +1 -1
  33. package/dist/utils.js +11 -5
  34. package/dist/utils.js.map +1 -1
  35. package/package.json +13 -13
  36. package/src/Entity.test.ts +31 -9
  37. package/src/Entity.ts +289 -113
  38. package/src/Entity.types.ts +13 -1
  39. package/src/Nymph.ts +386 -82
  40. package/src/Nymph.types.ts +76 -5
  41. package/src/driver/NymphDriver.ts +19 -85
  42. package/src/driver/testArtifacts.ts +125 -44
  43. package/src/errors/InvalidStateError.ts +6 -0
  44. package/src/errors/index.ts +2 -0
  45. package/src/testArtifacts.ts +28 -10
  46. package/src/testMocks.ts +38 -21
  47. package/src/utils.ts +21 -7
  48. package/typedoc.json +4 -0
package/CHANGELOG.md CHANGED
@@ -3,6 +3,201 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.0.0-beta.41](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.40...v1.0.0-beta.41) (2023-07-12)
7
+
8
+ ### Features
9
+
10
+ - remove synchronous database queries ([b579fb2](https://github.com/sciactive/nymphjs/commit/b579fb2eacd96cdd1b386a62c5c00cdbb2438f6e))
11
+ - rewrite server side async api to match client side api ([9c537a8](https://github.com/sciactive/nymphjs/commit/9c537a8be49e9b989af0822a4c2236e8c2d20f87))
12
+
13
+ # [1.0.0-beta.40](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.39...v1.0.0-beta.40) (2023-07-10)
14
+
15
+ **Note:** Version bump only for package @nymphjs/nymph
16
+
17
+ # [1.0.0-beta.39](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.38...v1.0.0-beta.39) (2023-07-09)
18
+
19
+ **Note:** Version bump only for package @nymphjs/nymph
20
+
21
+ # [1.0.0-beta.38](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.37...v1.0.0-beta.38) (2023-07-09)
22
+
23
+ **Note:** Version bump only for package @nymphjs/nymph
24
+
25
+ # [1.0.0-beta.37](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.36...v1.0.0-beta.37) (2023-07-09)
26
+
27
+ **Note:** Version bump only for package @nymphjs/nymph
28
+
29
+ # [1.0.0-beta.36](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.35...v1.0.0-beta.36) (2023-07-09)
30
+
31
+ **Note:** Version bump only for package @nymphjs/nymph
32
+
33
+ # [1.0.0-beta.35](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.34...v1.0.0-beta.35) (2023-06-14)
34
+
35
+ ### Bug Fixes
36
+
37
+ - get class from nymph instead of using constructor ([fc8538e](https://github.com/sciactive/nymphjs/commit/fc8538ea24be79b845ab1e00f930542f34517bfb))
38
+
39
+ # [1.0.0-beta.34](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.33...v1.0.0-beta.34) (2023-05-13)
40
+
41
+ **Note:** Version bump only for package @nymphjs/nymph
42
+
43
+ # [1.0.0-beta.33](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.32...v1.0.0-beta.33) (2023-05-13)
44
+
45
+ **Note:** Version bump only for package @nymphjs/nymph
46
+
47
+ # [1.0.0-beta.32](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.31...v1.0.0-beta.32) (2023-05-13)
48
+
49
+ ### Features
50
+
51
+ - issue initial request with pubsub instead of rest on subscribe ([8a232d2](https://github.com/sciactive/nymphjs/commit/8a232d2faeb8622924f9c35a01a8f71a70659bb3))
52
+
53
+ # [1.0.0-beta.31](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.30...v1.0.0-beta.31) (2023-05-12)
54
+
55
+ **Note:** Version bump only for package @nymphjs/nymph
56
+
57
+ # [1.0.0-beta.30](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.29...v1.0.0-beta.30) (2023-05-12)
58
+
59
+ ### Features
60
+
61
+ - allow providing getEntityClass with a class instead of string ([ecd64c1](https://github.com/sciactive/nymphjs/commit/ecd64c1bf92e3657889613b76bcc46652f371ead))
62
+
63
+ # [1.0.0-beta.29](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.28...v1.0.0-beta.29) (2023-05-08)
64
+
65
+ ### Bug Fixes
66
+
67
+ - use 4 byte utf8 encoding in mysql ([c335b6e](https://github.com/sciactive/nymphjs/commit/c335b6e8416f935c9116e7f54de753d4b2255a73))
68
+
69
+ # [1.0.0-beta.28](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.27...v1.0.0-beta.28) (2023-05-05)
70
+
71
+ **Note:** Version bump only for package @nymphjs/nymph
72
+
73
+ # [1.0.0-beta.27](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.26...v1.0.0-beta.27) (2023-05-04)
74
+
75
+ ### Bug Fixes
76
+
77
+ - properly escape mysql ids with dots ([64bfaa5](https://github.com/sciactive/nymphjs/commit/64bfaa5d606f97a753ca7e6c5d2d86f7c0f7729a))
78
+
79
+ # [1.0.0-beta.26](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.25...v1.0.0-beta.26) (2023-05-04)
80
+
81
+ ### Features
82
+
83
+ - update packages and migrate to mysql2 ([72ad611](https://github.com/sciactive/nymphjs/commit/72ad611bd2bf7bf85c3ba8a3486503d9b50c49d6))
84
+
85
+ # [1.0.0-beta.25](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.24...v1.0.0-beta.25) (2023-05-04)
86
+
87
+ ### Bug Fixes
88
+
89
+ - don't create empty entities ([1d4d2e9](https://github.com/sciactive/nymphjs/commit/1d4d2e99af2e9cdc647bcf58ac34572836f41176))
90
+ - tilmeld uses wrong class when cloned with user ([059c2ce](https://github.com/sciactive/nymphjs/commit/059c2cedf1b07b9681e87c240eb36723a4581918))
91
+
92
+ ### Features
93
+
94
+ - add flags to disable rest and pubsub support on an entity class ([52106a3](https://github.com/sciactive/nymphjs/commit/52106a3d44065bcfec40d361344bf1eba59a5136)), closes [#1](https://github.com/sciactive/nymphjs/issues/1)
95
+
96
+ # [1.0.0-beta.24](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.23...v1.0.0-beta.24) (2023-05-02)
97
+
98
+ **Note:** Version bump only for package @nymphjs/nymph
99
+
100
+ # [1.0.0-beta.23](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.22...v1.0.0-beta.23) (2023-05-02)
101
+
102
+ ### Bug Fixes
103
+
104
+ - rare case where currentUser isn't corrent ([97f233a](https://github.com/sciactive/nymphjs/commit/97f233a5fcfd4b97dd282562b0c99097ac3ef41d))
105
+
106
+ # [1.0.0-beta.22](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.21...v1.0.0-beta.22) (2023-05-01)
107
+
108
+ **Note:** Version bump only for package @nymphjs/nymph
109
+
110
+ # [1.0.0-beta.21](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.20...v1.0.0-beta.21) (2023-05-01)
111
+
112
+ **Note:** Version bump only for package @nymphjs/nymph
113
+
114
+ # [1.0.0-beta.20](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.19...v1.0.0-beta.20) (2023-04-30)
115
+
116
+ **Note:** Version bump only for package @nymphjs/nymph
117
+
118
+ # [1.0.0-beta.19](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.18...v1.0.0-beta.19) (2023-04-29)
119
+
120
+ **Note:** Version bump only for package @nymphjs/nymph
121
+
122
+ # [1.0.0-beta.18](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.17...v1.0.0-beta.18) (2023-04-27)
123
+
124
+ ### Bug Fixes
125
+
126
+ - small type issues ([b91579c](https://github.com/sciactive/nymphjs/commit/b91579c9c1e96500d903332648f5a93c9a7e7d9b))
127
+
128
+ ### Features
129
+
130
+ - add the ability to switch to a user without their password ([ca4466a](https://github.com/sciactive/nymphjs/commit/ca4466af1704d68905ac087350a8cf151c1072d9))
131
+ - forbid modifying ac props from client ([f9e896f](https://github.com/sciactive/nymphjs/commit/f9e896f6c57b08ae100bc50d33a0234b6a431333))
132
+
133
+ # [1.0.0-beta.17](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.16...v1.0.0-beta.17) (2023-04-24)
134
+
135
+ **Note:** Version bump only for package @nymphjs/nymph
136
+
137
+ # [1.0.0-beta.16](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.15...v1.0.0-beta.16) (2023-03-31)
138
+
139
+ **Note:** Version bump only for package @nymphjs/nymph
140
+
141
+ # [1.0.0-beta.15](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.14...v1.0.0-beta.15) (2023-03-23)
142
+
143
+ ### Features
144
+
145
+ - add option to sort results by a property ([16384e7](https://github.com/sciactive/nymphjs/commit/16384e7bdab88abb55ccccabb06ac09f92fa8a03))
146
+
147
+ # [1.0.0-beta.14](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.13...v1.0.0-beta.14) (2023-03-17)
148
+
149
+ **Note:** Version bump only for package @nymphjs/nymph
150
+
151
+ # [1.0.0-beta.13](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.12...v1.0.0-beta.13) (2023-03-16)
152
+
153
+ ### Bug Fixes
154
+
155
+ - pubsub publishing changes before transaction is finished ([a918cc1](https://github.com/sciactive/nymphjs/commit/a918cc1451e03015ecce20f1c9bf6ceb62b7dff1))
156
+
157
+ # [1.0.0-beta.12](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.11...v1.0.0-beta.12) (2023-03-04)
158
+
159
+ **Note:** Version bump only for package @nymphjs/nymph
160
+
161
+ # [1.0.0-beta.11](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.10...v1.0.0-beta.11) (2023-02-27)
162
+
163
+ **Note:** Version bump only for package @nymphjs/nymph
164
+
165
+ # [1.0.0-beta.10](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.9...v1.0.0-beta.10) (2023-01-19)
166
+
167
+ **Note:** Version bump only for package @nymphjs/nymph
168
+
169
+ # [1.0.0-beta.9](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.8...v1.0.0-beta.9) (2023-01-09)
170
+
171
+ ### Bug Fixes
172
+
173
+ - reworked $is and $equals to better work with new instance based classes ([b1f3f0c](https://github.com/sciactive/nymphjs/commit/b1f3f0cca3e2b0dd392cd9da31167a6bd9487b40))
174
+
175
+ # [1.0.0-beta.8](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.7...v1.0.0-beta.8) (2023-01-09)
176
+
177
+ ### Features
178
+
179
+ - make entities in nymph client instance specific too ([1029f06](https://github.com/sciactive/nymphjs/commit/1029f061a1ad193e4a8a2dab0186b9a4b517f646))
180
+
181
+ # [1.0.0-beta.7](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.6...v1.0.0-beta.7) (2023-01-05)
182
+
183
+ ### Bug Fixes
184
+
185
+ - sqlite transaction returns wrong instance of nymph if it has been cloned ([b278c76](https://github.com/sciactive/nymphjs/commit/b278c7633722cb1cca7a941187ae2f1ff8ebdc7b))
186
+
187
+ # [1.0.0-beta.6](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.5...v1.0.0-beta.6) (2023-01-05)
188
+
189
+ ### Bug Fixes
190
+
191
+ - extend class with correct nymph property when added to instance ([1d63f45](https://github.com/sciactive/nymphjs/commit/1d63f457c16de852322d81fd9fdc25e3eb841c8d))
192
+
193
+ ### Features
194
+
195
+ - addEntityClass now returns the new class, which is required to use the class ([e752c3e](https://github.com/sciactive/nymphjs/commit/e752c3e50796656bdea8f8525932ede07c8a5378))
196
+
197
+ # [1.0.0-beta.5](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.4...v1.0.0-beta.5) (2022-11-24)
198
+
199
+ **Note:** Version bump only for package @nymphjs/nymph
200
+
6
201
  # [1.0.0-beta.4](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.3...v1.0.0-beta.4) (2022-11-23)
7
202
 
8
203
  **Note:** Version bump only for package @nymphjs/nymph
package/README.md CHANGED
@@ -22,7 +22,7 @@ Here's an overview:
22
22
  // main.ts
23
23
  import { Nymph } from '@nymphjs/nymph';
24
24
  import MySQLDriver from '@nymphjs/driver-mysql';
25
- import Todo from './Todo';
25
+ import TodoClass from './Todo';
26
26
 
27
27
  const mysqlConfig = {
28
28
  host: 'your_db_host',
@@ -31,8 +31,10 @@ const mysqlConfig = {
31
31
  password: 'your_password',
32
32
  };
33
33
 
34
+ // Create a new instance of Nymph.
34
35
  const nymph = new Nymph({}, new MySQLDriver(mysqlConfig));
35
- nymph.addEntityClass(Todo);
36
+ // addEntityClass returns the class you should use for this instance of Nymph.
37
+ const Todo = nymph.addEntityClass(TodoClass);
36
38
 
37
39
  // You are set up. Now you can use entity classes like `Todo` to store data,
38
40
  // and Nymph's query methods like `getEntities` to retrieve them.
@@ -74,19 +76,17 @@ export default class Todo extends Entity<TodoData> {
74
76
  return (await super.factory(guid)) as Todo & TodoData;
75
77
  }
76
78
 
77
- static factorySync(guid?: string): Todo & TodoData {
78
- return super.factorySync(guid) as Todo & TodoData;
79
+ static factorySync(): Todo & TodoData {
80
+ return super.factorySync() as Todo & TodoData;
79
81
  }
80
82
 
81
- constructor(guid?: string) {
82
- super(guid);
83
+ constructor() {
84
+ super();
83
85
 
84
- if (this.guid == null) {
85
- // Within the methods of an entity, you will use `this.$data` to access
86
- // its data. Outside, you don't need the $data part.
87
- this.$data.text = '';
88
- this.$data.done = false;
89
- }
86
+ // Within the methods of an entity, you will use `this.$data` to access
87
+ // its data. Outside, you don't need the $data part.
88
+ this.$data.text = '';
89
+ this.$data.done = false;
90
90
  }
91
91
 
92
92
  async $getOtherTodos() {
package/dist/Entity.d.ts CHANGED
@@ -15,7 +15,10 @@ export default class Entity<T extends EntityData = EntityData> implements Entity
15
15
  protected $data: T;
16
16
  protected $isASleepingReference: boolean;
17
17
  protected $sleepingReference: EntityReference | null;
18
+ protected $wakePromise: Promise<Entity<T>> | null;
18
19
  protected $privateData: string[];
20
+ static pubSubEnabled: boolean;
21
+ static restEnabled: boolean;
19
22
  static searchRestrictedData: string[];
20
23
  protected $protectedData: string[];
21
24
  protected $allowlistData?: string[];
@@ -25,9 +28,9 @@ export default class Entity<T extends EntityData = EntityData> implements Entity
25
28
  static clientEnabledStaticMethods: string[];
26
29
  private $skipAc;
27
30
  private $originalAcValues;
28
- constructor(guid?: string);
31
+ constructor();
29
32
  static factory(guid?: string): Promise<EntityInterface | Entity<EntityData>>;
30
- static factorySync(guid?: string): Entity<EntityData>;
33
+ static factorySync(): Entity<EntityData>;
31
34
  static factoryReference(reference: EntityReference): Entity<EntityData>;
32
35
  toJSON(): EntityReference | EntityJson | null;
33
36
  $addTag(...tags: string[]): void;
@@ -39,6 +42,21 @@ export default class Entity<T extends EntityData = EntityData> implements Entity
39
42
  $getData(includeSData?: boolean): any;
40
43
  $getSData(): SerializedEntityData;
41
44
  $getOriginalAcValues(): ACProperties;
45
+ $getCurrentAcValues(): {
46
+ user: string | null;
47
+ group: string | null;
48
+ acUser: any;
49
+ acGroup: any;
50
+ acOther: any;
51
+ acRead: string[] | null;
52
+ acWrite: string[] | null;
53
+ acFull: string[] | null;
54
+ };
55
+ $getAcUid(): string | null;
56
+ $getAcGid(): string | null;
57
+ $getAcReadIds(): string[] | null;
58
+ $getAcWriteIds(): string[] | null;
59
+ $getAcFullIds(): string[] | null;
42
60
  $getValidatable(): any;
43
61
  $getTags(): string[];
44
62
  $hasTag(...tags: string[]): boolean;
@@ -48,7 +66,10 @@ export default class Entity<T extends EntityData = EntityData> implements Entity
48
66
  $jsonAcceptPatch(patch: EntityPatch, allowConflict?: boolean): void;
49
67
  $putData(data: EntityData, sdata?: SerializedEntityData): void;
50
68
  protected $referenceSleep(reference: EntityReference): void;
51
- protected $referenceWake(): boolean;
69
+ protected $check(): void;
70
+ $asleep(): boolean;
71
+ $wake(): Promise<Entity<T>>;
72
+ $wakeAll(level?: number): Promise<Entity<T>>;
52
73
  $refresh(): Promise<boolean | 0>;
53
74
  $removeTag(...tags: string[]): void;
54
75
  $save(): Promise<boolean>;