@nymphjs/nymph 1.0.0-beta.13 → 1.0.0-beta.130
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 +644 -0
- package/README.md +34 -24
- package/dist/Entity.d.ts +304 -15
- package/dist/Entity.js +609 -154
- package/dist/Entity.js.map +1 -1
- package/dist/Entity.test.js +75 -29
- package/dist/Entity.test.js.map +1 -1
- package/dist/Entity.types.d.ts +275 -28
- package/dist/Entity.types.js +1 -2
- package/dist/Nymph.d.ts +575 -11
- package/dist/Nymph.js +825 -288
- package/dist/Nymph.js.map +1 -1
- package/dist/Nymph.types.d.ts +117 -7
- package/dist/Nymph.types.js +47 -5
- package/dist/Nymph.types.js.map +1 -1
- 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 +50 -2
- package/dist/conf/index.js +2 -8
- package/dist/conf/index.js.map +1 -1
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +2 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/transactional.d.ts +12 -0
- package/dist/decorators/transactional.js +45 -0
- package/dist/decorators/transactional.js.map +1 -0
- package/dist/driver/NymphDriver.d.ts +209 -41
- package/dist/driver/NymphDriver.js +737 -242
- package/dist/driver/NymphDriver.js.map +1 -1
- package/dist/driver/index.d.ts +1 -2
- package/dist/driver/index.js +2 -23
- package/dist/driver/index.js.map +1 -1
- package/dist/driver/testArtifacts.d.ts +4 -4
- package/dist/driver/testArtifacts.js +2016 -1086
- 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/HttpError.d.ts +5 -0
- package/dist/errors/HttpError.js +11 -0
- package/dist/errors/HttpError.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/MethodFailedError.d.ts +3 -0
- package/dist/errors/MethodFailedError.js +7 -0
- package/dist/errors/MethodFailedError.js.map +1 -0
- package/dist/errors/NotConfiguredError.js +1 -5
- package/dist/errors/NotConfiguredError.js.map +1 -1
- package/dist/errors/QueryFailedError.d.ts +2 -1
- package/dist/errors/QueryFailedError.js +5 -6
- 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 +12 -8
- package/dist/errors/index.js +12 -24
- package/dist/errors/index.js.map +1 -1
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.js +2 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/transaction.d.ts +15 -0
- package/dist/helpers/transaction.js +47 -0
- package/dist/helpers/transaction.js.map +1 -0
- package/dist/index.d.ts +13 -11
- package/dist/index.js +16 -34
- package/dist/index.js.map +1 -1
- package/dist/nymphJoiProps.d.ts +1 -1
- package/dist/nymphJoiProps.js +10 -15
- package/dist/nymphJoiProps.js.map +1 -1
- package/dist/testArtifacts.d.ts +21 -6
- package/dist/testArtifacts.js +124 -50
- package/dist/testArtifacts.js.map +1 -1
- package/dist/testMocks.d.ts +27 -12
- package/dist/testMocks.js +44 -33
- package/dist/testMocks.js.map +1 -1
- package/dist/utils.d.ts +5 -5
- package/dist/utils.js +106 -68
- package/dist/utils.js.map +1 -1
- package/jest.config.js +31 -5
- package/package.json +43 -24
- package/src/Entity.test.ts +73 -23
- package/src/Entity.ts +555 -169
- package/src/Entity.types.ts +102 -90
- package/src/Nymph.ts +930 -517
- package/src/Nymph.types.ts +145 -39
- package/src/conf/defaults.ts +34 -1
- package/src/conf/index.ts +50 -2
- package/src/decorators/index.ts +1 -0
- package/src/decorators/transactional.ts +63 -0
- package/src/driver/NymphDriver.ts +987 -417
- package/src/driver/index.ts +1 -3
- package/src/driver/testArtifacts.ts +2699 -1628
- package/src/errors/EntityUniqueConstraintError.ts +6 -0
- package/src/errors/HttpError.ts +12 -0
- package/src/errors/InvalidStateError.ts +6 -0
- package/src/errors/MethodFailedError.ts +6 -0
- package/src/errors/QueryFailedError.ts +3 -1
- package/src/errors/index.ts +16 -8
- package/src/helpers/index.ts +1 -0
- package/src/helpers/transaction.ts +65 -0
- package/src/index.ts +13 -11
- package/src/nymphJoiProps.ts +2 -2
- package/src/testArtifacts.ts +69 -20
- package/src/testMocks.ts +107 -41
- package/src/utils.ts +102 -67
- package/tsconfig.json +6 -3
- package/typedoc.json +4 -0
- package/dist/conf/d.d.ts +0 -6
- package/dist/conf/d.js +0 -3
- package/dist/conf/d.js.map +0 -1
- package/src/conf/d.ts +0 -24
package/dist/Entity.types.d.ts
CHANGED
|
@@ -1,24 +1,32 @@
|
|
|
1
|
-
import type Nymph from './Nymph';
|
|
2
|
-
import type
|
|
1
|
+
import type Nymph from './Nymph.js';
|
|
2
|
+
import type Entity from './Entity.js';
|
|
3
3
|
export type ACProperties = {
|
|
4
|
-
user:
|
|
5
|
-
group:
|
|
6
|
-
acUser:
|
|
7
|
-
acGroup:
|
|
8
|
-
acOther:
|
|
9
|
-
acRead:
|
|
10
|
-
acWrite:
|
|
11
|
-
acFull:
|
|
4
|
+
user: string | null;
|
|
5
|
+
group: string | null;
|
|
6
|
+
acUser: number | null;
|
|
7
|
+
acGroup: number | null;
|
|
8
|
+
acOther: number | null;
|
|
9
|
+
acRead: (string | null)[] | null;
|
|
10
|
+
acWrite: (string | null)[] | null;
|
|
11
|
+
acFull: (string | null)[] | null;
|
|
12
12
|
};
|
|
13
13
|
export type EntityReference = ['nymph_entity_reference', string, string];
|
|
14
|
+
export type ClassReference = ['nymph_class_reference', string];
|
|
14
15
|
export type EntityData = {
|
|
15
16
|
[k: string]: any;
|
|
16
17
|
};
|
|
17
18
|
export type SerializedEntityData = {
|
|
18
19
|
[k: string]: string;
|
|
19
20
|
};
|
|
21
|
+
export type EntityObject = {
|
|
22
|
+
guid: string | null;
|
|
23
|
+
cdate: number | null;
|
|
24
|
+
mdate: number | null;
|
|
25
|
+
tags: string[];
|
|
26
|
+
[k: string]: any;
|
|
27
|
+
};
|
|
20
28
|
export type EntityJson = {
|
|
21
|
-
class:
|
|
29
|
+
class: EntityConstructor;
|
|
22
30
|
guid: string | null;
|
|
23
31
|
cdate: number | null;
|
|
24
32
|
mdate: number | null;
|
|
@@ -26,7 +34,7 @@ export type EntityJson = {
|
|
|
26
34
|
data: EntityData;
|
|
27
35
|
};
|
|
28
36
|
export type EntityPatch = {
|
|
29
|
-
class:
|
|
37
|
+
class: EntityConstructor;
|
|
30
38
|
guid: string;
|
|
31
39
|
mdate: number | null;
|
|
32
40
|
set: EntityData;
|
|
@@ -34,46 +42,285 @@ export type EntityPatch = {
|
|
|
34
42
|
addTags: string[];
|
|
35
43
|
removeTags: string[];
|
|
36
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* Data Object interface.
|
|
47
|
+
*
|
|
48
|
+
* Objects which hold data from some type of storage.
|
|
49
|
+
*/
|
|
37
50
|
export interface DataObjectInterface {
|
|
51
|
+
/**
|
|
52
|
+
* Search the array for this object and return the corresponding index.
|
|
53
|
+
*
|
|
54
|
+
* If `strict` is false, `is()` is used to compare. If `strict` is true,
|
|
55
|
+
* `equals()` is used.
|
|
56
|
+
*
|
|
57
|
+
* @param array The array to search.
|
|
58
|
+
* @param strict Whether to use stronger comparison.
|
|
59
|
+
* @returns The index if the object is in the array, -1 if it isn't.
|
|
60
|
+
*/
|
|
38
61
|
$arraySearch(array: any[], strict?: boolean): number;
|
|
39
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Delete the object from storage.
|
|
64
|
+
*
|
|
65
|
+
* An error is thrown on failure.
|
|
66
|
+
*/
|
|
67
|
+
$delete(): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Perform a more strict comparison of this object to another.
|
|
70
|
+
*
|
|
71
|
+
* @param object The object to compare.
|
|
72
|
+
* @returns True or false.
|
|
73
|
+
*/
|
|
40
74
|
$equals(object: any): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Check whether this object is in an array.
|
|
77
|
+
*
|
|
78
|
+
* If `strict` is false, `is()` is used to compare. If `strict` is true,
|
|
79
|
+
* `equals()` is used.
|
|
80
|
+
*
|
|
81
|
+
* @param array The array to search.
|
|
82
|
+
* @param strict Whether to use stronger comparison.
|
|
83
|
+
* @returns True if the object is in the array, false if it isn't.
|
|
84
|
+
*/
|
|
41
85
|
$inArray(array: any[], strict?: boolean): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Perform a less strict comparison of this object to another.
|
|
88
|
+
*
|
|
89
|
+
* @param object The object to compare.
|
|
90
|
+
* @returns True or false.
|
|
91
|
+
*/
|
|
42
92
|
$is(object: any): boolean;
|
|
43
|
-
|
|
44
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Refresh the object from storage. (Bypasses Nymph's cache.)
|
|
95
|
+
*
|
|
96
|
+
* @returns False if the data has not been saved, true on success. An error is
|
|
97
|
+
* thrown on failure.
|
|
98
|
+
*/
|
|
99
|
+
$refresh(): Promise<boolean>;
|
|
100
|
+
/**
|
|
101
|
+
* Save the object to storage.
|
|
102
|
+
*
|
|
103
|
+
* An error is thrown on failure.
|
|
104
|
+
*/
|
|
105
|
+
$save(): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* The object's data.
|
|
108
|
+
*/
|
|
45
109
|
[k: string]: any;
|
|
46
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Entity interface.
|
|
113
|
+
*/
|
|
47
114
|
export interface EntityInterface extends DataObjectInterface {
|
|
115
|
+
/**
|
|
116
|
+
* The instance of Nymph to use for queries.
|
|
117
|
+
*/
|
|
48
118
|
$nymph: Nymph;
|
|
119
|
+
/**
|
|
120
|
+
* The entity's Globally Unique ID.
|
|
121
|
+
*
|
|
122
|
+
* This is a 12 byte number represented as a lower case HEX string (24
|
|
123
|
+
* characters).
|
|
124
|
+
*/
|
|
49
125
|
guid: string | null;
|
|
126
|
+
/**
|
|
127
|
+
* The creation date of the entity as a Unix timestamp in milliseconds.
|
|
128
|
+
*/
|
|
50
129
|
cdate: number | null;
|
|
130
|
+
/**
|
|
131
|
+
* The modified date of the entity as a Unix timestamp in milliseconds.
|
|
132
|
+
*/
|
|
51
133
|
mdate: number | null;
|
|
134
|
+
/**
|
|
135
|
+
* Array of the entity's tags.
|
|
136
|
+
*/
|
|
52
137
|
tags: string[];
|
|
138
|
+
/**
|
|
139
|
+
* Get a GUID for the entity.
|
|
140
|
+
*
|
|
141
|
+
* If the entity has already been saved, this will just return the GUID.
|
|
142
|
+
*
|
|
143
|
+
* If the entity has not yet been saved, this will return a new GUID that gets
|
|
144
|
+
* held by the entity. The `guid` property will remain null, but this method
|
|
145
|
+
* will then always return the same GUID. When the entity is eventually saved
|
|
146
|
+
* into the database, this GUID will be used.
|
|
147
|
+
*/
|
|
148
|
+
$getGuaranteedGUID(): string;
|
|
149
|
+
/**
|
|
150
|
+
* Add one or more tags.
|
|
151
|
+
*
|
|
152
|
+
* @param tags List of tags.
|
|
153
|
+
*/
|
|
53
154
|
$addTag(...tags: string[]): void;
|
|
155
|
+
/**
|
|
156
|
+
* Replace any referenced entities in the data with sleeping references.
|
|
157
|
+
*
|
|
158
|
+
* Calling this function ensures that the next time a referenced entity is
|
|
159
|
+
* accessed, it will be retrieved from the DB (unless it is in Nymph's cache).
|
|
160
|
+
*/
|
|
54
161
|
$clearCache(): void;
|
|
162
|
+
/**
|
|
163
|
+
* Get the client enabled methods.
|
|
164
|
+
*
|
|
165
|
+
* @returns The names of methods allowed to be called by the frontend with
|
|
166
|
+
* serverCall.
|
|
167
|
+
*/
|
|
55
168
|
$getClientEnabledMethods(): string[];
|
|
56
|
-
|
|
169
|
+
/**
|
|
170
|
+
* Used to retrieve the data object.
|
|
171
|
+
*
|
|
172
|
+
* This should only be used by Nymph to save the data into storage.
|
|
173
|
+
*
|
|
174
|
+
* @param includeSData Whether to include the serialized data as well.
|
|
175
|
+
* @param referenceOnlyExisting Whether to only turn existing entities into
|
|
176
|
+
* references.
|
|
177
|
+
* @returns The entity's data object.
|
|
178
|
+
*/
|
|
179
|
+
$getData(includeSData?: boolean, referenceOnlyExisting?: boolean): EntityData;
|
|
180
|
+
/**
|
|
181
|
+
* Used to retrieve the serialized data object.
|
|
182
|
+
*
|
|
183
|
+
* This should only be used by Nymph to save the data object into storage.
|
|
184
|
+
*
|
|
185
|
+
* This method is used by Nymph to avoid unserializing data that hasn't been
|
|
186
|
+
* requested yet.
|
|
187
|
+
*
|
|
188
|
+
* It should always be called after getData().
|
|
189
|
+
*
|
|
190
|
+
* @returns The entity's serialized data object.
|
|
191
|
+
*/
|
|
57
192
|
$getSData(): SerializedEntityData;
|
|
193
|
+
/**
|
|
194
|
+
* Get an array of strings that **must** be unique across the current etype.
|
|
195
|
+
*
|
|
196
|
+
* When you try to save another entity with any of the same unique strings,
|
|
197
|
+
* Nymph will throw an error.
|
|
198
|
+
*
|
|
199
|
+
* The default implementation of this method returns an empty array, meaning
|
|
200
|
+
* there are no uniqueness constraints applied to its etype.
|
|
201
|
+
*
|
|
202
|
+
* @returns Resolves to an array of entity's unique constraint strings.
|
|
203
|
+
*/
|
|
204
|
+
$getUniques(): Promise<string[]>;
|
|
205
|
+
/**
|
|
206
|
+
* Get the original values of the AC properties.
|
|
207
|
+
*
|
|
208
|
+
* @returns An object of AC properties.
|
|
209
|
+
*/
|
|
58
210
|
$getOriginalAcValues(): ACProperties;
|
|
211
|
+
/**
|
|
212
|
+
* Get the current values of the AC properties.
|
|
213
|
+
*
|
|
214
|
+
* @returns An object of AC properties.
|
|
215
|
+
*/
|
|
216
|
+
$getCurrentAcValues(): ACProperties;
|
|
217
|
+
/**
|
|
218
|
+
* Get an object that holds the same data as the entity.
|
|
219
|
+
*
|
|
220
|
+
* This provides an object that can be validated.
|
|
221
|
+
*
|
|
222
|
+
* @returns A pure object representation of the entity.
|
|
223
|
+
*/
|
|
59
224
|
$getValidatable(): Object;
|
|
225
|
+
/**
|
|
226
|
+
* Get the entity's tags.
|
|
227
|
+
*
|
|
228
|
+
* Using this instead of accessing the `tags` prop directly will wake sleeping
|
|
229
|
+
* references.
|
|
230
|
+
*
|
|
231
|
+
* @returns The entity's tags.
|
|
232
|
+
*/
|
|
60
233
|
$getTags(): string[];
|
|
234
|
+
/**
|
|
235
|
+
* Check that the entity has all of the given tags.
|
|
236
|
+
*
|
|
237
|
+
* @param tags List of tags.
|
|
238
|
+
* @returns True or false.
|
|
239
|
+
*/
|
|
61
240
|
$hasTag(...tags: string[]): boolean;
|
|
241
|
+
/**
|
|
242
|
+
* Accept JSON data from the client.
|
|
243
|
+
*
|
|
244
|
+
* The given data must already be dereferenced (class references turned into
|
|
245
|
+
* classes and entity references turned into entities).
|
|
246
|
+
*
|
|
247
|
+
* This function uses the security protection lists:
|
|
248
|
+
*
|
|
249
|
+
* - $protectedTags
|
|
250
|
+
* - $protectedData
|
|
251
|
+
* - $allowlistTags
|
|
252
|
+
* - $allowlistData
|
|
253
|
+
*
|
|
254
|
+
* @param input The input data. Please note, this will be modified
|
|
255
|
+
* (destroyed).
|
|
256
|
+
* @param allowConflict Allow to accept data that is older than the current
|
|
257
|
+
* data.
|
|
258
|
+
*/
|
|
62
259
|
$jsonAcceptData(input: EntityJson, allowConflict?: boolean): void;
|
|
260
|
+
/**
|
|
261
|
+
* Accept JSON patch from the client.
|
|
262
|
+
*
|
|
263
|
+
* The given data must already be dereferenced (class references turned into
|
|
264
|
+
* classes and entity references turned into entities).
|
|
265
|
+
*
|
|
266
|
+
* This function uses the security protection lists:
|
|
267
|
+
*
|
|
268
|
+
* - $protectedTags
|
|
269
|
+
* - $protectedData
|
|
270
|
+
* - $allowlistTags
|
|
271
|
+
* - $allowlistData
|
|
272
|
+
*
|
|
273
|
+
* @param patch The patch data. Please note, this will be modified
|
|
274
|
+
* (destroyed).
|
|
275
|
+
* @param allowConflict Allow to accept data that is older than the current
|
|
276
|
+
* data.
|
|
277
|
+
*/
|
|
63
278
|
$jsonAcceptPatch(patch: EntityPatch, allowConflict?: boolean): void;
|
|
64
|
-
|
|
279
|
+
/**
|
|
280
|
+
* Used to set the data.
|
|
281
|
+
*
|
|
282
|
+
* This should only be used by Nymph to push the data from storage or the
|
|
283
|
+
* client.
|
|
284
|
+
*
|
|
285
|
+
* The given data must already be dereferenced (class references turned into
|
|
286
|
+
* classes and entity references turned into entities).
|
|
287
|
+
*
|
|
288
|
+
* `sdata` is used by Nymph to avoid unserializing data that hasn't been
|
|
289
|
+
* requested yet.
|
|
290
|
+
*
|
|
291
|
+
* If `source` is set to "server", the data is coming from the DB or the
|
|
292
|
+
* cache. If not, assume the data is coming from the client and can't be
|
|
293
|
+
* trusted.
|
|
294
|
+
*
|
|
295
|
+
* @param data The data object.
|
|
296
|
+
* @param sdata The serialized data object.
|
|
297
|
+
* @param source If this is set to "server", the data is coming from the DB.
|
|
298
|
+
*/
|
|
299
|
+
$putData(data: EntityData, sdata?: SerializedEntityData, source?: 'server'): void;
|
|
300
|
+
/**
|
|
301
|
+
* Remove one or more tags.
|
|
302
|
+
*
|
|
303
|
+
* @param tags List of tags.
|
|
304
|
+
*/
|
|
65
305
|
$removeTag(...tags: string[]): void;
|
|
66
|
-
|
|
306
|
+
/**
|
|
307
|
+
* Return a Nymph Entity Reference for this entity.
|
|
308
|
+
*
|
|
309
|
+
* If the entity hasn't been saved yet (and has no GUID), it will use the
|
|
310
|
+
* guaranteed GUID from `$getGuaranteedGUID`, unless `existingOnly` is true,
|
|
311
|
+
* then it will return the entity.
|
|
312
|
+
*
|
|
313
|
+
* @param existingOnly Whether to only turn existing entities into references.
|
|
314
|
+
* @returns A Nymph Entity Reference array.
|
|
315
|
+
*/
|
|
316
|
+
$toReference(existingOnly?: boolean): EntityReference | EntityInterface;
|
|
317
|
+
/**
|
|
318
|
+
* Set whether to use "skipAc" when accessing entity references.
|
|
319
|
+
*
|
|
320
|
+
* @param useSkipAc True or false, whether to use it.
|
|
321
|
+
*/
|
|
67
322
|
$useSkipAc(useSkipAc: boolean): void;
|
|
68
323
|
}
|
|
69
|
-
export type EntityConstructor = (new (...args: any[]) =>
|
|
70
|
-
|
|
71
|
-
ETYPE: string;
|
|
72
|
-
class: string;
|
|
73
|
-
searchRestrictedData: string[];
|
|
74
|
-
clientEnabledStaticMethods: string[];
|
|
75
|
-
factory(guid?: string): Promise<EntityInterface>;
|
|
76
|
-
factorySync(guid?: string): EntityInterface;
|
|
77
|
-
factoryReference(reference: EntityReference): EntityInterface;
|
|
78
|
-
alterOptions?<T extends Options>(options: T): T;
|
|
324
|
+
export type EntityConstructor<D extends EntityData = EntityData, E extends Entity<D> = Entity<D>> = (new (...args: any[]) => E) & {
|
|
325
|
+
[k in keyof typeof Entity]: (typeof Entity)[k];
|
|
79
326
|
};
|
package/dist/Entity.types.js
CHANGED