1import * as Schema from "effect/Schema";
2import * as HttpApi from "effect/http-api/HttpApi";
3import * as HttpApiEndpoint from "effect/http-api/HttpApiEndpoint";
4import * as HttpApiGroup from "effect/http-api/HttpApiGroup";
5import * as HttpApiSchema from "effect/http-api/HttpApiSchema";
6
7export class Note extends Schema.Class<Note>("Note")({
8 id: Schema.String,
9 title: Schema.String,
10 source: Schema.String,
11 createdAt: Schema.Number,
12}) {}
13
14export class NotesList extends Schema.Class<NotesList>("NotesList")({
15 notes: Schema.Array(Note),
16}) {}
17
18export const listNotes = HttpApiEndpoint.get("listNotes", "/notes", {
19 success: NotesList,
20});
21
22export const createNote = HttpApiEndpoint.post("createNote", "/notes", {
23 success: Note.pipe(HttpApiSchema.status(201)),
24 payload: Schema.Struct({
25 title: Schema.String,
26 }),
27});
28
29export const deleteNote = HttpApiEndpoint.delete("deleteNote", "/notes/:id", {
30 params: Schema.Struct({
31 id: Schema.String,
32 }),
33 success: HttpApiSchema.NoContent,
34});
35
36export class BackendGroup extends HttpApiGroup.make("Backend").add(
37 listNotes,
38 createNote,
39 deleteNote,
40) {}
41
42/** Backend Worker HttpApi — D1 only. KV lives on the vinext frontend. */
43export class BackendApi extends HttpApi.make("BackendApi").add(BackendGroup) {}