@lantharos/pult 0.8.0 → 0.10.0

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.
package/README.md CHANGED
@@ -1,16 +1,18 @@
1
- # pult
1
+ # @lantharos/pult
2
2
 
3
- The other side of your app. Describe your inboxes, records, actions, pages and flags in code next to your app, and Pult turns them into a console your team runs the product from. Every action runs back inside your app.
3
+ The other side of your app. Describe your inboxes, resources, actions, pages and flags in code next to your app, and Pult turns them into a console your team runs the product from. Every action runs back inside your app.
4
4
 
5
5
  ```bash
6
- bun add pult@npm:@lantharos/pult
6
+ bun add @lantharos/pult
7
7
  ```
8
8
 
9
- Installing it under the name `pult` keeps your imports as `"pult"`.
9
+ Then run `bunx pult init` to set up a config, a first resource and inbox, and the client. Everything is imported from `"@lantharos/pult"`, and the package also gives you the `pult` command.
10
+
11
+ Resources are the records your team looks up and acts on, and flags can target them:
10
12
 
11
13
  ```ts
12
14
  // src/users/user.pult.ts
13
- import { b, resource } from "pult"
15
+ import { b, flag, resource } from "@lantharos/pult"
14
16
  import { z } from "zod"
15
17
 
16
18
  export const user = resource("user", {
@@ -27,28 +29,50 @@ export const user = resource("user", {
27
29
  }),
28
30
  }),
29
31
  })
32
+
33
+ export const newEditor = flag("new-editor", { target: user })
34
+ ```
35
+
36
+ Inboxes collect what needs a look, each item linked to the record it's about:
37
+
38
+ ```ts
39
+ // src/users/reports.pult.ts
40
+ import { b, inbox } from "@lantharos/pult"
41
+ import { z } from "zod"
42
+ import { user } from "./user.pult"
43
+
44
+ export const reports = inbox("reports", {
45
+ resource: user,
46
+ data: z.object({ reason: z.string(), body: z.string() }),
47
+ title: (data) => data.reason,
48
+ render: (item) => [b.markdown(item.data.body), b.actions("ban")],
49
+ })
30
50
  ```
31
51
 
52
+ Your app sends items as things happen and reads flags where it needs them:
53
+
32
54
  ```ts
33
55
  // src/pult.ts
34
- import { createPult } from "pult"
56
+ import { createPult } from "@lantharos/pult"
35
57
  import project from "../.pult"
58
+ import { reports } from "./users/reports.pult"
59
+ import { newEditor } from "./users/user.pult"
36
60
 
37
61
  export const pult = createPult({ project })
38
62
  pult.listen()
39
- ```
40
63
 
41
- ```ts
42
- // src/flags.ts
43
- import { flag } from "pult"
44
-
45
- export const newEditor = flag("new-editor", { target: user })
64
+ export async function report(userId: string, reason: string, body: string) {
65
+ await pult.send(reports, { record: userId, fingerprint: userId, data: { reason, body } })
66
+ }
46
67
 
47
- if (await pult.flag(newEditor, user.id)) showNewEditor()
68
+ export const editorFor = (userId: string) => pult.flag(newEditor, userId)
48
69
  ```
49
70
 
50
- The `pult` command builds your definitions, checks them and deploys them:
71
+ On Cloudflare Workers, set `delivery: { mode: "webhook", path: "/pult" }` in `pult.config.ts` and hand those requests to `pult.handler()` instead of calling `listen()`.
72
+
73
+ The `pult` command sets up, builds, checks and deploys your definitions:
51
74
 
75
+ - `pult init` writes a config, a first resource and inbox, and the client.
52
76
  - `pult build` compiles your definitions into `.pult/`. Commit it.
53
77
  - `pult check` catches broken references and stale builds. Run it in CI.
54
78
  - `pult diff` shows what a deploy would change, including who gains which permission.