@nymphjs/nymph 1.0.0-beta.131 → 1.0.0-beta.133
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 +16 -0
- package/README.md +16 -9
- package/dist/Entity.d.ts +6 -6
- package/dist/Entity.js +2 -6
- package/dist/Entity.js.map +1 -1
- package/dist/Entity.types.d.ts +5 -10
- package/dist/Nymph.d.ts +0 -2
- package/dist/Nymph.js.map +1 -1
- package/dist/Nymph.types.d.ts +1 -4
- package/dist/Nymph.types.js.map +1 -1
- package/dist/conf/defaults.js +0 -3
- package/dist/conf/defaults.js.map +1 -1
- package/dist/conf/index.d.ts +0 -14
- package/dist/conf/index.js.map +1 -1
- package/dist/driver/NymphDriver.d.ts +1 -50
- package/dist/driver/NymphDriver.js +2 -177
- package/dist/driver/NymphDriver.js.map +1 -1
- package/dist/testArtifacts.d.ts +6 -2
- package/dist/testArtifacts.js +13 -13
- package/dist/testArtifacts.js.map +1 -1
- package/package.json +3 -3
- package/src/Entity.ts +47 -49
- package/src/Entity.types.ts +6 -10
- package/src/Nymph.ts +0 -2
- package/src/Nymph.types.ts +4 -4
- package/src/conf/defaults.ts +0 -3
- package/src/conf/index.ts +0 -14
- package/src/driver/NymphDriver.ts +7 -237
- package/src/testArtifacts.ts +19 -15
package/src/Entity.ts
CHANGED
|
@@ -107,9 +107,7 @@ export type EntityObjectType<T extends EntityConstructor> =
|
|
|
107
107
|
* will fill its data from the DB. You can call clearCache() to turn all the
|
|
108
108
|
* entities back into sleeping references.
|
|
109
109
|
*/
|
|
110
|
-
export default class Entity<
|
|
111
|
-
T extends EntityData = EntityData,
|
|
112
|
-
> implements EntityInterface {
|
|
110
|
+
export default class Entity<T extends {} = {}> implements EntityInterface {
|
|
113
111
|
/**
|
|
114
112
|
* The instance of Nymph to use for queries.
|
|
115
113
|
*/
|
|
@@ -364,7 +362,7 @@ export default class Entity<
|
|
|
364
362
|
protected $proxy() {
|
|
365
363
|
if (this.$existingProxy == null) {
|
|
366
364
|
this.$existingProxy = new Proxy(this, {
|
|
367
|
-
has: (entity:
|
|
365
|
+
has: (entity: Record<string, any>, name: string) => {
|
|
368
366
|
if (
|
|
369
367
|
typeof name !== 'string' ||
|
|
370
368
|
name in entity ||
|
|
@@ -377,7 +375,7 @@ export default class Entity<
|
|
|
377
375
|
return name in entity.$data;
|
|
378
376
|
},
|
|
379
377
|
|
|
380
|
-
get: (entity:
|
|
378
|
+
get: (entity: Record<string, any>, name: string) => {
|
|
381
379
|
if (
|
|
382
380
|
typeof name !== 'string' ||
|
|
383
381
|
name in entity ||
|
|
@@ -396,7 +394,7 @@ export default class Entity<
|
|
|
396
394
|
return undefined;
|
|
397
395
|
},
|
|
398
396
|
|
|
399
|
-
set: (entity:
|
|
397
|
+
set: (entity: Record<string, any>, name: string, value: any) => {
|
|
400
398
|
if (
|
|
401
399
|
typeof name !== 'string' ||
|
|
402
400
|
name in entity ||
|
|
@@ -413,7 +411,7 @@ export default class Entity<
|
|
|
413
411
|
return true;
|
|
414
412
|
},
|
|
415
413
|
|
|
416
|
-
deleteProperty: (entity:
|
|
414
|
+
deleteProperty: (entity: Record<string, any>, name: string) => {
|
|
417
415
|
if (name in entity) {
|
|
418
416
|
return delete (entity as any)[name];
|
|
419
417
|
} else if (name in entity.$data) {
|
|
@@ -423,12 +421,12 @@ export default class Entity<
|
|
|
423
421
|
return true;
|
|
424
422
|
},
|
|
425
423
|
|
|
426
|
-
getPrototypeOf: (entity:
|
|
424
|
+
getPrototypeOf: (entity: Record<string, any>) => {
|
|
427
425
|
return entity.constructor.prototype;
|
|
428
426
|
},
|
|
429
427
|
|
|
430
428
|
defineProperty: (
|
|
431
|
-
entity:
|
|
429
|
+
entity: Record<string, any>,
|
|
432
430
|
name: string,
|
|
433
431
|
descriptor: PropertyDescriptor,
|
|
434
432
|
) => {
|
|
@@ -448,7 +446,10 @@ export default class Entity<
|
|
|
448
446
|
return true;
|
|
449
447
|
},
|
|
450
448
|
|
|
451
|
-
getOwnPropertyDescriptor: (
|
|
449
|
+
getOwnPropertyDescriptor: (
|
|
450
|
+
entity: Record<string, any>,
|
|
451
|
+
name: string,
|
|
452
|
+
) => {
|
|
452
453
|
if (
|
|
453
454
|
typeof name !== 'string' ||
|
|
454
455
|
name in entity ||
|
|
@@ -464,7 +465,7 @@ export default class Entity<
|
|
|
464
465
|
}
|
|
465
466
|
},
|
|
466
467
|
|
|
467
|
-
ownKeys: (entity:
|
|
468
|
+
ownKeys: (entity: Record<string, any>) => {
|
|
468
469
|
this.$check();
|
|
469
470
|
return Object.getOwnPropertyNames(entity).concat(
|
|
470
471
|
Object.getOwnPropertyNames(entity.$data),
|
|
@@ -487,7 +488,7 @@ export default class Entity<
|
|
|
487
488
|
new (): E;
|
|
488
489
|
},
|
|
489
490
|
guid?: string,
|
|
490
|
-
): Promise<E
|
|
491
|
+
): Promise<E> {
|
|
491
492
|
const entity = new this();
|
|
492
493
|
if (guid != null) {
|
|
493
494
|
const entity = await (
|
|
@@ -499,19 +500,17 @@ export default class Entity<
|
|
|
499
500
|
{ type: '&', guid },
|
|
500
501
|
);
|
|
501
502
|
if (entity != null) {
|
|
502
|
-
return entity as E
|
|
503
|
+
return entity as E;
|
|
503
504
|
}
|
|
504
505
|
}
|
|
505
|
-
return entity as E
|
|
506
|
+
return entity as E;
|
|
506
507
|
}
|
|
507
508
|
|
|
508
509
|
/**
|
|
509
510
|
* Create a new entity instance.
|
|
510
511
|
*/
|
|
511
|
-
public static factorySync<E extends Entity>(this: {
|
|
512
|
-
new ()
|
|
513
|
-
}): E & EntityDataType<E> {
|
|
514
|
-
return new this() as E & EntityDataType<E>;
|
|
512
|
+
public static factorySync<E extends Entity>(this: { new (): E }): E {
|
|
513
|
+
return new this() as E;
|
|
515
514
|
}
|
|
516
515
|
|
|
517
516
|
/**
|
|
@@ -528,10 +527,10 @@ export default class Entity<
|
|
|
528
527
|
new (): E;
|
|
529
528
|
},
|
|
530
529
|
reference: EntityReference,
|
|
531
|
-
): E
|
|
530
|
+
): E {
|
|
532
531
|
const entity = new this();
|
|
533
532
|
entity.$referenceSleep(reference);
|
|
534
|
-
return entity as E
|
|
533
|
+
return entity as E;
|
|
535
534
|
}
|
|
536
535
|
|
|
537
536
|
/**
|
|
@@ -601,7 +600,7 @@ export default class Entity<
|
|
|
601
600
|
}
|
|
602
601
|
|
|
603
602
|
public toJSON() {
|
|
604
|
-
if (this.$isASleepingReference) {
|
|
603
|
+
if (this.$isASleepingReference && this.$sleepingReference) {
|
|
605
604
|
return this.$sleepingReference;
|
|
606
605
|
}
|
|
607
606
|
const obj: EntityJson = {
|
|
@@ -618,7 +617,7 @@ export default class Entity<
|
|
|
618
617
|
]) {
|
|
619
618
|
if (this.$privateData.indexOf(key) === -1) {
|
|
620
619
|
obj.data[key] = entityConstructorsToClassNames(
|
|
621
|
-
entitiesToReferences(this.$data[key], true),
|
|
620
|
+
entitiesToReferences((this.$data as EntityData)[key], true),
|
|
622
621
|
);
|
|
623
622
|
}
|
|
624
623
|
}
|
|
@@ -769,9 +768,9 @@ export default class Entity<
|
|
|
769
768
|
return {
|
|
770
769
|
user: this.$getAcUid(),
|
|
771
770
|
group: this.$getAcGid(),
|
|
772
|
-
acUser: this.$data.acUser ?? null,
|
|
773
|
-
acGroup: this.$data.acGroup ?? null,
|
|
774
|
-
acOther: this.$data.acOther ?? null,
|
|
771
|
+
acUser: (this.$data as EntityData).acUser ?? null,
|
|
772
|
+
acGroup: (this.$data as EntityData).acGroup ?? null,
|
|
773
|
+
acOther: (this.$data as EntityData).acOther ?? null,
|
|
775
774
|
acRead: this.$getAcReadIds(),
|
|
776
775
|
acWrite: this.$getAcWriteIds(),
|
|
777
776
|
acFull: this.$getAcFullIds(),
|
|
@@ -788,7 +787,7 @@ export default class Entity<
|
|
|
788
787
|
return userValue[1];
|
|
789
788
|
}
|
|
790
789
|
}
|
|
791
|
-
return (this.$data.user?.guid ?? null) as string | null;
|
|
790
|
+
return ((this.$data as EntityData).user?.guid ?? null) as string | null;
|
|
792
791
|
}
|
|
793
792
|
public $getAcGid() {
|
|
794
793
|
if ('group' in this.$sdata) {
|
|
@@ -800,21 +799,24 @@ export default class Entity<
|
|
|
800
799
|
return groupValue[1];
|
|
801
800
|
}
|
|
802
801
|
}
|
|
803
|
-
return (this.$data.group?.guid ?? null) as string | null;
|
|
802
|
+
return ((this.$data as EntityData).group?.guid ?? null) as string | null;
|
|
804
803
|
}
|
|
805
804
|
public $getAcReadIds() {
|
|
806
|
-
return (this.$data.acRead?.map(
|
|
807
|
-
|
|
805
|
+
return ((this.$data as EntityData).acRead?.map(
|
|
806
|
+
(entity: EntityInterface | string) =>
|
|
807
|
+
typeof entity === 'string' ? entity : entity.guid,
|
|
808
808
|
) ?? null) as (string | null)[] | null;
|
|
809
809
|
}
|
|
810
810
|
public $getAcWriteIds() {
|
|
811
|
-
return (this.$data.acWrite?.map(
|
|
812
|
-
|
|
811
|
+
return ((this.$data as EntityData).acWrite?.map(
|
|
812
|
+
(entity: EntityInterface | string) =>
|
|
813
|
+
typeof entity === 'string' ? entity : entity.guid,
|
|
813
814
|
) ?? null) as (string | null)[] | null;
|
|
814
815
|
}
|
|
815
816
|
public $getAcFullIds() {
|
|
816
|
-
return (this.$data.acFull?.map(
|
|
817
|
-
|
|
817
|
+
return ((this.$data as EntityData).acFull?.map(
|
|
818
|
+
(entity: EntityInterface | string) =>
|
|
819
|
+
typeof entity === 'string' ? entity : entity.guid,
|
|
818
820
|
) ?? null) as (string | null)[] | null;
|
|
819
821
|
}
|
|
820
822
|
|
|
@@ -924,7 +926,7 @@ export default class Entity<
|
|
|
924
926
|
const privateData: EntityData = {};
|
|
925
927
|
for (const name of this.$privateData) {
|
|
926
928
|
if (name in this.$data) {
|
|
927
|
-
privateData[name] = this.$data[name];
|
|
929
|
+
privateData[name] = (this.$data as EntityData)[name];
|
|
928
930
|
}
|
|
929
931
|
if (name in data) {
|
|
930
932
|
delete data[name];
|
|
@@ -957,7 +959,7 @@ export default class Entity<
|
|
|
957
959
|
}
|
|
958
960
|
for (const name of protectedProps) {
|
|
959
961
|
if (name in this.$data) {
|
|
960
|
-
protectedData[name] = this.$data[name];
|
|
962
|
+
protectedData[name] = (this.$data as EntityData)[name];
|
|
961
963
|
}
|
|
962
964
|
if (name in data) {
|
|
963
965
|
delete data[name];
|
|
@@ -982,7 +984,7 @@ export default class Entity<
|
|
|
982
984
|
...data,
|
|
983
985
|
...protectedData,
|
|
984
986
|
...privateData,
|
|
985
|
-
});
|
|
987
|
+
} as T);
|
|
986
988
|
}
|
|
987
989
|
|
|
988
990
|
public $jsonAcceptPatch(patch: EntityPatch, allowConflict = false) {
|
|
@@ -1047,7 +1049,7 @@ export default class Entity<
|
|
|
1047
1049
|
) {
|
|
1048
1050
|
continue;
|
|
1049
1051
|
}
|
|
1050
|
-
delete this.$data[name];
|
|
1052
|
+
delete (this.$data as EntityData)[name];
|
|
1051
1053
|
}
|
|
1052
1054
|
|
|
1053
1055
|
for (const tag of patch.addTags) {
|
|
@@ -1073,11 +1075,7 @@ export default class Entity<
|
|
|
1073
1075
|
}
|
|
1074
1076
|
}
|
|
1075
1077
|
|
|
1076
|
-
public $putData(
|
|
1077
|
-
data: EntityData,
|
|
1078
|
-
sdata?: SerializedEntityData,
|
|
1079
|
-
_source?: 'server',
|
|
1080
|
-
) {
|
|
1078
|
+
public $putData(data: T, sdata?: SerializedEntityData, _source?: 'server') {
|
|
1081
1079
|
this.$check();
|
|
1082
1080
|
|
|
1083
1081
|
for (const name in this.$dataStore) {
|
|
@@ -1158,10 +1156,7 @@ export default class Entity<
|
|
|
1158
1156
|
);
|
|
1159
1157
|
this.$wakePromise = this.$nymph
|
|
1160
1158
|
.getEntity(
|
|
1161
|
-
{
|
|
1162
|
-
class: EntityClass,
|
|
1163
|
-
skipAc: this.$skipAc,
|
|
1164
|
-
},
|
|
1159
|
+
{ class: EntityClass, skipAc: this.$skipAc },
|
|
1165
1160
|
{ type: '&', guid: this.$sleepingReference[1] },
|
|
1166
1161
|
)
|
|
1167
1162
|
.then((entity) => {
|
|
@@ -1178,7 +1173,11 @@ export default class Entity<
|
|
|
1178
1173
|
this.tags = entity.tags;
|
|
1179
1174
|
this.cdate = entity.cdate;
|
|
1180
1175
|
this.mdate = entity.mdate;
|
|
1181
|
-
this.$putData(
|
|
1176
|
+
this.$putData(
|
|
1177
|
+
entity.$getData(false) as T,
|
|
1178
|
+
entity.$getSData(),
|
|
1179
|
+
'server',
|
|
1180
|
+
);
|
|
1182
1181
|
|
|
1183
1182
|
return this.$proxy();
|
|
1184
1183
|
})
|
|
@@ -1259,7 +1258,6 @@ export default class Entity<
|
|
|
1259
1258
|
const refresh = await this.$nymph.getEntity(
|
|
1260
1259
|
{
|
|
1261
1260
|
class: this.constructor as EntityConstructor,
|
|
1262
|
-
skipCache: true,
|
|
1263
1261
|
skipAc: this.$skipAc,
|
|
1264
1262
|
},
|
|
1265
1263
|
{ type: '&', guid: this.guid },
|
|
@@ -1270,7 +1268,7 @@ export default class Entity<
|
|
|
1270
1268
|
this.tags = refresh.tags;
|
|
1271
1269
|
this.cdate = refresh.cdate;
|
|
1272
1270
|
this.mdate = refresh.mdate;
|
|
1273
|
-
this.$putData(refresh.$getData(false), refresh.$getSData(), 'server');
|
|
1271
|
+
this.$putData(refresh.$getData(false) as T, refresh.$getSData(), 'server');
|
|
1274
1272
|
return true;
|
|
1275
1273
|
}
|
|
1276
1274
|
|
package/src/Entity.types.ts
CHANGED
|
@@ -99,7 +99,7 @@ export interface DataObjectInterface {
|
|
|
99
99
|
*/
|
|
100
100
|
$is(object: any): boolean;
|
|
101
101
|
/**
|
|
102
|
-
* Refresh the object from storage.
|
|
102
|
+
* Refresh the object from storage.
|
|
103
103
|
*
|
|
104
104
|
* @returns False if the data has not been saved, true on success. An error is
|
|
105
105
|
* thrown on failure.
|
|
@@ -111,10 +111,6 @@ export interface DataObjectInterface {
|
|
|
111
111
|
* An error is thrown on failure.
|
|
112
112
|
*/
|
|
113
113
|
$save(): Promise<void>;
|
|
114
|
-
/**
|
|
115
|
-
* The object's data.
|
|
116
|
-
*/
|
|
117
|
-
[k: string]: any;
|
|
118
114
|
}
|
|
119
115
|
|
|
120
116
|
/**
|
|
@@ -164,8 +160,7 @@ export interface EntityInterface extends DataObjectInterface {
|
|
|
164
160
|
/**
|
|
165
161
|
* Replace any referenced entities in the data with sleeping references.
|
|
166
162
|
*
|
|
167
|
-
*
|
|
168
|
-
* accessed, it will be retrieved from the DB (unless it is in Nymph's cache).
|
|
163
|
+
* After calling this function, referenced entities must be awoken again.
|
|
169
164
|
*/
|
|
170
165
|
$clearCache(): void;
|
|
171
166
|
/**
|
|
@@ -297,9 +292,8 @@ export interface EntityInterface extends DataObjectInterface {
|
|
|
297
292
|
* `sdata` is used by Nymph to avoid unserializing data that hasn't been
|
|
298
293
|
* requested yet.
|
|
299
294
|
*
|
|
300
|
-
* If `source` is set to "server", the data is coming from the DB
|
|
301
|
-
*
|
|
302
|
-
* trusted.
|
|
295
|
+
* If `source` is set to "server", the data is coming from the DB. If not,
|
|
296
|
+
* assume the data is coming from the client and can't be trusted.
|
|
303
297
|
*
|
|
304
298
|
* @param data The data object.
|
|
305
299
|
* @param sdata The serialized data object.
|
|
@@ -333,6 +327,8 @@ export interface EntityInterface extends DataObjectInterface {
|
|
|
333
327
|
* @param useSkipAc True or false, whether to use it.
|
|
334
328
|
*/
|
|
335
329
|
$useSkipAc(useSkipAc: boolean): void;
|
|
330
|
+
|
|
331
|
+
toJSON(): EntityReference | EntityJson;
|
|
336
332
|
}
|
|
337
333
|
|
|
338
334
|
export type EntityConstructor<
|
package/src/Nymph.ts
CHANGED
|
@@ -716,8 +716,6 @@ export default class Nymph {
|
|
|
716
716
|
* - return - What to return. "entity", "object", "guid", or "count". Defaults
|
|
717
717
|
* to "entity".
|
|
718
718
|
* - source - Will be 'client' if the query came from a REST call.
|
|
719
|
-
* - skipCache - If true, Nymph will skip the cache and retrieve the entity
|
|
720
|
-
* from the DB.
|
|
721
719
|
* - skipAc - If true, Tilmeld will not filter returned entities according to
|
|
722
720
|
* access controls. (If Tilmeld is installed.) (This is *always* set to
|
|
723
721
|
* false by the REST server.)
|
package/src/Nymph.types.ts
CHANGED
|
@@ -226,10 +226,6 @@ export type Options<T extends EntityConstructor = EntityConstructor> = {
|
|
|
226
226
|
* server. (Mainly used in Tilmeld for access control.)
|
|
227
227
|
*/
|
|
228
228
|
source?: string;
|
|
229
|
-
/**
|
|
230
|
-
* If true, Nymph will skip the cache and retrieve the entity from the DB.
|
|
231
|
-
*/
|
|
232
|
-
skipCache?: boolean;
|
|
233
229
|
/**
|
|
234
230
|
* The level(s) of access control requested.
|
|
235
231
|
*
|
|
@@ -488,4 +484,8 @@ export interface TilmeldInterface {
|
|
|
488
484
|
name: string,
|
|
489
485
|
type?: TilmeldAccessLevels,
|
|
490
486
|
): Promise<boolean>;
|
|
487
|
+
checkPermissions(
|
|
488
|
+
entity: EntityInterface,
|
|
489
|
+
type?: TilmeldAccessLevels,
|
|
490
|
+
): boolean;
|
|
491
491
|
}
|
package/src/conf/defaults.ts
CHANGED
package/src/conf/index.ts
CHANGED
|
@@ -2,20 +2,6 @@
|
|
|
2
2
|
* Nymph Config
|
|
3
3
|
*/
|
|
4
4
|
export interface Config {
|
|
5
|
-
/**
|
|
6
|
-
* Cache recently retrieved entities to speed up database queries. Uses more
|
|
7
|
-
* memory.
|
|
8
|
-
*/
|
|
9
|
-
cache: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Cache entities after they're accessed this many times.
|
|
12
|
-
*/
|
|
13
|
-
cacheThreshold: number;
|
|
14
|
-
/**
|
|
15
|
-
* The number of recently retrieved entities to cache. If you're running out
|
|
16
|
-
* of memory, try lowering this value. 0 means unlimited.
|
|
17
|
-
*/
|
|
18
|
-
cacheLimit: number;
|
|
19
5
|
/**
|
|
20
6
|
* When querying for multiple entities with NymphREST, if the list is empty,
|
|
21
7
|
* return a 404 error.
|