@onehat/data 1.6.4 → 1.6.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.
@@ -10,8 +10,9 @@ describe('Schema', function() {
10
10
  it('schema is valid', function() {
11
11
  expect(this.schema instanceof Schema).to.be.true;
12
12
  expect(this.schema.name).to.be.eq('GroupsUsers');
13
- expect(this.schema.repository.type).to.be.eq('onebuild');
13
+ expect(this.schema.model.associations.hasOne).to.be.an('array');
14
14
  expect(this.schema.entity.methods.testMethod).to.be.a('function');
15
+ expect(this.schema.repository.type).to.be.eq('onebuild');
15
16
  });
16
17
 
17
18
  it('clone', function() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/data",
3
- "version": "1.6.4",
3
+ "version": "1.6.5",
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
@@ -851,6 +851,31 @@ class Entity extends EventEmitter {
851
851
  return this._originalData;
852
852
  }
853
853
 
854
+ /**
855
+ * Gets the associated Repository
856
+ * @param {string} repositoryName - Name of the Repository to retrieve
857
+ * @return {boolean} hasProperty
858
+ */
859
+ getAssociatedRepository = (repositoryName) => {
860
+ if (this.isDestroyed) {
861
+ throw Error('this.getAssociatedRepository is no longer valid. Entity has been destroyed.');
862
+ }
863
+
864
+ const schema = this.getSchema();
865
+ if (!schema.associations.hasOne.includes(repositoryName) &&
866
+ !schema.associations.hasMany.includes(repositoryName) &&
867
+ !schema.associations.belongsTo.includes(repositoryName) &&
868
+ !schema.associations.belongsToMany.includes(repositoryName)
869
+ ) {
870
+ throw Error(repositoryName + ' is not associated with ' + this.getRepository().name);
871
+ }
872
+ const repository = this.getRepository();
873
+ if (!repository.oneHatData) {
874
+ throw Error('No global oneHatData object');
875
+ }
876
+ return repository.oneHatData.getRepository(repositoryName);
877
+ }
878
+
854
879
 
855
880
 
856
881
  // _____ __ __
package/src/OneHatData.js CHANGED
@@ -254,8 +254,8 @@ export class OneHatData extends EventEmitter {
254
254
  }
255
255
 
256
256
  // Apply the general config settings to each specific one
257
- const localConfig = _.assign({}, generalConfig, config.local),
258
- remoteConfig = _.assign({}, generalConfig, config.remote);
257
+ const localConfig = _.merge({}, generalConfig, config.local),
258
+ remoteConfig = _.merge({}, generalConfig, config.remote);
259
259
 
260
260
  // Actually create the local and remote repositories
261
261
  config.local = await this.createRepository(localConfig);
@@ -263,7 +263,7 @@ export class OneHatData extends EventEmitter {
263
263
  }
264
264
 
265
265
  const Repository = this._repositoryTypes[config.type],
266
- repository = new Repository(config);
266
+ repository = new Repository(config, this);
267
267
  await repository.initialize();
268
268
 
269
269
  return repository;
@@ -370,7 +370,7 @@ class AjaxRepository extends Repository {
370
370
  }
371
371
 
372
372
  const repository = this;
373
- const data = _.assign({}, this._baseParams, this._params);
373
+ const data = _.merge({}, this._baseParams, this._params);
374
374
 
375
375
  return this._send(this.methods.get, this.api.get, data)
376
376
  .then(result => {
@@ -23,7 +23,7 @@ export default class Repository extends EventEmitter {
23
23
  * - name {string} - Optional. Defaults to schema.name
24
24
  * - schema - Schema object
25
25
  */
26
- constructor(config = {}) {
26
+ constructor(config = {}, oneHatData = null) {
27
27
  super(...arguments);
28
28
 
29
29
  const { schema } = config;
@@ -214,6 +214,11 @@ export default class Repository extends EventEmitter {
214
214
  */
215
215
  this.isDestroyed = false;
216
216
 
217
+ /**
218
+ * @member {boolean} oneHatData - The global @onehat/data object
219
+ */
220
+ this.oneHatData = oneHatData;
221
+
217
222
  this.registerEvents([
218
223
  'add',
219
224
  'beforeSave',
@@ -109,7 +109,7 @@ export default class Schema extends EventEmitter {
109
109
 
110
110
  };
111
111
 
112
- this._originalConfig = _.assign({}, defaults, config);
112
+ this._originalConfig = _.merge({}, defaults, config);
113
113
  _.merge(this, this._originalConfig);
114
114
 
115
115
  /**