@cloudflare/deploy-helpers 0.27.2 → 0.28.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/context-DOE6X8vr.d.mts +212 -0
- package/dist/context.d.mts +2 -3
- package/dist/context.mjs +38 -5
- package/dist/create-worker-upload-form-BlSu1EfR.mjs +578 -0
- package/dist/create-worker-upload-form.d.mts +11 -13
- package/dist/create-worker-upload-form.mjs +1 -5
- package/dist/index.d.mts +717 -613
- package/dist/index.mjs +16035 -33673
- package/dist/rolldown-runtime-BMUeFane.mjs +30 -0
- package/dist/startup-profile.d.mts +13 -13
- package/dist/startup-profile.mjs +492 -610
- package/package.json +10 -10
- package/dist/chunk-DSGVRFIS.mjs +0 -828
- package/dist/chunk-U6NEESU5.mjs +0 -41
- package/dist/chunk-Y4VATABS.mjs +0 -27
- package/dist/context-BY_xpg-t.d.mts +0 -211
- package/dist/metafile-esm.json +0 -1
|
@@ -0,0 +1,578 @@
|
|
|
1
|
+
import "./rolldown-runtime-BMUeFane.mjs";
|
|
2
|
+
import assert from "node:assert";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import path, { resolve } from "node:path";
|
|
5
|
+
import { INHERIT_SYMBOL, UserError, extractBindingsOfType, isUnsafeBindingType } from "@cloudflare/workers-utils";
|
|
6
|
+
import { FormData } from "undici";
|
|
7
|
+
import { spawnSync } from "node:child_process";
|
|
8
|
+
import { sync } from "command-exists";
|
|
9
|
+
//#region src/deploy/helpers/capnp.ts
|
|
10
|
+
function handleUnsafeCapnp(capnp) {
|
|
11
|
+
if (capnp.compiled_schema) return readFileSync(resolve(capnp.compiled_schema));
|
|
12
|
+
const { base_path, source_schemas } = capnp;
|
|
13
|
+
const capnpSchemas = (source_schemas ?? []).map((x) => resolve(base_path, x));
|
|
14
|
+
if (!sync("capnp")) throw new UserError("The capnp compiler is required to upload capnp schemas, but is not present.", { telemetryMessage: "capnp compiler missing" });
|
|
15
|
+
const srcPrefix = resolve(base_path ?? ".");
|
|
16
|
+
const capnpProcess = spawnSync("capnp", [
|
|
17
|
+
"compile",
|
|
18
|
+
"-o-",
|
|
19
|
+
`--src-prefix=${srcPrefix}`,
|
|
20
|
+
...capnpSchemas
|
|
21
|
+
], { maxBuffer: 3145728 });
|
|
22
|
+
if (capnpProcess.error) throw capnpProcess.error;
|
|
23
|
+
if (capnpProcess.stderr.length) throw new Error(capnpProcess.stderr.toString());
|
|
24
|
+
return capnpProcess.stdout;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/deploy/helpers/create-worker-upload-form.ts
|
|
28
|
+
const moduleTypeMimeType = {
|
|
29
|
+
esm: "application/javascript+module",
|
|
30
|
+
commonjs: "application/javascript",
|
|
31
|
+
"compiled-wasm": "application/wasm",
|
|
32
|
+
buffer: "application/octet-stream",
|
|
33
|
+
text: "text/plain",
|
|
34
|
+
python: "text/x-python",
|
|
35
|
+
"python-requirement": "text/x-python-requirement"
|
|
36
|
+
};
|
|
37
|
+
function toMimeType(type) {
|
|
38
|
+
const mimeType = moduleTypeMimeType[type];
|
|
39
|
+
if (mimeType === void 0) throw new TypeError("Unsupported module: " + type);
|
|
40
|
+
return mimeType;
|
|
41
|
+
}
|
|
42
|
+
function fromMimeType(mimeType) {
|
|
43
|
+
const moduleType = Object.keys(moduleTypeMimeType).find((type) => moduleTypeMimeType[type] === mimeType);
|
|
44
|
+
if (moduleType === void 0) throw new TypeError("Unsupported mime type: " + mimeType);
|
|
45
|
+
return moduleType;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Creates a `FormData` upload from Worker data and bindings
|
|
49
|
+
*/
|
|
50
|
+
function createWorkerUploadForm(worker, bindings, options) {
|
|
51
|
+
const formData = new FormData();
|
|
52
|
+
const { main, sourceMaps, migrations, code_update_strategy, exports: configuredExports, compatibility_date, compatibility_flags, keepVars, keepSecrets, keepBindings, logpush, placement, tail_consumers, streaming_tail_consumers, limits, annotations, keep_assets, assets, observability, cache, package_dependencies } = worker;
|
|
53
|
+
const assetConfig = {
|
|
54
|
+
html_handling: assets?.assetConfig?.html_handling,
|
|
55
|
+
not_found_handling: assets?.assetConfig?.not_found_handling,
|
|
56
|
+
base_path: assets?.assetConfig?.base_path,
|
|
57
|
+
run_worker_first: assets?.run_worker_first,
|
|
58
|
+
_redirects: assets?._redirects,
|
|
59
|
+
_headers: assets?._headers
|
|
60
|
+
};
|
|
61
|
+
if (assets && !assets.routerConfig.has_user_worker) {
|
|
62
|
+
formData.set("metadata", JSON.stringify({
|
|
63
|
+
assets: {
|
|
64
|
+
jwt: assets.jwt,
|
|
65
|
+
config: assetConfig
|
|
66
|
+
},
|
|
67
|
+
...annotations && { annotations },
|
|
68
|
+
...compatibility_date && { compatibility_date },
|
|
69
|
+
...compatibility_flags && { compatibility_flags }
|
|
70
|
+
}));
|
|
71
|
+
return formData;
|
|
72
|
+
}
|
|
73
|
+
let { modules } = worker;
|
|
74
|
+
const metadataBindings = [];
|
|
75
|
+
const plain_text = extractBindingsOfType("plain_text", bindings);
|
|
76
|
+
const json_bindings = extractBindingsOfType("json", bindings);
|
|
77
|
+
const secret_text = extractBindingsOfType("secret_text", bindings);
|
|
78
|
+
const kv_namespaces = extractBindingsOfType("kv_namespace", bindings);
|
|
79
|
+
const send_email = extractBindingsOfType("send_email", bindings);
|
|
80
|
+
const durable_objects = extractBindingsOfType("durable_object_namespace", bindings);
|
|
81
|
+
const workflows = extractBindingsOfType("workflow", bindings);
|
|
82
|
+
const queues = extractBindingsOfType("queue", bindings);
|
|
83
|
+
const r2_buckets = extractBindingsOfType("r2_bucket", bindings);
|
|
84
|
+
const d1_databases = extractBindingsOfType("d1", bindings);
|
|
85
|
+
const vectorize = extractBindingsOfType("vectorize", bindings);
|
|
86
|
+
const ai_search_namespaces = extractBindingsOfType("ai_search_namespace", bindings);
|
|
87
|
+
const ai_search = extractBindingsOfType("ai_search", bindings);
|
|
88
|
+
const agent_memory = extractBindingsOfType("agent_memory", bindings);
|
|
89
|
+
const hyperdrive = extractBindingsOfType("hyperdrive", bindings);
|
|
90
|
+
const secrets_store_secrets = extractBindingsOfType("secrets_store_secret", bindings);
|
|
91
|
+
const artifacts = extractBindingsOfType("artifacts", bindings);
|
|
92
|
+
const unsafe_hello_world = extractBindingsOfType("unsafe_hello_world", bindings);
|
|
93
|
+
const flagship = extractBindingsOfType("flagship", bindings);
|
|
94
|
+
const ratelimits = extractBindingsOfType("ratelimit", bindings);
|
|
95
|
+
const vpc_services = extractBindingsOfType("vpc_service", bindings);
|
|
96
|
+
const vpc_networks = extractBindingsOfType("vpc_network", bindings);
|
|
97
|
+
const services = extractBindingsOfType("service", bindings);
|
|
98
|
+
const analytics_engine_datasets = extractBindingsOfType("analytics_engine", bindings);
|
|
99
|
+
const dispatch_namespaces = extractBindingsOfType("dispatch_namespace", bindings);
|
|
100
|
+
const mtls_certificates = extractBindingsOfType("mtls_certificate", bindings);
|
|
101
|
+
const pipelines = extractBindingsOfType("pipeline", bindings);
|
|
102
|
+
const k2 = extractBindingsOfType("k2", bindings);
|
|
103
|
+
const worker_loaders = extractBindingsOfType("worker_loader", bindings);
|
|
104
|
+
const logfwdr = extractBindingsOfType("logfwdr", bindings);
|
|
105
|
+
const wasm_modules = extractBindingsOfType("wasm_module", bindings);
|
|
106
|
+
const browser = extractBindingsOfType("browser", bindings)[0];
|
|
107
|
+
const analytics = extractBindingsOfType("analytics", bindings)[0];
|
|
108
|
+
const ai = extractBindingsOfType("ai", bindings)[0];
|
|
109
|
+
const images = extractBindingsOfType("images", bindings)[0];
|
|
110
|
+
const stream = extractBindingsOfType("stream", bindings)[0];
|
|
111
|
+
const media = extractBindingsOfType("media", bindings)[0];
|
|
112
|
+
const version_metadata = extractBindingsOfType("version_metadata", bindings)[0];
|
|
113
|
+
const assetsBinding = extractBindingsOfType("assets", bindings)[0];
|
|
114
|
+
const text_blobs = extractBindingsOfType("text_blob", bindings);
|
|
115
|
+
const data_blobs = extractBindingsOfType("data_blob", bindings);
|
|
116
|
+
extractBindingsOfType("inherit", bindings).forEach(({ binding }) => {
|
|
117
|
+
metadataBindings.push({
|
|
118
|
+
name: binding,
|
|
119
|
+
type: "inherit"
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
plain_text.forEach(({ binding, value }) => {
|
|
123
|
+
metadataBindings.push({
|
|
124
|
+
name: binding,
|
|
125
|
+
type: "plain_text",
|
|
126
|
+
text: value
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
json_bindings.forEach(({ binding, value }) => {
|
|
130
|
+
metadataBindings.push({
|
|
131
|
+
name: binding,
|
|
132
|
+
type: "json",
|
|
133
|
+
json: value
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
secret_text.forEach(({ binding, value }) => {
|
|
137
|
+
metadataBindings.push({
|
|
138
|
+
name: binding,
|
|
139
|
+
type: "secret_text",
|
|
140
|
+
text: value
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
kv_namespaces.forEach(({ id, binding, raw }) => {
|
|
144
|
+
if (options?.dryRun) id ??= INHERIT_SYMBOL;
|
|
145
|
+
if (id === void 0) throw new UserError(`${binding} bindings must have an "id" field`, { telemetryMessage: "kv namespace binding missing id" });
|
|
146
|
+
if (id === INHERIT_SYMBOL) metadataBindings.push({
|
|
147
|
+
name: binding,
|
|
148
|
+
type: "inherit"
|
|
149
|
+
});
|
|
150
|
+
else metadataBindings.push({
|
|
151
|
+
name: binding,
|
|
152
|
+
type: "kv_namespace",
|
|
153
|
+
namespace_id: id,
|
|
154
|
+
raw
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
send_email.forEach((emailBinding) => {
|
|
158
|
+
const shared = {
|
|
159
|
+
name: emailBinding.name,
|
|
160
|
+
type: "send_email",
|
|
161
|
+
allowed_sender_addresses: emailBinding.allowed_sender_addresses
|
|
162
|
+
};
|
|
163
|
+
if (emailBinding.destination_address !== void 0) metadataBindings.push({
|
|
164
|
+
...shared,
|
|
165
|
+
destination_address: emailBinding.destination_address
|
|
166
|
+
});
|
|
167
|
+
else if (emailBinding.allowed_destination_addresses !== void 0) metadataBindings.push({
|
|
168
|
+
...shared,
|
|
169
|
+
allowed_destination_addresses: emailBinding.allowed_destination_addresses
|
|
170
|
+
});
|
|
171
|
+
else metadataBindings.push(shared);
|
|
172
|
+
});
|
|
173
|
+
durable_objects.forEach(({ name, class_name, script_name, environment }) => {
|
|
174
|
+
metadataBindings.push({
|
|
175
|
+
name,
|
|
176
|
+
type: "durable_object_namespace",
|
|
177
|
+
class_name,
|
|
178
|
+
...script_name && { script_name },
|
|
179
|
+
...environment && { environment }
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
workflows.forEach(({ binding, name, class_name, script_name, raw }) => {
|
|
183
|
+
metadataBindings.push({
|
|
184
|
+
type: "workflow",
|
|
185
|
+
name: binding,
|
|
186
|
+
workflow_name: name,
|
|
187
|
+
class_name,
|
|
188
|
+
script_name,
|
|
189
|
+
raw
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
queues.forEach(({ binding, queue_name, delivery_delay, raw }) => {
|
|
193
|
+
if (options?.dryRun) queue_name ??= INHERIT_SYMBOL;
|
|
194
|
+
if (queue_name === void 0) throw new UserError(`${binding} bindings must have a "queue" field. Add a "queue" field to the producer in your Worker configuration specifying the name of the Queue to bind to.`, { telemetryMessage: "queue binding missing name" });
|
|
195
|
+
if (queue_name === INHERIT_SYMBOL) metadataBindings.push({
|
|
196
|
+
name: binding,
|
|
197
|
+
type: "inherit"
|
|
198
|
+
});
|
|
199
|
+
else metadataBindings.push({
|
|
200
|
+
type: "queue",
|
|
201
|
+
name: binding,
|
|
202
|
+
queue_name,
|
|
203
|
+
delivery_delay,
|
|
204
|
+
raw
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
r2_buckets.forEach(({ binding, bucket_name, jurisdiction, raw }) => {
|
|
208
|
+
if (options?.dryRun) bucket_name ??= INHERIT_SYMBOL;
|
|
209
|
+
if (bucket_name === void 0) throw new UserError(`${binding} bindings must have a "bucket_name" field. Add a "bucket_name" field to the binding in your Worker configuration specifying the name of the R2 bucket to bind to.`, { telemetryMessage: "r2 bucket binding missing bucket_name" });
|
|
210
|
+
if (bucket_name === INHERIT_SYMBOL) metadataBindings.push({
|
|
211
|
+
name: binding,
|
|
212
|
+
type: "inherit"
|
|
213
|
+
});
|
|
214
|
+
else metadataBindings.push({
|
|
215
|
+
name: binding,
|
|
216
|
+
type: "r2_bucket",
|
|
217
|
+
bucket_name,
|
|
218
|
+
jurisdiction,
|
|
219
|
+
raw
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
d1_databases.forEach(({ binding, database_id, database_internal_env, raw }) => {
|
|
223
|
+
if (options?.dryRun) database_id ??= INHERIT_SYMBOL;
|
|
224
|
+
if (database_id === void 0) throw new UserError(`${binding} bindings must have a "database_id" field. Add a "database_id" field to the binding in your Worker configuration specifying the ID of the D1 database to bind to.`, { telemetryMessage: "d1 database binding missing database_id" });
|
|
225
|
+
if (database_id === INHERIT_SYMBOL) metadataBindings.push({
|
|
226
|
+
name: binding,
|
|
227
|
+
type: "inherit"
|
|
228
|
+
});
|
|
229
|
+
else metadataBindings.push({
|
|
230
|
+
name: binding,
|
|
231
|
+
type: "d1",
|
|
232
|
+
id: database_id,
|
|
233
|
+
internalEnv: database_internal_env,
|
|
234
|
+
raw
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
vectorize.forEach(({ binding, index_name, raw }) => {
|
|
238
|
+
metadataBindings.push({
|
|
239
|
+
name: binding,
|
|
240
|
+
type: "vectorize",
|
|
241
|
+
index_name,
|
|
242
|
+
raw
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
ai_search_namespaces.forEach(({ binding, namespace }) => {
|
|
246
|
+
if (options?.dryRun) namespace ??= INHERIT_SYMBOL;
|
|
247
|
+
if (namespace === void 0) throw new UserError(`${binding} bindings must have a "namespace" field. Add a "namespace" field to the binding in your Worker configuration specifying the AI Search namespace to bind to.`, { telemetryMessage: "ai search namespace binding missing namespace" });
|
|
248
|
+
if (namespace === INHERIT_SYMBOL) metadataBindings.push({
|
|
249
|
+
name: binding,
|
|
250
|
+
type: "inherit"
|
|
251
|
+
});
|
|
252
|
+
else metadataBindings.push({
|
|
253
|
+
name: binding,
|
|
254
|
+
type: "ai_search_namespace",
|
|
255
|
+
namespace
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
ai_search.forEach(({ binding, instance_name }) => {
|
|
259
|
+
metadataBindings.push({
|
|
260
|
+
name: binding,
|
|
261
|
+
type: "ai_search",
|
|
262
|
+
instance_name
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
agent_memory.forEach(({ binding, namespace }) => {
|
|
266
|
+
if (options?.dryRun) namespace ??= INHERIT_SYMBOL;
|
|
267
|
+
if (namespace === void 0) throw new UserError(`${binding} bindings must have a "namespace" field. Add a "namespace" field to the binding in your Worker configuration specifying the namespace to bind to.`, { telemetryMessage: false });
|
|
268
|
+
if (namespace === INHERIT_SYMBOL) metadataBindings.push({
|
|
269
|
+
name: binding,
|
|
270
|
+
type: "inherit"
|
|
271
|
+
});
|
|
272
|
+
else metadataBindings.push({
|
|
273
|
+
name: binding,
|
|
274
|
+
type: "agent_memory",
|
|
275
|
+
namespace
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
hyperdrive.forEach(({ binding, id }) => {
|
|
279
|
+
metadataBindings.push({
|
|
280
|
+
name: binding,
|
|
281
|
+
type: "hyperdrive",
|
|
282
|
+
id
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
secrets_store_secrets.forEach(({ binding, store_id, secret_name }) => {
|
|
286
|
+
metadataBindings.push({
|
|
287
|
+
name: binding,
|
|
288
|
+
type: "secrets_store_secret",
|
|
289
|
+
store_id,
|
|
290
|
+
secret_name
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
artifacts.forEach(({ binding, namespace }) => {
|
|
294
|
+
metadataBindings.push({
|
|
295
|
+
name: binding,
|
|
296
|
+
type: "artifacts",
|
|
297
|
+
namespace
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
unsafe_hello_world.forEach(({ binding, enable_timer }) => {
|
|
301
|
+
metadataBindings.push({
|
|
302
|
+
name: binding,
|
|
303
|
+
type: "unsafe_hello_world",
|
|
304
|
+
enable_timer
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
flagship.forEach(({ binding, app_id }) => {
|
|
308
|
+
if (options?.dryRun) app_id ??= INHERIT_SYMBOL;
|
|
309
|
+
if (app_id === void 0) throw new UserError(`${binding} bindings must have an "app_id" field. Add an "app_id" field to the binding in your Worker configuration specifying the Flagship app to bind to.`, { telemetryMessage: "flagship binding missing app id" });
|
|
310
|
+
metadataBindings.push(app_id === INHERIT_SYMBOL ? {
|
|
311
|
+
name: binding,
|
|
312
|
+
type: "inherit"
|
|
313
|
+
} : {
|
|
314
|
+
name: binding,
|
|
315
|
+
type: "flagship",
|
|
316
|
+
app_id
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
ratelimits.forEach(({ name, namespace_id, simple }) => {
|
|
320
|
+
metadataBindings.push({
|
|
321
|
+
name,
|
|
322
|
+
type: "ratelimit",
|
|
323
|
+
namespace_id,
|
|
324
|
+
simple
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
vpc_services.forEach(({ binding, service_id }) => {
|
|
328
|
+
metadataBindings.push({
|
|
329
|
+
name: binding,
|
|
330
|
+
type: "vpc_service",
|
|
331
|
+
service_id
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
vpc_networks.forEach(({ binding, tunnel_id, network_id }) => {
|
|
335
|
+
metadataBindings.push({
|
|
336
|
+
name: binding,
|
|
337
|
+
type: "vpc_network",
|
|
338
|
+
...tunnel_id !== void 0 ? { tunnel_id } : { network_id }
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
services.forEach(({ binding, service, environment, entrypoint, props, cross_account_grant }) => {
|
|
342
|
+
metadataBindings.push({
|
|
343
|
+
name: binding,
|
|
344
|
+
type: "service",
|
|
345
|
+
service,
|
|
346
|
+
cross_account_grant,
|
|
347
|
+
...environment && { environment },
|
|
348
|
+
...entrypoint && { entrypoint },
|
|
349
|
+
...props && { props }
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
analytics_engine_datasets.forEach(({ binding, dataset }) => {
|
|
353
|
+
metadataBindings.push({
|
|
354
|
+
name: binding,
|
|
355
|
+
type: "analytics_engine",
|
|
356
|
+
dataset
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
dispatch_namespaces.forEach(({ binding, namespace, outbound }) => {
|
|
360
|
+
if (options?.dryRun) namespace ??= INHERIT_SYMBOL;
|
|
361
|
+
if (namespace === void 0) throw new UserError(`${binding} bindings must have a "namespace" field. Add a "namespace" field to the binding in your Worker configuration specifying the dispatch namespace to bind to.`, { telemetryMessage: "dispatch namespace binding missing namespace" });
|
|
362
|
+
if (namespace === INHERIT_SYMBOL) metadataBindings.push({
|
|
363
|
+
name: binding,
|
|
364
|
+
type: "inherit"
|
|
365
|
+
});
|
|
366
|
+
else metadataBindings.push({
|
|
367
|
+
name: binding,
|
|
368
|
+
type: "dispatch_namespace",
|
|
369
|
+
namespace,
|
|
370
|
+
...outbound && { outbound: {
|
|
371
|
+
worker: {
|
|
372
|
+
service: outbound.service,
|
|
373
|
+
environment: outbound.environment
|
|
374
|
+
},
|
|
375
|
+
params: outbound.parameters?.map((p) => ({ name: p }))
|
|
376
|
+
} }
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
mtls_certificates.forEach(({ binding, certificate_id }) => {
|
|
380
|
+
metadataBindings.push({
|
|
381
|
+
name: binding,
|
|
382
|
+
type: "mtls_certificate",
|
|
383
|
+
certificate_id
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
pipelines.forEach(({ binding, stream: pipelineStream, pipeline }) => {
|
|
387
|
+
if (pipelineStream) metadataBindings.push({
|
|
388
|
+
name: binding,
|
|
389
|
+
type: "pipelines",
|
|
390
|
+
stream: pipelineStream
|
|
391
|
+
});
|
|
392
|
+
else if (pipeline) metadataBindings.push({
|
|
393
|
+
name: binding,
|
|
394
|
+
type: "pipelines",
|
|
395
|
+
pipeline
|
|
396
|
+
});
|
|
397
|
+
else throw new Error("Pipeline binding must specify a stream or pipeline");
|
|
398
|
+
});
|
|
399
|
+
k2.forEach(({ binding, stream: k2Stream }) => {
|
|
400
|
+
metadataBindings.push({
|
|
401
|
+
name: binding,
|
|
402
|
+
type: "k2",
|
|
403
|
+
stream: k2Stream
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
worker_loaders.forEach(({ binding }) => {
|
|
407
|
+
metadataBindings.push({
|
|
408
|
+
name: binding,
|
|
409
|
+
type: "worker_loader"
|
|
410
|
+
});
|
|
411
|
+
});
|
|
412
|
+
logfwdr.forEach(({ name, destination }) => {
|
|
413
|
+
metadataBindings.push({
|
|
414
|
+
name,
|
|
415
|
+
type: "logfwdr",
|
|
416
|
+
destination
|
|
417
|
+
});
|
|
418
|
+
});
|
|
419
|
+
wasm_modules.forEach(({ binding: name, source }) => {
|
|
420
|
+
metadataBindings.push({
|
|
421
|
+
name,
|
|
422
|
+
type: "wasm_module",
|
|
423
|
+
part: name
|
|
424
|
+
});
|
|
425
|
+
formData.set(name, new File(["contents" in source ? source.contents : readFileSync(source.path)], "path" in source ? source.path ?? name : name, { type: "application/wasm" }));
|
|
426
|
+
});
|
|
427
|
+
if (browser !== void 0) metadataBindings.push({
|
|
428
|
+
name: browser.binding,
|
|
429
|
+
type: "browser",
|
|
430
|
+
raw: browser.raw
|
|
431
|
+
});
|
|
432
|
+
if (analytics !== void 0) metadataBindings.push({
|
|
433
|
+
name: analytics.binding,
|
|
434
|
+
type: "analytics"
|
|
435
|
+
});
|
|
436
|
+
if (ai !== void 0) metadataBindings.push({
|
|
437
|
+
name: ai.binding,
|
|
438
|
+
staging: ai.staging,
|
|
439
|
+
type: "ai",
|
|
440
|
+
raw: ai.raw
|
|
441
|
+
});
|
|
442
|
+
if (images !== void 0) metadataBindings.push({
|
|
443
|
+
name: images.binding,
|
|
444
|
+
type: "images",
|
|
445
|
+
raw: images.raw
|
|
446
|
+
});
|
|
447
|
+
if (stream !== void 0) metadataBindings.push({
|
|
448
|
+
name: stream.binding,
|
|
449
|
+
type: "stream"
|
|
450
|
+
});
|
|
451
|
+
if (media !== void 0) metadataBindings.push({
|
|
452
|
+
name: media.binding,
|
|
453
|
+
type: "media"
|
|
454
|
+
});
|
|
455
|
+
if (version_metadata !== void 0) metadataBindings.push({
|
|
456
|
+
name: version_metadata.binding,
|
|
457
|
+
type: "version_metadata"
|
|
458
|
+
});
|
|
459
|
+
if (assetsBinding !== void 0) metadataBindings.push({
|
|
460
|
+
name: assetsBinding.binding,
|
|
461
|
+
type: "assets"
|
|
462
|
+
});
|
|
463
|
+
text_blobs.forEach(({ binding: name, source }) => {
|
|
464
|
+
metadataBindings.push({
|
|
465
|
+
name,
|
|
466
|
+
type: "text_blob",
|
|
467
|
+
part: name
|
|
468
|
+
});
|
|
469
|
+
if (name !== "__STATIC_CONTENT_MANIFEST") {
|
|
470
|
+
if ("contents" in source) formData.set(name, new File([source.contents], source.path ?? name, { type: "text/plain" }));
|
|
471
|
+
else formData.set(name, new File([readFileSync(source.path)], source.path, { type: "text/plain" }));
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
data_blobs.forEach(({ binding: name, source }) => {
|
|
475
|
+
metadataBindings.push({
|
|
476
|
+
name,
|
|
477
|
+
type: "data_blob",
|
|
478
|
+
part: name
|
|
479
|
+
});
|
|
480
|
+
formData.set(name, new File(["contents" in source ? source.contents : readFileSync(source.path)], "path" in source ? source.path ?? name : name, { type: "application/octet-stream" }));
|
|
481
|
+
});
|
|
482
|
+
for (const [bindingName, config] of Object.entries(bindings ?? {})) if (isUnsafeBindingType(config.type) && config.type !== "unsafe_hello_world") {
|
|
483
|
+
const { type, ...data } = config;
|
|
484
|
+
metadataBindings.push({
|
|
485
|
+
name: bindingName,
|
|
486
|
+
type: type.slice(7),
|
|
487
|
+
...data
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
const manifestModuleName = "__STATIC_CONTENT_MANIFEST";
|
|
491
|
+
if (modules?.some(({ name }) => name === manifestModuleName) && main.type === "esm") {
|
|
492
|
+
assert(modules !== void 0);
|
|
493
|
+
const subDirs = new Set(modules.map((module) => path.posix.dirname(module.name)));
|
|
494
|
+
for (const subDir of subDirs) {
|
|
495
|
+
if (subDir === ".") continue;
|
|
496
|
+
const relativePath = path.posix.relative(subDir, manifestModuleName);
|
|
497
|
+
const filePath = path.posix.join(subDir, manifestModuleName);
|
|
498
|
+
modules.push({
|
|
499
|
+
name: filePath,
|
|
500
|
+
filePath,
|
|
501
|
+
content: `export { default } from ${JSON.stringify(relativePath)};`,
|
|
502
|
+
type: "esm"
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
if (main.type === "commonjs") {
|
|
507
|
+
for (const module of Object.values([...modules || []])) if (module.name === "__STATIC_CONTENT_MANIFEST") {
|
|
508
|
+
formData.set(module.name, new File([module.content], module.name, { type: "text/plain" }));
|
|
509
|
+
modules = modules?.filter((m) => m !== module);
|
|
510
|
+
} else if (module.type === "compiled-wasm" || module.type === "text" || module.type === "buffer") {
|
|
511
|
+
const name = module.name.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
512
|
+
metadataBindings.push({
|
|
513
|
+
name,
|
|
514
|
+
type: module.type === "compiled-wasm" ? "wasm_module" : module.type === "text" ? "text_blob" : "data_blob",
|
|
515
|
+
part: name
|
|
516
|
+
});
|
|
517
|
+
formData.set(name, new File([module.content], module.name, { type: module.type === "compiled-wasm" ? "application/wasm" : module.type === "text" ? "text/plain" : "application/octet-stream" }));
|
|
518
|
+
modules = modules?.filter((m) => m !== module);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
let capnpSchemaOutputFile;
|
|
522
|
+
if (options?.unsafe?.capnp) {
|
|
523
|
+
const capnpOutput = handleUnsafeCapnp(options.unsafe.capnp);
|
|
524
|
+
capnpSchemaOutputFile = `./capnp-${Date.now()}.compiled`;
|
|
525
|
+
formData.set(capnpSchemaOutputFile, new File([capnpOutput], capnpSchemaOutputFile, { type: "application/octet-stream" }));
|
|
526
|
+
}
|
|
527
|
+
let keep_bindings = void 0;
|
|
528
|
+
if (keepVars) {
|
|
529
|
+
keep_bindings ??= [];
|
|
530
|
+
keep_bindings.push("plain_text", "json");
|
|
531
|
+
}
|
|
532
|
+
if (keepSecrets) {
|
|
533
|
+
keep_bindings ??= [];
|
|
534
|
+
keep_bindings.push("secret_text", "secret_key");
|
|
535
|
+
}
|
|
536
|
+
if (keepBindings) {
|
|
537
|
+
keep_bindings ??= [];
|
|
538
|
+
keep_bindings.push(...keepBindings);
|
|
539
|
+
}
|
|
540
|
+
const metadata = {
|
|
541
|
+
...main.type !== "commonjs" ? { main_module: main.name } : { body_part: main.name },
|
|
542
|
+
bindings: metadataBindings,
|
|
543
|
+
containers: worker.containers === void 0 ? void 0 : worker.containers.map((c) => ({
|
|
544
|
+
...c.name !== void 0 && { name: c.name },
|
|
545
|
+
...c.class_name !== void 0 && { class_name: c.class_name },
|
|
546
|
+
...c.images !== void 0 && { images: c.images }
|
|
547
|
+
})),
|
|
548
|
+
...compatibility_date && { compatibility_date },
|
|
549
|
+
...compatibility_flags && { compatibility_flags },
|
|
550
|
+
...migrations && { migrations },
|
|
551
|
+
...code_update_strategy && { code_update_strategy },
|
|
552
|
+
...configuredExports && Object.keys(configuredExports).length > 0 && { exports: configuredExports },
|
|
553
|
+
capnp_schema: capnpSchemaOutputFile,
|
|
554
|
+
...keep_bindings && { keep_bindings },
|
|
555
|
+
...logpush !== void 0 && { logpush },
|
|
556
|
+
...placement && { placement },
|
|
557
|
+
...tail_consumers && { tail_consumers },
|
|
558
|
+
...streaming_tail_consumers && { streaming_tail_consumers },
|
|
559
|
+
...limits && { limits },
|
|
560
|
+
...annotations && { annotations },
|
|
561
|
+
...keep_assets !== void 0 && { keep_assets },
|
|
562
|
+
...assets && { assets: {
|
|
563
|
+
jwt: assets.jwt,
|
|
564
|
+
config: assetConfig
|
|
565
|
+
} },
|
|
566
|
+
...observability && { observability },
|
|
567
|
+
...cache && { cache_options: cache },
|
|
568
|
+
...package_dependencies?.length && { package_dependencies }
|
|
569
|
+
};
|
|
570
|
+
if (options?.unsafe?.metadata !== void 0) for (const key of Object.keys(options.unsafe.metadata)) metadata[key] = options.unsafe.metadata[key];
|
|
571
|
+
formData.set("metadata", JSON.stringify(metadata));
|
|
572
|
+
if (main.type === "commonjs" && modules && modules.length > 0) throw new TypeError("More than one module can only be specified when type = 'esm'");
|
|
573
|
+
for (const module of [main].concat(modules || [])) formData.set(module.name, new File([module.content], module.name, { type: toMimeType(module.type ?? main.type ?? "esm") }));
|
|
574
|
+
for (const sourceMap of sourceMaps || []) formData.set(sourceMap.name, new File([sourceMap.content], sourceMap.name, { type: "application/source-map" }));
|
|
575
|
+
return formData;
|
|
576
|
+
}
|
|
577
|
+
//#endregion
|
|
578
|
+
export { handleUnsafeCapnp as i, fromMimeType as n, moduleTypeMimeType as r, createWorkerUploadForm as t };
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
declare const moduleTypeMimeType: {
|
|
5
|
-
[type in CfModuleType]: string | undefined;
|
|
6
|
-
};
|
|
1
|
+
import { Binding, CfCapnp, CfModuleType, CfWorkerInit } from "@cloudflare/workers-utils";
|
|
2
|
+
import { FormData } from "undici";
|
|
3
|
+
//#region src/deploy/helpers/create-worker-upload-form.d.ts
|
|
4
|
+
declare const moduleTypeMimeType: { [type in CfModuleType]: string | undefined; };
|
|
7
5
|
declare function fromMimeType(mimeType: string): CfModuleType;
|
|
8
6
|
/**
|
|
9
7
|
* Creates a `FormData` upload from Worker data and bindings
|
|
10
8
|
*/
|
|
11
9
|
declare function createWorkerUploadForm(worker: Omit<CfWorkerInit, "bindings" | "rawBindings">, bindings: Record<string, Binding> | undefined, options?: {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
dryRun?: true;
|
|
11
|
+
unsafe?: {
|
|
12
|
+
metadata?: Record<string, unknown>;
|
|
13
|
+
capnp?: CfCapnp;
|
|
14
|
+
};
|
|
17
15
|
}): FormData;
|
|
18
|
-
|
|
19
|
-
export { createWorkerUploadForm, fromMimeType, moduleTypeMimeType };
|
|
16
|
+
//#endregion
|
|
17
|
+
export { createWorkerUploadForm, fromMimeType, moduleTypeMimeType };
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { createWorkerUploadForm, fromMimeType, moduleTypeMimeType } from './chunk-DSGVRFIS.mjs';
|
|
3
|
-
import './chunk-U6NEESU5.mjs';
|
|
4
|
-
|
|
5
|
-
createRequire(import.meta.url || (typeof __filename === "string" ? __filename : "/"));
|
|
1
|
+
export { t as createWorkerUploadForm, n as fromMimeType, r as moduleTypeMimeType } from "./create-worker-upload-form-BlSu1EfR.mjs";
|