-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Experiment with Zod #47
Draft
scotttrinh
wants to merge
3
commits into
avi12:main
Choose a base branch
from
scotttrinh:experiment/zod
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,47 @@ | ||
import { z } from "zod"; | ||
import { deployToEdgePublishApi } from "./edge-deploy.js"; | ||
import { getCorrectZip, getFullPath, getIsFileExists } from "../../utils.js"; | ||
|
||
const messageObtain = "To obtain one, follow https://github.com/avi12/web-ext-deploy/blob/main/EDGE_PUBLISH_API.md"; | ||
|
||
const EdgeOptionsPublishApiSchema = z.object({ | ||
clientId: z.string({ | ||
required_error: getErrorMessage(`No client ID is provided. ${messageObtain}`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I left these messages as is, but Zod provides the |
||
}), | ||
clientSecret: z.string({ | ||
required_error: getErrorMessage(`No client secret is provided. ${messageObtain}`) | ||
}), | ||
accessTokenUrl: z.string({ | ||
required_error: getErrorMessage(`No access token URL is provided. ${messageObtain}`) | ||
}), | ||
accessToken: z.string({ | ||
required_error: getErrorMessage(`No access token is provided. ${messageObtain}`) | ||
}), | ||
productId: z.string({ | ||
required_error: getErrorMessage( | ||
"No product ID is provided, e.g. https://partner.microsoft.com/en-us/dashboard/microsoftedge/PRODUCT_ID" | ||
) | ||
}), | ||
zip: z | ||
.string({ | ||
required_error: getErrorMessage("No zip is provided") | ||
}) | ||
.transform(getCorrectZip) | ||
.superRefine((val, ctx) => { | ||
if (!getIsFileExists(val)) { | ||
ctx.addIssue({ | ||
message: getErrorMessage(`Zip doesn't exist: ${getFullPath(val)}`), | ||
code: z.ZodIssueCode.custom | ||
}); | ||
} | ||
}), | ||
devChangelog: z | ||
.string() | ||
.transform(cl => cl.replace(/\/\n/g, "\n")) | ||
.optional(), | ||
verbose: z.boolean().optional() | ||
}); | ||
|
||
export class EdgeOptionsPublishApi { | ||
/** | ||
* The client ID.<br> | ||
|
@@ -46,40 +87,7 @@ export class EdgeOptionsPublishApi { | |
verbose?: boolean; | ||
|
||
constructor(options: EdgeOptionsPublishApi) { | ||
if (!options.productId) { | ||
throw new Error( | ||
getErrorMessage( | ||
"No product ID is provided, e.g. https://partner.microsoft.com/en-us/dashboard/microsoftedge/PRODUCT_ID" | ||
) | ||
); | ||
} | ||
|
||
const messageObtain = "To obtain one, follow https://github.com/avi12/web-ext-deploy/blob/main/EDGE_PUBLISH_API.md"; | ||
|
||
if (!options.clientId) { | ||
throw new Error(getErrorMessage(`No client ID is provided. ${messageObtain}`)); | ||
} | ||
|
||
if (!options.clientSecret) { | ||
throw new Error(getErrorMessage(`No client secret is provided. ${messageObtain}`)); | ||
} | ||
|
||
if (!options.accessTokenUrl) { | ||
throw new Error(getErrorMessage(`No access token URL is provided. ${messageObtain}`)); | ||
} | ||
|
||
if (!options.accessToken) { | ||
throw new Error(getErrorMessage(`No access token is provided. ${messageObtain}`)); | ||
} | ||
|
||
// Zip checking | ||
if (!options.zip) { | ||
throw new Error(getErrorMessage("No zip is provided")); | ||
} | ||
|
||
if (!getIsFileExists(options.zip)) { | ||
throw new Error(getErrorMessage(`Zip doesn't exist: ${getFullPath(options.zip)}`)); | ||
} | ||
Object.assign(this, EdgeOptionsPublishApiSchema.parse(options)); | ||
} | ||
} | ||
|
||
|
@@ -88,13 +96,5 @@ function getErrorMessage(message: string): string { | |
} | ||
|
||
export async function prepareToDeployEdgePublishApi(options: EdgeOptionsPublishApi): Promise<boolean> { | ||
options.zip = getCorrectZip(options.zip); | ||
|
||
if (options.devChangelog) { | ||
options.devChangelog = options.devChangelog.replace(/\/\n/g, "\n"); | ||
} | ||
|
||
// Validate the options | ||
new EdgeOptionsPublishApi(options); | ||
return deployToEdgePublishApi(options); | ||
return deployToEdgePublishApi(new EdgeOptionsPublishApi(options)); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This was causing prettier to rewrite the file I was working on to replace the existing
\n
with\n\r
. Apologies for the tooling churn here, feel free to tell me to revert! Otherwise, I can contribute a small whitespace PR that normalizes oncrlf
.