-
-
Notifications
You must be signed in to change notification settings - Fork 40
feat: Builder API for Sections and Entities #253
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: main
Are you sure you want to change the base?
Conversation
allows optional arg default without schema default
|
This is pretty cool! One major piece of feedback: IMO for the field/value pairs, those should just be options to a function, i.e Field.new(:type) |> Field.type(Type.one_of([:string, :integer, :boolean])) |> Field.required(),
# should just be:
Field.new(:type, type: .., required?: ...)I'm also not sure about enumerating all of the types as functions like that, i.e I don't think I see a test for using this in an actual DSL (the tests test the built data) but it might be good to have those and maybe an example guide on how to use this to define an extension. |
bf20497 to
9cd5d0b
Compare
9cd5d0b to
06798b4
Compare
|
Cool!
I also stumbled over Finally, I suspect the failing |
Contributor checklist
Leave anything that you believe does not apply unchecked.
Partially addresses #51 by providing a builder API for
SectionsandEntities.This was an experiment to understand Spark better, I thought the builder API might be interesting to dive into how the DSL works and things got a bit out of hand .
More of a discussion PR. Happy to know if it seems valuable and if yes, if the API matches expectations and what would be the required feature set to suffice for incorporation. Otherwise, it can also just be closed.
Caution
Disclaimer: I used AI to discuss the codebase and some parts were contributed by it (vetted by me, but I'm not an Elixir pro and not confident I understood all intricacies)
Also of note:
This builder here validates a bit 'earlier' than the DSL instead of waiting for
Spark.Dsl.Entity.build/5::name:targetsingleton_entity_keysas I don't fully understand yet how sth. likepatchableor overall howExtensionsshould work in a builder.It could also just not validate them akin to the DSL itself, but in a builder API, it felt better to fail earlier?
Example usage
Entities can be passed as builder structs (auto-built), explicitly built, or as functions: