@lafken/event 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BucketNames, DynamoTableNames, EventBusNames, LambdaMetadata } from '@lafken/common';
|
|
1
|
+
import type { BucketNames, DynamoTableNames, EventBusNames, LambdaMetadata, LambdaProps } from '@lafken/common';
|
|
2
2
|
export interface EventRuleBaseProps {
|
|
3
3
|
/**
|
|
4
4
|
* Maximum event age.
|
|
@@ -21,6 +21,24 @@ export interface EventRuleBaseProps {
|
|
|
21
21
|
* If not provided, the default event bus is used.
|
|
22
22
|
*/
|
|
23
23
|
bus?: EventBusNames;
|
|
24
|
+
/**
|
|
25
|
+
* Lambda configuration for the method.
|
|
26
|
+
*
|
|
27
|
+
* Specifies the properties and settings of the Lambda function
|
|
28
|
+
* associated with this API method. This allows you to customize
|
|
29
|
+
* aspects such as timeout, memory, runtime, environment variables,
|
|
30
|
+
* services, and tracing on a per-method basis.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* {
|
|
34
|
+
* timeout: 300,
|
|
35
|
+
* memory: 1024,
|
|
36
|
+
* runtime: 22,
|
|
37
|
+
* services: ['sqs'],
|
|
38
|
+
* enableTrace: booleam
|
|
39
|
+
* }
|
|
40
|
+
*/
|
|
41
|
+
lambda?: LambdaProps;
|
|
24
42
|
}
|
|
25
43
|
export type S3DetailType = 'Object Created' | 'Object Deleted';
|
|
26
44
|
export type S3ObjectKey = {
|
package/lib/resolver/resolver.js
CHANGED
|
@@ -7,6 +7,8 @@ const common_1 = require("@lafken/common");
|
|
|
7
7
|
const resolver_1 = require("@lafken/resolver");
|
|
8
8
|
const main_1 = require("../main");
|
|
9
9
|
const rule_1 = require("./rule/rule");
|
|
10
|
+
const LafkenEventBus = resolver_1.lafkenResource.make(cloudwatch_event_bus_1.CloudwatchEventBus);
|
|
11
|
+
const LafkenDataEventBus = resolver_1.lafkenResource.make(data_aws_cloudwatch_event_bus_1.DataAwsCloudwatchEventBus);
|
|
10
12
|
class EventRuleResolver {
|
|
11
13
|
type = main_1.RESOURCE_TYPE;
|
|
12
14
|
eventBuses = {};
|
|
@@ -20,14 +22,30 @@ class EventRuleResolver {
|
|
|
20
22
|
const defaultBus = new data_aws_cloudwatch_event_bus_1.DataAwsCloudwatchEventBus(scope, 'EventDefaultBus', {
|
|
21
23
|
name: 'default',
|
|
22
24
|
});
|
|
23
|
-
this.eventBuses.default =
|
|
25
|
+
this.eventBuses.default = {
|
|
26
|
+
eventBus: defaultBus,
|
|
27
|
+
};
|
|
24
28
|
for (const eventBusProps of this.props) {
|
|
25
29
|
if (eventBusProps.busName === 'default') {
|
|
26
30
|
throw new Error('Event bus default already exist');
|
|
27
31
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
let eventBus;
|
|
33
|
+
if (eventBusProps.isExternal) {
|
|
34
|
+
eventBus = new LafkenDataEventBus(scope, `${eventBusProps.busName}-bus`, {
|
|
35
|
+
name: eventBusProps.busName,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
eventBus = new LafkenEventBus(scope, `${eventBusProps.busName}-bus`, {
|
|
40
|
+
name: eventBusProps.busName,
|
|
41
|
+
});
|
|
42
|
+
new resolver_1.ResourceOutput(eventBus, eventBusProps.outputs);
|
|
43
|
+
}
|
|
44
|
+
eventBus.isGlobal('event-bus', eventBusProps.busName);
|
|
45
|
+
this.eventBuses[eventBusProps.busName] = {
|
|
46
|
+
eventBus: eventBus,
|
|
47
|
+
extend: eventBusProps.extend,
|
|
48
|
+
};
|
|
31
49
|
}
|
|
32
50
|
}
|
|
33
51
|
create(module, resource) {
|
|
@@ -44,11 +62,23 @@ class EventRuleResolver {
|
|
|
44
62
|
const id = `${handler.name}-${metadata.name}`;
|
|
45
63
|
const bus = this.eventBuses[handler.bus || 'default'];
|
|
46
64
|
new rule_1.Rule(module, id, {
|
|
47
|
-
bus,
|
|
65
|
+
bus: bus.eventBus,
|
|
48
66
|
handler,
|
|
49
67
|
resourceMetadata: metadata,
|
|
50
68
|
});
|
|
51
69
|
}
|
|
52
70
|
}
|
|
71
|
+
afterCreate(scope) {
|
|
72
|
+
for (const key in this.eventBuses) {
|
|
73
|
+
const { extend, eventBus } = this.eventBuses[key];
|
|
74
|
+
if (!extend) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
extend({
|
|
78
|
+
scope,
|
|
79
|
+
eventBus,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
53
83
|
}
|
|
54
84
|
exports.EventRuleResolver = EventRuleResolver;
|
|
@@ -1,12 +1,87 @@
|
|
|
1
1
|
import type { CloudwatchEventBus } from '@cdktn/provider-aws/lib/cloudwatch-event-bus';
|
|
2
|
-
import type {
|
|
2
|
+
import type { DataAwsCloudwatchEventBus } from '@cdktn/provider-aws/lib/data-aws-cloudwatch-event-bus';
|
|
3
|
+
import type { EventBusNames, ResourceOutputType } from '@lafken/common';
|
|
3
4
|
import type { AppStack } from '@lafken/resolver';
|
|
4
|
-
|
|
5
|
+
export type BusOutputAttributes = 'arn' | 'id';
|
|
6
|
+
interface ExtendProps<T> {
|
|
7
|
+
/**
|
|
8
|
+
* The CDKTN application stack scope.
|
|
9
|
+
*/
|
|
5
10
|
scope: AppStack;
|
|
6
|
-
|
|
11
|
+
/**
|
|
12
|
+
* The underlying CloudWatch Event Bus construct.
|
|
13
|
+
* Use this to apply additional CDKTN configuration beyond what
|
|
14
|
+
* `EventRuleResolverProps` exposes directly.
|
|
15
|
+
*/
|
|
16
|
+
eventBus: T;
|
|
7
17
|
}
|
|
8
|
-
export interface
|
|
18
|
+
export interface EventBusList {
|
|
19
|
+
eventBus: CloudwatchEventBus | DataAwsCloudwatchEventBus;
|
|
20
|
+
extend?: (props: ExtendProps<CloudwatchEventBus | DataAwsCloudwatchEventBus>) => void;
|
|
21
|
+
}
|
|
22
|
+
export interface EventRuleResolverBaseProps {
|
|
23
|
+
/**
|
|
24
|
+
* Defines the name of the custom EventBridge event bus to create.
|
|
25
|
+
*
|
|
26
|
+
* The value must match one of the registered `EventBusNames` in your application.
|
|
27
|
+
* The reserved name `'default'` cannot be used here — the default EventBridge bus
|
|
28
|
+
* is always provisioned automatically.
|
|
29
|
+
*/
|
|
9
30
|
busName: EventBusNames;
|
|
10
|
-
extend?: (props: ExtendProps) => void;
|
|
11
31
|
}
|
|
32
|
+
export interface InternalEventRuleResolverProps extends EventRuleResolverBaseProps {
|
|
33
|
+
isExternal?: never;
|
|
34
|
+
/**
|
|
35
|
+
* Defines which EventBridge event bus attributes should be exported.
|
|
36
|
+
*
|
|
37
|
+
* Supported attributes are based on Terraform `aws_cloudwatch_event_bus`
|
|
38
|
+
* attribute reference:
|
|
39
|
+
* - `arn`: ARN of the event bus.
|
|
40
|
+
* - `id`: Name of the event bus.
|
|
41
|
+
*
|
|
42
|
+
* Each selected attribute can be exported through SSM Parameter Store (`type: 'ssm'`)
|
|
43
|
+
* or Terraform outputs (`type: 'output'`).
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* {
|
|
47
|
+
* outputs: [
|
|
48
|
+
* { type: 'ssm', name: '/my-app/orders-bus-arn', value: 'arn' },
|
|
49
|
+
* { type: 'output', name: 'orders_bus_id', value: 'id' }
|
|
50
|
+
* ]
|
|
51
|
+
* }
|
|
52
|
+
*/
|
|
53
|
+
outputs?: ResourceOutputType<BusOutputAttributes>;
|
|
54
|
+
/**
|
|
55
|
+
* Allows extending the event bus with custom configurations or resources.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* {
|
|
59
|
+
* extend: ({ eventBus, scope }) => {
|
|
60
|
+
* // Apply additional CDKTN configuration
|
|
61
|
+
* },
|
|
62
|
+
* }
|
|
63
|
+
*/
|
|
64
|
+
extend?: (props: ExtendProps<CloudwatchEventBus>) => void;
|
|
65
|
+
}
|
|
66
|
+
export interface ExternalEventRuleResolverProps extends EventRuleResolverBaseProps {
|
|
67
|
+
/**
|
|
68
|
+
* Marks the EventBridge event bus as an external resource.
|
|
69
|
+
*
|
|
70
|
+
* When set to `true`, the event bus is not created by the framework.
|
|
71
|
+
* Instead, it references an existing EventBridge event bus using the provided `busName`.
|
|
72
|
+
*/
|
|
73
|
+
isExternal: true;
|
|
74
|
+
/**
|
|
75
|
+
* Allows extending the event bus with custom configurations or resources.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* {
|
|
79
|
+
* extend: ({ eventBus, scope }) => {
|
|
80
|
+
* // Apply additional CDKTN configuration
|
|
81
|
+
* },
|
|
82
|
+
* }
|
|
83
|
+
*/
|
|
84
|
+
extend?: (props: ExtendProps<DataAwsCloudwatchEventBus>) => void;
|
|
85
|
+
}
|
|
86
|
+
export type EventRuleResolverProps = InternalEventRuleResolverProps | ExternalEventRuleResolverProps;
|
|
12
87
|
export {};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { CloudwatchEventBus } from '@cdktn/provider-aws/lib/cloudwatch-event-bus';
|
|
2
|
+
import type { DataAwsCloudwatchEventBus } from '@cdktn/provider-aws/lib/data-aws-cloudwatch-event-bus';
|
|
2
3
|
import type { ResourceMetadata } from '@lafken/common';
|
|
3
4
|
import type { EventRuleMetadata } from '../../main';
|
|
4
5
|
export interface RuleProps {
|
|
5
6
|
resourceMetadata: ResourceMetadata;
|
|
6
7
|
handler: EventRuleMetadata;
|
|
7
|
-
bus: CloudwatchEventBus;
|
|
8
|
+
bus: CloudwatchEventBus | DataAwsCloudwatchEventBus;
|
|
8
9
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lafken/event",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Define EventBridge event listeners using TypeScript decorators - serverless event-driven infrastructure",
|
|
6
6
|
"keywords": [
|
|
@@ -49,24 +49,24 @@
|
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"reflect-metadata": "^0.2.2",
|
|
52
|
-
"@lafken/resolver": "0.
|
|
52
|
+
"@lafken/resolver": "0.9.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@cdktn/provider-aws": "^23.
|
|
56
|
-
"@swc/core": "^1.15.
|
|
57
|
-
"@swc/helpers": "^0.5.
|
|
58
|
-
"@vitest/runner": "^4.1.
|
|
59
|
-
"cdktn": "^0.22.
|
|
55
|
+
"@cdktn/provider-aws": "^23.5.0",
|
|
56
|
+
"@swc/core": "^1.15.21",
|
|
57
|
+
"@swc/helpers": "^0.5.20",
|
|
58
|
+
"@vitest/runner": "^4.1.2",
|
|
59
|
+
"cdktn": "^0.22.1",
|
|
60
60
|
"cdktn-vitest": "^1.0.0",
|
|
61
|
-
"constructs": "^10.
|
|
61
|
+
"constructs": "^10.6.0",
|
|
62
62
|
"unplugin-swc": "^1.5.9",
|
|
63
|
-
"vitest": "^4.1.
|
|
64
|
-
"@lafken/common": "0.
|
|
63
|
+
"vitest": "^4.1.2",
|
|
64
|
+
"@lafken/common": "0.9.0"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"@cdktn/provider-aws": "
|
|
68
|
-
"@lafken/common": "
|
|
69
|
-
"cdktn": "
|
|
67
|
+
"@cdktn/provider-aws": ">=23.0.0",
|
|
68
|
+
"@lafken/common": ">=0.8.0",
|
|
69
|
+
"cdktn": ">=0.22.0",
|
|
70
70
|
"constructs": "^10.4.5"
|
|
71
71
|
},
|
|
72
72
|
"engines": {
|