@configurator/ravendb
Version:
RavenDB client for Node.js
73 lines • 2.83 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LazyConditionalLoadOperation = void 0;
const GetRequest_1 = require("../../../Commands/MultiGet/GetRequest");
const Exceptions_1 = require("../../../../Exceptions");
const StatusCode_1 = require("../../../../Http/StatusCode");
const Constants_1 = require("../../../../Constants");
const QueryCommand_1 = require("../../../Commands/QueryCommand");
const StreamUtil_1 = require("../../../../Utility/StreamUtil");
const DocumentInfo_1 = require("../../DocumentInfo");
class LazyConditionalLoadOperation {
constructor(session, id, changeVector, clazz) {
this._clazz = clazz;
this._session = session;
this._id = id;
this._changeVector = changeVector;
}
createRequest() {
const request = new GetRequest_1.GetRequest();
request.url = "/docs";
request.method = "GET";
request.query = "?id=" + encodeURIComponent(this._id);
request.headers[Constants_1.HEADERS.IF_NONE_MATCH] = `"${this._changeVector}"`;
return request;
}
get queryResult() {
(0, Exceptions_1.throwError)("NotImplementedException");
return null;
}
get result() {
return this._result;
}
get requiresRetry() {
return this._requiresRetry;
}
async handleResponseAsync(response) {
if (response.forceRetry) {
this._result = null;
this._requiresRetry = true;
return;
}
switch (response.statusCode) {
case StatusCode_1.StatusCodes.NotModified:
this._result = {
entity: null,
changeVector: this._changeVector
};
return;
case StatusCode_1.StatusCodes.NotFound:
this._session.registerMissing(this._id);
this._result = {
entity: null,
changeVector: null
};
return;
}
if (response.result) {
const etag = response.headers[Constants_1.HEADERS.ETAG];
const res = await QueryCommand_1.QueryCommand.parseQueryResultResponseAsync((0, StreamUtil_1.stringToReadable)(response.result), this._session.conventions, false);
const documentInfo = DocumentInfo_1.DocumentInfo.getNewDocumentInfo(res.results[0]);
const r = this._session.trackEntity(this._clazz, documentInfo);
this._result = {
entity: r,
changeVector: etag
};
return;
}
this._result = null;
this._session.registerMissing(this._id);
}
}
exports.LazyConditionalLoadOperation = LazyConditionalLoadOperation;
//# sourceMappingURL=LazyConditionalLoadOperation.js.map