FaasJS
Home
  • Guide
  • Documents
  • Templates
  • Changelog
  • Ecosystem

    • Docker Images
  • Github
  • Contributing
  • Sponsor
  • Security
Home
  • Guide
  • Documents
  • Templates
  • Changelog
  • Ecosystem

    • Docker Images
  • Github
  • Contributing
  • Sponsor
  • Security

Documents / @faasjs/dev / Func

Class: Func<TEvent, TContext, TResult>

Core executable unit used by FaasJS runtimes and helpers.

A Func composes lifecycle plugins, exposes a runtime handler via Func.export, and keeps function configuration available across mounts and invokes.

Example

import { Func } from '@faasjs/core'

const func = new Func({
  async handler({ event }) {
    return { echo: event }
  },
})

const result = await func.export().handler({ name: 'FaasJS' })

Type Parameters

TEvent

TEvent = any

Runtime event type.

TContext

TContext = any

Runtime context type.

TResult

TResult = any

Async result type produced by the handler.

Indexable

[key: string]: any

Constructors

Constructor

new Func<TEvent, TContext, TResult>(config): Func<TEvent, TContext, TResult>

Create a FaasJS function.

Parameters

config

FuncConfig<TEvent, TContext>

Plugins and optional business handler used to configure the function.

Returns

Func<TEvent, TContext, TResult>

Methods

export()

export(): object

Build the exported handler wrapper for the function.

The wrapper initializes request id/runtime context fields, invokes mount hooks on first use, and throws any Error object stored in data.response.

Returns

object

Object containing the exported handler.

handler

handler: ExportedHandler<TEvent, TContext, TResult>

invoke()

invoke(data): Promise<void>

Invoke the function.

Parameters

data

InvokeData<TEvent, TContext, TResult>

Invocation state mutated by plugins and the final handler.

Returns

Promise<void>

Promise that resolves after invoke hooks complete.

mount()

mount(data?): Promise<void>

First time mount the function.

Parameters

data?

Optional initial event, context, config, and logger used during mount.

config?

Config

Function config override used during mount.

context

TContext

Initial context value passed through mount hooks.

event

TEvent

Initial event value passed through mount hooks.

logger?

Logger

Logger override used during mount.

Returns

Promise<void>

Promise that resolves after mount hooks complete.

Properties

config

config: Config

Mutable runtime configuration used by the function.

filename?

optional filename?: string

Resolved source filename inferred from the constructor call stack.

handler?

optional handler?: Handler<TEvent, TContext, TResult>

Final business handler invoked after plugins finish.

mounted

mounted: boolean = false

Indicates whether mount hooks have already run.

plugins

plugins: Plugin[]

Ordered plugin instances attached to this function.

runtime

runtime: FuncRuntime | undefined

Default runtime value written to context.runtime when the caller does not provide one.