ravendb
Version:
RavenDB client for Node.js
80 lines • 3.08 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LazyStartsWithOperation = void 0;
const GetRequest_js_1 = require("../../../Commands/MultiGet/GetRequest.js");
const GetDocumentsCommand_js_1 = require("../../../Commands/GetDocumentsCommand.js");
const StreamUtil_js_1 = require("../../../../Utility/StreamUtil.js");
const DocumentInfo_js_1 = require("../../DocumentInfo.js");
const enc = encodeURIComponent;
class LazyStartsWithOperation {
_clazz;
_idPrefix;
_matches;
_exclude;
_start;
_pageSize;
_sessionOperations;
_startAfter;
constructor(idPrefix, opts, sessionOperations) {
this._idPrefix = idPrefix;
this._matches = opts.matches;
this._exclude = opts.exclude;
this._start = opts.start;
this._pageSize = opts.pageSize;
this._sessionOperations = sessionOperations;
this._startAfter = opts.startAfter;
this._clazz = sessionOperations.conventions.getJsTypeByDocumentType(opts.documentType);
}
createRequest() {
const request = new GetRequest_js_1.GetRequest();
request.url = "/docs";
request.query =
`?startsWith=${enc(this._idPrefix)}&matches=${enc(this._matches) || ""}&exclude=${enc(this._exclude) || ""}&start=${this._start}&pageSize=${this._pageSize}&startAfter=${enc(this._startAfter)}`;
return request;
}
_result;
_queryResult;
_requiresRetry;
get result() {
return this._result;
}
set result(result) {
this._result = result;
}
get queryResult() {
return this._queryResult;
}
set queryResult(queryResult) {
this._queryResult = queryResult;
}
get requiresRetry() {
return this._requiresRetry;
}
set requiresRetry(result) {
this._requiresRetry = result;
}
async handleResponseAsync(response) {
const { results } = await GetDocumentsCommand_js_1.GetDocumentsCommand.parseDocumentsResultResponseAsync((0, StreamUtil_js_1.stringToReadable)(response.result), this._sessionOperations.conventions);
const finalResults = {};
for (const document of results) {
const newDocumentInfo = DocumentInfo_js_1.DocumentInfo.getNewDocumentInfo(document);
this._sessionOperations.documentsById.add(newDocumentInfo);
if (!newDocumentInfo.id) {
continue;
}
if (this._sessionOperations.isDeleted(newDocumentInfo.id)) {
finalResults[newDocumentInfo.id] = null;
continue;
}
const doc = this._sessionOperations.documentsById.getValue(newDocumentInfo.id);
if (doc) {
finalResults[newDocumentInfo.id] = this._sessionOperations.trackEntity(this._clazz, doc);
continue;
}
finalResults[newDocumentInfo.id] = null;
}
this.result = finalResults;
}
}
exports.LazyStartsWithOperation = LazyStartsWithOperation;
//# sourceMappingURL=LazyStartsWithOperation.js.map