Update checked-in dependencies

This commit is contained in:
github-actions[bot] 2021-07-27 16:54:30 +00:00
parent 35f1961385
commit 17223bdff7
20 changed files with 1756 additions and 646 deletions

203
node_modules/nock/lib/common.js generated vendored
View file

@ -1,9 +1,10 @@
'use strict'
const _ = require('lodash')
const debug = require('debug')('nock.common')
const url = require('url')
const set = require('lodash.set')
const timers = require('timers')
const url = require('url')
const util = require('util')
/**
* Normalizes the request options so that it always has `host` property.
@ -28,7 +29,7 @@ function normalizeRequestOptions(options) {
debug('options.host in the end: %j', options.host)
/// lowercase host names
;['hostname', 'host'].forEach(function(attr) {
;['hostname', 'host'].forEach(function (attr) {
if (options[attr]) {
options[attr] = options[attr].toLowerCase()
}
@ -66,7 +67,7 @@ let requestOverrides = {}
*/
function overrideRequests(newRequest) {
debug('overriding requests')
;['http', 'https'].forEach(function(proto) {
;['http', 'https'].forEach(function (proto) {
debug('- overriding request for', proto)
const moduleName = proto // 1 to 1 match of protocol and module is fortunate :)
@ -90,7 +91,7 @@ function overrideRequests(newRequest) {
get: overriddenGet,
}
// https://nodejs.org/api/http.html#http_http_request_url_options_callback
module.request = function(input, options, callback) {
module.request = function (input, options, callback) {
return newRequest(proto, overriddenRequest.bind(module), [
input,
options,
@ -98,7 +99,7 @@ function overrideRequests(newRequest) {
])
}
// https://nodejs.org/api/http.html#http_http_get_options_callback
module.get = function(input, options, callback) {
module.get = function (input, options, callback) {
const req = newRequest(proto, overriddenGet.bind(module), [
input,
options,
@ -179,7 +180,7 @@ function isContentEncoded(headers) {
function contentEncoding(headers, encoder) {
const contentEncoding = headers['content-encoding']
return contentEncoding === encoder
return contentEncoding !== undefined && contentEncoding.toString() === encoder
}
function isJSONContent(headers) {
@ -194,7 +195,7 @@ function isJSONContent(headers) {
* Duplicates throw an error.
*/
function headersFieldNamesToLowerCase(headers) {
if (!_.isPlainObject(headers)) {
if (!isPlainObject(headers)) {
throw Error('Headers must be provided as an object')
}
@ -243,11 +244,11 @@ function headersInputToRawArray(headers) {
}
// [].concat(...) is used instead of Array.flat until v11 is the minimum Node version
if (_.isMap(headers)) {
if (util.types.isMap(headers)) {
return [].concat(...Array.from(headers, ([k, v]) => [k.toString(), v]))
}
if (_.isPlainObject(headers)) {
if (isPlainObject(headers)) {
return [].concat(...Object.entries(headers))
}
@ -359,7 +360,7 @@ function addHeaderLine(headers, name, value) {
* @fieldName {String} field name - string with the case-insensitive field name
*/
function deleteHeadersField(headers, fieldNameToDelete) {
if (!_.isPlainObject(headers)) {
if (!isPlainObject(headers)) {
throw Error('headers must be an object')
}
@ -406,11 +407,8 @@ function percentDecode(str) {
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
*/
function percentEncode(str) {
return encodeURIComponent(str).replace(/[!'()*]/g, function(c) {
return `%${c
.charCodeAt(0)
.toString(16)
.toUpperCase()}`
return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
return `%${c.charCodeAt(0).toString(16).toUpperCase()}`
})
}
@ -418,9 +416,12 @@ function matchStringOrRegexp(target, pattern) {
const targetStr =
target === undefined || target === null ? '' : String(target)
return pattern instanceof RegExp
? pattern.test(targetStr)
: targetStr === String(pattern)
if (pattern instanceof RegExp) {
// if the regexp happens to have a global flag, we want to ensure we test the entire target
pattern.lastIndex = 0
return pattern.test(targetStr)
}
return targetStr === String(pattern)
}
/**
@ -452,13 +453,13 @@ function formatQueryValue(key, value, stringFormattingFn) {
case value instanceof RegExp:
break
case Array.isArray(value): {
value = value.map(function(val, idx) {
value = value.map(function (val, idx) {
return formatQueryValue(idx, val, stringFormattingFn)[1]
})
break
}
case typeof value === 'object': {
value = Object.entries(value).reduce(function(acc, [subKey, subVal]) {
value = Object.entries(value).reduce(function (acc, [subKey, subVal]) {
const subPair = formatQueryValue(subKey, subVal, stringFormattingFn)
acc[subPair[0]] = subPair[1]
@ -550,8 +551,15 @@ function urlToOptions(url) {
* - The expected data can use regexp to compare values
* - JSON path notation and nested objects are considered equal
*/
const dataEqual = (expected, actual) =>
deepEqual(expand(expected), expand(actual))
const dataEqual = (expected, actual) => {
if (isPlainObject(expected)) {
expected = expand(expected)
}
if (isPlainObject(actual)) {
actual = expand(actual)
}
return deepEqual(expected, actual)
}
/**
* Converts flat objects whose keys use JSON path notation to nested objects.
@ -562,7 +570,7 @@ const dataEqual = (expected, actual) =>
* { 'foo[bar][0]': 'baz' } -> { foo: { bar: [ 'baz' ] } }
*/
const expand = input =>
Object.entries(input).reduce((acc, [k, v]) => _.set(acc, k, v), {})
Object.entries(input).reduce((acc, [k, v]) => set(acc, k, v), {})
/**
* Performs a recursive strict comparison between two values.
@ -575,22 +583,70 @@ function deepEqual(expected, actual) {
return expected.test(actual)
}
if (Array.isArray(expected) || _.isPlainObject(expected)) {
if (actual === undefined) {
if (Array.isArray(expected) && Array.isArray(actual)) {
if (expected.length !== actual.length) {
return false
}
const expKeys = Object.keys(expected)
if (expKeys.length !== Object.keys(actual).length) {
return false
}
return expected.every((expVal, idx) => deepEqual(expVal, actual[idx]))
}
return expKeys.every(key => deepEqual(expected[key], actual[key]))
if (isPlainObject(expected) && isPlainObject(actual)) {
const allKeys = Array.from(
new Set(Object.keys(expected).concat(Object.keys(actual)))
)
return allKeys.every(key => deepEqual(expected[key], actual[key]))
}
return expected === actual
}
/**
* Checks if `value` is a plain object, that is, an object created by the
* `Object` constructor or one with a `[[Prototype]]` of `null`.
* https://github.com/lodash/lodash/blob/588bf3e20db0ae039a822a14a8fa238c5b298e65/isPlainObject.js
*
* @param {*} value The value to check.
* @return {boolean}
*/
function isPlainObject(value) {
const isObjectLike = typeof value === 'object' && value !== null
const tag = Object.prototype.toString.call(value)
if (!isObjectLike || tag !== '[object Object]') {
return false
}
if (Object.getPrototypeOf(value) === null) {
return true
}
let proto = value
while (Object.getPrototypeOf(proto) !== null) {
proto = Object.getPrototypeOf(proto)
}
return Object.getPrototypeOf(value) === proto
}
/**
* Creates an object with the same keys as `object` and values generated
* by running each own enumerable string keyed property of `object` thru
* `iteratee`. (iteration order is not guaranteed)
* The iteratee is invoked with three arguments: (value, key, object).
* https://github.com/lodash/lodash/blob/588bf3e20db0ae039a822a14a8fa238c5b298e65/mapValue.js
*
* @param {Object} object The object to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Object} Returns the new mapped object.
*/
function mapValue(object, iteratee) {
object = Object(object)
const result = {}
Object.keys(object).forEach(key => {
result[key] = iteratee(object[key], key, object)
})
return result
}
const timeouts = []
const intervals = []
const immediates = []
@ -617,29 +673,62 @@ function removeAllTimers() {
clearTimer(clearImmediate, immediates)
}
exports.normalizeClientRequestArgs = normalizeClientRequestArgs
exports.normalizeRequestOptions = normalizeRequestOptions
exports.normalizeOrigin = normalizeOrigin
exports.isUtf8Representable = isUtf8Representable
exports.overrideRequests = overrideRequests
exports.restoreOverriddenRequests = restoreOverriddenRequests
exports.stringifyRequest = stringifyRequest
exports.isContentEncoded = isContentEncoded
exports.contentEncoding = contentEncoding
exports.isJSONContent = isJSONContent
exports.headersFieldNamesToLowerCase = headersFieldNamesToLowerCase
exports.headersFieldsArrayToLowerCase = headersFieldsArrayToLowerCase
exports.headersArrayToObject = headersArrayToObject
exports.headersInputToRawArray = headersInputToRawArray
exports.deleteHeadersField = deleteHeadersField
exports.forEachHeader = forEachHeader
exports.percentEncode = percentEncode
exports.percentDecode = percentDecode
exports.matchStringOrRegexp = matchStringOrRegexp
exports.formatQueryValue = formatQueryValue
exports.isStream = isStream
exports.dataEqual = dataEqual
exports.setTimeout = setTimeout
exports.setInterval = setInterval
exports.setImmediate = setImmediate
exports.removeAllTimers = removeAllTimers
/**
* Check if the Client Request has been cancelled.
*
* Until Node 14 is the minimum, we need to look at both flags to see if the request has been cancelled.
* The two flags have the same purpose, but the Node maintainers are migrating from `abort(ed)` to
* `destroy(ed)` terminology, to be more consistent with `stream.Writable`.
* In Node 14.x+, Calling `abort()` will set both `aborted` and `destroyed` to true, however,
* calling `destroy()` will only set `destroyed` to true.
* Falling back on checking if the socket is destroyed to cover the case of Node <14.x where
* `destroy()` is called, but `destroyed` is undefined.
*
* Node Client Request history:
* - `request.abort()`: Added in: v0.3.8, Deprecated since: v14.1.0, v13.14.0
* - `request.aborted`: Added in: v0.11.14, Became a boolean instead of a timestamp: v11.0.0, Not deprecated (yet)
* - `request.destroy()`: Added in: v0.3.0
* - `request.destroyed`: Added in: v14.1.0, v13.14.0
*
* @param {ClientRequest} req
* @returns {boolean}
*/
function isRequestDestroyed(req) {
return !!(
req.destroyed === true ||
req.aborted ||
(req.socket && req.socket.destroyed)
)
}
module.exports = {
contentEncoding,
dataEqual,
deleteHeadersField,
forEachHeader,
formatQueryValue,
headersArrayToObject,
headersFieldNamesToLowerCase,
headersFieldsArrayToLowerCase,
headersInputToRawArray,
isContentEncoded,
isJSONContent,
isPlainObject,
isRequestDestroyed,
isStream,
isUtf8Representable,
mapValue,
matchStringOrRegexp,
normalizeClientRequestArgs,
normalizeOrigin,
normalizeRequestOptions,
overrideRequests,
percentDecode,
percentEncode,
removeAllTimers,
restoreOverriddenRequests,
setImmediate,
setInterval,
setTimeout,
stringifyRequest,
}