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
@@ -1,338 +0,0 @@
1
- import { type } from "arktype";
2
- import fs from "fs/promises";
3
- import path from "path";
4
- import { Data } from "../ai/data";
5
- import { Document } from "../ai/document";
6
- import { alchemy } from "../alchemy";
7
- import { Folder } from "../fs/folder";
8
- import { VitePressProject } from "../vitepress/vitepress";
9
-
10
- export interface DocsProps {
11
- docs?: boolean | number;
12
- }
13
-
14
- export type AlchemyDocs = Awaited<ReturnType<typeof AlchemyDocs>>;
15
-
16
- export async function AlchemyDocs({ docs: isDocsEnabled }: DocsProps) {
17
- const root = (await Folder("alchemy-web")).path;
18
-
19
- const docs = (await Folder(path.join(root, "docs"))).path;
20
-
21
- const providersDir = (await Folder(path.join(docs, "providers"))).path;
22
-
23
- const exclude = ["util", "test", "vitepress", "vite", "shadcn", "internal"];
24
-
25
- // Get all folders in the alchemy/src directory
26
- let providers = (
27
- await fs.readdir(path.resolve("alchemy", "src"), {
28
- withFileTypes: true,
29
- })
30
- )
31
- .filter((dirent) => dirent.isDirectory() && !exclude.includes(dirent.name))
32
- .map((dirent) => path.join(dirent.parentPath, dirent.name));
33
-
34
- // For each provider, list all files
35
- if (isDocsEnabled === false) {
36
- return;
37
- } else if (typeof isDocsEnabled === "number") {
38
- providers = providers.slice(0, isDocsEnabled);
39
- }
40
-
41
- const providerDocs = await Promise.all(
42
- providers.map(async (provider) => {
43
- const providerName = path.basename(provider);
44
- const files = (
45
- await fs.readdir(path.resolve(provider), {
46
- withFileTypes: true,
47
- })
48
- )
49
- .filter((dirent) => dirent.isFile())
50
- .map((dirent) =>
51
- path.relative(process.cwd(), path.resolve(provider, dirent.name)),
52
- )
53
- .filter((file) => file.endsWith(".ts") && !file.endsWith("index.ts"));
54
-
55
- const {
56
- object: { groups },
57
- } = await Data(`docs/${providerName}`, {
58
- schema: type({
59
- groups: type({
60
- title: type("string").describe(
61
- "The title of the group, should be the Resource Name exactly without spaces, e.g. Bucket or Static Site.",
62
- ),
63
- filename: type("string").describe(
64
- "The filename of the Resource's Document, e.g. bucket.md or static-site.md",
65
- ),
66
- category: type("'Resource'|'Client'|'Utility'|'Types'").describe(
67
- "The classification of the Resource's Document, one of: Resource, Client, Utility, or Types.",
68
- ),
69
- }).array(),
70
- }),
71
- system: await alchemy`
72
- You are a technical writer tasked with identifying the distinct documents that need to be written for a document group (folder) in a documentation site.
73
- You will be provided with a list of documents and instructions on how to classify them.
74
- Each document has a title, file name, and category.
75
- `,
76
- prompt: await alchemy`
77
- Identify and classify the documents that need to be written for the '${provider}' Service's Alchemy Resources.
78
- For background knowledge on Alchemy, see ${alchemy.file("./README.md")}.
79
- For background knowledge on the structure of an Alchemy Resource, see ${alchemy.file("./.cursorrules")}.
80
-
81
- The ${provider} Service has the following resources:
82
- ${alchemy.files(files)}
83
-
84
- A file is considered a "Resource" if it contains a const <ResourceName> = Resource(...) call or if it is a function that calls a Resource function, e.g. const TypeScriptFile = () => File(...).
85
- A file is considered a "Client" if it exposes a wrapper around creating a SDK client or fetch.
86
- A file is considered a "Utility" if it contains utility functions that are not resources or clients.
87
- A file is considered a "Types" if it contains just type definitions and maybe helpers around working with those types.
88
-
89
- The title should be simply the name of the resource, e.g. "Bucket" or "Function", except with spaces, e.g. "Static Site" instead of "StaticSite". Maintain all other casing.
90
- `,
91
- });
92
-
93
- const providerDocsDir = (
94
- await Folder(path.join(providersDir, providerName))
95
- ).path;
96
-
97
- const documents = await Promise.all(
98
- groups
99
- .filter((g) => g.category === "Resource")
100
- .map(async (g) =>
101
- Document(`docs/${providerName}/${g.title}`, {
102
- title: g.title,
103
- path: path.join(
104
- providerDocsDir,
105
- `${g.filename.replace(".ts", "").replace(".md", "")}.md`,
106
- ),
107
- prompt: await alchemy`
108
- You are a technical writer writing API documentation for an Alchemy IaC Resource.
109
- See ${alchemy.file("./README.md")} to understand the overview of Alchemy.
110
- See ${alchemy.file("./.cursorrules")} to better understand the structure and convention of an Alchemy Resource.
111
-
112
- Relevant files for the ${providerName} Service:
113
- ${alchemy.files(files)}
114
-
115
- Write concise documentation for the "${g.title}" Resource.
116
-
117
- > [!CAUTION]
118
- > Avoid the temptation to over explain or over describe. Focus on concise, simple, high value snippets. One heading and 0-1 descriptions per snippet.
119
-
120
- > [!TIP]
121
- > Make sure the examples follow a natural progression from the minimal example to logical next steps of how the Resource might be used.
122
-
123
- Each document must follow the following format:
124
-
125
- # ${g.title}
126
-
127
- (simple description with an external link to the provider's website)
128
- e.g.
129
- The Efs component lets you add [Amazon Elastic File System (EFS)](https://docs.aws.amazon.com/efs/latest/ug/whatisefs.html) to your app.
130
-
131
- # Minimal Example
132
-
133
- \`\`\`ts
134
- import { ${g.title.replaceAll(" ", "")} } from "alchemy/${providerName}";
135
-
136
- (example)
137
- \`\`\`
138
-
139
-
140
- # Create the ${g.title}
141
-
142
- \`\`\`ts
143
- import { ${g.title.replaceAll(" ", "")} } from "alchemy/${providerName}";
144
-
145
- (example)
146
- \`\`\`
147
-
148
- ${
149
- providerName === "cloudflare"
150
- ? await alchemy`# Bind to a Worker
151
- (if it is a Cloudflare Resource)
152
-
153
- \`\`\`ts
154
- import { Worker, ${g.title.replaceAll(" ", "")} } from "alchemy/${providerName}";
155
-
156
- const myResource = await ${g.title.replaceAll(" ", "")}("my-resource", {
157
- // ...
158
- });
159
-
160
- await Worker("my-worker", {
161
- name: "my-worker",
162
- script: "console.log('Hello, world!')",
163
- bindings: {
164
- myResource,
165
- },
166
- });
167
- \`\`\``
168
- : ""
169
- }
170
- `,
171
- }),
172
- ),
173
- );
174
-
175
- return {
176
- dir: providerDocsDir,
177
- provider: providerName,
178
- documents,
179
- } as const;
180
- }),
181
- );
182
-
183
- await VitePressProject("docs", {
184
- name: "alchemy-web",
185
- title: "Alchemy",
186
- description: "Alchemy is an TypeScript-native, embeddable IaC library",
187
- overwrite: true,
188
- delete: false,
189
- tsconfig: {
190
- extends: "../tsconfig.base.json",
191
- references: ["../alchemy/tsconfig.json"],
192
- },
193
- devDependencies: {
194
- alchemy: "workspace:*",
195
- },
196
- theme: {
197
- light: "light-plus",
198
- dark: "dark-plus",
199
- },
200
- home: {
201
- layout: "home",
202
- hero: {
203
- name: "Alchemy",
204
- text: "Materialize all the things! 🪄",
205
- tagline: "TypeScript-native Infrastructure-as-Code (IaC)",
206
- image: {
207
- src: "./public/alchemist.png",
208
- alt: "The Alchemist",
209
- },
210
- actions: [
211
- {
212
- text: "Get Started",
213
- link: "/docs",
214
- theme: "brand",
215
- },
216
- ],
217
- },
218
- features: [
219
- {
220
- title: "JS-native",
221
- details:
222
- "No second language, toolchains, dependencies, processes, services, etc. to lug around.",
223
- },
224
- {
225
- title: "Async",
226
- details:
227
- "Resources are just async functions - no complex abstraction to learn.",
228
- },
229
- {
230
- title: "ESM",
231
- details:
232
- "Built exclusively on ESM, with a slight preference for modern JS runtimes like Bun.",
233
- },
234
- {
235
- title: "Embeddable",
236
- details:
237
- "Runs in any JavaScript/TypeScript environment, including the browser!",
238
- },
239
- {
240
- title: "Extensible",
241
- details: "Implement your own resources with a simple function.",
242
- },
243
- {
244
- title: "AI-first",
245
- details:
246
- "Create, copy, fork, and modify resources using LLMs to fit your needs.",
247
- },
248
- {
249
- title: "No dependencies",
250
- details: "The alchemy core package has 0 required dependencies.",
251
- },
252
- {
253
- title: "No service",
254
- details:
255
- "State files are stored locally in your project for easy inspection and version control.",
256
- },
257
- {
258
- title: "No strong opinions",
259
- details:
260
- "Structure your codebase however you want, store state anywhere - we don't care!",
261
- },
262
- ],
263
- },
264
- themeConfig: {
265
- sidebar: {
266
- "/blog/": [{ text: "Blog", items: [{ text: "Blog", link: "/blog/" }] }],
267
- "/docs/": [
268
- {
269
- text: "Getting Started",
270
- items: [{ text: "Install", link: "/docs/getting-started/install" }],
271
- },
272
- {
273
- text: "Guides",
274
- items: [
275
- {
276
- text: "Custom Resource",
277
- link: "/docs/guides/custom-resource",
278
- },
279
- {
280
- text: "Automating with LLMs",
281
- link: "/docs/guides/llms",
282
- },
283
- ],
284
- },
285
- {
286
- text: "Core",
287
- collapsed: true,
288
- items: [
289
- { text: "App", link: "/docs/core/app" },
290
- { text: "Resource", link: "/docs/core/resource" },
291
- { text: "Scope", link: "/docs/core/scope" },
292
- { text: "Phase", link: "/docs/core/phase" },
293
- { text: "Finalize", link: "/docs/core/finalize" },
294
- { text: "State", link: "/docs/core/state" },
295
- { text: "Secret", link: "/docs/core/secret" },
296
- { text: "Context", link: "/docs/core/context" },
297
- ],
298
- },
299
- {
300
- text: "Providers",
301
- items: providerDocs
302
- .map((provider) => ({
303
- text: provider.provider,
304
- link: `/docs/providers/${provider.provider}`,
305
- collapsed: true,
306
- items: provider.documents.map((document) => ({
307
- text: document.title,
308
- link: `/docs/providers/${provider.provider}/${path.basename(document.path, ".md")}`,
309
- })),
310
- }))
311
- .sort((a, b) => a.text.localeCompare(b.text)),
312
- },
313
- ],
314
- "/examples/": [
315
- {
316
- text: "Examples",
317
- items: [{ text: "Foo", link: "/examples/foo" }],
318
- },
319
- ],
320
- "/": [
321
- {
322
- text: "Home",
323
- items: [
324
- { text: "Markdown Examples", link: "/markdown-examples" },
325
- { text: "Runtime API Examples", link: "/api-examples" },
326
- ],
327
- },
328
- ],
329
- },
330
- socialLinks: [
331
- {
332
- icon: "github",
333
- link: "https://github.com/sam-goodwin/alchemy",
334
- },
335
- ],
336
- },
337
- });
338
- }
@@ -1 +0,0 @@
1
- export * from "./component";
package/src/vite/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./vite";
@@ -1,166 +0,0 @@
1
- import yaml from "yaml";
2
-
3
- /**
4
- * Image that can be themed for light/dark mode
5
- */
6
- export interface ThemeableImage {
7
- /**
8
- * Image source URL
9
- */
10
- src?: string;
11
-
12
- /**
13
- * Image alt text
14
- */
15
- alt?: string;
16
-
17
- /**
18
- * Light theme image URL
19
- */
20
- light?: string;
21
-
22
- /**
23
- * Dark theme image URL
24
- */
25
- dark?: string;
26
- }
27
-
28
- /**
29
- * Hero action button configuration
30
- */
31
- export interface HeroAction {
32
- /**
33
- * Color theme of the button
34
- * @default "brand"
35
- */
36
- theme?: "brand" | "alt";
37
-
38
- /**
39
- * Label of the button
40
- */
41
- text: string;
42
-
43
- /**
44
- * Destination link of the button
45
- */
46
- link: string;
47
-
48
- /**
49
- * Link target attribute
50
- */
51
- target?: string;
52
-
53
- /**
54
- * Link rel attribute
55
- */
56
- rel?: string;
57
- }
58
-
59
- /**
60
- * Hero section configuration
61
- */
62
- export interface Hero {
63
- /**
64
- * The string shown top of text. Comes with brand color
65
- * and expected to be short, such as product name.
66
- */
67
- name?: string;
68
-
69
- /**
70
- * The main text for the hero section. This will be defined
71
- * as h1 tag.
72
- */
73
- text: string;
74
-
75
- /**
76
- * Tagline displayed below text
77
- */
78
- tagline?: string;
79
-
80
- /**
81
- * The image displayed next to the text and tagline area
82
- */
83
- image?: string | ThemeableImage;
84
-
85
- /**
86
- * Action buttons to display in home hero section
87
- */
88
- actions?: HeroAction[];
89
- }
90
-
91
- /**
92
- * Feature item configuration
93
- */
94
- export interface Feature {
95
- /**
96
- * Show icon on each feature box
97
- */
98
- icon?: string | ThemeableImage;
99
-
100
- /**
101
- * Title of the feature
102
- */
103
- title: string;
104
-
105
- /**
106
- * Details of the feature
107
- */
108
- details: string;
109
-
110
- /**
111
- * Link when clicked on feature component
112
- */
113
- link?: string;
114
-
115
- /**
116
- * Link text to be shown inside feature component
117
- */
118
- linkText?: string;
119
-
120
- /**
121
- * Link rel attribute
122
- */
123
- rel?: string;
124
-
125
- /**
126
- * Link target attribute
127
- */
128
- target?: string;
129
- }
130
-
131
- /**
132
- * VitePress home page configuration
133
- */
134
- export interface HomePage {
135
- /**
136
- * Use home page layout
137
- */
138
- layout: "home";
139
-
140
- /**
141
- * Hero section configuration
142
- */
143
- hero?: Hero;
144
-
145
- /**
146
- * Features section configuration
147
- */
148
- features?: Feature[];
149
-
150
- /**
151
- * Whether to apply default markdown styles
152
- * @default true
153
- */
154
- markdownStyles?: boolean;
155
- }
156
-
157
- /**
158
- * Parse YAML frontmatter to home page config
159
- */
160
- export function parseHomePage(content: string): HomePage {
161
- const match = content.match(/^---\n([\s\S]*?)\n---/);
162
- if (!match) {
163
- throw new Error("Invalid frontmatter format");
164
- }
165
- return yaml.parse(match[1]) as HomePage;
166
- }
File without changes