arangojs 7.8.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +264 -3
- package/CONTRIBUTING.md +1 -1
- package/MIGRATING.md +126 -2
- package/README.md +7 -13
- package/analyzer.d.ts +531 -253
- package/analyzer.d.ts.map +1 -1
- package/analyzer.js +9 -8
- package/analyzer.js.map +1 -1
- package/aql.d.ts +122 -139
- package/aql.d.ts.map +1 -1
- package/aql.js +146 -148
- package/aql.js.map +1 -1
- package/collection.d.ts +311 -310
- package/collection.d.ts.map +1 -1
- package/collection.js +163 -96
- package/collection.js.map +1 -1
- package/connection.d.ts +65 -52
- package/connection.d.ts.map +1 -1
- package/connection.js +142 -140
- package/connection.js.map +1 -1
- package/cursor.d.ts +108 -26
- package/cursor.d.ts.map +1 -1
- package/cursor.js +24 -23
- package/cursor.js.map +1 -1
- package/database.d.ts +298 -330
- package/database.d.ts.map +1 -1
- package/database.js +178 -252
- package/database.js.map +1 -1
- package/documents.d.ts +3 -4
- package/documents.d.ts.map +1 -1
- package/documents.js +0 -1
- package/documents.js.map +1 -1
- package/error.d.ts +3 -6
- package/error.d.ts.map +1 -1
- package/error.js +5 -7
- package/error.js.map +1 -1
- package/foxx-manifest.d.ts +7 -8
- package/foxx-manifest.d.ts.map +1 -1
- package/foxx-manifest.js +1 -1
- package/foxx-manifest.js.map +1 -1
- package/graph.d.ts +38 -56
- package/graph.d.ts.map +1 -1
- package/graph.js +59 -63
- package/graph.js.map +1 -1
- package/index.d.ts +6 -8
- package/index.d.ts.map +1 -1
- package/index.js +1 -6
- package/index.js.map +1 -1
- package/indexes.d.ts +348 -127
- package/indexes.d.ts.map +1 -1
- package/indexes.js +1 -3
- package/indexes.js.map +1 -1
- package/lib/blob.d.ts +0 -2
- package/lib/blob.d.ts.map +1 -1
- package/lib/blob.js +0 -1
- package/lib/blob.js.map +1 -1
- package/lib/btoa.d.ts +1 -3
- package/lib/btoa.d.ts.map +1 -1
- package/lib/btoa.js +3 -5
- package/lib/btoa.js.map +1 -1
- package/lib/btoa.web.d.ts +1 -3
- package/lib/btoa.web.d.ts.map +1 -1
- package/lib/btoa.web.js +4 -6
- package/lib/btoa.web.js.map +1 -1
- package/lib/codes.d.ts +2 -2
- package/lib/codes.d.ts.map +1 -1
- package/lib/codes.js +3 -3
- package/lib/codes.js.map +1 -1
- package/lib/errback.d.ts +0 -2
- package/lib/errback.d.ts.map +1 -1
- package/lib/errback.js.map +1 -1
- package/lib/joinPath.d.ts +0 -2
- package/lib/joinPath.d.ts.map +1 -1
- package/lib/joinPath.js +0 -2
- package/lib/joinPath.js.map +1 -1
- package/lib/joinPath.web.d.ts +1 -3
- package/lib/joinPath.web.d.ts.map +1 -1
- package/lib/joinPath.web.js +7 -4
- package/lib/joinPath.web.js.map +1 -1
- package/lib/multipart.d.ts +0 -4
- package/lib/multipart.d.ts.map +1 -1
- package/lib/multipart.js +16 -37
- package/lib/multipart.js.map +1 -1
- package/lib/multipart.web.d.ts +0 -2
- package/lib/multipart.web.d.ts.map +1 -1
- package/lib/multipart.web.js +0 -2
- package/lib/multipart.web.js.map +1 -1
- package/lib/normalizeUrl.d.ts +0 -2
- package/lib/normalizeUrl.d.ts.map +1 -1
- package/lib/normalizeUrl.js +0 -2
- package/lib/normalizeUrl.js.map +1 -1
- package/lib/omit.d.ts +1 -3
- package/lib/omit.d.ts.map +1 -1
- package/lib/omit.js +1 -2
- package/lib/omit.js.map +1 -1
- package/lib/querystringify.d.ts +4 -0
- package/lib/querystringify.d.ts.map +1 -0
- package/lib/querystringify.js +20 -0
- package/lib/querystringify.js.map +1 -0
- package/lib/querystringify.web.d.ts +2 -0
- package/lib/querystringify.web.d.ts.map +1 -0
- package/lib/querystringify.web.js +30 -0
- package/lib/querystringify.web.js.map +1 -0
- package/lib/request.d.ts +0 -1
- package/lib/request.d.ts.map +1 -1
- package/lib/request.js +6 -3
- package/lib/request.js.map +1 -1
- package/lib/request.node.d.ts +2 -8
- package/lib/request.node.d.ts.map +1 -1
- package/lib/request.node.js +16 -7
- package/lib/request.node.js.map +1 -1
- package/lib/request.web.d.ts +2 -3
- package/lib/request.web.d.ts.map +1 -1
- package/lib/request.web.js +26 -29
- package/lib/request.web.js.map +1 -1
- package/lib/xhr.d.ts +1 -3
- package/lib/xhr.d.ts.map +1 -1
- package/lib/xhr.js +0 -2
- package/lib/xhr.js.map +1 -1
- package/package.json +5 -6
- package/route.d.ts +1 -2
- package/route.d.ts.map +1 -1
- package/route.js +1 -2
- package/route.js.map +1 -1
- package/transaction.d.ts +31 -6
- package/transaction.d.ts.map +1 -1
- package/transaction.js +13 -6
- package/transaction.js.map +1 -1
- package/view.d.ts +237 -181
- package/view.d.ts.map +1 -1
- package/view.js +17 -25
- package/view.js.map +1 -1
- package/web.js +1 -1
- package/web.js.map +1 -1
- package/lib/error.d.ts +0 -18
- package/lib/error.d.ts.map +0 -1
- package/lib/error.js +0 -18
- package/lib/error.js.map +0 -1
package/route.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.js","sourceRoot":"","sources":["../src/route.ts"],"names":[],"mappings":";;;AAaA;;GAEG;AACH,MAAa,KAAK;IAKhB;;;OAGG;IACH,YAAY,EAAY,EAAE,OAAe,EAAE,EAAE,UAAmB,EAAE;QAChE,IAAI,CAAC,IAAI;YAAE,IAAI,GAAG,EAAE,CAAC;aAChB,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG;YAAE,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QACnD,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;QACd,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,IAAY,EAAE,OAAiB;QACnC,IAAI,CAAC,IAAI;YAAE,IAAI,GAAG,EAAE,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AE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IACpE,CAAC;IAqDD,IAAI,CAAC,GAAG,IAAW;QACjB,MAAM,IAAI,GAAG,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QACpE,MAAM,CAAC,IAAI,EAAE,EAAE,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;QACjC,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IACnE,CAAC;IA+CD,GAAG,CAAC,GAAG,IAAW;QAChB,MAAM,IAAI,GAAG,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QACpE,MAAM,CAAC,IAAI,EAAE,EAAE,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;QACjC,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IAClE,CAAC;CACF;AAnWD,sBAmWC","sourcesContent":["/**\n * ```ts\n * import type { Route } from \"arangojs/route\";\n * ```\n *\n * The \"route\" module provides route related types and interfaces for TypeScript.\n *\n * @packageDocumentation\n */\nimport { Headers, Params, RequestOptions } from \"./connection\";\nimport { Database } from \"./database\";\nimport { ArangojsResponse } from \"./lib/request\";\n\n/**\n * Represents an arbitrary route relative to an ArangoDB database.\n */\nexport class Route {\n protected _db: Database;\n protected _path: string;\n protected _headers: Headers;\n\n /**\n * @internal\n * @hidden\n */\n constructor(db: Database, path: string = \"\", headers: Headers = {}) {\n if (!path) path = \"\";\n else if (path.charAt(0) !== \"/\") path = `/${path}`;\n this._db = db;\n this._path = path;\n this._headers = headers;\n }\n\n /**\n * Creates a new route relative to this route that inherits any of its default\n * HTTP headers.\n *\n * @param path - Path relative to this route.\n * @param headers - Additional headers that will be sent with each request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const users = foxx.route(\"/users\");\n * ```\n */\n route(path: string, headers?: Headers) {\n if (!path) path = \"\";\n else if (path.charAt(0) !== \"/\") path = `/${path}`;\n return new Route(this._db, this._path + path, {\n ...this._headers,\n ...headers,\n });\n }\n\n /**\n * Performs an arbitrary HTTP request relative to this route and returns the\n * server response.\n *\n * @param options - Options for performing the request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const res = await foxx.request({\n * method: \"POST\",\n * path: \"/users\",\n * body: {\n * username: \"admin\",\n * password: \"hunter2\"\n * }\n * });\n * ```\n */\n request(options?: RequestOptions) {\n const opts = { ...options };\n if (!opts.path || opts.path === \"/\") opts.path = \"\";\n else if (!this._path || opts.path.charAt(0) === \"/\") opts.path = opts.path;\n else opts.path = `/${opts.path}`;\n opts.basePath = this._path;\n opts.headers = { ...this._headers, ...opts.headers };\n opts.method = opts.method ? opts.method.toUpperCase() : \"GET\";\n return this._db.request(opts);\n }\n\n /**\n * Performs a DELETE request against the given path relative to this route\n * and returns the server response.\n *\n * @param path - Path relative to this route.\n * @param qs - Query string parameters for this request.\n * @param headers - Additional headers to send with this request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const res = await foxx.delete(\"/users/admin\");\n * ```\n */\n delete(\n path: string,\n qs?: string | Params,\n headers?: Headers\n ): Promise<ArangojsResponse>;\n /**\n * Performs a DELETE request against the given path relative to this route\n * and returns the server response.\n *\n * @param qs - Query string parameters for this request.\n * @param headers - Additional headers to send with this request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const user = foxx.roue(\"/users/admin\");\n * const res = await user.delete();\n * ```\n */\n delete(qs?: Params, headers?: Headers): Promise<ArangojsResponse>;\n delete(...args: any[]): Promise<ArangojsResponse> {\n const path = typeof args[0] === \"string\" ? args.shift() : undefined;\n const [qs, headers] = args;\n return this.request({ method: \"DELETE\", path, qs, headers });\n }\n\n /**\n * Performs a GET request against the given path relative to this route\n * and returns the server response.\n *\n * @param path - Path relative to this route.\n * @param qs - Query string parameters for this request.\n * @param headers - Additional headers to send with this request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const res = await foxx.get(\"/users\", { offset: 10, limit: 5 });\n * ```\n */\n get(\n path: string,\n qs?: string | Params,\n headers?: Headers\n ): Promise<ArangojsResponse>;\n /**\n * Performs a GET request against the given path relative to this route\n * and returns the server response.\n *\n * @param qs - Query string parameters for this request.\n * @param headers - Additional headers to send with this request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const users = foxx.route(\"/users\");\n * const res = await users.get({ offset: 10, limit: 5 });\n * ```\n */\n get(qs?: Params, headers?: Headers): Promise<ArangojsResponse>;\n get(...args: any[]): Promise<ArangojsResponse> {\n const path = typeof args[0] === \"string\" ? args.shift() : undefined;\n const [qs, headers] = args;\n return this.request({ method: \"GET\", path, qs, headers });\n }\n\n /**\n * Performs a HEAD request against the given path relative to this route\n * and returns the server response.\n *\n * @param path - Path relative to this route.\n * @param qs - Query string parameters for this request.\n * @param headers - Additional headers to send with this request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const res = await foxx.head(\"/users\", { offset: 10, limit: 5 });\n * ```\n */\n head(\n path: string,\n qs?: string | Params,\n headers?: Headers\n ): Promise<ArangojsResponse>;\n /**\n * Performs a HEAD request against the given path relative to this route\n * and returns the server response.\n *\n * @param qs - Query string parameters for this request.\n * @param headers - Additional headers to send with this request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const users = foxx.route(\"/users\");\n * const res = await users.head({ offset: 10, limit: 5 });\n * ```\n */\n head(qs?: Params, headers?: Headers): Promise<ArangojsResponse>;\n head(...args: any[]): Promise<ArangojsResponse> {\n const path = typeof args[0] === \"string\" ? args.shift() : undefined;\n const [qs, headers] = args;\n return this.request({ method: \"HEAD\", path, qs, headers });\n }\n\n /**\n * Performs a PATCH request against the given path relative to this route\n * and returns the server response.\n *\n * @param path - Path relative to this route.\n * @param body - Body of the request object.\n * @param qs - Query string parameters for this request.\n * @param headers - Additional headers to send with this request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const res = await foxx.patch(\"/users/admin\", { password: \"admin\" });\n * ```\n */\n patch(\n path: string,\n body?: any,\n qs?: string | Params,\n headers?: Headers\n ): Promise<ArangojsResponse>;\n /**\n * Performs a PATCH request against the given path relative to this route\n * and returns the server response.\n *\n * **Note**: `body` must not be a `string`.\n *\n * @param body - Body of the request object. Must not be a string.\n * @param qs - Query string parameters for this request.\n * @param headers - Additional headers to send with this request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const user = foxx.route(\"/users/admin\")\n * const res = await user.patch({ password: \"admin\" });\n * ```\n */\n patch(\n body?: any,\n qs?: string | Params,\n headers?: Headers\n ): Promise<ArangojsResponse>;\n patch(...args: any[]): Promise<ArangojsResponse> {\n const path = typeof args[0] === \"string\" ? args.shift() : undefined;\n const [body, qs, headers] = args;\n return this.request({ method: \"PATCH\", path, body, qs, headers });\n }\n\n /**\n * Performs a POST request against the given path relative to this route\n * and returns the server response.\n *\n * @param path - Path relative to this route.\n * @param body - Body of the request object.\n * @param qs - Query string parameters for this request.\n * @param headers - Additional headers to send with this request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const res = await foxx.post(\"/users\", {\n * username: \"admin\",\n * password: \"hunter2\"\n * });\n * ```\n */\n post(\n path: string,\n body?: any,\n qs?: string | Params,\n headers?: Headers\n ): Promise<ArangojsResponse>;\n /**\n * Performs a POST request against the given path relative to this route\n * and returns the server response.\n *\n * **Note**: `body` must not be a `string`.\n *\n * @param body - Body of the request object. Must not be a string.\n * @param qs - Query string parameters for this request.\n * @param headers - Additional headers to send with this request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const users = foxx.route(\"/users\");\n * const res = await users.post({\n * username: \"admin\",\n * password: \"hunter2\"\n * });\n * ```\n */\n post(\n body?: any,\n qs?: string | Params,\n headers?: Headers\n ): Promise<ArangojsResponse>;\n post(...args: any[]): Promise<ArangojsResponse> {\n const path = typeof args[0] === \"string\" ? args.shift() : undefined;\n const [body, qs, headers] = args;\n return this.request({ method: \"POST\", path, body, qs, headers });\n }\n\n /**\n * Performs a PUT request against the given path relative to this route\n * and returns the server response.\n *\n * @param path - Path relative to this route.\n * @param body - Body of the request object.\n * @param qs - Query string parameters for this request.\n * @param headers - Additional headers to send with this request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const res = await foxx.put(\"/users/admin/password\", { password: \"admin\" });\n * ```\n */\n put(\n path: string,\n body?: any,\n qs?: string | Params,\n headers?: Headers\n ): Promise<ArangojsResponse>;\n /**\n * Performs a PUT request against the given path relative to this route\n * and returns the server response.\n *\n * **Note**: `body` must not be a `string`.\n *\n * @param body - Body of the request object. Must not be a string.\n * @param qs - Query string parameters for this request.\n * @param headers - Additional headers to send with this request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const password = foxx.route(\"/users/admin/password\");\n * const res = await password.put({ password: \"admin\" });\n * ```\n */\n put(\n body?: any,\n qs?: string | Params,\n headers?: Headers\n ): Promise<ArangojsResponse>;\n put(...args: any[]): Promise<ArangojsResponse> {\n const path = typeof args[0] === \"string\" ? args.shift() : undefined;\n const [body, qs, headers] = args;\n return this.request({ method: \"PUT\", path, body, qs, headers });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"route.js","sourceRoot":"","sources":["../src/route.ts"],"names":[],"mappings":";;;AAaA;;GAEG;AACH,MAAa,KAAK;IAKhB;;OAEG;IACH,YAAY,EAAY,EAAE,OAAe,EAAE,EAAE,UAAmB,EAAE;QAChE,IAAI,CAAC,IAAI;YAAE,IAAI,GAAG,EAAE,CAAC;aAChB,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG;YAAE,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QACnD,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;QACd,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,IAAY,EAAE,OAAiB;QACnC,IAAI,CAAC,IAAI;YAAE,IAAI,GAAG,EAAE,CAAC;aAChB,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG;YAAE,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QACnD,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,GAAG,IAAI,EAAE;YAC5C,GAAG,IAAI,CAAC,QAAQ;YAChB,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,OAAO,CAAC,OAAwB;QAC9B,MAAM,IAAI,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,GAAG;YAAE,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;aAC/C,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAA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Q,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QACpE,MAAM,CAAC,IAAI,EAAE,EAAE,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;QACjC,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IAClE,CAAC;CACF;AAlWD,sBAkWC","sourcesContent":["/**\n * ```ts\n * import type { Route } from \"arangojs/route\";\n * ```\n *\n * The \"route\" module provides route related types and interfaces for TypeScript.\n *\n * @packageDocumentation\n */\nimport { Headers, Params, RequestOptions } from \"./connection\";\nimport { Database } from \"./database\";\nimport { ArangojsResponse } from \"./lib/request\";\n\n/**\n * Represents an arbitrary route relative to an ArangoDB database.\n */\nexport class Route {\n protected _db: Database;\n protected _path: string;\n protected _headers: Headers;\n\n /**\n * @internal\n */\n constructor(db: Database, path: string = \"\", headers: Headers = {}) {\n if (!path) path = \"\";\n else if (path.charAt(0) !== \"/\") path = `/${path}`;\n this._db = db;\n this._path = path;\n this._headers = headers;\n }\n\n /**\n * Creates a new route relative to this route that inherits any of its default\n * HTTP headers.\n *\n * @param path - Path relative to this route.\n * @param headers - Additional headers that will be sent with each request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const users = foxx.route(\"/users\");\n * ```\n */\n route(path: string, headers?: Headers) {\n if (!path) path = \"\";\n else if (path.charAt(0) !== \"/\") path = `/${path}`;\n return new Route(this._db, this._path + path, {\n ...this._headers,\n ...headers,\n });\n }\n\n /**\n * Performs an arbitrary HTTP request relative to this route and returns the\n * server response.\n *\n * @param options - Options for performing the request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const res = await foxx.request({\n * method: \"POST\",\n * path: \"/users\",\n * body: {\n * username: \"admin\",\n * password: \"hunter2\"\n * }\n * });\n * ```\n */\n request(options?: RequestOptions) {\n const opts = { ...options };\n if (!opts.path || opts.path === \"/\") opts.path = \"\";\n else if (!this._path || opts.path.charAt(0) === \"/\") opts.path = opts.path;\n else opts.path = `/${opts.path}`;\n opts.basePath = this._path;\n opts.headers = { ...this._headers, ...opts.headers };\n opts.method = opts.method ? opts.method.toUpperCase() : \"GET\";\n return this._db.request(opts, false);\n }\n\n /**\n * Performs a DELETE request against the given path relative to this route\n * and returns the server response.\n *\n * @param path - Path relative to this route.\n * @param qs - Query string parameters for this request.\n * @param headers - Additional headers to send with this request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const res = await foxx.delete(\"/users/admin\");\n * ```\n */\n delete(\n path: string,\n qs?: string | Params,\n headers?: Headers\n ): Promise<ArangojsResponse>;\n /**\n * Performs a DELETE request against the given path relative to this route\n * and returns the server response.\n *\n * @param qs - Query string parameters for this request.\n * @param headers - Additional headers to send with this request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const user = foxx.roue(\"/users/admin\");\n * const res = await user.delete();\n * ```\n */\n delete(qs?: Params, headers?: Headers): Promise<ArangojsResponse>;\n delete(...args: any[]): Promise<ArangojsResponse> {\n const path = typeof args[0] === \"string\" ? args.shift() : undefined;\n const [qs, headers] = args;\n return this.request({ method: \"DELETE\", path, qs, headers });\n }\n\n /**\n * Performs a GET request against the given path relative to this route\n * and returns the server response.\n *\n * @param path - Path relative to this route.\n * @param qs - Query string parameters for this request.\n * @param headers - Additional headers to send with this request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const res = await foxx.get(\"/users\", { offset: 10, limit: 5 });\n * ```\n */\n get(\n path: string,\n qs?: string | Params,\n headers?: Headers\n ): Promise<ArangojsResponse>;\n /**\n * Performs a GET request against the given path relative to this route\n * and returns the server response.\n *\n * @param qs - Query string parameters for this request.\n * @param headers - Additional headers to send with this request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const users = foxx.route(\"/users\");\n * const res = await users.get({ offset: 10, limit: 5 });\n * ```\n */\n get(qs?: Params, headers?: Headers): Promise<ArangojsResponse>;\n get(...args: any[]): Promise<ArangojsResponse> {\n const path = typeof args[0] === \"string\" ? args.shift() : undefined;\n const [qs, headers] = args;\n return this.request({ method: \"GET\", path, qs, headers });\n }\n\n /**\n * Performs a HEAD request against the given path relative to this route\n * and returns the server response.\n *\n * @param path - Path relative to this route.\n * @param qs - Query string parameters for this request.\n * @param headers - Additional headers to send with this request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const res = await foxx.head(\"/users\", { offset: 10, limit: 5 });\n * ```\n */\n head(\n path: string,\n qs?: string | Params,\n headers?: Headers\n ): Promise<ArangojsResponse>;\n /**\n * Performs a HEAD request against the given path relative to this route\n * and returns the server response.\n *\n * @param qs - Query string parameters for this request.\n * @param headers - Additional headers to send with this request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const users = foxx.route(\"/users\");\n * const res = await users.head({ offset: 10, limit: 5 });\n * ```\n */\n head(qs?: Params, headers?: Headers): Promise<ArangojsResponse>;\n head(...args: any[]): Promise<ArangojsResponse> {\n const path = typeof args[0] === \"string\" ? args.shift() : undefined;\n const [qs, headers] = args;\n return this.request({ method: \"HEAD\", path, qs, headers });\n }\n\n /**\n * Performs a PATCH request against the given path relative to this route\n * and returns the server response.\n *\n * @param path - Path relative to this route.\n * @param body - Body of the request object.\n * @param qs - Query string parameters for this request.\n * @param headers - Additional headers to send with this request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const res = await foxx.patch(\"/users/admin\", { password: \"admin\" });\n * ```\n */\n patch(\n path: string,\n body?: any,\n qs?: string | Params,\n headers?: Headers\n ): Promise<ArangojsResponse>;\n /**\n * Performs a PATCH request against the given path relative to this route\n * and returns the server response.\n *\n * **Note**: `body` must not be a `string`.\n *\n * @param body - Body of the request object. Must not be a string.\n * @param qs - Query string parameters for this request.\n * @param headers - Additional headers to send with this request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const user = foxx.route(\"/users/admin\")\n * const res = await user.patch({ password: \"admin\" });\n * ```\n */\n patch(\n body?: any,\n qs?: string | Params,\n headers?: Headers\n ): Promise<ArangojsResponse>;\n patch(...args: any[]): Promise<ArangojsResponse> {\n const path = typeof args[0] === \"string\" ? args.shift() : undefined;\n const [body, qs, headers] = args;\n return this.request({ method: \"PATCH\", path, body, qs, headers });\n }\n\n /**\n * Performs a POST request against the given path relative to this route\n * and returns the server response.\n *\n * @param path - Path relative to this route.\n * @param body - Body of the request object.\n * @param qs - Query string parameters for this request.\n * @param headers - Additional headers to send with this request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const res = await foxx.post(\"/users\", {\n * username: \"admin\",\n * password: \"hunter2\"\n * });\n * ```\n */\n post(\n path: string,\n body?: any,\n qs?: string | Params,\n headers?: Headers\n ): Promise<ArangojsResponse>;\n /**\n * Performs a POST request against the given path relative to this route\n * and returns the server response.\n *\n * **Note**: `body` must not be a `string`.\n *\n * @param body - Body of the request object. Must not be a string.\n * @param qs - Query string parameters for this request.\n * @param headers - Additional headers to send with this request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const users = foxx.route(\"/users\");\n * const res = await users.post({\n * username: \"admin\",\n * password: \"hunter2\"\n * });\n * ```\n */\n post(\n body?: any,\n qs?: string | Params,\n headers?: Headers\n ): Promise<ArangojsResponse>;\n post(...args: any[]): Promise<ArangojsResponse> {\n const path = typeof args[0] === \"string\" ? args.shift() : undefined;\n const [body, qs, headers] = args;\n return this.request({ method: \"POST\", path, body, qs, headers });\n }\n\n /**\n * Performs a PUT request against the given path relative to this route\n * and returns the server response.\n *\n * @param path - Path relative to this route.\n * @param body - Body of the request object.\n * @param qs - Query string parameters for this request.\n * @param headers - Additional headers to send with this request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const res = await foxx.put(\"/users/admin/password\", { password: \"admin\" });\n * ```\n */\n put(\n path: string,\n body?: any,\n qs?: string | Params,\n headers?: Headers\n ): Promise<ArangojsResponse>;\n /**\n * Performs a PUT request against the given path relative to this route\n * and returns the server response.\n *\n * **Note**: `body` must not be a `string`.\n *\n * @param body - Body of the request object. Must not be a string.\n * @param qs - Query string parameters for this request.\n * @param headers - Additional headers to send with this request.\n *\n * @example\n * ```js\n * const db = new Database();\n * const foxx = db.route(\"/my-foxx-service\");\n * const password = foxx.route(\"/users/admin/password\");\n * const res = await password.put({ password: \"admin\" });\n * ```\n */\n put(\n body?: any,\n qs?: string | Params,\n headers?: Headers\n ): Promise<ArangojsResponse>;\n put(...args: any[]): Promise<ArangojsResponse> {\n const path = typeof args[0] === \"string\" ? args.shift() : undefined;\n const [body, qs, headers] = args;\n return this.request({ method: \"PUT\", path, body, qs, headers });\n }\n}\n"]}
|
package/transaction.d.ts
CHANGED
|
@@ -5,10 +5,32 @@ import { Database } from "./database";
|
|
|
5
5
|
* @param transaction - A value that might be a transaction.
|
|
6
6
|
*/
|
|
7
7
|
export declare function isArangoTransaction(transaction: any): transaction is Transaction;
|
|
8
|
+
/**
|
|
9
|
+
* Options for how the transaction should be committed.
|
|
10
|
+
*/
|
|
11
|
+
export declare type TransactionCommitOptions = {
|
|
12
|
+
/**
|
|
13
|
+
* If set to `true`, the request will explicitly permit ArangoDB to return a
|
|
14
|
+
* potentially dirty or stale result and arangojs will load balance the
|
|
15
|
+
* request without distinguishing between leaders and followers.
|
|
16
|
+
*/
|
|
17
|
+
allowDirtyRead?: boolean;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Options for how the transaction should be aborted.
|
|
21
|
+
*/
|
|
22
|
+
export declare type TransactionAbortOptions = {
|
|
23
|
+
/**
|
|
24
|
+
* If set to `true`, the request will explicitly permit ArangoDB to return a
|
|
25
|
+
* potentially dirty or stale result and arangojs will load balance the
|
|
26
|
+
* request without distinguishing between leaders and followers.
|
|
27
|
+
*/
|
|
28
|
+
allowDirtyRead?: boolean;
|
|
29
|
+
};
|
|
8
30
|
/**
|
|
9
31
|
* Status of a given transaction.
|
|
10
32
|
*
|
|
11
|
-
* See also {@link TransactionDetails}.
|
|
33
|
+
* See also {@link database.TransactionDetails}.
|
|
12
34
|
*/
|
|
13
35
|
export declare type TransactionStatus = {
|
|
14
36
|
/**
|
|
@@ -21,14 +43,13 @@ export declare type TransactionStatus = {
|
|
|
21
43
|
status: "running" | "committed" | "aborted";
|
|
22
44
|
};
|
|
23
45
|
/**
|
|
24
|
-
* Represents a streaming transaction in a {@link Database}.
|
|
46
|
+
* Represents a streaming transaction in a {@link database.Database}.
|
|
25
47
|
*/
|
|
26
48
|
export declare class Transaction {
|
|
27
49
|
protected _db: Database;
|
|
28
50
|
protected _id: string;
|
|
29
51
|
/**
|
|
30
52
|
* @internal
|
|
31
|
-
* @hidden
|
|
32
53
|
*/
|
|
33
54
|
constructor(db: Database, id: string);
|
|
34
55
|
/**
|
|
@@ -40,7 +61,7 @@ export declare class Transaction {
|
|
|
40
61
|
/**
|
|
41
62
|
* Unique identifier of this transaction.
|
|
42
63
|
*
|
|
43
|
-
* See {@link Database
|
|
64
|
+
* See {@link database.Database#transaction}.
|
|
44
65
|
*/
|
|
45
66
|
get id(): string;
|
|
46
67
|
/**
|
|
@@ -72,6 +93,8 @@ export declare class Transaction {
|
|
|
72
93
|
/**
|
|
73
94
|
* Attempts to commit the transaction to the databases.
|
|
74
95
|
*
|
|
96
|
+
* @param options - Options for comitting the transaction.
|
|
97
|
+
*
|
|
75
98
|
* @example
|
|
76
99
|
* ```js
|
|
77
100
|
* const db = new Database();
|
|
@@ -82,10 +105,12 @@ export declare class Transaction {
|
|
|
82
105
|
* // result indicates the updated transaction status
|
|
83
106
|
* ```
|
|
84
107
|
*/
|
|
85
|
-
commit(): Promise<TransactionStatus>;
|
|
108
|
+
commit(options?: TransactionCommitOptions): Promise<TransactionStatus>;
|
|
86
109
|
/**
|
|
87
110
|
* Attempts to abort the transaction to the databases.
|
|
88
111
|
*
|
|
112
|
+
* @param options - Options for aborting the transaction.
|
|
113
|
+
*
|
|
89
114
|
* @example
|
|
90
115
|
* ```js
|
|
91
116
|
* const db = new Database();
|
|
@@ -96,7 +121,7 @@ export declare class Transaction {
|
|
|
96
121
|
* // result indicates the updated transaction status
|
|
97
122
|
* ```
|
|
98
123
|
*/
|
|
99
|
-
abort(): Promise<TransactionStatus>;
|
|
124
|
+
abort(options?: TransactionAbortOptions): Promise<TransactionStatus>;
|
|
100
125
|
/**
|
|
101
126
|
* Executes the given function locally as a single step of the transaction.
|
|
102
127
|
*
|
package/transaction.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,GAAG,GACf,WAAW,IAAI,WAAW,CAE5B;AAED;;;;GAIG;AACH,oBAAY,iBAAiB,GAAG;IAC9B;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,SAAS,CAAC;CAC7C,CAAC;AAEF;;GAEG;AACH,qBAAa,WAAW;IACtB,SAAS,CAAC,GAAG,EAAE,QAAQ,CAAC;IACxB,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC;IAEtB
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA0LG;IACH,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAehD"}
|
package/transaction.js
CHANGED
|
@@ -13,12 +13,11 @@ function isArangoTransaction(transaction) {
|
|
|
13
13
|
}
|
|
14
14
|
exports.isArangoTransaction = isArangoTransaction;
|
|
15
15
|
/**
|
|
16
|
-
* Represents a streaming transaction in a {@link Database}.
|
|
16
|
+
* Represents a streaming transaction in a {@link database.Database}.
|
|
17
17
|
*/
|
|
18
18
|
class Transaction {
|
|
19
19
|
/**
|
|
20
20
|
* @internal
|
|
21
|
-
* @hidden
|
|
22
21
|
*/
|
|
23
22
|
constructor(db, id) {
|
|
24
23
|
this._db = db;
|
|
@@ -35,7 +34,7 @@ class Transaction {
|
|
|
35
34
|
/**
|
|
36
35
|
* Unique identifier of this transaction.
|
|
37
36
|
*
|
|
38
|
-
* See {@link Database
|
|
37
|
+
* See {@link database.Database#transaction}.
|
|
39
38
|
*/
|
|
40
39
|
get id() {
|
|
41
40
|
return this._id;
|
|
@@ -57,7 +56,7 @@ class Transaction {
|
|
|
57
56
|
return true;
|
|
58
57
|
}
|
|
59
58
|
catch (err) {
|
|
60
|
-
if (error_1.isArangoError(err) && err.errorNum === codes_1.TRANSACTION_NOT_FOUND) {
|
|
59
|
+
if ((0, error_1.isArangoError)(err) && err.errorNum === codes_1.TRANSACTION_NOT_FOUND) {
|
|
61
60
|
return false;
|
|
62
61
|
}
|
|
63
62
|
throw err;
|
|
@@ -84,6 +83,8 @@ class Transaction {
|
|
|
84
83
|
/**
|
|
85
84
|
* Attempts to commit the transaction to the databases.
|
|
86
85
|
*
|
|
86
|
+
* @param options - Options for comitting the transaction.
|
|
87
|
+
*
|
|
87
88
|
* @example
|
|
88
89
|
* ```js
|
|
89
90
|
* const db = new Database();
|
|
@@ -94,15 +95,19 @@ class Transaction {
|
|
|
94
95
|
* // result indicates the updated transaction status
|
|
95
96
|
* ```
|
|
96
97
|
*/
|
|
97
|
-
commit() {
|
|
98
|
+
commit(options = {}) {
|
|
99
|
+
const { allowDirtyRead = undefined } = options;
|
|
98
100
|
return this._db.request({
|
|
99
101
|
method: "PUT",
|
|
100
102
|
path: `/_api/transaction/${encodeURIComponent(this.id)}`,
|
|
103
|
+
allowDirtyRead,
|
|
101
104
|
}, (res) => res.body.result);
|
|
102
105
|
}
|
|
103
106
|
/**
|
|
104
107
|
* Attempts to abort the transaction to the databases.
|
|
105
108
|
*
|
|
109
|
+
* @param options - Options for aborting the transaction.
|
|
110
|
+
*
|
|
106
111
|
* @example
|
|
107
112
|
* ```js
|
|
108
113
|
* const db = new Database();
|
|
@@ -113,10 +118,12 @@ class Transaction {
|
|
|
113
118
|
* // result indicates the updated transaction status
|
|
114
119
|
* ```
|
|
115
120
|
*/
|
|
116
|
-
abort() {
|
|
121
|
+
abort(options = {}) {
|
|
122
|
+
const { allowDirtyRead = undefined } = options;
|
|
117
123
|
return this._db.request({
|
|
118
124
|
method: "DELETE",
|
|
119
125
|
path: `/_api/transaction/${encodeURIComponent(this.id)}`,
|
|
126
|
+
allowDirtyRead,
|
|
120
127
|
}, (res) => res.body.result);
|
|
121
128
|
}
|
|
122
129
|
/**
|
package/transaction.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":";;;AAYA,mCAAwC;AACxC,uCAAoD;AAEpD;;;;GAIG;AACH,SAAgB,mBAAmB,CACjC,WAAgB;IAEhB,OAAO,OAAO,CAAC,WAAW,IAAI,WAAW,CAAC,mBAAmB,CAAC,CAAC;AACjE,CAAC;AAJD,kDAIC;AAkBD;;GAEG;AACH,MAAa,WAAW;IAItB;;;OAGG;IACH,YAAY,EAAY,EAAE,EAAU;QAClC,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;QAC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C,GAAG,CAAC,IAAI,CAAC,MAAM,CACzB,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA0LG;IACH,IAAI,CAAI,QAA0B;QAChC,MAAM,IAAI,GAAI,IAAI,CAAC,GAAW,CAAC,WAAyB,CAAC;QACzD,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC/B,IAAI;YACF,MAAM,OAAO,GAAG,QAAQ,EAAE,CAAC;YAC3B,IAAI,CAAC,OAAO,EAAE;gBACZ,MAAM,IAAI,KAAK,CACb,6EAA6E,CAC9E,CAAC;aACH;YACD,OAAO,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;SACjC;gBAAS;YACR,IAAI,CAAC,kBAAkB,EAAE,CAAC;SAC3B;IACH,CAAC;CACF;AApUD,kCAoUC","sourcesContent":["/**\n * ```ts\n * import type { Transaction } from \"arangojs/transaction\";\n * ```\n *\n * The \"transaction\" module provides transaction related types and interfaces\n * for TypeScript.\n *\n * @packageDocumentation\n */\nimport { Connection } from \"./connection\";\nimport { Database } from \"./database\";\nimport { isArangoError } from \"./error\";\nimport { TRANSACTION_NOT_FOUND } from \"./lib/codes\";\n\n/**\n * Indicates whether the given value represents a {@link Transaction}.\n *\n * @param transaction - A value that might be a transaction.\n */\nexport function isArangoTransaction(\n transaction: any\n): transaction is Transaction {\n return Boolean(transaction && transaction.isArangoTransaction);\n}\n\n/**\n * Status of a given transaction.\n *\n * See also {@link TransactionDetails}.\n */\nexport type TransactionStatus = {\n /**\n * Unique identifier of the transaction.\n */\n id: string;\n /**\n * Status of the transaction.\n */\n status: \"running\" | \"committed\" | \"aborted\";\n};\n\n/**\n * Represents a streaming transaction in a {@link Database}.\n */\nexport class Transaction {\n protected _db: Database;\n protected _id: string;\n\n /**\n * @internal\n * @hidden\n */\n constructor(db: Database, id: string) {\n this._db = db;\n this._id = id;\n }\n\n /**\n * @internal\n *\n * Indicates that this object represents an ArangoDB transaction.\n */\n get isArangoTransaction(): true {\n return true;\n }\n\n /**\n * Unique identifier of this transaction.\n *\n * See {@link Database.transaction}.\n */\n get id() {\n return this._id;\n }\n\n /**\n * Checks whether the transaction exists.\n *\n * @example\n * ```js\n * const db = new Database();\n * const trx = db.transaction(\"some-transaction\");\n * const result = await trx.exists();\n * // result indicates whether the transaction exists\n * ```\n */\n async exists(): Promise<boolean> {\n try {\n await this.get();\n return true;\n } catch (err) {\n if (isArangoError(err) && err.errorNum === TRANSACTION_NOT_FOUND) {\n return false;\n }\n throw err;\n }\n }\n\n /**\n * Retrieves general information about the transaction.\n *\n * @example\n * ```js\n * const db = new Database();\n * const col = db.collection(\"some-collection\");\n * const trx = db.beginTransaction(col);\n * await trx.step(() => col.save({ hello: \"world\" }));\n * const info = await trx.get();\n * // the transaction exists\n * ```\n */\n get(): Promise<TransactionStatus> {\n return this._db.request(\n {\n path: `/_api/transaction/${encodeURIComponent(this.id)}`,\n },\n (res) => res.body.result\n );\n }\n\n /**\n * Attempts to commit the transaction to the databases.\n *\n * @example\n * ```js\n * const db = new Database();\n * const col = db.collection(\"some-collection\");\n * const trx = db.beginTransaction(col);\n * await trx.step(() => col.save({ hello: \"world\" }));\n * const result = await trx.commit();\n * // result indicates the updated transaction status\n * ```\n */\n commit(): Promise<TransactionStatus> {\n return this._db.request(\n {\n method: \"PUT\",\n path: `/_api/transaction/${encodeURIComponent(this.id)}`,\n },\n (res) => res.body.result\n );\n }\n\n /**\n * Attempts to abort the transaction to the databases.\n *\n * @example\n * ```js\n * const db = new Database();\n * const col = db.collection(\"some-collection\");\n * const trx = db.beginTransaction(col);\n * await trx.step(() => col.save({ hello: \"world\" }));\n * const result = await trx.abort();\n * // result indicates the updated transaction status\n * ```\n */\n abort(): Promise<TransactionStatus> {\n return this._db.request(\n {\n method: \"DELETE\",\n path: `/_api/transaction/${encodeURIComponent(this.id)}`,\n },\n (res) => res.body.result\n );\n }\n\n /**\n * Executes the given function locally as a single step of the transaction.\n *\n * @param T - Type of the callback's returned promise.\n * @param callback - Callback function returning a promise.\n *\n * **Warning**: The callback function should wrap a single call of an async\n * arangojs method (e.g. a method on a `Collection` object of a collection\n * that is involved in the transaction or the `db.query` method).\n * If the callback function is async, only the first promise-returning (or\n * async) method call will be executed as part of the transaction. See the\n * examples below for how to avoid common mistakes when using this method.\n *\n * **Note**: Avoid defining the callback as an async function if possible\n * as arangojs will throw an error if the callback did not return a promise.\n * Async functions will return an empty promise by default, making it harder\n * to notice if you forgot to return something from the callback.\n *\n * **Note**: Although almost anything can be wrapped in a callback and passed\n * to this method, that does not guarantee ArangoDB can actually do it in a\n * transaction. Refer to the ArangoDB documentation if you are unsure whether\n * a given operation can be executed as part of a transaction. Generally any\n * modification or retrieval of data is eligible but modifications of\n * collections or databases are not.\n *\n * @example\n * ```js\n * const db = new Database();\n * const vertices = db.collection(\"vertices\");\n * const edges = db.collection(\"edges\");\n * const trx = await db.beginTransaction({ write: [vertices, edges] });\n *\n * // The following code will be part of the transaction\n * const left = await trx.step(() => vertices.save({ label: \"left\" }));\n * const right = await trx.step(() => vertices.save({ label: \"right\" }));\n *\n * // Results from preceding actions can be used normally\n * await trx.step(() => edges.save({\n * _from: left._id,\n * _to: right._id,\n * data: \"potato\"\n * }));\n *\n * // Transaction must be committed for changes to take effected\n * // Always call either trx.commit or trx.abort to end a transaction\n * await trx.commit();\n * ```\n *\n * @example\n * ```js\n * // BAD! If the callback is an async function it must only use await once!\n * await trx.step(async () => {\n * await collection.save(data);\n * await collection.save(moreData); // WRONG\n * });\n *\n * // BAD! Callback function must use only one arangojs call!\n * await trx.step(() => {\n * return collection.save(data)\n * .then(() => collection.save(moreData)); // WRONG\n * });\n *\n * // BETTER: Wrap every arangojs method call that should be part of the\n * // transaction in a separate `trx.step` call\n * await trx.step(() => collection.save(data));\n * await trx.step(() => collection.save(moreData));\n * ```\n *\n * @example\n * ```js\n * // BAD! If the callback is an async function it must not await before\n * // calling an arangojs method!\n * await trx.step(async () => {\n * await doSomethingElse();\n * return collection.save(data); // WRONG\n * });\n *\n * // BAD! Any arangojs inside the callback must not happen inside a promise\n * // method!\n * await trx.step(() => {\n * return doSomethingElse()\n * .then(() => collection.save(data)); // WRONG\n * });\n *\n * // BETTER: Perform any async logic needed outside the `trx.step` call\n * await doSomethingElse();\n * await trx.step(() => collection.save(data));\n *\n * // OKAY: You can perform async logic in the callback after the arangojs\n * // method call as long as it does not involve additional arangojs method\n * // calls, but this makes it easy to make mistakes later\n * await trx.step(async () => {\n * await collection.save(data);\n * await doSomethingDifferent(); // no arangojs method calls allowed\n * });\n * ```\n *\n * @example\n * ```js\n * // BAD! The callback should not use any functions that themselves use any\n * // arangojs methods!\n * async function saveSomeData() {\n * await collection.save(data);\n * await collection.save(moreData);\n * }\n * await trx.step(() => saveSomeData()); // WRONG\n *\n * // BETTER: Pass the transaction to functions that need to call arangojs\n * // methods inside a transaction\n * async function saveSomeData(trx) {\n * await trx.step(() => collection.save(data));\n * await trx.step(() => collection.save(moreData));\n * }\n * await saveSomeData(); // no `trx.step` call needed\n * ```\n *\n * @example\n * ```js\n * // BAD! You must wait for the promise to resolve (or await on the\n * // `trx.step` call) before calling `trx.step` again!\n * trx.step(() => collection.save(data)); // WRONG\n * await trx.step(() => collection.save(moreData));\n *\n * // BAD! The trx.step callback can not make multiple calls to async arangojs\n * // methods, not even using Promise.all!\n * await trx.step(() => Promise.all([ // WRONG\n * collection.save(data),\n * collection.save(moreData),\n * ]));\n *\n * // BAD! Multiple `trx.step` calls can not run in parallel!\n * await Promise.all([ // WRONG\n * trx.step(() => collection.save(data)),\n * trx.step(() => collection.save(moreData)),\n * ]));\n *\n * // BETTER: Always call `trx.step` sequentially, one after the other\n * await trx.step(() => collection.save(data));\n * await trx.step(() => collection.save(moreData));\n *\n * // OKAY: The then callback can be used if async/await is not available\n * trx.step(() => collection.save(data))\n * .then(() => trx.step(() => collection.save(moreData)));\n * ```\n *\n * @example\n * ```js\n * // BAD! The callback will return an empty promise that resolves before\n * // the inner arangojs method call has even talked to ArangoDB!\n * await trx.step(async () => {\n * collection.save(data); // WRONG\n * });\n *\n * // BETTER: Use an arrow function so you don't forget to return\n * await trx.step(() => collection.save(data));\n *\n * // OKAY: Remember to always return when using a function body\n * await trx.step(() => {\n * return collection.save(data); // easy to forget!\n * });\n *\n * // OKAY: You do not have to use arrow functions but it helps\n * await trx.step(function () {\n * return collection.save(data);\n * });\n * ```\n *\n * @example\n * ```js\n * // BAD! You can not pass promises instead of a callback!\n * await trx.step(collection.save(data)); // WRONG\n *\n * // BETTER: Wrap the code in a function and pass the function instead\n * await trx.step(() => collection.save(data));\n * ```\n *\n * @example\n * ```js\n * // WORSE: Calls to non-async arangojs methods don't need to be performed\n * // as part of a transaction\n * const collection = await trx.step(() => db.collection(\"my-documents\"));\n *\n * // BETTER: If an arangojs method is not async and doesn't return promises,\n * // call it without `trx.step`\n * const collection = db.collection(\"my-documents\");\n * ```\n */\n step<T>(callback: () => Promise<T>): Promise<T> {\n const conn = (this._db as any)._connection as Connection;\n conn.setTransactionId(this.id);\n try {\n const promise = callback();\n if (!promise) {\n throw new Error(\n \"Transaction callback was not an async function or did not return a promise!\"\n );\n }\n return Promise.resolve(promise);\n } finally {\n conn.clearTransactionId();\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":";;;AAYA,mCAAwC;AACxC,uCAAoD;AAEpD;;;;GAIG;AACH,SAAgB,mBAAmB,CACjC,WAAgB;IAEhB,OAAO,OAAO,CAAC,WAAW,IAAI,WAAW,CAAC,mBAAmB,CAAC,CAAC;AACjE,CAAC;AAJD,kDAIC;AA0CD;;GAEG;AACH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;;;;;;OAcG;IACH,KAAK,CAAC,UAAmC,EAAE;QACzC,MAAM,EAAE,cAAc,GAAG,SAAS,EAAE,GAAG,OAAO,CAAC;QAC/C,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CACrB;YACE,MAAM,EAAE,QAAQ;YAChB,IAAI,EAAE,qBAAqB,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;YACxD,cAAc;SACf,EACD,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CACzB,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA0LG;IACH,IAAI,CAAI,QAA0B;QAChC,MAAM,IAAI,GAAI,IAAI,CAAC,GAAW,CAAC,WAAyB,CAAC;QACzD,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC/B,IAAI;YACF,MAAM,OAAO,GAAG,QAAQ,EAAE,CAAC;YAC3B,IAAI,CAAC,OAAO,EAAE;gBACZ,MAAM,IAAI,KAAK,CACb,6EAA6E,CAC9E,CAAC;aACH;YACD,OAAO,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;SACjC;gBAAS;YACR,IAAI,CAAC,kBAAkB,EAAE,CAAC;SAC3B;IACH,CAAC;CACF;AA3UD,kCA2UC","sourcesContent":["/**\n * ```ts\n * import type { Transaction } from \"arangojs/transaction\";\n * ```\n *\n * The \"transaction\" module provides transaction related types and interfaces\n * for TypeScript.\n *\n * @packageDocumentation\n */\nimport { Connection } from \"./connection\";\nimport { Database } from \"./database\";\nimport { isArangoError } from \"./error\";\nimport { TRANSACTION_NOT_FOUND } from \"./lib/codes\";\n\n/**\n * Indicates whether the given value represents a {@link Transaction}.\n *\n * @param transaction - A value that might be a transaction.\n */\nexport function isArangoTransaction(\n transaction: any\n): transaction is Transaction {\n return Boolean(transaction && transaction.isArangoTransaction);\n}\n\n/**\n * Options for how the transaction should be committed.\n */\nexport type TransactionCommitOptions = {\n /**\n * If set to `true`, the request will explicitly permit ArangoDB to return a\n * potentially dirty or stale result and arangojs will load balance the\n * request without distinguishing between leaders and followers.\n */\n allowDirtyRead?: boolean;\n};\n\n/**\n * Options for how the transaction should be aborted.\n */\nexport type TransactionAbortOptions = {\n /**\n * If set to `true`, the request will explicitly permit ArangoDB to return a\n * potentially dirty or stale result and arangojs will load balance the\n * request without distinguishing between leaders and followers.\n */\n allowDirtyRead?: boolean;\n};\n\n/**\n * Status of a given transaction.\n *\n * See also {@link database.TransactionDetails}.\n */\nexport type TransactionStatus = {\n /**\n * Unique identifier of the transaction.\n */\n id: string;\n /**\n * Status of the transaction.\n */\n status: \"running\" | \"committed\" | \"aborted\";\n};\n\n/**\n * Represents a streaming transaction in a {@link database.Database}.\n */\nexport class Transaction {\n protected _db: Database;\n protected _id: string;\n\n /**\n * @internal\n */\n constructor(db: Database, id: string) {\n this._db = db;\n this._id = id;\n }\n\n /**\n * @internal\n *\n * Indicates that this object represents an ArangoDB transaction.\n */\n get isArangoTransaction(): true {\n return true;\n }\n\n /**\n * Unique identifier of this transaction.\n *\n * See {@link database.Database#transaction}.\n */\n get id() {\n return this._id;\n }\n\n /**\n * Checks whether the transaction exists.\n *\n * @example\n * ```js\n * const db = new Database();\n * const trx = db.transaction(\"some-transaction\");\n * const result = await trx.exists();\n * // result indicates whether the transaction exists\n * ```\n */\n async exists(): Promise<boolean> {\n try {\n await this.get();\n return true;\n } catch (err: any) {\n if (isArangoError(err) && err.errorNum === TRANSACTION_NOT_FOUND) {\n return false;\n }\n throw err;\n }\n }\n\n /**\n * Retrieves general information about the transaction.\n *\n * @example\n * ```js\n * const db = new Database();\n * const col = db.collection(\"some-collection\");\n * const trx = db.beginTransaction(col);\n * await trx.step(() => col.save({ hello: \"world\" }));\n * const info = await trx.get();\n * // the transaction exists\n * ```\n */\n get(): Promise<TransactionStatus> {\n return this._db.request(\n {\n path: `/_api/transaction/${encodeURIComponent(this.id)}`,\n },\n (res) => res.body.result\n );\n }\n\n /**\n * Attempts to commit the transaction to the databases.\n *\n * @param options - Options for comitting the transaction.\n *\n * @example\n * ```js\n * const db = new Database();\n * const col = db.collection(\"some-collection\");\n * const trx = db.beginTransaction(col);\n * await trx.step(() => col.save({ hello: \"world\" }));\n * const result = await trx.commit();\n * // result indicates the updated transaction status\n * ```\n */\n commit(options: TransactionCommitOptions = {}): Promise<TransactionStatus> {\n const { allowDirtyRead = undefined } = options;\n return this._db.request(\n {\n method: \"PUT\",\n path: `/_api/transaction/${encodeURIComponent(this.id)}`,\n allowDirtyRead,\n },\n (res) => res.body.result\n );\n }\n\n /**\n * Attempts to abort the transaction to the databases.\n *\n * @param options - Options for aborting the transaction.\n *\n * @example\n * ```js\n * const db = new Database();\n * const col = db.collection(\"some-collection\");\n * const trx = db.beginTransaction(col);\n * await trx.step(() => col.save({ hello: \"world\" }));\n * const result = await trx.abort();\n * // result indicates the updated transaction status\n * ```\n */\n abort(options: TransactionAbortOptions = {}): Promise<TransactionStatus> {\n const { allowDirtyRead = undefined } = options;\n return this._db.request(\n {\n method: \"DELETE\",\n path: `/_api/transaction/${encodeURIComponent(this.id)}`,\n allowDirtyRead,\n },\n (res) => res.body.result\n );\n }\n\n /**\n * Executes the given function locally as a single step of the transaction.\n *\n * @param T - Type of the callback's returned promise.\n * @param callback - Callback function returning a promise.\n *\n * **Warning**: The callback function should wrap a single call of an async\n * arangojs method (e.g. a method on a `Collection` object of a collection\n * that is involved in the transaction or the `db.query` method).\n * If the callback function is async, only the first promise-returning (or\n * async) method call will be executed as part of the transaction. See the\n * examples below for how to avoid common mistakes when using this method.\n *\n * **Note**: Avoid defining the callback as an async function if possible\n * as arangojs will throw an error if the callback did not return a promise.\n * Async functions will return an empty promise by default, making it harder\n * to notice if you forgot to return something from the callback.\n *\n * **Note**: Although almost anything can be wrapped in a callback and passed\n * to this method, that does not guarantee ArangoDB can actually do it in a\n * transaction. Refer to the ArangoDB documentation if you are unsure whether\n * a given operation can be executed as part of a transaction. Generally any\n * modification or retrieval of data is eligible but modifications of\n * collections or databases are not.\n *\n * @example\n * ```js\n * const db = new Database();\n * const vertices = db.collection(\"vertices\");\n * const edges = db.collection(\"edges\");\n * const trx = await db.beginTransaction({ write: [vertices, edges] });\n *\n * // The following code will be part of the transaction\n * const left = await trx.step(() => vertices.save({ label: \"left\" }));\n * const right = await trx.step(() => vertices.save({ label: \"right\" }));\n *\n * // Results from preceding actions can be used normally\n * await trx.step(() => edges.save({\n * _from: left._id,\n * _to: right._id,\n * data: \"potato\"\n * }));\n *\n * // Transaction must be committed for changes to take effected\n * // Always call either trx.commit or trx.abort to end a transaction\n * await trx.commit();\n * ```\n *\n * @example\n * ```js\n * // BAD! If the callback is an async function it must only use await once!\n * await trx.step(async () => {\n * await collection.save(data);\n * await collection.save(moreData); // WRONG\n * });\n *\n * // BAD! Callback function must use only one arangojs call!\n * await trx.step(() => {\n * return collection.save(data)\n * .then(() => collection.save(moreData)); // WRONG\n * });\n *\n * // BETTER: Wrap every arangojs method call that should be part of the\n * // transaction in a separate `trx.step` call\n * await trx.step(() => collection.save(data));\n * await trx.step(() => collection.save(moreData));\n * ```\n *\n * @example\n * ```js\n * // BAD! If the callback is an async function it must not await before\n * // calling an arangojs method!\n * await trx.step(async () => {\n * await doSomethingElse();\n * return collection.save(data); // WRONG\n * });\n *\n * // BAD! Any arangojs inside the callback must not happen inside a promise\n * // method!\n * await trx.step(() => {\n * return doSomethingElse()\n * .then(() => collection.save(data)); // WRONG\n * });\n *\n * // BETTER: Perform any async logic needed outside the `trx.step` call\n * await doSomethingElse();\n * await trx.step(() => collection.save(data));\n *\n * // OKAY: You can perform async logic in the callback after the arangojs\n * // method call as long as it does not involve additional arangojs method\n * // calls, but this makes it easy to make mistakes later\n * await trx.step(async () => {\n * await collection.save(data);\n * await doSomethingDifferent(); // no arangojs method calls allowed\n * });\n * ```\n *\n * @example\n * ```js\n * // BAD! The callback should not use any functions that themselves use any\n * // arangojs methods!\n * async function saveSomeData() {\n * await collection.save(data);\n * await collection.save(moreData);\n * }\n * await trx.step(() => saveSomeData()); // WRONG\n *\n * // BETTER: Pass the transaction to functions that need to call arangojs\n * // methods inside a transaction\n * async function saveSomeData(trx) {\n * await trx.step(() => collection.save(data));\n * await trx.step(() => collection.save(moreData));\n * }\n * await saveSomeData(); // no `trx.step` call needed\n * ```\n *\n * @example\n * ```js\n * // BAD! You must wait for the promise to resolve (or await on the\n * // `trx.step` call) before calling `trx.step` again!\n * trx.step(() => collection.save(data)); // WRONG\n * await trx.step(() => collection.save(moreData));\n *\n * // BAD! The trx.step callback can not make multiple calls to async arangojs\n * // methods, not even using Promise.all!\n * await trx.step(() => Promise.all([ // WRONG\n * collection.save(data),\n * collection.save(moreData),\n * ]));\n *\n * // BAD! Multiple `trx.step` calls can not run in parallel!\n * await Promise.all([ // WRONG\n * trx.step(() => collection.save(data)),\n * trx.step(() => collection.save(moreData)),\n * ]));\n *\n * // BETTER: Always call `trx.step` sequentially, one after the other\n * await trx.step(() => collection.save(data));\n * await trx.step(() => collection.save(moreData));\n *\n * // OKAY: The then callback can be used if async/await is not available\n * trx.step(() => collection.save(data))\n * .then(() => trx.step(() => collection.save(moreData)));\n * ```\n *\n * @example\n * ```js\n * // BAD! The callback will return an empty promise that resolves before\n * // the inner arangojs method call has even talked to ArangoDB!\n * await trx.step(async () => {\n * collection.save(data); // WRONG\n * });\n *\n * // BETTER: Use an arrow function so you don't forget to return\n * await trx.step(() => collection.save(data));\n *\n * // OKAY: Remember to always return when using a function body\n * await trx.step(() => {\n * return collection.save(data); // easy to forget!\n * });\n *\n * // OKAY: You do not have to use arrow functions but it helps\n * await trx.step(function () {\n * return collection.save(data);\n * });\n * ```\n *\n * @example\n * ```js\n * // BAD! You can not pass promises instead of a callback!\n * await trx.step(collection.save(data)); // WRONG\n *\n * // BETTER: Wrap the code in a function and pass the function instead\n * await trx.step(() => collection.save(data));\n * ```\n *\n * @example\n * ```js\n * // WORSE: Calls to non-async arangojs methods don't need to be performed\n * // as part of a transaction\n * const collection = await trx.step(() => db.collection(\"my-documents\"));\n *\n * // BETTER: If an arangojs method is not async and doesn't return promises,\n * // call it without `trx.step`\n * const collection = db.collection(\"my-documents\");\n * ```\n */\n step<T>(callback: () => Promise<T>): Promise<T> {\n const conn = (this._db as any)._connection as Connection;\n conn.setTransactionId(this.id);\n try {\n const promise = callback();\n if (!promise) {\n throw new Error(\n \"Transaction callback was not an async function or did not return a promise!\"\n );\n }\n return Promise.resolve(promise);\n } finally {\n conn.clearTransactionId();\n }\n }\n}\n"]}
|