@acodeninja/persist 3.0.0-next.3 → 3.0.0-next.5
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 +34 -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,25 @@ 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
|
+
const currentIndex = this._getIndex(currentModel.constructor);
|
125
|
+
|
126
|
+
await this._putIndex(currentModel.constructor, _.omit(currentIndex, [currentModel.id]));
|
127
|
+
}
|
128
|
+
|
109
129
|
/**
|
110
130
|
* Get the model constructor from a model id
|
111
131
|
* @param {string} modelId
|
@@ -180,12 +200,23 @@ export default class StorageEngine {
|
|
180
200
|
* @param {string} _id
|
181
201
|
* @throws MethodNotImplementedStorageEngineError
|
182
202
|
* @throws ModelNotFoundStorageEngineError
|
183
|
-
* @return Promise<
|
203
|
+
* @return Promise<Model>
|
184
204
|
*/
|
185
205
|
_getModel(_id) {
|
186
206
|
return Promise.reject(new MethodNotImplementedStorageEngineError('_getModel', this));
|
187
207
|
}
|
188
208
|
|
209
|
+
/**
|
210
|
+
* Delete a model
|
211
|
+
* @param {string} _id
|
212
|
+
* @throws MethodNotImplementedStorageEngineError
|
213
|
+
* @throws ModelNotFoundStorageEngineError
|
214
|
+
* @return Promise<void>
|
215
|
+
*/
|
216
|
+
_deleteModel(_id) {
|
217
|
+
return Promise.reject(new MethodNotImplementedStorageEngineError('_deleteModel', this));
|
218
|
+
}
|
219
|
+
|
189
220
|
/**
|
190
221
|
* Get a model's index data
|
191
222
|
* @param {Model.constructor} _modelConstructor
|
@@ -239,6 +270,7 @@ export default class StorageEngine {
|
|
239
270
|
}
|
240
271
|
}
|
241
272
|
|
273
|
+
|
242
274
|
/**
|
243
275
|
* Decide if two models indexable fields have changed
|
244
276
|
* @param {Type.Model} currentModel
|