@configurator/ravendb
Version:
RavenDB client for Node.js
42 lines • 1.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.IndexCreation = void 0;
const LogUtil_1 = require("../../Utility/LogUtil");
const PutIndexesOperation_1 = require("../Operations/Indexes/PutIndexesOperation");
const log = (0, LogUtil_1.getLogger)({ module: "DocumentStore" });
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_1.PutIndexesOperation(...indexesToAdd));
}
catch (err) {
log.warn(err, "Could not create indexes in one shot (maybe using older version of RavenDB ?)");
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;
}
});
}
}
exports.IndexCreation = IndexCreation;
//# sourceMappingURL=IndexCreation.js.map