hide-a-bed 7.1.0 → 7.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/README.md +148 -156
- package/impl/bindConfig.mts +62 -69
- package/impl/headDB.mts +28 -28
- package/impl/utils/errors.mts +159 -189
- package/impl/utils/fetch.mts +94 -102
- package/index.mts +42 -55
- package/package.json +2 -2
- package/types/output/impl/bindConfig.d.mts +15 -15
- package/types/output/impl/bindConfig.d.mts.map +1 -1
- package/types/output/impl/headDB.d.mts +1 -1
- package/types/output/impl/headDB.d.mts.map +1 -1
- package/types/output/impl/utils/errors.d.mts +12 -12
- package/types/output/impl/utils/errors.d.mts.map +1 -1
- package/types/output/impl/utils/fetch.d.mts +4 -4
- package/types/output/impl/utils/fetch.d.mts.map +1 -1
- package/types/output/index.d.mts +35 -35
- package/types/output/index.d.mts.map +1 -1
package/README.md
CHANGED
|
@@ -49,25 +49,25 @@ If your CouchDB requires basic auth, pass `auth` on the config:
|
|
|
49
49
|
|
|
50
50
|
```javascript
|
|
51
51
|
const config = {
|
|
52
|
-
couch:
|
|
52
|
+
couch: 'https://the.couch.url.com:5984/mydb',
|
|
53
53
|
auth: {
|
|
54
54
|
username: process.env.COUCHDB_USER,
|
|
55
|
-
password: process.env.COUCHDB_PASSWORD
|
|
56
|
-
}
|
|
57
|
-
}
|
|
55
|
+
password: process.env.COUCHDB_PASSWORD
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
58
|
```
|
|
59
59
|
|
|
60
60
|
You can also set default request controls on the config:
|
|
61
61
|
|
|
62
62
|
```javascript
|
|
63
63
|
const config = {
|
|
64
|
-
couch:
|
|
64
|
+
couch: 'https://the.couch.url.com:5984/mydb',
|
|
65
65
|
request: {
|
|
66
66
|
timeout: 5000,
|
|
67
67
|
signal: abortController.signal,
|
|
68
|
-
dispatcher
|
|
69
|
-
}
|
|
70
|
-
}
|
|
68
|
+
dispatcher
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
71
|
```
|
|
72
72
|
|
|
73
73
|
See [Advanced Config Options](#advanced-config-options) for more advanced settings.
|
|
@@ -114,19 +114,19 @@ Get a single document by ID.
|
|
|
114
114
|
- Throws: `NotFoundError` when the document does not exist and `throwOnGetNotFound` is true
|
|
115
115
|
|
|
116
116
|
```javascript
|
|
117
|
-
const config = { couch:
|
|
118
|
-
const doc = await get(config,
|
|
119
|
-
console.log(doc._id, doc._rev)
|
|
117
|
+
const config = { couch: 'http://localhost:5984/mydb' }
|
|
118
|
+
const doc = await get(config, 'doc-123')
|
|
119
|
+
console.log(doc._id, doc._rev)
|
|
120
120
|
|
|
121
|
-
const missing = await get(config,
|
|
122
|
-
console.log(missing)
|
|
121
|
+
const missing = await get(config, 'notFound')
|
|
122
|
+
console.log(missing) // null
|
|
123
123
|
|
|
124
124
|
try {
|
|
125
|
-
await get({ ...config, throwOnGetNotFound: true },
|
|
125
|
+
await get({ ...config, throwOnGetNotFound: true }, 'notFound')
|
|
126
126
|
} catch (err) {
|
|
127
|
-
if (err.name ===
|
|
128
|
-
console.log(err.statusCode)
|
|
129
|
-
console.log(err.docId)
|
|
127
|
+
if (err.name === 'NotFoundError') {
|
|
128
|
+
console.log(err.statusCode) // 404
|
|
129
|
+
console.log(err.docId) // notFound
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
```
|
|
@@ -143,21 +143,21 @@ Save a document.
|
|
|
143
143
|
- Throws: `ConflictError` when CouchDB returns a 409 for a single-document write
|
|
144
144
|
|
|
145
145
|
```javascript
|
|
146
|
-
const config = { couch:
|
|
146
|
+
const config = { couch: 'http://localhost:5984/mydb' }
|
|
147
147
|
const doc = {
|
|
148
|
-
_id:
|
|
149
|
-
type:
|
|
150
|
-
name:
|
|
151
|
-
}
|
|
152
|
-
const result = await put(config, doc)
|
|
148
|
+
_id: 'doc-123',
|
|
149
|
+
type: 'user',
|
|
150
|
+
name: 'Alice'
|
|
151
|
+
}
|
|
152
|
+
const result = await put(config, doc)
|
|
153
153
|
// result: { ok: true, id: 'doc-123', rev: '1-abc123' }
|
|
154
154
|
|
|
155
155
|
try {
|
|
156
|
-
await put(config, { _id:
|
|
156
|
+
await put(config, { _id: 'notThereDoc', _rev: '32-does-not-compute' })
|
|
157
157
|
} catch (err) {
|
|
158
|
-
if (err.name ===
|
|
159
|
-
console.log(err.statusCode)
|
|
160
|
-
console.log(err.docId)
|
|
158
|
+
if (err.name === 'ConflictError') {
|
|
159
|
+
console.log(err.statusCode) // 409
|
|
160
|
+
console.log(err.docId) // notThereDoc
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
```
|
|
@@ -175,15 +175,15 @@ The patch function lets you update specific properties of a document. The \_rev
|
|
|
175
175
|
|
|
176
176
|
```javascript
|
|
177
177
|
const config = {
|
|
178
|
-
couch:
|
|
179
|
-
retries: 3
|
|
180
|
-
}
|
|
178
|
+
couch: 'http://localhost:5984/mydb',
|
|
179
|
+
retries: 3
|
|
180
|
+
}
|
|
181
181
|
const properties = {
|
|
182
|
-
_rev:
|
|
183
|
-
name:
|
|
184
|
-
updated: true
|
|
185
|
-
}
|
|
186
|
-
const result = await patch(config,
|
|
182
|
+
_rev: '3-fdskjhfsdkjhfsd',
|
|
183
|
+
name: 'Alice Smith',
|
|
184
|
+
updated: true
|
|
185
|
+
}
|
|
186
|
+
const result = await patch(config, 'doc-123', properties)
|
|
187
187
|
// result: { ok: true, id: 'doc-123', rev: '2-xyz789' }
|
|
188
188
|
```
|
|
189
189
|
|
|
@@ -205,14 +205,14 @@ _Warning_: patchDangerously can clobber data. It will retry even if a conflict h
|
|
|
205
205
|
|
|
206
206
|
```javascript
|
|
207
207
|
const config = {
|
|
208
|
-
couch:
|
|
209
|
-
retries: 3
|
|
210
|
-
}
|
|
208
|
+
couch: 'http://localhost:5984/mydb',
|
|
209
|
+
retries: 3
|
|
210
|
+
}
|
|
211
211
|
const properties = {
|
|
212
|
-
name:
|
|
213
|
-
updated: true
|
|
214
|
-
}
|
|
215
|
-
const result = await patchDangerously(config,
|
|
212
|
+
name: 'Alice Smith',
|
|
213
|
+
updated: true
|
|
214
|
+
}
|
|
215
|
+
const result = await patchDangerously(config, 'doc-123', properties)
|
|
216
216
|
// result: { ok: true, id: 'doc-123', rev: '2-xyz789' }
|
|
217
217
|
```
|
|
218
218
|
|
|
@@ -229,9 +229,9 @@ Return a document at the rev specified.
|
|
|
229
229
|
_CouchDB_ is not a version control db. This is a special function for unique situations. The \_rev might not be around as couch cleans up old revs.
|
|
230
230
|
|
|
231
231
|
```javascript
|
|
232
|
-
const config = { couch:
|
|
233
|
-
const doc = await getAtRev(config,
|
|
234
|
-
console.log(doc._id, doc._rev)
|
|
232
|
+
const config = { couch: 'http://localhost:5984/mydb' }
|
|
233
|
+
const doc = await getAtRev(config, 'doc-123', '2-fsdjfsdakljfsajlksd')
|
|
234
|
+
console.log(doc._id, doc._rev)
|
|
235
235
|
```
|
|
236
236
|
|
|
237
237
|
#### createLock
|
|
@@ -267,17 +267,17 @@ Remove a lock from a document.
|
|
|
267
267
|
Only the user who created the lock can remove it.
|
|
268
268
|
|
|
269
269
|
```javascript
|
|
270
|
-
const config = { couch:
|
|
270
|
+
const config = { couch: 'http://localhost:5984/mydb' }
|
|
271
271
|
const options = {
|
|
272
272
|
enableLocking: true,
|
|
273
|
-
username:
|
|
274
|
-
}
|
|
273
|
+
username: 'alice'
|
|
274
|
+
}
|
|
275
275
|
|
|
276
|
-
const locked = await createLock(config,
|
|
276
|
+
const locked = await createLock(config, 'doc-123', options)
|
|
277
277
|
if (locked) {
|
|
278
278
|
// Document is now locked for exclusive access
|
|
279
279
|
// Perform your updates here
|
|
280
|
-
await removeLock(config,
|
|
280
|
+
await removeLock(config, 'doc-123', options)
|
|
281
281
|
}
|
|
282
282
|
// Lock is now removed if it existed and was owned by 'alice'
|
|
283
283
|
```
|
|
@@ -295,12 +295,12 @@ Save multiple documents in one request.
|
|
|
295
295
|
- Returns: Promise resolving to array of results with `ok`, `id`, `rev` for each doc
|
|
296
296
|
|
|
297
297
|
```javascript
|
|
298
|
-
const config = { couch:
|
|
298
|
+
const config = { couch: 'http://localhost:5984/mydb' }
|
|
299
299
|
const docs = [
|
|
300
|
-
{ _id:
|
|
301
|
-
{ _id:
|
|
302
|
-
]
|
|
303
|
-
const results = await bulkSave(config, docs)
|
|
300
|
+
{ _id: 'doc1', type: 'user', name: 'Alice' },
|
|
301
|
+
{ _id: 'doc2', type: 'user', name: 'Bob' }
|
|
302
|
+
]
|
|
303
|
+
const results = await bulkSave(config, docs)
|
|
304
304
|
// [
|
|
305
305
|
// { ok: true, id: 'doc1', rev: '1-abc123' },
|
|
306
306
|
// { ok: true, id: 'doc2', rev: '1-def456' }
|
|
@@ -322,17 +322,17 @@ Get multiple documents by ID.
|
|
|
322
322
|
Warning: documents that are not found will still have a row in the results. The doc property will be null, and the error property will be set.
|
|
323
323
|
|
|
324
324
|
```javascript
|
|
325
|
-
import z from
|
|
325
|
+
import z from 'zod'
|
|
326
326
|
|
|
327
|
-
const config = { couch:
|
|
328
|
-
const ids = [
|
|
327
|
+
const config = { couch: 'http://localhost:5984/mydb' }
|
|
328
|
+
const ids = ['doc1', 'doc2', 'doesNotExist']
|
|
329
329
|
const docs = await bulkGet(config, ids, {
|
|
330
330
|
docSchema: z.looseObject({
|
|
331
331
|
_id: z.string(),
|
|
332
332
|
type: z.string(),
|
|
333
|
-
name: z.string()
|
|
334
|
-
})
|
|
335
|
-
})
|
|
333
|
+
name: z.string()
|
|
334
|
+
})
|
|
335
|
+
})
|
|
336
336
|
// rows: [
|
|
337
337
|
// { id: 'doc1', doc: { _id: 'doc1', type: 'user', name: 'Alice' } },
|
|
338
338
|
// { id: 'doc2', doc: { _id: 'doc2', type: 'user', name: 'Bob' } },
|
|
@@ -352,9 +352,9 @@ Delete multiple documents in one request.
|
|
|
352
352
|
- Throws: `RetryableError` or `OperationError` only for request-level failures. Missing documents remain item-level outcomes.
|
|
353
353
|
|
|
354
354
|
```javascript
|
|
355
|
-
const config = { couch:
|
|
356
|
-
const ids = [
|
|
357
|
-
const results = await bulkRemove(config, ids)
|
|
355
|
+
const config = { couch: 'http://localhost:5984/mydb' }
|
|
356
|
+
const ids = ['doc1', 'doc2']
|
|
357
|
+
const results = await bulkRemove(config, ids)
|
|
358
358
|
// results: [
|
|
359
359
|
// { ok: true, id: 'doc1', rev: '2-ghi789' },
|
|
360
360
|
// { ok: true, id: 'doc2', rev: '2-jkl012' }
|
|
@@ -376,10 +376,10 @@ Allows more efficient deletion of document by providing only id and rev. This is
|
|
|
376
376
|
- Throws: `NotFoundError` when the document does not exist
|
|
377
377
|
|
|
378
378
|
```javascript
|
|
379
|
-
const config = { couch:
|
|
380
|
-
const id =
|
|
381
|
-
const rev =
|
|
382
|
-
const result = await remove(config, id, rev)
|
|
379
|
+
const config = { couch: 'http://localhost:5984/mydb' }
|
|
380
|
+
const id = 'doc1'
|
|
381
|
+
const rev = '2-ghi789'
|
|
382
|
+
const result = await remove(config, id, rev)
|
|
383
383
|
// result:
|
|
384
384
|
// { ok: true, id: 'doc1', rev: '2-ghi789' }
|
|
385
385
|
```
|
|
@@ -396,9 +396,9 @@ Delete multiple documents in one request. Same inputs and outputs as [bulkRemove
|
|
|
396
396
|
- Throws: `RetryableError` or `OperationError` only for request-level failures while deleting an item. Missing or otherwise unremovable items are skipped.
|
|
397
397
|
|
|
398
398
|
```javascript
|
|
399
|
-
const config = { couch:
|
|
400
|
-
const ids = [
|
|
401
|
-
const results = await bulkRemoveMap(config, ids)
|
|
399
|
+
const config = { couch: 'http://localhost:5984/mydb' }
|
|
400
|
+
const ids = ['doc1', 'doc2']
|
|
401
|
+
const results = await bulkRemoveMap(config, ids)
|
|
402
402
|
// results: [
|
|
403
403
|
// { ok: true, id: 'doc1', rev: '2-ghi789' },
|
|
404
404
|
// { ok: true, id: 'doc2', rev: '2-jkl012' }
|
|
@@ -435,16 +435,16 @@ _notFound_ looks like
|
|
|
435
435
|
```
|
|
436
436
|
|
|
437
437
|
```javascript
|
|
438
|
-
import z from
|
|
438
|
+
import z from 'zod'
|
|
439
439
|
|
|
440
|
-
const config = { couch:
|
|
441
|
-
const ids = [
|
|
440
|
+
const config = { couch: 'http://localhost:5984/mydb' }
|
|
441
|
+
const ids = ['doc1', 'doc2', 'doesNotExist']
|
|
442
442
|
const results = await bulkGetDictionary(config, ids, {
|
|
443
443
|
docSchema: z.looseObject({
|
|
444
444
|
_id: z.string(),
|
|
445
|
-
data: z.record(z.any())
|
|
446
|
-
})
|
|
447
|
-
})
|
|
445
|
+
data: z.record(z.any())
|
|
446
|
+
})
|
|
447
|
+
})
|
|
448
448
|
// results: {
|
|
449
449
|
// found: {
|
|
450
450
|
// doc1: { _id: 'doc2', _rev: '1-221', data: {} },
|
|
@@ -479,28 +479,28 @@ Exceptions to handle:
|
|
|
479
479
|
- `TransactionRollbackError`: Thrown if the rollback operation fails after a transaction failure.
|
|
480
480
|
|
|
481
481
|
```javascript
|
|
482
|
-
const config = { couch:
|
|
483
|
-
const transactionId =
|
|
482
|
+
const config = { couch: 'http://localhost:5984/mydb' }
|
|
483
|
+
const transactionId = 'txn-123'
|
|
484
484
|
const docs = [
|
|
485
|
-
{ _id:
|
|
486
|
-
{ _id:
|
|
487
|
-
]
|
|
485
|
+
{ _id: 'doc1', type: 'user', name: 'Alice', _rev: '1-abc123' },
|
|
486
|
+
{ _id: 'doc2', type: 'user', name: 'Bob', _rev: '1-def456' }
|
|
487
|
+
]
|
|
488
488
|
|
|
489
489
|
try {
|
|
490
|
-
const results = await bulkSaveTransaction(config, transactionId, docs)
|
|
491
|
-
console.log(
|
|
490
|
+
const results = await bulkSaveTransaction(config, transactionId, docs)
|
|
491
|
+
console.log('Transaction successful:', results)
|
|
492
492
|
} catch (error) {
|
|
493
493
|
if (error instanceof TransactionSetupError) {
|
|
494
494
|
// the transaction could not start - usually an existing transaction with the same id
|
|
495
|
-
console.error(
|
|
495
|
+
console.error('Transaction setup failed:', error)
|
|
496
496
|
} else if (error instanceof TransactionVersionConflictError) {
|
|
497
497
|
// one or more of the versions of the docs provided dont match with what is currently in the db
|
|
498
|
-
console.error(
|
|
498
|
+
console.error('Version conflict error:', error)
|
|
499
499
|
} else if (error instanceof TransactionRollbackError) {
|
|
500
500
|
// the transaction was rolled back - so the 'or none' condition occured
|
|
501
|
-
console.error(
|
|
501
|
+
console.error('Rollback error:', error)
|
|
502
502
|
} else {
|
|
503
|
-
console.error(
|
|
503
|
+
console.error('Unexpected error:', error)
|
|
504
504
|
}
|
|
505
505
|
}
|
|
506
506
|
```
|
|
@@ -523,11 +523,11 @@ const result = await getDBInfo({
|
|
|
523
523
|
Run a lightweight database health check using CouchDB's `HEAD /{db}` route.
|
|
524
524
|
|
|
525
525
|
```javascript
|
|
526
|
-
const config = { couch:
|
|
526
|
+
const config = { couch: 'http://localhost:5984/mydb' }
|
|
527
527
|
const healthy = await headDB({
|
|
528
528
|
...config,
|
|
529
|
-
request: { timeout: 2000 }
|
|
530
|
-
})
|
|
529
|
+
request: { timeout: 2000 }
|
|
530
|
+
})
|
|
531
531
|
// healthy: true
|
|
532
532
|
```
|
|
533
533
|
|
|
@@ -555,15 +555,15 @@ Query a view with options.
|
|
|
555
555
|
- Returns: Promise resolving to response with `rows` array
|
|
556
556
|
|
|
557
557
|
```javascript
|
|
558
|
-
const config = { couch:
|
|
559
|
-
const view =
|
|
558
|
+
const config = { couch: 'http://localhost:5984/mydb' }
|
|
559
|
+
const view = '_design/users/_view/by_name'
|
|
560
560
|
const options = {
|
|
561
|
-
startkey:
|
|
562
|
-
endkey:
|
|
561
|
+
startkey: 'A',
|
|
562
|
+
endkey: 'B',
|
|
563
563
|
include_docs: true,
|
|
564
|
-
limit: 10
|
|
565
|
-
}
|
|
566
|
-
const result = await query(config, view, options)
|
|
564
|
+
limit: 10
|
|
565
|
+
}
|
|
566
|
+
const result = await query(config, view, options)
|
|
567
567
|
// result: {
|
|
568
568
|
// rows: [
|
|
569
569
|
// {
|
|
@@ -602,14 +602,9 @@ Create a query builder to help construct view queries with a fluent interface. N
|
|
|
602
602
|
- `build()`: Return the constructed query options object
|
|
603
603
|
|
|
604
604
|
```javascript
|
|
605
|
-
const options = createQuery()
|
|
606
|
-
.startkey("A")
|
|
607
|
-
.endkey("B")
|
|
608
|
-
.include_docs(true)
|
|
609
|
-
.limit(10)
|
|
610
|
-
.build();
|
|
605
|
+
const options = createQuery().startkey('A').endkey('B').include_docs(true).limit(10).build()
|
|
611
606
|
|
|
612
|
-
const result = await query(config, view, options)
|
|
607
|
+
const result = await query(config, view, options)
|
|
613
608
|
```
|
|
614
609
|
|
|
615
610
|
Again, use js types for array keys
|
|
@@ -675,22 +670,22 @@ npm install hide-a-bed-changes
|
|
|
675
670
|
Usage mirrors the original API:
|
|
676
671
|
|
|
677
672
|
```javascript
|
|
678
|
-
import { changes } from
|
|
673
|
+
import { changes } from 'hide-a-bed-changes'
|
|
679
674
|
|
|
680
|
-
const config = { couch:
|
|
675
|
+
const config = { couch: 'http://localhost:5984/mydb' }
|
|
681
676
|
|
|
682
677
|
const feed = await changes(
|
|
683
678
|
config,
|
|
684
|
-
|
|
685
|
-
console.log(
|
|
679
|
+
change => {
|
|
680
|
+
console.log('Document changed:', change.id)
|
|
686
681
|
},
|
|
687
|
-
{ since:
|
|
688
|
-
)
|
|
682
|
+
{ since: 'now', include_docs: true }
|
|
683
|
+
)
|
|
689
684
|
|
|
690
|
-
feed.on(
|
|
685
|
+
feed.on('error', console.error)
|
|
691
686
|
|
|
692
687
|
// later
|
|
693
|
-
feed.stop()
|
|
688
|
+
feed.stop()
|
|
694
689
|
```
|
|
695
690
|
|
|
696
691
|
`hide-a-bed-changes` reuses the same config structure and resolves `since: 'now'` to the current `update_seq` before starting the feed.
|
|
@@ -719,38 +714,38 @@ Returns an EventEmitter that emits:
|
|
|
719
714
|
- 'end' events with last sequence number.
|
|
720
715
|
|
|
721
716
|
```javascript
|
|
722
|
-
const config = { couch:
|
|
717
|
+
const config = { couch: 'http://localhost:5984/mydb' }
|
|
723
718
|
|
|
724
719
|
// Watch a single document
|
|
725
|
-
const feed = await watchDocs(config,
|
|
726
|
-
console.log(
|
|
727
|
-
console.log(
|
|
728
|
-
})
|
|
720
|
+
const feed = await watchDocs(config, 'doc123', change => {
|
|
721
|
+
console.log('Document changed:', change.id)
|
|
722
|
+
console.log('New revision:', change.changes[0].rev)
|
|
723
|
+
})
|
|
729
724
|
|
|
730
725
|
// Watch multiple documents with full doc content
|
|
731
726
|
const feed = await watchDocs(
|
|
732
727
|
config,
|
|
733
|
-
[
|
|
734
|
-
|
|
728
|
+
['doc1', 'doc2', 'doc3'],
|
|
729
|
+
change => {
|
|
735
730
|
if (change.doc) {
|
|
736
|
-
console.log(
|
|
731
|
+
console.log('Updated document:', change.doc)
|
|
737
732
|
}
|
|
738
733
|
},
|
|
739
|
-
{ include_docs: true }
|
|
740
|
-
)
|
|
734
|
+
{ include_docs: true }
|
|
735
|
+
)
|
|
741
736
|
|
|
742
737
|
// Handle errors
|
|
743
|
-
feed.on(
|
|
744
|
-
console.error(
|
|
745
|
-
})
|
|
738
|
+
feed.on('error', error => {
|
|
739
|
+
console.error('Watch error:', error)
|
|
740
|
+
})
|
|
746
741
|
|
|
747
742
|
// Handle end of feed
|
|
748
|
-
feed.on(
|
|
749
|
-
console.log(
|
|
750
|
-
})
|
|
743
|
+
feed.on('end', ({ lastSeq }) => {
|
|
744
|
+
console.log('Feed ended at sequence:', lastSeq)
|
|
745
|
+
})
|
|
751
746
|
|
|
752
747
|
// Stop watching
|
|
753
|
-
feed.stop()
|
|
748
|
+
feed.stop()
|
|
754
749
|
```
|
|
755
750
|
|
|
756
751
|
The watchDocs feed is useful for:
|
|
@@ -780,13 +775,13 @@ Example configuration with all options:
|
|
|
780
775
|
|
|
781
776
|
```javascript
|
|
782
777
|
const config = {
|
|
783
|
-
couch:
|
|
778
|
+
couch: 'http://localhost:5984/mydb',
|
|
784
779
|
auth: {
|
|
785
780
|
username: process.env.COUCHDB_USER,
|
|
786
|
-
password: process.env.COUCHDB_PASSWORD
|
|
781
|
+
password: process.env.COUCHDB_PASSWORD
|
|
787
782
|
},
|
|
788
783
|
request: {
|
|
789
|
-
timeout: 5000
|
|
784
|
+
timeout: 5000
|
|
790
785
|
},
|
|
791
786
|
throwOnGetNotFound: true,
|
|
792
787
|
bindWithRetry: true,
|
|
@@ -794,8 +789,8 @@ const config = {
|
|
|
794
789
|
initialDelay: 2000,
|
|
795
790
|
backoffFactor: 1.5,
|
|
796
791
|
useConsoleLogger: true,
|
|
797
|
-
logger: (level, ...args) => console.log(level, ...args)
|
|
798
|
-
}
|
|
792
|
+
logger: (level, ...args) => console.log(level, ...args)
|
|
793
|
+
}
|
|
799
794
|
```
|
|
800
795
|
|
|
801
796
|
`bindConfig()` and `withRetry()` now perform a single built-in retry for transient `401` and `403` responses before surfacing the error.
|
|
@@ -805,15 +800,12 @@ const config = {
|
|
|
805
800
|
`withRetry(fn, options)` wraps an async function and retries based on the built-in retry rules.
|
|
806
801
|
|
|
807
802
|
```javascript
|
|
808
|
-
import { withRetry, get } from
|
|
803
|
+
import { withRetry, get } from 'hide-a-bed'
|
|
809
804
|
|
|
810
|
-
const getWithCustomRetry = withRetry(
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
initialDelay: 250,
|
|
815
|
-
},
|
|
816
|
-
);
|
|
805
|
+
const getWithCustomRetry = withRetry(id => get({ couch: 'http://localhost:5984/mydb' }, id), {
|
|
806
|
+
maxRetries: 2,
|
|
807
|
+
initialDelay: 250
|
|
808
|
+
})
|
|
817
809
|
```
|
|
818
810
|
|
|
819
811
|
### Migration Note
|
|
@@ -831,26 +823,26 @@ The library supports flexible logging options that can be configured through the
|
|
|
831
823
|
```javascript
|
|
832
824
|
// Enable console logging (error, warn, info, debug)
|
|
833
825
|
const config = {
|
|
834
|
-
couch:
|
|
835
|
-
useConsoleLogger: true
|
|
836
|
-
}
|
|
826
|
+
couch: 'http://localhost:5984/mydb',
|
|
827
|
+
useConsoleLogger: true
|
|
828
|
+
}
|
|
837
829
|
|
|
838
830
|
// Use a custom logger object (winston-style)
|
|
839
831
|
const config = {
|
|
840
|
-
couch:
|
|
832
|
+
couch: 'http://localhost:5984/mydb',
|
|
841
833
|
logger: {
|
|
842
|
-
error:
|
|
843
|
-
warn:
|
|
844
|
-
info:
|
|
845
|
-
debug:
|
|
846
|
-
}
|
|
847
|
-
}
|
|
834
|
+
error: msg => console.error(msg),
|
|
835
|
+
warn: msg => console.warn(msg),
|
|
836
|
+
info: msg => console.info(msg),
|
|
837
|
+
debug: msg => console.debug(msg)
|
|
838
|
+
}
|
|
839
|
+
}
|
|
848
840
|
|
|
849
841
|
// Use a simple function logger
|
|
850
842
|
const config = {
|
|
851
|
-
couch:
|
|
852
|
-
logger: (level, ...args) => console.log(level, ...args)
|
|
853
|
-
}
|
|
843
|
+
couch: 'http://localhost:5984/mydb',
|
|
844
|
+
logger: (level, ...args) => console.log(level, ...args)
|
|
845
|
+
}
|
|
854
846
|
```
|
|
855
847
|
|
|
856
848
|
The logger will track operations including:
|