spiceflow 1.0.8 → 1.1.1
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/README.md +23 -8
- package/dist/benchmark.test.d.ts +2 -0
- package/dist/benchmark.test.d.ts.map +1 -0
- package/dist/benchmark.test.js +8 -0
- package/dist/benchmark.test.js.map +1 -0
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/types.d.ts +1 -1
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/ws.d.ts +1 -1
- package/dist/client/ws.d.ts.map +1 -1
- package/dist/client.test.js +1 -18
- package/dist/client.test.js.map +1 -1
- package/dist/{elysia-fork/context.d.ts → context.d.ts} +8 -7
- package/dist/context.d.ts.map +1 -0
- package/dist/{elysia-fork/context.js.map → context.js.map} +1 -1
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js.map +1 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/middleware.test.d.ts +2 -0
- package/dist/middleware.test.d.ts.map +1 -0
- package/dist/middleware.test.js +99 -0
- package/dist/middleware.test.js.map +1 -0
- package/dist/openapi.d.ts +4 -15
- package/dist/openapi.d.ts.map +1 -1
- package/dist/spiceflow.d.ts +41 -120
- package/dist/spiceflow.d.ts.map +1 -1
- package/dist/spiceflow.js +223 -169
- package/dist/spiceflow.js.map +1 -1
- package/dist/spiceflow.test.js +54 -16
- package/dist/spiceflow.test.js.map +1 -1
- package/dist/types.d.ts +407 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +72 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +69 -0
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/benchmark.test.ts +8 -0
- package/src/client/index.ts +1 -3
- package/src/client/types.ts +6 -13
- package/src/client/ws.ts +1 -1
- package/src/client.test.ts +1 -19
- package/src/context.ts +128 -0
- package/src/index.ts +1 -2
- package/src/middleware.test.ts +107 -0
- package/src/openapi.ts +1 -1
- package/src/spiceflow.test.ts +74 -16
- package/src/spiceflow.ts +324 -391
- package/src/types.test.ts +1 -1
- package/src/types.ts +929 -0
- package/src/utils.ts +84 -0
- package/dist/elysia-fork/context.d.ts.map +0 -1
- package/dist/elysia-fork/error.d.ts.map +0 -1
- package/dist/elysia-fork/error.js.map +0 -1
- package/dist/elysia-fork/types.d.ts +0 -560
- package/dist/elysia-fork/types.d.ts.map +0 -1
- package/dist/elysia-fork/types.js +0 -2
- package/dist/elysia-fork/types.js.map +0 -1
- package/dist/elysia-fork/utils.d.ts +0 -73
- package/dist/elysia-fork/utils.d.ts.map +0 -1
- package/dist/elysia-fork/utils.js +0 -70
- package/dist/elysia-fork/utils.js.map +0 -1
- package/src/elysia-fork/context.ts +0 -166
- package/src/elysia-fork/types.ts +0 -1281
- package/src/elysia-fork/utils.ts +0 -85
- /package/dist/{elysia-fork/context.js → context.js} +0 -0
- /package/dist/{elysia-fork/error.d.ts → error.d.ts} +0 -0
- /package/dist/{elysia-fork/error.js → error.js} +0 -0
- /package/src/{elysia-fork/error.ts → error.ts} +0 -0
package/src/spiceflow.test.ts
CHANGED
|
@@ -20,6 +20,9 @@ test('dynamic route', async () => {
|
|
|
20
20
|
test('GET dynamic route', async () => {
|
|
21
21
|
const res = await new Spiceflow()
|
|
22
22
|
.get('/ids/:id', () => 'hi')
|
|
23
|
+
.post('/ids/:id', ({ params: { id } }) => id, {
|
|
24
|
+
params: z.object({ id: z.string() }),
|
|
25
|
+
})
|
|
23
26
|
.handle(new Request('http://localhost/ids/xxx', { method: 'GET' }))
|
|
24
27
|
expect(res.status).toBe(200)
|
|
25
28
|
expect(await res.json()).toEqual('hi')
|
|
@@ -115,7 +118,7 @@ test('missing route is not found', async () => {
|
|
|
115
118
|
test('state works', async () => {
|
|
116
119
|
const res = await new Spiceflow()
|
|
117
120
|
.state('id', '')
|
|
118
|
-
.
|
|
121
|
+
.use(({ store, request }) => {
|
|
119
122
|
store.id = 'xxx'
|
|
120
123
|
})
|
|
121
124
|
.get('/get', ({ store }) => {
|
|
@@ -210,13 +213,13 @@ test('validate body works, request fails', async () => {
|
|
|
210
213
|
)
|
|
211
214
|
})
|
|
212
215
|
|
|
213
|
-
test('run
|
|
216
|
+
test('run use', async () => {
|
|
214
217
|
const res = await new Spiceflow()
|
|
215
|
-
.
|
|
218
|
+
.use(({ request }) => {
|
|
216
219
|
expect(request.method).toBe('HEAD')
|
|
217
220
|
return new Response('ok', { status: 401 })
|
|
218
221
|
})
|
|
219
|
-
.
|
|
222
|
+
.use(({ request }) => {
|
|
220
223
|
expect(request.method).toBe('HEAD')
|
|
221
224
|
return 'second one'
|
|
222
225
|
})
|
|
@@ -226,13 +229,13 @@ test('run onRequest', async () => {
|
|
|
226
229
|
expect(await res.text()).toBe('ok')
|
|
227
230
|
})
|
|
228
231
|
|
|
229
|
-
test('run
|
|
232
|
+
test('run use', async () => {
|
|
230
233
|
const res = await new Spiceflow()
|
|
231
|
-
.
|
|
234
|
+
.use(({ request }) => {
|
|
232
235
|
expect(request.method).toBe('HEAD')
|
|
233
236
|
return new Response('ok', { status: 401 })
|
|
234
237
|
})
|
|
235
|
-
.
|
|
238
|
+
.use(({ request }) => {
|
|
236
239
|
expect(request.method).toBe('HEAD')
|
|
237
240
|
return 'second one'
|
|
238
241
|
})
|
|
@@ -284,29 +287,84 @@ test('getRouteAndParents', async () => {
|
|
|
284
287
|
),
|
|
285
288
|
)
|
|
286
289
|
|
|
287
|
-
let routers = bfs(app
|
|
290
|
+
let routers = bfs(app)
|
|
288
291
|
let last = routers[routers.length - 1]
|
|
289
292
|
|
|
290
|
-
expect(app['
|
|
293
|
+
expect(app['getAppAndParents'](last).map((x) => x.prefix))
|
|
291
294
|
.toMatchInlineSnapshot(`
|
|
292
295
|
[
|
|
296
|
+
"/one",
|
|
297
|
+
"/two",
|
|
293
298
|
"/three",
|
|
299
|
+
]
|
|
300
|
+
`)
|
|
301
|
+
})
|
|
302
|
+
|
|
303
|
+
test('getAppsInScope include all parent apps', async () => {
|
|
304
|
+
let app = new Spiceflow({ basePath: '/one' })
|
|
305
|
+
.get('/ids/:id', () => 'hi')
|
|
306
|
+
.use(
|
|
307
|
+
new Spiceflow({ basePath: '/two' }).use(
|
|
308
|
+
new Spiceflow({ basePath: '/three' }).use(
|
|
309
|
+
new Spiceflow({ basePath: '/four' })
|
|
310
|
+
.get('/five', () => 'hi')
|
|
311
|
+
.use(({ request }) => {}),
|
|
312
|
+
),
|
|
313
|
+
),
|
|
314
|
+
)
|
|
315
|
+
|
|
316
|
+
let routers = bfs(app)
|
|
317
|
+
let secondLast = routers[routers.length - 2]
|
|
318
|
+
|
|
319
|
+
expect(app['getAppsInScope'](secondLast).map((x) => x.prefix))
|
|
320
|
+
.toMatchInlineSnapshot(`
|
|
321
|
+
[
|
|
322
|
+
"/one",
|
|
294
323
|
"/two",
|
|
324
|
+
"/three",
|
|
325
|
+
]
|
|
326
|
+
`)
|
|
327
|
+
})
|
|
328
|
+
|
|
329
|
+
test('getAppsInScope include all parent apps and non scoped apps', async () => {
|
|
330
|
+
let app = new Spiceflow({ basePath: '/one' })
|
|
331
|
+
.get('/ids/:id', () => 'hi')
|
|
332
|
+
.use(
|
|
333
|
+
new Spiceflow({ basePath: '/two' }).use(
|
|
334
|
+
new Spiceflow({ basePath: '/three' }).use(
|
|
335
|
+
new Spiceflow({ basePath: '/four', scoped: false })
|
|
336
|
+
.get('/five', () => 'hi')
|
|
337
|
+
.use(({ request }) => {}),
|
|
338
|
+
),
|
|
339
|
+
),
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
let routers = bfs(app)
|
|
343
|
+
let secondLast = routers[routers.length - 2]
|
|
344
|
+
|
|
345
|
+
expect(app['getAppsInScope'](secondLast).map((x) => x.prefix))
|
|
346
|
+
.toMatchInlineSnapshot(`
|
|
347
|
+
[
|
|
295
348
|
"/one",
|
|
349
|
+
"/two",
|
|
350
|
+
"/three",
|
|
351
|
+
"/four",
|
|
296
352
|
]
|
|
297
353
|
`)
|
|
298
354
|
})
|
|
355
|
+
|
|
299
356
|
test('use with 2 basPath works', async () => {
|
|
300
357
|
let oneOnReq = false
|
|
301
358
|
let twoOnReq = false
|
|
302
359
|
let onReqCalled: string[] = []
|
|
303
360
|
const app = await new Spiceflow()
|
|
304
|
-
.
|
|
361
|
+
.use(({ request }) => {
|
|
305
362
|
onReqCalled.push('root')
|
|
306
363
|
})
|
|
307
364
|
.use(
|
|
308
365
|
new Spiceflow({ basePath: '/one' })
|
|
309
|
-
|
|
366
|
+
|
|
367
|
+
.use(({ request }) => {
|
|
310
368
|
oneOnReq = true
|
|
311
369
|
onReqCalled.push('one')
|
|
312
370
|
})
|
|
@@ -314,11 +372,11 @@ test('use with 2 basPath works', async () => {
|
|
|
314
372
|
)
|
|
315
373
|
.use(
|
|
316
374
|
new Spiceflow({ basePath: '/two' })
|
|
317
|
-
.
|
|
375
|
+
.use((c) => {
|
|
318
376
|
twoOnReq = true
|
|
319
377
|
onReqCalled.push('two')
|
|
320
378
|
})
|
|
321
|
-
.get('/ids/:id', ({ params }) => params.id),
|
|
379
|
+
.get('/ids/:id', ({ params }) => params.id, {}),
|
|
322
380
|
)
|
|
323
381
|
|
|
324
382
|
{
|
|
@@ -383,7 +441,7 @@ test('errors inside basPath works', async () => {
|
|
|
383
441
|
onErrorTriggered.push('root')
|
|
384
442
|
// return new Response('root', { status: 500 })
|
|
385
443
|
})
|
|
386
|
-
.
|
|
444
|
+
.use(({ request }) => {
|
|
387
445
|
onReqTriggered.push('root')
|
|
388
446
|
// return new Response('root', { status: 500 })
|
|
389
447
|
})
|
|
@@ -394,7 +452,7 @@ test('errors inside basPath works', async () => {
|
|
|
394
452
|
onErrorTriggered.push('two')
|
|
395
453
|
// return new Response('two', { status: 500 })
|
|
396
454
|
})
|
|
397
|
-
.
|
|
455
|
+
.use(({ request }) => {
|
|
398
456
|
onReqTriggered.push('two')
|
|
399
457
|
// return new Response('two', { status: 500 })
|
|
400
458
|
})
|
|
@@ -404,7 +462,7 @@ test('errors inside basPath works', async () => {
|
|
|
404
462
|
onErrorTriggered.push('nested')
|
|
405
463
|
// return new Response('nested', { status: 500 })
|
|
406
464
|
})
|
|
407
|
-
.
|
|
465
|
+
.use(({ request }) => {
|
|
408
466
|
onReqTriggered.push('nested')
|
|
409
467
|
// return new Response('nested', { status: 500 })
|
|
410
468
|
})
|