@thescaffold/editor-nestjs
v0.2.0
Published
NestJS module wrapping @thescaffold/editor-server for collaborative editing
Downloads
163
Readme
@thescaffold/editor-nestjs
NestJS module that wraps @thescaffold/editor-server, providing a CollabService, a WebSocket CollabGateway, and a REST CollabController for document management — ready to drop into any NestJS application.
Installation
npm install @thescaffold/editor-nestjs @thescaffold/editor-server @nestjs/websockets @nestjs/platform-wsQuick Start
// app.module.ts
import { Module } from "@nestjs/common";
import { XEditorCollabModule } from "@thescaffold/editor-nestjs";
import { MemoryAdapter, PostgresAdapter } from "@thescaffold/editor-server";
@Module({
imports: [
XEditorCollabModule.forRoot({
path: "/collab",
persistence: new PostgresAdapter({
connectionString: process.env.DATABASE_URL,
}),
}),
],
})
export class AppModule {}Async configuration
XEditorCollabModule.forRootAsync({
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
path: "/collab",
persistence: new PostgresAdapter({
connectionString: config.get("DATABASE_URL"),
}),
auth: new JwtAuthAdapter({ secret: config.get("JWT_SECRET") }),
}),
});REST Endpoints
The CollabController registers these routes under /collab/documents:
| Method | Path | Description |
| -------- | ------------------------ | -------------------------- |
| GET | /:id | Check if a document exists |
| POST | /:id | Create a document |
| DELETE | /:id | Delete a document |
| GET | /:id/snapshots | List snapshots |
| POST | /:id/snapshots | Create snapshot |
| POST | /:id/snapshots/restore | Restore a snapshot |
CollabService
Inject CollabService to manage documents programmatically:
import { Injectable } from "@nestjs/common";
import { CollabService } from "@thescaffold/editor-nestjs";
@Injectable()
export class DocsService {
constructor(private readonly collab: CollabService) {}
async createNewDoc(id: string): Promise<void> {
await this.collab.createDocument(id);
}
}WebSocket
The CollabGateway wires @thescaffold/editor-server's WebSocket handling into NestJS automatically. Clients connect using:
ws://your-server/collab?doc=<document-id>License
MIT
