ts-typed-api 0.2.8 → 0.2.10

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.
@@ -1,6 +1,9 @@
1
+ import type { ApiBody, ApiDefinitionSchema, ApiParams, ApiQuery } from './definition';
2
+ import type { TypedRequest, TypedResponse } from './router';
1
3
  export { CreateApiDefinition, CreateResponses } from './definition';
2
4
  export { z as ZodSchema } from 'zod';
3
- export { EndpointMiddleware, EndpointMiddlewareCtx, createTypedHandler } from './object-handlers';
5
+ export { EndpointMiddleware, EndpointMiddlewareCtx } from './object-handlers';
6
+ export declare function createTypedHandler<TDef extends ApiDefinitionSchema, TDomain extends keyof TDef['endpoints'], TRouteKey extends keyof TDef['endpoints'][TDomain], Ctx extends Record<string, any> = Record<string, any>>(handler: (req: TypedRequest<TDef, TDomain, TRouteKey, ApiParams<TDef, TDomain, TRouteKey>, ApiBody<TDef, TDomain, TRouteKey>, ApiQuery<TDef, TDomain, TRouteKey>, Record<string, any>, Ctx>, res: TypedResponse<TDef, TDomain, TRouteKey>) => Promise<void> | void): (req: TypedRequest<TDef, TDomain, TRouteKey, ApiParams<TDef, TDomain, TRouteKey>, ApiBody<TDef, TDomain, TRouteKey>, ApiQuery<TDef, TDomain, TRouteKey>, Record<string, any>, Ctx>, res: TypedResponse<TDef, TDomain, TRouteKey>) => Promise<void> | void;
4
7
  export { RegisterHonoHandlers, CreateTypedHonoHandlerWithContext } from './hono-cloudflare-workers';
5
8
  export type { ApiDefinitionSchema, RouteSchema, UnifiedError, FileUploadConfig, HttpSuccessStatusCode, HttpClientErrorStatusCode, HttpServerErrorStatusCode, AllowedInputStatusCode, AllowedResponseStatusCode } from './definition';
6
9
  export type { HonoFile, HonoFileType, HonoTypedContext } from './hono-cloudflare-workers';
package/dist/hono-only.js CHANGED
@@ -1,15 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CreateTypedHonoHandlerWithContext = exports.RegisterHonoHandlers = exports.createTypedHandler = exports.ZodSchema = exports.CreateResponses = exports.CreateApiDefinition = void 0;
4
- // Hono-only exports - for Cloudflare Workers and other Hono environments
5
- // Excludes Express dependencies like multer, busboy, etc.
3
+ exports.CreateTypedHonoHandlerWithContext = exports.RegisterHonoHandlers = exports.ZodSchema = exports.CreateResponses = exports.CreateApiDefinition = void 0;
4
+ exports.createTypedHandler = createTypedHandler;
6
5
  var definition_1 = require("./definition");
7
6
  Object.defineProperty(exports, "CreateApiDefinition", { enumerable: true, get: function () { return definition_1.CreateApiDefinition; } });
8
7
  Object.defineProperty(exports, "CreateResponses", { enumerable: true, get: function () { return definition_1.CreateResponses; } });
9
8
  var zod_1 = require("zod");
10
9
  Object.defineProperty(exports, "ZodSchema", { enumerable: true, get: function () { return zod_1.z; } });
11
- var object_handlers_1 = require("./object-handlers");
12
- Object.defineProperty(exports, "createTypedHandler", { enumerable: true, get: function () { return object_handlers_1.createTypedHandler; } });
10
+ // Helper function to create typed handlers with proper type inference
11
+ // Defined locally to avoid Express dependencies in Hono-only bundle
12
+ function createTypedHandler(handler) {
13
+ return handler;
14
+ }
13
15
  // Hono adapter for Cloudflare Workers
14
16
  var hono_cloudflare_workers_1 = require("./hono-cloudflare-workers");
15
17
  Object.defineProperty(exports, "RegisterHonoHandlers", { enumerable: true, get: function () { return hono_cloudflare_workers_1.RegisterHonoHandlers; } });
@@ -1,5 +1,5 @@
1
1
  import express from "express";
2
- import { ApiDefinitionSchema } from "./definition";
2
+ import { ApiDefinitionSchema, ApiParams, ApiBody, ApiQuery } from "./definition";
3
3
  import { TypedRequest, TypedResponse } from "./router";
4
4
  export type EndpointInfo<TDef extends ApiDefinitionSchema = ApiDefinitionSchema> = {
5
5
  [TDomain in keyof TDef['endpoints']]: {
@@ -17,13 +17,13 @@ export type EndpointMiddlewareCtx<Ctx extends Record<string, any> = Record<strin
17
17
  ctx?: Ctx;
18
18
  }, res: express.Response, next: express.NextFunction, endpointInfo: EndpointInfo<TDef>) => void | Promise<void>) | ((c: any, next: any) => void | Promise<void>);
19
19
  export type AnyMiddleware<TDef extends ApiDefinitionSchema = ApiDefinitionSchema> = EndpointMiddleware<TDef> | UniversalEndpointMiddleware | SimpleMiddleware;
20
- type HandlerFunction<TDef extends ApiDefinitionSchema, TDomain extends keyof TDef['endpoints'], TRouteKey extends keyof TDef['endpoints'][TDomain], Ctx extends Record<string, any> = Record<string, any>> = (req: TypedRequest<TDef, TDomain, TRouteKey, any, any, any, any, Ctx>, res: TypedResponse<TDef, TDomain, TRouteKey>) => Promise<void> | void;
20
+ type HandlerFunction<TDef extends ApiDefinitionSchema, TDomain extends keyof TDef['endpoints'], TRouteKey extends keyof TDef['endpoints'][TDomain], Ctx extends Record<string, any> = Record<string, any>> = (req: TypedRequest<TDef, TDomain, TRouteKey, ApiParams<TDef, TDomain, TRouteKey>, ApiBody<TDef, TDomain, TRouteKey>, ApiQuery<TDef, TDomain, TRouteKey>, Record<string, any>, Ctx>, res: TypedResponse<TDef, TDomain, TRouteKey>) => Promise<void> | void;
21
21
  export type ObjectHandlers<TDef extends ApiDefinitionSchema, Ctx extends Record<string, any> = Record<string, any>> = {
22
22
  [TDomain in keyof TDef['endpoints']]: {
23
23
  [TRouteKey in keyof TDef['endpoints'][TDomain]]: HandlerFunction<TDef, TDomain, TRouteKey, Ctx>;
24
24
  };
25
25
  };
26
26
  export declare function RegisterHandlers<TDef extends ApiDefinitionSchema, Ctx extends Record<string, any> = Record<string, any>>(app: express.Express, apiDefinition: TDef, objectHandlers: ObjectHandlers<TDef, Ctx>, middlewares?: AnyMiddleware<TDef>[]): void;
27
- export declare function createTypedHandler<TDef extends ApiDefinitionSchema, TDomain extends keyof TDef['endpoints'], TRouteKey extends keyof TDef['endpoints'][TDomain], Ctx extends Record<string, any> = Record<string, any>>(handler: (req: TypedRequest<TDef, TDomain, TRouteKey, any, any, any, any, Ctx>, res: TypedResponse<TDef, TDomain, TRouteKey>) => Promise<void> | void): (req: TypedRequest<TDef, TDomain, TRouteKey, any, any, any, any, Ctx>, res: TypedResponse<TDef, TDomain, TRouteKey>) => Promise<void> | void;
27
+ export declare function createTypedHandler<TDef extends ApiDefinitionSchema, TDomain extends keyof TDef['endpoints'], TRouteKey extends keyof TDef['endpoints'][TDomain], Ctx extends Record<string, any> = Record<string, any>>(handler: (req: TypedRequest<TDef, TDomain, TRouteKey, ApiParams<TDef, TDomain, TRouteKey>, ApiBody<TDef, TDomain, TRouteKey>, ApiQuery<TDef, TDomain, TRouteKey>, Record<string, any>, Ctx>, res: TypedResponse<TDef, TDomain, TRouteKey>) => Promise<void> | void): (req: TypedRequest<TDef, TDomain, TRouteKey, ApiParams<TDef, TDomain, TRouteKey>, ApiBody<TDef, TDomain, TRouteKey>, ApiQuery<TDef, TDomain, TRouteKey>, Record<string, any>, Ctx>, res: TypedResponse<TDef, TDomain, TRouteKey>) => Promise<void> | void;
28
28
  export declare function makeObjectHandlerRegistrar<TDef extends ApiDefinitionSchema>(apiDefinition: TDef): (app: express.Express, objectHandlers: ObjectHandlers<TDef>, middlewares?: EndpointMiddleware<TDef>[]) => void;
29
29
  export {};
package/dist/router.d.ts CHANGED
@@ -17,10 +17,10 @@ export interface TypedResponse<TDef extends ApiDefinitionSchema, TDomain extends
17
17
  json: <B = any>(body: B) => this;
18
18
  }
19
19
  export declare function createRouteHandler<TDef extends ApiDefinitionSchema, TDomain extends keyof TDef['endpoints'], TRouteKey extends keyof TDef['endpoints'][TDomain], // Using direct keyof for simplicity
20
- Ctx extends Record<string, any> = Record<string, any>>(domain: TDomain, routeKey: TRouteKey, handler: (req: TypedRequest<TDef, TDomain, TRouteKey, any, any, any, any, Ctx>, res: TypedResponse<TDef, TDomain, TRouteKey>) => Promise<void> | void): {
20
+ Ctx extends Record<string, any> = Record<string, any>>(domain: TDomain, routeKey: TRouteKey, handler: (req: TypedRequest<TDef, TDomain, TRouteKey, ApiParams<TDef, TDomain, TRouteKey>, ApiBody<TDef, TDomain, TRouteKey>, ApiQuery<TDef, TDomain, TRouteKey>, Record<string, any>, Ctx>, res: TypedResponse<TDef, TDomain, TRouteKey>) => Promise<void> | void): {
21
21
  domain: TDomain;
22
22
  routeKey: TRouteKey;
23
- handler: (req: TypedRequest<TDef, TDomain, TRouteKey, any, any, any, any, Ctx>, res: TypedResponse<TDef, TDomain, TRouteKey>) => Promise<void> | void;
23
+ handler: (req: TypedRequest<TDef, TDomain, TRouteKey, ApiParams<TDef, TDomain, TRouteKey>, ApiBody<TDef, TDomain, TRouteKey>, ApiQuery<TDef, TDomain, TRouteKey>, Record<string, any>, Ctx>, res: TypedResponse<TDef, TDomain, TRouteKey>) => Promise<void> | void;
24
24
  };
25
25
  export declare function makeRouteHandlerCreator<TDef extends ApiDefinitionSchema>(): <TDomain extends keyof TDef["endpoints"], TRouteKey extends keyof TDef["endpoints"][TDomain]>(domain: TDomain, routeKey: TRouteKey, handler: (req: TypedRequest<TDef, TDomain, TRouteKey>, res: TypedResponse<TDef, TDomain, TRouteKey>) => Promise<void> | void) => ReturnType<typeof createRouteHandler<TDef, TDomain, TRouteKey>>;
26
26
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-typed-api",
3
- "version": "0.2.8",
3
+ "version": "0.2.10",
4
4
  "description": "A lightweight, type-safe RPC library for TypeScript with Zod validation",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/hono-only.ts CHANGED
@@ -1,8 +1,28 @@
1
1
  // Hono-only exports - for Cloudflare Workers and other Hono environments
2
2
  // Excludes Express dependencies like multer, busboy, etc.
3
+ import type { ApiBody, ApiDefinitionSchema, ApiParams, ApiQuery } from './definition';
4
+ import type { TypedRequest, TypedResponse } from './router';
5
+
3
6
  export { CreateApiDefinition, CreateResponses } from './definition';
4
7
  export { z as ZodSchema } from 'zod';
5
- export { EndpointMiddleware, EndpointMiddlewareCtx, createTypedHandler } from './object-handlers'
8
+ export { EndpointMiddleware, EndpointMiddlewareCtx } from './object-handlers'
9
+
10
+ // Helper function to create typed handlers with proper type inference
11
+ // Defined locally to avoid Express dependencies in Hono-only bundle
12
+ export function createTypedHandler<
13
+ TDef extends ApiDefinitionSchema,
14
+ TDomain extends keyof TDef['endpoints'],
15
+ TRouteKey extends keyof TDef['endpoints'][TDomain],
16
+ Ctx extends Record<string, any> = Record<string, any>
17
+ >(
18
+ handler: (
19
+ req: TypedRequest<TDef, TDomain, TRouteKey, ApiParams<TDef, TDomain, TRouteKey>, ApiBody<TDef, TDomain, TRouteKey>, ApiQuery<TDef, TDomain, TRouteKey>, Record<string, any>, Ctx>,
20
+ res: TypedResponse<TDef, TDomain, TRouteKey>
21
+ ) => Promise<void> | void
22
+ ) {
23
+ return handler;
24
+ }
25
+
6
26
 
7
27
  // Hono adapter for Cloudflare Workers
8
28
  export { RegisterHonoHandlers, CreateTypedHonoHandlerWithContext } from './hono-cloudflare-workers';
@@ -1,5 +1,5 @@
1
1
  import express from "express";
2
- import { ApiDefinitionSchema } from "./definition";
2
+ import { ApiDefinitionSchema, ApiParams, ApiBody, ApiQuery } from "./definition";
3
3
  import { registerRouteHandlers, SpecificRouteHandler } from "./handler";
4
4
  import { TypedRequest, TypedResponse } from "./router";
5
5
 
@@ -59,7 +59,7 @@ type HandlerFunction<
59
59
  TRouteKey extends keyof TDef['endpoints'][TDomain],
60
60
  Ctx extends Record<string, any> = Record<string, any>
61
61
  > = (
62
- req: TypedRequest<TDef, TDomain, TRouteKey, any, any, any, any, Ctx>,
62
+ req: TypedRequest<TDef, TDomain, TRouteKey, ApiParams<TDef, TDomain, TRouteKey>, ApiBody<TDef, TDomain, TRouteKey>, ApiQuery<TDef, TDomain, TRouteKey>, Record<string, any>, Ctx>,
63
63
  res: TypedResponse<TDef, TDomain, TRouteKey>
64
64
  ) => Promise<void> | void;
65
65
 
@@ -144,7 +144,7 @@ export function createTypedHandler<
144
144
  Ctx extends Record<string, any> = Record<string, any>
145
145
  >(
146
146
  handler: (
147
- req: TypedRequest<TDef, TDomain, TRouteKey, any, any, any, any, Ctx>,
147
+ req: TypedRequest<TDef, TDomain, TRouteKey, ApiParams<TDef, TDomain, TRouteKey>, ApiBody<TDef, TDomain, TRouteKey>, ApiQuery<TDef, TDomain, TRouteKey>, Record<string, any>, Ctx>,
148
148
  res: TypedResponse<TDef, TDomain, TRouteKey>
149
149
  ) => Promise<void> | void
150
150
  ) {
package/src/router.ts CHANGED
@@ -74,7 +74,7 @@ export function createRouteHandler<
74
74
  routeKey: TRouteKey,
75
75
  handler: (
76
76
  // Use the TDef generic for TypedRequest and TypedResponse with Ctx
77
- req: TypedRequest<TDef, TDomain, TRouteKey, any, any, any, any, Ctx>,
77
+ req: TypedRequest<TDef, TDomain, TRouteKey, ApiParams<TDef, TDomain, TRouteKey>, ApiBody<TDef, TDomain, TRouteKey>, ApiQuery<TDef, TDomain, TRouteKey>, Record<string, any>, Ctx>,
78
78
  res: TypedResponse<TDef, TDomain, TRouteKey>
79
79
  ) => Promise<void> | void
80
80
  ) {