Tracking de l'application VApp (IHM du jeu)
This commit is contained in:
35
VApp/node_modules/readable-stream/lib/ours/browser.js
generated
vendored
Normal file
35
VApp/node_modules/readable-stream/lib/ours/browser.js
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
'use strict'
|
||||
|
||||
const CustomStream = require('../stream')
|
||||
const promises = require('../stream/promises')
|
||||
const originalDestroy = CustomStream.Readable.destroy
|
||||
module.exports = CustomStream.Readable
|
||||
|
||||
// Explicit export naming is needed for ESM
|
||||
module.exports._uint8ArrayToBuffer = CustomStream._uint8ArrayToBuffer
|
||||
module.exports._isUint8Array = CustomStream._isUint8Array
|
||||
module.exports.isDisturbed = CustomStream.isDisturbed
|
||||
module.exports.isErrored = CustomStream.isErrored
|
||||
module.exports.isReadable = CustomStream.isReadable
|
||||
module.exports.Readable = CustomStream.Readable
|
||||
module.exports.Writable = CustomStream.Writable
|
||||
module.exports.Duplex = CustomStream.Duplex
|
||||
module.exports.Transform = CustomStream.Transform
|
||||
module.exports.PassThrough = CustomStream.PassThrough
|
||||
module.exports.addAbortSignal = CustomStream.addAbortSignal
|
||||
module.exports.finished = CustomStream.finished
|
||||
module.exports.destroy = CustomStream.destroy
|
||||
module.exports.destroy = originalDestroy
|
||||
module.exports.pipeline = CustomStream.pipeline
|
||||
module.exports.compose = CustomStream.compose
|
||||
Object.defineProperty(CustomStream, 'promises', {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
return promises
|
||||
}
|
||||
})
|
||||
module.exports.Stream = CustomStream.Stream
|
||||
|
||||
// Allow default importing
|
||||
module.exports.default = module.exports
|
341
VApp/node_modules/readable-stream/lib/ours/errors.js
generated
vendored
Normal file
341
VApp/node_modules/readable-stream/lib/ours/errors.js
generated
vendored
Normal file
@ -0,0 +1,341 @@
|
||||
'use strict'
|
||||
|
||||
const { format, inspect, AggregateError: CustomAggregateError } = require('./util')
|
||||
|
||||
/*
|
||||
This file is a reduced and adapted version of the main lib/internal/errors.js file defined at
|
||||
|
||||
https://github.com/nodejs/node/blob/master/lib/internal/errors.js
|
||||
|
||||
Don't try to replace with the original file and keep it up to date (starting from E(...) definitions)
|
||||
with the upstream file.
|
||||
*/
|
||||
|
||||
const AggregateError = globalThis.AggregateError || CustomAggregateError
|
||||
const kIsNodeError = Symbol('kIsNodeError')
|
||||
const kTypes = [
|
||||
'string',
|
||||
'function',
|
||||
'number',
|
||||
'object',
|
||||
// Accept 'Function' and 'Object' as alternative to the lower cased version.
|
||||
'Function',
|
||||
'Object',
|
||||
'boolean',
|
||||
'bigint',
|
||||
'symbol'
|
||||
]
|
||||
const classRegExp = /^([A-Z][a-z0-9]*)+$/
|
||||
const nodeInternalPrefix = '__node_internal_'
|
||||
const codes = {}
|
||||
function assert(value, message) {
|
||||
if (!value) {
|
||||
throw new codes.ERR_INTERNAL_ASSERTION(message)
|
||||
}
|
||||
}
|
||||
|
||||
// Only use this for integers! Decimal numbers do not work with this function.
|
||||
function addNumericalSeparator(val) {
|
||||
let res = ''
|
||||
let i = val.length
|
||||
const start = val[0] === '-' ? 1 : 0
|
||||
for (; i >= start + 4; i -= 3) {
|
||||
res = `_${val.slice(i - 3, i)}${res}`
|
||||
}
|
||||
return `${val.slice(0, i)}${res}`
|
||||
}
|
||||
function getMessage(key, msg, args) {
|
||||
if (typeof msg === 'function') {
|
||||
assert(
|
||||
msg.length <= args.length,
|
||||
// Default options do not count.
|
||||
`Code: ${key}; The provided arguments length (${args.length}) does not match the required ones (${msg.length}).`
|
||||
)
|
||||
return msg(...args)
|
||||
}
|
||||
const expectedLength = (msg.match(/%[dfijoOs]/g) || []).length
|
||||
assert(
|
||||
expectedLength === args.length,
|
||||
`Code: ${key}; The provided arguments length (${args.length}) does not match the required ones (${expectedLength}).`
|
||||
)
|
||||
if (args.length === 0) {
|
||||
return msg
|
||||
}
|
||||
return format(msg, ...args)
|
||||
}
|
||||
function E(code, message, Base) {
|
||||
if (!Base) {
|
||||
Base = Error
|
||||
}
|
||||
class NodeError extends Base {
|
||||
constructor(...args) {
|
||||
super(getMessage(code, message, args))
|
||||
}
|
||||
toString() {
|
||||
return `${this.name} [${code}]: ${this.message}`
|
||||
}
|
||||
}
|
||||
Object.defineProperties(NodeError.prototype, {
|
||||
name: {
|
||||
value: Base.name,
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
},
|
||||
toString: {
|
||||
value() {
|
||||
return `${this.name} [${code}]: ${this.message}`
|
||||
},
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
}
|
||||
})
|
||||
NodeError.prototype.code = code
|
||||
NodeError.prototype[kIsNodeError] = true
|
||||
codes[code] = NodeError
|
||||
}
|
||||
function hideStackFrames(fn) {
|
||||
// We rename the functions that will be hidden to cut off the stacktrace
|
||||
// at the outermost one
|
||||
const hidden = nodeInternalPrefix + fn.name
|
||||
Object.defineProperty(fn, 'name', {
|
||||
value: hidden
|
||||
})
|
||||
return fn
|
||||
}
|
||||
function aggregateTwoErrors(innerError, outerError) {
|
||||
if (innerError && outerError && innerError !== outerError) {
|
||||
if (Array.isArray(outerError.errors)) {
|
||||
// If `outerError` is already an `AggregateError`.
|
||||
outerError.errors.push(innerError)
|
||||
return outerError
|
||||
}
|
||||
const err = new AggregateError([outerError, innerError], outerError.message)
|
||||
err.code = outerError.code
|
||||
return err
|
||||
}
|
||||
return innerError || outerError
|
||||
}
|
||||
class AbortError extends Error {
|
||||
constructor(message = 'The operation was aborted', options = undefined) {
|
||||
if (options !== undefined && typeof options !== 'object') {
|
||||
throw new codes.ERR_INVALID_ARG_TYPE('options', 'Object', options)
|
||||
}
|
||||
super(message, options)
|
||||
this.code = 'ABORT_ERR'
|
||||
this.name = 'AbortError'
|
||||
}
|
||||
}
|
||||
E('ERR_ASSERTION', '%s', Error)
|
||||
E(
|
||||
'ERR_INVALID_ARG_TYPE',
|
||||
(name, expected, actual) => {
|
||||
assert(typeof name === 'string', "'name' must be a string")
|
||||
if (!Array.isArray(expected)) {
|
||||
expected = [expected]
|
||||
}
|
||||
let msg = 'The '
|
||||
if (name.endsWith(' argument')) {
|
||||
// For cases like 'first argument'
|
||||
msg += `${name} `
|
||||
} else {
|
||||
msg += `"${name}" ${name.includes('.') ? 'property' : 'argument'} `
|
||||
}
|
||||
msg += 'must be '
|
||||
const types = []
|
||||
const instances = []
|
||||
const other = []
|
||||
for (const value of expected) {
|
||||
assert(typeof value === 'string', 'All expected entries have to be of type string')
|
||||
if (kTypes.includes(value)) {
|
||||
types.push(value.toLowerCase())
|
||||
} else if (classRegExp.test(value)) {
|
||||
instances.push(value)
|
||||
} else {
|
||||
assert(value !== 'object', 'The value "object" should be written as "Object"')
|
||||
other.push(value)
|
||||
}
|
||||
}
|
||||
|
||||
// Special handle `object` in case other instances are allowed to outline
|
||||
// the differences between each other.
|
||||
if (instances.length > 0) {
|
||||
const pos = types.indexOf('object')
|
||||
if (pos !== -1) {
|
||||
types.splice(types, pos, 1)
|
||||
instances.push('Object')
|
||||
}
|
||||
}
|
||||
if (types.length > 0) {
|
||||
switch (types.length) {
|
||||
case 1:
|
||||
msg += `of type ${types[0]}`
|
||||
break
|
||||
case 2:
|
||||
msg += `one of type ${types[0]} or ${types[1]}`
|
||||
break
|
||||
default: {
|
||||
const last = types.pop()
|
||||
msg += `one of type ${types.join(', ')}, or ${last}`
|
||||
}
|
||||
}
|
||||
if (instances.length > 0 || other.length > 0) {
|
||||
msg += ' or '
|
||||
}
|
||||
}
|
||||
if (instances.length > 0) {
|
||||
switch (instances.length) {
|
||||
case 1:
|
||||
msg += `an instance of ${instances[0]}`
|
||||
break
|
||||
case 2:
|
||||
msg += `an instance of ${instances[0]} or ${instances[1]}`
|
||||
break
|
||||
default: {
|
||||
const last = instances.pop()
|
||||
msg += `an instance of ${instances.join(', ')}, or ${last}`
|
||||
}
|
||||
}
|
||||
if (other.length > 0) {
|
||||
msg += ' or '
|
||||
}
|
||||
}
|
||||
switch (other.length) {
|
||||
case 0:
|
||||
break
|
||||
case 1:
|
||||
if (other[0].toLowerCase() !== other[0]) {
|
||||
msg += 'an '
|
||||
}
|
||||
msg += `${other[0]}`
|
||||
break
|
||||
case 2:
|
||||
msg += `one of ${other[0]} or ${other[1]}`
|
||||
break
|
||||
default: {
|
||||
const last = other.pop()
|
||||
msg += `one of ${other.join(', ')}, or ${last}`
|
||||
}
|
||||
}
|
||||
if (actual == null) {
|
||||
msg += `. Received ${actual}`
|
||||
} else if (typeof actual === 'function' && actual.name) {
|
||||
msg += `. Received function ${actual.name}`
|
||||
} else if (typeof actual === 'object') {
|
||||
var _actual$constructor
|
||||
if (
|
||||
(_actual$constructor = actual.constructor) !== null &&
|
||||
_actual$constructor !== undefined &&
|
||||
_actual$constructor.name
|
||||
) {
|
||||
msg += `. Received an instance of ${actual.constructor.name}`
|
||||
} else {
|
||||
const inspected = inspect(actual, {
|
||||
depth: -1
|
||||
})
|
||||
msg += `. Received ${inspected}`
|
||||
}
|
||||
} else {
|
||||
let inspected = inspect(actual, {
|
||||
colors: false
|
||||
})
|
||||
if (inspected.length > 25) {
|
||||
inspected = `${inspected.slice(0, 25)}...`
|
||||
}
|
||||
msg += `. Received type ${typeof actual} (${inspected})`
|
||||
}
|
||||
return msg
|
||||
},
|
||||
TypeError
|
||||
)
|
||||
E(
|
||||
'ERR_INVALID_ARG_VALUE',
|
||||
(name, value, reason = 'is invalid') => {
|
||||
let inspected = inspect(value)
|
||||
if (inspected.length > 128) {
|
||||
inspected = inspected.slice(0, 128) + '...'
|
||||
}
|
||||
const type = name.includes('.') ? 'property' : 'argument'
|
||||
return `The ${type} '${name}' ${reason}. Received ${inspected}`
|
||||
},
|
||||
TypeError
|
||||
)
|
||||
E(
|
||||
'ERR_INVALID_RETURN_VALUE',
|
||||
(input, name, value) => {
|
||||
var _value$constructor
|
||||
const type =
|
||||
value !== null &&
|
||||
value !== undefined &&
|
||||
(_value$constructor = value.constructor) !== null &&
|
||||
_value$constructor !== undefined &&
|
||||
_value$constructor.name
|
||||
? `instance of ${value.constructor.name}`
|
||||
: `type ${typeof value}`
|
||||
return `Expected ${input} to be returned from the "${name}"` + ` function but got ${type}.`
|
||||
},
|
||||
TypeError
|
||||
)
|
||||
E(
|
||||
'ERR_MISSING_ARGS',
|
||||
(...args) => {
|
||||
assert(args.length > 0, 'At least one arg needs to be specified')
|
||||
let msg
|
||||
const len = args.length
|
||||
args = (Array.isArray(args) ? args : [args]).map((a) => `"${a}"`).join(' or ')
|
||||
switch (len) {
|
||||
case 1:
|
||||
msg += `The ${args[0]} argument`
|
||||
break
|
||||
case 2:
|
||||
msg += `The ${args[0]} and ${args[1]} arguments`
|
||||
break
|
||||
default:
|
||||
{
|
||||
const last = args.pop()
|
||||
msg += `The ${args.join(', ')}, and ${last} arguments`
|
||||
}
|
||||
break
|
||||
}
|
||||
return `${msg} must be specified`
|
||||
},
|
||||
TypeError
|
||||
)
|
||||
E(
|
||||
'ERR_OUT_OF_RANGE',
|
||||
(str, range, input) => {
|
||||
assert(range, 'Missing "range" argument')
|
||||
let received
|
||||
if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
|
||||
received = addNumericalSeparator(String(input))
|
||||
} else if (typeof input === 'bigint') {
|
||||
received = String(input)
|
||||
if (input > 2n ** 32n || input < -(2n ** 32n)) {
|
||||
received = addNumericalSeparator(received)
|
||||
}
|
||||
received += 'n'
|
||||
} else {
|
||||
received = inspect(input)
|
||||
}
|
||||
return `The value of "${str}" is out of range. It must be ${range}. Received ${received}`
|
||||
},
|
||||
RangeError
|
||||
)
|
||||
E('ERR_MULTIPLE_CALLBACK', 'Callback called multiple times', Error)
|
||||
E('ERR_METHOD_NOT_IMPLEMENTED', 'The %s method is not implemented', Error)
|
||||
E('ERR_STREAM_ALREADY_FINISHED', 'Cannot call %s after a stream was finished', Error)
|
||||
E('ERR_STREAM_CANNOT_PIPE', 'Cannot pipe, not readable', Error)
|
||||
E('ERR_STREAM_DESTROYED', 'Cannot call %s after a stream was destroyed', Error)
|
||||
E('ERR_STREAM_NULL_VALUES', 'May not write null values to stream', TypeError)
|
||||
E('ERR_STREAM_PREMATURE_CLOSE', 'Premature close', Error)
|
||||
E('ERR_STREAM_PUSH_AFTER_EOF', 'stream.push() after EOF', Error)
|
||||
E('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event', Error)
|
||||
E('ERR_STREAM_WRITE_AFTER_END', 'write after end', Error)
|
||||
E('ERR_UNKNOWN_ENCODING', 'Unknown encoding: %s', TypeError)
|
||||
module.exports = {
|
||||
AbortError,
|
||||
aggregateTwoErrors: hideStackFrames(aggregateTwoErrors),
|
||||
hideStackFrames,
|
||||
codes
|
||||
}
|
65
VApp/node_modules/readable-stream/lib/ours/index.js
generated
vendored
Normal file
65
VApp/node_modules/readable-stream/lib/ours/index.js
generated
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
'use strict'
|
||||
|
||||
const Stream = require('stream')
|
||||
if (Stream && process.env.READABLE_STREAM === 'disable') {
|
||||
const promises = Stream.promises
|
||||
|
||||
// Explicit export naming is needed for ESM
|
||||
module.exports._uint8ArrayToBuffer = Stream._uint8ArrayToBuffer
|
||||
module.exports._isUint8Array = Stream._isUint8Array
|
||||
module.exports.isDisturbed = Stream.isDisturbed
|
||||
module.exports.isErrored = Stream.isErrored
|
||||
module.exports.isReadable = Stream.isReadable
|
||||
module.exports.Readable = Stream.Readable
|
||||
module.exports.Writable = Stream.Writable
|
||||
module.exports.Duplex = Stream.Duplex
|
||||
module.exports.Transform = Stream.Transform
|
||||
module.exports.PassThrough = Stream.PassThrough
|
||||
module.exports.addAbortSignal = Stream.addAbortSignal
|
||||
module.exports.finished = Stream.finished
|
||||
module.exports.destroy = Stream.destroy
|
||||
module.exports.pipeline = Stream.pipeline
|
||||
module.exports.compose = Stream.compose
|
||||
Object.defineProperty(Stream, 'promises', {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
return promises
|
||||
}
|
||||
})
|
||||
module.exports.Stream = Stream.Stream
|
||||
} else {
|
||||
const CustomStream = require('../stream')
|
||||
const promises = require('../stream/promises')
|
||||
const originalDestroy = CustomStream.Readable.destroy
|
||||
module.exports = CustomStream.Readable
|
||||
|
||||
// Explicit export naming is needed for ESM
|
||||
module.exports._uint8ArrayToBuffer = CustomStream._uint8ArrayToBuffer
|
||||
module.exports._isUint8Array = CustomStream._isUint8Array
|
||||
module.exports.isDisturbed = CustomStream.isDisturbed
|
||||
module.exports.isErrored = CustomStream.isErrored
|
||||
module.exports.isReadable = CustomStream.isReadable
|
||||
module.exports.Readable = CustomStream.Readable
|
||||
module.exports.Writable = CustomStream.Writable
|
||||
module.exports.Duplex = CustomStream.Duplex
|
||||
module.exports.Transform = CustomStream.Transform
|
||||
module.exports.PassThrough = CustomStream.PassThrough
|
||||
module.exports.addAbortSignal = CustomStream.addAbortSignal
|
||||
module.exports.finished = CustomStream.finished
|
||||
module.exports.destroy = CustomStream.destroy
|
||||
module.exports.destroy = originalDestroy
|
||||
module.exports.pipeline = CustomStream.pipeline
|
||||
module.exports.compose = CustomStream.compose
|
||||
Object.defineProperty(CustomStream, 'promises', {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
return promises
|
||||
}
|
||||
})
|
||||
module.exports.Stream = CustomStream.Stream
|
||||
}
|
||||
|
||||
// Allow default importing
|
||||
module.exports.default = module.exports
|
107
VApp/node_modules/readable-stream/lib/ours/primordials.js
generated
vendored
Normal file
107
VApp/node_modules/readable-stream/lib/ours/primordials.js
generated
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
'use strict'
|
||||
|
||||
/*
|
||||
This file is a reduced and adapted version of the main lib/internal/per_context/primordials.js file defined at
|
||||
|
||||
https://github.com/nodejs/node/blob/master/lib/internal/per_context/primordials.js
|
||||
|
||||
Don't try to replace with the original file and keep it up to date with the upstream file.
|
||||
*/
|
||||
module.exports = {
|
||||
ArrayIsArray(self) {
|
||||
return Array.isArray(self)
|
||||
},
|
||||
ArrayPrototypeIncludes(self, el) {
|
||||
return self.includes(el)
|
||||
},
|
||||
ArrayPrototypeIndexOf(self, el) {
|
||||
return self.indexOf(el)
|
||||
},
|
||||
ArrayPrototypeJoin(self, sep) {
|
||||
return self.join(sep)
|
||||
},
|
||||
ArrayPrototypeMap(self, fn) {
|
||||
return self.map(fn)
|
||||
},
|
||||
ArrayPrototypePop(self, el) {
|
||||
return self.pop(el)
|
||||
},
|
||||
ArrayPrototypePush(self, el) {
|
||||
return self.push(el)
|
||||
},
|
||||
ArrayPrototypeSlice(self, start, end) {
|
||||
return self.slice(start, end)
|
||||
},
|
||||
Error,
|
||||
FunctionPrototypeCall(fn, thisArgs, ...args) {
|
||||
return fn.call(thisArgs, ...args)
|
||||
},
|
||||
FunctionPrototypeSymbolHasInstance(self, instance) {
|
||||
return Function.prototype[Symbol.hasInstance].call(self, instance)
|
||||
},
|
||||
MathFloor: Math.floor,
|
||||
Number,
|
||||
NumberIsInteger: Number.isInteger,
|
||||
NumberIsNaN: Number.isNaN,
|
||||
NumberMAX_SAFE_INTEGER: Number.MAX_SAFE_INTEGER,
|
||||
NumberMIN_SAFE_INTEGER: Number.MIN_SAFE_INTEGER,
|
||||
NumberParseInt: Number.parseInt,
|
||||
ObjectDefineProperties(self, props) {
|
||||
return Object.defineProperties(self, props)
|
||||
},
|
||||
ObjectDefineProperty(self, name, prop) {
|
||||
return Object.defineProperty(self, name, prop)
|
||||
},
|
||||
ObjectGetOwnPropertyDescriptor(self, name) {
|
||||
return Object.getOwnPropertyDescriptor(self, name)
|
||||
},
|
||||
ObjectKeys(obj) {
|
||||
return Object.keys(obj)
|
||||
},
|
||||
ObjectSetPrototypeOf(target, proto) {
|
||||
return Object.setPrototypeOf(target, proto)
|
||||
},
|
||||
Promise,
|
||||
PromisePrototypeCatch(self, fn) {
|
||||
return self.catch(fn)
|
||||
},
|
||||
PromisePrototypeThen(self, thenFn, catchFn) {
|
||||
return self.then(thenFn, catchFn)
|
||||
},
|
||||
PromiseReject(err) {
|
||||
return Promise.reject(err)
|
||||
},
|
||||
PromiseResolve(val) {
|
||||
return Promise.resolve(val)
|
||||
},
|
||||
ReflectApply: Reflect.apply,
|
||||
RegExpPrototypeTest(self, value) {
|
||||
return self.test(value)
|
||||
},
|
||||
SafeSet: Set,
|
||||
String,
|
||||
StringPrototypeSlice(self, start, end) {
|
||||
return self.slice(start, end)
|
||||
},
|
||||
StringPrototypeToLowerCase(self) {
|
||||
return self.toLowerCase()
|
||||
},
|
||||
StringPrototypeToUpperCase(self) {
|
||||
return self.toUpperCase()
|
||||
},
|
||||
StringPrototypeTrim(self) {
|
||||
return self.trim()
|
||||
},
|
||||
Symbol,
|
||||
SymbolFor: Symbol.for,
|
||||
SymbolAsyncIterator: Symbol.asyncIterator,
|
||||
SymbolHasInstance: Symbol.hasInstance,
|
||||
SymbolIterator: Symbol.iterator,
|
||||
SymbolDispose: Symbol.dispose || Symbol('Symbol.dispose'),
|
||||
SymbolAsyncDispose: Symbol.asyncDispose || Symbol('Symbol.asyncDispose'),
|
||||
TypedArrayPrototypeSet(self, buf, len) {
|
||||
return self.set(buf, len)
|
||||
},
|
||||
Boolean: Boolean,
|
||||
Uint8Array
|
||||
}
|
200
VApp/node_modules/readable-stream/lib/ours/util.js
generated
vendored
Normal file
200
VApp/node_modules/readable-stream/lib/ours/util.js
generated
vendored
Normal file
@ -0,0 +1,200 @@
|
||||
'use strict'
|
||||
|
||||
const bufferModule = require('buffer')
|
||||
const { kResistStopPropagation, SymbolDispose } = require('./primordials')
|
||||
const AbortSignal = globalThis.AbortSignal || require('abort-controller').AbortSignal
|
||||
const AbortController = globalThis.AbortController || require('abort-controller').AbortController
|
||||
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor
|
||||
const Blob = globalThis.Blob || bufferModule.Blob
|
||||
/* eslint-disable indent */
|
||||
const isBlob =
|
||||
typeof Blob !== 'undefined'
|
||||
? function isBlob(b) {
|
||||
// eslint-disable-next-line indent
|
||||
return b instanceof Blob
|
||||
}
|
||||
: function isBlob(b) {
|
||||
return false
|
||||
}
|
||||
/* eslint-enable indent */
|
||||
|
||||
const validateAbortSignal = (signal, name) => {
|
||||
if (signal !== undefined && (signal === null || typeof signal !== 'object' || !('aborted' in signal))) {
|
||||
throw new ERR_INVALID_ARG_TYPE(name, 'AbortSignal', signal)
|
||||
}
|
||||
}
|
||||
const validateFunction = (value, name) => {
|
||||
if (typeof value !== 'function') throw new ERR_INVALID_ARG_TYPE(name, 'Function', value)
|
||||
}
|
||||
|
||||
// This is a simplified version of AggregateError
|
||||
class AggregateError extends Error {
|
||||
constructor(errors) {
|
||||
if (!Array.isArray(errors)) {
|
||||
throw new TypeError(`Expected input to be an Array, got ${typeof errors}`)
|
||||
}
|
||||
let message = ''
|
||||
for (let i = 0; i < errors.length; i++) {
|
||||
message += ` ${errors[i].stack}\n`
|
||||
}
|
||||
super(message)
|
||||
this.name = 'AggregateError'
|
||||
this.errors = errors
|
||||
}
|
||||
}
|
||||
module.exports = {
|
||||
AggregateError,
|
||||
kEmptyObject: Object.freeze({}),
|
||||
once(callback) {
|
||||
let called = false
|
||||
return function (...args) {
|
||||
if (called) {
|
||||
return
|
||||
}
|
||||
called = true
|
||||
callback.apply(this, args)
|
||||
}
|
||||
},
|
||||
createDeferredPromise: function () {
|
||||
let resolve
|
||||
let reject
|
||||
|
||||
// eslint-disable-next-line promise/param-names
|
||||
const promise = new Promise((res, rej) => {
|
||||
resolve = res
|
||||
reject = rej
|
||||
})
|
||||
return {
|
||||
promise,
|
||||
resolve,
|
||||
reject
|
||||
}
|
||||
},
|
||||
promisify(fn) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fn((err, ...args) => {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
return resolve(...args)
|
||||
})
|
||||
})
|
||||
},
|
||||
debuglog() {
|
||||
return function () {}
|
||||
},
|
||||
format(format, ...args) {
|
||||
// Simplified version of https://nodejs.org/api/util.html#utilformatformat-args
|
||||
return format.replace(/%([sdifj])/g, function (...[_unused, type]) {
|
||||
const replacement = args.shift()
|
||||
if (type === 'f') {
|
||||
return replacement.toFixed(6)
|
||||
} else if (type === 'j') {
|
||||
return JSON.stringify(replacement)
|
||||
} else if (type === 's' && typeof replacement === 'object') {
|
||||
const ctor = replacement.constructor !== Object ? replacement.constructor.name : ''
|
||||
return `${ctor} {}`.trim()
|
||||
} else {
|
||||
return replacement.toString()
|
||||
}
|
||||
})
|
||||
},
|
||||
inspect(value) {
|
||||
// Vastly simplified version of https://nodejs.org/api/util.html#utilinspectobject-options
|
||||
switch (typeof value) {
|
||||
case 'string':
|
||||
if (value.includes("'")) {
|
||||
if (!value.includes('"')) {
|
||||
return `"${value}"`
|
||||
} else if (!value.includes('`') && !value.includes('${')) {
|
||||
return `\`${value}\``
|
||||
}
|
||||
}
|
||||
return `'${value}'`
|
||||
case 'number':
|
||||
if (isNaN(value)) {
|
||||
return 'NaN'
|
||||
} else if (Object.is(value, -0)) {
|
||||
return String(value)
|
||||
}
|
||||
return value
|
||||
case 'bigint':
|
||||
return `${String(value)}n`
|
||||
case 'boolean':
|
||||
case 'undefined':
|
||||
return String(value)
|
||||
case 'object':
|
||||
return '{}'
|
||||
}
|
||||
},
|
||||
types: {
|
||||
isAsyncFunction(fn) {
|
||||
return fn instanceof AsyncFunction
|
||||
},
|
||||
isArrayBufferView(arr) {
|
||||
return ArrayBuffer.isView(arr)
|
||||
}
|
||||
},
|
||||
isBlob,
|
||||
deprecate(fn, message) {
|
||||
return fn
|
||||
},
|
||||
addAbortListener:
|
||||
require('events').addAbortListener ||
|
||||
function addAbortListener(signal, listener) {
|
||||
if (signal === undefined) {
|
||||
throw new ERR_INVALID_ARG_TYPE('signal', 'AbortSignal', signal)
|
||||
}
|
||||
validateAbortSignal(signal, 'signal')
|
||||
validateFunction(listener, 'listener')
|
||||
let removeEventListener
|
||||
if (signal.aborted) {
|
||||
queueMicrotask(() => listener())
|
||||
} else {
|
||||
signal.addEventListener('abort', listener, {
|
||||
__proto__: null,
|
||||
once: true,
|
||||
[kResistStopPropagation]: true
|
||||
})
|
||||
removeEventListener = () => {
|
||||
signal.removeEventListener('abort', listener)
|
||||
}
|
||||
}
|
||||
return {
|
||||
__proto__: null,
|
||||
[SymbolDispose]() {
|
||||
var _removeEventListener
|
||||
;(_removeEventListener = removeEventListener) === null || _removeEventListener === undefined
|
||||
? undefined
|
||||
: _removeEventListener()
|
||||
}
|
||||
}
|
||||
},
|
||||
AbortSignalAny:
|
||||
AbortSignal.any ||
|
||||
function AbortSignalAny(signals) {
|
||||
// Fast path if there is only one signal.
|
||||
if (signals.length === 1) {
|
||||
return signals[0]
|
||||
}
|
||||
const ac = new AbortController()
|
||||
const abort = () => ac.abort()
|
||||
signals.forEach((signal) => {
|
||||
validateAbortSignal(signal, 'signals')
|
||||
signal.addEventListener('abort', abort, {
|
||||
once: true
|
||||
})
|
||||
})
|
||||
ac.signal.addEventListener(
|
||||
'abort',
|
||||
() => {
|
||||
signals.forEach((signal) => signal.removeEventListener('abort', abort))
|
||||
},
|
||||
{
|
||||
once: true
|
||||
}
|
||||
)
|
||||
return ac.signal
|
||||
}
|
||||
}
|
||||
module.exports.promisify.custom = Symbol.for('nodejs.util.promisify.custom')
|
Reference in New Issue
Block a user