apache / couchdb-nano

Nano: The official Apache CouchDB library for Node.js
https://www.npmjs.com/package/nano
Apache License 2.0
651 stars 165 forks source link

`update_seq` and `purge_seq` are defined as number but in actual response they are string #316

Closed divyanshshekhar closed 1 year ago

divyanshshekhar commented 1 year ago

CouchDB has update_seq field in response for changes API to identify the state of database. However, the actual response in couchdb contains string data in the field. For example, if we try to get db info for db foo from couchdb (localhost:5984/foo), we get response similar to below:

{
    "db_name": "foo",
    "purge_seq": "0-g1AAAABPeJzLYWBgYMpgTmHgzcvPy09JdcjLz8gvLskBCeexAEmGBiD1HwiyEhlwqEtkSKqHKMgCAIT2GV4",
    "update_seq": "1-g1AAAACLeJzLYWBgYMpgTmHgzcvPy09JdcjLz8gvLskBCeexAEmGBiD1HwiyMpgTGXKBAuwp5sZpKZYW6HpwmJLIkFQP1c4I1p6YZmhqYGqIrjgLAA4lKoc",
    "sizes": {
        "file": 20820,
        "external": 14,
        "active": 316
    },
    "props": {},
    "doc_del_count": 0,
    "doc_count": 1,
    "disk_format_version": 8,
    "compact_running": false,
    "cluster": {
        "q": 2,
        "n": 1,
        "w": 1,
        "r": 1
    },
    "instance_start_time": "0"
}

Expected Behavior

The following interfaces should have update_seq and purge_seq defined as string type:

Possible Solution

Change the datatype for the update_seq and purge_seq in nano.d.ts from number to string but it will be a breaking change. Instead we can change it to number | string to preserve backwards compatibility. Also, I believe, earlier the response contained actual integers but later it changed to string, so if define the datatype to be number | string instead of number that it is currently, it won't be a breaking change and will also conform to older versions of couchdb.

I have also raised a PR for the same.

Your Environment