wrangler 2.12.2 → 2.13.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 (53) hide show
  1. package/package.json +4 -3
  2. package/src/__tests__/configuration.test.ts +14 -12
  3. package/src/__tests__/d1/execute.test.ts +2 -0
  4. package/src/__tests__/d1/migrate.test.ts +2 -0
  5. package/src/__tests__/delete.test.ts +6 -0
  6. package/src/__tests__/deployments.test.ts +335 -95
  7. package/src/__tests__/dev.test.tsx +71 -56
  8. package/src/__tests__/helpers/mock-console.ts +6 -0
  9. package/src/__tests__/helpers/msw/handlers/deployments.ts +70 -3
  10. package/src/__tests__/helpers/msw/index.ts +4 -2
  11. package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
  12. package/src/__tests__/index.test.ts +10 -4
  13. package/src/__tests__/init.test.ts +127 -96
  14. package/src/__tests__/jest.setup.ts +4 -0
  15. package/src/__tests__/kv.test.ts +9 -9
  16. package/src/__tests__/middleware.scheduled.test.ts +2 -2
  17. package/src/__tests__/middleware.test.ts +2 -2
  18. package/src/__tests__/mtls-certificates.test.ts +5 -2
  19. package/src/__tests__/pages/deployment-list.test.ts +2 -0
  20. package/src/__tests__/pages/project-list.test.ts +2 -0
  21. package/src/__tests__/pages/project-upload.test.ts +43 -24
  22. package/src/__tests__/pages/publish.test.ts +69 -69
  23. package/src/__tests__/publish.test.ts +275 -155
  24. package/src/__tests__/pubsub.test.ts +3 -0
  25. package/src/__tests__/queues.test.ts +5 -2
  26. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  27. package/src/__tests__/worker-namespace.test.ts +1 -0
  28. package/src/bundle.ts +10 -0
  29. package/src/config/environment.ts +3 -0
  30. package/src/config/validation.ts +3 -1
  31. package/src/create-worker-upload-form.ts +1 -1
  32. package/src/d1/backups.tsx +15 -11
  33. package/src/d1/create.tsx +20 -16
  34. package/src/d1/execute.tsx +21 -18
  35. package/src/d1/list.tsx +2 -2
  36. package/src/d1/migrations/apply.tsx +35 -29
  37. package/src/d1/migrations/create.tsx +15 -12
  38. package/src/d1/migrations/list.tsx +10 -7
  39. package/src/deployments.ts +260 -8
  40. package/src/index.ts +75 -22
  41. package/src/init.ts +144 -135
  42. package/src/metrics/send-event.ts +2 -1
  43. package/src/pages/deployments.tsx +3 -5
  44. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  45. package/src/pages/projects.tsx +2 -5
  46. package/src/pages/upload.tsx +29 -9
  47. package/src/publish/publish.ts +7 -18
  48. package/src/queues/cli/commands/consumer/add.ts +6 -0
  49. package/src/queues/client.ts +1 -0
  50. package/src/utils/render.ts +93 -0
  51. package/templates/d1-beta-facade.js +3 -0
  52. package/wrangler-dist/cli.d.ts +2 -0
  53. package/wrangler-dist/cli.js +8174 -7873
@@ -12,6 +12,7 @@ import {
12
12
  import { fetchListResult, fetchResult } from "../cfetch";
13
13
  import { printBindings } from "../config";
14
14
  import { createWorkerUploadForm } from "../create-worker-upload-form";
15
+ import { addHyphens } from "../deployments";
15
16
  import { confirm } from "../dialogs";
16
17
  import { getMigrationsToUpload } from "../durable";
17
18
  import { logger } from "../logger";
@@ -30,7 +31,6 @@ import type {
30
31
  ZoneNameRoute,
31
32
  CustomDomainRoute,
32
33
  } from "../config/environment";
33
- import type { DeploymentListResult } from "../deployments";
34
34
  import type { Entry } from "../entry";
35
35
  import type { PutConsumerBody } from "../queues/client";
36
36
  import type { AssetPaths } from "../sites";
@@ -335,7 +335,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
335
335
 
336
336
  const jsxFactory = props.jsxFactory || config.jsx_factory;
337
337
  const jsxFragment = props.jsxFragment || config.jsx_fragment;
338
- const keepVars = props.keepVars ?? config.keep_vars;
338
+ const keepVars = props.keepVars || config.keep_vars;
339
339
 
340
340
  const minify = props.minify ?? config.minify;
341
341
 
@@ -401,7 +401,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
401
401
  : `/accounts/${accountId}/workers/scripts/${scriptName}`;
402
402
 
403
403
  let available_on_subdomain: boolean | undefined = undefined; // we'll set this later
404
- let scriptTag: string | null = null;
404
+ let deploymentId: string | null = null;
405
405
 
406
406
  const { format } = props.entry;
407
407
 
@@ -632,7 +632,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
632
632
  id: string | null;
633
633
  etag: string | null;
634
634
  pipeline_hash: string | null;
635
- tag: string | null;
635
+ deployment_id: string | null;
636
636
  }>(
637
637
  workerUrl,
638
638
  {
@@ -649,7 +649,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
649
649
  );
650
650
 
651
651
  available_on_subdomain = result.available_on_subdomain;
652
- scriptTag = result.tag;
652
+ deploymentId = addHyphens(result.deployment_id) ?? result.deployment_id;
653
653
 
654
654
  if (config.first_party_worker) {
655
655
  // Print some useful information returned after publishing
@@ -839,19 +839,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
839
839
  logger.log("No publish targets for", workerName, formatTime(deployMs));
840
840
  }
841
841
 
842
- try {
843
- const deploymentsList = await fetchResult<DeploymentListResult>(
844
- `/accounts/${accountId}/workers/deployments/by-script/${scriptTag}`
845
- );
846
-
847
- logger.log("Current Deployment ID:", deploymentsList.latest.id);
848
- } catch (e) {
849
- if ((e as { code: number }).code === 10023) {
850
- // TODO: remove this try/catch once deployments is completely rolled out
851
- } else {
852
- throw e;
853
- }
854
- }
842
+ logger.log("Current Deployment ID:", deploymentId);
855
843
  }
856
844
 
857
845
  export function helpIfErrorIsSizeOrScriptStartup(
@@ -1060,6 +1048,7 @@ function updateQueueConsumers(config: Config): Promise<string[]>[] {
1060
1048
  max_wait_time_ms: consumer.max_batch_timeout
1061
1049
  ? 1000 * consumer.max_batch_timeout
1062
1050
  : undefined,
1051
+ max_concurrency: consumer.max_concurrency,
1063
1052
  },
1064
1053
  };
1065
1054
 
@@ -37,6 +37,11 @@ export function options(yargs: CommonYargsArgv) {
37
37
  type: "string",
38
38
  describe: "Queue to send messages that failed to be consumed",
39
39
  },
40
+ "max-concurrency": {
41
+ type: "number",
42
+ describe:
43
+ "The maximum number of concurrent consumer Worker invocations. Must be a positive integer",
44
+ },
40
45
  });
41
46
  }
42
47
 
@@ -55,6 +60,7 @@ export async function handler(
55
60
  max_wait_time_ms: args.batchTimeout // API expects milliseconds
56
61
  ? 1000 * args.batchTimeout
57
62
  : undefined,
63
+ max_concurrency: args.maxConcurrency,
58
64
  },
59
65
  dead_letter_queue: args.deadLetterQueue,
60
66
  };
@@ -90,6 +90,7 @@ export interface ConsumerSettings {
90
90
  batch_size?: number;
91
91
  max_retries?: number;
92
92
  max_wait_time_ms?: number;
93
+ max_concurrency?: number | null;
93
94
  }
94
95
 
95
96
  export interface ConsumerResponse extends PostConsumerBody {
@@ -0,0 +1,93 @@
1
+ import { EventEmitter } from "events";
2
+ import { render as inkRender } from "ink";
3
+ import type { ReactElement } from "react";
4
+ import type { WriteStream } from "tty";
5
+
6
+ export function renderToString(tree: ReactElement): string {
7
+ const { output, cleanup } = render(tree);
8
+ cleanup();
9
+ return output;
10
+ }
11
+
12
+ // The code below is mostly copied from ink-render-string.
13
+ // See https://github.com/zhanwang626/ink-render-string.git.
14
+
15
+ // MIT License
16
+
17
+ // Copyright (c) 2021 Zhan Wang
18
+
19
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
20
+ // of this software and associated documentation files (the "Software"), to deal
21
+ // in the Software without restriction, including without limitation the rights
22
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23
+ // copies of the Software, and to permit persons to whom the Software is
24
+ // furnished to do so, subject to the following conditions:
25
+
26
+ // The above copyright notice and this permission notice shall be included in all
27
+ // copies or substantial portions of the Software.
28
+
29
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35
+ // SOFTWARE.
36
+
37
+ interface Instance {
38
+ output: string;
39
+ unmount: () => void;
40
+ cleanup: () => void;
41
+ stdout: OutputStream;
42
+ stderr: OutputStream;
43
+ frames: string[];
44
+ }
45
+
46
+ const LASTFRAME_UNDEFINED = "value of stdout.lastframe() is undefined";
47
+
48
+ export class OutputStream extends EventEmitter {
49
+ readonly frames: string[] = [];
50
+ private _lastFrame?: string;
51
+
52
+ get columns(): number {
53
+ return this._originalStream.columns;
54
+ }
55
+ get rows(): number {
56
+ return this._originalStream.rows;
57
+ }
58
+
59
+ constructor(private _originalStream: WriteStream) {
60
+ super();
61
+ }
62
+
63
+ write = (frame: string) => {
64
+ this.frames.push(frame);
65
+ this._lastFrame = frame;
66
+ };
67
+
68
+ lastFrame = () => {
69
+ return this._lastFrame;
70
+ };
71
+ }
72
+
73
+ export const render = (tree: ReactElement): Instance => {
74
+ const stdout = new OutputStream(process.stdout);
75
+ const stderr = new OutputStream(process.stderr);
76
+
77
+ const instance = inkRender(tree, {
78
+ stdout: stdout as unknown as WriteStream,
79
+ stderr: stderr as unknown as WriteStream,
80
+ debug: true,
81
+ exitOnCtrlC: false,
82
+ patchConsole: false,
83
+ });
84
+
85
+ return {
86
+ output: stdout.lastFrame() || LASTFRAME_UNDEFINED,
87
+ stdout,
88
+ stderr,
89
+ cleanup: instance.cleanup,
90
+ unmount: instance.unmount,
91
+ frames: stdout.frames,
92
+ };
93
+ };
@@ -237,5 +237,8 @@ var shim_default = {
237
237
  async trace(traces, env, ctx) {
238
238
  return worker.trace(traces, getMaskedEnv(env), ctx);
239
239
  },
240
+ async email(message, env, ctx) {
241
+ return worker.email(message, getMaskedEnv(env), ctx);
242
+ },
240
243
  };
241
244
  export { shim_default as default };
@@ -799,6 +799,8 @@ declare interface EnvironmentNonInheritable {
799
799
  max_retries?: number;
800
800
  /** The queue to send messages that failed to be consumed. */
801
801
  dead_letter_queue?: string;
802
+ /** The maximum number of concurrent consumer Worker invocations. Leaving this unset will allow your consumer to scale to the maximum concurrency needed to keep up with the message backlog. */
803
+ max_concurrency?: number | null;
802
804
  }[];
803
805
  };
804
806
  /**