@onehat/data 1.20.6 → 1.20.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/data",
3
- "version": "1.20.6",
3
+ "version": "1.20.7",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -579,6 +579,10 @@ class AjaxRepository extends Repository {
579
579
  this.throwError('No "add" api endpoint defined.');
580
580
  return;
581
581
  }
582
+ if (!this.canAdd) {
583
+ this.throwError('Adding has been disabled on this repository.');
584
+ return;
585
+ }
582
586
 
583
587
  this._operations.add = true;
584
588
  entity.isSaving = true;
@@ -630,6 +634,10 @@ class AjaxRepository extends Repository {
630
634
  this.throwError('No "batchAdd" api endpoint defined.');
631
635
  return;
632
636
  }
637
+ if (!this.canAdd) {
638
+ this.throwError('Adding has been disabled on this repository.');
639
+ return;
640
+ }
633
641
 
634
642
  this._operations.add = true;
635
643
 
@@ -690,6 +698,10 @@ class AjaxRepository extends Repository {
690
698
  this.throwError('No "edit" api endpoint defined.');
691
699
  return;
692
700
  }
701
+ if (!this.canEdit) {
702
+ this.throwError('Editing has been disabled on this repository.');
703
+ return;
704
+ }
693
705
 
694
706
  this._operations.edit = true;
695
707
  entity.isSaving = true;
@@ -741,6 +753,10 @@ class AjaxRepository extends Repository {
741
753
  this.throwError('No "batchEdit" api endpoint defined.');
742
754
  return;
743
755
  }
756
+ if (!this.canEdit) {
757
+ this.throwError('Editing has been disabled on this repository.');
758
+ return;
759
+ }
744
760
 
745
761
  this._operations.edit = true;
746
762
 
@@ -801,6 +817,10 @@ class AjaxRepository extends Repository {
801
817
  this.throwError('No "delete" api endpoint defined.');
802
818
  return;
803
819
  }
820
+ if (!this.canDelete) {
821
+ this.throwError('Deleting has been disabled on this repository.');
822
+ return;
823
+ }
804
824
 
805
825
  if (entity.isRemotePhantomMode && entity.isPhantom) {
806
826
  this._operations.deletePhantom = true;
@@ -862,6 +882,10 @@ class AjaxRepository extends Repository {
862
882
  this.throwError('No "batchDelete" api endpoint defined.');
863
883
  return;
864
884
  }
885
+ if (!this.canDelete) {
886
+ this.throwError('Deleting has been disabled on this repository.');
887
+ return;
888
+ }
865
889
 
866
890
  this._operations.delete = true; // NOTE: We don't use batchDelete for remotePhantom records
867
891
 
@@ -369,6 +369,10 @@ class MemoryRepository extends Repository {
369
369
  this.throwError('this._doAdd is no longer valid. Repository has been destroyed.');
370
370
  return;
371
371
  }
372
+ if (!this.canAdd) {
373
+ this.throwError('Adding has been disabled on this repository.');
374
+ return;
375
+ }
372
376
 
373
377
  // Give it a non-temporary ID, if needed
374
378
  if (entity.isPhantom) {
@@ -419,6 +423,10 @@ class MemoryRepository extends Repository {
419
423
  this.throwError('this._doEdit is no longer valid. Repository has been destroyed.');
420
424
  return;
421
425
  }
426
+ if (!this.canEdit) {
427
+ this.throwError('Editing has been disabled on this repository.');
428
+ return;
429
+ }
422
430
 
423
431
  entity.markSaved();
424
432
  return entity;
@@ -435,6 +443,11 @@ class MemoryRepository extends Repository {
435
443
  this.throwError('this._doDelete is no longer valid. Repository has been destroyed.');
436
444
  return;
437
445
  }
446
+ if (!this.canDelete) {
447
+ this.throwError('Deleting has been disabled on this repository.');
448
+ return;
449
+ }
450
+
438
451
  delete this._keyedEntities[entity.id];
439
452
  this.entities = _.filter(this.entities, (x) => x.id !== entity.id);
440
453
 
@@ -166,6 +166,11 @@ class OfflineRepository extends MemoryRepository {
166
166
  * @private
167
167
  */
168
168
  async _doAdd(entity) {
169
+ if (!this.canAdd) {
170
+ this.throwError('Adding has been disabled on this repository.');
171
+ return;
172
+ }
173
+
169
174
  // Get a clone, in case we need to revert back to it later
170
175
  const clone = entity.clone();
171
176
 
@@ -203,6 +208,11 @@ class OfflineRepository extends MemoryRepository {
203
208
  * Hook into super._doEdit, so we can save Entity changes to storage medium.
204
209
  */
205
210
  async _doEdit(entity) {
211
+ if (!this.canEdit) {
212
+ this.throwError('Editing has been disabled on this repository.');
213
+ return;
214
+ }
215
+
206
216
  // Get a clone, in case we need to revert back to it later
207
217
  const clone = entity.clone();
208
218
 
@@ -226,6 +236,11 @@ class OfflineRepository extends MemoryRepository {
226
236
  * Hook into super._doDelete, so we can delete Entity from storage medium.
227
237
  */
228
238
  async _doDelete(entity) {
239
+ if (!this.canDelete) {
240
+ this.throwError('Deleting has been disabled on this repository.');
241
+ return;
242
+ }
243
+
229
244
  // Get a clone, in case we need to revert back to it later
230
245
  const clone = entity.clone();
231
246
 
@@ -142,6 +142,21 @@ export default class Repository extends EventEmitter {
142
142
  */
143
143
  combineBatch: false,
144
144
 
145
+ /**
146
+ * @member {boolean} canAdd - Whether this Repository allows adding entities
147
+ */
148
+ canAdd: true,
149
+
150
+ /**
151
+ * @member {boolean} canEdit - Whether this Repository allows editing entities
152
+ */
153
+ canEdit: true,
154
+
155
+ /**
156
+ * @member {boolean} canDelete - Whether this Repository allows deleting entities
157
+ */
158
+ canDelete: true,
159
+
145
160
  /**
146
161
  * @member {boolean} debugMode - Whether this Repository should output debug messages
147
162
  */
@@ -1039,6 +1054,10 @@ export default class Repository extends EventEmitter {
1039
1054
  this.throwError('this.add is no longer valid. Repository has been destroyed.');
1040
1055
  return;
1041
1056
  }
1057
+ if (!this.canAdd) {
1058
+ this.throwError('Adding has been disabled on this repository.');
1059
+ return;
1060
+ }
1042
1061
 
1043
1062
  // Does it already exist? If so, edit the existing
1044
1063
  const idProperty = this.getSchema().model.idProperty;
@@ -1117,6 +1136,11 @@ export default class Repository extends EventEmitter {
1117
1136
  */
1118
1137
  addMultiple = async (allData, isPersisted = false) => {
1119
1138
 
1139
+ if (!this.canAdd) {
1140
+ this.throwError('Adding has been disabled on this repository.');
1141
+ return;
1142
+ }
1143
+
1120
1144
  let entities = [],
1121
1145
  i,
1122
1146
  data,
@@ -1868,7 +1892,6 @@ export default class Repository extends EventEmitter {
1868
1892
  return this._doDelete(entity);
1869
1893
  }
1870
1894
 
1871
-
1872
1895
  /**
1873
1896
  * Helper for save.
1874
1897
  * Should take the promises returned from batch operations and handle any errors.
@@ -1895,6 +1918,10 @@ export default class Repository extends EventEmitter {
1895
1918
  this.throwError('this.delete is no longer valid. Repository has been destroyed.');
1896
1919
  return;
1897
1920
  }
1921
+ if (!this.canDelete) {
1922
+ this.throwError('Deleting has been disabled on this repository.');
1923
+ return;
1924
+ }
1898
1925
  if (!entities) {
1899
1926
  return false;
1900
1927
  }