@configurator/ravendb
Version:
RavenDB client for Node.js
82 lines • 2.94 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BatchPatchCommandData = void 0;
const CaseInsensitiveStringSet_1 = require("../../../Primitives/CaseInsensitiveStringSet");
const Exceptions_1 = require("../../../Exceptions");
const TypeUtil_1 = require("../../../Utility/TypeUtil");
const StringUtil_1 = require("../../../Utility/StringUtil");
class BatchPatchCommandData {
constructor(patch, patchIfMissing, ...ids) {
this._seenIds = CaseInsensitiveStringSet_1.CaseInsensitiveStringSet.create();
this._ids = [];
this._name = null;
if (!patch) {
(0, Exceptions_1.throwError)("InvalidArgumentException", "Patch cannot be null.");
}
if (arguments.length >= 3) {
if (!ids) {
(0, Exceptions_1.throwError)("InvalidArgumentException", "Ids cannot be null.");
}
if (ids.length === 0) {
(0, Exceptions_1.throwError)("InvalidArgumentException", "Value cannot be an empty collection.");
}
for (const idEntry of ids) {
if (TypeUtil_1.TypeUtil.isObject(idEntry)) {
const { id, changeVector } = idEntry;
this._add(id, changeVector);
}
else {
this._add(idEntry);
}
}
}
this._patch = patch;
this._patchIfMissing = patchIfMissing;
}
_add(id, changeVector) {
if (StringUtil_1.StringUtil.isNullOrWhitespace(id)) {
(0, Exceptions_1.throwError)("InvalidArgumentException", "Value cannot be null or whitespace.");
}
if (!this._seenIds.add(id)) {
(0, Exceptions_1.throwError)("InvalidOperationException", "Could not add ID '" + id + "' because item with the same ID was already added");
}
this._ids.push({ id, changeVector });
}
get ids() {
return this._ids;
}
get id() {
return (0, Exceptions_1.throwError)("NotSupportedException");
}
get name() {
return this._name;
}
get patch() {
return this._patch;
}
patchIfMissing() {
return this._patchIfMissing;
}
get changeVector() {
return (0, Exceptions_1.throwError)("NotSupportedException");
}
get type() {
return "BatchPATCH";
}
serialize(conventions) {
const ids = this._ids.map(x => ({
Id: x.id,
ChangeVector: x.changeVector || undefined
}));
return {
Ids: ids,
Patch: this.patch.serialize(conventions),
Type: "BatchPATCH",
PatchIfMissing: this._patchIfMissing
? this._patchIfMissing.serialize(conventions)
: undefined
};
}
}
exports.BatchPatchCommandData = BatchPatchCommandData;
//# sourceMappingURL=BatchPatchCommandData.js.map