wrangler 0.0.0-e7a0cd5b → 0.0.0-e7cf0caa
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 +3 -3
- package/bin/wrangler.js +30 -10
- package/miniflare-dist/index.mjs +126 -74
- package/package.json +27 -19
- package/src/__tests__/api-dev.test.ts +65 -36
- package/src/__tests__/api-devregistry.test.ts +121 -0
- package/src/__tests__/api.test.ts +27 -5
- package/src/__tests__/configuration.test.ts +567 -86
- package/src/__tests__/d1/d1.test.ts +82 -0
- package/src/__tests__/d1/execute.test.ts +66 -0
- package/src/__tests__/d1/migrate.test.ts +157 -0
- package/src/__tests__/d1/splitter.test.ts +255 -0
- package/src/__tests__/delete.test.ts +91 -49
- package/src/__tests__/deployments.test.ts +330 -56
- package/src/__tests__/dev.test.tsx +198 -90
- package/src/__tests__/generate.test.ts +12 -10
- package/src/__tests__/guess-worker-format.test.ts +35 -0
- package/src/__tests__/helpers/end-event-loop.ts +6 -0
- package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
- package/src/__tests__/helpers/mock-console.ts +6 -0
- package/src/__tests__/helpers/mock-dialogs.ts +71 -85
- package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
- package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -5
- package/src/__tests__/helpers/mock-known-routes.ts +7 -2
- package/src/__tests__/helpers/mock-kv.ts +29 -16
- package/src/__tests__/helpers/mock-oauth-flow.ts +103 -92
- package/src/__tests__/helpers/mock-process.ts +8 -13
- package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
- package/src/__tests__/helpers/msw/blob-worker.cjs +19 -0
- package/src/__tests__/helpers/msw/handlers/deployments.ts +128 -27
- package/src/__tests__/helpers/msw/handlers/namespaces.ts +18 -41
- package/src/__tests__/helpers/msw/handlers/oauth.ts +13 -18
- 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__/helpers/msw/index.ts +32 -1
- package/src/__tests__/helpers/msw/read-file-sync.js +61 -0
- package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
- package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
- package/src/__tests__/index.test.ts +90 -72
- package/src/__tests__/init.test.ts +927 -631
- package/src/__tests__/jest.setup.ts +19 -42
- package/src/__tests__/kv.test.ts +355 -231
- package/src/__tests__/logger.test.ts +68 -2
- package/src/__tests__/logout.test.ts +47 -0
- package/src/__tests__/metrics.test.ts +94 -51
- package/src/__tests__/middleware.scheduled.test.ts +42 -32
- package/src/__tests__/middleware.test.ts +212 -122
- package/src/__tests__/mtls-certificates.test.ts +588 -0
- package/src/__tests__/pages/deployment-list.test.ts +80 -0
- package/src/__tests__/pages/functions-build.test.ts +452 -0
- package/src/__tests__/pages/pages.test.ts +81 -0
- package/src/__tests__/pages/project-create.test.ts +63 -0
- package/src/__tests__/pages/project-list.test.ts +110 -0
- package/src/__tests__/pages/project-upload.test.ts +500 -0
- package/src/__tests__/pages/publish.test.ts +2864 -0
- package/src/__tests__/pages-deployment-tail.test.ts +955 -0
- package/src/__tests__/parse.test.ts +106 -0
- package/src/__tests__/publish.test.ts +1615 -852
- package/src/__tests__/pubsub.test.ts +226 -100
- package/src/__tests__/queues.test.ts +238 -77
- package/src/__tests__/r2.test.ts +55 -57
- package/src/__tests__/secret.test.ts +179 -130
- package/src/__tests__/tail.test.ts +267 -109
- package/src/__tests__/test-old-node-version.js +3 -3
- package/src/__tests__/traverse-module-graph.test.ts +220 -0
- 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 +43 -26
- package/src/__tests__/user.test.ts +35 -72
- package/src/__tests__/whoami.test.tsx +8 -114
- package/src/__tests__/worker-namespace.test.ts +83 -69
- package/src/api/dev.ts +168 -60
- package/src/api/index.ts +10 -1
- package/src/api/mtls-certificate.ts +148 -0
- package/src/api/pages/create-worker-bundle-contents.ts +76 -0
- package/src/api/pages/index.ts +5 -0
- package/src/api/pages/publish.tsx +355 -0
- package/src/bundle.ts +263 -140
- package/src/cfetch/index.ts +0 -2
- package/src/cfetch/internal.ts +16 -21
- package/src/cli.ts +4 -4
- package/src/config/config.ts +14 -7
- package/src/config/environment.ts +79 -24
- package/src/config/index.ts +99 -38
- package/src/config/validation-helpers.ts +1 -1
- package/src/config/validation.ts +248 -19
- package/src/create-worker-preview.ts +19 -8
- package/src/create-worker-upload-form.ts +60 -22
- package/src/d1/backups.tsx +43 -42
- package/src/d1/constants.ts +2 -0
- package/src/d1/create.tsx +44 -30
- package/src/d1/{delete.tsx → delete.ts} +11 -14
- package/src/d1/execute.tsx +209 -151
- package/src/d1/index.ts +31 -7
- package/src/d1/list.tsx +22 -10
- package/src/d1/migrations/apply.tsx +212 -0
- package/src/d1/migrations/create.tsx +79 -0
- package/src/d1/migrations/helpers.ts +172 -0
- package/src/d1/migrations/index.ts +3 -0
- package/src/d1/migrations/list.tsx +95 -0
- package/src/d1/migrations/options.ts +23 -0
- package/src/d1/options.ts +12 -2
- package/src/d1/splitter.ts +161 -0
- package/src/d1/{types.tsx → types.ts} +11 -0
- package/src/d1/utils.ts +12 -2
- package/src/delete.ts +8 -16
- package/src/deployments.ts +340 -46
- package/src/deprecated/index.ts +8 -302
- package/src/dev/dev.tsx +57 -44
- package/src/dev/local.tsx +294 -91
- package/src/dev/remote.tsx +32 -3
- package/src/dev/start-server.ts +89 -68
- package/src/dev/use-esbuild.ts +17 -18
- package/src/dev/validate-dev-props.ts +9 -0
- package/src/{dev-registry.tsx → dev-registry.ts} +2 -1
- package/src/dev.tsx +178 -118
- package/src/dialogs.ts +136 -0
- package/src/dispatch-namespace.ts +21 -17
- package/src/docs/index.ts +97 -0
- package/src/entry.ts +19 -11
- package/src/environment-variables/factory.ts +88 -0
- package/src/environment-variables/misc-variables.ts +30 -0
- package/src/generate/index.ts +298 -0
- package/src/git-client.ts +15 -4
- package/src/{index.tsx → index.ts} +137 -63
- package/src/init.ts +249 -187
- package/src/inspect.ts +16 -1
- package/src/jest.d.ts +4 -0
- package/src/kv/index.ts +15 -17
- package/src/logger.ts +32 -5
- package/src/metrics/metrics-config.ts +3 -3
- package/src/metrics/send-event.ts +6 -1
- package/src/miniflare-cli/assets.ts +64 -28
- package/src/miniflare-cli/index.ts +4 -7
- 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 +91 -25
- package/src/mtls-certificate/cli.ts +155 -0
- package/src/pages/build.ts +410 -0
- package/src/pages/buildFunctions.ts +140 -0
- package/src/pages/deployment-tails.ts +281 -0
- package/src/pages/deployments.tsx +11 -33
- package/src/pages/{dev.tsx → dev.ts} +147 -124
- package/src/pages/errors.ts +1 -0
- package/src/pages/functions/buildPlugin.ts +72 -69
- package/src/pages/functions/buildWorker.ts +249 -114
- package/src/pages/functions/tsconfig.json +8 -0
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
- package/src/pages/{functions.tsx → functions.ts} +8 -4
- package/src/pages/{index.tsx → index.ts} +11 -3
- package/src/pages/projects.tsx +12 -22
- package/src/pages/prompt-select-project.tsx +31 -0
- package/src/pages/publish.tsx +45 -214
- package/src/pages/types.ts +6 -9
- package/src/pages/upload.tsx +58 -14
- package/src/pages/utils.ts +14 -3
- package/src/parse.ts +23 -1
- package/src/paths.ts +1 -1
- package/src/proxy.ts +5 -0
- package/src/publish/index.ts +20 -16
- package/src/publish/publish.ts +72 -47
- package/src/pubsub/{pubsub-commands.tsx → pubsub-commands.ts} +19 -20
- package/src/queues/cli/commands/consumer/add.ts +24 -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 +6 -4
- package/src/queues/cli/commands/list.ts +8 -8
- package/src/queues/client.ts +1 -0
- package/src/queues/utils.ts +18 -0
- package/src/r2/constants.ts +4 -0
- package/src/r2/helpers.ts +1 -0
- package/src/r2/index.ts +40 -28
- package/src/secret/index.ts +14 -17
- package/src/{sites.tsx → sites.ts} +1 -1
- package/src/tail/createTail.ts +94 -3
- package/src/tail/filters.ts +1 -1
- package/src/tail/index.ts +8 -11
- package/src/tail/printing.ts +15 -0
- package/src/traverse-module-graph.ts +53 -0
- package/src/tsconfig-sanity.ts +16 -0
- package/src/type-generation.ts +79 -57
- package/src/user/access.ts +0 -1
- package/src/user/auth-variables.ts +113 -0
- package/src/user/choose-account.tsx +1 -31
- package/src/user/index.ts +0 -1
- package/src/user/{user.tsx → user.ts} +123 -82
- package/src/utils/render.ts +93 -0
- package/src/{whoami.tsx → whoami.ts} +37 -71
- package/src/worker.ts +35 -3
- package/src/yargs-types.ts +22 -5
- package/templates/__tests__/tsconfig-sanity.ts +12 -0
- package/templates/__tests__/tsconfig.json +8 -0
- package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
- package/templates/checked-fetch.js +9 -3
- package/templates/d1-beta-facade.js +95 -25
- package/templates/facade.d.ts +14 -0
- package/templates/first-party-worker-module-facade.ts +4 -3
- package/templates/format-dev-errors.ts +8 -6
- package/templates/gitignore +1 -0
- package/templates/init-tests/test-jest-new-worker.js +3 -5
- package/templates/init-tests/test-vitest-new-worker.js +3 -5
- package/templates/init-tests/test-vitest-new-worker.ts +25 -0
- package/templates/middleware/loader-modules.ts +2 -2
- package/templates/middleware/loader-sw.ts +51 -31
- package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
- package/templates/new-worker.ts +3 -0
- package/templates/pages-dev-pipeline.ts +4 -1
- package/templates/pages-shim.ts +4 -1
- package/templates/pages-template-plugin.ts +19 -10
- package/templates/serve-static-assets.ts +17 -14
- package/templates/service-bindings-module-facade.js +1 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +105 -0
- package/templates/tsconfig.json +5 -103
- package/templates/tsconfig.tsbuildinfo +1 -0
- package/wrangler-dist/cli.d.ts +826 -77
- package/wrangler-dist/cli.js +130734 -140838
- package/wrangler-dist/wasm-sync.wasm +0 -0
- package/src/__tests__/api-devregistry.test.js +0 -57
- package/src/__tests__/d1.test.ts +0 -72
- package/src/__tests__/dialogs.test.tsx +0 -40
- package/src/__tests__/helpers/mock-cfetch.ts +0 -333
- package/src/__tests__/pages.test.ts +0 -2223
- package/src/dialogs.tsx +0 -163
- package/src/environment-variables.ts +0 -50
- package/src/pages/build.tsx +0 -238
- package/src/user/env-vars.ts +0 -46
- package/templates/experimental-local-cache-stubs.js +0 -27
- /package/src/{bundle-reporter.tsx → bundle-reporter.ts} +0 -0
- /package/src/dev/{get-local-persistence-path.tsx → get-local-persistence-path.ts} +0 -0
- /package/src/pages/{hash.tsx → hash.ts} +0 -0
|
@@ -5,22 +5,17 @@
|
|
|
5
5
|
|
|
6
6
|
let writeSpy: jest.SpyInstance;
|
|
7
7
|
|
|
8
|
-
function captureLastWriteCall(spy: jest.SpyInstance): Buffer {
|
|
8
|
+
function captureLastWriteCall(spy: jest.SpyInstance): Buffer | undefined {
|
|
9
9
|
const calls = spy.mock.calls;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
|
|
11
|
+
// Loop through and find the buffer in calls
|
|
12
|
+
// (we don't know the index of the buffer in the calls array)
|
|
13
|
+
const buffer = calls
|
|
14
|
+
.map((call) => call[0])
|
|
15
|
+
.find((call) => call instanceof Buffer);
|
|
16
|
+
|
|
16
17
|
if (buffer instanceof Buffer) {
|
|
17
18
|
return buffer;
|
|
18
|
-
} else {
|
|
19
|
-
throw new Error(
|
|
20
|
-
`Unexpected non-Buffer passed to \`stdout.write()\`: "${JSON.stringify(
|
|
21
|
-
buffer
|
|
22
|
-
)}"`
|
|
23
|
-
);
|
|
24
19
|
}
|
|
25
20
|
}
|
|
26
21
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
let setTimeoutSpy: jest.SpyInstance;
|
|
2
|
+
|
|
3
|
+
export function mockSetTimeout() {
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
setTimeoutSpy = jest
|
|
6
|
+
.spyOn(global, "setTimeout")
|
|
7
|
+
// @ts-expect-error we're using a very simple setTimeout mock here
|
|
8
|
+
.mockImplementation((fn, _period) => {
|
|
9
|
+
setImmediate(fn);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
setTimeoutSpy.mockRestore();
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*! Read blob sync in NodeJS. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource>
|
|
2
|
+
* Special Thanks to Jimmy Wärting helping in https://github.com/nodejs/undici/issues/1830
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { workerData } = require("worker_threads");
|
|
6
|
+
|
|
7
|
+
const { signal, port, blob } = workerData;
|
|
8
|
+
|
|
9
|
+
blob.arrayBuffer().then((ab) => {
|
|
10
|
+
// Post the result back to the main thread before unlocking 'signal'
|
|
11
|
+
port.postMessage(ab, [ab]);
|
|
12
|
+
port.close();
|
|
13
|
+
|
|
14
|
+
// Change the value of signal[0] to 1
|
|
15
|
+
Atomics.store(signal, 0, 1);
|
|
16
|
+
|
|
17
|
+
// This will unlock the main thread when we notify it
|
|
18
|
+
Atomics.notify(signal, 0);
|
|
19
|
+
});
|
|
@@ -1,37 +1,40 @@
|
|
|
1
1
|
import { rest } from "msw";
|
|
2
|
+
import { createFetchResult } from "../index";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
const latestDeployment = {
|
|
5
|
+
id: "Galaxy-Class",
|
|
6
|
+
number: "1701-E",
|
|
7
|
+
annotations: {
|
|
8
|
+
"workers/triggered_by": "rollback",
|
|
9
|
+
"workers/rollback_from": "MOCK-DEPLOYMENT-ID-2222",
|
|
10
|
+
},
|
|
11
|
+
metadata: {
|
|
12
|
+
author_id: "Picard-Gamma-6-0-7-3",
|
|
13
|
+
author_email: "Jean-Luc-Picard@federation.org",
|
|
14
|
+
source: "wrangler",
|
|
15
|
+
created_on: "2021-01-04T00:00:00.000000Z",
|
|
16
|
+
modified_on: "2021-01-04T00:00:00.000000Z",
|
|
17
|
+
},
|
|
18
|
+
resources: {
|
|
19
|
+
script: "MOCK-TAG",
|
|
20
|
+
bindings: [],
|
|
21
|
+
},
|
|
22
|
+
};
|
|
5
23
|
export const mswSuccessDeployments = [
|
|
6
24
|
rest.get(
|
|
7
|
-
"*/accounts/:accountId/workers/
|
|
25
|
+
"*/accounts/:accountId/workers/deployments/by-script/:scriptTag",
|
|
8
26
|
(_, response, context) =>
|
|
9
27
|
response.once(
|
|
10
|
-
context.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
errors: [],
|
|
14
|
-
messages: [],
|
|
15
|
-
result: {
|
|
16
|
-
latest: {
|
|
17
|
-
id: "Galaxy-Class",
|
|
18
|
-
number: "1701-E",
|
|
19
|
-
metadata: {
|
|
20
|
-
author_id: "Picard-Gamma-6-0-7-3",
|
|
21
|
-
author_email: "Jean-Luc-Picard@federation.org",
|
|
22
|
-
source: "wrangler",
|
|
23
|
-
created_on: "2021-01-01T00:00:00.000000Z",
|
|
24
|
-
modified_on: "2021-01-01T00:00:00.000000Z",
|
|
25
|
-
},
|
|
26
|
-
resources: {
|
|
27
|
-
script: "MOCK-TAG",
|
|
28
|
-
bindings: [],
|
|
29
|
-
},
|
|
30
|
-
},
|
|
28
|
+
context.json(
|
|
29
|
+
createFetchResult({
|
|
30
|
+
latest: latestDeployment,
|
|
31
31
|
items: [
|
|
32
32
|
{
|
|
33
|
-
id: "
|
|
33
|
+
id: "Constitution-Class",
|
|
34
34
|
number: "1701-E",
|
|
35
|
+
annotations: {
|
|
36
|
+
"workers/triggered_by": "upload",
|
|
37
|
+
},
|
|
35
38
|
metadata: {
|
|
36
39
|
author_id: "Picard-Gamma-6-0-7-3",
|
|
37
40
|
author_email: "Jean-Luc-Picard@federation.org",
|
|
@@ -43,6 +46,11 @@ export const mswSuccessDeployments = [
|
|
|
43
46
|
{
|
|
44
47
|
id: "Intrepid-Class",
|
|
45
48
|
number: "NCC-74656",
|
|
49
|
+
annotations: {
|
|
50
|
+
"workers/triggered_by": "rollback",
|
|
51
|
+
"workers/rollback_from": "MOCK-DEPLOYMENT-ID-1111",
|
|
52
|
+
"workers/message": "Rolled back for this version",
|
|
53
|
+
},
|
|
46
54
|
metadata: {
|
|
47
55
|
author_id: "Kathryn-Jane-Gamma-6-0-7-3",
|
|
48
56
|
author_email: "Kathryn-Janeway@federation.org",
|
|
@@ -51,9 +59,102 @@ export const mswSuccessDeployments = [
|
|
|
51
59
|
modified_on: "2021-02-02T00:00:00.000000Z",
|
|
52
60
|
},
|
|
53
61
|
},
|
|
62
|
+
{
|
|
63
|
+
id: "3mEgaU1T-Intrepid-someThing",
|
|
64
|
+
number: "NCC-74656",
|
|
65
|
+
metadata: {
|
|
66
|
+
author_id: "Kathryn-Jane-Gamma-6-0-7-3",
|
|
67
|
+
author_email: "Kathryn-Janeway@federation.org",
|
|
68
|
+
source: "wrangler",
|
|
69
|
+
created_on: "2021-02-03T00:00:00.000000Z",
|
|
70
|
+
modified_on: "2021-02-03T00:00:00.000000Z",
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
latestDeployment,
|
|
54
74
|
],
|
|
55
|
-
}
|
|
56
|
-
|
|
75
|
+
})
|
|
76
|
+
)
|
|
57
77
|
)
|
|
58
78
|
),
|
|
59
79
|
];
|
|
80
|
+
|
|
81
|
+
export const mswSuccessDeploymentScriptMetadata = [
|
|
82
|
+
rest.get(
|
|
83
|
+
"*/accounts/:accountId/workers/services/:scriptName",
|
|
84
|
+
(_, res, ctx) => {
|
|
85
|
+
return res.once(
|
|
86
|
+
ctx.json(
|
|
87
|
+
createFetchResult({
|
|
88
|
+
default_environment: {
|
|
89
|
+
script: { last_deployed_from: "wrangler", tag: "MOCK-TAG" },
|
|
90
|
+
},
|
|
91
|
+
})
|
|
92
|
+
)
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
),
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
export const mswSuccessDeploymentDetails = [
|
|
99
|
+
rest.get(
|
|
100
|
+
"*/accounts/:accountId/workers/deployments/by-script/:scriptTag/detail/:deploymentId",
|
|
101
|
+
(req, res, ctx) => {
|
|
102
|
+
let bindings: object[] = [];
|
|
103
|
+
if (req.url.toString().includes("bindings-tag")) {
|
|
104
|
+
bindings = [
|
|
105
|
+
{
|
|
106
|
+
bucket_name: "testr2",
|
|
107
|
+
name: "MY_BUCKET",
|
|
108
|
+
type: "r2_bucket",
|
|
109
|
+
},
|
|
110
|
+
];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
expect(req.url.toString().includes("1701-E"));
|
|
114
|
+
return res.once(
|
|
115
|
+
ctx.json(
|
|
116
|
+
createFetchResult({
|
|
117
|
+
id: "1701-E",
|
|
118
|
+
Number: 0,
|
|
119
|
+
metadata: {
|
|
120
|
+
author_id: "Picard-Gamma-6-0-7-3",
|
|
121
|
+
author_email: "Jean-Luc-Picard@federation.org",
|
|
122
|
+
source: "wrangler",
|
|
123
|
+
created_on: "2021-01-01T00:00:00.000000Z",
|
|
124
|
+
modified_on: "2021-01-01T00:00:00.000000Z",
|
|
125
|
+
},
|
|
126
|
+
resources: {
|
|
127
|
+
script: {
|
|
128
|
+
etag: "mock-e-tag",
|
|
129
|
+
handlers: ["fetch"],
|
|
130
|
+
last_deployed_from: "wrangler",
|
|
131
|
+
},
|
|
132
|
+
script_runtime: {
|
|
133
|
+
usage_model: "bundled",
|
|
134
|
+
},
|
|
135
|
+
bindings: bindings,
|
|
136
|
+
},
|
|
137
|
+
})
|
|
138
|
+
)
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
),
|
|
142
|
+
// ?deployment=<deploymentid> param used to get deployment <script content> as text
|
|
143
|
+
rest.get(
|
|
144
|
+
"*/accounts/:accountId/workers/scripts/:scriptName",
|
|
145
|
+
(req, res, ctx) => {
|
|
146
|
+
let scriptContent = "";
|
|
147
|
+
if (req.url.searchParams.get("deployment") === "1701-E") {
|
|
148
|
+
scriptContent = `
|
|
149
|
+
export default {
|
|
150
|
+
async fetch(request) {
|
|
151
|
+
return new Response('Hello World from Deployment 1701-E');
|
|
152
|
+
},
|
|
153
|
+
};`;
|
|
154
|
+
} else {
|
|
155
|
+
return res(ctx.status(400));
|
|
156
|
+
}
|
|
157
|
+
return res.once(ctx.text(scriptContent));
|
|
158
|
+
}
|
|
159
|
+
),
|
|
160
|
+
];
|
|
@@ -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
|
),
|
|
@@ -13,24 +13,19 @@ export const mswSuccessOauthHandlers = [
|
|
|
13
13
|
);
|
|
14
14
|
}),
|
|
15
15
|
// revoke access token
|
|
16
|
-
rest.post(
|
|
17
|
-
|
|
18
|
-
(_, response, context) =>
|
|
19
|
-
response.once(context.status(200), context.text(""))
|
|
16
|
+
rest.post("*/oauth2/revoke", (_, response, context) =>
|
|
17
|
+
response.once(context.status(200), context.text(""))
|
|
20
18
|
),
|
|
21
19
|
// exchange (auth code | refresh token) for access token
|
|
22
|
-
rest.post(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
),
|
|
20
|
+
rest.post("*/oauth2/token", (_, response, context) => {
|
|
21
|
+
return response.once(
|
|
22
|
+
context.status(200),
|
|
23
|
+
context.json({
|
|
24
|
+
access_token: "test-access-token",
|
|
25
|
+
expires_in: 100000,
|
|
26
|
+
refresh_token: "test-refresh-token",
|
|
27
|
+
scope: "account:read",
|
|
28
|
+
})
|
|
29
|
+
);
|
|
30
|
+
}),
|
|
36
31
|
];
|
|
@@ -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
|
];
|