@moostjs/event-http 0.2.12 → 0.2.14

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 CHANGED
@@ -472,7 +472,7 @@ function Query(name) {
472
472
  return value === '' && p.has(name) || value;
473
473
  }
474
474
  const json = jsonSearchParams();
475
- return Object.keys(json).length ? json : undefined;
475
+ return Object.keys(json).length ? json : null;
476
476
  }, name || 'Query');
477
477
  }
478
478
  /**
@@ -481,7 +481,7 @@ function Query(name) {
481
481
  * @paramType string
482
482
  */
483
483
  function Url() {
484
- return moost.Resolve(() => eventHttp.useRequest().url, 'url');
484
+ return moost.Resolve(() => eventHttp.useRequest().url || '', 'url');
485
485
  }
486
486
  /**
487
487
  * Get Requested HTTP Method
@@ -621,11 +621,12 @@ class Mate {
621
621
  }
622
622
  set(args, key, value, isArray) {
623
623
  var _a;
624
+ let level = 'CLASS';
624
625
  const newArgs = args.level === 'CLASS' ? { target: args.target }
625
- : args.level === 'PROPERTY' ? { target: args.target, propKey: args.propKey }
626
+ : args.level === 'PROP' ? { target: args.target, propKey: args.propKey }
626
627
  : args;
627
628
  let meta = Reflect.getOwnMetadata(this.workspace, newArgs.target, newArgs.propKey) || {};
628
- if (newArgs.propKey && this.options.readReturnType && !meta.returnType) {
629
+ if (newArgs.propKey && this.options.readReturnType && !meta.returnType && args.descriptor) {
629
630
  meta.returnType = Reflect.getOwnMetadata('design:returntype', newArgs.target, newArgs.propKey);
630
631
  }
631
632
  if (newArgs.propKey && this.options.readType && !meta.type) {
@@ -638,12 +639,13 @@ class Mate {
638
639
  data.params = (_a = Reflect.getOwnMetadata('design:paramtypes', newArgs.target, newArgs.propKey)) === null || _a === void 0 ? void 0 : _a.map((f) => ({ type: f }));
639
640
  }
640
641
  if (typeof index === 'number') {
642
+ level = 'PARAM';
641
643
  data.params = data.params || [];
642
644
  data.params[index] = data.params[index] || {
643
645
  type: undefined,
644
646
  };
645
647
  if (cb) {
646
- data.params[index] = cb(data.params[index], args.propKey, typeof args.index === 'number' ? args.index : undefined);
648
+ data.params[index] = cb(data.params[index], level, args.propKey, typeof args.index === 'number' ? args.index : undefined);
647
649
  }
648
650
  else {
649
651
  data = data.params[index];
@@ -660,6 +662,7 @@ class Mate {
660
662
  return meta;
661
663
  });
662
664
  }
665
+ level = typeof index === 'number' ? 'PARAM' : newArgs.propKey && newArgs.descriptor ? 'METHOD' : newArgs.propKey ? 'PROP' : 'CLASS';
663
666
  if (typeof key !== 'function') {
664
667
  if (isArray) {
665
668
  const newArray = (data[key] || []);
@@ -674,11 +677,11 @@ class Mate {
674
677
  }
675
678
  }
676
679
  else if (cb && typeof index !== 'number') {
677
- meta = cb(data, args.propKey, typeof args.index === 'number' ? args.index : undefined);
680
+ meta = cb(data, level, args.propKey, typeof args.index === 'number' ? args.index : undefined);
678
681
  }
679
682
  Reflect.defineMetadata(this.workspace, meta, newArgs.target, newArgs.propKey);
680
683
  }
681
- read(target, propKey, index) {
684
+ read(target, propKey) {
682
685
  const isConstr = isConstructor(target);
683
686
  const constructor = isConstr ? target : getConstructor(target);
684
687
  const proto = constructor.prototype;
@@ -689,17 +692,31 @@ class Mate {
689
692
  if (inheritFn) {
690
693
  if (typeof propKey === 'string') {
691
694
  const classMeta = Reflect.getOwnMetadata(this.workspace, constructor);
692
- shouldInherit = inheritFn(classMeta, propKey, ownMeta);
695
+ shouldInherit = inheritFn(classMeta, ownMeta, 'PROP', propKey);
693
696
  }
694
697
  else {
695
- shouldInherit = inheritFn(ownMeta);
698
+ shouldInherit = inheritFn(ownMeta, ownMeta, 'CLASS');
696
699
  }
697
700
  }
698
701
  if (shouldInherit) {
699
702
  const parent = Object.getPrototypeOf(constructor);
700
703
  if (typeof parent === 'function' && parent !== fnProto && parent !== constructor) {
701
- const inheritedMeta = this.read(parent, propKey);
702
- ownMeta = { ...inheritedMeta, ...ownMeta, params: ownMeta === null || ownMeta === void 0 ? void 0 : ownMeta.params };
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
+ }
703
720
  }
704
721
  }
705
722
  }
@@ -724,6 +741,16 @@ class Mate {
724
741
  this.set(args, key, value, isArray);
725
742
  });
726
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
+ }
727
754
  decorateClass(key, value, isArray) {
728
755
  return this.decorate(key, value, isArray, 'CLASS');
729
756
  }
@@ -735,6 +762,15 @@ const moostMate = new Mate(METADATA_WORKSPACE, {
735
762
  readType: true,
736
763
  readReturnType: true,
737
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
+ },
738
774
  });
739
775
  function getMoostMate() {
740
776
  return moostMate;
@@ -806,7 +842,7 @@ resolvePipe.priority = TPipePriority.RESOLVE;
806
842
  ];
807
843
 
808
844
  const setHeaderInterceptor = (name, value, opts) => {
809
- const fn = (before, after, onError) => {
845
+ const fn = (before, after) => {
810
846
  const h = eventHttp.useSetHeader(name);
811
847
  const status = eventHttp.useStatus();
812
848
  after(() => {
@@ -822,7 +858,7 @@ function SetHeader(...args) {
822
858
  return Intercept(setHeaderInterceptor(...args));
823
859
  }
824
860
  const setCookieInterceptor = (name, value, attrs) => {
825
- const fn = (before, after, onError) => {
861
+ const fn = (before, after) => {
826
862
  const { setCookie, getCookie } = eventHttp.useSetCookies();
827
863
  after(() => {
828
864
  if (!getCookie(name)) {
package/dist/index.mjs CHANGED
@@ -470,7 +470,7 @@ function Query(name) {
470
470
  return value === '' && p.has(name) || value;
471
471
  }
472
472
  const json = jsonSearchParams();
473
- return Object.keys(json).length ? json : undefined;
473
+ return Object.keys(json).length ? json : null;
474
474
  }, name || 'Query');
475
475
  }
476
476
  /**
@@ -479,7 +479,7 @@ function Query(name) {
479
479
  * @paramType string
480
480
  */
481
481
  function Url() {
482
- return Resolve(() => useRequest().url, 'url');
482
+ return Resolve(() => useRequest().url || '', 'url');
483
483
  }
484
484
  /**
485
485
  * Get Requested HTTP Method
@@ -619,11 +619,12 @@ class Mate {
619
619
  }
620
620
  set(args, key, value, isArray) {
621
621
  var _a;
622
+ let level = 'CLASS';
622
623
  const newArgs = args.level === 'CLASS' ? { target: args.target }
623
- : args.level === 'PROPERTY' ? { target: args.target, propKey: args.propKey }
624
+ : args.level === 'PROP' ? { target: args.target, propKey: args.propKey }
624
625
  : args;
625
626
  let meta = Reflect.getOwnMetadata(this.workspace, newArgs.target, newArgs.propKey) || {};
626
- if (newArgs.propKey && this.options.readReturnType && !meta.returnType) {
627
+ if (newArgs.propKey && this.options.readReturnType && !meta.returnType && args.descriptor) {
627
628
  meta.returnType = Reflect.getOwnMetadata('design:returntype', newArgs.target, newArgs.propKey);
628
629
  }
629
630
  if (newArgs.propKey && this.options.readType && !meta.type) {
@@ -636,12 +637,13 @@ class Mate {
636
637
  data.params = (_a = Reflect.getOwnMetadata('design:paramtypes', newArgs.target, newArgs.propKey)) === null || _a === void 0 ? void 0 : _a.map((f) => ({ type: f }));
637
638
  }
638
639
  if (typeof index === 'number') {
640
+ level = 'PARAM';
639
641
  data.params = data.params || [];
640
642
  data.params[index] = data.params[index] || {
641
643
  type: undefined,
642
644
  };
643
645
  if (cb) {
644
- data.params[index] = cb(data.params[index], args.propKey, typeof args.index === 'number' ? args.index : undefined);
646
+ data.params[index] = cb(data.params[index], level, args.propKey, typeof args.index === 'number' ? args.index : undefined);
645
647
  }
646
648
  else {
647
649
  data = data.params[index];
@@ -658,6 +660,7 @@ class Mate {
658
660
  return meta;
659
661
  });
660
662
  }
663
+ level = typeof index === 'number' ? 'PARAM' : newArgs.propKey && newArgs.descriptor ? 'METHOD' : newArgs.propKey ? 'PROP' : 'CLASS';
661
664
  if (typeof key !== 'function') {
662
665
  if (isArray) {
663
666
  const newArray = (data[key] || []);
@@ -672,11 +675,11 @@ class Mate {
672
675
  }
673
676
  }
674
677
  else if (cb && typeof index !== 'number') {
675
- meta = cb(data, args.propKey, typeof args.index === 'number' ? args.index : undefined);
678
+ meta = cb(data, level, args.propKey, typeof args.index === 'number' ? args.index : undefined);
676
679
  }
677
680
  Reflect.defineMetadata(this.workspace, meta, newArgs.target, newArgs.propKey);
678
681
  }
679
- read(target, propKey, index) {
682
+ read(target, propKey) {
680
683
  const isConstr = isConstructor(target);
681
684
  const constructor = isConstr ? target : getConstructor(target);
682
685
  const proto = constructor.prototype;
@@ -687,17 +690,31 @@ class Mate {
687
690
  if (inheritFn) {
688
691
  if (typeof propKey === 'string') {
689
692
  const classMeta = Reflect.getOwnMetadata(this.workspace, constructor);
690
- shouldInherit = inheritFn(classMeta, propKey, ownMeta);
693
+ shouldInherit = inheritFn(classMeta, ownMeta, 'PROP', propKey);
691
694
  }
692
695
  else {
693
- shouldInherit = inheritFn(ownMeta);
696
+ shouldInherit = inheritFn(ownMeta, ownMeta, 'CLASS');
694
697
  }
695
698
  }
696
699
  if (shouldInherit) {
697
700
  const parent = Object.getPrototypeOf(constructor);
698
701
  if (typeof parent === 'function' && parent !== fnProto && parent !== constructor) {
699
- const inheritedMeta = this.read(parent, propKey);
700
- ownMeta = { ...inheritedMeta, ...ownMeta, params: ownMeta === null || ownMeta === void 0 ? void 0 : ownMeta.params };
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
+ }
701
718
  }
702
719
  }
703
720
  }
@@ -722,6 +739,16 @@ class Mate {
722
739
  this.set(args, key, value, isArray);
723
740
  });
724
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
+ }
725
752
  decorateClass(key, value, isArray) {
726
753
  return this.decorate(key, value, isArray, 'CLASS');
727
754
  }
@@ -733,6 +760,15 @@ const moostMate = new Mate(METADATA_WORKSPACE, {
733
760
  readType: true,
734
761
  readReturnType: true,
735
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
+ },
736
772
  });
737
773
  function getMoostMate() {
738
774
  return moostMate;
@@ -804,7 +840,7 @@ resolvePipe.priority = TPipePriority.RESOLVE;
804
840
  ];
805
841
 
806
842
  const setHeaderInterceptor = (name, value, opts) => {
807
- const fn = (before, after, onError) => {
843
+ const fn = (before, after) => {
808
844
  const h = useSetHeader(name);
809
845
  const status = useStatus();
810
846
  after(() => {
@@ -820,7 +856,7 @@ function SetHeader(...args) {
820
856
  return Intercept(setHeaderInterceptor(...args));
821
857
  }
822
858
  const setCookieInterceptor = (name, value, attrs) => {
823
- const fn = (before, after, onError) => {
859
+ const fn = (before, after) => {
824
860
  const { setCookie, getCookie } = useSetCookies();
825
861
  after(() => {
826
862
  if (!getCookie(name)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moostjs/event-http",
3
- "version": "0.2.12",
3
+ "version": "0.2.14",
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.12",
32
- "wooks": "^0.2.6",
33
- "@wooksjs/event-core": "^0.2.6"
31
+ "moost": "0.2.14",
32
+ "wooks": "^0.2.7",
33
+ "@wooksjs/event-core": "^0.2.7"
34
34
  },
35
35
  "dependencies": {
36
- "@wooksjs/event-http": "^0.2.6"
36
+ "@wooksjs/event-http": "^0.2.7"
37
37
  }
38
38
  }