LoopKitBackend
Module Setup
Register and configure the LoopKit NestJS module
Registration
Use LoopKitModule.register() to add LoopKit to your NestJS application:
import { Module } from '@nestjs/common';
import {
LoopKitModule,
PrismaLoopKitAdapter,
createContentPipeline,
createMarkdownTransform,
createSanitizeTransform,
} from '@loopkit/nestjs';
import { parse } from 'marked';
import sanitize from 'sanitize-html';
@Module({
imports: [
LoopKitModule.register({
storage: new PrismaLoopKitAdapter(prismaClient),
// Optional: custom SRS algorithm (defaults to SM2Algorithm)
// algorithm: new MyCustomAlgorithm(),
// Optional: content pipeline with transforms
contentPipeline: createContentPipeline([
createMarkdownTransform({ parse }),
createSanitizeTransform(sanitize),
]),
}),
],
})
export class AppModule {}Options
interface LoopKitModuleOptions {
storage: LoopKitStorage; // Required — storage adapter
algorithm?: SRSAlgorithm; // Optional — defaults to SM2Algorithm
contentPipeline?: ContentPipeline; // Optional — defaults to basic interpolation
}| Option | Type | Default | Description |
|---|---|---|---|
storage | LoopKitStorage | — | Storage adapter (e.g., PrismaLoopKitAdapter) |
algorithm | SRSAlgorithm | SM2Algorithm | Spaced repetition algorithm |
contentPipeline | ContentPipeline | Basic interpolation | Content rendering pipeline |
Injection Tokens
Two injection tokens are available for advanced use cases:
import { Inject } from '@nestjs/common';
import { SRS_ALGORITHM, CONTENT_PIPELINE } from '@loopkit/nestjs';
import type { SRSAlgorithm, ContentPipeline } from '@loopkit/nestjs';
@Injectable()
export class MyService {
constructor(
@Inject(SRS_ALGORITHM) private readonly algorithm: SRSAlgorithm,
@Inject(CONTENT_PIPELINE) private readonly pipeline: ContentPipeline,
) {}
}Exported Services
All services are automatically exported and injectable in any module that imports LoopKitModule:
ReviewSessionServiceDeckServiceNoteServiceNoteTypeServiceImportExportServiceCardGeneratorLoopKitStorage(the adapter instance)