1 | /// <reference types="node" />
|
2 | /// <reference types="express" />
|
3 | import { BindingKey, Context } from '@loopback/core';
|
4 | import { InvokeMiddleware } from '@loopback/express';
|
5 | import { HttpProtocol } from '@loopback/http-server';
|
6 | import { OpenApiSpec, OperationObject } from '@loopback/openapi-v3';
|
7 | import https from 'https';
|
8 | import { ErrorWriterOptions } from 'strong-error-handler';
|
9 | import { BodyParser, RequestBodyParser } from './body-parsers';
|
10 | import { HttpHandler } from './http-handler';
|
11 | import { RestServer, RestServerConfig } from './rest.server';
|
12 | import { ResolvedRoute, RestRouter, RestRouterOptions } from './router';
|
13 | import { SequenceHandler } from './sequence';
|
14 | import { AjvFactory, FindRoute, InvokeMethod, LogError, OperationArgs, ParseParams, Reject, Request, RequestBodyParserOptions, Response, Send } from './types';
|
15 | /**
|
16 | * RestServer-specific bindings
|
17 | */
|
18 | export declare namespace RestBindings {
|
19 | /**
|
20 | * Binding key for setting and injecting RestComponentConfig
|
21 | */
|
22 | const CONFIG: BindingKey<RestServerConfig>;
|
23 | /**
|
24 | * Binding key for setting and injecting the host name of RestServer
|
25 | */
|
26 | const HOST: BindingKey<string | undefined>;
|
27 | /**
|
28 | * Binding key for setting and injecting the port number of RestServer
|
29 | */
|
30 | const PORT: BindingKey<number>;
|
31 | /**
|
32 | * Binding key for setting and injecting the socket path of the RestServer
|
33 | */
|
34 | const PATH: BindingKey<string | undefined>;
|
35 | /**
|
36 | * Binding key for setting and injecting the URL of RestServer
|
37 | */
|
38 | const URL: BindingKey<string>;
|
39 | /**
|
40 | * Binding key for setting and injecting the protocol of RestServer
|
41 | */
|
42 | const PROTOCOL: BindingKey<HttpProtocol>;
|
43 | /**
|
44 | * Binding key for HTTPS options
|
45 | */
|
46 | const HTTPS_OPTIONS: BindingKey<https.ServerOptions>;
|
47 | /**
|
48 | * Binding key for the server itself
|
49 | */
|
50 | const SERVER: BindingKey<RestServer>;
|
51 | /**
|
52 | * Internal binding key for basePath
|
53 | */
|
54 | const BASE_PATH: BindingKey<string>;
|
55 | /**
|
56 | * Internal binding key for http-handler
|
57 | */
|
58 | const HANDLER: BindingKey<HttpHandler>;
|
59 | /**
|
60 | * Internal binding key for rest router
|
61 | */
|
62 | const ROUTER: BindingKey<RestRouter>;
|
63 | const ROUTER_OPTIONS: BindingKey<RestRouterOptions>;
|
64 | /**
|
65 | * Binding key for setting and injecting Reject action's error handling
|
66 | * options.
|
67 | *
|
68 | * See https://github.com/loopbackio/strong-error-handler#options for
|
69 | * the list of available options. Please note that the flag `log` is not used
|
70 | * by `@loopback/rest`.
|
71 | */
|
72 | const ERROR_WRITER_OPTIONS: BindingKey<ErrorWriterOptions>;
|
73 | /**
|
74 | * Binding key for request body parser options
|
75 | */
|
76 | const REQUEST_BODY_PARSER_OPTIONS: BindingKey<RequestBodyParserOptions>;
|
77 | /**
|
78 | * Binding key for request body parser
|
79 | */
|
80 | const REQUEST_BODY_PARSER: BindingKey<RequestBodyParser>;
|
81 | /**
|
82 | * Binding key for request json body parser
|
83 | */
|
84 | const REQUEST_BODY_PARSER_JSON: BindingKey<BodyParser>;
|
85 | /**
|
86 | * Binding key for request urlencoded body parser
|
87 | */
|
88 | const REQUEST_BODY_PARSER_URLENCODED: BindingKey<BodyParser>;
|
89 | /**
|
90 | * Binding key for request text body parser
|
91 | */
|
92 | const REQUEST_BODY_PARSER_TEXT: BindingKey<BodyParser>;
|
93 | /**
|
94 | * Binding key for request raw body parser
|
95 | */
|
96 | const REQUEST_BODY_PARSER_RAW: BindingKey<BodyParser>;
|
97 | /**
|
98 | * Binding key for request raw body parser
|
99 | */
|
100 | const REQUEST_BODY_PARSER_STREAM: BindingKey<BodyParser>;
|
101 | /**
|
102 | * Binding key for AJV
|
103 | */
|
104 | const AJV_FACTORY: BindingKey<AjvFactory>;
|
105 | /**
|
106 | * Binding key for setting and injecting an OpenAPI spec
|
107 | */
|
108 | const API_SPEC: BindingKey<OpenApiSpec>;
|
109 | /**
|
110 | * Binding key for setting and injecting an OpenAPI operation spec
|
111 | */
|
112 | const OPERATION_SPEC_CURRENT: BindingKey<OperationObject>;
|
113 | /**
|
114 | * Binding key for setting and injecting a Sequence
|
115 | */
|
116 | const SEQUENCE: BindingKey<SequenceHandler>;
|
117 | /**
|
118 | * Binding key for setting and injecting a `invokeMiddleware` function for
|
119 | * middleware based sequence
|
120 | */
|
121 | const INVOKE_MIDDLEWARE_SERVICE: BindingKey<InvokeMiddleware>;
|
122 | /**
|
123 | * Bindings for potential actions that could be used in a sequence
|
124 | */
|
125 | namespace SequenceActions {
|
126 | /**
|
127 | * Binding key for setting and injecting `invokeMiddleware` function
|
128 | */
|
129 | const INVOKE_MIDDLEWARE: BindingKey<InvokeMiddleware>;
|
130 | /**
|
131 | * Binding key for setting and injecting a route finding function
|
132 | */
|
133 | const FIND_ROUTE: BindingKey<FindRoute>;
|
134 | /**
|
135 | * Binding key for setting and injecting a parameter parsing function
|
136 | */
|
137 | const PARSE_PARAMS: BindingKey<ParseParams>;
|
138 | /**
|
139 | * Binding key for setting and injecting a controller route invoking function
|
140 | */
|
141 | const INVOKE_METHOD: BindingKey<InvokeMethod>;
|
142 | /**
|
143 | * Binding key for setting and injecting an error logging function
|
144 | */
|
145 | const LOG_ERROR: BindingKey<LogError>;
|
146 | /**
|
147 | * Binding key for setting and injecting a response writing function
|
148 | */
|
149 | const SEND: BindingKey<Send>;
|
150 | /**
|
151 | * Binding key for setting and injecting a bad response writing function
|
152 | */
|
153 | const REJECT: BindingKey<Reject>;
|
154 | }
|
155 | namespace Operation {
|
156 | const ROUTE: BindingKey<ResolvedRoute>;
|
157 | const PARAMS: BindingKey<OperationArgs>;
|
158 | const RETURN_VALUE: BindingKey<any>;
|
159 | }
|
160 | /**
|
161 | * Request-specific bindings
|
162 | */
|
163 | namespace Http {
|
164 | /**
|
165 | * Binding key for setting and injecting the http request
|
166 | */
|
167 | const REQUEST: BindingKey<Request>;
|
168 | /**
|
169 | * Binding key for setting and injecting the http response
|
170 | */
|
171 | const RESPONSE: BindingKey<Response<any, Record<string, any>>>;
|
172 | /**
|
173 | * Binding key for setting and injecting the http request context
|
174 | */
|
175 | const CONTEXT: BindingKey<Context>;
|
176 | }
|
177 | /**
|
178 | * Namespace for REST routes
|
179 | */
|
180 | const ROUTES = "routes";
|
181 | }
|
182 | /**
|
183 | * Binding tags for RestServer
|
184 | */
|
185 | export declare namespace RestTags {
|
186 | /**
|
187 | * Binding tag to identify REST routes
|
188 | */
|
189 | const REST_ROUTE = "restRoute";
|
190 | /**
|
191 | * Binding tag for the REST route verb
|
192 | */
|
193 | const ROUTE_VERB = "restRouteVerb";
|
194 | /**
|
195 | * Binding tag for the REST route path
|
196 | */
|
197 | const ROUTE_PATH = "restRoutePath";
|
198 | /**
|
199 | * Binding tag to identify controller based REST routes
|
200 | */
|
201 | const CONTROLLER_ROUTE = "controllerRoute";
|
202 | /**
|
203 | * Binding tag for controller route bindings to represent the controller
|
204 | * binding key
|
205 | */
|
206 | const CONTROLLER_BINDING = "controllerBinding";
|
207 | const AJV_KEYWORD = "ajvKeyword";
|
208 | const AJV_FORMAT = "ajvFormat";
|
209 | const REST_MIDDLEWARE_CHAIN = "middlewareChain.default";
|
210 | /**
|
211 | * Legacy middleware chain for action-based REST sequence
|
212 | */
|
213 | const ACTION_MIDDLEWARE_CHAIN = "middlewareChain.rest.actions";
|
214 | }
|