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
feat(lambda,event-bridge): lambda event sources #179
Conversation
src/event-bridge/event-bus.ts
Outdated
@@ -115,16 +120,16 @@ export interface IEventBusFilterable<E extends Event> { | |||
): Rule<E, O>; | |||
} | |||
|
|||
export interface IEventBus<E extends Event = Event> | |||
export interface IEventBus<in E extends Event = Event, O extends E = E> |
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.
Might want to document the type parameters. Not immediately obvious what E and O mean
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.
In standard libraries, I usually prefer to use words for type parameters instead of symbols.
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.
Thanks, that was a helpful exercise.
/**
* @typeParam Evnt - the union type of events that this EventBus can accept.
* `Evnt` is the covariant version of `OutEnvt` in that
* the bus will accept any of `Evnt` while the EventBus can
* emit any of `OutEvnt`.
* @typeParam OutEvnt - the union type of events that this EventBus will emit through rules.
* `OutEvnt` is the contravariant version of `Envt` in that
* the bus will emit any of `OutEvnt` while the EventBus can
* can accept any of `Evnt`. This type parameter should be left
* empty to be inferred.
*/
* | ||
* ```ts | ||
* const bus = new EventBus(stack, 'bus'); | ||
* new Function(stack, 'func', { onSuccess: bus }, async () => {}); |
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.
Cool!
Should the title of the PR be more granular? Would someone reading the CHANGELOG know what this change is about based purely on the title? |
Ha... the change started with higher ambitions and then I realized that no one else but lambda and step function publish events! Will update. |
Signed-off-by: github-actions <github-actions@github.com>
…tionless into event_source_2
src/event-bridge/rule.ts
Outdated
* @typeParam - Evnt - The original event type from the {@link EventBus}. | ||
* @typeParam - OutEvnt - The narrowed event type after the predicate is applied. | ||
*/ | ||
export interface IRule<in Evnt extends Event, out OutEvnt extends Evnt> { |
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.
Why do we need two type parameters?
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.
Evnt
is the event in. The input to the predicate on the rule.
OutEvnt
is the narrowed type as the input to pipe
or map
or when
.
Essentially splitting and showing the two sides of the predicate.
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.
Why do you need Evnt
?
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.
Its being used on integration: IntegrationWithEventBus<Evnt, Props>,
But that doesn't seem right... will look.
src/event-bridge/event-bus.ts
Outdated
when<O extends E>( | ||
predicate: RulePredicateFunction<InEvnt, NewEvnt> | ||
): Rule<InEvnt, NewEvnt>; | ||
when<InEvnt extends OutEvnt, NewEvnt extends InEvnt>( |
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.
These two parameters seem overly complex and redundant. Why did you add them?
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.
Need to invert the in
Evntto
out NewEvntand
out OutEvntto
in InEvnt` for the when method.
src/event-bridge/event-bus.ts
Outdated
extends IEventBusFilterable<E>, | ||
/** | ||
* @typeParam Evnt - the union type of events that this EventBus can accept. | ||
* `Evnt` is the covariant version of `OutEvnt` in that |
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.
Evnt
is contra-variant, not co-variant. out
is for covariance
src/event-bridge/event-bus.ts
Outdated
* can accept any of `Evnt`. This type parameter should be left | ||
* empty to be inferred. ex: `EventBus<Event<Detail1> | Event<Detail2>>`. | ||
*/ | ||
export interface IEventBus<in Evnt extends Event = Event, OutEvnt extends Evnt = Evnt> |
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.
This doesn't seem right. I think we can remove the OutEvnt
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.
We can modify the types in a subsequent change. Ship it
Removed the unessecary Also fixed the covariance/contravariant naming issues and think I understand them better now :-) https://dmitripavlutin.com/typescript-covariance-contravariance/ |
I don't understand what changed |
Closes #44
Depends on #161 - This change made major changes to EventBus, stacking these changes to reduce churn.
❌ Api Gateway
❌ App Sync
❌ Dynamo
Lambda
Unlike Step Functions, Lambda does not emit events by default. Lambda has a concept of a
destination
orasync invocation
. Each lambda, version, and alias can only have a single onSuccess and onFailure destination. Destinations can be EventBuses, Sns topics, Sqs queues, or other lambda functions.