Skip to content

Commit 3cd7286

Browse files
elithrarpenalosaJacobMGEvans
authored
wrangler: some additions (#4013)
* vectorize: add wrangler vectorize * vectorize: add changeset * vectorize: remove bad mTLS test, add snapshot to index * vectorize: update @cloudflare/workers-types to tip * vectorize: update lockfile * Apply suggestions from code review Co-authored-by: Somhairle MacLeòid <[email protected]> * vectorize: fix test output * vectorize: skip-confirmation -> force * vectorize: fix ai command rebase issue? * vectorize: fix release notes * vectorize: indexes -> indices * vectorize: improve wrangler HTTP 204+205 handling * vectorize: test output spacing... * vectorize: fix unused import * vectorize: add binding support for [[vectorize]] * vectorize: update tests * vectorize: add lockfile * Upgrade XDG package (#4005) 2 major version upgrade changelogs: https://github.com/rivy/js.xdg-app-paths/blob/master/CHANGELOG.mkd * vectorize: fix missing binding config * vectorize: npm run bundle * vectorize: npm run bundle * vectorize: fix binding output * vectorize: use indexes > indices * vectorize: fix formatting * vectorize: address comments * vectorize: add mocks * running formatter * vectorize: comment HTTP 204/205 * vectorize: add validation tests * Fix tests & lockfile * Reduce lockfile diff --------- Co-authored-by: Somhairle MacLeòid <[email protected]> Co-authored-by: Jacob M-G Evans <[email protected]> Co-authored-by: Jacob M-G Evans <[email protected]>
1 parent 7161785 commit 3cd7286

27 files changed

+1103
-42
lines changed

.changeset/good-ads-fold.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
Adds wrangler support for Vectorize, Cloudflare's new vector database, with
6+
`wrangler vectorize`. Visit the developer documentation
7+
(https://developers.cloudflare.com/vectorize/) to learn more and create your
8+
first vector database with `wrangler vectorize create my-first-index`.

packages/wrangler/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@
116116
"xxhash-wasm": "^1.0.1"
117117
},
118118
"devDependencies": {
119-
"@cloudflare/pages-shared": "workspace:^",
120119
"@cloudflare/eslint-config-worker": "*",
120+
"@cloudflare/pages-shared": "workspace:^",
121121
"@cloudflare/types": "^6.18.4",
122122
"@cloudflare/workers-tsconfig": "workspace:*",
123-
"@cloudflare/workers-types": "^4.20230724.0",
123+
"@cloudflare/workers-types": "^4.20230914.0",
124124
"@iarna/toml": "^3.0.0",
125125
"@microsoft/api-extractor": "^7.28.3",
126126
"@types/body-parser": "^1.19.2",
@@ -130,6 +130,7 @@
130130
"@types/glob-to-regexp": "0.4.1",
131131
"@types/is-ci": "^3.0.0",
132132
"@types/javascript-time-ago": "^2.0.3",
133+
"@types/jest": "^29.5.5",
133134
"@types/mime": "^2.0.3",
134135
"@types/minimatch": "^5.1.2",
135136
"@types/prompts": "^2.0.14",
@@ -141,9 +142,6 @@
141142
"@types/ws": "^8.5.3",
142143
"@types/yargs": "^17.0.10",
143144
"@webcontainer/env": "^1.1.0",
144-
"@types/jest": "^29.5.5",
145-
"esbuild-jest": "0.5.0",
146-
"jest": "^29.7.0",
147145
"body-parser": "^1.20.0",
148146
"chalk": "^2.4.2",
149147
"cli-table3": "^0.6.3",
@@ -153,6 +151,7 @@
153151
"concurrently": "^7.2.2",
154152
"devtools-protocol": "^0.0.955664",
155153
"dotenv": "^16.0.0",
154+
"esbuild-jest": "0.5.0",
156155
"execa": "^6.1.0",
157156
"express": "^4.18.1",
158157
"finalhandler": "^1.2.0",
@@ -169,6 +168,7 @@
169168
"ink-text-input": "^4.0.3",
170169
"is-ci": "^3.0.1",
171170
"javascript-time-ago": "^2.5.4",
171+
"jest": "^29.7.0",
172172
"jest-fetch-mock": "^3.0.3",
173173
"jest-websocket-mock": "^2.5.0",
174174
"mime": "^3.0.0",

packages/wrangler/src/__tests__/configuration.test.ts

+90
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe("normalizeAndValidateConfig()", () => {
2626
compatibility_flags: [],
2727
configPath: undefined,
2828
d1_databases: [],
29+
vectorize: [],
2930
constellation: [],
3031
dev: {
3132
ip: "0.0.0.0",
@@ -1621,6 +1622,95 @@ describe("normalizeAndValidateConfig()", () => {
16211622
});
16221623
});
16231624

1625+
// Vectorize
1626+
describe("[vectorize]", () => {
1627+
it("should error if vectorize is an object", () => {
1628+
const { diagnostics } = normalizeAndValidateConfig(
1629+
{ vectorize: {} } as unknown as RawConfig,
1630+
undefined,
1631+
{ env: undefined }
1632+
);
1633+
1634+
expect(diagnostics.hasWarnings()).toBe(false);
1635+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1636+
"Processing wrangler configuration:
1637+
- The field \\"vectorize\\" should be an array but got {}."
1638+
`);
1639+
});
1640+
1641+
it("should error if vectorize bindings are not valid", () => {
1642+
const { diagnostics } = normalizeAndValidateConfig(
1643+
{
1644+
vectorize: [
1645+
{},
1646+
{ binding: "VALID" },
1647+
{ binding: 2000, index_name: 2111 },
1648+
{
1649+
binding: "BINDING_2",
1650+
index_name: "ID_2",
1651+
},
1652+
{ binding: "VALID", index_name: "" },
1653+
],
1654+
} as unknown as RawConfig,
1655+
undefined,
1656+
{ env: undefined }
1657+
);
1658+
1659+
expect(diagnostics.hasWarnings()).toBe(false);
1660+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1661+
"Processing wrangler configuration:
1662+
- \\"vectorize[0]\\" bindings should have a string \\"binding\\" field but got {}.
1663+
- \\"vectorize[0]\\" bindings must have an \\"index_name\\" field but got {}.
1664+
- \\"vectorize[1]\\" bindings must have an \\"index_name\\" field but got {\\"binding\\":\\"VALID\\"}.
1665+
- \\"vectorize[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2000,\\"index_name\\":2111}.
1666+
- \\"vectorize[2]\\" bindings must have an \\"index_name\\" field but got {\\"binding\\":2000,\\"index_name\\":2111}."
1667+
`);
1668+
});
1669+
1670+
it("should error if vectorize is a string", () => {
1671+
const { diagnostics } = normalizeAndValidateConfig(
1672+
{ vectorize: "BAD" } as unknown as RawConfig,
1673+
undefined,
1674+
{ env: undefined }
1675+
);
1676+
1677+
expect(diagnostics.hasWarnings()).toBe(false);
1678+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1679+
"Processing wrangler configuration:
1680+
- The field \\"vectorize\\" should be an array but got \\"BAD\\"."
1681+
`);
1682+
});
1683+
1684+
it("should error if vectorize is a number", () => {
1685+
const { diagnostics } = normalizeAndValidateConfig(
1686+
{ vectorize: 999 } as unknown as RawConfig,
1687+
undefined,
1688+
{ env: undefined }
1689+
);
1690+
1691+
expect(diagnostics.hasWarnings()).toBe(false);
1692+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1693+
"Processing wrangler configuration:
1694+
- The field \\"vectorize\\" should be an array but got 999."
1695+
`);
1696+
});
1697+
1698+
it("should error if vectorize is null", () => {
1699+
const { diagnostics } = normalizeAndValidateConfig(
1700+
{ vectorize: null } as unknown as RawConfig,
1701+
undefined,
1702+
{ env: undefined }
1703+
);
1704+
1705+
expect(diagnostics.hasWarnings()).toBe(false);
1706+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1707+
"Processing wrangler configuration:
1708+
- The field \\"vectorize\\" should be an array but got null."
1709+
`);
1710+
});
1711+
});
1712+
1713+
// AI
16241714
describe("[ai]", () => {
16251715
it("should error if ai is an array", () => {
16261716
const { diagnostics } = normalizeAndValidateConfig(

packages/wrangler/src/__tests__/index.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ describe("wrangler", () => {
5151
wrangler d1 🗄 Interact with a D1 database
5252
wrangler ai 🤖 Interact with AI models
5353
wrangler constellation 🤖 Interact with Constellation models
54+
wrangler vectorize 🧮 Interact with Vectorize indexes
5455
wrangler pubsub 📮 Interact and manage Pub/Sub Brokers
5556
wrangler mtls-certificate 🪪 Manage certificates used for mTLS connections
5657
wrangler login 🔓 Login to Cloudflare
@@ -104,6 +105,7 @@ describe("wrangler", () => {
104105
wrangler d1 🗄 Interact with a D1 database
105106
wrangler ai 🤖 Interact with AI models
106107
wrangler constellation 🤖 Interact with Constellation models
108+
wrangler vectorize 🧮 Interact with Vectorize indexes
107109
wrangler pubsub 📮 Interact and manage Pub/Sub Brokers
108110
wrangler mtls-certificate 🪪 Manage certificates used for mTLS connections
109111
wrangler login 🔓 Login to Cloudflare

packages/wrangler/src/__tests__/mtls-certificates.test.ts

+7-29
Original file line numberDiff line numberDiff line change
@@ -356,39 +356,17 @@ describe("wrangler", () => {
356356
describe("commands", () => {
357357
describe("help", () => {
358358
it("should show the correct help text", async () => {
359-
await runWrangler("mtls-certifiate --help");
359+
await runWrangler("mtls-certificate --help");
360360
expect(std.err).toMatchInlineSnapshot(`""`);
361361
expect(std.out).toMatchInlineSnapshot(`
362-
"wrangler
362+
"wrangler mtls-certificate
363+
364+
🪪 Manage certificates used for mTLS connections
363365
364366
Commands:
365-
wrangler docs [command..] 📚 Open wrangler's docs in your browser
366-
wrangler init [name] 📥 Initialize a basic Worker project, including a wrangler.toml file
367-
wrangler generate [name] [template] ✨ Generate a new Worker project from an existing Worker template. See https://github.com/cloudflare/templates
368-
wrangler dev [script] 👂 Start a local server for developing your worker
369-
wrangler deploy [script] 🆙 Deploy your Worker to Cloudflare. [aliases: publish]
370-
wrangler delete [script] 🗑 Delete your Worker from Cloudflare.
371-
wrangler tail [worker] 🦚 Starts a log tailing session for a published Worker.
372-
wrangler secret 🤫 Generate a secret that can be referenced in a Worker
373-
wrangler secret:bulk [json] 🗄️ Bulk upload secrets for a Worker
374-
wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
375-
wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
376-
wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
377-
wrangler pages ⚡️ Configure Cloudflare Pages
378-
wrangler queues 🇶 Configure Workers Queues
379-
wrangler r2 📦 Interact with an R2 store
380-
wrangler dispatch-namespace 📦 Interact with a dispatch namespace
381-
wrangler d1 🗄 Interact with a D1 database
382-
wrangler ai 🤖 Interact with AI models
383-
wrangler constellation 🤖 Interact with Constellation models
384-
wrangler pubsub 📮 Interact and manage Pub/Sub Brokers
385-
wrangler mtls-certificate 🪪 Manage certificates used for mTLS connections
386-
wrangler login 🔓 Login to Cloudflare
387-
wrangler logout 🚪 Logout from Cloudflare
388-
wrangler whoami 🕵️ Retrieve your user info and test your auth config
389-
wrangler types 📝 Generate types from bindings & module rules in config
390-
wrangler deployments 🚢 List and view details for deployments
391-
wrangler rollback [deployment-id] 🔙 Rollback a deployment
367+
wrangler mtls-certificate upload Upload an mTLS certificate
368+
wrangler mtls-certificate list List uploaded mTLS certificates
369+
wrangler mtls-certificate delete Delete an mTLS certificate
392370
393371
Flags:
394372
-j, --experimental-json-config Experimental: Support wrangler.json [boolean]

0 commit comments

Comments
 (0)