moved files
This commit is contained in:
21
administration/backend/node_modules/lru.min/LICENSE
generated
vendored
Normal file
21
administration/backend/node_modules/lru.min/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024-current Weslley Araújo (@wellwelwel)
|
||||
|
||||
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.
|
426
administration/backend/node_modules/lru.min/README.md
generated
vendored
Normal file
426
administration/backend/node_modules/lru.min/README.md
generated
vendored
Normal file
@@ -0,0 +1,426 @@
|
||||
<h1 align="center">lru.min</h1>
|
||||
<div align="center">
|
||||
|
||||
[](https://www.npmjs.com/package/lru.min)
|
||||
[](https://www.npmjs.com/package/lru.min)
|
||||
[](https://app.codecov.io/gh/wellwelwel/lru.min)<br />
|
||||
[](https://github.com/wellwelwel/lru.min/actions/workflows/ci_node.yml?query=branch%3Amain)
|
||||
[](https://github.com/wellwelwel/lru.min/actions/workflows/ci_bun.yml?query=branch%3Amain)
|
||||
[](https://github.com/wellwelwel/lru.min/actions/workflows/ci_deno.yml?query=branch%3Amain)
|
||||
|
||||
🔥 An extremely fast, efficient, and lightweight <strong><a href="https://en.m.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_.28LRU.29">LRU</a> Cache</strong> for <strong>JavaScript</strong> (<strong>Browser</strong> compatible).
|
||||
|
||||
</div>
|
||||
|
||||
## Why another LRU?
|
||||
|
||||
- 🎖️ **lru.min** is fully compatible with both **Node.js** _(8+)_, **Bun**, **Deno** and, browser environments. All of this, while maintaining the same high performance [_(and a little more)_](https://github.com/wellwelwel/lru.min?tab=readme-ov-file#performance) as the most popular **LRU** packages.
|
||||
|
||||
---
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
# Node.js
|
||||
npm i lru.min
|
||||
```
|
||||
|
||||
```bash
|
||||
# Bun
|
||||
bun add lru.min
|
||||
```
|
||||
|
||||
```bash
|
||||
# Deno
|
||||
deno add npm:lru.min
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Usage
|
||||
|
||||
### Quickstart
|
||||
|
||||
```js
|
||||
import { createLRU } from 'lru.min';
|
||||
|
||||
const max = 2;
|
||||
const onEviction = (key, value) => {
|
||||
console.log(`Key "${key}" with value "${value}" has been evicted.`);
|
||||
};
|
||||
|
||||
const LRU = createLRU({
|
||||
max,
|
||||
onEviction,
|
||||
});
|
||||
|
||||
LRU.set('A', 'My Value');
|
||||
LRU.set('B', 'Other Value');
|
||||
LRU.set('C', 'Another Value');
|
||||
|
||||
// => Key "A" with value "My Value" has been evicted.
|
||||
|
||||
LRU.has('B');
|
||||
LRU.get('B');
|
||||
LRU.delete('B');
|
||||
|
||||
// => Key "B" with value "Other Value" has been evicted.
|
||||
|
||||
LRU.peek('C');
|
||||
|
||||
LRU.clear(); // ← recommended | LRU.evict(max) → (slower alternative)
|
||||
|
||||
// => Key "C" with value "Another Value" has been evicted.
|
||||
|
||||
LRU.set('D', "You're amazing 💛");
|
||||
|
||||
LRU.size; // 1
|
||||
LRU.max; // 2
|
||||
LRU.available; // 1
|
||||
|
||||
LRU.resize(10);
|
||||
|
||||
LRU.size; // 1
|
||||
LRU.max; // 10
|
||||
LRU.available; // 9
|
||||
```
|
||||
|
||||
> For _up-to-date_ documentation, always follow the [**README.md**](https://github.com/wellwelwel/lru.min?tab=readme-ov-file#readme) in the **GitHub** repository.
|
||||
|
||||
### Import
|
||||
|
||||
#### ES Modules
|
||||
|
||||
```js
|
||||
import { createLRU } from 'lru.min';
|
||||
```
|
||||
|
||||
#### CommonJS
|
||||
|
||||
```js
|
||||
const { createLRU } = require('lru.min');
|
||||
```
|
||||
|
||||
#### Browser
|
||||
|
||||
> Requires **ES6**.
|
||||
|
||||
```html
|
||||
<script src="https://cdn.jsdelivr.net/npm/lru.min@1.x.x/browser/lru.min.js"></script>
|
||||
```
|
||||
|
||||
- You can use tools such as [**Babel**](https://github.com/babel/babel) to increase the compatibility rate.
|
||||
|
||||
### Create a new LRU Cache
|
||||
|
||||
> Set maximum size when creating **LRU**.
|
||||
|
||||
```ts
|
||||
const LRU = createLRU({ max: 150_000 });
|
||||
```
|
||||
|
||||
Also, you can set a callback for every deletion/eviction:
|
||||
|
||||
```ts
|
||||
const LRU = createLRU({
|
||||
max: 150_000,
|
||||
onEviction: (key, value) => {
|
||||
// do something
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
### Set a cache
|
||||
|
||||
Adds a key-value pair to the cache. Updates the value if the key already exists
|
||||
|
||||
```ts
|
||||
LRU.set('key', 'value');
|
||||
```
|
||||
|
||||
> `undefined` keys will simply be ignored.
|
||||
|
||||
- Complexity: **O(1)**.
|
||||
|
||||
### Get a cache
|
||||
|
||||
Retrieves the value for a given key and moves the key to the most recent position.
|
||||
|
||||
```ts
|
||||
LRU.get('key');
|
||||
```
|
||||
|
||||
- Complexity: **O(1)**.
|
||||
|
||||
### Peek a cache
|
||||
|
||||
Retrieves the value for a given key without changing its position.
|
||||
|
||||
```ts
|
||||
LRU.peek('key');
|
||||
```
|
||||
|
||||
- Complexity: **O(1)**.
|
||||
|
||||
### Check if a key exists
|
||||
|
||||
```ts
|
||||
LRU.has('key');
|
||||
```
|
||||
|
||||
- Complexity: **O(1)**.
|
||||
|
||||
### Delete a cache
|
||||
|
||||
```ts
|
||||
LRU.delete('key');
|
||||
```
|
||||
|
||||
- Complexity: **O(1)**.
|
||||
|
||||
### Evict from the oldest cache
|
||||
|
||||
Evicts the specified number of the oldest items from the cache.
|
||||
|
||||
```ts
|
||||
LRU.evict(1000);
|
||||
```
|
||||
|
||||
- Complexity: **O(key)** — even if passed a number greater than the number of items, only existing items will be evicted.
|
||||
|
||||
> [!TIP]
|
||||
>
|
||||
> - Methods that perform eviction(s) when maximum size is reached: `set` and `resize`.
|
||||
> - Methods that always perform eviction(s): `delete`, `clear`, and `evict` itself.
|
||||
|
||||
### Resize the cache
|
||||
|
||||
Resizes the cache to a new maximum size, evicting items if necessary.
|
||||
|
||||
```ts
|
||||
LRU.resize(50_000);
|
||||
```
|
||||
|
||||
- Complexity:
|
||||
- Increasing: **O(newMax - max)**.
|
||||
- Downsizing: **O(n)**.
|
||||
|
||||
### Clear the cache
|
||||
|
||||
Clears and disposes (if used) all key-value pairs from the cache.
|
||||
|
||||
```ts
|
||||
LRU.clear();
|
||||
```
|
||||
|
||||
- Complexity:
|
||||
- Without `onEviction`: **O(1)**.
|
||||
- Using `onEviction`: **O(entries)**.
|
||||
|
||||
### Debugging
|
||||
|
||||
#### Get the max size of the cache
|
||||
|
||||
```ts
|
||||
LRU.max;
|
||||
```
|
||||
|
||||
- Complexity: **O(1)**.
|
||||
|
||||
#### Get the current size of the cache
|
||||
|
||||
```ts
|
||||
LRU.size;
|
||||
```
|
||||
|
||||
- Complexity: **O(1)**.
|
||||
|
||||
#### Get the available slots in the cache
|
||||
|
||||
```ts
|
||||
LRU.available;
|
||||
```
|
||||
|
||||
- Complexity: **O(1)**.
|
||||
|
||||
### Iterating the cache
|
||||
|
||||
#### Get all keys
|
||||
|
||||
Iterates over all keys in the cache, from most recent to least recent.
|
||||
|
||||
```ts
|
||||
const keys = [...LRU.keys()];
|
||||
```
|
||||
|
||||
- Complexity: **O(keys)**.
|
||||
|
||||
#### Get all values
|
||||
|
||||
Iterates over all values in the cache, from most recent to least recent.
|
||||
|
||||
```ts
|
||||
const values = [...LRU.values()];
|
||||
```
|
||||
|
||||
- Complexity: **O(values)**.
|
||||
|
||||
#### Get all entries
|
||||
|
||||
Iterates over `[key, value]` pairs in the cache, from most recent to least recent.
|
||||
|
||||
```ts
|
||||
const entries = [...LRU.entries()];
|
||||
```
|
||||
|
||||
- Complexity: **O(entries)**.
|
||||
|
||||
#### Run a callback for each entry
|
||||
|
||||
Iterates over each value-key pair in the cache, from most recent to least recent.
|
||||
|
||||
```ts
|
||||
LRU.forEach((value, key) => {
|
||||
// do something
|
||||
});
|
||||
```
|
||||
|
||||
- Complexity: **O(entries)**.
|
||||
|
||||
---
|
||||
|
||||
> [!NOTE]
|
||||
>
|
||||
> - We use `O(keys)`, `O(values)`, `O(entries)`, and `O(newMax - max)` to explicitly indicate what is being iterated over. In traditional complexity notation, this would be represented as `O(n)`.
|
||||
|
||||
---
|
||||
|
||||
### TypeScript
|
||||
|
||||
You can set types for both keys and values. For example:
|
||||
|
||||
```ts
|
||||
import { createLRU } from 'lru.min';
|
||||
|
||||
type Key = number;
|
||||
|
||||
type Value = {
|
||||
name: string;
|
||||
};
|
||||
|
||||
const LRU = createLRU<Key, Value>({ max: 1000 });
|
||||
|
||||
LRU.set(1, { name: 'Peter' });
|
||||
LRU.set(2, { name: 'Mary' });
|
||||
```
|
||||
|
||||
Also:
|
||||
|
||||
```ts
|
||||
import { createLRU, type CacheOptions } from 'lru.min';
|
||||
|
||||
type Key = number;
|
||||
|
||||
type Value = {
|
||||
name: string;
|
||||
};
|
||||
|
||||
const options: CacheOptions<Key, Value> = {
|
||||
max: 10,
|
||||
onEviction(key, value) {
|
||||
console.log(key, value);
|
||||
},
|
||||
};
|
||||
|
||||
// No need to repeat the type params
|
||||
const LRU = createLRU(options);
|
||||
|
||||
LRU.set(1, { name: 'Peter' });
|
||||
LRU.set(2, { name: 'Mary' });
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Performance
|
||||
|
||||
The benchmark is performed by comparing `1,000,000` runs through a maximum cache limit of `100,000`, getting `333,333` caches and deleting `200,000` keys 10 consecutive times, clearing the cache every run.
|
||||
|
||||
> - [**lru-cache**](https://github.com/isaacs/node-lru-cache) `v11.0.0`
|
||||
> - [**quick-lru**](https://github.com/sindresorhus/quick-lru) `v7.0.0`
|
||||
|
||||
```sh
|
||||
# Time:
|
||||
lru.min: 240.45ms
|
||||
lru-cache: 258.32ms
|
||||
quick-lru: 279.89ms
|
||||
|
||||
# CPU:
|
||||
lru.min: 275558.30µs
|
||||
lru-cache: 306858.30µs
|
||||
quick-lru: 401318.80µs
|
||||
```
|
||||
|
||||
- See detailed results and how the tests are run and compared in the [**benchmark**](https://github.com/wellwelwel/lru.min/tree/main/benchmark) directory.
|
||||
|
||||
---
|
||||
|
||||
## Security Policy
|
||||
|
||||
[](https://github.com/wellwelwel/lru.min/actions/workflows/ci_codeql.yml?query=branch%3Amain)
|
||||
|
||||
Please check the [**SECURITY.md**](https://github.com/wellwelwel/lru.min/blob/main/SECURITY.md).
|
||||
|
||||
---
|
||||
|
||||
## Contributing
|
||||
|
||||
See the [**Contributing Guide**](https://github.com/wellwelwel/lru.min/blob/main/CONTRIBUTING.md) and please follow our [**Code of Conduct**](https://github.com/wellwelwel/lru.min/blob/main/CODE_OF_CONDUCT.md) 🚀
|
||||
|
||||
---
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
**lru.min** is based and inspired on the architecture and code of both [**lru-cache**](https://github.com/isaacs/node-lru-cache) and [**quick-lru**](https://github.com/sindresorhus/quick-lru), simplifying their core concepts for enhanced performance and compatibility.
|
||||
|
||||
For more comprehensive features such as **TTL** support, consider using and supporting them 🤝
|
||||
|
||||
- The architecture is mostly based on [@isaacs](https://github.com/isaacs) — [**lru-cache**](https://github.com/isaacs/node-lru-cache/blob/8f51d75351cbb4ac819952eb8e9f95eda00ef800/src/index.ts).
|
||||
- Most of the methods names and its functionalities were inspired by [@sindresorhus](https://github.com/sindresorhus) — [**quick-lru**](https://github.com/sindresorhus/quick-lru/blob/a2262c65e1952539cb4d985a67c46363a780d234/index.js).
|
||||
- [](https://github.com/wellwelwel/lru.min/graphs/contributors)
|
||||
|
||||
---
|
||||
|
||||
#### What comes from [**lru-cache**](https://github.com/isaacs/node-lru-cache)?
|
||||
|
||||
Architecture's essence:
|
||||
|
||||
> _It's not the same code, but majority based on [this](https://github.com/isaacs/node-lru-cache/blob/8f51d75351cbb4ac819952eb8e9f95eda00ef800/src/index.ts#L1385-L1394)._
|
||||
|
||||
```ts
|
||||
let free: number[] = [];
|
||||
|
||||
const keyMap: Map<Key, number> = new Map();
|
||||
const keyList: (Key | undefined)[] = new Array(max).fill(undefined);
|
||||
const valList: (Value | undefined)[] = new Array(max).fill(undefined);
|
||||
const next: number[] = new Array(max).fill(0);
|
||||
const prev: number[] = new Array(max).fill(0);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### What comes from [**quick-lru**](https://github.com/sindresorhus/quick-lru)?
|
||||
|
||||
Name of methods and options _(including their final functionality ideas)_:
|
||||
|
||||
- `resize`
|
||||
- `peek`
|
||||
- `onEviction`
|
||||
- `forEach`
|
||||
- `entriesDescending` as `entries`
|
||||
|
||||
---
|
||||
|
||||
## License
|
||||
|
||||
**lru.min** is under the [**MIT License**](https://github.com/wellwelwel/lru.min/blob/main/LICENSE).<br />
|
||||
Copyright © 2024-present [Weslley Araújo](https://github.com/wellwelwel) and **lru.min** [contributors](https://github.com/wellwelwel/lru.min/graphs/contributors).
|
1
administration/backend/node_modules/lru.min/browser/lru.min.js
generated
vendored
Normal file
1
administration/backend/node_modules/lru.min/browser/lru.min.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
"use strict";window.createLRU=function(e){var r=e.max;if(!(Number.isInteger(r)&&r>0))throw new TypeError("`max` must be a positive integer");var n=0,i=0,t=0,a=[],o=e.onEviction,l=new Map,f=new Array(r).fill(void 0),u=new Array(r).fill(void 0),v=new Array(r).fill(0),s=new Array(r).fill(0),d=function(e,r){if(e!==t){var n=v[e],a=s[e];e===i?i=n:("get"===r||0!==a)&&(v[a]=n),0!==n&&(s[n]=a),v[t]=e,s[e]=t,v[e]=0,t=e}},p=function(){var e=i,r=f[e];return null==o||o(r,u[e]),l.delete(r),f[e]=void 0,u[e]=void 0,0!==(i=v[e])&&(s[i]=0),0===--n&&(i=t=0),a.push(e),e};return{set:function(e,v){if(void 0!==e){var s=l.get(e);void 0===s?(s=n===r?p():a.length>0?a.pop():n,l.set(e,s),f[s]=e,n++):null==o||o(e,u[s]),u[s]=v,1===n?i=t=s:d(s,"set")}},get:function(e){var r=l.get(e);if(void 0!==r)return r!==t&&d(r,"get"),u[r]},peek:function(e){var r=l.get(e);return void 0!==r?u[r]:void 0},has:function(e){return l.has(e)},keys:function*(){for(var e=t,r=0;r<n;r++)yield f[e],e=s[e]},values:function*(){for(var e=t,r=0;r<n;r++)yield u[e],e=s[e]},entries:function*(){for(var e=t,r=0;r<n;r++)yield[f[e],u[e]],e=s[e]},forEach:function(e){for(var r=t,i=0;i<n;i++){var a=f[r];e(u[r],a),r=s[r]}},delete:function(e){var r=l.get(e);if(void 0===r)return!1;null==o||o(e,u[r]),l.delete(e),a.push(r),f[r]=void 0,u[r]=void 0;var d=s[r],p=v[r];return 0!==d&&(v[d]=p),0!==p&&(s[p]=d),r===i&&(i=p),r===t&&(t=d),n--,!0},evict:function(e){for(var r=Math.min(e,n);r>0;)p(),r--},clear:function(){if("function"==typeof o)for(var e=l.values(),r=e.next();!r.done;r=e.next())o(f[r.value],u[r.value]);l.clear(),f.fill(void 0),u.fill(void 0),a=[],n=0,i=t=0},resize:function(e){if(!(Number.isInteger(e)&&e>0))throw new TypeError("`max` must be a positive integer");if(e!==r){if(e<r){for(var d=t,p=Math.min(n,e),c=n-p,y=new Array(e),g=new Array(e),h=new Array(e),w=new Array(e),A=1;A<=c;A++)null==o||o(f[A],u[A]);for(var m=p-1;m>=0;m--)y[m]=f[d],g[m]=u[d],h[m]=m+1,w[m]=m-1,l.set(y[m],m),d=s[d];i=0,t=p-1,n=p,f.length=e,u.length=e,v.length=e,s.length=e;for(var x=0;x<p;x++)f[x]=y[x],u[x]=g[x],v[x]=h[x],s[x]=w[x];a=[];for(var b=p;b<e;b++)a.push(b)}else{var E=e-r;f.push.apply(f,new Array(E).fill(void 0)),u.push.apply(u,new Array(E).fill(void 0)),v.push.apply(v,new Array(E).fill(0)),s.push.apply(s,new Array(E).fill(0))}r=e}},get max(){return r},get size(){return n},get available(){return r-n}}};
|
38
administration/backend/node_modules/lru.min/lib/index.d.ts
generated
vendored
Normal file
38
administration/backend/node_modules/lru.min/lib/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
export type CacheOptions<Key = unknown, Value = unknown> = {
|
||||
/** Maximum number of items the cache can hold. */
|
||||
max: number;
|
||||
/** Function called when an item is evicted from the cache. */
|
||||
onEviction?: (key: Key, value: Value) => unknown;
|
||||
};
|
||||
export declare const createLRU: <Key, Value>(options: CacheOptions<Key, Value>) => {
|
||||
/** Adds a key-value pair to the cache. Updates the value if the key already exists. */
|
||||
set(key: Key, value: Value): undefined;
|
||||
/** Retrieves the value for a given key and moves the key to the most recent position. */
|
||||
get(key: Key): Value | undefined;
|
||||
/** Retrieves the value for a given key without changing its position. */
|
||||
peek: (key: Key) => Value | undefined;
|
||||
/** Checks if a key exists in the cache. */
|
||||
has: (key: Key) => boolean;
|
||||
/** Iterates over all keys in the cache, from most recent to least recent. */
|
||||
keys(): IterableIterator<Key>;
|
||||
/** Iterates over all values in the cache, from most recent to least recent. */
|
||||
values(): IterableIterator<Value>;
|
||||
/** Iterates over `[key, value]` pairs in the cache, from most recent to least recent. */
|
||||
entries(): IterableIterator<[Key, Value]>;
|
||||
/** Iterates over each value-key pair in the cache, from most recent to least recent. */
|
||||
forEach: (callback: (value: Value, key: Key) => unknown) => undefined;
|
||||
/** Deletes a key-value pair from the cache. */
|
||||
delete(key: Key): boolean;
|
||||
/** Evicts the oldest item or the specified number of the oldest items from the cache. */
|
||||
evict: (number: number) => undefined;
|
||||
/** Clears all key-value pairs from the cache. */
|
||||
clear(): undefined;
|
||||
/** Resizes the cache to a new maximum size, evicting items if necessary. */
|
||||
resize: (newMax: number) => undefined;
|
||||
/** Returns the maximum number of items that can be stored in the cache. */
|
||||
readonly max: number;
|
||||
/** Returns the number of items currently stored in the cache. */
|
||||
readonly size: number;
|
||||
/** Returns the number of currently available slots in the cache before reaching the maximum size. */
|
||||
readonly available: number;
|
||||
};
|
229
administration/backend/node_modules/lru.min/lib/index.js
generated
vendored
Normal file
229
administration/backend/node_modules/lru.min/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,229 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createLRU = void 0;
|
||||
const createLRU = (options) => {
|
||||
let { max } = options;
|
||||
if (!(Number.isInteger(max) && max > 0))
|
||||
throw new TypeError('`max` must be a positive integer');
|
||||
let size = 0;
|
||||
let head = 0;
|
||||
let tail = 0;
|
||||
let free = [];
|
||||
const { onEviction } = options;
|
||||
const keyMap = new Map();
|
||||
const keyList = new Array(max).fill(undefined);
|
||||
const valList = new Array(max).fill(undefined);
|
||||
const next = new Array(max).fill(0);
|
||||
const prev = new Array(max).fill(0);
|
||||
const setTail = (index, type) => {
|
||||
if (index === tail)
|
||||
return;
|
||||
const nextIndex = next[index];
|
||||
const prevIndex = prev[index];
|
||||
if (index === head)
|
||||
head = nextIndex;
|
||||
else if (type === 'get' || prevIndex !== 0)
|
||||
next[prevIndex] = nextIndex;
|
||||
if (nextIndex !== 0)
|
||||
prev[nextIndex] = prevIndex;
|
||||
next[tail] = index;
|
||||
prev[index] = tail;
|
||||
next[index] = 0;
|
||||
tail = index;
|
||||
};
|
||||
const _evict = () => {
|
||||
const evictHead = head;
|
||||
const key = keyList[evictHead];
|
||||
onEviction === null || onEviction === void 0 ? void 0 : onEviction(key, valList[evictHead]);
|
||||
keyMap.delete(key);
|
||||
keyList[evictHead] = undefined;
|
||||
valList[evictHead] = undefined;
|
||||
head = next[evictHead];
|
||||
if (head !== 0)
|
||||
prev[head] = 0;
|
||||
size--;
|
||||
if (size === 0)
|
||||
head = tail = 0;
|
||||
free.push(evictHead);
|
||||
return evictHead;
|
||||
};
|
||||
return {
|
||||
/** Adds a key-value pair to the cache. Updates the value if the key already exists. */
|
||||
set(key, value) {
|
||||
if (key === undefined)
|
||||
return;
|
||||
let index = keyMap.get(key);
|
||||
if (index === undefined) {
|
||||
index = size === max ? _evict() : free.length > 0 ? free.pop() : size;
|
||||
keyMap.set(key, index);
|
||||
keyList[index] = key;
|
||||
size++;
|
||||
}
|
||||
else
|
||||
onEviction === null || onEviction === void 0 ? void 0 : onEviction(key, valList[index]);
|
||||
valList[index] = value;
|
||||
if (size === 1)
|
||||
head = tail = index;
|
||||
else
|
||||
setTail(index, 'set');
|
||||
},
|
||||
/** Retrieves the value for a given key and moves the key to the most recent position. */
|
||||
get(key) {
|
||||
const index = keyMap.get(key);
|
||||
if (index === undefined)
|
||||
return;
|
||||
if (index !== tail)
|
||||
setTail(index, 'get');
|
||||
return valList[index];
|
||||
},
|
||||
/** Retrieves the value for a given key without changing its position. */
|
||||
peek: (key) => {
|
||||
const index = keyMap.get(key);
|
||||
return index !== undefined ? valList[index] : undefined;
|
||||
},
|
||||
/** Checks if a key exists in the cache. */
|
||||
has: (key) => keyMap.has(key),
|
||||
/** Iterates over all keys in the cache, from most recent to least recent. */
|
||||
*keys() {
|
||||
let current = tail;
|
||||
for (let i = 0; i < size; i++) {
|
||||
yield keyList[current];
|
||||
current = prev[current];
|
||||
}
|
||||
},
|
||||
/** Iterates over all values in the cache, from most recent to least recent. */
|
||||
*values() {
|
||||
let current = tail;
|
||||
for (let i = 0; i < size; i++) {
|
||||
yield valList[current];
|
||||
current = prev[current];
|
||||
}
|
||||
},
|
||||
/** Iterates over `[key, value]` pairs in the cache, from most recent to least recent. */
|
||||
*entries() {
|
||||
let current = tail;
|
||||
for (let i = 0; i < size; i++) {
|
||||
yield [keyList[current], valList[current]];
|
||||
current = prev[current];
|
||||
}
|
||||
},
|
||||
/** Iterates over each value-key pair in the cache, from most recent to least recent. */
|
||||
forEach: (callback) => {
|
||||
let current = tail;
|
||||
for (let i = 0; i < size; i++) {
|
||||
const key = keyList[current];
|
||||
const value = valList[current];
|
||||
callback(value, key);
|
||||
current = prev[current];
|
||||
}
|
||||
},
|
||||
/** Deletes a key-value pair from the cache. */
|
||||
delete(key) {
|
||||
const index = keyMap.get(key);
|
||||
if (index === undefined)
|
||||
return false;
|
||||
onEviction === null || onEviction === void 0 ? void 0 : onEviction(key, valList[index]);
|
||||
keyMap.delete(key);
|
||||
free.push(index);
|
||||
keyList[index] = undefined;
|
||||
valList[index] = undefined;
|
||||
const prevIndex = prev[index];
|
||||
const nextIndex = next[index];
|
||||
if (prevIndex !== 0)
|
||||
next[prevIndex] = nextIndex;
|
||||
if (nextIndex !== 0)
|
||||
prev[nextIndex] = prevIndex;
|
||||
if (index === head)
|
||||
head = nextIndex;
|
||||
if (index === tail)
|
||||
tail = prevIndex;
|
||||
size--;
|
||||
return true;
|
||||
},
|
||||
/** Evicts the oldest item or the specified number of the oldest items from the cache. */
|
||||
evict: (number) => {
|
||||
let toPrune = Math.min(number, size);
|
||||
while (toPrune > 0) {
|
||||
_evict();
|
||||
toPrune--;
|
||||
}
|
||||
},
|
||||
/** Clears all key-value pairs from the cache. */
|
||||
clear() {
|
||||
if (typeof onEviction === 'function') {
|
||||
const iterator = keyMap.values();
|
||||
for (let result = iterator.next(); !result.done; result = iterator.next())
|
||||
onEviction(keyList[result.value], valList[result.value]);
|
||||
}
|
||||
keyMap.clear();
|
||||
keyList.fill(undefined);
|
||||
valList.fill(undefined);
|
||||
free = [];
|
||||
size = 0;
|
||||
head = tail = 0;
|
||||
},
|
||||
/** Resizes the cache to a new maximum size, evicting items if necessary. */
|
||||
resize: (newMax) => {
|
||||
if (!(Number.isInteger(newMax) && newMax > 0))
|
||||
throw new TypeError('`max` must be a positive integer');
|
||||
if (newMax === max)
|
||||
return;
|
||||
if (newMax < max) {
|
||||
let current = tail;
|
||||
const preserve = Math.min(size, newMax);
|
||||
const remove = size - preserve;
|
||||
const newKeyList = new Array(newMax);
|
||||
const newValList = new Array(newMax);
|
||||
const newNext = new Array(newMax);
|
||||
const newPrev = new Array(newMax);
|
||||
for (let i = 1; i <= remove; i++)
|
||||
onEviction === null || onEviction === void 0 ? void 0 : onEviction(keyList[i], valList[i]);
|
||||
for (let i = preserve - 1; i >= 0; i--) {
|
||||
newKeyList[i] = keyList[current];
|
||||
newValList[i] = valList[current];
|
||||
newNext[i] = i + 1;
|
||||
newPrev[i] = i - 1;
|
||||
keyMap.set(newKeyList[i], i);
|
||||
current = prev[current];
|
||||
}
|
||||
head = 0;
|
||||
tail = preserve - 1;
|
||||
size = preserve;
|
||||
keyList.length = newMax;
|
||||
valList.length = newMax;
|
||||
next.length = newMax;
|
||||
prev.length = newMax;
|
||||
for (let i = 0; i < preserve; i++) {
|
||||
keyList[i] = newKeyList[i];
|
||||
valList[i] = newValList[i];
|
||||
next[i] = newNext[i];
|
||||
prev[i] = newPrev[i];
|
||||
}
|
||||
free = [];
|
||||
for (let i = preserve; i < newMax; i++)
|
||||
free.push(i);
|
||||
}
|
||||
else {
|
||||
const fill = newMax - max;
|
||||
keyList.push(...new Array(fill).fill(undefined));
|
||||
valList.push(...new Array(fill).fill(undefined));
|
||||
next.push(...new Array(fill).fill(0));
|
||||
prev.push(...new Array(fill).fill(0));
|
||||
}
|
||||
max = newMax;
|
||||
},
|
||||
/** Returns the maximum number of items that can be stored in the cache. */
|
||||
get max() {
|
||||
return max;
|
||||
},
|
||||
/** Returns the number of items currently stored in the cache. */
|
||||
get size() {
|
||||
return size;
|
||||
},
|
||||
/** Returns the number of currently available slots in the cache before reaching the maximum size. */
|
||||
get available() {
|
||||
return max - size;
|
||||
},
|
||||
};
|
||||
};
|
||||
exports.createLRU = createLRU;
|
207
administration/backend/node_modules/lru.min/lib/index.mjs
generated
vendored
Normal file
207
administration/backend/node_modules/lru.min/lib/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,207 @@
|
||||
const createLRU = (options) => {
|
||||
let { max } = options;
|
||||
if (!(Number.isInteger(max) && max > 0))
|
||||
throw new TypeError("`max` must be a positive integer");
|
||||
let size = 0;
|
||||
let head = 0;
|
||||
let tail = 0;
|
||||
let free = [];
|
||||
const { onEviction } = options;
|
||||
const keyMap = /* @__PURE__ */ new Map();
|
||||
const keyList = new Array(max).fill(void 0);
|
||||
const valList = new Array(max).fill(void 0);
|
||||
const next = new Array(max).fill(0);
|
||||
const prev = new Array(max).fill(0);
|
||||
const setTail = (index, type) => {
|
||||
if (index === tail) return;
|
||||
const nextIndex = next[index];
|
||||
const prevIndex = prev[index];
|
||||
if (index === head) head = nextIndex;
|
||||
else if (type === "get" || prevIndex !== 0) next[prevIndex] = nextIndex;
|
||||
if (nextIndex !== 0) prev[nextIndex] = prevIndex;
|
||||
next[tail] = index;
|
||||
prev[index] = tail;
|
||||
next[index] = 0;
|
||||
tail = index;
|
||||
};
|
||||
const _evict = () => {
|
||||
const evictHead = head;
|
||||
const key = keyList[evictHead];
|
||||
onEviction == null ? void 0 : onEviction(key, valList[evictHead]);
|
||||
keyMap.delete(key);
|
||||
keyList[evictHead] = void 0;
|
||||
valList[evictHead] = void 0;
|
||||
head = next[evictHead];
|
||||
if (head !== 0) prev[head] = 0;
|
||||
size--;
|
||||
if (size === 0) head = tail = 0;
|
||||
free.push(evictHead);
|
||||
return evictHead;
|
||||
};
|
||||
return {
|
||||
/** Adds a key-value pair to the cache. Updates the value if the key already exists. */
|
||||
set(key, value) {
|
||||
if (key === void 0) return;
|
||||
let index = keyMap.get(key);
|
||||
if (index === void 0) {
|
||||
index = size === max ? _evict() : free.length > 0 ? free.pop() : size;
|
||||
keyMap.set(key, index);
|
||||
keyList[index] = key;
|
||||
size++;
|
||||
} else onEviction == null ? void 0 : onEviction(key, valList[index]);
|
||||
valList[index] = value;
|
||||
if (size === 1) head = tail = index;
|
||||
else setTail(index, "set");
|
||||
},
|
||||
/** Retrieves the value for a given key and moves the key to the most recent position. */
|
||||
get(key) {
|
||||
const index = keyMap.get(key);
|
||||
if (index === void 0) return;
|
||||
if (index !== tail) setTail(index, "get");
|
||||
return valList[index];
|
||||
},
|
||||
/** Retrieves the value for a given key without changing its position. */
|
||||
peek: (key) => {
|
||||
const index = keyMap.get(key);
|
||||
return index !== void 0 ? valList[index] : void 0;
|
||||
},
|
||||
/** Checks if a key exists in the cache. */
|
||||
has: (key) => keyMap.has(key),
|
||||
/** Iterates over all keys in the cache, from most recent to least recent. */
|
||||
*keys() {
|
||||
let current = tail;
|
||||
for (let i = 0; i < size; i++) {
|
||||
yield keyList[current];
|
||||
current = prev[current];
|
||||
}
|
||||
},
|
||||
/** Iterates over all values in the cache, from most recent to least recent. */
|
||||
*values() {
|
||||
let current = tail;
|
||||
for (let i = 0; i < size; i++) {
|
||||
yield valList[current];
|
||||
current = prev[current];
|
||||
}
|
||||
},
|
||||
/** Iterates over `[key, value]` pairs in the cache, from most recent to least recent. */
|
||||
*entries() {
|
||||
let current = tail;
|
||||
for (let i = 0; i < size; i++) {
|
||||
yield [keyList[current], valList[current]];
|
||||
current = prev[current];
|
||||
}
|
||||
},
|
||||
/** Iterates over each value-key pair in the cache, from most recent to least recent. */
|
||||
forEach: (callback) => {
|
||||
let current = tail;
|
||||
for (let i = 0; i < size; i++) {
|
||||
const key = keyList[current];
|
||||
const value = valList[current];
|
||||
callback(value, key);
|
||||
current = prev[current];
|
||||
}
|
||||
},
|
||||
/** Deletes a key-value pair from the cache. */
|
||||
delete(key) {
|
||||
const index = keyMap.get(key);
|
||||
if (index === void 0) return false;
|
||||
onEviction == null ? void 0 : onEviction(key, valList[index]);
|
||||
keyMap.delete(key);
|
||||
free.push(index);
|
||||
keyList[index] = void 0;
|
||||
valList[index] = void 0;
|
||||
const prevIndex = prev[index];
|
||||
const nextIndex = next[index];
|
||||
if (prevIndex !== 0) next[prevIndex] = nextIndex;
|
||||
if (nextIndex !== 0) prev[nextIndex] = prevIndex;
|
||||
if (index === head) head = nextIndex;
|
||||
if (index === tail) tail = prevIndex;
|
||||
size--;
|
||||
return true;
|
||||
},
|
||||
/** Evicts the oldest item or the specified number of the oldest items from the cache. */
|
||||
evict: (number) => {
|
||||
let toPrune = Math.min(number, size);
|
||||
while (toPrune > 0) {
|
||||
_evict();
|
||||
toPrune--;
|
||||
}
|
||||
},
|
||||
/** Clears all key-value pairs from the cache. */
|
||||
clear() {
|
||||
if (typeof onEviction === "function") {
|
||||
const iterator = keyMap.values();
|
||||
for (let result = iterator.next(); !result.done; result = iterator.next())
|
||||
onEviction(keyList[result.value], valList[result.value]);
|
||||
}
|
||||
keyMap.clear();
|
||||
keyList.fill(void 0);
|
||||
valList.fill(void 0);
|
||||
free = [];
|
||||
size = 0;
|
||||
head = tail = 0;
|
||||
},
|
||||
/** Resizes the cache to a new maximum size, evicting items if necessary. */
|
||||
resize: (newMax) => {
|
||||
if (!(Number.isInteger(newMax) && newMax > 0))
|
||||
throw new TypeError("`max` must be a positive integer");
|
||||
if (newMax === max) return;
|
||||
if (newMax < max) {
|
||||
let current = tail;
|
||||
const preserve = Math.min(size, newMax);
|
||||
const remove = size - preserve;
|
||||
const newKeyList = new Array(newMax);
|
||||
const newValList = new Array(newMax);
|
||||
const newNext = new Array(newMax);
|
||||
const newPrev = new Array(newMax);
|
||||
for (let i = 1; i <= remove; i++)
|
||||
onEviction == null ? void 0 : onEviction(keyList[i], valList[i]);
|
||||
for (let i = preserve - 1; i >= 0; i--) {
|
||||
newKeyList[i] = keyList[current];
|
||||
newValList[i] = valList[current];
|
||||
newNext[i] = i + 1;
|
||||
newPrev[i] = i - 1;
|
||||
keyMap.set(newKeyList[i], i);
|
||||
current = prev[current];
|
||||
}
|
||||
head = 0;
|
||||
tail = preserve - 1;
|
||||
size = preserve;
|
||||
keyList.length = newMax;
|
||||
valList.length = newMax;
|
||||
next.length = newMax;
|
||||
prev.length = newMax;
|
||||
for (let i = 0; i < preserve; i++) {
|
||||
keyList[i] = newKeyList[i];
|
||||
valList[i] = newValList[i];
|
||||
next[i] = newNext[i];
|
||||
prev[i] = newPrev[i];
|
||||
}
|
||||
free = [];
|
||||
for (let i = preserve; i < newMax; i++) free.push(i);
|
||||
} else {
|
||||
const fill = newMax - max;
|
||||
keyList.push(...new Array(fill).fill(void 0));
|
||||
valList.push(...new Array(fill).fill(void 0));
|
||||
next.push(...new Array(fill).fill(0));
|
||||
prev.push(...new Array(fill).fill(0));
|
||||
}
|
||||
max = newMax;
|
||||
},
|
||||
/** Returns the maximum number of items that can be stored in the cache. */
|
||||
get max() {
|
||||
return max;
|
||||
},
|
||||
/** Returns the number of items currently stored in the cache. */
|
||||
get size() {
|
||||
return size;
|
||||
},
|
||||
/** Returns the number of currently available slots in the cache before reaching the maximum size. */
|
||||
get available() {
|
||||
return max - size;
|
||||
}
|
||||
};
|
||||
};
|
||||
export {
|
||||
createLRU
|
||||
};
|
89
administration/backend/node_modules/lru.min/package.json
generated
vendored
Normal file
89
administration/backend/node_modules/lru.min/package.json
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
{
|
||||
"name": "lru.min",
|
||||
"version": "1.1.2",
|
||||
"description": "🔥 An extremely fast and efficient LRU cache for JavaScript with high compatibility (including Browsers) — 6.8KB.",
|
||||
"main": "./lib/index.js",
|
||||
"module": "./lib/index.mjs",
|
||||
"types": "./lib/index.d.ts",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/wellwelwel/lru.min.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/wellwelwel/lru.min/issues"
|
||||
},
|
||||
"author": "https://github.com/wellwelwel",
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/wellwelwel"
|
||||
},
|
||||
"files": [
|
||||
"browser",
|
||||
"lib"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=8.0.0",
|
||||
"bun": ">=1.0.0",
|
||||
"deno": ">=1.30.0"
|
||||
},
|
||||
"scripts": {
|
||||
"benchmark:esm": "cd benchmark && npm ci && node index.mjs",
|
||||
"benchmark:cjs": "cd benchmark && npm ci && node index.cjs",
|
||||
"prebuild": "rm -rf ./browser ./lib",
|
||||
"build:browser": "tsx tools/browserfy.ts",
|
||||
"build:esm": "esbuild src/index.ts --outfile=lib/index.mjs --platform=node --target=node12 --format=esm",
|
||||
"build": "tsc && npm run build:esm && npm run build:browser",
|
||||
"test:node": "poku",
|
||||
"test:bun": "bun poku",
|
||||
"test:deno": "deno run -A npm:poku",
|
||||
"test:coverage": "mcr --import tsx --config mcr.config.ts npm run test:node",
|
||||
"lint": "npx @biomejs/biome lint && prettier --check .",
|
||||
"lint:fix": "npx @biomejs/biome lint --write && prettier --write .github/workflows/*.yml .",
|
||||
"update": "pu minor && npm i && npm audit fix",
|
||||
"postupdate": "npm run lint:fix",
|
||||
"size": "ls -lh lib/index.mjs | awk '{print $5}'"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.26.9",
|
||||
"@babel/preset-env": "^7.26.9",
|
||||
"@biomejs/biome": "^1.9.4",
|
||||
"@types/babel__core": "^7.20.5",
|
||||
"@types/node": "^22.13.10",
|
||||
"esbuild": "^0.25.0",
|
||||
"monocart-coverage-reports": "2.12.1",
|
||||
"packages-update": "^2.0.0",
|
||||
"poku": "^3.0.1",
|
||||
"prettier": "^3.5.3",
|
||||
"terser": "^5.39.0",
|
||||
"tsx": "^4.19.3",
|
||||
"typescript": "^5.8.2"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"import": {
|
||||
"types": "./lib/index.d.ts",
|
||||
"default": "./lib/index.mjs"
|
||||
},
|
||||
"require": {
|
||||
"types": "./lib/index.d.ts",
|
||||
"default": "./lib/index.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"keywords": [
|
||||
"lru",
|
||||
"cache",
|
||||
"caching",
|
||||
"hash",
|
||||
"node",
|
||||
"nodejs",
|
||||
"bun",
|
||||
"deno",
|
||||
"typescript",
|
||||
"browser",
|
||||
"fast",
|
||||
"lru-cache",
|
||||
"quick-lru"
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user