@fresho/router 0.3.2 → 0.5.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/README.md +65 -4
- package/dist/index.d.mts +102 -22
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +77 -15
- package/dist/index.mjs.map +1 -1
- package/dist/middleware/index.d.mts +50 -1
- package/dist/middleware/index.d.mts.map +1 -1
- package/dist/middleware/index.mjs +82 -1
- package/dist/middleware/index.mjs.map +1 -1
- package/dist/middleware-Bxq0LHLS.d.mts.map +1 -1
- package/docs/middleware.md +43 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ export default { fetch: api.handler() };
|
|
|
39
39
|
|
|
40
40
|
## Features
|
|
41
41
|
|
|
42
|
-
- **Type-safe path params** — `$id` creates dynamic segments
|
|
42
|
+
- **Type-safe path params** — `$id` creates dynamic segments whose names are inferred by handlers and clients
|
|
43
43
|
- **Schema validation** — query and body validated at runtime, typed at compile time
|
|
44
44
|
- **Property-based routing** — property names become URL segments
|
|
45
45
|
- **Typed HTTP client** — call your API with full type safety
|
|
@@ -210,7 +210,7 @@ const api = router(
|
|
|
210
210
|
);
|
|
211
211
|
```
|
|
212
212
|
|
|
213
|
-
Built-in middleware: `cors`, `errorHandler`, `logger`, `rateLimit`, `requestId`, `timeout`, `basicAuth`, `bearerAuth`, `jwtAuth`, `contentType`.
|
|
213
|
+
Built-in middleware: `cors`, `errorHandler`, `logger`, `rateLimit`, `requestId`, `timeout`, `basicAuth`, `bearerAuth`, `jwtAuth`, `contentType`, `cookies`.
|
|
214
214
|
|
|
215
215
|
See **[Middleware Documentation](docs/middleware.md)** for detailed usage.
|
|
216
216
|
|
|
@@ -278,6 +278,26 @@ await client.users.$get(); // GET /users
|
|
|
278
278
|
await client.users.$post({ body: { name: "Bob" } }); // POST /users
|
|
279
279
|
```
|
|
280
280
|
|
|
281
|
+
The `$id` segment determines the `id` key in the client's `path` option, so missing or misspelled
|
|
282
|
+
parameter names are caught at compile time.
|
|
283
|
+
|
|
284
|
+
### Routers Built by a Factory
|
|
285
|
+
|
|
286
|
+
If your router is created inside a factory so its handlers can close over injected dependencies,
|
|
287
|
+
derive the API type from the factory's return type. The type-only import keeps server code out of the
|
|
288
|
+
client bundle:
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
import { createHttpClient } from "@fresho/router";
|
|
292
|
+
import type { createServer } from "./server";
|
|
293
|
+
|
|
294
|
+
type Api = ReturnType<typeof createServer>["api"];
|
|
295
|
+
|
|
296
|
+
const client = createHttpClient<Api>({
|
|
297
|
+
baseUrl: "https://api.example.com",
|
|
298
|
+
});
|
|
299
|
+
```
|
|
300
|
+
|
|
281
301
|
### HTTP Method Syntax
|
|
282
302
|
|
|
283
303
|
HTTP methods are prefixed with `$` to distinguish them from path navigation:
|
|
@@ -295,6 +315,27 @@ client.api.get.$get(); // GET /api/get (navigate to "get", then execute GET)
|
|
|
295
315
|
|
|
296
316
|
This allows routes with path segments named after HTTP methods (e.g., `/api/get`, `/resources/delete`).
|
|
297
317
|
|
|
318
|
+
### Building URLs Without Fetching
|
|
319
|
+
|
|
320
|
+
Use `$url` to derive a URL string from the typed routes without firing a request. It accepts the
|
|
321
|
+
same `path`/`query` options as a real call, including the parameter names inferred from `$id`
|
|
322
|
+
segments:
|
|
323
|
+
|
|
324
|
+
```typescript
|
|
325
|
+
// Absolute URL when baseUrl is configured:
|
|
326
|
+
client.media.playlist.$url({ query: { channel: "classics", chunks: 1 } });
|
|
327
|
+
// → "https://api.example.com/media/playlist?channel=classics&chunks=1"
|
|
328
|
+
|
|
329
|
+
client.users.$id.$url({ path: { id: "123" } });
|
|
330
|
+
// → "https://api.example.com/users/123"
|
|
331
|
+
|
|
332
|
+
// Relative URL (pathname + search) when no baseUrl is set:
|
|
333
|
+
createHttpClient<typeof api>({}).users.$id.$url({ path: { id: "123" } });
|
|
334
|
+
// → "/users/123"
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
This keeps route paths as the single source of truth for URLs embedded in response bodies, deep links, or server-side URL generation — cases where `raw: true` can't help, since `Response.url` only exists after a request runs.
|
|
338
|
+
|
|
298
339
|
## Local Client
|
|
299
340
|
|
|
300
341
|
Test handlers directly without HTTP overhead:
|
|
@@ -336,16 +377,36 @@ const docs = router({
|
|
|
336
377
|
```typescript
|
|
337
378
|
import { sseResponse } from "@fresho/router";
|
|
338
379
|
|
|
380
|
+
export interface ItemEvents {
|
|
381
|
+
message: { connected: boolean };
|
|
382
|
+
update: { count: number };
|
|
383
|
+
removed: { id: string };
|
|
384
|
+
}
|
|
385
|
+
|
|
339
386
|
events: router({
|
|
340
387
|
get: async () =>
|
|
341
|
-
sseResponse(async (send, close) => {
|
|
342
|
-
send({ data:
|
|
388
|
+
sseResponse<ItemEvents>(async (send, close) => {
|
|
389
|
+
send({ data: { connected: true } });
|
|
343
390
|
send({ event: "update", data: { count: 1 } });
|
|
391
|
+
send({ event: "removed", data: { id: "item-1" } });
|
|
344
392
|
close();
|
|
345
393
|
}),
|
|
346
394
|
});
|
|
347
395
|
```
|
|
348
396
|
|
|
397
|
+
The event map checks event names and their corresponding payloads. The reserved `message` key types
|
|
398
|
+
events that omit the `event` field. Export the map for consumers, or extract it from a typed client
|
|
399
|
+
method:
|
|
400
|
+
|
|
401
|
+
```typescript
|
|
402
|
+
import type { SSEEventsOf } from "@fresho/router";
|
|
403
|
+
|
|
404
|
+
type ClientEvents = SSEEventsOf<ReturnType<typeof client.events>>;
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
HTTP and local clients return streaming routes as raw `Response` objects instead of parsing their
|
|
408
|
+
bodies as JSON, so callers can consume `response.body` as data arrives.
|
|
409
|
+
|
|
349
410
|
### JSON Lines
|
|
350
411
|
|
|
351
412
|
```typescript
|
package/dist/index.d.mts
CHANGED
|
@@ -75,7 +75,7 @@ interface CtxBuilder<Ctx> {
|
|
|
75
75
|
* export default { fetch: api.handler() };
|
|
76
76
|
* ```
|
|
77
77
|
*/
|
|
78
|
-
declare function router<T extends RouterRoutes, M
|
|
78
|
+
declare function router<T extends RouterRoutes, M extends Middleware<any>[]>(routes: T, ...middleware: M): Router<T>;
|
|
79
79
|
//#endregion
|
|
80
80
|
//#region src/docs.d.ts
|
|
81
81
|
/** Generates OpenAPI documentation from a router. */
|
|
@@ -92,7 +92,7 @@ type LowercaseMethods = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
|
92
92
|
/** Map lowercase method to $-prefixed version. */
|
|
93
93
|
type PrefixedMethod<T extends LowercaseMethods> = T extends 'get' ? '$get' : T extends 'post' ? '$post' : T extends 'put' ? '$put' : T extends 'patch' ? '$patch' : T extends 'delete' ? '$delete' : never;
|
|
94
94
|
/** Extract return type from a handler. */
|
|
95
|
-
type ExtractReturn<T> = T extends ((...args:
|
|
95
|
+
type ExtractReturn<T> = T extends ((...args: never[]) => infer R) ? R extends Promise<infer U> ? U : R : unknown;
|
|
96
96
|
/** Detects if a type is `any`. */
|
|
97
97
|
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
98
98
|
/** Checks if a schema type should require a property. */
|
|
@@ -102,7 +102,7 @@ type SafeInferSchema<T> = IsAny<T> extends true ? {} : keyof T extends never ? {
|
|
|
102
102
|
/** Check if router tree contains any $param properties. */
|
|
103
103
|
type HasParams<Path extends string[]> = Path extends [infer Head, ...infer Rest extends string[]] ? Head extends `$${string}` ? true : HasParams<Rest> : false;
|
|
104
104
|
/** Extract the MethodEntry part from a union type. */
|
|
105
|
-
type ExtractMethod<T> =
|
|
105
|
+
type ExtractMethod<T> = T extends RouteDefinition<infer _Q, infer _B, infer _R, infer _P, infer _Ctx> ? T : T extends ((...args: never[]) => unknown) ? T : never;
|
|
106
106
|
/** Remove string/number index signatures from a type. */
|
|
107
107
|
type RemoveIndex<T> = { [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K] };
|
|
108
108
|
/** Header value that can be static or dynamic. */
|
|
@@ -116,8 +116,8 @@ interface BaseRequestOptions {
|
|
|
116
116
|
/** Full request options including client-specific extras. */
|
|
117
117
|
type RequestOptions<Extra> = BaseRequestOptions & Extra;
|
|
118
118
|
/** Build options type based on whether path params are needed. */
|
|
119
|
-
type BuildOptions<
|
|
120
|
-
path:
|
|
119
|
+
type BuildOptions<Path extends string[], Q$1, B$1, Extra> = HasParams<Path> extends true ? {
|
|
120
|
+
path: CollectPathParams<Path>;
|
|
121
121
|
} & (RequiresProperty<Q$1> extends true ? {
|
|
122
122
|
query?: Q$1;
|
|
123
123
|
} : {}) & (RequiresProperty<B$1> extends true ? {
|
|
@@ -128,19 +128,33 @@ type BuildOptions<HasPathParams extends boolean, Q$1, B$1, Extra> = HasPathParam
|
|
|
128
128
|
body: B$1;
|
|
129
129
|
} : {}) & Extra;
|
|
130
130
|
/** Client type for a method entry (route or bare function). */
|
|
131
|
-
type MethodClient<T, Extra,
|
|
131
|
+
type MethodClient<T, Extra, Path extends string[] = []> = T extends RouteDefinition<infer Q, infer B, infer R, infer _P, infer _Ctx> ? (options?: BuildOptions<Path, SafeInferSchema<Q>, SafeInferSchema<B>, Extra>) => Promise<R> : T extends ((...args: never[]) => unknown) ? (options?: BuildOptions<Path, {}, {}, Extra>) => Promise<ExtractReturn<T>> : never;
|
|
132
132
|
/** Helper to extract return type for implicit GET calls. */
|
|
133
|
-
type ImplicitGetCall<T extends RouterRoutes, Extra, Path extends string[] = []> = 'get' extends keyof T ? ExtractMethod<T['get']> extends RouteDefinition<infer _Q, infer _B, infer R,
|
|
134
|
-
path:
|
|
133
|
+
type ImplicitGetCall<T extends RouterRoutes, Extra, Path extends string[] = []> = 'get' extends keyof T ? ExtractMethod<T['get']> extends RouteDefinition<infer _Q, infer _B, infer R, infer _P, infer _Ctx> ? HasParams<Path> extends true ? (options: {
|
|
134
|
+
path: CollectPathParams<Path>;
|
|
135
135
|
} & {
|
|
136
136
|
query?: Record<string, unknown>;
|
|
137
|
-
} & Extra) => Promise<R> : (options?: RequestOptions<Extra>) => Promise<R> : ExtractMethod<T['get']> extends ((...args:
|
|
138
|
-
path:
|
|
137
|
+
} & Extra) => Promise<R> : (options?: RequestOptions<Extra>) => Promise<R> : ExtractMethod<T['get']> extends ((...args: never[]) => unknown) ? HasParams<Path> extends true ? (options: {
|
|
138
|
+
path: CollectPathParams<Path>;
|
|
139
139
|
} & {
|
|
140
140
|
query?: Record<string, unknown>;
|
|
141
141
|
} & Extra) => Promise<ExtractReturn<ExtractMethod<T['get']>>> : (options?: RequestOptions<Extra>) => Promise<ExtractReturn<ExtractMethod<T['get']>>> : (options?: RequestOptions<Extra>) => Promise<unknown> : (options?: RequestOptions<Extra>) => Promise<unknown>;
|
|
142
|
+
/**
|
|
143
|
+
* Builds a URL string from the route path without executing a request.
|
|
144
|
+
*
|
|
145
|
+
* Path params are required when the path contains `$param` segments. Query
|
|
146
|
+
* params are always optional and untyped, since `$url` is method-agnostic.
|
|
147
|
+
*/
|
|
148
|
+
type UrlMethod<Path extends string[]> = HasParams<Path> extends true ? (options: {
|
|
149
|
+
path: CollectPathParams<Path>;
|
|
150
|
+
query?: Record<string, unknown>;
|
|
151
|
+
}) => string : (options?: {
|
|
152
|
+
query?: Record<string, unknown>;
|
|
153
|
+
}) => string;
|
|
142
154
|
/** Client type for a router. */
|
|
143
|
-
type RouterClient<T extends RouterRoutes, Extra, Path extends string[] = []> = {
|
|
155
|
+
type RouterClient<T extends RouterRoutes, Extra, Path extends string[] = []> = {
|
|
156
|
+
$url: UrlMethod<Path>;
|
|
157
|
+
} & { [K in keyof RemoveIndex<T> as K extends LowercaseMethods ? PrefixedMethod<K> : never]: MethodClient<ExtractMethod<T[K]>, Extra, Path> } & { [K in keyof RemoveIndex<T>]: IsAny<T[K]> extends true ? never : Extract<T[K], Router<RouterRoutes>> extends infer R ? R extends Router<infer Routes> ? RouterClient<Routes, Extra, [...Path, K & string]> & ImplicitGetCall<Routes, Extra, [...Path, K & string]> : never : never } & ImplicitGetCall<T, Extra, Path>;
|
|
144
158
|
//#endregion
|
|
145
159
|
//#region src/http-client.d.ts
|
|
146
160
|
/** HTTP client configuration. */
|
|
@@ -197,6 +211,18 @@ type HttpClient<T extends Router<RouterRoutes>> = {
|
|
|
197
211
|
* // GET /api/get
|
|
198
212
|
* await client.api.get.$get();
|
|
199
213
|
* ```
|
|
214
|
+
*
|
|
215
|
+
* @example Router built by a dependency-injected factory:
|
|
216
|
+
* ```typescript
|
|
217
|
+
* import type { createServer } from './server';
|
|
218
|
+
* import { createHttpClient } from '@fresho/router';
|
|
219
|
+
*
|
|
220
|
+
* type Api = ReturnType<typeof createServer>['api'];
|
|
221
|
+
*
|
|
222
|
+
* const client = createHttpClient<Api>({
|
|
223
|
+
* baseUrl: 'https://api.example.com',
|
|
224
|
+
* });
|
|
225
|
+
* ```
|
|
200
226
|
*/
|
|
201
227
|
declare function createHttpClient<T extends Router<RouterRoutes>>(config?: HttpClientConfig): HttpClient<T>;
|
|
202
228
|
//#endregion
|
|
@@ -246,10 +272,14 @@ declare function createLocalClient<T extends Router<RouterRoutes>>(routerDef: T)
|
|
|
246
272
|
* ```typescript
|
|
247
273
|
* import { router, sseResponse, streamJsonLines } from '@fresho/router';
|
|
248
274
|
*
|
|
275
|
+
* interface Events {
|
|
276
|
+
* tick: { count: number };
|
|
277
|
+
* }
|
|
278
|
+
*
|
|
249
279
|
* const api = router({
|
|
250
280
|
* // SSE for real-time updates
|
|
251
281
|
* events: router({
|
|
252
|
-
* get: async () => sseResponse(async (send, close) => {
|
|
282
|
+
* get: async () => sseResponse<Events>(async (send, close) => {
|
|
253
283
|
* for (let i = 0; i < 10; i++) {
|
|
254
284
|
* send({ event: 'tick', data: { count: i } });
|
|
255
285
|
* await sleep(1000);
|
|
@@ -280,27 +310,77 @@ interface SSEOptions {
|
|
|
280
310
|
keepAliveInterval?: number;
|
|
281
311
|
}
|
|
282
312
|
/**
|
|
283
|
-
*
|
|
313
|
+
* Data supported by an SSE message.
|
|
284
314
|
*/
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
315
|
+
type SSEData = string | object;
|
|
316
|
+
/**
|
|
317
|
+
* Untyped map of SSE event names to their payloads.
|
|
318
|
+
*
|
|
319
|
+
* Define a narrower map and pass it to {@link sseResponse} to type-check event
|
|
320
|
+
* names and their corresponding data.
|
|
321
|
+
*/
|
|
322
|
+
type SSEEventMap = Record<string, SSEData>;
|
|
323
|
+
type ValidSSEEventMap<Events$1> = { [Name in keyof Events$1]: SSEData };
|
|
324
|
+
interface SSEMessageMetadata {
|
|
290
325
|
/** Event ID (optional). */
|
|
291
326
|
id?: string;
|
|
292
327
|
/** Retry interval hint for client (optional). */
|
|
293
328
|
retry?: number;
|
|
294
329
|
}
|
|
330
|
+
/**
|
|
331
|
+
* Server-Sent Event message structure without a typed event map.
|
|
332
|
+
*/
|
|
333
|
+
interface SSEMessage extends SSEMessageMetadata {
|
|
334
|
+
/** Event type (optional). */
|
|
335
|
+
event?: string;
|
|
336
|
+
/** Event data. */
|
|
337
|
+
data: SSEData;
|
|
338
|
+
}
|
|
339
|
+
type NamedSSEMessage<Events$1> = { [Name in Exclude<keyof Events$1 & string, 'message'>]: {
|
|
340
|
+
event: Name;
|
|
341
|
+
data: Events$1[Name];
|
|
342
|
+
} }[Exclude<keyof Events$1 & string, 'message'>];
|
|
343
|
+
type DefaultSSEMessage<Events$1> = 'message' extends keyof Events$1 ? {
|
|
344
|
+
/** Omit the event name to dispatch the default `message` event. */
|
|
345
|
+
event?: 'message';
|
|
346
|
+
data: Events$1['message'];
|
|
347
|
+
} : never;
|
|
348
|
+
/**
|
|
349
|
+
* Server-Sent Event message structure.
|
|
350
|
+
*
|
|
351
|
+
* For a typed event map, each event name is coupled to its payload type. Use
|
|
352
|
+
* the reserved `message` key to type messages that omit the `event` field.
|
|
353
|
+
*/
|
|
354
|
+
type SSEEventMessage<Events$1 extends ValidSSEEventMap<Events$1>> = (string extends keyof Events$1 ? SSEMessage : NamedSSEMessage<Events$1> | DefaultSSEMessage<Events$1>) & SSEMessageMetadata;
|
|
355
|
+
declare const SSE_EVENTS: unique symbol;
|
|
356
|
+
/**
|
|
357
|
+
* Response carrying its SSE event map at the type level.
|
|
358
|
+
*/
|
|
359
|
+
type SSEResponse<Events$1 extends ValidSSEEventMap<Events$1> = SSEEventMap> = Response & {
|
|
360
|
+
readonly [SSE_EVENTS]: Events$1;
|
|
361
|
+
};
|
|
362
|
+
/**
|
|
363
|
+
* Extracts the event map carried by an SSE response or typed client method.
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
* ```typescript
|
|
367
|
+
* type Events = SSEEventsOf<ReturnType<typeof client.events>>;
|
|
368
|
+
* ```
|
|
369
|
+
*/
|
|
370
|
+
type SSEEventsOf<T> = Awaited<T> extends SSEResponse<infer Events> ? Events : never;
|
|
295
371
|
/**
|
|
296
372
|
* Creates a Server-Sent Events (SSE) response.
|
|
297
373
|
*
|
|
298
374
|
* @example
|
|
299
375
|
* ```typescript
|
|
376
|
+
* interface CounterEvents {
|
|
377
|
+
* tick: { count: number };
|
|
378
|
+
* }
|
|
379
|
+
*
|
|
300
380
|
* const handler = async (c) => {
|
|
301
|
-
* return sseResponse(async (send, close) => {
|
|
381
|
+
* return sseResponse<CounterEvents>(async (send, close) => {
|
|
302
382
|
* for (let i = 0; i < 5; i++) {
|
|
303
|
-
*
|
|
383
|
+
* send({ event: 'tick', data: { count: i } });
|
|
304
384
|
* await new Promise(r => setTimeout(r, 1000));
|
|
305
385
|
* }
|
|
306
386
|
* close();
|
|
@@ -308,7 +388,7 @@ interface SSEMessage {
|
|
|
308
388
|
* };
|
|
309
389
|
* ```
|
|
310
390
|
*/
|
|
311
|
-
declare function sseResponse(handler: (send: (message:
|
|
391
|
+
declare function sseResponse<Events$1 extends ValidSSEEventMap<Events$1> = SSEEventMap>(handler: (send: (message: SSEEventMessage<Events$1>) => void, close: () => void) => void | Promise<void>, options?: SSEOptions): SSEResponse<Events$1>;
|
|
312
392
|
/**
|
|
313
393
|
* Creates a streaming JSON response where each line is a JSON object.
|
|
314
394
|
*
|
|
@@ -331,5 +411,5 @@ declare function streamJsonLines(handler: (send: (data: object) => void, close:
|
|
|
331
411
|
headers?: HeadersInit;
|
|
332
412
|
}): Response;
|
|
333
413
|
//#endregion
|
|
334
|
-
export { type CollectPathParams, type CompiledSchema, type Context, type ExecutionContext, type FetchHandler, type HttpClient, type HttpClientConfig, type HttpRequestOptions, type InferSchema, type LocalClient, type LocalClientConfig, type LocalRequestOptions, type Method, type MethodEntry, type Middleware, type MiddlewareContext, type MiddlewareNext, type RouteDefinition, type Router, type RouterBrand, type RouterRoutes, type SSEMessage, type SSEOptions, type SchemaDefinition, type SchemaType, type SchemaTypeMap, type TypedHandler, type TypedResponse, type ValidationResult, compileSchema, createHttpClient, createLocalClient, generateDocs, isFunction, isRoute, isRouter, route, router, runMiddleware, sseResponse, streamJsonLines };
|
|
414
|
+
export { type CollectPathParams, type CompiledSchema, type Context, type ExecutionContext, type FetchHandler, type HttpClient, type HttpClientConfig, type HttpRequestOptions, type InferSchema, type LocalClient, type LocalClientConfig, type LocalRequestOptions, type Method, type MethodEntry, type Middleware, type MiddlewareContext, type MiddlewareNext, type RouteDefinition, type Router, type RouterBrand, type RouterRoutes, type SSEData, type SSEEventMap, type SSEEventMessage, type SSEEventsOf, type SSEMessage, type SSEOptions, type SSEResponse, type SchemaDefinition, type SchemaType, type SchemaTypeMap, type TypedHandler, type TypedResponse, type ValidationResult, compileSchema, createHttpClient, createLocalClient, generateDocs, isFunction, isRoute, isRouter, route, router, runMiddleware, sseResponse, streamJsonLines };
|
|
335
415
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/core.ts","../src/docs.ts","../src/client-types.ts","../src/http-client.ts","../src/local-client.ts","../src/streaming.ts"],"sourcesContent":[],"mappings":";;;;;;;AEQA;AAGA;;;;;;;;AAaA;;;;;;;AAOA;AAGA;;;;;AAIA;;;;;AAKS,iBFoCO,KEpCP,CAAA,kBFqCS,gBErCT,GAAA,CAAA,CAAA,EAAA,kBFsCS,gBEtCT,GAAA,CAAA,CAAA,EAAA,MAAA,OAAA,CAAA,CAAA,UAAA,EFwCK,eExCL,CFwCqB,GExCrB,EFwCwB,GExCxB,EFwC2B,GExC3B,EAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,EFwCwC,eExCxC,CFwCwD,GExCxD,EFwC2D,GExC3D,EFwC8D,GExC9D,EAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA;AACa,kBFmCN,KAAA,CEnCM;EAAZ,IAAA,GAAA,EAAA,CAAA,GAAA,CAAA,GAAA,GFmGW,UEnGX,CFmGsB,GEnGtB,CAAA;;AAIV;UFwCU,UExCqC,CAAA,GAAA,CAAA,CAAA;EAI3C,CAAA,kBFqCe,gBErCf,GAAA,CAAA,CAAA,EAAA,kBFqCsD,gBErCtD,GAAA,CAAA,CAAA,EAAA,MAAA,OAAA,CAAA,CAAA,UAAA,EFsCY,eEtCZ,CFsC4B,GEtC5B,EFsC+B,GEtC/B,EFsCkC,GEtClC,EAAA,CAAA,CAAA,EFsCyC,GEtCzC,CAAA,CAAA,EFuCC,eEvCD,CFuCiB,GEvCjB,EFuCoB,GEvCpB,EFuCuB,GEvCvB,EAAA,CAAA,CAAA,EFuC8B,GEvC9B,CAAA;EAEY,GAAA,CAAA,aAAA,CAAA,EAAA,EFuCQ,UEvCR,CFuCmB,GEvCnB,GFuCyB,aEvCzB,CAAA;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/core.ts","../src/docs.ts","../src/client-types.ts","../src/http-client.ts","../src/local-client.ts","../src/streaming.ts"],"sourcesContent":[],"mappings":";;;;;;;AEQA;AAGA;;;;;;;;AAaA;;;;;;;AAOA;AAGA;;;;;AAIA;;;;;AAKS,iBFoCO,KEpCP,CAAA,kBFqCS,gBErCT,GAAA,CAAA,CA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CAAA,EAAA,OAAA,CAAA,EGgFO,UHhFP,CAAA,EGiFD,WHjFC,CGiFW,QHjFX,CAAA;;;;;;;;AAKJ;;;;;;;;;;;AAgBc,iBGqIE,eAAA,CHrIF,OAAA,EAAA,CAAA,IAAA,EAAA,CAAA,IAAA,EAAA,MAAA,EAAA,GAAA,IAAA,EAAA,KAAA,EAAA,GAAA,GAAA,IAAA,EAAA,GAAA,IAAA,GGsIyD,OHtIzD,CAAA,IAAA,CAAA,EAAA,OACD,CADC,EAAA;EACO,OAAA,CAAA,EGsIE,WHtIF;CAAR,CAAA,EGuIV,QHvIU"}
|
package/dist/index.mjs
CHANGED
|
@@ -706,6 +706,7 @@ function createRecursiveProxy(config, segments = []) {
|
|
|
706
706
|
get(_target, prop) {
|
|
707
707
|
if (typeof prop !== "string") return void 0;
|
|
708
708
|
if (prop === "apply" || prop === "call" || prop === "bind" || prop === "toString" || prop === "toJSON") return _target[prop];
|
|
709
|
+
if (prop === "$url" && config.onBuildUrl) return (options) => config.onBuildUrl(segments, options);
|
|
709
710
|
if (PREFIXED_HTTP_METHODS.has(prop)) {
|
|
710
711
|
const method = prop.slice(1);
|
|
711
712
|
return (options) => {
|
|
@@ -720,6 +721,22 @@ function createRecursiveProxy(config, segments = []) {
|
|
|
720
721
|
});
|
|
721
722
|
}
|
|
722
723
|
|
|
724
|
+
//#endregion
|
|
725
|
+
//#region src/client-response.ts
|
|
726
|
+
const STREAMING_CONTENT_TYPES = new Set([
|
|
727
|
+
"text/event-stream",
|
|
728
|
+
"application/x-ndjson",
|
|
729
|
+
"application/ndjson"
|
|
730
|
+
]);
|
|
731
|
+
/**
|
|
732
|
+
* Parses ordinary client responses as JSON while preserving streaming bodies.
|
|
733
|
+
*/
|
|
734
|
+
async function parseClientResponse(response, raw = false) {
|
|
735
|
+
const contentType = response.headers.get("Content-Type")?.split(";", 1)[0].trim().toLowerCase();
|
|
736
|
+
if (raw || contentType && STREAMING_CONTENT_TYPES.has(contentType)) return response;
|
|
737
|
+
return response.json();
|
|
738
|
+
}
|
|
739
|
+
|
|
723
740
|
//#endregion
|
|
724
741
|
//#region src/http-client.ts
|
|
725
742
|
/**
|
|
@@ -795,15 +812,30 @@ const BODY_METHODS = new Set([
|
|
|
795
812
|
* // GET /api/get
|
|
796
813
|
* await client.api.get.$get();
|
|
797
814
|
* ```
|
|
815
|
+
*
|
|
816
|
+
* @example Router built by a dependency-injected factory:
|
|
817
|
+
* ```typescript
|
|
818
|
+
* import type { createServer } from './server';
|
|
819
|
+
* import { createHttpClient } from '@fresho/router';
|
|
820
|
+
*
|
|
821
|
+
* type Api = ReturnType<typeof createServer>['api'];
|
|
822
|
+
*
|
|
823
|
+
* const client = createHttpClient<Api>({
|
|
824
|
+
* baseUrl: 'https://api.example.com',
|
|
825
|
+
* });
|
|
826
|
+
* ```
|
|
798
827
|
*/
|
|
799
828
|
function createHttpClient(config = {}) {
|
|
800
829
|
const sharedConfig = { current: { ...config } };
|
|
801
830
|
const client = { configure(newConfig) {
|
|
802
831
|
Object.assign(sharedConfig.current, newConfig);
|
|
803
832
|
} };
|
|
804
|
-
const proxy = createRecursiveProxy({
|
|
805
|
-
|
|
806
|
-
|
|
833
|
+
const proxy = createRecursiveProxy({
|
|
834
|
+
onRequest: (segments, method, options) => {
|
|
835
|
+
return executeRequest(sharedConfig, segments, method, options);
|
|
836
|
+
},
|
|
837
|
+
onBuildUrl: (segments, options) => buildUrl(sharedConfig.current, segments, options)
|
|
838
|
+
});
|
|
807
839
|
return new Proxy(client, {
|
|
808
840
|
get(target, prop) {
|
|
809
841
|
if (prop === "configure") return target.configure;
|
|
@@ -825,15 +857,24 @@ function buildPath(segments, pathParams) {
|
|
|
825
857
|
} else parts.push(segment);
|
|
826
858
|
return `/${parts.join("/")}`;
|
|
827
859
|
}
|
|
828
|
-
/**
|
|
829
|
-
|
|
830
|
-
|
|
860
|
+
/**
|
|
861
|
+
* Builds a URL string from path segments and options without executing a request.
|
|
862
|
+
*
|
|
863
|
+
* Returns an absolute URL when a `baseUrl` is configured, otherwise a relative
|
|
864
|
+
* `pathname + search` string suitable for same-origin fetches.
|
|
865
|
+
*/
|
|
866
|
+
function buildUrl(config, segments, options) {
|
|
831
867
|
const path = buildPath(segments, options?.path);
|
|
832
868
|
const baseUrl = config.baseUrl || (typeof window !== "undefined" ? window.location?.origin : "");
|
|
833
869
|
const url = new URL(path, baseUrl || "http://localhost");
|
|
834
870
|
if (options?.query) {
|
|
835
871
|
for (const [key, value] of Object.entries(options.query)) if (value !== void 0) url.searchParams.set(key, String(value));
|
|
836
872
|
}
|
|
873
|
+
return config.baseUrl ? url.toString() : url.pathname + url.search;
|
|
874
|
+
}
|
|
875
|
+
/** Executes an HTTP request. */
|
|
876
|
+
async function executeRequest(sharedConfig, segments, method, options) {
|
|
877
|
+
const config = sharedConfig.current;
|
|
837
878
|
const headers = new Headers();
|
|
838
879
|
if (config.headers) for (const [key, value] of Object.entries(config.headers)) {
|
|
839
880
|
const resolved = typeof value === "function" ? await value() : value;
|
|
@@ -849,11 +890,10 @@ async function executeRequest(sharedConfig, segments, method, options) {
|
|
|
849
890
|
headers.set("Content-Type", "application/json");
|
|
850
891
|
init.body = JSON.stringify(options.body);
|
|
851
892
|
}
|
|
852
|
-
const fetchUrl = config
|
|
893
|
+
const fetchUrl = buildUrl(config, segments, options);
|
|
853
894
|
const response = await (config.fetch || fetch)(fetchUrl, init);
|
|
854
895
|
if (!response.ok) throw new Error(await response.text() || response.statusText);
|
|
855
|
-
|
|
856
|
-
return response.json();
|
|
896
|
+
return parseClientResponse(response, options?.raw);
|
|
857
897
|
}
|
|
858
898
|
|
|
859
899
|
//#endregion
|
|
@@ -938,9 +978,12 @@ function createLocalClient(routerDef) {
|
|
|
938
978
|
const client = { configure(config) {
|
|
939
979
|
Object.assign(sharedConfig.current, config);
|
|
940
980
|
} };
|
|
941
|
-
const proxy = createRecursiveProxy({
|
|
942
|
-
|
|
943
|
-
|
|
981
|
+
const proxy = createRecursiveProxy({
|
|
982
|
+
onRequest: (segments, method, options) => {
|
|
983
|
+
return invokeHandler(sharedConfig, routerDef, segments, method, options);
|
|
984
|
+
},
|
|
985
|
+
onBuildUrl: (segments, options) => buildLocalUrl(segments, options)
|
|
986
|
+
});
|
|
944
987
|
return new Proxy(client, {
|
|
945
988
|
get(target, prop) {
|
|
946
989
|
if (prop === "configure") return target.configure;
|
|
@@ -951,6 +994,21 @@ function createLocalClient(routerDef) {
|
|
|
951
994
|
}
|
|
952
995
|
});
|
|
953
996
|
}
|
|
997
|
+
/**
|
|
998
|
+
* Builds a relative URL string from path segments and options.
|
|
999
|
+
*
|
|
1000
|
+
* The local client has no baseUrl, so it returns a relative `pathname + search`
|
|
1001
|
+
* string. Mirrors the synthetic URL construction used in {@link invokeHandler}.
|
|
1002
|
+
*/
|
|
1003
|
+
function buildLocalUrl(segments, options) {
|
|
1004
|
+
const pathParams = collectPathParams(segments, options?.path);
|
|
1005
|
+
const pathParts = segments.map((s) => s.startsWith("$") ? encodeURIComponent(pathParams[s.slice(1)]) : s);
|
|
1006
|
+
const url = new URL(`/${pathParts.join("/")}`, "http://localhost");
|
|
1007
|
+
if (options?.query) {
|
|
1008
|
+
for (const [key, value] of Object.entries(options.query)) if (value !== void 0) url.searchParams.set(key, String(value));
|
|
1009
|
+
}
|
|
1010
|
+
return url.pathname + url.search;
|
|
1011
|
+
}
|
|
954
1012
|
/** Invokes a handler directly. */
|
|
955
1013
|
async function invokeHandler(sharedConfig, routerDef, segments, method, options) {
|
|
956
1014
|
const config = sharedConfig.current;
|
|
@@ -992,7 +1050,7 @@ async function invokeHandler(sharedConfig, routerDef, segments, method, options)
|
|
|
992
1050
|
executionCtx: options?.ctx ?? config.ctx
|
|
993
1051
|
};
|
|
994
1052
|
const result = await routeInfo.handler(context);
|
|
995
|
-
if (result instanceof Response) return result
|
|
1053
|
+
if (result instanceof Response) return parseClientResponse(result);
|
|
996
1054
|
return result;
|
|
997
1055
|
}
|
|
998
1056
|
|
|
@@ -1015,10 +1073,14 @@ function formatSSEMessage(message) {
|
|
|
1015
1073
|
*
|
|
1016
1074
|
* @example
|
|
1017
1075
|
* ```typescript
|
|
1076
|
+
* interface CounterEvents {
|
|
1077
|
+
* tick: { count: number };
|
|
1078
|
+
* }
|
|
1079
|
+
*
|
|
1018
1080
|
* const handler = async (c) => {
|
|
1019
|
-
* return sseResponse(async (send, close) => {
|
|
1081
|
+
* return sseResponse<CounterEvents>(async (send, close) => {
|
|
1020
1082
|
* for (let i = 0; i < 5; i++) {
|
|
1021
|
-
*
|
|
1083
|
+
* send({ event: 'tick', data: { count: i } });
|
|
1022
1084
|
* await new Promise(r => setTimeout(r, 1000));
|
|
1023
1085
|
* }
|
|
1024
1086
|
* close();
|