LoopKitBackend
Notes & Note Types
Create study materials with NoteService and NoteTypeService
NoteService
Manages study notes. When a note is created, cards are automatically generated based on its note type's templates.
createNote
async createNote(input: CreateNoteInput, deckId: string): Promise<NoteBase>- Validates the note against its note type's field schema
- Creates the note in storage
- Automatically generates cards for each template in the note type
- Cards are initialized with the SRS algorithm's initial state
interface CreateNoteInput {
noteTypeId: string;
fields: Field[]; // { name, value, ordinal }
tags?: string[];
}Example:
const note = await noteService.createNote(
{
noteTypeId: 'basic-type-id',
fields: [
{ name: 'Front', value: 'What is TypeScript?', ordinal: 0 },
{ name: 'Back', value: 'A typed superset of JavaScript', ordinal: 1 },
],
tags: ['programming', 'typescript'],
},
'target-deck-id',
);updateNote
async updateNote(id: string, input: UpdateNoteInput): Promise<NoteBase>deleteNote
async deleteNote(id: string): Promise<void>Cascade-deletes all cards associated with the note.
moveNoteToDeck
async moveNoteToDeck(noteId: string, newDeckId: string): Promise<void>Updates all cards belonging to this note to the new deck.
NoteTypeService
Manages note type definitions (field schemas and card templates).
createNoteType
async createNoteType(input: CreateNoteTypeInput): Promise<NoteType>interface CreateNoteTypeInput {
name: string;
fields: FieldDef[];
templates: TemplateDef[];
}addTemplate
async addTemplate(noteTypeId: string, template: TemplateDef): Promise<NoteType>Adds a template and retroactively generates cards for all existing notes of this type.
removeTemplate
async removeTemplate(noteTypeId: string, templateId: string): Promise<NoteType>Removes a template and deletes all cards generated from it.
seedDefaults
async seedDefaults(): Promise<void>Creates two default note types if they don't already exist:
Basic:
- Fields:
Front(required),Back(required) - Template: Front shows
{{Front}}, Back shows{{FrontSide}}<hr>{{Back}}
Basic + Reverse:
- Same fields as Basic
- Two templates: one forward (Front → Back) and one reverse (Back → Front)