alchemy 0.57.2 → 0.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/bin/alchemy.js +1 -1
  2. package/lib/apply.js +3 -3
  3. package/lib/apply.js.map +1 -1
  4. package/lib/cloudflare/api-error.js +1 -1
  5. package/lib/cloudflare/api-error.js.map +1 -1
  6. package/lib/cloudflare/api-response.d.ts +19 -0
  7. package/lib/cloudflare/api-response.d.ts.map +1 -1
  8. package/lib/cloudflare/api-response.js.map +1 -1
  9. package/lib/cloudflare/api.d.ts.map +1 -1
  10. package/lib/cloudflare/api.js +10 -2
  11. package/lib/cloudflare/api.js.map +1 -1
  12. package/lib/cloudflare/assets.d.ts +1 -1
  13. package/lib/cloudflare/assets.d.ts.map +1 -1
  14. package/lib/cloudflare/bucket.d.ts +21 -3
  15. package/lib/cloudflare/bucket.d.ts.map +1 -1
  16. package/lib/cloudflare/bucket.js +83 -53
  17. package/lib/cloudflare/bucket.js.map +1 -1
  18. package/lib/cloudflare/compatibility-date.gen.d.ts +1 -1
  19. package/lib/cloudflare/compatibility-date.gen.js +1 -1
  20. package/lib/cloudflare/container.d.ts +8 -0
  21. package/lib/cloudflare/container.d.ts.map +1 -1
  22. package/lib/cloudflare/container.js +7 -1
  23. package/lib/cloudflare/container.js.map +1 -1
  24. package/lib/cloudflare/custom-domain.d.ts +8 -0
  25. package/lib/cloudflare/custom-domain.d.ts.map +1 -1
  26. package/lib/cloudflare/custom-domain.js +11 -0
  27. package/lib/cloudflare/custom-domain.js.map +1 -1
  28. package/lib/cloudflare/d1-database.d.ts +15 -1
  29. package/lib/cloudflare/d1-database.d.ts.map +1 -1
  30. package/lib/cloudflare/d1-database.js +24 -17
  31. package/lib/cloudflare/d1-database.js.map +1 -1
  32. package/lib/cloudflare/d1-import.d.ts.map +1 -1
  33. package/lib/cloudflare/d1-import.js.map +1 -1
  34. package/lib/cloudflare/hyperdrive.d.ts +37 -9
  35. package/lib/cloudflare/hyperdrive.d.ts.map +1 -1
  36. package/lib/cloudflare/hyperdrive.js +91 -5
  37. package/lib/cloudflare/hyperdrive.js.map +1 -1
  38. package/lib/cloudflare/index.d.ts +1 -0
  39. package/lib/cloudflare/index.d.ts.map +1 -1
  40. package/lib/cloudflare/index.js +1 -0
  41. package/lib/cloudflare/index.js.map +1 -1
  42. package/lib/cloudflare/kv-namespace.d.ts +23 -4
  43. package/lib/cloudflare/kv-namespace.d.ts.map +1 -1
  44. package/lib/cloudflare/kv-namespace.js +70 -58
  45. package/lib/cloudflare/kv-namespace.js.map +1 -1
  46. package/lib/cloudflare/miniflare/build-worker-options.d.ts +2 -0
  47. package/lib/cloudflare/miniflare/build-worker-options.d.ts.map +1 -1
  48. package/lib/cloudflare/miniflare/build-worker-options.js +9 -7
  49. package/lib/cloudflare/miniflare/build-worker-options.js.map +1 -1
  50. package/lib/cloudflare/miniflare/delete.d.ts +21 -0
  51. package/lib/cloudflare/miniflare/delete.d.ts.map +1 -0
  52. package/lib/cloudflare/miniflare/delete.js +91 -0
  53. package/lib/cloudflare/miniflare/delete.js.map +1 -0
  54. package/lib/cloudflare/miniflare/miniflare-controller.d.ts.map +1 -1
  55. package/lib/cloudflare/miniflare/miniflare-controller.js +26 -9
  56. package/lib/cloudflare/miniflare/miniflare-controller.js.map +1 -1
  57. package/lib/cloudflare/miniflare/remote-binding-proxy.d.ts +2 -0
  58. package/lib/cloudflare/miniflare/remote-binding-proxy.d.ts.map +1 -1
  59. package/lib/cloudflare/miniflare/remote-binding-proxy.js +3 -4
  60. package/lib/cloudflare/miniflare/remote-binding-proxy.js.map +1 -1
  61. package/lib/cloudflare/pipeline.d.ts +3 -0
  62. package/lib/cloudflare/pipeline.d.ts.map +1 -1
  63. package/lib/cloudflare/pipeline.js +14 -1
  64. package/lib/cloudflare/pipeline.js.map +1 -1
  65. package/lib/cloudflare/queue-consumer.d.ts +8 -0
  66. package/lib/cloudflare/queue-consumer.d.ts.map +1 -1
  67. package/lib/cloudflare/queue-consumer.js +15 -4
  68. package/lib/cloudflare/queue-consumer.js.map +1 -1
  69. package/lib/cloudflare/queue.d.ts +22 -4
  70. package/lib/cloudflare/queue.d.ts.map +1 -1
  71. package/lib/cloudflare/queue.js +32 -9
  72. package/lib/cloudflare/queue.js.map +1 -1
  73. package/lib/cloudflare/route.d.ts +8 -0
  74. package/lib/cloudflare/route.d.ts.map +1 -1
  75. package/lib/cloudflare/route.js +13 -0
  76. package/lib/cloudflare/route.js.map +1 -1
  77. package/lib/cloudflare/tunnel.d.ts +448 -0
  78. package/lib/cloudflare/tunnel.d.ts.map +1 -0
  79. package/lib/cloudflare/tunnel.js +467 -0
  80. package/lib/cloudflare/tunnel.js.map +1 -0
  81. package/lib/cloudflare/worker-subdomain.d.ts +8 -0
  82. package/lib/cloudflare/worker-subdomain.d.ts.map +1 -1
  83. package/lib/cloudflare/worker-subdomain.js +9 -1
  84. package/lib/cloudflare/worker-subdomain.js.map +1 -1
  85. package/lib/cloudflare/worker.d.ts +7 -1
  86. package/lib/cloudflare/worker.d.ts.map +1 -1
  87. package/lib/cloudflare/worker.js +405 -375
  88. package/lib/cloudflare/worker.js.map +1 -1
  89. package/lib/cloudflare/wrangler.json.d.ts +1 -1
  90. package/lib/cloudflare/wrangler.json.d.ts.map +1 -1
  91. package/lib/cloudflare/wrangler.json.js +24 -12
  92. package/lib/cloudflare/wrangler.json.js.map +1 -1
  93. package/lib/destroy.d.ts.map +1 -1
  94. package/lib/destroy.js +4 -8
  95. package/lib/destroy.js.map +1 -1
  96. package/lib/esbuild/bundle.d.ts +1 -1
  97. package/lib/secret.d.ts +18 -1
  98. package/lib/secret.d.ts.map +1 -1
  99. package/lib/secret.js +25 -0
  100. package/lib/secret.js.map +1 -1
  101. package/package.json +1 -1
  102. package/src/apply.ts +5 -6
  103. package/src/cloudflare/api-error.ts +2 -2
  104. package/src/cloudflare/api-response.ts +22 -0
  105. package/src/cloudflare/api.ts +13 -2
  106. package/src/cloudflare/bucket.ts +126 -68
  107. package/src/cloudflare/compatibility-date.gen.ts +1 -1
  108. package/src/cloudflare/container.ts +18 -1
  109. package/src/cloudflare/custom-domain.ts +22 -0
  110. package/src/cloudflare/d1-database.ts +44 -19
  111. package/src/cloudflare/d1-import.ts +1 -14
  112. package/src/cloudflare/hyperdrive.ts +170 -14
  113. package/src/cloudflare/index.ts +1 -0
  114. package/src/cloudflare/kv-namespace.ts +117 -73
  115. package/src/cloudflare/miniflare/build-worker-options.ts +12 -8
  116. package/src/cloudflare/miniflare/delete.ts +136 -0
  117. package/src/cloudflare/miniflare/miniflare-controller.ts +26 -9
  118. package/src/cloudflare/miniflare/remote-binding-proxy.ts +5 -4
  119. package/src/cloudflare/pipeline.ts +17 -1
  120. package/src/cloudflare/queue-consumer.ts +27 -5
  121. package/src/cloudflare/queue.ts +62 -12
  122. package/src/cloudflare/route.ts +24 -0
  123. package/src/cloudflare/tunnel.ts +911 -0
  124. package/src/cloudflare/worker-subdomain.ts +29 -6
  125. package/src/cloudflare/worker.ts +484 -465
  126. package/src/cloudflare/wrangler.json.ts +34 -13
  127. package/src/destroy.ts +4 -8
  128. package/src/secret.ts +30 -1
  129. package/templates/astro/README.md +2 -0
  130. package/templates/nuxt/README.md +2 -0
  131. package/templates/react-router/README.md +2 -0
  132. package/templates/rwsdk/README.md +2 -0
  133. package/templates/sveltekit/README.md +2 -0
  134. package/templates/tanstack-start/README.md +2 -0
  135. package/templates/typescript/README.md +2 -0
  136. package/templates/vite/README.md +2 -0
@@ -178,6 +178,7 @@ export const WranglerJson = Resource(
178
178
  worker.name,
179
179
  cwd,
180
180
  props.secrets ?? false,
181
+ this.scope.local && !props.worker.dev?.remote,
181
182
  );
182
183
  }
183
184
 
@@ -450,7 +451,11 @@ export interface WranglerJsonSpec {
450
451
  /**
451
452
  * Hyperdrive bindings
452
453
  */
453
- hyperdrive?: { binding: string; id: string; localConnectionString: string }[];
454
+ hyperdrive?: {
455
+ binding: string;
456
+ id: string;
457
+ localConnectionString?: string;
458
+ }[];
454
459
 
455
460
  /**
456
461
  * Pipelines
@@ -500,6 +505,7 @@ function processBindings(
500
505
  workerName: string,
501
506
  workerCwd: string,
502
507
  writeSecrets: boolean,
508
+ local: boolean,
503
509
  ): void {
504
510
  // Arrays to collect different binding types
505
511
  const kvNamespaces: {
@@ -563,7 +569,7 @@ function processBindings(
563
569
  const hyperdrive: {
564
570
  binding: string;
565
571
  id: string;
566
- localConnectionString: string;
572
+ localConnectionString?: string;
567
573
  }[] = [];
568
574
  const pipelines: { binding: string; pipeline: string }[] = [];
569
575
  const secretsStoreSecrets: {
@@ -624,7 +630,12 @@ function processBindings(
624
630
  });
625
631
  } else if (binding.type === "kv_namespace") {
626
632
  // KV Namespace binding
627
- const id = "namespaceId" in binding ? binding.namespaceId : binding.id;
633
+ const id =
634
+ "dev" in binding && !binding.dev?.remote && local
635
+ ? binding.dev.id
636
+ : "namespaceId" in binding
637
+ ? binding.namespaceId
638
+ : binding.id;
628
639
  kvNamespaces.push({
629
640
  binding: bindingName,
630
641
  id: id,
@@ -651,10 +662,14 @@ function processBindings(
651
662
  new_classes.push(doBinding.className);
652
663
  }
653
664
  } else if (binding.type === "r2_bucket") {
665
+ const name =
666
+ "dev" in binding && !binding.dev?.remote && local
667
+ ? binding.dev.id
668
+ : binding.name;
654
669
  r2Buckets.push({
655
670
  binding: bindingName,
656
- bucket_name: binding.name,
657
- preview_bucket_name: binding.name,
671
+ bucket_name: name,
672
+ preview_bucket_name: name,
658
673
  ...(binding.dev?.remote ? { experimental_remote: true } : {}),
659
674
  });
660
675
  } else if (binding.type === "secret") {
@@ -673,18 +688,26 @@ function processBindings(
673
688
  script_name: binding.scriptName,
674
689
  });
675
690
  } else if (binding.type === "d1") {
691
+ const id =
692
+ "dev" in binding && !binding.dev?.remote && local
693
+ ? binding.dev.id
694
+ : binding.id;
676
695
  d1Databases.push({
677
696
  binding: bindingName,
678
- database_id: binding.id,
697
+ database_id: id,
679
698
  database_name: binding.name,
680
699
  migrations_dir: binding.migrationsDir,
681
- preview_database_id: binding.id,
700
+ preview_database_id: id,
682
701
  ...(binding.dev?.remote ? { experimental_remote: true } : {}),
683
702
  });
684
703
  } else if (binding.type === "queue") {
704
+ const id =
705
+ "dev" in binding && !binding.dev?.remote && local
706
+ ? binding.dev.id
707
+ : binding.id;
685
708
  queues.producers.push({
686
709
  binding: bindingName,
687
- queue: binding.name,
710
+ queue: id,
688
711
  });
689
712
  } else if (binding.type === "vectorize") {
690
713
  vectorizeIndexes.push({
@@ -737,14 +760,12 @@ function processBindings(
737
760
  binding: bindingName,
738
761
  };
739
762
  } else if (binding.type === "hyperdrive") {
740
- const password =
741
- "password" in binding.origin
742
- ? binding.origin.password.unencrypted
743
- : binding.origin.access_client_secret.unencrypted;
744
763
  hyperdrive.push({
745
764
  binding: bindingName,
746
765
  id: binding.hyperdriveId,
747
- localConnectionString: `${binding.origin.scheme || "postgres"}://${binding.origin.user}:${password}@${binding.origin.host}:${binding.origin.port || 5432}/${binding.origin.database}`,
766
+ localConnectionString: writeSecrets
767
+ ? binding.dev.origin.unencrypted
768
+ : undefined,
748
769
  });
749
770
  } else if (binding.type === "pipeline") {
750
771
  pipelines.push({
package/src/destroy.ts CHANGED
@@ -175,18 +175,14 @@ export async function destroy<Type extends string>(
175
175
  }
176
176
  }
177
177
 
178
- const destroyOptions = {
179
- ...options,
180
- strategy: instance[DestroyStrategy] ?? "sequential",
181
- };
182
178
  if (nestedScope) {
183
- await destroy(nestedScope, destroyOptions);
179
+ await destroy(nestedScope, {
180
+ ...options,
181
+ strategy: instance[DestroyStrategy] ?? "sequential",
182
+ });
184
183
  }
185
184
 
186
185
  if (options?.replace == null) {
187
- if (nestedScope) {
188
- await destroy(nestedScope, destroyOptions);
189
- }
190
186
  await scope.deleteResource(instance[ResourceID]);
191
187
  } else {
192
188
  let pendingDeletions =
package/src/secret.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { inspect } from "node:util";
1
2
  import { alchemy } from "./alchemy.ts";
2
3
 
3
4
  declare global {
@@ -70,12 +71,40 @@ export class Secret<T = string> {
70
71
  ) {
71
72
  globalSecrets[name] = this;
72
73
  }
74
+
75
+ /**
76
+ * Ensures that a value is wrapped in a Secret.
77
+ */
78
+ static wrap<T>(value: T | Secret<T>): Secret<T> {
79
+ return isSecret<T>(value) ? value : new Secret(value);
80
+ }
81
+
82
+ /**
83
+ * Unwraps a Secret if it is wrapped, otherwise returns the value.
84
+ */
85
+ static unwrap<T, U = T>(value: T | Secret<U>): T | U {
86
+ return isSecret<U>(value) ? value.unencrypted : value;
87
+ }
88
+
89
+ /**
90
+ * Override toString to prevent accidental exposure of secret values
91
+ */
92
+ toString(): string {
93
+ return `Secret(${this.name ?? ""})`;
94
+ }
95
+
96
+ /**
97
+ * Custom inspect implementation for console.log to prevent exposing secrets
98
+ */
99
+ [inspect.custom](): string {
100
+ return this.toString();
101
+ }
73
102
  }
74
103
 
75
104
  /**
76
105
  * Type guard to check if a value is a Secret wrapper
77
106
  */
78
- export function isSecret(binding: any): binding is Secret {
107
+ export function isSecret<T = string>(binding: any): binding is Secret<T> {
79
108
  return (
80
109
  binding instanceof Secret ||
81
110
  (typeof binding === "object" && binding?.type === "secret")
@@ -1,5 +1,7 @@
1
1
  # Astro Starter Kit: Basics
2
2
 
3
+ [![Deployed with Alchemy](https://alchemy.run/alchemy-badge.svg)](https://alchemy.run)
4
+
3
5
  ```sh
4
6
  bun create astro@latest -- --template basics
5
7
  ```
@@ -1,5 +1,7 @@
1
1
  # Nuxt Minimal Starter
2
2
 
3
+ [![Deployed with Alchemy](https://alchemy.run/alchemy-badge.svg)](https://alchemy.run)
4
+
3
5
  Look at the [Nuxt documentation](https://nuxt.com/docs/getting-started/introduction) to learn more.
4
6
 
5
7
  ## Setup
@@ -1,5 +1,7 @@
1
1
  # Welcome to React Router!
2
2
 
3
+ [![Deployed with Alchemy](https://alchemy.run/alchemy-badge.svg)](https://alchemy.run)
4
+
3
5
  A modern, production-ready template for building full-stack React applications using React Router.
4
6
 
5
7
  ## Features
@@ -1,5 +1,7 @@
1
1
  # Standard RedwoodSDK Starter
2
2
 
3
+ [![Deployed with Alchemy](https://alchemy.run/alchemy-badge.svg)](https://alchemy.run)
4
+
3
5
  This "standard starter" is the recommended implementation for RedwoodSDK. You get a Typescript project with:
4
6
 
5
7
  - Vite
@@ -1,5 +1,7 @@
1
1
  # sv
2
2
 
3
+ [![Deployed with Alchemy](https://alchemy.run/alchemy-badge.svg)](https://alchemy.run)
4
+
3
5
  Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli).
4
6
 
5
7
  ## Creating a project
@@ -1,5 +1,7 @@
1
1
  # Welcome to TanStack.com!
2
2
 
3
+ [![Deployed with Alchemy](https://alchemy.run/alchemy-badge.svg)](https://alchemy.run)
4
+
3
5
  This site is built with TanStack Router!
4
6
 
5
7
  - [TanStack Router Docs](https://tanstack.com/router)
@@ -1,5 +1,7 @@
1
1
  # my-alchemy-app
2
2
 
3
+ [![Deployed with Alchemy](https://alchemy.run/alchemy-badge.svg)](https://alchemy.run)
4
+
3
5
  To install dependencies:
4
6
 
5
7
  ```bash
@@ -1,5 +1,7 @@
1
1
  # React + TypeScript + Vite
2
2
 
3
+ [![Deployed with Alchemy](https://alchemy.run/alchemy-badge.svg)](https://alchemy.run)
4
+
3
5
  This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4
6
 
5
7
  Currently, two official plugins are available: