@moostjs/event-http 0.2.14 → 0.2.16
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 +27 -317
- package/dist/index.d.ts +8 -1
- package/dist/index.mjs +26 -317
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
var eventHttp = require('@wooksjs/event-http');
|
|
4
4
|
var moost = require('moost');
|
|
5
|
+
var infact = require('@prostojs/infact');
|
|
6
|
+
var http = require('http');
|
|
7
|
+
var https = require('https');
|
|
5
8
|
var eventCore = require('@wooksjs/event-core');
|
|
6
9
|
|
|
7
10
|
/******************************************************************************
|
|
@@ -29,19 +32,6 @@ function __awaiter$1(thisArg, _arguments, P, generator) {
|
|
|
29
32
|
});
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
function createProvideRegistry(...args) {
|
|
33
|
-
const provide = {};
|
|
34
|
-
for (const a of args) {
|
|
35
|
-
const [type, fn] = a;
|
|
36
|
-
const key = typeof type === 'string' ? type : Symbol.for(type);
|
|
37
|
-
provide[key] = {
|
|
38
|
-
fn,
|
|
39
|
-
resolved: false,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
return provide;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
35
|
class MoostHttp {
|
|
46
36
|
constructor(httpApp) {
|
|
47
37
|
this.pathBuilders = {};
|
|
@@ -65,7 +55,7 @@ class MoostHttp {
|
|
|
65
55
|
return this.httpApp.listen(...args);
|
|
66
56
|
}
|
|
67
57
|
getProvideRegistry() {
|
|
68
|
-
return createProvideRegistry([eventHttp.WooksHttp, () => this.getHttpApp()], ['WooksHttp', () => this.getHttpApp()]);
|
|
58
|
+
return infact.createProvideRegistry([eventHttp.WooksHttp, () => this.getHttpApp()], ['WooksHttp', () => this.getHttpApp()], [http.Server, () => this.getHttpApp().getServer()], [https.Server, () => this.getHttpApp().getServer()]);
|
|
69
59
|
}
|
|
70
60
|
bindHandler(opts) {
|
|
71
61
|
let fn;
|
|
@@ -177,15 +167,15 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
177
167
|
});
|
|
178
168
|
}
|
|
179
169
|
|
|
180
|
-
const banner
|
|
170
|
+
const banner = () => `[${"@wooksjs/http-body"}][${new Date().toISOString().replace('T', ' ').replace(/\.\d{3}z$/i, '')}] `;
|
|
181
171
|
|
|
182
172
|
/* istanbul ignore file */
|
|
183
|
-
function logError
|
|
184
|
-
console.error('[91m' + '[1m' + banner
|
|
173
|
+
function logError(error) {
|
|
174
|
+
console.error('[91m' + '[1m' + banner() + error + '[0m');
|
|
185
175
|
}
|
|
186
176
|
|
|
187
|
-
function panic
|
|
188
|
-
logError
|
|
177
|
+
function panic(error) {
|
|
178
|
+
logError(error);
|
|
189
179
|
return new Error(error);
|
|
190
180
|
}
|
|
191
181
|
|
|
@@ -200,7 +190,7 @@ function uncompressBody(encodings, body) {
|
|
|
200
190
|
let newBody = body;
|
|
201
191
|
for (const e of encodings.reverse()) {
|
|
202
192
|
if (!compressors[e]) {
|
|
203
|
-
throw panic
|
|
193
|
+
throw panic(`Usupported compression type "${e}".`);
|
|
204
194
|
}
|
|
205
195
|
newBody = yield compressors[e].uncompress(body);
|
|
206
196
|
}
|
|
@@ -257,7 +247,7 @@ function useBody() {
|
|
|
257
247
|
return v;
|
|
258
248
|
}
|
|
259
249
|
function formDataParser(v) {
|
|
260
|
-
const boundary = '--' + (/boundary=([^;]+)(?:;|$)/.exec(contentType || '') || [, ''])[1];
|
|
250
|
+
const boundary = '--' + ((/boundary=([^;]+)(?:;|$)/.exec(contentType || '') || [, ''])[1]);
|
|
261
251
|
if (!boundary)
|
|
262
252
|
throw new eventHttp.HttpError(eventHttp.EHttpStatusCode.BadRequest, 'form-data boundary not recognized');
|
|
263
253
|
const parts = v.trim().split(boundary);
|
|
@@ -549,298 +539,6 @@ function RawBody() {
|
|
|
549
539
|
return moost.Resolve(() => useBody().rawBody(), 'body');
|
|
550
540
|
}
|
|
551
541
|
|
|
552
|
-
function getConstructor(instance) {
|
|
553
|
-
return isConstructor(instance) ?
|
|
554
|
-
instance : instance.constructor ?
|
|
555
|
-
instance.constructor : Object.getPrototypeOf(instance).constructor;
|
|
556
|
-
}
|
|
557
|
-
function isConstructor(v) {
|
|
558
|
-
return typeof v === 'function' && Object.getOwnPropertyNames(v).includes('prototype') && !Object.getOwnPropertyNames(v).includes('caller') && !!v.name;
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
const classMetadata = {};
|
|
562
|
-
const paramMetadata = {};
|
|
563
|
-
const root = typeof global === 'object' ? global : typeof self === 'object' ? self : {};
|
|
564
|
-
function getMetaObject(target, prop) {
|
|
565
|
-
const isParam = typeof prop !== 'undefined';
|
|
566
|
-
const metadata = isParam ? paramMetadata : classMetadata;
|
|
567
|
-
const targetKey = Symbol.for(getConstructor(target));
|
|
568
|
-
let meta = metadata[targetKey] = metadata[targetKey] || {};
|
|
569
|
-
if (isParam)
|
|
570
|
-
meta = (meta[prop] = meta[prop] || {});
|
|
571
|
-
return meta;
|
|
572
|
-
}
|
|
573
|
-
const _reflect = {
|
|
574
|
-
getOwnMetadata(key, target, prop) {
|
|
575
|
-
return getMetaObject(target, prop)[key];
|
|
576
|
-
},
|
|
577
|
-
defineMetadata(key, data, target, prop) {
|
|
578
|
-
const meta = getMetaObject(target, prop);
|
|
579
|
-
meta[key] = data;
|
|
580
|
-
},
|
|
581
|
-
metadata(key, data) {
|
|
582
|
-
return ((target, propKey) => {
|
|
583
|
-
Reflect$1.defineMetadata(key, data, target, propKey);
|
|
584
|
-
});
|
|
585
|
-
},
|
|
586
|
-
};
|
|
587
|
-
if (!root.Reflect) {
|
|
588
|
-
root.Reflect = _reflect;
|
|
589
|
-
}
|
|
590
|
-
else {
|
|
591
|
-
const funcs = [
|
|
592
|
-
'getOwnMetadata',
|
|
593
|
-
'defineMetadata',
|
|
594
|
-
'metadata',
|
|
595
|
-
];
|
|
596
|
-
const target = root.Reflect;
|
|
597
|
-
for (const func of funcs) {
|
|
598
|
-
if (typeof target[func] !== 'function') {
|
|
599
|
-
Object.defineProperty(target, func, { configurable: true, writable: true, value: _reflect[func] });
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
const Reflect$1 = _reflect;
|
|
604
|
-
|
|
605
|
-
const banner = () => `[prostojs/mate][${new Date().toISOString().replace('T', ' ').replace(/\.\d{3}z$/i, '')}] `;
|
|
606
|
-
|
|
607
|
-
function logError(error) {
|
|
608
|
-
console.error('[91m' + '[1m' + banner() + error + '[0m');
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
function panic(error) {
|
|
612
|
-
logError(error);
|
|
613
|
-
return new Error(error);
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
const Reflect = (global === null || global === void 0 ? void 0 : global.Reflect) || (self === null || self === void 0 ? void 0 : self.Reflect) || Reflect$1;
|
|
617
|
-
class Mate {
|
|
618
|
-
constructor(workspace, options = {}) {
|
|
619
|
-
this.workspace = workspace;
|
|
620
|
-
this.options = options;
|
|
621
|
-
}
|
|
622
|
-
set(args, key, value, isArray) {
|
|
623
|
-
var _a;
|
|
624
|
-
let level = 'CLASS';
|
|
625
|
-
const newArgs = args.level === 'CLASS' ? { target: args.target }
|
|
626
|
-
: args.level === 'PROP' ? { target: args.target, propKey: args.propKey }
|
|
627
|
-
: args;
|
|
628
|
-
let meta = Reflect.getOwnMetadata(this.workspace, newArgs.target, newArgs.propKey) || {};
|
|
629
|
-
if (newArgs.propKey && this.options.readReturnType && !meta.returnType && args.descriptor) {
|
|
630
|
-
meta.returnType = Reflect.getOwnMetadata('design:returntype', newArgs.target, newArgs.propKey);
|
|
631
|
-
}
|
|
632
|
-
if (newArgs.propKey && this.options.readType && !meta.type) {
|
|
633
|
-
meta.type = Reflect.getOwnMetadata('design:type', newArgs.target, newArgs.propKey);
|
|
634
|
-
}
|
|
635
|
-
const { index } = newArgs;
|
|
636
|
-
const cb = typeof key === 'function' ? key : undefined;
|
|
637
|
-
let data = meta;
|
|
638
|
-
if (!data.params) {
|
|
639
|
-
data.params = (_a = Reflect.getOwnMetadata('design:paramtypes', newArgs.target, newArgs.propKey)) === null || _a === void 0 ? void 0 : _a.map((f) => ({ type: f }));
|
|
640
|
-
}
|
|
641
|
-
if (typeof index === 'number') {
|
|
642
|
-
level = 'PARAM';
|
|
643
|
-
data.params = data.params || [];
|
|
644
|
-
data.params[index] = data.params[index] || {
|
|
645
|
-
type: undefined,
|
|
646
|
-
};
|
|
647
|
-
if (cb) {
|
|
648
|
-
data.params[index] = cb(data.params[index], level, args.propKey, typeof args.index === 'number' ? args.index : undefined);
|
|
649
|
-
}
|
|
650
|
-
else {
|
|
651
|
-
data = data.params[index];
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
else if (!index && !args.descriptor && args.propKey && this.options.collectPropKeys && args.level !== 'CLASS') {
|
|
655
|
-
this.set({ ...args, level: 'CLASS' }, (meta) => {
|
|
656
|
-
if (!meta.properties) {
|
|
657
|
-
meta.properties = [args.propKey];
|
|
658
|
-
}
|
|
659
|
-
else if (!meta.properties.includes(args.propKey)) {
|
|
660
|
-
meta.properties.push(args.propKey);
|
|
661
|
-
}
|
|
662
|
-
return meta;
|
|
663
|
-
});
|
|
664
|
-
}
|
|
665
|
-
level = typeof index === 'number' ? 'PARAM' : newArgs.propKey && newArgs.descriptor ? 'METHOD' : newArgs.propKey ? 'PROP' : 'CLASS';
|
|
666
|
-
if (typeof key !== 'function') {
|
|
667
|
-
if (isArray) {
|
|
668
|
-
const newArray = (data[key] || []);
|
|
669
|
-
if (!Array.isArray(newArray)) {
|
|
670
|
-
panic('Mate.add (isArray=true) called for non-array metadata');
|
|
671
|
-
}
|
|
672
|
-
newArray.unshift(value);
|
|
673
|
-
data[key] = newArray;
|
|
674
|
-
}
|
|
675
|
-
else {
|
|
676
|
-
data[key] = value;
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
else if (cb && typeof index !== 'number') {
|
|
680
|
-
meta = cb(data, level, args.propKey, typeof args.index === 'number' ? args.index : undefined);
|
|
681
|
-
}
|
|
682
|
-
Reflect.defineMetadata(this.workspace, meta, newArgs.target, newArgs.propKey);
|
|
683
|
-
}
|
|
684
|
-
read(target, propKey) {
|
|
685
|
-
const isConstr = isConstructor(target);
|
|
686
|
-
const constructor = isConstr ? target : getConstructor(target);
|
|
687
|
-
const proto = constructor.prototype;
|
|
688
|
-
let ownMeta = Reflect.getOwnMetadata(this.workspace, typeof propKey === 'string' ? proto : constructor, propKey);
|
|
689
|
-
if (this.options.inherit) {
|
|
690
|
-
const inheritFn = typeof this.options.inherit === 'function' ? this.options.inherit : undefined;
|
|
691
|
-
let shouldInherit = this.options.inherit;
|
|
692
|
-
if (inheritFn) {
|
|
693
|
-
if (typeof propKey === 'string') {
|
|
694
|
-
const classMeta = Reflect.getOwnMetadata(this.workspace, constructor);
|
|
695
|
-
shouldInherit = inheritFn(classMeta, ownMeta, 'PROP', propKey);
|
|
696
|
-
}
|
|
697
|
-
else {
|
|
698
|
-
shouldInherit = inheritFn(ownMeta, ownMeta, 'CLASS');
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
if (shouldInherit) {
|
|
702
|
-
const parent = Object.getPrototypeOf(constructor);
|
|
703
|
-
if (typeof parent === 'function' && parent !== fnProto && parent !== constructor) {
|
|
704
|
-
const inheritedMeta = this.read(parent, propKey) || {};
|
|
705
|
-
const ownParams = ownMeta === null || ownMeta === void 0 ? void 0 : ownMeta.params;
|
|
706
|
-
ownMeta = { ...inheritedMeta, ...ownMeta };
|
|
707
|
-
if (typeof propKey === 'string' && ownParams && (inheritedMeta === null || inheritedMeta === void 0 ? void 0 : inheritedMeta.params)) {
|
|
708
|
-
for (let i = 0; i < ownParams.length; i++) {
|
|
709
|
-
if (typeof (inheritedMeta === null || inheritedMeta === void 0 ? void 0 : inheritedMeta.params[i]) !== 'undefined') {
|
|
710
|
-
const ownParam = ownParams[i];
|
|
711
|
-
if (ownMeta.params && inheritFn && inheritFn(ownMeta, ownParam, 'PARAM', typeof propKey === 'string' ? propKey : undefined)) {
|
|
712
|
-
ownMeta.params[i] = {
|
|
713
|
-
...inheritedMeta === null || inheritedMeta === void 0 ? void 0 : inheritedMeta.params[i],
|
|
714
|
-
...ownParams[i],
|
|
715
|
-
};
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
return ownMeta;
|
|
724
|
-
}
|
|
725
|
-
apply(...decorators) {
|
|
726
|
-
return ((target, propKey, descriptor) => {
|
|
727
|
-
for (const d of decorators) {
|
|
728
|
-
d(target, propKey, descriptor);
|
|
729
|
-
}
|
|
730
|
-
});
|
|
731
|
-
}
|
|
732
|
-
decorate(key, value, isArray, level) {
|
|
733
|
-
return ((target, propKey, descriptor) => {
|
|
734
|
-
const args = {
|
|
735
|
-
target,
|
|
736
|
-
propKey,
|
|
737
|
-
descriptor: typeof descriptor === 'number' ? undefined : descriptor,
|
|
738
|
-
index: typeof descriptor === 'number' ? descriptor : undefined,
|
|
739
|
-
level,
|
|
740
|
-
};
|
|
741
|
-
this.set(args, key, value, isArray);
|
|
742
|
-
});
|
|
743
|
-
}
|
|
744
|
-
decorateConditional(ccb) {
|
|
745
|
-
return ((target, propKey, descriptor) => {
|
|
746
|
-
const hasIndex = typeof descriptor === 'number';
|
|
747
|
-
const decoratorLevel = hasIndex ? 'PARAM' : propKey && descriptor ? 'METHOD' : propKey ? 'PROP' : 'CLASS';
|
|
748
|
-
const d = ccb(decoratorLevel);
|
|
749
|
-
if (d) {
|
|
750
|
-
d(target, propKey, descriptor);
|
|
751
|
-
}
|
|
752
|
-
});
|
|
753
|
-
}
|
|
754
|
-
decorateClass(key, value, isArray) {
|
|
755
|
-
return this.decorate(key, value, isArray, 'CLASS');
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
const fnProto = Object.getPrototypeOf(Function);
|
|
759
|
-
|
|
760
|
-
const METADATA_WORKSPACE = 'moost';
|
|
761
|
-
const moostMate = new Mate(METADATA_WORKSPACE, {
|
|
762
|
-
readType: true,
|
|
763
|
-
readReturnType: true,
|
|
764
|
-
collectPropKeys: true,
|
|
765
|
-
inherit(classMeta, targetMeta, level) {
|
|
766
|
-
if (level === 'CLASS') {
|
|
767
|
-
return !!(classMeta === null || classMeta === void 0 ? void 0 : classMeta.inherit);
|
|
768
|
-
}
|
|
769
|
-
if (level === 'PROP') {
|
|
770
|
-
return !!(targetMeta === null || targetMeta === void 0 ? void 0 : targetMeta.inherit) || !!((classMeta === null || classMeta === void 0 ? void 0 : classMeta.inherit) && !targetMeta);
|
|
771
|
-
}
|
|
772
|
-
return !!(targetMeta === null || targetMeta === void 0 ? void 0 : targetMeta.inherit);
|
|
773
|
-
},
|
|
774
|
-
});
|
|
775
|
-
function getMoostMate() {
|
|
776
|
-
return moostMate;
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
getMoostMate().decorate((meta) => {
|
|
780
|
-
if (!meta.injectable)
|
|
781
|
-
meta.injectable = true;
|
|
782
|
-
return meta;
|
|
783
|
-
});
|
|
784
|
-
|
|
785
|
-
var TInterceptorPriority;
|
|
786
|
-
(function (TInterceptorPriority) {
|
|
787
|
-
TInterceptorPriority[TInterceptorPriority["BEFORE_ALL"] = 0] = "BEFORE_ALL";
|
|
788
|
-
TInterceptorPriority[TInterceptorPriority["BEFORE_GUARD"] = 1] = "BEFORE_GUARD";
|
|
789
|
-
TInterceptorPriority[TInterceptorPriority["GUARD"] = 2] = "GUARD";
|
|
790
|
-
TInterceptorPriority[TInterceptorPriority["AFTER_GUARD"] = 3] = "AFTER_GUARD";
|
|
791
|
-
TInterceptorPriority[TInterceptorPriority["INTERCEPTOR"] = 4] = "INTERCEPTOR";
|
|
792
|
-
TInterceptorPriority[TInterceptorPriority["CATCH_ERROR"] = 5] = "CATCH_ERROR";
|
|
793
|
-
TInterceptorPriority[TInterceptorPriority["AFTER_ALL"] = 6] = "AFTER_ALL";
|
|
794
|
-
})(TInterceptorPriority || (TInterceptorPriority = {}));
|
|
795
|
-
function Intercept(handler, priority) {
|
|
796
|
-
return getMoostMate().decorate('interceptors', {
|
|
797
|
-
handler,
|
|
798
|
-
priority: priority || handler.priority || TInterceptorPriority.INTERCEPTOR,
|
|
799
|
-
}, true);
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
var TPipePriority;
|
|
803
|
-
(function (TPipePriority) {
|
|
804
|
-
TPipePriority[TPipePriority["BEFORE_RESOLVE"] = 0] = "BEFORE_RESOLVE";
|
|
805
|
-
TPipePriority[TPipePriority["RESOLVE"] = 1] = "RESOLVE";
|
|
806
|
-
TPipePriority[TPipePriority["AFTER_RESOLVE"] = 2] = "AFTER_RESOLVE";
|
|
807
|
-
TPipePriority[TPipePriority["BEFORE_TRANSFORM"] = 3] = "BEFORE_TRANSFORM";
|
|
808
|
-
TPipePriority[TPipePriority["TRANSFORM"] = 4] = "TRANSFORM";
|
|
809
|
-
TPipePriority[TPipePriority["AFTER_TRANSFORM"] = 5] = "AFTER_TRANSFORM";
|
|
810
|
-
TPipePriority[TPipePriority["BEFORE_VALIDATE"] = 6] = "BEFORE_VALIDATE";
|
|
811
|
-
TPipePriority[TPipePriority["VALIDATE"] = 7] = "VALIDATE";
|
|
812
|
-
TPipePriority[TPipePriority["AFTER_VALIDATE"] = 8] = "AFTER_VALIDATE";
|
|
813
|
-
})(TPipePriority || (TPipePriority = {}));
|
|
814
|
-
|
|
815
|
-
const resolvePipe = (_value, metas, level) => {
|
|
816
|
-
var _a, _b, _c, _d;
|
|
817
|
-
let resolver;
|
|
818
|
-
if (level === 'PARAM') {
|
|
819
|
-
resolver = (_a = metas.paramMeta) === null || _a === void 0 ? void 0 : _a.resolver;
|
|
820
|
-
}
|
|
821
|
-
else if (level === 'PROP') {
|
|
822
|
-
resolver = (_b = metas.propMeta) === null || _b === void 0 ? void 0 : _b.resolver;
|
|
823
|
-
}
|
|
824
|
-
else if (level === 'METHOD') {
|
|
825
|
-
resolver = (_c = metas.methodMeta) === null || _c === void 0 ? void 0 : _c.resolver;
|
|
826
|
-
}
|
|
827
|
-
else if (level === 'CLASS') {
|
|
828
|
-
resolver = (_d = metas.classMeta) === null || _d === void 0 ? void 0 : _d.resolver;
|
|
829
|
-
}
|
|
830
|
-
if (resolver) {
|
|
831
|
-
return resolver(metas, level);
|
|
832
|
-
}
|
|
833
|
-
return undefined;
|
|
834
|
-
};
|
|
835
|
-
resolvePipe.priority = TPipePriority.RESOLVE;
|
|
836
|
-
|
|
837
|
-
[
|
|
838
|
-
{
|
|
839
|
-
handler: resolvePipe,
|
|
840
|
-
priority: TPipePriority.RESOLVE,
|
|
841
|
-
},
|
|
842
|
-
];
|
|
843
|
-
|
|
844
542
|
const setHeaderInterceptor = (name, value, opts) => {
|
|
845
543
|
const fn = (before, after) => {
|
|
846
544
|
const h = eventHttp.useSetHeader(name);
|
|
@@ -851,11 +549,11 @@ const setHeaderInterceptor = (name, value, opts) => {
|
|
|
851
549
|
}
|
|
852
550
|
});
|
|
853
551
|
};
|
|
854
|
-
fn.priority = TInterceptorPriority.AFTER_ALL;
|
|
552
|
+
fn.priority = moost.TInterceptorPriority.AFTER_ALL;
|
|
855
553
|
return fn;
|
|
856
554
|
};
|
|
857
555
|
function SetHeader(...args) {
|
|
858
|
-
return Intercept(setHeaderInterceptor(...args));
|
|
556
|
+
return moost.Intercept(setHeaderInterceptor(...args));
|
|
859
557
|
}
|
|
860
558
|
const setCookieInterceptor = (name, value, attrs) => {
|
|
861
559
|
const fn = (before, after) => {
|
|
@@ -866,11 +564,22 @@ const setCookieInterceptor = (name, value, attrs) => {
|
|
|
866
564
|
}
|
|
867
565
|
});
|
|
868
566
|
};
|
|
869
|
-
fn.priority = TInterceptorPriority.AFTER_ALL;
|
|
567
|
+
fn.priority = moost.TInterceptorPriority.AFTER_ALL;
|
|
870
568
|
return fn;
|
|
871
569
|
};
|
|
872
570
|
function SetCookie(...args) {
|
|
873
|
-
return Intercept(setCookieInterceptor(...args));
|
|
571
|
+
return moost.Intercept(setCookieInterceptor(...args));
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
function httpValidatePipe(opts) {
|
|
575
|
+
return moost.validatePipe(Object.assign({ errorCb: (message, details) => {
|
|
576
|
+
throw new eventHttp.HttpError(400, {
|
|
577
|
+
statusCode: 400,
|
|
578
|
+
message,
|
|
579
|
+
error: 'Validation Error',
|
|
580
|
+
details,
|
|
581
|
+
});
|
|
582
|
+
} }, opts[0]));
|
|
874
583
|
}
|
|
875
584
|
|
|
876
585
|
exports.All = All;
|
|
@@ -900,3 +609,4 @@ exports.SetCookie = SetCookie;
|
|
|
900
609
|
exports.SetHeader = SetHeader;
|
|
901
610
|
exports.StatusHook = StatusHook;
|
|
902
611
|
exports.Url = Url;
|
|
612
|
+
exports.httpValidatePipe = httpValidatePipe;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,13 +3,15 @@
|
|
|
3
3
|
import { IncomingMessage } from 'http';
|
|
4
4
|
import { ServerResponse } from 'http';
|
|
5
5
|
import { TCookieAttributesInput } from '@wooksjs/event-http';
|
|
6
|
-
import { TInterceptorFn } from '
|
|
6
|
+
import { TInterceptorFn } from 'moost';
|
|
7
7
|
import { TMoostAdapter } from 'moost';
|
|
8
8
|
import { TMoostAdapterOptions } from 'moost';
|
|
9
|
+
import { TPipeFn } from 'moost';
|
|
9
10
|
import { TProstoRouterPathBuilder } from '@prostojs/router';
|
|
10
11
|
import { TProvideRegistry } from '@prostojs/infact';
|
|
11
12
|
import { TWooksHttpOptions } from '@wooksjs/event-http';
|
|
12
13
|
import { useSetCookies } from '@wooksjs/event-http';
|
|
14
|
+
import { validatePipe } from 'moost';
|
|
13
15
|
import { WooksHttp } from '@wooksjs/event-http';
|
|
14
16
|
|
|
15
17
|
export declare const All: (path?: string) => MethodDecorator;
|
|
@@ -76,6 +78,8 @@ export declare const HeaderHook: (name: string) => ParameterDecorator & Property
|
|
|
76
78
|
|
|
77
79
|
export declare function HttpMethod(method: '*' | 'GET' | 'PUT' | 'POST' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS', path?: string): MethodDecorator;
|
|
78
80
|
|
|
81
|
+
export declare function httpValidatePipe(opts: Parameters<typeof validatePipe>): TPipeFn<TEmpty>;
|
|
82
|
+
|
|
79
83
|
/**
|
|
80
84
|
* Get Request IP Address
|
|
81
85
|
* @decorator
|
|
@@ -183,6 +187,9 @@ export declare const StatusHook: () => ParameterDecorator & PropertyDecorator;
|
|
|
183
187
|
|
|
184
188
|
export { TCookieAttributesInput }
|
|
185
189
|
|
|
190
|
+
declare interface TEmpty {
|
|
191
|
+
}
|
|
192
|
+
|
|
186
193
|
export declare interface THttpHandlerMeta {
|
|
187
194
|
method: string;
|
|
188
195
|
path: string;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { WooksHttp, createHttpApp, useHttpContext, useRequest, useHeaders, HttpError, EHttpStatusCode, WooksURLSearchParams, useStatus, useSetHeader, useSetCookie, useAuthorization, useCookies, useSearchParams, useResponse, useSetCookies } from '@wooksjs/event-http';
|
|
2
|
-
import { getMoostMate
|
|
2
|
+
import { getMoostMate, Resolve, Intercept, TInterceptorPriority, validatePipe } from 'moost';
|
|
3
|
+
import { createProvideRegistry } from '@prostojs/infact';
|
|
4
|
+
import { Server } from 'http';
|
|
5
|
+
import { Server as Server$1 } from 'https';
|
|
3
6
|
import { attachHook } from '@wooksjs/event-core';
|
|
4
7
|
|
|
5
8
|
/******************************************************************************
|
|
@@ -27,19 +30,6 @@ function __awaiter$1(thisArg, _arguments, P, generator) {
|
|
|
27
30
|
});
|
|
28
31
|
}
|
|
29
32
|
|
|
30
|
-
function createProvideRegistry(...args) {
|
|
31
|
-
const provide = {};
|
|
32
|
-
for (const a of args) {
|
|
33
|
-
const [type, fn] = a;
|
|
34
|
-
const key = typeof type === 'string' ? type : Symbol.for(type);
|
|
35
|
-
provide[key] = {
|
|
36
|
-
fn,
|
|
37
|
-
resolved: false,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
return provide;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
33
|
class MoostHttp {
|
|
44
34
|
constructor(httpApp) {
|
|
45
35
|
this.pathBuilders = {};
|
|
@@ -63,7 +53,7 @@ class MoostHttp {
|
|
|
63
53
|
return this.httpApp.listen(...args);
|
|
64
54
|
}
|
|
65
55
|
getProvideRegistry() {
|
|
66
|
-
return createProvideRegistry([WooksHttp, () => this.getHttpApp()], ['WooksHttp', () => this.getHttpApp()]);
|
|
56
|
+
return createProvideRegistry([WooksHttp, () => this.getHttpApp()], ['WooksHttp', () => this.getHttpApp()], [Server, () => this.getHttpApp().getServer()], [Server$1, () => this.getHttpApp().getServer()]);
|
|
67
57
|
}
|
|
68
58
|
bindHandler(opts) {
|
|
69
59
|
let fn;
|
|
@@ -120,7 +110,7 @@ class MoostHttp {
|
|
|
120
110
|
});
|
|
121
111
|
}
|
|
122
112
|
const pathBuilder = this.httpApp.on(handler.method, targetPath, fn);
|
|
123
|
-
const methodMeta = getMoostMate
|
|
113
|
+
const methodMeta = getMoostMate().read(opts.fakeInstance, opts.method) || {};
|
|
124
114
|
const id = (methodMeta.id || opts.method);
|
|
125
115
|
if (id) {
|
|
126
116
|
const methods = this.pathBuilders[id] = this.pathBuilders[id] || {};
|
|
@@ -141,7 +131,7 @@ class MoostHttp {
|
|
|
141
131
|
}
|
|
142
132
|
|
|
143
133
|
function HttpMethod(method, path) {
|
|
144
|
-
return getMoostMate
|
|
134
|
+
return getMoostMate().decorate('handlers', { method, path, type: 'HTTP' }, true);
|
|
145
135
|
}
|
|
146
136
|
const All = (path) => HttpMethod('*', path);
|
|
147
137
|
const Get = (path) => HttpMethod('GET', path);
|
|
@@ -175,15 +165,15 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
175
165
|
});
|
|
176
166
|
}
|
|
177
167
|
|
|
178
|
-
const banner
|
|
168
|
+
const banner = () => `[${"@wooksjs/http-body"}][${new Date().toISOString().replace('T', ' ').replace(/\.\d{3}z$/i, '')}] `;
|
|
179
169
|
|
|
180
170
|
/* istanbul ignore file */
|
|
181
|
-
function logError
|
|
182
|
-
console.error('[91m' + '[1m' + banner
|
|
171
|
+
function logError(error) {
|
|
172
|
+
console.error('[91m' + '[1m' + banner() + error + '[0m');
|
|
183
173
|
}
|
|
184
174
|
|
|
185
|
-
function panic
|
|
186
|
-
logError
|
|
175
|
+
function panic(error) {
|
|
176
|
+
logError(error);
|
|
187
177
|
return new Error(error);
|
|
188
178
|
}
|
|
189
179
|
|
|
@@ -198,7 +188,7 @@ function uncompressBody(encodings, body) {
|
|
|
198
188
|
let newBody = body;
|
|
199
189
|
for (const e of encodings.reverse()) {
|
|
200
190
|
if (!compressors[e]) {
|
|
201
|
-
throw panic
|
|
191
|
+
throw panic(`Usupported compression type "${e}".`);
|
|
202
192
|
}
|
|
203
193
|
newBody = yield compressors[e].uncompress(body);
|
|
204
194
|
}
|
|
@@ -255,7 +245,7 @@ function useBody() {
|
|
|
255
245
|
return v;
|
|
256
246
|
}
|
|
257
247
|
function formDataParser(v) {
|
|
258
|
-
const boundary = '--' + (/boundary=([^;]+)(?:;|$)/.exec(contentType || '') || [, ''])[1];
|
|
248
|
+
const boundary = '--' + ((/boundary=([^;]+)(?:;|$)/.exec(contentType || '') || [, ''])[1]);
|
|
259
249
|
if (!boundary)
|
|
260
250
|
throw new HttpError(EHttpStatusCode.BadRequest, 'form-data boundary not recognized');
|
|
261
251
|
const parts = v.trim().split(boundary);
|
|
@@ -547,298 +537,6 @@ function RawBody() {
|
|
|
547
537
|
return Resolve(() => useBody().rawBody(), 'body');
|
|
548
538
|
}
|
|
549
539
|
|
|
550
|
-
function getConstructor(instance) {
|
|
551
|
-
return isConstructor(instance) ?
|
|
552
|
-
instance : instance.constructor ?
|
|
553
|
-
instance.constructor : Object.getPrototypeOf(instance).constructor;
|
|
554
|
-
}
|
|
555
|
-
function isConstructor(v) {
|
|
556
|
-
return typeof v === 'function' && Object.getOwnPropertyNames(v).includes('prototype') && !Object.getOwnPropertyNames(v).includes('caller') && !!v.name;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
const classMetadata = {};
|
|
560
|
-
const paramMetadata = {};
|
|
561
|
-
const root = typeof global === 'object' ? global : typeof self === 'object' ? self : {};
|
|
562
|
-
function getMetaObject(target, prop) {
|
|
563
|
-
const isParam = typeof prop !== 'undefined';
|
|
564
|
-
const metadata = isParam ? paramMetadata : classMetadata;
|
|
565
|
-
const targetKey = Symbol.for(getConstructor(target));
|
|
566
|
-
let meta = metadata[targetKey] = metadata[targetKey] || {};
|
|
567
|
-
if (isParam)
|
|
568
|
-
meta = (meta[prop] = meta[prop] || {});
|
|
569
|
-
return meta;
|
|
570
|
-
}
|
|
571
|
-
const _reflect = {
|
|
572
|
-
getOwnMetadata(key, target, prop) {
|
|
573
|
-
return getMetaObject(target, prop)[key];
|
|
574
|
-
},
|
|
575
|
-
defineMetadata(key, data, target, prop) {
|
|
576
|
-
const meta = getMetaObject(target, prop);
|
|
577
|
-
meta[key] = data;
|
|
578
|
-
},
|
|
579
|
-
metadata(key, data) {
|
|
580
|
-
return ((target, propKey) => {
|
|
581
|
-
Reflect$1.defineMetadata(key, data, target, propKey);
|
|
582
|
-
});
|
|
583
|
-
},
|
|
584
|
-
};
|
|
585
|
-
if (!root.Reflect) {
|
|
586
|
-
root.Reflect = _reflect;
|
|
587
|
-
}
|
|
588
|
-
else {
|
|
589
|
-
const funcs = [
|
|
590
|
-
'getOwnMetadata',
|
|
591
|
-
'defineMetadata',
|
|
592
|
-
'metadata',
|
|
593
|
-
];
|
|
594
|
-
const target = root.Reflect;
|
|
595
|
-
for (const func of funcs) {
|
|
596
|
-
if (typeof target[func] !== 'function') {
|
|
597
|
-
Object.defineProperty(target, func, { configurable: true, writable: true, value: _reflect[func] });
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
const Reflect$1 = _reflect;
|
|
602
|
-
|
|
603
|
-
const banner = () => `[prostojs/mate][${new Date().toISOString().replace('T', ' ').replace(/\.\d{3}z$/i, '')}] `;
|
|
604
|
-
|
|
605
|
-
function logError(error) {
|
|
606
|
-
console.error('[91m' + '[1m' + banner() + error + '[0m');
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
function panic(error) {
|
|
610
|
-
logError(error);
|
|
611
|
-
return new Error(error);
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
const Reflect = (global === null || global === void 0 ? void 0 : global.Reflect) || (self === null || self === void 0 ? void 0 : self.Reflect) || Reflect$1;
|
|
615
|
-
class Mate {
|
|
616
|
-
constructor(workspace, options = {}) {
|
|
617
|
-
this.workspace = workspace;
|
|
618
|
-
this.options = options;
|
|
619
|
-
}
|
|
620
|
-
set(args, key, value, isArray) {
|
|
621
|
-
var _a;
|
|
622
|
-
let level = 'CLASS';
|
|
623
|
-
const newArgs = args.level === 'CLASS' ? { target: args.target }
|
|
624
|
-
: args.level === 'PROP' ? { target: args.target, propKey: args.propKey }
|
|
625
|
-
: args;
|
|
626
|
-
let meta = Reflect.getOwnMetadata(this.workspace, newArgs.target, newArgs.propKey) || {};
|
|
627
|
-
if (newArgs.propKey && this.options.readReturnType && !meta.returnType && args.descriptor) {
|
|
628
|
-
meta.returnType = Reflect.getOwnMetadata('design:returntype', newArgs.target, newArgs.propKey);
|
|
629
|
-
}
|
|
630
|
-
if (newArgs.propKey && this.options.readType && !meta.type) {
|
|
631
|
-
meta.type = Reflect.getOwnMetadata('design:type', newArgs.target, newArgs.propKey);
|
|
632
|
-
}
|
|
633
|
-
const { index } = newArgs;
|
|
634
|
-
const cb = typeof key === 'function' ? key : undefined;
|
|
635
|
-
let data = meta;
|
|
636
|
-
if (!data.params) {
|
|
637
|
-
data.params = (_a = Reflect.getOwnMetadata('design:paramtypes', newArgs.target, newArgs.propKey)) === null || _a === void 0 ? void 0 : _a.map((f) => ({ type: f }));
|
|
638
|
-
}
|
|
639
|
-
if (typeof index === 'number') {
|
|
640
|
-
level = 'PARAM';
|
|
641
|
-
data.params = data.params || [];
|
|
642
|
-
data.params[index] = data.params[index] || {
|
|
643
|
-
type: undefined,
|
|
644
|
-
};
|
|
645
|
-
if (cb) {
|
|
646
|
-
data.params[index] = cb(data.params[index], level, args.propKey, typeof args.index === 'number' ? args.index : undefined);
|
|
647
|
-
}
|
|
648
|
-
else {
|
|
649
|
-
data = data.params[index];
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
else if (!index && !args.descriptor && args.propKey && this.options.collectPropKeys && args.level !== 'CLASS') {
|
|
653
|
-
this.set({ ...args, level: 'CLASS' }, (meta) => {
|
|
654
|
-
if (!meta.properties) {
|
|
655
|
-
meta.properties = [args.propKey];
|
|
656
|
-
}
|
|
657
|
-
else if (!meta.properties.includes(args.propKey)) {
|
|
658
|
-
meta.properties.push(args.propKey);
|
|
659
|
-
}
|
|
660
|
-
return meta;
|
|
661
|
-
});
|
|
662
|
-
}
|
|
663
|
-
level = typeof index === 'number' ? 'PARAM' : newArgs.propKey && newArgs.descriptor ? 'METHOD' : newArgs.propKey ? 'PROP' : 'CLASS';
|
|
664
|
-
if (typeof key !== 'function') {
|
|
665
|
-
if (isArray) {
|
|
666
|
-
const newArray = (data[key] || []);
|
|
667
|
-
if (!Array.isArray(newArray)) {
|
|
668
|
-
panic('Mate.add (isArray=true) called for non-array metadata');
|
|
669
|
-
}
|
|
670
|
-
newArray.unshift(value);
|
|
671
|
-
data[key] = newArray;
|
|
672
|
-
}
|
|
673
|
-
else {
|
|
674
|
-
data[key] = value;
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
else if (cb && typeof index !== 'number') {
|
|
678
|
-
meta = cb(data, level, args.propKey, typeof args.index === 'number' ? args.index : undefined);
|
|
679
|
-
}
|
|
680
|
-
Reflect.defineMetadata(this.workspace, meta, newArgs.target, newArgs.propKey);
|
|
681
|
-
}
|
|
682
|
-
read(target, propKey) {
|
|
683
|
-
const isConstr = isConstructor(target);
|
|
684
|
-
const constructor = isConstr ? target : getConstructor(target);
|
|
685
|
-
const proto = constructor.prototype;
|
|
686
|
-
let ownMeta = Reflect.getOwnMetadata(this.workspace, typeof propKey === 'string' ? proto : constructor, propKey);
|
|
687
|
-
if (this.options.inherit) {
|
|
688
|
-
const inheritFn = typeof this.options.inherit === 'function' ? this.options.inherit : undefined;
|
|
689
|
-
let shouldInherit = this.options.inherit;
|
|
690
|
-
if (inheritFn) {
|
|
691
|
-
if (typeof propKey === 'string') {
|
|
692
|
-
const classMeta = Reflect.getOwnMetadata(this.workspace, constructor);
|
|
693
|
-
shouldInherit = inheritFn(classMeta, ownMeta, 'PROP', propKey);
|
|
694
|
-
}
|
|
695
|
-
else {
|
|
696
|
-
shouldInherit = inheritFn(ownMeta, ownMeta, 'CLASS');
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
if (shouldInherit) {
|
|
700
|
-
const parent = Object.getPrototypeOf(constructor);
|
|
701
|
-
if (typeof parent === 'function' && parent !== fnProto && parent !== constructor) {
|
|
702
|
-
const inheritedMeta = this.read(parent, propKey) || {};
|
|
703
|
-
const ownParams = ownMeta === null || ownMeta === void 0 ? void 0 : ownMeta.params;
|
|
704
|
-
ownMeta = { ...inheritedMeta, ...ownMeta };
|
|
705
|
-
if (typeof propKey === 'string' && ownParams && (inheritedMeta === null || inheritedMeta === void 0 ? void 0 : inheritedMeta.params)) {
|
|
706
|
-
for (let i = 0; i < ownParams.length; i++) {
|
|
707
|
-
if (typeof (inheritedMeta === null || inheritedMeta === void 0 ? void 0 : inheritedMeta.params[i]) !== 'undefined') {
|
|
708
|
-
const ownParam = ownParams[i];
|
|
709
|
-
if (ownMeta.params && inheritFn && inheritFn(ownMeta, ownParam, 'PARAM', typeof propKey === 'string' ? propKey : undefined)) {
|
|
710
|
-
ownMeta.params[i] = {
|
|
711
|
-
...inheritedMeta === null || inheritedMeta === void 0 ? void 0 : inheritedMeta.params[i],
|
|
712
|
-
...ownParams[i],
|
|
713
|
-
};
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
return ownMeta;
|
|
722
|
-
}
|
|
723
|
-
apply(...decorators) {
|
|
724
|
-
return ((target, propKey, descriptor) => {
|
|
725
|
-
for (const d of decorators) {
|
|
726
|
-
d(target, propKey, descriptor);
|
|
727
|
-
}
|
|
728
|
-
});
|
|
729
|
-
}
|
|
730
|
-
decorate(key, value, isArray, level) {
|
|
731
|
-
return ((target, propKey, descriptor) => {
|
|
732
|
-
const args = {
|
|
733
|
-
target,
|
|
734
|
-
propKey,
|
|
735
|
-
descriptor: typeof descriptor === 'number' ? undefined : descriptor,
|
|
736
|
-
index: typeof descriptor === 'number' ? descriptor : undefined,
|
|
737
|
-
level,
|
|
738
|
-
};
|
|
739
|
-
this.set(args, key, value, isArray);
|
|
740
|
-
});
|
|
741
|
-
}
|
|
742
|
-
decorateConditional(ccb) {
|
|
743
|
-
return ((target, propKey, descriptor) => {
|
|
744
|
-
const hasIndex = typeof descriptor === 'number';
|
|
745
|
-
const decoratorLevel = hasIndex ? 'PARAM' : propKey && descriptor ? 'METHOD' : propKey ? 'PROP' : 'CLASS';
|
|
746
|
-
const d = ccb(decoratorLevel);
|
|
747
|
-
if (d) {
|
|
748
|
-
d(target, propKey, descriptor);
|
|
749
|
-
}
|
|
750
|
-
});
|
|
751
|
-
}
|
|
752
|
-
decorateClass(key, value, isArray) {
|
|
753
|
-
return this.decorate(key, value, isArray, 'CLASS');
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
const fnProto = Object.getPrototypeOf(Function);
|
|
757
|
-
|
|
758
|
-
const METADATA_WORKSPACE = 'moost';
|
|
759
|
-
const moostMate = new Mate(METADATA_WORKSPACE, {
|
|
760
|
-
readType: true,
|
|
761
|
-
readReturnType: true,
|
|
762
|
-
collectPropKeys: true,
|
|
763
|
-
inherit(classMeta, targetMeta, level) {
|
|
764
|
-
if (level === 'CLASS') {
|
|
765
|
-
return !!(classMeta === null || classMeta === void 0 ? void 0 : classMeta.inherit);
|
|
766
|
-
}
|
|
767
|
-
if (level === 'PROP') {
|
|
768
|
-
return !!(targetMeta === null || targetMeta === void 0 ? void 0 : targetMeta.inherit) || !!((classMeta === null || classMeta === void 0 ? void 0 : classMeta.inherit) && !targetMeta);
|
|
769
|
-
}
|
|
770
|
-
return !!(targetMeta === null || targetMeta === void 0 ? void 0 : targetMeta.inherit);
|
|
771
|
-
},
|
|
772
|
-
});
|
|
773
|
-
function getMoostMate() {
|
|
774
|
-
return moostMate;
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
getMoostMate().decorate((meta) => {
|
|
778
|
-
if (!meta.injectable)
|
|
779
|
-
meta.injectable = true;
|
|
780
|
-
return meta;
|
|
781
|
-
});
|
|
782
|
-
|
|
783
|
-
var TInterceptorPriority;
|
|
784
|
-
(function (TInterceptorPriority) {
|
|
785
|
-
TInterceptorPriority[TInterceptorPriority["BEFORE_ALL"] = 0] = "BEFORE_ALL";
|
|
786
|
-
TInterceptorPriority[TInterceptorPriority["BEFORE_GUARD"] = 1] = "BEFORE_GUARD";
|
|
787
|
-
TInterceptorPriority[TInterceptorPriority["GUARD"] = 2] = "GUARD";
|
|
788
|
-
TInterceptorPriority[TInterceptorPriority["AFTER_GUARD"] = 3] = "AFTER_GUARD";
|
|
789
|
-
TInterceptorPriority[TInterceptorPriority["INTERCEPTOR"] = 4] = "INTERCEPTOR";
|
|
790
|
-
TInterceptorPriority[TInterceptorPriority["CATCH_ERROR"] = 5] = "CATCH_ERROR";
|
|
791
|
-
TInterceptorPriority[TInterceptorPriority["AFTER_ALL"] = 6] = "AFTER_ALL";
|
|
792
|
-
})(TInterceptorPriority || (TInterceptorPriority = {}));
|
|
793
|
-
function Intercept(handler, priority) {
|
|
794
|
-
return getMoostMate().decorate('interceptors', {
|
|
795
|
-
handler,
|
|
796
|
-
priority: priority || handler.priority || TInterceptorPriority.INTERCEPTOR,
|
|
797
|
-
}, true);
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
var TPipePriority;
|
|
801
|
-
(function (TPipePriority) {
|
|
802
|
-
TPipePriority[TPipePriority["BEFORE_RESOLVE"] = 0] = "BEFORE_RESOLVE";
|
|
803
|
-
TPipePriority[TPipePriority["RESOLVE"] = 1] = "RESOLVE";
|
|
804
|
-
TPipePriority[TPipePriority["AFTER_RESOLVE"] = 2] = "AFTER_RESOLVE";
|
|
805
|
-
TPipePriority[TPipePriority["BEFORE_TRANSFORM"] = 3] = "BEFORE_TRANSFORM";
|
|
806
|
-
TPipePriority[TPipePriority["TRANSFORM"] = 4] = "TRANSFORM";
|
|
807
|
-
TPipePriority[TPipePriority["AFTER_TRANSFORM"] = 5] = "AFTER_TRANSFORM";
|
|
808
|
-
TPipePriority[TPipePriority["BEFORE_VALIDATE"] = 6] = "BEFORE_VALIDATE";
|
|
809
|
-
TPipePriority[TPipePriority["VALIDATE"] = 7] = "VALIDATE";
|
|
810
|
-
TPipePriority[TPipePriority["AFTER_VALIDATE"] = 8] = "AFTER_VALIDATE";
|
|
811
|
-
})(TPipePriority || (TPipePriority = {}));
|
|
812
|
-
|
|
813
|
-
const resolvePipe = (_value, metas, level) => {
|
|
814
|
-
var _a, _b, _c, _d;
|
|
815
|
-
let resolver;
|
|
816
|
-
if (level === 'PARAM') {
|
|
817
|
-
resolver = (_a = metas.paramMeta) === null || _a === void 0 ? void 0 : _a.resolver;
|
|
818
|
-
}
|
|
819
|
-
else if (level === 'PROP') {
|
|
820
|
-
resolver = (_b = metas.propMeta) === null || _b === void 0 ? void 0 : _b.resolver;
|
|
821
|
-
}
|
|
822
|
-
else if (level === 'METHOD') {
|
|
823
|
-
resolver = (_c = metas.methodMeta) === null || _c === void 0 ? void 0 : _c.resolver;
|
|
824
|
-
}
|
|
825
|
-
else if (level === 'CLASS') {
|
|
826
|
-
resolver = (_d = metas.classMeta) === null || _d === void 0 ? void 0 : _d.resolver;
|
|
827
|
-
}
|
|
828
|
-
if (resolver) {
|
|
829
|
-
return resolver(metas, level);
|
|
830
|
-
}
|
|
831
|
-
return undefined;
|
|
832
|
-
};
|
|
833
|
-
resolvePipe.priority = TPipePriority.RESOLVE;
|
|
834
|
-
|
|
835
|
-
[
|
|
836
|
-
{
|
|
837
|
-
handler: resolvePipe,
|
|
838
|
-
priority: TPipePriority.RESOLVE,
|
|
839
|
-
},
|
|
840
|
-
];
|
|
841
|
-
|
|
842
540
|
const setHeaderInterceptor = (name, value, opts) => {
|
|
843
541
|
const fn = (before, after) => {
|
|
844
542
|
const h = useSetHeader(name);
|
|
@@ -871,4 +569,15 @@ function SetCookie(...args) {
|
|
|
871
569
|
return Intercept(setCookieInterceptor(...args));
|
|
872
570
|
}
|
|
873
571
|
|
|
874
|
-
|
|
572
|
+
function httpValidatePipe(opts) {
|
|
573
|
+
return validatePipe(Object.assign({ errorCb: (message, details) => {
|
|
574
|
+
throw new HttpError(400, {
|
|
575
|
+
statusCode: 400,
|
|
576
|
+
message,
|
|
577
|
+
error: 'Validation Error',
|
|
578
|
+
details,
|
|
579
|
+
});
|
|
580
|
+
} }, opts[0]));
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
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, httpValidatePipe };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moostjs/event-http",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.16",
|
|
4
4
|
"description": "@moostjs/event-http",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
"url": "https://github.com/moostjs/moostjs/issues"
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/moostjs/moostjs/tree/main/packages/event-http#readme",
|
|
30
|
-
"peerDependencies": {
|
|
31
|
-
"moost": "0.2.14",
|
|
32
|
-
"wooks": "^0.2.7",
|
|
33
|
-
"@wooksjs/event-core": "^0.2.7"
|
|
34
|
-
},
|
|
30
|
+
"peerDependencies": {},
|
|
35
31
|
"dependencies": {
|
|
36
|
-
"
|
|
32
|
+
"moost": "0.2.16",
|
|
33
|
+
"@wooksjs/event-core": "^0.2.9",
|
|
34
|
+
"@wooksjs/event-http": "^0.2.9",
|
|
35
|
+
"@prostojs/infact": "^0.1.7",
|
|
36
|
+
"@prostojs/router": ""
|
|
37
37
|
}
|
|
38
38
|
}
|