@onehat/data 1.7.3 → 1.7.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/package.json
CHANGED
|
@@ -1183,6 +1183,49 @@ export default class Repository extends EventEmitter {
|
|
|
1183
1183
|
});
|
|
1184
1184
|
}
|
|
1185
1185
|
|
|
1186
|
+
/**
|
|
1187
|
+
* Gets the Schema object
|
|
1188
|
+
* @return {Schema} schema
|
|
1189
|
+
*/
|
|
1190
|
+
getSchema = () => {
|
|
1191
|
+
if (this.isDestroyed) {
|
|
1192
|
+
throw Error('this.getSchema is no longer valid. Entity has been destroyed.');
|
|
1193
|
+
}
|
|
1194
|
+
return this.schema;
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
/**
|
|
1198
|
+
* Gets the associated Repository
|
|
1199
|
+
* @param {string} repositoryName - Name of the Repository to retrieve
|
|
1200
|
+
* @return {boolean} hasProperty
|
|
1201
|
+
*/
|
|
1202
|
+
getAssociatedRepository = (repositoryName) => {
|
|
1203
|
+
if (this.isDestroyed) {
|
|
1204
|
+
throw Error('this.getAssociatedRepository is no longer valid. Entity has been destroyed.');
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
const schema = this.getSchema();
|
|
1208
|
+
if (!schema.model.associations.hasOne.includes(repositoryName) &&
|
|
1209
|
+
!schema.model.associations.hasMany.includes(repositoryName) &&
|
|
1210
|
+
!schema.model.associations.belongsTo.includes(repositoryName) &&
|
|
1211
|
+
!schema.model.associations.belongsToMany.includes(repositoryName)
|
|
1212
|
+
) {
|
|
1213
|
+
throw Error(repositoryName + ' is not associated with this schema');
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
const oneHatData = this.oneHatData;
|
|
1217
|
+
if (!oneHatData) {
|
|
1218
|
+
throw Error('No global oneHatData object');
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
const associatedRepository = oneHatData.getRepository(repositoryName);
|
|
1222
|
+
if (!associatedRepository) {
|
|
1223
|
+
throw Error('Repository ' + repositoryName + ' cannot be found');
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
return associatedRepository;
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1186
1229
|
/**
|
|
1187
1230
|
* Utility function.
|
|
1188
1231
|
* Detects if entity is in the current page of the storage medium.
|