wrangler 2.8.0 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/__tests__/d1/d1.test.ts +24 -62
- package/src/__tests__/d1/migrate.test.ts +48 -0
- package/src/__tests__/deployments.test.ts +4 -4
- package/src/__tests__/dev.test.tsx +5 -4
- package/src/__tests__/helpers/msw/handlers/deployments.ts +10 -18
- package/src/__tests__/helpers/msw/handlers/namespaces.ts +18 -41
- package/src/__tests__/helpers/msw/handlers/r2.ts +14 -34
- package/src/__tests__/helpers/msw/handlers/script.ts +9 -28
- package/src/__tests__/helpers/msw/handlers/user.ts +13 -24
- package/src/__tests__/helpers/msw/handlers/zones.ts +6 -8
- package/src/__tests__/index.test.ts +35 -28
- package/src/__tests__/kv.test.ts +55 -44
- package/src/__tests__/pages.test.ts +61 -57
- package/src/__tests__/parse.test.ts +106 -0
- package/src/__tests__/publish.test.ts +126 -0
- package/src/__tests__/pubsub.test.ts +15 -12
- package/src/__tests__/queues.test.ts +35 -28
- package/src/__tests__/r2.test.ts +36 -55
- package/src/__tests__/tail.test.ts +6 -18
- package/src/__tests__/tsconfig.tsbuildinfo +1 -1
- package/src/__tests__/user.test.ts +0 -1
- package/src/__tests__/whoami.test.tsx +6 -17
- package/src/__tests__/worker-namespace.test.ts +81 -68
- package/src/api/dev.ts +80 -11
- package/src/api/index.ts +1 -0
- package/src/api/pages/index.ts +5 -0
- package/src/api/pages/publish.tsx +324 -0
- package/src/bundle.ts +63 -11
- package/src/cli.ts +2 -2
- package/src/config/config.ts +7 -0
- package/src/config/environment.ts +12 -10
- package/src/config/index.ts +24 -20
- package/src/d1/backups.tsx +20 -24
- package/src/d1/create.tsx +6 -5
- package/src/d1/delete.ts +7 -10
- package/src/d1/execute.tsx +82 -84
- package/src/d1/index.ts +5 -6
- package/src/d1/list.tsx +21 -9
- package/src/d1/migrations/apply.tsx +7 -5
- package/src/d1/migrations/create.tsx +7 -10
- package/src/d1/migrations/list.tsx +7 -5
- package/src/d1/migrations/options.ts +2 -2
- package/src/d1/options.ts +3 -3
- package/src/d1/utils.ts +1 -1
- package/src/delete.ts +5 -8
- package/src/deployments.ts +16 -6
- package/src/deprecated/index.ts +7 -8
- package/src/dev/local.tsx +1 -10
- package/src/dev/start-server.ts +5 -10
- package/src/dev/use-esbuild.ts +1 -0
- package/src/dev.tsx +42 -80
- package/src/dispatch-namespace.ts +20 -16
- package/src/docs/index.ts +7 -8
- package/src/entry.ts +1 -2
- package/src/generate/index.ts +5 -7
- package/src/index.ts +23 -22
- package/src/init.ts +5 -7
- package/src/kv/index.ts +15 -17
- package/src/metrics/send-event.ts +2 -1
- package/src/pages/build.ts +9 -127
- package/src/pages/buildFunctions.ts +129 -0
- package/src/pages/deployment-tails.ts +7 -10
- package/src/pages/deployments.tsx +6 -4
- package/src/pages/dev.ts +27 -19
- package/src/pages/functions/buildPlugin.ts +1 -0
- package/src/pages/functions/buildWorker.ts +8 -2
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
- package/src/pages/functions.ts +8 -4
- package/src/pages/index.ts +3 -3
- package/src/pages/projects.tsx +7 -12
- package/src/pages/publish.tsx +15 -239
- package/src/pages/types.ts +5 -0
- package/src/pages/upload.tsx +6 -4
- package/src/parse.ts +23 -1
- package/src/publish/index.ts +19 -15
- package/src/publish/publish.ts +3 -2
- package/src/pubsub/pubsub-commands.ts +18 -19
- package/src/queues/cli/commands/consumer/add.ts +18 -24
- package/src/queues/cli/commands/consumer/index.ts +3 -6
- package/src/queues/cli/commands/consumer/remove.ts +11 -18
- package/src/queues/cli/commands/create.ts +8 -8
- package/src/queues/cli/commands/delete.ts +8 -8
- package/src/queues/cli/commands/index.ts +3 -4
- package/src/queues/cli/commands/list.ts +8 -8
- package/src/r2/index.ts +28 -28
- package/src/secret/index.ts +9 -14
- package/src/tail/index.ts +6 -8
- package/src/yargs-types.ts +18 -5
- package/templates/checked-fetch.js +9 -1
- package/templates/d1-beta-facade.js +1 -1
- package/templates/middleware/loader-modules.ts +2 -0
- package/templates/tsconfig.tsbuildinfo +1 -1
- package/wrangler-dist/cli.d.ts +132 -10
- package/wrangler-dist/cli.js +2474 -1635
package/package.json
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { cwd } from "process";
|
|
2
1
|
import { mockConsoleMethods } from "../helpers/mock-console";
|
|
3
|
-
import { useMockIsTTY } from "../helpers/mock-istty";
|
|
4
2
|
import { runInTempDir } from "../helpers/run-in-tmp";
|
|
5
3
|
import { runWrangler } from "../helpers/run-wrangler";
|
|
6
|
-
import writeWranglerToml from "../helpers/write-wrangler-toml";
|
|
7
4
|
|
|
8
5
|
function endEventLoop() {
|
|
9
6
|
return new Promise((resolve) => setImmediate(resolve));
|
|
@@ -12,7 +9,6 @@ function endEventLoop() {
|
|
|
12
9
|
describe("d1", () => {
|
|
13
10
|
const std = mockConsoleMethods();
|
|
14
11
|
runInTempDir();
|
|
15
|
-
const { setIsTTY } = useMockIsTTY();
|
|
16
12
|
|
|
17
13
|
it("should show help when no argument is passed", async () => {
|
|
18
14
|
await runWrangler("d1");
|
|
@@ -32,15 +28,18 @@ describe("d1", () => {
|
|
|
32
28
|
wrangler d1 migrations Interact with D1 Migrations
|
|
33
29
|
|
|
34
30
|
Flags:
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
31
|
+
-j, --experimental-json-config Experimental: Support wrangler.json [boolean]
|
|
32
|
+
-c, --config Path to .toml configuration file [string]
|
|
33
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
34
|
+
-h, --help Show help [boolean]
|
|
35
|
+
-v, --version Show version number [boolean]
|
|
36
|
+
|
|
37
|
+
--------------------
|
|
38
|
+
🚧 D1 is currently in open alpha and is not recommended for production data and traffic
|
|
39
|
+
🚧 Please report any bugs to https://github.com/cloudflare/wrangler2/issues/new/choose
|
|
40
|
+
🚧 To request features, visit https://community.cloudflare.com/c/developers/d1
|
|
41
|
+
🚧 To give feedback, visit https://discord.gg/cloudflaredev
|
|
42
|
+
--------------------"
|
|
44
43
|
`);
|
|
45
44
|
});
|
|
46
45
|
|
|
@@ -69,55 +68,18 @@ describe("d1", () => {
|
|
|
69
68
|
wrangler d1 migrations Interact with D1 Migrations
|
|
70
69
|
|
|
71
70
|
Flags:
|
|
72
|
-
-
|
|
73
|
-
-
|
|
74
|
-
-
|
|
75
|
-
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
71
|
+
-j, --experimental-json-config Experimental: Support wrangler.json [boolean]
|
|
72
|
+
-c, --config Path to .toml configuration file [string]
|
|
73
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
74
|
+
-h, --help Show help [boolean]
|
|
75
|
+
-v, --version Show version number [boolean]
|
|
76
|
+
|
|
77
|
+
--------------------
|
|
78
|
+
🚧 D1 is currently in open alpha and is not recommended for production data and traffic
|
|
79
|
+
🚧 Please report any bugs to https://github.com/cloudflare/wrangler2/issues/new/choose
|
|
80
|
+
🚧 To request features, visit https://community.cloudflare.com/c/developers/d1
|
|
81
|
+
🚧 To give feedback, visit https://discord.gg/cloudflaredev
|
|
82
|
+
--------------------"
|
|
81
83
|
`);
|
|
82
84
|
});
|
|
83
|
-
|
|
84
|
-
describe("migrate", () => {
|
|
85
|
-
describe("apply", () => {
|
|
86
|
-
it("should not attempt to login in local mode", async () => {
|
|
87
|
-
setIsTTY(false);
|
|
88
|
-
writeWranglerToml({
|
|
89
|
-
d1_databases: [
|
|
90
|
-
{ binding: "DATABASE", database_name: "db", database_id: "xxxx" },
|
|
91
|
-
],
|
|
92
|
-
});
|
|
93
|
-
// If we get to the point where we are checking for migrations then we have not been asked to log in.
|
|
94
|
-
await expect(
|
|
95
|
-
runWrangler("d1 migrations apply --local DATABASE")
|
|
96
|
-
).rejects.toThrowError(
|
|
97
|
-
`No migrations present at ${cwd().replaceAll("\\", "/")}/migrations.`
|
|
98
|
-
);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it("should try to read D1 config from wrangler.toml", async () => {
|
|
102
|
-
setIsTTY(false);
|
|
103
|
-
writeWranglerToml();
|
|
104
|
-
await expect(
|
|
105
|
-
runWrangler("d1 migrations apply DATABASE")
|
|
106
|
-
).rejects.toThrowError(
|
|
107
|
-
"Can't find a DB with name/binding 'DATABASE' in local config. Check info in wrangler.toml..."
|
|
108
|
-
);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("should not try to read wrangler.toml in local mode", async () => {
|
|
112
|
-
setIsTTY(false);
|
|
113
|
-
writeWranglerToml();
|
|
114
|
-
// If we get to the point where we are checking for migrations then we have not checked wrangler.toml.
|
|
115
|
-
await expect(
|
|
116
|
-
runWrangler("d1 migrations apply --local DATABASE")
|
|
117
|
-
).rejects.toThrowError(
|
|
118
|
-
`No migrations present at ${cwd().replaceAll("\\", "/")}/migrations.`
|
|
119
|
-
);
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
85
|
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { cwd } from "process";
|
|
2
|
+
import { useMockIsTTY } from "../helpers/mock-istty";
|
|
3
|
+
import { runInTempDir } from "../helpers/run-in-tmp";
|
|
4
|
+
import { runWrangler } from "../helpers/run-wrangler";
|
|
5
|
+
import writeWranglerToml from "../helpers/write-wrangler-toml";
|
|
6
|
+
|
|
7
|
+
describe("migrate", () => {
|
|
8
|
+
runInTempDir();
|
|
9
|
+
const { setIsTTY } = useMockIsTTY();
|
|
10
|
+
|
|
11
|
+
describe("apply", () => {
|
|
12
|
+
it("should not attempt to login in local mode", async () => {
|
|
13
|
+
setIsTTY(false);
|
|
14
|
+
writeWranglerToml({
|
|
15
|
+
d1_databases: [
|
|
16
|
+
{ binding: "DATABASE", database_name: "db", database_id: "xxxx" },
|
|
17
|
+
],
|
|
18
|
+
});
|
|
19
|
+
// If we get to the point where we are checking for migrations then we have not been asked to log in.
|
|
20
|
+
await expect(
|
|
21
|
+
runWrangler("d1 migrations apply --local DATABASE")
|
|
22
|
+
).rejects.toThrowError(
|
|
23
|
+
`No migrations present at ${cwd().replaceAll("\\", "/")}/migrations.`
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("should try to read D1 config from wrangler.toml", async () => {
|
|
28
|
+
setIsTTY(false);
|
|
29
|
+
writeWranglerToml();
|
|
30
|
+
await expect(
|
|
31
|
+
runWrangler("d1 migrations apply DATABASE")
|
|
32
|
+
).rejects.toThrowError(
|
|
33
|
+
"Can't find a DB with name/binding 'DATABASE' in local config. Check info in wrangler.toml..."
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("should not try to read wrangler.toml in local mode", async () => {
|
|
38
|
+
setIsTTY(false);
|
|
39
|
+
writeWranglerToml();
|
|
40
|
+
// If we get to the point where we are checking for migrations then we have not checked wrangler.toml.
|
|
41
|
+
await expect(
|
|
42
|
+
runWrangler("d1 migrations apply --local DATABASE")
|
|
43
|
+
).rejects.toThrowError(
|
|
44
|
+
`No migrations present at ${cwd().replaceAll("\\", "/")}/migrations.`
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -68,12 +68,12 @@ describe("deployments", () => {
|
|
|
68
68
|
Deployment ID: Galaxy-Class
|
|
69
69
|
Created on: 2021-01-01T00:00:00.000000Z
|
|
70
70
|
Author: Jean-Luc-Picard@federation.org
|
|
71
|
-
Source: Wrangler
|
|
71
|
+
Source: 🤠 Wrangler
|
|
72
72
|
|
|
73
73
|
Deployment ID: Intrepid-Class
|
|
74
74
|
Created on: 2021-02-02T00:00:00.000000Z
|
|
75
75
|
Author: Kathryn-Janeway@federation.org
|
|
76
|
-
Source: Wrangler
|
|
76
|
+
Source: 🤠 Wrangler
|
|
77
77
|
🟩 Active"
|
|
78
78
|
`);
|
|
79
79
|
});
|
|
@@ -87,12 +87,12 @@ describe("deployments", () => {
|
|
|
87
87
|
Deployment ID: Galaxy-Class
|
|
88
88
|
Created on: 2021-01-01T00:00:00.000000Z
|
|
89
89
|
Author: Jean-Luc-Picard@federation.org
|
|
90
|
-
Source: Wrangler
|
|
90
|
+
Source: 🤠 Wrangler
|
|
91
91
|
|
|
92
92
|
Deployment ID: Intrepid-Class
|
|
93
93
|
Created on: 2021-02-02T00:00:00.000000Z
|
|
94
94
|
Author: Kathryn-Janeway@federation.org
|
|
95
|
-
Source: Wrangler
|
|
95
|
+
Source: 🤠 Wrangler
|
|
96
96
|
🟩 Active"
|
|
97
97
|
`);
|
|
98
98
|
});
|
|
@@ -1218,10 +1218,11 @@ describe("wrangler dev", () => {
|
|
|
1218
1218
|
script The path to an entry point for your worker [string]
|
|
1219
1219
|
|
|
1220
1220
|
Flags:
|
|
1221
|
-
-
|
|
1222
|
-
-
|
|
1223
|
-
-
|
|
1224
|
-
-
|
|
1221
|
+
-j, --experimental-json-config Experimental: Support wrangler.json [boolean]
|
|
1222
|
+
-c, --config Path to .toml configuration file [string]
|
|
1223
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
1224
|
+
-h, --help Show help [boolean]
|
|
1225
|
+
-v, --version Show version number [boolean]
|
|
1225
1226
|
|
|
1226
1227
|
Options:
|
|
1227
1228
|
--name Name of the worker [string]
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
import { rest } from "msw";
|
|
2
|
-
|
|
3
|
-
import type { DeploymentListRes } from "../../../../deployments";
|
|
2
|
+
import { createFetchResult } from "../index";
|
|
4
3
|
|
|
5
4
|
export const mswSuccessDeployments = [
|
|
6
5
|
rest.get(
|
|
7
6
|
"*/accounts/:accountId/workers/deployments/by-script/:scriptTag",
|
|
8
7
|
(_, response, context) =>
|
|
9
8
|
response.once(
|
|
10
|
-
context.
|
|
11
|
-
|
|
12
|
-
success: true,
|
|
13
|
-
errors: [],
|
|
14
|
-
messages: [],
|
|
15
|
-
result: {
|
|
9
|
+
context.json(
|
|
10
|
+
createFetchResult({
|
|
16
11
|
latest: {
|
|
17
12
|
id: "Galaxy-Class",
|
|
18
13
|
number: "1701-E",
|
|
@@ -52,8 +47,8 @@ export const mswSuccessDeployments = [
|
|
|
52
47
|
},
|
|
53
48
|
},
|
|
54
49
|
],
|
|
55
|
-
}
|
|
56
|
-
|
|
50
|
+
})
|
|
51
|
+
)
|
|
57
52
|
)
|
|
58
53
|
),
|
|
59
54
|
];
|
|
@@ -61,16 +56,13 @@ export const mswSuccessDeployments = [
|
|
|
61
56
|
export const mswSuccessLastDeployment = [
|
|
62
57
|
rest.get(
|
|
63
58
|
"*/accounts/:accountId/workers/services/:scriptName",
|
|
64
|
-
(
|
|
59
|
+
(_, res, ctx) => {
|
|
65
60
|
return res.once(
|
|
66
|
-
ctx.json(
|
|
67
|
-
|
|
68
|
-
messages: [],
|
|
69
|
-
errors: [],
|
|
70
|
-
result: {
|
|
61
|
+
ctx.json(
|
|
62
|
+
createFetchResult({
|
|
71
63
|
default_environment: { script: { last_deployed_from: "wrangler" } },
|
|
72
|
-
}
|
|
73
|
-
|
|
64
|
+
})
|
|
65
|
+
)
|
|
74
66
|
);
|
|
75
67
|
}
|
|
76
68
|
),
|
|
@@ -1,59 +1,44 @@
|
|
|
1
1
|
import { rest } from "msw";
|
|
2
|
+
import { createFetchResult } from "../index";
|
|
2
3
|
|
|
3
4
|
export const mswSuccessNamespacesHandlers = [
|
|
4
5
|
rest.post(
|
|
5
6
|
"*/accounts/:accountId/workers/dispatch/namespaces",
|
|
6
7
|
(_, response, context) => {
|
|
7
8
|
return response.once(
|
|
8
|
-
context.
|
|
9
|
-
|
|
10
|
-
success: true,
|
|
11
|
-
errors: [],
|
|
12
|
-
messages: [],
|
|
13
|
-
result: {
|
|
9
|
+
context.json(
|
|
10
|
+
createFetchResult({
|
|
14
11
|
namespace_id: "some-namespace-id",
|
|
15
12
|
namespace_name: "namespace-name",
|
|
16
13
|
created_on: "2022-06-29T14:30:08.16152Z",
|
|
17
14
|
created_by: "1fc1df98cc4420fe00367c3ab68c1639",
|
|
18
15
|
modified_on: "2022-06-29T14:30:08.16152Z",
|
|
19
16
|
modified_by: "1fc1df98cc4420fe00367c3ab68c1639",
|
|
20
|
-
}
|
|
21
|
-
|
|
17
|
+
})
|
|
18
|
+
)
|
|
22
19
|
);
|
|
23
20
|
}
|
|
24
21
|
),
|
|
25
22
|
rest.delete(
|
|
26
23
|
"*/accounts/:accountId/workers/dispatch/namespaces/:namespaceName",
|
|
27
24
|
(_, response, context) => {
|
|
28
|
-
return response.once(
|
|
29
|
-
context.status(200),
|
|
30
|
-
context.json({
|
|
31
|
-
success: true,
|
|
32
|
-
errors: [],
|
|
33
|
-
messages: [],
|
|
34
|
-
result: null,
|
|
35
|
-
})
|
|
36
|
-
);
|
|
25
|
+
return response.once(context.json(createFetchResult(null)));
|
|
37
26
|
}
|
|
38
27
|
),
|
|
39
28
|
rest.put(
|
|
40
29
|
"*/accounts/:accountId/workers/dispatch/namespaces/:namespaceName",
|
|
41
30
|
(_, response, context) => {
|
|
42
31
|
return response.once(
|
|
43
|
-
context.
|
|
44
|
-
|
|
45
|
-
success: true,
|
|
46
|
-
errors: [],
|
|
47
|
-
messages: [],
|
|
48
|
-
result: {
|
|
32
|
+
context.json(
|
|
33
|
+
createFetchResult({
|
|
49
34
|
namespace_id: "some-namespace-id",
|
|
50
35
|
namespace_name: "namespace-name",
|
|
51
36
|
created_on: "2022-06-29T14:30:08.16152Z",
|
|
52
37
|
created_by: "1fc1df98cc4420fe00367c3ab68c1639",
|
|
53
38
|
modified_on: "2022-06-29T14:30:08.16152Z",
|
|
54
39
|
modified_by: "1fc1df98cc4420fe00367c3ab68c1639",
|
|
55
|
-
}
|
|
56
|
-
|
|
40
|
+
})
|
|
41
|
+
)
|
|
57
42
|
);
|
|
58
43
|
}
|
|
59
44
|
),
|
|
@@ -61,20 +46,16 @@ export const mswSuccessNamespacesHandlers = [
|
|
|
61
46
|
"*/accounts/:accountId/workers/dispatch/namespaces/:namespaceName",
|
|
62
47
|
(_, response, context) => {
|
|
63
48
|
return response.once(
|
|
64
|
-
context.
|
|
65
|
-
|
|
66
|
-
success: true,
|
|
67
|
-
errors: [],
|
|
68
|
-
messages: [],
|
|
69
|
-
result: {
|
|
49
|
+
context.json(
|
|
50
|
+
createFetchResult({
|
|
70
51
|
namespace_id: "some-namespace-id",
|
|
71
52
|
namespace_name: "namespace-name",
|
|
72
53
|
created_on: "2022-06-29T14:30:08.16152Z",
|
|
73
54
|
created_by: "1fc1df98cc4420fe00367c3ab68c1639",
|
|
74
55
|
modified_on: "2022-06-29T14:30:08.16152Z",
|
|
75
56
|
modified_by: "1fc1df98cc4420fe00367c3ab68c1639",
|
|
76
|
-
}
|
|
77
|
-
|
|
57
|
+
})
|
|
58
|
+
)
|
|
78
59
|
);
|
|
79
60
|
}
|
|
80
61
|
),
|
|
@@ -82,12 +63,8 @@ export const mswSuccessNamespacesHandlers = [
|
|
|
82
63
|
"*/accounts/:accountId/workers/dispatch/namespaces",
|
|
83
64
|
(_, response, context) => {
|
|
84
65
|
return response.once(
|
|
85
|
-
context.
|
|
86
|
-
|
|
87
|
-
success: true,
|
|
88
|
-
errors: [],
|
|
89
|
-
messages: [],
|
|
90
|
-
result: [
|
|
66
|
+
context.json(
|
|
67
|
+
createFetchResult([
|
|
91
68
|
{
|
|
92
69
|
namespace_id: "some-namespace-id",
|
|
93
70
|
namespace_name: "namespace-name",
|
|
@@ -96,8 +73,8 @@ export const mswSuccessNamespacesHandlers = [
|
|
|
96
73
|
modified_on: "2022-06-29T14:30:08.16152Z",
|
|
97
74
|
modified_by: "1fc1df98cc4420fe00367c3ab68c1639",
|
|
98
75
|
},
|
|
99
|
-
]
|
|
100
|
-
|
|
76
|
+
])
|
|
77
|
+
)
|
|
101
78
|
);
|
|
102
79
|
}
|
|
103
80
|
),
|
|
@@ -1,44 +1,31 @@
|
|
|
1
1
|
import { rest } from "msw";
|
|
2
|
+
import { createFetchResult } from "../index";
|
|
2
3
|
|
|
3
4
|
export const mswSuccessR2handlers = [
|
|
4
5
|
// List endpoint r2Buckets
|
|
5
6
|
rest.get("*/accounts/:accountId/r2/buckets", (_, response, context) =>
|
|
6
7
|
response.once(
|
|
7
|
-
context.
|
|
8
|
-
|
|
9
|
-
success: true,
|
|
10
|
-
errors: [],
|
|
11
|
-
messages: [],
|
|
12
|
-
result: {
|
|
8
|
+
context.json(
|
|
9
|
+
createFetchResult({
|
|
13
10
|
buckets: [
|
|
14
11
|
{ name: "bucket-1", creation_date: "01-01-2001" },
|
|
15
12
|
{ name: "bucket-2", creation_date: "01-01-2001" },
|
|
16
13
|
],
|
|
17
|
-
}
|
|
18
|
-
|
|
14
|
+
})
|
|
15
|
+
)
|
|
19
16
|
)
|
|
20
17
|
),
|
|
21
18
|
rest.post("*/accounts/:accountId/r2/buckets", (_, response, context) =>
|
|
22
|
-
response.once(
|
|
23
|
-
context.status(200),
|
|
24
|
-
context.json({ success: true, errors: [], messages: [], result: {} })
|
|
25
|
-
)
|
|
19
|
+
response.once(context.json(createFetchResult({})))
|
|
26
20
|
),
|
|
27
21
|
rest.put(
|
|
28
22
|
"*/accounts/:accountId/r2/buckets/:bucketName",
|
|
29
|
-
(_, response, context) =>
|
|
30
|
-
response.once(
|
|
31
|
-
context.status(200),
|
|
32
|
-
context.json({ success: true, errors: [], messages: [], result: {} })
|
|
33
|
-
)
|
|
23
|
+
(_, response, context) => response.once(context.json(createFetchResult({})))
|
|
34
24
|
),
|
|
35
25
|
rest.delete(
|
|
36
26
|
"*/accounts/:accountId/r2/buckets/:bucketName",
|
|
37
27
|
(_, response, context) =>
|
|
38
|
-
response.once(
|
|
39
|
-
context.status(200),
|
|
40
|
-
context.json({ success: true, errors: [], messages: [], result: null })
|
|
41
|
-
)
|
|
28
|
+
response.once(context.json(createFetchResult(null)))
|
|
42
29
|
),
|
|
43
30
|
rest.get(
|
|
44
31
|
"*/accounts/:accountId/r2/buckets/:bucketName/objects/:objectName",
|
|
@@ -47,7 +34,7 @@ export const mswSuccessR2handlers = [
|
|
|
47
34
|
return response.once(
|
|
48
35
|
context.set("Content-Length", imageBuffer.byteLength.toString()),
|
|
49
36
|
context.set("Content-Type", "image/png"),
|
|
50
|
-
|
|
37
|
+
|
|
51
38
|
context.body(imageBuffer)
|
|
52
39
|
);
|
|
53
40
|
}
|
|
@@ -56,25 +43,18 @@ export const mswSuccessR2handlers = [
|
|
|
56
43
|
"*/accounts/:accountId/r2/buckets/:bucketName/objects/:objectName",
|
|
57
44
|
(_, response, context) =>
|
|
58
45
|
response.once(
|
|
59
|
-
context.
|
|
60
|
-
|
|
61
|
-
success: true,
|
|
62
|
-
errors: [],
|
|
63
|
-
messages: [],
|
|
64
|
-
result: {
|
|
46
|
+
context.json(
|
|
47
|
+
createFetchResult({
|
|
65
48
|
accountId: "some-account-id",
|
|
66
49
|
bucketName: "bucketName-object-test",
|
|
67
50
|
objectName: "wormhole-img.png",
|
|
68
|
-
}
|
|
69
|
-
|
|
51
|
+
})
|
|
52
|
+
)
|
|
70
53
|
)
|
|
71
54
|
),
|
|
72
55
|
rest.delete(
|
|
73
56
|
"*/accounts/:accountId/r2/buckets/:bucketName/objects/:objectName",
|
|
74
57
|
(_, response, context) =>
|
|
75
|
-
response.once(
|
|
76
|
-
context.status(200),
|
|
77
|
-
context.json({ success: true, errors: [], messages: [], result: null })
|
|
78
|
-
)
|
|
58
|
+
response.once(context.json(createFetchResult(null)))
|
|
79
59
|
),
|
|
80
60
|
];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { rest } from "msw";
|
|
2
|
+
import { createFetchResult } from "../index";
|
|
2
3
|
import type { WorkerMetadata } from "../../../../create-worker-upload-form";
|
|
3
4
|
|
|
4
5
|
const bindings: Record<string, WorkerMetadata["bindings"]> = {
|
|
@@ -14,10 +15,12 @@ const scripts: Record<string, string> = {
|
|
|
14
15
|
websocket: `new WebSocket("ws://dummy")`,
|
|
15
16
|
response: `return new Response("ok")`,
|
|
16
17
|
};
|
|
17
|
-
function getBindings(scriptName: string) {
|
|
18
|
+
function getBindings(scriptName: string | readonly string[]) {
|
|
19
|
+
if (typeof scriptName !== "string") return "";
|
|
18
20
|
return scriptName.split("--").flatMap((part) => bindings[part] ?? []);
|
|
19
21
|
}
|
|
20
|
-
function getScript(scriptName: string) {
|
|
22
|
+
function getScript(scriptName: string | readonly string[]): string {
|
|
23
|
+
if (typeof scriptName !== "string") return "";
|
|
21
24
|
return `export default {fetch(request){
|
|
22
25
|
${scriptName
|
|
23
26
|
.split("--")
|
|
@@ -29,47 +32,25 @@ export default [
|
|
|
29
32
|
rest.get(
|
|
30
33
|
"*/accounts/:accountId/workers/services/:scriptName/environments/:env/content",
|
|
31
34
|
({ params: { scriptName } }, res, context) => {
|
|
32
|
-
return res(
|
|
33
|
-
context.status(200),
|
|
34
|
-
context.text(getScript(scriptName as string))
|
|
35
|
-
);
|
|
35
|
+
return res(context.text(getScript(scriptName)));
|
|
36
36
|
}
|
|
37
37
|
),
|
|
38
38
|
rest.get(
|
|
39
39
|
"*/accounts/:accountId/workers/scripts/:scriptName",
|
|
40
40
|
({ params: { scriptName } }, res, context) => {
|
|
41
|
-
return res(
|
|
42
|
-
context.status(200),
|
|
43
|
-
context.text(getScript(scriptName as string))
|
|
44
|
-
);
|
|
41
|
+
return res(context.text(getScript(scriptName)));
|
|
45
42
|
}
|
|
46
43
|
),
|
|
47
44
|
rest.get(
|
|
48
45
|
"*/accounts/:accountId/workers/services/:scriptName/environments/:env/bindings",
|
|
49
46
|
({ params: { scriptName } }, res, context) => {
|
|
50
|
-
return res(
|
|
51
|
-
context.status(200),
|
|
52
|
-
context.json({
|
|
53
|
-
success: true,
|
|
54
|
-
errors: [],
|
|
55
|
-
messages: [],
|
|
56
|
-
result: getBindings(scriptName as string),
|
|
57
|
-
})
|
|
58
|
-
);
|
|
47
|
+
return res(context.json(createFetchResult(getBindings(scriptName))));
|
|
59
48
|
}
|
|
60
49
|
),
|
|
61
50
|
rest.get(
|
|
62
51
|
"*/accounts/:accountId/workers/scripts/:scriptName/bindings",
|
|
63
52
|
({ params: { scriptName } }, res, context) => {
|
|
64
|
-
return res(
|
|
65
|
-
context.status(200),
|
|
66
|
-
context.json({
|
|
67
|
-
success: true,
|
|
68
|
-
errors: [],
|
|
69
|
-
messages: [],
|
|
70
|
-
result: getBindings(scriptName as string),
|
|
71
|
-
})
|
|
72
|
-
);
|
|
53
|
+
return res(context.json(createFetchResult(getBindings(scriptName))));
|
|
73
54
|
}
|
|
74
55
|
),
|
|
75
56
|
];
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { rest } from "msw";
|
|
2
|
+
import { createFetchResult } from "../index";
|
|
2
3
|
|
|
3
4
|
export const mswSuccessUserHandlers = [
|
|
4
5
|
rest.get("*/user", (_, response, cxt) => {
|
|
5
6
|
return response.once(
|
|
6
|
-
cxt.
|
|
7
|
-
|
|
8
|
-
success: true,
|
|
9
|
-
errors: [],
|
|
10
|
-
messages: [],
|
|
11
|
-
result: {
|
|
7
|
+
cxt.json(
|
|
8
|
+
createFetchResult({
|
|
12
9
|
id: "7c5dae5552338874e5053f2534d2767a",
|
|
13
10
|
email: "user@example.com",
|
|
14
11
|
first_name: "John",
|
|
@@ -21,33 +18,25 @@ export const mswSuccessUserHandlers = [
|
|
|
21
18
|
modified_on: "2014-01-01T05:20:00Z",
|
|
22
19
|
two_factor_authentication_enabled: false,
|
|
23
20
|
suspended: false,
|
|
24
|
-
}
|
|
25
|
-
|
|
21
|
+
})
|
|
22
|
+
)
|
|
26
23
|
);
|
|
27
24
|
}),
|
|
28
25
|
rest.get("*/accounts", (_, response, cxt) => {
|
|
29
26
|
return response.once(
|
|
30
|
-
cxt.
|
|
31
|
-
|
|
32
|
-
success: true,
|
|
33
|
-
errors: [],
|
|
34
|
-
messages: [],
|
|
35
|
-
result: [
|
|
27
|
+
cxt.json(
|
|
28
|
+
createFetchResult([
|
|
36
29
|
{ name: "Account One", id: "account-1" },
|
|
37
30
|
{ name: "Account Two", id: "account-2" },
|
|
38
31
|
{ name: "Account Three", id: "account-3" },
|
|
39
|
-
]
|
|
40
|
-
|
|
32
|
+
])
|
|
33
|
+
)
|
|
41
34
|
);
|
|
42
35
|
}),
|
|
43
36
|
rest.get("*/memberships", (_, response, context) => {
|
|
44
37
|
return response.once(
|
|
45
|
-
context.
|
|
46
|
-
|
|
47
|
-
success: true,
|
|
48
|
-
errors: [],
|
|
49
|
-
messages: [],
|
|
50
|
-
result: [
|
|
38
|
+
context.json(
|
|
39
|
+
createFetchResult([
|
|
51
40
|
{
|
|
52
41
|
id: "membership-id-1",
|
|
53
42
|
account: { id: "account-id-1", name: "My Personal Account" },
|
|
@@ -56,8 +45,8 @@ export const mswSuccessUserHandlers = [
|
|
|
56
45
|
id: "membership-id-2",
|
|
57
46
|
account: { id: "account-id-2", name: "Enterprise Account" },
|
|
58
47
|
},
|
|
59
|
-
]
|
|
60
|
-
|
|
48
|
+
])
|
|
49
|
+
)
|
|
61
50
|
);
|
|
62
51
|
}),
|
|
63
52
|
];
|
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import { rest } from "msw";
|
|
2
|
+
import { createFetchResult } from "../index";
|
|
2
3
|
|
|
3
4
|
export default [
|
|
4
5
|
rest.get("*/zones", ({ url: { searchParams } }, res, context) => {
|
|
5
6
|
return res(
|
|
6
|
-
context.
|
|
7
|
-
|
|
8
|
-
success: true,
|
|
9
|
-
errors: [],
|
|
10
|
-
messages: [],
|
|
11
|
-
result:
|
|
7
|
+
context.json(
|
|
8
|
+
createFetchResult(
|
|
12
9
|
searchParams.get("name") === "exists.com"
|
|
13
10
|
? [
|
|
14
11
|
{
|
|
15
12
|
id: "exists-com",
|
|
16
13
|
},
|
|
17
14
|
]
|
|
18
|
-
: []
|
|
19
|
-
|
|
15
|
+
: []
|
|
16
|
+
)
|
|
17
|
+
)
|
|
20
18
|
);
|
|
21
19
|
}),
|
|
22
20
|
];
|