@configurator/ravendb
Version:
RavenDB client for Node.js
65 lines • 2.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetIndexStatisticsCommand = exports.GetIndexStatisticsOperation = void 0;
const IndexStats_1 = require("../../Indexes/IndexStats");
const Exceptions_1 = require("../../../Exceptions");
const RavenCommand_1 = require("../../../Http/RavenCommand");
class GetIndexStatisticsOperation {
constructor(indexName) {
if (!indexName) {
(0, Exceptions_1.throwError)("InvalidArgumentException", "IndexName cannot be null.");
}
this._indexName = indexName;
}
getCommand(conventions) {
return new GetIndexStatisticsCommand(this._indexName, conventions);
}
get resultType() {
return "CommandResult";
}
}
exports.GetIndexStatisticsOperation = GetIndexStatisticsOperation;
class GetIndexStatisticsCommand extends RavenCommand_1.RavenCommand {
constructor(indexName, conventions) {
super();
if (!indexName) {
(0, Exceptions_1.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([[IndexStats_1.CollectionStats.name, IndexStats_1.CollectionStats]]));
const indexStatsResults = responseObj["results"];
if (!indexStatsResults.length) {
this._throwInvalidResponse();
}
this.result = indexStatsResults[0];
return body;
}
get isReadRequest() {
return true;
}
}
exports.GetIndexStatisticsCommand = GetIndexStatisticsCommand;
//# sourceMappingURL=GetIndexStatisticsOperation.js.map