wrangler 0.0.0-e2f9bb2 → 0.0.0-e322475

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 (103) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +3 -1
  3. package/bin/wrangler.js +36 -4
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +15 -7
  6. package/pages/functions/buildPlugin.ts +13 -0
  7. package/pages/functions/buildWorker.ts +14 -1
  8. package/pages/functions/template-plugin.ts +3 -2
  9. package/src/__tests__/configuration.test.ts +652 -229
  10. package/src/__tests__/dev.test.tsx +372 -79
  11. package/src/__tests__/helpers/mock-cfetch.ts +2 -2
  12. package/src/__tests__/helpers/mock-console.ts +11 -1
  13. package/src/__tests__/helpers/mock-dialogs.ts +75 -11
  14. package/src/__tests__/helpers/mock-process.ts +24 -0
  15. package/src/__tests__/index.test.ts +81 -72
  16. package/src/__tests__/init.test.ts +1360 -410
  17. package/src/__tests__/jest.setup.ts +38 -0
  18. package/src/__tests__/kv.test.ts +218 -152
  19. package/src/__tests__/logger.test.ts +26 -0
  20. package/src/__tests__/package-manager.test.ts +154 -7
  21. package/src/__tests__/pages.test.ts +478 -53
  22. package/src/__tests__/parse.test.ts +8 -0
  23. package/src/__tests__/publish.test.ts +1614 -333
  24. package/src/__tests__/r2.test.ts +55 -36
  25. package/src/__tests__/secret.test.ts +39 -4
  26. package/src/__tests__/user.test.ts +1 -0
  27. package/src/__tests__/whoami.test.tsx +34 -0
  28. package/src/abort.d.ts +3 -0
  29. package/src/bundle-reporter.tsx +29 -0
  30. package/src/bundle.ts +42 -7
  31. package/src/cfetch/index.ts +21 -4
  32. package/src/cfetch/internal.ts +25 -20
  33. package/src/config/config.ts +11 -2
  34. package/src/config/environment.ts +41 -15
  35. package/src/config/index.ts +162 -0
  36. package/src/config/validation-helpers.ts +10 -1
  37. package/src/config/validation.ts +234 -78
  38. package/src/create-worker-preview.ts +32 -22
  39. package/src/create-worker-upload-form.ts +22 -8
  40. package/src/dev/dev.tsx +48 -67
  41. package/src/dev/local.tsx +16 -7
  42. package/src/dev/remote.tsx +57 -21
  43. package/src/dev/use-esbuild.ts +1 -7
  44. package/src/dialogs.tsx +48 -0
  45. package/src/durable.ts +102 -0
  46. package/src/entry.ts +71 -10
  47. package/src/generate-auth-url.ts +33 -0
  48. package/src/generate-random-state.ts +16 -0
  49. package/src/git-client.ts +42 -0
  50. package/src/index.tsx +619 -338
  51. package/src/inspect.ts +39 -0
  52. package/src/kv.ts +116 -27
  53. package/src/logger.ts +8 -1
  54. package/src/open-in-browser.ts +3 -12
  55. package/src/package-manager.ts +50 -3
  56. package/src/pages.tsx +434 -207
  57. package/src/parse.ts +44 -5
  58. package/src/proxy.ts +66 -44
  59. package/src/publish.ts +407 -137
  60. package/src/sites.tsx +103 -28
  61. package/src/user.tsx +35 -26
  62. package/src/whoami.tsx +3 -2
  63. package/src/worker.ts +10 -1
  64. package/src/zones.ts +73 -0
  65. package/templates/new-worker-scheduled.js +17 -0
  66. package/templates/new-worker-scheduled.ts +32 -0
  67. package/templates/new-worker.ts +16 -1
  68. package/templates/no-op-worker.js +10 -0
  69. package/templates/static-asset-facade.js +2 -6
  70. package/wrangler-dist/cli.js +46122 -32396
  71. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  72. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  73. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  74. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  75. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  76. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  77. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  78. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  79. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  80. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  81. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  82. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  83. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  84. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  85. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  86. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  87. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  88. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  89. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  90. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  91. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  92. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  93. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  94. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  95. package/vendor/wrangler-mime/LICENSE +0 -21
  96. package/vendor/wrangler-mime/Mime.js +0 -97
  97. package/vendor/wrangler-mime/README.md +0 -187
  98. package/vendor/wrangler-mime/cli.js +0 -46
  99. package/vendor/wrangler-mime/index.js +0 -4
  100. package/vendor/wrangler-mime/lite.js +0 -4
  101. package/vendor/wrangler-mime/package.json +0 -52
  102. package/vendor/wrangler-mime/types/other.js +0 -1
  103. package/vendor/wrangler-mime/types/standard.js +0 -1
@@ -10,6 +10,7 @@ import {
10
10
  import { mockConsoleMethods } from "./helpers/mock-console";
11
11
  import { clearConfirmMocks, mockConfirm } from "./helpers/mock-dialogs";
12
12
  import { mockKeyListRequest } from "./helpers/mock-kv";
13
+ import { mockProcess } from "./helpers/mock-process";
13
14
  import { runInTempDir } from "./helpers/run-in-tmp";
14
15
  import { runWrangler } from "./helpers/run-wrangler";
15
16
  import type { KeyValue, KVNamespaceInfo, NamespaceKeyInfo } from "../kv";
@@ -19,6 +20,7 @@ describe("wrangler", () => {
19
20
  mockApiToken();
20
21
  runInTempDir();
21
22
  const std = mockConsoleMethods();
23
+ const proc = mockProcess();
22
24
 
23
25
  afterEach(() => {
24
26
  unsetAllMocks();
@@ -48,10 +50,7 @@ describe("wrangler", () => {
48
50
  );
49
51
  expect(std.out).toMatchInlineSnapshot(`
50
52
  "
51
- "
52
- `);
53
- expect(std.err).toMatchInlineSnapshot(`
54
- "wrangler kv:namespace create <namespace>
53
+ wrangler kv:namespace create <namespace>
55
54
 
56
55
  Create a new namespace
57
56
 
@@ -59,15 +58,16 @@ describe("wrangler", () => {
59
58
  namespace The name of the new namespace [string] [required]
60
59
 
61
60
  Flags:
62
- -c, --config Path to .toml configuration file [string]
63
- -h, --help Show help [boolean]
64
- -v, --version Show version number [boolean]
65
- --legacy-env Use legacy environments [boolean]
61
+ -c, --config Path to .toml configuration file [string]
62
+ -h, --help Show help [boolean]
63
+ -v, --version Show version number [boolean]
66
64
 
67
65
  Options:
68
66
  -e, --env Perform on a specific environment [string]
69
- --preview Interact with a preview namespace [boolean]
70
- X [ERROR] Not enough non-option arguments: got 0, need at least 1
67
+ --preview Interact with a preview namespace [boolean]"
68
+ `);
69
+ expect(std.err).toMatchInlineSnapshot(`
70
+ "X [ERROR] Not enough non-option arguments: got 0, need at least 1
71
71
 
72
72
  "
73
73
  `);
@@ -81,10 +81,7 @@ describe("wrangler", () => {
81
81
  );
82
82
  expect(std.out).toMatchInlineSnapshot(`
83
83
  "
84
- "
85
- `);
86
- expect(std.err).toMatchInlineSnapshot(`
87
- "wrangler kv:namespace create <namespace>
84
+ wrangler kv:namespace create <namespace>
88
85
 
89
86
  Create a new namespace
90
87
 
@@ -92,15 +89,16 @@ describe("wrangler", () => {
92
89
  namespace The name of the new namespace [string] [required]
93
90
 
94
91
  Flags:
95
- -c, --config Path to .toml configuration file [string]
96
- -h, --help Show help [boolean]
97
- -v, --version Show version number [boolean]
98
- --legacy-env Use legacy environments [boolean]
92
+ -c, --config Path to .toml configuration file [string]
93
+ -h, --help Show help [boolean]
94
+ -v, --version Show version number [boolean]
99
95
 
100
96
  Options:
101
97
  -e, --env Perform on a specific environment [string]
102
- --preview Interact with a preview namespace [boolean]
103
- X [ERROR] Unknown arguments: def, ghi
98
+ --preview Interact with a preview namespace [boolean]"
99
+ `);
100
+ expect(std.err).toMatchInlineSnapshot(`
101
+ "X [ERROR] Unknown arguments: def, ghi
104
102
 
105
103
  "
106
104
  `);
@@ -115,10 +113,7 @@ describe("wrangler", () => {
115
113
 
116
114
  expect(std.out).toMatchInlineSnapshot(`
117
115
  "
118
- "
119
- `);
120
- expect(std.err).toMatchInlineSnapshot(`
121
- "wrangler kv:namespace create <namespace>
116
+ wrangler kv:namespace create <namespace>
122
117
 
123
118
  Create a new namespace
124
119
 
@@ -126,15 +121,16 @@ describe("wrangler", () => {
126
121
  namespace The name of the new namespace [string] [required]
127
122
 
128
123
  Flags:
129
- -c, --config Path to .toml configuration file [string]
130
- -h, --help Show help [boolean]
131
- -v, --version Show version number [boolean]
132
- --legacy-env Use legacy environments [boolean]
124
+ -c, --config Path to .toml configuration file [string]
125
+ -h, --help Show help [boolean]
126
+ -v, --version Show version number [boolean]
133
127
 
134
128
  Options:
135
129
  -e, --env Perform on a specific environment [string]
136
- --preview Interact with a preview namespace [boolean]
137
- X [ERROR] The namespace binding name \\"abc-def\\" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number.
130
+ --preview Interact with a preview namespace [boolean]"
131
+ `);
132
+ expect(std.err).toMatchInlineSnapshot(`
133
+ "X [ERROR] The namespace binding name \\"abc-def\\" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number.
138
134
 
139
135
  "
140
136
  `);
@@ -286,22 +282,7 @@ describe("wrangler", () => {
286
282
  A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."
287
283
  `);
288
284
  expect(std.err).toMatchInlineSnapshot(`
289
- "wrangler kv:namespace delete
290
-
291
- Deletes a given namespace.
292
-
293
- Flags:
294
- -c, --config Path to .toml configuration file [string]
295
- -h, --help Show help [boolean]
296
- -v, --version Show version number [boolean]
297
- --legacy-env Use legacy environments [boolean]
298
-
299
- Options:
300
- --binding The name of the namespace to delete [string]
301
- --namespace-id The id of the namespace to delete [string]
302
- -e, --env Perform on a specific environment [string]
303
- --preview Interact with a preview namespace [boolean]
304
- X [ERROR] Not able to delete namespace.
285
+ "X [ERROR] Not able to delete namespace.
305
286
 
306
287
  A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
307
288
 
@@ -385,6 +366,21 @@ describe("wrangler", () => {
385
366
  expect(std.err).toMatchInlineSnapshot(`""`);
386
367
  });
387
368
 
369
+ it("should encode the key in the api request to put a value", async () => {
370
+ const requests = mockKeyPutRequest("DS9", {
371
+ key: "%2Fmy-key",
372
+ value: "my-value",
373
+ });
374
+
375
+ await runWrangler("kv:key put /my-key my-value --namespace-id DS9");
376
+
377
+ expect(requests.count).toEqual(1);
378
+ expect(std.out).toMatchInlineSnapshot(
379
+ `"Writing the value \\"my-value\\" to key \\"/my-key\\" on namespace DS9."`
380
+ );
381
+ expect(std.err).toMatchInlineSnapshot(`""`);
382
+ });
383
+
388
384
  it("should put a key in a given namespace specified by binding", async () => {
389
385
  writeWranglerConfig();
390
386
  const requests = mockKeyPutRequest("bound-id", {
@@ -454,10 +450,11 @@ describe("wrangler", () => {
454
450
  });
455
451
 
456
452
  it("should put a key with a value loaded from a given path", async () => {
457
- writeFileSync("foo.txt", "file-contents", "utf-8");
453
+ const buf = Buffer.from("file-contents", "utf-8");
454
+ writeFileSync("foo.txt", buf);
458
455
  const requests = mockKeyPutRequest("some-namespace-id", {
459
456
  key: "my-key",
460
- value: "file-contents",
457
+ value: buf,
461
458
  });
462
459
  await runWrangler(
463
460
  "kv:key put my-key --namespace-id some-namespace-id --path foo.txt"
@@ -469,6 +466,26 @@ describe("wrangler", () => {
469
466
  expect(requests.count).toEqual(1);
470
467
  });
471
468
 
469
+ it("should put a key with a binary value loaded from a given path", async () => {
470
+ const buf = Buffer.from(
471
+ "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAiSURBVHgB7coxEQAACMPAgH/PgAM6dGwu49fA/deIBXrgAj2cAhIFT4QxAAAAAElFTkSuQmCC",
472
+ "base64"
473
+ );
474
+ writeFileSync("test.png", buf);
475
+ const requests = mockKeyPutRequest("another-namespace-id", {
476
+ key: "my-key",
477
+ value: buf,
478
+ });
479
+ await runWrangler(
480
+ "kv:key put my-key --namespace-id another-namespace-id --path test.png"
481
+ );
482
+ expect(std.out).toMatchInlineSnapshot(
483
+ `"Writing the contents of test.png to the key \\"my-key\\" on namespace another-namespace-id."`
484
+ );
485
+ expect(std.err).toMatchInlineSnapshot(`""`);
486
+ expect(requests.count).toEqual(1);
487
+ });
488
+
472
489
  it("should error if no key is provided", async () => {
473
490
  await expect(
474
491
  runWrangler("kv:key put")
@@ -478,10 +495,7 @@ describe("wrangler", () => {
478
495
 
479
496
  expect(std.out).toMatchInlineSnapshot(`
480
497
  "
481
- "
482
- `);
483
- expect(std.err).toMatchInlineSnapshot(`
484
- "wrangler kv:key put <key> [value]
498
+ wrangler kv:key put <key> [value]
485
499
 
486
500
  Writes a single key/value pair to the given namespace.
487
501
 
@@ -490,10 +504,9 @@ describe("wrangler", () => {
490
504
  value The value to write [string]
491
505
 
492
506
  Flags:
493
- -c, --config Path to .toml configuration file [string]
494
- -h, --help Show help [boolean]
495
- -v, --version Show version number [boolean]
496
- --legacy-env Use legacy environments [boolean]
507
+ -c, --config Path to .toml configuration file [string]
508
+ -h, --help Show help [boolean]
509
+ -v, --version Show version number [boolean]
497
510
 
498
511
  Options:
499
512
  --binding The binding of the namespace to write to [string]
@@ -502,8 +515,10 @@ describe("wrangler", () => {
502
515
  --preview Interact with a preview namespace [boolean]
503
516
  --ttl Time for which the entries should be visible [number]
504
517
  --expiration Time since the UNIX epoch after which the entry expires [number]
505
- --path Read value from the file at a given path [string]
506
- X [ERROR] Not enough non-option arguments: got 0, need at least 1
518
+ --path Read value from the file at a given path [string]"
519
+ `);
520
+ expect(std.err).toMatchInlineSnapshot(`
521
+ "X [ERROR] Not enough non-option arguments: got 0, need at least 1
507
522
 
508
523
  "
509
524
  `);
@@ -518,10 +533,7 @@ describe("wrangler", () => {
518
533
 
519
534
  expect(std.out).toMatchInlineSnapshot(`
520
535
  "
521
- "
522
- `);
523
- expect(std.err).toMatchInlineSnapshot(`
524
- "wrangler kv:key put <key> [value]
536
+ wrangler kv:key put <key> [value]
525
537
 
526
538
  Writes a single key/value pair to the given namespace.
527
539
 
@@ -530,10 +542,9 @@ describe("wrangler", () => {
530
542
  value The value to write [string]
531
543
 
532
544
  Flags:
533
- -c, --config Path to .toml configuration file [string]
534
- -h, --help Show help [boolean]
535
- -v, --version Show version number [boolean]
536
- --legacy-env Use legacy environments [boolean]
545
+ -c, --config Path to .toml configuration file [string]
546
+ -h, --help Show help [boolean]
547
+ -v, --version Show version number [boolean]
537
548
 
538
549
  Options:
539
550
  --binding The binding of the namespace to write to [string]
@@ -542,8 +553,10 @@ describe("wrangler", () => {
542
553
  --preview Interact with a preview namespace [boolean]
543
554
  --ttl Time for which the entries should be visible [number]
544
555
  --expiration Time since the UNIX epoch after which the entry expires [number]
545
- --path Read value from the file at a given path [string]
546
- X [ERROR] Exactly one of the arguments binding and namespace-id is required
556
+ --path Read value from the file at a given path [string]"
557
+ `);
558
+ expect(std.err).toMatchInlineSnapshot(`
559
+ "X [ERROR] Exactly one of the arguments binding and namespace-id is required
547
560
 
548
561
  "
549
562
  `);
@@ -558,10 +571,7 @@ describe("wrangler", () => {
558
571
 
559
572
  expect(std.out).toMatchInlineSnapshot(`
560
573
  "
561
- "
562
- `);
563
- expect(std.err).toMatchInlineSnapshot(`
564
- "wrangler kv:key put <key> [value]
574
+ wrangler kv:key put <key> [value]
565
575
 
566
576
  Writes a single key/value pair to the given namespace.
567
577
 
@@ -570,10 +580,9 @@ describe("wrangler", () => {
570
580
  value The value to write [string]
571
581
 
572
582
  Flags:
573
- -c, --config Path to .toml configuration file [string]
574
- -h, --help Show help [boolean]
575
- -v, --version Show version number [boolean]
576
- --legacy-env Use legacy environments [boolean]
583
+ -c, --config Path to .toml configuration file [string]
584
+ -h, --help Show help [boolean]
585
+ -v, --version Show version number [boolean]
577
586
 
578
587
  Options:
579
588
  --binding The binding of the namespace to write to [string]
@@ -582,8 +591,10 @@ describe("wrangler", () => {
582
591
  --preview Interact with a preview namespace [boolean]
583
592
  --ttl Time for which the entries should be visible [number]
584
593
  --expiration Time since the UNIX epoch after which the entry expires [number]
585
- --path Read value from the file at a given path [string]
586
- X [ERROR] Arguments binding and namespace-id are mutually exclusive
594
+ --path Read value from the file at a given path [string]"
595
+ `);
596
+ expect(std.err).toMatchInlineSnapshot(`
597
+ "X [ERROR] Arguments binding and namespace-id are mutually exclusive
587
598
 
588
599
  "
589
600
  `);
@@ -598,10 +609,7 @@ describe("wrangler", () => {
598
609
 
599
610
  expect(std.out).toMatchInlineSnapshot(`
600
611
  "
601
- "
602
- `);
603
- expect(std.err).toMatchInlineSnapshot(`
604
- "wrangler kv:key put <key> [value]
612
+ wrangler kv:key put <key> [value]
605
613
 
606
614
  Writes a single key/value pair to the given namespace.
607
615
 
@@ -610,10 +618,9 @@ describe("wrangler", () => {
610
618
  value The value to write [string]
611
619
 
612
620
  Flags:
613
- -c, --config Path to .toml configuration file [string]
614
- -h, --help Show help [boolean]
615
- -v, --version Show version number [boolean]
616
- --legacy-env Use legacy environments [boolean]
621
+ -c, --config Path to .toml configuration file [string]
622
+ -h, --help Show help [boolean]
623
+ -v, --version Show version number [boolean]
617
624
 
618
625
  Options:
619
626
  --binding The binding of the namespace to write to [string]
@@ -622,8 +629,10 @@ describe("wrangler", () => {
622
629
  --preview Interact with a preview namespace [boolean]
623
630
  --ttl Time for which the entries should be visible [number]
624
631
  --expiration Time since the UNIX epoch after which the entry expires [number]
625
- --path Read value from the file at a given path [string]
626
- X [ERROR] Exactly one of the arguments value and path is required
632
+ --path Read value from the file at a given path [string]"
633
+ `);
634
+ expect(std.err).toMatchInlineSnapshot(`
635
+ "X [ERROR] Exactly one of the arguments value and path is required
627
636
 
628
637
  "
629
638
  `);
@@ -638,10 +647,7 @@ describe("wrangler", () => {
638
647
 
639
648
  expect(std.out).toMatchInlineSnapshot(`
640
649
  "
641
- "
642
- `);
643
- expect(std.err).toMatchInlineSnapshot(`
644
- "wrangler kv:key put <key> [value]
650
+ wrangler kv:key put <key> [value]
645
651
 
646
652
  Writes a single key/value pair to the given namespace.
647
653
 
@@ -650,10 +656,9 @@ describe("wrangler", () => {
650
656
  value The value to write [string]
651
657
 
652
658
  Flags:
653
- -c, --config Path to .toml configuration file [string]
654
- -h, --help Show help [boolean]
655
- -v, --version Show version number [boolean]
656
- --legacy-env Use legacy environments [boolean]
659
+ -c, --config Path to .toml configuration file [string]
660
+ -h, --help Show help [boolean]
661
+ -v, --version Show version number [boolean]
657
662
 
658
663
  Options:
659
664
  --binding The binding of the namespace to write to [string]
@@ -662,8 +667,10 @@ describe("wrangler", () => {
662
667
  --preview Interact with a preview namespace [boolean]
663
668
  --ttl Time for which the entries should be visible [number]
664
669
  --expiration Time since the UNIX epoch after which the entry expires [number]
665
- --path Read value from the file at a given path [string]
666
- X [ERROR] Arguments value and path are mutually exclusive
670
+ --path Read value from the file at a given path [string]"
671
+ `);
672
+ expect(std.err).toMatchInlineSnapshot(`
673
+ "X [ERROR] Arguments value and path are mutually exclusive
667
674
 
668
675
  "
669
676
  `);
@@ -679,7 +686,7 @@ describe("wrangler", () => {
679
686
 
680
687
  expect(std.out).toMatchInlineSnapshot(`
681
688
  "
682
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
689
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
683
690
  `);
684
691
  expect(std.err).toMatchInlineSnapshot(`
685
692
  "X [ERROR] A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
@@ -701,7 +708,7 @@ describe("wrangler", () => {
701
708
  );
702
709
  expect(std.out).toMatchInlineSnapshot(`
703
710
  "
704
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
711
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
705
712
  `);
706
713
  expect(std.err).toMatchInlineSnapshot(`
707
714
  "X [ERROR] someBinding has both a namespace ID and a preview ID. Specify \\"--preview\\" or \\"--preview false\\" to avoid writing data to the wrong namespace.
@@ -872,7 +879,7 @@ describe("wrangler", () => {
872
879
  `);
873
880
  expect(std.out).toMatchInlineSnapshot(`
874
881
  "
875
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
882
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
876
883
  `);
877
884
  });
878
885
  });
@@ -890,7 +897,23 @@ describe("wrangler", () => {
890
897
  "my-value"
891
898
  );
892
899
  await runWrangler("kv:key get my-key --namespace-id some-namespace-id");
893
- expect(std.out).toMatchInlineSnapshot(`"my-value"`);
900
+ expect(proc.write).toEqual(Buffer.from("my-value"));
901
+ expect(std.err).toMatchInlineSnapshot(`""`);
902
+ });
903
+
904
+ it("should get a binary file by key in a given namespace specified by namespace-id", async () => {
905
+ const buf = Buffer.from(
906
+ "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAiSURBVHgB7coxEQAACMPAgH/PgAM6dGwu49fA/deIBXrgAj2cAhIFT4QxAAAAAElFTkSuQmCC",
907
+ "base64"
908
+ );
909
+ setMockFetchKVGetValue(
910
+ "some-account-id",
911
+ "some-namespace-id",
912
+ "my-key",
913
+ buf
914
+ );
915
+ await runWrangler("kv:key get my-key --namespace-id some-namespace-id");
916
+ expect(proc.write).toEqual(buf);
894
917
  expect(std.err).toMatchInlineSnapshot(`""`);
895
918
  });
896
919
 
@@ -905,7 +928,7 @@ describe("wrangler", () => {
905
928
  await runWrangler(
906
929
  "kv:key get my-key --binding someBinding --preview false"
907
930
  );
908
- expect(std.out).toMatchInlineSnapshot(`"my-value"`);
931
+ expect(proc.write).toEqual(Buffer.from("my-value"));
909
932
  expect(std.err).toMatchInlineSnapshot(`""`);
910
933
  });
911
934
 
@@ -918,7 +941,7 @@ describe("wrangler", () => {
918
941
  "my-value"
919
942
  );
920
943
  await runWrangler("kv:key get my-key --binding someBinding --preview");
921
- expect(std.out).toMatchInlineSnapshot(`"my-value"`);
944
+ expect(proc.write).toEqual(Buffer.from("my-value"));
922
945
  expect(std.err).toMatchInlineSnapshot(`""`);
923
946
  });
924
947
 
@@ -933,7 +956,21 @@ describe("wrangler", () => {
933
956
  await runWrangler(
934
957
  "kv:key get my-key --binding someBinding --env some-environment --preview false"
935
958
  );
936
- expect(std.out).toMatchInlineSnapshot(`"my-value"`);
959
+ expect(proc.write).toEqual(Buffer.from("my-value"));
960
+ expect(std.err).toMatchInlineSnapshot(`""`);
961
+ });
962
+
963
+ it("should encode the key in the api request to get a value", async () => {
964
+ setMockFetchKVGetValue(
965
+ "some-account-id",
966
+ "some-namespace-id",
967
+ "%2Fmy%2Ckey",
968
+ "my-value"
969
+ );
970
+ await runWrangler(
971
+ "kv:key get /my,key --namespace-id some-namespace-id"
972
+ );
973
+ expect(proc.write).toEqual(Buffer.from("my-value"));
937
974
  expect(std.err).toMatchInlineSnapshot(`""`);
938
975
  });
939
976
 
@@ -945,10 +982,7 @@ describe("wrangler", () => {
945
982
  );
946
983
  expect(std.out).toMatchInlineSnapshot(`
947
984
  "
948
- "
949
- `);
950
- expect(std.err).toMatchInlineSnapshot(`
951
- "wrangler kv:key get <key>
985
+ wrangler kv:key get <key>
952
986
 
953
987
  Reads a single value by key from the given namespace.
954
988
 
@@ -956,17 +990,18 @@ describe("wrangler", () => {
956
990
  key The key value to get. [string] [required]
957
991
 
958
992
  Flags:
959
- -c, --config Path to .toml configuration file [string]
960
- -h, --help Show help [boolean]
961
- -v, --version Show version number [boolean]
962
- --legacy-env Use legacy environments [boolean]
993
+ -c, --config Path to .toml configuration file [string]
994
+ -h, --help Show help [boolean]
995
+ -v, --version Show version number [boolean]
963
996
 
964
997
  Options:
965
998
  --binding The name of the namespace to get from [string]
966
999
  --namespace-id The id of the namespace to get from [string]
967
1000
  -e, --env Perform on a specific environment [string]
968
- --preview Interact with a preview namespace [boolean] [default: false]
969
- X [ERROR] Not enough non-option arguments: got 0, need at least 1
1001
+ --preview Interact with a preview namespace [boolean] [default: false]"
1002
+ `);
1003
+ expect(std.err).toMatchInlineSnapshot(`
1004
+ "X [ERROR] Not enough non-option arguments: got 0, need at least 1
970
1005
 
971
1006
  "
972
1007
  `);
@@ -980,10 +1015,7 @@ describe("wrangler", () => {
980
1015
  );
981
1016
  expect(std.out).toMatchInlineSnapshot(`
982
1017
  "
983
- "
984
- `);
985
- expect(std.err).toMatchInlineSnapshot(`
986
- "wrangler kv:key get <key>
1018
+ wrangler kv:key get <key>
987
1019
 
988
1020
  Reads a single value by key from the given namespace.
989
1021
 
@@ -991,17 +1023,18 @@ describe("wrangler", () => {
991
1023
  key The key value to get. [string] [required]
992
1024
 
993
1025
  Flags:
994
- -c, --config Path to .toml configuration file [string]
995
- -h, --help Show help [boolean]
996
- -v, --version Show version number [boolean]
997
- --legacy-env Use legacy environments [boolean]
1026
+ -c, --config Path to .toml configuration file [string]
1027
+ -h, --help Show help [boolean]
1028
+ -v, --version Show version number [boolean]
998
1029
 
999
1030
  Options:
1000
1031
  --binding The name of the namespace to get from [string]
1001
1032
  --namespace-id The id of the namespace to get from [string]
1002
1033
  -e, --env Perform on a specific environment [string]
1003
- --preview Interact with a preview namespace [boolean] [default: false]
1004
- X [ERROR] Exactly one of the arguments binding and namespace-id is required
1034
+ --preview Interact with a preview namespace [boolean] [default: false]"
1035
+ `);
1036
+ expect(std.err).toMatchInlineSnapshot(`
1037
+ "X [ERROR] Exactly one of the arguments binding and namespace-id is required
1005
1038
 
1006
1039
  "
1007
1040
  `);
@@ -1016,10 +1049,7 @@ describe("wrangler", () => {
1016
1049
 
1017
1050
  expect(std.out).toMatchInlineSnapshot(`
1018
1051
  "
1019
- "
1020
- `);
1021
- expect(std.err).toMatchInlineSnapshot(`
1022
- "wrangler kv:key get <key>
1052
+ wrangler kv:key get <key>
1023
1053
 
1024
1054
  Reads a single value by key from the given namespace.
1025
1055
 
@@ -1027,17 +1057,18 @@ describe("wrangler", () => {
1027
1057
  key The key value to get. [string] [required]
1028
1058
 
1029
1059
  Flags:
1030
- -c, --config Path to .toml configuration file [string]
1031
- -h, --help Show help [boolean]
1032
- -v, --version Show version number [boolean]
1033
- --legacy-env Use legacy environments [boolean]
1060
+ -c, --config Path to .toml configuration file [string]
1061
+ -h, --help Show help [boolean]
1062
+ -v, --version Show version number [boolean]
1034
1063
 
1035
1064
  Options:
1036
1065
  --binding The name of the namespace to get from [string]
1037
1066
  --namespace-id The id of the namespace to get from [string]
1038
1067
  -e, --env Perform on a specific environment [string]
1039
- --preview Interact with a preview namespace [boolean] [default: false]
1040
- X [ERROR] Arguments binding and namespace-id are mutually exclusive
1068
+ --preview Interact with a preview namespace [boolean] [default: false]"
1069
+ `);
1070
+ expect(std.err).toMatchInlineSnapshot(`
1071
+ "X [ERROR] Arguments binding and namespace-id are mutually exclusive
1041
1072
 
1042
1073
  "
1043
1074
  `);
@@ -1052,7 +1083,7 @@ describe("wrangler", () => {
1052
1083
  );
1053
1084
  expect(std.out).toMatchInlineSnapshot(`
1054
1085
  "
1055
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
1086
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1056
1087
  `);
1057
1088
  expect(std.err).toMatchInlineSnapshot(`
1058
1089
  "X [ERROR] A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
@@ -1090,6 +1121,16 @@ describe("wrangler", () => {
1090
1121
  expect(requests.count).toEqual(1);
1091
1122
  });
1092
1123
 
1124
+ it("should encode the key in the api request to delete a value", async () => {
1125
+ const requests = mockDeleteRequest("voyager", "%2FNCC-74656");
1126
+ await runWrangler(`kv:key delete --namespace-id voyager /NCC-74656`);
1127
+ expect(requests.count).toEqual(1);
1128
+ expect(std.out).toMatchInlineSnapshot(
1129
+ `"Deleting the key \\"/NCC-74656\\" on namespace voyager."`
1130
+ );
1131
+ expect(std.err).toMatchInlineSnapshot(`""`);
1132
+ });
1133
+
1093
1134
  it("should delete a key in a namespace specified by binding name", async () => {
1094
1135
  writeWranglerConfig();
1095
1136
  const requests = mockDeleteRequest("bound-id", "someKey");
@@ -1203,10 +1244,10 @@ describe("wrangler", () => {
1203
1244
  );
1204
1245
  expect(requests.count).toEqual(3);
1205
1246
  expect(std.out).toMatchInlineSnapshot(`
1206
- "Uploaded 0 of 12000.
1207
- Uploaded 5000 of 12000.
1208
- Uploaded 10000 of 12000.
1209
- Uploaded 12000 of 12000.
1247
+ "Uploaded 0% (0 out of 12,000)
1248
+ Uploaded 41% (5,000 out of 12,000)
1249
+ Uploaded 83% (10,000 out of 12,000)
1250
+ Uploaded 100% (12,000 out of 12,000)
1210
1251
  Success!"
1211
1252
  `);
1212
1253
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -1224,7 +1265,7 @@ describe("wrangler", () => {
1224
1265
  `);
1225
1266
  expect(std.out).toMatchInlineSnapshot(`
1226
1267
  "
1227
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
1268
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1228
1269
  `);
1229
1270
  expect(std.warn).toMatchInlineSnapshot(`""`);
1230
1271
  });
@@ -1235,7 +1276,25 @@ describe("wrangler", () => {
1235
1276
  "a string",
1236
1277
  { key: "someKey" },
1237
1278
  { value: "someValue" },
1279
+ // add a valid object here to make sure it's not included
1280
+ { key: "someKey1", value: "someValue1" },
1281
+ // this one will only add a warning
1238
1282
  { key: "someKey1", value: "someValue1", invalid: true },
1283
+ // back to the invalid ones
1284
+ { key: 123, value: "somevalue" },
1285
+ { key: "somekey", value: 123 },
1286
+ { key: "someKey1", value: "someValue1", expiration: "string" },
1287
+ { key: "someKey1", value: "someValue1", expiration_ttl: "string" },
1288
+ {
1289
+ key: 123,
1290
+ value: {
1291
+ a: {
1292
+ nested: "object",
1293
+ },
1294
+ },
1295
+ },
1296
+ { key: "someKey1", value: "someValue1", metadata: 123 },
1297
+ { key: "someKey1", value: "someValue1", base64: "string" },
1239
1298
  ];
1240
1299
  writeFileSync("./keys.json", JSON.stringify(keyValues));
1241
1300
  await expect(
@@ -1253,20 +1312,27 @@ describe("wrangler", () => {
1253
1312
  base64?: boolean;
1254
1313
  }
1255
1314
 
1256
- The item at index 0 is type: \\"number\\" - 123
1257
- The item at index 1 is type: \\"string\\" - \\"a string\\"
1315
+ The item at index 0 is 123
1316
+ The item at index 1 is \\"a string\\"
1258
1317
  The item at index 2 is {\\"key\\":\\"someKey\\"}
1259
- The item at index 3 is {\\"value\\":\\"someValue\\"}"
1318
+ The item at index 3 is {\\"value\\":\\"someValue\\"}
1319
+ The item at index 6 is {\\"key\\":123,\\"value\\":\\"somevalue\\"}
1320
+ The item at index 7 is {\\"key\\":\\"somekey\\",\\"value\\":123}
1321
+ The item at index 8 is {\\"key\\":\\"someKey1\\",\\"value\\":\\"someValue1\\",\\"expiration\\":\\"string\\"}
1322
+ The item at index 9 is {\\"key\\":\\"someKey1\\",\\"value\\":\\"someValue1\\",\\"expiration_ttl\\":\\"string\\"}
1323
+ The item at index 10 is {\\"key\\":123,\\"value\\":{\\"a\\":{\\"nested\\":\\"object\\"}}}
1324
+ The item at index 11 is {\\"key\\":\\"someKey1\\",\\"value\\":\\"someValue1\\",\\"metadata\\":123}
1325
+ The item at index 12 is {\\"key\\":\\"someKey1\\",\\"value\\":\\"someValue1\\",\\"base64\\":\\"string\\"}"
1260
1326
  `);
1261
1327
 
1262
1328
  expect(std.out).toMatchInlineSnapshot(`
1263
1329
  "
1264
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
1330
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1265
1331
  `);
1266
1332
  expect(std.warn).toMatchInlineSnapshot(`
1267
1333
  "â–² [WARNING] Unexpected key-value properties in \\"keys.json\\".
1268
1334
 
1269
- The item at index 4 contains unexpected properties: [\\"invalid\\"].
1335
+ The item at index 5 contains unexpected properties: [\\"invalid\\"].
1270
1336
 
1271
1337
  "
1272
1338
  `);
@@ -1331,10 +1397,10 @@ describe("wrangler", () => {
1331
1397
  );
1332
1398
  expect(requests.count).toEqual(3);
1333
1399
  expect(std.out).toMatchInlineSnapshot(`
1334
- "Deleted 0 of 12000.
1335
- Deleted 5000 of 12000.
1336
- Deleted 10000 of 12000.
1337
- Deleted 12000 of 12000.
1400
+ "Deleted 0% (0 out of 12,000)
1401
+ Deleted 41% (5,000 out of 12,000)
1402
+ Deleted 83% (10,000 out of 12,000)
1403
+ Deleted 100% (12,000 out of 12,000)
1338
1404
  Success!"
1339
1405
  `);
1340
1406
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -1402,7 +1468,7 @@ describe("wrangler", () => {
1402
1468
  `);
1403
1469
  expect(std.out).toMatchInlineSnapshot(`
1404
1470
  "
1405
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
1471
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1406
1472
  `);
1407
1473
  expect(std.warn).toMatchInlineSnapshot(`""`);
1408
1474
  });
@@ -1427,7 +1493,7 @@ describe("wrangler", () => {
1427
1493
  `);
1428
1494
  expect(std.out).toMatchInlineSnapshot(`
1429
1495
  "
1430
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
1496
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1431
1497
  `);
1432
1498
  expect(std.warn).toMatchInlineSnapshot(`""`);
1433
1499
  });