@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 24 lines 870 Bytes
Raw
1 import * as Domain from "@alchemy.run/domain";
2 import * as Effect from "effect/Effect";
3 import * as Schema from "effect/Schema";
4 import { CurrentUser } from "./CurrentUser.context.ts";
5 import { Notebook } from "./Notebook.aggregate.ts";
6 import { NotYours } from "./NotYours.rejection.ts";
7 import { Session } from "./Session.middleware.ts";
8
9 /** The notes in a notebook. Only its owner may read them. */
10 export class Notes extends Domain.View("Notes", {
11 from: [Notebook],
12 key: Notebook,
13 middleware: [Session],
14 rejects: [NotYours],
15 state: Schema.Struct({ notes: Schema.Array(Schema.String) }),
16 initial: { notes: [] },
17 evolve: {
18 NoteWritten: (v, e) => ({ notes: [...v.notes, e.text] }),
19 },
20 validate: Effect.fn(function* (request) {
21 const user = yield* CurrentUser;
22 if (request.key.id !== user.userId) return yield* new NotYours();
23 }),
24 }) {}