UNPKG

@configurator/ravendb

Version:
64 lines 2.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PatchByQueryCommand = exports.PatchByQueryOperation = void 0; const IndexQuery_1 = require("../Queries/IndexQuery"); const TypeUtil_1 = require("../../Utility/TypeUtil"); const Exceptions_1 = require("../../Exceptions"); const RavenCommand_1 = require("../../Http/RavenCommand"); class PatchByQueryOperation { constructor(queryToUpdate, options) { if (TypeUtil_1.TypeUtil.isString(queryToUpdate)) { queryToUpdate = new IndexQuery_1.IndexQuery(queryToUpdate); } if (!queryToUpdate) { (0, Exceptions_1.throwError)("InvalidArgumentException", "QueryToUpdate cannot be null"); } this._queryToUpdate = queryToUpdate; this._options = options; } getCommand(store, conventions, cache) { return new PatchByQueryCommand(conventions, this._queryToUpdate, this._options); } get resultType() { return "OperationId"; } } exports.PatchByQueryOperation = PatchByQueryOperation; PatchByQueryOperation.DUMMY_QUERY = new IndexQuery_1.IndexQuery(); class PatchByQueryCommand extends RavenCommand_1.RavenCommand { get isReadRequest() { return false; } constructor(conventions, queryToUpdate, options) { super(); this._conventions = conventions; this._queryToUpdate = queryToUpdate; this._options = options || {}; } createRequest(node) { let path = node.url + "/databases/" + node.database + "/queries?allowStale=" + !!this._options.allowStale; if (!TypeUtil_1.TypeUtil.isNullOrUndefined(this._options.maxOpsPerSecond)) { path += "&maxOpsPerSec=" + this._options.maxOpsPerSecond; } path += "&details=" + !!this._options.retrieveDetails; if (!TypeUtil_1.TypeUtil.isNullOrUndefined(this._options.staleTimeout)) { path += "&staleTimeout=" + this._options.staleTimeout; } const body = `{ "Query": ${(0, IndexQuery_1.writeIndexQuery)(this._conventions, this._queryToUpdate)} }`; return { method: "PATCH", uri: path, headers: this._headers().typeAppJson().build(), body }; } async setResponseAsync(bodyStream, fromCache) { if (!bodyStream) { this._throwInvalidResponse(); } return this._parseResponseDefaultAsync(bodyStream); } } exports.PatchByQueryCommand = PatchByQueryCommand; //# sourceMappingURL=PatchByQueryOperation.js.map