Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for new bindings to wrangler types #5089

Merged
merged 8 commits into from
Mar 6, 2024

Conversation

DaniFoldi
Copy link
Contributor

@DaniFoldi DaniFoldi commented Feb 25, 2024

Fixes # [insert GH or internal issue number(s)].

What this PR solves / how to test:

This PR adds support for Email Send, Vectorize, Hyperdrive, mTLS, Browser Rendering and Workers AI bindings to wrangler types.

Author has addressed the following:

  • Tests
    • Included
    • Not necessary because:
  • Changeset (Changeset guidelines)
    • Included
    • Not necessary because:
  • Associated docs
    • Issue(s)/PR(s):
    • Not necessary because: adds support for bindings that should have already been supported i.e. addresses bug fix

Note for PR author:

We want to celebrate and highlight awesome PR review! If you think this PR received a particularly high-caliber review, please assign it the label highlight pr review so future reviewers can take inspiration and learn from it.

@DaniFoldi DaniFoldi requested a review from a team as a code owner February 25, 2024 12:36
Copy link

changeset-bot bot commented Feb 25, 2024

🦋 Changeset detected

Latest commit: eed80d3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
wrangler Patch
@cloudflare/vitest-pool-workers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@dario-piotrowicz dario-piotrowicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 😃 🚀 ❤️

if (configToDTS.ai) {
// The @cloudflare/ai package types specify any, but from its usage
// we can infer it's a Fetcher type (await this.binding.fetch)
envTypeStructure.push(`${configToDTS.ai.binding}: Fetcher;`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be tempted to keep it as any if it is in @cloudflare/ai 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should probably be any/unknown since I'm not sure it's guaranteed to always be a Fetcher

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to avoid generating any into user projects - lots of people use the recommended preset from typescript-eslint which includes no-explicit-any. unknown is somewhat better, I haven't thought of that myself. Let me push a fix

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I would also go with unknown, I didn't suggest it as I don't know if @cloudflare/ai could complain about that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fortunately anything can be passed to any, including unknown: ts playground

Changed to unknown in b69e965

Copy link
Contributor

github-actions bot commented Feb 26, 2024

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8158618486/npm-package-wrangler-5089

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/5089/npm-package-wrangler-5089

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8158618486/npm-package-wrangler-5089 dev path/to/script.js
Additional artifacts:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8158618486/npm-package-create-cloudflare-5089 --no-auto-update
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8158618486/npm-package-cloudflare-kv-asset-handler-5089
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8158618486/npm-package-miniflare-5089
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8158618486/npm-package-cloudflare-pages-shared-5089
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8158618486/npm-package-cloudflare-vitest-pool-workers-5089

Note that these links will no longer work once the GitHub Actions artifact expires.


wrangler@3.30.1 includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20240223.0
workerd 1.20240223.1 1.20240223.1
workerd --version 1.20240223.1 2024-02-23

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

Copy link

codecov bot commented Feb 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.39%. Comparing base (04b37fc) to head (eed80d3).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5089      +/-   ##
==========================================
+ Coverage   70.31%   70.39%   +0.07%     
==========================================
  Files         298      298              
  Lines       15551    15567      +16     
  Branches     4001     4007       +6     
==========================================
+ Hits        10935    10958      +23     
+ Misses       4616     4609       -7     
Files Coverage Δ
packages/wrangler/src/type-generation.ts 99.29% <100.00%> (+0.08%) ⬆️

... and 6 files with indirect coverage changes

Comment on lines +98 to +103
send_email: config.send_email,
vectorize: config.vectorize,
hyperdrive: config.hyperdrive,
mtls_certificates: config.mtls_certificates,
browser: config.browser,
ai: config.ai,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change the type of this object to make sure we catch issues like this in the future? It should be something like Omit<EnvironmentNonInheritable, "define" | "unsafe" | "tail_consumers" | "constellation" | "cloudchamber">

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 2e14c86

if (configToDTS.ai) {
// The @cloudflare/ai package types specify any, but from its usage
// we can infer it's a Fetcher type (await this.binding.fetch)
envTypeStructure.push(`${configToDTS.ai.binding}: Fetcher;`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should probably be any/unknown since I'm not sure it's guaranteed to always be a Fetcher

@mrbbot
Copy link
Contributor

mrbbot commented Mar 4, 2024

@DaniFoldi looks like this is failing type checking? Would you be able to fix these failures?

@DaniFoldi
Copy link
Contributor Author

Of course, I'll remove unsafe from the omit since the test actually has unsafe bindings defined.
How should I go about fixing the dispatch_namespaces error? It's defined on EnvironmentInheritable, so I can either move it to non-inheritable (which shouldn't be breaking as only their union is exported, and if anything this is a fix, or I can manually patch the type to also include dispatch namespaces from the inheritable config (smaller diff, but worse solution imo).

@lrapoport-cf lrapoport-cf added the awaiting Cloudflare response Awaiting response from workers-sdk maintainer team label Mar 4, 2024
@DaniFoldi DaniFoldi force-pushed the wrangler-types-new-bindings branch from ef301a6 to eed80d3 Compare March 5, 2024 15:14
@DaniFoldi
Copy link
Contributor Author

Rebased on main, test failures seemed unrelated. Could you please take another look, @mrbbot?

@mrbbot mrbbot merged commit 5b85dc9 into cloudflare:main Mar 6, 2024
17 checks passed
@workers-devprod workers-devprod mentioned this pull request Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting Cloudflare response Awaiting response from workers-sdk maintainer team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants