alchemy 2.0.0-beta.24 → 2.0.0-beta.25

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.
package/bin/alchemy.js CHANGED
@@ -145,7 +145,7 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
145
145
 
146
146
  //#endregion
147
147
  //#region package.json
148
- var version = "2.0.0-beta.24";
148
+ var version = "2.0.0-beta.25";
149
149
 
150
150
  //#endregion
151
151
  //#region src/AlchemyContext.ts
@@ -49622,7 +49622,7 @@ const readAssets = Effect.fnUntraced(function* (props) {
49622
49622
  const path$1 = yield* Path$1.Path;
49623
49623
  const resolvedDirectory = path$1.resolve(props.directory);
49624
49624
  const [files, ignore, _headers, _redirects] = yield* Effect.all([
49625
- fs$3.readDirectory(resolvedDirectory, { recursive: true }).pipe(Effect.catchTag("PlatformError", (e) => e.reason._tag === "NotFound" ? Effect.succeed([]) : Effect.fail(e))),
49625
+ fs$3.readDirectory(resolvedDirectory, { recursive: true }),
49626
49626
  maybeReadString(path$1.join(resolvedDirectory, ".assetsignore")),
49627
49627
  maybeReadString(path$1.join(resolvedDirectory, "_headers")),
49628
49628
  maybeReadString(path$1.join(resolvedDirectory, "_redirects"))
@@ -51246,55 +51246,49 @@ const LiveWorkerProvider = () => effect(Worker, Effect.gen(function* () {
51246
51246
  }
51247
51247
  return yield* Effect.die(`Could not infer Cloudflare Zone for hostname "${hostname}". Ensure the parent zone exists in this account.`);
51248
51248
  });
51249
- const reconcileDomains = (scriptName, desired, previous) => Effect.gen(function* () {
51249
+ const reconcileDomains = (scriptName, desired, _previous) => Effect.gen(function* () {
51250
+ const liveAll = yield* listDomains({
51251
+ accountId,
51252
+ service: scriptName
51253
+ }).pipe(Effect.map((r) => (r.result ?? []).flatMap((d) => d.id && d.hostname && d.zoneId ? [{
51254
+ id: d.id,
51255
+ hostname: d.hostname,
51256
+ zoneId: d.zoneId,
51257
+ service: d.service ?? void 0
51258
+ }] : [])), Effect.catch(() => Effect.succeed([])));
51250
51259
  const desiredSet = new Set(desired);
51251
- const toRemove = previous.filter((p$1) => !desiredSet.has(p$1.hostname));
51260
+ const liveByHostname = new Map(liveAll.map((d) => [d.hostname, d]));
51261
+ const toRemove = liveAll.filter((d) => !desiredSet.has(d.hostname));
51252
51262
  yield* Effect.all(toRemove.map((d) => deleteDomain({
51253
51263
  accountId,
51254
51264
  domainId: d.id
51255
51265
  }).pipe(Effect.catchTag("DomainNotFound", () => Effect.void))), { concurrency: "unbounded" });
51256
51266
  if (desired.length === 0) return [];
51257
- const adoptEnabled = yield* Effect.serviceOption(AdoptPolicy).pipe(Effect.map(Option.getOrElse(() => false)));
51258
51267
  const zoneCache = /* @__PURE__ */ new Map();
51259
- /**
51260
- * Attach `hostname` to `scriptName`, recovering from a "hostname
51261
- * already in use" conflict when adoption is enabled.
51262
- *
51263
- * The Cloudflare API rejects a `PUT /workers/domains` whose
51264
- * hostname is already registered (even when the existing entry
51265
- * points at the same Worker, which is exactly what happens
51266
- * after a state-store wipe). The SDK surfaces this as the
51267
- * unmatched `UnknownCloudflareError` channel because there's
51268
- * no dedicated error tag for it. With adoption opted-in we
51269
- * list domains for the hostname; if the existing entry
51270
- * already targets *this* Worker we adopt it in place. We
51271
- * never transfer a hostname off another Worker — that would
51272
- * silently re-route someone else's traffic.
51273
- */
51274
51268
  const attachDomain = Effect.fnUntraced(function* (hostname) {
51269
+ const live = liveByHostname.get(hostname);
51270
+ if (live) return {
51271
+ hostname: live.hostname,
51272
+ id: live.id,
51273
+ zoneId: live.zoneId
51274
+ };
51275
+ const otherOwner = yield* listDomains({
51276
+ accountId,
51277
+ hostname
51278
+ }).pipe(Effect.map((r) => (r.result ?? []).find((d) => d.hostname === hostname && d.service !== scriptName)), Effect.catch(() => Effect.succeed(void 0)));
51279
+ if (otherOwner?.id) return yield* Effect.die(/* @__PURE__ */ new Error(`Cannot attach hostname '${hostname}' to Worker '${scriptName}': it is already attached to Worker '${otherOwner.service ?? "<unknown>"}'. Detach it from that Worker first, or pick a different hostname.`));
51275
51280
  const zoneId = yield* inferZoneIdForHostname(hostname, zoneCache);
51276
- return yield* putDomain({
51281
+ const res = yield* putDomain({
51277
51282
  accountId,
51278
51283
  hostname,
51279
51284
  service: scriptName,
51280
51285
  zoneId
51281
- }).pipe(Effect.map((res) => ({
51286
+ });
51287
+ return {
51282
51288
  hostname,
51283
51289
  id: res.id ?? "",
51284
51290
  zoneId: res.zoneId ?? zoneId
51285
- })), Effect.catchTag("UnknownCloudflareError", (err) => adoptEnabled && /already in use/i.test(err.message) ? adoptDomainIfSameService(hostname, zoneId, err) : Effect.fail(err)));
51286
- });
51287
- const adoptDomainIfSameService = Effect.fnUntraced(function* (hostname, zoneId, originalError) {
51288
- const existing = yield* listDomains({
51289
- accountId,
51290
- hostname
51291
- }).pipe(Effect.map((r) => (r.result ?? []).find((d) => d.hostname === hostname)));
51292
- if (existing?.id && existing.service === scriptName) return {
51293
- hostname,
51294
- id: existing.id,
51295
- zoneId: existing.zoneId ?? zoneId
51296
51291
  };
51297
- return yield* Effect.die(/* @__PURE__ */ new Error(`Cannot attach hostname '${hostname}' to Worker '${scriptName}': it is already attached to Worker '${existing?.service ?? "<unknown>"}'. Detach it from that Worker first, or pick a different hostname. (Cloudflare reported: ${originalError.message})`));
51298
51292
  });
51299
51293
  return yield* Effect.all(desired.map(attachDomain), { concurrency: "unbounded" });
51300
51294
  });
@@ -51333,13 +51327,10 @@ const LiveWorkerProvider = () => effect(Worker, Effect.gen(function* () {
51333
51327
  });
51334
51328
  const prepareAssets = Effect.fnUntraced(function* (assets) {
51335
51329
  if (!assets) return;
51336
- if (typeof assets === "object" && "path" in assets && "hash" in assets) return {
51337
- ...yield* readAssets({
51338
- directory: assets.path,
51339
- config: assets.config
51340
- }),
51341
- hash: assets.hash
51342
- };
51330
+ if (typeof assets === "object" && "path" in assets && "hash" in assets) return yield* readAssets({
51331
+ directory: assets.path,
51332
+ config: assets.config
51333
+ });
51343
51334
  return yield* readAssets(typeof assets === "string" ? { directory: assets } : assets);
51344
51335
  });
51345
51336
  const getCompatibility$1 = (props) => ({
@@ -51552,20 +51543,14 @@ ${[...hasDoClasses ? ["const DurableObjectBridge = makeDurableObjectBridge(Durab
51552
51543
  const metadataBindings = bindings.flatMap((b) => b.data.bindings ?? []);
51553
51544
  const expectedDurableObjectClassNames = getExpectedDurableObjectClassNames(metadataBindings);
51554
51545
  let metadataAssets;
51555
- let keepAssets = false;
51546
+ const keepAssets = false;
51556
51547
  if (assets) {
51557
- if (output?.hash?.assets !== assets.hash) {
51558
- yield* Effect.logInfo(`Cloudflare Worker ${olds ? "update" : "create"}: uploading assets for ${name}`);
51559
- const { jwt } = yield* uploadAssets(accountId, name, assets, session);
51560
- metadataAssets = {
51561
- jwt,
51562
- config: assets.config
51563
- };
51564
- } else {
51565
- yield* Effect.logInfo(`Cloudflare Worker update: reusing existing assets for ${name}`);
51566
- metadataAssets = { config: assets.config };
51567
- keepAssets = true;
51568
- }
51548
+ yield* Effect.logInfo(`Cloudflare Worker ${olds ? "update" : "create"}: uploading assets for ${name}`);
51549
+ const { jwt } = yield* uploadAssets(accountId, name, assets, session);
51550
+ metadataAssets = {
51551
+ jwt,
51552
+ config: assets.config
51553
+ };
51569
51554
  metadataBindings.push({
51570
51555
  type: "assets",
51571
51556
  name: "ASSETS"
@@ -51721,7 +51706,7 @@ ${[...hasDoClasses ? ["const DurableObjectBridge = makeDurableObjectBridge(Durab
51721
51706
  });
51722
51707
  const hasChanged = Effect.fnUntraced(function* (id, props, output) {
51723
51708
  if (props.vite) return (yield* hashDirectory(props.vite)) !== output.hash?.input;
51724
- const [assetsHash, bundleHash] = yield* Effect.all(["assets" in output && output.hash?.assets ? Effect.succeed(output.hash.assets) : prepareAssets(props.assets).pipe(Effect.map((a) => a?.hash)), prepareBundle(id, props).pipe(Effect.map((b) => b.hash))], { concurrency: "unbounded" });
51709
+ const [assetsHash, bundleHash] = yield* Effect.all([prepareAssets(props.assets).pipe(Effect.map((a) => a?.hash)), prepareBundle(id, props).pipe(Effect.map((b) => b.hash))], { concurrency: "unbounded" });
51725
51710
  return assetsHash !== output.hash?.assets || bundleHash !== output.hash?.bundle;
51726
51711
  });
51727
51712
  return Worker.Provider.of({