Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fetch instead of axios #314

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
a30e3a5
working with fetch
Dec 12, 2022
fffb593
fix cookie renewal bug
Dec 12, 2022
5cbf072
removed unwanted request/axios code
Dec 13, 2022
529f506
tidy up
Dec 13, 2022
b91594c
remove tough-cookie and its patch
Dec 14, 2022
cb06484
log headers object instead of map
Dec 14, 2022
ae36ca6
http/https bug fix
Dec 14, 2022
1ad4561
added typescript parsing
Dec 14, 2022
fbed7ab
bug fixes for node16.8
Dec 14, 2022
6d800c3
custom agent and agentOptions with tests
Dec 14, 2022
2b5e5af
tidy up
Dec 15, 2022
a8a0825
show warning when requestDefaults is supplied
Dec 16, 2022
c329cc1
added description of each agentOptions attribute
Dec 16, 2022
c40a4a3
added missing test file
Dec 16, 2022
d14ff63
ensure "fetch" works on 16/18/19
Dec 20, 2022
f5280d5
fix test
Dec 20, 2022
aa9506d
nvm use 16.18.1
Dec 20, 2022
f692e14
rebase from main
Jan 9, 2023
3208204
remove node 14 support
Jan 9, 2023
7e8ffb8
upgrade undici to 5.15.0
Jan 11, 2023
999c6af
merge in latest changes
Jan 11, 2023
cffcd42
merge in latest changes
Jan 11, 2023
5a4ff3f
rebase on 10.1.2
Jan 26, 2023
0e7c06b
dependency bump
Feb 14, 2023
aba321c
fix cookie handling bug
Feb 14, 2023
e0c738a
dependency bump
Mar 6, 2023
aa4cc70
bump undici
Mar 24, 2023
46e08ba
dependency bump
May 22, 2023
c181a39
add node 20 to testing matrix
May 22, 2023
9c42fc3
pre v11 release tidy up
Sep 18, 2023
cead34a
prepare for merge
Sep 19, 2023
e16ad54
latest dependencies
Jan 2, 2024
6ee2510
allow clean merge
Aug 14, 2024
b7c560c
add Node v22 to the CI - it's been that long
Aug 14, 2024
47d4663
Update NOTICE
glynnbird Nov 4, 2024
c62d508
use contentType instead of ct
Nov 4, 2024
4f05cdb
beefed up the "breaking change" nature of Nano 11 for Node 16 (and ol…
Nov 4, 2024
e95b56b
assertion failures are rendered differently in Node 22, so the tests …
Nov 4, 2024
ff29111
added migration guide
Nov 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
glynnbird marked this conversation as resolved.
Show resolved Hide resolved
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Apache CouchDB Nano
Copyright [2016-2018] The Apache Software Foundation
Copyright [2016-2013] The Apache Software Foundation
glynnbird marked this conversation as resolved.
Show resolved Hide resolved

This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Offical [Apache CouchDB](https://couchdb.apache.org/) library for [Node.js](https://nodejs.org/).

> Note: Nano >=11.0.0 is for Node 18/20 and above. If you are using Node 16 or older, you need Nano 10.1.2.
glynnbird marked this conversation as resolved.
Show resolved Hide resolved

Features:

* **Minimalistic** - There is only a minimum of abstraction between you and
Expand Down Expand Up @@ -241,7 +243,9 @@ const agentOptions = {
connections: null,
maxRedirections: 0
}
const nano = Nano({ url: 'http://127.0.0.1:5984', agentOptions })
const undici = require('undici')
const undiciOptions = new undici.Agent(agentOptions)
const nano = Nano({ url: 'http://127.0.0.1:5984', undiciOptions })
```

The meanings of the agentOptions attributes is described [here](https://undici.nodejs.org/#/docs/api/Agent?id=new-undiciagentoptions), [here](https://undici.nodejs.org/#/docs/api/Pool?id=parameter-pooloptions) and [here](https://undici.nodejs.org/#/docs/api/Client?id=parameter-clientoptions)
Expand Down
16 changes: 4 additions & 12 deletions lib/nano.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@
// the License.

const { URL } = require('url')
const http = require('http')
const https = require('https')
const assert = require('assert')
const stream = require('stream')
const Readable = stream.Readable
const undici = require('undici')
const fetcher = global.fetch || undici.fetch
const ChangesReader = require('./changesreader.js')
const CookieJar = require('./cookie.js')
const MultiPartFactory = require('./multipart.js')
Expand Down Expand Up @@ -86,11 +82,7 @@ module.exports = exports = function dbScope (cfg) {
// if we've been passed a undici.Agent or undici.MockAgent,
// basically anything inherited from undici.Dispatcher, we
// can use it
if (cfg.agentOptions instanceof undici.Dispatcher) {
cfg.agent = cfg.agentOptions
} else if (typeof cfg.agentOptions === 'object') {
cfg.agent = new undici.Agent(cfg.agentOptions)
}
cfg.agent = cfg.agentOptions
}

// warn using still using requestDefaults
Expand Down Expand Up @@ -445,7 +437,7 @@ module.exports = exports = function dbScope (cfg) {
if (opts.stream) {
// return the Request object for streaming
const outStream = new stream.PassThrough()
fetcher(fetchOptions.url, fetchOptions).then((response) => {
fetch(fetchOptions.url, fetchOptions).then((response) => {
const readableWebStream = response.body
const readableNodeStream = Readable.fromWeb ? Readable.fromWeb(readableWebStream) : Readable.from(readableWebStream)
if (response.status > 300) {
Expand All @@ -459,14 +451,14 @@ module.exports = exports = function dbScope (cfg) {
return outStream
} else {
if (typeof callback === 'function') {
fetcher(fetchOptions.url, fetchOptions).then((response) => {
fetch(fetchOptions.url, fetchOptions).then((response) => {
responseHandler(response, fetchOptions, opts, null, null, callback)
}).catch((e) => {
responseHandler(e, fetchOptions, opts, null, null, callback)
})
} else {
return new Promise((resolve, reject) => {
fetcher(fetchOptions.url, fetchOptions).then((response) => {
fetch(fetchOptions.url, fetchOptions).then((response) => {
responseHandler(response, fetchOptions, opts, resolve, reject)
}).catch((e) => {
responseHandler(e, fetchOptions, opts, resolve, reject)
Expand Down
43 changes: 0 additions & 43 deletions migration_8_to_9.md

This file was deleted.

56 changes: 30 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 5 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,21 @@
"database"
],
"dependencies": {
"undici": "^5.22.1"
},
"devDependencies": {
"@types/node": "^20.2.3",
"typescript": "^5.0.4"
"undici": "^5.24.0",
"@types/node": "^20.6.2",
"typescript": "^5.2.2"
},
"scripts": {
"test": "tsc lib/nano.d.ts && node --test ./test/*.test.js"
},
"main": "./lib/nano.js",
"types": "./lib/nano.d.ts",
"engines": {
"node": ">=16.8"
"node": ">=18.0"
},
"pre-commit": [
"test"
],
"standard": {
"env": [
"jest"
]
}
]
}
5 changes: 3 additions & 2 deletions test/nano.agent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ test('should be able to supply a custom agent parameters', async () => {
const agentOptions = {
bodyTimeout: 10000
}
const nano = Nano({ url: COUCH_URL, agentOptions })
assert(nano.config.agent instanceof undici.Agent)
const undiciOptions = new undici.Agent(agentOptions)
const nano = Nano({ url: COUCH_URL, undiciOptions })
assert.equal(nano.config.agent, nano.config.agent)
})

test('should be able to supply a custom agent', async () => {
Expand Down