@nymphjs/nymph 1.0.0-alpha.1 → 1.0.0-alpha.13

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 (47) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/README.md +17 -7
  3. package/dist/Entity.d.ts +3 -0
  4. package/dist/Entity.js +15 -17
  5. package/dist/Entity.js.map +1 -1
  6. package/dist/Entity.test.js +6 -3
  7. package/dist/Entity.test.js.map +1 -1
  8. package/dist/Entity.types.d.ts +4 -1
  9. package/dist/Nymph.d.ts +56 -53
  10. package/dist/Nymph.js +138 -67
  11. package/dist/Nymph.js.map +1 -1
  12. package/dist/Nymph.types.d.ts +49 -28
  13. package/dist/Nymph.types.js +8 -0
  14. package/dist/Nymph.types.js.map +1 -1
  15. package/dist/driver/NymphDriver.d.ts +5 -2
  16. package/dist/driver/NymphDriver.js +68 -39
  17. package/dist/driver/NymphDriver.js.map +1 -1
  18. package/dist/driver/testArtifacts.d.ts +4 -3
  19. package/dist/driver/testArtifacts.js +265 -167
  20. package/dist/driver/testArtifacts.js.map +1 -1
  21. package/dist/index.d.ts +2 -1
  22. package/dist/index.js +3 -2
  23. package/dist/index.js.map +1 -1
  24. package/dist/nymphJoiProps.d.ts +8 -0
  25. package/dist/nymphJoiProps.js +24 -0
  26. package/dist/nymphJoiProps.js.map +1 -0
  27. package/dist/testArtifacts.js +0 -3
  28. package/dist/testArtifacts.js.map +1 -1
  29. package/dist/testMocks.d.ts +14 -13
  30. package/dist/testMocks.js +21 -11
  31. package/dist/testMocks.js.map +1 -1
  32. package/dist/utils.d.ts +2 -1
  33. package/dist/utils.js +9 -10
  34. package/dist/utils.js.map +1 -1
  35. package/package.json +3 -2
  36. package/src/Entity.test.ts +7 -4
  37. package/src/Entity.ts +22 -12
  38. package/src/Entity.types.ts +10 -1
  39. package/src/Nymph.ts +203 -119
  40. package/src/Nymph.types.ts +91 -22
  41. package/src/driver/NymphDriver.ts +93 -46
  42. package/src/driver/testArtifacts.ts +307 -161
  43. package/src/index.ts +3 -1
  44. package/src/nymphJoiProps.ts +24 -0
  45. package/src/testArtifacts.ts +0 -5
  46. package/src/testMocks.ts +34 -29
  47. package/src/utils.ts +12 -10
package/src/Nymph.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { Config, ConfigDefaults as defaults } from './conf';
2
2
  import { NymphDriver } from './driver';
3
- import { EntityConstructor, EntityInterface } from './Entity.types';
3
+ import Entity from './Entity';
4
+ import { EntityConstructor, EntityData, EntityInterface } from './Entity.types';
4
5
  import { ClassNotAvailableError } from './errors';
5
- import {
6
+ import type {
6
7
  Selector,
7
8
  Options,
8
9
  NymphConnectCallback,
@@ -24,6 +25,9 @@ import {
24
25
  NymphBeforeDeleteUIDCallback,
25
26
  NymphAfterDeleteUIDCallback,
26
27
  NymphEventType,
28
+ NymphQueryCallback,
29
+ FormattedSelector,
30
+ TilmeldInterface,
27
31
  } from './Nymph.types';
28
32
 
29
33
  /**
@@ -36,45 +40,63 @@ import {
36
40
  * @see http://nymph.io/
37
41
  */
38
42
  export default class Nymph {
39
- public static config: Config;
40
- public static driver: NymphDriver;
41
- public static entityClasses: { [k: string]: EntityConstructor } = {};
42
- public static Tilmeld: any = undefined;
43
- private static connectCallbacks: NymphConnectCallback[] = [];
44
- private static disconnectCallbacks: NymphDisconnectCallback[] = [];
45
- private static beforeGetEntityCallbacks: NymphBeforeGetEntityCallback[] = [];
46
- private static beforeGetEntitiesCallbacks: NymphBeforeGetEntitiesCallback[] =
47
- [];
48
- private static beforeSaveEntityCallbacks: NymphBeforeSaveEntityCallback[] =
49
- [];
50
- private static afterSaveEntityCallbacks: NymphAfterSaveEntityCallback[] = [];
51
- private static beforeDeleteEntityCallbacks: NymphBeforeDeleteEntityCallback[] =
52
- [];
53
- private static afterDeleteEntityCallbacks: NymphAfterDeleteEntityCallback[] =
54
- [];
55
- private static beforeDeleteEntityByIDCallbacks: NymphBeforeDeleteEntityByIDCallback[] =
43
+ /**
44
+ * The PubSub config.
45
+ */
46
+ public config: Config;
47
+
48
+ /**
49
+ * The Nymph database driver.
50
+ */
51
+ public driver: NymphDriver;
52
+
53
+ /**
54
+ * An optional Tilmeld user/group manager instance.
55
+ */
56
+ public tilmeld?: TilmeldInterface = undefined;
57
+
58
+ /**
59
+ * A simple map of names to Entity classes.
60
+ */
61
+ private entityClasses: { [k: string]: EntityConstructor } = {};
62
+
63
+ /**
64
+ * The entity class for this instance of Nymph.
65
+ */
66
+ public Entity: typeof Entity = Entity;
67
+
68
+ private connectCallbacks: NymphConnectCallback[] = [];
69
+ private disconnectCallbacks: NymphDisconnectCallback[] = [];
70
+ private queryCallbacks: NymphQueryCallback[] = [];
71
+ private beforeGetEntityCallbacks: NymphBeforeGetEntityCallback[] = [];
72
+ private beforeGetEntitiesCallbacks: NymphBeforeGetEntitiesCallback[] = [];
73
+ private beforeSaveEntityCallbacks: NymphBeforeSaveEntityCallback[] = [];
74
+ private afterSaveEntityCallbacks: NymphAfterSaveEntityCallback[] = [];
75
+ private beforeDeleteEntityCallbacks: NymphBeforeDeleteEntityCallback[] = [];
76
+ private afterDeleteEntityCallbacks: NymphAfterDeleteEntityCallback[] = [];
77
+ private beforeDeleteEntityByIDCallbacks: NymphBeforeDeleteEntityByIDCallback[] =
56
78
  [];
57
- private static afterDeleteEntityByIDCallbacks: NymphAfterDeleteEntityByIDCallback[] =
79
+ private afterDeleteEntityByIDCallbacks: NymphAfterDeleteEntityByIDCallback[] =
58
80
  [];
59
- private static beforeNewUIDCallbacks: NymphBeforeNewUIDCallback[] = [];
60
- private static afterNewUIDCallbacks: NymphAfterNewUIDCallback[] = [];
61
- private static beforeSetUIDCallbacks: NymphBeforeSetUIDCallback[] = [];
62
- private static afterSetUIDCallbacks: NymphAfterSetUIDCallback[] = [];
63
- private static beforeRenameUIDCallbacks: NymphBeforeRenameUIDCallback[] = [];
64
- private static afterRenameUIDCallbacks: NymphAfterRenameUIDCallback[] = [];
65
- private static beforeDeleteUIDCallbacks: NymphBeforeDeleteUIDCallback[] = [];
66
- private static afterDeleteUIDCallbacks: NymphAfterDeleteUIDCallback[] = [];
67
-
68
- public static setEntityClass(
69
- className: string,
70
- entityClass: EntityConstructor
71
- ) {
72
- this.entityClasses[className] = entityClass;
81
+ private beforeNewUIDCallbacks: NymphBeforeNewUIDCallback[] = [];
82
+ private afterNewUIDCallbacks: NymphAfterNewUIDCallback[] = [];
83
+ private beforeSetUIDCallbacks: NymphBeforeSetUIDCallback[] = [];
84
+ private afterSetUIDCallbacks: NymphAfterSetUIDCallback[] = [];
85
+ private beforeRenameUIDCallbacks: NymphBeforeRenameUIDCallback[] = [];
86
+ private afterRenameUIDCallbacks: NymphAfterRenameUIDCallback[] = [];
87
+ private beforeDeleteUIDCallbacks: NymphBeforeDeleteUIDCallback[] = [];
88
+ private afterDeleteUIDCallbacks: NymphAfterDeleteUIDCallback[] = [];
89
+
90
+ public addEntityClass(entityClass: EntityConstructor) {
91
+ this.entityClasses[entityClass.class] = entityClass;
92
+ entityClass.nymph = this;
73
93
  }
74
94
 
75
- public static getEntityClass(className: string): EntityConstructor {
95
+ public getEntityClass(className: string): EntityConstructor {
76
96
  if (className in this.entityClasses) {
77
- return this.entityClasses[className];
97
+ const EntityClass = this.entityClasses[className];
98
+ EntityClass.nymph = this;
99
+ return EntityClass;
78
100
  }
79
101
  throw new ClassNotAvailableError('Tried to use class: ' + className);
80
102
  }
@@ -84,16 +106,79 @@ export default class Nymph {
84
106
  *
85
107
  * @param config The Nymph configuration.
86
108
  * @param driver The Nymph database driver.
87
- * @param Tilmeld The Tilmeld user/group manager, if you want to use it.
109
+ * @param tilmeld The Tilmeld user/group manager instance, if you want to use it.
88
110
  */
89
- public static init(
111
+ public constructor(
90
112
  config: Partial<Config>,
91
113
  driver: NymphDriver,
92
- Tilmeld?: any
114
+ tilmeld?: TilmeldInterface
93
115
  ) {
94
116
  this.config = { ...defaults, ...config };
95
117
  this.driver = driver;
96
- this.Tilmeld = Tilmeld;
118
+ if (typeof tilmeld !== 'undefined') {
119
+ this.tilmeld = tilmeld;
120
+ }
121
+
122
+ class NymphEntity<T extends EntityData = EntityData> extends Entity<T> {}
123
+ NymphEntity.nymph = this;
124
+ this.Entity = NymphEntity;
125
+ this.addEntityClass(NymphEntity);
126
+
127
+ this.driver.init(this);
128
+ if (this.tilmeld) {
129
+ this.tilmeld.init(this);
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Get a clone of this instance with duplicate classes and event listeners.
135
+ *
136
+ * @returns A clone of this instance.
137
+ */
138
+ public clone() {
139
+ const nymph = new Nymph(this.config, this.driver, this.tilmeld?.clone());
140
+ for (const name in this.entityClasses) {
141
+ if (name === 'Entity' || (this.entityClasses[name] as any).skipOnClone) {
142
+ continue;
143
+ }
144
+ nymph.addEntityClass(this.entityClasses[name]);
145
+ }
146
+
147
+ const events = [
148
+ 'connect',
149
+ 'disconnect',
150
+ 'query',
151
+ 'beforeGetEntity',
152
+ 'beforeGetEntities',
153
+ 'beforeSaveEntity',
154
+ 'afterSaveEntity',
155
+ 'beforeDeleteEntity',
156
+ 'afterDeleteEntity',
157
+ 'beforeDeleteEntityByID',
158
+ 'afterDeleteEntityByID',
159
+ 'beforeNewUID',
160
+ 'afterNewUID',
161
+ 'beforeSetUID',
162
+ 'afterSetUID',
163
+ 'beforeRenameUID',
164
+ 'afterRenameUID',
165
+ 'beforeDeleteUID',
166
+ 'afterDeleteUID',
167
+ ];
168
+
169
+ for (let event of events) {
170
+ const prop = event + 'Callbacks';
171
+ // @ts-ignore: The callback should be the right type here.
172
+ const callbacks = this[prop];
173
+ for (let callback of callbacks) {
174
+ if (callback.skipOnClone) {
175
+ continue;
176
+ }
177
+ nymph.on(event as NymphEventType, callback);
178
+ }
179
+ }
180
+
181
+ return nymph;
97
182
  }
98
183
 
99
184
  /**
@@ -101,11 +186,11 @@ export default class Nymph {
101
186
  *
102
187
  * @returns Whether the instance is connected to the database.
103
188
  */
104
- public static async connect(): Promise<boolean> {
189
+ public async connect(): Promise<boolean> {
105
190
  const result = this.driver.connect();
106
191
  for (let callback of this.connectCallbacks) {
107
192
  if (callback) {
108
- callback(result);
193
+ callback(this, result);
109
194
  }
110
195
  }
111
196
  return await result;
@@ -116,33 +201,43 @@ export default class Nymph {
116
201
  *
117
202
  * @returns Whether the instance is connected to the database.
118
203
  */
119
- public static async disconnect(): Promise<boolean> {
204
+ public async disconnect(): Promise<boolean> {
120
205
  const result = this.driver.disconnect();
121
206
  for (let callback of this.disconnectCallbacks) {
122
207
  if (callback) {
123
- callback(result);
208
+ callback(this, result);
124
209
  }
125
210
  }
126
211
  return await result;
127
212
  }
128
213
 
129
214
  /**
130
- * Start an atomic transaction.
131
- *
132
- * If this function returns true, all proceeding changes will wait to be
133
- * written to the database's permanent storage until commit() is called. You
134
- * can also undo all the changes since this function ran with rollback().
215
+ * Run all the query callbacks on a query.
216
+ */
217
+ public async runQueryCallbacks(
218
+ options: Options,
219
+ selectors: FormattedSelector[]
220
+ ) {
221
+ for (let callback of this.queryCallbacks) {
222
+ if (callback) {
223
+ callback(this, options, selectors);
224
+ }
225
+ }
226
+ }
227
+
228
+ /**
229
+ * Start an atomic transaction and returns a new instance of Nymph.
135
230
  *
136
- * If it returns false instead of throwing an error, that probably means the
137
- * driver or the database doesn't support transaction. You should call
138
- * `rollback(name)` immediately in this case.
231
+ * All proceeding changes using this new instance will wait to be written to
232
+ * the database's permanent storage until commit() is called. You can also
233
+ * undo all the changes since this function ran with rollback().
139
234
  *
140
235
  * Transactions will nest as long as every name is unique. Internally, Nymph
141
236
  * uses names prefixed with "nymph-".
142
237
  *
143
238
  * @returns True on success, false on failure.
144
239
  */
145
- public static async startTransaction(name: string): Promise<boolean> {
240
+ public async startTransaction(name: string): Promise<Nymph> {
146
241
  return await this.driver.startTransaction(name);
147
242
  }
148
243
 
@@ -151,7 +246,7 @@ export default class Nymph {
151
246
  *
152
247
  * @returns True on success, false on failure.
153
248
  */
154
- public static async commit(name: string): Promise<boolean> {
249
+ public async commit(name: string): Promise<boolean> {
155
250
  return await this.driver.commit(name);
156
251
  }
157
252
 
@@ -160,7 +255,7 @@ export default class Nymph {
160
255
  *
161
256
  * @returns True on success, false on failure.
162
257
  */
163
- public static async rollback(name: string): Promise<boolean> {
258
+ public async rollback(name: string): Promise<boolean> {
164
259
  return await this.driver.rollback(name);
165
260
  }
166
261
 
@@ -169,7 +264,7 @@ export default class Nymph {
169
264
  *
170
265
  * @returns True if there is a transaction.
171
266
  */
172
- public static async inTransaction(): Promise<boolean> {
267
+ public async inTransaction(): Promise<boolean> {
173
268
  return await this.driver.inTransaction();
174
269
  }
175
270
 
@@ -194,16 +289,16 @@ export default class Nymph {
194
289
  * @param name The UID's name.
195
290
  * @returns The UID's new value, or null on failure.
196
291
  */
197
- public static async newUID(name: string): Promise<number | null> {
292
+ public async newUID(name: string): Promise<number | null> {
198
293
  for (let callback of this.beforeNewUIDCallbacks) {
199
294
  if (callback) {
200
- callback(name);
295
+ callback(this, name);
201
296
  }
202
297
  }
203
298
  const result = this.driver.newUID(name);
204
299
  for (let callback of this.afterNewUIDCallbacks) {
205
300
  if (callback) {
206
- callback(result);
301
+ callback(this, result);
207
302
  }
208
303
  }
209
304
  return await result;
@@ -214,7 +309,7 @@ export default class Nymph {
214
309
  * @param name The UID's name.
215
310
  * @returns The UID's value, or null on failure and if it doesn't exist.
216
311
  */
217
- public static async getUID(name: string): Promise<number | null> {
312
+ public async getUID(name: string): Promise<number | null> {
218
313
  return await this.driver.getUID(name);
219
314
  }
220
315
 
@@ -225,16 +320,16 @@ export default class Nymph {
225
320
  * @param value The value.
226
321
  * @returns True on success, false on failure.
227
322
  */
228
- public static async setUID(name: string, value: number): Promise<boolean> {
323
+ public async setUID(name: string, value: number): Promise<boolean> {
229
324
  for (let callback of this.beforeSetUIDCallbacks) {
230
325
  if (callback) {
231
- callback(name, value);
326
+ callback(this, name, value);
232
327
  }
233
328
  }
234
329
  const result = this.driver.setUID(name, value);
235
330
  for (let callback of this.afterSetUIDCallbacks) {
236
331
  if (callback) {
237
- callback(result);
332
+ callback(this, result);
238
333
  }
239
334
  }
240
335
  return await result;
@@ -246,16 +341,16 @@ export default class Nymph {
246
341
  * @param name The UID's name.
247
342
  * @returns True on success, false on failure.
248
343
  */
249
- public static async deleteUID(name: string): Promise<boolean> {
344
+ public async deleteUID(name: string): Promise<boolean> {
250
345
  for (let callback of this.beforeDeleteUIDCallbacks) {
251
346
  if (callback) {
252
- callback(name);
347
+ callback(this, name);
253
348
  }
254
349
  }
255
350
  const result = this.driver.deleteUID(name);
256
351
  for (let callback of this.afterDeleteUIDCallbacks) {
257
352
  if (callback) {
258
- callback(result);
353
+ callback(this, result);
259
354
  }
260
355
  }
261
356
  return await result;
@@ -268,19 +363,16 @@ export default class Nymph {
268
363
  * @param newName The new name.
269
364
  * @returns True on success, false on failure.
270
365
  */
271
- public static async renameUID(
272
- oldName: string,
273
- newName: string
274
- ): Promise<boolean> {
366
+ public async renameUID(oldName: string, newName: string): Promise<boolean> {
275
367
  for (let callback of this.beforeRenameUIDCallbacks) {
276
368
  if (callback) {
277
- callback(oldName, newName);
369
+ callback(this, oldName, newName);
278
370
  }
279
371
  }
280
372
  const result = this.driver.renameUID(oldName, newName);
281
373
  for (let callback of this.afterRenameUIDCallbacks) {
282
374
  if (callback) {
283
- callback(result);
375
+ callback(this, result);
284
376
  }
285
377
  }
286
378
  return await result;
@@ -297,16 +389,16 @@ export default class Nymph {
297
389
  * @param entity The entity.
298
390
  * @returns True on success, false on failure.
299
391
  */
300
- public static async saveEntity(entity: EntityInterface): Promise<boolean> {
392
+ public async saveEntity(entity: EntityInterface): Promise<boolean> {
301
393
  for (let callback of this.beforeSaveEntityCallbacks) {
302
394
  if (callback) {
303
- callback(entity);
395
+ callback(this, entity);
304
396
  }
305
397
  }
306
398
  const result = this.driver.saveEntity(entity);
307
399
  for (let callback of this.afterSaveEntityCallbacks) {
308
400
  if (callback) {
309
- callback(result);
401
+ callback(this, result);
310
402
  }
311
403
  }
312
404
  return await result;
@@ -379,9 +471,9 @@ export default class Nymph {
379
471
  * less than or equal to the value.
380
472
  * - ref - An array with a name, then either an entity, or a GUID. True if
381
473
  * the named property is the entity or contains the entity.
382
- * - qref - An array with a name, then a full query (including options). True
383
- * if the named property is an entity that matches the query or an array
384
- * containing an entity that matches the query.
474
+ * - qref - An array with a name, then a full query (including options) in an
475
+ * array. True if the named property is an entity that matches the query or
476
+ * contains an entity that matches the query.
385
477
  * - selector - A selector. (Keep in mind, you can also use an array of these,
386
478
  * just like any other clause.)
387
479
  *
@@ -395,10 +487,10 @@ export default class Nymph {
395
487
  * entities that were created in the last day:
396
488
  *
397
489
  * ```
398
- * [
399
- * '&',
400
- * 'gte' => ['cdate', null, '-1 day']
401
- * ]
490
+ * {
491
+ * type: '&',
492
+ * gte: ['cdate', null, '-1 day']
493
+ * }
402
494
  * ```
403
495
  *
404
496
  * Locutus' implementation: https://locutus.io/php/datetime/strtotime/
@@ -471,27 +563,21 @@ export default class Nymph {
471
563
  * @todo An option to place a total count in a var.
472
564
  * @todo Use an asterisk to specify any variable.
473
565
  */
474
- public static async getEntities<
475
- T extends EntityConstructor = EntityConstructor
476
- >(
566
+ public async getEntities<T extends EntityConstructor = EntityConstructor>(
477
567
  options: Options<T> & { return: 'guid' },
478
568
  ...selectors: Selector[]
479
569
  ): Promise<string[]>;
480
- public static async getEntities<
481
- T extends EntityConstructor = EntityConstructor
482
- >(
570
+ public async getEntities<T extends EntityConstructor = EntityConstructor>(
483
571
  options?: Options<T>,
484
572
  ...selectors: Selector[]
485
573
  ): Promise<ReturnType<T['factorySync']>[]>;
486
- public static async getEntities<
487
- T extends EntityConstructor = EntityConstructor
488
- >(
574
+ public async getEntities<T extends EntityConstructor = EntityConstructor>(
489
575
  options: Options<T> = {},
490
576
  ...selectors: Selector[]
491
577
  ): Promise<ReturnType<T['factorySync']>[] | string[]> {
492
578
  for (let callback of this.beforeGetEntitiesCallbacks) {
493
579
  if (callback) {
494
- callback(options, selectors);
580
+ callback(this, options, selectors);
495
581
  }
496
582
  }
497
583
  return await this.driver.getEntities(options, ...selectors);
@@ -510,33 +596,23 @@ export default class Nymph {
510
596
  * @param selectors Unlimited optional selectors to search for, or a single GUID. If none are given, all entities are searched for the given options.
511
597
  * @returns An entity, or null on failure or nothing found.
512
598
  */
513
- public static async getEntity<
514
- T extends EntityConstructor = EntityConstructor
515
- >(
599
+ public async getEntity<T extends EntityConstructor = EntityConstructor>(
516
600
  options: Options<T> & { return: 'guid' },
517
601
  ...selectors: Selector[]
518
602
  ): Promise<string | null>;
519
- public static async getEntity<
520
- T extends EntityConstructor = EntityConstructor
521
- >(
603
+ public async getEntity<T extends EntityConstructor = EntityConstructor>(
522
604
  options: Options<T>,
523
605
  ...selectors: Selector[]
524
606
  ): Promise<ReturnType<T['factorySync']> | null>;
525
- public static async getEntity<
526
- T extends EntityConstructor = EntityConstructor
527
- >(
607
+ public async getEntity<T extends EntityConstructor = EntityConstructor>(
528
608
  options: Options<T> & { return: 'guid' },
529
609
  guid: string
530
610
  ): Promise<string | null>;
531
- public static async getEntity<
532
- T extends EntityConstructor = EntityConstructor
533
- >(
611
+ public async getEntity<T extends EntityConstructor = EntityConstructor>(
534
612
  options: Options<T>,
535
613
  guid: string
536
614
  ): Promise<ReturnType<T['factorySync']> | null>;
537
- public static async getEntity<
538
- T extends EntityConstructor = EntityConstructor
539
- >(
615
+ public async getEntity<T extends EntityConstructor = EntityConstructor>(
540
616
  options: Options<T> = {},
541
617
  ...selectors: Selector[] | string[]
542
618
  ): Promise<ReturnType<T['factorySync']> | string | null> {
@@ -547,7 +623,7 @@ export default class Nymph {
547
623
  options.limit = 1;
548
624
  for (let callback of this.beforeGetEntityCallbacks) {
549
625
  if (callback) {
550
- callback(options, selectors as Selector[]);
626
+ callback(this, options, selectors as Selector[]);
551
627
  }
552
628
  }
553
629
  const entities = await this.driver.getEntities(
@@ -566,16 +642,16 @@ export default class Nymph {
566
642
  * @param entity The entity.
567
643
  * @returns True on success, false on failure.
568
644
  */
569
- public static async deleteEntity(entity: EntityInterface): Promise<boolean> {
645
+ public async deleteEntity(entity: EntityInterface): Promise<boolean> {
570
646
  for (let callback of this.beforeDeleteEntityCallbacks) {
571
647
  if (callback) {
572
- callback(entity);
648
+ callback(this, entity);
573
649
  }
574
650
  }
575
651
  const result = this.driver.deleteEntity(entity);
576
652
  for (let callback of this.afterDeleteEntityCallbacks) {
577
653
  if (callback) {
578
- callback(result);
654
+ callback(this, result);
579
655
  }
580
656
  }
581
657
  return await result;
@@ -588,19 +664,19 @@ export default class Nymph {
588
664
  * @param className The entity's class name.
589
665
  * @returns True on success, false on failure.
590
666
  */
591
- public static async deleteEntityByID(
667
+ public async deleteEntityByID(
592
668
  guid: string,
593
669
  className?: string
594
670
  ): Promise<boolean> {
595
671
  for (let callback of this.beforeDeleteEntityByIDCallbacks) {
596
672
  if (callback) {
597
- callback(guid, className);
673
+ callback(this, guid, className);
598
674
  }
599
675
  }
600
676
  const result = this.driver.deleteEntityByID(guid, className);
601
677
  for (let callback of this.afterDeleteEntityByIDCallbacks) {
602
678
  if (callback) {
603
- callback(result);
679
+ callback(this, result);
604
680
  }
605
681
  }
606
682
  return await result;
@@ -642,7 +718,7 @@ export default class Nymph {
642
718
  * @param filename The file to export to.
643
719
  * @returns True on success, false on failure.
644
720
  */
645
- public static async export(filename: string): Promise<boolean> {
721
+ public async export(filename: string): Promise<boolean> {
646
722
  return await this.driver.export(filename);
647
723
  }
648
724
 
@@ -651,7 +727,7 @@ export default class Nymph {
651
727
  *
652
728
  * @returns True on success, false on failure.
653
729
  */
654
- public static async exportPrint(): Promise<boolean> {
730
+ public async exportPrint(): Promise<boolean> {
655
731
  return await this.driver.exportPrint();
656
732
  }
657
733
 
@@ -661,16 +737,18 @@ export default class Nymph {
661
737
  * @param filename The file to import from.
662
738
  * @returns True on success, false on failure.
663
739
  */
664
- public static async import(filename: string): Promise<boolean> {
740
+ public async import(filename: string): Promise<boolean> {
665
741
  return await this.driver.import(filename);
666
742
  }
667
743
 
668
- public static on<T extends NymphEventType>(
744
+ public on<T extends NymphEventType>(
669
745
  event: T,
670
746
  callback: T extends 'connect'
671
747
  ? NymphConnectCallback
672
748
  : T extends 'disconnect'
673
749
  ? NymphDisconnectCallback
750
+ : T extends 'query'
751
+ ? NymphQueryCallback
674
752
  : T extends 'beforeGetEntity'
675
753
  ? NymphBeforeGetEntityCallback
676
754
  : T extends 'beforeGetEntities'
@@ -709,6 +787,8 @@ export default class Nymph {
709
787
  ? 'connectCallbacks'
710
788
  : T extends 'disconnect'
711
789
  ? 'disconnectCallbacks'
790
+ : T extends 'query'
791
+ ? 'queryCallbacks'
712
792
  : T extends 'beforeGetEntity'
713
793
  ? 'beforeGetEntityCallbacks'
714
794
  : T extends 'beforeGetEntities'
@@ -750,12 +830,14 @@ export default class Nymph {
750
830
  return () => this.off(event, callback);
751
831
  }
752
832
 
753
- public static off<T extends NymphEventType>(
833
+ public off<T extends NymphEventType>(
754
834
  event: T,
755
835
  callback: T extends 'connect'
756
836
  ? NymphConnectCallback
757
837
  : T extends 'disconnect'
758
838
  ? NymphDisconnectCallback
839
+ : T extends 'query'
840
+ ? NymphQueryCallback
759
841
  : T extends 'beforeGetEntity'
760
842
  ? NymphBeforeGetEntityCallback
761
843
  : T extends 'beforeGetEntities'
@@ -794,6 +876,8 @@ export default class Nymph {
794
876
  ? 'connectCallbacks'
795
877
  : T extends 'disconnect'
796
878
  ? 'disconnectCallbacks'
879
+ : T extends 'query'
880
+ ? 'queryCallbacks'
797
881
  : T extends 'beforeSaveEntity'
798
882
  ? 'beforeSaveEntityCallbacks'
799
883
  : T extends 'beforeGetEntity'