core: make imports compatible with esm

This commit is contained in:
Abdullah Atta
2024-09-23 15:08:57 +05:00
parent f100e157d3
commit 59739067b6
116 changed files with 559 additions and 486 deletions

View File

@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { bench, describe } from "vitest";
import { databaseTest } from "../__tests__/utils";
import Database from "../src/api";
import { databaseTest } from "../__tests__/utils/index.js";
import Database from "../src/api/index.js";
async function addNotes(db: Database) {
const words = [

View File

@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { bench, describe } from "vitest";
import { databaseTest } from "../__tests__/utils";
import Database from "../src/api";
import { databaseTest } from "../__tests__/utils/index.js";
import Database from "../src/api/index.js";
async function addNotes(db: Database) {
const titles = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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 { nanoid } from "nanoid";

View File

@@ -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/>.
*/
import { bench, describe } from "vitest";
import { databaseTest } from "../__tests__/utils";
import { describe } from "vitest";
import { databaseTest } from "../__tests__/utils/index.js";
describe("relations", async () => {
const db = await databaseTest();

View File

@@ -18,15 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { bench, describe } from "vitest";
import { databaseTest } from "../__tests__/utils";
import Database from "../src/api";
import { databaseTest } from "../__tests__/utils/index.js";
import Database from "../src/api/index.js";
import MockDate from "mockdate";
import dayjs from "dayjs";
import { Reminder } from "../src/types";
import { Reminder } from "../src/types.js";
import {
createUpcomingReminderTimeQuery,
getUpcomingReminderTime
} from "../src/collections/reminders";
} from "../src/collections/reminders.js";
async function addReminders(db: Database) {
const reminders: Partial<Reminder>[] = [

View File

@@ -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/>.
*/
import { databaseTest, noteTest } from "../__tests__/utils";
import { login, logout } from "./utils";
import { databaseTest, noteTest } from "../__tests__/utils/index.js";
import { login, logout } from "./utils.js";
import { test, expect, afterAll } from "vitest";
const TEST_TIMEOUT = 30 * 1000;

View File

@@ -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/>.
*/
import hosts from "../src/utils/constants";
import { Offers } from "../src/api/offers";
import hosts from "../src/utils/constants.js";
import { Offers } from "../src/api/offers.js";
import { test, expect } from "vitest";
test("get offer code", async () => {

View File

@@ -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/>.
*/
import { Pricing } from "../src/api/pricing";
import { Pricing } from "../src/api/pricing.js";
import { test, expect, describe } from "vitest";
test.each(["monthly", "yearly", undefined])(`get %s price`, async (period) => {

View File

@@ -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/>.
*/
import Database from "../src/api/index";
import { NodeStorageInterface } from "../__mocks__/node-storage.mock";
import { FS } from "../__mocks__/fs.mock";
import Compressor from "../__mocks__/compressor.mock";
import { CHECK_IDS, EV, EVENTS } from "../src/common";
import Database from "../src/api/index.js";
import { NodeStorageInterface } from "../__mocks__/node-storage.mock.js";
import { FS } from "../__mocks__/fs.mock.js";
import Compressor from "../__mocks__/compressor.mock.js";
import { CHECK_IDS, EV, EVENTS } from "../src/common.js";
import { EventSource } from "event-source-polyfill";
import { test, expect, vitest } from "vitest";
import { login } from "./utils";
import { login } from "./utils.js";
import { SqliteDialect } from "@streetwriters/kysely";
import BetterSQLite3 from "better-sqlite3-multiple-ciphers";

View File

@@ -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/>.
*/
import { databaseTest } from "../__tests__/utils";
import { login } from "./utils";
import { databaseTest } from "../__tests__/utils/index.js";
import { login } from "./utils.js";
import { test, expect } from "vitest";
test(

View File

@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { authenticator } from "otplib";
import { databaseTest } from "../__tests__/utils";
import { login, USER } from "./utils";
import { databaseTest } from "../__tests__/utils/index.js";
import { login, USER } from "./utils.js";
import { test, expect } from "vitest";
// test("signup user and check for token", async () => {

View File

@@ -22,7 +22,7 @@ import {
FileEncryptionMetadataWithOutputType,
IFileStorage,
RequestOptions
} from "../src/interfaces";
} from "../src/interfaces.js";
import { xxhash64 } from "hash-wasm";
import { IDataType } from "hash-wasm/dist/lib/util";

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Cipher, NNCrypto, SerializedKey } from "@notesnook/crypto";
import { IStorage } from "../src/interfaces";
import { IStorage } from "../src/interfaces.js";
export class NodeStorageInterface implements IStorage {
storage = {};

View File

@@ -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/>.
*/
import { TEST_NOTE, databaseTest, loginFakeUser, notebookTest } from "./utils";
import { TEST_NOTE, databaseTest, loginFakeUser, notebookTest } from "./utils/index.js";
import { test, expect } from "vitest";
test("export backup", () =>

View File

@@ -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/>.
*/
import Constants from "../src/utils/constants";
import Constants from "../src/utils/constants.js";
import { test, expect } from "vitest";
import { databaseTest } from "./utils";
import { databaseTest } from "./utils/index.js";
test("db.host should change HOST", () =>
databaseTest().then((db) => {

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { expect, test } from "vitest";
import { databaseTest, noteTest } from "./utils";
import { databaseTest, noteTest } from "./utils/index.js";
test("updating deleted content should not throw", () =>
databaseTest().then(async (db) => {

View File

@@ -18,11 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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 BetterSQLite3 from "better-sqlite3-multiple-ciphers";
import { NoopLogger } from "@notesnook/logger";
import { delay } from "./utils";
import { delay } from "./utils/index.js";
async function initializeLogger() {
await initialize(

View File

@@ -23,7 +23,7 @@ import {
notebookTest,
TEST_NOTEBOOK2,
databaseTest
} from "./utils";
} from "./utils/index.js";
import { test, expect } from "vitest";
const content = {

View File

@@ -18,11 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { test, expect, describe } from "vitest";
import { migrateItem, migrateKV, migrateVaultKey } from "../src/migrations";
import { databaseTest } from "./utils";
import { getId, makeId } from "../src/utils/id";
import { DeletedItem, LegacySettingsItem } from "../src/types";
import { KEYS } from "../src/database/kv";
import { migrateItem, migrateKV, migrateVaultKey } from "../src/migrations.js";
import { databaseTest } from "./utils/index.js";
import { getId, makeId } from "../src/utils/id.js";
import { DeletedItem, LegacySettingsItem } from "../src/types.js";
import { KEYS } from "../src/database/kv.js";
describe.concurrent("[5.2] replace date edited with date modified", () => {
const itemsWithDateEdited = ["note", "notebook", "trash", "tiny"] as const;

View File

@@ -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/>.
*/
import { delay, noteTest, TEST_NOTE } from "./utils";
import { delay, noteTest, TEST_NOTE } from "./utils/index.js";
import { test, expect } from "vitest";
// async function sessionTest(db, noteId) {

View File

@@ -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/>.
*/
import { notebookTest, TEST_NOTEBOOK } from "./utils";
import { notebookTest, TEST_NOTEBOOK } from "./utils/index.js";
import { test, expect } from "vitest";
test("add a notebook", () =>

View File

@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import dayjs from "dayjs";
import Database from "../src/api";
import { createKeySelector, groupArray } from "../src/utils/grouping";
import Database from "../src/api/index.js";
import { createKeySelector, groupArray } from "../src/utils/grouping.js";
import {
databaseTest,
noteTest,
@@ -27,10 +27,9 @@ import {
TEST_NOTEBOOK,
IMG_CONTENT,
loginFakeUser
} from "./utils";
} from "./utils/index.js";
import { test, expect } from "vitest";
import { MONTHS_FULL } from "../src/utils/date";
import { GroupOptions, Note } from "../src/types";
import { GroupOptions, Note } from "../src/types.js";
async function createAndAddNoteToNotebook(
db: Database,

View File

@@ -23,10 +23,10 @@ import {
formatReminderTime,
getUpcomingReminderTime,
isReminderActive
} from "../src/collections/reminders";
} from "../src/collections/reminders.js";
import MockDate from "mockdate";
import { describe, afterAll, beforeEach, test, expect } from "vitest";
import { databaseTest } from "./utils";
import { databaseTest } from "./utils/index.js";
import dayjs from "dayjs";
import assert from "assert";

View File

@@ -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/>.
*/
import { databaseTest } from "./utils";
import { databaseTest } from "./utils/index.js";
import { test, expect } from "vitest";
test("save group options", () =>

View File

@@ -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/>.
*/
import { databaseTest, notebookTest } from "./utils";
import { databaseTest, notebookTest } from "./utils/index.js";
import { test, expect } from "vitest";
test("create a shortcut of an invalid item should throw", () =>

View File

@@ -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/>.
*/
import { NodeStorageInterface } from "../__mocks__/node-storage.mock";
import { NodeStorageInterface } from "../__mocks__/node-storage.mock.js";
import { test, expect } from "vitest";
test("add a value", async () => {

View File

@@ -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/>.
*/
import { databaseTest, noteTest, TEST_NOTE } from "./utils";
import { databaseTest, noteTest, TEST_NOTE } from "./utils/index.js";
import { test, expect } from "vitest";
function tag(title: string) {

View File

@@ -24,7 +24,7 @@ import {
TEST_NOTE,
TEST_NOTEBOOK,
databaseTest
} from "./utils";
} from "./utils/index.js";
import { test, expect } from "vitest";
test("trash should be empty", () =>

View File

@@ -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/>.
*/
import DB from "../../src/api";
import { NodeStorageInterface } from "../../__mocks__/node-storage.mock";
import { FS } from "../../__mocks__/fs.mock";
import Compressor from "../../__mocks__/compressor.mock";
import DB from "../../src/api/index.js";
import { NodeStorageInterface } from "../../__mocks__/node-storage.mock.js";
import { FS } from "../../__mocks__/fs.mock.js";
import Compressor from "../../__mocks__/compressor.mock.js";
import { EventSourcePolyfill as EventSource } from "event-source-polyfill";
import { randomBytes } from "../../src/utils/random";
import { Note, Notebook } from "../../src/types";
import { NoteContent } from "../../src/collections/session-content";
import { randomBytes } from "../../src/utils/random.js";
import { Note, Notebook } from "../../src/types.js";
import { NoteContent } from "../../src/collections/session-content.js";
import { SqliteDialect } from "@streetwriters/kysely";
import BetterSQLite3 from "better-sqlite3-multiple-ciphers";
import path from "path";
import { tmpdir } from "os";
import { getId } from "../../src/utils/id";
import { getId } from "../../src/utils/id.js";
import { existsSync, mkdirSync } from "fs";
const TEST_NOTEBOOK: Partial<Notebook> = {

View File

@@ -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/>.
*/
import { VAULT_ERRORS } from "../src/api/vault";
import { databaseTest, delay, noteTest, TEST_NOTE } from "./utils";
import { VAULT_ERRORS } from "../src/api/vault.js";
import { databaseTest, delay, noteTest, TEST_NOTE } from "./utils/index.js";
import { test, expect } from "vitest";
test("create vault", () =>

View File

@@ -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/>.
*/
import { Debug } from "../debug";
import { Debug } from "../debug.js";
import createFetchMock from "vitest-fetch-mock";
import { vi, test, expect } from "vitest";
const fetchMocker = createFetchMock(vi);

View File

@@ -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/>.
*/
import { HealthCheck, check } from "../healthcheck";
import { HealthCheck, check } from "../healthcheck.js";
import { describe } from "vitest";
describe.concurrent("Health check", (test) => {

View File

@@ -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/>.
*/
import hosts from "../utils/constants";
import hosts from "../utils/constants.js";
export class Debug {
static async report(reportData: {

View File

@@ -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/>.
*/
import hosts from "../utils/constants";
import http from "../utils/http";
import hosts from "../utils/constants.js";
import http from "../utils/http.js";
export class HealthCheck {
static async auth() {

View File

@@ -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/>.
*/
import { Notes } from "../collections/notes";
import { Crypto, CryptoAccessor } from "../database/crypto";
import { FileStorage, FileStorageAccessor } from "../database/fs";
import { Notebooks } from "../collections/notebooks";
import Trash from "../collections/trash";
import Sync, { SyncOptions } from "./sync";
import { Tags } from "../collections/tags";
import { Colors } from "../collections/colors";
import Vault from "./vault";
import Lookup from "./lookup";
import { Content } from "../collections/content";
import Backup from "../database/backup";
import Hosts from "../utils/constants";
import { EV, EVENTS } from "../common";
import { LegacySettings } from "../collections/legacy-settings";
import Migrations from "./migrations";
import UserManager from "./user-manager";
import http from "../utils/http";
import { Monographs } from "./monographs";
import { Offers } from "./offers";
import { Attachments } from "../collections/attachments";
import { Debug } from "./debug";
import { Notes } from "../collections/notes.js";
import { Crypto, CryptoAccessor } from "../utils/crypto.js";
import { FileStorage, FileStorageAccessor } from "../database/fs.js";
import { Notebooks } from "../collections/notebooks.js";
import Trash from "../collections/trash.js";
import Sync, { SyncOptions } from "./sync/index.js";
import { Tags } from "../collections/tags.js";
import { Colors } from "../collections/colors.js";
import Vault from "./vault.js";
import Lookup from "./lookup.js";
import { Content } from "../collections/content.js";
import Backup from "../database/backup.js";
import Hosts from "../utils/constants.js";
import { EV, EVENTS } from "../common.js";
import { LegacySettings } from "../collections/legacy-settings.js";
import Migrations from "./migrations.js";
import UserManager from "./user-manager.js";
import http from "../utils/http.js";
import { Monographs } from "./monographs.js";
import { Offers } from "./offers.js";
import { Attachments } from "../collections/attachments.js";
import { Debug } from "./debug.js";
import { Mutex } from "async-mutex";
import { NoteHistory } from "../collections/note-history";
import MFAManager from "./mfa-manager";
import EventManager from "../utils/event-manager";
import { Pricing } from "./pricing";
import { logger } from "../logger";
import { Shortcuts } from "../collections/shortcuts";
import { Reminders } from "../collections/reminders";
import { Relations } from "../collections/relations";
import Subscriptions from "./subscriptions";
import { NoteHistory } from "../collections/note-history.js";
import MFAManager from "./mfa-manager.js";
import EventManager from "../utils/event-manager.js";
import { Pricing } from "./pricing.js";
import { logger } from "../logger.js";
import { Shortcuts } from "../collections/shortcuts.js";
import { Reminders } from "../collections/reminders.js";
import { Relations } from "../collections/relations.js";
import Subscriptions from "./subscriptions.js";
import {
CompressorAccessor,
ConfigStorageAccessor,
@@ -57,10 +57,10 @@ import {
IStorage,
KVStorageAccessor,
StorageAccessor
} from "../interfaces";
import TokenManager from "./token-manager";
import { Attachment } from "../types";
import { Settings } from "../collections/settings";
} from "../interfaces.js";
import TokenManager from "./token-manager.js";
import { Attachment } from "../types.js";
import { Settings } from "../collections/settings.js";
import {
DatabaseAccessor,
DatabaseSchema,
@@ -69,16 +69,16 @@ import {
changeDatabasePassword,
createDatabase,
initializeDatabase
} from "../database";
} from "../database/index.js";
import { Kysely, Transaction, sql } from "@streetwriters/kysely";
import { CachedCollection } from "../database/cached-collection";
import { Vaults } from "../collections/vaults";
import { KVStorage } from "../database/kv";
import { QueueValue } from "../utils/queue-value";
import { Sanitizer } from "../database/sanitizer";
import { createTriggers, dropTriggers } from "../database/triggers";
import { NNMigrationProvider } from "../database/migrations";
import { ConfigStorage } from "../database/config";
import { CachedCollection } from "../database/cached-collection.js";
import { Vaults } from "../collections/vaults.js";
import { KVStorage } from "../database/kv.js";
import { QueueValue } from "../utils/queue-value.js";
import { Sanitizer } from "../database/sanitizer.js";
import { createTriggers, dropTriggers } from "../database/triggers.js";
import { NNMigrationProvider } from "../database/migrations.js";
import { ConfigStorage } from "../database/config.js";
type EventSourceConstructor = new (
uri: string,

View File

@@ -18,15 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { match } from "fuzzyjs";
import Database from ".";
import { Item, Note, TrashItem } from "../types";
import { DatabaseSchema, RawDatabaseSchema } from "../database";
import Database from "./index.js";
import { Item, Note, TrashItem } from "../types.js";
import { DatabaseSchema, RawDatabaseSchema } from "../database/index.js";
import { AnyColumnWithTable, Kysely, sql } from "@streetwriters/kysely";
import { FilteredSelector } from "../database/sql-collection";
import { VirtualizedGrouping } from "../utils/virtualized-grouping";
import { logger } from "../logger";
import { rebuildSearchIndex } from "../database/fts";
import { transformQuery } from "../utils/query-transformer";
import { FilteredSelector } from "../database/sql-collection.js";
import { VirtualizedGrouping } from "../utils/virtualized-grouping.js";
import { logger } from "../logger.js";
import { rebuildSearchIndex } from "../database/fts.js";
import { transformQuery } from "../utils/query-transformer.js";
type SearchResults<T> = {
sorted: (limit?: number) => Promise<VirtualizedGrouping<T>>;

View File

@@ -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/>.
*/
import http from "../utils/http";
import constants from "../utils/constants";
import TokenManager from "./token-manager";
import http from "../utils/http.js";
import constants from "../utils/constants.js";
import TokenManager from "./token-manager.js";
const ENDPOINTS = {
setup: "/mfa",

View File

@@ -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/>.
*/
import Database from ".";
import { CURRENT_DATABASE_VERSION } from "../common";
import Migrator, { MigratableCollections } from "../database/migrator";
import Database from "./index.js";
import { CURRENT_DATABASE_VERSION } from "../common.js";
import Migrator, { MigratableCollections } from "../database/migrator.js";
const collections: MigratableCollections = [
{

View File

@@ -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/>.
*/
import http from "../utils/http";
import Constants from "../utils/constants";
import Database from ".";
import { Note, isDeleted } from "../types";
import http from "../utils/http.js";
import Constants from "../utils/constants.js";
import Database from "./index.js";
import { Note, isDeleted } from "../types.js";
import { Cipher } from "@notesnook/crypto";
import { isFalse } from "../database";
import { logger } from "../logger";
import { isFalse } from "../database/index.js";
import { logger } from "../logger.js";
type BaseMonograph = {
id: string;

View File

@@ -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/>.
*/
import { CLIENT_ID } from "../common";
import hosts from "../utils/constants";
import http from "../utils/http";
import { CLIENT_ID } from "../common.js";
import hosts from "../utils/constants.js";
import http from "../utils/http.js";
export class Offers {
static async getCode(promo: string, platform: "ios" | "android" | "web") {

View File

@@ -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/>.
*/
import http from "../utils/http";
import http from "../utils/http.js";
export type Product = {
country: string;

View File

@@ -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/>.
*/
import hosts from "../utils/constants";
import http from "../utils/http";
import TokenManager from "./token-manager";
import hosts from "../utils/constants.js";
import http from "../utils/http.js";
import TokenManager from "./token-manager.js";
export type TransactionStatus =
| "completed"

View File

@@ -21,8 +21,8 @@ import {
databaseTest,
TEST_NOTE,
loginFakeUser
} from "../../../../__tests__/utils";
import Collector from "../collector";
} from "../../../../__tests__/utils/index.js";
import Collector from "../collector.js";
import { test, expect } from "vitest";
test("newly created note should get included in collector", () =>

View File

@@ -21,9 +21,9 @@ import {
TEST_NOTE,
databaseTest,
loginFakeUser
} from "../../../../__tests__/utils";
} from "../../../../__tests__/utils/index.js";
import { expect, describe, vi } from "vitest";
import Merger from "../merger";
import Merger from "../merger.js";
describe.concurrent("merge item synchronously", (test) => {
test("accept remote item if no local item is found", () =>

View File

@@ -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/>.
*/
import Database from "..";
import { EVENTS } from "../../common";
import { DatabaseUpdatedEvent } from "../../database";
import { logger } from "../../logger";
import Database from "../index.js";
import { EVENTS } from "../../common.js";
import { DatabaseUpdatedEvent } from "../../database/index.js";
import { logger } from "../../logger.js";
export class AutoSync {
timeout = 0;

View File

@@ -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/>.
*/
import { Cipher, SerializedKey } from "@notesnook/crypto";
import Database from "..";
import { CURRENT_DATABASE_VERSION, EV, EVENTS } from "../../common";
import { logger } from "../../logger";
import { Cipher } from "@notesnook/crypto";
import Database from "../index.js";
import { CURRENT_DATABASE_VERSION, EV, EVENTS } from "../../common.js";
import { logger } from "../../logger.js";
import {
SyncItem,
SyncTransferItem,
SYNC_COLLECTIONS_MAP,
SYNC_ITEM_TYPES
} from "./types";
import { Item, MaybeDeletedItem } from "../../types";
} from "./types.js";
import { Item, MaybeDeletedItem } from "../../types.js";
class Collector {
logger = logger.scope("SyncCollector");

View File

@@ -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/>.
*/
import { KVStorageAccessor } from "../../interfaces";
import hosts from "../../utils/constants";
import http from "../../utils/http";
import { getId } from "../../utils/id";
import TokenManager from "../token-manager";
import { KVStorageAccessor } from "../../interfaces.js";
import hosts from "../../utils/constants.js";
import http from "../../utils/http.js";
import { getId } from "../../utils/id.js";
import TokenManager from "../token-manager.js";
export class SyncDevices {
constructor(

View File

@@ -24,17 +24,17 @@ import {
EVENTS,
sendSyncProgressEvent,
SYNC_CHECK_IDS
} from "../../common";
import Constants from "../../utils/constants";
import TokenManager from "../token-manager";
import Collector from "./collector";
} from "../../common.js";
import Constants from "../../utils/constants.js";
import TokenManager from "../token-manager.js";
import Collector from "./collector.js";
import * as signalr from "@microsoft/signalr";
import Merger from "./merger";
import { AutoSync } from "./auto-sync";
import { logger } from "../../logger";
import Merger from "./merger.js";
import { AutoSync } from "./auto-sync.js";
import { logger } from "../../logger.js";
import { Mutex } from "async-mutex";
import Database from "..";
import { migrateItem, migrateVaultKey } from "../../migrations";
import Database from "../index.js";
import { migrateItem, migrateVaultKey } from "../../migrations.js";
import { SerializedKey } from "@notesnook/crypto";
import {
Attachment,
@@ -44,15 +44,15 @@ import {
MaybeDeletedItem,
Note,
Notebook
} from "../../types";
} from "../../types.js";
import {
SYNC_COLLECTIONS_MAP,
SyncableItemType,
SyncTransferItem
} from "./types";
import { DownloadableFile } from "../../database/fs";
import { SyncDevices } from "./devices";
import { DefaultColors } from "../../collections/colors";
} from "./types.js";
import { DownloadableFile } from "../../database/fs.js";
import { SyncDevices } from "./devices.js";
import { DefaultColors } from "../../collections/colors.js";
export type SyncOptions = {
type: "full" | "fetch" | "send";
@@ -61,9 +61,12 @@ export type SyncOptions = {
};
export default class SyncManager {
sync = new Sync(this.db);
devices = this.sync.devices;
constructor(private readonly db: Database) {}
sync;
devices;
constructor(private readonly db: Database) {
this.sync = new Sync(db);
this.devices = this.sync.devices;
}
async start(options: SyncOptions) {
try {
@@ -114,17 +117,22 @@ export default class SyncManager {
}
class Sync {
collector = new Collector(this.db);
merger = new Merger(this.db);
autoSync = new AutoSync(this.db, 1000);
collector;
merger;
autoSync;
logger = logger.scope("Sync");
syncConnectionMutex = new Mutex();
connection?: signalr.HubConnection;
devices = new SyncDevices(this.db.kv, this.db.tokenManager);
devices;
private conflictedNoteIds: string[] = [];
private uncachedAttachments: DownloadableFile[] = [];
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 () => {
await this.connection?.stop();
this.autoSync.stop();

View File

@@ -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/>.
*/
import { logger } from "../../logger";
import { isHTMLEqual } from "../../utils/html-diff";
import Database from "..";
import { logger } from "../../logger.js";
import { isHTMLEqual } from "../../utils/html-diff.js";
import Database from "../index.js";
import {
Attachment,
ContentItem,
Item,
MaybeDeletedItem,
isDeleted
} from "../../types";
} from "../../types.js";
const THRESHOLD = process.env.NODE_ENV === "test" ? 6 * 1000 : 60 * 1000;
class Merger {

View File

@@ -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/>.
*/
import http from "../utils/http";
import constants from "../utils/constants";
import { EV, EVENTS } from "../common";
import http from "../utils/http.js";
import constants from "../utils/constants.js";
import { EV, EVENTS } from "../common.js";
import { withTimeout, Mutex } from "async-mutex";
import { logger } from "../logger";
import { KVStorageAccessor } from "../interfaces";
import { logger } from "../logger.js";
import { KVStorageAccessor } from "../interfaces.js";
export type Token = {
access_token: string;

View File

@@ -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/>.
*/
import { User } from "../types";
import http from "../utils/http";
import constants from "../utils/constants";
import TokenManager from "./token-manager";
import { EV, EVENTS } from "../common";
import { HealthCheck } from "./healthcheck";
import Database from ".";
import { User } from "../types.js";
import http from "../utils/http.js";
import constants from "../utils/constants.js";
import TokenManager from "./token-manager.js";
import { EV, EVENTS } from "../common.js";
import { HealthCheck } from "./healthcheck.js";
import Database from "./index.js";
import { SerializedKey } from "@notesnook/crypto";
import { logger } from "../logger";
import { logger } from "../logger.js";
const ENDPOINTS = {
signup: "/users",

View File

@@ -18,12 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Cipher } from "@notesnook/crypto";
import Database from ".";
import { CHECK_IDS, EV, EVENTS, checkIsUserPremium } from "../common";
import { isCipher } from "../database/crypto";
import { NoteContent } from "../collections/session-content";
import { Note } from "../types";
import { logger } from "../logger";
import Database from "./index.js";
import { CHECK_IDS, EV, EVENTS, checkIsUserPremium } from "../common.js";
import { isCipher } from "../utils/crypto.js";
import { Note, NoteContent } from "../types.js";
import { logger } from "../logger.js";
export const VAULT_ERRORS = {
noVault: "ERR_NO_VAULT",

View File

@@ -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/>.
*/
import { ICollection } from "./collection";
import { getId } from "../utils/id";
import { EV, EVENTS } from "../common";
import dataurl from "../utils/dataurl";
import { ICollection } from "./collection.js";
import { getId } from "../utils/id.js";
import { EV, EVENTS } from "../common.js";
import dataurl from "../utils/dataurl.js";
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 { Output } from "../interfaces";
import { Attachment } from "../types";
import Database from "../api";
import { FilteredSelector, SQLCollection } from "../database/sql-collection";
import { isFalse } from "../database";
import { Output } from "../interfaces.js";
import { Attachment } from "../types.js";
import Database from "../api/index.js";
import { FilteredSelector, SQLCollection } from "../database/sql-collection.js";
import { isFalse } from "../database/index.js";
import { sql } from "@streetwriters/kysely";
import { logger } from "../logger";
import { logger } from "../logger.js";
export class Attachments implements ICollection {
name = "attachments";

View File

@@ -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/>.
*/
import { ICollection } from "./collection";
import { getId } from "../utils/id";
import { Color } from "../types";
import Database from "../api";
import { Tags } from "./tags";
import { SQLCollection } from "../database/sql-collection";
import { isFalse } from "../database";
import { CHECK_IDS, checkIsUserPremium } from "../common";
import { ICollection } from "./collection.js";
import { getId } from "../utils/id.js";
import { Color } from "../types.js";
import Database from "../api/index.js";
import { sanitizeTag } from "./tags.js";
import { SQLCollection } from "../database/sql-collection.js";
import { isFalse } from "../database/index.js";
import { CHECK_IDS, checkIsUserPremium } from "../common.js";
export const DefaultColors: Record<string, string> = {
red: "#f44336",
@@ -70,7 +70,7 @@ export class Colors implements ICollection {
// }
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
? await this.color(item.id)
: item.colorCode

View File

@@ -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/>.
*/
import { ICollection } from "./collection";
import { getId } from "../utils/id";
import { getContentFromData } from "../content-types";
import { isCipher } from "../database/crypto";
import { ICollection } from "./collection.js";
import { getId } from "../utils/id.js";
import { getContentFromData } from "../content-types/index.js";
import { isCipher } from "../utils/crypto.js";
import {
ContentItem,
ContentType,
UnencryptedContentItem,
isDeleted
} from "../types";
import Database from "../api";
import { getOutputType } from "./attachments";
import { SQLCollection } from "../database/sql-collection";
import { NoteContent } from "./session-content";
import { InternalLink } from "../utils/internal-link";
import { tinyToTiptap } from "../migrations";
import { EVENTS } from "../common";
import { DeleteEvent, UpdateEvent } from "../database";
import { logger } from "../logger";
isDeleted,
NoteContent
} from "../types.js";
import Database from "../api/index.js";
import { getOutputType } from "./attachments.js";
import { SQLCollection } from "../database/sql-collection.js";
import { InternalLink } from "../utils/internal-link.js";
import { tinyToTiptap } from "../migrations.js";
import { EVENTS } from "../common.js";
import { DeleteEvent, UpdateEvent } from "../database/index.js";
import { logger } from "../logger.js";
export const EMPTY_CONTENT = (noteId: string): UnencryptedContentItem => ({
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);
}

View File

@@ -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/>.
*/
import { getId } from "../utils/id";
import Database from "../api";
import { LegacySettingsItem } from "../types";
import { ICollection } from "./collection";
import { getId } from "../utils/id.js";
import Database from "../api/index.js";
import { LegacySettingsItem } from "../types.js";
import { ICollection } from "./collection.js";
/**
* @deprecated only kept here for migration purposes

View File

@@ -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/>.
*/
import Database from "../api";
import { isCipher } from "../database/crypto";
import { FilteredSelector, SQLCollection } from "../database/sql-collection";
import { HistorySession, isDeleted } from "../types";
import { makeSessionContentId } from "../utils/id";
import { ICollection } from "./collection";
import { NoteContent, SessionContent } from "./session-content";
import Database from "../api/index.js";
import { isCipher } from "../utils/crypto.js";
import { FilteredSelector, SQLCollection } from "../database/sql-collection.js";
import { HistorySession, isDeleted, NoteContent } from "../types.js";
import { makeSessionContentId } from "../utils/id.js";
import { ICollection } from "./collection.js";
import { SessionContent } from "./session-content.js";
export class NoteHistory implements ICollection {
name = "notehistory";
versionsLimit = 100;
sessionContent = new SessionContent(this.db);
sessionContent;
readonly collection: SQLCollection<"notehistory", HistorySession>;
constructor(private readonly db: Database) {
this.sessionContent = new SessionContent(db);
this.collection = new SQLCollection(
db.sql,
db.transaction,

View File

@@ -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/>.
*/
import { getId } from "../utils/id";
import Database from "../api";
import { Notebook, TrashOrItem, isTrashItem } from "../types";
import { ICollection } from "./collection";
import { SQLCollection } from "../database/sql-collection";
import { isFalse } from "../database";
import { getId } from "../utils/id.js";
import Database from "../api/index.js";
import { Notebook, TrashOrItem, isTrashItem } from "../types.js";
import { ICollection } from "./collection.js";
import { SQLCollection } from "../database/sql-collection.js";
import { isFalse } from "../database/index.js";
import { sql } from "@streetwriters/kysely";
import { deleteItems } from "../utils/array";
import { CHECK_IDS, checkIsUserPremium } from "../common";
import { deleteItems } from "../utils/array.js";
import { CHECK_IDS, checkIsUserPremium } from "../common.js";
export class Notebooks implements ICollection {
name = "notebooks";

View File

@@ -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/>.
*/
import { getId } from "../utils/id";
import { getContentFromData } from "../content-types";
import { NEWLINE_STRIP_REGEX, formatTitle } from "../utils/title-format";
import { clone } from "../utils/clone";
import { Tiptap } from "../content-types/tiptap";
import { EMPTY_CONTENT } from "./content";
import { buildFromTemplate } from "../utils/templates";
import { Note, TrashOrItem, isTrashItem, isDeleted } from "../types";
import Database from "../api";
import { ICollection } from "./collection";
import { NoteContent } from "./session-content";
import { SQLCollection } from "../database/sql-collection";
import { isFalse } from "../database";
import { logger } from "../logger";
import { getId } from "../utils/id.js";
import { getContentFromData } from "../content-types/index.js";
import { NEWLINE_STRIP_REGEX, formatTitle } from "../utils/title-format.js";
import { clone } from "../utils/clone.js";
import { Tiptap } from "../content-types/tiptap.js";
import { EMPTY_CONTENT } from "./content.js";
import { buildFromTemplate } from "../utils/templates/index.js";
import {
Note,
TrashOrItem,
isTrashItem,
isDeleted,
NoteContent
} 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 = {
format: "html" | "md" | "txt" | "md-frontmatter";

View File

@@ -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/>.
*/
import { makeId } from "../utils/id";
import { ICollection } from "./collection";
import { makeId } from "../utils/id.js";
import { ICollection } from "./collection.js";
import {
Relation,
ItemMap,
ItemReference,
ItemReferences,
ValueOf
} from "../types";
import Database from "../api";
import { FilteredSelector, SQLCollection } from "../database/sql-collection";
import { DatabaseSchema, UnlinkEvent, isFalse } from "../database";
} from "../types.js";
import Database from "../api/index.js";
import { FilteredSelector, SQLCollection } from "../database/sql-collection.js";
import { DatabaseSchema, UnlinkEvent, isFalse } from "../database/index.js";
import { SelectQueryBuilder } from "@streetwriters/kysely";
import { EVENTS } from "../common";
import { EVENTS } from "../common.js";
export class Relations implements ICollection {
name = "relations";

View File

@@ -18,17 +18,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import dayjs from "dayjs";
import isSameOrBefore from "dayjs/plugin/isSameOrBefore";
import isToday from "dayjs/plugin/isToday";
import isTomorrow from "dayjs/plugin/isTomorrow";
import isYesterday from "dayjs/plugin/isYesterday";
import { TimeFormat, formatDate } from "../utils/date";
import { getId } from "../utils/id";
import { ICollection } from "./collection";
import { Reminder } from "../types";
import Database from "../api";
import { SQLCollection } from "../database/sql-collection";
import { isFalse } from "../database";
import isSameOrBefore from "dayjs/plugin/isSameOrBefore.js";
import isToday from "dayjs/plugin/isToday.js";
import isTomorrow from "dayjs/plugin/isTomorrow.js";
import isYesterday from "dayjs/plugin/isYesterday.js";
import { formatDate } from "../utils/date.js";
import { getId } from "../utils/id.js";
import { ICollection } from "./collection.js";
import { Reminder, TimeFormat } from "../types.js";
import Database from "../api/index.js";
import { SQLCollection } from "../database/sql-collection.js";
import { isFalse } from "../database/index.js";
import { sql } from "@streetwriters/kysely";
dayjs.extend(isTomorrow);

View File

@@ -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/>.
*/
import { Cipher } from "@notesnook/crypto";
import { tinyToTiptap } from "../migrations";
import { makeSessionContentId } from "../utils/id";
import { ICollection } from "./collection";
import { isCipher } from "../database/crypto";
import Database from "../api";
import { ContentType, SessionContentItem, isDeleted } from "../types";
import { SQLCollection } from "../database/sql-collection";
export type NoteContent<TLocked extends boolean> = {
data: TLocked extends true ? Cipher<"base64"> : string;
type: ContentType;
};
import { tinyToTiptap } from "../migrations.js";
import { makeSessionContentId } from "../utils/id.js";
import { ICollection } from "./collection.js";
import { isCipher } from "../utils/crypto.js";
import Database from "../api/index.js";
import { NoteContent, SessionContentItem, isDeleted } from "../types.js";
import { SQLCollection } from "../database/sql-collection.js";
export class SessionContent implements ICollection {
name = "sessioncontent";

View File

@@ -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/>.
*/
import { makeId } from "../utils/id";
import Database from "../api";
import { makeId } from "../utils/id.js";
import Database from "../api/index.js";
import {
GroupOptions,
GroupingKey,
@@ -29,11 +29,11 @@ import {
SideBarSection,
ToolbarConfig,
ToolbarConfigPlatforms,
TrashCleanupInterval
} from "../types";
import { ICollection } from "./collection";
import { TimeFormat } from "../utils/date";
import { SQLCachedCollection } from "../database/sql-cached-collection";
TrashCleanupInterval,
TimeFormat
} from "../types.js";
import { ICollection } from "./collection.js";
import { SQLCachedCollection } from "../database/sql-cached-collection.js";
const DEFAULT_GROUP_OPTIONS = (key: GroupingKey) =>
({

View File

@@ -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/>.
*/
import Database from "../api";
import { SQLCachedCollection } from "../database/sql-cached-collection";
import { Notebook, Shortcut, Tag } from "../types";
import { ICollection } from "./collection";
import Database from "../api/index.js";
import { SQLCachedCollection } from "../database/sql-cached-collection.js";
import { Notebook, Shortcut, Tag } from "../types.js";
import { ICollection } from "./collection.js";
type ResolveTypeToItem<T extends "notebooks" | "tags" | "all"> =
T extends "tags"

View File

@@ -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/>.
*/
import { getId } from "../utils/id";
import { Tag } from "../types";
import Database from "../api";
import { ICollection } from "./collection";
import { SQLCollection } from "../database/sql-collection";
import { isFalse } from "../database";
import { getId } from "../utils/id.js";
import { Tag } 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 { sql } from "@streetwriters/kysely";
import { CHECK_IDS, checkIsUserPremium } from "../common";
import { CHECK_IDS, checkIsUserPremium } from "../common.js";
export class Tags implements ICollection {
name = "tags";
@@ -52,7 +52,7 @@ export class Tags implements ICollection {
}
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;
@@ -103,8 +103,8 @@ export class Tags implements ICollection {
exists(id: string) {
return this.collection.exists(id);
}
}
static sanitize(title: string) {
export function sanitizeTag(title: string) {
return title.replace(/^\s+|\s+$/gm, "");
}
}

View File

@@ -18,17 +18,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import dayjs from "dayjs";
import Database from "../api";
import { deleteItems, toChunks } from "../utils/array";
import { GroupOptions, TrashItem } from "../types";
import { VirtualizedGrouping } from "../utils/virtualized-grouping";
import Database from "../api/index.js";
import { deleteItems, toChunks } from "../utils/array.js";
import { GroupOptions, TrashItem } from "../types.js";
import { VirtualizedGrouping } from "../utils/virtualized-grouping.js";
import {
createKeySelector,
getSortSelectors,
groupArray
} from "../utils/grouping";
} from "../utils/grouping.js";
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 {
collections = ["notes", "notebooks"] as const;

View File

@@ -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/>.
*/
import Database from "../api";
import { ItemReference, Vault } from "../types";
import { ICollection } from "./collection";
import { SQLCollection } from "../database/sql-collection";
import { getId } from "../utils/id";
import { isFalse } from "../database";
import Database from "../api/index.js";
import { ItemReference, Vault } from "../types.js";
import { ICollection } from "./collection.js";
import { SQLCollection } from "../database/sql-collection.js";
import { getId } from "../utils/id.js";
import { isFalse } from "../database/index.js";
export class Vaults implements ICollection {
name = "vaults";

View File

@@ -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/>.
*/
import EventManager from "./utils/event-manager";
import EventManager from "./utils/event-manager.js";
export const EV = new EventManager();

View File

@@ -20,8 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import {
IMG_CONTENT,
IMG_CONTENT_WITHOUT_HASH
} from "../../../__tests__/utils";
import { Tiptap } from "../tiptap";
} from "../../../__tests__/utils/index.js";
import { Tiptap } from "../tiptap.js";
import { test, expect } from "vitest";
test("img src is empty after extract attachments", async () => {

View File

@@ -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/>.
*/
import { ContentType } from "../types";
import { Tiptap } from "./tiptap";
import { ContentType } from "../types.js";
import { Tiptap } from "./tiptap.js";
export function getContentFromData(type: ContentType, data: string) {
switch (type) {
@@ -30,3 +30,5 @@ export function getContentFromData(type: ContentType, data: string) {
);
}
}
export * from "./tiptap.js";

View File

@@ -27,22 +27,22 @@ import {
} from "html-to-text";
import { BlockTextBuilder } from "html-to-text/lib/block-text-builder";
import { parseDocument } from "htmlparser2";
import dataurl from "../utils/dataurl";
import dataurl from "../utils/dataurl.js";
import {
HTMLParser,
extractFirstParagraph,
getDummyDocument
} from "../utils/html-parser";
import { HTMLRewriter } from "../utils/html-rewriter";
import { ContentBlock } from "../types";
} from "../utils/html-parser.js";
import { HTMLRewriter } from "../utils/html-rewriter.js";
import { ContentBlock } from "../types.js";
import {
InternalLink,
isInternalLink,
parseInternalLink
} from "../utils/internal-link";
} from "../utils/internal-link.js";
import { Element } from "domhandler";
import { render } from "dom-serializer";
import { logger } from "../logger";
import { logger } from "../logger.js";
export type ResolveHashes = (
hashes: string[]

View File

@@ -32,8 +32,8 @@ import {
isDeleted
} from "../types.js";
import { Cipher, SerializedKey } from "@notesnook/crypto";
import { isCipher } from "./crypto.js";
import { migrateItem } from "../migrations";
import { isCipher } from "../utils/crypto.js";
import { migrateItem } from "../migrations.js";
import { DatabaseCollection } from "./index.js";
import { DefaultColors } from "../collections/colors.js";
import { toChunks } from "../utils/array.js";

View File

@@ -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/>.
*/
import { IndexedCollection } from "./indexed-collection";
import { IndexedCollection } from "./indexed-collection.js";
import {
CollectionType,
Collections,
ItemMap,
MaybeDeletedItem,
isDeleted
} from "../types";
import { StorageAccessor } from "../interfaces";
} from "../types.js";
import { StorageAccessor } from "../interfaces.js";
/**
* @deprecated only kept here for migration purposes

View File

@@ -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/>.
*/
import { DatabaseAccessor, RawDatabaseSchema } from ".";
import { DatabaseAccessor, RawDatabaseSchema } from "./index.js";
export class ConfigStorage {
private readonly db: DatabaseAccessor<RawDatabaseSchema>;

View File

@@ -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/>.
*/
import hosts from "../utils/constants";
import TokenManager from "../api/token-manager";
import hosts from "../utils/constants.js";
import TokenManager from "../api/token-manager.js";
import {
FileEncryptionMetadataWithOutputType,
IFileStorage
} from "../interfaces";
import { DataFormat, SerializedKey } from "@notesnook/crypto/dist/src/types";
import { EV, EVENTS } from "../common";
import { logger } from "../logger";
} from "../interfaces.js";
import { DataFormat, SerializedKey } from "@notesnook/crypto";
import { EV, EVENTS } from "../common.js";
import { logger } from "../logger.js";
export type FileStorageAccessor = () => FileStorage;
export type DownloadableFile = {

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Kysely, sql } from "@streetwriters/kysely";
import { RawDatabaseSchema } from ".";
import { RawDatabaseSchema } from "./index.js";
export async function rebuildSearchIndex(db: Kysely<RawDatabaseSchema>) {
await db.transaction().execute(async (tx) => {

View File

@@ -58,8 +58,8 @@ import {
ValueOf,
Vault,
isDeleted
} from "../types";
import { logger } from "../logger";
} from "../types.js";
import { logger } from "../logger.js";
// type FilteredKeys<T, U> = {
// [P in keyof T]: T[P] extends U ? P : never;

View File

@@ -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/>.
*/
import { toChunks } from "../utils/array";
import { StorageAccessor } from "../interfaces";
import { toChunks } from "../utils/array.js";
import { StorageAccessor } from "../interfaces.js";
import {
CollectionType,
Collections,
ItemMap,
MaybeDeletedItem
} from "../types";
import Indexer from "./indexer";
} from "../types.js";
import Indexer from "./indexer.js";
/**
* @deprecated only kept here for migration purposes

View File

@@ -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/>.
*/
import { StorageAccessor } from "../interfaces";
import { MaybeDeletedItem } from "../types";
import { StorageAccessor } from "../interfaces.js";
import { MaybeDeletedItem } from "../types.js";
export default class Indexer<T> {
private _indices: string[] = [];

View File

@@ -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/>.
*/
import { DatabaseAccessor, RawDatabaseSchema } from ".";
import { Token } from "../api/token-manager";
import { User } from "../types";
import { DatabaseAccessor, RawDatabaseSchema } from "./index.js";
import { Token } from "../api/token-manager.js";
import { User } from "../types.js";
interface KV {
v: number;

View File

@@ -25,7 +25,7 @@ import {
MigrationProvider,
sql
} from "@streetwriters/kysely";
import { rebuildSearchIndex } from "./fts";
import { rebuildSearchIndex } from "./fts.js";
const COLLATE_NOCASE: ColumnBuilderCallback = (col) =>
col.modifyEnd(sql`collate nocase`);

View File

@@ -18,18 +18,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Cipher } from "@notesnook/crypto";
import { DatabaseSchema } from ".";
import Database from "../api";
import { DatabaseSchema } from "./index.js";
import Database from "../api/index.js";
import {
CURRENT_DATABASE_VERSION,
sendMigrationProgressEvent
} from "../common";
} from "../common.js";
import {
migrateCollection,
migrateItem,
migrateKV,
migrateVaultKey
} from "../migrations";
} from "../migrations.js";
import {
CollectionType,
Collections,
@@ -38,10 +38,10 @@ import {
MaybeDeletedItem,
isDeleted,
isTrashItem
} from "../types";
import { IndexedCollection } from "./indexed-collection";
import { SQLCollection } from "./sql-collection";
import { logger } from "../logger";
} from "../types.js";
import { IndexedCollection } from "./indexed-collection.js";
import { SQLCollection } from "./sql-collection.js";
import { logger } from "../logger.js";
export type RawItem = MaybeDeletedItem<Item>;
type MigratableCollection = {

View File

@@ -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/>.
*/
import { DatabaseAccessor } from ".";
import { logger } from "../logger";
import { DatabaseAccessor } from "./index.js";
import { logger } from "../logger.js";
export class Sanitizer {
tables: Record<string, Set<string>> = {};

View File

@@ -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/>.
*/
import { MaybeDeletedItem, isDeleted } from "../types";
import EventManager from "../utils/event-manager";
import { DatabaseAccessor, DatabaseCollection, DatabaseSchema } from ".";
import { SQLCollection } from "./sql-collection";
import { MaybeDeletedItem, isDeleted } from "../types.js";
import EventManager from "../utils/event-manager.js";
import { DatabaseAccessor, DatabaseCollection, DatabaseSchema } from "./index.js";
import { SQLCollection } from "./sql-collection.js";
import { Kysely } from "@streetwriters/kysely";
import { Sanitizer } from "./sanitizer";
import { Sanitizer } from "./sanitizer.js";
export class SQLCachedCollection<
TCollectionType extends keyof DatabaseSchema,

View File

@@ -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/>.
*/
import { EVENTS } from "../common";
import { EVENTS } from "../common.js";
import {
GroupOptions,
Item,
MaybeDeletedItem,
SortOptions,
isDeleted
} from "../types";
import EventManager from "../utils/event-manager";
} from "../types.js";
import EventManager from "../utils/event-manager.js";
import {
DatabaseAccessor,
DatabaseCollection,
@@ -35,7 +35,7 @@ import {
UpdateEvent,
UpsertEvent,
isFalse
} from ".";
} from "./index.js";
import {
AliasedRawBuilder,
AnyColumn,
@@ -46,14 +46,14 @@ import {
SqlBool,
sql
} from "@streetwriters/kysely";
import { VirtualizedGrouping } from "../utils/virtualized-grouping";
import { createKeySelector, groupArray } from "../utils/grouping";
import { toChunks } from "../utils/array";
import { Sanitizer } from "./sanitizer";
import { VirtualizedGrouping } from "../utils/virtualized-grouping.js";
import { createKeySelector, groupArray } from "../utils/grouping.js";
import { toChunks } from "../utils/array.js";
import { Sanitizer } from "./sanitizer.js";
import {
createIsReminderActiveQuery,
createUpcomingReminderTimeQuery
} from "../collections/reminders";
} from "../collections/reminders.js";
const formats = {
month: "%Y-%m",

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Kysely, sql } from "@streetwriters/kysely";
import { DatabaseSchema, RawDatabaseSchema } from ".";
import { DatabaseSchema, RawDatabaseSchema } from "./index.js";
export async function createTriggers(db: Kysely<RawDatabaseSchema>) {
// content triggers

View File

@@ -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/>.
*/
export * from "./types";
export { VirtualizedGrouping } from "./utils/virtualized-grouping";
export { DefaultColors } from "./collections/colors";
export { type BackupFile, type LegacyBackupFile } from "./database/backup";
export * from "./types.js";
export * from "./interfaces.js";
export * from "./utils/index.js";
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 {
createInternalLink,
parseInternalLink,
type InternalLink
} from "./utils/internal-link";
export {
extractInternalLinks,
highlightInternalLinks,
type TextSlice
} from "./utils/content-block";
export { type DatabaseUpdatedEvent } from "./database";
export { isServerCompatible } from "./utils/constants";
getUpcomingReminder,
formatReminderTime,
isReminderToday,
isReminderActive
} from "./collections/reminders.js";
export * from "./logger.js";
export * from "./api/debug.js";
export * from "./api/monographs.js";
export * from "./api/subscriptions.js";
export * from "./api/pricing.js";
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";

View File

@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Cipher, DataFormat, SerializedKey } from "@notesnook/crypto";
import { KVStorage } from "./database/kv";
import { ConfigStorage } from "./database/config";
import { KVStorage } from "./database/kv.js";
import { ConfigStorage } from "./database/config.js";
export type Output<TOutputFormat extends DataFormat> =
TOutputFormat extends "uint8array" ? Uint8Array : string;

View File

@@ -29,8 +29,8 @@ import {
ILogger
} from "@notesnook/logger";
import { Kysely, Migration, MigrationProvider } from "@streetwriters/kysely";
import { SQLiteOptions, createDatabase } from "./database";
import { toChunks } from "./utils/array";
import { SQLiteOptions, createDatabase } from "./database/index.js";
import { toChunks } from "./utils/array.js";
const WEEK = 86400000 * 7;

View File

@@ -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/>.
*/
import { parseHTML } from "./utils/html-parser";
import { parseHTML } from "./utils/html-parser.js";
import { decodeHTML5 } from "entities";
import { CURRENT_DATABASE_VERSION } from "./common";
import Database from "./api";
import { makeId } from "./utils/id";
import { CURRENT_DATABASE_VERSION } from "./common.js";
import Database from "./api/index.js";
import { makeId } from "./utils/id.js";
import {
Color,
ContentItem,
@@ -33,12 +33,12 @@ import {
ToolbarConfigPlatforms,
isDeleted,
isGroupingKey
} from "./types";
import { isCipher } from "./database/crypto";
import { IndexedCollection } from "./database/indexed-collection";
import { DefaultColors } from "./collections/colors";
} from "./types.js";
import { isCipher } from "./utils/crypto.js";
import { IndexedCollection } from "./database/indexed-collection.js";
import { DefaultColors } from "./collections/colors.js";
import { Cipher } from "@notesnook/crypto";
import { KEYS } from "./database/kv";
import { KEYS } from "./database/kv.js";
type MigrationType = "local" | "sync" | "backup";
type MigrationItemType = ItemType | "notehistory" | "content" | "never";

View File

@@ -18,7 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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 = {
sortBy:
@@ -567,3 +569,20 @@ export type ContentBlock = {
type: 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);
}

View File

@@ -22,8 +22,8 @@ import {
extractInternalLinks,
highlightInternalLinks,
ellipsize
} from "../content-block";
import { ContentBlock } from "../../types";
} from "../content-block.js";
import { ContentBlock } from "../../types.js";
describe("ContentBlock Utils", () => {
describe("extractInternalLinks", () => {

View File

@@ -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/>.
*/
import { isHTMLEqual } from "../html-diff";
import { isHTMLEqual } from "../html-diff.js";
import { test, expect, describe } from "vitest";
const equalPairs = [

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { expect, test } from "vitest";
import { transformQuery } from "../query-transformer";
import { transformQuery } from "../query-transformer.js";
const TRANSFORM_QUERY_TESTS = [
["hello world", `"hello world"`],

View File

@@ -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/>.
*/
import { set } from "../set";
import { set } from "../set.js";
import { test, expect } from "vitest";
test("union", () => {

View File

@@ -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/>.
*/
import { formatTitle } from "../title-format";
import { formatTitle } from "../title-format.js";
import MockDate from "mockdate";
import { test, expect, describe, beforeAll, afterAll } from "vitest";

View File

@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { test } from "vitest";
import { VirtualizedGrouping } from "../virtualized-grouping";
import { groupArray } from "../grouping";
import { VirtualizedGrouping } from "../virtualized-grouping.js";
import { groupArray } from "../grouping.js";
function generateItems(length: number, groupSize: number) {
const items: { group: string; id: string }[] = [];

View File

@@ -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/>.
*/
import { extractHostname } from "./hostname";
import { extractHostname } from "./hostname.js";
const COMPATIBLE_SERVER_VERSION = 1;

View File

@@ -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/>.
*/
import { ContentBlock } from "../types";
import { InternalLinkWithOffset, parseInternalLink } from "./internal-link";
import { ContentBlock } from "../types.js";
import { InternalLinkWithOffset, parseInternalLink } from "./internal-link.js";
const INTERNAL_LINK_REGEX = /(?:\[\[(nn:\/\/note\/.+?)\]\])/gm;
export function extractInternalLinks(block: ContentBlock) {

View File

@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Cipher } from "@notesnook/crypto";
import { StorageAccessor } from "../interfaces";
import { randomBytes } from "../utils/random";
import { StorageAccessor } from "../interfaces.js";
import { randomBytes } from "./random.js";
export type CryptoAccessor = () => Crypto;
export class Crypto {

Some files were not shown because too many files have changed in this diff Show More