@palbase/backend
v41.3.2
Published
Palbase Backend SDK — class controllers (@Controller/@Get/@Post + @Body/@QueryParams/@Param), error classes, schema DSL
Readme
@palbase/backend
The backend SDK for Palbase. Write TypeScript class controllers, services, and
schema that run in the Palbase managed runtime as a typed HTTP API — a
@Module says what exists, who owns it, and what it may reach; a class no
module lists does not exist.
// modules/notes/dto/create.ts
// The request and response schemas, each a value AND a same-named type.
import { z } from "@palbase/backend";
export const CreateNoteBody = z.object({ body: z.string().min(1) });
export type CreateNoteBody = z.infer<typeof CreateNoteBody>;
export const NoteSchema = z.object({ id: z.string(), body: z.string() });
export type NoteSchema = z.infer<typeof NoteSchema>;// modules/notes/notes.service.ts
// `@Injectable()` classes. The real work.
import { Database, Injectable } from "@palbase/backend";
import { NoteSchema } from "./dto/create";
@Injectable()
export class NoteService {
create(userId: string, body: string): Promise<NoteSchema> {
return Database.public.notes.insert({ user_id: userId, body });
}
}// modules/notes/notes.controller.ts
// The `@Controller` class. It never imports `Database`.
import { Body, Controller, Post, User } from "@palbase/backend";
import type { UserT } from "@palbase/backend";
import { CreateNoteBody, NoteSchema } from "./dto/create";
import { NoteService } from "./notes.service";
@Controller("/notes")
export class NotesController {
constructor(private readonly notes: NoteService) {}
@Post("")
create(@Body(CreateNoteBody) body: CreateNoteBody, @User() user: UserT): Promise<NoteSchema> {
return this.notes.create(user.id, body.body);
}
}// modules/notes/notes.module.ts
// Lists them. Nothing is wired by hand.
import { Module } from "@palbase/backend";
import { NotesController } from "./notes.controller";
import { NoteService } from "./notes.service";
@Module({
controllers: [NotesController],
providers: [NoteService],
})
export class NotesModule {}Documentation
Start with docs/README.md. For AI coding tools, a single
concatenated corpus is generated at docs/llms-full.txt.
See MIGRATION.md for breaking-change notes between major
versions.
License
MIT
