wrangler 0.0.0-beta.6 → 0.0.0-c6eb564
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 +18 -19
- package/src/__tests__/index.test.ts +66 -31
- package/src/__tests__/mock-cfetch.js +6 -13
- package/src/api/form_data.ts +35 -19
- package/src/api/preview.ts +28 -23
- package/src/api/worker.ts +24 -3
- package/src/config.ts +27 -5
- package/src/dev.tsx +52 -15
- package/src/dialogs.tsx +1 -1
- package/src/index.tsx +72 -21
- package/src/kv.tsx +2 -2
- package/src/module-collection.ts +64 -0
- package/src/pages.tsx +586 -80
- package/src/publish.ts +72 -14
- package/src/sites.tsx +1 -1
- package/src/tail.tsx +1 -1
- package/wrangler-dist/cli.js +27821 -39497
- package/wrangler-dist/cli.js.map +3 -3
- package/src/util/fetch.ts +0 -74
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wrangler",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-c6eb564",
|
|
4
4
|
"author": "wrangler@cloudflare.com",
|
|
5
5
|
"description": "Command-line interface for all things Cloudflare Workers",
|
|
6
6
|
"bin": {
|
|
@@ -36,11 +36,10 @@
|
|
|
36
36
|
"cli"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@cloudflare/pages-functions-compiler": "0.3.
|
|
40
|
-
"esbuild": "0.
|
|
41
|
-
"miniflare": "2.0.0-rc.
|
|
42
|
-
"semiver": "^1.1.0"
|
|
43
|
-
"serve": "^13.0.2"
|
|
39
|
+
"@cloudflare/pages-functions-compiler": "0.3.8",
|
|
40
|
+
"esbuild": "0.14.1",
|
|
41
|
+
"miniflare": "2.0.0-rc.3",
|
|
42
|
+
"semiver": "^1.1.0"
|
|
44
43
|
},
|
|
45
44
|
"optionalDependencies": {
|
|
46
45
|
"fsevents": "~2.3.2"
|
|
@@ -49,32 +48,32 @@
|
|
|
49
48
|
"@iarna/toml": "^2.2.5",
|
|
50
49
|
"@types/cloudflare": "^2.7.6",
|
|
51
50
|
"@types/express": "^4.17.13",
|
|
52
|
-
"@types/react": "^17.0.
|
|
51
|
+
"@types/react": "^17.0.37",
|
|
53
52
|
"@types/signal-exit": "^3.0.1",
|
|
54
|
-
"@types/ws": "^8.2.
|
|
55
|
-
"@types/yargs": "^17.0.
|
|
53
|
+
"@types/ws": "^8.2.1",
|
|
54
|
+
"@types/yargs": "^17.0.7",
|
|
55
|
+
"chokidar": "^3.5.2",
|
|
56
56
|
"clipboardy": "^3.0.0",
|
|
57
57
|
"command-exists": "^1.2.9",
|
|
58
|
-
"execa": "^
|
|
59
|
-
"express": "^4.17.1",
|
|
58
|
+
"execa": "^6.0.0",
|
|
60
59
|
"finalhandler": "^1.1.2",
|
|
61
60
|
"find-up": "^6.2.0",
|
|
62
61
|
"formdata-node": "^4.3.1",
|
|
63
62
|
"http-proxy": "^1.18.1",
|
|
64
|
-
"http-proxy-middleware": "^2.0.1",
|
|
65
63
|
"ink": "^3.2.0",
|
|
66
|
-
"ink-select-input": "^4.2.
|
|
64
|
+
"ink-select-input": "^4.2.1",
|
|
67
65
|
"ink-table": "^3.0.0",
|
|
68
|
-
"ink-text-input": "^4.0.
|
|
66
|
+
"ink-text-input": "^4.0.2",
|
|
69
67
|
"node-fetch": "^3.1.0",
|
|
70
68
|
"open": "^8.4.0",
|
|
71
69
|
"path-to-regexp": "^6.2.0",
|
|
72
70
|
"react": "^17.0.2",
|
|
73
71
|
"serve-static": "^1.14.1",
|
|
74
|
-
"signal-exit": "^3.0.
|
|
72
|
+
"signal-exit": "^3.0.6",
|
|
75
73
|
"tmp-promise": "^3.0.3",
|
|
76
|
-
"
|
|
77
|
-
"
|
|
74
|
+
"undici": "^4.11.1",
|
|
75
|
+
"ws": "^8.3.0",
|
|
76
|
+
"yargs": "^17.3.0"
|
|
78
77
|
},
|
|
79
78
|
"files": [
|
|
80
79
|
"src",
|
|
@@ -98,7 +97,7 @@
|
|
|
98
97
|
"jest": {
|
|
99
98
|
"testRegex": ".*.(test|spec)\\.[jt]sx?$",
|
|
100
99
|
"transformIgnorePatterns": [
|
|
101
|
-
"node_modules/(?!node-fetch|fetch-blob|find-up|locate-path|p-locate|p-limit|yocto-queue|path-exists|data-uri-to-buffer|formdata-polyfill)"
|
|
100
|
+
"node_modules/(?!node-fetch|fetch-blob|find-up|locate-path|p-locate|p-limit|yocto-queue|path-exists|data-uri-to-buffer|formdata-polyfill|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream)"
|
|
102
101
|
],
|
|
103
102
|
"moduleNameMapper": {
|
|
104
103
|
"clipboardy": "<rootDir>/src/__tests__/clipboardy-mock.js"
|
|
@@ -112,4 +111,4 @@
|
|
|
112
111
|
]
|
|
113
112
|
}
|
|
114
113
|
}
|
|
115
|
-
}
|
|
114
|
+
}
|
|
@@ -3,12 +3,9 @@ import * as fsp from "node:fs/promises";
|
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import * as TOML from "@iarna/toml";
|
|
5
5
|
import { main } from "../index";
|
|
6
|
-
|
|
7
|
-
import { setMock, unsetAllMocks } from "../cfetch";
|
|
6
|
+
import { setMock, unsetAllMocks } from "./mock-cfetch";
|
|
8
7
|
|
|
9
|
-
jest.mock("../cfetch", () =>
|
|
10
|
-
return jest.requireActual("./mock-cfetch");
|
|
11
|
-
});
|
|
8
|
+
jest.mock("../cfetch", () => jest.requireActual("./mock-cfetch"));
|
|
12
9
|
|
|
13
10
|
async function w(cmd: void | string, options?: { tap: boolean }) {
|
|
14
11
|
const tapped = options?.tap ? tap() : undefined;
|
|
@@ -44,31 +41,69 @@ function tap() {
|
|
|
44
41
|
}
|
|
45
42
|
|
|
46
43
|
describe("wrangler", () => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
44
|
+
describe("no command", () => {
|
|
45
|
+
it("should display a list of available commands", async () => {
|
|
46
|
+
const { stdout, stderr } = await w(undefined, { tap: true });
|
|
47
|
+
|
|
48
|
+
expect(stdout).toMatchInlineSnapshot(`
|
|
49
|
+
"wrangler
|
|
50
|
+
|
|
51
|
+
Commands:
|
|
52
|
+
wrangler init [name] 📥 Create a wrangler.toml configuration file
|
|
53
|
+
wrangler dev <filename> 👂 Start a local server for developing your worker
|
|
54
|
+
wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
|
|
55
|
+
wrangler tail [name] 🦚 Starts a log tailing session for a deployed Worker.
|
|
56
|
+
wrangler secret 🤫 Generate a secret that can be referenced in the worker script
|
|
57
|
+
wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
|
|
58
|
+
wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
|
|
59
|
+
wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
|
|
60
|
+
wrangler pages ⚡️ Configure Cloudflare Pages
|
|
61
|
+
|
|
62
|
+
Flags:
|
|
63
|
+
-c, --config Path to .toml configuration file [string]
|
|
64
|
+
-h, --help Show help [boolean]
|
|
65
|
+
-v, --version Show version number [boolean]
|
|
66
|
+
|
|
67
|
+
Options:
|
|
68
|
+
-l, --local Run on my machine [boolean] [default: false]"
|
|
69
|
+
`);
|
|
70
|
+
|
|
71
|
+
expect(stderr).toEqual("");
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe("invalid command", () => {
|
|
76
|
+
it("should display an error", async () => {
|
|
77
|
+
const { stdout, stderr } = await w("invalid-command", { tap: true });
|
|
78
|
+
|
|
79
|
+
expect(stdout).toMatchInlineSnapshot(`
|
|
80
|
+
"wrangler
|
|
81
|
+
|
|
82
|
+
Commands:
|
|
83
|
+
wrangler init [name] 📥 Create a wrangler.toml configuration file
|
|
84
|
+
wrangler dev <filename> 👂 Start a local server for developing your worker
|
|
85
|
+
wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
|
|
86
|
+
wrangler tail [name] 🦚 Starts a log tailing session for a deployed Worker.
|
|
87
|
+
wrangler secret 🤫 Generate a secret that can be referenced in the worker script
|
|
88
|
+
wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
|
|
89
|
+
wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
|
|
90
|
+
wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
|
|
91
|
+
wrangler pages ⚡️ Configure Cloudflare Pages
|
|
92
|
+
|
|
93
|
+
Flags:
|
|
94
|
+
-c, --config Path to .toml configuration file [string]
|
|
95
|
+
-h, --help Show help [boolean]
|
|
96
|
+
-v, --version Show version number [boolean]
|
|
97
|
+
|
|
98
|
+
Options:
|
|
99
|
+
-l, --local Run on my machine [boolean] [default: false]"
|
|
100
|
+
`);
|
|
101
|
+
|
|
102
|
+
expect(stderr).toMatchInlineSnapshot(`
|
|
103
|
+
"
|
|
104
|
+
Unknown command: invalid-command."
|
|
105
|
+
`);
|
|
106
|
+
});
|
|
72
107
|
});
|
|
73
108
|
|
|
74
109
|
describe("init", () => {
|
|
@@ -110,7 +145,7 @@ describe("wrangler", () => {
|
|
|
110
145
|
return { id: "some-namespace-id" };
|
|
111
146
|
});
|
|
112
147
|
|
|
113
|
-
await w(
|
|
148
|
+
await w("kv:namespace create UnitTestNamespace");
|
|
114
149
|
expect(
|
|
115
150
|
KVNamespaces.find((ns) => ns.title === `worker-UnitTestNamespace`)
|
|
116
151
|
).toBeTruthy();
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// This file mocks ../cfetch.ts
|
|
2
2
|
// so we can insert whatever responses we want from it
|
|
3
3
|
|
|
4
|
-
const pathToRegexp = require("path-to-regexp");
|
|
4
|
+
const { pathToRegexp } = require("path-to-regexp");
|
|
5
5
|
// TODO: add jsdoc style types here
|
|
6
6
|
|
|
7
7
|
// type MockHandler = (resource: string, init?: RequestInit) => any; // TODO: use a generic here
|
|
8
8
|
|
|
9
9
|
let mocks = [];
|
|
10
10
|
|
|
11
|
-
function mockCfetch(resource, init) {
|
|
11
|
+
export function mockCfetch(resource, init) {
|
|
12
12
|
for (const { regexp, handler } of mocks) {
|
|
13
13
|
if (regexp.test(resource)) {
|
|
14
14
|
return handler(resource, init); // should we have some kind of fallthrough system? we'll see.
|
|
@@ -17,7 +17,7 @@ function mockCfetch(resource, init) {
|
|
|
17
17
|
throw new Error(`no mocks found for ${resource}`);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
function setMock(resource, handler) {
|
|
20
|
+
export function setMock(resource, handler) {
|
|
21
21
|
const mock = {
|
|
22
22
|
resource,
|
|
23
23
|
handler,
|
|
@@ -29,18 +29,11 @@ function setMock(resource, handler) {
|
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
function unsetAllMocks() {
|
|
32
|
+
export function unsetAllMocks() {
|
|
33
33
|
mocks = [];
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
const CF_API_BASE_URL =
|
|
36
|
+
export const CF_API_BASE_URL =
|
|
37
37
|
process.env.CF_API_BASE_URL || "https://api.cloudflare.com/client/v4";
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
__esModule: true,
|
|
41
|
-
default: mockCfetch,
|
|
42
|
-
mockCfetch,
|
|
43
|
-
setMock,
|
|
44
|
-
unsetAllMocks,
|
|
45
|
-
CF_API_BASE_URL,
|
|
46
|
-
});
|
|
39
|
+
export default mockCfetch;
|
package/src/api/form_data.ts
CHANGED
|
@@ -3,8 +3,6 @@ import type {
|
|
|
3
3
|
CfModuleType,
|
|
4
4
|
CfVariable,
|
|
5
5
|
CfModule,
|
|
6
|
-
CfKvNamespace,
|
|
7
|
-
CfCryptoKey,
|
|
8
6
|
} from "./worker.js";
|
|
9
7
|
import { FormData, Blob } from "formdata-node";
|
|
10
8
|
|
|
@@ -27,12 +25,26 @@ function toBinding(
|
|
|
27
25
|
return { name, type: "plain_text", text: variable };
|
|
28
26
|
}
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
if ("namespaceId" in variable) {
|
|
29
|
+
return {
|
|
30
|
+
name,
|
|
31
|
+
type: "kv_namespace",
|
|
32
|
+
namespace_id: variable.namespaceId,
|
|
33
|
+
};
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
if ("class_name" in variable) {
|
|
37
|
+
return {
|
|
38
|
+
name,
|
|
39
|
+
type: "durable_object_namespace",
|
|
40
|
+
class_name: variable.class_name,
|
|
41
|
+
...(variable.script_name && {
|
|
42
|
+
script_name: variable.script_name,
|
|
43
|
+
}),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const { format, algorithm, usages, data } = variable;
|
|
36
48
|
if (format) {
|
|
37
49
|
let key_base64;
|
|
38
50
|
let key_jwk;
|
|
@@ -84,7 +96,15 @@ function toModule(module: CfModule, entryType?: CfModuleType): Blob {
|
|
|
84
96
|
*/
|
|
85
97
|
export function toFormData(worker: CfWorkerInit): FormData {
|
|
86
98
|
const formData = new FormData();
|
|
87
|
-
const {
|
|
99
|
+
const {
|
|
100
|
+
main,
|
|
101
|
+
modules,
|
|
102
|
+
variables,
|
|
103
|
+
migrations,
|
|
104
|
+
usage_model,
|
|
105
|
+
compatibility_date,
|
|
106
|
+
compatibility_flags,
|
|
107
|
+
} = worker;
|
|
88
108
|
const { name, type: mainType } = main;
|
|
89
109
|
|
|
90
110
|
const bindings = [];
|
|
@@ -93,23 +113,19 @@ export function toFormData(worker: CfWorkerInit): FormData {
|
|
|
93
113
|
bindings.push(binding);
|
|
94
114
|
}
|
|
95
115
|
|
|
96
|
-
|
|
116
|
+
// TODO: this object should be typed
|
|
97
117
|
const metadata = {
|
|
98
|
-
main_module:
|
|
99
|
-
body_part: singleton ? name : undefined,
|
|
118
|
+
...(mainType !== "commonjs" ? { main_module: name } : { body_part: name }),
|
|
100
119
|
bindings,
|
|
120
|
+
...(compatibility_date && { compatibility_date }),
|
|
121
|
+
...(compatibility_flags && { compatibility_flags }),
|
|
122
|
+
...(usage_model && { usage_model }),
|
|
123
|
+
...(migrations && { migrations }),
|
|
101
124
|
};
|
|
102
|
-
|
|
103
|
-
// @ts-expect-error - we should type metadata
|
|
104
|
-
metadata.compatibility_date = compatibility_date;
|
|
105
|
-
}
|
|
106
|
-
if (usage_model) {
|
|
107
|
-
// @ts-expect-error - we should type metadata
|
|
108
|
-
metadata.usage_model = usage_model;
|
|
109
|
-
}
|
|
125
|
+
|
|
110
126
|
formData.set("metadata", JSON.stringify(metadata));
|
|
111
127
|
|
|
112
|
-
if (
|
|
128
|
+
if (mainType === "commonjs" && modules && modules.length > 0) {
|
|
113
129
|
throw new TypeError(
|
|
114
130
|
"More than one module can only be specified when type = 'esm'"
|
|
115
131
|
);
|
package/src/api/preview.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import cfetch from "../cfetch";
|
|
2
|
-
import { fetchJson } from "../util/fetch";
|
|
3
2
|
import { toFormData } from "./form_data";
|
|
4
3
|
import type { CfAccount, CfWorkerInit } from "./worker";
|
|
4
|
+
import fetch from "node-fetch";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* A preview mode.
|
|
@@ -9,7 +9,7 @@ import type { CfAccount, CfWorkerInit } from "./worker";
|
|
|
9
9
|
* * If true, then using a `workers.dev` subdomain.
|
|
10
10
|
* * Otherwise, a list of routes under a single zone.
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
type CfPreviewMode = { workers_dev: boolean } | { routes: string[] };
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* A preview token.
|
|
@@ -60,17 +60,17 @@ async function sessionToken(account: CfAccount): Promise<CfPreviewToken> {
|
|
|
60
60
|
? `/zones/${zoneId}/workers/edge-preview`
|
|
61
61
|
: `/accounts/${accountId}/workers/subdomain/edge-preview`;
|
|
62
62
|
|
|
63
|
-
const { exchange_url
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const { host } = new URL(
|
|
63
|
+
const { exchange_url } = await cfetch<{ exchange_url: string }>(initUrl);
|
|
64
|
+
const { inspector_websocket, token } = (await (
|
|
65
|
+
await fetch(exchange_url)
|
|
66
|
+
).json()) as { inspector_websocket: string; token: string };
|
|
67
|
+
const { host } = new URL(inspector_websocket);
|
|
68
68
|
const query = `cf_workers_preview_token=${token}`;
|
|
69
69
|
|
|
70
70
|
return {
|
|
71
71
|
value: token,
|
|
72
72
|
host,
|
|
73
|
-
inspectorUrl: new URL(`${
|
|
73
|
+
inspectorUrl: new URL(`${inspector_websocket}?${query}`),
|
|
74
74
|
prewarmUrl: new URL(
|
|
75
75
|
`https://${host}/cdn-cgi/workers/preview/prewarm?${query}`
|
|
76
76
|
),
|
|
@@ -96,27 +96,32 @@ export async function previewToken(
|
|
|
96
96
|
const { value, host, inspectorUrl, prewarmUrl } = await sessionToken(account);
|
|
97
97
|
|
|
98
98
|
const { accountId, zoneId } = account;
|
|
99
|
-
const scriptId = zoneId ? randomId() : host.split(".")[0];
|
|
99
|
+
const scriptId = zoneId ? randomId() : worker.name || host.split(".")[0];
|
|
100
100
|
const url = `/accounts/${accountId}/workers/scripts/${scriptId}/edge-preview`;
|
|
101
101
|
|
|
102
|
-
const mode = zoneId
|
|
102
|
+
const mode: CfPreviewMode = zoneId
|
|
103
|
+
? { routes: ["*/*"] }
|
|
104
|
+
: { workers_dev: true };
|
|
105
|
+
|
|
103
106
|
const formData = toFormData(worker);
|
|
104
107
|
formData.set("wrangler-session-config", JSON.stringify(mode));
|
|
105
108
|
|
|
106
|
-
const { preview_token
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
);
|
|
109
|
+
const { preview_token } = await cfetch<{ preview_token: string }>(url, {
|
|
110
|
+
method: "POST",
|
|
111
|
+
// @ts-expect-error TODO: fix this
|
|
112
|
+
body: formData,
|
|
113
|
+
headers: {
|
|
114
|
+
"cf-preview-upload-config-token": value,
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
|
|
117
118
|
return {
|
|
118
|
-
value:
|
|
119
|
-
|
|
119
|
+
value: preview_token,
|
|
120
|
+
// TODO: verify this works with zoned workers
|
|
121
|
+
host:
|
|
122
|
+
worker.name && !zoneId
|
|
123
|
+
? `${worker.name}.${host.split(".").slice(1).join(".")}`
|
|
124
|
+
: host,
|
|
120
125
|
inspectorUrl,
|
|
121
126
|
prewarmUrl,
|
|
122
127
|
};
|
package/src/api/worker.ts
CHANGED
|
@@ -72,6 +72,21 @@ export interface CfKvNamespace {
|
|
|
72
72
|
namespaceId: string;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
export interface CfDurableObject {
|
|
76
|
+
class_name: string;
|
|
77
|
+
script_name?: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
interface CfDOMigrations {
|
|
81
|
+
old_tag?: string;
|
|
82
|
+
new_tag: string;
|
|
83
|
+
steps: {
|
|
84
|
+
new_classes?: string[];
|
|
85
|
+
renamed_classes?: string[];
|
|
86
|
+
deleted_classes?: string[];
|
|
87
|
+
}[];
|
|
88
|
+
}
|
|
89
|
+
|
|
75
90
|
/**
|
|
76
91
|
* A `WebCrypto` key.
|
|
77
92
|
*
|
|
@@ -99,12 +114,16 @@ export interface CfCryptoKey {
|
|
|
99
114
|
/**
|
|
100
115
|
* A variable (aka. environment variable).
|
|
101
116
|
*/
|
|
102
|
-
export type CfVariable = string | CfKvNamespace | CfCryptoKey;
|
|
117
|
+
export type CfVariable = string | CfKvNamespace | CfCryptoKey | CfDurableObject;
|
|
103
118
|
|
|
104
119
|
/**
|
|
105
120
|
* Options for creating a `CfWorker`.
|
|
106
121
|
*/
|
|
107
122
|
export interface CfWorkerInit {
|
|
123
|
+
/**
|
|
124
|
+
* The name of the worker.
|
|
125
|
+
*/
|
|
126
|
+
name: string | void;
|
|
108
127
|
/**
|
|
109
128
|
* The entrypoint module.
|
|
110
129
|
*/
|
|
@@ -117,8 +136,10 @@ export interface CfWorkerInit {
|
|
|
117
136
|
* The map of names to variables. (aka. environment variables)
|
|
118
137
|
*/
|
|
119
138
|
variables?: { [name: string]: CfVariable };
|
|
120
|
-
|
|
121
|
-
|
|
139
|
+
migrations: void | CfDOMigrations;
|
|
140
|
+
compatibility_date: string | void;
|
|
141
|
+
compatibility_flags: void | string[];
|
|
142
|
+
usage_model: void | "bundled" | "unbound";
|
|
122
143
|
}
|
|
123
144
|
|
|
124
145
|
/**
|
package/src/config.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
// we're going to manually write both the type definition AND
|
|
2
2
|
// the validator for the config, so that we can give better error messages
|
|
3
3
|
|
|
4
|
+
type DOMigration = {
|
|
5
|
+
tag: string;
|
|
6
|
+
new_classes?: string[];
|
|
7
|
+
renamed_classes?: string[];
|
|
8
|
+
deleted_classes?: string[];
|
|
9
|
+
};
|
|
10
|
+
|
|
4
11
|
type Project = "webpack" | "javascript" | "rust";
|
|
5
12
|
|
|
6
13
|
type Site = {
|
|
@@ -28,6 +35,12 @@ type KVNamespace = {
|
|
|
28
35
|
id: string;
|
|
29
36
|
};
|
|
30
37
|
|
|
38
|
+
type DurableObject = {
|
|
39
|
+
name: string;
|
|
40
|
+
class_name: string;
|
|
41
|
+
script_name?: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
31
44
|
type Build = {
|
|
32
45
|
command?: string;
|
|
33
46
|
cwd?: string;
|
|
@@ -59,16 +72,21 @@ type Env = {
|
|
|
59
72
|
name?: string; // inherited
|
|
60
73
|
account_id?: string; // inherited
|
|
61
74
|
workers_dev?: boolean; // inherited
|
|
75
|
+
compatibility_date?: string; // inherited
|
|
76
|
+
compatibility_flags?: string[]; // inherited
|
|
62
77
|
zone_id?: string; // inherited
|
|
63
78
|
routes?: string[]; // inherited
|
|
64
79
|
route?: string; // inherited
|
|
65
80
|
webpack_config?: string; // inherited
|
|
66
81
|
site?: Site;
|
|
67
|
-
|
|
68
|
-
|
|
82
|
+
jsx_factory?: string; // inherited
|
|
83
|
+
jsx_fragment?: string; // inherited
|
|
69
84
|
// we should use typescript to parse cron patterns
|
|
70
85
|
triggers?: { crons: Cron[] }; // inherited
|
|
86
|
+
vars?: Vars;
|
|
87
|
+
durable_objects?: { bindings: DurableObject[] };
|
|
71
88
|
kv_namespaces?: KVNamespace[];
|
|
89
|
+
usage_model?: UsageModel; // inherited
|
|
72
90
|
};
|
|
73
91
|
|
|
74
92
|
export type Config = {
|
|
@@ -76,6 +94,8 @@ export type Config = {
|
|
|
76
94
|
account_id?: string; // inherited
|
|
77
95
|
// @deprecated Don't use this
|
|
78
96
|
type?: Project; // top level
|
|
97
|
+
compatibility_date?: string; // inherited
|
|
98
|
+
compatibility_flags?: string[]; // inherited
|
|
79
99
|
// -- there's some mutually exclusive logic for this next block,
|
|
80
100
|
// but I didn't bother for now
|
|
81
101
|
workers_dev?: boolean; // inherited
|
|
@@ -85,9 +105,11 @@ export type Config = {
|
|
|
85
105
|
// -- end mutually exclusive stuff
|
|
86
106
|
// @deprecated Don't use this
|
|
87
107
|
webpack_config?: string; // inherited
|
|
88
|
-
|
|
89
|
-
|
|
108
|
+
jsx_factory?: string; // inherited
|
|
109
|
+
jsx_fragment?: string; // inherited
|
|
90
110
|
vars?: Vars;
|
|
111
|
+
migrations?: DOMigration[];
|
|
112
|
+
durable_objects?: { bindings: DurableObject[] };
|
|
91
113
|
kv_namespaces?: KVNamespace[];
|
|
92
114
|
site?: Site; // inherited
|
|
93
115
|
// we should use typescript to parse cron patterns
|
|
@@ -96,5 +118,5 @@ export type Config = {
|
|
|
96
118
|
usage_model?: UsageModel; // inherited
|
|
97
119
|
// top level
|
|
98
120
|
build?: Build;
|
|
99
|
-
env?: { [envName: string]: Env };
|
|
121
|
+
env?: { [envName: string]: void | Env };
|
|
100
122
|
};
|