@e22m4u/ts-rest-router 0.1.1 → 0.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/README.md +118 -118
- package/dist/cjs/index.cjs +346 -360
- package/dist/esm/controller-registry.js +28 -28
- package/dist/esm/debuggable-service.d.ts +10 -1
- package/dist/esm/debuggable-service.js +14 -3
- package/dist/esm/decorators/after-action/after-action-decorator.d.ts +9 -0
- package/dist/esm/decorators/{after/after-decorator.js → after-action/after-action-decorator.js} +7 -7
- package/dist/esm/decorators/{before/before-decorator.spec.js → after-action/after-action-decorator.spec.js} +19 -19
- package/dist/esm/decorators/{after/after-metadata.d.ts → after-action/after-action-metadata.d.ts} +4 -4
- package/dist/esm/decorators/after-action/after-action-metadata.js +5 -0
- package/dist/esm/decorators/{after/after-reflector.d.ts → after-action/after-action-reflector.d.ts} +5 -5
- package/dist/esm/decorators/{before/before-reflector.js → after-action/after-action-reflector.js} +6 -6
- package/dist/esm/decorators/{before/before-reflector.spec.js → after-action/after-action-reflector.spec.js} +23 -23
- package/dist/esm/decorators/after-action/index.d.ts +3 -0
- package/dist/esm/decorators/after-action/index.js +3 -0
- package/dist/esm/decorators/before-action/before-action-decorator.d.ts +9 -0
- package/dist/esm/decorators/{before/before-decorator.js → before-action/before-action-decorator.js} +7 -7
- package/dist/esm/decorators/{after/after-decorator.spec.js → before-action/before-action-decorator.spec.js} +19 -19
- package/dist/esm/decorators/{before/before-metadata.d.ts → before-action/before-action-metadata.d.ts} +4 -4
- package/dist/esm/decorators/before-action/before-action-metadata.js +5 -0
- package/dist/esm/decorators/{before/before-reflector.d.ts → before-action/before-action-reflector.d.ts} +5 -5
- package/dist/esm/decorators/{after/after-reflector.js → before-action/before-action-reflector.js} +6 -6
- package/dist/esm/decorators/{after/after-reflector.spec.js → before-action/before-action-reflector.spec.js} +23 -23
- package/dist/esm/decorators/before-action/index.d.ts +3 -0
- package/dist/esm/decorators/before-action/index.js +3 -0
- package/dist/esm/decorators/index.d.ts +4 -4
- package/dist/esm/decorators/index.js +4 -4
- package/dist/esm/decorators/request-context/request-context-decorator.d.ts +4 -4
- package/dist/esm/decorators/request-context/request-context-decorator.js +4 -4
- package/dist/esm/decorators/request-context/request-context-decorator.spec.js +6 -0
- package/dist/esm/decorators/request-data/request-data-decorator.d.ts +10 -10
- package/dist/esm/decorators/request-data/request-data-decorator.js +10 -10
- package/dist/esm/decorators/request-data/request-data-decorator.spec.js +44 -32
- package/dist/esm/decorators/request-data/request-data-metadata.d.ts +1 -1
- package/dist/esm/decorators/rest-action/index.d.ts +3 -0
- package/dist/esm/decorators/rest-action/index.js +3 -0
- package/dist/esm/decorators/rest-action/rest-action-decorator.d.ts +57 -0
- package/dist/esm/decorators/rest-action/rest-action-decorator.js +52 -0
- package/dist/esm/decorators/rest-action/rest-action-decorator.spec.js +401 -0
- package/dist/esm/decorators/{action/action-metadata.d.ts → rest-action/rest-action-metadata.d.ts} +6 -6
- package/dist/esm/decorators/rest-action/rest-action-metadata.js +5 -0
- package/dist/esm/decorators/rest-action/rest-action-reflector.d.ts +22 -0
- package/dist/esm/decorators/{action/action-reflector.js → rest-action/rest-action-reflector.js} +6 -6
- package/dist/esm/decorators/{action/action-reflector.spec.js → rest-action/rest-action-reflector.spec.js} +13 -13
- package/dist/esm/decorators/rest-controller/index.d.ts +3 -0
- package/dist/esm/decorators/rest-controller/index.js +3 -0
- package/dist/esm/decorators/rest-controller/rest-controller-decorator.d.ts +14 -0
- package/dist/esm/decorators/{controller/controller-decorator.js → rest-controller/rest-controller-decorator.js} +5 -5
- package/dist/esm/decorators/{controller/controller-decorator.spec.js → rest-controller/rest-controller-decorator.spec.js} +15 -15
- package/dist/esm/decorators/{controller/controller-metadata.d.ts → rest-controller/rest-controller-metadata.d.ts} +5 -5
- package/dist/esm/decorators/rest-controller/rest-controller-metadata.js +5 -0
- package/dist/esm/decorators/rest-controller/rest-controller-reflector.d.ts +20 -0
- package/dist/esm/decorators/rest-controller/rest-controller-reflector.js +24 -0
- package/dist/esm/decorators/{controller/controller-reflector.spec.js → rest-controller/rest-controller-reflector.spec.js} +12 -12
- package/dist/esm/errors/not-a-controller-error.js +1 -1
- package/dist/esm/types.d.ts +0 -10
- package/dist/esm/utils/index.d.ts +0 -1
- package/dist/esm/utils/index.js +0 -1
- package/package.json +19 -19
- package/src/controller-registry.spec.ts +122 -122
- package/src/controller-registry.ts +33 -35
- package/src/debuggable-service.ts +17 -4
- package/src/decorators/{after/after-decorator.spec.ts → after-action/after-action-decorator.spec.ts} +19 -19
- package/src/decorators/{before/before-decorator.ts → after-action/after-action-decorator.ts} +9 -9
- package/src/decorators/{after/after-metadata.ts → after-action/after-action-metadata.ts} +5 -5
- package/src/decorators/{before/before-reflector.spec.ts → after-action/after-action-reflector.spec.ts} +33 -23
- package/src/decorators/{before/before-reflector.ts → after-action/after-action-reflector.ts} +13 -9
- package/src/decorators/after-action/index.ts +3 -0
- package/src/decorators/{before/before-decorator.spec.ts → before-action/before-action-decorator.spec.ts} +19 -19
- package/src/decorators/{after/after-decorator.ts → before-action/before-action-decorator.ts} +9 -9
- package/src/decorators/before-action/before-action-metadata.ts +17 -0
- package/src/decorators/{after/after-reflector.spec.ts → before-action/before-action-reflector.spec.ts} +40 -23
- package/src/decorators/{after/after-reflector.ts → before-action/before-action-reflector.ts} +18 -9
- package/src/decorators/before-action/index.ts +3 -0
- package/src/decorators/index.ts +4 -4
- package/src/decorators/request-context/request-context-decorator.spec.ts +7 -0
- package/src/decorators/request-context/request-context-decorator.ts +4 -4
- package/src/decorators/request-data/request-data-decorator.spec.ts +45 -32
- package/src/decorators/request-data/request-data-decorator.ts +10 -10
- package/src/decorators/request-data/request-data-metadata.ts +1 -1
- package/src/decorators/rest-action/index.ts +3 -0
- package/src/decorators/rest-action/rest-action-decorator.spec.ts +325 -0
- package/src/decorators/rest-action/rest-action-decorator.ts +166 -0
- package/src/decorators/{action/action-metadata.ts → rest-action/rest-action-metadata.ts} +7 -7
- package/src/decorators/{action/action-reflector.spec.ts → rest-action/rest-action-reflector.spec.ts} +13 -13
- package/src/decorators/rest-action/rest-action-reflector.ts +41 -0
- package/src/decorators/rest-controller/index.ts +3 -0
- package/src/decorators/{controller/controller-decorator.spec.ts → rest-controller/rest-controller-decorator.spec.ts} +16 -16
- package/src/decorators/{controller/controller-decorator.ts → rest-controller/rest-controller-decorator.ts} +14 -10
- package/src/decorators/{controller/controller-metadata.ts → rest-controller/rest-controller-metadata.ts} +6 -7
- package/src/decorators/{controller/controller-reflector.spec.ts → rest-controller/rest-controller-reflector.spec.ts} +21 -12
- package/src/decorators/rest-controller/rest-controller-reflector.ts +32 -0
- package/src/errors/not-a-controller-error.ts +4 -1
- package/src/types.ts +0 -10
- package/src/utils/index.ts +0 -1
- package/README-ru.md +0 -268
- package/dist/esm/decorators/action/action-decorator.d.ts +0 -52
- package/dist/esm/decorators/action/action-decorator.js +0 -62
- package/dist/esm/decorators/action/action-decorator.spec.js +0 -59
- package/dist/esm/decorators/action/action-metadata.js +0 -5
- package/dist/esm/decorators/action/action-reflector.d.ts +0 -22
- package/dist/esm/decorators/action/index.d.ts +0 -3
- package/dist/esm/decorators/action/index.js +0 -3
- package/dist/esm/decorators/after/after-decorator.d.ts +0 -9
- package/dist/esm/decorators/after/after-metadata.js +0 -5
- package/dist/esm/decorators/after/index.d.ts +0 -3
- package/dist/esm/decorators/after/index.js +0 -3
- package/dist/esm/decorators/before/before-decorator.d.ts +0 -9
- package/dist/esm/decorators/before/before-metadata.js +0 -5
- package/dist/esm/decorators/before/index.d.ts +0 -3
- package/dist/esm/decorators/before/index.js +0 -3
- package/dist/esm/decorators/controller/controller-decorator.d.ts +0 -14
- package/dist/esm/decorators/controller/controller-metadata.js +0 -5
- package/dist/esm/decorators/controller/controller-reflector.d.ts +0 -20
- package/dist/esm/decorators/controller/controller-reflector.js +0 -24
- package/dist/esm/decorators/controller/index.d.ts +0 -3
- package/dist/esm/decorators/controller/index.js +0 -3
- package/dist/esm/utils/create-debugger.d.ts +0 -44
- package/dist/esm/utils/create-debugger.js +0 -81
- package/dist/esm/utils/create-debugger.spec.d.ts +0 -1
- package/dist/esm/utils/create-debugger.spec.js +0 -8
- package/src/decorators/action/action-decorator.spec.ts +0 -42
- package/src/decorators/action/action-decorator.ts +0 -98
- package/src/decorators/action/action-reflector.ts +0 -38
- package/src/decorators/action/index.ts +0 -3
- package/src/decorators/after/index.ts +0 -3
- package/src/decorators/before/before-metadata.ts +0 -17
- package/src/decorators/before/index.ts +0 -3
- package/src/decorators/controller/controller-reflector.ts +0 -28
- package/src/decorators/controller/index.ts +0 -3
- package/src/utils/create-debugger.spec.ts +0 -9
- package/src/utils/create-debugger.ts +0 -98
- /package/dist/esm/decorators/{action/action-decorator.spec.d.ts → after-action/after-action-decorator.spec.d.ts} +0 -0
- /package/dist/esm/decorators/{action/action-reflector.spec.d.ts → after-action/after-action-reflector.spec.d.ts} +0 -0
- /package/dist/esm/decorators/{after/after-decorator.spec.d.ts → before-action/before-action-decorator.spec.d.ts} +0 -0
- /package/dist/esm/decorators/{after/after-reflector.spec.d.ts → before-action/before-action-reflector.spec.d.ts} +0 -0
- /package/dist/esm/decorators/{before/before-decorator.spec.d.ts → rest-action/rest-action-decorator.spec.d.ts} +0 -0
- /package/dist/esm/decorators/{before/before-reflector.spec.d.ts → rest-action/rest-action-reflector.spec.d.ts} +0 -0
- /package/dist/esm/decorators/{controller/controller-decorator.spec.d.ts → rest-controller/rest-controller-decorator.spec.d.ts} +0 -0
- /package/dist/esm/decorators/{controller/controller-reflector.spec.d.ts → rest-controller/rest-controller-reflector.spec.d.ts} +0 -0
package/dist/cjs/index.cjs
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __create = Object.create;
|
3
2
|
var __defProp = Object.defineProperty;
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
6
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
9
7
|
var __export = (target, all) => {
|
@@ -18,61 +16,52 @@ var __copyProps = (to, from, except, desc) => {
|
|
18
16
|
}
|
19
17
|
return to;
|
20
18
|
};
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
27
|
-
mod
|
28
|
-
));
|
29
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
30
20
|
|
31
21
|
// dist/esm/index.js
|
32
22
|
var index_exports = {};
|
33
23
|
__export(index_exports, {
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
BEFORE_METADATA_KEY: () => BEFORE_METADATA_KEY,
|
39
|
-
BeforeReflector: () => BeforeReflector,
|
40
|
-
CONTROLLER_METADATA_KEY: () => CONTROLLER_METADATA_KEY,
|
41
|
-
ControllerReflector: () => ControllerReflector,
|
24
|
+
AFTER_ACTION_METADATA_KEY: () => AFTER_ACTION_METADATA_KEY,
|
25
|
+
AfterActionReflector: () => AfterActionReflector,
|
26
|
+
BEFORE_ACTION_METADATA_KEY: () => BEFORE_ACTION_METADATA_KEY,
|
27
|
+
BeforeActionReflector: () => BeforeActionReflector,
|
42
28
|
ControllerRegistry: () => ControllerRegistry,
|
43
29
|
NotAControllerError: () => NotAControllerError,
|
44
30
|
REQUEST_CONTEXT_METADATA_KEY: () => REQUEST_CONTEXT_METADATA_KEY,
|
45
31
|
REQUEST_DATA_METADATA_KEY: () => REQUEST_DATA_METADATA_KEY,
|
32
|
+
REST_ACTIONS_METADATA_KEY: () => REST_ACTIONS_METADATA_KEY,
|
33
|
+
REST_CONTROLLER_METADATA_KEY: () => REST_CONTROLLER_METADATA_KEY,
|
46
34
|
RequestContextReflector: () => RequestContextReflector,
|
47
35
|
RequestDataReflector: () => RequestDataReflector,
|
48
36
|
RequestDataSource: () => RequestDataSource,
|
37
|
+
RestActionReflector: () => RestActionReflector,
|
38
|
+
RestControllerReflector: () => RestControllerReflector,
|
49
39
|
RestRouter: () => RestRouter,
|
50
|
-
|
51
|
-
|
52
|
-
before: () => before,
|
53
|
-
body: () => body,
|
40
|
+
afterAction: () => afterAction,
|
41
|
+
beforeAction: () => beforeAction,
|
54
42
|
capitalize: () => capitalize,
|
55
|
-
controller: () => controller,
|
56
|
-
cookie: () => cookie,
|
57
|
-
cookies: () => cookies,
|
58
|
-
createDebugger: () => createDebugger,
|
59
43
|
createError: () => createError,
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
post: () => post,
|
69
|
-
put: () => put,
|
70
|
-
queries: () => queries,
|
71
|
-
query: () => query,
|
72
|
-
request: () => request,
|
44
|
+
deleteAction: () => deleteAction,
|
45
|
+
getAction: () => getAction,
|
46
|
+
httpRequest: () => httpRequest,
|
47
|
+
httpResponse: () => httpResponse,
|
48
|
+
patchAction: () => patchAction,
|
49
|
+
postAction: () => postAction,
|
50
|
+
putAction: () => putAction,
|
51
|
+
requestBody: () => requestBody,
|
73
52
|
requestContext: () => requestContext,
|
53
|
+
requestCookie: () => requestCookie,
|
54
|
+
requestCookies: () => requestCookies,
|
74
55
|
requestData: () => requestData,
|
75
|
-
|
56
|
+
requestField: () => requestField,
|
57
|
+
requestHeader: () => requestHeader,
|
58
|
+
requestHeaders: () => requestHeaders,
|
59
|
+
requestParam: () => requestParam,
|
60
|
+
requestParams: () => requestParams,
|
61
|
+
requestQueries: () => requestQueries,
|
62
|
+
requestQuery: () => requestQuery,
|
63
|
+
restAction: () => restAction,
|
64
|
+
restController: () => restController,
|
76
65
|
toCamelCase: () => toCamelCase
|
77
66
|
});
|
78
67
|
module.exports = __toCommonJS(index_exports);
|
@@ -97,53 +86,27 @@ function toCamelCase(input) {
|
|
97
86
|
}
|
98
87
|
__name(toCamelCase, "toCamelCase");
|
99
88
|
|
100
|
-
// dist/esm/utils/create-debugger.js
|
101
|
-
var import_util = require("util");
|
102
|
-
var import_debug = __toESM(require("debug"), 1);
|
103
|
-
var import_js_format2 = require("@e22m4u/js-format");
|
104
|
-
function colorizeString(input) {
|
105
|
-
const c = Number(import_debug.default["selectColor"](input));
|
106
|
-
const colorCode = "\x1B[3" + (c < 8 ? c : "8;5;" + c);
|
107
|
-
return `${colorCode};1m${input}\x1B[0m`;
|
108
|
-
}
|
109
|
-
__name(colorizeString, "colorizeString");
|
110
|
-
function createDebugger(name) {
|
111
|
-
const debuggerName = `tsRestRouter:${name}`;
|
112
|
-
const debug = (0, import_debug.default)(debuggerName);
|
113
|
-
return function(messageOrData, ...args) {
|
114
|
-
let prefix = "";
|
115
|
-
if (typeof this === "string") {
|
116
|
-
const isDebugUsesColors = debug.useColors;
|
117
|
-
prefix = isDebugUsesColors ? colorizeString(`[${this}] `) : `[${this}] `;
|
118
|
-
}
|
119
|
-
if (typeof messageOrData === "string") {
|
120
|
-
const interpolatedMessage = (0, import_js_format2.format)(messageOrData, ...args);
|
121
|
-
return debug(prefix + interpolatedMessage);
|
122
|
-
}
|
123
|
-
const inspectOptions = {
|
124
|
-
showHidden: false,
|
125
|
-
depth: null,
|
126
|
-
colors: true,
|
127
|
-
compact: false
|
128
|
-
};
|
129
|
-
const multiString = (0, import_util.inspect)(messageOrData, inspectOptions);
|
130
|
-
const rows = multiString.split("\n");
|
131
|
-
const colorizedDebuggerName = colorizeString(debuggerName);
|
132
|
-
[...args, ...rows].forEach((v) => console.log(` ${colorizedDebuggerName} ${prefix}${v}`));
|
133
|
-
};
|
134
|
-
}
|
135
|
-
__name(createDebugger, "createDebugger");
|
136
|
-
|
137
89
|
// dist/esm/rest-router.js
|
138
90
|
var import_js_trie_router3 = require("@e22m4u/js-trie-router");
|
139
91
|
|
140
92
|
// dist/esm/debuggable-service.js
|
141
93
|
var import_js_service = require("@e22m4u/js-service");
|
94
|
+
var import_js_debug = require("@e22m4u/js-debug");
|
142
95
|
var _DebuggableService = class _DebuggableService extends import_js_service.Service {
|
143
96
|
/**
|
144
97
|
* Debug.
|
145
98
|
*/
|
146
99
|
debug;
|
100
|
+
/**
|
101
|
+
* Возвращает функцию-отладчик с сегментом пространства имен
|
102
|
+
* указанного в параметре метода.
|
103
|
+
*
|
104
|
+
* @param method
|
105
|
+
* @protected
|
106
|
+
*/
|
107
|
+
getDebuggerFor(method) {
|
108
|
+
return this.debug.withHash().withNs(method.name);
|
109
|
+
}
|
147
110
|
/**
|
148
111
|
* Constructor.
|
149
112
|
*
|
@@ -152,25 +115,42 @@ var _DebuggableService = class _DebuggableService extends import_js_service.Serv
|
|
152
115
|
constructor(container) {
|
153
116
|
super(container);
|
154
117
|
const serviceName = toCamelCase(this.constructor.name);
|
155
|
-
this.debug = createDebugger(serviceName);
|
156
|
-
this.debug.
|
118
|
+
this.debug = (0, import_js_debug.createDebugger)("tsRestRouter", serviceName);
|
119
|
+
const debug = this.debug.withNs("constructor").withHash();
|
120
|
+
debug("Service created.");
|
157
121
|
}
|
158
122
|
};
|
159
123
|
__name(_DebuggableService, "DebuggableService");
|
160
124
|
var DebuggableService = _DebuggableService;
|
161
125
|
|
162
126
|
// dist/esm/controller-registry.js
|
163
|
-
var
|
127
|
+
var import_js_format3 = require("@e22m4u/js-format");
|
164
128
|
var import_js_trie_router2 = require("@e22m4u/js-trie-router");
|
165
129
|
var import_ts_data_schema2 = require("@e22m4u/ts-data-schema");
|
130
|
+
var import_ts_data_schema3 = require("@e22m4u/ts-data-schema");
|
166
131
|
|
167
|
-
// dist/esm/
|
132
|
+
// dist/esm/errors/not-a-controller-error.js
|
133
|
+
var import_js_format2 = require("@e22m4u/js-format");
|
134
|
+
var _NotAControllerError = class _NotAControllerError extends import_js_format2.Errorf {
|
135
|
+
/**
|
136
|
+
* Constructor.
|
137
|
+
*
|
138
|
+
* @param value
|
139
|
+
*/
|
140
|
+
constructor(value) {
|
141
|
+
super("%v is not a controller, do use @restController decorator on it.", value);
|
142
|
+
}
|
143
|
+
};
|
144
|
+
__name(_NotAControllerError, "NotAControllerError");
|
145
|
+
var NotAControllerError = _NotAControllerError;
|
146
|
+
|
147
|
+
// dist/esm/decorators/rest-action/rest-action-metadata.js
|
168
148
|
var import_ts_reflector = require("@e22m4u/ts-reflector");
|
169
|
-
var
|
149
|
+
var REST_ACTIONS_METADATA_KEY = new import_ts_reflector.MetadataKey("restActionsMetadataKey");
|
170
150
|
|
171
|
-
// dist/esm/decorators/
|
151
|
+
// dist/esm/decorators/rest-action/rest-action-reflector.js
|
172
152
|
var import_ts_reflector2 = require("@e22m4u/ts-reflector");
|
173
|
-
var
|
153
|
+
var _RestActionReflector = class _RestActionReflector {
|
174
154
|
/**
|
175
155
|
* Set metadata.
|
176
156
|
*
|
@@ -178,60 +158,112 @@ var _AfterReflector = class _AfterReflector {
|
|
178
158
|
* @param target
|
179
159
|
* @param propertyKey
|
180
160
|
*/
|
181
|
-
static
|
182
|
-
const
|
183
|
-
const
|
184
|
-
|
161
|
+
static setMetadata(metadata, target, propertyKey) {
|
162
|
+
const oldMap = import_ts_reflector2.Reflector.getOwnMetadata(REST_ACTIONS_METADATA_KEY, target);
|
163
|
+
const newMap = new Map(oldMap);
|
164
|
+
newMap.set(propertyKey, metadata);
|
165
|
+
import_ts_reflector2.Reflector.defineMetadata(REST_ACTIONS_METADATA_KEY, newMap, target);
|
185
166
|
}
|
186
167
|
/**
|
187
168
|
* Get metadata.
|
188
169
|
*
|
189
170
|
* @param target
|
190
|
-
* @param propertyKey
|
191
171
|
*/
|
192
|
-
static getMetadata(target
|
193
|
-
const metadata = import_ts_reflector2.Reflector.getOwnMetadata(
|
194
|
-
return metadata ??
|
172
|
+
static getMetadata(target) {
|
173
|
+
const metadata = import_ts_reflector2.Reflector.getOwnMetadata(REST_ACTIONS_METADATA_KEY, target);
|
174
|
+
return metadata ?? /* @__PURE__ */ new Map();
|
195
175
|
}
|
196
176
|
};
|
197
|
-
__name(
|
198
|
-
var
|
177
|
+
__name(_RestActionReflector, "RestActionReflector");
|
178
|
+
var RestActionReflector = _RestActionReflector;
|
199
179
|
|
200
|
-
// dist/esm/decorators/
|
180
|
+
// dist/esm/decorators/rest-action/rest-action-decorator.js
|
181
|
+
var import_js_trie_router = require("@e22m4u/js-trie-router");
|
201
182
|
var import_ts_reflector3 = require("@e22m4u/ts-reflector");
|
202
183
|
var import_ts_reflector4 = require("@e22m4u/ts-reflector");
|
203
|
-
function
|
184
|
+
function restAction(options) {
|
204
185
|
return function(target, propertyKey, descriptor) {
|
205
186
|
const decoratorType = (0, import_ts_reflector4.getDecoratorTargetType)(target, propertyKey, descriptor);
|
206
|
-
if (decoratorType
|
207
|
-
|
208
|
-
|
209
|
-
AfterReflector.addMetadata({ propertyKey, middleware }, target.constructor, propertyKey);
|
210
|
-
} else {
|
211
|
-
throw new Error("@after decorator is only supported on a class or an instance method.");
|
212
|
-
}
|
187
|
+
if (decoratorType !== import_ts_reflector3.DecoratorTargetType.INSTANCE_METHOD)
|
188
|
+
throw new Error("@restAction decorator is only supported on an instance method.");
|
189
|
+
RestActionReflector.setMetadata({ ...options, propertyKey }, target.constructor, propertyKey);
|
213
190
|
};
|
214
191
|
}
|
215
|
-
__name(
|
192
|
+
__name(restAction, "restAction");
|
193
|
+
function getAction(pathOrOptions, options) {
|
194
|
+
let path = typeof pathOrOptions === "string" ? pathOrOptions : "";
|
195
|
+
options = typeof pathOrOptions === "object" ? pathOrOptions : options;
|
196
|
+
if (typeof options === "object" && !path && options.path != null)
|
197
|
+
path = options.path;
|
198
|
+
return restAction({ ...options, path, method: import_js_trie_router.HttpMethod.GET });
|
199
|
+
}
|
200
|
+
__name(getAction, "getAction");
|
201
|
+
function postAction(pathOrOptions, options) {
|
202
|
+
let path = typeof pathOrOptions === "string" ? pathOrOptions : "";
|
203
|
+
options = typeof pathOrOptions === "object" ? pathOrOptions : options;
|
204
|
+
if (typeof options === "object" && !path && options.path != null)
|
205
|
+
path = options.path;
|
206
|
+
return restAction({ ...options, path, method: import_js_trie_router.HttpMethod.POST });
|
207
|
+
}
|
208
|
+
__name(postAction, "postAction");
|
209
|
+
function putAction(pathOrOptions, options) {
|
210
|
+
let path = typeof pathOrOptions === "string" ? pathOrOptions : "";
|
211
|
+
options = typeof pathOrOptions === "object" ? pathOrOptions : options;
|
212
|
+
if (typeof options === "object" && !path && options.path != null)
|
213
|
+
path = options.path;
|
214
|
+
return restAction({ ...options, path, method: import_js_trie_router.HttpMethod.PUT });
|
215
|
+
}
|
216
|
+
__name(putAction, "putAction");
|
217
|
+
function patchAction(pathOrOptions, options) {
|
218
|
+
let path = typeof pathOrOptions === "string" ? pathOrOptions : "";
|
219
|
+
options = typeof pathOrOptions === "object" ? pathOrOptions : options;
|
220
|
+
if (typeof options === "object" && !path && options.path != null)
|
221
|
+
path = options.path;
|
222
|
+
return restAction({ ...options, path, method: import_js_trie_router.HttpMethod.PATCH });
|
223
|
+
}
|
224
|
+
__name(patchAction, "patchAction");
|
225
|
+
function deleteAction(pathOrOptions, options) {
|
226
|
+
let path = typeof pathOrOptions === "string" ? pathOrOptions : "";
|
227
|
+
options = typeof pathOrOptions === "object" ? pathOrOptions : options;
|
228
|
+
if (typeof options === "object" && !path && options.path != null)
|
229
|
+
path = options.path;
|
230
|
+
return restAction({ ...options, path, method: import_js_trie_router.HttpMethod.DELETE });
|
231
|
+
}
|
232
|
+
__name(deleteAction, "deleteAction");
|
216
233
|
|
217
|
-
// dist/esm/decorators/
|
234
|
+
// dist/esm/decorators/request-data/request-data-metadata.js
|
218
235
|
var import_ts_reflector5 = require("@e22m4u/ts-reflector");
|
219
|
-
var
|
236
|
+
var RequestDataSource;
|
237
|
+
(function(RequestDataSource2) {
|
238
|
+
RequestDataSource2["PARAMS"] = "params";
|
239
|
+
RequestDataSource2["QUERY"] = "query";
|
240
|
+
RequestDataSource2["HEADERS"] = "headers";
|
241
|
+
RequestDataSource2["COOKIE"] = "cookie";
|
242
|
+
RequestDataSource2["BODY"] = "body";
|
243
|
+
})(RequestDataSource || (RequestDataSource = {}));
|
244
|
+
var REQUEST_DATA_METADATA_KEY = new import_ts_reflector5.MetadataKey("requestDataMetadataKey");
|
220
245
|
|
221
|
-
// dist/esm/decorators/
|
246
|
+
// dist/esm/decorators/request-data/request-data-decorator.js
|
247
|
+
var import_ts_data_schema = require("@e22m4u/ts-data-schema");
|
248
|
+
var import_ts_reflector7 = require("@e22m4u/ts-reflector");
|
249
|
+
var import_ts_reflector8 = require("@e22m4u/ts-reflector");
|
250
|
+
|
251
|
+
// dist/esm/decorators/request-data/request-data-reflector.js
|
222
252
|
var import_ts_reflector6 = require("@e22m4u/ts-reflector");
|
223
|
-
var
|
253
|
+
var _RequestDataReflector = class _RequestDataReflector {
|
224
254
|
/**
|
225
255
|
* Set metadata.
|
226
256
|
*
|
227
257
|
* @param metadata
|
228
258
|
* @param target
|
259
|
+
* @param index
|
229
260
|
* @param propertyKey
|
230
261
|
*/
|
231
|
-
static
|
232
|
-
const
|
233
|
-
const
|
234
|
-
|
262
|
+
static setMetadata(metadata, target, index, propertyKey) {
|
263
|
+
const oldMap = import_ts_reflector6.Reflector.getOwnMetadata(REQUEST_DATA_METADATA_KEY, target, propertyKey);
|
264
|
+
const newMap = new Map(oldMap);
|
265
|
+
newMap.set(index, metadata);
|
266
|
+
import_ts_reflector6.Reflector.defineMetadata(REQUEST_DATA_METADATA_KEY, newMap, target, propertyKey);
|
235
267
|
}
|
236
268
|
/**
|
237
269
|
* Get metadata.
|
@@ -240,37 +272,78 @@ var _BeforeReflector = class _BeforeReflector {
|
|
240
272
|
* @param propertyKey
|
241
273
|
*/
|
242
274
|
static getMetadata(target, propertyKey) {
|
243
|
-
const metadata = import_ts_reflector6.Reflector.getOwnMetadata(
|
244
|
-
return metadata ??
|
275
|
+
const metadata = import_ts_reflector6.Reflector.getOwnMetadata(REQUEST_DATA_METADATA_KEY, target, propertyKey);
|
276
|
+
return metadata ?? /* @__PURE__ */ new Map();
|
245
277
|
}
|
246
278
|
};
|
247
|
-
__name(
|
248
|
-
var
|
279
|
+
__name(_RequestDataReflector, "RequestDataReflector");
|
280
|
+
var RequestDataReflector = _RequestDataReflector;
|
249
281
|
|
250
|
-
// dist/esm/decorators/
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
282
|
+
// dist/esm/decorators/request-data/request-data-decorator.js
|
283
|
+
function requestData(options) {
|
284
|
+
return function(target, propertyKey, indexOrDescriptor) {
|
285
|
+
const decoratorType = (0, import_ts_reflector8.getDecoratorTargetType)(target, propertyKey, indexOrDescriptor);
|
286
|
+
if (decoratorType !== import_ts_reflector7.DecoratorTargetType.INSTANCE_METHOD_PARAMETER)
|
287
|
+
throw new Error("@requestData decorator is only supported on an instance method parameter.");
|
288
|
+
RequestDataReflector.setMetadata(options, target.constructor, indexOrDescriptor, propertyKey);
|
289
|
+
};
|
290
|
+
}
|
291
|
+
__name(requestData, "requestData");
|
292
|
+
function createRequestDataDecoratorWithSource(source) {
|
293
|
+
return function() {
|
294
|
+
const schema = { type: import_ts_data_schema.DataType.OBJECT };
|
295
|
+
return requestData({ schema, source });
|
296
|
+
};
|
297
|
+
}
|
298
|
+
__name(createRequestDataDecoratorWithSource, "createRequestDataDecoratorWithSource");
|
299
|
+
function createRequestDataPropertyDecoratorWithSource(source) {
|
300
|
+
return function(propertyKey, schemaOrType) {
|
301
|
+
const properties = {};
|
302
|
+
const rootSchema = { type: import_ts_data_schema.DataType.OBJECT };
|
303
|
+
if (typeof schemaOrType === "object") {
|
304
|
+
properties[propertyKey] = schemaOrType;
|
305
|
+
rootSchema.properties = properties;
|
306
|
+
} else if (typeof schemaOrType === "string") {
|
307
|
+
properties[propertyKey] = { type: schemaOrType };
|
308
|
+
rootSchema.properties = properties;
|
262
309
|
}
|
310
|
+
return requestData({
|
311
|
+
source,
|
312
|
+
schema: rootSchema,
|
313
|
+
property: propertyKey
|
314
|
+
});
|
263
315
|
};
|
264
316
|
}
|
265
|
-
__name(
|
317
|
+
__name(createRequestDataPropertyDecoratorWithSource, "createRequestDataPropertyDecoratorWithSource");
|
318
|
+
var requestParams = createRequestDataDecoratorWithSource(RequestDataSource.PARAMS);
|
319
|
+
var requestParam = createRequestDataPropertyDecoratorWithSource(RequestDataSource.PARAMS);
|
320
|
+
var requestQueries = createRequestDataDecoratorWithSource(RequestDataSource.QUERY);
|
321
|
+
var requestQuery = createRequestDataPropertyDecoratorWithSource(RequestDataSource.QUERY);
|
322
|
+
var requestHeaders = createRequestDataDecoratorWithSource(RequestDataSource.HEADERS);
|
323
|
+
var requestHeader = createRequestDataPropertyDecoratorWithSource(RequestDataSource.HEADERS);
|
324
|
+
var requestCookies = createRequestDataDecoratorWithSource(RequestDataSource.COOKIE);
|
325
|
+
var requestCookie = createRequestDataPropertyDecoratorWithSource(RequestDataSource.COOKIE);
|
326
|
+
var requestField = createRequestDataPropertyDecoratorWithSource(RequestDataSource.BODY);
|
327
|
+
function requestBody(schemaOrType) {
|
328
|
+
let schema;
|
329
|
+
if (typeof schemaOrType === "object") {
|
330
|
+
schema = schemaOrType;
|
331
|
+
} else if (typeof schemaOrType === "string") {
|
332
|
+
schema = { type: schemaOrType };
|
333
|
+
} else {
|
334
|
+
schema = { type: import_ts_data_schema.DataType.ANY };
|
335
|
+
}
|
336
|
+
return requestData({ schema, source: RequestDataSource.BODY });
|
337
|
+
}
|
338
|
+
__name(requestBody, "requestBody");
|
266
339
|
|
267
|
-
// dist/esm/decorators/action/action-metadata.js
|
340
|
+
// dist/esm/decorators/after-action/after-action-metadata.js
|
268
341
|
var import_ts_reflector9 = require("@e22m4u/ts-reflector");
|
269
|
-
var
|
342
|
+
var AFTER_ACTION_METADATA_KEY = new import_ts_reflector9.MetadataKey("afterActionMetadataKey");
|
270
343
|
|
271
|
-
// dist/esm/decorators/action/action-reflector.js
|
344
|
+
// dist/esm/decorators/after-action/after-action-reflector.js
|
272
345
|
var import_ts_reflector10 = require("@e22m4u/ts-reflector");
|
273
|
-
var
|
346
|
+
var _AfterActionReflector = class _AfterActionReflector {
|
274
347
|
/**
|
275
348
|
* Set metadata.
|
276
349
|
*
|
@@ -278,211 +351,143 @@ var _ActionReflector = class _ActionReflector {
|
|
278
351
|
* @param target
|
279
352
|
* @param propertyKey
|
280
353
|
*/
|
281
|
-
static
|
282
|
-
const
|
283
|
-
const
|
284
|
-
|
285
|
-
import_ts_reflector10.Reflector.defineMetadata(ACTIONS_METADATA_KEY, newMap, target);
|
354
|
+
static addMetadata(metadata, target, propertyKey) {
|
355
|
+
const oldArray = import_ts_reflector10.Reflector.getOwnMetadata(AFTER_ACTION_METADATA_KEY, target, propertyKey) ?? [];
|
356
|
+
const newArray = [metadata, ...oldArray];
|
357
|
+
import_ts_reflector10.Reflector.defineMetadata(AFTER_ACTION_METADATA_KEY, newArray, target, propertyKey);
|
286
358
|
}
|
287
359
|
/**
|
288
360
|
* Get metadata.
|
289
361
|
*
|
290
362
|
* @param target
|
363
|
+
* @param propertyKey
|
291
364
|
*/
|
292
|
-
static getMetadata(target) {
|
293
|
-
const metadata = import_ts_reflector10.Reflector.getOwnMetadata(
|
294
|
-
return metadata ??
|
365
|
+
static getMetadata(target, propertyKey) {
|
366
|
+
const metadata = import_ts_reflector10.Reflector.getOwnMetadata(AFTER_ACTION_METADATA_KEY, target, propertyKey);
|
367
|
+
return metadata ?? [];
|
295
368
|
}
|
296
369
|
};
|
297
|
-
__name(
|
298
|
-
var
|
370
|
+
__name(_AfterActionReflector, "AfterActionReflector");
|
371
|
+
var AfterActionReflector = _AfterActionReflector;
|
299
372
|
|
300
|
-
// dist/esm/decorators/action/action-decorator.js
|
301
|
-
var import_js_trie_router = require("@e22m4u/js-trie-router");
|
373
|
+
// dist/esm/decorators/after-action/after-action-decorator.js
|
302
374
|
var import_ts_reflector11 = require("@e22m4u/ts-reflector");
|
303
375
|
var import_ts_reflector12 = require("@e22m4u/ts-reflector");
|
304
|
-
function
|
376
|
+
function afterAction(middleware) {
|
305
377
|
return function(target, propertyKey, descriptor) {
|
306
378
|
const decoratorType = (0, import_ts_reflector12.getDecoratorTargetType)(target, propertyKey, descriptor);
|
307
|
-
if (decoratorType
|
308
|
-
|
309
|
-
|
379
|
+
if (decoratorType === import_ts_reflector11.DecoratorTargetType.CONSTRUCTOR) {
|
380
|
+
AfterActionReflector.addMetadata({ middleware }, target);
|
381
|
+
} else if (decoratorType === import_ts_reflector11.DecoratorTargetType.INSTANCE_METHOD) {
|
382
|
+
AfterActionReflector.addMetadata({ propertyKey, middleware }, target.constructor, propertyKey);
|
383
|
+
} else {
|
384
|
+
throw new Error("@afterAction decorator is only supported on a class or an instance method.");
|
385
|
+
}
|
310
386
|
};
|
311
387
|
}
|
312
|
-
__name(
|
313
|
-
var get = /* @__PURE__ */ __name((path, options) => {
|
314
|
-
return action({ ...options, path, method: import_js_trie_router.HttpMethod.GET });
|
315
|
-
}, "get");
|
316
|
-
var post = /* @__PURE__ */ __name((path, options) => {
|
317
|
-
return action({ ...options, path, method: import_js_trie_router.HttpMethod.POST });
|
318
|
-
}, "post");
|
319
|
-
var put = /* @__PURE__ */ __name((path, options) => {
|
320
|
-
return action({ ...options, path, method: import_js_trie_router.HttpMethod.PUT });
|
321
|
-
}, "put");
|
322
|
-
var patch = /* @__PURE__ */ __name((path, options) => {
|
323
|
-
return action({ ...options, path, method: import_js_trie_router.HttpMethod.PATCH });
|
324
|
-
}, "patch");
|
325
|
-
var del = /* @__PURE__ */ __name((path, options) => {
|
326
|
-
return action({ ...options, path, method: import_js_trie_router.HttpMethod.DELETE });
|
327
|
-
}, "del");
|
388
|
+
__name(afterAction, "afterAction");
|
328
389
|
|
329
|
-
// dist/esm/decorators/
|
390
|
+
// dist/esm/decorators/before-action/before-action-metadata.js
|
330
391
|
var import_ts_reflector13 = require("@e22m4u/ts-reflector");
|
331
|
-
var
|
332
|
-
|
333
|
-
// dist/esm/decorators/controller/controller-decorator.js
|
334
|
-
var import_ts_reflector15 = require("@e22m4u/ts-reflector");
|
335
|
-
var import_ts_reflector16 = require("@e22m4u/ts-reflector");
|
392
|
+
var BEFORE_ACTION_METADATA_KEY = new import_ts_reflector13.MetadataKey("beforeActionMetadataKey");
|
336
393
|
|
337
|
-
// dist/esm/decorators/
|
394
|
+
// dist/esm/decorators/before-action/before-action-reflector.js
|
338
395
|
var import_ts_reflector14 = require("@e22m4u/ts-reflector");
|
339
|
-
var
|
396
|
+
var _BeforeActionReflector = class _BeforeActionReflector {
|
340
397
|
/**
|
341
398
|
* Set metadata.
|
342
399
|
*
|
343
400
|
* @param metadata
|
344
401
|
* @param target
|
402
|
+
* @param propertyKey
|
345
403
|
*/
|
346
|
-
static
|
347
|
-
|
404
|
+
static addMetadata(metadata, target, propertyKey) {
|
405
|
+
const oldArray = import_ts_reflector14.Reflector.getOwnMetadata(BEFORE_ACTION_METADATA_KEY, target, propertyKey) ?? [];
|
406
|
+
const newArray = [metadata, ...oldArray];
|
407
|
+
import_ts_reflector14.Reflector.defineMetadata(BEFORE_ACTION_METADATA_KEY, newArray, target, propertyKey);
|
348
408
|
}
|
349
409
|
/**
|
350
410
|
* Get metadata.
|
351
411
|
*
|
352
412
|
* @param target
|
413
|
+
* @param propertyKey
|
353
414
|
*/
|
354
|
-
static getMetadata(target) {
|
355
|
-
|
415
|
+
static getMetadata(target, propertyKey) {
|
416
|
+
const metadata = import_ts_reflector14.Reflector.getOwnMetadata(BEFORE_ACTION_METADATA_KEY, target, propertyKey);
|
417
|
+
return metadata ?? [];
|
356
418
|
}
|
357
419
|
};
|
358
|
-
__name(
|
359
|
-
var
|
420
|
+
__name(_BeforeActionReflector, "BeforeActionReflector");
|
421
|
+
var BeforeActionReflector = _BeforeActionReflector;
|
360
422
|
|
361
|
-
// dist/esm/decorators/
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
if (
|
368
|
-
|
369
|
-
|
370
|
-
}
|
371
|
-
|
372
|
-
|
373
|
-
} else if (typeof pathOrOptions === "object") {
|
374
|
-
options = pathOrOptions;
|
423
|
+
// dist/esm/decorators/before-action/before-action-decorator.js
|
424
|
+
var import_ts_reflector15 = require("@e22m4u/ts-reflector");
|
425
|
+
var import_ts_reflector16 = require("@e22m4u/ts-reflector");
|
426
|
+
function beforeAction(middleware) {
|
427
|
+
return function(target, propertyKey, descriptor) {
|
428
|
+
const decoratorType = (0, import_ts_reflector16.getDecoratorTargetType)(target, propertyKey, descriptor);
|
429
|
+
if (decoratorType === import_ts_reflector15.DecoratorTargetType.CONSTRUCTOR) {
|
430
|
+
BeforeActionReflector.addMetadata({ middleware }, target);
|
431
|
+
} else if (decoratorType === import_ts_reflector15.DecoratorTargetType.INSTANCE_METHOD) {
|
432
|
+
BeforeActionReflector.addMetadata({ propertyKey, middleware }, target.constructor, propertyKey);
|
433
|
+
} else {
|
434
|
+
throw new Error("@beforeAction decorator is only supported on a class or an instance method.");
|
375
435
|
}
|
376
|
-
ControllerReflector.setMetadata({ ...options, className: target.name }, target);
|
377
436
|
};
|
378
437
|
}
|
379
|
-
__name(
|
438
|
+
__name(beforeAction, "beforeAction");
|
380
439
|
|
381
|
-
// dist/esm/decorators/
|
440
|
+
// dist/esm/decorators/rest-controller/rest-controller-metadata.js
|
382
441
|
var import_ts_reflector17 = require("@e22m4u/ts-reflector");
|
383
|
-
var
|
384
|
-
(function(RequestDataSource2) {
|
385
|
-
RequestDataSource2["PARAMS"] = "params";
|
386
|
-
RequestDataSource2["QUERY"] = "query";
|
387
|
-
RequestDataSource2["HEADERS"] = "headers";
|
388
|
-
RequestDataSource2["COOKIE"] = "cookie";
|
389
|
-
RequestDataSource2["BODY"] = "body";
|
390
|
-
})(RequestDataSource || (RequestDataSource = {}));
|
391
|
-
var REQUEST_DATA_METADATA_KEY = new import_ts_reflector17.MetadataKey("requestDataMetadataKey");
|
442
|
+
var REST_CONTROLLER_METADATA_KEY = new import_ts_reflector17.MetadataKey("restControllerMetadataKey");
|
392
443
|
|
393
|
-
// dist/esm/decorators/
|
394
|
-
var import_ts_data_schema = require("@e22m4u/ts-data-schema");
|
444
|
+
// dist/esm/decorators/rest-controller/rest-controller-decorator.js
|
395
445
|
var import_ts_reflector19 = require("@e22m4u/ts-reflector");
|
396
446
|
var import_ts_reflector20 = require("@e22m4u/ts-reflector");
|
397
447
|
|
398
|
-
// dist/esm/decorators/
|
448
|
+
// dist/esm/decorators/rest-controller/rest-controller-reflector.js
|
399
449
|
var import_ts_reflector18 = require("@e22m4u/ts-reflector");
|
400
|
-
var
|
450
|
+
var _RestControllerReflector = class _RestControllerReflector {
|
401
451
|
/**
|
402
452
|
* Set metadata.
|
403
453
|
*
|
404
454
|
* @param metadata
|
405
455
|
* @param target
|
406
|
-
* @param index
|
407
|
-
* @param propertyKey
|
408
456
|
*/
|
409
|
-
static setMetadata(metadata, target
|
410
|
-
|
411
|
-
const newMap = new Map(oldMap);
|
412
|
-
newMap.set(index, metadata);
|
413
|
-
import_ts_reflector18.Reflector.defineMetadata(REQUEST_DATA_METADATA_KEY, newMap, target, propertyKey);
|
457
|
+
static setMetadata(metadata, target) {
|
458
|
+
return import_ts_reflector18.Reflector.defineMetadata(REST_CONTROLLER_METADATA_KEY, metadata, target);
|
414
459
|
}
|
415
460
|
/**
|
416
461
|
* Get metadata.
|
417
462
|
*
|
418
463
|
* @param target
|
419
|
-
* @param propertyKey
|
420
464
|
*/
|
421
|
-
static getMetadata(target
|
422
|
-
|
423
|
-
return metadata ?? /* @__PURE__ */ new Map();
|
465
|
+
static getMetadata(target) {
|
466
|
+
return import_ts_reflector18.Reflector.getOwnMetadata(REST_CONTROLLER_METADATA_KEY, target);
|
424
467
|
}
|
425
468
|
};
|
426
|
-
__name(
|
427
|
-
var
|
469
|
+
__name(_RestControllerReflector, "RestControllerReflector");
|
470
|
+
var RestControllerReflector = _RestControllerReflector;
|
428
471
|
|
429
|
-
// dist/esm/decorators/
|
430
|
-
function
|
431
|
-
return function(target
|
432
|
-
const decoratorType = (0, import_ts_reflector20.getDecoratorTargetType)(target
|
433
|
-
if (decoratorType !== import_ts_reflector19.DecoratorTargetType.
|
434
|
-
throw new Error("@
|
435
|
-
|
436
|
-
|
437
|
-
}
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
};
|
444
|
-
}
|
445
|
-
__name(createRequestDataDecoratorWithSource, "createRequestDataDecoratorWithSource");
|
446
|
-
function createRequestDataPropertyDecoratorWithSource(source) {
|
447
|
-
return function(propertyKey, schemaOrType) {
|
448
|
-
const properties = {};
|
449
|
-
const rootSchema = { type: import_ts_data_schema.DataType.OBJECT };
|
450
|
-
if (typeof schemaOrType === "object") {
|
451
|
-
properties[propertyKey] = schemaOrType;
|
452
|
-
rootSchema.properties = properties;
|
453
|
-
} else if (typeof schemaOrType === "string") {
|
454
|
-
properties[propertyKey] = { type: schemaOrType };
|
455
|
-
rootSchema.properties = properties;
|
472
|
+
// dist/esm/decorators/rest-controller/rest-controller-decorator.js
|
473
|
+
function restController(pathOrOptions, options) {
|
474
|
+
return function(target) {
|
475
|
+
const decoratorType = (0, import_ts_reflector20.getDecoratorTargetType)(target);
|
476
|
+
if (decoratorType !== import_ts_reflector19.DecoratorTargetType.CONSTRUCTOR)
|
477
|
+
throw new Error("@restController decorator is only supported on a class.");
|
478
|
+
if (typeof pathOrOptions === "string") {
|
479
|
+
if (!options) {
|
480
|
+
options = { path: pathOrOptions };
|
481
|
+
} else {
|
482
|
+
options.path = pathOrOptions;
|
483
|
+
}
|
484
|
+
} else if (typeof pathOrOptions === "object") {
|
485
|
+
options = pathOrOptions;
|
456
486
|
}
|
457
|
-
|
458
|
-
source,
|
459
|
-
schema: rootSchema,
|
460
|
-
property: propertyKey
|
461
|
-
});
|
487
|
+
RestControllerReflector.setMetadata({ ...options, className: target.name }, target);
|
462
488
|
};
|
463
489
|
}
|
464
|
-
__name(
|
465
|
-
var params = createRequestDataDecoratorWithSource(RequestDataSource.PARAMS);
|
466
|
-
var param = createRequestDataPropertyDecoratorWithSource(RequestDataSource.PARAMS);
|
467
|
-
var queries = createRequestDataDecoratorWithSource(RequestDataSource.QUERY);
|
468
|
-
var query = createRequestDataPropertyDecoratorWithSource(RequestDataSource.QUERY);
|
469
|
-
var headers = createRequestDataDecoratorWithSource(RequestDataSource.HEADERS);
|
470
|
-
var header = createRequestDataPropertyDecoratorWithSource(RequestDataSource.HEADERS);
|
471
|
-
var cookies = createRequestDataDecoratorWithSource(RequestDataSource.COOKIE);
|
472
|
-
var cookie = createRequestDataPropertyDecoratorWithSource(RequestDataSource.COOKIE);
|
473
|
-
var field = createRequestDataPropertyDecoratorWithSource(RequestDataSource.BODY);
|
474
|
-
function body(schemaOrType) {
|
475
|
-
let schema;
|
476
|
-
if (typeof schemaOrType === "object") {
|
477
|
-
schema = schemaOrType;
|
478
|
-
} else if (typeof schemaOrType === "string") {
|
479
|
-
schema = { type: schemaOrType };
|
480
|
-
} else {
|
481
|
-
schema = { type: import_ts_data_schema.DataType.ANY };
|
482
|
-
}
|
483
|
-
return requestData({ schema, source: RequestDataSource.BODY });
|
484
|
-
}
|
485
|
-
__name(body, "body");
|
490
|
+
__name(restController, "restController");
|
486
491
|
|
487
492
|
// dist/esm/decorators/request-context/request-context-metadata.js
|
488
493
|
var import_ts_reflector21 = require("@e22m4u/ts-reflector");
|
@@ -533,32 +538,14 @@ function requestContext(propertyName) {
|
|
533
538
|
};
|
534
539
|
}
|
535
540
|
__name(requestContext, "requestContext");
|
536
|
-
function
|
541
|
+
function httpRequest() {
|
537
542
|
return requestContext("req");
|
538
543
|
}
|
539
|
-
__name(
|
540
|
-
function
|
544
|
+
__name(httpRequest, "httpRequest");
|
545
|
+
function httpResponse() {
|
541
546
|
return requestContext("res");
|
542
547
|
}
|
543
|
-
__name(
|
544
|
-
|
545
|
-
// dist/esm/controller-registry.js
|
546
|
-
var import_ts_data_schema3 = require("@e22m4u/ts-data-schema");
|
547
|
-
|
548
|
-
// dist/esm/errors/not-a-controller-error.js
|
549
|
-
var import_js_format3 = require("@e22m4u/js-format");
|
550
|
-
var _NotAControllerError = class _NotAControllerError extends import_js_format3.Errorf {
|
551
|
-
/**
|
552
|
-
* Constructor.
|
553
|
-
*
|
554
|
-
* @param value
|
555
|
-
*/
|
556
|
-
constructor(value) {
|
557
|
-
super("%v is not a controller, do use @controller decorator on it.", value);
|
558
|
-
}
|
559
|
-
};
|
560
|
-
__name(_NotAControllerError, "NotAControllerError");
|
561
|
-
var NotAControllerError = _NotAControllerError;
|
548
|
+
__name(httpResponse, "httpResponse");
|
562
549
|
|
563
550
|
// dist/esm/controller-registry.js
|
564
551
|
var _ControllerRegistry = class _ControllerRegistry extends DebuggableService {
|
@@ -573,10 +560,10 @@ var _ControllerRegistry = class _ControllerRegistry extends DebuggableService {
|
|
573
560
|
* @param options
|
574
561
|
*/
|
575
562
|
addController(ctor, options) {
|
576
|
-
const debug = this.
|
563
|
+
const debug = this.getDebuggerFor(this.addController);
|
577
564
|
if (this.hasController(ctor))
|
578
|
-
throw new
|
579
|
-
const controllerMd =
|
565
|
+
throw new import_js_format3.Errorf("The controller %v is already registered.");
|
566
|
+
const controllerMd = RestControllerReflector.getMetadata(ctor);
|
580
567
|
if (!controllerMd)
|
581
568
|
throw new NotAControllerError(ctor);
|
582
569
|
debug("Adding controller %s.", ctor.name);
|
@@ -598,7 +585,7 @@ var _ControllerRegistry = class _ControllerRegistry extends DebuggableService {
|
|
598
585
|
...this.getPostHandlersFromControllerMetadata(ctor)
|
599
586
|
];
|
600
587
|
debug("Controller has %v post-handlers.", postHandlers.length);
|
601
|
-
const actionsMd =
|
588
|
+
const actionsMd = RestActionReflector.getMetadata(ctor);
|
602
589
|
debug("%v actions found.", actionsMd.size);
|
603
590
|
const router = this.getService(import_js_trie_router2.TrieRouter);
|
604
591
|
actionsMd.forEach((actionMd, actionName) => {
|
@@ -645,7 +632,7 @@ var _ControllerRegistry = class _ControllerRegistry extends DebuggableService {
|
|
645
632
|
* @param options
|
646
633
|
*/
|
647
634
|
getPathPrefixFromControllerRootOptions(options) {
|
648
|
-
const debug = this.
|
635
|
+
const debug = this.getDebuggerFor(this.getPathPrefixFromControllerRootOptions);
|
649
636
|
debug("Getting path prefix from controller root options.");
|
650
637
|
const res = (options == null ? void 0 : options.pathPrefix) || "";
|
651
638
|
debug("Controller path prefix is %v.", res);
|
@@ -657,12 +644,12 @@ var _ControllerRegistry = class _ControllerRegistry extends DebuggableService {
|
|
657
644
|
* @param ctor
|
658
645
|
*/
|
659
646
|
getPathPrefixFromControllerMetadata(ctor) {
|
660
|
-
const debug = this.
|
661
|
-
debug("Getting path prefix from @
|
647
|
+
const debug = this.getDebuggerFor(this.getPathPrefixFromControllerMetadata);
|
648
|
+
debug("Getting path prefix from @restController metadata.");
|
662
649
|
debug("Metadata target is %s.", ctor.name);
|
663
|
-
const md =
|
650
|
+
const md = RestControllerReflector.getMetadata(ctor);
|
664
651
|
if (!md)
|
665
|
-
throw new
|
652
|
+
throw new import_js_format3.Errorf("Controller %v has no metadata.", ctor);
|
666
653
|
const res = md.path || "";
|
667
654
|
debug("Controller path prefix is %v.", res);
|
668
655
|
return md.path || "";
|
@@ -673,7 +660,7 @@ var _ControllerRegistry = class _ControllerRegistry extends DebuggableService {
|
|
673
660
|
* @param options
|
674
661
|
*/
|
675
662
|
getPreHandlersFromControllerRootOptions(options) {
|
676
|
-
const debug = this.
|
663
|
+
const debug = this.getDebuggerFor(this.getPreHandlersFromControllerRootOptions);
|
677
664
|
debug("Getting pre-handlers from controller root options.");
|
678
665
|
let res = [];
|
679
666
|
if (options == null ? void 0 : options.before)
|
@@ -687,7 +674,7 @@ var _ControllerRegistry = class _ControllerRegistry extends DebuggableService {
|
|
687
674
|
* @param options
|
688
675
|
*/
|
689
676
|
getPostHandlersFromControllerRootOptions(options) {
|
690
|
-
const debug = this.
|
677
|
+
const debug = this.getDebuggerFor(this.getPostHandlersFromControllerRootOptions);
|
691
678
|
debug("Getting post-handlers from controller root options.");
|
692
679
|
let res = [];
|
693
680
|
if (options == null ? void 0 : options.after)
|
@@ -702,7 +689,7 @@ var _ControllerRegistry = class _ControllerRegistry extends DebuggableService {
|
|
702
689
|
* @param actionName
|
703
690
|
*/
|
704
691
|
getPreHandlersFromBeforeMetadata(ctor, actionName) {
|
705
|
-
const debug = this.
|
692
|
+
const debug = this.getDebuggerFor(this.getPreHandlersFromBeforeMetadata);
|
706
693
|
debug("Getting pre-handlers from @before metadata.");
|
707
694
|
if (actionName) {
|
708
695
|
debug("Target is %s.%s.", ctor.name, actionName);
|
@@ -710,7 +697,7 @@ var _ControllerRegistry = class _ControllerRegistry extends DebuggableService {
|
|
710
697
|
debug("Target is %s.", ctor.name);
|
711
698
|
}
|
712
699
|
let preHandlers = [];
|
713
|
-
const mdArray =
|
700
|
+
const mdArray = BeforeActionReflector.getMetadata(ctor, actionName);
|
714
701
|
mdArray.forEach((md) => {
|
715
702
|
if (Array.isArray(md.middleware)) {
|
716
703
|
preHandlers = [...preHandlers, ...md.middleware];
|
@@ -732,7 +719,7 @@ var _ControllerRegistry = class _ControllerRegistry extends DebuggableService {
|
|
732
719
|
* @param actionName
|
733
720
|
*/
|
734
721
|
getPostHandlersFromAfterMetadata(ctor, actionName) {
|
735
|
-
const debug = this.
|
722
|
+
const debug = this.getDebuggerFor(this.getPostHandlersFromAfterMetadata);
|
736
723
|
debug("Getting post-handlers from @after metadata.");
|
737
724
|
if (actionName) {
|
738
725
|
debug("Target is %s.%s.", ctor.name, actionName);
|
@@ -740,7 +727,7 @@ var _ControllerRegistry = class _ControllerRegistry extends DebuggableService {
|
|
740
727
|
debug("Target is %s.", ctor.name);
|
741
728
|
}
|
742
729
|
let res = [];
|
743
|
-
const mdArray =
|
730
|
+
const mdArray = AfterActionReflector.getMetadata(ctor, actionName);
|
744
731
|
mdArray.forEach((md) => {
|
745
732
|
if (Array.isArray(md.middleware)) {
|
746
733
|
res = [...res, ...md.middleware];
|
@@ -761,12 +748,12 @@ var _ControllerRegistry = class _ControllerRegistry extends DebuggableService {
|
|
761
748
|
* @param ctor
|
762
749
|
*/
|
763
750
|
getPreHandlersFromControllerMetadata(ctor) {
|
764
|
-
const debug = this.
|
765
|
-
debug("Getting pre-handlers from @
|
751
|
+
const debug = this.getDebuggerFor(this.getPreHandlersFromControllerMetadata);
|
752
|
+
debug("Getting pre-handlers from @restController metadata.");
|
766
753
|
debug("Target is %s.", ctor.name);
|
767
|
-
const md =
|
754
|
+
const md = RestControllerReflector.getMetadata(ctor);
|
768
755
|
if (!md)
|
769
|
-
throw new
|
756
|
+
throw new import_js_format3.Errorf("Controller %v has no metadata.", ctor);
|
770
757
|
let res = [];
|
771
758
|
if (md.before)
|
772
759
|
res = Array.isArray(md.before) ? md.before : [md.before];
|
@@ -779,11 +766,11 @@ var _ControllerRegistry = class _ControllerRegistry extends DebuggableService {
|
|
779
766
|
* @param ctor
|
780
767
|
*/
|
781
768
|
getPostHandlersFromControllerMetadata(ctor) {
|
782
|
-
const debug = this.
|
783
|
-
debug("Getting post-handlers from @
|
784
|
-
const md =
|
769
|
+
const debug = this.getDebuggerFor(this.getPostHandlersFromControllerMetadata);
|
770
|
+
debug("Getting post-handlers from @restController metadata.");
|
771
|
+
const md = RestControllerReflector.getMetadata(ctor);
|
785
772
|
if (!md)
|
786
|
-
throw new
|
773
|
+
throw new import_js_format3.Errorf("Controller %v has no metadata.", ctor);
|
787
774
|
let res = [];
|
788
775
|
if (md.after)
|
789
776
|
res = Array.isArray(md.after) ? md.after : [md.after];
|
@@ -797,12 +784,12 @@ var _ControllerRegistry = class _ControllerRegistry extends DebuggableService {
|
|
797
784
|
* @param actionName
|
798
785
|
*/
|
799
786
|
getPreHandlersFromActionMetadata(ctor, actionName) {
|
800
|
-
const debug = this.
|
787
|
+
const debug = this.getDebuggerFor(this.getPreHandlersFromActionMetadata);
|
801
788
|
debug("Getting pre-handlers from @action metadata.");
|
802
|
-
const actionsMd =
|
789
|
+
const actionsMd = RestActionReflector.getMetadata(ctor);
|
803
790
|
const actionMd = actionsMd.get(actionName);
|
804
791
|
if (!actionMd)
|
805
|
-
throw new
|
792
|
+
throw new import_js_format3.Errorf("Action %s.%s has no metadata.", ctor.name, actionName);
|
806
793
|
let res = [];
|
807
794
|
if (actionMd.before)
|
808
795
|
res = Array.isArray(actionMd.before) ? actionMd.before : [actionMd.before];
|
@@ -816,12 +803,12 @@ var _ControllerRegistry = class _ControllerRegistry extends DebuggableService {
|
|
816
803
|
* @param actionName
|
817
804
|
*/
|
818
805
|
getPostHandlersFromActionMetadata(ctor, actionName) {
|
819
|
-
const debug = this.
|
806
|
+
const debug = this.getDebuggerFor(this.getPreHandlersFromActionMetadata);
|
820
807
|
debug("Getting post-handlers from @action metadata.");
|
821
|
-
const actionsMd =
|
808
|
+
const actionsMd = RestActionReflector.getMetadata(ctor);
|
822
809
|
const actionMd = actionsMd.get(actionName);
|
823
810
|
if (!actionMd)
|
824
|
-
throw new
|
811
|
+
throw new import_js_format3.Errorf("Action %s.%s has no metadata.", ctor.name, actionName);
|
825
812
|
let res = [];
|
826
813
|
if (actionMd.after)
|
827
814
|
res = Array.isArray(actionMd.after) ? actionMd.after : [actionMd.after];
|
@@ -836,7 +823,7 @@ var _ControllerRegistry = class _ControllerRegistry extends DebuggableService {
|
|
836
823
|
* @protected
|
837
824
|
*/
|
838
825
|
createRouteHandler(controllerCtor, actionName) {
|
839
|
-
const debug = this.
|
826
|
+
const debug = this.getDebuggerFor(this.createRouteHandler);
|
840
827
|
debug("Creating route handler for %s.%s.", controllerCtor.name, actionName);
|
841
828
|
const requestContextMetadataMap = RequestContextReflector.getMetadata(controllerCtor, actionName);
|
842
829
|
const requestDataMetadataMap = RequestDataReflector.getMetadata(controllerCtor, actionName);
|
@@ -908,8 +895,8 @@ var _ControllerRegistry = class _ControllerRegistry extends DebuggableService {
|
|
908
895
|
debug("No RequestDataMetadata specified for %v argument.", index);
|
909
896
|
}
|
910
897
|
});
|
911
|
-
const
|
912
|
-
return
|
898
|
+
const controller = this.getService(controllerCtor);
|
899
|
+
return controller[actionName](...args);
|
913
900
|
};
|
914
901
|
}
|
915
902
|
};
|
@@ -939,47 +926,46 @@ __name(_RestRouter, "RestRouter");
|
|
939
926
|
var RestRouter = _RestRouter;
|
940
927
|
// Annotate the CommonJS export names for ESM import in node:
|
941
928
|
0 && (module.exports = {
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
BEFORE_METADATA_KEY,
|
947
|
-
BeforeReflector,
|
948
|
-
CONTROLLER_METADATA_KEY,
|
949
|
-
ControllerReflector,
|
929
|
+
AFTER_ACTION_METADATA_KEY,
|
930
|
+
AfterActionReflector,
|
931
|
+
BEFORE_ACTION_METADATA_KEY,
|
932
|
+
BeforeActionReflector,
|
950
933
|
ControllerRegistry,
|
951
934
|
NotAControllerError,
|
952
935
|
REQUEST_CONTEXT_METADATA_KEY,
|
953
936
|
REQUEST_DATA_METADATA_KEY,
|
937
|
+
REST_ACTIONS_METADATA_KEY,
|
938
|
+
REST_CONTROLLER_METADATA_KEY,
|
954
939
|
RequestContextReflector,
|
955
940
|
RequestDataReflector,
|
956
941
|
RequestDataSource,
|
942
|
+
RestActionReflector,
|
943
|
+
RestControllerReflector,
|
957
944
|
RestRouter,
|
958
|
-
|
959
|
-
|
960
|
-
before,
|
961
|
-
body,
|
945
|
+
afterAction,
|
946
|
+
beforeAction,
|
962
947
|
capitalize,
|
963
|
-
controller,
|
964
|
-
cookie,
|
965
|
-
cookies,
|
966
|
-
createDebugger,
|
967
948
|
createError,
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
post,
|
977
|
-
put,
|
978
|
-
queries,
|
979
|
-
query,
|
980
|
-
request,
|
949
|
+
deleteAction,
|
950
|
+
getAction,
|
951
|
+
httpRequest,
|
952
|
+
httpResponse,
|
953
|
+
patchAction,
|
954
|
+
postAction,
|
955
|
+
putAction,
|
956
|
+
requestBody,
|
981
957
|
requestContext,
|
958
|
+
requestCookie,
|
959
|
+
requestCookies,
|
982
960
|
requestData,
|
983
|
-
|
961
|
+
requestField,
|
962
|
+
requestHeader,
|
963
|
+
requestHeaders,
|
964
|
+
requestParam,
|
965
|
+
requestParams,
|
966
|
+
requestQueries,
|
967
|
+
requestQuery,
|
968
|
+
restAction,
|
969
|
+
restController,
|
984
970
|
toCamelCase
|
985
971
|
});
|