@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.
- package/CHANGELOG.md +66 -0
- package/README.md +17 -7
- package/dist/Entity.d.ts +3 -0
- package/dist/Entity.js +15 -17
- package/dist/Entity.js.map +1 -1
- package/dist/Entity.test.js +6 -3
- package/dist/Entity.test.js.map +1 -1
- package/dist/Entity.types.d.ts +4 -1
- package/dist/Nymph.d.ts +56 -53
- package/dist/Nymph.js +138 -67
- package/dist/Nymph.js.map +1 -1
- package/dist/Nymph.types.d.ts +49 -28
- package/dist/Nymph.types.js +8 -0
- package/dist/Nymph.types.js.map +1 -1
- package/dist/driver/NymphDriver.d.ts +5 -2
- package/dist/driver/NymphDriver.js +68 -39
- package/dist/driver/NymphDriver.js.map +1 -1
- package/dist/driver/testArtifacts.d.ts +4 -3
- package/dist/driver/testArtifacts.js +265 -167
- package/dist/driver/testArtifacts.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/nymphJoiProps.d.ts +8 -0
- package/dist/nymphJoiProps.js +24 -0
- package/dist/nymphJoiProps.js.map +1 -0
- package/dist/testArtifacts.js +0 -3
- package/dist/testArtifacts.js.map +1 -1
- package/dist/testMocks.d.ts +14 -13
- package/dist/testMocks.js +21 -11
- package/dist/testMocks.js.map +1 -1
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +9 -10
- package/dist/utils.js.map +1 -1
- package/package.json +3 -2
- package/src/Entity.test.ts +7 -4
- package/src/Entity.ts +22 -12
- package/src/Entity.types.ts +10 -1
- package/src/Nymph.ts +203 -119
- package/src/Nymph.types.ts +91 -22
- package/src/driver/NymphDriver.ts +93 -46
- package/src/driver/testArtifacts.ts +307 -161
- package/src/index.ts +3 -1
- package/src/nymphJoiProps.ts +24 -0
- package/src/testArtifacts.ts +0 -5
- package/src/testMocks.ts +34 -29
- package/src/utils.ts +12 -10
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 from './Nymph';
|
|
15
15
|
import {
|
|
16
16
|
entitiesToReferences,
|
|
17
17
|
referencesToEntities,
|
|
@@ -91,6 +91,10 @@ import {
|
|
|
91
91
|
export default class Entity<T extends EntityData = EntityData>
|
|
92
92
|
implements EntityInterface
|
|
93
93
|
{
|
|
94
|
+
/**
|
|
95
|
+
* The instance of Nymph to use for queries.
|
|
96
|
+
*/
|
|
97
|
+
public static nymph = {} as Nymph;
|
|
94
98
|
/**
|
|
95
99
|
* A unique name for this type of entity used to separate its data from other
|
|
96
100
|
* types of entities in the database.
|
|
@@ -104,6 +108,7 @@ export default class Entity<T extends EntityData = EntityData>
|
|
|
104
108
|
*/
|
|
105
109
|
public static class = 'Entity';
|
|
106
110
|
|
|
111
|
+
public $nymph: Nymph;
|
|
107
112
|
public guid: string | null = null;
|
|
108
113
|
public cdate: number | null = null;
|
|
109
114
|
public mdate: number | null = null;
|
|
@@ -198,6 +203,7 @@ export default class Entity<T extends EntityData = EntityData>
|
|
|
198
203
|
* @param guid The ID of the entity to load, undefined for a new entity.
|
|
199
204
|
*/
|
|
200
205
|
public constructor(guid?: string) {
|
|
206
|
+
this.$nymph = (this.constructor as EntityConstructor).nymph;
|
|
201
207
|
this.$dataHandler = {
|
|
202
208
|
has: (data: EntityData, name: string) => {
|
|
203
209
|
this.$referenceWake();
|
|
@@ -211,6 +217,7 @@ export default class Entity<T extends EntityData = EntityData>
|
|
|
211
217
|
if (this.$sdata.hasOwnProperty(name)) {
|
|
212
218
|
data[name] = referencesToEntities(
|
|
213
219
|
JSON.parse(this.$sdata[name]),
|
|
220
|
+
this.$nymph,
|
|
214
221
|
this.$skipAc
|
|
215
222
|
);
|
|
216
223
|
delete this.$sdata[name];
|
|
@@ -249,7 +256,7 @@ export default class Entity<T extends EntityData = EntityData>
|
|
|
249
256
|
this.$data = new Proxy(this.$dataStore, this.$dataHandler);
|
|
250
257
|
|
|
251
258
|
if (guid != null) {
|
|
252
|
-
const entity =
|
|
259
|
+
const entity = this.$nymph.driver.getEntitySync(
|
|
253
260
|
{ class: this.constructor as EntityConstructor },
|
|
254
261
|
{ type: '&', guid }
|
|
255
262
|
);
|
|
@@ -331,7 +338,7 @@ export default class Entity<T extends EntityData = EntityData>
|
|
|
331
338
|
public static async factory(guid?: string) {
|
|
332
339
|
const entity = new this();
|
|
333
340
|
if (guid != null) {
|
|
334
|
-
const entity = await
|
|
341
|
+
const entity = await this.nymph.getEntity(
|
|
335
342
|
{
|
|
336
343
|
class: this as any as EntityConstructor,
|
|
337
344
|
},
|
|
@@ -412,7 +419,7 @@ export default class Entity<T extends EntityData = EntityData>
|
|
|
412
419
|
public async $delete(): Promise<boolean> {
|
|
413
420
|
this.$referenceWake();
|
|
414
421
|
|
|
415
|
-
return await
|
|
422
|
+
return await this.$nymph.deleteEntity(this);
|
|
416
423
|
}
|
|
417
424
|
|
|
418
425
|
public $equals(object: any) {
|
|
@@ -487,7 +494,7 @@ export default class Entity<T extends EntityData = EntityData>
|
|
|
487
494
|
cdate: this.cdate,
|
|
488
495
|
mdate: this.mdate,
|
|
489
496
|
tags: this.tags,
|
|
490
|
-
...referencesToEntities(this.$dataStore, this.$skipAc),
|
|
497
|
+
...referencesToEntities(this.$dataStore, this.$nymph, this.$skipAc),
|
|
491
498
|
};
|
|
492
499
|
}
|
|
493
500
|
|
|
@@ -578,7 +585,10 @@ export default class Entity<T extends EntityData = EntityData>
|
|
|
578
585
|
|
|
579
586
|
const protectedData: EntityData = {};
|
|
580
587
|
const protectedProps = [...this.$protectedData];
|
|
581
|
-
if (
|
|
588
|
+
if (
|
|
589
|
+
this.$nymph.tilmeld &&
|
|
590
|
+
!this.$nymph.tilmeld.gatekeeper('tilmeld/admin')
|
|
591
|
+
) {
|
|
582
592
|
protectedProps.push('user');
|
|
583
593
|
protectedProps.push('group');
|
|
584
594
|
}
|
|
@@ -640,6 +650,7 @@ export default class Entity<T extends EntityData = EntityData>
|
|
|
640
650
|
}
|
|
641
651
|
(this.$data as any)[name] = referencesToEntities(
|
|
642
652
|
patch.set[name],
|
|
653
|
+
this.$nymph,
|
|
643
654
|
this.$skipAc
|
|
644
655
|
);
|
|
645
656
|
}
|
|
@@ -692,6 +703,7 @@ export default class Entity<T extends EntityData = EntityData>
|
|
|
692
703
|
for (const name in data) {
|
|
693
704
|
(this.$dataStore as any)[name] = referencesToEntities(
|
|
694
705
|
data[name],
|
|
706
|
+
this.$nymph,
|
|
695
707
|
this.$skipAc
|
|
696
708
|
);
|
|
697
709
|
}
|
|
@@ -739,8 +751,8 @@ export default class Entity<T extends EntityData = EntityData>
|
|
|
739
751
|
if (!this.$isASleepingReference || this.$sleepingReference == null) {
|
|
740
752
|
return true;
|
|
741
753
|
}
|
|
742
|
-
const EntityClass =
|
|
743
|
-
const entity =
|
|
754
|
+
const EntityClass = this.$nymph.getEntityClass(this.$sleepingReference[2]);
|
|
755
|
+
const entity = this.$nymph.driver.getEntitySync(
|
|
744
756
|
{
|
|
745
757
|
class: EntityClass,
|
|
746
758
|
skipAc: this.$skipAc,
|
|
@@ -766,7 +778,7 @@ export default class Entity<T extends EntityData = EntityData>
|
|
|
766
778
|
if (this.guid == null) {
|
|
767
779
|
return false;
|
|
768
780
|
}
|
|
769
|
-
const refresh = await
|
|
781
|
+
const refresh = await this.$nymph.getEntity(
|
|
770
782
|
{
|
|
771
783
|
class: this.constructor as EntityConstructor,
|
|
772
784
|
skipCache: true,
|
|
@@ -793,7 +805,7 @@ export default class Entity<T extends EntityData = EntityData>
|
|
|
793
805
|
public async $save(): Promise<boolean> {
|
|
794
806
|
this.$referenceWake();
|
|
795
807
|
|
|
796
|
-
return await
|
|
808
|
+
return await this.$nymph.saveEntity(this);
|
|
797
809
|
}
|
|
798
810
|
|
|
799
811
|
public $toReference() {
|
|
@@ -814,5 +826,3 @@ export default class Entity<T extends EntityData = EntityData>
|
|
|
814
826
|
this.$skipAc = !!skipAc;
|
|
815
827
|
}
|
|
816
828
|
}
|
|
817
|
-
|
|
818
|
-
Nymph.setEntityClass(Entity.class, Entity);
|
package/src/Entity.types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type Nymph from './Nymph';
|
|
2
|
+
import type { Options } from './Nymph.types';
|
|
2
3
|
|
|
3
4
|
export type ACProperties = {
|
|
4
5
|
user: any;
|
|
@@ -113,6 +114,10 @@ export interface DataObjectInterface {
|
|
|
113
114
|
* Entity interface.
|
|
114
115
|
*/
|
|
115
116
|
export interface EntityInterface extends DataObjectInterface {
|
|
117
|
+
/**
|
|
118
|
+
* The instance of Nymph to use for queries.
|
|
119
|
+
*/
|
|
120
|
+
$nymph: Nymph;
|
|
116
121
|
/**
|
|
117
122
|
* The entity's Globally Unique ID.
|
|
118
123
|
*
|
|
@@ -267,6 +272,10 @@ export interface EntityInterface extends DataObjectInterface {
|
|
|
267
272
|
}
|
|
268
273
|
|
|
269
274
|
export type EntityConstructor = (new (guid?: string) => EntityInterface) & {
|
|
275
|
+
/**
|
|
276
|
+
* The instance of Nymph to use for queries.
|
|
277
|
+
*/
|
|
278
|
+
nymph: Nymph;
|
|
270
279
|
/**
|
|
271
280
|
* A unique name for this type of entity used to separate its data from other
|
|
272
281
|
* types of entities in the database.
|