@nymphjs/nymph 1.0.0-beta.130 → 1.0.0-beta.132
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/dist/Entity.d.ts +3 -1
- package/dist/Entity.js +94 -91
- package/dist/Entity.js.map +1 -1
- package/dist/Entity.types.d.ts +4 -6
- 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/package.json +3 -3
- package/src/Entity.ts +109 -105
- package/src/Entity.types.ts +4 -6
- 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 +8 -237
package/src/Entity.ts
CHANGED
|
@@ -357,114 +357,122 @@ export default class Entity<
|
|
|
357
357
|
|
|
358
358
|
this.$data = new Proxy(this.$dataStore, this.$dataHandler);
|
|
359
359
|
|
|
360
|
-
return
|
|
361
|
-
|
|
362
|
-
if (
|
|
363
|
-
typeof name !== 'string' ||
|
|
364
|
-
name in entity ||
|
|
365
|
-
name.substring(0, 1) === '$'
|
|
366
|
-
) {
|
|
367
|
-
return name in entity;
|
|
368
|
-
}
|
|
360
|
+
return this.$proxy();
|
|
361
|
+
}
|
|
369
362
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
363
|
+
private $existingProxy?: this & T;
|
|
364
|
+
protected $proxy() {
|
|
365
|
+
if (this.$existingProxy == null) {
|
|
366
|
+
this.$existingProxy = new Proxy(this, {
|
|
367
|
+
has: (entity: this, name: string) => {
|
|
368
|
+
if (
|
|
369
|
+
typeof name !== 'string' ||
|
|
370
|
+
name in entity ||
|
|
371
|
+
name.substring(0, 1) === '$'
|
|
372
|
+
) {
|
|
373
|
+
return name in entity;
|
|
374
|
+
}
|
|
373
375
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
376
|
+
this.$check();
|
|
377
|
+
return name in entity.$data;
|
|
378
|
+
},
|
|
379
|
+
|
|
380
|
+
get: (entity: this, name: string) => {
|
|
381
|
+
if (
|
|
382
|
+
typeof name !== 'string' ||
|
|
383
|
+
name in entity ||
|
|
384
|
+
name.substring(0, 1) === '$'
|
|
385
|
+
) {
|
|
386
|
+
if (name === 'tags' || name === 'cdate' || name === 'mdate') {
|
|
387
|
+
this.$check();
|
|
388
|
+
}
|
|
389
|
+
return (entity as any)[name];
|
|
382
390
|
}
|
|
383
|
-
return (entity as any)[name];
|
|
384
|
-
}
|
|
385
391
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
+
this.$check();
|
|
393
|
+
if (name in entity.$data) {
|
|
394
|
+
return entity.$data[name];
|
|
395
|
+
}
|
|
396
|
+
return undefined;
|
|
397
|
+
},
|
|
392
398
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
399
|
+
set: (entity: this, name: string, value: any) => {
|
|
400
|
+
if (
|
|
401
|
+
typeof name !== 'string' ||
|
|
402
|
+
name in entity ||
|
|
403
|
+
name.substring(0, 1) === '$'
|
|
404
|
+
) {
|
|
405
|
+
if (name === 'tags' || name === 'cdate' || name === 'mdate') {
|
|
406
|
+
this.$check();
|
|
407
|
+
}
|
|
408
|
+
(entity as any)[name] = value;
|
|
409
|
+
} else {
|
|
400
410
|
this.$check();
|
|
411
|
+
(entity.$data as any)[name] = value;
|
|
401
412
|
}
|
|
402
|
-
|
|
403
|
-
}
|
|
404
|
-
this.$check();
|
|
405
|
-
(entity.$data as any)[name] = value;
|
|
406
|
-
}
|
|
407
|
-
return true;
|
|
408
|
-
},
|
|
413
|
+
return true;
|
|
414
|
+
},
|
|
409
415
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
416
|
+
deleteProperty: (entity: this, name: string) => {
|
|
417
|
+
if (name in entity) {
|
|
418
|
+
return delete (entity as any)[name];
|
|
419
|
+
} else if (name in entity.$data) {
|
|
420
|
+
this.$check();
|
|
421
|
+
return delete entity.$data[name];
|
|
422
|
+
}
|
|
423
|
+
return true;
|
|
424
|
+
},
|
|
419
425
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
426
|
+
getPrototypeOf: (entity: this) => {
|
|
427
|
+
return entity.constructor.prototype;
|
|
428
|
+
},
|
|
423
429
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
430
|
+
defineProperty: (
|
|
431
|
+
entity: this,
|
|
432
|
+
name: string,
|
|
433
|
+
descriptor: PropertyDescriptor,
|
|
434
|
+
) => {
|
|
435
|
+
if (
|
|
436
|
+
typeof name !== 'string' ||
|
|
437
|
+
name in entity ||
|
|
438
|
+
name.substring(0, 1) === '$'
|
|
439
|
+
) {
|
|
440
|
+
if (name === 'tags' || name === 'cdate' || name === 'mdate') {
|
|
441
|
+
this.$check();
|
|
442
|
+
}
|
|
443
|
+
Object.defineProperty(entity, name, descriptor);
|
|
444
|
+
} else {
|
|
435
445
|
this.$check();
|
|
446
|
+
Object.defineProperty(entity.$data, name, descriptor);
|
|
436
447
|
}
|
|
437
|
-
|
|
438
|
-
}
|
|
439
|
-
this.$check();
|
|
440
|
-
Object.defineProperty(entity.$data, name, descriptor);
|
|
441
|
-
}
|
|
442
|
-
return true;
|
|
443
|
-
},
|
|
448
|
+
return true;
|
|
449
|
+
},
|
|
444
450
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
451
|
+
getOwnPropertyDescriptor: (entity: this, name: string) => {
|
|
452
|
+
if (
|
|
453
|
+
typeof name !== 'string' ||
|
|
454
|
+
name in entity ||
|
|
455
|
+
name.substring(0, 1) === '$'
|
|
456
|
+
) {
|
|
457
|
+
if (name === 'tags' || name === 'cdate' || name === 'mdate') {
|
|
458
|
+
this.$check();
|
|
459
|
+
}
|
|
460
|
+
return Object.getOwnPropertyDescriptor(entity, name);
|
|
461
|
+
} else {
|
|
452
462
|
this.$check();
|
|
463
|
+
return Object.getOwnPropertyDescriptor(entity.$data, name);
|
|
453
464
|
}
|
|
454
|
-
|
|
455
|
-
} else {
|
|
456
|
-
this.$check();
|
|
457
|
-
return Object.getOwnPropertyDescriptor(entity.$data, name);
|
|
458
|
-
}
|
|
459
|
-
},
|
|
465
|
+
},
|
|
460
466
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
467
|
+
ownKeys: (entity: this) => {
|
|
468
|
+
this.$check();
|
|
469
|
+
return Object.getOwnPropertyNames(entity).concat(
|
|
470
|
+
Object.getOwnPropertyNames(entity.$data),
|
|
471
|
+
);
|
|
472
|
+
},
|
|
473
|
+
}) as this & T;
|
|
474
|
+
}
|
|
475
|
+
return this.$existingProxy;
|
|
468
476
|
}
|
|
469
477
|
|
|
470
478
|
/**
|
|
@@ -1117,7 +1125,7 @@ export default class Entity<
|
|
|
1117
1125
|
* Check if this is a sleeping reference and throw an error if so.
|
|
1118
1126
|
*/
|
|
1119
1127
|
protected $check() {
|
|
1120
|
-
if (this.$
|
|
1128
|
+
if (this.$asleep()) {
|
|
1121
1129
|
throw new EntityIsSleepingReferenceError(
|
|
1122
1130
|
'This entity is in a sleeping reference state. You must use .$wake() to wake it.',
|
|
1123
1131
|
);
|
|
@@ -1135,9 +1143,9 @@ export default class Entity<
|
|
|
1135
1143
|
* Wake from a sleeping reference.
|
|
1136
1144
|
*/
|
|
1137
1145
|
public $wake() {
|
|
1138
|
-
if (!this.$
|
|
1146
|
+
if (!this.$asleep()) {
|
|
1139
1147
|
this.$wakePromise = null;
|
|
1140
|
-
return Promise.resolve(this);
|
|
1148
|
+
return Promise.resolve(this.$proxy());
|
|
1141
1149
|
}
|
|
1142
1150
|
if (this.$sleepingReference?.[1] == null) {
|
|
1143
1151
|
throw new InvalidStateError(
|
|
@@ -1150,10 +1158,7 @@ export default class Entity<
|
|
|
1150
1158
|
);
|
|
1151
1159
|
this.$wakePromise = this.$nymph
|
|
1152
1160
|
.getEntity(
|
|
1153
|
-
{
|
|
1154
|
-
class: EntityClass,
|
|
1155
|
-
skipAc: this.$skipAc,
|
|
1156
|
-
},
|
|
1161
|
+
{ class: EntityClass, skipAc: this.$skipAc },
|
|
1157
1162
|
{ type: '&', guid: this.$sleepingReference[1] },
|
|
1158
1163
|
)
|
|
1159
1164
|
.then((entity) => {
|
|
@@ -1172,7 +1177,7 @@ export default class Entity<
|
|
|
1172
1177
|
this.mdate = entity.mdate;
|
|
1173
1178
|
this.$putData(entity.$getData(false), entity.$getSData(), 'server');
|
|
1174
1179
|
|
|
1175
|
-
return this;
|
|
1180
|
+
return this.$proxy();
|
|
1176
1181
|
})
|
|
1177
1182
|
.finally(() => {
|
|
1178
1183
|
this.$wakePromise = null;
|
|
@@ -1192,7 +1197,7 @@ export default class Entity<
|
|
|
1192
1197
|
newLevel = level - 1;
|
|
1193
1198
|
}
|
|
1194
1199
|
if (newLevel !== undefined && newLevel < 0) {
|
|
1195
|
-
resolve(this);
|
|
1200
|
+
resolve(this.$proxy());
|
|
1196
1201
|
return;
|
|
1197
1202
|
}
|
|
1198
1203
|
const promises: Promise<any>[] = [];
|
|
@@ -1226,11 +1231,11 @@ export default class Entity<
|
|
|
1226
1231
|
walkData(this.$data);
|
|
1227
1232
|
if (promises.length) {
|
|
1228
1233
|
Promise.all(promises).then(
|
|
1229
|
-
() => resolve(this),
|
|
1234
|
+
() => resolve(this.$proxy()),
|
|
1230
1235
|
(errObj) => reject(errObj),
|
|
1231
1236
|
);
|
|
1232
1237
|
} else {
|
|
1233
|
-
resolve(this);
|
|
1238
|
+
resolve(this.$proxy());
|
|
1234
1239
|
}
|
|
1235
1240
|
};
|
|
1236
1241
|
|
|
@@ -1251,7 +1256,6 @@ export default class Entity<
|
|
|
1251
1256
|
const refresh = await this.$nymph.getEntity(
|
|
1252
1257
|
{
|
|
1253
1258
|
class: this.constructor as EntityConstructor,
|
|
1254
|
-
skipCache: true,
|
|
1255
1259
|
skipAc: this.$skipAc,
|
|
1256
1260
|
},
|
|
1257
1261
|
{ type: '&', guid: this.guid },
|
|
@@ -1285,7 +1289,7 @@ export default class Entity<
|
|
|
1285
1289
|
return this.$sleepingReference;
|
|
1286
1290
|
}
|
|
1287
1291
|
if (existingOnly && this.guid == null) {
|
|
1288
|
-
return this;
|
|
1292
|
+
return this.$proxy();
|
|
1289
1293
|
}
|
|
1290
1294
|
return [
|
|
1291
1295
|
'nymph_entity_reference',
|
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.
|
|
@@ -164,8 +164,7 @@ export interface EntityInterface extends DataObjectInterface {
|
|
|
164
164
|
/**
|
|
165
165
|
* Replace any referenced entities in the data with sleeping references.
|
|
166
166
|
*
|
|
167
|
-
*
|
|
168
|
-
* accessed, it will be retrieved from the DB (unless it is in Nymph's cache).
|
|
167
|
+
* After calling this function, referenced entities must be awoken again.
|
|
169
168
|
*/
|
|
170
169
|
$clearCache(): void;
|
|
171
170
|
/**
|
|
@@ -297,9 +296,8 @@ export interface EntityInterface extends DataObjectInterface {
|
|
|
297
296
|
* `sdata` is used by Nymph to avoid unserializing data that hasn't been
|
|
298
297
|
* requested yet.
|
|
299
298
|
*
|
|
300
|
-
* If `source` is set to "server", the data is coming from the DB
|
|
301
|
-
*
|
|
302
|
-
* trusted.
|
|
299
|
+
* If `source` is set to "server", the data is coming from the DB. If not,
|
|
300
|
+
* assume the data is coming from the client and can't be trusted.
|
|
303
301
|
*
|
|
304
302
|
* @param data The data object.
|
|
305
303
|
* @param sdata The serialized data object.
|
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.
|