alchemy 0.1.18 → 0.2.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.
Files changed (330) hide show
  1. package/README.md +506 -0
  2. package/lib/alchemy.d.ts +67 -0
  3. package/lib/alchemy.js +48 -0
  4. package/lib/apply.d.ts +3 -20
  5. package/lib/apply.js +95 -82
  6. package/lib/aws/account-id.d.ts +0 -1
  7. package/lib/aws/account-id.js +0 -1
  8. package/lib/aws/bucket.d.ts +4 -7
  9. package/lib/aws/bucket.js +8 -12
  10. package/lib/aws/function.d.ts +4 -7
  11. package/lib/aws/function.js +9 -30
  12. package/lib/aws/index.d.ts +1 -1
  13. package/lib/aws/index.js +1 -1
  14. package/lib/aws/oidc/github-oidc-provider.d.ts +2 -6
  15. package/lib/aws/oidc/github-oidc-provider.js +10 -15
  16. package/lib/aws/oidc/index.d.ts +0 -1
  17. package/lib/aws/oidc/index.js +0 -1
  18. package/lib/aws/oidc/oidc-provider.d.ts +4 -6
  19. package/lib/aws/oidc/oidc-provider.js +9 -11
  20. package/lib/aws/policy-attachment.d.ts +9 -0
  21. package/lib/aws/policy-attachment.js +20 -0
  22. package/lib/aws/policy.d.ts +4 -16
  23. package/lib/aws/policy.js +9 -40
  24. package/lib/aws/queue.d.ts +4 -34
  25. package/lib/aws/queue.js +10 -20
  26. package/lib/aws/role.d.ts +4 -7
  27. package/lib/aws/role.js +17 -26
  28. package/lib/aws/ses.d.ts +4 -10
  29. package/lib/aws/ses.js +118 -131
  30. package/lib/aws/table.d.ts +4 -7
  31. package/lib/aws/table.js +8 -11
  32. package/lib/cloudflare/api.d.ts +0 -1
  33. package/lib/cloudflare/api.js +0 -1
  34. package/lib/cloudflare/asset-manifest.d.ts +0 -1
  35. package/lib/cloudflare/asset-manifest.js +0 -1
  36. package/lib/cloudflare/auth.d.ts +0 -1
  37. package/lib/cloudflare/auth.js +0 -1
  38. package/lib/cloudflare/bindings.d.ts +1 -1
  39. package/lib/cloudflare/bindings.js +3 -2
  40. package/lib/cloudflare/bound.d.ts +0 -1
  41. package/lib/cloudflare/bound.js +0 -1
  42. package/lib/cloudflare/bucket.d.ts +7 -15
  43. package/lib/cloudflare/bucket.js +12 -19
  44. package/lib/cloudflare/durable-object-namespace.d.ts +0 -3
  45. package/lib/cloudflare/durable-object-namespace.js +0 -4
  46. package/lib/cloudflare/generate-asset-manifest.d.ts +0 -1
  47. package/lib/cloudflare/generate-asset-manifest.js +1 -2
  48. package/lib/cloudflare/index.d.ts +2 -1
  49. package/lib/cloudflare/index.js +2 -1
  50. package/lib/cloudflare/kv-namespace.d.ts +6 -9
  51. package/lib/cloudflare/kv-namespace.js +16 -20
  52. package/lib/cloudflare/state.d.ts +0 -1
  53. package/lib/cloudflare/state.js +0 -1
  54. package/lib/cloudflare/static-site-router.d.ts +0 -1
  55. package/lib/cloudflare/static-site-router.js +0 -4
  56. package/lib/cloudflare/static-site.d.ts +5 -11
  57. package/lib/cloudflare/static-site.js +25 -37
  58. package/lib/cloudflare/types.d.ts +0 -1
  59. package/lib/cloudflare/types.js +0 -1
  60. package/lib/cloudflare/upload-asset-manifest.d.ts +0 -1
  61. package/lib/cloudflare/upload-asset-manifest.js +0 -1
  62. package/lib/cloudflare/worker-metadata.d.ts +0 -1
  63. package/lib/cloudflare/worker-metadata.js +0 -1
  64. package/lib/cloudflare/worker-migration.d.ts +0 -1
  65. package/lib/cloudflare/worker-migration.js +0 -1
  66. package/lib/cloudflare/worker.d.ts +8 -14
  67. package/lib/cloudflare/worker.js +38 -50
  68. package/lib/cloudflare/wrangler.json.d.ts +243 -0
  69. package/lib/cloudflare/wrangler.json.js +35 -0
  70. package/lib/cloudflare/zone-settings.d.ts +301 -0
  71. package/lib/cloudflare/zone-settings.js +1 -0
  72. package/lib/cloudflare/zone.d.ts +196 -0
  73. package/lib/cloudflare/zone.js +175 -0
  74. package/lib/context.d.ts +58 -0
  75. package/lib/context.js +36 -0
  76. package/lib/destroy.d.ts +10 -13
  77. package/lib/destroy.js +104 -43
  78. package/lib/{esbuild.d.ts → esbuild/bundle.d.ts} +4 -18
  79. package/lib/{esbuild.js → esbuild/bundle.js} +10 -24
  80. package/lib/esbuild/index.d.ts +1 -0
  81. package/lib/esbuild/index.js +1 -0
  82. package/lib/fs/file.d.ts +13 -0
  83. package/lib/fs/file.js +20 -0
  84. package/lib/fs/folder.d.ts +10 -0
  85. package/lib/fs/folder.js +16 -0
  86. package/lib/fs/index.d.ts +2 -0
  87. package/lib/fs/index.js +2 -0
  88. package/lib/github/client.d.ts +0 -1
  89. package/lib/github/client.js +0 -1
  90. package/lib/github/index.d.ts +0 -1
  91. package/lib/github/index.js +0 -1
  92. package/lib/github/secret.d.ts +4 -6
  93. package/lib/github/secret.js +10 -12
  94. package/lib/index.d.ts +6 -10
  95. package/lib/index.js +5 -9
  96. package/lib/project/index.d.ts +1 -0
  97. package/lib/project/index.js +1 -0
  98. package/lib/project/vite.d.ts +39 -0
  99. package/lib/project/vite.js +68 -0
  100. package/lib/resource.d.ts +34 -62
  101. package/lib/resource.js +29 -270
  102. package/lib/scope.d.ts +37 -14
  103. package/lib/scope.js +97 -23
  104. package/lib/secret.d.ts +2 -7
  105. package/lib/secret.js +7 -20
  106. package/lib/state.d.ts +14 -10
  107. package/lib/state.js +20 -14
  108. package/lib/stripe/index.d.ts +0 -1
  109. package/lib/stripe/index.js +0 -1
  110. package/lib/stripe/price.d.ts +4 -5
  111. package/lib/stripe/price.js +10 -20
  112. package/lib/stripe/product.d.ts +4 -5
  113. package/lib/stripe/product.js +10 -20
  114. package/lib/stripe/webhook.d.ts +4 -6
  115. package/lib/stripe/webhook.js +12 -25
  116. package/lib/test/bun.d.ts +19 -0
  117. package/lib/test/bun.js +55 -0
  118. package/lib/{utils → util}/content-type.d.ts +0 -1
  119. package/lib/{utils → util}/content-type.js +0 -1
  120. package/lib/{encrypt.d.ts → util/encrypt.d.ts} +0 -1
  121. package/lib/{encrypt.js → util/encrypt.js} +0 -1
  122. package/lib/{error.d.ts → util/ignore.d.ts} +0 -1
  123. package/lib/{error.js → util/ignore.js} +0 -1
  124. package/lib/{utils → util}/retry.d.ts +0 -1
  125. package/lib/{utils → util}/retry.js +0 -1
  126. package/lib/util/rm.d.ts +1 -0
  127. package/lib/util/rm.js +11 -0
  128. package/lib/util/serde.d.ts +3 -0
  129. package/lib/{serde.js → util/serde.js} +19 -10
  130. package/lib/util/slugify.d.ts +1 -0
  131. package/lib/util/slugify.js +3 -0
  132. package/package.json +7 -5
  133. package/src/alchemy.ts +127 -0
  134. package/src/apply.ts +116 -115
  135. package/src/aws/bucket.ts +11 -14
  136. package/src/aws/function.ts +13 -33
  137. package/src/aws/index.ts +1 -0
  138. package/src/aws/oidc/github-oidc-provider.ts +14 -19
  139. package/src/aws/oidc/oidc-provider.ts +19 -12
  140. package/src/aws/policy-attachment.ts +51 -0
  141. package/src/aws/policy.ts +15 -60
  142. package/src/aws/queue.ts +17 -21
  143. package/src/aws/role.ts +25 -28
  144. package/src/aws/ses.ts +150 -164
  145. package/src/aws/table.ts +15 -15
  146. package/src/cloudflare/bindings.ts +8 -0
  147. package/src/cloudflare/bucket.ts +39 -47
  148. package/src/cloudflare/durable-object-namespace.ts +0 -10
  149. package/src/cloudflare/generate-asset-manifest.ts +1 -1
  150. package/src/cloudflare/index.ts +2 -0
  151. package/src/cloudflare/kv-namespace.ts +35 -33
  152. package/src/cloudflare/static-site-router.ts +0 -3
  153. package/src/cloudflare/static-site.ts +55 -71
  154. package/src/cloudflare/worker.ts +106 -112
  155. package/src/cloudflare/wrangler.json.ts +309 -0
  156. package/src/cloudflare/zone-settings.ts +368 -0
  157. package/src/cloudflare/zone.ts +491 -0
  158. package/src/context.ts +122 -0
  159. package/src/destroy.ts +124 -73
  160. package/src/{esbuild.ts → esbuild/bundle.ts} +16 -28
  161. package/src/esbuild/index.ts +1 -0
  162. package/src/fs/file.ts +39 -0
  163. package/src/fs/folder.ts +32 -0
  164. package/src/fs/index.ts +2 -0
  165. package/src/github/secret.ts +19 -16
  166. package/src/index.ts +7 -15
  167. package/src/project/index.ts +1 -0
  168. package/src/project/vite.ts +152 -0
  169. package/src/resource.ts +101 -462
  170. package/src/scope.ts +125 -36
  171. package/src/secret.ts +9 -32
  172. package/src/state.ts +38 -21
  173. package/src/stripe/price.ts +17 -22
  174. package/src/stripe/product.ts +17 -22
  175. package/src/stripe/webhook.ts +21 -27
  176. package/src/test/bun.ts +105 -0
  177. package/src/util/rm.ts +11 -0
  178. package/src/util/serde.ts +53 -0
  179. package/src/util/slugify.ts +3 -0
  180. package/lib/$.d.ts +0 -12
  181. package/lib/$.d.ts.map +0 -1
  182. package/lib/$.js +0 -42
  183. package/lib/$.js.map +0 -1
  184. package/lib/alchemize.d.ts +0 -47
  185. package/lib/alchemize.d.ts.map +0 -1
  186. package/lib/alchemize.js +0 -116
  187. package/lib/alchemize.js.map +0 -1
  188. package/lib/apply.d.ts.map +0 -1
  189. package/lib/apply.js.map +0 -1
  190. package/lib/aws/account-id.d.ts.map +0 -1
  191. package/lib/aws/account-id.js.map +0 -1
  192. package/lib/aws/bucket.d.ts.map +0 -1
  193. package/lib/aws/bucket.js.map +0 -1
  194. package/lib/aws/function.d.ts.map +0 -1
  195. package/lib/aws/function.js.map +0 -1
  196. package/lib/aws/index.d.ts.map +0 -1
  197. package/lib/aws/index.js.map +0 -1
  198. package/lib/aws/oidc/github-oidc-provider.d.ts.map +0 -1
  199. package/lib/aws/oidc/github-oidc-provider.js.map +0 -1
  200. package/lib/aws/oidc/index.d.ts.map +0 -1
  201. package/lib/aws/oidc/index.js.map +0 -1
  202. package/lib/aws/oidc/oidc-provider.d.ts.map +0 -1
  203. package/lib/aws/oidc/oidc-provider.js.map +0 -1
  204. package/lib/aws/policy.d.ts.map +0 -1
  205. package/lib/aws/policy.js.map +0 -1
  206. package/lib/aws/queue.d.ts.map +0 -1
  207. package/lib/aws/queue.js.map +0 -1
  208. package/lib/aws/role.d.ts.map +0 -1
  209. package/lib/aws/role.js.map +0 -1
  210. package/lib/aws/ses.d.ts.map +0 -1
  211. package/lib/aws/ses.js.map +0 -1
  212. package/lib/aws/table.d.ts.map +0 -1
  213. package/lib/aws/table.js.map +0 -1
  214. package/lib/cloudflare/api.d.ts.map +0 -1
  215. package/lib/cloudflare/api.js.map +0 -1
  216. package/lib/cloudflare/asset-manifest.d.ts.map +0 -1
  217. package/lib/cloudflare/asset-manifest.js.map +0 -1
  218. package/lib/cloudflare/auth.d.ts.map +0 -1
  219. package/lib/cloudflare/auth.js.map +0 -1
  220. package/lib/cloudflare/bindings.d.ts.map +0 -1
  221. package/lib/cloudflare/bindings.js.map +0 -1
  222. package/lib/cloudflare/bound.d.ts.map +0 -1
  223. package/lib/cloudflare/bound.js.map +0 -1
  224. package/lib/cloudflare/bucket.d.ts.map +0 -1
  225. package/lib/cloudflare/bucket.js.map +0 -1
  226. package/lib/cloudflare/durable-object-namespace.d.ts.map +0 -1
  227. package/lib/cloudflare/durable-object-namespace.js.map +0 -1
  228. package/lib/cloudflare/generate-asset-manifest.d.ts.map +0 -1
  229. package/lib/cloudflare/generate-asset-manifest.js.map +0 -1
  230. package/lib/cloudflare/index.d.ts.map +0 -1
  231. package/lib/cloudflare/index.js.map +0 -1
  232. package/lib/cloudflare/kv-namespace.d.ts.map +0 -1
  233. package/lib/cloudflare/kv-namespace.js.map +0 -1
  234. package/lib/cloudflare/state.d.ts.map +0 -1
  235. package/lib/cloudflare/state.js.map +0 -1
  236. package/lib/cloudflare/static-site-router.d.ts.map +0 -1
  237. package/lib/cloudflare/static-site-router.js.map +0 -1
  238. package/lib/cloudflare/static-site.d.ts.map +0 -1
  239. package/lib/cloudflare/static-site.js.map +0 -1
  240. package/lib/cloudflare/types.d.ts.map +0 -1
  241. package/lib/cloudflare/types.js.map +0 -1
  242. package/lib/cloudflare/upload-asset-manifest.d.ts.map +0 -1
  243. package/lib/cloudflare/upload-asset-manifest.js.map +0 -1
  244. package/lib/cloudflare/worker-metadata.d.ts.map +0 -1
  245. package/lib/cloudflare/worker-metadata.js.map +0 -1
  246. package/lib/cloudflare/worker-migration.d.ts.map +0 -1
  247. package/lib/cloudflare/worker-migration.js.map +0 -1
  248. package/lib/cloudflare/worker.d.ts.map +0 -1
  249. package/lib/cloudflare/worker.js.map +0 -1
  250. package/lib/destroy.d.ts.map +0 -1
  251. package/lib/destroy.js.map +0 -1
  252. package/lib/encrypt.d.ts.map +0 -1
  253. package/lib/encrypt.js.map +0 -1
  254. package/lib/error.d.ts.map +0 -1
  255. package/lib/error.js.map +0 -1
  256. package/lib/esbuild.d.ts.map +0 -1
  257. package/lib/esbuild.js.map +0 -1
  258. package/lib/fs.d.ts +0 -12
  259. package/lib/fs.d.ts.map +0 -1
  260. package/lib/fs.js +0 -41
  261. package/lib/fs.js.map +0 -1
  262. package/lib/github/client.d.ts.map +0 -1
  263. package/lib/github/client.js.map +0 -1
  264. package/lib/github/index.d.ts.map +0 -1
  265. package/lib/github/index.js.map +0 -1
  266. package/lib/github/secret.d.ts.map +0 -1
  267. package/lib/github/secret.js.map +0 -1
  268. package/lib/global.d.ts +0 -16
  269. package/lib/global.d.ts.map +0 -1
  270. package/lib/global.js +0 -42
  271. package/lib/global.js.map +0 -1
  272. package/lib/index.d.ts.map +0 -1
  273. package/lib/index.js.map +0 -1
  274. package/lib/input.d.ts +0 -7
  275. package/lib/input.d.ts.map +0 -1
  276. package/lib/input.js +0 -2
  277. package/lib/input.js.map +0 -1
  278. package/lib/main.d.ts +0 -3
  279. package/lib/main.d.ts.map +0 -1
  280. package/lib/main.js +0 -32
  281. package/lib/main.js.map +0 -1
  282. package/lib/output.d.ts +0 -25
  283. package/lib/output.d.ts.map +0 -1
  284. package/lib/output.js +0 -23
  285. package/lib/output.js.map +0 -1
  286. package/lib/print.d.ts +0 -7
  287. package/lib/print.d.ts.map +0 -1
  288. package/lib/print.js +0 -10
  289. package/lib/print.js.map +0 -1
  290. package/lib/resource.d.ts.map +0 -1
  291. package/lib/resource.js.map +0 -1
  292. package/lib/scope.d.ts.map +0 -1
  293. package/lib/scope.js.map +0 -1
  294. package/lib/secret.d.ts.map +0 -1
  295. package/lib/secret.js.map +0 -1
  296. package/lib/serde.d.ts +0 -3
  297. package/lib/serde.d.ts.map +0 -1
  298. package/lib/serde.js.map +0 -1
  299. package/lib/slug.d.ts +0 -2
  300. package/lib/slug.d.ts.map +0 -1
  301. package/lib/slug.js +0 -4
  302. package/lib/slug.js.map +0 -1
  303. package/lib/state.d.ts.map +0 -1
  304. package/lib/state.js.map +0 -1
  305. package/lib/stripe/index.d.ts.map +0 -1
  306. package/lib/stripe/index.js.map +0 -1
  307. package/lib/stripe/price.d.ts.map +0 -1
  308. package/lib/stripe/price.js.map +0 -1
  309. package/lib/stripe/product.d.ts.map +0 -1
  310. package/lib/stripe/product.js.map +0 -1
  311. package/lib/stripe/webhook.d.ts.map +0 -1
  312. package/lib/stripe/webhook.js.map +0 -1
  313. package/lib/utils/content-type.d.ts.map +0 -1
  314. package/lib/utils/content-type.js.map +0 -1
  315. package/lib/utils/retry.d.ts.map +0 -1
  316. package/lib/utils/retry.js.map +0 -1
  317. package/src/$.ts +0 -69
  318. package/src/alchemize.ts +0 -195
  319. package/src/fs.ts +0 -47
  320. package/src/global.ts +0 -63
  321. package/src/input.ts +0 -19
  322. package/src/main.ts +0 -34
  323. package/src/output.ts +0 -75
  324. package/src/print.ts +0 -18
  325. package/src/serde.ts +0 -46
  326. package/src/slug.ts +0 -3
  327. /package/src/{utils → util}/content-type.ts +0 -0
  328. /package/src/{encrypt.ts → util/encrypt.ts} +0 -0
  329. /package/src/{error.ts → util/ignore.ts} +0 -0
  330. /package/src/{utils → util}/retry.ts +0 -0
@@ -1,4 +1,6 @@
1
1
  import * as esbuild from "esbuild";
2
+ import type { Context } from "../context";
3
+ import { Resource } from "../resource";
2
4
  export interface BundleProps {
3
5
  /**
4
6
  * Entry point for the bundle
@@ -41,7 +43,7 @@ export interface BundleProps {
41
43
  */
42
44
  options?: Partial<esbuild.BuildOptions>;
43
45
  }
44
- export interface BundleOutput {
46
+ export interface Bundle extends Resource<"esbuild::Bundle"> {
45
47
  /**
46
48
  * Path to the bundled file
47
49
  */
@@ -51,21 +53,7 @@ export interface BundleOutput {
51
53
  */
52
54
  hash: string;
53
55
  }
54
- declare const Bundle_base: import("./resource").Provider<string, [props: BundleProps], BundleOutput>;
55
- export declare class Bundle extends Bundle_base {
56
- /**
57
- * Get the metafile from the last build
58
- */
59
- getMetafile(ctx: {
60
- get<T>(key: string): Promise<T | undefined>;
61
- }): Promise<esbuild.Metafile | undefined>;
62
- /**
63
- * Get the hash from the last build
64
- */
65
- getHash(ctx: {
66
- get<T>(key: string): Promise<T | undefined>;
67
- }): Promise<string | undefined>;
68
- }
56
+ export declare const Bundle: ((this: Context<Bundle>, id: string, props: BundleProps) => Promise<Bundle>) | (((this: any, id: string, props: BundleProps) => never) & (new (_: never) => never));
69
57
  export declare function bundle(props: BundleProps): Promise<esbuild.BuildResult<{
70
58
  bundle: boolean;
71
59
  splitting?: boolean;
@@ -148,5 +136,3 @@ export declare function bundle(props: BundleProps): Promise<esbuild.BuildResult<
148
136
  logOverride?: Record<string, esbuild.LogLevel>;
149
137
  tsconfigRaw?: string | esbuild.TsconfigRaw;
150
138
  }>>;
151
- export {};
152
- //# sourceMappingURL=esbuild.d.ts.map
@@ -2,46 +2,33 @@ import * as esbuild from "esbuild";
2
2
  import crypto from "node:crypto";
3
3
  import fs from "node:fs";
4
4
  import path from "node:path";
5
- import { Resource } from "./resource";
6
- export class Bundle extends Resource("esbuild::Bundle", {
5
+ import { Resource } from "../resource";
6
+ export const Bundle = Resource("esbuild::Bundle", {
7
7
  alwaysUpdate: true,
8
- }, async (ctx, props) => {
8
+ }, async function (id, props) {
9
9
  // Determine output path
10
10
  const outputPath = getOutputPath(props);
11
11
  // Ensure output directory exists
12
12
  await fs.promises.mkdir(path.dirname(outputPath), { recursive: true });
13
- if (ctx.event === "delete") {
13
+ if (this.phase === "delete") {
14
14
  await fs.promises.unlink(outputPath).catch(() => { });
15
15
  // Also clean up sourcemap if it exists
16
16
  await fs.promises.unlink(outputPath + ".map").catch(() => { });
17
- return { path: outputPath, hash: "" };
17
+ return this.destroy();
18
18
  }
19
19
  const result = await bundle(props);
20
20
  // Calculate hash of the output
21
21
  const contents = await fs.promises.readFile(outputPath);
22
22
  const hash = crypto.createHash("sha256").update(contents).digest("hex");
23
23
  // Store metadata in context
24
- await ctx.set("metafile", result.metafile);
25
- await ctx.set("hash", hash);
24
+ await this.set("metafile", result.metafile);
25
+ await this.set("hash", hash);
26
26
  // Return output info
27
- return {
27
+ return this({
28
28
  path: outputPath,
29
29
  hash,
30
- };
31
- }) {
32
- /**
33
- * Get the metafile from the last build
34
- */
35
- async getMetafile(ctx) {
36
- return ctx.get("metafile");
37
- }
38
- /**
39
- * Get the hash from the last build
40
- */
41
- async getHash(ctx) {
42
- return ctx.get("hash");
43
- }
44
- }
30
+ });
31
+ });
45
32
  export async function bundle(props) {
46
33
  const outputPath = getOutputPath(props);
47
34
  // Build the bundle
@@ -64,4 +51,3 @@ function getOutputPath(props) {
64
51
  return (props.outfile ||
65
52
  path.join(props.outdir || "dist", path.basename(props.entryPoint, path.extname(props.entryPoint)) + ".js"));
66
53
  }
67
- //# sourceMappingURL=esbuild.js.map
@@ -0,0 +1 @@
1
+ export * from "./bundle";
@@ -0,0 +1 @@
1
+ export * from "./bundle";
@@ -0,0 +1,13 @@
1
+ import type { Context } from "../context";
2
+ import { Resource } from "../resource";
3
+ export interface File extends Resource<"fs::File"> {
4
+ path: string;
5
+ content: string;
6
+ }
7
+ export declare const File: ((this: Context<File>, id: string, { path: filePath, content, }: {
8
+ path: string;
9
+ content: string;
10
+ }) => Promise<File>) | (((this: any, id: string, props: {
11
+ path: string;
12
+ content: string;
13
+ }) => never) & (new (_: never) => never));
package/lib/fs/file.js ADDED
@@ -0,0 +1,20 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { Resource } from "../resource";
4
+ import { ignore } from "../util/ignore";
5
+ export const File = Resource("fs::File", async function (id, { path: filePath, content, }) {
6
+ if (this.phase === "delete") {
7
+ await ignore("ENOENT", async () => fs.promises.unlink(filePath));
8
+ return this.destroy();
9
+ }
10
+ else {
11
+ await fs.promises.mkdir(path.dirname(filePath), {
12
+ recursive: true,
13
+ });
14
+ await fs.promises.writeFile(filePath, content);
15
+ }
16
+ return this({
17
+ path: filePath,
18
+ content,
19
+ });
20
+ });
@@ -0,0 +1,10 @@
1
+ import type { Context } from "../context";
2
+ import { Resource } from "../resource";
3
+ export interface Folder extends Resource<"fs::Folder"> {
4
+ path: string;
5
+ }
6
+ export declare const Folder: ((this: Context<Folder>, id: string, { path: dirPath }: {
7
+ path: string;
8
+ }) => Promise<Folder>) | (((this: any, id: string, props: {
9
+ path: string;
10
+ }) => never) & (new (_: never) => never));
@@ -0,0 +1,16 @@
1
+ import fs from "node:fs";
2
+ import { Resource } from "../resource";
3
+ import { ignore } from "../util/ignore";
4
+ export const Folder = Resource("fs::Folder", async function (id, { path: dirPath }) {
5
+ if (this.phase === "delete") {
6
+ // we just do a best effort attempt
7
+ await ignore(["ENOENT", "ENOTEMPTY"], async () => fs.promises.rmdir(dirPath));
8
+ return this.destroy();
9
+ }
10
+ else {
11
+ await ignore("EEXIST", async () => fs.promises.mkdir(dirPath, { recursive: true }));
12
+ }
13
+ return this({
14
+ path: dirPath,
15
+ });
16
+ });
@@ -0,0 +1,2 @@
1
+ export * from "./file";
2
+ export * from "./folder";
@@ -0,0 +1,2 @@
1
+ export * from "./file";
2
+ export * from "./folder";
@@ -31,4 +31,3 @@ export declare function createGitHubClient(options?: {
31
31
  * @param repo Repository name
32
32
  */
33
33
  export declare function verifyGitHubAuth(octokit: Octokit, owner: string, repo: string): Promise<void>;
34
- //# sourceMappingURL=client.d.ts.map
@@ -88,4 +88,3 @@ export async function verifyGitHubAuth(octokit, owner, repo) {
88
88
  }
89
89
  }
90
90
  }
91
- //# sourceMappingURL=client.js.map
@@ -1,2 +1 @@
1
1
  export * from "./secret";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1,2 +1 @@
1
1
  export * from "./secret";
2
- //# sourceMappingURL=index.js.map
@@ -1,3 +1,5 @@
1
+ import type { Context } from "../context";
2
+ import { Resource } from "../resource";
1
3
  import type { Secret } from "../secret";
2
4
  /**
3
5
  * Properties for creating or updating a GitHub Secret
@@ -27,7 +29,7 @@ export interface GitHubSecretProps {
27
29
  /**
28
30
  * Output returned after Secret creation/update
29
31
  */
30
- export interface GitHubSecretOutput extends Omit<GitHubSecretProps, "value"> {
32
+ export interface GitHubSecretOutput extends Resource<"github::Secret">, Omit<GitHubSecretProps, "value"> {
31
33
  /**
32
34
  * The ID of the resource
33
35
  */
@@ -37,11 +39,7 @@ export interface GitHubSecretOutput extends Omit<GitHubSecretProps, "value"> {
37
39
  */
38
40
  updatedAt: string;
39
41
  }
40
- declare const GitHubSecret_base: import("../resource").Provider<"github::Secret", [props: GitHubSecretProps], GitHubSecretOutput>;
41
42
  /**
42
43
  * Resource for managing GitHub repository secrets
43
44
  */
44
- export declare class GitHubSecret extends GitHubSecret_base {
45
- }
46
- export {};
47
- //# sourceMappingURL=secret.d.ts.map
45
+ export declare const GitHubSecret: ((this: Context<GitHubSecretOutput>, id: string, props: GitHubSecretProps) => Promise<GitHubSecretOutput>) | (((this: any, id: string, props: GitHubSecretProps) => never) & (new (_: never) => never));
@@ -4,15 +4,16 @@ import { createGitHubClient, verifyGitHubAuth } from "./client";
4
4
  /**
5
5
  * Resource for managing GitHub repository secrets
6
6
  */
7
- export class GitHubSecret extends Resource("github::Secret", async (ctx, props) => {
7
+ export const GitHubSecret = Resource("github::Secret", async function (id, props) {
8
8
  // Create authenticated Octokit client - will automatically handle token resolution
9
+ /// TODO: use fetch
9
10
  const octokit = await createGitHubClient({ token: props.token });
10
11
  // Verify authentication and permissions
11
- if (!ctx.quiet) {
12
+ if (!this.quiet) {
12
13
  await verifyGitHubAuth(octokit, props.owner, props.repository);
13
14
  }
14
- if (ctx.event === "delete") {
15
- if (ctx.output?.id) {
15
+ if (this.phase === "delete") {
16
+ if (this.output?.id) {
16
17
  try {
17
18
  // Delete the secret
18
19
  await octokit.rest.actions.deleteRepoSecret({
@@ -32,7 +33,7 @@ export class GitHubSecret extends Resource("github::Secret", async (ctx, props)
32
33
  }
33
34
  }
34
35
  // Return void (a deleted resource has no content)
35
- return undefined;
36
+ return this.destroy();
36
37
  }
37
38
  else {
38
39
  try {
@@ -44,7 +45,7 @@ export class GitHubSecret extends Resource("github::Secret", async (ctx, props)
44
45
  // Encrypt the secret value using libsodium
45
46
  const encryptedValue = await encryptString(props.value.unencrypted, publicKey.key);
46
47
  // Create or update the secret with the encrypted value and key_id
47
- const response = await octokit.rest.actions.createOrUpdateRepoSecret({
48
+ await octokit.rest.actions.createOrUpdateRepoSecret({
48
49
  owner: props.owner,
49
50
  repo: props.repository,
50
51
  secret_name: props.name,
@@ -52,15 +53,14 @@ export class GitHubSecret extends Resource("github::Secret", async (ctx, props)
52
53
  key_id: publicKey.key_id,
53
54
  });
54
55
  // GitHub doesn't return the secret details on create/update, so we need to construct it
55
- const output = {
56
+ return this({
56
57
  id: `${props.owner}/${props.repository}/${props.name}`,
57
58
  owner: props.owner,
58
59
  repository: props.repository,
59
60
  name: props.name,
60
61
  token: props.token,
61
62
  updatedAt: new Date().toISOString(),
62
- };
63
- return output;
63
+ });
64
64
  }
65
65
  catch (error) {
66
66
  if (error.status === 403 &&
@@ -74,8 +74,7 @@ export class GitHubSecret extends Resource("github::Secret", async (ctx, props)
74
74
  throw error;
75
75
  }
76
76
  }
77
- }) {
78
- }
77
+ });
79
78
  /**
80
79
  * Encrypt a value for GitHub using libsodium
81
80
  * Based on GitHub's documentation for encrypting secrets
@@ -96,4 +95,3 @@ async function encryptString(value, publicKey) {
96
95
  // Convert the encrypted message to base64
97
96
  return sodium.to_base64(encryptedBin, sodium.base64_variants.ORIGINAL);
98
97
  }
99
- //# sourceMappingURL=secret.js.map
package/lib/index.d.ts CHANGED
@@ -1,11 +1,7 @@
1
- export * from "./$";
2
- export * from "./alchemize";
3
- export * from "./error";
4
- export * from "./global";
5
- export * from "./input";
6
- export * from "./output";
7
- export * from "./print";
8
- export { Resource, type Context, type CreateContext, type DeleteContext, type UpdateContext, } from "./resource";
1
+ export type * from "./context";
2
+ export * from "./resource";
9
3
  export * from "./secret";
10
- export type { FileSystemStateStore as StateStore } from "./state";
11
- //# sourceMappingURL=index.d.ts.map
4
+ export * from "./state";
5
+ export * from "./util/ignore";
6
+ import { alchemy } from "./alchemy";
7
+ export default alchemy;
package/lib/index.js CHANGED
@@ -1,10 +1,6 @@
1
- export * from "./$";
2
- export * from "./alchemize";
3
- export * from "./error";
4
- export * from "./global";
5
- export * from "./input";
6
- export * from "./output";
7
- export * from "./print";
8
- export { Resource, } from "./resource";
1
+ export * from "./resource";
9
2
  export * from "./secret";
10
- //# sourceMappingURL=index.js.map
3
+ export * from "./state";
4
+ export * from "./util/ignore";
5
+ import { alchemy } from "./alchemy";
6
+ export default alchemy;
@@ -0,0 +1 @@
1
+ export * from "./vite";
@@ -0,0 +1 @@
1
+ export * from "./vite";
@@ -0,0 +1,39 @@
1
+ import type { Context } from "../context";
2
+ import { Resource } from "../resource";
3
+ type ViteTemplate = "vanilla" | "vanilla-ts" | "vue" | "vue-ts" | "react" | "react-ts" | "react-swc" | "react-swc-ts" | "preact" | "preact-ts" | "lit" | "lit-ts" | "svelte" | "svelte-ts" | "solid" | "solid-ts" | "qwik" | "qwik-ts";
4
+ export interface ViteProjectProps {
5
+ /**
6
+ * The name/path of the project
7
+ */
8
+ name: string;
9
+ /**
10
+ * The Vite template to use
11
+ */
12
+ template: ViteTemplate;
13
+ /**
14
+ * The extends to add to the tsconfig.json file
15
+ */
16
+ extends?: string;
17
+ /**
18
+ * The references to add to the tsconfig.json file
19
+ */
20
+ references?: string[];
21
+ /**
22
+ * @default false
23
+ */
24
+ tailwind?: boolean;
25
+ /**
26
+ * Force overwrite the project config tfiles during the update phase
27
+ *
28
+ * @default false
29
+ */
30
+ overwrite?: boolean;
31
+ }
32
+ export interface ViteProject extends ViteProjectProps, Resource {
33
+ /**
34
+ * The name/path of the project
35
+ */
36
+ name: string;
37
+ }
38
+ export declare const ViteProject: ((this: Context<ViteProject>, id: string, props: ViteProjectProps) => Promise<ViteProject>) | (((this: any, id: string, props: ViteProjectProps) => never) & (new (_: never) => never));
39
+ export {};
@@ -0,0 +1,68 @@
1
+ import { exec } from "child_process";
2
+ import fs from "fs/promises";
3
+ import path from "path";
4
+ import { promisify } from "util";
5
+ import { Resource } from "../resource";
6
+ import { rm } from "../util/rm";
7
+ const execAsync = promisify(exec);
8
+ export const ViteProject = Resource("project::ViteProject", async function (id, props) {
9
+ if (this.phase === "delete") {
10
+ try {
11
+ if (await fs.exists(props.name)) {
12
+ // TODO: OS agnostic - fs.rm is slow to delete node_modules/
13
+ await execAsync("rm -rf " + props.name);
14
+ }
15
+ }
16
+ catch (error) {
17
+ console.error(`Error deleting project ${id}:`, error);
18
+ }
19
+ return this.destroy();
20
+ }
21
+ if (this.phase === "update") {
22
+ if (props.overwrite) {
23
+ await modifyConfig(props);
24
+ }
25
+ else {
26
+ console.warn("ViteProject does not support updates - the project must be recreated to change the template");
27
+ }
28
+ }
29
+ else {
30
+ // Create phase
31
+ await execAsync(`bun create vite ${id} --template ${props.template}`);
32
+ await modifyConfig(props);
33
+ }
34
+ return this(props);
35
+ });
36
+ async function modifyConfig(props) {
37
+ if (props.tailwind) {
38
+ await execAsync(`bun add tailwindcss @tailwindcss/vite`);
39
+ await fs.writeFile(path.join(props.name, "vite.config.ts"), `import tailwindcss from "@tailwindcss/vite";
40
+ import react from "@vitejs/plugin-react";
41
+ import { defineConfig } from "vite";
42
+
43
+ // https://vite.dev/config/
44
+ export default defineConfig({
45
+ plugins: [react(), tailwindcss()],
46
+ });`);
47
+ // Add Tailwind CSS import to index.css
48
+ const indexCssPath = path.join(props.name, "src", "index.css");
49
+ const currentCss = await fs.readFile(indexCssPath, "utf-8");
50
+ if (!currentCss.includes('@import "tailwindcss";')) {
51
+ await fs.writeFile(indexCssPath, '@import "tailwindcss";\n\n' + currentCss);
52
+ }
53
+ }
54
+ await Promise.all([
55
+ rm(path.join(props.name, "tsconfig.app.json")),
56
+ rm(path.join(props.name, "tsconfig.node.json")),
57
+ fs.writeFile(path.join(props.name, "tsconfig.json"), JSON.stringify({
58
+ extends: props.extends,
59
+ compilerOptions: {
60
+ types: ["@cloudflare/workers-types"],
61
+ allowImportingTsExtensions: true,
62
+ jsx: "react-jsx",
63
+ },
64
+ include: ["vite/*.ts", "src/**/*.ts", "src/**/*.tsx", "src/env.d.ts"],
65
+ references: props.references?.map((path) => ({ path })),
66
+ }, null, 2)),
67
+ ]);
68
+ }
package/lib/resource.d.ts CHANGED
@@ -1,71 +1,43 @@
1
- import { type ApplyOptions } from "./apply";
2
- import type { DestroyOptions } from "./destroy";
3
- import type { Inputs, Input as input } from "./input";
4
- import { type Export, type Output, type Resolved } from "./output";
5
- import { type Scope as IScope } from "./scope";
6
- import type { State, StateStore } from "./state";
1
+ import type { Context } from "./context";
2
+ import { Scope as _Scope } from "./scope";
3
+ export declare const PROVIDERS: Map<string, any>;
7
4
  export type ResourceID = string;
8
5
  export type ResourceFQN = string;
9
- export type ResourceType = string;
10
- export declare const ResourceID: unique symbol;
11
- export declare const ResourceFQN: unique symbol;
12
- export declare const ResourceHandle: unique symbol;
13
- export declare const Provider: unique symbol;
14
- export declare const Input: unique symbol;
15
- export declare const Value: unique symbol;
16
- export declare const Apply: unique symbol;
17
- export declare const Provide: unique symbol;
18
- export declare const Scope: unique symbol;
19
- export declare const Options: unique symbol;
6
+ export type ResourceKind = string;
20
7
  export interface ProviderOptions {
21
8
  /**
22
9
  * If true, the resource will be updated even if the inputs have not changed.
23
10
  */
24
11
  alwaysUpdate: boolean;
25
12
  }
26
- export type Resource<In extends any[] = any[], Out = any> = {
27
- [ResourceID]: string;
28
- [Provider]: Provider<any, any[], any>;
29
- [Input]: Inputs<In>;
30
- [Value]?: Out;
31
- [Apply]: <O>(value: Out) => O;
32
- [Provide]: (value: Out) => void;
33
- [Options]: ProviderOptions;
34
- } & Output<Out> & Export<Resolved<Out>>;
35
- export interface BaseContext {
36
- quiet: boolean;
37
- stage: string;
38
- resourceID: ResourceID;
39
- resourceFQN: ResourceFQN;
40
- scope: IScope;
41
- get<T>(key: string): Promise<T | undefined>;
42
- set<T>(key: string, value: T): Promise<void>;
43
- delete<T>(key: string): Promise<T | undefined>;
44
- /**
45
- * Indicate that this resource is being replaced.
46
- * This will cause the resource to be deleted at the end of the stack's CREATE phase.
47
- */
48
- replace(): void;
49
- }
50
- export interface CreateContext extends BaseContext {
51
- event: "create";
52
- output?: undefined;
53
- }
54
- export interface UpdateContext<Outputs> extends BaseContext {
55
- event: "update";
56
- output: Outputs;
57
- }
58
- export interface DeleteContext<Outputs> extends BaseContext {
59
- event: "delete";
60
- output: Outputs;
61
- }
62
- export type Context<Outputs> = CreateContext | UpdateContext<Outputs> | DeleteContext<Outputs>;
63
- export type Provider<Type extends ResourceType = ResourceType, In extends any[] = any[], Out = any> = {
13
+ export type ResourceProps = {
14
+ [key: string]: any;
15
+ };
16
+ export type Provider<Type extends string = string, F extends ResourceLifecycleHandler = ResourceLifecycleHandler> = F & IsClass & {
64
17
  type: Type;
65
- update(stage: string, resource: Resource, deps: Set<ResourceID>, inputs: Inputs<In>, stateStore: StateStore, options: ApplyOptions): Promise<Awaited<Out>>;
66
- delete(stage: string, scope: IScope | undefined, resourceID: ResourceID, state: State, inputs: Inputs<In>, options: DestroyOptions): Promise<void>;
67
- } & (new (id: string, ...inputs: [...Inputs<In>, ...any[]]) => Resource<In, Out>);
68
- export declare function isResource(value: any): value is Resource;
69
- export declare function Resource<Args extends any[], Out>(type: string, options: Partial<ProviderOptions>, func: (ctx: Context<Out>, ...args: Args) => Promise<input<Out> | void> | input<Out> | void): Provider<string, Args, Awaited<Out>>;
70
- export declare function Resource<const Type extends ResourceType, Args extends any[], Out>(type: Type, func: (ctx: Context<Out>, ...args: Args) => Promise<input<Out> | void> | input<Out> | void): Provider<Type, Args, Awaited<Out>>;
71
- //# sourceMappingURL=resource.d.ts.map
18
+ options: Partial<ProviderOptions> | undefined;
19
+ handler: F;
20
+ };
21
+ export type PendingResource<Out = unknown, Kind extends ResourceKind = ResourceKind, ID extends ResourceID = ResourceID, FQN extends ResourceFQN = ResourceFQN, Scope extends _Scope = _Scope, Seq extends number = number> = Promise<Out> & {
22
+ Kind: Kind;
23
+ ID: ID;
24
+ FQN: FQN;
25
+ Seq: Seq;
26
+ Scope: Scope;
27
+ signal: () => void;
28
+ };
29
+ export interface Resource<Kind extends ResourceKind = ResourceKind, ID extends ResourceID = ResourceID, FQN extends ResourceFQN = ResourceFQN, Scope extends _Scope = _Scope, Seq extends number = number> {
30
+ Kind: Kind;
31
+ ID: ID;
32
+ FQN: FQN;
33
+ Scope: Scope;
34
+ Seq: Seq;
35
+ }
36
+ type IsClass = {
37
+ new (_: never): never;
38
+ };
39
+ type ResourceLifecycleHandler = (this: Context<any>, id: string, props: any) => Promise<Resource<string>>;
40
+ type Handler<F extends (...args: any[]) => any> = F | (((this: any, id: string, props: Parameters<F>[1]) => never) & IsClass);
41
+ export declare function Resource<const Type extends string, F extends ResourceLifecycleHandler>(type: Type, fn: F): Handler<F>;
42
+ export declare function Resource<const Type extends string, F extends ResourceLifecycleHandler>(type: Type, options: Partial<ProviderOptions>, fn: F): Handler<F>;
43
+ export {};