UNPKG

2.88 kBPlain TextView Raw
1import {
2 HandlerEvent as LambdaHandlerEvent,
3 HandlerContext as LambdaHandlerContext,
4 HandlerResponse as LambdaHandlerResponse,
5} from '@netlify/functions'
6
7import * as log from './log'
8import { createEmitter } from './createEmitter'
9import { wrapHandler } from './wrapHandler'
10import { getCurrentPrestaInstance } from './currentPrestaInstance'
11
12export type AWS = {
13 HandlerEvent: LambdaHandlerEvent
14 HandlerContext: LambdaHandlerContext
15 HandlerResponse: LambdaHandlerResponse
16 Handler: (event: LambdaHandlerEvent, context: Partial<LambdaHandlerContext>) => Promise<LambdaHandlerResponse>
17}
18
19export type Callable = (...args: any[]) => void
20
21export type ContextGetter = typeof getCurrentPrestaInstance
22
23export type PluginInterface = any
24export type PluginInit = (context: ContextGetter) => PluginInterface
25export type Plugin = (props: Record<string, unknown>) => PluginInit
26
27export type Config = {
28 files?: string | string[]
29 output?: string
30 assets?: string
31 plugins?: PluginInit[]
32 port?: number
33}
34
35export type CLI = {
36 config?: string
37 debug?: boolean
38 port?: string
39} & Config
40
41export type FunctionsManifest = {
42 [route: string]: string
43}
44
45export type HookPostBuild = {
46 output: Presta['output']
47 staticOutput: Presta['staticOutputDir']
48 functionsOutput: Presta['functionsOutputDir']
49 functionsManifest: FunctionsManifest
50}
51export type HookBuildFile = {
52 file: string
53}
54
55export type DestroyHookCallback = () => void
56export type Hooks = {
57 emitPostBuild(props: HookPostBuild): void
58 onPostBuild(cb: (props: HookPostBuild) => void): DestroyHookCallback
59 emitBuildFile(props: HookBuildFile): void
60 onBuildFile(cb: (props: HookBuildFile) => void): DestroyHookCallback
61 emitBrowserRefresh(): void
62 onBrowserRefresh(cb: () => void): DestroyHookCallback
63}
64
65export type Presta = {
66 pid: number
67 cwd: string
68 env: string
69 port: number
70 debug: boolean
71 configFilepath: string
72 staticOutputDir: string
73 functionsOutputDir: string
74 functionsManifest: string
75 events: ReturnType<typeof createEmitter>
76 hooks: Hooks
77} & Required<Config>
78
79export type RouteParameters = Partial<Record<string, string>>
80export type Event = LambdaHandlerEvent & { routeParameters: RouteParameters }
81export type Context = LambdaHandlerContext
82export type Response = Partial<LambdaHandlerResponse> & {
83 html?: string
84 json?: object
85 xml?: string
86}
87
88export type Route = string
89export type GetStaticPaths = () => Promise<string[]>
90export type Handler = (event: Event, context: Context) => Promise<Response>
91
92export type StaticLambda = {
93 getStaticPaths: GetStaticPaths
94 handler: Handler
95}
96
97export type Lambda = {
98 route: Route
99 handler: Handler
100}
101
102export type PrestaError = Error & {
103 status?: number
104 statusCode?: number
105 source?: string
106 title?: string
107 details?: string
108}
109
110export { getCurrentPrestaInstance }
111export { wrapHandler }
112export const logger = log