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