aboutsummaryrefslogtreecommitdiff
path: root/node_modules/cacheable-request
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/cacheable-request')
-rw-r--r--node_modules/cacheable-request/LICENSE21
-rw-r--r--node_modules/cacheable-request/README.md206
-rw-r--r--node_modules/cacheable-request/node_modules/get-stream/buffer-stream.js52
-rw-r--r--node_modules/cacheable-request/node_modules/get-stream/index.d.ts108
-rw-r--r--node_modules/cacheable-request/node_modules/get-stream/index.js60
-rw-r--r--node_modules/cacheable-request/node_modules/get-stream/license9
-rw-r--r--node_modules/cacheable-request/node_modules/get-stream/package.json50
-rw-r--r--node_modules/cacheable-request/node_modules/get-stream/readme.md124
-rw-r--r--node_modules/cacheable-request/package.json56
-rw-r--r--node_modules/cacheable-request/src/index.js251
10 files changed, 937 insertions, 0 deletions
diff --git a/node_modules/cacheable-request/LICENSE b/node_modules/cacheable-request/LICENSE
new file mode 100644
index 0000000..f27ee9b
--- /dev/null
+++ b/node_modules/cacheable-request/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2017 Luke Childs
+
+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.
diff --git a/node_modules/cacheable-request/README.md b/node_modules/cacheable-request/README.md
new file mode 100644
index 0000000..725e7e0
--- /dev/null
+++ b/node_modules/cacheable-request/README.md
@@ -0,0 +1,206 @@
+# cacheable-request
+
+> Wrap native HTTP requests with RFC compliant cache support
+
+[![Build Status](https://travis-ci.org/lukechilds/cacheable-request.svg?branch=master)](https://travis-ci.org/lukechilds/cacheable-request)
+[![Coverage Status](https://coveralls.io/repos/github/lukechilds/cacheable-request/badge.svg?branch=master)](https://coveralls.io/github/lukechilds/cacheable-request?branch=master)
+[![npm](https://img.shields.io/npm/dm/cacheable-request.svg)](https://www.npmjs.com/package/cacheable-request)
+[![npm](https://img.shields.io/npm/v/cacheable-request.svg)](https://www.npmjs.com/package/cacheable-request)
+
+[RFC 7234](http://httpwg.org/specs/rfc7234.html) compliant HTTP caching for native Node.js HTTP/HTTPS requests. Caching works out of the box in memory or is easily pluggable with a wide range of storage adapters.
+
+**Note:** This is a low level wrapper around the core HTTP modules, it's not a high level request library.
+
+## Features
+
+- Only stores cacheable responses as defined by RFC 7234
+- Fresh cache entries are served directly from cache
+- Stale cache entries are revalidated with `If-None-Match`/`If-Modified-Since` headers
+- 304 responses from revalidation requests use cached body
+- Updates `Age` header on cached responses
+- Can completely bypass cache on a per request basis
+- In memory cache by default
+- Official support for Redis, MongoDB, SQLite, PostgreSQL and MySQL storage adapters
+- Easily plug in your own or third-party storage adapters
+- If DB connection fails, cache is automatically bypassed ([disabled by default](#optsautomaticfailover))
+- Adds cache support to any existing HTTP code with minimal changes
+- Uses [http-cache-semantics](https://github.com/pornel/http-cache-semantics) internally for HTTP RFC 7234 compliance
+
+## Install
+
+```shell
+npm install cacheable-request
+```
+
+## Usage
+
+```js
+const http = require('http');
+const CacheableRequest = require('cacheable-request');
+
+// Then instead of
+const req = http.request('http://example.com', cb);
+req.end();
+
+// You can do
+const cacheableRequest = new CacheableRequest(http.request);
+const cacheReq = cacheableRequest('http://example.com', cb);
+cacheReq.on('request', req => req.end());
+// Future requests to 'example.com' will be returned from cache if still valid
+
+// You pass in any other http.request API compatible method to be wrapped with cache support:
+const cacheableRequest = new CacheableRequest(https.request);
+const cacheableRequest = new CacheableRequest(electron.net);
+```
+
+## Storage Adapters
+
+`cacheable-request` uses [Keyv](https://github.com/lukechilds/keyv) to support a wide range of storage adapters.
+
+For example, to use Redis as a cache backend, you just need to install the official Redis Keyv storage adapter:
+
+```
+npm install @keyv/redis
+```
+
+And then you can pass `CacheableRequest` your connection string:
+
+```js
+const cacheableRequest = new CacheableRequest(http.request, 'redis://user:pass@localhost:6379');
+```
+
+[View all official Keyv storage adapters.](https://github.com/lukechilds/keyv#official-storage-adapters)
+
+Keyv also supports anything that follows the Map API so it's easy to write your own storage adapter or use a third-party solution.
+
+e.g The following are all valid storage adapters
+
+```js
+const storageAdapter = new Map();
+// or
+const storageAdapter = require('./my-storage-adapter');
+// or
+const QuickLRU = require('quick-lru');
+const storageAdapter = new QuickLRU({ maxSize: 1000 });
+
+const cacheableRequest = new CacheableRequest(http.request, storageAdapter);
+```
+
+View the [Keyv docs](https://github.com/lukechilds/keyv) for more information on how to use storage adapters.
+
+## API
+
+### new cacheableRequest(request, [storageAdapter])
+
+Returns the provided request function wrapped with cache support.
+
+#### request
+
+Type: `function`
+
+Request function to wrap with cache support. Should be [`http.request`](https://nodejs.org/api/http.html#http_http_request_options_callback) or a similar API compatible request function.
+
+#### storageAdapter
+
+Type: `Keyv storage adapter`<br>
+Default: `new Map()`
+
+A [Keyv](https://github.com/lukechilds/keyv) storage adapter instance, or connection string if using with an official Keyv storage adapter.
+
+### Instance
+
+#### cacheableRequest(opts, [cb])
+
+Returns an event emitter.
+
+##### opts
+
+Type: `object`, `string`
+
+- Any of the default request functions options.
+- Any [`http-cache-semantics`](https://github.com/kornelski/http-cache-semantics#constructor-options) options.
+- Any of the following:
+
+###### opts.cache
+
+Type: `boolean`<br>
+Default: `true`
+
+If the cache should be used. Setting this to false will completely bypass the cache for the current request.
+
+###### opts.strictTtl
+
+Type: `boolean`<br>
+Default: `false`
+
+If set to `true` once a cached resource has expired it is deleted and will have to be re-requested.
+
+If set to `false` (default), after a cached resource's TTL expires it is kept in the cache and will be revalidated on the next request with `If-None-Match`/`If-Modified-Since` headers.
+
+###### opts.maxTtl
+
+Type: `number`<br>
+Default: `undefined`
+
+Limits TTL. The `number` represents milliseconds.
+
+###### opts.automaticFailover
+
+Type: `boolean`<br>
+Default: `false`
+
+When set to `true`, if the DB connection fails we will automatically fallback to a network request. DB errors will still be emitted to notify you of the problem even though the request callback may succeed.
+
+###### opts.forceRefresh
+
+Type: `boolean`<br>
+Default: `false`
+
+Forces refreshing the cache. If the response could be retrieved from the cache, it will perform a new request and override the cache instead.
+
+##### cb
+
+Type: `function`
+
+The callback function which will receive the response as an argument.
+
+The response can be either a [Node.js HTTP response stream](https://nodejs.org/api/http.html#http_class_http_incomingmessage) or a [responselike object](https://github.com/lukechilds/responselike). The response will also have a `fromCache` property set with a boolean value.
+
+##### .on('request', request)
+
+`request` event to get the request object of the request.
+
+**Note:** This event will only fire if an HTTP request is actually made, not when a response is retrieved from cache. However, you should always handle the `request` event to end the request and handle any potential request errors.
+
+##### .on('response', response)
+
+`response` event to get the response object from the HTTP request or cache.
+
+##### .on('error', error)
+
+`error` event emitted in case of an error with the cache.
+
+Errors emitted here will be an instance of `CacheableRequest.RequestError` or `CacheableRequest.CacheError`. You will only ever receive a `RequestError` if the request function throws (normally caused by invalid user input). Normal request errors should be handled inside the `request` event.
+
+To properly handle all error scenarios you should use the following pattern:
+
+```js
+cacheableRequest('example.com', cb)
+ .on('error', err => {
+ if (err instanceof CacheableRequest.CacheError) {
+ handleCacheError(err); // Cache error
+ } else if (err instanceof CacheableRequest.RequestError) {
+ handleRequestError(err); // Request function thrown
+ }
+ })
+ .on('request', req => {
+ req.on('error', handleRequestError); // Request error emitted
+ req.end();
+ });
+```
+
+**Note:** Database connection errors are emitted here, however `cacheable-request` will attempt to re-request the resource and bypass the cache on a connection error. Therefore a database connection error doesn't necessarily mean the request won't be fulfilled.
+
+## License
+
+MIT © Luke Childs
diff --git a/node_modules/cacheable-request/node_modules/get-stream/buffer-stream.js b/node_modules/cacheable-request/node_modules/get-stream/buffer-stream.js
new file mode 100644
index 0000000..2dd7574
--- /dev/null
+++ b/node_modules/cacheable-request/node_modules/get-stream/buffer-stream.js
@@ -0,0 +1,52 @@
+'use strict';
+const {PassThrough: PassThroughStream} = require('stream');
+
+module.exports = options => {
+ options = {...options};
+
+ const {array} = options;
+ let {encoding} = options;
+ const isBuffer = encoding === 'buffer';
+ let objectMode = false;
+
+ if (array) {
+ objectMode = !(encoding || isBuffer);
+ } else {
+ encoding = encoding || 'utf8';
+ }
+
+ if (isBuffer) {
+ encoding = null;
+ }
+
+ const stream = new PassThroughStream({objectMode});
+
+ if (encoding) {
+ stream.setEncoding(encoding);
+ }
+
+ let length = 0;
+ const chunks = [];
+
+ stream.on('data', chunk => {
+ chunks.push(chunk);
+
+ if (objectMode) {
+ length = chunks.length;
+ } else {
+ length += chunk.length;
+ }
+ });
+
+ stream.getBufferedValue = () => {
+ if (array) {
+ return chunks;
+ }
+
+ return isBuffer ? Buffer.concat(chunks, length) : chunks.join('');
+ };
+
+ stream.getBufferedLength = () => length;
+
+ return stream;
+};
diff --git a/node_modules/cacheable-request/node_modules/get-stream/index.d.ts b/node_modules/cacheable-request/node_modules/get-stream/index.d.ts
new file mode 100644
index 0000000..7b98134
--- /dev/null
+++ b/node_modules/cacheable-request/node_modules/get-stream/index.d.ts
@@ -0,0 +1,108 @@
+/// <reference types="node"/>
+import {Stream} from 'stream';
+
+declare class MaxBufferErrorClass extends Error {
+ readonly name: 'MaxBufferError';
+ constructor();
+}
+
+declare namespace getStream {
+ interface Options {
+ /**
+ Maximum length of the returned string. If it exceeds this value before the stream ends, the promise will be rejected with a `MaxBufferError` error.
+
+ @default Infinity
+ */
+ readonly maxBuffer?: number;
+ }
+
+ interface OptionsWithEncoding<EncodingType = BufferEncoding> extends Options {
+ /**
+ [Encoding](https://nodejs.org/api/buffer.html#buffer_buffer) of the incoming stream.
+
+ @default 'utf8'
+ */
+ readonly encoding?: EncodingType;
+ }
+
+ type MaxBufferError = MaxBufferErrorClass;
+}
+
+declare const getStream: {
+ /**
+ Get the `stream` as a string.
+
+ @returns A promise that resolves when the end event fires on the stream, indicating that there is no more data to be read. The stream is switched to flowing mode.
+
+ @example
+ ```
+ import * as fs from 'fs';
+ import getStream = require('get-stream');
+
+ (async () => {
+ const stream = fs.createReadStream('unicorn.txt');
+
+ console.log(await getStream(stream));
+ // ,,))))))));,
+ // __)))))))))))))),
+ // \|/ -\(((((''''((((((((.
+ // -*-==//////(('' . `)))))),
+ // /|\ ))| o ;-. '((((( ,(,
+ // ( `| / ) ;))))' ,_))^;(~
+ // | | | ,))((((_ _____------~~~-. %,;(;(>';'~
+ // o_); ; )))(((` ~---~ `:: \ %%~~)(v;(`('~
+ // ; ''''```` `: `:::|\,__,%% );`'; ~
+ // | _ ) / `:|`----' `-'
+ // ______/\/~ | / /
+ // /~;;.____/;;' / ___--,-( `;;;/
+ // / // _;______;'------~~~~~ /;;/\ /
+ // // | | / ; \;;,\
+ // (<_ | ; /',/-----' _>
+ // \_| ||_ //~;~~~~~~~~~
+ // `\_| (,~~
+ // \~\
+ // ~~
+ })();
+ ```
+ */
+ (stream: Stream, options?: getStream.OptionsWithEncoding): Promise<string>;
+
+ /**
+ Get the `stream` as a buffer.
+
+ It honors the `maxBuffer` option as above, but it refers to byte length rather than string length.
+ */
+ buffer(
+ stream: Stream,
+ options?: getStream.OptionsWithEncoding
+ ): Promise<Buffer>;
+
+ /**
+ Get the `stream` as an array of values.
+
+ It honors both the `maxBuffer` and `encoding` options. The behavior changes slightly based on the encoding chosen:
+
+ - When `encoding` is unset, it assumes an [object mode stream](https://nodesource.com/blog/understanding-object-streams/) and collects values emitted from `stream` unmodified. In this case `maxBuffer` refers to the number of items in the array (not the sum of their sizes).
+ - When `encoding` is set to `buffer`, it collects an array of buffers. `maxBuffer` refers to the summed byte lengths of every buffer in the array.
+ - When `encoding` is set to anything else, it collects an array of strings. `maxBuffer` refers to the summed character lengths of every string in the array.
+ */
+ array<StreamObjectModeType>(
+ stream: Stream,
+ options?: getStream.Options
+ ): Promise<StreamObjectModeType[]>;
+ array(
+ stream: Stream,
+ options: getStream.OptionsWithEncoding<'buffer'>
+ ): Promise<Buffer[]>;
+ array(
+ stream: Stream,
+ options: getStream.OptionsWithEncoding<BufferEncoding>
+ ): Promise<string[]>;
+
+ MaxBufferError: typeof MaxBufferErrorClass;
+
+ // TODO: Remove this for the next major release
+ default: typeof getStream;
+};
+
+export = getStream;
diff --git a/node_modules/cacheable-request/node_modules/get-stream/index.js b/node_modules/cacheable-request/node_modules/get-stream/index.js
new file mode 100644
index 0000000..71f3991
--- /dev/null
+++ b/node_modules/cacheable-request/node_modules/get-stream/index.js
@@ -0,0 +1,60 @@
+'use strict';
+const {constants: BufferConstants} = require('buffer');
+const pump = require('pump');
+const bufferStream = require('./buffer-stream');
+
+class MaxBufferError extends Error {
+ constructor() {
+ super('maxBuffer exceeded');
+ this.name = 'MaxBufferError';
+ }
+}
+
+async function getStream(inputStream, options) {
+ if (!inputStream) {
+ return Promise.reject(new Error('Expected a stream'));
+ }
+
+ options = {
+ maxBuffer: Infinity,
+ ...options
+ };
+
+ const {maxBuffer} = options;
+
+ let stream;
+ await new Promise((resolve, reject) => {
+ const rejectPromise = error => {
+ // Don't retrieve an oversized buffer.
+ if (error && stream.getBufferedLength() <= BufferConstants.MAX_LENGTH) {
+ error.bufferedData = stream.getBufferedValue();
+ }
+
+ reject(error);
+ };
+
+ stream = pump(inputStream, bufferStream(options), error => {
+ if (error) {
+ rejectPromise(error);
+ return;
+ }
+
+ resolve();
+ });
+
+ stream.on('data', () => {
+ if (stream.getBufferedLength() > maxBuffer) {
+ rejectPromise(new MaxBufferError());
+ }
+ });
+ });
+
+ return stream.getBufferedValue();
+}
+
+module.exports = getStream;
+// TODO: Remove this for the next major release
+module.exports.default = getStream;
+module.exports.buffer = (stream, options) => getStream(stream, {...options, encoding: 'buffer'});
+module.exports.array = (stream, options) => getStream(stream, {...options, array: true});
+module.exports.MaxBufferError = MaxBufferError;
diff --git a/node_modules/cacheable-request/node_modules/get-stream/license b/node_modules/cacheable-request/node_modules/get-stream/license
new file mode 100644
index 0000000..fa7ceba
--- /dev/null
+++ b/node_modules/cacheable-request/node_modules/get-stream/license
@@ -0,0 +1,9 @@
+MIT License
+
+Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.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.
diff --git a/node_modules/cacheable-request/node_modules/get-stream/package.json b/node_modules/cacheable-request/node_modules/get-stream/package.json
new file mode 100644
index 0000000..e2f1687
--- /dev/null
+++ b/node_modules/cacheable-request/node_modules/get-stream/package.json
@@ -0,0 +1,50 @@
+{
+ "name": "get-stream",
+ "version": "5.2.0",
+ "description": "Get a stream as a string, buffer, or array",
+ "license": "MIT",
+ "repository": "sindresorhus/get-stream",
+ "funding": "https://github.com/sponsors/sindresorhus",
+ "author": {
+ "name": "Sindre Sorhus",
+ "email": "sindresorhus@gmail.com",
+ "url": "https://sindresorhus.com"
+ },
+ "engines": {
+ "node": ">=8"
+ },
+ "scripts": {
+ "test": "xo && ava && tsd"
+ },
+ "files": [
+ "index.js",
+ "index.d.ts",
+ "buffer-stream.js"
+ ],
+ "keywords": [
+ "get",
+ "stream",
+ "promise",
+ "concat",
+ "string",
+ "text",
+ "buffer",
+ "read",
+ "data",
+ "consume",
+ "readable",
+ "readablestream",
+ "array",
+ "object"
+ ],
+ "dependencies": {
+ "pump": "^3.0.0"
+ },
+ "devDependencies": {
+ "@types/node": "^12.0.7",
+ "ava": "^2.0.0",
+ "into-stream": "^5.0.0",
+ "tsd": "^0.7.2",
+ "xo": "^0.24.0"
+ }
+}
diff --git a/node_modules/cacheable-request/node_modules/get-stream/readme.md b/node_modules/cacheable-request/node_modules/get-stream/readme.md
new file mode 100644
index 0000000..7d7565d
--- /dev/null
+++ b/node_modules/cacheable-request/node_modules/get-stream/readme.md
@@ -0,0 +1,124 @@
+# get-stream [![Build Status](https://travis-ci.com/sindresorhus/get-stream.svg?branch=master)](https://travis-ci.com/github/sindresorhus/get-stream)
+
+> Get a stream as a string, buffer, or array
+
+## Install
+
+```
+$ npm install get-stream
+```
+
+## Usage
+
+```js
+const fs = require('fs');
+const getStream = require('get-stream');
+
+(async () => {
+ const stream = fs.createReadStream('unicorn.txt');
+
+ console.log(await getStream(stream));
+ /*
+ ,,))))))));,
+ __)))))))))))))),
+ \|/ -\(((((''''((((((((.
+ -*-==//////(('' . `)))))),
+ /|\ ))| o ;-. '((((( ,(,
+ ( `| / ) ;))))' ,_))^;(~
+ | | | ,))((((_ _____------~~~-. %,;(;(>';'~
+ o_); ; )))(((` ~---~ `:: \ %%~~)(v;(`('~
+ ; ''''```` `: `:::|\,__,%% );`'; ~
+ | _ ) / `:|`----' `-'
+ ______/\/~ | / /
+ /~;;.____/;;' / ___--,-( `;;;/
+ / // _;______;'------~~~~~ /;;/\ /
+ // | | / ; \;;,\
+ (<_ | ; /',/-----' _>
+ \_| ||_ //~;~~~~~~~~~
+ `\_| (,~~
+ \~\
+ ~~
+ */
+})();
+```
+
+## API
+
+The methods returns a promise that resolves when the `end` event fires on the stream, indicating that there is no more data to be read. The stream is switched to flowing mode.
+
+### getStream(stream, options?)
+
+Get the `stream` as a string.
+
+#### options
+
+Type: `object`
+
+##### encoding
+
+Type: `string`\
+Default: `'utf8'`
+
+[Encoding](https://nodejs.org/api/buffer.html#buffer_buffer) of the incoming stream.
+
+##### maxBuffer
+
+Type: `number`\
+Default: `Infinity`
+
+Maximum length of the returned string. If it exceeds this value before the stream ends, the promise will be rejected with a `getStream.MaxBufferError` error.
+
+### getStream.buffer(stream, options?)
+
+Get the `stream` as a buffer.
+
+It honors the `maxBuffer` option as above, but it refers to byte length rather than string length.
+
+### getStream.array(stream, options?)
+
+Get the `stream` as an array of values.
+
+It honors both the `maxBuffer` and `encoding` options. The behavior changes slightly based on the encoding chosen:
+
+- When `encoding` is unset, it assumes an [object mode stream](https://nodesource.com/blog/understanding-object-streams/) and collects values emitted from `stream` unmodified. In this case `maxBuffer` refers to the number of items in the array (not the sum of their sizes).
+
+- When `encoding` is set to `buffer`, it collects an array of buffers. `maxBuffer` refers to the summed byte lengths of every buffer in the array.
+
+- When `encoding` is set to anything else, it collects an array of strings. `maxBuffer` refers to the summed character lengths of every string in the array.
+
+## Errors
+
+If the input stream emits an `error` event, the promise will be rejected with the error. The buffered data will be attached to the `bufferedData` property of the error.
+
+```js
+(async () => {
+ try {
+ await getStream(streamThatErrorsAtTheEnd('unicorn'));
+ } catch (error) {
+ console.log(error.bufferedData);
+ //=> 'unicorn'
+ }
+})()
+```
+
+## FAQ
+
+### How is this different from [`concat-stream`](https://github.com/maxogden/concat-stream)?
+
+This module accepts a stream instead of being one and returns a promise instead of using a callback. The API is simpler and it only supports returning a string, buffer, or array. It doesn't have a fragile type inference. You explicitly choose what you want. And it doesn't depend on the huge `readable-stream` package.
+
+## Related
+
+- [get-stdin](https://github.com/sindresorhus/get-stdin) - Get stdin as a string or buffer
+
+---
+
+<div align="center">
+ <b>
+ <a href="https://tidelift.com/subscription/pkg/npm-get-stream?utm_source=npm-get-stream&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
+ </b>
+ <br>
+ <sub>
+ Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
+ </sub>
+</div>
diff --git a/node_modules/cacheable-request/package.json b/node_modules/cacheable-request/package.json
new file mode 100644
index 0000000..b3e0242
--- /dev/null
+++ b/node_modules/cacheable-request/package.json
@@ -0,0 +1,56 @@
+{
+ "name": "cacheable-request",
+ "version": "7.0.2",
+ "description": "Wrap native HTTP requests with RFC compliant cache support",
+ "license": "MIT",
+ "repository": "lukechilds/cacheable-request",
+ "author": "Luke Childs <lukechilds123@gmail.com> (http://lukechilds.co.uk)",
+ "main": "src/index.js",
+ "engines": {
+ "node": ">=8"
+ },
+ "scripts": {
+ "test": "xo && nyc ava",
+ "coverage": "nyc report --reporter=text-lcov | coveralls"
+ },
+ "files": [
+ "src"
+ ],
+ "keywords": [
+ "HTTP",
+ "HTTPS",
+ "cache",
+ "caching",
+ "layer",
+ "cacheable",
+ "RFC 7234",
+ "RFC",
+ "7234",
+ "compliant"
+ ],
+ "dependencies": {
+ "clone-response": "^1.0.2",
+ "get-stream": "^5.1.0",
+ "http-cache-semantics": "^4.0.0",
+ "keyv": "^4.0.0",
+ "lowercase-keys": "^2.0.0",
+ "normalize-url": "^6.0.1",
+ "responselike": "^2.0.0"
+ },
+ "devDependencies": {
+ "@keyv/sqlite": "^2.0.0",
+ "ava": "^1.1.0",
+ "coveralls": "^3.0.0",
+ "create-test-server": "3.0.0",
+ "delay": "^4.0.0",
+ "eslint-config-xo-lukechilds": "^1.0.0",
+ "nyc": "^14.1.1",
+ "pify": "^4.0.0",
+ "sqlite3": "^4.0.2",
+ "this": "^1.0.2",
+ "xo": "^0.23.0"
+ },
+ "xo": {
+ "extends": "xo-lukechilds"
+ }
+}
diff --git a/node_modules/cacheable-request/src/index.js b/node_modules/cacheable-request/src/index.js
new file mode 100644
index 0000000..3fcea3f
--- /dev/null
+++ b/node_modules/cacheable-request/src/index.js
@@ -0,0 +1,251 @@
+'use strict';
+
+const EventEmitter = require('events');
+const urlLib = require('url');
+const normalizeUrl = require('normalize-url');
+const getStream = require('get-stream');
+const CachePolicy = require('http-cache-semantics');
+const Response = require('responselike');
+const lowercaseKeys = require('lowercase-keys');
+const cloneResponse = require('clone-response');
+const Keyv = require('keyv');
+
+class CacheableRequest {
+ constructor(request, cacheAdapter) {
+ if (typeof request !== 'function') {
+ throw new TypeError('Parameter `request` must be a function');
+ }
+
+ this.cache = new Keyv({
+ uri: typeof cacheAdapter === 'string' && cacheAdapter,
+ store: typeof cacheAdapter !== 'string' && cacheAdapter,
+ namespace: 'cacheable-request'
+ });
+
+ return this.createCacheableRequest(request);
+ }
+
+ createCacheableRequest(request) {
+ return (opts, cb) => {
+ let url;
+ if (typeof opts === 'string') {
+ url = normalizeUrlObject(urlLib.parse(opts));
+ opts = {};
+ } else if (opts instanceof urlLib.URL) {
+ url = normalizeUrlObject(urlLib.parse(opts.toString()));
+ opts = {};
+ } else {
+ const [pathname, ...searchParts] = (opts.path || '').split('?');
+ const search = searchParts.length > 0 ?
+ `?${searchParts.join('?')}` :
+ '';
+ url = normalizeUrlObject({ ...opts, pathname, search });
+ }
+
+ opts = {
+ headers: {},
+ method: 'GET',
+ cache: true,
+ strictTtl: false,
+ automaticFailover: false,
+ ...opts,
+ ...urlObjectToRequestOptions(url)
+ };
+ opts.headers = lowercaseKeys(opts.headers);
+
+ const ee = new EventEmitter();
+ const normalizedUrlString = normalizeUrl(
+ urlLib.format(url),
+ {
+ stripWWW: false,
+ removeTrailingSlash: false,
+ stripAuthentication: false
+ }
+ );
+ const key = `${opts.method}:${normalizedUrlString}`;
+ let revalidate = false;
+ let madeRequest = false;
+
+ const makeRequest = opts => {
+ madeRequest = true;
+ let requestErrored = false;
+ let requestErrorCallback;
+
+ const requestErrorPromise = new Promise(resolve => {
+ requestErrorCallback = () => {
+ if (!requestErrored) {
+ requestErrored = true;
+ resolve();
+ }
+ };
+ });
+
+ const handler = response => {
+ if (revalidate && !opts.forceRefresh) {
+ response.status = response.statusCode;
+ const revalidatedPolicy = CachePolicy.fromObject(revalidate.cachePolicy).revalidatedPolicy(opts, response);
+ if (!revalidatedPolicy.modified) {
+ const headers = revalidatedPolicy.policy.responseHeaders();
+ response = new Response(revalidate.statusCode, headers, revalidate.body, revalidate.url);
+ response.cachePolicy = revalidatedPolicy.policy;
+ response.fromCache = true;
+ }
+ }
+
+ if (!response.fromCache) {
+ response.cachePolicy = new CachePolicy(opts, response, opts);
+ response.fromCache = false;
+ }
+
+ let clonedResponse;
+ if (opts.cache && response.cachePolicy.storable()) {
+ clonedResponse = cloneResponse(response);
+
+ (async () => {
+ try {
+ const bodyPromise = getStream.buffer(response);
+
+ await Promise.race([
+ requestErrorPromise,
+ new Promise(resolve => response.once('end', resolve))
+ ]);
+
+ if (requestErrored) {
+ return;
+ }
+
+ const body = await bodyPromise;
+
+ const value = {
+ cachePolicy: response.cachePolicy.toObject(),
+ url: response.url,
+ statusCode: response.fromCache ? revalidate.statusCode : response.statusCode,
+ body
+ };
+
+ let ttl = opts.strictTtl ? response.cachePolicy.timeToLive() : undefined;
+ if (opts.maxTtl) {
+ ttl = ttl ? Math.min(ttl, opts.maxTtl) : opts.maxTtl;
+ }
+
+ await this.cache.set(key, value, ttl);
+ } catch (error) {
+ ee.emit('error', new CacheableRequest.CacheError(error));
+ }
+ })();
+ } else if (opts.cache && revalidate) {
+ (async () => {
+ try {
+ await this.cache.delete(key);
+ } catch (error) {
+ ee.emit('error', new CacheableRequest.CacheError(error));
+ }
+ })();
+ }
+
+ ee.emit('response', clonedResponse || response);
+ if (typeof cb === 'function') {
+ cb(clonedResponse || response);
+ }
+ };
+
+ try {
+ const req = request(opts, handler);
+ req.once('error', requestErrorCallback);
+ req.once('abort', requestErrorCallback);
+ ee.emit('request', req);
+ } catch (error) {
+ ee.emit('error', new CacheableRequest.RequestError(error));
+ }
+ };
+
+ (async () => {
+ const get = async opts => {
+ await Promise.resolve();
+
+ const cacheEntry = opts.cache ? await this.cache.get(key) : undefined;
+ if (typeof cacheEntry === 'undefined') {
+ return makeRequest(opts);
+ }
+
+ const policy = CachePolicy.fromObject(cacheEntry.cachePolicy);
+ if (policy.satisfiesWithoutRevalidation(opts) && !opts.forceRefresh) {
+ const headers = policy.responseHeaders();
+ const response = new Response(cacheEntry.statusCode, headers, cacheEntry.body, cacheEntry.url);
+ response.cachePolicy = policy;
+ response.fromCache = true;
+
+ ee.emit('response', response);
+ if (typeof cb === 'function') {
+ cb(response);
+ }
+ } else {
+ revalidate = cacheEntry;
+ opts.headers = policy.revalidationHeaders(opts);
+ makeRequest(opts);
+ }
+ };
+
+ const errorHandler = error => ee.emit('error', new CacheableRequest.CacheError(error));
+ this.cache.once('error', errorHandler);
+ ee.on('response', () => this.cache.removeListener('error', errorHandler));
+
+ try {
+ await get(opts);
+ } catch (error) {
+ if (opts.automaticFailover && !madeRequest) {
+ makeRequest(opts);
+ }
+
+ ee.emit('error', new CacheableRequest.CacheError(error));
+ }
+ })();
+
+ return ee;
+ };
+ }
+}
+
+function urlObjectToRequestOptions(url) {
+ const options = { ...url };
+ options.path = `${url.pathname || '/'}${url.search || ''}`;
+ delete options.pathname;
+ delete options.search;
+ return options;
+}
+
+function normalizeUrlObject(url) {
+ // If url was parsed by url.parse or new URL:
+ // - hostname will be set
+ // - host will be hostname[:port]
+ // - port will be set if it was explicit in the parsed string
+ // Otherwise, url was from request options:
+ // - hostname or host may be set
+ // - host shall not have port encoded
+ return {
+ protocol: url.protocol,
+ auth: url.auth,
+ hostname: url.hostname || url.host || 'localhost',
+ port: url.port,
+ pathname: url.pathname,
+ search: url.search
+ };
+}
+
+CacheableRequest.RequestError = class extends Error {
+ constructor(error) {
+ super(error.message);
+ this.name = 'RequestError';
+ Object.assign(this, error);
+ }
+};
+
+CacheableRequest.CacheError = class extends Error {
+ constructor(error) {
+ super(error.message);
+ this.name = 'CacheError';
+ Object.assign(this, error);
+ }
+};
+
+module.exports = CacheableRequest;