@moostjs/event-http 0.2.8 → 0.2.10
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/dist/index.cjs +103 -22
- package/dist/index.d.ts +27 -16
- package/dist/index.mjs +103 -23
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var eventHttp = require('@wooksjs/event-http');
|
|
4
4
|
var moost = require('moost');
|
|
5
|
-
require('@wooksjs/event-core');
|
|
5
|
+
var eventCore = require('@wooksjs/event-core');
|
|
6
6
|
|
|
7
7
|
/******************************************************************************
|
|
8
8
|
Copyright (c) Microsoft Corporation.
|
|
@@ -335,21 +335,83 @@ function useBody() {
|
|
|
335
335
|
* @decorator
|
|
336
336
|
* @paramType TStatusHook
|
|
337
337
|
*/
|
|
338
|
-
const StatusHook =
|
|
338
|
+
const StatusHook = () => moost.Resolve((metas, level) => {
|
|
339
|
+
const hook = eventHttp.useStatus();
|
|
340
|
+
if (level === 'PARAM') {
|
|
341
|
+
return hook;
|
|
342
|
+
}
|
|
343
|
+
if (level === 'PROP' && metas.instance && metas.key) {
|
|
344
|
+
const initialValue = metas.instance[metas.key];
|
|
345
|
+
eventCore.attachHook(metas.instance, {
|
|
346
|
+
get: () => hook.value,
|
|
347
|
+
set: (v) => hook.value = v,
|
|
348
|
+
}, metas.key);
|
|
349
|
+
return typeof initialValue === 'number' ? initialValue : 200;
|
|
350
|
+
}
|
|
351
|
+
}, 'statusCode');
|
|
339
352
|
/**
|
|
340
353
|
* Hook to the Response Header
|
|
341
354
|
* @decorator
|
|
342
355
|
* @param name - header name
|
|
343
356
|
* @paramType THeaderHook
|
|
344
357
|
*/
|
|
345
|
-
const HeaderHook = (name) => moost.Resolve(() =>
|
|
358
|
+
const HeaderHook = (name) => moost.Resolve((metas, level) => {
|
|
359
|
+
const hook = eventHttp.useSetHeader(name);
|
|
360
|
+
if (level === 'PARAM') {
|
|
361
|
+
return hook;
|
|
362
|
+
}
|
|
363
|
+
if (level === 'PROP' && metas.instance && metas.key) {
|
|
364
|
+
const initialValue = metas.instance[metas.key];
|
|
365
|
+
eventCore.attachHook(metas.instance, {
|
|
366
|
+
get: () => hook.value,
|
|
367
|
+
set: (v) => hook.value = v,
|
|
368
|
+
}, metas.key);
|
|
369
|
+
return typeof initialValue === 'string' ? initialValue : '';
|
|
370
|
+
}
|
|
371
|
+
}, name);
|
|
346
372
|
/**
|
|
347
373
|
* Hook to the Response Cookie
|
|
348
374
|
* @decorator
|
|
349
|
-
* @param name -
|
|
375
|
+
* @param name - cookie name
|
|
350
376
|
* @paramType TCookieHook
|
|
351
377
|
*/
|
|
352
|
-
const CookieHook = (name) => moost.Resolve(() =>
|
|
378
|
+
const CookieHook = (name) => moost.Resolve((metas, level) => {
|
|
379
|
+
const hook = eventHttp.useSetCookie(name);
|
|
380
|
+
if (level === 'PARAM') {
|
|
381
|
+
return hook;
|
|
382
|
+
}
|
|
383
|
+
if (level === 'PROP' && metas.instance && metas.key) {
|
|
384
|
+
const initialValue = metas.instance[metas.key];
|
|
385
|
+
eventCore.attachHook(metas.instance, {
|
|
386
|
+
get: () => hook.value,
|
|
387
|
+
set: (v) => hook.value = v,
|
|
388
|
+
}, metas.key);
|
|
389
|
+
return typeof initialValue === 'string' ? initialValue : '';
|
|
390
|
+
}
|
|
391
|
+
}, name);
|
|
392
|
+
/**
|
|
393
|
+
* Hook to the Response Cookie Attributes
|
|
394
|
+
* @decorator
|
|
395
|
+
* @param name - cookie name
|
|
396
|
+
* @paramType TCookieHook
|
|
397
|
+
*/
|
|
398
|
+
const CookieAttrsHook = (name) => moost.Resolve((metas, level) => {
|
|
399
|
+
const hook = eventHttp.useSetCookie(name);
|
|
400
|
+
if (level === 'PARAM') {
|
|
401
|
+
return eventCore.attachHook({}, {
|
|
402
|
+
get: () => hook.attrs,
|
|
403
|
+
set: (v) => hook.attrs = v,
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
if (level === 'PROP' && metas.instance && metas.key) {
|
|
407
|
+
const initialValue = metas.instance[metas.key];
|
|
408
|
+
eventCore.attachHook(metas.instance, {
|
|
409
|
+
get: () => hook.attrs,
|
|
410
|
+
set: (v) => hook.attrs = v,
|
|
411
|
+
}, metas.key);
|
|
412
|
+
return typeof initialValue === 'object' ? initialValue : {};
|
|
413
|
+
}
|
|
414
|
+
}, name);
|
|
353
415
|
/**
|
|
354
416
|
* Parse Authorisation Header
|
|
355
417
|
* @decorator
|
|
@@ -497,15 +559,6 @@ function isConstructor(v) {
|
|
|
497
559
|
return typeof v === 'function' && Object.getOwnPropertyNames(v).includes('prototype') && !Object.getOwnPropertyNames(v).includes('caller') && !!v.name;
|
|
498
560
|
}
|
|
499
561
|
|
|
500
|
-
const banner = () => `[prostojs/mate][${new Date().toISOString().replace('T', ' ').replace(/\.\d{3}z$/i, '')}] `;
|
|
501
|
-
|
|
502
|
-
function warn(text) {
|
|
503
|
-
console.log('[33m' + banner() + text + '[0m');
|
|
504
|
-
}
|
|
505
|
-
function logError(error) {
|
|
506
|
-
console.error('[91m' + '[1m' + banner() + error + '[0m');
|
|
507
|
-
}
|
|
508
|
-
|
|
509
562
|
const classMetadata = {};
|
|
510
563
|
const paramMetadata = {};
|
|
511
564
|
const root = typeof global === 'object' ? global : typeof self === 'object' ? self : {};
|
|
@@ -542,19 +595,20 @@ else {
|
|
|
542
595
|
'metadata',
|
|
543
596
|
];
|
|
544
597
|
const target = root.Reflect;
|
|
545
|
-
let isOriginalReflectMetadata = true;
|
|
546
598
|
for (const func of funcs) {
|
|
547
599
|
if (typeof target[func] !== 'function') {
|
|
548
600
|
Object.defineProperty(target, func, { configurable: true, writable: true, value: _reflect[func] });
|
|
549
|
-
isOriginalReflectMetadata = false;
|
|
550
601
|
}
|
|
551
602
|
}
|
|
552
|
-
if (!isOriginalReflectMetadata) {
|
|
553
|
-
warn('A limited \'reflect-metadata\' implementation is used. In case of any issues include original \'reflect-metadata\' package and require it before any @prostojs/mate import.');
|
|
554
|
-
}
|
|
555
603
|
}
|
|
556
604
|
const Reflect$1 = _reflect;
|
|
557
605
|
|
|
606
|
+
const banner = () => `[prostojs/mate][${new Date().toISOString().replace('T', ' ').replace(/\.\d{3}z$/i, '')}] `;
|
|
607
|
+
|
|
608
|
+
function logError(error) {
|
|
609
|
+
console.error('[91m' + '[1m' + banner() + error + '[0m');
|
|
610
|
+
}
|
|
611
|
+
|
|
558
612
|
function panic(error) {
|
|
559
613
|
logError(error);
|
|
560
614
|
return new Error(error);
|
|
@@ -596,6 +650,17 @@ class Mate {
|
|
|
596
650
|
data = data.params[index];
|
|
597
651
|
}
|
|
598
652
|
}
|
|
653
|
+
else if (!index && !args.descriptor && args.propKey && this.options.collectPropKeys && args.level !== 'CLASS') {
|
|
654
|
+
this.set({ ...args, level: 'CLASS' }, (meta) => {
|
|
655
|
+
if (!meta.properties) {
|
|
656
|
+
meta.properties = [args.propKey];
|
|
657
|
+
}
|
|
658
|
+
else if (!meta.properties.includes(args.propKey)) {
|
|
659
|
+
meta.properties.push(args.propKey);
|
|
660
|
+
}
|
|
661
|
+
return meta;
|
|
662
|
+
});
|
|
663
|
+
}
|
|
599
664
|
if (typeof key !== 'function') {
|
|
600
665
|
if (isArray) {
|
|
601
666
|
const newArray = (data[key] || []);
|
|
@@ -670,6 +735,7 @@ const METADATA_WORKSPACE = 'moost';
|
|
|
670
735
|
const moostMate = new Mate(METADATA_WORKSPACE, {
|
|
671
736
|
readType: true,
|
|
672
737
|
readReturnType: true,
|
|
738
|
+
collectPropKeys: true,
|
|
673
739
|
});
|
|
674
740
|
function getMoostMate() {
|
|
675
741
|
return moostMate;
|
|
@@ -688,9 +754,23 @@ var TPipePriority;
|
|
|
688
754
|
TPipePriority[TPipePriority["AFTER_VALIDATE"] = 8] = "AFTER_VALIDATE";
|
|
689
755
|
})(TPipePriority || (TPipePriority = {}));
|
|
690
756
|
|
|
691
|
-
const resolvePipe = (_value,
|
|
692
|
-
|
|
693
|
-
|
|
757
|
+
const resolvePipe = (_value, metas, level) => {
|
|
758
|
+
var _a, _b, _c, _d;
|
|
759
|
+
let resolver;
|
|
760
|
+
if (level === 'PARAM') {
|
|
761
|
+
resolver = (_a = metas.paramMeta) === null || _a === void 0 ? void 0 : _a.resolver;
|
|
762
|
+
}
|
|
763
|
+
else if (level === 'PROP') {
|
|
764
|
+
resolver = (_b = metas.propMeta) === null || _b === void 0 ? void 0 : _b.resolver;
|
|
765
|
+
}
|
|
766
|
+
else if (level === 'METHOD') {
|
|
767
|
+
resolver = (_c = metas.methodMeta) === null || _c === void 0 ? void 0 : _c.resolver;
|
|
768
|
+
}
|
|
769
|
+
else if (level === 'CLASS') {
|
|
770
|
+
resolver = (_d = metas.classMeta) === null || _d === void 0 ? void 0 : _d.resolver;
|
|
771
|
+
}
|
|
772
|
+
if (resolver) {
|
|
773
|
+
return resolver(metas, level);
|
|
694
774
|
}
|
|
695
775
|
return undefined;
|
|
696
776
|
};
|
|
@@ -762,6 +842,7 @@ exports.All = All;
|
|
|
762
842
|
exports.Authorization = Authorization;
|
|
763
843
|
exports.Body = Body;
|
|
764
844
|
exports.Cookie = Cookie;
|
|
845
|
+
exports.CookieAttrsHook = CookieAttrsHook;
|
|
765
846
|
exports.CookieHook = CookieHook;
|
|
766
847
|
exports.Delete = Delete;
|
|
767
848
|
exports.Get = Get;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { IncomingMessage } from 'http';
|
|
4
4
|
import { ServerResponse } from 'http';
|
|
5
|
+
import { TCookieAttributesInput } from '@wooksjs/event-http';
|
|
5
6
|
import { TInterceptorFn } from '@moostjs/moost';
|
|
6
7
|
import { TMoostAdapter } from 'moost';
|
|
7
8
|
import { TMoostAdapterOptions } from 'moost';
|
|
@@ -19,14 +20,14 @@ export declare const All: (path?: string) => MethodDecorator;
|
|
|
19
20
|
* @param name - define what to take from the Auth header
|
|
20
21
|
* @paramType string
|
|
21
22
|
*/
|
|
22
|
-
export declare function Authorization(name: 'username' | 'password' | 'bearer' | 'raw' | 'type'): ParameterDecorator;
|
|
23
|
+
export declare function Authorization(name: 'username' | 'password' | 'bearer' | 'raw' | 'type'): ParameterDecorator & PropertyDecorator;
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* Get Parsed Request Body
|
|
26
27
|
* @decorator
|
|
27
28
|
* @paramType object | string | unknown
|
|
28
29
|
*/
|
|
29
|
-
declare function Body_2(): ParameterDecorator;
|
|
30
|
+
declare function Body_2(): ParameterDecorator & PropertyDecorator;
|
|
30
31
|
export { Body_2 as Body }
|
|
31
32
|
|
|
32
33
|
/**
|
|
@@ -35,15 +36,23 @@ export { Body_2 as Body }
|
|
|
35
36
|
* @param name - cookie name
|
|
36
37
|
* @paramType string
|
|
37
38
|
*/
|
|
38
|
-
export declare function Cookie(name: string): ParameterDecorator;
|
|
39
|
+
export declare function Cookie(name: string): ParameterDecorator & PropertyDecorator;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Hook to the Response Cookie Attributes
|
|
43
|
+
* @decorator
|
|
44
|
+
* @param name - cookie name
|
|
45
|
+
* @paramType TCookieHook
|
|
46
|
+
*/
|
|
47
|
+
export declare const CookieAttrsHook: (name: string) => ParameterDecorator & PropertyDecorator;
|
|
39
48
|
|
|
40
49
|
/**
|
|
41
50
|
* Hook to the Response Cookie
|
|
42
51
|
* @decorator
|
|
43
|
-
* @param name -
|
|
52
|
+
* @param name - cookie name
|
|
44
53
|
* @paramType TCookieHook
|
|
45
54
|
*/
|
|
46
|
-
export declare const CookieHook: (name: string) => ParameterDecorator;
|
|
55
|
+
export declare const CookieHook: (name: string) => ParameterDecorator & PropertyDecorator;
|
|
47
56
|
|
|
48
57
|
export declare const Delete: (path?: string) => MethodDecorator;
|
|
49
58
|
|
|
@@ -55,7 +64,7 @@ export declare const Get: (path?: string) => MethodDecorator;
|
|
|
55
64
|
* @param name - header name
|
|
56
65
|
* @paramType string
|
|
57
66
|
*/
|
|
58
|
-
export declare function Header(name: string): ParameterDecorator;
|
|
67
|
+
export declare function Header(name: string): ParameterDecorator & PropertyDecorator;
|
|
59
68
|
|
|
60
69
|
/**
|
|
61
70
|
* Hook to the Response Header
|
|
@@ -63,7 +72,7 @@ export declare function Header(name: string): ParameterDecorator;
|
|
|
63
72
|
* @param name - header name
|
|
64
73
|
* @paramType THeaderHook
|
|
65
74
|
*/
|
|
66
|
-
export declare const HeaderHook: (name: string) => ParameterDecorator;
|
|
75
|
+
export declare const HeaderHook: (name: string) => ParameterDecorator & PropertyDecorator;
|
|
67
76
|
|
|
68
77
|
export declare function HttpMethod(method: '*' | 'GET' | 'PUT' | 'POST' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS', path?: string): MethodDecorator;
|
|
69
78
|
|
|
@@ -74,21 +83,21 @@ export declare function HttpMethod(method: '*' | 'GET' | 'PUT' | 'POST' | 'PATCH
|
|
|
74
83
|
*/
|
|
75
84
|
export declare function Ip(opts?: {
|
|
76
85
|
trustProxy: boolean;
|
|
77
|
-
}): ParameterDecorator;
|
|
86
|
+
}): ParameterDecorator & PropertyDecorator;
|
|
78
87
|
|
|
79
88
|
/**
|
|
80
89
|
* Get Request IP Address list
|
|
81
90
|
* @decorator
|
|
82
91
|
* @paramType string[]
|
|
83
92
|
*/
|
|
84
|
-
export declare function IpList(): ParameterDecorator;
|
|
93
|
+
export declare function IpList(): ParameterDecorator & PropertyDecorator;
|
|
85
94
|
|
|
86
95
|
/**
|
|
87
96
|
* Get Requested HTTP Method
|
|
88
97
|
* @decorator
|
|
89
98
|
* @paramType string
|
|
90
99
|
*/
|
|
91
|
-
export declare function Method(): ParameterDecorator;
|
|
100
|
+
export declare function Method(): ParameterDecorator & PropertyDecorator;
|
|
92
101
|
|
|
93
102
|
export declare class MoostHttp implements TMoostAdapter<THttpHandlerMeta> {
|
|
94
103
|
protected httpApp: WooksHttp;
|
|
@@ -128,21 +137,21 @@ export declare function Query(name?: string): ParameterDecorator;
|
|
|
128
137
|
* @decorator
|
|
129
138
|
* @paramType Promise<Buffer>
|
|
130
139
|
*/
|
|
131
|
-
export declare function RawBody(): ParameterDecorator;
|
|
140
|
+
export declare function RawBody(): ParameterDecorator & PropertyDecorator;
|
|
132
141
|
|
|
133
142
|
/**
|
|
134
143
|
* Get Raw Request Instance
|
|
135
144
|
* @decorator
|
|
136
145
|
* @paramType IncomingMessage
|
|
137
146
|
*/
|
|
138
|
-
export declare function Req(): ParameterDecorator;
|
|
147
|
+
export declare function Req(): ParameterDecorator & PropertyDecorator;
|
|
139
148
|
|
|
140
149
|
/**
|
|
141
150
|
* Get Request Unique Identificator (UUID)
|
|
142
151
|
* @decorator
|
|
143
152
|
* @paramType string
|
|
144
153
|
*/
|
|
145
|
-
export declare function ReqId(): ParameterDecorator;
|
|
154
|
+
export declare function ReqId(): ParameterDecorator & PropertyDecorator;
|
|
146
155
|
|
|
147
156
|
/**
|
|
148
157
|
* Get Raw Response Object
|
|
@@ -152,7 +161,7 @@ export declare function ReqId(): ParameterDecorator;
|
|
|
152
161
|
*/
|
|
153
162
|
export declare function Res(options?: {
|
|
154
163
|
passthrough: boolean;
|
|
155
|
-
}): ParameterDecorator;
|
|
164
|
+
}): ParameterDecorator & PropertyDecorator;
|
|
156
165
|
|
|
157
166
|
export declare function SetCookie(...args: Parameters<typeof setCookieInterceptor>): ClassDecorator & MethodDecorator;
|
|
158
167
|
|
|
@@ -170,7 +179,9 @@ declare const setHeaderInterceptor: (name: string, value: string, opts?: {
|
|
|
170
179
|
* @decorator
|
|
171
180
|
* @paramType TStatusHook
|
|
172
181
|
*/
|
|
173
|
-
export declare const StatusHook: ParameterDecorator;
|
|
182
|
+
export declare const StatusHook: () => ParameterDecorator & PropertyDecorator;
|
|
183
|
+
|
|
184
|
+
export { TCookieAttributesInput }
|
|
174
185
|
|
|
175
186
|
export declare interface THttpHandlerMeta {
|
|
176
187
|
method: string;
|
|
@@ -182,6 +193,6 @@ export declare interface THttpHandlerMeta {
|
|
|
182
193
|
* @decorator
|
|
183
194
|
* @paramType string
|
|
184
195
|
*/
|
|
185
|
-
export declare function Url(): ParameterDecorator;
|
|
196
|
+
export declare function Url(): ParameterDecorator & PropertyDecorator;
|
|
186
197
|
|
|
187
198
|
export { }
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WooksHttp, createHttpApp, useHttpContext, useRequest, useHeaders, HttpError, EHttpStatusCode, WooksURLSearchParams, useStatus, useSetHeader, useSetCookie, useAuthorization, useCookies, useSearchParams, useResponse, useSetCookies } from '@wooksjs/event-http';
|
|
2
2
|
import { getMoostMate as getMoostMate$1, Resolve } from 'moost';
|
|
3
|
-
import '@wooksjs/event-core';
|
|
3
|
+
import { attachHook } from '@wooksjs/event-core';
|
|
4
4
|
|
|
5
5
|
/******************************************************************************
|
|
6
6
|
Copyright (c) Microsoft Corporation.
|
|
@@ -333,21 +333,83 @@ function useBody() {
|
|
|
333
333
|
* @decorator
|
|
334
334
|
* @paramType TStatusHook
|
|
335
335
|
*/
|
|
336
|
-
const StatusHook =
|
|
336
|
+
const StatusHook = () => Resolve((metas, level) => {
|
|
337
|
+
const hook = useStatus();
|
|
338
|
+
if (level === 'PARAM') {
|
|
339
|
+
return hook;
|
|
340
|
+
}
|
|
341
|
+
if (level === 'PROP' && metas.instance && metas.key) {
|
|
342
|
+
const initialValue = metas.instance[metas.key];
|
|
343
|
+
attachHook(metas.instance, {
|
|
344
|
+
get: () => hook.value,
|
|
345
|
+
set: (v) => hook.value = v,
|
|
346
|
+
}, metas.key);
|
|
347
|
+
return typeof initialValue === 'number' ? initialValue : 200;
|
|
348
|
+
}
|
|
349
|
+
}, 'statusCode');
|
|
337
350
|
/**
|
|
338
351
|
* Hook to the Response Header
|
|
339
352
|
* @decorator
|
|
340
353
|
* @param name - header name
|
|
341
354
|
* @paramType THeaderHook
|
|
342
355
|
*/
|
|
343
|
-
const HeaderHook = (name) => Resolve(() =>
|
|
356
|
+
const HeaderHook = (name) => Resolve((metas, level) => {
|
|
357
|
+
const hook = useSetHeader(name);
|
|
358
|
+
if (level === 'PARAM') {
|
|
359
|
+
return hook;
|
|
360
|
+
}
|
|
361
|
+
if (level === 'PROP' && metas.instance && metas.key) {
|
|
362
|
+
const initialValue = metas.instance[metas.key];
|
|
363
|
+
attachHook(metas.instance, {
|
|
364
|
+
get: () => hook.value,
|
|
365
|
+
set: (v) => hook.value = v,
|
|
366
|
+
}, metas.key);
|
|
367
|
+
return typeof initialValue === 'string' ? initialValue : '';
|
|
368
|
+
}
|
|
369
|
+
}, name);
|
|
344
370
|
/**
|
|
345
371
|
* Hook to the Response Cookie
|
|
346
372
|
* @decorator
|
|
347
|
-
* @param name -
|
|
373
|
+
* @param name - cookie name
|
|
348
374
|
* @paramType TCookieHook
|
|
349
375
|
*/
|
|
350
|
-
const CookieHook = (name) => Resolve(() =>
|
|
376
|
+
const CookieHook = (name) => Resolve((metas, level) => {
|
|
377
|
+
const hook = useSetCookie(name);
|
|
378
|
+
if (level === 'PARAM') {
|
|
379
|
+
return hook;
|
|
380
|
+
}
|
|
381
|
+
if (level === 'PROP' && metas.instance && metas.key) {
|
|
382
|
+
const initialValue = metas.instance[metas.key];
|
|
383
|
+
attachHook(metas.instance, {
|
|
384
|
+
get: () => hook.value,
|
|
385
|
+
set: (v) => hook.value = v,
|
|
386
|
+
}, metas.key);
|
|
387
|
+
return typeof initialValue === 'string' ? initialValue : '';
|
|
388
|
+
}
|
|
389
|
+
}, name);
|
|
390
|
+
/**
|
|
391
|
+
* Hook to the Response Cookie Attributes
|
|
392
|
+
* @decorator
|
|
393
|
+
* @param name - cookie name
|
|
394
|
+
* @paramType TCookieHook
|
|
395
|
+
*/
|
|
396
|
+
const CookieAttrsHook = (name) => Resolve((metas, level) => {
|
|
397
|
+
const hook = useSetCookie(name);
|
|
398
|
+
if (level === 'PARAM') {
|
|
399
|
+
return attachHook({}, {
|
|
400
|
+
get: () => hook.attrs,
|
|
401
|
+
set: (v) => hook.attrs = v,
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
if (level === 'PROP' && metas.instance && metas.key) {
|
|
405
|
+
const initialValue = metas.instance[metas.key];
|
|
406
|
+
attachHook(metas.instance, {
|
|
407
|
+
get: () => hook.attrs,
|
|
408
|
+
set: (v) => hook.attrs = v,
|
|
409
|
+
}, metas.key);
|
|
410
|
+
return typeof initialValue === 'object' ? initialValue : {};
|
|
411
|
+
}
|
|
412
|
+
}, name);
|
|
351
413
|
/**
|
|
352
414
|
* Parse Authorisation Header
|
|
353
415
|
* @decorator
|
|
@@ -495,15 +557,6 @@ function isConstructor(v) {
|
|
|
495
557
|
return typeof v === 'function' && Object.getOwnPropertyNames(v).includes('prototype') && !Object.getOwnPropertyNames(v).includes('caller') && !!v.name;
|
|
496
558
|
}
|
|
497
559
|
|
|
498
|
-
const banner = () => `[prostojs/mate][${new Date().toISOString().replace('T', ' ').replace(/\.\d{3}z$/i, '')}] `;
|
|
499
|
-
|
|
500
|
-
function warn(text) {
|
|
501
|
-
console.log('[33m' + banner() + text + '[0m');
|
|
502
|
-
}
|
|
503
|
-
function logError(error) {
|
|
504
|
-
console.error('[91m' + '[1m' + banner() + error + '[0m');
|
|
505
|
-
}
|
|
506
|
-
|
|
507
560
|
const classMetadata = {};
|
|
508
561
|
const paramMetadata = {};
|
|
509
562
|
const root = typeof global === 'object' ? global : typeof self === 'object' ? self : {};
|
|
@@ -540,19 +593,20 @@ else {
|
|
|
540
593
|
'metadata',
|
|
541
594
|
];
|
|
542
595
|
const target = root.Reflect;
|
|
543
|
-
let isOriginalReflectMetadata = true;
|
|
544
596
|
for (const func of funcs) {
|
|
545
597
|
if (typeof target[func] !== 'function') {
|
|
546
598
|
Object.defineProperty(target, func, { configurable: true, writable: true, value: _reflect[func] });
|
|
547
|
-
isOriginalReflectMetadata = false;
|
|
548
599
|
}
|
|
549
600
|
}
|
|
550
|
-
if (!isOriginalReflectMetadata) {
|
|
551
|
-
warn('A limited \'reflect-metadata\' implementation is used. In case of any issues include original \'reflect-metadata\' package and require it before any @prostojs/mate import.');
|
|
552
|
-
}
|
|
553
601
|
}
|
|
554
602
|
const Reflect$1 = _reflect;
|
|
555
603
|
|
|
604
|
+
const banner = () => `[prostojs/mate][${new Date().toISOString().replace('T', ' ').replace(/\.\d{3}z$/i, '')}] `;
|
|
605
|
+
|
|
606
|
+
function logError(error) {
|
|
607
|
+
console.error('[91m' + '[1m' + banner() + error + '[0m');
|
|
608
|
+
}
|
|
609
|
+
|
|
556
610
|
function panic(error) {
|
|
557
611
|
logError(error);
|
|
558
612
|
return new Error(error);
|
|
@@ -594,6 +648,17 @@ class Mate {
|
|
|
594
648
|
data = data.params[index];
|
|
595
649
|
}
|
|
596
650
|
}
|
|
651
|
+
else if (!index && !args.descriptor && args.propKey && this.options.collectPropKeys && args.level !== 'CLASS') {
|
|
652
|
+
this.set({ ...args, level: 'CLASS' }, (meta) => {
|
|
653
|
+
if (!meta.properties) {
|
|
654
|
+
meta.properties = [args.propKey];
|
|
655
|
+
}
|
|
656
|
+
else if (!meta.properties.includes(args.propKey)) {
|
|
657
|
+
meta.properties.push(args.propKey);
|
|
658
|
+
}
|
|
659
|
+
return meta;
|
|
660
|
+
});
|
|
661
|
+
}
|
|
597
662
|
if (typeof key !== 'function') {
|
|
598
663
|
if (isArray) {
|
|
599
664
|
const newArray = (data[key] || []);
|
|
@@ -668,6 +733,7 @@ const METADATA_WORKSPACE = 'moost';
|
|
|
668
733
|
const moostMate = new Mate(METADATA_WORKSPACE, {
|
|
669
734
|
readType: true,
|
|
670
735
|
readReturnType: true,
|
|
736
|
+
collectPropKeys: true,
|
|
671
737
|
});
|
|
672
738
|
function getMoostMate() {
|
|
673
739
|
return moostMate;
|
|
@@ -686,9 +752,23 @@ var TPipePriority;
|
|
|
686
752
|
TPipePriority[TPipePriority["AFTER_VALIDATE"] = 8] = "AFTER_VALIDATE";
|
|
687
753
|
})(TPipePriority || (TPipePriority = {}));
|
|
688
754
|
|
|
689
|
-
const resolvePipe = (_value,
|
|
690
|
-
|
|
691
|
-
|
|
755
|
+
const resolvePipe = (_value, metas, level) => {
|
|
756
|
+
var _a, _b, _c, _d;
|
|
757
|
+
let resolver;
|
|
758
|
+
if (level === 'PARAM') {
|
|
759
|
+
resolver = (_a = metas.paramMeta) === null || _a === void 0 ? void 0 : _a.resolver;
|
|
760
|
+
}
|
|
761
|
+
else if (level === 'PROP') {
|
|
762
|
+
resolver = (_b = metas.propMeta) === null || _b === void 0 ? void 0 : _b.resolver;
|
|
763
|
+
}
|
|
764
|
+
else if (level === 'METHOD') {
|
|
765
|
+
resolver = (_c = metas.methodMeta) === null || _c === void 0 ? void 0 : _c.resolver;
|
|
766
|
+
}
|
|
767
|
+
else if (level === 'CLASS') {
|
|
768
|
+
resolver = (_d = metas.classMeta) === null || _d === void 0 ? void 0 : _d.resolver;
|
|
769
|
+
}
|
|
770
|
+
if (resolver) {
|
|
771
|
+
return resolver(metas, level);
|
|
692
772
|
}
|
|
693
773
|
return undefined;
|
|
694
774
|
};
|
|
@@ -756,4 +836,4 @@ function SetCookie(...args) {
|
|
|
756
836
|
return Intercept(setCookieInterceptor(...args));
|
|
757
837
|
}
|
|
758
838
|
|
|
759
|
-
export { All, Authorization, Body, Cookie, CookieHook, Delete, Get, Header, HeaderHook, HttpMethod, Ip, IpList, Method, MoostHttp, Patch, Post, Put, Query, RawBody, Req, ReqId, Res, SetCookie, SetHeader, StatusHook, Url };
|
|
839
|
+
export { All, Authorization, Body, Cookie, CookieAttrsHook, CookieHook, Delete, Get, Header, HeaderHook, HttpMethod, Ip, IpList, Method, MoostHttp, Patch, Post, Put, Query, RawBody, Req, ReqId, Res, SetCookie, SetHeader, StatusHook, Url };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moostjs/event-http",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
4
4
|
"description": "@moostjs/event-http",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/moostjs/moostjs/tree/main/packages/event-http#readme",
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"moost": "0.2.
|
|
32
|
-
"wooks": "^0.2.
|
|
33
|
-
"@wooksjs/event-core": "^0.2.
|
|
31
|
+
"moost": "0.2.10",
|
|
32
|
+
"wooks": "^0.2.6",
|
|
33
|
+
"@wooksjs/event-core": "^0.2.6"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@wooksjs/event-http": "^0.2.
|
|
36
|
+
"@wooksjs/event-http": "^0.2.6"
|
|
37
37
|
}
|
|
38
38
|
}
|