-
Notifications
You must be signed in to change notification settings - Fork 770
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
polish: validate payload for kv:bulk put
on client side
#1024
Conversation
🦋 Changeset detectedLatest commit: 575cf21 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
A wrangler prerelease is available for testing. You can install this latest build in your project with: npm install --save-dev https://prerelease-registry.developers.workers.dev/runs/2333441982/npm-package-wrangler-1024 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.developers.workers.dev/prs/1024/npm-package-wrangler-1024 Or you can use npx https://prerelease-registry.developers.workers.dev/runs/2333441982/npm-package-wrangler-1024 dev path/to/script.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A small slip with the metadata
validation. If we are going to add validation for these optional properties, then we should also add tests.
packages/wrangler/src/kv.ts
Outdated
typeof keyValue.expiration_ttl === "number" | ||
) || | ||
!(keyValue.base64 === undefined || typeof keyValue.base64 === "boolean") || | ||
!(keyValue.metadata === undefined || typeof keyValue.base64 === "object") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!(keyValue.metadata === undefined || typeof keyValue.base64 === "object") | |
!(keyValue.metadata === undefined || typeof keyValue.metadata === "object") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed these! Adding now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
ba764a9
to
186a7a7
Compare
@@ -2334,13 +2334,7 @@ export async function main(argv: string[]): Promise<void> { | |||
const warnings: string[] = []; | |||
for (let i = 0; i < content.length; i++) { | |||
const keyValue = content[i]; | |||
if (typeof keyValue !== "object") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to add this check into the validation helper function! 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concise straightforward improvement and I rather like the validation helper refactor.
This adds client side validation for the paylod for `kv:bulk put`, importantly ensuring we're uploading only string key/value pairs (as well as validation for the other fields). Fixes #571
186a7a7
to
575cf21
Compare
Thanks for the review! Rebasing on top of the windows ci fix also passed checks. I'll wait for @petebacondarwin to stamp this and land it. |
This adds client side validation for the paylod for
kv:bulk put
, importantly ensuring we're uploading only string key/value pairs (as well as validation for the other fields).Fixes #571