UNPKG

arangojs

Version:

The official ArangoDB JavaScript driver.

160 lines 4.61 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Analyzer = exports.isArangoAnalyzer = void 0; const errors = __importStar(require("./errors.js")); const codes_js_1 = require("./lib/codes.js"); //#endregion //#region Analyzer class /** * Indicates whether the given value represents an {@link Analyzer}. * * @param analyzer - A value that might be an Analyzer. */ function isArangoAnalyzer(analyzer) { return Boolean(analyzer && analyzer.isArangoAnalyzer); } exports.isArangoAnalyzer = isArangoAnalyzer; /** * Represents an Analyzer in a {@link databases.Database}. */ class Analyzer { _name; _db; /** * @internal */ constructor(db, name) { this._db = db; this._name = name; } /** * Database this analyzer belongs to. */ get database() { return this._db; } /** * @internal * * Indicates that this object represents an ArangoDB Analyzer. */ get isArangoAnalyzer() { return true; } /** * Name of this Analyzer. * * See also {@link databases.Database}. */ get name() { return this._name; } /** * 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 * ``` */ async exists() { try { await this.get(); return true; } catch (err) { if (errors.isArangoError(err) && err.errorNum === codes_js_1.ANALYZER_NOT_FOUND) { return false; } throw err; } } /** * 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({ pathname: `/_api/analyzer/${encodeURIComponent(this._name)}`, }); } /** * Creates a new Analyzer with the given `options` and the instance's name. * * See also {@link databases.Database#createAnalyzer}. * * @param options - Options for creating the Analyzer. * * @example * ```js * const db = new Database(); * const analyzer = db.analyzer("potatoes"); * await analyzer.create({ type: "identity" }); * // the identity Analyzer "potatoes" now exists * ``` */ create(options) { return this._db.request({ method: "POST", pathname: "/_api/analyzer", body: { name: this._name, ...options }, }); } /** * 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 = false) { return this._db.request({ method: "DELETE", pathname: `/_api/analyzer/${encodeURIComponent(this._name)}`, search: { force }, }); } } exports.Analyzer = Analyzer; //#endregion //# sourceMappingURL=analyzers.js.map