Comparing version 8.5.0 to 8.6.0
@@ -17,2 +17,20 @@ # Changelog | ||
## [8.6.0] - 2023-10-24 | ||
### Added | ||
- Added `db.createJob` method to convert arbitrary requests into async jobs (DE-610) | ||
This method can be used to set the `x-arango-async: store` header on any | ||
request, which will cause the server to store the request in an async job: | ||
```js | ||
const collectionsJob = await db.createJob(() => db.collections()); | ||
// once loaded, collectionsJob.result will be an array of Collection instances | ||
const numbersJob = await db.createJob(() => | ||
db.query(aql`FOR i IN 1..1000 RETURN i`) | ||
); | ||
// once loaded, numbersJob.result will be an ArrayCursor of numbers | ||
``` | ||
## [8.5.0] - 2023-10-09 | ||
@@ -1729,2 +1747,3 @@ | ||
[8.6.0]: https://github.com/arangodb/arangojs/compare/v8.5.0...v8.6.0 | ||
[8.5.0]: https://github.com/arangodb/arangojs/compare/v8.4.1...v8.5.0 | ||
@@ -1731,0 +1750,0 @@ [8.4.1]: https://github.com/arangodb/arangojs/compare/v8.4.0...v8.4.1 |
@@ -454,3 +454,3 @@ "use strict"; | ||
"x-arango-version": String(this._arangoVersion), | ||
"x-arango-driver": `arangojs/8.5.0 (cloud)`, | ||
"x-arango-driver": `arangojs/8.6.0 (cloud)`, | ||
}; | ||
@@ -457,0 +457,0 @@ if (this._transactionId) { |
import { Database } from "./database"; | ||
import { ArangojsResponse } from "./lib/request.node"; | ||
/** | ||
@@ -8,2 +9,4 @@ * Represents an async job in a {@link database.Database}. | ||
protected _db: Database; | ||
protected _transformResponse?: (res: ArangojsResponse) => Promise<T>; | ||
protected _transformError?: (error: any) => Promise<T>; | ||
protected _loaded: boolean; | ||
@@ -14,3 +17,3 @@ protected _result: T | undefined; | ||
*/ | ||
constructor(db: Database, id: string); | ||
constructor(db: Database, id: string, transformResponse?: (res: ArangojsResponse) => Promise<T>, transformError?: (error: any) => Promise<T>); | ||
/** | ||
@@ -17,0 +20,0 @@ * Whether the job's results have been loaded. If set to `true`, the job's |
28
job.js
@@ -11,6 +11,8 @@ "use strict"; | ||
*/ | ||
constructor(db, id) { | ||
constructor(db, id, transformResponse, transformError) { | ||
this._loaded = false; | ||
this._db = db; | ||
this._id = id; | ||
this._transformResponse = transformResponse; | ||
this._transformError = transformError; | ||
} | ||
@@ -47,9 +49,23 @@ /** | ||
if (!this.isLoaded) { | ||
const res = await this._db.request({ | ||
method: "PUT", | ||
path: `/_api/job/${this._id}`, | ||
}, false); | ||
let res; | ||
try { | ||
res = await this._db.request({ | ||
method: "PUT", | ||
path: `/_api/job/${this._id}`, | ||
}, false); | ||
} | ||
catch (e) { | ||
if (this._transformError) { | ||
return this._transformError(e); | ||
} | ||
throw e; | ||
} | ||
if (res.statusCode !== 204) { | ||
this._loaded = true; | ||
this._result = res.body; | ||
if (this._transformResponse) { | ||
this._result = await this._transformResponse(res); | ||
} | ||
else { | ||
this._result = res.body; | ||
} | ||
} | ||
@@ -56,0 +72,0 @@ } |
{ | ||
"name": "arangojs", | ||
"version": "8.5.0", | ||
"version": "8.6.0", | ||
"engines": { | ||
@@ -5,0 +5,0 @@ "node": ">=14" |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2319004
21694