fets 0.4.8 → 0.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fets",
3
- "version": "0.4.8",
3
+ "version": "0.4.9",
4
4
  "description": "TypeScript HTTP Framework focusing on e2e type-safety, easy setup, performance & great developer experience",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
@@ -1,7 +1,7 @@
1
1
  import type { B, Call, Fn, Objects, Pipe, Strings, Tuples } from 'hotscript';
2
2
  import { type O } from 'ts-toolbelt';
3
3
  import { HTTPMethod, NotOkStatusCode, OkStatusCode, StatusCode, TypedResponse } from '../typed-fetch.cjs';
4
- import type { FromSchema, JSONSchema, OpenAPIDocument, Simplify } from '../types.cjs';
4
+ import type { ExtractPathParamsWithBrackets, ExtractPathParamsWithPattern, FromSchema, JSONSchema, OpenAPIDocument, Simplify } from '../types.cjs';
5
5
  import type { OASOAuthPath, OAuth2AuthParams } from './auth/oauth.cjs';
6
6
  type JSONSchema7TypeName = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null';
7
7
  type Mutable<Type> = FixJSONSchema<{
@@ -325,18 +325,6 @@ export interface ClientOnResponseHookPayload {
325
325
  requestInit: RequestInit;
326
326
  response: Response;
327
327
  }
328
- export type ExtractPathParamsWithBrackets<TPath extends string> = Pipe<TPath, [
329
- Strings.Split<'/' | ';'>,
330
- Tuples.Filter<Strings.StartsWith<'{'>>,
331
- Tuples.Map<Strings.Trim<'{' | '}'>>,
332
- Tuples.ToUnion
333
- ]>;
334
- export type ExtractPathParamsWithPattern<TPath extends string> = Pipe<TPath, [
335
- Strings.Split<'/'>,
336
- Tuples.Filter<Strings.StartsWith<':'>>,
337
- Tuples.Map<Strings.Trim<':'>>,
338
- Tuples.ToUnion
339
- ]>;
340
328
  export type BasicAuthParams<TSecurityScheme> = TSecurityScheme extends {
341
329
  type: 'http';
342
330
  scheme: 'basic';
@@ -1,7 +1,7 @@
1
1
  import type { B, Call, Fn, Objects, Pipe, Strings, Tuples } from 'hotscript';
2
2
  import { type O } from 'ts-toolbelt';
3
3
  import { HTTPMethod, NotOkStatusCode, OkStatusCode, StatusCode, TypedResponse } from '../typed-fetch.js';
4
- import type { FromSchema, JSONSchema, OpenAPIDocument, Simplify } from '../types.js';
4
+ import type { ExtractPathParamsWithBrackets, ExtractPathParamsWithPattern, FromSchema, JSONSchema, OpenAPIDocument, Simplify } from '../types.js';
5
5
  import type { OASOAuthPath, OAuth2AuthParams } from './auth/oauth.js';
6
6
  type JSONSchema7TypeName = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null';
7
7
  type Mutable<Type> = FixJSONSchema<{
@@ -325,18 +325,6 @@ export interface ClientOnResponseHookPayload {
325
325
  requestInit: RequestInit;
326
326
  response: Response;
327
327
  }
328
- export type ExtractPathParamsWithBrackets<TPath extends string> = Pipe<TPath, [
329
- Strings.Split<'/' | ';'>,
330
- Tuples.Filter<Strings.StartsWith<'{'>>,
331
- Tuples.Map<Strings.Trim<'{' | '}'>>,
332
- Tuples.ToUnion
333
- ]>;
334
- export type ExtractPathParamsWithPattern<TPath extends string> = Pipe<TPath, [
335
- Strings.Split<'/'>,
336
- Tuples.Filter<Strings.StartsWith<':'>>,
337
- Tuples.Map<Strings.Trim<':'>>,
338
- Tuples.ToUnion
339
- ]>;
340
328
  export type BasicAuthParams<TSecurityScheme> = TSecurityScheme extends {
341
329
  type: 'http';
342
330
  scheme: 'basic';
@@ -1,9 +1,10 @@
1
- import { FromSchema as FromSchemaOriginal, JSONSchema as JSONSchemaOrBoolean } from 'json-schema-to-ts';
2
- import { ServerAdapter, ServerAdapterOptions, ServerAdapterPlugin, ServerAdapterRequestHandler } from '@whatwg-node/server';
3
- import { SwaggerUIOpts } from './plugins/openapi.cjs';
4
- import { LazySerializedResponse } from './Response.cjs';
1
+ import type { Pipe, Strings, Tuples } from 'hotscript';
2
+ import type { FromSchema as FromSchemaOriginal, JSONSchema as JSONSchemaOrBoolean } from 'json-schema-to-ts';
3
+ import type { ServerAdapter, ServerAdapterOptions, ServerAdapterPlugin, ServerAdapterRequestHandler } from '@whatwg-node/server';
4
+ import type { SwaggerUIOpts } from './plugins/openapi.cjs';
5
+ import type { LazySerializedResponse } from './Response.cjs';
5
6
  import type { HTTPMethod, StatusCode, TypedRequest, TypedResponse, TypedResponseWithJSONStatusMap } from './typed-fetch.cjs';
6
- import { AddRouteWithZodSchemasOpts, RouteZodSchemas, TypedRequestFromRouteZodSchemas, TypedResponseFromRouteZodSchemas } from './zod/types.cjs';
7
+ import type { AddRouteWithZodSchemasOpts, RouteZodSchemas, TypedRequestFromRouteZodSchemas, TypedResponseFromRouteZodSchemas } from './zod/types.cjs';
7
8
  export { TypedRequest as RouterRequest };
8
9
  export type Simplify<T> = {
9
10
  [KeyType in keyof T]: Simplify<T[KeyType]>;
@@ -101,7 +102,7 @@ export type PromiseOrValue<T> = T | Promise<T>;
101
102
  export type StatusCodeMap<T> = {
102
103
  [TKey in StatusCode]?: T;
103
104
  };
104
- export type TypedRouterHandlerTypeConfig<TRequestJSON = any, TRequestFormData extends Record<string, FormDataEntryValue> = Record<string, FormDataEntryValue>, TRequestHeaders extends Record<string, string> = Record<string, string>, TRequestQueryParams extends Record<string, string | string[]> = Record<string, string | string[]>, TRequestPathParams extends Record<string, any> = Record<string, any>, TResponseJSONStatusMap extends StatusCodeMap<any> = StatusCodeMap<any>> = {
105
+ export type TypedRouterHandlerTypeConfig<TPath extends string, TRequestJSON = any, TRequestFormData extends Record<string, FormDataEntryValue> = Record<string, FormDataEntryValue>, TRequestHeaders extends Record<string, string> = Record<string, string>, TRequestQueryParams extends Record<string, string | string[]> = Record<string, string | string[]>, TRequestPathParams extends Record<string, any> = Record<ExtractPathParamsWithPattern<TPath>, string>, TResponseJSONStatusMap extends StatusCodeMap<any> = StatusCodeMap<any>> = {
105
106
  request: {
106
107
  json?: TRequestJSON;
107
108
  formData?: TRequestFormData;
@@ -111,18 +112,18 @@ export type TypedRouterHandlerTypeConfig<TRequestJSON = any, TRequestFormData ex
111
112
  };
112
113
  responses?: TResponseJSONStatusMap;
113
114
  };
114
- export type TypedRequestFromTypeConfig<TMethod extends HTTPMethod, TTypeConfig extends TypedRouterHandlerTypeConfig> = TTypeConfig extends {
115
- request: Required<TypedRouterHandlerTypeConfig>['request'];
116
- } ? TTypeConfig extends TypedRouterHandlerTypeConfig<infer TRequestJSON, infer TRequestFormData, infer TRequestHeaders, infer TRequestQueryParams, infer TRequestPathParams> ? TypedRequest<TRequestJSON, TRequestFormData, TRequestHeaders, TMethod, TRequestQueryParams, TRequestPathParams> : never : TypedRequest;
117
- export type TypedResponseFromTypeConfig<TTypeConfig extends TypedRouterHandlerTypeConfig> = TTypeConfig extends {
115
+ export type TypedRequestFromTypeConfig<TMethod extends HTTPMethod, TPath extends string, TTypeConfig extends TypedRouterHandlerTypeConfig<TPath>> = TTypeConfig extends {
116
+ request: Required<TypedRouterHandlerTypeConfig<TPath>>['request'];
117
+ } ? TTypeConfig extends TypedRouterHandlerTypeConfig<TPath, infer TRequestJSON, infer TRequestFormData, infer TRequestHeaders, infer TRequestQueryParams, infer TRequestPathParams> ? TypedRequest<TRequestJSON, TRequestFormData, TRequestHeaders, TMethod, TRequestQueryParams, TRequestPathParams> : never : TypedRequest<any, Record<string, FormDataEntryValue>, Record<string, string>, TMethod, Record<string, string | string[]>, Record<ExtractPathParamsWithPattern<TPath>, string>>;
118
+ export type TypedResponseFromTypeConfig<TTypeConfig extends TypedRouterHandlerTypeConfig<string>> = TTypeConfig extends {
118
119
  responses: infer TResponses;
119
120
  } ? TResponses extends StatusCodeMap<any> ? TypedResponseWithJSONStatusMap<TResponses> : never : TypedResponse;
120
121
  export interface RouterBaseObject<TServerContext, TComponents extends RouterComponentsBase, TRouterSDK extends RouterSDK<string, TypedRequest, TypedResponse>> {
121
122
  openAPIDocument: OpenAPIDocument;
122
123
  handle: ServerAdapterRequestHandler<TServerContext>;
123
- route<TRouteSchemas extends RouteSchemas, TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequestFromRouteSchemas<TComponents, TRouteSchemas, TMethod>, TTypedResponse extends TypedResponseFromRouteSchemas<TComponents, TRouteSchemas>>(opts: AddRouteWithSchemasOpts<TServerContext, TComponents, TRouteSchemas, TMethod, TPath, TTypedRequest, TTypedResponse>): Router<TServerContext, TComponents, TRouterSDK & RouterSDK<TPath, TTypedRequest, TTypedResponse>>;
124
+ route<TRouteSchemas extends RouteSchemas, TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequestFromRouteSchemas<TComponents, TRouteSchemas, TMethod, TPath>, TTypedResponse extends TypedResponseFromRouteSchemas<TComponents, TRouteSchemas>>(opts: AddRouteWithSchemasOpts<TServerContext, TComponents, TRouteSchemas, TMethod, TPath, TTypedRequest, TTypedResponse>): Router<TServerContext, TComponents, TRouterSDK & RouterSDK<TPath, TTypedRequest, TTypedResponse>>;
124
125
  route<TRouteZodSchemas extends RouteZodSchemas, TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequestFromRouteZodSchemas<TRouteZodSchemas, TMethod>, TTypedResponse extends TypedResponseFromRouteZodSchemas<TRouteZodSchemas>>(opts: AddRouteWithZodSchemasOpts<TServerContext, TRouteZodSchemas, TMethod, TPath, TTypedRequest, TTypedResponse>): Router<TServerContext, TComponents, TRouterSDK & RouterSDK<TPath, TTypedRequest, TTypedResponse>>;
125
- route<TTypeConfig extends TypedRouterHandlerTypeConfig, TMethod extends HTTPMethod = HTTPMethod, TTypedRequest extends TypedRequestFromTypeConfig<TMethod, TTypeConfig> = TypedRequestFromTypeConfig<TMethod, TTypeConfig>, TTypedResponse extends TypedResponseFromTypeConfig<TTypeConfig> = TypedResponseFromTypeConfig<TTypeConfig>, TPath extends string = string>(opts: AddRouteWithTypesOpts<TServerContext, TMethod, TPath, TTypedRequest, TTypedResponse>): Router<TServerContext, TComponents, TRouterSDK & RouterSDK<TPath, TTypedRequest, TTypedResponse>>;
126
+ route<TTypeConfig extends TypedRouterHandlerTypeConfig<TPath>, TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequestFromTypeConfig<TMethod, TPath, TTypeConfig> = TypedRequestFromTypeConfig<TMethod, TPath, TTypeConfig>, TTypedResponse extends TypedResponseFromTypeConfig<TTypeConfig> = TypedResponseFromTypeConfig<TTypeConfig>>(opts: AddRouteWithTypesOpts<TServerContext, TMethod, TPath, TTypedRequest, TTypedResponse>): Router<TServerContext, TComponents, TRouterSDK & RouterSDK<TPath, TTypedRequest, TTypedResponse>>;
126
127
  __client: TRouterSDK;
127
128
  __onRouterInitHooks: OnRouterInitHook<TServerContext>[];
128
129
  }
@@ -133,7 +134,7 @@ export type RouteHandler<TServerContext = {}, TTypedRequest extends TypedRequest
133
134
  * The request object represents the incoming HTTP request.
134
135
  * This object implements [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) interface.
135
136
  */
136
- request: TTypedRequest, context: TServerContext) => PromiseOrValue<TTypedResponse | Response | void>;
137
+ request: TTypedRequest, context: TServerContext) => PromiseOrValue<TTypedResponse | void>;
137
138
  export type OnRouteHookPayload<TServerContext> = {
138
139
  operationId?: string;
139
140
  description?: string;
@@ -184,7 +185,7 @@ export type FromSchemaWithComponents<TComponents, TSchema extends JSONSchema> =
184
185
  } ? FromSchema<{
185
186
  components: TComponents;
186
187
  } & TSchema> : FromSchema<TSchema>;
187
- export type TypedRequestFromRouteSchemas<TComponents extends RouterComponentsBase, TRouteSchemas extends RouteSchemas, TMethod extends HTTPMethod> = TRouteSchemas extends {
188
+ export type TypedRequestFromRouteSchemas<TComponents extends RouterComponentsBase, TRouteSchemas extends RouteSchemas, TMethod extends HTTPMethod, TPath extends string> = TRouteSchemas extends {
188
189
  request: Required<RouteSchemas>['request'];
189
190
  } ? TypedRequest<TRouteSchemas['request'] extends {
190
191
  json: JSONSchema;
@@ -194,18 +195,18 @@ export type TypedRequestFromRouteSchemas<TComponents extends RouterComponentsBas
194
195
  headers: JSONSchema;
195
196
  } ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['headers']> extends Record<string, string> ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['headers']> : Record<string, string> : Record<string, string>, TMethod, TRouteSchemas['request'] extends {
196
197
  query: JSONSchema;
197
- } ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['query']> extends Record<string, string> ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['query']> : Record<string, string | string[]> : Record<string, string | string[]>, TRouteSchemas['request'] extends {
198
+ } ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['query']> extends Record<string, string | string[]> ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['query']> : Record<string, string | string[]> : Record<string, string | string[]>, TRouteSchemas['request'] extends {
198
199
  params: JSONSchema;
199
- } ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['params']> extends Record<string, string> ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['params']> : Record<string, any> : Record<string, any>> : TypedRequest<any, Record<string, FormDataEntryValue>, Record<string, string>, TMethod>;
200
+ } ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['params']> extends Record<string, any> ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['params']> : Record<ExtractPathParamsWithPattern<TPath>, string> : Record<ExtractPathParamsWithPattern<TPath>, string>> : TypedRequest<any, Record<string, FormDataEntryValue>, Record<string, string>, TMethod, Record<string, string | string[]>, Record<ExtractPathParamsWithPattern<TPath>, string>>;
200
201
  export type TypedResponseFromRouteSchemas<TComponents extends RouterComponentsBase, TRouteSchemas extends RouteSchemas> = TRouteSchemas extends {
201
202
  responses: StatusCodeMap<JSONSchema>;
202
203
  } ? TypedResponseWithJSONStatusMap<{
203
204
  [TStatusCode in keyof TRouteSchemas['responses']]: TRouteSchemas['responses'][TStatusCode] extends JSONSchema ? FromSchemaWithComponents<TComponents, TRouteSchemas['responses'][TStatusCode]> : never;
204
205
  }> : TypedResponse;
205
- export type AddRouteWithSchemasOpts<TServerContext, TComponents extends RouterComponentsBase, TRouteSchemas extends RouteSchemas, TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequestFromRouteSchemas<TComponents, TRouteSchemas, TMethod>, TTypedResponse extends TypedResponseFromRouteSchemas<TComponents, TRouteSchemas>> = {
206
+ export type AddRouteWithSchemasOpts<TServerContext, TComponents extends RouterComponentsBase, TRouteSchemas extends RouteSchemas, TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequestFromRouteSchemas<TComponents, TRouteSchemas, TMethod, TPath>, TTypedResponse extends TypedResponseFromRouteSchemas<TComponents, TRouteSchemas>> = {
206
207
  schemas: TRouteSchemas;
207
208
  } & AddRouteWithTypesOpts<TServerContext, TMethod, TPath, TTypedRequest, TTypedResponse>;
208
- export type AddRouteWithTypesOpts<TServerContext, TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequest, TTypedResponse extends TypedResponse> = {
209
+ export type AddRouteWithTypesOpts<TServerContext, TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequest<any, Record<string, FormDataEntryValue>, Record<string, string>, TMethod, Record<string, string | string[]>, Record<ExtractPathParamsWithPattern<TPath>, string>>, TTypedResponse extends TypedResponse> = {
209
210
  operationId?: string;
210
211
  description?: string;
211
212
  method?: TMethod;
@@ -246,3 +247,15 @@ export type RouterOutput<TRouter extends Router<any, any, any>> = {
246
247
  export type RouterComponentSchema<TRouter extends Router<any, any, any>, TName extends string> = TRouter extends Router<any, infer TComponents, any> ? TComponents extends {
247
248
  schemas: Record<string, JSONSchema>;
248
249
  } ? FromSchema<TComponents['schemas'][TName]> : never : never;
250
+ export type ExtractPathParamsWithBrackets<TPath extends string> = Pipe<TPath, [
251
+ Strings.Split<'/' | ';'>,
252
+ Tuples.Filter<Strings.StartsWith<'{'>>,
253
+ Tuples.Map<Strings.Trim<'{' | '}'>>,
254
+ Tuples.ToUnion
255
+ ]>;
256
+ export type ExtractPathParamsWithPattern<TPath extends string> = Pipe<TPath, [
257
+ Strings.Split<'/'>,
258
+ Tuples.Filter<Strings.StartsWith<':'>>,
259
+ Tuples.Map<Strings.Trim<':'>>,
260
+ Tuples.ToUnion
261
+ ]>;
@@ -1,9 +1,10 @@
1
- import { FromSchema as FromSchemaOriginal, JSONSchema as JSONSchemaOrBoolean } from 'json-schema-to-ts';
2
- import { ServerAdapter, ServerAdapterOptions, ServerAdapterPlugin, ServerAdapterRequestHandler } from '@whatwg-node/server';
3
- import { SwaggerUIOpts } from './plugins/openapi.js';
4
- import { LazySerializedResponse } from './Response.js';
1
+ import type { Pipe, Strings, Tuples } from 'hotscript';
2
+ import type { FromSchema as FromSchemaOriginal, JSONSchema as JSONSchemaOrBoolean } from 'json-schema-to-ts';
3
+ import type { ServerAdapter, ServerAdapterOptions, ServerAdapterPlugin, ServerAdapterRequestHandler } from '@whatwg-node/server';
4
+ import type { SwaggerUIOpts } from './plugins/openapi.js';
5
+ import type { LazySerializedResponse } from './Response.js';
5
6
  import type { HTTPMethod, StatusCode, TypedRequest, TypedResponse, TypedResponseWithJSONStatusMap } from './typed-fetch.js';
6
- import { AddRouteWithZodSchemasOpts, RouteZodSchemas, TypedRequestFromRouteZodSchemas, TypedResponseFromRouteZodSchemas } from './zod/types.js';
7
+ import type { AddRouteWithZodSchemasOpts, RouteZodSchemas, TypedRequestFromRouteZodSchemas, TypedResponseFromRouteZodSchemas } from './zod/types.js';
7
8
  export { TypedRequest as RouterRequest };
8
9
  export type Simplify<T> = {
9
10
  [KeyType in keyof T]: Simplify<T[KeyType]>;
@@ -101,7 +102,7 @@ export type PromiseOrValue<T> = T | Promise<T>;
101
102
  export type StatusCodeMap<T> = {
102
103
  [TKey in StatusCode]?: T;
103
104
  };
104
- export type TypedRouterHandlerTypeConfig<TRequestJSON = any, TRequestFormData extends Record<string, FormDataEntryValue> = Record<string, FormDataEntryValue>, TRequestHeaders extends Record<string, string> = Record<string, string>, TRequestQueryParams extends Record<string, string | string[]> = Record<string, string | string[]>, TRequestPathParams extends Record<string, any> = Record<string, any>, TResponseJSONStatusMap extends StatusCodeMap<any> = StatusCodeMap<any>> = {
105
+ export type TypedRouterHandlerTypeConfig<TPath extends string, TRequestJSON = any, TRequestFormData extends Record<string, FormDataEntryValue> = Record<string, FormDataEntryValue>, TRequestHeaders extends Record<string, string> = Record<string, string>, TRequestQueryParams extends Record<string, string | string[]> = Record<string, string | string[]>, TRequestPathParams extends Record<string, any> = Record<ExtractPathParamsWithPattern<TPath>, string>, TResponseJSONStatusMap extends StatusCodeMap<any> = StatusCodeMap<any>> = {
105
106
  request: {
106
107
  json?: TRequestJSON;
107
108
  formData?: TRequestFormData;
@@ -111,18 +112,18 @@ export type TypedRouterHandlerTypeConfig<TRequestJSON = any, TRequestFormData ex
111
112
  };
112
113
  responses?: TResponseJSONStatusMap;
113
114
  };
114
- export type TypedRequestFromTypeConfig<TMethod extends HTTPMethod, TTypeConfig extends TypedRouterHandlerTypeConfig> = TTypeConfig extends {
115
- request: Required<TypedRouterHandlerTypeConfig>['request'];
116
- } ? TTypeConfig extends TypedRouterHandlerTypeConfig<infer TRequestJSON, infer TRequestFormData, infer TRequestHeaders, infer TRequestQueryParams, infer TRequestPathParams> ? TypedRequest<TRequestJSON, TRequestFormData, TRequestHeaders, TMethod, TRequestQueryParams, TRequestPathParams> : never : TypedRequest;
117
- export type TypedResponseFromTypeConfig<TTypeConfig extends TypedRouterHandlerTypeConfig> = TTypeConfig extends {
115
+ export type TypedRequestFromTypeConfig<TMethod extends HTTPMethod, TPath extends string, TTypeConfig extends TypedRouterHandlerTypeConfig<TPath>> = TTypeConfig extends {
116
+ request: Required<TypedRouterHandlerTypeConfig<TPath>>['request'];
117
+ } ? TTypeConfig extends TypedRouterHandlerTypeConfig<TPath, infer TRequestJSON, infer TRequestFormData, infer TRequestHeaders, infer TRequestQueryParams, infer TRequestPathParams> ? TypedRequest<TRequestJSON, TRequestFormData, TRequestHeaders, TMethod, TRequestQueryParams, TRequestPathParams> : never : TypedRequest<any, Record<string, FormDataEntryValue>, Record<string, string>, TMethod, Record<string, string | string[]>, Record<ExtractPathParamsWithPattern<TPath>, string>>;
118
+ export type TypedResponseFromTypeConfig<TTypeConfig extends TypedRouterHandlerTypeConfig<string>> = TTypeConfig extends {
118
119
  responses: infer TResponses;
119
120
  } ? TResponses extends StatusCodeMap<any> ? TypedResponseWithJSONStatusMap<TResponses> : never : TypedResponse;
120
121
  export interface RouterBaseObject<TServerContext, TComponents extends RouterComponentsBase, TRouterSDK extends RouterSDK<string, TypedRequest, TypedResponse>> {
121
122
  openAPIDocument: OpenAPIDocument;
122
123
  handle: ServerAdapterRequestHandler<TServerContext>;
123
- route<TRouteSchemas extends RouteSchemas, TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequestFromRouteSchemas<TComponents, TRouteSchemas, TMethod>, TTypedResponse extends TypedResponseFromRouteSchemas<TComponents, TRouteSchemas>>(opts: AddRouteWithSchemasOpts<TServerContext, TComponents, TRouteSchemas, TMethod, TPath, TTypedRequest, TTypedResponse>): Router<TServerContext, TComponents, TRouterSDK & RouterSDK<TPath, TTypedRequest, TTypedResponse>>;
124
+ route<TRouteSchemas extends RouteSchemas, TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequestFromRouteSchemas<TComponents, TRouteSchemas, TMethod, TPath>, TTypedResponse extends TypedResponseFromRouteSchemas<TComponents, TRouteSchemas>>(opts: AddRouteWithSchemasOpts<TServerContext, TComponents, TRouteSchemas, TMethod, TPath, TTypedRequest, TTypedResponse>): Router<TServerContext, TComponents, TRouterSDK & RouterSDK<TPath, TTypedRequest, TTypedResponse>>;
124
125
  route<TRouteZodSchemas extends RouteZodSchemas, TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequestFromRouteZodSchemas<TRouteZodSchemas, TMethod>, TTypedResponse extends TypedResponseFromRouteZodSchemas<TRouteZodSchemas>>(opts: AddRouteWithZodSchemasOpts<TServerContext, TRouteZodSchemas, TMethod, TPath, TTypedRequest, TTypedResponse>): Router<TServerContext, TComponents, TRouterSDK & RouterSDK<TPath, TTypedRequest, TTypedResponse>>;
125
- route<TTypeConfig extends TypedRouterHandlerTypeConfig, TMethod extends HTTPMethod = HTTPMethod, TTypedRequest extends TypedRequestFromTypeConfig<TMethod, TTypeConfig> = TypedRequestFromTypeConfig<TMethod, TTypeConfig>, TTypedResponse extends TypedResponseFromTypeConfig<TTypeConfig> = TypedResponseFromTypeConfig<TTypeConfig>, TPath extends string = string>(opts: AddRouteWithTypesOpts<TServerContext, TMethod, TPath, TTypedRequest, TTypedResponse>): Router<TServerContext, TComponents, TRouterSDK & RouterSDK<TPath, TTypedRequest, TTypedResponse>>;
126
+ route<TTypeConfig extends TypedRouterHandlerTypeConfig<TPath>, TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequestFromTypeConfig<TMethod, TPath, TTypeConfig> = TypedRequestFromTypeConfig<TMethod, TPath, TTypeConfig>, TTypedResponse extends TypedResponseFromTypeConfig<TTypeConfig> = TypedResponseFromTypeConfig<TTypeConfig>>(opts: AddRouteWithTypesOpts<TServerContext, TMethod, TPath, TTypedRequest, TTypedResponse>): Router<TServerContext, TComponents, TRouterSDK & RouterSDK<TPath, TTypedRequest, TTypedResponse>>;
126
127
  __client: TRouterSDK;
127
128
  __onRouterInitHooks: OnRouterInitHook<TServerContext>[];
128
129
  }
@@ -133,7 +134,7 @@ export type RouteHandler<TServerContext = {}, TTypedRequest extends TypedRequest
133
134
  * The request object represents the incoming HTTP request.
134
135
  * This object implements [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) interface.
135
136
  */
136
- request: TTypedRequest, context: TServerContext) => PromiseOrValue<TTypedResponse | Response | void>;
137
+ request: TTypedRequest, context: TServerContext) => PromiseOrValue<TTypedResponse | void>;
137
138
  export type OnRouteHookPayload<TServerContext> = {
138
139
  operationId?: string;
139
140
  description?: string;
@@ -184,7 +185,7 @@ export type FromSchemaWithComponents<TComponents, TSchema extends JSONSchema> =
184
185
  } ? FromSchema<{
185
186
  components: TComponents;
186
187
  } & TSchema> : FromSchema<TSchema>;
187
- export type TypedRequestFromRouteSchemas<TComponents extends RouterComponentsBase, TRouteSchemas extends RouteSchemas, TMethod extends HTTPMethod> = TRouteSchemas extends {
188
+ export type TypedRequestFromRouteSchemas<TComponents extends RouterComponentsBase, TRouteSchemas extends RouteSchemas, TMethod extends HTTPMethod, TPath extends string> = TRouteSchemas extends {
188
189
  request: Required<RouteSchemas>['request'];
189
190
  } ? TypedRequest<TRouteSchemas['request'] extends {
190
191
  json: JSONSchema;
@@ -194,18 +195,18 @@ export type TypedRequestFromRouteSchemas<TComponents extends RouterComponentsBas
194
195
  headers: JSONSchema;
195
196
  } ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['headers']> extends Record<string, string> ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['headers']> : Record<string, string> : Record<string, string>, TMethod, TRouteSchemas['request'] extends {
196
197
  query: JSONSchema;
197
- } ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['query']> extends Record<string, string> ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['query']> : Record<string, string | string[]> : Record<string, string | string[]>, TRouteSchemas['request'] extends {
198
+ } ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['query']> extends Record<string, string | string[]> ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['query']> : Record<string, string | string[]> : Record<string, string | string[]>, TRouteSchemas['request'] extends {
198
199
  params: JSONSchema;
199
- } ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['params']> extends Record<string, string> ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['params']> : Record<string, any> : Record<string, any>> : TypedRequest<any, Record<string, FormDataEntryValue>, Record<string, string>, TMethod>;
200
+ } ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['params']> extends Record<string, any> ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['params']> : Record<ExtractPathParamsWithPattern<TPath>, string> : Record<ExtractPathParamsWithPattern<TPath>, string>> : TypedRequest<any, Record<string, FormDataEntryValue>, Record<string, string>, TMethod, Record<string, string | string[]>, Record<ExtractPathParamsWithPattern<TPath>, string>>;
200
201
  export type TypedResponseFromRouteSchemas<TComponents extends RouterComponentsBase, TRouteSchemas extends RouteSchemas> = TRouteSchemas extends {
201
202
  responses: StatusCodeMap<JSONSchema>;
202
203
  } ? TypedResponseWithJSONStatusMap<{
203
204
  [TStatusCode in keyof TRouteSchemas['responses']]: TRouteSchemas['responses'][TStatusCode] extends JSONSchema ? FromSchemaWithComponents<TComponents, TRouteSchemas['responses'][TStatusCode]> : never;
204
205
  }> : TypedResponse;
205
- export type AddRouteWithSchemasOpts<TServerContext, TComponents extends RouterComponentsBase, TRouteSchemas extends RouteSchemas, TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequestFromRouteSchemas<TComponents, TRouteSchemas, TMethod>, TTypedResponse extends TypedResponseFromRouteSchemas<TComponents, TRouteSchemas>> = {
206
+ export type AddRouteWithSchemasOpts<TServerContext, TComponents extends RouterComponentsBase, TRouteSchemas extends RouteSchemas, TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequestFromRouteSchemas<TComponents, TRouteSchemas, TMethod, TPath>, TTypedResponse extends TypedResponseFromRouteSchemas<TComponents, TRouteSchemas>> = {
206
207
  schemas: TRouteSchemas;
207
208
  } & AddRouteWithTypesOpts<TServerContext, TMethod, TPath, TTypedRequest, TTypedResponse>;
208
- export type AddRouteWithTypesOpts<TServerContext, TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequest, TTypedResponse extends TypedResponse> = {
209
+ export type AddRouteWithTypesOpts<TServerContext, TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequest<any, Record<string, FormDataEntryValue>, Record<string, string>, TMethod, Record<string, string | string[]>, Record<ExtractPathParamsWithPattern<TPath>, string>>, TTypedResponse extends TypedResponse> = {
209
210
  operationId?: string;
210
211
  description?: string;
211
212
  method?: TMethod;
@@ -246,3 +247,15 @@ export type RouterOutput<TRouter extends Router<any, any, any>> = {
246
247
  export type RouterComponentSchema<TRouter extends Router<any, any, any>, TName extends string> = TRouter extends Router<any, infer TComponents, any> ? TComponents extends {
247
248
  schemas: Record<string, JSONSchema>;
248
249
  } ? FromSchema<TComponents['schemas'][TName]> : never : never;
250
+ export type ExtractPathParamsWithBrackets<TPath extends string> = Pipe<TPath, [
251
+ Strings.Split<'/' | ';'>,
252
+ Tuples.Filter<Strings.StartsWith<'{'>>,
253
+ Tuples.Map<Strings.Trim<'{' | '}'>>,
254
+ Tuples.ToUnion
255
+ ]>;
256
+ export type ExtractPathParamsWithPattern<TPath extends string> = Pipe<TPath, [
257
+ Strings.Split<'/'>,
258
+ Tuples.Filter<Strings.StartsWith<':'>>,
259
+ Tuples.Map<Strings.Trim<':'>>,
260
+ Tuples.ToUnion
261
+ ]>;