@moostjs/event-http 0.5.21 → 0.5.23

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 moostjs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs CHANGED
@@ -1,338 +1,345 @@
1
- 'use strict';
1
+ "use strict";
2
+ //#region rolldown:runtime
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
2
23
 
3
- var moost = require('moost');
4
- var eventCore = require('@wooksjs/event-core');
5
- var eventHttp = require('@wooksjs/event-http');
6
- var httpBody = require('@wooksjs/http-body');
7
- var infact = require('@prostojs/infact');
8
- var http = require('http');
9
- var https = require('https');
24
+ //#endregion
25
+ const moost = __toESM(require("moost"));
26
+ const __wooksjs_event_core = __toESM(require("@wooksjs/event-core"));
27
+ const __wooksjs_event_http = __toESM(require("@wooksjs/event-http"));
28
+ const __wooksjs_http_body = __toESM(require("@wooksjs/http-body"));
29
+ const __prostojs_infact = __toESM(require("@prostojs/infact"));
30
+ const http = __toESM(require("http"));
31
+ const https = __toESM(require("https"));
10
32
 
33
+ //#region packages/event-http/src/decorators/http-method.decorator.ts
11
34
  function HttpMethod(method, path) {
12
- return moost.getMoostMate().decorate('handlers', { method, path, type: 'HTTP' }, true);
35
+ return (0, moost.getMoostMate)().decorate("handlers", {
36
+ method,
37
+ path,
38
+ type: "HTTP"
39
+ }, true);
13
40
  }
14
- const All = (path) => HttpMethod('*', path);
15
- const Get = (path) => HttpMethod('GET', path);
16
- const Post = (path) => HttpMethod('POST', path);
17
- const Put = (path) => HttpMethod('PUT', path);
18
- const Delete = (path) => HttpMethod('DELETE', path);
19
- const Patch = (path) => HttpMethod('PATCH', path);
41
+ const All = (path) => HttpMethod("*", path);
42
+ const Get = (path) => HttpMethod("GET", path);
43
+ const Post = (path) => HttpMethod("POST", path);
44
+ const Put = (path) => HttpMethod("PUT", path);
45
+ const Delete = (path) => HttpMethod("DELETE", path);
46
+ const Patch = (path) => HttpMethod("PATCH", path);
20
47
 
21
- const StatusHook = () => moost.Resolve((metas, level) => {
22
- const hook = eventHttp.useStatus();
23
- if (level === 'PARAM') {
24
- return hook;
25
- }
26
- if (level === 'PROP' && metas.instance && metas.key) {
27
- const initialValue = metas.instance[metas.key];
28
- eventCore.attachHook(metas.instance, {
29
- get: () => hook.value,
30
- set: v => (hook.value = v),
31
- }, metas.key);
32
- return typeof initialValue === 'number' ? initialValue : 200;
33
- }
34
- }, 'statusCode');
35
- const HeaderHook = (name) => moost.Resolve((metas, level) => {
36
- const hook = eventHttp.useSetHeader(name);
37
- if (level === 'PARAM') {
38
- return hook;
39
- }
40
- if (level === 'PROP' && metas.instance && metas.key) {
41
- const initialValue = metas.instance[metas.key];
42
- eventCore.attachHook(metas.instance, {
43
- get: () => hook.value,
44
- set: v => (hook.value = v),
45
- }, metas.key);
46
- return typeof initialValue === 'string' ? initialValue : '';
47
- }
48
+ //#endregion
49
+ //#region packages/event-http/src/decorators/resolve.decorator.ts
50
+ const StatusHook = () => (0, moost.Resolve)((metas, level) => {
51
+ const hook = (0, __wooksjs_event_http.useStatus)();
52
+ if (level === "PARAM") return hook;
53
+ if (level === "PROP" && metas.instance && metas.key) {
54
+ const initialValue = metas.instance[metas.key];
55
+ (0, __wooksjs_event_core.attachHook)(metas.instance, {
56
+ get: () => hook.value,
57
+ set: (v) => hook.value = v
58
+ }, metas.key);
59
+ return typeof initialValue === "number" ? initialValue : 200;
60
+ }
61
+ }, "statusCode");
62
+ const HeaderHook = (name) => (0, moost.Resolve)((metas, level) => {
63
+ const hook = (0, __wooksjs_event_http.useSetHeader)(name);
64
+ if (level === "PARAM") return hook;
65
+ if (level === "PROP" && metas.instance && metas.key) {
66
+ const initialValue = metas.instance[metas.key];
67
+ (0, __wooksjs_event_core.attachHook)(metas.instance, {
68
+ get: () => hook.value,
69
+ set: (v) => hook.value = v
70
+ }, metas.key);
71
+ return typeof initialValue === "string" ? initialValue : "";
72
+ }
48
73
  }, name);
49
- const CookieHook = (name) => moost.Resolve((metas, level) => {
50
- const hook = eventHttp.useSetCookie(name);
51
- if (level === 'PARAM') {
52
- return hook;
53
- }
54
- if (level === 'PROP' && metas.instance && metas.key) {
55
- const initialValue = metas.instance[metas.key];
56
- eventCore.attachHook(metas.instance, {
57
- get: () => hook.value,
58
- set: v => (hook.value = v),
59
- }, metas.key);
60
- return typeof initialValue === 'string' ? initialValue : '';
61
- }
74
+ const CookieHook = (name) => (0, moost.Resolve)((metas, level) => {
75
+ const hook = (0, __wooksjs_event_http.useSetCookie)(name);
76
+ if (level === "PARAM") return hook;
77
+ if (level === "PROP" && metas.instance && metas.key) {
78
+ const initialValue = metas.instance[metas.key];
79
+ (0, __wooksjs_event_core.attachHook)(metas.instance, {
80
+ get: () => hook.value,
81
+ set: (v) => hook.value = v
82
+ }, metas.key);
83
+ return typeof initialValue === "string" ? initialValue : "";
84
+ }
62
85
  }, name);
63
- const CookieAttrsHook = (name) => moost.Resolve((metas, level) => {
64
- const hook = eventHttp.useSetCookie(name);
65
- if (level === 'PARAM') {
66
- return eventCore.attachHook({}, {
67
- get: () => hook.attrs,
68
- set: v => (hook.attrs = v),
69
- });
70
- }
71
- if (level === 'PROP' && metas.instance && metas.key) {
72
- const initialValue = metas.instance[metas.key];
73
- eventCore.attachHook(metas.instance, {
74
- get: () => hook.attrs,
75
- set: v => (hook.attrs = v),
76
- }, metas.key);
77
- return typeof initialValue === 'object' ? initialValue : {};
78
- }
86
+ const CookieAttrsHook = (name) => (0, moost.Resolve)((metas, level) => {
87
+ const hook = (0, __wooksjs_event_http.useSetCookie)(name);
88
+ if (level === "PARAM") return (0, __wooksjs_event_core.attachHook)({}, {
89
+ get: () => hook.attrs,
90
+ set: (v) => hook.attrs = v
91
+ });
92
+ if (level === "PROP" && metas.instance && metas.key) {
93
+ const initialValue = metas.instance[metas.key];
94
+ (0, __wooksjs_event_core.attachHook)(metas.instance, {
95
+ get: () => hook.attrs,
96
+ set: (v) => hook.attrs = v
97
+ }, metas.key);
98
+ return typeof initialValue === "object" ? initialValue : {};
99
+ }
79
100
  }, name);
80
101
  function Authorization(name) {
81
- return moost.Resolve(() => {
82
- const auth = eventHttp.useAuthorization();
83
- switch (name) {
84
- case 'username': {
85
- return auth.isBasic() ? auth.basicCredentials()?.username : undefined;
86
- }
87
- case 'password': {
88
- return auth.isBasic() ? auth.basicCredentials()?.password : undefined;
89
- }
90
- case 'bearer': {
91
- return auth.isBearer() ? auth.authorization : undefined;
92
- }
93
- case 'raw': {
94
- return auth.authRawCredentials();
95
- }
96
- case 'type': {
97
- return auth.authType();
98
- }
99
- }
100
- }, 'authorization');
102
+ return (0, moost.Resolve)(() => {
103
+ const auth = (0, __wooksjs_event_http.useAuthorization)();
104
+ switch (name) {
105
+ case "username": return auth.isBasic() ? auth.basicCredentials()?.username : undefined;
106
+ case "password": return auth.isBasic() ? auth.basicCredentials()?.password : undefined;
107
+ case "bearer": return auth.isBearer() ? auth.authorization : undefined;
108
+ case "raw": return auth.authRawCredentials();
109
+ case "type": return auth.authType();
110
+ }
111
+ }, "authorization");
101
112
  }
102
113
  function Header(name) {
103
- return moost.Resolve(() => {
104
- const headers = eventHttp.useHeaders();
105
- return headers[name];
106
- }, `header: ${name}`);
114
+ return (0, moost.Resolve)(() => {
115
+ const headers = (0, __wooksjs_event_http.useHeaders)();
116
+ return headers[name];
117
+ }, `header: ${name}`);
107
118
  }
108
119
  function Cookie(name) {
109
- return moost.Resolve(() => eventHttp.useCookies().getCookie(name), `cookie: ${name}`);
120
+ return (0, moost.Resolve)(() => (0, __wooksjs_event_http.useCookies)().getCookie(name), `cookie: ${name}`);
110
121
  }
111
122
  function Query(name) {
112
- const isItem = !!name;
113
- const _name = isItem ? name : 'Query';
114
- return moost.getMoostMate().apply(moost.getMoostMate().decorate('paramSource', isItem ? 'QUERY_ITEM' : 'QUERY'), moost.getMoostMate().decorate('paramName', _name), moost.Resolve(() => {
115
- const { jsonSearchParams, urlSearchParams } = eventHttp.useSearchParams();
116
- if (isItem) {
117
- const p = urlSearchParams();
118
- const value = p.get(name);
119
- return value === null ? undefined : value;
120
- }
121
- const json = jsonSearchParams();
122
- return Object.keys(json).length > 0 ? json : undefined;
123
- }, _name));
123
+ const isItem = !!name;
124
+ const _name = isItem ? name : "Query";
125
+ return (0, moost.getMoostMate)().apply((0, moost.getMoostMate)().decorate("paramSource", isItem ? "QUERY_ITEM" : "QUERY"), (0, moost.getMoostMate)().decorate("paramName", _name), (0, moost.Resolve)(() => {
126
+ const { jsonSearchParams, urlSearchParams } = (0, __wooksjs_event_http.useSearchParams)();
127
+ if (isItem) {
128
+ const p = urlSearchParams();
129
+ const value = p.get(name);
130
+ return value === null ? undefined : value;
131
+ }
132
+ const json = jsonSearchParams();
133
+ return Object.keys(json).length > 0 ? json : undefined;
134
+ }, _name));
124
135
  }
125
136
  function Url() {
126
- return moost.Resolve(() => eventHttp.useRequest().url || '', 'url');
137
+ return (0, moost.Resolve)(() => (0, __wooksjs_event_http.useRequest)().url || "", "url");
127
138
  }
128
139
  function Method() {
129
- return moost.Resolve(() => eventHttp.useRequest().method, 'http_method');
140
+ return (0, moost.Resolve)(() => (0, __wooksjs_event_http.useRequest)().method, "http_method");
130
141
  }
131
142
  function Req() {
132
- return moost.Resolve(() => eventHttp.useRequest().rawRequest, 'request');
143
+ return (0, moost.Resolve)(() => (0, __wooksjs_event_http.useRequest)().rawRequest, "request");
133
144
  }
134
145
  function Res(opts) {
135
- return moost.Resolve(() => eventHttp.useResponse().rawResponse(opts), 'response');
146
+ return (0, moost.Resolve)(() => (0, __wooksjs_event_http.useResponse)().rawResponse(opts), "response");
136
147
  }
137
148
  function ReqId() {
138
- return moost.Resolve(() => eventHttp.useRequest().reqId(), 'reqId');
149
+ return (0, moost.Resolve)(() => (0, __wooksjs_event_http.useRequest)().reqId(), "reqId");
139
150
  }
140
151
  function Ip(opts) {
141
- return moost.Resolve(() => eventHttp.useRequest().getIp(opts), 'ip');
152
+ return (0, moost.Resolve)(() => (0, __wooksjs_event_http.useRequest)().getIp(opts), "ip");
142
153
  }
143
154
  function IpList() {
144
- return moost.Resolve(() => eventHttp.useRequest().getIpList(), 'ipList');
155
+ return (0, moost.Resolve)(() => (0, __wooksjs_event_http.useRequest)().getIpList(), "ipList");
145
156
  }
146
157
  function Body() {
147
- return moost.getMoostMate().apply(moost.getMoostMate().decorate('paramSource', 'BODY'), moost.Resolve(() => httpBody.useBody().parseBody(), 'body'));
158
+ return (0, moost.getMoostMate)().apply((0, moost.getMoostMate)().decorate("paramSource", "BODY"), (0, moost.Resolve)(() => (0, __wooksjs_http_body.useBody)().parseBody(), "body"));
148
159
  }
149
160
  function RawBody() {
150
- return moost.Resolve(() => httpBody.useBody().rawBody(), 'body');
161
+ return (0, moost.Resolve)(() => (0, __wooksjs_http_body.useBody)().rawBody(), "body");
151
162
  }
152
163
 
164
+ //#endregion
165
+ //#region packages/event-http/src/decorators/set.decorator.ts
153
166
  const setHeaderInterceptor = (name, value, opts) => {
154
- const fn = (_before, after, onError) => {
155
- const h = eventHttp.useSetHeader(name);
156
- const status = eventHttp.useStatus();
157
- const cb = () => {
158
- if ((!h.value || opts?.force) && (!opts?.status || opts.status === status.value)) {
159
- h.value = value;
160
- }
161
- };
162
- if (opts?.when !== 'error') {
163
- after(cb);
164
- }
165
- if (opts?.when === 'always' || opts?.when === 'error') {
166
- onError(cb);
167
- }
168
- };
169
- fn.priority = moost.TInterceptorPriority.AFTER_ALL;
170
- return fn;
167
+ const fn = (_before, after, onError) => {
168
+ const h = (0, __wooksjs_event_http.useSetHeader)(name);
169
+ const status = (0, __wooksjs_event_http.useStatus)();
170
+ const cb = () => {
171
+ if ((!h.value || opts?.force) && (!opts?.status || opts.status === status.value)) h.value = value;
172
+ };
173
+ if (opts?.when !== "error") after(cb);
174
+ if (opts?.when === "always" || opts?.when === "error") onError(cb);
175
+ };
176
+ fn.priority = moost.TInterceptorPriority.AFTER_ALL;
177
+ return fn;
171
178
  };
172
179
  function SetHeader(...args) {
173
- return moost.Intercept(setHeaderInterceptor(...args));
180
+ return (0, moost.Intercept)(setHeaderInterceptor(...args));
174
181
  }
175
182
  const setCookieInterceptor = (name, value, attrs) => {
176
- const fn = (before, after) => {
177
- const { setCookie, getCookie } = eventHttp.useSetCookies();
178
- after(() => {
179
- if (!getCookie(name)) {
180
- setCookie(name, value, attrs);
181
- }
182
- });
183
- };
184
- fn.priority = moost.TInterceptorPriority.AFTER_ALL;
185
- return fn;
183
+ const fn = (before, after) => {
184
+ const { setCookie, getCookie } = (0, __wooksjs_event_http.useSetCookies)();
185
+ after(() => {
186
+ if (!getCookie(name)) setCookie(name, value, attrs);
187
+ });
188
+ };
189
+ fn.priority = moost.TInterceptorPriority.AFTER_ALL;
190
+ return fn;
186
191
  };
187
192
  function SetCookie(...args) {
188
- return moost.Intercept(setCookieInterceptor(...args));
193
+ return (0, moost.Intercept)(setCookieInterceptor(...args));
189
194
  }
190
- const setStatusInterceptor = (code, opts) => moost.defineInterceptorFn((before, after) => {
191
- const status = eventHttp.useStatus();
192
- after(() => {
193
- if (!status.isDefined || opts?.force) {
194
- status.value = code;
195
- }
196
- });
195
+ const setStatusInterceptor = (code, opts) => (0, moost.defineInterceptorFn)((before, after) => {
196
+ const status = (0, __wooksjs_event_http.useStatus)();
197
+ after(() => {
198
+ if (!status.isDefined || opts?.force) status.value = code;
199
+ });
197
200
  });
198
201
  function SetStatus(...args) {
199
- return moost.Intercept(setStatusInterceptor(...args));
202
+ return (0, moost.Intercept)(setStatusInterceptor(...args));
200
203
  }
201
204
 
202
- const LOGGER_TITLE = 'moost-http';
203
- const CONTEXT_TYPE = 'HTTP';
204
- class MoostHttp {
205
- constructor(httpApp) {
206
- this.name = 'http';
207
- this.pathBuilders = {};
208
- if (httpApp && httpApp instanceof eventHttp.WooksHttp) {
209
- this.httpApp = httpApp;
210
- }
211
- else if (httpApp) {
212
- this.httpApp = eventHttp.createHttpApp({
213
- ...httpApp,
214
- onNotFound: this.onNotFound.bind(this),
215
- });
216
- }
217
- else {
218
- this.httpApp = eventHttp.createHttpApp({
219
- onNotFound: this.onNotFound.bind(this),
220
- });
221
- }
222
- }
223
- getHttpApp() {
224
- return this.httpApp;
225
- }
226
- getServerCb() {
227
- return this.httpApp.getServerCb();
228
- }
229
- listen(port, hostname, backlog, listeningListener) {
230
- return this.httpApp.listen(port, hostname, backlog, listeningListener);
231
- }
232
- async onNotFound() {
233
- return moost.defineMoostEventHandler({
234
- loggerTitle: LOGGER_TITLE,
235
- getIterceptorHandler: () => this.moost?.getGlobalInterceptorHandler(),
236
- getControllerInstance: () => this.moost,
237
- callControllerMethod: () => new eventHttp.HttpError(404, 'Resource Not Found'),
238
- targetPath: '',
239
- handlerType: '__SYSTEM__',
240
- })();
241
- }
242
- onInit(moost) {
243
- this.moost = moost;
244
- }
245
- getProvideRegistry() {
246
- return infact.createProvideRegistry([eventHttp.WooksHttp, () => this.getHttpApp()], ['WooksHttp', () => this.getHttpApp()], [http.Server, () => this.getHttpApp().getServer()], [https.Server, () => this.getHttpApp().getServer()]);
247
- }
248
- getLogger() {
249
- return this.getHttpApp().getLogger('[moost-http]');
250
- }
251
- bindHandler(opts) {
252
- let fn;
253
- for (const handler of opts.handlers) {
254
- if (handler.type !== 'HTTP') {
255
- continue;
256
- }
257
- const httpPath = handler.path;
258
- const path = typeof httpPath === 'string' ? httpPath : typeof opts.method === 'string' ? opts.method : '';
259
- const targetPath = `${`${opts.prefix || ''}/${path}`.replace(/\/\/+/g, '/')}${path.endsWith('//') ? '/' : ''}`;
260
- fn = moost.defineMoostEventHandler({
261
- contextType: CONTEXT_TYPE,
262
- loggerTitle: LOGGER_TITLE,
263
- getIterceptorHandler: opts.getIterceptorHandler,
264
- getControllerInstance: opts.getInstance,
265
- controllerMethod: opts.method,
266
- resolveArgs: opts.resolveArgs,
267
- manualUnscope: true,
268
- hooks: {
269
- init: ({ unscope }) => {
270
- const { rawRequest } = eventHttp.useRequest();
271
- rawRequest.on('end', unscope);
272
- },
273
- },
274
- targetPath,
275
- handlerType: handler.type,
276
- });
277
- const routerBinding = this.httpApp.on(handler.method, targetPath, fn);
278
- const { getPath: pathBuilder } = routerBinding;
279
- const methodMeta = moost.getMoostMate().read(opts.fakeInstance, opts.method) || {};
280
- const id = (methodMeta.id || opts.method);
281
- if (id) {
282
- const methods = (this.pathBuilders[id] = this.pathBuilders[id] || {});
283
- if (handler.method === '*') {
284
- methods.GET = pathBuilder;
285
- methods.PUT = pathBuilder;
286
- methods.PATCH = pathBuilder;
287
- methods.POST = pathBuilder;
288
- methods.DELETE = pathBuilder;
289
- }
290
- else {
291
- methods[handler.method] = pathBuilder;
292
- }
293
- }
294
- opts.logHandler(`${''}(${handler.method})${''}${targetPath}`);
295
- const args = routerBinding.getArgs();
296
- const params = {};
297
- args.forEach(a => (params[a] = `{${a}}`));
298
- opts.register(handler, routerBinding.getPath(params), args);
299
- }
300
- }
205
+ //#endregion
206
+ //#region packages/event-http/src/event-http.ts
207
+ function _define_property(obj, key, value) {
208
+ if (key in obj) Object.defineProperty(obj, key, {
209
+ value,
210
+ enumerable: true,
211
+ configurable: true,
212
+ writable: true
213
+ });
214
+ else obj[key] = value;
215
+ return obj;
301
216
  }
217
+ const LOGGER_TITLE = "moost-http";
218
+ const CONTEXT_TYPE = "HTTP";
219
+ var MoostHttp = class {
220
+ getHttpApp() {
221
+ return this.httpApp;
222
+ }
223
+ getServerCb() {
224
+ return this.httpApp.getServerCb();
225
+ }
226
+ listen(port, hostname, backlog, listeningListener) {
227
+ return this.httpApp.listen(port, hostname, backlog, listeningListener);
228
+ }
229
+ async onNotFound() {
230
+ return (0, moost.defineMoostEventHandler)({
231
+ loggerTitle: LOGGER_TITLE,
232
+ getIterceptorHandler: () => this.moost?.getGlobalInterceptorHandler(),
233
+ getControllerInstance: () => this.moost,
234
+ callControllerMethod: () => new __wooksjs_event_http.HttpError(404, "Resource Not Found"),
235
+ targetPath: "",
236
+ handlerType: "__SYSTEM__"
237
+ })();
238
+ }
239
+ onInit(moost$1) {
240
+ this.moost = moost$1;
241
+ }
242
+ getProvideRegistry() {
243
+ return (0, __prostojs_infact.createProvideRegistry)([__wooksjs_event_http.WooksHttp, () => this.getHttpApp()], ["WooksHttp", () => this.getHttpApp()], [http.Server, () => this.getHttpApp().getServer()], [https.Server, () => this.getHttpApp().getServer()]);
244
+ }
245
+ getLogger() {
246
+ return this.getHttpApp().getLogger("[moost-http]");
247
+ }
248
+ bindHandler(opts) {
249
+ let fn;
250
+ for (const handler of opts.handlers) {
251
+ if (handler.type !== "HTTP") continue;
252
+ const httpPath = handler.path;
253
+ const path = typeof httpPath === "string" ? httpPath : typeof opts.method === "string" ? opts.method : "";
254
+ const targetPath = `${`${opts.prefix || ""}/${path}`.replace(/\/\/+/g, "/")}${path.endsWith("//") ? "/" : ""}`;
255
+ fn = (0, moost.defineMoostEventHandler)({
256
+ contextType: CONTEXT_TYPE,
257
+ loggerTitle: LOGGER_TITLE,
258
+ getIterceptorHandler: opts.getIterceptorHandler,
259
+ getControllerInstance: opts.getInstance,
260
+ controllerMethod: opts.method,
261
+ resolveArgs: opts.resolveArgs,
262
+ manualUnscope: true,
263
+ hooks: { init: ({ unscope }) => {
264
+ const { rawRequest } = (0, __wooksjs_event_http.useRequest)();
265
+ rawRequest.on("end", unscope);
266
+ } },
267
+ targetPath,
268
+ handlerType: handler.type
269
+ });
270
+ const routerBinding = this.httpApp.on(handler.method, targetPath, fn);
271
+ const { getPath: pathBuilder } = routerBinding;
272
+ const methodMeta = (0, moost.getMoostMate)().read(opts.fakeInstance, opts.method) || {};
273
+ const id = methodMeta.id || opts.method;
274
+ if (id) {
275
+ const methods = this.pathBuilders[id] = this.pathBuilders[id] || {};
276
+ if (handler.method === "*") {
277
+ methods.GET = pathBuilder;
278
+ methods.PUT = pathBuilder;
279
+ methods.PATCH = pathBuilder;
280
+ methods.POST = pathBuilder;
281
+ methods.DELETE = pathBuilder;
282
+ } else methods[handler.method] = pathBuilder;
283
+ }
284
+ opts.logHandler(`${"\x1B[36m"}(${handler.method})${"\x1B[32m"}${targetPath}`);
285
+ const args = routerBinding.getArgs();
286
+ const params = {};
287
+ args.forEach((a) => params[a] = `{${a}}`);
288
+ opts.register(handler, routerBinding.getPath(params), args);
289
+ }
290
+ }
291
+ constructor(httpApp) {
292
+ _define_property(this, "name", "http");
293
+ _define_property(this, "httpApp", void 0);
294
+ _define_property(this, "pathBuilders", {});
295
+ _define_property(this, "moost", void 0);
296
+ if (httpApp && httpApp instanceof __wooksjs_event_http.WooksHttp) this.httpApp = httpApp;
297
+ else if (httpApp) this.httpApp = (0, __wooksjs_event_http.createHttpApp)({
298
+ ...httpApp,
299
+ onNotFound: this.onNotFound.bind(this)
300
+ });
301
+ else this.httpApp = (0, __wooksjs_event_http.createHttpApp)({ onNotFound: this.onNotFound.bind(this) });
302
+ }
303
+ };
302
304
 
303
- Object.defineProperty(exports, "HttpError", {
305
+ //#endregion
306
+ exports.All = All
307
+ exports.Authorization = Authorization
308
+ exports.Body = Body
309
+ exports.Cookie = Cookie
310
+ exports.CookieAttrsHook = CookieAttrsHook
311
+ exports.CookieHook = CookieHook
312
+ exports.Delete = Delete
313
+ exports.Get = Get
314
+ exports.Header = Header
315
+ exports.HeaderHook = HeaderHook
316
+ Object.defineProperty(exports, 'HttpError', {
304
317
  enumerable: true,
305
- get: function () { return eventHttp.HttpError; }
318
+ get: function () {
319
+ return __wooksjs_event_http.HttpError;
320
+ }
306
321
  });
307
- Object.defineProperty(exports, "useHttpContext", {
322
+ exports.HttpMethod = HttpMethod
323
+ exports.Ip = Ip
324
+ exports.IpList = IpList
325
+ exports.Method = Method
326
+ exports.MoostHttp = MoostHttp
327
+ exports.Patch = Patch
328
+ exports.Post = Post
329
+ exports.Put = Put
330
+ exports.Query = Query
331
+ exports.RawBody = RawBody
332
+ exports.Req = Req
333
+ exports.ReqId = ReqId
334
+ exports.Res = Res
335
+ exports.SetCookie = SetCookie
336
+ exports.SetHeader = SetHeader
337
+ exports.SetStatus = SetStatus
338
+ exports.StatusHook = StatusHook
339
+ exports.Url = Url
340
+ Object.defineProperty(exports, 'useHttpContext', {
308
341
  enumerable: true,
309
- get: function () { return eventHttp.useHttpContext; }
310
- });
311
- exports.All = All;
312
- exports.Authorization = Authorization;
313
- exports.Body = Body;
314
- exports.Cookie = Cookie;
315
- exports.CookieAttrsHook = CookieAttrsHook;
316
- exports.CookieHook = CookieHook;
317
- exports.Delete = Delete;
318
- exports.Get = Get;
319
- exports.Header = Header;
320
- exports.HeaderHook = HeaderHook;
321
- exports.HttpMethod = HttpMethod;
322
- exports.Ip = Ip;
323
- exports.IpList = IpList;
324
- exports.Method = Method;
325
- exports.MoostHttp = MoostHttp;
326
- exports.Patch = Patch;
327
- exports.Post = Post;
328
- exports.Put = Put;
329
- exports.Query = Query;
330
- exports.RawBody = RawBody;
331
- exports.Req = Req;
332
- exports.ReqId = ReqId;
333
- exports.Res = Res;
334
- exports.SetCookie = SetCookie;
335
- exports.SetHeader = SetHeader;
336
- exports.SetStatus = SetStatus;
337
- exports.StatusHook = StatusHook;
338
- exports.Url = Url;
342
+ get: function () {
343
+ return __wooksjs_event_http.useHttpContext;
344
+ }
345
+ });