@tanstack/start-client-core 1.120.4-alpha.19 → 1.120.5
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 +27 -6
- package/dist/cjs/createMiddleware.cjs +5 -8
- package/dist/cjs/createMiddleware.cjs.map +1 -1
- package/dist/cjs/createMiddleware.d.cts +81 -125
- package/dist/cjs/createServerFn.cjs +0 -1
- package/dist/cjs/createServerFn.cjs.map +1 -1
- package/dist/cjs/createServerFn.d.cts +5 -6
- package/dist/cjs/index.cjs +0 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +2 -2
- package/dist/cjs/registerGlobalMiddleware.cjs.map +1 -1
- package/dist/cjs/registerGlobalMiddleware.d.cts +3 -3
- package/dist/cjs/ssr-client.cjs +25 -24
- package/dist/cjs/ssr-client.cjs.map +1 -1
- package/dist/cjs/ssr-client.d.cts +1 -2
- package/dist/esm/createMiddleware.d.ts +81 -125
- package/dist/esm/createMiddleware.js +5 -8
- package/dist/esm/createMiddleware.js.map +1 -1
- package/dist/esm/createServerFn.d.ts +5 -6
- package/dist/esm/createServerFn.js +0 -1
- package/dist/esm/createServerFn.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +1 -2
- package/dist/esm/registerGlobalMiddleware.d.ts +3 -3
- package/dist/esm/registerGlobalMiddleware.js.map +1 -1
- package/dist/esm/ssr-client.d.ts +1 -2
- package/dist/esm/ssr-client.js +25 -24
- package/dist/esm/ssr-client.js.map +1 -1
- package/package.json +2 -2
- package/src/createMiddleware.ts +368 -479
- package/src/createServerFn.ts +16 -31
- package/src/index.tsx +21 -22
- package/src/registerGlobalMiddleware.ts +3 -3
- package/src/ssr-client.tsx +29 -33
- package/src/tests/createServerFn.test-d.ts +13 -20
- package/src/tests/createServerMiddleware.test-d.ts +73 -186
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { expectTypeOf, test } from 'vitest'
|
|
2
2
|
import { createMiddleware } from '../createMiddleware'
|
|
3
|
-
import type { RequestServerNextFn } from '../createMiddleware'
|
|
4
3
|
import type { Constrain, Validator } from '@tanstack/router-core'
|
|
5
4
|
import type { ConstrainValidator } from '../createServerFn'
|
|
6
5
|
|
|
7
6
|
test('createServeMiddleware removes middleware after middleware,', () => {
|
|
8
|
-
const middleware = createMiddleware(
|
|
7
|
+
const middleware = createMiddleware()
|
|
9
8
|
|
|
10
9
|
expectTypeOf(middleware).toHaveProperty('middleware')
|
|
11
10
|
expectTypeOf(middleware).toHaveProperty('server')
|
|
@@ -46,55 +45,51 @@ test('createServeMiddleware removes middleware after middleware,', () => {
|
|
|
46
45
|
})
|
|
47
46
|
|
|
48
47
|
test('createMiddleware merges server context', () => {
|
|
49
|
-
const middleware1 = createMiddleware(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
expectTypeOf(options.method).toEqualTypeOf<'GET' | 'POST'>()
|
|
48
|
+
const middleware1 = createMiddleware().server(async (options) => {
|
|
49
|
+
expectTypeOf(options.context).toEqualTypeOf<undefined>()
|
|
50
|
+
expectTypeOf(options.data).toEqualTypeOf<undefined>()
|
|
51
|
+
expectTypeOf(options.method).toEqualTypeOf<'GET' | 'POST'>()
|
|
54
52
|
|
|
55
|
-
|
|
53
|
+
const result = await options.next({ context: { a: true } })
|
|
56
54
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
sendContext: undefined
|
|
55
|
+
expectTypeOf(result).toEqualTypeOf<{
|
|
56
|
+
'use functions must return the result of next()': true
|
|
57
|
+
_types: {
|
|
58
|
+
context: {
|
|
59
|
+
a: boolean
|
|
64
60
|
}
|
|
65
|
-
context: { a: boolean }
|
|
66
61
|
sendContext: undefined
|
|
67
|
-
}
|
|
62
|
+
}
|
|
63
|
+
context: { a: boolean }
|
|
64
|
+
sendContext: undefined
|
|
65
|
+
}>()
|
|
68
66
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
)
|
|
67
|
+
return result
|
|
68
|
+
})
|
|
72
69
|
|
|
73
|
-
const middleware2 = createMiddleware(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
expectTypeOf(options.method).toEqualTypeOf<'GET' | 'POST'>()
|
|
70
|
+
const middleware2 = createMiddleware().server(async (options) => {
|
|
71
|
+
expectTypeOf(options.context).toEqualTypeOf<undefined>()
|
|
72
|
+
expectTypeOf(options.data).toEqualTypeOf<undefined>()
|
|
73
|
+
expectTypeOf(options.method).toEqualTypeOf<'GET' | 'POST'>()
|
|
78
74
|
|
|
79
|
-
|
|
75
|
+
const result = await options.next({ context: { b: 'test' } })
|
|
80
76
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
sendContext: undefined
|
|
77
|
+
expectTypeOf(result).toEqualTypeOf<{
|
|
78
|
+
'use functions must return the result of next()': true
|
|
79
|
+
_types: {
|
|
80
|
+
context: {
|
|
81
|
+
b: string
|
|
88
82
|
}
|
|
89
|
-
context: { b: string }
|
|
90
83
|
sendContext: undefined
|
|
91
|
-
}
|
|
84
|
+
}
|
|
85
|
+
context: { b: string }
|
|
86
|
+
sendContext: undefined
|
|
87
|
+
}>()
|
|
92
88
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
)
|
|
89
|
+
return result
|
|
90
|
+
})
|
|
96
91
|
|
|
97
|
-
const middleware3 = createMiddleware(
|
|
92
|
+
const middleware3 = createMiddleware()
|
|
98
93
|
.middleware([middleware1, middleware2])
|
|
99
94
|
.server(async (options) => {
|
|
100
95
|
expectTypeOf(options.context).toEqualTypeOf<{ a: boolean; b: string }>()
|
|
@@ -116,7 +111,7 @@ test('createMiddleware merges server context', () => {
|
|
|
116
111
|
return result
|
|
117
112
|
})
|
|
118
113
|
|
|
119
|
-
createMiddleware(
|
|
114
|
+
createMiddleware()
|
|
120
115
|
.middleware([middleware3])
|
|
121
116
|
.server(async (options) => {
|
|
122
117
|
expectTypeOf(options.context).toEqualTypeOf<{
|
|
@@ -144,41 +139,37 @@ test('createMiddleware merges server context', () => {
|
|
|
144
139
|
})
|
|
145
140
|
|
|
146
141
|
test('createMiddleware merges client context and sends to the server', () => {
|
|
147
|
-
const middleware1 = createMiddleware(
|
|
148
|
-
|
|
149
|
-
expectTypeOf(options.context).toEqualTypeOf<undefined>()
|
|
142
|
+
const middleware1 = createMiddleware().client(async (options) => {
|
|
143
|
+
expectTypeOf(options.context).toEqualTypeOf<undefined>()
|
|
150
144
|
|
|
151
|
-
|
|
145
|
+
const result = await options.next({ context: { a: true } })
|
|
152
146
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
147
|
+
expectTypeOf(result).toEqualTypeOf<{
|
|
148
|
+
'use functions must return the result of next()': true
|
|
149
|
+
context: { a: boolean }
|
|
150
|
+
sendContext: undefined
|
|
151
|
+
headers: HeadersInit
|
|
152
|
+
}>()
|
|
159
153
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
)
|
|
154
|
+
return result
|
|
155
|
+
})
|
|
163
156
|
|
|
164
|
-
const middleware2 = createMiddleware(
|
|
165
|
-
|
|
166
|
-
expectTypeOf(options.context).toEqualTypeOf<undefined>()
|
|
157
|
+
const middleware2 = createMiddleware().client(async (options) => {
|
|
158
|
+
expectTypeOf(options.context).toEqualTypeOf<undefined>()
|
|
167
159
|
|
|
168
|
-
|
|
160
|
+
const result = await options.next({ context: { b: 'test' } })
|
|
169
161
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
162
|
+
expectTypeOf(result).toEqualTypeOf<{
|
|
163
|
+
'use functions must return the result of next()': true
|
|
164
|
+
context: { b: string }
|
|
165
|
+
sendContext: undefined
|
|
166
|
+
headers: HeadersInit
|
|
167
|
+
}>()
|
|
176
168
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
)
|
|
169
|
+
return result
|
|
170
|
+
})
|
|
180
171
|
|
|
181
|
-
const middleware3 = createMiddleware(
|
|
172
|
+
const middleware3 = createMiddleware()
|
|
182
173
|
.middleware([middleware1, middleware2])
|
|
183
174
|
.client(async (options) => {
|
|
184
175
|
expectTypeOf(options.context).toEqualTypeOf<{ a: boolean; b: string }>()
|
|
@@ -195,7 +186,7 @@ test('createMiddleware merges client context and sends to the server', () => {
|
|
|
195
186
|
return result
|
|
196
187
|
})
|
|
197
188
|
|
|
198
|
-
const middleware4 = createMiddleware(
|
|
189
|
+
const middleware4 = createMiddleware()
|
|
199
190
|
.middleware([middleware3])
|
|
200
191
|
.client(async (options) => {
|
|
201
192
|
expectTypeOf(options.context).toEqualTypeOf<{
|
|
@@ -218,7 +209,7 @@ test('createMiddleware merges client context and sends to the server', () => {
|
|
|
218
209
|
return result
|
|
219
210
|
})
|
|
220
211
|
|
|
221
|
-
createMiddleware(
|
|
212
|
+
createMiddleware()
|
|
222
213
|
.middleware([middleware4])
|
|
223
214
|
.server(async (options) => {
|
|
224
215
|
expectTypeOf(options.context).toEqualTypeOf<{
|
|
@@ -251,7 +242,7 @@ test('createMiddleware merges client context and sends to the server', () => {
|
|
|
251
242
|
})
|
|
252
243
|
|
|
253
244
|
test('createMiddleware merges input', () => {
|
|
254
|
-
const middleware1 = createMiddleware(
|
|
245
|
+
const middleware1 = createMiddleware()
|
|
255
246
|
.validator(() => {
|
|
256
247
|
return {
|
|
257
248
|
a: 'a',
|
|
@@ -262,7 +253,7 @@ test('createMiddleware merges input', () => {
|
|
|
262
253
|
return next()
|
|
263
254
|
})
|
|
264
255
|
|
|
265
|
-
const middleware2 = createMiddleware(
|
|
256
|
+
const middleware2 = createMiddleware()
|
|
266
257
|
.middleware([middleware1])
|
|
267
258
|
.validator(() => {
|
|
268
259
|
return {
|
|
@@ -274,7 +265,7 @@ test('createMiddleware merges input', () => {
|
|
|
274
265
|
return next()
|
|
275
266
|
})
|
|
276
267
|
|
|
277
|
-
createMiddleware(
|
|
268
|
+
createMiddleware()
|
|
278
269
|
.middleware([middleware2])
|
|
279
270
|
.validator(() => ({ c: 'c' }) as const)
|
|
280
271
|
.server(({ next, data }) => {
|
|
@@ -288,7 +279,7 @@ test('createMiddleware merges input', () => {
|
|
|
288
279
|
})
|
|
289
280
|
|
|
290
281
|
test('createMiddleware merges server context and client context, sends server context to the client and merges ', () => {
|
|
291
|
-
const middleware1 = createMiddleware(
|
|
282
|
+
const middleware1 = createMiddleware()
|
|
292
283
|
.client(async (options) => {
|
|
293
284
|
expectTypeOf(options.context).toEqualTypeOf<undefined>()
|
|
294
285
|
|
|
@@ -327,7 +318,7 @@ test('createMiddleware merges server context and client context, sends server co
|
|
|
327
318
|
return result
|
|
328
319
|
})
|
|
329
320
|
|
|
330
|
-
const middleware2 = createMiddleware(
|
|
321
|
+
const middleware2 = createMiddleware()
|
|
331
322
|
.client(async (options) => {
|
|
332
323
|
expectTypeOf(options.context).toEqualTypeOf<undefined>()
|
|
333
324
|
|
|
@@ -366,7 +357,7 @@ test('createMiddleware merges server context and client context, sends server co
|
|
|
366
357
|
return result
|
|
367
358
|
})
|
|
368
359
|
|
|
369
|
-
const middleware3 = createMiddleware(
|
|
360
|
+
const middleware3 = createMiddleware()
|
|
370
361
|
.middleware([middleware1, middleware2])
|
|
371
362
|
.client(async (options) => {
|
|
372
363
|
expectTypeOf(options.context).toEqualTypeOf<{
|
|
@@ -420,7 +411,7 @@ test('createMiddleware merges server context and client context, sends server co
|
|
|
420
411
|
return result
|
|
421
412
|
})
|
|
422
413
|
|
|
423
|
-
const middleware4 = createMiddleware(
|
|
414
|
+
const middleware4 = createMiddleware()
|
|
424
415
|
.middleware([middleware3])
|
|
425
416
|
.client(async (options) => {
|
|
426
417
|
expectTypeOf(options.context).toEqualTypeOf<{
|
|
@@ -484,7 +475,7 @@ test('createMiddleware merges server context and client context, sends server co
|
|
|
484
475
|
return result
|
|
485
476
|
})
|
|
486
477
|
|
|
487
|
-
createMiddleware(
|
|
478
|
+
createMiddleware()
|
|
488
479
|
.middleware([middleware4])
|
|
489
480
|
.client(async (options) => {
|
|
490
481
|
expectTypeOf(options.context).toEqualTypeOf<{
|
|
@@ -557,7 +548,7 @@ test('createMiddleware merges server context and client context, sends server co
|
|
|
557
548
|
})
|
|
558
549
|
|
|
559
550
|
test('createMiddleware sendContext cannot send a function', () => {
|
|
560
|
-
createMiddleware(
|
|
551
|
+
createMiddleware()
|
|
561
552
|
.client(({ next }) => {
|
|
562
553
|
expectTypeOf(next<{ func: () => 'func' }>)
|
|
563
554
|
.parameter(0)
|
|
@@ -579,7 +570,7 @@ test('createMiddleware sendContext cannot send a function', () => {
|
|
|
579
570
|
})
|
|
580
571
|
|
|
581
572
|
test('createMiddleware cannot validate function', () => {
|
|
582
|
-
const validator = createMiddleware(
|
|
573
|
+
const validator = createMiddleware().validator<
|
|
583
574
|
(input: { func: () => 'string' }) => { output: 'string' }
|
|
584
575
|
>
|
|
585
576
|
|
|
@@ -594,7 +585,7 @@ test('createMiddleware cannot validate function', () => {
|
|
|
594
585
|
})
|
|
595
586
|
|
|
596
587
|
test('createMiddleware can validate Date', () => {
|
|
597
|
-
const validator = createMiddleware(
|
|
588
|
+
const validator = createMiddleware().validator<
|
|
598
589
|
(input: Date) => { output: 'string' }
|
|
599
590
|
>
|
|
600
591
|
|
|
@@ -604,7 +595,7 @@ test('createMiddleware can validate Date', () => {
|
|
|
604
595
|
})
|
|
605
596
|
|
|
606
597
|
test('createMiddleware can validate FormData', () => {
|
|
607
|
-
const validator = createMiddleware(
|
|
598
|
+
const validator = createMiddleware().validator<
|
|
608
599
|
(input: FormData) => { output: 'string' }
|
|
609
600
|
>
|
|
610
601
|
|
|
@@ -615,22 +606,8 @@ test('createMiddleware can validate FormData', () => {
|
|
|
615
606
|
>()
|
|
616
607
|
})
|
|
617
608
|
|
|
618
|
-
test('createMiddleware merging from parent with undefined validator', () => {
|
|
619
|
-
const middleware1 = createMiddleware({ type: 'function' }).validator(
|
|
620
|
-
(input: { test: string }) => input.test,
|
|
621
|
-
)
|
|
622
|
-
|
|
623
|
-
createMiddleware({ type: 'function' })
|
|
624
|
-
.middleware([middleware1])
|
|
625
|
-
.server((ctx) => {
|
|
626
|
-
expectTypeOf(ctx.data).toEqualTypeOf<string>()
|
|
627
|
-
|
|
628
|
-
return ctx.next()
|
|
629
|
-
})
|
|
630
|
-
})
|
|
631
|
-
|
|
632
609
|
test('createMiddleware validator infers unknown for default input type', () => {
|
|
633
|
-
createMiddleware(
|
|
610
|
+
createMiddleware()
|
|
634
611
|
.validator((input) => {
|
|
635
612
|
expectTypeOf(input).toEqualTypeOf<unknown>()
|
|
636
613
|
|
|
@@ -644,93 +621,3 @@ test('createMiddleware validator infers unknown for default input type', () => {
|
|
|
644
621
|
return next()
|
|
645
622
|
})
|
|
646
623
|
})
|
|
647
|
-
|
|
648
|
-
test('createMiddleware with type request, no middleware or context', () => {
|
|
649
|
-
createMiddleware({ type: 'request' }).server(async (options) => {
|
|
650
|
-
expectTypeOf(options).toEqualTypeOf<{
|
|
651
|
-
request: Request
|
|
652
|
-
next: RequestServerNextFn<undefined>
|
|
653
|
-
pathname: string
|
|
654
|
-
context: undefined
|
|
655
|
-
}>()
|
|
656
|
-
|
|
657
|
-
const result = await options.next()
|
|
658
|
-
|
|
659
|
-
expectTypeOf(result).toEqualTypeOf<{
|
|
660
|
-
context: undefined
|
|
661
|
-
pathname: string
|
|
662
|
-
request: Request
|
|
663
|
-
response: Response
|
|
664
|
-
}>()
|
|
665
|
-
|
|
666
|
-
return result
|
|
667
|
-
})
|
|
668
|
-
})
|
|
669
|
-
|
|
670
|
-
test('createMiddleware with type request, no middleware with context', () => {
|
|
671
|
-
createMiddleware({ type: 'request' }).server(async (options) => {
|
|
672
|
-
expectTypeOf(options).toEqualTypeOf<{
|
|
673
|
-
request: Request
|
|
674
|
-
next: RequestServerNextFn<undefined>
|
|
675
|
-
pathname: string
|
|
676
|
-
context: undefined
|
|
677
|
-
}>()
|
|
678
|
-
|
|
679
|
-
const result = await options.next({ context: { a: 'a' } })
|
|
680
|
-
|
|
681
|
-
expectTypeOf(result).toEqualTypeOf<{
|
|
682
|
-
context: { a: string }
|
|
683
|
-
pathname: string
|
|
684
|
-
request: Request
|
|
685
|
-
response: Response
|
|
686
|
-
}>()
|
|
687
|
-
|
|
688
|
-
return result
|
|
689
|
-
})
|
|
690
|
-
})
|
|
691
|
-
|
|
692
|
-
test('createMiddleware with type request, middleware and context', () => {
|
|
693
|
-
const middleware1 = createMiddleware({ type: 'request' }).server(
|
|
694
|
-
async (options) => {
|
|
695
|
-
expectTypeOf(options).toEqualTypeOf<{
|
|
696
|
-
request: Request
|
|
697
|
-
next: RequestServerNextFn<undefined>
|
|
698
|
-
pathname: string
|
|
699
|
-
context: undefined
|
|
700
|
-
}>()
|
|
701
|
-
|
|
702
|
-
const result = await options.next({ context: { a: 'a' } })
|
|
703
|
-
|
|
704
|
-
expectTypeOf(result).toEqualTypeOf<{
|
|
705
|
-
context: { a: string }
|
|
706
|
-
pathname: string
|
|
707
|
-
request: Request
|
|
708
|
-
response: Response
|
|
709
|
-
}>()
|
|
710
|
-
|
|
711
|
-
return result
|
|
712
|
-
},
|
|
713
|
-
)
|
|
714
|
-
|
|
715
|
-
createMiddleware({ type: 'request' })
|
|
716
|
-
.middleware([middleware1])
|
|
717
|
-
.server(async (options) => {
|
|
718
|
-
expectTypeOf(options).toEqualTypeOf<{
|
|
719
|
-
request: Request
|
|
720
|
-
next: RequestServerNextFn<undefined>
|
|
721
|
-
pathname: string
|
|
722
|
-
context: { a: string }
|
|
723
|
-
}>()
|
|
724
|
-
|
|
725
|
-
const result = await options.next({ context: { b: 'b' } })
|
|
726
|
-
|
|
727
|
-
expectTypeOf(result).toEqualTypeOf<{
|
|
728
|
-
context: { a: string; b: string }
|
|
729
|
-
pathname: string
|
|
730
|
-
request: Request
|
|
731
|
-
response: Response
|
|
732
|
-
}>()
|
|
733
|
-
|
|
734
|
-
return result
|
|
735
|
-
})
|
|
736
|
-
})
|