tsoa
This commit is contained in:
11
node_modules/@hapi/catbox-memory/LICENSE.md
generated
vendored
Executable file
11
node_modules/@hapi/catbox-memory/LICENSE.md
generated
vendored
Executable file
@@ -0,0 +1,11 @@
|
||||
Copyright (c) 2012-2022, Project contributors
|
||||
Copyright (c) 2012-2020, Sideway Inc
|
||||
Copyright (c) 2012-2014, Walmart.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* The names of any contributors may not be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS OFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
17
node_modules/@hapi/catbox-memory/README.md
generated
vendored
Executable file
17
node_modules/@hapi/catbox-memory/README.md
generated
vendored
Executable file
@@ -0,0 +1,17 @@
|
||||
<a href="https://hapi.dev"><img src="https://raw.githubusercontent.com/hapijs/assets/master/images/family.png" width="180px" align="right" /></a>
|
||||
|
||||
# @hapi/catbox-memory
|
||||
|
||||
#### Memory adaptor for [catbox](https://github.com/hapijs/catbox).
|
||||
|
||||
**catbox-memory** is part of the **hapi** ecosystem and was designed to work seamlessly with the [hapi web framework](https://hapi.dev) and its other components (but works great on its own or with other frameworks). If you are using a different web framework and find this module useful, check out [hapi](https://hapi.dev) – they work even better together.
|
||||
|
||||
### Visit the [hapi.dev](https://hapi.dev) Developer Portal for tutorials, documentation, and support
|
||||
|
||||
## Useful resources
|
||||
|
||||
- [Documentation and API](https://hapi.dev/family/catbox-memory/)
|
||||
- [Versions status](https://hapi.dev/resources/status/#catbox-memory) (builds, dependencies, node versions, licenses, eol)
|
||||
- [Changelog](https://hapi.dev/family/catbox-memory/changelog/)
|
||||
- [Project policies](https://hapi.dev/policies/)
|
||||
- [Free and commercial support options](https://hapi.dev/support/)
|
||||
33
node_modules/@hapi/catbox-memory/lib/index.d.ts
generated
vendored
Normal file
33
node_modules/@hapi/catbox-memory/lib/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
import { ClientApi, ClientOptions } from '@hapi/catbox';
|
||||
|
||||
interface Engine<T> extends ClientApi<T> {}
|
||||
|
||||
declare class Engine<T> implements ClientApi<T> {
|
||||
constructor(options?: Engine.Options);
|
||||
}
|
||||
|
||||
declare namespace Engine {
|
||||
interface Options extends ClientOptions {
|
||||
/**
|
||||
* Sets an upper limit on the number of bytes that can be stored in the cache.
|
||||
* Once this limit is reached no additional items will be added to the cache until some expire.
|
||||
* The utilized memory calculation is a rough approximation and must not be relied on.
|
||||
* @default 104857600 (100MB).
|
||||
*/
|
||||
maxByteSize?: number;
|
||||
/**
|
||||
* The minimum number of milliseconds in between each cache cleanup.
|
||||
* @default 1000 (1 second)
|
||||
*/
|
||||
minCleanupIntervalMsec?: number;
|
||||
/**
|
||||
* by default, buffers stored in the cache with allowMixedContent set to true are copied when they are set but not when they are retrieved.
|
||||
* This means a change to the buffer returned by a get() will change the value in the cache. To prevent this,
|
||||
* set cloneBuffersOnGet to true to always return a copy of the cached buffer.
|
||||
* @default false
|
||||
*/
|
||||
cloneBuffersOnGet?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
export { Engine };
|
||||
230
node_modules/@hapi/catbox-memory/lib/index.js
generated
vendored
Executable file
230
node_modules/@hapi/catbox-memory/lib/index.js
generated
vendored
Executable file
@@ -0,0 +1,230 @@
|
||||
'use strict';
|
||||
|
||||
const Boom = require('@hapi/boom');
|
||||
const Hoek = require('@hapi/hoek');
|
||||
|
||||
|
||||
const internals = {
|
||||
maxTimer: 2147483647, // 2 ^ 31 - 1
|
||||
entrySize: 144 // Approximate cache entry size without value: 144 bytes
|
||||
};
|
||||
|
||||
|
||||
internals.defaults = {
|
||||
maxByteSize: 100 * 1024 * 1024, // 100MB
|
||||
minCleanupIntervalMsec: 1000,
|
||||
cloneBuffersOnGet: false
|
||||
};
|
||||
|
||||
|
||||
exports.Engine = class CatboxMemoryEngine {
|
||||
|
||||
constructor(options = {}) {
|
||||
|
||||
Hoek.assert(options.maxByteSize === undefined || options.maxByteSize >= 0, 'Invalid cache maxByteSize value');
|
||||
Hoek.assert(options.allowMixedContent === undefined, 'allowMixedContent no longer supported');
|
||||
Hoek.assert(options.minCleanupIntervalMsec === undefined || options.minCleanupIntervalMsec < internals.maxTimer, 'Invalid cache minCleanupIntervalMsec value');
|
||||
Hoek.assert(options.cloneBuffersOnGet === undefined || typeof options.cloneBuffersOnGet === 'boolean', 'Invalid cloneBuffersOnGet value');
|
||||
|
||||
this.settings = Hoek.applyToDefaults(internals.defaults, options);
|
||||
this.cache = null;
|
||||
|
||||
this._timer = null;
|
||||
this._timerDue = null;
|
||||
}
|
||||
|
||||
start() {
|
||||
|
||||
if (!this.cache) {
|
||||
this.cache = new Map();
|
||||
this.byteSize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
_scheduleCleanup(msec) {
|
||||
|
||||
const cleanup = () => {
|
||||
|
||||
this._timer = null;
|
||||
this._timerDue = null;
|
||||
|
||||
const now = Date.now();
|
||||
let next = Infinity;
|
||||
for (const [, segment] of this.cache) {
|
||||
for (const [id, envelope] of segment) {
|
||||
const ttl = envelope.stored + envelope.ttl - now;
|
||||
if (ttl <= 0) {
|
||||
segment.delete(id);
|
||||
this.byteSize -= envelope.byteSize;
|
||||
}
|
||||
else {
|
||||
next = Math.min(next, ttl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (next !== Infinity) {
|
||||
this._scheduleCleanup(next);
|
||||
}
|
||||
};
|
||||
|
||||
const now = Date.now();
|
||||
const timeout = Math.min(Math.max(this.settings.minCleanupIntervalMsec, msec), internals.maxTimer);
|
||||
if (this._timer) {
|
||||
if (this._timerDue - now < msec) {
|
||||
return;
|
||||
}
|
||||
|
||||
clearTimeout(this._timer);
|
||||
}
|
||||
|
||||
this._timerDue = now + timeout;
|
||||
this._timer = setTimeout(cleanup, timeout);
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
||||
clearTimeout(this._timer);
|
||||
this._timer = null;
|
||||
this._timerDue = null;
|
||||
|
||||
this.cache = null;
|
||||
this.byteSize = 0;
|
||||
}
|
||||
|
||||
isReady() {
|
||||
|
||||
return !!this.cache;
|
||||
}
|
||||
|
||||
validateSegmentName(name) {
|
||||
|
||||
if (!name) {
|
||||
throw new Boom.Boom('Empty string');
|
||||
}
|
||||
|
||||
if (name.indexOf('\u0000') !== -1) {
|
||||
throw new Boom.Boom('Includes null character');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
get(key) {
|
||||
|
||||
if (!this.cache) {
|
||||
throw new Boom.Boom('Connection not started');
|
||||
}
|
||||
|
||||
const segment = this.cache.get(key.segment);
|
||||
if (!segment) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const envelope = segment.get(key.id);
|
||||
if (!envelope) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (envelope.stored + envelope.ttl < Date.now()) {
|
||||
this.drop(key);
|
||||
return null;
|
||||
}
|
||||
|
||||
let item = null;
|
||||
if (Buffer.isBuffer(envelope.item)) {
|
||||
item = envelope.item;
|
||||
if (this.settings.cloneBuffersOnGet) {
|
||||
const copy = Buffer.alloc(item.length);
|
||||
item.copy(copy);
|
||||
item = copy;
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
item = JSON.parse(envelope.item);
|
||||
}
|
||||
catch (err) {
|
||||
throw new Boom.Boom('Bad value content');
|
||||
}
|
||||
}
|
||||
|
||||
const result = {
|
||||
item,
|
||||
stored: envelope.stored,
|
||||
ttl: envelope.ttl
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
set(key, value, ttl) {
|
||||
|
||||
if (!this.cache) {
|
||||
throw new Boom.Boom('Connection not started');
|
||||
}
|
||||
|
||||
const envelope = new internals.MemoryCacheEntry(key, value, ttl);
|
||||
|
||||
let segment = this.cache.get(key.segment);
|
||||
if (!segment) {
|
||||
segment = new Map();
|
||||
this.cache.set(key.segment, segment);
|
||||
}
|
||||
|
||||
const cachedItem = segment.get(key.id);
|
||||
if (cachedItem) {
|
||||
this.byteSize -= cachedItem.byteSize; // If the item existed, decrement the byteSize as the value could be different
|
||||
}
|
||||
|
||||
if (this.settings.maxByteSize &&
|
||||
(this.byteSize + envelope.byteSize > this.settings.maxByteSize)) {
|
||||
|
||||
throw new Boom.Boom('Cache size limit reached');
|
||||
}
|
||||
|
||||
this._scheduleCleanup(ttl);
|
||||
segment.set(key.id, envelope);
|
||||
this.byteSize += envelope.byteSize;
|
||||
}
|
||||
|
||||
drop(key) {
|
||||
|
||||
if (!this.cache) {
|
||||
throw new Boom.Boom('Connection not started');
|
||||
}
|
||||
|
||||
const segment = this.cache.get(key.segment);
|
||||
if (segment) {
|
||||
const item = segment.get(key.id);
|
||||
if (item) {
|
||||
this.byteSize -= item.byteSize;
|
||||
segment.delete(key.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
internals.MemoryCacheEntry = class {
|
||||
|
||||
constructor(key, value, ttl) {
|
||||
|
||||
let valueByteSize = 0;
|
||||
|
||||
if (Buffer.isBuffer(value)) {
|
||||
this.item = Buffer.alloc(value.length);
|
||||
value.copy(this.item); // Copy buffer to prevent value from changing while in the cache
|
||||
valueByteSize = this.item.length;
|
||||
}
|
||||
else {
|
||||
this.item = JSON.stringify(value); // stringify() to prevent value from changing while in the cache
|
||||
valueByteSize = Buffer.byteLength(this.item);
|
||||
}
|
||||
|
||||
this.stored = Date.now();
|
||||
this.ttl = ttl;
|
||||
this.byteSize = internals.entrySize + valueByteSize + Buffer.byteLength(key.segment) + Buffer.byteLength(key.id);
|
||||
this.timeoutId = null;
|
||||
}
|
||||
};
|
||||
38
node_modules/@hapi/catbox-memory/package.json
generated
vendored
Normal file
38
node_modules/@hapi/catbox-memory/package.json
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "@hapi/catbox-memory",
|
||||
"description": "Memory adapter for catbox",
|
||||
"version": "6.0.2",
|
||||
"repository": "git://github.com/hapijs/catbox-memory",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"keywords": [
|
||||
"cache",
|
||||
"catbox",
|
||||
"memory"
|
||||
],
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"plugin:@hapi/module"
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"@hapi/boom": "^10.0.1",
|
||||
"@hapi/hoek": "^11.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@hapi/catbox": "^12.1.1",
|
||||
"@hapi/code": "^9.0.3",
|
||||
"@hapi/eslint-plugin": "*",
|
||||
"@hapi/lab": "^25.1.2",
|
||||
"@types/node": "^16.18.98",
|
||||
"typescript": "^5.4.5"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "lab -a @hapi/code -L -t 100 -Y",
|
||||
"test-cov-html": "lab -a @hapi/code -r html -o coverage.html"
|
||||
},
|
||||
"license": "BSD-3-Clause"
|
||||
}
|
||||
Reference in New Issue
Block a user