first commit

This commit is contained in:
Myk
2025-07-31 23:47:20 +03:00
commit 2186b278a0
5149 changed files with 537218 additions and 0 deletions

21
node_modules/async-lock/AUTHORS generated vendored Normal file
View File

@@ -0,0 +1,21 @@
# Authors ordered by first contribution.
rain1017 (https://github.com/rain1017)
JonathanPicques (https://github.com/JonathanPicques)
Rogier Schouten (https://github.com/rogierschouten)
erikvold (https://github.com/erikvold)
Christian Passet (https://github.com/thePunIssuer)
Tanguy Krotoff (https://github.com/tkrotoff)
jtyers (https://github.com/jtyers)
Paul Roub (https://github.com/paulroub)
Geoff Whatley (https://github.com/meatwallace)
Patryk L. (https://github.com/LosTigeros)
Julian Saunderson (https://github.com/bitrivers)
Philipp Keck (https://github.com/Philipp91)
abozaralizadeh (https://github.com/abozaralizadeh)
ThePiz (https://github.com/ThePiz)
Luke Stead (https://github.com/luke-stead-sonocent)
Simeon Borko (https://github.com/simeonborko)
Tim Schmidt (https://github.com/taschmidt)
Motty Milshtein (https://github.com/mottymilshtein)

132
node_modules/async-lock/History.md generated vendored Normal file
View File

@@ -0,0 +1,132 @@
1.4.0
==================
* add execution timeout (thank you @mottymilshtein)
1.3.2
==================
* Handle errors from user-supplied callback better (Thank you @simeonborko)
* Ensure the array parameter does not get mutated for batch acquire (Thank you @taschmidt)
1.3.1
==================
* Show queue name in errors (thank you @luke-stead-sonocent)
1.3.0
==================
* Add maxOccupationTime option (Thank you @abozaralizadeh and @ThePiz)
1.2.8
==================
* Fix #37 process not set when acquiring lock (Thank you @Philipp91)
1.2.7
==================
DO NOT USE, erroneous publish
1.2.6
==================
* Fix `maxPending = Infinity` no longer allowed (thank you @coderaiser)
1.2.5
==================
* Allow `maxPending = 0` (thank you @bmrpatel)
* Upgrade dependencies
1.2.4
==================
* Be robust to lock names that are also Object keys - simpler solution, extra tests.
1.2.3
==================
* Be robust to lock names that are also Object keys.
* Upgrade dependencies
1.2.2
==================
* Fix grunt-env accidentally having become a dependency (#25)
1.2.1
==================
* Remove empty postinstall script (#24)
* Fixed some vulnerable dev dependencies
1.2.0
==================
* ES5 compatibility (#21)
1.1.4
==================
* Fix for #17, update dependencies
1.1.3
==================
* Fix for #14
1.1.1
==================
* Fix result Promise not resolving when locking empty key array
1.1.0 / 2017-10-17
==================
* Add option to add waiters to the front of the queue
1.1.0 / 2017-10-17
==================
* Add option to add waiters to the front of the queue
1.0.0 / 2017-06-29
==================
* Remove dependency on Q by using the global Promise variable by default. Thank you @erikvold (https://github.com/erikvold) for the PR
0.3.10 / 2017-06-27
==================
* Remove dependencies on Q-specific nodify(), try(), and defer() methods so that you can inject e.g. standard ES6 promises using `new AsyncLock({ Promise: Promise })`
0.3.9 / 2016-11-30
==================
* Referred to MIT license in package.json
* Update NPM module dependencies, remove no-longer-maintained blanket code coverage
* Change author to rogierschouten
* Fix invalid JSDoc comments (thanks @JonathanPicques)
* Bugfix: TypeError when locking multiple keys at once
0.3.7-0.3.8
==================
Unknown, previous author did not commit this to Github.
0.3.6 / 2015-09-07
==================
* Performance improvement
0.3.5 / 2015-06-15
==================
* Performance improvement
0.3.4 / 2015-06-09
==================
* Bug fix
0.3.3 / 2015-05-19
==================
* Bug fix
0.3.2 / 2015-05-08
==================
* Set default timeout to never
0.3.1 / 2015-04-15
==================
* Use your own promise
0.3.0 / 2015-03-06
==================
* Domain reentrant
0.2.0 / 2015-02-21
==================
* Support promise mode
* Pending task limit
0.1.0 / 2015-01-13
==================
* Initial version

22
node_modules/async-lock/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2016 Rogier Schouten <github@workingcode.ninja>
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.

177
node_modules/async-lock/README.md generated vendored Normal file
View File

@@ -0,0 +1,177 @@
# async-lock
Lock on asynchronous code
[![Build Status](https://travis-ci.org/rogierschouten/async-lock.svg?branch=master)](https://travis-ci.org/rogierschouten/async-lock)
* ES6 promise supported
* Multiple keys lock supported
* Timeout supported
* Occupation time limit supported
* Execution time limit supported
* Pending task limit supported
* Domain reentrant supported
* 100% code coverage
## Disclaimer
I did not create this package, and I will not add any features to it myself. I was granted the ownership because it was no longer being
maintained, and I volunteered to fix a bug.
If you have a new feature you would like to have incorporated, please send me a PR and I will be happy to work with you and get it merged.
For any bugs, PRs are most welcome but when possible I will try to get them resolved as soon as possible.
## Why do you need locking on single threaded nodejs?
Nodejs is single threaded, and the code execution never gets interrupted inside an event loop, so locking is unnecessary? This is true ONLY IF your critical section can be executed inside a single event loop.
However, if you have any async code inside your critical section (it can be simply triggered by any I/O operation, or timer), your critical logic will across multiple event loops, therefore it's not concurrency safe!
Consider the following code
```js
redis.get('key', function(err, value) {
redis.set('key', value * 2);
});
```
The above code simply multiply a redis key by 2.
However, if two users run concurrently, the execution order may like this
```
user1: redis.get('key') -> 1
user2: redis.get('key') -> 1
user1: redis.set('key', 1 x 2) -> 2
user2: redis.set('key', 1 x 2) -> 2
```
Obviously it's not what you expected
With asyncLock, you can easily write your async critical section
```js
lock.acquire('key', function(cb) {
// Concurrency safe
redis.get('key', function(err, value) {
redis.set('key', value * 2, cb);
});
}, function(err, ret) {
});
```
## Get Started
```js
var AsyncLock = require('async-lock');
var lock = new AsyncLock();
/**
* @param {String|Array} key resource key or keys to lock
* @param {function} fn execute function
* @param {function} cb (optional) callback function, otherwise will return a promise
* @param {Object} opts (optional) options
*/
lock.acquire(key, function(done) {
// async work
done(err, ret);
}, function(err, ret) {
// lock released
}, opts);
// Promise mode
lock.acquire(key, function() {
// return value or promise
}, opts).then(function() {
// lock released
});
```
## Error Handling
```js
// Callback mode
lock.acquire(key, function(done) {
done(new Error('error'));
}, function(err, ret) {
console.log(err.message) // output: error
});
// Promise mode
lock.acquire(key, function() {
throw new Error('error');
}).catch(function(err) {
console.log(err.message) // output: error
});
```
## Acquire multiple keys
```js
lock.acquire([key1, key2], fn, cb);
```
## Domain reentrant lock
Lock is reentrant in the same domain
```js
var domain = require('domain');
var lock = new AsyncLock({domainReentrant : true});
var d = domain.create();
d.run(function() {
lock.acquire('key', function() {
//Enter lock
return lock.acquire('key', function() {
//Enter same lock twice
});
});
});
```
## Options
```js
// Specify timeout - max amount of time an item can remain in the queue before acquiring the lock
var lock = new AsyncLock({timeout: 5000});
lock.acquire(key, fn, function(err, ret) {
// timed out error will be returned here if lock not acquired in given time
});
// Specify max occupation time - max amount of time allowed between entering the queue and completing execution
var lock = new AsyncLock({maxOccupationTime: 3000});
lock.acquire(key, fn, function(err, ret) {
// occupation time exceeded error will be returned here if job not completed in given time
});
// Specify max execution time - max amount of time allowed between acquiring the lock and completing execution
var lock = new AsyncLock({maxExecutionTime: 3000});
lock.acquire(key, fn, function(err, ret) {
// execution time exceeded error will be returned here if job not completed in given time
});
// Set max pending tasks - max number of tasks allowed in the queue at a time
var lock = new AsyncLock({maxPending: 1000});
lock.acquire(key, fn, function(err, ret) {
// Handle too much pending error
})
// Whether there is any running or pending async function
lock.isBusy();
// Use your own promise library instead of the global Promise variable
var lock = new AsyncLock({Promise: require('bluebird')}); // Bluebird
var lock = new AsyncLock({Promise: require('q')}); // Q
// Add a task to the front of the queue waiting for a given lock
lock.acquire(key, fn1, cb); // runs immediately
lock.acquire(key, fn2, cb); // added to queue
lock.acquire(key, priorityFn, cb, {skipQueue: true}); // jumps queue and runs before fn2
```
## Changelog
See [Changelog](./History.md)
## Issues
See [issue tracker](https://github.com/rogierschouten/async-lock/issues).
## License
MIT, see [LICENSE](./LICENSE)

2
node_modules/async-lock/index.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
'use strict';
module.exports = require('./lib');

312
node_modules/async-lock/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,312 @@
'use strict';
var AsyncLock = function (opts) {
opts = opts || {};
this.Promise = opts.Promise || Promise;
// format: {key : [fn, fn]}
// queues[key] = null indicates no job running for key
this.queues = Object.create(null);
// lock is reentrant for same domain
this.domainReentrant = opts.domainReentrant || false;
if (this.domainReentrant) {
if (typeof process === 'undefined' || typeof process.domain === 'undefined') {
throw new Error(
'Domain-reentrant locks require `process.domain` to exist. Please flip `opts.domainReentrant = false`, ' +
'use a NodeJS version that still implements Domain, or install a browser polyfill.');
}
// domain of current running func {key : fn}
this.domains = Object.create(null);
}
this.timeout = opts.timeout || AsyncLock.DEFAULT_TIMEOUT;
this.maxOccupationTime = opts.maxOccupationTime || AsyncLock.DEFAULT_MAX_OCCUPATION_TIME;
this.maxExecutionTime = opts.maxExecutionTime || AsyncLock.DEFAULT_MAX_EXECUTION_TIME;
if (opts.maxPending === Infinity || (Number.isInteger(opts.maxPending) && opts.maxPending >= 0)) {
this.maxPending = opts.maxPending;
} else {
this.maxPending = AsyncLock.DEFAULT_MAX_PENDING;
}
};
AsyncLock.DEFAULT_TIMEOUT = 0; //Never
AsyncLock.DEFAULT_MAX_OCCUPATION_TIME = 0; //Never
AsyncLock.DEFAULT_MAX_EXECUTION_TIME = 0; //Never
AsyncLock.DEFAULT_MAX_PENDING = 1000;
/**
* Acquire Locks
*
* @param {String|Array} key resource key or keys to lock
* @param {function} fn async function
* @param {function} cb callback function, otherwise will return a promise
* @param {Object} opts options
*/
AsyncLock.prototype.acquire = function (key, fn, cb, opts) {
if (Array.isArray(key)) {
return this._acquireBatch(key, fn, cb, opts);
}
if (typeof (fn) !== 'function') {
throw new Error('You must pass a function to execute');
}
// faux-deferred promise using new Promise() (as Promise.defer is deprecated)
var deferredResolve = null;
var deferredReject = null;
var deferred = null;
if (typeof (cb) !== 'function') {
opts = cb;
cb = null;
// will return a promise
deferred = new this.Promise(function(resolve, reject) {
deferredResolve = resolve;
deferredReject = reject;
});
}
opts = opts || {};
var resolved = false;
var timer = null;
var occupationTimer = null;
var executionTimer = null;
var self = this;
var done = function (locked, err, ret) {
if (occupationTimer) {
clearTimeout(occupationTimer);
occupationTimer = null;
}
if (executionTimer) {
clearTimeout(executionTimer);
executionTimer = null;
}
if (locked) {
if (!!self.queues[key] && self.queues[key].length === 0) {
delete self.queues[key];
}
if (self.domainReentrant) {
delete self.domains[key];
}
}
if (!resolved) {
if (!deferred) {
if (typeof (cb) === 'function') {
cb(err, ret);
}
}
else {
//promise mode
if (err) {
deferredReject(err);
}
else {
deferredResolve(ret);
}
}
resolved = true;
}
if (locked) {
//run next func
if (!!self.queues[key] && self.queues[key].length > 0) {
self.queues[key].shift()();
}
}
};
var exec = function (locked) {
if (resolved) { // may due to timed out
return done(locked);
}
if (timer) {
clearTimeout(timer);
timer = null;
}
if (self.domainReentrant && locked) {
self.domains[key] = process.domain;
}
var maxExecutionTime = opts.maxExecutionTime || self.maxExecutionTime;
if (maxExecutionTime) {
executionTimer = setTimeout(function () {
if (!!self.queues[key]) {
done(locked, new Error('Maximum execution time is exceeded ' + key));
}
}, maxExecutionTime);
}
// Callback mode
if (fn.length === 1) {
var called = false;
try {
fn(function (err, ret) {
if (!called) {
called = true;
done(locked, err, ret);
}
});
} catch (err) {
// catching error thrown in user function fn
if (!called) {
called = true;
done(locked, err);
}
}
}
else {
// Promise mode
self._promiseTry(function () {
return fn();
})
.then(function(ret){
done(locked, undefined, ret);
}, function(error){
done(locked, error);
});
}
};
if (self.domainReentrant && !!process.domain) {
exec = process.domain.bind(exec);
}
var maxPending = opts.maxPending || self.maxPending;
if (!self.queues[key]) {
self.queues[key] = [];
exec(true);
}
else if (self.domainReentrant && !!process.domain && process.domain === self.domains[key]) {
// If code is in the same domain of current running task, run it directly
// Since lock is re-enterable
exec(false);
}
else if (self.queues[key].length >= maxPending) {
done(false, new Error('Too many pending tasks in queue ' + key));
}
else {
var taskFn = function () {
exec(true);
};
if (opts.skipQueue) {
self.queues[key].unshift(taskFn);
} else {
self.queues[key].push(taskFn);
}
var timeout = opts.timeout || self.timeout;
if (timeout) {
timer = setTimeout(function () {
timer = null;
done(false, new Error('async-lock timed out in queue ' + key));
}, timeout);
}
}
var maxOccupationTime = opts.maxOccupationTime || self.maxOccupationTime;
if (maxOccupationTime) {
occupationTimer = setTimeout(function () {
if (!!self.queues[key]) {
done(false, new Error('Maximum occupation time is exceeded in queue ' + key));
}
}, maxOccupationTime);
}
if (deferred) {
return deferred;
}
};
/*
* Below is how this function works:
*
* Equivalent code:
* self.acquire(key1, function(cb){
* self.acquire(key2, function(cb){
* self.acquire(key3, fn, cb);
* }, cb);
* }, cb);
*
* Equivalent code:
* var fn3 = getFn(key3, fn);
* var fn2 = getFn(key2, fn3);
* var fn1 = getFn(key1, fn2);
* fn1(cb);
*/
AsyncLock.prototype._acquireBatch = function (keys, fn, cb, opts) {
if (typeof (cb) !== 'function') {
opts = cb;
cb = null;
}
var self = this;
var getFn = function (key, fn) {
return function (cb) {
self.acquire(key, fn, cb, opts);
};
};
var fnx = keys.reduceRight(function (prev, key) {
return getFn(key, prev);
}, fn);
if (typeof (cb) === 'function') {
fnx(cb);
}
else {
return new this.Promise(function (resolve, reject) {
// check for promise mode in case keys is empty array
if (fnx.length === 1) {
fnx(function (err, ret) {
if (err) {
reject(err);
}
else {
resolve(ret);
}
});
} else {
resolve(fnx());
}
});
}
};
/*
* Whether there is any running or pending asyncFunc
*
* @param {String} key
*/
AsyncLock.prototype.isBusy = function (key) {
if (!key) {
return Object.keys(this.queues).length > 0;
}
else {
return !!this.queues[key];
}
};
/**
* Promise.try() implementation to become independent of Q-specific methods
*/
AsyncLock.prototype._promiseTry = function(fn) {
try {
return this.Promise.resolve(fn());
} catch (e) {
return this.Promise.reject(e);
}
};
module.exports = AsyncLock;

48
node_modules/async-lock/package.json generated vendored Normal file
View File

@@ -0,0 +1,48 @@
{
"name": "async-lock",
"description": "Lock on asynchronous code",
"version": "1.4.1",
"author": {
"name": "Rogier Schouten",
"url": "https://github.com/rogierschouten/",
"email": "github@workingcode.ninja"
},
"private": false,
"homepage": "https://github.com/rogierschouten/async-lock",
"repository": {
"type": "git",
"url": "git+https://github.com/rogierschouten/async-lock.git"
},
"bugs": {
"url": "https://github.com/rogierschouten/async-lock/issues"
},
"license": "MIT",
"keywords": [
"lock",
"async",
"concurrency",
"critical",
"section",
"mutex"
],
"engines": {},
"scripts": {
"start": "grunt",
"test": "grunt test"
},
"devDependencies": {
"bluebird": "^3.5.1",
"grunt": "^1.0.4",
"grunt-cli": "^1.2.0",
"grunt-contrib-clean": "^1.1.0",
"grunt-contrib-jshint": "^3.2.0",
"grunt-contrib-watch": "^1.1.0",
"grunt-env": "^1.0.1",
"grunt-mocha-test": "^0.13.3",
"load-grunt-tasks": "^4.0.0",
"lodash": "^4.17.20",
"mocha": "^10.2.0",
"q": "^1.5.1",
"should": "^13.2.1"
}
}