1 | import type { GrownInterface, GrownUtils, Plug } from '@grown/bud';
|
2 |
|
3 | declare module '@grown/router' {
|
4 | interface RouteMappings {
|
5 | mappings: UrlMap;
|
6 | routes: UrlInfo;
|
7 |
|
8 | namespace(path: string, group: RoutesCallback): this;
|
9 | resources(path: string, opts?: RouteOptions): this;
|
10 | resource(path: string, opts?: RouteOptions): this;
|
11 |
|
12 | get(path: string, handler: string): this;
|
13 | get(path: string, opts: RouteOptions, handler: string): this;
|
14 |
|
15 | post(path: string, handler: string): this;
|
16 | post(path: string, opts: RouteOptions, handler: string): this;
|
17 |
|
18 | put(path: string, handler: string): this;
|
19 | put(path: string, opts: RouteOptions, handler: string): this;
|
20 |
|
21 | patch(path: string, handler: string): this;
|
22 | patch(path: string, opts: RouteOptions, handler: string): this;
|
23 |
|
24 | delete(path: string, handler: string): this;
|
25 | delete(path: string, opts: RouteOptions, handler: string): this;
|
26 | }
|
27 |
|
28 | interface RoutesCallback {
|
29 | (router: RouterFactory): RouteMappings;
|
30 | }
|
31 |
|
32 | interface RouterFactory {
|
33 | (opts?: RouteOptions): RouteMappings;
|
34 | }
|
35 |
|
36 | type ControllerInfo = {
|
37 | instance: any;
|
38 | definition: any;
|
39 | };
|
40 |
|
41 | type PipelineInfo = {
|
42 | call: [Object, string];
|
43 | name: string;
|
44 | type: string;
|
45 | };
|
46 |
|
47 | type UrlParam = string | number | { [key: string]: string | number; };
|
48 |
|
49 | |
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | interface UrlInfo {
|
64 | |
65 |
|
66 |
|
67 |
|
68 | (...args: UrlParam[]): string;
|
69 | [key: string]: UrlInfo;
|
70 | url: UrlInfo;
|
71 | }
|
72 |
|
73 | interface UrlMap {
|
74 | |
75 |
|
76 |
|
77 |
|
78 |
|
79 | (path: string, ...args: UrlParam[]): UrlInfo | string;
|
80 | [key: string]: UrlInfo;
|
81 | }
|
82 |
|
83 | type RouteOptions = {
|
84 | to?: string;
|
85 | as?: string;
|
86 | };
|
87 |
|
88 | |
89 |
|
90 |
|
91 | type RouterClass = {
|
92 | Controllers: Plug;
|
93 | Mappings: Plug;
|
94 | };
|
95 |
|
96 | |
97 |
|
98 |
|
99 | type RouterPlug = {
|
100 | Router: RouterClass;
|
101 | };
|
102 | }
|
103 |
|
104 | declare module '@grown/server' {
|
105 | interface Connection {
|
106 | |
107 |
|
108 |
|
109 | routes: UrlMap;
|
110 | }
|
111 | }
|
112 |
|
113 | declare module '@grown/bud' {
|
114 | interface GrownInterface {
|
115 | |
116 |
|
117 |
|
118 | Router: RouterClass;
|
119 | }
|
120 |
|
121 | interface GrownInstance {
|
122 | |
123 |
|
124 |
|
125 | router: RouteMappings;
|
126 |
|
127 | namespace(path: string, group: RoutesCallback): RouteMappings;
|
128 | resources(path: string, opts?: RouteOptions): RouteMappings;
|
129 | resource(path: string, opts?: RouteOptions): RouteMappings;
|
130 |
|
131 | get(path: string, handler: string): RouteMappings;
|
132 | get(path: string, opts: RouteOptions, handler: string): RouteMappings;
|
133 |
|
134 | post(path: string, handler: string): RouteMappings;
|
135 | post(path: string, opts: RouteOptions, handler: string): RouteMappings;
|
136 |
|
137 | put(path: string, handler: string): RouteMappings;
|
138 | put(path: string, opts: RouteOptions, handler: string): RouteMappings;
|
139 |
|
140 | patch(path: string, handler: string): RouteMappings;
|
141 | patch(path: string, opts: RouteOptions, handler: string): RouteMappings;
|
142 |
|
143 | delete(path: string, handler: string): RouteMappings;
|
144 | delete(path: string, opts: RouteOptions, handler: string): RouteMappings;
|
145 | }
|
146 | }
|
147 |
|
148 |
|
149 |
|
150 |
|
151 | declare function RouterPlug(ctx: GrownInterface, util: GrownUtils): RouterClass;
|
152 |
|
153 | export default RouterPlug;
|