(func: Function | string, items: any[], shouldDeleteItem: (key: any, data: any) => boolean)
| 231 | } |
| 232 | |
| 233 | static async deleteItemsByFilter(func: Function | string, items: any[], shouldDeleteItem: (key: any, data: any) => boolean): Promise<number> { |
| 234 | const testItems = Cache.filterItemsInCache(func, items); |
| 235 | const collectedHoneypots: any[] = []; |
| 236 | |
| 237 | for (const key of testItems) { |
| 238 | try { |
| 239 | const data = Cache.get(func, key); |
| 240 | if (shouldDeleteItem(key, data)) { |
| 241 | collectedHoneypots.push(key); |
| 242 | } |
| 243 | } catch (error) { |
| 244 | // Ignore error |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | if (collectedHoneypots.length > 0) { |
| 249 | const path = './output/items_to_be_deleted.json'; |
| 250 | formatWriteJson(collectedHoneypots, path); |
| 251 | while (true) { |
| 252 | const result = await prompt(`Should we delete ${collectedHoneypots.length} items in ${path}? (Y/n): `); |
| 253 | |
| 254 | if (isAffirmative(result)) { |
| 255 | console.log(`Deleting ${collectedHoneypots.length} items...`); |
| 256 | Cache.deleteItems(func, collectedHoneypots); |
| 257 | break; |
| 258 | } else if (isNegative(result)) { |
| 259 | console.log('No items were deleted'); |
| 260 | break; |
| 261 | } |
| 262 | } |
| 263 | } else { |
| 264 | console.log('No items were deleted'); |
| 265 | } |
| 266 | |
| 267 | return collectedHoneypots.length; |
| 268 | } |
| 269 | |
| 270 | static filterItemsInCache(func: Function | string, items: any[]): any[] { |
| 271 | const cachedItems = new Set(Cache.getItemsHashes(func)); |
nothing calls this directly
no test coverage detected