UNPKG

ravendb

Version:
88 lines 3.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BatchPatchCommandData = void 0; const CaseInsensitiveStringSet_js_1 = require("../../../Primitives/CaseInsensitiveStringSet.js"); const index_js_1 = require("../../../Exceptions/index.js"); const TypeUtil_js_1 = require("../../../Utility/TypeUtil.js"); const StringUtil_js_1 = require("../../../Utility/StringUtil.js"); /** * Commands that patches multiple documents using same patch script * CAUTION: This command does not update session state after .saveChanges() call */ class BatchPatchCommandData { _seenIds = CaseInsensitiveStringSet_js_1.CaseInsensitiveStringSet.create(); _ids = []; _name = null; _patch; _patchIfMissing; constructor(patch, patchIfMissing, ...ids) { if (!patch) { (0, index_js_1.throwError)("InvalidArgumentException", "Patch cannot be null."); } if (arguments.length >= 3) { if (!ids) { (0, index_js_1.throwError)("InvalidArgumentException", "Ids cannot be null."); } if (ids.length === 0) { (0, index_js_1.throwError)("InvalidArgumentException", "Value cannot be an empty collection."); } for (const idEntry of ids) { if (TypeUtil_js_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_js_1.StringUtil.isNullOrWhitespace(id)) { (0, index_js_1.throwError)("InvalidArgumentException", "Value cannot be null or whitespace."); } if (!this._seenIds.add(id)) { (0, index_js_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, index_js_1.throwError)("NotSupportedException"); } get name() { return this._name; } get patch() { return this._patch; } patchIfMissing() { return this._patchIfMissing; } get changeVector() { return (0, index_js_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