@tanstack/start-client-core 1.132.0-alpha.9 → 1.132.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/dist/esm/{serializer → client}/ServerFunctionSerializationAdapter.js +2 -2
- package/dist/esm/client/ServerFunctionSerializationAdapter.js.map +1 -0
- package/dist/esm/client/createClientRpc.d.ts +6 -0
- package/dist/esm/{createClientRpc.js → client/createClientRpc.js} +4 -4
- package/dist/esm/client/createClientRpc.js.map +1 -0
- package/dist/esm/client/hydrateStart.d.ts +2 -0
- package/dist/esm/client/hydrateStart.js +29 -0
- package/dist/esm/client/hydrateStart.js.map +1 -0
- package/dist/esm/client/index.d.ts +2 -0
- package/dist/esm/client/index.js +7 -0
- package/dist/esm/client/index.js.map +1 -0
- package/dist/esm/{serverFnFetcher.js → client/serverFnFetcher.js} +6 -6
- package/dist/esm/client/serverFnFetcher.js.map +1 -0
- package/dist/esm/constants.d.ts +1 -0
- package/dist/esm/constants.js +4 -0
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/createMiddleware.d.ts +95 -86
- package/dist/esm/createMiddleware.js +5 -5
- package/dist/esm/createMiddleware.js.map +1 -1
- package/dist/esm/createServerFn.d.ts +63 -69
- package/dist/esm/createServerFn.js +38 -22
- package/dist/esm/createServerFn.js.map +1 -1
- package/dist/esm/createStart.d.ts +27 -0
- package/dist/esm/createStart.js +14 -0
- package/dist/esm/createStart.js.map +1 -0
- package/dist/esm/fake-start-entry.d.ts +5 -0
- package/dist/esm/fake-start-entry.js +11 -0
- package/dist/esm/fake-start-entry.js.map +1 -0
- package/dist/esm/getDefaultSerovalPlugins.d.ts +1 -0
- package/dist/esm/getDefaultSerovalPlugins.js +14 -0
- package/dist/esm/getDefaultSerovalPlugins.js.map +1 -0
- package/dist/esm/getGlobalStartContext.d.ts +3 -0
- package/dist/esm/getGlobalStartContext.js +15 -0
- package/dist/esm/getGlobalStartContext.js.map +1 -0
- package/dist/esm/getRouterInstance.d.ts +2 -1
- package/dist/esm/getRouterInstance.js +1 -1
- package/dist/esm/getRouterInstance.js.map +1 -1
- package/dist/esm/getServerContextAfterGlobalMiddlewares.d.ts +1 -0
- package/dist/esm/getServerContextAfterGlobalMiddlewares.js +10 -0
- package/dist/esm/getServerContextAfterGlobalMiddlewares.js.map +1 -0
- package/dist/esm/getStartOptions.d.ts +1 -0
- package/dist/esm/getStartOptions.js +7 -0
- package/dist/esm/getStartOptions.js.map +1 -0
- package/dist/esm/global.d.ts +7 -0
- package/dist/esm/index.d.ts +11 -6
- package/dist/esm/index.js +9 -9
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/serverRoute.d.ts +66 -0
- package/dist/esm/startEntry.d.ts +8 -0
- package/package.json +18 -5
- package/src/{serializer → client}/ServerFunctionSerializationAdapter.ts +2 -2
- package/src/{createClientRpc.ts → client/createClientRpc.ts} +5 -3
- package/src/client/hydrateStart.ts +33 -0
- package/src/client/index.ts +3 -0
- package/src/{serverFnFetcher.ts → client/serverFnFetcher.ts} +11 -16
- package/src/constants.ts +3 -0
- package/src/createMiddleware.ts +269 -255
- package/src/createServerFn.ts +248 -300
- package/src/createStart.ts +122 -0
- package/src/fake-start-entry.ts +4 -0
- package/src/getDefaultSerovalPlugins.ts +17 -0
- package/src/getGlobalStartContext.ts +18 -0
- package/src/getRouterInstance.ts +5 -4
- package/src/getServerContextAfterGlobalMiddlewares.ts +7 -0
- package/src/getStartOptions.ts +6 -0
- package/src/global.ts +9 -0
- package/src/index.tsx +12 -11
- package/src/serverRoute.ts +474 -0
- package/src/start-entry.d.ts +11 -0
- package/src/startEntry.ts +10 -0
- package/src/tests/createServerFn.test-d.ts +68 -128
- package/src/tests/createServerMiddleware.test-d.ts +22 -17
- package/dist/esm/createClientRpc.d.ts +0 -6
- package/dist/esm/createClientRpc.js.map +0 -1
- package/dist/esm/registerGlobalMiddleware.d.ts +0 -5
- package/dist/esm/registerGlobalMiddleware.js +0 -9
- package/dist/esm/registerGlobalMiddleware.js.map +0 -1
- package/dist/esm/serializer/ServerFunctionSerializationAdapter.js.map +0 -1
- package/dist/esm/serializer/getClientSerovalPlugins.d.ts +0 -3
- package/dist/esm/serializer/getClientSerovalPlugins.js +0 -13
- package/dist/esm/serializer/getClientSerovalPlugins.js.map +0 -1
- package/dist/esm/serializer/getDefaultSerovalPlugins.d.ts +0 -3
- package/dist/esm/serializer/getDefaultSerovalPlugins.js +0 -19
- package/dist/esm/serializer/getDefaultSerovalPlugins.js.map +0 -1
- package/dist/esm/serverFnFetcher.js.map +0 -1
- package/src/registerGlobalMiddleware.ts +0 -9
- package/src/serializer/getClientSerovalPlugins.ts +0 -10
- package/src/serializer/getDefaultSerovalPlugins.ts +0 -24
- /package/dist/esm/{serializer → client}/ServerFunctionSerializationAdapter.d.ts +0 -0
- /package/dist/esm/{serverFnFetcher.d.ts → client/serverFnFetcher.d.ts} +0 -0
|
@@ -13,7 +13,7 @@ test('createServerFn method with autocomplete', () => {
|
|
|
13
13
|
test('createServerFn without middleware', () => {
|
|
14
14
|
expectTypeOf(createServerFn()).toHaveProperty('handler')
|
|
15
15
|
expectTypeOf(createServerFn()).toHaveProperty('middleware')
|
|
16
|
-
expectTypeOf(createServerFn()).toHaveProperty('
|
|
16
|
+
expectTypeOf(createServerFn()).toHaveProperty('inputValidator')
|
|
17
17
|
|
|
18
18
|
createServerFn({ method: 'GET' }).handler((options) => {
|
|
19
19
|
expectTypeOf(options).toEqualTypeOf<{
|
|
@@ -21,7 +21,6 @@ test('createServerFn without middleware', () => {
|
|
|
21
21
|
context: undefined
|
|
22
22
|
data: undefined
|
|
23
23
|
signal: AbortSignal
|
|
24
|
-
response: 'data'
|
|
25
24
|
}>()
|
|
26
25
|
})
|
|
27
26
|
})
|
|
@@ -29,13 +28,13 @@ test('createServerFn without middleware', () => {
|
|
|
29
28
|
test('createServerFn with validator', () => {
|
|
30
29
|
const fnAfterValidator = createServerFn({
|
|
31
30
|
method: 'GET',
|
|
32
|
-
}).
|
|
31
|
+
}).inputValidator((input: { input: string }) => ({
|
|
33
32
|
a: input.input,
|
|
34
33
|
}))
|
|
35
34
|
|
|
36
35
|
expectTypeOf(fnAfterValidator).toHaveProperty('handler')
|
|
37
36
|
expectTypeOf(fnAfterValidator).toHaveProperty('middleware')
|
|
38
|
-
expectTypeOf(fnAfterValidator).not.toHaveProperty('
|
|
37
|
+
expectTypeOf(fnAfterValidator).not.toHaveProperty('inputValidator')
|
|
39
38
|
|
|
40
39
|
const fn = fnAfterValidator.handler((options) => {
|
|
41
40
|
expectTypeOf(options).toEqualTypeOf<{
|
|
@@ -45,7 +44,6 @@ test('createServerFn with validator', () => {
|
|
|
45
44
|
a: string
|
|
46
45
|
}
|
|
47
46
|
signal: AbortSignal
|
|
48
|
-
response: 'data'
|
|
49
47
|
}>()
|
|
50
48
|
})
|
|
51
49
|
|
|
@@ -96,7 +94,7 @@ test('createServerFn with middleware and context', () => {
|
|
|
96
94
|
])
|
|
97
95
|
|
|
98
96
|
expectTypeOf(fnWithMiddleware).toHaveProperty('handler')
|
|
99
|
-
expectTypeOf(fnWithMiddleware).toHaveProperty('
|
|
97
|
+
expectTypeOf(fnWithMiddleware).toHaveProperty('inputValidator')
|
|
100
98
|
|
|
101
99
|
fnWithMiddleware.handler((options) => {
|
|
102
100
|
expectTypeOf(options).toEqualTypeOf<{
|
|
@@ -109,20 +107,19 @@ test('createServerFn with middleware and context', () => {
|
|
|
109
107
|
}
|
|
110
108
|
data: undefined
|
|
111
109
|
signal: AbortSignal
|
|
112
|
-
response: 'data'
|
|
113
110
|
}>()
|
|
114
111
|
})
|
|
115
112
|
})
|
|
116
113
|
|
|
117
114
|
describe('createServerFn with middleware and validator', () => {
|
|
118
|
-
const middleware1 = createMiddleware({ type: 'function' }).
|
|
115
|
+
const middleware1 = createMiddleware({ type: 'function' }).inputValidator(
|
|
119
116
|
(input: { readonly inputA: 'inputA' }) =>
|
|
120
117
|
({
|
|
121
118
|
outputA: 'outputA',
|
|
122
119
|
}) as const,
|
|
123
120
|
)
|
|
124
121
|
|
|
125
|
-
const middleware2 = createMiddleware({ type: 'function' }).
|
|
122
|
+
const middleware2 = createMiddleware({ type: 'function' }).inputValidator(
|
|
126
123
|
(input: { readonly inputB: 'inputB' }) =>
|
|
127
124
|
({
|
|
128
125
|
outputB: 'outputB',
|
|
@@ -134,10 +131,10 @@ describe('createServerFn with middleware and validator', () => {
|
|
|
134
131
|
middleware2,
|
|
135
132
|
])
|
|
136
133
|
|
|
137
|
-
test(`response
|
|
138
|
-
const fn = createServerFn({ method: 'GET'
|
|
134
|
+
test(`response`, () => {
|
|
135
|
+
const fn = createServerFn({ method: 'GET' })
|
|
139
136
|
.middleware([middleware3])
|
|
140
|
-
.
|
|
137
|
+
.inputValidator(
|
|
141
138
|
(input: { readonly inputC: 'inputC' }) =>
|
|
142
139
|
({
|
|
143
140
|
outputC: 'outputC',
|
|
@@ -153,7 +150,6 @@ describe('createServerFn with middleware and validator', () => {
|
|
|
153
150
|
readonly outputC: 'outputC'
|
|
154
151
|
}
|
|
155
152
|
signal: AbortSignal
|
|
156
|
-
response: 'data'
|
|
157
153
|
}>()
|
|
158
154
|
|
|
159
155
|
return 'some-data' as const
|
|
@@ -176,57 +172,11 @@ describe('createServerFn with middleware and validator', () => {
|
|
|
176
172
|
}),
|
|
177
173
|
).returns.resolves.toEqualTypeOf<'some-data'>()
|
|
178
174
|
})
|
|
179
|
-
|
|
180
|
-
test(`response: 'full'`, () => {
|
|
181
|
-
const fn = createServerFn({ method: 'GET', response: 'full' })
|
|
182
|
-
.middleware([middleware3])
|
|
183
|
-
.validator(
|
|
184
|
-
(input: { readonly inputC: 'inputC' }) =>
|
|
185
|
-
({
|
|
186
|
-
outputC: 'outputC',
|
|
187
|
-
}) as const,
|
|
188
|
-
)
|
|
189
|
-
.handler((options) => {
|
|
190
|
-
expectTypeOf(options).toEqualTypeOf<{
|
|
191
|
-
method: 'GET'
|
|
192
|
-
context: undefined
|
|
193
|
-
data: {
|
|
194
|
-
readonly outputA: 'outputA'
|
|
195
|
-
readonly outputB: 'outputB'
|
|
196
|
-
readonly outputC: 'outputC'
|
|
197
|
-
}
|
|
198
|
-
signal: AbortSignal
|
|
199
|
-
response: 'full'
|
|
200
|
-
}>()
|
|
201
|
-
|
|
202
|
-
return 'some-data' as const
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
expectTypeOf(fn).parameter(0).toEqualTypeOf<{
|
|
206
|
-
data: {
|
|
207
|
-
readonly inputA: 'inputA'
|
|
208
|
-
readonly inputB: 'inputB'
|
|
209
|
-
readonly inputC: 'inputC'
|
|
210
|
-
}
|
|
211
|
-
headers?: HeadersInit
|
|
212
|
-
signal?: AbortSignal
|
|
213
|
-
}>()
|
|
214
|
-
|
|
215
|
-
expectTypeOf(() =>
|
|
216
|
-
fn({
|
|
217
|
-
data: { inputA: 'inputA', inputB: 'inputB', inputC: 'inputC' },
|
|
218
|
-
}),
|
|
219
|
-
).returns.resolves.toEqualTypeOf<{
|
|
220
|
-
result: 'some-data'
|
|
221
|
-
context: undefined
|
|
222
|
-
error: unknown
|
|
223
|
-
}>()
|
|
224
|
-
})
|
|
225
175
|
})
|
|
226
176
|
|
|
227
177
|
test('createServerFn overrides properties', () => {
|
|
228
178
|
const middleware1 = createMiddleware({ type: 'function' })
|
|
229
|
-
.
|
|
179
|
+
.inputValidator(
|
|
230
180
|
() =>
|
|
231
181
|
({
|
|
232
182
|
input: 'a' as 'a' | 'b' | 'c',
|
|
@@ -251,7 +201,7 @@ test('createServerFn overrides properties', () => {
|
|
|
251
201
|
|
|
252
202
|
const middleware2 = createMiddleware({ type: 'function' })
|
|
253
203
|
.middleware([middleware1])
|
|
254
|
-
.
|
|
204
|
+
.inputValidator(
|
|
255
205
|
() =>
|
|
256
206
|
({
|
|
257
207
|
input: 'b' as 'b' | 'c',
|
|
@@ -274,7 +224,7 @@ test('createServerFn overrides properties', () => {
|
|
|
274
224
|
|
|
275
225
|
createServerFn()
|
|
276
226
|
.middleware([middleware2])
|
|
277
|
-
.
|
|
227
|
+
.inputValidator(
|
|
278
228
|
() =>
|
|
279
229
|
({
|
|
280
230
|
input: 'c',
|
|
@@ -290,28 +240,26 @@ test('createServerFn overrides properties', () => {
|
|
|
290
240
|
|
|
291
241
|
test('createServerFn where validator is a primitive', () => {
|
|
292
242
|
createServerFn({ method: 'GET' })
|
|
293
|
-
.
|
|
243
|
+
.inputValidator(() => 'c' as const)
|
|
294
244
|
.handler((options) => {
|
|
295
245
|
expectTypeOf(options).toEqualTypeOf<{
|
|
296
246
|
method: 'GET'
|
|
297
247
|
context: undefined
|
|
298
248
|
data: 'c'
|
|
299
249
|
signal: AbortSignal
|
|
300
|
-
response: 'data'
|
|
301
250
|
}>()
|
|
302
251
|
})
|
|
303
252
|
})
|
|
304
253
|
|
|
305
254
|
test('createServerFn where validator is optional if object is optional', () => {
|
|
306
255
|
const fn = createServerFn({ method: 'GET' })
|
|
307
|
-
.
|
|
256
|
+
.inputValidator((input: 'c' | undefined) => input)
|
|
308
257
|
.handler((options) => {
|
|
309
258
|
expectTypeOf(options).toEqualTypeOf<{
|
|
310
259
|
method: 'GET'
|
|
311
260
|
context: undefined
|
|
312
261
|
data: 'c' | undefined
|
|
313
262
|
signal: AbortSignal
|
|
314
|
-
response: 'data'
|
|
315
263
|
}>()
|
|
316
264
|
})
|
|
317
265
|
|
|
@@ -334,7 +282,6 @@ test('createServerFn where data is optional if there is no validator', () => {
|
|
|
334
282
|
context: undefined
|
|
335
283
|
data: undefined
|
|
336
284
|
signal: AbortSignal
|
|
337
|
-
response: 'data'
|
|
338
285
|
}>()
|
|
339
286
|
})
|
|
340
287
|
|
|
@@ -370,13 +317,14 @@ test('createServerFn cannot return function', () => {
|
|
|
370
317
|
expectTypeOf(createServerFn().handler<{ func: () => 'func' }>)
|
|
371
318
|
.parameter(0)
|
|
372
319
|
.returns.toEqualTypeOf<
|
|
320
|
+
| Response
|
|
373
321
|
| { func: 'Function is not serializable' }
|
|
374
322
|
| Promise<{ func: 'Function is not serializable' }>
|
|
375
323
|
>()
|
|
376
324
|
})
|
|
377
325
|
|
|
378
326
|
test('createServerFn cannot validate function', () => {
|
|
379
|
-
const validator = createServerFn().
|
|
327
|
+
const validator = createServerFn().inputValidator<
|
|
380
328
|
(input: { func: () => 'string' }) => { output: 'string' }
|
|
381
329
|
>
|
|
382
330
|
|
|
@@ -391,87 +339,49 @@ test('createServerFn cannot validate function', () => {
|
|
|
391
339
|
})
|
|
392
340
|
|
|
393
341
|
test('createServerFn can validate Date', () => {
|
|
394
|
-
const validator = createServerFn().
|
|
342
|
+
const validator = createServerFn().inputValidator<
|
|
395
343
|
(input: Date) => { output: 'string' }
|
|
396
344
|
>
|
|
397
345
|
|
|
398
346
|
expectTypeOf(validator)
|
|
399
347
|
.parameter(0)
|
|
400
348
|
.toEqualTypeOf<
|
|
401
|
-
ConstrainValidator<Register, (input: Date) => { output: 'string' }>
|
|
349
|
+
ConstrainValidator<Register, 'GET', (input: Date) => { output: 'string' }>
|
|
402
350
|
>()
|
|
403
351
|
})
|
|
404
352
|
|
|
405
353
|
test('createServerFn can validate FormData', () => {
|
|
406
|
-
const validator = createServerFn().
|
|
354
|
+
const validator = createServerFn({ method: 'POST' }).inputValidator<
|
|
355
|
+
(input: FormData) => { output: 'string' }
|
|
356
|
+
>
|
|
357
|
+
|
|
358
|
+
expectTypeOf(validator).parameter(0).parameter(0).toEqualTypeOf<FormData>()
|
|
359
|
+
})
|
|
360
|
+
|
|
361
|
+
test('createServerFn cannot validate FormData for GET', () => {
|
|
362
|
+
const validator = createServerFn({ method: 'GET' }).inputValidator<
|
|
407
363
|
(input: FormData) => { output: 'string' }
|
|
408
364
|
>
|
|
409
365
|
|
|
410
366
|
expectTypeOf(validator)
|
|
411
367
|
.parameter(0)
|
|
412
|
-
.
|
|
413
|
-
|
|
414
|
-
>()
|
|
368
|
+
.parameter(0)
|
|
369
|
+
.not.toEqualTypeOf<FormData>()
|
|
415
370
|
})
|
|
416
371
|
|
|
417
372
|
describe('response', () => {
|
|
418
|
-
describe('data', () => {
|
|
419
|
-
test(`response: 'data' is passed into handler without response being set`, () => {
|
|
420
|
-
createServerFn().handler((options) => {
|
|
421
|
-
expectTypeOf(options.response).toEqualTypeOf<'data'>()
|
|
422
|
-
})
|
|
423
|
-
})
|
|
424
|
-
|
|
425
|
-
test(`response: 'data' is passed into handler with explicit response: 'data'`, () => {
|
|
426
|
-
createServerFn({ response: 'data' }).handler((options) => {
|
|
427
|
-
expectTypeOf(options.response).toEqualTypeOf<'data'>()
|
|
428
|
-
})
|
|
429
|
-
})
|
|
430
|
-
})
|
|
431
|
-
describe('full', () => {
|
|
432
|
-
test(`response: 'full' is passed into handler`, () => {
|
|
433
|
-
createServerFn({ response: 'full' }).handler((options) => {
|
|
434
|
-
expectTypeOf(options.response).toEqualTypeOf<'full'>()
|
|
435
|
-
})
|
|
436
|
-
})
|
|
437
|
-
})
|
|
438
|
-
|
|
439
|
-
describe('raw', () => {
|
|
440
|
-
test(`response: 'raw' is passed into handler`, () => {
|
|
441
|
-
createServerFn({ response: 'raw' }).handler((options) => {
|
|
442
|
-
expectTypeOf(options.response).toEqualTypeOf<'raw'>()
|
|
443
|
-
return null
|
|
444
|
-
})
|
|
445
|
-
})
|
|
446
|
-
})
|
|
447
373
|
test(`client receives Response when Response is returned`, () => {
|
|
448
|
-
const fn = createServerFn(
|
|
374
|
+
const fn = createServerFn().handler(() => {
|
|
449
375
|
return new Response('Hello World')
|
|
450
376
|
})
|
|
451
377
|
|
|
452
378
|
expectTypeOf(fn()).toEqualTypeOf<Promise<Response>>()
|
|
453
379
|
})
|
|
454
|
-
|
|
455
|
-
test(`client receives Response when ReadableStream is returned`, () => {
|
|
456
|
-
const fn = createServerFn({ response: 'raw' }).handler(() => {
|
|
457
|
-
return new ReadableStream()
|
|
458
|
-
})
|
|
459
|
-
|
|
460
|
-
expectTypeOf(fn()).toEqualTypeOf<Promise<Response>>()
|
|
461
|
-
})
|
|
462
|
-
|
|
463
|
-
test(`client receives Response when string is returned`, () => {
|
|
464
|
-
const fn = createServerFn({ response: 'raw' }).handler(() => {
|
|
465
|
-
return 'hello'
|
|
466
|
-
})
|
|
467
|
-
|
|
468
|
-
expectTypeOf(fn()).toEqualTypeOf<Promise<Response>>()
|
|
469
|
-
})
|
|
470
380
|
})
|
|
471
381
|
|
|
472
382
|
test('createServerFn can be used as a mutation function', () => {
|
|
473
383
|
const serverFn = createServerFn()
|
|
474
|
-
.
|
|
384
|
+
.inputValidator((data: number) => data)
|
|
475
385
|
.handler(() => 'foo')
|
|
476
386
|
|
|
477
387
|
type MutationFunction<TData = unknown, TVariables = unknown> = (
|
|
@@ -488,7 +398,7 @@ test('createServerFn can be used as a mutation function', () => {
|
|
|
488
398
|
|
|
489
399
|
test('createServerFn validator infers unknown for default input type', () => {
|
|
490
400
|
const fn = createServerFn()
|
|
491
|
-
.
|
|
401
|
+
.inputValidator((input) => {
|
|
492
402
|
expectTypeOf(input).toEqualTypeOf<unknown>()
|
|
493
403
|
|
|
494
404
|
if (typeof input === 'number') return 'success' as const
|
|
@@ -537,7 +447,7 @@ test('incrementally building createServerFn with multiple middleware calls', ()
|
|
|
537
447
|
])
|
|
538
448
|
|
|
539
449
|
expectTypeOf(builderWithMw1).toHaveProperty('handler')
|
|
540
|
-
expectTypeOf(builderWithMw1).toHaveProperty('
|
|
450
|
+
expectTypeOf(builderWithMw1).toHaveProperty('inputValidator')
|
|
541
451
|
expectTypeOf(builderWithMw1).toHaveProperty('middleware')
|
|
542
452
|
|
|
543
453
|
builderWithMw1.handler((options) => {
|
|
@@ -548,7 +458,6 @@ test('incrementally building createServerFn with multiple middleware calls', ()
|
|
|
548
458
|
}
|
|
549
459
|
data: undefined
|
|
550
460
|
signal: AbortSignal
|
|
551
|
-
response: 'data'
|
|
552
461
|
}>()
|
|
553
462
|
})
|
|
554
463
|
|
|
@@ -558,7 +467,7 @@ test('incrementally building createServerFn with multiple middleware calls', ()
|
|
|
558
467
|
])
|
|
559
468
|
|
|
560
469
|
expectTypeOf(builderWithMw2).toHaveProperty('handler')
|
|
561
|
-
expectTypeOf(builderWithMw2).toHaveProperty('
|
|
470
|
+
expectTypeOf(builderWithMw2).toHaveProperty('inputValidator')
|
|
562
471
|
expectTypeOf(builderWithMw2).toHaveProperty('middleware')
|
|
563
472
|
|
|
564
473
|
builderWithMw2.handler((options) => {
|
|
@@ -570,7 +479,6 @@ test('incrementally building createServerFn with multiple middleware calls', ()
|
|
|
570
479
|
}
|
|
571
480
|
data: undefined
|
|
572
481
|
signal: AbortSignal
|
|
573
|
-
response: 'data'
|
|
574
482
|
}>()
|
|
575
483
|
})
|
|
576
484
|
|
|
@@ -580,7 +488,7 @@ test('incrementally building createServerFn with multiple middleware calls', ()
|
|
|
580
488
|
])
|
|
581
489
|
|
|
582
490
|
expectTypeOf(builderWithMw3).toHaveProperty('handler')
|
|
583
|
-
expectTypeOf(builderWithMw3).toHaveProperty('
|
|
491
|
+
expectTypeOf(builderWithMw3).toHaveProperty('inputValidator')
|
|
584
492
|
expectTypeOf(builderWithMw3).toHaveProperty('middleware')
|
|
585
493
|
|
|
586
494
|
builderWithMw3.handler((options) => {
|
|
@@ -593,7 +501,39 @@ test('incrementally building createServerFn with multiple middleware calls', ()
|
|
|
593
501
|
}
|
|
594
502
|
data: undefined
|
|
595
503
|
signal: AbortSignal
|
|
596
|
-
|
|
504
|
+
}>()
|
|
505
|
+
})
|
|
506
|
+
})
|
|
507
|
+
|
|
508
|
+
test('compose middlewares and server function factories', () => {
|
|
509
|
+
const middleware1 = createMiddleware({ type: 'function' }).server(
|
|
510
|
+
({ next }) => {
|
|
511
|
+
return next({ context: { a: 'a' } as const })
|
|
512
|
+
},
|
|
513
|
+
)
|
|
514
|
+
|
|
515
|
+
const middleware2 = createMiddleware({ type: 'function' }).server(
|
|
516
|
+
({ next }) => {
|
|
517
|
+
return next({ context: { b: 'b' } as const })
|
|
518
|
+
},
|
|
519
|
+
)
|
|
520
|
+
|
|
521
|
+
const builderWithMw1 = createServerFn().middleware([middleware1])
|
|
522
|
+
|
|
523
|
+
const composedBuilder = createServerFn({ method: 'GET' }).middleware([
|
|
524
|
+
middleware2,
|
|
525
|
+
builderWithMw1,
|
|
526
|
+
])
|
|
527
|
+
|
|
528
|
+
composedBuilder.handler((options) => {
|
|
529
|
+
expectTypeOf(options).toEqualTypeOf<{
|
|
530
|
+
method: 'GET'
|
|
531
|
+
context: {
|
|
532
|
+
readonly a: 'a'
|
|
533
|
+
readonly b: 'b'
|
|
534
|
+
}
|
|
535
|
+
data: undefined
|
|
536
|
+
signal: AbortSignal
|
|
597
537
|
}>()
|
|
598
538
|
})
|
|
599
539
|
})
|
|
@@ -9,15 +9,15 @@ test('createServeMiddleware removes middleware after middleware,', () => {
|
|
|
9
9
|
|
|
10
10
|
expectTypeOf(middleware).toHaveProperty('middleware')
|
|
11
11
|
expectTypeOf(middleware).toHaveProperty('server')
|
|
12
|
-
expectTypeOf(middleware).toHaveProperty('
|
|
12
|
+
expectTypeOf(middleware).toHaveProperty('inputValidator')
|
|
13
13
|
|
|
14
14
|
const middlewareAfterMiddleware = middleware.middleware([])
|
|
15
15
|
|
|
16
|
-
expectTypeOf(middlewareAfterMiddleware).toHaveProperty('
|
|
16
|
+
expectTypeOf(middlewareAfterMiddleware).toHaveProperty('inputValidator')
|
|
17
17
|
expectTypeOf(middlewareAfterMiddleware).toHaveProperty('server')
|
|
18
18
|
expectTypeOf(middlewareAfterMiddleware).not.toHaveProperty('middleware')
|
|
19
19
|
|
|
20
|
-
const middlewareAfterInput = middleware.
|
|
20
|
+
const middlewareAfterInput = middleware.inputValidator(() => {})
|
|
21
21
|
|
|
22
22
|
expectTypeOf(middlewareAfterInput).toHaveProperty('server')
|
|
23
23
|
expectTypeOf(middlewareAfterInput).not.toHaveProperty('middleware')
|
|
@@ -252,7 +252,7 @@ test('createMiddleware merges client context and sends to the server', () => {
|
|
|
252
252
|
|
|
253
253
|
test('createMiddleware merges input', () => {
|
|
254
254
|
const middleware1 = createMiddleware({ type: 'function' })
|
|
255
|
-
.
|
|
255
|
+
.inputValidator(() => {
|
|
256
256
|
return {
|
|
257
257
|
a: 'a',
|
|
258
258
|
} as const
|
|
@@ -264,7 +264,7 @@ test('createMiddleware merges input', () => {
|
|
|
264
264
|
|
|
265
265
|
const middleware2 = createMiddleware({ type: 'function' })
|
|
266
266
|
.middleware([middleware1])
|
|
267
|
-
.
|
|
267
|
+
.inputValidator(() => {
|
|
268
268
|
return {
|
|
269
269
|
b: 'b',
|
|
270
270
|
} as const
|
|
@@ -276,7 +276,7 @@ test('createMiddleware merges input', () => {
|
|
|
276
276
|
|
|
277
277
|
createMiddleware({ type: 'function' })
|
|
278
278
|
.middleware([middleware2])
|
|
279
|
-
.
|
|
279
|
+
.inputValidator(() => ({ c: 'c' }) as const)
|
|
280
280
|
.server(({ next, data }) => {
|
|
281
281
|
expectTypeOf(data).toEqualTypeOf<{
|
|
282
282
|
readonly a: 'a'
|
|
@@ -579,7 +579,7 @@ test('createMiddleware sendContext cannot send a function', () => {
|
|
|
579
579
|
})
|
|
580
580
|
|
|
581
581
|
test('createMiddleware cannot validate function', () => {
|
|
582
|
-
const validator = createMiddleware({ type: 'function' }).
|
|
582
|
+
const validator = createMiddleware({ type: 'function' }).inputValidator<
|
|
583
583
|
(input: { func: () => 'string' }) => { output: 'string' }
|
|
584
584
|
>
|
|
585
585
|
|
|
@@ -588,37 +588,42 @@ test('createMiddleware cannot validate function', () => {
|
|
|
588
588
|
.toEqualTypeOf<
|
|
589
589
|
ConstrainValidator<
|
|
590
590
|
Register,
|
|
591
|
+
'GET',
|
|
591
592
|
(input: { func: () => 'string' }) => { output: 'string' }
|
|
592
593
|
>
|
|
593
594
|
>()
|
|
594
595
|
})
|
|
595
596
|
|
|
596
597
|
test('createMiddleware can validate Date', () => {
|
|
597
|
-
const validator = createMiddleware({ type: 'function' }).
|
|
598
|
+
const validator = createMiddleware({ type: 'function' }).inputValidator<
|
|
598
599
|
(input: Date) => { output: 'string' }
|
|
599
600
|
>
|
|
600
601
|
|
|
601
602
|
expectTypeOf(validator)
|
|
602
603
|
.parameter(0)
|
|
603
604
|
.toEqualTypeOf<
|
|
604
|
-
ConstrainValidator<Register, (input: Date) => { output: 'string' }>
|
|
605
|
+
ConstrainValidator<Register, 'GET', (input: Date) => { output: 'string' }>
|
|
605
606
|
>()
|
|
606
607
|
})
|
|
607
608
|
|
|
608
609
|
test('createMiddleware can validate FormData', () => {
|
|
609
|
-
const validator = createMiddleware({ type: 'function' }).
|
|
610
|
+
const validator = createMiddleware({ type: 'function' }).inputValidator<
|
|
610
611
|
(input: FormData) => { output: 'string' }
|
|
611
612
|
>
|
|
612
613
|
|
|
613
614
|
expectTypeOf(validator)
|
|
614
615
|
.parameter(0)
|
|
615
616
|
.toEqualTypeOf<
|
|
616
|
-
ConstrainValidator<
|
|
617
|
+
ConstrainValidator<
|
|
618
|
+
Register,
|
|
619
|
+
'GET',
|
|
620
|
+
(input: FormData) => { output: 'string' }
|
|
621
|
+
>
|
|
617
622
|
>()
|
|
618
623
|
})
|
|
619
624
|
|
|
620
625
|
test('createMiddleware merging from parent with undefined validator', () => {
|
|
621
|
-
const middleware1 = createMiddleware({ type: 'function' }).
|
|
626
|
+
const middleware1 = createMiddleware({ type: 'function' }).inputValidator(
|
|
622
627
|
(input: { test: string }) => input.test,
|
|
623
628
|
)
|
|
624
629
|
|
|
@@ -633,7 +638,7 @@ test('createMiddleware merging from parent with undefined validator', () => {
|
|
|
633
638
|
|
|
634
639
|
test('createMiddleware validator infers unknown for default input type', () => {
|
|
635
640
|
createMiddleware({ type: 'function' })
|
|
636
|
-
.
|
|
641
|
+
.inputValidator((input) => {
|
|
637
642
|
expectTypeOf(input).toEqualTypeOf<unknown>()
|
|
638
643
|
|
|
639
644
|
if (typeof input === 'number') return 'success' as const
|
|
@@ -651,7 +656,7 @@ test('createMiddleware with type request, no middleware or context', () => {
|
|
|
651
656
|
createMiddleware({ type: 'request' }).server(async (options) => {
|
|
652
657
|
expectTypeOf(options).toEqualTypeOf<{
|
|
653
658
|
request: Request
|
|
654
|
-
next: RequestServerNextFn<undefined>
|
|
659
|
+
next: RequestServerNextFn<{}, undefined>
|
|
655
660
|
pathname: string
|
|
656
661
|
context: undefined
|
|
657
662
|
}>()
|
|
@@ -673,7 +678,7 @@ test('createMiddleware with type request, no middleware with context', () => {
|
|
|
673
678
|
createMiddleware({ type: 'request' }).server(async (options) => {
|
|
674
679
|
expectTypeOf(options).toEqualTypeOf<{
|
|
675
680
|
request: Request
|
|
676
|
-
next: RequestServerNextFn<undefined>
|
|
681
|
+
next: RequestServerNextFn<{}, undefined>
|
|
677
682
|
pathname: string
|
|
678
683
|
context: undefined
|
|
679
684
|
}>()
|
|
@@ -696,7 +701,7 @@ test('createMiddleware with type request, middleware and context', () => {
|
|
|
696
701
|
async (options) => {
|
|
697
702
|
expectTypeOf(options).toEqualTypeOf<{
|
|
698
703
|
request: Request
|
|
699
|
-
next: RequestServerNextFn<undefined>
|
|
704
|
+
next: RequestServerNextFn<{}, undefined>
|
|
700
705
|
pathname: string
|
|
701
706
|
context: undefined
|
|
702
707
|
}>()
|
|
@@ -719,7 +724,7 @@ test('createMiddleware with type request, middleware and context', () => {
|
|
|
719
724
|
.server(async (options) => {
|
|
720
725
|
expectTypeOf(options).toEqualTypeOf<{
|
|
721
726
|
request: Request
|
|
722
|
-
next: RequestServerNextFn<undefined>
|
|
727
|
+
next: RequestServerNextFn<{}, undefined>
|
|
723
728
|
pathname: string
|
|
724
729
|
context: { a: string }
|
|
725
730
|
}>()
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createClientRpc.js","sources":["../../src/createClientRpc.ts"],"sourcesContent":["import { TSS_SERVER_FUNCTION } from './constants'\nimport { serverFnFetcher } from './serverFnFetcher'\n\nlet baseUrl: string\nfunction sanitizeBase(base: string) {\n return base.replace(/^\\/|\\/$/g, '')\n}\n\nexport const createClientRpc = (functionId: string) => {\n if (!baseUrl) {\n const sanitizedAppBase = sanitizeBase(process.env.TSS_APP_BASE || '/')\n const sanitizedServerBase = sanitizeBase(process.env.TSS_SERVER_FN_BASE!)\n baseUrl = `${sanitizedAppBase ? `/${sanitizedAppBase}` : ''}/${sanitizedServerBase}/`\n }\n const url = baseUrl + functionId\n\n const clientFn = (...args: Array<any>) => {\n return serverFnFetcher(url, args, fetch)\n }\n\n return Object.assign(clientFn, {\n url,\n functionId,\n [TSS_SERVER_FUNCTION]: true,\n })\n}\n"],"names":[],"mappings":";;AAGA,IAAI;AACJ,SAAS,aAAa,MAAc;AAClC,SAAO,KAAK,QAAQ,YAAY,EAAE;AACpC;AAEO,MAAM,kBAAkB,CAAC,eAAuB;AACrD,MAAI,CAAC,SAAS;AACZ,UAAM,mBAAmB,aAAa,QAAQ,IAAI,gBAAgB,GAAG;AACrE,UAAM,sBAAsB,aAAa,QAAQ,IAAI,kBAAmB;AACxE,cAAU,GAAG,mBAAmB,IAAI,gBAAgB,KAAK,EAAE,IAAI,mBAAmB;AAAA,EACpF;AACA,QAAM,MAAM,UAAU;AAEtB,QAAM,WAAW,IAAI,SAAqB;AACxC,WAAO,gBAAgB,KAAK,MAAM,KAAK;AAAA,EACzC;AAEA,SAAO,OAAO,OAAO,UAAU;AAAA,IAC7B;AAAA,IACA;AAAA,IACA,CAAC,mBAAmB,GAAG;AAAA,EAAA,CACxB;AACH;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"registerGlobalMiddleware.js","sources":["../../src/registerGlobalMiddleware.ts"],"sourcesContent":["import type { AnyFunctionMiddleware } from './createMiddleware'\n\nexport const globalMiddleware: Array<AnyFunctionMiddleware> = []\n\nexport function registerGlobalMiddleware(options: {\n middleware: Array<AnyFunctionMiddleware>\n}) {\n globalMiddleware.push(...options.middleware)\n}\n"],"names":[],"mappings":"AAEO,MAAM,mBAAiD,CAAA;AAEvD,SAAS,yBAAyB,SAEtC;AACD,mBAAiB,KAAK,GAAG,QAAQ,UAAU;AAC7C;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ServerFunctionSerializationAdapter.js","sources":["../../../src/serializer/ServerFunctionSerializationAdapter.ts"],"sourcesContent":["import { createSerializationAdapter } from '@tanstack/router-core'\nimport { createClientRpc } from '../createClientRpc'\nimport { TSS_SERVER_FUNCTION } from '../constants'\n\nexport const ServerFunctionSerializationAdapter = createSerializationAdapter({\n key: '$TSS/serverfn',\n test: (v): v is { functionId: string } => {\n if (typeof v !== 'object' || v === null) return false\n\n if (!(TSS_SERVER_FUNCTION in v)) return false\n\n return !!v[TSS_SERVER_FUNCTION]\n },\n toSerializable: ({ functionId }) => ({ functionId }),\n fromSerializable: ({ functionId }) => createClientRpc(functionId),\n})\n"],"names":[],"mappings":";;;AAIO,MAAM,qCAAqC,2BAA2B;AAAA,EAC3E,KAAK;AAAA,EACL,MAAM,CAAC,MAAmC;AACxC,QAAI,OAAO,MAAM,YAAY,MAAM,KAAM,QAAO;AAEhD,QAAI,EAAE,uBAAuB,GAAI,QAAO;AAExC,WAAO,CAAC,CAAC,EAAE,mBAAmB;AAAA,EAChC;AAAA,EACA,gBAAgB,CAAC,EAAE,kBAAkB,EAAE,WAAA;AAAA,EACvC,kBAAkB,CAAC,EAAE,WAAA,MAAiB,gBAAgB,UAAU;AAClE,CAAC;"}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export declare function getClientSerovalPlugins(): (import('seroval').Plugin<Error, any> | import('seroval').Plugin<ReadableStream<any>, any> | import('seroval').Plugin<FormData, any> | import('seroval').Plugin<any, import('seroval').SerovalNode> | import('seroval').Plugin<{
|
|
2
|
-
functionId: string;
|
|
3
|
-
}, import('seroval').SerovalNode>)[];
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { makeSerovalPlugin } from "@tanstack/router-core";
|
|
2
|
-
import { getDefaultSerovalPlugins } from "./getDefaultSerovalPlugins.js";
|
|
3
|
-
import { ServerFunctionSerializationAdapter } from "./ServerFunctionSerializationAdapter.js";
|
|
4
|
-
function getClientSerovalPlugins() {
|
|
5
|
-
return [
|
|
6
|
-
...getDefaultSerovalPlugins(),
|
|
7
|
-
makeSerovalPlugin(ServerFunctionSerializationAdapter)
|
|
8
|
-
];
|
|
9
|
-
}
|
|
10
|
-
export {
|
|
11
|
-
getClientSerovalPlugins
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=getClientSerovalPlugins.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getClientSerovalPlugins.js","sources":["../../../src/serializer/getClientSerovalPlugins.ts"],"sourcesContent":["import { makeSerovalPlugin } from '@tanstack/router-core'\nimport { getDefaultSerovalPlugins } from './getDefaultSerovalPlugins'\nimport { ServerFunctionSerializationAdapter } from './ServerFunctionSerializationAdapter'\n\nexport function getClientSerovalPlugins() {\n return [\n ...getDefaultSerovalPlugins(),\n makeSerovalPlugin(ServerFunctionSerializationAdapter),\n ]\n}\n"],"names":[],"mappings":";;;AAIO,SAAS,0BAA0B;AACxC,SAAO;AAAA,IACL,GAAG,yBAAA;AAAA,IACH,kBAAkB,kCAAkC;AAAA,EAAA;AAExD;"}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'seroval';
|
|
2
|
-
export declare const defaultSerovalPlugins: (Plugin<Error, any> | Plugin<ReadableStream<any>, any> | Plugin<FormData, any>)[];
|
|
3
|
-
export declare function getDefaultSerovalPlugins(): (Plugin<Error, any> | Plugin<ReadableStream<any>, any> | Plugin<FormData, any> | Plugin<any, import('seroval').SerovalNode>)[];
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import invariant from "tiny-invariant";
|
|
2
|
-
import { defaultSerovalPlugins as defaultSerovalPlugins$1, makeSerovalPlugin } from "@tanstack/router-core";
|
|
3
|
-
import { FormDataPlugin } from "seroval-plugins/web";
|
|
4
|
-
import { getRouterInstance } from "../getRouterInstance.js";
|
|
5
|
-
const defaultSerovalPlugins = [
|
|
6
|
-
...defaultSerovalPlugins$1,
|
|
7
|
-
FormDataPlugin
|
|
8
|
-
];
|
|
9
|
-
function getDefaultSerovalPlugins() {
|
|
10
|
-
const router = getRouterInstance();
|
|
11
|
-
invariant(router, "Expected router instance to be available");
|
|
12
|
-
const adapters = router.options.serializationAdapters;
|
|
13
|
-
return [...adapters?.map(makeSerovalPlugin) ?? [], ...defaultSerovalPlugins];
|
|
14
|
-
}
|
|
15
|
-
export {
|
|
16
|
-
defaultSerovalPlugins,
|
|
17
|
-
getDefaultSerovalPlugins
|
|
18
|
-
};
|
|
19
|
-
//# sourceMappingURL=getDefaultSerovalPlugins.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getDefaultSerovalPlugins.js","sources":["../../../src/serializer/getDefaultSerovalPlugins.ts"],"sourcesContent":["import invariant from 'tiny-invariant'\nimport {\n makeSerovalPlugin,\n defaultSerovalPlugins as routerDefaultSerovalPlugins,\n} from '@tanstack/router-core'\nimport { FormDataPlugin } from 'seroval-plugins/web'\nimport { getRouterInstance } from '../getRouterInstance'\nimport type { AnySerializationAdapter } from '@tanstack/router-core'\n\nimport type { Plugin } from 'seroval'\n\nexport const defaultSerovalPlugins = [\n ...routerDefaultSerovalPlugins,\n FormDataPlugin as Plugin<FormData, any>,\n]\n\nexport function getDefaultSerovalPlugins() {\n const router = getRouterInstance()\n invariant(router, 'Expected router instance to be available')\n const adapters = router.options.serializationAdapters as\n | Array<AnySerializationAdapter>\n | undefined\n return [...(adapters?.map(makeSerovalPlugin) ?? []), ...defaultSerovalPlugins]\n}\n"],"names":["routerDefaultSerovalPlugins"],"mappings":";;;;AAWO,MAAM,wBAAwB;AAAA,EACnC,GAAGA;AAAAA,EACH;AACF;AAEO,SAAS,2BAA2B;AACzC,QAAM,SAAS,kBAAA;AACf,YAAU,QAAQ,0CAA0C;AAC5D,QAAM,WAAW,OAAO,QAAQ;AAGhC,SAAO,CAAC,GAAI,UAAU,IAAI,iBAAiB,KAAK,CAAA,GAAK,GAAG,qBAAqB;AAC/E;"}
|