You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* use new url.URL instead of url.parse/url.reslove
* remove mocha tests
* add jest framework. Remove tape/mocha/istanbul.
* first jest tests
* finished top level tests
* document tests complete
* design functions
* multipart tests
* attachment tests
* tidy up
* auth/session/uuids
* 100% coverage
* partitioned functions and tests
* tidy up
* standard styling of examples
* only support current versions of node
* stash changes
* remove db.copy function - axios does not support COPY HTTP method
* alter the way attachment.insertAsStream works
* typescript update
* combine attachment.insert attachment.insertAsStream
* ensure db.head passes the test
* configure default http agent, user-agent string and gzipping
* added tests for gzip/user-agent headers + TypeScript defs
* ensure tests run in env=node mode
* typescript defs
* remove cloudant-follow and replace with changesReader
* added further tests
* readme
* removed errs dependency
* resurrect logging
* get changesreader to use relax
* fixed suggestions from @eridal
* avoid extra function wrapper in setTimeout
* handle numeric sequence tokens
* remove callback from wait:true mode - switch to pause()/resume() functions
* ensure the response attributes are assigned to the error object thrown
* add description to error messages
* prevent Error message being overwritten
* dependency bump
* ensure Node version list matches current/supported versions
* fixup readme
* fix(nano.d.ts): add opts and callback for relax (#225)
* fix(nano.d.ts): add opts and callback for nano.request
* fix(nano.d.ts): add opts and callback for relax and dinosaur
* Add FollowEmitter.stop() to typescript declaration file (#230)
* Patch typescript declaration file (#231)
* Add string to View.map type (#220)
addresses #219
* - Addded viewWithListAsStream function (#227)
- Added test case for viewWithListAsStream
- Added documntation for viewWithListm and viewWithListAsStream
* dependency bump
* updated Node.js versions used to test to reflect current supported versions
* standard fixes
* added 8->9 migration guide
Co-authored-by: Glynn Bird <glynnbird@apache.org>
Co-authored-by: Steven Tang <steven.yc.tang@gmail.com>
Co-authored-by: Leon <sxwei123@users.noreply.github.com>
Co-authored-by: Luiz Victor Linhares Rocha <luizvictorlrocha@gmail.com>
Co-authored-by: Luca Morandini <lmorandini@ieee.org>
Nano provides a low-level API for making calls to CouchDB's changes feed, or if you want a
670
+
reliable, resumable changes feed follower, then you need the `changesReader`.
671
+
672
+
There are three ways to start listening to the changes feed:
673
+
674
+
1.`changesReader.start()` - to listen to changes indefinitely by repeated "long poll" requests. This mode continues to poll for changes forever.
675
+
2.`changesReader.get()` - to listen to changes until the end of the changes feed is reached, by repeated "long poll" requests. Once a response with zero changes is received, the 'end' event will indicate the end of the changes and polling will stop.
676
+
3.`changesReader.spool()` - listen to changes in one long HTTP request. (as opposed to repeated round trips) - spool is faster but less reliable.
677
+
678
+
> Note: for `.get()` & `.start()`, the sequence of API calls can be paused by calling `changesReader.pause()` and resumed by calling `changesReader.resume()`.
679
+
680
+
Set up your database connection and then choose `changesReader.start()` to listen to that database's changes:
console.log('a batch of', b.length, 'changes has arrived');
688
+
}).on('seq', (s) => {
689
+
console.log('sequence token', s);
690
+
}).on('error', (e) => {
691
+
console.error('error', e);
692
+
})
693
+
```
694
+
695
+
> Note: you probably want to monitor *either* the `change` or `batch` event, not both.
696
+
697
+
If you want `changesReader` to hold off making the next `_changes` API call until you are ready, then supply `wait:true` in the options to `get`/`start`. The next request will only fire when you call `changesReader.resume()`:
698
+
699
+
```js
700
+
db.changesReader.get({wait:true})
701
+
.on('batch', (b) => {
702
+
console.log('a batch of', b.length, 'changes has arrived');
703
+
// do some asynchronous work here and call "changesReader.resume()"
704
+
// when you're ready for the next API call to be dispatched.
705
+
// In this case, wait 5s before the next changes feed request.
706
+
setTimeout( () => {
707
+
db.changesReader.resume()
708
+
}, 5000)
709
+
}).on('end', () => {
710
+
console.log('changes feed monitoring has stopped');
711
+
});
712
+
```
713
+
714
+
You may supply a number of options when you start to listen to the changes feed:
715
+
716
+
| Parameter | Description | Default value | e.g. ||
| batchSize | The maximum number of changes to ask CouchDB for per HTTP request. This is the maximum number of changes you will receive in a `batch` event. | 100 | 500 ||
719
+
| since | The position in the changes feed to start from where `0` means the beginning of time, `now` means the current position or a string token indicates a fixed position in the changes feed | now | 390768-g1AAAAGveJzLYWBgYMlgTmGQ ||
720
+
| includeDocs | Whether to include document bodies or not | false | e.g. true |
721
+
| wait | For `get`/`start` mode, automatically pause the changes reader after each request. When the the user calls `resume()`, the changes reader will resume. | false | e.g. true |
722
+
| fastChanges | Adds a seq_interval parameter to fetch changes more quickly | false | true ||
723
+
| selector | Filters the changes feed with the supplied Mango selector | {"name":"fred} | null ||
724
+
| timeout | The number of milliseconds a changes feed request waits for data| 60000 | 10000
| change | Each detected change is emitted individually. Only available in `get`/`start` modes. | A change object ||
731
+
| batch | Each batch of changes is emitted in bulk in quantities up to `batchSize`. | An array of change objects ||
732
+
| seq | Each new sequence token (per HTTP request). This token can be passed into `ChangesReader` as the `since` parameter to resume changes feed consumption from a known point. Only available in `get`/`start` modes. | String ||
733
+
| error | On a fatal error, a descriptive object is returned and change consumption stops. | Error object ||
734
+
| end | Emitted when the end of the changes feed is reached. `ChangesReader.get()` mode only, | Nothing ||
735
+
736
+
The *ChangesReader* library will handle many temporal errors such as network connectivity, service capacity limits and malformed data but it will emit an `error` event and exit when fed incorrect authentication credentials or an invalid `since` token.
737
+
738
+
The `change` event delivers a change object that looks like this:
-`doc` is only present if `includeDocs:true` is supplied
758
+
-`seq` is not present for every change
759
+
760
+
The `id` is the unique identifier of the document that changed and the `changes` array contains the document revision tokens that were written to the database.
761
+
762
+
The `batch` event delivers an array of change objects.
763
+
722
764
## Partition Functions
723
765
724
766
Functions related to [partitioned databses](https://docs.couchdb.org/en/latest/partitioned-dbs/index.html).
@@ -1291,6 +1325,39 @@ and document level functions
1291
1325
1292
1326
- db.listAsStream
1293
1327
1328
+
### Logging
1329
+
1330
+
When instantiating Nano, you may supply the function that will perform the logging of requests and responses. In its simplest for, simply pass `console.log` as your logger:
0 commit comments