-
Notifications
You must be signed in to change notification settings - Fork 658
Refactor paramsSchema to function-based pattern with z in context #4858
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
base: next
Are you sure you want to change the base?
Conversation
Co-authored-by: adrians5j <[email protected]>
Co-authored-by: adrians5j <[email protected]>
…iBackendService Co-authored-by: adrians5j <[email protected]>
Co-authored-by: adrians5j <[email protected]>
Co-authored-by: adrians5j <[email protected]>
Co-authored-by: adrians5j <[email protected]>
Co-authored-by: adrians5j <[email protected]>
| multiple: true, | ||
| description: "Define a custom implementation or replace an existing one.", | ||
| paramsSchema: ({ project }) => { | ||
| paramsSchema: ({ project }: ExtensionInstanceModelContext) => { |
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.
maybe you misunderstood me but..
paramsSchema: ({ project }: ExtensionInstanceModelContext) => {
return z.object({
src: zodPathToFile(project),
singleton: z.boolean().optional().default(true)
the above should become
paramsSchema: ({ project, z }) => {
return z.object({
src: zodPathToFile(project),
singleton: z.boolean().optional().default(true)
So, include z in callback. Also, I should not be required to pass any typings here. It should happen automatically, like in packages/cognito/src/admin/routes.ts. Check this example again.
This is the file where its impl resides: packages/app/src/features/router/Route.ts:11
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.
Updated all extensions to use ({ project, z }) pattern. Type annotations are now automatic through TypeScript inference, matching the Route pattern. Changes in commit d4a869b.
Co-authored-by: adrians5j <[email protected]>
adrians5j
left a comment
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.
| import { defineExtension } from "~/defineExtension/index.js"; | ||
| import { zodPathToAbstraction } from "~/defineExtension/zodTypes/zodPathToAbstraction.js"; | ||
| import { ApiAfterDeploy as ApiAfterDeployAbstraction } from "~/abstractions/index.js"; | ||
| import { z } from "zod"; |
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.
Why leave this import here? Please remove.
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.
Removed the unused z import from ApiAfterDeploy.ts and all other hook/pulumi files that use ({ z }) or ({ project, z }) pattern. Changes in commit b7a5b33.
| description: "Add custom logic to be executed before the ADMIN deployment process.", | ||
| multiple: true, | ||
| paramsSchema: ({ project }) => { | ||
| paramsSchema: ({ project, z }) => { |
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.
I love what you did here, so now do the same in packages/project-aws please.
P.S. Ofc, you did not remove the import of zod at the top of the file. Make sure to not forget removing this.
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.
Applied the same refactoring to packages/project-aws. Updated 7 extension files to use the new ({ z }) => ({...}) pattern and removed all z imports. Changes in commit b7a5b33.
…-aws Co-authored-by: adrians5j <[email protected]>
Co-authored-by: adrians5j <[email protected]>
…ms-schema-definition
|
/e2e |
|
/cypress |
|
Cypress E2E tests have been initiated (for more information, click here). ✨ |
|
/vitest |
|
Vitest tests have been initiated (for more information, click here). ✨ |
…ms-schema-definition
|
/e2e |
|
/vitest |
|
Cypress E2E tests have been initiated (for more information, click here). ✨ |
|
Vitest tests have been initiated (for more information, click here). ✨ |
|
/vitest |
|
Vitest tests have been initiated (for more information, click here). ✨ |
|
/vitest |
|
Vitest tests have been initiated (for more information, click here). ✨ |
Refactor paramsSchema to Use Function-Based Approach with z in Context
zalongside context propertiesparamsSchemasignature to({ z, ...context }) => ...({ z }) => ({...})({ project, z }) => ({...})returning plain objectsExtensionInstanceModelContextimports from extension filesimport { z } from "zod";from packages/project files({ project, z }) => z.object({...})to({ project, z }) => ({...})zfrom destructuring in files that only useprojectPattern Examples
Simple (only z needed):
With project context (no z usage):
With project context (using z):
Key points:
{...}, NOTz.object({...})z.object()wrapping happens automatically inExtensionInstanceModel.validateParams()Files Updated (24 files)
packages/project:
zfrom 20 hook files that only useprojectzfrom 3 pulumi files (AdminPulumi, ApiPulumi, CorePulumi)zfrom ProjectDecorator.tszin ProjectImplementation.ts and defineApiExtension.ts (they use it)Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.