@onehat/data 1.8.28 → 1.8.30

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.
@@ -25,4 +25,9 @@ describe('Schema', function() {
25
25
  expect(_.isEqual(clone._originalConfig, this.schema._originalConfig)).to.be.true;
26
26
  });
27
27
 
28
+ it('getProperty', function() {
29
+ const property = this.schema.getProperty('groups_users__id');
30
+ expect(_.isEqual(property.name, 'groups_users__id')).to.be.true;
31
+ });
32
+
28
33
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/data",
3
- "version": "1.8.28",
3
+ "version": "1.8.30",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -181,6 +181,24 @@ export default class Schema extends EventEmitter {
181
181
  this._boundRepository = null;
182
182
  }
183
183
 
184
+ /**
185
+ * Gets a single Property definition by name,
186
+ * @param {string} propertyName - Name of the Property to retrieve
187
+ * @return {object} property - The named Property
188
+ */
189
+ getProperty = (propertyName) => {
190
+ if (this.isDestroyed) {
191
+ throw Error('this.getProperty is no longer valid. Schema has been destroyed.');
192
+ }
193
+ const property = _.find(this.model.properties, (propertyDefinition) => {
194
+ return propertyDefinition.name === propertyName;
195
+ });
196
+ if (!property) {
197
+ throw new Error('Property ' + propertyName + ' not found. Are you sure you initialized this Entity?');
198
+ }
199
+ return property;
200
+ }
201
+
184
202
  /**
185
203
  * Clones this Schema.
186
204
  * @return {object} Schema - The clone