@travetto/model 4.1.3 → 4.1.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model",
3
- "version": "4.1.3",
3
+ "version": "4.1.4",
4
4
  "description": "Datastore abstraction for core operations.",
5
5
  "keywords": [
6
6
  "datastore",
@@ -221,7 +221,17 @@ export class FileModelService implements ModelCrudSupport, ModelStreamSupport, M
221
221
 
222
222
  // Expiry
223
223
  async deleteExpired<T extends ModelType>(cls: Class<T>): Promise<number> {
224
- return ModelExpiryUtil.naiveDeleteExpired(this, cls);
224
+ let deleted = 0;
225
+ for await (const [_id, file] of FileModelService.scanFolder(await this.#resolveName(cls, '.json'), '.json')) {
226
+ try {
227
+ const res = await ModelCrudUtil.load(cls, await fs.readFile(file));
228
+ if (ModelExpiryUtil.getExpiryState(cls, res).expired) {
229
+ await fs.rm(file, { force: true });
230
+ deleted += 1;
231
+ }
232
+ } catch { } // Don't let a single failure stop the process
233
+ }
234
+ return deleted;
225
235
  }
226
236
 
227
237
  // Storage management
@@ -281,7 +281,18 @@ export class MemoryModelService implements ModelCrudSupport, ModelStreamSupport,
281
281
 
282
282
  // Expiry
283
283
  async deleteExpired<T extends ModelType>(cls: Class<T>): Promise<number> {
284
- return ModelExpiryUtil.naiveDeleteExpired(this, cls);
284
+ const store = this.#getStore(cls);
285
+ let deleted = 0;
286
+ for (const key of [...store.keys()]) {
287
+ try {
288
+ const res = await ModelCrudUtil.load(cls, store.get(key)!);
289
+ if (ModelExpiryUtil.getExpiryState(cls, res).expired) {
290
+ store.delete(key);
291
+ deleted += 1;
292
+ }
293
+ } catch { } // Do not let a single error stop the process
294
+ }
295
+ return deleted;
285
296
  }
286
297
 
287
298
  // Storage Support