alchemy 0.43.5 → 0.44.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 (144) hide show
  1. package/bin/alchemy.mjs +430 -343
  2. package/bin/alchemy.ts +7 -21
  3. package/bin/commands/create.ts +79 -23
  4. package/bin/services/template-manager.ts +9 -4
  5. package/bin/services/vibe-rules.ts +47 -0
  6. package/bin/types.ts +25 -5
  7. package/lib/alchemy.d.ts.map +1 -1
  8. package/lib/alchemy.js +8 -11
  9. package/lib/alchemy.js.map +1 -1
  10. package/lib/apply.js +2 -0
  11. package/lib/apply.js.map +1 -1
  12. package/lib/build-date.d.ts +1 -1
  13. package/lib/build-date.js +1 -1
  14. package/lib/cloudflare/assets.d.ts +1 -1
  15. package/lib/cloudflare/assets.d.ts.map +1 -1
  16. package/lib/cloudflare/bucket.d.ts.map +1 -1
  17. package/lib/cloudflare/bucket.js +9 -6
  18. package/lib/cloudflare/bucket.js.map +1 -1
  19. package/lib/cloudflare/bundle/bundle-worker-dev.d.ts.map +1 -1
  20. package/lib/cloudflare/bundle/bundle-worker-dev.js +4 -1
  21. package/lib/cloudflare/bundle/bundle-worker-dev.js.map +1 -1
  22. package/lib/cloudflare/bundle/bundle-worker.d.ts.map +1 -1
  23. package/lib/cloudflare/bundle/bundle-worker.js +4 -1
  24. package/lib/cloudflare/bundle/bundle-worker.js.map +1 -1
  25. package/lib/cloudflare/bundle/external.d.ts +1 -0
  26. package/lib/cloudflare/bundle/external.d.ts.map +1 -1
  27. package/lib/cloudflare/bundle/external.js +1 -1
  28. package/lib/cloudflare/bundle/external.js.map +1 -1
  29. package/lib/cloudflare/bundle/nodejs-import-warning-plugin.d.ts +10 -0
  30. package/lib/cloudflare/bundle/nodejs-import-warning-plugin.d.ts.map +1 -0
  31. package/lib/cloudflare/bundle/nodejs-import-warning-plugin.js +67 -0
  32. package/lib/cloudflare/bundle/nodejs-import-warning-plugin.js.map +1 -0
  33. package/lib/cloudflare/container.d.ts +27 -2
  34. package/lib/cloudflare/container.d.ts.map +1 -1
  35. package/lib/cloudflare/container.js +82 -24
  36. package/lib/cloudflare/container.js.map +1 -1
  37. package/lib/cloudflare/do-state-store/store.d.ts.map +1 -1
  38. package/lib/cloudflare/do-state-store/store.js +5 -1
  39. package/lib/cloudflare/do-state-store/store.js.map +1 -1
  40. package/lib/cloudflare/redirect-rule.js +1 -1
  41. package/lib/cloudflare/redirect-rule.js.map +1 -1
  42. package/lib/cloudflare/website.d.ts +17 -0
  43. package/lib/cloudflare/website.d.ts.map +1 -1
  44. package/lib/cloudflare/website.js +1 -0
  45. package/lib/cloudflare/website.js.map +1 -1
  46. package/lib/cloudflare/worker/miniflare.d.ts +4 -1
  47. package/lib/cloudflare/worker/miniflare.d.ts.map +1 -1
  48. package/lib/cloudflare/worker/miniflare.js +22 -2
  49. package/lib/cloudflare/worker/miniflare.js.map +1 -1
  50. package/lib/cloudflare/worker-metadata.d.ts.map +1 -1
  51. package/lib/cloudflare/worker-metadata.js +12 -0
  52. package/lib/cloudflare/worker-metadata.js.map +1 -1
  53. package/lib/cloudflare/worker.d.ts +1 -1
  54. package/lib/cloudflare/wrangler.json.d.ts +24 -0
  55. package/lib/cloudflare/wrangler.json.d.ts.map +1 -1
  56. package/lib/cloudflare/wrangler.json.js +20 -2
  57. package/lib/cloudflare/wrangler.json.js.map +1 -1
  58. package/lib/context.d.ts +6 -1
  59. package/lib/context.d.ts.map +1 -1
  60. package/lib/context.js +2 -1
  61. package/lib/context.js.map +1 -1
  62. package/lib/destroy.d.ts.map +1 -1
  63. package/lib/destroy.js +1 -0
  64. package/lib/destroy.js.map +1 -1
  65. package/lib/docker/api.d.ts +11 -0
  66. package/lib/docker/api.d.ts.map +1 -1
  67. package/lib/docker/api.js +41 -1
  68. package/lib/docker/api.js.map +1 -1
  69. package/lib/docker/image.d.ts +1 -1
  70. package/lib/docker/image.d.ts.map +1 -1
  71. package/lib/docker/image.js +11 -5
  72. package/lib/docker/image.js.map +1 -1
  73. package/lib/esbuild/bundle.d.ts +2 -2
  74. package/lib/index.d.ts.map +1 -1
  75. package/lib/index.js.map +1 -1
  76. package/lib/llms.cloudflare.txt +379 -0
  77. package/lib/llms.d.ts +10 -0
  78. package/lib/llms.d.ts.map +1 -0
  79. package/lib/llms.js +12 -0
  80. package/lib/llms.js.map +1 -0
  81. package/lib/planetscale/index.d.ts +3 -2
  82. package/lib/planetscale/index.d.ts.map +1 -1
  83. package/lib/planetscale/index.js +3 -2
  84. package/lib/planetscale/index.js.map +1 -1
  85. package/lib/planetscale/password.d.ts +233 -0
  86. package/lib/planetscale/password.d.ts.map +1 -0
  87. package/lib/planetscale/password.js +238 -0
  88. package/lib/planetscale/password.js.map +1 -0
  89. package/lib/scope.d.ts +6 -5
  90. package/lib/scope.d.ts.map +1 -1
  91. package/lib/scope.js +18 -7
  92. package/lib/scope.js.map +1 -1
  93. package/lib/test/bun.d.ts.map +1 -1
  94. package/lib/test/bun.js +1 -0
  95. package/lib/test/bun.js.map +1 -1
  96. package/lib/test/vitest.d.ts.map +1 -1
  97. package/lib/test/vitest.js +1 -0
  98. package/lib/test/vitest.js.map +1 -1
  99. package/lib/util/nanoid.d.ts +3 -0
  100. package/lib/util/nanoid.d.ts.map +1 -0
  101. package/lib/util/nanoid.js +13 -0
  102. package/lib/util/nanoid.js.map +1 -0
  103. package/lib/util/safe-fetch.d.ts.map +1 -1
  104. package/lib/util/safe-fetch.js +0 -1
  105. package/lib/util/safe-fetch.js.map +1 -1
  106. package/lib/util/telemetry/client.d.ts.map +1 -1
  107. package/lib/util/telemetry/client.js +13 -3
  108. package/lib/util/telemetry/client.js.map +1 -1
  109. package/lib/util/telemetry/constants.d.ts +2 -1
  110. package/lib/util/telemetry/constants.d.ts.map +1 -1
  111. package/lib/util/telemetry/constants.js +3 -2
  112. package/lib/util/telemetry/constants.js.map +1 -1
  113. package/package.json +10 -2
  114. package/src/alchemy.ts +8 -13
  115. package/src/apply.ts +2 -0
  116. package/src/build-date.ts +1 -1
  117. package/src/cloudflare/bucket.ts +22 -14
  118. package/src/cloudflare/bundle/bundle-worker-dev.ts +4 -1
  119. package/src/cloudflare/bundle/bundle-worker.ts +4 -1
  120. package/src/cloudflare/bundle/external.ts +1 -1
  121. package/src/cloudflare/bundle/nodejs-import-warning-plugin.ts +94 -0
  122. package/src/cloudflare/container.ts +113 -28
  123. package/src/cloudflare/do-state-store/store.ts +5 -1
  124. package/src/cloudflare/redirect-rule.ts +1 -1
  125. package/src/cloudflare/website.ts +21 -1
  126. package/src/cloudflare/worker/miniflare.ts +33 -8
  127. package/src/cloudflare/worker-metadata.ts +15 -0
  128. package/src/cloudflare/wrangler.json.ts +61 -5
  129. package/src/context.ts +7 -0
  130. package/src/destroy.ts +1 -0
  131. package/src/docker/api.ts +57 -1
  132. package/src/docker/image.ts +15 -6
  133. package/src/index.ts +1 -0
  134. package/src/llms.cloudflare.txt +379 -0
  135. package/src/llms.ts +25 -0
  136. package/src/planetscale/index.ts +3 -2
  137. package/src/planetscale/password.ts +366 -0
  138. package/src/scope.ts +25 -11
  139. package/src/test/bun.ts +1 -0
  140. package/src/test/vitest.ts +1 -0
  141. package/src/util/nanoid.ts +13 -0
  142. package/src/util/safe-fetch.ts +0 -1
  143. package/src/util/telemetry/client.ts +17 -3
  144. package/src/util/telemetry/constants.ts +5 -3
@@ -0,0 +1,379 @@
1
+ # Alchemy - TypeScript-native Infrastructure as Code
2
+
3
+ Alchemy is a TypeScript-native Infrastructure-as-Code framework that allows you to define cloud resources using familiar TypeScript patterns. This guide focuses on Cloudflare integration.
4
+
5
+ ## Core Concepts
6
+
7
+ **Resources**: Async functions that manage cloud infrastructure lifecycle (create, update, delete)
8
+ **Bindings**: Type-safe connections between resources (workers, KV stores, databases)
9
+ **State Management**: Tracks resource state for consistent deployments
10
+ **Finalization**: Always call `app.finalize()` to clean up orphaned resources
11
+
12
+ ## Basic Setup
13
+
14
+ ### Project Structure
15
+ ```typescript
16
+ // alchemy.run.ts - Your infrastructure definition
17
+ import alchemy from "alchemy";
18
+ import { Worker, KVNamespace } from "alchemy/cloudflare";
19
+
20
+ const app = await alchemy("my-app");
21
+
22
+ export const worker = await Worker("api", {
23
+ entrypoint: "./src/worker.ts",
24
+ bindings: {
25
+ CACHE: await KVNamespace("cache", { title: "cache-store" })
26
+ }
27
+ });
28
+
29
+ console.log({ url: worker.url });
30
+ await app.finalize(); // ⚠️ ALWAYS call finalize()
31
+ ```
32
+
33
+ ### Environment Setup
34
+ ```bash
35
+ # .env - Required for secret encryption
36
+ ALCHEMY_PASSWORD=your-secure-password
37
+
38
+ # Optional: Use Cloudflare state store in production
39
+ ALCHEMY_STATE_STORE=cloudflare
40
+ ```
41
+
42
+ ### Commands
43
+ ```bash
44
+ bun ./alchemy.run.ts # Deploy
45
+ bun ./alchemy.run.ts --destroy # Destroy all resources
46
+ ```
47
+
48
+ ## Workers
49
+
50
+ ### Basic Worker
51
+ ```typescript
52
+ const worker = await Worker("api", {
53
+ entrypoint: "./src/worker.ts",
54
+ url: true, // Get public URL
55
+ });
56
+ ```
57
+
58
+ ### Worker with Bindings
59
+ ```typescript
60
+ const worker = await Worker("api", {
61
+ entrypoint: "./src/worker.ts",
62
+ bindings: {
63
+ // Resource bindings
64
+ CACHE: kvNamespace,
65
+ STORAGE: r2Bucket,
66
+ COUNTER: durableObjectNamespace,
67
+ QUEUE: queue,
68
+ API: otherWorker,
69
+
70
+ // Environment variables
71
+ API_KEY: alchemy.secret(process.env.API_KEY),
72
+ DEBUG: "true"
73
+ }
74
+ });
75
+ ```
76
+
77
+ ### Worker Implementation
78
+ ```typescript
79
+ // src/worker.ts
80
+ import type { worker } from "../alchemy.run";
81
+
82
+ export default {
83
+ async fetch(request: Request, env: typeof worker.Env): Promise<Response> {
84
+ // Type-safe access to all bindings
85
+ const cached = await env.CACHE.get("key");
86
+ const apiKey = env.API_KEY;
87
+
88
+ return new Response("Hello World");
89
+ }
90
+ };
91
+ ```
92
+
93
+ ### Type Safety Setup
94
+ ```typescript
95
+ // types/env.d.ts
96
+ import type { worker } from "../alchemy.run";
97
+
98
+ declare module "cloudflare:workers" {
99
+ namespace Cloudflare {
100
+ export interface Env extends typeof worker.Env {}
101
+ }
102
+ }
103
+ ```
104
+
105
+ ## Durable Objects
106
+
107
+ ### Creating Durable Object Namespace
108
+ ```typescript
109
+ // Use 'new' instead of 'await' for DurableObjectNamespace
110
+ const counter = new DurableObjectNamespace("counter", {
111
+ className: "Counter",
112
+ sqlite: true, // Enable SQLite storage
113
+ });
114
+
115
+ const worker = await Worker("api", {
116
+ entrypoint: "./src/worker.ts",
117
+ bindings: {
118
+ COUNTER: counter, // Bind to worker
119
+ }
120
+ });
121
+ ```
122
+
123
+ ### Durable Object Implementation
124
+ ```typescript
125
+ // src/counter.ts
126
+ import { DurableObject } from "cloudflare:workers";
127
+
128
+ export class Counter extends DurableObject {
129
+ async increment(): Promise<number> {
130
+ let count = (await this.ctx.storage.get("count")) || 0;
131
+ count++;
132
+ await this.ctx.storage.put("count", count);
133
+ return count;
134
+ }
135
+
136
+ async fetch(request: Request): Promise<Response> {
137
+ const count = await this.increment();
138
+ return new Response(JSON.stringify({ count }));
139
+ }
140
+ }
141
+ ```
142
+
143
+ ### Using Durable Objects in Worker
144
+ ```typescript
145
+ // src/worker.ts
146
+ export default {
147
+ async fetch(request: Request, env: typeof worker.Env) {
148
+ // Get a Durable Object instance
149
+ const id = env.COUNTER.idFromName("global-counter");
150
+ const obj = env.COUNTER.get(id);
151
+
152
+ // Call the Durable Object
153
+ return obj.fetch(request);
154
+ }
155
+ };
156
+ ```
157
+
158
+ ### Cross-Script Durable Objects
159
+ ```typescript
160
+ // Method 1: Re-export from provider worker
161
+ const sharedCounter = host.bindings.SHARED_COUNTER;
162
+
163
+ // Method 2: Reference by worker script name
164
+ const counter = new DurableObjectNamespace("counter", {
165
+ className: "Counter",
166
+ scriptName: "provider-worker"
167
+ });
168
+ ```
169
+
170
+ ## Key Resources
171
+
172
+ ### KV Namespace
173
+ ```typescript
174
+ const cache = await KVNamespace("cache", {
175
+ title: "my-cache-store"
176
+ });
177
+
178
+ // Usage in worker
179
+ const value = await env.CACHE.get("key");
180
+ await env.CACHE.put("key", "value", { expirationTtl: 3600 });
181
+ ```
182
+
183
+ ### R2 Bucket
184
+ ```typescript
185
+ const storage = await R2Bucket("storage", {
186
+ allowPublicAccess: false
187
+ });
188
+
189
+ // Usage in worker
190
+ const object = await env.STORAGE.get("file.txt");
191
+ await env.STORAGE.put("file.txt", "content");
192
+ ```
193
+
194
+ ### Queue
195
+ ```typescript
196
+ // Typed queue
197
+ const queue = await Queue<{ name: string; email: string }>("notifications");
198
+
199
+ // Producer worker
200
+ const producer = await Worker("producer", {
201
+ bindings: { QUEUE: queue },
202
+ // Queue sending code
203
+ });
204
+
205
+ // Consumer worker
206
+ const consumer = await Worker("consumer", {
207
+ eventSources: [queue], // Register as consumer
208
+ // Queue processing code
209
+ });
210
+
211
+ // Worker implementation for queue processing
212
+ export default {
213
+ async queue(batch: typeof queue.Batch, env: Env) {
214
+ for (const message of batch.messages) {
215
+ console.log("Processing:", message.body);
216
+ message.ack(); // Acknowledge message
217
+ }
218
+ }
219
+ };
220
+ ```
221
+
222
+ ### Custom Domains
223
+ ```typescript
224
+ const worker = await Worker("api", {
225
+ entrypoint: "./src/worker.ts",
226
+ routes: [
227
+ { pattern: "api.example.com/*", zone: "example.com" },
228
+ { pattern: "example.com/api/*", zone: "example.com" }
229
+ ]
230
+ });
231
+ ```
232
+
233
+ ## Converting Existing Cloudflare Projects
234
+
235
+ ### 1. Migrate wrangler.toml Configuration
236
+ ```toml
237
+ # Old wrangler.toml
238
+ name = "my-worker"
239
+ main = "src/index.js"
240
+
241
+ [env.production]
242
+ kv_namespaces = [
243
+ { binding = "CACHE", id = "abc123" }
244
+ ]
245
+
246
+ [[env.production.r2_buckets]]
247
+ binding = "STORAGE"
248
+ bucket_name = "my-bucket"
249
+ ```
250
+
251
+ ```typescript
252
+ // New alchemy.run.ts
253
+ const worker = await Worker("my-worker", {
254
+ entrypoint: "./src/index.js",
255
+ bindings: {
256
+ CACHE: await KVNamespace("cache", {
257
+ title: "cache-store",
258
+ adopt: true // Use existing KV namespace
259
+ }),
260
+ STORAGE: await R2Bucket("storage", {
261
+ name: "my-bucket",
262
+ adopt: true // Use existing bucket
263
+ })
264
+ }
265
+ });
266
+ ```
267
+
268
+ ### 2. Enable Development Compatibility
269
+ ```typescript
270
+ // Generate wrangler.json for local development
271
+ await WranglerJson("wrangler.json", {
272
+ worker,
273
+ });
274
+ ```
275
+
276
+ ### 3. Adopt Existing Resources
277
+ ```typescript
278
+ // Use adopt: true to use existing resources instead of failing
279
+ const bucket = await R2Bucket("storage", {
280
+ name: "existing-bucket-name",
281
+ adopt: true // Won't fail if bucket already exists
282
+ });
283
+ ```
284
+
285
+ ### 4. State Store Migration
286
+ ```typescript
287
+ // Local development (default)
288
+ const app = await alchemy("my-app");
289
+
290
+ // Production with Cloudflare state store
291
+ const app = await alchemy("my-app", {
292
+ stateStore: process.env.NODE_ENV === "production"
293
+ ? (scope) => new DOStateStore(scope)
294
+ : undefined
295
+ });
296
+ ```
297
+
298
+ ## Advanced Patterns
299
+
300
+ ### Framework Integration (Vite/React/etc.)
301
+ ```typescript
302
+ const website = await Vite("website", {
303
+ main: "./src/worker.ts",
304
+ command: "bun run build", // Build command
305
+ bindings: {
306
+ API: await Worker("api", { entrypoint: "./api/worker.ts" }),
307
+ STORAGE: await R2Bucket("assets")
308
+ }
309
+ });
310
+ ```
311
+
312
+ ### Resource Scoping
313
+ ```typescript
314
+ // Organize resources into logical groups
315
+ await alchemy.run("backend", async () => {
316
+ await Worker("api", { entrypoint: "./api.ts" });
317
+ await KVNamespace("cache", { title: "api-cache" });
318
+ });
319
+
320
+ await alchemy.run("frontend", async () => {
321
+ await Vite("website", { main: "./src/worker.ts" });
322
+ });
323
+ ```
324
+
325
+ ### Testing Pattern
326
+ ```typescript
327
+ import { alchemy } from "../../src/alchemy";
328
+ const test = alchemy.test(import.meta, { prefix: "test" });
329
+
330
+ describe("Worker Tests", () => {
331
+ test("creates worker", async (scope) => {
332
+ const worker = await Worker("test-worker", {
333
+ entrypoint: "./src/worker.ts"
334
+ });
335
+
336
+ expect(worker.url).toBeTruthy();
337
+ // Resources auto-cleaned after test
338
+ });
339
+ });
340
+ ```
341
+
342
+ ## Best Practices
343
+
344
+ 1. **Always call finalize()**: `await app.finalize()` at the end of your script
345
+ 2. **Use adoption for migrations**: `adopt: true` when converting existing projects
346
+ 3. **Type-safe bindings**: Set up env.d.ts for full type safety
347
+ 4. **Resource naming**: Use consistent, descriptive names for resources
348
+ 5. **State store**: Use DOStateStore for production deployments
349
+ 6. **Secrets**: Use `alchemy.secret()` for sensitive values
350
+ 7. **Scoping**: Organize related resources using `alchemy.run()`
351
+ 8. **Testing**: Use `alchemy.test()` for integration tests
352
+
353
+ ## Common Issues
354
+
355
+ - **Missing finalize()**: Resources won't be cleaned up properly
356
+ - **Wrong DurableObject syntax**: Use `new DurableObjectNamespace()` not `await`
357
+ - **Type errors**: Set up env.d.ts file for binding types
358
+ - **State conflicts**: Use different stages/prefixes for different environments
359
+ - **Resource adoption**: Use `adopt: true` when migrating existing resources
360
+
361
+ ## Development Workflow
362
+
363
+ ```bash
364
+ # Create new project
365
+ bunx alchemy create my-app --template=vite
366
+ cd my-app
367
+
368
+ # Set up authentication (one-time)
369
+ bun wrangler login
370
+
371
+ # Deploy infrastructure
372
+ bun run deploy
373
+
374
+ # Local development
375
+ bun run dev
376
+
377
+ # Clean up
378
+ bun run destroy
379
+ ```
package/lib/llms.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export interface AlchemyRule {
2
+ name: string;
3
+ rule: string;
4
+ description?: string;
5
+ alwaysApply?: boolean;
6
+ globs?: string | string[];
7
+ }
8
+ declare const alchemyRules: AlchemyRule[];
9
+ export default alchemyRules;
10
+ //# sourceMappingURL=llms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llms.d.ts","sourceRoot":"","sources":["../src/llms.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC3B;AAaD,QAAA,MAAM,YAAY,EAAE,WAAW,EAAc,CAAC;AAE9C,eAAe,YAAY,CAAC"}
package/lib/llms.js ADDED
@@ -0,0 +1,12 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ const alchemy = {
4
+ name: "cloudflare",
5
+ description: "Core Alchemy development guidelines and patterns",
6
+ alwaysApply: true,
7
+ globs: ["*.ts"],
8
+ rule: await fs.readFile(path.join(import.meta.dirname, "llms.cloudflare.txt"), "utf-8"),
9
+ };
10
+ const alchemyRules = [alchemy];
11
+ export default alchemyRules;
12
+ //# sourceMappingURL=llms.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llms.js","sourceRoot":"","sources":["../src/llms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAU7B,MAAM,OAAO,GAAgB;IAC3B,IAAI,EAAE,YAAY;IAClB,WAAW,EAAE,kDAAkD;IAC/D,WAAW,EAAE,IAAI;IACjB,KAAK,EAAE,CAAC,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,EAAE,CAAC,QAAQ,CACrB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,qBAAqB,CAAC,EACrD,OAAO,CACR;CACF,CAAC;AAEF,MAAM,YAAY,GAAkB,CAAC,OAAO,CAAC,CAAC;AAE9C,eAAe,YAAY,CAAC"}
@@ -1,5 +1,6 @@
1
1
  export * from "./api.ts";
2
- export * from "./utils.ts";
3
- export * from "./database.ts";
4
2
  export * from "./branch.ts";
3
+ export * from "./database.ts";
4
+ export * from "./password.ts";
5
+ export * from "./utils.ts";
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/planetscale/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/planetscale/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC"}
@@ -1,5 +1,6 @@
1
1
  export * from "./api.js";
2
- export * from "./utils.js";
3
- export * from "./database.js";
4
2
  export * from "./branch.js";
3
+ export * from "./database.js";
4
+ export * from "./password.js";
5
+ export * from "./utils.js";
5
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/planetscale/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/planetscale/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,233 @@
1
+ import type { Context } from "../context.ts";
2
+ import { Resource } from "../resource.ts";
3
+ import type { Secret } from "../secret.ts";
4
+ import type { Branch } from "./branch.ts";
5
+ import type { Database } from "./database.ts";
6
+ /**
7
+ * Properties for creating or updating a PlanetScale Branch
8
+ */
9
+ export interface PasswordProps {
10
+ /**
11
+ * The name of the password
12
+ */
13
+ name: string;
14
+ /**
15
+ * The organization ID where the password will be created
16
+ * Required when using string database name, optional when using Database resource
17
+ */
18
+ organizationId?: string;
19
+ /**
20
+ * The database where the password will be created
21
+ * Can be either a database name (string) or Database resource
22
+ */
23
+ database: string | Database;
24
+ /**
25
+ * The branch where the password will be created
26
+ * Can be either a branch name (string) or Branch resource
27
+ * Defaults to "main" if not provided
28
+ */
29
+ branch?: string | Branch;
30
+ /**
31
+ * PlanetScale API token (overrides environment variable)
32
+ */
33
+ apiKey?: Secret;
34
+ /**
35
+ * The password
36
+ */
37
+ role: "reader" | "writer" | "admin" | "readwriter";
38
+ /**
39
+ * Whether the password is for a read replica
40
+ */
41
+ replica?: boolean;
42
+ /**
43
+ * The TTL of the password in seconds
44
+ */
45
+ ttl?: number;
46
+ /**
47
+ * The CIDRs of the password
48
+ */
49
+ cidrs?: string[];
50
+ }
51
+ /**
52
+ * Represents a PlanetScale Branch
53
+ */
54
+ export interface Password extends Resource<"planetscale::Password">, PasswordProps {
55
+ /**
56
+ * The unique identifier for the password
57
+ */
58
+ id: string;
59
+ /**
60
+ * The timestamp when the password expires (ISO 8601 format)
61
+ */
62
+ expiresAt: string;
63
+ /**
64
+ * The host URL for database connection
65
+ */
66
+ host: string;
67
+ /**
68
+ * The username for database authentication
69
+ */
70
+ username: string;
71
+ /**
72
+ * The encrypted password for database authentication
73
+ */
74
+ password: Secret<string>;
75
+ /**
76
+ * The name slug for the password
77
+ */
78
+ nameSlug: string;
79
+ }
80
+ /**
81
+ * Create and manage database passwords for PlanetScale branches. Database passwords provide secure access to your database with specific roles and permissions.
82
+ *
83
+ * @example
84
+ * ## Basic Reader Password
85
+ *
86
+ * Create a read-only password for a database branch:
87
+ *
88
+ * ```ts
89
+ * import { Password } from "alchemy/planetscale";
90
+ *
91
+ * const readerPassword = await Password("app-reader", {
92
+ * name: "app-reader",
93
+ * organizationId: "my-org",
94
+ * database: "my-app-db",
95
+ * branch: "main",
96
+ * role: "reader"
97
+ * });
98
+ *
99
+ * // Access connection details
100
+ * console.log(`Host: ${readerPassword.password.host}`);
101
+ * console.log(`Username: ${readerPassword.password.username}`);
102
+ * console.log(`Password: ${readerPassword.password.password.unencrypted}`);
103
+ * ```
104
+ *
105
+ * @example
106
+ * ## Writer Password with TTL
107
+ *
108
+ * Create a writer password that expires after 24 hours:
109
+ *
110
+ * ```ts
111
+ * import { Password } from "alchemy/planetscale";
112
+ *
113
+ * const writerPassword = await Password("app-writer", {
114
+ * name: "app-writer",
115
+ * organizationId: "my-org",
116
+ * database: "my-app-db",
117
+ * branch: "development",
118
+ * role: "writer",
119
+ * ttl: 86400 // 24 hours in seconds
120
+ * });
121
+ *
122
+ * // Password will expire at the specified time
123
+ * console.log(`Expires at: ${writerPassword.expiresAt}`);
124
+ * ```
125
+ *
126
+ * @example
127
+ * ## Admin Password with IP Restrictions
128
+ *
129
+ * Create an admin password that only allows connections from specific IP addresses:
130
+ *
131
+ * ```ts
132
+ * import { Password } from "alchemy/planetscale";
133
+ *
134
+ * const adminPassword = await Password("admin-access", {
135
+ * name: "admin-access",
136
+ * organizationId: "my-org",
137
+ * database: "my-app-db",
138
+ * branch: "main",
139
+ * role: "admin",
140
+ * cidrs: ["203.0.113.0/24", "198.51.100.0/24"],
141
+ * ttl: 3600 // 1 hour
142
+ * });
143
+ * ```
144
+ *
145
+ * @example
146
+ * ## Database Password with Custom API Key
147
+ *
148
+ * Create a password using a specific API key instead of the default environment variable:
149
+ *
150
+ * ```ts
151
+ * import { Password } from "alchemy/planetscale";
152
+ *
153
+ * const password = await Password("custom-auth", {
154
+ * name: "custom-auth",
155
+ * organizationId: "my-org",
156
+ * database: "my-app-db",
157
+ * branch: "main",
158
+ * role: "readwriter",
159
+ * apiKey: alchemy.secret(process.env.CUSTOM_PLANETSCALE_TOKEN)
160
+ * });
161
+ * ```
162
+ *
163
+ * @example
164
+ * ## Read Replica Password
165
+ *
166
+ * Create a password for accessing a read replica:
167
+ *
168
+ * ```ts
169
+ * import { Password } from "alchemy/planetscale";
170
+ *
171
+ * const replicaPassword = await Password("replica-reader", {
172
+ * name: "replica-reader",
173
+ * organizationId: "my-org",
174
+ * database: "my-app-db",
175
+ * branch: "main",
176
+ * role: "reader",
177
+ * replica: true
178
+ * });
179
+ *
180
+ * @example
181
+ * ## Using Database Resource Instance
182
+ *
183
+ * Create a password using a Database resource instead of string:
184
+ *
185
+ * ```ts
186
+ * import { Database, Password } from "alchemy/planetscale";
187
+ *
188
+ * const database = await Database("my-db", {
189
+ * name: "my-app-db",
190
+ * organizationId: "my-org",
191
+ * clusterSize: "PS_10"
192
+ * });
193
+ *
194
+ * const password = await Password("db-reader", {
195
+ * name: "db-reader",
196
+ * database: database, // Using Database resource
197
+ * role: "reader"
198
+ * });
199
+ * ```
200
+ *
201
+ * @example
202
+ * ## Using Both Database and Branch Resources
203
+ *
204
+ * Create a password using both Database and Branch resources:
205
+ *
206
+ * ```ts
207
+ * import { Database, Branch, Password } from "alchemy/planetscale";
208
+ *
209
+ * const database = await Database("my-db", {
210
+ * name: "my-app-db",
211
+ * organizationId: "my-org",
212
+ * clusterSize: "PS_10"
213
+ * });
214
+ *
215
+ * const branch = await Branch("feature-branch", {
216
+ * name: "feature-branch",
217
+ * organizationId: "my-org",
218
+ * databaseName: "my-app-db",
219
+ * parentBranch: "main",
220
+ * isProduction: false
221
+ * });
222
+ *
223
+ * const password = await Password("feature-writer", {
224
+ * name: "feature-writer",
225
+ * database: database, // Using Database resource
226
+ * branch: branch, // Using Branch resource
227
+ * role: "writer"
228
+ * });
229
+ * ```
230
+ * ```
231
+ */
232
+ export declare const Password: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context<Password>, _id: string, props: PasswordProps) => Promise<Password>);
233
+ //# sourceMappingURL=password.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password.d.ts","sourceRoot":"","sources":["../../src/planetscale/password.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAI3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAAC;IAE5B;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAEzB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,YAAY,CAAC;IAEnD;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,QACf,SAAQ,QAAQ,CAAC,uBAAuB,CAAC,EACvC,aAAa;IACf;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAEzB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuJG;AACH,eAAO,MAAM,QAAQ,yFAGX,OAAO,CAAC,QAAQ,CAAC,OAClB,MAAM,SACJ,aAAa,KACnB,OAAO,CAAC,QAAQ,CAAC,CA0GrB,CAAC"}