Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

arangojs

Package Overview
Dependencies
Maintainers
4
Versions
132
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arangojs - npm Package Compare versions

Comparing version 7.0.0-preview.1 to 7.0.0-rc.0

foxx-manifest.d.ts

91

analyzer.d.ts

@@ -6,6 +6,8 @@ /**

*
* TODO
* The "analyzer" module provides analyzer related types and interfaces
* for TypeScript.
*
* @packageDocumentation
*/
import { ArangoResponseMetadata } from "./connection";
import { Database } from "./database";

@@ -23,3 +25,3 @@ /**

/**
* TODO
* An object describing an Analyzer.
*/

@@ -44,7 +46,7 @@ export declare type AnalyzerDescription = AnalyzerInfo & {

/**
* TODO
* Analyzer type and type-specific properties for an Identity Analyzer.
*/
export declare type IdentityAnalyzerInfo = {
/**
* The type of the Analyzer.
* Type of the Analyzer.
*/

@@ -60,7 +62,7 @@ type: "identity";

/**
* TODO
* Analyzer type and type-specific properties for a Delimiter Analyzer.
*/
export declare type DelimiterAnalyzerInfo = {
/**
* The type of the Analyzer.
* Type of the Analyzer.
*/

@@ -79,7 +81,7 @@ type: "delimiter";

/**
* TODO
* Analyzer type and type-specific properties for a Stem Analyzer.
*/
export declare type StemAnalyzerInfo = {
/**
* The type of the Analyzer.
* Type of the Analyzer.
*/

@@ -99,7 +101,7 @@ type: "stem";

/**
* TODO
* Properties of a Norm Analyzer.
*/
export declare type NormAnalyzerProperties = {
/**
* The text locale.
* Text locale.
*

@@ -123,7 +125,7 @@ * Format: `language[_COUNTRY][.encoding][@variant]`

/**
* TODO
* Analyzer type and type-specific properties for a Norm Analyzer.
*/
export declare type NormAnalyzerInfo = {
/**
* The type of the Analyzer.
* Type of the Analyzer.
*/

@@ -137,3 +139,3 @@ type: "norm";

/**
* TODO
* Properties of an Ngram Analyzer.
*/

@@ -155,7 +157,7 @@ export declare type NgramAnalyzerProperties = {

/**
* TODO
* Analyzer type and type-specific properties for an Ngram Analyzer.
*/
export declare type NgramAnalyzerInfo = {
/**
* The type of the Analyzer.
* Type of the Analyzer.
*/

@@ -169,7 +171,7 @@ type: "ngram";

/**
* TODO
* Properties of a Text Analyzer.
*/
export declare type TextAnalyzerProperties = {
/**
* The text locale.
* Text locale.
*

@@ -213,7 +215,7 @@ * Format: `language[_COUNTRY][.encoding][@variant]`

/**
* TODO
* Analyzer type and type-specific properties for a Text Analyzer.
*/
export declare type TextAnalyzerInfo = {
/**
* The type of the Analyzer.
* Type of the Analyzer.
*/

@@ -227,3 +229,3 @@ type: "text";

/**
* TODO
* Represents an Analyzer in a {@link Database}.
*/

@@ -245,21 +247,54 @@ export declare class Analyzer {

/**
* TODO
* Name of this Analyzer.
*
* See also {@link Database.analyzer}.
*/
get name(): string;
/**
* TODO
* Checks whether the Analyzer exists.
*
* @example
* ```js
* const db = new Database();
* const analyzer = db.analyzer("some-analyzer");
* const result = await analyzer.exists();
* // result indicates whether the Analyzer exists
* ```
*/
get(): Promise<AnalyzerDescription>;
exists(): Promise<boolean>;
/**
* TODO
* Retrieves the Analyzer definition for the Analyzer.
*
* @example
* ```js
* const db = new Database();
* const analyzer = db.analyzer("some-analyzer");
* const definition = await analyzer.get();
* // definition contains the Analyzer definition
* ```
*/
exists(): Promise<boolean>;
get(): Promise<ArangoResponseMetadata & AnalyzerDescription>;
/**
* TODO
* Creates a new Analyzer with the given `options` and the instance's name.
*
* See also {@link Database.createAnalyzer}.
*
* @param options - Options for creating the Analyzer.
*/
create(options: CreateAnalyzerOptions): Promise<AnalyzerDescription>;
/**
* TODO
* Deletes the Analyzer from the database.
*
* @param force - Whether the Analyzer should still be deleted even if it
* is currently in use.
*
* @example
* ```js
* const db = new Database();
* const analyzer = db.analyzer("some-analyzer");
* await analyzer.drop();
* // the Analyzer "some-analyzer" no longer exists
* ```
*/
drop(force?: boolean): Promise<{
drop(force?: boolean): Promise<ArangoResponseMetadata & {
name: string;

@@ -266,0 +301,0 @@ }>;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Analyzer = exports.isArangoAnalyzer = void 0;
const error_1 = require("./error");
const codes_1 = require("./util/codes");
const codes_1 = require("./lib/codes");
/**

@@ -15,3 +16,3 @@ * Indicates whether the given value represents an {@link Analyzer}.

/**
* TODO
* Represents an Analyzer in a {@link Database}.
*/

@@ -36,3 +37,5 @@ class Analyzer {

/**
* TODO
* Name of this Analyzer.
*
* See also {@link Database.analyzer}.
*/

@@ -43,10 +46,12 @@ get name() {

/**
* TODO
* Checks whether the Analyzer exists.
*
* @example
* ```js
* const db = new Database();
* const analyzer = db.analyzer("some-analyzer");
* const result = await analyzer.exists();
* // result indicates whether the Analyzer exists
* ```
*/
get() {
return this._db.request({ path: `/_api/analyzer/${this.name}` }, (res) => res.body);
}
/**
* TODO
*/
async exists() {

@@ -65,4 +70,22 @@ try {

/**
* TODO
* Retrieves the Analyzer definition for the Analyzer.
*
* @example
* ```js
* const db = new Database();
* const analyzer = db.analyzer("some-analyzer");
* const definition = await analyzer.get();
* // definition contains the Analyzer definition
* ```
*/
get() {
return this._db.request({ path: `/_api/analyzer/${this.name}` }, (res) => res.body);
}
/**
* Creates a new Analyzer with the given `options` and the instance's name.
*
* See also {@link Database.createAnalyzer}.
*
* @param options - Options for creating the Analyzer.
*/
create(options) {

@@ -76,5 +99,16 @@ return this._db.request({

/**
* TODO
* Deletes the Analyzer from the database.
*
* @param force - Whether the Analyzer should still be deleted even if it
* is currently in use.
*
* @example
* ```js
* const db = new Database();
* const analyzer = db.analyzer("some-analyzer");
* await analyzer.drop();
* // the Analyzer "some-analyzer" no longer exists
* ```
*/
drop(force) {
drop(force = false) {
return this._db.request({

@@ -81,0 +115,0 @@ method: "DELETE",

@@ -14,3 +14,4 @@ /**

import { ArangoCollection } from "./collection";
import { Dict } from "./util/types";
import { Dict } from "./connection";
import { View } from "./view";
/**

@@ -70,3 +71,3 @@ * Generic AQL query object consisting of an AQL query string and its bind

*/
export declare type AqlValue = ArangoCollection | GeneratedAqlQuery | AqlLiteral | string | number | boolean | null | undefined | object | any[];
export declare type AqlValue = ArangoCollection | View | GeneratedAqlQuery | AqlLiteral | string | number | boolean | null | undefined | object | any[];
/**

@@ -73,0 +74,0 @@ * Indicates whether the given value is an {@link AqlQuery}.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.aql = exports.isAqlLiteral = exports.isGeneratedAqlQuery = exports.isAqlQuery = void 0;
/**

@@ -16,2 +17,3 @@ * ```js

const collection_1 = require("./collection");
const view_1 = require("./view");
/**

@@ -139,3 +141,3 @@ * Indicates whether the given value is an {@link AqlQuery}.

const bindVars = {};
const bindVals = [];
const bindValues = [];
let query = strings[0];

@@ -168,6 +170,6 @@ for (let i = 0; i < args.length; i++) {

}
const index = bindVals.indexOf(rawValue);
const index = bindValues.indexOf(rawValue);
const isKnown = index !== -1;
let name = `value${isKnown ? index : bindVals.length}`;
if (collection_1.isArangoCollection(rawValue)) {
let name = `value${isKnown ? index : bindValues.length}`;
if (collection_1.isArangoCollection(rawValue) || view_1.isArangoView(rawValue)) {
name = `@${name}`;

@@ -177,3 +179,3 @@ value = rawValue.name;

if (!isKnown) {
bindVals.push(rawValue);
bindValues.push(rawValue);
bindVars[name] = value;

@@ -180,0 +182,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Collection = exports.CollectionStatus = exports.CollectionType = exports.collectionToString = exports.isArangoCollection = void 0;
const cursor_1 = require("./cursor");

@@ -7,3 +8,3 @@ const documents_1 = require("./documents");

const indexes_1 = require("./indexes");
const codes_1 = require("./util/codes");
const codes_1 = require("./lib/codes");
/**

@@ -19,2 +20,16 @@ * Indicates whether the given value represents an {@link ArangoCollection}.

/**
* Coerces the given collection name or {@link ArangoCollection} object to
* a string representing the collection name.
*
* @param collection - Collection name or {@link ArangoCollection} object.
*/
function collectionToString(collection) {
if (isArangoCollection(collection)) {
return String(collection.name);
}
else
return String(collection);
}
exports.collectionToString = collectionToString;
/**
* Integer values indicating the collection type.

@@ -40,22 +55,4 @@ */

/**
* The `Collection` type represents a collection in a {@link Database}.
*
* When using TypeScript, collections can be cast to {@link DocumentCollection}
* or {@link EdgeCollection} in order to increase type safety.
*
* @param T - Type to use for document data. Defaults to `any`.
*
* @example
* ```ts
* interface Person {
* name: string;
* }
* interface Friend {
* startDate: number;
* endDate?: number;
* }
* const db = new Database();
* const documents = db.collection("persons") as DocumentCollection<Person>;
* const edges = db.collection("friends") as EdgeCollection<Friend>;
* ```
* @internal
* @hidden
*/

@@ -195,3 +192,3 @@ class Collection {

catch (err) {
if (err.statusCode === 404) {
if (err.code === 404) {
return false;

@@ -339,3 +336,3 @@ }

body: { type, collection: this._name },
}, (res) => new cursor_1.ArrayCursor(this._db, res.body, res.arangojsHostId));
}, (res) => new cursor_1.BatchedArrayCursor(this._db, res.body, res.arangojsHostId).items);
}

@@ -350,3 +347,3 @@ all(options) {

},
}, (res) => new cursor_1.ArrayCursor(this._db, res.body, res.arangojsHostId));
}, (res) => new cursor_1.BatchedArrayCursor(this._db, res.body, res.arangojsHostId).items);
}

@@ -369,3 +366,3 @@ any() {

},
}, (res) => new cursor_1.ArrayCursor(this._db, res.body, res.arangojsHostId));
}, (res) => new cursor_1.BatchedArrayCursor(this._db, res.body, res.arangojsHostId).items);
}

@@ -474,3 +471,3 @@ firstExample(example) {

},
}, (res) => new cursor_1.ArrayCursor(this._db, res.body, res.arangojsHostId));
}, (res) => new cursor_1.BatchedArrayCursor(this._db, res.body, res.arangojsHostId).items);
}

@@ -477,0 +474,0 @@ }

@@ -12,7 +12,16 @@ /// <reference types="node" />

*/
import { AgentOptions } from "https";
import { ClientRequest } from "http";
import { AgentOptions as NodeAgentOptions } from "https";
import { LinkedList } from "x3-linkedlist";
import { Database } from "./database";
import { ArangojsResponse, RequestFunction } from "./lib/request";
import { ArangojsError, ArangojsResponse, RequestFunction } from "./lib/request";
/**
* Generic type representing an object with values of a given value type.
*
* @param T - Type of the object's property values.
*/
export declare type Dict<T> = {
[key: string]: T;
};
/**
* Determines the behavior when multiple URLs are used:

@@ -36,5 +45,3 @@ *

*/
export declare type Headers = {
[key: string]: string;
};
export declare type Headers = Dict<string>;
/**

@@ -44,5 +51,3 @@ * An arbitrary object with scalar values representing query string parameters

*/
export declare type Params = {
[key: string]: any;
};
export declare type Params = Dict<any>;
/**

@@ -57,3 +62,3 @@ * Generic properties shared by all ArangoDB HTTP API responses.

/**
* The response status code, typically `200`.
* Response status code, typically `200`.
*/

@@ -65,9 +70,9 @@ code: number;

*/
export declare type BasicAuth = {
export declare type BasicAuthCredentials = {
/**
* The username, e.g. `"root"`.
* Username to use for authentication, e.g. `"root"`.
*/
username: string;
/**
* The password. Defaults to an empty string.
* Password to use for authentication. Defaults to an empty string.
*/

@@ -79,8 +84,12 @@ password?: string;

*/
export declare type BearerAuth = {
export declare type BearerAuthCredentials = {
/**
* The Bearer token.
* Bearer token to use for authentication.
*/
token: string;
};
/**
* @internal
* @hidden
*/
declare type UrlInfo = {

@@ -100,10 +109,64 @@ absolutePath?: boolean;

export declare type XhrOptions = {
/**
* Maximum number of parallel requests arangojs will perform. If any
* additional requests are attempted, they will be enqueued until one of the
* active requests has completed.
*/
maxSockets?: number;
/**
* Number of milliseconds to wait for a response.
*
* Default: `0` (disabled)
*/
timeout?: number;
/**
* Callback that will be invoked immediately before the `send` method of the
* request is called.
*
* See also {@link RequestInterceptors}.
*/
beforeSend?: (xhrObject: any) => void;
/**
* `XMLHttpRequest` object to use instead of the native implementation.
*/
xhr?: any;
/**
* (Internet Explorer 10 and lower only.) Whether `XDomainRequest` should be
* used instead of `XMLHttpRequest`. Only required for performing
* cross-domain requests in older versions of Internet Explorer.
*/
useXdr?: boolean;
/**
* Specifies whether browser credentials (e.g. cookies) should be sent if
* performing a cross-domain request.
*
* See {@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials | `XMLHttpRequest.withCredentials`}.
*/
withCredentials?: boolean;
};
/**
* Additional options for intercepting the request/response. These methods
* are primarily intended for tracking network related metrics.
*/
export declare type RequestInterceptors = {
/**
* Callback that will be invoked with the finished request object before it
* is finalized. In the browser the request may already have been sent.
*
* @param req - Request object or XHR instance used for this request.
*/
before?: (req: ClientRequest) => void;
/**
* Callback that will be invoked when the server response has been received
* and processed or when the request has been failed without a response.
*
* The originating request will be available as the `request` property
* on either the error or response object.
*
* @param err - Error encountered when handling this request or `null`.
* @param res - Response object for this request, if no error occurred.
*/
after?: (err: ArangojsError | null, res?: ArangojsResponse) => void;
};
/**
* Options for performing a request with arangojs.

@@ -169,4 +232,9 @@ */

};
/**
* @internal
* @hidden
*/
declare type Task = {
host?: number;
stack?: string;
allowDirtyRead: boolean;

@@ -189,2 +257,14 @@ resolve: Function;

/**
* Options for creating the Node.js `http.Agent` or `https.Agent`.
*
* In browser environments this option can be used to pass additional options
* to the underlying calls of the
* {@link https://www.npmjs.com/package/xhr | xhr module}.
*
* See also {@link https://nodejs.org/api/http.html#http_new_agent_options | `http.Agent`}
* and {@link https://nodejs.org/api/https.html#https_new_agent_options | `https.Agent`}
* (when using TLS).
*/
export declare type AgentOptions = NodeAgentOptions | XhrOptions;
/**
* Options for configuring arangojs.

@@ -236,3 +316,3 @@ */

*/
auth?: BasicAuth | BearerAuth;
auth?: BasicAuthCredentials | BearerAuthCredentials;
/**

@@ -313,10 +393,2 @@ * Numeric representation of the ArangoDB version the driver should expect.

*
* In the browser version of arangojs this option can be used to pass
* additional options to the underlying calls of the
* {@link https://www.npmjs.com/package/xhr | xhr module}.
*
* See also: {@link https://nodejs.org/api/http.html#http_new_agent_options | `http.Agent`}
* and {@link https://nodejs.org/api/https.html#https_new_agent_options | `https.Agent`}
* (when using TLS).
*
* Default (Node.js): `{ maxSockets: 3, keepAlive: true, keepAliveMsecs: 1000 }`

@@ -326,3 +398,3 @@ *

*/
agentOptions?: AgentOptions | XhrOptions;
agentOptions?: AgentOptions & RequestInterceptors;
/**

@@ -336,2 +408,11 @@ * An object with additional headers to send with every request.

headers?: Headers;
/**
* If set to `true`, arangojs will generate stack traces every time a request
* is initiated and augment the stack traces of any errors it generates.
*
* **Warning**: This will cause arangojs to generate stack traces in advance
* even if the request does not result in an error. Generating stack traces
* may negatively impact performance.
*/
precaptureStackTraces?: boolean;
};

@@ -373,2 +454,3 @@ /**

protected _transactionId: string | null;
protected _precaptureStackTraces: boolean;
/**

@@ -398,4 +480,4 @@ * @internal

};
setBearerAuth(auth: BearerAuth): void;
setBasicAuth(auth: BasicAuth): void;
setBearerAuth(auth: BearerAuthCredentials): void;
setBasicAuth(auth: BasicAuthCredentials): void;
/**

@@ -449,3 +531,3 @@ * @internal

*
* See {@link Connection.clearTransactionId}.
* See also {@link Connection.clearTransactionId}.
*

@@ -452,0 +534,0 @@ * @param transactionId - ID of the active transaction.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Connection = exports.isArangoConnection = void 0;
const querystring_1 = require("querystring");

@@ -7,4 +8,4 @@ const x3_linkedlist_1 = require("x3-linkedlist");

const btoa_1 = require("./lib/btoa");
const normalizeUrl_1 = require("./lib/normalizeUrl");
const request_1 = require("./lib/request");
const sanitizeUrl_1 = require("./lib/sanitizeUrl");
const MIME_JSON = /\/(json|javascript)(\W|$)/;

@@ -26,2 +27,18 @@ const LEADER_ENDPOINT_HEADER = "x-arango-endpoint";

/**
* @internal
* @hidden
*/
function generateStackTrace() {
let err = new Error();
if (!err.stack) {
try {
throw err;
}
catch (e) {
err = e;
}
}
return err.stack;
}
/**
* Indicates whether the given value represents a {@link Connection}.

@@ -80,2 +97,3 @@ *

this._useFailOver = this._loadBalancingStrategy !== "ROUND_ROBIN";
this._precaptureStackTraces = Boolean(config.precaptureStackTraces);
if (config.maxRetries === false) {

@@ -156,2 +174,5 @@ this._shouldRetry = false;

else {
if (task.stack) {
err.stack += task.stack;
}
task.reject(err);

@@ -224,3 +245,3 @@ }

addToHostList(urls) {
const cleanUrls = (Array.isArray(urls) ? urls : [urls]).map((url) => sanitizeUrl_1.sanitizeUrl(url));
const cleanUrls = (Array.isArray(urls) ? urls : [urls]).map((url) => normalizeUrl_1.normalizeUrl(url));
const newUrls = cleanUrls.filter((url) => this._urls.indexOf(url) === -1);

@@ -240,3 +261,3 @@ this._urls.push(...newUrls);

*
* See {@link Connection.clearTransactionId}.
* See also {@link Connection.clearTransactionId}.
*

@@ -314,3 +335,3 @@ * @param transactionId - ID of the active transaction.

}
this._queue.push({
const task = {
retries: 0,

@@ -353,7 +374,3 @@ host,

}
if (parsedBody &&
parsedBody.hasOwnProperty("error") &&
parsedBody.hasOwnProperty("code") &&
parsedBody.hasOwnProperty("errorMessage") &&
parsedBody.hasOwnProperty("errorNum")) {
if (error_1.isArangoErrorResponse(parsedBody)) {
res.body = parsedBody;

@@ -372,3 +389,16 @@ reject(new error_1.ArangoError(res));

},
});
};
if (this._precaptureStackTraces) {
if (typeof Error.captureStackTrace === "function") {
Error.captureStackTrace(task);
task.stack = `\n${task.stack.split("\n").slice(3).join("\n")}`;
}
else {
const stack = generateStackTrace();
if (stack) {
task.stack = `\n${stack.split("\n").slice(4).join("\n")}`;
}
}
}
this._queue.push(task);
this._runQueue();

@@ -375,0 +405,0 @@ });

/**
* ```ts
* import type { ArrayCursor } from "arangojs/cursor";
* import type { ArrayCursor, BatchedArrayCursor } from "arangojs/cursor";
* ```
*
* The "cursor" module provides the {@link ArrayCursor} type for TypeScript.
* The "cursor" module provides cursor-related interfaces for TypeScript.
*

@@ -11,4 +11,4 @@ * @packageDocumentation

import { LinkedList } from "x3-linkedlist";
import { Dict } from "./connection";
import { Database } from "./database";
import { Dict } from "./util/types";
/**

@@ -18,2 +18,5 @@ * Additional information about the cursor.

export interface CursorExtras {
/**
* Warnings encountered while executing the query.
*/
warnings: {

@@ -23,9 +26,22 @@ code: number;

}[];
/**
* Query execution plan for the executed query.
*/
plan?: any;
/**
* Additional profiling information for the executed query.
*/
profile?: any;
/**
* Additional statistics about the query execution.
*/
stats?: Dict<any>;
}
interface BatchView<T = any> {
isEmpty: boolean;
more(): Promise<void>;
shift(): T | undefined;
}
/**
* The `ArrayCursor` type represents a cursor returned from a
* {@link Database.query}.
* The `BatchedArrayCursor` provides a batch-wise API to an {@link ArrayCursor}.
*

@@ -41,8 +57,22 @@ * When using TypeScript, cursors can be cast to a specific item type in order

* const query = aql`FOR x IN 1..5 RETURN x`;
* const result = await db.query(query) as ArrayCursor<number>;
* const cursor = await db.query(query) as ArrayCursor<number>;
* const batches = cursor.batches;
* ```
*
* @example
* ```js
* const db = new Database();
* const query = aql`FOR x IN 1..10000 RETURN x`;
* const cursor = await db.query(query, { batchSize: 10 });
* for await (const batch of cursor.batches) {
* // Process all values in a batch in parallel
* await Promise.all(batch.map(
* value => asyncProcessValue(value)
* ));
* }
* ```
*/
export declare class ArrayCursor<T = any> {
export declare class BatchedArrayCursor<T = any> {
protected _db: Database;
protected _result: LinkedList<any>;
protected _batches: LinkedList<LinkedList<any>>;
protected _count?: number;

@@ -54,2 +84,3 @@ protected _extra: CursorExtras;

protected _allowDirtyRead?: boolean;
protected _itemsCursor: ArrayCursor<T>;
/**

@@ -66,10 +97,15 @@ * @internal

}, host?: number, allowDirtyRead?: boolean);
protected _drain(): Promise<ArrayCursor<T>>;
protected _more(): Promise<void>;
/**
* An {@link ArrayCursor} providing item-wise access to the cursor result set.
*
* See also {@link ArrayCursor.batches}.
*/
get items(): ArrayCursor<T>;
/**
* Additional information about the cursor.
*/
get extra(): CursorExtras;
get extra(): Readonly<CursorExtras>;
/**
* The total number of documents in the query result. Only available if the
* Total number of documents in the query result. Only available if the
* `count` option was used.

@@ -82,6 +118,390 @@ */

* additional requests to the server will be made when consuming any
* remaining items from this cursor.
* remaining batches from this cursor.
*/
get hasMore(): boolean;
/**
* Whether the cursor has more batches. If set to `false`, the cursor has
* already been depleted and contains no more batches.
*/
get hasNext(): boolean;
/**
* Enables use with `for await` to deplete the cursor by asynchronously
* yielding every batch in the cursor's remaining result set.
*
* **Note**: If the result set spans multiple batches, any remaining batches
* will only be fetched on demand. Depending on the cursor's TTL and the
* processing speed, this may result in the server discarding the cursor
* before it is fully depleted.
*
* @example
* ```js
* const cursor = await db.query(aql`
* FOR user IN users
* FILTER user.isActive
* RETURN user
* `);
* for await (const users of cursor.batches) {
* for (const user of users) {
* console.log(user.email, user.isAdmin);
* }
* }
* ```
*/
[Symbol.asyncIterator](): AsyncGenerator<T[], undefined, undefined>;
/**
* Loads all remaining batches from the server.
*
* **Warning**: This may impact memory use when working with very large
* query result sets.
*
* @example
* ```js
* const cursor = await db.query(
* aql`FOR x IN 1..5 RETURN x`,
* { batchSize: 1 }
* );
* console.log(cursor.hasMore); // true
* await cursor.batches.loadAll();
* console.log(cursor.hasMore); // false
* console.log(cursor.hasNext); // true
* for await (const item of cursor) {
* console.log(item);
* // No server roundtrips necessary any more
* }
* ```
*/
loadAll(): Promise<void>;
/**
* Depletes the cursor, then returns an array containing all batches in the
* cursor's remaining result list.
*
* @example
* ```js
* const cursor = await db.query(
* aql`FOR x IN 1..5 RETURN x`,
* { batchSize: 2 }
* );
* const result = await cursor.batches.all(); // [[1, 2], [3, 4], [5]]
* console.log(cursor.hasNext); // false
* ```
*/
all(): Promise<T[][]>;
/**
* Advances the cursor and returns all remaining values in the cursor's
* current batch. If the current batch has already been exhausted, fetches
* the next batch from the server and returns it, or `undefined` if the
* cursor has been depleted.
*
* **Note**: If the result set spans multiple batches, any remaining batches
* will only be fetched on demand. Depending on the cursor's TTL and the
* processing speed, this may result in the server discarding the cursor
* before it is fully depleted.
*
* @example
* ```js
* const cursor = await db.query(
* aql`FOR i IN 1..10 RETURN i`,
* { batchSize: 5 }
* );
* const firstBatch = await cursor.batches.next(); // [1, 2, 3, 4, 5]
* await cursor.next(); // 6
* const lastBatch = await cursor.batches.next(); // [7, 8, 9, 10]
* console.log(cursor.hasNext); // false
* ```
*/
next(): Promise<T[] | undefined>;
/**
* Advances the cursor by applying the `callback` function to each item in
* the cursor's remaining result list until the cursor is depleted or
* `callback` returns the exact value `false`. Returns a promise that
* evalues to `true` unless the function returned `false`.
*
* **Note**: If the result set spans multiple batches, any remaining batches
* will only be fetched on demand. Depending on the cursor's TTL and the
* processing speed, this may result in the server discarding the cursor
* before it is fully depleted.
*
* See also:
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach | `Array.prototype.forEach`}.
*
* @param callback - Function to execute on each element.
*
* @example
* ```js
* const cursor = await db.query(
* aql`FOR x IN 1..5 RETURN x`,
* { batchSize: 2 }
* );
* const result = await cursor.batches.forEach((currentBatch) => {
* for (const value of currentBatch) {
* console.log(value);
* }
* });
* console.log(result) // true
* console.log(cursor.hasNext); // false
* ```
*
* @example
* ```js
* const cursor = await db.query(
* aql`FOR x IN 1..5 RETURN x`,
* { batchSize: 2 }
* );
* const result = await cursor.batches.forEach((currentBatch) => {
* for (const value of currentBatch) {
* console.log(value);
* }
* return false; // stop after the first batch
* });
* console.log(result); // false
* console.log(cursor.hasNext); // true
* ```
*/
forEach(callback: (currentBatch: T[], index: number, self: this) => false | void): Promise<boolean>;
/**
* Depletes the cursor by applying the `callback` function to each batch in
* the cursor's remaining result list. Returns an array containing the
* return values of `callback` for each batch.
*
* **Note**: This creates an array of all return values, which may impact
* memory use when working with very large query result sets. Consider using
* {@link BatchedArrayCursor.forEach}, {@link BatchedArrayCursor.reduce} or
* {@link BatchedArrayCursor.flatMap} instead.
*
* See also:
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | `Array.prototype.map`}.
*
* @param R - Return type of the `callback` function.
* @param callback - Function to execute on each element.
*
* @example
* ```js
* const cursor = await db.query(
* aql`FOR x IN 1..5 RETURN x`,
* { batchSize: 2 }
* );
* const squares = await cursor.batches.map((currentBatch) => {
* return currentBatch.map((value) => value ** 2);
* });
* console.log(squares); // [[1, 4], [9, 16], [25]]
* console.log(cursor.hasNext); // false
* ```
*/
map<R>(callback: (currentBatch: T[], index: number, self: this) => R): Promise<R[]>;
/**
* Depletes the cursor by applying the `callback` function to each batch in
* the cursor's remaining result list. Returns an array containing the
* return values of `callback` for each batch, flattened to a depth of 1.
*
* **Note**: If the result set spans multiple batches, any remaining batches
* will only be fetched on demand. Depending on the cursor's TTL and the
* processing speed, this may result in the server discarding the cursor
* before it is fully depleted.
*
* See also:
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap | `Array.prototype.flatMap`}.
*
* @param R - Return type of the `callback` function.
* @param callback - Function to execute on each element.
*
* @example
* ```js
* const cursor = await db.query(
* aql`FOR x IN 1..5 RETURN x`,
* { batchSize: 2 }
* );
* const squares = await cursor.batches.flatMap((currentBatch) => {
* return currentBatch.map((value) => value ** 2);
* });
* console.log(squares); // [1, 1, 2, 4, 3, 9, 4, 16, 5, 25]
* console.log(cursor.hasNext); // false
* ```
*
* @example
* ```js
* const cursor = await db.query(
* aql`FOR x IN 1..5 RETURN x`,
* { batchSize: 1 }
* );
* const odds = await cursor.batches.flatMap((currentBatch) => {
* if (currentBatch[0] % 2 === 0) {
* return []; // empty array flattens into nothing
* }
* return currentBatch;
* });
* console.logs(odds); // [1, 3, 5]
* ```
*/
flatMap<R>(callback: (currentBatch: T[], index: number, self: this) => R | R[]): Promise<R[]>;
/**
* Depletes the cursor by applying the `reducer` function to each batch in
* the cursor's remaining result list. Returns the return value of `reducer`
* for the last batch.
*
* **Note**: Most complex uses of the `reduce` method can be replaced with
* simpler code using {@link BatchedArrayCursor.forEach} or the `for await`
* syntax.
*
* **Note**: If the result set spans multiple batches, any remaining batches
* will only be fetched on demand. Depending on the cursor's TTL and the
* processing speed, this may result in the server discarding the cursor
* before it is fully depleted.
*
* See also:
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce | `Array.prototype.reduce`}.
*
* @param R - Return type of the `reducer` function.
* @param reducer - Function to execute on each element.
* @param initialValue - Initial value of the `accumulator` value passed to
* the `reducer` function.
*
* @example
* ```js
* function largestValue(baseline, values) {
* return Math.max(baseline, ...values);
* }
* const cursor = await db.query(
* aql`FOR x IN 1..5 RETURN x`,
* { batchSize: 3 }
* );
* const result = await cursor.batches.reduce(largestValue, 0);
* console.log(result); // 5
* console.log(cursor.hasNext); // false
* const emptyResult = await cursor.batches.reduce(largestValue, 0);
* console.log(emptyResult); // 0
* ```
*
* @example
* ```js
* // BAD! NEEDLESSLY COMPLEX!
* const cursor = await db.query(
* aql`FOR x IN 1..5 RETURN x`,
* { batchSize: 1 }
* );
* const result = await cursor.reduce((accumulator, currentBatch) => {
* accumulator[
* currentBatch[0] % 2 === 0 ? "even" : "odd"
* ].push(...currentBatch);
* return accumulator;
* }, { odd: [], even: [] });
* console.log(result); // { odd: [1, 3, 5], even: [2, 4] }
*
* // GOOD! MUCH SIMPLER!
* const cursor = await db.query(aql`FOR x IN 1..5 RETURN x`);
* const odd = [];
* const even = [];
* for await (const item of cursor) {
* if (currentBatch[0] % 2 === 0) {
* even.push(...currentBatch);
* } else {
* odd.push(...currentBatch);
* }
* }
* console.log({ odd, even }); // { odd: [1, 3, 5], even: [2, 4] }
* ```
*/
reduce<R>(reducer: (accumulator: R, currentBatch: T[], index: number, self: this) => R, initialValue: R): Promise<R>;
/**
* Depletes the cursor by applying the `reducer` function to each batch in
* the cursor's remaining result list. Returns the return value of `reducer`
* for the last batch.
*
* **Note**: If the result set spans multiple batches, any remaining batches
* will only be fetched on demand. Depending on the cursor's TTL and the
* processing speed, this may result in the server discarding the cursor
* before it is fully depleted.
*
* See also:
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce | `Array.prototype.reduce`}.
*
* @param R - Return type of the `reducer` function.
* @param reducer - Function to execute on each element.
*
* @example
* ```js
* function largestValue(values1, values2) {
* return [Math.max(...values1, ...values2)];
* }
* const cursor = await db.query(
* aql`FOR x IN 1..5 RETURN x`,
* { batchSize: 3 }
* );
* const result = await cursor.batches.reduce(largestValue);
* console.log(result); // [5]
* console.log(cursor.hasNext); // false
* ```
*
*/
reduce<R>(reducer: (accumulator: T[] | R, currentBatch: T[], index: number, self: this) => R): Promise<R | undefined>;
/**
* Kills the cursor and frees up associated database resources.
*
* This method has no effect if all batches have already been fetched.
*
* @example
* ```js
* const cursor1 = await db.query(aql`FOR x IN 1..5 RETURN x`);
* console.log(cursor1.hasMore); // false
* await cursor1.kill(); // no effect
*
* const cursor2 = await db.query(
* aql`FOR x IN 1..5 RETURN x`,
* { batchSize: 2 }
* );
* console.log(cursor2.hasMore); // true
* await cursor2.kill(); // cursor is depleted
* ```
*/
kill(): Promise<void>;
}
/**
* The `ArrayCursor` type represents a cursor returned from a
* {@link Database.query}.
*
* When using TypeScript, cursors can be cast to a specific item type in order
* to increase type safety.
*
* See also {@link BatchedArrayCursor}.
*
* @param T - Type to use for each item. Defaults to `any`.
*
* @example
* ```ts
* const db = new Database();
* const query = aql`FOR x IN 1..5 RETURN x`;
* const result = await db.query(query) as ArrayCursor<number>;
* ```
*
* @example
* ```js
* const db = new Database();
* const query = aql`FOR x IN 1..10 RETURN x`;
* const cursor = await db.query(query);
* for await (const value of cursor) {
* // Process each value asynchronously
* await processValue(value);
* }
* ```
*/
export declare class ArrayCursor<T = any> {
protected _batches: BatchedArrayCursor<T>;
protected _view: BatchView<T>;
constructor(batchedCursor: BatchedArrayCursor, view: BatchView<T>);
/**
* A {@link BatchedArrayCursor} providing batch-wise access to the cursor
* result set.
*
* See also {@link BatchedArrayCursor.items}.
*/
get batches(): BatchedArrayCursor<T>;
/**
* Additional information about the cursor.
*/
get extra(): CursorExtras;
/**
* Total number of documents in the query result. Only available if the
* `count` option was used.
*/
get count(): number | undefined;
/**
* Whether the cursor has more values. If set to `false`, the cursor has

@@ -122,2 +542,3 @@ * already been depleted and contains no more items.

* console.log(cursor.hasNext); // false
* ```
*/

@@ -145,26 +566,2 @@ all(): Promise<T[]>;

/**
* Advances the cursor and returns all remaining values in the cursor's
* current batch. If the current batch has already been exhausted, fetches
* the next batch from the server and returns it, or `undefined` if the
* cursor has been depleted.
*
* **Note**: If the result set spans multiple batches, any remaining batches
* will only be fetched on demand. Depending on the cursor's TTL and the
* processing speed, this may result in the server discarding the cursor
* before it is fully depleted.
*
* @example
* ```js
* const cursor = await db.query(
* aql`FOR i IN 1..10 RETURN i`,
* { batchSize: 5 }
* );
* const firstBatch = await cursor.nextBatch(); // [1, 2, 3, 4, 5]
* await cursor.next(); // 6
* const lastBatch = await cursor.nextBatch(); // [7, 8, 9, 10]
* console.log(cursor.hasNext); // false
* ```
*/
nextBatch(): Promise<any[] | undefined>;
/**
* Advances the cursor by applying the `callback` function to each item in

@@ -383,2 +780,3 @@ * the cursor's remaining result list until the cursor is depleted or

}
export {};
//# sourceMappingURL=cursor.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ArrayCursor = exports.BatchedArrayCursor = void 0;
/**
* ```ts
* import type { ArrayCursor } from "arangojs/cursor";
* import type { ArrayCursor, BatchedArrayCursor } from "arangojs/cursor";
* ```
*
* The "cursor" module provides the {@link ArrayCursor} type for TypeScript.
* The "cursor" module provides cursor-related interfaces for TypeScript.
*

@@ -14,4 +15,3 @@ * @packageDocumentation

/**
* The `ArrayCursor` type represents a cursor returned from a
* {@link Database.query}.
* The `BatchedArrayCursor` provides a batch-wise API to an {@link ArrayCursor}.
*

@@ -27,6 +27,20 @@ * When using TypeScript, cursors can be cast to a specific item type in order

* const query = aql`FOR x IN 1..5 RETURN x`;
* const result = await db.query(query) as ArrayCursor<number>;
* const cursor = await db.query(query) as ArrayCursor<number>;
* const batches = cursor.batches;
* ```
*
* @example
* ```js
* const db = new Database();
* const query = aql`FOR x IN 1..10000 RETURN x`;
* const cursor = await db.query(query, { batchSize: 10 });
* for await (const batch of cursor.batches) {
* // Process all values in a batch in parallel
* await Promise.all(batch.map(
* value => asyncProcessValue(value)
* ));
* }
* ```
*/
class ArrayCursor {
class BatchedArrayCursor {
/**

@@ -37,4 +51,6 @@ * @internal

constructor(db, body, host, allowDirtyRead) {
const initialBatch = new x3_linkedlist_1.LinkedList(body.result);
const batches = new x3_linkedlist_1.LinkedList([initialBatch]);
this._db = db;
this._result = new x3_linkedlist_1.LinkedList(body.result);
this._batches = batches;
this._id = body.id;

@@ -46,9 +62,23 @@ this._hasMore = Boolean(body.id && body.hasMore);

this._allowDirtyRead = allowDirtyRead;
this._itemsCursor = new ArrayCursor(this, {
get isEmpty() {
return !batches.length;
},
more: () => this._more(),
shift: () => {
var _a, _b;
let batch = (_a = batches.first) === null || _a === void 0 ? void 0 : _a.value;
while (batch && !batch.length) {
batches.shift();
batch = (_b = batches.first) === null || _b === void 0 ? void 0 : _b.value;
}
if (!batch)
return undefined;
const value = batch.shift();
if (!batch.length)
batches.shift();
return value;
},
});
}
async _drain() {
await this._more();
if (!this.hasMore)
return this;
return this._drain();
}
async _more() {

@@ -63,6 +93,14 @@ if (!this.hasMore)

});
this._result.push(...res.body.result);
this._batches.push(new x3_linkedlist_1.LinkedList(res.body.result));
this._hasMore = res.body.hasMore;
}
/**
* An {@link ArrayCursor} providing item-wise access to the cursor result set.
*
* See also {@link ArrayCursor.batches}.
*/
get items() {
return this._itemsCursor;
}
/**
* Additional information about the cursor.

@@ -74,3 +112,3 @@ */

/**
* The total number of documents in the query result. Only available if the
* Total number of documents in the query result. Only available if the
* `count` option was used.

@@ -85,3 +123,3 @@ */

* additional requests to the server will be made when consuming any
* remaining items from this cursor.
* remaining batches from this cursor.
*/

@@ -92,11 +130,11 @@ get hasMore() {

/**
* Whether the cursor has more values. If set to `false`, the cursor has
* already been depleted and contains no more items.
* Whether the cursor has more batches. If set to `false`, the cursor has
* already been depleted and contains no more batches.
*/
get hasNext() {
return this.hasMore || Boolean(this._result.length);
return this.hasMore || Boolean(this._batches.length);
}
/**
* Enables use with `for await` to deplete the cursor by asynchronously
* yielding every value in the cursor's remaining result set.
* yielding every batch in the cursor's remaining result set.
*

@@ -115,4 +153,6 @@ * **Note**: If the result set spans multiple batches, any remaining batches

* `);
* for await (const user of cursor) {
* console.log(user.email, user.isAdmin);
* for await (const users of cursor.batches) {
* for (const user of users) {
* console.log(user.email, user.isAdmin);
* }
* }

@@ -128,3 +168,30 @@ * ```

/**
* Depletes the cursor, then returns an array containing all values in the
* Loads all remaining batches from the server.
*
* **Warning**: This may impact memory use when working with very large
* query result sets.
*
* @example
* ```js
* const cursor = await db.query(
* aql`FOR x IN 1..5 RETURN x`,
* { batchSize: 1 }
* );
* console.log(cursor.hasMore); // true
* await cursor.batches.loadAll();
* console.log(cursor.hasMore); // false
* console.log(cursor.hasNext); // true
* for await (const item of cursor) {
* console.log(item);
* // No server roundtrips necessary any more
* }
* ```
*/
async loadAll() {
while (this._hasMore) {
await this._more();
}
}
/**
* Depletes the cursor, then returns an array containing all batches in the
* cursor's remaining result list.

@@ -134,15 +201,18 @@ *

* ```js
* const cursor = await db.query(aql`FOR x IN 1..5 RETURN x`);
* const result = await cursor.all(); // [1, 2, 3, 4, 5]
* const cursor = await db.query(
* aql`FOR x IN 1..5 RETURN x`,
* { batchSize: 2 }
* );
* const result = await cursor.batches.all(); // [[1, 2], [3, 4], [5]]
* console.log(cursor.hasNext); // false
* ```
*/
async all() {
await this._drain();
const result = [...this._result.values()];
this._result.clear();
return result;
return this.map((batch) => batch);
}
/**
* Advances the cursor and returns the next value in the cursor's remaining
* result list, or `undefined` if the cursor has been depleted.
* Advances the cursor and returns all remaining values in the cursor's
* current batch. If the current batch has already been exhausted, fetches
* the next batch from the server and returns it, or `undefined` if the
* cursor has been depleted.
*

@@ -156,23 +226,27 @@ * **Note**: If the result set spans multiple batches, any remaining batches

* ```js
* const cursor = await db.query(aql`FOR x IN 1..3 RETURN x`);
* const one = await cursor.next(); // 1
* const two = await cursor.next(); // 2
* const three = await cursor.next(); // 3
* const empty = await cursor.next(); // undefined
* const cursor = await db.query(
* aql`FOR i IN 1..10 RETURN i`,
* { batchSize: 5 }
* );
* const firstBatch = await cursor.batches.next(); // [1, 2, 3, 4, 5]
* await cursor.next(); // 6
* const lastBatch = await cursor.batches.next(); // [7, 8, 9, 10]
* console.log(cursor.hasNext); // false
* ```
*/
async next() {
while (!this._result.length && this.hasMore) {
while (!this._batches.length && this.hasNext) {
await this._more();
}
if (!this._result.length) {
if (!this._batches.length) {
return undefined;
}
return this._result.shift();
const batch = this._batches.shift();
return batch && [...batch.values()];
}
/**
* Advances the cursor and returns all remaining values in the cursor's
* current batch. If the current batch has already been exhausted, fetches
* the next batch from the server and returns it, or `undefined` if the
* cursor has been depleted.
* Advances the cursor by applying the `callback` function to each item in
* the cursor's remaining result list until the cursor is depleted or
* `callback` returns the exact value `false`. Returns a promise that
* evalues to `true` unless the function returned `false`.
*

@@ -184,26 +258,330 @@ * **Note**: If the result set spans multiple batches, any remaining batches

*
* See also:
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach | `Array.prototype.forEach`}.
*
* @param callback - Function to execute on each element.
*
* @example
* ```js
* const cursor = await db.query(
* aql`FOR i IN 1..10 RETURN i`,
* { batchSize: 5 }
* aql`FOR x IN 1..5 RETURN x`,
* { batchSize: 2 }
* );
* const firstBatch = await cursor.nextBatch(); // [1, 2, 3, 4, 5]
* await cursor.next(); // 6
* const lastBatch = await cursor.nextBatch(); // [7, 8, 9, 10]
* const result = await cursor.batches.forEach((currentBatch) => {
* for (const value of currentBatch) {
* console.log(value);
* }
* });
* console.log(result) // true
* console.log(cursor.hasNext); // false
* ```
*
* @example
* ```js
* const cursor = await db.query(
* aql`FOR x IN 1..5 RETURN x`,
* { batchSize: 2 }
* );
* const result = await cursor.batches.forEach((currentBatch) => {
* for (const value of currentBatch) {
* console.log(value);
* }
* return false; // stop after the first batch
* });
* console.log(result); // false
* console.log(cursor.hasNext); // true
* ```
*/
async nextBatch() {
while (!this._result.length && this.hasMore) {
await this._more();
async forEach(callback) {
let index = 0;
while (this.hasNext) {
const currentBatch = await this.next();
const result = callback(currentBatch, index, this);
index++;
if (result === false)
return result;
if (this.hasNext)
await this._more();
}
if (!this._result.length) {
return undefined;
return true;
}
/**
* Depletes the cursor by applying the `callback` function to each batch in
* the cursor's remaining result list. Returns an array containing the
* return values of `callback` for each batch.
*
* **Note**: This creates an array of all return values, which may impact
* memory use when working with very large query result sets. Consider using
* {@link BatchedArrayCursor.forEach}, {@link BatchedArrayCursor.reduce} or
* {@link BatchedArrayCursor.flatMap} instead.
*
* See also:
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | `Array.prototype.map`}.
*
* @param R - Return type of the `callback` function.
* @param callback - Function to execute on each element.
*
* @example
* ```js
* const cursor = await db.query(
* aql`FOR x IN 1..5 RETURN x`,
* { batchSize: 2 }
* );
* const squares = await cursor.batches.map((currentBatch) => {
* return currentBatch.map((value) => value ** 2);
* });
* console.log(squares); // [[1, 4], [9, 16], [25]]
* console.log(cursor.hasNext); // false
* ```
*/
async map(callback) {
let index = 0;
let result = [];
while (this.hasNext) {
const currentBatch = await this.next();
result.push(callback(currentBatch, index, this));
index++;
}
const result = [...this._result.values()];
this._result.clear();
return result;
}
/**
* Depletes the cursor by applying the `callback` function to each batch in
* the cursor's remaining result list. Returns an array containing the
* return values of `callback` for each batch, flattened to a depth of 1.
*
* **Note**: If the result set spans multiple batches, any remaining batches
* will only be fetched on demand. Depending on the cursor's TTL and the
* processing speed, this may result in the server discarding the cursor
* before it is fully depleted.
*
* See also:
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap | `Array.prototype.flatMap`}.
*
* @param R - Return type of the `callback` function.
* @param callback - Function to execute on each element.
*
* @example
* ```js
* const cursor = await db.query(
* aql`FOR x IN 1..5 RETURN x`,
* { batchSize: 2 }
* );
* const squares = await cursor.batches.flatMap((currentBatch) => {
* return currentBatch.map((value) => value ** 2);
* });
* console.log(squares); // [1, 1, 2, 4, 3, 9, 4, 16, 5, 25]
* console.log(cursor.hasNext); // false
* ```
*
* @example
* ```js
* const cursor = await db.query(
* aql`FOR x IN 1..5 RETURN x`,
* { batchSize: 1 }
* );
* const odds = await cursor.batches.flatMap((currentBatch) => {
* if (currentBatch[0] % 2 === 0) {
* return []; // empty array flattens into nothing
* }
* return currentBatch;
* });
* console.logs(odds); // [1, 3, 5]
* ```
*/
async flatMap(callback) {
let index = 0;
let result = [];
while (this.hasNext) {
const currentBatch = await this.next();
const value = callback(currentBatch, index, this);
if (Array.isArray(value)) {
result.push(...value);
}
else {
result.push(value);
}
index++;
}
return result;
}
async reduce(reducer, initialValue) {
let index = 0;
if (!this.hasNext)
return initialValue;
if (initialValue === undefined) {
initialValue = (await this.next());
index += 1;
}
let value = initialValue;
while (this.hasNext) {
const currentBatch = await this.next();
value = reducer(value, currentBatch, index, this);
index++;
}
return value;
}
/**
* Kills the cursor and frees up associated database resources.
*
* This method has no effect if all batches have already been fetched.
*
* @example
* ```js
* const cursor1 = await db.query(aql`FOR x IN 1..5 RETURN x`);
* console.log(cursor1.hasMore); // false
* await cursor1.kill(); // no effect
*
* const cursor2 = await db.query(
* aql`FOR x IN 1..5 RETURN x`,
* { batchSize: 2 }
* );
* console.log(cursor2.hasMore); // true
* await cursor2.kill(); // cursor is depleted
* ```
*/
async kill() {
if (!this.hasNext)
return undefined;
return this._db.request({
method: "DELETE",
path: `/_api/cursor/${this._id}`,
}, () => {
this._hasMore = false;
return undefined;
});
}
}
exports.BatchedArrayCursor = BatchedArrayCursor;
/**
* The `ArrayCursor` type represents a cursor returned from a
* {@link Database.query}.
*
* When using TypeScript, cursors can be cast to a specific item type in order
* to increase type safety.
*
* See also {@link BatchedArrayCursor}.
*
* @param T - Type to use for each item. Defaults to `any`.
*
* @example
* ```ts
* const db = new Database();
* const query = aql`FOR x IN 1..5 RETURN x`;
* const result = await db.query(query) as ArrayCursor<number>;
* ```
*
* @example
* ```js
* const db = new Database();
* const query = aql`FOR x IN 1..10 RETURN x`;
* const cursor = await db.query(query);
* for await (const value of cursor) {
* // Process each value asynchronously
* await processValue(value);
* }
* ```
*/
class ArrayCursor {
constructor(batchedCursor, view) {
this._batches = batchedCursor;
this._view = view;
}
/**
* A {@link BatchedArrayCursor} providing batch-wise access to the cursor
* result set.
*
* See also {@link BatchedArrayCursor.items}.
*/
get batches() {
return this._batches;
}
/**
* Additional information about the cursor.
*/
get extra() {
return this.batches.extra;
}
/**
* Total number of documents in the query result. Only available if the
* `count` option was used.
*/
get count() {
return this.batches.count;
}
/**
* Whether the cursor has more values. If set to `false`, the cursor has
* already been depleted and contains no more items.
*/
get hasNext() {
return this.batches.hasNext;
}
/**
* Enables use with `for await` to deplete the cursor by asynchronously
* yielding every value in the cursor's remaining result set.
*
* **Note**: If the result set spans multiple batches, any remaining batches
* will only be fetched on demand. Depending on the cursor's TTL and the
* processing speed, this may result in the server discarding the cursor
* before it is fully depleted.
*
* @example
* ```js
* const cursor = await db.query(aql`
* FOR user IN users
* FILTER user.isActive
* RETURN user
* `);
* for await (const user of cursor) {
* console.log(user.email, user.isAdmin);
* }
* ```
*/
async *[Symbol.asyncIterator]() {
while (this.hasNext) {
yield this.next();
}
return undefined;
}
/**
* Depletes the cursor, then returns an array containing all values in the
* cursor's remaining result list.
*
* @example
* ```js
* const cursor = await db.query(aql`FOR x IN 1..5 RETURN x`);
* const result = await cursor.all(); // [1, 2, 3, 4, 5]
* console.log(cursor.hasNext); // false
* ```
*/
async all() {
return this.batches.flatMap((v) => v);
}
/**
* Advances the cursor and returns the next value in the cursor's remaining
* result list, or `undefined` if the cursor has been depleted.
*
* **Note**: If the result set spans multiple batches, any remaining batches
* will only be fetched on demand. Depending on the cursor's TTL and the
* processing speed, this may result in the server discarding the cursor
* before it is fully depleted.
*
* @example
* ```js
* const cursor = await db.query(aql`FOR x IN 1..3 RETURN x`);
* const one = await cursor.next(); // 1
* const two = await cursor.next(); // 2
* const three = await cursor.next(); // 3
* const empty = await cursor.next(); // undefined
* ```
*/
async next() {
while (this._view.isEmpty && this.batches.hasMore) {
await this._view.more();
}
if (this._view.isEmpty) {
return undefined;
}
return this._view.shift();
}
/**
* Advances the cursor by applying the `callback` function to each item in

@@ -247,12 +625,8 @@ * the cursor's remaining result list until the cursor is depleted or

let index = 0;
while (this._result.length || this.hasMore) {
let result;
while (this._result.length) {
result = callback(this._result.shift(), index, this);
index++;
if (result === false)
return result;
}
if (this.hasMore)
await this._more();
while (this.hasNext) {
const value = await this.next();
const result = callback(value, index, this);
index++;
if (result === false)
return result;
}

@@ -290,9 +664,6 @@ return true;

let result = [];
while (this._result.length || this.hasMore) {
while (this._result.length) {
result.push(callback(this._result.shift(), index, this));
index++;
}
if (this.hasMore)
await this._more();
while (this.hasNext) {
const value = await this.next();
result.push(callback(value, index, this));
index++;
}

@@ -342,15 +713,12 @@ return result;

let result = [];
while (this._result.length || this.hasMore) {
while (this._result.length) {
const value = callback(this._result.shift(), index, this);
if (Array.isArray(value)) {
result.push(...value);
}
else {
result.push(value);
}
index++;
while (this.hasNext) {
const value = await this.next();
const item = callback(value, index, this);
if (Array.isArray(item)) {
result.push(...item);
}
if (this.hasMore)
await this._more();
else {
result.push(item);
}
index++;
}

@@ -361,20 +729,16 @@ return result;

let index = 0;
if (!this._result.length)
if (!this.hasNext)
return initialValue;
if (initialValue === undefined) {
if (!this._result.length && !this.hasMore) {
await this._more();
}
initialValue = this._result.shift();
const value = (await this.next());
initialValue = value;
index += 1;
}
while (this._result.length || this.hasMore) {
while (this._result.length) {
initialValue = reducer(initialValue, this._result.shift(), index, this);
index++;
}
if (this.hasMore)
await this._more();
let value = initialValue;
while (this.hasNext) {
const item = await this.next();
value = reducer(value, item, index, this);
index++;
}
return initialValue;
return value;
}

@@ -401,11 +765,3 @@ /**

async kill() {
if (!this.hasMore)
return undefined;
return this._db.request({
method: "DELETE",
path: `/_api/cursor/${this._id}`,
}, () => {
this._hasMore = false;
return undefined;
});
return this.batches.kill();
}

@@ -412,0 +768,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Database = exports.isArangoDatabase = void 0;
const analyzer_1 = require("./analyzer");

@@ -10,14 +11,7 @@ const aql_1 = require("./aql");

const graph_1 = require("./graph");
const codes_1 = require("./lib/codes");
const multipart_1 = require("./lib/multipart");
const route_1 = require("./route");
const transaction_1 = require("./transaction");
const codes_1 = require("./util/codes");
const view_1 = require("./view");
function colToString(collection) {
if (collection_1.isArangoCollection(collection)) {
return String(collection.name);
}
else
return String(collection);
}
/**

@@ -33,2 +27,39 @@ * Indicates whether the given value represents a {@link Database}.

/**
* @internal
* @hidden
*/
function coerceTransactionCollections(collections) {
if (typeof collections === "string") {
return { write: [collections] };
}
if (Array.isArray(collections)) {
return { write: collections.map(collection_1.collectionToString) };
}
if (collection_1.isArangoCollection(collections)) {
return { write: collection_1.collectionToString(collections) };
}
const cols = {};
if (collections) {
if (collections.allowImplicit !== undefined) {
cols.allowImplicit = collections.allowImplicit;
}
if (collections.read) {
cols.read = Array.isArray(collections.read)
? collections.read.map(collection_1.collectionToString)
: collection_1.collectionToString(collections.read);
}
if (collections.write) {
cols.write = Array.isArray(collections.write)
? collections.write.map(collection_1.collectionToString)
: collection_1.collectionToString(collections.write);
}
if (collections.exclusive) {
cols.exclusive = Array.isArray(collections.exclusive)
? collections.exclusive.map(collection_1.collectionToString)
: collection_1.collectionToString(collections.exclusive);
}
}
return cols;
}
/**
* An object representing a single ArangoDB database. All arangojs collections,

@@ -77,3 +108,3 @@ * cursors, analyzers and so on are linked to a `Database` object.

/**
* The name of the ArangoDB database this instance represents.
* Name of the ArangoDB database this instance represents.
*/

@@ -86,2 +117,5 @@ get name() {

*
* @param details - If set to `true`, additional information about the
* ArangoDB server will be available as the `details` property.
*
* @example

@@ -97,6 +131,7 @@ * ```js

*/
version() {
version(details) {
return this.request({
method: "GET",
path: "/_api/version",
qs: { details },
}, (res) => res.body);

@@ -509,3 +544,3 @@ }

*
* @param collectionName - The current name of the collection.
* @param collectionName - Current name of the collection.
* @param newName - The new name of the collection.

@@ -671,7 +706,7 @@ */

* const db = new Database();
* const view = await db.createArangoSearchView("potatoes");
* const view = await db.createView("potatoes");
* // the ArangoSearch View "potatoes" now exists
* ```
*/
async createArangoSearchView(viewName, options) {
async createView(viewName, options) {
const view = this.view(viewName);

@@ -690,3 +725,3 @@ await view.create({ ...options, type: view_1.ViewType.ARANGOSEARCH_VIEW });

*
* @param viewName - The current name of the view.
* @param viewName - Current name of the view.
* @param newName - The new name of the view.

@@ -907,3 +942,3 @@ */

timeout,
}, (res) => new cursor_1.ArrayCursor(this, res.body, res.arangojsHostId, allowDirtyRead));
}, (res) => new cursor_1.BatchedArrayCursor(this, res.body, res.arangojsHostId, allowDirtyRead).items);
}

@@ -1545,35 +1580,2 @@ explain(query, bindVars, options) {

exports.Database = Database;
function coerceTransactionCollections(collections) {
if (typeof collections === "string") {
return { write: [collections] };
}
if (Array.isArray(collections)) {
return { write: collections.map(colToString) };
}
if (collection_1.isArangoCollection(collections)) {
return { write: colToString(collections) };
}
const cols = {};
if (collections) {
if (collections.allowImplicit !== undefined) {
cols.allowImplicit = collections.allowImplicit;
}
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;
}
//# sourceMappingURL=database.js.map

@@ -6,3 +6,3 @@ /**

*
* TODO
* The "document" module provides document/edge related types for TypeScript.
*

@@ -12,35 +12,64 @@ * @packageDocumentation

/**
* TODO
* Common ArangoDB metadata properties of a document.
*/
export declare type DocumentMetadata = {
/**
* Key of the document, which uniquely identifies the document within its
* collection.
*/
_key: string;
/**
* Unique ID of the document, which is composed of the collection name
* and the document `_key`.
*/
_id: string;
/**
* Revision of the document data.
*/
_rev: string;
};
/**
* TODO
* ArangoDB metadata defining the relations of an edge document.
*/
export declare type EdgeMetadata = {
/**
* Unique ID of the document that acts as the edge's start vertex.
*/
_from: string;
/**
* Unique ID of the document that acts as the edge's end vertex.
*/
_to: string;
};
/**
* TODO
* Type representing an object that can be stored in a collection.
*/
export declare type DocumentData<T extends object = any> = T & Partial<DocumentMetadata> & Partial<EdgeMetadata>;
/**
* TODO
* Type representing an object that can be stored in an edge collection.
*/
export declare type EdgeData<T extends object = any> = T & Partial<DocumentMetadata> & EdgeMetadata;
/**
* TODO
* Type representing a document stored in a collection.
*/
export declare type Document<T extends object = any> = T & DocumentMetadata & Partial<EdgeMetadata>;
/**
* TODO
* Type representing an edge document stored in an edge collection.
*/
export declare type Edge<T extends object = any> = T & DocumentMetadata & EdgeMetadata;
/**
* TODO
* Type representing patch data for a given object type to represent a payload
* ArangoDB can apply in a document PATCH request (i.e. a partial update).
*
* This differs from `Partial` in that it also applies itself to any nested
* objects recursively.
*/
export declare type Patch<T = object> = {
[K in keyof T]?: T[K] | Patch<T[K]>;
};
/**
* An object with an ArangoDB document `_id` property.
*
* See {@link DocumentMetadata}.
*/
export declare type ObjectWithId = {

@@ -51,3 +80,5 @@ [key: string]: any;

/**
* TODO
* An object with an ArangoDB document `_key` property.
*
* See {@link DocumentMetadata}.
*/

@@ -59,8 +90,10 @@ export declare type ObjectWithKey = {

/**
* TODO
* A value that can be used to identify a document within a collection in
* arangojs methods, i.e. a partial ArangoDB document or the value of a
* document's `_key` or `_id`.
*
* See {@link DocumentMetadata}.
*/
export declare type DocumentSelector = ObjectWithId | ObjectWithKey | string;
/**
* TODO
*
* @internal

@@ -67,0 +100,0 @@ * @hidden

@@ -7,3 +7,3 @@ "use strict";

*
* TODO
* The "document" module provides document/edge related types for TypeScript.
*

@@ -13,5 +13,4 @@ * @packageDocumentation

Object.defineProperty(exports, "__esModule", { value: true });
exports._documentHandle = void 0;
/**
* TODO
*
* @internal

@@ -18,0 +17,0 @@ * @hidden

/**
* ```ts
* import type { ArangoError } from "arangojs/error";
* import type { ArangoError, HttpError } from "arangojs/error";
* ```
*
* TODO
* The "error" module provides types and interfaces for TypeScript related
* to arangojs error handling.
*

@@ -18,7 +19,13 @@ * @packageDocumentation

/**
* TODO
* Indicates whether the given value represents an ArangoDB error response.
*
* @internal
*/
export declare function isArangoErrorResponse(body: any): boolean;
/**
* Indicates whether the given value represents a Node.js `SystemError`.
*/
export declare function isSystemError(err: any): err is SystemError;
/**
* TODO
* Interface representing a Node.js `SystemError`.
*/

@@ -31,9 +38,19 @@ export interface SystemError extends Error {

/**
* TODO
* Represents an error returned by ArangoDB.
*/
export declare class ArangoError extends ExtendableError {
name: string;
/**
* ArangoDB error code.
*
* See {@link https://www.arangodb.com/docs/stable/appendix-error-codes.html | ArangoDB error documentation}.
*/
errorNum: number;
/**
* HTTP status code included in the server error response object.
*/
code: number;
statusCode: number;
/**
* Server response object.
*/
response: any;

@@ -53,9 +70,14 @@ /**

/**
* TODO
* Represents a plain HTTP error response.
*/
export declare class HttpError extends ExtendableError {
name: string;
/**
* Server response object.
*/
response: any;
/**
* HTTP status code of the server response.
*/
code: number;
statusCode: number;
/**

@@ -62,0 +84,0 @@ * @internal

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HttpError = exports.ArangoError = exports.isSystemError = exports.isArangoErrorResponse = exports.isArangoError = void 0;
/**
* ```ts
* import type { ArangoError } from "arangojs/error";
* import type { ArangoError, HttpError } from "arangojs/error";
* ```
*
* TODO
* The "error" module provides types and interfaces for TypeScript related
* to arangojs error handling.
*

@@ -76,4 +78,17 @@ * @packageDocumentation

/**
* TODO
* Indicates whether the given value represents an ArangoDB error response.
*
* @internal
*/
function isArangoErrorResponse(body) {
return (body &&
body.hasOwnProperty("error") &&
body.hasOwnProperty("code") &&
body.hasOwnProperty("errorMessage") &&
body.hasOwnProperty("errorNum"));
}
exports.isArangoErrorResponse = isArangoErrorResponse;
/**
* Indicates whether the given value represents a Node.js `SystemError`.
*/
function isSystemError(err) {

@@ -87,3 +102,3 @@ return (Object.getPrototypeOf(err) === Error.prototype &&

/**
* TODO
* Represents an error returned by ArangoDB.
*/

@@ -99,3 +114,2 @@ class ArangoError extends error_1.ExtendableError {

this.response = response;
this.statusCode = response.statusCode;
this.message = response.body.errorMessage;

@@ -122,3 +136,3 @@ this.errorNum = response.body.errorNum;

/**
* TODO
* Represents a plain HTTP error response.
*/

@@ -134,5 +148,4 @@ class HttpError extends error_1.ExtendableError {

this.response = response;
this.statusCode = response.statusCode || 500;
this.message = messages[this.statusCode] || messages[500];
this.code = this.statusCode;
this.code = response.statusCode || 500;
this.message = messages[this.code] || messages[500];
const err = new Error(this.message);

@@ -139,0 +152,0 @@ err.name = this.name;

@@ -10,3 +10,4 @@ /**

*
* TODO
* The "graph" module provides graph related types and interfaces
* for TypeScript.
*

@@ -17,40 +18,276 @@ * @packageDocumentation

import { Database } from "./database";
import { Document, DocumentData, DocumentMetadata, DocumentSelector, Edge, EdgeData } from "./documents";
import { Patch } from "./util/types";
import { Document, DocumentData, DocumentMetadata, DocumentSelector, Edge, EdgeData, Patch } from "./documents";
/**
* TODO
* Options for retrieving a document from a graph collection.
*/
export declare type GraphCollectionReadOptions = {
/**
* If set to a document revision, the document will only be returned if its
* `_rev` property matches this value.
*
* See also {@link DocumentMetadata}.
*/
rev?: string;
/**
* If set to `true`, `null` is returned instead of an exception being thrown
* if the document does not exist.
*
* Default: `false`
*/
graceful?: boolean;
/**
* If set to `true`, the request will explicitly permit ArangoDB to return a
* potentially dirty or stale result and arangojs will load balance the
* request without distinguishing between leaders and followers.
*
* Default: `false`
*/
allowDirtyRead?: boolean;
};
/**
* TODO
* Options for inserting a document into a graph collection.
*/
export declare type GraphCollectionInsertOptions = {
/**
* If set to `true`, data will be synchronized to disk before returning.
*
* Default: `false`
*/
waitForSync?: boolean;
/**
* If set to `true`, the complete new document will be returned as the `new`
* property on the result object.
*
* Default: `false`
*/
returnNew?: boolean;
};
/**
* TODO
* Options for replacing a document in a graph collection.
*/
export declare type GraphCollectionReplaceOptions = {
/**
* If set to a document revision, the document will only be modified if its
* `_rev` property matches this value.
*
* See also {@link DocumentMetadata}.
*/
rev?: string;
/**
* If set to `true`, data will be synchronized to disk before returning.
*
* Default: `false`
*/
waitForSync?: boolean;
/**
* If set to `false`, properties with a value of `null` will be removed from
* the new document.
*
* Default: `true`
*/
keepNull?: boolean;
/**
* If set to `true`, the complete old document will be returned as the `old`
* property on the result object.
*
* Default: `false`
*/
returnOld?: boolean;
/**
* If set to `true`, the complete new document will be returned as the `new`
* property on the result object.
*
* Default: `false`
*/
returnNew?: boolean;
};
/**
* TODO
* Options for removing a document from a graph collection.
*/
export declare type GraphCollectionRemoveOptions = {
/**
* If set to a document revision, the document will only be removed if its
* `_rev` property matches this value.
*
* See also {@link DocumentMetadata}.
*/
rev?: string;
/**
* If set to `true`, data will be synchronized to disk before returning.
*
* Default: `false`
*/
waitForSync?: boolean;
/**
* If set to `true`, the complete old document will be returned as the `old`
* property on the result object.
*
* Default: `false`
*/
returnOld?: boolean;
};
/**
* TODO
* Definition of a relation in a {@link Graph}.
*/
export declare type EdgeDefinition = {
/**
* Name of the collection containing the edges.
*/
collection: string;
/**
* Array of names of collections containing the start vertices.
*/
from: string[];
/**
* Array of names of collections containing the end vertices.
*/
to: string[];
};
/**
* An edge definition used to define a collection of edges in a {@link Graph}.
*/
export declare type EdgeDefinitionOptions = {
/**
* Collection containing the edges.
*/
collection: string | ArangoCollection;
/**
* Collection or collections containing the start vertices.
*/
from: (string | ArangoCollection)[] | string | ArangoCollection;
/**
* Collection or collections containing the end vertices.
*/
to: (string | ArangoCollection)[] | string | ArangoCollection;
};
/**
* General information about a graph.
*/
export declare type GraphInfo = {
/**
* Key of the document internally representing this graph.
*
* See {@link DocumentMetadata}.
*
* @internal
*/
_key: string;
/**
* Unique identifier of the document internally representing this graph.
*
* See {@link DocumentMetadata}.
*
* @internal
*/
_id: string;
/**
* Revision of the document internally representing this graph.
*
* See {@link DocumentMetadata}.
*
* @internal
*/
_rev: string;
/**
* Name of the graph.
*/
name: string;
/**
* Definitions for the relations of the graph.
*/
edgeDefinitions: EdgeDefinition[];
/**
* Additional vertex collections. Documents within these collections do not
* have edges within this graph.
*/
orphanCollections: string[];
/**
* (Cluster only.) Number of shards that is used for every collection
* within this graph.
*/
numberOfShards?: number;
/**
* (Cluster only.) Replication factor used when initially creating
* collections for this graph.
*/
replicationFactor?: number;
/**
* (Cluster only.) Write concern for new collections in the graph.
*/
writeConcern?: number;
/**
* (Cluster only.) Write concern for new collections in the graph.
*
* @deprecated Renamed to `writeConcern` in ArangoDB 3.6.
*/
minReplicationFactor?: number;
/**
* (Enterprise Edition cluster only.) If set to `true`, the graph has been
* created as a SmartGraph.
*/
isSmart?: boolean;
/**
* (Enterprise Edition cluster only.) Attribute containing the shard key
* value to use for smart sharding.
*/
smartGraphAttribute?: string;
};
/**
* Option for creating a graph.
*/
export declare type GraphCreateOptions = {
/**
* If set to `true`, the request will wait until all modifications have been
* synchronized to disk before returning successfully.
*
* Default: `false`
*/
waitForSync?: boolean;
/**
* Additional vertex collections. Documents within these collections do not
* have edges within this graph.
*/
orphanCollections?: (string | ArangoCollection)[] | string | ArangoCollection;
/**
* (Cluster only.) Number of shards that is used for every collection
* within this graph.
*/
numberOfShards?: number;
/**
* (Cluster only.) Replication factor used when initially creating
* collections for this graph.
*
* Default: `1`
*/
replicationFactor?: number | "satellite";
/**
* (Cluster only.) Write concern for new collections in the graph.
*/
writeConcern?: number;
/**
* (Cluster only.) Write concern for new collections in the graph.
*
* @deprecated Renamed to `writeConcern` in ArangoDB 3.6.
*/
minReplicationFactor?: number;
/**
* (Enterprise Edition cluster only.) If set to `true`, the graph will be
* created as a SmartGraph.
*
* Default: `false`
*/
isSmart?: boolean;
/**
* (Enterprise Edition cluster only.) Attribute containing the shard key
* value to use for smart sharding.
*
* **Note**: `isSmart` must be set to `true`.
*/
smartGraphAttribute?: string;
};
/**
* Represents a {@link Collection} of vertices in a {@link Graph}.
*
* @param T - Type to use for document data. Defaults to `any`.
*/
export declare class GraphVertexCollection<T extends object = any> implements ArangoCollection {

@@ -73,33 +310,148 @@ protected _db: Database;

/**
* TODO
* Name of the collection.
*/
get name(): string;
/**
* TODO
* A {@link DocumentCollection} instance for this vertex collection.
*/
get collection(): DocumentCollection<T>;
/**
* TODO
* The {@link Graph} instance this vertex collection is bound to.
*/
get graph(): Graph;
/**
* TODO
* Checks whether a vertex matching the given key or id exists in this
* collection.
*
* Throws an exception when passed a vertex or `_id` from a different
* collection.
*
* @param selector - Document `_key`, `_id` or object with either of those
* properties (e.g. a vertex from this collection).
*
* @example
* ```js
* const graph = db.graph("some-graph");
* const collection = graph.vertexCollection("vertices");
* const exists = await collection.vertexExists("abc123");
* if (!exists) {
* console.log("Vertex does not exist");
* }
* ```
*/
vertexExists(selector: DocumentSelector): Promise<boolean>;
/**
* TODO
* Retrieves the vertex matching the given key or id.
*
* Throws an exception when passed a vertex or `_id` from a different
* collection.
*
* @param selector - Document `_key`, `_id` or object with either of those
* properties (e.g. a vertex from this collection).
* @param options - Options for retrieving the vertex.
*
* @example
* ```js
* const graph = db.graph("some-graph");
* const collection = graph.vertexCollection("vertices");
* try {
* const vertex = await collection.vertex("abc123");
* console.log(vertex);
* } catch (e) {
* console.error("Could not find vertex");
* }
* ```
*
* @example
* ```js
* const graph = db.graph("some-graph");
* const collection = graph.vertexCollection("vertices");
* const vertex = await collection.vertex("abc123", { graceful: true });
* if (vertex) {
* console.log(vertex);
* } else {
* console.error("Could not find vertex");
* }
* ```
*/
vertex(selector: DocumentSelector, options?: GraphCollectionReadOptions): Promise<Document<T>>;
/**
* TODO
* Retrieves the vertex matching the given key or id.
*
* Throws an exception when passed a vertex or `_id` from a different
* collection.
*
* @param selector - Document `_key`, `_id` or object with either of those
* properties (e.g. a vertex from this collection).
* @param graceful - If set to `true`, `null` is returned instead of an
* exception being thrown if the vertex does not exist.
*
* @example
* ```js
* const graph = db.graph("some-graph");
* const collection = graph.vertexCollection("vertices");
* try {
* const vertex = await collection.vertex("abc123", false);
* console.log(vertex);
* } catch (e) {
* console.error("Could not find vertex");
* }
* ```
*
* @example
* ```js
* const graph = db.graph("some-graph");
* const collection = graph.vertexCollection("vertices");
* const vertex = await collection.vertex("abc123", true);
* if (vertex) {
* console.log(vertex);
* } else {
* console.error("Could not find vertex");
* }
* ```
*/
vertex(selector: DocumentSelector, graceful: boolean): Promise<Document<T>>;
/**
* TODO
* Inserts a new vertex with the given `data` into the collection.
*
* @param data - The contents of the new vertex.
* @param options - Options for inserting the vertex.
*
* @example
* ```js
* const graph = db.graph("some-graph");
* const collection = graph.vertexCollection("friends");
* const result = await collection.save(
* { _key: "a", color: "blue", count: 1 },
* { returnNew: true }
* );
* console.log(result.new.color, result.new.count); // "blue" 1
* ```
*/
save(data: EdgeData<T>, options?: GraphCollectionInsertOptions): Promise<DocumentMetadata & {
save(data: DocumentData<T>, options?: GraphCollectionInsertOptions): Promise<DocumentMetadata & {
new?: Document<T>;
}>;
/**
* TODO
* Replaces an existing vertex in the collection.
*
* Throws an exception when passed a vertex or `_id` from a different
* collection.
*
* @param selector - Document `_key`, `_id` or object with either of those
* properties (e.g. a vertex from this collection).
* @param newData - The contents of the new vertex.
* @param options - Options for replacing the vertex.
*
* @example
* ```js
* const graph = db.graph("some-graph");
* const collection = graph.collection("vertices");
* await collection.save({ _key: "a", color: "blue", count: 1 });
* const result = await collection.replace(
* "a",
* { color: "red" },
* { returnNew: true }
* );
* console.log(result.new.color, result.new.count); // "red" undefined
* ```
*/

@@ -111,3 +463,24 @@ replace(selector: DocumentSelector, newValue: DocumentData<T>, options?: GraphCollectionReplaceOptions): Promise<DocumentMetadata & {

/**
* TODO
* Updates an existing vertex in the collection.
*
* Throws an exception when passed a vertex or `_id` from a different
* collection.
*
* @param selector - Document `_key`, `_id` or object with either of those
* properties (e.g. a vertex from this collection).
* @param newData - The data for updating the vertex.
* @param options - Options for updating the vertex.
*
* @example
* ```js
* const graph = db.graph("some-graph");
* const collection = graph.collection("vertices");
* await collection.save({ _key: "a", color: "blue", count: 1 });
* const result = await collection.update(
* "a",
* { count: 2 },
* { returnNew: true }
* );
* console.log(result.new.color, result.new.count); // "blue" 2
* ```
*/

@@ -119,3 +492,27 @@ update(selector: DocumentSelector, newValue: Patch<DocumentData<T>>, options?: GraphCollectionReplaceOptions): Promise<DocumentMetadata & {

/**
* TODO
* Removes an existing vertex from the collection.
*
* Throws an exception when passed a vertex or `_id` from a different
* collection.
*
* @param selector - Document `_key`, `_id` or object with either of those
* properties (e.g. a vertex from this collection).
* @param options - Options for removing the vertex.
*
* @example
* ```js
* const graph = db.graph("some-graph");
* const collection = graph.vertexCollection("vertices");
* await collection.remove("abc123");
* // document with key "abc123" deleted
* ```
*
* @example
* ```js
* const graph = db.graph("some-graph");
* const collection = graph.vertexCollection("vertices");
* const doc = await collection.vertex("abc123");
* await collection.remove(doc);
* // document with key "abc123" deleted
* ```
*/

@@ -127,3 +524,5 @@ remove(selector: DocumentSelector, options?: GraphCollectionRemoveOptions): Promise<DocumentMetadata & {

/**
* TODO
* Represents a {@link Collection} of edges in a {@link Graph}.
*
* @param T - Type to use for document data. Defaults to `any`.
*/

@@ -147,27 +546,120 @@ export declare class GraphEdgeCollection<T extends object = any> implements ArangoCollection {

/**
* TODO
* Name of the collection.
*/
get name(): string;
/**
* TODO
* A {@link EdgeCollection} instance for this edge collection.
*/
get collection(): EdgeCollection<T>;
/**
* TODO
* The {@link Graph} instance this edge collection is bound to.
*/
get graph(): Graph;
/**
* TODO
* Checks whether a edge matching the given key or id exists in this
* collection.
*
* Throws an exception when passed a edge or `_id` from a different
* collection.
*
* @param selector - Document `_key`, `_id` or object with either of those
* properties (e.g. a edge from this collection).
*
* @example
* ```js
* const graph = db.graph("some-graph");
* const collection = graph.edgeCollection("friends")
* const exists = await collection.edgeExists("abc123");
* if (!exists) {
* console.log("Edge does not exist");
* }
* ```
*/
edgeExists(selector: DocumentSelector): Promise<boolean>;
/**
* TODO
* Retrieves the edge matching the given key or id.
*
* Throws an exception when passed a edge or `_id` from a different
* collection, or if the edge does not exist.
*
* @param selector - Document `_key`, `_id` or object with either of those
* properties (e.g. a edge from this collection).
* @param options - Options for retrieving the edge.
*
* @example
* ```js
* const graph = db.graph("some-graph");
* const collection = graph.edgeCollection("friends")
* try {
* const edge = await collection.edge("abc123");
* console.log(edge);
* } catch (e) {
* console.error("Could not find edge");
* }
* ```
*
* @example
* ```js
* const graph = db.graph("some-graph");
* const collection = graph.edgeCollection("friends")
* const edge = await collection.edge("abc123", { graceful: true });
* if (edge) {
* console.log(edge);
* } else {
* console.error("Edge does not exist");
* }
* ```
*/
edge(selector: DocumentSelector, options?: GraphCollectionReadOptions): Promise<Edge<T>>;
/**
* TODO
* Retrieves the edge matching the given key or id.
*
* Throws an exception when passed a edge or `_id` from a different
* collection, or if the edge does not exist.
*
* @param selector - Document `_key`, `_id` or object with either of those
* properties (e.g. a edge from this collection).
* @param graceful - If set to `true`, `null` is returned instead of an
* exception being thrown if the edge does not exist.
*
* @example
* ```js
* const graph = db.graph("some-graph");
* const collection = graph.edgeCollection("friends")
* try {
* const edge = await collection.edge("abc123", false);
* console.log(edge);
* } catch (e) {
* console.error("Could not find edge");
* }
* ```
*
* @example
* ```js
* const graph = db.graph("some-graph");
* const collection = graph.edgeCollection("friends")
* const edge = await collection.edge("abc123", true);
* if (edge) {
* console.log(edge);
* } else {
* console.error("Edge does not exist");
* }
* ```
*/
edge(selector: DocumentSelector, graceful: boolean): Promise<Edge<T>>;
/**
* TODO
* Inserts a new edge with the given `data` into the collection.
*
* @param data - The contents of the new edge.
* @param options - Options for inserting the edge.
*
* @example
* ```js
* const db = new Database();
* const collection = db.collection("friends");
* const result = await collection.save(
* { _from: "users/rana", _to: "users/mudasir", active: false },
* { returnNew: true }
* );
* ```
*/

@@ -178,3 +670,32 @@ save(data: EdgeData<T>, options?: GraphCollectionInsertOptions): Promise<DocumentMetadata & {

/**
* TODO
* Replaces an existing edge in the collection.
*
* Throws an exception when passed a edge or `_id` from a different
* collection.
*
* @param selector - Document `_key`, `_id` or object with either of those
* properties (e.g. a edge from this collection).
* @param newData - The contents of the new edge.
* @param options - Options for replacing the edge.
*
* @example
* ```js
* const db = new Database();
* const collection = db.collection("friends");
* await collection.save(
* {
* _key: "musadir",
* _from: "users/rana",
* _to: "users/mudasir",
* active: true,
* best: true
* }
* );
* const result = await collection.replace(
* "musadir",
* { active: false },
* { returnNew: true }
* );
* console.log(result.new.active, result.new.best); // false undefined
* ```
*/

@@ -186,3 +707,32 @@ replace(selector: DocumentSelector, newValue: EdgeData<T>, options?: GraphCollectionReplaceOptions): Promise<DocumentMetadata & {

/**
* TODO
* Updates an existing edge in the collection.
*
* Throws an exception when passed a edge or `_id` from a different
* collection.
*
* @param selector - Document `_key`, `_id` or object with either of those
* properties (e.g. a edge from this collection).
* @param newData - The data for updating the edge.
* @param options - Options for updating the edge.
*
* @example
* ```js
* const db = new Database();
* const collection = db.collection("friends");
* await collection.save(
* {
* _key: "musadir",
* _from: "users/rana",
* _to: "users/mudasir",
* active: true,
* best: true
* }
* );
* const result = await collection.update(
* "musadir",
* { active: false },
* { returnNew: true }
* );
* console.log(result.new.active, result.new.best); // false true
* ```
*/

@@ -194,3 +744,19 @@ update(selector: DocumentSelector, newValue: Patch<EdgeData<T>>, options?: GraphCollectionReplaceOptions): Promise<DocumentMetadata & {

/**
* TODO
* Removes an existing edge from the collection.
*
* Throws an exception when passed a edge or `_id` from a different
* collection.
*
* @param selector - Document `_key`, `_id` or object with either of those
* properties (e.g. a edge from this collection).
* @param options - Options for removing the edge.
*
* @example
* ```js
* const db = new Database();
* const collection = db.collection("friends");
* const doc = await collection.edge("musadir");
* await collection.remove(doc);
* // edge with key "musadir" deleted
* ```
*/

@@ -202,96 +768,4 @@ remove(selector: DocumentSelector, options?: GraphCollectionRemoveOptions): Promise<DocumentMetadata & {

/**
* An edge definition used to define a collection of edges in a {@link Graph}.
* Represents a graph in a {@link Database}.
*/
export declare type EdgeDefinition = {
/**
* Name of the collection containing the edges.
*/
collection: string;
/**
* Array of names of collections containing the start vertices.
*/
from: string[];
/**
* Array of names of collections containing the end vertices.
*/
to: string[];
};
/**
* TODO
*/
export declare type GraphInfo = {
_id: string;
_key: string;
_rev: string;
name: string;
edgeDefinitions: EdgeDefinition[];
orphanCollections: string[];
numberOfShards?: number;
replicationFactor?: number;
writeConcern?: number;
/**
* @deprecated Renamed to `writeConcern` in ArangoDB 3.6.
*/
minReplicationFactor?: number;
/** Enterprise Edition only */
isSatellite?: boolean;
/** Enterprise Edition only */
isSmart?: boolean;
/** Enterprise Edition only */
smartGraphAttribute?: string;
};
/**
* TODO
*/
export declare type GraphCreateOptions = {
/**
* If set to `true`, the request will wait until everything is synced to
* disk before returning successfully.
*/
waitForSync?: boolean;
/**
* An array of additional vertex collections. Documents within these
* collections do not have edges within this graph.
*/
orphanCollections?: string[];
/**
* (Cluster only.) The number of shards that is used for every collection
* within this graph.
*/
numberOfShards?: number;
/**
* (Cluster only.) The replication factor used when initially creating
* collections for this graph.
*
* Default: `1`
*/
replicationFactor?: number | "satellite";
/**
* (Cluster only.) Write concern for new collections in the graph.
*/
writeConcern?: number;
/**
* (Cluster only.) Write concern for new collections in the graph.
*
* @deprecated Renamed to `writeConcern` in ArangoDB 3.6.
*/
minReplicationFactor?: number;
/**
* (Enterprise Edition cluster only.) If set to `true`, the graph will be
* created as a SmartGraph.
*
* Default: `false`
*/
isSmart?: boolean;
/**
* (Enterprise Edition cluster only.) Attribute containing the shard key
* value to use for smart sharding.
*
* **Note**: `isSmart` must be set to `true`.
*/
smartGraphAttribute?: string;
};
/**
* TODO
*/
export declare class Graph {

@@ -306,69 +780,153 @@ protected _name: string;

/**
* TODO
* Name of the graph.
*/
get name(): string;
/**
* TODO
* Checks whether the graph exists.
*
* @example
* ```js
* const db = new Database();
* const graph = db.graph("some-graph");
* const result = await graph.exists();
* // result indicates whether the graph exists
* ```
*/
get(): Promise<GraphInfo>;
exists(): Promise<boolean>;
/**
* TODO
* Retrieves general information about the graph.
*
* @example
* ```js
* const db = new Database();
* const graph = db.graph("some-graph");
* const data = await graph.get();
* // data contains general information about the graph
* ```
*/
exists(): Promise<boolean>;
get(): Promise<GraphInfo>;
/**
* TODO
* Creates a graph with the given `edgeDefinitions` and `options` for this
* graph's name.
*
* @param edgeDefinitions - Definitions for the relations of the graph.
* @param options - Options for creating the graph.
*
* @example
* ```js
* const db = new Database();
* const graph = db.graph("some-graph");
* const info = await graph.create([
* {
* collection: "edges",
* from: ["start-vertices"],
* to: ["end-vertices"],
* },
* ]);
* // graph now exists
* ```
*/
create(edgeDefinitions: EdgeDefinition[], options?: GraphCreateOptions): Promise<GraphInfo>;
create(edgeDefinitions: EdgeDefinitionOptions[], options?: GraphCreateOptions): Promise<GraphInfo>;
/**
* TODO
* Deletes the graph from the database.
*
* @param dropCollections - If set to `true`, the collections associated with
* the graph will also be deleted.
*
* @example
* ```js
* const db = new Database();
* const graph = db.graph("some-graph");
* await graph.drop();
* // the graph "some-graph" no longer exists
* ```
*/
drop(dropCollections?: boolean): Promise<boolean>;
/**
* TODO
* Returns a {@link GraphVertexCollection} instance for the given collection
* name representing the collection in this graph.
*
* @param T - Type to use for document data. Defaults to `any`.
* @param collection - Name of the vertex collection.
*/
vertexCollection<T extends object = any>(collectionName: string): GraphVertexCollection<T>;
vertexCollection<T extends object = any>(collection: string | ArangoCollection): GraphVertexCollection<T>;
/**
* TODO
* Fetches all vertex collections of this graph from the database and returns
* an array of their names.
*
* See also {@link Graph.vertexCollections}.
*/
listVertexCollections(): Promise<string[]>;
/**
* TODO
* Fetches all vertex collections of this graph from the database and returns
* an array of {@link GraphVertexCollection} instances.
*
* See also {@link Graph.listVertexCollections}.
*/
vertexCollections(): Promise<GraphVertexCollection[]>;
/**
* TODO
* Adds the given collection to this graph as a vertex collection.
*
* @param collection - Collection to add to the graph.
*/
addVertexCollection(collection: string | ArangoCollection): Promise<GraphInfo>;
/**
* TODO
* Removes the given collection from this graph as a vertex collection.
*
* @param collection - Collection to remove from the graph.
* @param dropCollection - If set to `true`, the collection will also be
* deleted from the database.
*/
removeVertexCollection(collection: string | ArangoCollection, dropCollection?: boolean): Promise<GraphInfo>;
/**
* TODO
* Returns a {@link GraphEdgeCollection} instance for the given collection
* name representing the collection in this graph.
*
* @param T - Type to use for document data. Defaults to `any`.
* @param collection - Name of the edge collection.
*/
edgeCollection<T extends object = any>(collectionName: string): GraphEdgeCollection<T>;
edgeCollection<T extends object = any>(collection: string | ArangoCollection): GraphEdgeCollection<T>;
/**
* TODO
* Fetches all edge collections of this graph from the database and returns
* an array of their names.
*
* See also {@link Graph.edgeCollections}.
*/
listEdgeCollections(): Promise<string[]>;
/**
* TODO
* Fetches all edge collections of this graph from the database and returns
* an array of {@link GraphEdgeCollection} instances.
*
* See also {@link Graph.listEdgeCollections}.
*/
edgeCollections(): Promise<GraphEdgeCollection[]>;
/**
* TODO
* Adds an edge definition to this graph.
*
* @param edgeDefinition - Definition of a relation in this graph.
*/
addEdgeDefinition(definition: EdgeDefinition): Promise<GraphInfo>;
addEdgeDefinition(edgeDefinition: EdgeDefinitionOptions): Promise<GraphInfo>;
/**
* TODO
* Replaces an edge definition in this graph. The existing edge definition
* for the given edge collection will be overwritten.
*
* @param edgeDefinition - Definition of a relation in this graph.
*/
replaceEdgeDefinition(definition: EdgeDefinition): Promise<GraphInfo>;
replaceEdgeDefinition(edgeDefinition: EdgeDefinitionOptions): Promise<GraphInfo>;
/**
* TODO
* Replaces an edge definition in this graph. The existing edge definition
* for the given edge collection will be overwritten.
*
* @param collection - Edge collection for which to replace the definition.
* @param edgeDefinition - Definition of a relation in this graph.
*/
replaceEdgeDefinition(edgeCollection: string, definition: EdgeDefinition): Promise<GraphInfo>;
replaceEdgeDefinition(collection: string | ArangoCollection, edgeDefinition: EdgeDefinitionOptions): Promise<GraphInfo>;
/**
* TODO
* Removes the edge definition for the given edge collection from this graph.
*
* @param collection - Edge collection for which to remove the definition.
* @param dropCollection - If set to `true`, the collection will also be
* deleted from the database.
*/
removeEdgeDefinition(edgeCollection: string, dropCollection?: boolean): Promise<GraphInfo>;
removeEdgeDefinition(collection: string | ArangoCollection, dropCollection?: boolean): Promise<GraphInfo>;
/**

@@ -403,2 +961,3 @@ * Performs a traversal starting from the given `startVertex` and following

* console.log(result.vertices); // ["a", "b", "c", "d"]
* ```
*/

@@ -405,0 +964,0 @@ traversal(startVertex: string, options?: TraversalOptions): Promise<any>;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Graph = exports.GraphEdgeCollection = exports.GraphVertexCollection = void 0;
/**

@@ -12,3 +13,4 @@ * ```ts

*
* TODO
* The "graph" module provides graph related types and interfaces
* for TypeScript.
*

@@ -20,3 +22,7 @@ * @packageDocumentation

const error_1 = require("./error");
const codes_1 = require("./util/codes");
const codes_1 = require("./lib/codes");
/**
* @internal
* @hidden
*/
function mungeGharialResponse(body, prop) {

@@ -32,4 +38,21 @@ const { new: newDoc, old: oldDoc, [prop]: doc, ...meta } = body;

/**
* TODO
* @internal
* @hidden
*/
function coerceEdgeDefinition(options) {
const edgeDefinition = {};
edgeDefinition.collection = collection_1.collectionToString(options.collection);
edgeDefinition.from = Array.isArray(options.from)
? options.from.map(collection_1.collectionToString)
: [collection_1.collectionToString(options.from)];
edgeDefinition.to = Array.isArray(options.to)
? options.to.map(collection_1.collectionToString)
: [collection_1.collectionToString(options.to)];
return edgeDefinition;
}
/**
* Represents a {@link Collection} of vertices in a {@link Graph}.
*
* @param T - Type to use for document data. Defaults to `any`.
*/
class GraphVertexCollection {

@@ -55,3 +78,3 @@ /**

/**
* TODO
* Name of the collection.
*/

@@ -62,3 +85,3 @@ get name() {

/**
* TODO
* A {@link DocumentCollection} instance for this vertex collection.
*/

@@ -69,3 +92,3 @@ get collection() {

/**
* TODO
* The {@link Graph} instance this vertex collection is bound to.
*/

@@ -76,3 +99,20 @@ get graph() {

/**
* TODO
* Checks whether a vertex matching the given key or id exists in this
* collection.
*
* Throws an exception when passed a vertex or `_id` from a different
* collection.
*
* @param selector - Document `_key`, `_id` or object with either of those
* properties (e.g. a vertex from this collection).
*
* @example
* ```js
* const graph = db.graph("some-graph");
* const collection = graph.vertexCollection("vertices");
* const exists = await collection.vertexExists("abc123");
* if (!exists) {
* console.log("Vertex does not exist");
* }
* ```
*/

@@ -87,3 +127,3 @@ async vertexExists(selector) {

catch (err) {
if (err.statusCode === 404) {
if (err.code === 404) {
return false;

@@ -178,3 +218,5 @@ }

/**
* TODO
* Represents a {@link Collection} of edges in a {@link Graph}.
*
* @param T - Type to use for document data. Defaults to `any`.
*/

@@ -201,3 +243,3 @@ class GraphEdgeCollection {

/**
* TODO
* Name of the collection.
*/

@@ -208,3 +250,3 @@ get name() {

/**
* TODO
* A {@link EdgeCollection} instance for this edge collection.
*/

@@ -215,3 +257,3 @@ get collection() {

/**
* TODO
* The {@link Graph} instance this edge collection is bound to.
*/

@@ -222,3 +264,20 @@ get graph() {

/**
* TODO
* Checks whether a edge matching the given key or id exists in this
* collection.
*
* Throws an exception when passed a edge or `_id` from a different
* collection.
*
* @param selector - Document `_key`, `_id` or object with either of those
* properties (e.g. a edge from this collection).
*
* @example
* ```js
* const graph = db.graph("some-graph");
* const collection = graph.edgeCollection("friends")
* const exists = await collection.edgeExists("abc123");
* if (!exists) {
* console.log("Edge does not exist");
* }
* ```
*/

@@ -233,3 +292,3 @@ async edgeExists(selector) {

catch (err) {
if (err.statusCode === 404) {
if (err.code === 404) {
return false;

@@ -323,3 +382,3 @@ }

/**
* TODO
* Represents a graph in a {@link Database}.
*/

@@ -336,3 +395,3 @@ class Graph {

/**
* TODO
* Name of the graph.
*/

@@ -343,10 +402,12 @@ get name() {

/**
* TODO
* Checks whether the graph exists.
*
* @example
* ```js
* const db = new Database();
* const graph = db.graph("some-graph");
* const result = await graph.exists();
* // result indicates whether the graph exists
* ```
*/
get() {
return this._db.request({ path: `/_api/gharial/${this._name}` }, (res) => res.body.graph);
}
/**
* TODO
*/
async exists() {

@@ -365,4 +426,36 @@ try {

/**
* TODO
* Retrieves general information about the graph.
*
* @example
* ```js
* const db = new Database();
* const graph = db.graph("some-graph");
* const data = await graph.get();
* // data contains general information about the graph
* ```
*/
get() {
return this._db.request({ path: `/_api/gharial/${this._name}` }, (res) => res.body.graph);
}
/**
* Creates a graph with the given `edgeDefinitions` and `options` for this
* graph's name.
*
* @param edgeDefinitions - Definitions for the relations of the graph.
* @param options - Options for creating the graph.
*
* @example
* ```js
* const db = new Database();
* const graph = db.graph("some-graph");
* const info = await graph.create([
* {
* collection: "edges",
* from: ["start-vertices"],
* to: ["end-vertices"],
* },
* ]);
* // graph now exists
* ```
*/
create(edgeDefinitions, options) {

@@ -374,4 +467,7 @@ const { orphanCollections, waitForSync, isSmart, ...opts } = options || {};

body: {
orphanCollections,
edgeDefinitions,
orphanCollections: orphanCollections &&
(Array.isArray(orphanCollections)
? orphanCollections.map(collection_1.collectionToString)
: [collection_1.collectionToString(orphanCollections)]),
edgeDefinitions: edgeDefinitions.map(coerceEdgeDefinition),
isSmart,

@@ -385,3 +481,14 @@ name: this._name,

/**
* TODO
* Deletes the graph from the database.
*
* @param dropCollections - If set to `true`, the collections associated with
* the graph will also be deleted.
*
* @example
* ```js
* const db = new Database();
* const graph = db.graph("some-graph");
* await graph.drop();
* // the graph "some-graph" no longer exists
* ```
*/

@@ -396,9 +503,19 @@ drop(dropCollections = false) {

/**
* TODO
* Returns a {@link GraphVertexCollection} instance for the given collection
* name representing the collection in this graph.
*
* @param T - Type to use for document data. Defaults to `any`.
* @param collection - Name of the vertex collection.
*/
vertexCollection(collectionName) {
return new GraphVertexCollection(this._db, collectionName, this);
vertexCollection(collection) {
if (collection_1.isArangoCollection(collection)) {
collection = collection.name;
}
return new GraphVertexCollection(this._db, collection, this);
}
/**
* TODO
* Fetches all vertex collections of this graph from the database and returns
* an array of their names.
*
* See also {@link Graph.vertexCollections}.
*/

@@ -409,3 +526,6 @@ listVertexCollections() {

/**
* TODO
* Fetches all vertex collections of this graph from the database and returns
* an array of {@link GraphVertexCollection} instances.
*
* See also {@link Graph.listVertexCollections}.
*/

@@ -417,3 +537,5 @@ async vertexCollections() {

/**
* TODO
* Adds the given collection to this graph as a vertex collection.
*
* @param collection - Collection to add to the graph.
*/

@@ -431,3 +553,7 @@ addVertexCollection(collection) {

/**
* TODO
* Removes the given collection from this graph as a vertex collection.
*
* @param collection - Collection to remove from the graph.
* @param dropCollection - If set to `true`, the collection will also be
* deleted from the database.
*/

@@ -447,9 +573,19 @@ removeVertexCollection(collection, dropCollection = false) {

/**
* TODO
* Returns a {@link GraphEdgeCollection} instance for the given collection
* name representing the collection in this graph.
*
* @param T - Type to use for document data. Defaults to `any`.
* @param collection - Name of the edge collection.
*/
edgeCollection(collectionName) {
return new GraphEdgeCollection(this._db, collectionName, this);
edgeCollection(collection) {
if (collection_1.isArangoCollection(collection)) {
collection = collection.name;
}
return new GraphEdgeCollection(this._db, collection, this);
}
/**
* TODO
* Fetches all edge collections of this graph from the database and returns
* an array of their names.
*
* See also {@link Graph.edgeCollections}.
*/

@@ -460,3 +596,6 @@ listEdgeCollections() {

/**
* TODO
* Fetches all edge collections of this graph from the database and returns
* an array of {@link GraphEdgeCollection} instances.
*
* See also {@link Graph.listEdgeCollections}.
*/

@@ -468,29 +607,41 @@ async edgeCollections() {

/**
* TODO
* Adds an edge definition to this graph.
*
* @param edgeDefinition - Definition of a relation in this graph.
*/
addEdgeDefinition(definition) {
addEdgeDefinition(edgeDefinition) {
return this._db.request({
method: "POST",
path: `/_api/gharial/${this._name}/edge`,
body: definition,
body: coerceEdgeDefinition(edgeDefinition),
}, (res) => res.body.graph);
}
replaceEdgeDefinition(edgeCollection, definition) {
if (!definition) {
definition = edgeCollection;
edgeCollection = definition.collection;
replaceEdgeDefinition(collection, edgeDefinition) {
if (!edgeDefinition) {
edgeDefinition = collection;
collection = edgeDefinition.collection;
}
if (collection_1.isArangoCollection(collection)) {
collection = collection.name;
}
return this._db.request({
method: "PUT",
path: `/_api/gharial/${this._name}/edge/${edgeCollection}`,
body: definition,
path: `/_api/gharial/${this._name}/edge/${collection}`,
body: coerceEdgeDefinition(edgeDefinition),
}, (res) => res.body.graph);
}
/**
* TODO
* Removes the edge definition for the given edge collection from this graph.
*
* @param collection - Edge collection for which to remove the definition.
* @param dropCollection - If set to `true`, the collection will also be
* deleted from the database.
*/
removeEdgeDefinition(edgeCollection, dropCollection = false) {
removeEdgeDefinition(collection, dropCollection = false) {
if (collection_1.isArangoCollection(collection)) {
collection = collection.name;
}
return this._db.request({
method: "DELETE",
path: `/_api/gharial/${this._name}/edge/${edgeCollection}`,
path: `/_api/gharial/${this._name}/edge/${collection}`,
qs: {

@@ -530,2 +681,3 @@ dropCollection,

* console.log(result.vertices); // ["a", "b", "c", "d"]
* ```
*/

@@ -532,0 +684,0 @@ traversal(startVertex, options) {

@@ -0,1 +1,15 @@

/**
* ```js
* import arangojs, { aql, Database } from "arangojs";
* ```
*
* The "index" module is the default entry point when importing the arangojs
* module or using the web build in the browser.
*
* If you are just getting started, you probably want to use the
* {@link arangojs} function, which is also the default export of this module,
* or the {@link Database} class for which it is a wrapper.
*
* @packageDocumentation
*/
import { Config } from "./connection";

@@ -10,12 +24,3 @@ import { Database } from "./database";

*/
declare function arangojs(config?: Config): Database;
declare namespace arangojs {
var ArangoError: typeof import("./error").ArangoError;
var CollectionStatus: typeof import("./collection").CollectionStatus;
var CollectionType: typeof import("./collection").CollectionType;
var ViewType: typeof import("./view").ViewType;
var Database: typeof import("./database").Database;
var aql: typeof import("./aql").aql;
}
export default arangojs;
export declare function arangojs(config?: Config): Database;
/**

@@ -29,11 +34,3 @@ * Creates a new `Database` instance with its own connection pool.

*/
declare function arangojs(url: string | string[]): Database;
declare namespace arangojs {
var ArangoError: typeof import("./error").ArangoError;
var CollectionStatus: typeof import("./collection").CollectionStatus;
var CollectionType: typeof import("./collection").CollectionType;
var ViewType: typeof import("./view").ViewType;
var Database: typeof import("./database").Database;
var aql: typeof import("./aql").aql;
}
export declare function arangojs(url: string | string[]): Database;
export default arangojs;

@@ -43,4 +40,3 @@ export { aql } from "./aql";

export { Database } from "./database";
export { ArangoError } from "./error";
export { ViewType } from "./view";
//# sourceMappingURL=index.d.ts.map
"use strict";
const { aql } = require("./aql");
const { CollectionStatus, CollectionType } = require("./collection");
const { Database } = require("./database");
const { ArangoError } = require("./error");
const { ViewType } = require("./view");
module.exports = function arangojs(config) {
return new Database(config);
};
module.exports.default = module.exports;
module.exports.ArangoError = ArangoError;
module.exports.CollectionStatus = CollectionStatus;
module.exports.CollectionType = CollectionType;
module.exports.ViewType = ViewType;
module.exports.Database = Database;
module.exports.aql = aql;
Object.defineProperty(module.exports, "__esModule", { value: true });
Object.defineProperty(exports, "__esModule", { value: true });
exports.arangojs = void 0;
const database_1 = require("./database");
module.exports = exports = arangojs;
function arangojs(config) {
if (typeof config === "string" || Array.isArray(config)) {
const url = config;
return new database_1.Database(url);
}
return new database_1.Database(config);
}
exports.arangojs = arangojs;
exports.default = arangojs;
var aql_1 = require("./aql");
Object.defineProperty(exports, "aql", { enumerable: true, get: function () { return aql_1.aql; } });
var collection_1 = require("./collection");
Object.defineProperty(exports, "CollectionStatus", { enumerable: true, get: function () { return collection_1.CollectionStatus; } });
Object.defineProperty(exports, "CollectionType", { enumerable: true, get: function () { return collection_1.CollectionType; } });
var database_2 = require("./database");
Object.defineProperty(exports, "Database", { enumerable: true, get: function () { return database_2.Database; } });
var view_1 = require("./view");
Object.defineProperty(exports, "ViewType", { enumerable: true, get: function () { return view_1.ViewType; } });
//# sourceMappingURL=index.js.map

@@ -25,2 +25,5 @@ /**

export declare type EnsureHashIndexOptions = {
/**
* Type of this index.
*/
type: "hash";

@@ -63,2 +66,5 @@ /**

export declare type EnsureSkiplistIndexOptions = {
/**
* Type of this index.
*/
type: "skiplist";

@@ -98,2 +104,5 @@ /**

export declare type EnsurePersistentIndexOptions = {
/**
* Type of this index.
*/
type: "persistent";

@@ -172,2 +181,5 @@ /**

export declare type EnsureFulltextIndexOptions = {
/**
* Type of this index.
*/
type: "fulltext";

@@ -183,3 +195,3 @@ /**

/**
* The minimum character length of words to index.
* Minimum character length of words to index.
*/

@@ -192,2 +204,5 @@ minLength?: number;

export declare type EnsureTtlIndexOptions = {
/**
* Type of this index.
*/
type: "ttl";

@@ -194,0 +209,0 @@ /**

@@ -20,2 +20,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports._indexHandle = void 0;
/**

@@ -22,0 +23,0 @@ * @internal

/**
* TODO
* Blob type, equivalent to `Buffer` for browser-like environments.
*

@@ -4,0 +4,0 @@ * @packageDocumentation

"use strict";
/**
* TODO
* Blob type, equivalent to `Buffer` for browser-like environments.
*

@@ -5,0 +5,0 @@ * @packageDocumentation

/**
* TODO
* Node.js implementation of browser `btoa` function.
*

@@ -4,0 +4,0 @@ * @packageDocumentation

"use strict";
/**
* TODO
* Node.js implementation of browser `btoa` function.
*

@@ -10,2 +10,3 @@ * @packageDocumentation

Object.defineProperty(exports, "__esModule", { value: true });
exports.btoa = void 0;
/**

@@ -12,0 +13,0 @@ * @internal

/**
* TODO
* Wrapper around browser `btoa` function to allow substituting a
* Node.js-specific implementation.
*

@@ -4,0 +5,0 @@ * @packageDocumentation

"use strict";
/**
* TODO
* Wrapper around browser `btoa` function to allow substituting a
* Node.js-specific implementation.
*

@@ -10,2 +11,3 @@ * @packageDocumentation

Object.defineProperty(exports, "__esModule", { value: true });
exports.btoa = void 0;
/**

@@ -12,0 +14,0 @@ * @internal

/**
* TODO
* Wrapper around the `es6-error` module.
*

@@ -4,0 +4,0 @@ * @packageDocumentation

"use strict";
/**
* TODO
* Wrapper around the `es6-error` module.
*

@@ -10,2 +10,3 @@ * @packageDocumentation

Object.defineProperty(exports, "__esModule", { value: true });
exports.ExtendableError = void 0;
const Es6Error = require("es6-error");

@@ -12,0 +13,0 @@ /**

/**
* TODO
* Wrapper around the browser-compatible implementation of the path module.
*

@@ -4,0 +4,0 @@ * @packageDocumentation

"use strict";
/**
* TODO
* Wrapper around the browser-compatible implementation of the path module.
*

@@ -10,2 +10,3 @@ * @packageDocumentation

Object.defineProperty(exports, "__esModule", { value: true });
exports.joinPath = void 0;
const path_1 = require("path");

@@ -12,0 +13,0 @@ /**

/**
* TODO
* Wrapper around the browser-specific implementation of the path module.
*

@@ -4,0 +4,0 @@ * @packageDocumentation

"use strict";
/**
* TODO
* Wrapper around the browser-specific implementation of the path module.
*

@@ -15,3 +15,3 @@ * @packageDocumentation

var path_1 = require("path");
exports.joinPath = path_1.join;
Object.defineProperty(exports, "joinPath", { enumerable: true, get: function () { return path_1.join; } });
//# sourceMappingURL=joinPath.web.js.map
/**
* TODO
* Utility function for constructing a multipart form in Node.js.
*

@@ -4,0 +4,0 @@ * @packageDocumentation

"use strict";
/**
* TODO
* Utility function for constructing a multipart form in Node.js.
*

@@ -10,2 +10,3 @@ * @packageDocumentation

Object.defineProperty(exports, "__esModule", { value: true });
exports.toForm = void 0;
const stream_1 = require("stream");

@@ -12,0 +13,0 @@ const Multipart = require("multi-part");

/**
* TODO
* Utility function for constructing a multipart form in the browser.
*

@@ -8,3 +8,3 @@ * @packageDocumentation

*/
import { Errback } from "../util/types";
import { Errback } from "./errback";
import { Fields, MultipartRequest } from "./multipart";

@@ -11,0 +11,0 @@ /**

"use strict";
/**
* TODO
* Utility function for constructing a multipart form in the browser.
*

@@ -10,2 +10,3 @@ * @packageDocumentation

Object.defineProperty(exports, "__esModule", { value: true });
exports.toForm = void 0;
/**

@@ -12,0 +13,0 @@ * @internal

/**
* TODO
* Wrapper for the Node.js implementation of the HTTP(S) request function.
*
* In the future this module could conditionally provide VST support.
*
* @packageDocumentation

@@ -5,0 +7,0 @@ * @internal

"use strict";
/**
* TODO
* Wrapper for the Node.js implementation of the HTTP(S) request function.
*
* In the future this module could conditionally provide VST support.
*
* @packageDocumentation

@@ -9,7 +11,14 @@ * @internal

*/
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./request.node"));
__exportStar(require("./request.node"), exports);
//# sourceMappingURL=request.js.map
/**
* TODO
* Node.js implementation of the HTTP(S) request function.
*

@@ -11,3 +11,3 @@ * @packageDocumentation

import { Headers } from "../connection";
import { Errback } from "../util/types";
import { Errback } from "./errback";
/**

@@ -58,7 +58,7 @@ * @internal

/**
* TODO
* Create a function for performing requests against a given host.
*
* @param baseUrl
* @param agentOptions
* @param agent
* @param baseUrl - Base URL of the host, i.e. protocol, port and domain name.
* @param agentOptions - Options to use for creating the agent.
* @param agent - Agent to use for performing requests.
*

@@ -68,3 +68,3 @@ * @internal

*/
export declare function createRequest(baseUrl: string, agentOptions: any, agent: any): RequestFunction;
export declare function createRequest(baseUrl: string, agentOptions: any, agent?: any): RequestFunction;
//# sourceMappingURL=request.node.d.ts.map
"use strict";
/**
* TODO
* Node.js implementation of the HTTP(S) request function.
*

@@ -10,2 +10,3 @@ * @packageDocumentation

Object.defineProperty(exports, "__esModule", { value: true });
exports.createRequest = exports.isBrowser = void 0;
const http_1 = require("http");

@@ -16,2 +17,3 @@ const https_1 = require("https");

const joinPath_1 = require("./joinPath");
const omit_1 = require("./omit");
/**

@@ -23,7 +25,7 @@ * @internal

/**
* TODO
* Create a function for performing requests against a given host.
*
* @param baseUrl
* @param agentOptions
* @param agent
* @param baseUrl - Base URL of the host, i.e. protocol, port and domain name.
* @param agentOptions - Options to use for creating the agent.
* @param agent - Agent to use for performing requests.
*

@@ -61,6 +63,7 @@ * @internal

if (!agent) {
const opts = omit_1.omit(agentOptions, ["before", "after"]);
if (isTls)
agent = new https_1.Agent(agentOptions);
agent = new https_1.Agent(opts);
else
agent = new http_1.Agent(agentOptions);
agent = new http_1.Agent(opts);
}

@@ -100,9 +103,12 @@ return Object.assign(function request({ method, url, headers, body, timeout }, callback) {

res.on("end", () => {
const result = res;
result.request = req;
result.body = Buffer.concat(data);
const response = res;
response.request = req;
response.body = Buffer.concat(data);
if (called)
return;
called = true;
callback(null, result);
if (agentOptions.after) {
agentOptions.after(null, response);
}
callback(null, response);
});

@@ -122,2 +128,5 @@ });

called = true;
if (agentOptions.after) {
agentOptions.after(err);
}
callback(err);

@@ -127,2 +136,5 @@ });

req.write(body);
if (agentOptions.before) {
agentOptions.before(req);
}
req.end();

@@ -129,0 +141,0 @@ }

/**
* Node.js implementation of the HTTP(S) request function.
*
* @packageDocumentation

@@ -6,8 +8,11 @@ * @internal

*/
import { Errback } from "../util/types";
import { Errback } from "./errback";
import { ArangojsResponse, RequestOptions } from "./request.node";
export declare const isBrowser = true;
/**
* TODO
* Create a function for performing requests against a given host.
*
* @param baseUrl - Base URL of the host, i.e. protocol, port and domain name.
* @param agentOptions - Options to use for performing requests.
*
* @param baseUrl

@@ -14,0 +19,0 @@ * @param agentOptions

"use strict";
/**
* Node.js implementation of the HTTP(S) request function.
*
* @packageDocumentation

@@ -8,19 +10,15 @@ * @internal

Object.defineProperty(exports, "__esModule", { value: true });
exports.createRequest = exports.isBrowser = void 0;
const url_1 = require("url");
const btoa_1 = require("./btoa");
const joinPath_1 = require("./joinPath");
const omit_1 = require("./omit");
const xhr_1 = require("./xhr");
exports.isBrowser = true;
function omit(obj, keys) {
const result = {};
for (const key of Object.keys(obj)) {
if (keys.includes(key))
continue;
result[key] = obj[key];
}
return result;
}
/**
* TODO
* Create a function for performing requests against a given host.
*
* @param baseUrl - Base URL of the host, i.e. protocol, port and domain name.
* @param agentOptions - Options to use for performing requests.
*
* @param baseUrl

@@ -34,3 +32,3 @@ * @param agentOptions

const { auth, ...baseUrlParts } = url_1.parse(baseUrl);
const options = omit(agentOptions, ["maxSockets"]);
const options = omit_1.omit(agentOptions, ["maxSockets"]);
return function request({ method, url, headers, body, timeout, expectBinary }, cb) {

@@ -69,5 +67,8 @@ const urlParts = {

if (!err) {
if (!res.body)
res.body = "";
callback(null, res);
const response = res;
response.request = req;
if (!response.body)
response.body = "";
options.after(null, response);
callback(null, response);
}

@@ -77,5 +78,9 @@ else {

error.request = req;
options.after(error);
callback(error);
}
});
if (options.before) {
options.before(req);
}
};

@@ -82,0 +87,0 @@ }

/**
* TODO
* Wrapper around the `xhr` module for HTTP(S) requests in the browser.
*

@@ -8,5 +8,4 @@ * @packageDocumentation

*/
/// <reference types="node" />
import { ClientRequest } from "http";
import { Errback } from "../util/types";
import { Errback } from "./errback";
declare const _default: (options: any, cb: Errback<any>) => ClientRequest;

@@ -13,0 +12,0 @@ /**

"use strict";
/**
* TODO
* Wrapper around the `xhr` module for HTTP(S) requests in the browser.
*

@@ -5,0 +5,0 @@ * @packageDocumentation

{
"name": "arangojs",
"version": "7.0.0-preview.1",
"version": "7.0.0-rc.0",
"engines": {

@@ -5,0 +5,0 @@ "node": ">=10"

@@ -6,11 +6,11 @@ /**

*
* TODO
* The "route" module provides route related types and interfaces for TypeScript.
*
* @packageDocumentation
*/
import { Headers, Params } from "./connection";
import { Headers, Params, RequestOptions } from "./connection";
import { Database } from "./database";
import { ArangojsResponse } from "./lib/request";
/**
* TODO
* Represents an arbitrary route relative to an ArangoDB database.
*/

@@ -27,60 +27,248 @@ export declare class Route {

/**
* TODO
* Creates a new route relative to this route that inherits any of its default
* HTTP headers.
*
* @param path - Path relative to this route.
* @param headers - Additional headers that will be sent with each request.
*
* @example
* ```js
* const db = new Database();
* const foxx = db.route("/my-foxx-service");
* const users = foxx.route("/users");
* ```
*/
route(path: string, headers?: Headers): Route;
/**
* TODO
* Performs an arbitrary HTTP request relative to this route and returns the
* server response.
*
* @param options - Options for performing the request.
*
* @example
* ```js
* const db = new Database();
* const foxx = db.route("/my-foxx-service");
* const res = await foxx.request({
* method: "POST",
* path: "/users",
* body: {
* username: "admin",
* password: "hunter2"
* }
* });
* ```
*/
request({ method, path, headers, ...options }: any): Promise<ArangojsResponse>;
protected _request1(method: string, ...args: any[]): Promise<ArangojsResponse>;
protected _request2(method: string, ...args: any[]): Promise<ArangojsResponse>;
request(options?: RequestOptions): Promise<ArangojsResponse>;
/**
* TODO
* Performs a DELETE request against the given path relative to this route
* and returns the server response.
*
* @param path - Path relative to this route.
* @param qs - Query string parameters for this request.
* @param headers - Additional headers to send with this request.
*
* @example
* ```js
* const db = new Database();
* const foxx = db.route("/my-foxx-service");
* const res = await foxx.delete("/users/admin");
* ```
*/
delete(path?: string, qs?: Params, headers?: Headers): Promise<ArangojsResponse>;
delete(path: string, qs?: string | Params, headers?: Headers): Promise<ArangojsResponse>;
/**
* TODO
* Performs a DELETE request against the given path relative to this route
* and returns the server response.
*
* @param qs - Query string parameters for this request.
* @param headers - Additional headers to send with this request.
*
* @example
* ```js
* const db = new Database();
* const foxx = db.route("/my-foxx-service");
* const user = foxx.roue("/users/admin");
* const res = await user.delete();
* ```
*/
delete(qs?: Params, headers?: Headers): Promise<ArangojsResponse>;
/**
* TODO
* Performs a GET request against the given path relative to this route
* and returns the server response.
*
* @param path - Path relative to this route.
* @param qs - Query string parameters for this request.
* @param headers - Additional headers to send with this request.
*
* @example
* ```js
* const db = new Database();
* const foxx = db.route("/my-foxx-service");
* const res = await foxx.get("/users", { offset: 10, limit: 5 });
* ```
*/
get(path?: string, qs?: Params, headers?: Headers): Promise<ArangojsResponse>;
get(path: string, qs?: string | Params, headers?: Headers): Promise<ArangojsResponse>;
/**
* TODO
* Performs a GET request against the given path relative to this route
* and returns the server response.
*
* @param qs - Query string parameters for this request.
* @param headers - Additional headers to send with this request.
*
* @example
* ```js
* const db = new Database();
* const foxx = db.route("/my-foxx-service");
* const users = foxx.route("/users");
* const res = await users.get({ offset: 10, limit: 5 });
* ```
*/
get(qs?: Params, headers?: Headers): Promise<ArangojsResponse>;
/**
* TODO
* Performs a HEAD request against the given path relative to this route
* and returns the server response.
*
* @param path - Path relative to this route.
* @param qs - Query string parameters for this request.
* @param headers - Additional headers to send with this request.
*
* @example
* ```js
* const db = new Database();
* const foxx = db.route("/my-foxx-service");
* const res = await foxx.head("/users", { offset: 10, limit: 5 });
* ```
*/
head(path?: string, qs?: Params, headers?: Headers): Promise<ArangojsResponse>;
head(path: string, qs?: string | Params, headers?: Headers): Promise<ArangojsResponse>;
/**
* TODO
* Performs a HEAD request against the given path relative to this route
* and returns the server response.
*
* @param qs - Query string parameters for this request.
* @param headers - Additional headers to send with this request.
*
* @example
* ```js
* const db = new Database();
* const foxx = db.route("/my-foxx-service");
* const users = foxx.route("/users");
* const res = await users.head({ offset: 10, limit: 5 });
* ```
*/
head(qs?: Params, headers?: Headers): Promise<ArangojsResponse>;
/**
* TODO
* Performs a PATCH request against the given path relative to this route
* and returns the server response.
*
* @param path - Path relative to this route.
* @param body - Body of the request object.
* @param qs - Query string parameters for this request.
* @param headers - Additional headers to send with this request.
*
* @example
* ```js
* const db = new Database();
* const foxx = db.route("/my-foxx-service");
* const res = await foxx.patch("/users/admin", { password: "admin" });
* ```
*/
patch(path?: string, body?: any, qs?: Params, headers?: Headers): Promise<ArangojsResponse>;
patch(path: string, body?: any, qs?: string | Params, headers?: Headers): Promise<ArangojsResponse>;
/**
* TODO
* Performs a PATCH request against the given path relative to this route
* and returns the server response.
*
* **Note**: `body` must not be a `string`.
*
* @param body - Body of the request object. Must not be a string.
* @param qs - Query string parameters for this request.
* @param headers - Additional headers to send with this request.
*
* @example
* ```js
* const db = new Database();
* const foxx = db.route("/my-foxx-service");
* const user = foxx.route("/users/admin")
* const res = await user.patch({ password: "admin" });
* ```
*/
patch(body?: any, qs?: Params, headers?: Headers): Promise<ArangojsResponse>;
patch(body?: any, qs?: string | Params, headers?: Headers): Promise<ArangojsResponse>;
/**
* TODO
* Performs a POST request against the given path relative to this route
* and returns the server response.
*
* @param path - Path relative to this route.
* @param body - Body of the request object.
* @param qs - Query string parameters for this request.
* @param headers - Additional headers to send with this request.
*
* @example
* ```js
* const db = new Database();
* const foxx = db.route("/my-foxx-service");
* const res = await foxx.post("/users", {
* username: "admin",
* password: "hunter2"
* });
* ```
*/
post(path?: string, body?: any, qs?: Params, headers?: Headers): Promise<ArangojsResponse>;
post(path: string, body?: any, qs?: string | Params, headers?: Headers): Promise<ArangojsResponse>;
/**
* TODO
* Performs a POST request against the given path relative to this route
* and returns the server response.
*
* **Note**: `body` must not be a `string`.
*
* @param body - Body of the request object. Must not be a string.
* @param qs - Query string parameters for this request.
* @param headers - Additional headers to send with this request.
*
* @example
* ```js
* const db = new Database();
* const foxx = db.route("/my-foxx-service");
* const users = foxx.route("/users");
* const res = await users.post({
* username: "admin",
* password: "hunter2"
* });
* ```
*/
post(body?: any, qs?: Params, headers?: Headers): Promise<ArangojsResponse>;
post(body?: any, qs?: string | Params, headers?: Headers): Promise<ArangojsResponse>;
/**
* TODO
* Performs a PUT request against the given path relative to this route
* and returns the server response.
*
* @param path - Path relative to this route.
* @param body - Body of the request object.
* @param qs - Query string parameters for this request.
* @param headers - Additional headers to send with this request.
*
* @example
* ```js
* const db = new Database();
* const foxx = db.route("/my-foxx-service");
* const res = await foxx.put("/users/admin/password", { password: "admin" });
* ```
*/
put(path?: string, body?: any, qs?: Params, headers?: Headers): Promise<ArangojsResponse>;
put(path: string, body?: any, qs?: string | Params, headers?: Headers): Promise<ArangojsResponse>;
/**
* TODO
* Performs a PUT request against the given path relative to this route
* and returns the server response.
*
* **Note**: `body` must not be a `string`.
*
* @param body - Body of the request object. Must not be a string.
* @param qs - Query string parameters for this request.
* @param headers - Additional headers to send with this request.
*
* @example
* ```js
* const db = new Database();
* const foxx = db.route("/my-foxx-service");
* const password = foxx.route("/users/admin/password");
* const res = await password.put({ password: "admin" });
* ```
*/
put(body?: any, qs?: Params, headers?: Headers): Promise<ArangojsResponse>;
put(body?: any, qs?: string | Params, headers?: Headers): Promise<ArangojsResponse>;
}
//# sourceMappingURL=route.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Route = void 0;
/**
* TODO
* Represents an arbitrary route relative to an ArangoDB database.
*/

@@ -21,3 +22,14 @@ class Route {

/**
* TODO
* Creates a new route relative to this route that inherits any of its default
* HTTP headers.
*
* @param path - Path relative to this route.
* @param headers - Additional headers that will be sent with each request.
*
* @example
* ```js
* const db = new Database();
* const foxx = db.route("/my-foxx-service");
* const users = foxx.route("/users");
* ```
*/

@@ -35,65 +47,63 @@ route(path, headers) {

/**
* TODO
* Performs an arbitrary HTTP request relative to this route and returns the
* server response.
*
* @param options - Options for performing the request.
*
* @example
* ```js
* const db = new Database();
* const foxx = db.route("/my-foxx-service");
* const res = await foxx.request({
* method: "POST",
* path: "/users",
* body: {
* username: "admin",
* password: "hunter2"
* }
* });
* ```
*/
request({ method, path, headers = {}, ...options }) {
if (!path)
options.path = "";
else if (this._path && path.charAt(0) !== "/")
options.path = `/${path}`;
request(options) {
const opts = { ...options };
if (!opts.path || opts.path === "/")
opts.path = "";
else if (!this._path || opts.path.charAt(0) === "/")
opts.path = opts.path;
else
options.path = path;
options.basePath = this._path;
options.headers = { ...this._headers, ...headers };
options.method = method ? method.toUpperCase() : "GET";
return this._db.request(options);
opts.path = `/${opts.path}`;
opts.basePath = this._path;
opts.headers = { ...this._headers, ...opts.headers };
opts.method = opts.method ? opts.method.toUpperCase() : "GET";
return this._db.request(opts);
}
_request1(method, ...args) {
let path = "";
let qs;
let headers;
if (args[0] === undefined || typeof args[0] === "string") {
path = args.shift();
}
if (args[0] === undefined || typeof args[0] === "object") {
qs = args.shift();
}
if (args[0] === undefined || typeof args[0] === "object") {
headers = args.shift();
}
return this.request({ method, path, qs, headers });
}
_request2(method, ...args) {
let path = "";
let body = undefined;
let qs;
let headers;
if (args[0] === undefined || typeof args[0] === "string") {
path = args.shift();
}
body = args.shift();
if (args[0] === undefined || typeof args[0] === "object") {
qs = args.shift();
}
if (args[0] === undefined || typeof args[0] === "object") {
headers = args.shift();
}
return this.request({ method, path, body, qs, headers });
}
delete(...args) {
return this._request1("DELETE", ...args);
const path = typeof args[0] === "string" ? args.shift() : undefined;
const [qs, headers] = args;
return this.request({ method: "DELETE", path, qs, headers });
}
get(...args) {
return this._request1("GET", ...args);
const path = typeof args[0] === "string" ? args.shift() : undefined;
const [qs, headers] = args;
return this.request({ method: "GET", path, qs, headers });
}
head(...args) {
return this._request1("HEAD", ...args);
const path = typeof args[0] === "string" ? args.shift() : undefined;
const [qs, headers] = args;
return this.request({ method: "HEAD", path, qs, headers });
}
patch(...args) {
return this._request2("PATCH", ...args);
const path = typeof args[0] === "string" ? args.shift() : undefined;
const [body, qs, headers] = args;
return this.request({ method: "DELETE", path, body, qs, headers });
}
post(...args) {
return this._request2("POST", ...args);
const path = typeof args[0] === "string" ? args.shift() : undefined;
const [body, qs, headers] = args;
return this.request({ method: "POST", path, body, qs, headers });
}
put(...args) {
return this._request2("PUT", ...args);
const path = typeof args[0] === "string" ? args.shift() : undefined;
const [body, qs, headers] = args;
return this.request({ method: "PUT", path, body, qs, headers });
}

@@ -100,0 +110,0 @@ }

import { Database } from "./database";
/**
* Indicates whether the given value represents an {@link ArangoTransaction}.
* Indicates whether the given value represents a {@link Transaction}.
*

@@ -9,10 +9,18 @@ * @param transaction - A value that might be a transaction.

/**
* TODO
* Status of a given transaction.
*
* See also {@link TransactionDetails}.
*/
export declare type TransactionStatus = {
/**
* Unique identifier of the transaction.
*/
id: string;
/**
* Status of the transaction.
*/
status: "running" | "committed" | "aborted";
};
/**
* TODO
* Represents a streaming transaction in a {@link Database}.
*/

@@ -34,26 +42,250 @@ export declare class Transaction {

/**
* TODO
* Unique identifier of this transaction.
*
* See {@link Database.transaction}.
*/
get id(): string;
/**
* TODO
* Checks whether the transaction exists.
*
* @example
* ```js
* const db = new Database();
* const trx = db.transaction("some-transaction");
* const result = await trx.exists();
* // result indicates whether the transaction exists
* ```
*/
exists(): Promise<boolean>;
/**
* TODO
* Retrieves general information about the transaction.
*
* @example
* ```js
* const db = new Database();
* const col = db.collection("some-collection");
* const trx = db.beginTransaction(col);
* await trx.step(() => col.save({ hello: "world" }));
* const info = await trx.get();
* // the transaction exists
* ```
*/
get(): Promise<TransactionStatus>;
/**
* TODO
* Attempts to commit the transaction to the databases.
*
* @example
* ```js
* const db = new Database();
* const col = db.collection("some-collection");
* const trx = db.beginTransaction(col);
* await trx.step(() => col.save({ hello: "world" }));
* const result = await trx.commit();
* // result indicates the updated transaction status
* ```
*/
commit(): Promise<TransactionStatus>;
/**
* TODO
* Attempts to abort the transaction to the databases.
*
* @example
* ```js
* const db = new Database();
* const col = db.collection("some-collection");
* const trx = db.beginTransaction(col);
* await trx.step(() => col.save({ hello: "world" }));
* const result = await trx.abort();
* // result indicates the updated transaction status
* ```
*/
abort(): Promise<TransactionStatus>;
/**
* TODO
* Executes the given function locally as a single step of the transaction.
*
* @param T - Type of the callback's returned promise.
* @param callback - Callback function returning a promise.
*
* **Warning**: The callback function should wrap a single call of an async
* arangojs method (e.g. a method on a {@link Collection} object of a
* collection that is involved in the transaction or the `db.query` method).
* If the callback function is async, only the first promise-returning (or
* async) method call will be executed as part of the transaction. See the
* examples below for how to avoid common mistakes when using this method.
*
* **Note**: Avoid defining the callback as an async function if possible
* as arangojs will throw an error if the callback did not return a promise.
* Async functions will return an empty promise by default, making it harder
* to notice if you forgot to return something from the callback.
*
* **Note**: Although almost anything can be wrapped in a callback and passed
* to this method, that does not guarantee ArangoDB can actually do it in a
* transaction. Refer to the ArangoDB documentation if you are unsure whether
* a given operation can be executed as part of a transaction. Generally any
* modification or retrieval of data is eligible but modifications of
* collections or databases are not.
*
* @example
* ```js
* const db = new Database();
* const vertices = db.collection("vertices");
* const edges = db.collection("edges");
* const trx = await db.beginTransaction({ write: [vertices, edges] });
*
* // The following code will be part of the transaction
* const left = await trx.step(() => vertices.save({ label: "left" }));
* const right = await trx.step(() => vertices.save({ label: "right" }));
*
* // Results from preceding actions can be used normally
* await trx.step(() => edges.save({
* _from: left._id,
* _to: right._id,
* data: "potato"
* }));
*
* // Transaction must be committed for changes to take effected
* // Always call either trx.commit or trx.abort to end a transaction
* await trx.commit();
* ```
*
* @example
* ```js
* // BAD! If the callback is an async function it must only use await once!
* await trx.step(async () => {
* await collection.save(data);
* await collection.save(moreData); // WRONG
* });
*
* // BAD! Callback function must use only one arangojs call!
* await trx.step(() => {
* return collection.save(data)
* .then(() => collection.save(moreData)); // WRONG
* });
*
* // BETTER: Wrap every arangojs method call that should be part of the
* // transaction in a separate `trx.step` call
* await trx.step(() => collection.save(data));
* await trx.step(() => collection.save(moreData));
* ```
*
* @example
* ```js
* // BAD! If the callback is an async function it must not await before
* // calling an arangojs method!
* await trx.step(async () => {
* await doSomethingElse();
* return collection.save(data); // WRONG
* });
*
* // BAD! Any arangojs inside the callback must not happen inside a promise
* // method!
* await trx.step(() => {
* return doSomethingElse()
* .then(() => collection.save(data)); // WRONG
* });
*
* // BETTER: Perform any async logic needed outside the `trx.step` call
* await doSomethingElse();
* await trx.step(() => collection.save(data));
*
* // OKAY: You can perform async logic in the callback after the arangojs
* // method call as long as it does not involve additional arangojs method
* // calls, but this makes it easy to make mistakes later
* await trx.step(async () => {
* await collection.save(data);
* await doSomethingDifferent(); // no arangojs method calls allowed
* });
* ```
*
* @example
* ```js
* // BAD! The callback should not use any functions that themselves use any
* // arangojs methods!
* async function saveSomeData() {
* await collection.save(data);
* await collection.save(moreData);
* }
* await trx.step(() => saveSomeData()); // WRONG
*
* // BETTER: Pass the transaction to functions that need to call arangojs
* // methods inside a transaction
* async function saveSomeData(trx) {
* await trx.step(() => collection.save(data));
* await trx.step(() => collection.save(moreData));
* }
* await saveSomeData(); // no `trx.step` call needed
* ```
*
* @example
* ```js
* // BAD! You must wait for the promise to resolve (or await on the
* // `trx.step` call) before calling `trx.step` again!
* trx.step(() => collection.save(data)); // WRONG
* await trx.step(() => collection.save(moreData));
*
* // BAD! The trx.step callback can not make multiple calls to async arangojs
* // methods, not even using Promise.all!
* await trx.step(() => Promise.all([ // WRONG
* collection.save(data),
* collection.save(moreData),
* ]));
*
* // BAD! Multiple `trx.step` calls can not run in parallel!
* await Promise.all([ // WRONG
* trx.step(() => collection.save(data)),
* trx.step(() => collection.save(moreData)),
* ]));
*
* // BETTER: Always call `trx.step` sequentially, one after the other
* await trx.step(() => collection.save(data));
* await trx.step(() => collection.save(moreData));
*
* // OKAY: The then callback can be used if async/await is not available
* trx.step(() => collection.save(data))
* .then(() => trx.step(() => collection.save(moreData)));
* ```
*
* @example
* ```js
* // BAD! The callback will return an empty promise that resolves before
* // the inner arangojs method call has even talked to ArangoDB!
* await trx.step(async () => {
* collection.save(data); // WRONG
* });
*
* // BETTER: Use an arrow function so you don't forget to return
* await trx.step(() => collection.save(data));
*
* // OKAY: Remember to always return when using a function body
* await trx.step(() => {
* return collection.save(data); // easy to forget!
* });
*
* // OKAY: You do not have to use arrow functions but it helps
* await trx.step(function () {
* return collection.save(data);
* });
* ```
*
* @example
* ```js
* // BAD! You can not pass promises instead of a callback!
* await trx.step(collection.save(data)); // WRONG
*
* // BETTER: Wrap the code in a function and pass the function instead
* await trx.step(() => collection.save(data));
* ```
*
* @example
* ```js
* // WORSE: Calls to non-async arangojs methods don't need to be performed
* // as part of a transaction
* const collection = await trx.step(() => db.collection("my-documents"));
*
* // BETTER: If an arangojs method is not async and doesn't return promises,
* // call it without `trx.step`
* const collection = db.collection("my-documents");
* ```
*/
run<T>(fn: () => Promise<T>): Promise<T>;
step<T>(callback: () => Promise<T>): Promise<T>;
}
//# sourceMappingURL=transaction.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Transaction = exports.isArangoTransaction = void 0;
const error_1 = require("./error");
const codes_1 = require("./util/codes");
const codes_1 = require("./lib/codes");
/**
* Indicates whether the given value represents an {@link ArangoTransaction}.
* Indicates whether the given value represents a {@link Transaction}.
*

@@ -15,3 +16,3 @@ * @param transaction - A value that might be a transaction.

/**
* TODO
* Represents a streaming transaction in a {@link Database}.
*/

@@ -36,3 +37,5 @@ class Transaction {

/**
* TODO
* Unique identifier of this transaction.
*
* See {@link Database.transaction}.
*/

@@ -43,3 +46,11 @@ get id() {

/**
* TODO
* Checks whether the transaction exists.
*
* @example
* ```js
* const db = new Database();
* const trx = db.transaction("some-transaction");
* const result = await trx.exists();
* // result indicates whether the transaction exists
* ```
*/

@@ -59,3 +70,13 @@ async exists() {

/**
* TODO
* Retrieves general information about the transaction.
*
* @example
* ```js
* const db = new Database();
* const col = db.collection("some-collection");
* const trx = db.beginTransaction(col);
* await trx.step(() => col.save({ hello: "world" }));
* const info = await trx.get();
* // the transaction exists
* ```
*/

@@ -68,3 +89,13 @@ get() {

/**
* TODO
* Attempts to commit the transaction to the databases.
*
* @example
* ```js
* const db = new Database();
* const col = db.collection("some-collection");
* const trx = db.beginTransaction(col);
* await trx.step(() => col.save({ hello: "world" }));
* const result = await trx.commit();
* // result indicates the updated transaction status
* ```
*/

@@ -78,3 +109,13 @@ commit() {

/**
* TODO
* Attempts to abort the transaction to the databases.
*
* @example
* ```js
* const db = new Database();
* const col = db.collection("some-collection");
* const trx = db.beginTransaction(col);
* await trx.step(() => col.save({ hello: "world" }));
* const result = await trx.abort();
* // result indicates the updated transaction status
* ```
*/

@@ -88,9 +129,197 @@ abort() {

/**
* TODO
* Executes the given function locally as a single step of the transaction.
*
* @param T - Type of the callback's returned promise.
* @param callback - Callback function returning a promise.
*
* **Warning**: The callback function should wrap a single call of an async
* arangojs method (e.g. a method on a {@link Collection} object of a
* collection that is involved in the transaction or the `db.query` method).
* If the callback function is async, only the first promise-returning (or
* async) method call will be executed as part of the transaction. See the
* examples below for how to avoid common mistakes when using this method.
*
* **Note**: Avoid defining the callback as an async function if possible
* as arangojs will throw an error if the callback did not return a promise.
* Async functions will return an empty promise by default, making it harder
* to notice if you forgot to return something from the callback.
*
* **Note**: Although almost anything can be wrapped in a callback and passed
* to this method, that does not guarantee ArangoDB can actually do it in a
* transaction. Refer to the ArangoDB documentation if you are unsure whether
* a given operation can be executed as part of a transaction. Generally any
* modification or retrieval of data is eligible but modifications of
* collections or databases are not.
*
* @example
* ```js
* const db = new Database();
* const vertices = db.collection("vertices");
* const edges = db.collection("edges");
* const trx = await db.beginTransaction({ write: [vertices, edges] });
*
* // The following code will be part of the transaction
* const left = await trx.step(() => vertices.save({ label: "left" }));
* const right = await trx.step(() => vertices.save({ label: "right" }));
*
* // Results from preceding actions can be used normally
* await trx.step(() => edges.save({
* _from: left._id,
* _to: right._id,
* data: "potato"
* }));
*
* // Transaction must be committed for changes to take effected
* // Always call either trx.commit or trx.abort to end a transaction
* await trx.commit();
* ```
*
* @example
* ```js
* // BAD! If the callback is an async function it must only use await once!
* await trx.step(async () => {
* await collection.save(data);
* await collection.save(moreData); // WRONG
* });
*
* // BAD! Callback function must use only one arangojs call!
* await trx.step(() => {
* return collection.save(data)
* .then(() => collection.save(moreData)); // WRONG
* });
*
* // BETTER: Wrap every arangojs method call that should be part of the
* // transaction in a separate `trx.step` call
* await trx.step(() => collection.save(data));
* await trx.step(() => collection.save(moreData));
* ```
*
* @example
* ```js
* // BAD! If the callback is an async function it must not await before
* // calling an arangojs method!
* await trx.step(async () => {
* await doSomethingElse();
* return collection.save(data); // WRONG
* });
*
* // BAD! Any arangojs inside the callback must not happen inside a promise
* // method!
* await trx.step(() => {
* return doSomethingElse()
* .then(() => collection.save(data)); // WRONG
* });
*
* // BETTER: Perform any async logic needed outside the `trx.step` call
* await doSomethingElse();
* await trx.step(() => collection.save(data));
*
* // OKAY: You can perform async logic in the callback after the arangojs
* // method call as long as it does not involve additional arangojs method
* // calls, but this makes it easy to make mistakes later
* await trx.step(async () => {
* await collection.save(data);
* await doSomethingDifferent(); // no arangojs method calls allowed
* });
* ```
*
* @example
* ```js
* // BAD! The callback should not use any functions that themselves use any
* // arangojs methods!
* async function saveSomeData() {
* await collection.save(data);
* await collection.save(moreData);
* }
* await trx.step(() => saveSomeData()); // WRONG
*
* // BETTER: Pass the transaction to functions that need to call arangojs
* // methods inside a transaction
* async function saveSomeData(trx) {
* await trx.step(() => collection.save(data));
* await trx.step(() => collection.save(moreData));
* }
* await saveSomeData(); // no `trx.step` call needed
* ```
*
* @example
* ```js
* // BAD! You must wait for the promise to resolve (or await on the
* // `trx.step` call) before calling `trx.step` again!
* trx.step(() => collection.save(data)); // WRONG
* await trx.step(() => collection.save(moreData));
*
* // BAD! The trx.step callback can not make multiple calls to async arangojs
* // methods, not even using Promise.all!
* await trx.step(() => Promise.all([ // WRONG
* collection.save(data),
* collection.save(moreData),
* ]));
*
* // BAD! Multiple `trx.step` calls can not run in parallel!
* await Promise.all([ // WRONG
* trx.step(() => collection.save(data)),
* trx.step(() => collection.save(moreData)),
* ]));
*
* // BETTER: Always call `trx.step` sequentially, one after the other
* await trx.step(() => collection.save(data));
* await trx.step(() => collection.save(moreData));
*
* // OKAY: The then callback can be used if async/await is not available
* trx.step(() => collection.save(data))
* .then(() => trx.step(() => collection.save(moreData)));
* ```
*
* @example
* ```js
* // BAD! The callback will return an empty promise that resolves before
* // the inner arangojs method call has even talked to ArangoDB!
* await trx.step(async () => {
* collection.save(data); // WRONG
* });
*
* // BETTER: Use an arrow function so you don't forget to return
* await trx.step(() => collection.save(data));
*
* // OKAY: Remember to always return when using a function body
* await trx.step(() => {
* return collection.save(data); // easy to forget!
* });
*
* // OKAY: You do not have to use arrow functions but it helps
* await trx.step(function () {
* return collection.save(data);
* });
* ```
*
* @example
* ```js
* // BAD! You can not pass promises instead of a callback!
* await trx.step(collection.save(data)); // WRONG
*
* // BETTER: Wrap the code in a function and pass the function instead
* await trx.step(() => collection.save(data));
* ```
*
* @example
* ```js
* // WORSE: Calls to non-async arangojs methods don't need to be performed
* // as part of a transaction
* const collection = await trx.step(() => db.collection("my-documents"));
*
* // BETTER: If an arangojs method is not async and doesn't return promises,
* // call it without `trx.step`
* const collection = db.collection("my-documents");
* ```
*/
run(fn) {
step(callback) {
const conn = this._db._connection;
conn.setTransactionId(this.id);
try {
return Promise.resolve(fn());
const promise = callback();
if (!promise) {
throw new Error("Transaction callback was not an async function or did not return a promise!");
}
return Promise.resolve(promise);
}

@@ -97,0 +326,0 @@ finally {

@@ -10,5 +10,4 @@ /**

*/
import { ArangoResponseMetadata } from "./connection";
import { ArangoResponseMetadata, Dict } from "./connection";
import { Database } from "./database";
import { Dict } from "./util/types";
/**

@@ -39,7 +38,7 @@ * String values indicating the View type.

/**
* The View name.
* Name of the View.
*/
name: string;
/**
* The type of View.
* Type of the View.
*/

@@ -108,3 +107,3 @@ type: ViewType;

/**
* The consolidation policy to apply for selecting which segments should be
* Consolidation policy to apply for selecting which segments should be
* merged.

@@ -125,3 +124,3 @@ */

/**
* The type of consolidation policy.
* Type of consolidation policy.
*/

@@ -140,7 +139,7 @@ type: "bytes_accum";

/**
* The type of consolidation policy.
* Type of consolidation policy.
*/
type: "tier";
/**
* The minimum number of segments that will be evaluated as candidates
* Minimum number of segments that will be evaluated as candidates
* for consolidation.

@@ -152,3 +151,3 @@ *

/**
* The maximum number of segments that will be evaluated as candidates
* Maximum number of segments that will be evaluated as candidates
* for consolidation.

@@ -219,3 +218,3 @@ *

/**
* The consolidation policy to apply for selecting which segments should be
* Consolidation policy to apply for selecting which segments should be
* merged.

@@ -225,3 +224,3 @@ */

/**
* The attribute path (`field`) for the value of each document that will be
* Attribute path (`field`) for the value of each document that will be
* used for sorting.

@@ -237,3 +236,3 @@ *

/**
* The attribute path for the value of each document to use for
* Attribute path for the value of each document to use for
* sorting.

@@ -249,3 +248,3 @@ */

/**
* The attribute path for the value of each document to use for
* Attribute path for the value of each document to use for
* sorting.

@@ -317,3 +316,3 @@ */

*
* See also {@link Database.createArangoSearchView}.
* See also {@link Database.createView}.
*/

@@ -320,0 +319,0 @@ create(options?: PropertiesOptions & {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.View = exports.isArangoView = exports.ViewType = void 0;
const error_1 = require("./error");
const codes_1 = require("./util/codes");
const codes_1 = require("./lib/codes");
/**

@@ -90,3 +91,3 @@ * String values indicating the View type.

*
* See also {@link Database.createArangoSearchView}.
* See also {@link Database.createView}.
*/

@@ -93,0 +94,0 @@ create(options) {

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

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc