Skip to content

Commit 6c8627f

Browse files
committed
feat: add typescript-nextjs
1 parent 775be90 commit 6c8627f

File tree

11 files changed

+986
-2
lines changed

11 files changed

+986
-2
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/** AUTOGENERATED - DO NOT EDIT **/
2+
/* tslint:disable */
3+
/* eslint-disable */
4+
5+
import {
6+
t_CreateTodoListItemBodySchema,
7+
t_CreateTodoListItemParamSchema,
8+
t_GetTodoListItemsParamSchema,
9+
} from "../../../../../lib/models"
10+
import {
11+
KoaRuntimeError,
12+
RequestInputType,
13+
} from "@nahkies/typescript-koa-runtime/errors"
14+
import {
15+
KoaRuntimeResponder,
16+
KoaRuntimeResponse,
17+
StatusCode,
18+
StatusCode5xx,
19+
} from "@nahkies/typescript-koa-runtime/server"
20+
import { Params, parseRequestInput } from "@nahkies/typescript-koa-runtime/zod"
21+
import { NextRequest } from "next/server"
22+
import { z } from "zod"
23+
24+
//region safe-edit-region-header
25+
26+
//endregion safe-edit-region-header
27+
export type GetTodoListItemsResponder = {
28+
with200(): KoaRuntimeResponse<{
29+
completedAt?: string
30+
content: string
31+
createdAt: string
32+
id: string
33+
}>
34+
withStatusCode5xx(status: StatusCode5xx): KoaRuntimeResponse<{
35+
code: string
36+
message: string
37+
}>
38+
} & KoaRuntimeResponder
39+
40+
export type GetTodoListItems = (
41+
params: Params<t_GetTodoListItemsParamSchema, void, void>,
42+
respond: GetTodoListItemsResponder,
43+
ctx: { request: NextRequest },
44+
) => Promise<KoaRuntimeResponse<unknown>>
45+
46+
export type CreateTodoListItemResponder = {
47+
with204(): KoaRuntimeResponse<void>
48+
} & KoaRuntimeResponder
49+
50+
export type CreateTodoListItem = (
51+
params: Params<
52+
t_CreateTodoListItemParamSchema,
53+
void,
54+
t_CreateTodoListItemBodySchema
55+
>,
56+
respond: CreateTodoListItemResponder,
57+
ctx: { request: NextRequest },
58+
) => Promise<KoaRuntimeResponse<unknown>>
59+
60+
const getTodoListItemsParamSchema = z.object({ listId: z.string() })
61+
62+
export const GET = async (
63+
request: NextRequest,
64+
{ params }: { params: unknown },
65+
): Promise<Response> => {
66+
const input = {
67+
params: parseRequestInput(
68+
getTodoListItemsParamSchema,
69+
params,
70+
RequestInputType.RouteParam,
71+
),
72+
// TODO: this swallows repeated parameters
73+
query: undefined,
74+
body: undefined,
75+
}
76+
77+
const responder = {
78+
with200() {
79+
return new KoaRuntimeResponse<{
80+
completedAt?: string
81+
content: string
82+
createdAt: string
83+
id: string
84+
}>(200)
85+
},
86+
withStatusCode5xx(status: StatusCode5xx) {
87+
return new KoaRuntimeResponse<{
88+
code: string
89+
message: string
90+
}>(status)
91+
},
92+
withStatus(status: StatusCode) {
93+
return new KoaRuntimeResponse(status)
94+
},
95+
}
96+
97+
const { status, body } = await import("@/lib/api/list/[listId]/items/route")
98+
.then((it) => it.GET(input, responder, { request }))
99+
.then((it) => it.unpack())
100+
.catch((err) => {
101+
throw KoaRuntimeError.HandlerError(err)
102+
})
103+
104+
return Response.json(body, { status })
105+
}
106+
107+
const createTodoListItemParamSchema = z.object({ listId: z.string() })
108+
109+
const createTodoListItemBodySchema = z.object({
110+
id: z.string(),
111+
content: z.string(),
112+
completedAt: z.string().datetime({ offset: true }).optional(),
113+
})
114+
115+
export const POST = async (
116+
request: NextRequest,
117+
{ params }: { params: unknown },
118+
): Promise<Response> => {
119+
const input = {
120+
params: parseRequestInput(
121+
createTodoListItemParamSchema,
122+
params,
123+
RequestInputType.RouteParam,
124+
),
125+
// TODO: this swallows repeated parameters
126+
query: undefined,
127+
body: parseRequestInput(
128+
createTodoListItemBodySchema,
129+
await request.json(),
130+
RequestInputType.RequestBody,
131+
),
132+
}
133+
134+
const responder = {
135+
with204() {
136+
return new KoaRuntimeResponse<void>(204)
137+
},
138+
withStatus(status: StatusCode) {
139+
return new KoaRuntimeResponse(status)
140+
},
141+
}
142+
143+
const { status, body } = await import("@/lib/api/list/[listId]/items/route")
144+
.then((it) => it.GET(input, responder, { request }))
145+
.then((it) => it.unpack())
146+
.catch((err) => {
147+
throw KoaRuntimeError.HandlerError(err)
148+
})
149+
150+
return Response.json(body, { status })
151+
}
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
/** AUTOGENERATED - DO NOT EDIT **/
2+
/* tslint:disable */
3+
/* eslint-disable */
4+
5+
import {
6+
t_DeleteTodoListByIdParamSchema,
7+
t_Error,
8+
t_GetTodoListByIdParamSchema,
9+
t_TodoList,
10+
t_UpdateTodoListByIdBodySchema,
11+
t_UpdateTodoListByIdParamSchema,
12+
} from "../../../../lib/models"
13+
import { s_CreateUpdateTodoList } from "../../../../lib/schemas"
14+
import {
15+
KoaRuntimeError,
16+
RequestInputType,
17+
} from "@nahkies/typescript-koa-runtime/errors"
18+
import {
19+
KoaRuntimeResponder,
20+
KoaRuntimeResponse,
21+
StatusCode,
22+
StatusCode4xx,
23+
} from "@nahkies/typescript-koa-runtime/server"
24+
import { Params, parseRequestInput } from "@nahkies/typescript-koa-runtime/zod"
25+
import { NextRequest } from "next/server"
26+
import { z } from "zod"
27+
28+
//region safe-edit-region-header
29+
30+
//endregion safe-edit-region-header
31+
export type GetTodoListByIdResponder = {
32+
with200(): KoaRuntimeResponse<t_TodoList>
33+
withStatusCode4xx(status: StatusCode4xx): KoaRuntimeResponse<t_Error>
34+
withDefault(status: StatusCode): KoaRuntimeResponse<void>
35+
} & KoaRuntimeResponder
36+
37+
export type GetTodoListById = (
38+
params: Params<t_GetTodoListByIdParamSchema, void, void>,
39+
respond: GetTodoListByIdResponder,
40+
ctx: { request: NextRequest },
41+
) => Promise<KoaRuntimeResponse<unknown>>
42+
43+
export type UpdateTodoListByIdResponder = {
44+
with200(): KoaRuntimeResponse<t_TodoList>
45+
withStatusCode4xx(status: StatusCode4xx): KoaRuntimeResponse<t_Error>
46+
withDefault(status: StatusCode): KoaRuntimeResponse<void>
47+
} & KoaRuntimeResponder
48+
49+
export type UpdateTodoListById = (
50+
params: Params<
51+
t_UpdateTodoListByIdParamSchema,
52+
void,
53+
t_UpdateTodoListByIdBodySchema
54+
>,
55+
respond: UpdateTodoListByIdResponder,
56+
ctx: { request: NextRequest },
57+
) => Promise<KoaRuntimeResponse<unknown>>
58+
59+
export type DeleteTodoListByIdResponder = {
60+
with204(): KoaRuntimeResponse<void>
61+
withStatusCode4xx(status: StatusCode4xx): KoaRuntimeResponse<t_Error>
62+
withDefault(status: StatusCode): KoaRuntimeResponse<void>
63+
} & KoaRuntimeResponder
64+
65+
export type DeleteTodoListById = (
66+
params: Params<t_DeleteTodoListByIdParamSchema, void, void>,
67+
respond: DeleteTodoListByIdResponder,
68+
ctx: { request: NextRequest },
69+
) => Promise<KoaRuntimeResponse<unknown>>
70+
71+
const getTodoListByIdParamSchema = z.object({ listId: z.string() })
72+
73+
export const GET = async (
74+
request: NextRequest,
75+
{ params }: { params: unknown },
76+
): Promise<Response> => {
77+
const input = {
78+
params: parseRequestInput(
79+
getTodoListByIdParamSchema,
80+
params,
81+
RequestInputType.RouteParam,
82+
),
83+
// TODO: this swallows repeated parameters
84+
query: undefined,
85+
body: undefined,
86+
}
87+
88+
const responder = {
89+
with200() {
90+
return new KoaRuntimeResponse<t_TodoList>(200)
91+
},
92+
withStatusCode4xx(status: StatusCode4xx) {
93+
return new KoaRuntimeResponse<t_Error>(status)
94+
},
95+
withDefault(status: StatusCode) {
96+
return new KoaRuntimeResponse<void>(status)
97+
},
98+
withStatus(status: StatusCode) {
99+
return new KoaRuntimeResponse(status)
100+
},
101+
}
102+
103+
const { status, body } = await import("@/lib/api/list/[listId]/route")
104+
.then((it) => it.GET(input, responder, { request }))
105+
.then((it) => it.unpack())
106+
.catch((err) => {
107+
throw KoaRuntimeError.HandlerError(err)
108+
})
109+
110+
return Response.json(body, { status })
111+
}
112+
113+
const updateTodoListByIdParamSchema = z.object({ listId: z.string() })
114+
115+
const updateTodoListByIdBodySchema = s_CreateUpdateTodoList
116+
117+
export const PUT = async (
118+
request: NextRequest,
119+
{ params }: { params: unknown },
120+
): Promise<Response> => {
121+
const input = {
122+
params: parseRequestInput(
123+
updateTodoListByIdParamSchema,
124+
params,
125+
RequestInputType.RouteParam,
126+
),
127+
// TODO: this swallows repeated parameters
128+
query: undefined,
129+
body: parseRequestInput(
130+
updateTodoListByIdBodySchema,
131+
await request.json(),
132+
RequestInputType.RequestBody,
133+
),
134+
}
135+
136+
const responder = {
137+
with200() {
138+
return new KoaRuntimeResponse<t_TodoList>(200)
139+
},
140+
withStatusCode4xx(status: StatusCode4xx) {
141+
return new KoaRuntimeResponse<t_Error>(status)
142+
},
143+
withDefault(status: StatusCode) {
144+
return new KoaRuntimeResponse<void>(status)
145+
},
146+
withStatus(status: StatusCode) {
147+
return new KoaRuntimeResponse(status)
148+
},
149+
}
150+
151+
const { status, body } = await import("@/lib/api/list/[listId]/route")
152+
.then((it) => it.GET(input, responder, { request }))
153+
.then((it) => it.unpack())
154+
.catch((err) => {
155+
throw KoaRuntimeError.HandlerError(err)
156+
})
157+
158+
return Response.json(body, { status })
159+
}
160+
161+
const deleteTodoListByIdParamSchema = z.object({ listId: z.string() })
162+
163+
export const DELETE = async (
164+
request: NextRequest,
165+
{ params }: { params: unknown },
166+
): Promise<Response> => {
167+
const input = {
168+
params: parseRequestInput(
169+
deleteTodoListByIdParamSchema,
170+
params,
171+
RequestInputType.RouteParam,
172+
),
173+
// TODO: this swallows repeated parameters
174+
query: undefined,
175+
body: undefined,
176+
}
177+
178+
const responder = {
179+
with204() {
180+
return new KoaRuntimeResponse<void>(204)
181+
},
182+
withStatusCode4xx(status: StatusCode4xx) {
183+
return new KoaRuntimeResponse<t_Error>(status)
184+
},
185+
withDefault(status: StatusCode) {
186+
return new KoaRuntimeResponse<void>(status)
187+
},
188+
withStatus(status: StatusCode) {
189+
return new KoaRuntimeResponse(status)
190+
},
191+
}
192+
193+
const { status, body } = await import("@/lib/api/list/[listId]/route")
194+
.then((it) => it.GET(input, responder, { request }))
195+
.then((it) => it.unpack())
196+
.catch((err) => {
197+
throw KoaRuntimeError.HandlerError(err)
198+
})
199+
200+
return Response.json(body, { status })
201+
}

0 commit comments

Comments
 (0)