chore: fix ContentType usage (#2353)

* chore: fix ContentType usage

* chore: fix specs
This commit is contained in:
Karol Sójko
2023-07-12 13:53:29 +02:00
committed by GitHub
parent d057cdff84
commit 325737bfbd
247 changed files with 1092 additions and 1060 deletions

View File

@@ -15,7 +15,8 @@
"test": "jest spec"
},
"dependencies": {
"@standardnotes/common": "^1.48.3",
"@standardnotes/common": "^1.50.0",
"@standardnotes/domain-core": "^1.22.0",
"@standardnotes/features": "workspace:^",
"@standardnotes/filepicker": "workspace:^",
"@standardnotes/models": "workspace:^",

View File

@@ -5,7 +5,7 @@ import {
EncryptedItemInterface,
NoteContent,
} from '@standardnotes/models'
import { ContentType } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
import { ApplicationInterface } from '@standardnotes/services'
export function sanitizeFileName(name: string): string {
@@ -87,7 +87,7 @@ export class ArchiveManager {
const item = items[index]
let name, contents
if (item.content_type === ContentType.Note) {
if (item.content_type === ContentType.TYPES.Note) {
const note = item as BackupFileDecryptedContextualPayload<NoteContent>
name = note.content.title
contents = note.content.text

View File

@@ -1,8 +1,8 @@
import { DecryptedTransferPayload, NoteContent } from '@standardnotes/models'
import { ContentType } from '@standardnotes/common'
import { readFileAsText } from '../Utils'
import { FeatureIdentifier, NoteType } from '@standardnotes/features'
import { WebApplicationInterface } from '../../WebApplication/WebApplicationInterface'
import { ContentType } from '@standardnotes/domain-core'
type AegisData = {
db: {
@@ -62,7 +62,7 @@ export class AegisToAuthenticatorConverter {
updated_at: new Date(file.lastModified),
updated_at_timestamp: file.lastModified,
uuid: this.application.generateUUID(),
content_type: ContentType.Note,
content_type: ContentType.TYPES.Note,
content: {
title: file.name.split('.')[0],
text: JSON.stringify(entries),

View File

@@ -2,7 +2,7 @@
* @jest-environment jsdom
*/
import { ContentType } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
import { DecryptedTransferPayload, NoteContent, TagContent } from '@standardnotes/models'
import { EvernoteConverter } from './EvernoteConverter'
import data from './testData'
@@ -37,13 +37,13 @@ describe('EvernoteConverter', () => {
expect(result).not.toBeNull()
expect(result?.length).toBe(3)
expect(result?.[0].content_type).toBe(ContentType.Note)
expect(result?.[0].content_type).toBe(ContentType.TYPES.Note)
expect((result?.[0] as DecryptedTransferPayload<NoteContent>).content.text).toBe('This is a test.')
expect(result?.[1].content_type).toBe(ContentType.Note)
expect(result?.[1].content_type).toBe(ContentType.TYPES.Note)
expect((result?.[1] as DecryptedTransferPayload<NoteContent>).content.text).toBe(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
)
expect(result?.[2].content_type).toBe(ContentType.Tag)
expect(result?.[2].content_type).toBe(ContentType.TYPES.Tag)
expect((result?.[2] as DecryptedTransferPayload<TagContent>).content.title).toBe('evernote')
expect((result?.[2] as DecryptedTransferPayload<TagContent>).content.references.length).toBe(2)
expect((result?.[2] as DecryptedTransferPayload<TagContent>).content.references[0].uuid).toBe(result?.[0].uuid)
@@ -57,13 +57,13 @@ describe('EvernoteConverter', () => {
expect(result).not.toBeNull()
expect(result?.length).toBe(3)
expect(result?.[0].content_type).toBe(ContentType.Note)
expect(result?.[0].content_type).toBe(ContentType.TYPES.Note)
expect((result?.[0] as DecryptedTransferPayload<NoteContent>).content.text).toBe('<div>This is a test.</div>')
expect(result?.[1].content_type).toBe(ContentType.Note)
expect(result?.[1].content_type).toBe(ContentType.TYPES.Note)
expect((result?.[1] as DecryptedTransferPayload<NoteContent>).content.text).toBe(
'<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>',
)
expect(result?.[2].content_type).toBe(ContentType.Tag)
expect(result?.[2].content_type).toBe(ContentType.TYPES.Tag)
expect((result?.[2] as DecryptedTransferPayload<TagContent>).content.title).toBe('evernote')
expect((result?.[2] as DecryptedTransferPayload<TagContent>).content.references.length).toBe(2)
expect((result?.[2] as DecryptedTransferPayload<TagContent>).content.references[0].uuid).toBe(result?.[0].uuid)

View File

@@ -1,10 +1,10 @@
import { ContentType } from '@standardnotes/common'
import { DecryptedTransferPayload, NoteContent, TagContent } from '@standardnotes/models'
import { readFileAsText } from '../Utils'
import dayjs from 'dayjs'
import customParseFormat from 'dayjs/plugin/customParseFormat'
import utc from 'dayjs/plugin/utc'
import { WebApplicationInterface } from '../../WebApplication/WebApplicationInterface'
import { ContentType } from '@standardnotes/domain-core'
dayjs.extend(customParseFormat)
dayjs.extend(utc)
@@ -36,7 +36,7 @@ export class EvernoteConverter {
updated_at: now,
updated_at_timestamp: now.getTime(),
uuid: this.application.generateUUID(),
content_type: ContentType.Tag,
content_type: ContentType.TYPES.Tag,
content: {
title: defaultTagName,
expanded: false,
@@ -89,7 +89,7 @@ export class EvernoteConverter {
updated_at: updatedAtDate,
updated_at_timestamp: updatedAtDate.getTime(),
uuid: this.application.generateUUID(),
content_type: ContentType.Note,
content_type: ContentType.TYPES.Note,
content: {
title: !title ? `Imported note ${index + 1} from Evernote` : title,
text,
@@ -99,7 +99,7 @@ export class EvernoteConverter {
if (defaultTag) {
defaultTag.content.references.push({
content_type: ContentType.Note,
content_type: ContentType.TYPES.Note,
uuid: note.uuid,
})
}
@@ -112,7 +112,7 @@ export class EvernoteConverter {
const now = new Date()
tag = {
uuid: this.application.generateUUID(),
content_type: ContentType.Tag,
content_type: ContentType.TYPES.Tag,
created_at: now,
created_at_timestamp: now.getTime(),
updated_at: now,

View File

@@ -1,4 +1,4 @@
import { ContentType } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
import { DecryptedTransferPayload, NoteContent } from '@standardnotes/models'
import { readFileAsText } from '../Utils'
import { WebApplicationInterface } from '../../WebApplication/WebApplicationInterface'
@@ -67,7 +67,7 @@ export class GoogleKeepConverter {
updated_at: date,
updated_at_timestamp: date.getTime(),
uuid: this.application.generateUUID(),
content_type: ContentType.Note,
content_type: ContentType.TYPES.Note,
content: {
title: title,
text: content,
@@ -121,7 +121,7 @@ export class GoogleKeepConverter {
updated_at: date,
updated_at_timestamp: date.getTime(),
uuid: this.application.generateUUID(),
content_type: ContentType.Note,
content_type: ContentType.TYPES.Note,
content: {
title: parsed.title,
text: parsed.textContent,

View File

@@ -1,4 +1,4 @@
import { ContentType } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
import { parseFileName } from '@standardnotes/filepicker'
import { DecryptedTransferPayload, NoteContent } from '@standardnotes/models'
import { readFileAsText } from '../Utils'
@@ -25,7 +25,7 @@ export class PlaintextConverter {
updated_at: updatedAtDate,
updated_at_timestamp: updatedAtDate.getTime(),
uuid: this.application.generateUUID(),
content_type: ContentType.Note,
content_type: ContentType.TYPES.Note,
content: {
title: name,
text: content,

View File

@@ -1,5 +1,5 @@
import { DecryptedTransferPayload, NoteContent } from '@standardnotes/models'
import { ContentType } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
import { readFileAsText } from '../Utils'
import { WebApplicationInterface } from '../../WebApplication/WebApplicationInterface'
@@ -54,7 +54,7 @@ export class SimplenoteConverter {
updated_at: updatedAtDate,
updated_at_timestamp: updatedAtDate.getTime(),
uuid: this.application.generateUUID(),
content_type: ContentType.Note,
content_type: ContentType.TYPES.Note,
content: {
title,
text: content,

View File

@@ -1,5 +1,5 @@
import { dismissToast, ToastType, addTimedToast } from '@standardnotes/toast'
import { ContentType } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
import {
CreateDecryptedLocalStorageContextPayload,
LocalStorageDecryptedContextualPayload,
@@ -136,7 +136,7 @@ export class ThemeManager extends AbstractUIServicee {
}
}
const activeThemes = (this.application.items.getItems(ContentType.Theme) as SNTheme[]).filter(
const activeThemes = (this.application.items.getItems(ContentType.TYPES.Theme) as SNTheme[]).filter(
(theme) => theme.active,
)
@@ -244,7 +244,7 @@ export class ThemeManager extends AbstractUIServicee {
}
})
this.unregisterStream = this.application.streamItems(ContentType.Theme, ({ changed, inserted, source }) => {
this.unregisterStream = this.application.streamItems(ContentType.TYPES.Theme, ({ changed, inserted, source }) => {
const items = changed.concat(inserted)
const themes = items as SNTheme[]
for (const theme of themes) {