@cloudflare/config 0.3.0 → 0.5.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/dist/index.d.mts +138 -60
- package/dist/index.mjs +819 -917
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { a as triggers, i as exports$1, n as defineWorker, o as bindings, r as resolveExportDefinition, t as defineSettings } from "./public-D2QZv1n6.mjs";
|
|
2
2
|
import * as nodeModule from "node:module";
|
|
3
|
-
import * as
|
|
4
|
-
import
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
5
5
|
import path2__default, { dirname, isAbsolute, join, resolve } from "node:path";
|
|
6
|
-
import fs2, { existsSync, readFileSync, statSync } from "node:fs";
|
|
7
6
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
8
7
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
9
|
-
import * as z from "zod";
|
|
10
8
|
|
|
11
9
|
//#region rolldown:runtime
|
|
12
10
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -15,144 +13,655 @@ var __commonJS = (cb, mod) => function() {
|
|
|
15
13
|
};
|
|
16
14
|
|
|
17
15
|
//#endregion
|
|
18
|
-
//#region
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
//#region src/schema.ts
|
|
17
|
+
const AssetsSchema = z.strictObject({
|
|
18
|
+
htmlHandling: z.enum([
|
|
19
|
+
"auto-trailing-slash",
|
|
20
|
+
"drop-trailing-slash",
|
|
21
|
+
"force-trailing-slash",
|
|
22
|
+
"none"
|
|
23
|
+
]).optional(),
|
|
24
|
+
notFoundHandling: z.enum([
|
|
25
|
+
"single-page-application",
|
|
26
|
+
"404-page",
|
|
27
|
+
"none"
|
|
28
|
+
]).optional(),
|
|
29
|
+
runWorkerFirst: z.union([z.array(z.string()), z.boolean()]).optional()
|
|
23
30
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
31
|
+
const BrowserBindingSchema = z.strictObject({
|
|
32
|
+
type: z.literal("browser"),
|
|
33
|
+
remote: z.boolean().optional()
|
|
34
|
+
});
|
|
35
|
+
const WorkerBindingSchema = z.strictObject({
|
|
36
|
+
type: z.literal("worker"),
|
|
37
|
+
workerName: z.string(),
|
|
38
|
+
exportName: z.string().optional(),
|
|
39
|
+
props: z.record(z.string(), z.unknown()).optional(),
|
|
40
|
+
remote: z.boolean().optional()
|
|
41
|
+
});
|
|
42
|
+
const D1BindingSchema = z.strictObject({
|
|
43
|
+
type: z.literal("d1"),
|
|
44
|
+
name: z.string().optional(),
|
|
45
|
+
id: z.string().optional(),
|
|
46
|
+
remote: z.boolean().optional()
|
|
47
|
+
});
|
|
48
|
+
const KVBindingSchema = z.strictObject({
|
|
49
|
+
type: z.literal("kv"),
|
|
50
|
+
id: z.string().optional(),
|
|
51
|
+
remote: z.boolean().optional()
|
|
52
|
+
});
|
|
53
|
+
const QueueBindingSchema = z.strictObject({
|
|
54
|
+
type: z.literal("queue"),
|
|
55
|
+
name: z.string().optional(),
|
|
56
|
+
deliveryDelay: z.number().optional(),
|
|
57
|
+
remote: z.boolean().optional()
|
|
58
|
+
});
|
|
59
|
+
const R2BindingSchema = z.strictObject({
|
|
60
|
+
type: z.literal("r2"),
|
|
61
|
+
name: z.string().optional(),
|
|
62
|
+
jurisdiction: z.string().optional(),
|
|
63
|
+
remote: z.boolean().optional()
|
|
64
|
+
});
|
|
65
|
+
const FlagshipBindingSchema = z.strictObject({
|
|
66
|
+
type: z.literal("flagship"),
|
|
67
|
+
id: z.string().optional(),
|
|
68
|
+
remote: z.boolean().optional()
|
|
69
|
+
});
|
|
70
|
+
const HyperdriveBindingSchema = z.strictObject({
|
|
71
|
+
type: z.literal("hyperdrive"),
|
|
72
|
+
id: z.string(),
|
|
73
|
+
localConnectionString: z.string().optional()
|
|
74
|
+
});
|
|
75
|
+
const KnownBindingSchema = z.discriminatedUnion("type", [
|
|
76
|
+
z.strictObject({
|
|
77
|
+
type: z.literal("agent-memory"),
|
|
78
|
+
namespace: z.string(),
|
|
79
|
+
remote: z.boolean().optional()
|
|
80
|
+
}),
|
|
81
|
+
z.strictObject({
|
|
82
|
+
type: z.literal("ai"),
|
|
83
|
+
remote: z.boolean().optional()
|
|
84
|
+
}),
|
|
85
|
+
z.strictObject({
|
|
86
|
+
type: z.literal("ai-search"),
|
|
87
|
+
name: z.string(),
|
|
88
|
+
remote: z.boolean().optional()
|
|
89
|
+
}),
|
|
90
|
+
z.strictObject({
|
|
91
|
+
type: z.literal("ai-search-namespace"),
|
|
92
|
+
namespace: z.string(),
|
|
93
|
+
remote: z.boolean().optional()
|
|
94
|
+
}),
|
|
95
|
+
z.strictObject({
|
|
96
|
+
type: z.literal("analytics-engine-dataset"),
|
|
97
|
+
name: z.string().optional()
|
|
98
|
+
}),
|
|
99
|
+
z.strictObject({
|
|
100
|
+
type: z.literal("artifacts"),
|
|
101
|
+
namespace: z.string(),
|
|
102
|
+
remote: z.boolean().optional()
|
|
103
|
+
}),
|
|
104
|
+
z.strictObject({ type: z.literal("assets") }),
|
|
105
|
+
BrowserBindingSchema,
|
|
106
|
+
D1BindingSchema,
|
|
107
|
+
z.strictObject({
|
|
108
|
+
type: z.literal("dispatch-namespace"),
|
|
109
|
+
namespace: z.string().optional(),
|
|
110
|
+
outbound: z.strictObject({
|
|
111
|
+
workerName: z.string(),
|
|
112
|
+
parameters: z.array(z.string()).optional()
|
|
113
|
+
}).optional(),
|
|
114
|
+
remote: z.boolean().optional()
|
|
115
|
+
}),
|
|
116
|
+
z.strictObject({
|
|
117
|
+
type: z.literal("durable-object"),
|
|
118
|
+
workerName: z.string(),
|
|
119
|
+
exportName: z.string()
|
|
120
|
+
}),
|
|
121
|
+
FlagshipBindingSchema,
|
|
122
|
+
HyperdriveBindingSchema,
|
|
123
|
+
z.strictObject({
|
|
124
|
+
type: z.literal("images"),
|
|
125
|
+
remote: z.boolean().optional()
|
|
126
|
+
}),
|
|
127
|
+
z.strictObject({
|
|
128
|
+
type: z.literal("json"),
|
|
129
|
+
value: z.json()
|
|
130
|
+
}),
|
|
131
|
+
KVBindingSchema,
|
|
132
|
+
z.strictObject({
|
|
133
|
+
type: z.literal("logfwdr"),
|
|
134
|
+
destination: z.string()
|
|
135
|
+
}),
|
|
136
|
+
z.strictObject({
|
|
137
|
+
type: z.literal("media"),
|
|
138
|
+
remote: z.boolean().optional()
|
|
139
|
+
}),
|
|
140
|
+
z.strictObject({
|
|
141
|
+
type: z.literal("mtls-certificate"),
|
|
142
|
+
id: z.string(),
|
|
143
|
+
remote: z.boolean().optional()
|
|
144
|
+
}),
|
|
145
|
+
z.strictObject({
|
|
146
|
+
type: z.literal("pipeline"),
|
|
147
|
+
name: z.string(),
|
|
148
|
+
remote: z.boolean().optional()
|
|
149
|
+
}),
|
|
150
|
+
QueueBindingSchema,
|
|
151
|
+
z.strictObject({
|
|
152
|
+
type: z.literal("rate-limit"),
|
|
153
|
+
namespace: z.string(),
|
|
154
|
+
simple: z.strictObject({
|
|
155
|
+
limit: z.number(),
|
|
156
|
+
period: z.union([z.literal(10), z.literal(60)])
|
|
157
|
+
})
|
|
158
|
+
}),
|
|
159
|
+
R2BindingSchema,
|
|
160
|
+
z.strictObject({ type: z.literal("secret") }),
|
|
161
|
+
z.strictObject({
|
|
162
|
+
type: z.literal("secrets-store-secret"),
|
|
163
|
+
storeId: z.string(),
|
|
164
|
+
secretName: z.string()
|
|
165
|
+
}),
|
|
166
|
+
z.strictObject({
|
|
167
|
+
type: z.literal("send-email"),
|
|
168
|
+
destinationAddress: z.string().optional(),
|
|
169
|
+
allowedDestinationAddresses: z.array(z.string()).optional(),
|
|
170
|
+
allowedSenderAddresses: z.array(z.string()).optional(),
|
|
171
|
+
remote: z.boolean().optional()
|
|
172
|
+
}),
|
|
173
|
+
z.strictObject({
|
|
174
|
+
type: z.literal("stream"),
|
|
175
|
+
remote: z.boolean().optional()
|
|
176
|
+
}),
|
|
177
|
+
z.strictObject({
|
|
178
|
+
type: z.literal("text"),
|
|
179
|
+
value: z.string()
|
|
180
|
+
}),
|
|
181
|
+
z.strictObject({
|
|
182
|
+
type: z.literal("vectorize"),
|
|
183
|
+
name: z.string(),
|
|
184
|
+
remote: z.boolean().optional()
|
|
185
|
+
}),
|
|
186
|
+
z.strictObject({ type: z.literal("version-metadata") }),
|
|
187
|
+
z.strictObject({
|
|
188
|
+
type: z.literal("vpc-service"),
|
|
189
|
+
id: z.string(),
|
|
190
|
+
remote: z.boolean().optional()
|
|
191
|
+
}),
|
|
192
|
+
z.strictObject({
|
|
193
|
+
type: z.literal("vpc-network"),
|
|
194
|
+
tunnelId: z.string().optional(),
|
|
195
|
+
networkId: z.string().optional(),
|
|
196
|
+
remote: z.boolean().optional()
|
|
197
|
+
}).superRefine((value, ctx) => {
|
|
198
|
+
const hasTunnel = value.tunnelId !== void 0;
|
|
199
|
+
if (hasTunnel === (value.networkId !== void 0)) ctx.addIssue({
|
|
200
|
+
code: "custom",
|
|
201
|
+
message: hasTunnel ? `"vpc-network" bindings must specify exactly one of "tunnelId" or "networkId", not both` : `"vpc-network" bindings must specify either "tunnelId" or "networkId"`
|
|
202
|
+
});
|
|
203
|
+
}),
|
|
204
|
+
z.strictObject({
|
|
205
|
+
type: z.literal("web-search"),
|
|
206
|
+
remote: z.boolean().optional()
|
|
207
|
+
}),
|
|
208
|
+
WorkerBindingSchema,
|
|
209
|
+
z.strictObject({ type: z.literal("worker-loader") })
|
|
210
|
+
]);
|
|
211
|
+
const UnsafeBindingSchema = z.looseObject({
|
|
212
|
+
type: z.templateLiteral(["unsafe:", z.string().min(1)]),
|
|
213
|
+
dev: z.strictObject({
|
|
214
|
+
plugin: z.strictObject({
|
|
215
|
+
package: z.string(),
|
|
216
|
+
name: z.string()
|
|
217
|
+
}),
|
|
218
|
+
options: z.record(z.string(), z.unknown()).optional()
|
|
219
|
+
}).optional()
|
|
220
|
+
});
|
|
221
|
+
const BindingSchema = z.unknown().transform((value, ctx) => {
|
|
222
|
+
const result = (typeof value === "object" && value !== null && "type" in value && typeof value.type === "string" && value.type.startsWith("unsafe:") ? UnsafeBindingSchema : KnownBindingSchema).safeParse(value);
|
|
223
|
+
if (!result.success) {
|
|
224
|
+
ctx.issues.push(...result.error.issues);
|
|
225
|
+
return z.NEVER;
|
|
112
226
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return
|
|
227
|
+
return result.data;
|
|
228
|
+
});
|
|
229
|
+
function isParsedUnsafeBinding(binding) {
|
|
230
|
+
return binding.type.startsWith("unsafe:");
|
|
117
231
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
232
|
+
const CacheSchema = z.strictObject({
|
|
233
|
+
enabled: z.boolean(),
|
|
234
|
+
crossVersionCache: z.boolean().optional()
|
|
235
|
+
});
|
|
236
|
+
/**
|
|
237
|
+
* Binding types that can only be defined once per worker.
|
|
238
|
+
*/
|
|
239
|
+
const SINGLETON_BINDING_TYPES = new Set([
|
|
240
|
+
"ai",
|
|
241
|
+
"assets",
|
|
242
|
+
"browser",
|
|
243
|
+
"images",
|
|
244
|
+
"media",
|
|
245
|
+
"stream",
|
|
246
|
+
"version-metadata",
|
|
247
|
+
"web-search"
|
|
248
|
+
]);
|
|
249
|
+
const listFormatter = new Intl.ListFormat("en-US");
|
|
250
|
+
function validateSingletonBindings(env, ctx) {
|
|
251
|
+
const seen = /* @__PURE__ */ new Set();
|
|
252
|
+
const duplicates = /* @__PURE__ */ new Set();
|
|
253
|
+
for (const binding of Object.values(env)) {
|
|
254
|
+
const type = binding.type;
|
|
255
|
+
if (SINGLETON_BINDING_TYPES.has(type)) {
|
|
256
|
+
if (seen.has(type)) duplicates.add(type);
|
|
257
|
+
seen.add(type);
|
|
133
258
|
}
|
|
134
|
-
if (digits < count) value2 = -1;
|
|
135
|
-
return value2;
|
|
136
259
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
260
|
+
if (duplicates.size > 0) ctx.addIssue({
|
|
261
|
+
code: "custom",
|
|
262
|
+
message: `${listFormatter.format([...duplicates].sort())} bindings can only be defined once`
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
const EnvSchema = z.record(z.string(), BindingSchema).superRefine(validateSingletonBindings).optional();
|
|
266
|
+
const DurableObjectCreatedExportSchema = z.strictObject({
|
|
267
|
+
type: z.literal("durable-object"),
|
|
268
|
+
state: z.literal("created").optional(),
|
|
269
|
+
storage: z.enum(["sqlite", "legacy-kv"])
|
|
270
|
+
});
|
|
271
|
+
const DurableObjectDeletedExportSchema = z.strictObject({
|
|
272
|
+
type: z.literal("durable-object"),
|
|
273
|
+
state: z.literal("deleted")
|
|
274
|
+
});
|
|
275
|
+
const DurableObjectRenamedExportSchema = z.strictObject({
|
|
276
|
+
type: z.literal("durable-object"),
|
|
277
|
+
state: z.literal("renamed"),
|
|
278
|
+
renamedTo: z.string()
|
|
279
|
+
});
|
|
280
|
+
const DurableObjectTransferredExportSchema = z.strictObject({
|
|
281
|
+
type: z.literal("durable-object"),
|
|
282
|
+
state: z.literal("transferred"),
|
|
283
|
+
transferredTo: z.string()
|
|
284
|
+
});
|
|
285
|
+
const DurableObjectExpectingTransferExportSchema = z.strictObject({
|
|
286
|
+
type: z.literal("durable-object"),
|
|
287
|
+
state: z.literal("expecting-transfer"),
|
|
288
|
+
storage: z.enum(["sqlite", "legacy-kv"]),
|
|
289
|
+
transferFrom: z.string()
|
|
290
|
+
});
|
|
291
|
+
const WorkerEntrypointExportSchema = z.strictObject({
|
|
292
|
+
type: z.literal("worker"),
|
|
293
|
+
cache: z.strictObject({ enabled: z.boolean() }).optional()
|
|
294
|
+
});
|
|
295
|
+
const ExportSchema = z.union([
|
|
296
|
+
DurableObjectCreatedExportSchema,
|
|
297
|
+
DurableObjectDeletedExportSchema,
|
|
298
|
+
DurableObjectRenamedExportSchema,
|
|
299
|
+
DurableObjectTransferredExportSchema,
|
|
300
|
+
DurableObjectExpectingTransferExportSchema,
|
|
301
|
+
WorkerEntrypointExportSchema
|
|
302
|
+
]);
|
|
303
|
+
const LimitsSchema = z.strictObject({
|
|
304
|
+
cpuMs: z.number().optional(),
|
|
305
|
+
subrequests: z.number().optional()
|
|
306
|
+
});
|
|
307
|
+
const ObservabilitySchema = z.strictObject({
|
|
308
|
+
enabled: z.boolean().optional(),
|
|
309
|
+
headSamplingRate: z.number().optional(),
|
|
310
|
+
logs: z.strictObject({
|
|
311
|
+
enabled: z.boolean().optional(),
|
|
312
|
+
headSamplingRate: z.number().optional(),
|
|
313
|
+
invocationLogs: z.boolean().optional(),
|
|
314
|
+
persist: z.boolean().optional(),
|
|
315
|
+
destinations: z.array(z.string()).optional()
|
|
316
|
+
}).optional(),
|
|
317
|
+
traces: z.strictObject({
|
|
318
|
+
enabled: z.boolean().optional(),
|
|
319
|
+
headSamplingRate: z.number().optional(),
|
|
320
|
+
persist: z.boolean().optional(),
|
|
321
|
+
destinations: z.array(z.string()).optional()
|
|
322
|
+
}).optional()
|
|
323
|
+
});
|
|
324
|
+
const PlacementSchema = z.union([
|
|
325
|
+
z.strictObject({
|
|
326
|
+
mode: z.enum(["off", "smart"]),
|
|
327
|
+
hint: z.string().optional()
|
|
328
|
+
}),
|
|
329
|
+
z.strictObject({
|
|
330
|
+
mode: z.literal("targeted").optional(),
|
|
331
|
+
region: z.string()
|
|
332
|
+
}),
|
|
333
|
+
z.strictObject({
|
|
334
|
+
mode: z.literal("targeted").optional(),
|
|
335
|
+
host: z.string()
|
|
336
|
+
}),
|
|
337
|
+
z.strictObject({
|
|
338
|
+
mode: z.literal("targeted").optional(),
|
|
339
|
+
hostname: z.string()
|
|
340
|
+
})
|
|
341
|
+
]);
|
|
342
|
+
const TailConsumerSchema = z.strictObject({
|
|
343
|
+
workerName: z.string(),
|
|
344
|
+
streaming: z.boolean().optional()
|
|
345
|
+
});
|
|
346
|
+
const TriggerSchema = z.discriminatedUnion("type", [
|
|
347
|
+
z.strictObject({
|
|
348
|
+
type: z.literal("email"),
|
|
349
|
+
addresses: z.array(z.string())
|
|
350
|
+
}),
|
|
351
|
+
z.strictObject({
|
|
352
|
+
type: z.literal("fetch"),
|
|
353
|
+
pattern: z.string(),
|
|
354
|
+
zone: z.string().optional()
|
|
355
|
+
}),
|
|
356
|
+
z.strictObject({
|
|
357
|
+
type: z.literal("queue"),
|
|
358
|
+
name: z.string(),
|
|
359
|
+
deadLetterQueue: z.string().optional(),
|
|
360
|
+
maxBatchSize: z.number().optional(),
|
|
361
|
+
maxBatchTimeout: z.number().optional(),
|
|
362
|
+
maxConcurrency: z.number().nullable().optional(),
|
|
363
|
+
maxRetries: z.number().optional(),
|
|
364
|
+
retryDelay: z.number().optional(),
|
|
365
|
+
visibilityTimeoutMs: z.number().optional()
|
|
366
|
+
}),
|
|
367
|
+
z.strictObject({
|
|
368
|
+
type: z.literal("scheduled"),
|
|
369
|
+
schedule: z.string()
|
|
370
|
+
})
|
|
371
|
+
]);
|
|
372
|
+
const UnsafeSchema = z.strictObject({
|
|
373
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
374
|
+
capnp: z.union([z.strictObject({
|
|
375
|
+
basePath: z.string(),
|
|
376
|
+
sourceSchemas: z.array(z.string()),
|
|
377
|
+
compiledSchema: z.never().optional()
|
|
378
|
+
}), z.strictObject({
|
|
379
|
+
basePath: z.never().optional(),
|
|
380
|
+
sourceSchemas: z.never().optional(),
|
|
381
|
+
compiledSchema: z.string()
|
|
382
|
+
})]).optional()
|
|
383
|
+
});
|
|
384
|
+
/**
|
|
385
|
+
* Base Worker schema — the set of fields shared between the input
|
|
386
|
+
* (user-authored) and output (on-disk) Worker configs.
|
|
387
|
+
*/
|
|
388
|
+
const BaseWorkerSchema = z.strictObject({
|
|
389
|
+
type: z.literal("worker"),
|
|
390
|
+
name: z.string(),
|
|
391
|
+
compatibilityDate: z.string(),
|
|
392
|
+
compatibilityFlags: z.array(z.string()).optional(),
|
|
393
|
+
assets: AssetsSchema.optional(),
|
|
394
|
+
domains: z.array(z.string()).optional(),
|
|
395
|
+
triggers: z.array(TriggerSchema).optional(),
|
|
396
|
+
tailConsumers: z.array(TailConsumerSchema).optional(),
|
|
397
|
+
cache: CacheSchema.optional(),
|
|
398
|
+
placement: PlacementSchema.optional(),
|
|
399
|
+
limits: LimitsSchema.optional(),
|
|
400
|
+
logpush: z.boolean().optional(),
|
|
401
|
+
observability: ObservabilitySchema.optional(),
|
|
402
|
+
workersDev: z.boolean().optional(),
|
|
403
|
+
previewUrls: z.boolean().optional(),
|
|
404
|
+
firstPartyWorker: z.boolean().optional(),
|
|
405
|
+
unsafe: UnsafeSchema.optional(),
|
|
406
|
+
env: EnvSchema,
|
|
407
|
+
exports: z.record(z.string(), ExportSchema).optional()
|
|
408
|
+
});
|
|
409
|
+
/**
|
|
410
|
+
* Input Worker schema — the shape that user-authored `cloudflare.config.ts`
|
|
411
|
+
* files are validated against. Adds an optional `entrypoint` field to the
|
|
412
|
+
* base schema.
|
|
413
|
+
*/
|
|
414
|
+
const InputWorkerSchema = BaseWorkerSchema.extend({ entrypoint: z.union([z.string(), z.strictObject({ default: z.string() })]).transform((value) => typeof value === "string" ? value : value.default).optional() });
|
|
415
|
+
/**
|
|
416
|
+
* Settings schema — validates the named `settings` export of a
|
|
417
|
+
* `cloudflare.config.ts`. Holds account/deployment settings shared by the other exports.
|
|
418
|
+
*/
|
|
419
|
+
const SettingsSchema = z.strictObject({
|
|
420
|
+
type: z.literal("settings"),
|
|
421
|
+
accountId: z.string().optional(),
|
|
422
|
+
complianceRegion: z.enum(["public", "fedramp-high"]).optional()
|
|
423
|
+
});
|
|
424
|
+
/**
|
|
425
|
+
* Discriminated union of the config kinds a single export may resolve to.
|
|
426
|
+
*/
|
|
427
|
+
const ConfigExportSchema = z.discriminatedUnion("type", [InputWorkerSchema, SettingsSchema]);
|
|
428
|
+
const SETTINGS_EXPORT_NAME = "settings";
|
|
429
|
+
/**
|
|
430
|
+
* Schema for the resolved config exports, keyed by export
|
|
431
|
+
* name. Each value is discriminated on its `type` field. Reserves the
|
|
432
|
+
* `settings` export name exclusively for settings configs: a `settings`
|
|
433
|
+
* config must live on the `settings` export, and the `settings` export
|
|
434
|
+
* may only hold a `settings` config.
|
|
435
|
+
*/
|
|
436
|
+
const ConfigExportsSchema = z.record(z.string(), ConfigExportSchema).check((ctx) => {
|
|
437
|
+
for (const [key, value] of Object.entries(ctx.value)) {
|
|
438
|
+
const isSettingsName = key === SETTINGS_EXPORT_NAME;
|
|
439
|
+
const isSettingsType = value.type === "settings";
|
|
440
|
+
if (isSettingsType && !isSettingsName) ctx.issues.push({
|
|
441
|
+
code: "custom",
|
|
442
|
+
input: value,
|
|
443
|
+
path: [key],
|
|
444
|
+
message: `A \`settings\` config is only allowed on the \`${SETTINGS_EXPORT_NAME}\` export; found one on the \`${key}\` export.`
|
|
445
|
+
});
|
|
446
|
+
else if (isSettingsName && !isSettingsType) ctx.issues.push({
|
|
447
|
+
code: "custom",
|
|
448
|
+
input: value,
|
|
449
|
+
path: [key],
|
|
450
|
+
message: `The \`${SETTINGS_EXPORT_NAME}\` export is reserved for a \`settings\` config; found a \`${value.type}\` config.`
|
|
451
|
+
});
|
|
144
452
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
453
|
+
});
|
|
454
|
+
const ModuleTypeSchema = z.enum([
|
|
455
|
+
"esm",
|
|
456
|
+
"cjs",
|
|
457
|
+
"python",
|
|
458
|
+
"python-requirement",
|
|
459
|
+
"wasm",
|
|
460
|
+
"text",
|
|
461
|
+
"data",
|
|
462
|
+
"json",
|
|
463
|
+
"sourcemap"
|
|
464
|
+
]);
|
|
465
|
+
const ManifestSchema = z.strictObject({
|
|
466
|
+
mainModule: z.string(),
|
|
467
|
+
modules: z.record(z.string(), z.strictObject({ type: ModuleTypeSchema }))
|
|
468
|
+
});
|
|
469
|
+
/**
|
|
470
|
+
* Output Worker schema — the shape of the Worker's `config.json` in the
|
|
471
|
+
* Build Output Specification. Adds an optional `manifest` field to the
|
|
472
|
+
* base schema.
|
|
473
|
+
*/
|
|
474
|
+
const OutputWorkerSchema = BaseWorkerSchema.extend({ manifest: ManifestSchema.optional() });
|
|
475
|
+
|
|
476
|
+
//#endregion
|
|
477
|
+
//#region ../../node_modules/.pnpm/ts-dedent@2.2.0/node_modules/ts-dedent/dist/index.js
|
|
478
|
+
var require_dist = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/ts-dedent@2.2.0/node_modules/ts-dedent/dist/index.js": ((exports) => {
|
|
479
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
480
|
+
exports.dedent = void 0;
|
|
481
|
+
function dedent$2(templ) {
|
|
482
|
+
var values = [];
|
|
483
|
+
for (var _i = 1; _i < arguments.length; _i++) values[_i - 1] = arguments[_i];
|
|
484
|
+
var strings = Array.from(typeof templ === "string" ? [templ] : templ);
|
|
485
|
+
strings[strings.length - 1] = strings[strings.length - 1].replace(/\r?\n([\t ]*)$/, "");
|
|
486
|
+
var indentLengths = strings.reduce(function(arr, str) {
|
|
487
|
+
var matches = str.match(/\n([\t ]+|(?!\s).)/g);
|
|
488
|
+
if (matches) return arr.concat(matches.map(function(match) {
|
|
489
|
+
var _a, _b;
|
|
490
|
+
return (_b = (_a = match.match(/[\t ]/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
491
|
+
}));
|
|
492
|
+
return arr;
|
|
493
|
+
}, []);
|
|
494
|
+
if (indentLengths.length) {
|
|
495
|
+
var pattern_1 = new RegExp("\n[ ]{" + Math.min.apply(Math, indentLengths) + "}", "g");
|
|
496
|
+
strings = strings.map(function(str) {
|
|
497
|
+
return str.replace(pattern_1, "\n");
|
|
498
|
+
});
|
|
152
499
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
500
|
+
strings[0] = strings[0].replace(/^\r?\n/, "");
|
|
501
|
+
var string = strings[0];
|
|
502
|
+
values.forEach(function(value, i) {
|
|
503
|
+
var endentations = string.match(/(?:^|\n)( *)$/);
|
|
504
|
+
var endentation = endentations ? endentations[1] : "";
|
|
505
|
+
var indentedValue = value;
|
|
506
|
+
if (typeof value === "string" && value.includes("\n")) indentedValue = String(value).split("\n").map(function(str, i$1) {
|
|
507
|
+
return i$1 === 0 ? str : "" + endentation + str;
|
|
508
|
+
}).join("\n");
|
|
509
|
+
string += indentedValue + strings[i + 1];
|
|
510
|
+
});
|
|
511
|
+
return string;
|
|
512
|
+
}
|
|
513
|
+
exports.dedent = dedent$2;
|
|
514
|
+
}) });
|
|
515
|
+
|
|
516
|
+
//#endregion
|
|
517
|
+
//#region src/generate.ts
|
|
518
|
+
var import_dist = require_dist();
|
|
519
|
+
/**
|
|
520
|
+
* Generate the content for worker-configuration.d.ts
|
|
521
|
+
*
|
|
522
|
+
* @example
|
|
523
|
+
* ```typescript
|
|
524
|
+
* import { generateTypes } from "@cloudflare/config";
|
|
525
|
+
* import { writeFileSync } from "node:fs";
|
|
526
|
+
*
|
|
527
|
+
* const content = generateTypes({
|
|
528
|
+
* configPath: "./cloudflare.config.ts",
|
|
529
|
+
* });
|
|
530
|
+
*
|
|
531
|
+
* writeFileSync("worker-configuration.d.ts", content);
|
|
532
|
+
* ```
|
|
533
|
+
*/
|
|
534
|
+
function generateTypes({ configPath, packageName = "@cloudflare/config" }) {
|
|
535
|
+
return import_dist.dedent`
|
|
536
|
+
/* eslint-disable */
|
|
537
|
+
// Generated by @cloudflare/config
|
|
538
|
+
type __WorkerConfig = import("${packageName}").UnwrapConfig<typeof import("${configPath.replace(/\.(ts|js|mts|mjs)$/, "")}").default>;
|
|
539
|
+
type __Env = import("${packageName}").InferEnv<__WorkerConfig>;
|
|
540
|
+
|
|
541
|
+
declare namespace Cloudflare {
|
|
542
|
+
interface GlobalProps {
|
|
543
|
+
mainModule: import("${packageName}").InferMainModule<__WorkerConfig>;
|
|
544
|
+
durableNamespaces: import("${packageName}").InferDurableNamespaces<__WorkerConfig>;
|
|
545
|
+
}
|
|
546
|
+
interface Env extends __Env {}
|
|
547
|
+
}
|
|
548
|
+
interface Env extends Cloudflare.Env {}
|
|
549
|
+
|
|
550
|
+
`;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
//#endregion
|
|
554
|
+
//#region ../workers-utils/dist/chunk-Q72B4Q5Z.mjs
|
|
555
|
+
var __defProp = Object.defineProperty;
|
|
556
|
+
var __name = (target, value) => __defProp(target, "name", {
|
|
557
|
+
value,
|
|
558
|
+
configurable: true
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
//#endregion
|
|
562
|
+
//#region ../workers-utils/dist/chunk-3K53PSCY.mjs
|
|
563
|
+
function partitionExports(exports$2) {
|
|
564
|
+
const partitioned = {
|
|
565
|
+
"durable-object": {},
|
|
566
|
+
worker: {}
|
|
567
|
+
};
|
|
568
|
+
if (exports$2 === void 0) return partitioned;
|
|
569
|
+
for (const [name, entry] of Object.entries(exports$2)) partitioned[entry.type][name] = entry;
|
|
570
|
+
return partitioned;
|
|
571
|
+
}
|
|
572
|
+
__name(partitionExports, "partitionExports");
|
|
573
|
+
var UserError = class extends Error {
|
|
574
|
+
static {
|
|
575
|
+
__name(this, "UserError");
|
|
576
|
+
}
|
|
577
|
+
telemetryMessage;
|
|
578
|
+
constructor(message, options) {
|
|
579
|
+
super(message, options);
|
|
580
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
581
|
+
this.telemetryMessage = typeof options?.telemetryMessage === "string" ? options.telemetryMessage : options?.telemetryMessage ? message : void 0;
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
var DeprecationError = class extends UserError {
|
|
585
|
+
static {
|
|
586
|
+
__name(this, "DeprecationError");
|
|
587
|
+
}
|
|
588
|
+
constructor(message, options) {
|
|
589
|
+
super(`Deprecation:
|
|
590
|
+
${message}`, options);
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
var FatalError = class extends UserError {
|
|
594
|
+
static {
|
|
595
|
+
__name(this, "FatalError");
|
|
596
|
+
}
|
|
597
|
+
code;
|
|
598
|
+
constructor(message, options) {
|
|
599
|
+
super(message, options);
|
|
600
|
+
this.code = options.code;
|
|
601
|
+
}
|
|
602
|
+
};
|
|
603
|
+
var CommandLineArgsError = class extends UserError {
|
|
604
|
+
static {
|
|
605
|
+
__name(this, "CommandLineArgsError");
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
var JsonFriendlyFatalError = class extends FatalError {
|
|
609
|
+
static {
|
|
610
|
+
__name(this, "JsonFriendlyFatalError");
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
var MissingConfigError = class extends Error {
|
|
614
|
+
static {
|
|
615
|
+
__name(this, "MissingConfigError");
|
|
616
|
+
}
|
|
617
|
+
telemetryMessage;
|
|
618
|
+
constructor(key) {
|
|
619
|
+
super(`Missing config value for ${key}`);
|
|
620
|
+
this.telemetryMessage = `Missing config value for ${key}`;
|
|
621
|
+
}
|
|
622
|
+
};
|
|
623
|
+
function createFatalError(message, isJson, options) {
|
|
624
|
+
if (isJson) return new JsonFriendlyFatalError(JSON.stringify(message), options);
|
|
625
|
+
return new FatalError(`${message}`, options);
|
|
626
|
+
}
|
|
627
|
+
__name(createFatalError, "createFatalError");
|
|
628
|
+
function createScanner(text, ignoreTrivia = false) {
|
|
629
|
+
const len = text.length;
|
|
630
|
+
let pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
|
|
631
|
+
function scanHexDigits(count, exact) {
|
|
632
|
+
let digits = 0;
|
|
633
|
+
let value2 = 0;
|
|
634
|
+
while (digits < count || !exact) {
|
|
635
|
+
let ch = text.charCodeAt(pos);
|
|
636
|
+
if (ch >= 48 && ch <= 57) value2 = value2 * 16 + ch - 48;
|
|
637
|
+
else if (ch >= 65 && ch <= 70) value2 = value2 * 16 + ch - 65 + 10;
|
|
638
|
+
else if (ch >= 97 && ch <= 102) value2 = value2 * 16 + ch - 97 + 10;
|
|
639
|
+
else break;
|
|
640
|
+
pos++;
|
|
641
|
+
digits++;
|
|
642
|
+
}
|
|
643
|
+
if (digits < count) value2 = -1;
|
|
644
|
+
return value2;
|
|
645
|
+
}
|
|
646
|
+
__name(scanHexDigits, "scanHexDigits");
|
|
647
|
+
function setPosition(newPosition) {
|
|
648
|
+
pos = newPosition;
|
|
649
|
+
value = "";
|
|
650
|
+
tokenOffset = 0;
|
|
651
|
+
token = 16;
|
|
652
|
+
scanError = 0;
|
|
653
|
+
}
|
|
654
|
+
__name(setPosition, "setPosition");
|
|
655
|
+
function scanNumber() {
|
|
656
|
+
let start = pos;
|
|
657
|
+
if (text.charCodeAt(pos) === 48) pos++;
|
|
658
|
+
else {
|
|
659
|
+
pos++;
|
|
660
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) pos++;
|
|
661
|
+
}
|
|
662
|
+
if (pos < text.length && text.charCodeAt(pos) === 46) {
|
|
663
|
+
pos++;
|
|
664
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
156
665
|
pos++;
|
|
157
666
|
while (pos < text.length && isDigit(text.charCodeAt(pos))) pos++;
|
|
158
667
|
} else {
|
|
@@ -2060,10 +2569,16 @@ var APIError = class extends ParseError {
|
|
|
2060
2569
|
* endpoint-specific structured error payloads.
|
|
2061
2570
|
*/
|
|
2062
2571
|
meta;
|
|
2063
|
-
|
|
2572
|
+
/**
|
|
2573
|
+
* Optional number of milliseconds the API asked us to wait before retrying,
|
|
2574
|
+
* derived from the response's `Retry-After` header (if present).
|
|
2575
|
+
*/
|
|
2576
|
+
retryAfterMs;
|
|
2577
|
+
constructor({ status, retryAfterMs,...rest }) {
|
|
2064
2578
|
super(rest);
|
|
2065
2579
|
this.name = this.constructor.name;
|
|
2066
2580
|
this.#status = status;
|
|
2581
|
+
this.retryAfterMs = retryAfterMs;
|
|
2067
2582
|
}
|
|
2068
2583
|
get status() {
|
|
2069
2584
|
return this.#status;
|
|
@@ -2333,791 +2848,178 @@ function removeBOMAndValidate(buffer, file2) {
|
|
|
2333
2848
|
return content;
|
|
2334
2849
|
}
|
|
2335
2850
|
__name(removeBOMAndValidate, "removeBOMAndValidate");
|
|
2336
|
-
var INHERIT_SYMBOL = Symbol.for("inherit_binding");
|
|
2337
|
-
var PATH_TO_DEPLOY_CONFIG = ".wrangler/deploy/config.json";
|
|
2338
|
-
function absolute(input, root) {
|
|
2339
|
-
return isAbsolute(input) ? input : resolve(root || ".", input);
|
|
2340
|
-
}
|
|
2341
|
-
__name(absolute, "absolute");
|
|
2342
|
-
function up(base, options) {
|
|
2343
|
-
let { last, cwd } = options || {};
|
|
2344
|
-
let tmp = absolute(base, cwd);
|
|
2345
|
-
let root = absolute(last || "/", cwd);
|
|
2346
|
-
let prev, arr = [];
|
|
2347
|
-
while (prev !== root) {
|
|
2348
|
-
arr.push(tmp);
|
|
2349
|
-
tmp = dirname(prev = tmp);
|
|
2350
|
-
if (tmp === prev) break;
|
|
2351
|
-
}
|
|
2352
|
-
return arr;
|
|
2353
|
-
}
|
|
2354
|
-
__name(up, "up");
|
|
2355
|
-
function file(name, options) {
|
|
2356
|
-
let dir2, tmp;
|
|
2357
|
-
for (dir2 of up(options && options.cwd || "", options)) try {
|
|
2358
|
-
tmp = join(dir2, name);
|
|
2359
|
-
if (statSync(tmp).isFile()) return tmp;
|
|
2360
|
-
} catch {}
|
|
2361
|
-
}
|
|
2362
|
-
__name(file, "file");
|
|
2363
|
-
function dir(name, options) {
|
|
2364
|
-
let dir2, tmp;
|
|
2365
|
-
for (dir2 of up(options && options.cwd || "", options)) try {
|
|
2366
|
-
tmp = join(dir2, name);
|
|
2367
|
-
if (statSync(tmp).isDirectory()) return tmp;
|
|
2368
|
-
} catch {}
|
|
2369
|
-
}
|
|
2370
|
-
__name(dir, "dir");
|
|
2371
|
-
function dedent
|
|
2372
|
-
var values = [];
|
|
2373
|
-
for (var _i = 1; _i < arguments.length; _i++) values[_i - 1] = arguments[_i];
|
|
2374
|
-
var strings = Array.from(typeof templ === "string" ? [templ] : templ);
|
|
2375
|
-
strings[strings.length - 1] = strings[strings.length - 1].replace(/\r?\n([\t ]*)$/, "");
|
|
2376
|
-
var indentLengths = strings.reduce(function(arr, str) {
|
|
2377
|
-
var matches = str.match(/\n([\t ]+|(?!\s).)/g);
|
|
2378
|
-
if (matches) return arr.concat(matches.map(function(match) {
|
|
2379
|
-
var _a, _b;
|
|
2380
|
-
return (_b = (_a = match.match(/[\t ]/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
2381
|
-
}));
|
|
2382
|
-
return arr;
|
|
2383
|
-
}, []);
|
|
2384
|
-
if (indentLengths.length) {
|
|
2385
|
-
var pattern_1 = new RegExp("\n[ ]{" + Math.min.apply(Math, indentLengths) + "}", "g");
|
|
2386
|
-
strings = strings.map(function(str) {
|
|
2387
|
-
return str.replace(pattern_1, "\n");
|
|
2388
|
-
});
|
|
2389
|
-
}
|
|
2390
|
-
strings[0] = strings[0].replace(/^\r?\n/, "");
|
|
2391
|
-
var string = strings[0];
|
|
2392
|
-
values.forEach(function(value, i) {
|
|
2393
|
-
var endentations = string.match(/(?:^|\n)( *)$/);
|
|
2394
|
-
var endentation = endentations ? endentations[1] : "";
|
|
2395
|
-
var indentedValue = value;
|
|
2396
|
-
if (typeof value === "string" && value.includes("\n")) indentedValue = String(value).split("\n").map(function(str, i2) {
|
|
2397
|
-
return i2 === 0 ? str : "" + endentation + str;
|
|
2398
|
-
}).join("\n");
|
|
2399
|
-
string += indentedValue + strings[i + 1];
|
|
2400
|
-
});
|
|
2401
|
-
return string;
|
|
2402
|
-
}
|
|
2403
|
-
__name(dedent$2, "dedent");
|
|
2404
|
-
var esm_default = dedent$2;
|
|
2405
|
-
function resolveWranglerConfigPath({ config, script }, options) {
|
|
2406
|
-
if (config !== void 0) return {
|
|
2407
|
-
userConfigPath: config,
|
|
2408
|
-
configPath: config,
|
|
2409
|
-
deployConfigPath: void 0,
|
|
2410
|
-
redirected: false
|
|
2411
|
-
};
|
|
2412
|
-
return findWranglerConfig(script !== void 0 ? path2__default.dirname(script) : process.cwd(), options);
|
|
2413
|
-
}
|
|
2414
|
-
__name(resolveWranglerConfigPath, "resolveWranglerConfigPath");
|
|
2415
|
-
function findWranglerConfig(referencePath = process.cwd(), { useRedirectIfAvailable = false } = {}) {
|
|
2416
|
-
const userConfigPath = file(`wrangler.json`, { cwd: referencePath }) ?? file(`wrangler.jsonc`, { cwd: referencePath }) ?? file(`wrangler.toml`, { cwd: referencePath });
|
|
2417
|
-
if (!useRedirectIfAvailable) return {
|
|
2418
|
-
userConfigPath,
|
|
2419
|
-
configPath: userConfigPath,
|
|
2420
|
-
deployConfigPath: void 0,
|
|
2421
|
-
redirected: false
|
|
2422
|
-
};
|
|
2423
|
-
const { configPath, deployConfigPath, redirected } = findRedirectedWranglerConfig(referencePath, userConfigPath);
|
|
2424
|
-
return {
|
|
2425
|
-
userConfigPath,
|
|
2426
|
-
configPath,
|
|
2427
|
-
deployConfigPath,
|
|
2428
|
-
redirected
|
|
2429
|
-
};
|
|
2430
|
-
}
|
|
2431
|
-
__name(findWranglerConfig, "findWranglerConfig");
|
|
2432
|
-
function findRedirectedWranglerConfig(cwd, userConfigPath) {
|
|
2433
|
-
const deployConfigPath = file(PATH_TO_DEPLOY_CONFIG, { cwd });
|
|
2434
|
-
if (deployConfigPath === void 0) return {
|
|
2435
|
-
configPath: userConfigPath,
|
|
2436
|
-
deployConfigPath,
|
|
2437
|
-
redirected: false
|
|
2438
|
-
};
|
|
2439
|
-
let redirectedConfigPath;
|
|
2440
|
-
const deployConfigFile = readFileSync$1(deployConfigPath);
|
|
2441
|
-
try {
|
|
2442
|
-
const deployConfig = parseJSONC(deployConfigFile, deployConfigPath);
|
|
2443
|
-
redirectedConfigPath = deployConfig.configPath && path2__default.resolve(path2__default.dirname(deployConfigPath), deployConfig.configPath);
|
|
2444
|
-
} catch (e) {
|
|
2445
|
-
throw new UserError(`Failed to parse the deploy configuration file at ${path2__default.relative(".", deployConfigPath)}`, {
|
|
2446
|
-
cause: e,
|
|
2447
|
-
telemetryMessage: false
|
|
2448
|
-
});
|
|
2449
|
-
}
|
|
2450
|
-
if (!redirectedConfigPath) throw new UserError(esm_default`
|
|
2451
|
-
A deploy configuration file was found at "${path2__default.relative(".", deployConfigPath)}".
|
|
2452
|
-
But this is not valid - the required "configPath" property was not found.
|
|
2453
|
-
Instead this file contains:
|
|
2454
|
-
\`\`\`
|
|
2455
|
-
${deployConfigFile}
|
|
2456
|
-
\`\`\`
|
|
2457
|
-
`, { telemetryMessage: false });
|
|
2458
|
-
if (!existsSync(redirectedConfigPath)) throw new UserError(esm_default`
|
|
2459
|
-
There is a deploy configuration at "${path2__default.relative(".", deployConfigPath)}".
|
|
2460
|
-
But the redirected configuration path it points to, "${path2__default.relative(".", redirectedConfigPath)}", does not exist.
|
|
2461
|
-
`, { telemetryMessage: false });
|
|
2462
|
-
if (userConfigPath) {
|
|
2463
|
-
if (path2__default.join(path2__default.dirname(userConfigPath), PATH_TO_DEPLOY_CONFIG) !== deployConfigPath) throw new UserError(esm_default`
|
|
2464
|
-
Found both a user configuration file at "${path2__default.relative(".", userConfigPath)}"
|
|
2465
|
-
and a deploy configuration file at "${path2__default.relative(".", deployConfigPath)}".
|
|
2466
|
-
But these do not share the same base path so it is not clear which should be used.
|
|
2467
|
-
`, { telemetryMessage: false });
|
|
2468
|
-
}
|
|
2469
|
-
return {
|
|
2470
|
-
configPath: redirectedConfigPath,
|
|
2471
|
-
deployConfigPath,
|
|
2472
|
-
redirected: true
|
|
2473
|
-
};
|
|
2474
|
-
}
|
|
2475
|
-
__name(findRedirectedWranglerConfig, "findRedirectedWranglerConfig");
|
|
2476
|
-
function isRedirectedConfig(config) {
|
|
2477
|
-
return config.configPath !== void 0 && config.configPath !== config.userConfigPath;
|
|
2478
|
-
}
|
|
2479
|
-
__name(isRedirectedConfig, "isRedirectedConfig");
|
|
2480
|
-
function isRedirectedRawConfig(rawConfig, configPath, userConfigPath) {
|
|
2481
|
-
return isRedirectedConfig({
|
|
2482
|
-
configPath,
|
|
2483
|
-
userConfigPath
|
|
2484
|
-
});
|
|
2485
|
-
}
|
|
2486
|
-
__name(isRedirectedRawConfig, "isRedirectedRawConfig");
|
|
2487
|
-
function configFormat(configPath) {
|
|
2488
|
-
if (configPath?.endsWith("toml")) return "toml";
|
|
2489
|
-
if (configPath?.endsWith("jsonc")) return "jsonc";
|
|
2490
|
-
if (configPath?.endsWith("json")) return "json";
|
|
2491
|
-
return "none";
|
|
2492
|
-
}
|
|
2493
|
-
__name(configFormat, "configFormat");
|
|
2494
|
-
function configFileName(configPath) {
|
|
2495
|
-
switch (configFormat(configPath)) {
|
|
2496
|
-
case "toml": return "wrangler.toml";
|
|
2497
|
-
case "json": return "wrangler.json";
|
|
2498
|
-
case "jsonc": return "wrangler.jsonc";
|
|
2499
|
-
default: return "Wrangler configuration";
|
|
2500
|
-
}
|
|
2501
|
-
}
|
|
2502
|
-
__name(configFileName, "configFileName");
|
|
2503
|
-
function formatConfigSnippet(snippet, configPath, formatted = true) {
|
|
2504
|
-
if (configFormat(configPath) === "toml") return dist_default.stringify(snippet);
|
|
2505
|
-
else return formatted ? JSON.stringify(snippet, null, 2) : JSON.stringify(snippet);
|
|
2506
|
-
}
|
|
2507
|
-
__name(formatConfigSnippet, "formatConfigSnippet");
|
|
2508
|
-
|
|
2509
|
-
//#endregion
|
|
2510
|
-
//#region src/build-output.ts
|
|
2511
|
-
/**
|
|
2512
|
-
* Initial draft version of the Build Output API.
|
|
2513
|
-
*
|
|
2514
|
-
* Will move to `v1` when the spec stabilises.
|
|
2515
|
-
*/
|
|
2516
|
-
const BUILD_OUTPUT_VERSION = "v0";
|
|
2517
|
-
/**
|
|
2518
|
-
* Project-relative root.
|
|
2519
|
-
*/
|
|
2520
|
-
const BUILD_OUTPUT_ROOT = ".cloudflare/output";
|
|
2521
|
-
/**
|
|
2522
|
-
* Filename of the top-level (root) config holding shared settings.
|
|
2523
|
-
*/
|
|
2524
|
-
const ROOT_CONFIG_FILENAME = "config.json";
|
|
2525
|
-
/**
|
|
2526
|
-
* Filename of the per-Worker config.
|
|
2527
|
-
*/
|
|
2528
|
-
const WORKER_CONFIG_FILENAME = "worker.config.json";
|
|
2529
|
-
/**
|
|
2530
|
-
* Absolute path to the Build Output API root for the current project.
|
|
2531
|
-
*/
|
|
2532
|
-
function getBuildOutputDir(root) {
|
|
2533
|
-
return path.resolve(root, BUILD_OUTPUT_ROOT);
|
|
2534
|
-
}
|
|
2535
|
-
/**
|
|
2536
|
-
* Absolute path to the top-level `config.json` for the current project.
|
|
2537
|
-
*/
|
|
2538
|
-
function getRootConfigPath(root) {
|
|
2539
|
-
return path.join(getBuildOutputDir(root), BUILD_OUTPUT_VERSION, ROOT_CONFIG_FILENAME);
|
|
2540
|
-
}
|
|
2541
|
-
/**
|
|
2542
|
-
* Clean the build output directory.
|
|
2543
|
-
*/
|
|
2544
|
-
async function cleanBuildOutputDir(root) {
|
|
2545
|
-
await removeDir(getBuildOutputDir(root));
|
|
2546
|
-
}
|
|
2547
|
-
/**
|
|
2548
|
-
* Absolute path to the Workers output directory.
|
|
2549
|
-
*/
|
|
2550
|
-
function getWorkersDir(root) {
|
|
2551
|
-
return path.join(getBuildOutputDir(root), BUILD_OUTPUT_VERSION, "workers");
|
|
2552
|
-
}
|
|
2553
|
-
/**
|
|
2554
|
-
* Absolute path to the config file for a given Worker.
|
|
2555
|
-
*/
|
|
2556
|
-
function getWorkerConfigPath(root, workerName) {
|
|
2557
|
-
return path.join(getWorkersDir(root), workerName, WORKER_CONFIG_FILENAME);
|
|
2558
|
-
}
|
|
2559
|
-
/**
|
|
2560
|
-
* Absolute path to the bundle directory for a given Worker.
|
|
2561
|
-
*/
|
|
2562
|
-
function getWorkerBundleDir(root, workerName) {
|
|
2563
|
-
return path.join(getWorkersDir(root), workerName, "bundle");
|
|
2564
|
-
}
|
|
2565
|
-
/**
|
|
2566
|
-
* Absolute path to the assets directory for a given Worker.
|
|
2567
|
-
*/
|
|
2568
|
-
function getWorkerAssetsDir(root, workerName) {
|
|
2569
|
-
return path.join(getWorkersDir(root), workerName, "assets");
|
|
2570
|
-
}
|
|
2571
|
-
/**
|
|
2572
|
-
* Write the output `worker.config.json` for a given Worker to the Build
|
|
2573
|
-
* Output API tree.
|
|
2574
|
-
*
|
|
2575
|
-
* - Workers mode: `manifest` is provided (bundle/ present on disk).
|
|
2576
|
-
* - Assets-only mode: `manifest` is omitted (no bundle/ directory).
|
|
2577
|
-
*/
|
|
2578
|
-
async function writeOutputWorkerConfig(root, parsedConfig, manifest) {
|
|
2579
|
-
const { entrypoint: _entrypoint,...rest } = parsedConfig;
|
|
2580
|
-
const outputConfig = {
|
|
2581
|
-
...rest,
|
|
2582
|
-
manifest
|
|
2583
|
-
};
|
|
2584
|
-
const workerOutputDir = path.join(getWorkersDir(root), outputConfig.name);
|
|
2585
|
-
await fsp.mkdir(workerOutputDir, { recursive: true });
|
|
2586
|
-
const configPath = getWorkerConfigPath(root, outputConfig.name);
|
|
2587
|
-
await fsp.writeFile(configPath, JSON.stringify(outputConfig));
|
|
2588
|
-
}
|
|
2589
|
-
/**
|
|
2590
|
-
* Write the top-level `config.json` holding shared settings to the Build
|
|
2591
|
-
* Output API tree.
|
|
2592
|
-
*/
|
|
2593
|
-
async function writeRootOutputConfig(root, settings) {
|
|
2594
|
-
const configPath = getRootConfigPath(root);
|
|
2595
|
-
await fsp.mkdir(path.dirname(configPath), { recursive: true });
|
|
2596
|
-
await fsp.writeFile(configPath, JSON.stringify(settings));
|
|
2597
|
-
}
|
|
2598
|
-
|
|
2599
|
-
//#endregion
|
|
2600
|
-
//#region src/schema.ts
|
|
2601
|
-
const AssetsSchema = z.strictObject({
|
|
2602
|
-
htmlHandling: z.enum([
|
|
2603
|
-
"auto-trailing-slash",
|
|
2604
|
-
"drop-trailing-slash",
|
|
2605
|
-
"force-trailing-slash",
|
|
2606
|
-
"none"
|
|
2607
|
-
]).optional(),
|
|
2608
|
-
notFoundHandling: z.enum([
|
|
2609
|
-
"single-page-application",
|
|
2610
|
-
"404-page",
|
|
2611
|
-
"none"
|
|
2612
|
-
]).optional(),
|
|
2613
|
-
runWorkerFirst: z.union([z.array(z.string()), z.boolean()]).optional()
|
|
2614
|
-
});
|
|
2615
|
-
const KnownBindingSchema = z.discriminatedUnion("type", [
|
|
2616
|
-
z.strictObject({
|
|
2617
|
-
type: z.literal("agent-memory"),
|
|
2618
|
-
namespace: z.string(),
|
|
2619
|
-
remote: z.boolean().optional()
|
|
2620
|
-
}),
|
|
2621
|
-
z.strictObject({
|
|
2622
|
-
type: z.literal("ai"),
|
|
2623
|
-
remote: z.boolean().optional()
|
|
2624
|
-
}),
|
|
2625
|
-
z.strictObject({
|
|
2626
|
-
type: z.literal("ai-search"),
|
|
2627
|
-
name: z.string(),
|
|
2628
|
-
remote: z.boolean().optional()
|
|
2629
|
-
}),
|
|
2630
|
-
z.strictObject({
|
|
2631
|
-
type: z.literal("ai-search-namespace"),
|
|
2632
|
-
namespace: z.string(),
|
|
2633
|
-
remote: z.boolean().optional()
|
|
2634
|
-
}),
|
|
2635
|
-
z.strictObject({
|
|
2636
|
-
type: z.literal("analytics-engine-dataset"),
|
|
2637
|
-
name: z.string().optional()
|
|
2638
|
-
}),
|
|
2639
|
-
z.strictObject({
|
|
2640
|
-
type: z.literal("artifacts"),
|
|
2641
|
-
namespace: z.string(),
|
|
2642
|
-
remote: z.boolean().optional()
|
|
2643
|
-
}),
|
|
2644
|
-
z.strictObject({ type: z.literal("assets") }),
|
|
2645
|
-
z.strictObject({
|
|
2646
|
-
type: z.literal("browser"),
|
|
2647
|
-
remote: z.boolean().optional()
|
|
2648
|
-
}),
|
|
2649
|
-
z.strictObject({
|
|
2650
|
-
type: z.literal("d1"),
|
|
2651
|
-
name: z.string().optional(),
|
|
2652
|
-
id: z.string().optional(),
|
|
2653
|
-
remote: z.boolean().optional()
|
|
2654
|
-
}),
|
|
2655
|
-
z.strictObject({
|
|
2656
|
-
type: z.literal("dispatch-namespace"),
|
|
2657
|
-
namespace: z.string().optional(),
|
|
2658
|
-
outbound: z.strictObject({
|
|
2659
|
-
workerName: z.string(),
|
|
2660
|
-
parameters: z.array(z.string()).optional()
|
|
2661
|
-
}).optional(),
|
|
2662
|
-
remote: z.boolean().optional()
|
|
2663
|
-
}),
|
|
2664
|
-
z.strictObject({
|
|
2665
|
-
type: z.literal("durable-object"),
|
|
2666
|
-
workerName: z.string(),
|
|
2667
|
-
exportName: z.string()
|
|
2668
|
-
}),
|
|
2669
|
-
z.strictObject({
|
|
2670
|
-
type: z.literal("flagship"),
|
|
2671
|
-
id: z.string().optional(),
|
|
2672
|
-
remote: z.boolean().optional()
|
|
2673
|
-
}),
|
|
2674
|
-
z.strictObject({
|
|
2675
|
-
type: z.literal("hyperdrive"),
|
|
2676
|
-
id: z.string(),
|
|
2677
|
-
localConnectionString: z.string().optional()
|
|
2678
|
-
}),
|
|
2679
|
-
z.strictObject({
|
|
2680
|
-
type: z.literal("images"),
|
|
2681
|
-
remote: z.boolean().optional()
|
|
2682
|
-
}),
|
|
2683
|
-
z.strictObject({
|
|
2684
|
-
type: z.literal("json"),
|
|
2685
|
-
value: z.json()
|
|
2686
|
-
}),
|
|
2687
|
-
z.strictObject({
|
|
2688
|
-
type: z.literal("kv"),
|
|
2689
|
-
id: z.string().optional(),
|
|
2690
|
-
remote: z.boolean().optional()
|
|
2691
|
-
}),
|
|
2692
|
-
z.strictObject({
|
|
2693
|
-
type: z.literal("logfwdr"),
|
|
2694
|
-
destination: z.string()
|
|
2695
|
-
}),
|
|
2696
|
-
z.strictObject({
|
|
2697
|
-
type: z.literal("media"),
|
|
2698
|
-
remote: z.boolean().optional()
|
|
2699
|
-
}),
|
|
2700
|
-
z.strictObject({
|
|
2701
|
-
type: z.literal("mtls-certificate"),
|
|
2702
|
-
id: z.string(),
|
|
2703
|
-
remote: z.boolean().optional()
|
|
2704
|
-
}),
|
|
2705
|
-
z.strictObject({
|
|
2706
|
-
type: z.literal("pipeline"),
|
|
2707
|
-
name: z.string(),
|
|
2708
|
-
remote: z.boolean().optional()
|
|
2709
|
-
}),
|
|
2710
|
-
z.strictObject({
|
|
2711
|
-
type: z.literal("queue"),
|
|
2712
|
-
name: z.string().optional(),
|
|
2713
|
-
deliveryDelay: z.number().optional(),
|
|
2714
|
-
remote: z.boolean().optional()
|
|
2715
|
-
}),
|
|
2716
|
-
z.strictObject({
|
|
2717
|
-
type: z.literal("rate-limit"),
|
|
2718
|
-
namespace: z.string(),
|
|
2719
|
-
simple: z.strictObject({
|
|
2720
|
-
limit: z.number(),
|
|
2721
|
-
period: z.union([z.literal(10), z.literal(60)])
|
|
2722
|
-
})
|
|
2723
|
-
}),
|
|
2724
|
-
z.strictObject({
|
|
2725
|
-
type: z.literal("r2"),
|
|
2726
|
-
name: z.string().optional(),
|
|
2727
|
-
jurisdiction: z.string().optional(),
|
|
2728
|
-
remote: z.boolean().optional()
|
|
2729
|
-
}),
|
|
2730
|
-
z.strictObject({ type: z.literal("secret") }),
|
|
2731
|
-
z.strictObject({
|
|
2732
|
-
type: z.literal("secrets-store-secret"),
|
|
2733
|
-
storeId: z.string(),
|
|
2734
|
-
secretName: z.string()
|
|
2735
|
-
}),
|
|
2736
|
-
z.strictObject({
|
|
2737
|
-
type: z.literal("send-email"),
|
|
2738
|
-
destinationAddress: z.string().optional(),
|
|
2739
|
-
allowedDestinationAddresses: z.array(z.string()).optional(),
|
|
2740
|
-
allowedSenderAddresses: z.array(z.string()).optional(),
|
|
2741
|
-
remote: z.boolean().optional()
|
|
2742
|
-
}),
|
|
2743
|
-
z.strictObject({
|
|
2744
|
-
type: z.literal("stream"),
|
|
2745
|
-
remote: z.boolean().optional()
|
|
2746
|
-
}),
|
|
2747
|
-
z.strictObject({
|
|
2748
|
-
type: z.literal("text"),
|
|
2749
|
-
value: z.string()
|
|
2750
|
-
}),
|
|
2751
|
-
z.strictObject({
|
|
2752
|
-
type: z.literal("vectorize"),
|
|
2753
|
-
name: z.string(),
|
|
2754
|
-
remote: z.boolean().optional()
|
|
2755
|
-
}),
|
|
2756
|
-
z.strictObject({ type: z.literal("version-metadata") }),
|
|
2757
|
-
z.strictObject({
|
|
2758
|
-
type: z.literal("vpc-service"),
|
|
2759
|
-
id: z.string(),
|
|
2760
|
-
remote: z.boolean().optional()
|
|
2761
|
-
}),
|
|
2762
|
-
z.strictObject({
|
|
2763
|
-
type: z.literal("vpc-network"),
|
|
2764
|
-
tunnelId: z.string().optional(),
|
|
2765
|
-
networkId: z.string().optional(),
|
|
2766
|
-
remote: z.boolean().optional()
|
|
2767
|
-
}).superRefine((value, ctx) => {
|
|
2768
|
-
const hasTunnel = value.tunnelId !== void 0;
|
|
2769
|
-
if (hasTunnel === (value.networkId !== void 0)) ctx.addIssue({
|
|
2770
|
-
code: "custom",
|
|
2771
|
-
message: hasTunnel ? `"vpc-network" bindings must specify exactly one of "tunnelId" or "networkId", not both` : `"vpc-network" bindings must specify either "tunnelId" or "networkId"`
|
|
2772
|
-
});
|
|
2773
|
-
}),
|
|
2774
|
-
z.strictObject({
|
|
2775
|
-
type: z.literal("web-search"),
|
|
2776
|
-
remote: z.boolean().optional()
|
|
2777
|
-
}),
|
|
2778
|
-
z.strictObject({
|
|
2779
|
-
type: z.literal("worker"),
|
|
2780
|
-
workerName: z.string(),
|
|
2781
|
-
exportName: z.string().optional(),
|
|
2782
|
-
props: z.record(z.string(), z.unknown()).optional(),
|
|
2783
|
-
remote: z.boolean().optional()
|
|
2784
|
-
}),
|
|
2785
|
-
z.strictObject({ type: z.literal("worker-loader") })
|
|
2786
|
-
]);
|
|
2787
|
-
const UnsafeBindingSchema = z.looseObject({
|
|
2788
|
-
type: z.templateLiteral(["unsafe:", z.string().min(1)]),
|
|
2789
|
-
dev: z.strictObject({
|
|
2790
|
-
plugin: z.strictObject({
|
|
2791
|
-
package: z.string(),
|
|
2792
|
-
name: z.string()
|
|
2793
|
-
}),
|
|
2794
|
-
options: z.record(z.string(), z.unknown()).optional()
|
|
2795
|
-
}).optional()
|
|
2796
|
-
});
|
|
2797
|
-
const BindingSchema = z.unknown().transform((value, ctx) => {
|
|
2798
|
-
const result = (typeof value === "object" && value !== null && "type" in value && typeof value.type === "string" && value.type.startsWith("unsafe:") ? UnsafeBindingSchema : KnownBindingSchema).safeParse(value);
|
|
2799
|
-
if (!result.success) {
|
|
2800
|
-
ctx.issues.push(...result.error.issues);
|
|
2801
|
-
return z.NEVER;
|
|
2802
|
-
}
|
|
2803
|
-
return result.data;
|
|
2804
|
-
});
|
|
2805
|
-
function isParsedUnsafeBinding(binding) {
|
|
2806
|
-
return binding.type.startsWith("unsafe:");
|
|
2807
|
-
}
|
|
2808
|
-
const CacheSchema = z.strictObject({
|
|
2809
|
-
enabled: z.boolean(),
|
|
2810
|
-
crossVersionCache: z.boolean().optional()
|
|
2811
|
-
});
|
|
2812
|
-
/**
|
|
2813
|
-
* Binding types that can only be defined once per worker.
|
|
2814
|
-
*/
|
|
2815
|
-
const SINGLETON_BINDING_TYPES = new Set([
|
|
2816
|
-
"ai",
|
|
2817
|
-
"assets",
|
|
2818
|
-
"browser",
|
|
2819
|
-
"images",
|
|
2820
|
-
"media",
|
|
2821
|
-
"stream",
|
|
2822
|
-
"version-metadata",
|
|
2823
|
-
"web-search"
|
|
2824
|
-
]);
|
|
2825
|
-
const listFormatter = new Intl.ListFormat("en-US");
|
|
2826
|
-
const EnvSchema = z.record(z.string(), BindingSchema).superRefine((env, ctx) => {
|
|
2827
|
-
const seen = /* @__PURE__ */ new Set();
|
|
2828
|
-
const duplicates = /* @__PURE__ */ new Set();
|
|
2829
|
-
for (const binding of Object.values(env)) {
|
|
2830
|
-
const type = binding.type;
|
|
2831
|
-
if (SINGLETON_BINDING_TYPES.has(type)) {
|
|
2832
|
-
if (seen.has(type)) duplicates.add(type);
|
|
2833
|
-
seen.add(type);
|
|
2834
|
-
}
|
|
2835
|
-
}
|
|
2836
|
-
if (duplicates.size > 0) ctx.addIssue({
|
|
2837
|
-
code: "custom",
|
|
2838
|
-
message: `${listFormatter.format([...duplicates].sort())} bindings can only be defined once`
|
|
2839
|
-
});
|
|
2840
|
-
}).optional();
|
|
2841
|
-
const ExportSchema = z.union([
|
|
2842
|
-
z.strictObject({
|
|
2843
|
-
type: z.literal("durable-object"),
|
|
2844
|
-
state: z.literal("created").optional(),
|
|
2845
|
-
storage: z.enum(["sqlite", "legacy-kv"])
|
|
2846
|
-
}),
|
|
2847
|
-
z.strictObject({
|
|
2848
|
-
type: z.literal("durable-object"),
|
|
2849
|
-
state: z.literal("deleted")
|
|
2850
|
-
}),
|
|
2851
|
-
z.strictObject({
|
|
2852
|
-
type: z.literal("durable-object"),
|
|
2853
|
-
state: z.literal("renamed"),
|
|
2854
|
-
renamedTo: z.string()
|
|
2855
|
-
}),
|
|
2856
|
-
z.strictObject({
|
|
2857
|
-
type: z.literal("durable-object"),
|
|
2858
|
-
state: z.literal("transferred"),
|
|
2859
|
-
transferredTo: z.string()
|
|
2860
|
-
}),
|
|
2861
|
-
z.strictObject({
|
|
2862
|
-
type: z.literal("durable-object"),
|
|
2863
|
-
state: z.literal("expecting-transfer"),
|
|
2864
|
-
storage: z.enum(["sqlite", "legacy-kv"]),
|
|
2865
|
-
transferFrom: z.string()
|
|
2866
|
-
}),
|
|
2867
|
-
z.strictObject({
|
|
2868
|
-
type: z.literal("worker"),
|
|
2869
|
-
cache: z.strictObject({ enabled: z.boolean() }).optional()
|
|
2870
|
-
})
|
|
2871
|
-
]);
|
|
2872
|
-
const LimitsSchema = z.strictObject({
|
|
2873
|
-
cpuMs: z.number().optional(),
|
|
2874
|
-
subrequests: z.number().optional()
|
|
2875
|
-
});
|
|
2876
|
-
const ObservabilitySchema = z.strictObject({
|
|
2877
|
-
enabled: z.boolean().optional(),
|
|
2878
|
-
headSamplingRate: z.number().optional(),
|
|
2879
|
-
logs: z.strictObject({
|
|
2880
|
-
enabled: z.boolean().optional(),
|
|
2881
|
-
headSamplingRate: z.number().optional(),
|
|
2882
|
-
invocationLogs: z.boolean().optional(),
|
|
2883
|
-
persist: z.boolean().optional(),
|
|
2884
|
-
destinations: z.array(z.string()).optional()
|
|
2885
|
-
}).optional(),
|
|
2886
|
-
traces: z.strictObject({
|
|
2887
|
-
enabled: z.boolean().optional(),
|
|
2888
|
-
headSamplingRate: z.number().optional(),
|
|
2889
|
-
persist: z.boolean().optional(),
|
|
2890
|
-
destinations: z.array(z.string()).optional()
|
|
2891
|
-
}).optional()
|
|
2892
|
-
});
|
|
2893
|
-
const PlacementSchema = z.union([
|
|
2894
|
-
z.strictObject({
|
|
2895
|
-
mode: z.enum(["off", "smart"]),
|
|
2896
|
-
hint: z.string().optional()
|
|
2897
|
-
}),
|
|
2898
|
-
z.strictObject({
|
|
2899
|
-
mode: z.literal("targeted").optional(),
|
|
2900
|
-
region: z.string()
|
|
2901
|
-
}),
|
|
2902
|
-
z.strictObject({
|
|
2903
|
-
mode: z.literal("targeted").optional(),
|
|
2904
|
-
host: z.string()
|
|
2905
|
-
}),
|
|
2906
|
-
z.strictObject({
|
|
2907
|
-
mode: z.literal("targeted").optional(),
|
|
2908
|
-
hostname: z.string()
|
|
2909
|
-
})
|
|
2910
|
-
]);
|
|
2911
|
-
const TailConsumerSchema = z.strictObject({
|
|
2912
|
-
workerName: z.string(),
|
|
2913
|
-
streaming: z.boolean().optional()
|
|
2914
|
-
});
|
|
2915
|
-
const TriggerSchema = z.discriminatedUnion("type", [
|
|
2916
|
-
z.strictObject({
|
|
2917
|
-
type: z.literal("email"),
|
|
2918
|
-
addresses: z.array(z.string())
|
|
2919
|
-
}),
|
|
2920
|
-
z.strictObject({
|
|
2921
|
-
type: z.literal("fetch"),
|
|
2922
|
-
pattern: z.string(),
|
|
2923
|
-
zone: z.string().optional()
|
|
2924
|
-
}),
|
|
2925
|
-
z.strictObject({
|
|
2926
|
-
type: z.literal("queue"),
|
|
2927
|
-
name: z.string(),
|
|
2928
|
-
deadLetterQueue: z.string().optional(),
|
|
2929
|
-
maxBatchSize: z.number().optional(),
|
|
2930
|
-
maxBatchTimeout: z.number().optional(),
|
|
2931
|
-
maxConcurrency: z.number().nullable().optional(),
|
|
2932
|
-
maxRetries: z.number().optional(),
|
|
2933
|
-
retryDelay: z.number().optional(),
|
|
2934
|
-
visibilityTimeoutMs: z.number().optional()
|
|
2935
|
-
}),
|
|
2936
|
-
z.strictObject({
|
|
2937
|
-
type: z.literal("scheduled"),
|
|
2938
|
-
schedule: z.string()
|
|
2939
|
-
})
|
|
2940
|
-
]);
|
|
2941
|
-
const UnsafeSchema = z.strictObject({
|
|
2942
|
-
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
2943
|
-
capnp: z.union([z.strictObject({
|
|
2944
|
-
basePath: z.string(),
|
|
2945
|
-
sourceSchemas: z.array(z.string()),
|
|
2946
|
-
compiledSchema: z.never().optional()
|
|
2947
|
-
}), z.strictObject({
|
|
2948
|
-
basePath: z.never().optional(),
|
|
2949
|
-
sourceSchemas: z.never().optional(),
|
|
2950
|
-
compiledSchema: z.string()
|
|
2951
|
-
})]).optional()
|
|
2952
|
-
});
|
|
2953
|
-
/**
|
|
2954
|
-
* Base Worker schema — the set of fields shared between the input
|
|
2955
|
-
* (user-authored) and output (on-disk) Worker configs.
|
|
2956
|
-
*/
|
|
2957
|
-
const BaseWorkerSchema = z.strictObject({
|
|
2958
|
-
type: z.literal("worker"),
|
|
2959
|
-
name: z.string(),
|
|
2960
|
-
compatibilityDate: z.string(),
|
|
2961
|
-
compatibilityFlags: z.array(z.string()).optional(),
|
|
2962
|
-
assets: AssetsSchema.optional(),
|
|
2963
|
-
domains: z.array(z.string()).optional(),
|
|
2964
|
-
triggers: z.array(TriggerSchema).optional(),
|
|
2965
|
-
tailConsumers: z.array(TailConsumerSchema).optional(),
|
|
2966
|
-
cache: CacheSchema.optional(),
|
|
2967
|
-
placement: PlacementSchema.optional(),
|
|
2968
|
-
limits: LimitsSchema.optional(),
|
|
2969
|
-
logpush: z.boolean().optional(),
|
|
2970
|
-
observability: ObservabilitySchema.optional(),
|
|
2971
|
-
workersDev: z.boolean().optional(),
|
|
2972
|
-
previewUrls: z.boolean().optional(),
|
|
2973
|
-
firstPartyWorker: z.boolean().optional(),
|
|
2974
|
-
unsafe: UnsafeSchema.optional(),
|
|
2975
|
-
env: EnvSchema,
|
|
2976
|
-
exports: z.record(z.string(), ExportSchema).optional()
|
|
2977
|
-
});
|
|
2978
|
-
/**
|
|
2979
|
-
* Input Worker schema — the shape that user-authored `cloudflare.config.ts`
|
|
2980
|
-
* files are validated against. Adds an optional `entrypoint` field to the
|
|
2981
|
-
* base schema.
|
|
2982
|
-
*/
|
|
2983
|
-
const InputWorkerSchema = BaseWorkerSchema.extend({ entrypoint: z.union([z.string(), z.strictObject({ default: z.string() })]).transform((value) => typeof value === "string" ? value : value.default).optional() });
|
|
2984
|
-
/**
|
|
2985
|
-
* Settings schema — validates the named `settings` export of a
|
|
2986
|
-
* `cloudflare.config.ts`. Holds account/deployment settings shared by the other exports.
|
|
2987
|
-
*/
|
|
2988
|
-
const SettingsSchema = z.strictObject({
|
|
2989
|
-
type: z.literal("settings"),
|
|
2990
|
-
accountId: z.string().optional(),
|
|
2991
|
-
complianceRegion: z.enum(["public", "fedramp-high"]).optional()
|
|
2992
|
-
});
|
|
2993
|
-
/**
|
|
2994
|
-
* Discriminated union of the config kinds a single export may resolve to.
|
|
2995
|
-
*/
|
|
2996
|
-
const ConfigExportSchema = z.discriminatedUnion("type", [InputWorkerSchema, SettingsSchema]);
|
|
2997
|
-
const SETTINGS_EXPORT_NAME = "settings";
|
|
2998
|
-
/**
|
|
2999
|
-
* Schema for the resolved config exports, keyed by export
|
|
3000
|
-
* name. Each value is discriminated on its `type` field. Reserves the
|
|
3001
|
-
* `settings` export name exclusively for settings configs: a `settings`
|
|
3002
|
-
* config must live on the `settings` export, and the `settings` export
|
|
3003
|
-
* may only hold a `settings` config.
|
|
3004
|
-
*/
|
|
3005
|
-
const ConfigExportsSchema = z.record(z.string(), ConfigExportSchema).check((ctx) => {
|
|
3006
|
-
for (const [key, value] of Object.entries(ctx.value)) {
|
|
3007
|
-
const isSettingsName = key === SETTINGS_EXPORT_NAME;
|
|
3008
|
-
const isSettingsType = value.type === "settings";
|
|
3009
|
-
if (isSettingsType && !isSettingsName) ctx.issues.push({
|
|
3010
|
-
code: "custom",
|
|
3011
|
-
input: value,
|
|
3012
|
-
path: [key],
|
|
3013
|
-
message: `A \`settings\` config is only allowed on the \`${SETTINGS_EXPORT_NAME}\` export; found one on the \`${key}\` export.`
|
|
3014
|
-
});
|
|
3015
|
-
else if (isSettingsName && !isSettingsType) ctx.issues.push({
|
|
3016
|
-
code: "custom",
|
|
3017
|
-
input: value,
|
|
3018
|
-
path: [key],
|
|
3019
|
-
message: `The \`${SETTINGS_EXPORT_NAME}\` export is reserved for a \`settings\` config; found a \`${value.type}\` config.`
|
|
2851
|
+
var INHERIT_SYMBOL = Symbol.for("inherit_binding");
|
|
2852
|
+
var PATH_TO_DEPLOY_CONFIG = ".wrangler/deploy/config.json";
|
|
2853
|
+
function absolute(input, root) {
|
|
2854
|
+
return isAbsolute(input) ? input : resolve(root || ".", input);
|
|
2855
|
+
}
|
|
2856
|
+
__name(absolute, "absolute");
|
|
2857
|
+
function up(base, options) {
|
|
2858
|
+
let { last, cwd } = options || {};
|
|
2859
|
+
let tmp = absolute(base, cwd);
|
|
2860
|
+
let root = absolute(last || "/", cwd);
|
|
2861
|
+
let prev, arr = [];
|
|
2862
|
+
while (prev !== root) {
|
|
2863
|
+
arr.push(tmp);
|
|
2864
|
+
tmp = dirname(prev = tmp);
|
|
2865
|
+
if (tmp === prev) break;
|
|
2866
|
+
}
|
|
2867
|
+
return arr;
|
|
2868
|
+
}
|
|
2869
|
+
__name(up, "up");
|
|
2870
|
+
function file(name, options) {
|
|
2871
|
+
let dir2, tmp;
|
|
2872
|
+
for (dir2 of up(options && options.cwd || "", options)) try {
|
|
2873
|
+
tmp = join(dir2, name);
|
|
2874
|
+
if (statSync(tmp).isFile()) return tmp;
|
|
2875
|
+
} catch {}
|
|
2876
|
+
}
|
|
2877
|
+
__name(file, "file");
|
|
2878
|
+
function dir(name, options) {
|
|
2879
|
+
let dir2, tmp;
|
|
2880
|
+
for (dir2 of up(options && options.cwd || "", options)) try {
|
|
2881
|
+
tmp = join(dir2, name);
|
|
2882
|
+
if (statSync(tmp).isDirectory()) return tmp;
|
|
2883
|
+
} catch {}
|
|
2884
|
+
}
|
|
2885
|
+
__name(dir, "dir");
|
|
2886
|
+
function dedent(templ) {
|
|
2887
|
+
var values = [];
|
|
2888
|
+
for (var _i = 1; _i < arguments.length; _i++) values[_i - 1] = arguments[_i];
|
|
2889
|
+
var strings = Array.from(typeof templ === "string" ? [templ] : templ);
|
|
2890
|
+
strings[strings.length - 1] = strings[strings.length - 1].replace(/\r?\n([\t ]*)$/, "");
|
|
2891
|
+
var indentLengths = strings.reduce(function(arr, str) {
|
|
2892
|
+
var matches = str.match(/\n([\t ]+|(?!\s).)/g);
|
|
2893
|
+
if (matches) return arr.concat(matches.map(function(match) {
|
|
2894
|
+
var _a, _b;
|
|
2895
|
+
return (_b = (_a = match.match(/[\t ]/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
2896
|
+
}));
|
|
2897
|
+
return arr;
|
|
2898
|
+
}, []);
|
|
2899
|
+
if (indentLengths.length) {
|
|
2900
|
+
var pattern_1 = new RegExp("\n[ ]{" + Math.min.apply(Math, indentLengths) + "}", "g");
|
|
2901
|
+
strings = strings.map(function(str) {
|
|
2902
|
+
return str.replace(pattern_1, "\n");
|
|
3020
2903
|
});
|
|
3021
2904
|
}
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
})
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
2905
|
+
strings[0] = strings[0].replace(/^\r?\n/, "");
|
|
2906
|
+
var string = strings[0];
|
|
2907
|
+
values.forEach(function(value, i) {
|
|
2908
|
+
var endentations = string.match(/(?:^|\n)( *)$/);
|
|
2909
|
+
var endentation = endentations ? endentations[1] : "";
|
|
2910
|
+
var indentedValue = value;
|
|
2911
|
+
if (typeof value === "string" && value.includes("\n")) indentedValue = String(value).split("\n").map(function(str, i2) {
|
|
2912
|
+
return i2 === 0 ? str : "" + endentation + str;
|
|
2913
|
+
}).join("\n");
|
|
2914
|
+
string += indentedValue + strings[i + 1];
|
|
2915
|
+
});
|
|
2916
|
+
return string;
|
|
2917
|
+
}
|
|
2918
|
+
__name(dedent, "dedent");
|
|
2919
|
+
var esm_default = dedent;
|
|
2920
|
+
function resolveWranglerConfigPath({ config, script }, options) {
|
|
2921
|
+
if (config !== void 0) return {
|
|
2922
|
+
userConfigPath: config,
|
|
2923
|
+
configPath: config,
|
|
2924
|
+
deployConfigPath: void 0,
|
|
2925
|
+
redirected: false
|
|
2926
|
+
};
|
|
2927
|
+
return findWranglerConfig(script !== void 0 ? path2__default.dirname(script) : process.cwd(), options);
|
|
2928
|
+
}
|
|
2929
|
+
__name(resolveWranglerConfigPath, "resolveWranglerConfigPath");
|
|
2930
|
+
function findWranglerConfig(referencePath = process.cwd(), { useRedirectIfAvailable = false } = {}) {
|
|
2931
|
+
const userConfigPath = file(`wrangler.json`, { cwd: referencePath }) ?? file(`wrangler.jsonc`, { cwd: referencePath }) ?? file(`wrangler.toml`, { cwd: referencePath });
|
|
2932
|
+
if (!useRedirectIfAvailable) return {
|
|
2933
|
+
userConfigPath,
|
|
2934
|
+
configPath: userConfigPath,
|
|
2935
|
+
deployConfigPath: void 0,
|
|
2936
|
+
redirected: false
|
|
2937
|
+
};
|
|
2938
|
+
const { configPath, deployConfigPath, redirected } = findRedirectedWranglerConfig(referencePath, userConfigPath);
|
|
2939
|
+
return {
|
|
2940
|
+
userConfigPath,
|
|
2941
|
+
configPath,
|
|
2942
|
+
deployConfigPath,
|
|
2943
|
+
redirected
|
|
2944
|
+
};
|
|
2945
|
+
}
|
|
2946
|
+
__name(findWranglerConfig, "findWranglerConfig");
|
|
2947
|
+
function findRedirectedWranglerConfig(cwd, userConfigPath) {
|
|
2948
|
+
const deployConfigPath = file(PATH_TO_DEPLOY_CONFIG, { cwd });
|
|
2949
|
+
if (deployConfigPath === void 0) return {
|
|
2950
|
+
configPath: userConfigPath,
|
|
2951
|
+
deployConfigPath,
|
|
2952
|
+
redirected: false
|
|
2953
|
+
};
|
|
2954
|
+
let redirectedConfigPath;
|
|
2955
|
+
const deployConfigFile = readFileSync$1(deployConfigPath);
|
|
2956
|
+
try {
|
|
2957
|
+
const deployConfig = parseJSONC(deployConfigFile, deployConfigPath);
|
|
2958
|
+
redirectedConfigPath = deployConfig.configPath && path2__default.resolve(path2__default.dirname(deployConfigPath), deployConfig.configPath);
|
|
2959
|
+
} catch (e) {
|
|
2960
|
+
throw new UserError(`Failed to parse the deploy configuration file at ${path2__default.relative(".", deployConfigPath)}`, {
|
|
2961
|
+
cause: e,
|
|
2962
|
+
telemetryMessage: false
|
|
3079
2963
|
});
|
|
3080
|
-
return string;
|
|
3081
2964
|
}
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
2965
|
+
if (!redirectedConfigPath) throw new UserError(esm_default`
|
|
2966
|
+
A deploy configuration file was found at "${path2__default.relative(".", deployConfigPath)}".
|
|
2967
|
+
But this is not valid - the required "configPath" property was not found.
|
|
2968
|
+
Instead this file contains:
|
|
2969
|
+
\`\`\`
|
|
2970
|
+
${deployConfigFile}
|
|
2971
|
+
\`\`\`
|
|
2972
|
+
`, { telemetryMessage: false });
|
|
2973
|
+
if (!existsSync(redirectedConfigPath)) throw new UserError(esm_default`
|
|
2974
|
+
There is a deploy configuration at "${path2__default.relative(".", deployConfigPath)}".
|
|
2975
|
+
But the redirected configuration path it points to, "${path2__default.relative(".", redirectedConfigPath)}", does not exist.
|
|
2976
|
+
`, { telemetryMessage: false });
|
|
2977
|
+
if (userConfigPath) {
|
|
2978
|
+
if (path2__default.join(path2__default.dirname(userConfigPath), PATH_TO_DEPLOY_CONFIG) !== deployConfigPath) throw new UserError(esm_default`
|
|
2979
|
+
Found both a user configuration file at "${path2__default.relative(".", userConfigPath)}"
|
|
2980
|
+
and a deploy configuration file at "${path2__default.relative(".", deployConfigPath)}".
|
|
2981
|
+
But these do not share the same base path so it is not clear which should be used.
|
|
2982
|
+
`, { telemetryMessage: false });
|
|
2983
|
+
}
|
|
2984
|
+
return {
|
|
2985
|
+
configPath: redirectedConfigPath,
|
|
2986
|
+
deployConfigPath,
|
|
2987
|
+
redirected: true
|
|
2988
|
+
};
|
|
2989
|
+
}
|
|
2990
|
+
__name(findRedirectedWranglerConfig, "findRedirectedWranglerConfig");
|
|
2991
|
+
function isRedirectedConfig(config) {
|
|
2992
|
+
return config.configPath !== void 0 && config.configPath !== config.userConfigPath;
|
|
2993
|
+
}
|
|
2994
|
+
__name(isRedirectedConfig, "isRedirectedConfig");
|
|
2995
|
+
function isRedirectedRawConfig(rawConfig, configPath, userConfigPath) {
|
|
2996
|
+
return isRedirectedConfig({
|
|
2997
|
+
configPath,
|
|
2998
|
+
userConfigPath
|
|
2999
|
+
});
|
|
3000
|
+
}
|
|
3001
|
+
__name(isRedirectedRawConfig, "isRedirectedRawConfig");
|
|
3002
|
+
function configFormat(configPath) {
|
|
3003
|
+
if (configPath?.endsWith("toml")) return "toml";
|
|
3004
|
+
if (configPath?.endsWith("jsonc")) return "jsonc";
|
|
3005
|
+
if (configPath?.endsWith("json")) return "json";
|
|
3006
|
+
return "none";
|
|
3007
|
+
}
|
|
3008
|
+
__name(configFormat, "configFormat");
|
|
3009
|
+
function configFileName(configPath) {
|
|
3010
|
+
switch (configFormat(configPath)) {
|
|
3011
|
+
case "toml": return "wrangler.toml";
|
|
3012
|
+
case "json": return "wrangler.json";
|
|
3013
|
+
case "jsonc": return "wrangler.jsonc";
|
|
3014
|
+
default: return "Wrangler configuration";
|
|
3015
|
+
}
|
|
3016
|
+
}
|
|
3017
|
+
__name(configFileName, "configFileName");
|
|
3018
|
+
function formatConfigSnippet(snippet, configPath, formatted = true) {
|
|
3019
|
+
if (configFormat(configPath) === "toml") return dist_default.stringify(snippet);
|
|
3020
|
+
else return formatted ? JSON.stringify(snippet, null, 2) : JSON.stringify(snippet);
|
|
3120
3021
|
}
|
|
3022
|
+
__name(formatConfigSnippet, "formatConfigSnippet");
|
|
3121
3023
|
|
|
3122
3024
|
//#endregion
|
|
3123
3025
|
//#region src/convert.ts
|
|
@@ -3804,4 +3706,4 @@ async function loadAndValidateConfig(configPath, ctx, options) {
|
|
|
3804
3706
|
}
|
|
3805
3707
|
|
|
3806
3708
|
//#endregion
|
|
3807
|
-
export {
|
|
3709
|
+
export { AssetsSchema, BindingSchema, BrowserBindingSchema, ConfigExportsSchema, D1BindingSchema, DurableObjectCreatedExportSchema, DurableObjectDeletedExportSchema, DurableObjectExpectingTransferExportSchema, DurableObjectRenamedExportSchema, DurableObjectTransferredExportSchema, ExportSchema, FlagshipBindingSchema, HyperdriveBindingSchema, InputWorkerSchema, KVBindingSchema, KnownBindingSchema, ModuleTypeSchema, OutputWorkerSchema, QueueBindingSchema, R2BindingSchema, SettingsSchema, TailConsumerSchema, UnsafeBindingSchema, WorkerBindingSchema, WorkerEntrypointExportSchema, bindings, convertToWranglerConfig, defineSettings, defineWorker, exports$1 as exports, generateTypes, loadAndValidateConfig, loadConfig, registerConfigHooks, resolveExportDefinition, triggers, validateSingletonBindings };
|