@onehat/data 1.9.2 → 1.9.3
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.
|
@@ -12,6 +12,15 @@ async function beforeEach() {
|
|
|
12
12
|
this.oneHatData = new OneHatData();
|
|
13
13
|
this.schema = this.oneHatData.createSchema({
|
|
14
14
|
name: 'bar',
|
|
15
|
+
model: {
|
|
16
|
+
idProperty: 'key',
|
|
17
|
+
displayProperty: 'value',
|
|
18
|
+
properties: [
|
|
19
|
+
{ name: 'key', },
|
|
20
|
+
{ name: 'value', },
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
repository: 'memory',
|
|
15
24
|
});
|
|
16
25
|
await this.oneHatData.createRepository({
|
|
17
26
|
id: 'foo',
|
|
@@ -334,6 +343,23 @@ describe('OneHatData', function() {
|
|
|
334
343
|
})();
|
|
335
344
|
});
|
|
336
345
|
|
|
346
|
+
it('isEntity', async function() {
|
|
347
|
+
(async function() {
|
|
348
|
+
debugger;
|
|
349
|
+
await beforeEach();
|
|
350
|
+
const oneHatData = this.oneHatData;
|
|
351
|
+
const repository = oneHatData.getRepository('bar');
|
|
352
|
+
const entity = await repository.add({ key: 1, value: 'value', });
|
|
353
|
+
|
|
354
|
+
expect(isEntity(entity)).to.be.true;
|
|
355
|
+
expect(isEntity({})).to.be.false;
|
|
356
|
+
expect(isEntity(2)).to.be.false;
|
|
357
|
+
expect(isEntity([1,2])).to.be.false;
|
|
358
|
+
|
|
359
|
+
afterEach();
|
|
360
|
+
})();
|
|
361
|
+
});
|
|
362
|
+
|
|
337
363
|
it('destroy', function() {
|
|
338
364
|
(async function() {
|
|
339
365
|
await beforeEach();
|
package/package.json
CHANGED
package/src/OneHatData.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import EventEmitter from '@onehat/events';
|
|
4
4
|
import CoreRepositoryTypes from './Repository/index.js';
|
|
5
|
+
import Entity from './Entity.js';
|
|
5
6
|
import {
|
|
6
7
|
MODE_LOCAL_MIRROR,
|
|
7
8
|
MODE_COMMAND_QUEUE,
|
|
@@ -620,6 +621,24 @@ export class OneHatData extends EventEmitter {
|
|
|
620
621
|
return this;
|
|
621
622
|
}
|
|
622
623
|
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
// _ __ ___ __ __
|
|
628
|
+
// | | / /___ _/ (_)___/ /___ _/ /____
|
|
629
|
+
// | | / / __ `/ / / __ / __ `/ __/ _ \
|
|
630
|
+
// | |/ / /_/ / / / /_/ / /_/ / /_/ __/
|
|
631
|
+
// |___/\__,_/_/_/\__,_/\__,_/\__/\___/
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* Determines if submitted object is an entity
|
|
635
|
+
* @return boolean
|
|
636
|
+
*/
|
|
637
|
+
isEntity = (obj) => {
|
|
638
|
+
return obj?.__proto__?.constructor === Entity;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
|
|
623
642
|
/**
|
|
624
643
|
* Destroy this object.
|
|
625
644
|
* - Removes child objects
|
package/src/Schema/KeyValues.js
CHANGED