@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.
Files changed (88) hide show
  1. package/dist/index.js +2737 -0
  2. package/dist/index.js.map +1 -0
  3. package/dist/templates/addons/docker/.dockerignore +13 -0
  4. package/dist/templates/addons/docker/Dockerfile +65 -0
  5. package/dist/templates/addons/docker/healthcheck.js +15 -0
  6. package/dist/templates/minimal-cloudflare/.baerly/scaffold.json +10 -0
  7. package/dist/templates/minimal-cloudflare/AGENTS.md +556 -0
  8. package/dist/templates/minimal-cloudflare/README.md +169 -0
  9. package/dist/templates/minimal-cloudflare/_gitignore +6 -0
  10. package/dist/templates/minimal-cloudflare/baerly.config.ts +20 -0
  11. package/dist/templates/minimal-cloudflare/index.html +12 -0
  12. package/dist/templates/minimal-cloudflare/package.json +28 -0
  13. package/dist/templates/minimal-cloudflare/pnpm-workspace.yaml +15 -0
  14. package/dist/templates/minimal-cloudflare/src/notes.test.ts +19 -0
  15. package/dist/templates/minimal-cloudflare/src/server/index.ts +11 -0
  16. package/dist/templates/minimal-cloudflare/src/web/main.ts +27 -0
  17. package/dist/templates/minimal-cloudflare/tsconfig.app.json +28 -0
  18. package/dist/templates/minimal-cloudflare/tsconfig.json +9 -0
  19. package/dist/templates/minimal-cloudflare/tsconfig.worker.json +28 -0
  20. package/dist/templates/minimal-cloudflare/types.ts +23 -0
  21. package/dist/templates/minimal-cloudflare/uint8array-base64.d.ts +16 -0
  22. package/dist/templates/minimal-cloudflare/vite.config.ts +6 -0
  23. package/dist/templates/minimal-cloudflare/vitest.config.ts +11 -0
  24. package/dist/templates/minimal-cloudflare/wrangler.jsonc +27 -0
  25. package/dist/templates/minimal-node/.baerly/scaffold.json +13 -0
  26. package/dist/templates/minimal-node/.env.example +14 -0
  27. package/dist/templates/minimal-node/AGENTS.md +488 -0
  28. package/dist/templates/minimal-node/README.md +180 -0
  29. package/dist/templates/minimal-node/_gitignore +7 -0
  30. package/dist/templates/minimal-node/baerly.config.ts +20 -0
  31. package/dist/templates/minimal-node/index.html +12 -0
  32. package/dist/templates/minimal-node/package.json +26 -0
  33. package/dist/templates/minimal-node/pnpm-workspace.yaml +9 -0
  34. package/dist/templates/minimal-node/src/notes.test.ts +19 -0
  35. package/dist/templates/minimal-node/src/server/index.ts +46 -0
  36. package/dist/templates/minimal-node/src/web/main.ts +27 -0
  37. package/dist/templates/minimal-node/tsconfig.app.json +28 -0
  38. package/dist/templates/minimal-node/tsconfig.json +9 -0
  39. package/dist/templates/minimal-node/tsconfig.server.json +28 -0
  40. package/dist/templates/minimal-node/types.ts +23 -0
  41. package/dist/templates/minimal-node/uint8array-base64.d.ts +16 -0
  42. package/dist/templates/minimal-node/vite.config.ts +15 -0
  43. package/dist/templates/minimal-node/vitest.config.ts +12 -0
  44. package/dist/templates/react-cloudflare/.baerly/scaffold.json +10 -0
  45. package/dist/templates/react-cloudflare/AGENTS.md +715 -0
  46. package/dist/templates/react-cloudflare/README.md +115 -0
  47. package/dist/templates/react-cloudflare/_gitignore +6 -0
  48. package/dist/templates/react-cloudflare/baerly.config.ts +37 -0
  49. package/dist/templates/react-cloudflare/index.html +12 -0
  50. package/dist/templates/react-cloudflare/package.json +34 -0
  51. package/dist/templates/react-cloudflare/pnpm-workspace.yaml +15 -0
  52. package/dist/templates/react-cloudflare/src/notes.test.ts +19 -0
  53. package/dist/templates/react-cloudflare/src/server/index.ts +12 -0
  54. package/dist/templates/react-cloudflare/src/web/App.tsx +38 -0
  55. package/dist/templates/react-cloudflare/src/web/NoteList.tsx +93 -0
  56. package/dist/templates/react-cloudflare/src/web/client.ts +13 -0
  57. package/dist/templates/react-cloudflare/src/web/main.tsx +14 -0
  58. package/dist/templates/react-cloudflare/src/web/styles.css +57 -0
  59. package/dist/templates/react-cloudflare/tsconfig.app.json +29 -0
  60. package/dist/templates/react-cloudflare/tsconfig.json +9 -0
  61. package/dist/templates/react-cloudflare/tsconfig.worker.json +28 -0
  62. package/dist/templates/react-cloudflare/uint8array-base64.d.ts +16 -0
  63. package/dist/templates/react-cloudflare/vite.config.ts +7 -0
  64. package/dist/templates/react-cloudflare/vitest.config.ts +11 -0
  65. package/dist/templates/react-cloudflare/wrangler.jsonc +27 -0
  66. package/dist/templates/react-node/.baerly/scaffold.json +13 -0
  67. package/dist/templates/react-node/.env.example +14 -0
  68. package/dist/templates/react-node/AGENTS.md +662 -0
  69. package/dist/templates/react-node/README.md +187 -0
  70. package/dist/templates/react-node/_gitignore +7 -0
  71. package/dist/templates/react-node/baerly.config.ts +37 -0
  72. package/dist/templates/react-node/index.html +12 -0
  73. package/dist/templates/react-node/package.json +32 -0
  74. package/dist/templates/react-node/pnpm-workspace.yaml +9 -0
  75. package/dist/templates/react-node/src/notes.test.ts +19 -0
  76. package/dist/templates/react-node/src/server/index.ts +48 -0
  77. package/dist/templates/react-node/src/web/App.tsx +38 -0
  78. package/dist/templates/react-node/src/web/NoteList.tsx +93 -0
  79. package/dist/templates/react-node/src/web/client.ts +13 -0
  80. package/dist/templates/react-node/src/web/main.tsx +14 -0
  81. package/dist/templates/react-node/src/web/styles.css +57 -0
  82. package/dist/templates/react-node/tsconfig.app.json +29 -0
  83. package/dist/templates/react-node/tsconfig.json +9 -0
  84. package/dist/templates/react-node/tsconfig.server.json +28 -0
  85. package/dist/templates/react-node/uint8array-base64.d.ts +16 -0
  86. package/dist/templates/react-node/vite.config.ts +17 -0
  87. package/dist/templates/react-node/vitest.config.ts +12 -0
  88. package/package.json +41 -0
@@ -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-node",
13
+ tenant: "minimal-demo",
14
+ target: "node",
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-node</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,26 @@
1
+ {
2
+ "name": "minimal-node",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "tsc -b && vite build",
9
+ "start": "node --experimental-strip-types src/server/index.ts",
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
+ "aws4fetch": "^1.0.20"
17
+ },
18
+ "devDependencies": {
19
+ "@types/node": "^24.0.0",
20
+ "happy-dom": "^20.9.0",
21
+ "typescript": "^6.0.3",
22
+ "vite": "^8.0.14",
23
+ "vitest": "^4.1.7"
24
+ },
25
+ "packageManager": "pnpm@11.1.2"
26
+ }
@@ -0,0 +1,9 @@
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
+ # bundler chain below.
5
+ #
6
+ # `esbuild` ships a working install script we want to run (it
7
+ # arrives via vite).
8
+ allowBuilds:
9
+ esbuild: true
@@ -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,46 @@
1
+ /**
2
+ * Server entry for minimal-node. `baerlyNode(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
+ * Storage: AWS S3 by default; set `R2_ACCOUNT_ID` to switch to
9
+ * Cloudflare R2 via the S3-compat endpoint.
10
+ */
11
+ import { baerlyNode, r2Storage, s3Storage } from "@gusto/baerly-storage/node";
12
+ import type { Storage } from "@gusto/baerly-storage";
13
+ import config from "../../baerly.config.ts";
14
+
15
+ const reqEnv = (name: string): string => {
16
+ const v = process.env[name];
17
+ if (v === undefined || v === "") {
18
+ throw new Error(`Missing required env var: ${name}`);
19
+ }
20
+ return v;
21
+ };
22
+
23
+ const storage: Storage =
24
+ process.env["R2_ACCOUNT_ID"] !== undefined
25
+ ? r2Storage({
26
+ accountId: reqEnv("R2_ACCOUNT_ID"),
27
+ bucket: reqEnv("BUCKET"),
28
+ credentials: {
29
+ accessKeyId: reqEnv("AWS_ACCESS_KEY_ID"),
30
+ secretAccessKey: reqEnv("AWS_SECRET_ACCESS_KEY"),
31
+ },
32
+ })
33
+ : s3Storage({
34
+ region: process.env["AWS_REGION"] ?? "us-east-1",
35
+ bucket: reqEnv("BUCKET"),
36
+ credentials: {
37
+ accessKeyId: reqEnv("AWS_ACCESS_KEY_ID"),
38
+ secretAccessKey: reqEnv("AWS_SECRET_ACCESS_KEY"),
39
+ },
40
+ });
41
+
42
+ const PORT = Number(process.env["PORT"] ?? 8080);
43
+
44
+ await baerlyNode({ config, storage }).listen(PORT);
45
+
46
+ console.log(`minimal-node listening on :${PORT}`);
@@ -0,0 +1,27 @@
1
+ import { createBaerlyClient } from "@gusto/baerly-storage/client";
2
+ import config from "../../baerly.config.ts";
3
+
4
+ // Same-origin baseUrl: `baerlyDev()` in vite.config.ts mounts the Node
5
+ // HTTP listener as Connect middleware on the same Vite process that
6
+ // serves this SPA, and injects Authorization server-side — so this
7
+ // file never sees the bearer token.
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-node</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.server.json`
3
+ // covers the Node entry (`server.ts`). 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.server.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": ["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 Node server (`src/server/`) and the SPA
3
+ * (`src/web/`). `tsconfig.server.json` and `tsconfig.app.json` both
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,15 @@
1
+ import { resolve } from "node:path";
2
+ import { defineConfig } from "vite";
3
+ import { baerlyDev } from "@gusto/baerly-storage/dev/vite";
4
+ import config from "./baerly.config.ts";
5
+
6
+ export default defineConfig({
7
+ build: { outDir: "dist/client", emptyOutDir: true },
8
+ server: { port: 5173 },
9
+ plugins: [
10
+ baerlyDev({
11
+ config,
12
+ dataDir: resolve(import.meta.dirname, ".baerly-data"),
13
+ }),
14
+ ],
15
+ });
@@ -0,0 +1,12 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ // Standalone so vitest doesn't pick up `vite.config.ts` and try to
4
+ // resolve its plugins. Node environment matches where this scaffold's
5
+ // code runs — set `environment: "happy-dom"` for browser-side tests
6
+ // (already in devDependencies).
7
+ export default defineConfig({
8
+ test: {
9
+ environment: "node",
10
+ include: ["src/**/*.test.{ts,tsx}", "*.test.ts"],
11
+ },
12
+ });
@@ -0,0 +1,10 @@
1
+ {
2
+ "renames": [
3
+ { "from": "react-cloudflare", "fromKey": "appName" },
4
+ { "from": "react-demo", "fromKey": "tenant" }
5
+ ],
6
+ "excludePaths": [".baerly/scaffold.json"],
7
+ "excludeNames": ["node_modules", "dist", ".wrangler", ".dev.vars", ".DS_Store", "*.tsbuildinfo"],
8
+ "dropDevDeps": [],
9
+ "copies": [{ "from": "AGENTS.md", "to": "CLAUDE.md" }]
10
+ }