Skip to content

Commit

Permalink
build: update distribution (#3221)
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-bot authored Aug 20, 2024
1 parent 4cfc1fc commit 00897e0
Showing 1 changed file with 57 additions and 31 deletions.
88 changes: 57 additions & 31 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15930,9 +15930,23 @@ const kWeight = Symbol('kWeight')
const kMaxWeightPerServer = Symbol('kMaxWeightPerServer')
const kErrorPenalty = Symbol('kErrorPenalty')

/**
* Calculate the greatest common divisor of two numbers by
* using the Euclidean algorithm.
*
* @param {number} a
* @param {number} b
* @returns {number}
*/
function getGreatestCommonDivisor (a, b) {
if (b === 0) return a
return getGreatestCommonDivisor(b, a % b)
if (a === 0) return b

while (b !== 0) {
const t = b
b = a % b
a = t
}
return a
}

function defaultFactory (origin, opts) {
Expand Down Expand Up @@ -16010,7 +16024,12 @@ class BalancedPool extends PoolBase {
}

_updateBalancedPoolStats () {
this[kGreatestCommonDivisor] = this[kClients].map(p => p[kWeight]).reduce(getGreatestCommonDivisor, 0)
let result = 0
for (let i = 0; i < this[kClients].length; i++) {
result = getGreatestCommonDivisor(this[kClients][i][kWeight], result)
}

this[kGreatestCommonDivisor] = result
}

removeUpstream (upstream) {
Expand Down Expand Up @@ -25197,12 +25216,25 @@ const { kState } = __nccwpck_require__(749)
const { webidl } = __nccwpck_require__(4890)
const { Blob } = __nccwpck_require__(2254)
const assert = __nccwpck_require__(8061)
const { isErrored } = __nccwpck_require__(3983)
const { isErrored, isDisturbed } = __nccwpck_require__(4492)
const { isArrayBuffer } = __nccwpck_require__(3746)
const { serializeAMimeType } = __nccwpck_require__(7704)
const { multipartFormDataParser } = __nccwpck_require__(7991)

const textEncoder = new TextEncoder()
function noop () {}

const hasFinalizationRegistry = globalThis.FinalizationRegistry && process.version.indexOf('v18') !== 0
let streamRegistry

if (hasFinalizationRegistry) {
streamRegistry = new FinalizationRegistry((weakRef) => {
const stream = weakRef.deref()
if (stream && !stream.locked && !isDisturbed(stream) && !isErrored(stream)) {
stream.cancel('Response object has been garbage collected').catch(noop)
}
})
}

// https://fetch.spec.whatwg.org/#concept-bodyinit-extract
function extractBody (object, keepalive = false) {
Expand Down Expand Up @@ -25445,14 +25477,18 @@ function safelyExtractBody (object, keepalive = false) {
return extractBody(object, keepalive)
}

function cloneBody (body) {
function cloneBody (instance, body) {
// To clone a body body, run these steps:

// https://fetch.spec.whatwg.org/#concept-body-clone

// 1. Let « out1, out2 » be the result of teeing body’s stream.
const [out1, out2] = body.stream.tee()

if (hasFinalizationRegistry) {
streamRegistry.register(instance, new WeakRef(out1))
}

// 2. Set body’s stream to out1.
body.stream = out1

Expand Down Expand Up @@ -25595,7 +25631,7 @@ async function consumeBody (object, convertBytesToJSValue, instance) {

// 1. If object is unusable, then return a promise rejected
// with a TypeError.
if (bodyUnusable(object[kState].body)) {
if (bodyUnusable(object)) {
throw new TypeError('Body is unusable: Body has already been read')
}

Expand Down Expand Up @@ -25635,7 +25671,9 @@ async function consumeBody (object, convertBytesToJSValue, instance) {
}

// https://fetch.spec.whatwg.org/#body-unusable
function bodyUnusable (body) {
function bodyUnusable (object) {
const body = object[kState].body

// An object including the Body interface mixin is
// said to be unusable if its body is non-null and
// its body’s stream is disturbed or locked.
Expand Down Expand Up @@ -25677,7 +25715,10 @@ module.exports = {
extractBody,
safelyExtractBody,
cloneBody,
mixinBody
mixinBody,
streamRegistry,
hasFinalizationRegistry,
bodyUnusable
}


Expand Down Expand Up @@ -30487,7 +30528,7 @@ module.exports = {



const { extractBody, mixinBody, cloneBody } = __nccwpck_require__(6682)
const { extractBody, mixinBody, cloneBody, bodyUnusable } = __nccwpck_require__(6682)
const { Headers, fill: fillHeaders, HeadersList, setHeadersGuard, getHeadersGuard, setHeadersList, getHeadersList } = __nccwpck_require__(2991)
const { FinalizationRegistry } = __nccwpck_require__(1922)()
const util = __nccwpck_require__(3983)
Expand Down Expand Up @@ -31042,7 +31083,7 @@ class Request {
// 40. If initBody is null and inputBody is non-null, then:
if (initBody == null && inputBody != null) {
// 1. If input is unusable, then throw a TypeError.
if (util.isDisturbed(inputBody.stream) || inputBody.stream.locked) {
if (bodyUnusable(input)) {
throw new TypeError(
'Cannot construct a Request with a Request object that has already been used.'
)
Expand Down Expand Up @@ -31244,7 +31285,7 @@ class Request {
webidl.brandCheck(this, Request)

// 1. If this is unusable, then throw a TypeError.
if (this.bodyUsed || this.body?.locked) {
if (bodyUnusable(this)) {
throw new TypeError('unusable')
}

Expand Down Expand Up @@ -31362,7 +31403,7 @@ function cloneRequest (request) {
// 2. If request’s body is non-null, set newRequest’s body to the
// result of cloning request’s body.
if (request.body != null) {
newRequest.body = cloneBody(request.body)
newRequest.body = cloneBody(newRequest, request.body)
}

// 3. Return newRequest.
Expand Down Expand Up @@ -31530,7 +31571,7 @@ module.exports = { Request, makeRequest, fromInnerRequest, cloneRequest }


const { Headers, HeadersList, fill, getHeadersGuard, setHeadersGuard, setHeadersList } = __nccwpck_require__(2991)
const { extractBody, cloneBody, mixinBody } = __nccwpck_require__(6682)
const { extractBody, cloneBody, mixinBody, hasFinalizationRegistry, streamRegistry, bodyUnusable } = __nccwpck_require__(6682)
const util = __nccwpck_require__(3983)
const nodeUtil = __nccwpck_require__(7261)
const { kEnumerableProperty } = util
Expand All @@ -31555,24 +31596,9 @@ const { URLSerializer } = __nccwpck_require__(7704)
const { kConstruct } = __nccwpck_require__(2785)
const assert = __nccwpck_require__(8061)
const { types } = __nccwpck_require__(7261)
const { isDisturbed, isErrored } = __nccwpck_require__(4492)

const textEncoder = new TextEncoder('utf-8')

const hasFinalizationRegistry = globalThis.FinalizationRegistry && process.version.indexOf('v18') !== 0
let registry

if (hasFinalizationRegistry) {
registry = new FinalizationRegistry((weakRef) => {
const stream = weakRef.deref()
if (stream && !stream.locked && !isDisturbed(stream) && !isErrored(stream)) {
stream.cancel('Response object has been garbage collected').catch(noop)
}
})
}

function noop () {}

// https://fetch.spec.whatwg.org/#response-class
class Response {
// Creates network error Response.
Expand Down Expand Up @@ -31773,7 +31799,7 @@ class Response {
webidl.brandCheck(this, Response)

// 1. If this is unusable, then throw a TypeError.
if (this.bodyUsed || this.body?.locked) {
if (bodyUnusable(this)) {
throw webidl.errors.exception({
header: 'Response.clone',
message: 'Body has already been consumed.'
Expand Down Expand Up @@ -31856,7 +31882,7 @@ function cloneResponse (response) {
// 3. If response’s body is non-null, then set newResponse’s body to the
// result of cloning response’s body.
if (response.body != null) {
newResponse.body = cloneBody(response.body)
newResponse.body = cloneBody(newResponse, response.body)
}

// 4. Return newResponse.
Expand Down Expand Up @@ -32061,7 +32087,7 @@ function fromInnerResponse (innerResponse, guard) {
// a primitive or an object, even undefined. If the held value is an object, the registry keeps
// a strong reference to it (so it can pass it to the cleanup callback later). Reworded from
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry
registry.register(response, new WeakRef(innerResponse.body.stream))
streamRegistry.register(response, new WeakRef(innerResponse.body.stream))
}

return response
Expand Down

0 comments on commit 00897e0

Please sign in to comment.