wrangler 0.0.0-e178d6fb → 0.0.0-e1c2f5b9

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 (239) hide show
  1. package/README.md +16 -2
  2. package/bin/wrangler.js +31 -11
  3. package/miniflare-dist/index.mjs +1340 -330
  4. package/package.json +40 -13
  5. package/src/__tests__/access.test.ts +25 -0
  6. package/src/__tests__/api-dev.test.ts +238 -0
  7. package/src/__tests__/api-devregistry.test.js +64 -0
  8. package/src/__tests__/api.test.ts +80 -0
  9. package/src/__tests__/configuration.test.ts +683 -470
  10. package/src/__tests__/d1.test.ts +123 -0
  11. package/src/__tests__/delete.test.ts +263 -0
  12. package/src/__tests__/deployments.test.ts +105 -0
  13. package/src/__tests__/dev.test.tsx +453 -70
  14. package/src/__tests__/dialogs.test.tsx +40 -0
  15. package/src/__tests__/generate.test.ts +235 -0
  16. package/src/__tests__/get-host-from-url.test.ts +16 -0
  17. package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
  18. package/src/__tests__/helpers/mock-cfetch.ts +92 -26
  19. package/src/__tests__/helpers/mock-console.ts +11 -2
  20. package/src/__tests__/helpers/mock-dialogs.ts +1 -1
  21. package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -0
  22. package/src/__tests__/helpers/mock-known-routes.ts +7 -0
  23. package/src/__tests__/helpers/mock-kv.ts +1 -1
  24. package/src/__tests__/helpers/mock-oauth-flow.ts +74 -53
  25. package/src/__tests__/helpers/mock-process.ts +8 -13
  26. package/src/__tests__/helpers/msw/handlers/access.ts +13 -0
  27. package/src/__tests__/helpers/msw/handlers/deployments.ts +59 -0
  28. package/src/__tests__/helpers/msw/handlers/namespaces.ts +104 -0
  29. package/src/__tests__/helpers/msw/handlers/oauth.ts +31 -0
  30. package/src/__tests__/helpers/msw/handlers/r2.ts +80 -0
  31. package/src/__tests__/helpers/msw/handlers/script.ts +75 -0
  32. package/src/__tests__/helpers/msw/handlers/user.ts +63 -0
  33. package/src/__tests__/helpers/msw/handlers/zones.ts +22 -0
  34. package/src/__tests__/helpers/msw/index.ts +21 -0
  35. package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +1 -0
  36. package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +5 -0
  37. package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +1 -0
  38. package/src/__tests__/helpers/worker-scripts/parent-worker.js +8 -0
  39. package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +5 -0
  40. package/src/__tests__/index.test.ts +103 -97
  41. package/src/__tests__/init.test.ts +1484 -382
  42. package/src/__tests__/jest.setup.ts +88 -5
  43. package/src/__tests__/kv.test.ts +655 -540
  44. package/src/__tests__/logout.test.ts +47 -0
  45. package/src/__tests__/metrics.test.ts +95 -45
  46. package/src/__tests__/middleware.scheduled.test.ts +145 -0
  47. package/src/__tests__/middleware.test.ts +750 -0
  48. package/src/__tests__/pages-deployment-tail.test.ts +884 -0
  49. package/src/__tests__/pages.test.ts +1301 -119
  50. package/src/__tests__/paths.test.ts +39 -0
  51. package/src/__tests__/publish.test.ts +2266 -1180
  52. package/src/__tests__/pubsub.test.ts +211 -88
  53. package/src/__tests__/queues.test.ts +522 -0
  54. package/src/__tests__/r2.test.ts +363 -203
  55. package/src/__tests__/secret.test.ts +261 -59
  56. package/src/__tests__/tail.test.ts +352 -151
  57. package/src/__tests__/test-old-node-version.js +3 -3
  58. package/src/__tests__/tsconfig-sanity.ts +12 -0
  59. package/src/__tests__/tsconfig.json +8 -0
  60. package/src/__tests__/tsconfig.tsbuildinfo +1 -0
  61. package/src/__tests__/type-generation.test.ts +233 -0
  62. package/src/__tests__/user.test.ts +59 -73
  63. package/src/__tests__/utils-collectKeyValues.test.ts +47 -0
  64. package/src/__tests__/validate-dev-props.test.ts +56 -0
  65. package/src/__tests__/whoami.test.tsx +114 -66
  66. package/src/__tests__/worker-namespace.test.ts +154 -155
  67. package/src/api/dev.ts +170 -38
  68. package/src/api/index.ts +1 -0
  69. package/src/bundle-reporter.tsx +41 -2
  70. package/src/bundle.ts +668 -81
  71. package/src/cfetch/index.ts +40 -3
  72. package/src/cfetch/internal.ts +144 -32
  73. package/src/cli.ts +4 -3
  74. package/src/config/config.ts +27 -3
  75. package/src/config/environment.ts +131 -7
  76. package/src/config/index.ts +128 -8
  77. package/src/config/validation-helpers.ts +19 -6
  78. package/src/config/validation.ts +411 -14
  79. package/src/config-cache.ts +3 -2
  80. package/src/create-worker-preview.ts +31 -6
  81. package/src/create-worker-upload-form.ts +84 -22
  82. package/src/d1/backups.tsx +223 -0
  83. package/src/d1/constants.ts +2 -0
  84. package/src/d1/create.tsx +63 -0
  85. package/src/d1/delete.tsx +56 -0
  86. package/src/d1/execute.tsx +352 -0
  87. package/src/d1/formatTimeAgo.ts +14 -0
  88. package/src/d1/index.ts +101 -0
  89. package/src/d1/list.tsx +48 -0
  90. package/src/d1/migrations/apply.tsx +196 -0
  91. package/src/d1/migrations/create.tsx +77 -0
  92. package/src/d1/migrations/helpers.ts +147 -0
  93. package/src/d1/migrations/index.tsx +3 -0
  94. package/src/d1/migrations/list.tsx +79 -0
  95. package/src/d1/migrations/options.ts +18 -0
  96. package/src/d1/options.ts +22 -0
  97. package/src/d1/types.tsx +24 -0
  98. package/src/d1/utils.ts +48 -0
  99. package/src/delete.ts +108 -0
  100. package/src/deployments.ts +83 -0
  101. package/src/deprecated/index.ts +145 -0
  102. package/src/dev/dev-vars.ts +11 -8
  103. package/src/dev/dev.tsx +220 -58
  104. package/src/dev/get-local-persistence-path.tsx +31 -0
  105. package/src/dev/local.tsx +740 -181
  106. package/src/dev/remote.tsx +340 -123
  107. package/src/dev/start-server.ts +543 -0
  108. package/src/dev/use-esbuild.ts +61 -7
  109. package/src/dev/validate-dev-props.ts +31 -0
  110. package/src/dev-registry.tsx +201 -0
  111. package/src/dev.tsx +614 -258
  112. package/src/dialogs.tsx +41 -8
  113. package/src/{worker-namespace.ts → dispatch-namespace.ts} +23 -22
  114. package/src/docs/index.ts +97 -0
  115. package/src/entry.ts +3 -2
  116. package/src/environment-variables/factory.ts +88 -0
  117. package/src/environment-variables/misc-variables.ts +30 -0
  118. package/src/generate/index.ts +300 -0
  119. package/src/git-client.ts +100 -7
  120. package/src/index.tsx +249 -1560
  121. package/src/init.ts +626 -150
  122. package/src/inspect.ts +137 -32
  123. package/src/{metrics/is-ci.ts → is-ci.ts} +0 -0
  124. package/src/is-interactive.ts +4 -0
  125. package/src/jest.d.ts +4 -0
  126. package/src/{kv.ts → kv/helpers.ts} +3 -3
  127. package/src/kv/index.ts +596 -0
  128. package/src/logger.ts +27 -8
  129. package/src/metrics/index.ts +1 -0
  130. package/src/metrics/metrics-config.ts +4 -4
  131. package/src/metrics/metrics-dispatcher.ts +1 -0
  132. package/src/metrics/metrics-usage-headers.ts +24 -0
  133. package/src/metrics/send-event.ts +13 -8
  134. package/src/miniflare-cli/assets.ts +172 -465
  135. package/src/miniflare-cli/index.ts +149 -24
  136. package/src/miniflare-cli/tsconfig.json +9 -0
  137. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
  138. package/src/miniflare-cli/types.ts +11 -0
  139. package/src/module-collection.ts +12 -3
  140. package/src/pages/build.tsx +108 -42
  141. package/src/pages/constants.ts +11 -0
  142. package/src/pages/deployment-tails.tsx +284 -0
  143. package/src/pages/deployments.tsx +9 -31
  144. package/src/pages/dev.tsx +417 -108
  145. package/src/pages/errors.ts +66 -0
  146. package/src/pages/functions/buildPlugin.ts +86 -84
  147. package/src/pages/functions/buildWorker.ts +121 -106
  148. package/src/pages/functions/routes-consolidation.test.ts +250 -0
  149. package/src/pages/functions/routes-consolidation.ts +73 -0
  150. package/src/pages/functions/routes-transformation.test.ts +282 -0
  151. package/src/pages/functions/routes-transformation.ts +115 -0
  152. package/src/pages/functions/routes-validation.test.ts +403 -0
  153. package/src/pages/functions/routes-validation.ts +202 -0
  154. package/src/pages/functions/tsconfig.json +8 -0
  155. package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
  156. package/src/pages/functions.tsx +82 -0
  157. package/src/pages/hash.tsx +13 -0
  158. package/src/pages/index.tsx +73 -55
  159. package/src/pages/projects.tsx +9 -3
  160. package/src/pages/prompt-select-project.tsx +31 -0
  161. package/src/pages/publish.tsx +183 -60
  162. package/src/pages/types.ts +1 -0
  163. package/src/pages/upload.tsx +107 -56
  164. package/src/pages/utils.ts +13 -2
  165. package/src/paths.ts +49 -4
  166. package/src/proxy.ts +375 -157
  167. package/src/publish/index.ts +270 -0
  168. package/src/{publish.ts → publish/publish.ts} +431 -188
  169. package/src/pubsub/pubsub-commands.tsx +4 -3
  170. package/src/queues/cli/commands/consumer/add.ts +71 -0
  171. package/src/queues/cli/commands/consumer/index.ts +22 -0
  172. package/src/queues/cli/commands/consumer/remove.ts +38 -0
  173. package/src/queues/cli/commands/create.ts +25 -0
  174. package/src/queues/cli/commands/delete.ts +26 -0
  175. package/src/queues/cli/commands/index.ts +36 -0
  176. package/src/queues/cli/commands/list.ts +25 -0
  177. package/src/queues/client.ts +135 -0
  178. package/src/queues/utils.ts +18 -0
  179. package/src/r2/constants.ts +4 -0
  180. package/src/r2/helpers.ts +131 -0
  181. package/src/r2/index.ts +289 -0
  182. package/src/routes.ts +140 -0
  183. package/src/secret/index.ts +379 -0
  184. package/src/sites.tsx +3 -3
  185. package/src/tail/createTail.ts +379 -0
  186. package/src/tail/filters.ts +4 -6
  187. package/src/tail/index.ts +199 -284
  188. package/src/tail/printing.ts +43 -3
  189. package/src/tsconfig-sanity.ts +16 -0
  190. package/src/type-generation.ts +181 -0
  191. package/src/user/access.ts +68 -0
  192. package/src/user/auth-variables.ts +113 -0
  193. package/src/user/choose-account.tsx +1 -1
  194. package/src/user/index.ts +0 -1
  195. package/src/user/user.tsx +116 -49
  196. package/src/utils/collectKeyValues.ts +14 -0
  197. package/src/whoami.tsx +80 -2
  198. package/src/worker.ts +69 -9
  199. package/src/yargs-types.ts +24 -0
  200. package/src/zones.ts +124 -9
  201. package/templates/__tests__/pages-dev-util.test.ts +128 -0
  202. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  203. package/templates/__tests__/tsconfig.json +8 -0
  204. package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
  205. package/templates/d1-beta-facade.js +205 -0
  206. package/templates/facade.d.ts +14 -0
  207. package/templates/first-party-worker-module-facade.ts +19 -0
  208. package/templates/format-dev-errors.ts +33 -0
  209. package/templates/init-tests/test-jest-new-worker.js +23 -0
  210. package/templates/init-tests/test-vitest-new-worker.js +24 -0
  211. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  212. package/templates/middleware/common.ts +62 -0
  213. package/templates/middleware/loader-modules.ts +82 -0
  214. package/templates/middleware/loader-sw.ts +233 -0
  215. package/templates/middleware/middleware-miniflare3-json-error.ts +20 -0
  216. package/templates/middleware/middleware-pretty-error.ts +40 -0
  217. package/templates/middleware/middleware-scheduled.ts +15 -0
  218. package/templates/new-worker.js +1 -1
  219. package/templates/pages-dev-pipeline.ts +31 -0
  220. package/templates/pages-dev-util.ts +52 -0
  221. package/templates/pages-shim.ts +4 -1
  222. package/templates/pages-template-plugin.ts +21 -5
  223. package/templates/pages-template-worker.ts +37 -9
  224. package/templates/{static-asset-facade.js → serve-static-assets.ts} +23 -7
  225. package/templates/service-bindings-module-facade.js +54 -0
  226. package/templates/service-bindings-sw-facade.js +42 -0
  227. package/templates/tsconfig-sanity.ts +11 -0
  228. package/templates/tsconfig.init.json +106 -0
  229. package/templates/tsconfig.json +5 -102
  230. package/templates/tsconfig.tsbuildinfo +1 -0
  231. package/wrangler-dist/cli.d.ts +621 -42
  232. package/wrangler-dist/cli.js +144441 -102606
  233. package/src/environment-variables.ts +0 -35
  234. package/src/faye-websocket.d.ts +0 -6
  235. package/src/generate.ts +0 -33
  236. package/src/miniflare-cli/enum-keys.ts +0 -17
  237. package/src/preview.ts +0 -31
  238. package/src/r2.ts +0 -50
  239. package/src/user/env-vars.ts +0 -46
@@ -1,21 +1,20 @@
1
+ import { rest } from "msw";
1
2
  import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
2
- import { setMockResponse, unsetAllMocks } from "./helpers/mock-cfetch";
3
3
  import { mockConsoleMethods } from "./helpers/mock-console";
4
+ import { msw, mswSuccessNamespacesHandlers } from "./helpers/msw";
4
5
  import { runInTempDir } from "./helpers/run-in-tmp";
5
6
  import { runWrangler } from "./helpers/run-wrangler";
6
7
 
7
- describe("worker-namespace", () => {
8
- runInTempDir();
8
+ describe("dispatch-namespace", () => {
9
9
  const std = mockConsoleMethods();
10
+ beforeEach(() => msw.use(...mswSuccessNamespacesHandlers));
11
+
12
+ runInTempDir();
10
13
  mockAccountId();
11
14
  mockApiToken();
12
15
 
13
- afterEach(() => {
14
- unsetAllMocks();
15
- });
16
-
17
- it("should should display a list of available subcommands, for worker-namespace with no subcommand", async () => {
18
- await runWrangler("worker-namespace");
16
+ it("should should display a list of available subcommands, for dispatch-namespace with no subcommand", async () => {
17
+ await runWrangler("dispatch-namespace");
19
18
 
20
19
  // wait a tick for the help menu to be printed
21
20
  await new Promise((resolve) => setImmediate(resolve));
@@ -24,19 +23,20 @@ describe("worker-namespace", () => {
24
23
  Object {
25
24
  "debug": "",
26
25
  "err": "",
27
- "out": "wrangler worker-namespace
26
+ "out": "wrangler dispatch-namespace
28
27
 
29
- 📦 Interact with a worker namespace
28
+ 📦 Interact with a dispatch namespace
30
29
 
31
30
  Commands:
32
- wrangler worker-namespace list List all Worker namespaces
33
- wrangler worker-namespace get <name> Get information about a Worker namespace
34
- wrangler worker-namespace create <name> Create a Worker namespace
35
- wrangler worker-namespace delete <name> Delete a Worker namespace
36
- wrangler worker-namespace rename <old-name> <new-name> Rename a Worker namespace
31
+ wrangler dispatch-namespace list List all dispatch namespaces
32
+ wrangler dispatch-namespace get <name> Get information about a dispatch namespace
33
+ wrangler dispatch-namespace create <name> Create a dispatch namespace
34
+ wrangler dispatch-namespace delete <name> Delete a dispatch namespace
35
+ wrangler dispatch-namespace rename <old-name> <new-name> Rename a dispatch namespace
37
36
 
38
37
  Flags:
39
38
  -c, --config Path to .toml configuration file [string]
39
+ -e, --env Environment to use for operations and .env files [string]
40
40
  -h, --help Show help [boolean]
41
41
  -v, --version Show version number [boolean]",
42
42
  "warn": "",
@@ -45,170 +45,165 @@ describe("worker-namespace", () => {
45
45
  });
46
46
 
47
47
  describe("create namespace", () => {
48
- function mockCreateRequest(expectedName: string) {
49
- const requests = { count: 0 };
50
- setMockResponse(
51
- "/accounts/:accountId/workers/dispatch/namespaces",
52
- ([_url], init) => {
53
- requests.count += 1;
54
-
55
- const incomingText = init.body?.toString() || "";
56
- const { name: namespace_name } = JSON.parse(incomingText);
57
-
58
- expect(init.method).toBe("POST");
59
- expect(namespace_name).toEqual(expectedName);
60
-
61
- return {
62
- namespace_id: "some-namespace-id",
63
- namespace_name: "namespace-name",
64
- created_on: "2022-06-29T14:30:08.16152Z",
65
- created_by: "1fc1df98cc4420fe00367c3ab68c1639",
66
- modified_on: "2022-06-29T14:30:08.16152Z",
67
- modified_by: "1fc1df98cc4420fe00367c3ab68c1639",
68
- };
48
+ const namespaceName = "my-namespace";
49
+ let counter = 0;
50
+ msw.use(
51
+ rest.post(
52
+ "/accounts/:accountId/workers/dispatch/namespaces/:namespaceNameParam",
53
+ (req, res, cxt) => {
54
+ counter++;
55
+ const { namespaceNameParam } = req.params;
56
+ expect(counter).toBe(1);
57
+ expect(namespaceNameParam).toBe(namespaceName);
58
+ return res.once(
59
+ cxt.status(200),
60
+ cxt.json({
61
+ namespace_id: "some-namespace-id",
62
+ namespace_name: "namespace-name",
63
+ created_on: "2022-06-29T14:30:08.16152Z",
64
+ created_by: "1fc1df98cc4420fe00367c3ab68c1639",
65
+ modified_on: "2022-06-29T14:30:08.16152Z",
66
+ modified_by: "1fc1df98cc4420fe00367c3ab68c1639",
67
+ })
68
+ );
69
69
  }
70
- );
71
- return requests;
72
- }
70
+ )
71
+ );
73
72
 
74
73
  it("should display help for create", async () => {
75
74
  await expect(
76
- runWrangler("worker-namespace create")
75
+ runWrangler("dispatch-namespace create")
77
76
  ).rejects.toThrowErrorMatchingInlineSnapshot(
78
77
  `"Not enough non-option arguments: got 0, need at least 1"`
79
78
  );
80
79
 
81
80
  expect(std.out).toMatchInlineSnapshot(`
82
81
  "
83
- wrangler worker-namespace create <name>
82
+ wrangler dispatch-namespace create <name>
84
83
 
85
- Create a Worker namespace
84
+ Create a dispatch namespace
86
85
 
87
86
  Positionals:
88
- name Name of the Worker namespace [string] [required]
87
+ name Name of the dispatch namespace [string] [required]
89
88
 
90
89
  Flags:
91
90
  -c, --config Path to .toml configuration file [string]
91
+ -e, --env Environment to use for operations and .env files [string]
92
92
  -h, --help Show help [boolean]
93
93
  -v, --version Show version number [boolean]"
94
94
  `);
95
95
  });
96
96
 
97
97
  it("should attempt to create the given namespace", async () => {
98
- const namespaceName = "my-namespace";
99
- const requests = mockCreateRequest(namespaceName);
100
- await runWrangler(`worker-namespace create ${namespaceName}`);
101
- expect(requests.count).toEqual(1);
98
+ await runWrangler(`dispatch-namespace create ${namespaceName}`);
102
99
 
103
100
  expect(std.out).toMatchInlineSnapshot(
104
- `"Created Worker namespace \\"my-namespace\\" with ID \\"some-namespace-id\\""`
101
+ `"Created dispatch namespace \\"my-namespace\\" with ID \\"some-namespace-id\\""`
105
102
  );
106
103
  });
107
104
  });
108
105
 
109
106
  describe("delete namespace", () => {
110
- function mockDeleteRequest(expectedName: string) {
111
- const requests = { count: 0 };
112
- setMockResponse(
113
- "/accounts/:accountId/workers/dispatch/namespaces/:namespaceName",
114
- ([_url, _, namespaceName], init) => {
115
- requests.count += 1;
116
-
117
- expect(init.method).toBe("DELETE");
118
- expect(namespaceName).toEqual(expectedName);
119
-
120
- return null;
107
+ const namespaceName = "my-namespace";
108
+ let counter = 0;
109
+ msw.use(
110
+ rest.delete(
111
+ "/accounts/:accountId/workers/dispatch/namespaces/:namespaceNameParam",
112
+ (req, res, cxt) => {
113
+ counter++;
114
+ const { namespaceNameParam } = req.params;
115
+ expect(counter).toBe(1);
116
+ expect(namespaceNameParam).toBe(namespaceName);
117
+ return res.once(cxt.status(200), cxt.json(null));
121
118
  }
122
- );
123
- return requests;
124
- }
119
+ )
120
+ );
125
121
 
126
122
  it("should display help for delete", async () => {
127
123
  await expect(
128
- runWrangler("worker-namespace create")
124
+ runWrangler("dispatch-namespace create")
129
125
  ).rejects.toThrowErrorMatchingInlineSnapshot(
130
126
  `"Not enough non-option arguments: got 0, need at least 1"`
131
127
  );
132
128
 
133
129
  expect(std.out).toMatchInlineSnapshot(`
134
130
  "
135
- wrangler worker-namespace create <name>
131
+ wrangler dispatch-namespace create <name>
136
132
 
137
- Create a Worker namespace
133
+ Create a dispatch namespace
138
134
 
139
135
  Positionals:
140
- name Name of the Worker namespace [string] [required]
136
+ name Name of the dispatch namespace [string] [required]
141
137
 
142
138
  Flags:
143
139
  -c, --config Path to .toml configuration file [string]
140
+ -e, --env Environment to use for operations and .env files [string]
144
141
  -h, --help Show help [boolean]
145
142
  -v, --version Show version number [boolean]"
146
143
  `);
147
144
  });
148
145
 
149
146
  it("should try to delete the given namespace", async () => {
150
- const namespaceName = "my-namespace";
151
- const requests = mockDeleteRequest(namespaceName);
152
- await runWrangler(`worker-namespace delete ${namespaceName}`);
153
- expect(requests.count).toBe(1);
147
+ await runWrangler(`dispatch-namespace delete ${namespaceName}`);
154
148
 
155
149
  expect(std.out).toMatchInlineSnapshot(
156
- `"Deleted Worker namespace \\"my-namespace\\""`
150
+ `"Deleted dispatch namespace \\"my-namespace\\""`
157
151
  );
158
152
  });
159
153
  });
160
154
 
161
155
  describe("get namespace", () => {
162
- function mockInfoRequest(expectedName: string) {
163
- const requests = { count: 0 };
164
- setMockResponse(
165
- "/accounts/:accountId/workers/dispatch/namespaces/:namespaceName",
166
- ([_url, _, namespaceName], _init) => {
167
- requests.count += 1;
168
-
169
- expect(namespaceName).toEqual(expectedName);
170
-
171
- return {
172
- namespace_id: "some-namespace-id",
173
- namespace_name: "namespace-name",
174
- created_on: "2022-06-29T14:30:08.16152Z",
175
- created_by: "1fc1df98cc4420fe00367c3ab68c1639",
176
- modified_on: "2022-06-29T14:30:08.16152Z",
177
- modified_by: "1fc1df98cc4420fe00367c3ab68c1639",
178
- };
156
+ const namespaceName = "my-namespace";
157
+ let counter = 0;
158
+ msw.use(
159
+ rest.get(
160
+ "/accounts/:accountId/workers/dispatch/namespaces/:namespaceNameParam",
161
+ (req, res, cxt) => {
162
+ counter++;
163
+ const { namespaceNameParam } = req.params;
164
+ expect(counter).toBe(1);
165
+ expect(namespaceNameParam).toBe(namespaceName);
166
+ return res.once(
167
+ cxt.status(200),
168
+ cxt.json({
169
+ namespace_id: "some-namespace-id",
170
+ namespace_name: "namespace-name",
171
+ created_on: "2022-06-29T14:30:08.16152Z",
172
+ created_by: "1fc1df98cc4420fe00367c3ab68c1639",
173
+ modified_on: "2022-06-29T14:30:08.16152Z",
174
+ modified_by: "1fc1df98cc4420fe00367c3ab68c1639",
175
+ })
176
+ );
179
177
  }
180
- );
181
- return requests;
182
- }
178
+ )
179
+ );
183
180
 
184
181
  it("should display help for get", async () => {
185
182
  await expect(
186
- runWrangler("worker-namespace get")
183
+ runWrangler("dispatch-namespace get")
187
184
  ).rejects.toThrowErrorMatchingInlineSnapshot(
188
185
  `"Not enough non-option arguments: got 0, need at least 1"`
189
186
  );
190
187
 
191
188
  expect(std.out).toMatchInlineSnapshot(`
192
- "
193
- wrangler worker-namespace get <name>
189
+ "
190
+ wrangler dispatch-namespace get <name>
194
191
 
195
- Get information about a Worker namespace
192
+ Get information about a dispatch namespace
196
193
 
197
- Positionals:
198
- name Name of the Worker namespace [string] [required]
194
+ Positionals:
195
+ name Name of the dispatch namespace [string] [required]
199
196
 
200
- Flags:
201
- -c, --config Path to .toml configuration file [string]
202
- -h, --help Show help [boolean]
203
- -v, --version Show version number [boolean]"
204
- `);
197
+ Flags:
198
+ -c, --config Path to .toml configuration file [string]
199
+ -e, --env Environment to use for operations and .env files [string]
200
+ -h, --help Show help [boolean]
201
+ -v, --version Show version number [boolean]"
202
+ `);
205
203
  });
206
204
 
207
205
  it("should attempt to get info for the given namespace", async () => {
208
- const namespaceName = "my-namespace";
209
- const requests = mockInfoRequest(namespaceName);
210
- await runWrangler(`worker-namespace get ${namespaceName}`);
211
- expect(requests.count).toBe(1);
206
+ await runWrangler(`dispatch-namespace get ${namespaceName}`);
212
207
 
213
208
  expect(std.out).toMatchInlineSnapshot(`
214
209
  "{
@@ -224,32 +219,33 @@ describe("worker-namespace", () => {
224
219
  });
225
220
 
226
221
  describe("list namespaces", () => {
227
- function mockListRequest() {
228
- const requests = { count: 0 };
229
- setMockResponse(
230
- "/accounts/:accountId/workers/dispatch/namespaces",
231
- ([_url, _, _page, _perPage], _init) => {
232
- requests.count += 1;
233
-
234
- return [
235
- {
222
+ const namespaceName = "my-namespace";
223
+ let counter = 0;
224
+ msw.use(
225
+ rest.get(
226
+ "/accounts/:accountId/workers/dispatch/namespaces/:namespaceNameParam",
227
+ (req, res, cxt) => {
228
+ counter++;
229
+ const { namespaceNameParam } = req.params;
230
+ expect(counter).toBe(1);
231
+ expect(namespaceNameParam).toBe(namespaceName);
232
+ return res.once(
233
+ cxt.status(200),
234
+ cxt.json({
236
235
  namespace_id: "some-namespace-id",
237
236
  namespace_name: "namespace-name",
238
237
  created_on: "2022-06-29T14:30:08.16152Z",
239
238
  created_by: "1fc1df98cc4420fe00367c3ab68c1639",
240
239
  modified_on: "2022-06-29T14:30:08.16152Z",
241
240
  modified_by: "1fc1df98cc4420fe00367c3ab68c1639",
242
- },
243
- ];
241
+ })
242
+ );
244
243
  }
245
- );
246
- return requests;
247
- }
244
+ )
245
+ );
248
246
 
249
247
  it("should list all namespaces", async () => {
250
- const requests = mockListRequest();
251
- await runWrangler("worker-namespace list");
252
- expect(requests.count).toBe(1);
248
+ await runWrangler("dispatch-namespace list");
253
249
  expect(std.out).toMatchInlineSnapshot(`
254
250
  "[
255
251
  {
@@ -266,61 +262,64 @@ describe("worker-namespace", () => {
266
262
  });
267
263
 
268
264
  describe("rename namespace", () => {
269
- function mockRenameRequest(expectedName: string) {
270
- const requests = { count: 0 };
271
- setMockResponse(
272
- "/accounts/:accountId/workers/dispatch/namespaces/:namespaceName",
273
- ([_url, _, namespaceName], init) => {
274
- requests.count += 1;
275
-
276
- expect(init.method).toEqual("PUT");
277
- expect(namespaceName).toEqual(expectedName);
278
-
279
- return {
280
- namespace_id: "some-namespace-id",
281
- namespace_name: "namespace-name",
282
- created_on: "2022-06-29T14:30:08.16152Z",
283
- created_by: "1fc1df98cc4420fe00367c3ab68c1639",
284
- modified_on: "2022-06-29T14:30:08.16152Z",
285
- modified_by: "1fc1df98cc4420fe00367c3ab68c1639",
286
- };
265
+ const namespaceName = "my-namespace";
266
+ let counter = 0;
267
+ msw.use(
268
+ rest.put(
269
+ "/accounts/:accountId/workers/dispatch/namespaces/:namespaceNameParam",
270
+ (req, res, cxt) => {
271
+ counter++;
272
+ const { namespaceNameParam } = req.params;
273
+ expect(counter).toBe(1);
274
+ expect(namespaceNameParam).toBe(namespaceName);
275
+ return res.once(
276
+ cxt.status(200),
277
+ cxt.json({
278
+ namespace_id: "some-namespace-id",
279
+ namespace_name: "namespace-name",
280
+ created_on: "2022-06-29T14:30:08.16152Z",
281
+ created_by: "1fc1df98cc4420fe00367c3ab68c1639",
282
+ modified_on: "2022-06-29T14:30:08.16152Z",
283
+ modified_by: "1fc1df98cc4420fe00367c3ab68c1639",
284
+ })
285
+ );
287
286
  }
288
- );
289
- return requests;
290
- }
287
+ )
288
+ );
291
289
 
292
290
  it("should display help for rename", async () => {
293
291
  await expect(
294
- runWrangler("worker-namespace rename")
292
+ runWrangler("dispatch-namespace rename")
295
293
  ).rejects.toThrowErrorMatchingInlineSnapshot(
296
294
  `"Not enough non-option arguments: got 0, need at least 2"`
297
295
  );
298
296
 
299
297
  expect(std.out).toMatchInlineSnapshot(`
300
298
  "
301
- wrangler worker-namespace rename <old-name> <new-name>
299
+ wrangler dispatch-namespace rename <old-name> <new-name>
302
300
 
303
- Rename a Worker namespace
301
+ Rename a dispatch namespace
304
302
 
305
303
  Positionals:
306
- old-name Name of the Worker namespace [string] [required]
307
- new-name New name of the Worker namespace [string] [required]
304
+ old-name Name of the dispatch namespace [string] [required]
305
+ new-name New name of the dispatch namespace [string] [required]
308
306
 
309
307
  Flags:
310
308
  -c, --config Path to .toml configuration file [string]
309
+ -e, --env Environment to use for operations and .env files [string]
311
310
  -h, --help Show help [boolean]
312
311
  -v, --version Show version number [boolean]"
313
312
  `);
314
313
  });
315
314
 
316
315
  it("should attempt to rename the given namespace", async () => {
317
- const namespaceName = "my-namespace";
318
316
  const newName = "new-namespace";
319
- const requests = mockRenameRequest(namespaceName);
320
- await runWrangler(`worker-namespace rename ${namespaceName} ${newName}`);
321
- expect(requests.count).toBe(1);
317
+ await runWrangler(
318
+ `dispatch-namespace rename ${namespaceName} ${newName}`
319
+ );
320
+
322
321
  expect(std.out).toMatchInlineSnapshot(
323
- `"Renamed Worker namespace \\"my-namespace\\" to \\"new-namespace\\""`
322
+ `"Renamed dispatch namespace \\"my-namespace\\" to \\"new-namespace\\""`
324
323
  );
325
324
  });
326
325
  });