Skip to content

Commit f3adcc7

Browse files
committed
Fix type/validation divergence: align Cf* types, config types, and upload form
- Update Cf* interfaces in worker.ts: ID fields now optional + INHERIT_SYMBOL - Update config types in environment.ts: ID fields now optional - Add INHERIT_SYMBOL handling in create-worker-upload-form.ts for all 7 new provisionable binding types (queue, vectorize, hyperdrive, dispatch_namespace, pipeline, vpc_service, mtls_certificate) - Fix downstream type errors in miniflare, queues client, type-generation, and print-bindings This ensures the type system accurately reflects that provisionable bindings may not have their ID field set in config, and that INHERIT_SYMBOL flows correctly through the entire pipeline from config -> binding -> upload form.
1 parent 463f36a commit f3adcc7

File tree

7 files changed

+168
-82
lines changed

7 files changed

+168
-82
lines changed

packages/workers-utils/src/config/environment.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -848,8 +848,8 @@ export interface EnvironmentNonInheritable {
848848
/** The binding name used to refer to the Queue in the Worker. */
849849
binding: string;
850850

851-
/** The name of this Queue. */
852-
queue: string;
851+
/** The name of this Queue. Omit to auto-provision. */
852+
queue?: string;
853853

854854
/** The number of seconds to wait before delivering a message */
855855
delivery_delay?: number;
@@ -957,8 +957,8 @@ export interface EnvironmentNonInheritable {
957957
vectorize: {
958958
/** The binding name used to refer to the Vectorize index in the Worker. */
959959
binding: string;
960-
/** The name of the index. */
961-
index_name: string;
960+
/** The name of the index. Omit to auto-provision. */
961+
index_name?: string;
962962
/** Whether the Vectorize index should be remote or not in local development */
963963
remote?: boolean;
964964
}[];
@@ -1015,8 +1015,8 @@ export interface EnvironmentNonInheritable {
10151015
hyperdrive: {
10161016
/** The binding name used to refer to the project in the Worker. */
10171017
binding: string;
1018-
/** The id of the database. */
1019-
id: string;
1018+
/** The id of the database. Omit to auto-provision. */
1019+
id?: string;
10201020
/** The local database connection string for `wrangler dev` */
10211021
localConnectionString?: string;
10221022
}[];
@@ -1231,8 +1231,8 @@ export interface EnvironmentNonInheritable {
12311231
mtls_certificates: {
12321232
/** The binding name used to refer to the certificate in the Worker */
12331233
binding: string;
1234-
/** The uuid of the uploaded mTLS certificate */
1235-
certificate_id: string;
1234+
/** The uuid of the uploaded mTLS certificate. Omit to auto-provision. */
1235+
certificate_id?: string;
12361236
/** Whether the mtls fetcher should be remote or not in local development */
12371237
remote?: boolean;
12381238
}[];
@@ -1273,8 +1273,8 @@ export interface EnvironmentNonInheritable {
12731273
dispatch_namespaces: {
12741274
/** The binding name used to refer to the bound service. */
12751275
binding: string;
1276-
/** The namespace to bind to. */
1277-
namespace: string;
1276+
/** The namespace to bind to. Omit to auto-provision. */
1277+
namespace?: string;
12781278
/** Details about the outbound Worker which will handle outbound requests from your namespace */
12791279
outbound?: DispatchNamespaceOutbound;
12801280
/** Whether the Dispatch Namespace should be remote or not in local development */
@@ -1293,8 +1293,8 @@ export interface EnvironmentNonInheritable {
12931293
pipelines: {
12941294
/** The binding name used to refer to the bound service. */
12951295
binding: string;
1296-
/** Name of the Pipeline to bind */
1297-
pipeline: string;
1296+
/** Name of the Pipeline to bind. Omit to auto-provision. */
1297+
pipeline?: string;
12981298
/** Whether the pipeline should be remote or not in local development */
12991299
remote?: boolean;
13001300
}[];
@@ -1385,8 +1385,8 @@ export interface EnvironmentNonInheritable {
13851385
vpc_services: {
13861386
/** The binding name used to refer to the VPC service in the Worker. */
13871387
binding: string;
1388-
/** The service ID of the VPC connectivity service. */
1389-
service_id: string;
1388+
/** The service ID of the VPC connectivity service. Omit to auto-provision. */
1389+
service_id?: string;
13901390
/** Whether the VPC service is remote or not */
13911391
remote?: boolean;
13921392
}[];

packages/workers-utils/src/worker.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export interface CfWorkflow {
196196

197197
export interface CfQueue {
198198
binding: string;
199-
queue_name: string;
199+
queue_name?: string | typeof INHERIT_SYMBOL;
200200
delivery_delay?: number;
201201
remote?: boolean;
202202
raw?: boolean;
@@ -225,7 +225,7 @@ export interface CfD1Database {
225225

226226
export interface CfVectorize {
227227
binding: string;
228-
index_name: string;
228+
index_name?: string | typeof INHERIT_SYMBOL;
229229
raw?: boolean;
230230
remote?: boolean;
231231
}
@@ -268,7 +268,7 @@ export interface CfRateLimit {
268268

269269
export interface CfHyperdrive {
270270
binding: string;
271-
id: string;
271+
id?: string | typeof INHERIT_SYMBOL;
272272
localConnectionString?: string;
273273
}
274274

@@ -284,7 +284,7 @@ export interface CfService {
284284

285285
export interface CfVpcService {
286286
binding: string;
287-
service_id: string;
287+
service_id?: string | typeof INHERIT_SYMBOL;
288288
remote?: boolean;
289289
}
290290

@@ -302,7 +302,7 @@ export interface CfAnalyticsEngineDataset {
302302

303303
export interface CfDispatchNamespace {
304304
binding: string;
305-
namespace: string;
305+
namespace?: string | typeof INHERIT_SYMBOL;
306306
outbound?: {
307307
service: string;
308308
environment?: string;
@@ -313,7 +313,7 @@ export interface CfDispatchNamespace {
313313

314314
export interface CfMTlsCertificate {
315315
binding: string;
316-
certificate_id: string;
316+
certificate_id?: string | typeof INHERIT_SYMBOL;
317317
remote?: boolean;
318318
}
319319

@@ -332,7 +332,7 @@ export interface CfAssetsBinding {
332332

333333
export interface CfPipeline {
334334
binding: string;
335-
pipeline: string;
335+
pipeline?: string | typeof INHERIT_SYMBOL;
336336
remote?: boolean;
337337
}
338338

packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts

Lines changed: 120 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,23 @@ export function createWorkerUploadForm(
257257
});
258258

259259
queues.forEach(({ binding, queue_name, delivery_delay, raw }) => {
260-
metadataBindings.push({
261-
type: "queue",
262-
name: binding,
263-
queue_name,
264-
delivery_delay,
265-
raw,
266-
});
260+
if (options?.dryRun) {
261+
queue_name ??= INHERIT_SYMBOL;
262+
}
263+
if (queue_name === undefined) {
264+
throw new UserError(`${binding} bindings must have a "queue_name" field`);
265+
}
266+
if (queue_name === INHERIT_SYMBOL) {
267+
metadataBindings.push({ name: binding, type: "inherit" });
268+
} else {
269+
metadataBindings.push({
270+
type: "queue",
271+
name: binding,
272+
queue_name,
273+
delivery_delay,
274+
raw,
275+
});
276+
}
267277
});
268278

269279
r2_buckets.forEach(({ binding, bucket_name, jurisdiction, raw }) => {
@@ -321,12 +331,24 @@ export function createWorkerUploadForm(
321331
);
322332

323333
vectorize.forEach(({ binding, index_name, raw }) => {
324-
metadataBindings.push({
325-
name: binding,
326-
type: "vectorize",
327-
index_name: index_name,
328-
raw,
329-
});
334+
if (options?.dryRun) {
335+
index_name ??= INHERIT_SYMBOL;
336+
}
337+
if (index_name === undefined) {
338+
throw new UserError(
339+
`${binding} bindings must have an "index_name" field`
340+
);
341+
}
342+
if (index_name === INHERIT_SYMBOL) {
343+
metadataBindings.push({ name: binding, type: "inherit" });
344+
} else {
345+
metadataBindings.push({
346+
name: binding,
347+
type: "vectorize",
348+
index_name,
349+
raw,
350+
});
351+
}
330352
});
331353

332354
ai_search_namespaces.forEach(({ binding, namespace }) => {
@@ -360,11 +382,21 @@ export function createWorkerUploadForm(
360382
});
361383

362384
hyperdrive.forEach(({ binding, id }) => {
363-
metadataBindings.push({
364-
name: binding,
365-
type: "hyperdrive",
366-
id: id,
367-
});
385+
if (options?.dryRun) {
386+
id ??= INHERIT_SYMBOL;
387+
}
388+
if (id === undefined) {
389+
throw new UserError(`${binding} bindings must have an "id" field`);
390+
}
391+
if (id === INHERIT_SYMBOL) {
392+
metadataBindings.push({ name: binding, type: "inherit" });
393+
} else {
394+
metadataBindings.push({
395+
name: binding,
396+
type: "hyperdrive",
397+
id,
398+
});
399+
}
368400
});
369401

370402
secrets_store_secrets.forEach(({ binding, store_id, secret_name }) => {
@@ -394,11 +426,21 @@ export function createWorkerUploadForm(
394426
});
395427

396428
vpc_services.forEach(({ binding, service_id }) => {
397-
metadataBindings.push({
398-
name: binding,
399-
type: "vpc_service",
400-
service_id,
401-
});
429+
if (options?.dryRun) {
430+
service_id ??= INHERIT_SYMBOL;
431+
}
432+
if (service_id === undefined) {
433+
throw new UserError(`${binding} bindings must have a "service_id" field`);
434+
}
435+
if (service_id === INHERIT_SYMBOL) {
436+
metadataBindings.push({ name: binding, type: "inherit" });
437+
} else {
438+
metadataBindings.push({
439+
name: binding,
440+
type: "vpc_service",
441+
service_id,
442+
});
443+
}
402444
});
403445

404446
vpc_networks.forEach(({ binding, tunnel_id, network_id }) => {
@@ -439,36 +481,68 @@ export function createWorkerUploadForm(
439481
});
440482

441483
dispatch_namespaces.forEach(({ binding, namespace, outbound }) => {
442-
metadataBindings.push({
443-
name: binding,
444-
type: "dispatch_namespace",
445-
namespace,
446-
...(outbound && {
447-
outbound: {
448-
worker: {
449-
service: outbound.service,
450-
environment: outbound.environment,
484+
if (options?.dryRun) {
485+
namespace ??= INHERIT_SYMBOL;
486+
}
487+
if (namespace === undefined) {
488+
throw new UserError(`${binding} bindings must have a "namespace" field`);
489+
}
490+
if (namespace === INHERIT_SYMBOL) {
491+
metadataBindings.push({ name: binding, type: "inherit" });
492+
} else {
493+
metadataBindings.push({
494+
name: binding,
495+
type: "dispatch_namespace",
496+
namespace,
497+
...(outbound && {
498+
outbound: {
499+
worker: {
500+
service: outbound.service,
501+
environment: outbound.environment,
502+
},
503+
params: outbound.parameters?.map((p) => ({ name: p })),
451504
},
452-
params: outbound.parameters?.map((p) => ({ name: p })),
453-
},
454-
}),
455-
});
505+
}),
506+
});
507+
}
456508
});
457509

458510
mtls_certificates.forEach(({ binding, certificate_id }) => {
459-
metadataBindings.push({
460-
name: binding,
461-
type: "mtls_certificate",
462-
certificate_id,
463-
});
511+
if (options?.dryRun) {
512+
certificate_id ??= INHERIT_SYMBOL;
513+
}
514+
if (certificate_id === undefined) {
515+
throw new UserError(
516+
`${binding} bindings must have a "certificate_id" field`
517+
);
518+
}
519+
if (certificate_id === INHERIT_SYMBOL) {
520+
metadataBindings.push({ name: binding, type: "inherit" });
521+
} else {
522+
metadataBindings.push({
523+
name: binding,
524+
type: "mtls_certificate",
525+
certificate_id,
526+
});
527+
}
464528
});
465529

466530
pipelines.forEach(({ binding, pipeline }) => {
467-
metadataBindings.push({
468-
name: binding,
469-
type: "pipelines",
470-
pipeline: pipeline,
471-
});
531+
if (options?.dryRun) {
532+
pipeline ??= INHERIT_SYMBOL;
533+
}
534+
if (pipeline === undefined) {
535+
throw new UserError(`${binding} bindings must have a "pipeline" field`);
536+
}
537+
if (pipeline === INHERIT_SYMBOL) {
538+
metadataBindings.push({ name: binding, type: "inherit" });
539+
} else {
540+
metadataBindings.push({
541+
name: binding,
542+
type: "pipelines",
543+
pipeline,
544+
});
545+
}
472546
});
473547

474548
worker_loaders.forEach(({ binding }) => {

0 commit comments

Comments
 (0)