@acodeninja/persist 3.0.0-next.3 → 3.0.0-next.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 +1 -1
- package/src/engine/StorageEngine.js +30 -2
package/package.json
CHANGED
@@ -95,7 +95,8 @@ export default class StorageEngine {
|
|
95
95
|
/**
|
96
96
|
* Get a model by its id
|
97
97
|
* @param {string} modelId
|
98
|
-
* @
|
98
|
+
* @throws {ModelNotFoundStorageEngineError}
|
99
|
+
* @return {Promise<Type.Model>}
|
99
100
|
*/
|
100
101
|
get(modelId) {
|
101
102
|
try {
|
@@ -106,6 +107,21 @@ export default class StorageEngine {
|
|
106
107
|
return this._getModel(modelId);
|
107
108
|
}
|
108
109
|
|
110
|
+
/**
|
111
|
+
*
|
112
|
+
* @param {Type.Model} model
|
113
|
+
* @throws {ModelNotRegisteredStorageEngineError}
|
114
|
+
* @throws {ModelNotFoundStorageEngineError}
|
115
|
+
*/
|
116
|
+
async delete(model) {
|
117
|
+
if (!Object.keys(this.models).includes(model.constructor.name))
|
118
|
+
throw new ModelNotRegisteredStorageEngineError(model, this);
|
119
|
+
|
120
|
+
const currentModel = await this.get(model.id);
|
121
|
+
|
122
|
+
await this._deleteModel(currentModel.id);
|
123
|
+
}
|
124
|
+
|
109
125
|
/**
|
110
126
|
* Get the model constructor from a model id
|
111
127
|
* @param {string} modelId
|
@@ -180,12 +196,23 @@ export default class StorageEngine {
|
|
180
196
|
* @param {string} _id
|
181
197
|
* @throws MethodNotImplementedStorageEngineError
|
182
198
|
* @throws ModelNotFoundStorageEngineError
|
183
|
-
* @return Promise<
|
199
|
+
* @return Promise<Model>
|
184
200
|
*/
|
185
201
|
_getModel(_id) {
|
186
202
|
return Promise.reject(new MethodNotImplementedStorageEngineError('_getModel', this));
|
187
203
|
}
|
188
204
|
|
205
|
+
/**
|
206
|
+
* Delete a model
|
207
|
+
* @param {string} _id
|
208
|
+
* @throws MethodNotImplementedStorageEngineError
|
209
|
+
* @throws ModelNotFoundStorageEngineError
|
210
|
+
* @return Promise<void>
|
211
|
+
*/
|
212
|
+
_deleteModel(_id) {
|
213
|
+
return Promise.reject(new MethodNotImplementedStorageEngineError('_deleteModel', this));
|
214
|
+
}
|
215
|
+
|
189
216
|
/**
|
190
217
|
* Get a model's index data
|
191
218
|
* @param {Model.constructor} _modelConstructor
|
@@ -239,6 +266,7 @@ export default class StorageEngine {
|
|
239
266
|
}
|
240
267
|
}
|
241
268
|
|
269
|
+
|
242
270
|
/**
|
243
271
|
* Decide if two models indexable fields have changed
|
244
272
|
* @param {Type.Model} currentModel
|