-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtypes.ts
120 lines (115 loc) · 2.71 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import { RouterContext, Status } from "./deps.ts";
// Copyright 2020 Liam Tan. All rights reserved. MIT license.
export enum HttpMethod {
GET = "get",
POST = "post",
PUT = "put",
PATCH = "patch",
DELETE = "delete",
}
/**
* All parameter decorator types. When a route argument is declared
* using a parameter decorator, the correct `ArgsType` is assigned
* so that at runtime `Router` can determine where to retreive the
* data from
*/
export enum ArgsType {
PARAM = "param",
BODY = "body",
QUERY = "query",
HEADER = "header",
CONTEXT = "context",
REQUEST = "request",
RESPONSE = "response",
COOKIE = "cookie",
INJECT = "inject",
}
/**
* Metadata shape describing a controller and its
* subsidiary routes. Includes all data in addtion
* to routes like controller action args, response
* codes
*/
export interface ControllerMetadata {
prefix: string | null;
scope: EInjectionScope;
routes: Map<string | Symbol, RouteDefinition>;
defaultResponseCodes: Map<string | Symbol, number>;
args: RouteArgument[];
beforeFns: Map<string, Array<Function>>;
}
/**
* Route definition metadata, as mapped to a controller
* action. Consumed in `ControllerMetadata` to build
* routes that oak understands
*/
export interface RouteDefinition {
path: string;
requestMethod: HttpMethod;
methodName: string | Symbol;
}
/**
* Definition for a parameter decorator on a controller
* action.
*/
export interface RouteArgument {
type: ArgsType;
index: number;
key: string | undefined;
argFor: string | Symbol;
}
/**
* Definition for parameter decorator to apply a `@Before`
* function to be called before action is executed
*/
export interface BeforeDefinition {
functionFor: string | Symbol;
fn: Function;
}
/**
* Root config for the `Application` class.
*/
export interface ApplicationConfig {
controllers: Array<Newable<any>>;
injectables: Array<Newable<any>>;
}
/**
* Definition for a class.
*/
export interface Newable<T> {
new (...args: any[]): T;
}
/**
* Structure of callback to be applied to Oak
* router
*/
export type ControllerCallback = (context: RouterContext) => Promise<void>;
/**
* Injection scope. Used by the `@Injectable` decorator
* to determine lifetime of dependency
*/
export enum EInjectionScope {
SINGLETON = "singleton",
TRANSIENT = "transient",
REQUEST = "request",
}
/**
* Definition consumable by `DependencyContainer` class
*/
export interface DependencyDefinition {
scope: EInjectionScope;
newable: Newable<any>;
}
/**
* Result of execution container
*/
export interface ExecutionResult {
success: boolean;
body: any;
status: Status;
}
export interface RequestLifetime {
requestId: string;
resolve: (key: string) => any | null;
end: () => void;
}