alchemy 0.3.1 → 0.4.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 (113) hide show
  1. package/README.md +8 -3
  2. package/lib/ai/document.d.ts +12 -1
  3. package/lib/ai/document.js +10 -1
  4. package/lib/ai/index.d.ts +0 -2
  5. package/lib/ai/index.js +0 -2
  6. package/lib/alchemy.d.ts +5 -0
  7. package/lib/alchemy.js +44 -1
  8. package/lib/apply.js +17 -10
  9. package/lib/aws/account-id.d.ts +4 -1
  10. package/lib/aws/account-id.js +1 -1
  11. package/lib/aws/credentials.d.ts +5 -0
  12. package/lib/aws/credentials.js +0 -0
  13. package/lib/aws/oidc/oidc-provider.js +2 -2
  14. package/lib/aws/role.js +35 -23
  15. package/lib/cloudflare/account-api-token.d.ts +168 -0
  16. package/lib/cloudflare/account-api-token.js +179 -0
  17. package/lib/cloudflare/account-id.d.ts +1 -0
  18. package/lib/cloudflare/account-id.js +0 -0
  19. package/lib/cloudflare/api.d.ts +38 -1
  20. package/lib/cloudflare/api.js +55 -4
  21. package/lib/cloudflare/assets.d.ts +74 -0
  22. package/lib/cloudflare/assets.js +73 -0
  23. package/lib/cloudflare/bindings.d.ts +6 -1
  24. package/lib/cloudflare/bindings.js +6 -0
  25. package/lib/cloudflare/bucket.d.ts +118 -3
  26. package/lib/cloudflare/bucket.js +269 -89
  27. package/lib/cloudflare/custom-domain.d.ts +75 -0
  28. package/lib/cloudflare/custom-domain.js +154 -0
  29. package/lib/cloudflare/{dns.js → dns-records.js} +14 -1
  30. package/lib/cloudflare/index.d.ts +6 -1
  31. package/lib/cloudflare/index.js +6 -1
  32. package/lib/cloudflare/permission-groups.d.ts +78 -0
  33. package/lib/cloudflare/permission-groups.js +48 -0
  34. package/lib/cloudflare/r2-rest-state-store.d.ts +2 -1
  35. package/lib/cloudflare/r2-rest-state-store.js +55 -24
  36. package/lib/cloudflare/static-site.d.ts +17 -18
  37. package/lib/cloudflare/static-site.js +19 -10
  38. package/lib/cloudflare/worker.d.ts +14 -0
  39. package/lib/cloudflare/worker.js +150 -3
  40. package/lib/{util/encrypt.d.ts → encrypt.d.ts} +1 -1
  41. package/lib/{util/encrypt.js → encrypt.js} +1 -1
  42. package/lib/fs/file-system-state-store.js +1 -1
  43. package/lib/fs/file.d.ts +18 -0
  44. package/lib/fs/file.js +6 -0
  45. package/lib/internal/{providers.d.ts → docs/providers.d.ts} +10 -4
  46. package/lib/internal/docs/providers.js +196 -0
  47. package/lib/secret.d.ts +3 -0
  48. package/lib/secret.js +13 -0
  49. package/lib/{util/serde.d.ts → serde.d.ts} +1 -1
  50. package/lib/{util/serde.js → serde.js} +12 -4
  51. package/lib/test/bun.js +3 -2
  52. package/lib/util/sha256.d.ts +1 -0
  53. package/lib/util/sha256.js +4 -0
  54. package/lib/web/vitepress/config.d.ts +2 -1
  55. package/lib/web/vitepress/config.js +1 -0
  56. package/lib/web/vitepress/index.d.ts +1 -0
  57. package/lib/web/vitepress/index.js +1 -0
  58. package/lib/web/vitepress/process-front-matter-files.d.ts +18 -0
  59. package/lib/web/vitepress/process-front-matter-files.js +68 -0
  60. package/lib/web/vitepress/vitepress.js +3 -2
  61. package/package.json +8 -4
  62. package/src/ai/document.ts +26 -2
  63. package/src/ai/index.ts +0 -2
  64. package/src/alchemy.ts +56 -2
  65. package/src/apply.ts +21 -20
  66. package/src/aws/account-id.ts +6 -2
  67. package/src/aws/credentials.ts +6 -0
  68. package/src/aws/oidc/oidc-provider.ts +17 -17
  69. package/src/aws/role.ts +68 -54
  70. package/src/cloudflare/account-api-token.ts +365 -0
  71. package/src/cloudflare/account-id.ts +0 -0
  72. package/src/cloudflare/api.ts +88 -17
  73. package/src/cloudflare/assets.ts +155 -0
  74. package/src/cloudflare/bindings.ts +11 -2
  75. package/src/cloudflare/bucket.ts +493 -133
  76. package/src/cloudflare/custom-domain.ts +318 -0
  77. package/src/cloudflare/{dns.ts → dns-records.ts} +36 -22
  78. package/src/cloudflare/index.ts +6 -1
  79. package/src/cloudflare/permission-groups.ts +137 -0
  80. package/src/cloudflare/r2-rest-state-store.ts +87 -42
  81. package/src/cloudflare/static-site.ts +20 -32
  82. package/src/cloudflare/worker.ts +253 -5
  83. package/src/dns/import-dns.ts +4 -4
  84. package/src/{util/encrypt.ts → encrypt.ts} +7 -10
  85. package/src/fs/file-system-state-store.ts +5 -5
  86. package/src/fs/file.ts +29 -0
  87. package/src/internal/docs/providers.ts +281 -0
  88. package/src/secret.ts +16 -0
  89. package/src/{util/serde.ts → serde.ts} +16 -10
  90. package/src/test/bun.ts +8 -7
  91. package/src/util/sha256.ts +5 -0
  92. package/src/web/vitepress/config.ts +3 -1
  93. package/src/web/vitepress/index.ts +1 -0
  94. package/src/web/vitepress/process-front-matter-files.ts +98 -0
  95. package/src/web/vitepress/vitepress.ts +3 -2
  96. package/lib/ai/approve.d.ts +0 -99
  97. package/lib/ai/approve.js +0 -76
  98. package/lib/ai/review.d.ts +0 -122
  99. package/lib/ai/review.js +0 -101
  100. package/lib/internal/getting-started.d.ts +0 -21
  101. package/lib/internal/getting-started.js +0 -87
  102. package/lib/internal/index.d.ts +0 -3
  103. package/lib/internal/index.js +0 -3
  104. package/lib/internal/providers.js +0 -172
  105. package/lib/internal/tutorial.d.ts +0 -104
  106. package/lib/internal/tutorial.js +0 -251
  107. package/src/ai/approve.ts +0 -163
  108. package/src/ai/review.ts +0 -213
  109. package/src/internal/getting-started.ts +0 -115
  110. package/src/internal/index.ts +0 -3
  111. package/src/internal/providers.ts +0 -241
  112. package/src/internal/tutorial.ts +0 -392
  113. /package/lib/cloudflare/{dns.d.ts → dns-records.d.ts} +0 -0
@@ -0,0 +1,155 @@
1
+ import * as fs from "fs/promises";
2
+ import * as path from "path";
3
+ import type { Context } from "../context";
4
+ import { Resource } from "../resource";
5
+ import { getContentType } from "../util/content-type";
6
+
7
+ /**
8
+ * Properties for creating or updating Assets
9
+ */
10
+ export interface AssetsProps {
11
+ /**
12
+ * Path to a directory containing static assets to be uploaded
13
+ * These files will be served by Cloudflare's Workers runtime
14
+ */
15
+ path: string;
16
+ }
17
+
18
+ /**
19
+ * Output returned after Assets creation/update
20
+ */
21
+ export interface Assets extends Resource<"cloudflare::Asset">, AssetsProps {
22
+ /**
23
+ * The type of binding
24
+ */
25
+ type: "assets";
26
+
27
+ /**
28
+ * The ID of the assets bundle
29
+ */
30
+ id: string;
31
+
32
+ /**
33
+ * Asset files that were found
34
+ */
35
+ files: AssetFile[];
36
+
37
+ /**
38
+ * Time at which the assets were created
39
+ */
40
+ createdAt: number;
41
+
42
+ /**
43
+ * Time at which the assets were last updated
44
+ */
45
+ updatedAt: number;
46
+ }
47
+
48
+ /**
49
+ * Represents a single asset file
50
+ */
51
+ export interface AssetFile {
52
+ /**
53
+ * Path relative to the assets directory
54
+ */
55
+ path: string;
56
+
57
+ /**
58
+ * Full filesystem path to the file
59
+ */
60
+ filePath: string;
61
+
62
+ /**
63
+ * Content type of the file
64
+ */
65
+ contentType: string;
66
+ }
67
+
68
+ /**
69
+ * Cloudflare Assets represent a collection of static files that can be uploaded and served
70
+ * by Cloudflare Workers.
71
+ *
72
+ * @example
73
+ * // Create a basic assets bundle from a local directory
74
+ * const staticAssets = await Assets("static", {
75
+ * path: "./src/assets"
76
+ * });
77
+ *
78
+ * // Use these assets with a worker
79
+ * const worker = await Worker("frontend", {
80
+ * name: "frontend-worker",
81
+ * entrypoint: "./src/worker.ts",
82
+ * bindings: {
83
+ * ASSETS: staticAssets
84
+ * }
85
+ * });
86
+ */
87
+ export const Assets = Resource(
88
+ "cloudflare::Asset",
89
+ async function (
90
+ this: Context<Assets>,
91
+ id: string,
92
+ props: AssetsProps
93
+ ): Promise<Assets> {
94
+ if (this.phase === "delete") {
95
+ return this.destroy();
96
+ }
97
+
98
+ try {
99
+ // Check if the assets directory exists
100
+ const stats = await fs.stat(props.path);
101
+ if (!stats.isDirectory()) {
102
+ throw new Error(`Assets path ${props.path} is not a directory`);
103
+ }
104
+ } catch (error) {
105
+ throw new Error(
106
+ `Assets directory ${props.path} does not exist or is not accessible`
107
+ );
108
+ }
109
+
110
+ // Recursively get all files in the assets directory
111
+ const filesList = await getFilesRecursively(props.path);
112
+
113
+ // Create asset file objects
114
+ const files: AssetFile[] = filesList.map((filePath) => {
115
+ const relativePath = path.relative(props.path, filePath);
116
+ const normalizedPath = relativePath.split(path.sep).join("/"); // Ensure forward slashes for URLs
117
+
118
+ return {
119
+ path: normalizedPath,
120
+ filePath,
121
+ contentType: getContentType(filePath),
122
+ };
123
+ });
124
+
125
+ // Get current timestamp
126
+ const now = Date.now();
127
+
128
+ // Construct the output
129
+ return this({
130
+ id,
131
+ type: "assets",
132
+ path: props.path,
133
+ files,
134
+ createdAt: this.output?.createdAt || now,
135
+ updatedAt: now,
136
+ });
137
+ }
138
+ );
139
+
140
+ // Helper functions for file operations
141
+ async function getFilesRecursively(dir: string): Promise<string[]> {
142
+ const files = await fs.readdir(dir, { withFileTypes: true });
143
+
144
+ const allFiles = await Promise.all(
145
+ files.map(async (file) => {
146
+ const path = `${dir}/${file.name}`;
147
+ if (file.isDirectory()) {
148
+ return getFilesRecursively(path);
149
+ }
150
+ return path;
151
+ })
152
+ );
153
+
154
+ return allFiles.flat();
155
+ }
@@ -4,6 +4,7 @@
4
4
  * https://developers.cloudflare.com/api/resources/workers/subresources/scripts/methods/update/
5
5
  */
6
6
  import type { Secret } from "../secret";
7
+ import type { Assets } from "./assets";
7
8
  import type { R2Bucket } from "./bucket";
8
9
  import type { DurableObjectNamespace } from "./durable-object-namespace";
9
10
  import type { KVNamespace } from "./kv-namespace";
@@ -22,16 +23,24 @@ export type Binding =
22
23
  | Worker
23
24
  | R2Bucket
24
25
  | Secret
25
- | string;
26
+ | string
27
+ | Assets;
26
28
 
27
29
  export function isDurableObjectNamespace(
28
- binding: Binding,
30
+ binding: Binding
29
31
  ): binding is DurableObjectNamespace {
30
32
  return (
31
33
  typeof binding === "object" && binding.type === "durable_object_namespace"
32
34
  );
33
35
  }
34
36
 
37
+ /**
38
+ * Check if a binding is an Assets resource
39
+ */
40
+ export function isAssets(binding: Binding): binding is Assets {
41
+ return typeof binding === "object" && binding.type === "assets";
42
+ }
43
+
35
44
  /**
36
45
  * Union type for all Worker binding types (API spec)
37
46
  */