Skip to content

Commit

Permalink
wrangler: some additions (#4013)
Browse files Browse the repository at this point in the history
* 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 <smacleod@cloudflare.com>

* 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 <smacleod@cloudflare.com>
Co-authored-by: Jacob M-G Evans <27247160+JacobMGEvans@users.noreply.github.com>
Co-authored-by: Jacob M-G Evans <jacobmgevans@gmail.com>
  • Loading branch information
4 people authored Sep 26, 2023
1 parent 7161785 commit 3cd7286
Show file tree
Hide file tree
Showing 27 changed files with 1,103 additions and 42 deletions.
8 changes: 8 additions & 0 deletions .changeset/good-ads-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"wrangler": minor
---

Adds wrangler support for Vectorize, Cloudflare's new vector database, with
`wrangler vectorize`. Visit the developer documentation
(https://developers.cloudflare.com/vectorize/) to learn more and create your
first vector database with `wrangler vectorize create my-first-index`.
10 changes: 5 additions & 5 deletions packages/wrangler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@
"xxhash-wasm": "^1.0.1"
},
"devDependencies": {
"@cloudflare/pages-shared": "workspace:^",
"@cloudflare/eslint-config-worker": "*",
"@cloudflare/pages-shared": "workspace:^",
"@cloudflare/types": "^6.18.4",
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20230724.0",
"@cloudflare/workers-types": "^4.20230914.0",
"@iarna/toml": "^3.0.0",
"@microsoft/api-extractor": "^7.28.3",
"@types/body-parser": "^1.19.2",
Expand All @@ -130,6 +130,7 @@
"@types/glob-to-regexp": "0.4.1",
"@types/is-ci": "^3.0.0",
"@types/javascript-time-ago": "^2.0.3",
"@types/jest": "^29.5.5",
"@types/mime": "^2.0.3",
"@types/minimatch": "^5.1.2",
"@types/prompts": "^2.0.14",
Expand All @@ -141,9 +142,6 @@
"@types/ws": "^8.5.3",
"@types/yargs": "^17.0.10",
"@webcontainer/env": "^1.1.0",
"@types/jest": "^29.5.5",
"esbuild-jest": "0.5.0",
"jest": "^29.7.0",
"body-parser": "^1.20.0",
"chalk": "^2.4.2",
"cli-table3": "^0.6.3",
Expand All @@ -153,6 +151,7 @@
"concurrently": "^7.2.2",
"devtools-protocol": "^0.0.955664",
"dotenv": "^16.0.0",
"esbuild-jest": "0.5.0",
"execa": "^6.1.0",
"express": "^4.18.1",
"finalhandler": "^1.2.0",
Expand All @@ -169,6 +168,7 @@
"ink-text-input": "^4.0.3",
"is-ci": "^3.0.1",
"javascript-time-ago": "^2.5.4",
"jest": "^29.7.0",
"jest-fetch-mock": "^3.0.3",
"jest-websocket-mock": "^2.5.0",
"mime": "^3.0.0",
Expand Down
90 changes: 90 additions & 0 deletions packages/wrangler/src/__tests__/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe("normalizeAndValidateConfig()", () => {
compatibility_flags: [],
configPath: undefined,
d1_databases: [],
vectorize: [],
constellation: [],
dev: {
ip: "0.0.0.0",
Expand Down Expand Up @@ -1621,6 +1622,95 @@ describe("normalizeAndValidateConfig()", () => {
});
});

// Vectorize
describe("[vectorize]", () => {
it("should error if vectorize is an object", () => {
const { diagnostics } = normalizeAndValidateConfig(
{ vectorize: {} } as unknown as RawConfig,
undefined,
{ env: undefined }
);

expect(diagnostics.hasWarnings()).toBe(false);
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
"Processing wrangler configuration:
- The field \\"vectorize\\" should be an array but got {}."
`);
});

it("should error if vectorize bindings are not valid", () => {
const { diagnostics } = normalizeAndValidateConfig(
{
vectorize: [
{},
{ binding: "VALID" },
{ binding: 2000, index_name: 2111 },
{
binding: "BINDING_2",
index_name: "ID_2",
},
{ binding: "VALID", index_name: "" },
],
} as unknown as RawConfig,
undefined,
{ env: undefined }
);

expect(diagnostics.hasWarnings()).toBe(false);
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}."
`);
});

it("should error if vectorize is a string", () => {
const { diagnostics } = normalizeAndValidateConfig(
{ vectorize: "BAD" } as unknown as RawConfig,
undefined,
{ env: undefined }
);

expect(diagnostics.hasWarnings()).toBe(false);
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
"Processing wrangler configuration:
- The field \\"vectorize\\" should be an array but got \\"BAD\\"."
`);
});

it("should error if vectorize is a number", () => {
const { diagnostics } = normalizeAndValidateConfig(
{ vectorize: 999 } as unknown as RawConfig,
undefined,
{ env: undefined }
);

expect(diagnostics.hasWarnings()).toBe(false);
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
"Processing wrangler configuration:
- The field \\"vectorize\\" should be an array but got 999."
`);
});

it("should error if vectorize is null", () => {
const { diagnostics } = normalizeAndValidateConfig(
{ vectorize: null } as unknown as RawConfig,
undefined,
{ env: undefined }
);

expect(diagnostics.hasWarnings()).toBe(false);
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
"Processing wrangler configuration:
- The field \\"vectorize\\" should be an array but got null."
`);
});
});

// AI
describe("[ai]", () => {
it("should error if ai is an array", () => {
const { diagnostics } = normalizeAndValidateConfig(
Expand Down
2 changes: 2 additions & 0 deletions packages/wrangler/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe("wrangler", () => {
wrangler d1 🗄 Interact with a D1 database
wrangler ai 🤖 Interact with AI models
wrangler constellation 🤖 Interact with Constellation models
wrangler vectorize 🧮 Interact with Vectorize indexes
wrangler pubsub 📮 Interact and manage Pub/Sub Brokers
wrangler mtls-certificate 🪪 Manage certificates used for mTLS connections
wrangler login 🔓 Login to Cloudflare
Expand Down Expand Up @@ -104,6 +105,7 @@ describe("wrangler", () => {
wrangler d1 🗄 Interact with a D1 database
wrangler ai 🤖 Interact with AI models
wrangler constellation 🤖 Interact with Constellation models
wrangler vectorize 🧮 Interact with Vectorize indexes
wrangler pubsub 📮 Interact and manage Pub/Sub Brokers
wrangler mtls-certificate 🪪 Manage certificates used for mTLS connections
wrangler login 🔓 Login to Cloudflare
Expand Down
36 changes: 7 additions & 29 deletions packages/wrangler/src/__tests__/mtls-certificates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,39 +356,17 @@ describe("wrangler", () => {
describe("commands", () => {
describe("help", () => {
it("should show the correct help text", async () => {
await runWrangler("mtls-certifiate --help");
await runWrangler("mtls-certificate --help");
expect(std.err).toMatchInlineSnapshot(`""`);
expect(std.out).toMatchInlineSnapshot(`
"wrangler
"wrangler mtls-certificate
🪪 Manage certificates used for mTLS connections
Commands:
wrangler docs [command..] 📚 Open wrangler's docs in your browser
wrangler init [name] 📥 Initialize a basic Worker project, including a wrangler.toml file
wrangler generate [name] [template] ✨ Generate a new Worker project from an existing Worker template. See https://github.com/cloudflare/templates
wrangler dev [script] 👂 Start a local server for developing your worker
wrangler deploy [script] 🆙 Deploy your Worker to Cloudflare. [aliases: publish]
wrangler delete [script] 🗑 Delete your Worker from Cloudflare.
wrangler tail [worker] 🦚 Starts a log tailing session for a published Worker.
wrangler secret 🤫 Generate a secret that can be referenced in a Worker
wrangler secret:bulk [json] 🗄️ Bulk upload secrets for a Worker
wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
wrangler pages ⚡️ Configure Cloudflare Pages
wrangler queues 🇶 Configure Workers Queues
wrangler r2 📦 Interact with an R2 store
wrangler dispatch-namespace 📦 Interact with a dispatch namespace
wrangler d1 🗄 Interact with a D1 database
wrangler ai 🤖 Interact with AI models
wrangler constellation 🤖 Interact with Constellation models
wrangler pubsub 📮 Interact and manage Pub/Sub Brokers
wrangler mtls-certificate 🪪 Manage certificates used for mTLS connections
wrangler login 🔓 Login to Cloudflare
wrangler logout 🚪 Logout from Cloudflare
wrangler whoami 🕵️ Retrieve your user info and test your auth config
wrangler types 📝 Generate types from bindings & module rules in config
wrangler deployments 🚢 List and view details for deployments
wrangler rollback [deployment-id] 🔙 Rollback a deployment
wrangler mtls-certificate upload Upload an mTLS certificate
wrangler mtls-certificate list List uploaded mTLS certificates
wrangler mtls-certificate delete Delete an mTLS certificate
Flags:
-j, --experimental-json-config Experimental: Support wrangler.json [boolean]
Expand Down
Loading

0 comments on commit 3cd7286

Please sign in to comment.