wrangler 2.0.12 → 2.0.16
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 +7 -1
- package/bin/wrangler.js +111 -57
- package/miniflare-dist/index.mjs +9 -2
- package/package.json +156 -154
- package/src/__tests__/config-cache-without-cache-dir.test.ts +38 -0
- package/src/__tests__/config-cache.test.ts +30 -24
- package/src/__tests__/configuration.test.ts +3935 -3476
- package/src/__tests__/dev.test.tsx +1128 -979
- package/src/__tests__/guess-worker-format.test.ts +68 -68
- package/src/__tests__/helpers/cmd-shim.d.ts +6 -6
- package/src/__tests__/helpers/faye-websocket.d.ts +4 -4
- package/src/__tests__/helpers/mock-account-id.ts +24 -24
- package/src/__tests__/helpers/mock-bin.ts +20 -20
- package/src/__tests__/helpers/mock-cfetch.ts +92 -92
- package/src/__tests__/helpers/mock-console.ts +49 -39
- package/src/__tests__/helpers/mock-dialogs.ts +94 -71
- package/src/__tests__/helpers/mock-http-server.ts +30 -30
- package/src/__tests__/helpers/mock-istty.ts +65 -18
- package/src/__tests__/helpers/mock-kv.ts +26 -26
- package/src/__tests__/helpers/mock-oauth-flow.ts +223 -228
- package/src/__tests__/helpers/mock-process.ts +39 -0
- package/src/__tests__/helpers/mock-stdin.ts +82 -77
- package/src/__tests__/helpers/mock-web-socket.ts +21 -21
- package/src/__tests__/helpers/run-in-tmp.ts +27 -27
- package/src/__tests__/helpers/run-wrangler.ts +8 -8
- package/src/__tests__/helpers/write-worker-source.ts +16 -16
- package/src/__tests__/helpers/write-wrangler-toml.ts +9 -9
- package/src/__tests__/https-options.test.ts +104 -104
- package/src/__tests__/index.test.ts +239 -234
- package/src/__tests__/init.test.ts +1605 -1250
- package/src/__tests__/jest.setup.ts +63 -33
- package/src/__tests__/kv.test.ts +1128 -1011
- package/src/__tests__/logger.test.ts +100 -74
- package/src/__tests__/package-manager.test.ts +303 -303
- package/src/__tests__/pages.test.ts +1152 -652
- package/src/__tests__/parse.test.ts +252 -252
- package/src/__tests__/publish.test.ts +6371 -5622
- package/src/__tests__/pubsub.test.ts +367 -0
- package/src/__tests__/r2.test.ts +133 -133
- package/src/__tests__/route.test.ts +18 -18
- package/src/__tests__/secret.test.ts +382 -377
- package/src/__tests__/tail.test.ts +530 -530
- package/src/__tests__/user.test.ts +123 -111
- package/src/__tests__/whoami.test.tsx +198 -117
- package/src/__tests__/worker-namespace.test.ts +327 -0
- package/src/abort.d.ts +1 -1
- package/src/api/dev.ts +49 -0
- package/src/api/index.ts +1 -0
- package/src/bundle-reporter.tsx +29 -0
- package/src/bundle.ts +157 -149
- package/src/cfetch/index.ts +80 -80
- package/src/cfetch/internal.ts +90 -83
- package/src/cli.ts +21 -7
- package/src/config/config.ts +204 -195
- package/src/config/diagnostics.ts +61 -61
- package/src/config/environment.ts +390 -357
- package/src/config/index.ts +206 -193
- package/src/config/validation-helpers.ts +366 -366
- package/src/config/validation.ts +1573 -1376
- package/src/config-cache.ts +79 -41
- package/src/create-worker-preview.ts +206 -136
- package/src/create-worker-upload-form.ts +247 -238
- package/src/dev/dev-vars.ts +13 -13
- package/src/dev/dev.tsx +329 -307
- package/src/dev/local.tsx +304 -275
- package/src/dev/remote.tsx +366 -224
- package/src/dev/use-esbuild.ts +126 -91
- package/src/dev.tsx +538 -0
- package/src/dialogs.tsx +97 -97
- package/src/durable.ts +87 -87
- package/src/entry.ts +234 -228
- package/src/environment-variables.ts +23 -23
- package/src/errors.ts +6 -6
- package/src/generate.ts +33 -0
- package/src/git-client.ts +42 -0
- package/src/https-options.ts +79 -79
- package/src/index.tsx +1775 -2763
- package/src/init.ts +549 -0
- package/src/inspect.ts +593 -593
- package/src/intl-polyfill.d.ts +123 -123
- package/src/is-interactive.ts +12 -0
- package/src/kv.ts +277 -277
- package/src/logger.ts +46 -39
- package/src/miniflare-cli/enum-keys.ts +8 -8
- package/src/miniflare-cli/index.ts +42 -31
- package/src/miniflare-cli/request-context.ts +18 -18
- package/src/module-collection.ts +212 -212
- package/src/open-in-browser.ts +4 -6
- package/src/package-manager.ts +123 -123
- package/src/pages/build.tsx +202 -0
- package/src/pages/constants.ts +7 -0
- package/src/pages/deployments.tsx +101 -0
- package/src/pages/dev.tsx +964 -0
- package/src/pages/functions/buildPlugin.ts +105 -0
- package/src/pages/functions/buildWorker.ts +151 -0
- package/{pages → src/pages}/functions/filepath-routing.test.ts +113 -113
- package/src/pages/functions/filepath-routing.ts +189 -0
- package/src/pages/functions/identifiers.ts +78 -0
- package/src/pages/functions/routes.ts +151 -0
- package/src/pages/index.tsx +84 -0
- package/src/pages/projects.tsx +157 -0
- package/src/pages/publish.tsx +335 -0
- package/src/pages/types.ts +40 -0
- package/src/pages/upload.tsx +384 -0
- package/src/pages/utils.ts +12 -0
- package/src/parse.ts +202 -138
- package/src/paths.ts +6 -6
- package/src/preview.ts +31 -0
- package/src/proxy.ts +400 -402
- package/src/publish.ts +667 -621
- package/src/pubsub/index.ts +286 -0
- package/src/pubsub/pubsub-commands.tsx +577 -0
- package/src/r2.ts +19 -19
- package/src/selfsigned.d.ts +23 -23
- package/src/sites.tsx +271 -225
- package/src/tail/filters.ts +108 -108
- package/src/tail/index.ts +217 -217
- package/src/tail/printing.ts +45 -45
- package/src/update-check.ts +11 -11
- package/src/user/choose-account.tsx +60 -0
- package/src/user/env-vars.ts +46 -0
- package/src/user/generate-auth-url.ts +33 -0
- package/src/user/generate-random-state.ts +16 -0
- package/src/user/index.ts +3 -0
- package/src/user/user.tsx +1161 -0
- package/src/whoami.tsx +61 -42
- package/src/worker-namespace.ts +190 -0
- package/src/worker.ts +110 -100
- package/src/zones.ts +39 -36
- package/templates/checked-fetch.js +17 -0
- package/templates/new-worker-scheduled.js +3 -3
- package/templates/new-worker-scheduled.ts +15 -15
- package/templates/new-worker.js +3 -3
- package/templates/new-worker.ts +15 -15
- package/templates/no-op-worker.js +10 -0
- package/templates/pages-template-plugin.ts +155 -0
- package/templates/pages-template-worker.ts +161 -0
- package/templates/static-asset-facade.js +31 -31
- package/templates/tsconfig.json +95 -95
- package/wrangler-dist/cli.js +55383 -54138
- package/pages/functions/buildPlugin.ts +0 -105
- package/pages/functions/buildWorker.ts +0 -151
- package/pages/functions/filepath-routing.ts +0 -189
- package/pages/functions/identifiers.ts +0 -78
- package/pages/functions/routes.ts +0 -156
- package/pages/functions/template-plugin.ts +0 -147
- package/pages/functions/template-worker.ts +0 -143
- package/src/pages.tsx +0 -2093
- package/src/user.tsx +0 -1214
package/src/whoami.tsx
CHANGED
|
@@ -3,69 +3,88 @@ import Table from "ink-table";
|
|
|
3
3
|
import React from "react";
|
|
4
4
|
import { fetchListResult, fetchResult } from "./cfetch";
|
|
5
5
|
import { logger } from "./logger";
|
|
6
|
-
import { getAPIToken,
|
|
6
|
+
import { getAPIToken, getAuthFromEnv } from "./user";
|
|
7
7
|
|
|
8
8
|
export async function whoami() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
logger.log("Getting User settings...");
|
|
10
|
+
const user = await getUserInfo();
|
|
11
|
+
render(<WhoAmI user={user}></WhoAmI>);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export function WhoAmI({ user }: { user: UserInfo | undefined }) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
return user ? (
|
|
16
|
+
<>
|
|
17
|
+
<Email tokenType={user.authType} email={user.email}></Email>
|
|
18
|
+
<Accounts accounts={user.accounts}></Accounts>
|
|
19
|
+
</>
|
|
20
|
+
) : (
|
|
21
|
+
<Text>You are not authenticated. Please run `wrangler login`.</Text>
|
|
22
|
+
);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
function Email(props: { tokenType: string; email: string }) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
function Email(props: { tokenType: string; email: string | undefined }) {
|
|
26
|
+
return props.email === undefined ? (
|
|
27
|
+
<Text>
|
|
28
|
+
👋 You are logged in with an {props.tokenType}. Unable to retrieve email
|
|
29
|
+
for this user. Are you missing the `User->User Details->Read`
|
|
30
|
+
permission?
|
|
31
|
+
</Text>
|
|
32
|
+
) : (
|
|
33
|
+
<Text>
|
|
34
|
+
👋 You are logged in with an {props.tokenType}, associated with the email
|
|
35
|
+
'{props.email}'!
|
|
36
|
+
</Text>
|
|
37
|
+
);
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
function Accounts(props: { accounts: AccountInfo[] }) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
const accounts = props.accounts.map((account) => ({
|
|
42
|
+
"Account Name": account.name,
|
|
43
|
+
"Account ID": account.id,
|
|
44
|
+
}));
|
|
45
|
+
return <Table data={accounts}></Table>;
|
|
40
46
|
}
|
|
41
47
|
|
|
42
48
|
export interface UserInfo {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
apiToken: string;
|
|
50
|
+
authType: string;
|
|
51
|
+
email: string | undefined;
|
|
52
|
+
accounts: AccountInfo[];
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
export async function getUserInfo(): Promise<UserInfo | undefined> {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
const apiToken = getAPIToken();
|
|
57
|
+
if (!apiToken) return;
|
|
58
|
+
|
|
59
|
+
const usingEnvAuth = !!getAuthFromEnv();
|
|
60
|
+
const usingGlobalAuthKey = "authKey" in apiToken;
|
|
61
|
+
return {
|
|
62
|
+
apiToken: usingGlobalAuthKey ? apiToken.authKey : apiToken.apiToken,
|
|
63
|
+
authType: usingGlobalAuthKey
|
|
64
|
+
? "Global API Key"
|
|
65
|
+
: usingEnvAuth
|
|
66
|
+
? "API Token"
|
|
67
|
+
: "OAuth Token",
|
|
68
|
+
email: "authEmail" in apiToken ? apiToken.authEmail : await getEmail(),
|
|
69
|
+
accounts: await getAccounts(),
|
|
70
|
+
};
|
|
60
71
|
}
|
|
61
72
|
|
|
62
|
-
async function getEmail(): Promise<string> {
|
|
63
|
-
|
|
64
|
-
|
|
73
|
+
async function getEmail(): Promise<string | undefined> {
|
|
74
|
+
try {
|
|
75
|
+
const { email } = await fetchResult<{ email: string }>("/user");
|
|
76
|
+
return email;
|
|
77
|
+
} catch (e) {
|
|
78
|
+
if ((e as { code?: number }).code === 9109) {
|
|
79
|
+
return undefined;
|
|
80
|
+
} else {
|
|
81
|
+
throw e;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
65
84
|
}
|
|
66
85
|
|
|
67
86
|
type AccountInfo = { name: string; id: string };
|
|
68
87
|
|
|
69
88
|
async function getAccounts(): Promise<AccountInfo[]> {
|
|
70
|
-
|
|
89
|
+
return await fetchListResult<AccountInfo>("/accounts");
|
|
71
90
|
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { fetchResult } from "./cfetch";
|
|
2
|
+
import { readConfig } from "./config";
|
|
3
|
+
import { logger } from "./logger";
|
|
4
|
+
import { requireAuth } from "./user";
|
|
5
|
+
import { printWranglerBanner } from ".";
|
|
6
|
+
import type { ConfigPath } from ".";
|
|
7
|
+
import type { Argv, CommandModule } from "yargs";
|
|
8
|
+
|
|
9
|
+
type Namespace = {
|
|
10
|
+
namespace_id: string;
|
|
11
|
+
namespace_name: string;
|
|
12
|
+
created_on: string;
|
|
13
|
+
created_by: string;
|
|
14
|
+
modified_on: string;
|
|
15
|
+
modified_by: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// Supporting Workers For Platforms
|
|
19
|
+
// More details at https://blog.cloudflare.com/workers-for-platforms/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Create a dynamic dispatch namespace.
|
|
23
|
+
*/
|
|
24
|
+
async function createWorkerNamespace(accountId: string, name: string) {
|
|
25
|
+
const namespace = await fetchResult<Namespace>(
|
|
26
|
+
`/accounts/${accountId}/workers/dispatch/namespaces`,
|
|
27
|
+
{
|
|
28
|
+
method: "POST",
|
|
29
|
+
headers: {
|
|
30
|
+
"Content-Type": "application/json",
|
|
31
|
+
},
|
|
32
|
+
body: JSON.stringify({ name }),
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
logger.log(
|
|
36
|
+
`Created Worker namespace "${name}" with ID "${namespace.namespace_id}"`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Delete a dynamic dispatch namespace.
|
|
42
|
+
*/
|
|
43
|
+
async function deleteWorkerNamespace(accountId: string, name: string) {
|
|
44
|
+
await fetchResult(
|
|
45
|
+
`/accounts/${accountId}/workers/dispatch/namespaces/${name}`,
|
|
46
|
+
{ method: "DELETE" }
|
|
47
|
+
);
|
|
48
|
+
logger.log(`Deleted Worker namespace "${name}"`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* List all created dynamic dispatch namespaces for an account
|
|
53
|
+
*/
|
|
54
|
+
async function listWorkerNamespaces(accountId: string) {
|
|
55
|
+
logger.log(
|
|
56
|
+
await fetchResult<Namespace>(
|
|
57
|
+
`/accounts/${accountId}/workers/dispatch/namespaces`,
|
|
58
|
+
{
|
|
59
|
+
headers: {
|
|
60
|
+
"Content-Type": "application/json",
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Get info for a specific dynamic dispatch namespace
|
|
69
|
+
*/
|
|
70
|
+
async function getWorkerNamespaceInfo(accountId: string, name: string) {
|
|
71
|
+
logger.log(
|
|
72
|
+
await fetchResult<Namespace>(
|
|
73
|
+
`/accounts/${accountId}/workers/dispatch/namespaces/${name}`,
|
|
74
|
+
{
|
|
75
|
+
headers: {
|
|
76
|
+
"Content-Type": "application/json",
|
|
77
|
+
},
|
|
78
|
+
}
|
|
79
|
+
)
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Rename a dynamic dispatch namespace
|
|
85
|
+
*/
|
|
86
|
+
async function renameWorkerNamespace(
|
|
87
|
+
accountId: string,
|
|
88
|
+
oldName: string,
|
|
89
|
+
newName: string
|
|
90
|
+
) {
|
|
91
|
+
printWranglerBanner();
|
|
92
|
+
|
|
93
|
+
await fetchResult(
|
|
94
|
+
`/accounts/${accountId}/workers/dispatch/namespaces/${oldName}`,
|
|
95
|
+
{
|
|
96
|
+
method: "PUT",
|
|
97
|
+
headers: {
|
|
98
|
+
"Content-Type": "application/json",
|
|
99
|
+
},
|
|
100
|
+
body: JSON.stringify({ name: newName }),
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
logger.log(`Renamed Worker namespace "${oldName}" to "${newName}"`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function workerNamespaceCommands(
|
|
107
|
+
workerNamespaceYargs: Argv,
|
|
108
|
+
subHelp: CommandModule
|
|
109
|
+
): Argv {
|
|
110
|
+
return workerNamespaceYargs
|
|
111
|
+
.command(subHelp)
|
|
112
|
+
.command("list", "List all Worker namespaces", {}, async (args) => {
|
|
113
|
+
const config = readConfig(args.config as ConfigPath, args);
|
|
114
|
+
const accountId = await requireAuth(config);
|
|
115
|
+
await listWorkerNamespaces(accountId);
|
|
116
|
+
})
|
|
117
|
+
.command(
|
|
118
|
+
"get <name>",
|
|
119
|
+
"Get information about a Worker namespace",
|
|
120
|
+
(yargs) => {
|
|
121
|
+
return yargs.positional("name", {
|
|
122
|
+
describe: "Name of the Worker namespace",
|
|
123
|
+
type: "string",
|
|
124
|
+
demandOption: true,
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
async (args) => {
|
|
128
|
+
const config = readConfig(args.config as ConfigPath, args);
|
|
129
|
+
const accountId = await requireAuth(config);
|
|
130
|
+
await getWorkerNamespaceInfo(accountId, args.name);
|
|
131
|
+
}
|
|
132
|
+
)
|
|
133
|
+
.command(
|
|
134
|
+
"create <name>",
|
|
135
|
+
"Create a Worker namespace",
|
|
136
|
+
(yargs) => {
|
|
137
|
+
return yargs.positional("name", {
|
|
138
|
+
describe: "Name of the Worker namespace",
|
|
139
|
+
type: "string",
|
|
140
|
+
demandOption: true,
|
|
141
|
+
});
|
|
142
|
+
},
|
|
143
|
+
async (args) => {
|
|
144
|
+
await printWranglerBanner();
|
|
145
|
+
const config = readConfig(args.config as ConfigPath, args);
|
|
146
|
+
const accountId = await requireAuth(config);
|
|
147
|
+
await createWorkerNamespace(accountId, args.name);
|
|
148
|
+
}
|
|
149
|
+
)
|
|
150
|
+
.command(
|
|
151
|
+
"delete <name>",
|
|
152
|
+
"Delete a Worker namespace",
|
|
153
|
+
(yargs) => {
|
|
154
|
+
return yargs.positional("name", {
|
|
155
|
+
describe: "Name of the Worker namespace",
|
|
156
|
+
type: "string",
|
|
157
|
+
demandOption: true,
|
|
158
|
+
});
|
|
159
|
+
},
|
|
160
|
+
async (args) => {
|
|
161
|
+
await printWranglerBanner();
|
|
162
|
+
const config = readConfig(args.config as ConfigPath, args);
|
|
163
|
+
const accountId = await requireAuth(config);
|
|
164
|
+
await deleteWorkerNamespace(accountId, args.name);
|
|
165
|
+
}
|
|
166
|
+
)
|
|
167
|
+
.command(
|
|
168
|
+
"rename <old-name> <new-name>",
|
|
169
|
+
"Rename a Worker namespace",
|
|
170
|
+
(yargs) => {
|
|
171
|
+
return yargs
|
|
172
|
+
.positional("old-name", {
|
|
173
|
+
describe: "Name of the Worker namespace",
|
|
174
|
+
type: "string",
|
|
175
|
+
demandOption: true,
|
|
176
|
+
})
|
|
177
|
+
.positional("new-name", {
|
|
178
|
+
describe: "New name of the Worker namespace",
|
|
179
|
+
type: "string",
|
|
180
|
+
demandOption: true,
|
|
181
|
+
});
|
|
182
|
+
},
|
|
183
|
+
async (args) => {
|
|
184
|
+
await printWranglerBanner();
|
|
185
|
+
const config = readConfig(args.config as ConfigPath, args);
|
|
186
|
+
const accountId = await requireAuth(config);
|
|
187
|
+
await renameWorkerNamespace(accountId, args.oldName, args.newName);
|
|
188
|
+
}
|
|
189
|
+
);
|
|
190
|
+
}
|
package/src/worker.ts
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
+
import type { Route } from "./config/environment";
|
|
2
|
+
import type { ApiCredentials } from "./user";
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* A Cloudflare account.
|
|
3
6
|
*/
|
|
4
7
|
export interface CfAccount {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
/**
|
|
9
|
+
* An API token.
|
|
10
|
+
*
|
|
11
|
+
* @link https://api.cloudflare.com/#user-api-tokens-properties
|
|
12
|
+
*/
|
|
13
|
+
apiToken: ApiCredentials;
|
|
14
|
+
/**
|
|
15
|
+
* An account ID.
|
|
16
|
+
*/
|
|
17
|
+
accountId: string;
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
/**
|
|
@@ -23,55 +26,55 @@ export type CfScriptFormat = "modules" | "service-worker";
|
|
|
23
26
|
* A module type.
|
|
24
27
|
*/
|
|
25
28
|
export type CfModuleType =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
| "esm"
|
|
30
|
+
| "commonjs"
|
|
31
|
+
| "compiled-wasm"
|
|
32
|
+
| "text"
|
|
33
|
+
| "buffer";
|
|
31
34
|
|
|
32
35
|
/**
|
|
33
36
|
* An imported module.
|
|
34
37
|
*/
|
|
35
38
|
export interface CfModule {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
39
|
+
/**
|
|
40
|
+
* The module name.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* './src/index.js'
|
|
44
|
+
*/
|
|
45
|
+
name: string;
|
|
46
|
+
/**
|
|
47
|
+
* The module content, usually JavaScript or WASM code.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* export default {
|
|
51
|
+
* async fetch(request) {
|
|
52
|
+
* return new Response('Ok')
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
*/
|
|
56
|
+
content: string | Buffer;
|
|
57
|
+
/**
|
|
58
|
+
* The module type.
|
|
59
|
+
*
|
|
60
|
+
* If absent, will default to the main module's type.
|
|
61
|
+
*/
|
|
62
|
+
type?: CfModuleType;
|
|
60
63
|
}
|
|
61
64
|
|
|
62
65
|
/**
|
|
63
66
|
* A map of variable names to values.
|
|
64
67
|
*/
|
|
65
68
|
interface CfVars {
|
|
66
|
-
|
|
69
|
+
[key: string]: unknown;
|
|
67
70
|
}
|
|
68
71
|
|
|
69
72
|
/**
|
|
70
73
|
* A KV namespace.
|
|
71
74
|
*/
|
|
72
75
|
interface CfKvNamespace {
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
binding: string;
|
|
77
|
+
id: string;
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
/**
|
|
@@ -79,7 +82,7 @@ interface CfKvNamespace {
|
|
|
79
82
|
*/
|
|
80
83
|
|
|
81
84
|
interface CfWasmModuleBindings {
|
|
82
|
-
|
|
85
|
+
[key: string]: string;
|
|
83
86
|
}
|
|
84
87
|
|
|
85
88
|
/**
|
|
@@ -87,7 +90,7 @@ interface CfWasmModuleBindings {
|
|
|
87
90
|
*/
|
|
88
91
|
|
|
89
92
|
interface CfTextBlobBindings {
|
|
90
|
-
|
|
93
|
+
[key: string]: string;
|
|
91
94
|
}
|
|
92
95
|
|
|
93
96
|
/**
|
|
@@ -95,87 +98,94 @@ interface CfTextBlobBindings {
|
|
|
95
98
|
*/
|
|
96
99
|
|
|
97
100
|
interface CfDataBlobBindings {
|
|
98
|
-
|
|
101
|
+
[key: string]: string;
|
|
99
102
|
}
|
|
100
103
|
|
|
101
104
|
/**
|
|
102
105
|
* A Durable Object.
|
|
103
106
|
*/
|
|
104
107
|
interface CfDurableObject {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
108
|
+
name: string;
|
|
109
|
+
class_name: string;
|
|
110
|
+
script_name?: string;
|
|
111
|
+
environment?: string;
|
|
109
112
|
}
|
|
110
113
|
|
|
111
114
|
interface CfR2Bucket {
|
|
112
|
-
|
|
113
|
-
|
|
115
|
+
binding: string;
|
|
116
|
+
bucket_name: string;
|
|
114
117
|
}
|
|
115
118
|
|
|
116
119
|
interface CfService {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
+
binding: string;
|
|
121
|
+
service: string;
|
|
122
|
+
environment?: string;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
interface CfWorkerNamespace {
|
|
126
|
+
binding: string;
|
|
127
|
+
namespace: string;
|
|
120
128
|
}
|
|
121
129
|
|
|
122
130
|
interface CfUnsafeBinding {
|
|
123
|
-
|
|
124
|
-
|
|
131
|
+
name: string;
|
|
132
|
+
type: string;
|
|
125
133
|
}
|
|
126
134
|
|
|
127
135
|
export interface CfDurableObjectMigrations {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
old_tag?: string;
|
|
137
|
+
new_tag: string;
|
|
138
|
+
steps: {
|
|
139
|
+
new_classes?: string[];
|
|
140
|
+
renamed_classes?: {
|
|
141
|
+
from: string;
|
|
142
|
+
to: string;
|
|
143
|
+
}[];
|
|
144
|
+
deleted_classes?: string[];
|
|
145
|
+
}[];
|
|
138
146
|
}
|
|
139
147
|
|
|
140
148
|
/**
|
|
141
149
|
* Options for creating a `CfWorker`.
|
|
142
150
|
*/
|
|
143
151
|
export interface CfWorkerInit {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
152
|
+
/**
|
|
153
|
+
* The name of the worker.
|
|
154
|
+
*/
|
|
155
|
+
name: string | undefined;
|
|
156
|
+
/**
|
|
157
|
+
* The entrypoint module.
|
|
158
|
+
*/
|
|
159
|
+
main: CfModule;
|
|
160
|
+
/**
|
|
161
|
+
* The list of additional modules.
|
|
162
|
+
*/
|
|
163
|
+
modules: CfModule[] | undefined;
|
|
164
|
+
/**
|
|
165
|
+
* All the bindings
|
|
166
|
+
*/
|
|
167
|
+
bindings: {
|
|
168
|
+
vars: CfVars | undefined;
|
|
169
|
+
kv_namespaces: CfKvNamespace[] | undefined;
|
|
170
|
+
wasm_modules: CfWasmModuleBindings | undefined;
|
|
171
|
+
text_blobs: CfTextBlobBindings | undefined;
|
|
172
|
+
data_blobs: CfDataBlobBindings | undefined;
|
|
173
|
+
durable_objects: { bindings: CfDurableObject[] } | undefined;
|
|
174
|
+
r2_buckets: CfR2Bucket[] | undefined;
|
|
175
|
+
services: CfService[] | undefined;
|
|
176
|
+
worker_namespaces: CfWorkerNamespace[] | undefined;
|
|
177
|
+
unsafe: CfUnsafeBinding[] | undefined;
|
|
178
|
+
};
|
|
179
|
+
migrations: CfDurableObjectMigrations | undefined;
|
|
180
|
+
compatibility_date: string | undefined;
|
|
181
|
+
compatibility_flags: string[] | undefined;
|
|
182
|
+
usage_model: "bundled" | "unbound" | undefined;
|
|
174
183
|
}
|
|
175
184
|
|
|
176
185
|
export interface CfWorkerContext {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
186
|
+
env: string | undefined;
|
|
187
|
+
legacyEnv: boolean | undefined;
|
|
188
|
+
zone: string | undefined;
|
|
189
|
+
host: string | undefined;
|
|
190
|
+
routes: Route[] | undefined;
|
|
181
191
|
}
|