initial commit

This commit is contained in:
2025-09-01 22:12:29 +02:00
parent b1873f9c1d
commit 02a54f61c0
5598 changed files with 903558 additions and 0 deletions

41
server/node_modules/lru-memoizer/.jshintrc generated vendored Normal file
View File

@@ -0,0 +1,41 @@
{
"camelcase": false,
"curly": false,
"node": true,
"esnext": true,
"bitwise": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
"latedef": false,
"newcap": true,
"noarg": true,
"regexp": true,
"undef": true,
"strict": false,
"smarttabs": true,
"expr": true,
"evil": true,
"browser": true,
"regexdash": true,
"wsh": true,
"trailing": true,
"sub": true,
"unused": true,
"laxcomma": true,
"nonbsp": true,
"newcap": false,
"globals": {
"after": false,
"before": false,
"afterEach": false,
"beforeEach": false,
"describe": false,
"it": false,
"escape": false
}
}

21
server/node_modules/lru-memoizer/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 JOSE FERNANDO ROMANIELLO <jfromaniello@gmail.com> (http://joseoncode.com)
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.

88
server/node_modules/lru-memoizer/README.md generated vendored Normal file
View File

@@ -0,0 +1,88 @@
Memoize functions results using an lru-cache.
## Installation
```
npm i lru-memoizer --save
```
## Intro
This module uses an [lru-cache](https://github.com/isaacs/node-lru-cache) internally to cache the results of an async function.
The `load` function can have N parameters and the last one must be a callback. The callback should be an errback (first parameter is `err`).
The `hash` function purpose is generate a custom hash for storing results. It has all the arguments applied to it minus the callback, and must return an string synchronous.
The `disable` function allows you to conditionally disable the use of the cache. Useful for test environments.
The `freeze` option (defaults to **false**) allows you to deep-freeze the result of the async function.
The `clone` option (defaults to **false**) allows you to deep-clone the result every time is returned from the cache.
## Usage
```javascript
var memoizer = require('lru-memoizer');
var memoizedGet = memoizer({
//defines how to load the resource when
//it is not in the cache.
load: function (options, callback) {
request.get(options, callback);
},
//defines how to create a cache key from the params.
hash: function (options) {
return options.url + qs.stringify(options.qs);
},
//don't cache in test environment
disable: isTestEnv(),
//all other params for the LRU cache.
max: 100,
maxAge: 1000 * 60
});
memoizedGet({
url: 'https://google.com',
qs: { foo: 123 }
}, function (err, result, body) {
//console.log(body);
})
```
## Sync lru-memoizer
Use `memoizer.sync` to cache things that are slow to calculate or methods returning promises.
```
var memoizer = require('lru-memoizer');
var memoizedGet = memoizer.sync({
//defines how to load the resource when
//it is not in the cache.
load: function (params) {
//return something_hard_to_compute;s
},
//defines how to create a cache key from the params.
hash: function (params) {
return params.foo;
},
//all other params for the LRU cache.
max: 100,
maxAge: 1000 * 60
});
```
## Similar modules
This module is very similar to [async-cache](https://github.com/isaacs/async-cache), the main difference is the `hash` function.
## License
MIT 2016 - José F. Romaniello

85
server/node_modules/lru-memoizer/lib/async.d.ts generated vendored Normal file
View File

@@ -0,0 +1,85 @@
import { syncMemoizer } from './sync';
import { INodeStyleCallBack as CB, ResultBase, IParamsBase0, IParamsBase1, IParamsBase2, IParamsBase3, IParamsBase4, IParamsBase5, IParamsBase6 } from './util';
export interface IMemoized<T1, T2, T3, T4, T5, T6, TResult> extends ResultBase {
(cb: CB<TResult>): void;
(a1: T1, cb: CB<TResult>): void;
(a1: T1, a2: T2, cb: CB<TResult>): void;
(a1: T1, a2: T2, a3: T3, cb: CB<TResult>): void;
(a1: T1, a2: T2, a3: T3, a4: T4, cb: CB<TResult>): void;
(a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, cb: CB<TResult>): void;
(a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, cb: CB<TResult>): void;
}
interface IMemoizableFunction0<TResult> {
(cb: CB<TResult>): void;
}
interface IMemoizableFunction1<T1, TResult> {
(a1: T1, cb: CB<TResult>): void;
}
interface IMemoizableFunction2<T1, T2, TResult> {
(a1: T1, a2: T2, cb: CB<TResult>): void;
}
interface IMemoizableFunction3<T1, T2, T3, TResult> {
(a1: T1, a2: T2, a3: T3, cb: CB<TResult>): void;
}
interface IMemoizableFunction4<T1, T2, T3, T4, TResult> {
(a1: T1, a2: T2, a3: T3, a4: T4, cb: CB<TResult>): void;
}
interface IMemoizableFunction5<T1, T2, T3, T4, T5, TResult> {
(a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, cb: CB<TResult>): void;
}
interface IMemoizableFunction6<T1, T2, T3, T4, T5, T6, TResult> {
(a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, cb: CB<TResult>): void;
}
interface AsyncParams0<TResult> extends IParamsBase0<TResult> {
load: IMemoizableFunction0<TResult>;
}
interface AsyncParams1<T1, TResult> extends IParamsBase1<T1, TResult> {
load: IMemoizableFunction1<T1, TResult>;
}
interface AsyncParams2<T1, T2, TResult> extends IParamsBase2<T1, T2, TResult> {
load: IMemoizableFunction2<T1, T2, TResult>;
}
interface AsyncParams3<T1, T2, T3, TResult> extends IParamsBase3<T1, T2, T3, TResult> {
load: IMemoizableFunction3<T1, T2, T3, TResult>;
}
interface AsyncParams4<T1, T2, T3, T4, TResult> extends IParamsBase4<T1, T2, T3, T4, TResult> {
load: IMemoizableFunction4<T1, T2, T3, T4, TResult>;
}
interface AsyncParams5<T1, T2, T3, T4, T5, TResult> extends IParamsBase5<T1, T2, T3, T4, T5, TResult> {
load: IMemoizableFunction5<T1, T2, T3, T4, T5, TResult>;
}
interface AsyncParams6<T1, T2, T3, T4, T5, T6, TResult> extends IParamsBase6<T1, T2, T3, T4, T5, T6, TResult> {
/**
* The function that loads the resource when is not in the cache.
*/
load: IMemoizableFunction6<T1, T2, T3, T4, T5, T6, TResult>;
}
declare function asyncMemoizer<TResult>(options: AsyncParams0<TResult>): IMemoized<unknown, unknown, unknown, unknown, unknown, unknown, TResult>;
declare namespace asyncMemoizer {
var sync: typeof syncMemoizer;
}
declare function asyncMemoizer<T1, TResult>(options: AsyncParams1<T1, TResult>): IMemoized<T1, unknown, unknown, unknown, unknown, unknown, TResult>;
declare namespace asyncMemoizer {
var sync: typeof syncMemoizer;
}
declare function asyncMemoizer<T1, T2, TResult>(options: AsyncParams2<T1, T2, TResult>): IMemoized<T1, T2, unknown, unknown, unknown, unknown, TResult>;
declare namespace asyncMemoizer {
var sync: typeof syncMemoizer;
}
declare function asyncMemoizer<T1, T2, T3, TResult>(options: AsyncParams3<T1, T2, T3, TResult>): IMemoized<T1, T2, T3, unknown, unknown, unknown, TResult>;
declare namespace asyncMemoizer {
var sync: typeof syncMemoizer;
}
declare function asyncMemoizer<T1, T2, T3, T4, TResult>(options: AsyncParams4<T1, T2, T3, T4, TResult>): IMemoized<T1, T2, T3, T4, unknown, unknown, TResult>;
declare namespace asyncMemoizer {
var sync: typeof syncMemoizer;
}
declare function asyncMemoizer<T1, T2, T3, T4, T5, TResult>(options: AsyncParams5<T1, T2, T3, T4, T5, TResult>): IMemoized<T1, T2, T3, T4, T5, unknown, TResult>;
declare namespace asyncMemoizer {
var sync: typeof syncMemoizer;
}
declare function asyncMemoizer<T1, T2, T3, T4, T5, T6, TResult>(options: AsyncParams6<T1, T2, T3, T4, T5, T6, TResult>): IMemoized<T1, T2, T3, T4, T5, T6, TResult>;
declare namespace asyncMemoizer {
var sync: typeof syncMemoizer;
}
export { asyncMemoizer };

178
server/node_modules/lru-memoizer/lib/async.js generated vendored Normal file

File diff suppressed because one or more lines are too long

1
server/node_modules/lru-memoizer/lib/freeze.d.ts generated vendored Normal file
View File

@@ -0,0 +1 @@
export declare function deepFreeze(o: any): any;

23
server/node_modules/lru-memoizer/lib/freeze.js generated vendored Normal file
View File

@@ -0,0 +1,23 @@
"use strict";
// From https://raw.githubusercontent.com/nikoskalogridis/deep-freeze/fb921b32064dce1645197be2bf975fe0385450b0/index.js
// which is sadly, no longer maintained
Object.defineProperty(exports, "__esModule", { value: true });
exports.deepFreeze = void 0;
function deepFreeze(o) {
if (o) {
Object.freeze(o);
Object.getOwnPropertyNames(o).forEach(function (prop) {
if (o.hasOwnProperty(prop)
&& o[prop] !== null
&& (typeof o[prop] === 'object' || typeof o[prop] === 'function')
&& (o[prop].constructor !== Buffer)
&& !Object.isFrozen(o[prop])) {
deepFreeze(o[prop]);
}
});
}
return o;
}
exports.deepFreeze = deepFreeze;
;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZnJlZXplLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2ZyZWV6ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsdUhBQXVIO0FBQ3ZILHVDQUF1Qzs7O0FBRXZDLFNBQWdCLFVBQVUsQ0FBRSxDQUFNO0lBQ2hDLElBQUksQ0FBQyxFQUFFO1FBQ0wsTUFBTSxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUMsQ0FBQztRQUVqQixNQUFNLENBQUMsbUJBQW1CLENBQUMsQ0FBQyxDQUFDLENBQUMsT0FBTyxDQUFDLFVBQVUsSUFBSTtZQUNsRCxJQUFJLENBQUMsQ0FBQyxjQUFjLENBQUMsSUFBSSxDQUFDO21CQUNyQixDQUFDLENBQUMsSUFBSSxDQUFDLEtBQUssSUFBSTttQkFDaEIsQ0FBQyxPQUFPLENBQUMsQ0FBQyxJQUFJLENBQUMsS0FBSyxRQUFRLElBQUksT0FBTyxDQUFDLENBQUMsSUFBSSxDQUFDLEtBQUssVUFBVSxDQUFDO21CQUM5RCxDQUFDLENBQUMsQ0FBQyxJQUFJLENBQUMsQ0FBQyxXQUFXLEtBQUssTUFBTSxDQUFDO21CQUNoQyxDQUFDLE1BQU0sQ0FBQyxRQUFRLENBQUMsQ0FBQyxDQUFDLElBQUksQ0FBQyxDQUFDLEVBQUU7Z0JBQzVCLFVBQVUsQ0FBQyxDQUFDLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQzthQUNyQjtRQUNMLENBQUMsQ0FBQyxDQUFDO0tBQ0o7SUFFRCxPQUFPLENBQUMsQ0FBQztBQUNYLENBQUM7QUFoQkQsZ0NBZ0JDO0FBQUEsQ0FBQyJ9

2
server/node_modules/lru-memoizer/lib/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import { asyncMemoizer } from './async';
export = asyncMemoizer;

4
server/node_modules/lru-memoizer/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,4 @@
"use strict";
var async_1 = require("./async");
module.exports = async_1.asyncMemoizer;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLGlDQUF3QztBQUV4QyxpQkFBUyxxQkFBYSxDQUFDIn0=

65
server/node_modules/lru-memoizer/lib/sync.d.ts generated vendored Normal file
View File

@@ -0,0 +1,65 @@
import { ResultBase, IParamsBase0, IParamsBase1, IParamsBase2, IParamsBase3, IParamsBase4, IParamsBase5, IParamsBase6, IParamsBasePlus } from './util';
interface IMemoizedSync<T1, T2, T3, T4, T5, T6, TResult> extends ResultBase {
(arg1: T1): TResult;
(arg1: T1, arg2: T2): TResult;
(arg1: T1, arg2: T2, arg3: T3): TResult;
(arg1: T1, arg2: T2, arg3: T3, arg4: T4): TResult;
(arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5): TResult;
(arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6): TResult;
}
interface IMemoizableFunctionSync0<TResult> {
(): TResult;
}
interface IMemoizableFunctionSync1<T1, TResult> {
(arg1: T1): TResult;
}
interface IMemoizableFunctionSync2<T1, T2, TResult> {
(arg1: T1, arg2: T2): TResult;
}
interface IMemoizableFunctionSync3<T1, T2, T3, TResult> {
(arg1: T1, arg2: T2, arg3: T3): TResult;
}
interface IMemoizableFunctionSync4<T1, T2, T3, T4, TResult> {
(arg1: T1, arg2: T2, arg3: T3, arg4: T4): TResult;
}
interface IMemoizableFunctionSync5<T1, T2, T3, T4, T5, TResult> {
(arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5): TResult;
}
interface IMemoizableFunctionSync6<T1, T2, T3, T4, T5, T6, TResult> {
(a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6): TResult;
}
interface IMemoizableFunctionSyncPlus<TResult> {
(...args: any[]): TResult;
}
export interface SyncParams0<TResult> extends IParamsBase0<TResult> {
load: IMemoizableFunctionSync0<TResult>;
}
export interface SyncParams1<T1, TResult> extends IParamsBase1<T1, TResult> {
load: IMemoizableFunctionSync1<T1, TResult>;
}
export interface SyncParams2<T1, T2, TResult> extends IParamsBase2<T1, T2, TResult> {
load: IMemoizableFunctionSync2<T1, T2, TResult>;
}
export interface SyncParams3<T1, T2, T3, TResult> extends IParamsBase3<T1, T2, T3, TResult> {
load: IMemoizableFunctionSync3<T1, T2, T3, TResult>;
}
export interface SyncParams4<T1, T2, T3, T4, TResult> extends IParamsBase4<T1, T2, T3, T4, TResult> {
load: IMemoizableFunctionSync4<T1, T2, T3, T4, TResult>;
}
export interface SyncParams5<T1, T2, T3, T4, T5, TResult> extends IParamsBase5<T1, T2, T3, T4, T5, TResult> {
load: IMemoizableFunctionSync5<T1, T2, T3, T4, T5, TResult>;
}
export interface SyncParams6<T1, T2, T3, T4, T5, T6, TResult> extends IParamsBase6<T1, T2, T3, T4, T5, T6, TResult> {
load: IMemoizableFunctionSync6<T1, T2, T3, T4, T5, T6, TResult>;
}
export interface SyncParamsPlus<TResult> extends IParamsBasePlus {
load: IMemoizableFunctionSyncPlus<TResult>;
}
export declare function syncMemoizer<TResult>(options: SyncParams0<TResult>): IMemoizedSync<unknown, unknown, unknown, unknown, unknown, unknown, TResult>;
export declare function syncMemoizer<T1, TResult>(options: SyncParams1<T1, TResult>): IMemoizedSync<T1, unknown, unknown, unknown, unknown, unknown, TResult>;
export declare function syncMemoizer<T1, T2, TResult>(options: SyncParams2<T1, T2, TResult>): IMemoizedSync<T1, T2, unknown, unknown, unknown, unknown, TResult>;
export declare function syncMemoizer<T1, T2, T3, TResult>(options: SyncParams3<T1, T2, T3, TResult>): IMemoizedSync<T1, T2, T3, unknown, unknown, unknown, TResult>;
export declare function syncMemoizer<T1, T2, T3, T4, TResult>(options: SyncParams4<T1, T2, T3, T4, TResult>): IMemoizedSync<T1, T2, T3, T4, unknown, unknown, TResult>;
export declare function syncMemoizer<T1, T2, T3, T4, T5, TResult>(options: SyncParams5<T1, T2, T3, T4, T5, TResult>): IMemoizedSync<T1, T2, T3, T4, T5, unknown, TResult>;
export declare function syncMemoizer<T1, T2, T3, T4, T5, T6, TResult>(options: SyncParams6<T1, T2, T3, T4, T5, T6, TResult>): IMemoizedSync<T1, T2, T3, T4, T5, T6, TResult>;
export {};

114
server/node_modules/lru-memoizer/lib/sync.js generated vendored Normal file
View File

@@ -0,0 +1,114 @@
"use strict";
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.syncMemoizer = void 0;
var lru_cache_1 = __importDefault(require("lru-cache"));
var events_1 = require("events");
var lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
var freeze_1 = require("./freeze");
function syncMemoizer(options) {
var cache = new lru_cache_1.default(options);
var load = options.load;
var hash = options.hash;
var bypass = options.bypass;
var itemMaxAge = options.itemMaxAge;
var freeze = options.freeze;
var clone = options.clone;
var emitter = new events_1.EventEmitter();
var defaultResult = Object.assign({
del: del,
reset: function () { return cache.reset(); },
keys: cache.keys.bind(cache),
on: emitter.on.bind(emitter),
once: emitter.once.bind(emitter),
}, options);
if (options.disable) {
return Object.assign(load, defaultResult);
}
function del() {
var key = hash.apply(void 0, __spread(arguments));
cache.del(key);
}
function emit(event) {
var parameters = [];
for (var _i = 1; _i < arguments.length; _i++) {
parameters[_i - 1] = arguments[_i];
}
emitter.emit.apply(emitter, __spread([event], parameters));
}
function isPromise(result) {
// detect native, bluebird, A+ promises
return result && result.then && typeof result.then === 'function';
}
function processResult(result) {
var res = result;
if (clone) {
if (isPromise(res)) {
res = res.then(lodash_clonedeep_1.default);
}
else {
res = lodash_clonedeep_1.default(res);
}
}
if (freeze) {
if (isPromise(res)) {
res = res.then(freeze_1.deepFreeze);
}
else {
freeze_1.deepFreeze(res);
}
}
return res;
}
var result = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (bypass && bypass.apply(void 0, __spread(args))) {
emit.apply(void 0, __spread(['miss'], args));
return load.apply(void 0, __spread(args));
}
var key = hash.apply(void 0, __spread(args));
var fromCache = cache.get(key);
if (fromCache) {
emit.apply(void 0, __spread(['hit'], args));
return processResult(fromCache);
}
emit.apply(void 0, __spread(['miss'], args));
var result = load.apply(void 0, __spread(args));
if (itemMaxAge) {
// @ts-ignore
cache.set(key, result, itemMaxAge.apply(void 0, __spread(args.concat([result]))));
}
else {
cache.set(key, result);
}
return processResult(result);
};
return Object.assign(result, defaultResult);
}
exports.syncMemoizer = syncMemoizer;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3luYy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9zeW5jLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBQUEsd0RBQTRCO0FBQzVCLGlDQUFzQztBQUN0QyxzRUFBeUM7QUFDekMsbUNBQXNDO0FBaUd0QyxTQUFnQixZQUFZLENBQzFCLE9BQWdDO0lBRWhDLElBQU0sS0FBSyxHQUFRLElBQUksbUJBQUcsQ0FBQyxPQUFPLENBQUMsQ0FBQztJQUNwQyxJQUFNLElBQUksR0FBUyxPQUFPLENBQUMsSUFBSSxDQUFDO0lBQ2hDLElBQU0sSUFBSSxHQUFTLE9BQU8sQ0FBQyxJQUFJLENBQUM7SUFDaEMsSUFBTSxNQUFNLEdBQU8sT0FBTyxDQUFDLE1BQU0sQ0FBQztJQUNsQyxJQUFNLFVBQVUsR0FBRyxPQUFPLENBQUMsVUFBVSxDQUFDO0lBQ3RDLElBQU0sTUFBTSxHQUFPLE9BQU8sQ0FBQyxNQUFNLENBQUM7SUFDbEMsSUFBTSxLQUFLLEdBQVEsT0FBTyxDQUFDLEtBQUssQ0FBQztJQUNqQyxJQUFNLE9BQU8sR0FBTSxJQUFJLHFCQUFZLEVBQUUsQ0FBQztJQUV0QyxJQUFNLGFBQWEsR0FBRyxNQUFNLENBQUMsTUFBTSxDQUFDO1FBQ2xDLEdBQUcsS0FBQTtRQUNILEtBQUssRUFBRSxjQUFNLE9BQUEsS0FBSyxDQUFDLEtBQUssRUFBRSxFQUFiLENBQWE7UUFDMUIsSUFBSSxFQUFFLEtBQUssQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQztRQUM1QixFQUFFLEVBQUUsT0FBTyxDQUFDLEVBQUUsQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDO1FBQzVCLElBQUksRUFBRSxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7S0FDakMsRUFBRSxPQUFPLENBQUMsQ0FBQztJQUVaLElBQUksT0FBTyxDQUFDLE9BQU8sRUFBRTtRQUNuQixPQUFPLE1BQU0sQ0FB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

162
server/node_modules/lru-memoizer/lib/util.d.ts generated vendored Normal file
View File

@@ -0,0 +1,162 @@
import LRU from 'lru-cache';
export declare type Listener = (...as: any[]) => void;
export declare type INodeStyleCallBack<Success> = (err: Error | null, result?: Success) => void;
export interface ResultBase {
/**
* Returns all keys in the cache.
*/
keys: () => string[];
/**
* Clear the cache.
*/
reset: () => void;
/**
* Delete an item given the parameters.
*/
del: <T1, T2, T3, T4, T5, T6>(a1?: T1, a2?: T2, a3?: T3, a4?: T4, a5?: T5, a6?: T6) => void;
on(event: 'hit', handler: Listener): void;
on(event: 'miss', handler: Listener): void;
on(event: 'queue', handler: Listener): void;
}
export interface IHashingFunction0 {
(): string;
}
export interface IHashingFunction1<T1> {
(a1: T1): string;
}
export interface IHashingFunction2<T1, T2> {
(a1: T1, a2: T2): string;
}
export interface IHashingFunction3<T1, T2, T3> {
(a1: T1, a2: T2, a3: T3): string;
}
export interface IHashingFunction4<T1, T2, T3, T4> {
(a1: T1, a2: T2, a3: T3, a4: T4): string;
}
export interface IHashingFunction5<T1, T2, T3, T4, T5> {
(a1: T1, a2: T2, a3: T3, a4: T4, a5: T5): string;
}
export interface IHashingFunction6<T1, T2, T3, T4, T5, T6> {
(a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6): string;
}
export interface IHashingFunctionPlus {
(...rest: any[]): string;
}
export interface IBypassFunction0 {
(): boolean;
}
export interface IBypassFunction1<T1> {
(a1: T1): boolean;
}
export interface IBypassFunction2<T1, T2> {
(a1: T1, a2: T2): boolean;
}
export interface IBypassFunction3<T1, T2, T3> {
(a1: T1, a2: T2, a3: T3): boolean;
}
export interface IBypassFunction4<T1, T2, T3, T4> {
(a1: T1, a2: T2, a3: T3, a4: T4): boolean;
}
export interface IBypassFunction5<T1, T2, T3, T4, T5> {
(a1: T1, a2: T2, a3: T3, a4: T4, a5: T5): boolean;
}
export interface IBypassFunction6<T1, T2, T3, T4, T5, T6> {
(a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6): boolean;
}
export interface IBypassFunctionPlus {
(...rest: any[]): boolean;
}
export interface IMaxAgeFunction0<TResult> {
(res: TResult): number;
}
export interface IMaxAgeFunction1<T1, TResult> {
(a1: T1, res: TResult): number;
}
export interface IMaxAgeFunction2<T1, T2, TResult> {
(a1: T1, a2: T2, res: TResult): number;
}
export interface IMaxAgeFunction3<T1, T2, T3, TResult> {
(a1: T1, a2: T2, a3: T3, res: TResult): number;
}
export interface IMaxAgeFunction4<T1, T2, T3, T4, TResult> {
(a1: T1, a2: T2, a3: T3, a4: T4, res: TResult): number;
}
export interface IMaxAgeFunction5<T1, T2, T3, T4, T5, TResult> {
(a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, res: TResult): number;
}
export interface IMaxAgeFunction6<T1, T2, T3, T4, T5, T6, TResult> {
(a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, res: TResult): number;
}
export interface IMaxAgeFunctionPlus {
(...rest: any[]): number;
}
export interface IParamsBase0<TResult> extends IParamsBaseCommons {
hash: IHashingFunction0;
bypass?: IBypassFunction0;
itemMaxAge?: IMaxAgeFunction0<TResult>;
}
export interface IParamsBase1<T1, TResult> extends IParamsBaseCommons {
hash: IHashingFunction1<T1>;
bypass?: IBypassFunction1<T1>;
itemMaxAge?: IMaxAgeFunction1<T1, TResult>;
}
export interface IParamsBase2<T1, T2, TResult> extends IParamsBaseCommons {
hash: IHashingFunction2<T1, T2>;
bypass?: IBypassFunction2<T1, T2>;
itemMaxAge?: IMaxAgeFunction2<T1, T2, TResult>;
}
export interface IParamsBase3<T1, T2, T3, TResult> extends IParamsBaseCommons {
hash: IHashingFunction3<T1, T2, T3>;
bypass?: IBypassFunction3<T1, T2, T3>;
itemMaxAge?: IMaxAgeFunction3<T1, T2, T3, TResult>;
}
export interface IParamsBase4<T1, T2, T3, T4, TResult> extends IParamsBaseCommons {
hash: IHashingFunction4<T1, T2, T3, T4>;
bypass?: IBypassFunction4<T1, T2, T3, T4>;
itemMaxAge?: IMaxAgeFunction4<T1, T2, T3, T4, TResult>;
}
export interface IParamsBase5<T1, T2, T3, T4, T5, TResult> extends IParamsBaseCommons {
hash: IHashingFunction5<T1, T2, T3, T4, T5>;
bypass?: IBypassFunction5<T1, T2, T3, T4, T5>;
itemMaxAge?: IMaxAgeFunction5<T1, T2, T3, T4, T5, TResult>;
}
export interface IParamsBase6<T1, T2, T3, T4, T5, T6, TResult> extends IParamsBaseCommons {
/**
* A function to generate the key of the cache.
*/
hash: IHashingFunction6<T1, T2, T3, T4, T5, T6>;
/**
* Return true if the result should not be retrieved from the cache.
*/
bypass?: IBypassFunction6<T1, T2, T3, T4, T5, T6>;
/**
* An optional function to indicate the maxAge of an specific item.
*/
itemMaxAge?: IMaxAgeFunction6<T1, T2, T3, T4, T5, T6, TResult>;
}
export interface IParamsBasePlus extends IParamsBaseCommons {
hash: IHashingFunctionPlus;
bypass?: IBypassFunctionPlus;
itemMaxAge?: IMaxAgeFunctionPlus;
}
interface IParamsBaseCommons extends LRU.Options<string, any> {
/**
* Indicates if the resource should be freezed.
*/
freeze?: boolean;
/**
* Indicates if the resource should be cloned before is returned.
*/
clone?: boolean;
/**
* Disable the cache and executes the load logic directly.
*/
disable?: boolean;
/**
* Do not queue requests if initial call is more than `queueMaxAge` milliseconds old.
* Instead, invoke `load` again and create a new queue.
* Defaults to 1000ms.
*/
queueMaxAge?: number;
}
export {};

3
server/node_modules/lru-memoizer/lib/util.js generated vendored Normal file
View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy91dGlsLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiIifQ==

34
server/node_modules/lru-memoizer/package.json generated vendored Normal file
View File

@@ -0,0 +1,34 @@
{
"name": "lru-memoizer",
"description": "Memoize functions results using an lru-cache.",
"version": "2.3.0",
"author": "José F. Romaniello <jfromaniello@gmail.com> (http://joseoncode.com)",
"repository": {
"url": "git://github.com/jfromaniello/lru-memoizer.git"
},
"keywords": [
"cache",
"memoize",
"lru"
],
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"scripts": {
"prepare": "tsc",
"test": "npm run prepare && mocha"
},
"dependencies": {
"lodash.clonedeep": "^4.5.0",
"lru-cache": "6.0.0"
},
"license": "MIT",
"devDependencies": {
"@types/lodash.clonedeep": "^4.5.9",
"@types/lru-cache": "^5.1.0",
"@types/node": "^12.0.10",
"chai": "^3.5.0",
"mocha": "^10.4.0",
"sinon": "^7.3.2",
"typescript": "^3.5.2"
}
}

View File

@@ -0,0 +1,39 @@
const memoizer = require('../lib/index.js');
const assert = require('chai').assert;
describe('lru-memoizer (bypass)', function () {
var loadTimes = 0, memoized;
beforeEach(function () {
loadTimes = 0;
memoized = memoizer({
load: function (a, b, callback) {
loadTimes++;
callback(null, a + b);
},
hash: function (a, b) {
return a + '-' + b;
},
bypass: function (a, b) {
return a < b;
},
max: 10
});
});
it('should call the load function every time', function (done) {
memoized(1, 2, function (err) {
assert.isNull(err);
assert.strictEqual(loadTimes, 1);
memoized(1, 2, function (err) {
assert.isNull(err);
assert.strictEqual(loadTimes, 2);
done();
});
});
});
});

View File

@@ -0,0 +1,44 @@
const memoizer = require('./..');
const assert = require('chai').assert;
describe('lru-memoizer (clone)', () => {
let loadTimes = 0, memoized;
beforeEach(() => {
loadTimes = 0;
memoized = memoizer({
load: (key, callback) => {
loadTimes++;
callback(null, { foo: key, buffer: Buffer.from('1234') });
},
hash: (key) => {
return key;
},
clone: true
});
});
it('should return a clone every time with the same cached structure', (done) => {
memoized('bar', (err, r1) => {
assert.isNull(err);
assert.strictEqual(loadTimes, 1);
assert.equal(r1.foo, 'bar');
r1.foo = 'bax';
memoized('bar', (err, r2) => {
assert.isNull(err);
assert.strictEqual(loadTimes, 1);
assert.equal(r2.foo, 'bar');
assert.notStrictEqual(r1, r2);
assert.notEqual(r1, r2);
done();
});
});
});
});

View File

@@ -0,0 +1,49 @@
const memoizer = require('./..');
const assert = require('chai').assert;
describe('lru-memoizer (disabled)', function () {
var loadTimes = 0, memoized;
beforeEach(function () {
loadTimes = 0;
memoized = memoizer({
disable: true,
load: function (a, b, callback) {
loadTimes++;
return setTimeout(function () {
if (a === 0) {
return callback(new Error('a cant be 0'));
}
callback(null, a+b);
}, 10);
},
hash: function (a, b) {
return a + '-' + b;
},
max: 10
});
});
it('should call the load function every time', function (done) {
memoized(1,2, function (err, result) {
assert.isNull(err);
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 1);
memoized(1,2, function (err, result) {
assert.isNull(err);
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 2);
done();
});
});
});
it('should expose hash function', function() {
assert.equal(memoized.hash(1, 2), '1-2');
});
});

View File

@@ -0,0 +1,132 @@
const memoizer = require('./..');
const sinon = require('sinon');
describe('lru-memoizer (events)', function () {
let memoized;
let onMiss, onHit, onQueue;
beforeEach(function () {
loadTimes = 0;
onMiss = sinon.stub();
onHit = sinon.stub();
onQueue = sinon.stub();
memoized = memoizer({
load: function (a, b, bypass, callback) {
return setTimeout(function () {
if (a === 0) {
return callback(new Error('a cant be 0'));
}
callback(null, a+b);
}, 10);
},
hash: function (a, b) {
return a + '-' + b;
},
bypass: function(a, b, bypass) {
return bypass;
},
max: 10
});
memoized.on('hit', onHit);
memoized.on('miss', onMiss);
memoized.on('queue', onQueue);
});
describe('when the result is not in the cache', () => {
beforeEach((done) => {
memoized(1, 2, false, done);
});
it('should not call onHit', () => {
sinon.assert.notCalled(onHit);
});
it('should not call onQueue', () => {
sinon.assert.notCalled(onQueue);
});
it('should call onMiss with the load arguments', () => {
sinon.assert.calledOnce(onMiss);
sinon.assert.calledWith(onMiss, 1, 2, false);
});
});
describe('when the result is in the cache', () => {
beforeEach((done) => {
memoized(1,2, false, () => {
onHit.reset();
onMiss.reset();
onQueue.reset();
memoized(1, 2, false, done);
});
});
it('should call onHit with the load arguments', () => {
sinon.assert.calledOnce(onHit);
sinon.assert.calledWith(onHit, 1, 2, false);
});
it('should not call onQueue', () => {
sinon.assert.notCalled(onQueue);
});
it('should not call onMiss', () => {
sinon.assert.notCalled(onQueue);
});
});
describe('when the cache is by passed', () => {
beforeEach((done) => {
memoized(1,2, false, () => {
onHit.reset();
onMiss.reset();
onQueue.reset();
memoized(1, 2, true, done);
});
});
it('should not call onHit', () => {
sinon.assert.notCalled(onHit);
});
it('should not call onQueue', () => {
sinon.assert.notCalled(onQueue);
});
it('should call onMiss with the load arguments', () => {
sinon.assert.calledOnce(onMiss);
sinon.assert.calledWith(onMiss, 1, 2, true);
});
});
describe('when the result is pending', () => {
beforeEach((done) => {
let pending = 2;
function onDone() {
pending -= 1;
if (pending === 0) {
done();
}
}
memoized(1, 2, false, onDone);
onHit.reset();
onMiss.reset();
onQueue.reset();
memoized(1, 2, false, onDone);
});
it('should not call onHit', () => {
sinon.assert.notCalled(onHit);
});
it('should call onQueue with the load arguments', () => {
sinon.assert.calledOnce(onQueue);
sinon.assert.calledWith(onQueue, 1, 2, false);
});
it('should not call onMiss', () => {
sinon.assert.notCalled(onMiss);
});
});
});

View File

@@ -0,0 +1,43 @@
const memoizer = require("./..");
const assert = require("chai").assert;
describe("lru-memoizer (freeze)", function () {
var loadTimes = 0,
memoized;
beforeEach(function () {
loadTimes = 0;
memoized = memoizer({
load: function (key, callback) {
loadTimes++;
callback(null, { foo: "bar", buffer: Buffer.from("1234") });
},
hash: function (key) {
return key;
},
freeze: true,
});
});
it("should return a freeze every time with the same cached structure", function (done) {
memoized("test", function (err, r1) {
assert.isNull(err);
assert.strictEqual(loadTimes, 1);
assert.equal(r1.foo, "bar");
r1.foo = "bax";
assert.isFrozen(r1);
memoized("test", function (err, r2) {
assert.isNull(err);
assert.strictEqual(loadTimes, 1);
assert.equal(r2.foo, "bar");
assert.strictEqual(r1, r2);
assert.isFrozen(r2);
done();
});
});
});
});

View File

@@ -0,0 +1,204 @@
var memoizer = require('./..');
var assert = require('chai').assert;
describe('lru-memoizer (itemMaxAge)', function () {
var loadTimes = 0, memoized;
beforeEach(function () {
loadTimes = 0;
});
it('should use default behavior if not configured', function (done) {
memoized = memoizer({
load: function (a, b, callback) {
loadTimes++;
setTimeout(function () {
callback(null, a + b);
}, 100);
},
hash: function (a, b) {
return a + '-' + b;
},
max: 10,
maxAge: 500
});
memoized(1,2, function (err, result) {
assert.isNull(err);
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 1);
// Not expired yet.
setTimeout(function() {
memoized(1,2, function (err, result) {
assert.isNull(err);
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 1);
// Expired, load times will increase.
setTimeout(function() {
memoized(1,2, function (err, result) {
assert.isNull(err);
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 2);
done();
});
}, 200);
});
}, 400);
});
});
it('should return all args and the result in the itemMaxAge function', function (done) {
var args;
memoized = memoizer({
load: function (a, b, callback) {
loadTimes++;
setTimeout(function () {
callback(null, a + b);
}, 100);
},
itemMaxAge: function (a, b, result) {
args = arguments;
return 1000;
},
hash: function (a, b) {
return a + '-' + b;
},
max: 10,
maxAge: 600
});
memoized(1,2, function (err, result) {
assert.isNull(err);
assert.strictEqual(args[0], 1);
assert.strictEqual(args[1], 2);
assert.strictEqual(args[2], 3);
done();
});
});
it('should overwrite the default behavior if configured', function (done) {
var maxAge = 0;
var lastKey = null;
memoized = memoizer({
load: function (a, b, callback) {
loadTimes++;
setTimeout(function () {
callback(null, a + b);
}, 100);
},
itemMaxAge: function (a, b, result) {
lastKey = a + '-' + b;
// In this test, we set the maxAge of the current item to (result*100).
// If the result is 3, the max age of this item will be 300.
maxAge = result * 100;
return maxAge;
},
hash: function (a, b) {
return a + '-' + b;
},
max: 10,
maxAge: 600
});
memoized(1,2, function (err, result) {
assert.isNull(err);
assert.strictEqual(maxAge, 300);
assert.strictEqual(lastKey, '1-2');
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 1);
// Not expired yet after 200 ms, because the expiration is 300
setTimeout(function() {
memoized(1,2, function (err, result) {
assert.isNull(err);
assert.strictEqual(maxAge, 300);
assert.strictEqual(lastKey, '1-2');
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 1);
// Expired because now we are at 350 ms (even though gloabl expiration has been set to 600)
setTimeout(function() {
memoized(1,2, function (err, result) {
assert.isNull(err);
assert.strictEqual(maxAge, 300);
assert.strictEqual(lastKey, '1-2');
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 2);
// Expired again, because 350ms have passed again.
setTimeout(function() {
memoized(1,2, function (err, result) {
assert.isNull(err);
assert.strictEqual(maxAge, 300);
assert.strictEqual(lastKey, '1-2');
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 3);
done();
});
}, 350);
});
}, 150);
});
}, 200);
});
});
it('should overwrite the default behavior if configured (sync)', function (done) {
var maxAge = 0;
var lastKey = null;
memoized = memoizer.sync({
load: function (a, b) {
loadTimes++;
return a + b;
},
itemMaxAge: function (a, b, result) {
lastKey = a + '-' + b;
// In this test, we set the maxAge of the current item to (result*100).
// If the result is 3, the max age of this item will be 300.
maxAge = result * 100;
return maxAge;
},
hash: function (a, b) {
return a + '-' + b;
},
max: 10,
maxAge: 600
});
var result = memoized(1, 2);
assert.strictEqual(maxAge, 300);
assert.strictEqual(lastKey, '1-2');
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 1);
// Not expired yet after 200 ms, because the expiration is 300
setTimeout(function() {
result = memoized(1, 2);
assert.strictEqual(maxAge, 300);
assert.strictEqual(lastKey, '1-2');
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 1);
// Expired because now we are at 350 ms (even though gloabl expiration has been set to 600)
setTimeout(function() {
result = memoized(1,2);
assert.strictEqual(maxAge, 300);
assert.strictEqual(lastKey, '1-2');
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 2);
// Expired again, because 350ms have passed again.
setTimeout(function() {
result = memoized(1,2);
assert.strictEqual(maxAge, 300);
assert.strictEqual(lastKey, '1-2');
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 3);
done();
}, 350);
}, 150);
}, 200);
});
});

View File

@@ -0,0 +1,36 @@
const memoizer = require('./..');
const assert = require('chai').assert;
const _ = require('lodash');
describe('lru-simultaneos calls', function () {
var loadTimes = 0, memoized;
beforeEach(function () {
loadTimes = 0;
memoized = memoizer({
load: function (a, b, callback) {
loadTimes++;
setTimeout(function () {
callback(null, a + b);
}, 100);
},
hash: function (a, b) {
return a + '-' + b;
},
max: 10
});
});
it('should call once', function (done) {
memoized(1, 2, _.noop);
memoized(1, 2, _.noop);
memoized(1, 2, function (err, result) {
if (err) { return done(err); }
assert.strictEqual(loadTimes, 1);
assert.strictEqual(result, 3);
done();
});
});
});

View File

@@ -0,0 +1,43 @@
var memoizer = require('./..');
var assert = require('chai').assert;
describe('lru-memoizer (no key)', function () {
var loadTimes = 0, memoized;
beforeEach(function () {
loadTimes = 0;
memoized = memoizer({
load: function (callback) {
loadTimes++;
return setTimeout(function () {
callback(null, loadTimes);
}, 10);
}
});
});
it('should cache the result of an async function', function (done) {
memoized(function (err, result) {
assert.isNull(err);
assert.equal(result, 1);
assert.equal(loadTimes, 1);
memoized(function (err, result) {
assert.isNull(err);
assert.equal(result, 1);
assert.equal(loadTimes, 1);
done();
});
});
});
it('should use the hash function for keys', function (done) {
memoized(function () {
memoized(function () {
assert.includeMembers(memoized.keys(), ['_']);
done();
});
});
});
});

View File

@@ -0,0 +1,110 @@
var memoizer = require('./..');
var assert = require('chai').assert;
describe('lru-memoizer (queueMaxAge)', function () {
var loadTimes = 0, memoized;
beforeEach(function () {
loadTimes = 0;
});
function observer() {
const listeners = [];
return {
listen(listener) {
listeners.push(listener);
},
trigger() {
listeners.forEach(listener => listener());
}
}
}
it('should create a new queue once expired', function (done) {
memoized = memoizer({
load: function (a, b, onResolve, callback) {
loadTimes++;
onResolve(() => callback(null, a + b));
},
queueMaxAge: 10,
hash: function (a, b) {
return a + '-' + b;
}
});
const observer1 = observer();
const observer2 = observer();
const observer3 = observer();
const resolved = [];
memoized(1, 2, observer1.listen, function (err, result) {
assert.isNull(err);
assert.strictEqual(result, 3);
resolved.push('A');
});
assert.strictEqual(loadTimes, 1);
memoized(1, 2, assert.fail, function (err, result) {
assert.isNull(err);
assert.strictEqual(result, 3);
resolved.push('B');
});
assert.strictEqual(loadTimes, 1);
setTimeout(() => {
// previous queue expired, this calls will be added to a new queue.
memoized(1, 2, observer2.listen, function (err, result) {
assert.isNull(err);
assert.strictEqual(result, 3);
resolved.push('C');
});
memoized(1, 2, assert.fail, function (err, result) {
assert.isNull(err);
assert.strictEqual(result, 3);
resolved.push('D');
});
// only one new invocation to load
assert.strictEqual(loadTimes, 2);
setTimeout(() => {
// second queue expired, this calls will be added to a third queue.
memoized(1, 2, observer3.listen, function (err, result) {
assert.isNull(err);
assert.strictEqual(result, 3);
resolved.push('E');
});
memoized(1, 2, assert.fail.listen, function (err, result) {
assert.isNull(err);
assert.strictEqual(result, 3);
resolved.push('F');
});
assert.strictEqual(loadTimes, 3);
observer1.trigger();
setImmediate(() => {
// first queue was resolved
assert.deepEqual(['A', 'B'], resolved);
observer3.trigger();
setImmediate(() => {
// third queue was resolved
assert.deepEqual(['A', 'B', 'E', 'F'], resolved);
observer2.trigger();
setImmediate(() => {
// second queue was resolved
assert.deepEqual(['A', 'B', 'E', 'F', 'C', 'D'], resolved);
done();
});
});
});
}, 100);
}, 100);
});
});

View File

@@ -0,0 +1,76 @@
const memoizer = require('./..');
const assert = require('chai').assert;
describe('lru-memoizer sync (clone)', () => {
describe('call', () => {
let loadTimes = 0, memoized;
beforeEach(() => {
loadTimes = 0;
memoized = memoizer.sync({
load: (key) => {
loadTimes++;
return { foo: key , buffer: Buffer.from('1234') };
},
hash: (key) => {
return key;
},
clone: true
});
});
it('should return a clone every time with the same cached structure', () => {
const r1 = memoized('bar');
assert.strictEqual(loadTimes, 1);
assert.equal(r1.foo, 'bar');
r1.foo = 'bax';
const r2 = memoized('bar');
assert.strictEqual(loadTimes, 1);
assert.equal(r2.foo, 'bar');
assert.notStrictEqual(r1, r2);
assert.notEqual(r1, r2);
});
});
describe('Promise', () => {
let loadTimes = 0, memoized;
beforeEach(() => {
loadTimes = 0;
memoized = memoizer.sync({
load: (key) => {
loadTimes++;
return Promise.resolve({ foo: key, buffer: Buffer.from('1234') });
},
hash: (key) => {
return key;
},
clone: true
});
});
it('should return a clone every time with the same cached structure', (done) => {
memoized('bar').then(r1 => {
assert.strictEqual(loadTimes, 1);
assert.equal(r1.foo, 'bar');
r1.foo = 'bax';
memoized('bar').then(r2 => {
assert.strictEqual(loadTimes, 1);
assert.equal(r2.foo, 'bar');
assert.notStrictEqual(r1, r2);
assert.notEqual(r1, r2);
done();
});
})
.catch(done);
});
});
});

View File

@@ -0,0 +1,95 @@
const memoizer = require('./..');
const sinon = require('sinon');
describe('lru-memoizer sync (events)', function () {
let memoized;
let onMiss, onHit, onQueue;
beforeEach(function () {
loadTimes = 0;
onMiss = sinon.stub();
onHit = sinon.stub();
onQueue = sinon.stub();
memoized = memoizer.sync({
load: function (a, b, bypass) {
return a + b;
},
hash: function (a, b, bypass) {
return a + '-' + b;
},
bypass: function(a, b, bypass) {
return bypass;
},
max: 10
});
memoized.on('hit', onHit);
memoized.on('miss', onMiss);
memoized.on('queue', onQueue);
});
describe('when the result is not in the cache', () => {
beforeEach(() => {
memoized(1, 2, false);
});
it('should not call onHit', () => {
sinon.assert.notCalled(onHit);
});
it('should not call onQueue', () => {
sinon.assert.notCalled(onQueue);
});
it('should call onMiss with the load arguments', () => {
sinon.assert.calledOnce(onMiss);
sinon.assert.calledWith(onMiss, 1, 2, false);
});
});
describe('when the result is in the cache', () => {
beforeEach(() => {
memoized(1,2, false);
onHit.reset();
onMiss.reset();
onQueue.reset();
memoized(1, 2, false);
});
it('should call onHit with the load arguments', () => {
sinon.assert.calledOnce(onHit);
sinon.assert.calledWith(onHit, 1, 2, false);
});
it('should not call onQueue', () => {
sinon.assert.notCalled(onQueue);
});
it('should not call onMiss', () => {
sinon.assert.notCalled(onQueue);
});
});
describe('when the cache is by passed', () => {
beforeEach(() => {
memoized(1,2, false);
onHit.reset();
onMiss.reset();
onQueue.reset();
memoized(1, 2, true);
});
it('should not call onHit', () => {
sinon.assert.notCalled(onHit);
});
it('should not call onQueue', () => {
sinon.assert.notCalled(onQueue);
});
it('should call onMiss with the load arguments', () => {
sinon.assert.calledOnce(onMiss);
sinon.assert.calledWith(onMiss, 1, 2, true);
});
});
});

View File

@@ -0,0 +1,74 @@
const memoizer = require('./..');
const assert = require('chai').assert;
describe('lru-memoizer sync (freeze)', () => {
describe('call', () => {
let loadTimes = 0, memoized;
beforeEach(() => {
loadTimes = 0;
memoized = memoizer.sync({
load: (key) => {
loadTimes++;
return { foo: key , buffer: Buffer.from('1234') };
},
hash: (key) => {
return key;
},
freeze: true
});
});
it('should return a freeze every time with the same cached structure', () => {
const r1 = memoized('bar');
assert.strictEqual(loadTimes, 1);
assert.equal(r1.foo, 'bar');
assert.isFrozen(r1);
const r2 = memoized('bar');
assert.strictEqual(loadTimes, 1);
assert.equal(r2.foo, 'bar');
assert.isFrozen(r2);
});
});
describe('Promise', () => {
let loadTimes = 0, memoized;
beforeEach(() => {
loadTimes = 0;
memoized = memoizer.sync({
load: (key) => {
loadTimes++;
return Promise.resolve({ foo: key, buffer: Buffer.from('1234') });
},
hash: (key) => {
return key;
},
freeze: true
});
});
it('should return a freeze every time with the same cached structure', (done) => {
memoized('bar').then(r1 => {
assert.strictEqual(loadTimes, 1);
assert.equal(r1.foo, 'bar');
assert.isFrozen(r1);
memoized('bar').then(r2 => {
assert.strictEqual(loadTimes, 1);
assert.equal(r2.foo, 'bar');
assert.isFrozen(r2);
done();
});
})
.catch(done);
});
});
});

View File

@@ -0,0 +1,47 @@
var memoizer = require('./..');
var assert = require('chai').assert;
describe('lru-memoizer sync', function () {
var loadTimes = 0, memoized;
beforeEach(function () {
loadTimes = 0;
memoized = memoizer.sync({
load: function (a, b) {
loadTimes++;
if (a === 0) {
throw new Error('a cant be 0');
}
return a + b;
},
hash: function (a, b) {
return a + '-' + b;
},
max: 10
});
});
it('should cache the result of an async function', function () {
var result = memoized(1, 2);
assert.equal(result, 3);
assert.equal(loadTimes, 1);
var result2 = memoized(1,2);
assert.equal(result2, 3);
assert.equal(loadTimes, 1);
});
it('shuld use the hash function for keys', function () {
memoized(1, 2);
memoized(2, 3);
assert.includeMembers(memoized.keys(), ['1-2', '2-3']);
});
it('should not cache errored funcs', function () {
try {
memoized(0, 2);
} catch(err) {}
assert.notInclude(memoized.keys(), ['0-2']);
});
});

View File

@@ -0,0 +1,88 @@
var memoizer = require('./..');
var assert = require('chai').assert;
describe('lru-memoizer', function () {
var loadTimes = 0, memoized;
beforeEach(function () {
loadTimes = 0;
memoized = memoizer({
load: function (a, b, callback) {
loadTimes++;
return setTimeout(function () {
if (a === 0) {
return callback(new Error('a cant be 0'));
}
callback(null, a+b);
}, 10);
},
hash: function (a, b) {
return a + '-' + b;
},
max: 10
});
});
it('should cache the result of an async function', function (done) {
memoized(1,2, function (err, result) {
assert.isNull(err);
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 1);
memoized(1,2, function (err, result) {
assert.isNull(err);
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 1);
done();
});
});
});
it('should use the hash function for keys', function (done) {
memoized(1, 2, function () {
memoized(2,3, function () {
assert.includeMembers(memoized.keys(), ['1-2', '2-3']);
done();
});
});
});
it('should not cache errored funcs', function (done) {
memoized(0, 2, function (err) {
assert.isNotNull(err);
assert.notInclude(memoized.keys(), ['0-2']);
done();
});
});
it('should expose the hash function', function() {
assert.equal(memoized.hash(0, 2), '0-2');
});
it('should expose the load function', function(done) {
memoized.load(1, 2, (err, result) => {
assert.equal(result, 3);
done();
});
});
it('should expose the max prop', function() {
assert.equal(memoized.max, 10);
});
it('should allow to del a key', function(done) {
memoized(1,2, () => {
assert.strictEqual(loadTimes, 1);
memoized.del(1,2);
memoized(1,2, (err, result) => {
assert.isNull(err);
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 2);
done();
});
});
});
});

59
server/node_modules/lru-memoizer/tsconfig.json generated vendored Normal file
View File

@@ -0,0 +1,59 @@
{
"compilerOptions": {
/* Basic Options */
"target": "ES5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": ["es2015", "es2017"], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./lib", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
"downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
"strictNullChecks": false, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictPropertyInitialization": false, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
"inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
}
}