@opra/common 0.16.2 → 0.17.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/cjs/document/constants.js +1 -1
- package/cjs/document/data-type/complex-type.js +69 -56
- package/cjs/document/data-type/simple-type.js +0 -1
- package/cjs/document/resource/collection.js +15 -16
- package/cjs/document/resource/singleton.js +2 -2
- package/cjs/http/http-params.js +10 -11
- package/esm/document/api-document.js +33 -37
- package/esm/document/constants.js +3 -6
- package/esm/document/data-type/api-field.js +12 -15
- package/esm/document/data-type/builtin/any.type.js +5 -8
- package/esm/document/data-type/builtin/base64.type.js +5 -8
- package/esm/document/data-type/builtin/bigint.type.js +5 -8
- package/esm/document/data-type/builtin/boolean.type.js +8 -11
- package/esm/document/data-type/builtin/date.type.js +7 -10
- package/esm/document/data-type/builtin/guid.type.js +9 -12
- package/esm/document/data-type/builtin/index.js +10 -13
- package/esm/document/data-type/builtin/integer.type.js +10 -13
- package/esm/document/data-type/builtin/number.type.js +7 -10
- package/esm/document/data-type/builtin/object.type.js +5 -8
- package/esm/document/data-type/builtin/string.type.js +8 -11
- package/esm/document/data-type/builtin/time.type.js +7 -10
- package/esm/document/data-type/builtin/timestamp.type.js +9 -12
- package/esm/document/data-type/complex-type.js +94 -85
- package/esm/document/data-type/data-type.js +9 -12
- package/esm/document/data-type/enum-type.js +15 -19
- package/esm/document/data-type/mapped-type.js +24 -29
- package/esm/document/data-type/simple-type.js +17 -22
- package/esm/document/data-type/union-type.js +26 -29
- package/esm/document/factory/add-references.js +3 -7
- package/esm/document/factory/create-document.js +10 -16
- package/esm/document/factory/factory.js +33 -37
- package/esm/document/factory/import-resource-class.js +16 -22
- package/esm/document/factory/import-type-class.js +24 -34
- package/esm/document/factory/index.js +1 -4
- package/esm/document/factory/process-resources.js +10 -16
- package/esm/document/factory/process-types.js +31 -37
- package/esm/document/index.js +14 -17
- package/esm/document/resource/collection.js +58 -63
- package/esm/document/resource/resource.js +9 -12
- package/esm/document/resource/singleton.js +27 -31
- package/esm/document/utils/inspect.util.js +4 -7
- package/esm/document/utils/string-compare.util.js +1 -5
- package/esm/exception/enums/issue-severity.enum.js +2 -5
- package/esm/exception/error-issue.js +1 -2
- package/esm/exception/http-errors/bad-request.error.js +4 -8
- package/esm/exception/http-errors/failed-dependency.error.js +4 -8
- package/esm/exception/http-errors/forbidden.error.js +4 -8
- package/esm/exception/http-errors/internal-server.error.js +4 -8
- package/esm/exception/http-errors/method-not-allowed.error.js +4 -8
- package/esm/exception/http-errors/not-acceptable.error.js +4 -8
- package/esm/exception/http-errors/not-found.error.js +4 -8
- package/esm/exception/http-errors/unauthorized.error.js +4 -8
- package/esm/exception/http-errors/unprocessable-entity.error.js +4 -8
- package/esm/exception/index.js +15 -18
- package/esm/exception/opra-exception.js +3 -7
- package/esm/exception/resource-errors/resource-conflict.error.js +4 -8
- package/esm/exception/resource-errors/resource-not-found.error.js +4 -8
- package/esm/exception/wrap-exception.js +20 -24
- package/esm/filter/antlr/OpraFilterLexer.js +6 -9
- package/esm/filter/antlr/OpraFilterListener.js +2 -5
- package/esm/filter/antlr/OpraFilterParser.js +79 -126
- package/esm/filter/antlr/OpraFilterVisitor.js +2 -5
- package/esm/filter/ast/abstract/ast.js +1 -5
- package/esm/filter/ast/abstract/expression.js +2 -6
- package/esm/filter/ast/abstract/literal.js +2 -6
- package/esm/filter/ast/abstract/term.js +2 -6
- package/esm/filter/ast/expressions/arithmetic-expression.js +3 -8
- package/esm/filter/ast/expressions/array-expression.js +2 -6
- package/esm/filter/ast/expressions/comparison-expression.js +2 -6
- package/esm/filter/ast/expressions/logical-expression.js +2 -6
- package/esm/filter/ast/expressions/parentheses-expression.js +2 -6
- package/esm/filter/ast/index.js +16 -19
- package/esm/filter/ast/terms/boolean-literal.js +2 -6
- package/esm/filter/ast/terms/date-literal.js +8 -12
- package/esm/filter/ast/terms/external-constant.js +2 -6
- package/esm/filter/ast/terms/null-literal.js +2 -6
- package/esm/filter/ast/terms/number-literal.js +4 -8
- package/esm/filter/ast/terms/qualified-identifier.js +2 -6
- package/esm/filter/ast/terms/string-literal.js +4 -8
- package/esm/filter/ast/terms/time-literal.js +6 -10
- package/esm/filter/build.js +45 -69
- package/esm/filter/errors.js +3 -9
- package/esm/filter/filter-tree-visitor.js +26 -31
- package/esm/filter/index.js +5 -8
- package/esm/filter/opra-error-listener.js +4 -8
- package/esm/filter/parse.js +14 -19
- package/esm/filter/utils.js +2 -7
- package/esm/helpers/function-utils.js +8 -14
- package/esm/helpers/get-stack-filename.js +1 -5
- package/esm/helpers/index.js +8 -11
- package/esm/helpers/is-url.js +1 -5
- package/esm/helpers/mixin-utils.js +2 -7
- package/esm/helpers/object-utils.js +6 -12
- package/esm/helpers/path-to-object-tree.js +1 -5
- package/esm/helpers/responsive-map.js +1 -5
- package/esm/helpers/type-guards.js +7 -17
- package/esm/http/codecs/boolean-codec.js +1 -5
- package/esm/http/codecs/date-codec.js +1 -5
- package/esm/http/codecs/filter-codec.js +5 -9
- package/esm/http/codecs/integer-codec.js +2 -6
- package/esm/http/codecs/number-codec.js +1 -5
- package/esm/http/codecs/string-codec.js +1 -5
- package/esm/http/enums/http-headers-codes.enum.js +2 -5
- package/esm/http/enums/http-status-codes.enum.js +2 -5
- package/esm/http/enums/http-status-messages.js +1 -4
- package/esm/http/http-headers.js +5 -9
- package/esm/http/http-message.host.js +13 -18
- package/esm/http/http-params.js +30 -36
- package/esm/http/http-request-message.js +18 -22
- package/esm/http/http-response-message.js +23 -28
- package/esm/http/index.js +14 -17
- package/esm/http/interfaces/client-http-headers.interface.js +1 -2
- package/esm/http/interfaces/cookie-options.interface.js +1 -2
- package/esm/http/interfaces/server-http-headers.interface.js +1 -2
- package/esm/i18n/i18n.js +23 -28
- package/esm/i18n/index.js +5 -9
- package/esm/i18n/string-utils.js +2 -7
- package/esm/i18n/translate.js +3 -7
- package/esm/index.js +11 -16
- package/esm/schema/constants.js +1 -4
- package/esm/schema/data-type/complex-type.interface.js +2 -5
- package/esm/schema/data-type/data-type.interface.js +1 -2
- package/esm/schema/data-type/enum-type.interface.js +2 -5
- package/esm/schema/data-type/field.interface.js +1 -2
- package/esm/schema/data-type/mapped-type.interface.js +2 -5
- package/esm/schema/data-type/simple-type.interface.js +2 -5
- package/esm/schema/data-type/union-type.interface.js +2 -5
- package/esm/schema/document.interface.js +1 -2
- package/esm/schema/index.js +31 -34
- package/esm/schema/resource/collection.interface.js +2 -5
- package/esm/schema/resource/container.interface.js +2 -5
- package/esm/schema/resource/endpoint.interface.js +1 -2
- package/esm/schema/resource/resource.interface.js +1 -2
- package/esm/schema/resource/singleton.interface.js +2 -5
- package/esm/schema/type-guards.js +40 -53
- package/esm/types.js +1 -2
- package/esm/url/index.js +5 -8
- package/esm/url/opra-url-path-component.js +3 -7
- package/esm/url/opra-url-path.js +14 -18
- package/esm/url/opra-url.js +15 -19
- package/esm/url/utils/decode-path-component.js +4 -8
- package/esm/url/utils/encode-path-component.js +3 -8
- package/esm/utils/path-utils.js +2 -7
- package/package.json +1 -1
- package/types/document/data-type/complex-type.d.ts +8 -2
- package/types/document/resource/collection.d.ts +5 -3
- package/types/document/resource/singleton.d.ts +3 -1
- package/types/filter/ast/terms/qualified-identifier.d.ts +4 -0
- package/types/http/http-params.d.ts +20 -19
|
@@ -1,32 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const index_js_1 = require("../../helpers/index.js");
|
|
7
|
-
const index_js_2 = require("../../schema/index.js");
|
|
8
|
-
const constants_js_1 = require("../constants.js");
|
|
9
|
-
const resource_js_1 = require("./resource.js");
|
|
1
|
+
import omit from 'lodash.omit';
|
|
2
|
+
import { omitUndefined } from '../../helpers/index.js';
|
|
3
|
+
import { OpraSchema } from '../../schema/index.js';
|
|
4
|
+
import { METADATA_KEY } from '../constants.js';
|
|
5
|
+
import { Resource } from './resource.js';
|
|
10
6
|
const NESTJS_INJECTABLE_WATERMARK = '__injectable__';
|
|
11
7
|
const NAME_PATTERN = /^(.*)(Resource|Singleton)$/;
|
|
12
|
-
|
|
8
|
+
export const Singleton = function (...args) {
|
|
13
9
|
// ClassDecorator
|
|
14
10
|
if (!this) {
|
|
15
11
|
const [type, options] = args;
|
|
16
12
|
return function (target) {
|
|
17
13
|
const name = options?.name || target.name.match(NAME_PATTERN)?.[1] || target.name;
|
|
18
|
-
const metadata = Reflect.getOwnMetadata(
|
|
19
|
-
metadata.kind =
|
|
14
|
+
const metadata = Reflect.getOwnMetadata(METADATA_KEY, target) || {};
|
|
15
|
+
metadata.kind = OpraSchema.Singleton.Kind;
|
|
20
16
|
metadata.name = name;
|
|
21
17
|
metadata.type = type;
|
|
22
18
|
// Merge with previous metadata object
|
|
23
|
-
const m = Reflect.getMetadata(
|
|
19
|
+
const m = Reflect.getMetadata(METADATA_KEY, target);
|
|
24
20
|
if (m && metadata !== m)
|
|
25
|
-
Object.assign(metadata, (
|
|
21
|
+
Object.assign(metadata, omit(m), Object.keys(metadata));
|
|
26
22
|
// Merge options
|
|
27
23
|
if (options)
|
|
28
|
-
Object.assign(metadata, (
|
|
29
|
-
Reflect.defineMetadata(
|
|
24
|
+
Object.assign(metadata, omit(options, ['kind', 'name', 'type', 'controller']));
|
|
25
|
+
Reflect.defineMetadata(METADATA_KEY, metadata, target);
|
|
30
26
|
/* Define Injectable metadata for NestJS support*/
|
|
31
27
|
Reflect.defineMetadata(NESTJS_INJECTABLE_WATERMARK, true, target);
|
|
32
28
|
};
|
|
@@ -34,14 +30,14 @@ exports.Singleton = function (...args) {
|
|
|
34
30
|
// Constructor
|
|
35
31
|
const [document, init] = args;
|
|
36
32
|
// call super()
|
|
37
|
-
|
|
33
|
+
Resource.apply(this, [document, init]);
|
|
38
34
|
};
|
|
39
35
|
const proto = {
|
|
40
36
|
_construct(init) {
|
|
41
37
|
// call super()
|
|
42
|
-
|
|
38
|
+
Resource.prototype._construct.call(this, init);
|
|
43
39
|
const _this = this;
|
|
44
|
-
_this.kind =
|
|
40
|
+
_this.kind = OpraSchema.Singleton.Kind;
|
|
45
41
|
_this.controller = init.controller;
|
|
46
42
|
const operations = _this.operations = init.operations || {};
|
|
47
43
|
_this.type = init.type;
|
|
@@ -60,32 +56,32 @@ const proto = {
|
|
|
60
56
|
}
|
|
61
57
|
},
|
|
62
58
|
exportSchema() {
|
|
63
|
-
const out =
|
|
64
|
-
Object.assign(out,
|
|
59
|
+
const out = Resource.prototype.exportSchema.call(this);
|
|
60
|
+
Object.assign(out, omitUndefined({
|
|
65
61
|
type: this.type.name,
|
|
66
62
|
operations: this.operations
|
|
67
63
|
}));
|
|
68
64
|
return out;
|
|
69
65
|
},
|
|
70
|
-
|
|
71
|
-
return this.type.
|
|
66
|
+
normalizeFieldPath(path) {
|
|
67
|
+
return this.type.normalizeFieldPath(path);
|
|
72
68
|
},
|
|
73
69
|
};
|
|
74
|
-
Object.assign(
|
|
75
|
-
Object.setPrototypeOf(
|
|
70
|
+
Object.assign(Singleton.prototype, proto);
|
|
71
|
+
Object.setPrototypeOf(Singleton.prototype, Resource.prototype);
|
|
76
72
|
function createOperationDecorator(operation) {
|
|
77
73
|
return (options) => ((target, propertyKey) => {
|
|
78
74
|
const metadata = {
|
|
79
75
|
...options,
|
|
80
76
|
handlerName: propertyKey
|
|
81
77
|
};
|
|
82
|
-
const resourceMetadata = (Reflect.getOwnMetadata(
|
|
78
|
+
const resourceMetadata = (Reflect.getOwnMetadata(METADATA_KEY, target.constructor) || {});
|
|
83
79
|
resourceMetadata.operations = resourceMetadata.operations || {};
|
|
84
80
|
resourceMetadata.operations[operation] = metadata;
|
|
85
|
-
Reflect.defineMetadata(
|
|
81
|
+
Reflect.defineMetadata(METADATA_KEY, resourceMetadata, target.constructor);
|
|
86
82
|
});
|
|
87
83
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
84
|
+
Singleton.Create = createOperationDecorator('create');
|
|
85
|
+
Singleton.Get = createOperationDecorator('get');
|
|
86
|
+
Singleton.Delete = createOperationDecorator('delete');
|
|
87
|
+
Singleton.Update = createOperationDecorator('update');
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
exports.colorReset = "\x1b[0m";
|
|
6
|
-
exports.colorFgYellow = "\x1b[33m";
|
|
7
|
-
exports.colorFgMagenta = "\x1b[35m";
|
|
1
|
+
export const nodeInspectCustom = Symbol.for('nodejs.util.inspect.custom');
|
|
2
|
+
export const colorReset = "\x1b[0m";
|
|
3
|
+
export const colorFgYellow = "\x1b[33m";
|
|
4
|
+
export const colorFgMagenta = "\x1b[35m";
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stringCompare = void 0;
|
|
4
|
-
function stringCompare(a, b) {
|
|
1
|
+
export function stringCompare(a, b) {
|
|
5
2
|
if (a < b)
|
|
6
3
|
return -1;
|
|
7
4
|
if (a > b)
|
|
8
5
|
return 1;
|
|
9
6
|
return 0;
|
|
10
7
|
}
|
|
11
|
-
exports.stringCompare = stringCompare;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IssueSeverity = void 0;
|
|
4
|
-
var IssueSeverity;
|
|
1
|
+
export var IssueSeverity;
|
|
5
2
|
(function (IssueSeverity) {
|
|
6
3
|
let Enum;
|
|
7
4
|
(function (Enum) {
|
|
@@ -20,4 +17,4 @@ var IssueSeverity;
|
|
|
20
17
|
'may cause it to be performed suboptimally or in a way that is not as desired',
|
|
21
18
|
info: 'The issue has no relation to the degree of success of the action'
|
|
22
19
|
};
|
|
23
|
-
})(IssueSeverity
|
|
20
|
+
})(IssueSeverity || (IssueSeverity = {}));
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.BadRequestError = void 0;
|
|
4
|
-
const index_js_1 = require("../../i18n/index.js");
|
|
5
|
-
const opra_exception_js_1 = require("../opra-exception.js");
|
|
1
|
+
import { translate } from '../../i18n/index.js';
|
|
2
|
+
import { OpraException } from '../opra-exception.js';
|
|
6
3
|
/**
|
|
7
4
|
* 400 Bad Request
|
|
8
5
|
* The server cannot or will not process the request due to something that is perceived to be a client error
|
|
9
6
|
* (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
|
|
10
7
|
*/
|
|
11
|
-
class BadRequestError extends
|
|
8
|
+
export class BadRequestError extends OpraException {
|
|
12
9
|
constructor() {
|
|
13
10
|
super(...arguments);
|
|
14
11
|
this.status = 400;
|
|
15
12
|
}
|
|
16
13
|
setIssue(issue) {
|
|
17
14
|
super.setIssue({
|
|
18
|
-
message:
|
|
15
|
+
message: translate('error:BAD_REQUEST', 'Bad request'),
|
|
19
16
|
severity: 'error',
|
|
20
17
|
code: 'BAD_REQUEST',
|
|
21
18
|
...issue
|
|
22
19
|
});
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
|
-
exports.BadRequestError = BadRequestError;
|
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.FailedDependencyError = void 0;
|
|
4
|
-
const index_js_1 = require("../../i18n/index.js");
|
|
5
|
-
const opra_exception_js_1 = require("../opra-exception.js");
|
|
1
|
+
import { translate } from '../../i18n/index.js';
|
|
2
|
+
import { OpraException } from '../opra-exception.js';
|
|
6
3
|
/**
|
|
7
4
|
* 424 Failed Dependency
|
|
8
5
|
* The request failed due to failure of a previous request.
|
|
9
6
|
*/
|
|
10
|
-
class FailedDependencyError extends
|
|
7
|
+
export class FailedDependencyError extends OpraException {
|
|
11
8
|
constructor() {
|
|
12
9
|
super(...arguments);
|
|
13
10
|
this.status = 424;
|
|
14
11
|
}
|
|
15
12
|
setIssue(issue) {
|
|
16
13
|
super.setIssue({
|
|
17
|
-
message:
|
|
14
|
+
message: translate('error:FAILED_DEPENDENCY', 'The request failed due to failure of a previous request'),
|
|
18
15
|
severity: 'error',
|
|
19
16
|
code: 'FAILED_DEPENDENCY',
|
|
20
17
|
...issue
|
|
21
18
|
});
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
|
-
exports.FailedDependencyError = FailedDependencyError;
|
|
@@ -1,26 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ForbiddenError = void 0;
|
|
4
|
-
const index_js_1 = require("../../i18n/index.js");
|
|
5
|
-
const opra_exception_js_1 = require("../opra-exception.js");
|
|
1
|
+
import { translate } from '../../i18n/index.js';
|
|
2
|
+
import { OpraException } from '../opra-exception.js';
|
|
6
3
|
/**
|
|
7
4
|
* 403 Forbidden
|
|
8
5
|
* The client does not have access rights to the content; that is, it is unauthorized,
|
|
9
6
|
* so the server is refusing to give the requested resource. Unlike 401 Unauthorized,
|
|
10
7
|
* the client's identity is known to the server.
|
|
11
8
|
*/
|
|
12
|
-
class ForbiddenError extends
|
|
9
|
+
export class ForbiddenError extends OpraException {
|
|
13
10
|
constructor() {
|
|
14
11
|
super(...arguments);
|
|
15
12
|
this.status = 403;
|
|
16
13
|
}
|
|
17
14
|
setIssue(issue) {
|
|
18
15
|
super.setIssue({
|
|
19
|
-
message:
|
|
16
|
+
message: translate('error:FORBIDDEN', 'You are not authorized to perform this action'),
|
|
20
17
|
severity: 'error',
|
|
21
18
|
code: 'FORBIDDEN',
|
|
22
19
|
...issue
|
|
23
20
|
});
|
|
24
21
|
}
|
|
25
22
|
}
|
|
26
|
-
exports.ForbiddenError = ForbiddenError;
|
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.InternalServerError = void 0;
|
|
4
|
-
const index_js_1 = require("../../i18n/index.js");
|
|
5
|
-
const opra_exception_js_1 = require("../opra-exception.js");
|
|
1
|
+
import { translate } from '../../i18n/index.js';
|
|
2
|
+
import { OpraException } from '../opra-exception.js';
|
|
6
3
|
/**
|
|
7
4
|
* 500 Internal Server Error
|
|
8
5
|
* The server has encountered a situation it does not know how to handle.
|
|
9
6
|
*/
|
|
10
|
-
class InternalServerError extends
|
|
7
|
+
export class InternalServerError extends OpraException {
|
|
11
8
|
constructor() {
|
|
12
9
|
super(...arguments);
|
|
13
10
|
this.status = 500;
|
|
14
11
|
}
|
|
15
12
|
setIssue(issue) {
|
|
16
13
|
super.setIssue({
|
|
17
|
-
message:
|
|
14
|
+
message: translate('error:INTERNAL_SERVER_ERROR', 'Internal server error'),
|
|
18
15
|
severity: 'error',
|
|
19
16
|
code: 'INTERNAL_SERVER_ERROR',
|
|
20
17
|
...issue
|
|
21
18
|
});
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
|
-
exports.InternalServerError = InternalServerError;
|
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.MethodNotAllowedError = void 0;
|
|
4
|
-
const index_js_1 = require("../../i18n/index.js");
|
|
5
|
-
const opra_exception_js_1 = require("../opra-exception.js");
|
|
1
|
+
import { translate } from '../../i18n/index.js';
|
|
2
|
+
import { OpraException } from '../opra-exception.js';
|
|
6
3
|
/**
|
|
7
4
|
* 405 Method Not Allowed
|
|
8
5
|
* The request method is known by the server but is not supported by the target resource.
|
|
9
6
|
* For example, an API may not allow calling DELETE to remove a resource.
|
|
10
7
|
*/
|
|
11
|
-
class MethodNotAllowedError extends
|
|
8
|
+
export class MethodNotAllowedError extends OpraException {
|
|
12
9
|
constructor() {
|
|
13
10
|
super(...arguments);
|
|
14
11
|
this.status = 405;
|
|
15
12
|
}
|
|
16
13
|
setIssue(issue) {
|
|
17
14
|
super.setIssue({
|
|
18
|
-
message:
|
|
15
|
+
message: translate('error:METHOD_NOT_ALLOWED', 'Method not allowed'),
|
|
19
16
|
severity: 'error',
|
|
20
17
|
code: 'METHOD_NOT_ALLOWED',
|
|
21
18
|
...issue
|
|
22
19
|
});
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
|
-
exports.MethodNotAllowedError = MethodNotAllowedError;
|
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.NotAcceptableError = void 0;
|
|
4
|
-
const index_js_1 = require("../../i18n/index.js");
|
|
5
|
-
const opra_exception_js_1 = require("../opra-exception.js");
|
|
1
|
+
import { translate } from '../../i18n/index.js';
|
|
2
|
+
import { OpraException } from '../opra-exception.js';
|
|
6
3
|
/**
|
|
7
4
|
* 406 Not Acceptable
|
|
8
5
|
* This response is sent when the web server, after performing server-driven content negotiation,
|
|
9
6
|
* doesn't find any content that conforms to the criteria given by the user agent.
|
|
10
7
|
*/
|
|
11
|
-
class NotAcceptableError extends
|
|
8
|
+
export class NotAcceptableError extends OpraException {
|
|
12
9
|
constructor() {
|
|
13
10
|
super(...arguments);
|
|
14
11
|
this.status = 406;
|
|
15
12
|
}
|
|
16
13
|
setIssue(issue) {
|
|
17
14
|
super.setIssue({
|
|
18
|
-
message:
|
|
15
|
+
message: translate('error:NOT_ACCEPTABLE', 'Not Acceptable'),
|
|
19
16
|
severity: 'error',
|
|
20
17
|
code: 'NOT_ACCEPTABLE',
|
|
21
18
|
...issue
|
|
22
19
|
});
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
|
-
exports.NotAcceptableError = NotAcceptableError;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.NotFoundError = void 0;
|
|
4
|
-
const index_js_1 = require("../../i18n/index.js");
|
|
5
|
-
const opra_exception_js_1 = require("../opra-exception.js");
|
|
1
|
+
import { translate } from '../../i18n/index.js';
|
|
2
|
+
import { OpraException } from '../opra-exception.js';
|
|
6
3
|
/**
|
|
7
4
|
* 404 Not Found
|
|
8
5
|
* The server can not find the requested resource. In the browser, this means the URL is not recognized.
|
|
@@ -11,18 +8,17 @@ const opra_exception_js_1 = require("../opra-exception.js");
|
|
|
11
8
|
* from an unauthorized client. This response code is probably the most well known due to its
|
|
12
9
|
* frequent occurrence on the web.
|
|
13
10
|
*/
|
|
14
|
-
class NotFoundError extends
|
|
11
|
+
export class NotFoundError extends OpraException {
|
|
15
12
|
constructor() {
|
|
16
13
|
super(...arguments);
|
|
17
14
|
this.status = 404;
|
|
18
15
|
}
|
|
19
16
|
setIssue(issue) {
|
|
20
17
|
super.setIssue({
|
|
21
|
-
message:
|
|
18
|
+
message: translate('error:NOT_FOUND', 'Not found'),
|
|
22
19
|
severity: 'error',
|
|
23
20
|
code: 'NOT_FOUND',
|
|
24
21
|
...issue
|
|
25
22
|
});
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
|
-
exports.NotFoundError = NotFoundError;
|
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.UnauthorizedError = void 0;
|
|
4
|
-
const index_js_1 = require("../../i18n/index.js");
|
|
5
|
-
const opra_exception_js_1 = require("../opra-exception.js");
|
|
1
|
+
import { translate } from '../../i18n/index.js';
|
|
2
|
+
import { OpraException } from '../opra-exception.js';
|
|
6
3
|
/**
|
|
7
4
|
* 401 Unauthorized
|
|
8
5
|
* Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated".
|
|
9
6
|
* That is, the client must authenticate itself to get the requested response.
|
|
10
7
|
*/
|
|
11
|
-
class UnauthorizedError extends
|
|
8
|
+
export class UnauthorizedError extends OpraException {
|
|
12
9
|
constructor() {
|
|
13
10
|
super(...arguments);
|
|
14
11
|
this.status = 401;
|
|
15
12
|
}
|
|
16
13
|
setIssue(issue) {
|
|
17
14
|
super.setIssue({
|
|
18
|
-
message:
|
|
15
|
+
message: translate('error:UNAUTHORIZED', 'You have not been authenticated to perform this action'),
|
|
19
16
|
severity: 'error',
|
|
20
17
|
code: 'UNAUTHORIZED',
|
|
21
18
|
...issue
|
|
22
19
|
});
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
|
-
exports.UnauthorizedError = UnauthorizedError;
|
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.UnprocessableEntityError = void 0;
|
|
4
|
-
const index_js_1 = require("../../i18n/index.js");
|
|
5
|
-
const opra_exception_js_1 = require("../opra-exception.js");
|
|
1
|
+
import { translate } from '../../i18n/index.js';
|
|
2
|
+
import { OpraException } from '../opra-exception.js';
|
|
6
3
|
/**
|
|
7
4
|
* 422 Unprocessable Entity
|
|
8
5
|
* The request was well-formed but was unable to be followed due to semantic errors.
|
|
9
6
|
*/
|
|
10
|
-
class UnprocessableEntityError extends
|
|
7
|
+
export class UnprocessableEntityError extends OpraException {
|
|
11
8
|
constructor() {
|
|
12
9
|
super(...arguments);
|
|
13
10
|
this.status = 422;
|
|
14
11
|
}
|
|
15
12
|
setIssue(issue) {
|
|
16
13
|
super.setIssue({
|
|
17
|
-
message:
|
|
14
|
+
message: translate('error:UNPROCESSABLE_ENTITY', 'Unprocessable entity'),
|
|
18
15
|
severity: 'error',
|
|
19
16
|
code: 'UNPROCESSABLE_ENTITY',
|
|
20
17
|
...issue
|
|
21
18
|
});
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
|
-
exports.UnprocessableEntityError = UnprocessableEntityError;
|
package/esm/exception/index.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
tslib_1.__exportStar(require("./http-errors/unprocessable-entity.error.js"), exports);
|
|
17
|
-
tslib_1.__exportStar(require("./resource-errors/resource-conflict.error.js"), exports);
|
|
18
|
-
tslib_1.__exportStar(require("./resource-errors/resource-not-found.error.js"), exports);
|
|
1
|
+
export * from './opra-exception.js';
|
|
2
|
+
export * from './error-issue.js';
|
|
3
|
+
export * from './wrap-exception.js';
|
|
4
|
+
export * from './enums/issue-severity.enum.js';
|
|
5
|
+
export * from './http-errors/bad-request.error.js';
|
|
6
|
+
export * from './http-errors/failed-dependency.error.js';
|
|
7
|
+
export * from './http-errors/forbidden.error.js';
|
|
8
|
+
export * from './http-errors/internal-server.error.js';
|
|
9
|
+
export * from './http-errors/method-not-allowed.error.js';
|
|
10
|
+
export * from './http-errors/not-acceptable.error.js';
|
|
11
|
+
export * from './http-errors/not-found.error.js';
|
|
12
|
+
export * from './http-errors/unauthorized.error.js';
|
|
13
|
+
export * from './http-errors/unprocessable-entity.error.js';
|
|
14
|
+
export * from './resource-errors/resource-conflict.error.js';
|
|
15
|
+
export * from './resource-errors/resource-not-found.error.js';
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpraException = void 0;
|
|
4
|
-
const index_js_1 = require("../i18n/index.js");
|
|
1
|
+
import { i18n } from '../i18n/index.js';
|
|
5
2
|
/**
|
|
6
3
|
* Defines the base Opra exception, which is handled by the default Exceptions Handler.
|
|
7
4
|
*/
|
|
8
|
-
class OpraException extends Error {
|
|
5
|
+
export class OpraException extends Error {
|
|
9
6
|
constructor(issue, cause) {
|
|
10
7
|
super('');
|
|
11
8
|
this.status = 500;
|
|
@@ -18,7 +15,7 @@ class OpraException extends Error {
|
|
|
18
15
|
this._init(issue || cause || 'Unknown error');
|
|
19
16
|
if (issue instanceof Error)
|
|
20
17
|
this.stack = issue.stack;
|
|
21
|
-
this.message =
|
|
18
|
+
this.message = i18n.deep(this.issue.message);
|
|
22
19
|
}
|
|
23
20
|
get issue() {
|
|
24
21
|
return this._issue;
|
|
@@ -53,4 +50,3 @@ class OpraException extends Error {
|
|
|
53
50
|
}
|
|
54
51
|
}
|
|
55
52
|
}
|
|
56
|
-
exports.OpraException = OpraException;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const index_js_1 = require("../../i18n/index.js");
|
|
5
|
-
const opra_exception_js_1 = require("../opra-exception.js");
|
|
6
|
-
class ResourceConflictError extends opra_exception_js_1.OpraException {
|
|
1
|
+
import { translate } from '../../i18n/index.js';
|
|
2
|
+
import { OpraException } from '../opra-exception.js';
|
|
3
|
+
export class ResourceConflictError extends OpraException {
|
|
7
4
|
constructor(resource, fields, cause) {
|
|
8
5
|
super({
|
|
9
|
-
message:
|
|
6
|
+
message: translate(`error:RESOURCE_CONFLICT`, { resource, fields }, `There is already an other {{resource}} resource with same field values ({{fields}})`),
|
|
10
7
|
severity: 'error',
|
|
11
8
|
code: 'RESOURCE_CONFLICT',
|
|
12
9
|
details: {
|
|
@@ -17,4 +14,3 @@ class ResourceConflictError extends opra_exception_js_1.OpraException {
|
|
|
17
14
|
this.status = 409;
|
|
18
15
|
}
|
|
19
16
|
}
|
|
20
|
-
exports.ResourceConflictError = ResourceConflictError;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ResourceNotFoundError = void 0;
|
|
4
|
-
const index_js_1 = require("../../i18n/index.js");
|
|
5
|
-
const opra_exception_js_1 = require("../opra-exception.js");
|
|
1
|
+
import { translate } from '../../i18n/index.js';
|
|
2
|
+
import { OpraException } from '../opra-exception.js';
|
|
6
3
|
/**
|
|
7
4
|
* The server cannot find the requested resource.
|
|
8
5
|
* This can also mean that the endpoint is valid but the resource itself does not exist.
|
|
9
6
|
*/
|
|
10
|
-
class ResourceNotFoundError extends
|
|
7
|
+
export class ResourceNotFoundError extends OpraException {
|
|
11
8
|
constructor(resource, keyValue, cause) {
|
|
12
9
|
super({
|
|
13
|
-
message:
|
|
10
|
+
message: translate(`error:RESOURCE_NOT_FOUND`, { resource: resource + (keyValue ? '@' + keyValue : '') }, `The resource '{{resource}}' could not be found`),
|
|
14
11
|
severity: 'error',
|
|
15
12
|
code: 'RESOURCE_NOT_FOUND',
|
|
16
13
|
details: {
|
|
@@ -21,4 +18,3 @@ class ResourceNotFoundError extends opra_exception_js_1.OpraException {
|
|
|
21
18
|
this.status = 404;
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
|
-
exports.ResourceNotFoundError = ResourceNotFoundError;
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const opra_exception_js_1 = require("./opra-exception.js");
|
|
13
|
-
function wrapException(e) {
|
|
14
|
-
if (e instanceof opra_exception_js_1.OpraException)
|
|
1
|
+
import { BadRequestError } from './http-errors/bad-request.error.js';
|
|
2
|
+
import { FailedDependencyError } from './http-errors/failed-dependency.error.js';
|
|
3
|
+
import { ForbiddenError } from './http-errors/forbidden.error.js';
|
|
4
|
+
import { MethodNotAllowedError } from './http-errors/method-not-allowed.error.js';
|
|
5
|
+
import { NotAcceptableError } from './http-errors/not-acceptable.error.js';
|
|
6
|
+
import { NotFoundError } from './http-errors/not-found.error.js';
|
|
7
|
+
import { UnauthorizedError } from './http-errors/unauthorized.error.js';
|
|
8
|
+
import { UnprocessableEntityError } from './http-errors/unprocessable-entity.error.js';
|
|
9
|
+
import { OpraException } from './opra-exception.js';
|
|
10
|
+
export function wrapException(e) {
|
|
11
|
+
if (e instanceof OpraException)
|
|
15
12
|
return e;
|
|
16
13
|
let status = 500;
|
|
17
14
|
if (typeof e.status === 'number')
|
|
@@ -20,23 +17,22 @@ function wrapException(e) {
|
|
|
20
17
|
status = e.getStatus();
|
|
21
18
|
switch (status) {
|
|
22
19
|
case 400:
|
|
23
|
-
return new
|
|
20
|
+
return new BadRequestError(e);
|
|
24
21
|
case 401:
|
|
25
|
-
return new
|
|
22
|
+
return new UnauthorizedError(e);
|
|
26
23
|
case 403:
|
|
27
|
-
return new
|
|
24
|
+
return new ForbiddenError(e);
|
|
28
25
|
case 404:
|
|
29
|
-
return new
|
|
26
|
+
return new NotFoundError(e);
|
|
30
27
|
case 405:
|
|
31
|
-
return new
|
|
28
|
+
return new MethodNotAllowedError(e);
|
|
32
29
|
case 406:
|
|
33
|
-
return new
|
|
30
|
+
return new NotAcceptableError(e);
|
|
34
31
|
case 422:
|
|
35
|
-
return new
|
|
32
|
+
return new UnprocessableEntityError(e);
|
|
36
33
|
case 424:
|
|
37
|
-
return new
|
|
34
|
+
return new FailedDependencyError(e);
|
|
38
35
|
default:
|
|
39
|
-
return new
|
|
36
|
+
return new FailedDependencyError(e);
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
|
-
exports.wrapException = wrapException;
|