wrangler 0.0.0-e6733a3 → 0.0.0-e6ada079

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.

Potentially problematic release.


This version of wrangler might be problematic. Click here for more details.

Files changed (119) hide show
  1. package/README.md +47 -16
  2. package/bin/wrangler.js +94 -31
  3. package/config-schema.json +3100 -0
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +154 -82
  6. package/templates/__tests__/pages-dev-util.test.ts +128 -0
  7. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  8. package/templates/__tests__/tsconfig.json +8 -0
  9. package/templates/checked-fetch.js +30 -0
  10. package/templates/facade.d.ts +19 -0
  11. package/templates/gitignore +170 -0
  12. package/templates/init-tests/test-jest-new-worker.js +23 -0
  13. package/templates/init-tests/test-vitest-new-worker.js +24 -0
  14. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  15. package/templates/middleware/common.ts +67 -0
  16. package/templates/middleware/loader-modules.ts +134 -0
  17. package/templates/middleware/loader-sw.ts +229 -0
  18. package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
  19. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  20. package/templates/middleware/middleware-pretty-error.ts +40 -0
  21. package/templates/middleware/middleware-scheduled.ts +15 -0
  22. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  23. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  24. package/templates/modules-watch-stub.js +4 -0
  25. package/templates/new-worker-scheduled.js +17 -0
  26. package/templates/new-worker-scheduled.ts +32 -0
  27. package/templates/new-worker.js +15 -0
  28. package/templates/new-worker.ts +33 -0
  29. package/templates/no-op-worker.js +10 -0
  30. package/templates/pages-dev-pipeline.ts +32 -0
  31. package/templates/pages-dev-util.ts +55 -0
  32. package/templates/pages-shim.ts +9 -0
  33. package/templates/pages-template-plugin.ts +190 -0
  34. package/templates/pages-template-worker.ts +198 -0
  35. package/templates/startDevWorker/InspectorProxyWorker.ts +664 -0
  36. package/templates/startDevWorker/ProxyWorker.ts +334 -0
  37. package/templates/tsconfig-sanity.ts +11 -0
  38. package/templates/tsconfig.init.json +22 -0
  39. package/templates/tsconfig.json +8 -0
  40. package/wrangler-dist/InspectorProxyWorker.js +464 -0
  41. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  42. package/wrangler-dist/ProxyWorker.js +240 -0
  43. package/wrangler-dist/ProxyWorker.js.map +6 -0
  44. package/wrangler-dist/cli.d.ts +26391 -0
  45. package/wrangler-dist/cli.js +204293 -116652
  46. package/wrangler-dist/wasm-sync.wasm +0 -0
  47. package/import_meta_url.js +0 -3
  48. package/miniflare-config-stubs/.env.empty +0 -0
  49. package/miniflare-config-stubs/package.empty.json +0 -1
  50. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  51. package/pages/functions/buildWorker.ts +0 -62
  52. package/pages/functions/filepath-routing.test.ts +0 -39
  53. package/pages/functions/filepath-routing.ts +0 -221
  54. package/pages/functions/identifiers.ts +0 -78
  55. package/pages/functions/routes.ts +0 -158
  56. package/pages/functions/template-worker.ts +0 -144
  57. package/src/__tests__/clipboardy-mock.js +0 -4
  58. package/src/__tests__/dev.test.tsx +0 -66
  59. package/src/__tests__/index.test.ts +0 -287
  60. package/src/__tests__/jest.setup.ts +0 -22
  61. package/src/__tests__/kv.test.ts +0 -1098
  62. package/src/__tests__/mock-cfetch.ts +0 -171
  63. package/src/__tests__/mock-dialogs.ts +0 -65
  64. package/src/__tests__/run-in-tmp.ts +0 -19
  65. package/src/__tests__/run-wrangler.ts +0 -32
  66. package/src/api/form_data.ts +0 -131
  67. package/src/api/preview.ts +0 -128
  68. package/src/api/worker.ts +0 -155
  69. package/src/cfetch/index.ts +0 -102
  70. package/src/cfetch/internal.ts +0 -69
  71. package/src/cli.ts +0 -9
  72. package/src/config.ts +0 -487
  73. package/src/dev.tsx +0 -771
  74. package/src/dialogs.tsx +0 -77
  75. package/src/index.tsx +0 -1974
  76. package/src/inspect.ts +0 -524
  77. package/src/kv.tsx +0 -267
  78. package/src/module-collection.ts +0 -64
  79. package/src/pages.tsx +0 -1031
  80. package/src/proxy.ts +0 -294
  81. package/src/publish.ts +0 -358
  82. package/src/sites.tsx +0 -114
  83. package/src/tail.tsx +0 -73
  84. package/src/user.tsx +0 -1025
  85. package/static-asset-facade.js +0 -47
  86. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  87. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  88. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  89. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  90. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  91. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  92. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  93. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  94. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  95. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  96. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  97. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  98. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  99. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  100. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  101. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  102. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  103. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  104. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  105. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  106. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  107. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  108. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  109. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  110. package/vendor/wrangler-mime/LICENSE +0 -21
  111. package/vendor/wrangler-mime/Mime.js +0 -97
  112. package/vendor/wrangler-mime/README.md +0 -187
  113. package/vendor/wrangler-mime/cli.js +0 -46
  114. package/vendor/wrangler-mime/index.js +0 -4
  115. package/vendor/wrangler-mime/lite.js +0 -4
  116. package/vendor/wrangler-mime/package.json +0 -52
  117. package/vendor/wrangler-mime/types/other.js +0 -1
  118. package/vendor/wrangler-mime/types/standard.js +0 -1
  119. package/wrangler-dist/cli.js.map +0 -7
@@ -1,1098 +0,0 @@
1
- import { writeFileSync } from "fs";
2
- import {
3
- setMockResponse,
4
- setMockRawResponse,
5
- unsetAllMocks,
6
- createFetchResult,
7
- } from "./mock-cfetch";
8
- import { runWrangler } from "./run-wrangler";
9
- import { runInTempDir } from "./run-in-tmp";
10
-
11
- describe("wrangler", () => {
12
- runInTempDir();
13
-
14
- afterEach(() => {
15
- unsetAllMocks();
16
- });
17
-
18
- describe("kv:namespace", () => {
19
- describe("create", () => {
20
- function mockCreateRequest(expectedTitle: string) {
21
- setMockResponse(
22
- "/accounts/:accountId/storage/kv/namespaces",
23
- "POST",
24
- ([_url, accountId], { body }) => {
25
- expect(accountId).toEqual("some-account-id");
26
- const title = JSON.parse(body as string).title;
27
- expect(title).toEqual(expectedTitle);
28
- return { id: "some-namespace-id" };
29
- }
30
- );
31
- }
32
-
33
- it("should error if no namespace is given", async () => {
34
- const { error, stdout, stderr } = await runWrangler(
35
- "kv:namespace create"
36
- );
37
- expect(stdout).toMatchInlineSnapshot(`""`);
38
- expect(stderr).toMatchInlineSnapshot(`
39
- "wrangler kv:namespace create <namespace>
40
-
41
- Create a new namespace
42
-
43
- Positionals:
44
- namespace The name of the new namespace [string] [required]
45
-
46
- Flags:
47
- -c, --config Path to .toml configuration file [string]
48
- -h, --help Show help [boolean]
49
- -v, --version Show version number [boolean]
50
-
51
- Options:
52
- -l, --local Run on my machine [boolean] [default: false]
53
- --env Perform on a specific environment [string]
54
- --preview Interact with a preview namespace [boolean]
55
-
56
- Not enough non-option arguments: got 0, need at least 1"
57
- `);
58
- expect(error).toMatchInlineSnapshot(
59
- `[Error: Not enough non-option arguments: got 0, need at least 1]`
60
- );
61
- });
62
-
63
- it("should error if the namespace to create contains spaces", async () => {
64
- const { error, stdout, stderr } = await runWrangler(
65
- "kv:namespace create abc def ghi"
66
- );
67
- expect(stdout).toMatchInlineSnapshot(`""`);
68
- expect(stderr).toMatchInlineSnapshot(`
69
- "wrangler kv:namespace create <namespace>
70
-
71
- Create a new namespace
72
-
73
- Positionals:
74
- namespace The name of the new namespace [string] [required]
75
-
76
- Flags:
77
- -c, --config Path to .toml configuration file [string]
78
- -h, --help Show help [boolean]
79
- -v, --version Show version number [boolean]
80
-
81
- Options:
82
- -l, --local Run on my machine [boolean] [default: false]
83
- --env Perform on a specific environment [string]
84
- --preview Interact with a preview namespace [boolean]
85
-
86
- Unexpected additional positional arguments \\"def ghi\\"."
87
- `);
88
- expect(error).toMatchInlineSnapshot(
89
- `[Error: Unexpected additional positional arguments "def ghi".]`
90
- );
91
- });
92
-
93
- it("should error if the namespace to create is not valid", async () => {
94
- const { error, stdout, stderr } = await runWrangler(
95
- "kv:namespace create abc-def"
96
- );
97
- expect(stdout).toMatchInlineSnapshot(`""`);
98
- expect(stderr).toMatchInlineSnapshot(`
99
- "wrangler kv:namespace create <namespace>
100
-
101
- Create a new namespace
102
-
103
- Positionals:
104
- namespace The name of the new namespace [string] [required]
105
-
106
- Flags:
107
- -c, --config Path to .toml configuration file [string]
108
- -h, --help Show help [boolean]
109
- -v, --version Show version number [boolean]
110
-
111
- Options:
112
- -l, --local Run on my machine [boolean] [default: false]
113
- --env Perform on a specific environment [string]
114
- --preview Interact with a preview namespace [boolean]
115
-
116
- The namespace binding name \\"abc-def\\" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number."
117
- `);
118
- expect(error).toMatchInlineSnapshot(
119
- `[Error: The namespace binding name "abc-def" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number.]`
120
- );
121
- });
122
-
123
- it("should create a namespace", async () => {
124
- mockCreateRequest("worker-UnitTestNamespace");
125
- const { stdout } = await runWrangler(
126
- "kv:namespace create UnitTestNamespace"
127
- );
128
- expect(stdout).toMatchInlineSnapshot(`
129
- "🌀 Creating namespace with title \\"worker-UnitTestNamespace\\"
130
- ✨ Success!
131
- Add the following to your configuration file in your kv_namespaces array:
132
- { binding = \\"UnitTestNamespace\\", id = \\"some-namespace-id\\" }"
133
- `);
134
- });
135
-
136
- it("should create a preview namespace if configured to do so", async () => {
137
- mockCreateRequest("worker-UnitTestNamespace_preview");
138
- const { stdout } = await runWrangler(
139
- "kv:namespace create UnitTestNamespace --preview"
140
- );
141
- expect(stdout).toMatchInlineSnapshot(`
142
- "🌀 Creating namespace with title \\"worker-UnitTestNamespace_preview\\"
143
- ✨ Success!
144
- Add the following to your configuration file in your kv_namespaces array:
145
- { binding = \\"UnitTestNamespace\\", preview_id = \\"some-namespace-id\\" }"
146
- `);
147
- });
148
-
149
- it("should create a namespace using configured worker name", async () => {
150
- writeFileSync("./wrangler.toml", 'name = "otherWorker"', "utf-8");
151
- mockCreateRequest("otherWorker-UnitTestNamespace");
152
- const { stdout } = await runWrangler(
153
- "kv:namespace create UnitTestNamespace"
154
- );
155
- expect(stdout).toMatchInlineSnapshot(`
156
- "🌀 Creating namespace with title \\"otherWorker-UnitTestNamespace\\"
157
- ✨ Success!
158
- Add the following to your configuration file in your kv_namespaces array:
159
- { binding = \\"UnitTestNamespace\\", id = \\"some-namespace-id\\" }"
160
- `);
161
- });
162
-
163
- it("should create a namespace in an environment if configured to do so", async () => {
164
- mockCreateRequest("worker-customEnv-UnitTestNamespace");
165
- const { stdout } = await runWrangler(
166
- "kv:namespace create UnitTestNamespace --env customEnv"
167
- );
168
- expect(stdout).toMatchInlineSnapshot(`
169
- "🌀 Creating namespace with title \\"worker-customEnv-UnitTestNamespace\\"
170
- ✨ Success!
171
- Add the following to your configuration file in your kv_namespaces array under [env.customEnv]:
172
- { binding = \\"UnitTestNamespace\\", id = \\"some-namespace-id\\" }"
173
- `);
174
- });
175
- });
176
-
177
- describe("list", () => {
178
- function mockListRequest(namespaces: unknown[]) {
179
- const requests = { count: 0 };
180
- setMockResponse(
181
- "/accounts/:accountId/storage/kv/namespaces",
182
- ([_url, accountId], init, query) => {
183
- requests.count++;
184
- expect(accountId).toEqual("some-account-id");
185
- expect(query.get("per_page")).toEqual("100");
186
- expect(query.get("order")).toEqual("title");
187
- expect(query.get("direction")).toEqual("asc");
188
- expect(query.get("page")).toEqual(`${requests.count}`);
189
- expect(init).toEqual({});
190
- const pageSize = Number(query.get("per_page"));
191
- const page = Number(query.get("page"));
192
- return namespaces.slice((page - 1) * pageSize, page * pageSize);
193
- }
194
- );
195
- return requests;
196
- }
197
-
198
- it("should list namespaces", async () => {
199
- const KVNamespaces = [
200
- { title: "title-1", id: "id-1" },
201
- { title: "title-2", id: "id-2" },
202
- ];
203
- mockListRequest(KVNamespaces);
204
- const { error, stdout, stderr } = await runWrangler(
205
- "kv:namespace list"
206
- );
207
- expect(error).toMatchInlineSnapshot(`undefined`);
208
- expect(stderr).toMatchInlineSnapshot(`""`);
209
- const namespaces = JSON.parse(stdout);
210
- expect(namespaces).toEqual(KVNamespaces);
211
- });
212
-
213
- it("should make multiple requests for paginated results", async () => {
214
- // Create a lot of mock namespaces, so that the fetch requests will be paginated
215
- const KVNamespaces = [];
216
- for (let i = 0; i < 550; i++) {
217
- KVNamespaces.push({ title: "title-" + i, id: "id-" + i });
218
- }
219
- const requests = mockListRequest(KVNamespaces);
220
- const { stdout } = await runWrangler("kv:namespace list");
221
- const namespaces = JSON.parse(stdout);
222
- expect(namespaces).toEqual(KVNamespaces);
223
- expect(requests.count).toEqual(6);
224
- });
225
- });
226
-
227
- describe("delete", () => {
228
- function mockDeleteRequest(expectedNamespaceId: string) {
229
- const requests = { count: 0 };
230
- setMockResponse(
231
- "/accounts/:accountId/storage/kv/namespaces/:namespaceId",
232
- "DELETE",
233
- ([_url, accountId, namespaceId]) => {
234
- requests.count++;
235
- expect(accountId).toEqual("some-account-id");
236
- expect(namespaceId).toEqual(expectedNamespaceId);
237
- return null;
238
- }
239
- );
240
- return requests;
241
- }
242
-
243
- it("should delete a namespace specified by id", async () => {
244
- const requests = mockDeleteRequest("some-namespace-id");
245
- await runWrangler(
246
- `kv:namespace delete --namespace-id some-namespace-id`
247
- );
248
- expect(requests.count).toEqual(1);
249
- });
250
-
251
- it("should delete a namespace specified by binding name", async () => {
252
- writeWranglerConfig();
253
- const requests = mockDeleteRequest("bound-id");
254
- await runWrangler(
255
- `kv:namespace delete --binding someBinding --preview false`
256
- );
257
- expect(requests.count).toEqual(1);
258
- });
259
-
260
- it("should delete a preview namespace specified by binding name", async () => {
261
- writeWranglerConfig();
262
- const requests = mockDeleteRequest("preview-bound-id");
263
- await runWrangler(
264
- `kv:namespace delete --binding someBinding --preview`
265
- );
266
- expect(requests.count).toEqual(1);
267
- });
268
-
269
- it("should error if a given binding name is not in the configured kv namespaces", async () => {
270
- writeWranglerConfig();
271
- const { stderr } = await runWrangler(
272
- `kv:namespace delete --binding otherBinding`
273
- );
274
- expect(stderr).toMatchInlineSnapshot(`
275
- "wrangler kv:namespace delete
276
-
277
- Deletes a given namespace.
278
-
279
- Flags:
280
- -c, --config Path to .toml configuration file [string]
281
- -h, --help Show help [boolean]
282
- -v, --version Show version number [boolean]
283
-
284
- Options:
285
- -l, --local Run on my machine [boolean] [default: false]
286
- --binding The name of the namespace to delete [string]
287
- --namespace-id The id of the namespace to delete [string]
288
- --env Perform on a specific environment [string]
289
- --preview Interact with a preview namespace [boolean]
290
-
291
- Not able to delete namespace.
292
- A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."
293
- `);
294
- });
295
-
296
- it("should delete a namespace specified by binding name in a given environment", async () => {
297
- writeWranglerConfig();
298
- const requests = mockDeleteRequest("env-bound-id");
299
- const { stdout, stderr, error } = await runWrangler(
300
- `kv:namespace delete --binding someBinding --env some-environment --preview false`
301
- );
302
- expect(stdout).toMatchInlineSnapshot(`""`);
303
- expect(stderr).toMatchInlineSnapshot(`""`);
304
- expect(error).toMatchInlineSnapshot(`undefined`);
305
- expect(requests.count).toEqual(1);
306
- });
307
-
308
- it("should delete a preview namespace specified by binding name in a given environment", async () => {
309
- writeWranglerConfig();
310
- const requests = mockDeleteRequest("preview-env-bound-id");
311
- await runWrangler(
312
- `kv:namespace delete --binding someBinding --env some-environment --preview`
313
- );
314
- expect(requests.count).toEqual(1);
315
- });
316
- });
317
- });
318
-
319
- describe("kv:key", () => {
320
- describe("put", () => {
321
- function mockKeyPutRequest(
322
- expectedNamespaceId: string,
323
- expectedKey: string,
324
- expectedValue: string,
325
- expiration?: number,
326
- expirationTtl?: number
327
- ) {
328
- const requests = { count: 0 };
329
- setMockResponse(
330
- "/accounts/:accountId/storage/kv/namespaces/:namespaceId/values/:key",
331
- "PUT",
332
- ([_url, accountId, namespaceId, key], { body }, query) => {
333
- requests.count++;
334
- expect(accountId).toEqual("some-account-id");
335
- expect(namespaceId).toEqual(expectedNamespaceId);
336
- expect(key).toEqual(expectedKey);
337
- expect(body).toEqual(expectedValue);
338
- expect(query.get("expiration")).toEqual(`${expiration}`);
339
- expect(query.get("expiration_ttl")).toEqual(`${expirationTtl}`);
340
- return null;
341
- }
342
- );
343
- return requests;
344
- }
345
-
346
- it("should put a key in a given namespace specified by namespace-id", async () => {
347
- const requests = mockKeyPutRequest(
348
- "some-namespace-id",
349
- "my-key",
350
- "my-value"
351
- );
352
- const { error, stderr, stdout } = await runWrangler(
353
- "kv:key put my-key my-value --namespace-id some-namespace-id"
354
- );
355
- expect(requests.count).toEqual(1);
356
- expect(stdout).toMatchInlineSnapshot(
357
- `"writing the value \\"my-value\\" to key \\"my-key\\" on namespace some-namespace-id"`
358
- );
359
- expect(stderr).toMatchInlineSnapshot(`""`);
360
- expect(error).toMatchInlineSnapshot(`undefined`);
361
- });
362
-
363
- it("should put a key in a given namespace specified by binding", async () => {
364
- writeWranglerConfig();
365
- const requests = mockKeyPutRequest("bound-id", "my-key", "my-value");
366
- const { error, stderr, stdout } = await runWrangler(
367
- "kv:key put my-key my-value --binding someBinding --preview false"
368
- );
369
- expect(stdout).toMatchInlineSnapshot(
370
- `"writing the value \\"my-value\\" to key \\"my-key\\" on namespace bound-id"`
371
- );
372
- expect(stderr).toMatchInlineSnapshot(`""`);
373
- expect(error).toMatchInlineSnapshot(`undefined`);
374
- expect(requests.count).toEqual(1);
375
- });
376
-
377
- it("should put a key in a given preview namespace specified by binding", async () => {
378
- writeWranglerConfig();
379
- const requests = mockKeyPutRequest(
380
- "preview-bound-id",
381
- "my-key",
382
- "my-value"
383
- );
384
- const { error, stderr, stdout } = await runWrangler(
385
- "kv:key put my-key my-value --binding someBinding --preview"
386
- );
387
- expect(stdout).toMatchInlineSnapshot(
388
- `"writing the value \\"my-value\\" to key \\"my-key\\" on namespace preview-bound-id"`
389
- );
390
- expect(stderr).toMatchInlineSnapshot(`""`);
391
- expect(error).toMatchInlineSnapshot(`undefined`);
392
- expect(requests.count).toEqual(1);
393
- });
394
-
395
- it("should add expiration and ttl properties when putting a key", async () => {
396
- const requests = mockKeyPutRequest(
397
- "some-namespace-id",
398
- "my-key",
399
- "my-value",
400
- 10,
401
- 20
402
- );
403
- const { error, stderr, stdout } = await runWrangler(
404
- "kv:key put my-key my-value --namespace-id some-namespace-id --expiration 10 --ttl 20"
405
- );
406
- expect(requests.count).toEqual(1);
407
- expect(stdout).toMatchInlineSnapshot(
408
- `"writing the value \\"my-value\\" to key \\"my-key\\" on namespace some-namespace-id"`
409
- );
410
- expect(stderr).toMatchInlineSnapshot(`""`);
411
- expect(error).toMatchInlineSnapshot(`undefined`);
412
- });
413
-
414
- it("should put a key to the specified environment in a given namespace", async () => {
415
- writeWranglerConfig();
416
- const requests = mockKeyPutRequest(
417
- "env-bound-id",
418
- "my-key",
419
- "my-value"
420
- );
421
- const { error, stderr, stdout } = await runWrangler(
422
- "kv:key put my-key my-value --binding someBinding --env some-environment --preview false"
423
- );
424
- expect(stdout).toMatchInlineSnapshot(
425
- `"writing the value \\"my-value\\" to key \\"my-key\\" on namespace env-bound-id"`
426
- );
427
- expect(stderr).toMatchInlineSnapshot(`""`);
428
- expect(error).toMatchInlineSnapshot(`undefined`);
429
- expect(requests.count).toEqual(1);
430
- });
431
-
432
- it("should put a key with a value loaded from a given path", async () => {
433
- writeFileSync("foo.txt", "file-contents", "utf-8");
434
- const requests = mockKeyPutRequest(
435
- "some-namespace-id",
436
- "my-key",
437
- "file-contents"
438
- );
439
- const { error, stderr, stdout } = await runWrangler(
440
- "kv:key put my-key --namespace-id some-namespace-id --path foo.txt"
441
- );
442
- expect(stdout).toMatchInlineSnapshot(
443
- `"writing the contents of foo.txt to the key \\"my-key\\" on namespace some-namespace-id"`
444
- );
445
- expect(stderr).toMatchInlineSnapshot(`""`);
446
- expect(error).toMatchInlineSnapshot(`undefined`);
447
- expect(requests.count).toEqual(1);
448
- });
449
-
450
- it("should error if no key is provided", async () => {
451
- const { error, stdout, stderr } = await runWrangler("kv:key put");
452
-
453
- expect(stdout).toMatchInlineSnapshot(`""`);
454
- expect(stderr).toMatchInlineSnapshot(`
455
- "wrangler kv:key put <key> [value]
456
-
457
- Writes a single key/value pair to the given namespace.
458
-
459
- Positionals:
460
- key The key to write to. [string] [required]
461
- value The value to write. [string]
462
-
463
- Flags:
464
- -c, --config Path to .toml configuration file [string]
465
- -h, --help Show help [boolean]
466
- -v, --version Show version number [boolean]
467
-
468
- Options:
469
- -l, --local Run on my machine [boolean] [default: false]
470
- --binding The binding of the namespace to write to. [string]
471
- --namespace-id The id of the namespace to write to. [string]
472
- --env Perform on a specific environment [string]
473
- --preview Interact with a preview namespace [boolean]
474
- --ttl Time for which the entries should be visible. [number]
475
- --expiration Time since the UNIX epoch after which the entry expires [number]
476
- --path Read value from the file at a given path. [string]
477
-
478
- Not enough non-option arguments: got 0, need at least 1"
479
- `);
480
- expect(error).toMatchInlineSnapshot(
481
- `[Error: Not enough non-option arguments: got 0, need at least 1]`
482
- );
483
- });
484
-
485
- it("should error if no binding nor namespace is provided", async () => {
486
- const { error, stdout, stderr } = await runWrangler(
487
- "kv:key put foo bar"
488
- );
489
-
490
- expect(stdout).toMatchInlineSnapshot(`""`);
491
- expect(stderr).toMatchInlineSnapshot(`
492
- "wrangler kv:key put <key> [value]
493
-
494
- Writes a single key/value pair to the given namespace.
495
-
496
- Positionals:
497
- key The key to write to. [string] [required]
498
- value The value to write. [string]
499
-
500
- Flags:
501
- -c, --config Path to .toml configuration file [string]
502
- -h, --help Show help [boolean]
503
- -v, --version Show version number [boolean]
504
-
505
- Options:
506
- -l, --local Run on my machine [boolean] [default: false]
507
- --binding The binding of the namespace to write to. [string]
508
- --namespace-id The id of the namespace to write to. [string]
509
- --env Perform on a specific environment [string]
510
- --preview Interact with a preview namespace [boolean]
511
- --ttl Time for which the entries should be visible. [number]
512
- --expiration Time since the UNIX epoch after which the entry expires [number]
513
- --path Read value from the file at a given path. [string]
514
-
515
- Exactly one of the arguments binding and namespace-id is required"
516
- `);
517
- expect(error).toMatchInlineSnapshot(
518
- `[Error: Exactly one of the arguments binding and namespace-id is required]`
519
- );
520
- });
521
-
522
- it("should error if both binding and namespace is provided", async () => {
523
- const { error, stdout, stderr } = await runWrangler(
524
- "kv:key put foo bar --binding x --namespace-id y"
525
- );
526
-
527
- expect(stdout).toMatchInlineSnapshot(`""`);
528
- expect(stderr).toMatchInlineSnapshot(`
529
- "wrangler kv:key put <key> [value]
530
-
531
- Writes a single key/value pair to the given namespace.
532
-
533
- Positionals:
534
- key The key to write to. [string] [required]
535
- value The value to write. [string]
536
-
537
- Flags:
538
- -c, --config Path to .toml configuration file [string]
539
- -h, --help Show help [boolean]
540
- -v, --version Show version number [boolean]
541
-
542
- Options:
543
- -l, --local Run on my machine [boolean] [default: false]
544
- --binding The binding of the namespace to write to. [string]
545
- --namespace-id The id of the namespace to write to. [string]
546
- --env Perform on a specific environment [string]
547
- --preview Interact with a preview namespace [boolean]
548
- --ttl Time for which the entries should be visible. [number]
549
- --expiration Time since the UNIX epoch after which the entry expires [number]
550
- --path Read value from the file at a given path. [string]
551
-
552
- Arguments binding and namespace-id are mutually exclusive"
553
- `);
554
- expect(error).toMatchInlineSnapshot(
555
- `[Error: Arguments binding and namespace-id are mutually exclusive]`
556
- );
557
- });
558
-
559
- it("should error if no value nor path is provided", async () => {
560
- const { error, stdout, stderr } = await runWrangler(
561
- "kv:key put key --namespace-id 12345"
562
- );
563
-
564
- expect(stdout).toMatchInlineSnapshot(`""`);
565
- expect(stderr).toMatchInlineSnapshot(`
566
- "wrangler kv:key put <key> [value]
567
-
568
- Writes a single key/value pair to the given namespace.
569
-
570
- Positionals:
571
- key The key to write to. [string] [required]
572
- value The value to write. [string]
573
-
574
- Flags:
575
- -c, --config Path to .toml configuration file [string]
576
- -h, --help Show help [boolean]
577
- -v, --version Show version number [boolean]
578
-
579
- Options:
580
- -l, --local Run on my machine [boolean] [default: false]
581
- --binding The binding of the namespace to write to. [string]
582
- --namespace-id The id of the namespace to write to. [string]
583
- --env Perform on a specific environment [string]
584
- --preview Interact with a preview namespace [boolean]
585
- --ttl Time for which the entries should be visible. [number]
586
- --expiration Time since the UNIX epoch after which the entry expires [number]
587
- --path Read value from the file at a given path. [string]
588
-
589
- Exactly one of the arguments value and path is required"
590
- `);
591
- expect(error).toMatchInlineSnapshot(
592
- `[Error: Exactly one of the arguments value and path is required]`
593
- );
594
- });
595
-
596
- it("should error if both value and path is provided", async () => {
597
- const { error, stdout, stderr } = await runWrangler(
598
- "kv:key put key value --path xyz --namespace-id 12345"
599
- );
600
-
601
- expect(stdout).toMatchInlineSnapshot(`""`);
602
- expect(stderr).toMatchInlineSnapshot(`
603
- "wrangler kv:key put <key> [value]
604
-
605
- Writes a single key/value pair to the given namespace.
606
-
607
- Positionals:
608
- key The key to write to. [string] [required]
609
- value The value to write. [string]
610
-
611
- Flags:
612
- -c, --config Path to .toml configuration file [string]
613
- -h, --help Show help [boolean]
614
- -v, --version Show version number [boolean]
615
-
616
- Options:
617
- -l, --local Run on my machine [boolean] [default: false]
618
- --binding The binding of the namespace to write to. [string]
619
- --namespace-id The id of the namespace to write to. [string]
620
- --env Perform on a specific environment [string]
621
- --preview Interact with a preview namespace [boolean]
622
- --ttl Time for which the entries should be visible. [number]
623
- --expiration Time since the UNIX epoch after which the entry expires [number]
624
- --path Read value from the file at a given path. [string]
625
-
626
- Arguments value and path are mutually exclusive"
627
- `);
628
- expect(error).toMatchInlineSnapshot(
629
- `[Error: Arguments value and path are mutually exclusive]`
630
- );
631
- });
632
-
633
- it("should error if a given binding name is not in the configured kv namespaces", async () => {
634
- writeWranglerConfig();
635
- const { error, stdout, stderr } = await runWrangler(
636
- `kv:key put key value --binding otherBinding`
637
- );
638
- expect(stdout).toMatchInlineSnapshot(`""`);
639
- expect(stderr).toMatchInlineSnapshot(
640
- `"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
641
- );
642
- expect(error).toMatchInlineSnapshot(
643
- `[Error: A namespace with binding name "otherBinding" was not found in the configured "kv_namespaces".]`
644
- );
645
- });
646
-
647
- it("should error if a given binding has both preview and non-preview and --preview is not specified", async () => {
648
- writeWranglerConfig();
649
- const requests = mockKeyPutRequest(
650
- "preview-bound-id",
651
- "my-key",
652
- "my-value"
653
- );
654
- const { error, stderr, stdout } = await runWrangler(
655
- "kv:key put my-key my-value --binding someBinding"
656
- );
657
- expect(stdout).toMatchInlineSnapshot(`""`);
658
- expect(stderr).toMatchInlineSnapshot(
659
- `"someBinding has both a namespace ID and a preview ID. Specify \\"--preview\\" or \\"--preview false\\" to avoid writing data to the wrong namespace."`
660
- );
661
- expect(error).toMatchInlineSnapshot(
662
- `[Error: someBinding has both a namespace ID and a preview ID. Specify "--preview" or "--preview false" to avoid writing data to the wrong namespace.]`
663
- );
664
- expect(requests.count).toEqual(0);
665
- });
666
- });
667
-
668
- describe("list", () => {
669
- function mockKeyListRequest(
670
- expectedNamespaceId: string,
671
- expectedKeys: string[],
672
- keysPerRequest = 1000
673
- ) {
674
- const requests = { count: 0 };
675
- setMockRawResponse(
676
- "/accounts/:accountId/storage/kv/namespaces/:namespaceId/keys",
677
- ([_url, accountId, namespaceId], _init, query) => {
678
- requests.count++;
679
- expect(accountId).toEqual("some-account-id");
680
- expect(namespaceId).toEqual(expectedNamespaceId);
681
- if (expectedKeys.length <= keysPerRequest) {
682
- return createFetchResult(expectedKeys);
683
- } else {
684
- const start = parseInt(query.get("cursor")) || 0;
685
- const end = start + keysPerRequest;
686
- const cursor = end < expectedKeys.length ? end : undefined;
687
- return createFetchResult(
688
- expectedKeys.slice(start, end),
689
- true,
690
- [],
691
- [],
692
- { cursor }
693
- );
694
- }
695
- }
696
- );
697
- return requests;
698
- }
699
-
700
- it("should list the keys of a namespace specified by namespace-id", async () => {
701
- const keys = ["key-1", "key-2", "key-3"];
702
- mockKeyListRequest("some-namespace-id", keys);
703
- const { error, stdout, stderr } = await runWrangler(
704
- "kv:key list --namespace-id some-namespace-id"
705
- );
706
- expect(error).toMatchInlineSnapshot(`undefined`);
707
- expect(stderr).toMatchInlineSnapshot(`""`);
708
- expect(stdout).toMatchInlineSnapshot(`
709
- "key-1
710
- key-2
711
- key-3"
712
- `);
713
- });
714
-
715
- it("should list the keys of a namespace specified by binding", async () => {
716
- writeWranglerConfig();
717
- const keys = ["key-1", "key-2", "key-3"];
718
- mockKeyListRequest("bound-id", keys);
719
- const { error, stdout, stderr } = await runWrangler(
720
- "kv:key list --binding someBinding"
721
- );
722
- expect(error).toMatchInlineSnapshot(`undefined`);
723
- expect(stderr).toMatchInlineSnapshot(`""`);
724
- expect(stdout).toMatchInlineSnapshot(`
725
- "key-1
726
- key-2
727
- key-3"
728
- `);
729
- });
730
-
731
- it("should list the keys of a preview namespace specified by binding", async () => {
732
- writeWranglerConfig();
733
- const keys = ["key-1", "key-2", "key-3"];
734
- mockKeyListRequest("preview-bound-id", keys);
735
- const { error, stdout, stderr } = await runWrangler(
736
- "kv:key list --binding someBinding --preview"
737
- );
738
- expect(error).toMatchInlineSnapshot(`undefined`);
739
- expect(stderr).toMatchInlineSnapshot(`""`);
740
- expect(stdout).toMatchInlineSnapshot(`
741
- "key-1
742
- key-2
743
- key-3"
744
- `);
745
- });
746
-
747
- it("should list the keys of a namespace specified by binding, in a given environment", async () => {
748
- writeWranglerConfig();
749
- const keys = ["key-1", "key-2", "key-3"];
750
- mockKeyListRequest("env-bound-id", keys);
751
- const { error, stdout, stderr } = await runWrangler(
752
- "kv:key list --binding someBinding --env some-environment"
753
- );
754
- expect(error).toMatchInlineSnapshot(`undefined`);
755
- expect(stderr).toMatchInlineSnapshot(`""`);
756
- expect(stdout).toMatchInlineSnapshot(`
757
- "key-1
758
- key-2
759
- key-3"
760
- `);
761
- });
762
-
763
- it("should list the keys of a preview namespace specified by binding, in a given environment", async () => {
764
- writeWranglerConfig();
765
- const keys = ["key-1", "key-2", "key-3"];
766
- mockKeyListRequest("preview-env-bound-id", keys);
767
- const { error, stdout, stderr } = await runWrangler(
768
- "kv:key list --binding someBinding --preview --env some-environment"
769
- );
770
- expect(error).toMatchInlineSnapshot(`undefined`);
771
- expect(stderr).toMatchInlineSnapshot(`""`);
772
- expect(stdout).toMatchInlineSnapshot(`
773
- "key-1
774
- key-2
775
- key-3"
776
- `);
777
- });
778
-
779
- it("should make multiple requests for paginated results", async () => {
780
- // Create a lot of mock keys, so that the fetch requests will be paginated
781
- const keys = [];
782
- for (let i = 0; i < 550; i++) {
783
- keys.push("key-" + i);
784
- }
785
- // Ask for the keys in pages of size 100.
786
- const requests = mockKeyListRequest("some-namespace-id", keys, 100);
787
- const { stdout, stderr, error } = await runWrangler(
788
- "kv:key list --namespace-id some-namespace-id --limit 100"
789
- );
790
- expect(error).toMatchInlineSnapshot(`undefined`);
791
- expect(stderr).toMatchInlineSnapshot(`""`);
792
- expect(stdout).toEqual(keys.join("\n"));
793
- expect(requests.count).toEqual(6);
794
- });
795
-
796
- it("should error if a given binding name is not in the configured kv namespaces", async () => {
797
- writeWranglerConfig();
798
- const { error, stdout, stderr } = await runWrangler(
799
- "kv:key list --binding otherBinding"
800
- );
801
- expect(error).toMatchInlineSnapshot(
802
- `[Error: A namespace with binding name "otherBinding" was not found in the configured "kv_namespaces".]`
803
- );
804
- expect(stderr).toMatchInlineSnapshot(
805
- `"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
806
- );
807
- expect(stdout).toMatchInlineSnapshot(`""`);
808
- });
809
- });
810
-
811
- describe("get", () => {
812
- function mockKeyGetRequest(
813
- expectedNamespaceId: string,
814
- expectedKey: string,
815
- expectedValue: string
816
- ) {
817
- const requests = { count: 0 };
818
- setMockRawResponse(
819
- "/accounts/:accountId/storage/kv/namespaces/:namespaceId/values/:key",
820
- ([_url, accountId, namespaceId, key]) => {
821
- requests.count++;
822
- expect(accountId).toEqual("some-account-id");
823
- expect(namespaceId).toEqual(expectedNamespaceId);
824
- expect(key).toEqual(expectedKey);
825
- return expectedValue;
826
- }
827
- );
828
- return requests;
829
- }
830
-
831
- it("should get a key in a given namespace specified by namespace-id", async () => {
832
- const requests = mockKeyGetRequest(
833
- "some-namespace-id",
834
- "my-key",
835
- "my-value"
836
- );
837
- const { error, stderr, stdout } = await runWrangler(
838
- "kv:key get my-key --namespace-id some-namespace-id"
839
- );
840
- expect(stdout).toMatchInlineSnapshot(`"my-value"`);
841
- expect(stderr).toMatchInlineSnapshot(`""`);
842
- expect(error).toMatchInlineSnapshot(`undefined`);
843
- expect(requests.count).toEqual(1);
844
- });
845
-
846
- it("should get a key in a given namespace specified by binding", async () => {
847
- writeWranglerConfig();
848
- const requests = mockKeyGetRequest("bound-id", "my-key", "my-value");
849
- const { error, stderr, stdout } = await runWrangler(
850
- "kv:key get my-key --binding someBinding --preview false"
851
- );
852
- expect(stdout).toMatchInlineSnapshot(`"my-value"`);
853
- expect(stderr).toMatchInlineSnapshot(`""`);
854
- expect(error).toMatchInlineSnapshot(`undefined`);
855
- expect(requests.count).toEqual(1);
856
- });
857
-
858
- it("should get a key in a given preview namespace specified by binding", async () => {
859
- writeWranglerConfig();
860
- const requests = mockKeyGetRequest(
861
- "preview-bound-id",
862
- "my-key",
863
- "my-value"
864
- );
865
- const { error, stderr, stdout } = await runWrangler(
866
- "kv:key get my-key --binding someBinding --preview"
867
- );
868
- expect(stdout).toMatchInlineSnapshot(`"my-value"`);
869
- expect(stderr).toMatchInlineSnapshot(`""`);
870
- expect(error).toMatchInlineSnapshot(`undefined`);
871
- expect(requests.count).toEqual(1);
872
- });
873
-
874
- it("should get a key for the specified environment in a given namespace", async () => {
875
- writeWranglerConfig();
876
- const requests = mockKeyGetRequest(
877
- "env-bound-id",
878
- "my-key",
879
- "my-value"
880
- );
881
- const { error, stderr, stdout } = await runWrangler(
882
- "kv:key get my-key my-value --binding someBinding --env some-environment --preview false"
883
- );
884
- expect(stdout).toMatchInlineSnapshot(`"my-value"`);
885
- expect(stderr).toMatchInlineSnapshot(`""`);
886
- expect(error).toMatchInlineSnapshot(`undefined`);
887
- expect(requests.count).toEqual(1);
888
- });
889
-
890
- it("should error if no key is provided", async () => {
891
- const { error, stdout, stderr } = await runWrangler("kv:key get");
892
-
893
- expect(stdout).toMatchInlineSnapshot(`""`);
894
- expect(stderr).toMatchInlineSnapshot(`
895
- "wrangler kv:key get <key>
896
-
897
- Reads a single value by key from the given namespace.
898
-
899
- Positionals:
900
- key The key value to get. [string] [required]
901
-
902
- Flags:
903
- -c, --config Path to .toml configuration file [string]
904
- -h, --help Show help [boolean]
905
- -v, --version Show version number [boolean]
906
-
907
- Options:
908
- -l, --local Run on my machine [boolean] [default: false]
909
- --binding The name of the namespace to get from [string]
910
- --namespace-id The id of the namespace to get from [string]
911
- --env Perform on a specific environment [string]
912
- --preview Interact with a preview namespace [boolean] [default: false]
913
-
914
- Not enough non-option arguments: got 0, need at least 1"
915
- `);
916
- expect(error).toMatchInlineSnapshot(
917
- `[Error: Not enough non-option arguments: got 0, need at least 1]`
918
- );
919
- });
920
-
921
- it("should error if no binding nor namespace is provided", async () => {
922
- const { error, stdout, stderr } = await runWrangler("kv:key get foo");
923
-
924
- expect(stdout).toMatchInlineSnapshot(`""`);
925
- expect(stderr).toMatchInlineSnapshot(`
926
- "wrangler kv:key get <key>
927
-
928
- Reads a single value by key from the given namespace.
929
-
930
- Positionals:
931
- key The key value to get. [string] [required]
932
-
933
- Flags:
934
- -c, --config Path to .toml configuration file [string]
935
- -h, --help Show help [boolean]
936
- -v, --version Show version number [boolean]
937
-
938
- Options:
939
- -l, --local Run on my machine [boolean] [default: false]
940
- --binding The name of the namespace to get from [string]
941
- --namespace-id The id of the namespace to get from [string]
942
- --env Perform on a specific environment [string]
943
- --preview Interact with a preview namespace [boolean] [default: false]
944
-
945
- Exactly one of the arguments binding and namespace-id is required"
946
- `);
947
- expect(error).toMatchInlineSnapshot(
948
- `[Error: Exactly one of the arguments binding and namespace-id is required]`
949
- );
950
- });
951
-
952
- it("should error if both binding and namespace is provided", async () => {
953
- const { error, stdout, stderr } = await runWrangler(
954
- "kv:key get foo --binding x --namespace-id y"
955
- );
956
-
957
- expect(stdout).toMatchInlineSnapshot(`""`);
958
- expect(stderr).toMatchInlineSnapshot(`
959
- "wrangler kv:key get <key>
960
-
961
- Reads a single value by key from the given namespace.
962
-
963
- Positionals:
964
- key The key value to get. [string] [required]
965
-
966
- Flags:
967
- -c, --config Path to .toml configuration file [string]
968
- -h, --help Show help [boolean]
969
- -v, --version Show version number [boolean]
970
-
971
- Options:
972
- -l, --local Run on my machine [boolean] [default: false]
973
- --binding The name of the namespace to get from [string]
974
- --namespace-id The id of the namespace to get from [string]
975
- --env Perform on a specific environment [string]
976
- --preview Interact with a preview namespace [boolean] [default: false]
977
-
978
- Arguments binding and namespace-id are mutually exclusive"
979
- `);
980
- expect(error).toMatchInlineSnapshot(
981
- `[Error: Arguments binding and namespace-id are mutually exclusive]`
982
- );
983
- });
984
-
985
- it("should error if a given binding name is not in the configured kv namespaces", async () => {
986
- writeWranglerConfig();
987
- const { error, stdout, stderr } = await runWrangler(
988
- `kv:key get key --binding otherBinding`
989
- );
990
- expect(stdout).toMatchInlineSnapshot(`""`);
991
- expect(stderr).toMatchInlineSnapshot(
992
- `"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
993
- );
994
- expect(error).toMatchInlineSnapshot(
995
- `[Error: A namespace with binding name "otherBinding" was not found in the configured "kv_namespaces".]`
996
- );
997
- });
998
- });
999
-
1000
- describe("delete", () => {
1001
- function mockDeleteRequest(
1002
- expectedNamespaceId: string,
1003
- expectedKey: string
1004
- ) {
1005
- const requests = { count: 0 };
1006
- setMockResponse(
1007
- "/accounts/:accountId/storage/kv/namespaces/:namespaceId/values/:key",
1008
- "DELETE",
1009
- ([_url, accountId, namespaceId, key]) => {
1010
- requests.count++;
1011
- expect(accountId).toEqual("some-account-id");
1012
- expect(namespaceId).toEqual(expectedNamespaceId);
1013
- expect(key).toEqual(expectedKey);
1014
- return null;
1015
- }
1016
- );
1017
- return requests;
1018
- }
1019
-
1020
- it("should delete a key in a namespace specified by id", async () => {
1021
- const requests = mockDeleteRequest("some-namespace-id", "someKey");
1022
- await runWrangler(
1023
- `kv:key delete --namespace-id some-namespace-id someKey`
1024
- );
1025
- expect(requests.count).toEqual(1);
1026
- });
1027
-
1028
- it("should delete a key in a namespace specified by binding name", async () => {
1029
- writeWranglerConfig();
1030
- const requests = mockDeleteRequest("bound-id", "someKey");
1031
- await runWrangler(
1032
- `kv:key delete --binding someBinding --preview false someKey`
1033
- );
1034
- expect(requests.count).toEqual(1);
1035
- });
1036
-
1037
- it("should delete a key in a preview namespace specified by binding name", async () => {
1038
- writeWranglerConfig();
1039
- const requests = mockDeleteRequest("preview-bound-id", "someKey");
1040
- await runWrangler(
1041
- `kv:key delete --binding someBinding --preview someKey`
1042
- );
1043
- expect(requests.count).toEqual(1);
1044
- });
1045
-
1046
- it("should error if a given binding name is not in the configured kv namespaces", async () => {
1047
- writeWranglerConfig();
1048
- const { stderr } = await runWrangler(
1049
- `kv:key delete --binding otherBinding someKey`
1050
- );
1051
- expect(stderr).toMatchInlineSnapshot(
1052
- `"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
1053
- );
1054
- });
1055
-
1056
- it("should delete a key in a namespace specified by binding name in a given environment", async () => {
1057
- writeWranglerConfig();
1058
- const requests = mockDeleteRequest("env-bound-id", "someKey");
1059
- const { stdout, stderr, error } = await runWrangler(
1060
- `kv:key delete --binding someBinding --env some-environment --preview false someKey`
1061
- );
1062
- expect(stdout).toMatchInlineSnapshot(
1063
- `"deleting the key \\"someKey\\" on namespace env-bound-id"`
1064
- );
1065
- expect(stderr).toMatchInlineSnapshot(`""`);
1066
- expect(error).toMatchInlineSnapshot(`undefined`);
1067
- expect(requests.count).toEqual(1);
1068
- });
1069
-
1070
- it("should delete a key in a preview namespace specified by binding name in a given environment", async () => {
1071
- writeWranglerConfig();
1072
- const requests = mockDeleteRequest("preview-env-bound-id", "someKey");
1073
- await runWrangler(
1074
- `kv:key delete --binding someBinding --env some-environment --preview someKey`
1075
- );
1076
- expect(requests.count).toEqual(1);
1077
- });
1078
- });
1079
- });
1080
- });
1081
-
1082
- function writeWranglerConfig() {
1083
- writeFileSync(
1084
- "./wrangler.toml",
1085
- [
1086
- 'name = "otherWorker"',
1087
- "kv_namespaces = [",
1088
- ' { binding = "someBinding", id = "bound-id", preview_id = "preview-bound-id" }',
1089
- "]",
1090
- "",
1091
- "[env.some-environment]",
1092
- "kv_namespaces = [",
1093
- ' { binding = "someBinding", id = "env-bound-id", preview_id = "preview-env-bound-id" }',
1094
- "]",
1095
- ].join("\n"),
1096
- "utf-8"
1097
- );
1098
- }