@tanstack/start-client-core 1.132.0-alpha.7 → 1.132.0-alpha.8

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.
@@ -3,17 +3,17 @@ import { mergeHeaders } from '@tanstack/router-core/ssr/client'
3
3
  import { globalMiddleware } from './registerGlobalMiddleware'
4
4
 
5
5
  import { getRouterInstance } from './getRouterInstance'
6
- import type {
7
- SerializerParse,
8
- SerializerStringify,
9
- SerializerStringifyBy,
10
- } from './serializer'
11
6
  import type {
12
7
  AnyRouter,
13
8
  AnyValidator,
14
9
  Constrain,
15
10
  Expand,
11
+ Register,
12
+ RegisteredSerializableInput,
16
13
  ResolveValidatorInput,
14
+ ValidateSerializable,
15
+ ValidateSerializableInput,
16
+ ValidateSerializableInputResult,
17
17
  Validator,
18
18
  } from '@tanstack/router-core'
19
19
  import type { JsonResponse } from '@tanstack/router-core/ssr/client'
@@ -31,6 +31,7 @@ import type {
31
31
  type TODO = any
32
32
 
33
33
  export function createServerFn<
34
+ TRegister extends Register,
34
35
  TMethod extends Method,
35
36
  TServerFnResponseType extends ServerFnResponseType = 'data',
36
37
  TResponse = unknown,
@@ -42,14 +43,16 @@ export function createServerFn<
42
43
  response?: TServerFnResponseType
43
44
  },
44
45
  __opts?: ServerFnBaseOptions<
46
+ TRegister,
45
47
  TMethod,
46
48
  TServerFnResponseType,
47
49
  TResponse,
48
50
  TMiddlewares,
49
51
  TValidator
50
52
  >,
51
- ): ServerFnBuilder<TMethod, TServerFnResponseType> {
53
+ ): ServerFnBuilder<TRegister, TMethod, TServerFnResponseType> {
52
54
  const resolvedOptions = (__opts || options || {}) as ServerFnBaseOptions<
55
+ TRegister,
53
56
  TMethod,
54
57
  ServerFnResponseType,
55
58
  TResponse,
@@ -65,6 +68,7 @@ export function createServerFn<
65
68
  options: resolvedOptions as any,
66
69
  middleware: (middleware) => {
67
70
  return createServerFn<
71
+ TRegister,
68
72
  TMethod,
69
73
  ServerFnResponseType,
70
74
  TResponse,
@@ -74,6 +78,7 @@ export function createServerFn<
74
78
  },
75
79
  validator: (validator) => {
76
80
  return createServerFn<
81
+ TRegister,
77
82
  TMethod,
78
83
  ServerFnResponseType,
79
84
  TResponse,
@@ -86,8 +91,9 @@ export function createServerFn<
86
91
  // in the babel plugin. We need to cast it to the correct
87
92
  // function signature post-transformation
88
93
  const [extractedFn, serverFn] = args as unknown as [
89
- CompiledFetcherFn<TResponse, TServerFnResponseType>,
94
+ CompiledFetcherFn<TRegister, TResponse, TServerFnResponseType>,
90
95
  ServerFn<
96
+ TRegister,
91
97
  TMethod,
92
98
  TServerFnResponseType,
93
99
  TMiddlewares,
@@ -230,6 +236,7 @@ export type CompiledFetcherFnOptions = {
230
236
  }
231
237
 
232
238
  export type Fetcher<
239
+ TRegister extends Register,
233
240
  TMiddlewares,
234
241
  TValidator,
235
242
  TResponse,
@@ -237,12 +244,14 @@ export type Fetcher<
237
244
  > =
238
245
  undefined extends IntersectAllValidatorInputs<TMiddlewares, TValidator>
239
246
  ? OptionalFetcher<
247
+ TRegister,
240
248
  TMiddlewares,
241
249
  TValidator,
242
250
  TResponse,
243
251
  TServerFnResponseType
244
252
  >
245
253
  : RequiredFetcher<
254
+ TRegister,
246
255
  TMiddlewares,
247
256
  TValidator,
248
257
  TResponse,
@@ -262,16 +271,18 @@ export interface FetcherBase {
262
271
  }
263
272
 
264
273
  export type FetchResult<
274
+ TRegister extends Register,
265
275
  TMiddlewares,
266
276
  TResponse,
267
277
  TServerFnResponseType extends ServerFnResponseType,
268
278
  > = TServerFnResponseType extends 'raw'
269
279
  ? Promise<Response>
270
280
  : TServerFnResponseType extends 'full'
271
- ? Promise<FullFetcherData<TMiddlewares, TResponse>>
272
- : Promise<FetcherData<TResponse>>
281
+ ? Promise<FullFetcherData<TRegister, TMiddlewares, TResponse>>
282
+ : Promise<FetcherData<TRegister, TResponse>>
273
283
 
274
284
  export interface OptionalFetcher<
285
+ TRegister extends Register,
275
286
  TMiddlewares,
276
287
  TValidator,
277
288
  TResponse,
@@ -279,10 +290,11 @@ export interface OptionalFetcher<
279
290
  > extends FetcherBase {
280
291
  (
281
292
  options?: OptionalFetcherDataOptions<TMiddlewares, TValidator>,
282
- ): FetchResult<TMiddlewares, TResponse, TServerFnResponseType>
293
+ ): FetchResult<TRegister, TMiddlewares, TResponse, TServerFnResponseType>
283
294
  }
284
295
 
285
296
  export interface RequiredFetcher<
297
+ TRegister extends Register,
286
298
  TMiddlewares,
287
299
  TValidator,
288
300
  TResponse,
@@ -290,7 +302,7 @@ export interface RequiredFetcher<
290
302
  > extends FetcherBase {
291
303
  (
292
304
  opts: RequiredFetcherDataOptions<TMiddlewares, TValidator>,
293
- ): FetchResult<TMiddlewares, TResponse, TServerFnResponseType>
305
+ ): FetchResult<TRegister, TMiddlewares, TResponse, TServerFnResponseType>
294
306
  }
295
307
 
296
308
  export type FetcherBaseOptions = {
@@ -308,16 +320,20 @@ export interface RequiredFetcherDataOptions<TMiddlewares, TValidator>
308
320
  data: Expand<IntersectAllValidatorInputs<TMiddlewares, TValidator>>
309
321
  }
310
322
 
311
- export interface FullFetcherData<TMiddlewares, TResponse> {
323
+ export interface FullFetcherData<
324
+ TRegister extends Register,
325
+ TMiddlewares,
326
+ TResponse,
327
+ > {
312
328
  error: unknown
313
- result: FetcherData<TResponse>
329
+ result: FetcherData<TRegister, TResponse>
314
330
  context: AssignAllClientSendContext<TMiddlewares>
315
331
  }
316
332
 
317
- export type FetcherData<TResponse> =
333
+ export type FetcherData<TRegister extends Register, TResponse> =
318
334
  TResponse extends JsonResponse<any>
319
- ? SerializerParse<ReturnType<TResponse['json']>>
320
- : SerializerParse<TResponse>
335
+ ? ValidateSerializableInputResult<TRegister, ReturnType<TResponse['json']>>
336
+ : ValidateSerializableInputResult<TRegister, TResponse>
321
337
 
322
338
  export type RscStream<T> = {
323
339
  __cacheState: T
@@ -330,13 +346,17 @@ export type ServerFnResponseType = 'data' | 'full' | 'raw'
330
346
  export type RawResponse = Response | ReadableStream | Readable | null | string
331
347
 
332
348
  export type ServerFnReturnType<
349
+ TRegister extends Register,
333
350
  TServerFnResponseType extends ServerFnResponseType,
334
351
  TResponse,
335
352
  > = TServerFnResponseType extends 'raw'
336
353
  ? RawResponse | Promise<RawResponse>
337
- : Promise<SerializerStringify<TResponse>> | SerializerStringify<TResponse>
354
+ :
355
+ | Promise<ValidateSerializableInput<TRegister, TResponse>>
356
+ | ValidateSerializableInput<TRegister, TResponse>
338
357
 
339
358
  export type ServerFn<
359
+ TRegister extends Register,
340
360
  TMethod,
341
361
  TServerFnResponseType extends ServerFnResponseType,
342
362
  TMiddlewares,
@@ -344,7 +364,7 @@ export type ServerFn<
344
364
  TResponse,
345
365
  > = (
346
366
  ctx: ServerFnCtx<TMethod, TServerFnResponseType, TMiddlewares, TValidator>,
347
- ) => ServerFnReturnType<TServerFnResponseType, TResponse>
367
+ ) => ServerFnReturnType<TRegister, TServerFnResponseType, TResponse>
348
368
 
349
369
  export interface ServerFnCtx<
350
370
  TMethod,
@@ -360,17 +380,19 @@ export interface ServerFnCtx<
360
380
  }
361
381
 
362
382
  export type CompiledFetcherFn<
383
+ TRegister extends Register,
363
384
  TResponse,
364
385
  TServerFnResponseType extends ServerFnResponseType,
365
386
  > = {
366
387
  (
367
388
  opts: CompiledFetcherFnOptions &
368
- ServerFnBaseOptions<Method, TServerFnResponseType>,
389
+ ServerFnBaseOptions<TRegister, Method, TServerFnResponseType>,
369
390
  ): Promise<TResponse>
370
391
  url: string
371
392
  }
372
393
 
373
394
  export type ServerFnBaseOptions<
395
+ TRegister extends Register,
374
396
  TMethod extends Method = 'GET',
375
397
  TServerFnResponseType extends ServerFnResponseType = 'data',
376
398
  TResponse = unknown,
@@ -381,9 +403,10 @@ export type ServerFnBaseOptions<
381
403
  response?: TServerFnResponseType
382
404
  validateClient?: boolean
383
405
  middleware?: Constrain<TMiddlewares, ReadonlyArray<AnyFunctionMiddleware>>
384
- validator?: ConstrainValidator<TInput>
385
- extractedFn?: CompiledFetcherFn<TResponse, TServerFnResponseType>
406
+ validator?: ConstrainValidator<TRegister, TInput>
407
+ extractedFn?: CompiledFetcherFn<TRegister, TResponse, TServerFnResponseType>
386
408
  serverFn?: ServerFn<
409
+ TRegister,
387
410
  TMethod,
388
411
  TServerFnResponseType,
389
412
  TMiddlewares,
@@ -393,25 +416,32 @@ export type ServerFnBaseOptions<
393
416
  functionId: string
394
417
  }
395
418
 
396
- export type ValidatorInputStringify<TValidator> = SerializerStringifyBy<
419
+ export type ValidateValidatorInput<
420
+ TRegister extends Register,
421
+ TValidator,
422
+ > = ValidateSerializable<
397
423
  ResolveValidatorInput<TValidator>,
398
- Date | undefined | FormData
424
+ RegisteredSerializableInput<TRegister> | FormData
399
425
  >
400
426
 
401
- export type ValidatorSerializerStringify<TValidator> =
402
- ValidatorInputStringify<TValidator> extends infer TInput
427
+ export type ValidateValidator<TRegister extends Register, TValidator> =
428
+ ValidateValidatorInput<TRegister, TValidator> extends infer TInput
403
429
  ? Validator<TInput, any>
404
430
  : never
405
431
 
406
- export type ConstrainValidator<TValidator> =
432
+ export type ConstrainValidator<TRegister extends Register, TValidator> =
407
433
  | (unknown extends TValidator
408
434
  ? TValidator
409
- : ResolveValidatorInput<TValidator> extends ValidatorInputStringify<TValidator>
435
+ : ResolveValidatorInput<TValidator> extends ValidateValidator<
436
+ TRegister,
437
+ TValidator
438
+ >
410
439
  ? TValidator
411
440
  : never)
412
- | ValidatorSerializerStringify<TValidator>
441
+ | ValidateValidator<TRegister, TValidator>
413
442
 
414
443
  export interface ServerFnMiddleware<
444
+ TRegister extends Register,
415
445
  TMethod extends Method,
416
446
  TServerFnResponseType extends ServerFnResponseType,
417
447
  TValidator,
@@ -422,6 +452,7 @@ export interface ServerFnMiddleware<
422
452
  ReadonlyArray<AnyFunctionMiddleware>
423
453
  >,
424
454
  ) => ServerFnAfterMiddleware<
455
+ TRegister,
425
456
  TMethod,
426
457
  TServerFnResponseType,
427
458
  TNewMiddlewares,
@@ -430,20 +461,34 @@ export interface ServerFnMiddleware<
430
461
  }
431
462
 
432
463
  export interface ServerFnAfterMiddleware<
464
+ TRegister extends Register,
433
465
  TMethod extends Method,
434
466
  TServerFnResponseType extends ServerFnResponseType,
435
467
  TMiddlewares,
436
468
  TValidator,
437
- > extends ServerFnValidator<TMethod, TServerFnResponseType, TMiddlewares>,
438
- ServerFnHandler<TMethod, TServerFnResponseType, TMiddlewares, TValidator> {}
469
+ > extends ServerFnValidator<
470
+ TRegister,
471
+ TMethod,
472
+ TServerFnResponseType,
473
+ TMiddlewares
474
+ >,
475
+ ServerFnHandler<
476
+ TRegister,
477
+ TMethod,
478
+ TServerFnResponseType,
479
+ TMiddlewares,
480
+ TValidator
481
+ > {}
439
482
 
440
483
  export type ValidatorFn<
484
+ TRegister extends Register,
441
485
  TMethod extends Method,
442
486
  TServerFnResponseType extends ServerFnResponseType,
443
487
  TMiddlewares,
444
488
  > = <TValidator>(
445
- validator: ConstrainValidator<TValidator>,
489
+ validator: ConstrainValidator<TRegister, TValidator>,
446
490
  ) => ServerFnAfterValidator<
491
+ TRegister,
447
492
  TMethod,
448
493
  TServerFnResponseType,
449
494
  TMiddlewares,
@@ -451,27 +496,47 @@ export type ValidatorFn<
451
496
  >
452
497
 
453
498
  export interface ServerFnValidator<
499
+ TRegister extends Register,
454
500
  TMethod extends Method,
455
501
  TServerFnResponseType extends ServerFnResponseType,
456
502
  TMiddlewares,
457
503
  > {
458
- validator: ValidatorFn<TMethod, TServerFnResponseType, TMiddlewares>
504
+ validator: ValidatorFn<
505
+ TRegister,
506
+ TMethod,
507
+ TServerFnResponseType,
508
+ TMiddlewares
509
+ >
459
510
  }
460
511
 
461
512
  export interface ServerFnAfterValidator<
513
+ TRegister extends Register,
462
514
  TMethod extends Method,
463
515
  TServerFnResponseType extends ServerFnResponseType,
464
516
  TMiddlewares,
465
517
  TValidator,
466
- > extends ServerFnMiddleware<TMethod, TServerFnResponseType, TValidator>,
467
- ServerFnHandler<TMethod, TServerFnResponseType, TMiddlewares, TValidator> {}
518
+ > extends ServerFnMiddleware<
519
+ TRegister,
520
+ TMethod,
521
+ TServerFnResponseType,
522
+ TValidator
523
+ >,
524
+ ServerFnHandler<
525
+ TRegister,
526
+ TMethod,
527
+ TServerFnResponseType,
528
+ TMiddlewares,
529
+ TValidator
530
+ > {}
468
531
 
469
532
  export interface ServerFnAfterTyper<
533
+ TRegister extends Register,
470
534
  TMethod extends Method,
471
535
  TServerFnResponseType extends ServerFnResponseType,
472
536
  TMiddlewares,
473
537
  TValidator,
474
538
  > extends ServerFnHandler<
539
+ TRegister,
475
540
  TMethod,
476
541
  TServerFnResponseType,
477
542
  TMiddlewares,
@@ -480,6 +545,7 @@ export interface ServerFnAfterTyper<
480
545
 
481
546
  // Handler
482
547
  export interface ServerFnHandler<
548
+ TRegister extends Register,
483
549
  TMethod extends Method,
484
550
  TServerFnResponseType extends ServerFnResponseType,
485
551
  TMiddlewares,
@@ -487,22 +553,42 @@ export interface ServerFnHandler<
487
553
  > {
488
554
  handler: <TNewResponse>(
489
555
  fn?: ServerFn<
556
+ TRegister,
490
557
  TMethod,
491
558
  TServerFnResponseType,
492
559
  TMiddlewares,
493
560
  TValidator,
494
561
  TNewResponse
495
562
  >,
496
- ) => Fetcher<TMiddlewares, TValidator, TNewResponse, TServerFnResponseType>
563
+ ) => Fetcher<
564
+ TRegister,
565
+ TMiddlewares,
566
+ TValidator,
567
+ TNewResponse,
568
+ TServerFnResponseType
569
+ >
497
570
  }
498
571
 
499
572
  export interface ServerFnBuilder<
573
+ TRegister extends Register,
500
574
  TMethod extends Method = 'GET',
501
575
  TServerFnResponseType extends ServerFnResponseType = 'data',
502
- > extends ServerFnMiddleware<TMethod, TServerFnResponseType, undefined>,
503
- ServerFnValidator<TMethod, TServerFnResponseType, undefined>,
504
- ServerFnHandler<TMethod, TServerFnResponseType, undefined, undefined> {
576
+ > extends ServerFnMiddleware<
577
+ TRegister,
578
+ TMethod,
579
+ TServerFnResponseType,
580
+ undefined
581
+ >,
582
+ ServerFnValidator<TRegister, TMethod, TServerFnResponseType, undefined>,
583
+ ServerFnHandler<
584
+ TRegister,
585
+ TMethod,
586
+ TServerFnResponseType,
587
+ undefined,
588
+ undefined
589
+ > {
505
590
  options: ServerFnBaseOptions<
591
+ TRegister,
506
592
  TMethod,
507
593
  TServerFnResponseType,
508
594
  unknown,
@@ -627,7 +713,7 @@ export function execValidator(
627
713
  }
628
714
 
629
715
  export function serverFnBaseToMiddleware(
630
- options: ServerFnBaseOptions<any, any, any, any, any>,
716
+ options: ServerFnBaseOptions<any, any, any, any, any, any>,
631
717
  ): AnyFunctionMiddleware {
632
718
  return {
633
719
  _types: undefined!,
package/src/index.tsx CHANGED
@@ -5,15 +5,6 @@ export type {
5
5
 
6
6
  export { hydrate, json, mergeHeaders } from '@tanstack/router-core/ssr/client'
7
7
 
8
- export type {
9
- Serializable,
10
- SerializerParse,
11
- SerializerParseBy,
12
- SerializerStringify,
13
- SerializerStringifyBy,
14
- SerializerExtensions,
15
- } from './serializer'
16
-
17
8
  export {
18
9
  createIsomorphicFn,
19
10
  type IsomorphicFn,
@@ -4,7 +4,13 @@ import { TSS_SERVER_FUNCTION } from '../constants'
4
4
 
5
5
  export const ServerFunctionSerializationAdapter = createSerializationAdapter({
6
6
  key: '$TSS/serverfn',
7
- test: (v): v is { functionId: string } => v[TSS_SERVER_FUNCTION],
7
+ test: (v): v is { functionId: string } => {
8
+ if (typeof v !== 'object' || v === null) return false
9
+
10
+ if (!(TSS_SERVER_FUNCTION in v)) return false
11
+
12
+ return !!v[TSS_SERVER_FUNCTION]
13
+ },
8
14
  toSerializable: ({ functionId }) => ({ functionId }),
9
15
  fromSerializable: ({ functionId }) => createClientRpc(functionId),
10
16
  })
@@ -5,7 +5,7 @@ import {
5
5
  } from '@tanstack/router-core'
6
6
  import { FormDataPlugin } from 'seroval-plugins/web'
7
7
  import { getRouterInstance } from '../getRouterInstance'
8
- import type { AnyTransformer } from '@tanstack/router-core'
8
+ import type { AnySerializationAdapter } from '@tanstack/router-core'
9
9
 
10
10
  import type { Plugin } from 'seroval'
11
11
 
@@ -18,7 +18,7 @@ export function getDefaultSerovalPlugins() {
18
18
  const router = getRouterInstance()
19
19
  invariant(router, 'Expected router instance to be available')
20
20
  const adapters = router.options.serializationAdapters as
21
- | Array<AnyTransformer>
21
+ | Array<AnySerializationAdapter>
22
22
  | undefined
23
23
  return [...(adapters?.map(makeSerovalPlugin) ?? []), ...defaultSerovalPlugins]
24
24
  }
@@ -30,6 +30,7 @@ export async function serverFnFetcher(
30
30
  any,
31
31
  any,
32
32
  any,
33
+ any,
33
34
  any
34
35
  > & {
35
36
  headers: HeadersInit
@@ -100,7 +101,7 @@ export async function serverFnFetcher(
100
101
  }
101
102
 
102
103
  async function serializePayload(
103
- opts: FunctionMiddlewareClientFnOptions<any, any, any, any>,
104
+ opts: FunctionMiddlewareClientFnOptions<any, any, any, any, any>,
104
105
  ) {
105
106
  const payloadToSerialize: any = {}
106
107
  if (opts.data) {
@@ -121,7 +122,7 @@ async function serialize(data: any) {
121
122
  }
122
123
 
123
124
  async function getFetcherRequestOptions(
124
- opts: FunctionMiddlewareClientFnOptions<any, any, any, any>,
125
+ opts: FunctionMiddlewareClientFnOptions<any, any, any, any, any>,
125
126
  ) {
126
127
  if (opts.method === 'POST') {
127
128
  if (opts.data instanceof FormData) {
@@ -1,7 +1,7 @@
1
1
  import { describe, expectTypeOf, test } from 'vitest'
2
2
  import { createMiddleware } from '../createMiddleware'
3
3
  import { createServerFn } from '../createServerFn'
4
- import type { Constrain, Validator } from '@tanstack/router-core'
4
+ import type { Constrain, Register, Validator } from '@tanstack/router-core'
5
5
  import type { ConstrainValidator } from '../createServerFn'
6
6
 
7
7
  test('createServerFn method with autocomplete', () => {
@@ -398,7 +398,9 @@ test('createServerFn can validate Date', () => {
398
398
 
399
399
  expectTypeOf(validator)
400
400
  .parameter(0)
401
- .toEqualTypeOf<ConstrainValidator<(input: Date) => { output: 'string' }>>()
401
+ .toEqualTypeOf<
402
+ ConstrainValidator<Register, (input: Date) => { output: 'string' }>
403
+ >()
402
404
  })
403
405
 
404
406
  test('createServerFn can validate FormData', () => {
@@ -409,7 +411,7 @@ test('createServerFn can validate FormData', () => {
409
411
  expectTypeOf(validator)
410
412
  .parameter(0)
411
413
  .toEqualTypeOf<
412
- ConstrainValidator<(input: FormData) => { output: 'string' }>
414
+ ConstrainValidator<Register, (input: FormData) => { output: 'string' }>
413
415
  >()
414
416
  })
415
417
 
@@ -1,8 +1,8 @@
1
1
  import { expectTypeOf, test } from 'vitest'
2
2
  import { createMiddleware } from '../createMiddleware'
3
3
  import type { RequestServerNextFn } from '../createMiddleware'
4
- import type { Constrain, Validator } from '@tanstack/router-core'
5
4
  import type { ConstrainValidator } from '../createServerFn'
5
+ import type { Register } from '@tanstack/router-core'
6
6
 
7
7
  test('createServeMiddleware removes middleware after middleware,', () => {
8
8
  const middleware = createMiddleware({ type: 'function' })
@@ -211,7 +211,7 @@ test('createMiddleware merges client context and sends to the server', () => {
211
211
  expectTypeOf(result).toEqualTypeOf<{
212
212
  'use functions must return the result of next()': true
213
213
  context: { a: boolean; b: string; c: number }
214
- sendContext: { a: boolean; b: string; c: number; d: number }
214
+ sendContext: { a: boolean; b: string; c: number; d: 5 }
215
215
  headers: HeadersInit
216
216
  }>()
217
217
 
@@ -225,7 +225,7 @@ test('createMiddleware merges client context and sends to the server', () => {
225
225
  a: boolean
226
226
  b: string
227
227
  c: number
228
- d: number
228
+ d: 5
229
229
  }>()
230
230
 
231
231
  const result = await options.next({
@@ -242,7 +242,7 @@ test('createMiddleware merges client context and sends to the server', () => {
242
242
  }
243
243
  sendContext: undefined
244
244
  }
245
- context: { a: boolean; b: string; c: number; d: number; e: string }
245
+ context: { a: boolean; b: string; c: number; d: 5; e: string }
246
246
  sendContext: undefined
247
247
  }>()
248
248
 
@@ -586,9 +586,9 @@ test('createMiddleware cannot validate function', () => {
586
586
  expectTypeOf(validator)
587
587
  .parameter(0)
588
588
  .toEqualTypeOf<
589
- Constrain<
590
- (input: { func: () => 'string' }) => { output: 'string' },
591
- Validator<{ func: 'Function is not serializable' }, any>
589
+ ConstrainValidator<
590
+ Register,
591
+ (input: { func: () => 'string' }) => { output: 'string' }
592
592
  >
593
593
  >()
594
594
  })
@@ -600,7 +600,9 @@ test('createMiddleware can validate Date', () => {
600
600
 
601
601
  expectTypeOf(validator)
602
602
  .parameter(0)
603
- .toEqualTypeOf<ConstrainValidator<(input: Date) => { output: 'string' }>>()
603
+ .toEqualTypeOf<
604
+ ConstrainValidator<Register, (input: Date) => { output: 'string' }>
605
+ >()
604
606
  })
605
607
 
606
608
  test('createMiddleware can validate FormData', () => {
@@ -611,7 +613,7 @@ test('createMiddleware can validate FormData', () => {
611
613
  expectTypeOf(validator)
612
614
  .parameter(0)
613
615
  .toEqualTypeOf<
614
- ConstrainValidator<(input: FormData) => { output: 'string' }>
616
+ ConstrainValidator<Register, (input: FormData) => { output: 'string' }>
615
617
  >()
616
618
  })
617
619
 
@@ -1,16 +0,0 @@
1
- export type SerializerStringifyBy<T, TSerializable> = T extends TSerializable ? T : T extends (...args: Array<any>) => any ? 'Function is not serializable' : {
2
- [K in keyof T]: SerializerStringifyBy<T[K], TSerializable>;
3
- };
4
- export type SerializerParseBy<T, TSerializable> = T extends TSerializable ? T : unknown extends SerializerExtensions['ReadableStream'] ? {
5
- [K in keyof T]: SerializerParseBy<T[K], TSerializable>;
6
- } : T extends SerializerExtensions['ReadableStream'] ? ReadableStream : {
7
- [K in keyof T]: SerializerParseBy<T[K], TSerializable>;
8
- };
9
- export interface DefaultSerializerExtensions {
10
- ReadableStream: unknown;
11
- }
12
- export interface SerializerExtensions extends DefaultSerializerExtensions {
13
- }
14
- export type Serializable = Date | undefined | Error | FormData | bigint;
15
- export type SerializerStringify<T> = SerializerStringifyBy<T, Serializable>;
16
- export type SerializerParse<T> = SerializerParseBy<T, Serializable>;
package/src/serializer.ts DELETED
@@ -1,25 +0,0 @@
1
- export type SerializerStringifyBy<T, TSerializable> = T extends TSerializable
2
- ? T
3
- : T extends (...args: Array<any>) => any
4
- ? 'Function is not serializable'
5
- : { [K in keyof T]: SerializerStringifyBy<T[K], TSerializable> }
6
-
7
- export type SerializerParseBy<T, TSerializable> = T extends TSerializable
8
- ? T
9
- : unknown extends SerializerExtensions['ReadableStream']
10
- ? { [K in keyof T]: SerializerParseBy<T[K], TSerializable> }
11
- : T extends SerializerExtensions['ReadableStream']
12
- ? ReadableStream
13
- : { [K in keyof T]: SerializerParseBy<T[K], TSerializable> }
14
-
15
- export interface DefaultSerializerExtensions {
16
- ReadableStream: unknown
17
- }
18
-
19
- export interface SerializerExtensions extends DefaultSerializerExtensions {}
20
-
21
- export type Serializable = Date | undefined | Error | FormData | bigint
22
-
23
- export type SerializerStringify<T> = SerializerStringifyBy<T, Serializable>
24
-
25
- export type SerializerParse<T> = SerializerParseBy<T, Serializable>