wrangler 0.0.0-e151223 → 0.0.0-e1b8ac4
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/Cloudflare_CA.pem +18 -0
- package/README.md +27 -14
- package/bin/wrangler.js +49 -5
- package/kv-asset-handler.js +1 -0
- package/miniflare-dist/index.mjs +4886 -0
- package/package.json +57 -28
- package/pages/functions/buildPlugin.ts +105 -0
- package/pages/functions/buildWorker.ts +93 -4
- package/pages/functions/filepath-routing.test.ts +223 -36
- package/pages/functions/filepath-routing.ts +78 -120
- package/pages/functions/routes.ts +13 -17
- package/pages/functions/template-plugin.ts +147 -0
- package/pages/functions/template-worker.ts +24 -17
- package/src/__tests__/config-cache.test.ts +36 -0
- package/src/__tests__/configuration.test.ts +3548 -0
- package/src/__tests__/dev.test.tsx +1049 -65
- package/src/__tests__/guess-worker-format.test.ts +85 -0
- package/src/__tests__/helpers/cmd-shim.d.ts +11 -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 +36 -0
- package/src/__tests__/helpers/mock-cfetch.ts +48 -10
- package/src/__tests__/helpers/mock-console.ts +39 -8
- package/src/__tests__/helpers/mock-dialogs.ts +99 -11
- 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/mock-process.ts +24 -0
- 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 +10 -0
- package/src/__tests__/helpers/run-wrangler.ts +5 -3
- package/src/__tests__/helpers/write-worker-source.ts +31 -0
- package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
- package/src/__tests__/https-options.test.ts +130 -0
- package/src/__tests__/index.test.ts +160 -309
- package/src/__tests__/init.test.ts +1992 -0
- package/src/__tests__/jest.setup.ts +79 -6
- package/src/__tests__/kv.test.ts +651 -280
- package/src/__tests__/logger.test.ts +141 -0
- package/src/__tests__/package-manager.test.ts +353 -0
- package/src/__tests__/pages.test.ts +754 -0
- package/src/__tests__/parse.test.ts +330 -0
- package/src/__tests__/publish.test.ts +5671 -959
- package/src/__tests__/r2.test.ts +233 -0
- package/src/__tests__/route.test.ts +45 -0
- package/src/__tests__/secret.test.ts +362 -91
- package/src/__tests__/tail.test.ts +690 -0
- package/src/__tests__/user.test.ts +132 -0
- package/src/__tests__/whoami.test.tsx +60 -7
- package/src/abort.d.ts +3 -0
- package/src/bundle.ts +204 -0
- package/src/cfetch/index.ts +28 -18
- package/src/cfetch/internal.ts +99 -29
- package/src/cli.ts +6 -2
- package/src/config/README.md +107 -0
- package/src/config/config.ts +243 -0
- package/src/config/diagnostics.ts +80 -0
- package/src/config/environment.ts +420 -0
- package/src/config/index.ts +225 -0
- package/src/config/validation-helpers.ts +584 -0
- package/src/config/validation.ts +1580 -0
- package/src/config-cache.ts +45 -0
- package/src/create-worker-preview.ts +185 -0
- package/src/create-worker-upload-form.ts +254 -0
- package/src/dev/dev-vars.ts +36 -0
- package/src/dev/dev.tsx +399 -0
- package/src/dev/local.tsx +321 -0
- package/src/dev/remote.tsx +242 -0
- package/src/dev/use-esbuild.ts +112 -0
- package/src/dialogs.tsx +64 -6
- package/src/durable.ts +102 -0
- package/src/entry.ts +322 -0
- package/src/environment-variables.ts +35 -0
- package/src/errors.ts +11 -0
- package/src/generate-auth-url.ts +33 -0
- package/src/generate-random-state.ts +16 -0
- package/src/https-options.ts +123 -0
- package/src/index.tsx +1835 -988
- package/src/inspect.ts +80 -14
- package/src/intl-polyfill.d.ts +139 -0
- package/src/{kv.tsx → kv.ts} +199 -67
- package/src/logger.ts +73 -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 +226 -31
- package/src/open-in-browser.ts +17 -0
- package/src/package-manager.ts +174 -0
- package/src/pages.tsx +1132 -84
- package/src/parse.ts +222 -0
- package/src/proxy.ts +176 -70
- package/src/publish.ts +624 -308
- package/src/r2.ts +50 -0
- package/src/selfsigned.d.ts +29 -0
- package/src/sites.tsx +185 -57
- package/src/tail/filters.ts +279 -0
- package/src/tail/index.ts +299 -0
- package/src/tail/printing.ts +67 -0
- package/src/update-check.ts +19 -0
- package/src/user.tsx +349 -166
- package/src/whoami.tsx +5 -3
- package/src/{api/worker.ts → worker.ts} +65 -39
- package/src/zones.ts +73 -0
- package/templates/gitignore +171 -0
- package/templates/new-worker-scheduled.js +17 -0
- package/templates/new-worker-scheduled.ts +32 -0
- package/templates/new-worker.js +15 -0
- package/templates/new-worker.ts +30 -0
- package/{static-asset-facade.js → templates/static-asset-facade.js} +3 -7
- package/templates/tsconfig.json +105 -0
- package/wrangler-dist/cli.js +76649 -75066
- package/src/__tests__/helpers/mock-user.ts +0 -27
- package/src/__tests__/logout.test.ts +0 -50
- package/src/api/form_data.ts +0 -134
- package/src/api/preview.ts +0 -128
- package/src/config.ts +0 -641
- package/src/dev.tsx +0 -834
- package/src/npm-installer.ts +0 -20
- package/src/tail.tsx +0 -73
- package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
- package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
- package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
- package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
- package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
- package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
- package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
- package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
- package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
- package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
- package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
- package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
- package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
- package/vendor/wrangler-mime/CHANGELOG.md +0 -289
- package/vendor/wrangler-mime/LICENSE +0 -21
- package/vendor/wrangler-mime/Mime.js +0 -97
- package/vendor/wrangler-mime/README.md +0 -187
- package/vendor/wrangler-mime/cli.js +0 -46
- package/vendor/wrangler-mime/index.js +0 -4
- package/vendor/wrangler-mime/lite.js +0 -4
- package/vendor/wrangler-mime/package.json +0 -52
- package/vendor/wrangler-mime/types/other.js +0 -1
- package/vendor/wrangler-mime/types/standard.js +0 -1
- package/wrangler-dist/cli.js.map +0 -7
package/src/__tests__/kv.test.ts
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
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,
|
|
5
|
-
setMockRawResponse,
|
|
6
6
|
unsetAllMocks,
|
|
7
|
+
unsetMockFetchKVGetValues,
|
|
8
|
+
setMockFetchKVGetValue,
|
|
7
9
|
} from "./helpers/mock-cfetch";
|
|
8
10
|
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
11
|
+
import { clearConfirmMocks, mockConfirm } from "./helpers/mock-dialogs";
|
|
9
12
|
import { mockKeyListRequest } from "./helpers/mock-kv";
|
|
13
|
+
import { mockProcess } from "./helpers/mock-process";
|
|
10
14
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
11
15
|
import { runWrangler } from "./helpers/run-wrangler";
|
|
12
|
-
import type { KVNamespaceInfo } from "../kv";
|
|
16
|
+
import type { KeyValue, KVNamespaceInfo, NamespaceKeyInfo } from "../kv";
|
|
13
17
|
|
|
14
18
|
describe("wrangler", () => {
|
|
15
19
|
mockAccountId();
|
|
16
20
|
mockApiToken();
|
|
17
21
|
runInTempDir();
|
|
18
22
|
const std = mockConsoleMethods();
|
|
23
|
+
const proc = mockProcess();
|
|
19
24
|
|
|
20
25
|
afterEach(() => {
|
|
21
26
|
unsetAllMocks();
|
|
27
|
+
clearConfirmMocks();
|
|
22
28
|
});
|
|
23
29
|
|
|
24
30
|
describe("kv:namespace", () => {
|
|
@@ -42,9 +48,9 @@ describe("wrangler", () => {
|
|
|
42
48
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
43
49
|
`"Not enough non-option arguments: got 0, need at least 1"`
|
|
44
50
|
);
|
|
45
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
46
|
-
|
|
47
|
-
|
|
51
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
52
|
+
"
|
|
53
|
+
wrangler kv:namespace create <namespace>
|
|
48
54
|
|
|
49
55
|
Create a new namespace
|
|
50
56
|
|
|
@@ -57,11 +63,13 @@ describe("wrangler", () => {
|
|
|
57
63
|
-v, --version Show version number [boolean]
|
|
58
64
|
|
|
59
65
|
Options:
|
|
60
|
-
-
|
|
61
|
-
--
|
|
62
|
-
|
|
66
|
+
-e, --env Perform on a specific environment [string]
|
|
67
|
+
--preview Interact with a preview namespace [boolean]"
|
|
68
|
+
`);
|
|
69
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
70
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot enough non-option arguments: got 0, need at least 1[0m
|
|
63
71
|
|
|
64
|
-
|
|
72
|
+
"
|
|
65
73
|
`);
|
|
66
74
|
});
|
|
67
75
|
|
|
@@ -69,11 +77,11 @@ describe("wrangler", () => {
|
|
|
69
77
|
await expect(
|
|
70
78
|
runWrangler("kv:namespace create abc def ghi")
|
|
71
79
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
72
|
-
`"
|
|
80
|
+
`"Unknown arguments: def, ghi"`
|
|
73
81
|
);
|
|
74
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
75
|
-
|
|
76
|
-
|
|
82
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
83
|
+
"
|
|
84
|
+
wrangler kv:namespace create <namespace>
|
|
77
85
|
|
|
78
86
|
Create a new namespace
|
|
79
87
|
|
|
@@ -86,11 +94,13 @@ describe("wrangler", () => {
|
|
|
86
94
|
-v, --version Show version number [boolean]
|
|
87
95
|
|
|
88
96
|
Options:
|
|
89
|
-
-
|
|
90
|
-
--
|
|
91
|
-
|
|
97
|
+
-e, --env Perform on a specific environment [string]
|
|
98
|
+
--preview Interact with a preview namespace [boolean]"
|
|
99
|
+
`);
|
|
100
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
101
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mUnknown arguments: def, ghi[0m
|
|
92
102
|
|
|
93
|
-
|
|
103
|
+
"
|
|
94
104
|
`);
|
|
95
105
|
});
|
|
96
106
|
|
|
@@ -101,9 +111,9 @@ describe("wrangler", () => {
|
|
|
101
111
|
`"The namespace binding name \\"abc-def\\" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number."`
|
|
102
112
|
);
|
|
103
113
|
|
|
104
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
105
|
-
|
|
106
|
-
|
|
114
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
115
|
+
"
|
|
116
|
+
wrangler kv:namespace create <namespace>
|
|
107
117
|
|
|
108
118
|
Create a new namespace
|
|
109
119
|
|
|
@@ -116,11 +126,13 @@ describe("wrangler", () => {
|
|
|
116
126
|
-v, --version Show version number [boolean]
|
|
117
127
|
|
|
118
128
|
Options:
|
|
119
|
-
-
|
|
120
|
-
--
|
|
121
|
-
|
|
129
|
+
-e, --env Perform on a specific environment [string]
|
|
130
|
+
--preview Interact with a preview namespace [boolean]"
|
|
131
|
+
`);
|
|
132
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
133
|
+
"[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
|
|
122
134
|
|
|
123
|
-
|
|
135
|
+
"
|
|
124
136
|
`);
|
|
125
137
|
});
|
|
126
138
|
|
|
@@ -147,11 +159,11 @@ describe("wrangler", () => {
|
|
|
147
159
|
});
|
|
148
160
|
|
|
149
161
|
it("should create a namespace using configured worker name", async () => {
|
|
150
|
-
writeFileSync("./wrangler.toml", 'name = "
|
|
151
|
-
mockCreateRequest("
|
|
162
|
+
writeFileSync("./wrangler.toml", 'name = "other-worker"', "utf-8");
|
|
163
|
+
mockCreateRequest("other-worker-UnitTestNamespace");
|
|
152
164
|
await runWrangler("kv:namespace create UnitTestNamespace");
|
|
153
165
|
expect(std.out).toMatchInlineSnapshot(`
|
|
154
|
-
"🌀 Creating namespace with title \\"
|
|
166
|
+
"🌀 Creating namespace with title \\"other-worker-UnitTestNamespace\\"
|
|
155
167
|
✨ Success!
|
|
156
168
|
Add the following to your configuration file in your kv_namespaces array:
|
|
157
169
|
{ binding = \\"UnitTestNamespace\\", id = \\"some-namespace-id\\" }"
|
|
@@ -270,24 +282,11 @@ describe("wrangler", () => {
|
|
|
270
282
|
A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."
|
|
271
283
|
`);
|
|
272
284
|
expect(std.err).toMatchInlineSnapshot(`
|
|
273
|
-
"
|
|
285
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot able to delete namespace.[0m
|
|
274
286
|
|
|
275
|
-
|
|
287
|
+
A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
|
|
276
288
|
|
|
277
|
-
|
|
278
|
-
-c, --config Path to .toml configuration file [string]
|
|
279
|
-
-h, --help Show help [boolean]
|
|
280
|
-
-v, --version Show version number [boolean]
|
|
281
|
-
|
|
282
|
-
Options:
|
|
283
|
-
-l, --local Run on my machine [boolean] [default: false]
|
|
284
|
-
--binding The name of the namespace to delete [string]
|
|
285
|
-
--namespace-id The id of the namespace to delete [string]
|
|
286
|
-
--env Perform on a specific environment [string]
|
|
287
|
-
--preview Interact with a preview namespace [boolean]
|
|
288
|
-
|
|
289
|
-
Not able to delete namespace.
|
|
290
|
-
A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."
|
|
289
|
+
"
|
|
291
290
|
`);
|
|
292
291
|
});
|
|
293
292
|
|
|
@@ -318,10 +317,7 @@ describe("wrangler", () => {
|
|
|
318
317
|
describe("put", () => {
|
|
319
318
|
function mockKeyPutRequest(
|
|
320
319
|
expectedNamespaceId: string,
|
|
321
|
-
|
|
322
|
-
expectedValue: string,
|
|
323
|
-
expiration?: number,
|
|
324
|
-
expirationTtl?: number
|
|
320
|
+
expectedKV: KeyValue
|
|
325
321
|
) {
|
|
326
322
|
const requests = { count: 0 };
|
|
327
323
|
setMockResponse(
|
|
@@ -331,15 +327,19 @@ describe("wrangler", () => {
|
|
|
331
327
|
requests.count++;
|
|
332
328
|
expect(accountId).toEqual("some-account-id");
|
|
333
329
|
expect(namespaceId).toEqual(expectedNamespaceId);
|
|
334
|
-
expect(key).toEqual(
|
|
335
|
-
expect(body).toEqual(
|
|
336
|
-
if (expiration !== undefined) {
|
|
337
|
-
expect(query.get("expiration")).toEqual(
|
|
330
|
+
expect(key).toEqual(expectedKV.key);
|
|
331
|
+
expect(body).toEqual(expectedKV.value);
|
|
332
|
+
if (expectedKV.expiration !== undefined) {
|
|
333
|
+
expect(query.get("expiration")).toEqual(
|
|
334
|
+
`${expectedKV.expiration}`
|
|
335
|
+
);
|
|
338
336
|
} else {
|
|
339
337
|
expect(query.has("expiration")).toBe(false);
|
|
340
338
|
}
|
|
341
|
-
if (
|
|
342
|
-
expect(query.get("expiration_ttl")).toEqual(
|
|
339
|
+
if (expectedKV.expiration_ttl) {
|
|
340
|
+
expect(query.get("expiration_ttl")).toEqual(
|
|
341
|
+
`${expectedKV.expiration_ttl}`
|
|
342
|
+
);
|
|
343
343
|
} else {
|
|
344
344
|
expect(query.has("expiration_ttl")).toBe(false);
|
|
345
345
|
}
|
|
@@ -350,11 +350,10 @@ describe("wrangler", () => {
|
|
|
350
350
|
}
|
|
351
351
|
|
|
352
352
|
it("should put a key in a given namespace specified by namespace-id", async () => {
|
|
353
|
-
const requests = mockKeyPutRequest(
|
|
354
|
-
"
|
|
355
|
-
"my-
|
|
356
|
-
|
|
357
|
-
);
|
|
353
|
+
const requests = mockKeyPutRequest("some-namespace-id", {
|
|
354
|
+
key: "my-key",
|
|
355
|
+
value: "my-value",
|
|
356
|
+
});
|
|
358
357
|
|
|
359
358
|
await runWrangler(
|
|
360
359
|
"kv:key put my-key my-value --namespace-id some-namespace-id"
|
|
@@ -362,20 +361,38 @@ describe("wrangler", () => {
|
|
|
362
361
|
|
|
363
362
|
expect(requests.count).toEqual(1);
|
|
364
363
|
expect(std.out).toMatchInlineSnapshot(
|
|
365
|
-
`"
|
|
364
|
+
`"Writing the value \\"my-value\\" to key \\"my-key\\" on namespace some-namespace-id."`
|
|
365
|
+
);
|
|
366
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
367
|
+
});
|
|
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."`
|
|
366
380
|
);
|
|
367
381
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
368
382
|
});
|
|
369
383
|
|
|
370
384
|
it("should put a key in a given namespace specified by binding", async () => {
|
|
371
385
|
writeWranglerConfig();
|
|
372
|
-
const requests = mockKeyPutRequest("bound-id",
|
|
386
|
+
const requests = mockKeyPutRequest("bound-id", {
|
|
387
|
+
key: "my-key",
|
|
388
|
+
value: "my-value",
|
|
389
|
+
});
|
|
373
390
|
await runWrangler(
|
|
374
391
|
"kv:key put my-key my-value --binding someBinding --preview false"
|
|
375
392
|
);
|
|
376
393
|
|
|
377
394
|
expect(std.out).toMatchInlineSnapshot(
|
|
378
|
-
`"
|
|
395
|
+
`"Writing the value \\"my-value\\" to key \\"my-key\\" on namespace bound-id."`
|
|
379
396
|
);
|
|
380
397
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
381
398
|
expect(requests.count).toEqual(1);
|
|
@@ -383,70 +400,87 @@ describe("wrangler", () => {
|
|
|
383
400
|
|
|
384
401
|
it("should put a key in a given preview namespace specified by binding", async () => {
|
|
385
402
|
writeWranglerConfig();
|
|
386
|
-
const requests = mockKeyPutRequest(
|
|
387
|
-
"
|
|
388
|
-
"my-
|
|
389
|
-
|
|
390
|
-
);
|
|
403
|
+
const requests = mockKeyPutRequest("preview-bound-id", {
|
|
404
|
+
key: "my-key",
|
|
405
|
+
value: "my-value",
|
|
406
|
+
});
|
|
391
407
|
|
|
392
408
|
await runWrangler(
|
|
393
409
|
"kv:key put my-key my-value --binding someBinding --preview"
|
|
394
410
|
);
|
|
395
411
|
|
|
396
412
|
expect(std.out).toMatchInlineSnapshot(
|
|
397
|
-
`"
|
|
413
|
+
`"Writing the value \\"my-value\\" to key \\"my-key\\" on namespace preview-bound-id."`
|
|
398
414
|
);
|
|
399
415
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
400
416
|
expect(requests.count).toEqual(1);
|
|
401
417
|
});
|
|
402
418
|
|
|
403
419
|
it("should add expiration and ttl properties when putting a key", async () => {
|
|
404
|
-
const requests = mockKeyPutRequest(
|
|
405
|
-
"
|
|
406
|
-
"my-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
);
|
|
420
|
+
const requests = mockKeyPutRequest("some-namespace-id", {
|
|
421
|
+
key: "my-key",
|
|
422
|
+
value: "my-value",
|
|
423
|
+
expiration: 10,
|
|
424
|
+
expiration_ttl: 20,
|
|
425
|
+
});
|
|
411
426
|
await runWrangler(
|
|
412
427
|
"kv:key put my-key my-value --namespace-id some-namespace-id --expiration 10 --ttl 20"
|
|
413
428
|
);
|
|
414
429
|
expect(requests.count).toEqual(1);
|
|
415
430
|
expect(std.out).toMatchInlineSnapshot(
|
|
416
|
-
`"
|
|
431
|
+
`"Writing the value \\"my-value\\" to key \\"my-key\\" on namespace some-namespace-id."`
|
|
417
432
|
);
|
|
418
433
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
419
434
|
});
|
|
420
435
|
|
|
421
436
|
it("should put a key to the specified environment in a given namespace", async () => {
|
|
422
437
|
writeWranglerConfig();
|
|
423
|
-
const requests = mockKeyPutRequest(
|
|
424
|
-
"
|
|
425
|
-
"my-
|
|
426
|
-
|
|
427
|
-
);
|
|
438
|
+
const requests = mockKeyPutRequest("env-bound-id", {
|
|
439
|
+
key: "my-key",
|
|
440
|
+
value: "my-value",
|
|
441
|
+
});
|
|
428
442
|
await runWrangler(
|
|
429
443
|
"kv:key put my-key my-value --binding someBinding --env some-environment --preview false"
|
|
430
444
|
);
|
|
431
445
|
expect(std.out).toMatchInlineSnapshot(
|
|
432
|
-
`"
|
|
446
|
+
`"Writing the value \\"my-value\\" to key \\"my-key\\" on namespace env-bound-id."`
|
|
433
447
|
);
|
|
434
448
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
435
449
|
expect(requests.count).toEqual(1);
|
|
436
450
|
});
|
|
437
451
|
|
|
438
452
|
it("should put a key with a value loaded from a given path", async () => {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
"my-key",
|
|
443
|
-
|
|
444
|
-
);
|
|
453
|
+
const buf = Buffer.from("file-contents", "utf-8");
|
|
454
|
+
writeFileSync("foo.txt", buf);
|
|
455
|
+
const requests = mockKeyPutRequest("some-namespace-id", {
|
|
456
|
+
key: "my-key",
|
|
457
|
+
value: buf,
|
|
458
|
+
});
|
|
445
459
|
await runWrangler(
|
|
446
460
|
"kv:key put my-key --namespace-id some-namespace-id --path foo.txt"
|
|
447
461
|
);
|
|
448
462
|
expect(std.out).toMatchInlineSnapshot(
|
|
449
|
-
`"
|
|
463
|
+
`"Writing the contents of foo.txt to the key \\"my-key\\" on namespace some-namespace-id."`
|
|
464
|
+
);
|
|
465
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
466
|
+
expect(requests.count).toEqual(1);
|
|
467
|
+
});
|
|
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."`
|
|
450
484
|
);
|
|
451
485
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
452
486
|
expect(requests.count).toEqual(1);
|
|
@@ -459,15 +493,15 @@ describe("wrangler", () => {
|
|
|
459
493
|
`"Not enough non-option arguments: got 0, need at least 1"`
|
|
460
494
|
);
|
|
461
495
|
|
|
462
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
463
|
-
|
|
464
|
-
|
|
496
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
497
|
+
"
|
|
498
|
+
wrangler kv:key put <key> [value]
|
|
465
499
|
|
|
466
500
|
Writes a single key/value pair to the given namespace.
|
|
467
501
|
|
|
468
502
|
Positionals:
|
|
469
|
-
key The key to write to
|
|
470
|
-
value The value to write
|
|
503
|
+
key The key to write to [string] [required]
|
|
504
|
+
value The value to write [string]
|
|
471
505
|
|
|
472
506
|
Flags:
|
|
473
507
|
-c, --config Path to .toml configuration file [string]
|
|
@@ -475,16 +509,18 @@ describe("wrangler", () => {
|
|
|
475
509
|
-v, --version Show version number [boolean]
|
|
476
510
|
|
|
477
511
|
Options:
|
|
478
|
-
|
|
479
|
-
--
|
|
480
|
-
|
|
481
|
-
--env Perform on a specific environment [string]
|
|
512
|
+
--binding The binding of the namespace to write to [string]
|
|
513
|
+
--namespace-id The id of the namespace to write to [string]
|
|
514
|
+
-e, --env Perform on a specific environment [string]
|
|
482
515
|
--preview Interact with a preview namespace [boolean]
|
|
483
|
-
--ttl Time for which the entries should be visible
|
|
516
|
+
--ttl Time for which the entries should be visible [number]
|
|
484
517
|
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
485
|
-
--path Read value from the file at a given path
|
|
518
|
+
--path Read value from the file at a given path [string]"
|
|
519
|
+
`);
|
|
520
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
521
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot enough non-option arguments: got 0, need at least 1[0m
|
|
486
522
|
|
|
487
|
-
|
|
523
|
+
"
|
|
488
524
|
`);
|
|
489
525
|
});
|
|
490
526
|
|
|
@@ -495,15 +531,15 @@ describe("wrangler", () => {
|
|
|
495
531
|
`"Exactly one of the arguments binding and namespace-id is required"`
|
|
496
532
|
);
|
|
497
533
|
|
|
498
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
499
|
-
|
|
500
|
-
|
|
534
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
535
|
+
"
|
|
536
|
+
wrangler kv:key put <key> [value]
|
|
501
537
|
|
|
502
538
|
Writes a single key/value pair to the given namespace.
|
|
503
539
|
|
|
504
540
|
Positionals:
|
|
505
|
-
key The key to write to
|
|
506
|
-
value The value to write
|
|
541
|
+
key The key to write to [string] [required]
|
|
542
|
+
value The value to write [string]
|
|
507
543
|
|
|
508
544
|
Flags:
|
|
509
545
|
-c, --config Path to .toml configuration file [string]
|
|
@@ -511,16 +547,18 @@ describe("wrangler", () => {
|
|
|
511
547
|
-v, --version Show version number [boolean]
|
|
512
548
|
|
|
513
549
|
Options:
|
|
514
|
-
|
|
515
|
-
--
|
|
516
|
-
|
|
517
|
-
--env Perform on a specific environment [string]
|
|
550
|
+
--binding The binding of the namespace to write to [string]
|
|
551
|
+
--namespace-id The id of the namespace to write to [string]
|
|
552
|
+
-e, --env Perform on a specific environment [string]
|
|
518
553
|
--preview Interact with a preview namespace [boolean]
|
|
519
|
-
--ttl Time for which the entries should be visible
|
|
554
|
+
--ttl Time for which the entries should be visible [number]
|
|
520
555
|
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
521
|
-
--path Read value from the file at a given path
|
|
556
|
+
--path Read value from the file at a given path [string]"
|
|
557
|
+
`);
|
|
558
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
559
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mExactly one of the arguments binding and namespace-id is required[0m
|
|
522
560
|
|
|
523
|
-
|
|
561
|
+
"
|
|
524
562
|
`);
|
|
525
563
|
});
|
|
526
564
|
|
|
@@ -531,15 +569,15 @@ describe("wrangler", () => {
|
|
|
531
569
|
`"Arguments binding and namespace-id are mutually exclusive"`
|
|
532
570
|
);
|
|
533
571
|
|
|
534
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
535
|
-
|
|
536
|
-
|
|
572
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
573
|
+
"
|
|
574
|
+
wrangler kv:key put <key> [value]
|
|
537
575
|
|
|
538
576
|
Writes a single key/value pair to the given namespace.
|
|
539
577
|
|
|
540
578
|
Positionals:
|
|
541
|
-
key The key to write to
|
|
542
|
-
value The value to write
|
|
579
|
+
key The key to write to [string] [required]
|
|
580
|
+
value The value to write [string]
|
|
543
581
|
|
|
544
582
|
Flags:
|
|
545
583
|
-c, --config Path to .toml configuration file [string]
|
|
@@ -547,16 +585,18 @@ describe("wrangler", () => {
|
|
|
547
585
|
-v, --version Show version number [boolean]
|
|
548
586
|
|
|
549
587
|
Options:
|
|
550
|
-
|
|
551
|
-
--
|
|
552
|
-
|
|
553
|
-
--env Perform on a specific environment [string]
|
|
588
|
+
--binding The binding of the namespace to write to [string]
|
|
589
|
+
--namespace-id The id of the namespace to write to [string]
|
|
590
|
+
-e, --env Perform on a specific environment [string]
|
|
554
591
|
--preview Interact with a preview namespace [boolean]
|
|
555
|
-
--ttl Time for which the entries should be visible
|
|
592
|
+
--ttl Time for which the entries should be visible [number]
|
|
556
593
|
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
557
|
-
--path Read value from the file at a given path
|
|
594
|
+
--path Read value from the file at a given path [string]"
|
|
595
|
+
`);
|
|
596
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
597
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mArguments binding and namespace-id are mutually exclusive[0m
|
|
558
598
|
|
|
559
|
-
|
|
599
|
+
"
|
|
560
600
|
`);
|
|
561
601
|
});
|
|
562
602
|
|
|
@@ -567,15 +607,15 @@ describe("wrangler", () => {
|
|
|
567
607
|
`"Exactly one of the arguments value and path is required"`
|
|
568
608
|
);
|
|
569
609
|
|
|
570
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
571
|
-
|
|
572
|
-
|
|
610
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
611
|
+
"
|
|
612
|
+
wrangler kv:key put <key> [value]
|
|
573
613
|
|
|
574
614
|
Writes a single key/value pair to the given namespace.
|
|
575
615
|
|
|
576
616
|
Positionals:
|
|
577
|
-
key The key to write to
|
|
578
|
-
value The value to write
|
|
617
|
+
key The key to write to [string] [required]
|
|
618
|
+
value The value to write [string]
|
|
579
619
|
|
|
580
620
|
Flags:
|
|
581
621
|
-c, --config Path to .toml configuration file [string]
|
|
@@ -583,16 +623,18 @@ describe("wrangler", () => {
|
|
|
583
623
|
-v, --version Show version number [boolean]
|
|
584
624
|
|
|
585
625
|
Options:
|
|
586
|
-
|
|
587
|
-
--
|
|
588
|
-
|
|
589
|
-
--env Perform on a specific environment [string]
|
|
626
|
+
--binding The binding of the namespace to write to [string]
|
|
627
|
+
--namespace-id The id of the namespace to write to [string]
|
|
628
|
+
-e, --env Perform on a specific environment [string]
|
|
590
629
|
--preview Interact with a preview namespace [boolean]
|
|
591
|
-
--ttl Time for which the entries should be visible
|
|
630
|
+
--ttl Time for which the entries should be visible [number]
|
|
592
631
|
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
593
|
-
--path Read value from the file at a given path
|
|
632
|
+
--path Read value from the file at a given path [string]"
|
|
633
|
+
`);
|
|
634
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
635
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mExactly one of the arguments value and path is required[0m
|
|
594
636
|
|
|
595
|
-
|
|
637
|
+
"
|
|
596
638
|
`);
|
|
597
639
|
});
|
|
598
640
|
|
|
@@ -603,15 +645,15 @@ describe("wrangler", () => {
|
|
|
603
645
|
`"Arguments value and path are mutually exclusive"`
|
|
604
646
|
);
|
|
605
647
|
|
|
606
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
607
|
-
|
|
608
|
-
|
|
648
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
649
|
+
"
|
|
650
|
+
wrangler kv:key put <key> [value]
|
|
609
651
|
|
|
610
652
|
Writes a single key/value pair to the given namespace.
|
|
611
653
|
|
|
612
654
|
Positionals:
|
|
613
|
-
key The key to write to
|
|
614
|
-
value The value to write
|
|
655
|
+
key The key to write to [string] [required]
|
|
656
|
+
value The value to write [string]
|
|
615
657
|
|
|
616
658
|
Flags:
|
|
617
659
|
-c, --config Path to .toml configuration file [string]
|
|
@@ -619,16 +661,18 @@ describe("wrangler", () => {
|
|
|
619
661
|
-v, --version Show version number [boolean]
|
|
620
662
|
|
|
621
663
|
Options:
|
|
622
|
-
|
|
623
|
-
--
|
|
624
|
-
|
|
625
|
-
--env Perform on a specific environment [string]
|
|
664
|
+
--binding The binding of the namespace to write to [string]
|
|
665
|
+
--namespace-id The id of the namespace to write to [string]
|
|
666
|
+
-e, --env Perform on a specific environment [string]
|
|
626
667
|
--preview Interact with a preview namespace [boolean]
|
|
627
|
-
--ttl Time for which the entries should be visible
|
|
668
|
+
--ttl Time for which the entries should be visible [number]
|
|
628
669
|
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
629
|
-
--path Read value from the file at a given path
|
|
670
|
+
--path Read value from the file at a given path [string]"
|
|
671
|
+
`);
|
|
672
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
673
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mArguments value and path are mutually exclusive[0m
|
|
630
674
|
|
|
631
|
-
|
|
675
|
+
"
|
|
632
676
|
`);
|
|
633
677
|
});
|
|
634
678
|
|
|
@@ -640,33 +684,36 @@ describe("wrangler", () => {
|
|
|
640
684
|
`"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
|
|
641
685
|
);
|
|
642
686
|
|
|
643
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
687
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
688
|
+
"
|
|
689
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
690
|
+
`);
|
|
644
691
|
expect(std.err).toMatchInlineSnapshot(`
|
|
645
|
-
"
|
|
692
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".[0m
|
|
646
693
|
|
|
647
|
-
|
|
648
|
-
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
694
|
+
"
|
|
649
695
|
`);
|
|
650
696
|
});
|
|
651
697
|
|
|
652
698
|
it("should error if a given binding has both preview and non-preview and --preview is not specified", async () => {
|
|
653
699
|
writeWranglerConfig();
|
|
654
|
-
const requests = mockKeyPutRequest(
|
|
655
|
-
"
|
|
656
|
-
"my-
|
|
657
|
-
|
|
658
|
-
);
|
|
700
|
+
const requests = mockKeyPutRequest("preview-bound-id", {
|
|
701
|
+
key: "my-key",
|
|
702
|
+
value: "my-value",
|
|
703
|
+
});
|
|
659
704
|
await expect(
|
|
660
705
|
runWrangler("kv:key put my-key my-value --binding someBinding")
|
|
661
706
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
662
707
|
`"someBinding has both a namespace ID and a preview ID. Specify \\"--preview\\" or \\"--preview false\\" to avoid writing data to the wrong namespace."`
|
|
663
708
|
);
|
|
664
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
709
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
710
|
+
"
|
|
711
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
712
|
+
`);
|
|
665
713
|
expect(std.err).toMatchInlineSnapshot(`
|
|
666
|
-
"
|
|
714
|
+
"[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
715
|
|
|
668
|
-
|
|
669
|
-
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
716
|
+
"
|
|
670
717
|
`);
|
|
671
718
|
expect(requests.count).toEqual(0);
|
|
672
719
|
});
|
|
@@ -674,26 +721,26 @@ describe("wrangler", () => {
|
|
|
674
721
|
|
|
675
722
|
describe("list", () => {
|
|
676
723
|
it("should list the keys of a namespace specified by namespace-id", async () => {
|
|
677
|
-
const keys = [
|
|
724
|
+
const keys = [
|
|
725
|
+
{ name: "key-1" },
|
|
726
|
+
{ name: "key-2", expiration: 123456789 },
|
|
727
|
+
{ name: "key-3", expiration_ttl: 666 },
|
|
728
|
+
];
|
|
678
729
|
mockKeyListRequest("some-namespace-id", keys);
|
|
679
730
|
await runWrangler("kv:key list --namespace-id some-namespace-id");
|
|
680
731
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
681
732
|
expect(std.out).toMatchInlineSnapshot(`
|
|
682
733
|
"[
|
|
683
734
|
{
|
|
684
|
-
\\"name\\": \\"key-1\\"
|
|
685
|
-
\\"expiration\\": 123456789,
|
|
686
|
-
\\"metadata\\": {}
|
|
735
|
+
\\"name\\": \\"key-1\\"
|
|
687
736
|
},
|
|
688
737
|
{
|
|
689
738
|
\\"name\\": \\"key-2\\",
|
|
690
|
-
\\"expiration\\": 123456789
|
|
691
|
-
\\"metadata\\": {}
|
|
739
|
+
\\"expiration\\": 123456789
|
|
692
740
|
},
|
|
693
741
|
{
|
|
694
742
|
\\"name\\": \\"key-3\\",
|
|
695
|
-
\\"
|
|
696
|
-
\\"metadata\\": {}
|
|
743
|
+
\\"expiration_ttl\\": 666
|
|
697
744
|
}
|
|
698
745
|
]"
|
|
699
746
|
`);
|
|
@@ -701,7 +748,7 @@ describe("wrangler", () => {
|
|
|
701
748
|
|
|
702
749
|
it("should list the keys of a namespace specified by binding", async () => {
|
|
703
750
|
writeWranglerConfig();
|
|
704
|
-
const keys = ["key-1", "key-2", "key-3"];
|
|
751
|
+
const keys = [{ name: "key-1" }, { name: "key-2" }, { name: "key-3" }];
|
|
705
752
|
mockKeyListRequest("bound-id", keys);
|
|
706
753
|
|
|
707
754
|
await runWrangler("kv:key list --binding someBinding");
|
|
@@ -709,19 +756,13 @@ describe("wrangler", () => {
|
|
|
709
756
|
expect(std.out).toMatchInlineSnapshot(`
|
|
710
757
|
"[
|
|
711
758
|
{
|
|
712
|
-
\\"name\\": \\"key-1\\"
|
|
713
|
-
\\"expiration\\": 123456789,
|
|
714
|
-
\\"metadata\\": {}
|
|
759
|
+
\\"name\\": \\"key-1\\"
|
|
715
760
|
},
|
|
716
761
|
{
|
|
717
|
-
\\"name\\": \\"key-2\\"
|
|
718
|
-
\\"expiration\\": 123456789,
|
|
719
|
-
\\"metadata\\": {}
|
|
762
|
+
\\"name\\": \\"key-2\\"
|
|
720
763
|
},
|
|
721
764
|
{
|
|
722
|
-
\\"name\\": \\"key-3\\"
|
|
723
|
-
\\"expiration\\": 123456789,
|
|
724
|
-
\\"metadata\\": {}
|
|
765
|
+
\\"name\\": \\"key-3\\"
|
|
725
766
|
}
|
|
726
767
|
]"
|
|
727
768
|
`);
|
|
@@ -729,26 +770,20 @@ describe("wrangler", () => {
|
|
|
729
770
|
|
|
730
771
|
it("should list the keys of a preview namespace specified by binding", async () => {
|
|
731
772
|
writeWranglerConfig();
|
|
732
|
-
const keys = ["key-1", "key-2", "key-3"];
|
|
773
|
+
const keys = [{ name: "key-1" }, { name: "key-2" }, { name: "key-3" }];
|
|
733
774
|
mockKeyListRequest("preview-bound-id", keys);
|
|
734
775
|
await runWrangler("kv:key list --binding someBinding --preview");
|
|
735
776
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
736
777
|
expect(std.out).toMatchInlineSnapshot(`
|
|
737
778
|
"[
|
|
738
779
|
{
|
|
739
|
-
\\"name\\": \\"key-1\\"
|
|
740
|
-
\\"expiration\\": 123456789,
|
|
741
|
-
\\"metadata\\": {}
|
|
780
|
+
\\"name\\": \\"key-1\\"
|
|
742
781
|
},
|
|
743
782
|
{
|
|
744
|
-
\\"name\\": \\"key-2\\"
|
|
745
|
-
\\"expiration\\": 123456789,
|
|
746
|
-
\\"metadata\\": {}
|
|
783
|
+
\\"name\\": \\"key-2\\"
|
|
747
784
|
},
|
|
748
785
|
{
|
|
749
|
-
\\"name\\": \\"key-3\\"
|
|
750
|
-
\\"expiration\\": 123456789,
|
|
751
|
-
\\"metadata\\": {}
|
|
786
|
+
\\"name\\": \\"key-3\\"
|
|
752
787
|
}
|
|
753
788
|
]"
|
|
754
789
|
`);
|
|
@@ -756,7 +791,7 @@ describe("wrangler", () => {
|
|
|
756
791
|
|
|
757
792
|
it("should list the keys of a namespace specified by binding, in a given environment", async () => {
|
|
758
793
|
writeWranglerConfig();
|
|
759
|
-
const keys = ["key-1", "key-2", "key-3"];
|
|
794
|
+
const keys = [{ name: "key-1" }, { name: "key-2" }, { name: "key-3" }];
|
|
760
795
|
mockKeyListRequest("env-bound-id", keys);
|
|
761
796
|
await runWrangler(
|
|
762
797
|
"kv:key list --binding someBinding --env some-environment"
|
|
@@ -765,19 +800,13 @@ describe("wrangler", () => {
|
|
|
765
800
|
expect(std.out).toMatchInlineSnapshot(`
|
|
766
801
|
"[
|
|
767
802
|
{
|
|
768
|
-
\\"name\\": \\"key-1\\"
|
|
769
|
-
\\"expiration\\": 123456789,
|
|
770
|
-
\\"metadata\\": {}
|
|
803
|
+
\\"name\\": \\"key-1\\"
|
|
771
804
|
},
|
|
772
805
|
{
|
|
773
|
-
\\"name\\": \\"key-2\\"
|
|
774
|
-
\\"expiration\\": 123456789,
|
|
775
|
-
\\"metadata\\": {}
|
|
806
|
+
\\"name\\": \\"key-2\\"
|
|
776
807
|
},
|
|
777
808
|
{
|
|
778
|
-
\\"name\\": \\"key-3\\"
|
|
779
|
-
\\"expiration\\": 123456789,
|
|
780
|
-
\\"metadata\\": {}
|
|
809
|
+
\\"name\\": \\"key-3\\"
|
|
781
810
|
}
|
|
782
811
|
]"
|
|
783
812
|
`);
|
|
@@ -785,7 +814,7 @@ describe("wrangler", () => {
|
|
|
785
814
|
|
|
786
815
|
it("should list the keys of a preview namespace specified by binding, in a given environment", async () => {
|
|
787
816
|
writeWranglerConfig();
|
|
788
|
-
const keys = ["key-1", "key-2", "key-3"];
|
|
817
|
+
const keys = [{ name: "key-1" }, { name: "key-2" }, { name: "key-3" }];
|
|
789
818
|
mockKeyListRequest("preview-env-bound-id", keys);
|
|
790
819
|
await runWrangler(
|
|
791
820
|
"kv:key list --binding someBinding --preview --env some-environment"
|
|
@@ -794,19 +823,13 @@ describe("wrangler", () => {
|
|
|
794
823
|
expect(std.out).toMatchInlineSnapshot(`
|
|
795
824
|
"[
|
|
796
825
|
{
|
|
797
|
-
\\"name\\": \\"key-1\\"
|
|
798
|
-
\\"expiration\\": 123456789,
|
|
799
|
-
\\"metadata\\": {}
|
|
826
|
+
\\"name\\": \\"key-1\\"
|
|
800
827
|
},
|
|
801
828
|
{
|
|
802
|
-
\\"name\\": \\"key-2\\"
|
|
803
|
-
\\"expiration\\": 123456789,
|
|
804
|
-
\\"metadata\\": {}
|
|
829
|
+
\\"name\\": \\"key-2\\"
|
|
805
830
|
},
|
|
806
831
|
{
|
|
807
|
-
\\"name\\": \\"key-3\\"
|
|
808
|
-
\\"expiration\\": 123456789,
|
|
809
|
-
\\"metadata\\": {}
|
|
832
|
+
\\"name\\": \\"key-3\\"
|
|
810
833
|
}
|
|
811
834
|
]"
|
|
812
835
|
`);
|
|
@@ -823,9 +846,9 @@ describe("wrangler", () => {
|
|
|
823
846
|
describe(`cursor - ${blankCursorValue}`, () => {
|
|
824
847
|
it("should make multiple requests for paginated results", async () => {
|
|
825
848
|
// Create a lot of mock keys, so that the fetch requests will be paginated
|
|
826
|
-
const keys:
|
|
849
|
+
const keys: NamespaceKeyInfo[] = [];
|
|
827
850
|
for (let i = 0; i < 550; i++) {
|
|
828
|
-
keys.push("key-" + i);
|
|
851
|
+
keys.push({ name: "key-" + i });
|
|
829
852
|
}
|
|
830
853
|
// Ask for the keys in pages of size 100.
|
|
831
854
|
const requests = mockKeyListRequest(
|
|
@@ -834,11 +857,9 @@ describe("wrangler", () => {
|
|
|
834
857
|
100,
|
|
835
858
|
blankCursorValue
|
|
836
859
|
);
|
|
837
|
-
await runWrangler(
|
|
838
|
-
"kv:key list --namespace-id some-namespace-id --limit 100"
|
|
839
|
-
);
|
|
860
|
+
await runWrangler("kv:key list --namespace-id some-namespace-id");
|
|
840
861
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
841
|
-
expect(JSON.parse(std.out)
|
|
862
|
+
expect(JSON.parse(std.out)).toEqual(keys);
|
|
842
863
|
expect(requests.count).toEqual(6);
|
|
843
864
|
});
|
|
844
865
|
});
|
|
@@ -852,84 +873,105 @@ describe("wrangler", () => {
|
|
|
852
873
|
`"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
|
|
853
874
|
);
|
|
854
875
|
expect(std.err).toMatchInlineSnapshot(`
|
|
855
|
-
"
|
|
876
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".[0m
|
|
856
877
|
|
|
857
|
-
|
|
858
|
-
|
|
878
|
+
"
|
|
879
|
+
`);
|
|
880
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
881
|
+
"
|
|
882
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
859
883
|
`);
|
|
860
|
-
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
861
884
|
});
|
|
862
885
|
});
|
|
863
886
|
|
|
864
887
|
describe("get", () => {
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
expectedValue: string
|
|
869
|
-
) {
|
|
870
|
-
const requests = { count: 0 };
|
|
871
|
-
setMockRawResponse(
|
|
872
|
-
"/accounts/:accountId/storage/kv/namespaces/:namespaceId/values/:key",
|
|
873
|
-
([_url, accountId, namespaceId, key]) => {
|
|
874
|
-
requests.count++;
|
|
875
|
-
expect(accountId).toEqual("some-account-id");
|
|
876
|
-
expect(namespaceId).toEqual(expectedNamespaceId);
|
|
877
|
-
expect(key).toEqual(expectedKey);
|
|
878
|
-
return expectedValue;
|
|
879
|
-
}
|
|
880
|
-
);
|
|
881
|
-
return requests;
|
|
882
|
-
}
|
|
888
|
+
afterEach(() => {
|
|
889
|
+
unsetMockFetchKVGetValues();
|
|
890
|
+
});
|
|
883
891
|
|
|
884
892
|
it("should get a key in a given namespace specified by namespace-id", async () => {
|
|
885
|
-
|
|
893
|
+
setMockFetchKVGetValue(
|
|
894
|
+
"some-account-id",
|
|
886
895
|
"some-namespace-id",
|
|
887
896
|
"my-key",
|
|
888
897
|
"my-value"
|
|
889
898
|
);
|
|
890
899
|
await runWrangler("kv:key get my-key --namespace-id some-namespace-id");
|
|
891
|
-
expect(
|
|
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);
|
|
892
917
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
893
|
-
expect(requests.count).toEqual(1);
|
|
894
918
|
});
|
|
895
919
|
|
|
896
920
|
it("should get a key in a given namespace specified by binding", async () => {
|
|
897
921
|
writeWranglerConfig();
|
|
898
|
-
|
|
922
|
+
setMockFetchKVGetValue(
|
|
923
|
+
"some-account-id",
|
|
924
|
+
"bound-id",
|
|
925
|
+
"my-key",
|
|
926
|
+
"my-value"
|
|
927
|
+
);
|
|
899
928
|
await runWrangler(
|
|
900
929
|
"kv:key get my-key --binding someBinding --preview false"
|
|
901
930
|
);
|
|
902
|
-
expect(
|
|
931
|
+
expect(proc.write).toEqual(Buffer.from("my-value"));
|
|
903
932
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
904
|
-
expect(requests.count).toEqual(1);
|
|
905
933
|
});
|
|
906
934
|
|
|
907
935
|
it("should get a key in a given preview namespace specified by binding", async () => {
|
|
908
936
|
writeWranglerConfig();
|
|
909
|
-
|
|
937
|
+
setMockFetchKVGetValue(
|
|
938
|
+
"some-account-id",
|
|
910
939
|
"preview-bound-id",
|
|
911
940
|
"my-key",
|
|
912
941
|
"my-value"
|
|
913
942
|
);
|
|
914
943
|
await runWrangler("kv:key get my-key --binding someBinding --preview");
|
|
915
|
-
expect(
|
|
944
|
+
expect(proc.write).toEqual(Buffer.from("my-value"));
|
|
916
945
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
917
|
-
expect(requests.count).toEqual(1);
|
|
918
946
|
});
|
|
919
947
|
|
|
920
948
|
it("should get a key for the specified environment in a given namespace", async () => {
|
|
921
949
|
writeWranglerConfig();
|
|
922
|
-
|
|
950
|
+
setMockFetchKVGetValue(
|
|
951
|
+
"some-account-id",
|
|
923
952
|
"env-bound-id",
|
|
924
953
|
"my-key",
|
|
925
954
|
"my-value"
|
|
926
955
|
);
|
|
927
956
|
await runWrangler(
|
|
928
|
-
"kv:key get my-key
|
|
957
|
+
"kv:key get my-key --binding someBinding --env some-environment --preview false"
|
|
929
958
|
);
|
|
930
|
-
expect(
|
|
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"));
|
|
931
974
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
932
|
-
expect(requests.count).toEqual(1);
|
|
933
975
|
});
|
|
934
976
|
|
|
935
977
|
it("should error if no key is provided", async () => {
|
|
@@ -938,9 +980,9 @@ describe("wrangler", () => {
|
|
|
938
980
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
939
981
|
`"Not enough non-option arguments: got 0, need at least 1"`
|
|
940
982
|
);
|
|
941
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
942
|
-
|
|
943
|
-
|
|
983
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
984
|
+
"
|
|
985
|
+
wrangler kv:key get <key>
|
|
944
986
|
|
|
945
987
|
Reads a single value by key from the given namespace.
|
|
946
988
|
|
|
@@ -953,13 +995,15 @@ describe("wrangler", () => {
|
|
|
953
995
|
-v, --version Show version number [boolean]
|
|
954
996
|
|
|
955
997
|
Options:
|
|
956
|
-
-l, --local Run on my machine [boolean] [default: false]
|
|
957
998
|
--binding The name of the namespace to get from [string]
|
|
958
999
|
--namespace-id The id of the namespace to get from [string]
|
|
959
|
-
|
|
960
|
-
--preview Interact with a preview namespace [boolean] [default: false]
|
|
1000
|
+
-e, --env Perform on a specific environment [string]
|
|
1001
|
+
--preview Interact with a preview namespace [boolean] [default: false]"
|
|
1002
|
+
`);
|
|
1003
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
1004
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot enough non-option arguments: got 0, need at least 1[0m
|
|
961
1005
|
|
|
962
|
-
|
|
1006
|
+
"
|
|
963
1007
|
`);
|
|
964
1008
|
});
|
|
965
1009
|
|
|
@@ -969,9 +1013,9 @@ describe("wrangler", () => {
|
|
|
969
1013
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
970
1014
|
`"Exactly one of the arguments binding and namespace-id is required"`
|
|
971
1015
|
);
|
|
972
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
973
|
-
|
|
974
|
-
|
|
1016
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1017
|
+
"
|
|
1018
|
+
wrangler kv:key get <key>
|
|
975
1019
|
|
|
976
1020
|
Reads a single value by key from the given namespace.
|
|
977
1021
|
|
|
@@ -984,13 +1028,15 @@ describe("wrangler", () => {
|
|
|
984
1028
|
-v, --version Show version number [boolean]
|
|
985
1029
|
|
|
986
1030
|
Options:
|
|
987
|
-
-l, --local Run on my machine [boolean] [default: false]
|
|
988
1031
|
--binding The name of the namespace to get from [string]
|
|
989
1032
|
--namespace-id The id of the namespace to get from [string]
|
|
990
|
-
|
|
991
|
-
--preview Interact with a preview namespace [boolean] [default: false]
|
|
1033
|
+
-e, --env Perform on a specific environment [string]
|
|
1034
|
+
--preview Interact with a preview namespace [boolean] [default: false]"
|
|
1035
|
+
`);
|
|
1036
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
1037
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mExactly one of the arguments binding and namespace-id is required[0m
|
|
992
1038
|
|
|
993
|
-
|
|
1039
|
+
"
|
|
994
1040
|
`);
|
|
995
1041
|
});
|
|
996
1042
|
|
|
@@ -1001,9 +1047,9 @@ describe("wrangler", () => {
|
|
|
1001
1047
|
`"Arguments binding and namespace-id are mutually exclusive"`
|
|
1002
1048
|
);
|
|
1003
1049
|
|
|
1004
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
1005
|
-
|
|
1006
|
-
|
|
1050
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1051
|
+
"
|
|
1052
|
+
wrangler kv:key get <key>
|
|
1007
1053
|
|
|
1008
1054
|
Reads a single value by key from the given namespace.
|
|
1009
1055
|
|
|
@@ -1016,13 +1062,15 @@ describe("wrangler", () => {
|
|
|
1016
1062
|
-v, --version Show version number [boolean]
|
|
1017
1063
|
|
|
1018
1064
|
Options:
|
|
1019
|
-
-l, --local Run on my machine [boolean] [default: false]
|
|
1020
1065
|
--binding The name of the namespace to get from [string]
|
|
1021
1066
|
--namespace-id The id of the namespace to get from [string]
|
|
1022
|
-
|
|
1023
|
-
--preview Interact with a preview namespace [boolean] [default: false]
|
|
1067
|
+
-e, --env Perform on a specific environment [string]
|
|
1068
|
+
--preview Interact with a preview namespace [boolean] [default: false]"
|
|
1069
|
+
`);
|
|
1070
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
1071
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mArguments binding and namespace-id are mutually exclusive[0m
|
|
1024
1072
|
|
|
1025
|
-
|
|
1073
|
+
"
|
|
1026
1074
|
`);
|
|
1027
1075
|
});
|
|
1028
1076
|
|
|
@@ -1033,12 +1081,14 @@ describe("wrangler", () => {
|
|
|
1033
1081
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
1034
1082
|
`"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
|
|
1035
1083
|
);
|
|
1036
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
1084
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1085
|
+
"
|
|
1086
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
1087
|
+
`);
|
|
1037
1088
|
expect(std.err).toMatchInlineSnapshot(`
|
|
1038
|
-
"
|
|
1089
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".[0m
|
|
1039
1090
|
|
|
1040
|
-
|
|
1041
|
-
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
1091
|
+
"
|
|
1042
1092
|
`);
|
|
1043
1093
|
});
|
|
1044
1094
|
});
|
|
@@ -1071,6 +1121,16 @@ describe("wrangler", () => {
|
|
|
1071
1121
|
expect(requests.count).toEqual(1);
|
|
1072
1122
|
});
|
|
1073
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
|
+
|
|
1074
1134
|
it("should delete a key in a namespace specified by binding name", async () => {
|
|
1075
1135
|
writeWranglerConfig();
|
|
1076
1136
|
const requests = mockDeleteRequest("bound-id", "someKey");
|
|
@@ -1098,10 +1158,9 @@ describe("wrangler", () => {
|
|
|
1098
1158
|
);
|
|
1099
1159
|
|
|
1100
1160
|
expect(std.err).toMatchInlineSnapshot(`
|
|
1101
|
-
"
|
|
1161
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".[0m
|
|
1102
1162
|
|
|
1103
|
-
|
|
1104
|
-
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
1163
|
+
"
|
|
1105
1164
|
`);
|
|
1106
1165
|
});
|
|
1107
1166
|
|
|
@@ -1112,7 +1171,7 @@ describe("wrangler", () => {
|
|
|
1112
1171
|
`kv:key delete --binding someBinding --env some-environment --preview false someKey`
|
|
1113
1172
|
);
|
|
1114
1173
|
expect(std.out).toMatchInlineSnapshot(
|
|
1115
|
-
`"
|
|
1174
|
+
`"Deleting the key \\"someKey\\" on namespace env-bound-id."`
|
|
1116
1175
|
);
|
|
1117
1176
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1118
1177
|
expect(requests.count).toEqual(1);
|
|
@@ -1128,13 +1187,325 @@ describe("wrangler", () => {
|
|
|
1128
1187
|
});
|
|
1129
1188
|
});
|
|
1130
1189
|
});
|
|
1190
|
+
|
|
1191
|
+
describe("kv:bulk", () => {
|
|
1192
|
+
describe("put", () => {
|
|
1193
|
+
function mockPutRequest(
|
|
1194
|
+
expectedNamespaceId: string,
|
|
1195
|
+
expectedKeyValues: KeyValue[]
|
|
1196
|
+
) {
|
|
1197
|
+
const requests = { count: 0 };
|
|
1198
|
+
setMockResponse(
|
|
1199
|
+
"/accounts/:accountId/storage/kv/namespaces/:namespaceId/bulk",
|
|
1200
|
+
"PUT",
|
|
1201
|
+
([_url, accountId, namespaceId], { body }) => {
|
|
1202
|
+
requests.count++;
|
|
1203
|
+
expect(accountId).toEqual("some-account-id");
|
|
1204
|
+
expect(namespaceId).toEqual(expectedNamespaceId);
|
|
1205
|
+
expect(JSON.parse(body as string)).toEqual(
|
|
1206
|
+
expectedKeyValues.slice(
|
|
1207
|
+
(requests.count - 1) * 5000,
|
|
1208
|
+
requests.count * 5000
|
|
1209
|
+
)
|
|
1210
|
+
);
|
|
1211
|
+
return null;
|
|
1212
|
+
}
|
|
1213
|
+
);
|
|
1214
|
+
return requests;
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
it("should put the key-values parsed from a file", async () => {
|
|
1218
|
+
const keyValues: KeyValue[] = [
|
|
1219
|
+
{ key: "someKey1", value: "someValue1" },
|
|
1220
|
+
{ key: "ns:someKey2", value: "123", base64: true },
|
|
1221
|
+
{ key: "someKey3", value: "someValue3", expiration: 100 },
|
|
1222
|
+
{ key: "someKey4", value: "someValue4", expiration_ttl: 500 },
|
|
1223
|
+
];
|
|
1224
|
+
writeFileSync("./keys.json", JSON.stringify(keyValues));
|
|
1225
|
+
const requests = mockPutRequest("some-namespace-id", keyValues);
|
|
1226
|
+
await runWrangler(
|
|
1227
|
+
`kv:bulk put --namespace-id some-namespace-id keys.json`
|
|
1228
|
+
);
|
|
1229
|
+
expect(requests.count).toEqual(1);
|
|
1230
|
+
expect(std.out).toMatchInlineSnapshot(`"Success!"`);
|
|
1231
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1232
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1233
|
+
});
|
|
1234
|
+
|
|
1235
|
+
it("should put the key-values in batches of 5000 parsed from a file", async () => {
|
|
1236
|
+
const keyValues: KeyValue[] = new Array(12000).fill({
|
|
1237
|
+
key: "someKey1",
|
|
1238
|
+
value: "someValue1",
|
|
1239
|
+
});
|
|
1240
|
+
writeFileSync("./keys.json", JSON.stringify(keyValues));
|
|
1241
|
+
const requests = mockPutRequest("some-namespace-id", keyValues);
|
|
1242
|
+
await runWrangler(
|
|
1243
|
+
`kv:bulk put --namespace-id some-namespace-id keys.json`
|
|
1244
|
+
);
|
|
1245
|
+
expect(requests.count).toEqual(3);
|
|
1246
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
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)
|
|
1251
|
+
Success!"
|
|
1252
|
+
`);
|
|
1253
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1254
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1255
|
+
});
|
|
1256
|
+
|
|
1257
|
+
it("should error if the file is not a JSON array", async () => {
|
|
1258
|
+
const keyValues = { key: "someKey1", value: "someValue1" };
|
|
1259
|
+
writeFileSync("./keys.json", JSON.stringify(keyValues));
|
|
1260
|
+
await expect(
|
|
1261
|
+
runWrangler(`kv:bulk put --namespace-id some-namespace-id keys.json`)
|
|
1262
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
1263
|
+
"Unexpected JSON input from \\"keys.json\\".
|
|
1264
|
+
Expected an array of key-value objects but got type \\"object\\"."
|
|
1265
|
+
`);
|
|
1266
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1267
|
+
"
|
|
1268
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
1269
|
+
`);
|
|
1270
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1271
|
+
});
|
|
1272
|
+
|
|
1273
|
+
it("should error if the array contains items that are not key-value objects", async () => {
|
|
1274
|
+
const keyValues = [
|
|
1275
|
+
123,
|
|
1276
|
+
"a string",
|
|
1277
|
+
{ key: "someKey" },
|
|
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
|
|
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" },
|
|
1298
|
+
];
|
|
1299
|
+
writeFileSync("./keys.json", JSON.stringify(keyValues));
|
|
1300
|
+
await expect(
|
|
1301
|
+
runWrangler(`kv:bulk put --namespace-id some-namespace-id keys.json`)
|
|
1302
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
1303
|
+
"Unexpected JSON input from \\"keys.json\\".
|
|
1304
|
+
Each item in the array should be an object that matches:
|
|
1305
|
+
|
|
1306
|
+
interface KeyValue {
|
|
1307
|
+
key: string;
|
|
1308
|
+
value: string;
|
|
1309
|
+
expiration?: number;
|
|
1310
|
+
expiration_ttl?: number;
|
|
1311
|
+
metadata?: object;
|
|
1312
|
+
base64?: boolean;
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
The item at index 0 is 123
|
|
1316
|
+
The item at index 1 is \\"a string\\"
|
|
1317
|
+
The item at index 2 is {\\"key\\":\\"someKey\\"}
|
|
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\\"}"
|
|
1326
|
+
`);
|
|
1327
|
+
|
|
1328
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1329
|
+
"
|
|
1330
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
1331
|
+
`);
|
|
1332
|
+
expect(std.warn).toMatchInlineSnapshot(`
|
|
1333
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mUnexpected key-value properties in \\"keys.json\\".[0m
|
|
1334
|
+
|
|
1335
|
+
The item at index 5 contains unexpected properties: [\\"invalid\\"].
|
|
1336
|
+
|
|
1337
|
+
"
|
|
1338
|
+
`);
|
|
1339
|
+
});
|
|
1340
|
+
});
|
|
1341
|
+
|
|
1342
|
+
describe("delete", () => {
|
|
1343
|
+
function mockDeleteRequest(
|
|
1344
|
+
expectedNamespaceId: string,
|
|
1345
|
+
expectedKeys: string[]
|
|
1346
|
+
) {
|
|
1347
|
+
const requests = { count: 0 };
|
|
1348
|
+
setMockResponse(
|
|
1349
|
+
"/accounts/:accountId/storage/kv/namespaces/:namespaceId/bulk",
|
|
1350
|
+
"DELETE",
|
|
1351
|
+
([_url, accountId, namespaceId], { headers, body }) => {
|
|
1352
|
+
requests.count++;
|
|
1353
|
+
expect(accountId).toEqual("some-account-id");
|
|
1354
|
+
expect(namespaceId).toEqual(expectedNamespaceId);
|
|
1355
|
+
expect(new Headers(headers ?? []).get("Content-Type")).toEqual(
|
|
1356
|
+
"application/json"
|
|
1357
|
+
);
|
|
1358
|
+
expect(JSON.parse(body as string)).toEqual(
|
|
1359
|
+
expectedKeys.slice(
|
|
1360
|
+
(requests.count - 1) * 5000,
|
|
1361
|
+
requests.count * 5000
|
|
1362
|
+
)
|
|
1363
|
+
);
|
|
1364
|
+
return null;
|
|
1365
|
+
}
|
|
1366
|
+
);
|
|
1367
|
+
return requests;
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
it("should delete the keys parsed from a file", async () => {
|
|
1371
|
+
const keys = ["someKey1", "ns:someKey2"];
|
|
1372
|
+
writeFileSync("./keys.json", JSON.stringify(keys));
|
|
1373
|
+
mockConfirm({
|
|
1374
|
+
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
|
|
1375
|
+
result: true,
|
|
1376
|
+
});
|
|
1377
|
+
const requests = mockDeleteRequest("some-namespace-id", keys);
|
|
1378
|
+
await runWrangler(
|
|
1379
|
+
`kv:bulk delete --namespace-id some-namespace-id keys.json`
|
|
1380
|
+
);
|
|
1381
|
+
expect(requests.count).toEqual(1);
|
|
1382
|
+
expect(std.out).toMatchInlineSnapshot(`"Success!"`);
|
|
1383
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1384
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1385
|
+
});
|
|
1386
|
+
|
|
1387
|
+
it("should delete the keys in batches of 5000 parsed from a file", async () => {
|
|
1388
|
+
const keys = new Array(12000).fill("some-key");
|
|
1389
|
+
writeFileSync("./keys.json", JSON.stringify(keys));
|
|
1390
|
+
mockConfirm({
|
|
1391
|
+
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
|
|
1392
|
+
result: true,
|
|
1393
|
+
});
|
|
1394
|
+
const requests = mockDeleteRequest("some-namespace-id", keys);
|
|
1395
|
+
await runWrangler(
|
|
1396
|
+
`kv:bulk delete --namespace-id some-namespace-id keys.json`
|
|
1397
|
+
);
|
|
1398
|
+
expect(requests.count).toEqual(3);
|
|
1399
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
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)
|
|
1404
|
+
Success!"
|
|
1405
|
+
`);
|
|
1406
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1407
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1408
|
+
});
|
|
1409
|
+
|
|
1410
|
+
it("should not delete the keys if the user confirms no", async () => {
|
|
1411
|
+
const keys = ["someKey1", "ns:someKey2"];
|
|
1412
|
+
writeFileSync("./keys.json", JSON.stringify(keys));
|
|
1413
|
+
mockConfirm({
|
|
1414
|
+
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
|
|
1415
|
+
result: false,
|
|
1416
|
+
});
|
|
1417
|
+
await runWrangler(
|
|
1418
|
+
`kv:bulk delete --namespace-id some-namespace-id keys.json`
|
|
1419
|
+
);
|
|
1420
|
+
expect(std.out).toMatchInlineSnapshot(
|
|
1421
|
+
`"Not deleting keys read from \\"keys.json\\"."`
|
|
1422
|
+
);
|
|
1423
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1424
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1425
|
+
});
|
|
1426
|
+
|
|
1427
|
+
it("should delete the keys without asking if --force is provided", async () => {
|
|
1428
|
+
const keys = ["someKey1", "ns:someKey2"];
|
|
1429
|
+
writeFileSync("./keys.json", JSON.stringify(keys));
|
|
1430
|
+
const requests = mockDeleteRequest("some-namespace-id", keys);
|
|
1431
|
+
await runWrangler(
|
|
1432
|
+
`kv:bulk delete --namespace-id some-namespace-id keys.json --force`
|
|
1433
|
+
);
|
|
1434
|
+
expect(requests.count).toEqual(1);
|
|
1435
|
+
expect(std.out).toMatchInlineSnapshot(`"Success!"`);
|
|
1436
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1437
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1438
|
+
});
|
|
1439
|
+
|
|
1440
|
+
it("should delete the keys without asking if -f is provided", async () => {
|
|
1441
|
+
const keys = ["someKey1", "ns:someKey2"];
|
|
1442
|
+
writeFileSync("./keys.json", JSON.stringify(keys));
|
|
1443
|
+
const requests = mockDeleteRequest("some-namespace-id", keys);
|
|
1444
|
+
await runWrangler(
|
|
1445
|
+
`kv:bulk delete --namespace-id some-namespace-id keys.json -f`
|
|
1446
|
+
);
|
|
1447
|
+
expect(requests.count).toEqual(1);
|
|
1448
|
+
expect(std.out).toMatchInlineSnapshot(`"Success!"`);
|
|
1449
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1450
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1451
|
+
});
|
|
1452
|
+
|
|
1453
|
+
it("should error if the file is not a JSON array", async () => {
|
|
1454
|
+
const keys = 12354;
|
|
1455
|
+
writeFileSync("./keys.json", JSON.stringify(keys));
|
|
1456
|
+
mockConfirm({
|
|
1457
|
+
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
|
|
1458
|
+
result: true,
|
|
1459
|
+
});
|
|
1460
|
+
await expect(
|
|
1461
|
+
runWrangler(
|
|
1462
|
+
`kv:bulk delete --namespace-id some-namespace-id keys.json`
|
|
1463
|
+
)
|
|
1464
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
1465
|
+
"Unexpected JSON input from \\"keys.json\\".
|
|
1466
|
+
Expected an array of strings but got:
|
|
1467
|
+
12354"
|
|
1468
|
+
`);
|
|
1469
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1470
|
+
"
|
|
1471
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
1472
|
+
`);
|
|
1473
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1474
|
+
});
|
|
1475
|
+
|
|
1476
|
+
it("should error if the file contains non-string items", async () => {
|
|
1477
|
+
const keys = ["good", 12354, { key: "someKey" }, null];
|
|
1478
|
+
writeFileSync("./keys.json", JSON.stringify(keys));
|
|
1479
|
+
mockConfirm({
|
|
1480
|
+
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
|
|
1481
|
+
result: true,
|
|
1482
|
+
});
|
|
1483
|
+
await expect(
|
|
1484
|
+
runWrangler(
|
|
1485
|
+
`kv:bulk delete --namespace-id some-namespace-id keys.json`
|
|
1486
|
+
)
|
|
1487
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
1488
|
+
"Unexpected JSON input from \\"keys.json\\".
|
|
1489
|
+
Expected an array of strings.
|
|
1490
|
+
The item at index 1 is type: \\"number\\" - 12354
|
|
1491
|
+
The item at index 2 is type: \\"object\\" - {\\"key\\":\\"someKey\\"}
|
|
1492
|
+
The item at index 3 is type: \\"object\\" - null"
|
|
1493
|
+
`);
|
|
1494
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1495
|
+
"
|
|
1496
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
1497
|
+
`);
|
|
1498
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1499
|
+
});
|
|
1500
|
+
});
|
|
1501
|
+
});
|
|
1131
1502
|
});
|
|
1132
1503
|
|
|
1133
1504
|
function writeWranglerConfig() {
|
|
1134
1505
|
writeFileSync(
|
|
1135
1506
|
"./wrangler.toml",
|
|
1136
1507
|
[
|
|
1137
|
-
'name = "
|
|
1508
|
+
'name = "other-worker"',
|
|
1138
1509
|
"kv_namespaces = [",
|
|
1139
1510
|
' { binding = "someBinding", id = "bound-id", preview_id = "preview-bound-id" }',
|
|
1140
1511
|
"]",
|