brustjs 0.1.15-alpha → 0.1.17-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,40 @@
1
+ // Treaty actions — the team-store RPC surface. Wired into brust.run({ actions }).
2
+ //
3
+ // Client calls (from the islands):
4
+ // api.team.get() → GET /_brust/action/team
5
+ // api.team.post({ … }) → POST /_brust/action/team
6
+ // api.team({ id }).delete() → DELETE /_brust/action/team/{id}
7
+
8
+ import { z } from 'zod'
9
+ import { defineActions } from 'brustjs'
10
+ import { MAX_TEAM, teamStore } from './lib/team-store'
11
+
12
+ const TeamMemberInput = z.object({
13
+ id: z.number().int().positive(),
14
+ name: z.string().min(1),
15
+ displayName: z.string().min(1),
16
+ num: z.string(),
17
+ types: z.array(z.string()).max(2),
18
+ artwork: z.string(),
19
+ })
20
+
21
+ export const actions = defineActions()
22
+ .get('/team', () => ({ team: teamStore.list(), max: MAX_TEAM }))
23
+ .post(
24
+ '/team',
25
+ ({ body }) => {
26
+ const ok = teamStore.add(body)
27
+ // GAP S7: a domain error (team full) cannot throw a typed non-2xx across
28
+ // the treaty boundary, so it rides back inside the success payload as a
29
+ // `full` flag. The client therefore checks two places (transport `error`
30
+ // AND `data.full`). See ./FRAMEWORK-GAPS.md S7.
31
+ return { team: teamStore.list(), max: MAX_TEAM, full: !ok }
32
+ },
33
+ { body: TeamMemberInput },
34
+ )
35
+ .delete('/team/{id}', ({ params }) => {
36
+ teamStore.remove(Number(params.id))
37
+ return { team: teamStore.list(), max: MAX_TEAM }
38
+ })
39
+
40
+ export type Actions = typeof actions