@opra/common 0.23.0 → 0.23.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/browser.js +89 -83
- package/cjs/document/data-type/union-type.js +1 -1
- package/cjs/document/utils/generate-codec.js +1 -1
- package/cjs/exception/http-errors/bad-request.error.js +2 -3
- package/cjs/exception/http-errors/failed-dependency.error.js +2 -3
- package/cjs/exception/http-errors/forbidden.error.js +2 -3
- package/cjs/exception/http-errors/internal-server.error.js +2 -3
- package/cjs/exception/http-errors/method-not-allowed.error.js +2 -3
- package/cjs/exception/http-errors/not-acceptable.error.js +2 -3
- package/cjs/exception/http-errors/not-found.error.js +2 -3
- package/cjs/exception/http-errors/unauthorized.error.js +2 -3
- package/cjs/exception/http-errors/unprocessable-entity.error.js +2 -2
- package/cjs/exception/opra-exception.js +48 -33
- package/cjs/exception/resource-errors/resource-not-found.error.js +1 -2
- package/cjs/exception/wrap-exception.js +16 -16
- package/esm/document/data-type/union-type.js +1 -1
- package/esm/document/utils/generate-codec.js +1 -1
- package/esm/exception/http-errors/bad-request.error.js +2 -3
- package/esm/exception/http-errors/failed-dependency.error.js +2 -3
- package/esm/exception/http-errors/forbidden.error.js +2 -3
- package/esm/exception/http-errors/internal-server.error.js +2 -3
- package/esm/exception/http-errors/method-not-allowed.error.js +2 -3
- package/esm/exception/http-errors/not-acceptable.error.js +2 -3
- package/esm/exception/http-errors/not-found.error.js +2 -3
- package/esm/exception/http-errors/unauthorized.error.js +2 -3
- package/esm/exception/http-errors/unprocessable-entity.error.js +2 -2
- package/esm/exception/opra-exception.js +47 -32
- package/esm/exception/resource-errors/resource-not-found.error.js +1 -2
- package/esm/exception/wrap-exception.js +16 -16
- package/package.json +5 -5
- package/types/document/data-type/complex-type.d.ts +1 -1
- package/types/document/data-type/mapped-type.d.ts +1 -1
- package/types/document/data-type/union-type.d.ts +2 -1
- package/types/document/resource/resource.d.ts +1 -1
- package/types/exception/error-issue.d.ts +2 -1
- package/types/exception/http-errors/bad-request.error.d.ts +2 -1
- package/types/exception/http-errors/failed-dependency.error.d.ts +2 -1
- package/types/exception/http-errors/forbidden.error.d.ts +2 -1
- package/types/exception/http-errors/internal-server.error.d.ts +2 -1
- package/types/exception/http-errors/method-not-allowed.error.d.ts +2 -1
- package/types/exception/http-errors/not-acceptable.error.d.ts +2 -1
- package/types/exception/http-errors/not-found.error.d.ts +2 -1
- package/types/exception/http-errors/unauthorized.error.d.ts +2 -1
- package/types/exception/http-errors/unprocessable-entity.error.d.ts +2 -1
- package/types/exception/opra-exception.d.ts +13 -8
- package/types/exception/wrap-exception.d.ts +1 -1
- package/types/helpers/object-utils.d.ts +1 -1
- package/types/schema/data-type/complex-type.interface.d.ts +1 -1
- package/types/schema/resource/resource.interface.d.ts +0 -1
- package/types/schema/resource/storage.interface.d.ts +1 -1
package/browser.js
CHANGED
|
@@ -18,12 +18,6 @@ var METADATA_KEY = Symbol.for("opra.metadata");
|
|
|
18
18
|
var NAMESPACE_PATTERN = /([A-Z$_]\w+)(?::.+)?/i;
|
|
19
19
|
var TYPENAME_PATTERN = /^(.*)Type(\d*)$/;
|
|
20
20
|
|
|
21
|
-
// ../../build/common/esm/i18n/i18n.js
|
|
22
|
-
import { splitString, tokenize } from "fast-tokenizer";
|
|
23
|
-
import fs from "@browsery/fs";
|
|
24
|
-
import path from "path-browserify";
|
|
25
|
-
import i18next from "@browsery/i18next";
|
|
26
|
-
|
|
27
21
|
// ../../build/common/esm/helpers/function-utils.js
|
|
28
22
|
import promisify from "putil-promisify";
|
|
29
23
|
|
|
@@ -368,6 +362,12 @@ var ResponsiveMap = class extends Map {
|
|
|
368
362
|
}
|
|
369
363
|
};
|
|
370
364
|
|
|
365
|
+
// ../../build/common/esm/i18n/i18n.js
|
|
366
|
+
import { splitString, tokenize } from "fast-tokenizer";
|
|
367
|
+
import fs from "@browsery/fs";
|
|
368
|
+
import path from "path-browserify";
|
|
369
|
+
import i18next from "@browsery/i18next";
|
|
370
|
+
|
|
371
371
|
// ../../build/common/esm/i18n/string-utils.js
|
|
372
372
|
var unescapeRegEx = /\\(.)/g;
|
|
373
373
|
var escapeRegEx = /(\\)/g;
|
|
@@ -548,53 +548,68 @@ var i18n = I18n.createInstance();
|
|
|
548
548
|
i18n.init().catch(() => void 0);
|
|
549
549
|
|
|
550
550
|
// ../../build/common/esm/exception/opra-exception.js
|
|
551
|
+
var inDevelopment = (process.env.NODE_ENV || "").startsWith("dev");
|
|
551
552
|
var OpraException = class extends Error {
|
|
552
553
|
static {
|
|
553
554
|
__name(this, "OpraException");
|
|
554
555
|
}
|
|
555
|
-
constructor(issue,
|
|
556
|
-
super("");
|
|
556
|
+
constructor(issue, arg1, arg2) {
|
|
557
|
+
super("Unknown error");
|
|
557
558
|
this.status = 500;
|
|
558
|
-
|
|
559
|
+
let cause = arg1 && arg1 instanceof Error ? arg1 : void 0;
|
|
560
|
+
this.status = (typeof arg1 === "number" ? arg1 : Number(arg2)) || 500;
|
|
559
561
|
if (issue instanceof Error)
|
|
560
562
|
cause = issue;
|
|
561
|
-
if (cause) {
|
|
563
|
+
if (cause && cause instanceof Error) {
|
|
562
564
|
this.cause = cause;
|
|
563
565
|
if (cause.stack)
|
|
564
566
|
this.stack = cause.stack;
|
|
565
567
|
}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
this._issue = {
|
|
574
|
-
message: "Unknown error",
|
|
575
|
-
severity: "error",
|
|
576
|
-
...issue
|
|
577
|
-
};
|
|
568
|
+
if (typeof issue === "string")
|
|
569
|
+
this.initString(issue);
|
|
570
|
+
else if (issue instanceof Error)
|
|
571
|
+
this.initError(issue);
|
|
572
|
+
else if (issue && typeof issue === "object")
|
|
573
|
+
this.init(issue);
|
|
574
|
+
this.message = this.message || this.constructor.name;
|
|
578
575
|
}
|
|
579
576
|
setStatus(status) {
|
|
580
577
|
this.status = status;
|
|
581
578
|
return this;
|
|
582
579
|
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
580
|
+
toString() {
|
|
581
|
+
return i18n.deep(this.message);
|
|
582
|
+
}
|
|
583
|
+
toJSON() {
|
|
584
|
+
return omitUndefined({
|
|
585
|
+
message: this.message,
|
|
586
|
+
severity: this.severity,
|
|
587
|
+
system: this.system,
|
|
588
|
+
code: this.code,
|
|
589
|
+
details: this.details,
|
|
590
|
+
stack: inDevelopment ? this.stack?.split("\n") : void 0
|
|
591
|
+
}, true);
|
|
592
|
+
}
|
|
593
|
+
init(issue) {
|
|
594
|
+
this.message = issue.message || this.constructor.name;
|
|
595
|
+
this.severity = issue.severity || "error";
|
|
596
|
+
this.system = issue.system;
|
|
597
|
+
this.code = issue.code;
|
|
598
|
+
this.details = issue.details;
|
|
599
|
+
}
|
|
600
|
+
initString(issue) {
|
|
601
|
+
this.message = String(issue || "") || this.constructor.name;
|
|
602
|
+
this.severity = "error";
|
|
603
|
+
this.code = this.constructor.name;
|
|
604
|
+
}
|
|
605
|
+
initError(issue) {
|
|
606
|
+
if (typeof issue.status === "number")
|
|
607
|
+
this.status = issue.status;
|
|
608
|
+
else if (typeof issue.getStatus === "function")
|
|
609
|
+
this.status = issue.getStatus();
|
|
610
|
+
this.message = issue.message;
|
|
611
|
+
this.severity = issue.severity || "error";
|
|
612
|
+
this.code = issue.code || issue.constructor.name;
|
|
598
613
|
}
|
|
599
614
|
};
|
|
600
615
|
|
|
@@ -607,10 +622,9 @@ var BadRequestError = class extends OpraException {
|
|
|
607
622
|
super(...arguments);
|
|
608
623
|
this.status = 400;
|
|
609
624
|
}
|
|
610
|
-
|
|
611
|
-
super.
|
|
625
|
+
init(issue) {
|
|
626
|
+
super.init({
|
|
612
627
|
message: translate("error:BAD_REQUEST", "Bad request"),
|
|
613
|
-
severity: "error",
|
|
614
628
|
code: "BAD_REQUEST",
|
|
615
629
|
...issue
|
|
616
630
|
});
|
|
@@ -626,10 +640,9 @@ var FailedDependencyError = class extends OpraException {
|
|
|
626
640
|
super(...arguments);
|
|
627
641
|
this.status = 424;
|
|
628
642
|
}
|
|
629
|
-
|
|
630
|
-
super.
|
|
643
|
+
init(issue) {
|
|
644
|
+
super.init({
|
|
631
645
|
message: translate("error:FAILED_DEPENDENCY", "The request failed due to failure of a previous request"),
|
|
632
|
-
severity: "error",
|
|
633
646
|
code: "FAILED_DEPENDENCY",
|
|
634
647
|
...issue
|
|
635
648
|
});
|
|
@@ -645,10 +658,9 @@ var ForbiddenError = class extends OpraException {
|
|
|
645
658
|
super(...arguments);
|
|
646
659
|
this.status = 403;
|
|
647
660
|
}
|
|
648
|
-
|
|
649
|
-
super.
|
|
661
|
+
init(issue) {
|
|
662
|
+
super.init({
|
|
650
663
|
message: translate("error:FORBIDDEN", "You are not authorized to perform this action"),
|
|
651
|
-
severity: "error",
|
|
652
664
|
code: "FORBIDDEN",
|
|
653
665
|
...issue
|
|
654
666
|
});
|
|
@@ -664,10 +676,9 @@ var MethodNotAllowedError = class extends OpraException {
|
|
|
664
676
|
super(...arguments);
|
|
665
677
|
this.status = 405;
|
|
666
678
|
}
|
|
667
|
-
|
|
668
|
-
super.
|
|
679
|
+
init(issue) {
|
|
680
|
+
super.init({
|
|
669
681
|
message: translate("error:METHOD_NOT_ALLOWED", "Method not allowed"),
|
|
670
|
-
severity: "error",
|
|
671
682
|
code: "METHOD_NOT_ALLOWED",
|
|
672
683
|
...issue
|
|
673
684
|
});
|
|
@@ -683,10 +694,9 @@ var NotAcceptableError = class extends OpraException {
|
|
|
683
694
|
super(...arguments);
|
|
684
695
|
this.status = 406;
|
|
685
696
|
}
|
|
686
|
-
|
|
687
|
-
super.
|
|
697
|
+
init(issue) {
|
|
698
|
+
super.init({
|
|
688
699
|
message: translate("error:NOT_ACCEPTABLE", "Not Acceptable"),
|
|
689
|
-
severity: "error",
|
|
690
700
|
code: "NOT_ACCEPTABLE",
|
|
691
701
|
...issue
|
|
692
702
|
});
|
|
@@ -702,10 +712,9 @@ var NotFoundError = class extends OpraException {
|
|
|
702
712
|
super(...arguments);
|
|
703
713
|
this.status = 404;
|
|
704
714
|
}
|
|
705
|
-
|
|
706
|
-
super.
|
|
715
|
+
init(issue) {
|
|
716
|
+
super.init({
|
|
707
717
|
message: translate("error:NOT_FOUND", "Not found"),
|
|
708
|
-
severity: "error",
|
|
709
718
|
code: "NOT_FOUND",
|
|
710
719
|
...issue
|
|
711
720
|
});
|
|
@@ -721,10 +730,9 @@ var UnauthorizedError = class extends OpraException {
|
|
|
721
730
|
super(...arguments);
|
|
722
731
|
this.status = 401;
|
|
723
732
|
}
|
|
724
|
-
|
|
725
|
-
super.
|
|
733
|
+
init(issue) {
|
|
734
|
+
super.init({
|
|
726
735
|
message: translate("error:UNAUTHORIZED", "You have not been authenticated to perform this action"),
|
|
727
|
-
severity: "error",
|
|
728
736
|
code: "UNAUTHORIZED",
|
|
729
737
|
...issue
|
|
730
738
|
});
|
|
@@ -740,8 +748,8 @@ var UnprocessableEntityError = class extends OpraException {
|
|
|
740
748
|
super(...arguments);
|
|
741
749
|
this.status = 422;
|
|
742
750
|
}
|
|
743
|
-
|
|
744
|
-
super.
|
|
751
|
+
init(issue) {
|
|
752
|
+
super.init({
|
|
745
753
|
message: translate("error:UNPROCESSABLE_ENTITY", "Unprocessable entity"),
|
|
746
754
|
severity: "error",
|
|
747
755
|
code: "UNPROCESSABLE_ENTITY",
|
|
@@ -751,33 +759,33 @@ var UnprocessableEntityError = class extends OpraException {
|
|
|
751
759
|
};
|
|
752
760
|
|
|
753
761
|
// ../../build/common/esm/exception/wrap-exception.js
|
|
754
|
-
function wrapException(
|
|
755
|
-
if (
|
|
756
|
-
return
|
|
762
|
+
function wrapException(error) {
|
|
763
|
+
if (error instanceof OpraException)
|
|
764
|
+
return error;
|
|
757
765
|
let status = 500;
|
|
758
|
-
if (typeof
|
|
759
|
-
status =
|
|
760
|
-
else if (typeof
|
|
761
|
-
status =
|
|
766
|
+
if (typeof error.status === "number")
|
|
767
|
+
status = error.status;
|
|
768
|
+
else if (typeof error.getStatus === "function")
|
|
769
|
+
status = error.getStatus();
|
|
762
770
|
switch (status) {
|
|
763
771
|
case 400:
|
|
764
|
-
return new BadRequestError(
|
|
772
|
+
return new BadRequestError(error);
|
|
765
773
|
case 401:
|
|
766
|
-
return new UnauthorizedError(
|
|
774
|
+
return new UnauthorizedError(error);
|
|
767
775
|
case 403:
|
|
768
|
-
return new ForbiddenError(
|
|
776
|
+
return new ForbiddenError(error);
|
|
769
777
|
case 404:
|
|
770
|
-
return new NotFoundError(
|
|
778
|
+
return new NotFoundError(error);
|
|
771
779
|
case 405:
|
|
772
|
-
return new MethodNotAllowedError(
|
|
780
|
+
return new MethodNotAllowedError(error);
|
|
773
781
|
case 406:
|
|
774
|
-
return new NotAcceptableError(
|
|
782
|
+
return new NotAcceptableError(error);
|
|
775
783
|
case 422:
|
|
776
|
-
return new UnprocessableEntityError(
|
|
784
|
+
return new UnprocessableEntityError(error);
|
|
777
785
|
case 424:
|
|
778
|
-
return new FailedDependencyError(
|
|
786
|
+
return new FailedDependencyError(error);
|
|
779
787
|
default:
|
|
780
|
-
return new FailedDependencyError(
|
|
788
|
+
return new FailedDependencyError(error);
|
|
781
789
|
}
|
|
782
790
|
}
|
|
783
791
|
__name(wrapException, "wrapException");
|
|
@@ -812,10 +820,9 @@ var InternalServerError = class extends OpraException {
|
|
|
812
820
|
super(...arguments);
|
|
813
821
|
this.status = 500;
|
|
814
822
|
}
|
|
815
|
-
|
|
816
|
-
super.
|
|
823
|
+
init(issue) {
|
|
824
|
+
super.init({
|
|
817
825
|
message: translate("error:INTERNAL_SERVER_ERROR", "Internal server error"),
|
|
818
|
-
severity: "error",
|
|
819
826
|
code: "INTERNAL_SERVER_ERROR",
|
|
820
827
|
...issue
|
|
821
828
|
});
|
|
@@ -855,8 +862,7 @@ var ResourceNotFoundError = class extends OpraException {
|
|
|
855
862
|
resource,
|
|
856
863
|
key: keyValue
|
|
857
864
|
}
|
|
858
|
-
}, cause);
|
|
859
|
-
this.status = 404;
|
|
865
|
+
}, cause, 404);
|
|
860
866
|
}
|
|
861
867
|
};
|
|
862
868
|
|
|
@@ -9726,7 +9732,7 @@ var UnionTypeClass = class extends DataType {
|
|
|
9726
9732
|
throw new TypeError(`${opra_schema_ns_exports.UnionType.Kind} shall contain ${opra_schema_ns_exports.ComplexType.Kind}, ${opra_schema_ns_exports.UnionType.Kind} of ${opra_schema_ns_exports.MappedType.Kind} types.`);
|
|
9727
9733
|
own.types.push(base);
|
|
9728
9734
|
if (base.additionalFields)
|
|
9729
|
-
this.additionalFields =
|
|
9735
|
+
this.additionalFields = base.additionalFields;
|
|
9730
9736
|
this.fields.setAll(base.fields);
|
|
9731
9737
|
}
|
|
9732
9738
|
this.types = [...own.types];
|
|
@@ -9799,7 +9805,7 @@ function _generateDecoder(type, codec, options) {
|
|
|
9799
9805
|
}
|
|
9800
9806
|
return vg3.isObject(schema, {
|
|
9801
9807
|
ctor: type.ctor,
|
|
9802
|
-
additionalFields: type.additionalFields ??
|
|
9808
|
+
additionalFields: type.additionalFields ?? false,
|
|
9803
9809
|
name: type.name,
|
|
9804
9810
|
caseInSensitive: true
|
|
9805
9811
|
});
|
|
@@ -23,7 +23,7 @@ class UnionTypeClass extends data_type_js_1.DataType {
|
|
|
23
23
|
`${index_js_2.OpraSchema.UnionType.Kind} of ${index_js_2.OpraSchema.MappedType.Kind} types.`);
|
|
24
24
|
own.types.push(base);
|
|
25
25
|
if (base.additionalFields)
|
|
26
|
-
this.additionalFields =
|
|
26
|
+
this.additionalFields = base.additionalFields;
|
|
27
27
|
this.fields.setAll(base.fields);
|
|
28
28
|
}
|
|
29
29
|
this.types = [...own.types];
|
|
@@ -31,7 +31,7 @@ function _generateDecoder(type, codec, options) {
|
|
|
31
31
|
}
|
|
32
32
|
return vg.isObject(schema, {
|
|
33
33
|
ctor: type.ctor,
|
|
34
|
-
additionalFields: type.additionalFields ??
|
|
34
|
+
additionalFields: type.additionalFields ?? false,
|
|
35
35
|
name: type.name,
|
|
36
36
|
caseInSensitive: true,
|
|
37
37
|
});
|
|
@@ -13,10 +13,9 @@ class BadRequestError extends opra_exception_js_1.OpraException {
|
|
|
13
13
|
super(...arguments);
|
|
14
14
|
this.status = 400;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
super.
|
|
16
|
+
init(issue) {
|
|
17
|
+
super.init({
|
|
18
18
|
message: (0, index_js_1.translate)('error:BAD_REQUEST', 'Bad request'),
|
|
19
|
-
severity: 'error',
|
|
20
19
|
code: 'BAD_REQUEST',
|
|
21
20
|
...issue
|
|
22
21
|
});
|
|
@@ -12,10 +12,9 @@ class FailedDependencyError extends opra_exception_js_1.OpraException {
|
|
|
12
12
|
super(...arguments);
|
|
13
13
|
this.status = 424;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
super.
|
|
15
|
+
init(issue) {
|
|
16
|
+
super.init({
|
|
17
17
|
message: (0, index_js_1.translate)('error:FAILED_DEPENDENCY', 'The request failed due to failure of a previous request'),
|
|
18
|
-
severity: 'error',
|
|
19
18
|
code: 'FAILED_DEPENDENCY',
|
|
20
19
|
...issue
|
|
21
20
|
});
|
|
@@ -14,10 +14,9 @@ class ForbiddenError extends opra_exception_js_1.OpraException {
|
|
|
14
14
|
super(...arguments);
|
|
15
15
|
this.status = 403;
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
super.
|
|
17
|
+
init(issue) {
|
|
18
|
+
super.init({
|
|
19
19
|
message: (0, index_js_1.translate)('error:FORBIDDEN', 'You are not authorized to perform this action'),
|
|
20
|
-
severity: 'error',
|
|
21
20
|
code: 'FORBIDDEN',
|
|
22
21
|
...issue
|
|
23
22
|
});
|
|
@@ -12,10 +12,9 @@ class InternalServerError extends opra_exception_js_1.OpraException {
|
|
|
12
12
|
super(...arguments);
|
|
13
13
|
this.status = 500;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
super.
|
|
15
|
+
init(issue) {
|
|
16
|
+
super.init({
|
|
17
17
|
message: (0, index_js_1.translate)('error:INTERNAL_SERVER_ERROR', 'Internal server error'),
|
|
18
|
-
severity: 'error',
|
|
19
18
|
code: 'INTERNAL_SERVER_ERROR',
|
|
20
19
|
...issue
|
|
21
20
|
});
|
|
@@ -13,10 +13,9 @@ class MethodNotAllowedError extends opra_exception_js_1.OpraException {
|
|
|
13
13
|
super(...arguments);
|
|
14
14
|
this.status = 405;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
super.
|
|
16
|
+
init(issue) {
|
|
17
|
+
super.init({
|
|
18
18
|
message: (0, index_js_1.translate)('error:METHOD_NOT_ALLOWED', 'Method not allowed'),
|
|
19
|
-
severity: 'error',
|
|
20
19
|
code: 'METHOD_NOT_ALLOWED',
|
|
21
20
|
...issue
|
|
22
21
|
});
|
|
@@ -13,10 +13,9 @@ class NotAcceptableError extends opra_exception_js_1.OpraException {
|
|
|
13
13
|
super(...arguments);
|
|
14
14
|
this.status = 406;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
super.
|
|
16
|
+
init(issue) {
|
|
17
|
+
super.init({
|
|
18
18
|
message: (0, index_js_1.translate)('error:NOT_ACCEPTABLE', 'Not Acceptable'),
|
|
19
|
-
severity: 'error',
|
|
20
19
|
code: 'NOT_ACCEPTABLE',
|
|
21
20
|
...issue
|
|
22
21
|
});
|
|
@@ -16,10 +16,9 @@ class NotFoundError extends opra_exception_js_1.OpraException {
|
|
|
16
16
|
super(...arguments);
|
|
17
17
|
this.status = 404;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
super.
|
|
19
|
+
init(issue) {
|
|
20
|
+
super.init({
|
|
21
21
|
message: (0, index_js_1.translate)('error:NOT_FOUND', 'Not found'),
|
|
22
|
-
severity: 'error',
|
|
23
22
|
code: 'NOT_FOUND',
|
|
24
23
|
...issue
|
|
25
24
|
});
|
|
@@ -13,10 +13,9 @@ class UnauthorizedError extends opra_exception_js_1.OpraException {
|
|
|
13
13
|
super(...arguments);
|
|
14
14
|
this.status = 401;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
super.
|
|
16
|
+
init(issue) {
|
|
17
|
+
super.init({
|
|
18
18
|
message: (0, index_js_1.translate)('error:UNAUTHORIZED', 'You have not been authenticated to perform this action'),
|
|
19
|
-
severity: 'error',
|
|
20
19
|
code: 'UNAUTHORIZED',
|
|
21
20
|
...issue
|
|
22
21
|
});
|
|
@@ -12,8 +12,8 @@ class UnprocessableEntityError extends opra_exception_js_1.OpraException {
|
|
|
12
12
|
super(...arguments);
|
|
13
13
|
this.status = 422;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
super.
|
|
15
|
+
init(issue) {
|
|
16
|
+
super.init({
|
|
17
17
|
message: (0, index_js_1.translate)('error:UNPROCESSABLE_ENTITY', 'Unprocessable entity'),
|
|
18
18
|
severity: 'error',
|
|
19
19
|
code: 'UNPROCESSABLE_ENTITY',
|
|
@@ -1,56 +1,71 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OpraException = void 0;
|
|
4
|
-
const index_js_1 = require("../
|
|
4
|
+
const index_js_1 = require("../helpers/index.js");
|
|
5
|
+
const index_js_2 = require("../i18n/index.js");
|
|
6
|
+
const inDevelopment = (process.env.NODE_ENV || '').startsWith('dev');
|
|
5
7
|
/**
|
|
6
8
|
* Defines the base Opra exception, which is handled by the default Exceptions Handler.
|
|
7
9
|
*/
|
|
8
10
|
class OpraException extends Error {
|
|
9
|
-
constructor(issue,
|
|
10
|
-
super('');
|
|
11
|
+
constructor(issue, arg1, arg2) {
|
|
12
|
+
super('Unknown error');
|
|
11
13
|
this.status = 500;
|
|
12
|
-
|
|
14
|
+
let cause = arg1 && arg1 instanceof Error ? arg1 : undefined;
|
|
15
|
+
this.status = (typeof arg1 === 'number' ? arg1 : Number(arg2)) || 500;
|
|
13
16
|
if (issue instanceof Error)
|
|
14
17
|
cause = issue;
|
|
15
|
-
|
|
18
|
+
// noinspection SuspiciousTypeOfGuard
|
|
19
|
+
if (cause && cause instanceof Error) {
|
|
16
20
|
this.cause = cause;
|
|
17
21
|
if (cause.stack)
|
|
18
22
|
this.stack = cause.stack;
|
|
19
23
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this._issue = {
|
|
28
|
-
message: 'Unknown error',
|
|
29
|
-
severity: 'error',
|
|
30
|
-
...issue,
|
|
31
|
-
};
|
|
24
|
+
if (typeof issue === 'string')
|
|
25
|
+
this.initString(issue);
|
|
26
|
+
else if (issue instanceof Error)
|
|
27
|
+
this.initError(issue);
|
|
28
|
+
else if (issue && typeof issue === 'object')
|
|
29
|
+
this.init(issue);
|
|
30
|
+
this.message = this.message || this.constructor.name;
|
|
32
31
|
}
|
|
33
32
|
setStatus(status) {
|
|
34
33
|
this.status = status;
|
|
35
34
|
return this;
|
|
36
35
|
}
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
toString() {
|
|
37
|
+
return index_js_2.i18n.deep(this.message);
|
|
39
38
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
39
|
+
toJSON() {
|
|
40
|
+
return (0, index_js_1.omitUndefined)({
|
|
41
|
+
message: this.message,
|
|
42
|
+
severity: this.severity,
|
|
43
|
+
system: this.system,
|
|
44
|
+
code: this.code,
|
|
45
|
+
details: this.details,
|
|
46
|
+
stack: inDevelopment ? this.stack?.split('\n') : undefined
|
|
47
|
+
}, true);
|
|
48
|
+
}
|
|
49
|
+
init(issue) {
|
|
50
|
+
this.message = issue.message || this.constructor.name;
|
|
51
|
+
this.severity = issue.severity || 'error';
|
|
52
|
+
this.system = issue.system;
|
|
53
|
+
this.code = issue.code;
|
|
54
|
+
this.details = issue.details;
|
|
55
|
+
}
|
|
56
|
+
initString(issue) {
|
|
57
|
+
this.message = String(issue || '') || this.constructor.name;
|
|
58
|
+
this.severity = 'error';
|
|
59
|
+
this.code = this.constructor.name;
|
|
60
|
+
}
|
|
61
|
+
initError(issue) {
|
|
62
|
+
if (typeof issue.status === 'number')
|
|
63
|
+
this.status = issue.status;
|
|
64
|
+
else if (typeof issue.getStatus === 'function')
|
|
65
|
+
this.status = issue.getStatus();
|
|
66
|
+
this.message = issue.message;
|
|
67
|
+
this.severity = issue.severity || 'error';
|
|
68
|
+
this.code = issue.code || (issue.constructor.name);
|
|
54
69
|
}
|
|
55
70
|
}
|
|
56
71
|
exports.OpraException = OpraException;
|
|
@@ -10,33 +10,33 @@ const not_found_error_js_1 = require("./http-errors/not-found.error.js");
|
|
|
10
10
|
const unauthorized_error_js_1 = require("./http-errors/unauthorized.error.js");
|
|
11
11
|
const unprocessable_entity_error_js_1 = require("./http-errors/unprocessable-entity.error.js");
|
|
12
12
|
const opra_exception_js_1 = require("./opra-exception.js");
|
|
13
|
-
function wrapException(
|
|
14
|
-
if (
|
|
15
|
-
return
|
|
13
|
+
function wrapException(error) {
|
|
14
|
+
if (error instanceof opra_exception_js_1.OpraException)
|
|
15
|
+
return error;
|
|
16
16
|
let status = 500;
|
|
17
|
-
if (typeof
|
|
18
|
-
status =
|
|
19
|
-
else if (typeof
|
|
20
|
-
status =
|
|
17
|
+
if (typeof error.status === 'number')
|
|
18
|
+
status = error.status;
|
|
19
|
+
else if (typeof error.getStatus === 'function')
|
|
20
|
+
status = error.getStatus();
|
|
21
21
|
switch (status) {
|
|
22
22
|
case 400:
|
|
23
|
-
return new bad_request_error_js_1.BadRequestError(
|
|
23
|
+
return new bad_request_error_js_1.BadRequestError(error);
|
|
24
24
|
case 401:
|
|
25
|
-
return new unauthorized_error_js_1.UnauthorizedError(
|
|
25
|
+
return new unauthorized_error_js_1.UnauthorizedError(error);
|
|
26
26
|
case 403:
|
|
27
|
-
return new forbidden_error_js_1.ForbiddenError(
|
|
27
|
+
return new forbidden_error_js_1.ForbiddenError(error);
|
|
28
28
|
case 404:
|
|
29
|
-
return new not_found_error_js_1.NotFoundError(
|
|
29
|
+
return new not_found_error_js_1.NotFoundError(error);
|
|
30
30
|
case 405:
|
|
31
|
-
return new method_not_allowed_error_js_1.MethodNotAllowedError(
|
|
31
|
+
return new method_not_allowed_error_js_1.MethodNotAllowedError(error);
|
|
32
32
|
case 406:
|
|
33
|
-
return new not_acceptable_error_js_1.NotAcceptableError(
|
|
33
|
+
return new not_acceptable_error_js_1.NotAcceptableError(error);
|
|
34
34
|
case 422:
|
|
35
|
-
return new unprocessable_entity_error_js_1.UnprocessableEntityError(
|
|
35
|
+
return new unprocessable_entity_error_js_1.UnprocessableEntityError(error);
|
|
36
36
|
case 424:
|
|
37
|
-
return new failed_dependency_error_js_1.FailedDependencyError(
|
|
37
|
+
return new failed_dependency_error_js_1.FailedDependencyError(error);
|
|
38
38
|
default:
|
|
39
|
-
return new failed_dependency_error_js_1.FailedDependencyError(
|
|
39
|
+
return new failed_dependency_error_js_1.FailedDependencyError(error);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
exports.wrapException = wrapException;
|
|
@@ -19,7 +19,7 @@ class UnionTypeClass extends DataType {
|
|
|
19
19
|
`${OpraSchema.UnionType.Kind} of ${OpraSchema.MappedType.Kind} types.`);
|
|
20
20
|
own.types.push(base);
|
|
21
21
|
if (base.additionalFields)
|
|
22
|
-
this.additionalFields =
|
|
22
|
+
this.additionalFields = base.additionalFields;
|
|
23
23
|
this.fields.setAll(base.fields);
|
|
24
24
|
}
|
|
25
25
|
this.types = [...own.types];
|
|
@@ -26,7 +26,7 @@ export function _generateDecoder(type, codec, options) {
|
|
|
26
26
|
}
|
|
27
27
|
return vg.isObject(schema, {
|
|
28
28
|
ctor: type.ctor,
|
|
29
|
-
additionalFields: type.additionalFields ??
|
|
29
|
+
additionalFields: type.additionalFields ?? false,
|
|
30
30
|
name: type.name,
|
|
31
31
|
caseInSensitive: true,
|
|
32
32
|
});
|
|
@@ -10,10 +10,9 @@ export class BadRequestError extends OpraException {
|
|
|
10
10
|
super(...arguments);
|
|
11
11
|
this.status = 400;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
super.
|
|
13
|
+
init(issue) {
|
|
14
|
+
super.init({
|
|
15
15
|
message: translate('error:BAD_REQUEST', 'Bad request'),
|
|
16
|
-
severity: 'error',
|
|
17
16
|
code: 'BAD_REQUEST',
|
|
18
17
|
...issue
|
|
19
18
|
});
|
|
@@ -9,10 +9,9 @@ export class FailedDependencyError extends OpraException {
|
|
|
9
9
|
super(...arguments);
|
|
10
10
|
this.status = 424;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
super.
|
|
12
|
+
init(issue) {
|
|
13
|
+
super.init({
|
|
14
14
|
message: translate('error:FAILED_DEPENDENCY', 'The request failed due to failure of a previous request'),
|
|
15
|
-
severity: 'error',
|
|
16
15
|
code: 'FAILED_DEPENDENCY',
|
|
17
16
|
...issue
|
|
18
17
|
});
|
|
@@ -11,10 +11,9 @@ export class ForbiddenError extends OpraException {
|
|
|
11
11
|
super(...arguments);
|
|
12
12
|
this.status = 403;
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
super.
|
|
14
|
+
init(issue) {
|
|
15
|
+
super.init({
|
|
16
16
|
message: translate('error:FORBIDDEN', 'You are not authorized to perform this action'),
|
|
17
|
-
severity: 'error',
|
|
18
17
|
code: 'FORBIDDEN',
|
|
19
18
|
...issue
|
|
20
19
|
});
|
|
@@ -9,10 +9,9 @@ export class InternalServerError extends OpraException {
|
|
|
9
9
|
super(...arguments);
|
|
10
10
|
this.status = 500;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
super.
|
|
12
|
+
init(issue) {
|
|
13
|
+
super.init({
|
|
14
14
|
message: translate('error:INTERNAL_SERVER_ERROR', 'Internal server error'),
|
|
15
|
-
severity: 'error',
|
|
16
15
|
code: 'INTERNAL_SERVER_ERROR',
|
|
17
16
|
...issue
|
|
18
17
|
});
|
|
@@ -10,10 +10,9 @@ export class MethodNotAllowedError extends OpraException {
|
|
|
10
10
|
super(...arguments);
|
|
11
11
|
this.status = 405;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
super.
|
|
13
|
+
init(issue) {
|
|
14
|
+
super.init({
|
|
15
15
|
message: translate('error:METHOD_NOT_ALLOWED', 'Method not allowed'),
|
|
16
|
-
severity: 'error',
|
|
17
16
|
code: 'METHOD_NOT_ALLOWED',
|
|
18
17
|
...issue
|
|
19
18
|
});
|
|
@@ -10,10 +10,9 @@ export class NotAcceptableError extends OpraException {
|
|
|
10
10
|
super(...arguments);
|
|
11
11
|
this.status = 406;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
super.
|
|
13
|
+
init(issue) {
|
|
14
|
+
super.init({
|
|
15
15
|
message: translate('error:NOT_ACCEPTABLE', 'Not Acceptable'),
|
|
16
|
-
severity: 'error',
|
|
17
16
|
code: 'NOT_ACCEPTABLE',
|
|
18
17
|
...issue
|
|
19
18
|
});
|
|
@@ -13,10 +13,9 @@ export class NotFoundError extends OpraException {
|
|
|
13
13
|
super(...arguments);
|
|
14
14
|
this.status = 404;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
super.
|
|
16
|
+
init(issue) {
|
|
17
|
+
super.init({
|
|
18
18
|
message: translate('error:NOT_FOUND', 'Not found'),
|
|
19
|
-
severity: 'error',
|
|
20
19
|
code: 'NOT_FOUND',
|
|
21
20
|
...issue
|
|
22
21
|
});
|
|
@@ -10,10 +10,9 @@ export class UnauthorizedError extends OpraException {
|
|
|
10
10
|
super(...arguments);
|
|
11
11
|
this.status = 401;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
super.
|
|
13
|
+
init(issue) {
|
|
14
|
+
super.init({
|
|
15
15
|
message: translate('error:UNAUTHORIZED', 'You have not been authenticated to perform this action'),
|
|
16
|
-
severity: 'error',
|
|
17
16
|
code: 'UNAUTHORIZED',
|
|
18
17
|
...issue
|
|
19
18
|
});
|
|
@@ -9,8 +9,8 @@ export class UnprocessableEntityError extends OpraException {
|
|
|
9
9
|
super(...arguments);
|
|
10
10
|
this.status = 422;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
super.
|
|
12
|
+
init(issue) {
|
|
13
|
+
super.init({
|
|
14
14
|
message: translate('error:UNPROCESSABLE_ENTITY', 'Unprocessable entity'),
|
|
15
15
|
severity: 'error',
|
|
16
16
|
code: 'UNPROCESSABLE_ENTITY',
|
|
@@ -1,52 +1,67 @@
|
|
|
1
|
+
import { omitUndefined } from '../helpers/index.js';
|
|
1
2
|
import { i18n } from '../i18n/index.js';
|
|
3
|
+
const inDevelopment = (process.env.NODE_ENV || '').startsWith('dev');
|
|
2
4
|
/**
|
|
3
5
|
* Defines the base Opra exception, which is handled by the default Exceptions Handler.
|
|
4
6
|
*/
|
|
5
7
|
export class OpraException extends Error {
|
|
6
|
-
constructor(issue,
|
|
7
|
-
super('');
|
|
8
|
+
constructor(issue, arg1, arg2) {
|
|
9
|
+
super('Unknown error');
|
|
8
10
|
this.status = 500;
|
|
9
|
-
|
|
11
|
+
let cause = arg1 && arg1 instanceof Error ? arg1 : undefined;
|
|
12
|
+
this.status = (typeof arg1 === 'number' ? arg1 : Number(arg2)) || 500;
|
|
10
13
|
if (issue instanceof Error)
|
|
11
14
|
cause = issue;
|
|
12
|
-
|
|
15
|
+
// noinspection SuspiciousTypeOfGuard
|
|
16
|
+
if (cause && cause instanceof Error) {
|
|
13
17
|
this.cause = cause;
|
|
14
18
|
if (cause.stack)
|
|
15
19
|
this.stack = cause.stack;
|
|
16
20
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
this._issue = {
|
|
25
|
-
message: 'Unknown error',
|
|
26
|
-
severity: 'error',
|
|
27
|
-
...issue,
|
|
28
|
-
};
|
|
21
|
+
if (typeof issue === 'string')
|
|
22
|
+
this.initString(issue);
|
|
23
|
+
else if (issue instanceof Error)
|
|
24
|
+
this.initError(issue);
|
|
25
|
+
else if (issue && typeof issue === 'object')
|
|
26
|
+
this.init(issue);
|
|
27
|
+
this.message = this.message || this.constructor.name;
|
|
29
28
|
}
|
|
30
29
|
setStatus(status) {
|
|
31
30
|
this.status = status;
|
|
32
31
|
return this;
|
|
33
32
|
}
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
toString() {
|
|
34
|
+
return i18n.deep(this.message);
|
|
36
35
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
36
|
+
toJSON() {
|
|
37
|
+
return omitUndefined({
|
|
38
|
+
message: this.message,
|
|
39
|
+
severity: this.severity,
|
|
40
|
+
system: this.system,
|
|
41
|
+
code: this.code,
|
|
42
|
+
details: this.details,
|
|
43
|
+
stack: inDevelopment ? this.stack?.split('\n') : undefined
|
|
44
|
+
}, true);
|
|
45
|
+
}
|
|
46
|
+
init(issue) {
|
|
47
|
+
this.message = issue.message || this.constructor.name;
|
|
48
|
+
this.severity = issue.severity || 'error';
|
|
49
|
+
this.system = issue.system;
|
|
50
|
+
this.code = issue.code;
|
|
51
|
+
this.details = issue.details;
|
|
52
|
+
}
|
|
53
|
+
initString(issue) {
|
|
54
|
+
this.message = String(issue || '') || this.constructor.name;
|
|
55
|
+
this.severity = 'error';
|
|
56
|
+
this.code = this.constructor.name;
|
|
57
|
+
}
|
|
58
|
+
initError(issue) {
|
|
59
|
+
if (typeof issue.status === 'number')
|
|
60
|
+
this.status = issue.status;
|
|
61
|
+
else if (typeof issue.getStatus === 'function')
|
|
62
|
+
this.status = issue.getStatus();
|
|
63
|
+
this.message = issue.message;
|
|
64
|
+
this.severity = issue.severity || 'error';
|
|
65
|
+
this.code = issue.code || (issue.constructor.name);
|
|
51
66
|
}
|
|
52
67
|
}
|
|
@@ -7,32 +7,32 @@ import { NotFoundError } from './http-errors/not-found.error.js';
|
|
|
7
7
|
import { UnauthorizedError } from './http-errors/unauthorized.error.js';
|
|
8
8
|
import { UnprocessableEntityError } from './http-errors/unprocessable-entity.error.js';
|
|
9
9
|
import { OpraException } from './opra-exception.js';
|
|
10
|
-
export function wrapException(
|
|
11
|
-
if (
|
|
12
|
-
return
|
|
10
|
+
export function wrapException(error) {
|
|
11
|
+
if (error instanceof OpraException)
|
|
12
|
+
return error;
|
|
13
13
|
let status = 500;
|
|
14
|
-
if (typeof
|
|
15
|
-
status =
|
|
16
|
-
else if (typeof
|
|
17
|
-
status =
|
|
14
|
+
if (typeof error.status === 'number')
|
|
15
|
+
status = error.status;
|
|
16
|
+
else if (typeof error.getStatus === 'function')
|
|
17
|
+
status = error.getStatus();
|
|
18
18
|
switch (status) {
|
|
19
19
|
case 400:
|
|
20
|
-
return new BadRequestError(
|
|
20
|
+
return new BadRequestError(error);
|
|
21
21
|
case 401:
|
|
22
|
-
return new UnauthorizedError(
|
|
22
|
+
return new UnauthorizedError(error);
|
|
23
23
|
case 403:
|
|
24
|
-
return new ForbiddenError(
|
|
24
|
+
return new ForbiddenError(error);
|
|
25
25
|
case 404:
|
|
26
|
-
return new NotFoundError(
|
|
26
|
+
return new NotFoundError(error);
|
|
27
27
|
case 405:
|
|
28
|
-
return new MethodNotAllowedError(
|
|
28
|
+
return new MethodNotAllowedError(error);
|
|
29
29
|
case 406:
|
|
30
|
-
return new NotAcceptableError(
|
|
30
|
+
return new NotAcceptableError(error);
|
|
31
31
|
case 422:
|
|
32
|
-
return new UnprocessableEntityError(
|
|
32
|
+
return new UnprocessableEntityError(error);
|
|
33
33
|
case 424:
|
|
34
|
-
return new FailedDependencyError(
|
|
34
|
+
return new FailedDependencyError(error);
|
|
35
35
|
default:
|
|
36
|
-
return new FailedDependencyError(
|
|
36
|
+
return new FailedDependencyError(error);
|
|
37
37
|
}
|
|
38
38
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/common",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.1",
|
|
4
4
|
"description": "Opra common package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,20 +49,20 @@
|
|
|
49
49
|
"lodash.omit": "^4.5.0",
|
|
50
50
|
"putil-isplainobject": "^1.1.5",
|
|
51
51
|
"putil-merge": "^3.10.3",
|
|
52
|
-
"putil-promisify": "^1.10.
|
|
52
|
+
"putil-promisify": "^1.10.1",
|
|
53
53
|
"putil-varhelpers": "^1.6.5",
|
|
54
54
|
"reflect-metadata": "^0.1.13",
|
|
55
55
|
"uid": "^2.0.1",
|
|
56
|
-
"valgen": "^4.0.0
|
|
56
|
+
"valgen": "^4.0.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@browsery/fs": "^0.4.0",
|
|
60
60
|
"@browsery/stream": "^0.5.0",
|
|
61
61
|
"@browsery/util": "^0.4.0",
|
|
62
62
|
"@types/encodeurl": "^1.0.0",
|
|
63
|
-
"@types/validator": "^13.
|
|
63
|
+
"@types/validator": "^13.11.1",
|
|
64
64
|
"path-browserify": "^1.0.1",
|
|
65
|
-
"ts-gems": "^2.4.
|
|
65
|
+
"ts-gems": "^2.4.1"
|
|
66
66
|
},
|
|
67
67
|
"engines": {
|
|
68
68
|
"node": ">=16.0",
|
|
@@ -37,7 +37,7 @@ declare class ComplexTypeClass extends DataType {
|
|
|
37
37
|
readonly own: ComplexType.OwnProperties;
|
|
38
38
|
readonly fields: ResponsiveMap<ApiField>;
|
|
39
39
|
readonly abstract?: boolean;
|
|
40
|
-
readonly additionalFields?: boolean | vg.Validator
|
|
40
|
+
readonly additionalFields?: boolean | vg.Validator | 'error';
|
|
41
41
|
constructor(document: ApiDocument, init: ComplexType.InitArguments);
|
|
42
42
|
addField(init: ApiField.InitArguments): ApiField;
|
|
43
43
|
findField(nameOrPath: string): ApiField | undefined;
|
|
@@ -29,7 +29,7 @@ declare class MappedTypeClass extends DataType {
|
|
|
29
29
|
readonly kind = "MappedType";
|
|
30
30
|
readonly own: MappedType.OwnProperties;
|
|
31
31
|
readonly type: ComplexType;
|
|
32
|
-
readonly additionalFields?: boolean | vg.Validator
|
|
32
|
+
readonly additionalFields?: boolean | vg.Validator | 'error';
|
|
33
33
|
readonly fields: ResponsiveMap<ApiField>;
|
|
34
34
|
readonly omit?: Field.Name[];
|
|
35
35
|
readonly pick?: Field.Name[];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import { Class, StrictOmit, Type } from 'ts-gems';
|
|
3
|
+
import * as vg from 'valgen';
|
|
3
4
|
import { ResponsiveMap } from '../../helpers/index.js';
|
|
4
5
|
import { OpraSchema } from '../../schema/index.js';
|
|
5
6
|
import type { ApiDocument } from '../api-document.js';
|
|
@@ -25,7 +26,7 @@ declare class UnionTypeClass extends DataType {
|
|
|
25
26
|
readonly kind = "UnionType";
|
|
26
27
|
readonly own: UnionType.OwnProperties;
|
|
27
28
|
readonly types: (ComplexType | UnionType | MappedType)[];
|
|
28
|
-
readonly additionalFields?: boolean;
|
|
29
|
+
readonly additionalFields?: boolean | vg.Validator | 'error';
|
|
29
30
|
readonly fields: ResponsiveMap<ApiField>;
|
|
30
31
|
constructor(document: ApiDocument, init: UnionType.InitArguments);
|
|
31
32
|
exportSchema(): OpraSchema.UnionType;
|
|
@@ -3,7 +3,7 @@ import { OpraSchema } from '../../schema/index.js';
|
|
|
3
3
|
import type { ApiDocument } from '../api-document.js';
|
|
4
4
|
import { nodeInspectCustom } from '../utils/inspect.util.js';
|
|
5
5
|
export declare namespace Resource {
|
|
6
|
-
interface InitArguments extends StrictOmit<OpraSchema.ResourceBase, 'kind'
|
|
6
|
+
interface InitArguments extends StrictOmit<OpraSchema.ResourceBase, 'kind'> {
|
|
7
7
|
name: string;
|
|
8
8
|
controller?: object | Type;
|
|
9
9
|
}
|
|
@@ -2,8 +2,9 @@ import { IssueSeverity } from './issue-severity.enum.js';
|
|
|
2
2
|
export interface ErrorIssue {
|
|
3
3
|
message: string;
|
|
4
4
|
severity: IssueSeverity.Type;
|
|
5
|
+
system?: string;
|
|
5
6
|
code?: string;
|
|
6
7
|
details?: any;
|
|
7
8
|
diagnostics?: string | string[];
|
|
8
|
-
|
|
9
|
+
stack?: string[];
|
|
9
10
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ErrorIssue } from '../error-issue.js';
|
|
1
2
|
import { OpraException } from '../opra-exception.js';
|
|
2
3
|
/**
|
|
3
4
|
* 400 Bad Request
|
|
@@ -6,5 +7,5 @@ import { OpraException } from '../opra-exception.js';
|
|
|
6
7
|
*/
|
|
7
8
|
export declare class BadRequestError extends OpraException {
|
|
8
9
|
status: number;
|
|
9
|
-
|
|
10
|
+
protected init(issue: Partial<ErrorIssue>): void;
|
|
10
11
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ErrorIssue } from '../error-issue.js';
|
|
1
2
|
import { OpraException } from '../opra-exception.js';
|
|
2
3
|
/**
|
|
3
4
|
* 424 Failed Dependency
|
|
@@ -5,5 +6,5 @@ import { OpraException } from '../opra-exception.js';
|
|
|
5
6
|
*/
|
|
6
7
|
export declare class FailedDependencyError extends OpraException {
|
|
7
8
|
status: number;
|
|
8
|
-
|
|
9
|
+
protected init(issue: Partial<ErrorIssue>): void;
|
|
9
10
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ErrorIssue } from '../error-issue.js';
|
|
1
2
|
import { OpraException } from '../opra-exception.js';
|
|
2
3
|
/**
|
|
3
4
|
* 403 Forbidden
|
|
@@ -7,5 +8,5 @@ import { OpraException } from '../opra-exception.js';
|
|
|
7
8
|
*/
|
|
8
9
|
export declare class ForbiddenError extends OpraException {
|
|
9
10
|
status: number;
|
|
10
|
-
|
|
11
|
+
protected init(issue: Partial<ErrorIssue>): void;
|
|
11
12
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ErrorIssue } from '../error-issue.js';
|
|
1
2
|
import { OpraException } from '../opra-exception.js';
|
|
2
3
|
/**
|
|
3
4
|
* 500 Internal Server Error
|
|
@@ -5,5 +6,5 @@ import { OpraException } from '../opra-exception.js';
|
|
|
5
6
|
*/
|
|
6
7
|
export declare class InternalServerError extends OpraException {
|
|
7
8
|
status: number;
|
|
8
|
-
|
|
9
|
+
protected init(issue: Partial<ErrorIssue>): void;
|
|
9
10
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ErrorIssue } from '../error-issue.js';
|
|
1
2
|
import { OpraException } from '../opra-exception.js';
|
|
2
3
|
/**
|
|
3
4
|
* 405 Method Not Allowed
|
|
@@ -6,5 +7,5 @@ import { OpraException } from '../opra-exception.js';
|
|
|
6
7
|
*/
|
|
7
8
|
export declare class MethodNotAllowedError extends OpraException {
|
|
8
9
|
status: number;
|
|
9
|
-
|
|
10
|
+
protected init(issue: Partial<ErrorIssue>): void;
|
|
10
11
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ErrorIssue } from '../error-issue.js';
|
|
1
2
|
import { OpraException } from '../opra-exception.js';
|
|
2
3
|
/**
|
|
3
4
|
* 406 Not Acceptable
|
|
@@ -6,5 +7,5 @@ import { OpraException } from '../opra-exception.js';
|
|
|
6
7
|
*/
|
|
7
8
|
export declare class NotAcceptableError extends OpraException {
|
|
8
9
|
status: number;
|
|
9
|
-
|
|
10
|
+
protected init(issue: Partial<ErrorIssue>): void;
|
|
10
11
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ErrorIssue } from '../error-issue.js';
|
|
1
2
|
import { OpraException } from '../opra-exception.js';
|
|
2
3
|
/**
|
|
3
4
|
* 404 Not Found
|
|
@@ -9,5 +10,5 @@ import { OpraException } from '../opra-exception.js';
|
|
|
9
10
|
*/
|
|
10
11
|
export declare class NotFoundError extends OpraException {
|
|
11
12
|
status: number;
|
|
12
|
-
|
|
13
|
+
protected init(issue: Partial<ErrorIssue>): void;
|
|
13
14
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ErrorIssue } from '../error-issue.js';
|
|
1
2
|
import { OpraException } from '../opra-exception.js';
|
|
2
3
|
/**
|
|
3
4
|
* 401 Unauthorized
|
|
@@ -6,5 +7,5 @@ import { OpraException } from '../opra-exception.js';
|
|
|
6
7
|
*/
|
|
7
8
|
export declare class UnauthorizedError extends OpraException {
|
|
8
9
|
status: number;
|
|
9
|
-
|
|
10
|
+
protected init(issue: Partial<ErrorIssue>): void;
|
|
10
11
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ErrorIssue } from '../error-issue.js';
|
|
1
2
|
import { OpraException } from '../opra-exception.js';
|
|
2
3
|
/**
|
|
3
4
|
* 422 Unprocessable Entity
|
|
@@ -5,5 +6,5 @@ import { OpraException } from '../opra-exception.js';
|
|
|
5
6
|
*/
|
|
6
7
|
export declare class UnprocessableEntityError extends OpraException {
|
|
7
8
|
status: number;
|
|
8
|
-
|
|
9
|
+
protected init(issue: Partial<ErrorIssue>): void;
|
|
9
10
|
}
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import { ErrorIssue } from './error-issue.js';
|
|
2
|
+
import { IssueSeverity } from './issue-severity.enum.js';
|
|
2
3
|
/**
|
|
3
4
|
* Defines the base Opra exception, which is handled by the default Exceptions Handler.
|
|
4
5
|
*/
|
|
5
6
|
export declare class OpraException extends Error {
|
|
6
|
-
protected _issue: ErrorIssue;
|
|
7
|
-
status: number;
|
|
8
7
|
cause?: Error;
|
|
8
|
+
status: number;
|
|
9
|
+
severity: IssueSeverity.Type;
|
|
10
|
+
system?: string;
|
|
11
|
+
code?: string;
|
|
12
|
+
details?: any;
|
|
9
13
|
constructor();
|
|
10
|
-
constructor(issue: string | Partial<ErrorIssue> | Error);
|
|
11
|
-
constructor(issue: string | Partial<ErrorIssue>, cause?: Error);
|
|
12
|
-
get issue(): ErrorIssue;
|
|
13
|
-
setIssue(issue: Partial<ErrorIssue>): void;
|
|
14
|
+
constructor(issue: string | Partial<ErrorIssue> | Error, status?: number);
|
|
15
|
+
constructor(issue: string | Partial<ErrorIssue>, cause?: Error, status?: number);
|
|
14
16
|
setStatus(status: number): this;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
toString(): string;
|
|
18
|
+
toJSON(): ErrorIssue;
|
|
19
|
+
protected init(issue: Partial<ErrorIssue>): void;
|
|
20
|
+
protected initString(issue: string): void;
|
|
21
|
+
protected initError(issue: Error): void;
|
|
17
22
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { OpraException } from './opra-exception.js';
|
|
2
|
-
export declare function wrapException(
|
|
2
|
+
export declare function wrapException(error: any): OpraException;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare function cloneObject<T extends {}>(obj: T, jsonOnly?: boolean): T;
|
|
2
|
-
export declare function omitUndefined(obj:
|
|
2
|
+
export declare function omitUndefined<T>(obj: T, recursive?: boolean): T;
|
|
@@ -8,7 +8,7 @@ export interface ComplexType extends DataTypeBase {
|
|
|
8
8
|
base?: DataType.Name | ComplexType | UnionType | MappedType;
|
|
9
9
|
abstract?: boolean;
|
|
10
10
|
fields?: Record<Field.Name, Field | DataType.Name>;
|
|
11
|
-
additionalFields?: boolean;
|
|
11
|
+
additionalFields?: boolean | 'error';
|
|
12
12
|
}
|
|
13
13
|
export declare namespace ComplexType {
|
|
14
14
|
const Kind = "ComplexType";
|