// Copyright 2017 - 2026 will Farrell, Luciano Mammino, and Middy contributors. // SPDX-License-Identifier: MIT import type middy from "@middy/core"; import type { Context as LambdaContext } from "aws-lambda"; import type { ArrayValues, Choose, DeepAwaited, IsUnknown, SanitizeKey, SanitizeKeys, } from "./type-utils.d.ts"; export interface Options { AwsClient?: new (config: ClientOptions) => Client; awsClientOptions?: Partial; awsClientAssumeRole?: string; awsClientCapture?: (service: Client) => Client; fetchData?: { [key: string]: string }; disablePrefetch?: boolean; cacheKey?: string; cacheExpiry?: number; cacheKeyExpiry?: Record; cacheMaxSize?: number; setToContext?: boolean; } export declare class HttpError extends Error { status: number; statusCode: number; expose: boolean; [key: string]: unknown; [key: number]: unknown; } declare function createPrefetchClient( options: Options, ): Client; declare function createClient( options: Options, request: middy.Request, ): Promise; declare function canPrefetch( options: Options, ): boolean; // get an empty object if false is passed declare function getInternal< TContext extends LambdaContext, TInternal extends Record, >( variables: false, request: middy.Request, ): Promise<{}>; // get all internal values if true is passed (with promises resolved) declare function getInternal< TContext extends LambdaContext, TInternal extends Record, >( variables: true, request: middy.Request, ): Promise>; // get a single value declare function getInternal< TContext extends LambdaContext, TInternal extends Record, TVars extends keyof TInternal | string, >( variables: TVars, request: middy.Request, ): TVars extends keyof TInternal ? Promise]: TInternal[TVars] }>> : TVars extends string ? IsUnknown, TVars>> extends true ? unknown // could not find the path : Promise<{ [_ in SanitizeKey]: Choose, TVars>; }> : unknown; // path is not a string or a keyof TInternal // get multiple values declare function getInternal< TContext extends LambdaContext, TInternal extends Record, TVars extends Array, >( variables: TVars, request: middy.Request, ): Promise< SanitizeKeys<{ [TVar in ArrayValues]: TVar extends keyof TInternal ? DeepAwaited : TVar extends string ? Choose, TVar> : unknown; // path is not a string or a keyof TInternal }> >; // remap object declare function getInternal< TContext extends LambdaContext, TInternal extends Record, TMap extends Record, >( variables: TMap, request: middy.Request, ): Promise<{ [P in keyof TMap]: TMap[P] extends keyof TInternal ? DeepAwaited : TMap[P] extends string ? Choose, TMap[P]> : unknown; // path is not a string or a keyof TInternal }>; declare function sanitizeKey(key: T): SanitizeKey; declare function processCache( options: Options, fetch: (request: middy.Request, cachedValues: unknown) => unknown, request?: middy.Request, ): { value: unknown; expiry: number }; declare function getCache(keys: string): unknown; declare function clearCache(keys?: string | string[] | null): void; declare function jsonSafeParse( string: string, reviver?: (key: string, value: unknown) => unknown, ): unknown; declare function jsonParseProtectProto( text: string, reviver?: (key: string, value: unknown) => unknown, packageName?: string, ): unknown; declare function normalizeHttpResponse( request: middy.Request, fallbackResponse?: Record, ): Record; declare function createError( code: number, message: string, properties?: Record, ): HttpError; declare function modifyCache(cacheKey: string, value: unknown): void; declare function catchInvalidSignatureException( e: Error & { __type?: string }, client: Client, command: Command, ): Promise; declare function isJsonStructured(text: unknown): boolean; declare const jsonContentTypePattern: RegExp; declare function decodeBody( body: string | null | undefined, isBase64Encoded?: boolean, ): string | null | undefined; declare const lambdaContextKeys: string[]; declare const executionContextKeys: string[]; declare function isExecutionModeDurable(context: LambdaContext): boolean; export type JsonSchemaType = | "string" | "number" | "integer" | "boolean" | "object" | "array"; export type StringRule = { type: "string"; pattern?: string; minLength?: number; maxLength?: number; enum?: readonly string[]; examples?: readonly string[]; }; export type NumberRule = { type: "number" | "integer"; minimum?: number; maximum?: number; exclusiveMinimum?: number; enum?: readonly number[]; examples?: readonly number[]; }; export type BooleanRule = { type: "boolean"; enum?: readonly boolean[]; examples?: readonly boolean[]; }; export type ArrayRule = { type: "array"; items?: OptionSchemaRule; uniqueItems?: boolean; examples?: readonly unknown[]; }; export type ObjectRule = { type: "object"; required?: readonly string[]; properties?: { [key: string]: OptionSchemaRule }; additionalProperties?: boolean | OptionSchemaRule; examples?: readonly object[]; }; export type EnumRule = { enum: readonly unknown[]; type?: JsonSchemaType; examples?: readonly unknown[]; }; export type ConstRule = { const: unknown; examples?: readonly unknown[]; }; export type InstanceofRule = { instanceof: string; examples?: readonly unknown[]; }; export type OneOfRule = { oneOf: readonly OptionSchemaRule[]; examples?: readonly unknown[]; }; export type AllOfRule = { allOf: readonly OptionSchemaRule[]; examples?: readonly unknown[]; }; export type OptionSchemaRule = | StringRule | NumberRule | BooleanRule | ArrayRule | ObjectRule | EnumRule | ConstRule | InstanceofRule | OneOfRule | AllOfRule; export type OptionSchema = ObjectRule; export declare function validateOptions( packageName: string, schema: OptionSchema, options?: Record, ): void;