UNPKG

@configurator/ravendb

Version:
85 lines 3.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IndexDefinitionBuilder = exports.IndexDefinition = void 0; const Exceptions_1 = require("../../Exceptions"); const IndexDefinitionHelper_1 = require("./IndexDefinitionHelper"); const AbstractIndexDefinitionBuilder_1 = require("./AbstractIndexDefinitionBuilder"); const IndexDefinitionBase_1 = require("./IndexDefinitionBase"); class IndexDefinition extends IndexDefinitionBase_1.IndexDefinitionBase { constructor() { super(...arguments); this.additionalSources = {}; this.additionalAssemblies = []; this.maps = new Set(); this.fields = {}; this.configuration = {}; } toString() { return this.name; } detectStaticIndexSourceType() { if (!this.maps || !this.maps.size) { (0, Exceptions_1.throwError)("InvalidArgumentException", "Index definition contains no Maps"); } let sourceType = "None"; for (const map of this.maps) { const mapSourceType = IndexDefinitionHelper_1.IndexDefinitionHelper.detectStaticIndexSourceType(map); if (sourceType === "None") { sourceType = mapSourceType; continue; } if (sourceType !== mapSourceType) { (0, Exceptions_1.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) { (0, Exceptions_1.throwError)("InvalidArgumentException", "Index definitions contains no Maps"); } return IndexDefinitionHelper_1.IndexDefinitionHelper.detectStaticIndexType(firstMap, this.reduce); } } exports.IndexDefinition = IndexDefinition; class IndexDefinitionBuilder extends AbstractIndexDefinitionBuilder_1.AbstractIndexDefinitionBuilder { constructor(indexName) { super(indexName); } _newIndexDefinition() { return new IndexDefinition(); } toIndexDefinition(conventions, validateMap = true) { if (!this.map && validateMap) { (0, Exceptions_1.throwError)("InvalidArgumentException", "Map is required to generate an index, you cannot create an index without a valid Map property (in index " + this._indexName + ")."); } return super.toIndexDefinition(conventions, validateMap); } _toIndexDefinition(indexDefinition, conventions) { if (!this.map) { return; } indexDefinition.maps.add(this.map); } } exports.IndexDefinitionBuilder = IndexDefinitionBuilder; //# sourceMappingURL=IndexDefinition.js.map