@frockbot/applet-sdk 0.0.0 → 0.3.12
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 +77 -1
- package/dist/cli.mjs +1007 -0
- package/package.json +51 -5
- package/src/cli/bin.ts +128 -0
- package/src/cli/build.ts +181 -0
- package/src/cli/check.ts +134 -0
- package/src/cli/dev.ts +84 -0
- package/src/cli/main.ts +17 -0
- package/src/cli/manifest.ts +58 -0
- package/src/cli/new.ts +74 -0
- package/src/cli/paths.ts +98 -0
- package/src/cli/runtime.ts +123 -0
- package/src/client/collections.ts +72 -0
- package/src/client/index.ts +203 -0
- package/src/client/transport.ts +334 -0
- package/src/kit/README.md +130 -0
- package/src/kit/index.tsx +427 -0
- package/src/kit/styles.ts +200 -0
- package/src/lint/index.ts +148 -0
- package/src/lint/rules.ts +394 -0
- package/src/protocol/index.ts +411 -0
- package/src/schema/index.ts +436 -0
- package/src/server/applet.ts +399 -0
- package/src/server/index.ts +53 -0
- package/src/server/session.ts +156 -0
- package/src/server/store.ts +398 -0
- package/template/README.md +37 -0
- package/template/applet.json +5 -0
- package/template/server.ts +46 -0
- package/template/ui.tsx +113 -0
- package/types/cloudflare-workers.d.ts +55 -0
package/README.md
CHANGED
|
@@ -1,3 +1,79 @@
|
|
|
1
1
|
# @frockbot/applet-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The SDK a FrockBot Applet is written against: a schema-first Durable Object
|
|
4
|
+
server, a TanStack DB client over one real-time socket, a precompiled component
|
|
5
|
+
kit on the theme tokens, a linter, and the `applet` CLI.
|
|
6
|
+
|
|
7
|
+
See [ADR 0022](../../docs/adr/0022-applets-as-instance-packages.md) for why an
|
|
8
|
+
Applet's state is a Durable Object facet the kernel owns the lifecycle of, and
|
|
9
|
+
`docs/plans/applets.md` §8 for this package's place in the build.
|
|
10
|
+
|
|
11
|
+
## Entry points
|
|
12
|
+
|
|
13
|
+
| Import | For |
|
|
14
|
+
| ------------------------------- | -------------------------------------------------------- |
|
|
15
|
+
| `@frockbot/applet-sdk/server` | `Applet`, `table`, `t` — the Applet's `server.ts` |
|
|
16
|
+
| `@frockbot/applet-sdk/client` | `createApplet`, `mount`, `newId` — the Applet's `ui.tsx` |
|
|
17
|
+
| `@frockbot/applet-sdk/kit` | the fourteen components (`src/kit/README.md`) |
|
|
18
|
+
| `@frockbot/applet-sdk/lint` | the flat ESLint config and the five custom rules |
|
|
19
|
+
| `@frockbot/applet-sdk/protocol` | wire protocol v1, for the kernel and for tests |
|
|
20
|
+
|
|
21
|
+
## The CLI
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
applet new "Weekly Todos" # scaffold from template/
|
|
25
|
+
applet check # tsc + lint; path:line:col message; non-zero on error
|
|
26
|
+
applet build # dist/{server.js,ui.html,manifest.json}
|
|
27
|
+
applet dev # Miniflare on a local port; prints a URL, opens nothing
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`applet build` derives `manifest.json`'s tool declarations by mounting the built
|
|
31
|
+
`dist/server.js` in Miniflare and calling `health()` — the same question the
|
|
32
|
+
kernel asks the facet before it admits a generation, so the manifest cannot
|
|
33
|
+
disagree with the code.
|
|
34
|
+
|
|
35
|
+
**The CLI runs under Bun.** Every entry point in this package is TypeScript and
|
|
36
|
+
resolves sibling modules through `.js` specifiers, which Bun and esbuild handle
|
|
37
|
+
and plain Node does not. The `applets` provisioning phase on the Computer
|
|
38
|
+
(lane C1) must therefore put Bun on the image, or this package must gain a
|
|
39
|
+
prepublish step that bundles `src/cli/bin.ts` to `dist/cli.mjs` and points `bin`
|
|
40
|
+
there. Nothing else in the SDK depends on which of those is chosen.
|
|
41
|
+
|
|
42
|
+
## What runs where
|
|
43
|
+
|
|
44
|
+
`server.ts` becomes a single ESM file whose only import is `cloudflare:workers`,
|
|
45
|
+
loaded by the kernel's `APPLETS` Worker Loader with no outbound network, and
|
|
46
|
+
mounted as a facet under `AppletState`. `ui.tsx` becomes one self-contained HTML
|
|
47
|
+
page served from the anonymous artifact origin into a sandboxed iframe, which
|
|
48
|
+
receives its theme tokens and a short-lived viewer token through the host's
|
|
49
|
+
`init` message and opens exactly one WebSocket back to the facet.
|
|
50
|
+
|
|
51
|
+
The Cloudflare programming model is not hidden and ADR 0022 says so: an Applet
|
|
52
|
+
is a Durable Object with SQLite and hibernating sockets. What the SDK does hide
|
|
53
|
+
is every binding name — an author sees `tables`, `tools`, and `this.db`.
|
|
54
|
+
|
|
55
|
+
## Wire protocol v1
|
|
56
|
+
|
|
57
|
+
JSON frames, at most 64 KB each, decoded by `src/protocol/` at both ends;
|
|
58
|
+
an unknown type, field, or table fails closed.
|
|
59
|
+
|
|
60
|
+
| Direction | Frame | Carries |
|
|
61
|
+
| --------------- | ---------- | ----------------------------------------------------------- |
|
|
62
|
+
| server → client | `hello` | contract, generationId, viewer, tables, revision, cursor |
|
|
63
|
+
| client → server | `hello` | contract, optional `since` cursor for catch-up |
|
|
64
|
+
| server → client | `snapshot` | every row of every table, plus the cursor |
|
|
65
|
+
| server → client | `changes` | ordered row changes, optionally tagged with a client txn id |
|
|
66
|
+
| client → server | `mutate` | one client transaction: insert/update/delete |
|
|
67
|
+
| server → client | `ack` | the resulting rows for that txn |
|
|
68
|
+
| server → client | `reject` | why the txn was refused (the client rolls back) |
|
|
69
|
+
|
|
70
|
+
## Tests
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
bun test test spike
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Pure modules and the client are tested in `bun test`: the store runs against
|
|
77
|
+
`bun:sqlite`, and `test/loopback.ts` joins the real protocol server to the real
|
|
78
|
+
client transport through a pair of fake sockets. `test/cli.test.ts` and
|
|
79
|
+
`spike/` run the built Applet in Miniflare for real.
|