alchemy 0.68.0 → 0.69.1
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/bin/alchemy.js +32 -33
- package/bin/commands/init.ts +41 -55
- package/lib/aws/control/properties.d.ts +64 -0
- package/lib/aws/control/properties.d.ts.map +1 -1
- package/lib/aws/control/properties.js +554 -39
- package/lib/aws/control/properties.js.map +1 -1
- package/lib/aws/control/resource.d.ts.map +1 -1
- package/lib/aws/control/resource.js +33 -0
- package/lib/aws/control/resource.js.map +1 -1
- package/lib/aws/control/types.d.ts +5451 -1587
- package/lib/aws/control/types.d.ts.map +1 -1
- package/lib/aws/control/types.js.map +1 -1
- package/lib/aws/control/update-types.d.ts +12913 -0
- package/lib/aws/control/update-types.d.ts.map +1 -0
- package/lib/aws/control/update-types.js +12916 -0
- package/lib/aws/control/update-types.js.map +1 -0
- package/lib/cloudflare/api.d.ts +1 -1
- package/lib/cloudflare/api.d.ts.map +1 -1
- package/lib/cloudflare/api.js +9 -10
- package/lib/cloudflare/api.js.map +1 -1
- package/lib/cloudflare/astro/astro.d.ts.map +1 -1
- package/lib/cloudflare/astro/astro.js +3 -3
- package/lib/cloudflare/astro/astro.js.map +1 -1
- package/lib/cloudflare/bucket-object.d.ts +86 -0
- package/lib/cloudflare/bucket-object.d.ts.map +1 -0
- package/lib/cloudflare/bucket-object.js +67 -0
- package/lib/cloudflare/bucket-object.js.map +1 -0
- package/lib/cloudflare/bucket.d.ts +36 -6
- package/lib/cloudflare/bucket.d.ts.map +1 -1
- package/lib/cloudflare/bucket.js +154 -18
- package/lib/cloudflare/bucket.js.map +1 -1
- package/lib/cloudflare/compatibility-date.gen.d.ts +1 -1
- package/lib/cloudflare/compatibility-date.gen.js +1 -1
- package/lib/cloudflare/container.d.ts.map +1 -1
- package/lib/cloudflare/container.js +2 -2
- package/lib/cloudflare/container.js.map +1 -1
- package/lib/cloudflare/index.d.ts +1 -0
- package/lib/cloudflare/index.d.ts.map +1 -1
- package/lib/cloudflare/index.js +1 -0
- package/lib/cloudflare/index.js.map +1 -1
- package/lib/cloudflare/miniflare/miniflare-worker-proxy.d.ts.map +1 -1
- package/lib/cloudflare/miniflare/miniflare-worker-proxy.js +44 -12
- package/lib/cloudflare/miniflare/miniflare-worker-proxy.js.map +1 -1
- package/lib/cloudflare/next.js.map +1 -1
- package/lib/cloudflare/nuxt/nuxt.d.ts.map +1 -1
- package/lib/cloudflare/nuxt/nuxt.js +3 -3
- package/lib/cloudflare/nuxt/nuxt.js.map +1 -1
- package/lib/cloudflare/tanstack-start/plugin.d.ts +2 -15
- package/lib/cloudflare/tanstack-start/plugin.d.ts.map +1 -1
- package/lib/cloudflare/tanstack-start/plugin.js +5 -25
- package/lib/cloudflare/tanstack-start/plugin.js.map +1 -1
- package/lib/cloudflare/tanstack-start/tanstack-start.d.ts.map +1 -1
- package/lib/cloudflare/tanstack-start/tanstack-start.js +15 -4
- package/lib/cloudflare/tanstack-start/tanstack-start.js.map +1 -1
- package/lib/cloudflare/vite/vite.d.ts.map +1 -1
- package/lib/cloudflare/vite/vite.js +3 -3
- package/lib/cloudflare/vite/vite.js.map +1 -1
- package/lib/cloudflare/website.d.ts +7 -1
- package/lib/cloudflare/website.d.ts.map +1 -1
- package/lib/cloudflare/website.js +20 -1
- package/lib/cloudflare/website.js.map +1 -1
- package/lib/cloudflare/worker-metadata.d.ts +4 -1
- package/lib/cloudflare/worker-metadata.d.ts.map +1 -1
- package/lib/cloudflare/worker-metadata.js +2 -0
- package/lib/cloudflare/worker-metadata.js.map +1 -1
- package/lib/cloudflare/worker.d.ts +6 -0
- package/lib/cloudflare/worker.d.ts.map +1 -1
- package/lib/cloudflare/worker.js +1 -0
- package/lib/cloudflare/worker.js.map +1 -1
- package/lib/cloudflare/wrangler.json.d.ts +34 -9
- package/lib/cloudflare/wrangler.json.d.ts.map +1 -1
- package/lib/cloudflare/wrangler.json.js +12 -1
- package/lib/cloudflare/wrangler.json.js.map +1 -1
- package/lib/docker/api.d.ts +22 -1
- package/lib/docker/api.d.ts.map +1 -1
- package/lib/docker/api.js +64 -2
- package/lib/docker/api.js.map +1 -1
- package/lib/docker/container.d.ts +88 -0
- package/lib/docker/container.d.ts.map +1 -1
- package/lib/docker/container.js +36 -0
- package/lib/docker/container.js.map +1 -1
- package/lib/llms.cloudflare.txt +2 -2
- package/lib/neon/branch.d.ts +19 -3
- package/lib/neon/branch.d.ts.map +1 -1
- package/lib/neon/branch.js +4 -4
- package/lib/neon/branch.js.map +1 -1
- package/lib/neon/project.d.ts +17 -1
- package/lib/neon/project.d.ts.map +1 -1
- package/lib/neon/project.js +4 -4
- package/lib/neon/project.js.map +1 -1
- package/lib/serde.d.ts +3 -0
- package/lib/serde.d.ts.map +1 -1
- package/lib/serde.js +40 -0
- package/lib/serde.js.map +1 -1
- package/lib/test/bun.js.map +1 -1
- package/package.json +1 -1
- package/src/aws/control/properties.ts +554 -39
- package/src/aws/control/resource.ts +58 -0
- package/src/aws/control/types.ts +85281 -84914
- package/src/aws/control/update-types.ts +12917 -0
- package/src/cloudflare/api.ts +9 -10
- package/src/cloudflare/astro/astro.ts +8 -3
- package/src/cloudflare/bucket-object.ts +127 -0
- package/src/cloudflare/bucket.ts +218 -18
- package/src/cloudflare/compatibility-date.gen.ts +1 -1
- package/src/cloudflare/container.ts +4 -5
- package/src/cloudflare/index.ts +1 -0
- package/src/cloudflare/miniflare/miniflare-worker-proxy.ts +57 -13
- package/src/cloudflare/next.ts +2 -2
- package/src/cloudflare/nuxt/nuxt.ts +8 -3
- package/src/cloudflare/tanstack-start/plugin.ts +7 -28
- package/src/cloudflare/tanstack-start/tanstack-start.ts +15 -4
- package/src/cloudflare/vite/vite.ts +8 -3
- package/src/cloudflare/website.ts +29 -2
- package/src/cloudflare/worker-metadata.ts +6 -1
- package/src/cloudflare/worker.ts +7 -0
- package/src/cloudflare/wrangler.json.ts +47 -18
- package/src/docker/api.ts +86 -2
- package/src/docker/container.ts +97 -0
- package/src/llms.cloudflare.txt +2 -2
- package/src/neon/branch.ts +6 -5
- package/src/neon/project.ts +4 -4
- package/src/serde.ts +50 -0
- package/src/test/bun.ts +1 -1
- package/templates/rwsdk/.cursor/rules/alchemy_cloudflare.mdc +2 -2
- package/templates/tanstack-start/.cta.json +13 -0
- package/templates/tanstack-start/README.md +267 -49
- package/templates/tanstack-start/_gitignore +9 -18
- package/templates/tanstack-start/alchemy.run.ts +2 -2
- package/templates/tanstack-start/package.json +24 -19
- package/templates/tanstack-start/public/favicon.ico +0 -0
- package/templates/tanstack-start/public/logo192.png +0 -0
- package/templates/tanstack-start/public/logo512.png +0 -0
- package/templates/tanstack-start/public/manifest.json +25 -0
- package/templates/tanstack-start/public/robots.txt +3 -0
- package/templates/tanstack-start/src/components/Header.tsx +21 -0
- package/templates/tanstack-start/src/logo.svg +12 -0
- package/templates/tanstack-start/src/router.tsx +7 -16
- package/templates/tanstack-start/src/routes/__root.tsx +13 -114
- package/templates/tanstack-start/src/routes/api.demo-names.ts +15 -0
- package/templates/tanstack-start/src/routes/demo.start.api-request.tsx +44 -0
- package/templates/tanstack-start/src/routes/demo.start.server-funcs.tsx +97 -0
- package/templates/tanstack-start/src/routes/index.tsx +31 -4
- package/templates/tanstack-start/src/styles.css +15 -0
- package/templates/tanstack-start/tsconfig.json +19 -22
- package/templates/tanstack-start/types/env.d.ts +2 -2
- package/templates/tanstack-start/vite.config.ts +16 -25
- package/workers/tunnel-proxy.js +1 -1
- package/templates/tanstack-start/_prettierignore +0 -4
- package/templates/tanstack-start/public/android-chrome-192x192.png +0 -0
- package/templates/tanstack-start/public/android-chrome-512x512.png +0 -0
- package/templates/tanstack-start/public/apple-touch-icon.png +0 -0
- package/templates/tanstack-start/public/favicon-16x16.png +0 -0
- package/templates/tanstack-start/public/favicon-32x32.png +0 -0
- package/templates/tanstack-start/public/favicon.png +0 -0
- package/templates/tanstack-start/public/site.webmanifest +0 -19
- package/templates/tanstack-start/src/components/DefaultCatchBoundary.tsx +0 -53
- package/templates/tanstack-start/src/components/NotFound.tsx +0 -25
- package/templates/tanstack-start/src/components/PostError.tsx +0 -5
- package/templates/tanstack-start/src/components/UserError.tsx +0 -5
- package/templates/tanstack-start/src/routes/_pathlessLayout/_nested-layout/route-a.tsx +0 -10
- package/templates/tanstack-start/src/routes/_pathlessLayout/_nested-layout/route-b.tsx +0 -10
- package/templates/tanstack-start/src/routes/_pathlessLayout/_nested-layout.tsx +0 -34
- package/templates/tanstack-start/src/routes/_pathlessLayout.tsx +0 -16
- package/templates/tanstack-start/src/routes/api/users.$userId.ts +0 -28
- package/templates/tanstack-start/src/routes/api/users.ts +0 -59
- package/templates/tanstack-start/src/routes/customScript[.]js.ts +0 -10
- package/templates/tanstack-start/src/routes/deferred.tsx +0 -62
- package/templates/tanstack-start/src/routes/posts.$postId.tsx +0 -34
- package/templates/tanstack-start/src/routes/posts.index.tsx +0 -8
- package/templates/tanstack-start/src/routes/posts.tsx +0 -38
- package/templates/tanstack-start/src/routes/posts_.$postId.deep.tsx +0 -29
- package/templates/tanstack-start/src/routes/redirect.tsx +0 -9
- package/templates/tanstack-start/src/routes/users.$userId.tsx +0 -44
- package/templates/tanstack-start/src/routes/users.index.tsx +0 -18
- package/templates/tanstack-start/src/routes/users.tsx +0 -49
- package/templates/tanstack-start/src/styles/app.css +0 -12
- package/templates/tanstack-start/src/utils/loggingMiddleware.tsx +0 -41
- package/templates/tanstack-start/src/utils/posts.tsx +0 -40
- package/templates/tanstack-start/src/utils/seo.ts +0 -33
- package/templates/tanstack-start/src/utils/users.tsx +0 -5
package/src/docker/container.ts
CHANGED
|
@@ -59,6 +59,62 @@ export interface NetworkMapping {
|
|
|
59
59
|
aliases?: string[];
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Duration value supporting both number (seconds) and string format (value + unit)
|
|
64
|
+
* Units: ms (milliseconds), s (seconds), m (minutes), h (hours)
|
|
65
|
+
* Examples: 30, "30s", "1m", "500ms", "2h"
|
|
66
|
+
*/
|
|
67
|
+
export type Duration = number | `${number}${"ms" | "s" | "m" | "h"}`;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Healthcheck configuration
|
|
71
|
+
*/
|
|
72
|
+
export interface HealthcheckConfig {
|
|
73
|
+
/**
|
|
74
|
+
* Command to run to check health.
|
|
75
|
+
* Can be an array of command arguments or a shell command string.
|
|
76
|
+
* Examples:
|
|
77
|
+
* - ["curl", "-f", "http://localhost/"]
|
|
78
|
+
* - "curl -f http://localhost/ || exit 1"
|
|
79
|
+
*/
|
|
80
|
+
cmd: string[] | string;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Time between running the check
|
|
84
|
+
* Can be a number (in seconds) or string with unit (e.g., "30s", "1m")
|
|
85
|
+
* @default 0
|
|
86
|
+
*/
|
|
87
|
+
interval?: Duration;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Maximum time to allow one check to run
|
|
91
|
+
* Can be a number (in seconds) or string with unit (e.g., "10s", "500ms")
|
|
92
|
+
* @default 0
|
|
93
|
+
*/
|
|
94
|
+
timeout?: Duration;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Consecutive failures needed to report unhealthy
|
|
98
|
+
*/
|
|
99
|
+
retries?: number;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Start period for the container to initialize before starting
|
|
103
|
+
* health-retries countdown
|
|
104
|
+
* Can be a number (in seconds) or string with unit (e.g., "40s", "1m")
|
|
105
|
+
* @default 0
|
|
106
|
+
*/
|
|
107
|
+
startPeriod?: Duration;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Time between running the check during the start period
|
|
111
|
+
* Can be a number (in seconds) or string with unit (e.g., "5s", "500ms")
|
|
112
|
+
* Requires Docker API 1.44+
|
|
113
|
+
* @default 0
|
|
114
|
+
*/
|
|
115
|
+
startInterval?: Duration;
|
|
116
|
+
}
|
|
117
|
+
|
|
62
118
|
/**
|
|
63
119
|
* Properties for creating a Docker container
|
|
64
120
|
*/
|
|
@@ -115,6 +171,11 @@ export interface ContainerProps {
|
|
|
115
171
|
* Start the container after creation
|
|
116
172
|
*/
|
|
117
173
|
start?: boolean;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Healthcheck configuration
|
|
177
|
+
*/
|
|
178
|
+
healthcheck?: HealthcheckConfig;
|
|
118
179
|
}
|
|
119
180
|
|
|
120
181
|
/**
|
|
@@ -172,6 +233,41 @@ export interface Container extends ContainerProps {
|
|
|
172
233
|
* restart: "always",
|
|
173
234
|
* start: true
|
|
174
235
|
* });
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* // Create a container with healthcheck using numeric values (seconds)
|
|
239
|
+
* const healthyContainer = await Container("api", {
|
|
240
|
+
* image: "my-api:latest",
|
|
241
|
+
* ports: [
|
|
242
|
+
* { external: 3000, internal: 3000 }
|
|
243
|
+
* ],
|
|
244
|
+
* healthcheck: {
|
|
245
|
+
* cmd: ["curl", "-f", "http://localhost:3000/health"],
|
|
246
|
+
* interval: 30,
|
|
247
|
+
* timeout: 10,
|
|
248
|
+
* retries: 3,
|
|
249
|
+
* startPeriod: 40
|
|
250
|
+
* },
|
|
251
|
+
* start: true
|
|
252
|
+
* });
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* // Create a container with healthcheck using string duration format
|
|
256
|
+
* const healthyContainer2 = await Container("api2", {
|
|
257
|
+
* image: "my-api:latest",
|
|
258
|
+
* ports: [
|
|
259
|
+
* { external: 3001, internal: 3000 }
|
|
260
|
+
* ],
|
|
261
|
+
* healthcheck: {
|
|
262
|
+
* cmd: ["curl", "-f", "http://localhost:3000/health"],
|
|
263
|
+
* interval: "30s",
|
|
264
|
+
* timeout: "10s",
|
|
265
|
+
* retries: 3,
|
|
266
|
+
* startPeriod: "1m",
|
|
267
|
+
* startInterval: "500ms"
|
|
268
|
+
* },
|
|
269
|
+
* start: true
|
|
270
|
+
* });
|
|
175
271
|
*/
|
|
176
272
|
export const Container = Resource(
|
|
177
273
|
"docker::Container",
|
|
@@ -245,6 +341,7 @@ export const Container = Resource(
|
|
|
245
341
|
env: props.environment,
|
|
246
342
|
volumes: volumeMappings,
|
|
247
343
|
cmd: props.command,
|
|
344
|
+
healthcheck: props.healthcheck,
|
|
248
345
|
});
|
|
249
346
|
|
|
250
347
|
// Connect to networks if specified
|
package/src/llms.cloudflare.txt
CHANGED
|
@@ -301,7 +301,7 @@ const app = await alchemy("my-app", {
|
|
|
301
301
|
### Framework Integration (Vite/React/etc.)
|
|
302
302
|
```typescript
|
|
303
303
|
const website = await Vite("website", {
|
|
304
|
-
|
|
304
|
+
entrypoint: "./src/worker.ts",
|
|
305
305
|
command: "bun run build", // Build command
|
|
306
306
|
bindings: {
|
|
307
307
|
API: await Worker("api", { entrypoint: "./api/worker.ts" }),
|
|
@@ -319,7 +319,7 @@ await alchemy.run("backend", async () => {
|
|
|
319
319
|
});
|
|
320
320
|
|
|
321
321
|
await alchemy.run("frontend", async () => {
|
|
322
|
-
await Vite("website", {
|
|
322
|
+
await Vite("website", { entrypoint: "./src/worker.ts" });
|
|
323
323
|
});
|
|
324
324
|
```
|
|
325
325
|
|
package/src/neon/branch.ts
CHANGED
|
@@ -76,7 +76,7 @@ export interface NeonBranchProps extends NeonApiOptions {
|
|
|
76
76
|
endpoints: neon.BranchCreateRequestEndpointOptions[];
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
export interface NeonBranch
|
|
79
|
+
export interface NeonBranch {
|
|
80
80
|
/**
|
|
81
81
|
* The branch ID. This value is generated when a branch is created. A branch_id value has a br- prefix. For example: br-small-term-683261.
|
|
82
82
|
*/
|
|
@@ -215,7 +215,7 @@ export const NeonBranch = Resource(
|
|
|
215
215
|
),
|
|
216
216
|
);
|
|
217
217
|
|
|
218
|
-
return
|
|
218
|
+
return {
|
|
219
219
|
id: data.branch.id,
|
|
220
220
|
name: data.branch.name,
|
|
221
221
|
projectId: data.branch.project_id,
|
|
@@ -237,7 +237,7 @@ export const NeonBranch = Resource(
|
|
|
237
237
|
databases: data.databases,
|
|
238
238
|
roles: data.roles.map(formatRole),
|
|
239
239
|
connectionUris: data.connection_uris?.map(formatConnectionUri) ?? [],
|
|
240
|
-
}
|
|
240
|
+
};
|
|
241
241
|
}
|
|
242
242
|
case "update": {
|
|
243
243
|
if (
|
|
@@ -263,7 +263,8 @@ export const NeonBranch = Resource(
|
|
|
263
263
|
},
|
|
264
264
|
},
|
|
265
265
|
});
|
|
266
|
-
|
|
266
|
+
|
|
267
|
+
return {
|
|
267
268
|
...this.output,
|
|
268
269
|
name,
|
|
269
270
|
protected: data.branch.protected,
|
|
@@ -271,7 +272,7 @@ export const NeonBranch = Resource(
|
|
|
271
272
|
expiresAt: data.branch.expires_at
|
|
272
273
|
? new Date(data.branch.expires_at)
|
|
273
274
|
: undefined,
|
|
274
|
-
}
|
|
275
|
+
};
|
|
275
276
|
}
|
|
276
277
|
}
|
|
277
278
|
},
|
package/src/neon/project.ts
CHANGED
|
@@ -229,7 +229,7 @@ export const NeonProject = Resource(
|
|
|
229
229
|
.then((res) => res.data.endpoints),
|
|
230
230
|
]);
|
|
231
231
|
|
|
232
|
-
return
|
|
232
|
+
return {
|
|
233
233
|
id: data.project.id,
|
|
234
234
|
name: data.project.name,
|
|
235
235
|
created_at: data.project.created_at,
|
|
@@ -248,7 +248,7 @@ export const NeonProject = Resource(
|
|
|
248
248
|
databases: data.databases as [neon.Database, ...neon.Database[]],
|
|
249
249
|
branch,
|
|
250
250
|
endpoints: endpoints as [neon.Endpoint, ...neon.Endpoint[]],
|
|
251
|
-
}
|
|
251
|
+
};
|
|
252
252
|
}
|
|
253
253
|
case "update": {
|
|
254
254
|
const { data } = await api.updateProject({
|
|
@@ -264,7 +264,7 @@ export const NeonProject = Resource(
|
|
|
264
264
|
},
|
|
265
265
|
},
|
|
266
266
|
});
|
|
267
|
-
return
|
|
267
|
+
return {
|
|
268
268
|
...this.output,
|
|
269
269
|
name: data.project.name,
|
|
270
270
|
updated_at: data.project.updated_at,
|
|
@@ -274,7 +274,7 @@ export const NeonProject = Resource(
|
|
|
274
274
|
settings: data.project.settings,
|
|
275
275
|
default_endpoint_settings: data.project.default_endpoint_settings,
|
|
276
276
|
history_retention_seconds: data.project.history_retention_seconds,
|
|
277
|
-
}
|
|
277
|
+
};
|
|
278
278
|
}
|
|
279
279
|
case "delete": {
|
|
280
280
|
if (this.output?.id) {
|
package/src/serde.ts
CHANGED
|
@@ -119,6 +119,10 @@ export async function serialize(
|
|
|
119
119
|
.filter((prop) => prop === "env")
|
|
120
120
|
.map((prop) => [prop, (value as any)[prop]]),
|
|
121
121
|
);
|
|
122
|
+
} else if (isBinary(value)) {
|
|
123
|
+
return {
|
|
124
|
+
"@buffer": await serializeBinary(value),
|
|
125
|
+
};
|
|
122
126
|
} else if (value && typeof value === "object") {
|
|
123
127
|
for (const symbol of Object.getOwnPropertySymbols(value)) {
|
|
124
128
|
assertNotUniqueSymbol(symbol);
|
|
@@ -195,6 +199,8 @@ export async function deserialize(
|
|
|
195
199
|
return parseSymbol(value["@symbol"]);
|
|
196
200
|
} else if ("@scope" in value) {
|
|
197
201
|
return scope;
|
|
202
|
+
} else if ("@buffer" in value) {
|
|
203
|
+
return Buffer.from(value["@buffer"], "base64");
|
|
198
204
|
}
|
|
199
205
|
|
|
200
206
|
return Object.fromEntries(
|
|
@@ -227,3 +233,47 @@ function assertNotUniqueSymbol(symbol: Symbol) {
|
|
|
227
233
|
throw new Error(`Cannot serialize unique symbol: ${symbol.description}`);
|
|
228
234
|
}
|
|
229
235
|
}
|
|
236
|
+
|
|
237
|
+
export const isBinary = (
|
|
238
|
+
value: any,
|
|
239
|
+
): value is Buffer | Uint8Array | ArrayBuffer | Blob | ReadableStream => {
|
|
240
|
+
return (
|
|
241
|
+
value instanceof Buffer ||
|
|
242
|
+
value instanceof Uint8Array ||
|
|
243
|
+
value instanceof ArrayBuffer ||
|
|
244
|
+
value instanceof Blob ||
|
|
245
|
+
value instanceof ReadableStream ||
|
|
246
|
+
ArrayBuffer.isView(value)
|
|
247
|
+
);
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
export const serializeBinary = async (
|
|
251
|
+
value: Buffer | Uint8Array | ArrayBuffer | Blob | ReadableStream,
|
|
252
|
+
): Promise<string> => {
|
|
253
|
+
return value instanceof Buffer
|
|
254
|
+
? value.toString("base64")
|
|
255
|
+
: value instanceof Uint8Array
|
|
256
|
+
? value.toString("base64")
|
|
257
|
+
: value instanceof ArrayBuffer
|
|
258
|
+
? serializeBinary(Buffer.from(value))
|
|
259
|
+
: value instanceof Blob
|
|
260
|
+
? serializeBinary(await value.arrayBuffer())
|
|
261
|
+
: value instanceof ReadableStream
|
|
262
|
+
? serializeBinary(await streamToBuffer(value))
|
|
263
|
+
: value;
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
export async function streamToBuffer(
|
|
267
|
+
stream: ReadableStream<Uint8Array>,
|
|
268
|
+
): Promise<Buffer> {
|
|
269
|
+
const reader = stream.getReader();
|
|
270
|
+
const chunks: Uint8Array[] = [];
|
|
271
|
+
|
|
272
|
+
while (true) {
|
|
273
|
+
const { done, value } = await reader.read();
|
|
274
|
+
if (done) break;
|
|
275
|
+
chunks.push(value);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return Buffer.concat(chunks);
|
|
279
|
+
}
|
package/src/test/bun.ts
CHANGED
|
@@ -306,7 +306,7 @@ const app = await alchemy("my-app", {
|
|
|
306
306
|
### Framework Integration (Vite/React/etc.)
|
|
307
307
|
```typescript
|
|
308
308
|
const website = await Vite("website", {
|
|
309
|
-
|
|
309
|
+
entrypoint: "./src/worker.ts",
|
|
310
310
|
command: "bun run build", // Build command
|
|
311
311
|
bindings: {
|
|
312
312
|
API: await Worker("api", { entrypoint: "./api/worker.ts" }),
|
|
@@ -324,7 +324,7 @@ await alchemy.run("backend", async () => {
|
|
|
324
324
|
});
|
|
325
325
|
|
|
326
326
|
await alchemy.run("frontend", async () => {
|
|
327
|
-
await Vite("website", {
|
|
327
|
+
await Vite("website", { entrypoint: "./src/worker.ts" });
|
|
328
328
|
});
|
|
329
329
|
```
|
|
330
330
|
|
|
@@ -1,74 +1,292 @@
|
|
|
1
|
-
|
|
1
|
+
Welcome to your new TanStack app!
|
|
2
2
|
|
|
3
3
|
[](https://alchemy.run)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
# Getting Started
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
To run this application:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bun install
|
|
11
|
+
bunx --bun run start
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
# Building For Production
|
|
15
|
+
|
|
16
|
+
To build this application for production:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
bunx --bun run build
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Testing
|
|
23
|
+
|
|
24
|
+
This project uses [Vitest](https://vitest.dev/) for testing. You can run the tests with:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
bunx --bun run test
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Styling
|
|
31
|
+
|
|
32
|
+
This project uses [Tailwind CSS](https://tailwindcss.com/) for styling.
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
## Routing
|
|
38
|
+
This project uses [TanStack Router](https://tanstack.com/router). The initial setup is a file based router. Which means that the routes are managed as files in `src/routes`.
|
|
39
|
+
|
|
40
|
+
### Adding A Route
|
|
41
|
+
|
|
42
|
+
To add a new route to your application just add another a new file in the `./src/routes` directory.
|
|
43
|
+
|
|
44
|
+
TanStack will automatically generate the content of the route file for you.
|
|
45
|
+
|
|
46
|
+
Now that you have two routes you can use a `Link` component to navigate between them.
|
|
47
|
+
|
|
48
|
+
### Adding Links
|
|
49
|
+
|
|
50
|
+
To use SPA (Single Page Application) navigation you will need to import the `Link` component from `@tanstack/react-router`.
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
import { Link } from "@tanstack/react-router";
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Then anywhere in your JSX you can use it like so:
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
<Link to="/about">About</Link>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
This will create a link that will navigate to the `/about` route.
|
|
63
|
+
|
|
64
|
+
More information on the `Link` component can be found in the [Link documentation](https://tanstack.com/router/v1/docs/framework/react/api/router/linkComponent).
|
|
65
|
+
|
|
66
|
+
### Using A Layout
|
|
67
|
+
|
|
68
|
+
In the File Based Routing setup the layout is located in `src/routes/__root.tsx`. Anything you add to the root route will appear in all the routes. The route content will appear in the JSX where you use the `<Outlet />` component.
|
|
69
|
+
|
|
70
|
+
Here is an example layout that includes a header:
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
import { Outlet, createRootRoute } from '@tanstack/react-router'
|
|
74
|
+
import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
|
|
75
|
+
|
|
76
|
+
import { Link } from "@tanstack/react-router";
|
|
77
|
+
|
|
78
|
+
export const Route = createRootRoute({
|
|
79
|
+
component: () => (
|
|
80
|
+
<>
|
|
81
|
+
<header>
|
|
82
|
+
<nav>
|
|
83
|
+
<Link to="/">Home</Link>
|
|
84
|
+
<Link to="/about">About</Link>
|
|
85
|
+
</nav>
|
|
86
|
+
</header>
|
|
87
|
+
<Outlet />
|
|
88
|
+
<TanStackRouterDevtools />
|
|
89
|
+
</>
|
|
90
|
+
),
|
|
91
|
+
})
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The `<TanStackRouterDevtools />` component is not required so you can remove it if you don't want it in your layout.
|
|
95
|
+
|
|
96
|
+
More information on layouts can be found in the [Layouts documentation](https://tanstack.com/router/latest/docs/framework/react/guide/routing-concepts#layouts).
|
|
8
97
|
|
|
9
|
-
It's deployed automagically with Netlify!
|
|
10
98
|
|
|
11
|
-
|
|
99
|
+
## Data Fetching
|
|
12
100
|
|
|
13
|
-
|
|
101
|
+
There are multiple ways to fetch data in your application. You can use TanStack Query to fetch data from a server. But you can also use the `loader` functionality built into TanStack Router to load the data for a route before it's rendered.
|
|
14
102
|
|
|
15
|
-
|
|
103
|
+
For example:
|
|
16
104
|
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
|
|
105
|
+
```tsx
|
|
106
|
+
const peopleRoute = createRoute({
|
|
107
|
+
getParentRoute: () => rootRoute,
|
|
108
|
+
path: "/people",
|
|
109
|
+
loader: async () => {
|
|
110
|
+
const response = await fetch("https://swapi.dev/api/people");
|
|
111
|
+
return response.json() as Promise<{
|
|
112
|
+
results: {
|
|
113
|
+
name: string;
|
|
114
|
+
}[];
|
|
115
|
+
}>;
|
|
116
|
+
},
|
|
117
|
+
component: () => {
|
|
118
|
+
const data = peopleRoute.useLoaderData();
|
|
119
|
+
return (
|
|
120
|
+
<ul>
|
|
121
|
+
{data.results.map((person) => (
|
|
122
|
+
<li key={person.name}>{person.name}</li>
|
|
123
|
+
))}
|
|
124
|
+
</ul>
|
|
125
|
+
);
|
|
126
|
+
},
|
|
127
|
+
});
|
|
20
128
|
```
|
|
21
129
|
|
|
22
|
-
|
|
130
|
+
Loaders simplify your data fetching logic dramatically. Check out more information in the [Loader documentation](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#loader-parameters).
|
|
23
131
|
|
|
24
|
-
|
|
132
|
+
### React-Query
|
|
25
133
|
|
|
26
|
-
|
|
27
|
-
In production, the markdown doc pages are fetched from the GitHub repos of the projects, but in development they are read from the local file system.
|
|
134
|
+
React-Query is an excellent addition or alternative to route loading and integrating it into you application is a breeze.
|
|
28
135
|
|
|
29
|
-
|
|
136
|
+
First add your dependencies:
|
|
30
137
|
|
|
31
|
-
|
|
138
|
+
```bash
|
|
139
|
+
bun install @tanstack/react-query @tanstack/react-query-devtools
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Next we'll need to create a query client and provider. We recommend putting those in `main.tsx`.
|
|
143
|
+
|
|
144
|
+
```tsx
|
|
145
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
146
|
+
|
|
147
|
+
// ...
|
|
148
|
+
|
|
149
|
+
const queryClient = new QueryClient();
|
|
150
|
+
|
|
151
|
+
// ...
|
|
152
|
+
|
|
153
|
+
if (!rootElement.innerHTML) {
|
|
154
|
+
const root = ReactDOM.createRoot(rootElement);
|
|
155
|
+
|
|
156
|
+
root.render(
|
|
157
|
+
<QueryClientProvider client={queryClient}>
|
|
158
|
+
<RouterProvider router={router} />
|
|
159
|
+
</QueryClientProvider>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
You can also add TanStack Query Devtools to the root route (optional).
|
|
165
|
+
|
|
166
|
+
```tsx
|
|
167
|
+
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
|
168
|
+
|
|
169
|
+
const rootRoute = createRootRoute({
|
|
170
|
+
component: () => (
|
|
171
|
+
<>
|
|
172
|
+
<Outlet />
|
|
173
|
+
<ReactQueryDevtools buttonPosition="top-right" />
|
|
174
|
+
<TanStackRouterDevtools />
|
|
175
|
+
</>
|
|
176
|
+
),
|
|
177
|
+
});
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Now you can use `useQuery` to fetch your data.
|
|
181
|
+
|
|
182
|
+
```tsx
|
|
183
|
+
import { useQuery } from "@tanstack/react-query";
|
|
184
|
+
|
|
185
|
+
import "./App.css";
|
|
186
|
+
|
|
187
|
+
function App() {
|
|
188
|
+
const { data } = useQuery({
|
|
189
|
+
queryKey: ["people"],
|
|
190
|
+
queryFn: () =>
|
|
191
|
+
fetch("https://swapi.dev/api/people")
|
|
192
|
+
.then((res) => res.json())
|
|
193
|
+
.then((data) => data.results as { name: string }[]),
|
|
194
|
+
initialData: [],
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
return (
|
|
198
|
+
<div>
|
|
199
|
+
<ul>
|
|
200
|
+
{data.map((person) => (
|
|
201
|
+
<li key={person.name}>{person.name}</li>
|
|
202
|
+
))}
|
|
203
|
+
</ul>
|
|
204
|
+
</div>
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export default App;
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
You can find out everything you need to know on how to use React-Query in the [React-Query documentation](https://tanstack.com/query/latest/docs/framework/react/overview).
|
|
212
|
+
|
|
213
|
+
## State Management
|
|
214
|
+
|
|
215
|
+
Another common requirement for React applications is state management. There are many options for state management in React. TanStack Store provides a great starting point for your project.
|
|
216
|
+
|
|
217
|
+
First you need to add TanStack Store as a dependency:
|
|
32
218
|
|
|
33
|
-
```
|
|
34
|
-
|
|
219
|
+
```bash
|
|
220
|
+
bun install @tanstack/store
|
|
35
221
|
```
|
|
36
222
|
|
|
37
|
-
|
|
223
|
+
Now let's create a simple counter in the `src/App.tsx` file as a demonstration.
|
|
38
224
|
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
225
|
+
```tsx
|
|
226
|
+
import { useStore } from "@tanstack/react-store";
|
|
227
|
+
import { Store } from "@tanstack/store";
|
|
228
|
+
import "./App.css";
|
|
229
|
+
|
|
230
|
+
const countStore = new Store(0);
|
|
231
|
+
|
|
232
|
+
function App() {
|
|
233
|
+
const count = useStore(countStore);
|
|
234
|
+
return (
|
|
235
|
+
<div>
|
|
236
|
+
<button onClick={() => countStore.setState((n) => n + 1)}>
|
|
237
|
+
Increment - {count}
|
|
238
|
+
</button>
|
|
239
|
+
</div>
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export default App;
|
|
43
244
|
```
|
|
44
245
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
246
|
+
One of the many nice features of TanStack Store is the ability to derive state from other state. That derived state will update when the base state updates.
|
|
247
|
+
|
|
248
|
+
Let's check this out by doubling the count using derived state.
|
|
249
|
+
|
|
250
|
+
```tsx
|
|
251
|
+
import { useStore } from "@tanstack/react-store";
|
|
252
|
+
import { Store, Derived } from "@tanstack/store";
|
|
253
|
+
import "./App.css";
|
|
254
|
+
|
|
255
|
+
const countStore = new Store(0);
|
|
256
|
+
|
|
257
|
+
const doubledStore = new Derived({
|
|
258
|
+
fn: () => countStore.state * 2,
|
|
259
|
+
deps: [countStore],
|
|
260
|
+
});
|
|
261
|
+
doubledStore.mount();
|
|
262
|
+
|
|
263
|
+
function App() {
|
|
264
|
+
const count = useStore(countStore);
|
|
265
|
+
const doubledCount = useStore(doubledStore);
|
|
266
|
+
|
|
267
|
+
return (
|
|
268
|
+
<div>
|
|
269
|
+
<button onClick={() => countStore.setState((n) => n + 1)}>
|
|
270
|
+
Increment - {count}
|
|
271
|
+
</button>
|
|
272
|
+
<div>Doubled - {doubledCount}</div>
|
|
273
|
+
</div>
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export default App;
|
|
66
278
|
```
|
|
67
279
|
|
|
68
|
-
|
|
280
|
+
We use the `Derived` class to create a new store that is derived from another store. The `Derived` class has a `mount` method that will start the derived store updating.
|
|
281
|
+
|
|
282
|
+
Once we've created the derived store we can use it in the `App` component just like we would any other store using the `useStore` hook.
|
|
283
|
+
|
|
284
|
+
You can find out everything you need to know on how to use TanStack Store in the [TanStack Store documentation](https://tanstack.com/store/latest).
|
|
285
|
+
|
|
286
|
+
# Demo files
|
|
287
|
+
|
|
288
|
+
Files prefixed with `demo` can be safely deleted. They are there to provide a starting point for you to play around with the features you've installed.
|
|
69
289
|
|
|
70
|
-
|
|
71
|
-
> The updated pages need to be manually reloaded in the browser.
|
|
290
|
+
# Learn More
|
|
72
291
|
|
|
73
|
-
|
|
74
|
-
> You will need to update the `docs/config.json` file (in the project's repo) if you add a new doc page!
|
|
292
|
+
You can learn more about all of the offerings from TanStack in the [TanStack documentation](https://tanstack.com).
|