@jspm/core
Version:
This package contains the core libraries used in jspm 2.
1,487 lines (1,412 loc) • 213 kB
JavaScript
import { d as dew$p } from './chunk-DtuTasat.js';
import exports$q from './events.js';
import { p as process } from './chunk-DEMDiNwt.js';
import { e as exports$r } from './chunk-CcCWfKp1.js';
import { promisify } from './util.js';
import './chunk-DtcTpLWz.js';
import './chunk-CkFCi-G1.js';
var exports$p = {},
_dewExec$o = false;
function dew$o() {
if (_dewExec$o) return exports$p;
_dewExec$o = true;
/*
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.
*/
exports$p = {
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
};
return exports$p;
}
var exports$o = {},
_dewExec$n = false;
function dew$n() {
if (_dewExec$n) return exports$o;
_dewExec$n = true;
/*eslint-disable @mysticatea/prettier */
const {
AbortController,
AbortSignal
} = typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : /* otherwise */undefined;
/*eslint-enable @mysticatea/prettier */
exports$o = AbortController;
exports$o.AbortSignal = AbortSignal;
exports$o.default = AbortController;
return exports$o;
}
var exports$n = {},
_dewExec$m = false;
function dew$m() {
if (_dewExec$m) return exports$n;
_dewExec$m = true;
const bufferModule = dew$p();
const {
kResistStopPropagation,
SymbolDispose
} = dew$o();
const AbortSignal = globalThis.AbortSignal || dew$n().AbortSignal;
const AbortController = globalThis.AbortController || dew$n().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;
}
}
exports$n = {
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: exports$q.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;
}
};
exports$n.promisify.custom = Symbol.for("nodejs.util.promisify.custom");
return exports$n;
}
var exports$m = {},
_dewExec$l = false;
function dew$l() {
if (_dewExec$l) return exports$m;
_dewExec$l = true;
const {
format,
inspect,
AggregateError: CustomAggregateError
} = dew$m();
/*
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);
exports$m = {
AbortError,
aggregateTwoErrors: hideStackFrames(aggregateTwoErrors),
hideStackFrames,
codes
};
return exports$m;
}
var exports$l = {},
_dewExec$k = false;
function dew$k() {
if (_dewExec$k) return exports$l;
_dewExec$k = true;
const {
ArrayIsArray,
ArrayPrototypeIncludes,
ArrayPrototypeJoin,
ArrayPrototypeMap,
NumberIsInteger,
NumberIsNaN,
NumberMAX_SAFE_INTEGER,
NumberMIN_SAFE_INTEGER,
NumberParseInt,
ObjectPrototypeHasOwnProperty,
RegExpPrototypeExec,
String,
StringPrototypeToUpperCase,
StringPrototypeTrim
} = dew$o();
const {
hideStackFrames,
codes: {
ERR_SOCKET_BAD_PORT,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_OUT_OF_RANGE,
ERR_UNKNOWN_SIGNAL
}
} = dew$l();
const {
normalizeEncoding
} = dew$m();
const {
isAsyncFunction,
isArrayBufferView
} = dew$m().types;
const signals = {};
/**
* @param {*} value
* @returns {boolean}
*/
function isInt32(value) {
return value === (value | 0);
}
/**
* @param {*} value
* @returns {boolean}
*/
function isUint32(value) {
return value === value >>> 0;
}
const octalReg = /^[0-7]+$/;
const modeDesc = "must be a 32-bit unsigned integer or an octal string";
/**
* Parse and validate values that will be converted into mode_t (the S_*
* constants). Only valid numbers and octal strings are allowed. They could be
* converted to 32-bit unsigned integers or non-negative signed integers in the
* C++ land, but any value higher than 0o777 will result in platform-specific
* behaviors.
* @param {*} value Values to be validated
* @param {string} name Name of the argument
* @param {number} [def] If specified, will be returned for invalid values
* @returns {number}
*/
function parseFileMode(value, name, def) {
if (typeof value === "undefined") {
value = def;
}
if (typeof value === "string") {
if (RegExpPrototypeExec(octalReg, value) === null) {
throw new ERR_INVALID_ARG_VALUE(name, value, modeDesc);
}
value = NumberParseInt(value, 8);
}
validateUint32(value, name);
return value;
}
/**
* @callback validateInteger
* @param {*} value
* @param {string} name
* @param {number} [min]
* @param {number} [max]
* @returns {asserts value is number}
*/
/** @type {validateInteger} */
const validateInteger = hideStackFrames((value, name, min = NumberMIN_SAFE_INTEGER, max = NumberMAX_SAFE_INTEGER) => {
if (typeof value !== "number") throw new ERR_INVALID_ARG_TYPE(name, "number", value);
if (!NumberIsInteger(value)) throw new ERR_OUT_OF_RANGE(name, "an integer", value);
if (value < min || value > max) throw new ERR_OUT_OF_RANGE(name, `>= ${min} && <= ${max}`, value);
});
/**
* @callback validateInt32
* @param {*} value
* @param {string} name
* @param {number} [min]
* @param {number} [max]
* @returns {asserts value is number}
*/
/** @type {validateInt32} */
const validateInt32 = hideStackFrames((value, name, min = -2147483648, max = 2147483647) => {
// The defaults for min and max correspond to the limits of 32-bit integers.
if (typeof value !== "number") {
throw new ERR_INVALID_ARG_TYPE(name, "number", value);
}
if (!NumberIsInteger(value)) {
throw new ERR_OUT_OF_RANGE(name, "an integer", value);
}
if (value < min || value > max) {
throw new ERR_OUT_OF_RANGE(name, `>= ${min} && <= ${max}`, value);
}
});
/**
* @callback validateUint32
* @param {*} value
* @param {string} name
* @param {number|boolean} [positive=false]
* @returns {asserts value is number}
*/
/** @type {validateUint32} */
const validateUint32 = hideStackFrames((value, name, positive = false) => {
if (typeof value !== "number") {
throw new ERR_INVALID_ARG_TYPE(name, "number", value);
}
if (!NumberIsInteger(value)) {
throw new ERR_OUT_OF_RANGE(name, "an integer", value);
}
const min = positive ? 1 : 0;
// 2 ** 32 === 4294967296
const max = 4294967295;
if (value < min || value > max) {
throw new ERR_OUT_OF_RANGE(name, `>= ${min} && <= ${max}`, value);
}
});
/**
* @callback validateString
* @param {*} value
* @param {string} name
* @returns {asserts value is string}
*/
/** @type {validateString} */
function validateString(value, name) {
if (typeof value !== "string") throw new ERR_INVALID_ARG_TYPE(name, "string", value);
}
/**
* @callback validateNumber
* @param {*} value
* @param {string} name
* @param {number} [min]
* @param {number} [max]
* @returns {asserts value is number}
*/
/** @type {validateNumber} */
function validateNumber(value, name, min = undefined, max) {
if (typeof value !== "number") throw new ERR_INVALID_ARG_TYPE(name, "number", value);
if (min != null && value < min || max != null && value > max || (min != null || max != null) && NumberIsNaN(value)) {
throw new ERR_OUT_OF_RANGE(name, `${min != null ? `>= ${min}` : ""}${min != null && max != null ? " && " : ""}${max != null ? `<= ${max}` : ""}`, value);
}
}
/**
* @callback validateOneOf
* @template T
* @param {T} value
* @param {string} name
* @param {T[]} oneOf
*/
/** @type {validateOneOf} */
const validateOneOf = hideStackFrames((value, name, oneOf) => {
if (!ArrayPrototypeIncludes(oneOf, value)) {
const allowed = ArrayPrototypeJoin(ArrayPrototypeMap(oneOf, v => typeof v === "string" ? `'${v}'` : String(v)), ", ");
const reason = "must be one of: " + allowed;
throw new ERR_INVALID_ARG_VALUE(name, value, reason);
}
});
/**
* @callback validateBoolean
* @param {*} value
* @param {string} name
* @returns {asserts value is boolean}
*/
/** @type {validateBoolean} */
function validateBoolean(value, name) {
if (typeof value !== "boolean") throw new ERR_INVALID_ARG_TYPE(name, "boolean", value);
}
/**
* @param {any} options
* @param {string} key
* @param {boolean} defaultValue
* @returns {boolean}
*/
function getOwnPropertyValueOrDefault(options, key, defaultValue) {
return options == null || !ObjectPrototypeHasOwnProperty(options, key) ? defaultValue : options[key];
}
/**
* @callback validateObject
* @param {*} value
* @param {string} name
* @param {{
* allowArray?: boolean,
* allowFunction?: boolean,
* nullable?: boolean
* }} [options]
*/
/** @type {validateObject} */
const validateObject = hideStackFrames((value, name, options = null) => {
const allowArray = getOwnPropertyValueOrDefault(options, "allowArray", false);
const allowFunction = getOwnPropertyValueOrDefault(options, "allowFunction", false);
const nullable = getOwnPropertyValueOrDefault(options, "nullable", false);
if (!nullable && value === null || !allowArray && ArrayIsArray(value) || typeof value !== "object" && (!allowFunction || typeof value !== "function")) {
throw new ERR_INVALID_ARG_TYPE(name, "Object", value);
}
});
/**
* @callback validateDictionary - We are using the Web IDL Standard definition
* of "dictionary" here, which means any value
* whose Type is either Undefined, Null, or
* Object (which includes functions).
* @param {*} value
* @param {string} name
* @see https://webidl.spec.whatwg.org/#es-dictionary
* @see https://tc39.es/ecma262/#table-typeof-operator-results
*/
/** @type {validateDictionary} */
const validateDictionary = hideStackFrames((value, name) => {
if (value != null && typeof value !== "object" && typeof value !== "function") {
throw new ERR_INVALID_ARG_TYPE(name, "a dictionary", value);
}
});
/**
* @callback validateArray
* @param {*} value
* @param {string} name
* @param {number} [minLength]
* @returns {asserts value is any[]}
*/
/** @type {validateArray} */
const validateArray = hideStackFrames((value, name, minLength = 0) => {
if (!ArrayIsArray(value)) {
throw new ERR_INVALID_ARG_TYPE(name, "Array", value);
}
if (value.length < minLength) {
const reason = `must be longer than ${minLength}`;
throw new ERR_INVALID_ARG_VALUE(name, value, reason);
}
});
/**
* @callback validateStringArray
* @param {*} value
* @param {string} name
* @returns {asserts value is string[]}
*/
/** @type {validateStringArray} */
function validateStringArray(value, name) {
validateArray(value, name);
for (let i = 0; i < value.length; i++) {
validateString(value[i], `${name}[${i}]`);
}
}
/**
* @callback validateBooleanArray
* @param {*} value
* @param {string} name
* @returns {asserts value is boolean[]}
*/
/** @type {validateBooleanArray} */
function validateBooleanArray(value, name) {
validateArray(value, name);
for (let i = 0; i < value.length; i++) {
validateBoolean(value[i], `${name}[${i}]`);
}
}
/**
* @callback validateAbortSignalArray
* @param {*} value
* @param {string} name
* @returns {asserts value is AbortSignal[]}
*/
/** @type {validateAbortSignalArray} */
function validateAbortSignalArray(value, name) {
validateArray(value, name);
for (let i = 0; i < value.length; i++) {
const signal = value[i];
const indexedName = `${name}[${i}]`;
if (signal == null) {
throw new ERR_INVALID_ARG_TYPE(indexedName, "AbortSignal", signal);
}
validateAbortSignal(signal, indexedName);
}
}
/**
* @param {*} signal
* @param {string} [name='signal']
* @returns {asserts signal is keyof signals}
*/
function validateSignalName(signal, name = "signal") {
validateString(signal, name);
if (signals[signal] === undefined) {
if (signals[StringPrototypeToUpperCase(signal)] !== undefined) {
throw new ERR_UNKNOWN_SIGNAL(signal + " (signals must use all capital letters)");
}
throw new ERR_UNKNOWN_SIGNAL(signal);
}
}
/**
* @callback validateBuffer
* @param {*} buffer
* @param {string} [name='buffer']
* @returns {asserts buffer is ArrayBufferView}
*/
/** @type {validateBuffer} */
const validateBuffer = hideStackFrames((buffer, name = "buffer") => {
if (!isArrayBufferView(buffer)) {
throw new ERR_INVALID_ARG_TYPE(name, ["Buffer", "TypedArray", "DataView"], buffer);
}
});
/**
* @param {string} data
* @param {string} encoding
*/
function validateEncoding(data, encoding) {
const normalizedEncoding = normalizeEncoding(encoding);
const length = data.length;
if (normalizedEncoding === "hex" && length % 2 !== 0) {
throw new ERR_INVALID_ARG_VALUE("encoding", encoding, `is invalid for data of length ${length}`);
}
}
/**
* Check that the port number is not NaN when coerced to a number,
* is an integer and that it falls within the legal range of port numbers.
* @param {*} port
* @param {string} [name='Port']
* @param {boolean} [allowZero=true]
* @returns {number}
*/
function validatePort(port, name = "Port", allowZero = true) {
if (typeof port !== "number" && typeof port !== "string" || typeof port === "string" && StringPrototypeTrim(port).length === 0 || +port !== +port >>> 0 || port > 65535 || port === 0 && !allowZero) {
throw new ERR_SOCKET_BAD_PORT(name, port, allowZero);
}
return port | 0;
}
/**
* @callback validateAbortSignal
* @param {*} signal
* @param {string} name
*/
/** @type {validateAbortSignal} */
const validateAbortSignal = hideStackFrames((signal, name) => {
if (signal !== undefined && (signal === null || typeof signal !== "object" || !("aborted" in signal))) {
throw new ERR_INVALID_ARG_TYPE(name, "AbortSignal", signal);
}
});
/**
* @callback validateFunction
* @param {*} value
* @param {string} name
* @returns {asserts value is Function}
*/
/** @type {validateFunction} */
const validateFunction = hideStackFrames((value, name) => {
if (typeof value !== "function") throw new ERR_INVALID_ARG_TYPE(name, "Function", value);
});
/**
* @callback validatePlainFunction
* @param {*} value
* @param {string} name
* @returns {asserts value is Function}
*/
/** @type {validatePlainFunction} */
const validatePlainFunction = hideStackFrames((value, name) => {
if (typeof value !== "function" || isAsyncFunction(value)) throw new ERR_INVALID_ARG_TYPE(name, "Function", value);
});
/**
* @callback validateUndefined
* @param {*} value
* @param {string} name
* @returns {asserts value is undefined}
*/
/** @type {validateUndefined} */
const validateUndefined = hideStackFrames((value, name) => {
if (value !== undefined) throw new ERR_INVALID_ARG_TYPE(name, "undefined", value);
});
/**
* @template T
* @param {T} value
* @param {string} name
* @param {T[]} union
*/
function validateUnion(value, name, union) {
if (!ArrayPrototypeIncludes(union, value)) {
throw new ERR_INVALID_ARG_TYPE(name, `('${ArrayPrototypeJoin(union, "|")}')`, value);
}
}
/*
The rules for the Link header field are described here:
https://www.rfc-editor.org/rfc/rfc8288.html#section-3
This regex validates any string surrounded by angle brackets
(not necessarily a valid URI reference) followed by zero or more
link-params separated by semicolons.
*/
const linkValueRegExp = /^(?:<[^>]*>)(?:\s*;\s*[^;"\s]+(?:=(")?[^;"\s]*\1)?)*$/;
/**
* @param {any} value
* @param {string} name
*/
function validateLinkHeaderFormat(value, name) {
if (typeof value === "undefined" || !RegExpPrototypeExec(linkValueRegExp, value)) {
throw new ERR_INVALID_ARG_VALUE(name, value, "must be an array or string of format \"</styles.css>; rel=preload; as=style\"");
}
}
/**
* @param {any} hints
* @return {string}
*/
function validateLinkHeaderValue(hints) {
if (typeof hints === "string") {
validateLinkHeaderFormat(hints, "hints");
return hints;
} else if (ArrayIsArray(hints)) {
const hintsLength = hints.length;
let result = "";
if (hintsLength === 0) {
return result;
}
for (let i = 0; i < hintsLength; i++) {
const link = hints[i];
validateLinkHeaderFormat(link, "hints");
result += link;
if (i !== hintsLength - 1) {
result += ", ";
}
}
return result;
}
throw new ERR_INVALID_ARG_VALUE("hints", hints, "must be an array or string of format \"</styles.css>; rel=preload; as=style\"");
}
exports$l = {
isInt32,
isUint32,
parseFileMode,
validateArray,
validateStringArray,
validateBooleanArray,
validateAbortSignalArray,
validateBoolean,
validateBuffer,
validateDictionary,
validateEncoding,
validateFunction,
validateInt32,
validateInteger,
validateNumber,
validateObject,
validateOneOf,
validatePlainFunction,
validatePort,
validateSignalName,
validateString,
validateUint32,
validateUndefined,
validateUnion,
validateAbortSignal,
validateLinkHeaderValue
};
return exports$l;
}
var exports$k = {},
_dewExec$j = false;
function dew$j() {
if (_dewExec$j) return exports$k;
_dewExec$j = true;
const {
SymbolAsyncIterator,
SymbolIterator,
SymbolFor
} = dew$o();
// We need to use SymbolFor to make these globally available
// for interopt with readable-stream, i.e. readable-stream
// and node core needs to be able to read/write private state
// from each other for proper interoperability.
const kIsDestroyed = SymbolFor("nodejs.stream.destroyed");
const kIsErrored = SymbolFor("nodejs.stream.errored");
const kIsReadable = SymbolFor("nodejs.stream.readable");
const kIsWritable = SymbolFor("nodejs.stream.writable");
const kIsDisturbed = SymbolFor("nodejs.stream.disturbed");
const kIsClosedPromise = SymbolFor("nodejs.webstream.isClosedPromise");
const kControllerErrorFunction = SymbolFor("nodejs.webstream.controllerErrorFunction");
function isReadableNodeStream(obj, strict = false) {
var _obj$_readableState;
return !!(obj && typeof obj.pipe === "function" && typeof obj.on === "function" && (!strict || typeof obj.pause === "function" && typeof obj.resume === "function") && (!obj._writableState || ((_obj$_readableState = obj._readableState) === null || _obj$_readableState === undefined ? undefined : _obj$_readableState.readable) !== false) && (
// Duplex
!obj._writableState || obj._readableState)
// Writable has .pipe.
);
}
function isWritableNodeStream(obj) {
var _obj$_writableState;
return !!(obj && typeof obj.write === "function" && typeof obj.on === "function" && (!obj._readableState || ((_obj$_writableState = obj._writableState) === null || _obj$_writableState === undefined ? undefined : _obj$_writableState.writable) !== false)
// Duplex
);
}
function isDuplexNodeStream(obj) {
return !!(obj && typeof obj.pipe === "function" && obj._readableState && typeof obj.on === "function" && typeof obj.write === "function");
}
function isNodeStream(obj) {
return obj && (obj._readableState || obj._writableState || typeof obj.write === "function" && typeof obj.on === "function" || typeof obj.pipe === "function" && typeof obj.on === "function");
}
function isReadableStream(obj) {
return !!(obj && !isNodeStream(obj) && typeof obj.pipeThrough === "function" && typeof obj.getReader === "function" && typeof obj.cancel === "function");
}
function isWritableStream(obj) {
return !!(obj && !isNodeStream(obj) && typeof obj.getWriter === "function" && typeof obj.abort === "function");
}
function isTransformStream(obj) {
return !!(obj && !isNodeStream(obj) && typeof obj.readable === "object" && typeof obj.writable === "object");
}
function isWebStream(obj) {
return isReadableStream(obj) || isWritableStream(obj) || isTransformStream(obj);
}
function isIterable(obj, isAsync) {
if (obj == null) return false;
if (isAsync === true) return typeof obj[SymbolAsyncIterator] === "function";
if (isAsync === false) return typeof obj[SymbolIterator] === "function";
return typeof obj[SymbolAsyncIterator] === "function" || typeof obj[SymbolIterator] === "function";
}
function isDestroyed(stream) {
if (!isNodeStream(stream)) return null;
const wState = stream._writableState;
const rState = stream._readableState;
const state = wState || rState;
return !!(stream.destroyed || stream[kIsDestroyed] || state !== null && state !== undefined && state.destroyed);
}
// Have been end():d.
function isWritableEnded(stream) {
if (!isWritableNodeStream(stream)) return null;
if (stream.writableEnded === true) return true;
const wState = stream._writableState;
if (wState !== null && wState !== undefined && wState.errored) return false;
if (typeof (wState === null || wState === undefined ? undefined : wState.ended) !== "boolean") return null;
return wState.ended;
}
// Have emitted 'finish'.
function isWritableFinished(stream, strict) {
if (!isWritableNodeStream(stream)) return null;
if (stream.writableFinished === true) return true;
const wState = stream._writableState;
if (wState !== null && wState !== undefined && wState.errored) return false;
if (typeof (wState === null || wState === undefined ? undefined : wState.finished) !== "boolean") return null;
return !!(wState.finished || strict === false && wState.ended === true && wState.length === 0);
}
// Have been push(null):d.
function isReadableEnded(stream) {
if (!isReadableNodeStream(stream)) return null;
if (stream.readableEnded === true) return true;
const rState = stream._readableState;
if (!rState || rState.errored) return false;
if (typeof (rState === null || rState === undefined ? undefined : rState.ended) !== "boolean") return null;
return rState.ended;
}
// Have emitted 'end'.
function isReadableFinished(stream, strict) {
if (!isReadableNodeStream(stream)) return null;
const rState = stream._readableState;
if (rState !== null && rState !== undefined && rState.errored) return false;
if (typeof (rState === null || rState === undefined ? undefined : rState.endEmitted) !== "boolean") return null;
return !!(rState.endEmitted || strict === false && rState.ended === true && rState.length === 0);
}
function isReadable(stream) {
if (stream && stream[kIsReadable] != null) return stream[kIsReadable];
if (typeof (stream === null || stream === undefined ? undefined : stream.readable) !== "boolean") return null;
if (isDestroyed(stream)) return false;
return isReadableNodeStream(stream) && stream.readable && !isReadableFinished(stream);
}
function isWritable(stream) {
if (stream && stream[kIsWritable] != null) return stream[kIsWritable];
if (typeof (stream === null || stream === undefined ? undefined : stream.writable) !== "boolean") return null;
if (isDestroyed(stream)) return false;
return isWritableNodeStream(stream) && stream.writable && !isWritableEnded(stream);
}
function isFinished(stream, opts) {
if (!isNodeStream(stream)) {
return null;
}
if (isDestroyed(stream)) {
return true;
}
if ((opts === null || opts === undefined ? undefined : opts.readable) !== false && isReadable(stream)) {
return false;
}
if ((opts === null || opts === undefined ? undefined : opts.writable) !== false && isWritable(stream)) {
return false;
}
return true;
}
function isWritableErrored(stream) {
var _stream$_writableStat, _stream$_writableStat2;
if (!isNodeStream(stream)) {
return null;
}
if (stream.writableErrored) {
return stream.writableErrored;
}
return (_stream$_writableStat = (_stream$_writableStat2 = stream._writableState) === null || _stream$_writableStat2 === undefined ? undefined : _stream$_writableStat2.errored) !== null && _stream$_writableStat !== undefined ? _stream$_writableStat : null;
}
function isReadableErrored(stream) {
var _stream$_readableStat, _stream$_readableStat2;
if (!isNodeStream(stream)) {
return null;
}
if (stream.readableErrored) {
return stream.readableErrored;
}
return (_stream$_readableStat = (_stream$_readableStat2 = stream._readableState) === null || _stream$_readableStat2 === undefined ? undefined : _stream$_readableStat2.errored) !== null && _stream$_readableStat !== undefined ? _stream$_readableStat : null;
}
function isClosed(stream) {
if (!isNodeStream(stream)) {
return null;
}
if (typeof stream.closed === "boolean") {
return stream.closed;
}
const wState = stream._writableState;
const rState = stream._readableState;
if (typeof (wState === null || wState === undefined ? undefined : wState.closed) === "boolean" || typeof (rState === null || rState === undefined ? undefined : rState.closed) === "boolean") {
return (wState === null || wState === undefined ? undefined : wState.closed) || (rState === null || rState === undefined ? undefined : rState.closed);
}
if (typeof stream._closed === "boolean" && isOutgoingMessage(stream)) {
return stream._closed;
}
return null;
}
function isOutgoingMessage(stream) {
return typeof stream._closed === "boolean" && typeof stream._defaultKeepAlive === "boolean" && typeof stream._removedConnection === "boolean" && typeof stream._removedContLen === "boolean";
}
function isServerResponse(stream) {
return typeof stream._sent100 === "boolean" && isOutgoingMessage(stream);
}
function isServerRequest(stream) {
var _stream$req;
return typeof stream._consuming === "boolean" && typeof stream._dumped === "boolean" && ((_stream$req = stream.req) === null || _stream$req === undefined ? undefined : _stream$req.upgradeOrConnect) === undefined;
}
function willEmitClose(stream) {
if (!isNodeStream(stream)) return null;
const wState = stream._writableState;
const rState = stream._readableState;
const state = wState || rState;
return !state && isServerResponse(stream) || !!(state && state.autoDestroy && state.emitClose && state.closed === false);
}
function isDisturbed(stream) {
var _stream$kIsDisturbed;
return !!(stream && ((_stream$kIsDisturbed = stream[kIsDisturbed]) !== null && _stream$kIsDisturbed !== undefined ? _stream$kIsDisturbed : stream.readableDidRead || stream.readableAborted));
}
function isErrored(stream) {
var _ref, _ref2, _ref3, _ref4, _ref5, _stream$kIsErrored, _stream$_readableStat3, _stream$_writableStat3, _stream$_readableStat4, _stream$_writableStat4;
return !!(stream && ((_ref = (_ref2 = (_ref3 = (_ref4 = (_ref5 = (_stream$kIsErrored = stream[kIsErrored]) !== null && _stream$kIsErrored !== undefined ? _stream$kIsErrored : stream.readableErrored) !== null && _ref5 !== undefined ? _ref5 : stream.writableErrored) !== null && _ref4 !== undefined ? _ref4 : (_stream$_readableStat3 = stream._readableState) === null || _stream$_readableStat3 === undefined ? undefined : _stream$_readableStat3.errorEmitted) !== null && _ref3 !== undefined ? _ref3 : (_stream$_writableStat3 = stream._writableState) === null || _stream$_writableStat3 === undefined ? undefined : _stream$_writableStat3.errorEmitted) !== null && _ref2 !== undefined ? _ref2 : (_stream$_readableStat4 = stream._readableState) === null || _stream$_readableStat4 === undefined ? undefined : _stream$_readableStat4.errored) !== null && _ref !== undefined ? _ref : (_stream$_writableStat4 = stream._writableState) === null || _stream$_writableStat4 === undefined ? undefined : _stream$_writableStat4.errored));
}
exports$k = {
isDestroyed,
kIsDestroyed,
isDisturbed,
kIsDisturbed,
isErrored,
kIsErrored,
isReadable,
kIsReadable,
kIsClosedPromise,
kControllerErrorFunction,
kIsWritable,
isClosed,
isDuplexNodeStream,
isFinished,
isIterable,
isReadableNodeStream,
isReadableStream,
isReadableEnded,
isReadableFinished,
isReadableErrored,
isNodeStream,
isWebStream,
isWritable,
isWritableNodeStream,
isWritableStream,
isWritableEnded,
isWritableFinished,
isWritableErrored,
isServerRequest,
isServerResponse,
willEmitClose,
isTransformStream
};
return exports$k;
}
var exports$j = {},
_dewExec$i = false;
function dew$i() {
if (_dewExec$i) return exports$j;
_dewExec$i = true;
/* replacement start */
const process$1 = process
/* replacement end */
// Ported from https://github.com/mafintosh/end-of-stream with
// permission from the author, Mathias Buus (@mafintosh).
;
const {
AbortError,
codes
} = dew$l();
const {
ERR_INVALID_ARG_TYPE,
ERR_STREAM_PREMATURE_CLOSE
} = codes;
const {
kEmptyObject,
once
} = dew$m();
const {
validateAbortSignal,
validateFunction,
validateObject,
validateBoolean
} = dew$k();
const {
Promise,
PromisePrototypeThen,
SymbolDispose
} = dew$o();
const {
isClosed,
isReadable,
isReadableNodeStream,
isReadableStream,
isReadableFinished,
isReadableErrored,
isWritable,
isWritableNodeStream,
isWritableStream,
isWritableFinished,
isWritableErrored,
isNodeStream,
willEmitClose: _willEmitClose,
kIsClosedPromise
} = dew$j();
let addAbortListener;
function isRequest(stream) {
return stream.setHeader && typeof stream.abort === "function";
}
const nop = () => {};
function eos(stream, options, callback) {
var _options$readable, _options$writable;
if (arguments.length === 2) {
callback = options;
options = kEmptyObject;
} else if (options == null) {
options = kEmptyObject;
} else {
validateObject(options, "options");
}
validateFunction(callback, "callback");
validateAbortSignal(options.signal, "options.signal");
callback = once(callback);
if (isReadableStream(stream) || isWritableStream(stream)) {
return eosWeb(stream, options, callback);
}
if (!isNodeStream(stream)) {
throw new ERR_INVALID_ARG_TYPE("stream", ["ReadableStream", "WritableStream", "Stream"], stream);
}
const readable = (_options$readable = options.readable) !== null && _options$readable !== undefined ? _options$readable : isReadableNodeStream(stream);
const writable = (_options$writable = options.writable) !== null && _options$writable !== undefined ? _options$writable : isWritableNodeStream(stream);
const wState = stream._writableState;
const rState = stream._readableState;
const onlegacyfinish = () => {
if (!stream.writable) {
onfinish();
}
};
// TODO (ronag): Improve soft detection to include core modules and
// common ecosystem modules that do properly emit 'close' but fail
// this generic check.
let willEmitClose = _willEmitClose(stream) && isReadableNodeStream(stream) === readable && isWritableNodeStream(stream) === writable;
let writableFinished = isWritableFinished(stream, false);
const onfinish = () => {
writableFinished = true;
// Stream should not be destroyed here. If it is that
// means tha