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 function schema #243

Open
Jimdooz opened this issue Nov 4, 2023 · 4 comments
Open

Add support for function schema #243

Jimdooz opened this issue Nov 4, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request priority This has priority

Comments

@Jimdooz
Copy link

Jimdooz commented Nov 4, 2023

Hi,

I've been exploring the current features and noticed that function schema validation, similar to what's available in Zod, isn't part of the project. I think incorporating this could enhance the functionality for users who rely on strict typing for functions.

I was thinking about something like this

const MyFunctionSchema = v.function()
  .args(
    v.string()
  )
  .returns(
    v.boolean()
  )

type FunctionSchema = Output<typeof MyFunctionSchema >;
@fabian-hiller
Copy link
Owner

Thank your for creating this issue. In Valibot we don't chain methods. Instead it will probably look something like this:

const MyFunctionSchema = v.function([v.string()], v.boolean());

What is your use case for a function schema? I haven't figured that out yet. That's why it's not part of the library. But I am happy to add it.

@fabian-hiller fabian-hiller self-assigned this Nov 5, 2023
@fabian-hiller fabian-hiller added enhancement New feature or request priority This has priority labels Nov 5, 2023
@Jimdooz
Copy link
Author

Jimdooz commented Nov 5, 2023

Thank you for your reply!

Yes, you're right, this declaration format will be more in line with current syntax.

My use case involves a list of validators where each has a name and a corresponding validation function. I'm aiming to automate the process of checking argument schemas against these validators. Having function schema validation would streamline this process, ensuring that each function receives the correct type and structure of data before processing.

@fabian-hiller
Copy link
Owner

Thank you for your reply. Can you imagine creating a PR with a function_ schema function? The code does not have to be perfect. Valibot is implemented very simply. You can copy the basic structure from another schema.

@Jimdooz
Copy link
Author

Jimdooz commented Nov 6, 2023

Yes I can try :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority This has priority
Projects
None yet
Development

No branches or pull requests

2 participants