hide-a-bed 5.1.0 → 5.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/impl/retry.cjs +7 -6
- package/impl/retry.mjs +9 -9
- package/index.mjs +7 -7
- package/package.json +1 -1
- package/schema/bind.d.mts.map +1 -1
- package/schema/bind.mjs +2 -2
package/cjs/impl/retry.cjs
CHANGED
|
@@ -28,27 +28,28 @@ function withRetry(fn, options = {}) {
|
|
|
28
28
|
maxRetries = 3,
|
|
29
29
|
initialDelay = 1e3,
|
|
30
30
|
// 1 second
|
|
31
|
-
backoffFactor = 2
|
|
31
|
+
backoffFactor = 2,
|
|
32
32
|
// exponential backoff multiplier
|
|
33
|
+
maxDelay = 3e4
|
|
34
|
+
// 30 seconds max delay
|
|
33
35
|
} = options;
|
|
34
36
|
return async (...args) => {
|
|
35
|
-
let lastError;
|
|
36
37
|
let delay = initialDelay;
|
|
37
38
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
38
39
|
try {
|
|
39
|
-
|
|
40
|
+
const result = await fn(...args);
|
|
41
|
+
return result;
|
|
40
42
|
} catch (error) {
|
|
41
|
-
lastError = error;
|
|
42
43
|
if (!(error instanceof import_errors.RetryableError)) {
|
|
43
44
|
throw error;
|
|
44
45
|
}
|
|
45
46
|
if (attempt === maxRetries) {
|
|
46
47
|
throw error;
|
|
47
48
|
}
|
|
48
|
-
|
|
49
|
+
const nextDelay = Math.min(delay, maxDelay);
|
|
50
|
+
await (0, import_patch.sleep)(nextDelay);
|
|
49
51
|
delay *= backoffFactor;
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
|
-
throw lastError;
|
|
53
54
|
};
|
|
54
55
|
}
|
package/impl/retry.mjs
CHANGED
|
@@ -5,35 +5,35 @@ export function withRetry (fn, options = {}) {
|
|
|
5
5
|
const {
|
|
6
6
|
maxRetries = 3,
|
|
7
7
|
initialDelay = 1000, // 1 second
|
|
8
|
-
backoffFactor = 2 // exponential backoff multiplier
|
|
8
|
+
backoffFactor = 2, // exponential backoff multiplier
|
|
9
|
+
maxDelay = 30000 // 30 seconds max delay
|
|
9
10
|
} = options
|
|
10
11
|
|
|
11
12
|
return async (...args) => {
|
|
12
|
-
let lastError
|
|
13
13
|
let delay = initialDelay
|
|
14
14
|
|
|
15
15
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
16
16
|
try {
|
|
17
|
-
|
|
17
|
+
// Clear any references to previous attempts
|
|
18
|
+
const result = await fn(...args)
|
|
19
|
+
return result
|
|
18
20
|
} catch (error) {
|
|
19
|
-
lastError = error
|
|
20
|
-
|
|
21
21
|
// Only retry if it's a RetryableError
|
|
22
22
|
if (!(error instanceof RetryableError)) {
|
|
23
23
|
throw error
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
// If we've used all retries, throw the
|
|
26
|
+
// If we've used all retries, throw the error
|
|
27
27
|
if (attempt === maxRetries) {
|
|
28
28
|
throw error
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
// Calculate next delay with a maximum cap
|
|
32
|
+
const nextDelay = Math.min(delay, maxDelay)
|
|
31
33
|
// Wait with exponential backoff
|
|
32
|
-
await sleep(
|
|
34
|
+
await sleep(nextDelay)
|
|
33
35
|
delay *= backoffFactor
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
|
-
|
|
37
|
-
throw lastError
|
|
38
38
|
}
|
|
39
39
|
}
|
package/index.mjs
CHANGED
|
@@ -48,17 +48,17 @@ const schema = {
|
|
|
48
48
|
ChangesOptions,
|
|
49
49
|
ChangesResponse
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
/**
|
|
52
52
|
* @param {import('./schema/config.mjs').CouchConfigSchema } config
|
|
53
53
|
*/
|
|
54
|
-
function doBind(config) {
|
|
54
|
+
function doBind (config) {
|
|
55
55
|
// Default retry options
|
|
56
56
|
const retryOptions = {
|
|
57
57
|
maxRetries: config.maxRetries ?? 10,
|
|
58
58
|
initialDelay: config.initialDelay ?? 1000,
|
|
59
59
|
backoffFactor: config.backoffFactor ?? 2
|
|
60
60
|
}
|
|
61
|
-
|
|
61
|
+
|
|
62
62
|
// Create the object without the config property first
|
|
63
63
|
const result = {
|
|
64
64
|
get: config.bindWithRetry ? withRetry(get.bind(null, config), retryOptions) : get.bind(null, config),
|
|
@@ -79,8 +79,8 @@ function doBind(config) {
|
|
|
79
79
|
watchDocs: watchDocs.bind(null, config),
|
|
80
80
|
changes: changes.bind(null, config)
|
|
81
81
|
}
|
|
82
|
-
|
|
83
|
-
return result
|
|
82
|
+
|
|
83
|
+
return result
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
/** @type { import('./schema/bind.mjs').BindSchema } */
|
|
@@ -92,7 +92,7 @@ const bindConfig = Bind.implement((
|
|
|
92
92
|
|
|
93
93
|
/** @type { import('./schema/bind.mjs').BindBaseSchema } funcs */
|
|
94
94
|
const funcs = doBind(parsedConfig)
|
|
95
|
-
|
|
95
|
+
|
|
96
96
|
// Add the options function that returns a new bound instance
|
|
97
97
|
// this allows the user to override some options
|
|
98
98
|
const reconfig = (
|
|
@@ -103,7 +103,7 @@ const bindConfig = Bind.implement((
|
|
|
103
103
|
const newConfig = { ...config, ..._overrides }
|
|
104
104
|
return bindConfig(newConfig)
|
|
105
105
|
}
|
|
106
|
-
|
|
106
|
+
/** @type { import('./schema/bind.mjs').BindReturnsSchema } */
|
|
107
107
|
const all = { ...funcs, options: reconfig }
|
|
108
108
|
return all
|
|
109
109
|
})
|
package/package.json
CHANGED
package/schema/bind.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bind.d.mts","sourceRoot":"","sources":["bind.mjs"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,KAAK,CAAC,OAAO,IAAI,CAAC;kBAvCjB,KAAK"}
|
package/schema/bind.mjs
CHANGED
|
@@ -32,8 +32,8 @@ export const BindBase = z.object({
|
|
|
32
32
|
const RebindOptions = CouchConfig.omit({ couch: true })
|
|
33
33
|
|
|
34
34
|
// Define a recursive type where config returns the same type
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
export const BindReturns = BindBase.extend({
|
|
36
|
+
options: z.function().args(RebindOptions).returns(BindBase)
|
|
37
37
|
})
|
|
38
38
|
/** @typedef { z.infer<typeof BindReturns> } BindReturnsSchema */
|
|
39
39
|
|