import { aws_events } from "aws-cdk-lib"; import { Construct } from "constructs"; import { IEventBus, IEventBusFilterable, DynamicProps, IntegrationWithEventBus } from "./event-bus"; import { PatternDocument } from "./event-pattern/pattern"; import { EventTransformFunction, EventTransform } from "./transform"; import type { Event } from "./types"; /** * A function interface used by the {@link EventBus}'s when function to generate a rule. * * event is every event sent to the bus to be filtered. This argument is optional. */ export declare type RulePredicateFunction = ((event: Evnt) => event is OutEvnt) | ((event: Evnt) => boolean); /** * @typeParam - Evnt - The original event type from the {@link EventBus}. * @typeParam - OutEvnt - The narrowed event type after the predicate is applied. */ export interface IRule { readonly resource: aws_events.Rule; /** * This static property identifies this class as a Rule to the TypeScript plugin. */ readonly functionlessKind: typeof RuleBase.FunctionlessType; /** * Transform the event before sending to a target using pipe using TargetInput transforms. * https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-transform-target-input.html * * Return the entire event (or directly call .pipe without map) * * ```ts * .map(event => event) * ``` * * Return only the detail object * * ```ts * .map(event => event.detail) * ``` * * Create a new object * * ```ts * .map(event => ({ * source: event.source, * value: event.detail.value * })) * ``` * * Format a string * * ```ts * .map(event => `this is the source ${event.source}`) * ``` * * Format a string in an object * * ```ts * .map(event => ({ formattedSource: `this is the source ${event.source}` })) * ``` * * Get the rule name * * ```ts * .map((event, $utils) => ({ * ruleName: $utils.context.ruleName, * detail: event.detail * })) * ``` * * * Local variables * * ```ts * .map(event => { * const formatted = `${event.id}_${event.detail.id}`; * return ({ * formatted * }) * }) * ``` * * Unsupported by EventBridge: * * String slicing/sub string * * Arithmetic * * Boolean logic `event.source === "lambda"`) * * Formatting the whole event `event: ${event}` * * More... * * Unsupported by Functionless: * * Variables from outside of the function scope * * @typeParam - NewEvnt - The type transformed to in the transform function. * @typeParam - InEvnt - `InEvnt` is the covariant of `OutEvnt`. This type parameter should be left * empty to be inferred. ex: `.map(() => {})` or `.map(() => {})`. */ map(transform: EventTransformFunction): EventTransform; /** * Defines a target of the {@link EventTransform}'s rule using this TargetInput. * * The event is sent to the target verbatim unless .map is used first. * * Event buses do not support TargetInput transforms. * https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-bus-to-bus.html * * Send to lambda * * ```ts * const myFunction = new Function(this, 'awsTarget', ...); * bus.when(...).pipe(myFunction) * ``` * * Send to event bus with DLQ and Retries * * ```ts * const myFunction = new Function(this, 'awsTarget', ...); * const myQueue = new aws_sqs.Queue(this, 'queue'); * bus.when(...).pipe(myFunction, { deadLetterQueue: myQueue, retryAttempts: 10 }); * ``` * * Send to event bus * * ```ts * const targetBus = aws_events.EventBus(this, 'awsBus'); * bus.when(...).pipe(new EventBus(targetBus)) * ``` */ pipe(integration: IntegrationWithEventBus, ...props: Parameters>): void; pipe(callback: () => aws_events.IRuleTarget): void; } /** * @typeParam - Evnt - The original event type from the {@link EventBus}. * @typeParam - OutEvnt - The narrowed event type after the predicate is applied. */ declare abstract class RuleBase implements IRule { readonly ruleGenerator: () => aws_events.Rule; /** * This static properties identifies this class as a Rule to the TypeScript plugin. */ static readonly FunctionlessType = "Rule"; readonly functionlessKind = "Rule"; _resource: aws_events.Rule | undefined; get resource(): aws_events.Rule; constructor(ruleGenerator: () => aws_events.Rule); /** * @inheritdoc */ map(transform: EventTransformFunction): EventTransform; /** * @inheritdoc */ pipe(integration: IntegrationWithEventBus, ...props: Parameters>): void; pipe(callback: () => aws_events.IRuleTarget): void; } /** * Special base rule that supports some internal behaviors like joining (AND) compiled rules. * * @typeParam - Evnt - The original event type from the {@link EventBus}. * @typeParam - OutEvnt - The narrowed event type after the predicate is applied. */ export declare class PredicateRuleBase extends RuleBase implements IEventBusFilterable { private bus; readonly document: PatternDocument; constructor(scope: Construct, id: string, bus: IEventBus, /** * Functionless Pattern Document representation of Event Bridge rules. */ document: PatternDocument, /** * Documents to join (AND) with the document. * Allows chaining of when statement. */ ...aggregateDocuments: PatternDocument[]); /** * @inheritdoc * * @typeParam InEvnt - The type the {@link Rule} matches. Covariant of output {@link OutEvnt}. * @typeParam NewEvnt - The type the predicate narrows to, a sub-type of {@link InEvnt}. */ when(id: string, predicate: RulePredicateFunction): PredicateRuleBase; when(scope: Construct, id: string, predicate: RulePredicateFunction): PredicateRuleBase; } /** * Represents a set of events filtered by the when predicate using event bus's EventPatterns. * https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-patterns.html * * @see EventBus.when for more details on filtering events. * * @typeParam - Evnt - The original event type from the {@link EventBus}. * @typeParam - OutEvnt - The narrowed event type after the predicate is applied. */ export declare class Rule extends PredicateRuleBase { constructor(scope: Construct, id: string, bus: IEventBus, predicate: RulePredicateFunction); /** * Import an {@link aws_events.Rule} wrapped with Functionless abilities. */ static fromRule(rule: aws_events.Rule): IRule; } /** * The event structure output for all scheduled events. * @see https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-run-lambda-schedule.html#eb-schedule-create-rule */ export interface ScheduledEvent extends Event<{}, "Scheduled Event", "aws.events"> { } export declare class ImportedRule extends RuleBase { constructor(rule: aws_events.Rule); } export declare const deploymentOnlyModule = true; export {}; //# sourceMappingURL=rule.d.ts.map