UNPKG

ravendb

Version:
98 lines 3.58 kB
import { throwError } from "../../Exceptions/index.js"; import { IndexDefinitionHelper } from "./IndexDefinitionHelper.js"; import { AbstractIndexDefinitionBuilder } from "./AbstractIndexDefinitionBuilder.js"; import { IndexDefinitionBase } from "./IndexDefinitionBase.js"; export class IndexDefinition extends IndexDefinitionBase { /** * Index lock mode: * - Unlock - all index definition changes acceptable * - LockedIgnore - all index definition changes will be ignored, only log entry will be created * - LockedError - all index definition changes will raise exception */ lockMode; indexType; additionalSources = {}; compoundFields = []; additionalAssemblies = []; maps = new Set(); reduce; fields = {}; _indexSourceType; archivedDataProcessingBehavior; configuration = {}; outputReduceToCollection; reduceOutputIndex; patternForOutputReduceToCollectionReferences; patternReferencesCollectionName; deploymentMode; toString() { return this.name; } detectStaticIndexSourceType() { if (!this.maps || !this.maps.size) { throwError("InvalidArgumentException", "Index definition contains no Maps"); } let sourceType = "None"; for (const map of this.maps) { const mapSourceType = IndexDefinitionHelper.detectStaticIndexSourceType(map); if (sourceType === "None") { sourceType = mapSourceType; continue; } if (sourceType !== mapSourceType) { throwError("InvalidOperationException", "Index definition cannot contain maps with different source types."); } } return sourceType; } get sourceType() { if (!this._indexSourceType || this._indexSourceType === "None") { this._indexSourceType = this.detectStaticIndexSourceType(); } return this._indexSourceType; } set sourceType(value) { this._indexSourceType = value; } get type() { if (!this.indexType || this.indexType === "None") { this.indexType = this.detectStaticIndexType(); } return this.indexType; } set type(indexType) { this.indexType = indexType; } detectStaticIndexType() { const firstMap = this.maps.values().next().value; if (!firstMap) { throwError("InvalidArgumentException", "Index definitions contains no Maps"); } return IndexDefinitionHelper.detectStaticIndexType(firstMap, this.reduce); } } export class IndexDefinitionBuilder extends AbstractIndexDefinitionBuilder { map; archivedDataProcessingBehavior; constructor(indexName) { super(indexName); } _newIndexDefinition() { return new IndexDefinition(); } toIndexDefinition(conventions, validateMap = true) { if (!this.map && validateMap) { throwError("InvalidArgumentException", "Map is required to generate an index, you cannot create an index without a valid Map property (in index " + this._indexName + ")."); } const indexDefinition = super.toIndexDefinition(conventions, validateMap); indexDefinition.archivedDataProcessingBehavior = this.archivedDataProcessingBehavior; return indexDefinition; } _toIndexDefinition(indexDefinition, conventions) { if (!this.map) { return; } indexDefinition.maps.add(this.map); } } //# sourceMappingURL=IndexDefinition.js.map