feat: add models package

This commit is contained in:
Karol Sójko
2022-07-05 20:47:11 +02:00
parent 60d1554ff7
commit b614c71e79
199 changed files with 8772 additions and 22 deletions

View File

@@ -0,0 +1,80 @@
import { TagContent } from './../../Syncable/Tag/Tag'
import { ContentType } from '@standardnotes/common'
import { FillItemContent, ItemContent } from '../../Abstract/Content/ItemContent'
import { DecryptedPayload, PayloadSource, PayloadTimestampDefaults } from '../../Abstract/Payload'
import { FileContent, FileItem } from '../../Syncable/File'
import { NoteContent, SNNote } from '../../Syncable/Note'
import { SNTag } from '../../Syncable/Tag'
let currentId = 0
export const mockUuid = () => {
return `${currentId++}`
}
export const createNote = (payload?: Partial<NoteContent>): SNNote => {
return new SNNote(
new DecryptedPayload(
{
uuid: mockUuid(),
content_type: ContentType.Note,
content: FillItemContent({ ...payload }),
...PayloadTimestampDefaults(),
},
PayloadSource.Constructor,
),
)
}
export const createNoteWithContent = (content: Partial<NoteContent>, createdAt?: Date): SNNote => {
return new SNNote(
new DecryptedPayload(
{
uuid: mockUuid(),
content_type: ContentType.Note,
content: FillItemContent<NoteContent>(content),
...PayloadTimestampDefaults(),
created_at: createdAt || new Date(),
},
PayloadSource.Constructor,
),
)
}
export const createTag = (title = 'photos') => {
return new SNTag(
new DecryptedPayload(
{
uuid: mockUuid(),
content_type: ContentType.Tag,
content: FillItemContent<TagContent>({ title }),
...PayloadTimestampDefaults(),
},
PayloadSource.Constructor,
),
)
}
export const createFile = (name = 'screenshot.png') => {
return new FileItem(
new DecryptedPayload(
{
uuid: mockUuid(),
content_type: ContentType.File,
content: FillItemContent<FileContent>({ name }),
...PayloadTimestampDefaults(),
},
PayloadSource.Constructor,
),
)
}
export const pinnedContent = (): Partial<ItemContent> => {
return {
appData: {
'org.standardnotes.sn': {
pinned: true,
},
},
}
}