mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
core: make imports compatible with esm
This commit is contained in:
@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { bench, describe } from "vitest";
|
import { bench, describe } from "vitest";
|
||||||
import { databaseTest } from "../__tests__/utils";
|
import { databaseTest } from "../__tests__/utils/index.js";
|
||||||
import Database from "../src/api";
|
import Database from "../src/api/index.js";
|
||||||
|
|
||||||
async function addNotes(db: Database) {
|
async function addNotes(db: Database) {
|
||||||
const words = [
|
const words = [
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { bench, describe } from "vitest";
|
import { bench, describe } from "vitest";
|
||||||
import { databaseTest } from "../__tests__/utils";
|
import { databaseTest } from "../__tests__/utils/index.js";
|
||||||
import Database from "../src/api";
|
import Database from "../src/api/index.js";
|
||||||
|
|
||||||
async function addNotes(db: Database) {
|
async function addNotes(db: Database) {
|
||||||
const titles = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(
|
const titles = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { bench, describe } from "vitest";
|
import { bench, describe } from "vitest";
|
||||||
import { createObjectId } from "../src/utils/object-id";
|
import { createObjectId } from "../src/utils/object-id.js";
|
||||||
import boid from "bson-objectid";
|
import boid from "bson-objectid";
|
||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { bench, describe } from "vitest";
|
import { describe } from "vitest";
|
||||||
import { databaseTest } from "../__tests__/utils";
|
import { databaseTest } from "../__tests__/utils/index.js";
|
||||||
|
|
||||||
describe("relations", async () => {
|
describe("relations", async () => {
|
||||||
const db = await databaseTest();
|
const db = await databaseTest();
|
||||||
|
|||||||
@@ -18,15 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { bench, describe } from "vitest";
|
import { bench, describe } from "vitest";
|
||||||
import { databaseTest } from "../__tests__/utils";
|
import { databaseTest } from "../__tests__/utils/index.js";
|
||||||
import Database from "../src/api";
|
import Database from "../src/api/index.js";
|
||||||
import MockDate from "mockdate";
|
import MockDate from "mockdate";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { Reminder } from "../src/types";
|
import { Reminder } from "../src/types.js";
|
||||||
import {
|
import {
|
||||||
createUpcomingReminderTimeQuery,
|
createUpcomingReminderTimeQuery,
|
||||||
getUpcomingReminderTime
|
getUpcomingReminderTime
|
||||||
} from "../src/collections/reminders";
|
} from "../src/collections/reminders.js";
|
||||||
|
|
||||||
async function addReminders(db: Database) {
|
async function addReminders(db: Database) {
|
||||||
const reminders: Partial<Reminder>[] = [
|
const reminders: Partial<Reminder>[] = [
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { databaseTest, noteTest } from "../__tests__/utils";
|
import { databaseTest, noteTest } from "../__tests__/utils/index.js";
|
||||||
import { login, logout } from "./utils";
|
import { login, logout } from "./utils.js";
|
||||||
import { test, expect, afterAll } from "vitest";
|
import { test, expect, afterAll } from "vitest";
|
||||||
|
|
||||||
const TEST_TIMEOUT = 30 * 1000;
|
const TEST_TIMEOUT = 30 * 1000;
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import hosts from "../src/utils/constants";
|
import hosts from "../src/utils/constants.js";
|
||||||
import { Offers } from "../src/api/offers";
|
import { Offers } from "../src/api/offers.js";
|
||||||
import { test, expect } from "vitest";
|
import { test, expect } from "vitest";
|
||||||
|
|
||||||
test("get offer code", async () => {
|
test("get offer code", async () => {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Pricing } from "../src/api/pricing";
|
import { Pricing } from "../src/api/pricing.js";
|
||||||
import { test, expect, describe } from "vitest";
|
import { test, expect, describe } from "vitest";
|
||||||
|
|
||||||
test.each(["monthly", "yearly", undefined])(`get %s price`, async (period) => {
|
test.each(["monthly", "yearly", undefined])(`get %s price`, async (period) => {
|
||||||
|
|||||||
@@ -17,14 +17,14 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Database from "../src/api/index";
|
import Database from "../src/api/index.js";
|
||||||
import { NodeStorageInterface } from "../__mocks__/node-storage.mock";
|
import { NodeStorageInterface } from "../__mocks__/node-storage.mock.js";
|
||||||
import { FS } from "../__mocks__/fs.mock";
|
import { FS } from "../__mocks__/fs.mock.js";
|
||||||
import Compressor from "../__mocks__/compressor.mock";
|
import Compressor from "../__mocks__/compressor.mock.js";
|
||||||
import { CHECK_IDS, EV, EVENTS } from "../src/common";
|
import { CHECK_IDS, EV, EVENTS } from "../src/common.js";
|
||||||
import { EventSource } from "event-source-polyfill";
|
import { EventSource } from "event-source-polyfill";
|
||||||
import { test, expect, vitest } from "vitest";
|
import { test, expect, vitest } from "vitest";
|
||||||
import { login } from "./utils";
|
import { login } from "./utils.js";
|
||||||
import { SqliteDialect } from "@streetwriters/kysely";
|
import { SqliteDialect } from "@streetwriters/kysely";
|
||||||
import BetterSQLite3 from "better-sqlite3-multiple-ciphers";
|
import BetterSQLite3 from "better-sqlite3-multiple-ciphers";
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { databaseTest } from "../__tests__/utils";
|
import { databaseTest } from "../__tests__/utils/index.js";
|
||||||
import { login } from "./utils";
|
import { login } from "./utils.js";
|
||||||
import { test, expect } from "vitest";
|
import { test, expect } from "vitest";
|
||||||
|
|
||||||
test(
|
test(
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { authenticator } from "otplib";
|
import { authenticator } from "otplib";
|
||||||
import { databaseTest } from "../__tests__/utils";
|
import { databaseTest } from "../__tests__/utils/index.js";
|
||||||
import { login, USER } from "./utils";
|
import { login, USER } from "./utils.js";
|
||||||
import { test, expect } from "vitest";
|
import { test, expect } from "vitest";
|
||||||
|
|
||||||
// test("signup user and check for token", async () => {
|
// test("signup user and check for token", async () => {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import {
|
|||||||
FileEncryptionMetadataWithOutputType,
|
FileEncryptionMetadataWithOutputType,
|
||||||
IFileStorage,
|
IFileStorage,
|
||||||
RequestOptions
|
RequestOptions
|
||||||
} from "../src/interfaces";
|
} from "../src/interfaces.js";
|
||||||
import { xxhash64 } from "hash-wasm";
|
import { xxhash64 } from "hash-wasm";
|
||||||
import { IDataType } from "hash-wasm/dist/lib/util";
|
import { IDataType } from "hash-wasm/dist/lib/util";
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Cipher, NNCrypto, SerializedKey } from "@notesnook/crypto";
|
import { Cipher, NNCrypto, SerializedKey } from "@notesnook/crypto";
|
||||||
import { IStorage } from "../src/interfaces";
|
import { IStorage } from "../src/interfaces.js";
|
||||||
|
|
||||||
export class NodeStorageInterface implements IStorage {
|
export class NodeStorageInterface implements IStorage {
|
||||||
storage = {};
|
storage = {};
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { TEST_NOTE, databaseTest, loginFakeUser, notebookTest } from "./utils";
|
import { TEST_NOTE, databaseTest, loginFakeUser, notebookTest } from "./utils/index.js";
|
||||||
import { test, expect } from "vitest";
|
import { test, expect } from "vitest";
|
||||||
|
|
||||||
test("export backup", () =>
|
test("export backup", () =>
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Constants from "../src/utils/constants";
|
import Constants from "../src/utils/constants.js";
|
||||||
import { test, expect } from "vitest";
|
import { test, expect } from "vitest";
|
||||||
import { databaseTest } from "./utils";
|
import { databaseTest } from "./utils/index.js";
|
||||||
|
|
||||||
test("db.host should change HOST", () =>
|
test("db.host should change HOST", () =>
|
||||||
databaseTest().then((db) => {
|
databaseTest().then((db) => {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { expect, test } from "vitest";
|
import { expect, test } from "vitest";
|
||||||
import { databaseTest, noteTest } from "./utils";
|
import { databaseTest, noteTest } from "./utils/index.js";
|
||||||
|
|
||||||
test("updating deleted content should not throw", () =>
|
test("updating deleted content should not throw", () =>
|
||||||
databaseTest().then(async (db) => {
|
databaseTest().then(async (db) => {
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { describe, it, expect } from "vitest";
|
import { describe, it, expect } from "vitest";
|
||||||
import { initialize, logManager, logger } from "../src/logger";
|
import { initialize, logManager, logger } from "../src/logger.js";
|
||||||
import { SqliteDialect } from "@streetwriters/kysely";
|
import { SqliteDialect } from "@streetwriters/kysely";
|
||||||
import BetterSQLite3 from "better-sqlite3-multiple-ciphers";
|
import BetterSQLite3 from "better-sqlite3-multiple-ciphers";
|
||||||
import { NoopLogger } from "@notesnook/logger";
|
import { NoopLogger } from "@notesnook/logger";
|
||||||
import { delay } from "./utils";
|
import { delay } from "./utils/index.js";
|
||||||
|
|
||||||
async function initializeLogger() {
|
async function initializeLogger() {
|
||||||
await initialize(
|
await initialize(
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import {
|
|||||||
notebookTest,
|
notebookTest,
|
||||||
TEST_NOTEBOOK2,
|
TEST_NOTEBOOK2,
|
||||||
databaseTest
|
databaseTest
|
||||||
} from "./utils";
|
} from "./utils/index.js";
|
||||||
import { test, expect } from "vitest";
|
import { test, expect } from "vitest";
|
||||||
|
|
||||||
const content = {
|
const content = {
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { test, expect, describe } from "vitest";
|
import { test, expect, describe } from "vitest";
|
||||||
import { migrateItem, migrateKV, migrateVaultKey } from "../src/migrations";
|
import { migrateItem, migrateKV, migrateVaultKey } from "../src/migrations.js";
|
||||||
import { databaseTest } from "./utils";
|
import { databaseTest } from "./utils/index.js";
|
||||||
import { getId, makeId } from "../src/utils/id";
|
import { getId, makeId } from "../src/utils/id.js";
|
||||||
import { DeletedItem, LegacySettingsItem } from "../src/types";
|
import { DeletedItem, LegacySettingsItem } from "../src/types.js";
|
||||||
import { KEYS } from "../src/database/kv";
|
import { KEYS } from "../src/database/kv.js";
|
||||||
|
|
||||||
describe.concurrent("[5.2] replace date edited with date modified", () => {
|
describe.concurrent("[5.2] replace date edited with date modified", () => {
|
||||||
const itemsWithDateEdited = ["note", "notebook", "trash", "tiny"] as const;
|
const itemsWithDateEdited = ["note", "notebook", "trash", "tiny"] as const;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { delay, noteTest, TEST_NOTE } from "./utils";
|
import { delay, noteTest, TEST_NOTE } from "./utils/index.js";
|
||||||
import { test, expect } from "vitest";
|
import { test, expect } from "vitest";
|
||||||
|
|
||||||
// async function sessionTest(db, noteId) {
|
// async function sessionTest(db, noteId) {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { notebookTest, TEST_NOTEBOOK } from "./utils";
|
import { notebookTest, TEST_NOTEBOOK } from "./utils/index.js";
|
||||||
import { test, expect } from "vitest";
|
import { test, expect } from "vitest";
|
||||||
|
|
||||||
test("add a notebook", () =>
|
test("add a notebook", () =>
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import Database from "../src/api";
|
import Database from "../src/api/index.js";
|
||||||
import { createKeySelector, groupArray } from "../src/utils/grouping";
|
import { createKeySelector, groupArray } from "../src/utils/grouping.js";
|
||||||
import {
|
import {
|
||||||
databaseTest,
|
databaseTest,
|
||||||
noteTest,
|
noteTest,
|
||||||
@@ -27,10 +27,9 @@ import {
|
|||||||
TEST_NOTEBOOK,
|
TEST_NOTEBOOK,
|
||||||
IMG_CONTENT,
|
IMG_CONTENT,
|
||||||
loginFakeUser
|
loginFakeUser
|
||||||
} from "./utils";
|
} from "./utils/index.js";
|
||||||
import { test, expect } from "vitest";
|
import { test, expect } from "vitest";
|
||||||
import { MONTHS_FULL } from "../src/utils/date";
|
import { GroupOptions, Note } from "../src/types.js";
|
||||||
import { GroupOptions, Note } from "../src/types";
|
|
||||||
|
|
||||||
async function createAndAddNoteToNotebook(
|
async function createAndAddNoteToNotebook(
|
||||||
db: Database,
|
db: Database,
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ import {
|
|||||||
formatReminderTime,
|
formatReminderTime,
|
||||||
getUpcomingReminderTime,
|
getUpcomingReminderTime,
|
||||||
isReminderActive
|
isReminderActive
|
||||||
} from "../src/collections/reminders";
|
} from "../src/collections/reminders.js";
|
||||||
import MockDate from "mockdate";
|
import MockDate from "mockdate";
|
||||||
import { describe, afterAll, beforeEach, test, expect } from "vitest";
|
import { describe, afterAll, beforeEach, test, expect } from "vitest";
|
||||||
import { databaseTest } from "./utils";
|
import { databaseTest } from "./utils/index.js";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { databaseTest } from "./utils";
|
import { databaseTest } from "./utils/index.js";
|
||||||
import { test, expect } from "vitest";
|
import { test, expect } from "vitest";
|
||||||
|
|
||||||
test("save group options", () =>
|
test("save group options", () =>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { databaseTest, notebookTest } from "./utils";
|
import { databaseTest, notebookTest } from "./utils/index.js";
|
||||||
import { test, expect } from "vitest";
|
import { test, expect } from "vitest";
|
||||||
|
|
||||||
test("create a shortcut of an invalid item should throw", () =>
|
test("create a shortcut of an invalid item should throw", () =>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { NodeStorageInterface } from "../__mocks__/node-storage.mock";
|
import { NodeStorageInterface } from "../__mocks__/node-storage.mock.js";
|
||||||
import { test, expect } from "vitest";
|
import { test, expect } from "vitest";
|
||||||
|
|
||||||
test("add a value", async () => {
|
test("add a value", async () => {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { databaseTest, noteTest, TEST_NOTE } from "./utils";
|
import { databaseTest, noteTest, TEST_NOTE } from "./utils/index.js";
|
||||||
import { test, expect } from "vitest";
|
import { test, expect } from "vitest";
|
||||||
|
|
||||||
function tag(title: string) {
|
function tag(title: string) {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import {
|
|||||||
TEST_NOTE,
|
TEST_NOTE,
|
||||||
TEST_NOTEBOOK,
|
TEST_NOTEBOOK,
|
||||||
databaseTest
|
databaseTest
|
||||||
} from "./utils";
|
} from "./utils/index.js";
|
||||||
import { test, expect } from "vitest";
|
import { test, expect } from "vitest";
|
||||||
|
|
||||||
test("trash should be empty", () =>
|
test("trash should be empty", () =>
|
||||||
|
|||||||
@@ -17,19 +17,19 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import DB from "../../src/api";
|
import DB from "../../src/api/index.js";
|
||||||
import { NodeStorageInterface } from "../../__mocks__/node-storage.mock";
|
import { NodeStorageInterface } from "../../__mocks__/node-storage.mock.js";
|
||||||
import { FS } from "../../__mocks__/fs.mock";
|
import { FS } from "../../__mocks__/fs.mock.js";
|
||||||
import Compressor from "../../__mocks__/compressor.mock";
|
import Compressor from "../../__mocks__/compressor.mock.js";
|
||||||
import { EventSourcePolyfill as EventSource } from "event-source-polyfill";
|
import { EventSourcePolyfill as EventSource } from "event-source-polyfill";
|
||||||
import { randomBytes } from "../../src/utils/random";
|
import { randomBytes } from "../../src/utils/random.js";
|
||||||
import { Note, Notebook } from "../../src/types";
|
import { Note, Notebook } from "../../src/types.js";
|
||||||
import { NoteContent } from "../../src/collections/session-content";
|
import { NoteContent } from "../../src/collections/session-content.js";
|
||||||
import { SqliteDialect } from "@streetwriters/kysely";
|
import { SqliteDialect } from "@streetwriters/kysely";
|
||||||
import BetterSQLite3 from "better-sqlite3-multiple-ciphers";
|
import BetterSQLite3 from "better-sqlite3-multiple-ciphers";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { tmpdir } from "os";
|
import { tmpdir } from "os";
|
||||||
import { getId } from "../../src/utils/id";
|
import { getId } from "../../src/utils/id.js";
|
||||||
import { existsSync, mkdirSync } from "fs";
|
import { existsSync, mkdirSync } from "fs";
|
||||||
|
|
||||||
const TEST_NOTEBOOK: Partial<Notebook> = {
|
const TEST_NOTEBOOK: Partial<Notebook> = {
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { VAULT_ERRORS } from "../src/api/vault";
|
import { VAULT_ERRORS } from "../src/api/vault.js";
|
||||||
import { databaseTest, delay, noteTest, TEST_NOTE } from "./utils";
|
import { databaseTest, delay, noteTest, TEST_NOTE } from "./utils/index.js";
|
||||||
import { test, expect } from "vitest";
|
import { test, expect } from "vitest";
|
||||||
|
|
||||||
test("create vault", () =>
|
test("create vault", () =>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Debug } from "../debug";
|
import { Debug } from "../debug.js";
|
||||||
import createFetchMock from "vitest-fetch-mock";
|
import createFetchMock from "vitest-fetch-mock";
|
||||||
import { vi, test, expect } from "vitest";
|
import { vi, test, expect } from "vitest";
|
||||||
const fetchMocker = createFetchMock(vi);
|
const fetchMocker = createFetchMock(vi);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { HealthCheck, check } from "../healthcheck";
|
import { HealthCheck, check } from "../healthcheck.js";
|
||||||
import { describe } from "vitest";
|
import { describe } from "vitest";
|
||||||
|
|
||||||
describe.concurrent("Health check", (test) => {
|
describe.concurrent("Health check", (test) => {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import hosts from "../utils/constants";
|
import hosts from "../utils/constants.js";
|
||||||
|
|
||||||
export class Debug {
|
export class Debug {
|
||||||
static async report(reportData: {
|
static async report(reportData: {
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import hosts from "../utils/constants";
|
import hosts from "../utils/constants.js";
|
||||||
import http from "../utils/http";
|
import http from "../utils/http.js";
|
||||||
|
|
||||||
export class HealthCheck {
|
export class HealthCheck {
|
||||||
static async auth() {
|
static async auth() {
|
||||||
|
|||||||
@@ -17,38 +17,38 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Notes } from "../collections/notes";
|
import { Notes } from "../collections/notes.js";
|
||||||
import { Crypto, CryptoAccessor } from "../database/crypto";
|
import { Crypto, CryptoAccessor } from "../utils/crypto.js";
|
||||||
import { FileStorage, FileStorageAccessor } from "../database/fs";
|
import { FileStorage, FileStorageAccessor } from "../database/fs.js";
|
||||||
import { Notebooks } from "../collections/notebooks";
|
import { Notebooks } from "../collections/notebooks.js";
|
||||||
import Trash from "../collections/trash";
|
import Trash from "../collections/trash.js";
|
||||||
import Sync, { SyncOptions } from "./sync";
|
import Sync, { SyncOptions } from "./sync/index.js";
|
||||||
import { Tags } from "../collections/tags";
|
import { Tags } from "../collections/tags.js";
|
||||||
import { Colors } from "../collections/colors";
|
import { Colors } from "../collections/colors.js";
|
||||||
import Vault from "./vault";
|
import Vault from "./vault.js";
|
||||||
import Lookup from "./lookup";
|
import Lookup from "./lookup.js";
|
||||||
import { Content } from "../collections/content";
|
import { Content } from "../collections/content.js";
|
||||||
import Backup from "../database/backup";
|
import Backup from "../database/backup.js";
|
||||||
import Hosts from "../utils/constants";
|
import Hosts from "../utils/constants.js";
|
||||||
import { EV, EVENTS } from "../common";
|
import { EV, EVENTS } from "../common.js";
|
||||||
import { LegacySettings } from "../collections/legacy-settings";
|
import { LegacySettings } from "../collections/legacy-settings.js";
|
||||||
import Migrations from "./migrations";
|
import Migrations from "./migrations.js";
|
||||||
import UserManager from "./user-manager";
|
import UserManager from "./user-manager.js";
|
||||||
import http from "../utils/http";
|
import http from "../utils/http.js";
|
||||||
import { Monographs } from "./monographs";
|
import { Monographs } from "./monographs.js";
|
||||||
import { Offers } from "./offers";
|
import { Offers } from "./offers.js";
|
||||||
import { Attachments } from "../collections/attachments";
|
import { Attachments } from "../collections/attachments.js";
|
||||||
import { Debug } from "./debug";
|
import { Debug } from "./debug.js";
|
||||||
import { Mutex } from "async-mutex";
|
import { Mutex } from "async-mutex";
|
||||||
import { NoteHistory } from "../collections/note-history";
|
import { NoteHistory } from "../collections/note-history.js";
|
||||||
import MFAManager from "./mfa-manager";
|
import MFAManager from "./mfa-manager.js";
|
||||||
import EventManager from "../utils/event-manager";
|
import EventManager from "../utils/event-manager.js";
|
||||||
import { Pricing } from "./pricing";
|
import { Pricing } from "./pricing.js";
|
||||||
import { logger } from "../logger";
|
import { logger } from "../logger.js";
|
||||||
import { Shortcuts } from "../collections/shortcuts";
|
import { Shortcuts } from "../collections/shortcuts.js";
|
||||||
import { Reminders } from "../collections/reminders";
|
import { Reminders } from "../collections/reminders.js";
|
||||||
import { Relations } from "../collections/relations";
|
import { Relations } from "../collections/relations.js";
|
||||||
import Subscriptions from "./subscriptions";
|
import Subscriptions from "./subscriptions.js";
|
||||||
import {
|
import {
|
||||||
CompressorAccessor,
|
CompressorAccessor,
|
||||||
ConfigStorageAccessor,
|
ConfigStorageAccessor,
|
||||||
@@ -57,10 +57,10 @@ import {
|
|||||||
IStorage,
|
IStorage,
|
||||||
KVStorageAccessor,
|
KVStorageAccessor,
|
||||||
StorageAccessor
|
StorageAccessor
|
||||||
} from "../interfaces";
|
} from "../interfaces.js";
|
||||||
import TokenManager from "./token-manager";
|
import TokenManager from "./token-manager.js";
|
||||||
import { Attachment } from "../types";
|
import { Attachment } from "../types.js";
|
||||||
import { Settings } from "../collections/settings";
|
import { Settings } from "../collections/settings.js";
|
||||||
import {
|
import {
|
||||||
DatabaseAccessor,
|
DatabaseAccessor,
|
||||||
DatabaseSchema,
|
DatabaseSchema,
|
||||||
@@ -69,16 +69,16 @@ import {
|
|||||||
changeDatabasePassword,
|
changeDatabasePassword,
|
||||||
createDatabase,
|
createDatabase,
|
||||||
initializeDatabase
|
initializeDatabase
|
||||||
} from "../database";
|
} from "../database/index.js";
|
||||||
import { Kysely, Transaction, sql } from "@streetwriters/kysely";
|
import { Kysely, Transaction, sql } from "@streetwriters/kysely";
|
||||||
import { CachedCollection } from "../database/cached-collection";
|
import { CachedCollection } from "../database/cached-collection.js";
|
||||||
import { Vaults } from "../collections/vaults";
|
import { Vaults } from "../collections/vaults.js";
|
||||||
import { KVStorage } from "../database/kv";
|
import { KVStorage } from "../database/kv.js";
|
||||||
import { QueueValue } from "../utils/queue-value";
|
import { QueueValue } from "../utils/queue-value.js";
|
||||||
import { Sanitizer } from "../database/sanitizer";
|
import { Sanitizer } from "../database/sanitizer.js";
|
||||||
import { createTriggers, dropTriggers } from "../database/triggers";
|
import { createTriggers, dropTriggers } from "../database/triggers.js";
|
||||||
import { NNMigrationProvider } from "../database/migrations";
|
import { NNMigrationProvider } from "../database/migrations.js";
|
||||||
import { ConfigStorage } from "../database/config";
|
import { ConfigStorage } from "../database/config.js";
|
||||||
|
|
||||||
type EventSourceConstructor = new (
|
type EventSourceConstructor = new (
|
||||||
uri: string,
|
uri: string,
|
||||||
|
|||||||
@@ -18,15 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { match } from "fuzzyjs";
|
import { match } from "fuzzyjs";
|
||||||
import Database from ".";
|
import Database from "./index.js";
|
||||||
import { Item, Note, TrashItem } from "../types";
|
import { Item, Note, TrashItem } from "../types.js";
|
||||||
import { DatabaseSchema, RawDatabaseSchema } from "../database";
|
import { DatabaseSchema, RawDatabaseSchema } from "../database/index.js";
|
||||||
import { AnyColumnWithTable, Kysely, sql } from "@streetwriters/kysely";
|
import { AnyColumnWithTable, Kysely, sql } from "@streetwriters/kysely";
|
||||||
import { FilteredSelector } from "../database/sql-collection";
|
import { FilteredSelector } from "../database/sql-collection.js";
|
||||||
import { VirtualizedGrouping } from "../utils/virtualized-grouping";
|
import { VirtualizedGrouping } from "../utils/virtualized-grouping.js";
|
||||||
import { logger } from "../logger";
|
import { logger } from "../logger.js";
|
||||||
import { rebuildSearchIndex } from "../database/fts";
|
import { rebuildSearchIndex } from "../database/fts.js";
|
||||||
import { transformQuery } from "../utils/query-transformer";
|
import { transformQuery } from "../utils/query-transformer.js";
|
||||||
|
|
||||||
type SearchResults<T> = {
|
type SearchResults<T> = {
|
||||||
sorted: (limit?: number) => Promise<VirtualizedGrouping<T>>;
|
sorted: (limit?: number) => Promise<VirtualizedGrouping<T>>;
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import http from "../utils/http";
|
import http from "../utils/http.js";
|
||||||
import constants from "../utils/constants";
|
import constants from "../utils/constants.js";
|
||||||
import TokenManager from "./token-manager";
|
import TokenManager from "./token-manager.js";
|
||||||
|
|
||||||
const ENDPOINTS = {
|
const ENDPOINTS = {
|
||||||
setup: "/mfa",
|
setup: "/mfa",
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Database from ".";
|
import Database from "./index.js";
|
||||||
import { CURRENT_DATABASE_VERSION } from "../common";
|
import { CURRENT_DATABASE_VERSION } from "../common.js";
|
||||||
import Migrator, { MigratableCollections } from "../database/migrator";
|
import Migrator, { MigratableCollections } from "../database/migrator.js";
|
||||||
|
|
||||||
const collections: MigratableCollections = [
|
const collections: MigratableCollections = [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,13 +17,13 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import http from "../utils/http";
|
import http from "../utils/http.js";
|
||||||
import Constants from "../utils/constants";
|
import Constants from "../utils/constants.js";
|
||||||
import Database from ".";
|
import Database from "./index.js";
|
||||||
import { Note, isDeleted } from "../types";
|
import { Note, isDeleted } from "../types.js";
|
||||||
import { Cipher } from "@notesnook/crypto";
|
import { Cipher } from "@notesnook/crypto";
|
||||||
import { isFalse } from "../database";
|
import { isFalse } from "../database/index.js";
|
||||||
import { logger } from "../logger";
|
import { logger } from "../logger.js";
|
||||||
|
|
||||||
type BaseMonograph = {
|
type BaseMonograph = {
|
||||||
id: string;
|
id: string;
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { CLIENT_ID } from "../common";
|
import { CLIENT_ID } from "../common.js";
|
||||||
import hosts from "../utils/constants";
|
import hosts from "../utils/constants.js";
|
||||||
import http from "../utils/http";
|
import http from "../utils/http.js";
|
||||||
|
|
||||||
export class Offers {
|
export class Offers {
|
||||||
static async getCode(promo: string, platform: "ios" | "android" | "web") {
|
static async getCode(promo: string, platform: "ios" | "android" | "web") {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import http from "../utils/http";
|
import http from "../utils/http.js";
|
||||||
|
|
||||||
export type Product = {
|
export type Product = {
|
||||||
country: string;
|
country: string;
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import hosts from "../utils/constants";
|
import hosts from "../utils/constants.js";
|
||||||
import http from "../utils/http";
|
import http from "../utils/http.js";
|
||||||
import TokenManager from "./token-manager";
|
import TokenManager from "./token-manager.js";
|
||||||
|
|
||||||
export type TransactionStatus =
|
export type TransactionStatus =
|
||||||
| "completed"
|
| "completed"
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ import {
|
|||||||
databaseTest,
|
databaseTest,
|
||||||
TEST_NOTE,
|
TEST_NOTE,
|
||||||
loginFakeUser
|
loginFakeUser
|
||||||
} from "../../../../__tests__/utils";
|
} from "../../../../__tests__/utils/index.js";
|
||||||
import Collector from "../collector";
|
import Collector from "../collector.js";
|
||||||
import { test, expect } from "vitest";
|
import { test, expect } from "vitest";
|
||||||
|
|
||||||
test("newly created note should get included in collector", () =>
|
test("newly created note should get included in collector", () =>
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ import {
|
|||||||
TEST_NOTE,
|
TEST_NOTE,
|
||||||
databaseTest,
|
databaseTest,
|
||||||
loginFakeUser
|
loginFakeUser
|
||||||
} from "../../../../__tests__/utils";
|
} from "../../../../__tests__/utils/index.js";
|
||||||
import { expect, describe, vi } from "vitest";
|
import { expect, describe, vi } from "vitest";
|
||||||
import Merger from "../merger";
|
import Merger from "../merger.js";
|
||||||
|
|
||||||
describe.concurrent("merge item synchronously", (test) => {
|
describe.concurrent("merge item synchronously", (test) => {
|
||||||
test("accept remote item if no local item is found", () =>
|
test("accept remote item if no local item is found", () =>
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Database from "..";
|
import Database from "../index.js";
|
||||||
import { EVENTS } from "../../common";
|
import { EVENTS } from "../../common.js";
|
||||||
import { DatabaseUpdatedEvent } from "../../database";
|
import { DatabaseUpdatedEvent } from "../../database/index.js";
|
||||||
import { logger } from "../../logger";
|
import { logger } from "../../logger.js";
|
||||||
|
|
||||||
export class AutoSync {
|
export class AutoSync {
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
|
|||||||
@@ -17,17 +17,17 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Cipher, SerializedKey } from "@notesnook/crypto";
|
import { Cipher } from "@notesnook/crypto";
|
||||||
import Database from "..";
|
import Database from "../index.js";
|
||||||
import { CURRENT_DATABASE_VERSION, EV, EVENTS } from "../../common";
|
import { CURRENT_DATABASE_VERSION, EV, EVENTS } from "../../common.js";
|
||||||
import { logger } from "../../logger";
|
import { logger } from "../../logger.js";
|
||||||
import {
|
import {
|
||||||
SyncItem,
|
SyncItem,
|
||||||
SyncTransferItem,
|
SyncTransferItem,
|
||||||
SYNC_COLLECTIONS_MAP,
|
SYNC_COLLECTIONS_MAP,
|
||||||
SYNC_ITEM_TYPES
|
SYNC_ITEM_TYPES
|
||||||
} from "./types";
|
} from "./types.js";
|
||||||
import { Item, MaybeDeletedItem } from "../../types";
|
import { Item, MaybeDeletedItem } from "../../types.js";
|
||||||
|
|
||||||
class Collector {
|
class Collector {
|
||||||
logger = logger.scope("SyncCollector");
|
logger = logger.scope("SyncCollector");
|
||||||
|
|||||||
@@ -17,11 +17,11 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { KVStorageAccessor } from "../../interfaces";
|
import { KVStorageAccessor } from "../../interfaces.js";
|
||||||
import hosts from "../../utils/constants";
|
import hosts from "../../utils/constants.js";
|
||||||
import http from "../../utils/http";
|
import http from "../../utils/http.js";
|
||||||
import { getId } from "../../utils/id";
|
import { getId } from "../../utils/id.js";
|
||||||
import TokenManager from "../token-manager";
|
import TokenManager from "../token-manager.js";
|
||||||
|
|
||||||
export class SyncDevices {
|
export class SyncDevices {
|
||||||
constructor(
|
constructor(
|
||||||
|
|||||||
@@ -24,17 +24,17 @@ import {
|
|||||||
EVENTS,
|
EVENTS,
|
||||||
sendSyncProgressEvent,
|
sendSyncProgressEvent,
|
||||||
SYNC_CHECK_IDS
|
SYNC_CHECK_IDS
|
||||||
} from "../../common";
|
} from "../../common.js";
|
||||||
import Constants from "../../utils/constants";
|
import Constants from "../../utils/constants.js";
|
||||||
import TokenManager from "../token-manager";
|
import TokenManager from "../token-manager.js";
|
||||||
import Collector from "./collector";
|
import Collector from "./collector.js";
|
||||||
import * as signalr from "@microsoft/signalr";
|
import * as signalr from "@microsoft/signalr";
|
||||||
import Merger from "./merger";
|
import Merger from "./merger.js";
|
||||||
import { AutoSync } from "./auto-sync";
|
import { AutoSync } from "./auto-sync.js";
|
||||||
import { logger } from "../../logger";
|
import { logger } from "../../logger.js";
|
||||||
import { Mutex } from "async-mutex";
|
import { Mutex } from "async-mutex";
|
||||||
import Database from "..";
|
import Database from "../index.js";
|
||||||
import { migrateItem, migrateVaultKey } from "../../migrations";
|
import { migrateItem, migrateVaultKey } from "../../migrations.js";
|
||||||
import { SerializedKey } from "@notesnook/crypto";
|
import { SerializedKey } from "@notesnook/crypto";
|
||||||
import {
|
import {
|
||||||
Attachment,
|
Attachment,
|
||||||
@@ -44,15 +44,15 @@ import {
|
|||||||
MaybeDeletedItem,
|
MaybeDeletedItem,
|
||||||
Note,
|
Note,
|
||||||
Notebook
|
Notebook
|
||||||
} from "../../types";
|
} from "../../types.js";
|
||||||
import {
|
import {
|
||||||
SYNC_COLLECTIONS_MAP,
|
SYNC_COLLECTIONS_MAP,
|
||||||
SyncableItemType,
|
SyncableItemType,
|
||||||
SyncTransferItem
|
SyncTransferItem
|
||||||
} from "./types";
|
} from "./types.js";
|
||||||
import { DownloadableFile } from "../../database/fs";
|
import { DownloadableFile } from "../../database/fs.js";
|
||||||
import { SyncDevices } from "./devices";
|
import { SyncDevices } from "./devices.js";
|
||||||
import { DefaultColors } from "../../collections/colors";
|
import { DefaultColors } from "../../collections/colors.js";
|
||||||
|
|
||||||
export type SyncOptions = {
|
export type SyncOptions = {
|
||||||
type: "full" | "fetch" | "send";
|
type: "full" | "fetch" | "send";
|
||||||
@@ -61,9 +61,12 @@ export type SyncOptions = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default class SyncManager {
|
export default class SyncManager {
|
||||||
sync = new Sync(this.db);
|
sync;
|
||||||
devices = this.sync.devices;
|
devices;
|
||||||
constructor(private readonly db: Database) {}
|
constructor(private readonly db: Database) {
|
||||||
|
this.sync = new Sync(db);
|
||||||
|
this.devices = this.sync.devices;
|
||||||
|
}
|
||||||
|
|
||||||
async start(options: SyncOptions) {
|
async start(options: SyncOptions) {
|
||||||
try {
|
try {
|
||||||
@@ -114,17 +117,22 @@ export default class SyncManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Sync {
|
class Sync {
|
||||||
collector = new Collector(this.db);
|
collector;
|
||||||
merger = new Merger(this.db);
|
merger;
|
||||||
autoSync = new AutoSync(this.db, 1000);
|
autoSync;
|
||||||
logger = logger.scope("Sync");
|
logger = logger.scope("Sync");
|
||||||
syncConnectionMutex = new Mutex();
|
syncConnectionMutex = new Mutex();
|
||||||
connection?: signalr.HubConnection;
|
connection?: signalr.HubConnection;
|
||||||
devices = new SyncDevices(this.db.kv, this.db.tokenManager);
|
devices;
|
||||||
private conflictedNoteIds: string[] = [];
|
private conflictedNoteIds: string[] = [];
|
||||||
private uncachedAttachments: DownloadableFile[] = [];
|
private uncachedAttachments: DownloadableFile[] = [];
|
||||||
|
|
||||||
constructor(private readonly db: Database) {
|
constructor(private readonly db: Database) {
|
||||||
|
this.collector = new Collector(db);
|
||||||
|
this.merger = new Merger(db);
|
||||||
|
this.autoSync = new AutoSync(db, 1000);
|
||||||
|
this.devices = new SyncDevices(db.kv, db.tokenManager);
|
||||||
|
|
||||||
EV.subscribe(EVENTS.userLoggedOut, async () => {
|
EV.subscribe(EVENTS.userLoggedOut, async () => {
|
||||||
await this.connection?.stop();
|
await this.connection?.stop();
|
||||||
this.autoSync.stop();
|
this.autoSync.stop();
|
||||||
|
|||||||
@@ -17,16 +17,16 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { logger } from "../../logger";
|
import { logger } from "../../logger.js";
|
||||||
import { isHTMLEqual } from "../../utils/html-diff";
|
import { isHTMLEqual } from "../../utils/html-diff.js";
|
||||||
import Database from "..";
|
import Database from "../index.js";
|
||||||
import {
|
import {
|
||||||
Attachment,
|
Attachment,
|
||||||
ContentItem,
|
ContentItem,
|
||||||
Item,
|
Item,
|
||||||
MaybeDeletedItem,
|
MaybeDeletedItem,
|
||||||
isDeleted
|
isDeleted
|
||||||
} from "../../types";
|
} from "../../types.js";
|
||||||
|
|
||||||
const THRESHOLD = process.env.NODE_ENV === "test" ? 6 * 1000 : 60 * 1000;
|
const THRESHOLD = process.env.NODE_ENV === "test" ? 6 * 1000 : 60 * 1000;
|
||||||
class Merger {
|
class Merger {
|
||||||
|
|||||||
@@ -17,12 +17,12 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import http from "../utils/http";
|
import http from "../utils/http.js";
|
||||||
import constants from "../utils/constants";
|
import constants from "../utils/constants.js";
|
||||||
import { EV, EVENTS } from "../common";
|
import { EV, EVENTS } from "../common.js";
|
||||||
import { withTimeout, Mutex } from "async-mutex";
|
import { withTimeout, Mutex } from "async-mutex";
|
||||||
import { logger } from "../logger";
|
import { logger } from "../logger.js";
|
||||||
import { KVStorageAccessor } from "../interfaces";
|
import { KVStorageAccessor } from "../interfaces.js";
|
||||||
|
|
||||||
export type Token = {
|
export type Token = {
|
||||||
access_token: string;
|
access_token: string;
|
||||||
|
|||||||
@@ -17,15 +17,15 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { User } from "../types";
|
import { User } from "../types.js";
|
||||||
import http from "../utils/http";
|
import http from "../utils/http.js";
|
||||||
import constants from "../utils/constants";
|
import constants from "../utils/constants.js";
|
||||||
import TokenManager from "./token-manager";
|
import TokenManager from "./token-manager.js";
|
||||||
import { EV, EVENTS } from "../common";
|
import { EV, EVENTS } from "../common.js";
|
||||||
import { HealthCheck } from "./healthcheck";
|
import { HealthCheck } from "./healthcheck.js";
|
||||||
import Database from ".";
|
import Database from "./index.js";
|
||||||
import { SerializedKey } from "@notesnook/crypto";
|
import { SerializedKey } from "@notesnook/crypto";
|
||||||
import { logger } from "../logger";
|
import { logger } from "../logger.js";
|
||||||
|
|
||||||
const ENDPOINTS = {
|
const ENDPOINTS = {
|
||||||
signup: "/users",
|
signup: "/users",
|
||||||
|
|||||||
@@ -18,12 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Cipher } from "@notesnook/crypto";
|
import { Cipher } from "@notesnook/crypto";
|
||||||
import Database from ".";
|
import Database from "./index.js";
|
||||||
import { CHECK_IDS, EV, EVENTS, checkIsUserPremium } from "../common";
|
import { CHECK_IDS, EV, EVENTS, checkIsUserPremium } from "../common.js";
|
||||||
import { isCipher } from "../database/crypto";
|
import { isCipher } from "../utils/crypto.js";
|
||||||
import { NoteContent } from "../collections/session-content";
|
import { Note, NoteContent } from "../types.js";
|
||||||
import { Note } from "../types";
|
import { logger } from "../logger.js";
|
||||||
import { logger } from "../logger";
|
|
||||||
|
|
||||||
export const VAULT_ERRORS = {
|
export const VAULT_ERRORS = {
|
||||||
noVault: "ERR_NO_VAULT",
|
noVault: "ERR_NO_VAULT",
|
||||||
|
|||||||
@@ -17,20 +17,23 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ICollection } from "./collection";
|
import { ICollection } from "./collection.js";
|
||||||
import { getId } from "../utils/id";
|
import { getId } from "../utils/id.js";
|
||||||
import { EV, EVENTS } from "../common";
|
import { EV, EVENTS } from "../common.js";
|
||||||
import dataurl from "../utils/dataurl";
|
import dataurl from "../utils/dataurl.js";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { DocumentMimeTypes, getFileNameWithExtension } from "../utils/filename";
|
import {
|
||||||
|
DocumentMimeTypes,
|
||||||
|
getFileNameWithExtension
|
||||||
|
} from "../utils/filename.js";
|
||||||
import { Cipher, DataFormat, SerializedKey } from "@notesnook/crypto";
|
import { Cipher, DataFormat, SerializedKey } from "@notesnook/crypto";
|
||||||
import { Output } from "../interfaces";
|
import { Output } from "../interfaces.js";
|
||||||
import { Attachment } from "../types";
|
import { Attachment } from "../types.js";
|
||||||
import Database from "../api";
|
import Database from "../api/index.js";
|
||||||
import { FilteredSelector, SQLCollection } from "../database/sql-collection";
|
import { FilteredSelector, SQLCollection } from "../database/sql-collection.js";
|
||||||
import { isFalse } from "../database";
|
import { isFalse } from "../database/index.js";
|
||||||
import { sql } from "@streetwriters/kysely";
|
import { sql } from "@streetwriters/kysely";
|
||||||
import { logger } from "../logger";
|
import { logger } from "../logger.js";
|
||||||
|
|
||||||
export class Attachments implements ICollection {
|
export class Attachments implements ICollection {
|
||||||
name = "attachments";
|
name = "attachments";
|
||||||
|
|||||||
@@ -17,14 +17,14 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ICollection } from "./collection";
|
import { ICollection } from "./collection.js";
|
||||||
import { getId } from "../utils/id";
|
import { getId } from "../utils/id.js";
|
||||||
import { Color } from "../types";
|
import { Color } from "../types.js";
|
||||||
import Database from "../api";
|
import Database from "../api/index.js";
|
||||||
import { Tags } from "./tags";
|
import { sanitizeTag } from "./tags.js";
|
||||||
import { SQLCollection } from "../database/sql-collection";
|
import { SQLCollection } from "../database/sql-collection.js";
|
||||||
import { isFalse } from "../database";
|
import { isFalse } from "../database/index.js";
|
||||||
import { CHECK_IDS, checkIsUserPremium } from "../common";
|
import { CHECK_IDS, checkIsUserPremium } from "../common.js";
|
||||||
|
|
||||||
export const DefaultColors: Record<string, string> = {
|
export const DefaultColors: Record<string, string> = {
|
||||||
red: "#f44336",
|
red: "#f44336",
|
||||||
@@ -70,7 +70,7 @@ export class Colors implements ICollection {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
async add(item: Partial<Color>) {
|
async add(item: Partial<Color>) {
|
||||||
item.title = item.title ? Tags.sanitize(item.title) : item.title;
|
item.title = item.title ? sanitizeTag(item.title) : item.title;
|
||||||
const oldColor = item.id
|
const oldColor = item.id
|
||||||
? await this.color(item.id)
|
? await this.color(item.id)
|
||||||
: item.colorCode
|
: item.colorCode
|
||||||
|
|||||||
@@ -17,25 +17,25 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ICollection } from "./collection";
|
import { ICollection } from "./collection.js";
|
||||||
import { getId } from "../utils/id";
|
import { getId } from "../utils/id.js";
|
||||||
import { getContentFromData } from "../content-types";
|
import { getContentFromData } from "../content-types/index.js";
|
||||||
import { isCipher } from "../database/crypto";
|
import { isCipher } from "../utils/crypto.js";
|
||||||
import {
|
import {
|
||||||
ContentItem,
|
ContentItem,
|
||||||
ContentType,
|
ContentType,
|
||||||
UnencryptedContentItem,
|
UnencryptedContentItem,
|
||||||
isDeleted
|
isDeleted,
|
||||||
} from "../types";
|
NoteContent
|
||||||
import Database from "../api";
|
} from "../types.js";
|
||||||
import { getOutputType } from "./attachments";
|
import Database from "../api/index.js";
|
||||||
import { SQLCollection } from "../database/sql-collection";
|
import { getOutputType } from "./attachments.js";
|
||||||
import { NoteContent } from "./session-content";
|
import { SQLCollection } from "../database/sql-collection.js";
|
||||||
import { InternalLink } from "../utils/internal-link";
|
import { InternalLink } from "../utils/internal-link.js";
|
||||||
import { tinyToTiptap } from "../migrations";
|
import { tinyToTiptap } from "../migrations.js";
|
||||||
import { EVENTS } from "../common";
|
import { EVENTS } from "../common.js";
|
||||||
import { DeleteEvent, UpdateEvent } from "../database";
|
import { DeleteEvent, UpdateEvent } from "../database/index.js";
|
||||||
import { logger } from "../logger";
|
import { logger } from "../logger.js";
|
||||||
|
|
||||||
export const EMPTY_CONTENT = (noteId: string): UnencryptedContentItem => ({
|
export const EMPTY_CONTENT = (noteId: string): UnencryptedContentItem => ({
|
||||||
noteId,
|
noteId,
|
||||||
@@ -419,15 +419,3 @@ export class Content implements ICollection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isDecryptedContent(
|
|
||||||
content: NoteContent<boolean>
|
|
||||||
): content is NoteContent<false> {
|
|
||||||
return !isCipher(content.data);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isEncryptedContent(
|
|
||||||
content: NoteContent<boolean>
|
|
||||||
): content is NoteContent<true> {
|
|
||||||
return isCipher(content.data);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getId } from "../utils/id";
|
import { getId } from "../utils/id.js";
|
||||||
import Database from "../api";
|
import Database from "../api/index.js";
|
||||||
import { LegacySettingsItem } from "../types";
|
import { LegacySettingsItem } from "../types.js";
|
||||||
import { ICollection } from "./collection";
|
import { ICollection } from "./collection.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated only kept here for migration purposes
|
* @deprecated only kept here for migration purposes
|
||||||
|
|||||||
@@ -17,20 +17,21 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Database from "../api";
|
import Database from "../api/index.js";
|
||||||
import { isCipher } from "../database/crypto";
|
import { isCipher } from "../utils/crypto.js";
|
||||||
import { FilteredSelector, SQLCollection } from "../database/sql-collection";
|
import { FilteredSelector, SQLCollection } from "../database/sql-collection.js";
|
||||||
import { HistorySession, isDeleted } from "../types";
|
import { HistorySession, isDeleted, NoteContent } from "../types.js";
|
||||||
import { makeSessionContentId } from "../utils/id";
|
import { makeSessionContentId } from "../utils/id.js";
|
||||||
import { ICollection } from "./collection";
|
import { ICollection } from "./collection.js";
|
||||||
import { NoteContent, SessionContent } from "./session-content";
|
import { SessionContent } from "./session-content.js";
|
||||||
|
|
||||||
export class NoteHistory implements ICollection {
|
export class NoteHistory implements ICollection {
|
||||||
name = "notehistory";
|
name = "notehistory";
|
||||||
versionsLimit = 100;
|
versionsLimit = 100;
|
||||||
sessionContent = new SessionContent(this.db);
|
sessionContent;
|
||||||
readonly collection: SQLCollection<"notehistory", HistorySession>;
|
readonly collection: SQLCollection<"notehistory", HistorySession>;
|
||||||
constructor(private readonly db: Database) {
|
constructor(private readonly db: Database) {
|
||||||
|
this.sessionContent = new SessionContent(db);
|
||||||
this.collection = new SQLCollection(
|
this.collection = new SQLCollection(
|
||||||
db.sql,
|
db.sql,
|
||||||
db.transaction,
|
db.transaction,
|
||||||
|
|||||||
@@ -17,15 +17,15 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getId } from "../utils/id";
|
import { getId } from "../utils/id.js";
|
||||||
import Database from "../api";
|
import Database from "../api/index.js";
|
||||||
import { Notebook, TrashOrItem, isTrashItem } from "../types";
|
import { Notebook, TrashOrItem, isTrashItem } from "../types.js";
|
||||||
import { ICollection } from "./collection";
|
import { ICollection } from "./collection.js";
|
||||||
import { SQLCollection } from "../database/sql-collection";
|
import { SQLCollection } from "../database/sql-collection.js";
|
||||||
import { isFalse } from "../database";
|
import { isFalse } from "../database/index.js";
|
||||||
import { sql } from "@streetwriters/kysely";
|
import { sql } from "@streetwriters/kysely";
|
||||||
import { deleteItems } from "../utils/array";
|
import { deleteItems } from "../utils/array.js";
|
||||||
import { CHECK_IDS, checkIsUserPremium } from "../common";
|
import { CHECK_IDS, checkIsUserPremium } from "../common.js";
|
||||||
|
|
||||||
export class Notebooks implements ICollection {
|
export class Notebooks implements ICollection {
|
||||||
name = "notebooks";
|
name = "notebooks";
|
||||||
|
|||||||
@@ -17,20 +17,25 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getId } from "../utils/id";
|
import { getId } from "../utils/id.js";
|
||||||
import { getContentFromData } from "../content-types";
|
import { getContentFromData } from "../content-types/index.js";
|
||||||
import { NEWLINE_STRIP_REGEX, formatTitle } from "../utils/title-format";
|
import { NEWLINE_STRIP_REGEX, formatTitle } from "../utils/title-format.js";
|
||||||
import { clone } from "../utils/clone";
|
import { clone } from "../utils/clone.js";
|
||||||
import { Tiptap } from "../content-types/tiptap";
|
import { Tiptap } from "../content-types/tiptap.js";
|
||||||
import { EMPTY_CONTENT } from "./content";
|
import { EMPTY_CONTENT } from "./content.js";
|
||||||
import { buildFromTemplate } from "../utils/templates";
|
import { buildFromTemplate } from "../utils/templates/index.js";
|
||||||
import { Note, TrashOrItem, isTrashItem, isDeleted } from "../types";
|
import {
|
||||||
import Database from "../api";
|
Note,
|
||||||
import { ICollection } from "./collection";
|
TrashOrItem,
|
||||||
import { NoteContent } from "./session-content";
|
isTrashItem,
|
||||||
import { SQLCollection } from "../database/sql-collection";
|
isDeleted,
|
||||||
import { isFalse } from "../database";
|
NoteContent
|
||||||
import { logger } from "../logger";
|
} from "../types.js";
|
||||||
|
import Database from "../api/index.js";
|
||||||
|
import { ICollection } from "./collection.js";
|
||||||
|
import { SQLCollection } from "../database/sql-collection.js";
|
||||||
|
import { isFalse } from "../database/index.js";
|
||||||
|
import { logger } from "../logger.js";
|
||||||
|
|
||||||
export type ExportOptions = {
|
export type ExportOptions = {
|
||||||
format: "html" | "md" | "txt" | "md-frontmatter";
|
format: "html" | "md" | "txt" | "md-frontmatter";
|
||||||
|
|||||||
@@ -17,20 +17,20 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { makeId } from "../utils/id";
|
import { makeId } from "../utils/id.js";
|
||||||
import { ICollection } from "./collection";
|
import { ICollection } from "./collection.js";
|
||||||
import {
|
import {
|
||||||
Relation,
|
Relation,
|
||||||
ItemMap,
|
ItemMap,
|
||||||
ItemReference,
|
ItemReference,
|
||||||
ItemReferences,
|
ItemReferences,
|
||||||
ValueOf
|
ValueOf
|
||||||
} from "../types";
|
} from "../types.js";
|
||||||
import Database from "../api";
|
import Database from "../api/index.js";
|
||||||
import { FilteredSelector, SQLCollection } from "../database/sql-collection";
|
import { FilteredSelector, SQLCollection } from "../database/sql-collection.js";
|
||||||
import { DatabaseSchema, UnlinkEvent, isFalse } from "../database";
|
import { DatabaseSchema, UnlinkEvent, isFalse } from "../database/index.js";
|
||||||
import { SelectQueryBuilder } from "@streetwriters/kysely";
|
import { SelectQueryBuilder } from "@streetwriters/kysely";
|
||||||
import { EVENTS } from "../common";
|
import { EVENTS } from "../common.js";
|
||||||
|
|
||||||
export class Relations implements ICollection {
|
export class Relations implements ICollection {
|
||||||
name = "relations";
|
name = "relations";
|
||||||
|
|||||||
@@ -18,17 +18,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import isSameOrBefore from "dayjs/plugin/isSameOrBefore";
|
import isSameOrBefore from "dayjs/plugin/isSameOrBefore.js";
|
||||||
import isToday from "dayjs/plugin/isToday";
|
import isToday from "dayjs/plugin/isToday.js";
|
||||||
import isTomorrow from "dayjs/plugin/isTomorrow";
|
import isTomorrow from "dayjs/plugin/isTomorrow.js";
|
||||||
import isYesterday from "dayjs/plugin/isYesterday";
|
import isYesterday from "dayjs/plugin/isYesterday.js";
|
||||||
import { TimeFormat, formatDate } from "../utils/date";
|
import { formatDate } from "../utils/date.js";
|
||||||
import { getId } from "../utils/id";
|
import { getId } from "../utils/id.js";
|
||||||
import { ICollection } from "./collection";
|
import { ICollection } from "./collection.js";
|
||||||
import { Reminder } from "../types";
|
import { Reminder, TimeFormat } from "../types.js";
|
||||||
import Database from "../api";
|
import Database from "../api/index.js";
|
||||||
import { SQLCollection } from "../database/sql-collection";
|
import { SQLCollection } from "../database/sql-collection.js";
|
||||||
import { isFalse } from "../database";
|
import { isFalse } from "../database/index.js";
|
||||||
import { sql } from "@streetwriters/kysely";
|
import { sql } from "@streetwriters/kysely";
|
||||||
|
|
||||||
dayjs.extend(isTomorrow);
|
dayjs.extend(isTomorrow);
|
||||||
|
|||||||
@@ -17,19 +17,13 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Cipher } from "@notesnook/crypto";
|
import { tinyToTiptap } from "../migrations.js";
|
||||||
import { tinyToTiptap } from "../migrations";
|
import { makeSessionContentId } from "../utils/id.js";
|
||||||
import { makeSessionContentId } from "../utils/id";
|
import { ICollection } from "./collection.js";
|
||||||
import { ICollection } from "./collection";
|
import { isCipher } from "../utils/crypto.js";
|
||||||
import { isCipher } from "../database/crypto";
|
import Database from "../api/index.js";
|
||||||
import Database from "../api";
|
import { NoteContent, SessionContentItem, isDeleted } from "../types.js";
|
||||||
import { ContentType, SessionContentItem, isDeleted } from "../types";
|
import { SQLCollection } from "../database/sql-collection.js";
|
||||||
import { SQLCollection } from "../database/sql-collection";
|
|
||||||
|
|
||||||
export type NoteContent<TLocked extends boolean> = {
|
|
||||||
data: TLocked extends true ? Cipher<"base64"> : string;
|
|
||||||
type: ContentType;
|
|
||||||
};
|
|
||||||
|
|
||||||
export class SessionContent implements ICollection {
|
export class SessionContent implements ICollection {
|
||||||
name = "sessioncontent";
|
name = "sessioncontent";
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { makeId } from "../utils/id";
|
import { makeId } from "../utils/id.js";
|
||||||
import Database from "../api";
|
import Database from "../api/index.js";
|
||||||
import {
|
import {
|
||||||
GroupOptions,
|
GroupOptions,
|
||||||
GroupingKey,
|
GroupingKey,
|
||||||
@@ -29,11 +29,11 @@ import {
|
|||||||
SideBarSection,
|
SideBarSection,
|
||||||
ToolbarConfig,
|
ToolbarConfig,
|
||||||
ToolbarConfigPlatforms,
|
ToolbarConfigPlatforms,
|
||||||
TrashCleanupInterval
|
TrashCleanupInterval,
|
||||||
} from "../types";
|
TimeFormat
|
||||||
import { ICollection } from "./collection";
|
} from "../types.js";
|
||||||
import { TimeFormat } from "../utils/date";
|
import { ICollection } from "./collection.js";
|
||||||
import { SQLCachedCollection } from "../database/sql-cached-collection";
|
import { SQLCachedCollection } from "../database/sql-cached-collection.js";
|
||||||
|
|
||||||
const DEFAULT_GROUP_OPTIONS = (key: GroupingKey) =>
|
const DEFAULT_GROUP_OPTIONS = (key: GroupingKey) =>
|
||||||
({
|
({
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Database from "../api";
|
import Database from "../api/index.js";
|
||||||
import { SQLCachedCollection } from "../database/sql-cached-collection";
|
import { SQLCachedCollection } from "../database/sql-cached-collection.js";
|
||||||
import { Notebook, Shortcut, Tag } from "../types";
|
import { Notebook, Shortcut, Tag } from "../types.js";
|
||||||
import { ICollection } from "./collection";
|
import { ICollection } from "./collection.js";
|
||||||
|
|
||||||
type ResolveTypeToItem<T extends "notebooks" | "tags" | "all"> =
|
type ResolveTypeToItem<T extends "notebooks" | "tags" | "all"> =
|
||||||
T extends "tags"
|
T extends "tags"
|
||||||
|
|||||||
@@ -17,14 +17,14 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getId } from "../utils/id";
|
import { getId } from "../utils/id.js";
|
||||||
import { Tag } from "../types";
|
import { Tag } from "../types.js";
|
||||||
import Database from "../api";
|
import Database from "../api/index.js";
|
||||||
import { ICollection } from "./collection";
|
import { ICollection } from "./collection.js";
|
||||||
import { SQLCollection } from "../database/sql-collection";
|
import { SQLCollection } from "../database/sql-collection.js";
|
||||||
import { isFalse } from "../database";
|
import { isFalse } from "../database/index.js";
|
||||||
import { sql } from "@streetwriters/kysely";
|
import { sql } from "@streetwriters/kysely";
|
||||||
import { CHECK_IDS, checkIsUserPremium } from "../common";
|
import { CHECK_IDS, checkIsUserPremium } from "../common.js";
|
||||||
|
|
||||||
export class Tags implements ICollection {
|
export class Tags implements ICollection {
|
||||||
name = "tags";
|
name = "tags";
|
||||||
@@ -52,7 +52,7 @@ export class Tags implements ICollection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async add(item: Partial<Tag> & { title: string }) {
|
async add(item: Partial<Tag> & { title: string }) {
|
||||||
item.title = Tags.sanitize(item.title);
|
item.title = sanitizeTag(item.title);
|
||||||
|
|
||||||
const oldTag = item.id ? await this.tag(item.id) : undefined;
|
const oldTag = item.id ? await this.tag(item.id) : undefined;
|
||||||
|
|
||||||
@@ -103,8 +103,8 @@ export class Tags implements ICollection {
|
|||||||
exists(id: string) {
|
exists(id: string) {
|
||||||
return this.collection.exists(id);
|
return this.collection.exists(id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
static sanitize(title: string) {
|
|
||||||
return title.replace(/^\s+|\s+$/gm, "");
|
export function sanitizeTag(title: string) {
|
||||||
}
|
return title.replace(/^\s+|\s+$/gm, "");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,17 +18,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import Database from "../api";
|
import Database from "../api/index.js";
|
||||||
import { deleteItems, toChunks } from "../utils/array";
|
import { deleteItems, toChunks } from "../utils/array.js";
|
||||||
import { GroupOptions, TrashItem } from "../types";
|
import { GroupOptions, TrashItem } from "../types.js";
|
||||||
import { VirtualizedGrouping } from "../utils/virtualized-grouping";
|
import { VirtualizedGrouping } from "../utils/virtualized-grouping.js";
|
||||||
import {
|
import {
|
||||||
createKeySelector,
|
createKeySelector,
|
||||||
getSortSelectors,
|
getSortSelectors,
|
||||||
groupArray
|
groupArray
|
||||||
} from "../utils/grouping";
|
} from "../utils/grouping.js";
|
||||||
import { sql } from "@streetwriters/kysely";
|
import { sql } from "@streetwriters/kysely";
|
||||||
import { MAX_SQL_PARAMETERS } from "../database/sql-collection";
|
import { MAX_SQL_PARAMETERS } from "../database/sql-collection.js";
|
||||||
|
|
||||||
export default class Trash {
|
export default class Trash {
|
||||||
collections = ["notes", "notebooks"] as const;
|
collections = ["notes", "notebooks"] as const;
|
||||||
|
|||||||
@@ -17,12 +17,12 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Database from "../api";
|
import Database from "../api/index.js";
|
||||||
import { ItemReference, Vault } from "../types";
|
import { ItemReference, Vault } from "../types.js";
|
||||||
import { ICollection } from "./collection";
|
import { ICollection } from "./collection.js";
|
||||||
import { SQLCollection } from "../database/sql-collection";
|
import { SQLCollection } from "../database/sql-collection.js";
|
||||||
import { getId } from "../utils/id";
|
import { getId } from "../utils/id.js";
|
||||||
import { isFalse } from "../database";
|
import { isFalse } from "../database/index.js";
|
||||||
|
|
||||||
export class Vaults implements ICollection {
|
export class Vaults implements ICollection {
|
||||||
name = "vaults";
|
name = "vaults";
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import EventManager from "./utils/event-manager";
|
import EventManager from "./utils/event-manager.js";
|
||||||
|
|
||||||
export const EV = new EventManager();
|
export const EV = new EventManager();
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
import {
|
import {
|
||||||
IMG_CONTENT,
|
IMG_CONTENT,
|
||||||
IMG_CONTENT_WITHOUT_HASH
|
IMG_CONTENT_WITHOUT_HASH
|
||||||
} from "../../../__tests__/utils";
|
} from "../../../__tests__/utils/index.js";
|
||||||
import { Tiptap } from "../tiptap";
|
import { Tiptap } from "../tiptap.js";
|
||||||
import { test, expect } from "vitest";
|
import { test, expect } from "vitest";
|
||||||
|
|
||||||
test("img src is empty after extract attachments", async () => {
|
test("img src is empty after extract attachments", async () => {
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ContentType } from "../types";
|
import { ContentType } from "../types.js";
|
||||||
import { Tiptap } from "./tiptap";
|
import { Tiptap } from "./tiptap.js";
|
||||||
|
|
||||||
export function getContentFromData(type: ContentType, data: string) {
|
export function getContentFromData(type: ContentType, data: string) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -30,3 +30,5 @@ export function getContentFromData(type: ContentType, data: string) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export * from "./tiptap.js";
|
||||||
|
|||||||
@@ -27,22 +27,22 @@ import {
|
|||||||
} from "html-to-text";
|
} from "html-to-text";
|
||||||
import { BlockTextBuilder } from "html-to-text/lib/block-text-builder";
|
import { BlockTextBuilder } from "html-to-text/lib/block-text-builder";
|
||||||
import { parseDocument } from "htmlparser2";
|
import { parseDocument } from "htmlparser2";
|
||||||
import dataurl from "../utils/dataurl";
|
import dataurl from "../utils/dataurl.js";
|
||||||
import {
|
import {
|
||||||
HTMLParser,
|
HTMLParser,
|
||||||
extractFirstParagraph,
|
extractFirstParagraph,
|
||||||
getDummyDocument
|
getDummyDocument
|
||||||
} from "../utils/html-parser";
|
} from "../utils/html-parser.js";
|
||||||
import { HTMLRewriter } from "../utils/html-rewriter";
|
import { HTMLRewriter } from "../utils/html-rewriter.js";
|
||||||
import { ContentBlock } from "../types";
|
import { ContentBlock } from "../types.js";
|
||||||
import {
|
import {
|
||||||
InternalLink,
|
InternalLink,
|
||||||
isInternalLink,
|
isInternalLink,
|
||||||
parseInternalLink
|
parseInternalLink
|
||||||
} from "../utils/internal-link";
|
} from "../utils/internal-link.js";
|
||||||
import { Element } from "domhandler";
|
import { Element } from "domhandler";
|
||||||
import { render } from "dom-serializer";
|
import { render } from "dom-serializer";
|
||||||
import { logger } from "../logger";
|
import { logger } from "../logger.js";
|
||||||
|
|
||||||
export type ResolveHashes = (
|
export type ResolveHashes = (
|
||||||
hashes: string[]
|
hashes: string[]
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ import {
|
|||||||
isDeleted
|
isDeleted
|
||||||
} from "../types.js";
|
} from "../types.js";
|
||||||
import { Cipher, SerializedKey } from "@notesnook/crypto";
|
import { Cipher, SerializedKey } from "@notesnook/crypto";
|
||||||
import { isCipher } from "./crypto.js";
|
import { isCipher } from "../utils/crypto.js";
|
||||||
import { migrateItem } from "../migrations";
|
import { migrateItem } from "../migrations.js";
|
||||||
import { DatabaseCollection } from "./index.js";
|
import { DatabaseCollection } from "./index.js";
|
||||||
import { DefaultColors } from "../collections/colors.js";
|
import { DefaultColors } from "../collections/colors.js";
|
||||||
import { toChunks } from "../utils/array.js";
|
import { toChunks } from "../utils/array.js";
|
||||||
|
|||||||
@@ -17,15 +17,15 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { IndexedCollection } from "./indexed-collection";
|
import { IndexedCollection } from "./indexed-collection.js";
|
||||||
import {
|
import {
|
||||||
CollectionType,
|
CollectionType,
|
||||||
Collections,
|
Collections,
|
||||||
ItemMap,
|
ItemMap,
|
||||||
MaybeDeletedItem,
|
MaybeDeletedItem,
|
||||||
isDeleted
|
isDeleted
|
||||||
} from "../types";
|
} from "../types.js";
|
||||||
import { StorageAccessor } from "../interfaces";
|
import { StorageAccessor } from "../interfaces.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated only kept here for migration purposes
|
* @deprecated only kept here for migration purposes
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { DatabaseAccessor, RawDatabaseSchema } from ".";
|
import { DatabaseAccessor, RawDatabaseSchema } from "./index.js";
|
||||||
|
|
||||||
export class ConfigStorage {
|
export class ConfigStorage {
|
||||||
private readonly db: DatabaseAccessor<RawDatabaseSchema>;
|
private readonly db: DatabaseAccessor<RawDatabaseSchema>;
|
||||||
|
|||||||
@@ -17,15 +17,15 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import hosts from "../utils/constants";
|
import hosts from "../utils/constants.js";
|
||||||
import TokenManager from "../api/token-manager";
|
import TokenManager from "../api/token-manager.js";
|
||||||
import {
|
import {
|
||||||
FileEncryptionMetadataWithOutputType,
|
FileEncryptionMetadataWithOutputType,
|
||||||
IFileStorage
|
IFileStorage
|
||||||
} from "../interfaces";
|
} from "../interfaces.js";
|
||||||
import { DataFormat, SerializedKey } from "@notesnook/crypto/dist/src/types";
|
import { DataFormat, SerializedKey } from "@notesnook/crypto";
|
||||||
import { EV, EVENTS } from "../common";
|
import { EV, EVENTS } from "../common.js";
|
||||||
import { logger } from "../logger";
|
import { logger } from "../logger.js";
|
||||||
|
|
||||||
export type FileStorageAccessor = () => FileStorage;
|
export type FileStorageAccessor = () => FileStorage;
|
||||||
export type DownloadableFile = {
|
export type DownloadableFile = {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Kysely, sql } from "@streetwriters/kysely";
|
import { Kysely, sql } from "@streetwriters/kysely";
|
||||||
import { RawDatabaseSchema } from ".";
|
import { RawDatabaseSchema } from "./index.js";
|
||||||
|
|
||||||
export async function rebuildSearchIndex(db: Kysely<RawDatabaseSchema>) {
|
export async function rebuildSearchIndex(db: Kysely<RawDatabaseSchema>) {
|
||||||
await db.transaction().execute(async (tx) => {
|
await db.transaction().execute(async (tx) => {
|
||||||
|
|||||||
@@ -58,8 +58,8 @@ import {
|
|||||||
ValueOf,
|
ValueOf,
|
||||||
Vault,
|
Vault,
|
||||||
isDeleted
|
isDeleted
|
||||||
} from "../types";
|
} from "../types.js";
|
||||||
import { logger } from "../logger";
|
import { logger } from "../logger.js";
|
||||||
|
|
||||||
// type FilteredKeys<T, U> = {
|
// type FilteredKeys<T, U> = {
|
||||||
// [P in keyof T]: T[P] extends U ? P : never;
|
// [P in keyof T]: T[P] extends U ? P : never;
|
||||||
|
|||||||
@@ -17,15 +17,15 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { toChunks } from "../utils/array";
|
import { toChunks } from "../utils/array.js";
|
||||||
import { StorageAccessor } from "../interfaces";
|
import { StorageAccessor } from "../interfaces.js";
|
||||||
import {
|
import {
|
||||||
CollectionType,
|
CollectionType,
|
||||||
Collections,
|
Collections,
|
||||||
ItemMap,
|
ItemMap,
|
||||||
MaybeDeletedItem
|
MaybeDeletedItem
|
||||||
} from "../types";
|
} from "../types.js";
|
||||||
import Indexer from "./indexer";
|
import Indexer from "./indexer.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated only kept here for migration purposes
|
* @deprecated only kept here for migration purposes
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { StorageAccessor } from "../interfaces";
|
import { StorageAccessor } from "../interfaces.js";
|
||||||
import { MaybeDeletedItem } from "../types";
|
import { MaybeDeletedItem } from "../types.js";
|
||||||
|
|
||||||
export default class Indexer<T> {
|
export default class Indexer<T> {
|
||||||
private _indices: string[] = [];
|
private _indices: string[] = [];
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { DatabaseAccessor, RawDatabaseSchema } from ".";
|
import { DatabaseAccessor, RawDatabaseSchema } from "./index.js";
|
||||||
import { Token } from "../api/token-manager";
|
import { Token } from "../api/token-manager.js";
|
||||||
import { User } from "../types";
|
import { User } from "../types.js";
|
||||||
|
|
||||||
interface KV {
|
interface KV {
|
||||||
v: number;
|
v: number;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import {
|
|||||||
MigrationProvider,
|
MigrationProvider,
|
||||||
sql
|
sql
|
||||||
} from "@streetwriters/kysely";
|
} from "@streetwriters/kysely";
|
||||||
import { rebuildSearchIndex } from "./fts";
|
import { rebuildSearchIndex } from "./fts.js";
|
||||||
|
|
||||||
const COLLATE_NOCASE: ColumnBuilderCallback = (col) =>
|
const COLLATE_NOCASE: ColumnBuilderCallback = (col) =>
|
||||||
col.modifyEnd(sql`collate nocase`);
|
col.modifyEnd(sql`collate nocase`);
|
||||||
|
|||||||
@@ -18,18 +18,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Cipher } from "@notesnook/crypto";
|
import { Cipher } from "@notesnook/crypto";
|
||||||
import { DatabaseSchema } from ".";
|
import { DatabaseSchema } from "./index.js";
|
||||||
import Database from "../api";
|
import Database from "../api/index.js";
|
||||||
import {
|
import {
|
||||||
CURRENT_DATABASE_VERSION,
|
CURRENT_DATABASE_VERSION,
|
||||||
sendMigrationProgressEvent
|
sendMigrationProgressEvent
|
||||||
} from "../common";
|
} from "../common.js";
|
||||||
import {
|
import {
|
||||||
migrateCollection,
|
migrateCollection,
|
||||||
migrateItem,
|
migrateItem,
|
||||||
migrateKV,
|
migrateKV,
|
||||||
migrateVaultKey
|
migrateVaultKey
|
||||||
} from "../migrations";
|
} from "../migrations.js";
|
||||||
import {
|
import {
|
||||||
CollectionType,
|
CollectionType,
|
||||||
Collections,
|
Collections,
|
||||||
@@ -38,10 +38,10 @@ import {
|
|||||||
MaybeDeletedItem,
|
MaybeDeletedItem,
|
||||||
isDeleted,
|
isDeleted,
|
||||||
isTrashItem
|
isTrashItem
|
||||||
} from "../types";
|
} from "../types.js";
|
||||||
import { IndexedCollection } from "./indexed-collection";
|
import { IndexedCollection } from "./indexed-collection.js";
|
||||||
import { SQLCollection } from "./sql-collection";
|
import { SQLCollection } from "./sql-collection.js";
|
||||||
import { logger } from "../logger";
|
import { logger } from "../logger.js";
|
||||||
|
|
||||||
export type RawItem = MaybeDeletedItem<Item>;
|
export type RawItem = MaybeDeletedItem<Item>;
|
||||||
type MigratableCollection = {
|
type MigratableCollection = {
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { DatabaseAccessor } from ".";
|
import { DatabaseAccessor } from "./index.js";
|
||||||
import { logger } from "../logger";
|
import { logger } from "../logger.js";
|
||||||
|
|
||||||
export class Sanitizer {
|
export class Sanitizer {
|
||||||
tables: Record<string, Set<string>> = {};
|
tables: Record<string, Set<string>> = {};
|
||||||
|
|||||||
@@ -17,12 +17,12 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { MaybeDeletedItem, isDeleted } from "../types";
|
import { MaybeDeletedItem, isDeleted } from "../types.js";
|
||||||
import EventManager from "../utils/event-manager";
|
import EventManager from "../utils/event-manager.js";
|
||||||
import { DatabaseAccessor, DatabaseCollection, DatabaseSchema } from ".";
|
import { DatabaseAccessor, DatabaseCollection, DatabaseSchema } from "./index.js";
|
||||||
import { SQLCollection } from "./sql-collection";
|
import { SQLCollection } from "./sql-collection.js";
|
||||||
import { Kysely } from "@streetwriters/kysely";
|
import { Kysely } from "@streetwriters/kysely";
|
||||||
import { Sanitizer } from "./sanitizer";
|
import { Sanitizer } from "./sanitizer.js";
|
||||||
|
|
||||||
export class SQLCachedCollection<
|
export class SQLCachedCollection<
|
||||||
TCollectionType extends keyof DatabaseSchema,
|
TCollectionType extends keyof DatabaseSchema,
|
||||||
|
|||||||
@@ -17,15 +17,15 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { EVENTS } from "../common";
|
import { EVENTS } from "../common.js";
|
||||||
import {
|
import {
|
||||||
GroupOptions,
|
GroupOptions,
|
||||||
Item,
|
Item,
|
||||||
MaybeDeletedItem,
|
MaybeDeletedItem,
|
||||||
SortOptions,
|
SortOptions,
|
||||||
isDeleted
|
isDeleted
|
||||||
} from "../types";
|
} from "../types.js";
|
||||||
import EventManager from "../utils/event-manager";
|
import EventManager from "../utils/event-manager.js";
|
||||||
import {
|
import {
|
||||||
DatabaseAccessor,
|
DatabaseAccessor,
|
||||||
DatabaseCollection,
|
DatabaseCollection,
|
||||||
@@ -35,7 +35,7 @@ import {
|
|||||||
UpdateEvent,
|
UpdateEvent,
|
||||||
UpsertEvent,
|
UpsertEvent,
|
||||||
isFalse
|
isFalse
|
||||||
} from ".";
|
} from "./index.js";
|
||||||
import {
|
import {
|
||||||
AliasedRawBuilder,
|
AliasedRawBuilder,
|
||||||
AnyColumn,
|
AnyColumn,
|
||||||
@@ -46,14 +46,14 @@ import {
|
|||||||
SqlBool,
|
SqlBool,
|
||||||
sql
|
sql
|
||||||
} from "@streetwriters/kysely";
|
} from "@streetwriters/kysely";
|
||||||
import { VirtualizedGrouping } from "../utils/virtualized-grouping";
|
import { VirtualizedGrouping } from "../utils/virtualized-grouping.js";
|
||||||
import { createKeySelector, groupArray } from "../utils/grouping";
|
import { createKeySelector, groupArray } from "../utils/grouping.js";
|
||||||
import { toChunks } from "../utils/array";
|
import { toChunks } from "../utils/array.js";
|
||||||
import { Sanitizer } from "./sanitizer";
|
import { Sanitizer } from "./sanitizer.js";
|
||||||
import {
|
import {
|
||||||
createIsReminderActiveQuery,
|
createIsReminderActiveQuery,
|
||||||
createUpcomingReminderTimeQuery
|
createUpcomingReminderTimeQuery
|
||||||
} from "../collections/reminders";
|
} from "../collections/reminders.js";
|
||||||
|
|
||||||
const formats = {
|
const formats = {
|
||||||
month: "%Y-%m",
|
month: "%Y-%m",
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Kysely, sql } from "@streetwriters/kysely";
|
import { Kysely, sql } from "@streetwriters/kysely";
|
||||||
import { DatabaseSchema, RawDatabaseSchema } from ".";
|
import { DatabaseSchema, RawDatabaseSchema } from "./index.js";
|
||||||
|
|
||||||
export async function createTriggers(db: Kysely<RawDatabaseSchema>) {
|
export async function createTriggers(db: Kysely<RawDatabaseSchema>) {
|
||||||
// content triggers
|
// content triggers
|
||||||
|
|||||||
@@ -17,19 +17,29 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * from "./types";
|
export * from "./types.js";
|
||||||
export { VirtualizedGrouping } from "./utils/virtualized-grouping";
|
export * from "./interfaces.js";
|
||||||
export { DefaultColors } from "./collections/colors";
|
export * from "./utils/index.js";
|
||||||
export { type BackupFile, type LegacyBackupFile } from "./database/backup";
|
export * from "./content-types/index.js";
|
||||||
|
export * from "./common.js";
|
||||||
|
export { default as Database } from "./api/index.js";
|
||||||
|
export { DefaultColors } from "./collections/colors.js";
|
||||||
|
export { EMPTY_CONTENT } from "./collections/content.js";
|
||||||
|
export { type BackupFile, type LegacyBackupFile } from "./database/backup.js";
|
||||||
|
export { type DatabaseUpdatedEvent } from "./database/index.js";
|
||||||
|
export { FilteredSelector } from "./database/sql-collection.js";
|
||||||
export {
|
export {
|
||||||
createInternalLink,
|
getUpcomingReminder,
|
||||||
parseInternalLink,
|
formatReminderTime,
|
||||||
type InternalLink
|
isReminderToday,
|
||||||
} from "./utils/internal-link";
|
isReminderActive
|
||||||
export {
|
} from "./collections/reminders.js";
|
||||||
extractInternalLinks,
|
export * from "./logger.js";
|
||||||
highlightInternalLinks,
|
export * from "./api/debug.js";
|
||||||
type TextSlice
|
export * from "./api/monographs.js";
|
||||||
} from "./utils/content-block";
|
export * from "./api/subscriptions.js";
|
||||||
export { type DatabaseUpdatedEvent } from "./database";
|
export * from "./api/pricing.js";
|
||||||
export { isServerCompatible } from "./utils/constants";
|
export { VAULT_ERRORS } from "./api/vault.js";
|
||||||
|
export type { SyncOptions } from "./api/sync/index.js";
|
||||||
|
export { sanitizeTag } from "./collections/tags.js";
|
||||||
|
export { default as DataURL } from "./utils/dataurl.js";
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Cipher, DataFormat, SerializedKey } from "@notesnook/crypto";
|
import { Cipher, DataFormat, SerializedKey } from "@notesnook/crypto";
|
||||||
import { KVStorage } from "./database/kv";
|
import { KVStorage } from "./database/kv.js";
|
||||||
import { ConfigStorage } from "./database/config";
|
import { ConfigStorage } from "./database/config.js";
|
||||||
|
|
||||||
export type Output<TOutputFormat extends DataFormat> =
|
export type Output<TOutputFormat extends DataFormat> =
|
||||||
TOutputFormat extends "uint8array" ? Uint8Array : string;
|
TOutputFormat extends "uint8array" ? Uint8Array : string;
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ import {
|
|||||||
ILogger
|
ILogger
|
||||||
} from "@notesnook/logger";
|
} from "@notesnook/logger";
|
||||||
import { Kysely, Migration, MigrationProvider } from "@streetwriters/kysely";
|
import { Kysely, Migration, MigrationProvider } from "@streetwriters/kysely";
|
||||||
import { SQLiteOptions, createDatabase } from "./database";
|
import { SQLiteOptions, createDatabase } from "./database/index.js";
|
||||||
import { toChunks } from "./utils/array";
|
import { toChunks } from "./utils/array.js";
|
||||||
|
|
||||||
const WEEK = 86400000 * 7;
|
const WEEK = 86400000 * 7;
|
||||||
|
|
||||||
|
|||||||
@@ -17,11 +17,11 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { parseHTML } from "./utils/html-parser";
|
import { parseHTML } from "./utils/html-parser.js";
|
||||||
import { decodeHTML5 } from "entities";
|
import { decodeHTML5 } from "entities";
|
||||||
import { CURRENT_DATABASE_VERSION } from "./common";
|
import { CURRENT_DATABASE_VERSION } from "./common.js";
|
||||||
import Database from "./api";
|
import Database from "./api/index.js";
|
||||||
import { makeId } from "./utils/id";
|
import { makeId } from "./utils/id.js";
|
||||||
import {
|
import {
|
||||||
Color,
|
Color,
|
||||||
ContentItem,
|
ContentItem,
|
||||||
@@ -33,12 +33,12 @@ import {
|
|||||||
ToolbarConfigPlatforms,
|
ToolbarConfigPlatforms,
|
||||||
isDeleted,
|
isDeleted,
|
||||||
isGroupingKey
|
isGroupingKey
|
||||||
} from "./types";
|
} from "./types.js";
|
||||||
import { isCipher } from "./database/crypto";
|
import { isCipher } from "./utils/crypto.js";
|
||||||
import { IndexedCollection } from "./database/indexed-collection";
|
import { IndexedCollection } from "./database/indexed-collection.js";
|
||||||
import { DefaultColors } from "./collections/colors";
|
import { DefaultColors } from "./collections/colors.js";
|
||||||
import { Cipher } from "@notesnook/crypto";
|
import { Cipher } from "@notesnook/crypto";
|
||||||
import { KEYS } from "./database/kv";
|
import { KEYS } from "./database/kv.js";
|
||||||
|
|
||||||
type MigrationType = "local" | "sync" | "backup";
|
type MigrationType = "local" | "sync" | "backup";
|
||||||
type MigrationItemType = ItemType | "notehistory" | "content" | "never";
|
type MigrationItemType = ItemType | "notehistory" | "content" | "never";
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Cipher } from "@notesnook/crypto";
|
import { Cipher } from "@notesnook/crypto";
|
||||||
import { TimeFormat } from "./utils/date";
|
import { isCipher } from "./utils/index.js";
|
||||||
|
|
||||||
|
export type TimeFormat = "12-hour" | "24-hour";
|
||||||
|
|
||||||
export type SortOptions = {
|
export type SortOptions = {
|
||||||
sortBy:
|
sortBy:
|
||||||
@@ -567,3 +569,20 @@ export type ContentBlock = {
|
|||||||
type: string;
|
type: string;
|
||||||
id: string;
|
id: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type NoteContent<TLocked extends boolean> = {
|
||||||
|
data: TLocked extends true ? Cipher<"base64"> : string;
|
||||||
|
type: ContentType;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function isDecryptedContent(
|
||||||
|
content: NoteContent<boolean>
|
||||||
|
): content is NoteContent<false> {
|
||||||
|
return !isCipher(content.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isEncryptedContent(
|
||||||
|
content: NoteContent<boolean>
|
||||||
|
): content is NoteContent<true> {
|
||||||
|
return isCipher(content.data);
|
||||||
|
}
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ import {
|
|||||||
extractInternalLinks,
|
extractInternalLinks,
|
||||||
highlightInternalLinks,
|
highlightInternalLinks,
|
||||||
ellipsize
|
ellipsize
|
||||||
} from "../content-block";
|
} from "../content-block.js";
|
||||||
import { ContentBlock } from "../../types";
|
import { ContentBlock } from "../../types.js";
|
||||||
|
|
||||||
describe("ContentBlock Utils", () => {
|
describe("ContentBlock Utils", () => {
|
||||||
describe("extractInternalLinks", () => {
|
describe("extractInternalLinks", () => {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { isHTMLEqual } from "../html-diff";
|
import { isHTMLEqual } from "../html-diff.js";
|
||||||
import { test, expect, describe } from "vitest";
|
import { test, expect, describe } from "vitest";
|
||||||
|
|
||||||
const equalPairs = [
|
const equalPairs = [
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { expect, test } from "vitest";
|
import { expect, test } from "vitest";
|
||||||
import { transformQuery } from "../query-transformer";
|
import { transformQuery } from "../query-transformer.js";
|
||||||
|
|
||||||
const TRANSFORM_QUERY_TESTS = [
|
const TRANSFORM_QUERY_TESTS = [
|
||||||
["hello world", `"hello world"`],
|
["hello world", `"hello world"`],
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { set } from "../set";
|
import { set } from "../set.js";
|
||||||
import { test, expect } from "vitest";
|
import { test, expect } from "vitest";
|
||||||
|
|
||||||
test("union", () => {
|
test("union", () => {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { formatTitle } from "../title-format";
|
import { formatTitle } from "../title-format.js";
|
||||||
import MockDate from "mockdate";
|
import MockDate from "mockdate";
|
||||||
import { test, expect, describe, beforeAll, afterAll } from "vitest";
|
import { test, expect, describe, beforeAll, afterAll } from "vitest";
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { test } from "vitest";
|
import { test } from "vitest";
|
||||||
import { VirtualizedGrouping } from "../virtualized-grouping";
|
import { VirtualizedGrouping } from "../virtualized-grouping.js";
|
||||||
import { groupArray } from "../grouping";
|
import { groupArray } from "../grouping.js";
|
||||||
|
|
||||||
function generateItems(length: number, groupSize: number) {
|
function generateItems(length: number, groupSize: number) {
|
||||||
const items: { group: string; id: string }[] = [];
|
const items: { group: string; id: string }[] = [];
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { extractHostname } from "./hostname";
|
import { extractHostname } from "./hostname.js";
|
||||||
|
|
||||||
const COMPATIBLE_SERVER_VERSION = 1;
|
const COMPATIBLE_SERVER_VERSION = 1;
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ContentBlock } from "../types";
|
import { ContentBlock } from "../types.js";
|
||||||
import { InternalLinkWithOffset, parseInternalLink } from "./internal-link";
|
import { InternalLinkWithOffset, parseInternalLink } from "./internal-link.js";
|
||||||
|
|
||||||
const INTERNAL_LINK_REGEX = /(?:\[\[(nn:\/\/note\/.+?)\]\])/gm;
|
const INTERNAL_LINK_REGEX = /(?:\[\[(nn:\/\/note\/.+?)\]\])/gm;
|
||||||
export function extractInternalLinks(block: ContentBlock) {
|
export function extractInternalLinks(block: ContentBlock) {
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Cipher } from "@notesnook/crypto";
|
import { Cipher } from "@notesnook/crypto";
|
||||||
import { StorageAccessor } from "../interfaces";
|
import { StorageAccessor } from "../interfaces.js";
|
||||||
import { randomBytes } from "../utils/random";
|
import { randomBytes } from "./random.js";
|
||||||
|
|
||||||
export type CryptoAccessor = () => Crypto;
|
export type CryptoAccessor = () => Crypto;
|
||||||
export class Crypto {
|
export class Crypto {
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user