code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
async json() { return consume(this, "json"); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
json
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
async blob() { return consume(this, "blob"); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
blob
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
async bytes() { return consume(this, "bytes"); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
bytes
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
async arrayBuffer() { return consume(this, "arrayBuffer"); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
arrayBuffer
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
async formData() { throw new NotSupportedError(); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
formData
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
get bodyUsed() { return util.isDisturbed(this); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
bodyUsed
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
get body() { if (!this[kBody]) { this[kBody] = ReadableStreamFrom(this); if (this[kConsume]) { this[kBody].getReader(); assert(this[kBody].locked); } } return this[kBody]; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
body
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
async dump(opts) { let limit = Number.isFinite(opts?.limit) ? opts.limit : 128 * 1024; const signal = opts?.signal; if (signal != null && (typeof signal !== "object" || !("aborted" in signal))) { throw new InvalidArgumentError("signal must be an AbortSignal"); } signal?.throwIfAborted(); if (this._readableState.closeEmitted) { return null; } return await new Promise((resolve, reject) => { if (this[kContentLength] > limit) { this.destroy(new AbortError()); } const onAbort = /* @__PURE__ */ __name(() => { this.destroy(signal.reason ?? new AbortError()); }, "onAbort"); signal?.addEventListener("abort", onAbort); this.on("close", function() { signal?.removeEventListener("abort", onAbort); if (signal?.aborted) { reject(signal.reason ?? new AbortError()); } else { resolve(null); } }).on("error", noop).on("data", function(chunk) { limit -= chunk.length; if (limit <= 0) { this.destroy(); } }).resume(); }); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
dump
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function isLocked(self) { return self[kBody] && self[kBody].locked === true || self[kConsume]; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
isLocked
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function isUnusable(self) { return util.isDisturbed(self) || isLocked(self); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
isUnusable
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
async function consume(stream, type) { assert(!stream[kConsume]); return new Promise((resolve, reject) => { if (isUnusable(stream)) { const rState = stream._readableState; if (rState.destroyed && rState.closeEmitted === false) { stream.on("error", (err) => { reject(err); }).on("close", () => { reject(new TypeError("unusable")); }); } else { reject(rState.errored ?? new TypeError("unusable")); } } else { queueMicrotask(() => { stream[kConsume] = { type, stream, resolve, reject, length: 0, body: [] }; stream.on("error", function(err) { consumeFinish(this[kConsume], err); }).on("close", function() { if (this[kConsume].body !== null) { consumeFinish(this[kConsume], new RequestAbortedError()); } }); consumeStart(stream[kConsume]); }); } }); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
consume
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function consumeStart(consume2) { if (consume2.body === null) { return; } const { _readableState: state } = consume2.stream; if (state.bufferIndex) { const start = state.bufferIndex; const end = state.buffer.length; for (let n = start; n < end; n++) { consumePush(consume2, state.buffer[n]); } } else { for (const chunk of state.buffer) { consumePush(consume2, chunk); } } if (state.endEmitted) { consumeEnd(this[kConsume]); } else { consume2.stream.on("end", function() { consumeEnd(this[kConsume]); }); } consume2.stream.resume(); while (consume2.stream.read() != null) { } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
consumeStart
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function chunksDecode(chunks, length) { if (chunks.length === 0 || length === 0) { return ""; } const buffer = chunks.length === 1 ? chunks[0] : Buffer.concat(chunks, length); const bufferLength = buffer.length; const start = bufferLength > 2 && buffer[0] === 239 && buffer[1] === 187 && buffer[2] === 191 ? 3 : 0; return buffer.utf8Slice(start, bufferLength); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
chunksDecode
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function chunksConcat(chunks, length) { if (chunks.length === 0 || length === 0) { return new Uint8Array(0); } if (chunks.length === 1) { return new Uint8Array(chunks[0]); } const buffer = new Uint8Array(Buffer.allocUnsafeSlow(length).buffer); let offset = 0; for (let i = 0; i < chunks.length; ++i) { const chunk = chunks[i]; buffer.set(chunk, offset); offset += chunk.length; } return buffer; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
chunksConcat
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function consumeEnd(consume2) { const { type, body, resolve, stream, length } = consume2; try { if (type === "text") { resolve(chunksDecode(body, length)); } else if (type === "json") { resolve(JSON.parse(chunksDecode(body, length))); } else if (type === "arrayBuffer") { resolve(chunksConcat(body, length).buffer); } else if (type === "blob") { resolve(new Blob(body, { type: stream[kContentType] })); } else if (type === "bytes") { resolve(chunksConcat(body, length)); } consumeFinish(consume2); } catch (err) { stream.destroy(err); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
consumeEnd
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function consumePush(consume2, chunk) { consume2.length += chunk.length; consume2.body.push(chunk); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
consumePush
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function consumeFinish(consume2, err) { if (consume2.body === null) { return; } if (err) { consume2.reject(err); } else { consume2.resolve(); } consume2.type = null; consume2.stream = null; consume2.resolve = null; consume2.reject = null; consume2.length = 0; consume2.body = null; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
consumeFinish
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
async function getResolveErrorBodyCallback({ callback, body, contentType, statusCode, statusMessage, headers }) { assert(body); let chunks = []; let length = 0; try { for await (const chunk of body) { chunks.push(chunk); length += chunk.length; if (length > CHUNK_LIMIT) { chunks = []; length = 0; break; } } } catch { chunks = []; length = 0; } const message = `Response status code ${statusCode}${statusMessage ? `: ${statusMessage}` : ""}`; if (statusCode === 204 || !contentType || !length) { queueMicrotask(() => callback(new ResponseStatusCodeError(message, statusCode, headers))); return; } const stackTraceLimit = Error.stackTraceLimit; Error.stackTraceLimit = 0; let payload; try { if (isContentTypeApplicationJson(contentType)) { payload = JSON.parse(chunksDecode(chunks, length)); } else if (isContentTypeText(contentType)) { payload = chunksDecode(chunks, length); } } catch { } finally { Error.stackTraceLimit = stackTraceLimit; } queueMicrotask(() => callback(new ResponseStatusCodeError(message, statusCode, headers, payload))); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
getResolveErrorBodyCallback
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
constructor(opts, callback) { if (!opts || typeof opts !== "object") { throw new InvalidArgumentError("invalid opts"); } const { signal, method, opaque, body, onInfo, responseHeaders, throwOnError, highWaterMark } = opts; try { if (typeof callback !== "function") { throw new InvalidArgumentError("invalid callback"); } if (highWaterMark && (typeof highWaterMark !== "number" || highWaterMark < 0)) { throw new InvalidArgumentError("invalid highWaterMark"); } if (signal && typeof signal.on !== "function" && typeof signal.addEventListener !== "function") { throw new InvalidArgumentError("signal must be an EventEmitter or EventTarget"); } if (method === "CONNECT") { throw new InvalidArgumentError("invalid method"); } if (onInfo && typeof onInfo !== "function") { throw new InvalidArgumentError("invalid onInfo callback"); } super("UNDICI_REQUEST"); } catch (err) { if (util.isStream(body)) { util.destroy(body.on("error", util.nop), err); } throw err; } this.method = method; this.responseHeaders = responseHeaders || null; this.opaque = opaque || null; this.callback = callback; this.res = null; this.abort = null; this.body = body; this.trailers = {}; this.context = null; this.onInfo = onInfo || null; this.throwOnError = throwOnError; this.highWaterMark = highWaterMark; this.signal = signal; this.reason = null; this.removeAbortListener = null; if (util.isStream(body)) { body.on("error", (err) => { this.onError(err); }); } if (this.signal) { if (this.signal.aborted) { this.reason = this.signal.reason ?? new RequestAbortedError(); } else { this.removeAbortListener = util.addAbortListener(this.signal, () => { this.reason = this.signal.reason ?? new RequestAbortedError(); if (this.res) { util.destroy(this.res, this.reason); } else if (this.abort) { this.abort(this.reason); } if (this.removeAbortListener) { this.res?.off("close", this.removeAbortListener); this.removeAbortListener(); this.removeAbortListener = null; } }); } } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
onConnect(abort, context) { if (this.reason) { abort(this.reason); return; } assert(this.callback); this.abort = abort; this.context = context; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onConnect
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
onHeaders(statusCode, rawHeaders, resume, statusMessage) { const { callback, opaque, abort, context, responseHeaders, highWaterMark } = this; const headers = responseHeaders === "raw" ? util.parseRawHeaders(rawHeaders) : util.parseHeaders(rawHeaders); if (statusCode < 200) { if (this.onInfo) { this.onInfo({ statusCode, headers }); } return; } const parsedHeaders = responseHeaders === "raw" ? util.parseHeaders(rawHeaders) : headers; const contentType = parsedHeaders["content-type"]; const contentLength = parsedHeaders["content-length"]; const res = new Readable({ resume, abort, contentType, contentLength: this.method !== "HEAD" && contentLength ? Number(contentLength) : null, highWaterMark }); if (this.removeAbortListener) { res.on("close", this.removeAbortListener); } this.callback = null; this.res = res; if (callback !== null) { if (this.throwOnError && statusCode >= 400) { this.runInAsyncScope( getResolveErrorBodyCallback, null, { callback, body: res, contentType, statusCode, statusMessage, headers } ); } else { this.runInAsyncScope(callback, null, null, { statusCode, headers, trailers: this.trailers, opaque, body: res, context }); } } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onHeaders
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
onData(chunk) { return this.res.push(chunk); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onData
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
onComplete(trailers) { util.parseHeaders(trailers, this.trailers); this.res.push(null); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onComplete
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
onError(err) { const { res, callback, body, opaque } = this; if (callback) { this.callback = null; queueMicrotask(() => { this.runInAsyncScope(callback, null, err, { opaque }); }); } if (res) { this.res = null; queueMicrotask(() => { util.destroy(res, err); }); } if (body) { this.body = null; util.destroy(body, err); } if (this.removeAbortListener) { res?.off("close", this.removeAbortListener); this.removeAbortListener(); this.removeAbortListener = null; } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onError
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function request(opts, callback) { if (callback === void 0) { return new Promise((resolve, reject) => { request.call(this, opts, (err, data) => { return err ? reject(err) : resolve(data); }); }); } try { this.dispatch(opts, new RequestHandler(opts, callback)); } catch (err) { if (typeof callback !== "function") { throw err; } const opaque = opts?.opaque; queueMicrotask(() => callback(err, { opaque })); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
request
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function abort(self) { if (self.abort) { self.abort(self[kSignal]?.reason); } else { self.reason = self[kSignal]?.reason ?? new RequestAbortedError(); } removeSignal(self); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
abort
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function addSignal(self, signal) { self.reason = null; self[kSignal] = null; self[kListener] = null; if (!signal) { return; } if (signal.aborted) { abort(self); return; } self[kSignal] = signal; self[kListener] = () => { abort(self); }; addAbortListener(self[kSignal], self[kListener]); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
addSignal
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function removeSignal(self) { if (!self[kSignal]) { return; } if ("removeEventListener" in self[kSignal]) { self[kSignal].removeEventListener("abort", self[kListener]); } else { self[kSignal].removeListener("abort", self[kListener]); } self[kSignal] = null; self[kListener] = null; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
removeSignal
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
constructor(opts, factory, callback) { if (!opts || typeof opts !== "object") { throw new InvalidArgumentError("invalid opts"); } const { signal, method, opaque, body, onInfo, responseHeaders, throwOnError } = opts; try { if (typeof callback !== "function") { throw new InvalidArgumentError("invalid callback"); } if (typeof factory !== "function") { throw new InvalidArgumentError("invalid factory"); } if (signal && typeof signal.on !== "function" && typeof signal.addEventListener !== "function") { throw new InvalidArgumentError("signal must be an EventEmitter or EventTarget"); } if (method === "CONNECT") { throw new InvalidArgumentError("invalid method"); } if (onInfo && typeof onInfo !== "function") { throw new InvalidArgumentError("invalid onInfo callback"); } super("UNDICI_STREAM"); } catch (err) { if (util.isStream(body)) { util.destroy(body.on("error", util.nop), err); } throw err; } this.responseHeaders = responseHeaders || null; this.opaque = opaque || null; this.factory = factory; this.callback = callback; this.res = null; this.abort = null; this.context = null; this.trailers = null; this.body = body; this.onInfo = onInfo || null; this.throwOnError = throwOnError || false; if (util.isStream(body)) { body.on("error", (err) => { this.onError(err); }); } addSignal(this, signal); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
onConnect(abort, context) { if (this.reason) { abort(this.reason); return; } assert(this.callback); this.abort = abort; this.context = context; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onConnect
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
onHeaders(statusCode, rawHeaders, resume, statusMessage) { const { factory, opaque, context, callback, responseHeaders } = this; const headers = responseHeaders === "raw" ? util.parseRawHeaders(rawHeaders) : util.parseHeaders(rawHeaders); if (statusCode < 200) { if (this.onInfo) { this.onInfo({ statusCode, headers }); } return; } this.factory = null; let res; if (this.throwOnError && statusCode >= 400) { const parsedHeaders = responseHeaders === "raw" ? util.parseHeaders(rawHeaders) : headers; const contentType = parsedHeaders["content-type"]; res = new PassThrough(); this.callback = null; this.runInAsyncScope( getResolveErrorBodyCallback, null, { callback, body: res, contentType, statusCode, statusMessage, headers } ); } else { if (factory === null) { return; } res = this.runInAsyncScope(factory, null, { statusCode, headers, opaque, context }); if (!res || typeof res.write !== "function" || typeof res.end !== "function" || typeof res.on !== "function") { throw new InvalidReturnValueError("expected Writable"); } finished(res, { readable: false }, (err) => { const { callback: callback2, res: res2, opaque: opaque2, trailers, abort } = this; this.res = null; if (err || !res2.readable) { util.destroy(res2, err); } this.callback = null; this.runInAsyncScope(callback2, null, err || null, { opaque: opaque2, trailers }); if (err) { abort(); } }); } res.on("drain", resume); this.res = res; const needDrain = res.writableNeedDrain !== void 0 ? res.writableNeedDrain : res._writableState?.needDrain; return needDrain !== true; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onHeaders
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
onData(chunk) { const { res } = this; return res ? res.write(chunk) : true; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onData
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
onComplete(trailers) { const { res } = this; removeSignal(this); if (!res) { return; } this.trailers = util.parseHeaders(trailers); res.end(); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onComplete
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
onError(err) { const { res, callback, opaque, body } = this; removeSignal(this); this.factory = null; if (res) { this.res = null; util.destroy(res, err); } else if (callback) { this.callback = null; queueMicrotask(() => { this.runInAsyncScope(callback, null, err, { opaque }); }); } if (body) { this.body = null; util.destroy(body, err); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onError
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function stream(opts, factory, callback) { if (callback === void 0) { return new Promise((resolve, reject) => { stream.call(this, opts, factory, (err, data) => { return err ? reject(err) : resolve(data); }); }); } try { this.dispatch(opts, new StreamHandler(opts, factory, callback)); } catch (err) { if (typeof callback !== "function") { throw err; } const opaque = opts?.opaque; queueMicrotask(() => callback(err, { opaque })); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
stream
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
constructor() { super({ autoDestroy: true }); this[kResume] = null; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
_read() { const { [kResume]: resume } = this; if (resume) { this[kResume] = null; resume(); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
_read
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
_destroy(err, callback) { this._read(); callback(err); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
_destroy
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
constructor(resume) { super({ autoDestroy: true }); this[kResume] = resume; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
_destroy(err, callback) { if (!err && !this._readableState.endEmitted) { err = new RequestAbortedError(); } callback(err); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
_destroy
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
constructor(opts, handler) { if (!opts || typeof opts !== "object") { throw new InvalidArgumentError("invalid opts"); } if (typeof handler !== "function") { throw new InvalidArgumentError("invalid handler"); } const { signal, method, opaque, onInfo, responseHeaders } = opts; if (signal && typeof signal.on !== "function" && typeof signal.addEventListener !== "function") { throw new InvalidArgumentError("signal must be an EventEmitter or EventTarget"); } if (method === "CONNECT") { throw new InvalidArgumentError("invalid method"); } if (onInfo && typeof onInfo !== "function") { throw new InvalidArgumentError("invalid onInfo callback"); } super("UNDICI_PIPELINE"); this.opaque = opaque || null; this.responseHeaders = responseHeaders || null; this.handler = handler; this.abort = null; this.context = null; this.onInfo = onInfo || null; this.req = new PipelineRequest().on("error", util.nop); this.ret = new Duplex({ readableObjectMode: opts.objectMode, autoDestroy: true, read: () => { const { body } = this; if (body?.resume) { body.resume(); } }, write: (chunk, encoding, callback) => { const { req } = this; if (req.push(chunk, encoding) || req._readableState.destroyed) { callback(); } else { req[kResume] = callback; } }, destroy: (err, callback) => { const { body, req, res, ret, abort } = this; if (!err && !ret._readableState.endEmitted) { err = new RequestAbortedError(); } if (abort && err) { abort(); } util.destroy(body, err); util.destroy(req, err); util.destroy(res, err); removeSignal(this); callback(err); } }).on("prefinish", () => { const { req } = this; req.push(null); }); this.res = null; addSignal(this, signal); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
onConnect(abort, context) { const { ret, res } = this; if (this.reason) { abort(this.reason); return; } assert(!res, "pipeline cannot be retried"); assert(!ret.destroyed); this.abort = abort; this.context = context; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onConnect
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
onHeaders(statusCode, rawHeaders, resume) { const { opaque, handler, context } = this; if (statusCode < 200) { if (this.onInfo) { const headers = this.responseHeaders === "raw" ? util.parseRawHeaders(rawHeaders) : util.parseHeaders(rawHeaders); this.onInfo({ statusCode, headers }); } return; } this.res = new PipelineResponse(resume); let body; try { this.handler = null; const headers = this.responseHeaders === "raw" ? util.parseRawHeaders(rawHeaders) : util.parseHeaders(rawHeaders); body = this.runInAsyncScope(handler, null, { statusCode, headers, opaque, body: this.res, context }); } catch (err) { this.res.on("error", util.nop); throw err; } if (!body || typeof body.on !== "function") { throw new InvalidReturnValueError("expected Readable"); } body.on("data", (chunk) => { const { ret, body: body2 } = this; if (!ret.push(chunk) && body2.pause) { body2.pause(); } }).on("error", (err) => { const { ret } = this; util.destroy(ret, err); }).on("end", () => { const { ret } = this; ret.push(null); }).on("close", () => { const { ret } = this; if (!ret._readableState.ended) { util.destroy(ret, new RequestAbortedError()); } }); this.body = body; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onHeaders
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
onData(chunk) { const { res } = this; return res.push(chunk); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onData
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
onComplete(trailers) { const { res } = this; res.push(null); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onComplete
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
onError(err) { const { ret } = this; this.handler = null; util.destroy(ret, err); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onError
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function pipeline(opts, handler) { try { const pipelineHandler = new PipelineHandler(opts, handler); this.dispatch({ ...opts, body: pipelineHandler.req }, pipelineHandler); return pipelineHandler.ret; } catch (err) { return new PassThrough().destroy(err); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
pipeline
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
constructor(opts, callback) { if (!opts || typeof opts !== "object") { throw new InvalidArgumentError("invalid opts"); } if (typeof callback !== "function") { throw new InvalidArgumentError("invalid callback"); } const { signal, opaque, responseHeaders } = opts; if (signal && typeof signal.on !== "function" && typeof signal.addEventListener !== "function") { throw new InvalidArgumentError("signal must be an EventEmitter or EventTarget"); } super("UNDICI_UPGRADE"); this.responseHeaders = responseHeaders || null; this.opaque = opaque || null; this.callback = callback; this.abort = null; this.context = null; addSignal(this, signal); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
onConnect(abort, context) { if (this.reason) { abort(this.reason); return; } assert(this.callback); this.abort = abort; this.context = null; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onConnect
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
onHeaders() { throw new SocketError("bad upgrade", null); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onHeaders
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
onUpgrade(statusCode, rawHeaders, socket) { assert(statusCode === 101); const { callback, opaque, context } = this; removeSignal(this); this.callback = null; const headers = this.responseHeaders === "raw" ? util.parseRawHeaders(rawHeaders) : util.parseHeaders(rawHeaders); this.runInAsyncScope(callback, null, null, { headers, socket, opaque, context }); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onUpgrade
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
onError(err) { const { callback, opaque } = this; removeSignal(this); if (callback) { this.callback = null; queueMicrotask(() => { this.runInAsyncScope(callback, null, err, { opaque }); }); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onError
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function upgrade(opts, callback) { if (callback === void 0) { return new Promise((resolve, reject) => { upgrade.call(this, opts, (err, data) => { return err ? reject(err) : resolve(data); }); }); } try { const upgradeHandler = new UpgradeHandler(opts, callback); this.dispatch({ ...opts, method: opts.method || "GET", upgrade: opts.protocol || "Websocket" }, upgradeHandler); } catch (err) { if (typeof callback !== "function") { throw err; } const opaque = opts?.opaque; queueMicrotask(() => callback(err, { opaque })); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
upgrade
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
constructor(opts, callback) { if (!opts || typeof opts !== "object") { throw new InvalidArgumentError("invalid opts"); } if (typeof callback !== "function") { throw new InvalidArgumentError("invalid callback"); } const { signal, opaque, responseHeaders } = opts; if (signal && typeof signal.on !== "function" && typeof signal.addEventListener !== "function") { throw new InvalidArgumentError("signal must be an EventEmitter or EventTarget"); } super("UNDICI_CONNECT"); this.opaque = opaque || null; this.responseHeaders = responseHeaders || null; this.callback = callback; this.abort = null; addSignal(this, signal); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
onConnect(abort, context) { if (this.reason) { abort(this.reason); return; } assert(this.callback); this.abort = abort; this.context = context; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onConnect
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
onHeaders() { throw new SocketError("bad connect", null); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onHeaders
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
onUpgrade(statusCode, rawHeaders, socket) { const { callback, opaque, context } = this; removeSignal(this); this.callback = null; let headers = rawHeaders; if (headers != null) { headers = this.responseHeaders === "raw" ? util.parseRawHeaders(rawHeaders) : util.parseHeaders(rawHeaders); } this.runInAsyncScope(callback, null, null, { statusCode, headers, socket, opaque, context }); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onUpgrade
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
onError(err) { const { callback, opaque } = this; removeSignal(this); if (callback) { this.callback = null; queueMicrotask(() => { this.runInAsyncScope(callback, null, err, { opaque }); }); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onError
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function connect(opts, callback) { if (callback === void 0) { return new Promise((resolve, reject) => { connect.call(this, opts, (err, data) => { return err ? reject(err) : resolve(data); }); }); } try { const connectHandler = new ConnectHandler(opts, callback); this.dispatch({ ...opts, method: "CONNECT" }, connectHandler); } catch (err) { if (typeof callback !== "function") { throw err; } const opaque = opts?.opaque; queueMicrotask(() => callback(err, { opaque })); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
connect
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
constructor(message) { super(message); Error.captureStackTrace(this, _MockNotMatchedError); this.name = "MockNotMatchedError"; this.message = message || "The request does not match any registered mock dispatches"; this.code = "UND_MOCK_ERR_MOCK_NOT_MATCHED"; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function matchValue(match, value) { if (typeof match === "string") { return match === value; } if (match instanceof RegExp) { return match.test(value); } if (typeof match === "function") { return match(value) === true; } return false; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
matchValue
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function lowerCaseEntries(headers) { return Object.fromEntries( Object.entries(headers).map(([headerName, headerValue]) => { return [headerName.toLocaleLowerCase(), headerValue]; }) ); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
lowerCaseEntries
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function getHeaderByName(headers, key) { if (Array.isArray(headers)) { for (let i = 0; i < headers.length; i += 2) { if (headers[i].toLocaleLowerCase() === key.toLocaleLowerCase()) { return headers[i + 1]; } } return void 0; } else if (typeof headers.get === "function") { return headers.get(key); } else { return lowerCaseEntries(headers)[key.toLocaleLowerCase()]; } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
getHeaderByName
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function buildHeadersFromArray(headers) { const clone = headers.slice(); const entries = []; for (let index = 0; index < clone.length; index += 2) { entries.push([clone[index], clone[index + 1]]); } return Object.fromEntries(entries); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
buildHeadersFromArray
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function matchHeaders(mockDispatch2, headers) { if (typeof mockDispatch2.headers === "function") { if (Array.isArray(headers)) { headers = buildHeadersFromArray(headers); } return mockDispatch2.headers(headers ? lowerCaseEntries(headers) : {}); } if (typeof mockDispatch2.headers === "undefined") { return true; } if (typeof headers !== "object" || typeof mockDispatch2.headers !== "object") { return false; } for (const [matchHeaderName, matchHeaderValue] of Object.entries(mockDispatch2.headers)) { const headerValue = getHeaderByName(headers, matchHeaderName); if (!matchValue(matchHeaderValue, headerValue)) { return false; } } return true; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
matchHeaders
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function safeUrl(path) { if (typeof path !== "string") { return path; } const pathSegments = path.split("?"); if (pathSegments.length !== 2) { return path; } const qp = new URLSearchParams(pathSegments.pop()); qp.sort(); return [...pathSegments, qp.toString()].join("?"); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
safeUrl
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function matchKey(mockDispatch2, { path, method, body, headers }) { const pathMatch = matchValue(mockDispatch2.path, path); const methodMatch = matchValue(mockDispatch2.method, method); const bodyMatch = typeof mockDispatch2.body !== "undefined" ? matchValue(mockDispatch2.body, body) : true; const headersMatch = matchHeaders(mockDispatch2, headers); return pathMatch && methodMatch && bodyMatch && headersMatch; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
matchKey
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function getResponseData(data) { if (Buffer.isBuffer(data)) { return data; } else if (data instanceof Uint8Array) { return data; } else if (data instanceof ArrayBuffer) { return data; } else if (typeof data === "object") { return JSON.stringify(data); } else { return data.toString(); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
getResponseData
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function getMockDispatch(mockDispatches, key) { const basePath = key.query ? buildURL(key.path, key.query) : key.path; const resolvedPath = typeof basePath === "string" ? safeUrl(basePath) : basePath; let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path }) => matchValue(safeUrl(path), resolvedPath)); if (matchedMockDispatches.length === 0) { throw new MockNotMatchedError(`Mock dispatch not matched for path '${resolvedPath}'`); } matchedMockDispatches = matchedMockDispatches.filter(({ method }) => matchValue(method, key.method)); if (matchedMockDispatches.length === 0) { throw new MockNotMatchedError(`Mock dispatch not matched for method '${key.method}' on path '${resolvedPath}'`); } matchedMockDispatches = matchedMockDispatches.filter(({ body }) => typeof body !== "undefined" ? matchValue(body, key.body) : true); if (matchedMockDispatches.length === 0) { throw new MockNotMatchedError(`Mock dispatch not matched for body '${key.body}' on path '${resolvedPath}'`); } matchedMockDispatches = matchedMockDispatches.filter((mockDispatch2) => matchHeaders(mockDispatch2, key.headers)); if (matchedMockDispatches.length === 0) { const headers = typeof key.headers === "object" ? JSON.stringify(key.headers) : key.headers; throw new MockNotMatchedError(`Mock dispatch not matched for headers '${headers}' on path '${resolvedPath}'`); } return matchedMockDispatches[0]; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
getMockDispatch
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function addMockDispatch(mockDispatches, key, data) { const baseData = { timesInvoked: 0, times: 1, persist: false, consumed: false }; const replyData = typeof data === "function" ? { callback: data } : { ...data }; const newMockDispatch = { ...baseData, ...key, pending: true, data: { error: null, ...replyData } }; mockDispatches.push(newMockDispatch); return newMockDispatch; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
addMockDispatch
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function deleteMockDispatch(mockDispatches, key) { const index = mockDispatches.findIndex((dispatch) => { if (!dispatch.consumed) { return false; } return matchKey(dispatch, key); }); if (index !== -1) { mockDispatches.splice(index, 1); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
deleteMockDispatch
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function buildKey(opts) { const { path, method, body, headers, query } = opts; return { path, method, body, headers, query }; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
buildKey
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function generateKeyValues(data) { const keys = Object.keys(data); const result = []; for (let i = 0; i < keys.length; ++i) { const key = keys[i]; const value = data[key]; const name = Buffer.from(`${key}`); if (Array.isArray(value)) { for (let j = 0; j < value.length; ++j) { result.push(name, Buffer.from(`${value[j]}`)); } } else { result.push(name, Buffer.from(`${value}`)); } } return result; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
generateKeyValues
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function getStatusText(statusCode) { return STATUS_CODES[statusCode] || "unknown"; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
getStatusText
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
async function getResponse(body) { const buffers = []; for await (const data of body) { buffers.push(data); } return Buffer.concat(buffers).toString("utf8"); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
getResponse
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function mockDispatch(opts, handler) { const key = buildKey(opts); const mockDispatch2 = getMockDispatch(this[kDispatches], key); mockDispatch2.timesInvoked++; if (mockDispatch2.data.callback) { mockDispatch2.data = { ...mockDispatch2.data, ...mockDispatch2.data.callback(opts) }; } const { data: { statusCode, data, headers, trailers, error }, delay, persist } = mockDispatch2; const { timesInvoked, times } = mockDispatch2; mockDispatch2.consumed = !persist && timesInvoked >= times; mockDispatch2.pending = timesInvoked < times; if (error !== null) { deleteMockDispatch(this[kDispatches], key); handler.onError(error); return true; } if (typeof delay === "number" && delay > 0) { setTimeout(() => { handleReply(this[kDispatches]); }, delay); } else { handleReply(this[kDispatches]); } function handleReply(mockDispatches, _data = data) { const optsHeaders = Array.isArray(opts.headers) ? buildHeadersFromArray(opts.headers) : opts.headers; const body = typeof _data === "function" ? _data({ ...opts, headers: optsHeaders }) : _data; if (isPromise(body)) { body.then((newData) => handleReply(mockDispatches, newData)); return; } const responseData = getResponseData(body); const responseHeaders = generateKeyValues(headers); const responseTrailers = generateKeyValues(trailers); handler.onConnect?.((err) => handler.onError(err), null); handler.onHeaders?.(statusCode, responseHeaders, resume, getStatusText(statusCode)); handler.onData?.(Buffer.from(responseData)); handler.onComplete?.(responseTrailers); deleteMockDispatch(mockDispatches, key); } __name(handleReply, "handleReply"); function resume() { } __name(resume, "resume"); return true; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
mockDispatch
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function handleReply(mockDispatches, _data = data) { const optsHeaders = Array.isArray(opts.headers) ? buildHeadersFromArray(opts.headers) : opts.headers; const body = typeof _data === "function" ? _data({ ...opts, headers: optsHeaders }) : _data; if (isPromise(body)) { body.then((newData) => handleReply(mockDispatches, newData)); return; } const responseData = getResponseData(body); const responseHeaders = generateKeyValues(headers); const responseTrailers = generateKeyValues(trailers); handler.onConnect?.((err) => handler.onError(err), null); handler.onHeaders?.(statusCode, responseHeaders, resume, getStatusText(statusCode)); handler.onData?.(Buffer.from(responseData)); handler.onComplete?.(responseTrailers); deleteMockDispatch(mockDispatches, key); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
handleReply
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function buildMockDispatch() { const agent = this[kMockAgent]; const origin = this[kOrigin]; const originalDispatch = this[kOriginalDispatch]; return /* @__PURE__ */ __name(function dispatch(opts, handler) { if (agent.isMockActive) { try { mockDispatch.call(this, opts, handler); } catch (error) { if (error instanceof MockNotMatchedError) { const netConnect = agent[kGetNetConnect](); if (netConnect === false) { throw new MockNotMatchedError(`${error.message}: subsequent request to origin ${origin} was not allowed (net.connect disabled)`); } if (checkNetConnect(netConnect, origin)) { originalDispatch.call(this, opts, handler); } else { throw new MockNotMatchedError(`${error.message}: subsequent request to origin ${origin} was not allowed (net.connect is not enabled for this origin)`); } } else { throw error; } } } else { originalDispatch.call(this, opts, handler); } }, "dispatch"); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
buildMockDispatch
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function checkNetConnect(netConnect, origin) { const url = new URL(origin); if (netConnect === true) { return true; } else if (Array.isArray(netConnect) && netConnect.some((matcher) => matchValue(matcher, url.host))) { return true; } return false; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
checkNetConnect
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
function buildMockOptions(opts) { if (opts) { const { agent, ...mockOptions } = opts; return mockOptions; } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
buildMockOptions
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
constructor(mockDispatch) { this[kMockDispatch] = mockDispatch; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
delay(waitInMs) { if (typeof waitInMs !== "number" || !Number.isInteger(waitInMs) || waitInMs <= 0) { throw new InvalidArgumentError("waitInMs must be a valid integer > 0"); } this[kMockDispatch].delay = waitInMs; return this; }
Delay a reply by a set amount in ms.
delay
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
persist() { this[kMockDispatch].persist = true; return this; }
For a defined reply, never mark as consumed.
persist
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
times(repeatTimes) { if (typeof repeatTimes !== "number" || !Number.isInteger(repeatTimes) || repeatTimes <= 0) { throw new InvalidArgumentError("repeatTimes must be a valid integer > 0"); } this[kMockDispatch].times = repeatTimes; return this; }
Allow one to define a reply for a set amount of matching requests.
times
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
constructor(opts, mockDispatches) { if (typeof opts !== "object") { throw new InvalidArgumentError("opts must be an object"); } if (typeof opts.path === "undefined") { throw new InvalidArgumentError("opts.path must be defined"); } if (typeof opts.method === "undefined") { opts.method = "GET"; } if (typeof opts.path === "string") { if (opts.query) { opts.path = buildURL(opts.path, opts.query); } else { const parsedURL = new URL(opts.path, "data://"); opts.path = parsedURL.pathname + parsedURL.search; } } if (typeof opts.method === "string") { opts.method = opts.method.toUpperCase(); } this[kDispatchKey] = buildKey(opts); this[kDispatches] = mockDispatches; this[kDefaultHeaders] = {}; this[kDefaultTrailers] = {}; this[kContentLength] = false; }
Allow one to define a reply for a set amount of matching requests.
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
createMockScopeDispatchData({ statusCode, data, responseOptions }) { const responseData = getResponseData(data); const contentLength = this[kContentLength] ? { "content-length": responseData.length } : {}; const headers = { ...this[kDefaultHeaders], ...contentLength, ...responseOptions.headers }; const trailers = { ...this[kDefaultTrailers], ...responseOptions.trailers }; return { statusCode, data, headers, trailers }; }
Allow one to define a reply for a set amount of matching requests.
createMockScopeDispatchData
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
validateReplyParameters(replyParameters) { if (typeof replyParameters.statusCode === "undefined") { throw new InvalidArgumentError("statusCode must be defined"); } if (typeof replyParameters.responseOptions !== "object" || replyParameters.responseOptions === null) { throw new InvalidArgumentError("responseOptions must be an object"); } }
Allow one to define a reply for a set amount of matching requests.
validateReplyParameters
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
reply(replyOptionsCallbackOrStatusCode) { if (typeof replyOptionsCallbackOrStatusCode === "function") { const wrappedDefaultsCallback = /* @__PURE__ */ __name((opts) => { const resolvedData = replyOptionsCallbackOrStatusCode(opts); if (typeof resolvedData !== "object" || resolvedData === null) { throw new InvalidArgumentError("reply options callback must return an object"); } const replyParameters2 = { data: "", responseOptions: {}, ...resolvedData }; this.validateReplyParameters(replyParameters2); return { ...this.createMockScopeDispatchData(replyParameters2) }; }, "wrappedDefaultsCallback"); const newMockDispatch2 = addMockDispatch(this[kDispatches], this[kDispatchKey], wrappedDefaultsCallback); return new MockScope(newMockDispatch2); } const replyParameters = { statusCode: replyOptionsCallbackOrStatusCode, data: arguments[1] === void 0 ? "" : arguments[1], responseOptions: arguments[2] === void 0 ? {} : arguments[2] }; this.validateReplyParameters(replyParameters); const dispatchData = this.createMockScopeDispatchData(replyParameters); const newMockDispatch = addMockDispatch(this[kDispatches], this[kDispatchKey], dispatchData); return new MockScope(newMockDispatch); }
Mock an undici request with a defined reply.
reply
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
replyWithError(error) { if (typeof error === "undefined") { throw new InvalidArgumentError("error must be defined"); } const newMockDispatch = addMockDispatch(this[kDispatches], this[kDispatchKey], { error }); return new MockScope(newMockDispatch); }
Mock an undici request with a defined error.
replyWithError
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
defaultReplyHeaders(headers) { if (typeof headers === "undefined") { throw new InvalidArgumentError("headers must be defined"); } this[kDefaultHeaders] = headers; return this; }
Set default reply headers on the interceptor for subsequent replies
defaultReplyHeaders
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
defaultReplyTrailers(trailers) { if (typeof trailers === "undefined") { throw new InvalidArgumentError("trailers must be defined"); } this[kDefaultTrailers] = trailers; return this; }
Set default reply trailers on the interceptor for subsequent replies
defaultReplyTrailers
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
replyContentLength() { this[kContentLength] = true; return this; }
Set reply content length header for replies on the interceptor
replyContentLength
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
constructor(origin, opts) { super(origin, opts); if (!opts || !opts.agent || typeof opts.agent.dispatch !== "function") { throw new InvalidArgumentError("Argument opts.agent must implement Agent"); } this[kMockAgent] = opts.agent; this[kOrigin] = origin; this[kDispatches] = []; this[kConnected] = 1; this[kOriginalDispatch] = this.dispatch; this[kOriginalClose] = this.close.bind(this); this.dispatch = buildMockDispatch.call(this); this.close = this[kClose]; }
Set reply content length header for replies on the interceptor
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
intercept(opts) { return new MockInterceptor(opts, this[kDispatches]); }
Sets up the base interceptor for mocking replies from undici.
intercept
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
constructor(origin, opts) { super(origin, opts); if (!opts || !opts.agent || typeof opts.agent.dispatch !== "function") { throw new InvalidArgumentError("Argument opts.agent must implement Agent"); } this[kMockAgent] = opts.agent; this[kOrigin] = origin; this[kDispatches] = []; this[kConnected] = 1; this[kOriginalDispatch] = this.dispatch; this[kOriginalClose] = this.close.bind(this); this.dispatch = buildMockDispatch.call(this); this.close = this[kClose]; }
Sets up the base interceptor for mocking replies from undici.
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
intercept(opts) { return new MockInterceptor(opts, this[kDispatches]); }
Sets up the base interceptor for mocking replies from undici.
intercept
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
constructor(singular, plural) { this.singular = singular; this.plural = plural; }
Sets up the base interceptor for mocking replies from undici.
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
pluralize(count) { const one = count === 1; const keys = one ? singulars : plurals; const noun = one ? this.singular : this.plural; return { ...keys, count, noun }; }
Sets up the base interceptor for mocking replies from undici.
pluralize
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
constructor({ disableColors } = {}) { this.transform = new Transform({ transform(chunk, _enc, cb) { cb(null, chunk); } }); this.logger = new Console({ stdout: this.transform, inspectOptions: { colors: !disableColors && !define_process_default.env.CI } }); }
Sets up the base interceptor for mocking replies from undici.
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT
transform(chunk, _enc, cb) { cb(null, chunk); }
Sets up the base interceptor for mocking replies from undici.
transform
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/load.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/load.js
MIT