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/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
- : never
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> = 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
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]: IsBothObject<
123
- A[key],
124
- // @ts-ignore trust me bro
125
- B[key]
126
- > extends true
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
- Override,
133
- [0, ...Stack]
134
- >
135
- : A[key]
136
- }
137
- : Prettify<
138
- {
139
- [key in keyof A]: A[key]
140
- } & Collision
141
- >
142
- : never
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 interface RouteSchema {
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 OptionalField = {
169
- [OptionalKind]: 'Optional'
170
- }
171
-
172
- export type TypeSchema = TSchema | ZodTypeAny
162
+ export type TypeSchema = StandardSchemaV1
173
163
 
174
- export type TypeObject = TObject | ZodObject<any, any, any>
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
- > = undefined extends Schema
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
- [k in keyof Schema['response']]: UnwrapSchema<
207
- Schema['response'][k],
208
- Definitions
209
- >
210
- }
211
- : unknown | void
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
- ? A['response']
301
- : A['response'] & Omit<B['response'], keyof A['response']>
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> = 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
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> = 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
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
- > = Handler<Route, Singleton, Path> extends (
378
- context: infer Context,
379
- ) => infer Returned
380
- ? (context: Context) => Returned | MaybePromise<void>
381
- : never
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
- > = 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
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
- ? _CreateClient<'index', Property>
637
- : _CreateClient<Path, Property>
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
- ? B
874
- : B extends `/${string}`
875
- ? B
876
- : B}`
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>