alchemy 0.2.0 → 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.
@@ -0,0 +1,196 @@
1
+ import type { Context } from "../context";
2
+ import { Resource } from "../resource";
3
+ import type { AlwaysUseHTTPSValue, AutomaticHTTPSRewritesValue, BrotliValue, DevelopmentModeValue, EarlyHintsValue, EmailObfuscationValue, HTTP2Value, HTTP3Value, HotlinkProtectionValue, IPv6Value, MinTLSVersionValue, SSLValue, TLS13Value, WebSocketsValue, ZeroRTTValue } from "./zone-settings";
4
+ /**
5
+ * Properties for creating or updating a Zone
6
+ */
7
+ export interface ZoneProps {
8
+ /**
9
+ * The domain name for the zone
10
+ */
11
+ name: string;
12
+ /**
13
+ * Account ID to use for the zone
14
+ * If not provided, will use the default account
15
+ */
16
+ accountId?: string;
17
+ /**
18
+ * The type of zone to create
19
+ * "full" - Full zone implies that DNS is hosted with Cloudflare
20
+ * "partial" - Partial zone is typically a partner-hosted zone or a CNAME setup
21
+ * "secondary" - Secondary zone is a zone that mirrors the primary zone
22
+ * @default "full"
23
+ */
24
+ type?: "full" | "partial" | "secondary";
25
+ /**
26
+ * Whether to jump start the zone
27
+ * When enabled, Cloudflare will attempt to fetch existing DNS records
28
+ * @default true
29
+ */
30
+ jumpStart?: boolean;
31
+ /**
32
+ * Settings to apply to the zone
33
+ */
34
+ settings?: {
35
+ /**
36
+ * Enable SSL/TLS encryption for the zone
37
+ * "off" - SSL disabled
38
+ * "flexible" - Encrypts traffic between browser and Cloudflare
39
+ * "full" - Encrypts traffic between browser and server, allows self-signed certs
40
+ * "strict" - Encrypts traffic between browser and server, requires valid cert
41
+ */
42
+ ssl?: SSLValue;
43
+ /**
44
+ * Enable Always Use HTTPS
45
+ * Redirects all HTTP traffic to HTTPS
46
+ * @default "off"
47
+ */
48
+ alwaysUseHttps?: AlwaysUseHTTPSValue;
49
+ /**
50
+ * Enable Automatic HTTPS Rewrites
51
+ * Automatically rewrites HTTP URLs to HTTPS
52
+ * @default "off"
53
+ */
54
+ automaticHttpsRewrites?: AutomaticHTTPSRewritesValue;
55
+ /**
56
+ * Enable TLS 1.3
57
+ * Enables the latest version of TLS encryption
58
+ * @default "off"
59
+ */
60
+ tls13?: TLS13Value;
61
+ /**
62
+ * Enable Early Hints
63
+ * Speeds up page loads by serving Link headers
64
+ * @default "off"
65
+ */
66
+ earlyHints?: EarlyHintsValue;
67
+ /**
68
+ * Enable Email Obfuscation
69
+ * Obfuscates email addresses on the site
70
+ * @default "off"
71
+ */
72
+ emailObfuscation?: EmailObfuscationValue;
73
+ /**
74
+ * Enable Browser Cache TTL
75
+ * Sets the browser cache TTL in seconds
76
+ */
77
+ browserCacheTtl?: number;
78
+ /**
79
+ * Enable Development Mode
80
+ * Disables caching and enables real-time updates
81
+ * @default "off"
82
+ */
83
+ developmentMode?: DevelopmentModeValue;
84
+ /**
85
+ * Enable HTTP/2
86
+ * @default "on"
87
+ */
88
+ http2?: HTTP2Value;
89
+ /**
90
+ * Enable HTTP/3
91
+ * @default "on"
92
+ */
93
+ http3?: HTTP3Value;
94
+ /**
95
+ * Enable IPv6
96
+ * @default "on"
97
+ */
98
+ ipv6?: IPv6Value;
99
+ /**
100
+ * Enable WebSockets
101
+ * @default "on"
102
+ */
103
+ websockets?: WebSocketsValue;
104
+ /**
105
+ * Enable Zero-RTT
106
+ * @default "off"
107
+ */
108
+ zeroRtt?: ZeroRTTValue;
109
+ /**
110
+ * Enable Brotli compression
111
+ * @default "on"
112
+ */
113
+ brotli?: BrotliValue;
114
+ /**
115
+ * Enable Hotlink Protection
116
+ * @default "off"
117
+ */
118
+ hotlinkProtection?: HotlinkProtectionValue;
119
+ /**
120
+ * Minimum TLS Version
121
+ * @default "1.0"
122
+ */
123
+ minTlsVersion?: MinTLSVersionValue;
124
+ };
125
+ }
126
+ /**
127
+ * Output returned after Zone creation/update
128
+ */
129
+ export interface Zone extends Resource<"cloudflare::Zone"> {
130
+ /**
131
+ * The ID of the zone
132
+ */
133
+ id: string;
134
+ /**
135
+ * The domain name for the zone
136
+ */
137
+ name: string;
138
+ /**
139
+ * The type of zone
140
+ */
141
+ type: "full" | "partial" | "secondary";
142
+ /**
143
+ * The status of the zone
144
+ */
145
+ status: string;
146
+ /**
147
+ * Whether the zone is paused
148
+ */
149
+ paused: boolean;
150
+ /**
151
+ * The account ID the zone belongs to
152
+ */
153
+ accountId: string;
154
+ /**
155
+ * The nameservers assigned to the zone
156
+ */
157
+ nameservers: string[];
158
+ /**
159
+ * The original nameservers for the zone
160
+ */
161
+ originalNameservers: string[] | null;
162
+ /**
163
+ * Time at which the zone was created
164
+ */
165
+ createdAt: number;
166
+ /**
167
+ * Time at which the zone was last modified
168
+ */
169
+ modifiedAt: number;
170
+ /**
171
+ * Time at which the zone was activated
172
+ */
173
+ activatedAt: number | null;
174
+ /**
175
+ * The zone's current settings
176
+ */
177
+ settings: {
178
+ ssl: SSLValue;
179
+ alwaysUseHttps: AlwaysUseHTTPSValue;
180
+ automaticHttpsRewrites: AutomaticHTTPSRewritesValue;
181
+ tls13: TLS13Value;
182
+ earlyHints: EarlyHintsValue;
183
+ emailObfuscation: EmailObfuscationValue;
184
+ browserCacheTtl: number;
185
+ developmentMode: DevelopmentModeValue;
186
+ http2: HTTP2Value;
187
+ http3: HTTP3Value;
188
+ ipv6: IPv6Value;
189
+ websockets: WebSocketsValue;
190
+ zeroRtt: ZeroRTTValue;
191
+ brotli: BrotliValue;
192
+ hotlinkProtection: HotlinkProtectionValue;
193
+ minTlsVersion: MinTLSVersionValue;
194
+ };
195
+ }
196
+ export declare const Zone: ((this: Context<Zone>, id: string, props: ZoneProps) => Promise<Zone>) | (((this: any, id: string, props: ZoneProps) => never) & (new (_: never) => never));
@@ -0,0 +1,175 @@
1
+ import { Resource } from "../resource";
2
+ import { createCloudflareApi } from "./api";
3
+ export const Zone = Resource("cloudflare::Zone", async function (id, props) {
4
+ // Create Cloudflare API client with automatic account discovery
5
+ const api = await createCloudflareApi({
6
+ accountId: props.accountId,
7
+ });
8
+ if (this.phase === "delete") {
9
+ if (this.output?.id) {
10
+ // Delete zone
11
+ const deleteResponse = await api.delete(`/zones/${this.output.id}`);
12
+ if (!deleteResponse.ok && deleteResponse.status !== 404) {
13
+ const errorData = await deleteResponse.json().catch(() => ({
14
+ errors: [{ message: deleteResponse.statusText }],
15
+ }));
16
+ throw new Error(`Error deleting zone '${props.name}': ${errorData.errors?.[0]?.message || deleteResponse.statusText}`);
17
+ }
18
+ }
19
+ else {
20
+ console.warn(`Zone '${props.name}' not found, skipping delete`);
21
+ }
22
+ return this.destroy();
23
+ }
24
+ if (this.phase === "update" && this.output?.id) {
25
+ // Get zone details to verify it exists
26
+ const response = await api.get(`/zones/${this.output.id}`);
27
+ if (!response.ok) {
28
+ throw new Error(`Error getting zone '${props.name}': ${response.statusText}`);
29
+ }
30
+ const result = (await response.json());
31
+ const zoneData = result.result;
32
+ // Update zone settings if provided
33
+ if (props.settings) {
34
+ await updateZoneSettings(api, this.output.id, props.settings);
35
+ // Add a small delay to ensure settings are propagated
36
+ await new Promise((resolve) => setTimeout(resolve, 2000));
37
+ }
38
+ return this({
39
+ id: zoneData.id,
40
+ name: zoneData.name,
41
+ type: zoneData.type,
42
+ status: zoneData.status,
43
+ paused: zoneData.paused,
44
+ accountId: zoneData.account.id,
45
+ nameservers: zoneData.name_servers,
46
+ originalNameservers: zoneData.original_name_servers,
47
+ createdAt: new Date(zoneData.created_on).getTime(),
48
+ modifiedAt: new Date(zoneData.modified_on).getTime(),
49
+ activatedAt: zoneData.activated_on
50
+ ? new Date(zoneData.activated_on).getTime()
51
+ : null,
52
+ settings: await getZoneSettings(api, zoneData.id),
53
+ });
54
+ }
55
+ else {
56
+ // Create new zone
57
+ const response = await api.post("/zones", {
58
+ name: props.name,
59
+ type: props.type || "full",
60
+ jump_start: props.jumpStart !== false,
61
+ account: {
62
+ id: api.accountId,
63
+ },
64
+ });
65
+ const body = await response.text();
66
+ if (!response.ok) {
67
+ if (response.status === 400 && body.includes("already exists")) {
68
+ // TODO: should we error?
69
+ }
70
+ else {
71
+ throw new Error(`Error creating zone '${props.name}': ${response.statusText}\n${body}`);
72
+ }
73
+ }
74
+ const zoneData = JSON.parse(body).result;
75
+ // Update zone settings if provided
76
+ if (props.settings) {
77
+ await updateZoneSettings(api, zoneData.id, props.settings);
78
+ // Add a small delay to ensure settings are propagated
79
+ await new Promise((resolve) => setTimeout(resolve, 2000));
80
+ }
81
+ return this({
82
+ id: zoneData.id,
83
+ name: zoneData.name,
84
+ type: zoneData.type,
85
+ status: zoneData.status,
86
+ paused: zoneData.paused,
87
+ accountId: zoneData.account.id,
88
+ nameservers: zoneData.name_servers,
89
+ originalNameservers: zoneData.original_name_servers,
90
+ createdAt: new Date(zoneData.created_on).getTime(),
91
+ modifiedAt: new Date(zoneData.modified_on).getTime(),
92
+ activatedAt: zoneData.activated_on
93
+ ? new Date(zoneData.activated_on).getTime()
94
+ : null,
95
+ settings: await getZoneSettings(api, zoneData.id),
96
+ });
97
+ }
98
+ });
99
+ /**
100
+ * Helper function to update zone settings
101
+ */
102
+ async function updateZoneSettings(api, zoneId, settings) {
103
+ if (!settings)
104
+ return;
105
+ const settingsMap = {
106
+ ssl: "ssl",
107
+ alwaysUseHttps: "always_use_https",
108
+ automaticHttpsRewrites: "automatic_https_rewrites",
109
+ tls13: "tls_1_3",
110
+ earlyHints: "early_hints",
111
+ emailObfuscation: "email_obfuscation",
112
+ browserCacheTtl: "browser_cache_ttl",
113
+ developmentMode: "development_mode",
114
+ http2: "http2",
115
+ http3: "http3",
116
+ ipv6: "ipv6",
117
+ websockets: "websockets",
118
+ zeroRtt: "0rtt",
119
+ brotli: "brotli",
120
+ hotlinkProtection: "hotlink_protection",
121
+ minTlsVersion: "min_tls_version",
122
+ };
123
+ await Promise.all(Object.entries(settings)
124
+ .filter(([_, value]) => value !== undefined)
125
+ .map(async ([key, value]) => {
126
+ const settingId = settingsMap[key];
127
+ if (!settingId)
128
+ return;
129
+ const response = await api.patch(`/zones/${zoneId}/settings/${settingId}`, {
130
+ value,
131
+ });
132
+ if (!response.ok) {
133
+ const data = await response.text();
134
+ if (response.status === 400 && data.includes("already enabled")) {
135
+ console.warn(`Warning: Setting '${key}' already enabled`);
136
+ return;
137
+ }
138
+ throw new Error(`Failed to update zone setting ${key}: ${response.statusText}`);
139
+ }
140
+ }));
141
+ }
142
+ /**
143
+ * Helper function to get current zone settings
144
+ */
145
+ async function getZoneSettings(api, zoneId) {
146
+ const settingsResponse = await api.get(`/zones/${zoneId}/settings`);
147
+ if (!settingsResponse.ok) {
148
+ throw new Error(`Failed to fetch zone settings: ${settingsResponse.status} ${settingsResponse.statusText}`);
149
+ }
150
+ const result = (await settingsResponse.json());
151
+ const settingsData = result.result;
152
+ // Helper to get setting value with default
153
+ const getSetting = (id, defaultValue) => {
154
+ const setting = settingsData.find((s) => s.id === id);
155
+ return setting?.value ?? defaultValue;
156
+ };
157
+ return {
158
+ ssl: getSetting("ssl", "off"),
159
+ alwaysUseHttps: getSetting("always_use_https", "off"),
160
+ automaticHttpsRewrites: getSetting("automatic_https_rewrites", "off"),
161
+ tls13: getSetting("tls_1_3", "off"),
162
+ earlyHints: getSetting("early_hints", "off"),
163
+ emailObfuscation: getSetting("email_obfuscation", "off"),
164
+ browserCacheTtl: getSetting("browser_cache_ttl", 14400),
165
+ developmentMode: getSetting("development_mode", "off"),
166
+ http2: getSetting("http2", "on"),
167
+ http3: getSetting("http3", "on"),
168
+ ipv6: getSetting("ipv6", "on"),
169
+ websockets: getSetting("websockets", "on"),
170
+ zeroRtt: getSetting("0rtt", "off"),
171
+ brotli: getSetting("brotli", "on"),
172
+ hotlinkProtection: getSetting("hotlink_protection", "off"),
173
+ minTlsVersion: getSetting("min_tls_version", "1.0"),
174
+ };
175
+ }
package/lib/destroy.js CHANGED
@@ -67,7 +67,7 @@ export async function destroy(...args) {
67
67
  // BUG: this does not restore persisted scope
68
68
  await alchemy.run(instance.ID, async (scope) => {
69
69
  nestedScope = scope;
70
- return Provider.handler.bind(ctx)(instance.ID, state.props);
70
+ return await Provider.handler.bind(ctx)(instance.ID, state.props);
71
71
  });
72
72
  }
73
73
  catch (err) {
@@ -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/scope.d.ts CHANGED
@@ -20,11 +20,13 @@ export declare class Scope {
20
20
  readonly password: string | undefined;
21
21
  readonly state: StateStore;
22
22
  readonly quiet: boolean;
23
+ private isErrored;
23
24
  constructor(options: ScopeOptions);
24
25
  delete(resourceID: ResourceID): Promise<void>;
25
26
  private _seq;
26
27
  seq(): number;
27
28
  get chain(): string[];
29
+ fail(): void;
28
30
  enter(): void;
29
31
  init(): Promise<void>;
30
32
  deinit(): Promise<void>;
package/lib/scope.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { destroy } from "./destroy";
2
3
  import { FileSystemStateStore, } from "./state";
3
4
  const scopeStorage = new AsyncLocalStorage();
4
5
  export class Scope {
@@ -20,6 +21,7 @@ export class Scope {
20
21
  password;
21
22
  state;
22
23
  quiet;
24
+ isErrored = false;
23
25
  constructor(options) {
24
26
  this.appName = options.appName;
25
27
  this.stage = options.stage;
@@ -50,6 +52,10 @@ export class Scope {
50
52
  return [...app, this.stage, ...thisScope];
51
53
  }
52
54
  }
55
+ fail() {
56
+ console.error("Scope failed", this.chain.join("/"));
57
+ this.isErrored = true;
58
+ }
53
59
  enter() {
54
60
  scopeStorage.enterWith(this);
55
61
  }
@@ -63,7 +69,20 @@ export class Scope {
63
69
  return [...this.chain, resourceID].join("/");
64
70
  }
65
71
  async finalize() {
66
- // TODO
72
+ if (!this.isErrored) {
73
+ // TODO: need to detect if it is in error
74
+ const resourceIds = await this.state.list();
75
+ const aliveIds = new Set(this.resources.keys());
76
+ const orphanIds = Array.from(resourceIds.filter((id) => !aliveIds.has(id)));
77
+ const orphans = await Promise.all(orphanIds.map(async (id) => (await this.state.get(id)).output));
78
+ await destroy.all(orphans, {
79
+ quiet: this.quiet,
80
+ strategy: "sequential",
81
+ });
82
+ }
83
+ else {
84
+ console.warn("Scope is in error, skipping finalize");
85
+ }
67
86
  }
68
87
  async run(fn) {
69
88
  return scopeStorage.run(this, () => fn(this));
package/lib/state.js CHANGED
@@ -39,7 +39,12 @@ export class FileSystemStateStore {
39
39
  async get(key) {
40
40
  try {
41
41
  const content = await fs.promises.readFile(await this.getPath(key), "utf8");
42
- return (await deserialize(this.scope, JSON.parse(content)));
42
+ const state = (await deserialize(this.scope, JSON.parse(content)));
43
+ if (state.output === undefined) {
44
+ state.output = {};
45
+ }
46
+ state.output.Scope = this.scope;
47
+ return state;
43
48
  }
44
49
  catch (error) {
45
50
  if (error.code === "ENOENT") {
@@ -0,0 +1 @@
1
+ export declare function rm(path: string): Promise<void>;
package/lib/util/rm.js ADDED
@@ -0,0 +1,11 @@
1
+ import fs from "fs/promises";
2
+ export async function rm(path) {
3
+ try {
4
+ await fs.rm(path, { recursive: true, force: true });
5
+ }
6
+ catch (error) {
7
+ if (error.code !== "ENOENT") {
8
+ throw error;
9
+ }
10
+ }
11
+ }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "alchemy",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "module": "./lib/index.js",
6
6
  "scripts": {
7
- "publish:npm": "rm -rf ./*.tsbuildinfo && rm -rf ./lib && tsc -b && npm publish"
7
+ "publish:npm": "cp ../README.md . && rm -rf ./*.tsbuildinfo && rm -rf ./lib && tsc -b && npm publish && rm README.md"
8
8
  },
9
9
  "files": ["lib", "src"],
10
10
  "exports": {
@@ -15,6 +15,7 @@
15
15
  "./esbuild": "./lib/esbuild/index.js",
16
16
  "./fs": "./lib/fs/index.js",
17
17
  "./github": "./lib/github/index.js",
18
+ "./project": "./lib/project/index.js",
18
19
  "./stripe": "./lib/stripe/index.js",
19
20
  "./test/bun": "./lib/test/bun.js"
20
21
  },
package/src/alchemy.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { destroy } from "./destroy";
1
+ import { DestroyedSignal, destroy } from "./destroy";
2
2
  import { Scope } from "./scope";
3
3
  import { secret } from "./secret";
4
4
  import type { StateStoreType } from "./state";
@@ -116,5 +116,12 @@ async function run<T>(
116
116
  (this: Scope, scope: Scope) => Promise<T>,
117
117
  ]);
118
118
  await using scope = alchemy.scope(id, options);
119
- return await fn.bind(scope)(scope);
119
+ try {
120
+ return await fn.bind(scope)(scope);
121
+ } catch (error) {
122
+ if (!(error instanceof DestroyedSignal)) {
123
+ scope.fail();
124
+ }
125
+ throw error;
126
+ }
120
127
  }