1 | import { Context, ValueOrPromise } from '@loopback/core';
|
2 | import { InvokeMiddleware, InvokeMiddlewareOptions } from '@loopback/express';
|
3 | import { RequestContext } from './request-context';
|
4 | import { FindRoute, InvokeMethod, ParseParams, Reject, Send } from './types';
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | export type SequenceFunction = (context: RequestContext, sequence: DefaultSequence) => ValueOrPromise<void>;
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | export interface SequenceHandler {
|
15 | |
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | handle(context: RequestContext): Promise<void>;
|
22 | }
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | export declare class DefaultSequence implements SequenceHandler {
|
42 | protected findRoute: FindRoute;
|
43 | protected parseParams: ParseParams;
|
44 | protected invoke: InvokeMethod;
|
45 | send: Send;
|
46 | reject: Reject;
|
47 | |
48 |
|
49 |
|
50 |
|
51 | protected invokeMiddleware: InvokeMiddleware;
|
52 | |
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | constructor(findRoute: FindRoute, parseParams: ParseParams, invoke: InvokeMethod, send: Send, reject: Reject);
|
68 | /**
|
69 | * Runs the default sequence. Given a handler context (request and response),
|
70 | * running the sequence will produce a response or an error.
|
71 | *
|
72 | * Default sequence executes these steps
|
73 | * - Executes middleware for CORS, OpenAPI spec endpoints
|
74 | * - Finds the appropriate controller method, swagger spec
|
75 | * and args for invocation
|
76 | * - Parses HTTP request to get API argument list
|
77 | * - Invokes the API which is defined in the Application Controller
|
78 | * - Writes the result from API into the HTTP response
|
79 | * - Error is caught and logged using 'logError' if any of the above steps
|
80 | * in the sequence fails with an error.
|
81 | *
|
82 | * @param context - The request context: HTTP request and response objects,
|
83 | * per-request IoC container and more.
|
84 | */
|
85 | handle(context: RequestContext): Promise<void>;
|
86 | }
|
87 | /**
|
88 | * Built-in middleware groups for the REST sequence
|
89 | */
|
90 | export declare namespace RestMiddlewareGroups {
|
91 | |
92 |
|
93 |
|
94 |
|
95 | const SEND_RESPONSE = "sendResponse";
|
96 | |
97 |
|
98 |
|
99 | const CORS = "cors";
|
100 | |
101 |
|
102 |
|
103 | const API_SPEC = "apiSpec";
|
104 | |
105 |
|
106 |
|
107 | const MIDDLEWARE = "middleware";
|
108 | const DEFAULT = "middleware";
|
109 | |
110 |
|
111 |
|
112 | const FIND_ROUTE = "findRoute";
|
113 | |
114 |
|
115 |
|
116 | const AUTHENTICATION = "authentication";
|
117 | |
118 |
|
119 |
|
120 | const PARSE_PARAMS = "parseParams";
|
121 | |
122 |
|
123 |
|
124 | const INVOKE_METHOD = "invokeMethod";
|
125 | }
|
126 |
|
127 |
|
128 |
|
129 | export declare class MiddlewareSequence implements SequenceHandler {
|
130 | readonly invokeMiddleware: InvokeMiddleware;
|
131 | readonly options: InvokeMiddlewareOptions;
|
132 | private middlewareView;
|
133 | static defaultOptions: InvokeMiddlewareOptions;
|
134 | |
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 | constructor(context: Context, invokeMiddleware: InvokeMiddleware, options?: InvokeMiddlewareOptions);
|
141 | /**
|
142 | * Runs the default sequence. Given a handler context (request and response),
|
143 | * running the sequence will produce a response or an error.
|
144 | *
|
145 | * Default sequence executes these groups of middleware:
|
146 | *
|
147 | * - `cors`: Enforces `CORS`
|
148 | * - `openApiSpec`: Serves OpenAPI specs
|
149 | * - `findRoute`: Finds the appropriate controller method, swagger spec and
|
150 | * args for invocation
|
151 | * - `parseParams`: Parses HTTP request to get API argument list
|
152 | * - `invokeMethod`: Invokes the API which is defined in the Application
|
153 | * controller method
|
154 | *
|
155 | * In front of the groups above, we have a special middleware called
|
156 | * `sendResponse`, which first invokes downstream middleware to get a result
|
157 | * and handles the result or error respectively.
|
158 | *
|
159 | * - Writes the result from API into the HTTP response (if the HTTP response
|
160 | * has not been produced yet by the middleware chain.
|
161 | * - Catches error logs it using 'logError' if any of the above steps
|
162 | * in the sequence fails with an error.
|
163 | *
|
164 | * @param context - The request context: HTTP request and response objects,
|
165 | * per-request IoC container and more.
|
166 | */
|
167 | handle(context: RequestContext): Promise<void>;
|
168 | }
|
169 |
|
\ | No newline at end of file |