This commit is contained in:
girinb
2025-05-29 15:41:51 +09:00
parent a1bd4f87a1
commit 485098cd1a
5611 changed files with 881685 additions and 0 deletions

View File

@@ -0,0 +1,127 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export interface TeenyStatisticsOptions {
/**
* A positive number representing when to issue a warning about the number
* of concurrent requests using teeny-request.
* Set to 0 to disable this warning.
* Corresponds to the TEENY_REQUEST_WARN_CONCURRENT_REQUESTS environment
* variable.
*/
concurrentRequests?: number;
}
type TeenyStatisticsConfig = Required<TeenyStatisticsOptions>;
/**
* TeenyStatisticsCounters is distinct from TeenyStatisticsOptions:
* Used when dumping current counters and other internal metrics.
*/
export interface TeenyStatisticsCounters {
concurrentRequests: number;
}
/**
* @class TeenyStatisticsWarning
* @extends Error
* @description While an error, is used for emitting warnings when
* meeting certain configured thresholds.
* @see process.emitWarning
*/
export declare class TeenyStatisticsWarning extends Error {
static readonly CONCURRENT_REQUESTS = "ConcurrentRequestsExceededWarning";
threshold: number;
type: string;
value: number;
/**
* @param {string} message
*/
constructor(message: string);
}
/**
* @class TeenyStatistics
* @description Maintain various statistics internal to teeny-request. Tracking
* is not automatic and must be instrumented within teeny-request.
*/
export declare class TeenyStatistics {
/**
* @description A default threshold representing when to warn about excessive
* in-flight/concurrent requests.
* @type {number}
* @static
* @readonly
* @default 5000
*/
static readonly DEFAULT_WARN_CONCURRENT_REQUESTS = 5000;
/**
* @type {TeenyStatisticsConfig}
* @private
*/
private _options;
/**
* @type {number}
* @private
* @default 0
*/
private _concurrentRequests;
/**
* @type {boolean}
* @private
* @default false
*/
private _didConcurrentRequestWarn;
/**
* @param {TeenyStatisticsOptions} [opts]
*/
constructor(opts?: TeenyStatisticsOptions);
/**
* Returns a copy of the current options.
* @return {TeenyStatisticsOptions}
*/
getOptions(): TeenyStatisticsOptions;
/**
* Change configured statistics options. This will not preserve unspecified
* options that were previously specified, i.e. this is a reset of options.
* @param {TeenyStatisticsOptions} [opts]
* @returns {TeenyStatisticsConfig} The previous options.
* @see _prepareOptions
*/
setOptions(opts?: TeenyStatisticsOptions): TeenyStatisticsConfig;
/**
* @readonly
* @return {TeenyStatisticsCounters}
*/
get counters(): TeenyStatisticsCounters;
/**
* @description Should call this right before making a request.
*/
requestStarting(): void;
/**
* @description When using `requestStarting`, call this after the request
* has finished.
*/
requestFinished(): void;
/**
* Configuration Precedence:
* 1. Dependency inversion via defined option.
* 2. Global numeric environment variable.
* 3. Built-in default.
* This will not preserve unspecified options previously specified.
* @param {TeenyStatisticsOptions} [opts]
* @returns {TeenyStatisticsOptions}
* @private
*/
private static _prepareOptions;
}
export {};

156
node_modules/teeny-request/build/src/TeenyStatistics.js generated vendored Normal file
View File

@@ -0,0 +1,156 @@
"use strict";
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.TeenyStatistics = exports.TeenyStatisticsWarning = void 0;
/**
* @class TeenyStatisticsWarning
* @extends Error
* @description While an error, is used for emitting warnings when
* meeting certain configured thresholds.
* @see process.emitWarning
*/
class TeenyStatisticsWarning extends Error {
/**
* @param {string} message
*/
constructor(message) {
super(message);
this.threshold = 0;
this.type = '';
this.value = 0;
this.name = this.constructor.name;
Error.captureStackTrace(this, this.constructor);
}
}
exports.TeenyStatisticsWarning = TeenyStatisticsWarning;
TeenyStatisticsWarning.CONCURRENT_REQUESTS = 'ConcurrentRequestsExceededWarning';
/**
* @class TeenyStatistics
* @description Maintain various statistics internal to teeny-request. Tracking
* is not automatic and must be instrumented within teeny-request.
*/
class TeenyStatistics {
/**
* @param {TeenyStatisticsOptions} [opts]
*/
constructor(opts) {
/**
* @type {number}
* @private
* @default 0
*/
this._concurrentRequests = 0;
/**
* @type {boolean}
* @private
* @default false
*/
this._didConcurrentRequestWarn = false;
this._options = TeenyStatistics._prepareOptions(opts);
}
/**
* Returns a copy of the current options.
* @return {TeenyStatisticsOptions}
*/
getOptions() {
return Object.assign({}, this._options);
}
/**
* Change configured statistics options. This will not preserve unspecified
* options that were previously specified, i.e. this is a reset of options.
* @param {TeenyStatisticsOptions} [opts]
* @returns {TeenyStatisticsConfig} The previous options.
* @see _prepareOptions
*/
setOptions(opts) {
const oldOpts = this._options;
this._options = TeenyStatistics._prepareOptions(opts);
return oldOpts;
}
/**
* @readonly
* @return {TeenyStatisticsCounters}
*/
get counters() {
return {
concurrentRequests: this._concurrentRequests,
};
}
/**
* @description Should call this right before making a request.
*/
requestStarting() {
this._concurrentRequests++;
if (this._options.concurrentRequests > 0 &&
this._concurrentRequests >= this._options.concurrentRequests &&
!this._didConcurrentRequestWarn) {
this._didConcurrentRequestWarn = true;
const warning = new TeenyStatisticsWarning('Possible excessive concurrent requests detected. ' +
this._concurrentRequests +
' requests in-flight, which exceeds the configured threshold of ' +
this._options.concurrentRequests +
'. Use the TEENY_REQUEST_WARN_CONCURRENT_REQUESTS environment ' +
'variable or the concurrentRequests option of teeny-request to ' +
'increase or disable (0) this warning.');
warning.type = TeenyStatisticsWarning.CONCURRENT_REQUESTS;
warning.value = this._concurrentRequests;
warning.threshold = this._options.concurrentRequests;
process.emitWarning(warning);
}
}
/**
* @description When using `requestStarting`, call this after the request
* has finished.
*/
requestFinished() {
// TODO negative?
this._concurrentRequests--;
}
/**
* Configuration Precedence:
* 1. Dependency inversion via defined option.
* 2. Global numeric environment variable.
* 3. Built-in default.
* This will not preserve unspecified options previously specified.
* @param {TeenyStatisticsOptions} [opts]
* @returns {TeenyStatisticsOptions}
* @private
*/
static _prepareOptions({ concurrentRequests: diConcurrentRequests, } = {}) {
let concurrentRequests = this.DEFAULT_WARN_CONCURRENT_REQUESTS;
const envConcurrentRequests = Number(process.env.TEENY_REQUEST_WARN_CONCURRENT_REQUESTS);
if (diConcurrentRequests !== undefined) {
concurrentRequests = diConcurrentRequests;
}
else if (!Number.isNaN(envConcurrentRequests)) {
concurrentRequests = envConcurrentRequests;
}
return { concurrentRequests };
}
}
exports.TeenyStatistics = TeenyStatistics;
/**
* @description A default threshold representing when to warn about excessive
* in-flight/concurrent requests.
* @type {number}
* @static
* @readonly
* @default 5000
*/
TeenyStatistics.DEFAULT_WARN_CONCURRENT_REQUESTS = 5000;
//# sourceMappingURL=TeenyStatistics.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"TeenyStatistics.js","sourceRoot":"","sources":["../../src/TeenyStatistics.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAuBH;;;;;;GAMG;AACH,MAAa,sBAAuB,SAAQ,KAAK;IAO/C;;OAEG;IACH,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QARV,cAAS,GAAG,CAAC,CAAC;QACd,SAAI,GAAG,EAAE,CAAC;QACV,UAAK,GAAG,CAAC,CAAC;QAOf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAClD,CAAC;;AAdH,wDAeC;AAdiB,0CAAmB,GAAG,mCAAmC,AAAtC,CAAuC;AAgB5E;;;;GAIG;AACH,MAAa,eAAe;IA+B1B;;OAEG;IACH,YAAY,IAA6B;QAjBzC;;;;WAIG;QACK,wBAAmB,GAAG,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O,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;SAC9B;IACH,CAAC;IAED;;;OAGG;IACH,eAAe;QACb,iBAAiB;QACjB,IAAI,CAAC,mBAAmB,EAAE,CAAC;IAC7B,CAAC;IAED;;;;;;;;;OASG;IACK,MAAM,CAAC,eAAe,CAAC,EAC7B,kBAAkB,EAAE,oBAAoB,MACd,EAAE;QAC5B,IAAI,kBAAkB,GAAG,IAAI,CAAC,gCAAgC,CAAC;QAE/D,MAAM,qBAAqB,GAAG,MAAM,CAClC,OAAO,CAAC,GAAG,CAAC,sCAAsC,CACnD,CAAC;QACF,IAAI,oBAAoB,KAAK,SAAS,EAAE;YACtC,kBAAkB,GAAG,oBAAoB,CAAC;SAC3C;aAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,qBAAqB,CAAC,EAAE;YAC/C,kBAAkB,GAAG,qBAAqB,CAAC;SAC5C;QAED,OAAO,EAAC,kBAAkB,EAAC,CAAC;IAC9B,CAAC;;AAnIH,0CAoIC;AAnIC;;;;;;;GAOG;AACa,gDAAgC,GAAG,IAAI,AAAP,CAAQ"}

32
node_modules/teeny-request/build/src/agents.d.ts generated vendored Normal file
View File

@@ -0,0 +1,32 @@
/**
* @license
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/// <reference types="node" />
/// <reference types="node" />
import { Agent as HTTPAgent } from 'http';
import { Agent as HTTPSAgent } from 'https';
import { Options } from './';
export declare const pool: Map<string, HTTPAgent>;
export type HttpAnyAgent = HTTPAgent | HTTPSAgent;
/**
* Returns a custom request Agent if one is found, otherwise returns undefined
* which will result in the global http(s) Agent being used.
* @private
* @param {string} uri The request uri
* @param {Options} reqOpts The request options
* @returns {HttpAnyAgent|undefined}
*/
export declare function getAgent(uri: string, reqOpts: Options): HttpAnyAgent | undefined;

89
node_modules/teeny-request/build/src/agents.js generated vendored Normal file
View File

@@ -0,0 +1,89 @@
"use strict";
/**
* @license
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAgent = exports.pool = void 0;
const http_1 = require("http");
const https_1 = require("https");
// eslint-disable-next-line node/no-deprecated-api
const url_1 = require("url");
exports.pool = new Map();
/**
* Determines if a proxy should be considered based on the environment.
*
* @param uri The request uri
* @returns {boolean}
*/
function shouldUseProxyForURI(uri) {
const noProxyEnv = process.env.NO_PROXY || process.env.no_proxy;
if (!noProxyEnv) {
return true;
}
const givenURI = new URL(uri);
for (const noProxyRaw of noProxyEnv.split(',')) {
const noProxy = noProxyRaw.trim();
if (noProxy === givenURI.origin || noProxy === givenURI.hostname) {
return false;
}
else if (noProxy.startsWith('*.') || noProxy.startsWith('.')) {
const noProxyWildcard = noProxy.replace(/^\*\./, '.');
if (givenURI.hostname.endsWith(noProxyWildcard)) {
return false;
}
}
}
return true;
}
/**
* Returns a custom request Agent if one is found, otherwise returns undefined
* which will result in the global http(s) Agent being used.
* @private
* @param {string} uri The request uri
* @param {Options} reqOpts The request options
* @returns {HttpAnyAgent|undefined}
*/
function getAgent(uri, reqOpts) {
const isHttp = uri.startsWith('http://');
const proxy = reqOpts.proxy ||
process.env.HTTP_PROXY ||
process.env.http_proxy ||
process.env.HTTPS_PROXY ||
process.env.https_proxy;
const poolOptions = Object.assign({}, reqOpts.pool);
const manuallyProvidedProxy = !!reqOpts.proxy;
const shouldUseProxy = manuallyProvidedProxy || shouldUseProxyForURI(uri);
if (proxy && shouldUseProxy) {
// tslint:disable-next-line variable-name
const Agent = isHttp
? require('http-proxy-agent')
: require('https-proxy-agent');
const proxyOpts = { ...(0, url_1.parse)(proxy), ...poolOptions };
return new Agent(proxyOpts);
}
let key = isHttp ? 'http' : 'https';
if (reqOpts.forever) {
key += ':forever';
if (!exports.pool.has(key)) {
// tslint:disable-next-line variable-name
const Agent = isHttp ? http_1.Agent : https_1.Agent;
exports.pool.set(key, new Agent({ ...poolOptions, keepAlive: true }));
}
}
return exports.pool.get(key);
}
exports.getAgent = getAgent;
//# sourceMappingURL=agents.js.map

1
node_modules/teeny-request/build/src/agents.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"agents.js","sourceRoot":"","sources":["../../src/agents.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAEH,+BAAwC;AACxC,iCAA0C;AAC1C,kDAAkD;AAClD,6BAA0B;AAGb,QAAA,IAAI,GAAG,IAAI,GAAG,EAAqB,CAAC;AAIjD;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,GAAW;IACvC,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;IAChE,IAAI,CAAC,UAAU,EAAE;QACf,OAAO,IAAI,CAAC;KACb;IAED,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAE9B,KAAK,MAAM,UAAU,IAAI,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;QAC9C,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;QAElC,IAAI,OAAO,KAAK,QAAQ,CAAC,MAAM,IAAI,OAAO,KAAK,QAAQ,CAAC,QAAQ,EAAE;YAChE,OAAO,KAAK,CAAC;SACd;aAAM,IAAI,OAAO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AM,CAAC,CAAC,CAAC,OAAO,CAAC;IAEpC,IAAI,OAAO,CAAC,OAAO,EAAE;QACnB,GAAG,IAAI,UAAU,CAAC;QAElB,IAAI,CAAC,YAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YAClB,yCAAyC;YACzC,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,YAAS,CAAC,CAAC,CAAC,aAAU,CAAC;YAC9C,YAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,KAAK,CAAC,EAAC,GAAG,WAAW,EAAE,SAAS,EAAE,IAAI,EAAC,CAAC,CAAC,CAAC;SAC7D;KACF;IAED,OAAO,YAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC;AAxCD,4BAwCC"}

76
node_modules/teeny-request/build/src/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,76 @@
/**
* @license
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import { Agent, AgentOptions as HttpsAgentOptions } from 'https';
import { AgentOptions as HttpAgentOptions } from 'http';
import { PassThrough, Readable } from 'stream';
import { TeenyStatistics } from './TeenyStatistics';
export interface CoreOptions {
method?: string;
timeout?: number;
gzip?: boolean;
json?: any;
headers?: Headers;
body?: string | {};
useQuerystring?: boolean;
qs?: any;
proxy?: string;
multipart?: RequestPart[];
forever?: boolean;
pool?: HttpsAgentOptions | HttpAgentOptions;
}
export interface OptionsWithUri extends CoreOptions {
uri: string;
}
export interface OptionsWithUrl extends CoreOptions {
url: string;
}
export type Options = OptionsWithUri | OptionsWithUrl;
export interface Request extends PassThrough {
agent: Agent | false;
headers: Headers;
href?: string;
}
export interface Response<T = any> {
statusCode: number;
headers: Headers;
body: T;
request: Request;
statusMessage?: string;
}
export interface RequestPart {
body: string | Readable;
}
export interface RequestCallback<T = any> {
(err: Error | null, response: Response, body?: T): void;
}
export declare class RequestError extends Error {
code?: number;
}
interface Headers {
[index: string]: any;
}
declare function teenyRequest(reqOpts: Options): Request;
declare function teenyRequest(reqOpts: Options, callback: RequestCallback): void;
declare namespace teenyRequest {
var defaults: (defaults: CoreOptions) => (reqOpts: Options, callback?: RequestCallback<any> | undefined) => void | Request;
var stats: TeenyStatistics;
var resetStats: () => void;
}
export { teenyRequest };

253
node_modules/teeny-request/build/src/index.js generated vendored Normal file
View File

@@ -0,0 +1,253 @@
"use strict";
/**
* @license
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.teenyRequest = exports.RequestError = void 0;
const node_fetch_1 = require("node-fetch");
const stream_1 = require("stream");
const uuid = require("uuid");
const agents_1 = require("./agents");
const TeenyStatistics_1 = require("./TeenyStatistics");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const streamEvents = require('stream-events');
class RequestError extends Error {
}
exports.RequestError = RequestError;
/**
* Convert options from Request to Fetch format
* @private
* @param reqOpts Request options
*/
function requestToFetchOptions(reqOpts) {
const options = {
method: reqOpts.method || 'GET',
...(reqOpts.timeout && { timeout: reqOpts.timeout }),
...(typeof reqOpts.gzip === 'boolean' && { compress: reqOpts.gzip }),
};
if (typeof reqOpts.json === 'object') {
// Add Content-type: application/json header
reqOpts.headers = reqOpts.headers || {};
reqOpts.headers['Content-Type'] = 'application/json';
// Set body to JSON representation of value
options.body = JSON.stringify(reqOpts.json);
}
else {
if (Buffer.isBuffer(reqOpts.body)) {
options.body = reqOpts.body;
}
else if (typeof reqOpts.body !== 'string') {
options.body = JSON.stringify(reqOpts.body);
}
else {
options.body = reqOpts.body;
}
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
options.headers = reqOpts.headers;
let uri = (reqOpts.uri ||
reqOpts.url);
if (!uri) {
throw new Error('Missing uri or url in reqOpts.');
}
if (reqOpts.useQuerystring === true || typeof reqOpts.qs === 'object') {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const qs = require('querystring');
const params = qs.stringify(reqOpts.qs);
uri = uri + '?' + params;
}
options.agent = (0, agents_1.getAgent)(uri, reqOpts);
return { uri, options };
}
/**
* Convert a response from `fetch` to `request` format.
* @private
* @param opts The `request` options used to create the request.
* @param res The Fetch response
* @returns A `request` response object
*/
function fetchToRequestResponse(opts, res) {
const request = {};
request.agent = opts.agent || false;
request.headers = (opts.headers || {});
request.href = res.url;
// headers need to be converted from a map to an obj
const resHeaders = {};
res.headers.forEach((value, key) => (resHeaders[key] = value));
const response = Object.assign(res.body, {
statusCode: res.status,
statusMessage: res.statusText,
request,
body: res.body,
headers: resHeaders,
toJSON: () => ({ headers: resHeaders }),
});
return response;
}
/**
* Create POST body from two parts as multipart/related content-type
* @private
* @param boundary
* @param multipart
*/
function createMultipartStream(boundary, multipart) {
const finale = `--${boundary}--`;
const stream = new stream_1.PassThrough();
for (const part of multipart) {
const preamble = `--${boundary}\r\nContent-Type: ${part['Content-Type']}\r\n\r\n`;
stream.write(preamble);
if (typeof part.body === 'string') {
stream.write(part.body);
stream.write('\r\n');
}
else {
part.body.pipe(stream, { end: false });
part.body.on('end', () => {
stream.write('\r\n');
stream.write(finale);
stream.end();
});
}
}
return stream;
}
function teenyRequest(reqOpts, callback) {
const { uri, options } = requestToFetchOptions(reqOpts);
const multipart = reqOpts.multipart;
if (reqOpts.multipart && multipart.length === 2) {
if (!callback) {
// TODO: add support for multipart uploads through streaming
throw new Error('Multipart without callback is not implemented.');
}
const boundary = uuid.v4();
options.headers['Content-Type'] = `multipart/related; boundary=${boundary}`;
options.body = createMultipartStream(boundary, multipart);
// Multipart upload
teenyRequest.stats.requestStarting();
(0, node_fetch_1.default)(uri, options).then(res => {
teenyRequest.stats.requestFinished();
const header = res.headers.get('content-type');
const response = fetchToRequestResponse(options, res);
const body = response.body;
if (header === 'application/json' ||
header === 'application/json; charset=utf-8') {
res.json().then(json => {
response.body = json;
callback(null, response, json);
}, (err) => {
callback(err, response, body);
});
return;
}
res.text().then(text => {
response.body = text;
callback(null, response, text);
}, err => {
callback(err, response, body);
});
}, err => {
teenyRequest.stats.requestFinished();
callback(err, null, null);
});
return;
}
if (callback === undefined) {
// Stream mode
const requestStream = streamEvents(new stream_1.PassThrough());
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let responseStream;
requestStream.once('reading', () => {
if (responseStream) {
(0, stream_1.pipeline)(responseStream, requestStream, () => { });
}
else {
requestStream.once('response', () => {
(0, stream_1.pipeline)(responseStream, requestStream, () => { });
});
}
});
options.compress = false;
teenyRequest.stats.requestStarting();
(0, node_fetch_1.default)(uri, options).then(res => {
teenyRequest.stats.requestFinished();
responseStream = res.body;
responseStream.on('error', (err) => {
requestStream.emit('error', err);
});
const response = fetchToRequestResponse(options, res);
requestStream.emit('response', response);
}, err => {
teenyRequest.stats.requestFinished();
requestStream.emit('error', err);
});
// fetch doesn't supply the raw HTTP stream, instead it
// returns a PassThrough piped from the HTTP response
// stream.
return requestStream;
}
// GET or POST with callback
teenyRequest.stats.requestStarting();
(0, node_fetch_1.default)(uri, options).then(res => {
teenyRequest.stats.requestFinished();
const header = res.headers.get('content-type');
const response = fetchToRequestResponse(options, res);
const body = response.body;
if (header === 'application/json' ||
header === 'application/json; charset=utf-8') {
if (response.statusCode === 204) {
// Probably a DELETE
callback(null, response, body);
return;
}
res.json().then(json => {
response.body = json;
callback(null, response, json);
}, err => {
callback(err, response, body);
});
return;
}
res.text().then(text => {
const response = fetchToRequestResponse(options, res);
response.body = text;
callback(null, response, text);
}, err => {
callback(err, response, body);
});
}, err => {
teenyRequest.stats.requestFinished();
callback(err, null, null);
});
return;
}
exports.teenyRequest = teenyRequest;
teenyRequest.defaults = (defaults) => {
return (reqOpts, callback) => {
const opts = { ...defaults, ...reqOpts };
if (callback === undefined) {
return teenyRequest(opts);
}
teenyRequest(opts, callback);
};
};
/**
* Single instance of an interface for keeping track of things.
*/
teenyRequest.stats = new TeenyStatistics_1.TeenyStatistics();
teenyRequest.resetStats = () => {
teenyRequest.stats = new TeenyStatistics_1.TeenyStatistics(teenyRequest.stats.getOptions());
};
//# sourceMappingURL=index.js.map

1
node_modules/teeny-request/build/src/index.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long