1 | /**
|
2 | * Copyright 2018 Google Inc. All Rights Reserved.
|
3 | *
|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | * you may not use this file except in compliance with the License.
|
6 | * You may obtain a copy of the License at
|
7 | *
|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
9 | *
|
10 | * Unless required by applicable law or agreed to in writing, software
|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 | * See the License for the specific language governing permissions and
|
14 | * limitations under the License.
|
15 | */
|
16 |
|
17 | import {ExpressHandler, Express, ExpressMetadata, express} from './express';
|
18 | import {LambdaHandler, Lambda, LambdaMetadata, lambda} from './lambda';
|
19 | import {JsonObject} from '../common';
|
20 |
|
21 | export interface Frameworks {
|
22 | /** @public */
|
23 | [name: string]: Framework<Function>;
|
24 | }
|
25 |
|
26 | /** @public */
|
27 | export interface Framework<THandler> {
|
28 | /** @public */
|
29 | handle(base: StandardHandler): THandler;
|
30 |
|
31 | /** @public */
|
32 | // tslint:disable-next-line:no-any detect if it is the correct framework from any parameter type
|
33 | check(...args: any[]): boolean;
|
34 | }
|
35 |
|
36 | /** @public */
|
37 | export interface OmniHandler
|
38 | extends StandardHandler,
|
39 | ExpressHandler,
|
40 | LambdaHandler {
|
41 | /** @public */
|
42 | // tslint:disable-next-line:no-any allow any inputs and outputs depending on framework
|
43 | (...args: any[]): any;
|
44 | }
|
45 |
|
46 | export interface FrameworkMetadata {
|
47 | /** @public */
|
48 | // tslint:disable-next-line:no-any allow any framework metadata
|
49 | [name: string]: any;
|
50 | }
|
51 |
|
52 | export interface BuiltinFrameworkMetadata extends FrameworkMetadata {
|
53 | /** @public */
|
54 | express?: ExpressMetadata;
|
55 |
|
56 | /** @public */
|
57 | lambda?: LambdaMetadata;
|
58 | }
|
59 |
|
60 | export interface BuiltinFrameworks extends Frameworks {
|
61 | /**
|
62 | * Plug and play web framework support for express using body-parser
|
63 | * @public
|
64 | */
|
65 | express: Express;
|
66 |
|
67 | /**
|
68 | * Plug and play web framework support for lambda API gateway
|
69 | * @public
|
70 | */
|
71 | lambda: Lambda;
|
72 | }
|
73 |
|
74 | /** @hidden */
|
75 | export const builtin: BuiltinFrameworks = {
|
76 | express,
|
77 | lambda,
|
78 | };
|
79 |
|
80 | /** @public */
|
81 | export interface StandardResponse {
|
82 | /** @public */
|
83 | status: number;
|
84 |
|
85 | /** @public */
|
86 | body: JsonObject;
|
87 |
|
88 | /** @public */
|
89 | headers?: Headers;
|
90 | }
|
91 |
|
92 | /** @public */
|
93 | export interface Headers {
|
94 | /** @public */
|
95 | [header: string]: string | string[] | undefined;
|
96 | }
|
97 |
|
98 | /** @public */
|
99 | export interface StandardHandler {
|
100 | /** @public */
|
101 | (
|
102 | /** @public */
|
103 | body: JsonObject,
|
104 |
|
105 | /** @public */
|
106 | headers: Headers,
|
107 |
|
108 | /** @public */
|
109 | metadata?: BuiltinFrameworkMetadata
|
110 | ): Promise<StandardResponse>;
|
111 | }
|