@tanstack/start-client-core 1.143.12 → 1.145.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/client-rpc/frame-decoder.d.ts +23 -0
- package/dist/esm/client-rpc/frame-decoder.js +243 -0
- package/dist/esm/client-rpc/frame-decoder.js.map +1 -0
- package/dist/esm/client-rpc/serverFnFetcher.js +57 -6
- package/dist/esm/client-rpc/serverFnFetcher.js.map +1 -1
- package/dist/esm/constants.d.ts +28 -0
- package/dist/esm/constants.js +38 -1
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/createMiddleware.d.ts +1 -1
- package/dist/esm/createMiddleware.js.map +1 -1
- package/dist/esm/createServerFn.d.ts +1 -1
- package/dist/esm/createServerFn.js +2 -4
- package/dist/esm/createServerFn.js.map +1 -1
- package/dist/esm/getDefaultSerovalPlugins.d.ts +1 -1
- package/dist/esm/index.d.ts +4 -1
- package/dist/esm/index.js +10 -2
- package/dist/esm/index.js.map +1 -1
- package/package.json +3 -3
- package/src/client-rpc/frame-decoder.ts +389 -0
- package/src/client-rpc/serverFnFetcher.ts +90 -4
- package/src/constants.ts +59 -0
- package/src/createMiddleware.ts +1 -1
- package/src/createServerFn.ts +3 -6
- package/src/index.tsx +10 -0
- package/src/tests/createServerFn.test-d.ts +174 -1
|
@@ -25,7 +25,7 @@ test('createServerFn without middleware', () => {
|
|
|
25
25
|
})
|
|
26
26
|
})
|
|
27
27
|
|
|
28
|
-
test('createServerFn with validator', () => {
|
|
28
|
+
test('createServerFn with validator function', () => {
|
|
29
29
|
const fnAfterValidator = createServerFn({
|
|
30
30
|
method: 'GET',
|
|
31
31
|
}).inputValidator((input: { input: string }) => ({
|
|
@@ -55,6 +55,179 @@ test('createServerFn with validator', () => {
|
|
|
55
55
|
expectTypeOf<ReturnType<typeof fn>>().resolves.toEqualTypeOf<void>()
|
|
56
56
|
})
|
|
57
57
|
|
|
58
|
+
test('createServerFn with async validator function', () => {
|
|
59
|
+
const fnAfterValidator = createServerFn({
|
|
60
|
+
method: 'GET',
|
|
61
|
+
}).inputValidator((input: string) => Promise.resolve(input))
|
|
62
|
+
|
|
63
|
+
expectTypeOf(fnAfterValidator).toHaveProperty('handler')
|
|
64
|
+
expectTypeOf(fnAfterValidator).toHaveProperty('middleware')
|
|
65
|
+
expectTypeOf(fnAfterValidator).not.toHaveProperty('inputValidator')
|
|
66
|
+
|
|
67
|
+
const fn = fnAfterValidator.handler((options) => {
|
|
68
|
+
expectTypeOf(options).toEqualTypeOf<{
|
|
69
|
+
context: undefined
|
|
70
|
+
data: string
|
|
71
|
+
signal: AbortSignal
|
|
72
|
+
}>()
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
expectTypeOf(fn).parameter(0).toEqualTypeOf<{
|
|
76
|
+
data: string
|
|
77
|
+
headers?: HeadersInit
|
|
78
|
+
signal?: AbortSignal
|
|
79
|
+
}>()
|
|
80
|
+
|
|
81
|
+
expectTypeOf<ReturnType<typeof fn>>().resolves.toEqualTypeOf<void>()
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
test('createServerFn with validator with parse method', () => {
|
|
85
|
+
const fnAfterValidator = createServerFn({
|
|
86
|
+
method: 'GET',
|
|
87
|
+
}).inputValidator({
|
|
88
|
+
parse: (input: string) => input,
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
expectTypeOf(fnAfterValidator).toHaveProperty('handler')
|
|
92
|
+
expectTypeOf(fnAfterValidator).toHaveProperty('middleware')
|
|
93
|
+
expectTypeOf(fnAfterValidator).not.toHaveProperty('inputValidator')
|
|
94
|
+
|
|
95
|
+
const fn = fnAfterValidator.handler((options) => {
|
|
96
|
+
expectTypeOf(options).toEqualTypeOf<{
|
|
97
|
+
context: undefined
|
|
98
|
+
data: string
|
|
99
|
+
signal: AbortSignal
|
|
100
|
+
}>()
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
expectTypeOf(fn).parameter(0).toEqualTypeOf<{
|
|
104
|
+
data: string
|
|
105
|
+
headers?: HeadersInit
|
|
106
|
+
signal?: AbortSignal
|
|
107
|
+
}>()
|
|
108
|
+
|
|
109
|
+
expectTypeOf<ReturnType<typeof fn>>().resolves.toEqualTypeOf<void>()
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
test('createServerFn with async validator with parse method', () => {
|
|
113
|
+
const fnAfterValidator = createServerFn({
|
|
114
|
+
method: 'GET',
|
|
115
|
+
}).inputValidator({
|
|
116
|
+
parse: (input: string) => Promise.resolve(input),
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
expectTypeOf(fnAfterValidator).toHaveProperty('handler')
|
|
120
|
+
expectTypeOf(fnAfterValidator).toHaveProperty('middleware')
|
|
121
|
+
expectTypeOf(fnAfterValidator).not.toHaveProperty('inputValidator')
|
|
122
|
+
|
|
123
|
+
const fn = fnAfterValidator.handler((options) => {
|
|
124
|
+
expectTypeOf(options).toEqualTypeOf<{
|
|
125
|
+
context: undefined
|
|
126
|
+
data: string
|
|
127
|
+
signal: AbortSignal
|
|
128
|
+
}>()
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
expectTypeOf(fn).parameter(0).toEqualTypeOf<{
|
|
132
|
+
data: string
|
|
133
|
+
headers?: HeadersInit
|
|
134
|
+
signal?: AbortSignal
|
|
135
|
+
}>()
|
|
136
|
+
|
|
137
|
+
expectTypeOf<ReturnType<typeof fn>>().resolves.toEqualTypeOf<void>()
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
test('createServerFn with standard validator', () => {
|
|
141
|
+
interface SyncValidator {
|
|
142
|
+
readonly '~standard': {
|
|
143
|
+
types?: {
|
|
144
|
+
input: string
|
|
145
|
+
output: string
|
|
146
|
+
}
|
|
147
|
+
validate: (input: unknown) => {
|
|
148
|
+
value: string
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const validator: SyncValidator = {
|
|
153
|
+
['~standard']: {
|
|
154
|
+
validate: (input: unknown) => ({
|
|
155
|
+
value: input as string,
|
|
156
|
+
}),
|
|
157
|
+
},
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const fnAfterValidator = createServerFn({
|
|
161
|
+
method: 'GET',
|
|
162
|
+
}).inputValidator(validator)
|
|
163
|
+
|
|
164
|
+
expectTypeOf(fnAfterValidator).toHaveProperty('handler')
|
|
165
|
+
expectTypeOf(fnAfterValidator).toHaveProperty('middleware')
|
|
166
|
+
expectTypeOf(fnAfterValidator).not.toHaveProperty('inputValidator')
|
|
167
|
+
|
|
168
|
+
const fn = fnAfterValidator.handler((options) => {
|
|
169
|
+
expectTypeOf(options).toEqualTypeOf<{
|
|
170
|
+
context: undefined
|
|
171
|
+
data: string
|
|
172
|
+
signal: AbortSignal
|
|
173
|
+
}>()
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
expectTypeOf(fn).parameter(0).toEqualTypeOf<{
|
|
177
|
+
data: string
|
|
178
|
+
headers?: HeadersInit
|
|
179
|
+
signal?: AbortSignal
|
|
180
|
+
}>()
|
|
181
|
+
|
|
182
|
+
expectTypeOf<ReturnType<typeof fn>>().resolves.toEqualTypeOf<void>()
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
test('createServerFn with async standard validator', () => {
|
|
186
|
+
interface AsyncValidator {
|
|
187
|
+
readonly '~standard': {
|
|
188
|
+
types?: {
|
|
189
|
+
input: string
|
|
190
|
+
output: string
|
|
191
|
+
}
|
|
192
|
+
validate: (input: unknown) => Promise<{
|
|
193
|
+
value: string
|
|
194
|
+
}>
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const validator: AsyncValidator = {
|
|
198
|
+
['~standard']: {
|
|
199
|
+
validate: (input: unknown) =>
|
|
200
|
+
Promise.resolve({
|
|
201
|
+
value: input as string,
|
|
202
|
+
}),
|
|
203
|
+
},
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const fnAfterValidator = createServerFn({
|
|
207
|
+
method: 'GET',
|
|
208
|
+
}).inputValidator(validator)
|
|
209
|
+
|
|
210
|
+
expectTypeOf(fnAfterValidator).toHaveProperty('handler')
|
|
211
|
+
expectTypeOf(fnAfterValidator).toHaveProperty('middleware')
|
|
212
|
+
expectTypeOf(fnAfterValidator).not.toHaveProperty('inputValidator')
|
|
213
|
+
|
|
214
|
+
const fn = fnAfterValidator.handler((options) => {
|
|
215
|
+
expectTypeOf(options).toEqualTypeOf<{
|
|
216
|
+
context: undefined
|
|
217
|
+
data: string
|
|
218
|
+
signal: AbortSignal
|
|
219
|
+
}>()
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
expectTypeOf(fn).parameter(0).toEqualTypeOf<{
|
|
223
|
+
data: string
|
|
224
|
+
headers?: HeadersInit
|
|
225
|
+
signal?: AbortSignal
|
|
226
|
+
}>()
|
|
227
|
+
|
|
228
|
+
expectTypeOf<ReturnType<typeof fn>>().resolves.toEqualTypeOf<void>()
|
|
229
|
+
})
|
|
230
|
+
|
|
58
231
|
test('createServerFn with middleware and context', () => {
|
|
59
232
|
const middleware1 = createMiddleware({ type: 'function' }).server(
|
|
60
233
|
({ next }) => {
|