@thednp/rpc 0.2.0 → 0.3.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/AGENTS.md +54 -38
- package/CHANGELOG.md +85 -0
- package/README.md +27 -12
- package/dist/express/express.d.mts +5 -3
- package/dist/express/express.d.mts.map +1 -1
- package/dist/express/express.mjs +95 -20
- package/dist/express/express.mjs.map +1 -1
- package/dist/fastify/fastify.d.mts.map +1 -1
- package/dist/fastify/fastify.mjs +59 -10
- package/dist/fastify/fastify.mjs.map +1 -1
- package/dist/fastify/plugin/fastify/plugin.d.mts +13 -0
- package/dist/fastify/plugin/fastify/plugin.d.mts.map +1 -1
- package/dist/fastify/plugin/fastify/plugin.mjs +59 -10
- package/dist/fastify/plugin/fastify/plugin.mjs.map +1 -1
- package/dist/h3/h3.d.mts.map +1 -1
- package/dist/h3/h3.mjs +69 -16
- package/dist/h3/h3.mjs.map +1 -1
- package/dist/helpers/helpers.d.mts +63 -5
- package/dist/helpers/helpers.d.mts.map +1 -1
- package/dist/helpers/helpers.mjs +58 -1
- package/dist/helpers/helpers.mjs.map +1 -1
- package/dist/hono/hono.d.mts.map +1 -1
- package/dist/hono/hono.mjs +59 -8
- package/dist/hono/hono.mjs.map +1 -1
- package/dist/index.d.mts +48 -5
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +84 -50
- package/dist/index.mjs.map +1 -1
- package/dist/koa/koa.d.mts.map +1 -1
- package/dist/koa/koa.mjs +70 -19
- package/dist/koa/koa.mjs.map +1 -1
- package/dist/server/server.d.mts +302 -27
- package/dist/server/server.d.mts.map +1 -1
- package/dist/server/server.mjs +180 -69
- package/dist/server/server.mjs.map +1 -1
- package/package.json +20 -18
package/dist/server/server.d.mts
CHANGED
|
@@ -1,15 +1,95 @@
|
|
|
1
|
-
import { ResolvedConfig, ViteDevServer } from "vite";
|
|
1
|
+
import { Connect, ResolvedConfig, ViteDevServer } from "vite";
|
|
2
2
|
import "@thednp/rpc";
|
|
3
|
-
import "
|
|
4
|
-
import "
|
|
3
|
+
import { IncomingMessage, ServerResponse } from "node:http";
|
|
4
|
+
import { NextFunction, Request, Response as Response$1 } from "express";
|
|
5
|
+
import { MiddlewareHandler } from "hono";
|
|
5
6
|
import "@hono/node-server";
|
|
6
7
|
import "hono/utils/http-status";
|
|
7
8
|
import "hono/factory";
|
|
8
|
-
import "fastify";
|
|
9
|
+
import { FastifyReply, FastifyRequest, HookHandlerDoneFunction } from "fastify";
|
|
9
10
|
import "fastify-plugin";
|
|
10
|
-
import "koa";
|
|
11
|
-
import "h3";
|
|
11
|
+
import { Context, Next } from "koa";
|
|
12
|
+
import { Middleware } from "h3";
|
|
13
|
+
//#region src/express/types.d.ts
|
|
14
|
+
/**
|
|
15
|
+
* Express/Connect middleware handler signature used by the RPC middleware.
|
|
16
|
+
*/
|
|
17
|
+
interface ExpressMiddlewareHooks {
|
|
18
|
+
/**
|
|
19
|
+
* The handler invoked for each matched request.
|
|
20
|
+
* @param req - Node or Express request object
|
|
21
|
+
* @param res - Node or Express response object
|
|
22
|
+
* @param next - Connect or Express next function
|
|
23
|
+
*/
|
|
24
|
+
handler: (req: IncomingMessage | Request, res: ServerResponse | Response$1, next: Connect.NextFunction | NextFunction) => Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/hono/types.d.ts
|
|
28
|
+
/**
|
|
29
|
+
* Hono middleware handler signature used by the RPC middleware.
|
|
30
|
+
*/
|
|
31
|
+
interface HonoMiddlewareHooks {
|
|
32
|
+
/** Hono middleware handler */
|
|
33
|
+
handler: MiddlewareHandler;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/fastify/types.d.ts
|
|
37
|
+
/**
|
|
38
|
+
* Fastify middleware handler signature used by the RPC middleware.
|
|
39
|
+
*/
|
|
40
|
+
interface FastifyMiddlewareHooks {
|
|
41
|
+
/**
|
|
42
|
+
* The handler invoked for each matched request.
|
|
43
|
+
* @param req - Fastify request object
|
|
44
|
+
* @param res - Fastify reply object
|
|
45
|
+
* @param done - Fastify hook completion callback
|
|
46
|
+
*/
|
|
47
|
+
handler: (req: FastifyRequest, res: FastifyReply, done: HookHandlerDoneFunction) => Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/koa/types.d.ts
|
|
51
|
+
/**
|
|
52
|
+
* Koa middleware handler signature used by the RPC middleware.
|
|
53
|
+
*/
|
|
54
|
+
interface KoaMiddlewareHooks {
|
|
55
|
+
/**
|
|
56
|
+
* The handler invoked for each matched request.
|
|
57
|
+
* @param ctx - Koa context object
|
|
58
|
+
* @param next - Koa next function
|
|
59
|
+
*/
|
|
60
|
+
handler: (ctx: Context, next: Next) => Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/h3/types.d.ts
|
|
64
|
+
/**
|
|
65
|
+
* h3 middleware handler signature used by the RPC middleware.
|
|
66
|
+
*/
|
|
67
|
+
interface H3MiddlewareHooks {
|
|
68
|
+
/**
|
|
69
|
+
* The handler invoked for each matched request.
|
|
70
|
+
* @param event - h3 event object
|
|
71
|
+
* @param next - h3 next function
|
|
72
|
+
*/
|
|
73
|
+
handler: Middleware;
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
12
76
|
//#region src/types.d.ts
|
|
77
|
+
/**
|
|
78
|
+
* Maps each supported framework adapter to its middleware hooks (handler signatures).
|
|
79
|
+
* Used to keep the middleware options type-safe per adapter.
|
|
80
|
+
*/
|
|
81
|
+
interface FrameworkHooks {
|
|
82
|
+
/** Express/Connect middleware handler signature */
|
|
83
|
+
express: ExpressMiddlewareHooks;
|
|
84
|
+
/** Hono middleware handler signature */
|
|
85
|
+
hono: HonoMiddlewareHooks;
|
|
86
|
+
/** Fastify middleware handler signature */
|
|
87
|
+
fastify: FastifyMiddlewareHooks;
|
|
88
|
+
/** Koa middleware handler signature */
|
|
89
|
+
koa: KoaMiddlewareHooks;
|
|
90
|
+
/** h3 middleware handler signature */
|
|
91
|
+
h3: H3MiddlewareHooks;
|
|
92
|
+
}
|
|
13
93
|
/**
|
|
14
94
|
* Content types the RPC client modules send with each request.
|
|
15
95
|
*/
|
|
@@ -40,6 +120,11 @@ interface ServerFunctionOptions {
|
|
|
40
120
|
* @default "POST"
|
|
41
121
|
*/
|
|
42
122
|
method?: "GET" | "POST";
|
|
123
|
+
/**
|
|
124
|
+
* RPC endpoint prefix
|
|
125
|
+
* @default "__rpc"
|
|
126
|
+
*/
|
|
127
|
+
rpcPrefix?: string;
|
|
43
128
|
}
|
|
44
129
|
// primitives and their compositions
|
|
45
130
|
/**
|
|
@@ -98,12 +183,14 @@ interface RpcPluginOptionsInternal {
|
|
|
98
183
|
/**
|
|
99
184
|
* Partial Vite config used when scanning server files outside a running dev server.
|
|
100
185
|
*/
|
|
101
|
-
|
|
186
|
+
interface ScanConfig extends Pick<ResolvedConfig, "base"> {
|
|
102
187
|
root?: string;
|
|
103
188
|
server?: Partial<ResolvedConfig["server"]>;
|
|
104
189
|
serverFiles?: "exact" | "glob";
|
|
105
190
|
scanRoot?: string;
|
|
106
|
-
|
|
191
|
+
/** Default rpcPrefix to register scanned functions under when a function does not declare its own. Defaults to `__rpc` for backward compatibility. */
|
|
192
|
+
rpcPrefix?: string;
|
|
193
|
+
}
|
|
107
194
|
/**
|
|
108
195
|
* Entry in the server functions map: registered name, client handler,
|
|
109
196
|
* optional per-function options, and the original export name.
|
|
@@ -158,8 +245,91 @@ interface RpcPluginOptions {
|
|
|
158
245
|
*/
|
|
159
246
|
serverFiles?: "exact" | "glob";
|
|
160
247
|
}
|
|
248
|
+
interface MiddlewareOptions<A extends RpcPluginOptions["adapter"] = "express"> {
|
|
249
|
+
/**
|
|
250
|
+
* Name for the middleware (used for identification in Express stack)
|
|
251
|
+
*/
|
|
252
|
+
name?: string;
|
|
253
|
+
/**
|
|
254
|
+
* Path pattern to match for middleware execution.
|
|
255
|
+
* Accepts string or RegExp to filter requests based on URL path.
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* // String path
|
|
259
|
+
* path: "/api/v1"
|
|
260
|
+
*
|
|
261
|
+
* // RegExp pattern
|
|
262
|
+
* path: /^\/api\/v[0-9]+/
|
|
263
|
+
*/
|
|
264
|
+
path?: string | RegExp;
|
|
265
|
+
/**
|
|
266
|
+
* RPC prefix without leading slash (e.g. "__rpc")
|
|
267
|
+
* Leading slash will be added automatically by the middleware.
|
|
268
|
+
* This prefix defines the base path for all RPC endpoints.
|
|
269
|
+
* @default string
|
|
270
|
+
* @example
|
|
271
|
+
* // Results in endpoints like: /api/rpc/myFunction
|
|
272
|
+
* rpcPrefix: "api/rpc"
|
|
273
|
+
*/
|
|
274
|
+
rpcPrefix?: string | false;
|
|
275
|
+
/**
|
|
276
|
+
* Allowed request origin (e.g. "https://example.com").
|
|
277
|
+
* When set, any request carrying an `Origin` header that does not match
|
|
278
|
+
* is rejected with a 403 Forbidden response. Requests without an `Origin`
|
|
279
|
+
* header (curl, native clients) pass through unchecked.
|
|
280
|
+
* When unset (default), no origin validation is performed.
|
|
281
|
+
*/
|
|
282
|
+
origin?: string;
|
|
283
|
+
/**
|
|
284
|
+
* Server file matching mode. Use `"exact"` for `server.ts|js|mjs|mts`
|
|
285
|
+
* names, or `"glob"` to match `**\/*.server.{ts,js,mjs,mts}` inside the
|
|
286
|
+
* scan root. Only used for the lazy production scan when the middleware
|
|
287
|
+
* populates its prefix map on first request.
|
|
288
|
+
* @default "exact"
|
|
289
|
+
*/
|
|
290
|
+
serverFiles?: "exact" | "glob";
|
|
291
|
+
/**
|
|
292
|
+
* Root directory for scanning server files. Defaults to `<root>/src/api`.
|
|
293
|
+
* Only used for the lazy production scan.
|
|
294
|
+
*/
|
|
295
|
+
scanRoot?: string;
|
|
296
|
+
/**
|
|
297
|
+
* Async handler for request processing.
|
|
298
|
+
* Core middleware function that processes incoming requests.
|
|
299
|
+
*
|
|
300
|
+
* @param req - The incoming request object
|
|
301
|
+
* @param res - The server response object
|
|
302
|
+
* @param next - Function to pass control to the next middleware
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* handler: async (req, res, next) => {
|
|
306
|
+
* // Process request
|
|
307
|
+
* const data = await processRequest(req);
|
|
308
|
+
*
|
|
309
|
+
* // Send response
|
|
310
|
+
* sendResponse(res, { data }, 200);
|
|
311
|
+
* }
|
|
312
|
+
*/
|
|
313
|
+
handler?: FrameworkHooks[A]["handler"];
|
|
314
|
+
}
|
|
161
315
|
//#endregion
|
|
162
316
|
//#region src/functionsMap.d.ts
|
|
317
|
+
/**
|
|
318
|
+
* Map of rpcPrefix -> Map of function names -> ServerFnEntry
|
|
319
|
+
* Enables multiple RPC instances with different prefixes to coexist
|
|
320
|
+
* without name collisions.
|
|
321
|
+
*/
|
|
322
|
+
declare const serverFunctionsByPrefix: Map<string, Map<string, ServerFnEntry>>;
|
|
323
|
+
/**
|
|
324
|
+
* Gets or creates the function map for a specific prefix.
|
|
325
|
+
* @param prefix - The RPC prefix (e.g., "__rpc", "v1:rpc", "admin:rpc")
|
|
326
|
+
* @returns Map of function names to ServerFnEntry for that prefix
|
|
327
|
+
*/
|
|
328
|
+
declare const getFunctionsForPrefix: (prefix: string) => Map<string, ServerFnEntry>;
|
|
329
|
+
/**
|
|
330
|
+
* Backward compatibility: default map for the default prefix.
|
|
331
|
+
* Legacy code can still use serverFunctionsMap.set(name, entry).
|
|
332
|
+
*/
|
|
163
333
|
declare const serverFunctionsMap: Map<string, ServerFnEntry>;
|
|
164
334
|
//#endregion
|
|
165
335
|
//#region src/scanForServerFiles.d.ts
|
|
@@ -167,7 +337,7 @@ declare const serverFunctionsMap: Map<string, ServerFnEntry>;
|
|
|
167
337
|
declare const scannedServerFiles: Set<string>;
|
|
168
338
|
/**
|
|
169
339
|
* Scans `src/api/` (or an explicit `scanRoot`) for server function files
|
|
170
|
-
* and populates the
|
|
340
|
+
* and populates the server functions map (scoped by rpcPrefix) with their exported functions.
|
|
171
341
|
* Uses Vite's SSR module loading to resolve and execute each file.
|
|
172
342
|
*
|
|
173
343
|
* Supports two matching modes via `config.serverFiles`:
|
|
@@ -179,22 +349,49 @@ declare const scannedServerFiles: Set<string>;
|
|
|
179
349
|
declare const scanForServerFiles: (initialCfg?: ScanConfig, devServer?: ViteDevServer) => Promise<void>;
|
|
180
350
|
//#endregion
|
|
181
351
|
//#region src/createFunction.d.ts
|
|
352
|
+
/**
|
|
353
|
+
* Extended options for createServerFunction, including rpcPrefix for multi-instance support.
|
|
354
|
+
*/
|
|
355
|
+
interface CreateServerFunctionOptions extends Partial<ServerFunctionOptions> {
|
|
356
|
+
/**
|
|
357
|
+
* RPC prefix for this function. Enables multiple RPC instances with different prefixes.
|
|
358
|
+
* When using multi-prefix setup, functions with the same name but different prefixes
|
|
359
|
+
* can coexist without collision.
|
|
360
|
+
* @default "__rpc"
|
|
361
|
+
* @example
|
|
362
|
+
* // v1 API
|
|
363
|
+
* export const login = createServerFunction(
|
|
364
|
+
* "login",
|
|
365
|
+
* async (signal, email, password) => ({...}),
|
|
366
|
+
* { rpcPrefix: "v1:rpc" },
|
|
367
|
+
* );
|
|
368
|
+
*
|
|
369
|
+
* // v2 API - same function name, different prefix
|
|
370
|
+
* export const login = createServerFunction(
|
|
371
|
+
* "login",
|
|
372
|
+
* async (signal, credentials) => ({...}),
|
|
373
|
+
* { rpcPrefix: "v2:rpc" },
|
|
374
|
+
* );
|
|
375
|
+
*/
|
|
376
|
+
rpcPrefix?: string;
|
|
377
|
+
}
|
|
182
378
|
/**
|
|
183
379
|
* Creates a server-side RPC function.
|
|
184
|
-
* Registers the function in the server functions map and returns
|
|
185
|
-
* wrapper that exposes `data` (Promise) and `cancel` (function)
|
|
380
|
+
* Registers the function in the server functions map (scoped by rpcPrefix) and returns
|
|
381
|
+
* a client-compatible wrapper that exposes `data` (Promise) and `cancel` (function)
|
|
382
|
+
* for request lifecycle control.
|
|
186
383
|
* @param name - Unique identifier used by the RPC router to dispatch requests
|
|
187
384
|
* @param handler - The actual implementation receiving an AbortSignal followed by JSON-serializable arguments
|
|
188
|
-
* @param fnOptions - Optional contentType and
|
|
385
|
+
* @param fnOptions - Optional contentType, credentials, and rpcPrefix settings
|
|
189
386
|
* @returns A client stub with `data` promise and `cancel` method, auto-registered in the server map
|
|
190
387
|
*/
|
|
191
|
-
declare function createServerFunction<TArgs extends JsonArray = JsonArray, TResult extends JsonValue = JsonValue>(name: string, handler: ServerFunctionInit<TArgs, TResult>, fnOptions?:
|
|
388
|
+
declare function createServerFunction<TArgs extends JsonArray = JsonArray, TResult extends JsonValue = JsonValue>(name: string, handler: ServerFunctionInit<TArgs, TResult>, fnOptions?: CreateServerFunctionOptions): ClientFunction<TArgs, TResult>;
|
|
192
389
|
//#endregion
|
|
193
390
|
//#region src/getClientModules.d.ts
|
|
194
391
|
/**
|
|
195
392
|
* Generates the complete client-side module bundle by iterating all registered server functions
|
|
196
|
-
* and producing fetch-based stubs for each. The result is transformed by Vite
|
|
197
|
-
* the dev server or production build.
|
|
393
|
+
* for a specific prefix and producing fetch-based stubs for each. The result is transformed by Vite
|
|
394
|
+
* (or Oxc) during the dev server or production build.
|
|
198
395
|
* @param initialOptions - Plugin options containing rpcPrefix and optional adapter
|
|
199
396
|
* @returns A string of JavaScript code with all client RPC modules and their import dependencies
|
|
200
397
|
*/
|
|
@@ -253,9 +450,25 @@ declare const hasContentTypeMismatch: (declared: ContentType, rawHeader: string
|
|
|
253
450
|
* @returns The escaped string safe for use in new RegExp()
|
|
254
451
|
*/
|
|
255
452
|
declare function escapeRegExp(s: string): string;
|
|
453
|
+
/**
|
|
454
|
+
* Parses a raw request URL against a fixed base without ever throwing.
|
|
455
|
+
* Malformed request-targets (e.g. `/\`, `//`, `/\/`) make the WHATWG URL
|
|
456
|
+
* parser throw `TypeError: Invalid URL`; the adapters call this while
|
|
457
|
+
* building the per-request URL **before** their dispatch `try` block, so an
|
|
458
|
+
* unhandled rejection there crashes raw `node:http` hosts (and Express 4).
|
|
459
|
+
* On failure we fall back to the base root: the resulting pathname never
|
|
460
|
+
* matches the RPC prefix, so the request is treated as non-RPC and falls
|
|
461
|
+
* through to `next()` / 404 instead of crashing the process.
|
|
462
|
+
* @param rawUrl - Raw request URL (path + optional query string)
|
|
463
|
+
* @param base - Optional base URL, defaults to a fixed localhost origin
|
|
464
|
+
* @returns A URL object; never throws
|
|
465
|
+
*/
|
|
466
|
+
declare const safeURL: (rawUrl: string, base?: string) => URL;
|
|
467
|
+
/** Global rpcPrefix from the last loaded config / middleware — fallback for functions without explicit prefix. */
|
|
468
|
+
declare const getGlobalPrefix: () => string | undefined;
|
|
469
|
+
declare const setGlobalPrefix: (prefix: string | undefined) => void;
|
|
256
470
|
//#endregion
|
|
257
471
|
//#region src/context.d.ts
|
|
258
|
-
/** @module Server-side request context. Exports the `RequestEvent` shape, `provideRequestContext` to establish it around a dispatch, `getRequestContext` to read it from anywhere inside the async tree, and `redirect` for framework-level redirects. Never import this module in client code — it is server-only. */
|
|
259
472
|
/**
|
|
260
473
|
* A per-request context established by the framework adapters around
|
|
261
474
|
* server-function dispatch, mirroring Solid Start's `FetchEvent`. Any code
|
|
@@ -293,6 +506,30 @@ interface RequestEvent {
|
|
|
293
506
|
location: string;
|
|
294
507
|
status: number;
|
|
295
508
|
};
|
|
509
|
+
/**
|
|
510
|
+
* Bound adapter-native response short-circuit. Writes the given status and
|
|
511
|
+
* JSON body (plus optional headers) directly, bypassing the standard
|
|
512
|
+
* `{ data }` response. Setting `sent` makes the middleware skip the JSON
|
|
513
|
+
* `{ data }` send, mirroring `redirect`/`redirected`.
|
|
514
|
+
* @param status - HTTP status code (e.g. 401, 413, 429)
|
|
515
|
+
* @param body - JSON-serializable response body
|
|
516
|
+
* @param headers - Optional response headers (e.g. `{ "Retry-After": "60" }`)
|
|
517
|
+
*/
|
|
518
|
+
send: (status: number, body: JsonValue, headers?: Record<string, string>) => void;
|
|
519
|
+
/**
|
|
520
|
+
* Set by `send` once a response has been issued. The middleware checks this
|
|
521
|
+
* after `await`ing the server function to avoid double-responding.
|
|
522
|
+
*/
|
|
523
|
+
sent?: {
|
|
524
|
+
status: number;
|
|
525
|
+
body: JsonValue;
|
|
526
|
+
headers?: Record<string, string>;
|
|
527
|
+
};
|
|
528
|
+
/**
|
|
529
|
+
* The matched RPC function name for the current request, when available.
|
|
530
|
+
* Useful for per-function rate limiting or auditing inside middleware.
|
|
531
|
+
*/
|
|
532
|
+
functionName?: string;
|
|
296
533
|
/** Per-request app data shared across the async tree of the dispatch */
|
|
297
534
|
locals: Record<string, unknown>;
|
|
298
535
|
[prop: string]: unknown;
|
|
@@ -320,19 +557,57 @@ declare const getRequestContext: () => RequestEvent;
|
|
|
320
557
|
* @throws When called outside of a request
|
|
321
558
|
*/
|
|
322
559
|
declare const redirect: (location: string, status?: number) => void;
|
|
560
|
+
/**
|
|
561
|
+
* Sends a raw JSON response for the current request, bypassing the standard
|
|
562
|
+
* `{ data }` shape. Reads the adapter-bound `send` from the current request
|
|
563
|
+
* context — callable from anywhere inside a server-function tree. Any code in
|
|
564
|
+
* the async tree of a dispatch can call this (e.g. custom middleware) to
|
|
565
|
+
* short-circuit with a specific status code (401, 413, 429, ...).
|
|
566
|
+
* @param status - HTTP status code
|
|
567
|
+
* @param body - JSON-serializable response body
|
|
568
|
+
* @param headers - Optional response headers
|
|
569
|
+
* @throws When called outside of a request
|
|
570
|
+
*/
|
|
571
|
+
declare const sendResponse: (status: number, body: JsonValue, headers?: Record<string, string>) => void;
|
|
572
|
+
/**
|
|
573
|
+
* Normalized, adapter-agnostic view of the current request. Reads the request
|
|
574
|
+
* object off the current request context and normalizes it across the five
|
|
575
|
+
* adapter request shapes (Express `req`, Fastify `req`, Koa `ctx.req`,
|
|
576
|
+
* Hono `c.req`, h3 `event.req`) so middleware can be written once.
|
|
577
|
+
*/
|
|
578
|
+
interface RequestMeta {
|
|
579
|
+
/** HTTP method, upper-cased (e.g. "GET", "POST") */
|
|
580
|
+
method: string;
|
|
581
|
+
/** URL pathname (e.g. "/__rpc/greet") */
|
|
582
|
+
pathname: string;
|
|
583
|
+
/** Raw search string including the leading "?", or "" when absent */
|
|
584
|
+
search: string;
|
|
585
|
+
/** Parsed search params */
|
|
586
|
+
searchParams: URLSearchParams;
|
|
587
|
+
/** Request headers, lower-cased */
|
|
588
|
+
headers: Record<string, string | string[] | undefined>;
|
|
589
|
+
/** Host header value (e.g. "localhost:5173"), when present */
|
|
590
|
+
host?: string;
|
|
591
|
+
/** Client IP when the framework exposes it (e.g. Fastify `req.ip`) */
|
|
592
|
+
ip?: string;
|
|
593
|
+
/** Request protocol ("http" or "https"), when determinable */
|
|
594
|
+
protocol?: string;
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Reads normalized, adapter-agnostic request metadata from the current request
|
|
598
|
+
* context. Works with Express `req`, Fastify `req`, Koa `ctx.req`,
|
|
599
|
+
* Hono `c.req` and h3 `event.req` by feature-detecting the request shape
|
|
600
|
+
* (`originalUrl`/`url`/`path`, raw `headers` map vs `Headers`-like API).
|
|
601
|
+
* @param event - The request context to read, typically the result of
|
|
602
|
+
* {@link getRequestContext}
|
|
603
|
+
*/
|
|
604
|
+
declare const getRequestMeta: (event: RequestEvent) => RequestMeta;
|
|
323
605
|
//#endregion
|
|
324
606
|
//#region src/options.d.ts
|
|
325
|
-
declare const defaultServerFnOptions:
|
|
326
|
-
|
|
327
|
-
credentials: "same-origin";
|
|
328
|
-
method: "POST";
|
|
329
|
-
};
|
|
607
|
+
declare const defaultServerFnOptions: ServerFunctionOptions;
|
|
608
|
+
declare const defaultPrefix = "__rpc";
|
|
330
609
|
declare const defaultRPCOptions: RpcPluginOptions;
|
|
331
|
-
declare const defaultMiddlewareOptions:
|
|
332
|
-
rpcPrefix: undefined;
|
|
333
|
-
path: undefined;
|
|
334
|
-
origin: undefined;
|
|
335
|
-
};
|
|
610
|
+
declare const defaultMiddlewareOptions: MiddlewareOptions;
|
|
336
611
|
//#endregion
|
|
337
|
-
export { RPCError, RequestEvent, createServerFunction, defaultMiddlewareOptions, defaultRPCOptions, defaultServerFnOptions, escapeRegExp, formatError, getClientModules, getRequestContext, hasContentTypeMismatch, isFormContentType, provideRequestContext, redirect, scanForServerFiles, scannedServerFiles, serverFunctionsMap, walkGlobFiles };
|
|
612
|
+
export { CreateServerFunctionOptions, RPCError, RequestEvent, RequestMeta, createServerFunction, defaultMiddlewareOptions, defaultPrefix, defaultRPCOptions, defaultServerFnOptions, escapeRegExp, formatError, getClientModules, getFunctionsForPrefix, getGlobalPrefix, getRequestContext, getRequestMeta, hasContentTypeMismatch, isFormContentType, provideRequestContext, redirect, safeURL, scanForServerFiles, scannedServerFiles, sendResponse, serverFunctionsByPrefix, serverFunctionsMap, setGlobalPrefix, walkGlobFiles };
|
|
338
613
|
//# sourceMappingURL=server.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.mts","names":[],"sources":["../../src/types.d.ts","../../src/functionsMap.ts","../../src/scanForServerFiles.ts","../../src/createFunction.ts","../../src/getClientModules.ts","../../src/server-helpers.ts","../../src/context.ts","../../src/options.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.d.mts","names":[],"sources":["../../src/express/types.d.ts","../../src/hono/types.d.ts","../../src/fastify/types.d.ts","../../src/koa/types.d.ts","../../src/h3/types.d.ts","../../src/types.d.ts","../../src/functionsMap.ts","../../src/scanForServerFiles.ts","../../src/createFunction.ts","../../src/getClientModules.ts","../../src/server-helpers.ts","../../src/context.ts","../../src/options.ts"],"mappings":";;;;;;;;;;;;;;;;UA+BiB;;;;;;;EAOf,UACE,KAAK,kBAAkB,SACvB,KAAK,iBAAiB,YACtB,MAAM,QAAQ,eAAe,iBAC1B;;;;;;;UCzBU;;EAEf,SAAS;;;;;;;UCmCM;;;;;;;EAOf,UACE,KAAK,gBACL,KAAK,cACL,MAAM,4BACH;;;;;;;UCzCU;;;;;;EAMf,UAAU,KAAK,SAAS,MAAM,SAAS;;;;;;;UClBxB;;;;;;EAM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