@barqjs/start 0.0.0-stage → 0.2.0-next.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.
Files changed (68) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +791 -2
  3. package/dist/client-BHyIiYxt.js +1527 -0
  4. package/dist/client-BHyIiYxt.js.map +1 -0
  5. package/dist/client-DHCV7yvQ.d.ts +440 -0
  6. package/dist/client-DHCV7yvQ.d.ts.map +1 -0
  7. package/dist/client.d.ts +3 -0
  8. package/dist/client.js +4 -0
  9. package/dist/env-qA8EyOr1.d.ts +49 -0
  10. package/dist/env-qA8EyOr1.d.ts.map +1 -0
  11. package/dist/env.d.ts +2 -0
  12. package/dist/env.js +44 -0
  13. package/dist/env.js.map +1 -0
  14. package/dist/index-Bm_-MTj6.d.ts +915 -0
  15. package/dist/index-Bm_-MTj6.d.ts.map +1 -0
  16. package/dist/index.d.ts +5 -0
  17. package/dist/index.js +6 -0
  18. package/dist/middleware-BdVlE8qm.d.ts +576 -0
  19. package/dist/middleware-BdVlE8qm.d.ts.map +1 -0
  20. package/dist/middleware.d.ts +2 -0
  21. package/dist/middleware.js +282 -0
  22. package/dist/middleware.js.map +1 -0
  23. package/dist/prerender.d.ts +98 -0
  24. package/dist/prerender.d.ts.map +1 -0
  25. package/dist/prerender.js +289 -0
  26. package/dist/prerender.js.map +1 -0
  27. package/dist/protocol.d.ts +58 -0
  28. package/dist/protocol.d.ts.map +1 -0
  29. package/dist/protocol.js +26 -0
  30. package/dist/protocol.js.map +1 -0
  31. package/dist/serve.d.ts +135 -0
  32. package/dist/serve.d.ts.map +1 -0
  33. package/dist/serve.js +223 -0
  34. package/dist/serve.js.map +1 -0
  35. package/dist/server-BV3xKmLa.js +1148 -0
  36. package/dist/server-BV3xKmLa.js.map +1 -0
  37. package/dist/server.d.ts +142 -0
  38. package/dist/server.d.ts.map +1 -0
  39. package/dist/server.js +1 -0
  40. package/dist/src-ChnB_xug.js +1140 -0
  41. package/dist/src-ChnB_xug.js.map +1 -0
  42. package/dist/static-fn-DgjNArBe.js +123 -0
  43. package/dist/static-fn-DgjNArBe.js.map +1 -0
  44. package/package.json +106 -4
  45. package/src/client.ts +672 -0
  46. package/src/context.ts +666 -0
  47. package/src/cookies.ts +229 -0
  48. package/src/env.ts +86 -0
  49. package/src/fn-error.ts +97 -0
  50. package/src/frames-client.ts +1216 -0
  51. package/src/frames-server.ts +464 -0
  52. package/src/frames.ts +285 -0
  53. package/src/index.ts +714 -0
  54. package/src/live-client.ts +50 -0
  55. package/src/live-server.ts +182 -0
  56. package/src/middleware.ts +994 -0
  57. package/src/prerender.ts +477 -0
  58. package/src/protocol.ts +61 -0
  59. package/src/rate-limit.ts +202 -0
  60. package/src/serve.ts +153 -0
  61. package/src/server.ts +990 -0
  62. package/src/session.ts +449 -0
  63. package/src/start-instance.ts +147 -0
  64. package/src/static-fn.ts +181 -0
  65. package/src/static.ts +302 -0
  66. package/src/stubs.ts +32 -0
  67. package/src/timing.ts +29 -0
  68. package/src/wire-types.ts +139 -0
@@ -0,0 +1,915 @@
1
+ import { E as Streamed, T as ServerFnMethod, b as ServerFn, n as ChainStep, t as AnyServerFn, w as ServerFnMeta } from "./client-DHCV7yvQ.js";
2
+ import { E as OpenContext, F as StandardInput, I as StandardOutput, R as StandardSchemaLike, T as NoContribution, V as Validator, d as Empty, g as Middleware, h as Merged, n as Carries, r as ChainContribution, s as Contribution } from "./middleware-BdVlE8qm.js";
3
+ import { commitResponseStub } from "@barqjs/web/internal";
4
+ import { AnySerializationAdapter, AnySerializationAdapter as AnySerializationAdapter$1, SerializationAdapter, createSerializationAdapter } from "@barqjs/server/codec";
5
+ import { RequestEventLocals, ResponseStub } from "@barqjs/web";
6
+ //#region src/cookies.d.ts
7
+ /**
8
+ * Cookies, parsed and serialized here rather than taken from a package.
9
+ *
10
+ * It is a hundred lines and the traps are all known, so a dependency buys
11
+ * nothing this file does not — but the traps are REAL, and every one of them is
12
+ * a rule a browser enforces SILENTLY. A cookie a browser drops looks exactly
13
+ * like a cookie the server never set, so each rule below is a THROW rather than
14
+ * a correction: being told the attribute combination is impossible beats
15
+ * debugging a login that works on the server and not in Chrome.
16
+ *
17
+ * The rules, and where they come from:
18
+ *
19
+ * - `SameSite=None` REQUIRES `Secure`. Chrome 80 made this a hard drop
20
+ * (RFC 6265bis §5.4.7); without it the cookie is not stored at all.
21
+ * - `Partitioned` REQUIRES `Secure` (CHIPS), and is rejected without it.
22
+ * - `__Host-` requires `Secure`, `Path=/`, and NO `Domain` (RFC 6265bis
23
+ * §4.1.3). `__Secure-` requires `Secure`.
24
+ * - `Max-Age` must be an INTEGER. A fractional one is ignored, which silently
25
+ * turns a dated cookie into a session one.
26
+ * - `Expires` is an IMF-fixdate, which is what `Date.toUTCString()` produces
27
+ * and what nothing else does.
28
+ * - A cookie NAME may not hold a separator or a control character (RFC 6265
29
+ * §4.1.1), and a VALUE is percent-encoded by default — a raw `;` in one
30
+ * truncates the cookie where the browser splits it.
31
+ */
32
+ /** Attributes a `Set-Cookie` may carry. */
33
+ interface CookieOptions {
34
+ readonly domain?: string;
35
+ readonly expires?: Date;
36
+ readonly httpOnly?: boolean;
37
+ /** Seconds. Must be an integer — a browser ignores anything else. */
38
+ readonly maxAge?: number;
39
+ /** CHIPS. Browsers that do not know it ignore it. */
40
+ readonly partitioned?: boolean;
41
+ readonly path?: string;
42
+ readonly priority?: "low" | "medium" | "high";
43
+ readonly sameSite?: "strict" | "lax" | "none";
44
+ readonly secure?: boolean;
45
+ /**
46
+ * How the VALUE is encoded. `encodeURIComponent` by default, because a raw
47
+ * `;` or `,` truncates the cookie where the browser splits it. Pass the
48
+ * identity function for a value already in a cookie-safe alphabet — a
49
+ * base64url session token, say — to keep it readable in devtools.
50
+ */
51
+ readonly encode?: (value: string) => string;
52
+ }
53
+ /**
54
+ * Every cookie on a request, by name.
55
+ *
56
+ * FIRST WINS on a duplicate, which is what a browser sends when one cookie
57
+ * exists at two paths and is what every parser in the survey does. A value that
58
+ * is not valid percent-encoding comes back RAW rather than throwing: it arrived
59
+ * off the wire, a client may put anything there, and one malformed cookie must
60
+ * not take the request down.
61
+ */
62
+ declare function parseCookies(header: string | null | undefined): Record<string, string>;
63
+ /**
64
+ * One `Set-Cookie` line.
65
+ *
66
+ * Throws on any combination a browser would drop in silence — see the header
67
+ * for which, and why a throw is the kinder answer.
68
+ */
69
+ declare function serializeCookie(name: string, value: string, options?: CookieOptions): string;
70
+ /**
71
+ * The line that DELETES a cookie.
72
+ *
73
+ * A cookie is deleted by being set again, expired — and the `path` and `domain`
74
+ * must MATCH the ones it was set with, or the browser deletes nothing and keeps
75
+ * the original. That is why both ride through rather than being dropped: a
76
+ * `deleteCookie("sid")` against a cookie set at `path: "/app"` is a no-op, and
77
+ * a silent one.
78
+ */
79
+ declare function deleteCookieLine(name: string, options?: CookieOptions): string;
80
+ //#endregion
81
+ //#region src/session.d.ts
82
+ /** What a session holds. An application narrows it with the type argument. */
83
+ type SessionData = Record<string, unknown>;
84
+ interface Session<T extends SessionData = SessionData> {
85
+ /** Stable for the life of the session. Useful as a log correlation key. */
86
+ readonly id: string;
87
+ /** When it was first sealed, as a millisecond timestamp. */
88
+ readonly createdAt: number;
89
+ readonly data: Partial<T>;
90
+ }
91
+ interface SessionManager<T extends SessionData = SessionData> {
92
+ readonly id: string;
93
+ /** When the session was first sealed, as a millisecond timestamp. */
94
+ readonly createdAt: number;
95
+ readonly data: Partial<T>;
96
+ /** Merge and re-seal. A function receives the current data. */
97
+ update(patch: Partial<T> | ((current: Partial<T>) => Partial<T> | undefined)): Promise<SessionManager<T>>;
98
+ /** Drop it and expire the cookie. */
99
+ clear(): Promise<SessionManager<T>>;
100
+ }
101
+ interface SessionConfig {
102
+ /**
103
+ * The key the cookie is sealed with. At least 32 characters.
104
+ *
105
+ * It is a SECRET and belongs in the environment, never in source. Rotating it
106
+ * invalidates every live session, which is the intended way to log everyone
107
+ * out.
108
+ */
109
+ readonly password: string;
110
+ /** Cookie name. Default `barq-session`. */
111
+ readonly name?: string;
112
+ /**
113
+ * How long a sealed cookie stays valid, in seconds. Default 7 days.
114
+ *
115
+ * Enforced on UNSEAL as well as on the cookie, because the cookie's own expiry
116
+ * is a request the client is free to ignore — the timestamp inside the sealed
117
+ * payload is the one that cannot be edited.
118
+ */
119
+ readonly maxAge?: number;
120
+ /**
121
+ * Cookie attributes. The defaults are the strict ones — `httpOnly`, `secure`,
122
+ * `sameSite: "lax"`, `path: "/"` — because a session cookie readable from
123
+ * script is a session cookie an XSS takes.
124
+ */
125
+ readonly cookie?: CookieOptions;
126
+ /**
127
+ * Has this session been revoked? Asked on every unseal.
128
+ *
129
+ * THE ONE THING A SEALED COOKIE CANNOT DO BY ITSELF. Nothing on the server is
130
+ * consulted to open one, so "log out everywhere" and "ban this account now"
131
+ * are otherwise impossible — an issued cookie is valid until it expires, and
132
+ * that is the trade the whole design makes.
133
+ *
134
+ * This is the smallest seam that closes it. The fast path stays stateless:
135
+ * without the hook there is no lookup, and with it an application keeps only a
136
+ * set of revoked IDS until they expire, which `maxAge` bounds. That is a much
137
+ * smaller thing to store than a session per user, and it is only ever written
138
+ * when somebody signs out or is banned.
139
+ *
140
+ * A REVOKED SESSION READS AS ABSENT, like every other reason a cookie will not
141
+ * open — see `unsealSession`. Throwing here would tell a caller the difference
142
+ * between "forged" and "revoked", which is an oracle.
143
+ *
144
+ * It is asked AFTER the cookie is authenticated, so an unauthenticated client
145
+ * cannot make the application do a lookup by sending a garbage cookie.
146
+ */
147
+ readonly isRevoked?: (id: string) => boolean | Promise<boolean>;
148
+ }
149
+ interface Sealed {
150
+ readonly id: string;
151
+ readonly createdAt: number;
152
+ readonly data: SessionData;
153
+ }
154
+ /**
155
+ * A session as one request holds it: what the cookie said, then every `update`
156
+ * and `clear` since.
157
+ */
158
+ interface OpenSession {
159
+ current: Sealed;
160
+ /** Settles when the write in flight has, whichever way it went. */
161
+ writing: Promise<unknown>;
162
+ }
163
+ /** Encrypt and sign a session. Exported for code that seals outside a request. */
164
+ declare function sealSession(config: SessionConfig, session: Sealed): Promise<string>;
165
+ /**
166
+ * Decrypt and verify, or `null`.
167
+ *
168
+ * `null` for EVERY failure — a wrong password, a tampered ciphertext, an expired
169
+ * timestamp, a envelope from a future version — and never a throw. A session
170
+ * that will not open is not an error the request should fail on; it is a visitor
171
+ * who is not signed in, and the two must be indistinguishable to the caller so
172
+ * that a forged cookie cannot be told apart from an absent one.
173
+ */
174
+ declare function unsealSession(config: SessionConfig, sealed: string): Promise<Sealed | null>;
175
+ /**
176
+ * The session for this request, opening the cookie if there is one.
177
+ *
178
+ * Always answers a manager, never `null`: a visitor with no session has an empty
179
+ * one, which is the same thing from the application's side and removes the
180
+ * branch that is easy to get backwards.
181
+ *
182
+ * NOTHING IS WRITTEN until `update` is called. Reading a session must not
183
+ * re-issue its cookie, or every page render would refresh an expiry the user did
184
+ * not earn — and on a page that also sets `Cache-Control: public` that
185
+ * `Set-Cookie` is a cache poisoning waiting to happen.
186
+ */
187
+ declare function useSession<T extends SessionData = SessionData>(config: SessionConfig): Promise<SessionManager<T>>;
188
+ /** The session's data, for code that only reads. */
189
+ declare function getSession<T extends SessionData = SessionData>(config: SessionConfig): Promise<Session<T>>;
190
+ /** Merge into the session and re-seal it. */
191
+ declare function updateSession<T extends SessionData = SessionData>(config: SessionConfig, patch: Partial<T> | ((current: Partial<T>) => Partial<T> | undefined)): Promise<SessionManager<T>>;
192
+ /** Drop the session and expire its cookie. */
193
+ declare function clearSession(config: SessionConfig): Promise<void>;
194
+ //#endregion
195
+ //#region src/start-instance.d.ts
196
+ interface StartOptions {
197
+ /** Runs for every request the server answers: a page, a route handler, a server function. */
198
+ readonly requestMiddleware?: readonly Middleware[];
199
+ /** Runs for every server function, ahead of the function's own chain. */
200
+ readonly functionMiddleware?: readonly Middleware[];
201
+ /**
202
+ * How a type only the application knows crosses the wire, in a server
203
+ * function's input and result and in the page's seed. Installed when the
204
+ * options are first read, which both sides do before they encode anything.
205
+ */
206
+ readonly serializationAdapters?: readonly AnySerializationAdapter[];
207
+ /**
208
+ * What a route that says nothing about `ssr` does, for every route: `true`,
209
+ * `false` (rendered in the browser alone) or `"data-only"` (loaders run on
210
+ * the server, the component in the browser). Wins over the router's own
211
+ * `defaultSsr`, as TanStack's does.
212
+ */
213
+ readonly defaultSsr?: boolean | "data-only";
214
+ readonly serverFns?: {
215
+ /**
216
+ * The `fetch` every call goes out through, in place of the global one. A
217
+ * client middleware's `next({ fetch })` and the call's own `fetch` win
218
+ * over it.
219
+ */
220
+ readonly fetch?: typeof fetch;
221
+ };
222
+ }
223
+ interface StartInstance<Options extends StartOptions = StartOptions> {
224
+ getOptions(): Options;
225
+ }
226
+ declare const UNREGISTERED: unique symbol;
227
+ /**
228
+ * Where an application tells the types about its `src/start.ts`:
229
+ *
230
+ * ```ts
231
+ * declare module "@barqjs/start" {
232
+ * interface Register {
233
+ * start: typeof startInstance;
234
+ * }
235
+ * }
236
+ * ```
237
+ *
238
+ * With that, what the global middleware passes to `next({ context })` is typed
239
+ * in every server function's `context` and in `getGlobalStartContext()`.
240
+ * Without it they are untyped, never wrong. The member below exists so the
241
+ * interface is not the empty object type before anything augments it.
242
+ */
243
+ interface Register {
244
+ readonly [UNREGISTERED]?: never;
245
+ }
246
+ type RegisteredInstance = Register extends {
247
+ readonly start: infer Instance;
248
+ } ? Instance : StartInstance;
249
+ /** What an instance's request middleware adds, for the whole request. */
250
+ type RequestContextOf<Instance> = Instance extends StartInstance<infer Options> ? ChainContribution<NonNullable<Options["requestMiddleware"]>>["context"] : Empty;
251
+ /** What an instance's middleware hands every server function: request, then function. */
252
+ type FunctionContextOf<Instance> = Instance extends StartInstance<infer Options> ? RequestContextOf<Instance> & ChainContribution<NonNullable<Options["functionMiddleware"]>>["context"] : Empty;
253
+ /** What the registered global request middleware adds, for the whole request. */
254
+ type GlobalRequestContext = RequestContextOf<RegisteredInstance>;
255
+ /** What every server function's `context` starts from. */
256
+ type GlobalFunctionContext = FunctionContextOf<RegisteredInstance>;
257
+ /**
258
+ * Declare the application's global middleware.
259
+ *
260
+ * The function is called once, the first time anything asks, so a middleware
261
+ * module that imports this one back is fully evaluated by then.
262
+ */
263
+ declare function createStart<const Options extends StartOptions>(options: () => Options): StartInstance<Options>;
264
+ /** What the application declared, or nothing. */
265
+ declare function startOptions(): StartOptions;
266
+ /** Test seam. Not for application use. */
267
+ declare function clearStart(): void;
268
+ //#endregion
269
+ //#region src/context.d.ts
270
+ /**
271
+ * Headers and a status a handler asked for, merged into whatever is returned:
272
+ * the request event's response head, Solid's `ResponseStub`, under the name
273
+ * this package's helpers have always given it.
274
+ */
275
+ type ResponseDraft = ResponseStub;
276
+ interface RequestContext {
277
+ request: Request;
278
+ /** What the handler has asked the response to carry. */
279
+ response: ResponseDraft;
280
+ /** Solid's `RequestEvent.locals`: what middleware hangs on the request. */
281
+ locals: RequestEventLocals;
282
+ /**
283
+ * The request's cookies, parsed ONCE.
284
+ *
285
+ * `getCookie` went through `parseCookies` every call, so a middleware that
286
+ * reads a session, a handler that reads a preference and a loader that reads a
287
+ * locale re-split the same header three times. The header is immutable for the
288
+ * life of the request, so the parse is too.
289
+ */
290
+ cookies?: Record<string, string>;
291
+ /**
292
+ * Rules `@barqjs/css` registered while rendering THIS request.
293
+ *
294
+ * A server imports the application once and serves forever, so a module-scope
295
+ * rule belongs to every request and a rule a component body registers belongs
296
+ * to one. Kept here rather than in the css package because this is what knows
297
+ * which request is current — two in flight at once cannot take each other's.
298
+ */
299
+ css?: Map<string, string>;
300
+ /**
301
+ * Reads every rule registered after THIS request's head sheet was serialised.
302
+ *
303
+ * What the page is owed once it has a head, in place of {@link css}: a rule
304
+ * ANOTHER request registered after this one's head is one this render can
305
+ * still use, as a class a module already holds, and it registers nothing
306
+ * when it does. So the line is the head and not who registered what.
307
+ */
308
+ lateCss?: () => string;
309
+ /**
310
+ * What a server function's chain asked to send back, held for the request
311
+ * handler to put on the response.
312
+ *
313
+ * Here and not in a module-level variable for the reason this file opens
314
+ * with: two requests whose handlers settle in the same tick would each read
315
+ * whichever chain wrote last, and that is one caller's `sendContext` on
316
+ * another caller's response.
317
+ */
318
+ sendContext?: Record<string, unknown>;
319
+ /** The server functions whose frames this request's mutation changed. */
320
+ invalidatedFrames?: Set<string>;
321
+ /**
322
+ * The sessions this request has opened, by cookie name.
323
+ *
324
+ * The request's cookie is what the browser HAD. A second `useSession` that
325
+ * read it again would start from before the first one's `update`, and its own
326
+ * `update` would then seal a session without that change over the top of it.
327
+ */
328
+ sessions?: Map<string, Promise<OpenSession>>;
329
+ /**
330
+ * What the request middleware chain contributed with `next({ context })`.
331
+ *
332
+ * A server function's own chain starts from it, and a route handler is
333
+ * handed it, so a global middleware that resolved a session says so once.
334
+ */
335
+ middlewareContext?: Record<string, unknown>;
336
+ /**
337
+ * Why this request must not be read, when it must not be.
338
+ *
339
+ * A PRERENDER holds a `Request` a build minted, so `getRequest()` would
340
+ * answer with a build machine's headers and a cookie jar that is empty for
341
+ * everyone. SvelteKit guards `url.search` alone and lets `cookies.get` and
342
+ * `request.headers` return null in silence; its own tracker records that as
343
+ * multi-day debugging. Refusing is the honest answer, and the message names
344
+ * what to do instead.
345
+ */
346
+ refuse?: string;
347
+ }
348
+ /** A fresh, empty draft, one per request: Solid's `createResponseStub`. */
349
+ declare const createResponseDraft: () => ResponseDraft;
350
+ /**
351
+ * Send `@barqjs/css`'s render-time rules to whichever request is running.
352
+ *
353
+ * Installed once, by the generated server entry. Outside a request — module
354
+ * scope, and the browser — there is nothing to attribute a rule to, so it falls
355
+ * back to the package's own sheet, which is where a module-scope rule belongs.
356
+ */
357
+ declare function collectRequestCss(): string;
358
+ /** `@barqjs/css`'s `CssSink`, restated so this package does not import that one. */
359
+ interface CssSink {
360
+ (key: string, rules: string): boolean;
361
+ head?(late: () => string): void;
362
+ }
363
+ declare function installCssSink(setSink: (sink: CssSink) => void): void;
364
+ /**
365
+ * Run `body` with `request` as the ambient one, under the event
366
+ * `createRequestEvent` builds for it and `provideRequestEvent` enters.
367
+ *
368
+ * The DRAFT is the caller's to hold, because the caller is what builds the
369
+ * response and it does so after `body` has returned.
370
+ */
371
+ declare function withRequest<T>(request: Request, body: () => T, options?: {
372
+ readonly refuse?: string;
373
+ readonly response?: ResponseDraft;
374
+ } | string): T;
375
+ /**
376
+ * The request this handler is running for.
377
+ *
378
+ * Throws outside one rather than returning undefined: a handler reading cookies
379
+ * off `undefined` is a bug that should surface where it happens, not resolve to
380
+ * "no session" and let the request through.
381
+ */
382
+ declare function getRequest(): Request;
383
+ /**
384
+ * The request, or undefined outside one. For code that legitimately runs both ways.
385
+ *
386
+ * A refused context reads as ABSENT here rather than throwing: `peekRequest` is
387
+ * the "I may not be in a request" spelling, and a prerender is exactly that
388
+ * case. Code that must have one calls `getRequest` and gets the refusal.
389
+ */
390
+ declare function peekRequest(): Request | undefined;
391
+ /**
392
+ * The draft, or `undefined` outside a request.
393
+ *
394
+ * Used by the two handlers to merge on the way out, and by nothing else. A
395
+ * REFUSED context still answers here: a prerender may not read the request, but
396
+ * a `head` or a loader that sets a cache header during one is describing the
397
+ * page rather than the requester, and the prerenderer can write it to disk.
398
+ */
399
+ declare function peekResponseDraft(): ResponseDraft | undefined;
400
+ /**
401
+ * Say that this mutation changed what these server functions' frames show, so
402
+ * its answer carries those regions, rendered again, beside its value: single
403
+ * flight, one round trip. A frame the page has not mounted is not rendered.
404
+ * Outside a request it does nothing, as there is no answer to carry them.
405
+ */
406
+ declare function invalidateFrames(...fns: readonly {
407
+ readonly meta: {
408
+ readonly id: string;
409
+ };
410
+ }[]): void;
411
+ /** Take the pending `sendContext`, leaving nothing behind for the next call. */
412
+ declare function takeSendContext(): Record<string, unknown>;
413
+ /**
414
+ * What this request's middleware chain has contributed, or an empty record
415
+ * outside a request. TanStack's name.
416
+ *
417
+ * Typed by what the registered global request middleware passes to
418
+ * `next({ context })`, each key optional: outside a request, or before the
419
+ * chain has reached the step that adds it, it is not there.
420
+ */
421
+ declare function getGlobalStartContext(): OpenContext<Partial<GlobalRequestContext>>;
422
+ /** Record what the request middleware chain is contributing, for the rest of the request. */
423
+ declare function setRequestMiddlewareContext(context: Record<string, unknown>): void;
424
+ declare function getRequestHeaders(): Headers;
425
+ declare function getRequestHeader(name: string): string | undefined;
426
+ /** The request URL, parsed. */
427
+ declare function getRequestUrl(): URL;
428
+ /**
429
+ * How far `X-Forwarded-For` is believed.
430
+ *
431
+ * `true` takes the LEFTMOST entry, and is safe only when the edge proxy
432
+ * OVERWRITES the header. A proxy that appends, which is what most do, leaves
433
+ * whatever the client sent at the front: `X-Forwarded-For: 203.0.113.9` on the
434
+ * request arrives as `203.0.113.9, <real address>`, and the leftmost entry is
435
+ * the one the caller typed.
436
+ *
437
+ * `{ trustedProxies: n }` counts from the RIGHT instead: the entry the nth
438
+ * proxy in front of this process wrote, which is the address that proxy saw.
439
+ * Entries to its left were there before any trusted hop touched the header, so
440
+ * a forged prefix is never read. A header with fewer than `n` entries did not
441
+ * come through that chain and is ignored whole.
442
+ */
443
+ type ForwardedForTrust = boolean | {
444
+ readonly trustedProxies: number;
445
+ };
446
+ /**
447
+ * The client's address, or `undefined`.
448
+ *
449
+ * `xForwardedFor` IS OFF BY DEFAULT and that is the whole design of this
450
+ * function. `X-Forwarded-For` is a header a client can send, so trusting it
451
+ * unconditionally lets any caller claim any address — and an address is exactly
452
+ * what rate limiting and audit logging key on. It is trustworthy only when a
453
+ * proxy you control overwrites it, which is a fact about the deployment that
454
+ * this process cannot discover. So it is opt-in, and the opt-in is per call.
455
+ *
456
+ * The LEFTMOST entry is taken when it is trusted, since that is the original
457
+ * client; every entry to its right was appended by a hop. {@link
458
+ * ForwardedForTrust} says when that is forgeable and what to pass instead.
459
+ */
460
+ declare function getRequestIP(options?: {
461
+ readonly xForwardedFor?: ForwardedForTrust;
462
+ }): string | undefined;
463
+ /**
464
+ * The host, from the URL — and from `X-Forwarded-Host` only when asked.
465
+ *
466
+ * Same rule as `getRequestIP`, and the consequence is sharper: a host taken
467
+ * from an untrusted header and used to build an absolute URL is a host-header
468
+ * injection, which turns a password-reset link into a link to the attacker.
469
+ */
470
+ declare function getRequestHost(options?: {
471
+ readonly xForwardedHost?: boolean;
472
+ }): string;
473
+ /** `http` or `https`. `X-Forwarded-Proto` only when asked, for the reason above. */
474
+ declare function getRequestProtocol(options?: {
475
+ readonly xForwardedProto?: boolean;
476
+ }): string;
477
+ /**
478
+ * Mark the draft's response as handed to the server: Solid's
479
+ * `commitResponseStub`. A streamed page goes on rendering after this, and so
480
+ * does a streamed server function, and a header one of them writes now changes
481
+ * nothing the browser receives.
482
+ */
483
+ declare const markResponseSent: typeof commitResponseStub;
484
+ declare function getResponseHeaders(): Headers;
485
+ declare function getResponseHeader(name: string): string | undefined;
486
+ /**
487
+ * Set a response header. An array APPENDS each value, which is what a header
488
+ * that may legitimately repeat needs.
489
+ */
490
+ declare function setResponseHeader(name: string, value: string | readonly string[]): void;
491
+ /**
492
+ * Add a value to a response header, keeping the ones already there.
493
+ *
494
+ * For a header that is a list: `Vary`, `Link`, `Cache-Control` built up by more
495
+ * than one caller. `setResponseHeader` replaces.
496
+ */
497
+ declare function appendResponseHeader(name: string, value: string): void;
498
+ declare function setResponseHeaders(headers: Record<string, string>): void;
499
+ declare function removeResponseHeader(name: string): void;
500
+ /** Clear the named headers, or every header this request has drafted. */
501
+ declare function clearResponseHeaders(names?: readonly string[]): void;
502
+ declare function getResponseStatus(): number;
503
+ /**
504
+ * Set the status the framework's own response will carry.
505
+ *
506
+ * It does NOT override a `Response` a handler returns for itself — see
507
+ * `applyResponseDraft`, which says why.
508
+ */
509
+ declare function setResponseStatus(status: number, statusText?: string): void;
510
+ /**
511
+ * Every cookie the REQUEST carried, by name.
512
+ *
513
+ * Parsed once and memoised on the context: the header cannot change for the life
514
+ * of the request, and re-splitting it per lookup made three readers three
515
+ * parses. The object is returned as it stands rather than copied, which is the
516
+ * point — copying it per call would put the allocation back.
517
+ */
518
+ declare function getCookies(): Record<string, string>;
519
+ declare function getCookie(name: string): string | undefined;
520
+ /**
521
+ * Set a cookie on the response.
522
+ *
523
+ * APPENDS, because several cookies are several `Set-Cookie` lines and a
524
+ * browser keeps only the last of a set. Setting the same NAME twice in one
525
+ * request is the caller's business — the last one wins in the browser, as ever.
526
+ */
527
+ declare function setCookie(name: string, value: string, options?: CookieOptions): void;
528
+ /**
529
+ * Delete a cookie.
530
+ *
531
+ * `path` and `domain` MUST match the ones it was set with, or the browser
532
+ * deletes nothing and keeps the original — silently. They are options here for
533
+ * exactly that reason rather than as decoration. With no `path` it names `/`,
534
+ * which is what `setCookie` gave a cookie that was set with none.
535
+ */
536
+ declare function deleteCookie(name: string, options?: CookieOptions): void;
537
+ /**
538
+ * Fold a draft into a response, Solid's fold for `commitEventResponse` without
539
+ * the commit: `foldResponseStub` in `@barqjs/web` says what wins and why.
540
+ *
541
+ * It does NOT override the status of a `Response` a handler returned, because
542
+ * a handler that built a whole response has said what it wants.
543
+ */
544
+ declare const applyResponseDraft: (response: Response, draft: ResponseDraft | undefined) => Response;
545
+ /**
546
+ * The status and text a framework-built response should carry.
547
+ *
548
+ * Separate from `applyResponseDraft` because the two answer different
549
+ * questions: this is "what did the handler ask for", used where the framework
550
+ * is deciding the status itself, and that one is "what does a returned response
551
+ * already say", where the handler has decided.
552
+ */
553
+ declare function draftedStatus(draft: ResponseDraft | undefined, fallback: number): {
554
+ status: number;
555
+ statusText?: string;
556
+ };
557
+ //#endregion
558
+ //#region src/rate-limit.d.ts
559
+ /** One key's usage, as the store hands it back. */
560
+ interface RateLimitCount {
561
+ /** How many requests this key has made in the current window. */
562
+ readonly count: number;
563
+ /** When the current window ends, as a millisecond timestamp. */
564
+ readonly resetAt: number;
565
+ }
566
+ /**
567
+ * Where the counts live.
568
+ *
569
+ * ONE METHOD, and it is atomic by contract: `hit` must increment and return the
570
+ * new value in a single step. A `get` then `set` pair is a race — two requests
571
+ * read the same count and both write it — and a limiter that loses increments
572
+ * under load is one that stops working exactly when it is needed. Redis does
573
+ * this with `INCR` plus `PEXPIRE`; the memory store below does it by being
574
+ * single-threaded.
575
+ */
576
+ interface RateLimitStore {
577
+ hit(key: string, windowMs: number): RateLimitCount | Promise<RateLimitCount>;
578
+ }
579
+ interface RateLimitOptions {
580
+ /** How many requests a key may make per window. */
581
+ readonly limit: number;
582
+ /** The window, in milliseconds. */
583
+ readonly windowMs: number;
584
+ /**
585
+ * What counts as one caller.
586
+ *
587
+ * There is no default, for the same reason the store has none: keying by IP is
588
+ * right for a public endpoint and wrong for an authenticated one behind a
589
+ * corporate NAT, where it limits a whole building as though it were one user.
590
+ * Key by user id where there is one, and by IP only where there is not.
591
+ *
592
+ * Returning `null` EXEMPTS the request — an internal caller, a health check.
593
+ */
594
+ readonly key: () => string | null | Promise<string | null>;
595
+ readonly store: RateLimitStore;
596
+ /**
597
+ * What to answer when the limit is reached. A 429 with `Retry-After` by
598
+ * default, which is what a well-behaved client backs off on.
599
+ */
600
+ readonly onLimit?: (info: RateLimitCount & {
601
+ readonly limit: number;
602
+ }) => Response;
603
+ }
604
+ /**
605
+ * A store for ONE PROCESS. Named so the choice is visible at the call site.
606
+ *
607
+ * Correct for a single instance and wrong for every other deployment — see the
608
+ * header. It is here because "no store at all" would push everyone to write this
609
+ * same map badly, not because it is the one to reach for.
610
+ *
611
+ * Expired entries are swept by a `hit` rather than on a timer: a timer keeps
612
+ * the process alive on Node and has to be unref'd. A key is one caller and most
613
+ * callers are never seen again (a scan, a client rotating through an IPv6
614
+ * prefix), so an entry dropped only when its own key came back would stay for
615
+ * the life of the process and the map would grow with every address ever seen.
616
+ *
617
+ * The sweep runs at most once per the longest window in use, so an entry that
618
+ * has expired is gone by the second sweep after it was made, and the map holds
619
+ * what the last two such windows saw rather than everything since boot.
620
+ */
621
+ declare function memoryStore(): RateLimitStore;
622
+ /**
623
+ * Key a limit by client address.
624
+ *
625
+ * `xForwardedFor` IS OFF BY DEFAULT and turning it on is a claim about the
626
+ * deployment: `X-Forwarded-For` is a header a CLIENT can send, so trusting it
627
+ * where no proxy overwrites it lets any caller pick their own bucket and the
628
+ * limit stops existing. See `getRequestIP`.
629
+ *
630
+ * `true` reads the LEFTMOST entry, which is the client only when the edge proxy
631
+ * overwrites the header. Behind a proxy that appends, pass
632
+ * `{ trustedProxies: n }` for the `n` proxies you run: it reads the entry the
633
+ * outermost of them wrote and ignores anything a caller put in front of it.
634
+ *
635
+ * A request with no address at all keys as `"unknown"`, which pools every such
636
+ * caller into one bucket — strict rather than exempt, because the alternative is
637
+ * a bucket an attacker can opt into by arranging to have no address.
638
+ */
639
+ declare function byIP(options?: {
640
+ readonly xForwardedFor?: ForwardedForTrust;
641
+ }): () => string;
642
+ /**
643
+ * The middleware.
644
+ *
645
+ * It runs BEFORE the handler and before validation, which is the whole point:
646
+ * refusing after the body has been parsed is a refusal that already did the
647
+ * work. That ordering is `serverRpc`'s and the route dispatch's, and it is why
648
+ * this is a middleware rather than something a handler calls.
649
+ *
650
+ * A STORE THAT THROWS FAILS OPEN, deliberately and loudly. If Redis is down,
651
+ * refusing every request turns a limiter into the outage — so the request
652
+ * proceeds and the failure is reported. That is the right trade for a limiter
653
+ * and the wrong one for an authorization check, which is why this is not one.
654
+ */
655
+ declare function rateLimit(options: RateLimitOptions): Middleware;
656
+ //#endregion
657
+ //#region src/timing.d.ts
658
+ /**
659
+ * `Server-Timing` entries for the development server: how long a page's
660
+ * `beforeLoad`, its awaited loaders and its render took, and how long a server
661
+ * function ran. The browser's network panel shows them under Timing.
662
+ *
663
+ * Callers gate on `isDev`, a literal `false` in a production build, so none of
664
+ * this reaches a production response.
665
+ */
666
+ /** A clock that starts now and reads off one `Server-Timing` entry per phase. */
667
+ interface ServerTiming {
668
+ /** Close the phase that began at the last call (or at the start) under `name`. */
669
+ phase(name: string, description: string): void;
670
+ /** The header value, or `""` when nothing was measured. */
671
+ header(): string;
672
+ }
673
+ declare function serverTiming(): ServerTiming;
674
+ //#endregion
675
+ //#region src/wire-types.d.ts
676
+ /**
677
+ * What can cross the wire, as types: the check `createServerFn` runs on a
678
+ * handler's result and a validator's input, so a value the codec would refuse
679
+ * at runtime is a type error where it is written.
680
+ *
681
+ * The codec is seroval with `RegExp` refused and errors redacted
682
+ * (`@barqjs/server/codec`). It carries primitives, `bigint`, `undefined`,
683
+ * `Date`, `Error`, `Map`, `Set`, `Promise`, typed arrays, `ArrayBuffer`, arrays
684
+ * and plain objects, and throws on a function, a symbol, a `RegExp`, a `URL`, a
685
+ * `Blob` and an instance of a class it was not given an adapter for.
686
+ *
687
+ * A class instance whose type has no methods is structurally a plain object,
688
+ * and no type can tell the two apart, so that one is caught at runtime only.
689
+ * The same is true of a class a `createSerializationAdapter` carries: its type
690
+ * has methods, so it is a type error here, and `strict: { output: false }` is
691
+ * how a function that returns one says the adapter is there.
692
+ */
693
+ type Leaf = string | number | boolean | bigint | null | undefined | void | Date | Error | ArrayBuffer | ArrayBufferView;
694
+ /** Classes the codec refuses whose types would otherwise be read member by member. */
695
+ type Refused = readonly [RegExp, "a RegExp"] | readonly [URL, "a URL"] | readonly [URLSearchParams, "a URLSearchParams"] | readonly [Blob, "a Blob"] | readonly [Headers, "a Headers"] | readonly [Request, "a Request"] | readonly [Response, "a Response, which crosses only as the whole result"] | readonly [ReadableStream, "a stream, which crosses only as the whole result"] | readonly [WeakMap<object, unknown>, "a WeakMap"] | readonly [WeakSet<object>, "a WeakSet"];
696
+ type RefusedName<Value> = Refused extends (infer Each) ? Each extends readonly [infer Class, infer Name] ? Value extends Class ? Name : never : never : never;
697
+ /** Deep enough for any payload written by hand; a recursive type stops here rather than looping. */
698
+ type Depth = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
699
+ /**
700
+ * Every place in `Value` the codec cannot carry, as a sentence naming where,
701
+ * or `never` when there is none.
702
+ */
703
+ type WireProblem<Value, Path extends string = "the value", Left extends number = 10> = [Left] extends [never] ? never : 0 extends 1 & Value ? never : unknown extends Value ? never : Value extends Leaf ? never : Value extends symbol ? `${Path} is a symbol` : Value extends ((...args: never[]) => unknown) ? `${Path} is a function` : [RefusedName<Value>] extends [never] ? Value extends Promise<infer Settled> ? WireProblem<Settled, Path, Depth[Left]> : Value extends ReadonlyMap<infer Key, infer Item> ? WireProblem<Key, `${Path}'s keys`, Depth[Left]> | WireProblem<Item, `${Path}'s values`, Depth[Left]> : Value extends ReadonlySet<infer Item> ? WireProblem<Item, `${Path}'s members`, Depth[Left]> : Value extends readonly unknown[] ? WireProblem<Value[number], `${Path}[number]`, Depth[Left]> : Value extends object ? { [Key in keyof Value]-?: WireProblem<Value[Key], `${Path}.${Key & string}`, Depth[Left]>; }[keyof Value] : never : `${Path} is ${RefusedName<Value>}`;
704
+ /**
705
+ * A handler's result: a `Response` or a stream as the whole of it, a
706
+ * component, which crosses as a frame of its markup, or a value the codec
707
+ * carries. A stream's values are checked like any other.
708
+ */
709
+ type ResultProblem<Result> = 0 extends 1 & Result ? never : Result extends Response ? never : Result extends ((props: never) => unknown) ? never : Result extends ReadableStream<infer Value> ? WireProblem<Value, "each value it streams"> : Result extends AsyncIterable<infer Value> ? WireProblem<Value, "each value it yields"> : WireProblem<Result, "the result">;
710
+ /** A validator's input: a value the codec carries, or a form where a form can be sent. */
711
+ type InputProblem<Input, Method> = 0 extends 1 & Input ? never : Input extends FormData ? Method extends "POST" ? never : "the input is a form, and a GET has no body to carry one" : WireProblem<Input, "the input">;
712
+ /**
713
+ * What a checked type must also be: anything, when there is no problem, and a
714
+ * type naming the problem, which nothing is, when there is one. The name is
715
+ * what the type error shows.
716
+ */
717
+ type Crossable<Problem> = [Problem] extends [never] ? unknown : {
718
+ readonly "cannot cross the wire": Problem;
719
+ };
720
+ /** `strict`, as `createServerFn` takes it. */
721
+ type Strictness = boolean | {
722
+ readonly input?: boolean;
723
+ readonly output?: boolean;
724
+ };
725
+ /** Whether a side is checked: on unless `strict` or its side says `false`. */
726
+ type StrictOn<Strict, Side extends "input" | "output"> = Strict extends false ? false : Strict extends { readonly [Key in Side]: false; } ? false : true;
727
+ //#endregion
728
+ //#region src/index.d.ts
729
+ /** TanStack's `json`: a JSON `Response`, which a handler returns as its answer. */
730
+ declare function json(payload: unknown, init?: ResponseInit): Response;
731
+ declare function checkInput(built: {
732
+ readonly validator: Validator<unknown> | null;
733
+ }, raw: unknown,
734
+ /**
735
+ * Whether a MIDDLEWARE in the chain declared a validator.
736
+ *
737
+ * The refusal below asks "does anything expect input?", and before middleware
738
+ * validators existed the function's own was the only thing that could answer.
739
+ * A chain that validates has opened the channel just as surely, so refusing
740
+ * here would make `.validator(schema)` on a middleware unusable by any
741
+ * function that declares none of its own — which is the whole point of
742
+ * putting one there.
743
+ */
744
+ chainValidates?: boolean): Promise<unknown>;
745
+ /**
746
+ * What a handler is handed, which is TanStack's shape:
747
+ * `.handler(async ({ data }) => …)`.
748
+ *
749
+ * `context` is what the middleware chain contributed, merged outermost-first,
750
+ * and typed by what each middleware passed to `next({ context })`.
751
+ * `signal` aborts with the request, so a handler can hand it to `fetch` and a
752
+ * client that navigates away stops paying for the work.
753
+ */
754
+ interface HandlerContext<In, Context extends object = Empty> {
755
+ readonly data: In;
756
+ readonly context: OpenContext<Context>;
757
+ readonly signal: AbortSignal;
758
+ /** The method this function answers. */
759
+ readonly method: ServerFnMethod;
760
+ /** Which function is running, by the id it is mounted at. Empty when it is not mounted. */
761
+ readonly serverFnMeta: {
762
+ readonly id: string;
763
+ };
764
+ }
765
+ interface Built<Data, Out, Context extends object = Empty> {
766
+ validator: Validator<unknown> | null;
767
+ middleware: readonly Middleware[];
768
+ handler: (context: HandlerContext<Data, Context>) => Out | Promise<Out>;
769
+ }
770
+ /**
771
+ * Where a server function's builder is: its chain, its own validator, its
772
+ * method, and whether what crosses the wire is checked.
773
+ */
774
+ interface ServerFnState {
775
+ readonly chain: Contribution;
776
+ readonly own: Contribution;
777
+ readonly method: ServerFnMethod;
778
+ readonly strict: Strictness;
779
+ }
780
+ interface FreshServerFn<Method extends ServerFnMethod, Strict extends Strictness = true> extends ServerFnState {
781
+ readonly chain: NoContribution;
782
+ readonly own: NoContribution;
783
+ readonly method: Method;
784
+ readonly strict: Strict;
785
+ }
786
+ interface FnWithChain<State extends ServerFnState, Chain> extends ServerFnState {
787
+ readonly chain: Merged<State["chain"], ChainContribution<Chain>>;
788
+ readonly own: State["own"];
789
+ readonly method: State["method"];
790
+ readonly strict: State["strict"];
791
+ }
792
+ interface Validates<In, Out> extends Contribution {
793
+ readonly context: Empty;
794
+ readonly sent: Empty;
795
+ readonly clientContext: Empty;
796
+ readonly input: In;
797
+ readonly output: Out;
798
+ readonly validates: true;
799
+ }
800
+ interface FnWithValidator<State extends ServerFnState, In, Out> extends ServerFnState {
801
+ readonly chain: State["chain"];
802
+ readonly own: Validates<In, Out>;
803
+ readonly method: State["method"];
804
+ readonly strict: State["strict"];
805
+ }
806
+ /**
807
+ * What a validator's input must also be: anything, unless it holds something
808
+ * the codec cannot carry, when it must be a type naming that, which nothing is.
809
+ */
810
+ type InputCheck<State extends ServerFnState, In> = StrictOn<State["strict"], "input"> extends true ? Crossable<InputProblem<In, State["method"]>> : unknown;
811
+ /** The same, for what a handler returns. */
812
+ type ResultCheck<State extends ServerFnState, Result> = StrictOn<State["strict"], "output"> extends true ? Crossable<ResultProblem<Result>> : unknown;
813
+ /**
814
+ * What the caller passes: the input of the first validator that runs, which is
815
+ * a middleware's when the chain validates. `undefined` when nothing validates,
816
+ * since a function that declares no validator accepts no argument.
817
+ */
818
+ type CallerInput<State extends ServerFnState> = State["chain"]["validates"] extends true ? State["chain"]["input"] : State["own"]["validates"] extends true ? State["own"]["input"] : undefined;
819
+ /** What the handler is handed: the last validator's output. */
820
+ type HandlerData<State extends ServerFnState> = State["own"]["validates"] extends true ? State["own"]["output"] : State["chain"]["validates"] extends true ? State["chain"]["output"] : undefined;
821
+ /** What the handler's `context` holds: the global middleware's, then its own chain's. */
822
+ type HandlerContextOf<State extends ServerFnState> = GlobalFunctionContext & State["chain"]["context"];
823
+ /**
824
+ * The three-state discriminator, which is SvelteKit's idea and the best value
825
+ * in the survey: no validator means any argument is a 400, and opening the
826
+ * channel costs a schema or the literal `'unchecked'`.
827
+ *
828
+ * Every step is typed: the schema decides what a caller passes and what the
829
+ * handler is handed, and each middleware's `next({ context })` decides what the
830
+ * handler's `context` holds.
831
+ */
832
+ interface ServerFnBuilder<State extends ServerFnState = ServerFnState> {
833
+ /**
834
+ * Middleware that runs before the handler, after any listed before. A server
835
+ * function in the list stands for the middleware it declared: its guards
836
+ * run here, its handler does not.
837
+ */
838
+ middleware<const Chain extends readonly ChainStep[]>(chain: Chain): ServerFnBuilder<FnWithChain<State, Chain>>;
839
+ /**
840
+ * Open the input channel: a Standard Schema, a function that returns the
841
+ * validated value or throws, an object with a `parse`, or `"unchecked"`.
842
+ * What a caller passes is the schema's input, and what it produces is the
843
+ * type of `data` in the handler. The schema form is tried first: an arktype
844
+ * type is callable as well, and read as a function its input would be lost.
845
+ */
846
+ validator<Schema extends StandardSchemaLike>(schema: Schema & InputCheck<State, StandardInput<Schema>>): ServerFnBuilder<FnWithValidator<State, StandardInput<Schema>, StandardOutput<Schema>>>;
847
+ validator<In, Out>(validate: ((input: In) => Out) & InputCheck<State, In>): ServerFnBuilder<FnWithValidator<State, In, Awaited<Out>>>;
848
+ validator<In, Out>(schema: {
849
+ readonly parse: (input: In) => Out;
850
+ } & InputCheck<State, In>): ServerFnBuilder<FnWithValidator<State, In, Awaited<Out>>>;
851
+ validator(unchecked: "unchecked"): ServerFnBuilder<FnWithValidator<State, unknown, unknown>>;
852
+ /** `validator` under the name TanStack's release candidates used. */
853
+ inputValidator<Schema extends StandardSchemaLike>(schema: Schema & InputCheck<State, StandardInput<Schema>>): ServerFnBuilder<FnWithValidator<State, StandardInput<Schema>, StandardOutput<Schema>>>;
854
+ inputValidator<In, Out>(validate: ((input: In) => Out) & InputCheck<State, In>): ServerFnBuilder<FnWithValidator<State, In, Awaited<Out>>>;
855
+ inputValidator<In, Out>(schema: {
856
+ readonly parse: (input: In) => Out;
857
+ } & InputCheck<State, In>): ServerFnBuilder<FnWithValidator<State, In, Awaited<Out>>>;
858
+ inputValidator(unchecked: "unchecked"): ServerFnBuilder<FnWithValidator<State, unknown, unknown>>;
859
+ /**
860
+ * The body. What it returns must cross the wire: a function, a symbol, or an
861
+ * instance of a class the codec refuses is a type error here, naming where
862
+ * it is. `createServerFn({ strict: false })` turns the check off.
863
+ */
864
+ handler<Result>(fn: ((context: HandlerContext<HandlerData<State>, HandlerContextOf<State>>) => Result | Promise<Result>) & ResultCheck<State, Result>): ServerFn<CallerInput<State>, Streamed<Awaited<Result>>, State["method"]> & Carries<State["chain"]>;
865
+ }
866
+ /**
867
+ * What `createServerFn` accepts.
868
+ *
869
+ * `method` is TanStack's, with TanStack's default: `GET`. A function that
870
+ * writes declares `POST`, which is also the only method a form can reach. A
871
+ * link still cannot reach a `GET` one: every call carries the
872
+ * {@link RPC_CALLER} header, which nothing but script can set, and the server
873
+ * refuses a `GET` without it.
874
+ */
875
+ interface ServerFnOptions<Method extends ServerFnMethod = ServerFnMethod, Strict extends Strictness = Strictness> {
876
+ readonly method?: Method;
877
+ /**
878
+ * Whether the types refuse an input or a result the codec cannot carry. On
879
+ * by default; `false` turns both off, `{ input: false }` or
880
+ * `{ output: false }` one side. The codec still refuses at runtime what it
881
+ * cannot carry: this only says the author knows, as for a class a
882
+ * `createSerializationAdapter` carries.
883
+ */
884
+ readonly strict?: Strict;
885
+ }
886
+ /**
887
+ * Author a server function. The value this returns is replaced by the compiler
888
+ * on both sides, so what it does when compiled by nothing is only the
889
+ * uncompiled-development path: it runs the handler in-process.
890
+ */
891
+ declare function createServerFn<Method extends ServerFnMethod = "GET", const Strict extends Strictness = true>(options?: ServerFnOptions<Method, Strict>): ServerFnBuilder<FreshServerFn<Method, Strict>>;
892
+ /**
893
+ * The server half. The compiler emits this in a module compiled for the server,
894
+ * with the real handler and the id it assigned.
895
+ *
896
+ * `In` is what a caller passes and `Data` what the handler is handed; the
897
+ * validator is what turns one into the other, at runtime.
898
+ */
899
+ declare function serverRpc<In, Out, Data = In, Context extends object = Empty, Method extends ServerFnMethod = "POST">(meta: ServerFnMeta, built: Built<Data, Out, Context>): ServerFn<In, Streamed<Awaited<Out>>, Method>;
900
+ /**
901
+ * The middleware chain a server function carries, by REFERENCE.
902
+ *
903
+ * `serverRpc` attaches `built` to the function object, so the chain is the real
904
+ * array of closures rather than something re-derived. That matters: a build
905
+ * cannot read a chain out of source. `.middleware([m])`, `.middleware([...c])`
906
+ * and `.middleware(c.filter(Boolean))` are all runtime expressions, and
907
+ * `Middleware` is an anonymous closure with no build-visible identity — so the
908
+ * only sound comparison is `===` against the same closure the route declared.
909
+ *
910
+ * Empty for a client stub, which carries no chain because it carries no handler.
911
+ */
912
+ declare function middlewareOf(fn: AnyServerFn): readonly Middleware[];
913
+ //#endregion
914
+ export { getRequestIP as $, RateLimitCount as A, SessionData as At, applyResponseDraft as B, parseCookies as Bt, InputProblem as C, StartInstance as Ct, WireProblem as D, startOptions as Dt, Strictness as E, createStart as Et, rateLimit as F, unsealSession as Ft, draftedStatus as G, collectRequestCss as H, ForwardedForTrust as I, updateSession as It, getGlobalStartContext as J, getCookie as K, RequestContext as L, useSession as Lt, RateLimitStore as M, clearSession as Mt, byIP as N, getSession as Nt, ServerTiming as O, Session as Ot, memoryStore as P, sealSession as Pt, getRequestHost as Q, ResponseDraft as R, CookieOptions as Rt, Crossable as S, RequestContextOf as St, StrictOn as T, clearStart as Tt, createResponseDraft as U, clearResponseHeaders as V, serializeCookie as Vt, deleteCookie as W, getRequestHeader as X, getRequest as Y, getRequestHeaders as Z, createSerializationAdapter as _, withRequest as _t, FreshServerFn as a, installCssSink as at, middlewareOf as b, GlobalRequestContext as bt, HandlerData as c, peekRequest as ct, SerializationAdapter as d, setCookie as dt, getRequestProtocol as et, ServerFnBuilder as f, setRequestMiddlewareContext as ft, checkInput as g, takeSendContext as gt, Validates as h, setResponseStatus as ht, FnWithValidator as i, getResponseStatus as it, RateLimitOptions as j, SessionManager as jt, serverTiming as k, SessionConfig as kt, InputCheck as l, peekResponseDraft as lt, ServerFnState as m, setResponseHeaders as mt, CallerInput as n, getResponseHeader as nt, HandlerContext as o, invalidateFrames as ot, ServerFnOptions as p, setResponseHeader as pt, getCookies as q, FnWithChain as r, getResponseHeaders as rt, HandlerContextOf as s, markResponseSent as st, AnySerializationAdapter$1 as t, getRequestUrl as tt, ResultCheck as u, removeResponseHeader as ut, createServerFn as v, FunctionContextOf as vt, ResultProblem as w, StartOptions as wt, serverRpc as x, Register as xt, json as y, GlobalFunctionContext as yt, appendResponseHeader as z, deleteCookieLine as zt };
915
+ //# sourceMappingURL=index-Bm_-MTj6.d.ts.map