alchemy 0.2.2 → 0.2.4

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 (161) hide show
  1. package/lib/ai/ark.d.ts +11 -0
  2. package/lib/ai/ark.js +86 -0
  3. package/lib/ai/client.d.ts +51 -0
  4. package/lib/ai/client.js +29 -0
  5. package/lib/ai/document.d.ts +97 -0
  6. package/lib/ai/document.js +82 -0
  7. package/lib/ai/index.d.ts +2 -0
  8. package/lib/ai/index.js +2 -0
  9. package/lib/ai/object.d.ts +101 -0
  10. package/lib/ai/object.js +70 -0
  11. package/lib/alchemy.d.ts +84 -2
  12. package/lib/alchemy.js +114 -10
  13. package/lib/apply.d.ts +1 -1
  14. package/lib/apply.js +13 -10
  15. package/lib/aws/bucket.d.ts +87 -1
  16. package/lib/aws/bucket.js +48 -1
  17. package/lib/aws/function.d.ts +186 -1
  18. package/lib/aws/function.js +62 -8
  19. package/lib/aws/oidc/github-oidc-provider.d.ts +81 -0
  20. package/lib/aws/oidc/github-oidc-provider.js +68 -0
  21. package/lib/aws/oidc/oidc-provider.d.ts +14 -6
  22. package/lib/aws/oidc/oidc-provider.js +26 -5
  23. package/lib/aws/policy-attachment.d.ts +44 -1
  24. package/lib/aws/policy-attachment.js +31 -0
  25. package/lib/aws/policy.d.ts +160 -1
  26. package/lib/aws/policy.js +78 -0
  27. package/lib/aws/queue.d.ts +83 -1
  28. package/lib/aws/queue.js +39 -0
  29. package/lib/aws/role.d.ts +162 -1
  30. package/lib/aws/role.js +114 -0
  31. package/lib/aws/ses.d.ts +57 -2
  32. package/lib/aws/ses.js +42 -1
  33. package/lib/aws/table.d.ts +96 -1
  34. package/lib/aws/table.js +36 -0
  35. package/lib/cloudflare/asset-manifest.js +0 -1
  36. package/lib/cloudflare/bound.js +0 -1
  37. package/lib/cloudflare/bucket.d.ts +37 -1
  38. package/lib/cloudflare/bucket.js +36 -0
  39. package/lib/cloudflare/durable-object-namespace.d.ts +25 -0
  40. package/lib/cloudflare/durable-object-namespace.js +22 -0
  41. package/lib/cloudflare/kv-namespace.d.ts +37 -1
  42. package/lib/cloudflare/kv-namespace.js +36 -0
  43. package/lib/cloudflare/static-site.d.ts +53 -1
  44. package/lib/cloudflare/static-site.js +53 -1
  45. package/lib/cloudflare/worker-metadata.js +0 -1
  46. package/lib/cloudflare/worker.d.ts +64 -1
  47. package/lib/cloudflare/worker.js +63 -0
  48. package/lib/cloudflare/wrangler.json.d.ts +1 -1
  49. package/lib/cloudflare/zone-settings.js +0 -1
  50. package/lib/cloudflare/zone.d.ts +56 -1
  51. package/lib/cloudflare/zone.js +55 -0
  52. package/lib/context.d.ts +9 -4
  53. package/lib/context.js +4 -2
  54. package/lib/destroy.js +9 -8
  55. package/lib/esbuild/bundle.d.ts +43 -4
  56. package/lib/esbuild/bundle.js +16 -0
  57. package/lib/fs/file-collection.d.ts +16 -0
  58. package/lib/fs/file-collection.js +6 -0
  59. package/lib/fs/file-ref.d.ts +14 -0
  60. package/lib/fs/file-ref.js +6 -0
  61. package/lib/fs/file.d.ts +78 -5
  62. package/lib/fs/file.js +39 -3
  63. package/lib/fs/folder.d.ts +37 -5
  64. package/lib/fs/folder.js +28 -3
  65. package/lib/fs/index.d.ts +6 -0
  66. package/lib/fs/index.js +6 -0
  67. package/lib/fs/json-file.d.ts +16 -0
  68. package/lib/fs/json-file.js +7 -0
  69. package/lib/fs/text-file.d.ts +12 -0
  70. package/lib/fs/text-file.js +7 -0
  71. package/lib/fs/typescript-file.d.ts +19 -0
  72. package/lib/fs/typescript-file.js +14 -0
  73. package/lib/fs/yaml-file.d.ts +19 -0
  74. package/lib/fs/yaml-file.js +8 -0
  75. package/lib/github/secret.d.ts +63 -2
  76. package/lib/github/secret.js +61 -1
  77. package/lib/internal/docs.d.ts +5 -0
  78. package/lib/internal/docs.js +324 -0
  79. package/lib/resource.d.ts +2 -2
  80. package/lib/resource.js +4 -0
  81. package/lib/scope.d.ts +1 -1
  82. package/lib/scope.js +6 -6
  83. package/lib/secret.d.ts +67 -0
  84. package/lib/secret.js +67 -0
  85. package/lib/shadcn/component.d.ts +1 -1
  86. package/lib/state.d.ts +1 -1
  87. package/lib/state.js +8 -1
  88. package/lib/stripe/price.d.ts +51 -1
  89. package/lib/stripe/price.js +50 -0
  90. package/lib/stripe/product.d.ts +39 -1
  91. package/lib/stripe/product.js +38 -0
  92. package/lib/stripe/webhook.d.ts +46 -1
  93. package/lib/stripe/webhook.js +45 -0
  94. package/lib/test/bun.d.ts +64 -0
  95. package/lib/test/bun.js +35 -3
  96. package/lib/util/serde.d.ts +3 -1
  97. package/lib/util/serde.js +20 -4
  98. package/lib/vite/vite.d.ts +1 -1
  99. package/lib/vitepress/dependencies.d.ts +12 -0
  100. package/lib/vitepress/dependencies.js +35 -0
  101. package/lib/vitepress/home-page.d.ts +133 -0
  102. package/lib/vitepress/home-page.js +11 -0
  103. package/lib/vitepress/index.d.ts +2 -0
  104. package/lib/vitepress/index.js +2 -0
  105. package/lib/vitepress/vitepress.d.ts +71 -0
  106. package/lib/vitepress/vitepress.js +266 -0
  107. package/package.json +22 -10
  108. package/src/ai/ark.ts +118 -0
  109. package/src/ai/client.ts +78 -0
  110. package/src/ai/document.ts +160 -0
  111. package/src/ai/index.ts +2 -0
  112. package/src/ai/object.ts +149 -0
  113. package/src/alchemy.ts +192 -17
  114. package/src/apply.ts +25 -13
  115. package/src/aws/bucket.ts +111 -7
  116. package/src/aws/function.ts +231 -10
  117. package/src/aws/oidc/github-oidc-provider.ts +83 -0
  118. package/src/aws/oidc/oidc-provider.ts +39 -7
  119. package/src/aws/policy-attachment.ts +44 -1
  120. package/src/aws/policy.ts +177 -2
  121. package/src/aws/queue.ts +89 -0
  122. package/src/aws/role.ts +174 -2
  123. package/src/aws/ses.ts +56 -1
  124. package/src/aws/table.ts +103 -0
  125. package/src/cloudflare/bucket.ts +36 -0
  126. package/src/cloudflare/durable-object-namespace.ts +25 -0
  127. package/src/cloudflare/kv-namespace.ts +36 -0
  128. package/src/cloudflare/static-site.ts +53 -1
  129. package/src/cloudflare/worker.ts +63 -0
  130. package/src/cloudflare/zone.ts +55 -0
  131. package/src/context.ts +30 -10
  132. package/src/destroy.ts +11 -8
  133. package/src/esbuild/bundle.ts +53 -3
  134. package/src/fs/file-collection.ts +24 -0
  135. package/src/fs/file-ref.ts +22 -0
  136. package/src/fs/file.ts +107 -6
  137. package/src/fs/folder.ts +45 -5
  138. package/src/fs/index.ts +6 -0
  139. package/src/fs/json-file.ts +23 -0
  140. package/src/fs/text-file.ts +19 -0
  141. package/src/fs/typescript-file.ts +36 -0
  142. package/src/fs/yaml-file.ts +26 -0
  143. package/src/github/secret.ts +65 -2
  144. package/src/internal/docs.ts +369 -0
  145. package/src/resource.ts +7 -2
  146. package/src/scope.ts +9 -9
  147. package/src/secret.ts +67 -0
  148. package/src/state.ts +9 -2
  149. package/src/stripe/price.ts +50 -0
  150. package/src/stripe/product.ts +38 -0
  151. package/src/stripe/webhook.ts +45 -0
  152. package/src/test/bun.ts +83 -3
  153. package/src/util/serde.ts +30 -4
  154. package/src/vitepress/dependencies.ts +68 -0
  155. package/src/vitepress/home-page.ts +166 -0
  156. package/src/vitepress/index.md +75 -0
  157. package/src/vitepress/index.ts +2 -0
  158. package/src/vitepress/vitepress.ts +382 -0
  159. package/lib/project/vite.d.ts +0 -90
  160. package/lib/project/vite.js +0 -228
  161. package/src/project/vite.ts +0 -406
@@ -1,406 +0,0 @@
1
- import { exec } from "child_process";
2
- import fs from "fs/promises";
3
- import path from "path";
4
- import { promisify } from "util";
5
- import type { Context } from "../context";
6
- import { Resource } from "../resource";
7
- import { ShadcnComponent } from "../shadcn/component";
8
- import { rm } from "../util/rm";
9
-
10
- const execAsync = promisify(exec);
11
-
12
- type ViteTemplate =
13
- | "vanilla"
14
- | "vanilla-ts"
15
- | "vue"
16
- | "vue-ts"
17
- | "react"
18
- | "react-ts"
19
- | "react-swc"
20
- | "react-swc-ts"
21
- | "preact"
22
- | "preact-ts"
23
- | "lit"
24
- | "lit-ts"
25
- | "svelte"
26
- | "svelte-ts"
27
- | "solid"
28
- | "solid-ts"
29
- | "qwik"
30
- | "qwik-ts";
31
-
32
- export interface ViteProjectProps {
33
- /**
34
- * The name/path of the project
35
- */
36
- name: string;
37
- /**
38
- * The Vite template to use
39
- */
40
- template: ViteTemplate;
41
- /**
42
- * The extends to add to the tsconfig.json file
43
- */
44
- extends?: string;
45
- /**
46
- * The references to add to the tsconfig.json file
47
- */
48
- references?: string[];
49
- /**
50
- * Add Tailwind CSS to the project
51
- * @default false
52
- */
53
- tailwind?: boolean;
54
- /**
55
- * Add Tanstack Router to the project
56
- * @default false
57
- */
58
- tanstack?: boolean;
59
- /**
60
- * Add Shadcn UI to the project
61
- * @default false
62
- */
63
- shadcn?: {
64
- /**
65
- * The base color to use
66
- * @default "neutral"
67
- */
68
- baseColor?: "neutral" | "gray" | "zinc" | "stone" | "slate";
69
- /**
70
- * Use default configuration
71
- * @default false
72
- */
73
- defaults?: boolean;
74
-
75
- /**
76
- * Force overwrite of existing configuration
77
- * @default false
78
- */
79
- force?: boolean;
80
-
81
- /**
82
- * The working directory
83
- * @default current directory
84
- */
85
- cwd?: string;
86
-
87
- /**
88
- * Mute output
89
- * @default false
90
- */
91
- silent?: boolean;
92
-
93
- /**
94
- * Use the src directory when creating a new project
95
- * @default false
96
- */
97
- srcDir?: boolean;
98
-
99
- /**
100
- * Use css variables for theming
101
- * @default true
102
- */
103
- cssVariables?: boolean;
104
-
105
- /**
106
- * The components to add
107
- */
108
- components?: string[];
109
- };
110
- /**
111
- * Force overwrite the project config files during the update phase
112
- *
113
- * @default false
114
- */
115
- overwrite?: boolean;
116
- }
117
-
118
- export interface ViteProject extends ViteProjectProps, Resource {
119
- /**
120
- * The name/path of the project
121
- */
122
- name: string;
123
- }
124
-
125
- export const ViteProject = Resource(
126
- "project::ViteProject",
127
- {
128
- alwaysUpdate: true,
129
- },
130
- async function (
131
- this: Context<ViteProject>,
132
- id: string,
133
- props: ViteProjectProps,
134
- ): Promise<ViteProject> {
135
- const phase = this.phase;
136
- if (this.phase === "delete") {
137
- try {
138
- if (await fs.exists(props.name)) {
139
- // TODO: OS agnostic - fs.rm is slow to delete node_modules/
140
- await execAsync("rm -rf " + props.name);
141
- }
142
- } catch (error) {
143
- console.error(`Error deleting project ${id}:`, error);
144
- }
145
- return this.destroy();
146
- }
147
-
148
- if (this.phase === "update") {
149
- if (props.overwrite) {
150
- await modifyConfig(props);
151
- } else {
152
- console.warn(
153
- "ViteProject does not support updates - the project must be recreated to change the template",
154
- );
155
- }
156
- } else {
157
- await execAsync(`bun create vite ${id} --template ${props.template}`);
158
-
159
- await modifyConfig(props);
160
- }
161
-
162
- return this(props);
163
-
164
- async function modifyConfig(props: ViteProjectProps) {
165
- const tailwind = props.tailwind ?? false;
166
- const tanstack = props.tanstack ?? false;
167
-
168
- const plugins = [
169
- tailwind && "tailwindcss()",
170
- tanstack &&
171
- "TanStackRouterVite({ target: 'react', autoCodeSplitting: true })",
172
- "react()",
173
- ].filter((s) => typeof s === "string");
174
-
175
- const cwd = path.resolve(process.cwd(), props.name);
176
-
177
- const exec = (command: string) => execAsync(command, { cwd });
178
-
179
- if (phase === "create" || props.overwrite) {
180
- await removeUnnecessaryFiles();
181
- }
182
-
183
- await patchTsConfig();
184
-
185
- if (props.tailwind) {
186
- await installTailwind();
187
- }
188
-
189
- if (props.tanstack) {
190
- await installTanstack();
191
- }
192
-
193
- if (props.shadcn !== undefined) {
194
- await installShadcn();
195
- }
196
-
197
- await build();
198
-
199
- async function build() {
200
- // tsc -b will fail if we have not invoked tan stacks' code gen
201
- await execAsync(`bun vite build`, { cwd: props.name });
202
- }
203
-
204
- async function installTailwind() {
205
- await exec(`bun add tailwindcss @tailwindcss/vite`);
206
-
207
- await fs.writeFile(
208
- path.join(props.name, "vite.config.ts"),
209
- `import path from "path";
210
- import react from "@vitejs/plugin-react";
211
- import { defineConfig } from "vite";
212
- ${tailwind ? "import tailwindcss from '@tailwindcss/vite';" : ""}
213
- ${tanstack ? 'import { TanStackRouterVite } from "@tanstack/router-plugin/vite";' : ""}
214
-
215
- // https://vite.dev/config/
216
- export default defineConfig({
217
- plugins: [${plugins.join(", ")}],
218
- resolve: {
219
- alias: {
220
- "@": path.resolve(__dirname, "./src"),
221
- },
222
- },
223
- });`,
224
- );
225
-
226
- // Add Tailwind CSS import to index.css
227
- const indexCssPath = path.join(props.name, "src", "index.css");
228
- const currentCss = await fs.readFile(indexCssPath, "utf-8");
229
- if (!currentCss.includes('@import "tailwindcss";')) {
230
- await fs.writeFile(
231
- indexCssPath,
232
- '@import "tailwindcss";\n\n' + currentCss,
233
- );
234
- }
235
- }
236
-
237
- async function installShadcn() {
238
- await exec("bun add -D @types/node");
239
-
240
- // Build the shadcn init command with all options
241
- const shadcnOptions = props.shadcn;
242
- const initCommand = [
243
- "bunx --bun shadcn@latest init",
244
- shadcnOptions?.baseColor && `-b ${shadcnOptions.baseColor}`,
245
- shadcnOptions?.defaults && "-d",
246
- shadcnOptions?.force && "-f",
247
- shadcnOptions?.cwd && `-c ${shadcnOptions.cwd}`,
248
- shadcnOptions?.silent && "-s",
249
- shadcnOptions?.srcDir && "--src-dir",
250
- shadcnOptions?.cssVariables === false && "--no-css-variables",
251
- ]
252
- .filter(Boolean)
253
- .join(" ");
254
-
255
- await exec(initCommand);
256
-
257
- // Install requested components using the ShadcnComponent resource
258
- for (const componentName of props.shadcn?.components ?? []) {
259
- await ShadcnComponent(`shadcn-component-${componentName}`, {
260
- name: componentName,
261
- cwd: props.name,
262
- force: props.shadcn?.force,
263
- silent: props.shadcn?.silent,
264
- });
265
- }
266
- }
267
-
268
- async function installTanstack() {
269
- await exec(`bun add @tanstack/react-router`);
270
- await exec(
271
- `bun add -D @tanstack/router-plugin @tanstack/react-router-devtools`,
272
- );
273
-
274
- const src = path.join(props.name, "src");
275
- const routes = path.join(src, "routes");
276
- await fs.mkdir(routes, { recursive: true });
277
- await fs.writeFile(
278
- path.join(routes, "__root.tsx"),
279
- `import { Link, Outlet, createRootRoute } from "@tanstack/react-router";
280
- import { TanStackRouterDevtools } from "@tanstack/react-router-devtools";
281
-
282
- export const Route = createRootRoute({
283
- component: () => (
284
- <div className="w-full min-h-screen flex flex-col">
285
- <div className="p-2 flex gap-2">
286
- <Link to="/" className="[&.active]:font-bold">
287
- Home
288
- </Link>{" "}
289
- <Link to="/about" className="[&.active]:font-bold">
290
- About
291
- </Link>
292
- </div>
293
- <hr />
294
- <Outlet />
295
- <TanStackRouterDevtools />
296
- </div>
297
- ),
298
- });
299
- `,
300
- );
301
-
302
- await fs.writeFile(
303
- path.join(routes, "index.tsx"),
304
- `import { createLazyFileRoute } from '@tanstack/react-router'
305
-
306
- export const Route = createLazyFileRoute('/')({
307
- component: Index,
308
- })
309
-
310
- function Index() {
311
- return (
312
- <div className="p-2">
313
- <h3>Welcome Home!</h3>
314
- </div>
315
- )
316
- }`,
317
- );
318
-
319
- await fs.writeFile(
320
- path.join(routes, "about.tsx"),
321
- `import { createLazyFileRoute } from '@tanstack/react-router'
322
-
323
- export const Route = createLazyFileRoute('/about')({
324
- component: About,
325
- })
326
-
327
- function About() {
328
- return <div className="p-2">Hello from About!</div>
329
- }`,
330
- );
331
-
332
- await fs.writeFile(
333
- path.join(src, "main.tsx"),
334
- `import { StrictMode } from 'react'
335
- import ReactDOM from 'react-dom/client'
336
- import { RouterProvider, createRouter } from '@tanstack/react-router'
337
- import './index.css'
338
-
339
- // Import the generated route tree
340
- import { routeTree } from './routeTree.gen'
341
-
342
- // Create a new router instance
343
- const router = createRouter({ routeTree })
344
-
345
- // Register the router instance for type safety
346
- declare module '@tanstack/react-router' {
347
- interface Register {
348
- router: typeof router
349
- }
350
- }
351
-
352
- // Render the app
353
- const rootElement = document.getElementById('root')!
354
- if (!rootElement.innerHTML) {
355
- const root = ReactDOM.createRoot(rootElement)
356
- root.render(
357
- <StrictMode>
358
- <RouterProvider router={router} />
359
- </StrictMode>,
360
- )
361
- }`,
362
- );
363
- }
364
-
365
- async function removeUnnecessaryFiles() {
366
- await Promise.all([
367
- rm(path.join(props.name, "src", "App.tsx")),
368
- rm(path.join(props.name, "src", "App.css")),
369
- ]);
370
- }
371
-
372
- async function patchTsConfig() {
373
- await Promise.all([
374
- rm(path.join(props.name, "tsconfig.app.json")),
375
- rm(path.join(props.name, "tsconfig.node.json")),
376
- fs.writeFile(
377
- path.join(props.name, "tsconfig.json"),
378
- JSON.stringify(
379
- {
380
- extends: props.extends,
381
- compilerOptions: {
382
- baseUrl: ".",
383
- paths: {
384
- "@/*": ["./src/*"],
385
- },
386
- types: ["@cloudflare/workers-types"],
387
- allowImportingTsExtensions: true,
388
- jsx: "react-jsx",
389
- },
390
- include: [
391
- "vite/*.ts",
392
- "src/**/*.ts",
393
- "src/**/*.tsx",
394
- "src/env.d.ts",
395
- ],
396
- references: props.references?.map((path) => ({ path })),
397
- },
398
- null,
399
- 2,
400
- ),
401
- ),
402
- ]);
403
- }
404
- }
405
- },
406
- );