ravendb
Version:
RavenDB client for Node.js
103 lines • 4 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IndexDefinitionBuilder = exports.IndexDefinition = void 0;
const index_js_1 = require("../../Exceptions/index.js");
const IndexDefinitionHelper_js_1 = require("./IndexDefinitionHelper.js");
const AbstractIndexDefinitionBuilder_js_1 = require("./AbstractIndexDefinitionBuilder.js");
const IndexDefinitionBase_js_1 = require("./IndexDefinitionBase.js");
class IndexDefinition extends IndexDefinitionBase_js_1.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) {
(0, index_js_1.throwError)("InvalidArgumentException", "Index definition contains no Maps");
}
let sourceType = "None";
for (const map of this.maps) {
const mapSourceType = IndexDefinitionHelper_js_1.IndexDefinitionHelper.detectStaticIndexSourceType(map);
if (sourceType === "None") {
sourceType = mapSourceType;
continue;
}
if (sourceType !== mapSourceType) {
(0, index_js_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, index_js_1.throwError)("InvalidArgumentException", "Index definitions contains no Maps");
}
return IndexDefinitionHelper_js_1.IndexDefinitionHelper.detectStaticIndexType(firstMap, this.reduce);
}
}
exports.IndexDefinition = IndexDefinition;
class IndexDefinitionBuilder extends AbstractIndexDefinitionBuilder_js_1.AbstractIndexDefinitionBuilder {
map;
archivedDataProcessingBehavior;
constructor(indexName) {
super(indexName);
}
_newIndexDefinition() {
return new IndexDefinition();
}
toIndexDefinition(conventions, validateMap = true) {
if (!this.map && validateMap) {
(0, index_js_1.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);
}
}
exports.IndexDefinitionBuilder = IndexDefinitionBuilder;
//# sourceMappingURL=IndexDefinition.js.map