@nymphjs/nymph 1.0.0-beta.3 → 1.0.0-beta.31

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
  /**
@@ -513,15 +536,17 @@ export default class Entity<T extends EntityData = EntityData>
513
536
  return false;
514
537
  }
515
538
  }
516
- if (object.constructor !== this.constructor) {
517
- return false;
518
- }
519
539
  if (object.cdate !== this.cdate) {
520
540
  return false;
521
541
  }
522
542
  if (object.mdate !== this.mdate) {
523
543
  return false;
524
544
  }
545
+ const obTags = [...object.tags].sort();
546
+ const myTags = [...this.tags].sort();
547
+ if (!isEqual(obTags, myTags)) {
548
+ return false;
549
+ }
525
550
  const obData = object.$getData(true);
526
551
  const myData = this.$getData(true);
527
552
  return isEqual(obData, myData);
@@ -615,6 +640,11 @@ export default class Entity<T extends EntityData = EntityData>
615
640
  if (typeof object.$getData !== 'function') {
616
641
  return false;
617
642
  } else {
643
+ const obTags = [...object.tags].sort();
644
+ const myTags = [...this.tags].sort();
645
+ if (!isEqual(obTags, myTags)) {
646
+ return false;
647
+ }
618
648
  const obData = object.$getData(true);
619
649
  const myData = this.$getData(true);
620
650
  return isEqual(obData, myData);
@@ -665,12 +695,21 @@ export default class Entity<T extends EntityData = EntityData>
665
695
 
666
696
  const protectedData: EntityData = {};
667
697
  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');
698
+ if (this.$nymph.tilmeld) {
699
+ protectedProps.push('acUser');
700
+ protectedProps.push('acGroup');
701
+ protectedProps.push('acOther');
702
+ protectedProps.push('acRead');
703
+ protectedProps.push('acWrite');
704
+ protectedProps.push('acFull');
705
+ if (
706
+ ((this.constructor as typeof Entity).class !== 'User' &&
707
+ (this.constructor as typeof Entity).class !== 'Group') ||
708
+ !this.$nymph.tilmeld.gatekeeper('tilmeld/admin')
709
+ ) {
710
+ protectedProps.push('user');
711
+ protectedProps.push('group');
712
+ }
674
713
  }
675
714
  for (const name of protectedProps) {
676
715
  if (name in this.$data) {
@@ -719,11 +758,29 @@ export default class Entity<T extends EntityData = EntityData>
719
758
  }
720
759
  this.mdate = patch.mdate;
721
760
 
761
+ const protectedProps = [...this.$protectedData];
762
+ if (this.$nymph.tilmeld) {
763
+ protectedProps.push('acUser');
764
+ protectedProps.push('acGroup');
765
+ protectedProps.push('acOther');
766
+ protectedProps.push('acRead');
767
+ protectedProps.push('acWrite');
768
+ protectedProps.push('acFull');
769
+ if (
770
+ ((this.constructor as typeof Entity).class !== 'User' &&
771
+ (this.constructor as typeof Entity).class !== 'Group') ||
772
+ !this.$nymph.tilmeld.gatekeeper('tilmeld/admin')
773
+ ) {
774
+ protectedProps.push('user');
775
+ protectedProps.push('group');
776
+ }
777
+ }
778
+
722
779
  for (const name in patch.set) {
723
780
  if (
724
781
  (this.$allowlistData != null &&
725
782
  this.$allowlistData.indexOf(name) === -1) ||
726
- this.$protectedData.indexOf(name) !== -1 ||
783
+ protectedProps.indexOf(name) !== -1 ||
727
784
  this.$privateData.indexOf(name) !== -1
728
785
  ) {
729
786
  continue;
@@ -739,7 +796,7 @@ export default class Entity<T extends EntityData = EntityData>
739
796
  if (
740
797
  (this.$allowlistData != null &&
741
798
  this.$allowlistData.indexOf(name) === -1) ||
742
- this.$protectedData.indexOf(name) !== -1 ||
799
+ protectedProps.indexOf(name) !== -1 ||
743
800
  this.$privateData.indexOf(name) !== -1
744
801
  ) {
745
802
  continue;
@@ -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