Skip to content

Commit 5e14077

Browse files
committed
Add optional undici support
1 parent be8cc34 commit 5e14077

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+972
-753
lines changed

CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ This driver uses semantic versioning:
2222

2323
- Renamed `CollectionTruncateOptions` type to `TruncateCollectionOptions`
2424

25+
- Renamed `Config` type to `ConfigOptions`
26+
27+
- Renamed `path` option to `pathname` in `RequestOptions` type
28+
29+
This affects the `db.waitForPropagation` and `route.request` methods.
30+
31+
- Removed `basePath` option from `RequestOptions` type
32+
33+
This affects the `db.waitForPropagation` and `route.request` methods.
34+
35+
- Renamed `route.path` property to `route.pathname`
36+
2537
- Changed error type constructor signatures
2638

2739
The `request` property is now always positional and the `options` property
@@ -36,6 +48,11 @@ This driver uses semantic versioning:
3648

3749
The type is now also no longer marked as internal.
3850

51+
- Moved configuration related types to new `configuration` module
52+
53+
The following types were moved: `ConfigOptions`, `LoadBalancingStrategy`,
54+
`BasicAuthCredentials` and `BearerAuthCredentials`.
55+
3956
- Moved internal utility functions to new `lib/util` module
4057

4158
These methods are all still marked as internal and should not be used
@@ -48,6 +65,17 @@ This driver uses semantic versioning:
4865
does not guarantee the underlying connections are closed as these are
4966
handled by Node.js or the browser natively.
5067

68+
### Added
69+
70+
- Restored support for Unix domain sockets
71+
72+
Using Unix domain sockets requires the `undici` library to be installed.
73+
74+
- Restored support for `config.agentOptions`
75+
76+
The `config.agentOptions` option can now be used to create a custom `undici`
77+
agent if the `undici` library is installed.
78+
5179
## [10.0.0-alpha.0] - 2024-11-28
5280

5381
This is a major release and breaks backwards compatibility.

README.md

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ allowing arangojs to provide more meaningful stack traces at the cost of an
255255
impact to performance even when no error occurs.
256256

257257
```diff
258-
const { Database } = require("arangojs");
258+
import { Database } from "arangojs";
259259

260260
const db = new Database({
261261
url: ARANGODB_SERVER,
@@ -269,15 +269,47 @@ that do not support the `stack` property on error objects, this option will
269269
still impact performance but not result in any additional information becoming
270270
available.
271271

272+
### Unix domain sockets
273+
274+
If you want to use Unix domain sockets, you need to install the `undici` module,
275+
which is an optional dependency of arangojs.
276+
277+
```sh
278+
npm install --save undici
279+
```
280+
281+
If the `undici` module is not installed and arangojs attempts to make a request
282+
over a Unix domain socket, the request will fail with a plain `Error` with a
283+
message indicating that the `undici` module is unavailable.
284+
272285
### Node.js with self-signed HTTPS certificates
273286

274-
If you need to support self-signed HTTPS certificates in Node.js, you may have
275-
to override the global fetch agent. At the time of this writing, there is no
276-
official way to do this for the native `fetch` implementation in Node.js.
287+
If you need to support self-signed HTTPS certificates in Node.js, you will need
288+
to install the `undici` module, which is an optional dependency of arangojs.
289+
290+
```sh
291+
npm install --save undici
292+
```
293+
294+
You can instruct arangojs to use the `undici` module by setting the
295+
`config.agentOptions` option:
296+
297+
```diff
298+
import { Database } from "arangojs";
299+
300+
const db = new Database({
301+
url: ARANGODB_SERVER,
302+
+ agentOptions: {
303+
+ ca: [
304+
+ fs.readFileSync(".ssl/sub.class1.server.ca.pem"),
305+
+ fs.readFileSync(".ssl/ca.pem"),
306+
+ ],
307+
+ },
308+
});
309+
```
277310

278-
However as Node.js uses the `undici` module for its `fetch` implementation
279-
internally, you can override the global agent by adding `undici` as a
280-
dependency to your project and using its `setGlobalDispatcher` as follows:
311+
To override the global fetch agent instead, you can use the `undici` module's
312+
`setGlobalDispatcher` method as follows:
281313

282314
```js
283315
import { Agent, setGlobalDispatcher } from "undici";
@@ -293,20 +325,22 @@ setGlobalDispatcher(
293325
```
294326

295327
Although this is **strongly discouraged**, it's also possible to disable
296-
HTTPS certificate validation entirely, but note this has
328+
HTTPS certificate validation entirely this way, but note this has
297329
**extremely dangerous** security implications:
298330

299-
```js
300-
import { Agent, setGlobalDispatcher } from "undici";
331+
```diff
332+
import { Database } from "arangojs";
301333

302-
setGlobalDispatcher(
303-
new Agent({
304-
rejectUnauthorized: false,
305-
})
306-
);
334+
const db = new Database({
335+
url: ARANGODB_SERVER,
336+
+ agentOptions: {
337+
+ rejectUnauthorized: false,
338+
+ },
339+
});
307340
```
308341

309-
This is a [known limitation](https://github.com/orgs/nodejs/discussions/44038#discussioncomment-5701073)
342+
The requirement to use the `undici` module to override these settings is a
343+
[known limitation](https://github.com/orgs/nodejs/discussions/44038#discussioncomment-5701073)
310344
of Node.js at the time of this writing.
311345

312346
When using arangojs in the browser, self-signed HTTPS certificates need to

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,8 @@
102102
"source-map-support": "^0.5.21",
103103
"typedoc": "^0.25.12",
104104
"typescript": "^5.4.2"
105+
},
106+
"optionalDependencies": {
107+
"undici": ">=5.21.0"
105108
}
106109
}

src/administration.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export type ServerStatusInformation = {
141141
license: "community" | "enterprise";
142142
/**
143143
* Server operation mode.
144-
*
144+
*
145145
* @deprecated use `operationMode` instead
146146
*/
147147
mode: "server" | "console";
@@ -213,7 +213,7 @@ export type ServerStatusInformation = {
213213
version: string;
214214
/**
215215
* Whether writes are enabled.
216-
*
216+
*
217217
* @deprecated Use `readOnly` instead.
218218
*/
219219
writeOpsEnabled: boolean;
@@ -224,9 +224,9 @@ export type ServerStatusInformation = {
224224
* Server availability.
225225
*
226226
* - `"default"`: The server is operational.
227-
*
227+
*
228228
* - `"readonly"`: The server is in read-only mode.
229-
*
229+
*
230230
* - `false`: The server is not available.
231231
*/
232232
export type ServerAvailability = "default" | "readonly" | false;
@@ -245,9 +245,9 @@ export type SingleServerSupportInfo = {
245245
deployment: {
246246
/**
247247
* Deployment mode:
248-
*
248+
*
249249
* - `"single"`: A single server deployment.
250-
*
250+
*
251251
* - `"cluster"`: A cluster deployment.
252252
*/
253253
type: "single";
@@ -268,9 +268,9 @@ export type ClusterSupportInfo = {
268268
deployment: {
269269
/**
270270
* Deployment mode:
271-
*
271+
*
272272
* - `"single"`: A single server deployment.
273-
*
273+
*
274274
* - `"cluster"`: A cluster deployment.
275275
*/
276276
type: "cluster";

src/analyzers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ export class Analyzer {
912912
*/
913913
get(): Promise<connection.ArangoApiResponse<AnalyzerDescription>> {
914914
return this._db.request({
915-
path: `/_api/analyzer/${encodeURIComponent(this._name)}`,
915+
pathname: `/_api/analyzer/${encodeURIComponent(this._name)}`,
916916
});
917917
}
918918

@@ -972,7 +972,7 @@ export class Analyzer {
972972
> {
973973
return this._db.request({
974974
method: "POST",
975-
path: "/_api/analyzer",
975+
pathname: "/_api/analyzer",
976976
body: { name: this._name, ...options },
977977
});
978978
}
@@ -994,7 +994,7 @@ export class Analyzer {
994994
drop(force: boolean = false): Promise<connection.ArangoApiResponse<{ name: string }>> {
995995
return this._db.request({
996996
method: "DELETE",
997-
path: `/_api/analyzer/${encodeURIComponent(this._name)}`,
997+
pathname: `/_api/analyzer/${encodeURIComponent(this._name)}`,
998998
search: { force },
999999
});
10001000
}

0 commit comments

Comments
 (0)