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.
Files changed (61) hide show
  1. package/README.md +177 -92
  2. package/dist/benchmark.benchmark.js.map +1 -1
  3. package/dist/client/errors.d.ts.map +1 -1
  4. package/dist/client/errors.js.map +1 -1
  5. package/dist/client/index.d.ts.map +1 -1
  6. package/dist/client/index.js +8 -12
  7. package/dist/client/index.js.map +1 -1
  8. package/dist/client/types.d.ts.map +1 -1
  9. package/dist/client/utils.js.map +1 -1
  10. package/dist/client/ws.d.ts.map +1 -1
  11. package/dist/client/ws.js +1 -3
  12. package/dist/client/ws.js.map +1 -1
  13. package/dist/client.test.js.map +1 -1
  14. package/dist/context.d.ts.map +1 -1
  15. package/dist/cors.d.ts.map +1 -1
  16. package/dist/cors.js.map +1 -1
  17. package/dist/cors.test.js.map +1 -1
  18. package/dist/error.d.ts.map +1 -1
  19. package/dist/error.js.map +1 -1
  20. package/dist/middleware.test.js +65 -0
  21. package/dist/middleware.test.js.map +1 -1
  22. package/dist/openapi.d.ts.map +1 -1
  23. package/dist/openapi.js +1 -1
  24. package/dist/openapi.js.map +1 -1
  25. package/dist/openapi.test.js.map +1 -1
  26. package/dist/spiceflow.d.ts.map +1 -1
  27. package/dist/spiceflow.js +12 -5
  28. package/dist/spiceflow.js.map +1 -1
  29. package/dist/spiceflow.test.js.map +1 -1
  30. package/dist/stream.test.js +6 -6
  31. package/dist/stream.test.js.map +1 -1
  32. package/dist/types.d.ts +1 -1
  33. package/dist/types.d.ts.map +1 -1
  34. package/dist/types.js.map +1 -1
  35. package/dist/types.test.js +56 -6
  36. package/dist/types.test.js.map +1 -1
  37. package/dist/utils.d.ts.map +1 -1
  38. package/dist/utils.js.map +1 -1
  39. package/dist/zod.test.js.map +1 -1
  40. package/package.json +1 -1
  41. package/src/benchmark.benchmark.ts +8 -8
  42. package/src/client/errors.ts +17 -17
  43. package/src/client/index.ts +437 -469
  44. package/src/client/types.ts +168 -191
  45. package/src/client/utils.ts +5 -5
  46. package/src/client/ws.ts +87 -89
  47. package/src/client.test.ts +176 -183
  48. package/src/context.ts +82 -82
  49. package/src/cors.test.ts +38 -38
  50. package/src/cors.ts +87 -92
  51. package/src/error.ts +13 -13
  52. package/src/middleware.test.ts +221 -149
  53. package/src/openapi.test.ts +97 -97
  54. package/src/openapi.ts +365 -365
  55. package/src/spiceflow.test.ts +461 -467
  56. package/src/spiceflow.ts +1117 -1157
  57. package/src/stream.test.ts +310 -310
  58. package/src/types.test.ts +59 -39
  59. package/src/types.ts +698 -701
  60. package/src/utils.ts +79 -79
  61. 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
- function nonSpiceflowReturn() {
10
- return new Spiceflow() as any
11
- }
12
- const app = new Spiceflow()
13
- .use(nonSpiceflowReturn())
14
- .post('/xxx', () => 'hi')
15
- const res = await app.handle(
16
- new Request('http://localhost/xxx', { method: 'POST' }),
17
- )
18
-
19
- let client = createSpiceflowClient(app)
20
-
21
- type ClientType = Prettify<typeof client>
22
- // @ts-expect-error
23
- client.something
24
-
25
- client.xxx.post()
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
- function nonSpiceflowReturn() {
31
- return new Spiceflow().post('/usePost', () => 'hi')
32
- }
33
- const app = new Spiceflow()
34
- .use(nonSpiceflowReturn())
35
- .post('/xxx', () => 'hi')
36
- const res = await app.handle(
37
- new Request('http://localhost/xxx', { method: 'POST' }),
38
- )
39
-
40
- let client = createSpiceflowClient(app)
41
- client.xxx.post()
42
- client.usePost.post()
43
-
44
- type ClientType = Prettify<typeof client>
45
- // @ts-expect-error
46
- client.something
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
+ })