ts-typed-api 0.2.9 → 0.2.11
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/hono-only.d.ts +0 -3
- package/dist/hono-only.js +2 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -2
- package/dist/object-handlers.d.ts +2 -3
- package/dist/object-handlers.js +0 -5
- package/dist/router.d.ts +2 -2
- package/examples/hono-cloudflare-worker-example.ts +3 -3
- package/package.json +1 -1
- package/src/hono-only.ts +0 -18
- package/src/index.ts +1 -1
- package/src/object-handlers.ts +2 -17
- package/src/router.ts +1 -1
package/dist/hono-only.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import type { ApiDefinitionSchema } from './definition';
|
|
2
|
-
import type { TypedRequest, TypedResponse } from './router';
|
|
3
1
|
export { CreateApiDefinition, CreateResponses } from './definition';
|
|
4
2
|
export { z as ZodSchema } from 'zod';
|
|
5
3
|
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, 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;
|
|
7
4
|
export { RegisterHonoHandlers, CreateTypedHonoHandlerWithContext } from './hono-cloudflare-workers';
|
|
8
5
|
export type { ApiDefinitionSchema, RouteSchema, UnifiedError, FileUploadConfig, HttpSuccessStatusCode, HttpClientErrorStatusCode, HttpServerErrorStatusCode, AllowedInputStatusCode, AllowedResponseStatusCode } from './definition';
|
|
9
6
|
export type { HonoFile, HonoFileType, HonoTypedContext } from './hono-cloudflare-workers';
|
package/dist/hono-only.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CreateTypedHonoHandlerWithContext = exports.RegisterHonoHandlers = exports.ZodSchema = exports.CreateResponses = exports.CreateApiDefinition = void 0;
|
|
4
|
-
exports
|
|
4
|
+
// Hono-only exports - for Cloudflare Workers and other Hono environments
|
|
5
|
+
// Excludes Express dependencies like multer, busboy, etc.
|
|
5
6
|
var definition_1 = require("./definition");
|
|
6
7
|
Object.defineProperty(exports, "CreateApiDefinition", { enumerable: true, get: function () { return definition_1.CreateApiDefinition; } });
|
|
7
8
|
Object.defineProperty(exports, "CreateResponses", { enumerable: true, get: function () { return definition_1.CreateResponses; } });
|
|
8
9
|
var zod_1 = require("zod");
|
|
9
10
|
Object.defineProperty(exports, "ZodSchema", { enumerable: true, get: function () { return zod_1.z; } });
|
|
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
|
-
}
|
|
15
11
|
// Hono adapter for Cloudflare Workers
|
|
16
12
|
var hono_cloudflare_workers_1 = require("./hono-cloudflare-workers");
|
|
17
13
|
Object.defineProperty(exports, "RegisterHonoHandlers", { enumerable: true, get: function () { return hono_cloudflare_workers_1.RegisterHonoHandlers; } });
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { ApiClient, FetchHttpClientAdapter } from './client';
|
|
|
2
2
|
export { generateOpenApiSpec } from './openapi';
|
|
3
3
|
export { generateOpenApiSpec as generateOpenApiSpec2 } from './openapi-self';
|
|
4
4
|
export { CreateApiDefinition, CreateResponses, ApiDefinitionSchema } from './definition';
|
|
5
|
-
export { RegisterHandlers, EndpointMiddleware, UniversalEndpointMiddleware, SimpleMiddleware, EndpointInfo
|
|
5
|
+
export { RegisterHandlers, EndpointMiddleware, UniversalEndpointMiddleware, SimpleMiddleware, EndpointInfo } from './object-handlers';
|
|
6
6
|
export { File as UploadedFile } from './router';
|
|
7
7
|
export { z as ZodSchema } from 'zod';
|
|
8
8
|
export { RegisterHonoHandlers, registerHonoRouteHandlers, HonoFile, HonoFileType, honoFileSchema, HonoTypedContext, CreateTypedHonoHandlerWithContext } from './hono-cloudflare-workers';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CreateTypedHonoHandlerWithContext = exports.honoFileSchema = exports.registerHonoRouteHandlers = exports.RegisterHonoHandlers = exports.ZodSchema = exports.
|
|
3
|
+
exports.CreateTypedHonoHandlerWithContext = exports.honoFileSchema = exports.registerHonoRouteHandlers = exports.RegisterHonoHandlers = exports.ZodSchema = exports.RegisterHandlers = exports.CreateResponses = exports.CreateApiDefinition = exports.generateOpenApiSpec2 = exports.generateOpenApiSpec = exports.FetchHttpClientAdapter = exports.ApiClient = void 0;
|
|
4
4
|
var client_1 = require("./client");
|
|
5
5
|
Object.defineProperty(exports, "ApiClient", { enumerable: true, get: function () { return client_1.ApiClient; } });
|
|
6
6
|
Object.defineProperty(exports, "FetchHttpClientAdapter", { enumerable: true, get: function () { return client_1.FetchHttpClientAdapter; } });
|
|
@@ -13,7 +13,6 @@ Object.defineProperty(exports, "CreateApiDefinition", { enumerable: true, get: f
|
|
|
13
13
|
Object.defineProperty(exports, "CreateResponses", { enumerable: true, get: function () { return definition_1.CreateResponses; } });
|
|
14
14
|
var object_handlers_1 = require("./object-handlers");
|
|
15
15
|
Object.defineProperty(exports, "RegisterHandlers", { enumerable: true, get: function () { return object_handlers_1.RegisterHandlers; } });
|
|
16
|
-
Object.defineProperty(exports, "createTypedHandler", { enumerable: true, get: function () { return object_handlers_1.createTypedHandler; } });
|
|
17
16
|
var zod_1 = require("zod");
|
|
18
17
|
Object.defineProperty(exports, "ZodSchema", { enumerable: true, get: function () { return zod_1.z; } });
|
|
19
18
|
// Hono adapter for 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 { TypedRequest, TypedResponse } from "./router";
|
|
4
4
|
export type EndpointInfo<TDef extends ApiDefinitionSchema = ApiDefinitionSchema> = {
|
|
5
5
|
[TDomain in keyof TDef['endpoints']]: {
|
|
@@ -17,13 +17,12 @@ 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,
|
|
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;
|
|
28
27
|
export declare function makeObjectHandlerRegistrar<TDef extends ApiDefinitionSchema>(apiDefinition: TDef): (app: express.Express, objectHandlers: ObjectHandlers<TDef>, middlewares?: EndpointMiddleware<TDef>[]) => void;
|
|
29
28
|
export {};
|
package/dist/object-handlers.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RegisterHandlers = RegisterHandlers;
|
|
4
|
-
exports.createTypedHandler = createTypedHandler;
|
|
5
4
|
exports.makeObjectHandlerRegistrar = makeObjectHandlerRegistrar;
|
|
6
5
|
const handler_1 = require("./handler");
|
|
7
6
|
// Transform object-based handlers to array format
|
|
@@ -46,10 +45,6 @@ function RegisterHandlers(app, apiDefinition, objectHandlers, middlewares) {
|
|
|
46
45
|
}) || [];
|
|
47
46
|
(0, handler_1.registerRouteHandlers)(app, apiDefinition, handlerArray, endpointMiddlewares);
|
|
48
47
|
}
|
|
49
|
-
// Helper function to create typed handlers with proper type inference
|
|
50
|
-
function createTypedHandler(handler) {
|
|
51
|
-
return handler;
|
|
52
|
-
}
|
|
53
48
|
// Factory function to create a typed handler registrar for a specific API definition
|
|
54
49
|
function makeObjectHandlerRegistrar(apiDefinition) {
|
|
55
50
|
return function (app, objectHandlers, middlewares) {
|
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,
|
|
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,
|
|
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 {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Hono } from 'hono';
|
|
2
|
-
import { RegisterHonoHandlers
|
|
2
|
+
import { RegisterHonoHandlers } from '../src';
|
|
3
3
|
import { PublicApiDefinition, PrivateApiDefinition } from './simple/definitions';
|
|
4
4
|
|
|
5
5
|
// Create Hono app for Cloudflare Workers
|
|
@@ -45,10 +45,10 @@ RegisterHonoHandlers(app, PublicApiDefinition, {
|
|
|
45
45
|
// Register private handlers with auth
|
|
46
46
|
RegisterHonoHandlers(app, PrivateApiDefinition, {
|
|
47
47
|
user: {
|
|
48
|
-
get:
|
|
48
|
+
get: async (req, res) => {
|
|
49
49
|
console.log('Fetching user', req.params.id);
|
|
50
50
|
res.respond(200, "ok");
|
|
51
|
-
}
|
|
51
|
+
}
|
|
52
52
|
}
|
|
53
53
|
}, [loggingMiddleware, authMiddleware]);
|
|
54
54
|
|
package/package.json
CHANGED
package/src/hono-only.ts
CHANGED
|
@@ -1,27 +1,9 @@
|
|
|
1
1
|
// Hono-only exports - for Cloudflare Workers and other Hono environments
|
|
2
2
|
// Excludes Express dependencies like multer, busboy, etc.
|
|
3
|
-
import type { ApiDefinitionSchema } from './definition';
|
|
4
|
-
import type { TypedRequest, TypedResponse } from './router';
|
|
5
|
-
|
|
6
3
|
export { CreateApiDefinition, CreateResponses } from './definition';
|
|
7
4
|
export { z as ZodSchema } from 'zod';
|
|
8
5
|
export { EndpointMiddleware, EndpointMiddlewareCtx } from './object-handlers'
|
|
9
6
|
|
|
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, any, any, any, any, Ctx>,
|
|
20
|
-
res: TypedResponse<TDef, TDomain, TRouteKey>
|
|
21
|
-
) => Promise<void> | void
|
|
22
|
-
) {
|
|
23
|
-
return handler;
|
|
24
|
-
}
|
|
25
7
|
|
|
26
8
|
// Hono adapter for Cloudflare Workers
|
|
27
9
|
export { RegisterHonoHandlers, CreateTypedHonoHandlerWithContext } from './hono-cloudflare-workers';
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { ApiClient, FetchHttpClientAdapter } from './client';
|
|
|
2
2
|
export { generateOpenApiSpec } from './openapi'
|
|
3
3
|
export { generateOpenApiSpec as generateOpenApiSpec2 } from './openapi-self'
|
|
4
4
|
export { CreateApiDefinition, CreateResponses, ApiDefinitionSchema } from './definition';
|
|
5
|
-
export { RegisterHandlers, EndpointMiddleware, UniversalEndpointMiddleware, SimpleMiddleware, EndpointInfo
|
|
5
|
+
export { RegisterHandlers, EndpointMiddleware, UniversalEndpointMiddleware, SimpleMiddleware, EndpointInfo } from './object-handlers';
|
|
6
6
|
export { File as UploadedFile } from './router';
|
|
7
7
|
export { z as ZodSchema } from 'zod';
|
|
8
8
|
|
package/src/object-handlers.ts
CHANGED
|
@@ -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,
|
|
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
|
|
|
@@ -136,21 +136,6 @@ export function RegisterHandlers<
|
|
|
136
136
|
registerRouteHandlers(app, apiDefinition, handlerArray, endpointMiddlewares);
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
// Helper function to create typed handlers with proper type inference
|
|
140
|
-
export function createTypedHandler<
|
|
141
|
-
TDef extends ApiDefinitionSchema,
|
|
142
|
-
TDomain extends keyof TDef['endpoints'],
|
|
143
|
-
TRouteKey extends keyof TDef['endpoints'][TDomain],
|
|
144
|
-
Ctx extends Record<string, any> = Record<string, any>
|
|
145
|
-
>(
|
|
146
|
-
handler: (
|
|
147
|
-
req: TypedRequest<TDef, TDomain, TRouteKey, any, any, any, any, Ctx>,
|
|
148
|
-
res: TypedResponse<TDef, TDomain, TRouteKey>
|
|
149
|
-
) => Promise<void> | void
|
|
150
|
-
) {
|
|
151
|
-
return handler;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
139
|
// Factory function to create a typed handler registrar for a specific API definition
|
|
155
140
|
export function makeObjectHandlerRegistrar<TDef extends ApiDefinitionSchema>(
|
|
156
141
|
apiDefinition: TDef
|
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,
|
|
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
|
) {
|