-
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
Open
djfarrelly
wants to merge
4
commits into
main
Choose a base branch
from
dan/inn-3336-simplify-inngestsend-for-sending-events-without-require
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
package com.inngest | ||
|
||
data class Event( | ||
import com.beust.klaxon.Json | ||
|
||
/** | ||
* An internal class used for parsing events sent to Inngest functions | ||
*/ | ||
internal data class Event( | ||
val id: String, | ||
val name: String, | ||
val data: LinkedHashMap<String, Any>, | ||
|
@@ -9,7 +14,61 @@ data class Event( | |
val v: Any? = null, | ||
) | ||
|
||
// data class EventAPIResponse( | ||
// val ids: Array<String>, | ||
// val status: String, | ||
// ) | ||
/** | ||
* Create an event to send to Inngest | ||
*/ | ||
data class InngestEvent | ||
@JvmOverloads | ||
constructor( | ||
val name: String, | ||
val data: Map<String, Any>, | ||
@Json(serializeNull = false) | ||
val user: Map<String, Any>? = null, | ||
@Json(serializeNull = false) | ||
val id: String? = null, | ||
@Json(serializeNull = false) | ||
val ts: Long? = null, | ||
@Json(serializeNull = false) | ||
val v: String? = null, | ||
) | ||
|
||
/** | ||
* Construct a new Inngest Event via builder | ||
*/ | ||
class InngestEventBuilder( | ||
val name: String, | ||
val data: Map<String, Any>, | ||
) { | ||
private var id: String? = null | ||
private var user: Map<String, Any>? = null | ||
private var ts: Long? = null | ||
private var v: String? = null | ||
|
||
fun id(id: String): InngestEventBuilder = apply { this.id = id } | ||
|
||
fun ts(ts: Long): InngestEventBuilder = apply { this.ts = ts } | ||
|
||
fun user(user: Map<String, Any>) = apply { this.user = user } | ||
|
||
fun v(v: String): InngestEventBuilder = apply { this.v = v } | ||
|
||
fun build(): InngestEvent { | ||
return InngestEvent( | ||
name, | ||
data, | ||
user, | ||
id, | ||
ts, | ||
v, | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* The response from the Inngest Event API including the ids of any event created | ||
* 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 commentThe reason will be displayed to describe this comment to others. Learn more. The PR originally changed this from |
||
val status: Int, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
inngest/src/test/kotlin/com/inngest/InngestEventBuilderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.inngest | ||
|
||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class InngestEventBuilderTest { | ||
@Test | ||
fun constructorOnlyWithRequiredParameters() { | ||
val event = | ||
InngestEventBuilder("test-name", mapOf()) | ||
.build() | ||
assertEquals(InngestEvent("test-name", mapOf()), event) | ||
} | ||
|
||
@Test | ||
fun optionalParameters() { | ||
val event = | ||
InngestEventBuilder("test-name", mapOf()) | ||
.user(mapOf("userId" to 5)) | ||
.id("test-id") | ||
.ts(100) | ||
.v("1.0") | ||
.build() | ||
assertEquals(InngestEvent("test-name", mapOf(), mapOf("userId" to 5), "test-id", 100, "1.0"), event) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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, thisEvent
is no longer used. I don't know if the intent was to convert externalInngestEvent
s to internalEvent
s somewhere, but I wasn't sure where so I'm punting on that for this PR