@nattyjs/core 0.0.1-beta.34 → 0.0.1-beta.35

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
@@ -494,6 +494,32 @@ const entityContainer = new class {
494
494
  }
495
495
  }();
496
496
 
497
+ class ForbiddenAccessException extends HttpException {
498
+ constructor(data) {
499
+ super({
500
+ body: data,
501
+ status: 403
502
+ });
503
+ }
504
+ }
505
+
506
+ class UnauthorizedAccessException extends HttpException {
507
+ constructor(data) {
508
+ super({
509
+ body: data,
510
+ status: 401
511
+ });
512
+ }
513
+ }
514
+
515
+ function CreateProblemDetail(modelName, detail) {
516
+ return {
517
+ type: "https://tools.ietf.org/html/rfc7231#section-6.5.1",
518
+ title: `The specified ${modelName} model props are invalid.`,
519
+ detail
520
+ };
521
+ }
522
+
497
523
  class ParameterTypeConverter extends BaseResponse {
498
524
  constructor() {
499
525
  super(...arguments);
@@ -582,7 +608,10 @@ class ParameterTypeConverter extends BaseResponse {
582
608
  for (const parameterInfo of methodInfo.parameters) {
583
609
  const value = jObject[parameterInfo.name];
584
610
  if (value !== void 0) {
585
- jObject[parameterInfo.name] = SANITIZERS[parameterInfo.type](value);
611
+ const sanitizedValue = SANITIZERS[parameterInfo.type](value);
612
+ if (sanitizedValue === null && sanitizedValue != value)
613
+ throw new HttpBadRequestException(CreateProblemDetail(parameterInfo.type, [{ [parameterInfo.name]: `The supplied data type must be "${parameterInfo.type}"` }]));
614
+ jObject[parameterInfo.name] = sanitizedValue;
586
615
  }
587
616
  }
588
617
  return jObject;
@@ -699,15 +728,6 @@ class RouteParser extends ParameterTypeConverter {
699
728
  }
700
729
  }
701
730
 
702
- class UnauthorizedAccessException extends HttpException {
703
- constructor(data) {
704
- super({
705
- body: data,
706
- status: 401
707
- });
708
- }
709
- }
710
-
711
731
  const decoratorStateContainer = new class {
712
732
  constructor() {
713
733
  this.controllerConfig = {};
@@ -753,15 +773,6 @@ var DecoratorType = /* @__PURE__ */ ((DecoratorType2) => {
753
773
  return DecoratorType2;
754
774
  })(DecoratorType || {});
755
775
 
756
- class ForbiddenAccessException extends HttpException {
757
- constructor(data) {
758
- super({
759
- body: data,
760
- status: 403
761
- });
762
- }
763
- }
764
-
765
776
  class AbstractExecutionContext {
766
777
  constructor(context, routeInfo) {
767
778
  this.context = context;
@@ -791,14 +802,6 @@ class ActionExecutingContext extends AbstractExecutionContext {
791
802
  }
792
803
  }
793
804
 
794
- function CreateProblemDetail(modelName, detail) {
795
- return {
796
- type: "https://tools.ietf.org/html/rfc7231#section-6.5.1",
797
- title: `The specified ${modelName} model props are invalid.`,
798
- detail
799
- };
800
- }
801
-
802
805
  function runValidators(entityName, value) {
803
806
  const typeInfo = nattyContainer.types[entityName];
804
807
  let errors = {};
@@ -860,6 +863,8 @@ class ModelBindingContext extends ParameterTypeConverter {
860
863
  else
861
864
  this.data = body;
862
865
  this.instance = this.convertToInstance(this.type, this.data);
866
+ if (!this.isValid)
867
+ throw new HttpBadRequestException(CreateProblemDetail(this.type, this.errors));
863
868
  }
864
869
  get isValid() {
865
870
  const errors = runValidators(this.type, this.instance);
package/dist/index.d.ts CHANGED
@@ -53,9 +53,9 @@ declare function route(path: string): (target: any, propertyKey?: string, parame
53
53
 
54
54
  declare function get(path: string): (target: any, propertyKey?: string, descriptor?: any) => void;
55
55
 
56
- declare function post(path: string): (target: any, propertyKey?: string, descriptor?: any) => void;
56
+ declare function post(path?: string): (target: any, propertyKey?: string, descriptor?: any) => void;
57
57
 
58
- declare function put(path: string): (target: any, propertyKey?: string, descriptor?: any) => void;
58
+ declare function put(path?: string): (target: any, propertyKey?: string, descriptor?: any) => void;
59
59
 
60
60
  declare function Delete(): (target: any, propertyKey?: string, descriptor?: any) => void;
61
61
 
package/dist/index.mjs CHANGED
@@ -492,6 +492,32 @@ const entityContainer = new class {
492
492
  }
493
493
  }();
494
494
 
495
+ class ForbiddenAccessException extends HttpException {
496
+ constructor(data) {
497
+ super({
498
+ body: data,
499
+ status: 403
500
+ });
501
+ }
502
+ }
503
+
504
+ class UnauthorizedAccessException extends HttpException {
505
+ constructor(data) {
506
+ super({
507
+ body: data,
508
+ status: 401
509
+ });
510
+ }
511
+ }
512
+
513
+ function CreateProblemDetail(modelName, detail) {
514
+ return {
515
+ type: "https://tools.ietf.org/html/rfc7231#section-6.5.1",
516
+ title: `The specified ${modelName} model props are invalid.`,
517
+ detail
518
+ };
519
+ }
520
+
495
521
  class ParameterTypeConverter extends BaseResponse {
496
522
  constructor() {
497
523
  super(...arguments);
@@ -580,7 +606,10 @@ class ParameterTypeConverter extends BaseResponse {
580
606
  for (const parameterInfo of methodInfo.parameters) {
581
607
  const value = jObject[parameterInfo.name];
582
608
  if (value !== void 0) {
583
- jObject[parameterInfo.name] = SANITIZERS[parameterInfo.type](value);
609
+ const sanitizedValue = SANITIZERS[parameterInfo.type](value);
610
+ if (sanitizedValue === null && sanitizedValue != value)
611
+ throw new HttpBadRequestException(CreateProblemDetail(parameterInfo.type, [{ [parameterInfo.name]: `The supplied data type must be "${parameterInfo.type}"` }]));
612
+ jObject[parameterInfo.name] = sanitizedValue;
584
613
  }
585
614
  }
586
615
  return jObject;
@@ -697,15 +726,6 @@ class RouteParser extends ParameterTypeConverter {
697
726
  }
698
727
  }
699
728
 
700
- class UnauthorizedAccessException extends HttpException {
701
- constructor(data) {
702
- super({
703
- body: data,
704
- status: 401
705
- });
706
- }
707
- }
708
-
709
729
  const decoratorStateContainer = new class {
710
730
  constructor() {
711
731
  this.controllerConfig = {};
@@ -751,15 +771,6 @@ var DecoratorType = /* @__PURE__ */ ((DecoratorType2) => {
751
771
  return DecoratorType2;
752
772
  })(DecoratorType || {});
753
773
 
754
- class ForbiddenAccessException extends HttpException {
755
- constructor(data) {
756
- super({
757
- body: data,
758
- status: 403
759
- });
760
- }
761
- }
762
-
763
774
  class AbstractExecutionContext {
764
775
  constructor(context, routeInfo) {
765
776
  this.context = context;
@@ -789,14 +800,6 @@ class ActionExecutingContext extends AbstractExecutionContext {
789
800
  }
790
801
  }
791
802
 
792
- function CreateProblemDetail(modelName, detail) {
793
- return {
794
- type: "https://tools.ietf.org/html/rfc7231#section-6.5.1",
795
- title: `The specified ${modelName} model props are invalid.`,
796
- detail
797
- };
798
- }
799
-
800
803
  function runValidators(entityName, value) {
801
804
  const typeInfo = nattyContainer.types[entityName];
802
805
  let errors = {};
@@ -858,6 +861,8 @@ class ModelBindingContext extends ParameterTypeConverter {
858
861
  else
859
862
  this.data = body;
860
863
  this.instance = this.convertToInstance(this.type, this.data);
864
+ if (!this.isValid)
865
+ throw new HttpBadRequestException(CreateProblemDetail(this.type, this.errors));
861
866
  }
862
867
  get isValid() {
863
868
  const errors = runValidators(this.type, this.instance);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nattyjs/core",
3
- "version": "0.0.1-beta.34",
3
+ "version": "0.0.1-beta.35",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "ajayojha",
@@ -15,9 +15,10 @@
15
15
  "build": "unbuild"
16
16
  },
17
17
  "dependencies": {
18
+ "reflect-metadata": "0.2.2",
18
19
  "tsyringe": "^4.7.0",
19
20
  "path-to-regexp": "6.2.1",
20
- "@nattyjs/common": "0.0.1-beta.34"
21
+ "@nattyjs/common": "0.0.1-beta.35"
21
22
  },
22
23
  "devDependencies": {
23
24
  "unbuild": "1.2.1"