galbe 0.12.1 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/commands/generate/code/openapi.parser.ts +18 -11
- package/bin/commands/generate/index.ts +3 -1
- package/bin/commands/generate/model.ts +153 -0
- package/bin/commands/generate/spec.ts +7 -5
- package/bin/util.ts +9 -0
- package/package.json +8 -4
- package/src/types.ts +1 -1
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -35
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -23
- package/.github/workflows/build_test.yml +0 -17
- package/.github/workflows/deploy_website.yml +0 -20
- package/.github/workflows/release.yml +0 -39
- package/.prettierrc +0 -10
- package/bun.lock +0 -904
- package/bunfig.toml +0 -2
- package/docs/CONTRIBUTING.md +0 -105
- package/docs/cli.md +0 -343
- package/docs/configuration.md +0 -80
- package/docs/context.md +0 -104
- package/docs/error-handler.md +0 -54
- package/docs/getting-started.md +0 -164
- package/docs/handler.md +0 -119
- package/docs/hooks.md +0 -90
- package/docs/plugins.md +0 -146
- package/docs/router.md +0 -10
- package/docs/routes.md +0 -133
- package/docs/schemas.md +0 -327
- package/test/hooks.test.ts +0 -200
- package/test/parser.test.ts +0 -1358
- package/test/plugins.test.ts +0 -239
- package/test/requests.test.ts +0 -917
- package/test/resources/image.png +0 -0
- package/test/resources/object.badSyntax.json +0 -8
- package/test/resources/object.json +0 -8
- package/test/resources/object.missing.json +0 -6
- package/test/resources/static/chameleon.png +0 -0
- package/test/resources/static/index.html +0 -13
- package/test/resources/static/sub/index.html +0 -13
- package/test/resources/static/sub/other.html +0 -13
- package/test/resources/test.route.comment.ts +0 -58
- package/test/resources/test.route.empty.ts +0 -9
- package/test/responses.test.ts +0 -483
- package/test/routeFiles.test.ts +0 -239
- package/test/router.test.ts +0 -231
- package/test/test.utils.ts +0 -109
- package/test/types.test.ts +0 -909
- package/tsconfig.json +0 -23
package/test/plugins.test.ts
DELETED
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
import { expect, test, describe, afterEach, mock } from 'bun:test'
|
|
2
|
-
import { type Context, Galbe, type GalbePlugin, type Route } from '../src'
|
|
3
|
-
|
|
4
|
-
const port = 7361
|
|
5
|
-
|
|
6
|
-
describe('plugins', async () => {
|
|
7
|
-
const galbe = new Galbe({
|
|
8
|
-
plugin: {
|
|
9
|
-
'dev.galbe.test.init': {
|
|
10
|
-
message: 'Hello Mom!'
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
})
|
|
14
|
-
galbe.get('/plugin', ctx => ctx.query.param)
|
|
15
|
-
galbe.get('/plugin/state', ctx => ctx.state)
|
|
16
|
-
|
|
17
|
-
afterEach(() => {
|
|
18
|
-
galbe.plugins = []
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
test('plugin init', async () => {
|
|
22
|
-
let pluginConfig: any = null
|
|
23
|
-
const plugin: GalbePlugin = {
|
|
24
|
-
name: 'dev.galbe.test.init',
|
|
25
|
-
init: mock(config => {
|
|
26
|
-
pluginConfig = config
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
await galbe.use(plugin)
|
|
31
|
-
expect(plugin.init).toHaveBeenCalledTimes(0)
|
|
32
|
-
|
|
33
|
-
await galbe.listen(port)
|
|
34
|
-
expect(plugin.init).toHaveBeenCalledTimes(1)
|
|
35
|
-
expect(pluginConfig).toEqual({ message: 'Hello Mom!' })
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
test('plugin onFetch, no return', async () => {
|
|
39
|
-
let request: any = null
|
|
40
|
-
const plugin: GalbePlugin = {
|
|
41
|
-
name: 'dev.galbe.test.init',
|
|
42
|
-
onFetch: mock(ctx => {
|
|
43
|
-
request = ctx.request
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
await galbe.use(plugin)
|
|
48
|
-
await galbe.listen(port)
|
|
49
|
-
|
|
50
|
-
expect(plugin.onFetch).toHaveBeenCalledTimes(0)
|
|
51
|
-
|
|
52
|
-
const url = `http://localhost:${port}/plugin?param=hello`
|
|
53
|
-
const resp = await fetch(url)
|
|
54
|
-
|
|
55
|
-
expect(plugin.onFetch).toHaveBeenCalledTimes(1)
|
|
56
|
-
expect(request).toMatchObject({
|
|
57
|
-
method: 'GET',
|
|
58
|
-
url: url
|
|
59
|
-
})
|
|
60
|
-
expect(resp.status).toBe(200)
|
|
61
|
-
expect(await resp.text()).toBe('hello')
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
test('plugin onFetch, return', async () => {
|
|
65
|
-
let response = new Response('🫖', { status: 418 })
|
|
66
|
-
const plugin: GalbePlugin = {
|
|
67
|
-
name: 'dev.galbe.test.init',
|
|
68
|
-
onFetch: mock(() => {
|
|
69
|
-
return response
|
|
70
|
-
})
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
await galbe.use(plugin)
|
|
74
|
-
await galbe.listen(port)
|
|
75
|
-
|
|
76
|
-
expect(plugin.onFetch).toHaveBeenCalledTimes(0)
|
|
77
|
-
|
|
78
|
-
let resp = await fetch(`http://localhost:${port}/plugin`)
|
|
79
|
-
|
|
80
|
-
expect(plugin.onFetch).toHaveBeenCalledTimes(1)
|
|
81
|
-
expect(resp).toEqual(response)
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
test('plugin onRoute, no return', async () => {
|
|
85
|
-
let route: Route | null = null
|
|
86
|
-
const plugin: GalbePlugin = {
|
|
87
|
-
name: 'dev.galbe.test.init',
|
|
88
|
-
onRoute: mock(r => {
|
|
89
|
-
route = r.route
|
|
90
|
-
})
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
await galbe.use(plugin)
|
|
94
|
-
await galbe.listen(port)
|
|
95
|
-
|
|
96
|
-
expect(plugin.onRoute).toHaveBeenCalledTimes(0)
|
|
97
|
-
|
|
98
|
-
let resp = await fetch(`http://localhost:${port}/plugin?param=hello`)
|
|
99
|
-
|
|
100
|
-
expect(plugin.onRoute).toHaveBeenCalledTimes(1)
|
|
101
|
-
expect(route).toMatchObject({
|
|
102
|
-
method: 'get',
|
|
103
|
-
path: `/plugin`,
|
|
104
|
-
hooks: [],
|
|
105
|
-
handler: () => {}
|
|
106
|
-
})
|
|
107
|
-
expect(resp.status).toBe(200)
|
|
108
|
-
expect(await resp.text()).toBe('hello')
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
test('plugin onRoute, return', async () => {
|
|
112
|
-
let response = new Response('🫖', { status: 418 })
|
|
113
|
-
const plugin: GalbePlugin = {
|
|
114
|
-
name: 'dev.galbe.test.init',
|
|
115
|
-
onRoute: mock(() => {
|
|
116
|
-
return response
|
|
117
|
-
})
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
await galbe.use(plugin)
|
|
121
|
-
await galbe.listen(port)
|
|
122
|
-
|
|
123
|
-
expect(plugin.onRoute).toHaveBeenCalledTimes(0)
|
|
124
|
-
|
|
125
|
-
let resp = await fetch(`http://localhost:${port}/plugin`)
|
|
126
|
-
|
|
127
|
-
expect(plugin.onRoute).toHaveBeenCalledTimes(1)
|
|
128
|
-
expect(resp).toEqual(response)
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
test('plugin beforeHandle, no return', async () => {
|
|
132
|
-
let context: Context | undefined
|
|
133
|
-
const plugin: GalbePlugin = {
|
|
134
|
-
name: 'dev.galbe.test.init',
|
|
135
|
-
beforeHandle: mock((ctx: Context) => {
|
|
136
|
-
context = ctx
|
|
137
|
-
})
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
await galbe.use(plugin)
|
|
141
|
-
await galbe.listen(port)
|
|
142
|
-
|
|
143
|
-
expect(plugin.beforeHandle).toHaveBeenCalledTimes(0)
|
|
144
|
-
|
|
145
|
-
const url = `http://localhost:${port}/plugin?param=hello`
|
|
146
|
-
let resp = await fetch(url)
|
|
147
|
-
|
|
148
|
-
expect(plugin.beforeHandle).toHaveBeenCalledTimes(1)
|
|
149
|
-
expect(context?.request).toMatchObject({
|
|
150
|
-
method: 'GET',
|
|
151
|
-
url: url
|
|
152
|
-
})
|
|
153
|
-
expect(context?.query).toEqual({
|
|
154
|
-
param: 'hello'
|
|
155
|
-
})
|
|
156
|
-
expect(context?.body).toBeNull()
|
|
157
|
-
expect(resp.status).toBe(200)
|
|
158
|
-
expect(await resp.text()).toBe('hello')
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
test('plugin beforeHandle, return', async () => {
|
|
162
|
-
let response = new Response('🫖', { status: 418 })
|
|
163
|
-
const plugin: GalbePlugin = {
|
|
164
|
-
name: 'dev.galbe.test.init',
|
|
165
|
-
beforeHandle: mock(() => {
|
|
166
|
-
return response
|
|
167
|
-
})
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
await galbe.use(plugin)
|
|
171
|
-
await galbe.listen(port)
|
|
172
|
-
|
|
173
|
-
expect(plugin.beforeHandle).toHaveBeenCalledTimes(0)
|
|
174
|
-
|
|
175
|
-
let resp = await fetch(`http://localhost:${port}/plugin`)
|
|
176
|
-
|
|
177
|
-
expect(plugin.beforeHandle).toHaveBeenCalledTimes(1)
|
|
178
|
-
expect(resp).toEqual(response)
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
test('plugin afterHandle, no return', async () => {
|
|
182
|
-
let response: Response | undefined
|
|
183
|
-
const plugin: GalbePlugin = {
|
|
184
|
-
name: 'dev.galbe.test.init',
|
|
185
|
-
afterHandle: mock((resp: Response) => {
|
|
186
|
-
response = resp
|
|
187
|
-
})
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
await galbe.use(plugin)
|
|
191
|
-
await galbe.listen(port)
|
|
192
|
-
|
|
193
|
-
expect(plugin.afterHandle).toHaveBeenCalledTimes(0)
|
|
194
|
-
|
|
195
|
-
const url = `http://localhost:${port}/plugin?param=hello`
|
|
196
|
-
let resp = await fetch(url)
|
|
197
|
-
|
|
198
|
-
expect(plugin.afterHandle).toHaveBeenCalledTimes(1)
|
|
199
|
-
expect(response).toEqual(resp)
|
|
200
|
-
})
|
|
201
|
-
|
|
202
|
-
test('plugin afterHandle, return', async () => {
|
|
203
|
-
let response = new Response('🫖', { status: 418 })
|
|
204
|
-
const plugin: GalbePlugin = {
|
|
205
|
-
name: 'dev.galbe.test.init',
|
|
206
|
-
afterHandle: mock(() => {
|
|
207
|
-
return response
|
|
208
|
-
})
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
await galbe.use(plugin)
|
|
212
|
-
await galbe.listen(port)
|
|
213
|
-
|
|
214
|
-
expect(plugin.afterHandle).toHaveBeenCalledTimes(0)
|
|
215
|
-
|
|
216
|
-
let resp = await fetch(`http://localhost:${port}/plugin`)
|
|
217
|
-
|
|
218
|
-
expect(plugin.afterHandle).toHaveBeenCalledTimes(1)
|
|
219
|
-
expect(resp).toEqual(response)
|
|
220
|
-
})
|
|
221
|
-
|
|
222
|
-
test('plugin add state to context', async () => {
|
|
223
|
-
const plugin: GalbePlugin = {
|
|
224
|
-
name: 'dev.galbe.test.init',
|
|
225
|
-
beforeHandle: mock((ctx: Context) => {
|
|
226
|
-
ctx.state.foo = 'bar'
|
|
227
|
-
})
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
await galbe.use(plugin)
|
|
231
|
-
await galbe.listen(port)
|
|
232
|
-
|
|
233
|
-
const url = `http://localhost:${port}/plugin/state`
|
|
234
|
-
let resp = await fetch(url)
|
|
235
|
-
|
|
236
|
-
expect(resp.status).toBe(200)
|
|
237
|
-
expect(await resp.json()).toEqual({ foo: 'bar' })
|
|
238
|
-
})
|
|
239
|
-
})
|