Skip to content

Commit 579a367

Browse files
committed
Merge branch 'v10'
2 parents eeae04b + ffac1e8 commit 579a367

Some content is hidden

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

68 files changed

+8404
-6884
lines changed

CHANGELOG.md

+435
Large diffs are not rendered by default.

MIGRATING.md

+50
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,55 @@
11
# Migrating
22

3+
## v9 to v10
4+
5+
Version 10 changes the error handling to make it easier to diagnose network
6+
issues and distinguish between different error conditions.
7+
8+
If you previously inspected errors other than `ArangoError` and `HttpError`
9+
directly, you should now expect to see `NetworkError` or a subclass thereof
10+
instead. The originating error can be found using the `cause` property of the
11+
`NetworkError` error:
12+
13+
```js
14+
try {
15+
await db.collection("my-collection").get();
16+
} catch (err) {
17+
if (err instanceof NetworkError) console.log(err.cause);
18+
}
19+
```
20+
21+
### Module name changes
22+
23+
Module names referring to resource types such as analyzers, collections,
24+
databases, or views have been changed to use the plural form:
25+
26+
```diff
27+
-import { Database } from "arangojs/database";
28+
+import { Database } from "arangojs/databases";
29+
```
30+
31+
Note that the `aql` module and `foxx-manifest` modules have not been renamed
32+
as these are utility modules.
33+
34+
### Type imports
35+
36+
Types that were previously exported by the `database` module but are not
37+
related to managing databases have been moved to separate modules:
38+
39+
```diff
40+
-import type {
41+
- ParseResult,
42+
- TransactionOptions,
43+
- VersionInfo
44+
-} from "arangojs/database";
45+
+import type { VersionInfo } from "arangojs/administration";
46+
+import type { TransactionOptions } from "arangojs/transactions";
47+
+import type { ParseResult } from "arangojs/queries";
48+
```
49+
50+
Additionally, some types were renamed. For a full list of changes, see the
51+
[changelog](./CHANGELOG.md).
52+
353
## v8 to v9
454

555
Version 9 reverts the automatic NFC normalization introduced in v7.7.0. This

README.md

+92-27
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,42 @@ and [the `db` object](https://www.arangodb.com/docs/stable/appendix-references-d
139139

140140
## Error responses
141141

142-
If arangojs encounters an API error, it will throw an `ArangoError` with
143-
an `errorNum` property indicating the ArangoDB error code and the `code`
144-
property indicating the HTTP status code from the response body.
142+
If the server returns an ArangoDB error response, arangojs will throw an
143+
`ArangoError` with an `errorNum` property indicating the ArangoDB error code
144+
and expose the response body as the `response` property of the error object.
145145

146-
For any other non-ArangoDB error responses (4xx/5xx status code), it will throw
147-
an `HttpError` error with the status code indicated by the `code` property.
146+
For all other errors during the request/response cycle, arangojs will throw a
147+
`NetworkError` or a more specific subclass thereof and expose the originating
148+
request object as the `request` property of the error object.
148149

149-
If the server response did not indicate an error but the response body could
150-
not be parsed, a regular `SyntaxError` may be thrown instead.
150+
If the server responded with a non-2xx status code, this `NetworkError` will
151+
be an `HttpError` with a `code` property indicating the HTTP status code of the
152+
response and a `response` property containing the response object itself.
151153

152-
In all of these cases the server response object will be exposed as the
153-
`response` property on the error object.
154+
If the error is caused by an exception, the originating exception will be
155+
available as the `cause` property of the error object thrown by arangojs. For
156+
network errors, this will often be a `TypeError`.
154157

155-
If the request failed at a network level or the connection was closed without
156-
receiving a response, the underlying system error will be thrown instead.
158+
### Node.js network errors
159+
160+
In Node.js, network errors caused by a `TypeError` will often have a `cause`
161+
property containing a more detailed exception.
162+
163+
Specifically, these are often either system errors (represented by regular
164+
`Error` objects with additional properties) or errors from the `undici` module
165+
Node.js uses internally for its native `fetch` implementation.
166+
167+
Node.js system error objects provide a `code` property containing the specific
168+
string error code, a `syscall` property identifying the underlying system call
169+
that triggered the error (e.g. `connect`), as well as other helpful properties.
170+
171+
For more details on Node.js system errors, see the Node.js documentation of the
172+
[`SystemError` interface](https://nodejs.org/api/errors.html#class-systemerror)
173+
as well as the section on
174+
[Node.js error codes](https://nodejs.org/api/errors.html#nodejs-error-codes).
175+
176+
For more details on the errors thrown by `undici`, see the
177+
[undici errors documentation](https://undici.nodejs.org/#/docs/api/Errors.md).
157178

158179
## Common issues
159180

@@ -170,6 +191,15 @@ Additionally please ensure that your version of Node.js (or browser) and
170191
ArangoDB are supported by the version of arangojs you are trying to use. See
171192
the [compatibility section](#compatibility) for additional information.
172193

194+
You can install an older version of arangojs using `npm` or `yarn`:
195+
196+
```sh
197+
# for version 8.x.x
198+
yarn add arangojs@8
199+
# - or -
200+
npm install --save arangojs@8
201+
```
202+
173203
### No code intelligence when using require instead of import
174204

175205
If you are using `require` to import the `arangojs` module in JavaScript, the
@@ -225,7 +255,7 @@ allowing arangojs to provide more meaningful stack traces at the cost of an
225255
impact to performance even when no error occurs.
226256

227257
```diff
228-
const { Database } = require("arangojs");
258+
import { Database } from "arangojs";
229259

230260
const db = new Database({
231261
url: ARANGODB_SERVER,
@@ -239,15 +269,48 @@ that do not support the `stack` property on error objects, this option will
239269
still impact performance but not result in any additional information becoming
240270
available.
241271

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 peer 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+
242285
### Node.js with self-signed HTTPS certificates
243286

244-
If you need to support self-signed HTTPS certificates in Node.js, you may have
245-
to override the global fetch agent. At the time of this writing, there is no
246-
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 peer dependency of
289+
arangojs.
247290

248-
However as Node.js uses the `undici` module for its `fetch` implementation
249-
internally, you can override the global agent by adding `undici` as a
250-
dependency to your project and using its `setGlobalDispatcher` as follows:
291+
```sh
292+
npm install --save undici
293+
```
294+
295+
You can instruct arangojs to use the `undici` module by setting the
296+
`config.agentOptions` option:
297+
298+
```diff
299+
import { Database } from "arangojs";
300+
301+
const db = new Database({
302+
url: ARANGODB_SERVER,
303+
+ agentOptions: {
304+
+ ca: [
305+
+ fs.readFileSync(".ssl/sub.class1.server.ca.pem"),
306+
+ fs.readFileSync(".ssl/ca.pem"),
307+
+ ],
308+
+ },
309+
});
310+
```
311+
312+
To override the global fetch agent instead, you can use the `undici` module's
313+
`setGlobalDispatcher` method as follows:
251314

252315
```js
253316
import { Agent, setGlobalDispatcher } from "undici";
@@ -263,20 +326,22 @@ setGlobalDispatcher(
263326
```
264327

265328
Although this is **strongly discouraged**, it's also possible to disable
266-
HTTPS certificate validation entirely, but note this has
329+
HTTPS certificate validation entirely this way, but note this has
267330
**extremely dangerous** security implications:
268331

269-
```js
270-
import { Agent, setGlobalDispatcher } from "undici";
332+
```diff
333+
import { Database } from "arangojs";
271334

272-
setGlobalDispatcher(
273-
new Agent({
274-
rejectUnauthorized: false,
275-
})
276-
);
335+
const db = new Database({
336+
url: ARANGODB_SERVER,
337+
+ agentOptions: {
338+
+ rejectUnauthorized: false,
339+
+ },
340+
});
277341
```
278342

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

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

package.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"private": true,
33
"type": "module",
44
"name": "arangojs",
5-
"version": "9.3.0",
5+
"version": "10.0.0",
66
"engines": {
77
"node": ">=18"
88
},
@@ -14,7 +14,7 @@
1414
},
1515
"repository": {
1616
"type": "git",
17-
"url": "https://github.com/arangodb/arangojs.git"
17+
"url": "git+https://github.com/arangodb/arangojs.git"
1818
},
1919
"author": "ArangoDB GmbH",
2020
"contributors": [
@@ -102,5 +102,13 @@
102102
"source-map-support": "^0.5.21",
103103
"typedoc": "^0.25.12",
104104
"typescript": "^5.4.2"
105+
},
106+
"peerDependencies": {
107+
"undici": ">=5.21.0"
108+
},
109+
"peerDependenciesMeta": {
110+
"undici": {
111+
"optional": true
112+
}
105113
}
106114
}

0 commit comments

Comments
 (0)