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.
- package/README.md +147 -0
- package/dist/client/index.d.ts +4 -3
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +5 -5
- package/dist/client/index.js.map +1 -1
- package/dist/client/types.d.ts +4 -5
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/ws.d.ts +4 -4
- package/dist/client/ws.d.ts.map +1 -1
- package/dist/client/ws.js.map +1 -1
- package/dist/client.test.js +9 -8
- package/dist/client.test.js.map +1 -1
- package/dist/elysia-fork/error.d.ts +5 -65
- package/dist/elysia-fork/error.d.ts.map +1 -1
- package/dist/elysia-fork/error.js +2 -2
- package/dist/elysia-fork/error.js.map +1 -1
- package/dist/elysia-fork/types.d.ts +27 -116
- package/dist/elysia-fork/types.d.ts.map +1 -1
- package/dist/elysia-fork/types.js +1 -2
- package/dist/elysia-fork/types.js.map +1 -1
- package/dist/elysia-fork/utils.d.ts +1 -62
- package/dist/elysia-fork/utils.d.ts.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/openapi.d.ts +68 -0
- package/dist/openapi.d.ts.map +1 -0
- package/dist/openapi.js +250 -0
- package/dist/openapi.js.map +1 -0
- package/dist/spiceflow.d.ts +48 -52
- package/dist/spiceflow.d.ts.map +1 -1
- package/dist/spiceflow.js +148 -87
- package/dist/spiceflow.js.map +1 -1
- package/dist/spiceflow.test.js +80 -43
- package/dist/spiceflow.test.js.map +1 -1
- package/dist/stream.test.js +14 -14
- package/dist/stream.test.js.map +1 -1
- package/dist/zod.test.d.ts +2 -0
- package/dist/zod.test.d.ts.map +1 -0
- package/dist/zod.test.js +59 -0
- package/dist/zod.test.js.map +1 -0
- package/package.json +7 -4
- package/src/client/index.ts +10 -8
- package/src/client/types.ts +4 -4
- package/src/client/ws.ts +4 -4
- package/src/client.test.ts +9 -8
- package/src/elysia-fork/context.ts +2 -2
- package/src/elysia-fork/error.ts +3 -3
- package/src/elysia-fork/types.ts +108 -284
- package/src/index.ts +2 -0
- package/src/openapi.ts +426 -0
- package/src/spiceflow.test.ts +117 -64
- package/src/spiceflow.ts +261 -179
- package/src/stream.test.ts +14 -14
- package/src/zod.test.ts +71 -0
package/src/stream.test.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { describe, it, expect } from 'vitest'
|
|
|
2
2
|
|
|
3
3
|
import { createParser } from 'eventsource-parser'
|
|
4
4
|
|
|
5
|
-
import {
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
309
|
+
const app = new Spiceflow().get('/', async function* () {
|
|
310
310
|
yield expected[0]
|
|
311
311
|
await sleep(10)
|
|
312
312
|
|
package/src/zod.test.ts
ADDED
|
@@ -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
|
+
})
|