core: shorcuts -> shortcuts

This commit is contained in:
Abdullah Atta
2022-09-07 14:13:26 +05:00
parent 1e99d7732c
commit ac7aad93b3
9 changed files with 29 additions and 29 deletions

View File

@@ -26,56 +26,56 @@ beforeEach(() => {
test("create a shortcut of an invalid item should throw", () => test("create a shortcut of an invalid item should throw", () =>
databaseTest().then(async (db) => { databaseTest().then(async (db) => {
await expect(() => await expect(() =>
db.shorcuts.add({ item: { type: "HELLO!" } }) db.shortcuts.add({ item: { type: "HELLO!" } })
).rejects.toThrow(/cannot create a shortcut/i); ).rejects.toThrow(/cannot create a shortcut/i);
})); }));
test("create a shortcut of notebook", () => test("create a shortcut of notebook", () =>
notebookTest().then(async ({ db, id }) => { notebookTest().then(async ({ db, id }) => {
await db.shorcuts.add({ item: { type: "notebook", id } }); await db.shortcuts.add({ item: { type: "notebook", id } });
expect(db.shorcuts.exists(id)).toBe(true); expect(db.shortcuts.exists(id)).toBe(true);
expect(db.shorcuts.all[0].item.id).toBe(id); expect(db.shortcuts.all[0].item.id).toBe(id);
})); }));
test("create a duplicate shortcut of notebook", () => test("create a duplicate shortcut of notebook", () =>
notebookTest().then(async ({ db, id }) => { notebookTest().then(async ({ db, id }) => {
await db.shorcuts.add({ item: { type: "notebook", id } }); await db.shortcuts.add({ item: { type: "notebook", id } });
await db.shorcuts.add({ item: { type: "notebook", id } }); await db.shortcuts.add({ item: { type: "notebook", id } });
expect(db.shorcuts.all).toHaveLength(1); expect(db.shortcuts.all).toHaveLength(1);
expect(db.shorcuts.all[0].item.id).toBe(id); expect(db.shortcuts.all[0].item.id).toBe(id);
})); }));
test("create shortcut of a topic", () => test("create shortcut of a topic", () =>
notebookTest().then(async ({ db, id }) => { notebookTest().then(async ({ db, id }) => {
const notebook = db.notebooks.notebook(id)._notebook; const notebook = db.notebooks.notebook(id)._notebook;
const topic = notebook.topics[0]; const topic = notebook.topics[0];
await db.shorcuts.add({ await db.shortcuts.add({
item: { type: "topic", id: topic.id, notebookId: id } item: { type: "topic", id: topic.id, notebookId: id }
}); });
expect(db.shorcuts.all).toHaveLength(1); expect(db.shortcuts.all).toHaveLength(1);
expect(db.shorcuts.all[0].item.id).toBe(topic.id); expect(db.shortcuts.all[0].item.id).toBe(topic.id);
})); }));
test("pin a tag", () => test("pin a tag", () =>
databaseTest().then(async (db) => { databaseTest().then(async (db) => {
const tag = await db.tags.add("HELLO!"); const tag = await db.tags.add("HELLO!");
await db.shorcuts.add({ item: { type: "tag", id: tag.id } }); await db.shortcuts.add({ item: { type: "tag", id: tag.id } });
expect(db.shorcuts.all).toHaveLength(1); expect(db.shortcuts.all).toHaveLength(1);
expect(db.shorcuts.all[0].item.id).toBe(tag.id); expect(db.shortcuts.all[0].item.id).toBe(tag.id);
})); }));
test("remove shortcut", () => test("remove shortcut", () =>
databaseTest().then(async (db) => { databaseTest().then(async (db) => {
const tag = await db.tags.add("HELLO!"); const tag = await db.tags.add("HELLO!");
const shortcutId = await db.shorcuts.add({ const shortcutId = await db.shortcuts.add({
item: { type: "tag", id: tag.id } item: { type: "tag", id: tag.id }
}); });
expect(db.shorcuts.all).toHaveLength(1); expect(db.shortcuts.all).toHaveLength(1);
await db.shorcuts.remove(shortcutId); await db.shortcuts.remove(shortcutId);
expect(db.shorcuts.all).toHaveLength(0); expect(db.shortcuts.all).toHaveLength(0);
})); }));

View File

@@ -141,7 +141,7 @@ class Database {
/**@type {NoteHistory} */ /**@type {NoteHistory} */
this.noteHistory = await NoteHistory.new(this, "notehistory", false); this.noteHistory = await NoteHistory.new(this, "notehistory", false);
/**@type {Shortcuts} */ /**@type {Shortcuts} */
this.shorcuts = await Shortcuts.new(this, "shorcuts"); this.shortcuts = await Shortcuts.new(this, "shortcuts");
this.trash = new Trash(this); this.trash = new Trash(this);

View File

@@ -76,8 +76,8 @@ class Migrations {
type: "settings" type: "settings"
}, },
{ {
index: this._db.shorcuts.raw, index: this._db.shortcuts.raw,
dbCollection: this._db.shorcuts dbCollection: this._db.shortcuts
}, },
{ {
index: this._db.notes.raw, index: this._db.notes.raw,

View File

@@ -38,7 +38,7 @@ class Collector {
const items = [ const items = [
...this._collect("note", this._db.notes.raw, isForceSync), ...this._collect("note", this._db.notes.raw, isForceSync),
...this._collect("shortcut", this._db.shorcuts.raw, isForceSync), ...this._collect("shortcut", this._db.shortcuts.raw, isForceSync),
...this._collect("notebook", this._db.notebooks.raw, isForceSync), ...this._collect("notebook", this._db.notebooks.raw, isForceSync),
...this._collect("content", await this._db.content.all(), isForceSync), ...this._collect("content", await this._db.content.all(), isForceSync),
...this._collect( ...this._collect(

View File

@@ -44,8 +44,8 @@ class Merger {
set: (item) => this._db.notes.merge(item) set: (item) => this._db.notes.merge(item)
}, },
shortcut: { shortcut: {
get: (id) => this._db.shorcuts.shortcut(id), get: (id) => this._db.shortcuts.shortcut(id),
set: (item) => this._db.shorcuts.merge(item) set: (item) => this._db.shortcuts.merge(item)
}, },
notebook: { notebook: {
threshold: 1000, threshold: 1000,

View File

@@ -165,7 +165,7 @@ export default class Notebooks extends Collection {
const notebookData = qclone(notebook.data); const notebookData = qclone(notebook.data);
await notebook.topics.delete(...notebook.data.topics); await notebook.topics.delete(...notebook.data.topics);
await this._collection.removeItem(id); await this._collection.removeItem(id);
await this._db.settings.unpin(id); await this._db.shortcuts.remove(id);
await this._db.trash.add(notebookData); await this._db.trash.add(notebookData);
} }
} }

View File

@@ -120,7 +120,7 @@ export default class Tags extends Collection {
if (hasItem(note.tags, tag.title)) await note.untag(tag.title); if (hasItem(note.tags, tag.title)) await note.untag(tag.title);
} }
await this._db.settings.unpin(tagId); await this._db.shortcuts.remove(tagId);
await this._collection.deleteItem(tagId); await this._collection.deleteItem(tagId);
} }
@@ -135,7 +135,7 @@ export default class Tags extends Collection {
if (tag.noteIds.length > 0) await this._collection.addItem(tag); if (tag.noteIds.length > 0) await this._collection.addItem(tag);
else { else {
await this._db.settings.unpin(tag.id); await this._db.shortcuts.remove(tag.id);
await this._collection.deleteItem(tag.id); await this._collection.deleteItem(tag.id);
} }
} }

View File

@@ -117,7 +117,7 @@ export default class Topics {
if (!topic) continue; if (!topic) continue;
await topic.delete(...topic._topic.notes); await topic.delete(...topic._topic.notes);
await this._db.settings.unpin(topicId); await this._db.shortcuts.remove(topicId);
const topicIndex = allTopics.findIndex( const topicIndex = allTopics.findIndex(
(t) => t.id === topicId || t.title === topicId (t) => t.id === topicId || t.title === topicId

View File

@@ -171,7 +171,7 @@ export default class Backup {
}, },
{ {
index: data["shortcuts"], index: data["shortcuts"],
dbCollection: this._db.shorcuts dbCollection: this._db.shortcuts
}, },
{ {
index: data["notes"], index: data["notes"],