1+ /** @internal */
2+ import { Router as _router } from 'itty-router'
3+ import { HttpRequest } from './spinSdk'
4+
5+ declare type GenericTraps = {
6+ [ key : string ] : any ;
7+ } ;
8+
9+ export declare type RequestLike = {
10+ method : string ;
11+ url : string ;
12+ } & GenericTraps ;
13+
14+ declare type IRequest = {
15+ method : string ;
16+ url : string ;
17+ params : {
18+ [ key : string ] : string ;
19+ } ;
20+ query : {
21+ [ key : string ] : string | string [ ] | undefined ;
22+ } ;
23+ proxy ?: any ;
24+ } & GenericTraps ;
25+
26+ interface RouteHandler {
27+ ( request : IRequest , ...args : any ) : any ;
28+ }
29+
30+ declare type RouteEntry = [ string , RegExp , RouteHandler [ ] ] ;
31+ declare type Route = < T extends RouterType > ( path : string , ...handlers : RouteHandler [ ] ) => T ;
32+ declare type RouterHints = {
33+ all : Route ;
34+ delete : Route ;
35+ get : Route ;
36+ options : Route ;
37+ patch : Route ;
38+ post : Route ;
39+ put : Route ;
40+ } ;
41+ declare type RouterType = {
42+ __proto__ : RouterType ;
43+ routes : RouteEntry [ ] ;
44+ handle : ( request : RequestLike , ...extra : any ) => Promise < any > ;
45+ } & RouterHints ;
46+
47+ interface routerType {
48+ all ( path : string , ...handlers : RouteHandler [ ] ) : RouterType
49+ delete ( path : string , ...handlers : RouteHandler [ ] ) : RouterType
50+ get ( path : string , ...handlers : RouteHandler [ ] ) : RouterType
51+ handle ( request : RequestLike , ...extras : any ) : Promise < any >
52+ handleRequest ( request : HttpRequest , ...extras : any ) : Promise < any >
53+ options ( path : string , ...handlers : RouteHandler [ ] ) : RouterType
54+ patch ( path : string , ...handlers : RouteHandler [ ] ) : RouterType
55+ post ( path : string , ...handlers : RouteHandler [ ] ) : RouterType
56+ put ( path : string , ...handlers : RouteHandler [ ] ) : RouterType
57+ routes : RouteEntry [ ]
58+ }
59+
60+ /** @internal */
61+ function router ( ) : routerType {
62+ let _spinRouter = _router ( )
63+
64+ return {
65+ all : function ( path : string , ...handlers : RouteHandler [ ] ) : RouterType { return _spinRouter . all ( path , ...handlers ) } ,
66+ delete : function ( path : string , ...handlers : RouteHandler [ ] ) : RouterType { return _spinRouter . delete ( path , ...handlers ) } ,
67+ get : function ( path : string , ...handlers : RouteHandler [ ] ) : RouterType { return _spinRouter . get ( path , ...handlers ) } ,
68+ handle :function ( request : RequestLike , ...extra : any ) : Promise < any > { return _spinRouter . handle ( request , ...extra ) } ,
69+ handleRequest : function ( request : HttpRequest , ...a : any ) : Promise < any > {
70+ return _spinRouter . handle ( {
71+ method : request . method ,
72+ url : request . headers [ "spin-full-url" ]
73+ } , ...a )
74+ } ,
75+ options : function ( path : string , ...handlers : RouteHandler [ ] ) : RouterType { return _spinRouter . options ( path , ...handlers ) } ,
76+ patch : function ( path : string , ...handlers : RouteHandler [ ] ) : RouterType { return _spinRouter . patch ( path , ...handlers ) } ,
77+ post : function ( path : string , ...handlers : RouteHandler [ ] ) : RouterType { return _spinRouter . post ( path , ...handlers ) } ,
78+ put : function ( path : string , ...handlers : RouteHandler [ ] ) : RouterType { return _spinRouter . put ( path , ...handlers ) } ,
79+ routes : _spinRouter . routes
80+ }
81+ }
82+
83+ /** @internal */
84+ export { router }
85+ export { routerType }
0 commit comments