moost 0.0.1 → 0.2.1
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 +14 -8
- package/dist/index.cjs +913 -0
- package/dist/{moost.d.ts → index.d.ts} +43 -158
- package/dist/index.mjs +883 -0
- package/package.json +14 -69
- package/LICENSE +0 -21
- package/dist/moost.cjs.prod.js +0 -923
- package/dist/moost.esm-bundler.js +0 -870
- package/dist/src/binding/bind-controller.d.ts +0 -13
- package/dist/src/binding/bind-controller.d.ts.map +0 -1
- package/dist/src/binding/bind-handler.d.ts +0 -18
- package/dist/src/binding/bind-handler.d.ts.map +0 -1
- package/dist/src/binding/index.d.ts +0 -3
- package/dist/src/binding/index.d.ts.map +0 -1
- package/dist/src/binding/tests/binding.spec.d.ts +0 -2
- package/dist/src/binding/tests/binding.spec.d.ts.map +0 -1
- package/dist/src/binding/utils.d.ts +0 -3
- package/dist/src/binding/utils.d.ts.map +0 -1
- package/dist/src/class-function/class-function.d.ts +0 -4
- package/dist/src/class-function/class-function.d.ts.map +0 -1
- package/dist/src/class-function/index.d.ts +0 -2
- package/dist/src/class-function/index.d.ts.map +0 -1
- package/dist/src/class-function/types.d.ts +0 -9
- package/dist/src/class-function/types.d.ts.map +0 -1
- package/dist/src/composables/controller-meta.d.ts +0 -13
- package/dist/src/composables/controller-meta.d.ts.map +0 -1
- package/dist/src/composables/index.d.ts +0 -2
- package/dist/src/composables/index.d.ts.map +0 -1
- package/dist/src/decorators/circular.decorator.d.ts +0 -3
- package/dist/src/decorators/circular.decorator.d.ts.map +0 -1
- package/dist/src/decorators/common.decorator.d.ts +0 -4
- package/dist/src/decorators/common.decorator.d.ts.map +0 -1
- package/dist/src/decorators/controller.decorator.d.ts +0 -24
- package/dist/src/decorators/controller.decorator.d.ts.map +0 -1
- package/dist/src/decorators/http-method.decorator.d.ts +0 -8
- package/dist/src/decorators/http-method.decorator.d.ts.map +0 -1
- package/dist/src/decorators/index.d.ts +0 -10
- package/dist/src/decorators/index.d.ts.map +0 -1
- package/dist/src/decorators/injectable.decorator.d.ts +0 -12
- package/dist/src/decorators/injectable.decorator.d.ts.map +0 -1
- package/dist/src/decorators/intercept.decorator.d.ts +0 -20
- package/dist/src/decorators/intercept.decorator.d.ts.map +0 -1
- package/dist/src/decorators/pipe.decorator.d.ts +0 -3
- package/dist/src/decorators/pipe.decorator.d.ts.map +0 -1
- package/dist/src/decorators/provide.decorator.d.ts +0 -5
- package/dist/src/decorators/provide.decorator.d.ts.map +0 -1
- package/dist/src/decorators/resolve.decorator.d.ts +0 -137
- package/dist/src/decorators/resolve.decorator.d.ts.map +0 -1
- package/dist/src/decorators/tests/circular.artifacts.d.ts +0 -7
- package/dist/src/decorators/tests/circular.artifacts.d.ts.map +0 -1
- package/dist/src/decorators/tests/circular.spec.d.ts +0 -2
- package/dist/src/decorators/tests/circular.spec.d.ts.map +0 -1
- package/dist/src/decorators/tests/common.artifacts.d.ts +0 -4
- package/dist/src/decorators/tests/common.artifacts.d.ts.map +0 -1
- package/dist/src/decorators/tests/common.spec.d.ts +0 -2
- package/dist/src/decorators/tests/common.spec.d.ts.map +0 -1
- package/dist/src/decorators/tests/controller.spec.d.ts +0 -2
- package/dist/src/decorators/tests/controller.spec.d.ts.map +0 -1
- package/dist/src/decorators/tests/http-method.artifacts.d.ts +0 -12
- package/dist/src/decorators/tests/http-method.artifacts.d.ts.map +0 -1
- package/dist/src/decorators/tests/http-method.spec.d.ts +0 -2
- package/dist/src/decorators/tests/http-method.spec.d.ts.map +0 -1
- package/dist/src/decorators/tests/injectable.spec.d.ts +0 -2
- package/dist/src/decorators/tests/injectable.spec.d.ts.map +0 -1
- package/dist/src/decorators/tests/intercept.spec.d.ts +0 -2
- package/dist/src/decorators/tests/intercept.spec.d.ts.map +0 -1
- package/dist/src/decorators/tests/pipe.artifacts.d.ts +0 -4
- package/dist/src/decorators/tests/pipe.artifacts.d.ts.map +0 -1
- package/dist/src/decorators/tests/pipe.spec.d.ts +0 -2
- package/dist/src/decorators/tests/pipe.spec.d.ts.map +0 -1
- package/dist/src/decorators/tests/provide.artifacts.d.ts +0 -9
- package/dist/src/decorators/tests/provide.artifacts.d.ts.map +0 -1
- package/dist/src/decorators/tests/provide.spec.d.ts +0 -2
- package/dist/src/decorators/tests/provide.spec.d.ts.map +0 -1
- package/dist/src/decorators/tests/resolve.artifacts.d.ts +0 -4
- package/dist/src/decorators/tests/resolve.artifacts.d.ts.map +0 -1
- package/dist/src/decorators/tests/resolve.spec.d.ts +0 -2
- package/dist/src/decorators/tests/resolve.spec.d.ts.map +0 -1
- package/dist/src/decorators/tests/validate.artifacts.d.ts +0 -21
- package/dist/src/decorators/tests/validate.artifacts.d.ts.map +0 -1
- package/dist/src/decorators/tests/validate.spec.d.ts +0 -2
- package/dist/src/decorators/tests/validate.spec.d.ts.map +0 -1
- package/dist/src/decorators/validate.decorator.d.ts +0 -10
- package/dist/src/decorators/validate.decorator.d.ts.map +0 -1
- package/dist/src/index.d.ts +0 -7
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/metadata/index.d.ts +0 -2
- package/dist/src/metadata/index.d.ts.map +0 -1
- package/dist/src/metadata/infact.d.ts +0 -7
- package/dist/src/metadata/infact.d.ts.map +0 -1
- package/dist/src/metadata/moost-metadata.d.ts +0 -62
- package/dist/src/metadata/moost-metadata.d.ts.map +0 -1
- package/dist/src/metadata/valido.d.ts +0 -3
- package/dist/src/metadata/valido.d.ts.map +0 -1
- package/dist/src/moost.d.ts +0 -46
- package/dist/src/moost.d.ts.map +0 -1
- package/dist/src/moost.spec.d.ts +0 -2
- package/dist/src/moost.spec.d.ts.map +0 -1
- package/dist/src/pipes/generic-types-cast.pipe.d.ts +0 -3
- package/dist/src/pipes/generic-types-cast.pipe.d.ts.map +0 -1
- package/dist/src/pipes/index.d.ts +0 -5
- package/dist/src/pipes/index.d.ts.map +0 -1
- package/dist/src/pipes/resolve.pipe.d.ts +0 -3
- package/dist/src/pipes/resolve.pipe.d.ts.map +0 -1
- package/dist/src/pipes/run-pipes.d.ts +0 -5
- package/dist/src/pipes/run-pipes.d.ts.map +0 -1
- package/dist/src/pipes/shared-pipes.d.ts +0 -3
- package/dist/src/pipes/shared-pipes.d.ts.map +0 -1
- package/dist/src/pipes/types.d.ts +0 -21
- package/dist/src/pipes/types.d.ts.map +0 -1
- package/dist/src/pipes/validate.pipe.d.ts +0 -7
- package/dist/src/pipes/validate.pipe.d.ts.map +0 -1
- package/dist/src/pipes/validation.spec.d.ts +0 -2
- package/dist/src/pipes/validation.spec.d.ts.map +0 -1
- package/dist/src/tests/e2e.artifacts.d.ts +0 -17
- package/dist/src/tests/e2e.artifacts.d.ts.map +0 -1
- package/dist/src/tests/e2e.spec.d.ts +0 -2
- package/dist/src/tests/e2e.spec.d.ts.map +0 -1
- package/dist/src/tests/request.artifacts.d.ts +0 -10
- package/dist/src/tests/request.artifacts.d.ts.map +0 -1
- package/dist/src/types.d.ts +0 -8
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/utils/banner.d.ts +0 -2
- package/dist/src/utils/banner.d.ts.map +0 -1
- package/dist/src/utils/log.d.ts +0 -5
- package/dist/src/utils/log.d.ts.map +0 -1
- package/dist/src/utils/panic.d.ts +0 -2
- package/dist/src/utils/panic.d.ts.map +0 -1
- package/index.js +0 -2
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,913 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var eventCore = require('@wooksjs/event-core');
|
|
4
|
+
require('url');
|
|
5
|
+
require('stream');
|
|
6
|
+
require('wooks');
|
|
7
|
+
require('http');
|
|
8
|
+
var mate = require('@prostojs/mate');
|
|
9
|
+
var infact = require('@prostojs/infact');
|
|
10
|
+
var valido$1 = require('@prostojs/valido');
|
|
11
|
+
|
|
12
|
+
/******************************************************************************
|
|
13
|
+
Copyright (c) Microsoft Corporation.
|
|
14
|
+
|
|
15
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
16
|
+
purpose with or without fee is hereby granted.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
19
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
20
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
21
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
22
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
23
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
24
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
25
|
+
***************************************************************************** */
|
|
26
|
+
|
|
27
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
28
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
29
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
30
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
31
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
32
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
33
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function useHttpContext() {
|
|
38
|
+
return eventCore.useEventContext('HTTP');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const httpStatusCodes = {
|
|
42
|
+
[100]: 'Continue',
|
|
43
|
+
[101]: 'Switching protocols',
|
|
44
|
+
[102]: 'Processing',
|
|
45
|
+
[103]: 'Early Hints',
|
|
46
|
+
[200]: 'OK',
|
|
47
|
+
[201]: 'Created',
|
|
48
|
+
[202]: 'Accepted',
|
|
49
|
+
[203]: 'Non-Authoritative Information',
|
|
50
|
+
[204]: 'No Content',
|
|
51
|
+
[205]: 'Reset Content',
|
|
52
|
+
[206]: 'Partial Content',
|
|
53
|
+
[207]: 'Multi-Status',
|
|
54
|
+
[208]: 'Already Reported',
|
|
55
|
+
[226]: 'IM Used',
|
|
56
|
+
[300]: 'Multiple Choices',
|
|
57
|
+
[301]: 'Moved Permanently',
|
|
58
|
+
[302]: 'Found (Previously "Moved Temporarily")',
|
|
59
|
+
[303]: 'See Other',
|
|
60
|
+
[304]: 'Not Modified',
|
|
61
|
+
[305]: 'Use Proxy',
|
|
62
|
+
[306]: 'Switch Proxy',
|
|
63
|
+
[307]: 'Temporary Redirect',
|
|
64
|
+
[308]: 'Permanent Redirect',
|
|
65
|
+
[400]: 'Bad Request',
|
|
66
|
+
[401]: 'Unauthorized',
|
|
67
|
+
[402]: 'Payment Required',
|
|
68
|
+
[403]: 'Forbidden',
|
|
69
|
+
[404]: 'Not Found',
|
|
70
|
+
[405]: 'Method Not Allowed',
|
|
71
|
+
[406]: 'Not Acceptable',
|
|
72
|
+
[407]: 'Proxy Authentication Required',
|
|
73
|
+
[408]: 'Request Timeout',
|
|
74
|
+
[409]: 'Conflict',
|
|
75
|
+
[410]: 'Gone',
|
|
76
|
+
[411]: 'Length Required',
|
|
77
|
+
[412]: 'Precondition Failed',
|
|
78
|
+
[413]: 'Payload Too Large',
|
|
79
|
+
[414]: 'URI Too Long',
|
|
80
|
+
[415]: 'Unsupported Media Type',
|
|
81
|
+
[416]: 'Range Not Satisfiable',
|
|
82
|
+
[417]: 'Expectation Failed',
|
|
83
|
+
[418]: 'I\'m a Teapot',
|
|
84
|
+
[421]: 'Misdirected Request',
|
|
85
|
+
[422]: 'Unprocessable Entity',
|
|
86
|
+
[423]: 'Locked',
|
|
87
|
+
[424]: 'Failed Dependency',
|
|
88
|
+
[425]: 'Too Early',
|
|
89
|
+
[426]: 'Upgrade Required',
|
|
90
|
+
[428]: 'Precondition Required',
|
|
91
|
+
[429]: 'Too Many Requests',
|
|
92
|
+
[431]: 'Request Header Fields Too Large',
|
|
93
|
+
[451]: 'Unavailable For Legal Reasons',
|
|
94
|
+
[500]: 'Internal Server Error',
|
|
95
|
+
[501]: 'Not Implemented',
|
|
96
|
+
[502]: 'Bad Gateway',
|
|
97
|
+
[503]: 'Service Unavailable',
|
|
98
|
+
[504]: 'Gateway Timeout',
|
|
99
|
+
[505]: 'HTTP Version Not Supported',
|
|
100
|
+
[506]: 'Variant Also Negotiates',
|
|
101
|
+
[507]: 'Insufficient Storage',
|
|
102
|
+
[508]: 'Loop Detected',
|
|
103
|
+
[510]: 'Not Extended',
|
|
104
|
+
[511]: 'Network Authentication Required',
|
|
105
|
+
};
|
|
106
|
+
var EHttpStatusCode;
|
|
107
|
+
(function (EHttpStatusCode) {
|
|
108
|
+
EHttpStatusCode[EHttpStatusCode["Continue"] = 100] = "Continue";
|
|
109
|
+
EHttpStatusCode[EHttpStatusCode["SwitchingProtocols"] = 101] = "SwitchingProtocols";
|
|
110
|
+
EHttpStatusCode[EHttpStatusCode["Processing"] = 102] = "Processing";
|
|
111
|
+
EHttpStatusCode[EHttpStatusCode["EarlyHints"] = 103] = "EarlyHints";
|
|
112
|
+
EHttpStatusCode[EHttpStatusCode["OK"] = 200] = "OK";
|
|
113
|
+
EHttpStatusCode[EHttpStatusCode["Created"] = 201] = "Created";
|
|
114
|
+
EHttpStatusCode[EHttpStatusCode["Accepted"] = 202] = "Accepted";
|
|
115
|
+
EHttpStatusCode[EHttpStatusCode["NonAuthoritativeInformation"] = 203] = "NonAuthoritativeInformation";
|
|
116
|
+
EHttpStatusCode[EHttpStatusCode["NoContent"] = 204] = "NoContent";
|
|
117
|
+
EHttpStatusCode[EHttpStatusCode["ResetContent"] = 205] = "ResetContent";
|
|
118
|
+
EHttpStatusCode[EHttpStatusCode["PartialContent"] = 206] = "PartialContent";
|
|
119
|
+
EHttpStatusCode[EHttpStatusCode["MultiStatus"] = 207] = "MultiStatus";
|
|
120
|
+
EHttpStatusCode[EHttpStatusCode["AlreadyReported"] = 208] = "AlreadyReported";
|
|
121
|
+
EHttpStatusCode[EHttpStatusCode["IMUsed"] = 226] = "IMUsed";
|
|
122
|
+
EHttpStatusCode[EHttpStatusCode["MultipleChoices"] = 300] = "MultipleChoices";
|
|
123
|
+
EHttpStatusCode[EHttpStatusCode["MovedPermanently"] = 301] = "MovedPermanently";
|
|
124
|
+
EHttpStatusCode[EHttpStatusCode["Found"] = 302] = "Found";
|
|
125
|
+
EHttpStatusCode[EHttpStatusCode["SeeOther"] = 303] = "SeeOther";
|
|
126
|
+
EHttpStatusCode[EHttpStatusCode["NotModified"] = 304] = "NotModified";
|
|
127
|
+
EHttpStatusCode[EHttpStatusCode["UseProxy"] = 305] = "UseProxy";
|
|
128
|
+
EHttpStatusCode[EHttpStatusCode["SwitchProxy"] = 306] = "SwitchProxy";
|
|
129
|
+
EHttpStatusCode[EHttpStatusCode["TemporaryRedirect"] = 307] = "TemporaryRedirect";
|
|
130
|
+
EHttpStatusCode[EHttpStatusCode["PermanentRedirect"] = 308] = "PermanentRedirect";
|
|
131
|
+
EHttpStatusCode[EHttpStatusCode["BadRequest"] = 400] = "BadRequest";
|
|
132
|
+
EHttpStatusCode[EHttpStatusCode["Unauthorized"] = 401] = "Unauthorized";
|
|
133
|
+
EHttpStatusCode[EHttpStatusCode["PaymentRequired"] = 402] = "PaymentRequired";
|
|
134
|
+
EHttpStatusCode[EHttpStatusCode["Forbidden"] = 403] = "Forbidden";
|
|
135
|
+
EHttpStatusCode[EHttpStatusCode["NotFound"] = 404] = "NotFound";
|
|
136
|
+
EHttpStatusCode[EHttpStatusCode["MethodNotAllowed"] = 405] = "MethodNotAllowed";
|
|
137
|
+
EHttpStatusCode[EHttpStatusCode["NotAcceptable"] = 406] = "NotAcceptable";
|
|
138
|
+
EHttpStatusCode[EHttpStatusCode["ProxyAuthenticationRequired"] = 407] = "ProxyAuthenticationRequired";
|
|
139
|
+
EHttpStatusCode[EHttpStatusCode["RequestTimeout"] = 408] = "RequestTimeout";
|
|
140
|
+
EHttpStatusCode[EHttpStatusCode["Conflict"] = 409] = "Conflict";
|
|
141
|
+
EHttpStatusCode[EHttpStatusCode["Gone"] = 410] = "Gone";
|
|
142
|
+
EHttpStatusCode[EHttpStatusCode["LengthRequired"] = 411] = "LengthRequired";
|
|
143
|
+
EHttpStatusCode[EHttpStatusCode["PreconditionFailed"] = 412] = "PreconditionFailed";
|
|
144
|
+
EHttpStatusCode[EHttpStatusCode["PayloadTooLarge"] = 413] = "PayloadTooLarge";
|
|
145
|
+
EHttpStatusCode[EHttpStatusCode["URITooLong"] = 414] = "URITooLong";
|
|
146
|
+
EHttpStatusCode[EHttpStatusCode["UnsupportedMediaType"] = 415] = "UnsupportedMediaType";
|
|
147
|
+
EHttpStatusCode[EHttpStatusCode["RangeNotSatisfiable"] = 416] = "RangeNotSatisfiable";
|
|
148
|
+
EHttpStatusCode[EHttpStatusCode["ExpectationFailed"] = 417] = "ExpectationFailed";
|
|
149
|
+
EHttpStatusCode[EHttpStatusCode["ImATeapot"] = 418] = "ImATeapot";
|
|
150
|
+
EHttpStatusCode[EHttpStatusCode["MisdirectedRequest"] = 421] = "MisdirectedRequest";
|
|
151
|
+
EHttpStatusCode[EHttpStatusCode["UnprocessableEntity"] = 422] = "UnprocessableEntity";
|
|
152
|
+
EHttpStatusCode[EHttpStatusCode["Locked"] = 423] = "Locked";
|
|
153
|
+
EHttpStatusCode[EHttpStatusCode["FailedDependency"] = 424] = "FailedDependency";
|
|
154
|
+
EHttpStatusCode[EHttpStatusCode["TooEarly"] = 425] = "TooEarly";
|
|
155
|
+
EHttpStatusCode[EHttpStatusCode["UpgradeRequired"] = 426] = "UpgradeRequired";
|
|
156
|
+
EHttpStatusCode[EHttpStatusCode["PreconditionRequired"] = 428] = "PreconditionRequired";
|
|
157
|
+
EHttpStatusCode[EHttpStatusCode["TooManyRequests"] = 429] = "TooManyRequests";
|
|
158
|
+
EHttpStatusCode[EHttpStatusCode["RequestHeaderFieldsTooLarge"] = 431] = "RequestHeaderFieldsTooLarge";
|
|
159
|
+
EHttpStatusCode[EHttpStatusCode["UnavailableForLegalReasons"] = 451] = "UnavailableForLegalReasons";
|
|
160
|
+
EHttpStatusCode[EHttpStatusCode["InternalServerError"] = 500] = "InternalServerError";
|
|
161
|
+
EHttpStatusCode[EHttpStatusCode["NotImplemented"] = 501] = "NotImplemented";
|
|
162
|
+
EHttpStatusCode[EHttpStatusCode["BadGateway"] = 502] = "BadGateway";
|
|
163
|
+
EHttpStatusCode[EHttpStatusCode["ServiceUnavailable"] = 503] = "ServiceUnavailable";
|
|
164
|
+
EHttpStatusCode[EHttpStatusCode["GatewayTimeout"] = 504] = "GatewayTimeout";
|
|
165
|
+
EHttpStatusCode[EHttpStatusCode["HTTPVersionNotSupported"] = 505] = "HTTPVersionNotSupported";
|
|
166
|
+
EHttpStatusCode[EHttpStatusCode["VariantAlsoNegotiates"] = 506] = "VariantAlsoNegotiates";
|
|
167
|
+
EHttpStatusCode[EHttpStatusCode["InsufficientStorage"] = 507] = "InsufficientStorage";
|
|
168
|
+
EHttpStatusCode[EHttpStatusCode["LoopDetected"] = 508] = "LoopDetected";
|
|
169
|
+
EHttpStatusCode[EHttpStatusCode["NotExtended"] = 510] = "NotExtended";
|
|
170
|
+
EHttpStatusCode[EHttpStatusCode["NetworkAuthenticationRequired"] = 511] = "NetworkAuthenticationRequired";
|
|
171
|
+
})(EHttpStatusCode || (EHttpStatusCode = {}));
|
|
172
|
+
|
|
173
|
+
({
|
|
174
|
+
GET: EHttpStatusCode.OK,
|
|
175
|
+
POST: EHttpStatusCode.Created,
|
|
176
|
+
PUT: EHttpStatusCode.Created,
|
|
177
|
+
PATCH: EHttpStatusCode.Accepted,
|
|
178
|
+
DELETE: EHttpStatusCode.Accepted,
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
class WooksError extends Error {
|
|
182
|
+
constructor(code = 500, _body = '') {
|
|
183
|
+
super(typeof _body === 'string' ? _body : _body.message);
|
|
184
|
+
this.code = code;
|
|
185
|
+
this._body = _body;
|
|
186
|
+
}
|
|
187
|
+
get body() {
|
|
188
|
+
return typeof this._body === 'string' ? {
|
|
189
|
+
statusCode: this.code,
|
|
190
|
+
message: this.message,
|
|
191
|
+
error: httpStatusCodes[this.code],
|
|
192
|
+
} : Object.assign(Object.assign({}, this._body), { statusCode: this.code, message: this.message, error: httpStatusCodes[this.code] });
|
|
193
|
+
}
|
|
194
|
+
attachRenderer(renderer) {
|
|
195
|
+
this.renderer = renderer;
|
|
196
|
+
}
|
|
197
|
+
getRenderer() {
|
|
198
|
+
return this.renderer;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const METADATA_WORKSPACE = 'moost';
|
|
203
|
+
const moostMate = new mate.Mate(METADATA_WORKSPACE, {
|
|
204
|
+
readType: true,
|
|
205
|
+
readReturnType: true,
|
|
206
|
+
});
|
|
207
|
+
function getMoostMate() {
|
|
208
|
+
return moostMate;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function getInstanceOwnMethods(instance) {
|
|
212
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
213
|
+
const proto = Object.getPrototypeOf(instance);
|
|
214
|
+
return [
|
|
215
|
+
...Object.getOwnPropertyNames(proto),
|
|
216
|
+
...Object.getOwnPropertyNames(instance),
|
|
217
|
+
].filter(m => typeof instance[m] === 'function');
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const banner = () => `[${"moost"}][${new Date().toISOString().replace('T', ' ').replace(/\.\d{3}z$/i, '')}] `;
|
|
221
|
+
|
|
222
|
+
/* istanbul ignore file */
|
|
223
|
+
function log(text) {
|
|
224
|
+
console.log('[32m' + '[2m' + banner() + text + '[0m');
|
|
225
|
+
}
|
|
226
|
+
function logError(error) {
|
|
227
|
+
console.error('[91m' + '[1m' + banner() + error + '[0m');
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function panic(error) {
|
|
231
|
+
logError(error);
|
|
232
|
+
return new Error(error);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function runPipes(pipes, meta, restoreCtx) {
|
|
236
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
237
|
+
let v = undefined;
|
|
238
|
+
for (const pipe of pipes) {
|
|
239
|
+
restoreCtx && restoreCtx();
|
|
240
|
+
v = yield pipe.handler(v, meta);
|
|
241
|
+
}
|
|
242
|
+
return v;
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
exports.TPipePriority = void 0;
|
|
247
|
+
(function (TPipePriority) {
|
|
248
|
+
TPipePriority[TPipePriority["BEFORE_RESOLVE"] = 0] = "BEFORE_RESOLVE";
|
|
249
|
+
TPipePriority[TPipePriority["RESOLVE"] = 1] = "RESOLVE";
|
|
250
|
+
TPipePriority[TPipePriority["AFTER_RESOLVE"] = 2] = "AFTER_RESOLVE";
|
|
251
|
+
TPipePriority[TPipePriority["BEFORE_TRANSFORM"] = 3] = "BEFORE_TRANSFORM";
|
|
252
|
+
TPipePriority[TPipePriority["TRANSFORM"] = 4] = "TRANSFORM";
|
|
253
|
+
TPipePriority[TPipePriority["AFTER_TRANSFORM"] = 5] = "AFTER_TRANSFORM";
|
|
254
|
+
TPipePriority[TPipePriority["BEFORE_VALIDATE"] = 6] = "BEFORE_VALIDATE";
|
|
255
|
+
TPipePriority[TPipePriority["VALIDATE"] = 7] = "VALIDATE";
|
|
256
|
+
TPipePriority[TPipePriority["AFTER_VALIDATE"] = 8] = "AFTER_VALIDATE";
|
|
257
|
+
})(exports.TPipePriority || (exports.TPipePriority = {}));
|
|
258
|
+
|
|
259
|
+
const resolvePipe = (_value, meta) => {
|
|
260
|
+
if (meta === null || meta === void 0 ? void 0 : meta.resolver) {
|
|
261
|
+
return meta.resolver();
|
|
262
|
+
}
|
|
263
|
+
return undefined;
|
|
264
|
+
};
|
|
265
|
+
resolvePipe.priority = exports.TPipePriority.RESOLVE;
|
|
266
|
+
|
|
267
|
+
const sharedPipes = [
|
|
268
|
+
{
|
|
269
|
+
handler: resolvePipe,
|
|
270
|
+
priority: exports.TPipePriority.RESOLVE,
|
|
271
|
+
},
|
|
272
|
+
];
|
|
273
|
+
|
|
274
|
+
const sharedMoostInfact = getNewMoostInfact();
|
|
275
|
+
function getMoostInfact() {
|
|
276
|
+
return sharedMoostInfact;
|
|
277
|
+
}
|
|
278
|
+
function getNewMoostInfact() {
|
|
279
|
+
return new infact.Infact({
|
|
280
|
+
describeClass(classConstructor) {
|
|
281
|
+
const meta = getMoostMate().read(classConstructor);
|
|
282
|
+
const infactMeta = {
|
|
283
|
+
injectable: !!(meta === null || meta === void 0 ? void 0 : meta.injectable),
|
|
284
|
+
global: false,
|
|
285
|
+
constructorParams: (meta === null || meta === void 0 ? void 0 : meta.params) || [],
|
|
286
|
+
provide: meta === null || meta === void 0 ? void 0 : meta.provide,
|
|
287
|
+
scopeId: (meta === null || meta === void 0 ? void 0 : meta.injectable) === 'FOR_EVENT' ? eventCore.useEventId().getId() : undefined,
|
|
288
|
+
};
|
|
289
|
+
return infactMeta;
|
|
290
|
+
},
|
|
291
|
+
resolveParam(paramMeta) {
|
|
292
|
+
if (paramMeta.resolver) {
|
|
293
|
+
return runPipes(sharedPipes, paramMeta);
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
storeProvideRegByInstance: true,
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function getCallableFn(targetInstance, fn, restoreCtx) {
|
|
301
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
302
|
+
const mate$1 = getMoostMate();
|
|
303
|
+
const meta = mate$1.read(fn);
|
|
304
|
+
if (meta === null || meta === void 0 ? void 0 : meta.injectable) {
|
|
305
|
+
const infact = getMoostInfact();
|
|
306
|
+
infact.silent(meta.injectable === 'FOR_EVENT');
|
|
307
|
+
const instance = yield infact.getForInstance(targetInstance, fn, [], () => { restoreCtx && restoreCtx(); });
|
|
308
|
+
infact.silent(false);
|
|
309
|
+
return ((...args) => {
|
|
310
|
+
return instance.handler(...args);
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
if (typeof fn === 'function') {
|
|
314
|
+
return fn;
|
|
315
|
+
}
|
|
316
|
+
throw panic(`getCallableFn failed for "${mate.getConstructor(targetInstance).name}" because the passed arg is not a Function nor TClassFunction`);
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
class InterceptorHandler {
|
|
321
|
+
constructor(handlers) {
|
|
322
|
+
this.handlers = handlers;
|
|
323
|
+
this.before = [];
|
|
324
|
+
this.after = [];
|
|
325
|
+
this.onError = [];
|
|
326
|
+
this.responseOverwritten = false;
|
|
327
|
+
}
|
|
328
|
+
replyFn(reply) {
|
|
329
|
+
this.response = reply;
|
|
330
|
+
this.responseOverwritten = true;
|
|
331
|
+
}
|
|
332
|
+
init() {
|
|
333
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
334
|
+
const { restoreCtx } = eventCore.useEventContext();
|
|
335
|
+
for (const handler of this.handlers) {
|
|
336
|
+
restoreCtx();
|
|
337
|
+
yield handler((fn) => { this.before.push(fn); }, (fn) => { this.after.unshift(fn); }, (fn) => { this.onError.unshift(fn); });
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
fireBefore(response) {
|
|
342
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
343
|
+
const { restoreCtx } = eventCore.useEventContext();
|
|
344
|
+
this.response = response;
|
|
345
|
+
for (const handler of this.before) {
|
|
346
|
+
restoreCtx();
|
|
347
|
+
yield handler(this.replyFn.bind(this));
|
|
348
|
+
if (this.responseOverwritten)
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
return this.response;
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
fireAfter(response) {
|
|
355
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
356
|
+
const { restoreCtx } = eventCore.useEventContext();
|
|
357
|
+
this.response = response;
|
|
358
|
+
if (response instanceof Error) {
|
|
359
|
+
for (const handler of this.onError) {
|
|
360
|
+
restoreCtx();
|
|
361
|
+
yield handler(response, this.replyFn.bind(this));
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
for (const handler of this.after) {
|
|
366
|
+
restoreCtx();
|
|
367
|
+
yield handler(response, this.replyFn.bind(this));
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return this.response;
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function bindControllerMethods(options) {
|
|
376
|
+
var _a;
|
|
377
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
378
|
+
const opts = options || {};
|
|
379
|
+
const { getInstance } = opts;
|
|
380
|
+
const { classConstructor } = opts;
|
|
381
|
+
const { adapters } = opts;
|
|
382
|
+
opts.globalPrefix = opts.globalPrefix || '';
|
|
383
|
+
opts.provide = opts.provide || {};
|
|
384
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
385
|
+
const fakeInstance = Object.create(classConstructor.prototype);
|
|
386
|
+
const methods = getInstanceOwnMethods(fakeInstance);
|
|
387
|
+
const mate = getMoostMate();
|
|
388
|
+
const meta = mate.read(classConstructor) || {};
|
|
389
|
+
const ownPrefix = typeof opts.replaceOwnPrefix === 'string' ? opts.replaceOwnPrefix : (((_a = meta.controller) === null || _a === void 0 ? void 0 : _a.prefix) || '');
|
|
390
|
+
const prefix = `${opts.globalPrefix}/${ownPrefix}`;
|
|
391
|
+
for (const method of methods) {
|
|
392
|
+
const methodMeta = getMoostMate().read(fakeInstance, method) || {};
|
|
393
|
+
if (!methodMeta.handlers || !methodMeta.handlers.length)
|
|
394
|
+
continue;
|
|
395
|
+
// preparing interceptors
|
|
396
|
+
const interceptors = [...(opts.interceptors || []), ...(meta.interceptors || []), ...(methodMeta.interceptors || [])].sort((a, b) => a.priority - b.priority);
|
|
397
|
+
const getIterceptorHandler = () => __awaiter(this, void 0, void 0, function* () {
|
|
398
|
+
const interceptorHandlers = [];
|
|
399
|
+
for (const { handler } of interceptors) {
|
|
400
|
+
const interceptorMeta = mate.read(handler);
|
|
401
|
+
if (interceptorMeta === null || interceptorMeta === void 0 ? void 0 : interceptorMeta.injectable) {
|
|
402
|
+
interceptorHandlers.push((...args) => __awaiter(this, void 0, void 0, function* () {
|
|
403
|
+
const { restoreCtx } = useHttpContext();
|
|
404
|
+
const targetInstance = yield getInstance();
|
|
405
|
+
restoreCtx();
|
|
406
|
+
return (yield getCallableFn(targetInstance, handler, restoreCtx))(...args);
|
|
407
|
+
}));
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
interceptorHandlers.push(handler);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return new InterceptorHandler(interceptorHandlers);
|
|
414
|
+
});
|
|
415
|
+
// preparing pipes
|
|
416
|
+
const pipes = [...(opts.pipes || []), ...(meta.pipes || []), ...(methodMeta.pipes || [])];
|
|
417
|
+
const argsPipes = [];
|
|
418
|
+
for (const p of methodMeta.params || []) {
|
|
419
|
+
argsPipes.push({
|
|
420
|
+
meta: p,
|
|
421
|
+
pipes: [...pipes, ...(p.pipes || [])].sort((a, b) => a.priority - b.priority),
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
const resolveArgs = () => __awaiter(this, void 0, void 0, function* () {
|
|
425
|
+
const args = [];
|
|
426
|
+
const { restoreCtx } = eventCore.useEventContext();
|
|
427
|
+
for (let i = 0; i < argsPipes.length; i++) {
|
|
428
|
+
const { pipes, meta } = argsPipes[i];
|
|
429
|
+
args[i] = yield runPipes(pipes, meta, restoreCtx);
|
|
430
|
+
}
|
|
431
|
+
return args;
|
|
432
|
+
});
|
|
433
|
+
// preparing provide
|
|
434
|
+
// const provide = {...(opts.provide || {}), ...(meta.provide || {})}
|
|
435
|
+
for (const adapter of adapters) {
|
|
436
|
+
yield adapter.bindHandler({
|
|
437
|
+
prefix,
|
|
438
|
+
fakeInstance,
|
|
439
|
+
getInstance,
|
|
440
|
+
registerEventScope: (scopeId) => {
|
|
441
|
+
const infact = getMoostInfact();
|
|
442
|
+
infact.registerScope(scopeId);
|
|
443
|
+
return () => infact.unregisterScope(scopeId);
|
|
444
|
+
},
|
|
445
|
+
method,
|
|
446
|
+
handlers: methodMeta.handlers,
|
|
447
|
+
getIterceptorHandler,
|
|
448
|
+
resolveArgs,
|
|
449
|
+
logHandler: (eventName) => log(`• ${eventName} ${'[0m' + '[2m' + '[32m'}→ ${classConstructor.name}.${'[36m'}${method}${'[32m'}()`),
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function Label(value) {
|
|
457
|
+
return getMoostMate().decorate('label', value);
|
|
458
|
+
}
|
|
459
|
+
function Id(value) {
|
|
460
|
+
return getMoostMate().decorate('id', value);
|
|
461
|
+
}
|
|
462
|
+
function Optional() {
|
|
463
|
+
return getMoostMate().decorate('optional', true);
|
|
464
|
+
}
|
|
465
|
+
function Required() {
|
|
466
|
+
const mate = getMoostMate();
|
|
467
|
+
return mate.apply(mate.decorate('required', true),
|
|
468
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
469
|
+
mate.decorateClass((meta, key, index) => {
|
|
470
|
+
if (typeof index !== 'number' && meta && ['string', 'symbol'].includes(typeof key)) {
|
|
471
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
472
|
+
meta.requiredProps = meta.requiredProps || [];
|
|
473
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
474
|
+
meta.requiredProps.push(key);
|
|
475
|
+
}
|
|
476
|
+
return meta;
|
|
477
|
+
}));
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Hook to the Response Status
|
|
482
|
+
* @decorator
|
|
483
|
+
* @param resolver - resolver function
|
|
484
|
+
* @param label - field label
|
|
485
|
+
* @paramType unknown
|
|
486
|
+
*/
|
|
487
|
+
function Resolve(resolver, label) {
|
|
488
|
+
return (target, key, index) => {
|
|
489
|
+
fillLabel(target, key, index, label);
|
|
490
|
+
getMoostMate().decorate('resolver', resolver)(target, key, index);
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Get Param Value from url parh
|
|
495
|
+
* @decorator
|
|
496
|
+
* @param name - param name
|
|
497
|
+
* @paramType string
|
|
498
|
+
*/
|
|
499
|
+
function Param(name) {
|
|
500
|
+
return Resolve(() => eventCore.useRouteParams().get(name), name);
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Get Parsed Params from url parh
|
|
504
|
+
* @decorator
|
|
505
|
+
* @paramType object
|
|
506
|
+
*/
|
|
507
|
+
function Params() {
|
|
508
|
+
return Resolve(() => eventCore.useRouteParams().params, 'params');
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Provide Const Value
|
|
512
|
+
* @decorator
|
|
513
|
+
* @param value - provided value
|
|
514
|
+
* @param label - label of the field
|
|
515
|
+
* @paramType unknown
|
|
516
|
+
*/
|
|
517
|
+
function Const(value, label) {
|
|
518
|
+
return Resolve(() => value, label);
|
|
519
|
+
}
|
|
520
|
+
function fillLabel(target, key, index, name) {
|
|
521
|
+
if (name) {
|
|
522
|
+
const meta = getMoostMate().read(target, key);
|
|
523
|
+
if (!(meta === null || meta === void 0 ? void 0 : meta.params) || !(meta === null || meta === void 0 ? void 0 : meta.params[index]) || !(meta === null || meta === void 0 ? void 0 : meta.params[index].label)) {
|
|
524
|
+
Label(name)(target, key, index);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Mark the Class as Injectable to enable it to be used in dependency injection
|
|
531
|
+
* @decorator
|
|
532
|
+
* @param scope - Scope for injection ("FOR_EVENT" | "SINGLETON" | true)
|
|
533
|
+
* FOR_EVENT - will create a new instance for each incoming request
|
|
534
|
+
* SINGLETON | true - will create a new instance only once
|
|
535
|
+
* @param label - field label
|
|
536
|
+
*/
|
|
537
|
+
function Injectable(scope = true) {
|
|
538
|
+
return getMoostMate().decorate('injectable', scope);
|
|
539
|
+
}
|
|
540
|
+
const insureInjectable = getMoostMate().decorate((meta) => {
|
|
541
|
+
if (!meta.injectable)
|
|
542
|
+
meta.injectable = true;
|
|
543
|
+
return meta;
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Set Class as a Controller
|
|
548
|
+
* @decorator
|
|
549
|
+
* @param prefix - define the prefix for all the paths of this controller
|
|
550
|
+
*/
|
|
551
|
+
function Controller(prefix) {
|
|
552
|
+
const mate = getMoostMate();
|
|
553
|
+
return mate.apply(insureInjectable, mate.decorate('controller', { prefix: prefix || '' }));
|
|
554
|
+
}
|
|
555
|
+
function ImportController(prefix, controller, provide) {
|
|
556
|
+
return getMoostMate().decorate('importController', {
|
|
557
|
+
prefix: typeof prefix === 'string' ? prefix : undefined,
|
|
558
|
+
typeResolver: typeof prefix === 'string' ? controller : prefix,
|
|
559
|
+
provide: typeof prefix === 'string' ? provide || undefined : controller || undefined,
|
|
560
|
+
}, true);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
function Circular(resolver) {
|
|
564
|
+
return getMoostMate().decorate('circular', resolver);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
exports.TInterceptorPriority = void 0;
|
|
568
|
+
(function (TInterceptorPriority) {
|
|
569
|
+
TInterceptorPriority[TInterceptorPriority["BEFORE_ALL"] = 0] = "BEFORE_ALL";
|
|
570
|
+
TInterceptorPriority[TInterceptorPriority["BEFORE_GUARD"] = 1] = "BEFORE_GUARD";
|
|
571
|
+
TInterceptorPriority[TInterceptorPriority["GUARD"] = 2] = "GUARD";
|
|
572
|
+
TInterceptorPriority[TInterceptorPriority["AFTER_GUARD"] = 3] = "AFTER_GUARD";
|
|
573
|
+
TInterceptorPriority[TInterceptorPriority["INTERCEPTOR"] = 4] = "INTERCEPTOR";
|
|
574
|
+
TInterceptorPriority[TInterceptorPriority["CATCH_ERROR"] = 5] = "CATCH_ERROR";
|
|
575
|
+
TInterceptorPriority[TInterceptorPriority["AFTER_ALL"] = 6] = "AFTER_ALL";
|
|
576
|
+
})(exports.TInterceptorPriority || (exports.TInterceptorPriority = {}));
|
|
577
|
+
function Intercept(handler, priority) {
|
|
578
|
+
return getMoostMate().decorate('interceptors', {
|
|
579
|
+
handler,
|
|
580
|
+
priority: priority || handler.priority || exports.TInterceptorPriority.INTERCEPTOR,
|
|
581
|
+
}, true);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
function Provide(type, fn) {
|
|
585
|
+
return getMoostMate().decorate(meta => {
|
|
586
|
+
meta.provide = meta.provide || {};
|
|
587
|
+
Object.assign(meta.provide, infact.createProvideRegistry([type, fn]));
|
|
588
|
+
return meta;
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
function Inject(type) {
|
|
592
|
+
return getMoostMate().decorate('inject', type);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
function Dto(dtoOptions = {}) {
|
|
596
|
+
return getMoostMate().decorate('dto', dtoOptions || {});
|
|
597
|
+
}
|
|
598
|
+
let isArrayItemValidator = false;
|
|
599
|
+
function Validate(validator) {
|
|
600
|
+
return getMoostMate().decorate(isArrayItemValidator ? 'validatorsOfItem' : 'validators', validator, true);
|
|
601
|
+
}
|
|
602
|
+
function IsArray(opts) {
|
|
603
|
+
const mate = getMoostMate();
|
|
604
|
+
const decorators = [mate.decorate('arrayType', opts || true)];
|
|
605
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.itemValidators) && !isArrayItemValidator) {
|
|
606
|
+
isArrayItemValidator = true;
|
|
607
|
+
decorators.push(...opts.itemValidators());
|
|
608
|
+
isArrayItemValidator = false;
|
|
609
|
+
}
|
|
610
|
+
else if ((opts === null || opts === void 0 ? void 0 : opts.itemValidators) && isArrayItemValidator) {
|
|
611
|
+
throw new Error('IsArray validator is not supported inside of array type');
|
|
612
|
+
}
|
|
613
|
+
const decorator = mate.apply(...decorators);
|
|
614
|
+
return decorator;
|
|
615
|
+
}
|
|
616
|
+
function IsTypeOf(type, errorText) {
|
|
617
|
+
return Validate(valido$1.validoIsTypeOf(type, errorText));
|
|
618
|
+
}
|
|
619
|
+
function IsString(...args) {
|
|
620
|
+
return Validate(valido$1.validoIsString(...args));
|
|
621
|
+
}
|
|
622
|
+
function IsNumber(...args) {
|
|
623
|
+
return Validate(valido$1.validoIsNumber(...args));
|
|
624
|
+
}
|
|
625
|
+
function IsBoolean(...args) {
|
|
626
|
+
return Validate(valido$1.validoIsBoolean(...args));
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
const valido = new valido$1.Valido({
|
|
630
|
+
getDtoMeta(value, _type) {
|
|
631
|
+
let type = _type;
|
|
632
|
+
if (!type) {
|
|
633
|
+
type = mate.getConstructor(value);
|
|
634
|
+
}
|
|
635
|
+
const mate$1 = getMoostMate();
|
|
636
|
+
return mate$1.read(type);
|
|
637
|
+
},
|
|
638
|
+
getDtoParamMeta(value, type, key) {
|
|
639
|
+
const mate = getMoostMate();
|
|
640
|
+
return mate.read(type, key);
|
|
641
|
+
},
|
|
642
|
+
});
|
|
643
|
+
function getMoostValido() {
|
|
644
|
+
return valido;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
class Moost {
|
|
648
|
+
constructor(options) {
|
|
649
|
+
this.options = options;
|
|
650
|
+
this.pipes = [...sharedPipes];
|
|
651
|
+
this.interceptors = [];
|
|
652
|
+
this.adapters = [];
|
|
653
|
+
this.provide = infact.createProvideRegistry([infact.Infact, getMoostInfact], [mate.Mate, getMoostMate], [valido$1.Valido, getMoostValido]);
|
|
654
|
+
this.unregisteredControllers = [];
|
|
655
|
+
}
|
|
656
|
+
adapter(a) {
|
|
657
|
+
this.adapters.push(a);
|
|
658
|
+
return a;
|
|
659
|
+
}
|
|
660
|
+
init() {
|
|
661
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
662
|
+
this.setProvideRegistry(infact.createProvideRegistry([Moost, () => this]));
|
|
663
|
+
this.unregisteredControllers.unshift(this);
|
|
664
|
+
yield this.bindControllers();
|
|
665
|
+
for (const a of this.adapters) {
|
|
666
|
+
yield (a.onInit && a.onInit());
|
|
667
|
+
}
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
bindControllers() {
|
|
671
|
+
var _a;
|
|
672
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
673
|
+
const meta = getMoostMate();
|
|
674
|
+
const thisMeta = meta.read(this);
|
|
675
|
+
const provide = Object.assign(Object.assign({}, ((thisMeta === null || thisMeta === void 0 ? void 0 : thisMeta.provide) || {})), this.provide);
|
|
676
|
+
for (const controller of this.unregisteredControllers) {
|
|
677
|
+
yield this.bindController(controller, provide, ((_a = this.options) === null || _a === void 0 ? void 0 : _a.globalPrefix) || '');
|
|
678
|
+
}
|
|
679
|
+
this.unregisteredControllers = [];
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
bindController(controller, provide, globalPrefix, replaceOwnPrefix) {
|
|
683
|
+
var _a;
|
|
684
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
685
|
+
const meta = getMoostMate();
|
|
686
|
+
const classMeta = meta.read(controller);
|
|
687
|
+
const infact = getMoostInfact();
|
|
688
|
+
const isControllerConsructor = mate.isConstructor(controller);
|
|
689
|
+
let instance;
|
|
690
|
+
if (isControllerConsructor && (classMeta === null || classMeta === void 0 ? void 0 : classMeta.injectable) === 'SINGLETON') {
|
|
691
|
+
instance = (yield infact.get(controller, provide));
|
|
692
|
+
}
|
|
693
|
+
else if (!isControllerConsructor) {
|
|
694
|
+
instance = controller;
|
|
695
|
+
infact.setProvideRegByInstance(instance, provide);
|
|
696
|
+
}
|
|
697
|
+
// getInstance - instance factory for resolving SINGLETON and FOR_EVENT instance
|
|
698
|
+
const getInstance = instance ? () => Promise.resolve(instance) : () => __awaiter(this, void 0, void 0, function* () {
|
|
699
|
+
// if (!instance) {
|
|
700
|
+
infact.silent();
|
|
701
|
+
const instance = yield infact.get(controller, provide);
|
|
702
|
+
infact.silent(false);
|
|
703
|
+
// }
|
|
704
|
+
return instance;
|
|
705
|
+
});
|
|
706
|
+
const classConstructor = mate.isConstructor(controller) ? controller : mate.getConstructor(controller);
|
|
707
|
+
yield bindControllerMethods({
|
|
708
|
+
getInstance,
|
|
709
|
+
classConstructor,
|
|
710
|
+
adapters: this.adapters,
|
|
711
|
+
globalPrefix,
|
|
712
|
+
replaceOwnPrefix,
|
|
713
|
+
interceptors: [...this.interceptors],
|
|
714
|
+
pipes: [...this.pipes],
|
|
715
|
+
provide: (classMeta === null || classMeta === void 0 ? void 0 : classMeta.provide) || {},
|
|
716
|
+
});
|
|
717
|
+
if (classMeta && classMeta.importController) {
|
|
718
|
+
const prefix = typeof replaceOwnPrefix === 'string' ? replaceOwnPrefix : (_a = classMeta === null || classMeta === void 0 ? void 0 : classMeta.controller) === null || _a === void 0 ? void 0 : _a.prefix;
|
|
719
|
+
const mergedProvide = Object.assign(Object.assign({}, provide), ((classMeta === null || classMeta === void 0 ? void 0 : classMeta.provide) || {}));
|
|
720
|
+
for (const ic of classMeta.importController) {
|
|
721
|
+
if (ic.typeResolver) {
|
|
722
|
+
const isConstr = mate.isConstructor(ic.typeResolver);
|
|
723
|
+
const isFunc = typeof ic.typeResolver === 'function';
|
|
724
|
+
yield this.bindController(
|
|
725
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
726
|
+
isConstr ? ic.typeResolver : isFunc ? yield ic.typeResolver() : ic.typeResolver, ic.provide ? Object.assign(Object.assign({}, mergedProvide), ic.provide) : mergedProvide, `${globalPrefix}/${(prefix || '')}`, ic.prefix);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
applyGlobalPipes(...items) {
|
|
733
|
+
for (const item of items) {
|
|
734
|
+
if (typeof item === 'function') {
|
|
735
|
+
this.pipes.push({
|
|
736
|
+
handler: item,
|
|
737
|
+
priority: typeof item.priority === 'number' ? item.priority : exports.TPipePriority.TRANSFORM,
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
else {
|
|
741
|
+
this.pipes.push({
|
|
742
|
+
handler: item.handler,
|
|
743
|
+
priority: item.priority,
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
return this;
|
|
748
|
+
}
|
|
749
|
+
applyGlobalInterceptors(...items) {
|
|
750
|
+
for (const item of items) {
|
|
751
|
+
if (typeof item === 'function') {
|
|
752
|
+
this.interceptors.push({
|
|
753
|
+
handler: item,
|
|
754
|
+
priority: typeof item.priority === 'number' ? item.priority : exports.TInterceptorPriority.INTERCEPTOR,
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
else {
|
|
758
|
+
this.interceptors.push({
|
|
759
|
+
handler: item.handler,
|
|
760
|
+
priority: item.priority,
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
return this;
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* Register new entried to provide as dependency injections
|
|
768
|
+
* @param provide - Provide Registry (use createProvideRegistry from '\@prostojs/infact')
|
|
769
|
+
* @returns
|
|
770
|
+
*/
|
|
771
|
+
setProvideRegistry(provide) {
|
|
772
|
+
this.provide = Object.assign(Object.assign({}, this.provide), provide);
|
|
773
|
+
return this;
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* Register controllers (similar to @ImportController decorator)
|
|
777
|
+
* @param controllers - list of target controllers (instances)
|
|
778
|
+
* @returns
|
|
779
|
+
*/
|
|
780
|
+
registerControllers(...controllers) {
|
|
781
|
+
this.unregisteredControllers.push(...controllers);
|
|
782
|
+
return this;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
function useControllerMeta() {
|
|
787
|
+
const moostStore = useMoostStore();
|
|
788
|
+
return {
|
|
789
|
+
getClassMeta: () => getMoostMate().read(moostStore.value.controller),
|
|
790
|
+
getMethodMeta: () => getMoostMate().read(moostStore.value.controller, moostStore.value.method),
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
function useMoostStore() {
|
|
794
|
+
return useHttpContext().store('moost');
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
const genericTypesCastPipe = (strict) => {
|
|
798
|
+
const handler = (value, meta) => {
|
|
799
|
+
if (meta === null || meta === void 0 ? void 0 : meta.type) {
|
|
800
|
+
if ((value === undefined || value === null || (meta.type !== String && value === '')) && meta.optional) {
|
|
801
|
+
return undefined;
|
|
802
|
+
}
|
|
803
|
+
switch (meta.type) {
|
|
804
|
+
case Date: {
|
|
805
|
+
let d;
|
|
806
|
+
if (typeof value === 'string') {
|
|
807
|
+
d = new Date(/^\d+$/.test(value) ? Number(value) : value);
|
|
808
|
+
}
|
|
809
|
+
else {
|
|
810
|
+
d = new Date(value);
|
|
811
|
+
}
|
|
812
|
+
if (strict && Number.isNaN(d.getTime())) {
|
|
813
|
+
typeError(value, 'Date', meta.label);
|
|
814
|
+
}
|
|
815
|
+
return Number.isNaN(d.getTime()) ? value : d;
|
|
816
|
+
}
|
|
817
|
+
case Boolean:
|
|
818
|
+
if ([true, 'true', 'TRUE', 'True', 1, '1', 'X', 'x'].includes(value)) {
|
|
819
|
+
return true;
|
|
820
|
+
}
|
|
821
|
+
if ([false, 'false', 'FALSE', 'False', 0, '0', '', ' ', null, undefined].includes(value)) {
|
|
822
|
+
return false;
|
|
823
|
+
}
|
|
824
|
+
if (strict) {
|
|
825
|
+
typeError(value, 'boolean', meta.label);
|
|
826
|
+
}
|
|
827
|
+
return value;
|
|
828
|
+
case Number: {
|
|
829
|
+
if (strict && !value && value !== 0) {
|
|
830
|
+
typeError(value, 'numeric', meta.label);
|
|
831
|
+
}
|
|
832
|
+
const n = typeof value === 'string' && value.length > 0 ? Number(value) : NaN;
|
|
833
|
+
if (strict && Number.isNaN(n)) {
|
|
834
|
+
typeError(value, 'numeric', meta.label);
|
|
835
|
+
}
|
|
836
|
+
return Number.isNaN(n) ? value : n;
|
|
837
|
+
}
|
|
838
|
+
case String:
|
|
839
|
+
if (strict && ['object', 'function'].includes(typeof value)) {
|
|
840
|
+
typeError(value, 'string', meta.label);
|
|
841
|
+
}
|
|
842
|
+
return value && String(value) || value;
|
|
843
|
+
default:
|
|
844
|
+
return value;
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
};
|
|
848
|
+
handler.priority = exports.TPipePriority.AFTER_TRANSFORM;
|
|
849
|
+
return handler;
|
|
850
|
+
};
|
|
851
|
+
function typeError(value, targetType, label) {
|
|
852
|
+
const prefix = label ? `Argument "${label}" with value ` : '';
|
|
853
|
+
throw new WooksError(400, `${prefix}${JSON.stringify(value)} is not a ${targetType} type`);
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
const DEFAULT_ERROR_LIMIT = 10;
|
|
857
|
+
function firstString(errors) {
|
|
858
|
+
const keys = Object.keys(errors);
|
|
859
|
+
for (const key of keys) {
|
|
860
|
+
if (typeof errors[key] === 'string')
|
|
861
|
+
return errors[key];
|
|
862
|
+
return firstString(errors[key]);
|
|
863
|
+
}
|
|
864
|
+
return '';
|
|
865
|
+
}
|
|
866
|
+
const validatePipe = (opts) => {
|
|
867
|
+
const pipe = (_value, meta) => __awaiter(void 0, void 0, void 0, function* () {
|
|
868
|
+
const { restoreCtx } = useHttpContext();
|
|
869
|
+
const valido = getMoostValido();
|
|
870
|
+
const result = yield valido.validateParam(_value, meta, undefined, undefined, undefined, undefined, 0, 0, (opts === null || opts === void 0 ? void 0 : opts.errorLimit) || DEFAULT_ERROR_LIMIT, restoreCtx);
|
|
871
|
+
if (result !== true) {
|
|
872
|
+
throw new WooksError(400, {
|
|
873
|
+
statusCode: 400,
|
|
874
|
+
message: typeof result === 'string' ? result : firstString(result),
|
|
875
|
+
error: 'Validation Error',
|
|
876
|
+
details: result,
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
return _value;
|
|
880
|
+
});
|
|
881
|
+
pipe.priority = exports.TPipePriority.VALIDATE;
|
|
882
|
+
return pipe;
|
|
883
|
+
};
|
|
884
|
+
|
|
885
|
+
exports.Circular = Circular;
|
|
886
|
+
exports.Const = Const;
|
|
887
|
+
exports.Controller = Controller;
|
|
888
|
+
exports.Dto = Dto;
|
|
889
|
+
exports.Id = Id;
|
|
890
|
+
exports.ImportController = ImportController;
|
|
891
|
+
exports.Inject = Inject;
|
|
892
|
+
exports.Injectable = Injectable;
|
|
893
|
+
exports.Intercept = Intercept;
|
|
894
|
+
exports.InterceptorHandler = InterceptorHandler;
|
|
895
|
+
exports.IsArray = IsArray;
|
|
896
|
+
exports.IsBoolean = IsBoolean;
|
|
897
|
+
exports.IsNumber = IsNumber;
|
|
898
|
+
exports.IsString = IsString;
|
|
899
|
+
exports.IsTypeOf = IsTypeOf;
|
|
900
|
+
exports.Label = Label;
|
|
901
|
+
exports.Moost = Moost;
|
|
902
|
+
exports.Optional = Optional;
|
|
903
|
+
exports.Param = Param;
|
|
904
|
+
exports.Params = Params;
|
|
905
|
+
exports.Provide = Provide;
|
|
906
|
+
exports.Required = Required;
|
|
907
|
+
exports.Resolve = Resolve;
|
|
908
|
+
exports.Validate = Validate;
|
|
909
|
+
exports.genericTypesCastPipe = genericTypesCastPipe;
|
|
910
|
+
exports.getMoostMate = getMoostMate;
|
|
911
|
+
exports.resolvePipe = resolvePipe;
|
|
912
|
+
exports.useControllerMeta = useControllerMeta;
|
|
913
|
+
exports.validatePipe = validatePipe;
|