@nymphjs/nymph 1.0.0-alpha.2 → 1.0.0-alpha.20

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 (53) hide show
  1. package/CHANGELOG.md +88 -0
  2. package/README.md +3 -5
  3. package/dist/Entity.d.ts +1 -1
  4. package/dist/Entity.js +4 -9
  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 +2 -2
  9. package/dist/Nymph.d.ts +6 -9
  10. package/dist/Nymph.js +50 -46
  11. package/dist/Nymph.js.map +1 -1
  12. package/dist/Nymph.types.d.ts +37 -29
  13. package/dist/Nymph.types.js +8 -0
  14. package/dist/Nymph.types.js.map +1 -1
  15. package/dist/driver/NymphDriver.d.ts +1 -1
  16. package/dist/driver/index.d.ts +0 -2
  17. package/dist/driver/index.js +1 -3
  18. package/dist/driver/index.js.map +1 -1
  19. package/dist/driver/testArtifacts.d.ts +4 -3
  20. package/dist/driver/testArtifacts.js +158 -153
  21. package/dist/driver/testArtifacts.js.map +1 -1
  22. package/dist/index.d.ts +4 -2
  23. package/dist/index.js +4 -2
  24. package/dist/index.js.map +1 -1
  25. package/dist/nymphJoiProps.d.ts +8 -0
  26. package/dist/nymphJoiProps.js +24 -0
  27. package/dist/nymphJoiProps.js.map +1 -0
  28. package/dist/testArtifacts.js +0 -3
  29. package/dist/testArtifacts.js.map +1 -1
  30. package/dist/testMocks.d.ts +14 -13
  31. package/dist/testMocks.js +21 -11
  32. package/dist/testMocks.js.map +1 -1
  33. package/dist/utils.d.ts +2 -2
  34. package/dist/utils.js +9 -7
  35. package/dist/utils.js.map +1 -1
  36. package/package.json +11 -10
  37. package/src/Entity.test.ts +7 -4
  38. package/src/Entity.ts +6 -7
  39. package/src/Entity.types.ts +2 -2
  40. package/src/Nymph.ts +76 -64
  41. package/src/Nymph.types.ts +73 -23
  42. package/src/driver/NymphDriver.ts +1 -1
  43. package/src/driver/index.ts +0 -3
  44. package/src/driver/testArtifacts.ts +22 -4
  45. package/src/index.ts +5 -2
  46. package/src/nymphJoiProps.ts +24 -0
  47. package/src/testArtifacts.ts +0 -5
  48. package/src/testMocks.ts +34 -29
  49. package/src/utils.ts +6 -9
  50. package/dist/driver/PreInitializedDriver.d.ts +0 -30
  51. package/dist/driver/PreInitializedDriver.js +0 -65
  52. package/dist/driver/PreInitializedDriver.js.map +0 -1
  53. package/src/driver/PreInitializedDriver.ts +0 -88
@@ -1,13 +1,16 @@
1
1
  import { MockNymph } from './testMocks';
2
- import Nymph from './Nymph';
2
+ import { TestBModel, TestModel, TestModelData } from './testArtifacts';
3
+ import { cloneDeep } from 'lodash';
4
+
5
+ const nymph = new MockNymph();
3
6
 
4
7
  jest.mock('./Nymph', () => ({
5
8
  __esModule: true,
6
- default: MockNymph,
9
+ default: nymph,
7
10
  }));
8
11
 
9
- import { TestModel, TestModelData } from './testArtifacts';
10
- import { cloneDeep } from 'lodash';
12
+ nymph.addEntityClass(TestModel);
13
+ nymph.addEntityClass(TestBModel);
11
14
 
12
15
  let testEntity = TestModel.factorySync();
13
16
  let entityReferenceTest: TestModel & TestModelData;
package/src/Entity.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { difference, intersection, isEqual } from 'lodash';
2
2
 
3
+ import type Nymph from './Nymph';
3
4
  import {
4
5
  ACProperties,
5
6
  EntityConstructor,
@@ -11,7 +12,6 @@ import {
11
12
  SerializedEntityData,
12
13
  } from './Entity.types';
13
14
  import { EntityConflictError, InvalidParametersError } from './errors';
14
- import nymph, { Nymph } from './Nymph';
15
15
  import {
16
16
  entitiesToReferences,
17
17
  referencesToEntities,
@@ -94,7 +94,7 @@ export default class Entity<T extends EntityData = EntityData>
94
94
  /**
95
95
  * The instance of Nymph to use for queries.
96
96
  */
97
- public static nymph = nymph;
97
+ public static nymph = {} as Nymph;
98
98
  /**
99
99
  * A unique name for this type of entity used to separate its data from other
100
100
  * types of entities in the database.
@@ -108,7 +108,7 @@ export default class Entity<T extends EntityData = EntityData>
108
108
  */
109
109
  public static class = 'Entity';
110
110
 
111
- public $nymph: Nymph = Entity.nymph;
111
+ public $nymph: Nymph;
112
112
  public guid: string | null = null;
113
113
  public cdate: number | null = null;
114
114
  public mdate: number | null = null;
@@ -203,6 +203,7 @@ export default class Entity<T extends EntityData = EntityData>
203
203
  * @param guid The ID of the entity to load, undefined for a new entity.
204
204
  */
205
205
  public constructor(guid?: string) {
206
+ this.$nymph = (this.constructor as EntityConstructor).nymph;
206
207
  this.$dataHandler = {
207
208
  has: (data: EntityData, name: string) => {
208
209
  this.$referenceWake();
@@ -375,7 +376,7 @@ export default class Entity<T extends EntityData = EntityData>
375
376
  const data = this.$getData(true);
376
377
  for (const key in data) {
377
378
  if (this.$privateData.indexOf(key) === -1) {
378
- obj.data[key] = entitiesToReferences(data[key], this.$nymph);
379
+ obj.data[key] = entitiesToReferences(data[key]);
379
380
  }
380
381
  }
381
382
  return obj;
@@ -455,7 +456,7 @@ export default class Entity<T extends EntityData = EntityData>
455
456
  const unused: any = (this as any)[key];
456
457
  }
457
458
  }
458
- return entitiesToReferences({ ...this.$dataStore }, this.$nymph);
459
+ return entitiesToReferences({ ...this.$dataStore });
459
460
  }
460
461
 
461
462
  public $getSData() {
@@ -825,5 +826,3 @@ export default class Entity<T extends EntityData = EntityData>
825
826
  this.$skipAc = !!skipAc;
826
827
  }
827
828
  }
828
-
829
- Entity.nymph.setEntityClass(Entity.class, Entity);
@@ -1,5 +1,5 @@
1
- import { Nymph } from './Nymph';
2
- import { Options } from './Nymph.types';
1
+ import type Nymph from './Nymph';
2
+ import type { Options } from './Nymph.types';
3
3
 
4
4
  export type ACProperties = {
5
5
  user: any;
package/src/Nymph.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Config, ConfigDefaults as defaults } from './conf';
2
2
  import { NymphDriver } from './driver';
3
- import PreInitializedDriver from './driver/PreInitializedDriver';
4
- import { EntityConstructor, EntityInterface } from './Entity.types';
3
+ import Entity from './Entity';
4
+ import { EntityConstructor, EntityData, EntityInterface } from './Entity.types';
5
5
  import { ClassNotAvailableError } from './errors';
6
6
  import type {
7
7
  Selector,
@@ -39,7 +39,7 @@ import type {
39
39
  * @copyright SciActive Inc
40
40
  * @see http://nymph.io/
41
41
  */
42
- export class Nymph {
42
+ export default class Nymph {
43
43
  /**
44
44
  * The PubSub config.
45
45
  */
@@ -58,7 +58,12 @@ export class Nymph {
58
58
  /**
59
59
  * A simple map of names to Entity classes.
60
60
  */
61
- public entityClasses: { [k: string]: EntityConstructor } = {};
61
+ private entityClasses: { [k: string]: EntityConstructor } = {};
62
+
63
+ /**
64
+ * The entity class for this instance of Nymph.
65
+ */
66
+ public Entity: typeof Entity = Entity;
62
67
 
63
68
  private connectCallbacks: NymphConnectCallback[] = [];
64
69
  private disconnectCallbacks: NymphDisconnectCallback[] = [];
@@ -82,8 +87,9 @@ export class Nymph {
82
87
  private beforeDeleteUIDCallbacks: NymphBeforeDeleteUIDCallback[] = [];
83
88
  private afterDeleteUIDCallbacks: NymphAfterDeleteUIDCallback[] = [];
84
89
 
85
- public setEntityClass(className: string, entityClass: EntityConstructor) {
86
- this.entityClasses[className] = entityClass;
90
+ public addEntityClass(entityClass: EntityConstructor) {
91
+ this.entityClasses[entityClass.class] = entityClass;
92
+ entityClass.nymph = this;
87
93
  }
88
94
 
89
95
  public getEntityClass(className: string): EntityConstructor {
@@ -95,19 +101,47 @@ export class Nymph {
95
101
  throw new ClassNotAvailableError('Tried to use class: ' + className);
96
102
  }
97
103
 
98
- public constructor() {
99
- this.config = { ...defaults };
100
- this.driver = new PreInitializedDriver();
104
+ /**
105
+ * Initialize Nymph.
106
+ *
107
+ * @param config The Nymph configuration.
108
+ * @param driver The Nymph database driver.
109
+ * @param tilmeld The Tilmeld user/group manager instance, if you want to use it.
110
+ */
111
+ public constructor(
112
+ config: Partial<Config>,
113
+ driver: NymphDriver,
114
+ tilmeld?: TilmeldInterface
115
+ ) {
116
+ this.config = { ...defaults, ...config };
117
+ this.driver = driver;
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
+ }
101
131
  }
102
132
 
133
+ /**
134
+ * Get a clone of this instance with duplicate classes and event listeners.
135
+ *
136
+ * @returns A clone of this instance.
137
+ */
103
138
  public clone() {
104
- const nymph = new Nymph();
105
- nymph.config = this.config;
106
- nymph.driver = this.driver;
107
- nymph.tilmeld = this.tilmeld;
108
- nymph.entityClasses = this.entityClasses;
109
- if (nymph.tilmeld) {
110
- nymph.tilmeld.nymph = nymph;
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]);
111
145
  }
112
146
 
113
147
  const events = [
@@ -137,6 +171,9 @@ export class Nymph {
137
171
  // @ts-ignore: The callback should be the right type here.
138
172
  const callbacks = this[prop];
139
173
  for (let callback of callbacks) {
174
+ if (callback.skipOnClone) {
175
+ continue;
176
+ }
140
177
  nymph.on(event as NymphEventType, callback);
141
178
  }
142
179
  }
@@ -144,29 +181,6 @@ export class Nymph {
144
181
  return nymph;
145
182
  }
146
183
 
147
- /**
148
- * Initialize Nymph.
149
- *
150
- * @param config The Nymph configuration.
151
- * @param driver The Nymph database driver.
152
- * @param tilmeld The Tilmeld user/group manager instance, if you want to use it.
153
- */
154
- public init(
155
- config: Partial<Config>,
156
- driver: NymphDriver,
157
- tilmeld?: TilmeldInterface
158
- ) {
159
- this.config = { ...defaults, ...config };
160
- this.driver = driver;
161
- if (typeof tilmeld !== 'undefined') {
162
- this.tilmeld = tilmeld;
163
- }
164
- this.driver.init(this);
165
- if (this.tilmeld) {
166
- this.tilmeld.init(this);
167
- }
168
- }
169
-
170
184
  /**
171
185
  * Connect to the database.
172
186
  *
@@ -176,7 +190,7 @@ export class Nymph {
176
190
  const result = this.driver.connect();
177
191
  for (let callback of this.connectCallbacks) {
178
192
  if (callback) {
179
- callback(result);
193
+ callback(this, result);
180
194
  }
181
195
  }
182
196
  return await result;
@@ -191,7 +205,7 @@ export class Nymph {
191
205
  const result = this.driver.disconnect();
192
206
  for (let callback of this.disconnectCallbacks) {
193
207
  if (callback) {
194
- callback(result);
208
+ callback(this, result);
195
209
  }
196
210
  }
197
211
  return await result;
@@ -206,7 +220,7 @@ export class Nymph {
206
220
  ) {
207
221
  for (let callback of this.queryCallbacks) {
208
222
  if (callback) {
209
- callback(options, selectors);
223
+ callback(this, options, selectors);
210
224
  }
211
225
  }
212
226
  }
@@ -278,13 +292,13 @@ export class Nymph {
278
292
  public async newUID(name: string): Promise<number | null> {
279
293
  for (let callback of this.beforeNewUIDCallbacks) {
280
294
  if (callback) {
281
- callback(name);
295
+ callback(this, name);
282
296
  }
283
297
  }
284
298
  const result = this.driver.newUID(name);
285
299
  for (let callback of this.afterNewUIDCallbacks) {
286
300
  if (callback) {
287
- callback(result);
301
+ callback(this, result);
288
302
  }
289
303
  }
290
304
  return await result;
@@ -309,13 +323,13 @@ export class Nymph {
309
323
  public async setUID(name: string, value: number): Promise<boolean> {
310
324
  for (let callback of this.beforeSetUIDCallbacks) {
311
325
  if (callback) {
312
- callback(name, value);
326
+ callback(this, name, value);
313
327
  }
314
328
  }
315
329
  const result = this.driver.setUID(name, value);
316
330
  for (let callback of this.afterSetUIDCallbacks) {
317
331
  if (callback) {
318
- callback(result);
332
+ callback(this, result);
319
333
  }
320
334
  }
321
335
  return await result;
@@ -330,13 +344,13 @@ export class Nymph {
330
344
  public async deleteUID(name: string): Promise<boolean> {
331
345
  for (let callback of this.beforeDeleteUIDCallbacks) {
332
346
  if (callback) {
333
- callback(name);
347
+ callback(this, name);
334
348
  }
335
349
  }
336
350
  const result = this.driver.deleteUID(name);
337
351
  for (let callback of this.afterDeleteUIDCallbacks) {
338
352
  if (callback) {
339
- callback(result);
353
+ callback(this, result);
340
354
  }
341
355
  }
342
356
  return await result;
@@ -352,13 +366,13 @@ export class Nymph {
352
366
  public async renameUID(oldName: string, newName: string): Promise<boolean> {
353
367
  for (let callback of this.beforeRenameUIDCallbacks) {
354
368
  if (callback) {
355
- callback(oldName, newName);
369
+ callback(this, oldName, newName);
356
370
  }
357
371
  }
358
372
  const result = this.driver.renameUID(oldName, newName);
359
373
  for (let callback of this.afterRenameUIDCallbacks) {
360
374
  if (callback) {
361
- callback(result);
375
+ callback(this, result);
362
376
  }
363
377
  }
364
378
  return await result;
@@ -378,13 +392,13 @@ export class Nymph {
378
392
  public async saveEntity(entity: EntityInterface): Promise<boolean> {
379
393
  for (let callback of this.beforeSaveEntityCallbacks) {
380
394
  if (callback) {
381
- callback(entity);
395
+ callback(this, entity);
382
396
  }
383
397
  }
384
398
  const result = this.driver.saveEntity(entity);
385
399
  for (let callback of this.afterSaveEntityCallbacks) {
386
400
  if (callback) {
387
- callback(result);
401
+ callback(this, result);
388
402
  }
389
403
  }
390
404
  return await result;
@@ -473,10 +487,10 @@ export class Nymph {
473
487
  * entities that were created in the last day:
474
488
  *
475
489
  * ```
476
- * [
477
- * '&',
478
- * 'gte' => ['cdate', null, '-1 day']
479
- * ]
490
+ * {
491
+ * type: '&',
492
+ * gte: ['cdate', null, '-1 day']
493
+ * }
480
494
  * ```
481
495
  *
482
496
  * Locutus' implementation: https://locutus.io/php/datetime/strtotime/
@@ -563,7 +577,7 @@ export class Nymph {
563
577
  ): Promise<ReturnType<T['factorySync']>[] | string[]> {
564
578
  for (let callback of this.beforeGetEntitiesCallbacks) {
565
579
  if (callback) {
566
- callback(options, selectors);
580
+ callback(this, options, selectors);
567
581
  }
568
582
  }
569
583
  return await this.driver.getEntities(options, ...selectors);
@@ -609,7 +623,7 @@ export class Nymph {
609
623
  options.limit = 1;
610
624
  for (let callback of this.beforeGetEntityCallbacks) {
611
625
  if (callback) {
612
- callback(options, selectors as Selector[]);
626
+ callback(this, options, selectors as Selector[]);
613
627
  }
614
628
  }
615
629
  const entities = await this.driver.getEntities(
@@ -631,13 +645,13 @@ export class Nymph {
631
645
  public async deleteEntity(entity: EntityInterface): Promise<boolean> {
632
646
  for (let callback of this.beforeDeleteEntityCallbacks) {
633
647
  if (callback) {
634
- callback(entity);
648
+ callback(this, entity);
635
649
  }
636
650
  }
637
651
  const result = this.driver.deleteEntity(entity);
638
652
  for (let callback of this.afterDeleteEntityCallbacks) {
639
653
  if (callback) {
640
- callback(result);
654
+ callback(this, result);
641
655
  }
642
656
  }
643
657
  return await result;
@@ -656,13 +670,13 @@ export class Nymph {
656
670
  ): Promise<boolean> {
657
671
  for (let callback of this.beforeDeleteEntityByIDCallbacks) {
658
672
  if (callback) {
659
- callback(guid, className);
673
+ callback(this, guid, className);
660
674
  }
661
675
  }
662
676
  const result = this.driver.deleteEntityByID(guid, className);
663
677
  for (let callback of this.afterDeleteEntityByIDCallbacks) {
664
678
  if (callback) {
665
- callback(result);
679
+ callback(this, result);
666
680
  }
667
681
  }
668
682
  return await result;
@@ -909,5 +923,3 @@ export class Nymph {
909
923
  return true;
910
924
  }
911
925
  }
912
-
913
- export default new Nymph();
@@ -1,5 +1,5 @@
1
1
  import { EntityConstructor, EntityInterface } from './Entity.types';
2
- import { Nymph } from './Nymph';
2
+ import Nymph from './Nymph';
3
3
 
4
4
  export type NymphEventType =
5
5
  | 'connect'
@@ -21,43 +21,83 @@ export type NymphEventType =
21
21
  | 'afterRenameUID'
22
22
  | 'beforeDeleteUID'
23
23
  | 'afterDeleteUID';
24
- export type NymphConnectCallback = (result: Promise<boolean>) => void;
25
- export type NymphDisconnectCallback = (result: Promise<boolean>) => void;
24
+ export type NymphConnectCallback = (
25
+ nymph: Nymph,
26
+ result: Promise<boolean>
27
+ ) => void;
28
+ export type NymphDisconnectCallback = (
29
+ nymph: Nymph,
30
+ result: Promise<boolean>
31
+ ) => void;
26
32
  /** The NymphQueryCallback will be called on both top level and qref queries. */
27
33
  export type NymphQueryCallback = (
34
+ nymph: Nymph,
28
35
  options: Options,
29
36
  selectors: FormattedSelector[]
30
37
  ) => void;
31
38
  export type NymphBeforeGetEntityCallback = (
39
+ nymph: Nymph,
32
40
  options: Options,
33
41
  selectors: Selector[]
34
42
  ) => void;
35
43
  export type NymphBeforeGetEntitiesCallback = (
44
+ nymph: Nymph,
36
45
  options: Options,
37
46
  selectors: Selector[]
38
47
  ) => void;
39
- export type NymphBeforeSaveEntityCallback = (entity: EntityInterface) => void;
40
- export type NymphAfterSaveEntityCallback = (result: Promise<boolean>) => void;
41
- export type NymphBeforeDeleteEntityCallback = (entity: EntityInterface) => void;
42
- export type NymphAfterDeleteEntityCallback = (result: Promise<boolean>) => void;
48
+ export type NymphBeforeSaveEntityCallback = (
49
+ nymph: Nymph,
50
+ entity: EntityInterface
51
+ ) => void;
52
+ export type NymphAfterSaveEntityCallback = (
53
+ nymph: Nymph,
54
+ result: Promise<boolean>
55
+ ) => void;
56
+ export type NymphBeforeDeleteEntityCallback = (
57
+ nymph: Nymph,
58
+ entity: EntityInterface
59
+ ) => void;
60
+ export type NymphAfterDeleteEntityCallback = (
61
+ nymph: Nymph,
62
+ result: Promise<boolean>
63
+ ) => void;
43
64
  export type NymphBeforeDeleteEntityByIDCallback = (
65
+ nymph: Nymph,
44
66
  guid: string,
45
67
  className?: string
46
68
  ) => void;
47
69
  export type NymphAfterDeleteEntityByIDCallback = (
70
+ nymph: Nymph,
71
+ result: Promise<boolean>
72
+ ) => void;
73
+ export type NymphBeforeNewUIDCallback = (nymph: Nymph, name: string) => void;
74
+ export type NymphAfterNewUIDCallback = (
75
+ nymph: Nymph,
76
+ result: Promise<number | null>
77
+ ) => void;
78
+ export type NymphBeforeSetUIDCallback = (
79
+ nymph: Nymph,
80
+ name: string,
81
+ value: number
82
+ ) => void;
83
+ export type NymphAfterSetUIDCallback = (
84
+ nymph: Nymph,
48
85
  result: Promise<boolean>
49
86
  ) => void;
50
- export type NymphBeforeNewUIDCallback = (name: string) => void;
51
- export type NymphAfterNewUIDCallback = (result: Promise<number | null>) => void;
52
- export type NymphBeforeSetUIDCallback = (name: string, value: number) => void;
53
- export type NymphAfterSetUIDCallback = (result: Promise<boolean>) => void;
54
87
  export type NymphBeforeRenameUIDCallback = (
88
+ nymph: Nymph,
55
89
  oldName: string,
56
90
  newName: string
57
91
  ) => void;
58
- export type NymphAfterRenameUIDCallback = (result: Promise<boolean>) => void;
59
- export type NymphBeforeDeleteUIDCallback = (name: string) => void;
60
- export type NymphAfterDeleteUIDCallback = (result: Promise<boolean>) => void;
92
+ export type NymphAfterRenameUIDCallback = (
93
+ nymph: Nymph,
94
+ result: Promise<boolean>
95
+ ) => void;
96
+ export type NymphBeforeDeleteUIDCallback = (nymph: Nymph, name: string) => void;
97
+ export type NymphAfterDeleteUIDCallback = (
98
+ nymph: Nymph,
99
+ result: Promise<boolean>
100
+ ) => void;
61
101
 
62
102
  export type Options<T extends EntityConstructor = EntityConstructor> = {
63
103
  class?: T;
@@ -186,17 +226,17 @@ export type Selector = {
186
226
  export type FormattedSelector = {
187
227
  type: '&' | '|' | '!&' | '!|';
188
228
 
189
- guid?: PrimitiveSelector['guid'][];
190
- '!guid'?: PrimitiveSelector['guid'][];
229
+ guid?: PrimitiveSelector['guid'][][];
230
+ '!guid'?: PrimitiveSelector['guid'][][];
191
231
 
192
- tag?: PrimitiveSelector['tag'][];
193
- '!tag'?: PrimitiveSelector['tag'][];
232
+ tag?: PrimitiveSelector['tag'][][];
233
+ '!tag'?: PrimitiveSelector['tag'][][];
194
234
 
195
- defined?: PrimitiveSelector['defined'][];
196
- '!defined'?: PrimitiveSelector['defined'][];
235
+ defined?: PrimitiveSelector['defined'][][];
236
+ '!defined'?: PrimitiveSelector['defined'][][];
197
237
 
198
- truthy?: PrimitiveSelector['truthy'][];
199
- '!truthy'?: PrimitiveSelector['truthy'][];
238
+ truthy?: PrimitiveSelector['truthy'][][];
239
+ '!truthy'?: PrimitiveSelector['truthy'][][];
200
240
 
201
241
  equal?: PrimitiveSelector['equal'][];
202
242
  '!equal'?: PrimitiveSelector['equal'][];
@@ -238,14 +278,24 @@ export type FormattedSelector = {
238
278
  '!selector'?: FormattedSelector['selector'];
239
279
  };
240
280
 
281
+ export enum TilmeldAccessLevels {
282
+ NO_ACCESS = 0,
283
+ READ_ACCESS = 1,
284
+ WRITE_ACCESS = 2,
285
+ // Keeping 3 open in case we ever need one between write and full.
286
+ FULL_ACCESS = 4,
287
+ }
288
+
241
289
  export interface TilmeldInterface {
242
290
  nymph: Nymph;
243
291
  request: any;
244
292
  response: any;
245
293
  init(nymph: Nymph): void;
294
+ clone(): TilmeldInterface;
246
295
  gatekeeper(ability?: string): boolean;
247
296
  authenticate(): void;
248
297
  clearSession(): void;
249
- extractToken(token: string): any;
298
+ extractToken(token: string): Promise<any>;
250
299
  fillSession(user: any): void;
300
+ checkClientUIDPermissions(name: string, type?: TilmeldAccessLevels): boolean;
251
301
  }
@@ -3,7 +3,7 @@ import { difference } from 'lodash';
3
3
  import ReadLines from 'n-readlines';
4
4
  import strtotime from 'locutus/php/datetime/strtotime';
5
5
 
6
- import type { Nymph } from '../Nymph';
6
+ import type Nymph from '../Nymph';
7
7
  import newGUID from '../newGUID';
8
8
  import {
9
9
  EntityConstructor,
@@ -1,7 +1,4 @@
1
1
  import NymphDriver from './NymphDriver';
2
2
  export { NymphDriver };
3
3
 
4
- import PreInitializedDriver from './PreInitializedDriver';
5
- export { PreInitializedDriver };
6
-
7
4
  export * from './testArtifacts';
@@ -1,11 +1,17 @@
1
1
  import fs from 'fs';
2
2
  import strtotime from 'locutus/php/datetime/strtotime';
3
3
 
4
+ import type Nymph from '../Nymph';
4
5
  import newGUID from '../newGUID';
5
- import nymph from '../Nymph';
6
6
  import { TestBModel, TestModel, TestModelData } from '../testArtifacts';
7
7
 
8
- export function QueriesTest(it: (name: string, fn: () => void) => void) {
8
+ export function QueriesTest(
9
+ nymph: Nymph,
10
+ it: (name: string, fn: () => void) => void
11
+ ) {
12
+ nymph.addEntityClass(TestModel);
13
+ nymph.addEntityClass(TestBModel);
14
+
9
15
  let testEntity: TestModel & TestModelData;
10
16
  let testGuid: string;
11
17
  let refGuid: string;
@@ -1669,7 +1675,13 @@ This one's zip code is 92064.`;
1669
1675
  });
1670
1676
  }
1671
1677
 
1672
- export function UIDTest(it: (name: string, fn: () => void) => void) {
1678
+ export function UIDTest(
1679
+ nymph: Nymph,
1680
+ it: (name: string, fn: () => void) => void
1681
+ ) {
1682
+ nymph.addEntityClass(TestModel);
1683
+ nymph.addEntityClass(TestBModel);
1684
+
1673
1685
  it('delete old test data', async () => {
1674
1686
  expect(await nymph.deleteUID('TestUID')).toEqual(true);
1675
1687
  expect(await nymph.deleteUID('NewUID')).toEqual(true);
@@ -1707,7 +1719,13 @@ export function UIDTest(it: (name: string, fn: () => void) => void) {
1707
1719
  });
1708
1720
  }
1709
1721
 
1710
- export function ExportImportTest(it: (name: string, fn: () => void) => void) {
1722
+ export function ExportImportTest(
1723
+ nymph: Nymph,
1724
+ it: (name: string, fn: () => void) => void
1725
+ ) {
1726
+ nymph.addEntityClass(TestModel);
1727
+ nymph.addEntityClass(TestBModel);
1728
+
1711
1729
  async function deleteTestData() {
1712
1730
  let all = await nymph.getEntities({ class: TestModel });
1713
1731
  expect(Array.isArray(all)).toEqual(true);
package/src/index.ts CHANGED
@@ -14,7 +14,10 @@ export { newGUID };
14
14
  export * from './Nymph.types';
15
15
 
16
16
  export * from './Nymph';
17
- import nymph from './Nymph';
18
- export default nymph;
17
+ import Nymph from './Nymph';
18
+ export { Nymph };
19
+
20
+ import nymphJoiProps from './nymphJoiProps';
21
+ export { nymphJoiProps };
19
22
 
20
23
  export * from './utils';
@@ -0,0 +1,24 @@
1
+ import Joi from 'joi';
2
+
3
+ export default {
4
+ guid: Joi.alternatives()
5
+ .try(
6
+ Joi.any().only().allow(null),
7
+ Joi.string().trim(false).length(24).hex()
8
+ )
9
+ .required(),
10
+ cdate: Joi.alternatives()
11
+ .try(Joi.any().only().allow(null), Joi.number())
12
+ .required(),
13
+ mdate: Joi.alternatives()
14
+ .try(Joi.any().only().allow(null), Joi.number())
15
+ .required(),
16
+ tags: Joi.array()
17
+ .items(
18
+ Joi.string().pattern(/[[\x01-\x1F\x7F]]/, {
19
+ name: 'control characters',
20
+ invert: true,
21
+ })
22
+ )
23
+ .required(),
24
+ };
@@ -1,5 +1,4 @@
1
1
  import Entity from './Entity';
2
- import nymph from './Nymph';
3
2
 
4
3
  export type TestModelData = {
5
4
  name?: string;
@@ -72,8 +71,6 @@ export class TestModel extends Entity<TestModelData> {
72
71
  }
73
72
  }
74
73
 
75
- nymph.setEntityClass(TestModel.class, TestModel);
76
-
77
74
  /**
78
75
  * This class is a test class that extends the Entity class.
79
76
  */
@@ -89,5 +86,3 @@ export class TestBModel extends TestModel {
89
86
  return super.factorySync(guid) as TestBModel & TestModelData;
90
87
  }
91
88
  }
92
-
93
- nymph.setEntityClass(TestBModel.class, TestBModel);