ravendb
Version:
RavenDB client for Node.js
72 lines • 2.8 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PatchByQueryCommand = exports.PatchByQueryOperation = void 0;
const IndexQuery_js_1 = require("../Queries/IndexQuery.js");
const TypeUtil_js_1 = require("../../Utility/TypeUtil.js");
const index_js_1 = require("../../Exceptions/index.js");
const RavenCommand_js_1 = require("../../Http/RavenCommand.js");
class PatchByQueryOperation {
static DUMMY_QUERY = new IndexQuery_js_1.IndexQuery();
_queryToUpdate;
_options;
constructor(queryToUpdate, options) {
if (TypeUtil_js_1.TypeUtil.isString(queryToUpdate)) {
queryToUpdate = new IndexQuery_js_1.IndexQuery(queryToUpdate);
}
if (!queryToUpdate) {
(0, index_js_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;
class PatchByQueryCommand extends RavenCommand_js_1.RavenCommand {
_conventions;
_queryToUpdate;
_options;
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_js_1.TypeUtil.isNullOrUndefined(this._options.maxOpsPerSecond)) {
path += "&maxOpsPerSec=" + this._options.maxOpsPerSecond;
}
path += "&details=" + !!this._options.retrieveDetails;
if (!TypeUtil_js_1.TypeUtil.isNullOrUndefined(this._options.staleTimeout)) {
path += "&staleTimeout=" + this._options.staleTimeout;
}
if (this._options.ignoreMaxStepsForScript) {
path += "&ignoreMaxStepsForScript=true";
}
const body = `{ "Query": ${(0, IndexQuery_js_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