@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 +1 -1
- package/src/provider/file.ts +11 -1
- package/src/provider/memory.ts +12 -1
package/package.json
CHANGED
package/src/provider/file.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
package/src/provider/memory.ts
CHANGED
|
@@ -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
|
-
|
|
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
|