@onehat/data 1.10.3 → 1.10.5
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/integration/Entity.spec.js +19 -0
- package/cypress/integration/OneHatData.spec.js +25 -11
- package/package.json +1 -1
- package/src/Entity.js +24 -2
- package/src/OneHatData.js +14 -1
- package/src/Property/Property.js +1 -1
- package/src/Repository/OneBuild.js +5 -1
- package/src/Repository/Repository.js +1 -1
|
@@ -112,6 +112,25 @@ 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
|
+
|
|
115
134
|
it('_createProperties', function() {
|
|
116
135
|
const entity = this.entity;
|
|
117
136
|
expect(_.size(entity.properties)).to.be.eq(3);
|
|
@@ -8,9 +8,9 @@ import KeyValues from '../../src/Schema/KeyValues.js';
|
|
|
8
8
|
|
|
9
9
|
// NOTE: Cypress can't handle async functions for beforeEach,
|
|
10
10
|
// so we have to manually apply it to every test. Ugh!
|
|
11
|
-
async function beforeEach() {
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
async function beforeEach(that) {
|
|
12
|
+
that.oneHatData = new OneHatData();
|
|
13
|
+
that.schema = that.oneHatData.createSchema({
|
|
14
14
|
name: 'bar',
|
|
15
15
|
model: {
|
|
16
16
|
idProperty: 'key',
|
|
@@ -22,14 +22,14 @@ async function beforeEach() {
|
|
|
22
22
|
},
|
|
23
23
|
repository: 'memory',
|
|
24
24
|
});
|
|
25
|
-
await
|
|
25
|
+
await that.oneHatData.createRepository({
|
|
26
26
|
id: 'foo',
|
|
27
|
-
schema:
|
|
27
|
+
schema: that.schema,
|
|
28
28
|
}, true);
|
|
29
|
-
|
|
29
|
+
that.repository = that.oneHatData.getRepositoryById('foo');
|
|
30
30
|
}
|
|
31
|
-
function afterEach() {
|
|
32
|
-
|
|
31
|
+
function afterEach(that) {
|
|
32
|
+
that.oneHatData.destroy();
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
describe('OneHatData', function() {
|
|
@@ -250,15 +250,30 @@ describe('OneHatData', function() {
|
|
|
250
250
|
|
|
251
251
|
it('getRepository', function() {
|
|
252
252
|
(async function() {
|
|
253
|
+
|
|
253
254
|
await beforeEach();
|
|
254
255
|
|
|
255
|
-
const result =
|
|
256
|
-
expect(result).to.be.eq(
|
|
256
|
+
const result = that.oneHatData.getRepository('bar');
|
|
257
|
+
expect(result).to.be.eq(that.repository);
|
|
257
258
|
|
|
258
259
|
afterEach();
|
|
259
260
|
})();
|
|
260
261
|
});
|
|
261
262
|
|
|
263
|
+
it('getUniqueRepository', function() {
|
|
264
|
+
(async () => {
|
|
265
|
+
const that = {};
|
|
266
|
+
await beforeEach(that);
|
|
267
|
+
|
|
268
|
+
const
|
|
269
|
+
repo1 = that.oneHatData.getRepository('bar'),
|
|
270
|
+
repo2 = that.oneHatData.getRepository('bar', true);
|
|
271
|
+
expect(repo1 !== repo2).to.be.true;
|
|
272
|
+
|
|
273
|
+
afterEach(that);
|
|
274
|
+
})();
|
|
275
|
+
});
|
|
276
|
+
|
|
262
277
|
it('getRepositoriesBy', function() {
|
|
263
278
|
(async function() {
|
|
264
279
|
await beforeEach();
|
|
@@ -345,7 +360,6 @@ describe('OneHatData', function() {
|
|
|
345
360
|
|
|
346
361
|
it('isEntity', async function() {
|
|
347
362
|
(async function() {
|
|
348
|
-
debugger;
|
|
349
363
|
await beforeEach();
|
|
350
364
|
const oneHatData = this.oneHatData;
|
|
351
365
|
const repository = oneHatData.getRepository('bar');
|
package/package.json
CHANGED
package/src/Entity.js
CHANGED
|
@@ -23,7 +23,7 @@ import _ from 'lodash';
|
|
|
23
23
|
* - entity.getPropertySubmitValue('users__last_name');
|
|
24
24
|
*
|
|
25
25
|
* @extends EventEmitter
|
|
26
|
-
* @fires ['change', 'reset', 'save', 'delete', 'destroy']
|
|
26
|
+
* @fires ['change', 'changeValidity', 'reset', 'reload', 'save', 'delete', 'undelete', 'destroy']
|
|
27
27
|
*/
|
|
28
28
|
class Entity extends EventEmitter {
|
|
29
29
|
|
|
@@ -322,7 +322,7 @@ class Entity extends EventEmitter {
|
|
|
322
322
|
}
|
|
323
323
|
|
|
324
324
|
/**
|
|
325
|
-
*
|
|
325
|
+
* Creates an exact copy of this Entity in its current state.
|
|
326
326
|
* @return {object} Entity - The clone
|
|
327
327
|
* @memberOf Entity
|
|
328
328
|
*/
|
|
@@ -338,6 +338,28 @@ 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
|
+
|
|
341
363
|
/**
|
|
342
364
|
* Resets the Entity to a state as if it had just been created,
|
|
343
365
|
* Gets data to restore from _originalData.
|
package/src/OneHatData.js
CHANGED
|
@@ -12,6 +12,9 @@ import {
|
|
|
12
12
|
default as Schema,
|
|
13
13
|
CoreSchemas,
|
|
14
14
|
} from './Schema/index.js';
|
|
15
|
+
import {
|
|
16
|
+
v4 as uuid,
|
|
17
|
+
} from 'uuid';
|
|
15
18
|
import _ from 'lodash';
|
|
16
19
|
|
|
17
20
|
/**
|
|
@@ -443,7 +446,7 @@ export class OneHatData extends EventEmitter {
|
|
|
443
446
|
* @param {string} name - Name of Schema
|
|
444
447
|
* @return {Repository} repository
|
|
445
448
|
*/
|
|
446
|
-
getRepository = (name) => {
|
|
449
|
+
getRepository = (name, unique = false) => {
|
|
447
450
|
if (this.isDestroyed) {
|
|
448
451
|
throw new Error('this.getRepository is no longer valid. OneHatData has been destroyed.');
|
|
449
452
|
}
|
|
@@ -451,6 +454,16 @@ export class OneHatData extends EventEmitter {
|
|
|
451
454
|
if (!schema) {
|
|
452
455
|
return null;
|
|
453
456
|
}
|
|
457
|
+
if (unique) {
|
|
458
|
+
const
|
|
459
|
+
repoToClone = schema.getBoundRepository(),
|
|
460
|
+
clone = _.cloneDeep(repoToClone);
|
|
461
|
+
|
|
462
|
+
const id = uuid();
|
|
463
|
+
clone.name = clone.name + '-' + id;
|
|
464
|
+
clone.id = id;
|
|
465
|
+
return clone;
|
|
466
|
+
}
|
|
454
467
|
return schema.getBoundRepository();
|
|
455
468
|
}
|
|
456
469
|
|
package/src/Property/Property.js
CHANGED
|
@@ -8,7 +8,7 @@ import _ from 'lodash';
|
|
|
8
8
|
* This class should not be instantiated directly.
|
|
9
9
|
* Rather, instantiate a subclass, like StringProperty
|
|
10
10
|
* @extends EventEmitter
|
|
11
|
-
* @fires ['change', 'destroy']
|
|
11
|
+
* @fires ['change', 'changeValidity', 'destroy']
|
|
12
12
|
*/
|
|
13
13
|
export default class Property extends EventEmitter {
|
|
14
14
|
|
|
@@ -184,7 +184,11 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
if (this.isLoaded && this.autoLoad) {
|
|
187
|
-
return this.reload()
|
|
187
|
+
return this.reload().then(() => {
|
|
188
|
+
this.emit('changeSorters');
|
|
189
|
+
});
|
|
190
|
+
} else {
|
|
191
|
+
this.emit('changeSorters');
|
|
188
192
|
}
|
|
189
193
|
}
|
|
190
194
|
|
|
@@ -528,10 +528,10 @@ export default class Repository extends EventEmitter {
|
|
|
528
528
|
});
|
|
529
529
|
|
|
530
530
|
this.sorters = sorters;
|
|
531
|
-
this.emit('changeSorters');
|
|
532
531
|
if (this._onChangeSorters) {
|
|
533
532
|
return this._onChangeSorters();
|
|
534
533
|
}
|
|
534
|
+
this.emit('changeSorters');
|
|
535
535
|
}
|
|
536
536
|
return isChanged;
|
|
537
537
|
}
|