Skip to content
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

Merged
merged 58 commits into from
Jun 11, 2022
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
e99cca9
chore: update rule name
thantos May 26, 2022
22e4057
feat(EventBus): schedule, whenAny, rename, when without scope
thantos May 27, 2022
242f086
chore: update repo reference
thantos May 28, 2022
49a0eb1
Merge branch 'main' into event_bus_v2_2
thantos May 29, 2022
240d94e
fix: change whenAny to all
thantos May 29, 2022
0b9bd85
feat: event bridge docs
thantos May 29, 2022
811d000
Merge branch 'main' into event_bus_v2_2
thantos May 29, 2022
81a6edc
Merge branch 'main' into event_bus_v2_2
thantos May 30, 2022
062ba3e
fix: feedback
thantos May 30, 2022
50f0c3d
feat: breaking change: update bus invocation to putEvents method
thantos May 31, 2022
0e187f5
feat: rename EventBusEvent interface to Event
thantos May 31, 2022
2e73a83
feat: more docs
thantos May 31, 2022
bd92146
feat: pipe escape hatch and escape hatch docs
thantos May 31, 2022
f3c4c12
feat(lambda,step-functions,event-bridge): event sources
thantos May 31, 2022
b40fe5e
fix: sussman is bad at spelling
thantos May 31, 2022
b644d08
feat: lambda event sources
thantos May 31, 2022
bb88954
Merge branch 'event_bus_v2_2' into event_source_2
thantos May 31, 2022
be9f3fa
fix: add missing ids to when statements
thantos Jun 1, 2022
b5b449f
Merge branch 'event_bus_v2_2' into event_source_2
thantos Jun 1, 2022
d8223ae
fix: failing test-app
thantos Jun 1, 2022
63550ff
feat: tests
thantos Jun 1, 2022
84f8889
feat: configure async
thantos Jun 1, 2022
96d3998
feat: comments
thantos Jun 1, 2022
fcb8edb
chore: docs
thantos Jun 1, 2022
415b37b
fix: feedback
thantos Jun 1, 2022
e814f3f
Merge branch 'event_bus_v2_2' into event_source_2
thantos Jun 1, 2022
0168cee
fix: explicitly make EventBus event parameter as contra-variant (#185)
Jun 1, 2022
64dc91b
fix: feedback
thantos Jun 2, 2022
2c404f7
chore: eslint explitit accessibility
thantos Jun 2, 2022
40e3ad1
fix: eslint
thantos Jun 2, 2022
414b83d
Merge branch 'main' into event_source_2
thantos Jun 2, 2022
83fc9d5
adding lint-staged back
thantos Jun 2, 2022
259c0ab
fix: upgrade typescript for website
thantos Jun 2, 2022
bebeeb6
fix: function links in docs
thantos Jun 2, 2022
cc1c31f
fix: feedback
thantos Jun 2, 2022
6dd4fb1
Merge branch 'main' into event_source_2
thantos Jun 2, 2022
64d8944
Merge branch 'main' into event_source_2
thantos Jun 5, 2022
1bc5e88
fix: restore lint-staged
thantos Jun 5, 2022
7b0f680
fix: feedback
thantos Jun 5, 2022
fdcc5ff
fix: reduce use of in
thantos Jun 5, 2022
462c40c
chore: self mutation
invalid-email-address Jun 5, 2022
7892478
Merge branch 'main' into event_source_2
thantos Jun 7, 2022
bd37996
Merge branch 'event_source_2' of https://github.com/functionless/func…
thantos Jun 7, 2022
f0ac49c
Merge branch 'main' into event_source_2
thantos Jun 7, 2022
53016f8
Merge branch 'main' into event_source_2
thantos Jun 8, 2022
5a7c076
fix: renaming type params and fixing variance
thantos Jun 8, 2022
4e1fc75
fix: event bus variant coverage
thantos Jun 8, 2022
68be9d4
chore: document event bus types
thantos Jun 8, 2022
f85a60e
chore: function type docs, naming, and variance
thantos Jun 8, 2022
4d59856
Merge branch 'main' into event_source_2
thantos Jun 8, 2022
32c7def
chore: skip lib check test app
thantos Jun 8, 2022
5eb61a8
fix: rename configureAsyncInvoke to enableAsyncInvoke
thantos Jun 8, 2022
406ae98
chore: self mutation
invalid-email-address Jun 8, 2022
761cf5a
formatting
thantos Jun 8, 2022
a19df01
Merge branch 'event_source_2' of https://github.com/functionless/func…
thantos Jun 8, 2022
4bb3260
Merge branch 'main' into event_source_2
thantos Jun 11, 2022
7bf95e0
fix: remove extra type parameters in rules, fix variant labeling
thantos Jun 11, 2022
471e64f
fix: reduce use of covariant types
thantos Jun 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion .eslintrc.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 18 additions & 5 deletions .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const project = new CustomTypescriptProject({
"constructs@^10.0.0",
"esbuild",
"typesafe-dynamodb@^0.1.5",
"typescript@^4.6.2",
"typescript@^4.7.2",
],
eslintOptions: {
lintProjenRc: true,
Expand Down Expand Up @@ -172,20 +172,33 @@ project.eslint.addRules({
"@typescript-eslint/no-shadow": "off",
"@typescript-eslint/member-ordering": "off",
"brace-style": "off",
"@typescript-eslint/explicit-member-accessibility": "off",
});

/**
* ES Lint parser needs to know about all of the tsconfig files to use.
*/
project.eslint.addOverride({
files: ["*.ts", "*.tsx"],
files: ["*.ts", "*.mts", "*.cts", "*.tsx"],
parserOptions: {
project: [
"./tsconfig.dev.json",
"./test-app/tsconfig.json",
"./website/tsconfig.json",
],
},
rules: {
"@typescript-eslint/explicit-member-accessibility": [
"error",
{
accessibility: "explicit",
overrides: {
accessors: "explicit",
constructors: "no-public",
methods: "explicit",
properties: "off",
parameterProperties: "off",
},
},
],
},
});

project.synth();
4 changes: 2 additions & 2 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 43 additions & 40 deletions src/event-bridge/event-bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ export const isEventBus = <E extends Event>(v: any): v is IEventBus<E> => {
);
};

export interface IEventBusFilterable<E extends Event> {
/**
* Returns the {@link Event} type on the {@link EventBus}.
*/
export type EventBusEvent<B extends IEventBus<any>> = [B] extends [IEventBus<infer E>] ? E : never;
thantos marked this conversation as resolved.
Show resolved Hide resolved

export interface IEventBusFilterable<in E extends Event> {
/**
* EventBus Rules can filter events using Functionless predicate functions.
*
Expand Down Expand Up @@ -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>
Copy link
Collaborator

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

Copy link
Collaborator

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.

Copy link
Collaborator Author

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.
 */

extends IEventBusFilterable<E>,
Integration<
"EventBus",
(
event: EventBusPutEventInput<E>,
...events: EventBusPutEventInput<E>[]
event: EventBusPutEventInput<O>,
...events: EventBusPutEventInput<O>[]
) => void,
EventBusTargetIntegration<
EventBusPutEventInput<E>,
EventBusPutEventInput<O>,
aws_events_targets.EventBusProps | undefined
>
> {
Expand All @@ -134,8 +139,8 @@ export interface IEventBus<E extends Event = Event>

// @ts-ignore - value does not exist, is only available at compile time
readonly __functionBrand: (
event: EventBusPutEventInput<E>,
...events: EventBusPutEventInput<E>[]
event: EventBusPutEventInput<O>,
...events: EventBusPutEventInput<O>[]
) => void;

/**
Expand All @@ -147,15 +152,10 @@ export interface IEventBus<E extends Event = Event>
* Put one or more events on an Event Bus.
*/
putEvents(
event: EventBusPutEventInput<E>,
...events: EventBusPutEventInput<E>[]
event: EventBusPutEventInput<O>,
...events: EventBusPutEventInput<O>[]
): void;

readonly eventBus: EventBusTargetIntegration<
E,
aws_events_targets.EventBusProps | undefined
>;

/**
* Creates a rule that matches all events on the bus.
*
Expand All @@ -176,11 +176,11 @@ export interface IEventBus<E extends Event = Event>
* .pipe(func);
* ```
*/
all(): PredicateRuleBase<E>;
all(scope: Construct, id: string): PredicateRuleBase<E>;
all(): PredicateRuleBase<O>;
all(scope: Construct, id: string): PredicateRuleBase<O>;
}

abstract class EventBusBase<E extends Event> implements IEventBus<E> {
abstract class EventBusBase<in E extends Event, O extends E> implements IEventBus<E, O> {
/**
* This static properties identifies this class as an EventBus to the TypeScript plugin.
*/
Expand All @@ -192,7 +192,7 @@ abstract class EventBusBase<E extends Event> implements IEventBus<E> {

protected static singletonDefaultNode = "__DefaultBus";

private allRule: PredicateRuleBase<E> | undefined;
private allRule: PredicateRuleBase<O> | undefined;

public readonly putEvents: IntegrationCall<
"EventBus.putEvents",
Expand All @@ -201,8 +201,8 @@ abstract class EventBusBase<E extends Event> implements IEventBus<E> {

// @ts-ignore - value does not exist, is only available at compile time
readonly __functionBrand: (
event: EventBusPutEventInput<E>,
...events: EventBusPutEventInput<E>[]
event: EventBusPutEventInput<O>,
...events: EventBusPutEventInput<O>[]
) => void;

constructor(readonly bus: aws_events.IEventBus) {
Expand Down Expand Up @@ -339,7 +339,7 @@ abstract class EventBusBase<E extends Event> implements IEventBus<E> {
}

public readonly eventBus = makeEventBusIntegration<
E,
EventBusPutEventInput<O>,
thantos marked this conversation as resolved.
Show resolved Hide resolved
aws_events_targets.EventBusProps | undefined
>({
target: (props, targetInput?) => {
Expand All @@ -354,16 +354,16 @@ abstract class EventBusBase<E extends Event> implements IEventBus<E> {
/**
* @inheritdoc
*/
when<O extends E>(
public when<O extends E>(
id: string,
predicate: RulePredicateFunction<E, O>
): Rule<E, O>;
when<O extends E>(
public when<O extends E>(
scope: Construct,
id: string,
predicate: RulePredicateFunction<E, O>
): Rule<E, O>;
when<O extends E>(
public when<O extends E>(
scope: Construct | string,
id?: string | RulePredicateFunction<E, O>,
predicate?: RulePredicateFunction<E, O>
Expand All @@ -385,12 +385,12 @@ abstract class EventBusBase<E extends Event> implements IEventBus<E> {
}
}

all(): PredicateRuleBase<E>;
all(scope: Construct, id: string): PredicateRuleBase<E>;
all(scope?: Construct, id?: string): PredicateRuleBase<E> {
public all(): PredicateRuleBase<O>;
public all(scope: Construct, id: string): PredicateRuleBase<O>;
public all(scope?: Construct, id?: string): PredicateRuleBase<O> {
if (!scope || !id) {
if (!this.allRule) {
this.allRule = new PredicateRuleBase<E>(
this.allRule = new PredicateRuleBase<O>(
this.bus,
"all",
this as IEventBus<any>,
Expand All @@ -400,7 +400,7 @@ abstract class EventBusBase<E extends Event> implements IEventBus<E> {
}
return this.allRule;
}
return new PredicateRuleBase<E>(scope, id, this as IEventBus<any>, {
return new PredicateRuleBase<O>(scope, id, this as IEventBus<any>, {
doc: {},
});
}
Expand Down Expand Up @@ -456,15 +456,15 @@ export type EventBusPutEventInput<E extends Event> = Partial<E> &
* .pipe(anotherEventBus);
* ```
*/
export class EventBus<E extends Event> extends EventBusBase<E> {
export class EventBus<in E extends Event, O extends E = E> extends EventBusBase<E, O> {
constructor(scope: Construct, id: string, props?: aws_events.EventBusProps) {
super(new aws_events.EventBus(scope, id, props));
}

/**
* Import an {@link aws_events.IEventBus} wrapped with Functionless abilities.
*/
static fromBus<E extends Event>(bus: aws_events.IEventBus): IEventBus<E> {
public static fromBus<E extends Event>(bus: aws_events.IEventBus): IEventBus<E> {
return new ImportedEventBus<E>(bus);
}

Expand All @@ -477,9 +477,9 @@ export class EventBus<E extends Event> extends EventBusBase<E> {
* new functionless.EventBus.fromBus(awsBus);
* ```
*/
static default<E extends Event>(stack: Stack): DefaultEventBus<E>;
static default<E extends Event>(scope: Construct): DefaultEventBus<E>;
static default<E extends Event>(
public static default<E extends Event>(stack: Stack): DefaultEventBus<E>;
public static default<E extends Event>(scope: Construct): DefaultEventBus<E>;
public static default<E extends Event>(
scope: Construct | Stack
): DefaultEventBus<E> {
return new DefaultEventBus<E>(scope);
Expand All @@ -501,7 +501,7 @@ export class EventBus<E extends Event> extends EventBusBase<E> {
* .pipe(func);
* ```
*/
static schedule(
public static schedule(
scope: Construct,
id: string,
schedule: aws_events.Schedule,
Expand All @@ -514,7 +514,7 @@ export class EventBus<E extends Event> extends EventBusBase<E> {
}
}

export class DefaultEventBus<E extends Event> extends EventBusBase<E> {
export class DefaultEventBus<in E extends Event> extends EventBusBase<E, E> {
constructor(scope: Construct) {
const stack = scope instanceof Stack ? scope : Stack.of(scope);
const bus =
Expand Down Expand Up @@ -547,7 +547,7 @@ export class DefaultEventBus<E extends Event> extends EventBusBase<E> {
* .pipe(func);
* ```
*/
schedule(
public schedule(
scope: Construct,
id: string,
schedule: aws_events.Schedule,
Expand All @@ -565,7 +565,7 @@ export class DefaultEventBus<E extends Event> extends EventBusBase<E> {
}
}

class ImportedEventBus<E extends Event> extends EventBusBase<E> {
class ImportedEventBus<in E extends Event> extends EventBusBase<E, E> {
constructor(bus: aws_events.IEventBus) {
super(bus);
}
Expand All @@ -589,7 +589,7 @@ class ImportedEventBus<E extends Event> extends EventBusBase<E> {
*/
export interface EventBusTargetIntegration<
// the payload type we expect to be transformed into before making this call.
P,
in P,
Props extends object | undefined = undefined
> {
/**
Expand All @@ -599,8 +599,11 @@ export interface EventBusTargetIntegration<
*
* This is useful for cases like {@link IRule.pipe} and {@link IEventTransform.pipe} which need to validate that
* an integration implements the right EventBus integration.
*
* We use a function interface in order to satisfy the covariant relationship that we expect the super-P in as opposed to
* returning sub-P.
*/
__payloadBrand: P;
__payloadBrand: ((p: P) => void);

/**
* Method called when an integration is passed to EventBus's `.pipe` function.
Expand Down
7 changes: 6 additions & 1 deletion src/event-bridge/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export { EventBus, EventBusTargetIntegration } from "./event-bus";
export {
EventBus,
isEventBus,
IEventBus,
EventBusTargetIntegration,
} from "./event-bus";
export * from "./rule";
export * from "./types";