Skip to content

Commit

Permalink
feat: update typings
Browse files Browse the repository at this point in the history
  • Loading branch information
cemreyuksel committed Jan 25, 2024
1 parent 26992f6 commit 6031dee
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export type {
AppActionCallContext,
CanonicalRequest,
SignedRequestHeaders,
DeliveryFunctionEventContext,
DeliveryFunctionEventHandler,
DeliveryFunctionEventType,
DeliveryFunctionEvent,
FunctionEventContext,
FunctionEventHandler,
FunctionEventType,
FunctionEvent,
} from './requests'
8 changes: 4 additions & 4 deletions src/requests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ export { ContentfulHeader, ContentfulContextHeader } from './typings'
export type {
AppActionCallContext,
CanonicalRequest,
DeliveryFunctionEvent,
DeliveryFunctionEventContext,
DeliveryFunctionEventHandler,
DeliveryFunctionEventType,
FunctionEvent,
FunctionEventContext,
FunctionEventHandler,
FunctionEventType,
SignedRequestWithContextHeadersWithApp,
SignedRequestWithContextHeadersWithUser,
SignedRequestWithoutContextHeaders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ export type GraphQLQueryResponse = {
/**
* P: Possibility to type app installation parameters
*/
export type DeliveryFunctionEventContext<P extends Record<string, any> = Record<string, any>> = {
export type FunctionEventContext<P extends Record<string, any> = Record<string, any>> = {
spaceId: string
environmentId: string
appInstallationParameters: P
}

type DeliveryFunctionEventHandlers = {
type FunctionEventHandlers = {
[GRAPHQL_FIELD_MAPPING_EVENT]: {
event: GraphQLFieldTypeMappingRequest
response: GraphQLFieldTypeMappingResponse
Expand All @@ -65,22 +65,22 @@ type DeliveryFunctionEventHandlers = {
}
}

export type DeliveryFunctionEvent = GraphQLFieldTypeMappingRequest | GraphQLQueryRequest
export type DeliveryFunctionEventType = keyof DeliveryFunctionEventHandlers
export type FunctionEvent = GraphQLFieldTypeMappingRequest | GraphQLQueryRequest
export type FunctionEventType = keyof FunctionEventHandlers

/**
* Event handler type that needs to be exported as `handler` from your delivery function.
* e.g. `const handler: DeliveryFunctionEventHandler = (event, context) => { ... }`
* Event handler type that needs to be exported as `handler` from your function.
* e.g. `const handler: FunctionEventHandler = (event, context) => { ... }`
*
* This type can also be used to construct helper functions for specific events
* e.g. `const queryHandler: DeliveryFunctionEventHandler<'graphql.query'> = (event, context) => { ... }
* e.g. `const queryHandler: FunctionEventHandler<'graphql.query'> = (event, context) => { ... }
*/
export type DeliveryFunctionEventHandler<
K extends DeliveryFunctionEventType = DeliveryFunctionEventType,
export type FunctionEventHandler<
K extends FunctionEventType = FunctionEventType,
P extends Record<string, any> = Record<string, any>,
> = (
event: DeliveryFunctionEventHandlers[K]['event'],
context: DeliveryFunctionEventContext<P>,
event: FunctionEventHandlers[K]['event'],
context: FunctionEventContext<P>,
) =>
| Promise<DeliveryFunctionEventHandlers[K]['response']>
| DeliveryFunctionEventHandlers[K]['response']
| Promise<FunctionEventHandlers[K]['response']>
| FunctionEventHandlers[K]['response']
2 changes: 1 addition & 1 deletion src/requests/typings/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './appAction'
export * from './deliveryFunction'
export * from './function'
export * from './request'
export * from './validators'

0 comments on commit 6031dee

Please sign in to comment.