jax-hono 1.0.5 → 1.0.7
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/helpers/crud.ts +5 -1
- package/middleware/api-response.ts +2 -2
- package/package.json +1 -1
package/helpers/crud.ts
CHANGED
|
@@ -10,7 +10,11 @@ export type JaxCrudController = {
|
|
|
10
10
|
destroy?: Handler;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export function registerCrudRoutes
|
|
13
|
+
export function registerCrudRoutes<TApp extends Hono>(
|
|
14
|
+
app: TApp,
|
|
15
|
+
path: string,
|
|
16
|
+
controller: JaxCrudController
|
|
17
|
+
): TApp {
|
|
14
18
|
const basePath = normalizeRoutePath(path);
|
|
15
19
|
const detailPath = basePath === '/' ? '/:id' : `${basePath}/:id`;
|
|
16
20
|
const deleteHandler = controller.delete ?? controller.destroy;
|
|
@@ -13,7 +13,7 @@ export type ApiFailResponse = {
|
|
|
13
13
|
|
|
14
14
|
export type ApiResponse<T = unknown> = ApiSuccessResponse<T> | ApiFailResponse;
|
|
15
15
|
|
|
16
|
-
export function ok<T>(c: Context, data?: T, msg = 'success') {
|
|
16
|
+
export function ok<T>(c: Context, data?: T, msg = 'success'): Response {
|
|
17
17
|
return c.json<ApiSuccessResponse<T>>({
|
|
18
18
|
code: 0,
|
|
19
19
|
msg,
|
|
@@ -21,7 +21,7 @@ export function ok<T>(c: Context, data?: T, msg = 'success') {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export function fail(c: Context, msg: string) {
|
|
24
|
+
export function fail(c: Context, msg: string): Response {
|
|
25
25
|
return c.json<ApiFailResponse>({
|
|
26
26
|
code: 1,
|
|
27
27
|
msg
|