hide-a-bed 5.1.0 → 5.1.1
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/impl/retry.mjs +19 -9
- package/index.mjs +7 -7
- package/log.txt +43 -0
- package/package.json +1 -1
- package/schema/bind.mjs +2 -2
package/impl/retry.mjs
CHANGED
|
@@ -1,39 +1,49 @@
|
|
|
1
1
|
import { RetryableError } from './errors.mjs'
|
|
2
2
|
import { sleep } from './patch.mjs'
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Wraps a function with retry logic for RetryableError instances
|
|
6
|
+
* @param {Function} fn - The function to retry
|
|
7
|
+
* @param {Object} options - Retry options
|
|
8
|
+
* @param {number} [options.maxRetries=3] - Maximum number of retry attempts
|
|
9
|
+
* @param {number} [options.initialDelay=1000] - Initial delay in ms
|
|
10
|
+
* @param {number} [options.backoffFactor=2] - Multiplier for exponential backoff
|
|
11
|
+
* @param {number} [options.maxDelay] - Maximum delay between retries in ms
|
|
12
|
+
* @returns {Function} - Wrapped function with retry logic
|
|
13
|
+
*/
|
|
4
14
|
export function withRetry (fn, options = {}) {
|
|
5
15
|
const {
|
|
6
16
|
maxRetries = 3,
|
|
7
17
|
initialDelay = 1000, // 1 second
|
|
8
|
-
backoffFactor = 2 // exponential backoff multiplier
|
|
18
|
+
backoffFactor = 2, // exponential backoff multiplier
|
|
19
|
+
maxDelay = 30000 // 30 seconds max delay
|
|
9
20
|
} = options
|
|
10
21
|
|
|
11
22
|
return async (...args) => {
|
|
12
|
-
let lastError
|
|
13
23
|
let delay = initialDelay
|
|
14
24
|
|
|
15
25
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
16
26
|
try {
|
|
17
|
-
|
|
27
|
+
// Clear any references to previous attempts
|
|
28
|
+
const result = await fn(...args)
|
|
29
|
+
return result
|
|
18
30
|
} catch (error) {
|
|
19
|
-
lastError = error
|
|
20
|
-
|
|
21
31
|
// Only retry if it's a RetryableError
|
|
22
32
|
if (!(error instanceof RetryableError)) {
|
|
23
33
|
throw error
|
|
24
34
|
}
|
|
25
35
|
|
|
26
|
-
// If we've used all retries, throw the
|
|
36
|
+
// If we've used all retries, throw the error
|
|
27
37
|
if (attempt === maxRetries) {
|
|
28
38
|
throw error
|
|
29
39
|
}
|
|
30
40
|
|
|
41
|
+
// Calculate next delay with a maximum cap
|
|
42
|
+
const nextDelay = Math.min(delay, maxDelay)
|
|
31
43
|
// Wait with exponential backoff
|
|
32
|
-
await sleep(
|
|
44
|
+
await sleep(nextDelay)
|
|
33
45
|
delay *= backoffFactor
|
|
34
46
|
}
|
|
35
47
|
}
|
|
36
|
-
|
|
37
|
-
throw lastError
|
|
38
48
|
}
|
|
39
49
|
}
|
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/log.txt
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[Wed, 12 Mar 2025 14:28:53 GMT] [info] [<0.000.0>] pouchdb-server has started on http://127.0.0.1:8985/
|
|
2
|
+
[Wed, 12 Mar 2025 14:28:53 GMT] [info] [<0.000.0>] database is in-memory; no changes will be saved.
|
|
3
|
+
[Wed, 12 Mar 2025 14:28:53 GMT] [info] [<0.000.0>] navigate to http://127.0.0.1:8985/_utils for the Fauxton UI.
|
|
4
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - PUT /testdb 201
|
|
5
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - PUT /testdb/testdoc 201
|
|
6
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - GET /testdb/testdoc 200
|
|
7
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - GET /testdb/testdoc-not-there 404
|
|
8
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - GET /testdb/testdoc-not-there-override 404
|
|
9
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - GET /testdb/testdoc-not-there 404
|
|
10
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - PUT /testdb/notThereDoc 409
|
|
11
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - POST /testdb/_all_docs?include_docs=true 200
|
|
12
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - PUT /testdb/txn:fsda 201
|
|
13
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - POST /testdb/_all_docs?include_docs=true 200
|
|
14
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - POST /testdb/_bulk_docs 201
|
|
15
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - PUT /testdb/txn:fsda 201
|
|
16
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - PUT /testdb/txn:fsda-1 201
|
|
17
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - POST /testdb/_all_docs?include_docs=true 200
|
|
18
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - PUT /testdb/txn:fsda-2 201
|
|
19
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - POST /testdb/_all_docs?include_docs=true 200
|
|
20
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - POST /testdb/_bulk_docs 201
|
|
21
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - PUT /testdb/txn:fsda-2 201
|
|
22
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - PUT /testdb/txn:fsda-3 201
|
|
23
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - POST /testdb/_all_docs?include_docs=true 200
|
|
24
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - PUT /testdb/a 201
|
|
25
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - POST /testdb/_bulk_docs 201
|
|
26
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - POST /testdb/_bulk_docs 201
|
|
27
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - PUT /testdb/txn:fsda-3 201
|
|
28
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - POST /testdb/_all_docs?include_docs=true 200
|
|
29
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - PUT /testdb/conflict-test 201
|
|
30
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - PUT /testdb/txn:conflict-error 201
|
|
31
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - POST /testdb/_all_docs?include_docs=true 200
|
|
32
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - PUT /testdb/txn:bulk-error 201
|
|
33
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - POST /testdb/_all_docs?include_docs=true 200
|
|
34
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - PUT /testdb/lock-doc-to-lock 201
|
|
35
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - GET /testdb/lock-doc-to-lock 200
|
|
36
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - PUT /testdb/lock-doc-to-lock 409
|
|
37
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - GET /testdb/lock-doc-to-lock 200
|
|
38
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - PUT /testdb/lock-doc-to-lock 201
|
|
39
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - GET /testdb/lock-doc-to-lock 404
|
|
40
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - PUT /testdb/lock-doc-to-lock 201
|
|
41
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - GET /testdb/lock-doc-to-lock 200
|
|
42
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - GET /testdb/lock-doc-to-lock 200
|
|
43
|
+
[Wed, 12 Mar 2025 14:28:54 GMT] [info] [<0.000.0>] 127.0.0.1 - - GET /testdb/lock-doc-to-lock-2 404
|
package/package.json
CHANGED
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
|
|