Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ graph LR;
debug-->ms;
fdir-->picomatch;
fs-minipass-->minipass;
gar-promise-retry-->retry;
glob-->minimatch;
glob-->minipass;
glob-->path-scurry;
Expand Down Expand Up @@ -673,8 +672,6 @@ graph LR;
path-scurry-->minipass;
postcss-selector-parser-->cssesc;
postcss-selector-parser-->util-deprecate;
promise-retry-->err-code;
promise-retry-->retry;
promzard-->read;
read-->mute-stream;
sigstore-->sigstore-bundle["@sigstore/bundle"];
Expand All @@ -684,9 +681,9 @@ graph LR;
sigstore-->sigstore-tuf["@sigstore/tuf"];
sigstore-->sigstore-verify["@sigstore/verify"];
sigstore-bundle-->sigstore-protobuf-specs["@sigstore/protobuf-specs"];
sigstore-sign-->gar-promise-retry["@gar/promise-retry"];
sigstore-sign-->make-fetch-happen;
sigstore-sign-->proc-log;
sigstore-sign-->promise-retry;
sigstore-sign-->sigstore-bundle["@sigstore/bundle"];
sigstore-sign-->sigstore-core["@sigstore/core"];
sigstore-sign-->sigstore-protobuf-specs["@sigstore/protobuf-specs"];
Expand Down
6 changes: 0 additions & 6 deletions node_modules/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
!/@gar/
/@gar/*
!/@gar/promise-retry
!/@gar/promise-retry/node_modules/
/@gar/promise-retry/node_modules/*
!/@gar/promise-retry/node_modules/retry
!/@isaacs/
/@isaacs/*
!/@isaacs/fs-minipass
Expand Down Expand Up @@ -59,7 +56,6 @@
!/debug
!/diff
!/env-paths
!/err-code
!/exponential-backoff
!/fastest-levenshtein
!/fs-minipass
Expand Down Expand Up @@ -123,12 +119,10 @@
!/proggy
!/promise-all-reject-late
!/promise-call-limit
!/promise-retry
!/promzard
!/qrcode-terminal
!/read-cmd-shim
!/read
!/retry
!/safer-buffer
!/semver
!/signal-exit
Expand Down
1 change: 1 addition & 0 deletions node_modules/@gar/promise-retry/LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Copyright (c) 2011 Tim Koschützki (tim@debuggable.com), Felix Geisendörfer (felix@debuggable.com)
Copyright (c) 2014 IndigoUnited

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
52 changes: 43 additions & 9 deletions node_modules/@gar/promise-retry/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,44 @@
const retry = require('retry')
const { RetryOperation } = require('./retry')

const isRetryError = (err) => err?.code === 'EPROMISERETRY' && Object.hasOwn(err, 'retried')
const createTimeout = (attempt, opts) => Math.min(Math.round((1 + (opts.randomize ? Math.random() : 0)) * Math.max(opts.minTimeout, 1) * Math.pow(opts.factor, attempt)), opts.maxTimeout)
const isRetryError = err => err?.code === 'EPROMISERETRY' && Object.hasOwn(err, 'retried')

async function promiseRetry (fn, options = {}) {
const operation = retry.operation(options)
const promiseRetry = async (fn, options = {}) => {
let timeouts = []
if (options instanceof Array) {
timeouts = [...options]
} else {
if (options.retries === Infinity) {
options.forever = true
delete options.retries
}
const opts = {
retries: 10,
factor: 2,
minTimeout: 1 * 1000,
maxTimeout: Infinity,
randomize: false,
...options
}
if (opts.minTimeout > opts.maxTimeout) {
throw new Error('minTimeout is greater than maxTimeout')
}
if (opts.retries) {
for (let i = 0; i < opts.retries; i++) {
timeouts.push(createTimeout(i, opts))
}
// sort the array numerically ascending (since the timeouts may be out of order at factor < 1)
timeouts.sort((a, b) => a - b)
} else if (options.forever) {
timeouts.push(createTimeout(0, opts))
}
}

const operation = new RetryOperation(timeouts, {
forever: options.forever,
unref: options.unref,
maxRetryTime: options.maxRetryTime
})

return new Promise(function (resolve, reject) {
operation.attempt(async number => {
Expand All @@ -13,13 +48,12 @@ async function promiseRetry (fn, options = {}) {
}, number, operation)
return resolve(result)
} catch (err) {
if (isRetryError(err)) {
if (operation.retry(err.retried || new Error())) {
return
}
if (!isRetryError(err)) {
return reject(err)
}
if (!operation.retry(err.retried || new Error())) {
return reject(err.retried)
}
return reject(err)
}
})
})
Expand Down
109 changes: 109 additions & 0 deletions node_modules/@gar/promise-retry/lib/retry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
class RetryOperation {
#attempts = 1
#cachedTimeouts = null
#errors = []
#fn = null
#maxRetryTime
#operationStart = null
#originalTimeouts
#timeouts
#timer = null
#unref

constructor (timeouts, options = {}) {
this.#originalTimeouts = [...timeouts]
this.#timeouts = [...timeouts]
this.#unref = options.unref
this.#maxRetryTime = options.maxRetryTime || Infinity
if (options.forever) {
this.#cachedTimeouts = [...this.#timeouts]
}
}

get timeouts () {
return [...this.#timeouts]
}

get errors () {
return [...this.#errors]
}

get attempts () {
return this.#attempts
}

get mainError () {
let mainError = null
if (this.#errors.length) {
let mainErrorCount = 0
const counts = {}
for (let i = 0; i < this.#errors.length; i++) {
const error = this.#errors[i]
const { message } = error
if (!counts[message]) {
counts[message] = 0
}
counts[message]++

if (counts[message] >= mainErrorCount) {
mainError = error
mainErrorCount = counts[message]
}
}
}
return mainError
}

reset () {
this.#attempts = 1
this.#timeouts = [...this.#originalTimeouts]
}

stop () {
if (this.#timer) {
clearTimeout(this.#timer)
}

this.#timeouts = []
this.#cachedTimeouts = null
}

retry (err) {
this.#errors.push(err)
if (new Date().getTime() - this.#operationStart >= this.#maxRetryTime) {
// XXX This puts the timeout error first, meaning it will never show as mainError, there may be no way to ever see this
this.#errors.unshift(new Error('RetryOperation timeout occurred'))
return false
}

let timeout = this.#timeouts.shift()
if (timeout === undefined) {
// We're out of timeouts, clear the last error and repeat the final timeout
if (this.#cachedTimeouts) {
this.#errors.pop()
timeout = this.#cachedTimeouts.at(-1)
} else {
return false
}
}

// TODO what if there already is a timer?
this.#timer = setTimeout(() => {
this.#attempts++
this.#fn(this.#attempts)
}, timeout)

if (this.#unref) {
this.#timer.unref()
}

return true
}

attempt (fn) {
this.#fn = fn
this.#operationStart = new Date().getTime()
this.#fn(this.#attempts)
}
}
module.exports = { RetryOperation }
21 changes: 0 additions & 21 deletions node_modules/@gar/promise-retry/node_modules/retry/License

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading