spiceflow 1.1.7 → 1.1.9
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 +177 -92
- package/dist/benchmark.benchmark.js.map +1 -1
- package/dist/client/errors.d.ts.map +1 -1
- package/dist/client/errors.js.map +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +8 -12
- package/dist/client/index.js.map +1 -1
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/utils.js.map +1 -1
- package/dist/client/ws.d.ts.map +1 -1
- package/dist/client/ws.js +1 -3
- package/dist/client/ws.js.map +1 -1
- package/dist/client.test.js.map +1 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/cors.d.ts.map +1 -1
- package/dist/cors.js.map +1 -1
- package/dist/cors.test.js.map +1 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js.map +1 -1
- package/dist/middleware.test.js +65 -0
- package/dist/middleware.test.js.map +1 -1
- package/dist/openapi.d.ts.map +1 -1
- package/dist/openapi.js +1 -1
- package/dist/openapi.js.map +1 -1
- package/dist/openapi.test.js.map +1 -1
- package/dist/spiceflow.d.ts.map +1 -1
- package/dist/spiceflow.js +12 -5
- package/dist/spiceflow.js.map +1 -1
- package/dist/spiceflow.test.js.map +1 -1
- package/dist/stream.test.js +6 -6
- package/dist/stream.test.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/types.test.js +56 -6
- package/dist/types.test.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js.map +1 -1
- package/dist/zod.test.js.map +1 -1
- package/package.json +1 -1
- package/src/benchmark.benchmark.ts +8 -8
- package/src/client/errors.ts +17 -17
- package/src/client/index.ts +437 -469
- package/src/client/types.ts +168 -191
- package/src/client/utils.ts +5 -5
- package/src/client/ws.ts +87 -89
- package/src/client.test.ts +176 -183
- package/src/context.ts +82 -82
- package/src/cors.test.ts +38 -38
- package/src/cors.ts +87 -92
- package/src/error.ts +13 -13
- package/src/middleware.test.ts +221 -149
- package/src/openapi.test.ts +97 -97
- package/src/openapi.ts +365 -365
- package/src/spiceflow.test.ts +461 -467
- package/src/spiceflow.ts +1117 -1157
- package/src/stream.test.ts +310 -310
- package/src/types.test.ts +59 -39
- package/src/types.ts +698 -701
- package/src/utils.ts +79 -79
- package/src/zod.test.ts +64 -64
package/src/types.test.ts
CHANGED
|
@@ -6,46 +6,66 @@ import { createSpiceflowClient } from './client/index.js'
|
|
|
6
6
|
import { Prettify } from './types.js'
|
|
7
7
|
|
|
8
8
|
test('`use` on non Spiceflow return', async () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
expect(res.status).toBe(200)
|
|
27
|
-
expect(await res.json()).toEqual('hi')
|
|
9
|
+
function nonSpiceflowReturn() {
|
|
10
|
+
return new Spiceflow() as any
|
|
11
|
+
}
|
|
12
|
+
const app = new Spiceflow().use(nonSpiceflowReturn()).post('/xxx', () => 'hi')
|
|
13
|
+
const res = await app.handle(
|
|
14
|
+
new Request('http://localhost/xxx', { method: 'POST' }),
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
let client = createSpiceflowClient(app)
|
|
18
|
+
|
|
19
|
+
type ClientType = Prettify<typeof client>
|
|
20
|
+
// @ts-expect-error
|
|
21
|
+
client.something
|
|
22
|
+
|
|
23
|
+
client.xxx.post()
|
|
24
|
+
expect(res.status).toBe(200)
|
|
25
|
+
expect(await res.json()).toEqual('hi')
|
|
28
26
|
})
|
|
29
27
|
test('`use` on Spiceflow return', async () => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
expect(res.status).toBe(200)
|
|
49
|
-
expect(await res.json()).toEqual('hi')
|
|
28
|
+
function nonSpiceflowReturn() {
|
|
29
|
+
return new Spiceflow().post('/usePost', () => 'hi')
|
|
30
|
+
}
|
|
31
|
+
const app = new Spiceflow().use(nonSpiceflowReturn()).post('/xxx', () => 'hi')
|
|
32
|
+
const res = await app.handle(
|
|
33
|
+
new Request('http://localhost/xxx', { method: 'POST' }),
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
let client = createSpiceflowClient(app)
|
|
37
|
+
client.xxx.post()
|
|
38
|
+
client.usePost.post()
|
|
39
|
+
|
|
40
|
+
type ClientType = Prettify<typeof client>
|
|
41
|
+
// @ts-expect-error
|
|
42
|
+
client.something
|
|
43
|
+
|
|
44
|
+
expect(res.status).toBe(200)
|
|
45
|
+
expect(await res.json()).toEqual('hi')
|
|
50
46
|
})
|
|
51
47
|
|
|
48
|
+
test('async generator type with client', async () => {
|
|
49
|
+
const app = new Spiceflow().get('/stream', async function* () {
|
|
50
|
+
yield { message: 'Hello' }
|
|
51
|
+
yield { message: 'World' }
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
const client = createSpiceflowClient(app)
|
|
55
|
+
|
|
56
|
+
const streamResponse = await client.stream.get()
|
|
57
|
+
if (streamResponse.error) {
|
|
58
|
+
throw streamResponse.error
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Type check: each yielded item should have the 'message' property
|
|
62
|
+
for await (const item of streamResponse.data) {
|
|
63
|
+
// @ts-expect-error
|
|
64
|
+
item.something
|
|
65
|
+
|
|
66
|
+
item.message
|
|
67
|
+
|
|
68
|
+
expect(item).toHaveProperty('message')
|
|
69
|
+
expect(typeof item.message).toBe('string')
|
|
70
|
+
}
|
|
71
|
+
})
|