UNPKG

ravendb

Version:
63 lines 2.24 kB
import { CollectionStats } from "../../Indexes/IndexStats.js"; import { throwError } from "../../../Exceptions/index.js"; import { RavenCommand } from "../../../Http/RavenCommand.js"; export class GetIndexStatisticsOperation { _indexName; constructor(indexName) { if (!indexName) { throwError("InvalidArgumentException", "IndexName cannot be null."); } this._indexName = indexName; } getCommand(conventions) { return new GetIndexStatisticsCommand(this._indexName, conventions); } get resultType() { return "CommandResult"; } } export class GetIndexStatisticsCommand extends RavenCommand { _indexName; _conventions; constructor(indexName, conventions) { super(); if (!indexName) { throwError("InvalidArgumentException", "IndexName cannot be null."); } this._indexName = indexName; this._conventions = conventions; } createRequest(node) { const uri = node.url + "/databases/" + node.database + "/indexes/stats?name=" + encodeURIComponent(this._indexName); return { uri }; } async setResponseAsync(bodyStream, fromCache) { if (!bodyStream) { this._throwInvalidResponse(); } let body = null; const results = await this._defaultPipeline(_ => body = _) .process(bodyStream); for (const r of results["results"]) { r.collections = Object.keys(r.collections) .reduce((result, next) => [...result, [next, result[next]]], []); } const responseObj = this._reviveResultTypes(results, this._conventions, { nestedTypes: { "results[].collections": "Map", "results[].collections$MAP": "CollectionStats" } }, new Map([[CollectionStats.name, CollectionStats]])); const indexStatsResults = responseObj["results"]; if (!indexStatsResults.length) { this._throwInvalidResponse(); } this.result = indexStatsResults[0]; return body; } get isReadRequest() { return true; } } //# sourceMappingURL=GetIndexStatisticsOperation.js.map