Comparing version 6.10.0 to 6.11.0
@@ -8,2 +8,46 @@ # Changelog | ||
## [6.11.0] - 2019-08-16 | ||
### Changed | ||
- Renamed `db.transaction` to `db.executeTransaction` | ||
The method for executing server-side transactions is now called | ||
`executeTransaction` and the `params` argument now must be passed via the | ||
`options` object. | ||
For backwards-compatible the new `db.transaction` method will continue to | ||
behave like before when passed an `action` string as the second argument. | ||
Note that this behavior is deprecated and will be removed in arangojs 7. | ||
### Added | ||
- Added support for ArangoDB 3.5 streaming transactions | ||
New streaming transactions can be created using `db.beginTransaction` and | ||
existing streaming transactions can be accessed by passing the transaction ID | ||
to `db.transaction`. | ||
See the documentation of the `transaction.run` method for examples of using | ||
streaming transactions with arangojs. | ||
- Added support for ArangoDB 3.5 Analyzers API | ||
See the documentation of the `database.analyzer` method and the `Analyzer` | ||
instances for information on using this API. | ||
- Added `collection.getResponsibleShard` method | ||
- Added support for new ArangoDB 3.5 collection properties | ||
- Added support for new ArangoDB 3.5 view properties | ||
### Fixed | ||
- Fixed a problem causing empty nested AQL expressions to be converted to bind variables | ||
Nesting an empty AQL expression like the result of calling `aql.join` with an empty | ||
array would previously result in the AQL expression not being recognised and being | ||
converted to an object bind variable instead. | ||
## [6.10.0] - 2018-12-22 | ||
@@ -424,2 +468,3 @@ | ||
[6.11.0]: https://github.com/arangodb/arangojs/compare/v6.10.0...v6.11.0 | ||
[6.10.0]: https://github.com/arangodb/arangojs/compare/v6.9.0...v6.10.0 | ||
@@ -426,0 +471,0 @@ [6.9.0]: https://github.com/arangodb/arangojs/compare/v6.8.0...v6.9.0 |
@@ -5,3 +5,3 @@ "use strict"; | ||
function isAqlQuery(query) { | ||
return Boolean(query && query.query && query.bindVars); | ||
return Boolean(query && typeof query.query === "string" && query.bindVars); | ||
} | ||
@@ -8,0 +8,0 @@ exports.isAqlQuery = isAqlQuery; |
/// <reference types="node" /> | ||
import { Connection } from "./connection"; | ||
import { ArrayCursor } from "./cursor"; | ||
import { CollectionChecksum, CollectionFigures, CollectionProperties, CollectionPropertiesOptions, CreateCollectionOptions, CreateCollectionQueryOptions, Document, DocumentData, Edge, InsertOptions, RemoveByExampleOptions, RemoveOptions, ReplaceOptions, UpdateByExampleOptions, UpdateOptions } from "./util/types"; | ||
export declare enum CollectionType { | ||
@@ -45,3 +46,3 @@ DOCUMENT_COLLECTION = 2, | ||
export declare const COLLECTION_NOT_FOUND = 1203; | ||
export declare abstract class BaseCollection implements ArangoCollection { | ||
export declare abstract class BaseCollection<T extends object = any> implements ArangoCollection { | ||
isArangoCollection: true; | ||
@@ -60,11 +61,11 @@ name: string; | ||
exists(): Promise<boolean>; | ||
create(properties?: any): Promise<any>; | ||
properties(): Promise<any>; | ||
create(properties?: CreateCollectionOptions & CreateCollectionQueryOptions): Promise<any>; | ||
properties(): Promise<CollectionProperties>; | ||
count(): Promise<any>; | ||
figures(): Promise<any>; | ||
figures(): Promise<CollectionFigures>; | ||
revision(): Promise<any>; | ||
checksum(opts?: any): Promise<any>; | ||
checksum(opts?: any): Promise<CollectionChecksum>; | ||
load(count?: boolean): Promise<any>; | ||
unload(): Promise<any>; | ||
setProperties(properties: any): Promise<any>; | ||
setProperties(properties: CollectionPropertiesOptions): Promise<any>; | ||
rename(name: string): Promise<any>; | ||
@@ -74,9 +75,10 @@ rotate(): Promise<any>; | ||
drop(opts?: any): Promise<any>; | ||
getResponsibleShard(document: Object): Promise<string>; | ||
documentExists(documentHandle: DocumentHandle): Promise<boolean>; | ||
document(documentHandle: DocumentHandle, graceful: boolean): Promise<any>; | ||
document(documentHandle: DocumentHandle, opts?: DocumentReadOptions): Promise<any>; | ||
replace(documentHandle: DocumentHandle, newValue: any, opts?: any): Promise<any>; | ||
update(documentHandle: DocumentHandle, newValue: any, opts?: any): Promise<any>; | ||
bulkUpdate(newValues: any, opts?: any): Promise<any>; | ||
remove(documentHandle: DocumentHandle, opts?: any): Promise<any>; | ||
document(documentHandle: DocumentHandle, graceful: boolean): Promise<Document<T>>; | ||
document(documentHandle: DocumentHandle, opts?: DocumentReadOptions): Promise<Document<T>>; | ||
replace(documentHandle: DocumentHandle, newValue: Object | Array<Object>, opts?: ReplaceOptions): Promise<any>; | ||
update(documentHandle: DocumentHandle, newValue: Object | Array<Object>, opts?: UpdateOptions): Promise<any>; | ||
bulkUpdate(newValues: Object | Array<Object>, opts?: any): Promise<any>; | ||
remove(documentHandle: DocumentHandle, opts?: RemoveOptions): Promise<any>; | ||
list(type?: string): Promise<any>; | ||
@@ -89,5 +91,8 @@ all(opts?: any): Promise<ArrayCursor>; | ||
firstExample(example: any): Promise<any>; | ||
removeByExample(example: any, opts?: any): Promise<any>; | ||
replaceByExample(example: any, newValue: any, opts?: any): Promise<any>; | ||
updateByExample(example: any, newValue: any, opts?: any): Promise<any>; | ||
removeByExample(example: any, opts?: RemoveByExampleOptions): Promise<any>; | ||
replaceByExample(example: any, newValue: any, opts?: { | ||
waitForSync?: boolean; | ||
limit?: number; | ||
}): Promise<any>; | ||
updateByExample(example: any, newValue: any, opts?: UpdateByExampleOptions): Promise<any>; | ||
lookupByKeys(keys: string[]): Promise<any>; | ||
@@ -108,23 +113,16 @@ removeByKeys(keys: string[], options: any): Promise<any>; | ||
} | ||
export interface DocumentSaveOptions { | ||
waitForSync?: boolean; | ||
returnNew?: boolean; | ||
returnOld?: boolean; | ||
overwrite?: boolean; | ||
silent?: boolean; | ||
} | ||
export declare class DocumentCollection extends BaseCollection { | ||
export declare class DocumentCollection<T extends object = any> extends BaseCollection<T> { | ||
type: CollectionType; | ||
constructor(connection: Connection, name: string); | ||
save(data: any, opts?: DocumentSaveOptions | boolean): Promise<any>; | ||
save(data: DocumentData<T> | Array<DocumentData<T>>, opts?: InsertOptions | boolean): Promise<any>; | ||
} | ||
export declare class EdgeCollection extends BaseCollection { | ||
export declare class EdgeCollection<T extends object = any> extends BaseCollection<T> { | ||
type: CollectionType; | ||
constructor(connection: Connection, name: string); | ||
protected _documentPath(documentHandle: DocumentHandle): string; | ||
edge(documentHandle: DocumentHandle, graceful: boolean): Promise<any>; | ||
edge(documentHandle: DocumentHandle, opts?: DocumentReadOptions): Promise<any>; | ||
save(data: any, opts?: DocumentSaveOptions | boolean): Promise<any>; | ||
save(data: any, fromId: DocumentHandle, toId: DocumentHandle, opts?: DocumentSaveOptions | boolean): Promise<any>; | ||
protected _edges(documentHandle: DocumentHandle, direction: any): Promise<any>; | ||
edge(documentHandle: DocumentHandle, graceful: boolean): Promise<Edge<T>>; | ||
edge(documentHandle: DocumentHandle, opts?: DocumentReadOptions): Promise<Edge<T>>; | ||
save(data: T | Array<T>, opts?: InsertOptions | boolean): Promise<any>; | ||
save(data: T | Array<T>, fromId: DocumentHandle, toId: DocumentHandle, opts?: InsertOptions | boolean): Promise<any>; | ||
protected _edges(documentHandle: DocumentHandle, direction?: "in" | "out"): Promise<any>; | ||
edges(vertex: DocumentHandle): Promise<any>; | ||
@@ -135,3 +133,3 @@ inEdges(vertex: DocumentHandle): Promise<any>; | ||
} | ||
export declare function constructCollection(connection: Connection, data: any): DocumentCollection; | ||
export declare function constructCollection(connection: Connection, data: any): DocumentCollection<any>; | ||
//# sourceMappingURL=collection.d.ts.map |
"use strict"; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -89,6 +80,19 @@ const cursor_1 = require("./cursor"); | ||
create(properties) { | ||
const { waitForSyncReplication = undefined, enforceReplicationFactor = undefined, ...options } = properties || {}; | ||
const qs = {}; | ||
if (typeof waitForSyncReplication === "boolean") { | ||
qs.waitForSyncReplication = waitForSyncReplication ? 1 : 0; | ||
} | ||
if (typeof enforceReplicationFactor === "boolean") { | ||
qs.enforceReplicationFactor = enforceReplicationFactor ? 1 : 0; | ||
} | ||
return this._connection.request({ | ||
method: "POST", | ||
path: "/_api/collection", | ||
body: Object.assign({}, properties, { name: this.name, type: this.type }) | ||
qs, | ||
body: { | ||
...options, | ||
name: this.name, | ||
type: this.type | ||
} | ||
}, res => res.body); | ||
@@ -143,2 +147,9 @@ } | ||
} | ||
getResponsibleShard(document) { | ||
return this._connection.request({ | ||
method: "PUT", | ||
path: `/_api/collection/${this.name}/responsibleShard`, | ||
body: document | ||
}, res => res.body.shardId); | ||
} | ||
documentExists(documentHandle) { | ||
@@ -173,3 +184,2 @@ return this._connection | ||
replace(documentHandle, newValue, opts = {}) { | ||
var _a; | ||
const headers = {}; | ||
@@ -181,3 +191,3 @@ if (typeof opts === "string") { | ||
let rev; | ||
(_a = opts, { rev } = _a, opts = __rest(_a, ["rev"])); | ||
({ rev, ...opts } = opts); | ||
headers["if-match"] = rev; | ||
@@ -194,3 +204,2 @@ } | ||
update(documentHandle, newValue, opts = {}) { | ||
var _a; | ||
const headers = {}; | ||
@@ -202,3 +211,3 @@ if (typeof opts === "string") { | ||
let rev; | ||
(_a = opts, { rev } = _a, opts = __rest(_a, ["rev"])); | ||
({ rev, ...opts } = opts); | ||
headers["if-match"] = rev; | ||
@@ -223,3 +232,2 @@ } | ||
remove(documentHandle, opts = {}) { | ||
var _a; | ||
const headers = {}; | ||
@@ -231,3 +239,3 @@ if (typeof opts === "string") { | ||
let rev; | ||
(_a = opts, { rev } = _a, opts = __rest(_a, ["rev"])); | ||
({ rev, ...opts } = opts); | ||
headers["if-match"] = rev; | ||
@@ -259,3 +267,6 @@ } | ||
path: "/_api/simple/all", | ||
body: Object.assign({}, opts, { collection: this.name }) | ||
body: { | ||
...opts, | ||
collection: this.name | ||
} | ||
}, res => new cursor_1.ArrayCursor(this._connection, res.body, res.host)); | ||
@@ -277,3 +288,6 @@ } | ||
path: "/_api/simple/first", | ||
body: Object.assign({}, opts, { collection: this.name }) | ||
body: { | ||
...opts, | ||
collection: this.name | ||
} | ||
}, res => res.body.result); | ||
@@ -288,3 +302,6 @@ } | ||
path: "/_api/simple/last", | ||
body: Object.assign({}, opts, { collection: this.name }) | ||
body: { | ||
...opts, | ||
collection: this.name | ||
} | ||
}, res => res.body.result); | ||
@@ -296,3 +313,7 @@ } | ||
path: "/_api/simple/by-example", | ||
body: Object.assign({}, opts, { example, collection: this.name }) | ||
body: { | ||
...opts, | ||
example, | ||
collection: this.name | ||
} | ||
}, res => new cursor_1.ArrayCursor(this._connection, res.body, res.host)); | ||
@@ -314,3 +335,7 @@ } | ||
path: "/_api/simple/remove-by-example", | ||
body: Object.assign({}, opts, { example, collection: this.name }) | ||
body: { | ||
...opts, | ||
example, | ||
collection: this.name | ||
} | ||
}, res => res.body); | ||
@@ -322,4 +347,8 @@ } | ||
path: "/_api/simple/replace-by-example", | ||
body: Object.assign({}, opts, { example, | ||
newValue, collection: this.name }) | ||
body: { | ||
...opts, | ||
example, | ||
newValue, | ||
collection: this.name | ||
} | ||
}, res => res.body); | ||
@@ -331,4 +360,8 @@ } | ||
path: "/_api/simple/update-by-example", | ||
body: Object.assign({}, opts, { example, | ||
newValue, collection: this.name }) | ||
body: { | ||
...opts, | ||
example, | ||
newValue, | ||
collection: this.name | ||
} | ||
}, res => res.body); | ||
@@ -357,4 +390,3 @@ } | ||
} | ||
import(data, _a = {}) { | ||
var { type = "auto" } = _a, opts = __rest(_a, ["type"]); | ||
import(data, { type = "auto", ...opts } = {}) { | ||
if (Array.isArray(data)) { | ||
@@ -368,3 +400,7 @@ data = data.map(line => JSON.stringify(line)).join("\r\n") + "\r\n"; | ||
isBinary: true, | ||
qs: Object.assign({ type: type === null ? undefined : type }, opts, { collection: this.name }) | ||
qs: { | ||
type: type === null ? undefined : type, | ||
...opts, | ||
collection: this.name | ||
} | ||
}, res => res.body); | ||
@@ -402,3 +438,3 @@ } | ||
path: "/_api/index", | ||
body: Object.assign({}, opts, { type: "cap" }), | ||
body: { ...opts, type: "cap" }, | ||
qs: { collection: this.name } | ||
@@ -417,3 +453,3 @@ }, res => res.body); | ||
path: "/_api/index", | ||
body: Object.assign({ unique: false }, opts, { type: "hash", fields: fields }), | ||
body: { unique: false, ...opts, type: "hash", fields: fields }, | ||
qs: { collection: this.name } | ||
@@ -432,3 +468,3 @@ }, res => res.body); | ||
path: "/_api/index", | ||
body: Object.assign({ unique: false }, opts, { type: "skiplist", fields: fields }), | ||
body: { unique: false, ...opts, type: "skiplist", fields: fields }, | ||
qs: { collection: this.name } | ||
@@ -447,3 +483,3 @@ }, res => res.body); | ||
path: "/_api/index", | ||
body: Object.assign({ unique: false }, opts, { type: "persistent", fields: fields }), | ||
body: { unique: false, ...opts, type: "persistent", fields: fields }, | ||
qs: { collection: this.name } | ||
@@ -459,3 +495,3 @@ }, res => res.body); | ||
path: "/_api/index", | ||
body: Object.assign({}, opts, { fields, type: "geo" }), | ||
body: { ...opts, fields, type: "geo" }, | ||
qs: { collection: this.name } | ||
@@ -481,4 +517,8 @@ }, res => res.body); | ||
path: "/_api/simple/fulltext", | ||
body: Object.assign({}, opts, { attribute, | ||
query, collection: this.name }) | ||
body: { | ||
...opts, | ||
attribute, | ||
query, | ||
collection: this.name | ||
} | ||
}, res => new cursor_1.ArrayCursor(this._connection, res.body, res.host)); | ||
@@ -502,3 +542,6 @@ } | ||
body: data, | ||
qs: Object.assign({}, opts, { collection: this.name }) | ||
qs: { | ||
...opts, | ||
collection: this.name | ||
} | ||
}, res => res.body); | ||
@@ -534,7 +577,15 @@ } | ||
if (toId !== undefined) { | ||
data._from = this._documentHandle(fromIdOrOpts); | ||
data._to = this._documentHandle(toId); | ||
const fromId = this._documentHandle(fromIdOrOpts); | ||
toId = this._documentHandle(toId); | ||
if (Array.isArray(data)) { | ||
data = data.map(data => Object.assign(data, { _from: fromId, _to: toId })); | ||
} | ||
else { | ||
data = Object.assign(data, { _from: fromId, _to: toId }); | ||
} | ||
} | ||
else if (fromIdOrOpts !== undefined) { | ||
opts = fromIdOrOpts; | ||
else { | ||
if (fromIdOrOpts !== undefined) { | ||
opts = fromIdOrOpts; | ||
} | ||
} | ||
@@ -545,2 +596,5 @@ if (typeof opts === "boolean") { | ||
if (this._connection.arangoMajor <= 2) { | ||
if (Array.isArray(data)) { | ||
throw new Error("ArangoDB 2 does not support batch operations"); | ||
} | ||
return this._connection.request({ | ||
@@ -550,3 +604,8 @@ method: "POST", | ||
body: data, | ||
qs: Object.assign({}, opts, { collection: this.name, from: data._from, to: data._to }) | ||
qs: { | ||
...opts, | ||
collection: this.name, | ||
from: data._from, | ||
to: data._to | ||
} | ||
}, res => res.body); | ||
@@ -558,3 +617,6 @@ } | ||
body: data, | ||
qs: Object.assign({}, opts, { collection: this.name }) | ||
qs: { | ||
...opts, | ||
collection: this.name | ||
} | ||
}, res => res.body); | ||
@@ -572,3 +634,3 @@ } | ||
edges(vertex) { | ||
return this._edges(vertex, undefined); | ||
return this._edges(vertex); | ||
} | ||
@@ -585,3 +647,7 @@ inEdges(vertex) { | ||
path: "/_api/traversal", | ||
body: Object.assign({}, opts, { startVertex, edgeCollection: this.name }) | ||
body: { | ||
...opts, | ||
startVertex, | ||
edgeCollection: this.name | ||
} | ||
}, res => res.body.result); | ||
@@ -588,0 +654,0 @@ } |
@@ -52,2 +52,3 @@ import { ArangojsResponse } from "./util/request"; | ||
private _activeDirtyHost; | ||
private _transactionId; | ||
constructor(config?: Config); | ||
@@ -62,2 +63,4 @@ private readonly _databasePath; | ||
setDatabaseName(databaseName: string): void; | ||
setTransactionId(transactionId: string): void; | ||
clearTransactionId(): void; | ||
setHeader(key: string, value: string): void; | ||
@@ -64,0 +67,0 @@ close(): void; |
"use strict"; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -33,2 +24,3 @@ const querystring_1 = require("querystring"); | ||
this._urls = []; | ||
this._transactionId = null; | ||
if (typeof config === "string") | ||
@@ -46,7 +38,13 @@ config = { url: config }; | ||
this._agentOptions = request_1.isBrowser | ||
? Object.assign({}, config.agentOptions) : Object.assign({ maxSockets: 3, keepAlive: true, keepAliveMsecs: 1000 }, config.agentOptions); | ||
? { ...config.agentOptions } | ||
: { | ||
maxSockets: 3, | ||
keepAlive: true, | ||
keepAliveMsecs: 1000, | ||
...config.agentOptions | ||
}; | ||
this._maxTasks = this._agentOptions.maxSockets || 3; | ||
if (this._agentOptions.keepAlive) | ||
this._maxTasks *= 2; | ||
this._headers = Object.assign({}, config.headers); | ||
this._headers = { ...config.headers }; | ||
this._loadBalancingStrategy = config.loadBalancingStrategy || "NONE"; | ||
@@ -97,3 +95,3 @@ this._useFailOver = this._loadBalancingStrategy !== "ROUND_ROBIN"; | ||
this._activeTasks += 1; | ||
this._hosts[host](task.options, (err, res) => { | ||
const callback = (err, res) => { | ||
this._activeTasks -= 1; | ||
@@ -138,3 +136,9 @@ if (err) { | ||
this._runQueue(); | ||
}); | ||
}; | ||
try { | ||
this._hosts[host](task.options, callback); | ||
} | ||
catch (e) { | ||
callback(e); | ||
} | ||
} | ||
@@ -181,2 +185,8 @@ _buildUrl({ absolutePath = false, basePath, path, qs }) { | ||
} | ||
setTransactionId(transactionId) { | ||
this._transactionId = transactionId; | ||
} | ||
clearTransactionId() { | ||
this._transactionId = null; | ||
} | ||
setHeader(key, value) { | ||
@@ -191,4 +201,3 @@ this._headers[key] = value; | ||
} | ||
request(_a, getter) { | ||
var { host, method = "GET", body, expectBinary = false, isBinary = false, allowDirtyRead = false, timeout = 0, headers } = _a, urlInfo = __rest(_a, ["host", "method", "body", "expectBinary", "isBinary", "allowDirtyRead", "timeout", "headers"]); | ||
request({ host, method = "GET", body, expectBinary = false, isBinary = false, allowDirtyRead = false, timeout = 0, headers, ...urlInfo }, getter) { | ||
return new Promise((resolve, reject) => { | ||
@@ -208,3 +217,10 @@ let contentType = "text/plain"; | ||
} | ||
const extraHeaders = Object.assign({}, this._headers, { "content-type": contentType, "x-arango-version": String(this._arangoVersion) }); | ||
const extraHeaders = { | ||
...this._headers, | ||
"content-type": contentType, | ||
"x-arango-version": String(this._arangoVersion) | ||
}; | ||
if (this._transactionId) { | ||
extraHeaders["x-arango-trx-id"] = this._transactionId; | ||
} | ||
this._queue.push({ | ||
@@ -216,3 +232,3 @@ retries: 0, | ||
url: this._buildUrl(urlInfo), | ||
headers: Object.assign({}, extraHeaders, headers), | ||
headers: { ...extraHeaders, ...headers }, | ||
timeout, | ||
@@ -219,0 +235,0 @@ method, |
/// <reference types="node" /> | ||
import { AnalyzerDescription, ArangoAnalyzer } from "./analyzer"; | ||
import { AqlLiteral, AqlQuery } from "./aql-query"; | ||
@@ -8,4 +9,11 @@ import { ArangoCollection, DocumentCollection, EdgeCollection } from "./collection"; | ||
import { Route } from "./route"; | ||
import { ArangoTransaction } from "./transaction"; | ||
import { ArangoSearchView, ArangoView, ViewType } from "./view"; | ||
export declare type TransactionCollectionsObject = { | ||
exclusive?: string | string[]; | ||
write?: string | string[]; | ||
read?: string | string[]; | ||
}; | ||
export declare type TransactionCollections = string | ArangoCollection | (string | ArangoCollection)[] | { | ||
exclusive?: string | ArangoCollection | (string | ArangoCollection)[]; | ||
write?: string | ArangoCollection | (string | ArangoCollection)[]; | ||
@@ -15,5 +23,8 @@ read?: string | ArangoCollection | (string | ArangoCollection)[]; | ||
export declare type TransactionOptions = { | ||
allowImplicit?: boolean; | ||
lockTimeout?: number; | ||
maxTransactionSize?: number; | ||
/** @deprecated removed in ArangoDB 3.4, RocksDB-only */ | ||
intermediateCommitCount?: number; | ||
/** @deprecated removed in ArangoDB 3.4, RocksDB-only */ | ||
intermediateCommitSize?: number; | ||
@@ -46,5 +57,7 @@ waitForSync?: boolean; | ||
maxWarningsCount?: number; | ||
/** RocksDB-only */ | ||
intermediateCommitCount?: number; | ||
satteliteSyncWait?: number; | ||
fullCount?: boolean; | ||
/** RocksDB-only */ | ||
intermediateCommitSize?: number; | ||
@@ -133,8 +146,10 @@ optimizer?: { | ||
readonly name: string | null; | ||
version(): Promise<any>; | ||
route(path?: string, headers?: Object): Route; | ||
acquireHostList(): Promise<void>; | ||
close(): void; | ||
useDatabase(databaseName: string): this; | ||
login(username?: string, password?: string): Promise<string>; | ||
useBearerAuth(token: string): this; | ||
useBasicAuth(username?: string, password?: string): this; | ||
useDatabase(databaseName: string): this; | ||
get(): Promise<any>; | ||
@@ -146,18 +161,24 @@ exists(): Promise<boolean>; | ||
dropDatabase(databaseName: string): Promise<any>; | ||
collection(collectionName: string): DocumentCollection; | ||
edgeCollection(collectionName: string): EdgeCollection; | ||
collection<T extends object = any>(collectionName: string): DocumentCollection<T>; | ||
edgeCollection<T extends object = any>(collectionName: string): EdgeCollection<T>; | ||
listCollections(excludeSystem?: boolean): Promise<any>; | ||
collections(excludeSystem?: boolean): Promise<ArangoCollection[]>; | ||
truncate(excludeSystem?: boolean): Promise<[{}, {}, {}, {}, {}, {}, {}, {}, {}, {}]>; | ||
truncate(excludeSystem?: boolean): Promise<[unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown]>; | ||
arangoSearchView(viewName: string): ArangoSearchView; | ||
listViews(): Promise<ViewDescription[]>; | ||
views(): Promise<ArangoView[]>; | ||
analyzer(name: string): ArangoAnalyzer; | ||
listAnalyzers(): Promise<AnalyzerDescription[]>; | ||
analyzers(): Promise<ArangoAnalyzer[]>; | ||
executeTransaction(collections: TransactionCollections, action: string, options?: TransactionOptions & { | ||
params?: any; | ||
}): Promise<any>; | ||
transaction(transactionId: string): ArangoTransaction; | ||
transaction(collections: TransactionCollections, action: string, params?: any, options?: TransactionOptions): Promise<any>; | ||
transaction(collections: TransactionCollections, action: string, lockTimeout?: number): Promise<any>; | ||
transaction(collections: TransactionCollections, action: string, params?: any, lockTimeout?: number): Promise<any>; | ||
beginTransaction(collections: TransactionCollections, options?: TransactionOptions): Promise<ArangoTransaction>; | ||
graph(graphName: string): Graph; | ||
listGraphs(): Promise<any>; | ||
graphs(): Promise<Graph[]>; | ||
transaction(collections: TransactionCollections, action: string): Promise<any>; | ||
transaction(collections: TransactionCollections, action: string, params?: Object): Promise<any>; | ||
transaction(collections: TransactionCollections, action: string, params?: Object, options?: TransactionOptions): Promise<any>; | ||
transaction(collections: TransactionCollections, action: string, lockTimeout?: number): Promise<any>; | ||
transaction(collections: TransactionCollections, action: string, params?: Object, lockTimeout?: number): Promise<any>; | ||
query(query: string | AqlQuery | AqlLiteral): Promise<ArrayCursor>; | ||
@@ -204,5 +225,3 @@ query(query: AqlQuery, opts?: QueryOptions): Promise<ArrayCursor>; | ||
commitLocalServiceState(replace?: boolean): Promise<void>; | ||
version(): Promise<any>; | ||
login(username?: string, password?: string): Promise<string>; | ||
} | ||
//# sourceMappingURL=database.d.ts.map |
"use strict"; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const analyzer_1 = require("./analyzer"); | ||
const aql_query_1 = require("./aql-query"); | ||
@@ -19,2 +11,3 @@ const collection_1 = require("./collection"); | ||
const route_1 = require("./route"); | ||
const transaction_1 = require("./transaction"); | ||
const btoa_1 = require("./util/btoa"); | ||
@@ -38,2 +31,9 @@ const multipart_1 = require("./util/multipart"); | ||
} | ||
//#region misc | ||
version() { | ||
return this._connection.request({ | ||
method: "GET", | ||
path: "/_api/version" | ||
}, res => res.body); | ||
} | ||
route(path, headers) { | ||
@@ -52,6 +52,13 @@ return new route_1.Route(this._connection, path, headers); | ||
} | ||
// Database manipulation | ||
useDatabase(databaseName) { | ||
this._connection.setDatabaseName(databaseName); | ||
return this; | ||
//#endregion | ||
//#region auth | ||
login(username = "root", password = "") { | ||
return this._connection.request({ | ||
method: "POST", | ||
path: "/_open/auth", | ||
body: { username, password } | ||
}, res => { | ||
this.useBearerAuth(res.body.jwt); | ||
return res.body.jwt; | ||
}); | ||
} | ||
@@ -66,2 +73,8 @@ useBearerAuth(token) { | ||
} | ||
//#endregion | ||
//#region databases | ||
useDatabase(databaseName) { | ||
this._connection.setDatabaseName(databaseName); | ||
return this; | ||
} | ||
get() { | ||
@@ -97,3 +110,4 @@ return this._connection.request({ path: "/_api/database/current" }, res => res.body.result); | ||
} | ||
// Collection manipulation | ||
//#endregion | ||
//#region collections | ||
collection(collectionName) { | ||
@@ -124,3 +138,4 @@ return new collection_1.DocumentCollection(this._connection, collectionName); | ||
} | ||
// Views | ||
//#endregion | ||
//#region views | ||
arangoSearchView(viewName) { | ||
@@ -136,14 +151,31 @@ return new view_1.ArangoSearchView(this._connection, viewName); | ||
} | ||
// Graph manipulation | ||
graph(graphName) { | ||
return new graph_1.Graph(this._connection, graphName); | ||
//#endregion | ||
//#region analyzers | ||
analyzer(name) { | ||
return new analyzer_1.ArangoAnalyzer(this._connection, name); | ||
} | ||
listGraphs() { | ||
return this._connection.request({ path: "/_api/gharial" }, res => res.body.graphs); | ||
listAnalyzers() { | ||
return this._connection.request({ path: "/_api/analyzer" }, res => res.body.result); | ||
} | ||
async graphs() { | ||
const graphs = await this.listGraphs(); | ||
return graphs.map((data) => this.graph(data._key)); | ||
async analyzers() { | ||
const analyzers = await this.listAnalyzers(); | ||
return analyzers.map(data => this.analyzer(data.name)); | ||
} | ||
transaction(collections, action, params, options) { | ||
//#endregion | ||
//#region transactions | ||
executeTransaction(collections, action, options) { | ||
return this._connection.request({ | ||
method: "POST", | ||
path: "/_api/transaction", | ||
body: { | ||
collections: coerceTransactionCollections(collections), | ||
action, | ||
...options | ||
} | ||
}, res => res.body.result); | ||
} | ||
transaction(collectionsOrId, action, params, options) { | ||
if (arguments.length === 1 && typeof collectionsOrId === "string") { | ||
return new transaction_1.ArangoTransaction(this._connection, collectionsOrId); | ||
} | ||
if (typeof params === "number") { | ||
@@ -156,36 +188,29 @@ options = params; | ||
} | ||
if (typeof collections === "string") { | ||
collections = { write: [collections] }; | ||
} | ||
else if (Array.isArray(collections)) { | ||
collections = { write: collections.map(colToString) }; | ||
} | ||
else if (collection_1.isArangoCollection(collections)) { | ||
collections = { write: colToString(collections) }; | ||
} | ||
else if (collections && typeof collections === "object") { | ||
collections = Object.assign({}, collections); | ||
if (collections.read) { | ||
if (!Array.isArray(collections.read)) { | ||
collections.read = colToString(collections.read); | ||
} | ||
else | ||
collections.read = collections.read.map(colToString); | ||
} | ||
if (collections.write) { | ||
if (!Array.isArray(collections.write)) { | ||
collections.write = colToString(collections.write); | ||
} | ||
else | ||
collections.write = collections.write.map(colToString); | ||
} | ||
} | ||
return this.executeTransaction(collectionsOrId, action, { | ||
params, | ||
...options | ||
}); | ||
} | ||
beginTransaction(collections, options) { | ||
return this._connection.request({ | ||
method: "POST", | ||
path: "/_api/transaction", | ||
body: Object.assign({ collections, | ||
action, | ||
params }, options) | ||
}, res => res.body.result); | ||
path: "/_api/transaction/begin", | ||
body: { | ||
collections: coerceTransactionCollections(collections), | ||
...options | ||
} | ||
}, res => new transaction_1.ArangoTransaction(this._connection, res.body.result.id)); | ||
} | ||
//#endregion | ||
//#region graphs | ||
graph(graphName) { | ||
return new graph_1.Graph(this._connection, graphName); | ||
} | ||
listGraphs() { | ||
return this._connection.request({ path: "/_api/gharial" }, res => res.body.graphs); | ||
} | ||
async graphs() { | ||
const graphs = await this.listGraphs(); | ||
return graphs.map((data) => this.graph(data._key)); | ||
} | ||
query(query, bindVars, opts) { | ||
@@ -200,7 +225,7 @@ if (aql_query_1.isAqlQuery(query)) { | ||
} | ||
const _a = opts || {}, { allowDirtyRead = undefined, timeout = undefined } = _a, extra = __rest(_a, ["allowDirtyRead", "timeout"]); | ||
const { allowDirtyRead = undefined, timeout = undefined, ...extra } = opts || {}; | ||
return this._connection.request({ | ||
method: "POST", | ||
path: "/_api/cursor", | ||
body: Object.assign({}, extra, { query, bindVars }), | ||
body: { ...extra, query, bindVars }, | ||
allowDirtyRead, | ||
@@ -275,3 +300,4 @@ timeout | ||
} | ||
// Function management | ||
//#endregion | ||
//#region functions | ||
listFunctions() { | ||
@@ -294,3 +320,4 @@ return this._connection.request({ path: "/_api/aqlfunction" }, res => res.body); | ||
} | ||
// Service management | ||
//#endregion | ||
//#region services | ||
listServices() { | ||
@@ -300,3 +327,3 @@ return this._connection.request({ path: "/_api/foxx" }, res => res.body); | ||
async installService(mount, source, opts = {}) { | ||
const { configuration, dependencies } = opts, qs = __rest(opts, ["configuration", "dependencies"]); | ||
const { configuration, dependencies, ...qs } = opts; | ||
const req = await multipart_1.toForm({ | ||
@@ -307,6 +334,12 @@ configuration, | ||
}); | ||
return await this._connection.request(Object.assign({}, req, { method: "POST", path: "/_api/foxx", isBinary: true, qs: Object.assign({}, qs, { mount }) }), res => res.body); | ||
return await this._connection.request({ | ||
...req, | ||
method: "POST", | ||
path: "/_api/foxx", | ||
isBinary: true, | ||
qs: { ...qs, mount } | ||
}, res => res.body); | ||
} | ||
async upgradeService(mount, source, opts = {}) { | ||
const { configuration, dependencies } = opts, qs = __rest(opts, ["configuration", "dependencies"]); | ||
const { configuration, dependencies, ...qs } = opts; | ||
const req = await multipart_1.toForm({ | ||
@@ -317,6 +350,12 @@ configuration, | ||
}); | ||
return await this._connection.request(Object.assign({}, req, { method: "PATCH", path: "/_api/foxx/service", isBinary: true, qs: Object.assign({}, qs, { mount }) }), res => res.body); | ||
return await this._connection.request({ | ||
...req, | ||
method: "PATCH", | ||
path: "/_api/foxx/service", | ||
isBinary: true, | ||
qs: { ...qs, mount } | ||
}, res => res.body); | ||
} | ||
async replaceService(mount, source, opts = {}) { | ||
const { configuration, dependencies } = opts, qs = __rest(opts, ["configuration", "dependencies"]); | ||
const { configuration, dependencies, ...qs } = opts; | ||
const req = await multipart_1.toForm({ | ||
@@ -327,3 +366,9 @@ configuration, | ||
}); | ||
return await this._connection.request(Object.assign({}, req, { method: "PUT", path: "/_api/foxx/service", isBinary: true, qs: Object.assign({}, qs, { mount }) }), res => res.body); | ||
return await this._connection.request({ | ||
...req, | ||
method: "PUT", | ||
path: "/_api/foxx/service", | ||
isBinary: true, | ||
qs: { ...qs, mount } | ||
}, res => res.body); | ||
} | ||
@@ -334,3 +379,3 @@ uninstallService(mount, opts = {}) { | ||
path: "/_api/foxx/service", | ||
qs: Object.assign({}, opts, { mount }) | ||
qs: { ...opts, mount } | ||
}, () => undefined); | ||
@@ -484,3 +529,6 @@ } | ||
path: "/_api/foxx/tests", | ||
qs: Object.assign({}, opts, { mount }) | ||
qs: { | ||
...opts, | ||
mount | ||
} | ||
}, res => res.body); | ||
@@ -515,20 +563,34 @@ } | ||
} | ||
version() { | ||
return this._connection.request({ | ||
method: "GET", | ||
path: "/_api/version" | ||
}, res => res.body); | ||
} | ||
exports.Database = Database; | ||
function coerceTransactionCollections(collections) { | ||
if (typeof collections === "string") { | ||
return { write: [collections] }; | ||
} | ||
login(username = "root", password = "") { | ||
return this._connection.request({ | ||
method: "POST", | ||
path: "/_open/auth", | ||
body: { username, password } | ||
}, res => { | ||
this.useBearerAuth(res.body.jwt); | ||
return res.body.jwt; | ||
}); | ||
if (Array.isArray(collections)) { | ||
return { write: collections.map(colToString) }; | ||
} | ||
if (collection_1.isArangoCollection(collections)) { | ||
return { write: colToString(collections) }; | ||
} | ||
const cols = {}; | ||
if (collections) { | ||
if (collections.read) { | ||
cols.read = Array.isArray(collections.read) | ||
? collections.read.map(colToString) | ||
: colToString(collections.read); | ||
} | ||
if (collections.write) { | ||
cols.write = Array.isArray(collections.write) | ||
? collections.write.map(colToString) | ||
: colToString(collections.write); | ||
} | ||
if (collections.exclusive) { | ||
cols.exclusive = Array.isArray(collections.exclusive) | ||
? collections.exclusive.map(colToString) | ||
: colToString(collections.exclusive); | ||
} | ||
} | ||
return cols; | ||
} | ||
exports.Database = Database; | ||
//# sourceMappingURL=database.js.map |
@@ -11,7 +11,7 @@ import { ArangoCollection, BaseCollection, CollectionType, DocumentHandle, DocumentReadOptions, EdgeCollection } from "./collection"; | ||
vertex(documentHandle: DocumentHandle, opts?: DocumentReadOptions): Promise<any>; | ||
save(data: any, opts?: { | ||
save(data: Object | Array<Object>, opts?: { | ||
waitForSync?: boolean; | ||
}): Promise<any>; | ||
replace(documentHandle: DocumentHandle, newValue: any, opts?: any): Promise<any>; | ||
update(documentHandle: DocumentHandle, newValue: any, opts?: any): Promise<any>; | ||
replace(documentHandle: DocumentHandle, newValue: Object | Array<Object>, opts?: any): Promise<any>; | ||
update(documentHandle: DocumentHandle, newValue: Object | Array<Object>, opts?: any): Promise<any>; | ||
remove(documentHandle: DocumentHandle, opts?: any): Promise<any>; | ||
@@ -25,10 +25,10 @@ } | ||
document(documentHandle: DocumentHandle, opts?: DocumentReadOptions): Promise<any>; | ||
save(data: any, opts?: { | ||
save(data: Object | Array<Object>, opts?: { | ||
waitForSync?: boolean; | ||
}): Promise<any>; | ||
save(data: any, fromId: DocumentHandle, toId: DocumentHandle, opts?: { | ||
save(data: Object | Array<Object>, fromId: DocumentHandle, toId: DocumentHandle, opts?: { | ||
waitForSync?: boolean; | ||
}): Promise<any>; | ||
replace(documentHandle: DocumentHandle, newValue: any, opts?: any): Promise<any>; | ||
update(documentHandle: DocumentHandle, newValue: any, opts?: any): Promise<any>; | ||
replace(documentHandle: DocumentHandle, newValue: Object | Array<Object>, opts?: any): Promise<any>; | ||
update(documentHandle: DocumentHandle, newValue: Object | Array<Object>, opts?: any): Promise<any>; | ||
remove(documentHandle: DocumentHandle, opts?: any): Promise<any>; | ||
@@ -35,0 +35,0 @@ } |
"use strict"; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -53,3 +44,2 @@ const collection_1 = require("./collection"); | ||
replace(documentHandle, newValue, opts = {}) { | ||
var _a; | ||
const headers = {}; | ||
@@ -61,3 +51,3 @@ if (typeof opts === "string") { | ||
let rev; | ||
(_a = opts, { rev } = _a, opts = __rest(_a, ["rev"])); | ||
({ rev, ...opts } = opts); | ||
headers["if-match"] = rev; | ||
@@ -74,3 +64,2 @@ } | ||
update(documentHandle, newValue, opts = {}) { | ||
var _a; | ||
const headers = {}; | ||
@@ -82,3 +71,3 @@ if (typeof opts === "string") { | ||
let rev; | ||
(_a = opts, { rev } = _a, opts = __rest(_a, ["rev"])); | ||
({ rev, ...opts } = opts); | ||
headers["if-match"] = rev; | ||
@@ -95,3 +84,2 @@ } | ||
remove(documentHandle, opts = {}) { | ||
var _a; | ||
const headers = {}; | ||
@@ -103,3 +91,3 @@ if (typeof opts === "string") { | ||
let rev; | ||
(_a = opts, { rev } = _a, opts = __rest(_a, ["rev"])); | ||
({ rev, ...opts } = opts); | ||
headers["if-match"] = rev; | ||
@@ -141,12 +129,18 @@ } | ||
} | ||
save(data, fromId, toId, opts) { | ||
if (fromId !== undefined) { | ||
if (toId !== undefined) { | ||
data._from = this._documentHandle(fromId); | ||
data._to = this._documentHandle(toId); | ||
save(data, fromIdOrOpts, toId, opts) { | ||
if (toId !== undefined) { | ||
const fromId = this._documentHandle(fromIdOrOpts); | ||
toId = this._documentHandle(toId); | ||
if (Array.isArray(data)) { | ||
data = data.map(data => ({ ...data, _from: fromId, _to: toId })); | ||
} | ||
else { | ||
opts = fromId; | ||
data = { ...data, _from: fromId, _to: toId }; | ||
} | ||
} | ||
else { | ||
if (fromIdOrOpts !== undefined) { | ||
opts = fromIdOrOpts; | ||
} | ||
} | ||
return this._connection.request({ | ||
@@ -160,3 +154,2 @@ method: "POST", | ||
replace(documentHandle, newValue, opts = {}) { | ||
var _a; | ||
const headers = {}; | ||
@@ -168,3 +161,3 @@ if (typeof opts === "string") { | ||
let rev; | ||
(_a = opts, { rev } = _a, opts = __rest(_a, ["rev"])); | ||
({ rev, ...opts } = opts); | ||
headers["if-match"] = rev; | ||
@@ -181,3 +174,2 @@ } | ||
update(documentHandle, newValue, opts = {}) { | ||
var _a; | ||
const headers = {}; | ||
@@ -189,3 +181,3 @@ if (typeof opts === "string") { | ||
let rev; | ||
(_a = opts, { rev } = _a, opts = __rest(_a, ["rev"])); | ||
({ rev, ...opts } = opts); | ||
headers["if-match"] = rev; | ||
@@ -202,3 +194,2 @@ } | ||
remove(documentHandle, opts = {}) { | ||
var _a; | ||
const headers = {}; | ||
@@ -210,3 +201,3 @@ if (typeof opts === "string") { | ||
let rev; | ||
(_a = opts, { rev } = _a, opts = __rest(_a, ["rev"])); | ||
({ rev, ...opts } = opts); | ||
headers["if-match"] = rev; | ||
@@ -244,3 +235,6 @@ } | ||
path: "/_api/gharial", | ||
body: Object.assign({}, properties, { name: this.name }), | ||
body: { | ||
...properties, | ||
name: this.name | ||
}, | ||
qs: opts | ||
@@ -325,3 +319,7 @@ }, res => res.body.graph); | ||
path: `/_api/traversal`, | ||
body: Object.assign({}, opts, { startVertex, graphName: this.name }) | ||
body: { | ||
...opts, | ||
startVertex, | ||
graphName: this.name | ||
} | ||
}, res => res.body.result); | ||
@@ -328,0 +326,0 @@ } |
"use strict"; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -27,6 +18,8 @@ class Route { | ||
path = `/${path}`; | ||
return new Route(this._connection, this._path + path, Object.assign({}, this._headers, headers)); | ||
return new Route(this._connection, this._path + path, { | ||
...this._headers, | ||
...headers | ||
}); | ||
} | ||
request(_a) { | ||
var { method, path, headers = {} } = _a, opts = __rest(_a, ["method", "path", "headers"]); | ||
request({ method, path, headers = {}, ...opts }) { | ||
if (!path) | ||
@@ -39,3 +32,3 @@ opts.path = ""; | ||
opts.basePath = this._path; | ||
opts.headers = Object.assign({}, this._headers, headers); | ||
opts.headers = { ...this._headers, ...headers }; | ||
opts.method = method ? method.toUpperCase() : "GET"; | ||
@@ -42,0 +35,0 @@ return this._connection.request(opts); |
@@ -103,3 +103,5 @@ "use strict"; | ||
called = true; | ||
callback(e); | ||
setTimeout(() => { | ||
callback(e); | ||
}); | ||
} | ||
@@ -106,0 +108,0 @@ }, { |
"use strict"; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -26,3 +17,3 @@ const url_1 = require("url"); | ||
function createRequest(baseUrl, agentOptions) { | ||
const _a = url_1.parse(baseUrl), { auth } = _a, baseUrlParts = __rest(_a, ["auth"]); | ||
const { auth, ...baseUrlParts } = url_1.parse(baseUrl); | ||
const options = omit(agentOptions, [ | ||
@@ -34,11 +25,15 @@ "keepAlive", | ||
return function request({ method, url, headers, body, timeout, expectBinary }, cb) { | ||
const urlParts = Object.assign({}, baseUrlParts, { pathname: url.pathname | ||
const urlParts = { | ||
...baseUrlParts, | ||
pathname: url.pathname | ||
? baseUrlParts.pathname | ||
? joinPath_1.joinPath(baseUrlParts.pathname, url.pathname) | ||
: url.pathname | ||
: baseUrlParts.pathname, search: url.search | ||
: baseUrlParts.pathname, | ||
search: url.search | ||
? baseUrlParts.search | ||
? `${baseUrlParts.search}&${url.search.slice(1)}` | ||
: url.search | ||
: baseUrlParts.search }); | ||
: baseUrlParts.search | ||
}; | ||
if (!headers["authorization"]) { | ||
@@ -51,6 +46,13 @@ headers["authorization"] = `Basic ${btoa(auth || "root:")}`; | ||
}; | ||
const req = xhr_1.default(Object.assign({ responseType: expectBinary ? "blob" : "text" }, options, { url: url_1.format(urlParts), withCredentials: true, useXDR: true, body, | ||
const req = xhr_1.default({ | ||
responseType: expectBinary ? "blob" : "text", | ||
...options, | ||
url: url_1.format(urlParts), | ||
withCredentials: true, | ||
useXDR: true, | ||
body, | ||
method, | ||
headers, | ||
timeout }), (err, res) => { | ||
timeout | ||
}, (err, res) => { | ||
if (!err) { | ||
@@ -57,0 +59,0 @@ if (!res.body) |
export declare type Errback<T> = (err: Error | null, result?: T) => void; | ||
export declare type KeyGeneratorType = "traditional" | "autoincrement"; | ||
export interface CollectionChecksum { | ||
checksum: string; | ||
revision: string; | ||
} | ||
export interface CollectionFigures { | ||
alive: { | ||
count: number; | ||
size: number; | ||
}; | ||
dead: { | ||
count: number; | ||
size: number; | ||
deletion: number; | ||
}; | ||
datafiles: { | ||
count: number; | ||
fileSize: number; | ||
}; | ||
journals: { | ||
count: number; | ||
fileSize: number; | ||
}; | ||
compactors: { | ||
count: number; | ||
fileSize: number; | ||
}; | ||
shapefiles: { | ||
count: number; | ||
fileSize: number; | ||
}; | ||
shapes: { | ||
count: number; | ||
size: number; | ||
}; | ||
attributes: { | ||
count: number; | ||
size: number; | ||
}; | ||
indexes: { | ||
count: number; | ||
size: number; | ||
}; | ||
lastTick: number; | ||
uncollectedLogfileEntries: number; | ||
documentReferences: number; | ||
waitingFor: string; | ||
compactionStatus: { | ||
time: string; | ||
message: string; | ||
count: number; | ||
filesCombined: number; | ||
bytesRead: number; | ||
bytesWritten: number; | ||
}; | ||
} | ||
export interface CollectionPropertiesOptions { | ||
waitForSync?: boolean; | ||
journalSize?: number; | ||
indexBuckets?: number; | ||
replicationFactor?: number; | ||
minReplicationFactor?: number; | ||
} | ||
export interface CreateCollectionQueryOptions { | ||
waitForSyncReplication?: boolean; | ||
enforceReplicationFactor?: boolean; | ||
} | ||
export interface CreateCollectionOptions { | ||
waitForSync?: boolean; | ||
journalSize?: number; | ||
isVolatile?: boolean; | ||
isSystem?: boolean; | ||
keyOptions?: { | ||
type?: KeyGeneratorType; | ||
allowUserKeys?: boolean; | ||
increment?: number; | ||
offset?: number; | ||
}; | ||
numberOfShards?: number; | ||
shardKeys?: string[]; | ||
distributeShardsLike?: string; | ||
shardingStrategy?: string; | ||
smartJoinAttribute?: string; | ||
replicationFactor?: number; | ||
minReplicationFactor?: number; | ||
} | ||
export interface CollectionProperties { | ||
waitForSync: boolean; | ||
journalSize: number; | ||
isSystem: boolean; | ||
isVolatile: boolean; | ||
keyOptions?: { | ||
type: KeyGeneratorType; | ||
allowUserKeys: boolean; | ||
increment?: number; | ||
offset?: number; | ||
}; | ||
indexBuckets: number; | ||
numberOfShards?: number; | ||
shardKeys?: string[]; | ||
distributeShardsLike?: string; | ||
shardingStrategy?: string; | ||
smartJoinAttribute?: string; | ||
replicationFactor?: number; | ||
minReplicationFactor?: number; | ||
} | ||
export declare type Patch<T> = { | ||
[K in keyof T]?: T[K] | Patch<T[K]>; | ||
}; | ||
export interface DocumentMetadata { | ||
_key: string; | ||
_id: string; | ||
_rev: string; | ||
} | ||
export interface UpdateMetadata extends DocumentMetadata { | ||
_oldRev: string; | ||
} | ||
export declare type Document<T extends object = any> = { | ||
[K in keyof T]: T[K]; | ||
} & DocumentMetadata & { | ||
_from?: string; | ||
_to?: string; | ||
} & { | ||
[key: string]: any; | ||
}; | ||
export declare type DocumentData<T extends object = any> = { | ||
[K in keyof T]: T[K]; | ||
} & Partial<DocumentMetadata>; | ||
export declare type Edge<T extends object = any> = Document<T> & { | ||
_from: string; | ||
_to: string; | ||
}; | ||
export interface InsertOptions { | ||
waitForSync?: boolean; | ||
silent?: boolean; | ||
returnNew?: boolean; | ||
} | ||
export interface ReplaceOptions extends InsertOptions { | ||
rev?: string; | ||
overwrite?: boolean; | ||
returnOld?: boolean; | ||
} | ||
export interface UpdateOptions extends ReplaceOptions { | ||
keepNull?: boolean; | ||
mergeObjects?: boolean; | ||
} | ||
export interface UpdateByExampleOptions { | ||
keepNull?: boolean; | ||
waitForSync?: boolean; | ||
limit?: number; | ||
mergeObjects?: boolean; | ||
} | ||
export interface RemoveOptions { | ||
rev?: string; | ||
waitForSync?: boolean; | ||
overwrite?: boolean; | ||
returnOld?: boolean; | ||
silent?: boolean; | ||
} | ||
export interface RemoveByExampleOptions { | ||
waitForSync?: boolean; | ||
limit?: number; | ||
} | ||
//# sourceMappingURL=types.d.ts.map |
@@ -48,2 +48,3 @@ import { Connection } from "./connection"; | ||
consolidationIntervalMsec?: number; | ||
commitIntervalMsec?: number; | ||
writebufferIdle?: number; | ||
@@ -63,2 +64,9 @@ writebufferActive?: number; | ||
}; | ||
primarySort?: ({ | ||
field: string; | ||
direction: "desc" | "asc"; | ||
} | { | ||
field: string; | ||
asc: boolean; | ||
})[]; | ||
links?: { | ||
@@ -65,0 +73,0 @@ [key: string]: ArangoSearchViewCollectionLink | undefined; |
@@ -5,3 +5,3 @@ "use strict"; | ||
function isAqlQuery(query) { | ||
return Boolean(query && query.query && query.bindVars); | ||
return Boolean(query && typeof query.query === "string" && query.bindVars); | ||
} | ||
@@ -8,0 +8,0 @@ exports.isAqlQuery = isAqlQuery; |
/// <reference types="node" /> | ||
import { Connection } from "./connection"; | ||
import { ArrayCursor } from "./cursor"; | ||
import { CollectionChecksum, CollectionFigures, CollectionProperties, CollectionPropertiesOptions, CreateCollectionOptions, CreateCollectionQueryOptions, Document, DocumentData, Edge, InsertOptions, RemoveByExampleOptions, RemoveOptions, ReplaceOptions, UpdateByExampleOptions, UpdateOptions } from "./util/types"; | ||
export declare enum CollectionType { | ||
@@ -45,3 +46,3 @@ DOCUMENT_COLLECTION = 2, | ||
export declare const COLLECTION_NOT_FOUND = 1203; | ||
export declare abstract class BaseCollection implements ArangoCollection { | ||
export declare abstract class BaseCollection<T extends object = any> implements ArangoCollection { | ||
isArangoCollection: true; | ||
@@ -60,11 +61,11 @@ name: string; | ||
exists(): Promise<boolean>; | ||
create(properties?: any): Promise<any>; | ||
properties(): Promise<any>; | ||
create(properties?: CreateCollectionOptions & CreateCollectionQueryOptions): Promise<any>; | ||
properties(): Promise<CollectionProperties>; | ||
count(): Promise<any>; | ||
figures(): Promise<any>; | ||
figures(): Promise<CollectionFigures>; | ||
revision(): Promise<any>; | ||
checksum(opts?: any): Promise<any>; | ||
checksum(opts?: any): Promise<CollectionChecksum>; | ||
load(count?: boolean): Promise<any>; | ||
unload(): Promise<any>; | ||
setProperties(properties: any): Promise<any>; | ||
setProperties(properties: CollectionPropertiesOptions): Promise<any>; | ||
rename(name: string): Promise<any>; | ||
@@ -74,9 +75,10 @@ rotate(): Promise<any>; | ||
drop(opts?: any): Promise<any>; | ||
getResponsibleShard(document: Object): Promise<string>; | ||
documentExists(documentHandle: DocumentHandle): Promise<boolean>; | ||
document(documentHandle: DocumentHandle, graceful: boolean): Promise<any>; | ||
document(documentHandle: DocumentHandle, opts?: DocumentReadOptions): Promise<any>; | ||
replace(documentHandle: DocumentHandle, newValue: any, opts?: any): Promise<any>; | ||
update(documentHandle: DocumentHandle, newValue: any, opts?: any): Promise<any>; | ||
bulkUpdate(newValues: any, opts?: any): Promise<any>; | ||
remove(documentHandle: DocumentHandle, opts?: any): Promise<any>; | ||
document(documentHandle: DocumentHandle, graceful: boolean): Promise<Document<T>>; | ||
document(documentHandle: DocumentHandle, opts?: DocumentReadOptions): Promise<Document<T>>; | ||
replace(documentHandle: DocumentHandle, newValue: Object | Array<Object>, opts?: ReplaceOptions): Promise<any>; | ||
update(documentHandle: DocumentHandle, newValue: Object | Array<Object>, opts?: UpdateOptions): Promise<any>; | ||
bulkUpdate(newValues: Object | Array<Object>, opts?: any): Promise<any>; | ||
remove(documentHandle: DocumentHandle, opts?: RemoveOptions): Promise<any>; | ||
list(type?: string): Promise<any>; | ||
@@ -89,5 +91,8 @@ all(opts?: any): Promise<ArrayCursor>; | ||
firstExample(example: any): Promise<any>; | ||
removeByExample(example: any, opts?: any): Promise<any>; | ||
replaceByExample(example: any, newValue: any, opts?: any): Promise<any>; | ||
updateByExample(example: any, newValue: any, opts?: any): Promise<any>; | ||
removeByExample(example: any, opts?: RemoveByExampleOptions): Promise<any>; | ||
replaceByExample(example: any, newValue: any, opts?: { | ||
waitForSync?: boolean; | ||
limit?: number; | ||
}): Promise<any>; | ||
updateByExample(example: any, newValue: any, opts?: UpdateByExampleOptions): Promise<any>; | ||
lookupByKeys(keys: string[]): Promise<any>; | ||
@@ -108,23 +113,16 @@ removeByKeys(keys: string[], options: any): Promise<any>; | ||
} | ||
export interface DocumentSaveOptions { | ||
waitForSync?: boolean; | ||
returnNew?: boolean; | ||
returnOld?: boolean; | ||
overwrite?: boolean; | ||
silent?: boolean; | ||
} | ||
export declare class DocumentCollection extends BaseCollection { | ||
export declare class DocumentCollection<T extends object = any> extends BaseCollection<T> { | ||
type: CollectionType; | ||
constructor(connection: Connection, name: string); | ||
save(data: any, opts?: DocumentSaveOptions | boolean): Promise<any>; | ||
save(data: DocumentData<T> | Array<DocumentData<T>>, opts?: InsertOptions | boolean): Promise<any>; | ||
} | ||
export declare class EdgeCollection extends BaseCollection { | ||
export declare class EdgeCollection<T extends object = any> extends BaseCollection<T> { | ||
type: CollectionType; | ||
constructor(connection: Connection, name: string); | ||
protected _documentPath(documentHandle: DocumentHandle): string; | ||
edge(documentHandle: DocumentHandle, graceful: boolean): Promise<any>; | ||
edge(documentHandle: DocumentHandle, opts?: DocumentReadOptions): Promise<any>; | ||
save(data: any, opts?: DocumentSaveOptions | boolean): Promise<any>; | ||
save(data: any, fromId: DocumentHandle, toId: DocumentHandle, opts?: DocumentSaveOptions | boolean): Promise<any>; | ||
protected _edges(documentHandle: DocumentHandle, direction: any): Promise<any>; | ||
edge(documentHandle: DocumentHandle, graceful: boolean): Promise<Edge<T>>; | ||
edge(documentHandle: DocumentHandle, opts?: DocumentReadOptions): Promise<Edge<T>>; | ||
save(data: T | Array<T>, opts?: InsertOptions | boolean): Promise<any>; | ||
save(data: T | Array<T>, fromId: DocumentHandle, toId: DocumentHandle, opts?: InsertOptions | boolean): Promise<any>; | ||
protected _edges(documentHandle: DocumentHandle, direction?: "in" | "out"): Promise<any>; | ||
edges(vertex: DocumentHandle): Promise<any>; | ||
@@ -135,3 +133,3 @@ inEdges(vertex: DocumentHandle): Promise<any>; | ||
} | ||
export declare function constructCollection(connection: Connection, data: any): DocumentCollection; | ||
export declare function constructCollection(connection: Connection, data: any): DocumentCollection<any>; | ||
//# sourceMappingURL=collection.d.ts.map |
@@ -15,4 +15,6 @@ "use strict"; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
@@ -98,6 +100,15 @@ }; | ||
create(properties) { | ||
const _a = properties || {}, { waitForSyncReplication = undefined, enforceReplicationFactor = undefined } = _a, options = __rest(_a, ["waitForSyncReplication", "enforceReplicationFactor"]); | ||
const qs = {}; | ||
if (typeof waitForSyncReplication === "boolean") { | ||
qs.waitForSyncReplication = waitForSyncReplication ? 1 : 0; | ||
} | ||
if (typeof enforceReplicationFactor === "boolean") { | ||
qs.enforceReplicationFactor = enforceReplicationFactor ? 1 : 0; | ||
} | ||
return this._connection.request({ | ||
method: "POST", | ||
path: "/_api/collection", | ||
body: Object.assign({}, properties, { name: this.name, type: this.type }) | ||
qs, | ||
body: Object.assign({}, options, { name: this.name, type: this.type }) | ||
}, res => res.body); | ||
@@ -154,2 +165,9 @@ } | ||
} | ||
getResponsibleShard(document) { | ||
return this._connection.request({ | ||
method: "PUT", | ||
path: `/_api/collection/${this.name}/responsibleShard`, | ||
body: document | ||
}, res => res.body.shardId); | ||
} | ||
documentExists(documentHandle) { | ||
@@ -523,7 +541,15 @@ return this._connection | ||
if (toId !== undefined) { | ||
data._from = this._documentHandle(fromIdOrOpts); | ||
data._to = this._documentHandle(toId); | ||
const fromId = this._documentHandle(fromIdOrOpts); | ||
toId = this._documentHandle(toId); | ||
if (Array.isArray(data)) { | ||
data = data.map(data => Object.assign(data, { _from: fromId, _to: toId })); | ||
} | ||
else { | ||
data = Object.assign(data, { _from: fromId, _to: toId }); | ||
} | ||
} | ||
else if (fromIdOrOpts !== undefined) { | ||
opts = fromIdOrOpts; | ||
else { | ||
if (fromIdOrOpts !== undefined) { | ||
opts = fromIdOrOpts; | ||
} | ||
} | ||
@@ -534,2 +560,5 @@ if (typeof opts === "boolean") { | ||
if (this._connection.arangoMajor <= 2) { | ||
if (Array.isArray(data)) { | ||
throw new Error("ArangoDB 2 does not support batch operations"); | ||
} | ||
return this._connection.request({ | ||
@@ -559,3 +588,3 @@ method: "POST", | ||
edges(vertex) { | ||
return this._edges(vertex, undefined); | ||
return this._edges(vertex); | ||
} | ||
@@ -562,0 +591,0 @@ inEdges(vertex) { |
@@ -52,2 +52,3 @@ import { ArangojsResponse } from "./util/request"; | ||
private _activeDirtyHost; | ||
private _transactionId; | ||
constructor(config?: Config); | ||
@@ -62,2 +63,4 @@ private readonly _databasePath; | ||
setDatabaseName(databaseName: string): void; | ||
setTransactionId(transactionId: string): void; | ||
clearTransactionId(): void; | ||
setHeader(key: string, value: string): void; | ||
@@ -64,0 +67,0 @@ close(): void; |
@@ -7,4 +7,6 @@ "use strict"; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
@@ -34,2 +36,3 @@ }; | ||
this._urls = []; | ||
this._transactionId = null; | ||
if (typeof config === "string") | ||
@@ -97,3 +100,3 @@ config = { url: config }; | ||
this._activeTasks += 1; | ||
this._hosts[host](task.options, (err, res) => { | ||
const callback = (err, res) => { | ||
this._activeTasks -= 1; | ||
@@ -138,3 +141,9 @@ if (err) { | ||
this._runQueue(); | ||
}); | ||
}; | ||
try { | ||
this._hosts[host](task.options, callback); | ||
} | ||
catch (e) { | ||
callback(e); | ||
} | ||
} | ||
@@ -181,2 +190,8 @@ _buildUrl({ absolutePath = false, basePath, path, qs }) { | ||
} | ||
setTransactionId(transactionId) { | ||
this._transactionId = transactionId; | ||
} | ||
clearTransactionId() { | ||
this._transactionId = null; | ||
} | ||
setHeader(key, value) { | ||
@@ -208,2 +223,5 @@ this._headers[key] = value; | ||
const extraHeaders = Object.assign({}, this._headers, { "content-type": contentType, "x-arango-version": String(this._arangoVersion) }); | ||
if (this._transactionId) { | ||
extraHeaders["x-arango-trx-id"] = this._transactionId; | ||
} | ||
this._queue.push({ | ||
@@ -210,0 +228,0 @@ retries: 0, |
/// <reference types="node" /> | ||
import { AnalyzerDescription, ArangoAnalyzer } from "./analyzer"; | ||
import { AqlLiteral, AqlQuery } from "./aql-query"; | ||
@@ -8,4 +9,11 @@ import { ArangoCollection, DocumentCollection, EdgeCollection } from "./collection"; | ||
import { Route } from "./route"; | ||
import { ArangoTransaction } from "./transaction"; | ||
import { ArangoSearchView, ArangoView, ViewType } from "./view"; | ||
export declare type TransactionCollectionsObject = { | ||
exclusive?: string | string[]; | ||
write?: string | string[]; | ||
read?: string | string[]; | ||
}; | ||
export declare type TransactionCollections = string | ArangoCollection | (string | ArangoCollection)[] | { | ||
exclusive?: string | ArangoCollection | (string | ArangoCollection)[]; | ||
write?: string | ArangoCollection | (string | ArangoCollection)[]; | ||
@@ -15,5 +23,8 @@ read?: string | ArangoCollection | (string | ArangoCollection)[]; | ||
export declare type TransactionOptions = { | ||
allowImplicit?: boolean; | ||
lockTimeout?: number; | ||
maxTransactionSize?: number; | ||
/** @deprecated removed in ArangoDB 3.4, RocksDB-only */ | ||
intermediateCommitCount?: number; | ||
/** @deprecated removed in ArangoDB 3.4, RocksDB-only */ | ||
intermediateCommitSize?: number; | ||
@@ -46,5 +57,7 @@ waitForSync?: boolean; | ||
maxWarningsCount?: number; | ||
/** RocksDB-only */ | ||
intermediateCommitCount?: number; | ||
satteliteSyncWait?: number; | ||
fullCount?: boolean; | ||
/** RocksDB-only */ | ||
intermediateCommitSize?: number; | ||
@@ -133,8 +146,10 @@ optimizer?: { | ||
readonly name: string | null; | ||
version(): Promise<any>; | ||
route(path?: string, headers?: Object): Route; | ||
acquireHostList(): Promise<void>; | ||
close(): void; | ||
useDatabase(databaseName: string): this; | ||
login(username?: string, password?: string): Promise<string>; | ||
useBearerAuth(token: string): this; | ||
useBasicAuth(username?: string, password?: string): this; | ||
useDatabase(databaseName: string): this; | ||
get(): Promise<any>; | ||
@@ -146,18 +161,24 @@ exists(): Promise<boolean>; | ||
dropDatabase(databaseName: string): Promise<any>; | ||
collection(collectionName: string): DocumentCollection; | ||
edgeCollection(collectionName: string): EdgeCollection; | ||
collection<T extends object = any>(collectionName: string): DocumentCollection<T>; | ||
edgeCollection<T extends object = any>(collectionName: string): EdgeCollection<T>; | ||
listCollections(excludeSystem?: boolean): Promise<any>; | ||
collections(excludeSystem?: boolean): Promise<ArangoCollection[]>; | ||
truncate(excludeSystem?: boolean): Promise<[{}, {}, {}, {}, {}, {}, {}, {}, {}, {}]>; | ||
truncate(excludeSystem?: boolean): Promise<[unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown]>; | ||
arangoSearchView(viewName: string): ArangoSearchView; | ||
listViews(): Promise<ViewDescription[]>; | ||
views(): Promise<ArangoView[]>; | ||
analyzer(name: string): ArangoAnalyzer; | ||
listAnalyzers(): Promise<AnalyzerDescription[]>; | ||
analyzers(): Promise<ArangoAnalyzer[]>; | ||
executeTransaction(collections: TransactionCollections, action: string, options?: TransactionOptions & { | ||
params?: any; | ||
}): Promise<any>; | ||
transaction(transactionId: string): ArangoTransaction; | ||
transaction(collections: TransactionCollections, action: string, params?: any, options?: TransactionOptions): Promise<any>; | ||
transaction(collections: TransactionCollections, action: string, lockTimeout?: number): Promise<any>; | ||
transaction(collections: TransactionCollections, action: string, params?: any, lockTimeout?: number): Promise<any>; | ||
beginTransaction(collections: TransactionCollections, options?: TransactionOptions): Promise<ArangoTransaction>; | ||
graph(graphName: string): Graph; | ||
listGraphs(): Promise<any>; | ||
graphs(): Promise<Graph[]>; | ||
transaction(collections: TransactionCollections, action: string): Promise<any>; | ||
transaction(collections: TransactionCollections, action: string, params?: Object): Promise<any>; | ||
transaction(collections: TransactionCollections, action: string, params?: Object, options?: TransactionOptions): Promise<any>; | ||
transaction(collections: TransactionCollections, action: string, lockTimeout?: number): Promise<any>; | ||
transaction(collections: TransactionCollections, action: string, params?: Object, lockTimeout?: number): Promise<any>; | ||
query(query: string | AqlQuery | AqlLiteral): Promise<ArrayCursor>; | ||
@@ -204,5 +225,3 @@ query(query: AqlQuery, opts?: QueryOptions): Promise<ArrayCursor>; | ||
commitLocalServiceState(replace?: boolean): Promise<void>; | ||
version(): Promise<any>; | ||
login(username?: string, password?: string): Promise<string>; | ||
} | ||
//# sourceMappingURL=database.d.ts.map |
@@ -15,7 +15,10 @@ "use strict"; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const analyzer_1 = require("./analyzer"); | ||
const aql_query_1 = require("./aql-query"); | ||
@@ -28,2 +31,3 @@ const collection_1 = require("./collection"); | ||
const route_1 = require("./route"); | ||
const transaction_1 = require("./transaction"); | ||
const btoa_1 = require("./util/btoa"); | ||
@@ -47,2 +51,9 @@ const multipart_1 = require("./util/multipart"); | ||
} | ||
//#region misc | ||
version() { | ||
return this._connection.request({ | ||
method: "GET", | ||
path: "/_api/version" | ||
}, res => res.body); | ||
} | ||
route(path, headers) { | ||
@@ -63,6 +74,13 @@ return new route_1.Route(this._connection, path, headers); | ||
} | ||
// Database manipulation | ||
useDatabase(databaseName) { | ||
this._connection.setDatabaseName(databaseName); | ||
return this; | ||
//#endregion | ||
//#region auth | ||
login(username = "root", password = "") { | ||
return this._connection.request({ | ||
method: "POST", | ||
path: "/_open/auth", | ||
body: { username, password } | ||
}, res => { | ||
this.useBearerAuth(res.body.jwt); | ||
return res.body.jwt; | ||
}); | ||
} | ||
@@ -77,2 +95,8 @@ useBearerAuth(token) { | ||
} | ||
//#endregion | ||
//#region databases | ||
useDatabase(databaseName) { | ||
this._connection.setDatabaseName(databaseName); | ||
return this; | ||
} | ||
get() { | ||
@@ -108,3 +132,4 @@ return this._connection.request({ path: "/_api/database/current" }, res => res.body.result); | ||
} | ||
// Collection manipulation | ||
//#endregion | ||
//#region collections | ||
collection(collectionName) { | ||
@@ -139,3 +164,4 @@ return new collection_1.DocumentCollection(this._connection, collectionName); | ||
} | ||
// Views | ||
//#endregion | ||
//#region views | ||
arangoSearchView(viewName) { | ||
@@ -153,16 +179,29 @@ return new view_1.ArangoSearchView(this._connection, viewName); | ||
} | ||
// Graph manipulation | ||
graph(graphName) { | ||
return new graph_1.Graph(this._connection, graphName); | ||
//#endregion | ||
//#region analyzers | ||
analyzer(name) { | ||
return new analyzer_1.ArangoAnalyzer(this._connection, name); | ||
} | ||
listGraphs() { | ||
return this._connection.request({ path: "/_api/gharial" }, res => res.body.graphs); | ||
listAnalyzers() { | ||
return this._connection.request({ path: "/_api/analyzer" }, res => res.body.result); | ||
} | ||
graphs() { | ||
analyzers() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const graphs = yield this.listGraphs(); | ||
return graphs.map((data) => this.graph(data._key)); | ||
const analyzers = yield this.listAnalyzers(); | ||
return analyzers.map(data => this.analyzer(data.name)); | ||
}); | ||
} | ||
transaction(collections, action, params, options) { | ||
//#endregion | ||
//#region transactions | ||
executeTransaction(collections, action, options) { | ||
return this._connection.request({ | ||
method: "POST", | ||
path: "/_api/transaction", | ||
body: Object.assign({ collections: coerceTransactionCollections(collections), action }, options) | ||
}, res => res.body.result); | ||
} | ||
transaction(collectionsOrId, action, params, options) { | ||
if (arguments.length === 1 && typeof collectionsOrId === "string") { | ||
return new transaction_1.ArangoTransaction(this._connection, collectionsOrId); | ||
} | ||
if (typeof params === "number") { | ||
@@ -175,36 +214,25 @@ options = params; | ||
} | ||
if (typeof collections === "string") { | ||
collections = { write: [collections] }; | ||
} | ||
else if (Array.isArray(collections)) { | ||
collections = { write: collections.map(colToString) }; | ||
} | ||
else if (collection_1.isArangoCollection(collections)) { | ||
collections = { write: colToString(collections) }; | ||
} | ||
else if (collections && typeof collections === "object") { | ||
collections = Object.assign({}, collections); | ||
if (collections.read) { | ||
if (!Array.isArray(collections.read)) { | ||
collections.read = colToString(collections.read); | ||
} | ||
else | ||
collections.read = collections.read.map(colToString); | ||
} | ||
if (collections.write) { | ||
if (!Array.isArray(collections.write)) { | ||
collections.write = colToString(collections.write); | ||
} | ||
else | ||
collections.write = collections.write.map(colToString); | ||
} | ||
} | ||
return this.executeTransaction(collectionsOrId, action, Object.assign({ params }, options)); | ||
} | ||
beginTransaction(collections, options) { | ||
return this._connection.request({ | ||
method: "POST", | ||
path: "/_api/transaction", | ||
body: Object.assign({ collections, | ||
action, | ||
params }, options) | ||
}, res => res.body.result); | ||
path: "/_api/transaction/begin", | ||
body: Object.assign({ collections: coerceTransactionCollections(collections) }, options) | ||
}, res => new transaction_1.ArangoTransaction(this._connection, res.body.result.id)); | ||
} | ||
//#endregion | ||
//#region graphs | ||
graph(graphName) { | ||
return new graph_1.Graph(this._connection, graphName); | ||
} | ||
listGraphs() { | ||
return this._connection.request({ path: "/_api/gharial" }, res => res.body.graphs); | ||
} | ||
graphs() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const graphs = yield this.listGraphs(); | ||
return graphs.map((data) => this.graph(data._key)); | ||
}); | ||
} | ||
query(query, bindVars, opts) { | ||
@@ -293,3 +321,4 @@ if (aql_query_1.isAqlQuery(query)) { | ||
} | ||
// Function management | ||
//#endregion | ||
//#region functions | ||
listFunctions() { | ||
@@ -312,3 +341,4 @@ return this._connection.request({ path: "/_api/aqlfunction" }, res => res.body); | ||
} | ||
// Service management | ||
//#endregion | ||
//#region services | ||
listServices() { | ||
@@ -545,20 +575,34 @@ return this._connection.request({ path: "/_api/foxx" }, res => res.body); | ||
} | ||
version() { | ||
return this._connection.request({ | ||
method: "GET", | ||
path: "/_api/version" | ||
}, res => res.body); | ||
} | ||
exports.Database = Database; | ||
function coerceTransactionCollections(collections) { | ||
if (typeof collections === "string") { | ||
return { write: [collections] }; | ||
} | ||
login(username = "root", password = "") { | ||
return this._connection.request({ | ||
method: "POST", | ||
path: "/_open/auth", | ||
body: { username, password } | ||
}, res => { | ||
this.useBearerAuth(res.body.jwt); | ||
return res.body.jwt; | ||
}); | ||
if (Array.isArray(collections)) { | ||
return { write: collections.map(colToString) }; | ||
} | ||
if (collection_1.isArangoCollection(collections)) { | ||
return { write: colToString(collections) }; | ||
} | ||
const cols = {}; | ||
if (collections) { | ||
if (collections.read) { | ||
cols.read = Array.isArray(collections.read) | ||
? collections.read.map(colToString) | ||
: colToString(collections.read); | ||
} | ||
if (collections.write) { | ||
cols.write = Array.isArray(collections.write) | ||
? collections.write.map(colToString) | ||
: colToString(collections.write); | ||
} | ||
if (collections.exclusive) { | ||
cols.exclusive = Array.isArray(collections.exclusive) | ||
? collections.exclusive.map(colToString) | ||
: colToString(collections.exclusive); | ||
} | ||
} | ||
return cols; | ||
} | ||
exports.Database = Database; | ||
//# sourceMappingURL=database.js.map |
@@ -11,7 +11,7 @@ import { ArangoCollection, BaseCollection, CollectionType, DocumentHandle, DocumentReadOptions, EdgeCollection } from "./collection"; | ||
vertex(documentHandle: DocumentHandle, opts?: DocumentReadOptions): Promise<any>; | ||
save(data: any, opts?: { | ||
save(data: Object | Array<Object>, opts?: { | ||
waitForSync?: boolean; | ||
}): Promise<any>; | ||
replace(documentHandle: DocumentHandle, newValue: any, opts?: any): Promise<any>; | ||
update(documentHandle: DocumentHandle, newValue: any, opts?: any): Promise<any>; | ||
replace(documentHandle: DocumentHandle, newValue: Object | Array<Object>, opts?: any): Promise<any>; | ||
update(documentHandle: DocumentHandle, newValue: Object | Array<Object>, opts?: any): Promise<any>; | ||
remove(documentHandle: DocumentHandle, opts?: any): Promise<any>; | ||
@@ -25,10 +25,10 @@ } | ||
document(documentHandle: DocumentHandle, opts?: DocumentReadOptions): Promise<any>; | ||
save(data: any, opts?: { | ||
save(data: Object | Array<Object>, opts?: { | ||
waitForSync?: boolean; | ||
}): Promise<any>; | ||
save(data: any, fromId: DocumentHandle, toId: DocumentHandle, opts?: { | ||
save(data: Object | Array<Object>, fromId: DocumentHandle, toId: DocumentHandle, opts?: { | ||
waitForSync?: boolean; | ||
}): Promise<any>; | ||
replace(documentHandle: DocumentHandle, newValue: any, opts?: any): Promise<any>; | ||
update(documentHandle: DocumentHandle, newValue: any, opts?: any): Promise<any>; | ||
replace(documentHandle: DocumentHandle, newValue: Object | Array<Object>, opts?: any): Promise<any>; | ||
update(documentHandle: DocumentHandle, newValue: Object | Array<Object>, opts?: any): Promise<any>; | ||
remove(documentHandle: DocumentHandle, opts?: any): Promise<any>; | ||
@@ -35,0 +35,0 @@ } |
@@ -15,4 +15,6 @@ "use strict"; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
@@ -144,12 +146,18 @@ }; | ||
} | ||
save(data, fromId, toId, opts) { | ||
if (fromId !== undefined) { | ||
if (toId !== undefined) { | ||
data._from = this._documentHandle(fromId); | ||
data._to = this._documentHandle(toId); | ||
save(data, fromIdOrOpts, toId, opts) { | ||
if (toId !== undefined) { | ||
const fromId = this._documentHandle(fromIdOrOpts); | ||
toId = this._documentHandle(toId); | ||
if (Array.isArray(data)) { | ||
data = data.map(data => (Object.assign({}, data, { _from: fromId, _to: toId }))); | ||
} | ||
else { | ||
opts = fromId; | ||
data = Object.assign({}, data, { _from: fromId, _to: toId }); | ||
} | ||
} | ||
else { | ||
if (fromIdOrOpts !== undefined) { | ||
opts = fromIdOrOpts; | ||
} | ||
} | ||
return this._connection.request({ | ||
@@ -156,0 +164,0 @@ method: "POST", |
@@ -7,4 +7,6 @@ "use strict"; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
@@ -11,0 +13,0 @@ }; |
@@ -103,3 +103,5 @@ "use strict"; | ||
called = true; | ||
callback(e); | ||
setTimeout(() => { | ||
callback(e); | ||
}); | ||
} | ||
@@ -106,0 +108,0 @@ }, { |
@@ -7,4 +7,6 @@ "use strict"; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
@@ -11,0 +13,0 @@ }; |
export declare type Errback<T> = (err: Error | null, result?: T) => void; | ||
export declare type KeyGeneratorType = "traditional" | "autoincrement"; | ||
export interface CollectionChecksum { | ||
checksum: string; | ||
revision: string; | ||
} | ||
export interface CollectionFigures { | ||
alive: { | ||
count: number; | ||
size: number; | ||
}; | ||
dead: { | ||
count: number; | ||
size: number; | ||
deletion: number; | ||
}; | ||
datafiles: { | ||
count: number; | ||
fileSize: number; | ||
}; | ||
journals: { | ||
count: number; | ||
fileSize: number; | ||
}; | ||
compactors: { | ||
count: number; | ||
fileSize: number; | ||
}; | ||
shapefiles: { | ||
count: number; | ||
fileSize: number; | ||
}; | ||
shapes: { | ||
count: number; | ||
size: number; | ||
}; | ||
attributes: { | ||
count: number; | ||
size: number; | ||
}; | ||
indexes: { | ||
count: number; | ||
size: number; | ||
}; | ||
lastTick: number; | ||
uncollectedLogfileEntries: number; | ||
documentReferences: number; | ||
waitingFor: string; | ||
compactionStatus: { | ||
time: string; | ||
message: string; | ||
count: number; | ||
filesCombined: number; | ||
bytesRead: number; | ||
bytesWritten: number; | ||
}; | ||
} | ||
export interface CollectionPropertiesOptions { | ||
waitForSync?: boolean; | ||
journalSize?: number; | ||
indexBuckets?: number; | ||
replicationFactor?: number; | ||
minReplicationFactor?: number; | ||
} | ||
export interface CreateCollectionQueryOptions { | ||
waitForSyncReplication?: boolean; | ||
enforceReplicationFactor?: boolean; | ||
} | ||
export interface CreateCollectionOptions { | ||
waitForSync?: boolean; | ||
journalSize?: number; | ||
isVolatile?: boolean; | ||
isSystem?: boolean; | ||
keyOptions?: { | ||
type?: KeyGeneratorType; | ||
allowUserKeys?: boolean; | ||
increment?: number; | ||
offset?: number; | ||
}; | ||
numberOfShards?: number; | ||
shardKeys?: string[]; | ||
distributeShardsLike?: string; | ||
shardingStrategy?: string; | ||
smartJoinAttribute?: string; | ||
replicationFactor?: number; | ||
minReplicationFactor?: number; | ||
} | ||
export interface CollectionProperties { | ||
waitForSync: boolean; | ||
journalSize: number; | ||
isSystem: boolean; | ||
isVolatile: boolean; | ||
keyOptions?: { | ||
type: KeyGeneratorType; | ||
allowUserKeys: boolean; | ||
increment?: number; | ||
offset?: number; | ||
}; | ||
indexBuckets: number; | ||
numberOfShards?: number; | ||
shardKeys?: string[]; | ||
distributeShardsLike?: string; | ||
shardingStrategy?: string; | ||
smartJoinAttribute?: string; | ||
replicationFactor?: number; | ||
minReplicationFactor?: number; | ||
} | ||
export declare type Patch<T> = { | ||
[K in keyof T]?: T[K] | Patch<T[K]>; | ||
}; | ||
export interface DocumentMetadata { | ||
_key: string; | ||
_id: string; | ||
_rev: string; | ||
} | ||
export interface UpdateMetadata extends DocumentMetadata { | ||
_oldRev: string; | ||
} | ||
export declare type Document<T extends object = any> = { | ||
[K in keyof T]: T[K]; | ||
} & DocumentMetadata & { | ||
_from?: string; | ||
_to?: string; | ||
} & { | ||
[key: string]: any; | ||
}; | ||
export declare type DocumentData<T extends object = any> = { | ||
[K in keyof T]: T[K]; | ||
} & Partial<DocumentMetadata>; | ||
export declare type Edge<T extends object = any> = Document<T> & { | ||
_from: string; | ||
_to: string; | ||
}; | ||
export interface InsertOptions { | ||
waitForSync?: boolean; | ||
silent?: boolean; | ||
returnNew?: boolean; | ||
} | ||
export interface ReplaceOptions extends InsertOptions { | ||
rev?: string; | ||
overwrite?: boolean; | ||
returnOld?: boolean; | ||
} | ||
export interface UpdateOptions extends ReplaceOptions { | ||
keepNull?: boolean; | ||
mergeObjects?: boolean; | ||
} | ||
export interface UpdateByExampleOptions { | ||
keepNull?: boolean; | ||
waitForSync?: boolean; | ||
limit?: number; | ||
mergeObjects?: boolean; | ||
} | ||
export interface RemoveOptions { | ||
rev?: string; | ||
waitForSync?: boolean; | ||
overwrite?: boolean; | ||
returnOld?: boolean; | ||
silent?: boolean; | ||
} | ||
export interface RemoveByExampleOptions { | ||
waitForSync?: boolean; | ||
limit?: number; | ||
} | ||
//# sourceMappingURL=types.d.ts.map |
@@ -48,2 +48,3 @@ import { Connection } from "./connection"; | ||
consolidationIntervalMsec?: number; | ||
commitIntervalMsec?: number; | ||
writebufferIdle?: number; | ||
@@ -63,2 +64,9 @@ writebufferActive?: number; | ||
}; | ||
primarySort?: ({ | ||
field: string; | ||
direction: "desc" | "asc"; | ||
} | { | ||
field: string; | ||
asc: boolean; | ||
})[]; | ||
links?: { | ||
@@ -65,0 +73,0 @@ [key: string]: ArangoSearchViewCollectionLink | undefined; |
{ | ||
"name": "arangojs", | ||
"version": "6.10.0", | ||
"version": "6.11.0", | ||
"license": "Apache-2.0", | ||
@@ -50,7 +50,7 @@ "description": "The official ArangoDB JavaScript driver.", | ||
"scripts": { | ||
"test": "mocha --growl --reporter spec --require source-map-support/register --timeout 10000 lib/async/test", | ||
"test": "mocha --reporter spec --require source-map-support/register --timeout 10000 lib/async/test", | ||
"pretest": "yarn dist", | ||
"ci": "mocha --reporter spec --require source-map-support/register --timeout 10000 lib/cjs/test", | ||
"ci": "mocha --reporter spec --require source-map-support/register --timeout 30000 lib/cjs/test", | ||
"preci": "yarn install", | ||
"jenkins": "yarn ci -- --timeout 0 --reporter xunit-file", | ||
"jenkins": "mocha --reporter spec --require source-map-support/register --timeout 0 lib/cjs/test", | ||
"dist:cjs": "tsc -p . --outDir ./lib/cjs/ --declarationMap true && cpy src/index.js lib/cjs/", | ||
@@ -73,3 +73,3 @@ "dist:async": "tsc -p . --outDir ./lib/async/ --target es2018 --declarationMap true && cpy src/index.js lib/async/", | ||
"@types/request-promise": "^4.1.42", | ||
"arangodb-instance-manager": "^0.1.1", | ||
"arangodb-instance-manager": "^1.1.2", | ||
"babel-core": "^6.26.0", | ||
@@ -86,7 +86,7 @@ "babel-eslint": "^8.0.3", | ||
"eslint-plugin-prettier": "^2.3.1", | ||
"mocha": "^5.2.0", | ||
"mocha": "^6.2.0", | ||
"npm-run-all": "^4.1.2", | ||
"prettier": "^1.9.1", | ||
"regenerator-runtime": "^0.11.1", | ||
"rimraf": "^2.6.2", | ||
"rimraf": "^3.0.0", | ||
"source-map-support": "^0.5.0", | ||
@@ -93,0 +93,0 @@ "ts-loader": "^3.2.0", |
@@ -68,3 +68,7 @@ # ArangoDB JavaScript Driver | ||
Even if your project doesn't contain any browser code, you need to add `"dom"` to the `"lib"` array in your `tsconfig.json` to make arangojs work. This is a known limitation because the library supports both browser and Node environments and there is no common binary format that works in both environments: | ||
Even if your project doesn't contain any browser code, you need to add `"dom"` | ||
to the `"lib"` array in your `tsconfig.json` to make arangojs work. This is a | ||
known limitation because the library supports both browser and Node | ||
environments and there is no common binary format that works in | ||
both environments: | ||
@@ -77,2 +81,19 @@ ```diff | ||
### Node.js `ReferenceError: window is not defined` | ||
If you compile your Node project using a build tool like Webpack, you may need | ||
to tell it to | ||
[target the correct environment](https://webpack.js.org/configuration/target/): | ||
```diff | ||
// webpack.config.js | ||
+ "target": "node", | ||
``` | ||
To support use in both browser and Node environments arangojs uses the | ||
[`package.json` `browser` field](https://github.com/defunctzombie/package-browser-field-spec), | ||
to substitute browser-specific implementations for certain modules. | ||
Build tools like Webpack will respect this field when targetting a browser | ||
environment and may need to be explicitly told you are targetting Node instead. | ||
## Documentation | ||
@@ -79,0 +100,0 @@ |
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 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 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 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 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 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 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 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 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 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 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 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
1664603
209
7934
161