UNPKG

ravendb

Version:
131 lines 4.29 kB
import { throwError } from "../../Exceptions/index.js"; import { SessionBeforeDeleteEventArgs } from "../Session/SessionEvents.js"; export class DeleteCommandData { id; name; changeVector; originalChangeVector; document; get type() { return "DELETE"; } constructor(id, changeVector, originalChangeVector) { this.id = id; if (!id) { throwError("InvalidArgumentException", "Id cannot be null or undefined."); } this.changeVector = changeVector; this.originalChangeVector = originalChangeVector; } serialize(conventions) { const result = { Id: this.id, ChangeVector: this.changeVector, Type: "DELETE", Document: this.document }; if (this.originalChangeVector) { result.OriginalChangeVector = this.originalChangeVector; } this._serializeExtraFields(result); return result; } onBeforeSaveChanges(session) { session.emit("beforeDelete", new SessionBeforeDeleteEventArgs(session, this.id, null)); } // eslint-disable-next-line @typescript-eslint/no-empty-function _serializeExtraFields(resultingObject) { } } export class PutCommandDataBase { get type() { return "PUT"; } id; name = null; changeVector; originalChangeVector; forceRevisionCreationStrategy; _document; constructor(id, changeVector, originalChangeVector, document, strategy = "None") { if (!document) { throwError("InvalidArgumentException", "Document cannot be null or undefined."); } this.id = id; this.changeVector = changeVector; this.originalChangeVector = originalChangeVector; this._document = document; this.forceRevisionCreationStrategy = strategy; } serialize(conventions) { const result = { Id: this.id, ChangeVector: this.changeVector, OriginalChangeVector: this.originalChangeVector, Document: this._document, Type: "PUT" }; if (this.forceRevisionCreationStrategy !== "None") { result["ForceRevisionCreationStrategy"] = this.forceRevisionCreationStrategy; } return result; } } export class PutCommandDataWithJson extends PutCommandDataBase { constructor(id, changeVector, originalChangeVector, document, strategy) { super(id, changeVector, originalChangeVector, document, strategy); } } export class SaveChangesData { deferredCommands; deferredCommandsMap; sessionCommands = []; entities = []; options; onSuccess; constructor(args) { this.deferredCommands = args.deferredCommands; this.deferredCommandsMap = args.deferredCommandsMap; this.options = args.options; this.onSuccess = new ActionsToRunOnSuccess(args.session); } } export class ActionsToRunOnSuccess { _session; _documentsByIdToRemove = []; _documentsByEntityToRemove = []; _documentInfosToUpdate = []; _clearDeletedEntities; constructor(session) { this._session = session; } removeDocumentById(id) { this._documentsByIdToRemove.push(id); } removeDocumentByEntity(entity) { this._documentsByEntityToRemove.push(entity); } updateEntityDocumentInfo(documentInfo, document) { this._documentInfosToUpdate.push([documentInfo, document]); } clearSessionStateAfterSuccessfulSaveChanges() { for (const id of this._documentsByIdToRemove) { this._session.documentsById.remove(id); } for (const entity of this._documentsByEntityToRemove) { this._session.documentsByEntity.remove(entity); } for (const [info, document] of this._documentInfosToUpdate) { info.newDocument = false; info.document = document; } if (this._clearDeletedEntities) { this._session.deletedEntities.clear(); } this._session.deferredCommands.length = 0; this._session.deferredCommandsMap.clear(); } clearDeletedEntities() { this._clearDeletedEntities = true; } } //# sourceMappingURL=CommandData.js.map