alchemy 0.2.5 → 0.3.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 (151) hide show
  1. package/README.md +3 -3
  2. package/lib/ai/astro-file.d.ts +137 -0
  3. package/lib/ai/astro-file.js +173 -0
  4. package/lib/ai/client.d.ts +2 -10
  5. package/lib/ai/client.js +8 -24
  6. package/lib/ai/css-file.d.ts +131 -0
  7. package/lib/ai/css-file.js +158 -0
  8. package/lib/ai/data.d.ts +45 -5
  9. package/lib/ai/data.js +45 -10
  10. package/lib/ai/document.d.ts +44 -20
  11. package/lib/ai/document.js +95 -28
  12. package/lib/ai/html-file.d.ts +128 -0
  13. package/lib/ai/html-file.js +155 -0
  14. package/lib/ai/index.d.ts +7 -0
  15. package/lib/ai/index.js +7 -0
  16. package/lib/ai/json-file.d.ts +160 -0
  17. package/lib/ai/json-file.js +208 -0
  18. package/lib/ai/typescript-file.d.ts +140 -0
  19. package/lib/ai/typescript-file.js +176 -0
  20. package/lib/ai/vue-file.d.ts +126 -0
  21. package/lib/ai/vue-file.js +153 -0
  22. package/lib/ai/yaml-file.d.ts +169 -0
  23. package/lib/ai/yaml-file.js +236 -0
  24. package/lib/cloudflare/dns.d.ts +88 -0
  25. package/lib/cloudflare/dns.js +192 -0
  26. package/lib/cloudflare/index.d.ts +2 -1
  27. package/lib/cloudflare/index.js +2 -1
  28. package/lib/cloudflare/r2-rest-state-store.d.ts +125 -0
  29. package/lib/cloudflare/r2-rest-state-store.js +254 -0
  30. package/lib/cloudflare/response.d.ts +12 -0
  31. package/lib/cloudflare/response.js +0 -0
  32. package/lib/cloudflare/zone.d.ts +18 -0
  33. package/lib/cloudflare/zone.js +17 -4
  34. package/lib/dns/godaddy.d.ts +7 -0
  35. package/lib/dns/godaddy.js +21 -0
  36. package/lib/dns/import-dns.d.ts +82 -0
  37. package/lib/dns/import-dns.js +114 -0
  38. package/lib/dns/index.d.ts +2 -0
  39. package/lib/dns/index.js +2 -0
  40. package/lib/dns/record.d.ts +88 -0
  41. package/lib/dns/record.js +13 -0
  42. package/lib/fs/file-system-state-store.d.ts +17 -0
  43. package/lib/fs/file-system-state-store.js +87 -0
  44. package/lib/fs/folder.d.ts +10 -0
  45. package/lib/fs/folder.js +2 -2
  46. package/lib/fs/index.d.ts +4 -4
  47. package/lib/fs/index.js +4 -4
  48. package/lib/fs/{json-file.d.ts → static-json-file.d.ts} +2 -2
  49. package/lib/fs/static-json-file.js +14 -0
  50. package/lib/fs/{text-file.d.ts → static-text-file.d.ts} +2 -2
  51. package/lib/fs/{text-file.js → static-text-file.js} +1 -1
  52. package/lib/fs/{typescript-file.d.ts → static-typescript-file.d.ts} +2 -2
  53. package/lib/fs/{typescript-file.js → static-typescript-file.js} +1 -1
  54. package/lib/fs/{yaml-file.d.ts → static-yaml-file.d.ts} +2 -2
  55. package/lib/fs/{yaml-file.js → static-yaml-file.js} +1 -1
  56. package/lib/internal/getting-started.d.ts +10 -0
  57. package/lib/internal/getting-started.js +94 -0
  58. package/lib/internal/project.d.ts +13 -0
  59. package/lib/internal/project.js +101 -0
  60. package/lib/internal/providers.d.ts +23 -0
  61. package/lib/internal/providers.js +148 -0
  62. package/lib/resource.js +8 -1
  63. package/lib/scope.d.ts +1 -1
  64. package/lib/scope.js +4 -2
  65. package/lib/state.d.ts +1 -16
  66. package/lib/state.js +0 -87
  67. package/lib/test/bun.d.ts +11 -0
  68. package/lib/test/bun.js +36 -8
  69. package/lib/web/astro.d.ts +147 -0
  70. package/lib/web/astro.js +414 -0
  71. package/lib/{shadcn/component.js → web/shadcn-component.js} +2 -9
  72. package/lib/web/shadcn.d.ts +97 -0
  73. package/lib/web/shadcn.js +99 -0
  74. package/lib/web/tailwind.d.ts +64 -0
  75. package/lib/web/tailwind.js +97 -0
  76. package/lib/{vite → web}/vite.d.ts +5 -0
  77. package/lib/{vite → web}/vite.js +44 -44
  78. package/lib/web/vitepress/custom-theme.d.ts +173 -0
  79. package/lib/web/vitepress/custom-theme.js +336 -0
  80. package/lib/{vitepress → web/vitepress}/dependencies.d.ts +2 -2
  81. package/lib/{vitepress → web/vitepress}/dependencies.js +1 -1
  82. package/lib/web/vitepress/home-page.d.ts +244 -0
  83. package/lib/web/vitepress/home-page.js +134 -0
  84. package/lib/{vitepress → web/vitepress}/index.d.ts +1 -0
  85. package/lib/{vitepress → web/vitepress}/index.js +1 -0
  86. package/lib/{vitepress → web/vitepress}/vitepress.d.ts +10 -8
  87. package/lib/{vitepress → web/vitepress}/vitepress.js +11 -12
  88. package/package.json +6 -2
  89. package/src/ai/astro-file.ts +288 -0
  90. package/src/ai/client.ts +8 -28
  91. package/src/ai/css-file.ts +266 -0
  92. package/src/ai/data.ts +53 -16
  93. package/src/ai/document.ts +130 -33
  94. package/src/ai/html-file.ts +263 -0
  95. package/src/ai/index.ts +7 -0
  96. package/src/ai/json-file.ts +349 -0
  97. package/src/ai/typescript-file.ts +293 -0
  98. package/src/ai/vue-file.ts +261 -0
  99. package/src/ai/yaml-file.ts +368 -0
  100. package/src/apply.ts +0 -1
  101. package/src/cloudflare/dns.ts +344 -0
  102. package/src/cloudflare/index.ts +2 -1
  103. package/src/cloudflare/r2-rest-state-store.ts +353 -0
  104. package/src/cloudflare/response.ts +9 -0
  105. package/src/cloudflare/zone.ts +39 -23
  106. package/src/dns/godaddy.ts +29 -0
  107. package/src/dns/import-dns.ts +213 -0
  108. package/src/dns/index.ts +2 -0
  109. package/src/dns/record.ts +121 -0
  110. package/src/fs/file-system-state-store.ts +109 -0
  111. package/src/fs/folder.ts +14 -2
  112. package/src/fs/index.ts +4 -4
  113. package/src/fs/{json-file.ts → static-json-file.ts} +13 -3
  114. package/src/fs/{text-file.ts → static-text-file.ts} +5 -2
  115. package/src/fs/{typescript-file.ts → static-typescript-file.ts} +3 -3
  116. package/src/fs/{yaml-file.ts → static-yaml-file.ts} +5 -2
  117. package/src/internal/getting-started.ts +107 -0
  118. package/src/internal/project.ts +119 -0
  119. package/src/internal/providers.ts +209 -0
  120. package/src/resource.ts +10 -1
  121. package/src/scope.ts +5 -6
  122. package/src/state.ts +1 -111
  123. package/src/test/bun.ts +60 -10
  124. package/src/web/astro.ts +644 -0
  125. package/src/{shadcn/component.ts → web/shadcn-component.ts} +5 -13
  126. package/src/web/shadcn.ts +219 -0
  127. package/src/web/tailwind.ts +167 -0
  128. package/src/{vite → web}/vite.ts +54 -56
  129. package/src/web/vitepress/custom-theme.ts +514 -0
  130. package/src/{vitepress → web/vitepress}/dependencies.ts +2 -2
  131. package/src/web/vitepress/home-page.ts +363 -0
  132. package/src/{vitepress → web/vitepress}/index.ts +1 -0
  133. package/src/{vitepress → web/vitepress}/vitepress.ts +34 -27
  134. package/lib/cloudflare/state.d.ts +0 -82
  135. package/lib/cloudflare/state.js +0 -108
  136. package/lib/fs/json-file.js +0 -7
  137. package/lib/internal/docs.d.ts +0 -5
  138. package/lib/internal/docs.js +0 -287
  139. package/lib/shadcn/index.d.ts +0 -1
  140. package/lib/shadcn/index.js +0 -1
  141. package/lib/vite/index.d.ts +0 -1
  142. package/lib/vite/index.js +0 -1
  143. package/lib/vitepress/home-page.d.ts +0 -133
  144. package/lib/vitepress/home-page.js +0 -11
  145. package/src/cloudflare/state.ts +0 -138
  146. package/src/internal/docs.ts +0 -338
  147. package/src/shadcn/index.ts +0 -1
  148. package/src/vite/index.ts +0 -1
  149. package/src/vitepress/home-page.ts +0 -166
  150. /package/lib/{shadcn/component.d.ts → web/shadcn-component.d.ts} +0 -0
  151. /package/src/{vitepress → web/vitepress}/index.md +0 -0
@@ -0,0 +1,363 @@
1
+ import alchemy from "alchemy";
2
+ import yaml from "yaml";
3
+ import { Document } from "../../ai/document";
4
+ import type { Secret } from "../../secret";
5
+
6
+ /**
7
+ * Image that can be themed for light/dark mode
8
+ */
9
+ export interface ThemeableImage {
10
+ /**
11
+ * Image source URL
12
+ */
13
+ src?: string;
14
+
15
+ /**
16
+ * Image alt text
17
+ */
18
+ alt?: string;
19
+
20
+ /**
21
+ * Light theme image URL
22
+ */
23
+ light?: string;
24
+
25
+ /**
26
+ * Dark theme image URL
27
+ */
28
+ dark?: string;
29
+ }
30
+
31
+ /**
32
+ * Hero action button configuration
33
+ */
34
+ export interface HeroAction {
35
+ /**
36
+ * Color theme of the button
37
+ * @default "brand"
38
+ */
39
+ theme?: "brand" | "alt";
40
+
41
+ /**
42
+ * Label of the button
43
+ */
44
+ text: string;
45
+
46
+ /**
47
+ * Destination link of the button
48
+ */
49
+ link: string;
50
+
51
+ /**
52
+ * Link target attribute
53
+ */
54
+ target?: string;
55
+
56
+ /**
57
+ * Link rel attribute
58
+ */
59
+ rel?: string;
60
+ }
61
+
62
+ /**
63
+ * Hero section configuration
64
+ */
65
+ export interface Hero {
66
+ /**
67
+ * The string shown top of text. Comes with brand color
68
+ * and expected to be short, such as product name.
69
+ */
70
+ name?: string;
71
+
72
+ /**
73
+ * The main text for the hero section. This will be defined
74
+ * as h1 tag.
75
+ */
76
+ text: string;
77
+
78
+ /**
79
+ * Tagline displayed below text
80
+ */
81
+ tagline?: string;
82
+
83
+ /**
84
+ * The image displayed next to the text and tagline area
85
+ */
86
+ image?: string | ThemeableImage;
87
+
88
+ /**
89
+ * Action buttons to display in home hero section
90
+ */
91
+ actions?: HeroAction[];
92
+ }
93
+
94
+ /**
95
+ * Feature item configuration
96
+ */
97
+ export interface Feature {
98
+ /**
99
+ * Show icon on each feature box
100
+ */
101
+ icon?: string | ThemeableImage;
102
+
103
+ /**
104
+ * Title of the feature
105
+ */
106
+ title: string;
107
+
108
+ /**
109
+ * Details of the feature
110
+ */
111
+ details: string;
112
+
113
+ /**
114
+ * Link when clicked on feature component
115
+ */
116
+ link?: string;
117
+
118
+ /**
119
+ * Link text to be shown inside feature component
120
+ */
121
+ linkText?: string;
122
+
123
+ /**
124
+ * Link rel attribute
125
+ */
126
+ rel?: string;
127
+
128
+ /**
129
+ * Link target attribute
130
+ */
131
+ target?: string;
132
+ }
133
+
134
+ /**
135
+ * VitePress home page configuration
136
+ */
137
+ export interface HomePageConfig {
138
+ /**
139
+ * Use home page layout
140
+ */
141
+ layout: "home";
142
+
143
+ /**
144
+ * Hero section configuration
145
+ */
146
+ hero?: Hero;
147
+
148
+ /**
149
+ * Features section configuration
150
+ */
151
+ features?: Feature[];
152
+
153
+ /**
154
+ * Whether to apply default markdown styles
155
+ * @default true
156
+ */
157
+ markdownStyles?: boolean;
158
+ }
159
+
160
+ /**
161
+ * Properties for creating or updating a VitePress HomePage
162
+ */
163
+ export interface HomePageProps {
164
+ /**
165
+ * Output directory for the home page markdown file
166
+ */
167
+ outFile: string;
168
+
169
+ /**
170
+ * Title of the home page document
171
+ */
172
+ title: string;
173
+
174
+ /**
175
+ * Hero section configuration
176
+ */
177
+ hero?: Hero;
178
+
179
+ /**
180
+ * Features section configuration
181
+ */
182
+ features?: Feature[];
183
+
184
+ /**
185
+ * User prompt describing the design of the home page
186
+ */
187
+ prompt: string;
188
+
189
+ /**
190
+ * Optional extension to the built-in system prompt
191
+ */
192
+ systemPromptExtension?: string;
193
+
194
+ /**
195
+ * Base URL for the OpenAI API
196
+ * @default 'https://api.openai.com/v1'
197
+ */
198
+ baseURL?: string;
199
+
200
+ /**
201
+ * OpenAI API key to use for generating content
202
+ * If not provided, will use OPENAI_API_KEY environment variable
203
+ */
204
+ apiKey?: Secret;
205
+
206
+ /**
207
+ * Model configuration for the AI generator
208
+ */
209
+ model?: import("../../ai/client").ModelConfig;
210
+
211
+ /**
212
+ * Temperature for controlling randomness in generation
213
+ * @default 0.7
214
+ */
215
+ temperature?: number;
216
+ }
217
+
218
+ /**
219
+ * Output type for the HomePage resource
220
+ */
221
+ export type HomePage = import("../../ai/document").Document;
222
+
223
+ /**
224
+ * Parse YAML frontmatter to home page config
225
+ */
226
+ export function parseHomePage(content: string): HomePageConfig {
227
+ const match = content.match(/^---\n([\s\S]*?)\n---/);
228
+ if (!match) {
229
+ throw new Error("Invalid frontmatter format");
230
+ }
231
+ return yaml.parse(match[1]) as HomePageConfig;
232
+ }
233
+
234
+ /**
235
+ * Resource for generating a VitePress homepage using AI.
236
+ * Creates an index.md file with the appropriate frontmatter and content
237
+ * based on the provided prompt and configuration.
238
+ *
239
+ * @example
240
+ * // Create a basic home page with just a prompt
241
+ * const homePage = await HomePage("docs-home", {
242
+ * outDir: "./docs",
243
+ * title: "My Project Documentation",
244
+ * prompt: "Create a welcoming homepage for a JavaScript utility library with modern design"
245
+ * });
246
+ *
247
+ * @example
248
+ * // Create a home page with hero and features configuration
249
+ * const detailedHome = await HomePage("product-home", {
250
+ * outDir: "./website",
251
+ * title: "Product Landing Page",
252
+ * prompt: "Create an engaging product page for our cloud database service",
253
+ * hero: {
254
+ * name: "CloudDB",
255
+ * text: "The database built for the cloud era",
256
+ * tagline: "Scalable, reliable, and developer-friendly",
257
+ * image: "/images/cloud-db-logo.png",
258
+ * actions: [
259
+ * { text: "Get Started", link: "/guide/", theme: "brand" },
260
+ * { text: "View on GitHub", link: "https://github.com/org/cloud-db" }
261
+ * ]
262
+ * },
263
+ * features: [
264
+ * {
265
+ * icon: "🚀",
266
+ * title: "Lightning Fast",
267
+ * details: "Optimized for performance at any scale"
268
+ * },
269
+ * {
270
+ * icon: "🔒",
271
+ * title: "Secure by Default",
272
+ * details: "Enterprise-grade security built in"
273
+ * }
274
+ * ]
275
+ * });
276
+ *
277
+ * @example
278
+ * // Create a home page with custom model settings
279
+ * const customHome = await HomePage("docs-home", {
280
+ * outDir: "./docs",
281
+ * title: "API Documentation",
282
+ * prompt: "Create a technical homepage for our REST API documentation",
283
+ * model: {
284
+ * id: "gpt-4o",
285
+ * provider: "openai"
286
+ * },
287
+ * temperature: 0.3,
288
+ * systemPromptExtension: "Make sure to use technical terminology appropriate for developers."
289
+ * });
290
+ */
291
+ export async function HomePage(
292
+ id: string,
293
+ props: HomePageProps,
294
+ ): Promise<HomePage> {
295
+ // Build the system prompt with optional extension
296
+ const systemPrompt = `
297
+ You are creating a VitePress homepage (index.md file).
298
+
299
+ VitePress uses YAML frontmatter to configure the homepage.
300
+ The homepage must have "layout: home" in its frontmatter.
301
+
302
+ The homepage can include:
303
+ - A hero section with name, text, tagline, image, and action buttons
304
+ - A features section with multiple feature items (title, icon, details)
305
+ - Additional markdown content below the frontmatter
306
+
307
+ Follow these guidelines:
308
+ 1. Start with YAML frontmatter (--- at beginning and end)
309
+ 2. Include "layout: home" in the frontmatter
310
+ 3. Use the provided hero and features configuration if supplied
311
+ 4. Add any additional sections or content based on the user's prompt
312
+ 5. Create visually appealing, well-structured content
313
+ 6. Ensure all links are properly formatted
314
+ 7. Use appropriate markdown formatting for headings, lists, etc.
315
+
316
+ ${props.systemPromptExtension || ""}
317
+ `;
318
+
319
+ // Convert hero and features to YAML strings if provided
320
+ const heroYaml = props.hero ? JSON.stringify(props.hero, null, 2) : "";
321
+ const featuresYaml = props.features
322
+ ? JSON.stringify(props.features, null, 2)
323
+ : "";
324
+
325
+ // Create the document using the AI Document resource
326
+ return Document(`${id}`, {
327
+ title: props.title,
328
+ path: props.outFile,
329
+ baseURL: props.baseURL,
330
+ apiKey: props.apiKey,
331
+ model: props.model ?? {
332
+ id: "claude-3-7-sonnet-latest",
333
+ provider: "anthropic",
334
+ },
335
+ temperature: props.temperature ?? 0.7,
336
+ prompt: await alchemy`
337
+ ${systemPrompt}
338
+
339
+ Create a VitePress homepage based on the following description:
340
+ ${props.prompt}
341
+
342
+ ${
343
+ props.hero
344
+ ? `Use this hero section configuration:
345
+ \`\`\`json
346
+ ${heroYaml}
347
+ \`\`\``
348
+ : ""
349
+ }
350
+
351
+ ${
352
+ props.features
353
+ ? `Use these features:
354
+ \`\`\`json
355
+ ${featuresYaml}
356
+ \`\`\``
357
+ : ""
358
+ }
359
+
360
+ The output should be a complete index.md file with proper YAML frontmatter and markdown content.
361
+ `,
362
+ });
363
+ }
@@ -1,2 +1,3 @@
1
+ export * from "./custom-theme";
1
2
  export * from "./home-page";
2
3
  export * from "./vitepress";
@@ -3,12 +3,15 @@ import fs from "fs/promises";
3
3
  import path from "path";
4
4
  import { promisify } from "util";
5
5
  import type { DefaultTheme, ThemeOptions } from "vitepress";
6
- import yaml from "yaml";
7
- import type { Context } from "../context";
8
- import { Folder, JsonFile, TextFile, TypeScriptFile } from "../fs";
9
- import { Resource } from "../resource";
6
+ import type { Context } from "../../context";
7
+ import {
8
+ Folder,
9
+ StaticJsonFile,
10
+ StaticTextFile,
11
+ StaticTypeScriptFile,
12
+ } from "../../fs";
13
+ import { Resource } from "../../resource";
10
14
  import { InstallDependencies, fixedDependencies } from "./dependencies";
11
- import type { HomePage } from "./home-page";
12
15
 
13
16
  const execAsync = promisify(exec);
14
17
 
@@ -34,6 +37,14 @@ export interface VitePressProjectProps {
34
37
  */
35
38
  typescript?: boolean;
36
39
 
40
+ /**
41
+ * The scripts to add to the project
42
+ */
43
+ scripts?: Record<string, string>;
44
+
45
+ /**
46
+ * The tsconfig to use
47
+ */
37
48
  tsconfig?: {
38
49
  extends?: string;
39
50
  references?: string[];
@@ -66,11 +77,6 @@ export interface VitePressProjectProps {
66
77
  */
67
78
  themeConfig: DefaultTheme.Config;
68
79
 
69
- /**
70
- * The home page configuration
71
- */
72
- home: HomePage;
73
-
74
80
  /**
75
81
  * Whether to delete the project folder during the delete phase
76
82
  * @default true
@@ -78,7 +84,7 @@ export interface VitePressProjectProps {
78
84
  delete?: boolean;
79
85
 
80
86
  /**
81
- * The directory to generate the docs in
87
+ * The directory to initialize the project in.
82
88
  *
83
89
  * @default {@link name}
84
90
  */
@@ -117,21 +123,25 @@ export const VitePressProject = Resource(
117
123
  return this.destroy();
118
124
  }
119
125
 
120
- const cwd = (
121
- await Folder("dir", {
122
- path: dir,
123
- delete: props.delete,
124
- })
125
- ).path;
126
+ const cwd = path.relative(
127
+ process.cwd(),
128
+ (
129
+ await Folder("dir", {
130
+ path: dir,
131
+ delete: props.delete,
132
+ })
133
+ ).path,
134
+ );
126
135
 
127
136
  // Initialize package.json
128
- await JsonFile(path.join(cwd, "package.json"), {
137
+ await StaticJsonFile(path.join(cwd, "package.json"), {
129
138
  name: props.name,
130
139
  scripts: {
131
140
  "docs:gen": "bun alchemy.run.ts",
132
141
  "docs:dev": "vitepress dev",
133
142
  "docs:build": "vitepress build",
134
143
  "docs:preview": "vitepress preview",
144
+ ...props.scripts,
135
145
  },
136
146
  dependencies: fixedDependencies(props.dependencies || {}),
137
147
  devDependencies: fixedDependencies(props.devDependencies || {}),
@@ -153,16 +163,13 @@ export const VitePressProject = Resource(
153
163
  await Folder(path.join(cwd, ".vitepress", "theme"));
154
164
 
155
165
  await Promise.all([
156
- TextFile(path.join(cwd, ".gitignore"), `.vitepress/cache\n`),
157
- JsonFile(path.join(cwd, "tsconfig.json"), {
166
+ StaticTextFile(path.join(cwd, ".gitignore"), `.vitepress/cache\n`),
167
+ StaticJsonFile(path.join(cwd, "tsconfig.json"), {
158
168
  extends: props.tsconfig?.extends,
159
169
  references: props.tsconfig?.references?.map((path) => ({ path })),
160
170
  compilerOptions: props.tsconfig?.compilerOptions,
161
171
  }),
162
- TextFile(
163
- path.join(cwd, "index.md"),
164
- `---\n${yaml.stringify(props.home)}---\n`,
165
- ),
172
+
166
173
  // TypeScriptFile(
167
174
  // path.join(cwd, "alchemy.run.ts"),
168
175
  // `import alchemy from "alchemy";
@@ -185,7 +192,7 @@ export const VitePressProject = Resource(
185
192
  // });
186
193
  // `,
187
194
  // ),
188
- TypeScriptFile(
195
+ StaticTypeScriptFile(
189
196
  path.join(cwd, ".vitepress", "theme", "index.ts"),
190
197
  `import TwoslashFloatingVue from "@shikijs/vitepress-twoslash/client";
191
198
  import "@shikijs/vitepress-twoslash/style.css";
@@ -201,7 +208,7 @@ export default {
201
208
  } satisfies ThemeConfig;
202
209
  `,
203
210
  ),
204
- TextFile(
211
+ StaticTextFile(
205
212
  path.join(cwd, ".vitepress", "theme", "style.css"),
206
213
  `/**
207
214
  * Customize default theme styling by overriding CSS variables:
@@ -343,7 +350,7 @@ export default {
343
350
  }
344
351
  `,
345
352
  ),
346
- TypeScriptFile(
353
+ StaticTypeScriptFile(
347
354
  path.join(cwd, ".vitepress", "config.mts"),
348
355
  `import { transformerTwoslash } from "@shikijs/vitepress-twoslash";
349
356
  import footnotePlugin from "markdown-it-footnote";
@@ -1,82 +0,0 @@
1
- import type { KVNamespace } from "@cloudflare/workers-types";
2
- import type { State, StateStore } from "../state";
3
- /**
4
- * Options for CloudflareStateStore
5
- */
6
- export interface CloudflareStateStoreOptions {
7
- /**
8
- * The prefix to use for keys in the KV namespace
9
- * This allows multiple state stores to use the same KV namespace
10
- */
11
- prefix?: string;
12
- }
13
- /**
14
- * State store implementation using Cloudflare KV Namespace
15
- */
16
- export declare class CloudflareStateStore implements StateStore {
17
- private namespace;
18
- private prefix;
19
- /**
20
- * Create a new CloudflareStateStore
21
- *
22
- * @param namespace The KV namespace to use for storing state
23
- * @param options Options for the state store
24
- */
25
- constructor(namespace: KVNamespace, options?: CloudflareStateStoreOptions);
26
- /**
27
- * No initialization needed for KV namespaces as they are pre-provisioned
28
- */
29
- init(): Promise<void>;
30
- /**
31
- * KV namespaces cannot be deleted programmatically
32
- */
33
- deinit(): Promise<void>;
34
- /**
35
- * List all resources in the state store
36
- */
37
- list(): Promise<string[]>;
38
- /**
39
- * Count the number of items in the state store
40
- */
41
- count(): Promise<number>;
42
- /**
43
- * Get a state by key
44
- *
45
- * @param key The key to look up
46
- * @returns The state or undefined if not found
47
- */
48
- get(key: string): Promise<State | undefined>;
49
- /**
50
- * Get multiple states by their keys
51
- *
52
- * @param ids Array of keys to fetch
53
- * @returns Record mapping keys to their states
54
- */
55
- getBatch(ids: string[]): Promise<Record<string, State>>;
56
- /**
57
- * Get all states in the store
58
- *
59
- * @returns Record mapping all keys to their states
60
- */
61
- all(): Promise<Record<string, State>>;
62
- /**
63
- * Set a state for a key
64
- *
65
- * @param key The key to set
66
- * @param value The state to store
67
- */
68
- set(key: string, value: State): Promise<void>;
69
- /**
70
- * Delete a state by key
71
- *
72
- * @param key The key to delete
73
- */
74
- delete(key: string): Promise<void>;
75
- /**
76
- * Get the namespaced key for storage
77
- *
78
- * @param key The original key
79
- * @returns The key with prefix for use in the KV namespace
80
- */
81
- private getNamespacedKey;
82
- }
@@ -1,108 +0,0 @@
1
- /**
2
- * State store implementation using Cloudflare KV Namespace
3
- */
4
- export class CloudflareStateStore {
5
- namespace;
6
- prefix;
7
- /**
8
- * Create a new CloudflareStateStore
9
- *
10
- * @param namespace The KV namespace to use for storing state
11
- * @param options Options for the state store
12
- */
13
- constructor(namespace, options = {}) {
14
- this.namespace = namespace;
15
- this.prefix = options.prefix || "alchemy-state:";
16
- }
17
- /**
18
- * No initialization needed for KV namespaces as they are pre-provisioned
19
- */
20
- async init() {
21
- // KV namespaces are pre-provisioned in Cloudflare, so no initialization is needed
22
- }
23
- /**
24
- * KV namespaces cannot be deleted programmatically
25
- */
26
- async deinit() {
27
- // KV namespaces can only be deleted through the Cloudflare dashboard or API
28
- // We cannot delete the namespace itself here
29
- }
30
- /**
31
- * List all resources in the state store
32
- */
33
- async list() {
34
- const list = await this.namespace.list({ prefix: this.prefix });
35
- return list.keys.map((key) => key.name.slice(this.prefix.length));
36
- }
37
- /**
38
- * Count the number of items in the state store
39
- */
40
- async count() {
41
- const list = await this.namespace.list({ prefix: this.prefix });
42
- return list.keys.length;
43
- }
44
- /**
45
- * Get a state by key
46
- *
47
- * @param key The key to look up
48
- * @returns The state or undefined if not found
49
- */
50
- async get(key) {
51
- const data = await this.namespace.get(this.getNamespacedKey(key), "json");
52
- return data;
53
- }
54
- /**
55
- * Get multiple states by their keys
56
- *
57
- * @param ids Array of keys to fetch
58
- * @returns Record mapping keys to their states
59
- */
60
- async getBatch(ids) {
61
- const result = {};
62
- // KV doesn't have a native batch get operation, so we need to make multiple requests
63
- // We could optimize this with Promise.all for parallel fetching
64
- const promises = ids.map(async (id) => {
65
- const state = await this.get(id);
66
- if (state) {
67
- result[id] = state;
68
- }
69
- });
70
- await Promise.all(promises);
71
- return result;
72
- }
73
- /**
74
- * Get all states in the store
75
- *
76
- * @returns Record mapping all keys to their states
77
- */
78
- async all() {
79
- const keys = await this.list();
80
- return this.getBatch(keys);
81
- }
82
- /**
83
- * Set a state for a key
84
- *
85
- * @param key The key to set
86
- * @param value The state to store
87
- */
88
- async set(key, value) {
89
- await this.namespace.put(this.getNamespacedKey(key), JSON.stringify(value));
90
- }
91
- /**
92
- * Delete a state by key
93
- *
94
- * @param key The key to delete
95
- */
96
- async delete(key) {
97
- await this.namespace.delete(this.getNamespacedKey(key));
98
- }
99
- /**
100
- * Get the namespaced key for storage
101
- *
102
- * @param key The original key
103
- * @returns The key with prefix for use in the KV namespace
104
- */
105
- getNamespacedKey(key) {
106
- return `${this.prefix}${key}`;
107
- }
108
- }
@@ -1,7 +0,0 @@
1
- import { File } from "./file";
2
- export function JsonFile(id, content) {
3
- return File(id, {
4
- path: id,
5
- content: JSON.stringify(content, null, 2),
6
- });
7
- }
@@ -1,5 +0,0 @@
1
- export interface DocsProps {
2
- docs?: boolean | number;
3
- }
4
- export type AlchemyDocs = Awaited<ReturnType<typeof AlchemyDocs>>;
5
- export declare function AlchemyDocs({ docs: isDocsEnabled }: DocsProps): Promise<void>;