Files
notesnook/apps/web/src/common/db.js

73 lines
2.2 KiB
JavaScript
Raw Normal View History

/*
This file is part of the Notesnook project (https://notesnook.com/)
Copyright (C) 2022 Streetwriters (Private) Limited
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2022-08-30 16:13:11 +05:00
import { EventSourcePolyfill as EventSource } from "event-source-polyfill";
2022-07-20 09:20:14 +05:00
import { NNStorage } from "../interfaces/storage";
import { logger } from "../utils/logger";
2021-02-17 01:24:20 +05:00
/**
* @type {import("@notesnook/core/api/index").default}
2021-02-17 01:24:20 +05:00
*/
var db;
2022-04-01 19:01:06 +05:00
async function initializeDatabase(persistence) {
2022-07-20 09:20:14 +05:00
logger.measure("Database initialization");
const { default: Database } = await import("@notesnook/core/api");
const { default: FS } = await import("../interfaces/fs");
db = new Database(new NNStorage("Notesnook", persistence), EventSource, FS);
// if (isTesting()) {
2022-07-07 13:29:52 +05:00
db.host({
API_HOST: "https://api.notesnook.com",
AUTH_HOST: "https://auth.streetwriters.co",
SSE_HOST: "https://events.streetwriters.co"
2022-07-07 13:29:52 +05:00
});
// } else {
// db.host({
// API_HOST: "http://localhost:5264",
// AUTH_HOST: "http://localhost:8264",
// SSE_HOST: "http://localhost:7264",
// });
2022-07-07 13:29:52 +05:00
// const base = `http://${process.env.REACT_APP_LOCALHOST}`;
// db.host({
// API_HOST: `${base}:5264`,
// AUTH_HOST: `${base}:8264`,
// SSE_HOST: `${base}:7264`,
// ISSUES_HOST: `${base}:2624`,
// SUBSCRIPTIONS_HOST: `${base}:9264`,
// });
// }
2021-04-06 11:55:23 +05:00
2022-07-20 09:20:14 +05:00
// db.eventManager.subscribe(EVENTS.databaseMigrating, async ({ from, to }) => {
// });
2022-07-07 13:29:52 +05:00
await db.init();
2022-07-20 09:20:14 +05:00
logger.measure("Database initialization");
if (db.migrations.required()) {
const { showMigrationDialog } = await import("./dialog-controller");
await showMigrationDialog();
}
return db;
2021-02-17 01:24:20 +05:00
}
export { db, initializeDatabase };