spiceflow 1.8.0 → 1.9.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.
- package/README.md +35 -0
- package/dist/_node_utils.d.ts +3 -0
- package/dist/_node_utils.d.ts.map +1 -0
- package/dist/_node_utils.js +2 -0
- package/dist/_node_utils_browser.d.ts +2 -0
- package/dist/_node_utils_browser.d.ts.map +1 -0
- package/dist/_node_utils_browser.js +3 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/cors.d.ts.map +1 -1
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +1 -12
- package/dist/openapi.d.ts.map +1 -1
- package/dist/spiceflow.d.ts +10 -9
- package/dist/spiceflow.d.ts.map +1 -1
- package/dist/spiceflow.js +31 -83
- package/dist/spiceflow.test.js +3 -3
- package/dist/static-node.d.ts.map +1 -1
- package/dist/static.d.ts.map +1 -1
- package/dist/types.d.ts +5 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/package.json +8 -4
- package/src/_node_utils.ts +2 -0
- package/src/_node_utils_browser.ts +3 -0
- package/src/mcp.ts +3 -12
- package/src/openapi.ts +47 -49
- package/src/spiceflow.test.ts +3 -3
- package/src/spiceflow.ts +46 -109
- package/src/types.ts +118 -126
package/src/types.ts
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
// https://github.com/remorses/elysia/blob/main/src/types.ts#L6
|
|
2
2
|
|
|
3
3
|
import z from 'zod'
|
|
4
|
-
|
|
5
|
-
import type {
|
|
6
|
-
OptionalKind,
|
|
7
|
-
Static,
|
|
8
|
-
StaticDecode,
|
|
9
|
-
TObject,
|
|
10
|
-
TSchema,
|
|
11
|
-
} from '@sinclair/typebox'
|
|
4
|
+
import { StandardSchemaV1 } from '@standard-schema/spec'
|
|
12
5
|
|
|
13
6
|
import type { OpenAPIV3 } from 'openapi-types'
|
|
14
7
|
|
|
@@ -31,8 +24,8 @@ export type ObjectValues<T extends object> = T[keyof T]
|
|
|
31
24
|
type IsPathParameter<Part extends string> = Part extends `:${infer Parameter}`
|
|
32
25
|
? Parameter
|
|
33
26
|
: Part extends `*`
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
? '*'
|
|
28
|
+
: never
|
|
36
29
|
|
|
37
30
|
export type GetPathParameter<Path extends string> =
|
|
38
31
|
Path extends `${infer A}/${infer B}`
|
|
@@ -68,15 +61,16 @@ export type NeverKey<T> = {
|
|
|
68
61
|
[K in keyof T]?: T[K]
|
|
69
62
|
} & {}
|
|
70
63
|
|
|
71
|
-
type IsBothObject<A, B> =
|
|
72
|
-
|
|
73
|
-
?
|
|
74
|
-
? IsClass<
|
|
75
|
-
?
|
|
64
|
+
type IsBothObject<A, B> =
|
|
65
|
+
A extends Record<string | number | symbol, unknown>
|
|
66
|
+
? B extends Record<string | number | symbol, unknown>
|
|
67
|
+
? IsClass<A> extends false
|
|
68
|
+
? IsClass<B> extends false
|
|
69
|
+
? true
|
|
70
|
+
: false
|
|
76
71
|
: false
|
|
77
72
|
: false
|
|
78
73
|
: false
|
|
79
|
-
: false
|
|
80
74
|
|
|
81
75
|
type IsClass<V> = V extends abstract new (...args: any) => any ? true : false
|
|
82
76
|
|
|
@@ -89,57 +83,57 @@ export type Reconcile<
|
|
|
89
83
|
> = Stack['length'] extends 16
|
|
90
84
|
? A
|
|
91
85
|
: 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
|
|
121
86
|
? {
|
|
122
|
-
[key in keyof A]:
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
? Reconcile<
|
|
87
|
+
[key in keyof A as key extends keyof B ? never : key]: A[key]
|
|
88
|
+
} extends infer Collision
|
|
89
|
+
? {} extends Collision
|
|
90
|
+
? {
|
|
91
|
+
[key in keyof B]: IsBothObject<
|
|
128
92
|
// @ts-ignore trust me bro
|
|
93
|
+
A[key],
|
|
94
|
+
B[key]
|
|
95
|
+
> extends true
|
|
96
|
+
? Reconcile<
|
|
97
|
+
// @ts-ignore trust me bro
|
|
98
|
+
A[key],
|
|
99
|
+
B[key],
|
|
100
|
+
Override,
|
|
101
|
+
[0, ...Stack]
|
|
102
|
+
>
|
|
103
|
+
: B[key]
|
|
104
|
+
}
|
|
105
|
+
: Prettify<
|
|
106
|
+
Collision & {
|
|
107
|
+
[key in keyof B]: B[key]
|
|
108
|
+
}
|
|
109
|
+
>
|
|
110
|
+
: never
|
|
111
|
+
: {
|
|
112
|
+
[key in keyof B as key extends keyof A ? never : key]: B[key]
|
|
113
|
+
} extends infer Collision
|
|
114
|
+
? {} extends Collision
|
|
115
|
+
? {
|
|
116
|
+
[key in keyof A]: IsBothObject<
|
|
129
117
|
A[key],
|
|
130
118
|
// @ts-ignore trust me bro
|
|
131
|
-
B[key]
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
119
|
+
B[key]
|
|
120
|
+
> extends true
|
|
121
|
+
? Reconcile<
|
|
122
|
+
// @ts-ignore trust me bro
|
|
123
|
+
A[key],
|
|
124
|
+
// @ts-ignore trust me bro
|
|
125
|
+
B[key],
|
|
126
|
+
Override,
|
|
127
|
+
[0, ...Stack]
|
|
128
|
+
>
|
|
129
|
+
: A[key]
|
|
130
|
+
}
|
|
131
|
+
: Prettify<
|
|
132
|
+
{
|
|
133
|
+
[key in keyof A]: A[key]
|
|
134
|
+
} & Collision
|
|
135
|
+
>
|
|
136
|
+
: never
|
|
143
137
|
|
|
144
138
|
export interface SingletonBase {
|
|
145
139
|
state: Record<string, unknown>
|
|
@@ -158,32 +152,26 @@ export interface MetadataBase {
|
|
|
158
152
|
macroFn: BaseMacroFn
|
|
159
153
|
}
|
|
160
154
|
|
|
161
|
-
export
|
|
155
|
+
export type RouteSchema = {
|
|
162
156
|
body?: unknown
|
|
163
157
|
query?: unknown
|
|
164
158
|
params?: unknown
|
|
165
159
|
response?: unknown
|
|
166
160
|
}
|
|
167
161
|
|
|
168
|
-
type
|
|
169
|
-
[OptionalKind]: 'Optional'
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export type TypeSchema = TSchema | ZodTypeAny
|
|
162
|
+
export type TypeSchema = StandardSchemaV1
|
|
173
163
|
|
|
174
|
-
export type TypeObject =
|
|
164
|
+
export type TypeObject = ZodObject<any, any, any>
|
|
175
165
|
|
|
176
166
|
export type UnwrapSchema<
|
|
177
167
|
Schema extends TypeSchema | string | undefined,
|
|
178
168
|
Definitions extends Record<string, unknown> = {},
|
|
179
|
-
> =
|
|
169
|
+
> = Schema extends undefined
|
|
180
170
|
? unknown
|
|
171
|
+
: Schema extends StandardSchemaV1
|
|
172
|
+
? StandardSchemaV1.InferOutput<Schema>
|
|
181
173
|
: Schema extends ZodTypeAny
|
|
182
174
|
? z.infer<Schema>
|
|
183
|
-
: Schema extends TSchema
|
|
184
|
-
? Schema extends OptionalField
|
|
185
|
-
? Prettify<Partial<Static<Schema>>>
|
|
186
|
-
: StaticDecode<Schema>
|
|
187
175
|
: Schema extends string
|
|
188
176
|
? Definitions extends Record<Schema, infer NamedSchema>
|
|
189
177
|
? NamedSchema
|
|
@@ -202,13 +190,13 @@ export interface UnwrapRoute<
|
|
|
202
190
|
200: UnwrapSchema<Schema['response'], Definitions>
|
|
203
191
|
}
|
|
204
192
|
: Schema['response'] extends Record<number, TypeSchema | string>
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
193
|
+
? {
|
|
194
|
+
[k in keyof Schema['response']]: UnwrapSchema<
|
|
195
|
+
Schema['response'][k],
|
|
196
|
+
Definitions
|
|
197
|
+
>
|
|
198
|
+
}
|
|
199
|
+
: unknown | void
|
|
212
200
|
}
|
|
213
201
|
|
|
214
202
|
export type LifeCycleEvent =
|
|
@@ -297,8 +285,8 @@ export interface MergeSchema<
|
|
|
297
285
|
? {}
|
|
298
286
|
: B['response']
|
|
299
287
|
: {} extends B['response']
|
|
300
|
-
|
|
301
|
-
|
|
288
|
+
? A['response']
|
|
289
|
+
: A['response'] & Omit<B['response'], keyof A['response']>
|
|
302
290
|
}
|
|
303
291
|
|
|
304
292
|
export type Handler<
|
|
@@ -315,29 +303,31 @@ export type Handler<
|
|
|
315
303
|
: Route['response'][keyof Route['response']]
|
|
316
304
|
>
|
|
317
305
|
|
|
318
|
-
export type Replace<Original, Target, With> =
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
306
|
+
export type Replace<Original, Target, With> =
|
|
307
|
+
IsAny<Target> extends true
|
|
308
|
+
? Original
|
|
309
|
+
: Original extends Record<string, unknown>
|
|
310
|
+
? {
|
|
311
|
+
[K in keyof Original]: Original[K] extends Target ? With : Original[K]
|
|
312
|
+
}
|
|
313
|
+
: Original extends Target
|
|
314
|
+
? With
|
|
315
|
+
: Original
|
|
327
316
|
|
|
328
317
|
export type IsAny<T> = 0 extends 1 & T ? true : false
|
|
329
318
|
|
|
330
|
-
export type CoExist<Original, Target, With> =
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
319
|
+
export type CoExist<Original, Target, With> =
|
|
320
|
+
IsAny<Target> extends true
|
|
321
|
+
? Original
|
|
322
|
+
: Original extends Record<string, unknown>
|
|
323
|
+
? {
|
|
324
|
+
[K in keyof Original]: Original[K] extends Target
|
|
325
|
+
? Original[K] | With
|
|
326
|
+
: Original[K]
|
|
327
|
+
}
|
|
328
|
+
: Original extends Target
|
|
329
|
+
? Original | With
|
|
330
|
+
: Original
|
|
341
331
|
|
|
342
332
|
export type InlineHandler<
|
|
343
333
|
Route extends RouteSchema = {},
|
|
@@ -374,11 +364,12 @@ export type OptionalHandler<
|
|
|
374
364
|
state: {}
|
|
375
365
|
},
|
|
376
366
|
Path extends string = '',
|
|
377
|
-
> =
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
367
|
+
> =
|
|
368
|
+
Handler<Route, Singleton, Path> extends (
|
|
369
|
+
context: infer Context,
|
|
370
|
+
) => infer Returned
|
|
371
|
+
? (context: Context) => Returned | MaybePromise<void>
|
|
372
|
+
: never
|
|
382
373
|
|
|
383
374
|
export type AfterHandler<
|
|
384
375
|
in out Route extends RouteSchema = {},
|
|
@@ -386,17 +377,18 @@ export type AfterHandler<
|
|
|
386
377
|
state: {}
|
|
387
378
|
},
|
|
388
379
|
Path extends string = '',
|
|
389
|
-
> =
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
380
|
+
> =
|
|
381
|
+
Handler<Route, Singleton, Path> extends (
|
|
382
|
+
context: infer Context,
|
|
383
|
+
) => infer Returned
|
|
384
|
+
? (
|
|
385
|
+
context: Prettify<
|
|
386
|
+
{
|
|
387
|
+
response: Route['response']
|
|
388
|
+
} & Context
|
|
389
|
+
>,
|
|
390
|
+
) => Returned | MaybePromise<void>
|
|
391
|
+
: never
|
|
400
392
|
|
|
401
393
|
export type MapResponse<
|
|
402
394
|
in out Route extends RouteSchema = {},
|
|
@@ -633,8 +625,8 @@ export type CreateClient<
|
|
|
633
625
|
> = Path extends `/${infer Rest}`
|
|
634
626
|
? _CreateClient<Rest, Property>
|
|
635
627
|
: Path extends ''
|
|
636
|
-
|
|
637
|
-
|
|
628
|
+
? _CreateClient<'index', Property>
|
|
629
|
+
: _CreateClient<Path, Property>
|
|
638
630
|
|
|
639
631
|
export type ComposeSpiceflowResponse<Response, Handle> = Handle extends (
|
|
640
632
|
...a: any[]
|
|
@@ -870,10 +862,10 @@ export type HTTPHeaders = Record<string, string> & {
|
|
|
870
862
|
export type JoinPath<A extends string, B extends string> = `${A}${B extends '/'
|
|
871
863
|
? '/index'
|
|
872
864
|
: B extends ''
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
865
|
+
? B
|
|
866
|
+
: B extends `/${string}`
|
|
867
|
+
? B
|
|
868
|
+
: B}`
|
|
877
869
|
|
|
878
870
|
export type PartialWithRequired<T, K extends keyof T> = Partial<Omit<T, K>> &
|
|
879
871
|
Pick<T, K>
|