@onehat/data 1.10.5 → 1.11.0

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.
@@ -44,7 +44,7 @@ const GroupsUsers = {
44
44
 
45
45
  repository: {
46
46
  type: 'onebuild',
47
- autoSave: false,
47
+ isAutoSave: false,
48
48
  },
49
49
 
50
50
  };
@@ -66,7 +66,7 @@ describe('Async playground', function() {
66
66
 
67
67
  });
68
68
 
69
- it.skip('autoLoad & autoSave', function() {
69
+ it.skip('isAutoLoad & isAutoSave', function() {
70
70
 
71
71
  (async () => {
72
72
  const oneHatData = new OneHatData();
@@ -83,8 +83,8 @@ describe('Async playground', function() {
83
83
  },
84
84
  repository: {
85
85
  type: 'memory',
86
- autoLoad: true,
87
- autoSave: true,
86
+ isAutoLoad: true,
87
+ isAutoSave: true,
88
88
  data: [
89
89
  { key: 1, value: 'one', },
90
90
  { key: 2, value: 'two', },
@@ -140,8 +140,8 @@ describe('Async playground', function() {
140
140
  },
141
141
  repository: {
142
142
  type: 'memory',
143
- autoLoad: false,
144
- autoSave: false,
143
+ isAutoLoad: false,
144
+ isAutoSave: false,
145
145
  data: [
146
146
  { key: 1, value: 'one', },
147
147
  { key: 2, value: 'two', },
@@ -112,25 +112,6 @@ describe('Entity', function() {
112
112
  expect(_.isEqual(entity.getSubmitValues(), clone.getSubmitValues())).to.be.true;
113
113
  });
114
114
 
115
- it.skip('duplicate', function() {
116
- const entity = this.entity;
117
-
118
- const duplicate = entity.duplicate();
119
-
120
- expect(entity === duplicate).to.be.false;
121
- expect(_.isEqual(entity.id, duplicate.id)).to.be.true;
122
- expect(_.isEqual(entity.displayValue, duplicate.displayValue)).to.be.true;
123
- expect(_.isEqual(entity.isDirty, duplicate.isDirty)).to.be.true;
124
- expect(_.isEqual(entity.isPersisted, duplicate.isPersisted)).to.be.true;
125
- expect(_.isEqual(entity.isDeleted, duplicate.isDeleted)).to.be.true;
126
- expect(_.isEqual(entity._originalData, duplicate._originalData)).to.be.true;
127
- expect(_.isEqual(entity.getOriginalData(), duplicate.getOriginalData())).to.be.true;
128
- expect(_.isEqual(entity.getRawValues(), duplicate.getRawValues())).to.be.true;
129
- expect(_.isEqual(entity.getParsedValues(), duplicate.getParsedValues())).to.be.true;
130
- expect(_.isEqual(entity.getDisplayValues(), duplicate.getDisplayValues())).to.be.true;
131
- expect(_.isEqual(entity.getSubmitValues(), duplicate.getSubmitValues())).to.be.true;
132
- });
133
-
134
115
  it('_createProperties', function() {
135
116
  const entity = this.entity;
136
117
  expect(_.size(entity.properties)).to.be.eq(3);
@@ -465,16 +465,16 @@ describe('OneHatData', function() {
465
465
  name: 'bar',
466
466
  repository: {
467
467
  type: 'lfr',
468
- autoSync: true,
468
+ isAutoSync: true,
469
469
  local: {
470
470
  type: 'memory',
471
- autoLoad: false,
471
+ isAutoLoad: false,
472
472
  isRemote: false,
473
473
  isLocal: true,
474
474
  },
475
475
  remote: {
476
476
  type: 'memory',
477
- autoLoad: false,
477
+ isAutoLoad: false,
478
478
  isRemote: true, // hack
479
479
  isLocal: false,
480
480
  },
@@ -18,7 +18,7 @@ describe('OneBuildRepository', function() {
18
18
  this.repository = new this.Repository({
19
19
  id: 'foo',
20
20
  schema: this.schema,
21
- autoSave: false,
21
+ isAutoSave: false,
22
22
  });
23
23
  this.repository.initialize();
24
24
  this.schema.setBoundRepository(this.repository);
@@ -44,7 +44,7 @@ describe('LocalFromRemote', function() {
44
44
  this.repository = new this.Repository({
45
45
  local,
46
46
  remote,
47
- autoSync: false,
47
+ isAutoSync: false,
48
48
  retryRate: '+1 minute',
49
49
  });
50
50
  this.repository.initialize();
@@ -204,7 +204,7 @@ describe('LocalFromRemote', function() {
204
204
  remote,
205
205
  mode: MODE_COMMAND_QUEUE,
206
206
  isOnline: false,
207
- autoSync: false,
207
+ isAutoSync: false,
208
208
  retryRate: '+1 minute',
209
209
  });
210
210
 
@@ -25,8 +25,8 @@ describe('Repository Base', function() {
25
25
  this.repository = new this.Repository({
26
26
  id: 'foo',
27
27
  schema: this.schema,
28
- autoLoad: true,
29
- autoSave: true,
28
+ isAutoLoad: true,
29
+ isAutoSave: true,
30
30
  isPaginated: true,
31
31
  data: [
32
32
  { key: 1, value: 'one', },
@@ -142,9 +142,9 @@ describe('Repository Base', function() {
142
142
  });
143
143
 
144
144
  it('setAutoSave', function() {
145
- expect(this.repository.autoSave).to.be.true;
145
+ expect(this.repository.isAutoSave).to.be.true;
146
146
  this.repository.setAutoSave(false);
147
- expect(this.repository.autoSave).to.be.false;
147
+ expect(this.repository.isAutoSave).to.be.false;
148
148
  });
149
149
 
150
150
  });
@@ -609,7 +609,7 @@ describe('Repository Base', function() {
609
609
  })
610
610
 
611
611
  it('add with an existing id', async function() {
612
- this.repository.autoSave = false;
612
+ this.repository.isAutoSave = false;
613
613
 
614
614
  // ID suppied; should not be temp ID or phantom
615
615
  const entity = await this.repository.add({ key: 6, value: 'six' });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/data",
3
- "version": "1.10.5",
3
+ "version": "1.11.0",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/Entity.js CHANGED
@@ -338,28 +338,6 @@ class Entity extends EventEmitter {
338
338
  return clone;
339
339
  }
340
340
 
341
- /**
342
- * Duplicates this Entity and inserts the copy into the Repository.
343
- * @return {object} Entity - The clone
344
- * @memberOf Entity
345
- */
346
- duplicate = () => {
347
- let duplicate;
348
- if (this.repository) {
349
- duplicate = this.repository.add(this.rawData, false);
350
- }
351
- // const duplicate = new Entity(this.schema, this._originalData, this.repository);
352
- // duplicate.initialize();
353
- // if (this.isDirty) {
354
- // duplicate.setValues( this.getRawValues() );
355
- // }
356
- // duplicate.isPersisted = false;
357
- // duplicate.id = newId;
358
- // duplicate.isDeleted = false;
359
-
360
- return duplicate;
361
- }
362
-
363
341
  /**
364
342
  * Resets the Entity to a state as if it had just been created,
365
343
  * Gets data to restore from _originalData.
@@ -1275,7 +1253,7 @@ class Entity extends EventEmitter {
1275
1253
 
1276
1254
  /**
1277
1255
  * Marks a deleted entity as undeleted.
1278
- * Only works when autoSave is off for the containing repository
1256
+ * Only works when isAutoSave is off for the containing repository
1279
1257
  * @fires delete
1280
1258
  */
1281
1259
  undelete = () => {
@@ -1286,8 +1264,8 @@ class Entity extends EventEmitter {
1286
1264
  throw Error('this.undelete is no longer valid. Entity has been destroyed.');
1287
1265
  }
1288
1266
  const repository = this.getRepository();
1289
- if (repository && repository.autoSave) {
1290
- throw Error('Cannot undelete entities on an autoSave repository.');
1267
+ if (repository && repository.isAutoSave) {
1268
+ throw Error('Cannot undelete entities on an isAutoSave repository.');
1291
1269
  }
1292
1270
  this.markDeleted(false);
1293
1271
  this.emit('undelete', this._proxy);
@@ -186,7 +186,7 @@ class AjaxRepository extends Repository {
186
186
  }
187
187
 
188
188
  // Sorting
189
- if (this.autoSort) {
189
+ if (this.isAutoSort) {
190
190
  if (!this.sorters.length) {
191
191
  this.sorters = this.getDefaultSorters(); // Need this here, because _setInitialQueryParams() runs before this.load() in super.initialize()
192
192
  }
@@ -94,9 +94,9 @@ class LocalFromRemoteRepository extends EventEmitter {
94
94
  mode: MODE_LOCAL_MIRROR,
95
95
 
96
96
  /**
97
- * @member {boolean} autoSync - Whether to auto sync this repository on initialization
97
+ * @member {boolean} isAutoSync - Whether to auto sync this repository on initialization
98
98
  */
99
- autoSync: false,
99
+ isAutoSync: false,
100
100
 
101
101
  /**
102
102
  * @member {string} syncRate - Interval with which to sync local with remote.
@@ -201,7 +201,7 @@ class LocalFromRemoteRepository extends EventEmitter {
201
201
  this.registerCommands(commands);
202
202
  }
203
203
 
204
- if (this.autoSync) {
204
+ if (this.isAutoSync) {
205
205
  this._doAutoSync();
206
206
  }
207
207
  }
@@ -302,14 +302,14 @@ class LocalFromRemoteRepository extends EventEmitter {
302
302
 
303
303
  // Load remote data into local
304
304
  // Local <-- Remote
305
- if (!this.remote.autoLoad) {
305
+ if (!this.remote.isAutoLoad) {
306
306
  await this.remote.load();
307
307
  }
308
308
 
309
309
  remoteData = this.remote.getOriginalData();
310
310
  await this.local.load(remoteData);
311
311
 
312
- if (!this.local.autoSave) {
312
+ if (!this.local.isAutoSave) {
313
313
  await this.local.save();
314
314
  }
315
315
 
@@ -334,7 +334,7 @@ class LocalFromRemoteRepository extends EventEmitter {
334
334
 
335
335
  // local --> remote
336
336
  const remoteItem = await this.remote.add(localItem.getOriginalData());
337
- if (!this.remote.autoSave) {
337
+ if (!this.remote.isAutoSave) {
338
338
  await this.remote.save();
339
339
  }
340
340
 
@@ -369,14 +369,14 @@ class LocalFromRemoteRepository extends EventEmitter {
369
369
 
370
370
  // Load remote data into local
371
371
  // Local <-- Remote
372
- if (!this.remote.autoLoad) {
372
+ if (!this.remote.isAutoLoad) {
373
373
  await this.remote.load();
374
374
  }
375
375
 
376
376
  remoteData = this.remote.getOriginalData();
377
377
  await this.local.load(remoteData);
378
378
 
379
- if (!this.local.autoSave) {
379
+ if (!this.local.isAutoSave) {
380
380
  await this.local.save();
381
381
  }
382
382
 
@@ -572,12 +572,12 @@ class LocalFromRemoteRepository extends EventEmitter {
572
572
  /**
573
573
  * Sets autoSync. If autoSync is enabled, it immediately starts autosync process.
574
574
  */
575
- setAutoSync = async (autoSync) => {
575
+ setAutoSync = async (isAutoSync) => {
576
576
  let isChanged = false
577
- if (this.autoSync !== autoSync) {
577
+ if (this.isAutoSync !== isAutoSync) {
578
578
  isChanged = true;
579
- this.autoSync = autoSync;
580
- if (autoSync) {
579
+ this.isAutoSync = isAutoSync;
580
+ if (isAutoSync) {
581
581
  await this._doAutoSync();
582
582
  } else {
583
583
  clearTimeout(this._timeout);
@@ -595,11 +595,11 @@ class LocalFromRemoteRepository extends EventEmitter {
595
595
  }
596
596
 
597
597
  /**
598
- * Sets isOnline. If isOnline and autoSync is enabled, it immediately starts autosync process.
598
+ * Sets isOnline. If isOnline and autoSync is enabled, it immediately starts isAutosync process.
599
599
  */
600
600
  setIsOnline = (isOnline) => {
601
601
  this.isOnline = !!isOnline; // force convert type to boolean
602
- if (isOnline && this.autoSync) {
602
+ if (isOnline && this.isAutoSync) {
603
603
  this._doAutoSync();
604
604
  }
605
605
  }
@@ -21,9 +21,9 @@ class MemoryRepository extends Repository {
21
21
 
22
22
  const defaults = {
23
23
  isLocal: true,
24
- autoSort: true,
25
- autoLoad: true,
26
- autoSave: true,
24
+ isAutoSort: true,
25
+ isAutoLoad: true,
26
+ isAutoSave: true,
27
27
  };
28
28
  _.merge(this, defaults, config);
29
29
  }
@@ -31,8 +31,8 @@ class OneBuildRepository extends AjaxRepository {
31
31
 
32
32
  const defaults = {
33
33
 
34
- autoLoad: false,
35
- autoSave: true,
34
+ isAutoLoad: false,
35
+ isAutoSave: true,
36
36
 
37
37
  api: {
38
38
  get: this.name + '/get',
@@ -163,7 +163,7 @@ class OneBuildRepository extends AjaxRepository {
163
163
  }
164
164
  });
165
165
 
166
- if (this.isLoaded && this.autoLoad) {
166
+ if (this.isLoaded && this.isAutoLoad) {
167
167
  return this.reload();
168
168
  }
169
169
  }
@@ -183,7 +183,7 @@ class OneBuildRepository extends AjaxRepository {
183
183
  this.setBaseParam('order', sorterStrings.join(','));
184
184
  }
185
185
 
186
- if (this.isLoaded && this.autoLoad) {
186
+ if (this.isLoaded && this.isAutoLoad) {
187
187
  return this.reload().then(() => {
188
188
  this.emit('changeSorters');
189
189
  });
@@ -46,19 +46,19 @@ export default class Repository extends EventEmitter {
46
46
  name: schema.name,
47
47
 
48
48
  /**
49
- * @member {boolean} autoLoad - Whether to immediately load this repository's data on instantiation
49
+ * @member {boolean} isAutoLoad - Whether to immediately load this repository's data on instantiation
50
50
  */
51
- autoLoad: false,
51
+ isAutoLoad: false,
52
52
 
53
53
  /**
54
- * @member {boolean} autoSave - Whether to automatically save entity changes to permanent storage
54
+ * @member {boolean} isAutoSave - Whether to automatically save entity changes to permanent storage
55
55
  */
56
- autoSave: false,
56
+ isAutoSave: false,
57
57
 
58
58
  /**
59
- * @member {boolean} autoSort - Whether to automatically sort entities in permanent storage
59
+ * @member {boolean} isAutoSort - Whether to automatically sort entities in permanent storage
60
60
  */
61
- autoSort: true,
61
+ isAutoSort: true,
62
62
 
63
63
  /**
64
64
  * @member {boolean} isLocal - Whether this Repository saves its data to local permanent storage
@@ -253,22 +253,22 @@ export default class Repository extends EventEmitter {
253
253
  */
254
254
  async initialize() {
255
255
  // Create default sorters if none supplied
256
- if (this.autoSort && !this.sorters.length) {
256
+ if (this.isAutoSort && !this.sorters.length) {
257
257
  this.sorters = this.getDefaultSorters();
258
258
  }
259
259
 
260
260
  // Assign event handlers
261
261
  this.on('entity_change', async (entity) => { // Entity changed its value
262
- if (this.autoSave) {
262
+ if (this.isAutoSave) {
263
263
  return await this.save(entity);
264
264
  }
265
265
  });
266
266
 
267
267
  // Auto load & sort
268
- if (this.autoLoad) {
268
+ if (this.isAutoLoad) {
269
269
  await this.load();
270
270
  }
271
- if (!this.isSorted && this.autoSort && !this.isRemoteSort) { // load may have sorted, in which case this will be skipped.
271
+ if (!this.isSorted && this.isAutoSort && !this.isRemoteSort) { // load may have sorted, in which case this will be skipped.
272
272
  await this.sort();
273
273
  }
274
274
 
@@ -365,25 +365,25 @@ export default class Repository extends EventEmitter {
365
365
  }
366
366
 
367
367
  /**
368
- * Sets the autoSave setting of this Repository
369
- * @param {boolean} autoSave
368
+ * Sets the isAutoSave setting of this Repository
369
+ * @param {boolean} isAutoSave
370
370
  */
371
- setAutoSave = (autoSave) => {
371
+ setAutoSave = (isAutoSave) => {
372
372
  if (this.isDestroyed) {
373
373
  throw Error('this.setAutoSave is no longer valid. Repository has been destroyed.');
374
374
  }
375
- this.autoSave = autoSave
375
+ this.isAutoSave = isAutoSave
376
376
  }
377
377
 
378
378
  /**
379
- * Sets the autoLoad setting of this Repository
380
- * @param {boolean} autoLoad
379
+ * Sets the isAutoLoad setting of this Repository
380
+ * @param {boolean} isAutoLoad
381
381
  */
382
- setAutoLoad = (autoLoad) => {
382
+ setAutoLoad = (isAutoLoad) => {
383
383
  if (this.isDestroyed) {
384
384
  throw Error('this.setAutoLoad is no longer valid. Repository has been destroyed.');
385
385
  }
386
- this.autoLoad = autoLoad
386
+ this.isAutoLoad = isAutoLoad
387
387
  }
388
388
 
389
389
 
@@ -937,7 +937,7 @@ export default class Repository extends EventEmitter {
937
937
  if (this.isInRepository(data[idProperty])) {
938
938
  const existing = this.getById(data[idProperty]);
939
939
  existing.setRawValues(data);
940
- if (this.autoSave && !existing.isPersisted) {
940
+ if (this.isAutoSave && !existing.isPersisted) {
941
941
  await this.save(existing);
942
942
  }
943
943
  return existing;
@@ -959,7 +959,7 @@ export default class Repository extends EventEmitter {
959
959
 
960
960
  this.emit('add', entity);
961
961
 
962
- if (this.autoSave && !entity.isPersisted) {
962
+ if (this.isAutoSave && !entity.isPersisted) {
963
963
  await this.save(entity);
964
964
  }
965
965
 
@@ -1728,7 +1728,7 @@ export default class Repository extends EventEmitter {
1728
1728
 
1729
1729
  this.emit('delete', entities);
1730
1730
 
1731
- if (this.autoSave) {
1731
+ if (this.isAutoSave) {
1732
1732
  await this.save();
1733
1733
  }
1734
1734
  }