-
Notifications
You must be signed in to change notification settings - Fork 3
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
Fix inngest.send. Add Event Builder #57
base: main
Are you sure you want to change the base?
Fix inngest.send. Add Event Builder #57
Conversation
return this | ||
} | ||
|
||
fun data(data: Any): InngestEventBuilder { |
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.
name
and data
are mandatory so why not have an InngestEvent
with name and data for the constructor, and then chain itself instead?
Example/Reference in Rust
https://github.com/inngest/inngest-rs/blob/main/inngest/src/event.rs#L21-L49
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.
Also since the InngestEvent
is a data class with optional fields, honestly don't really need a builder?
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.
The general idea is that we'd have a couple different ways to do things, what you recommend and a builder pattern. It was recommended to have different options for users like this. The builder pattern might be preferred for users that want to set id
or v
but not have to include null arguments in a constructor.
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.
Following up here:
- Builder pattern is pretty established in Java because IIRC Java does not natively support optional parameters (unless that's changed in a recent version). If we use
@JvmOverloads
on a Kotlin constructor with optional params, it'll generate overloaded methods for us but not all the various permutations a user might want. - So given that we should provide a builder at all, I think Darwin's point about putting the required parameters in the constructor is pretty good. That's what the Book example from this article on builders from the Effective Java book has
However looking at these builder examples from several popular Java libraries, none of them seem to put required parameters in the builder constructor. So I guess it can go either way
// isbn and title are required public Builder(String isbn, String title) { this.isbn = isbn; this.title = title; } // genre is optional public Builder genre(Genre genre) { this.genre = genre; return this; }
- https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/util/UriComponentsBuilder.html#build()
- https://hc.apache.org/httpcomponents-client-5.2.x/current/httpclient5/apidocs/org/apache/hc/client5/http/config/RequestConfig.Builder.html
- https://grpc.github.io/grpc-java/javadoc/io/grpc/ServerBuilder.html
- https://square.github.io/okhttp/3.x/okhttp/okhttp3/Request.Builder.html
- One point for Java interop if we use non nullable constructor arguments in Kotlin. They will get annotated with
org.jetbrains.annotations.NotNull
for Java and immediately throwjava.lang.NullPointerException: Parameter specified as non-null is null
if called with a null argument. Thanks @KiKoS0 for confirming this behavior. - A minor question is whether we want to nest the builder as
InngestEvent.Builder
or keep it asInngestEventBuilder
. As you can see from the examples of other builders I linked, this seems to be up to the preference of the library author.
c8b6a70
to
53d0981
Compare
- moved Array -> List conversion out of scope of this PR, we can do that in a follow up
53d0981
to
5180111
Compare
- make name and data required params of the constructor - all the optional fields have setters - add tests - also modify user on InngestEvent to have a type of map matching data per https://github.com/inngest/inngest/blob/3f0b9cb28d38fa6f37abe82ded4734eea2f7dbc9/docs/SDK_SPEC.md?plain=1#L162
/** | ||
* An internal class used for parsing events sent to Inngest functions | ||
*/ | ||
internal data class Event( |
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.
After propagating InngestEvent
to enough places to get this PR to compile, this Event
is no longer used. I don't know if the intent was to convert external InngestEvent
s to internal Event
s somewhere, but I wasn't sure where so I'm punting on that for this PR
* in the order of which they were included in the request | ||
*/ | ||
data class SendEventsResponse( | ||
val ids: Array<String>, |
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.
The PR originally changed this from Array
to List
which I think is a good change, but to reduce scope for this PR I am punting on it to a follow up
return this | ||
} | ||
|
||
fun data(data: Any): InngestEventBuilder { |
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.
Following up here:
- Builder pattern is pretty established in Java because IIRC Java does not natively support optional parameters (unless that's changed in a recent version). If we use
@JvmOverloads
on a Kotlin constructor with optional params, it'll generate overloaded methods for us but not all the various permutations a user might want. - So given that we should provide a builder at all, I think Darwin's point about putting the required parameters in the constructor is pretty good. That's what the Book example from this article on builders from the Effective Java book has
However looking at these builder examples from several popular Java libraries, none of them seem to put required parameters in the builder constructor. So I guess it can go either way
// isbn and title are required public Builder(String isbn, String title) { this.isbn = isbn; this.title = title; } // genre is optional public Builder genre(Genre genre) { this.genre = genre; return this; }
- https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/util/UriComponentsBuilder.html#build()
- https://hc.apache.org/httpcomponents-client-5.2.x/current/httpclient5/apidocs/org/apache/hc/client5/http/config/RequestConfig.Builder.html
- https://grpc.github.io/grpc-java/javadoc/io/grpc/ServerBuilder.html
- https://square.github.io/okhttp/3.x/okhttp/okhttp3/Request.Builder.html
- One point for Java interop if we use non nullable constructor arguments in Kotlin. They will get annotated with
org.jetbrains.annotations.NotNull
for Java and immediately throwjava.lang.NullPointerException: Parameter specified as non-null is null
if called with a null argument. Thanks @KiKoS0 for confirming this behavior. - A minor question is whether we want to nest the builder as
InngestEvent.Builder
or keep it asInngestEventBuilder
. As you can see from the examples of other builders I linked, this seems to be up to the preference of the library author.
Summary
Fix and improve how events are sent using the
Inngest
client'ssend
method.Changes:
InngestEventBuilder
to expose a builder pattern to creating eventsStep.kt
to merge and simplify data classesChecklist
Related