import { AnyAsyncFunction, AnyFunction, CallExpr, Expr, FunctionLike } from "@functionless/ast"; import { aws_events_targets, aws_lambda } from "aws-cdk-lib"; import { IDestination } from "aws-cdk-lib/aws-lambda"; import type { Context } from "aws-lambda"; import { Construct } from "constructs"; import esbuild from "esbuild"; import { ApiGatewayVtlIntegration } from "./api"; import { AppSyncVtlIntegration } from "./appsync"; import { ASL, ASLGraph } from "./asl"; import { IEventBus, Event, EventBusTargetIntegration, Rule } from "./event-bridge"; import { NativePreWarmContext, PrewarmProps } from "./function-prewarm"; import { Integration } from "./integration"; export declare function isFunction(a: any): a is IFunction; export declare type AnyLambda = Function; export interface FunctionEventBusTargetProps extends Omit { } export declare type FunctionClosure = (payload: Payload, context: Context) => Promise; /** * Returns the payload type on the {@link IFunction}. */ export declare type FunctionPayloadType> = [ Func ] extends [IFunction] ? P : never; /** * Returns the output type on the {@link IFunction}. */ export declare type FunctionOutputType> = [ Func ] extends [IFunction] ? O : never; declare type FunctionAsyncOnFailureDestination = aws_lambda.FunctionProps["onFailure"] | IEventBus> | IFunction, any>; declare type FunctionAsyncOnSuccessDestination = aws_lambda.FunctionProps["onSuccess"] | IEventBus> | IFunction, any>; /** * Wrapper around {@link aws_lambda.EventInvokeConfigOptions} which allows users to provide Functionless * {@link EventBus} and {@link Function} for the onSuccess and onFailure async event destinations. */ export interface EventInvokeConfigOptions extends Omit { onSuccess?: FunctionAsyncOnSuccessDestination; onFailure?: FunctionAsyncOnFailureDestination; } /** * @typeParam Payload - The super-set payload type of the function. * @typeParam Output - The output type of the function. * @typeParam OutPayload - The covariant type of {@link Payload} used when the payload is output. * For example when the Payload is sent to a {@link Function} or {@link EventBus} * from onSuccess or onFailure event sources. This type parameter should be left * empty to be inferred. ex: `Function`. */ export interface IFunction extends Integration<"Function", ConditionalFunction> { readonly functionlessKind: typeof Function.FunctionlessType; readonly kind: typeof Function.FunctionlessType; readonly resource: aws_lambda.IFunction; (...args: Parameters>): ReturnType>; /** * Event Source for the {@link Function} onSuccess async invocation destination. * * For Lambda, the onSuccess destination is not enabled by default. * It must first be configured via either the {@link Function} constructor * or by using {@link IFunction.enableAsyncInvoke} and that destination must match the bus provided here. * * ```ts * const bus = new EventBus(stack, 'bus'); * new Function(stack, 'func', { onSuccess: bus }, async () => {}); * ``` * * or * * ```ts * const bus = new EventBus(stack, 'bus'); * const func = new Function(stack, 'func', async () => {}); * // if onSuccess or onFailure is already set, this will fail. * func.enableAsyncInvoke({ onSuccess: bus }); * ``` * * @see https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html#invocation-async-destinations * * The rule returned will contain the logic: * * ```ts * when(id, event => event.source === "lambda" * && event["detail-type"] === "Lambda Function Invocation Result - Success" * && event.resources.includes(this.resource.functionArn)) * ``` */ onSuccess(bus: IEventBus>, id: string): Rule>; /** * Event Source for the {@link Function} onFailure async invocation destination. * * The onFailure destination is not enabled by default. * It must first be configured via either the {@link Function} constructor * or by using {@link IFunction.enableAsyncInvoke} and that destination must match the bus provided here. * * ```ts * const bus = new EventBus(stack, 'bus'); * new Function(stack, 'func', { onFailure: bus }, async () => {}); * ``` * * or * * ```ts * const bus = new EventBus(stack, 'bus'); * const func = new Function(stack, 'func', async () => {}); * // if onSuccess or onFailure is already set, this will fail. * func.enableAsyncInvoke({ onFailure: bus }); * ``` * * @see https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html#invocation-async-destinations * * The rule returned will contain the logic: * * ```ts * when(id, event => event.source === "lambda" * && event["detail-type"] === "Lambda Function Invocation Result - Failure" * && event.resources.includes(this.resource.functionArn)) * ``` */ onFailure(bus: IEventBus>, id: string): Rule>; /** * Set the async invocation options on a function. Can be use to enable and set the onSuccess and onFailure destinations. * * Wraps {@link aws_lambda.IFunction.configureAsyncInvoke} provided by CDK to support Functionless resources directly. * * If onSuccess or onFailure were already set either through {@link FunctionProps} or {@link IFunction.enableAsyncInvoke} * This method will fail. */ enableAsyncInvoke(config: EventInvokeConfigOptions): void; readonly eventBus: EventBusTargetIntegration; } export interface AsyncResponseBase

{ version: string; /** * ISO 8601 */ timestamp: string; requestPayload: P; responseContext: { statusCode: number; executedVersion: "$LATEST" | string; functionError: string; }; } export declare type AsyncFunctionResponseEvent = AsyncResponseSuccessEvent | AsyncResponseFailureEvent

; export interface AsyncResponseSuccess extends AsyncResponseBase

{ responsePayload: O; requestContext: { requestId: string; functionArn: string; condition: "Success"; approximateInvokeCount: number; }; } export interface AsyncResponseFailure

extends AsyncResponseBase

{ requestContext: { requestId: string; functionArn: string; condition: "RetriesExhausted" | "EventAgeExceeded" | string; approximateInvokeCount: number; }; responsePayload: { errorMessage: string; errorType: string; stackTrace: string[]; }; } export interface AsyncResponseSuccessEvent extends Event, "Lambda Function Invocation Result - Success", "lambda"> { } export interface AsyncResponseFailureEvent

extends Event, "Lambda Function Invocation Result - Failure", "lambda"> { } declare abstract class FunctionBase implements IFunction, Integration<"Function", ConditionalFunction> { readonly resource: aws_lambda.IFunction; readonly kind: "Function"; readonly native: NativeIntegration>; readonly functionlessKind = "Function"; static readonly FunctionlessType = "Function"; readonly appSyncVtl: AppSyncVtlIntegration; readonly apiGWVtl: ApiGatewayVtlIntegration; readonly __functionBrand: ConditionalFunction; constructor(resource: aws_lambda.IFunction); asl(call: CallExpr, context: ASL): (import("./asl").Choice & { node?: import("@functionless/ast").FunctionlessNode | undefined; } & { output: ASLGraph.Output; }) | (import("./asl").Fail & { node?: import("@functionless/ast").FunctionlessNode | undefined; } & { output: ASLGraph.Output; }) | ({ Comment?: string | undefined; InputPath?: string | undefined; OutputPath?: string | undefined; } & { Next: string; End?: undefined; } & { Comment?: string | undefined; Parameters?: import("./asl").Parameters | undefined; ResultSelector?: import("./asl").Parameters | undefined; ResultPath?: string | null | undefined; Retry?: import("./asl").Retry[] | undefined; Catch?: import("./asl").Catch[] | undefined; } & { Type: "Map"; Iterator: import("./asl").StateMachine; ItemsPath?: string | undefined; ResultPath?: string | null | undefined; MaxConcurrency?: number | undefined; } & { node?: import("@functionless/ast").FunctionlessNode | undefined; } & { output: ASLGraph.Output; }) | ({ Comment?: string | undefined; InputPath?: string | undefined; OutputPath?: string | undefined; } & { End: true; Next?: undefined; } & { Comment?: string | undefined; Parameters?: import("./asl").Parameters | undefined; ResultSelector?: import("./asl").Parameters | undefined; ResultPath?: string | null | undefined; Retry?: import("./asl").Retry[] | undefined; Catch?: import("./asl").Catch[] | undefined; } & { Type: "Map"; Iterator: import("./asl").StateMachine; ItemsPath?: string | undefined; ResultPath?: string | null | undefined; MaxConcurrency?: number | undefined; } & { node?: import("@functionless/ast").FunctionlessNode | undefined; } & { output: ASLGraph.Output; }) | ({ Comment?: string | undefined; InputPath?: string | undefined; OutputPath?: string | undefined; } & { Next: string; End?: undefined; } & { Comment?: string | undefined; Parameters?: import("./asl").Parameters | undefined; ResultSelector?: import("./asl").Parameters | undefined; ResultPath?: string | null | undefined; Retry?: import("./asl").Retry[] | undefined; Catch?: import("./asl").Catch[] | undefined; } & { Type: "Parallel"; Branches: import("./asl").StateMachine[]; } & { node?: import("@functionless/ast").FunctionlessNode | undefined; } & { output: ASLGraph.Output; }) | ({ Comment?: string | undefined; InputPath?: string | undefined; OutputPath?: string | undefined; } & { End: true; Next?: undefined; } & { Comment?: string | undefined; Parameters?: import("./asl").Parameters | undefined; ResultSelector?: import("./asl").Parameters | undefined; ResultPath?: string | null | undefined; Retry?: import("./asl").Retry[] | undefined; Catch?: import("./asl").Catch[] | undefined; } & { Type: "Parallel"; Branches: import("./asl").StateMachine[]; } & { node?: import("@functionless/ast").FunctionlessNode | undefined; } & { output: ASLGraph.Output; }) | ({ Comment?: string | undefined; InputPath?: string | undefined; OutputPath?: string | undefined; } & { Next: string; End?: undefined; } & { Comment?: string | undefined; Type: "Pass"; Result?: any; ResultPath?: string | null | undefined; Parameters?: import("./asl").Parameters | undefined; } & { node?: import("@functionless/ast").FunctionlessNode | undefined; } & { output: ASLGraph.Output; }) | ({ Comment?: string | undefined; InputPath?: string | undefined; OutputPath?: string | undefined; } & { End: true; Next?: undefined; } & { Comment?: string | undefined; Type: "Pass"; Result?: any; ResultPath?: string | null | undefined; Parameters?: import("./asl").Parameters | undefined; } & { node?: import("@functionless/ast").FunctionlessNode | undefined; } & { output: ASLGraph.Output; }) | (import("./asl").Succeed & { node?: import("@functionless/ast").FunctionlessNode | undefined; } & { output: ASLGraph.Output; }) | ({ Comment?: string | undefined; InputPath?: string | undefined; OutputPath?: string | undefined; } & { Next: string; End?: undefined; } & { Comment?: string | undefined; Parameters?: import("./asl").Parameters | undefined; ResultSelector?: import("./asl").Parameters | undefined; ResultPath?: string | null | undefined; Retry?: import("./asl").Retry[] | undefined; Catch?: import("./asl").Catch[] | undefined; } & { Type: "Task"; Resource: string; TimeoutSeconds?: number | undefined; TimeoutSecondsPath?: string | undefined; HeartbeatSeconds?: number | undefined; HeartbeatSecondsPath?: string | undefined; } & { node?: import("@functionless/ast").FunctionlessNode | undefined; } & { output: ASLGraph.Output; }) | ({ Comment?: string | undefined; InputPath?: string | undefined; OutputPath?: string | undefined; } & { End: true; Next?: undefined; } & { Comment?: string | undefined; Parameters?: import("./asl").Parameters | undefined; ResultSelector?: import("./asl").Parameters | undefined; ResultPath?: string | null | undefined; Retry?: import("./asl").Retry[] | undefined; Catch?: import("./asl").Catch[] | undefined; } & { Type: "Task"; Resource: string; TimeoutSeconds?: number | undefined; TimeoutSecondsPath?: string | undefined; HeartbeatSeconds?: number | undefined; HeartbeatSecondsPath?: string | undefined; } & { node?: import("@functionless/ast").FunctionlessNode | undefined; } & { output: ASLGraph.Output; }) | ({ Comment?: string | undefined; InputPath?: string | undefined; OutputPath?: string | undefined; } & { Next: string; End?: undefined; } & { Type: "Wait"; Seconds?: number | undefined; Timestamp?: string | undefined; SecondsPath?: string | undefined; TimestampPath?: string | undefined; } & { node?: import("@functionless/ast").FunctionlessNode | undefined; } & { output: ASLGraph.Output; }) | ({ Comment?: string | undefined; InputPath?: string | undefined; OutputPath?: string | undefined; } & { End: true; Next?: undefined; } & { Type: "Wait"; Seconds?: number | undefined; Timestamp?: string | undefined; SecondsPath?: string | undefined; TimestampPath?: string | undefined; } & { node?: import("@functionless/ast").FunctionlessNode | undefined; } & { output: ASLGraph.Output; }) | ASLGraph.OutputSubState | ASLGraph.LiteralValue | ASLGraph.JsonPath | ASLGraph.ConditionOutput; protected static normalizeAsyncDestination(destination: FunctionAsyncOnSuccessDestination | FunctionAsyncOnFailureDestination

): IDestination | undefined; enableAsyncInvoke(config: EventInvokeConfigOptions): void; onSuccess(bus: IEventBus>, id: string): Rule>; onFailure(bus: IEventBus>, id: string): Rule>; readonly eventBus: EventBusTargetIntegration; } interface FunctionBase { (...args: Parameters>): ReturnType>; } export declare enum SerializerImpl { /** * The default serializer, uses the v8 inspector API to introspect closures. * * It is slow and has caveats such as not properly serializing stable references to variables. * * @see https://github.com/functionless/nodejs-closure-serializer */ V1 = 0, /** * A new experimental serializer that makes use of Functionless's SWC AST * reflection library that decorates syntax for use at runtime. * * It has not been as well tested, but is fast, synchronous and has support for * stable references and other features. * * @see https://www.npmjs.com/package/@functionless/ast-reflection */ V2 = 1, Default = 0 } export interface FunctionProps extends Omit { /** * Whether to generate source maps for serialized closures and * to set --enableSourceMaps on NODE_OPTIONS environment variable. * * Only supported when using {@link SerializerImpl.V2}. * * @default true */ sourceMaps?: boolean; /** * Which {@link SerializerImpl} to use when serializing closures. * * @default {@link SerializerImpl.V1} */ serializer?: SerializerImpl; /** * Method which allows runtime computation of AWS client configuration. * ```ts * new Lambda(clientConfigRetriever('LAMBDA')) * ``` * * @param clientName optionally return a different client config based on the {@link ClientName}. * */ clientConfigRetriever?: PrewarmProps["clientConfigRetriever"]; /** * The destination for failed invocations. * * Supports use of Functionless {@link IEventBus} or {@link IFunction}. * * ```ts * const bus = new EventBus<> * ``` * * @default - no destination */ onSuccess?: FunctionAsyncOnSuccessDestination; /** * The destination for successful invocations. * * @default - no destination */ onFailure?: FunctionAsyncOnFailureDestination; } /** * A type-safe NodeJS Lambda Function generated from the closure provided. * * Can be called from within an {@link AppsyncResolver}. * * For example: * ```ts * const getPerson = new Function(stack, 'func', async () => { * // get person logic * }); * * new AppsyncResolver(() => { * return getPerson("value"); * }) * ``` * * Can wrap an existing {@link aws_lambda.Function}. * * ```ts * const getPerson = Function.fromFunction( * new aws_lambda.Function(..) * ); * ``` */ export declare class Function extends FunctionBase { /** * Dangling promises which are processing Function handler code from the function serializer. * To correctly resolve these for CDK synthesis, either use `asyncSynth()` or use `cdk synth` in the CDK cli. * https://twitter.com/samgoodwin89/status/1516887131108438016?s=20&t=7GRGOQ1Bp0h_cPsJgFk3Ww */ static readonly promises: Promise[]; /** * Wrap a {@link aws_lambda.Function} with Functionless. * * A wrapped function can be invoked, but the code is provided in the CDK Construct. */ static fromFunction(func: aws_lambda.IFunction): ImportedFunction; /** * Create a lambda function using a native typescript closure. * * ```ts * new Function<{ val: string }, string>(this, 'myFunction', async (event) => event.val); * ``` */ constructor(scope: Construct, id: string, func: FunctionClosure); constructor(scope: Construct, id: string, props: FunctionProps, func: FunctionClosure); } export declare function inferIamPolicies(decl: FunctionLike, func: aws_lambda.IFunction): void; export interface IntegrationInvocation { integration: Integration; args: Expr[]; } export declare function findAllIntegrations(decl: FunctionLike): IntegrationInvocation[]; /** * A {@link Function} which wraps a CDK function. * * An imported function can be invoked, but the code is provided in the CDK Construct. */ export declare class ImportedFunction extends FunctionBase { } declare type ConditionalFunction = [Payload] extends [undefined] ? (payload?: Payload) => Promise : (payload: Payload) => Promise; interface CallbackLambdaCodeProps extends PrewarmProps { } /** * A special lambda code wrapper that serializes whatever closure it is given. * * Caveat: Relies on async functions which may not finish when using CDK's app.synth() * * Ensure the generate function's promise is completed using something like Lambda.promises and the `asyncSynth` function. * * Use: * * Initialize the {@link CallbackLambdaCode} `const code = new CallbackLambdaCode()` * * First bind the code to a Function `new aws_lambda.Function(..., { code })` * * Then call generate `const promise = code.generate(integrations)` * */ export declare class CallbackLambdaCode extends aws_lambda.Code { private func; private props; private scope; constructor(func: AnyAsyncFunction, props: CallbackLambdaCodeProps); bind(scope: Construct): aws_lambda.CodeConfig; /** * Thanks to cloudy for the help getting this to work. * https://github.com/skyrpex/cloudy/blob/main/packages/cdk/src/aws-lambda/callback-function.ts#L518-L540 * https://twitter.com/samgoodwin89/status/1516887131108438016?s=20&t=7GRGOQ1Bp0h_cPsJgFk3Ww */ generate(integrationPrewarms: NativeIntegration["preWarm"][], serializerImpl: SerializerImpl, sourceMaps: boolean): Promise; } /** * Interface to consume to add an Integration to Native Lambda Functions. * * ```ts * new Function(this, 'func', () => { * mySpecialIntegration() * }) * * const mySpecialIntegration = makeIntegration<() => void>({ * native: {...} // an instance of NativeIntegration * }) * ``` */ export interface NativeIntegration { /** * Called by any {@link Function} that will invoke this integration during CDK Synthesis. * Add permissions, create connecting resources, validate. * * @param context - The function invoking this function. * @param args - The functionless encoded AST form of the arguments passed to the integration. */ bind: (context: aws_lambda.IFunction, args: Expr[]) => void; /** * @param args The arguments passed to the integration function by the user. * @param preWarmContext contains singleton instances of client and other objects initialized outside of the native * function handler. */ call: (args: Parameters, preWarmContext: NativePreWarmContext) => ReturnType; /** * Method called outside of the handler to initialize things like the PreWarmContext */ preWarm?: (preWarmContext: NativePreWarmContext) => void; } interface TokenContext { token: string; env: `env__functionless${string}`; } /** * Serializes a function to a string, extracting tokens and replacing some objects with a simpler form. */ export declare function serialize(func: AnyAsyncFunction, integrationPrewarms: NativeIntegration["preWarm"][], serializerImpl?: SerializerImpl, props?: PrewarmProps): Promise<[string, TokenContext[]]>; /** * Bundles a serialized function with esbuild. */ export declare function bundle(text: string, sourceMap?: boolean): Promise; export declare const deploymentOnlyModule = true; export {}; //# sourceMappingURL=function.d.ts.map