UNPKG

ravendb

Version:
41 lines 2.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DocumentSessionRevisionsBase = void 0; const index_js_1 = require("../../Exceptions/index.js"); const TypeUtil_js_1 = require("../../Utility/TypeUtil.js"); const StringUtil_js_1 = require("../../Utility/StringUtil.js"); const AdvancedSessionExtensionBase_js_1 = require("./AdvancedSessionExtensionBase.js"); class DocumentSessionRevisionsBase extends AdvancedSessionExtensionBase_js_1.AdvancedSessionExtensionBase { forceRevisionCreationFor(entityOrId, strategy = "Before") { if (!entityOrId) { (0, index_js_1.throwError)("InvalidArgumentException", "Entity cannot be null"); } if (TypeUtil_js_1.TypeUtil.isString(entityOrId)) { this._addIdToList(entityOrId, strategy); } else { const documentInfo = this._session.documentsByEntity.get(entityOrId); if (!documentInfo) { (0, index_js_1.throwError)("InvalidOperationException", "Cannot create a revision for the requested entity because it is Not tracked by the session"); } this._addIdToList(documentInfo.id, strategy); } } _addIdToList(id, requestedStrategy) { if (StringUtil_js_1.StringUtil.isNullOrEmpty(id)) { (0, index_js_1.throwError)("InvalidArgumentException", "Id cannot be null or empty"); } const existingStrategy = this._session.idsForCreatingForcedRevisions.get(id); const idAlreadyAdded = !!existingStrategy; if (idAlreadyAdded && existingStrategy !== requestedStrategy) { (0, index_js_1.throwError)("InvalidOperationException", "A request for creating a revision was already made for document " + id + " in the current session but with a different force strategy. New strategy requested: " + requestedStrategy + ". Previous strategy: " + existingStrategy + "."); } if (!idAlreadyAdded) { this._session.idsForCreatingForcedRevisions.set(id, requestedStrategy); } } } exports.DocumentSessionRevisionsBase = DocumentSessionRevisionsBase; //# sourceMappingURL=DocumentSessionRevisionsBase.js.map