spiceflow 1.0.1 → 1.0.3

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 (42) hide show
  1. package/README.md +148 -1
  2. package/dist/client/index.d.ts.map +1 -1
  3. package/dist/client/types.d.ts +2 -6
  4. package/dist/client/types.d.ts.map +1 -1
  5. package/dist/client.test.js +26 -22
  6. package/dist/client.test.js.map +1 -1
  7. package/dist/elysia-fork/context.d.ts +6 -22
  8. package/dist/elysia-fork/context.d.ts.map +1 -1
  9. package/dist/elysia-fork/error.d.ts +2 -226
  10. package/dist/elysia-fork/error.d.ts.map +1 -1
  11. package/dist/elysia-fork/error.js +13 -166
  12. package/dist/elysia-fork/error.js.map +1 -1
  13. package/dist/elysia-fork/types.d.ts +20 -30
  14. package/dist/elysia-fork/types.d.ts.map +1 -1
  15. package/dist/elysia-fork/types.js +1 -2
  16. package/dist/elysia-fork/types.js.map +1 -1
  17. package/dist/elysia-fork/utils.d.ts +1 -62
  18. package/dist/elysia-fork/utils.d.ts.map +1 -1
  19. package/dist/openapi.d.ts +67 -0
  20. package/dist/openapi.d.ts.map +1 -0
  21. package/dist/openapi.js +250 -0
  22. package/dist/openapi.js.map +1 -0
  23. package/dist/spiceflow.d.ts +35 -23
  24. package/dist/spiceflow.d.ts.map +1 -1
  25. package/dist/spiceflow.js +214 -111
  26. package/dist/spiceflow.js.map +1 -1
  27. package/dist/spiceflow.test.js +135 -31
  28. package/dist/spiceflow.test.js.map +1 -1
  29. package/dist/zod.test.d.ts +2 -0
  30. package/dist/zod.test.d.ts.map +1 -0
  31. package/dist/zod.test.js +61 -0
  32. package/dist/zod.test.js.map +1 -0
  33. package/package.json +7 -3
  34. package/src/client/types.ts +14 -19
  35. package/src/client.test.ts +34 -25
  36. package/src/elysia-fork/context.ts +19 -49
  37. package/src/elysia-fork/error.ts +6 -259
  38. package/src/elysia-fork/types.ts +115 -188
  39. package/src/openapi.ts +426 -0
  40. package/src/spiceflow.test.ts +188 -51
  41. package/src/spiceflow.ts +312 -183
  42. package/src/zod.test.ts +73 -0
@@ -0,0 +1,73 @@
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
+ async (c) => {
15
+ const body = await c.request.json()
16
+ name = body.name
17
+ // @ts-expect-error
18
+ body.nonExistingField
19
+ return {
20
+ name,
21
+ nameEcho: body.name,
22
+ // add: 3,
23
+ }
24
+ },
25
+ {
26
+ body: z.object({
27
+ name: z.string(),
28
+ }),
29
+ response: z.object({
30
+ name: z.string(),
31
+ nameEcho: z.string(),
32
+ }),
33
+ },
34
+ )
35
+ .post(
36
+ '/post2',
37
+ async (c) => {
38
+ const body = await c.request.json()
39
+ name = body.name
40
+ // @ts-expect-error
41
+ body.nonExistingField
42
+ return {
43
+ name,
44
+ nameEcho: body.name,
45
+ }
46
+ },
47
+ {
48
+ body: z.object({
49
+ name: z.string(),
50
+ }),
51
+ response: {
52
+ 200: z.object({
53
+ name: z.string(),
54
+ nameEcho: z.string(),
55
+ }),
56
+ 400: z.object({
57
+ errorMessage: z.string(),
58
+ }),
59
+ },
60
+ },
61
+ )
62
+ .handle(
63
+ req('/post', {
64
+ method: 'POST',
65
+ headers: {
66
+ 'content-type': 'application/json',
67
+ },
68
+ body: JSON.stringify({ name: 'John' }),
69
+ }),
70
+ )
71
+ expect(res.status).toBe(200)
72
+ expect(await res.json()).toEqual({ name: 'John', nameEcho: 'John' })
73
+ })