Module runtime/closure

APIs

APIs

interface CapturedPropertyChain

interface CapturedPropertyChain

property infos

infos: CapturedPropertyInfo[];

interface CapturedPropertyInfo

interface CapturedPropertyInfo

property invoked

invoked: boolean;

property name

name: string;

type CapturedVariableMap

type CapturedVariableMap = Map<string, CapturedPropertyChain[]>;

interface CapturedVariables

interface CapturedVariables

property optional

optional: CapturedVariableMap;

property required

required: CapturedVariableMap;

interface CodePathOptions

interface CodePathOptions

Options for controlling what gets returned by [computeCodePaths].

property extraExcludePackages

extraExcludePackages?: string[];

Packages to explicitly exclude from the Assets for a serialized closure. This can be used when clients want to trim down the size of a closure, and they know that some package won’t ever actually be needed at runtime, but is still a dependency of some package that is being used at runtime.

property extraIncludePackages

extraIncludePackages?: string[];

Extra packages to include when producing the Assets for a serialized closure. This can be useful if the packages are acquired in a way that the serialization code does not understand. For example, if there was some sort of module that was pulled in based off of a computed string.

property extraIncludePaths

extraIncludePaths?: string[];

Local file/directory paths that we always want to include when producing the Assets to be included for a serialized closure.

property logResource

logResource?: Resource;

The resource to log any errors we encounter against.

function computeCodePaths

computeCodePaths(options?: CodePathOptions): Promise<Map<string, Asset | Archive>>

computeCodePaths computes the local node_module paths to include in an uploaded cloud ‘Lambda’. Specifically, it will examine the package.json for the caller’s code, and will transitively walk it’s ‘dependencies’ section to determine what packages should be included.

During this walk, if a package is encountered that contains a "pulumi": { ... } section then the normal "dependencies": { ... } section of that package will not be included. These are “pulumi” packages, and those dependencies are only intended for use at deployment time. However, a “pulumi” package can also specify package that should be available at cloud-runtime. These packages are found in a "runtimeDependencies": { ... } section in the package.json file with the same format as the normal “dependencies” section.

See [CodePathOptions] for information on ways to control and configure the final set of paths included in the resultant asset/archive map.

Note: this functionality is specifically intended for use by downstream library code that is determining what is needed for a cloud-lambda. i.e. the aws.serverless.Function or azure.serverless.FunctionApp libraries. In general, other clients should not need to use this helper.

DEPRECATED Use the [computeCodePaths] overload that takes a [CodePathOptions] instead.
computeCodePaths(extraIncludePaths?: string[], extraIncludePackages?: string[], extraExcludePackages?: string[]): Promise<Map<string, Asset | Archive>>

function createFunctionInfoAsync

createFunctionInfoAsync(func: Function, serialize: (o: any) => boolean, logResource: Resource | undefined): Promise<FunctionInfo>

createFunctionInfo serializes a function and its closure environment into a form that is amenable to persistence as simple JSON. Like toString, it includes the full text of the function’s source code, suitable for execution. Unlike toString, it actually includes information about the captured environment.

interface Entry

interface Entry

Entry is the environment slot for a named lexically captured variable.

property array

array?: Entry[];

property expr

expr?: undefined | string;

property function

function?: FunctionInfo;

property json

json?: any;

property module

module?: undefined | string;

property object

object?: ObjectInfo;

property output

output?: Entry;

property promise

promise?: Entry;

property regexp

regexp?: undefined | {
    flags: string;
    source: string;
};

interface FunctionInfo

interface FunctionInfo extends ObjectInfo

property capturedValues

capturedValues: PropertyMap;

property code

code: string;

property env

env: PropertyMap;

property name

name: string | undefined;

property paramCount

paramCount: number;

property proto

proto?: Entry;

property usesNonLexicalThis

usesNonLexicalThis: boolean;

function getFunctionLocationAsync

getFunctionLocationAsync(func: Function): Promise<{
    column: number;
    file: string;
    line: number;
}>
getFunctionLocationAsync(func: Function): Promise<{
    column: any;
    file: string;
    line: any;
}>

function isLegalFunctionName

isLegalFunctionName(n: string): boolean

function isLegalMemberName

isLegalMemberName(n: string): boolean

function lookupCapturedVariableValueAsync

lookupCapturedVariableValueAsync(func: Function, freeVariable: string, throwOnFailure: boolean): Promise<any>
lookupCapturedVariableValueAsync(func: Function, freeVariable: string, throwOnFailure: boolean): Promise<any>

interface ObjectInfo

interface ObjectInfo

property env

env: PropertyMap;

property proto

proto?: Entry;

interface ParsedFunction

interface ParsedFunction extends ParsedFunctionCode

property capturedVariables

capturedVariables: CapturedVariables;

property funcExprWithName

funcExprWithName?: undefined | string;

property funcExprWithoutName

funcExprWithoutName: string;

property functionDeclarationName

functionDeclarationName?: undefined | string;

property isArrowFunction

isArrowFunction: boolean;

property usesNonLexicalThis

usesNonLexicalThis: boolean;

interface ParsedFunctionCode

interface ParsedFunctionCode

property funcExprWithName

funcExprWithName?: undefined | string;

property funcExprWithoutName

funcExprWithoutName: string;

property functionDeclarationName

functionDeclarationName?: undefined | string;

property isArrowFunction

isArrowFunction: boolean;

function parseFunction

parseFunction(funcString: string): [, string, ParsedFunction]

interface PropertyInfo

interface PropertyInfo

property configurable

configurable?: undefined | false | true;

property enumerable

enumerable?: undefined | false | true;

property get

get?: Entry;

property hasValue

hasValue: boolean;

property set

set?: Entry;

property writable

writable?: undefined | false | true;

interface PropertyInfoAndValue

interface PropertyInfoAndValue

property entry

entry: Entry;

property info

info?: PropertyInfo;

interface PropertyMap

interface PropertyMap extends Map<Entry, PropertyInfoAndValue>

method __@iterator

__@iterator(): IterableIterator<[, Entry, PropertyInfoAndValue]>

Returns an iterable of entries in the map.

method clear

clear(): void

method delete

delete(key: Entry): boolean

method entries

entries(): IterableIterator<[, Entry, PropertyInfoAndValue]>

Returns an iterable of key, value pairs for every entry in the map.

method forEach

forEach(callbackfn: (value: PropertyInfoAndValue, key: Entry, map: Map<Entry, PropertyInfoAndValue>) => void, thisArg?: any): void

method get

get(key: Entry): PropertyInfoAndValue | undefined

method has

has(key: Entry): boolean

method keys

keys(): IterableIterator<Entry>

Returns an iterable of keys in the map

method set

set(key: Entry, value: PropertyInfoAndValue): this

method values

values(): IterableIterator<PropertyInfoAndValue>

Returns an iterable of values in the map

property Map

Map: MapConstructor;

property __@toStringTag

__@toStringTag: string;

property size

size: number;

function rewriteSuperReferences

rewriteSuperReferences(code: string, isStatic: boolean): string

interface SerializedFunction

interface SerializedFunction

SerializeFunction is a representation of a serialized JavaScript function.

property exportName

exportName: string;

The name of the exported module member.

property text

text: string;

The text of a JavaScript module which exports a single name bound to an appropriate value. In the case of a normal function, this value will just be serialized function. In the case of a factory function this value will be the result of invoking the factory function.

function serializeFunction

serializeFunction(func: Function, args: SerializeFunctionArgs): Promise<SerializedFunction>

serializeFunction serializes a JavaScript function into a text form that can be loaded in another execution context, for example as part of a function callback associated with an AWS Lambda. The function serialization captures any variables captured by the function body and serializes those values into the generated text along with the function body. This process is recursive, so that functions referenced by the body of the serialized function will themselves be serialized as well. This process also deeply serializes captured object values, including prototype chains and property descriptors, such that the semantics of the function when deserialized should match the original function.

There are several known limitations: - If a native function is captured either directly or indirectly, closure serialization will return an error. - Captured values will be serialized based on their values at the time that serializeFunction is called. Mutations to these values after that (but before the deserialized function is used) will not be observed by the deserialized function.

interface SerializeFunctionArgs

interface SerializeFunctionArgs

SerializeFunctionArgs are arguments used to serialize a JavaScript function

property exportName

exportName?: undefined | string;

The name to export from the module defined by the generated module text. Defaults to ‘handler’.

property isFactoryFunction

isFactoryFunction?: undefined | false | true;

If this is a function which, when invoked, will produce the actual entrypoint function. Useful for when serializing a function that has high startup cost that only wants to be run once. The signature of this function should be: () => (provider_handler_args…) => provider_result

This will then be emitted as: exports.[exportName] = serialized_func_name();

In other words, the function will be invoked (once) and the resulting inner function will be what is exported.

property logResource

logResource?: Resource;

The resource to log any errors we encounter against.

property serialize

serialize?: undefined | (o: any) => boolean;

A function to prevent serialization of certain objects captured during the serialization. Primarily used to prevent potential cycles.

function serializeFunctionAsync

DEPRECATED Please use 'serializeFunction' instead.
serializeFunctionAsync(func: Function, serialize?: undefined | (o: any) => boolean): Promise<string>