UNPKG

ravendb

Version:
93 lines 5.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractJavaScriptMultiMapIndexCreationTask = void 0; const IndexDefinition_js_1 = require("./IndexDefinition.js"); const StronglyTyped_js_1 = require("./StronglyTyped.js"); const TypeUtil_js_1 = require("../../Utility/TypeUtil.js"); const index_js_1 = require("../../Exceptions/index.js"); const StringUtil_js_1 = require("../../Utility/StringUtil.js"); const DocumentConventions_js_1 = require("../Conventions/DocumentConventions.js"); const StringBuilder_js_1 = require("../../Utility/StringBuilder.js"); const BaseJavaScriptIndexCreationTask_js_1 = require("./BaseJavaScriptIndexCreationTask.js"); const Constants_js_1 = require("../../Constants.js"); const ObjectUtil_js_1 = require("../../Utility/ObjectUtil.js"); class AbstractJavaScriptMultiMapIndexCreationTask extends BaseJavaScriptIndexCreationTask_js_1.BaseJavaScriptIndexCreationTask { _maps = []; _reduce; constructor() { super(); this.conventions = new DocumentConventions_js_1.DocumentConventions(); } /** * Register map * @param collectionOrDocumentType Collection name to index over * @param definition Index definition that maps to the indexed properties */ map(collectionOrDocumentType, definition) { const collection = TypeUtil_js_1.TypeUtil.isString(collectionOrDocumentType) ? collectionOrDocumentType : this.conventions.findCollectionName(collectionOrDocumentType); const escapedCollection = new StringBuilder_js_1.StringBuilder(); StringUtil_js_1.StringUtil.escapeString(escapedCollection, collection); const rawMap = `map('${escapedCollection.toString()}', ${definition})`; this._maps.push(this.postProcessDefinition(rawMap, "map")); } /** * Sets the index definition reduce * @param mapReduce Reduce definition */ reduce(mapReduce) { const rawReduce = mapReduce(new StronglyTyped_js_1.IndexingGroupResults()).format(); this._reduce = this.postProcessDefinition(rawReduce, "reduce"); } // eslint-disable-next-line @typescript-eslint/ban-types addSource(name, source) { this.additionalSources ??= {}; const sourceAsString = source.toString(); if (!sourceAsString.includes("function")) { (0, index_js_1.throwError)("InvalidOperationException", "Additional sources require named function. Arrow functions are not supported."); } this.additionalSources[name] = source.toString(); } /** * No implementation is required here, the interface is purely meant to expose map helper methods such as `load(id, collection)` etc */ mapUtils() { return new StronglyTyped_js_1.StubMapUtils(); } get isMapReduce() { return !!this.reduce; } createIndexDefinition() { const indexDefinitionBuilder = new IndexDefinition_js_1.IndexDefinitionBuilder(this.getIndexName()); indexDefinitionBuilder.indexesStrings = this.indexesStrings; indexDefinitionBuilder.analyzersStrings = this.analyzersStrings; indexDefinitionBuilder.reduce = this._reduce; indexDefinitionBuilder.storesStrings = this.storesStrings; indexDefinitionBuilder.suggestionsOptions = this.indexSuggestions; indexDefinitionBuilder.termVectorsStrings = this.termVectorsStrings; indexDefinitionBuilder.vectorFieldStrings = this.vectorOptionsStrings; indexDefinitionBuilder.spatialIndexesStrings = this.spatialOptionsStrings; indexDefinitionBuilder.outputReduceToCollection = this.outputReduceToCollection; indexDefinitionBuilder.patternForOutputReduceToCollectionReferences = this.patternForOutputReduceToCollectionReferences; indexDefinitionBuilder.patternReferencesCollectionName = this.patternReferencesCollectionName; indexDefinitionBuilder.additionalSources = this.additionalSources; indexDefinitionBuilder.additionalAssemblies = this.additionalAssemblies; indexDefinitionBuilder.configuration = this.configuration; indexDefinitionBuilder.lockMode = this.lockMode; indexDefinitionBuilder.priority = this.priority; indexDefinitionBuilder.state = this.state; indexDefinitionBuilder.deploymentMode = this.deploymentMode; if (this.searchEngineType) { indexDefinitionBuilder.configuration[Constants_js_1.INDEXES.INDEXING_STATIC_SEARCH_ENGINE_TYPE] = this.searchEngineType; } else if (!ObjectUtil_js_1.ObjectUtil.isEmpty(this.vectorOptionsStrings)) { indexDefinitionBuilder.configuration[Constants_js_1.INDEXES.INDEXING_STATIC_SEARCH_ENGINE_TYPE] = "Corax"; } const indexDefinition = indexDefinitionBuilder.toIndexDefinition(this.conventions, false); indexDefinition.maps = new Set(this._maps); return indexDefinition; } } exports.AbstractJavaScriptMultiMapIndexCreationTask = AbstractJavaScriptMultiMapIndexCreationTask; //# sourceMappingURL=AbstractJavaScriptMultiMapIndexCreationTask.js.map