@native-systems/utility 1.0.6 → 1.1.1

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
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var common = require('@nestjs/common');
4
-
5
3
  var PostgresError = /*#__PURE__*/ (function (PostgresError) {
6
4
  PostgresError['SUCCESSFUL_COMPLETION'] = '00000';
7
5
  PostgresError['WARNING'] = '01000';
@@ -298,7 +296,7 @@ function _call_super$1(_this, derived, args) {
298
296
  : derived.apply(_this, args)
299
297
  );
300
298
  }
301
- function _class_call_check$4(instance, Constructor) {
299
+ function _class_call_check$3(instance, Constructor) {
302
300
  if (!(instance instanceof Constructor)) {
303
301
  throw new TypeError('Cannot call a class as a function');
304
302
  }
@@ -419,7 +417,7 @@ function _is_native_reflect_construct$1() {
419
417
  var NativeException = /*#__PURE__*/ (function (Error1) {
420
418
  _inherits$1(NativeException, Error1);
421
419
  function NativeException(code, message) {
422
- _class_call_check$4(this, NativeException);
420
+ _class_call_check$3(this, NativeException);
423
421
  var _this;
424
422
  (_this = _call_super$1(this, NativeException, [message])),
425
423
  _define_property$2(_this, 'code', void 0);
@@ -451,7 +449,7 @@ function _call_super(_this, derived, args) {
451
449
  : derived.apply(_this, args)
452
450
  );
453
451
  }
454
- function _class_call_check$3(instance, Constructor) {
452
+ function _class_call_check$2(instance, Constructor) {
455
453
  if (!(instance instanceof Constructor)) {
456
454
  throw new TypeError('Cannot call a class as a function');
457
455
  }
@@ -471,7 +469,7 @@ function _construct(Parent, args, Class) {
471
469
  }
472
470
  return _construct.apply(null, arguments);
473
471
  }
474
- function _defineProperties$3(target, props) {
472
+ function _defineProperties$2(target, props) {
475
473
  for (var i = 0; i < props.length; i++) {
476
474
  var descriptor = props[i];
477
475
  descriptor.enumerable = descriptor.enumerable || false;
@@ -480,8 +478,8 @@ function _defineProperties$3(target, props) {
480
478
  Object.defineProperty(target, descriptor.key, descriptor);
481
479
  }
482
480
  }
483
- function _create_class$3(Constructor, protoProps, staticProps) {
484
- if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
481
+ function _create_class$2(Constructor, protoProps, staticProps) {
482
+ if (protoProps) _defineProperties$2(Constructor.prototype, protoProps);
485
483
  return Constructor;
486
484
  }
487
485
  function _define_property$1(obj, key, value) {
@@ -581,7 +579,7 @@ function _is_native_reflect_construct() {
581
579
  var PgException = /*#__PURE__*/ (function (Error1) {
582
580
  _inherits(PgException, Error1);
583
581
  function PgException(err, message, specific) {
584
- _class_call_check$3(this, PgException);
582
+ _class_call_check$2(this, PgException);
585
583
  var _this;
586
584
  (_this = _call_super(this, PgException, [message])),
587
585
  _define_property$1(_this, 'err', void 0),
@@ -591,7 +589,7 @@ var PgException = /*#__PURE__*/ (function (Error1) {
591
589
  _this.specific = specific;
592
590
  return _this;
593
591
  }
594
- _create_class$3(PgException, [
592
+ _create_class$2(PgException, [
595
593
  {
596
594
  key: 'getStatus',
597
595
  value: function getStatus() {
@@ -618,152 +616,6 @@ var PgException = /*#__PURE__*/ (function (Error1) {
618
616
  return PgException;
619
617
  })(_wrap_native_super(Error));
620
618
 
621
- function _class_call_check$2(instance, Constructor) {
622
- if (!(instance instanceof Constructor)) {
623
- throw new TypeError('Cannot call a class as a function');
624
- }
625
- }
626
- function _defineProperties$2(target, props) {
627
- for (var i = 0; i < props.length; i++) {
628
- var descriptor = props[i];
629
- descriptor.enumerable = descriptor.enumerable || false;
630
- descriptor.configurable = true;
631
- if ('value' in descriptor) descriptor.writable = true;
632
- Object.defineProperty(target, descriptor.key, descriptor);
633
- }
634
- }
635
- function _create_class$2(Constructor, protoProps, staticProps) {
636
- if (staticProps) _defineProperties$2(Constructor, staticProps);
637
- return Constructor;
638
- }
639
- function _instanceof(left, right) {
640
- if (
641
- right != null &&
642
- typeof Symbol !== 'undefined' &&
643
- right[Symbol.hasInstance]
644
- ) {
645
- return !!right[Symbol.hasInstance](left);
646
- } else {
647
- return left instanceof right;
648
- }
649
- }
650
- var statusMap = {
651
- 100: 'Continue',
652
- 101: 'Switching Protocols',
653
- 102: 'Processing',
654
- 103: 'Early Hints',
655
- 200: 'OK',
656
- 201: 'Created',
657
- 202: 'Accepted',
658
- 203: 'Non-Authoritative Information',
659
- 204: 'No Content',
660
- 205: 'Reset Content',
661
- 206: 'Partial Content',
662
- 300: 'Multiple Choices',
663
- 301: 'Moved Permanently',
664
- 302: 'Found',
665
- 303: 'See Other',
666
- 304: 'Not Modified',
667
- 307: 'Temporary Redirect',
668
- 308: 'Permanent Redirect',
669
- 400: 'Bad Request',
670
- 401: 'Unauthorized',
671
- 402: 'Payment Required',
672
- 403: 'Forbidden',
673
- 404: 'Not Found',
674
- 405: 'Method Not Allowed',
675
- 406: 'Not Acceptable',
676
- 407: 'Proxy Authentication Required',
677
- 408: 'Request Timeout',
678
- 409: 'Conflict',
679
- 410: 'Gone',
680
- 411: 'Length Required',
681
- 412: 'Precondition Failed',
682
- 413: 'Payload Too Large',
683
- 414: 'URI Too Long',
684
- 415: 'Unsupported Media Type',
685
- 416: 'Requested Range Not Satisfiable',
686
- 417: 'Expectation Failed',
687
- 418: "I'm a Teapot",
688
- 421: 'Misdirected Request',
689
- 422: 'Unprocessable Entity',
690
- 424: 'Failed Dependency',
691
- 428: 'Precondition Required',
692
- 429: 'Too Many Requests',
693
- 500: 'Internal Server Error',
694
- 501: 'Not Implemented',
695
- 502: 'Bad Gateway',
696
- 503: 'Service Unavailable',
697
- 504: 'Gateway Timeout',
698
- 505: 'HTTP Version Not Supported',
699
- };
700
- var Exceptions = /*#__PURE__*/ (function () {
701
- function Exceptions() {
702
- _class_call_check$2(this, Exceptions);
703
- }
704
- _create_class$2(Exceptions, null, [
705
- {
706
- key: 'getHttpStatusText',
707
- value: function getHttpStatusText(statusCode) {
708
- var statusText = statusMap[statusCode];
709
- if (!statusText) {
710
- return 'Error';
711
- }
712
- return statusText;
713
- },
714
- },
715
- {
716
- key: 'transformPgError',
717
- value: function transformPgError(error) {
718
- var httpStatus;
719
- var errMsg = null;
720
- switch (error.getStatus()) {
721
- case PostgresError.FOREIGN_KEY_VIOLATION:
722
- httpStatus = common.HttpStatus.NOT_FOUND;
723
- errMsg = error.getSpecificMessage(
724
- PostgresError.FOREIGN_KEY_VIOLATION
725
- );
726
- break;
727
- case PostgresError.UNIQUE_VIOLATION:
728
- httpStatus = common.HttpStatus.CONFLICT;
729
- errMsg = error.getSpecificMessage(PostgresError.UNIQUE_VIOLATION);
730
- break;
731
- case PostgresError.INVALID_TEXT_REPRESENTATION:
732
- httpStatus = common.HttpStatus.BAD_REQUEST;
733
- errMsg = error.getSpecificMessage(
734
- PostgresError.INVALID_TEXT_REPRESENTATION
735
- );
736
- break;
737
- default:
738
- httpStatus = common.HttpStatus.INTERNAL_SERVER_ERROR;
739
- }
740
- return new NativeException(
741
- httpStatus,
742
- errMsg !== null && errMsg !== void 0 ? errMsg : error.message
743
- );
744
- },
745
- },
746
- {
747
- key: 'toHttpException',
748
- value: function toHttpException(error) {
749
- var _error = error;
750
- if (_instanceof(_error, PgException)) {
751
- _error = this.transformPgError(_error);
752
- }
753
- return new common.HttpException(
754
- {
755
- status: _error.code,
756
- message: _error.message,
757
- error: this.getHttpStatusText(_error.code),
758
- },
759
- _error.code
760
- );
761
- },
762
- },
763
- ]);
764
- return Exceptions;
765
- })();
766
-
767
619
  function _class_call_check$1(instance, Constructor) {
768
620
  if (!(instance instanceof Constructor)) {
769
621
  throw new TypeError('Cannot call a class as a function');
@@ -930,7 +782,6 @@ var HttpHandler = /*#__PURE__*/ (function () {
930
782
  return HttpHandler;
931
783
  })();
932
784
 
933
- exports.Exceptions = Exceptions;
934
785
  exports.HttpHandler = HttpHandler;
935
786
  exports.NativeException = NativeException;
936
787
  exports.PgException = PgException;
package/dist/index.d.ts CHANGED
@@ -542,7 +542,59 @@ declare module "@native-systems/utility" {
542
542
  }
543
543
 
544
544
  declare module "@native-systems/utility" {
545
- import { HttpStatus } from "@nestjs/common";
545
+ export enum HttpStatus {
546
+ CONTINUE = 100,
547
+ SWITCHING_PROTOCOLS = 101,
548
+ PROCESSING = 102,
549
+ EARLYHINTS = 103,
550
+ OK = 200,
551
+ CREATED = 201,
552
+ ACCEPTED = 202,
553
+ NON_AUTHORITATIVE_INFORMATION = 203,
554
+ NO_CONTENT = 204,
555
+ RESET_CONTENT = 205,
556
+ PARTIAL_CONTENT = 206,
557
+ AMBIGUOUS = 300,
558
+ MOVED_PERMANENTLY = 301,
559
+ FOUND = 302,
560
+ SEE_OTHER = 303,
561
+ NOT_MODIFIED = 304,
562
+ TEMPORARY_REDIRECT = 307,
563
+ PERMANENT_REDIRECT = 308,
564
+ BAD_REQUEST = 400,
565
+ UNAUTHORIZED = 401,
566
+ PAYMENT_REQUIRED = 402,
567
+ FORBIDDEN = 403,
568
+ NOT_FOUND = 404,
569
+ METHOD_NOT_ALLOWED = 405,
570
+ NOT_ACCEPTABLE = 406,
571
+ PROXY_AUTHENTICATION_REQUIRED = 407,
572
+ REQUEST_TIMEOUT = 408,
573
+ CONFLICT = 409,
574
+ GONE = 410,
575
+ LENGTH_REQUIRED = 411,
576
+ PRECONDITION_FAILED = 412,
577
+ PAYLOAD_TOO_LARGE = 413,
578
+ URI_TOO_LONG = 414,
579
+ UNSUPPORTED_MEDIA_TYPE = 415,
580
+ REQUESTED_RANGE_NOT_SATISFIABLE = 416,
581
+ EXPECTATION_FAILED = 417,
582
+ I_AM_A_TEAPOT = 418,
583
+ MISDIRECTED = 421,
584
+ UNPROCESSABLE_ENTITY = 422,
585
+ FAILED_DEPENDENCY = 424,
586
+ PRECONDITION_REQUIRED = 428,
587
+ TOO_MANY_REQUESTS = 429,
588
+ INTERNAL_SERVER_ERROR = 500,
589
+ NOT_IMPLEMENTED = 501,
590
+ BAD_GATEWAY = 502,
591
+ SERVICE_UNAVAILABLE = 503,
592
+ GATEWAY_TIMEOUT = 504,
593
+ HTTP_VERSION_NOT_SUPPORTED = 505
594
+ }
595
+ }
596
+
597
+ declare module "@native-systems/utility" {
546
598
  /**
547
599
  * Custom exception object used by Native Systems, which extends the Error interface
548
600
  * and adds the 'code' attribute, to be able to provide an additional httpStatus.
@@ -588,26 +640,6 @@ declare module "@native-systems/utility" {
588
640
  export { PgException };
589
641
  }
590
642
 
591
- declare module "@native-systems/utility" {
592
- import { HttpException } from "@nestjs/common";
593
- class Exceptions {
594
- private static getHttpStatusText;
595
- /**
596
- * Evaluates a thrown postgres error object, which is then sanitized into an appropriate NativeError object.
597
- * @param error a postgres error that, for example is from a rejected promise.
598
- * @returns {NativeException} a NativeError object with either a concrete reason or a generic error message.
599
- */
600
- private static transformPgError;
601
- /**
602
- * Transforms an exception instance into a HttpException instance and returns it.
603
- * @param error {PgException | NativeException} An error object of one of those instances.
604
- * @returns {HttpException} The transformed exception, modeled into a HttpException instance.
605
- */
606
- static toHttpException(error: PgException | NativeException): HttpException;
607
- }
608
- export { Exceptions };
609
- }
610
-
611
643
  declare module "@native-systems/utility" {
612
644
  type LogLevel = 'log' | 'warn' | 'error';
613
645
  interface LogFn {
package/dist/index.esm.js CHANGED
@@ -1,5 +1,3 @@
1
- import { HttpStatus, HttpException } from '@nestjs/common';
2
-
3
1
  var PostgresError = /*#__PURE__*/ (function (PostgresError) {
4
2
  PostgresError['SUCCESSFUL_COMPLETION'] = '00000';
5
3
  PostgresError['WARNING'] = '01000';
@@ -296,7 +294,7 @@ function _call_super$1(_this, derived, args) {
296
294
  : derived.apply(_this, args)
297
295
  );
298
296
  }
299
- function _class_call_check$4(instance, Constructor) {
297
+ function _class_call_check$3(instance, Constructor) {
300
298
  if (!(instance instanceof Constructor)) {
301
299
  throw new TypeError('Cannot call a class as a function');
302
300
  }
@@ -417,7 +415,7 @@ function _is_native_reflect_construct$1() {
417
415
  var NativeException = /*#__PURE__*/ (function (Error1) {
418
416
  _inherits$1(NativeException, Error1);
419
417
  function NativeException(code, message) {
420
- _class_call_check$4(this, NativeException);
418
+ _class_call_check$3(this, NativeException);
421
419
  var _this;
422
420
  (_this = _call_super$1(this, NativeException, [message])),
423
421
  _define_property$2(_this, 'code', void 0);
@@ -449,7 +447,7 @@ function _call_super(_this, derived, args) {
449
447
  : derived.apply(_this, args)
450
448
  );
451
449
  }
452
- function _class_call_check$3(instance, Constructor) {
450
+ function _class_call_check$2(instance, Constructor) {
453
451
  if (!(instance instanceof Constructor)) {
454
452
  throw new TypeError('Cannot call a class as a function');
455
453
  }
@@ -469,7 +467,7 @@ function _construct(Parent, args, Class) {
469
467
  }
470
468
  return _construct.apply(null, arguments);
471
469
  }
472
- function _defineProperties$3(target, props) {
470
+ function _defineProperties$2(target, props) {
473
471
  for (var i = 0; i < props.length; i++) {
474
472
  var descriptor = props[i];
475
473
  descriptor.enumerable = descriptor.enumerable || false;
@@ -478,8 +476,8 @@ function _defineProperties$3(target, props) {
478
476
  Object.defineProperty(target, descriptor.key, descriptor);
479
477
  }
480
478
  }
481
- function _create_class$3(Constructor, protoProps, staticProps) {
482
- if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
479
+ function _create_class$2(Constructor, protoProps, staticProps) {
480
+ if (protoProps) _defineProperties$2(Constructor.prototype, protoProps);
483
481
  return Constructor;
484
482
  }
485
483
  function _define_property$1(obj, key, value) {
@@ -579,7 +577,7 @@ function _is_native_reflect_construct() {
579
577
  var PgException = /*#__PURE__*/ (function (Error1) {
580
578
  _inherits(PgException, Error1);
581
579
  function PgException(err, message, specific) {
582
- _class_call_check$3(this, PgException);
580
+ _class_call_check$2(this, PgException);
583
581
  var _this;
584
582
  (_this = _call_super(this, PgException, [message])),
585
583
  _define_property$1(_this, 'err', void 0),
@@ -589,7 +587,7 @@ var PgException = /*#__PURE__*/ (function (Error1) {
589
587
  _this.specific = specific;
590
588
  return _this;
591
589
  }
592
- _create_class$3(PgException, [
590
+ _create_class$2(PgException, [
593
591
  {
594
592
  key: 'getStatus',
595
593
  value: function getStatus() {
@@ -616,152 +614,6 @@ var PgException = /*#__PURE__*/ (function (Error1) {
616
614
  return PgException;
617
615
  })(_wrap_native_super(Error));
618
616
 
619
- function _class_call_check$2(instance, Constructor) {
620
- if (!(instance instanceof Constructor)) {
621
- throw new TypeError('Cannot call a class as a function');
622
- }
623
- }
624
- function _defineProperties$2(target, props) {
625
- for (var i = 0; i < props.length; i++) {
626
- var descriptor = props[i];
627
- descriptor.enumerable = descriptor.enumerable || false;
628
- descriptor.configurable = true;
629
- if ('value' in descriptor) descriptor.writable = true;
630
- Object.defineProperty(target, descriptor.key, descriptor);
631
- }
632
- }
633
- function _create_class$2(Constructor, protoProps, staticProps) {
634
- if (staticProps) _defineProperties$2(Constructor, staticProps);
635
- return Constructor;
636
- }
637
- function _instanceof(left, right) {
638
- if (
639
- right != null &&
640
- typeof Symbol !== 'undefined' &&
641
- right[Symbol.hasInstance]
642
- ) {
643
- return !!right[Symbol.hasInstance](left);
644
- } else {
645
- return left instanceof right;
646
- }
647
- }
648
- var statusMap = {
649
- 100: 'Continue',
650
- 101: 'Switching Protocols',
651
- 102: 'Processing',
652
- 103: 'Early Hints',
653
- 200: 'OK',
654
- 201: 'Created',
655
- 202: 'Accepted',
656
- 203: 'Non-Authoritative Information',
657
- 204: 'No Content',
658
- 205: 'Reset Content',
659
- 206: 'Partial Content',
660
- 300: 'Multiple Choices',
661
- 301: 'Moved Permanently',
662
- 302: 'Found',
663
- 303: 'See Other',
664
- 304: 'Not Modified',
665
- 307: 'Temporary Redirect',
666
- 308: 'Permanent Redirect',
667
- 400: 'Bad Request',
668
- 401: 'Unauthorized',
669
- 402: 'Payment Required',
670
- 403: 'Forbidden',
671
- 404: 'Not Found',
672
- 405: 'Method Not Allowed',
673
- 406: 'Not Acceptable',
674
- 407: 'Proxy Authentication Required',
675
- 408: 'Request Timeout',
676
- 409: 'Conflict',
677
- 410: 'Gone',
678
- 411: 'Length Required',
679
- 412: 'Precondition Failed',
680
- 413: 'Payload Too Large',
681
- 414: 'URI Too Long',
682
- 415: 'Unsupported Media Type',
683
- 416: 'Requested Range Not Satisfiable',
684
- 417: 'Expectation Failed',
685
- 418: "I'm a Teapot",
686
- 421: 'Misdirected Request',
687
- 422: 'Unprocessable Entity',
688
- 424: 'Failed Dependency',
689
- 428: 'Precondition Required',
690
- 429: 'Too Many Requests',
691
- 500: 'Internal Server Error',
692
- 501: 'Not Implemented',
693
- 502: 'Bad Gateway',
694
- 503: 'Service Unavailable',
695
- 504: 'Gateway Timeout',
696
- 505: 'HTTP Version Not Supported',
697
- };
698
- var Exceptions = /*#__PURE__*/ (function () {
699
- function Exceptions() {
700
- _class_call_check$2(this, Exceptions);
701
- }
702
- _create_class$2(Exceptions, null, [
703
- {
704
- key: 'getHttpStatusText',
705
- value: function getHttpStatusText(statusCode) {
706
- var statusText = statusMap[statusCode];
707
- if (!statusText) {
708
- return 'Error';
709
- }
710
- return statusText;
711
- },
712
- },
713
- {
714
- key: 'transformPgError',
715
- value: function transformPgError(error) {
716
- var httpStatus;
717
- var errMsg = null;
718
- switch (error.getStatus()) {
719
- case PostgresError.FOREIGN_KEY_VIOLATION:
720
- httpStatus = HttpStatus.NOT_FOUND;
721
- errMsg = error.getSpecificMessage(
722
- PostgresError.FOREIGN_KEY_VIOLATION
723
- );
724
- break;
725
- case PostgresError.UNIQUE_VIOLATION:
726
- httpStatus = HttpStatus.CONFLICT;
727
- errMsg = error.getSpecificMessage(PostgresError.UNIQUE_VIOLATION);
728
- break;
729
- case PostgresError.INVALID_TEXT_REPRESENTATION:
730
- httpStatus = HttpStatus.BAD_REQUEST;
731
- errMsg = error.getSpecificMessage(
732
- PostgresError.INVALID_TEXT_REPRESENTATION
733
- );
734
- break;
735
- default:
736
- httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;
737
- }
738
- return new NativeException(
739
- httpStatus,
740
- errMsg !== null && errMsg !== void 0 ? errMsg : error.message
741
- );
742
- },
743
- },
744
- {
745
- key: 'toHttpException',
746
- value: function toHttpException(error) {
747
- var _error = error;
748
- if (_instanceof(_error, PgException)) {
749
- _error = this.transformPgError(_error);
750
- }
751
- return new HttpException(
752
- {
753
- status: _error.code,
754
- message: _error.message,
755
- error: this.getHttpStatusText(_error.code),
756
- },
757
- _error.code
758
- );
759
- },
760
- },
761
- ]);
762
- return Exceptions;
763
- })();
764
-
765
617
  function _class_call_check$1(instance, Constructor) {
766
618
  if (!(instance instanceof Constructor)) {
767
619
  throw new TypeError('Cannot call a class as a function');
@@ -928,11 +780,4 @@ var HttpHandler = /*#__PURE__*/ (function () {
928
780
  return HttpHandler;
929
781
  })();
930
782
 
931
- export {
932
- Exceptions,
933
- HttpHandler,
934
- NativeException,
935
- PgException,
936
- PostgresError,
937
- logger,
938
- };
783
+ export { HttpHandler, NativeException, PgException, PostgresError, logger };
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "publishConfig": {
11
11
  "access": "public"
12
12
  },
13
- "version": "1.0.6",
13
+ "version": "1.1.1",
14
14
  "license": "MIT",
15
15
  "private": false,
16
16
  "engines": {
@@ -55,7 +55,6 @@
55
55
  "typescript",
56
56
  "react",
57
57
  "next",
58
- "nest",
59
58
  "utility"
60
59
  ],
61
60
  "release": {
@@ -65,7 +64,6 @@
65
64
  },
66
65
  "dependencies": {},
67
66
  "devDependencies": {
68
- "@nestjs/common": "^10.2.1",
69
67
  "@rollup/plugin-commonjs": "^22.0.2",
70
68
  "@rollup/plugin-json": "^4.1.0",
71
69
  "@rollup/plugin-node-resolve": "^14.0.0",
@@ -87,8 +85,5 @@
87
85
  "rollup-plugin-typescript-paths": "^1.5.0",
88
86
  "ts-node": "^10.9.1",
89
87
  "typescript": "5.6.3"
90
- },
91
- "peerDependencies": {
92
- "@nestjs/common": "^10.2.1"
93
88
  }
94
89
  }