@nubase/backend 0.1.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/dist/index.d.mts +34 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +104 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +76 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +42 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as hono from 'hono';
|
|
2
|
+
import { Context } from 'hono';
|
|
3
|
+
import { RequestSchema, InferRequestParams, InferRequestBody, InferResponseBody } from '@nubase/core';
|
|
4
|
+
|
|
5
|
+
type TypedHandlerContext<T extends RequestSchema> = {
|
|
6
|
+
params: InferRequestParams<T>;
|
|
7
|
+
body: InferRequestBody<T>;
|
|
8
|
+
ctx: Context;
|
|
9
|
+
};
|
|
10
|
+
type TypedHandler<T extends RequestSchema> = (context: TypedHandlerContext<T>) => Promise<InferResponseBody<T>>;
|
|
11
|
+
declare function createTypedHandler<T extends RequestSchema>(schema: T, handler: TypedHandler<T>): ReturnType<typeof createTypedHandlerInternal>;
|
|
12
|
+
declare function createTypedHandler<T extends RequestSchema>(endpointRef: T, // Can be apiEndpoints.ticketsGetTickets
|
|
13
|
+
handler: TypedHandler<T>): ReturnType<typeof createTypedHandlerInternal>;
|
|
14
|
+
declare function createTypedHandlerInternal<T extends RequestSchema>(schema: T, handler: TypedHandler<T>): (c: Context) => Promise<(Response & hono.TypedResponse<{
|
|
15
|
+
error: string;
|
|
16
|
+
details: string;
|
|
17
|
+
}, 400, "json">) | (Response & hono.TypedResponse<any, 200 | 201, "json">) | (Response & hono.TypedResponse<{
|
|
18
|
+
error: string;
|
|
19
|
+
details: string;
|
|
20
|
+
}, 500, "json">)>;
|
|
21
|
+
type TypedRouteDefinition<T extends RequestSchema> = {
|
|
22
|
+
schema: T;
|
|
23
|
+
handler: TypedHandler<T>;
|
|
24
|
+
};
|
|
25
|
+
type TypedRoutes = Record<string, TypedRouteDefinition<any>>;
|
|
26
|
+
declare function createTypedRoutes<T extends TypedRoutes>(routes: T): Record<string, (c: Context) => Promise<(Response & hono.TypedResponse<any, 200 | 201, "json">) | (Response & hono.TypedResponse<{
|
|
27
|
+
error: string;
|
|
28
|
+
details: string;
|
|
29
|
+
}, 400, "json">) | (Response & hono.TypedResponse<{
|
|
30
|
+
error: string;
|
|
31
|
+
details: string;
|
|
32
|
+
}, 500, "json">)>>;
|
|
33
|
+
|
|
34
|
+
export { type TypedHandler, type TypedHandlerContext, type TypedRouteDefinition, type TypedRoutes, createTypedHandler, createTypedRoutes };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as hono from 'hono';
|
|
2
|
+
import { Context } from 'hono';
|
|
3
|
+
import { RequestSchema, InferRequestParams, InferRequestBody, InferResponseBody } from '@nubase/core';
|
|
4
|
+
|
|
5
|
+
type TypedHandlerContext<T extends RequestSchema> = {
|
|
6
|
+
params: InferRequestParams<T>;
|
|
7
|
+
body: InferRequestBody<T>;
|
|
8
|
+
ctx: Context;
|
|
9
|
+
};
|
|
10
|
+
type TypedHandler<T extends RequestSchema> = (context: TypedHandlerContext<T>) => Promise<InferResponseBody<T>>;
|
|
11
|
+
declare function createTypedHandler<T extends RequestSchema>(schema: T, handler: TypedHandler<T>): ReturnType<typeof createTypedHandlerInternal>;
|
|
12
|
+
declare function createTypedHandler<T extends RequestSchema>(endpointRef: T, // Can be apiEndpoints.ticketsGetTickets
|
|
13
|
+
handler: TypedHandler<T>): ReturnType<typeof createTypedHandlerInternal>;
|
|
14
|
+
declare function createTypedHandlerInternal<T extends RequestSchema>(schema: T, handler: TypedHandler<T>): (c: Context) => Promise<(Response & hono.TypedResponse<{
|
|
15
|
+
error: string;
|
|
16
|
+
details: string;
|
|
17
|
+
}, 400, "json">) | (Response & hono.TypedResponse<any, 200 | 201, "json">) | (Response & hono.TypedResponse<{
|
|
18
|
+
error: string;
|
|
19
|
+
details: string;
|
|
20
|
+
}, 500, "json">)>;
|
|
21
|
+
type TypedRouteDefinition<T extends RequestSchema> = {
|
|
22
|
+
schema: T;
|
|
23
|
+
handler: TypedHandler<T>;
|
|
24
|
+
};
|
|
25
|
+
type TypedRoutes = Record<string, TypedRouteDefinition<any>>;
|
|
26
|
+
declare function createTypedRoutes<T extends TypedRoutes>(routes: T): Record<string, (c: Context) => Promise<(Response & hono.TypedResponse<any, 200 | 201, "json">) | (Response & hono.TypedResponse<{
|
|
27
|
+
error: string;
|
|
28
|
+
details: string;
|
|
29
|
+
}, 400, "json">) | (Response & hono.TypedResponse<{
|
|
30
|
+
error: string;
|
|
31
|
+
details: string;
|
|
32
|
+
}, 500, "json">)>>;
|
|
33
|
+
|
|
34
|
+
export { type TypedHandler, type TypedHandlerContext, type TypedRouteDefinition, type TypedRoutes, createTypedHandler, createTypedRoutes };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
createTypedHandler: () => createTypedHandler,
|
|
24
|
+
createTypedRoutes: () => createTypedRoutes
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/typed-handlers.ts
|
|
29
|
+
function createTypedHandler(schemaOrEndpoint, handler) {
|
|
30
|
+
return createTypedHandlerInternal(schemaOrEndpoint, handler);
|
|
31
|
+
}
|
|
32
|
+
function createTypedHandlerInternal(schema, handler) {
|
|
33
|
+
return async (c) => {
|
|
34
|
+
try {
|
|
35
|
+
let params;
|
|
36
|
+
try {
|
|
37
|
+
const rawParams = c.req.param();
|
|
38
|
+
params = schema.requestParams.parse(rawParams);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
return c.json(
|
|
41
|
+
{
|
|
42
|
+
error: "Invalid request parameters",
|
|
43
|
+
details: error instanceof Error ? error.message : String(error)
|
|
44
|
+
},
|
|
45
|
+
400
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
let body;
|
|
49
|
+
try {
|
|
50
|
+
const rawBody = schema.method === "GET" ? {} : await c.req.json();
|
|
51
|
+
body = schema.requestBody.parse(rawBody);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
return c.json(
|
|
54
|
+
{
|
|
55
|
+
error: "Invalid request body",
|
|
56
|
+
details: error instanceof Error ? error.message : String(error)
|
|
57
|
+
},
|
|
58
|
+
400
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
const result = await handler({
|
|
62
|
+
params,
|
|
63
|
+
body,
|
|
64
|
+
ctx: c
|
|
65
|
+
});
|
|
66
|
+
try {
|
|
67
|
+
const validatedResult = schema.responseBody.parse(result);
|
|
68
|
+
const statusCode = schema.method === "POST" ? 201 : 200;
|
|
69
|
+
return c.json(validatedResult, statusCode);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.error("Response validation failed:", error);
|
|
72
|
+
return c.json(
|
|
73
|
+
{
|
|
74
|
+
error: "Internal server error",
|
|
75
|
+
details: "Response validation failed"
|
|
76
|
+
},
|
|
77
|
+
500
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error("Handler error:", error);
|
|
82
|
+
return c.json(
|
|
83
|
+
{
|
|
84
|
+
error: "Internal server error",
|
|
85
|
+
details: error instanceof Error ? error.message : String(error)
|
|
86
|
+
},
|
|
87
|
+
500
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function createTypedRoutes(routes) {
|
|
93
|
+
const honoHandlers = {};
|
|
94
|
+
for (const [routeName, { schema, handler }] of Object.entries(routes)) {
|
|
95
|
+
honoHandlers[routeName] = createTypedHandler(schema, handler);
|
|
96
|
+
}
|
|
97
|
+
return honoHandlers;
|
|
98
|
+
}
|
|
99
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
100
|
+
0 && (module.exports = {
|
|
101
|
+
createTypedHandler,
|
|
102
|
+
createTypedRoutes
|
|
103
|
+
});
|
|
104
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/typed-handlers.ts"],"sourcesContent":["export * from \"./typed-handlers\";\n","import type {\n InferRequestBody,\n InferRequestParams,\n InferResponseBody,\n RequestSchema,\n} from \"@nubase/core\";\nimport type { Context } from \"hono\";\n\nexport type TypedHandlerContext<T extends RequestSchema> = {\n params: InferRequestParams<T>;\n body: InferRequestBody<T>;\n ctx: Context;\n};\n\nexport type TypedHandler<T extends RequestSchema> = (\n context: TypedHandlerContext<T>,\n) => Promise<InferResponseBody<T>>;\n\n// Overloaded function signatures for better ergonomics\nexport function createTypedHandler<T extends RequestSchema>(\n schema: T,\n handler: TypedHandler<T>,\n): ReturnType<typeof createTypedHandlerInternal>;\n\nexport function createTypedHandler<T extends RequestSchema>(\n endpointRef: T, // Can be apiEndpoints.ticketsGetTickets\n handler: TypedHandler<T>,\n): ReturnType<typeof createTypedHandlerInternal>;\n\nexport function createTypedHandler<T extends RequestSchema>(\n schemaOrEndpoint: T,\n handler: TypedHandler<T>,\n) {\n return createTypedHandlerInternal(schemaOrEndpoint, handler);\n}\n\n// Internal implementation\nfunction createTypedHandlerInternal<T extends RequestSchema>(\n schema: T,\n handler: TypedHandler<T>,\n) {\n return async (c: Context) => {\n try {\n // Parse and validate request parameters\n let params: InferRequestParams<T>;\n try {\n const rawParams = c.req.param();\n params = schema.requestParams.parse(rawParams) as InferRequestParams<T>;\n } catch (error) {\n return c.json(\n {\n error: \"Invalid request parameters\",\n details: error instanceof Error ? error.message : String(error),\n },\n 400,\n );\n }\n\n // Parse and validate request body\n let body: InferRequestBody<T>;\n try {\n const rawBody = schema.method === \"GET\" ? {} : await c.req.json();\n body = schema.requestBody.parse(rawBody) as InferRequestBody<T>;\n } catch (error) {\n return c.json(\n {\n error: \"Invalid request body\",\n details: error instanceof Error ? error.message : String(error),\n },\n 400,\n );\n }\n\n // Call the handler with typed context\n const result = await handler({\n params,\n body,\n ctx: c,\n });\n\n // Validate response body (optional, for development safety)\n try {\n const validatedResult = schema.responseBody.parse(result);\n\n // Return appropriate status code based on method\n const statusCode = schema.method === \"POST\" ? 201 : 200;\n return c.json(validatedResult, statusCode);\n } catch (error) {\n console.error(\"Response validation failed:\", error);\n // In production, you might want to return the result anyway\n // For development, this helps catch schema mismatches\n return c.json(\n {\n error: \"Internal server error\",\n details: \"Response validation failed\",\n },\n 500,\n );\n }\n } catch (error) {\n console.error(\"Handler error:\", error);\n return c.json(\n {\n error: \"Internal server error\",\n details: error instanceof Error ? error.message : String(error),\n },\n 500,\n );\n }\n };\n}\n\nexport type TypedRouteDefinition<T extends RequestSchema> = {\n schema: T;\n handler: TypedHandler<T>;\n};\n\nexport type TypedRoutes = Record<string, TypedRouteDefinition<any>>;\n\nexport function createTypedRoutes<T extends TypedRoutes>(routes: T) {\n const honoHandlers: Record<\n string,\n ReturnType<typeof createTypedHandler>\n > = {};\n\n for (const [routeName, { schema, handler }] of Object.entries(routes)) {\n honoHandlers[routeName] = createTypedHandler(schema, handler);\n }\n\n return honoHandlers;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC6BO,SAAS,mBACd,kBACA,SACA;AACA,SAAO,2BAA2B,kBAAkB,OAAO;AAC7D;AAGA,SAAS,2BACP,QACA,SACA;AACA,SAAO,OAAO,MAAe;AAC3B,QAAI;AAEF,UAAI;AACJ,UAAI;AACF,cAAM,YAAY,EAAE,IAAI,MAAM;AAC9B,iBAAS,OAAO,cAAc,MAAM,SAAS;AAAA,MAC/C,SAAS,OAAO;AACd,eAAO,EAAE;AAAA,UACP;AAAA,YACE,OAAO;AAAA,YACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,UAChE;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAGA,UAAI;AACJ,UAAI;AACF,cAAM,UAAU,OAAO,WAAW,QAAQ,CAAC,IAAI,MAAM,EAAE,IAAI,KAAK;AAChE,eAAO,OAAO,YAAY,MAAM,OAAO;AAAA,MACzC,SAAS,OAAO;AACd,eAAO,EAAE;AAAA,UACP;AAAA,YACE,OAAO;AAAA,YACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,UAChE;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAGA,YAAM,SAAS,MAAM,QAAQ;AAAA,QAC3B;AAAA,QACA;AAAA,QACA,KAAK;AAAA,MACP,CAAC;AAGD,UAAI;AACF,cAAM,kBAAkB,OAAO,aAAa,MAAM,MAAM;AAGxD,cAAM,aAAa,OAAO,WAAW,SAAS,MAAM;AACpD,eAAO,EAAE,KAAK,iBAAiB,UAAU;AAAA,MAC3C,SAAS,OAAO;AACd,gBAAQ,MAAM,+BAA+B,KAAK;AAGlD,eAAO,EAAE;AAAA,UACP;AAAA,YACE,OAAO;AAAA,YACP,SAAS;AAAA,UACX;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF,SAAS,OAAO;AACd,cAAQ,MAAM,kBAAkB,KAAK;AACrC,aAAO,EAAE;AAAA,QACP;AAAA,UACE,OAAO;AAAA,UACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,QAChE;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AASO,SAAS,kBAAyC,QAAW;AAClE,QAAM,eAGF,CAAC;AAEL,aAAW,CAAC,WAAW,EAAE,QAAQ,QAAQ,CAAC,KAAK,OAAO,QAAQ,MAAM,GAAG;AACrE,iBAAa,SAAS,IAAI,mBAAmB,QAAQ,OAAO;AAAA,EAC9D;AAEA,SAAO;AACT;","names":[]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// src/typed-handlers.ts
|
|
2
|
+
function createTypedHandler(schemaOrEndpoint, handler) {
|
|
3
|
+
return createTypedHandlerInternal(schemaOrEndpoint, handler);
|
|
4
|
+
}
|
|
5
|
+
function createTypedHandlerInternal(schema, handler) {
|
|
6
|
+
return async (c) => {
|
|
7
|
+
try {
|
|
8
|
+
let params;
|
|
9
|
+
try {
|
|
10
|
+
const rawParams = c.req.param();
|
|
11
|
+
params = schema.requestParams.parse(rawParams);
|
|
12
|
+
} catch (error) {
|
|
13
|
+
return c.json(
|
|
14
|
+
{
|
|
15
|
+
error: "Invalid request parameters",
|
|
16
|
+
details: error instanceof Error ? error.message : String(error)
|
|
17
|
+
},
|
|
18
|
+
400
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
let body;
|
|
22
|
+
try {
|
|
23
|
+
const rawBody = schema.method === "GET" ? {} : await c.req.json();
|
|
24
|
+
body = schema.requestBody.parse(rawBody);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
return c.json(
|
|
27
|
+
{
|
|
28
|
+
error: "Invalid request body",
|
|
29
|
+
details: error instanceof Error ? error.message : String(error)
|
|
30
|
+
},
|
|
31
|
+
400
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
const result = await handler({
|
|
35
|
+
params,
|
|
36
|
+
body,
|
|
37
|
+
ctx: c
|
|
38
|
+
});
|
|
39
|
+
try {
|
|
40
|
+
const validatedResult = schema.responseBody.parse(result);
|
|
41
|
+
const statusCode = schema.method === "POST" ? 201 : 200;
|
|
42
|
+
return c.json(validatedResult, statusCode);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.error("Response validation failed:", error);
|
|
45
|
+
return c.json(
|
|
46
|
+
{
|
|
47
|
+
error: "Internal server error",
|
|
48
|
+
details: "Response validation failed"
|
|
49
|
+
},
|
|
50
|
+
500
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error("Handler error:", error);
|
|
55
|
+
return c.json(
|
|
56
|
+
{
|
|
57
|
+
error: "Internal server error",
|
|
58
|
+
details: error instanceof Error ? error.message : String(error)
|
|
59
|
+
},
|
|
60
|
+
500
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function createTypedRoutes(routes) {
|
|
66
|
+
const honoHandlers = {};
|
|
67
|
+
for (const [routeName, { schema, handler }] of Object.entries(routes)) {
|
|
68
|
+
honoHandlers[routeName] = createTypedHandler(schema, handler);
|
|
69
|
+
}
|
|
70
|
+
return honoHandlers;
|
|
71
|
+
}
|
|
72
|
+
export {
|
|
73
|
+
createTypedHandler,
|
|
74
|
+
createTypedRoutes
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/typed-handlers.ts"],"sourcesContent":["import type {\n InferRequestBody,\n InferRequestParams,\n InferResponseBody,\n RequestSchema,\n} from \"@nubase/core\";\nimport type { Context } from \"hono\";\n\nexport type TypedHandlerContext<T extends RequestSchema> = {\n params: InferRequestParams<T>;\n body: InferRequestBody<T>;\n ctx: Context;\n};\n\nexport type TypedHandler<T extends RequestSchema> = (\n context: TypedHandlerContext<T>,\n) => Promise<InferResponseBody<T>>;\n\n// Overloaded function signatures for better ergonomics\nexport function createTypedHandler<T extends RequestSchema>(\n schema: T,\n handler: TypedHandler<T>,\n): ReturnType<typeof createTypedHandlerInternal>;\n\nexport function createTypedHandler<T extends RequestSchema>(\n endpointRef: T, // Can be apiEndpoints.ticketsGetTickets\n handler: TypedHandler<T>,\n): ReturnType<typeof createTypedHandlerInternal>;\n\nexport function createTypedHandler<T extends RequestSchema>(\n schemaOrEndpoint: T,\n handler: TypedHandler<T>,\n) {\n return createTypedHandlerInternal(schemaOrEndpoint, handler);\n}\n\n// Internal implementation\nfunction createTypedHandlerInternal<T extends RequestSchema>(\n schema: T,\n handler: TypedHandler<T>,\n) {\n return async (c: Context) => {\n try {\n // Parse and validate request parameters\n let params: InferRequestParams<T>;\n try {\n const rawParams = c.req.param();\n params = schema.requestParams.parse(rawParams) as InferRequestParams<T>;\n } catch (error) {\n return c.json(\n {\n error: \"Invalid request parameters\",\n details: error instanceof Error ? error.message : String(error),\n },\n 400,\n );\n }\n\n // Parse and validate request body\n let body: InferRequestBody<T>;\n try {\n const rawBody = schema.method === \"GET\" ? {} : await c.req.json();\n body = schema.requestBody.parse(rawBody) as InferRequestBody<T>;\n } catch (error) {\n return c.json(\n {\n error: \"Invalid request body\",\n details: error instanceof Error ? error.message : String(error),\n },\n 400,\n );\n }\n\n // Call the handler with typed context\n const result = await handler({\n params,\n body,\n ctx: c,\n });\n\n // Validate response body (optional, for development safety)\n try {\n const validatedResult = schema.responseBody.parse(result);\n\n // Return appropriate status code based on method\n const statusCode = schema.method === \"POST\" ? 201 : 200;\n return c.json(validatedResult, statusCode);\n } catch (error) {\n console.error(\"Response validation failed:\", error);\n // In production, you might want to return the result anyway\n // For development, this helps catch schema mismatches\n return c.json(\n {\n error: \"Internal server error\",\n details: \"Response validation failed\",\n },\n 500,\n );\n }\n } catch (error) {\n console.error(\"Handler error:\", error);\n return c.json(\n {\n error: \"Internal server error\",\n details: error instanceof Error ? error.message : String(error),\n },\n 500,\n );\n }\n };\n}\n\nexport type TypedRouteDefinition<T extends RequestSchema> = {\n schema: T;\n handler: TypedHandler<T>;\n};\n\nexport type TypedRoutes = Record<string, TypedRouteDefinition<any>>;\n\nexport function createTypedRoutes<T extends TypedRoutes>(routes: T) {\n const honoHandlers: Record<\n string,\n ReturnType<typeof createTypedHandler>\n > = {};\n\n for (const [routeName, { schema, handler }] of Object.entries(routes)) {\n honoHandlers[routeName] = createTypedHandler(schema, handler);\n }\n\n return honoHandlers;\n}\n"],"mappings":";AA6BO,SAAS,mBACd,kBACA,SACA;AACA,SAAO,2BAA2B,kBAAkB,OAAO;AAC7D;AAGA,SAAS,2BACP,QACA,SACA;AACA,SAAO,OAAO,MAAe;AAC3B,QAAI;AAEF,UAAI;AACJ,UAAI;AACF,cAAM,YAAY,EAAE,IAAI,MAAM;AAC9B,iBAAS,OAAO,cAAc,MAAM,SAAS;AAAA,MAC/C,SAAS,OAAO;AACd,eAAO,EAAE;AAAA,UACP;AAAA,YACE,OAAO;AAAA,YACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,UAChE;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAGA,UAAI;AACJ,UAAI;AACF,cAAM,UAAU,OAAO,WAAW,QAAQ,CAAC,IAAI,MAAM,EAAE,IAAI,KAAK;AAChE,eAAO,OAAO,YAAY,MAAM,OAAO;AAAA,MACzC,SAAS,OAAO;AACd,eAAO,EAAE;AAAA,UACP;AAAA,YACE,OAAO;AAAA,YACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,UAChE;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAGA,YAAM,SAAS,MAAM,QAAQ;AAAA,QAC3B;AAAA,QACA;AAAA,QACA,KAAK;AAAA,MACP,CAAC;AAGD,UAAI;AACF,cAAM,kBAAkB,OAAO,aAAa,MAAM,MAAM;AAGxD,cAAM,aAAa,OAAO,WAAW,SAAS,MAAM;AACpD,eAAO,EAAE,KAAK,iBAAiB,UAAU;AAAA,MAC3C,SAAS,OAAO;AACd,gBAAQ,MAAM,+BAA+B,KAAK;AAGlD,eAAO,EAAE;AAAA,UACP;AAAA,YACE,OAAO;AAAA,YACP,SAAS;AAAA,UACX;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF,SAAS,OAAO;AACd,cAAQ,MAAM,kBAAkB,KAAK;AACrC,aAAO,EAAE;AAAA,QACP;AAAA,UACE,OAAO;AAAA,UACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,QAChE;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AASO,SAAS,kBAAyC,QAAW;AAClE,QAAM,eAGF,CAAC;AAEL,aAAW,CAAC,WAAW,EAAE,QAAQ,QAAQ,CAAC,KAAK,OAAO,QAAQ,MAAM,GAAG;AACrE,iBAAa,SAAS,IAAI,mBAAmB,QAAQ,OAAO;AAAA,EAC9D;AAEA,SAAO;AACT;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nubase/backend",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Backend utilities and typed handlers for nubase",
|
|
5
|
+
"keywords": ["backend", "handlers", "api", "typescript"],
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"files": ["dist"],
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsup",
|
|
21
|
+
"test": "vitest run --reporter=verbose --passWithNoTests",
|
|
22
|
+
"check-types": "tsc --noEmit",
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"lint": "biome check .",
|
|
25
|
+
"lint:fix": "biome check . --write --unsafe",
|
|
26
|
+
"prepublishOnly": "npm run build",
|
|
27
|
+
"publish": "npm publish",
|
|
28
|
+
"watch": "tsup --watch",
|
|
29
|
+
"dev": "tsup --watch"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"hono": "^4"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"tsup": "^8.0.0",
|
|
36
|
+
"typescript": "5.8.2",
|
|
37
|
+
"vitest": "^3.1.4"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@nubase/core": "*"
|
|
41
|
+
}
|
|
42
|
+
}
|