@onehat/data 1.7.12 → 1.7.14
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/package.json +1 -1
- package/src/Repository/Repository.js +17 -43
package/package.json
CHANGED
|
@@ -266,6 +266,7 @@ export default class Repository extends EventEmitter {
|
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
this._createMethods();
|
|
269
|
+
this._createStatics();
|
|
269
270
|
|
|
270
271
|
if (this.schema.repository.init) {
|
|
271
272
|
await this.schema.repository.init.call(this);
|
|
@@ -291,6 +292,22 @@ export default class Repository extends EventEmitter {
|
|
|
291
292
|
}
|
|
292
293
|
}
|
|
293
294
|
|
|
295
|
+
/**
|
|
296
|
+
* Creates the static properties for this Repository, based on Schema.
|
|
297
|
+
* @private
|
|
298
|
+
*/
|
|
299
|
+
_createStatics = () => {
|
|
300
|
+
if (this.isDestroyed) {
|
|
301
|
+
throw Error('this._createStatics is no longer valid. Entity has been destroyed.');
|
|
302
|
+
}
|
|
303
|
+
const staticsDefinitions = this.schema.repository.statics;
|
|
304
|
+
if (!_.isEmpty(staticsDefinitions)) {
|
|
305
|
+
_.each(staticsDefinitions, (value, key) => {
|
|
306
|
+
this[key] = value;
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
294
311
|
|
|
295
312
|
// __ __
|
|
296
313
|
// / / ____ ____ _____/ /
|
|
@@ -1255,49 +1272,6 @@ export default class Repository extends EventEmitter {
|
|
|
1255
1272
|
return associatedRepository;
|
|
1256
1273
|
}
|
|
1257
1274
|
|
|
1258
|
-
/**
|
|
1259
|
-
* Gets the Schema object
|
|
1260
|
-
* @return {Schema} schema
|
|
1261
|
-
*/
|
|
1262
|
-
getSchema = () => {
|
|
1263
|
-
if (this.isDestroyed) {
|
|
1264
|
-
throw Error('this.getSchema is no longer valid. Entity has been destroyed.');
|
|
1265
|
-
}
|
|
1266
|
-
return this.schema;
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
/**
|
|
1270
|
-
* Gets the associated Repository
|
|
1271
|
-
* @param {string} repositoryName - Name of the Repository to retrieve
|
|
1272
|
-
* @return {boolean} hasProperty
|
|
1273
|
-
*/
|
|
1274
|
-
getAssociatedRepository = (repositoryName) => {
|
|
1275
|
-
if (this.isDestroyed) {
|
|
1276
|
-
throw Error('this.getAssociatedRepository is no longer valid. Entity has been destroyed.');
|
|
1277
|
-
}
|
|
1278
|
-
|
|
1279
|
-
const schema = this.getSchema();
|
|
1280
|
-
if (!schema.model.associations.hasOne.includes(repositoryName) &&
|
|
1281
|
-
!schema.model.associations.hasMany.includes(repositoryName) &&
|
|
1282
|
-
!schema.model.associations.belongsTo.includes(repositoryName) &&
|
|
1283
|
-
!schema.model.associations.belongsToMany.includes(repositoryName)
|
|
1284
|
-
) {
|
|
1285
|
-
throw Error(repositoryName + ' is not associated with this schema');
|
|
1286
|
-
}
|
|
1287
|
-
|
|
1288
|
-
const oneHatData = this.oneHatData;
|
|
1289
|
-
if (!oneHatData) {
|
|
1290
|
-
throw Error('No global oneHatData object');
|
|
1291
|
-
}
|
|
1292
|
-
|
|
1293
|
-
const associatedRepository = oneHatData.getRepository(repositoryName);
|
|
1294
|
-
if (!associatedRepository) {
|
|
1295
|
-
throw Error('Repository ' + repositoryName + ' cannot be found');
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
|
-
return associatedRepository;
|
|
1299
|
-
}
|
|
1300
|
-
|
|
1301
1275
|
/**
|
|
1302
1276
|
* Utility function.
|
|
1303
1277
|
* Detects if entity is in the current page of the storage medium.
|