wrangler 0.0.0-e2a26a0 → 0.0.0-e3a458e
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/package.json +24 -11
- package/pages/functions/filepath-routing.test.ts +212 -36
- package/pages/functions/filepath-routing.ts +69 -119
- package/pages/functions/routes.ts +8 -17
- package/pages/functions/template-worker.ts +3 -9
- package/src/__tests__/configuration.test.ts +2598 -0
- package/src/__tests__/dev.test.tsx +437 -63
- package/src/__tests__/dev2.test.tsx +154 -0
- package/src/__tests__/guess-worker-format.test.ts +58 -0
- package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
- package/src/__tests__/helpers/mock-account-id.ts +26 -8
- package/src/__tests__/helpers/mock-bin.ts +4 -1
- package/src/__tests__/helpers/mock-cfetch.ts +5 -5
- package/src/__tests__/helpers/mock-console.ts +21 -7
- package/src/__tests__/helpers/mock-kv.ts +9 -16
- package/src/__tests__/helpers/mock-stdin.ts +103 -0
- package/src/__tests__/helpers/mock-web-socket.ts +29 -0
- package/src/__tests__/helpers/run-in-tmp.ts +3 -0
- package/src/__tests__/helpers/run-wrangler.ts +5 -3
- package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
- package/src/__tests__/https-options.test.ts +127 -0
- package/src/__tests__/index.test.ts +468 -20
- package/src/__tests__/jest.setup.ts +37 -5
- package/src/__tests__/kv.test.ts +426 -183
- package/src/__tests__/logout.test.ts +15 -13
- package/src/__tests__/package-manager.test.ts +2 -2
- package/src/__tests__/pages.test.ts +44 -0
- package/src/__tests__/parse.test.ts +322 -0
- package/src/__tests__/publish.test.ts +1733 -344
- package/src/__tests__/r2.test.ts +198 -0
- package/src/__tests__/route.test.ts +45 -0
- package/src/__tests__/secret.test.ts +301 -86
- package/src/__tests__/sentry.test.ts +146 -0
- package/src/__tests__/tail.test.ts +564 -0
- package/src/__tests__/whoami.test.tsx +21 -7
- package/src/bundle.ts +142 -0
- package/src/cfetch/index.ts +8 -6
- package/src/cfetch/internal.ts +60 -22
- package/src/cli.ts +10 -0
- package/src/config/README.md +107 -0
- package/src/config/config.ts +279 -0
- package/src/config/diagnostics.ts +80 -0
- package/src/config/environment.ts +305 -0
- package/src/config/index.ts +52 -0
- package/src/config/validation-helpers.ts +468 -0
- package/src/config/validation.ts +1057 -0
- package/src/{api/preview.ts → create-worker-preview.ts} +59 -21
- package/src/create-worker-upload-form.ts +217 -0
- package/src/dev/dev.tsx +362 -0
- package/src/dev/local.tsx +247 -0
- package/src/dev/remote.tsx +203 -0
- package/src/dev/use-esbuild.ts +100 -0
- package/src/entry.ts +159 -0
- package/src/environment-variables.ts +33 -0
- package/src/https-options.ts +122 -0
- package/src/index.tsx +1030 -766
- package/src/inspect.ts +25 -4
- package/src/{kv.tsx → kv.ts} +110 -55
- package/src/module-collection.ts +212 -22
- package/src/open-in-browser.ts +25 -0
- package/src/package-manager.ts +21 -15
- package/src/pages.tsx +10 -11
- package/src/parse.ts +183 -0
- package/src/proxy.ts +115 -45
- package/src/publish.ts +273 -329
- package/src/r2.ts +50 -0
- package/src/reporting.ts +131 -0
- package/src/selfsigned.d.ts +29 -0
- package/src/sites.tsx +66 -33
- package/src/tail/filters.ts +279 -0
- package/src/tail/index.ts +299 -0
- package/src/tail/printing.ts +62 -0
- package/src/user.tsx +223 -124
- package/src/{api/worker.ts → worker.ts} +44 -36
- package/templates/new-worker.js +1 -1
- package/templates/new-worker.ts +1 -1
- package/templates/tsconfig.json +105 -0
- package/wrangler-dist/cli.js +129900 -113128
- package/wrangler-dist/cli.js.map +3 -3
- package/src/__tests__/helpers/mock-user.ts +0 -27
- package/src/api/form_data.ts +0 -134
- package/src/config.ts +0 -641
- package/src/dev.tsx +0 -834
- package/src/tail.tsx +0 -73
package/src/__tests__/kv.test.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { writeFileSync } from "node:fs";
|
|
2
|
+
import { Headers } from "undici";
|
|
2
3
|
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
|
|
3
4
|
import {
|
|
4
5
|
setMockResponse,
|
|
@@ -7,10 +8,11 @@ import {
|
|
|
7
8
|
setMockFetchKVGetValue,
|
|
8
9
|
} from "./helpers/mock-cfetch";
|
|
9
10
|
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
11
|
+
import { mockConfirm } from "./helpers/mock-dialogs";
|
|
10
12
|
import { mockKeyListRequest } from "./helpers/mock-kv";
|
|
11
13
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
12
14
|
import { runWrangler } from "./helpers/run-wrangler";
|
|
13
|
-
import type { KVNamespaceInfo } from "../kv";
|
|
15
|
+
import type { KeyValue, KVNamespaceInfo, NamespaceKeyInfo } from "../kv";
|
|
14
16
|
|
|
15
17
|
describe("wrangler", () => {
|
|
16
18
|
mockAccountId();
|
|
@@ -53,12 +55,12 @@ describe("wrangler", () => {
|
|
|
53
55
|
namespace The name of the new namespace [string] [required]
|
|
54
56
|
|
|
55
57
|
Flags:
|
|
56
|
-
-c, --config
|
|
57
|
-
-h, --help
|
|
58
|
-
-v, --version
|
|
58
|
+
-c, --config Path to .toml configuration file [string]
|
|
59
|
+
-h, --help Show help [boolean]
|
|
60
|
+
-v, --version Show version number [boolean]
|
|
61
|
+
--legacy-env Use legacy environments [boolean]
|
|
59
62
|
|
|
60
63
|
Options:
|
|
61
|
-
-l, --local Run on my machine [boolean] [default: false]
|
|
62
64
|
--env Perform on a specific environment [string]
|
|
63
65
|
--preview Interact with a preview namespace [boolean]
|
|
64
66
|
|
|
@@ -82,12 +84,12 @@ describe("wrangler", () => {
|
|
|
82
84
|
namespace The name of the new namespace [string] [required]
|
|
83
85
|
|
|
84
86
|
Flags:
|
|
85
|
-
-c, --config
|
|
86
|
-
-h, --help
|
|
87
|
-
-v, --version
|
|
87
|
+
-c, --config Path to .toml configuration file [string]
|
|
88
|
+
-h, --help Show help [boolean]
|
|
89
|
+
-v, --version Show version number [boolean]
|
|
90
|
+
--legacy-env Use legacy environments [boolean]
|
|
88
91
|
|
|
89
92
|
Options:
|
|
90
|
-
-l, --local Run on my machine [boolean] [default: false]
|
|
91
93
|
--env Perform on a specific environment [string]
|
|
92
94
|
--preview Interact with a preview namespace [boolean]
|
|
93
95
|
|
|
@@ -112,12 +114,12 @@ describe("wrangler", () => {
|
|
|
112
114
|
namespace The name of the new namespace [string] [required]
|
|
113
115
|
|
|
114
116
|
Flags:
|
|
115
|
-
-c, --config
|
|
116
|
-
-h, --help
|
|
117
|
-
-v, --version
|
|
117
|
+
-c, --config Path to .toml configuration file [string]
|
|
118
|
+
-h, --help Show help [boolean]
|
|
119
|
+
-v, --version Show version number [boolean]
|
|
120
|
+
--legacy-env Use legacy environments [boolean]
|
|
118
121
|
|
|
119
122
|
Options:
|
|
120
|
-
-l, --local Run on my machine [boolean] [default: false]
|
|
121
123
|
--env Perform on a specific environment [string]
|
|
122
124
|
--preview Interact with a preview namespace [boolean]
|
|
123
125
|
|
|
@@ -276,12 +278,12 @@ describe("wrangler", () => {
|
|
|
276
278
|
Deletes a given namespace.
|
|
277
279
|
|
|
278
280
|
Flags:
|
|
279
|
-
-c, --config
|
|
280
|
-
-h, --help
|
|
281
|
-
-v, --version
|
|
281
|
+
-c, --config Path to .toml configuration file [string]
|
|
282
|
+
-h, --help Show help [boolean]
|
|
283
|
+
-v, --version Show version number [boolean]
|
|
284
|
+
--legacy-env Use legacy environments [boolean]
|
|
282
285
|
|
|
283
286
|
Options:
|
|
284
|
-
-l, --local Run on my machine [boolean] [default: false]
|
|
285
287
|
--binding The name of the namespace to delete [string]
|
|
286
288
|
--namespace-id The id of the namespace to delete [string]
|
|
287
289
|
--env Perform on a specific environment [string]
|
|
@@ -319,10 +321,7 @@ describe("wrangler", () => {
|
|
|
319
321
|
describe("put", () => {
|
|
320
322
|
function mockKeyPutRequest(
|
|
321
323
|
expectedNamespaceId: string,
|
|
322
|
-
|
|
323
|
-
expectedValue: string,
|
|
324
|
-
expiration?: number,
|
|
325
|
-
expirationTtl?: number
|
|
324
|
+
expectedKV: KeyValue
|
|
326
325
|
) {
|
|
327
326
|
const requests = { count: 0 };
|
|
328
327
|
setMockResponse(
|
|
@@ -332,15 +331,19 @@ describe("wrangler", () => {
|
|
|
332
331
|
requests.count++;
|
|
333
332
|
expect(accountId).toEqual("some-account-id");
|
|
334
333
|
expect(namespaceId).toEqual(expectedNamespaceId);
|
|
335
|
-
expect(key).toEqual(
|
|
336
|
-
expect(body).toEqual(
|
|
337
|
-
if (expiration !== undefined) {
|
|
338
|
-
expect(query.get("expiration")).toEqual(
|
|
334
|
+
expect(key).toEqual(expectedKV.key);
|
|
335
|
+
expect(body).toEqual(expectedKV.value);
|
|
336
|
+
if (expectedKV.expiration !== undefined) {
|
|
337
|
+
expect(query.get("expiration")).toEqual(
|
|
338
|
+
`${expectedKV.expiration}`
|
|
339
|
+
);
|
|
339
340
|
} else {
|
|
340
341
|
expect(query.has("expiration")).toBe(false);
|
|
341
342
|
}
|
|
342
|
-
if (
|
|
343
|
-
expect(query.get("expiration_ttl")).toEqual(
|
|
343
|
+
if (expectedKV.expiration_ttl) {
|
|
344
|
+
expect(query.get("expiration_ttl")).toEqual(
|
|
345
|
+
`${expectedKV.expiration_ttl}`
|
|
346
|
+
);
|
|
344
347
|
} else {
|
|
345
348
|
expect(query.has("expiration_ttl")).toBe(false);
|
|
346
349
|
}
|
|
@@ -351,11 +354,10 @@ describe("wrangler", () => {
|
|
|
351
354
|
}
|
|
352
355
|
|
|
353
356
|
it("should put a key in a given namespace specified by namespace-id", async () => {
|
|
354
|
-
const requests = mockKeyPutRequest(
|
|
355
|
-
"
|
|
356
|
-
"my-
|
|
357
|
-
|
|
358
|
-
);
|
|
357
|
+
const requests = mockKeyPutRequest("some-namespace-id", {
|
|
358
|
+
key: "my-key",
|
|
359
|
+
value: "my-value",
|
|
360
|
+
});
|
|
359
361
|
|
|
360
362
|
await runWrangler(
|
|
361
363
|
"kv:key put my-key my-value --namespace-id some-namespace-id"
|
|
@@ -370,7 +372,10 @@ describe("wrangler", () => {
|
|
|
370
372
|
|
|
371
373
|
it("should put a key in a given namespace specified by binding", async () => {
|
|
372
374
|
writeWranglerConfig();
|
|
373
|
-
const requests = mockKeyPutRequest("bound-id",
|
|
375
|
+
const requests = mockKeyPutRequest("bound-id", {
|
|
376
|
+
key: "my-key",
|
|
377
|
+
value: "my-value",
|
|
378
|
+
});
|
|
374
379
|
await runWrangler(
|
|
375
380
|
"kv:key put my-key my-value --binding someBinding --preview false"
|
|
376
381
|
);
|
|
@@ -384,11 +389,10 @@ describe("wrangler", () => {
|
|
|
384
389
|
|
|
385
390
|
it("should put a key in a given preview namespace specified by binding", async () => {
|
|
386
391
|
writeWranglerConfig();
|
|
387
|
-
const requests = mockKeyPutRequest(
|
|
388
|
-
"
|
|
389
|
-
"my-
|
|
390
|
-
|
|
391
|
-
);
|
|
392
|
+
const requests = mockKeyPutRequest("preview-bound-id", {
|
|
393
|
+
key: "my-key",
|
|
394
|
+
value: "my-value",
|
|
395
|
+
});
|
|
392
396
|
|
|
393
397
|
await runWrangler(
|
|
394
398
|
"kv:key put my-key my-value --binding someBinding --preview"
|
|
@@ -402,13 +406,12 @@ describe("wrangler", () => {
|
|
|
402
406
|
});
|
|
403
407
|
|
|
404
408
|
it("should add expiration and ttl properties when putting a key", async () => {
|
|
405
|
-
const requests = mockKeyPutRequest(
|
|
406
|
-
"
|
|
407
|
-
"my-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
);
|
|
409
|
+
const requests = mockKeyPutRequest("some-namespace-id", {
|
|
410
|
+
key: "my-key",
|
|
411
|
+
value: "my-value",
|
|
412
|
+
expiration: 10,
|
|
413
|
+
expiration_ttl: 20,
|
|
414
|
+
});
|
|
412
415
|
await runWrangler(
|
|
413
416
|
"kv:key put my-key my-value --namespace-id some-namespace-id --expiration 10 --ttl 20"
|
|
414
417
|
);
|
|
@@ -421,11 +424,10 @@ describe("wrangler", () => {
|
|
|
421
424
|
|
|
422
425
|
it("should put a key to the specified environment in a given namespace", async () => {
|
|
423
426
|
writeWranglerConfig();
|
|
424
|
-
const requests = mockKeyPutRequest(
|
|
425
|
-
"
|
|
426
|
-
"my-
|
|
427
|
-
|
|
428
|
-
);
|
|
427
|
+
const requests = mockKeyPutRequest("env-bound-id", {
|
|
428
|
+
key: "my-key",
|
|
429
|
+
value: "my-value",
|
|
430
|
+
});
|
|
429
431
|
await runWrangler(
|
|
430
432
|
"kv:key put my-key my-value --binding someBinding --env some-environment --preview false"
|
|
431
433
|
);
|
|
@@ -438,11 +440,10 @@ describe("wrangler", () => {
|
|
|
438
440
|
|
|
439
441
|
it("should put a key with a value loaded from a given path", async () => {
|
|
440
442
|
writeFileSync("foo.txt", "file-contents", "utf-8");
|
|
441
|
-
const requests = mockKeyPutRequest(
|
|
442
|
-
"
|
|
443
|
-
"
|
|
444
|
-
|
|
445
|
-
);
|
|
443
|
+
const requests = mockKeyPutRequest("some-namespace-id", {
|
|
444
|
+
key: "my-key",
|
|
445
|
+
value: "file-contents",
|
|
446
|
+
});
|
|
446
447
|
await runWrangler(
|
|
447
448
|
"kv:key put my-key --namespace-id some-namespace-id --path foo.txt"
|
|
448
449
|
);
|
|
@@ -467,23 +468,23 @@ describe("wrangler", () => {
|
|
|
467
468
|
Writes a single key/value pair to the given namespace.
|
|
468
469
|
|
|
469
470
|
Positionals:
|
|
470
|
-
key The key to write to
|
|
471
|
-
value The value to write
|
|
471
|
+
key The key to write to [string] [required]
|
|
472
|
+
value The value to write [string]
|
|
472
473
|
|
|
473
474
|
Flags:
|
|
474
|
-
-c, --config
|
|
475
|
-
-h, --help
|
|
476
|
-
-v, --version
|
|
475
|
+
-c, --config Path to .toml configuration file [string]
|
|
476
|
+
-h, --help Show help [boolean]
|
|
477
|
+
-v, --version Show version number [boolean]
|
|
478
|
+
--legacy-env Use legacy environments [boolean]
|
|
477
479
|
|
|
478
480
|
Options:
|
|
479
|
-
|
|
480
|
-
--
|
|
481
|
-
--namespace-id The id of the namespace to write to. [string]
|
|
481
|
+
--binding The binding of the namespace to write to [string]
|
|
482
|
+
--namespace-id The id of the namespace to write to [string]
|
|
482
483
|
--env Perform on a specific environment [string]
|
|
483
484
|
--preview Interact with a preview namespace [boolean]
|
|
484
|
-
--ttl Time for which the entries should be visible
|
|
485
|
+
--ttl Time for which the entries should be visible [number]
|
|
485
486
|
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
486
|
-
--path Read value from the file at a given path
|
|
487
|
+
--path Read value from the file at a given path [string]
|
|
487
488
|
|
|
488
489
|
Not enough non-option arguments: got 0, need at least 1"
|
|
489
490
|
`);
|
|
@@ -503,23 +504,23 @@ describe("wrangler", () => {
|
|
|
503
504
|
Writes a single key/value pair to the given namespace.
|
|
504
505
|
|
|
505
506
|
Positionals:
|
|
506
|
-
key The key to write to
|
|
507
|
-
value The value to write
|
|
507
|
+
key The key to write to [string] [required]
|
|
508
|
+
value The value to write [string]
|
|
508
509
|
|
|
509
510
|
Flags:
|
|
510
|
-
-c, --config
|
|
511
|
-
-h, --help
|
|
512
|
-
-v, --version
|
|
511
|
+
-c, --config Path to .toml configuration file [string]
|
|
512
|
+
-h, --help Show help [boolean]
|
|
513
|
+
-v, --version Show version number [boolean]
|
|
514
|
+
--legacy-env Use legacy environments [boolean]
|
|
513
515
|
|
|
514
516
|
Options:
|
|
515
|
-
|
|
516
|
-
--
|
|
517
|
-
--namespace-id The id of the namespace to write to. [string]
|
|
517
|
+
--binding The binding of the namespace to write to [string]
|
|
518
|
+
--namespace-id The id of the namespace to write to [string]
|
|
518
519
|
--env Perform on a specific environment [string]
|
|
519
520
|
--preview Interact with a preview namespace [boolean]
|
|
520
|
-
--ttl Time for which the entries should be visible
|
|
521
|
+
--ttl Time for which the entries should be visible [number]
|
|
521
522
|
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
522
|
-
--path Read value from the file at a given path
|
|
523
|
+
--path Read value from the file at a given path [string]
|
|
523
524
|
|
|
524
525
|
Exactly one of the arguments binding and namespace-id is required"
|
|
525
526
|
`);
|
|
@@ -539,23 +540,23 @@ describe("wrangler", () => {
|
|
|
539
540
|
Writes a single key/value pair to the given namespace.
|
|
540
541
|
|
|
541
542
|
Positionals:
|
|
542
|
-
key The key to write to
|
|
543
|
-
value The value to write
|
|
543
|
+
key The key to write to [string] [required]
|
|
544
|
+
value The value to write [string]
|
|
544
545
|
|
|
545
546
|
Flags:
|
|
546
|
-
-c, --config
|
|
547
|
-
-h, --help
|
|
548
|
-
-v, --version
|
|
547
|
+
-c, --config Path to .toml configuration file [string]
|
|
548
|
+
-h, --help Show help [boolean]
|
|
549
|
+
-v, --version Show version number [boolean]
|
|
550
|
+
--legacy-env Use legacy environments [boolean]
|
|
549
551
|
|
|
550
552
|
Options:
|
|
551
|
-
|
|
552
|
-
--
|
|
553
|
-
--namespace-id The id of the namespace to write to. [string]
|
|
553
|
+
--binding The binding of the namespace to write to [string]
|
|
554
|
+
--namespace-id The id of the namespace to write to [string]
|
|
554
555
|
--env Perform on a specific environment [string]
|
|
555
556
|
--preview Interact with a preview namespace [boolean]
|
|
556
|
-
--ttl Time for which the entries should be visible
|
|
557
|
+
--ttl Time for which the entries should be visible [number]
|
|
557
558
|
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
558
|
-
--path Read value from the file at a given path
|
|
559
|
+
--path Read value from the file at a given path [string]
|
|
559
560
|
|
|
560
561
|
Arguments binding and namespace-id are mutually exclusive"
|
|
561
562
|
`);
|
|
@@ -575,23 +576,23 @@ describe("wrangler", () => {
|
|
|
575
576
|
Writes a single key/value pair to the given namespace.
|
|
576
577
|
|
|
577
578
|
Positionals:
|
|
578
|
-
key The key to write to
|
|
579
|
-
value The value to write
|
|
579
|
+
key The key to write to [string] [required]
|
|
580
|
+
value The value to write [string]
|
|
580
581
|
|
|
581
582
|
Flags:
|
|
582
|
-
-c, --config
|
|
583
|
-
-h, --help
|
|
584
|
-
-v, --version
|
|
583
|
+
-c, --config Path to .toml configuration file [string]
|
|
584
|
+
-h, --help Show help [boolean]
|
|
585
|
+
-v, --version Show version number [boolean]
|
|
586
|
+
--legacy-env Use legacy environments [boolean]
|
|
585
587
|
|
|
586
588
|
Options:
|
|
587
|
-
|
|
588
|
-
--
|
|
589
|
-
--namespace-id The id of the namespace to write to. [string]
|
|
589
|
+
--binding The binding of the namespace to write to [string]
|
|
590
|
+
--namespace-id The id of the namespace to write to [string]
|
|
590
591
|
--env Perform on a specific environment [string]
|
|
591
592
|
--preview Interact with a preview namespace [boolean]
|
|
592
|
-
--ttl Time for which the entries should be visible
|
|
593
|
+
--ttl Time for which the entries should be visible [number]
|
|
593
594
|
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
594
|
-
--path Read value from the file at a given path
|
|
595
|
+
--path Read value from the file at a given path [string]
|
|
595
596
|
|
|
596
597
|
Exactly one of the arguments value and path is required"
|
|
597
598
|
`);
|
|
@@ -611,23 +612,23 @@ describe("wrangler", () => {
|
|
|
611
612
|
Writes a single key/value pair to the given namespace.
|
|
612
613
|
|
|
613
614
|
Positionals:
|
|
614
|
-
key The key to write to
|
|
615
|
-
value The value to write
|
|
615
|
+
key The key to write to [string] [required]
|
|
616
|
+
value The value to write [string]
|
|
616
617
|
|
|
617
618
|
Flags:
|
|
618
|
-
-c, --config
|
|
619
|
-
-h, --help
|
|
620
|
-
-v, --version
|
|
619
|
+
-c, --config Path to .toml configuration file [string]
|
|
620
|
+
-h, --help Show help [boolean]
|
|
621
|
+
-v, --version Show version number [boolean]
|
|
622
|
+
--legacy-env Use legacy environments [boolean]
|
|
621
623
|
|
|
622
624
|
Options:
|
|
623
|
-
|
|
624
|
-
--
|
|
625
|
-
--namespace-id The id of the namespace to write to. [string]
|
|
625
|
+
--binding The binding of the namespace to write to [string]
|
|
626
|
+
--namespace-id The id of the namespace to write to [string]
|
|
626
627
|
--env Perform on a specific environment [string]
|
|
627
628
|
--preview Interact with a preview namespace [boolean]
|
|
628
|
-
--ttl Time for which the entries should be visible
|
|
629
|
+
--ttl Time for which the entries should be visible [number]
|
|
629
630
|
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
630
|
-
--path Read value from the file at a given path
|
|
631
|
+
--path Read value from the file at a given path [string]
|
|
631
632
|
|
|
632
633
|
Arguments value and path are mutually exclusive"
|
|
633
634
|
`);
|
|
@@ -645,18 +646,16 @@ describe("wrangler", () => {
|
|
|
645
646
|
expect(std.err).toMatchInlineSnapshot(`
|
|
646
647
|
"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
|
|
647
648
|
|
|
648
|
-
[32m%s[0m
|
|
649
|
-
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
649
|
+
[32m%s[0m If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
650
650
|
`);
|
|
651
651
|
});
|
|
652
652
|
|
|
653
653
|
it("should error if a given binding has both preview and non-preview and --preview is not specified", async () => {
|
|
654
654
|
writeWranglerConfig();
|
|
655
|
-
const requests = mockKeyPutRequest(
|
|
656
|
-
"
|
|
657
|
-
"my-
|
|
658
|
-
|
|
659
|
-
);
|
|
655
|
+
const requests = mockKeyPutRequest("preview-bound-id", {
|
|
656
|
+
key: "my-key",
|
|
657
|
+
value: "my-value",
|
|
658
|
+
});
|
|
660
659
|
await expect(
|
|
661
660
|
runWrangler("kv:key put my-key my-value --binding someBinding")
|
|
662
661
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
@@ -666,8 +665,7 @@ describe("wrangler", () => {
|
|
|
666
665
|
expect(std.err).toMatchInlineSnapshot(`
|
|
667
666
|
"someBinding has both a namespace ID and a preview ID. Specify \\"--preview\\" or \\"--preview false\\" to avoid writing data to the wrong namespace.
|
|
668
667
|
|
|
669
|
-
[32m%s[0m
|
|
670
|
-
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
668
|
+
[32m%s[0m If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
671
669
|
`);
|
|
672
670
|
expect(requests.count).toEqual(0);
|
|
673
671
|
});
|
|
@@ -675,26 +673,26 @@ describe("wrangler", () => {
|
|
|
675
673
|
|
|
676
674
|
describe("list", () => {
|
|
677
675
|
it("should list the keys of a namespace specified by namespace-id", async () => {
|
|
678
|
-
const keys = [
|
|
676
|
+
const keys = [
|
|
677
|
+
{ name: "key-1" },
|
|
678
|
+
{ name: "key-2", expiration: 123456789 },
|
|
679
|
+
{ name: "key-3", expiration_ttl: 666 },
|
|
680
|
+
];
|
|
679
681
|
mockKeyListRequest("some-namespace-id", keys);
|
|
680
682
|
await runWrangler("kv:key list --namespace-id some-namespace-id");
|
|
681
683
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
682
684
|
expect(std.out).toMatchInlineSnapshot(`
|
|
683
685
|
"[
|
|
684
686
|
{
|
|
685
|
-
\\"name\\": \\"key-1\\"
|
|
686
|
-
\\"expiration\\": 123456789,
|
|
687
|
-
\\"metadata\\": {}
|
|
687
|
+
\\"name\\": \\"key-1\\"
|
|
688
688
|
},
|
|
689
689
|
{
|
|
690
690
|
\\"name\\": \\"key-2\\",
|
|
691
|
-
\\"expiration\\": 123456789
|
|
692
|
-
\\"metadata\\": {}
|
|
691
|
+
\\"expiration\\": 123456789
|
|
693
692
|
},
|
|
694
693
|
{
|
|
695
694
|
\\"name\\": \\"key-3\\",
|
|
696
|
-
\\"
|
|
697
|
-
\\"metadata\\": {}
|
|
695
|
+
\\"expiration_ttl\\": 666
|
|
698
696
|
}
|
|
699
697
|
]"
|
|
700
698
|
`);
|
|
@@ -702,7 +700,7 @@ describe("wrangler", () => {
|
|
|
702
700
|
|
|
703
701
|
it("should list the keys of a namespace specified by binding", async () => {
|
|
704
702
|
writeWranglerConfig();
|
|
705
|
-
const keys = ["key-1", "key-2", "key-3"];
|
|
703
|
+
const keys = [{ name: "key-1" }, { name: "key-2" }, { name: "key-3" }];
|
|
706
704
|
mockKeyListRequest("bound-id", keys);
|
|
707
705
|
|
|
708
706
|
await runWrangler("kv:key list --binding someBinding");
|
|
@@ -710,19 +708,13 @@ describe("wrangler", () => {
|
|
|
710
708
|
expect(std.out).toMatchInlineSnapshot(`
|
|
711
709
|
"[
|
|
712
710
|
{
|
|
713
|
-
\\"name\\": \\"key-1\\"
|
|
714
|
-
\\"expiration\\": 123456789,
|
|
715
|
-
\\"metadata\\": {}
|
|
711
|
+
\\"name\\": \\"key-1\\"
|
|
716
712
|
},
|
|
717
713
|
{
|
|
718
|
-
\\"name\\": \\"key-2\\"
|
|
719
|
-
\\"expiration\\": 123456789,
|
|
720
|
-
\\"metadata\\": {}
|
|
714
|
+
\\"name\\": \\"key-2\\"
|
|
721
715
|
},
|
|
722
716
|
{
|
|
723
|
-
\\"name\\": \\"key-3\\"
|
|
724
|
-
\\"expiration\\": 123456789,
|
|
725
|
-
\\"metadata\\": {}
|
|
717
|
+
\\"name\\": \\"key-3\\"
|
|
726
718
|
}
|
|
727
719
|
]"
|
|
728
720
|
`);
|
|
@@ -730,26 +722,20 @@ describe("wrangler", () => {
|
|
|
730
722
|
|
|
731
723
|
it("should list the keys of a preview namespace specified by binding", async () => {
|
|
732
724
|
writeWranglerConfig();
|
|
733
|
-
const keys = ["key-1", "key-2", "key-3"];
|
|
725
|
+
const keys = [{ name: "key-1" }, { name: "key-2" }, { name: "key-3" }];
|
|
734
726
|
mockKeyListRequest("preview-bound-id", keys);
|
|
735
727
|
await runWrangler("kv:key list --binding someBinding --preview");
|
|
736
728
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
737
729
|
expect(std.out).toMatchInlineSnapshot(`
|
|
738
730
|
"[
|
|
739
731
|
{
|
|
740
|
-
\\"name\\": \\"key-1\\"
|
|
741
|
-
\\"expiration\\": 123456789,
|
|
742
|
-
\\"metadata\\": {}
|
|
732
|
+
\\"name\\": \\"key-1\\"
|
|
743
733
|
},
|
|
744
734
|
{
|
|
745
|
-
\\"name\\": \\"key-2\\"
|
|
746
|
-
\\"expiration\\": 123456789,
|
|
747
|
-
\\"metadata\\": {}
|
|
735
|
+
\\"name\\": \\"key-2\\"
|
|
748
736
|
},
|
|
749
737
|
{
|
|
750
|
-
\\"name\\": \\"key-3\\"
|
|
751
|
-
\\"expiration\\": 123456789,
|
|
752
|
-
\\"metadata\\": {}
|
|
738
|
+
\\"name\\": \\"key-3\\"
|
|
753
739
|
}
|
|
754
740
|
]"
|
|
755
741
|
`);
|
|
@@ -757,7 +743,7 @@ describe("wrangler", () => {
|
|
|
757
743
|
|
|
758
744
|
it("should list the keys of a namespace specified by binding, in a given environment", async () => {
|
|
759
745
|
writeWranglerConfig();
|
|
760
|
-
const keys = ["key-1", "key-2", "key-3"];
|
|
746
|
+
const keys = [{ name: "key-1" }, { name: "key-2" }, { name: "key-3" }];
|
|
761
747
|
mockKeyListRequest("env-bound-id", keys);
|
|
762
748
|
await runWrangler(
|
|
763
749
|
"kv:key list --binding someBinding --env some-environment"
|
|
@@ -766,19 +752,13 @@ describe("wrangler", () => {
|
|
|
766
752
|
expect(std.out).toMatchInlineSnapshot(`
|
|
767
753
|
"[
|
|
768
754
|
{
|
|
769
|
-
\\"name\\": \\"key-1\\"
|
|
770
|
-
\\"expiration\\": 123456789,
|
|
771
|
-
\\"metadata\\": {}
|
|
755
|
+
\\"name\\": \\"key-1\\"
|
|
772
756
|
},
|
|
773
757
|
{
|
|
774
|
-
\\"name\\": \\"key-2\\"
|
|
775
|
-
\\"expiration\\": 123456789,
|
|
776
|
-
\\"metadata\\": {}
|
|
758
|
+
\\"name\\": \\"key-2\\"
|
|
777
759
|
},
|
|
778
760
|
{
|
|
779
|
-
\\"name\\": \\"key-3\\"
|
|
780
|
-
\\"expiration\\": 123456789,
|
|
781
|
-
\\"metadata\\": {}
|
|
761
|
+
\\"name\\": \\"key-3\\"
|
|
782
762
|
}
|
|
783
763
|
]"
|
|
784
764
|
`);
|
|
@@ -786,7 +766,7 @@ describe("wrangler", () => {
|
|
|
786
766
|
|
|
787
767
|
it("should list the keys of a preview namespace specified by binding, in a given environment", async () => {
|
|
788
768
|
writeWranglerConfig();
|
|
789
|
-
const keys = ["key-1", "key-2", "key-3"];
|
|
769
|
+
const keys = [{ name: "key-1" }, { name: "key-2" }, { name: "key-3" }];
|
|
790
770
|
mockKeyListRequest("preview-env-bound-id", keys);
|
|
791
771
|
await runWrangler(
|
|
792
772
|
"kv:key list --binding someBinding --preview --env some-environment"
|
|
@@ -795,19 +775,13 @@ describe("wrangler", () => {
|
|
|
795
775
|
expect(std.out).toMatchInlineSnapshot(`
|
|
796
776
|
"[
|
|
797
777
|
{
|
|
798
|
-
\\"name\\": \\"key-1\\"
|
|
799
|
-
\\"expiration\\": 123456789,
|
|
800
|
-
\\"metadata\\": {}
|
|
778
|
+
\\"name\\": \\"key-1\\"
|
|
801
779
|
},
|
|
802
780
|
{
|
|
803
|
-
\\"name\\": \\"key-2\\"
|
|
804
|
-
\\"expiration\\": 123456789,
|
|
805
|
-
\\"metadata\\": {}
|
|
781
|
+
\\"name\\": \\"key-2\\"
|
|
806
782
|
},
|
|
807
783
|
{
|
|
808
|
-
\\"name\\": \\"key-3\\"
|
|
809
|
-
\\"expiration\\": 123456789,
|
|
810
|
-
\\"metadata\\": {}
|
|
784
|
+
\\"name\\": \\"key-3\\"
|
|
811
785
|
}
|
|
812
786
|
]"
|
|
813
787
|
`);
|
|
@@ -824,9 +798,9 @@ describe("wrangler", () => {
|
|
|
824
798
|
describe(`cursor - ${blankCursorValue}`, () => {
|
|
825
799
|
it("should make multiple requests for paginated results", async () => {
|
|
826
800
|
// Create a lot of mock keys, so that the fetch requests will be paginated
|
|
827
|
-
const keys:
|
|
801
|
+
const keys: NamespaceKeyInfo[] = [];
|
|
828
802
|
for (let i = 0; i < 550; i++) {
|
|
829
|
-
keys.push("key-" + i);
|
|
803
|
+
keys.push({ name: "key-" + i });
|
|
830
804
|
}
|
|
831
805
|
// Ask for the keys in pages of size 100.
|
|
832
806
|
const requests = mockKeyListRequest(
|
|
@@ -839,7 +813,7 @@ describe("wrangler", () => {
|
|
|
839
813
|
"kv:key list --namespace-id some-namespace-id --limit 100"
|
|
840
814
|
);
|
|
841
815
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
842
|
-
expect(JSON.parse(std.out)
|
|
816
|
+
expect(JSON.parse(std.out)).toEqual(keys);
|
|
843
817
|
expect(requests.count).toEqual(6);
|
|
844
818
|
});
|
|
845
819
|
});
|
|
@@ -855,8 +829,7 @@ describe("wrangler", () => {
|
|
|
855
829
|
expect(std.err).toMatchInlineSnapshot(`
|
|
856
830
|
"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
|
|
857
831
|
|
|
858
|
-
[32m%s[0m
|
|
859
|
-
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
832
|
+
[32m%s[0m If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
860
833
|
`);
|
|
861
834
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
862
835
|
});
|
|
@@ -938,12 +911,12 @@ describe("wrangler", () => {
|
|
|
938
911
|
key The key value to get. [string] [required]
|
|
939
912
|
|
|
940
913
|
Flags:
|
|
941
|
-
-c, --config
|
|
942
|
-
-h, --help
|
|
943
|
-
-v, --version
|
|
914
|
+
-c, --config Path to .toml configuration file [string]
|
|
915
|
+
-h, --help Show help [boolean]
|
|
916
|
+
-v, --version Show version number [boolean]
|
|
917
|
+
--legacy-env Use legacy environments [boolean]
|
|
944
918
|
|
|
945
919
|
Options:
|
|
946
|
-
-l, --local Run on my machine [boolean] [default: false]
|
|
947
920
|
--binding The name of the namespace to get from [string]
|
|
948
921
|
--namespace-id The id of the namespace to get from [string]
|
|
949
922
|
--env Perform on a specific environment [string]
|
|
@@ -969,12 +942,12 @@ describe("wrangler", () => {
|
|
|
969
942
|
key The key value to get. [string] [required]
|
|
970
943
|
|
|
971
944
|
Flags:
|
|
972
|
-
-c, --config
|
|
973
|
-
-h, --help
|
|
974
|
-
-v, --version
|
|
945
|
+
-c, --config Path to .toml configuration file [string]
|
|
946
|
+
-h, --help Show help [boolean]
|
|
947
|
+
-v, --version Show version number [boolean]
|
|
948
|
+
--legacy-env Use legacy environments [boolean]
|
|
975
949
|
|
|
976
950
|
Options:
|
|
977
|
-
-l, --local Run on my machine [boolean] [default: false]
|
|
978
951
|
--binding The name of the namespace to get from [string]
|
|
979
952
|
--namespace-id The id of the namespace to get from [string]
|
|
980
953
|
--env Perform on a specific environment [string]
|
|
@@ -1001,12 +974,12 @@ describe("wrangler", () => {
|
|
|
1001
974
|
key The key value to get. [string] [required]
|
|
1002
975
|
|
|
1003
976
|
Flags:
|
|
1004
|
-
-c, --config
|
|
1005
|
-
-h, --help
|
|
1006
|
-
-v, --version
|
|
977
|
+
-c, --config Path to .toml configuration file [string]
|
|
978
|
+
-h, --help Show help [boolean]
|
|
979
|
+
-v, --version Show version number [boolean]
|
|
980
|
+
--legacy-env Use legacy environments [boolean]
|
|
1007
981
|
|
|
1008
982
|
Options:
|
|
1009
|
-
-l, --local Run on my machine [boolean] [default: false]
|
|
1010
983
|
--binding The name of the namespace to get from [string]
|
|
1011
984
|
--namespace-id The id of the namespace to get from [string]
|
|
1012
985
|
--env Perform on a specific environment [string]
|
|
@@ -1027,8 +1000,7 @@ describe("wrangler", () => {
|
|
|
1027
1000
|
expect(std.err).toMatchInlineSnapshot(`
|
|
1028
1001
|
"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
|
|
1029
1002
|
|
|
1030
|
-
[32m%s[0m
|
|
1031
|
-
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
1003
|
+
[32m%s[0m If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
1032
1004
|
`);
|
|
1033
1005
|
});
|
|
1034
1006
|
});
|
|
@@ -1090,8 +1062,7 @@ describe("wrangler", () => {
|
|
|
1090
1062
|
expect(std.err).toMatchInlineSnapshot(`
|
|
1091
1063
|
"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
|
|
1092
1064
|
|
|
1093
|
-
[32m%s[0m
|
|
1094
|
-
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
1065
|
+
[32m%s[0m If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
1095
1066
|
`);
|
|
1096
1067
|
});
|
|
1097
1068
|
|
|
@@ -1118,6 +1089,278 @@ describe("wrangler", () => {
|
|
|
1118
1089
|
});
|
|
1119
1090
|
});
|
|
1120
1091
|
});
|
|
1092
|
+
|
|
1093
|
+
describe("kv:bulk", () => {
|
|
1094
|
+
describe("put", () => {
|
|
1095
|
+
function mockPutRequest(
|
|
1096
|
+
expectedNamespaceId: string,
|
|
1097
|
+
expectedKeyValues: KeyValue[]
|
|
1098
|
+
) {
|
|
1099
|
+
const requests = { count: 0 };
|
|
1100
|
+
setMockResponse(
|
|
1101
|
+
"/accounts/:accountId/storage/kv/namespaces/:namespaceId/bulk",
|
|
1102
|
+
"PUT",
|
|
1103
|
+
([_url, accountId, namespaceId], { body }) => {
|
|
1104
|
+
requests.count++;
|
|
1105
|
+
expect(accountId).toEqual("some-account-id");
|
|
1106
|
+
expect(namespaceId).toEqual(expectedNamespaceId);
|
|
1107
|
+
expect(JSON.parse(body as string)).toEqual(
|
|
1108
|
+
expectedKeyValues.slice(
|
|
1109
|
+
(requests.count - 1) * 5000,
|
|
1110
|
+
requests.count * 5000
|
|
1111
|
+
)
|
|
1112
|
+
);
|
|
1113
|
+
return null;
|
|
1114
|
+
}
|
|
1115
|
+
);
|
|
1116
|
+
return requests;
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
it("should put the key-values parsed from a file", async () => {
|
|
1120
|
+
const keyValues: KeyValue[] = [
|
|
1121
|
+
{ key: "someKey1", value: "someValue1" },
|
|
1122
|
+
{ key: "ns:someKey2", value: "123", base64: true },
|
|
1123
|
+
{ key: "someKey3", value: "someValue3", expiration: 100 },
|
|
1124
|
+
{ key: "someKey4", value: "someValue4", expiration_ttl: 500 },
|
|
1125
|
+
];
|
|
1126
|
+
writeFileSync("./keys.json", JSON.stringify(keyValues));
|
|
1127
|
+
const requests = mockPutRequest("some-namespace-id", keyValues);
|
|
1128
|
+
await runWrangler(
|
|
1129
|
+
`kv:bulk put --namespace-id some-namespace-id keys.json`
|
|
1130
|
+
);
|
|
1131
|
+
expect(requests.count).toEqual(1);
|
|
1132
|
+
expect(std.out).toMatchInlineSnapshot(`"Success!"`);
|
|
1133
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1134
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1135
|
+
});
|
|
1136
|
+
|
|
1137
|
+
it("should put the key-values in batches of 5000 parsed from a file", async () => {
|
|
1138
|
+
const keyValues: KeyValue[] = new Array(12000).fill({
|
|
1139
|
+
key: "someKey1",
|
|
1140
|
+
value: "someValue1",
|
|
1141
|
+
});
|
|
1142
|
+
writeFileSync("./keys.json", JSON.stringify(keyValues));
|
|
1143
|
+
const requests = mockPutRequest("some-namespace-id", keyValues);
|
|
1144
|
+
await runWrangler(
|
|
1145
|
+
`kv:bulk put --namespace-id some-namespace-id keys.json`
|
|
1146
|
+
);
|
|
1147
|
+
expect(requests.count).toEqual(3);
|
|
1148
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1149
|
+
"Uploaded 0 of 12000.
|
|
1150
|
+
Uploaded 5000 of 12000.
|
|
1151
|
+
Uploaded 10000 of 12000.
|
|
1152
|
+
Uploaded 12000 of 12000.
|
|
1153
|
+
Success!"
|
|
1154
|
+
`);
|
|
1155
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1156
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1157
|
+
});
|
|
1158
|
+
|
|
1159
|
+
it("should error if the file is not a JSON array", async () => {
|
|
1160
|
+
const keyValues = { key: "someKey1", value: "someValue1" };
|
|
1161
|
+
writeFileSync("./keys.json", JSON.stringify(keyValues));
|
|
1162
|
+
await expect(
|
|
1163
|
+
runWrangler(`kv:bulk put --namespace-id some-namespace-id keys.json`)
|
|
1164
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
1165
|
+
"Unexpected JSON input from \\"keys.json\\".
|
|
1166
|
+
Expected an array of key-value objects but got type \\"object\\"."
|
|
1167
|
+
`);
|
|
1168
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
1169
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1170
|
+
});
|
|
1171
|
+
|
|
1172
|
+
it("should error if the array contains items that are not key-value objects", async () => {
|
|
1173
|
+
const keyValues = [
|
|
1174
|
+
123,
|
|
1175
|
+
"a string",
|
|
1176
|
+
{ key: "someKey" },
|
|
1177
|
+
{ value: "someValue" },
|
|
1178
|
+
{ key: "someKey1", value: "someValue1", invalid: true },
|
|
1179
|
+
];
|
|
1180
|
+
writeFileSync("./keys.json", JSON.stringify(keyValues));
|
|
1181
|
+
await expect(
|
|
1182
|
+
runWrangler(`kv:bulk put --namespace-id some-namespace-id keys.json`)
|
|
1183
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
1184
|
+
"Unexpected JSON input from \\"keys.json\\".
|
|
1185
|
+
Each item in the array should be an object that matches:
|
|
1186
|
+
|
|
1187
|
+
interface KeyValue {
|
|
1188
|
+
key: string;
|
|
1189
|
+
value: string;
|
|
1190
|
+
expiration?: number;
|
|
1191
|
+
expiration_ttl?: number;
|
|
1192
|
+
metadata?: object;
|
|
1193
|
+
base64?: boolean;
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
The item at index 0 is type: \\"number\\" - 123
|
|
1197
|
+
The item at index 1 is type: \\"string\\" - \\"a string\\"
|
|
1198
|
+
The item at index 2 is {\\"key\\":\\"someKey\\"}
|
|
1199
|
+
The item at index 3 is {\\"value\\":\\"someValue\\"}"
|
|
1200
|
+
`);
|
|
1201
|
+
|
|
1202
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
1203
|
+
expect(std.warn).toMatchInlineSnapshot(`
|
|
1204
|
+
"Unexpected key-value properties in \\"keys.json\\".
|
|
1205
|
+
The item at index 4 contains unexpected properties: [\\"invalid\\"]."
|
|
1206
|
+
`);
|
|
1207
|
+
});
|
|
1208
|
+
});
|
|
1209
|
+
|
|
1210
|
+
describe("delete", () => {
|
|
1211
|
+
function mockDeleteRequest(
|
|
1212
|
+
expectedNamespaceId: string,
|
|
1213
|
+
expectedKeys: string[]
|
|
1214
|
+
) {
|
|
1215
|
+
const requests = { count: 0 };
|
|
1216
|
+
setMockResponse(
|
|
1217
|
+
"/accounts/:accountId/storage/kv/namespaces/:namespaceId/bulk",
|
|
1218
|
+
"DELETE",
|
|
1219
|
+
([_url, accountId, namespaceId], { headers, body }) => {
|
|
1220
|
+
requests.count++;
|
|
1221
|
+
expect(accountId).toEqual("some-account-id");
|
|
1222
|
+
expect(namespaceId).toEqual(expectedNamespaceId);
|
|
1223
|
+
expect(new Headers(headers ?? []).get("Content-Type")).toEqual(
|
|
1224
|
+
"application/json"
|
|
1225
|
+
);
|
|
1226
|
+
expect(JSON.parse(body as string)).toEqual(
|
|
1227
|
+
expectedKeys.slice(
|
|
1228
|
+
(requests.count - 1) * 5000,
|
|
1229
|
+
requests.count * 5000
|
|
1230
|
+
)
|
|
1231
|
+
);
|
|
1232
|
+
return null;
|
|
1233
|
+
}
|
|
1234
|
+
);
|
|
1235
|
+
return requests;
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
it("should delete the keys parsed from a file", async () => {
|
|
1239
|
+
const keys = ["someKey1", "ns:someKey2"];
|
|
1240
|
+
writeFileSync("./keys.json", JSON.stringify(keys));
|
|
1241
|
+
mockConfirm({
|
|
1242
|
+
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
|
|
1243
|
+
result: true,
|
|
1244
|
+
});
|
|
1245
|
+
const requests = mockDeleteRequest("some-namespace-id", keys);
|
|
1246
|
+
await runWrangler(
|
|
1247
|
+
`kv:bulk delete --namespace-id some-namespace-id keys.json`
|
|
1248
|
+
);
|
|
1249
|
+
expect(requests.count).toEqual(1);
|
|
1250
|
+
expect(std.out).toMatchInlineSnapshot(`"Success!"`);
|
|
1251
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1252
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1253
|
+
});
|
|
1254
|
+
|
|
1255
|
+
it("should delete the keys in batches of 5000 parsed from a file", async () => {
|
|
1256
|
+
const keys = new Array(12000).fill("some-key");
|
|
1257
|
+
writeFileSync("./keys.json", JSON.stringify(keys));
|
|
1258
|
+
mockConfirm({
|
|
1259
|
+
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
|
|
1260
|
+
result: true,
|
|
1261
|
+
});
|
|
1262
|
+
const requests = mockDeleteRequest("some-namespace-id", keys);
|
|
1263
|
+
await runWrangler(
|
|
1264
|
+
`kv:bulk delete --namespace-id some-namespace-id keys.json`
|
|
1265
|
+
);
|
|
1266
|
+
expect(requests.count).toEqual(3);
|
|
1267
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1268
|
+
"Deleted 0 of 12000.
|
|
1269
|
+
Deleted 5000 of 12000.
|
|
1270
|
+
Deleted 10000 of 12000.
|
|
1271
|
+
Deleted 12000 of 12000.
|
|
1272
|
+
Success!"
|
|
1273
|
+
`);
|
|
1274
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1275
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1276
|
+
});
|
|
1277
|
+
|
|
1278
|
+
it("should not delete the keys if the user confirms no", async () => {
|
|
1279
|
+
const keys = ["someKey1", "ns:someKey2"];
|
|
1280
|
+
writeFileSync("./keys.json", JSON.stringify(keys));
|
|
1281
|
+
mockConfirm({
|
|
1282
|
+
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
|
|
1283
|
+
result: false,
|
|
1284
|
+
});
|
|
1285
|
+
await runWrangler(
|
|
1286
|
+
`kv:bulk delete --namespace-id some-namespace-id keys.json`
|
|
1287
|
+
);
|
|
1288
|
+
expect(std.out).toMatchInlineSnapshot(
|
|
1289
|
+
`"Not deleting keys read from \\"keys.json\\"."`
|
|
1290
|
+
);
|
|
1291
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1292
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1293
|
+
});
|
|
1294
|
+
|
|
1295
|
+
it("should delete the keys without asking if --force is provided", async () => {
|
|
1296
|
+
const keys = ["someKey1", "ns:someKey2"];
|
|
1297
|
+
writeFileSync("./keys.json", JSON.stringify(keys));
|
|
1298
|
+
const requests = mockDeleteRequest("some-namespace-id", keys);
|
|
1299
|
+
await runWrangler(
|
|
1300
|
+
`kv:bulk delete --namespace-id some-namespace-id keys.json --force`
|
|
1301
|
+
);
|
|
1302
|
+
expect(requests.count).toEqual(1);
|
|
1303
|
+
expect(std.out).toMatchInlineSnapshot(`"Success!"`);
|
|
1304
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1305
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1306
|
+
});
|
|
1307
|
+
|
|
1308
|
+
it("should delete the keys without asking if -f is provided", async () => {
|
|
1309
|
+
const keys = ["someKey1", "ns:someKey2"];
|
|
1310
|
+
writeFileSync("./keys.json", JSON.stringify(keys));
|
|
1311
|
+
const requests = mockDeleteRequest("some-namespace-id", keys);
|
|
1312
|
+
await runWrangler(
|
|
1313
|
+
`kv:bulk delete --namespace-id some-namespace-id keys.json -f`
|
|
1314
|
+
);
|
|
1315
|
+
expect(requests.count).toEqual(1);
|
|
1316
|
+
expect(std.out).toMatchInlineSnapshot(`"Success!"`);
|
|
1317
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1318
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1319
|
+
});
|
|
1320
|
+
|
|
1321
|
+
it("should error if the file is not a JSON array", async () => {
|
|
1322
|
+
const keys = 12354;
|
|
1323
|
+
writeFileSync("./keys.json", JSON.stringify(keys));
|
|
1324
|
+
mockConfirm({
|
|
1325
|
+
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
|
|
1326
|
+
result: true,
|
|
1327
|
+
});
|
|
1328
|
+
await expect(
|
|
1329
|
+
runWrangler(
|
|
1330
|
+
`kv:bulk delete --namespace-id some-namespace-id keys.json`
|
|
1331
|
+
)
|
|
1332
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
1333
|
+
"Unexpected JSON input from \\"keys.json\\".
|
|
1334
|
+
Expected an array of strings but got:
|
|
1335
|
+
12354"
|
|
1336
|
+
`);
|
|
1337
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
1338
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1339
|
+
});
|
|
1340
|
+
|
|
1341
|
+
it("should error if the file contains non-string items", async () => {
|
|
1342
|
+
const keys = ["good", 12354, { key: "someKey" }, null];
|
|
1343
|
+
writeFileSync("./keys.json", JSON.stringify(keys));
|
|
1344
|
+
mockConfirm({
|
|
1345
|
+
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
|
|
1346
|
+
result: true,
|
|
1347
|
+
});
|
|
1348
|
+
await expect(
|
|
1349
|
+
runWrangler(
|
|
1350
|
+
`kv:bulk delete --namespace-id some-namespace-id keys.json`
|
|
1351
|
+
)
|
|
1352
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
1353
|
+
"Unexpected JSON input from \\"keys.json\\".
|
|
1354
|
+
Expected an array of strings.
|
|
1355
|
+
The item at index 1 is type: \\"number\\" - 12354
|
|
1356
|
+
The item at index 2 is type: \\"object\\" - {\\"key\\":\\"someKey\\"}
|
|
1357
|
+
The item at index 3 is type: \\"object\\" - null"
|
|
1358
|
+
`);
|
|
1359
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
1360
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1361
|
+
});
|
|
1362
|
+
});
|
|
1363
|
+
});
|
|
1121
1364
|
});
|
|
1122
1365
|
|
|
1123
1366
|
function writeWranglerConfig() {
|