Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 9, 2026

Refactor paramsSchema to Use Function-Based Approach with z in Context

  • Updated type system to pass z alongside context properties
  • Changed paramsSchema signature to ({ z, ...context }) => ...
  • Removed need for explicit type annotations - TypeScript infers automatically
  • Updated all simple extensions to use ({ z }) => ({...})
  • Updated all complex extensions to use ({ project, z }) => ({...}) returning plain objects
  • Removed ExtensionInstanceModelContext imports from extension files
  • Removed all unused import { z } from "zod"; from packages/project files
  • Applied same refactoring to packages/project-aws (7 extension files)
  • Fixed: Changed all ({ project, z }) => z.object({...}) to ({ project, z }) => ({...})
  • Cleaned up: Removed unused z from destructuring in files that only use project
  • Build successful - no TypeScript errors

Pattern Examples

Simple (only z needed):

paramsSchema: ({ z }) => ({
    setupName: z.enum(["ddb", "ddb+es", "ddb+os"]).describe(...)
})

With project context (no z usage):

paramsSchema: ({ project }) => ({
    src: zodPathToAbstraction(SomeAbstraction, project)
})

With project context (using z):

paramsSchema: ({ project, z }) => ({
    src: zodPathToFile(project),
    singleton: z.boolean().optional().default(true)
})

Key points:

  • Only destructure the parameters you actually use
  • Always return a plain object {...}, NOT z.object({...})
  • The z.object() wrapping happens automatically in ExtensionInstanceModel.validateParams()

Files Updated (24 files)

packages/project:

  • Removed unused z from 20 hook files that only use project
  • Removed unused z from 3 pulumi files (AdminPulumi, ApiPulumi, CorePulumi)
  • Removed unused z from ProjectDecorator.ts
  • Kept z in ProjectImplementation.ts and defineApiExtension.ts (they use it)
Original prompt

let's adjust the paramsSchema.. instead of

paramsSchema: z.object({
setupName: z
.enum(["ddb", "ddb+es", "ddb+os"])
.describe(
"The database setup type: ddb (DynamoDB only), ddb+es (DynamoDB + ElasticSearch), or ddb+os (DynamoDB + OpenSearch)"
)
})

let's have the same appraoch as in

packages/cognito/src/admin/routes.ts:9

So basically

paramsSchema: z => {
return {
setupName: z.enum(["ddb", "ddb+es", "ddb+os"]).describe(
"The database setup type: ddb (DynamoDB only), ddb+es (DynamoDB + ElasticSearch), or ddb+os (DynamoDB + OpenSearch)"
)
})

this needs to be done for ALL defineExtension calls but for starters, let's do just packages/project. So we see first how it went there.

The user has attached the following files from their workspace:

  • packages/project/src/extensions/DatabaseSetup.ts

TITLE: Refactoring paramsSchema Definition in packages/project to Use Function-Based Approach

USER INTENT:
The user wants to refactor the paramsSchema definition in the packages/project codebase to use a function-based approach (accepting z as an argument), similar to the pattern used in packages/cognito/src/admin/routes.ts. This change should be applied to all defineExtension calls, but the user wants to start with packages/project to validate the approach.

TASK DESCRIPTION:

  • Update the paramsSchema definition in packages/project so that it is a function accepting z as an argument, returning the schema object.
  • The new approach should mirror the implementation found in packages/cognito/src/admin/routes.ts:9.
  • The schema should still validate setupName as one of "ddb", "ddb+es", or "ddb+os", with the same descriptive text.
  • This is a preliminary step before applying the change to all defineExtension calls.

EXISTING:

  • The current paramsSchema in packages/project is defined as:
    paramsSchema: z.object({
        setupName: z
            .enum(["ddb", "ddb+es", "ddb+os"])
            .describe(
                "The database setup type: ddb (DynamoDB only), ddb+es (DynamoDB + ElasticSearch), or ddb+os (DynamoDB + OpenSearch)"
            )
    })
  • The desired pattern is already implemented in packages/cognito/src/admin/routes.ts at line 9.

PENDING:

  • Refactor the paramsSchema in packages/project to use the function-based approach:
    paramsSchema: z => ({
        setupName: z.enum(["ddb", "ddb+es", "ddb+os"]).describe(
            "The database setup type: ddb (DynamoDB only), ddb+es (DynamoDB + ElasticSearch), or ddb+os (DynamoDB + OpenSearch)"
        )
    })
  • Test and validate the change in packages/project before rolling out to other defineExtension calls.

CODE STATE:

  • packages/project (file(s) containing defineExtension calls with paramsSchema)
  • packages/cognito/src/admin/routes.ts (reference implementation at line 9)

RELEVANT CODE/DOCUMENTATION SNIPPETS:

  • Reference implementation from packages/cognito/src/admin/routes.ts:
    paramsSchema: z => ({
        // ...schema fields
    })
  • Target schema for setupName:
    setupName: z.enum(["ddb", "ddb+es", "ddb+os"]).describe(
        "The database setup type: ddb (DynamoDB only), ddb+es (DynamoDB + ElasticSearch), or ddb+os (DynamoDB + OpenSearch)"
    )

OTHER NOTES:

  • The user wants to see how the change works in packages/project before applying it more broadly.
  • The main motivation is to standardize the schema definition pattern across the codebase.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Refactor paramsSchema definition in packages/project to use function-based approach Refactor paramsSchema to function-based pattern in packages/project Jan 9, 2026
Copilot AI requested a review from adrians5j January 9, 2026 13:29
multiple: true,
description: "Define a custom implementation or replace an existing one.",
paramsSchema: ({ project }) => {
paramsSchema: ({ project }: ExtensionInstanceModelContext) => {
Copy link
Member

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

@copilot

Copy link
Contributor Author

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.

Copilot AI changed the title Refactor paramsSchema to function-based pattern in packages/project Refactor paramsSchema to function-based pattern with z in context Jan 9, 2026
Copilot AI requested a review from adrians5j January 9, 2026 14:43
Copy link
Member

@adrians5j adrians5j left a 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";
Copy link
Member

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.

Copy link
Contributor Author

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 }) => {
Copy link
Member

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.

Copy link
Contributor Author

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.

Copilot AI requested a review from adrians5j January 9, 2026 17:04
@adrians5j adrians5j changed the base branch from copilot/port-local-state-files-option to next January 12, 2026 13:31
@Pavel910 Pavel910 added this to the 6.0.0 milestone Jan 12, 2026
@adrians5j adrians5j marked this pull request as ready for review January 13, 2026 05:26
@adrians5j
Copy link
Member

/e2e

@adrians5j
Copy link
Member

/cypress

@github-actions
Copy link

Cypress E2E tests have been initiated (for more information, click here). ✨

@adrians5j
Copy link
Member

/vitest

@github-actions
Copy link

Vitest tests have been initiated (for more information, click here). ✨

@adrians5j
Copy link
Member

/e2e

@adrians5j
Copy link
Member

/vitest

@github-actions
Copy link

Cypress E2E tests have been initiated (for more information, click here). ✨

@github-actions
Copy link

Vitest tests have been initiated (for more information, click here). ✨

@adrians5j
Copy link
Member

/vitest

@github-actions
Copy link

Vitest tests have been initiated (for more information, click here). ✨

@adrians5j
Copy link
Member

/vitest

@github-actions
Copy link

Vitest tests have been initiated (for more information, click here). ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants