@kaito-http/core 3.0.0-beta.4 → 3.0.0-beta.6

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/dist/index.d.ts CHANGED
@@ -137,6 +137,7 @@ type PrefixRoutesPath<Prefix extends `/${string}`, R extends AnyRoute> = R exten
137
137
  type RouterOptions<ContextFrom, ContextTo> = {
138
138
  through: (context: ContextFrom) => Promise<ContextTo>;
139
139
  };
140
+ type InferRoutes<R extends Router<any, any, any>> = R extends Router<any, any, infer R> ? R : never;
140
141
  declare class Router<ContextFrom, ContextTo, R extends AnyRoute> {
141
142
  private readonly routerOptions;
142
143
  readonly routes: Set<R>;
@@ -198,13 +199,14 @@ declare function createUtilities<Context>(getContext: GetContext<Context>): {
198
199
  type InferContext<T> = T extends (req: KaitoRequest, res: KaitoResponse) => Promise<infer U> ? U : never;
199
200
  declare function getLastEntryInMultiHeaderValue(headerValue: string | string[]): string;
200
201
  interface Parsable<Output = any, Input = Output> {
201
- _input?: Input;
202
+ _input: Input;
202
203
  parse: (value: unknown) => Output;
203
204
  }
204
205
  type InferParsable<T> = T extends Parsable<infer Output, infer Input> ? {
205
206
  input: Input;
206
207
  output: Output;
207
208
  } : never;
209
+ declare function parsable<T>(parse: (value: unknown) => T): Parsable<T, T>;
208
210
  type RemoveEndSlashes<T extends string> = T extends `${infer U}/` ? U : T;
209
211
  type AddStartSlashes<T extends string> = T extends `/${infer U}` ? `/${U}` : `/${T}`;
210
212
  type NormalizePath<T extends string> = AddStartSlashes<RemoveEndSlashes<T>>;
@@ -218,7 +220,7 @@ type RouteArgument<Path extends string, Context, QueryOutput, BodyOutput> = {
218
220
  query: QueryOutput;
219
221
  params: ExtractRouteParams<Path>;
220
222
  };
221
- type AnyQueryDefinition = Record<string, Parsable>;
223
+ type AnyQueryDefinition = Record<string, Parsable<any, string | undefined>>;
222
224
  type RouteRunner<Result, Path extends string, Context, QueryOutput, BodyOutput> = (args: RouteArgument<Path, Context, QueryOutput, BodyOutput>) => Promise<Result>;
223
225
  type Route<ContextFrom, ContextTo, Result, Path extends string, Method extends KaitoMethod, Query extends AnyQueryDefinition, Body extends Parsable> = {
224
226
  through: (context: ContextFrom) => Promise<ContextTo>;
@@ -232,4 +234,4 @@ type Route<ContextFrom, ContextTo, Result, Path extends string, Method extends K
232
234
  };
233
235
  type AnyRoute<FromContext = any, ToContext = any> = Route<FromContext, ToContext, any, any, any, AnyQueryDefinition, any>;
234
236
 
235
- export { type APIResponse, type AddStartSlashes, type After, type AnyQueryDefinition, type AnyResponse, type AnyRoute, type Before, type ErroredAPIResponse, type ExtractRouteParams, type GetContext, type HandlerResult, type InferContext, type InferParsable, KaitoError, type KaitoMethod, KaitoRequest, KaitoResponse, type NoEmpty, type NormalizePath, type Parsable, type RemoveEndSlashes, type Route, type RouteArgument, type RouteRunner, Router, type RouterOptions, type ServerConfig, type ServerConfigWithBefore, type SuccessfulAPIResponse, type Values, WrappedError, createFMWServer, createGetContext, createServer, createUtilities, getBody, getLastEntryInMultiHeaderValue };
237
+ export { type APIResponse, type AddStartSlashes, type After, type AnyQueryDefinition, type AnyResponse, type AnyRoute, type Before, type ErroredAPIResponse, type ExtractRouteParams, type GetContext, type HandlerResult, type InferContext, type InferParsable, type InferRoutes, KaitoError, type KaitoMethod, KaitoRequest, KaitoResponse, type NoEmpty, type NormalizePath, type Parsable, type RemoveEndSlashes, type Route, type RouteArgument, type RouteRunner, Router, type RouterOptions, type ServerConfig, type ServerConfigWithBefore, type SuccessfulAPIResponse, type Values, WrappedError, createFMWServer, createGetContext, createServer, createUtilities, getBody, getLastEntryInMultiHeaderValue, parsable };
package/dist/index.js CHANGED
@@ -102,11 +102,11 @@ var Router = class _Router {
102
102
  }
103
103
  const result = {};
104
104
  for (const [key, value] of url.searchParams.entries()) {
105
- const parsable = schema[key];
106
- if (!parsable) {
105
+ const parsable2 = schema[key];
106
+ if (!parsable2) {
107
107
  continue;
108
108
  }
109
- const parsed = parsable.parse(value);
109
+ const parsed = parsable2.parse(value);
110
110
  result[key] = parsed;
111
111
  }
112
112
  return result;
@@ -258,6 +258,11 @@ function getLastEntryInMultiHeaderValue(headerValue) {
258
258
  const lastIndex = normalized.lastIndexOf(",");
259
259
  return lastIndex === -1 ? normalized.trim() : normalized.slice(lastIndex + 1).trim();
260
260
  }
261
+ function parsable(parse) {
262
+ return {
263
+ parse
264
+ };
265
+ }
261
266
  async function getBody(req) {
262
267
  if (!req.headers["content-type"]) {
263
268
  return null;
@@ -385,5 +390,6 @@ export {
385
390
  createServer2 as createServer,
386
391
  createUtilities,
387
392
  getBody,
388
- getLastEntryInMultiHeaderValue
393
+ getLastEntryInMultiHeaderValue,
394
+ parsable
389
395
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaito-http/core",
3
- "version": "3.0.0-beta.4",
3
+ "version": "3.0.0-beta.6",
4
4
  "type": "module",
5
5
  "author": "Alistair Smith <hi@alistair.sh>",
6
6
  "description": "Functional HTTP Framework for TypeScript",
@@ -23,6 +23,7 @@
23
23
  "@types/content-type": "^1.1.8",
24
24
  "@types/cookie": "^0.6.0",
25
25
  "@types/node": "^22.7.4",
26
+ "tsup": "^8.3.0",
26
27
  "typescript": "^5.6.2"
27
28
  },
28
29
  "files": [