UNPKG

ravendb

Version:
77 lines 2.65 kB
import { GetRequest } from "../../../Commands/MultiGet/GetRequest.js"; import { throwError } from "../../../../Exceptions/index.js"; import { StatusCodes } from "../../../../Http/StatusCode.js"; import { HEADERS } from "../../../../Constants.js"; import { QueryCommand } from "../../../Commands/QueryCommand.js"; import { stringToReadable } from "../../../../Utility/StreamUtil.js"; import { DocumentInfo } from "../../DocumentInfo.js"; export 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(); request.url = "/docs"; request.method = "GET"; request.query = "?id=" + encodeURIComponent(this._id); request.headers[HEADERS.IF_NONE_MATCH] = `"${this._changeVector}"`; return request; } _result; _requiresRetry; get queryResult() { 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 StatusCodes.NotModified: { this._result = { entity: null, changeVector: this._changeVector }; return; } case StatusCodes.NotFound: { this._session.registerMissing(this._id); this._result = { entity: null, changeVector: null }; return; } } if (response.result) { const etag = response.headers[HEADERS.ETAG]; const res = await QueryCommand.parseQueryResultResponseAsync(stringToReadable(response.result), this._session.conventions, false); const documentInfo = 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); } } //# sourceMappingURL=LazyConditionalLoadOperation.js.map