wrangler 0.0.0-e95bea2 → 0.0.0-e95e5a0
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.
- package/README.md +25 -14
- package/bin/wrangler.js +13 -1
- package/miniflare-dist/index.mjs +4886 -0
- package/package.json +33 -25
- package/pages/functions/buildPlugin.ts +92 -0
- package/pages/functions/buildWorker.ts +80 -4
- package/pages/functions/filepath-routing.test.ts +136 -25
- package/pages/functions/filepath-routing.ts +14 -3
- package/pages/functions/routes.ts +6 -1
- package/pages/functions/template-plugin.ts +146 -0
- package/pages/functions/template-worker.ts +21 -8
- package/src/__tests__/config-cache.test.ts +36 -0
- package/src/__tests__/configuration.test.ts +1179 -271
- package/src/__tests__/dev.test.tsx +382 -25
- package/src/__tests__/guess-worker-format.test.ts +28 -1
- package/src/__tests__/helpers/mock-account-id.ts +4 -0
- package/src/__tests__/helpers/mock-cfetch.ts +5 -1
- package/src/__tests__/helpers/mock-console.ts +20 -3
- package/src/__tests__/helpers/mock-dialogs.ts +26 -1
- package/src/__tests__/helpers/mock-http-server.ts +46 -0
- package/src/__tests__/helpers/mock-istty.ts +27 -0
- package/src/__tests__/helpers/mock-kv.ts +9 -16
- package/src/__tests__/helpers/mock-oauth-flow.ts +255 -0
- package/src/__tests__/helpers/run-in-tmp.ts +10 -0
- package/src/__tests__/helpers/write-worker-source.ts +31 -0
- package/src/__tests__/https-options.test.ts +5 -2
- package/src/__tests__/index.test.ts +27 -769
- package/src/__tests__/init.test.ts +1516 -0
- package/src/__tests__/jest.setup.ts +4 -4
- package/src/__tests__/kv.test.ts +172 -126
- package/src/__tests__/logger.test.ts +115 -0
- package/src/__tests__/pages.test.ts +311 -26
- package/src/__tests__/publish.test.ts +2946 -524
- package/src/__tests__/r2.test.ts +26 -10
- package/src/__tests__/route.test.ts +4 -4
- package/src/__tests__/secret.test.ts +55 -34
- package/src/__tests__/tail.test.ts +146 -20
- package/src/__tests__/user.test.ts +131 -0
- package/src/__tests__/whoami.test.tsx +26 -7
- package/src/bundle.ts +30 -3
- package/src/cfetch/internal.ts +9 -7
- package/src/cli.ts +5 -11
- package/src/config/README.md +7 -7
- package/src/config/config.ts +33 -78
- package/src/config/environment.ts +93 -4
- package/src/config/index.ts +15 -4
- package/src/config/validation-helpers.ts +202 -15
- package/src/config/validation.ts +530 -133
- package/src/config-cache.ts +45 -0
- package/src/create-worker-preview.ts +22 -13
- package/src/create-worker-upload-form.ts +32 -9
- package/src/dev/dev-vars.ts +36 -0
- package/src/dev/dev.tsx +136 -75
- package/src/dev/local.tsx +196 -125
- package/src/dev/remote.tsx +25 -13
- package/src/dev/use-esbuild.ts +23 -5
- package/src/dialogs.tsx +16 -6
- package/src/entry.ts +119 -11
- package/src/environment-variables.ts +3 -1
- package/src/errors.ts +11 -0
- package/src/https-options.ts +3 -2
- package/src/index.tsx +739 -400
- package/src/inspect.ts +17 -11
- package/src/intl-polyfill.d.ts +139 -0
- package/src/{kv/index.tsx → kv.ts} +8 -28
- package/src/logger.ts +66 -0
- package/src/miniflare-cli/README.md +30 -0
- package/src/miniflare-cli/enum-keys.ts +17 -0
- package/src/miniflare-cli/index.ts +41 -0
- package/src/miniflare-cli/request-context.ts +40 -0
- package/src/module-collection.ts +63 -58
- package/src/open-in-browser.ts +5 -4
- package/src/package-manager.ts +9 -8
- package/src/pages.tsx +883 -62
- package/src/parse.ts +1 -1
- package/src/proxy.ts +32 -21
- package/src/publish.ts +276 -161
- package/src/sites.tsx +88 -33
- package/src/tail/index.ts +2 -2
- package/src/tail/printing.ts +13 -8
- package/src/update-check.ts +19 -0
- package/src/user.tsx +231 -103
- package/src/whoami.tsx +2 -1
- package/src/worker.ts +15 -6
- package/templates/gitignore +171 -0
- package/templates/static-asset-facade.js +1 -1
- package/wrangler-dist/cli.js +22087 -49340
- package/src/__tests__/dev2.test.tsx +0 -152
- package/src/__tests__/helpers/mock-user.ts +0 -27
- package/src/__tests__/logout.test.ts +0 -50
- package/src/__tests__/sentry.test.ts +0 -146
- package/src/reporting.ts +0 -131
- package/wrangler-dist/cli.js.map +0 -7
package/src/__tests__/kv.test.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
setMockFetchKVGetValue,
|
|
9
9
|
} from "./helpers/mock-cfetch";
|
|
10
10
|
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
11
|
-
import { mockConfirm } from "./helpers/mock-dialogs";
|
|
11
|
+
import { clearConfirmMocks, mockConfirm } from "./helpers/mock-dialogs";
|
|
12
12
|
import { mockKeyListRequest } from "./helpers/mock-kv";
|
|
13
13
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
14
14
|
import { runWrangler } from "./helpers/run-wrangler";
|
|
@@ -22,6 +22,7 @@ describe("wrangler", () => {
|
|
|
22
22
|
|
|
23
23
|
afterEach(() => {
|
|
24
24
|
unsetAllMocks();
|
|
25
|
+
clearConfirmMocks();
|
|
25
26
|
});
|
|
26
27
|
|
|
27
28
|
describe("kv:namespace", () => {
|
|
@@ -45,7 +46,10 @@ describe("wrangler", () => {
|
|
|
45
46
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
46
47
|
`"Not enough non-option arguments: got 0, need at least 1"`
|
|
47
48
|
);
|
|
48
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
49
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
50
|
+
"
|
|
51
|
+
"
|
|
52
|
+
`);
|
|
49
53
|
expect(std.err).toMatchInlineSnapshot(`
|
|
50
54
|
"wrangler kv:namespace create <namespace>
|
|
51
55
|
|
|
@@ -61,10 +65,11 @@ describe("wrangler", () => {
|
|
|
61
65
|
--legacy-env Use legacy environments [boolean]
|
|
62
66
|
|
|
63
67
|
Options:
|
|
64
|
-
|
|
68
|
+
-e, --env Perform on a specific environment [string]
|
|
65
69
|
--preview Interact with a preview namespace [boolean]
|
|
70
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot enough non-option arguments: got 0, need at least 1[0m
|
|
66
71
|
|
|
67
|
-
|
|
72
|
+
"
|
|
68
73
|
`);
|
|
69
74
|
});
|
|
70
75
|
|
|
@@ -72,9 +77,12 @@ describe("wrangler", () => {
|
|
|
72
77
|
await expect(
|
|
73
78
|
runWrangler("kv:namespace create abc def ghi")
|
|
74
79
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
75
|
-
`"
|
|
80
|
+
`"Unknown arguments: def, ghi"`
|
|
76
81
|
);
|
|
77
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
82
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
83
|
+
"
|
|
84
|
+
"
|
|
85
|
+
`);
|
|
78
86
|
expect(std.err).toMatchInlineSnapshot(`
|
|
79
87
|
"wrangler kv:namespace create <namespace>
|
|
80
88
|
|
|
@@ -90,10 +98,11 @@ describe("wrangler", () => {
|
|
|
90
98
|
--legacy-env Use legacy environments [boolean]
|
|
91
99
|
|
|
92
100
|
Options:
|
|
93
|
-
|
|
101
|
+
-e, --env Perform on a specific environment [string]
|
|
94
102
|
--preview Interact with a preview namespace [boolean]
|
|
103
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mUnknown arguments: def, ghi[0m
|
|
95
104
|
|
|
96
|
-
|
|
105
|
+
"
|
|
97
106
|
`);
|
|
98
107
|
});
|
|
99
108
|
|
|
@@ -104,7 +113,10 @@ describe("wrangler", () => {
|
|
|
104
113
|
`"The namespace binding name \\"abc-def\\" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number."`
|
|
105
114
|
);
|
|
106
115
|
|
|
107
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
116
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
117
|
+
"
|
|
118
|
+
"
|
|
119
|
+
`);
|
|
108
120
|
expect(std.err).toMatchInlineSnapshot(`
|
|
109
121
|
"wrangler kv:namespace create <namespace>
|
|
110
122
|
|
|
@@ -120,10 +132,11 @@ describe("wrangler", () => {
|
|
|
120
132
|
--legacy-env Use legacy environments [boolean]
|
|
121
133
|
|
|
122
134
|
Options:
|
|
123
|
-
|
|
135
|
+
-e, --env Perform on a specific environment [string]
|
|
124
136
|
--preview Interact with a preview namespace [boolean]
|
|
137
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mThe namespace binding name \\"abc-def\\" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number.[0m
|
|
125
138
|
|
|
126
|
-
|
|
139
|
+
"
|
|
127
140
|
`);
|
|
128
141
|
});
|
|
129
142
|
|
|
@@ -150,11 +163,11 @@ describe("wrangler", () => {
|
|
|
150
163
|
});
|
|
151
164
|
|
|
152
165
|
it("should create a namespace using configured worker name", async () => {
|
|
153
|
-
writeFileSync("./wrangler.toml", 'name = "
|
|
154
|
-
mockCreateRequest("
|
|
166
|
+
writeFileSync("./wrangler.toml", 'name = "other-worker"', "utf-8");
|
|
167
|
+
mockCreateRequest("other-worker-UnitTestNamespace");
|
|
155
168
|
await runWrangler("kv:namespace create UnitTestNamespace");
|
|
156
169
|
expect(std.out).toMatchInlineSnapshot(`
|
|
157
|
-
"🌀 Creating namespace with title \\"
|
|
170
|
+
"🌀 Creating namespace with title \\"other-worker-UnitTestNamespace\\"
|
|
158
171
|
✨ Success!
|
|
159
172
|
Add the following to your configuration file in your kv_namespaces array:
|
|
160
173
|
{ binding = \\"UnitTestNamespace\\", id = \\"some-namespace-id\\" }"
|
|
@@ -286,11 +299,13 @@ describe("wrangler", () => {
|
|
|
286
299
|
Options:
|
|
287
300
|
--binding The name of the namespace to delete [string]
|
|
288
301
|
--namespace-id The id of the namespace to delete [string]
|
|
289
|
-
|
|
302
|
+
-e, --env Perform on a specific environment [string]
|
|
290
303
|
--preview Interact with a preview namespace [boolean]
|
|
304
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot able to delete namespace.[0m
|
|
291
305
|
|
|
292
|
-
|
|
293
|
-
|
|
306
|
+
A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
|
|
307
|
+
|
|
308
|
+
"
|
|
294
309
|
`);
|
|
295
310
|
});
|
|
296
311
|
|
|
@@ -365,7 +380,7 @@ describe("wrangler", () => {
|
|
|
365
380
|
|
|
366
381
|
expect(requests.count).toEqual(1);
|
|
367
382
|
expect(std.out).toMatchInlineSnapshot(
|
|
368
|
-
`"
|
|
383
|
+
`"Writing the value \\"my-value\\" to key \\"my-key\\" on namespace some-namespace-id."`
|
|
369
384
|
);
|
|
370
385
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
371
386
|
});
|
|
@@ -381,7 +396,7 @@ describe("wrangler", () => {
|
|
|
381
396
|
);
|
|
382
397
|
|
|
383
398
|
expect(std.out).toMatchInlineSnapshot(
|
|
384
|
-
`"
|
|
399
|
+
`"Writing the value \\"my-value\\" to key \\"my-key\\" on namespace bound-id."`
|
|
385
400
|
);
|
|
386
401
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
387
402
|
expect(requests.count).toEqual(1);
|
|
@@ -399,7 +414,7 @@ describe("wrangler", () => {
|
|
|
399
414
|
);
|
|
400
415
|
|
|
401
416
|
expect(std.out).toMatchInlineSnapshot(
|
|
402
|
-
`"
|
|
417
|
+
`"Writing the value \\"my-value\\" to key \\"my-key\\" on namespace preview-bound-id."`
|
|
403
418
|
);
|
|
404
419
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
405
420
|
expect(requests.count).toEqual(1);
|
|
@@ -417,7 +432,7 @@ describe("wrangler", () => {
|
|
|
417
432
|
);
|
|
418
433
|
expect(requests.count).toEqual(1);
|
|
419
434
|
expect(std.out).toMatchInlineSnapshot(
|
|
420
|
-
`"
|
|
435
|
+
`"Writing the value \\"my-value\\" to key \\"my-key\\" on namespace some-namespace-id."`
|
|
421
436
|
);
|
|
422
437
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
423
438
|
});
|
|
@@ -432,7 +447,7 @@ describe("wrangler", () => {
|
|
|
432
447
|
"kv:key put my-key my-value --binding someBinding --env some-environment --preview false"
|
|
433
448
|
);
|
|
434
449
|
expect(std.out).toMatchInlineSnapshot(
|
|
435
|
-
`"
|
|
450
|
+
`"Writing the value \\"my-value\\" to key \\"my-key\\" on namespace env-bound-id."`
|
|
436
451
|
);
|
|
437
452
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
438
453
|
expect(requests.count).toEqual(1);
|
|
@@ -448,7 +463,7 @@ describe("wrangler", () => {
|
|
|
448
463
|
"kv:key put my-key --namespace-id some-namespace-id --path foo.txt"
|
|
449
464
|
);
|
|
450
465
|
expect(std.out).toMatchInlineSnapshot(
|
|
451
|
-
`"
|
|
466
|
+
`"Writing the contents of foo.txt to the key \\"my-key\\" on namespace some-namespace-id."`
|
|
452
467
|
);
|
|
453
468
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
454
469
|
expect(requests.count).toEqual(1);
|
|
@@ -461,7 +476,10 @@ describe("wrangler", () => {
|
|
|
461
476
|
`"Not enough non-option arguments: got 0, need at least 1"`
|
|
462
477
|
);
|
|
463
478
|
|
|
464
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
479
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
480
|
+
"
|
|
481
|
+
"
|
|
482
|
+
`);
|
|
465
483
|
expect(std.err).toMatchInlineSnapshot(`
|
|
466
484
|
"wrangler kv:key put <key> [value]
|
|
467
485
|
|
|
@@ -480,13 +498,14 @@ describe("wrangler", () => {
|
|
|
480
498
|
Options:
|
|
481
499
|
--binding The binding of the namespace to write to [string]
|
|
482
500
|
--namespace-id The id of the namespace to write to [string]
|
|
483
|
-
|
|
501
|
+
-e, --env Perform on a specific environment [string]
|
|
484
502
|
--preview Interact with a preview namespace [boolean]
|
|
485
503
|
--ttl Time for which the entries should be visible [number]
|
|
486
504
|
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
487
505
|
--path Read value from the file at a given path [string]
|
|
506
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot enough non-option arguments: got 0, need at least 1[0m
|
|
488
507
|
|
|
489
|
-
|
|
508
|
+
"
|
|
490
509
|
`);
|
|
491
510
|
});
|
|
492
511
|
|
|
@@ -497,7 +516,10 @@ describe("wrangler", () => {
|
|
|
497
516
|
`"Exactly one of the arguments binding and namespace-id is required"`
|
|
498
517
|
);
|
|
499
518
|
|
|
500
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
519
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
520
|
+
"
|
|
521
|
+
"
|
|
522
|
+
`);
|
|
501
523
|
expect(std.err).toMatchInlineSnapshot(`
|
|
502
524
|
"wrangler kv:key put <key> [value]
|
|
503
525
|
|
|
@@ -516,13 +538,14 @@ describe("wrangler", () => {
|
|
|
516
538
|
Options:
|
|
517
539
|
--binding The binding of the namespace to write to [string]
|
|
518
540
|
--namespace-id The id of the namespace to write to [string]
|
|
519
|
-
|
|
541
|
+
-e, --env Perform on a specific environment [string]
|
|
520
542
|
--preview Interact with a preview namespace [boolean]
|
|
521
543
|
--ttl Time for which the entries should be visible [number]
|
|
522
544
|
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
523
545
|
--path Read value from the file at a given path [string]
|
|
546
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mExactly one of the arguments binding and namespace-id is required[0m
|
|
524
547
|
|
|
525
|
-
|
|
548
|
+
"
|
|
526
549
|
`);
|
|
527
550
|
});
|
|
528
551
|
|
|
@@ -533,7 +556,10 @@ describe("wrangler", () => {
|
|
|
533
556
|
`"Arguments binding and namespace-id are mutually exclusive"`
|
|
534
557
|
);
|
|
535
558
|
|
|
536
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
559
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
560
|
+
"
|
|
561
|
+
"
|
|
562
|
+
`);
|
|
537
563
|
expect(std.err).toMatchInlineSnapshot(`
|
|
538
564
|
"wrangler kv:key put <key> [value]
|
|
539
565
|
|
|
@@ -552,13 +578,14 @@ describe("wrangler", () => {
|
|
|
552
578
|
Options:
|
|
553
579
|
--binding The binding of the namespace to write to [string]
|
|
554
580
|
--namespace-id The id of the namespace to write to [string]
|
|
555
|
-
|
|
581
|
+
-e, --env Perform on a specific environment [string]
|
|
556
582
|
--preview Interact with a preview namespace [boolean]
|
|
557
583
|
--ttl Time for which the entries should be visible [number]
|
|
558
584
|
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
559
585
|
--path Read value from the file at a given path [string]
|
|
586
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mArguments binding and namespace-id are mutually exclusive[0m
|
|
560
587
|
|
|
561
|
-
|
|
588
|
+
"
|
|
562
589
|
`);
|
|
563
590
|
});
|
|
564
591
|
|
|
@@ -569,7 +596,10 @@ describe("wrangler", () => {
|
|
|
569
596
|
`"Exactly one of the arguments value and path is required"`
|
|
570
597
|
);
|
|
571
598
|
|
|
572
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
599
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
600
|
+
"
|
|
601
|
+
"
|
|
602
|
+
`);
|
|
573
603
|
expect(std.err).toMatchInlineSnapshot(`
|
|
574
604
|
"wrangler kv:key put <key> [value]
|
|
575
605
|
|
|
@@ -588,13 +618,14 @@ describe("wrangler", () => {
|
|
|
588
618
|
Options:
|
|
589
619
|
--binding The binding of the namespace to write to [string]
|
|
590
620
|
--namespace-id The id of the namespace to write to [string]
|
|
591
|
-
|
|
621
|
+
-e, --env Perform on a specific environment [string]
|
|
592
622
|
--preview Interact with a preview namespace [boolean]
|
|
593
623
|
--ttl Time for which the entries should be visible [number]
|
|
594
624
|
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
595
625
|
--path Read value from the file at a given path [string]
|
|
626
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mExactly one of the arguments value and path is required[0m
|
|
596
627
|
|
|
597
|
-
|
|
628
|
+
"
|
|
598
629
|
`);
|
|
599
630
|
});
|
|
600
631
|
|
|
@@ -605,7 +636,10 @@ describe("wrangler", () => {
|
|
|
605
636
|
`"Arguments value and path are mutually exclusive"`
|
|
606
637
|
);
|
|
607
638
|
|
|
608
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
639
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
640
|
+
"
|
|
641
|
+
"
|
|
642
|
+
`);
|
|
609
643
|
expect(std.err).toMatchInlineSnapshot(`
|
|
610
644
|
"wrangler kv:key put <key> [value]
|
|
611
645
|
|
|
@@ -624,13 +658,14 @@ describe("wrangler", () => {
|
|
|
624
658
|
Options:
|
|
625
659
|
--binding The binding of the namespace to write to [string]
|
|
626
660
|
--namespace-id The id of the namespace to write to [string]
|
|
627
|
-
|
|
661
|
+
-e, --env Perform on a specific environment [string]
|
|
628
662
|
--preview Interact with a preview namespace [boolean]
|
|
629
663
|
--ttl Time for which the entries should be visible [number]
|
|
630
664
|
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
631
665
|
--path Read value from the file at a given path [string]
|
|
666
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mArguments value and path are mutually exclusive[0m
|
|
632
667
|
|
|
633
|
-
|
|
668
|
+
"
|
|
634
669
|
`);
|
|
635
670
|
});
|
|
636
671
|
|
|
@@ -642,11 +677,14 @@ describe("wrangler", () => {
|
|
|
642
677
|
`"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
|
|
643
678
|
);
|
|
644
679
|
|
|
645
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
680
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
681
|
+
"
|
|
682
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
|
|
683
|
+
`);
|
|
646
684
|
expect(std.err).toMatchInlineSnapshot(`
|
|
647
|
-
"
|
|
685
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".[0m
|
|
648
686
|
|
|
649
|
-
|
|
687
|
+
"
|
|
650
688
|
`);
|
|
651
689
|
});
|
|
652
690
|
|
|
@@ -661,11 +699,14 @@ describe("wrangler", () => {
|
|
|
661
699
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
662
700
|
`"someBinding has both a namespace ID and a preview ID. Specify \\"--preview\\" or \\"--preview false\\" to avoid writing data to the wrong namespace."`
|
|
663
701
|
);
|
|
664
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
702
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
703
|
+
"
|
|
704
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
|
|
705
|
+
`);
|
|
665
706
|
expect(std.err).toMatchInlineSnapshot(`
|
|
666
|
-
"
|
|
707
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1msomeBinding has both a namespace ID and a preview ID. Specify \\"--preview\\" or \\"--preview false\\" to avoid writing data to the wrong namespace.[0m
|
|
667
708
|
|
|
668
|
-
|
|
709
|
+
"
|
|
669
710
|
`);
|
|
670
711
|
expect(requests.count).toEqual(0);
|
|
671
712
|
});
|
|
@@ -673,26 +714,26 @@ describe("wrangler", () => {
|
|
|
673
714
|
|
|
674
715
|
describe("list", () => {
|
|
675
716
|
it("should list the keys of a namespace specified by namespace-id", async () => {
|
|
676
|
-
const keys = [
|
|
717
|
+
const keys = [
|
|
718
|
+
{ name: "key-1" },
|
|
719
|
+
{ name: "key-2", expiration: 123456789 },
|
|
720
|
+
{ name: "key-3", expiration_ttl: 666 },
|
|
721
|
+
];
|
|
677
722
|
mockKeyListRequest("some-namespace-id", keys);
|
|
678
723
|
await runWrangler("kv:key list --namespace-id some-namespace-id");
|
|
679
724
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
680
725
|
expect(std.out).toMatchInlineSnapshot(`
|
|
681
726
|
"[
|
|
682
727
|
{
|
|
683
|
-
\\"name\\": \\"key-1\\"
|
|
684
|
-
\\"expiration\\": 123456789,
|
|
685
|
-
\\"metadata\\": {}
|
|
728
|
+
\\"name\\": \\"key-1\\"
|
|
686
729
|
},
|
|
687
730
|
{
|
|
688
731
|
\\"name\\": \\"key-2\\",
|
|
689
|
-
\\"expiration\\": 123456789
|
|
690
|
-
\\"metadata\\": {}
|
|
732
|
+
\\"expiration\\": 123456789
|
|
691
733
|
},
|
|
692
734
|
{
|
|
693
735
|
\\"name\\": \\"key-3\\",
|
|
694
|
-
\\"
|
|
695
|
-
\\"metadata\\": {}
|
|
736
|
+
\\"expiration_ttl\\": 666
|
|
696
737
|
}
|
|
697
738
|
]"
|
|
698
739
|
`);
|
|
@@ -700,7 +741,7 @@ describe("wrangler", () => {
|
|
|
700
741
|
|
|
701
742
|
it("should list the keys of a namespace specified by binding", async () => {
|
|
702
743
|
writeWranglerConfig();
|
|
703
|
-
const keys = ["key-1", "key-2", "key-3"];
|
|
744
|
+
const keys = [{ name: "key-1" }, { name: "key-2" }, { name: "key-3" }];
|
|
704
745
|
mockKeyListRequest("bound-id", keys);
|
|
705
746
|
|
|
706
747
|
await runWrangler("kv:key list --binding someBinding");
|
|
@@ -708,19 +749,13 @@ describe("wrangler", () => {
|
|
|
708
749
|
expect(std.out).toMatchInlineSnapshot(`
|
|
709
750
|
"[
|
|
710
751
|
{
|
|
711
|
-
\\"name\\": \\"key-1\\"
|
|
712
|
-
\\"expiration\\": 123456789,
|
|
713
|
-
\\"metadata\\": {}
|
|
752
|
+
\\"name\\": \\"key-1\\"
|
|
714
753
|
},
|
|
715
754
|
{
|
|
716
|
-
\\"name\\": \\"key-2\\"
|
|
717
|
-
\\"expiration\\": 123456789,
|
|
718
|
-
\\"metadata\\": {}
|
|
755
|
+
\\"name\\": \\"key-2\\"
|
|
719
756
|
},
|
|
720
757
|
{
|
|
721
|
-
\\"name\\": \\"key-3\\"
|
|
722
|
-
\\"expiration\\": 123456789,
|
|
723
|
-
\\"metadata\\": {}
|
|
758
|
+
\\"name\\": \\"key-3\\"
|
|
724
759
|
}
|
|
725
760
|
]"
|
|
726
761
|
`);
|
|
@@ -728,26 +763,20 @@ describe("wrangler", () => {
|
|
|
728
763
|
|
|
729
764
|
it("should list the keys of a preview namespace specified by binding", async () => {
|
|
730
765
|
writeWranglerConfig();
|
|
731
|
-
const keys = ["key-1", "key-2", "key-3"];
|
|
766
|
+
const keys = [{ name: "key-1" }, { name: "key-2" }, { name: "key-3" }];
|
|
732
767
|
mockKeyListRequest("preview-bound-id", keys);
|
|
733
768
|
await runWrangler("kv:key list --binding someBinding --preview");
|
|
734
769
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
735
770
|
expect(std.out).toMatchInlineSnapshot(`
|
|
736
771
|
"[
|
|
737
772
|
{
|
|
738
|
-
\\"name\\": \\"key-1\\"
|
|
739
|
-
\\"expiration\\": 123456789,
|
|
740
|
-
\\"metadata\\": {}
|
|
773
|
+
\\"name\\": \\"key-1\\"
|
|
741
774
|
},
|
|
742
775
|
{
|
|
743
|
-
\\"name\\": \\"key-2\\"
|
|
744
|
-
\\"expiration\\": 123456789,
|
|
745
|
-
\\"metadata\\": {}
|
|
776
|
+
\\"name\\": \\"key-2\\"
|
|
746
777
|
},
|
|
747
778
|
{
|
|
748
|
-
\\"name\\": \\"key-3\\"
|
|
749
|
-
\\"expiration\\": 123456789,
|
|
750
|
-
\\"metadata\\": {}
|
|
779
|
+
\\"name\\": \\"key-3\\"
|
|
751
780
|
}
|
|
752
781
|
]"
|
|
753
782
|
`);
|
|
@@ -755,7 +784,7 @@ describe("wrangler", () => {
|
|
|
755
784
|
|
|
756
785
|
it("should list the keys of a namespace specified by binding, in a given environment", async () => {
|
|
757
786
|
writeWranglerConfig();
|
|
758
|
-
const keys = ["key-1", "key-2", "key-3"];
|
|
787
|
+
const keys = [{ name: "key-1" }, { name: "key-2" }, { name: "key-3" }];
|
|
759
788
|
mockKeyListRequest("env-bound-id", keys);
|
|
760
789
|
await runWrangler(
|
|
761
790
|
"kv:key list --binding someBinding --env some-environment"
|
|
@@ -764,19 +793,13 @@ describe("wrangler", () => {
|
|
|
764
793
|
expect(std.out).toMatchInlineSnapshot(`
|
|
765
794
|
"[
|
|
766
795
|
{
|
|
767
|
-
\\"name\\": \\"key-1\\"
|
|
768
|
-
\\"expiration\\": 123456789,
|
|
769
|
-
\\"metadata\\": {}
|
|
796
|
+
\\"name\\": \\"key-1\\"
|
|
770
797
|
},
|
|
771
798
|
{
|
|
772
|
-
\\"name\\": \\"key-2\\"
|
|
773
|
-
\\"expiration\\": 123456789,
|
|
774
|
-
\\"metadata\\": {}
|
|
799
|
+
\\"name\\": \\"key-2\\"
|
|
775
800
|
},
|
|
776
801
|
{
|
|
777
|
-
\\"name\\": \\"key-3\\"
|
|
778
|
-
\\"expiration\\": 123456789,
|
|
779
|
-
\\"metadata\\": {}
|
|
802
|
+
\\"name\\": \\"key-3\\"
|
|
780
803
|
}
|
|
781
804
|
]"
|
|
782
805
|
`);
|
|
@@ -784,7 +807,7 @@ describe("wrangler", () => {
|
|
|
784
807
|
|
|
785
808
|
it("should list the keys of a preview namespace specified by binding, in a given environment", async () => {
|
|
786
809
|
writeWranglerConfig();
|
|
787
|
-
const keys = ["key-1", "key-2", "key-3"];
|
|
810
|
+
const keys = [{ name: "key-1" }, { name: "key-2" }, { name: "key-3" }];
|
|
788
811
|
mockKeyListRequest("preview-env-bound-id", keys);
|
|
789
812
|
await runWrangler(
|
|
790
813
|
"kv:key list --binding someBinding --preview --env some-environment"
|
|
@@ -793,19 +816,13 @@ describe("wrangler", () => {
|
|
|
793
816
|
expect(std.out).toMatchInlineSnapshot(`
|
|
794
817
|
"[
|
|
795
818
|
{
|
|
796
|
-
\\"name\\": \\"key-1\\"
|
|
797
|
-
\\"expiration\\": 123456789,
|
|
798
|
-
\\"metadata\\": {}
|
|
819
|
+
\\"name\\": \\"key-1\\"
|
|
799
820
|
},
|
|
800
821
|
{
|
|
801
|
-
\\"name\\": \\"key-2\\"
|
|
802
|
-
\\"expiration\\": 123456789,
|
|
803
|
-
\\"metadata\\": {}
|
|
822
|
+
\\"name\\": \\"key-2\\"
|
|
804
823
|
},
|
|
805
824
|
{
|
|
806
|
-
\\"name\\": \\"key-3\\"
|
|
807
|
-
\\"expiration\\": 123456789,
|
|
808
|
-
\\"metadata\\": {}
|
|
825
|
+
\\"name\\": \\"key-3\\"
|
|
809
826
|
}
|
|
810
827
|
]"
|
|
811
828
|
`);
|
|
@@ -822,9 +839,9 @@ describe("wrangler", () => {
|
|
|
822
839
|
describe(`cursor - ${blankCursorValue}`, () => {
|
|
823
840
|
it("should make multiple requests for paginated results", async () => {
|
|
824
841
|
// Create a lot of mock keys, so that the fetch requests will be paginated
|
|
825
|
-
const keys:
|
|
842
|
+
const keys: NamespaceKeyInfo[] = [];
|
|
826
843
|
for (let i = 0; i < 550; i++) {
|
|
827
|
-
keys.push("key-" + i);
|
|
844
|
+
keys.push({ name: "key-" + i });
|
|
828
845
|
}
|
|
829
846
|
// Ask for the keys in pages of size 100.
|
|
830
847
|
const requests = mockKeyListRequest(
|
|
@@ -833,13 +850,9 @@ describe("wrangler", () => {
|
|
|
833
850
|
100,
|
|
834
851
|
blankCursorValue
|
|
835
852
|
);
|
|
836
|
-
await runWrangler(
|
|
837
|
-
"kv:key list --namespace-id some-namespace-id --limit 100"
|
|
838
|
-
);
|
|
853
|
+
await runWrangler("kv:key list --namespace-id some-namespace-id");
|
|
839
854
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
840
|
-
expect(
|
|
841
|
-
JSON.parse(std.out).map((k: NamespaceKeyInfo) => k.name)
|
|
842
|
-
).toEqual(keys);
|
|
855
|
+
expect(JSON.parse(std.out)).toEqual(keys);
|
|
843
856
|
expect(requests.count).toEqual(6);
|
|
844
857
|
});
|
|
845
858
|
});
|
|
@@ -853,11 +866,14 @@ describe("wrangler", () => {
|
|
|
853
866
|
`"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
|
|
854
867
|
);
|
|
855
868
|
expect(std.err).toMatchInlineSnapshot(`
|
|
856
|
-
"
|
|
869
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".[0m
|
|
857
870
|
|
|
858
|
-
|
|
871
|
+
"
|
|
872
|
+
`);
|
|
873
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
874
|
+
"
|
|
875
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
|
|
859
876
|
`);
|
|
860
|
-
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
861
877
|
});
|
|
862
878
|
});
|
|
863
879
|
|
|
@@ -915,7 +931,7 @@ describe("wrangler", () => {
|
|
|
915
931
|
"my-value"
|
|
916
932
|
);
|
|
917
933
|
await runWrangler(
|
|
918
|
-
"kv:key get my-key
|
|
934
|
+
"kv:key get my-key --binding someBinding --env some-environment --preview false"
|
|
919
935
|
);
|
|
920
936
|
expect(std.out).toMatchInlineSnapshot(`"my-value"`);
|
|
921
937
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
@@ -927,7 +943,10 @@ describe("wrangler", () => {
|
|
|
927
943
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
928
944
|
`"Not enough non-option arguments: got 0, need at least 1"`
|
|
929
945
|
);
|
|
930
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
946
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
947
|
+
"
|
|
948
|
+
"
|
|
949
|
+
`);
|
|
931
950
|
expect(std.err).toMatchInlineSnapshot(`
|
|
932
951
|
"wrangler kv:key get <key>
|
|
933
952
|
|
|
@@ -945,10 +964,11 @@ describe("wrangler", () => {
|
|
|
945
964
|
Options:
|
|
946
965
|
--binding The name of the namespace to get from [string]
|
|
947
966
|
--namespace-id The id of the namespace to get from [string]
|
|
948
|
-
|
|
967
|
+
-e, --env Perform on a specific environment [string]
|
|
949
968
|
--preview Interact with a preview namespace [boolean] [default: false]
|
|
969
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot enough non-option arguments: got 0, need at least 1[0m
|
|
950
970
|
|
|
951
|
-
|
|
971
|
+
"
|
|
952
972
|
`);
|
|
953
973
|
});
|
|
954
974
|
|
|
@@ -958,7 +978,10 @@ describe("wrangler", () => {
|
|
|
958
978
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
959
979
|
`"Exactly one of the arguments binding and namespace-id is required"`
|
|
960
980
|
);
|
|
961
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
981
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
982
|
+
"
|
|
983
|
+
"
|
|
984
|
+
`);
|
|
962
985
|
expect(std.err).toMatchInlineSnapshot(`
|
|
963
986
|
"wrangler kv:key get <key>
|
|
964
987
|
|
|
@@ -976,10 +999,11 @@ describe("wrangler", () => {
|
|
|
976
999
|
Options:
|
|
977
1000
|
--binding The name of the namespace to get from [string]
|
|
978
1001
|
--namespace-id The id of the namespace to get from [string]
|
|
979
|
-
|
|
1002
|
+
-e, --env Perform on a specific environment [string]
|
|
980
1003
|
--preview Interact with a preview namespace [boolean] [default: false]
|
|
1004
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mExactly one of the arguments binding and namespace-id is required[0m
|
|
981
1005
|
|
|
982
|
-
|
|
1006
|
+
"
|
|
983
1007
|
`);
|
|
984
1008
|
});
|
|
985
1009
|
|
|
@@ -990,7 +1014,10 @@ describe("wrangler", () => {
|
|
|
990
1014
|
`"Arguments binding and namespace-id are mutually exclusive"`
|
|
991
1015
|
);
|
|
992
1016
|
|
|
993
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
1017
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1018
|
+
"
|
|
1019
|
+
"
|
|
1020
|
+
`);
|
|
994
1021
|
expect(std.err).toMatchInlineSnapshot(`
|
|
995
1022
|
"wrangler kv:key get <key>
|
|
996
1023
|
|
|
@@ -1008,10 +1035,11 @@ describe("wrangler", () => {
|
|
|
1008
1035
|
Options:
|
|
1009
1036
|
--binding The name of the namespace to get from [string]
|
|
1010
1037
|
--namespace-id The id of the namespace to get from [string]
|
|
1011
|
-
|
|
1038
|
+
-e, --env Perform on a specific environment [string]
|
|
1012
1039
|
--preview Interact with a preview namespace [boolean] [default: false]
|
|
1040
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mArguments binding and namespace-id are mutually exclusive[0m
|
|
1013
1041
|
|
|
1014
|
-
|
|
1042
|
+
"
|
|
1015
1043
|
`);
|
|
1016
1044
|
});
|
|
1017
1045
|
|
|
@@ -1022,11 +1050,14 @@ describe("wrangler", () => {
|
|
|
1022
1050
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
1023
1051
|
`"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
|
|
1024
1052
|
);
|
|
1025
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
1053
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1054
|
+
"
|
|
1055
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
|
|
1056
|
+
`);
|
|
1026
1057
|
expect(std.err).toMatchInlineSnapshot(`
|
|
1027
|
-
"
|
|
1058
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".[0m
|
|
1028
1059
|
|
|
1029
|
-
|
|
1060
|
+
"
|
|
1030
1061
|
`);
|
|
1031
1062
|
});
|
|
1032
1063
|
});
|
|
@@ -1086,9 +1117,9 @@ describe("wrangler", () => {
|
|
|
1086
1117
|
);
|
|
1087
1118
|
|
|
1088
1119
|
expect(std.err).toMatchInlineSnapshot(`
|
|
1089
|
-
"
|
|
1120
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".[0m
|
|
1090
1121
|
|
|
1091
|
-
|
|
1122
|
+
"
|
|
1092
1123
|
`);
|
|
1093
1124
|
});
|
|
1094
1125
|
|
|
@@ -1099,7 +1130,7 @@ describe("wrangler", () => {
|
|
|
1099
1130
|
`kv:key delete --binding someBinding --env some-environment --preview false someKey`
|
|
1100
1131
|
);
|
|
1101
1132
|
expect(std.out).toMatchInlineSnapshot(
|
|
1102
|
-
`"
|
|
1133
|
+
`"Deleting the key \\"someKey\\" on namespace env-bound-id."`
|
|
1103
1134
|
);
|
|
1104
1135
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1105
1136
|
expect(requests.count).toEqual(1);
|
|
@@ -1191,7 +1222,10 @@ describe("wrangler", () => {
|
|
|
1191
1222
|
"Unexpected JSON input from \\"keys.json\\".
|
|
1192
1223
|
Expected an array of key-value objects but got type \\"object\\"."
|
|
1193
1224
|
`);
|
|
1194
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
1225
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1226
|
+
"
|
|
1227
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
|
|
1228
|
+
`);
|
|
1195
1229
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1196
1230
|
});
|
|
1197
1231
|
|
|
@@ -1225,10 +1259,16 @@ describe("wrangler", () => {
|
|
|
1225
1259
|
The item at index 3 is {\\"value\\":\\"someValue\\"}"
|
|
1226
1260
|
`);
|
|
1227
1261
|
|
|
1228
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
1262
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1263
|
+
"
|
|
1264
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
|
|
1265
|
+
`);
|
|
1229
1266
|
expect(std.warn).toMatchInlineSnapshot(`
|
|
1230
|
-
"
|
|
1231
|
-
|
|
1267
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mUnexpected key-value properties in \\"keys.json\\".[0m
|
|
1268
|
+
|
|
1269
|
+
The item at index 4 contains unexpected properties: [\\"invalid\\"].
|
|
1270
|
+
|
|
1271
|
+
"
|
|
1232
1272
|
`);
|
|
1233
1273
|
});
|
|
1234
1274
|
});
|
|
@@ -1360,7 +1400,10 @@ describe("wrangler", () => {
|
|
|
1360
1400
|
Expected an array of strings but got:
|
|
1361
1401
|
12354"
|
|
1362
1402
|
`);
|
|
1363
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
1403
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1404
|
+
"
|
|
1405
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
|
|
1406
|
+
`);
|
|
1364
1407
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1365
1408
|
});
|
|
1366
1409
|
|
|
@@ -1382,7 +1425,10 @@ describe("wrangler", () => {
|
|
|
1382
1425
|
The item at index 2 is type: \\"object\\" - {\\"key\\":\\"someKey\\"}
|
|
1383
1426
|
The item at index 3 is type: \\"object\\" - null"
|
|
1384
1427
|
`);
|
|
1385
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
1428
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1429
|
+
"
|
|
1430
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
|
|
1431
|
+
`);
|
|
1386
1432
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1387
1433
|
});
|
|
1388
1434
|
});
|
|
@@ -1393,7 +1439,7 @@ function writeWranglerConfig() {
|
|
|
1393
1439
|
writeFileSync(
|
|
1394
1440
|
"./wrangler.toml",
|
|
1395
1441
|
[
|
|
1396
|
-
'name = "
|
|
1442
|
+
'name = "other-worker"',
|
|
1397
1443
|
"kv_namespaces = [",
|
|
1398
1444
|
' { binding = "someBinding", id = "bound-id", preview_id = "preview-bound-id" }',
|
|
1399
1445
|
"]",
|