UNPKG

ravendb

Version:
39 lines 1.57 kB
import { getLogger } from "../../Utility/LogUtil.js"; import { PutIndexesOperation } from "../Operations/Indexes/PutIndexesOperation.js"; const log = getLogger({ module: "DocumentStore" }); export class IndexCreation { static async createIndexes(indexes, store, conventions) { if (!conventions) { conventions = store.conventions; } try { const indexesToAdd = this.createIndexesToAdd(indexes, conventions); await store.maintenance.send(new PutIndexesOperation(...indexesToAdd)); } catch (err) { log.warn(err, "Could not create indexes in one shot (maybe using older version of RavenDB ?)"); // For old servers that don't have the new endpoint for executing multiple indexes for (const index of indexes) { await index.execute(store, conventions); } } } static createIndexesToAdd(indexCreationTasks, conventions) { return indexCreationTasks .map(x => { const oldConventions = x.conventions; try { x.conventions = conventions; const definition = x.createIndexDefinition(); definition.name = x.getIndexName(); definition.priority = x.priority || "Normal"; definition.state = x.state || "Normal"; return definition; } finally { x.conventions = oldConventions; } }); } } //# sourceMappingURL=IndexCreation.js.map