@nymphjs/nymph 1.0.0-beta.4 → 1.0.0-beta.40

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/src/Entity.ts CHANGED
@@ -45,9 +45,9 @@ import {
45
45
  *
46
46
  * Some notes about $equals() and $is(), the replacements for "==":
47
47
  *
48
- * The == operator will likely not give you the result you want, since any yet
49
- * to be unserialized data causes == to return false when you probably want it
50
- * to return true.
48
+ * The == operator will likely not give you the result you want, since two
49
+ * instances of the same entity will fail that check, even though they represent
50
+ * the same data in the database.
51
51
  *
52
52
  * $equals() performs a more strict comparison of the entity to another. Use
53
53
  * $equals() instead of the == operator when you want to check both the entities
@@ -56,8 +56,7 @@ import {
56
56
  *
57
57
  * - They must be entities.
58
58
  * - They must have equal GUIDs, or both must have no GUID.
59
- * - They must be instances of the same class.
60
- * - Their data must be equal.
59
+ * - Their data and tags must be equal.
61
60
  *
62
61
  * $is() performs a less strict comparison of the entity to another. Use $is()
63
62
  * instead of the == operator when the entity's data may have been changed, but
@@ -66,7 +65,7 @@ import {
66
65
  *
67
66
  * - They must be entities.
68
67
  * - They must have equal GUIDs, or both must have no GUID.
69
- * - If they have no GUIDs, their data must be equal.
68
+ * - If they have no GUIDs, their data and tags must be equal.
70
69
  *
71
70
  * Some notes about saving entities in other entity's properties:
72
71
  *
@@ -146,6 +145,18 @@ export default class Entity<T extends EntityData = EntityData>
146
145
  * also listed in searchRestrictedData.
147
146
  */
148
147
  protected $privateData: string[] = [];
148
+ /**
149
+ * Whether this entity should publish changes to PubSub servers.
150
+ */
151
+ public static pubSubEnabled = true;
152
+ /**
153
+ * Whether this entity should be accessible on the frontend through the REST
154
+ * server.
155
+ *
156
+ * If this is false, any request from the client that attempts to use this
157
+ * entity will fail.
158
+ */
159
+ public static restEnabled = true;
149
160
  /**
150
161
  * Properties that will not be searchable from the frontend. If the frontend
151
162
  * includes any of these properties in any of their clauses, they will be
@@ -157,8 +168,20 @@ export default class Entity<T extends EntityData = EntityData>
157
168
  * be visible on the frontend, unlike $privateData, but any changes to them
158
169
  * that come from the frontend will be ignored.
159
170
  *
160
- * In addition to what's listed here, the 'user' and 'group' properties will
161
- * be filtered for non-admins when Tilmeld is being used.
171
+ * In addition to what's listed here, all of the access control properties
172
+ * will be included when Tilmeld is being used. These are:
173
+ *
174
+ * - acUser
175
+ * - acGroup
176
+ * - acOther
177
+ * - acRead
178
+ * - acWrite
179
+ * - acFull
180
+ * - user
181
+ * - group
182
+ *
183
+ * You should modify these through client enabled methods or the $save method
184
+ * instead, for safety.
162
185
  */
163
186
  protected $protectedData: string[] = [];
164
187
  /**
@@ -293,7 +316,11 @@ export default class Entity<T extends EntityData = EntityData>
293
316
 
294
317
  if (guid != null) {
295
318
  const entity = this.$nymph.driver.getEntitySync(
296
- { class: this.constructor as EntityConstructor },
319
+ {
320
+ class: this.$nymph.getEntityClass(
321
+ this.constructor as EntityConstructor
322
+ ),
323
+ },
297
324
  { type: '&', guid }
298
325
  );
299
326
  if (entity) {
@@ -513,15 +540,17 @@ export default class Entity<T extends EntityData = EntityData>
513
540
  return false;
514
541
  }
515
542
  }
516
- if (object.constructor !== this.constructor) {
517
- return false;
518
- }
519
543
  if (object.cdate !== this.cdate) {
520
544
  return false;
521
545
  }
522
546
  if (object.mdate !== this.mdate) {
523
547
  return false;
524
548
  }
549
+ const obTags = [...object.tags].sort();
550
+ const myTags = [...this.tags].sort();
551
+ if (!isEqual(obTags, myTags)) {
552
+ return false;
553
+ }
525
554
  const obData = object.$getData(true);
526
555
  const myData = this.$getData(true);
527
556
  return isEqual(obData, myData);
@@ -615,6 +644,11 @@ export default class Entity<T extends EntityData = EntityData>
615
644
  if (typeof object.$getData !== 'function') {
616
645
  return false;
617
646
  } else {
647
+ const obTags = [...object.tags].sort();
648
+ const myTags = [...this.tags].sort();
649
+ if (!isEqual(obTags, myTags)) {
650
+ return false;
651
+ }
618
652
  const obData = object.$getData(true);
619
653
  const myData = this.$getData(true);
620
654
  return isEqual(obData, myData);
@@ -665,12 +699,21 @@ export default class Entity<T extends EntityData = EntityData>
665
699
 
666
700
  const protectedData: EntityData = {};
667
701
  const protectedProps = [...this.$protectedData];
668
- if (
669
- this.$nymph.tilmeld &&
670
- !this.$nymph.tilmeld.gatekeeper('tilmeld/admin')
671
- ) {
672
- protectedProps.push('user');
673
- protectedProps.push('group');
702
+ if (this.$nymph.tilmeld) {
703
+ protectedProps.push('acUser');
704
+ protectedProps.push('acGroup');
705
+ protectedProps.push('acOther');
706
+ protectedProps.push('acRead');
707
+ protectedProps.push('acWrite');
708
+ protectedProps.push('acFull');
709
+ if (
710
+ ((this.constructor as typeof Entity).class !== 'User' &&
711
+ (this.constructor as typeof Entity).class !== 'Group') ||
712
+ !this.$nymph.tilmeld.gatekeeper('tilmeld/admin')
713
+ ) {
714
+ protectedProps.push('user');
715
+ protectedProps.push('group');
716
+ }
674
717
  }
675
718
  for (const name of protectedProps) {
676
719
  if (name in this.$data) {
@@ -719,11 +762,29 @@ export default class Entity<T extends EntityData = EntityData>
719
762
  }
720
763
  this.mdate = patch.mdate;
721
764
 
765
+ const protectedProps = [...this.$protectedData];
766
+ if (this.$nymph.tilmeld) {
767
+ protectedProps.push('acUser');
768
+ protectedProps.push('acGroup');
769
+ protectedProps.push('acOther');
770
+ protectedProps.push('acRead');
771
+ protectedProps.push('acWrite');
772
+ protectedProps.push('acFull');
773
+ if (
774
+ ((this.constructor as typeof Entity).class !== 'User' &&
775
+ (this.constructor as typeof Entity).class !== 'Group') ||
776
+ !this.$nymph.tilmeld.gatekeeper('tilmeld/admin')
777
+ ) {
778
+ protectedProps.push('user');
779
+ protectedProps.push('group');
780
+ }
781
+ }
782
+
722
783
  for (const name in patch.set) {
723
784
  if (
724
785
  (this.$allowlistData != null &&
725
786
  this.$allowlistData.indexOf(name) === -1) ||
726
- this.$protectedData.indexOf(name) !== -1 ||
787
+ protectedProps.indexOf(name) !== -1 ||
727
788
  this.$privateData.indexOf(name) !== -1
728
789
  ) {
729
790
  continue;
@@ -739,7 +800,7 @@ export default class Entity<T extends EntityData = EntityData>
739
800
  if (
740
801
  (this.$allowlistData != null &&
741
802
  this.$allowlistData.indexOf(name) === -1) ||
742
- this.$protectedData.indexOf(name) !== -1 ||
803
+ protectedProps.indexOf(name) !== -1 ||
743
804
  this.$privateData.indexOf(name) !== -1
744
805
  ) {
745
806
  continue;
@@ -860,7 +921,9 @@ export default class Entity<T extends EntityData = EntityData>
860
921
  }
861
922
  const refresh = await this.$nymph.getEntity(
862
923
  {
863
- class: this.constructor as EntityConstructor,
924
+ class: this.$nymph.getEntityClass(
925
+ this.constructor as EntityConstructor
926
+ ),
864
927
  skipCache: true,
865
928
  skipAc: this.$skipAc,
866
929
  },
@@ -271,7 +271,7 @@ export interface EntityInterface extends DataObjectInterface {
271
271
  $useSkipAc(useSkipAc: boolean): void;
272
272
  }
273
273
 
274
- export type EntityConstructor = (new (guid?: string) => EntityInterface) & {
274
+ export type EntityConstructor = (new (...args: any[]) => EntityInterface) & {
275
275
  /**
276
276
  * The instance of Nymph to use for queries.
277
277
  */
@@ -288,6 +288,18 @@ export type EntityConstructor = (new (guid?: string) => EntityInterface) & {
288
288
  * requests.
289
289
  */
290
290
  class: string;
291
+ /**
292
+ * Whether this entity should publish changes to PubSub servers.
293
+ */
294
+ pubSubEnabled: boolean;
295
+ /**
296
+ * Whether this entity should be accessible on the frontend through the REST
297
+ * server.
298
+ *
299
+ * If this is false, any request from the client that attempts to use this
300
+ * entity will fail.
301
+ */
302
+ restEnabled: boolean;
291
303
  /**
292
304
  * Properties that will not be searchable from the frontend. If the frontend
293
305
  * includes any of these properties in any of their clauses, they will be