@configurator/ravendb
Version:
RavenDB client for Node.js
60 lines • 3.44 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AbstractIndexDefinitionBuilder = void 0;
const Exceptions_1 = require("../../Exceptions");
const IndexFieldOptions_1 = require("./IndexFieldOptions");
class AbstractIndexDefinitionBuilder {
constructor(indexName) {
this._indexName = indexName || this.constructor.name;
if (this._indexName.length > 256) {
(0, Exceptions_1.throwError)("InvalidArgumentException", "The index name is limited to 256 characters, but was: " + this._indexName);
}
this.storesStrings = {};
this.indexesStrings = {};
this.suggestionsOptions = new Set();
this.analyzersStrings = {};
this.termVectorsStrings = {};
this.spatialIndexesStrings = {};
this.configuration = {};
}
toIndexDefinition(conventions, validateMap = true) {
try {
const indexDefinition = this._newIndexDefinition();
indexDefinition.name = this._indexName;
indexDefinition.reduce = this.reduce;
indexDefinition.lockMode = this.lockMode;
indexDefinition.priority = this.priority;
indexDefinition.deploymentMode = this.deploymentMode;
indexDefinition.state = this.state;
indexDefinition.outputReduceToCollection = this.outputReduceToCollection;
indexDefinition.patternForOutputReduceToCollectionReferences = this.patternForOutputReduceToCollectionReferences;
indexDefinition.patternReferencesCollectionName = this.patternReferencesCollectionName;
const suggestions = Array.from(this.suggestionsOptions)
.reduce((result, item) => Object.assign(result, { [item]: true }), {});
this._applyValues(indexDefinition, this.indexesStrings, (options, value) => options.indexing = value);
this._applyValues(indexDefinition, this.storesStrings, (options, value) => options.storage = value);
this._applyValues(indexDefinition, this.analyzersStrings, (options, value) => options.analyzer = value);
this._applyValues(indexDefinition, this.termVectorsStrings, (options, value) => options.termVector = value);
this._applyValues(indexDefinition, this.spatialIndexesStrings, (options, value) => options.spatial = value);
this._applyValues(indexDefinition, suggestions, (options, value) => options.suggestions = value);
indexDefinition.additionalSources = this.additionalSources;
indexDefinition.additionalAssemblies = this.additionalAssemblies;
indexDefinition.configuration = this.configuration;
this._toIndexDefinition(indexDefinition, conventions);
return indexDefinition;
}
catch (err) {
(0, Exceptions_1.throwError)("IndexCompilationException", "Failed to create index " + this._indexName, err);
}
}
_applyValues(indexDefinition, values, action) {
for (const fieldName of Object.keys(values)) {
const fieldVal = values[fieldName];
const field = indexDefinition.fields[fieldName] =
indexDefinition.fields[fieldName] || new IndexFieldOptions_1.IndexFieldOptions();
action(field, fieldVal);
}
}
}
exports.AbstractIndexDefinitionBuilder = AbstractIndexDefinitionBuilder;
//# sourceMappingURL=AbstractIndexDefinitionBuilder.js.map