@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 +1 -1
- package/src/Entity.js +20 -3
- package/src/Repository/Repository.js +7 -0
- package/src/Schema/Schema.js +1 -0
package/package.json
CHANGED
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
|
|
174
|
-
if (!_.isEmpty(
|
|
175
|
-
_.each(
|
|
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.
|
package/src/Schema/Schema.js
CHANGED