first commit

This commit is contained in:
2026-03-10 16:18:05 +00:00
commit 11f9c069b5
31635 changed files with 3187747 additions and 0 deletions

15
node_modules/@isaacs/ttlcache/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,15 @@
The ISC License
Copyright (c) 2022-2023 - Isaac Z. Schlueter and Contributors
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

253
node_modules/@isaacs/ttlcache/README.md generated vendored Normal file
View File

@@ -0,0 +1,253 @@
# @isaacs/ttlcache
The time-based use-recency-unaware cousin of
[`lru-cache`](http://npm.im/lru-cache)
## Usage
Essentially, this is the same API as
[`lru-cache`](http://npm.im/lru-cache), but it does not do LRU tracking,
and is bound primarily by time, rather than space. Since entries are not
purged based on recency of use, it can save a lot of extra work managing
linked lists, mapping keys to pointers, and so on.
TTLs are millisecond granularity.
If a capacity limit is set, then the soonest-expiring items are purged
first, to bring it down to the size limit.
Iteration is in order from soonest expiring until latest expiring.
If multiple items are expiring in the same ms, then the soonest-added
items are considered "older" for purposes of iterating and purging down to
capacity.
A TTL _must_ be set for every entry, which can be defaulted in the
constructor.
Custom size calculation is not supported. Max capacity is simply the count
of items in the cache.
```js
const TTLCache = require('@isaacs/ttlcache')
const cache = new TTLCache({ max: 10000, ttl: 1000 })
// set some value
cache.set(1, 2)
// 999 ms later
cache.has(1) // returns true
cache.get(1) // returns 2
// 1000 ms later
cache.get(1) // returns undefined
cache.has(1) // returns false
```
## Caveat Regarding Timers and Graceful Exits
On Node.js, this module uses the `Timeout.unref()` method to
prevent its internal `setTimeout` calls from keeping the process
running indefinitely. However, on other systems such as Deno,
where the `setTimeout` method does not return an object with an
`unref()` method, the process will stay open as long as any
unexpired entry exists in the cache.
You may call `cache.cancelTimer()` to clear the timeout and
allow the process to exit normally. Be advised that canceling the
timer in this way will of course prevent anything from expiring.
## API
### `const TTLCache = require('@isaacs/ttlcache')` or `import TTLCache from '@isaacs/ttlcache'`
Default export is the `TTLCache` class.
### `new TTLCache({ ttl, max = Infinty, updateAgeOnGet = false, checkAgeOnGet = false, noUpdateTTL = false, noDisposeOnSet = false })`
Create a new `TTLCache` object.
* `max` The max number of items to keep in the cache. Must be
positive integer or `Infinity`, defaults to `Infinity` (ie,
limited only by TTL, not by item count).
* `ttl` The max time in ms to store items. Overridable on the `set()`
method. Must be a positive integer or `Infinity` (see note
below about immortality hazards). If `undefined` in
constructor, then a TTL _must_ be provided in each `set()`
call.
* `updateAgeOnGet` Should the age of an item be updated when it is
retrieved? Defaults to `false`. Overridable on the `get()` method.
* `checkAgeOnGet` Check the TTL whenever an item is retrieved
with `get()`. If the item is past its ttl, but the timer has
not yet fired, then delete it and return undefined. By default,
the cache will return a value if it has one, even if it is
technically beyond its TTL.
* `noUpdateTTL` Should setting a new value for an existing key leave the
TTL unchanged? Defaults to `false`. Overridable on the `set()` method.
(Note that TTL is _always_ updated if the item is expired, since that is
treated as a new `set()` and the old item is no longer relevant.)
* `dispose` Method called with `(value, key, reason)` when an item is
removed from the cache. Called once item is fully removed from cache.
It is safe to re-add at this point, but note that adding when `reason` is
`'set'` can result in infinite recursion if `noDisponseOnSet` is not
specified.
Disposal reasons:
* `'stale'` TTL expired.
* `'set'` Overwritten with a new different value.
* `'evict'` Removed from the cache to stay within capacity limit.
* `'delete'` Explicitly deleted with `cache.delete()` or
`cache.clear()`
* `noDisposeOnSet` Do not call `dispose()` method when overwriting a key
with a new value. Defaults to `false`. Overridable on `set()` method.
When used as an iterator, like `for (const [key, value] of cache)` or
`[...cache]`, the cache yields the same results as the `entries()` method.
### `cache.size`
The number of items in the cache.
### `cache.set(key, value, { ttl, noUpdateTTL, noDisposeOnSet } = {})`
Store a value in the cache for the specified time.
`ttl` and `noUpdateTTL` optionally override defaults on the constructor.
Returns the cache object.
### `cache.get(key, {updateAgeOnGet, checkAgeOnGet, ttl} = {})`
Get an item stored in the cache. Returns `undefined` if the item is not in
the cache (including if it has expired and been purged).
If `updateAgeOnGet` is `true`, then re-add the item into the
cache with the updated `ttl` value. All options default to the
settings on the constructor.
If `checkAgeOnGet`, then an item will be deleted if it is found
to be beyond its TTL, which can happen if the setTimeout timer
has not yet fired to trigger its expiration.
Note that using `updateAgeOnGet` _can_ effectively simulate a
"least-recently-used" type of algorithm, by repeatedly updating
the TTL of items as they are used. However, if you find yourself
doing this, consider using
[`lru-cache`](http://npm.im/lru-cache), as it is much more
optimized for an LRU use case.
### `cache.getRemainingTTL(key)`
Return the remaining time before an item expires. Returns `0` if the item
is not found in the cache or is already expired.
### `cache.has(key)`
Return true if the item is in the cache.
### `cache.delete(key)`
Remove an item from the cache.
### `cache.clear()`
Delete all items from the cache.
### `cache.entries()`
Return an iterator that walks through each `[key, value]` from soonest
expiring to latest expiring. (Items expiring at the same time are walked
in insertion order.)
Default iteration method for the cache object.
### `cache.keys()`
Return an iterator that walks through each `key` from soonest expiring to
latest expiring.
### `cache.values()`
Return an iterator that walks through each `value` from soonest expiring to
latest expiring.
### `cache.cancelTimer()`
Clear the internal timer, and stop automatically expiring items
when their TTL expires.
This allows the process to exit normally on Deno and other
platforms that lack Node's `Timer.unref()` method.
## Internal Methods
You should not ever call these, they are managed automatically.
### `purgeStale`
**Internal**
Removes items which have expired. Called automatically.
### `purgeToCapacity`
**Internal**
Removes soonest-expiring items when the capacity limit is reached. Called
automatically.
### `dispose`
**Internal**
Called when an item is removed from the cache and should be disposed. Set
this on the constructor options.
### `setTimer`
**Internal**
Called when an with a ttl is added. This ensures that only one timer
is setup at once. Called automatically.
## Algorithm
The cache uses two `Map` objects. The first maps item keys to their
expiration time, and the second maps item keys to their values. Then, a
null-prototype object uses the expiration time as keys, with the value
being an array of all the keys expiring at that time.
This leverages a few important features of modern JavaScript engines for
fairly good performance:
- `Map` objects are highly optimized for referring to arbitrary values by
arbitrary keys.
- Objects with solely integer-numeric keys are iterated in sorted numeric
order rather than insertion order, and insertions in the middle of the
key ordering are still very fast. This is true of all modern JS engines
tested at the time of this module's creation, but most particularly V8
(the engine in Node.js).
When it is time to prune, we can always walk the null-prototype object in
iteration order, deleting items until we come to the first key greater than
the current time.
Thus, the `start` time doesn't need to be tracked, only the expiration
time. When an item age is updated (either explicitly on `get()`, or by
setting to a new value), it is deleted and re-inserted.
## Immortality Hazards
It is possible to set a TTL of `Infinity`, in which case an item
will never expire. As it does not expire, its TTL is not
tracked, and `getRemainingTTL()` will return `Infinity` for that
key.
If you do this, then the item will never be purged. Create
enough immortal values, and the cache will grow to consume all
available memory. If find yourself doing this, it's _probably_
better to use a different data structure, such as a `Map` or
plain old object to store values, as it will have better
performance and the hazards will be more obvious.

231
node_modules/@isaacs/ttlcache/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,231 @@
// Type definitions for ttlcache 1.0.0
// Project: https://github.com/isaacs/ttlcache
// Loosely based on @isaacs/lru-cache
// https://github.com/isaacs/node-lru-cache/blob/v7.10.1/index.d.ts
declare class TTLCache<K, V> implements Iterable<[K, V]> {
constructor(options?: TTLCache.Options<K, V>)
ttl: number
max: number
updateAgeOnGet: boolean
checkAgeOnGet: boolean
noUpdateTTL: boolean
noDisposeOnSet: boolean
/**
* The total number of items held in the cache at the current moment.
*/
public readonly size: number
/**
* Add a value to the cache.
*/
public set(key: K, value: V, options?: TTLCache.SetOptions): this
/**
* Return a value from the cache.
* If the key is not found, `get()` will return `undefined`.
* This can be confusing when setting values specifically to `undefined`,
* as in `cache.set(key, undefined)`. Use `cache.has()` to determine
* whether a key is present in the cache at all.
*/
public get<T = V>(
key: K,
options?: TTLCache.GetOptions
): T | undefined
/**
* Check if a key is in the cache.
* Will return false if the item is stale, even though it is technically
* in the cache.
*/
public has(key: K): boolean
/**
* Deletes a key out of the cache.
* Returns true if the key was deleted, false otherwise.
*/
public delete(key: K): boolean
/**
* Clear the cache entirely, throwing away all values.
*/
public clear(): void
/**
* Delete any stale entries. Returns true if anything was removed, false
* otherwise.
*/
public purgeStale(): boolean
/**
* Return the remaining time before an item expires.
* Returns 0 if the item is not found in the cache or is already expired.
*/
public getRemainingTTL(key: K): number
/**
* Set the ttl explicitly to a value, defaulting to the TTL set on the ctor
*/
public setTTL(key: K, ttl?: number): void
/**
* Return a generator yielding `[key, value]` pairs, from soonest expiring
* to latest expiring. (Items expiring at the same time are walked in insertion order.)
*/
public entries(): Generator<[K, V]>
/**
* Return a generator yielding the keys in the cache,
* from soonest expiring to latest expiring.
*/
public keys(): Generator<K>
/**
* Return a generator yielding the values in the cache,
* from soonest expiring to latest expiring.
*/
public values(): Generator<V>
/**
* Iterating over the cache itself yields the same results as
* `cache.entries()`
*/
public [Symbol.iterator](): Iterator<[K, V]>
/**
* Cancel the timer and stop automatically expiring entries.
* This allows the process to gracefully exit where Timer.unref()
* is not available.
*/
public cancelTimer(): void
}
declare namespace TTLCache {
type DisposeReason = 'evict' | 'set' | 'delete' | 'stale'
type Disposer<K, V> = (
value: V,
key: K,
reason: DisposeReason
) => void
type TTLOptions = {
/**
* Max time in milliseconds for items to live in cache before they are
* considered stale. Note that stale items are NOT preemptively removed
* by default, and MAY live in the cache, contributing to max,
* long after they have expired.
*
* Must be an integer number of ms, or Infinity. Defaults to `undefined`,
* meaning that a TTL must be set explicitly for each set()
*/
ttl?: number
/**
* Boolean flag to tell the cache to not update the TTL when
* setting a new value for an existing key (ie, when updating a value
* rather than inserting a new value). Note that the TTL value is
* _always_ set when adding a new entry into the cache.
*
* @default false
*/
noUpdateTTL?: boolean
}
type Options<K, V> = {
/**
* The number of items to keep.
*
* @default Infinity
*/
max?: number
/**
* Update the age of items on cache.get(), renewing their TTL
*
* @default false
*/
updateAgeOnGet?: boolean
/**
* In the event that an item's expiration timer hasn't yet fired,
* and an attempt is made to get() it, then return undefined and
* delete it, rather than returning the cached value.
*
* By default, items are only expired when their timer fires, so there's
* a bit of a "best effort" expiration, and the cache will return a value
* if it has one, even if it's technically stale.
*
* @default false
*/
checkAgeOnGet?: boolean
/**
* Do not call dispose() function when overwriting a key with a new value
*
* @default false
*/
noDisposeOnSet?: boolean
/**
* Function that is called on items when they are dropped from the cache.
* This can be handy if you want to close file descriptors or do other
* cleanup tasks when items are no longer accessible. Called with `key,
* value`. It's called before actually removing the item from the
* internal cache, so it is *NOT* safe to re-add them.
* Use `disposeAfter` if you wish to dispose items after they have been
* full removed, when it is safe to add them back to the cache.
*/
dispose?: Disposer<K, V>
} & TTLOptions
type SetOptions = {
/**
* Do not call dispose() function when overwriting a key with a new value
* Overrides the value set in the constructor.
*/
noDisposeOnSet?: boolean
/**
* Do not update the TTL when overwriting an existing item.
*/
noUpdateTTL?: boolean
/**
* Override the default TTL for this one set() operation.
* Required if a TTL was not set in the constructor options.
*/
ttl?: number
}
type GetOptions = {
/**
* Update the age of items on cache.get(), renewing their TTL
*
* @default false
*/
updateAgeOnGet?: boolean
/**
* In the event that an item's expiration timer hasn't yet fired,
* and an attempt is made to get() it, then return undefined and
* delete it, rather than returning the cached value.
*
* By default, items are only expired when their timer fires, so there's
* a bit of a "best effort" expiration, and the cache will return a value
* if it has one, even if it's technically stale.
*
* @default false
*/
checkAgeOnGet?: boolean
/**
* Set new TTL, applied only when `updateAgeOnGet` is true
*/
ttl?: number
}
}
export = TTLCache

324
node_modules/@isaacs/ttlcache/index.js generated vendored Normal file
View File

@@ -0,0 +1,324 @@
// A simple TTL cache with max capacity option, ms resolution,
// autopurge, and reasonably optimized performance
// Relies on the fact that integer Object keys are kept sorted,
// and managed very efficiently by V8.
/* istanbul ignore next */
const perf =
typeof performance === 'object' &&
performance &&
typeof performance.now === 'function'
? performance
: Date
const now = () => perf.now()
const isPosInt = n => n && n === Math.floor(n) && n > 0 && isFinite(n)
const isPosIntOrInf = n => n === Infinity || isPosInt(n)
class TTLCache {
constructor({
max = Infinity,
ttl,
updateAgeOnGet = false,
checkAgeOnGet = false,
noUpdateTTL = false,
dispose,
noDisposeOnSet = false,
} = {}) {
// {[expirationTime]: [keys]}
this.expirations = Object.create(null)
// {key=>val}
this.data = new Map()
// {key=>expiration}
this.expirationMap = new Map()
if (ttl !== undefined && !isPosIntOrInf(ttl)) {
throw new TypeError(
'ttl must be positive integer or Infinity if set'
)
}
if (!isPosIntOrInf(max)) {
throw new TypeError('max must be positive integer or Infinity')
}
this.ttl = ttl
this.max = max
this.updateAgeOnGet = !!updateAgeOnGet
this.checkAgeOnGet = !!checkAgeOnGet
this.noUpdateTTL = !!noUpdateTTL
this.noDisposeOnSet = !!noDisposeOnSet
if (dispose !== undefined) {
if (typeof dispose !== 'function') {
throw new TypeError('dispose must be function if set')
}
this.dispose = dispose
}
this.timer = undefined
this.timerExpiration = undefined
}
setTimer(expiration, ttl) {
if (this.timerExpiration < expiration) {
return
}
if (this.timer) {
clearTimeout(this.timer)
}
const t = setTimeout(() => {
this.timer = undefined
this.timerExpiration = undefined
this.purgeStale()
for (const exp in this.expirations) {
this.setTimer(exp, exp - now())
break
}
}, ttl)
/* istanbul ignore else - affordance for non-node envs */
if (t.unref) t.unref()
this.timerExpiration = expiration
this.timer = t
}
// hang onto the timer so we can clearTimeout if all items
// are deleted. Deno doesn't have Timer.unref(), so it
// hangs otherwise.
cancelTimer() {
if (this.timer) {
clearTimeout(this.timer)
this.timerExpiration = undefined
this.timer = undefined
}
}
/* istanbul ignore next */
cancelTimers() {
process.emitWarning(
'TTLCache.cancelTimers has been renamed to ' +
'TTLCache.cancelTimer (no "s"), and will be removed in the next ' +
'major version update'
)
return this.cancelTimer()
}
clear() {
const entries =
this.dispose !== TTLCache.prototype.dispose ? [...this] : []
this.data.clear()
this.expirationMap.clear()
// no need for any purging now
this.cancelTimer()
this.expirations = Object.create(null)
for (const [key, val] of entries) {
this.dispose(val, key, 'delete')
}
}
setTTL(key, ttl = this.ttl) {
const current = this.expirationMap.get(key)
if (current !== undefined) {
// remove from the expirations list, so it isn't purged
const exp = this.expirations[current]
if (!exp || exp.length <= 1) {
delete this.expirations[current]
} else {
this.expirations[current] = exp.filter(k => k !== key)
}
}
if (ttl !== Infinity) {
const expiration = Math.floor(now() + ttl)
this.expirationMap.set(key, expiration)
if (!this.expirations[expiration]) {
this.expirations[expiration] = []
this.setTimer(expiration, ttl)
}
this.expirations[expiration].push(key)
} else {
this.expirationMap.set(key, Infinity)
}
}
set(
key,
val,
{
ttl = this.ttl,
noUpdateTTL = this.noUpdateTTL,
noDisposeOnSet = this.noDisposeOnSet,
} = {}
) {
if (!isPosIntOrInf(ttl)) {
throw new TypeError('ttl must be positive integer or Infinity')
}
if (this.expirationMap.has(key)) {
if (!noUpdateTTL) {
this.setTTL(key, ttl)
}
// has old value
const oldValue = this.data.get(key)
if (oldValue !== val) {
this.data.set(key, val)
if (!noDisposeOnSet) {
this.dispose(oldValue, key, 'set')
}
}
} else {
this.setTTL(key, ttl)
this.data.set(key, val)
}
while (this.size > this.max) {
this.purgeToCapacity()
}
return this
}
has(key) {
return this.data.has(key)
}
getRemainingTTL(key) {
const expiration = this.expirationMap.get(key)
return expiration === Infinity
? expiration
: expiration !== undefined
? Math.max(0, Math.ceil(expiration - now()))
: 0
}
get(
key,
{
updateAgeOnGet = this.updateAgeOnGet,
ttl = this.ttl,
checkAgeOnGet = this.checkAgeOnGet,
} = {}
) {
const val = this.data.get(key)
if (checkAgeOnGet && this.getRemainingTTL(key) === 0) {
this.delete(key)
return undefined
}
if (updateAgeOnGet) {
this.setTTL(key, ttl)
}
return val
}
dispose(_, __) {}
delete(key) {
const current = this.expirationMap.get(key)
if (current !== undefined) {
const value = this.data.get(key)
this.data.delete(key)
this.expirationMap.delete(key)
const exp = this.expirations[current]
if (exp) {
if (exp.length <= 1) {
delete this.expirations[current]
} else {
this.expirations[current] = exp.filter(k => k !== key)
}
}
this.dispose(value, key, 'delete')
if (this.size === 0) {
this.cancelTimer()
}
return true
}
return false
}
purgeToCapacity() {
for (const exp in this.expirations) {
const keys = this.expirations[exp]
if (this.size - keys.length >= this.max) {
delete this.expirations[exp]
const entries = []
for (const key of keys) {
entries.push([key, this.data.get(key)])
this.data.delete(key)
this.expirationMap.delete(key)
}
for (const [key, val] of entries) {
this.dispose(val, key, 'evict')
}
} else {
const s = this.size - this.max
const entries = []
for (const key of keys.splice(0, s)) {
entries.push([key, this.data.get(key)])
this.data.delete(key)
this.expirationMap.delete(key)
}
for (const [key, val] of entries) {
this.dispose(val, key, 'evict')
}
return
}
}
}
get size() {
return this.data.size
}
purgeStale() {
const n = Math.ceil(now())
for (const exp in this.expirations) {
if (exp === 'Infinity' || exp > n) {
return
}
/* istanbul ignore next
* mysterious need for a guard here?
* https://github.com/isaacs/ttlcache/issues/26 */
const keys = [...(this.expirations[exp] || [])]
const entries = []
delete this.expirations[exp]
for (const key of keys) {
entries.push([key, this.data.get(key)])
this.data.delete(key)
this.expirationMap.delete(key)
}
for (const [key, val] of entries) {
this.dispose(val, key, 'stale')
}
}
if (this.size === 0) {
this.cancelTimer()
}
}
*entries() {
for (const exp in this.expirations) {
for (const key of this.expirations[exp]) {
yield [key, this.data.get(key)]
}
}
}
*keys() {
for (const exp in this.expirations) {
for (const key of this.expirations[exp]) {
yield key
}
}
}
*values() {
for (const exp in this.expirations) {
for (const key of this.expirations[exp]) {
yield this.data.get(key)
}
}
}
[Symbol.iterator]() {
return this.entries()
}
}
module.exports = TTLCache

59
node_modules/@isaacs/ttlcache/package.json generated vendored Normal file
View File

@@ -0,0 +1,59 @@
{
"name": "@isaacs/ttlcache",
"version": "1.4.1",
"files": [
"index.js",
"index.d.ts"
],
"main": "index.js",
"exports": {
".": "./index.js"
},
"description": "The time-based use-recency-unaware cousin of [`lru-cache`](http://npm.im/lru-cache)",
"repository": {
"type": "git",
"url": "git+https://github.com/isaacs/ttlcache"
},
"author": "Isaac Z. Schlueter <i@izs.me> (https://izs.me)",
"license": "ISC",
"scripts": {
"test": "tap",
"snap": "tap",
"preversion": "npm test",
"postversion": "npm publish",
"prepublishOnly": "git push origin --follow-tags"
},
"devDependencies": {
"@types/node": "^17.0.42",
"@types/tap": "^15.0.7",
"clock-mock": "^1.0.6",
"prettier": "^2.7.0",
"tap": "^16.0.1",
"ts-node": "^10.8.1",
"typescript": "^4.7.3"
},
"engines": {
"node": ">=12"
},
"tap": {
"nyc-arg": [
"--include=index.js"
],
"node-arg": [
"--require",
"ts-node/register"
],
"ts": false
},
"prettier": {
"semi": false,
"printWidth": 70,
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"jsxSingleQuote": false,
"bracketSameLine": true,
"arrowParens": "avoid",
"endOfLine": "lf"
}
}