@gusto/create-baerly-storage 0.1.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/dist/index.js +2737 -0
- package/dist/index.js.map +1 -0
- package/dist/templates/addons/docker/.dockerignore +13 -0
- package/dist/templates/addons/docker/Dockerfile +65 -0
- package/dist/templates/addons/docker/healthcheck.js +15 -0
- package/dist/templates/minimal-cloudflare/.baerly/scaffold.json +10 -0
- package/dist/templates/minimal-cloudflare/AGENTS.md +556 -0
- package/dist/templates/minimal-cloudflare/README.md +169 -0
- package/dist/templates/minimal-cloudflare/_gitignore +6 -0
- package/dist/templates/minimal-cloudflare/baerly.config.ts +20 -0
- package/dist/templates/minimal-cloudflare/index.html +12 -0
- package/dist/templates/minimal-cloudflare/package.json +28 -0
- package/dist/templates/minimal-cloudflare/pnpm-workspace.yaml +15 -0
- package/dist/templates/minimal-cloudflare/src/notes.test.ts +19 -0
- package/dist/templates/minimal-cloudflare/src/server/index.ts +11 -0
- package/dist/templates/minimal-cloudflare/src/web/main.ts +27 -0
- package/dist/templates/minimal-cloudflare/tsconfig.app.json +28 -0
- package/dist/templates/minimal-cloudflare/tsconfig.json +9 -0
- package/dist/templates/minimal-cloudflare/tsconfig.worker.json +28 -0
- package/dist/templates/minimal-cloudflare/types.ts +23 -0
- package/dist/templates/minimal-cloudflare/uint8array-base64.d.ts +16 -0
- package/dist/templates/minimal-cloudflare/vite.config.ts +6 -0
- package/dist/templates/minimal-cloudflare/vitest.config.ts +11 -0
- package/dist/templates/minimal-cloudflare/wrangler.jsonc +27 -0
- package/dist/templates/minimal-node/.baerly/scaffold.json +13 -0
- package/dist/templates/minimal-node/.env.example +14 -0
- package/dist/templates/minimal-node/AGENTS.md +488 -0
- package/dist/templates/minimal-node/README.md +180 -0
- package/dist/templates/minimal-node/_gitignore +7 -0
- package/dist/templates/minimal-node/baerly.config.ts +20 -0
- package/dist/templates/minimal-node/index.html +12 -0
- package/dist/templates/minimal-node/package.json +26 -0
- package/dist/templates/minimal-node/pnpm-workspace.yaml +9 -0
- package/dist/templates/minimal-node/src/notes.test.ts +19 -0
- package/dist/templates/minimal-node/src/server/index.ts +46 -0
- package/dist/templates/minimal-node/src/web/main.ts +27 -0
- package/dist/templates/minimal-node/tsconfig.app.json +28 -0
- package/dist/templates/minimal-node/tsconfig.json +9 -0
- package/dist/templates/minimal-node/tsconfig.server.json +28 -0
- package/dist/templates/minimal-node/types.ts +23 -0
- package/dist/templates/minimal-node/uint8array-base64.d.ts +16 -0
- package/dist/templates/minimal-node/vite.config.ts +15 -0
- package/dist/templates/minimal-node/vitest.config.ts +12 -0
- package/dist/templates/react-cloudflare/.baerly/scaffold.json +10 -0
- package/dist/templates/react-cloudflare/AGENTS.md +715 -0
- package/dist/templates/react-cloudflare/README.md +115 -0
- package/dist/templates/react-cloudflare/_gitignore +6 -0
- package/dist/templates/react-cloudflare/baerly.config.ts +37 -0
- package/dist/templates/react-cloudflare/index.html +12 -0
- package/dist/templates/react-cloudflare/package.json +34 -0
- package/dist/templates/react-cloudflare/pnpm-workspace.yaml +15 -0
- package/dist/templates/react-cloudflare/src/notes.test.ts +19 -0
- package/dist/templates/react-cloudflare/src/server/index.ts +12 -0
- package/dist/templates/react-cloudflare/src/web/App.tsx +38 -0
- package/dist/templates/react-cloudflare/src/web/NoteList.tsx +93 -0
- package/dist/templates/react-cloudflare/src/web/client.ts +13 -0
- package/dist/templates/react-cloudflare/src/web/main.tsx +14 -0
- package/dist/templates/react-cloudflare/src/web/styles.css +57 -0
- package/dist/templates/react-cloudflare/tsconfig.app.json +29 -0
- package/dist/templates/react-cloudflare/tsconfig.json +9 -0
- package/dist/templates/react-cloudflare/tsconfig.worker.json +28 -0
- package/dist/templates/react-cloudflare/uint8array-base64.d.ts +16 -0
- package/dist/templates/react-cloudflare/vite.config.ts +7 -0
- package/dist/templates/react-cloudflare/vitest.config.ts +11 -0
- package/dist/templates/react-cloudflare/wrangler.jsonc +27 -0
- package/dist/templates/react-node/.baerly/scaffold.json +13 -0
- package/dist/templates/react-node/.env.example +14 -0
- package/dist/templates/react-node/AGENTS.md +662 -0
- package/dist/templates/react-node/README.md +187 -0
- package/dist/templates/react-node/_gitignore +7 -0
- package/dist/templates/react-node/baerly.config.ts +37 -0
- package/dist/templates/react-node/index.html +12 -0
- package/dist/templates/react-node/package.json +32 -0
- package/dist/templates/react-node/pnpm-workspace.yaml +9 -0
- package/dist/templates/react-node/src/notes.test.ts +19 -0
- package/dist/templates/react-node/src/server/index.ts +48 -0
- package/dist/templates/react-node/src/web/App.tsx +38 -0
- package/dist/templates/react-node/src/web/NoteList.tsx +93 -0
- package/dist/templates/react-node/src/web/client.ts +13 -0
- package/dist/templates/react-node/src/web/main.tsx +14 -0
- package/dist/templates/react-node/src/web/styles.css +57 -0
- package/dist/templates/react-node/tsconfig.app.json +29 -0
- package/dist/templates/react-node/tsconfig.json +9 -0
- package/dist/templates/react-node/tsconfig.server.json +28 -0
- package/dist/templates/react-node/uint8array-base64.d.ts +16 -0
- package/dist/templates/react-node/vite.config.ts +17 -0
- package/dist/templates/react-node/vitest.config.ts +12 -0
- package/package.json +41 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# minimal-cloudflare
|
|
2
|
+
|
|
3
|
+
A baerly app scaffolded with `@gusto/create-baerly-storage` for the **Cloudflare
|
|
4
|
+
Workers** target. Single-bucket R2-backed deployment via the
|
|
5
|
+
`@gusto/baerly-storage/cloudflare` adapter. Ships `auth: "none"` so the
|
|
6
|
+
day-1 happy path works with zero env vars; flip to Cloudflare
|
|
7
|
+
Access or a shared secret before deploy — see "Going to
|
|
8
|
+
production" below.
|
|
9
|
+
|
|
10
|
+
## What you got
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
minimal-cloudflare/
|
|
14
|
+
├── package.json # one package, all deps
|
|
15
|
+
├── tsconfig.json # project-references stub
|
|
16
|
+
├── tsconfig.app.json # client TS project (src/web)
|
|
17
|
+
├── tsconfig.worker.json # Worker TS project (src/server)
|
|
18
|
+
├── vite.config.ts # Vite + @cloudflare/vite-plugin
|
|
19
|
+
├── wrangler.jsonc # Worker manifest — R2 binding, assets, vars, triggers, limits, observability
|
|
20
|
+
├── index.html # SPA shell — Vite's entry point
|
|
21
|
+
├── baerly.config.ts # app, tenant, target, domain
|
|
22
|
+
├── AGENTS.md # deeper guide: predicates, schemas,
|
|
23
|
+
│ # auth recipes, graduation (Codex CLI)
|
|
24
|
+
├── CLAUDE.md # same content (Claude Code reads this)
|
|
25
|
+
├── src/
|
|
26
|
+
│ ├── server/
|
|
27
|
+
│ │ └── index.ts # baerlyWorker((env) => ({ verifier }))
|
|
28
|
+
│ └── web/
|
|
29
|
+
│ └── main.ts # SPA client entry — Workers Assets serves the build
|
|
30
|
+
└── README.md
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Run locally
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
pnpm install
|
|
37
|
+
pnpm dev
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`pnpm dev` runs `vite`. The `@cloudflare/vite-plugin` runs your Worker
|
|
41
|
+
inside `workerd` next to the SPA dev server, so `GET /` hits the SPA
|
|
42
|
+
on `http://localhost:5173/` and anything the Worker handles
|
|
43
|
+
(e.g. `GET /v1/healthz`) is served on the same origin. First run
|
|
44
|
+
downloads the `workerd` binary.
|
|
45
|
+
|
|
46
|
+
`pnpm build` runs `tsc -b && vite build`; the SPA lands in
|
|
47
|
+
`dist/client/` for the `assets:` binding in `wrangler.jsonc` to ingest
|
|
48
|
+
on deploy.
|
|
49
|
+
|
|
50
|
+
`pnpm typecheck` runs `tsc -b --noEmit` across both TS project
|
|
51
|
+
references.
|
|
52
|
+
|
|
53
|
+
## Deploy
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
# One-command deploy. baerly reads `baerly.config.ts:target`, finds
|
|
57
|
+
# `wrangler.jsonc`, and runs:
|
|
58
|
+
# wrangler deploy --x-provision --x-auto-create
|
|
59
|
+
# which auto-creates the declared R2 bucket(s) before the deploy.
|
|
60
|
+
# When the experimental flag is unavailable, baerly falls back to
|
|
61
|
+
# `wrangler r2 bucket create` + `wrangler deploy`.
|
|
62
|
+
baerly deploy
|
|
63
|
+
|
|
64
|
+
# Verify the deployed config — bindings, secrets, cron triggers.
|
|
65
|
+
baerly doctor --target=cloudflare
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`baerly doctor --target=cloudflare` warns on `auth: "none"` for
|
|
69
|
+
deploy targets — see "Going to production" below to flip the
|
|
70
|
+
posture before shipping.
|
|
71
|
+
|
|
72
|
+
If you'd rather run the steps by hand: `pnpm build` → `wrangler r2
|
|
73
|
+
bucket create minimal-cloudflare` → `wrangler deploy` from this
|
|
74
|
+
directory. The `assets:` binding in `wrangler.jsonc` picks up
|
|
75
|
+
`dist/client/` automatically.
|
|
76
|
+
|
|
77
|
+
## Secrets
|
|
78
|
+
|
|
79
|
+
Public configuration (`APP`, `TENANT`) lives in
|
|
80
|
+
`wrangler.jsonc:vars`. The default `auth: "none"` posture
|
|
81
|
+
needs no secrets. If you adopt a "Going to production" recipe:
|
|
82
|
+
|
|
83
|
+
- **Pattern A (CF Access):** `CF_ACCESS_TEAM_DOMAIN` +
|
|
84
|
+
`CF_ACCESS_AUDIENCE_TAG` go in `wrangler.jsonc:vars` (they're
|
|
85
|
+
public identifiers, not secrets).
|
|
86
|
+
- **Pattern B (`auth: "shared-secret"`):** `SHARED_SECRET` is a
|
|
87
|
+
secret — `.dev.vars` for `wrangler dev`, `wrangler secret put
|
|
88
|
+
SHARED_SECRET` for production. Each secret is encrypted at rest
|
|
89
|
+
and exposed on `env` at runtime.
|
|
90
|
+
|
|
91
|
+
## Next steps
|
|
92
|
+
|
|
93
|
+
1. **Read `AGENTS.md`** for the agent-facing guide — predicates,
|
|
94
|
+
indexes, schemas, auth recipes, the maintenance cron, and the
|
|
95
|
+
graduation criteria. Codex CLI reads `AGENTS.md`; Claude Code
|
|
96
|
+
reads `CLAUDE.md`; both files are byte-identical so either
|
|
97
|
+
surface lands you the same context.
|
|
98
|
+
2. **Declare your first collection schema** in `baerly.config.ts`
|
|
99
|
+
via `defineConfig({ collections: { ... } })` and pass it to
|
|
100
|
+
`Db.create({ ..., collections })`. Schema validation is live;
|
|
101
|
+
bad inserts return 422.
|
|
102
|
+
3. **Set up production auth** — follow `AGENTS.md` → "Going to
|
|
103
|
+
production". Pattern A wires CF Access via an env-aware factory
|
|
104
|
+
`verifier:` override; Pattern B flips `auth: "shared-secret"`.
|
|
105
|
+
`baerly doctor --target=cloudflare` reports any gaps.
|
|
106
|
+
4. **Check usage trends** — run `baerly doctor --target=cloudflare
|
|
107
|
+
--usage` periodically. It estimates your current writes/minute
|
|
108
|
+
per collection from recent log entries and warns when you're
|
|
109
|
+
approaching the graduation ceiling described in the "When to
|
|
110
|
+
graduate" section below.
|
|
111
|
+
|
|
112
|
+
## When to graduate
|
|
113
|
+
|
|
114
|
+
baerly is designed for the small-to-medium operating point. Past these
|
|
115
|
+
thresholds, S3 list-prefix latency and per-class operation pricing
|
|
116
|
+
start to dominate, and you're better off on a real database:
|
|
117
|
+
|
|
118
|
+
- **~30 writes / minute / collection**
|
|
119
|
+
- **~10 GB / tenant**
|
|
120
|
+
- **~100 collections / tenant**
|
|
121
|
+
|
|
122
|
+
When you cross the soft ceiling, graduation is mechanical:
|
|
123
|
+
`baerly export --target=postgres` walks your log entries (already
|
|
124
|
+
Postgres-logical-replication-shaped) into a real DB. If your
|
|
125
|
+
deploy target is Cloudflare Workers and you'll accept Cloudflare
|
|
126
|
+
lock-in, [D1](https://developers.cloudflare.com/d1/) is cheaper
|
|
127
|
+
per-write at M-size and is a natural next step. If you're on
|
|
128
|
+
AWS, on-prem, or want your data portable, managed Postgres is
|
|
129
|
+
the typical destination. Either way — graduation is a Baerly win,
|
|
130
|
+
not a churn event.
|
|
131
|
+
|
|
132
|
+
**Export to a real database** (swap `--target=` for `sqlite`,
|
|
133
|
+
`postgres`, or `d1`):
|
|
134
|
+
|
|
135
|
+
```sh
|
|
136
|
+
baerly export --target=postgres \
|
|
137
|
+
--bucket=minimal-cloudflare --app=minimal-cloudflare --tenant=<your-tenant> \
|
|
138
|
+
--collection=<collection-name> --output=./out.sql
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The export is a **point-in-time** snapshot and honors any active
|
|
142
|
+
schema on the collection. Your data was already in your bucket and
|
|
143
|
+
your code is a portable HTTP server, so the graduation doesn't
|
|
144
|
+
require vendor cooperation.
|
|
145
|
+
|
|
146
|
+
## Production auth
|
|
147
|
+
|
|
148
|
+
The scaffold ships `auth: "none"` so the day-1 happy path works
|
|
149
|
+
with zero env vars; every request resolves to `config.tenant`.
|
|
150
|
+
Before deploy, follow `AGENTS.md` → "Going to production":
|
|
151
|
+
|
|
152
|
+
- **Pattern A — CF Access (recommended).** Same artifact in dev and
|
|
153
|
+
prod; the factory `verifier:` override engages when
|
|
154
|
+
`CF_ACCESS_TEAM_DOMAIN` + `CF_ACCESS_AUDIENCE_TAG` are present in
|
|
155
|
+
`wrangler.jsonc:vars`. The `cloudflareAccess()` preset
|
|
156
|
+
(re-exported from `@gusto/baerly-storage/auth`) reads the JWT off
|
|
157
|
+
`Cf-Access-Jwt-Assertion`, validates it against your team's JWKS,
|
|
158
|
+
and derives `tenantPrefix` from the email claim.
|
|
159
|
+
- **Pattern B — `auth: "shared-secret"`.** Single-tenant
|
|
160
|
+
server-to-server callers. Flip `auth` in `baerly.config.ts` and
|
|
161
|
+
set `SHARED_SECRET` via `wrangler secret put`.
|
|
162
|
+
|
|
163
|
+
## Pointers
|
|
164
|
+
|
|
165
|
+
- `baerly.config.ts` — app config (`app`, `tenant`, `target`, `domain`).
|
|
166
|
+
- `src/server/index.ts` — Worker fetch + scheduled handler.
|
|
167
|
+
- `wrangler.jsonc` — Cloudflare Worker manifest (R2 binding, `assets:`, vars, cron, observability).
|
|
168
|
+
- `vite.config.ts` — Vite + `@cloudflare/vite-plugin`.
|
|
169
|
+
- `AGENTS.md` / `CLAUDE.md` — agent-facing guide (byte-identical).
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defineConfig } from "@gusto/baerly-storage/config";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* One collection (`notes`) ships out of the box so the wired
|
|
5
|
+
* example in `src/web/main.ts` round-trips through the DB on
|
|
6
|
+
* first load. No schema is declared — `defineConfig` accepts
|
|
7
|
+
* collection entries with neither `schema` nor `indexes` set, and
|
|
8
|
+
* the writer treats them as schema-free. See `react-cloudflare`
|
|
9
|
+
* for the schema-bound shape.
|
|
10
|
+
*/
|
|
11
|
+
export default defineConfig({
|
|
12
|
+
app: "minimal-cloudflare",
|
|
13
|
+
tenant: "minimal-demo",
|
|
14
|
+
target: "cloudflare",
|
|
15
|
+
auth: "none",
|
|
16
|
+
domain: undefined,
|
|
17
|
+
collections: {
|
|
18
|
+
notes: {},
|
|
19
|
+
},
|
|
20
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>minimal-cloudflare</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="app"></div>
|
|
10
|
+
<script type="module" src="/src/web/main.ts"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "minimal-cloudflare",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "tsc -b && vite build",
|
|
9
|
+
"deploy": "wrangler deploy",
|
|
10
|
+
"test": "vitest run",
|
|
11
|
+
"typecheck": "tsc -b --noEmit",
|
|
12
|
+
"verify": "pnpm run typecheck && pnpm run test"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@gusto/baerly-storage": "workspace:*"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@cloudflare/vite-plugin": "^1.39.0",
|
|
19
|
+
"@cloudflare/workers-types": "^4",
|
|
20
|
+
"@types/node": "^24.0.0",
|
|
21
|
+
"happy-dom": "^20.9.0",
|
|
22
|
+
"typescript": "^6.0.3",
|
|
23
|
+
"vite": "^8.0.14",
|
|
24
|
+
"vitest": "^4.1.7",
|
|
25
|
+
"wrangler": "^4.95.0"
|
|
26
|
+
},
|
|
27
|
+
"packageManager": "pnpm@11.1.2"
|
|
28
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# pnpm 11 reads the postinstall-script allowlist only from this
|
|
2
|
+
# file: `package.json#pnpm.*` is no longer honoured. Without this
|
|
3
|
+
# map, `pnpm install` exits with `ERR_PNPM_IGNORED_BUILDS` for the
|
|
4
|
+
# Cloudflare-stack deps below.
|
|
5
|
+
#
|
|
6
|
+
# - `esbuild` / `workerd` ship working install scripts we want to run.
|
|
7
|
+
# - `sharp` is a transitive miniflare dep whose install script falls
|
|
8
|
+
# back to a node-gyp build on Node 24 (no prebuilt for our
|
|
9
|
+
# platform/runtime combo). Set to `false` to suppress cleanly —
|
|
10
|
+
# sharp still loads from its prebuilt binary at require time, and
|
|
11
|
+
# nothing in a scaffolded baerly app exercises its code path.
|
|
12
|
+
allowBuilds:
|
|
13
|
+
esbuild: true
|
|
14
|
+
workerd: true
|
|
15
|
+
sharp: false
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Example test for the shipped `notes` collection. Replace or
|
|
2
|
+
// delete when you change the schema in `baerly.config.ts` — the
|
|
3
|
+
// import on line below will stop typechecking once `notes` is
|
|
4
|
+
// gone.
|
|
5
|
+
import { test, expect } from "vitest";
|
|
6
|
+
import { Db, MemoryStorage } from "@gusto/baerly-storage";
|
|
7
|
+
import config from "../baerly.config.ts";
|
|
8
|
+
|
|
9
|
+
test("notes round-trip", async () => {
|
|
10
|
+
const db = Db.create({
|
|
11
|
+
storage: new MemoryStorage(),
|
|
12
|
+
app: "test",
|
|
13
|
+
tenant: "t",
|
|
14
|
+
config,
|
|
15
|
+
});
|
|
16
|
+
const { _id } = await db.collection("notes").insert({ body: "hello" });
|
|
17
|
+
const row = await db.collection("notes").get(_id);
|
|
18
|
+
expect(row?.body).toBe("hello");
|
|
19
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker entry for minimal-cloudflare. `baerlyWorker(opts)` reads
|
|
3
|
+
* `opts.config.auth` to choose its verifier — the scaffold ships
|
|
4
|
+
* `auth: "none"`, so every request resolves to `config.tenant`
|
|
5
|
+
* with no header check. See AGENTS.md "Going to production" for
|
|
6
|
+
* the recipe to flip `auth` or wire a custom verifier.
|
|
7
|
+
*/
|
|
8
|
+
import { baerlyWorker } from "@gusto/baerly-storage/cloudflare";
|
|
9
|
+
import config from "../../baerly.config.ts";
|
|
10
|
+
|
|
11
|
+
export default baerlyWorker(() => ({ config }));
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createBaerlyClient } from "@gusto/baerly-storage/client";
|
|
2
|
+
import config from "../../baerly.config.ts";
|
|
3
|
+
|
|
4
|
+
// Same-origin baseUrl: in dev, `@cloudflare/vite-plugin` runs the
|
|
5
|
+
// Worker inside workerd on this Vite process. With `auth: "none"`
|
|
6
|
+
// in baerly.config.ts the SPA hits /v1/* without an `Authorization`
|
|
7
|
+
// header and the adapter pins every request to `config.tenant`.
|
|
8
|
+
const client = createBaerlyClient({ baseUrl: "", config });
|
|
9
|
+
|
|
10
|
+
const app = document.querySelector<HTMLDivElement>("#app");
|
|
11
|
+
if (app === null) {
|
|
12
|
+
throw new Error("missing #app root");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const render = async (): Promise<void> => {
|
|
16
|
+
const notes = await client.collection("notes").all();
|
|
17
|
+
app.innerHTML = `<h1>minimal-cloudflare</h1><p>${notes.length} note(s)</p><button id="add">Add note</button>`;
|
|
18
|
+
// innerHTML above replaced the previous button along with everything
|
|
19
|
+
// else, so the new #add has no listener yet — attach a fresh one.
|
|
20
|
+
app.querySelector("#add")?.addEventListener("click", async () => {
|
|
21
|
+
// `_id` is auto-stamped UUIDv7 — sortable by server mint time, no separate timestamp column needed.
|
|
22
|
+
await client.collection("notes").insert({ body: "note" });
|
|
23
|
+
await render();
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
await render();
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2024",
|
|
4
|
+
"lib": ["ES2024", "DOM", "DOM.Iterable"],
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "bundler",
|
|
7
|
+
"allowImportingTsExtensions": true,
|
|
8
|
+
"noEmit": true,
|
|
9
|
+
|
|
10
|
+
"strict": true,
|
|
11
|
+
"noUncheckedIndexedAccess": true,
|
|
12
|
+
"noImplicitOverride": true,
|
|
13
|
+
"noImplicitReturns": true,
|
|
14
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
15
|
+
"noFallthroughCasesInSwitch": true,
|
|
16
|
+
"noUnusedLocals": true,
|
|
17
|
+
"noUnusedParameters": true,
|
|
18
|
+
"verbatimModuleSyntax": true,
|
|
19
|
+
"isolatedModules": true,
|
|
20
|
+
"erasableSyntaxOnly": true,
|
|
21
|
+
|
|
22
|
+
"esModuleInterop": true,
|
|
23
|
+
"skipLibCheck": true,
|
|
24
|
+
"types": ["vite/client"],
|
|
25
|
+
"composite": true
|
|
26
|
+
},
|
|
27
|
+
"include": ["src/web/**/*", "uint8array-base64.d.ts", "types.ts", "baerly.config.ts"]
|
|
28
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Stub — TS picks up the referenced projects below.
|
|
2
|
+
// `tsconfig.app.json` covers the SPA (DOM); `tsconfig.worker.json`
|
|
3
|
+
// covers the Worker entry (workerd). Tests at the repo root match
|
|
4
|
+
// `vitest.config.ts:test.include` (e.g. `*.test.ts`); they don't
|
|
5
|
+
// belong to any tsconfig — vitest type-checks them via its own pipe.
|
|
6
|
+
{
|
|
7
|
+
"files": [],
|
|
8
|
+
"references": [{ "path": "./tsconfig.app.json" }, { "path": "./tsconfig.worker.json" }]
|
|
9
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2024",
|
|
4
|
+
"lib": ["ES2024", "DOM", "DOM.Iterable"],
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "bundler",
|
|
7
|
+
"allowImportingTsExtensions": true,
|
|
8
|
+
"noEmit": true,
|
|
9
|
+
|
|
10
|
+
"strict": true,
|
|
11
|
+
"noUncheckedIndexedAccess": true,
|
|
12
|
+
"noImplicitOverride": true,
|
|
13
|
+
"noImplicitReturns": true,
|
|
14
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
15
|
+
"noFallthroughCasesInSwitch": true,
|
|
16
|
+
"noUnusedLocals": true,
|
|
17
|
+
"noUnusedParameters": true,
|
|
18
|
+
"verbatimModuleSyntax": true,
|
|
19
|
+
"isolatedModules": true,
|
|
20
|
+
"erasableSyntaxOnly": true,
|
|
21
|
+
|
|
22
|
+
"esModuleInterop": true,
|
|
23
|
+
"skipLibCheck": true,
|
|
24
|
+
"types": ["@cloudflare/workers-types", "node"],
|
|
25
|
+
"composite": true
|
|
26
|
+
},
|
|
27
|
+
"include": ["src/server/**/*", "uint8array-base64.d.ts", "types.ts", "baerly.config.ts"]
|
|
28
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types shared between the Worker (`src/server/`) and the SPA
|
|
3
|
+
* (`src/web/`). Both `tsconfig.worker.json` and `tsconfig.app.json`
|
|
4
|
+
* include this file, so a type defined here is visible on both
|
|
5
|
+
* sides without a project-references workaround.
|
|
6
|
+
*/
|
|
7
|
+
import type { DocumentData } from "@gusto/baerly-storage/config";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* One row in the `notes` collection. The minimal scaffold ships a
|
|
11
|
+
* single collection so `src/web/main.ts` round-trips through the DB
|
|
12
|
+
* on first load. Extending the schema is one new field here +
|
|
13
|
+
* (optionally) a Standard Schema validator in `baerly.config.ts`.
|
|
14
|
+
*
|
|
15
|
+
* **Replacing the demo?** `src/web/main.ts` imports `Note` from this
|
|
16
|
+
* file. Rename the interface or swap it for your own row type
|
|
17
|
+
* (anything that extends `DocumentData`) and update the consumer's
|
|
18
|
+
* import — the kernel doesn't care about the name, only the shape.
|
|
19
|
+
*/
|
|
20
|
+
export interface Note extends DocumentData {
|
|
21
|
+
_id: string;
|
|
22
|
+
body: string;
|
|
23
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TC39 Stage-4 base64 codec methods — Node 22+, Bun, Workerd. Delete
|
|
3
|
+
* when TypeScript accepts `esnext.typedarrays` in `--lib`.
|
|
4
|
+
*/
|
|
5
|
+
interface Uint8Array<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike> {
|
|
6
|
+
toBase64(options?: { alphabet?: "base64" | "base64url"; omitPadding?: boolean }): string;
|
|
7
|
+
}
|
|
8
|
+
interface Uint8ArrayConstructor {
|
|
9
|
+
fromBase64(
|
|
10
|
+
input: string,
|
|
11
|
+
options?: {
|
|
12
|
+
alphabet?: "base64" | "base64url";
|
|
13
|
+
lastChunkHandling?: "loose" | "strict" | "stop-before-partial";
|
|
14
|
+
},
|
|
15
|
+
): Uint8Array;
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { defineConfig } from "vitest/config";
|
|
2
|
+
|
|
3
|
+
// Standalone — `vite.config.ts` loads `@cloudflare/vite-plugin`, which
|
|
4
|
+
// rejects vitest's pool/environment combo. Add `@cloudflare/vitest-pool-workers`
|
|
5
|
+
// here if you want Worker-side integration tests.
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
test: {
|
|
8
|
+
environment: "node",
|
|
9
|
+
include: ["src/**/*.test.{ts,tsx}", "*.test.ts"],
|
|
10
|
+
},
|
|
11
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Cloudflare Worker manifest. See `AGENTS.md` for what each field
|
|
3
|
+
// drives (R2 binding, assets, vars, cron, observability) and how
|
|
4
|
+
// the verifier consumes the vars.
|
|
5
|
+
"$schema": "node_modules/wrangler/config-schema.json",
|
|
6
|
+
"name": "minimal-cloudflare",
|
|
7
|
+
"main": "./src/server/index.ts",
|
|
8
|
+
"compatibility_date": "2026-05-01",
|
|
9
|
+
"compatibility_flags": ["nodejs_compat"],
|
|
10
|
+
|
|
11
|
+
"r2_buckets": [
|
|
12
|
+
{
|
|
13
|
+
"binding": "BUCKET",
|
|
14
|
+
"bucket_name": "minimal-cloudflare",
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
|
|
18
|
+
"assets": {
|
|
19
|
+
"directory": "./dist/client",
|
|
20
|
+
"not_found_handling": "single-page-application",
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
"vars": {
|
|
24
|
+
"APP": "minimal-cloudflare",
|
|
25
|
+
"TENANT": "minimal-demo",
|
|
26
|
+
},
|
|
27
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"renames": [
|
|
3
|
+
{ "from": "minimal-node", "fromKey": "appName" },
|
|
4
|
+
{ "from": "minimal-demo", "fromKey": "tenant" }
|
|
5
|
+
],
|
|
6
|
+
"excludePaths": [".baerly/scaffold.json"],
|
|
7
|
+
"excludeNames": ["node_modules", "dist", ".DS_Store", "*.tsbuildinfo"],
|
|
8
|
+
"dropDevDeps": [],
|
|
9
|
+
"copies": [
|
|
10
|
+
{ "from": "AGENTS.md", "to": "CLAUDE.md" },
|
|
11
|
+
{ "from": ".env.example", "to": ".env" }
|
|
12
|
+
]
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Storage credentials (AWS S3 default; R2 when R2_ACCOUNT_ID is set).
|
|
2
|
+
# For Minio / GCS, edit `src/server/index.ts` to use the matching
|
|
3
|
+
# factory from `baerly-storage/node` (`minioStorage` / `gcsStorage`).
|
|
4
|
+
AWS_ACCESS_KEY_ID=
|
|
5
|
+
AWS_SECRET_ACCESS_KEY=
|
|
6
|
+
AWS_REGION=us-east-1
|
|
7
|
+
BUCKET=
|
|
8
|
+
# Set to your Cloudflare R2 account ID (left half of the
|
|
9
|
+
# https://<account>.r2.cloudflarestorage.com endpoint) to switch
|
|
10
|
+
# storage from AWS S3 to R2. Leave unset for AWS S3.
|
|
11
|
+
# R2_ACCOUNT_ID=
|
|
12
|
+
|
|
13
|
+
# Server
|
|
14
|
+
PORT=8080
|