Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function mockStore(remoteUserRegex = DEF_REGEX): Store {
const userStore = new UserBridgeStore(new Datastore());
const roomStore = new RoomBridgeStore(new Datastore());
return new Store({
getRoomStore: () => roomStore,
getUserStore: () => userStore,
getBot: () => ({
isRemoteUser: (u) => remoteUserRegex.exec(u) !== null,
}),
});
}
const eventStore = new NeDB({ filename: path.join(NEDB_DIRECTORY, "event-store.db"), ...config});
try {
await promisify(teamStore.loadDatabase).bind(teamStore)();
await promisify(roomStore.loadDatabase).bind(roomStore)();
await promisify(userStore.loadDatabase).bind(userStore)();
await promisify(eventStore.loadDatabase).bind(eventStore)();
} catch (ex) {
log.error("Couldn't load datastores");
log.error("Ensure you have given the correct path to the database.");
throw ex;
}
const nedb = new NedbDatastore(
new UserBridgeStore(userStore),
new RoomBridgeStore(roomStore),
new EventBridgeStore(eventStore),
teamStore,
);
try {
const startedAt = Date.now();
await migrateFromNedb(nedb, pgres);
log.info(`Completed migration in ${Math.round(Date.now() - startedAt)}ms`);
} catch (ex) {
log.error("An error occured while migrating databases:");
log.error(ex);
log.error("Your existing databases have not been modified, but you may need to drop the postgres table and start over");
}
}
getRoomStore: () => new RoomBridgeStore(new Nedb()),
getUserStore: () => new UserBridgeStore(new Nedb()),