@configurator/ravendb
Version:
RavenDB client for Node.js
66 lines • 2.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.writeIndexQuery = exports.IndexQuery = void 0;
const Exceptions_1 = require("../../Exceptions");
const IndexQueryWithParameters_1 = require("./IndexQueryWithParameters");
const HashCalculator_1 = require("./HashCalculator");
const TypeUtil_1 = require("../../Utility/TypeUtil");
const Serializer_1 = require("../../Mapping/Json/Serializer");
class IndexQuery extends IndexQueryWithParameters_1.IndexQueryWithParameters {
constructor(query) {
super();
this.query = query;
}
getQueryHash(mapper) {
const hasher = new HashCalculator_1.HashCalculator();
try {
hasher.write(this.query, mapper);
hasher.write(this.waitForNonStaleResults);
hasher.write(this.skipDuplicateChecking);
hasher.write(this.waitForNonStaleResultsTimeout || 0);
hasher.write(this.start);
hasher.write(this.pageSize);
hasher.write(this.queryParameters, mapper);
return hasher.getHash();
}
catch (err) {
(0, Exceptions_1.throwError)("RavenException", "Unable to calculate hash", err);
}
}
}
exports.IndexQuery = IndexQuery;
function writeIndexQuery(conventions, indexQuery) {
const result = {
Query: indexQuery.query
};
if (indexQuery.pageSizeSet && indexQuery.pageSize >= 0) {
result["PageSize"] = indexQuery.pageSize;
}
if (indexQuery.waitForNonStaleResults) {
result["WaitForNonStaleResults"] = indexQuery.waitForNonStaleResults;
}
if (indexQuery.start > 0) {
result["Start"] = indexQuery.start;
}
if (!TypeUtil_1.TypeUtil.isNullOrUndefined(indexQuery.waitForNonStaleResultsTimeout)) {
result["WaitForNonStaleResultsTimeout"] = indexQuery.waitForNonStaleResultsTimeout;
}
if (indexQuery.disableCaching) {
result["DisableCaching"] = indexQuery.disableCaching;
}
if (indexQuery.skipDuplicateChecking) {
result["SkipDuplicateChecking"] = indexQuery.skipDuplicateChecking;
}
if (!indexQuery.queryParameters) {
result["QueryParameters"] = null;
}
else {
result["QueryParameters"] = indexQuery.queryParameters;
}
if (indexQuery.projectionBehavior && indexQuery.projectionBehavior !== "Default") {
result["ProjectionBehavior"] = indexQuery.projectionBehavior;
}
return Serializer_1.JsonSerializer.getDefault().serialize(result);
}
exports.writeIndexQuery = writeIndexQuery;
//# sourceMappingURL=IndexQuery.js.map