@benjavicente/start-client-core 1.167.9
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/LICENSE +21 -0
- package/README.md +12 -0
- package/bin/intent.js +25 -0
- package/dist/esm/client/ServerFunctionSerializationAdapter.d.ts +7 -0
- package/dist/esm/client/ServerFunctionSerializationAdapter.js +18 -0
- package/dist/esm/client/ServerFunctionSerializationAdapter.js.map +1 -0
- package/dist/esm/client/hydrateStart.d.ts +2 -0
- package/dist/esm/client/hydrateStart.js +31 -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 +2 -0
- package/dist/esm/client-rpc/createClientRpc.d.ts +6 -0
- package/dist/esm/client-rpc/createClientRpc.js +21 -0
- package/dist/esm/client-rpc/createClientRpc.js.map +1 -0
- package/dist/esm/client-rpc/frame-decoder.d.ts +23 -0
- package/dist/esm/client-rpc/frame-decoder.js +231 -0
- package/dist/esm/client-rpc/frame-decoder.js.map +1 -0
- package/dist/esm/client-rpc/index.d.ts +1 -0
- package/dist/esm/client-rpc/index.js +2 -0
- package/dist/esm/client-rpc/serverFnFetcher.d.ts +1 -0
- package/dist/esm/client-rpc/serverFnFetcher.js +231 -0
- package/dist/esm/client-rpc/serverFnFetcher.js.map +1 -0
- package/dist/esm/constants.d.ts +53 -0
- package/dist/esm/constants.js +46 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/createMiddleware.d.ts +195 -0
- package/dist/esm/createMiddleware.js +26 -0
- package/dist/esm/createMiddleware.js.map +1 -0
- package/dist/esm/createServerFn.d.ts +131 -0
- package/dist/esm/createServerFn.js +200 -0
- package/dist/esm/createServerFn.js.map +1 -0
- package/dist/esm/createStart.d.ts +50 -0
- package/dist/esm/createStart.js +29 -0
- package/dist/esm/createStart.js.map +1 -0
- package/dist/esm/fake-start-entry.d.ts +2 -0
- package/dist/esm/fake-start-entry.js +7 -0
- package/dist/esm/fake-start-entry.js.map +1 -0
- package/dist/esm/getDefaultSerovalPlugins.d.ts +1 -0
- package/dist/esm/getDefaultSerovalPlugins.js +10 -0
- package/dist/esm/getDefaultSerovalPlugins.js.map +1 -0
- package/dist/esm/getGlobalStartContext.d.ts +3 -0
- package/dist/esm/getGlobalStartContext.js +12 -0
- package/dist/esm/getGlobalStartContext.js.map +1 -0
- package/dist/esm/getRouterInstance.d.ts +2 -0
- package/dist/esm/getRouterInstance.js +8 -0
- package/dist/esm/getRouterInstance.js.map +1 -0
- package/dist/esm/getStartContextServerOnly.d.ts +2 -0
- package/dist/esm/getStartContextServerOnly.js +8 -0
- package/dist/esm/getStartContextServerOnly.js.map +1 -0
- package/dist/esm/getStartOptions.d.ts +2 -0
- package/dist/esm/getStartOptions.js +8 -0
- package/dist/esm/getStartOptions.js.map +1 -0
- package/dist/esm/global.d.ts +7 -0
- package/dist/esm/index.d.ts +20 -0
- package/dist/esm/index.js +12 -0
- package/dist/esm/safeObjectMerge.d.ts +10 -0
- package/dist/esm/safeObjectMerge.js +30 -0
- package/dist/esm/safeObjectMerge.js.map +1 -0
- package/dist/esm/serverRoute.d.ts +65 -0
- package/dist/esm/startEntry.d.ts +8 -0
- package/dist/esm/tests/createServerFn.test-d.d.ts +1 -0
- package/dist/esm/tests/createServerMiddleware.test-d.d.ts +1 -0
- package/package.json +98 -0
- package/skills/start-core/SKILL.md +210 -0
- package/skills/start-core/deployment/SKILL.md +306 -0
- package/skills/start-core/execution-model/SKILL.md +302 -0
- package/skills/start-core/middleware/SKILL.md +365 -0
- package/skills/start-core/server-functions/SKILL.md +335 -0
- package/skills/start-core/server-routes/SKILL.md +280 -0
- package/src/client/ServerFunctionSerializationAdapter.ts +16 -0
- package/src/client/hydrateStart.ts +43 -0
- package/src/client/index.ts +2 -0
- package/src/client-rpc/createClientRpc.ts +20 -0
- package/src/client-rpc/frame-decoder.ts +389 -0
- package/src/client-rpc/index.ts +1 -0
- package/src/client-rpc/serverFnFetcher.ts +416 -0
- package/src/constants.ts +90 -0
- package/src/createMiddleware.ts +824 -0
- package/src/createServerFn.ts +813 -0
- package/src/createStart.ts +166 -0
- package/src/fake-start-entry.ts +2 -0
- package/src/getDefaultSerovalPlugins.ts +17 -0
- package/src/getGlobalStartContext.ts +18 -0
- package/src/getRouterInstance.ts +8 -0
- package/src/getStartContextServerOnly.ts +4 -0
- package/src/getStartOptions.ts +8 -0
- package/src/global.ts +9 -0
- package/src/index.tsx +119 -0
- package/src/safeObjectMerge.ts +38 -0
- package/src/serverRoute.ts +509 -0
- package/src/start-entry.d.ts +11 -0
- package/src/startEntry.ts +10 -0
- package/src/tests/createServerFn.test-d.ts +866 -0
- package/src/tests/createServerMiddleware.test-d.ts +810 -0
|
@@ -0,0 +1,824 @@
|
|
|
1
|
+
import type { StartInstanceOptions } from './createStart'
|
|
2
|
+
import type {
|
|
3
|
+
AnyServerFn,
|
|
4
|
+
ConstrainValidator,
|
|
5
|
+
CustomFetch,
|
|
6
|
+
Method,
|
|
7
|
+
} from './createServerFn'
|
|
8
|
+
import type { ClientFnMeta, ServerFnMeta } from './constants'
|
|
9
|
+
import type {
|
|
10
|
+
AnyContext,
|
|
11
|
+
Assign,
|
|
12
|
+
Constrain,
|
|
13
|
+
Expand,
|
|
14
|
+
IntersectAssign,
|
|
15
|
+
Register,
|
|
16
|
+
ResolveValidatorInput,
|
|
17
|
+
ResolveValidatorOutput,
|
|
18
|
+
ValidateSerializableInput,
|
|
19
|
+
} from '@benjavicente/router-core'
|
|
20
|
+
|
|
21
|
+
export type CreateMiddlewareFn<TRegister> = <TType extends MiddlewareType>(
|
|
22
|
+
options?: {
|
|
23
|
+
type?: TType
|
|
24
|
+
},
|
|
25
|
+
__opts?: FunctionMiddlewareOptions<
|
|
26
|
+
TRegister,
|
|
27
|
+
unknown,
|
|
28
|
+
undefined,
|
|
29
|
+
undefined,
|
|
30
|
+
undefined
|
|
31
|
+
>,
|
|
32
|
+
) => CreateMiddlewareResult<TRegister, TType>
|
|
33
|
+
|
|
34
|
+
export const createMiddleware: CreateMiddlewareFn<{}> = (options, __opts) => {
|
|
35
|
+
const resolvedOptions = {
|
|
36
|
+
type: 'request',
|
|
37
|
+
...(__opts || options),
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
options: resolvedOptions,
|
|
42
|
+
middleware: (middleware: any) => {
|
|
43
|
+
return createMiddleware(
|
|
44
|
+
{} as any,
|
|
45
|
+
Object.assign(resolvedOptions, { middleware }),
|
|
46
|
+
) as any
|
|
47
|
+
},
|
|
48
|
+
inputValidator: (inputValidator: any) => {
|
|
49
|
+
return createMiddleware(
|
|
50
|
+
{} as any,
|
|
51
|
+
Object.assign(resolvedOptions, { inputValidator }),
|
|
52
|
+
) as any
|
|
53
|
+
},
|
|
54
|
+
client: (client: any) => {
|
|
55
|
+
return createMiddleware(
|
|
56
|
+
{} as any,
|
|
57
|
+
Object.assign(resolvedOptions, { client }),
|
|
58
|
+
) as any
|
|
59
|
+
},
|
|
60
|
+
server: (server: any) => {
|
|
61
|
+
return createMiddleware(
|
|
62
|
+
{} as any,
|
|
63
|
+
Object.assign(resolvedOptions, { server }),
|
|
64
|
+
) as any
|
|
65
|
+
},
|
|
66
|
+
} as any
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type MiddlewareType = 'request' | 'function'
|
|
70
|
+
|
|
71
|
+
export type CreateMiddlewareResult<
|
|
72
|
+
TRegister,
|
|
73
|
+
TType extends MiddlewareType,
|
|
74
|
+
> = 'request' extends TType
|
|
75
|
+
? RequestMiddleware<TRegister>
|
|
76
|
+
: FunctionMiddleware<TRegister>
|
|
77
|
+
|
|
78
|
+
export interface FunctionMiddleware<
|
|
79
|
+
TRegister,
|
|
80
|
+
> extends FunctionMiddlewareAfterMiddleware<TRegister, unknown> {
|
|
81
|
+
middleware: <const TNewMiddlewares = undefined>(
|
|
82
|
+
middlewares: Constrain<
|
|
83
|
+
TNewMiddlewares,
|
|
84
|
+
ReadonlyArray<AnyRequestMiddleware | AnyFunctionMiddleware>
|
|
85
|
+
>,
|
|
86
|
+
) => FunctionMiddlewareAfterMiddleware<TRegister, TNewMiddlewares>
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface FunctionMiddlewareAfterMiddleware<TRegister, TMiddlewares>
|
|
90
|
+
extends
|
|
91
|
+
FunctionMiddlewareWithTypes<
|
|
92
|
+
TRegister,
|
|
93
|
+
TMiddlewares,
|
|
94
|
+
undefined,
|
|
95
|
+
undefined,
|
|
96
|
+
undefined,
|
|
97
|
+
undefined,
|
|
98
|
+
undefined
|
|
99
|
+
>,
|
|
100
|
+
FunctionMiddlewareServer<
|
|
101
|
+
TRegister,
|
|
102
|
+
TMiddlewares,
|
|
103
|
+
undefined,
|
|
104
|
+
undefined,
|
|
105
|
+
undefined
|
|
106
|
+
>,
|
|
107
|
+
FunctionMiddlewareClient<TRegister, TMiddlewares, undefined>,
|
|
108
|
+
FunctionMiddlewareValidator<TRegister, TMiddlewares> {}
|
|
109
|
+
|
|
110
|
+
export interface FunctionMiddlewareWithTypes<
|
|
111
|
+
TRegister,
|
|
112
|
+
TMiddlewares,
|
|
113
|
+
TInputValidator,
|
|
114
|
+
TServerContext,
|
|
115
|
+
TServerSendContext,
|
|
116
|
+
TClientContext,
|
|
117
|
+
TClientSendContext,
|
|
118
|
+
> {
|
|
119
|
+
'~types': FunctionMiddlewareTypes<
|
|
120
|
+
TRegister,
|
|
121
|
+
TMiddlewares,
|
|
122
|
+
TInputValidator,
|
|
123
|
+
TServerContext,
|
|
124
|
+
TServerSendContext,
|
|
125
|
+
TClientContext,
|
|
126
|
+
TClientSendContext
|
|
127
|
+
>
|
|
128
|
+
options: FunctionMiddlewareOptions<
|
|
129
|
+
TRegister,
|
|
130
|
+
TMiddlewares,
|
|
131
|
+
TInputValidator,
|
|
132
|
+
TServerContext,
|
|
133
|
+
TClientContext
|
|
134
|
+
>
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export interface FunctionMiddlewareTypes<
|
|
138
|
+
in out TRegister,
|
|
139
|
+
in out TMiddlewares,
|
|
140
|
+
in out TInputValidator,
|
|
141
|
+
in out TServerContext,
|
|
142
|
+
in out TServerSendContext,
|
|
143
|
+
in out TClientContext,
|
|
144
|
+
in out TClientSendContext,
|
|
145
|
+
> {
|
|
146
|
+
type: 'function'
|
|
147
|
+
middlewares: TMiddlewares
|
|
148
|
+
input: ResolveValidatorInput<TInputValidator>
|
|
149
|
+
allInput: IntersectAllValidatorInputs<TMiddlewares, TInputValidator>
|
|
150
|
+
output: ResolveValidatorOutput<TInputValidator>
|
|
151
|
+
allOutput: IntersectAllValidatorOutputs<TMiddlewares, TInputValidator>
|
|
152
|
+
clientContext: TClientContext
|
|
153
|
+
allClientContextBeforeNext: AssignAllClientContextBeforeNext<
|
|
154
|
+
TMiddlewares,
|
|
155
|
+
TClientContext
|
|
156
|
+
>
|
|
157
|
+
allClientContextAfterNext: AssignAllClientContextAfterNext<
|
|
158
|
+
TMiddlewares,
|
|
159
|
+
TClientContext,
|
|
160
|
+
TClientSendContext
|
|
161
|
+
>
|
|
162
|
+
serverContext: TServerContext
|
|
163
|
+
serverSendContext: TServerSendContext
|
|
164
|
+
allServerSendContext: AssignAllServerSendContext<
|
|
165
|
+
TMiddlewares,
|
|
166
|
+
TServerSendContext
|
|
167
|
+
>
|
|
168
|
+
allServerContext: AssignAllServerFnContext<
|
|
169
|
+
TRegister,
|
|
170
|
+
TMiddlewares,
|
|
171
|
+
TServerSendContext,
|
|
172
|
+
TServerContext
|
|
173
|
+
>
|
|
174
|
+
clientSendContext: TClientSendContext
|
|
175
|
+
allClientSendContext: AssignAllClientSendContext<
|
|
176
|
+
TMiddlewares,
|
|
177
|
+
TClientSendContext
|
|
178
|
+
>
|
|
179
|
+
inputValidator: TInputValidator
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Recursively resolve the input type produced by a sequence of middleware
|
|
184
|
+
*/
|
|
185
|
+
export type IntersectAllValidatorInputs<TMiddlewares, TInputValidator> =
|
|
186
|
+
unknown extends TInputValidator
|
|
187
|
+
? TInputValidator
|
|
188
|
+
: TInputValidator extends undefined
|
|
189
|
+
? IntersectAllMiddleware<TMiddlewares, 'allInput'>
|
|
190
|
+
: IntersectAssign<
|
|
191
|
+
IntersectAllMiddleware<TMiddlewares, 'allInput'>,
|
|
192
|
+
ResolveValidatorInput<TInputValidator>
|
|
193
|
+
>
|
|
194
|
+
|
|
195
|
+
export type IntersectAllMiddleware<
|
|
196
|
+
TMiddlewares,
|
|
197
|
+
TType extends
|
|
198
|
+
| keyof AnyFunctionMiddleware['~types']
|
|
199
|
+
| keyof AnyRequestMiddleware['~types']
|
|
200
|
+
| keyof AnyServerFn['~types'],
|
|
201
|
+
TAcc = undefined,
|
|
202
|
+
> = TMiddlewares extends readonly [infer TMiddleware, ...infer TRest]
|
|
203
|
+
? TMiddleware extends
|
|
204
|
+
| AnyFunctionMiddleware
|
|
205
|
+
| AnyRequestMiddleware
|
|
206
|
+
| AnyServerFn
|
|
207
|
+
? IntersectAllMiddleware<
|
|
208
|
+
TRest,
|
|
209
|
+
TType,
|
|
210
|
+
IntersectAssign<
|
|
211
|
+
TAcc,
|
|
212
|
+
TMiddleware['~types'][TType & keyof TMiddleware['~types']]
|
|
213
|
+
>
|
|
214
|
+
>
|
|
215
|
+
: TAcc
|
|
216
|
+
: TAcc
|
|
217
|
+
|
|
218
|
+
export type AnyFunctionMiddleware = FunctionMiddlewareWithTypes<
|
|
219
|
+
any,
|
|
220
|
+
any,
|
|
221
|
+
any,
|
|
222
|
+
any,
|
|
223
|
+
any,
|
|
224
|
+
any,
|
|
225
|
+
any
|
|
226
|
+
>
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Recursively merge the output type produced by a sequence of middleware
|
|
230
|
+
*/
|
|
231
|
+
export type IntersectAllValidatorOutputs<TMiddlewares, TInputValidator> =
|
|
232
|
+
unknown extends TInputValidator
|
|
233
|
+
? TInputValidator
|
|
234
|
+
: TInputValidator extends undefined
|
|
235
|
+
? IntersectAllMiddleware<TMiddlewares, 'allOutput'>
|
|
236
|
+
: IntersectAssign<
|
|
237
|
+
IntersectAllMiddleware<TMiddlewares, 'allOutput'>,
|
|
238
|
+
Awaited<ResolveValidatorOutput<TInputValidator>>
|
|
239
|
+
>
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Recursively resolve the client context type produced by a sequence of middleware
|
|
243
|
+
*/
|
|
244
|
+
export type AssignAllClientContextBeforeNext<
|
|
245
|
+
TMiddlewares,
|
|
246
|
+
TClientContext = undefined,
|
|
247
|
+
> = unknown extends TClientContext
|
|
248
|
+
? TClientContext
|
|
249
|
+
: Assign<
|
|
250
|
+
AssignAllMiddleware<TMiddlewares, 'allClientContextBeforeNext'>,
|
|
251
|
+
TClientContext
|
|
252
|
+
>
|
|
253
|
+
|
|
254
|
+
export type AssignAllMiddleware<
|
|
255
|
+
TMiddlewares,
|
|
256
|
+
TType extends
|
|
257
|
+
| keyof AnyFunctionMiddleware['~types']
|
|
258
|
+
| keyof AnyRequestMiddleware['~types']
|
|
259
|
+
| keyof AnyServerFn['~types'],
|
|
260
|
+
TAcc = undefined,
|
|
261
|
+
> = TMiddlewares extends readonly [infer TMiddleware, ...infer TRest]
|
|
262
|
+
? TMiddleware extends
|
|
263
|
+
| AnyFunctionMiddleware
|
|
264
|
+
| AnyRequestMiddleware
|
|
265
|
+
| AnyServerFn
|
|
266
|
+
? AssignAllMiddleware<
|
|
267
|
+
TRest,
|
|
268
|
+
TType,
|
|
269
|
+
Assign<TAcc, TMiddleware['~types'][TType & keyof TMiddleware['~types']]>
|
|
270
|
+
>
|
|
271
|
+
: TAcc
|
|
272
|
+
: TAcc
|
|
273
|
+
|
|
274
|
+
export type AssignAllClientContextAfterNext<
|
|
275
|
+
TMiddlewares,
|
|
276
|
+
TClientContext = undefined,
|
|
277
|
+
TSendContext = undefined,
|
|
278
|
+
> = unknown extends TClientContext
|
|
279
|
+
? Assign<TClientContext, TSendContext>
|
|
280
|
+
: Assign<
|
|
281
|
+
AssignAllMiddleware<TMiddlewares, 'allClientContextAfterNext'>,
|
|
282
|
+
Assign<TClientContext, TSendContext>
|
|
283
|
+
>
|
|
284
|
+
|
|
285
|
+
export type AssignAllServerSendContext<
|
|
286
|
+
TMiddlewares,
|
|
287
|
+
TSendContext = undefined,
|
|
288
|
+
> = unknown extends TSendContext
|
|
289
|
+
? TSendContext
|
|
290
|
+
: Assign<
|
|
291
|
+
AssignAllMiddleware<TMiddlewares, 'allServerSendContext'>,
|
|
292
|
+
TSendContext
|
|
293
|
+
>
|
|
294
|
+
|
|
295
|
+
export type AssignAllServerRequestContext<
|
|
296
|
+
TRegister,
|
|
297
|
+
TMiddlewares,
|
|
298
|
+
TSendContext = undefined,
|
|
299
|
+
TServerContext = undefined,
|
|
300
|
+
> = Assign<
|
|
301
|
+
// Fetch Request Context
|
|
302
|
+
GlobalFetchRequestContext,
|
|
303
|
+
Assign<
|
|
304
|
+
GlobalServerRequestContext<TRegister>,
|
|
305
|
+
__AssignAllServerRequestContext<TMiddlewares, TSendContext, TServerContext>
|
|
306
|
+
>
|
|
307
|
+
>
|
|
308
|
+
|
|
309
|
+
// export type GlobalFetchRequestContext<TRegister> = AnyContext
|
|
310
|
+
export type GlobalFetchRequestContext = Register extends {
|
|
311
|
+
server: { requestContext: infer TRequestContext }
|
|
312
|
+
}
|
|
313
|
+
? TRequestContext
|
|
314
|
+
: AnyContext
|
|
315
|
+
|
|
316
|
+
export type GlobalServerRequestContext<TRegister> = TRegister extends {
|
|
317
|
+
config: StartInstanceOptions<any, any, infer TRequestMiddlewares, any>
|
|
318
|
+
}
|
|
319
|
+
? AssignAllMiddleware<TRequestMiddlewares, 'allServerContext'>
|
|
320
|
+
: AnyContext
|
|
321
|
+
|
|
322
|
+
type __AssignAllServerRequestContext<
|
|
323
|
+
TMiddlewares,
|
|
324
|
+
TSendContext = undefined,
|
|
325
|
+
TServerContext = undefined,
|
|
326
|
+
> = unknown extends TSendContext
|
|
327
|
+
? Assign<TSendContext, TServerContext>
|
|
328
|
+
: Assign<
|
|
329
|
+
AssignAllMiddleware<TMiddlewares, 'allServerContext'>,
|
|
330
|
+
Assign<TSendContext, TServerContext>
|
|
331
|
+
>
|
|
332
|
+
|
|
333
|
+
export type AssignAllServerFnContext<
|
|
334
|
+
TRegister,
|
|
335
|
+
TMiddlewares,
|
|
336
|
+
TSendContext = undefined,
|
|
337
|
+
TServerContext = undefined,
|
|
338
|
+
> = Assign<
|
|
339
|
+
GlobalFetchRequestContext,
|
|
340
|
+
Assign<
|
|
341
|
+
GlobalServerRequestContext<TRegister>, // TODO: This enabled global middleware
|
|
342
|
+
// type inference, but creates a circular types issue. No idea how to fix this.
|
|
343
|
+
// AnyContext,
|
|
344
|
+
Assign<
|
|
345
|
+
GlobalServerFnContext<TRegister>, // TODO: This enabled global middleware
|
|
346
|
+
// type inference, but creates a circular types issue. No idea how to fix this.
|
|
347
|
+
// AnyContext,/
|
|
348
|
+
__AssignAllServerFnContext<TMiddlewares, TSendContext, TServerContext>
|
|
349
|
+
>
|
|
350
|
+
>
|
|
351
|
+
>
|
|
352
|
+
|
|
353
|
+
type GlobalServerFnContext<TRegister> = TRegister extends {
|
|
354
|
+
config: StartInstanceOptions<any, any, any, infer TFunctionMiddlewares>
|
|
355
|
+
}
|
|
356
|
+
? AssignAllMiddleware<TFunctionMiddlewares, 'allServerContext'>
|
|
357
|
+
: AnyContext
|
|
358
|
+
|
|
359
|
+
type __AssignAllServerFnContext<
|
|
360
|
+
TMiddlewares,
|
|
361
|
+
TSendContext = undefined,
|
|
362
|
+
TServerContext = undefined,
|
|
363
|
+
> = unknown extends TSendContext
|
|
364
|
+
? Assign<TSendContext, TServerContext>
|
|
365
|
+
: Assign<
|
|
366
|
+
AssignAllMiddleware<TMiddlewares, 'allServerContext'>,
|
|
367
|
+
Assign<TSendContext, TServerContext>
|
|
368
|
+
>
|
|
369
|
+
|
|
370
|
+
export type AssignAllClientSendContext<
|
|
371
|
+
TMiddlewares,
|
|
372
|
+
TSendContext = undefined,
|
|
373
|
+
> = unknown extends TSendContext
|
|
374
|
+
? TSendContext
|
|
375
|
+
: Assign<
|
|
376
|
+
AssignAllMiddleware<TMiddlewares, 'allClientSendContext'>,
|
|
377
|
+
TSendContext
|
|
378
|
+
>
|
|
379
|
+
|
|
380
|
+
export interface FunctionMiddlewareOptions<
|
|
381
|
+
in out TRegister,
|
|
382
|
+
in out TMiddlewares,
|
|
383
|
+
in out TInputValidator,
|
|
384
|
+
in out TServerContext,
|
|
385
|
+
in out TClientContext,
|
|
386
|
+
> {
|
|
387
|
+
middleware?: TMiddlewares
|
|
388
|
+
inputValidator?: ConstrainValidator<TRegister, 'GET', TInputValidator>
|
|
389
|
+
client?: FunctionMiddlewareClientFn<
|
|
390
|
+
TRegister,
|
|
391
|
+
TMiddlewares,
|
|
392
|
+
TInputValidator,
|
|
393
|
+
TServerContext,
|
|
394
|
+
TClientContext
|
|
395
|
+
>
|
|
396
|
+
server?: FunctionMiddlewareServerFn<
|
|
397
|
+
TRegister,
|
|
398
|
+
TMiddlewares,
|
|
399
|
+
TInputValidator,
|
|
400
|
+
TServerContext,
|
|
401
|
+
unknown,
|
|
402
|
+
unknown
|
|
403
|
+
>
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export type FunctionMiddlewareClientNextFn<TRegister, TMiddlewares> = <
|
|
407
|
+
TSendContext = undefined,
|
|
408
|
+
TNewClientContext = undefined,
|
|
409
|
+
>(ctx?: {
|
|
410
|
+
context?: TNewClientContext
|
|
411
|
+
sendContext?: ValidateSerializableInput<TRegister, TSendContext>
|
|
412
|
+
headers?: HeadersInit
|
|
413
|
+
fetch?: CustomFetch
|
|
414
|
+
}) => Promise<
|
|
415
|
+
FunctionClientResultWithContext<TMiddlewares, TSendContext, TNewClientContext>
|
|
416
|
+
>
|
|
417
|
+
|
|
418
|
+
export interface FunctionMiddlewareServer<
|
|
419
|
+
TRegister,
|
|
420
|
+
TMiddlewares,
|
|
421
|
+
TInputValidator,
|
|
422
|
+
TServerSendContext,
|
|
423
|
+
TClientContext,
|
|
424
|
+
> {
|
|
425
|
+
server: <TNewServerContext = undefined, TSendContext = undefined>(
|
|
426
|
+
server: FunctionMiddlewareServerFn<
|
|
427
|
+
TRegister,
|
|
428
|
+
TMiddlewares,
|
|
429
|
+
TInputValidator,
|
|
430
|
+
TServerSendContext,
|
|
431
|
+
TNewServerContext,
|
|
432
|
+
TSendContext
|
|
433
|
+
>,
|
|
434
|
+
) => FunctionMiddlewareAfterServer<
|
|
435
|
+
TRegister,
|
|
436
|
+
TMiddlewares,
|
|
437
|
+
TInputValidator,
|
|
438
|
+
TNewServerContext,
|
|
439
|
+
TServerSendContext,
|
|
440
|
+
TClientContext,
|
|
441
|
+
TSendContext
|
|
442
|
+
>
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
export type FunctionMiddlewareServerFn<
|
|
446
|
+
TRegister,
|
|
447
|
+
TMiddlewares,
|
|
448
|
+
TInputValidator,
|
|
449
|
+
TServerSendContext,
|
|
450
|
+
TNewServerContext,
|
|
451
|
+
TSendContext,
|
|
452
|
+
> = (
|
|
453
|
+
options: FunctionMiddlewareServerFnOptions<
|
|
454
|
+
TRegister,
|
|
455
|
+
TMiddlewares,
|
|
456
|
+
TInputValidator,
|
|
457
|
+
TServerSendContext
|
|
458
|
+
>,
|
|
459
|
+
) => FunctionMiddlewareServerFnResult<
|
|
460
|
+
TRegister,
|
|
461
|
+
TMiddlewares,
|
|
462
|
+
TServerSendContext,
|
|
463
|
+
TNewServerContext,
|
|
464
|
+
TSendContext
|
|
465
|
+
>
|
|
466
|
+
|
|
467
|
+
export type FunctionMiddlewareServerNextFn<
|
|
468
|
+
TRegister,
|
|
469
|
+
TMiddlewares,
|
|
470
|
+
TServerSendContext,
|
|
471
|
+
> = <TNewServerContext = undefined, TSendContext = undefined>(ctx?: {
|
|
472
|
+
context?: TNewServerContext
|
|
473
|
+
sendContext?: ValidateSerializableInput<TRegister, TSendContext>
|
|
474
|
+
}) => Promise<
|
|
475
|
+
FunctionServerResultWithContext<
|
|
476
|
+
TRegister,
|
|
477
|
+
TMiddlewares,
|
|
478
|
+
TServerSendContext,
|
|
479
|
+
TNewServerContext,
|
|
480
|
+
TSendContext
|
|
481
|
+
>
|
|
482
|
+
>
|
|
483
|
+
|
|
484
|
+
export type FunctionServerResultWithContext<
|
|
485
|
+
in out TRegister,
|
|
486
|
+
in out TMiddlewares,
|
|
487
|
+
in out TServerSendContext,
|
|
488
|
+
in out TServerContext,
|
|
489
|
+
in out TSendContext,
|
|
490
|
+
> = {
|
|
491
|
+
'use functions must return the result of next()': true
|
|
492
|
+
'~types': {
|
|
493
|
+
context: TServerContext
|
|
494
|
+
sendContext: TSendContext
|
|
495
|
+
}
|
|
496
|
+
context: Expand<
|
|
497
|
+
AssignAllServerFnContext<
|
|
498
|
+
TRegister,
|
|
499
|
+
TMiddlewares,
|
|
500
|
+
TServerSendContext,
|
|
501
|
+
TServerContext
|
|
502
|
+
>
|
|
503
|
+
>
|
|
504
|
+
sendContext: Expand<AssignAllClientSendContext<TMiddlewares, TSendContext>>
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
export interface FunctionMiddlewareServerFnOptions<
|
|
508
|
+
in out TRegister,
|
|
509
|
+
in out TMiddlewares,
|
|
510
|
+
in out TInputValidator,
|
|
511
|
+
in out TServerSendContext,
|
|
512
|
+
> {
|
|
513
|
+
data: Expand<IntersectAllValidatorOutputs<TMiddlewares, TInputValidator>>
|
|
514
|
+
context: Expand<
|
|
515
|
+
AssignAllServerFnContext<TRegister, TMiddlewares, TServerSendContext>
|
|
516
|
+
>
|
|
517
|
+
next: FunctionMiddlewareServerNextFn<
|
|
518
|
+
TRegister,
|
|
519
|
+
TMiddlewares,
|
|
520
|
+
TServerSendContext
|
|
521
|
+
>
|
|
522
|
+
method: Method
|
|
523
|
+
serverFnMeta: ServerFnMeta
|
|
524
|
+
signal: AbortSignal
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
export type FunctionMiddlewareServerFnResult<
|
|
528
|
+
TRegister,
|
|
529
|
+
TMiddlewares,
|
|
530
|
+
TServerSendContext,
|
|
531
|
+
TServerContext,
|
|
532
|
+
TSendContext,
|
|
533
|
+
> =
|
|
534
|
+
| Promise<
|
|
535
|
+
FunctionServerResultWithContext<
|
|
536
|
+
TRegister,
|
|
537
|
+
TMiddlewares,
|
|
538
|
+
TServerSendContext,
|
|
539
|
+
TServerContext,
|
|
540
|
+
TSendContext
|
|
541
|
+
>
|
|
542
|
+
>
|
|
543
|
+
| FunctionServerResultWithContext<
|
|
544
|
+
TRegister,
|
|
545
|
+
TMiddlewares,
|
|
546
|
+
TServerSendContext,
|
|
547
|
+
TServerContext,
|
|
548
|
+
TSendContext
|
|
549
|
+
>
|
|
550
|
+
|
|
551
|
+
export interface FunctionMiddlewareAfterServer<
|
|
552
|
+
TRegister,
|
|
553
|
+
TMiddlewares,
|
|
554
|
+
TInputValidator,
|
|
555
|
+
TServerContext,
|
|
556
|
+
TServerSendContext,
|
|
557
|
+
TClientContext,
|
|
558
|
+
TClientSendContext,
|
|
559
|
+
> extends FunctionMiddlewareWithTypes<
|
|
560
|
+
TRegister,
|
|
561
|
+
TMiddlewares,
|
|
562
|
+
TInputValidator,
|
|
563
|
+
TServerContext,
|
|
564
|
+
TServerSendContext,
|
|
565
|
+
TClientContext,
|
|
566
|
+
TClientSendContext
|
|
567
|
+
> {}
|
|
568
|
+
|
|
569
|
+
export interface FunctionMiddlewareClient<
|
|
570
|
+
TRegister,
|
|
571
|
+
TMiddlewares,
|
|
572
|
+
TInputValidator,
|
|
573
|
+
> {
|
|
574
|
+
client: <TSendServerContext = undefined, TNewClientContext = undefined>(
|
|
575
|
+
client: FunctionMiddlewareClientFn<
|
|
576
|
+
TRegister,
|
|
577
|
+
TMiddlewares,
|
|
578
|
+
TInputValidator,
|
|
579
|
+
TSendServerContext,
|
|
580
|
+
TNewClientContext
|
|
581
|
+
>,
|
|
582
|
+
) => FunctionMiddlewareAfterClient<
|
|
583
|
+
TRegister,
|
|
584
|
+
TMiddlewares,
|
|
585
|
+
TInputValidator,
|
|
586
|
+
TSendServerContext,
|
|
587
|
+
TNewClientContext
|
|
588
|
+
>
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
export type FunctionMiddlewareClientFn<
|
|
592
|
+
TRegister,
|
|
593
|
+
TMiddlewares,
|
|
594
|
+
TInputValidator,
|
|
595
|
+
TSendContext,
|
|
596
|
+
TClientContext,
|
|
597
|
+
> = (
|
|
598
|
+
options: FunctionMiddlewareClientFnOptions<
|
|
599
|
+
TRegister,
|
|
600
|
+
TMiddlewares,
|
|
601
|
+
TInputValidator
|
|
602
|
+
>,
|
|
603
|
+
) => FunctionMiddlewareClientFnResult<
|
|
604
|
+
TMiddlewares,
|
|
605
|
+
TSendContext,
|
|
606
|
+
TClientContext
|
|
607
|
+
>
|
|
608
|
+
|
|
609
|
+
export interface FunctionMiddlewareClientFnOptions<
|
|
610
|
+
in out TRegister,
|
|
611
|
+
in out TMiddlewares,
|
|
612
|
+
in out TInputValidator,
|
|
613
|
+
> {
|
|
614
|
+
data: Expand<IntersectAllValidatorInputs<TMiddlewares, TInputValidator>>
|
|
615
|
+
context: Expand<AssignAllClientContextBeforeNext<TMiddlewares>>
|
|
616
|
+
sendContext: Expand<AssignAllServerSendContext<TMiddlewares>>
|
|
617
|
+
method: Method
|
|
618
|
+
signal: AbortSignal
|
|
619
|
+
serverFnMeta: ClientFnMeta
|
|
620
|
+
next: FunctionMiddlewareClientNextFn<TRegister, TMiddlewares>
|
|
621
|
+
filename: string
|
|
622
|
+
fetch?: CustomFetch
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
export type FunctionMiddlewareClientFnResult<
|
|
626
|
+
TMiddlewares,
|
|
627
|
+
TSendContext,
|
|
628
|
+
TClientContext,
|
|
629
|
+
> =
|
|
630
|
+
| Promise<
|
|
631
|
+
FunctionClientResultWithContext<
|
|
632
|
+
TMiddlewares,
|
|
633
|
+
TSendContext,
|
|
634
|
+
TClientContext
|
|
635
|
+
>
|
|
636
|
+
>
|
|
637
|
+
| FunctionClientResultWithContext<TMiddlewares, TSendContext, TClientContext>
|
|
638
|
+
|
|
639
|
+
export type FunctionClientResultWithContext<
|
|
640
|
+
in out TMiddlewares,
|
|
641
|
+
in out TSendContext,
|
|
642
|
+
in out TClientContext,
|
|
643
|
+
> = {
|
|
644
|
+
'use functions must return the result of next()': true
|
|
645
|
+
context: Expand<AssignAllClientContextAfterNext<TMiddlewares, TClientContext>>
|
|
646
|
+
sendContext: Expand<AssignAllServerSendContext<TMiddlewares, TSendContext>>
|
|
647
|
+
headers: HeadersInit
|
|
648
|
+
fetch?: CustomFetch
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
export interface FunctionMiddlewareAfterClient<
|
|
652
|
+
TRegister,
|
|
653
|
+
TMiddlewares,
|
|
654
|
+
TInputValidator,
|
|
655
|
+
TServerSendContext,
|
|
656
|
+
TClientContext,
|
|
657
|
+
>
|
|
658
|
+
extends
|
|
659
|
+
FunctionMiddlewareWithTypes<
|
|
660
|
+
TRegister,
|
|
661
|
+
TMiddlewares,
|
|
662
|
+
TInputValidator,
|
|
663
|
+
undefined,
|
|
664
|
+
TServerSendContext,
|
|
665
|
+
TClientContext,
|
|
666
|
+
undefined
|
|
667
|
+
>,
|
|
668
|
+
FunctionMiddlewareServer<
|
|
669
|
+
TRegister,
|
|
670
|
+
TMiddlewares,
|
|
671
|
+
TInputValidator,
|
|
672
|
+
TServerSendContext,
|
|
673
|
+
TClientContext
|
|
674
|
+
> {}
|
|
675
|
+
|
|
676
|
+
export interface FunctionMiddlewareValidator<TRegister, TMiddlewares> {
|
|
677
|
+
inputValidator: <TNewValidator>(
|
|
678
|
+
inputValidator: ConstrainValidator<TRegister, 'GET', TNewValidator>,
|
|
679
|
+
) => FunctionMiddlewareAfterValidator<TRegister, TMiddlewares, TNewValidator>
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
export interface FunctionMiddlewareAfterValidator<
|
|
683
|
+
TRegister,
|
|
684
|
+
TMiddlewares,
|
|
685
|
+
TInputValidator,
|
|
686
|
+
>
|
|
687
|
+
extends
|
|
688
|
+
FunctionMiddlewareWithTypes<
|
|
689
|
+
TRegister,
|
|
690
|
+
TMiddlewares,
|
|
691
|
+
TInputValidator,
|
|
692
|
+
undefined,
|
|
693
|
+
undefined,
|
|
694
|
+
undefined,
|
|
695
|
+
undefined
|
|
696
|
+
>,
|
|
697
|
+
FunctionMiddlewareServer<
|
|
698
|
+
TRegister,
|
|
699
|
+
TMiddlewares,
|
|
700
|
+
TInputValidator,
|
|
701
|
+
undefined,
|
|
702
|
+
undefined
|
|
703
|
+
>,
|
|
704
|
+
FunctionMiddlewareClient<TRegister, TMiddlewares, TInputValidator> {}
|
|
705
|
+
|
|
706
|
+
export interface RequestMiddleware<
|
|
707
|
+
TRegister,
|
|
708
|
+
> extends RequestMiddlewareAfterMiddleware<TRegister, undefined> {
|
|
709
|
+
middleware: <const TMiddlewares = undefined>(
|
|
710
|
+
middlewares: Constrain<TMiddlewares, ReadonlyArray<AnyRequestMiddleware>>,
|
|
711
|
+
) => RequestMiddlewareAfterMiddleware<TRegister, TMiddlewares>
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
export type AnyRequestMiddleware = RequestMiddlewareWithTypes<any, any, any>
|
|
715
|
+
|
|
716
|
+
export interface RequestMiddlewareWithTypes<
|
|
717
|
+
TRegister,
|
|
718
|
+
TMiddlewares,
|
|
719
|
+
TServerContext,
|
|
720
|
+
> {
|
|
721
|
+
'~types': RequestMiddlewareTypes<TRegister, TMiddlewares, TServerContext>
|
|
722
|
+
options: RequestMiddlewareOptions<TRegister, TMiddlewares, TServerContext>
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
export interface RequestMiddlewareOptions<
|
|
726
|
+
in out TRegister,
|
|
727
|
+
in out TMiddlewares,
|
|
728
|
+
in out TServerContext,
|
|
729
|
+
> {
|
|
730
|
+
middleware?: TMiddlewares
|
|
731
|
+
server?: RequestServerFn<TRegister, TMiddlewares, TServerContext>
|
|
732
|
+
}
|
|
733
|
+
export interface RequestMiddlewareTypes<
|
|
734
|
+
TRegister,
|
|
735
|
+
TMiddlewares,
|
|
736
|
+
TServerContext,
|
|
737
|
+
> {
|
|
738
|
+
type: 'request'
|
|
739
|
+
// this only exists so we can use request middlewares in server functions
|
|
740
|
+
allInput: undefined
|
|
741
|
+
// this only exists so we can use request middlewares in server functions
|
|
742
|
+
allOutput: undefined
|
|
743
|
+
middlewares: TMiddlewares
|
|
744
|
+
serverContext: TServerContext
|
|
745
|
+
allServerContext: AssignAllServerRequestContext<
|
|
746
|
+
TRegister,
|
|
747
|
+
TMiddlewares,
|
|
748
|
+
undefined,
|
|
749
|
+
TServerContext
|
|
750
|
+
>
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
export interface RequestMiddlewareAfterMiddleware<TRegister, TMiddlewares>
|
|
754
|
+
extends
|
|
755
|
+
RequestMiddlewareWithTypes<TRegister, TMiddlewares, undefined>,
|
|
756
|
+
RequestMiddlewareServer<TRegister, TMiddlewares> {}
|
|
757
|
+
|
|
758
|
+
export interface RequestMiddlewareServer<TRegister, TMiddlewares> {
|
|
759
|
+
server: <TServerContext = undefined>(
|
|
760
|
+
fn: RequestServerFn<TRegister, TMiddlewares, TServerContext>,
|
|
761
|
+
) => RequestMiddlewareAfterServer<TRegister, TMiddlewares, TServerContext>
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
export type RequestServerFn<TRegister, TMiddlewares, TServerContext> = (
|
|
765
|
+
options: RequestServerOptions<TRegister, TMiddlewares>,
|
|
766
|
+
) => RequestMiddlewareServerFnResult<TRegister, TMiddlewares, TServerContext>
|
|
767
|
+
|
|
768
|
+
export interface RequestServerOptions<TRegister, TMiddlewares> {
|
|
769
|
+
request: Request
|
|
770
|
+
pathname: string
|
|
771
|
+
context: Expand<AssignAllServerRequestContext<TRegister, TMiddlewares>>
|
|
772
|
+
next: RequestServerNextFn<TRegister, TMiddlewares>
|
|
773
|
+
/**
|
|
774
|
+
* Metadata about the server function being invoked.
|
|
775
|
+
* This is only present when the request is handling a server function call.
|
|
776
|
+
* For regular page requests, this will be undefined.
|
|
777
|
+
*/
|
|
778
|
+
serverFnMeta?: ServerFnMeta
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
export type RequestServerNextFn<TRegister, TMiddlewares> = <
|
|
782
|
+
TServerContext = undefined,
|
|
783
|
+
>(
|
|
784
|
+
options?: RequestServerNextFnOptions<TServerContext>,
|
|
785
|
+
) => RequestServerNextFnResult<TRegister, TMiddlewares, TServerContext>
|
|
786
|
+
|
|
787
|
+
export interface RequestServerNextFnOptions<TServerContext> {
|
|
788
|
+
context?: TServerContext
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
export type RequestServerNextFnResult<TRegister, TMiddlewares, TServerContext> =
|
|
792
|
+
| Promise<RequestServerResult<TRegister, TMiddlewares, TServerContext>>
|
|
793
|
+
| RequestServerResult<TRegister, TMiddlewares, TServerContext>
|
|
794
|
+
|
|
795
|
+
export type RequestMiddlewareServerFnResult<
|
|
796
|
+
TRegister,
|
|
797
|
+
TMiddlewares,
|
|
798
|
+
TServerContext,
|
|
799
|
+
> =
|
|
800
|
+
| Promise<
|
|
801
|
+
RequestServerResult<TRegister, TMiddlewares, TServerContext> | Response
|
|
802
|
+
>
|
|
803
|
+
| RequestServerResult<TRegister, TMiddlewares, TServerContext>
|
|
804
|
+
| Response
|
|
805
|
+
|
|
806
|
+
export interface RequestServerResult<TRegister, TMiddlewares, TServerContext> {
|
|
807
|
+
request: Request
|
|
808
|
+
pathname: string
|
|
809
|
+
context: Expand<
|
|
810
|
+
AssignAllServerRequestContext<
|
|
811
|
+
TRegister,
|
|
812
|
+
TMiddlewares,
|
|
813
|
+
undefined,
|
|
814
|
+
TServerContext
|
|
815
|
+
>
|
|
816
|
+
>
|
|
817
|
+
response: Response
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
export interface RequestMiddlewareAfterServer<
|
|
821
|
+
TRegister,
|
|
822
|
+
TMiddlewares,
|
|
823
|
+
TServerContext,
|
|
824
|
+
> extends RequestMiddlewareWithTypes<TRegister, TMiddlewares, TServerContext> {}
|