mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
core: fix The item must contain the id field. error on migration
This commit is contained in:
@@ -105,6 +105,8 @@ export class Settings implements ICollection {
|
||||
value: SettingItemMap[TKey]
|
||||
) {
|
||||
const id = KEY_IDS[key];
|
||||
if (!id) throw new Error(`Invalid settings key: ${key}.`);
|
||||
|
||||
const oldItem = this.collection.get(id);
|
||||
if (oldItem && oldItem.key !== key) throw new Error("Key conflict.");
|
||||
|
||||
|
||||
@@ -25,14 +25,14 @@ import { makeId } from "./utils/id";
|
||||
import {
|
||||
Color,
|
||||
ContentItem,
|
||||
GroupingKey,
|
||||
HistorySession,
|
||||
Item,
|
||||
ItemMap,
|
||||
ItemType,
|
||||
MaybeDeletedItem,
|
||||
ToolbarConfigPlatforms,
|
||||
isDeleted
|
||||
isDeleted,
|
||||
isGroupingKey
|
||||
} from "./types";
|
||||
import { isCipher } from "./database/crypto";
|
||||
import { IndexedCollection } from "./database/indexed-collection";
|
||||
@@ -390,9 +390,10 @@ const migrations: Migration[] = [
|
||||
|
||||
if (item.groupOptions) {
|
||||
for (const key in item.groupOptions) {
|
||||
const value = item.groupOptions[key as GroupingKey];
|
||||
if (!isGroupingKey(key)) continue;
|
||||
const value = item.groupOptions[key];
|
||||
if (!value) continue;
|
||||
await db.settings.setGroupOptions(key as GroupingKey, value);
|
||||
await db.settings.setGroupOptions(key, value);
|
||||
}
|
||||
}
|
||||
if (item.toolbarConfig) {
|
||||
|
||||
@@ -40,14 +40,16 @@ export type GroupOptions = SortOptions & {
|
||||
|
||||
export type GroupedItems<T> = (T | GroupHeader)[];
|
||||
|
||||
export type GroupingKey =
|
||||
| "home"
|
||||
| "notes"
|
||||
| "notebooks"
|
||||
| "tags"
|
||||
| "trash"
|
||||
| "favorites"
|
||||
| "reminders";
|
||||
export const GroupingKey = [
|
||||
"home",
|
||||
"notes",
|
||||
"notebooks",
|
||||
"tags",
|
||||
"trash",
|
||||
"favorites",
|
||||
"reminders"
|
||||
] as const;
|
||||
export type GroupingKey = (typeof GroupingKey)[number];
|
||||
|
||||
export type ValueOf<T> = T[keyof T];
|
||||
export type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
||||
@@ -552,6 +554,10 @@ export function isGroupHeader(item: any): item is GroupHeader {
|
||||
return item.type === "header";
|
||||
}
|
||||
|
||||
export function isGroupingKey(key: any): key is GroupingKey {
|
||||
return GroupingKey.includes(key);
|
||||
}
|
||||
|
||||
export type ContentBlock = {
|
||||
content: string;
|
||||
type: string;
|
||||
|
||||
Reference in New Issue
Block a user