33 getRouteMetadata ,
44 stripRouteMetadata ,
55 type RouteMetadata ,
6- type RouteMetadataMarker ,
76} from './metadata.js'
87import type { RawBodySchema , RouteSchema } from './types/schema.js'
98
@@ -59,8 +58,6 @@ export type HttpNode = HttpAction | HttpResource
5958/** Route tree accepted by HTTP clients and routers. */
6059export type HttpRouteTree = { [ key : string ] : HttpNode }
6160
62- type RouteDeclaration < T extends object > = T & Partial < RouteMetadataMarker >
63-
6461type StringKeys < T > = Pick < T , Extract < keyof T , string > >
6562
6663/**
@@ -75,7 +72,7 @@ export function resource<
7572 const TChildren extends HttpRouteTree ,
7673> (
7774 path : P ,
78- children : RouteDeclaration < TChildren >
75+ children : TChildren
7976) : HttpResource < P , StringKeys < TChildren > > {
8077 const metadata = getRouteMetadata ( children )
8178 return {
@@ -89,74 +86,74 @@ export function resource<
8986/** Declare a GET action, optionally with an action-local path segment. */
9087export function get < const P extends string , const T extends RouteSchema > (
9188 path : P ,
92- schema : RouteDeclaration < T >
89+ schema : T
9390) : HttpAction < P , T , 'GET' >
9491export function get < const T extends RouteSchema > (
95- schema : RouteDeclaration < T >
92+ schema : T
9693) : HttpAction < '' , T , 'GET' >
9794export function get (
98- pathOrSchema : string | RouteDeclaration < RouteSchema > ,
99- schema ?: RouteDeclaration < RouteSchema >
95+ pathOrSchema : string | RouteSchema ,
96+ schema ?: RouteSchema
10097) : any {
10198 return action ( 'GET' , pathOrSchema , schema )
10299}
103100
104101/** Declare a POST action, optionally with an action-local path segment. */
105102export function post < const P extends string , const T extends RouteSchema > (
106103 path : P ,
107- schema : RouteDeclaration < T >
104+ schema : T
108105) : HttpAction < P , T , 'POST' >
109106export function post < const T extends RouteSchema > (
110- schema : RouteDeclaration < T >
107+ schema : T
111108) : HttpAction < '' , T , 'POST' >
112109export function post (
113- pathOrSchema : string | RouteDeclaration < RouteSchema > ,
114- schema ?: RouteDeclaration < RouteSchema >
110+ pathOrSchema : string | RouteSchema ,
111+ schema ?: RouteSchema
115112) : any {
116113 return action ( 'POST' , pathOrSchema , schema )
117114}
118115
119116/** Declare a PUT action, optionally with an action-local path segment. */
120117export function put < const P extends string , const T extends RouteSchema > (
121118 path : P ,
122- schema : RouteDeclaration < T >
119+ schema : T
123120) : HttpAction < P , T , 'PUT' >
124121export function put < const T extends RouteSchema > (
125- schema : RouteDeclaration < T >
122+ schema : T
126123) : HttpAction < '' , T , 'PUT' >
127124export function put (
128- pathOrSchema : string | RouteDeclaration < RouteSchema > ,
129- schema ?: RouteDeclaration < RouteSchema >
125+ pathOrSchema : string | RouteSchema ,
126+ schema ?: RouteSchema
130127) : any {
131128 return action ( 'PUT' , pathOrSchema , schema )
132129}
133130
134131/** Declare a PATCH action, optionally with an action-local path segment. */
135132export function patch < const P extends string , const T extends RouteSchema > (
136133 path : P ,
137- schema : RouteDeclaration < T >
134+ schema : T
138135) : HttpAction < P , T , 'PATCH' >
139136export function patch < const T extends RouteSchema > (
140- schema : RouteDeclaration < T >
137+ schema : T
141138) : HttpAction < '' , T , 'PATCH' >
142139export function patch (
143- pathOrSchema : string | RouteDeclaration < RouteSchema > ,
144- schema ?: RouteDeclaration < RouteSchema >
140+ pathOrSchema : string | RouteSchema ,
141+ schema ?: RouteSchema
145142) : any {
146143 return action ( 'PATCH' , pathOrSchema , schema )
147144}
148145
149146/** Declare a DELETE action, optionally with an action-local path segment. */
150147function deleteAction < const P extends string , const T extends RouteSchema > (
151148 path : P ,
152- schema : RouteDeclaration < T >
149+ schema : T
153150) : HttpAction < P , T , 'DELETE' >
154151function deleteAction < const T extends RouteSchema > (
155- schema : RouteDeclaration < T >
152+ schema : T
156153) : HttpAction < '' , T , 'DELETE' >
157154function deleteAction (
158- pathOrSchema : string | RouteDeclaration < RouteSchema > ,
159- schema ?: RouteDeclaration < RouteSchema >
155+ pathOrSchema : string | RouteSchema ,
156+ schema ?: RouteSchema
160157) : any {
161158 return action ( 'DELETE' , pathOrSchema , schema )
162159}
@@ -182,8 +179,8 @@ export function isRawBodySchema(schema: unknown): schema is RawBodySchema {
182179
183180function action (
184181 method : HttpMethod ,
185- pathOrSchema : string | RouteDeclaration < RouteSchema > ,
186- schema ?: RouteDeclaration < RouteSchema >
182+ pathOrSchema : string | RouteSchema ,
183+ schema ?: RouteSchema
187184) {
188185 const path =
189186 typeof pathOrSchema === 'string'
0 commit comments