This commit is contained in:
eric sciple 2020-01-24 12:21:24 -05:00
parent fc725ba36b
commit 422b9fdb15
7395 changed files with 1786235 additions and 3476 deletions

20
node_modules/map-age-cleaner/dist/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,20 @@
interface Entry {
[key: string]: any;
}
interface MaxAgeEntry extends Entry {
maxAge: number;
}
/**
* Automatically cleanup the items in the provided `map`. The property of the expiration timestamp should be named `maxAge`.
*
* @param map - Map instance which should be cleaned up.
*/
export default function mapAgeCleaner<K = any, V extends MaxAgeEntry = MaxAgeEntry>(map: Map<K, V>): any;
/**
* Automatically cleanup the items in the provided `map`.
*
* @param map - Map instance which should be cleaned up.
* @param property - Name of the property which olds the expiry timestamp.
*/
export default function mapAgeCleaner<K = any, V = Entry>(map: Map<K, V>, property: string): any;
export {};

92
node_modules/map-age-cleaner/dist/index.js generated vendored Normal file
View file

@ -0,0 +1,92 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const p_defer_1 = __importDefault(require("p-defer"));
function mapAgeCleaner(map, property = 'maxAge') {
let processingKey;
let processingTimer;
let processingDeferred;
const cleanup = () => __awaiter(this, void 0, void 0, function* () {
if (processingKey !== undefined) {
// If we are already processing an item, we can safely exit
return;
}
const setupTimer = (item) => __awaiter(this, void 0, void 0, function* () {
processingDeferred = p_defer_1.default();
const delay = item[1][property] - Date.now();
if (delay <= 0) {
// Remove the item immediately if the delay is equal to or below 0
map.delete(item[0]);
processingDeferred.resolve();
return;
}
// Keep track of the current processed key
processingKey = item[0];
processingTimer = setTimeout(() => {
// Remove the item when the timeout fires
map.delete(item[0]);
if (processingDeferred) {
processingDeferred.resolve();
}
}, delay);
// tslint:disable-next-line:strict-type-predicates
if (typeof processingTimer.unref === 'function') {
// Don't hold up the process from exiting
processingTimer.unref();
}
return processingDeferred.promise;
});
try {
for (const entry of map) {
yield setupTimer(entry);
}
}
catch (_a) {
// Do nothing if an error occurs, this means the timer was cleaned up and we should stop processing
}
processingKey = undefined;
});
const reset = () => {
processingKey = undefined;
if (processingTimer !== undefined) {
clearTimeout(processingTimer);
processingTimer = undefined;
}
if (processingDeferred !== undefined) { // tslint:disable-line:early-exit
processingDeferred.reject(undefined);
processingDeferred = undefined;
}
};
const originalSet = map.set.bind(map);
map.set = (key, value) => {
if (map.has(key)) {
// If the key already exist, remove it so we can add it back at the end of the map.
map.delete(key);
}
// Call the original `map.set`
const result = originalSet(key, value);
// If we are already processing a key and the key added is the current processed key, stop processing it
if (processingKey && processingKey === key) {
reset();
}
// Always run the cleanup method in case it wasn't started yet
cleanup(); // tslint:disable-line:no-floating-promises
return result;
};
cleanup(); // tslint:disable-line:no-floating-promises
return map;
}
exports.default = mapAgeCleaner;
// Add support for CJS
module.exports = mapAgeCleaner;
module.exports.default = mapAgeCleaner;

9
node_modules/map-age-cleaner/license generated vendored Normal file
View file

@ -0,0 +1,9 @@
MIT License
Copyright (c) Sam Verschueren <sam.verschueren@gmail.com> (github.com/SamVerschueren)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

63
node_modules/map-age-cleaner/package.json generated vendored Normal file
View file

@ -0,0 +1,63 @@
{
"name": "map-age-cleaner",
"version": "0.1.3",
"description": "Automatically cleanup expired items in a Map",
"license": "MIT",
"repository": "SamVerschueren/map-age-cleaner",
"author": {
"name": "Sam Verschueren",
"email": "sam.verschueren@gmail.com",
"url": "github.com/SamVerschueren"
},
"main": "dist/index.js",
"engines": {
"node": ">=6"
},
"scripts": {
"prepublishOnly": "npm run build",
"pretest": "npm run build -- --sourceMap",
"test": "npm run lint && nyc ava dist/test.js",
"lint": "tslint --format stylish --project .",
"build": "npm run clean && tsc",
"clean": "del-cli dist"
},
"files": [
"dist/index.js",
"dist/index.d.ts"
],
"keywords": [
"map",
"age",
"cleaner",
"maxage",
"expire",
"expiration",
"expiring"
],
"dependencies": {
"p-defer": "^1.0.0"
},
"devDependencies": {
"@types/delay": "^2.0.1",
"@types/node": "^10.7.1",
"ava": "^0.25.0",
"codecov": "^3.0.0",
"del-cli": "^1.1.0",
"delay": "^3.0.0",
"nyc": "^12.0.0",
"tslint": "^5.11.0",
"tslint-xo": "^0.9.0",
"typescript": "^3.0.1"
},
"typings": "dist/index.d.ts",
"sideEffects": false,
"nyc": {
"exclude": [
"dist/test.js"
]
}
,"_resolved": "https://registry.npmjs.org/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz"
,"_integrity": "sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w=="
,"_from": "map-age-cleaner@0.1.3"
}

67
node_modules/map-age-cleaner/readme.md generated vendored Normal file
View file

@ -0,0 +1,67 @@
# map-age-cleaner
[![Build Status](https://travis-ci.org/SamVerschueren/map-age-cleaner.svg?branch=master)](https://travis-ci.org/SamVerschueren/map-age-cleaner) [![codecov](https://codecov.io/gh/SamVerschueren/map-age-cleaner/badge.svg?branch=master)](https://codecov.io/gh/SamVerschueren/map-age-cleaner?branch=master)
> Automatically cleanup expired items in a Map
## Install
```
$ npm install map-age-cleaner
```
## Usage
```js
import mapAgeCleaner from 'map-age-cleaner';
const map = new Map([
['unicorn', {data: '🦄', maxAge: Date.now() + 1000}]
]);
mapAgeCleaner(map);
map.has('unicorn');
//=> true
// Wait for 1 second...
map.has('unicorn');
//=> false
```
> **Note**: Items have to be ordered ascending based on the expiry property. This means that the item which will be expired first, should be in the first position of the `Map`.
## API
### mapAgeCleaner(map, [property])
Returns the `Map` instance.
#### map
Type: `Map`
Map instance which should be cleaned up.
#### property
Type: `string`<br>
Default: `maxAge`
Name of the property which olds the expiry timestamp.
## Related
- [expiry-map](https://github.com/SamVerschueren/expiry-map) - A `Map` implementation with expirable items
- [expiry-set](https://github.com/SamVerschueren/expiry-set) - A `Set` implementation with expirable keys
- [mem](https://github.com/sindresorhus/mem) - Memoize functions
## License
MIT © [Sam Verschueren](https://github.com/SamVerschueren)