alchemy 0.12.17 → 0.12.19

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 (62) hide show
  1. package/lib/cloudflare/ai.d.ts +11 -0
  2. package/lib/cloudflare/ai.d.ts.map +1 -0
  3. package/lib/cloudflare/ai.js +12 -0
  4. package/lib/cloudflare/ai.js.map +1 -0
  5. package/lib/cloudflare/bindings.d.ts +2 -1
  6. package/lib/cloudflare/bindings.d.ts.map +1 -1
  7. package/lib/cloudflare/bound.d.ts +2 -1
  8. package/lib/cloudflare/bound.d.ts.map +1 -1
  9. package/lib/cloudflare/bundle/external.d.ts.map +1 -0
  10. package/lib/cloudflare/{external.js → bundle/external.js} +2 -0
  11. package/lib/cloudflare/bundle/external.js.map +1 -0
  12. package/lib/cloudflare/bundle/hybrid-nodejs-compat.d.ts +11 -0
  13. package/lib/cloudflare/bundle/hybrid-nodejs-compat.d.ts.map +1 -0
  14. package/lib/cloudflare/bundle/hybrid-nodejs-compat.js +198 -0
  15. package/lib/cloudflare/bundle/hybrid-nodejs-compat.js.map +1 -0
  16. package/lib/cloudflare/bundle/local-dev-cloudflare-shim.d.ts.map +1 -0
  17. package/lib/cloudflare/bundle/local-dev-cloudflare-shim.js.map +1 -0
  18. package/lib/cloudflare/index.d.ts +3 -2
  19. package/lib/cloudflare/index.d.ts.map +1 -1
  20. package/lib/cloudflare/index.js +3 -2
  21. package/lib/cloudflare/index.js.map +1 -1
  22. package/lib/cloudflare/worker.d.ts.map +1 -1
  23. package/lib/cloudflare/worker.js +17 -6
  24. package/lib/cloudflare/worker.js.map +1 -1
  25. package/lib/cloudflare/wrangler.json.d.ts +6 -0
  26. package/lib/cloudflare/wrangler.json.d.ts.map +1 -1
  27. package/lib/cloudflare/wrangler.json.js +8 -0
  28. package/lib/cloudflare/wrangler.json.js.map +1 -1
  29. package/lib/neon/project.d.ts +2 -2
  30. package/lib/neon/project.d.ts.map +1 -1
  31. package/lib/neon/project.js +1 -1
  32. package/lib/neon/project.js.map +1 -1
  33. package/lib/serde.d.ts.map +1 -1
  34. package/lib/serde.js +4 -0
  35. package/lib/serde.js.map +1 -1
  36. package/lib/test/prune.js +1 -0
  37. package/lib/test/prune.js.map +1 -1
  38. package/lib/util/dedent.d.ts +18 -0
  39. package/lib/util/dedent.d.ts.map +1 -0
  40. package/lib/util/dedent.js +61 -0
  41. package/lib/util/dedent.js.map +1 -0
  42. package/package.json +3 -1
  43. package/src/cloudflare/ai.ts +12 -0
  44. package/src/cloudflare/bindings.ts +2 -0
  45. package/src/cloudflare/bound.ts +4 -1
  46. package/src/cloudflare/{external.ts → bundle/external.ts} +2 -0
  47. package/src/cloudflare/bundle/hybrid-nodejs-compat.ts +249 -0
  48. package/src/cloudflare/index.ts +3 -2
  49. package/src/cloudflare/worker.ts +22 -7
  50. package/src/cloudflare/wrangler.json.ts +14 -0
  51. package/src/neon/project.ts +4 -4
  52. package/src/serde.ts +3 -0
  53. package/src/test/prune.ts +1 -0
  54. package/src/util/dedent.ts +71 -0
  55. package/lib/cloudflare/external.d.ts.map +0 -1
  56. package/lib/cloudflare/external.js.map +0 -1
  57. package/lib/cloudflare/local-dev-cloudflare-shim.d.ts.map +0 -1
  58. package/lib/cloudflare/local-dev-cloudflare-shim.js.map +0 -1
  59. /package/lib/cloudflare/{external.d.ts → bundle/external.d.ts} +0 -0
  60. /package/lib/cloudflare/{local-dev-cloudflare-shim.d.ts → bundle/local-dev-cloudflare-shim.d.ts} +0 -0
  61. /package/lib/cloudflare/{local-dev-cloudflare-shim.js → bundle/local-dev-cloudflare-shim.js} +0 -0
  62. /package/src/cloudflare/{local-dev-cloudflare-shim.ts → bundle/local-dev-cloudflare-shim.ts} +0 -0
@@ -1,5 +1,6 @@
1
1
  export * from "./account-api-token.js";
2
2
  export * from "./ai-gateway.js";
3
+ export * from "./ai.js";
3
4
  export * from "./api-error.js";
4
5
  export * from "./api.js";
5
6
  export * from "./assets.js";
@@ -7,14 +8,14 @@ export * from "./bindings.js";
7
8
  export * from "./bound.js";
8
9
  export * from "./browser-rendering.js";
9
10
  export * from "./bucket.js";
11
+ export * from "./bundle/external.js";
12
+ export * from "./bundle/local-dev-cloudflare-shim.js";
10
13
  export * from "./custom-domain.js";
11
14
  export * from "./d1-database.js";
12
15
  export * from "./dns-records.js";
13
16
  export * from "./durable-object-namespace.js";
14
- export * from "./external.js";
15
17
  export * from "./hyperdrive.js";
16
18
  export * from "./kv-namespace.js";
17
- export * from "./local-dev-cloudflare-shim.js";
18
19
  export * from "./nuxt.js";
19
20
  export * from "./permission-groups.js";
20
21
  export * from "./pipeline.js";
@@ -15,9 +15,10 @@ import {
15
15
  import type { Assets } from "./assets.js";
16
16
  import type { Bindings, WorkerBindingSpec } from "./bindings.js";
17
17
  import type { Bound } from "./bound.js";
18
+ import { external } from "./bundle/external.js";
19
+ import { nodejsHybridPlugin } from "./bundle/hybrid-nodejs-compat.js";
18
20
  import type { DurableObjectNamespace } from "./durable-object-namespace.js";
19
21
  import { type EventSource, isQueueEventSource } from "./event-source.js";
20
- import { external } from "./external.js";
21
22
  import {
22
23
  QueueConsumer,
23
24
  deleteQueueConsumer,
@@ -364,8 +365,12 @@ export const Worker = Resource(
364
365
 
365
366
  const oldBindings = await this.get<Bindings>("bindings");
366
367
 
368
+ const compatibilityDate = props.compatibilityDate ?? "2025-04-20";
369
+ const compatibilityFlags = props.compatibilityFlags ?? [];
370
+
367
371
  // Get the script content - either from props.script, or by bundling
368
- const scriptContent = props.script ?? (await bundleWorkerScript(props));
372
+ const scriptContent =
373
+ props.script ?? (await bundleWorkerScript(compatibilityDate, props));
369
374
 
370
375
  // Find any assets bindings
371
376
  const assetsBindings: { name: string; assets: Assets }[] = [];
@@ -399,9 +404,6 @@ export const Worker = Resource(
399
404
  );
400
405
  }
401
406
 
402
- const compatibilityDate = props.compatibilityDate ?? "2025-04-20";
403
- const compatibilityFlags = props.compatibilityFlags ?? [];
404
-
405
407
  // Prepare metadata with bindings
406
408
  const scriptMetadata = await prepareWorkerMetadata(
407
409
  this,
@@ -822,6 +824,11 @@ async function prepareWorkerMetadata<B extends Bindings>(
822
824
  type: "browser",
823
825
  name: bindingName,
824
826
  });
827
+ } else if (binding.type === "ai") {
828
+ meta.bindings.push({
829
+ type: "ai",
830
+ name: bindingName,
831
+ });
825
832
  } else {
826
833
  // @ts-expect-error - we should never reach here
827
834
  throw new Error(`Unsupported binding type: ${binding.type}`);
@@ -923,13 +930,16 @@ async function assertWorkerDoesNotExist<B extends Bindings>(
923
930
  }
924
931
  }
925
932
 
926
- async function bundleWorkerScript<B extends Bindings>(props: WorkerProps) {
933
+ async function bundleWorkerScript<B extends Bindings>(
934
+ compatibilityDate: string,
935
+ props: WorkerProps<B>
936
+ ) {
927
937
  const bundle = await Bundle("bundle", {
928
938
  entryPoint: props.entrypoint!,
929
939
  format: props.format === "cjs" ? "cjs" : "esm", // Use the specified format or default to ESM
930
940
  target: "esnext",
931
941
  platform: "neutral",
932
- minify: true,
942
+ minify: false,
933
943
  ...(props.bundle || {}),
934
944
  options: {
935
945
  ...(props.bundle?.options || {}),
@@ -938,6 +948,11 @@ async function bundleWorkerScript<B extends Bindings>(props: WorkerProps) {
938
948
  ".sql": "text",
939
949
  ".json": "json",
940
950
  },
951
+ plugins:
952
+ compatibilityDate >= "2024-09-23" &&
953
+ props.compatibilityFlags?.find((flag) => flag === "nodejs_compat")
954
+ ? [await nodejsHybridPlugin()]
955
+ : [],
941
956
  },
942
957
  external: [
943
958
  ...external,
@@ -150,6 +150,13 @@ export interface WranglerJsonSpec {
150
150
  */
151
151
  routes?: string[];
152
152
 
153
+ /**
154
+ * AI bindings
155
+ */
156
+ ai?: {
157
+ binding: string;
158
+ };
159
+
153
160
  /**
154
161
  * Browser bindings
155
162
  */
@@ -400,6 +407,13 @@ function processBindings(
400
407
  spec.browser = {
401
408
  binding: bindingName,
402
409
  };
410
+ } else if (binding.type === "ai") {
411
+ if (spec.ai) {
412
+ throw new Error(`AI already bound to ${spec.ai.binding}`);
413
+ }
414
+ spec.ai = {
415
+ binding: bindingName,
416
+ };
403
417
  }
404
418
  }
405
419
 
@@ -38,9 +38,9 @@ export interface NeonProjectProps extends NeonApiOptions {
38
38
 
39
39
  /**
40
40
  * PostgreSQL version to use
41
- * @default 15
41
+ * @default 16
42
42
  */
43
- pg_version?: 14 | 15 | 16;
43
+ pg_version?: 14 | 15 | 16 | 17;
44
44
 
45
45
  /**
46
46
  * Whether to create a default branch and endpoint
@@ -607,7 +607,7 @@ export const NeonProject = Resource(
607
607
  id: response.project.id,
608
608
  name: response.project.name,
609
609
  region_id: response.project.region_id as NeonRegion,
610
- pg_version: response.project.pg_version as 14 | 15 | 16,
610
+ pg_version: response.project.pg_version as 14 | 15 | 16 | 17,
611
611
  created_at: response.project.created_at,
612
612
  updated_at: response.project.updated_at,
613
613
  proxy_host: response.project.proxy_host,
@@ -646,7 +646,7 @@ async function createNewProject(
646
646
  project: {
647
647
  name: props.name,
648
648
  region_id: props.region_id || "aws-us-east-1",
649
- pg_version: props.pg_version || 15,
649
+ pg_version: props.pg_version || 16,
650
650
  default_endpoint: defaultEndpoint,
651
651
  branch: defaultEndpoint
652
652
  ? { name: props.default_branch_name || "main" }
package/src/serde.ts CHANGED
@@ -51,6 +51,9 @@ export async function serialize(
51
51
  ])
52
52
  )
53
53
  );
54
+ } else if (typeof value === "function") {
55
+ // can't serialize functions
56
+ return undefined;
54
57
  }
55
58
  return value;
56
59
  }
package/src/test/prune.ts CHANGED
@@ -130,6 +130,7 @@ async function getDependencies(testFile: string): Promise<Set<string>> {
130
130
  bundle: true,
131
131
  metafile: true,
132
132
  external: ["@cloudflare/workers-types", "bun:test"],
133
+ logLevel: "error",
133
134
  });
134
135
 
135
136
  if (!result.metafile) {
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Removes common indentation from template literals to make them more readable in code.
3
+ * This allows writing multi-line strings with proper indentation in the source code
4
+ * while removing that indentation in the output string.
5
+ *
6
+ * @example
7
+ * const message = dedent`
8
+ * This is a multi-line string
9
+ * that will have its indentation removed.
10
+ * This line has extra indentation that will be preserved.
11
+ * `;
12
+ * // Result:
13
+ * // "This is a multi-line string
14
+ * // that will have its indentation removed.
15
+ * // This line has extra indentation that will be preserved."
16
+ */
17
+ export function dedent(
18
+ strings: TemplateStringsArray,
19
+ ...values: any[]
20
+ ): string {
21
+ // Combine the template strings and values
22
+ let result = strings.reduce((acc, str, i) => {
23
+ return acc + str + (values[i] !== undefined ? values[i] : "");
24
+ }, "");
25
+
26
+ // Split into lines
27
+ let lines = result.split("\n");
28
+
29
+ // Remove ALL leading blank/whitespace-only lines
30
+ while (lines.length > 0 && lines[0].trim() === "") {
31
+ lines.shift();
32
+ }
33
+
34
+ // Remove ALL trailing blank/whitespace-only lines
35
+ while (lines.length > 0 && lines[lines.length - 1].trim() === "") {
36
+ lines.pop();
37
+ }
38
+
39
+ // If there are no lines left after trimming, return an empty string
40
+ if (lines.length === 0) {
41
+ return "";
42
+ }
43
+
44
+ // Find the minimum indentation level (excluding empty/whitespace lines)
45
+ const minIndent = lines
46
+ .filter((line) => line.trim().length > 0) // Only consider non-blank lines for indent calculation
47
+ .reduce((min, line) => {
48
+ const indent = line.match(/^[ \t]*/)?.[0].length || 0;
49
+ // Handle potentially infinite min if all lines are blank (though handled by early return)
50
+ return indent < min ? indent : min;
51
+ }, Infinity);
52
+
53
+ // If minIndent remains Infinity (only blank lines existed), return empty string.
54
+ // This case should be caught by the lines.length check above, but belt-and-suspenders.
55
+ if (minIndent === Infinity) {
56
+ return "";
57
+ }
58
+
59
+ // Remove the common indentation from each line
60
+ const dedented = lines.map((line) => {
61
+ // Preserve internal blank lines as empty strings, don't try to substring them
62
+ if (line.trim().length === 0) {
63
+ return "";
64
+ }
65
+ // Apply dedent only to lines with content
66
+ return line.substring(minIndent);
67
+ });
68
+
69
+ // Join the lines back together
70
+ return dedented.join("\n");
71
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"external.d.ts","sourceRoot":"","sources":["../../src/cloudflare/external.ts"],"names":[],"mappings":"AAyBA,eAAO,MAAM,QAAQ,UAIpB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"external.js","sourceRoot":"","sources":["../../src/cloudflare/external.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,MAAM,aAAa,GAAG;IACpB,kBAAkB;IAClB,aAAa;IACb,aAAa;IACb,cAAc;IACd,aAAa;IACb,0BAA0B;IAC1B,UAAU;IACV,aAAa;IACb,gBAAgB;IAChB,UAAU;IACV,WAAW;IACX,iBAAiB;IACjB,cAAc;IACd,kBAAkB;IAClB,aAAa;IACb,qBAAqB;IACrB,aAAa;IACb,UAAU,EAAE,sBAAsB;IAClC,UAAU;IACV,WAAW;IACX,WAAW;CACZ,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,GAAG,aAAa;IAChB,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5C,oBAAoB;CACrB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"local-dev-cloudflare-shim.d.ts","sourceRoot":"","sources":["../../src/cloudflare/local-dev-cloudflare-shim.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,mCAAmC;;;;6BAKjC,MAAM;wBAGX,MAAM;EAUlB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"local-dev-cloudflare-shim.js","sourceRoot":"","sources":["../../src/cloudflare/local-dev-cloudflare-shim.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,mCAAmC;IACjD,OAAO;QACL,IAAI,EAAE,6BAA6B;QACnC,KAAK,EAAE,OAAO,EAAE,WAAW;QAC3B,OAAO,EAAE,KAAK;QACd,SAAS,CAAC,EAAU;YAClB,IAAI,EAAE,KAAK,oBAAoB;gBAAE,OAAO,EAAE,CAAC,CAAC,0BAA0B;QACxE,CAAC;QACD,IAAI,CAAC,EAAU;YACb,IAAI,EAAE,KAAK,oBAAoB;gBAC7B,OAAO;;;;;CAKd,CAAC;QACE,CAAC;KACO,CAAC;AACb,CAAC"}