Skip to content

feat: add types for streamingCma to FunctionEventContext [EXT-6173] #766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/requests/typings/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,31 @@ export type AppActionRequest<

export type AppActionResponse = void | Record<string, unknown>

// Recursively convert PlainClientAPI return types to Promise<ReadableStream>
type ConvertToStreamingAPI<T> = {
[K in keyof T]: T[K] extends (...args: infer A) => Promise<infer R>
? (...args: A) => Promise<ReadableStream<R>>
: T[K] extends Record<string, any>
? ConvertToStreamingAPI<T[K]>
: T[K]
}
export type StreamingPlainClientAPI = ConvertToStreamingAPI<PlainClientAPI>

/**
* P: Possibility to type app installation parameters
*/
export type FunctionEventContext<P extends Record<string, any> = Record<string, any>> = {
spaceId: string
environmentId: string
appInstallationParameters: P
/**
* The `cma` client is the **default** client for Contentful Management API requests.
*/
cma?: PlainClientAPI
/**
* The `streamingCma` client should be used when processing **big** entries.
*/
streamingCma?: StreamingPlainClientAPI
}

/**
Expand Down