Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions packages/workers-utils/src/config/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,8 +848,8 @@ export interface EnvironmentNonInheritable {
/** The binding name used to refer to the Queue in the Worker. */
binding: string;

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

/** The number of seconds to wait before delivering a message */
delivery_delay?: number;
Expand Down Expand Up @@ -958,7 +958,7 @@ export interface EnvironmentNonInheritable {
/** The binding name used to refer to the Vectorize index in the Worker. */
binding: string;
/** The name of the index. */
index_name: string;
index_name?: string;
/** Whether the Vectorize index should be remote or not in local development */
remote?: boolean;
}[];
Expand Down Expand Up @@ -1016,7 +1016,7 @@ export interface EnvironmentNonInheritable {
/** The binding name used to refer to the project in the Worker. */
binding: string;
/** The id of the database. */
id: string;
id?: string;
/** The local database connection string for `wrangler dev` */
localConnectionString?: string;
}[];
Expand Down Expand Up @@ -1232,7 +1232,7 @@ export interface EnvironmentNonInheritable {
/** The binding name used to refer to the certificate in the Worker */
binding: string;
/** The uuid of the uploaded mTLS certificate */
certificate_id: string;
certificate_id?: string;
/** Whether the mtls fetcher should be remote or not in local development */
remote?: boolean;
}[];
Expand Down Expand Up @@ -1274,7 +1274,7 @@ export interface EnvironmentNonInheritable {
/** The binding name used to refer to the bound service. */
binding: string;
/** The namespace to bind to. */
namespace: string;
namespace?: string;
/** Details about the outbound Worker which will handle outbound requests from your namespace */
outbound?: DispatchNamespaceOutbound;
/** Whether the Dispatch Namespace should be remote or not in local development */
Expand All @@ -1294,7 +1294,7 @@ export interface EnvironmentNonInheritable {
/** The binding name used to refer to the bound service. */
binding: string;
/** Name of the Pipeline to bind */
pipeline: string;
pipeline?: string;
/** Whether the pipeline should be remote or not in local development */
remote?: boolean;
}[];
Expand Down Expand Up @@ -1386,7 +1386,7 @@ export interface EnvironmentNonInheritable {
/** The binding name used to refer to the VPC service in the Worker. */
binding: string;
/** The service ID of the VPC connectivity service. */
service_id: string;
service_id?: string;
/** Whether the VPC service is remote or not */
remote?: boolean;
}[];
Expand Down
22 changes: 12 additions & 10 deletions packages/workers-utils/src/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3751,11 +3751,12 @@ const validateQueueBinding: ValidatorFn = (diagnostics, field, value) => {
}

if (
!isRequiredProperty(value, "queue", "string") ||
(value as { queue: string }).queue.length === 0
!isOptionalProperty(value, "queue", "string") ||
(isRequiredProperty(value, "queue", "string") &&
(value as { queue: string }).queue.length === 0)
) {
diagnostics.errors.push(
`"${field}" bindings should have a string "queue" field but got ${JSON.stringify(
`"${field}" bindings should, optionally, have a string "queue" field but got ${JSON.stringify(
value
)}.`
);
Expand Down Expand Up @@ -3940,7 +3941,7 @@ const validateVectorizeBinding: ValidatorFn = (diagnostics, field, value) => {
);
isValid = false;
}
if (!isRequiredProperty(value, "index_name", "string")) {
if (!isOptionalProperty(value, "index_name", "string")) {
diagnostics.errors.push(
`"${field}" bindings must have an "index_name" field but got ${JSON.stringify(
value
Expand Down Expand Up @@ -4052,7 +4053,7 @@ const validateHyperdriveBinding: ValidatorFn = (diagnostics, field, value) => {
);
isValid = false;
}
if (!isRequiredProperty(value, "id", "string")) {
if (!isOptionalProperty(value, "id", "string")) {
diagnostics.errors.push(
`"${field}" bindings must have a "id" field but got ${JSON.stringify(
value
Expand Down Expand Up @@ -4089,7 +4090,7 @@ const validateVpcServiceBinding: ValidatorFn = (diagnostics, field, value) => {
);
isValid = false;
}
if (!isRequiredProperty(value, "service_id", "string")) {
if (!isOptionalProperty(value, "service_id", "string")) {
diagnostics.errors.push(
`"${field}" bindings must have a "service_id" field but got ${JSON.stringify(
value
Expand Down Expand Up @@ -4381,7 +4382,7 @@ const validateWorkerNamespaceBinding: ValidatorFn = (
);
isValid = false;
}
if (!isRequiredProperty(value, "namespace", "string")) {
if (!isOptionalProperty(value, "namespace", "string")) {
diagnostics.errors.push(
`"${field}" should have a string "namespace" field but got ${JSON.stringify(
value
Expand Down Expand Up @@ -4477,8 +4478,9 @@ const validateMTlsCertificateBinding: ValidatorFn = (
isValid = false;
}
if (
!isRequiredProperty(value, "certificate_id", "string") ||
(value as { certificate_id: string }).certificate_id.length === 0
!isOptionalProperty(value, "certificate_id", "string") ||
((value as { certificate_id?: string }).certificate_id !== undefined &&
(value as { certificate_id: string }).certificate_id.length === 0)
) {
diagnostics.errors.push(
`"${field}" bindings should have a string "certificate_id" field but got ${JSON.stringify(
Expand Down Expand Up @@ -4666,7 +4668,7 @@ const validatePipelineBinding: ValidatorFn = (diagnostics, field, value) => {
);
isValid = false;
}
if (!isRequiredProperty(value, "pipeline", "string")) {
if (!isOptionalProperty(value, "pipeline", "string")) {
diagnostics.errors.push(
`"${field}" bindings must have a string "pipeline" field but got ${JSON.stringify(
value
Expand Down
14 changes: 7 additions & 7 deletions packages/workers-utils/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export interface CfWorkflow {

export interface CfQueue {
binding: string;
queue_name: string;
queue_name?: string | typeof INHERIT_SYMBOL;
delivery_delay?: number;
remote?: boolean;
raw?: boolean;
Expand Down Expand Up @@ -225,7 +225,7 @@ export interface CfD1Database {

export interface CfVectorize {
binding: string;
index_name: string;
index_name?: string | typeof INHERIT_SYMBOL;
raw?: boolean;
remote?: boolean;
}
Expand Down Expand Up @@ -268,7 +268,7 @@ export interface CfRateLimit {

export interface CfHyperdrive {
binding: string;
id: string;
id?: string | typeof INHERIT_SYMBOL;
localConnectionString?: string;
}

Expand All @@ -284,7 +284,7 @@ export interface CfService {

export interface CfVpcService {
binding: string;
service_id: string;
service_id?: string | typeof INHERIT_SYMBOL;
remote?: boolean;
}

Expand All @@ -302,7 +302,7 @@ export interface CfAnalyticsEngineDataset {

export interface CfDispatchNamespace {
binding: string;
namespace: string;
namespace?: string | typeof INHERIT_SYMBOL;
outbound?: {
service: string;
environment?: string;
Expand All @@ -313,7 +313,7 @@ export interface CfDispatchNamespace {

export interface CfMTlsCertificate {
binding: string;
certificate_id: string;
certificate_id?: string | typeof INHERIT_SYMBOL;
remote?: boolean;
}

Expand All @@ -332,7 +332,7 @@ export interface CfAssetsBinding {

export interface CfPipeline {
binding: string;
pipeline: string;
pipeline?: string | typeof INHERIT_SYMBOL;
remote?: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2038,7 +2038,6 @@ describe("normalizeAndValidateConfig()", () => {
{
vectorize: [
{},
{ binding: "VALID" },
{ binding: 2000, index_name: 2111 },
{
binding: "BINDING_2",
Expand All @@ -2056,10 +2055,8 @@ describe("normalizeAndValidateConfig()", () => {
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
"Processing wrangler configuration:
- "vectorize[0]" bindings should have a string "binding" field but got {}.
- "vectorize[0]" bindings must have an "index_name" field but got {}.
- "vectorize[1]" bindings must have an "index_name" field but got {"binding":"VALID"}.
- "vectorize[2]" bindings should have a string "binding" field but got {"binding":2000,"index_name":2111}.
- "vectorize[2]" bindings must have an "index_name" field but got {"binding":2000,"index_name":2111}."
- "vectorize[1]" bindings should have a string "binding" field but got {"binding":2000,"index_name":2111}.
- "vectorize[1]" bindings must have an "index_name" field but got {"binding":2000,"index_name":2111}."
`);
});

Expand Down Expand Up @@ -3537,9 +3534,7 @@ describe("normalizeAndValidateConfig()", () => {
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
"Processing wrangler configuration:
- "hyperdrive[0]" bindings should have a string "binding" field but got {}.
- "hyperdrive[0]" bindings must have a "id" field but got {}.
- "hyperdrive[2]" bindings should have a string "binding" field but got {"binding":2000,"project":2111}.
- "hyperdrive[2]" bindings must have a "id" field but got {"binding":2000,"project":2111}."
- "hyperdrive[2]" bindings should have a string "binding" field but got {"binding":2000,"project":2111}."
`);
});
});
Expand Down Expand Up @@ -3597,11 +3592,9 @@ describe("normalizeAndValidateConfig()", () => {
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
"Processing wrangler configuration:
- "queues.producers[0]" bindings should have a string "binding" field but got {}.
- "queues.producers[0]" bindings should have a string "queue" field but got {}.
- "queues.producers[1]" bindings should have a string "queue" field but got {"binding":"QUEUE_BINDING_1"}.
- "queues.producers[2]" bindings should have a string "binding" field but got {"binding":2333,"queue":2444}.
- "queues.producers[2]" bindings should have a string "queue" field but got {"binding":2333,"queue":2444}.
- "queues.producers[3]" bindings should have a string "queue" field but got {"binding":"QUEUE_BINDING_3","queue":""}."
- "queues.producers[2]" bindings should, optionally, have a string "queue" field but got {"binding":2333,"queue":2444}.
- "queues.producers[3]" bindings should, optionally, have a string "queue" field but got {"binding":"QUEUE_BINDING_3","queue":""}."
`);
});

Expand Down Expand Up @@ -4122,8 +4115,7 @@ describe("normalizeAndValidateConfig()", () => {
- "dispatch_namespaces[2]" should have a string "namespace" field but got {"binding":123,"namespace":456}.
- "dispatch_namespaces[3]" should have a string "namespace" field but got {"binding":"DISPATCH_NAMESPACE_BINDING_1","namespace":456}.
- "dispatch_namespaces[5]" should have a string "binding" field but got {"binding":123,"namespace":"DISPATCH_NAMESPACE_BINDING_SERVICE_1"}.
- "dispatch_namespaces[6]" should have a string "binding" field but got {"binding":123,"service":456}.
- "dispatch_namespaces[6]" should have a string "namespace" field but got {"binding":123,"service":456}."
- "dispatch_namespaces[6]" should have a string "binding" field but got {"binding":123,"service":456}."
`);
});

Expand Down Expand Up @@ -4306,11 +4298,8 @@ describe("normalizeAndValidateConfig()", () => {
- "mtls_certificates" bindings should be objects, but got 123
- "mtls_certificates" bindings should be objects, but got false
- "mtls_certificates[3]" bindings should have a string "binding" field but got {"binding":123,"namespace":123}.
- "mtls_certificates[3]" bindings should have a string "certificate_id" field but got {"binding":123,"namespace":123}.
- "mtls_certificates[4]" bindings should have a string "certificate_id" field but got {"binding":"CERT_ONE","id":"1234"}.
- "mtls_certificates[5]" bindings should have a string "certificate_id" field but got {"binding":"CERT_TWO","certificate_id":1234}.
- "mtls_certificates[7]" bindings should have a string "binding" field but got {"binding":true,"service":"1234"}.
- "mtls_certificates[7]" bindings should have a string "certificate_id" field but got {"binding":true,"service":"1234"}."
- "mtls_certificates[7]" bindings should have a string "binding" field but got {"binding":true,"service":"1234"}."
`);
});
});
Expand Down Expand Up @@ -4422,9 +4411,7 @@ describe("normalizeAndValidateConfig()", () => {
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
"Processing wrangler configuration:
- "pipelines[0]" bindings must have a string "binding" field but got {}.
- "pipelines[0]" bindings must have a string "pipeline" field but got {}.
- "pipelines[2]" bindings must have a string "binding" field but got {"binding":2000,"project":2111}.
- "pipelines[2]" bindings must have a string "pipeline" field but got {"binding":2000,"project":2111}."
- "pipelines[2]" bindings must have a string "binding" field but got {"binding":2000,"project":2111}."
`);
});
});
Expand Down Expand Up @@ -4861,7 +4848,6 @@ describe("normalizeAndValidateConfig()", () => {
service_id: "0199295b-b3ac-7760-8246-bca40877b3e9",
},
{ binding: null, service_id: 123, invalid: true },
{ binding: "MISSING_SERVICE_ID" },
],
} as unknown as RawConfig,
undefined,
Expand All @@ -4873,10 +4859,8 @@ describe("normalizeAndValidateConfig()", () => {
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
"Processing wrangler configuration:
- "vpc_services[0]" bindings should have a string "binding" field but got {}.
- "vpc_services[0]" bindings must have a "service_id" field but got {}.
- "vpc_services[2]" bindings should have a string "binding" field but got {"binding":null,"service_id":123,"invalid":true}.
- "vpc_services[2]" bindings must have a "service_id" field but got {"binding":null,"service_id":123,"invalid":true}.
- "vpc_services[3]" bindings must have a "service_id" field but got {"binding":"MISSING_SERVICE_ID"}."
- "vpc_services[2]" bindings must have a "service_id" field but got {"binding":null,"service_id":123,"invalid":true}."
`);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ describe("experimental_getWranglerCommands", () => {
"requiresArg": true,
"type": "string",
},
"experimental-auto-create": {
"alias": "x-auto-create",
"default": true,
"describe": "Automatically provision draft bindings with new resources",
"hidden": true,
"type": "boolean",
},
"experimental-provision": {
"alias": [
"x-provision",
Expand Down
29 changes: 29 additions & 0 deletions packages/wrangler/src/__tests__/helpers/mock-dialogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,35 @@ export function mockSelect<Values>(
}
}

/**
* The expected values for a search (autocomplete) request.
*/
export interface SearchExpectation {
/** The text expected to be seen in the search dialog (without the chalk-dimmed hint). */
text: string;
/** The mock response sent back from the search dialog. */
result: string;
}

/**
* Mock the implementation of `search()` (autocomplete prompt) that will respond
* with configured results for configured search text messages.
*/
export function mockSearch(...expectations: SearchExpectation[]) {
for (const expectation of expectations) {
(prompts as unknown as Mock).mockImplementationOnce(
({ type, name, message }) => {
expect(type).toStrictEqual("autocomplete");
expect(name).toStrictEqual("value");
// The message includes a chalk-dimmed "(type to filter)" suffix,
// so we check with a `toContain` rather than exact match.
expect(message).toContain(expectation.text);
return Promise.resolve({ value: expectation.result });
}
);
}
}

export function clearDialogs() {
// No dialog mocks should be left after each test, and so calling the dialog methods should throw
expect(() => prompts({ type: "select", name: "unknown" })).toThrow(
Expand Down
Loading
Loading