@karmaniverous/smoz
    Preparing search index...

    Interface DefineFunctionOptions<EventType, EventSchema, ResponseSchema, EnvKey>

    Options accepted by app.defineFunction(...).

    Only callerModuleUrl is required. Every other field is either optional or derived from the file's location under <appRootAbs>/functions and the app's functionDefaults. An explicit value always wins over a derived or defaulted one.

    Derivation gives the same result inside a deployed bundle: when esbuild inlines the app config into the function, so appRootAbs points inside a functions folder and the caller isn't under <appRootAbs>/functions, the root is the folder holding the caller's last functions/<eventType>/ (<eventType> a key of the app's eventTypeMapSchema). Read <appRootAbs> below as that root.

    interface DefineFunctionOptions<
        EventType extends string = string,
        EventSchema extends z.ZodType | undefined = z.ZodType | undefined,
        ResponseSchema extends z.ZodType | undefined = z.ZodType | undefined,
        EnvKey extends PropertyKey = PropertyKey,
    > {
        basePath?: string;
        callerModuleUrl: string;
        contentType?: string;
        endpointsRootAbs?: string;
        eventSchema?: EventSchema;
        eventType?: EventType;
        fnEnvKeys?: readonly EnvKey[];
        functionName?: string;
        http?: FunctionHttpConfig;
        httpContexts?: readonly ("my" | "private" | "public")[];
        method?:
            | "options"
            | "head"
            | "trace"
            | "parameters"
            | `x-${string}`
            | "summary"
            | "description"
            | "servers"
            | "get"
            | "put"
            | "post"
            | "delete"
            | "patch"
            | "query"
            | "additionalOperations"
            | "$ref";
        responseSchema?: ResponseSchema;
        serverless?: FunctionServerlessConfig;
    }

    Type Parameters

    • EventType extends string = string

      event token (a key of the app's eventTypeMapSchema)

    • EventSchema extends z.ZodType | undefined = z.ZodType | undefined

      optional Zod schema validated before the handler

    • ResponseSchema extends z.ZodType | undefined = z.ZodType | undefined

      optional Zod schema validated after the handler

    • EnvKey extends PropertyKey = PropertyKey

      keys of the app's global and stage params

    Index
    basePath?: string

    HTTP base path. Defaults to the folders between endpointsRootAbs and the method folder.

    callerModuleUrl: string

    import.meta.url of the registering module (required).

    contentType?: string

    Response content type. Beats every default (functionDefaults.contentType, app http.defaults, functionDefaults.http.options and the selected profile); only this function's own http.options.contentType beats it. Defaults to the highest of those that is set, else application/json.

    endpointsRootAbs?: string

    Root that method and basePath are derived from. Defaults to <appRootAbs>/functions/<eventType> (POSIX separators).

    eventSchema?: EventSchema

    Zod schema validated before the handler.

    eventType?: EventType

    Event token selecting the runtime event type (e.g. 'rest', 'sqs').

    Defaults to the first folder under <appRootAbs>/functions that contains the caller (functions/rest/users/get/lambda.ts gives 'rest'). Throws at definition time when the caller isn't under functions/<eventType>/ or that folder isn't a key of the app's eventTypeMapSchema.

    Given explicitly, the literal token types the handler's event. Omitted, the type widens to the union of the map's event types, so pass it explicitly when the handler needs the narrowed event type.

    fnEnvKeys?: readonly EnvKey[]

    Extra env keys exposed to this function (merged with functionDefaults.fnEnvKeys).

    functionName?: string

    Unique function name, used as the Serverless function key.

    Defaults to functionDefaults.functionName when set, else the caller's directory relative to appRootAbs, joined with _ (e.g. functions_rest_hello_get).

    HTTP middleware customization for this function: profile selection, option overrides, extend/transform/replace. Combined with functionDefaults.http; see FunctionDefaults.http.

    httpContexts?: readonly ("my" | "private" | "public")[]

    Security contexts to expose. Defaults to functionDefaults.httpContexts, else ['public'].

    method?:
        | "options"
        | "head"
        | "trace"
        | "parameters"
        | `x-${string}`
        | "summary"
        | "description"
        | "servers"
        | "get"
        | "put"
        | "post"
        | "delete"
        | "patch"
        | "query"
        | "additionalOperations"
        | "$ref"

    HTTP method. Defaults to the last folder name (e.g. get).

    responseSchema?: ResponseSchema

    Zod schema validated after the handler.

    Serverless Framework properties for this function (memorySize, timeout, tenancy, image, ...), merged key by key over functionDefaults.serverless (image one level deeper when both are objects). See FunctionServerlessConfig.