wrangler 0.0.0-e178d6fb → 0.0.0-e1c2f5b9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -2
- package/bin/wrangler.js +31 -11
- package/miniflare-dist/index.mjs +1340 -330
- package/package.json +40 -13
- package/src/__tests__/access.test.ts +25 -0
- package/src/__tests__/api-dev.test.ts +238 -0
- package/src/__tests__/api-devregistry.test.js +64 -0
- package/src/__tests__/api.test.ts +80 -0
- package/src/__tests__/configuration.test.ts +683 -470
- package/src/__tests__/d1.test.ts +123 -0
- package/src/__tests__/delete.test.ts +263 -0
- package/src/__tests__/deployments.test.ts +105 -0
- package/src/__tests__/dev.test.tsx +453 -70
- package/src/__tests__/dialogs.test.tsx +40 -0
- package/src/__tests__/generate.test.ts +235 -0
- package/src/__tests__/get-host-from-url.test.ts +16 -0
- package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
- package/src/__tests__/helpers/mock-cfetch.ts +92 -26
- package/src/__tests__/helpers/mock-console.ts +11 -2
- package/src/__tests__/helpers/mock-dialogs.ts +1 -1
- package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -0
- package/src/__tests__/helpers/mock-known-routes.ts +7 -0
- package/src/__tests__/helpers/mock-kv.ts +1 -1
- package/src/__tests__/helpers/mock-oauth-flow.ts +74 -53
- package/src/__tests__/helpers/mock-process.ts +8 -13
- package/src/__tests__/helpers/msw/handlers/access.ts +13 -0
- package/src/__tests__/helpers/msw/handlers/deployments.ts +59 -0
- package/src/__tests__/helpers/msw/handlers/namespaces.ts +104 -0
- package/src/__tests__/helpers/msw/handlers/oauth.ts +31 -0
- package/src/__tests__/helpers/msw/handlers/r2.ts +80 -0
- package/src/__tests__/helpers/msw/handlers/script.ts +75 -0
- package/src/__tests__/helpers/msw/handlers/user.ts +63 -0
- package/src/__tests__/helpers/msw/handlers/zones.ts +22 -0
- package/src/__tests__/helpers/msw/index.ts +21 -0
- package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +1 -0
- package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +5 -0
- package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +1 -0
- package/src/__tests__/helpers/worker-scripts/parent-worker.js +8 -0
- package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +5 -0
- package/src/__tests__/index.test.ts +103 -97
- package/src/__tests__/init.test.ts +1484 -382
- package/src/__tests__/jest.setup.ts +88 -5
- package/src/__tests__/kv.test.ts +655 -540
- package/src/__tests__/logout.test.ts +47 -0
- package/src/__tests__/metrics.test.ts +95 -45
- package/src/__tests__/middleware.scheduled.test.ts +145 -0
- package/src/__tests__/middleware.test.ts +750 -0
- package/src/__tests__/pages-deployment-tail.test.ts +884 -0
- package/src/__tests__/pages.test.ts +1301 -119
- package/src/__tests__/paths.test.ts +39 -0
- package/src/__tests__/publish.test.ts +2266 -1180
- package/src/__tests__/pubsub.test.ts +211 -88
- package/src/__tests__/queues.test.ts +522 -0
- package/src/__tests__/r2.test.ts +363 -203
- package/src/__tests__/secret.test.ts +261 -59
- package/src/__tests__/tail.test.ts +352 -151
- package/src/__tests__/test-old-node-version.js +3 -3
- package/src/__tests__/tsconfig-sanity.ts +12 -0
- package/src/__tests__/tsconfig.json +8 -0
- package/src/__tests__/tsconfig.tsbuildinfo +1 -0
- package/src/__tests__/type-generation.test.ts +233 -0
- package/src/__tests__/user.test.ts +59 -73
- package/src/__tests__/utils-collectKeyValues.test.ts +47 -0
- package/src/__tests__/validate-dev-props.test.ts +56 -0
- package/src/__tests__/whoami.test.tsx +114 -66
- package/src/__tests__/worker-namespace.test.ts +154 -155
- package/src/api/dev.ts +170 -38
- package/src/api/index.ts +1 -0
- package/src/bundle-reporter.tsx +41 -2
- package/src/bundle.ts +668 -81
- package/src/cfetch/index.ts +40 -3
- package/src/cfetch/internal.ts +144 -32
- package/src/cli.ts +4 -3
- package/src/config/config.ts +27 -3
- package/src/config/environment.ts +131 -7
- package/src/config/index.ts +128 -8
- package/src/config/validation-helpers.ts +19 -6
- package/src/config/validation.ts +411 -14
- package/src/config-cache.ts +3 -2
- package/src/create-worker-preview.ts +31 -6
- package/src/create-worker-upload-form.ts +84 -22
- package/src/d1/backups.tsx +223 -0
- package/src/d1/constants.ts +2 -0
- package/src/d1/create.tsx +63 -0
- package/src/d1/delete.tsx +56 -0
- package/src/d1/execute.tsx +352 -0
- package/src/d1/formatTimeAgo.ts +14 -0
- package/src/d1/index.ts +101 -0
- package/src/d1/list.tsx +48 -0
- package/src/d1/migrations/apply.tsx +196 -0
- package/src/d1/migrations/create.tsx +77 -0
- package/src/d1/migrations/helpers.ts +147 -0
- package/src/d1/migrations/index.tsx +3 -0
- package/src/d1/migrations/list.tsx +79 -0
- package/src/d1/migrations/options.ts +18 -0
- package/src/d1/options.ts +22 -0
- package/src/d1/types.tsx +24 -0
- package/src/d1/utils.ts +48 -0
- package/src/delete.ts +108 -0
- package/src/deployments.ts +83 -0
- package/src/deprecated/index.ts +145 -0
- package/src/dev/dev-vars.ts +11 -8
- package/src/dev/dev.tsx +220 -58
- package/src/dev/get-local-persistence-path.tsx +31 -0
- package/src/dev/local.tsx +740 -181
- package/src/dev/remote.tsx +340 -123
- package/src/dev/start-server.ts +543 -0
- package/src/dev/use-esbuild.ts +61 -7
- package/src/dev/validate-dev-props.ts +31 -0
- package/src/dev-registry.tsx +201 -0
- package/src/dev.tsx +614 -258
- package/src/dialogs.tsx +41 -8
- package/src/{worker-namespace.ts → dispatch-namespace.ts} +23 -22
- package/src/docs/index.ts +97 -0
- package/src/entry.ts +3 -2
- package/src/environment-variables/factory.ts +88 -0
- package/src/environment-variables/misc-variables.ts +30 -0
- package/src/generate/index.ts +300 -0
- package/src/git-client.ts +100 -7
- package/src/index.tsx +249 -1560
- package/src/init.ts +626 -150
- package/src/inspect.ts +137 -32
- package/src/{metrics/is-ci.ts → is-ci.ts} +0 -0
- package/src/is-interactive.ts +4 -0
- package/src/jest.d.ts +4 -0
- package/src/{kv.ts → kv/helpers.ts} +3 -3
- package/src/kv/index.ts +596 -0
- package/src/logger.ts +27 -8
- package/src/metrics/index.ts +1 -0
- package/src/metrics/metrics-config.ts +4 -4
- package/src/metrics/metrics-dispatcher.ts +1 -0
- package/src/metrics/metrics-usage-headers.ts +24 -0
- package/src/metrics/send-event.ts +13 -8
- package/src/miniflare-cli/assets.ts +172 -465
- package/src/miniflare-cli/index.ts +149 -24
- package/src/miniflare-cli/tsconfig.json +9 -0
- package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
- package/src/miniflare-cli/types.ts +11 -0
- package/src/module-collection.ts +12 -3
- package/src/pages/build.tsx +108 -42
- package/src/pages/constants.ts +11 -0
- package/src/pages/deployment-tails.tsx +284 -0
- package/src/pages/deployments.tsx +9 -31
- package/src/pages/dev.tsx +417 -108
- package/src/pages/errors.ts +66 -0
- package/src/pages/functions/buildPlugin.ts +86 -84
- package/src/pages/functions/buildWorker.ts +121 -106
- package/src/pages/functions/routes-consolidation.test.ts +250 -0
- package/src/pages/functions/routes-consolidation.ts +73 -0
- package/src/pages/functions/routes-transformation.test.ts +282 -0
- package/src/pages/functions/routes-transformation.ts +115 -0
- package/src/pages/functions/routes-validation.test.ts +403 -0
- package/src/pages/functions/routes-validation.ts +202 -0
- package/src/pages/functions/tsconfig.json +8 -0
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
- package/src/pages/functions.tsx +82 -0
- package/src/pages/hash.tsx +13 -0
- package/src/pages/index.tsx +73 -55
- package/src/pages/projects.tsx +9 -3
- package/src/pages/prompt-select-project.tsx +31 -0
- package/src/pages/publish.tsx +183 -60
- package/src/pages/types.ts +1 -0
- package/src/pages/upload.tsx +107 -56
- package/src/pages/utils.ts +13 -2
- package/src/paths.ts +49 -4
- package/src/proxy.ts +375 -157
- package/src/publish/index.ts +270 -0
- package/src/{publish.ts → publish/publish.ts} +431 -188
- package/src/pubsub/pubsub-commands.tsx +4 -3
- package/src/queues/cli/commands/consumer/add.ts +71 -0
- package/src/queues/cli/commands/consumer/index.ts +22 -0
- package/src/queues/cli/commands/consumer/remove.ts +38 -0
- package/src/queues/cli/commands/create.ts +25 -0
- package/src/queues/cli/commands/delete.ts +26 -0
- package/src/queues/cli/commands/index.ts +36 -0
- package/src/queues/cli/commands/list.ts +25 -0
- package/src/queues/client.ts +135 -0
- package/src/queues/utils.ts +18 -0
- package/src/r2/constants.ts +4 -0
- package/src/r2/helpers.ts +131 -0
- package/src/r2/index.ts +289 -0
- package/src/routes.ts +140 -0
- package/src/secret/index.ts +379 -0
- package/src/sites.tsx +3 -3
- package/src/tail/createTail.ts +379 -0
- package/src/tail/filters.ts +4 -6
- package/src/tail/index.ts +199 -284
- package/src/tail/printing.ts +43 -3
- package/src/tsconfig-sanity.ts +16 -0
- package/src/type-generation.ts +181 -0
- package/src/user/access.ts +68 -0
- package/src/user/auth-variables.ts +113 -0
- package/src/user/choose-account.tsx +1 -1
- package/src/user/index.ts +0 -1
- package/src/user/user.tsx +116 -49
- package/src/utils/collectKeyValues.ts +14 -0
- package/src/whoami.tsx +80 -2
- package/src/worker.ts +69 -9
- package/src/yargs-types.ts +24 -0
- package/src/zones.ts +124 -9
- package/templates/__tests__/pages-dev-util.test.ts +128 -0
- package/templates/__tests__/tsconfig-sanity.ts +12 -0
- package/templates/__tests__/tsconfig.json +8 -0
- package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
- package/templates/d1-beta-facade.js +205 -0
- package/templates/facade.d.ts +14 -0
- package/templates/first-party-worker-module-facade.ts +19 -0
- package/templates/format-dev-errors.ts +33 -0
- package/templates/init-tests/test-jest-new-worker.js +23 -0
- package/templates/init-tests/test-vitest-new-worker.js +24 -0
- package/templates/init-tests/test-vitest-new-worker.ts +25 -0
- package/templates/middleware/common.ts +62 -0
- package/templates/middleware/loader-modules.ts +82 -0
- package/templates/middleware/loader-sw.ts +233 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +20 -0
- package/templates/middleware/middleware-pretty-error.ts +40 -0
- package/templates/middleware/middleware-scheduled.ts +15 -0
- package/templates/new-worker.js +1 -1
- package/templates/pages-dev-pipeline.ts +31 -0
- package/templates/pages-dev-util.ts +52 -0
- package/templates/pages-shim.ts +4 -1
- package/templates/pages-template-plugin.ts +21 -5
- package/templates/pages-template-worker.ts +37 -9
- package/templates/{static-asset-facade.js → serve-static-assets.ts} +23 -7
- package/templates/service-bindings-module-facade.js +54 -0
- package/templates/service-bindings-sw-facade.js +42 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +106 -0
- package/templates/tsconfig.json +5 -102
- package/templates/tsconfig.tsbuildinfo +1 -0
- package/wrangler-dist/cli.d.ts +621 -42
- package/wrangler-dist/cli.js +144441 -102606
- package/src/environment-variables.ts +0 -35
- package/src/faye-websocket.d.ts +0 -6
- package/src/generate.ts +0 -33
- package/src/miniflare-cli/enum-keys.ts +0 -17
- package/src/preview.ts +0 -31
- package/src/r2.ts +0 -50
- package/src/user/env-vars.ts +0 -46
package/src/__tests__/kv.test.ts
CHANGED
|
@@ -1,48 +1,46 @@
|
|
|
1
1
|
import { writeFileSync } from "node:fs";
|
|
2
|
-
import {
|
|
2
|
+
import { rest } from "msw";
|
|
3
3
|
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
|
|
4
|
-
import {
|
|
5
|
-
setMockResponse,
|
|
6
|
-
unsetAllMocks,
|
|
7
|
-
unsetMockFetchKVGetValues,
|
|
8
|
-
setMockFetchKVGetValue,
|
|
9
|
-
setMockRawResponse,
|
|
10
|
-
createFetchResult,
|
|
11
|
-
} from "./helpers/mock-cfetch";
|
|
12
4
|
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
13
5
|
import { clearConfirmMocks, mockConfirm } from "./helpers/mock-dialogs";
|
|
14
6
|
import { useMockIsTTY } from "./helpers/mock-istty";
|
|
15
|
-
import { mockKeyListRequest } from "./helpers/mock-kv";
|
|
16
|
-
import { mockGetMemberships } from "./helpers/mock-oauth-flow";
|
|
17
7
|
import { mockProcess } from "./helpers/mock-process";
|
|
8
|
+
import { msw } from "./helpers/msw";
|
|
18
9
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
19
10
|
import { runWrangler } from "./helpers/run-wrangler";
|
|
20
|
-
import type {
|
|
11
|
+
import type {
|
|
12
|
+
KeyValue,
|
|
13
|
+
KVNamespaceInfo,
|
|
14
|
+
NamespaceKeyInfo,
|
|
15
|
+
} from "../kv/helpers";
|
|
21
16
|
|
|
22
17
|
describe("wrangler", () => {
|
|
23
18
|
mockAccountId();
|
|
24
19
|
mockApiToken();
|
|
25
20
|
runInTempDir();
|
|
21
|
+
|
|
26
22
|
const std = mockConsoleMethods();
|
|
27
23
|
const proc = mockProcess();
|
|
28
24
|
|
|
29
25
|
afterEach(() => {
|
|
30
|
-
unsetAllMocks();
|
|
31
26
|
clearConfirmMocks();
|
|
32
27
|
});
|
|
33
|
-
|
|
34
28
|
describe("kv:namespace", () => {
|
|
35
29
|
describe("create", () => {
|
|
36
30
|
function mockCreateRequest(expectedTitle: string) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
msw.use(
|
|
32
|
+
rest.post(
|
|
33
|
+
"*/accounts/:accountId/storage/kv/namespaces",
|
|
34
|
+
async (req, res, ctx) => {
|
|
35
|
+
expect(req.params.accountId).toEqual("some-account-id");
|
|
36
|
+
const title = (await req.json()).title as string;
|
|
37
|
+
expect(title).toEqual(expectedTitle);
|
|
38
|
+
return res.once(
|
|
39
|
+
ctx.status(200),
|
|
40
|
+
ctx.json(createFetchResult({ id: "some-namespace-id" }))
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
)
|
|
46
44
|
);
|
|
47
45
|
}
|
|
48
46
|
|
|
@@ -53,28 +51,28 @@ describe("wrangler", () => {
|
|
|
53
51
|
`"Not enough non-option arguments: got 0, need at least 1"`
|
|
54
52
|
);
|
|
55
53
|
expect(std.out).toMatchInlineSnapshot(`
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
"
|
|
55
|
+
wrangler kv:namespace create <namespace>
|
|
58
56
|
|
|
59
|
-
|
|
57
|
+
Create a new namespace
|
|
60
58
|
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
Positionals:
|
|
60
|
+
namespace The name of the new namespace [string] [required]
|
|
63
61
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
Flags:
|
|
63
|
+
-c, --config Path to .toml configuration file [string]
|
|
64
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
65
|
+
-h, --help Show help [boolean]
|
|
66
|
+
-v, --version Show version number [boolean]
|
|
68
67
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
`);
|
|
68
|
+
Options:
|
|
69
|
+
--preview Interact with a preview namespace [boolean]"
|
|
70
|
+
`);
|
|
73
71
|
expect(std.err).toMatchInlineSnapshot(`
|
|
74
|
-
|
|
72
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot enough non-option arguments: got 0, need at least 1[0m
|
|
75
73
|
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
"
|
|
75
|
+
`);
|
|
78
76
|
});
|
|
79
77
|
|
|
80
78
|
it("should error if the namespace to create contains spaces", async () => {
|
|
@@ -84,28 +82,28 @@ describe("wrangler", () => {
|
|
|
84
82
|
`"Unknown arguments: def, ghi"`
|
|
85
83
|
);
|
|
86
84
|
expect(std.out).toMatchInlineSnapshot(`
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
"
|
|
86
|
+
wrangler kv:namespace create <namespace>
|
|
89
87
|
|
|
90
|
-
|
|
88
|
+
Create a new namespace
|
|
91
89
|
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
Positionals:
|
|
91
|
+
namespace The name of the new namespace [string] [required]
|
|
94
92
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
93
|
+
Flags:
|
|
94
|
+
-c, --config Path to .toml configuration file [string]
|
|
95
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
96
|
+
-h, --help Show help [boolean]
|
|
97
|
+
-v, --version Show version number [boolean]
|
|
99
98
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
`);
|
|
99
|
+
Options:
|
|
100
|
+
--preview Interact with a preview namespace [boolean]"
|
|
101
|
+
`);
|
|
104
102
|
expect(std.err).toMatchInlineSnapshot(`
|
|
105
|
-
|
|
103
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mUnknown arguments: def, ghi[0m
|
|
106
104
|
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
"
|
|
106
|
+
`);
|
|
109
107
|
});
|
|
110
108
|
|
|
111
109
|
it("should error if the namespace to create is not valid", async () => {
|
|
@@ -116,50 +114,50 @@ describe("wrangler", () => {
|
|
|
116
114
|
);
|
|
117
115
|
|
|
118
116
|
expect(std.out).toMatchInlineSnapshot(`
|
|
119
|
-
|
|
120
|
-
|
|
117
|
+
"
|
|
118
|
+
wrangler kv:namespace create <namespace>
|
|
121
119
|
|
|
122
|
-
|
|
120
|
+
Create a new namespace
|
|
123
121
|
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
Positionals:
|
|
123
|
+
namespace The name of the new namespace [string] [required]
|
|
126
124
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
125
|
+
Flags:
|
|
126
|
+
-c, --config Path to .toml configuration file [string]
|
|
127
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
128
|
+
-h, --help Show help [boolean]
|
|
129
|
+
-v, --version Show version number [boolean]
|
|
131
130
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
`);
|
|
131
|
+
Options:
|
|
132
|
+
--preview Interact with a preview namespace [boolean]"
|
|
133
|
+
`);
|
|
136
134
|
expect(std.err).toMatchInlineSnapshot(`
|
|
137
|
-
|
|
135
|
+
"[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
|
|
138
136
|
|
|
139
|
-
|
|
140
|
-
|
|
137
|
+
"
|
|
138
|
+
`);
|
|
141
139
|
});
|
|
142
140
|
|
|
143
141
|
it("should create a namespace", async () => {
|
|
144
142
|
mockCreateRequest("worker-UnitTestNamespace");
|
|
145
143
|
await runWrangler("kv:namespace create UnitTestNamespace");
|
|
146
144
|
expect(std.out).toMatchInlineSnapshot(`
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
145
|
+
"🌀 Creating namespace with title \\"worker-UnitTestNamespace\\"
|
|
146
|
+
✨ Success!
|
|
147
|
+
Add the following to your configuration file in your kv_namespaces array:
|
|
148
|
+
{ binding = \\"UnitTestNamespace\\", id = \\"some-namespace-id\\" }"
|
|
149
|
+
`);
|
|
152
150
|
});
|
|
153
151
|
|
|
154
152
|
it("should create a preview namespace if configured to do so", async () => {
|
|
155
153
|
mockCreateRequest("worker-UnitTestNamespace_preview");
|
|
156
154
|
await runWrangler("kv:namespace create UnitTestNamespace --preview");
|
|
157
155
|
expect(std.out).toMatchInlineSnapshot(`
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
156
|
+
"🌀 Creating namespace with title \\"worker-UnitTestNamespace_preview\\"
|
|
157
|
+
✨ Success!
|
|
158
|
+
Add the following to your configuration file in your kv_namespaces array:
|
|
159
|
+
{ binding = \\"UnitTestNamespace\\", preview_id = \\"some-namespace-id\\" }"
|
|
160
|
+
`);
|
|
163
161
|
});
|
|
164
162
|
|
|
165
163
|
it("should create a namespace using configured worker name", async () => {
|
|
@@ -167,11 +165,11 @@ describe("wrangler", () => {
|
|
|
167
165
|
mockCreateRequest("other-worker-UnitTestNamespace");
|
|
168
166
|
await runWrangler("kv:namespace create UnitTestNamespace");
|
|
169
167
|
expect(std.out).toMatchInlineSnapshot(`
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
168
|
+
"🌀 Creating namespace with title \\"other-worker-UnitTestNamespace\\"
|
|
169
|
+
✨ Success!
|
|
170
|
+
Add the following to your configuration file in your kv_namespaces array:
|
|
171
|
+
{ binding = \\"UnitTestNamespace\\", id = \\"some-namespace-id\\" }"
|
|
172
|
+
`);
|
|
175
173
|
});
|
|
176
174
|
|
|
177
175
|
it("should create a namespace in an environment if configured to do so", async () => {
|
|
@@ -180,31 +178,41 @@ describe("wrangler", () => {
|
|
|
180
178
|
"kv:namespace create UnitTestNamespace --env customEnv"
|
|
181
179
|
);
|
|
182
180
|
expect(std.out).toMatchInlineSnapshot(`
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
181
|
+
"🌀 Creating namespace with title \\"worker-customEnv-UnitTestNamespace\\"
|
|
182
|
+
✨ Success!
|
|
183
|
+
Add the following to your configuration file in your kv_namespaces array under [env.customEnv]:
|
|
184
|
+
{ binding = \\"UnitTestNamespace\\", id = \\"some-namespace-id\\" }"
|
|
185
|
+
`);
|
|
188
186
|
});
|
|
189
187
|
});
|
|
190
188
|
|
|
191
189
|
describe("list", () => {
|
|
192
|
-
function mockListRequest(namespaces:
|
|
190
|
+
function mockListRequest(namespaces: KVNamespaceInfo[]) {
|
|
193
191
|
const requests = { count: 0 };
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
192
|
+
msw.use(
|
|
193
|
+
rest.get(
|
|
194
|
+
"*/accounts/:accountId/storage/kv/namespaces",
|
|
195
|
+
async (req, res, ctx) => {
|
|
196
|
+
requests.count++;
|
|
197
|
+
expect(req.params.accountId).toEqual("some-account-id");
|
|
198
|
+
expect(req.url.searchParams.get("per_page")).toEqual("100");
|
|
199
|
+
expect(req.url.searchParams.get("order")).toEqual("title");
|
|
200
|
+
expect(req.url.searchParams.get("direction")).toEqual("asc");
|
|
201
|
+
expect(req.url.searchParams.get("page")).toEqual(
|
|
202
|
+
`${requests.count}`
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
const pageSize = Number(req.url.searchParams.get("per_page"));
|
|
206
|
+
const page = Number(req.url.searchParams.get("page"));
|
|
207
|
+
return res(
|
|
208
|
+
ctx.json(
|
|
209
|
+
createFetchResult(
|
|
210
|
+
namespaces.slice((page - 1) * pageSize, page * pageSize)
|
|
211
|
+
)
|
|
212
|
+
)
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
)
|
|
208
216
|
);
|
|
209
217
|
return requests;
|
|
210
218
|
}
|
|
@@ -218,8 +226,7 @@ describe("wrangler", () => {
|
|
|
218
226
|
await runWrangler("kv:namespace list");
|
|
219
227
|
|
|
220
228
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
221
|
-
|
|
222
|
-
expect(namespaces).toEqual(kvNamespaces);
|
|
229
|
+
expect(JSON.parse(std.out)).toEqual(kvNamespaces);
|
|
223
230
|
});
|
|
224
231
|
|
|
225
232
|
it("should make multiple requests for paginated results", async () => {
|
|
@@ -230,8 +237,8 @@ describe("wrangler", () => {
|
|
|
230
237
|
}
|
|
231
238
|
const requests = mockListRequest(kvNamespaces);
|
|
232
239
|
await runWrangler("kv:namespace list");
|
|
233
|
-
|
|
234
|
-
expect(
|
|
240
|
+
|
|
241
|
+
expect(JSON.parse(std.out)).toEqual(kvNamespaces);
|
|
235
242
|
expect(requests.count).toEqual(6);
|
|
236
243
|
});
|
|
237
244
|
});
|
|
@@ -239,15 +246,16 @@ describe("wrangler", () => {
|
|
|
239
246
|
describe("delete", () => {
|
|
240
247
|
function mockDeleteRequest(expectedNamespaceId: string) {
|
|
241
248
|
const requests = { count: 0 };
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
249
|
+
msw.use(
|
|
250
|
+
rest.delete(
|
|
251
|
+
"*/accounts/:accountId/storage/kv/namespaces/:namespaceId",
|
|
252
|
+
(req, res, ctx) => {
|
|
253
|
+
requests.count++;
|
|
254
|
+
expect(req.params.accountId).toEqual("some-account-id");
|
|
255
|
+
expect(req.params.namespaceId).toEqual(expectedNamespaceId);
|
|
256
|
+
return res(ctx.status(200), ctx.json(createFetchResult(null)));
|
|
257
|
+
}
|
|
258
|
+
)
|
|
251
259
|
);
|
|
252
260
|
return requests;
|
|
253
261
|
}
|
|
@@ -286,12 +294,12 @@ describe("wrangler", () => {
|
|
|
286
294
|
A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."
|
|
287
295
|
`);
|
|
288
296
|
expect(std.err).toMatchInlineSnapshot(`
|
|
289
|
-
|
|
297
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot able to delete namespace.[0m
|
|
290
298
|
|
|
291
|
-
|
|
299
|
+
A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
|
|
292
300
|
|
|
293
|
-
|
|
294
|
-
|
|
301
|
+
"
|
|
302
|
+
`);
|
|
295
303
|
});
|
|
296
304
|
|
|
297
305
|
it("should delete a namespace specified by binding name in a given environment", async () => {
|
|
@@ -327,39 +335,43 @@ describe("wrangler", () => {
|
|
|
327
335
|
expectedKV: KeyValue
|
|
328
336
|
) {
|
|
329
337
|
const requests = { count: 0 };
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
expect(
|
|
341
|
-
expect((body as FormData).get("
|
|
342
|
-
|
|
343
|
-
);
|
|
344
|
-
|
|
345
|
-
|
|
338
|
+
msw.use(
|
|
339
|
+
rest.put(
|
|
340
|
+
"*/accounts/:accountId/storage/kv/namespaces/:namespaceId/values/:key",
|
|
341
|
+
(req, res, ctx) => {
|
|
342
|
+
requests.count++;
|
|
343
|
+
const { accountId, namespaceId, key } = req.params;
|
|
344
|
+
expect(accountId).toEqual("some-account-id");
|
|
345
|
+
expect(namespaceId).toEqual(expectedNamespaceId);
|
|
346
|
+
expect(encodeURIComponent(key as string)).toEqual(expectedKV.key);
|
|
347
|
+
// if (expectedKV.metadata) {
|
|
348
|
+
// expect(body).toBeInstanceOf(FormData);
|
|
349
|
+
// expect((body as FormData).get("value")).toEqual(
|
|
350
|
+
// expectedKV.value
|
|
351
|
+
// );
|
|
352
|
+
// expect((body as FormData).get("metadata")).toEqual(
|
|
353
|
+
// JSON.stringify(expectedKV.metadata)
|
|
354
|
+
// );
|
|
355
|
+
// } else {
|
|
356
|
+
// expect(body).toEqual(expectedKV.value);
|
|
357
|
+
// }
|
|
358
|
+
if (expectedKV.expiration !== undefined) {
|
|
359
|
+
expect(req.url.searchParams.get("expiration")).toEqual(
|
|
360
|
+
`${expectedKV.expiration}`
|
|
361
|
+
);
|
|
362
|
+
} else {
|
|
363
|
+
expect(req.url.searchParams.has("expiration")).toBe(false);
|
|
364
|
+
}
|
|
365
|
+
if (expectedKV.expiration_ttl) {
|
|
366
|
+
expect(req.url.searchParams.get("expiration_ttl")).toEqual(
|
|
367
|
+
`${expectedKV.expiration_ttl}`
|
|
368
|
+
);
|
|
369
|
+
} else {
|
|
370
|
+
expect(req.url.searchParams.has("expiration_ttl")).toBe(false);
|
|
371
|
+
}
|
|
372
|
+
return res(ctx.status(200), ctx.json(createFetchResult(null)));
|
|
346
373
|
}
|
|
347
|
-
|
|
348
|
-
expect(query.get("expiration")).toEqual(
|
|
349
|
-
`${expectedKV.expiration}`
|
|
350
|
-
);
|
|
351
|
-
} else {
|
|
352
|
-
expect(query.has("expiration")).toBe(false);
|
|
353
|
-
}
|
|
354
|
-
if (expectedKV.expiration_ttl) {
|
|
355
|
-
expect(query.get("expiration_ttl")).toEqual(
|
|
356
|
-
`${expectedKV.expiration_ttl}`
|
|
357
|
-
);
|
|
358
|
-
} else {
|
|
359
|
-
expect(query.has("expiration_ttl")).toBe(false);
|
|
360
|
-
}
|
|
361
|
-
return null;
|
|
362
|
-
}
|
|
374
|
+
)
|
|
363
375
|
);
|
|
364
376
|
return requests;
|
|
365
377
|
}
|
|
@@ -527,35 +539,35 @@ describe("wrangler", () => {
|
|
|
527
539
|
);
|
|
528
540
|
|
|
529
541
|
expect(std.out).toMatchInlineSnapshot(`
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
542
|
+
"
|
|
543
|
+
wrangler kv:key put <key> [value]
|
|
544
|
+
|
|
545
|
+
Writes a single key/value pair to the given namespace.
|
|
546
|
+
|
|
547
|
+
Positionals:
|
|
548
|
+
key The key to write to [string] [required]
|
|
549
|
+
value The value to write [string]
|
|
550
|
+
|
|
551
|
+
Flags:
|
|
552
|
+
-c, --config Path to .toml configuration file [string]
|
|
553
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
554
|
+
-h, --help Show help [boolean]
|
|
555
|
+
-v, --version Show version number [boolean]
|
|
556
|
+
|
|
557
|
+
Options:
|
|
558
|
+
--binding The binding of the namespace to write to [string]
|
|
559
|
+
--namespace-id The id of the namespace to write to [string]
|
|
560
|
+
--preview Interact with a preview namespace [boolean]
|
|
561
|
+
--ttl Time for which the entries should be visible [number]
|
|
562
|
+
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
563
|
+
--metadata Arbitrary JSON that is associated with a key [string]
|
|
564
|
+
--path Read value from the file at a given path [string]"
|
|
565
|
+
`);
|
|
554
566
|
expect(std.err).toMatchInlineSnapshot(`
|
|
555
|
-
|
|
567
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot enough non-option arguments: got 0, need at least 1[0m
|
|
556
568
|
|
|
557
|
-
|
|
558
|
-
|
|
569
|
+
"
|
|
570
|
+
`);
|
|
559
571
|
});
|
|
560
572
|
|
|
561
573
|
it("should error if no binding nor namespace is provided", async () => {
|
|
@@ -566,35 +578,35 @@ describe("wrangler", () => {
|
|
|
566
578
|
);
|
|
567
579
|
|
|
568
580
|
expect(std.out).toMatchInlineSnapshot(`
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
581
|
+
"
|
|
582
|
+
wrangler kv:key put <key> [value]
|
|
583
|
+
|
|
584
|
+
Writes a single key/value pair to the given namespace.
|
|
585
|
+
|
|
586
|
+
Positionals:
|
|
587
|
+
key The key to write to [string] [required]
|
|
588
|
+
value The value to write [string]
|
|
589
|
+
|
|
590
|
+
Flags:
|
|
591
|
+
-c, --config Path to .toml configuration file [string]
|
|
592
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
593
|
+
-h, --help Show help [boolean]
|
|
594
|
+
-v, --version Show version number [boolean]
|
|
595
|
+
|
|
596
|
+
Options:
|
|
597
|
+
--binding The binding of the namespace to write to [string]
|
|
598
|
+
--namespace-id The id of the namespace to write to [string]
|
|
599
|
+
--preview Interact with a preview namespace [boolean]
|
|
600
|
+
--ttl Time for which the entries should be visible [number]
|
|
601
|
+
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
602
|
+
--metadata Arbitrary JSON that is associated with a key [string]
|
|
603
|
+
--path Read value from the file at a given path [string]"
|
|
604
|
+
`);
|
|
593
605
|
expect(std.err).toMatchInlineSnapshot(`
|
|
594
|
-
|
|
606
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mExactly one of the arguments binding and namespace-id is required[0m
|
|
595
607
|
|
|
596
|
-
|
|
597
|
-
|
|
608
|
+
"
|
|
609
|
+
`);
|
|
598
610
|
});
|
|
599
611
|
|
|
600
612
|
it("should error if both binding and namespace is provided", async () => {
|
|
@@ -605,35 +617,35 @@ describe("wrangler", () => {
|
|
|
605
617
|
);
|
|
606
618
|
|
|
607
619
|
expect(std.out).toMatchInlineSnapshot(`
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
620
|
+
"
|
|
621
|
+
wrangler kv:key put <key> [value]
|
|
622
|
+
|
|
623
|
+
Writes a single key/value pair to the given namespace.
|
|
624
|
+
|
|
625
|
+
Positionals:
|
|
626
|
+
key The key to write to [string] [required]
|
|
627
|
+
value The value to write [string]
|
|
628
|
+
|
|
629
|
+
Flags:
|
|
630
|
+
-c, --config Path to .toml configuration file [string]
|
|
631
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
632
|
+
-h, --help Show help [boolean]
|
|
633
|
+
-v, --version Show version number [boolean]
|
|
634
|
+
|
|
635
|
+
Options:
|
|
636
|
+
--binding The binding of the namespace to write to [string]
|
|
637
|
+
--namespace-id The id of the namespace to write to [string]
|
|
638
|
+
--preview Interact with a preview namespace [boolean]
|
|
639
|
+
--ttl Time for which the entries should be visible [number]
|
|
640
|
+
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
641
|
+
--metadata Arbitrary JSON that is associated with a key [string]
|
|
642
|
+
--path Read value from the file at a given path [string]"
|
|
643
|
+
`);
|
|
632
644
|
expect(std.err).toMatchInlineSnapshot(`
|
|
633
|
-
|
|
645
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mArguments binding and namespace-id are mutually exclusive[0m
|
|
634
646
|
|
|
635
|
-
|
|
636
|
-
|
|
647
|
+
"
|
|
648
|
+
`);
|
|
637
649
|
});
|
|
638
650
|
|
|
639
651
|
it("should error if no value nor path is provided", async () => {
|
|
@@ -644,35 +656,35 @@ describe("wrangler", () => {
|
|
|
644
656
|
);
|
|
645
657
|
|
|
646
658
|
expect(std.out).toMatchInlineSnapshot(`
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
659
|
+
"
|
|
660
|
+
wrangler kv:key put <key> [value]
|
|
661
|
+
|
|
662
|
+
Writes a single key/value pair to the given namespace.
|
|
663
|
+
|
|
664
|
+
Positionals:
|
|
665
|
+
key The key to write to [string] [required]
|
|
666
|
+
value The value to write [string]
|
|
667
|
+
|
|
668
|
+
Flags:
|
|
669
|
+
-c, --config Path to .toml configuration file [string]
|
|
670
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
671
|
+
-h, --help Show help [boolean]
|
|
672
|
+
-v, --version Show version number [boolean]
|
|
673
|
+
|
|
674
|
+
Options:
|
|
675
|
+
--binding The binding of the namespace to write to [string]
|
|
676
|
+
--namespace-id The id of the namespace to write to [string]
|
|
677
|
+
--preview Interact with a preview namespace [boolean]
|
|
678
|
+
--ttl Time for which the entries should be visible [number]
|
|
679
|
+
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
680
|
+
--metadata Arbitrary JSON that is associated with a key [string]
|
|
681
|
+
--path Read value from the file at a given path [string]"
|
|
682
|
+
`);
|
|
671
683
|
expect(std.err).toMatchInlineSnapshot(`
|
|
672
|
-
|
|
684
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mExactly one of the arguments value and path is required[0m
|
|
673
685
|
|
|
674
|
-
|
|
675
|
-
|
|
686
|
+
"
|
|
687
|
+
`);
|
|
676
688
|
});
|
|
677
689
|
|
|
678
690
|
it("should error if both value and path is provided", async () => {
|
|
@@ -683,35 +695,35 @@ describe("wrangler", () => {
|
|
|
683
695
|
);
|
|
684
696
|
|
|
685
697
|
expect(std.out).toMatchInlineSnapshot(`
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
698
|
+
"
|
|
699
|
+
wrangler kv:key put <key> [value]
|
|
700
|
+
|
|
701
|
+
Writes a single key/value pair to the given namespace.
|
|
702
|
+
|
|
703
|
+
Positionals:
|
|
704
|
+
key The key to write to [string] [required]
|
|
705
|
+
value The value to write [string]
|
|
706
|
+
|
|
707
|
+
Flags:
|
|
708
|
+
-c, --config Path to .toml configuration file [string]
|
|
709
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
710
|
+
-h, --help Show help [boolean]
|
|
711
|
+
-v, --version Show version number [boolean]
|
|
712
|
+
|
|
713
|
+
Options:
|
|
714
|
+
--binding The binding of the namespace to write to [string]
|
|
715
|
+
--namespace-id The id of the namespace to write to [string]
|
|
716
|
+
--preview Interact with a preview namespace [boolean]
|
|
717
|
+
--ttl Time for which the entries should be visible [number]
|
|
718
|
+
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
719
|
+
--metadata Arbitrary JSON that is associated with a key [string]
|
|
720
|
+
--path Read value from the file at a given path [string]"
|
|
721
|
+
`);
|
|
710
722
|
expect(std.err).toMatchInlineSnapshot(`
|
|
711
|
-
|
|
723
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mArguments value and path are mutually exclusive[0m
|
|
712
724
|
|
|
713
|
-
|
|
714
|
-
|
|
725
|
+
"
|
|
726
|
+
`);
|
|
715
727
|
});
|
|
716
728
|
|
|
717
729
|
it("should error if a given binding name is not in the configured kv namespaces", async () => {
|
|
@@ -723,14 +735,14 @@ describe("wrangler", () => {
|
|
|
723
735
|
);
|
|
724
736
|
|
|
725
737
|
expect(std.out).toMatchInlineSnapshot(`
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
738
|
+
"
|
|
739
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
740
|
+
`);
|
|
729
741
|
expect(std.err).toMatchInlineSnapshot(`
|
|
730
|
-
|
|
742
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".[0m
|
|
731
743
|
|
|
732
|
-
|
|
733
|
-
|
|
744
|
+
"
|
|
745
|
+
`);
|
|
734
746
|
});
|
|
735
747
|
|
|
736
748
|
it("should error if a given binding has both preview and non-preview and --preview is not specified", async () => {
|
|
@@ -745,14 +757,14 @@ describe("wrangler", () => {
|
|
|
745
757
|
`"someBinding has both a namespace ID and a preview ID. Specify \\"--preview\\" or \\"--preview false\\" to avoid writing data to the wrong namespace."`
|
|
746
758
|
);
|
|
747
759
|
expect(std.out).toMatchInlineSnapshot(`
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
760
|
+
"
|
|
761
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
762
|
+
`);
|
|
751
763
|
expect(std.err).toMatchInlineSnapshot(`
|
|
752
|
-
|
|
764
|
+
"[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
|
|
753
765
|
|
|
754
|
-
|
|
755
|
-
|
|
766
|
+
"
|
|
767
|
+
`);
|
|
756
768
|
expect(requests.count).toEqual(0);
|
|
757
769
|
});
|
|
758
770
|
});
|
|
@@ -768,20 +780,20 @@ describe("wrangler", () => {
|
|
|
768
780
|
await runWrangler("kv:key list --namespace-id some-namespace-id");
|
|
769
781
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
770
782
|
expect(std.out).toMatchInlineSnapshot(`
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
783
|
+
"[
|
|
784
|
+
{
|
|
785
|
+
\\"name\\": \\"key-1\\"
|
|
786
|
+
},
|
|
787
|
+
{
|
|
788
|
+
\\"name\\": \\"key-2\\",
|
|
789
|
+
\\"expiration\\": 123456789
|
|
790
|
+
},
|
|
791
|
+
{
|
|
792
|
+
\\"name\\": \\"key-3\\",
|
|
793
|
+
\\"expiration_ttl\\": 666
|
|
794
|
+
}
|
|
795
|
+
]"
|
|
796
|
+
`);
|
|
785
797
|
});
|
|
786
798
|
|
|
787
799
|
it("should list the keys of a namespace specified by binding", async () => {
|
|
@@ -792,18 +804,18 @@ describe("wrangler", () => {
|
|
|
792
804
|
await runWrangler("kv:key list --binding someBinding");
|
|
793
805
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
794
806
|
expect(std.out).toMatchInlineSnapshot(`
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
+
"[
|
|
808
|
+
{
|
|
809
|
+
\\"name\\": \\"key-1\\"
|
|
810
|
+
},
|
|
811
|
+
{
|
|
812
|
+
\\"name\\": \\"key-2\\"
|
|
813
|
+
},
|
|
814
|
+
{
|
|
815
|
+
\\"name\\": \\"key-3\\"
|
|
816
|
+
}
|
|
817
|
+
]"
|
|
818
|
+
`);
|
|
807
819
|
});
|
|
808
820
|
|
|
809
821
|
it("should list the keys of a preview namespace specified by binding", async () => {
|
|
@@ -813,18 +825,18 @@ describe("wrangler", () => {
|
|
|
813
825
|
await runWrangler("kv:key list --binding someBinding --preview");
|
|
814
826
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
815
827
|
expect(std.out).toMatchInlineSnapshot(`
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
+
"[
|
|
829
|
+
{
|
|
830
|
+
\\"name\\": \\"key-1\\"
|
|
831
|
+
},
|
|
832
|
+
{
|
|
833
|
+
\\"name\\": \\"key-2\\"
|
|
834
|
+
},
|
|
835
|
+
{
|
|
836
|
+
\\"name\\": \\"key-3\\"
|
|
837
|
+
}
|
|
838
|
+
]"
|
|
839
|
+
`);
|
|
828
840
|
});
|
|
829
841
|
|
|
830
842
|
it("should list the keys of a namespace specified by binding, in a given environment", async () => {
|
|
@@ -836,18 +848,18 @@ describe("wrangler", () => {
|
|
|
836
848
|
);
|
|
837
849
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
838
850
|
expect(std.out).toMatchInlineSnapshot(`
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
+
"[
|
|
852
|
+
{
|
|
853
|
+
\\"name\\": \\"key-1\\"
|
|
854
|
+
},
|
|
855
|
+
{
|
|
856
|
+
\\"name\\": \\"key-2\\"
|
|
857
|
+
},
|
|
858
|
+
{
|
|
859
|
+
\\"name\\": \\"key-3\\"
|
|
860
|
+
}
|
|
861
|
+
]"
|
|
862
|
+
`);
|
|
851
863
|
});
|
|
852
864
|
|
|
853
865
|
it("should list the keys of a preview namespace specified by binding, in a given environment", async () => {
|
|
@@ -859,18 +871,18 @@ describe("wrangler", () => {
|
|
|
859
871
|
);
|
|
860
872
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
861
873
|
expect(std.out).toMatchInlineSnapshot(`
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
+
"[
|
|
875
|
+
{
|
|
876
|
+
\\"name\\": \\"key-1\\"
|
|
877
|
+
},
|
|
878
|
+
{
|
|
879
|
+
\\"name\\": \\"key-2\\"
|
|
880
|
+
},
|
|
881
|
+
{
|
|
882
|
+
\\"name\\": \\"key-3\\"
|
|
883
|
+
}
|
|
884
|
+
]"
|
|
885
|
+
`);
|
|
874
886
|
});
|
|
875
887
|
|
|
876
888
|
// We'll run the next test with variations on the cursor
|
|
@@ -911,22 +923,18 @@ describe("wrangler", () => {
|
|
|
911
923
|
`"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
|
|
912
924
|
);
|
|
913
925
|
expect(std.err).toMatchInlineSnapshot(`
|
|
914
|
-
|
|
926
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".[0m
|
|
915
927
|
|
|
916
|
-
|
|
917
|
-
|
|
928
|
+
"
|
|
929
|
+
`);
|
|
918
930
|
expect(std.out).toMatchInlineSnapshot(`
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
931
|
+
"
|
|
932
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
933
|
+
`);
|
|
922
934
|
});
|
|
923
935
|
});
|
|
924
936
|
|
|
925
937
|
describe("get", () => {
|
|
926
|
-
afterEach(() => {
|
|
927
|
-
unsetMockFetchKVGetValues();
|
|
928
|
-
});
|
|
929
|
-
|
|
930
938
|
it("should get a key in a given namespace specified by namespace-id", async () => {
|
|
931
939
|
setMockFetchKVGetValue(
|
|
932
940
|
"some-account-id",
|
|
@@ -934,7 +942,9 @@ describe("wrangler", () => {
|
|
|
934
942
|
"my-key",
|
|
935
943
|
"my-value"
|
|
936
944
|
);
|
|
945
|
+
|
|
937
946
|
await runWrangler("kv:key get my-key --namespace-id some-namespace-id");
|
|
947
|
+
|
|
938
948
|
expect(proc.write).toEqual(Buffer.from("my-value"));
|
|
939
949
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
940
950
|
});
|
|
@@ -951,13 +961,13 @@ describe("wrangler", () => {
|
|
|
951
961
|
);
|
|
952
962
|
expect(proc.write).not.toEqual(Buffer.from("my-value"));
|
|
953
963
|
expect(std).toMatchInlineSnapshot(`
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
964
|
+
Object {
|
|
965
|
+
"debug": "",
|
|
966
|
+
"err": "",
|
|
967
|
+
"out": "my-value",
|
|
968
|
+
"warn": "",
|
|
969
|
+
}
|
|
970
|
+
`);
|
|
961
971
|
});
|
|
962
972
|
|
|
963
973
|
it("should get a binary and decode as utf8 text, resulting in improper decoding", async () => {
|
|
@@ -1043,9 +1053,10 @@ describe("wrangler", () => {
|
|
|
1043
1053
|
setMockFetchKVGetValue(
|
|
1044
1054
|
"some-account-id",
|
|
1045
1055
|
"some-namespace-id",
|
|
1046
|
-
"%2Fmy%2Ckey",
|
|
1056
|
+
"%2Fmy%2Ckey", // expect the key /my,key to be encoded
|
|
1047
1057
|
"my-value"
|
|
1048
1058
|
);
|
|
1059
|
+
|
|
1049
1060
|
await runWrangler(
|
|
1050
1061
|
"kv:key get /my,key --namespace-id some-namespace-id"
|
|
1051
1062
|
);
|
|
@@ -1060,31 +1071,31 @@ describe("wrangler", () => {
|
|
|
1060
1071
|
`"Not enough non-option arguments: got 0, need at least 1"`
|
|
1061
1072
|
);
|
|
1062
1073
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1074
|
+
"
|
|
1075
|
+
wrangler kv:key get <key>
|
|
1076
|
+
|
|
1077
|
+
Reads a single value by key from the given namespace.
|
|
1078
|
+
|
|
1079
|
+
Positionals:
|
|
1080
|
+
key The key value to get. [string] [required]
|
|
1081
|
+
|
|
1082
|
+
Flags:
|
|
1083
|
+
-c, --config Path to .toml configuration file [string]
|
|
1084
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
1085
|
+
-h, --help Show help [boolean]
|
|
1086
|
+
-v, --version Show version number [boolean]
|
|
1087
|
+
|
|
1088
|
+
Options:
|
|
1089
|
+
--binding The name of the namespace to get from [string]
|
|
1090
|
+
--namespace-id The id of the namespace to get from [string]
|
|
1091
|
+
--preview Interact with a preview namespace [boolean] [default: false]
|
|
1092
|
+
--text Decode the returned value as a utf8 string [boolean] [default: false]"
|
|
1093
|
+
`);
|
|
1083
1094
|
expect(std.err).toMatchInlineSnapshot(`
|
|
1084
|
-
|
|
1095
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot enough non-option arguments: got 0, need at least 1[0m
|
|
1085
1096
|
|
|
1086
|
-
|
|
1087
|
-
|
|
1097
|
+
"
|
|
1098
|
+
`);
|
|
1088
1099
|
});
|
|
1089
1100
|
|
|
1090
1101
|
it("should error if no binding nor namespace is provided", async () => {
|
|
@@ -1094,31 +1105,31 @@ describe("wrangler", () => {
|
|
|
1094
1105
|
`"Exactly one of the arguments binding and namespace-id is required"`
|
|
1095
1106
|
);
|
|
1096
1107
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1108
|
+
"
|
|
1109
|
+
wrangler kv:key get <key>
|
|
1110
|
+
|
|
1111
|
+
Reads a single value by key from the given namespace.
|
|
1112
|
+
|
|
1113
|
+
Positionals:
|
|
1114
|
+
key The key value to get. [string] [required]
|
|
1115
|
+
|
|
1116
|
+
Flags:
|
|
1117
|
+
-c, --config Path to .toml configuration file [string]
|
|
1118
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
1119
|
+
-h, --help Show help [boolean]
|
|
1120
|
+
-v, --version Show version number [boolean]
|
|
1121
|
+
|
|
1122
|
+
Options:
|
|
1123
|
+
--binding The name of the namespace to get from [string]
|
|
1124
|
+
--namespace-id The id of the namespace to get from [string]
|
|
1125
|
+
--preview Interact with a preview namespace [boolean] [default: false]
|
|
1126
|
+
--text Decode the returned value as a utf8 string [boolean] [default: false]"
|
|
1127
|
+
`);
|
|
1117
1128
|
expect(std.err).toMatchInlineSnapshot(`
|
|
1118
|
-
|
|
1129
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mExactly one of the arguments binding and namespace-id is required[0m
|
|
1119
1130
|
|
|
1120
|
-
|
|
1121
|
-
|
|
1131
|
+
"
|
|
1132
|
+
`);
|
|
1122
1133
|
});
|
|
1123
1134
|
|
|
1124
1135
|
it("should error if both binding and namespace is provided", async () => {
|
|
@@ -1129,31 +1140,31 @@ describe("wrangler", () => {
|
|
|
1129
1140
|
);
|
|
1130
1141
|
|
|
1131
1142
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1143
|
+
"
|
|
1144
|
+
wrangler kv:key get <key>
|
|
1145
|
+
|
|
1146
|
+
Reads a single value by key from the given namespace.
|
|
1147
|
+
|
|
1148
|
+
Positionals:
|
|
1149
|
+
key The key value to get. [string] [required]
|
|
1150
|
+
|
|
1151
|
+
Flags:
|
|
1152
|
+
-c, --config Path to .toml configuration file [string]
|
|
1153
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
1154
|
+
-h, --help Show help [boolean]
|
|
1155
|
+
-v, --version Show version number [boolean]
|
|
1156
|
+
|
|
1157
|
+
Options:
|
|
1158
|
+
--binding The name of the namespace to get from [string]
|
|
1159
|
+
--namespace-id The id of the namespace to get from [string]
|
|
1160
|
+
--preview Interact with a preview namespace [boolean] [default: false]
|
|
1161
|
+
--text Decode the returned value as a utf8 string [boolean] [default: false]"
|
|
1162
|
+
`);
|
|
1152
1163
|
expect(std.err).toMatchInlineSnapshot(`
|
|
1153
|
-
|
|
1164
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mArguments binding and namespace-id are mutually exclusive[0m
|
|
1154
1165
|
|
|
1155
|
-
|
|
1156
|
-
|
|
1166
|
+
"
|
|
1167
|
+
`);
|
|
1157
1168
|
});
|
|
1158
1169
|
|
|
1159
1170
|
it("should error if a given binding name is not in the configured kv namespaces", async () => {
|
|
@@ -1164,14 +1175,14 @@ describe("wrangler", () => {
|
|
|
1164
1175
|
`"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
|
|
1165
1176
|
);
|
|
1166
1177
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1178
|
+
"
|
|
1179
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
1180
|
+
`);
|
|
1170
1181
|
expect(std.err).toMatchInlineSnapshot(`
|
|
1171
|
-
|
|
1182
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".[0m
|
|
1172
1183
|
|
|
1173
|
-
|
|
1174
|
-
|
|
1184
|
+
"
|
|
1185
|
+
`);
|
|
1175
1186
|
});
|
|
1176
1187
|
|
|
1177
1188
|
describe("non-interactive", () => {
|
|
@@ -1211,14 +1222,21 @@ describe("wrangler", () => {
|
|
|
1211
1222
|
});
|
|
1212
1223
|
|
|
1213
1224
|
it("should recommend using a configuration if unable to fetch memberships", async () => {
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1225
|
+
msw.use(
|
|
1226
|
+
rest.get("*/memberships", (req, res, ctx) => {
|
|
1227
|
+
return res.once(
|
|
1228
|
+
ctx.status(200),
|
|
1229
|
+
ctx.json(
|
|
1230
|
+
createFetchResult(null, false, [
|
|
1231
|
+
{
|
|
1232
|
+
code: 9109,
|
|
1233
|
+
message: "Uauthorized to access requested resource",
|
|
1234
|
+
},
|
|
1235
|
+
])
|
|
1236
|
+
)
|
|
1237
|
+
);
|
|
1238
|
+
})
|
|
1239
|
+
);
|
|
1222
1240
|
await expect(runWrangler("kv:key get key --namespace-id=xxxx"))
|
|
1223
1241
|
.rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
1224
1242
|
"Failed to automatically retrieve account IDs for the logged in user.
|
|
@@ -1250,16 +1268,20 @@ describe("wrangler", () => {
|
|
|
1250
1268
|
expectedKey: string
|
|
1251
1269
|
) {
|
|
1252
1270
|
const requests = { count: 0 };
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1271
|
+
msw.use(
|
|
1272
|
+
rest.delete(
|
|
1273
|
+
"*/accounts/:accountId/storage/kv/namespaces/:namespaceId/values/:key",
|
|
1274
|
+
(req, res, ctx) => {
|
|
1275
|
+
requests.count++;
|
|
1276
|
+
expect(req.params.accountId).toEqual("some-account-id");
|
|
1277
|
+
expect(req.params.namespaceId).toEqual(expectedNamespaceId);
|
|
1278
|
+
expect(req.params.key).toEqual(expectedKey);
|
|
1279
|
+
return res.once(
|
|
1280
|
+
ctx.status(200),
|
|
1281
|
+
ctx.json(createFetchResult(null))
|
|
1282
|
+
);
|
|
1283
|
+
}
|
|
1284
|
+
)
|
|
1263
1285
|
);
|
|
1264
1286
|
return requests;
|
|
1265
1287
|
}
|
|
@@ -1273,8 +1295,9 @@ describe("wrangler", () => {
|
|
|
1273
1295
|
});
|
|
1274
1296
|
|
|
1275
1297
|
it("should encode the key in the api request to delete a value", async () => {
|
|
1276
|
-
const requests = mockDeleteRequest("voyager", "
|
|
1298
|
+
const requests = mockDeleteRequest("voyager", "/NCC-74656");
|
|
1277
1299
|
await runWrangler(`kv:key delete --namespace-id voyager /NCC-74656`);
|
|
1300
|
+
|
|
1278
1301
|
expect(requests.count).toEqual(1);
|
|
1279
1302
|
expect(std.out).toMatchInlineSnapshot(
|
|
1280
1303
|
`"Deleting the key \\"/NCC-74656\\" on namespace voyager."`
|
|
@@ -1309,10 +1332,10 @@ describe("wrangler", () => {
|
|
|
1309
1332
|
);
|
|
1310
1333
|
|
|
1311
1334
|
expect(std.err).toMatchInlineSnapshot(`
|
|
1312
|
-
|
|
1335
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".[0m
|
|
1313
1336
|
|
|
1314
|
-
|
|
1315
|
-
|
|
1337
|
+
"
|
|
1338
|
+
`);
|
|
1316
1339
|
});
|
|
1317
1340
|
|
|
1318
1341
|
it("should delete a key in a namespace specified by binding name in a given environment", async () => {
|
|
@@ -1346,21 +1369,22 @@ describe("wrangler", () => {
|
|
|
1346
1369
|
expectedKeyValues: KeyValue[]
|
|
1347
1370
|
) {
|
|
1348
1371
|
const requests = { count: 0 };
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1372
|
+
msw.use(
|
|
1373
|
+
rest.put(
|
|
1374
|
+
"*/accounts/:accountId/storage/kv/namespaces/:namespaceId/bulk",
|
|
1375
|
+
async (req, res, ctx) => {
|
|
1376
|
+
requests.count++;
|
|
1377
|
+
expect(req.params.accountId).toEqual("some-account-id");
|
|
1378
|
+
expect(req.params.namespaceId).toEqual(expectedNamespaceId);
|
|
1379
|
+
expect(await req.json()).toEqual(
|
|
1380
|
+
expectedKeyValues.slice(
|
|
1381
|
+
(requests.count - 1) * 5000,
|
|
1382
|
+
requests.count * 5000
|
|
1383
|
+
)
|
|
1384
|
+
);
|
|
1385
|
+
return res(ctx.status(200), ctx.json(createFetchResult(null)));
|
|
1386
|
+
}
|
|
1387
|
+
)
|
|
1364
1388
|
);
|
|
1365
1389
|
return requests;
|
|
1366
1390
|
}
|
|
@@ -1395,12 +1419,12 @@ describe("wrangler", () => {
|
|
|
1395
1419
|
);
|
|
1396
1420
|
expect(requests.count).toEqual(3);
|
|
1397
1421
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1422
|
+
"Uploaded 0% (0 out of 12,000)
|
|
1423
|
+
Uploaded 41% (5,000 out of 12,000)
|
|
1424
|
+
Uploaded 83% (10,000 out of 12,000)
|
|
1425
|
+
Uploaded 100% (12,000 out of 12,000)
|
|
1426
|
+
Success!"
|
|
1427
|
+
`);
|
|
1404
1428
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1405
1429
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1406
1430
|
});
|
|
@@ -1415,9 +1439,9 @@ describe("wrangler", () => {
|
|
|
1415
1439
|
Expected an array of key-value objects but got type \\"object\\"."
|
|
1416
1440
|
`);
|
|
1417
1441
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1442
|
+
"
|
|
1443
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
1444
|
+
`);
|
|
1421
1445
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1422
1446
|
});
|
|
1423
1447
|
|
|
@@ -1477,16 +1501,16 @@ describe("wrangler", () => {
|
|
|
1477
1501
|
`);
|
|
1478
1502
|
|
|
1479
1503
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1504
|
+
"
|
|
1505
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
1506
|
+
`);
|
|
1483
1507
|
expect(std.warn).toMatchInlineSnapshot(`
|
|
1484
|
-
|
|
1508
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mUnexpected key-value properties in \\"keys.json\\".[0m
|
|
1485
1509
|
|
|
1486
|
-
|
|
1510
|
+
The item at index 5 contains unexpected properties: [\\"invalid\\"].
|
|
1487
1511
|
|
|
1488
|
-
|
|
1489
|
-
|
|
1512
|
+
"
|
|
1513
|
+
`);
|
|
1490
1514
|
});
|
|
1491
1515
|
});
|
|
1492
1516
|
|
|
@@ -1496,24 +1520,25 @@ describe("wrangler", () => {
|
|
|
1496
1520
|
expectedKeys: string[]
|
|
1497
1521
|
) {
|
|
1498
1522
|
const requests = { count: 0 };
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1523
|
+
msw.use(
|
|
1524
|
+
rest.delete(
|
|
1525
|
+
"*/accounts/:accountId/storage/kv/namespaces/:namespaceId/bulk",
|
|
1526
|
+
async (req, res, ctx) => {
|
|
1527
|
+
requests.count++;
|
|
1528
|
+
expect(req.params.accountId).toEqual("some-account-id");
|
|
1529
|
+
expect(req.params.namespaceId).toEqual(expectedNamespaceId);
|
|
1530
|
+
expect(req.headers.get("Content-Type")).toEqual(
|
|
1531
|
+
"application/json"
|
|
1532
|
+
);
|
|
1533
|
+
expect(await req.json()).toEqual(
|
|
1534
|
+
expectedKeys.slice(
|
|
1535
|
+
(requests.count - 1) * 5000,
|
|
1536
|
+
requests.count * 5000
|
|
1537
|
+
)
|
|
1538
|
+
);
|
|
1539
|
+
return res(ctx.status(200), ctx.json(createFetchResult(null)));
|
|
1540
|
+
}
|
|
1541
|
+
)
|
|
1517
1542
|
);
|
|
1518
1543
|
return requests;
|
|
1519
1544
|
}
|
|
@@ -1548,12 +1573,12 @@ describe("wrangler", () => {
|
|
|
1548
1573
|
);
|
|
1549
1574
|
expect(requests.count).toEqual(3);
|
|
1550
1575
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1576
|
+
"Deleted 0% (0 out of 12,000)
|
|
1577
|
+
Deleted 41% (5,000 out of 12,000)
|
|
1578
|
+
Deleted 83% (10,000 out of 12,000)
|
|
1579
|
+
Deleted 100% (12,000 out of 12,000)
|
|
1580
|
+
Success!"
|
|
1581
|
+
`);
|
|
1557
1582
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1558
1583
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1559
1584
|
});
|
|
@@ -1618,9 +1643,9 @@ describe("wrangler", () => {
|
|
|
1618
1643
|
12354"
|
|
1619
1644
|
`);
|
|
1620
1645
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1646
|
+
"
|
|
1647
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
1648
|
+
`);
|
|
1624
1649
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1625
1650
|
});
|
|
1626
1651
|
|
|
@@ -1643,9 +1668,9 @@ describe("wrangler", () => {
|
|
|
1643
1668
|
The item at index 3 is type: \\"object\\" - null"
|
|
1644
1669
|
`);
|
|
1645
1670
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1671
|
+
"
|
|
1672
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
1673
|
+
`);
|
|
1649
1674
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1650
1675
|
});
|
|
1651
1676
|
});
|
|
@@ -1669,3 +1694,93 @@ function writeWranglerConfig() {
|
|
|
1669
1694
|
"utf-8"
|
|
1670
1695
|
);
|
|
1671
1696
|
}
|
|
1697
|
+
|
|
1698
|
+
function setMockFetchKVGetValue(
|
|
1699
|
+
accountId: string,
|
|
1700
|
+
namespaceId: string,
|
|
1701
|
+
key: string,
|
|
1702
|
+
value: string | Buffer
|
|
1703
|
+
) {
|
|
1704
|
+
msw.use(
|
|
1705
|
+
rest.get(
|
|
1706
|
+
"*/accounts/:accountId/storage/kv/namespaces/:namespaceId/values/:key",
|
|
1707
|
+
(req, res, ctx) => {
|
|
1708
|
+
console.dir(req.params);
|
|
1709
|
+
expect(req.params.accountId).toEqual(accountId);
|
|
1710
|
+
expect(req.params.namespaceId).toEqual(namespaceId);
|
|
1711
|
+
// Getting the key from params decodes it so we need to grab the encoded key from the URL
|
|
1712
|
+
expect(req.url.toString().split("/").pop()).toBe(key);
|
|
1713
|
+
|
|
1714
|
+
return res.once(ctx.status(200), ctx.body(value));
|
|
1715
|
+
}
|
|
1716
|
+
)
|
|
1717
|
+
);
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
function createFetchResult(
|
|
1721
|
+
result: unknown,
|
|
1722
|
+
success = true,
|
|
1723
|
+
errors: { code: number; message: string }[] = []
|
|
1724
|
+
) {
|
|
1725
|
+
return {
|
|
1726
|
+
success,
|
|
1727
|
+
errors,
|
|
1728
|
+
messages: [],
|
|
1729
|
+
result,
|
|
1730
|
+
};
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
function mockGetMemberships(
|
|
1734
|
+
accounts: { id: string; account: { id: string; name: string } }[]
|
|
1735
|
+
) {
|
|
1736
|
+
msw.use(
|
|
1737
|
+
rest.get("*/memberships", (req, res, ctx) => {
|
|
1738
|
+
return res.once(ctx.json(createFetchResult(accounts)));
|
|
1739
|
+
})
|
|
1740
|
+
);
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
function mockKeyListRequest(
|
|
1744
|
+
expectedNamespaceId: string,
|
|
1745
|
+
expectedKeys: NamespaceKeyInfo[],
|
|
1746
|
+
keysPerRequest = 1000,
|
|
1747
|
+
blankCursorValue: "" | undefined | null = undefined
|
|
1748
|
+
) {
|
|
1749
|
+
const requests = { count: 0 };
|
|
1750
|
+
// See https://api.cloudflare.com/#workers-kv-namespace-list-a-namespace-s-keys
|
|
1751
|
+
msw.use(
|
|
1752
|
+
rest.get(
|
|
1753
|
+
"*/accounts/:accountId/storage/kv/namespaces/:namespaceId/keys",
|
|
1754
|
+
(req, res, ctx) => {
|
|
1755
|
+
requests.count++;
|
|
1756
|
+
let result;
|
|
1757
|
+
let cursor;
|
|
1758
|
+
|
|
1759
|
+
expect(req.params.accountId).toEqual("some-account-id");
|
|
1760
|
+
expect(req.params.namespaceId).toEqual(expectedNamespaceId);
|
|
1761
|
+
|
|
1762
|
+
if (expectedKeys.length <= keysPerRequest) {
|
|
1763
|
+
result = expectedKeys;
|
|
1764
|
+
} else {
|
|
1765
|
+
const start =
|
|
1766
|
+
parseInt(req.url.searchParams.get("cursor") ?? "0") || 0;
|
|
1767
|
+
const end = start + keysPerRequest;
|
|
1768
|
+
cursor = end < expectedKeys.length ? end : blankCursorValue;
|
|
1769
|
+
result = expectedKeys.slice(start, end);
|
|
1770
|
+
}
|
|
1771
|
+
return res(
|
|
1772
|
+
ctx.json({
|
|
1773
|
+
success: true,
|
|
1774
|
+
errors: [],
|
|
1775
|
+
messages: [],
|
|
1776
|
+
result,
|
|
1777
|
+
result_info: {
|
|
1778
|
+
cursor,
|
|
1779
|
+
},
|
|
1780
|
+
})
|
|
1781
|
+
);
|
|
1782
|
+
}
|
|
1783
|
+
)
|
|
1784
|
+
);
|
|
1785
|
+
return requests;
|
|
1786
|
+
}
|