UNPKG

@configurator/ravendb

Version:
48 lines 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SuggestionQueryBase = void 0; const Stopwatch_1 = require("../../../Utility/Stopwatch"); const QueryCommand_1 = require("../../Commands/QueryCommand"); const LazySuggestionQueryOperation_1 = require("../../Session/Operations/Lazy/LazySuggestionQueryOperation"); const QueryOperation_1 = require("../../Session/Operations/QueryOperation"); const ObjectUtil_1 = require("../../../Utility/ObjectUtil"); class SuggestionQueryBase { constructor(session) { this._session = session; } async execute() { const command = this._getCommand(); this._duration = Stopwatch_1.Stopwatch.createStarted(); this._session.incrementRequestCount(); await this._session.requestExecutor.execute(command); return this._processResults(command.result); } _processResults(queryResult) { this._invokeAfterQueryExecuted(queryResult); const results = {}; for (const result of queryResult.results) { const transformedResult = ObjectUtil_1.ObjectUtil.transformObjectKeys(result, { defaultTransform: "camel" }); results[transformedResult.name] = transformedResult; } QueryOperation_1.QueryOperation.ensureIsAcceptable(queryResult, this._query.waitForNonStaleResults, this._duration, this._session); return results; } executeLazy() { this._query = this._getIndexQuery(); return this._session.addLazyOperation(new LazySuggestionQueryOperation_1.LazySuggestionQueryOperation(this._session, this._query, result => this._invokeAfterQueryExecuted(result), (result) => this._processResults(result))); } _getCommand() { this._query = this._getIndexQuery(); return new QueryCommand_1.QueryCommand(this._session, this._query, { indexEntriesOnly: false, metadataOnly: false }); } toString() { return this._getIndexQuery(false).toString(); } } exports.SuggestionQueryBase = SuggestionQueryBase; //# sourceMappingURL=SuggestionQueryBase.js.map