UNPKG

ravendb

Version:
81 lines 3.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LazyConditionalLoadOperation = void 0; const GetRequest_js_1 = require("../../../Commands/MultiGet/GetRequest.js"); const index_js_1 = require("../../../../Exceptions/index.js"); const StatusCode_js_1 = require("../../../../Http/StatusCode.js"); const Constants_js_1 = require("../../../../Constants.js"); const QueryCommand_js_1 = require("../../../Commands/QueryCommand.js"); const StreamUtil_js_1 = require("../../../../Utility/StreamUtil.js"); const DocumentInfo_js_1 = require("../../DocumentInfo.js"); class LazyConditionalLoadOperation { _clazz; _session; _id; _changeVector; constructor(session, id, changeVector, clazz) { this._clazz = clazz; this._session = session; this._id = id; this._changeVector = changeVector; } createRequest() { const request = new GetRequest_js_1.GetRequest(); request.url = "/docs"; request.method = "GET"; request.query = "?id=" + encodeURIComponent(this._id); request.headers[Constants_js_1.HEADERS.IF_NONE_MATCH] = `"${this._changeVector}"`; return request; } _result; _requiresRetry; get queryResult() { (0, index_js_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_js_1.StatusCodes.NotModified: { this._result = { entity: null, changeVector: this._changeVector }; return; } case StatusCode_js_1.StatusCodes.NotFound: { this._session.registerMissing(this._id); this._result = { entity: null, changeVector: null }; return; } } if (response.result) { const etag = response.headers[Constants_js_1.HEADERS.ETAG]; const res = await QueryCommand_js_1.QueryCommand.parseQueryResultResponseAsync((0, StreamUtil_js_1.stringToReadable)(response.result), this._session.conventions, false); const documentInfo = DocumentInfo_js_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