@onehat/data 1.10.5 → 1.11.1
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/cypress/fixtures/Definitions/GroupsUsers.js +1 -1
- package/cypress/integration/Async.spec.js +5 -5
- package/cypress/integration/Entity.spec.js +0 -19
- package/cypress/integration/OneHatData.spec.js +3 -3
- package/cypress/integration/Repository/Ajax.spec.js +1 -1
- package/cypress/integration/Repository/LocalFromRemote.spec.js +2 -2
- package/cypress/integration/Repository/Repository.spec.js +5 -5
- package/package.json +1 -1
- package/src/Entity.js +3 -25
- package/src/Repository/Ajax.js +1 -1
- package/src/Repository/LocalFromRemote/LocalFromRemote.js +14 -14
- package/src/Repository/Memory.js +3 -3
- package/src/Repository/OneBuild.js +4 -4
- package/src/Repository/Repository.js +21 -21
- package/src/Util/Formatters.js +3 -3
|
@@ -66,7 +66,7 @@ describe('Async playground', function() {
|
|
|
66
66
|
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
-
it.skip('
|
|
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
|
-
|
|
87
|
-
|
|
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
|
-
|
|
144
|
-
|
|
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
|
-
|
|
468
|
+
isAutoSync: true,
|
|
469
469
|
local: {
|
|
470
470
|
type: 'memory',
|
|
471
|
-
|
|
471
|
+
isAutoLoad: false,
|
|
472
472
|
isRemote: false,
|
|
473
473
|
isLocal: true,
|
|
474
474
|
},
|
|
475
475
|
remote: {
|
|
476
476
|
type: 'memory',
|
|
477
|
-
|
|
477
|
+
isAutoLoad: false,
|
|
478
478
|
isRemote: true, // hack
|
|
479
479
|
isLocal: false,
|
|
480
480
|
},
|
|
@@ -44,7 +44,7 @@ describe('LocalFromRemote', function() {
|
|
|
44
44
|
this.repository = new this.Repository({
|
|
45
45
|
local,
|
|
46
46
|
remote,
|
|
47
|
-
|
|
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
|
-
|
|
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
|
-
|
|
29
|
-
|
|
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.
|
|
145
|
+
expect(this.repository.isAutoSave).to.be.true;
|
|
146
146
|
this.repository.setAutoSave(false);
|
|
147
|
-
expect(this.repository.
|
|
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.
|
|
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
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
|
|
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.
|
|
1290
|
-
throw Error('Cannot undelete entities on an
|
|
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);
|
package/src/Repository/Ajax.js
CHANGED
|
@@ -186,7 +186,7 @@ class AjaxRepository extends Repository {
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
// Sorting
|
|
189
|
-
if (this.
|
|
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}
|
|
97
|
+
* @member {boolean} isAutoSync - Whether to auto sync this repository on initialization
|
|
98
98
|
*/
|
|
99
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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 (
|
|
575
|
+
setAutoSync = async (isAutoSync) => {
|
|
576
576
|
let isChanged = false
|
|
577
|
-
if (this.
|
|
577
|
+
if (this.isAutoSync !== isAutoSync) {
|
|
578
578
|
isChanged = true;
|
|
579
|
-
this.
|
|
580
|
-
if (
|
|
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
|
|
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.
|
|
602
|
+
if (isOnline && this.isAutoSync) {
|
|
603
603
|
this._doAutoSync();
|
|
604
604
|
}
|
|
605
605
|
}
|
package/src/Repository/Memory.js
CHANGED
|
@@ -21,9 +21,9 @@ class MemoryRepository extends Repository {
|
|
|
21
21
|
|
|
22
22
|
const defaults = {
|
|
23
23
|
isLocal: true,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
35
|
-
|
|
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.
|
|
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.
|
|
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}
|
|
49
|
+
* @member {boolean} isAutoLoad - Whether to immediately load this repository's data on instantiation
|
|
50
50
|
*/
|
|
51
|
-
|
|
51
|
+
isAutoLoad: false,
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
* @member {boolean}
|
|
54
|
+
* @member {boolean} isAutoSave - Whether to automatically save entity changes to permanent storage
|
|
55
55
|
*/
|
|
56
|
-
|
|
56
|
+
isAutoSave: false,
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
|
-
* @member {boolean}
|
|
59
|
+
* @member {boolean} isAutoSort - Whether to automatically sort entities in permanent storage
|
|
60
60
|
*/
|
|
61
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
268
|
+
if (this.isAutoLoad) {
|
|
269
269
|
await this.load();
|
|
270
270
|
}
|
|
271
|
-
if (!this.isSorted && this.
|
|
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
|
|
369
|
-
* @param {boolean}
|
|
368
|
+
* Sets the isAutoSave setting of this Repository
|
|
369
|
+
* @param {boolean} isAutoSave
|
|
370
370
|
*/
|
|
371
|
-
setAutoSave = (
|
|
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.
|
|
375
|
+
this.isAutoSave = isAutoSave
|
|
376
376
|
}
|
|
377
377
|
|
|
378
378
|
/**
|
|
379
|
-
* Sets the
|
|
380
|
-
* @param {boolean}
|
|
379
|
+
* Sets the isAutoLoad setting of this Repository
|
|
380
|
+
* @param {boolean} isAutoLoad
|
|
381
381
|
*/
|
|
382
|
-
setAutoLoad = (
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
1731
|
+
if (this.isAutoSave) {
|
|
1732
1732
|
await this.save();
|
|
1733
1733
|
}
|
|
1734
1734
|
}
|
package/src/Util/Formatters.js
CHANGED
|
@@ -78,7 +78,7 @@ class Formatters {
|
|
|
78
78
|
return moment(date).format(format);
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
return
|
|
81
|
+
return null;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
static FormatDateTime = (value, format = 'MMM DD, YYYY HH:mm:ss') => {
|
|
@@ -94,7 +94,7 @@ class Formatters {
|
|
|
94
94
|
return moment(date).format(format);
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
return
|
|
97
|
+
return null;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
static FormatTime = (value) => {
|
|
@@ -111,7 +111,7 @@ class Formatters {
|
|
|
111
111
|
return moment(date).format(format);
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
-
return
|
|
114
|
+
return null;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
static FormatHours = (value) => {
|