sst 2.0.31 → 2.0.32

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.
@@ -152,7 +152,7 @@ export interface EventBusRuleProps {
152
152
  * },
153
153
  * },
154
154
  * targets: {
155
- * myTarget1: "test/lambda.handler",
155
+ * myTarget1: "src/lambda.handler",
156
156
  * },
157
157
  * },
158
158
  * },
@@ -262,6 +262,15 @@ export declare class EventBus extends Construct implements SSTConstruct {
262
262
  * The name of the internally created `EventBus` instance.
263
263
  */
264
264
  get eventBusName(): string;
265
+ /**
266
+ * Get a rule
267
+ *
268
+ * @example
269
+ * ```js
270
+ * bus.getRule("myRule");
271
+ * ```
272
+ */
273
+ getRule(key: string): events.Rule | undefined;
265
274
  /**
266
275
  * Add rules after the EventBus has been created.
267
276
  *
@@ -280,14 +289,17 @@ export declare class EventBus extends Construct implements SSTConstruct {
280
289
  */
281
290
  addRules(scope: Construct, rules: Record<string, EventBusRuleProps>): void;
282
291
  /**
283
- * Get a rule
292
+ * Add targets to existing rules.
284
293
  *
285
294
  * @example
286
295
  * ```js
287
- * bus.getRule("myRule");
296
+ * bus.addRules(stack, "myRule", {
297
+ * myTarget1: "src/function1.handler"
298
+ * myTarget2: "src/function2.handler"
299
+ * });
288
300
  * ```
289
301
  */
290
- getRule(key: string): events.Rule | undefined;
302
+ addTargets(scope: Construct, ruleKey: string, targets: Record<string, FunctionInlineDefinition | EventBusFunctionTargetProps | Queue | EventBusQueueTargetProps>): void;
291
303
  /**
292
304
  * Binds the given list of resources to all event targets in this EventBus.
293
305
  *
@@ -56,6 +56,17 @@ export class EventBus extends Construct {
56
56
  get eventBusName() {
57
57
  return this.cdk.eventBus.eventBusName;
58
58
  }
59
+ /**
60
+ * Get a rule
61
+ *
62
+ * @example
63
+ * ```js
64
+ * bus.getRule("myRule");
65
+ * ```
66
+ */
67
+ getRule(key) {
68
+ return this.rulesData[key];
69
+ }
59
70
  /**
60
71
  * Add rules after the EventBus has been created.
61
72
  *
@@ -76,15 +87,24 @@ export class EventBus extends Construct {
76
87
  Object.entries(rules).forEach(([ruleKey, rule]) => this.addRule(scope, ruleKey, rule));
77
88
  }
78
89
  /**
79
- * Get a rule
90
+ * Add targets to existing rules.
80
91
  *
81
92
  * @example
82
93
  * ```js
83
- * bus.getRule("myRule");
94
+ * bus.addRules(stack, "myRule", {
95
+ * myTarget1: "src/function1.handler"
96
+ * myTarget2: "src/function2.handler"
97
+ * });
84
98
  * ```
85
99
  */
86
- getRule(key) {
87
- return this.rulesData[key];
100
+ addTargets(scope, ruleKey, targets) {
101
+ // Get rule
102
+ const eventsRule = this.getRule(ruleKey);
103
+ if (!eventsRule) {
104
+ throw new Error(`Cannot find the rule "${ruleKey}" in the "${this.node.id}" EventBus.`);
105
+ }
106
+ // Add targets
107
+ Object.entries(targets).forEach(([targetName, target]) => this.addTarget(scope, ruleKey, eventsRule, targetName, target));
88
108
  }
89
109
  /**
90
110
  * Binds the given list of resources to all event targets in this EventBus.
@@ -246,10 +266,14 @@ export class EventBus extends Construct {
246
266
  });
247
267
  this.rulesData[ruleKey] = eventsRule;
248
268
  // Create Targets
249
- Object.entries(rule.targets || {}).forEach(([targetName, target]) => this.addTarget(scope, ruleKey, eventsRule, targetName, target));
269
+ this.addTargets(scope, ruleKey, rule.targets || {});
250
270
  }
251
271
  addTarget(scope, ruleKey, eventsRule, targetName, target) {
252
272
  this.targetsData[ruleKey] = this.targetsData[ruleKey] || {};
273
+ // Validate rule not redefined
274
+ if (this.targetsData[ruleKey][targetName]) {
275
+ throw new Error(`A target with name "${targetName}" already exists in rule "${ruleKey}"`);
276
+ }
253
277
  if (target instanceof Queue || target.queue) {
254
278
  target = target;
255
279
  this.addQueueTarget(scope, ruleKey, eventsRule, targetName, target);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sst",
3
- "version": "2.0.31",
3
+ "version": "2.0.32",
4
4
  "bin": {
5
5
  "sst": "cli/sst.js"
6
6
  },