ianstormtaylor / superstruct

A simple and composable way to validate data in JavaScript (and TypeScript).

Home Page:https://docs.superstructjs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Expose generator validation

ritave opened this issue · comments

I'm creating new struct using define and I'd like to return lazy iterator. That new struct internally uses more Structs such as type, I'd like to be able to lazily return errors from internal structs as well.

I know run exists, but it's not exposed in public interface as well as not being stable-end-user API

@ritave could you perhaps define your struct via new Struct()? I guess it is not exactly public API, but given that it is used all around the superstruct codebase, I have high hopes that it is fairly stable.

I sure can, though I'm having hard time understanding the expected business logic output of entries, validator and refiner.

Also while I can do that, rest of my team will have a really hard time reviewing and understanding that code due to lesser knowledge of superstruct internals.

For now I've settled on using define() and nested assert() on internal structs to prioritize code readability rather than efficiency.

Yeah, that is a good point (and probably a wise approach!).

@ianstormtaylor I wonder if it would make sense to publicly document the Struct class? People might want to use it in advanced use-cases, and it would also definitely be useful for contributors. An explicit explanation of what things like entries do sure beats trying to understand everything from context and just hoping that you're not missing some important use-case. 😅