@onehat/data 1.10.3 → 1.10.4
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/OneHatData.spec.js +25 -11
- package/package.json +1 -1
- package/src/Entity.js +1 -1
- package/src/OneHatData.js +14 -1
- package/src/Property/Property.js +1 -1
|
@@ -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.only('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
|
|
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
|
|