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