@native-systems/utility 1.0.1 → 1.0.3
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.js +187 -19
- package/dist/index.d.ts +51 -16
- package/dist/index.esm.js +193 -20
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -298,7 +298,7 @@ function _call_super$1(_this, derived, args) {
|
|
|
298
298
|
: derived.apply(_this, args)
|
|
299
299
|
);
|
|
300
300
|
}
|
|
301
|
-
function _class_call_check$
|
|
301
|
+
function _class_call_check$4(instance, Constructor) {
|
|
302
302
|
if (!(instance instanceof Constructor)) {
|
|
303
303
|
throw new TypeError('Cannot call a class as a function');
|
|
304
304
|
}
|
|
@@ -318,7 +318,7 @@ function _construct$1(Parent, args, Class) {
|
|
|
318
318
|
}
|
|
319
319
|
return _construct$1.apply(null, arguments);
|
|
320
320
|
}
|
|
321
|
-
function _define_property$
|
|
321
|
+
function _define_property$2(obj, key, value) {
|
|
322
322
|
if (key in obj) {
|
|
323
323
|
Object.defineProperty(obj, key, {
|
|
324
324
|
value: value,
|
|
@@ -419,10 +419,10 @@ function _is_native_reflect_construct$1() {
|
|
|
419
419
|
var NativeException = /*#__PURE__*/ (function (Error1) {
|
|
420
420
|
_inherits$1(NativeException, Error1);
|
|
421
421
|
function NativeException(code, message) {
|
|
422
|
-
_class_call_check$
|
|
422
|
+
_class_call_check$4(this, NativeException);
|
|
423
423
|
var _this;
|
|
424
424
|
(_this = _call_super$1(this, NativeException, [message])),
|
|
425
|
-
_define_property$
|
|
425
|
+
_define_property$2(_this, 'code', void 0);
|
|
426
426
|
_this.name = 'ShophubError';
|
|
427
427
|
_this.code = code;
|
|
428
428
|
return _this;
|
|
@@ -451,7 +451,7 @@ function _call_super(_this, derived, args) {
|
|
|
451
451
|
: derived.apply(_this, args)
|
|
452
452
|
);
|
|
453
453
|
}
|
|
454
|
-
function _class_call_check$
|
|
454
|
+
function _class_call_check$3(instance, Constructor) {
|
|
455
455
|
if (!(instance instanceof Constructor)) {
|
|
456
456
|
throw new TypeError('Cannot call a class as a function');
|
|
457
457
|
}
|
|
@@ -471,7 +471,7 @@ function _construct(Parent, args, Class) {
|
|
|
471
471
|
}
|
|
472
472
|
return _construct.apply(null, arguments);
|
|
473
473
|
}
|
|
474
|
-
function _defineProperties$
|
|
474
|
+
function _defineProperties$3(target, props) {
|
|
475
475
|
for (var i = 0; i < props.length; i++) {
|
|
476
476
|
var descriptor = props[i];
|
|
477
477
|
descriptor.enumerable = descriptor.enumerable || false;
|
|
@@ -480,11 +480,11 @@ function _defineProperties$1(target, props) {
|
|
|
480
480
|
Object.defineProperty(target, descriptor.key, descriptor);
|
|
481
481
|
}
|
|
482
482
|
}
|
|
483
|
-
function _create_class$
|
|
484
|
-
if (protoProps) _defineProperties$
|
|
483
|
+
function _create_class$3(Constructor, protoProps, staticProps) {
|
|
484
|
+
if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
|
|
485
485
|
return Constructor;
|
|
486
486
|
}
|
|
487
|
-
function _define_property(obj, key, value) {
|
|
487
|
+
function _define_property$1(obj, key, value) {
|
|
488
488
|
if (key in obj) {
|
|
489
489
|
Object.defineProperty(obj, key, {
|
|
490
490
|
value: value,
|
|
@@ -581,17 +581,17 @@ function _is_native_reflect_construct() {
|
|
|
581
581
|
var PgException = /*#__PURE__*/ (function (Error1) {
|
|
582
582
|
_inherits(PgException, Error1);
|
|
583
583
|
function PgException(err, message, specific) {
|
|
584
|
-
_class_call_check$
|
|
584
|
+
_class_call_check$3(this, PgException);
|
|
585
585
|
var _this;
|
|
586
586
|
(_this = _call_super(this, PgException, [message])),
|
|
587
|
-
_define_property(_this, 'err', void 0),
|
|
588
|
-
_define_property(_this, 'specific', void 0);
|
|
587
|
+
_define_property$1(_this, 'err', void 0),
|
|
588
|
+
_define_property$1(_this, 'specific', void 0);
|
|
589
589
|
_this.name = 'PgError';
|
|
590
590
|
_this.err = err;
|
|
591
591
|
_this.specific = specific;
|
|
592
592
|
return _this;
|
|
593
593
|
}
|
|
594
|
-
_create_class$
|
|
594
|
+
_create_class$3(PgException, [
|
|
595
595
|
{
|
|
596
596
|
key: 'getStatus',
|
|
597
597
|
value: function getStatus() {
|
|
@@ -618,12 +618,12 @@ var PgException = /*#__PURE__*/ (function (Error1) {
|
|
|
618
618
|
return PgException;
|
|
619
619
|
})(_wrap_native_super(Error));
|
|
620
620
|
|
|
621
|
-
function _class_call_check(instance, Constructor) {
|
|
621
|
+
function _class_call_check$2(instance, Constructor) {
|
|
622
622
|
if (!(instance instanceof Constructor)) {
|
|
623
623
|
throw new TypeError('Cannot call a class as a function');
|
|
624
624
|
}
|
|
625
625
|
}
|
|
626
|
-
function _defineProperties(target, props) {
|
|
626
|
+
function _defineProperties$2(target, props) {
|
|
627
627
|
for (var i = 0; i < props.length; i++) {
|
|
628
628
|
var descriptor = props[i];
|
|
629
629
|
descriptor.enumerable = descriptor.enumerable || false;
|
|
@@ -632,8 +632,8 @@ function _defineProperties(target, props) {
|
|
|
632
632
|
Object.defineProperty(target, descriptor.key, descriptor);
|
|
633
633
|
}
|
|
634
634
|
}
|
|
635
|
-
function _create_class(Constructor, protoProps, staticProps) {
|
|
636
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
635
|
+
function _create_class$2(Constructor, protoProps, staticProps) {
|
|
636
|
+
if (staticProps) _defineProperties$2(Constructor, staticProps);
|
|
637
637
|
return Constructor;
|
|
638
638
|
}
|
|
639
639
|
function _instanceof(left, right) {
|
|
@@ -699,9 +699,9 @@ var statusMap = {
|
|
|
699
699
|
};
|
|
700
700
|
var Exceptions = /*#__PURE__*/ (function () {
|
|
701
701
|
function Exceptions() {
|
|
702
|
-
_class_call_check(this, Exceptions);
|
|
702
|
+
_class_call_check$2(this, Exceptions);
|
|
703
703
|
}
|
|
704
|
-
_create_class(Exceptions, null, [
|
|
704
|
+
_create_class$2(Exceptions, null, [
|
|
705
705
|
{
|
|
706
706
|
key: 'getHttpStatusText',
|
|
707
707
|
value: function getHttpStatusText(statusCode) {
|
|
@@ -764,7 +764,175 @@ var Exceptions = /*#__PURE__*/ (function () {
|
|
|
764
764
|
return Exceptions;
|
|
765
765
|
})();
|
|
766
766
|
|
|
767
|
+
function _class_call_check$1(instance, Constructor) {
|
|
768
|
+
if (!(instance instanceof Constructor)) {
|
|
769
|
+
throw new TypeError('Cannot call a class as a function');
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
function _defineProperties$1(target, props) {
|
|
773
|
+
for (var i = 0; i < props.length; i++) {
|
|
774
|
+
var descriptor = props[i];
|
|
775
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
776
|
+
descriptor.configurable = true;
|
|
777
|
+
if ('value' in descriptor) descriptor.writable = true;
|
|
778
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
function _create_class$1(Constructor, protoProps, staticProps) {
|
|
782
|
+
if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
|
|
783
|
+
return Constructor;
|
|
784
|
+
}
|
|
785
|
+
function _define_property(obj, key, value) {
|
|
786
|
+
if (key in obj) {
|
|
787
|
+
Object.defineProperty(obj, key, {
|
|
788
|
+
value: value,
|
|
789
|
+
enumerable: true,
|
|
790
|
+
configurable: true,
|
|
791
|
+
writable: true,
|
|
792
|
+
});
|
|
793
|
+
} else {
|
|
794
|
+
obj[key] = value;
|
|
795
|
+
}
|
|
796
|
+
return obj;
|
|
797
|
+
}
|
|
798
|
+
var LOG_LEVEL = 'log';
|
|
799
|
+
var NO_OP = function (_message) {
|
|
800
|
+
for (
|
|
801
|
+
var _len = arguments.length,
|
|
802
|
+
_optionalParams = new Array(_len > 1 ? _len - 1 : 0),
|
|
803
|
+
_key = 1;
|
|
804
|
+
_key < _len;
|
|
805
|
+
_key++
|
|
806
|
+
) {
|
|
807
|
+
_optionalParams[_key - 1] = arguments[_key];
|
|
808
|
+
}
|
|
809
|
+
return undefined;
|
|
810
|
+
};
|
|
811
|
+
var ConsoleLogger = /*#__PURE__*/ (function () {
|
|
812
|
+
function ConsoleLogger(options) {
|
|
813
|
+
_class_call_check$1(this, ConsoleLogger);
|
|
814
|
+
_define_property(this, 'log', void 0);
|
|
815
|
+
_define_property(this, 'warn', void 0);
|
|
816
|
+
_define_property(this, 'error', void 0);
|
|
817
|
+
var level = (options || {}).level;
|
|
818
|
+
this.error = console.error.bind(console);
|
|
819
|
+
this.warn = NO_OP;
|
|
820
|
+
this.log = NO_OP;
|
|
821
|
+
switch (level) {
|
|
822
|
+
case 'warn':
|
|
823
|
+
this.warn = console.warn.bind(console);
|
|
824
|
+
break;
|
|
825
|
+
case 'log':
|
|
826
|
+
this.warn = console.warn.bind(console);
|
|
827
|
+
this.log = console.log.bind(console);
|
|
828
|
+
break;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
_create_class$1(ConsoleLogger, [
|
|
832
|
+
{
|
|
833
|
+
key: 'disable',
|
|
834
|
+
value: function disable() {
|
|
835
|
+
Object.defineProperty(this, 'error', {
|
|
836
|
+
value: NO_OP,
|
|
837
|
+
});
|
|
838
|
+
Object.defineProperty(this, 'warn', {
|
|
839
|
+
value: NO_OP,
|
|
840
|
+
});
|
|
841
|
+
Object.defineProperty(this, 'log', {
|
|
842
|
+
value: NO_OP,
|
|
843
|
+
});
|
|
844
|
+
},
|
|
845
|
+
},
|
|
846
|
+
{
|
|
847
|
+
key: 'enable',
|
|
848
|
+
value: function enable() {
|
|
849
|
+
Object.defineProperty(this, 'error', {
|
|
850
|
+
value: console.error.bind(console),
|
|
851
|
+
});
|
|
852
|
+
Object.defineProperty(this, 'warn', {
|
|
853
|
+
value: console.warn.bind(console),
|
|
854
|
+
});
|
|
855
|
+
Object.defineProperty(this, 'log', {
|
|
856
|
+
value: console.log.bind(console),
|
|
857
|
+
});
|
|
858
|
+
},
|
|
859
|
+
},
|
|
860
|
+
]);
|
|
861
|
+
return ConsoleLogger;
|
|
862
|
+
})();
|
|
863
|
+
var logger = new ConsoleLogger({
|
|
864
|
+
level: LOG_LEVEL,
|
|
865
|
+
});
|
|
866
|
+
|
|
867
|
+
function _class_call_check(instance, Constructor) {
|
|
868
|
+
if (!(instance instanceof Constructor)) {
|
|
869
|
+
throw new TypeError('Cannot call a class as a function');
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
function _defineProperties(target, props) {
|
|
873
|
+
for (var i = 0; i < props.length; i++) {
|
|
874
|
+
var descriptor = props[i];
|
|
875
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
876
|
+
descriptor.configurable = true;
|
|
877
|
+
if ('value' in descriptor) descriptor.writable = true;
|
|
878
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
882
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
883
|
+
return Constructor;
|
|
884
|
+
}
|
|
885
|
+
var HttpHandler = /*#__PURE__*/ (function () {
|
|
886
|
+
function HttpHandler() {
|
|
887
|
+
_class_call_check(this, HttpHandler);
|
|
888
|
+
}
|
|
889
|
+
_create_class(HttpHandler, null, [
|
|
890
|
+
{
|
|
891
|
+
key: 'response',
|
|
892
|
+
value: function response(response) {
|
|
893
|
+
if (response.ok) {
|
|
894
|
+
return response.text().then(function (text) {
|
|
895
|
+
if (!text) {
|
|
896
|
+
return null;
|
|
897
|
+
}
|
|
898
|
+
return JSON.parse(text);
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
var errorResponse = Object.assign(response, {
|
|
902
|
+
isNativeError: true,
|
|
903
|
+
});
|
|
904
|
+
return Promise.reject(errorResponse);
|
|
905
|
+
},
|
|
906
|
+
},
|
|
907
|
+
{
|
|
908
|
+
key: 'error',
|
|
909
|
+
value: function error(response) {
|
|
910
|
+
if ('isNativeError' in response && response.isNativeError) {
|
|
911
|
+
return response.json().then(function (error) {
|
|
912
|
+
logger.error('Request failed:', error.message);
|
|
913
|
+
return Promise.reject(error);
|
|
914
|
+
});
|
|
915
|
+
} else {
|
|
916
|
+
logger.error('Request failed because of a network error.');
|
|
917
|
+
var _response_toString;
|
|
918
|
+
var nativeError = new NativeException(
|
|
919
|
+
500,
|
|
920
|
+
(_response_toString = response.toString()) !== null &&
|
|
921
|
+
_response_toString !== void 0
|
|
922
|
+
? _response_toString
|
|
923
|
+
: 'Request failed for unknown reason. (Network error)'
|
|
924
|
+
);
|
|
925
|
+
return Promise.reject(nativeError);
|
|
926
|
+
}
|
|
927
|
+
},
|
|
928
|
+
},
|
|
929
|
+
]);
|
|
930
|
+
return HttpHandler;
|
|
931
|
+
})();
|
|
932
|
+
|
|
767
933
|
exports.Exceptions = Exceptions;
|
|
934
|
+
exports.HttpHandler = HttpHandler;
|
|
768
935
|
exports.NativeException = NativeException;
|
|
769
936
|
exports.PgException = PgException;
|
|
770
937
|
exports.PostgresError = PostgresError;
|
|
938
|
+
exports.logger = logger;
|
package/dist/index.d.ts
CHANGED
|
@@ -544,7 +544,7 @@ declare module "@native-systems/utility" {
|
|
|
544
544
|
declare module "@native-systems/utility" {
|
|
545
545
|
import { HttpStatus } from "@nestjs/common";
|
|
546
546
|
/**
|
|
547
|
-
* Custom
|
|
547
|
+
* Custom exception object used by Native Systems, which extends the Error interface
|
|
548
548
|
* and adds the 'code' attribute, to be able to provide an additional httpStatus.
|
|
549
549
|
*/
|
|
550
550
|
class NativeException extends Error {
|
|
@@ -609,29 +609,64 @@ declare module "@native-systems/utility" {
|
|
|
609
609
|
}
|
|
610
610
|
|
|
611
611
|
declare module "@native-systems/utility" {
|
|
612
|
-
type
|
|
613
|
-
|
|
614
|
-
message:
|
|
615
|
-
error: string;
|
|
616
|
-
};
|
|
617
|
-
export { Error };
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
declare module "@native-systems/utility" {
|
|
621
|
-
interface ErrorResponse extends Response {
|
|
622
|
-
isNativeError: boolean;
|
|
612
|
+
type LogLevel = 'log' | 'warn' | 'error';
|
|
613
|
+
interface LogFn {
|
|
614
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
623
615
|
}
|
|
624
|
-
export
|
|
616
|
+
export interface Logger {
|
|
617
|
+
log: LogFn;
|
|
618
|
+
warn: LogFn;
|
|
619
|
+
error: LogFn;
|
|
620
|
+
}
|
|
621
|
+
class ConsoleLogger implements Logger {
|
|
622
|
+
readonly log: LogFn;
|
|
623
|
+
readonly warn: LogFn;
|
|
624
|
+
readonly error: LogFn;
|
|
625
|
+
constructor(options?: {
|
|
626
|
+
level?: LogLevel;
|
|
627
|
+
});
|
|
628
|
+
disable(): void;
|
|
629
|
+
enable(): void;
|
|
630
|
+
}
|
|
631
|
+
export const logger: ConsoleLogger;
|
|
625
632
|
}
|
|
626
633
|
|
|
627
634
|
declare module "@native-systems/utility" {
|
|
628
635
|
namespace Native {
|
|
636
|
+
type Error = ErrorConstructor & {
|
|
637
|
+
status: number;
|
|
638
|
+
message: string;
|
|
639
|
+
error: string;
|
|
640
|
+
};
|
|
641
|
+
interface ErrorResponse extends Response {
|
|
642
|
+
isNativeError: boolean;
|
|
643
|
+
}
|
|
629
644
|
export { Error, ErrorResponse };
|
|
630
645
|
}
|
|
631
|
-
export { Native };
|
|
646
|
+
export type { Native };
|
|
632
647
|
}
|
|
633
648
|
|
|
634
649
|
declare module "@native-systems/utility" {
|
|
635
|
-
|
|
636
|
-
|
|
650
|
+
import { Native } from "@/types";
|
|
651
|
+
class HttpHandler {
|
|
652
|
+
/**
|
|
653
|
+
* Http request response handler, which checks if the given response is in status range 'ok'.
|
|
654
|
+
* If this is the case, parse and return the data.
|
|
655
|
+
* If the response is not ok, that means the response was successfully transmitted to the server, but the request failed.
|
|
656
|
+
* This means, that the reason of the error is not a network error for example.
|
|
657
|
+
* @param response {Response} The raw response data from the server, which could also be a Native.Error.
|
|
658
|
+
* @returns {<T>} The expected data resource, if the status of the request is 'ok'.
|
|
659
|
+
* @throws {Native.ErrorResponse} A modified version of the default Response object, to be able to detect if the error response is of the expected type.
|
|
660
|
+
*/
|
|
661
|
+
static response<T>(response: Response): Promise<T>;
|
|
662
|
+
/**
|
|
663
|
+
* Http request error handler, that always returns the correct error object.
|
|
664
|
+
* Either fast forwards the already correctly formatted naive error or set up a new native error, based on the provided info.
|
|
665
|
+
* The generic typing is just used to prevent type errors.
|
|
666
|
+
* @param response {Response | Native.ErrorResponse} The Response object that errored. Can either be a default object, or the modified native version.
|
|
667
|
+
* @throws {Native.Error} Always throws an error, which is always of this type.
|
|
668
|
+
*/
|
|
669
|
+
static error<T>(response: Response | Native.ErrorResponse): Promise<T>;
|
|
670
|
+
}
|
|
671
|
+
export { HttpHandler };
|
|
637
672
|
}
|
package/dist/index.esm.js
CHANGED
|
@@ -296,7 +296,7 @@ function _call_super$1(_this, derived, args) {
|
|
|
296
296
|
: derived.apply(_this, args)
|
|
297
297
|
);
|
|
298
298
|
}
|
|
299
|
-
function _class_call_check$
|
|
299
|
+
function _class_call_check$4(instance, Constructor) {
|
|
300
300
|
if (!(instance instanceof Constructor)) {
|
|
301
301
|
throw new TypeError('Cannot call a class as a function');
|
|
302
302
|
}
|
|
@@ -316,7 +316,7 @@ function _construct$1(Parent, args, Class) {
|
|
|
316
316
|
}
|
|
317
317
|
return _construct$1.apply(null, arguments);
|
|
318
318
|
}
|
|
319
|
-
function _define_property$
|
|
319
|
+
function _define_property$2(obj, key, value) {
|
|
320
320
|
if (key in obj) {
|
|
321
321
|
Object.defineProperty(obj, key, {
|
|
322
322
|
value: value,
|
|
@@ -417,10 +417,10 @@ function _is_native_reflect_construct$1() {
|
|
|
417
417
|
var NativeException = /*#__PURE__*/ (function (Error1) {
|
|
418
418
|
_inherits$1(NativeException, Error1);
|
|
419
419
|
function NativeException(code, message) {
|
|
420
|
-
_class_call_check$
|
|
420
|
+
_class_call_check$4(this, NativeException);
|
|
421
421
|
var _this;
|
|
422
422
|
(_this = _call_super$1(this, NativeException, [message])),
|
|
423
|
-
_define_property$
|
|
423
|
+
_define_property$2(_this, 'code', void 0);
|
|
424
424
|
_this.name = 'ShophubError';
|
|
425
425
|
_this.code = code;
|
|
426
426
|
return _this;
|
|
@@ -449,7 +449,7 @@ function _call_super(_this, derived, args) {
|
|
|
449
449
|
: derived.apply(_this, args)
|
|
450
450
|
);
|
|
451
451
|
}
|
|
452
|
-
function _class_call_check$
|
|
452
|
+
function _class_call_check$3(instance, Constructor) {
|
|
453
453
|
if (!(instance instanceof Constructor)) {
|
|
454
454
|
throw new TypeError('Cannot call a class as a function');
|
|
455
455
|
}
|
|
@@ -469,7 +469,7 @@ function _construct(Parent, args, Class) {
|
|
|
469
469
|
}
|
|
470
470
|
return _construct.apply(null, arguments);
|
|
471
471
|
}
|
|
472
|
-
function _defineProperties$
|
|
472
|
+
function _defineProperties$3(target, props) {
|
|
473
473
|
for (var i = 0; i < props.length; i++) {
|
|
474
474
|
var descriptor = props[i];
|
|
475
475
|
descriptor.enumerable = descriptor.enumerable || false;
|
|
@@ -478,11 +478,11 @@ function _defineProperties$1(target, props) {
|
|
|
478
478
|
Object.defineProperty(target, descriptor.key, descriptor);
|
|
479
479
|
}
|
|
480
480
|
}
|
|
481
|
-
function _create_class$
|
|
482
|
-
if (protoProps) _defineProperties$
|
|
481
|
+
function _create_class$3(Constructor, protoProps, staticProps) {
|
|
482
|
+
if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
|
|
483
483
|
return Constructor;
|
|
484
484
|
}
|
|
485
|
-
function _define_property(obj, key, value) {
|
|
485
|
+
function _define_property$1(obj, key, value) {
|
|
486
486
|
if (key in obj) {
|
|
487
487
|
Object.defineProperty(obj, key, {
|
|
488
488
|
value: value,
|
|
@@ -579,17 +579,17 @@ function _is_native_reflect_construct() {
|
|
|
579
579
|
var PgException = /*#__PURE__*/ (function (Error1) {
|
|
580
580
|
_inherits(PgException, Error1);
|
|
581
581
|
function PgException(err, message, specific) {
|
|
582
|
-
_class_call_check$
|
|
582
|
+
_class_call_check$3(this, PgException);
|
|
583
583
|
var _this;
|
|
584
584
|
(_this = _call_super(this, PgException, [message])),
|
|
585
|
-
_define_property(_this, 'err', void 0),
|
|
586
|
-
_define_property(_this, 'specific', void 0);
|
|
585
|
+
_define_property$1(_this, 'err', void 0),
|
|
586
|
+
_define_property$1(_this, 'specific', void 0);
|
|
587
587
|
_this.name = 'PgError';
|
|
588
588
|
_this.err = err;
|
|
589
589
|
_this.specific = specific;
|
|
590
590
|
return _this;
|
|
591
591
|
}
|
|
592
|
-
_create_class$
|
|
592
|
+
_create_class$3(PgException, [
|
|
593
593
|
{
|
|
594
594
|
key: 'getStatus',
|
|
595
595
|
value: function getStatus() {
|
|
@@ -616,12 +616,12 @@ var PgException = /*#__PURE__*/ (function (Error1) {
|
|
|
616
616
|
return PgException;
|
|
617
617
|
})(_wrap_native_super(Error));
|
|
618
618
|
|
|
619
|
-
function _class_call_check(instance, Constructor) {
|
|
619
|
+
function _class_call_check$2(instance, Constructor) {
|
|
620
620
|
if (!(instance instanceof Constructor)) {
|
|
621
621
|
throw new TypeError('Cannot call a class as a function');
|
|
622
622
|
}
|
|
623
623
|
}
|
|
624
|
-
function _defineProperties(target, props) {
|
|
624
|
+
function _defineProperties$2(target, props) {
|
|
625
625
|
for (var i = 0; i < props.length; i++) {
|
|
626
626
|
var descriptor = props[i];
|
|
627
627
|
descriptor.enumerable = descriptor.enumerable || false;
|
|
@@ -630,8 +630,8 @@ function _defineProperties(target, props) {
|
|
|
630
630
|
Object.defineProperty(target, descriptor.key, descriptor);
|
|
631
631
|
}
|
|
632
632
|
}
|
|
633
|
-
function _create_class(Constructor, protoProps, staticProps) {
|
|
634
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
633
|
+
function _create_class$2(Constructor, protoProps, staticProps) {
|
|
634
|
+
if (staticProps) _defineProperties$2(Constructor, staticProps);
|
|
635
635
|
return Constructor;
|
|
636
636
|
}
|
|
637
637
|
function _instanceof(left, right) {
|
|
@@ -697,9 +697,9 @@ var statusMap = {
|
|
|
697
697
|
};
|
|
698
698
|
var Exceptions = /*#__PURE__*/ (function () {
|
|
699
699
|
function Exceptions() {
|
|
700
|
-
_class_call_check(this, Exceptions);
|
|
700
|
+
_class_call_check$2(this, Exceptions);
|
|
701
701
|
}
|
|
702
|
-
_create_class(Exceptions, null, [
|
|
702
|
+
_create_class$2(Exceptions, null, [
|
|
703
703
|
{
|
|
704
704
|
key: 'getHttpStatusText',
|
|
705
705
|
value: function getHttpStatusText(statusCode) {
|
|
@@ -762,4 +762,177 @@ var Exceptions = /*#__PURE__*/ (function () {
|
|
|
762
762
|
return Exceptions;
|
|
763
763
|
})();
|
|
764
764
|
|
|
765
|
-
|
|
765
|
+
function _class_call_check$1(instance, Constructor) {
|
|
766
|
+
if (!(instance instanceof Constructor)) {
|
|
767
|
+
throw new TypeError('Cannot call a class as a function');
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
function _defineProperties$1(target, props) {
|
|
771
|
+
for (var i = 0; i < props.length; i++) {
|
|
772
|
+
var descriptor = props[i];
|
|
773
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
774
|
+
descriptor.configurable = true;
|
|
775
|
+
if ('value' in descriptor) descriptor.writable = true;
|
|
776
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
function _create_class$1(Constructor, protoProps, staticProps) {
|
|
780
|
+
if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
|
|
781
|
+
return Constructor;
|
|
782
|
+
}
|
|
783
|
+
function _define_property(obj, key, value) {
|
|
784
|
+
if (key in obj) {
|
|
785
|
+
Object.defineProperty(obj, key, {
|
|
786
|
+
value: value,
|
|
787
|
+
enumerable: true,
|
|
788
|
+
configurable: true,
|
|
789
|
+
writable: true,
|
|
790
|
+
});
|
|
791
|
+
} else {
|
|
792
|
+
obj[key] = value;
|
|
793
|
+
}
|
|
794
|
+
return obj;
|
|
795
|
+
}
|
|
796
|
+
var LOG_LEVEL = 'log';
|
|
797
|
+
var NO_OP = function (_message) {
|
|
798
|
+
for (
|
|
799
|
+
var _len = arguments.length,
|
|
800
|
+
_optionalParams = new Array(_len > 1 ? _len - 1 : 0),
|
|
801
|
+
_key = 1;
|
|
802
|
+
_key < _len;
|
|
803
|
+
_key++
|
|
804
|
+
) {
|
|
805
|
+
_optionalParams[_key - 1] = arguments[_key];
|
|
806
|
+
}
|
|
807
|
+
return undefined;
|
|
808
|
+
};
|
|
809
|
+
var ConsoleLogger = /*#__PURE__*/ (function () {
|
|
810
|
+
function ConsoleLogger(options) {
|
|
811
|
+
_class_call_check$1(this, ConsoleLogger);
|
|
812
|
+
_define_property(this, 'log', void 0);
|
|
813
|
+
_define_property(this, 'warn', void 0);
|
|
814
|
+
_define_property(this, 'error', void 0);
|
|
815
|
+
var level = (options || {}).level;
|
|
816
|
+
this.error = console.error.bind(console);
|
|
817
|
+
this.warn = NO_OP;
|
|
818
|
+
this.log = NO_OP;
|
|
819
|
+
switch (level) {
|
|
820
|
+
case 'warn':
|
|
821
|
+
this.warn = console.warn.bind(console);
|
|
822
|
+
break;
|
|
823
|
+
case 'log':
|
|
824
|
+
this.warn = console.warn.bind(console);
|
|
825
|
+
this.log = console.log.bind(console);
|
|
826
|
+
break;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
_create_class$1(ConsoleLogger, [
|
|
830
|
+
{
|
|
831
|
+
key: 'disable',
|
|
832
|
+
value: function disable() {
|
|
833
|
+
Object.defineProperty(this, 'error', {
|
|
834
|
+
value: NO_OP,
|
|
835
|
+
});
|
|
836
|
+
Object.defineProperty(this, 'warn', {
|
|
837
|
+
value: NO_OP,
|
|
838
|
+
});
|
|
839
|
+
Object.defineProperty(this, 'log', {
|
|
840
|
+
value: NO_OP,
|
|
841
|
+
});
|
|
842
|
+
},
|
|
843
|
+
},
|
|
844
|
+
{
|
|
845
|
+
key: 'enable',
|
|
846
|
+
value: function enable() {
|
|
847
|
+
Object.defineProperty(this, 'error', {
|
|
848
|
+
value: console.error.bind(console),
|
|
849
|
+
});
|
|
850
|
+
Object.defineProperty(this, 'warn', {
|
|
851
|
+
value: console.warn.bind(console),
|
|
852
|
+
});
|
|
853
|
+
Object.defineProperty(this, 'log', {
|
|
854
|
+
value: console.log.bind(console),
|
|
855
|
+
});
|
|
856
|
+
},
|
|
857
|
+
},
|
|
858
|
+
]);
|
|
859
|
+
return ConsoleLogger;
|
|
860
|
+
})();
|
|
861
|
+
var logger = new ConsoleLogger({
|
|
862
|
+
level: LOG_LEVEL,
|
|
863
|
+
});
|
|
864
|
+
|
|
865
|
+
function _class_call_check(instance, Constructor) {
|
|
866
|
+
if (!(instance instanceof Constructor)) {
|
|
867
|
+
throw new TypeError('Cannot call a class as a function');
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
function _defineProperties(target, props) {
|
|
871
|
+
for (var i = 0; i < props.length; i++) {
|
|
872
|
+
var descriptor = props[i];
|
|
873
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
874
|
+
descriptor.configurable = true;
|
|
875
|
+
if ('value' in descriptor) descriptor.writable = true;
|
|
876
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
880
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
881
|
+
return Constructor;
|
|
882
|
+
}
|
|
883
|
+
var HttpHandler = /*#__PURE__*/ (function () {
|
|
884
|
+
function HttpHandler() {
|
|
885
|
+
_class_call_check(this, HttpHandler);
|
|
886
|
+
}
|
|
887
|
+
_create_class(HttpHandler, null, [
|
|
888
|
+
{
|
|
889
|
+
key: 'response',
|
|
890
|
+
value: function response(response) {
|
|
891
|
+
if (response.ok) {
|
|
892
|
+
return response.text().then(function (text) {
|
|
893
|
+
if (!text) {
|
|
894
|
+
return null;
|
|
895
|
+
}
|
|
896
|
+
return JSON.parse(text);
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
var errorResponse = Object.assign(response, {
|
|
900
|
+
isNativeError: true,
|
|
901
|
+
});
|
|
902
|
+
return Promise.reject(errorResponse);
|
|
903
|
+
},
|
|
904
|
+
},
|
|
905
|
+
{
|
|
906
|
+
key: 'error',
|
|
907
|
+
value: function error(response) {
|
|
908
|
+
if ('isNativeError' in response && response.isNativeError) {
|
|
909
|
+
return response.json().then(function (error) {
|
|
910
|
+
logger.error('Request failed:', error.message);
|
|
911
|
+
return Promise.reject(error);
|
|
912
|
+
});
|
|
913
|
+
} else {
|
|
914
|
+
logger.error('Request failed because of a network error.');
|
|
915
|
+
var _response_toString;
|
|
916
|
+
var nativeError = new NativeException(
|
|
917
|
+
500,
|
|
918
|
+
(_response_toString = response.toString()) !== null &&
|
|
919
|
+
_response_toString !== void 0
|
|
920
|
+
? _response_toString
|
|
921
|
+
: 'Request failed for unknown reason. (Network error)'
|
|
922
|
+
);
|
|
923
|
+
return Promise.reject(nativeError);
|
|
924
|
+
}
|
|
925
|
+
},
|
|
926
|
+
},
|
|
927
|
+
]);
|
|
928
|
+
return HttpHandler;
|
|
929
|
+
})();
|
|
930
|
+
|
|
931
|
+
export {
|
|
932
|
+
Exceptions,
|
|
933
|
+
HttpHandler,
|
|
934
|
+
NativeException,
|
|
935
|
+
PgException,
|
|
936
|
+
PostgresError,
|
|
937
|
+
logger,
|
|
938
|
+
};
|