push the uni-demo project
This commit is contained in:
15
uni-demo/node_modules/promise-retry/.editorconfig
generated
vendored
Normal file
15
uni-demo/node_modules/promise-retry/.editorconfig
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[package.json]
|
||||
indent_size = 2
|
||||
64
uni-demo/node_modules/promise-retry/.jshintrc
generated
vendored
Normal file
64
uni-demo/node_modules/promise-retry/.jshintrc
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
{
|
||||
"predef": [
|
||||
"console",
|
||||
"require",
|
||||
"define",
|
||||
"describe",
|
||||
"it",
|
||||
"before",
|
||||
"beforeEach",
|
||||
"after",
|
||||
"afterEach",
|
||||
"Promise"
|
||||
],
|
||||
|
||||
"node": true,
|
||||
"devel": true,
|
||||
|
||||
"bitwise": true,
|
||||
"curly": true,
|
||||
"eqeqeq": true,
|
||||
"forin": false,
|
||||
"immed": true,
|
||||
"latedef": false,
|
||||
"newcap": true,
|
||||
"noarg": true,
|
||||
"noempty": false,
|
||||
"nonew": true,
|
||||
"plusplus": false,
|
||||
"regexp": true,
|
||||
"undef": true,
|
||||
"unused": true,
|
||||
"quotmark": "single",
|
||||
"strict": true,
|
||||
"trailing": true,
|
||||
|
||||
"asi": false,
|
||||
"boss": false,
|
||||
"debug": false,
|
||||
"eqnull": true,
|
||||
"es5": false,
|
||||
"esnext": false,
|
||||
"evil": false,
|
||||
"expr": true,
|
||||
"funcscope": false,
|
||||
"globalstrict": false,
|
||||
"iterator": false,
|
||||
"lastsemic": false,
|
||||
"laxbreak": false,
|
||||
"laxcomma": false,
|
||||
"loopfunc": true,
|
||||
"multistr": false,
|
||||
"onecase": true,
|
||||
"regexdash": false,
|
||||
"scripturl": false,
|
||||
"smarttabs": false,
|
||||
"shadow": false,
|
||||
"sub": false,
|
||||
"supernew": false,
|
||||
"validthis": false,
|
||||
|
||||
"nomen": false,
|
||||
"onevar": false,
|
||||
"white": true
|
||||
}
|
||||
4
uni-demo/node_modules/promise-retry/.travis.yml
generated
vendored
Normal file
4
uni-demo/node_modules/promise-retry/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "10"
|
||||
- "12"
|
||||
19
uni-demo/node_modules/promise-retry/LICENSE
generated
vendored
Normal file
19
uni-demo/node_modules/promise-retry/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2014 IndigoUnited
|
||||
|
||||
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.
|
||||
94
uni-demo/node_modules/promise-retry/README.md
generated
vendored
Normal file
94
uni-demo/node_modules/promise-retry/README.md
generated
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
# node-promise-retry
|
||||
|
||||
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url] [![Greenkeeper badge][greenkeeper-image]][greenkeeper-url]
|
||||
|
||||
[npm-url]:https://npmjs.org/package/promise-retry
|
||||
[downloads-image]:http://img.shields.io/npm/dm/promise-retry.svg
|
||||
[npm-image]:http://img.shields.io/npm/v/promise-retry.svg
|
||||
[travis-url]:https://travis-ci.org/IndigoUnited/node-promise-retry
|
||||
[travis-image]:http://img.shields.io/travis/IndigoUnited/node-promise-retry/master.svg
|
||||
[david-dm-url]:https://david-dm.org/IndigoUnited/node-promise-retry
|
||||
[david-dm-image]:https://img.shields.io/david/IndigoUnited/node-promise-retry.svg
|
||||
[david-dm-dev-url]:https://david-dm.org/IndigoUnited/node-promise-retry?type=dev
|
||||
[david-dm-dev-image]:https://img.shields.io/david/dev/IndigoUnited/node-promise-retry.svg
|
||||
[greenkeeper-image]:https://badges.greenkeeper.io/IndigoUnited/node-promise-retry.svg
|
||||
[greenkeeper-url]:https://greenkeeper.io/
|
||||
|
||||
Retries a function that returns a promise, leveraging the power of the [retry](https://github.com/tim-kos/node-retry) module to the promises world.
|
||||
|
||||
There's already some modules that are able to retry functions that return promises but
|
||||
they were rather difficult to use or do not offer an easy way to do conditional retries.
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
`$ npm install promise-retry`
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
### promiseRetry(fn, [options])
|
||||
|
||||
Calls `fn` until the returned promise ends up fulfilled or rejected with an error different than
|
||||
a `retry` error.
|
||||
The `options` argument is an object which maps to the [retry](https://github.com/tim-kos/node-retry) module options:
|
||||
|
||||
- `retries`: The maximum amount of times to retry the operation. Default is `10`.
|
||||
- `factor`: The exponential factor to use. Default is `2`.
|
||||
- `minTimeout`: The number of milliseconds before starting the first retry. Default is `1000`.
|
||||
- `maxTimeout`: The maximum number of milliseconds between two retries. Default is `Infinity`.
|
||||
- `randomize`: Randomizes the timeouts by multiplying with a factor between `1` to `2`. Default is `false`.
|
||||
|
||||
|
||||
The `fn` function will receive a `retry` function as its first argument that should be called with an error whenever you want to retry `fn`. The `retry` function will always throw an error.
|
||||
If there are retries left, it will throw a special `retry` error that will be handled internally to call `fn` again.
|
||||
If there are no retries left, it will throw the actual error passed to it.
|
||||
|
||||
If you prefer, you can pass the options first using the alternative function signature `promiseRetry([options], fn)`.
|
||||
|
||||
## Example
|
||||
```js
|
||||
var promiseRetry = require('promise-retry');
|
||||
|
||||
// Simple example
|
||||
promiseRetry(function (retry, number) {
|
||||
console.log('attempt number', number);
|
||||
|
||||
return doSomething()
|
||||
.catch(retry);
|
||||
})
|
||||
.then(function (value) {
|
||||
// ..
|
||||
}, function (err) {
|
||||
// ..
|
||||
});
|
||||
|
||||
// Conditional example
|
||||
promiseRetry(function (retry, number) {
|
||||
console.log('attempt number', number);
|
||||
|
||||
return doSomething()
|
||||
.catch(function (err) {
|
||||
if (err.code === 'ETIMEDOUT') {
|
||||
retry(err);
|
||||
}
|
||||
|
||||
throw err;
|
||||
});
|
||||
})
|
||||
.then(function (value) {
|
||||
// ..
|
||||
}, function (err) {
|
||||
// ..
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## Tests
|
||||
|
||||
`$ npm test`
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Released under the [MIT License](http://www.opensource.org/licenses/mit-license.php).
|
||||
52
uni-demo/node_modules/promise-retry/index.js
generated
vendored
Normal file
52
uni-demo/node_modules/promise-retry/index.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
'use strict';
|
||||
|
||||
var errcode = require('err-code');
|
||||
var retry = require('retry');
|
||||
|
||||
var hasOwn = Object.prototype.hasOwnProperty;
|
||||
|
||||
function isRetryError(err) {
|
||||
return err && err.code === 'EPROMISERETRY' && hasOwn.call(err, 'retried');
|
||||
}
|
||||
|
||||
function promiseRetry(fn, options) {
|
||||
var temp;
|
||||
var operation;
|
||||
|
||||
if (typeof fn === 'object' && typeof options === 'function') {
|
||||
// Swap options and fn when using alternate signature (options, fn)
|
||||
temp = options;
|
||||
options = fn;
|
||||
fn = temp;
|
||||
}
|
||||
|
||||
operation = retry.operation(options);
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
operation.attempt(function (number) {
|
||||
Promise.resolve()
|
||||
.then(function () {
|
||||
return fn(function (err) {
|
||||
if (isRetryError(err)) {
|
||||
err = err.retried;
|
||||
}
|
||||
|
||||
throw errcode(new Error('Retrying'), 'EPROMISERETRY', { retried: err });
|
||||
}, number);
|
||||
})
|
||||
.then(resolve, function (err) {
|
||||
if (isRetryError(err)) {
|
||||
err = err.retried;
|
||||
|
||||
if (operation.retry(err || new Error())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = promiseRetry;
|
||||
37
uni-demo/node_modules/promise-retry/package.json
generated
vendored
Normal file
37
uni-demo/node_modules/promise-retry/package.json
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "promise-retry",
|
||||
"version": "2.0.1",
|
||||
"description": "Retries a function that returns a promise, leveraging the power of the retry module.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "mocha --bail -t 10000"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/IndigoUnited/node-promise-retry/issues/"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/IndigoUnited/node-promise-retry.git"
|
||||
},
|
||||
"keywords": [
|
||||
"retry",
|
||||
"promise",
|
||||
"backoff",
|
||||
"repeat",
|
||||
"replay"
|
||||
],
|
||||
"author": "IndigoUnited <hello@indigounited.com> (http://indigounited.com)",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"expect.js": "^0.3.1",
|
||||
"mocha": "^8.0.1",
|
||||
"sleep-promise": "^8.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"err-code": "^2.0.2",
|
||||
"retry": "^0.12.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
}
|
||||
263
uni-demo/node_modules/promise-retry/test/test.js
generated
vendored
Normal file
263
uni-demo/node_modules/promise-retry/test/test.js
generated
vendored
Normal file
@@ -0,0 +1,263 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var promiseRetry = require('../');
|
||||
var promiseDelay = require('sleep-promise');
|
||||
|
||||
describe('promise-retry', function () {
|
||||
it('should call fn again if retry was called', function () {
|
||||
var count = 0;
|
||||
|
||||
return promiseRetry(function (retry) {
|
||||
count += 1;
|
||||
|
||||
return promiseDelay(10)
|
||||
.then(function () {
|
||||
if (count <= 2) {
|
||||
retry(new Error('foo'));
|
||||
}
|
||||
|
||||
return 'final';
|
||||
});
|
||||
}, { factor: 1 })
|
||||
.then(function (value) {
|
||||
expect(value).to.be('final');
|
||||
expect(count).to.be(3);
|
||||
}, function () {
|
||||
throw new Error('should not fail');
|
||||
});
|
||||
});
|
||||
|
||||
it('should call fn with the attempt number', function () {
|
||||
var count = 0;
|
||||
|
||||
return promiseRetry(function (retry, number) {
|
||||
count += 1;
|
||||
expect(count).to.equal(number);
|
||||
|
||||
return promiseDelay(10)
|
||||
.then(function () {
|
||||
if (count <= 2) {
|
||||
retry(new Error('foo'));
|
||||
}
|
||||
|
||||
return 'final';
|
||||
});
|
||||
}, { factor: 1 })
|
||||
.then(function (value) {
|
||||
expect(value).to.be('final');
|
||||
expect(count).to.be(3);
|
||||
}, function () {
|
||||
throw new Error('should not fail');
|
||||
});
|
||||
});
|
||||
|
||||
it('should not retry on fulfillment if retry was not called', function () {
|
||||
var count = 0;
|
||||
|
||||
return promiseRetry(function () {
|
||||
count += 1;
|
||||
|
||||
return promiseDelay(10)
|
||||
.then(function () {
|
||||
return 'final';
|
||||
});
|
||||
})
|
||||
.then(function (value) {
|
||||
expect(value).to.be('final');
|
||||
expect(count).to.be(1);
|
||||
}, function () {
|
||||
throw new Error('should not fail');
|
||||
});
|
||||
});
|
||||
|
||||
it('should not retry on rejection if retry was not called', function () {
|
||||
var count = 0;
|
||||
|
||||
return promiseRetry(function () {
|
||||
count += 1;
|
||||
|
||||
return promiseDelay(10)
|
||||
.then(function () {
|
||||
throw new Error('foo');
|
||||
});
|
||||
})
|
||||
.then(function () {
|
||||
throw new Error('should not succeed');
|
||||
}, function (err) {
|
||||
expect(err.message).to.be('foo');
|
||||
expect(count).to.be(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not retry on rejection if nr of retries is 0', function () {
|
||||
var count = 0;
|
||||
|
||||
return promiseRetry(function (retry) {
|
||||
count += 1;
|
||||
|
||||
return promiseDelay(10)
|
||||
.then(function () {
|
||||
throw new Error('foo');
|
||||
})
|
||||
.catch(retry);
|
||||
}, { retries : 0 })
|
||||
.then(function () {
|
||||
throw new Error('should not succeed');
|
||||
}, function (err) {
|
||||
expect(err.message).to.be('foo');
|
||||
expect(count).to.be(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('should reject the promise if the retries were exceeded', function () {
|
||||
var count = 0;
|
||||
|
||||
return promiseRetry(function (retry) {
|
||||
count += 1;
|
||||
|
||||
return promiseDelay(10)
|
||||
.then(function () {
|
||||
throw new Error('foo');
|
||||
})
|
||||
.catch(retry);
|
||||
}, { retries: 2, factor: 1 })
|
||||
.then(function () {
|
||||
throw new Error('should not succeed');
|
||||
}, function (err) {
|
||||
expect(err.message).to.be('foo');
|
||||
expect(count).to.be(3);
|
||||
});
|
||||
});
|
||||
|
||||
it('should pass options to the underlying retry module', function () {
|
||||
var count = 0;
|
||||
|
||||
return promiseRetry(function (retry) {
|
||||
return promiseDelay(10)
|
||||
.then(function () {
|
||||
if (count < 2) {
|
||||
count += 1;
|
||||
retry(new Error('foo'));
|
||||
}
|
||||
|
||||
return 'final';
|
||||
});
|
||||
}, { retries: 1, factor: 1 })
|
||||
.then(function () {
|
||||
throw new Error('should not succeed');
|
||||
}, function (err) {
|
||||
expect(err.message).to.be('foo');
|
||||
});
|
||||
});
|
||||
|
||||
it('should convert direct fulfillments into promises', function () {
|
||||
return promiseRetry(function () {
|
||||
return 'final';
|
||||
}, { factor: 1 })
|
||||
.then(function (value) {
|
||||
expect(value).to.be('final');
|
||||
}, function () {
|
||||
throw new Error('should not fail');
|
||||
});
|
||||
});
|
||||
|
||||
it('should convert direct rejections into promises', function () {
|
||||
promiseRetry(function () {
|
||||
throw new Error('foo');
|
||||
}, { retries: 1, factor: 1 })
|
||||
.then(function () {
|
||||
throw new Error('should not succeed');
|
||||
}, function (err) {
|
||||
expect(err.message).to.be('foo');
|
||||
});
|
||||
});
|
||||
|
||||
it('should not crash on undefined rejections', function () {
|
||||
return promiseRetry(function () {
|
||||
throw undefined;
|
||||
}, { retries: 1, factor: 1 })
|
||||
.then(function () {
|
||||
throw new Error('should not succeed');
|
||||
}, function (err) {
|
||||
expect(err).to.be(undefined);
|
||||
})
|
||||
.then(function () {
|
||||
return promiseRetry(function (retry) {
|
||||
retry();
|
||||
}, { retries: 1, factor: 1 });
|
||||
})
|
||||
.then(function () {
|
||||
throw new Error('should not succeed');
|
||||
}, function (err) {
|
||||
expect(err).to.be(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
it('should retry if retry() was called with undefined', function () {
|
||||
var count = 0;
|
||||
|
||||
return promiseRetry(function (retry) {
|
||||
count += 1;
|
||||
|
||||
return promiseDelay(10)
|
||||
.then(function () {
|
||||
if (count <= 2) {
|
||||
retry();
|
||||
}
|
||||
|
||||
return 'final';
|
||||
});
|
||||
}, { factor: 1 })
|
||||
.then(function (value) {
|
||||
expect(value).to.be('final');
|
||||
expect(count).to.be(3);
|
||||
}, function () {
|
||||
throw new Error('should not fail');
|
||||
});
|
||||
});
|
||||
|
||||
it('should work with several retries in the same chain', function () {
|
||||
var count = 0;
|
||||
|
||||
return promiseRetry(function (retry) {
|
||||
count += 1;
|
||||
|
||||
return promiseDelay(10)
|
||||
.then(function () {
|
||||
retry(new Error('foo'));
|
||||
})
|
||||
.catch(function (err) {
|
||||
retry(err);
|
||||
});
|
||||
}, { retries: 1, factor: 1 })
|
||||
.then(function () {
|
||||
throw new Error('should not succeed');
|
||||
}, function (err) {
|
||||
expect(err.message).to.be('foo');
|
||||
expect(count).to.be(2);
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow options to be passed first', function () {
|
||||
var count = 0;
|
||||
|
||||
return promiseRetry({ factor: 1 }, function (retry) {
|
||||
count += 1;
|
||||
|
||||
return promiseDelay(10)
|
||||
.then(function () {
|
||||
if (count <= 2) {
|
||||
retry(new Error('foo'));
|
||||
}
|
||||
|
||||
return 'final';
|
||||
});
|
||||
}).then(function (value) {
|
||||
expect(value).to.be('final');
|
||||
expect(count).to.be(3);
|
||||
}, function () {
|
||||
throw new Error('should not fail');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user