UNPKG

@configurator/ravendb

Version:
64 lines 3.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LazySessionOperations = void 0; const LazyMultiLoaderWithInclude_1 = require("../../Loaders/LazyMultiLoaderWithInclude"); const Lazy_1 = require("../../../Lazy"); const LazyStartsWithOperation_1 = require("./LazyStartsWithOperation"); const LoadStartingWithOperation_1 = require("../LoadStartingWithOperation"); const StringUtil_1 = require("../../../../Utility/StringUtil"); const Exceptions_1 = require("../../../../Exceptions"); const LazyConditionalLoadOperation_1 = require("./LazyConditionalLoadOperation"); class LazySessionOperations { constructor(delegate) { this._delegate = delegate; } include(path) { return new LazyMultiLoaderWithInclude_1.LazyMultiLoaderWithInclude(this._delegate).include(path); } load(idOrIds, clazz) { const isMultipleIds = Array.isArray(idOrIds); if (!isMultipleIds && this._delegate.isLoaded(idOrIds)) { return new Lazy_1.Lazy(() => this._delegate.load(idOrIds, { documentType: clazz })); } const ids = isMultipleIds ? idOrIds : [idOrIds]; const result = this._delegate.lazyLoadInternal(ids, [], clazz); return isMultipleIds ? result : new Lazy_1.Lazy(async () => (await result.getValue())[idOrIds]); } loadStartingWith(idPrefix, opts) { opts = opts || null; opts = Object.assign({}, LoadStartingWithOperation_1.LoadStartingWithOperation.DEFAULT, opts); const operation = new LazyStartsWithOperation_1.LazyStartsWithOperation(idPrefix, opts, this._delegate); return this._delegate.addLazyOperation(operation); } conditionalLoad(id, changeVector, clazz) { if (StringUtil_1.StringUtil.isNullOrEmpty(id)) { (0, Exceptions_1.throwError)("InvalidArgumentException", "Id cannot be null"); } if (this._delegate.isLoaded(id)) { return new Lazy_1.Lazy(async () => { const entity = await this._delegate.load(id, clazz); if (!entity) { return { entity: null, changeVector: null }; } const cv = this._delegate.advanced.getChangeVectorFor(entity); return { entity, changeVector: cv }; }); } if (StringUtil_1.StringUtil.isNullOrEmpty(changeVector)) { (0, Exceptions_1.throwError)("InvalidArgumentException", "The requested document with id '" + id + "' is not loaded into the session and could not conditional load when changeVector is null or empty."); } const lazyLoadOperation = new LazyConditionalLoadOperation_1.LazyConditionalLoadOperation(this._delegate, id, changeVector, clazz); return this._delegate.addLazyOperation(lazyLoadOperation); } } exports.LazySessionOperations = LazySessionOperations; //# sourceMappingURL=LazySessionOperations.js.map