forked from alephjs/aleph.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
152 lines (143 loc) · 4.94 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import type { AcceptedPlugin, bufio, Response } from './deps.ts';
/**
* A plugin for **Aleph.js** application.
*/
export interface Plugin {
/** `name` gives the plugin a name. */
name?: string
/** `test` matches the import url. */
test: RegExp
/** `acceptHMR` accepts the HMR. */
acceptHMR?: boolean
/** `transform` transforms the source content. */
transform?(content: Uint8Array, url: string): Promise<{ code: string, map?: string, loader?: 'js' | 'ts' | 'jsx' | 'tsx' | 'css' | 'markdown' }>
}
/**
* The options for **SSR**.
*/
export interface SSROptions {
/** The fallback html **dynamic routes** (default is '**_fallback_spa.html**'). */
fallback?: string
/** A list of RegExp for paths to use **SSR**. */
include?: RegExp[]
/** A list of RegExp for paths to skip **SSR**. */
exclude?: RegExp[]
/** A list of paths for **dynamic routes** in **SSG**. */
staticPaths?: string[]
}
/**
* Config for Aleph.js application.
*/
export interface Config {
/** `framework` to run your application (default is 'react'). */
framework?: 'alef' | 'react'
/** `srcDir` to put your application source code (default is '/'). */
srcDir?: string
/** `outputDir` specifies the output directory for `build` command (default is '**dist**'). */
outputDir?: string
/** `baseUrl` specifies the path prefix for the application (default is '/'). */
baseUrl?: string
/** `reactVersion` specifies the **react version** (default is '17.0.1'). */
reactVersion?: string
/** `defaultLocale` specifies the default locale of the application (default is '**en**'). */
defaultLocale?: string
/** A list of locales. */
locales?: string[]
/** The options for **SSR**. */
ssr?: boolean | SSROptions
/** A list of plugin. */
plugins?: Plugin[]
/** A list of plugin of PostCSS. */
postcss?: { plugins: (string | AcceptedPlugin | [string | ((options: Record<string, any>) => AcceptedPlugin), Record<string, any>])[] }
/** `buildTarget` specifies the build target for **swc** in production mode (default is **es5**). */
buildTarget?: 'es5' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020'
/** `env` appends env variables (use `Deno.env.get(key)` to get an env variable) */
env?: Record<string, string>
}
/**
* A handler to handle api requests.
*
* @param req APIRequest object
*/
export interface APIHandler {
(req: APIRequest): void
}
/**
* The raw request object of http request.
*/
export interface ServerRequest {
readonly url: string
readonly method: string
readonly proto: string
readonly protoMinor: number
readonly protoMajor: number
readonly headers: Headers
readonly conn: Deno.Conn
readonly r: bufio.BufReader
readonly w: bufio.BufWriter
readonly done: Promise<Error | undefined>
readonly contentLength: number | null
readonly body: Deno.Reader
respond(r: Response): Promise<void>
finalize(): Promise<void>
}
/**
* The request object of api request.
*/
export interface APIRequest extends ServerRequest {
readonly pathname: string
readonly params: Record<string, string>
readonly query: URLSearchParams
readonly cookies: ReadonlyMap<string, string>
/** `status` sets response status of the request. */
status(code: number): this
/**
* `addHeader` adds a new value onto an existing response header of the request, or
* adds the header if it does not already exist.
*/
addHeader(key: string, value: string): this
/**
* `setHeader` sets a new value for an existing response header of the request, or adds
* the header if it does not already exist.
*/
setHeader(key: string, value: string): this
/** `removeHeader` removes the value for an existing response header of the request. */
removeHeader(key: string): this
/** `send` replies to the request with any content with type */
send(data: string | Uint8Array | ArrayBuffer, contentType?: string): Promise<void>
/** `json` replies to the request with a json content */
json(data: any): Promise<void>
/** `decodeBody` will return a string, a form-data or any json object */
decodeBody(type: "text"): Promise<string>
decodeBody(type: "json"): Promise<any>
decodeBody(type: "form-data"): Promise<FormDataBody>
}
/**
* The Router object of the routing, you can access it with `useRouter()` hook.
*/
export interface RouterURL {
readonly locale: string
readonly pathname: string
readonly pagePath: string
readonly params: Record<string, string>
readonly query: URLSearchParams
}
/**
* The form data body
*/
export interface FormDataBody {
fields: Record<string, string>;
files: FormFile[];
get(key: string): string | undefined;
getFile(key: string): FormFile | undefined;
}
/**
* The form file data
*/
export interface FormFile {
name: string
content: Uint8Array
contentType: string
filename: string
size: number
}