@configurator/ravendb
Version:
RavenDB client for Node.js
102 lines • 4.55 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DocumentSessionRevisions = void 0;
const GetRevisionOperation_1 = require("./Operations/GetRevisionOperation");
const TypeUtil_1 = require("../../Utility/TypeUtil");
const DocumentSessionRevisionsBase_1 = require("./DocumentSessionRevisionsBase");
const LazyRevisionOperations_1 = require("./Operations/Lazy/LazyRevisionOperations");
const GetRevisionsCountOperation_1 = require("./Operations/GetRevisionsCountOperation");
class DocumentSessionRevisions extends DocumentSessionRevisionsBase_1.DocumentSessionRevisionsBase {
constructor(session) {
super(session);
}
get lazily() {
return new LazyRevisionOperations_1.LazyRevisionOperations(this._session);
}
async getFor(id, options) {
options = Object.assign({
pageSize: 25,
start: 0
}, options || {});
const operation = new GetRevisionOperation_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_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_1.TypeUtil.isDocumentType(documentTypeOrDate)
? documentTypeOrDate
: undefined;
if (TypeUtil_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_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_1.GetRevisionOperation(this._session, changeVectorOrVectors);
const command = operation.createRequest();
if (!command) {
return TypeUtil_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_1.TypeUtil.isArray(changeVectorOrVectors)
? operation.getRevisions(documentType)
: operation.getRevision(documentType);
}
async getCountFor(id) {
const operation = new GetRevisionsCountOperation_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