| 1 | import * as eventbridge from "@distilled.cloud/aws/eventbridge"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | |
| 5 | export interface TestEventPatternRequest |
| 6 | extends eventbridge.TestEventPatternRequest {} |
| 7 | |
| 8 | /** |
| 9 | * Tests whether an event matches an event pattern |
| 10 | * (`events:TestEventPattern`). |
| 11 | * |
| 12 | * An account-level operation — bind it with no resource argument. Useful for |
| 13 | * validating patterns before creating a `Rule`. Provide the |
| 14 | * `TestEventPatternHttp` layer on the Function to satisfy the binding. |
| 15 | * ### Testing Patterns |
| 16 | * **Example:** Test an Event Against a Pattern |
| 17 | * ```typescript |
| 18 | * // init — no resource argument (provide AWS.EventBridge.TestEventPatternHttp on the Function) |
| 19 | * const testEventPattern = yield* AWS.EventBridge.TestEventPattern(); |
| 20 | * |
| 21 | * // runtime — check whether the event would match |
| 22 | * const { Result } = yield* testEventPattern({ |
| 23 | * EventPattern: JSON.stringify({ source: ["my.app"] }), |
| 24 | * Event: JSON.stringify({ |
| 25 | * id: "1", |
| 26 | * source: "my.app", |
| 27 | * "detail-type": "OrderCreated", |
| 28 | * account: "123456789012", |
| 29 | * region: "us-east-1", |
| 30 | * time: new Date().toISOString(), |
| 31 | * detail: {}, |
| 32 | * }), |
| 33 | * }); |
| 34 | * ``` |
| 35 | * |
| 36 | * @binding |
| 37 | */ |
| 38 | export interface TestEventPattern extends Binding.Service< |
| 39 | TestEventPattern, |
| 40 | "AWS.EventBridge.TestEventPattern", |
| 41 | () => Effect.Effect< |
| 42 | ( |
| 43 | request: TestEventPatternRequest, |
| 44 | ) => Effect.Effect< |
| 45 | eventbridge.TestEventPatternResponse, |
| 46 | eventbridge.TestEventPatternError |
| 47 | > |
| 48 | > |
| 49 | > {} |
| 50 | export const TestEventPattern = Binding.Service<TestEventPattern>( |
| 51 | "AWS.EventBridge.TestEventPattern", |
| 52 | ); |