@nymphjs/nymph 1.0.0-beta.6 → 1.0.0-beta.61

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