@expressots/adapter-express 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/CHANGELOG.md +21 -0
- package/lib/cjs/adapter-express/application-express.js +80 -21
- package/lib/cjs/types/adapter-express/application-base.d.ts +0 -1
- package/lib/cjs/types/adapter-express/application-express.d.ts +36 -2
- package/lib/cjs/types/adapter-express/application-express.interface.d.ts +0 -1
- package/lib/cjs/types/adapter-express/express-utils/base-middleware.d.ts +0 -1
- package/lib/cjs/types/adapter-express/express-utils/constants.d.ts +0 -1
- package/lib/cjs/types/adapter-express/express-utils/content/httpContent.d.ts +0 -1
- package/lib/cjs/types/adapter-express/express-utils/decorators.d.ts +0 -1
- package/lib/cjs/types/adapter-express/express-utils/httpResponseMessage.d.ts +0 -1
- package/lib/cjs/types/adapter-express/express-utils/index.d.ts +0 -1
- package/lib/cjs/types/adapter-express/express-utils/interfaces.d.ts +0 -1
- package/lib/cjs/types/adapter-express/express-utils/inversify-express-server.d.ts +0 -1
- package/lib/cjs/types/adapter-express/express-utils/utils.d.ts +0 -1
- package/lib/cjs/types/adapter-express/index.d.ts +0 -1
- package/lib/cjs/types/index.d.ts +0 -1
- package/lib/package.json +5 -10
- package/package.json +5 -10
- package/lib/cjs/types/adapter-express/application-base.d.ts.map +0 -1
- package/lib/cjs/types/adapter-express/application-express.d.ts.map +0 -1
- package/lib/cjs/types/adapter-express/application-express.interface.d.ts.map +0 -1
- package/lib/cjs/types/adapter-express/express-utils/base-middleware.d.ts.map +0 -1
- package/lib/cjs/types/adapter-express/express-utils/constants.d.ts.map +0 -1
- package/lib/cjs/types/adapter-express/express-utils/content/httpContent.d.ts.map +0 -1
- package/lib/cjs/types/adapter-express/express-utils/decorators.d.ts.map +0 -1
- package/lib/cjs/types/adapter-express/express-utils/httpResponseMessage.d.ts.map +0 -1
- package/lib/cjs/types/adapter-express/express-utils/index.d.ts.map +0 -1
- package/lib/cjs/types/adapter-express/express-utils/interfaces.d.ts.map +0 -1
- package/lib/cjs/types/adapter-express/express-utils/inversify-express-server.d.ts.map +0 -1
- package/lib/cjs/types/adapter-express/express-utils/utils.d.ts.map +0 -1
- package/lib/cjs/types/adapter-express/index.d.ts.map +0 -1
- package/lib/cjs/types/index.d.ts.map +0 -1
- package/lib/esm/adapter-express/application-base.js +0 -36
- package/lib/esm/adapter-express/application-express.interface.js +0 -2
- package/lib/esm/adapter-express/application-express.js +0 -152
- package/lib/esm/adapter-express/express-utils/base-middleware.js +0 -22
- package/lib/esm/adapter-express/express-utils/constants.js +0 -46
- package/lib/esm/adapter-express/express-utils/content/httpContent.js +0 -10
- package/lib/esm/adapter-express/express-utils/decorators.js +0 -110
- package/lib/esm/adapter-express/express-utils/httpResponseMessage.js +0 -33
- package/lib/esm/adapter-express/express-utils/index.js +0 -17
- package/lib/esm/adapter-express/express-utils/interfaces.js +0 -2
- package/lib/esm/adapter-express/express-utils/inversify-express-server.js +0 -293
- package/lib/esm/adapter-express/express-utils/utils.js +0 -58
- package/lib/esm/adapter-express/index.js +0 -21
- package/lib/esm/index.mjs +0 -17
- package/lib/esm/types/adapter-express/application-base.d.ts +0 -55
- package/lib/esm/types/adapter-express/application-base.d.ts.map +0 -1
- package/lib/esm/types/adapter-express/application-express.d.ts +0 -71
- package/lib/esm/types/adapter-express/application-express.d.ts.map +0 -1
- package/lib/esm/types/adapter-express/application-express.interface.d.ts +0 -29
- package/lib/esm/types/adapter-express/application-express.interface.d.ts.map +0 -1
- package/lib/esm/types/adapter-express/express-utils/base-middleware.d.ts +0 -9
- package/lib/esm/types/adapter-express/express-utils/base-middleware.d.ts.map +0 -1
- package/lib/esm/types/adapter-express/express-utils/constants.d.ts +0 -39
- package/lib/esm/types/adapter-express/express-utils/constants.d.ts.map +0 -1
- package/lib/esm/types/adapter-express/express-utils/content/httpContent.d.ts +0 -8
- package/lib/esm/types/adapter-express/express-utils/content/httpContent.d.ts.map +0 -1
- package/lib/esm/types/adapter-express/express-utils/decorators.d.ts +0 -24
- package/lib/esm/types/adapter-express/express-utils/decorators.d.ts.map +0 -1
- package/lib/esm/types/adapter-express/express-utils/httpResponseMessage.d.ts +0 -16
- package/lib/esm/types/adapter-express/express-utils/httpResponseMessage.d.ts.map +0 -1
- package/lib/esm/types/adapter-express/express-utils/index.d.ts +0 -3
- package/lib/esm/types/adapter-express/express-utils/index.d.ts.map +0 -1
- package/lib/esm/types/adapter-express/express-utils/interfaces.d.ts +0 -76
- package/lib/esm/types/adapter-express/express-utils/interfaces.d.ts.map +0 -1
- package/lib/esm/types/adapter-express/express-utils/inversify-express-server.d.ts +0 -60
- package/lib/esm/types/adapter-express/express-utils/inversify-express-server.d.ts.map +0 -1
- package/lib/esm/types/adapter-express/express-utils/utils.d.ts +0 -10
- package/lib/esm/types/adapter-express/express-utils/utils.d.ts.map +0 -1
- package/lib/esm/types/adapter-express/index.d.ts +0 -4
- package/lib/esm/types/adapter-express/index.d.ts.map +0 -1
- package/lib/esm/types/index.d.ts +0 -2
- package/lib/esm/types/index.d.ts.map +0 -1
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.ServerEnvironment = exports.AppExpress = void 0;
|
|
13
|
-
const inversify_binding_decorators_1 = require("inversify-binding-decorators");
|
|
14
|
-
const process_1 = __importDefault(require("process"));
|
|
15
|
-
const core_1 = require("@expressots/core");
|
|
16
|
-
const inversify_express_server_1 = require("./express-utils/inversify-express-server");
|
|
17
|
-
const application_base_1 = require("./application-base");
|
|
18
|
-
/**
|
|
19
|
-
* Enum representing possible server environments.
|
|
20
|
-
*/
|
|
21
|
-
var ServerEnvironment;
|
|
22
|
-
(function (ServerEnvironment) {
|
|
23
|
-
ServerEnvironment["Development"] = "development";
|
|
24
|
-
ServerEnvironment["Production"] = "production";
|
|
25
|
-
})(ServerEnvironment || (exports.ServerEnvironment = ServerEnvironment = {}));
|
|
26
|
-
/**
|
|
27
|
-
* The Application class provides a way to configure and manage an Express application.
|
|
28
|
-
* @provide Application
|
|
29
|
-
*/
|
|
30
|
-
let ApplicationExpress = class ApplicationExpress extends application_base_1.ApplicationBase {
|
|
31
|
-
app;
|
|
32
|
-
port;
|
|
33
|
-
environment;
|
|
34
|
-
container;
|
|
35
|
-
middlewares = [];
|
|
36
|
-
configureServices() { }
|
|
37
|
-
postServerInitialization() { }
|
|
38
|
-
serverShutdown() { }
|
|
39
|
-
/**
|
|
40
|
-
* Handles process exit by calling serverShutdown and then exiting the process.
|
|
41
|
-
*/
|
|
42
|
-
handleExit() {
|
|
43
|
-
this.serverShutdown();
|
|
44
|
-
process_1.default.exit(0);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Create and configure the Express application.
|
|
48
|
-
* @param container - The InversifyJS container.
|
|
49
|
-
* @param middlewares - An array of Express middlewares to be applied.
|
|
50
|
-
* @returns The configured Application instance.
|
|
51
|
-
*/
|
|
52
|
-
async create(container, middlewares = []) {
|
|
53
|
-
this.container = container;
|
|
54
|
-
await Promise.resolve(this.configureServices());
|
|
55
|
-
const middleware = container.get(core_1.Middleware);
|
|
56
|
-
const sortedMiddlewarePipeline = middleware.getMiddlewarePipeline();
|
|
57
|
-
const pipeline = sortedMiddlewarePipeline.map((entry) => entry.middleware);
|
|
58
|
-
this.middlewares.push(...middlewares, ...pipeline);
|
|
59
|
-
const allMiddlewareEntries = [...this.middlewares];
|
|
60
|
-
const expressServer = new inversify_express_server_1.InversifyExpressServer(container);
|
|
61
|
-
expressServer.setConfig((app) => {
|
|
62
|
-
allMiddlewareEntries.forEach((entry) => {
|
|
63
|
-
if (typeof entry === "function") {
|
|
64
|
-
app.use(entry);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
const { path, middlewares } = entry;
|
|
68
|
-
middlewares.forEach((middleware) => {
|
|
69
|
-
if (path) {
|
|
70
|
-
app.use(path, middleware);
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
app.use(middleware);
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
expressServer.setErrorConfig((app) => {
|
|
80
|
-
if (middleware.getErrorHandler()) {
|
|
81
|
-
app.use(middleware.getErrorHandler());
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
this.app = expressServer.build();
|
|
85
|
-
return this;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Start listening on the given port and environment.
|
|
89
|
-
* @param port - The port number to listen on.
|
|
90
|
-
* @param environment - The server environment.
|
|
91
|
-
* @param consoleMessage - Optional message to display in the console.
|
|
92
|
-
*/
|
|
93
|
-
async listen(port, environment, consoleMessage) {
|
|
94
|
-
this.port = port;
|
|
95
|
-
this.environment = environment;
|
|
96
|
-
this.app.set("env", environment);
|
|
97
|
-
this.app.listen(this.port, () => {
|
|
98
|
-
const console = this.container.get(core_1.Console);
|
|
99
|
-
console.messageServer(this.port, this.environment, consoleMessage);
|
|
100
|
-
["SIGTERM", "SIGHUP", "SIGBREAK", "SIGQUIT", "SIGINT"].forEach((signal) => {
|
|
101
|
-
process_1.default.on(signal, this.handleExit.bind(this));
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
await Promise.resolve(this.postServerInitialization());
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Configures the application's view engine based on the provided configuration options.
|
|
108
|
-
*
|
|
109
|
-
* @public
|
|
110
|
-
* @method setEngine
|
|
111
|
-
* @template T - A generic type extending from RenderTemplateOptions.
|
|
112
|
-
*
|
|
113
|
-
* @param {T} options - An object of type T (must be an object that extends RenderTemplateOptions)
|
|
114
|
-
* that provides the configuration options for setting the view engine.
|
|
115
|
-
* This includes the extension name, view path, and the engine function itself.
|
|
116
|
-
*/
|
|
117
|
-
setEngine(options) {
|
|
118
|
-
if ("extName" in options) {
|
|
119
|
-
const { extName, viewPath, engine } = options;
|
|
120
|
-
this.app.engine(extName, engine);
|
|
121
|
-
this.app.set("view engine", extName);
|
|
122
|
-
this.app.set("views", viewPath);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Verifies if the current environment is development.
|
|
127
|
-
*
|
|
128
|
-
* @returns A boolean value indicating whether the current environment is development or not.
|
|
129
|
-
*/
|
|
130
|
-
isDevelopment() {
|
|
131
|
-
if (this.app) {
|
|
132
|
-
return this.app.get("env") === ServerEnvironment.Development;
|
|
133
|
-
}
|
|
134
|
-
this.container
|
|
135
|
-
.get(core_1.Logger)
|
|
136
|
-
.error("isDevelopment() method must be called on `PostServerInitialization`", "application");
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Verifies if the current environment is production.
|
|
141
|
-
*
|
|
142
|
-
* @returns A boolean value indicating whether the current environment is production or not.
|
|
143
|
-
*
|
|
144
|
-
*/
|
|
145
|
-
get ExpressApp() {
|
|
146
|
-
return this.app;
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
exports.AppExpress = ApplicationExpress;
|
|
150
|
-
exports.AppExpress = ApplicationExpress = __decorate([
|
|
151
|
-
(0, inversify_binding_decorators_1.provide)(ApplicationExpress)
|
|
152
|
-
], ApplicationExpress);
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.BaseMiddleware = void 0;
|
|
10
|
-
const inversify_1 = require("inversify");
|
|
11
|
-
let BaseMiddleware = class BaseMiddleware {
|
|
12
|
-
// httpContext is initialized when the middleware is invoked
|
|
13
|
-
// see resolveMiddleware in server.ts for more details
|
|
14
|
-
httpContext;
|
|
15
|
-
bind(serviceIdentifier) {
|
|
16
|
-
return this.httpContext.container.bind(serviceIdentifier);
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
exports.BaseMiddleware = BaseMiddleware;
|
|
20
|
-
exports.BaseMiddleware = BaseMiddleware = __decorate([
|
|
21
|
-
(0, inversify_1.injectable)()
|
|
22
|
-
], BaseMiddleware);
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_ROUTING_ROOT_PATH = exports.NO_CONTROLLERS_FOUND = exports.DUPLICATED_CONTROLLER_NAME = exports.HTTP_VERBS_ENUM = exports.PARAMETER_TYPE = exports.METADATA_KEY = exports.TYPE = void 0;
|
|
4
|
-
exports.TYPE = {
|
|
5
|
-
AuthProvider: Symbol.for("AuthProvider"),
|
|
6
|
-
Controller: Symbol.for("Controller"),
|
|
7
|
-
HttpContext: Symbol.for("HttpContext"),
|
|
8
|
-
};
|
|
9
|
-
exports.METADATA_KEY = {
|
|
10
|
-
controller: "inversify-express-utils:controller",
|
|
11
|
-
controllerMethod: "inversify-express-utils:controller-method",
|
|
12
|
-
controllerParameter: "inversify-express-utils:controller-parameter",
|
|
13
|
-
httpContext: "inversify-express-utils:httpcontext",
|
|
14
|
-
};
|
|
15
|
-
var PARAMETER_TYPE;
|
|
16
|
-
(function (PARAMETER_TYPE) {
|
|
17
|
-
PARAMETER_TYPE[PARAMETER_TYPE["REQUEST"] = 0] = "REQUEST";
|
|
18
|
-
PARAMETER_TYPE[PARAMETER_TYPE["RESPONSE"] = 1] = "RESPONSE";
|
|
19
|
-
PARAMETER_TYPE[PARAMETER_TYPE["PARAMS"] = 2] = "PARAMS";
|
|
20
|
-
PARAMETER_TYPE[PARAMETER_TYPE["QUERY"] = 3] = "QUERY";
|
|
21
|
-
PARAMETER_TYPE[PARAMETER_TYPE["BODY"] = 4] = "BODY";
|
|
22
|
-
PARAMETER_TYPE[PARAMETER_TYPE["HEADERS"] = 5] = "HEADERS";
|
|
23
|
-
PARAMETER_TYPE[PARAMETER_TYPE["COOKIES"] = 6] = "COOKIES";
|
|
24
|
-
PARAMETER_TYPE[PARAMETER_TYPE["NEXT"] = 7] = "NEXT";
|
|
25
|
-
PARAMETER_TYPE[PARAMETER_TYPE["PRINCIPAL"] = 8] = "PRINCIPAL";
|
|
26
|
-
})(PARAMETER_TYPE || (exports.PARAMETER_TYPE = PARAMETER_TYPE = {}));
|
|
27
|
-
var HTTP_VERBS_ENUM;
|
|
28
|
-
(function (HTTP_VERBS_ENUM) {
|
|
29
|
-
HTTP_VERBS_ENUM["all"] = "ALL";
|
|
30
|
-
HTTP_VERBS_ENUM["connect"] = "CONNECT";
|
|
31
|
-
HTTP_VERBS_ENUM["delete"] = "DELETE";
|
|
32
|
-
HTTP_VERBS_ENUM["get"] = "GET";
|
|
33
|
-
HTTP_VERBS_ENUM["head"] = "HEAD";
|
|
34
|
-
HTTP_VERBS_ENUM["options"] = "OPTIONS";
|
|
35
|
-
HTTP_VERBS_ENUM["patch"] = "PATCH";
|
|
36
|
-
HTTP_VERBS_ENUM["post"] = "POST";
|
|
37
|
-
HTTP_VERBS_ENUM["propfind"] = "PROPFIND";
|
|
38
|
-
HTTP_VERBS_ENUM["put"] = "PUT";
|
|
39
|
-
HTTP_VERBS_ENUM["trace"] = "TRACE";
|
|
40
|
-
})(HTTP_VERBS_ENUM || (exports.HTTP_VERBS_ENUM = HTTP_VERBS_ENUM = {}));
|
|
41
|
-
const DUPLICATED_CONTROLLER_NAME = (name) => `Two controllers cannot have the same name: ${name}`;
|
|
42
|
-
exports.DUPLICATED_CONTROLLER_NAME = DUPLICATED_CONTROLLER_NAME;
|
|
43
|
-
exports.NO_CONTROLLERS_FOUND = "No controllers" +
|
|
44
|
-
"have been found! Please ensure that you have register" +
|
|
45
|
-
"at least one Controller.";
|
|
46
|
-
exports.DEFAULT_ROUTING_ROOT_PATH = "/";
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.params = exports.Principal = exports.next = exports.cookies = exports.headers = exports.body = exports.query = exports.param = exports.response = exports.request = exports.httpMethod = exports.Delete = exports.Head = exports.Patch = exports.Put = exports.Post = exports.Get = exports.all = exports.controller = exports.injectHttpContext = void 0;
|
|
4
|
-
require("reflect-metadata");
|
|
5
|
-
const inversify_1 = require("inversify");
|
|
6
|
-
const constants_1 = require("./constants");
|
|
7
|
-
exports.injectHttpContext = (0, inversify_1.inject)(constants_1.TYPE.HttpContext);
|
|
8
|
-
function controller(path, ...middleware) {
|
|
9
|
-
return (target) => {
|
|
10
|
-
const currentMetadata = {
|
|
11
|
-
middleware,
|
|
12
|
-
path,
|
|
13
|
-
target,
|
|
14
|
-
};
|
|
15
|
-
(0, inversify_1.decorate)((0, inversify_1.injectable)(), target);
|
|
16
|
-
Reflect.defineMetadata(constants_1.METADATA_KEY.controller, currentMetadata, target);
|
|
17
|
-
const previousMetadata = Reflect.getMetadata(constants_1.METADATA_KEY.controller, Reflect) || [];
|
|
18
|
-
const newMetadata = [currentMetadata, ...previousMetadata];
|
|
19
|
-
Reflect.defineMetadata(constants_1.METADATA_KEY.controller, newMetadata, Reflect);
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
exports.controller = controller;
|
|
23
|
-
function all(path, ...middleware) {
|
|
24
|
-
return httpMethod("all", path, ...middleware);
|
|
25
|
-
}
|
|
26
|
-
exports.all = all;
|
|
27
|
-
function Get(path, ...middleware) {
|
|
28
|
-
return httpMethod("get", path, ...middleware);
|
|
29
|
-
}
|
|
30
|
-
exports.Get = Get;
|
|
31
|
-
function Post(path, ...middleware) {
|
|
32
|
-
return httpMethod("post", path, ...middleware);
|
|
33
|
-
}
|
|
34
|
-
exports.Post = Post;
|
|
35
|
-
function Put(path, ...middleware) {
|
|
36
|
-
return httpMethod("put", path, ...middleware);
|
|
37
|
-
}
|
|
38
|
-
exports.Put = Put;
|
|
39
|
-
function Patch(path, ...middleware) {
|
|
40
|
-
return httpMethod("patch", path, ...middleware);
|
|
41
|
-
}
|
|
42
|
-
exports.Patch = Patch;
|
|
43
|
-
function Head(path, ...middleware) {
|
|
44
|
-
return httpMethod("head", path, ...middleware);
|
|
45
|
-
}
|
|
46
|
-
exports.Head = Head;
|
|
47
|
-
function Delete(path, ...middleware) {
|
|
48
|
-
return httpMethod("delete", path, ...middleware);
|
|
49
|
-
}
|
|
50
|
-
exports.Delete = Delete;
|
|
51
|
-
function httpMethod(method, path, ...middleware) {
|
|
52
|
-
return (target, key) => {
|
|
53
|
-
const metadata = {
|
|
54
|
-
key,
|
|
55
|
-
method,
|
|
56
|
-
middleware,
|
|
57
|
-
path,
|
|
58
|
-
target,
|
|
59
|
-
};
|
|
60
|
-
let metadataList = [];
|
|
61
|
-
if (!Reflect.hasOwnMetadata(constants_1.METADATA_KEY.controllerMethod, target.constructor)) {
|
|
62
|
-
Reflect.defineMetadata(constants_1.METADATA_KEY.controllerMethod, metadataList, target.constructor);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
metadataList = Reflect.getOwnMetadata(constants_1.METADATA_KEY.controllerMethod, target.constructor);
|
|
66
|
-
}
|
|
67
|
-
metadataList.push(metadata);
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
exports.httpMethod = httpMethod;
|
|
71
|
-
/*
|
|
72
|
-
* Parameter Decorators
|
|
73
|
-
*/
|
|
74
|
-
exports.request = paramDecoratorFactory(constants_1.PARAMETER_TYPE.REQUEST);
|
|
75
|
-
exports.response = paramDecoratorFactory(constants_1.PARAMETER_TYPE.RESPONSE);
|
|
76
|
-
exports.param = paramDecoratorFactory(constants_1.PARAMETER_TYPE.PARAMS);
|
|
77
|
-
exports.query = paramDecoratorFactory(constants_1.PARAMETER_TYPE.QUERY);
|
|
78
|
-
exports.body = paramDecoratorFactory(constants_1.PARAMETER_TYPE.BODY);
|
|
79
|
-
exports.headers = paramDecoratorFactory(constants_1.PARAMETER_TYPE.HEADERS);
|
|
80
|
-
exports.cookies = paramDecoratorFactory(constants_1.PARAMETER_TYPE.COOKIES);
|
|
81
|
-
exports.next = paramDecoratorFactory(constants_1.PARAMETER_TYPE.NEXT);
|
|
82
|
-
exports.Principal = paramDecoratorFactory(constants_1.PARAMETER_TYPE.PRINCIPAL);
|
|
83
|
-
function paramDecoratorFactory(parameterType) {
|
|
84
|
-
return (name) => params(parameterType, name);
|
|
85
|
-
}
|
|
86
|
-
function params(type, parameterName) {
|
|
87
|
-
return (target, methodName, index) => {
|
|
88
|
-
let metadataList = {};
|
|
89
|
-
let parameterMetadataList = [];
|
|
90
|
-
const parameterMetadata = {
|
|
91
|
-
index,
|
|
92
|
-
injectRoot: parameterName === undefined,
|
|
93
|
-
parameterName,
|
|
94
|
-
type,
|
|
95
|
-
};
|
|
96
|
-
if (!Reflect.hasOwnMetadata(constants_1.METADATA_KEY.controllerParameter, target.constructor)) {
|
|
97
|
-
parameterMetadataList.unshift(parameterMetadata);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
metadataList = Reflect.getOwnMetadata(constants_1.METADATA_KEY.controllerParameter, target.constructor);
|
|
101
|
-
if (metadataList[methodName]) {
|
|
102
|
-
parameterMetadataList = metadataList[methodName] || [];
|
|
103
|
-
}
|
|
104
|
-
parameterMetadataList.unshift(parameterMetadata);
|
|
105
|
-
}
|
|
106
|
-
metadataList[methodName] = parameterMetadataList;
|
|
107
|
-
Reflect.defineMetadata(constants_1.METADATA_KEY.controllerParameter, metadataList, target.constructor);
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
exports.params = params;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpResponseMessage = void 0;
|
|
4
|
-
class HttpResponseMessage {
|
|
5
|
-
_content;
|
|
6
|
-
_headers = {};
|
|
7
|
-
get headers() {
|
|
8
|
-
return this._headers;
|
|
9
|
-
}
|
|
10
|
-
set headers(headers) {
|
|
11
|
-
this._headers = headers;
|
|
12
|
-
}
|
|
13
|
-
get content() {
|
|
14
|
-
return this._content;
|
|
15
|
-
}
|
|
16
|
-
set content(value) {
|
|
17
|
-
this._content = value;
|
|
18
|
-
}
|
|
19
|
-
_statusCode;
|
|
20
|
-
get statusCode() {
|
|
21
|
-
return this._statusCode;
|
|
22
|
-
}
|
|
23
|
-
set statusCode(code) {
|
|
24
|
-
if (code < 0 || code > 999) {
|
|
25
|
-
throw new Error(`${code} is not a valid status code`);
|
|
26
|
-
}
|
|
27
|
-
this._statusCode = code;
|
|
28
|
-
}
|
|
29
|
-
constructor(statusCode = 200) {
|
|
30
|
-
this.statusCode = statusCode;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.HttpResponseMessage = HttpResponseMessage;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./decorators"), exports);
|