spiceflow 1.1.18 → 1.3.0

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 (49) hide show
  1. package/README.md +245 -10
  2. package/dist/cors.d.ts +2 -0
  3. package/dist/cors.d.ts.map +1 -1
  4. package/dist/cors.js +10 -2
  5. package/dist/cors.js.map +1 -1
  6. package/dist/index.d.ts +2 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/mcp-transport.d.ts +45 -0
  10. package/dist/mcp-transport.d.ts.map +1 -0
  11. package/dist/mcp-transport.js +107 -0
  12. package/dist/mcp-transport.js.map +1 -0
  13. package/dist/mcp.d.ts +36 -0
  14. package/dist/mcp.d.ts.map +1 -0
  15. package/dist/mcp.js +211 -0
  16. package/dist/mcp.js.map +1 -0
  17. package/dist/mcp.test.d.ts +2 -0
  18. package/dist/mcp.test.d.ts.map +1 -0
  19. package/dist/mcp.test.js +224 -0
  20. package/dist/mcp.test.js.map +1 -0
  21. package/dist/openapi.d.ts +14 -27
  22. package/dist/openapi.d.ts.map +1 -1
  23. package/dist/openapi.js +101 -49
  24. package/dist/openapi.js.map +1 -1
  25. package/dist/openapi.test.js +242 -18
  26. package/dist/openapi.test.js.map +1 -1
  27. package/dist/spiceflow.d.ts +5 -3
  28. package/dist/spiceflow.d.ts.map +1 -1
  29. package/dist/spiceflow.js +42 -10
  30. package/dist/spiceflow.js.map +1 -1
  31. package/dist/spiceflow.test.js +21 -3
  32. package/dist/spiceflow.test.js.map +1 -1
  33. package/dist/stream.test.js +4 -2
  34. package/dist/stream.test.js.map +1 -1
  35. package/dist/types.d.ts +7 -13
  36. package/dist/types.d.ts.map +1 -1
  37. package/dist/types.js.map +1 -1
  38. package/package.json +20 -5
  39. package/src/cors.ts +14 -2
  40. package/src/index.ts +2 -1
  41. package/src/mcp-transport.ts +148 -0
  42. package/src/mcp.test.ts +273 -0
  43. package/src/mcp.ts +270 -0
  44. package/src/openapi.test.ts +238 -18
  45. package/src/openapi.ts +136 -66
  46. package/src/spiceflow.test.ts +27 -3
  47. package/src/spiceflow.ts +83 -13
  48. package/src/stream.test.ts +4 -2
  49. package/src/types.ts +129 -140
package/src/types.ts CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  import z from 'zod'
4
4
 
5
-
6
5
  import type {
7
6
  OptionalKind,
8
7
  Static,
@@ -25,14 +24,15 @@ import { Spiceflow } from './spiceflow.js'
25
24
 
26
25
  export type MaybeArray<T> = T | T[]
27
26
  export type MaybePromise<T> = T | Promise<T>
27
+ export type MaybePromiseIterable<T> = T | Promise<T> | AsyncIterable<T>
28
28
 
29
29
  export type ObjectValues<T extends object> = T[keyof T]
30
30
 
31
31
  type IsPathParameter<Part extends string> = Part extends `:${infer Parameter}`
32
32
  ? Parameter
33
33
  : Part extends `*`
34
- ? '*'
35
- : never
34
+ ? '*'
35
+ : never
36
36
 
37
37
  export type GetPathParameter<Path extends string> =
38
38
  Path extends `${infer A}/${infer B}`
@@ -68,19 +68,17 @@ export type NeverKey<T> = {
68
68
  [K in keyof T]?: T[K]
69
69
  } & {}
70
70
 
71
- type IsBothObject<A, B> =
72
- A extends Record<string | number | symbol, unknown>
73
- ? B extends Record<string | number | symbol, unknown>
74
- ? IsClass<A> extends false
75
- ? IsClass<B> extends false
76
- ? true
77
- : false
71
+ type IsBothObject<A, B> = A extends Record<string | number | symbol, unknown>
72
+ ? B extends Record<string | number | symbol, unknown>
73
+ ? IsClass<A> extends false
74
+ ? IsClass<B> extends false
75
+ ? true
78
76
  : false
79
77
  : false
80
78
  : false
79
+ : false
81
80
 
82
81
  type IsClass<V> = V extends abstract new (...args: any) => any ? true : false
83
- type And<A, B> = A extends true ? (B extends true ? true : false) : false
84
82
 
85
83
  export type Reconcile<
86
84
  A extends Object,
@@ -91,57 +89,57 @@ export type Reconcile<
91
89
  > = Stack['length'] extends 16
92
90
  ? A
93
91
  : Override extends true
92
+ ? {
93
+ [key in keyof A as key extends keyof B ? never : key]: A[key]
94
+ } extends infer Collision
95
+ ? {} extends Collision
96
+ ? {
97
+ [key in keyof B]: IsBothObject<
98
+ // @ts-ignore trust me bro
99
+ A[key],
100
+ B[key]
101
+ > extends true
102
+ ? Reconcile<
103
+ // @ts-ignore trust me bro
104
+ A[key],
105
+ B[key],
106
+ Override,
107
+ [0, ...Stack]
108
+ >
109
+ : B[key]
110
+ }
111
+ : Prettify<
112
+ Collision & {
113
+ [key in keyof B]: B[key]
114
+ }
115
+ >
116
+ : never
117
+ : {
118
+ [key in keyof B as key extends keyof A ? never : key]: B[key]
119
+ } extends infer Collision
120
+ ? {} extends Collision
94
121
  ? {
95
- [key in keyof A as key extends keyof B ? never : key]: A[key]
96
- } extends infer Collision
97
- ? {} extends Collision
98
- ? {
99
- [key in keyof B]: IsBothObject<
122
+ [key in keyof A]: IsBothObject<
123
+ A[key],
124
+ // @ts-ignore trust me bro
125
+ B[key]
126
+ > extends true
127
+ ? Reconcile<
100
128
  // @ts-ignore trust me bro
101
- A[key],
102
- B[key]
103
- > extends true
104
- ? Reconcile<
105
- // @ts-ignore trust me bro
106
- A[key],
107
- B[key],
108
- Override,
109
- [0, ...Stack]
110
- >
111
- : B[key]
112
- }
113
- : Prettify<
114
- Collision & {
115
- [key in keyof B]: B[key]
116
- }
117
- >
118
- : never
119
- : {
120
- [key in keyof B as key extends keyof A ? never : key]: B[key]
121
- } extends infer Collision
122
- ? {} extends Collision
123
- ? {
124
- [key in keyof A]: IsBothObject<
125
129
  A[key],
126
130
  // @ts-ignore trust me bro
127
- B[key]
128
- > extends true
129
- ? Reconcile<
130
- // @ts-ignore trust me bro
131
- A[key],
132
- // @ts-ignore trust me bro
133
- B[key],
134
- Override,
135
- [0, ...Stack]
136
- >
137
- : A[key]
138
- }
139
- : Prettify<
140
- {
141
- [key in keyof A]: A[key]
142
- } & Collision
143
- >
144
- : never
131
+ B[key],
132
+ Override,
133
+ [0, ...Stack]
134
+ >
135
+ : A[key]
136
+ }
137
+ : Prettify<
138
+ {
139
+ [key in keyof A]: A[key]
140
+ } & Collision
141
+ >
142
+ : never
145
143
 
146
144
  export interface SingletonBase {
147
145
  state: Record<string, unknown>
@@ -181,16 +179,16 @@ export type UnwrapSchema<
181
179
  > = undefined extends Schema
182
180
  ? unknown
183
181
  : Schema extends ZodTypeAny
184
- ? z.infer<Schema>
185
- : Schema extends TSchema
186
- ? Schema extends OptionalField
187
- ? Prettify<Partial<Static<Schema>>>
188
- : StaticDecode<Schema>
189
- : Schema extends string
190
- ? Definitions extends Record<Schema, infer NamedSchema>
191
- ? NamedSchema
192
- : Definitions
193
- : unknown
182
+ ? z.infer<Schema>
183
+ : Schema extends TSchema
184
+ ? Schema extends OptionalField
185
+ ? Prettify<Partial<Static<Schema>>>
186
+ : StaticDecode<Schema>
187
+ : Schema extends string
188
+ ? Definitions extends Record<Schema, infer NamedSchema>
189
+ ? NamedSchema
190
+ : Definitions
191
+ : unknown
194
192
 
195
193
  export interface UnwrapRoute<
196
194
  in out Schema extends InputSchema<any>,
@@ -204,10 +202,13 @@ export interface UnwrapRoute<
204
202
  200: UnwrapSchema<Schema['response'], Definitions>
205
203
  }
206
204
  : Schema['response'] extends Record<number, TypeSchema | string>
207
- ? {
208
- [k in keyof Schema['response']]: UnwrapSchema<Schema['response'][k], Definitions>
209
- }
210
- : unknown | void
205
+ ? {
206
+ [k in keyof Schema['response']]: UnwrapSchema<
207
+ Schema['response'][k],
208
+ Definitions
209
+ >
210
+ }
211
+ : unknown | void
211
212
  }
212
213
 
213
214
  export type LifeCycleEvent =
@@ -223,12 +224,12 @@ export type LifeCycleEvent =
223
224
 
224
225
  export type ContentType = MaybeArray<
225
226
  | (string & {})
226
- | 'none'
227
- | 'text'
228
- | 'json'
229
- | 'formdata'
230
- | 'urlencoded'
231
- | 'arrayBuffer'
227
+ // | 'none'
228
+ // | 'text'
229
+ // | 'json'
230
+ // | 'formdata'
231
+ // | 'urlencoded'
232
+ // | 'arrayBuffer'
232
233
  | 'text/plain'
233
234
  | 'application/json'
234
235
  | 'multipart/form-data'
@@ -296,8 +297,8 @@ export interface MergeSchema<
296
297
  ? {}
297
298
  : B['response']
298
299
  : {} extends B['response']
299
- ? A['response']
300
- : A['response'] & Omit<B['response'], keyof A['response']>
300
+ ? A['response']
301
+ : A['response'] & Omit<B['response'], keyof A['response']>
301
302
  }
302
303
 
303
304
  export type Handler<
@@ -314,31 +315,29 @@ export type Handler<
314
315
  : Route['response'][keyof Route['response']]
315
316
  >
316
317
 
317
- export type Replace<Original, Target, With> =
318
- IsAny<Target> extends true
319
- ? Original
320
- : Original extends Record<string, unknown>
321
- ? {
322
- [K in keyof Original]: Original[K] extends Target ? With : Original[K]
323
- }
324
- : Original extends Target
325
- ? With
326
- : Original
318
+ export type Replace<Original, Target, With> = IsAny<Target> extends true
319
+ ? Original
320
+ : Original extends Record<string, unknown>
321
+ ? {
322
+ [K in keyof Original]: Original[K] extends Target ? With : Original[K]
323
+ }
324
+ : Original extends Target
325
+ ? With
326
+ : Original
327
327
 
328
328
  export type IsAny<T> = 0 extends 1 & T ? true : false
329
329
 
330
- export type CoExist<Original, Target, With> =
331
- IsAny<Target> extends true
332
- ? Original
333
- : Original extends Record<string, unknown>
334
- ? {
335
- [K in keyof Original]: Original[K] extends Target
336
- ? Original[K] | With
337
- : Original[K]
338
- }
339
- : Original extends Target
340
- ? Original | With
341
- : Original
330
+ export type CoExist<Original, Target, With> = IsAny<Target> extends true
331
+ ? Original
332
+ : Original extends Record<string, unknown>
333
+ ? {
334
+ [K in keyof Original]: Original[K] extends Target
335
+ ? Original[K] | With
336
+ : Original[K]
337
+ }
338
+ : Original extends Target
339
+ ? Original | With
340
+ : Original
342
341
 
343
342
  export type InlineHandler<
344
343
  Route extends RouteSchema = {},
@@ -353,7 +352,7 @@ export type InlineHandler<
353
352
  : Context<Route, Singleton, Path>,
354
353
  ) =>
355
354
  | Response
356
- | MaybePromise<
355
+ | MaybePromiseIterable<
357
356
  {} extends Route['response']
358
357
  ? unknown
359
358
  :
@@ -375,12 +374,11 @@ export type OptionalHandler<
375
374
  state: {}
376
375
  },
377
376
  Path extends string = '',
378
- > =
379
- Handler<Route, Singleton, Path> extends (
380
- context: infer Context,
381
- ) => infer Returned
382
- ? (context: Context) => Returned | MaybePromise<void>
383
- : never
377
+ > = Handler<Route, Singleton, Path> extends (
378
+ context: infer Context,
379
+ ) => infer Returned
380
+ ? (context: Context) => Returned | MaybePromise<void>
381
+ : never
384
382
 
385
383
  export type AfterHandler<
386
384
  in out Route extends RouteSchema = {},
@@ -388,18 +386,17 @@ export type AfterHandler<
388
386
  state: {}
389
387
  },
390
388
  Path extends string = '',
391
- > =
392
- Handler<Route, Singleton, Path> extends (
393
- context: infer Context,
394
- ) => infer Returned
395
- ? (
396
- context: Prettify<
397
- {
398
- response: Route['response']
399
- } & Context
400
- >,
401
- ) => Returned | MaybePromise<void>
402
- : never
389
+ > = Handler<Route, Singleton, Path> extends (
390
+ context: infer Context,
391
+ ) => infer Returned
392
+ ? (
393
+ context: Prettify<
394
+ {
395
+ response: Route['response']
396
+ } & Context
397
+ >,
398
+ ) => Returned | MaybePromise<void>
399
+ : never
403
400
 
404
401
  export type MapResponse<
405
402
  in out Route extends RouteSchema = {},
@@ -558,6 +555,10 @@ export type DocumentDecoration = Partial<OpenAPIV3.OperationObject> & {
558
555
  * Pass `true` to hide route from OpenAPI/swagger document
559
556
  * */
560
557
  hide?: boolean
558
+ // 'x-fern-type-name'?: string
559
+ 'x-fern-sdk-group-name'?: string | string[]
560
+ 'x-fern-sdk-method-name'?: string
561
+ 'x-fern-webhook'?: boolean
561
562
  }
562
563
 
563
564
  export type LocalHook<
@@ -579,17 +580,7 @@ export type LocalHook<
579
580
  > = (LocalSchema extends {} ? LocalSchema : Isolate<LocalSchema>) &
580
581
  Extension & {
581
582
  detail?: DocumentDecoration
582
- /**
583
- * Short for 'Content-Type'
584
- *
585
- * Available:
586
- * - 'none': do not parse body
587
- * - 'text' / 'text/plain': parse body as string
588
- * - 'json' / 'application/json': parse body as json
589
- * - 'formdata' / 'multipart/form-data': parse body as form-data
590
- * - 'urlencoded' / 'application/x-www-form-urlencoded: parse body as urlencoded
591
- * - 'arraybuffer': parse body as readable stream
592
- */
583
+ bodyType?: ContentType
593
584
  type?: ContentType
594
585
  }
595
586
 
@@ -603,8 +594,6 @@ export interface InternalRoute {
603
594
  hooks: LocalHook<any, any, any, any, any, any, any>
604
595
  }
605
596
 
606
-
607
-
608
597
  export type AddPrefix<Prefix extends string, T> = {
609
598
  [K in keyof T as Prefix extends string ? `${Prefix}${K & string}` : K]: T[K]
610
599
  }
@@ -644,8 +633,8 @@ export type CreateClient<
644
633
  > = Path extends `/${infer Rest}`
645
634
  ? _CreateClient<Rest, Property>
646
635
  : Path extends ''
647
- ? _CreateClient<'index', Property>
648
- : _CreateClient<Path, Property>
636
+ ? _CreateClient<'index', Property>
637
+ : _CreateClient<Path, Property>
649
638
 
650
639
  export type ComposeSpiceflowResponse<Response, Handle> = Handle extends (
651
640
  ...a: any[]
@@ -881,10 +870,10 @@ export type HTTPHeaders = Record<string, string> & {
881
870
  export type JoinPath<A extends string, B extends string> = `${A}${B extends '/'
882
871
  ? '/index'
883
872
  : B extends ''
884
- ? B
885
- : B extends `/${string}`
886
- ? B
887
- : B}`
873
+ ? B
874
+ : B extends `/${string}`
875
+ ? B
876
+ : B}`
888
877
 
889
878
  export type PartialWithRequired<T, K extends keyof T> = Partial<Omit<T, K>> &
890
879
  Pick<T, K>