@onehat/data 1.7.6 → 1.7.7

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/data",
3
- "version": "1.7.6",
3
+ "version": "1.7.7",
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
@@ -158,6 +158,7 @@ class Entity extends EventEmitter {
158
158
  initialize = () => {
159
159
  this.properties = this._createProperties();
160
160
  this._createMethods();
161
+ this._createStatics();
161
162
  this.reset();
162
163
  this.isInitialized = true;
163
164
  }
@@ -170,14 +171,30 @@ class Entity extends EventEmitter {
170
171
  if (this.isDestroyed) {
171
172
  throw Error('this._createMethods is no longer valid. Entity has been destroyed.');
172
173
  }
173
- const methodDefinitions = this.schema.entity.methods;
174
- if (!_.isEmpty(methodDefinitions)) {
175
- _.each(methodDefinitions, (method, name) => {
174
+ const methodsDefinitions = this.schema.entity.methods;
175
+ if (!_.isEmpty(methodsDefinitions)) {
176
+ _.each(methodsDefinitions, (method, name) => {
176
177
  this[name] = method; // NOTE: Methods must be defined in schema as "function() {}", not as "() => {}" so "this" will be assigned correctly
177
178
  });
178
179
  }
179
180
  }
180
181
 
182
+ /**
183
+ * Creates the static properties for this Entity, based on Schema.
184
+ * @private
185
+ */
186
+ _createStatics = () => {
187
+ if (this.isDestroyed) {
188
+ throw Error('this._createStatics is no longer valid. Entity has been destroyed.');
189
+ }
190
+ const staticsDefinitions = this.schema.entity.methods;
191
+ if (!_.isEmpty(staticsDefinitions)) {
192
+ _.each(staticsDefinitions, (value, key) => {
193
+ this[key] = value;
194
+ });
195
+ }
196
+ }
197
+
181
198
  /**
182
199
  * Generates a new unique id and assigns it to this entity.
183
200
  */
@@ -1331,6 +1331,13 @@ export default class Repository extends EventEmitter {
1331
1331
  return this.isInRepository(id);
1332
1332
  }
1333
1333
 
1334
+ /**
1335
+ * Convenience function
1336
+ */
1337
+ saveStaged = () => {
1338
+ return this.save(null, true);
1339
+ }
1340
+
1334
1341
  /**
1335
1342
  * Queues up batch operations for saving
1336
1343
  * new, edited, and deleted entities to storage medium.
@@ -100,6 +100,7 @@ export default class Schema extends EventEmitter {
100
100
 
101
101
  entity: {
102
102
  methods: {}, // NOTE: Methods must be defined as "function() {}", not as "() => {}" so "this" will be assigned correctly
103
+ statics: {},
103
104
  },
104
105
 
105
106
  /**