UNPKG

ravendb

Version:
102 lines 4.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DocumentSessionRevisions = void 0; const GetRevisionOperation_js_1 = require("./Operations/GetRevisionOperation.js"); const TypeUtil_js_1 = require("../../Utility/TypeUtil.js"); const DocumentSessionRevisionsBase_js_1 = require("./DocumentSessionRevisionsBase.js"); const LazyRevisionOperations_js_1 = require("./Operations/Lazy/LazyRevisionOperations.js"); const GetRevisionsCountOperation_js_1 = require("./Operations/GetRevisionsCountOperation.js"); class DocumentSessionRevisions extends DocumentSessionRevisionsBase_js_1.DocumentSessionRevisionsBase { constructor(session) { super(session); } get lazily() { return new LazyRevisionOperations_js_1.LazyRevisionOperations(this._session); } async getFor(id, options) { options = Object.assign({ pageSize: 25, start: 0 }, options || {}); const operation = new GetRevisionOperation_js_1.GetRevisionOperation(this._session, id, options.start, options.pageSize); const command = operation.createRequest(); if (!command) { return operation.getRevisionsFor(options.documentType); } if (this._sessionInfo) { this._sessionInfo.incrementRequestCount(); } await this._requestExecutor.execute(command, this._sessionInfo); operation.result = command.result; return operation.getRevisionsFor(options.documentType); } async getMetadataFor(id, options) { options = Object.assign({ pageSize: 25, start: 0 }, options || {}); const operation = new GetRevisionOperation_js_1.GetRevisionOperation(this._session, id, options.start, options.pageSize, true); const command = operation.createRequest(); if (!command) { return operation.getRevisionsMetadataFor(); } if (this._sessionInfo) { this._sessionInfo.incrementRequestCount(); } await this._requestExecutor.execute(command, this._sessionInfo); operation.result = command.result; return operation.getRevisionsMetadataFor(); } async get(changeVectorOrVectorsOrId, documentTypeOrDate, documentTypeForDateOverload) { const documentType = TypeUtil_js_1.TypeUtil.isDocumentType(documentTypeOrDate) ? documentTypeOrDate : undefined; if (TypeUtil_js_1.TypeUtil.isDate(documentTypeOrDate)) { return this._getByIdAndDate(changeVectorOrVectorsOrId, documentTypeOrDate, documentTypeForDateOverload); } else { return this._get(changeVectorOrVectorsOrId, documentType); } } async _getByIdAndDate(id, date, clazz) { const operation = new GetRevisionOperation_js_1.GetRevisionOperation(this._session, id, date); const command = operation.createRequest(); if (!command) { return operation.getRevision(clazz); } if (this._sessionInfo) { this._sessionInfo.incrementRequestCount(); } await this._requestExecutor.execute(command, this._sessionInfo); operation.result = command.result; return operation.getRevision(clazz); } async _get(changeVectorOrVectors, documentType) { const operation = new GetRevisionOperation_js_1.GetRevisionOperation(this._session, changeVectorOrVectors); const command = operation.createRequest(); if (!command) { return TypeUtil_js_1.TypeUtil.isArray(changeVectorOrVectors) ? operation.getRevisions(documentType) : operation.getRevision(documentType); } if (this._sessionInfo) { this._sessionInfo.incrementRequestCount(); } await this._requestExecutor.execute(command, this._sessionInfo); operation.result = command.result; return TypeUtil_js_1.TypeUtil.isArray(changeVectorOrVectors) ? operation.getRevisions(documentType) : operation.getRevision(documentType); } async getCountFor(id) { const operation = new GetRevisionsCountOperation_js_1.GetRevisionsCountOperation(id); const command = operation.createRequest(); if (this._sessionInfo) { this._sessionInfo.incrementRequestCount(); } await this._requestExecutor.execute(command, this._sessionInfo); return command.result; } } exports.DocumentSessionRevisions = DocumentSessionRevisions; //# sourceMappingURL=DocumentSessionRevisions.js.map