spiceflow 1.0.0 → 1.0.2

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.
Files changed (56) hide show
  1. package/README.md +147 -0
  2. package/dist/client/index.d.ts +4 -3
  3. package/dist/client/index.d.ts.map +1 -1
  4. package/dist/client/index.js +5 -5
  5. package/dist/client/index.js.map +1 -1
  6. package/dist/client/types.d.ts +4 -5
  7. package/dist/client/types.d.ts.map +1 -1
  8. package/dist/client/ws.d.ts +4 -4
  9. package/dist/client/ws.d.ts.map +1 -1
  10. package/dist/client/ws.js.map +1 -1
  11. package/dist/client.test.js +9 -8
  12. package/dist/client.test.js.map +1 -1
  13. package/dist/elysia-fork/error.d.ts +5 -65
  14. package/dist/elysia-fork/error.d.ts.map +1 -1
  15. package/dist/elysia-fork/error.js +2 -2
  16. package/dist/elysia-fork/error.js.map +1 -1
  17. package/dist/elysia-fork/types.d.ts +27 -116
  18. package/dist/elysia-fork/types.d.ts.map +1 -1
  19. package/dist/elysia-fork/types.js +1 -2
  20. package/dist/elysia-fork/types.js.map +1 -1
  21. package/dist/elysia-fork/utils.d.ts +1 -62
  22. package/dist/elysia-fork/utils.d.ts.map +1 -1
  23. package/dist/index.d.ts +3 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +2 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/openapi.d.ts +68 -0
  28. package/dist/openapi.d.ts.map +1 -0
  29. package/dist/openapi.js +250 -0
  30. package/dist/openapi.js.map +1 -0
  31. package/dist/spiceflow.d.ts +48 -52
  32. package/dist/spiceflow.d.ts.map +1 -1
  33. package/dist/spiceflow.js +148 -87
  34. package/dist/spiceflow.js.map +1 -1
  35. package/dist/spiceflow.test.js +80 -43
  36. package/dist/spiceflow.test.js.map +1 -1
  37. package/dist/stream.test.js +14 -14
  38. package/dist/stream.test.js.map +1 -1
  39. package/dist/zod.test.d.ts +2 -0
  40. package/dist/zod.test.d.ts.map +1 -0
  41. package/dist/zod.test.js +59 -0
  42. package/dist/zod.test.js.map +1 -0
  43. package/package.json +7 -4
  44. package/src/client/index.ts +10 -8
  45. package/src/client/types.ts +4 -4
  46. package/src/client/ws.ts +4 -4
  47. package/src/client.test.ts +9 -8
  48. package/src/elysia-fork/context.ts +2 -2
  49. package/src/elysia-fork/error.ts +3 -3
  50. package/src/elysia-fork/types.ts +108 -284
  51. package/src/index.ts +2 -0
  52. package/src/openapi.ts +426 -0
  53. package/src/spiceflow.test.ts +117 -64
  54. package/src/spiceflow.ts +261 -179
  55. package/src/stream.test.ts +14 -14
  56. package/src/zod.test.ts +71 -0
@@ -2,7 +2,7 @@ import { describe, it, expect } from 'vitest'
2
2
 
3
3
  import { createParser } from 'eventsource-parser'
4
4
 
5
- import { Elysia } from './spiceflow'
5
+ import { Spiceflow } from './spiceflow'
6
6
 
7
7
  import { req, sleep } from './utils'
8
8
 
@@ -21,7 +21,7 @@ describe('Stream', () => {
21
21
  it('handle stream', async () => {
22
22
  const expected = ['a', 'b', 'c']
23
23
 
24
- const app = new Elysia().get('/', async function* () {
24
+ const app = new Spiceflow().get('/', async function* () {
25
25
  yield 'a'
26
26
  await sleep(10)
27
27
 
@@ -60,7 +60,7 @@ describe('Stream', () => {
60
60
  expect(response).toBe(textEventStream(['a', 'b', 'c']))
61
61
  })
62
62
  it('handle errors after yield', async () => {
63
- const app = new Elysia().get('/', async function* () {
63
+ const app = new Spiceflow().get('/', async function* () {
64
64
  yield 'a'
65
65
  await sleep(10)
66
66
 
@@ -75,7 +75,7 @@ describe('Stream', () => {
75
75
  })
76
76
 
77
77
  it('handle errors before yield when aot is false', async () => {
78
- const app = new Elysia()
78
+ const app = new Spiceflow()
79
79
  .onError(({ error }) => {
80
80
  return new Response(error.message)
81
81
  })
@@ -89,7 +89,7 @@ describe('Stream', () => {
89
89
  })
90
90
 
91
91
  it.todo('handle errors before yield when aot is true', async () => {
92
- const app = new Elysia()
92
+ const app = new Spiceflow()
93
93
  .onError(({ error }) => {
94
94
  return new Response(error.message)
95
95
  })
@@ -104,7 +104,7 @@ describe('Stream', () => {
104
104
 
105
105
  it.todo('handle errors before yield with onError', async () => {
106
106
  const expected = 'error expected'
107
- const app = new Elysia()
107
+ const app = new Spiceflow()
108
108
  .onError(({}) => {
109
109
  return new Response(expected)
110
110
  })
@@ -120,7 +120,7 @@ describe('Stream', () => {
120
120
  it('stop stream on canceled request', async () => {
121
121
  const expected = ['a', 'b']
122
122
 
123
- const app = new Elysia().get('/', async function* () {
123
+ const app = new Spiceflow().get('/', async function* () {
124
124
  yield 'a'
125
125
  await sleep(10)
126
126
 
@@ -174,7 +174,7 @@ describe('Stream', () => {
174
174
  // it('mutate set before yield is called', async () => {
175
175
  // const expected = ['a', 'b', 'c']
176
176
 
177
- // const app = new Elysia().get('/', function* () {
177
+ // const app = new Spiceflow().get('/', function* () {
178
178
  // set.headers['access-control-allow-origin'] = 'http://saltyaom.com'
179
179
 
180
180
  // yield 'a'
@@ -195,7 +195,7 @@ describe('Stream', () => {
195
195
  { data: [1, 2, 3] },
196
196
  { result: [4, 5, 6] }
197
197
  ]
198
- const app = new Elysia().get('/', async function* ({}) {
198
+ const app = new Spiceflow().get('/', async function* ({}) {
199
199
  for (const obj of objects) {
200
200
  yield obj
201
201
  }
@@ -228,7 +228,7 @@ describe('Stream', () => {
228
228
  // it('mutate set before yield is called', async () => {
229
229
  // const expected = ['a', 'b', 'c']
230
230
 
231
- // const app = new Elysia().get('/', function* () {
231
+ // const app = new Spiceflow().get('/', function* () {
232
232
  // set.headers['access-control-allow-origin'] = 'http://saltyaom.com'
233
233
 
234
234
  // yield 'a'
@@ -246,7 +246,7 @@ describe('Stream', () => {
246
246
  // it('async mutate set before yield is called', async () => {
247
247
  // const expected = ['a', 'b', 'c']
248
248
 
249
- // const app = new Elysia().get('/', async function* () {
249
+ // const app = new Spiceflow().get('/', async function* () {
250
250
  // set.headers['access-control-allow-origin'] = 'http://saltyaom.com'
251
251
 
252
252
  // yield 'a'
@@ -262,7 +262,7 @@ describe('Stream', () => {
262
262
  // })
263
263
 
264
264
  it('return value if not yield', async () => {
265
- const app = new Elysia()
265
+ const app = new Spiceflow()
266
266
  .get('/', function* () {
267
267
  return 'hello'
268
268
  })
@@ -282,7 +282,7 @@ describe('Stream', () => {
282
282
  })
283
283
 
284
284
  it('return async value if not yield', async () => {
285
- const app = new Elysia()
285
+ const app = new Spiceflow()
286
286
  .get('/', function* () {
287
287
  return 'hello'
288
288
  })
@@ -306,7 +306,7 @@ describe('Stream', () => {
306
306
  const expectedResponse = JSON.stringify([...expected])
307
307
  let i = 0
308
308
 
309
- const app = new Elysia().get('/', async function* () {
309
+ const app = new Spiceflow().get('/', async function* () {
310
310
  yield expected[0]
311
311
  await sleep(10)
312
312
 
@@ -0,0 +1,71 @@
1
+ import { test, describe, expect } from 'vitest'
2
+ import { Type } from '@sinclair/typebox'
3
+ import { Spiceflow } from './spiceflow'
4
+ import { req } from './utils'
5
+ import { z } from 'zod'
6
+
7
+ test('body is parsed as json', async () => {
8
+ let name = ''
9
+ const res = await new Spiceflow()
10
+ .state('id', '')
11
+
12
+ .post(
13
+ '/post',
14
+ (c) => {
15
+ name = c.body.name
16
+ // @ts-expect-error
17
+ c.body.nonExistingField
18
+ return {
19
+ name,
20
+ nameEcho: c.body.name,
21
+ // add: 3,
22
+ }
23
+ },
24
+ {
25
+ body: z.object({
26
+ name: z.string(),
27
+ }),
28
+ response: z.object({
29
+ name: z.string(),
30
+ nameEcho: z.string(),
31
+ }),
32
+ },
33
+ )
34
+ .post(
35
+ '/post2',
36
+ (c) => {
37
+ name = c.body.name
38
+ // @ts-expect-error
39
+ c.body.nonExistingField
40
+ return {
41
+ name,
42
+ nameEcho: c.body.name,
43
+ }
44
+ },
45
+ {
46
+ body: z.object({
47
+ name: z.string(),
48
+ }),
49
+ response: {
50
+ 200: z.object({
51
+ name: z.string(),
52
+ nameEcho: z.string(),
53
+ }),
54
+ 400: z.object({
55
+ errorMessage: z.string(),
56
+ }),
57
+ },
58
+ },
59
+ )
60
+ .handle(
61
+ req('/post', {
62
+ method: 'POST',
63
+ headers: {
64
+ 'content-type': 'application/json',
65
+ },
66
+ body: JSON.stringify({ name: 'John' }),
67
+ }),
68
+ )
69
+ expect(res.status).toBe(200)
70
+ expect(await res.json()).toEqual({ name: 'John', nameEcho: 'John' })
71
+ })