@opra/core 0.1.0 → 0.2.0
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/enums/http-headers.enum.js +3 -2
- package/cjs/implementation/adapter-utils/entity-resource-execute.util.js +36 -34
- package/cjs/implementation/adapter-utils/resource-prepare.util.js +1 -1
- package/cjs/implementation/adapter.js +14 -19
- package/cjs/implementation/express-adapter.js +3 -0
- package/cjs/implementation/headers-map.js +18 -0
- package/cjs/implementation/http-adapter.js +65 -79
- package/cjs/implementation/query-context.js +12 -19
- package/cjs/index.js +0 -2
- package/cjs/services/json-data-service.js +367 -131
- package/cjs/utils/path-to-tree.js +7 -5
- package/esm/enums/http-headers.enum.d.ts +3 -2
- package/esm/enums/http-headers.enum.js +3 -2
- package/esm/implementation/adapter-utils/entity-resource-execute.util.js +35 -33
- package/esm/implementation/adapter-utils/resource-execute.util.d.ts +2 -2
- package/esm/implementation/adapter-utils/resource-prepare.util.d.ts +2 -2
- package/esm/implementation/adapter-utils/resource-prepare.util.js +1 -1
- package/esm/implementation/adapter.d.ts +2 -2
- package/esm/implementation/adapter.js +12 -17
- package/esm/implementation/express-adapter.js +2 -0
- package/esm/implementation/headers-map.d.ts +5 -0
- package/esm/implementation/headers-map.js +14 -0
- package/esm/implementation/http-adapter.d.ts +6 -6
- package/esm/implementation/http-adapter.js +61 -75
- package/esm/implementation/query-context.d.ts +9 -15
- package/esm/implementation/query-context.js +11 -17
- package/esm/index.d.ts +0 -2
- package/esm/index.js +0 -2
- package/esm/interfaces/entity-service.interface.d.ts +8 -6
- package/esm/services/json-data-service.d.ts +56 -39
- package/esm/services/json-data-service.js +365 -129
- package/esm/types.d.ts +0 -3
- package/esm/utils/path-to-tree.d.ts +1 -1
- package/esm/utils/path-to-tree.js +7 -5
- package/i18n/en/error.json +5 -5
- package/package.json +11 -8
- package/cjs/exception/api-exception.js +0 -68
- package/cjs/exception/http-errors/bad-request.error.js +0 -26
- package/cjs/exception/http-errors/failed-dependency.error.js +0 -25
- package/cjs/exception/http-errors/forbidden.error.js +0 -27
- package/cjs/exception/http-errors/internal-server.error.js +0 -27
- package/cjs/exception/http-errors/method-not-allowed.error.js +0 -26
- package/cjs/exception/http-errors/not-acceptable.error.js +0 -26
- package/cjs/exception/http-errors/not-found.error.js +0 -29
- package/cjs/exception/http-errors/unauthorized.error.js +0 -26
- package/cjs/exception/http-errors/unprocessable-entity.error.js +0 -25
- package/cjs/exception/index.js +0 -15
- package/cjs/exception/resource-errors/resource-conflict.error.js +0 -19
- package/cjs/exception/resource-errors/resource-not-found.error.js +0 -19
- package/cjs/exception/wrap-error.js +0 -17
- package/cjs/interfaces/query.interface.js +0 -207
- package/esm/exception/api-exception.d.ts +0 -40
- package/esm/exception/api-exception.js +0 -64
- package/esm/exception/http-errors/bad-request.error.d.ts +0 -10
- package/esm/exception/http-errors/bad-request.error.js +0 -22
- package/esm/exception/http-errors/failed-dependency.error.d.ts +0 -9
- package/esm/exception/http-errors/failed-dependency.error.js +0 -21
- package/esm/exception/http-errors/forbidden.error.d.ts +0 -11
- package/esm/exception/http-errors/forbidden.error.js +0 -23
- package/esm/exception/http-errors/internal-server.error.d.ts +0 -9
- package/esm/exception/http-errors/internal-server.error.js +0 -22
- package/esm/exception/http-errors/method-not-allowed.error.d.ts +0 -10
- package/esm/exception/http-errors/method-not-allowed.error.js +0 -22
- package/esm/exception/http-errors/not-acceptable.error.d.ts +0 -10
- package/esm/exception/http-errors/not-acceptable.error.js +0 -22
- package/esm/exception/http-errors/not-found.error.d.ts +0 -13
- package/esm/exception/http-errors/not-found.error.js +0 -25
- package/esm/exception/http-errors/unauthorized.error.d.ts +0 -10
- package/esm/exception/http-errors/unauthorized.error.js +0 -22
- package/esm/exception/http-errors/unprocessable-entity.error.d.ts +0 -9
- package/esm/exception/http-errors/unprocessable-entity.error.js +0 -21
- package/esm/exception/index.d.ts +0 -12
- package/esm/exception/index.js +0 -12
- package/esm/exception/resource-errors/resource-conflict.error.d.ts +0 -4
- package/esm/exception/resource-errors/resource-conflict.error.js +0 -15
- package/esm/exception/resource-errors/resource-not-found.error.d.ts +0 -4
- package/esm/exception/resource-errors/resource-not-found.error.js +0 -15
- package/esm/exception/wrap-error.d.ts +0 -2
- package/esm/exception/wrap-error.js +0 -13
- package/esm/interfaces/query.interface.d.ts +0 -115
- package/esm/interfaces/query.interface.js +0 -203
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Opra schema package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,21 +27,24 @@
|
|
|
27
27
|
"clean:cover": "rimraf ../../coverage/core"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@opra/
|
|
31
|
-
"@opra/
|
|
32
|
-
"@opra/
|
|
33
|
-
"@opra/
|
|
30
|
+
"@opra/exception": "^0.2.0",
|
|
31
|
+
"@opra/i18n": "^0.2.0",
|
|
32
|
+
"@opra/optionals": "^0.2.0",
|
|
33
|
+
"@opra/schema": "^0.2.0",
|
|
34
|
+
"@opra/url": "^0.2.0",
|
|
35
|
+
"@nano-sql/core": "^2.3.7",
|
|
36
|
+
"express": "^4.18.1",
|
|
37
|
+
"body-parser": "^1.20.1",
|
|
34
38
|
"lodash": "^4.17.21",
|
|
35
39
|
"putil-isplainobject": "^1.1.4",
|
|
36
40
|
"putil-varhelpers": "^1.6.4",
|
|
37
41
|
"putil-merge": "^3.9.0",
|
|
38
|
-
"rule-judgment": "^1.1.5",
|
|
39
42
|
"strict-typed-events": "^2.2.0",
|
|
40
43
|
"ts-gems": "^2.2.0"
|
|
41
44
|
},
|
|
42
45
|
"devDependencies": {
|
|
43
46
|
"@types/express": "^4.17.14",
|
|
44
|
-
"
|
|
47
|
+
"@faker-js/faker": "^7.5.0"
|
|
45
48
|
},
|
|
46
49
|
"type": "module",
|
|
47
50
|
"types": "esm/index.d.ts",
|
|
@@ -76,4 +79,4 @@
|
|
|
76
79
|
"http",
|
|
77
80
|
"web"
|
|
78
81
|
]
|
|
79
|
-
}
|
|
82
|
+
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApiException = void 0;
|
|
4
|
-
const index_js_1 = require("../enums/index.js");
|
|
5
|
-
/**
|
|
6
|
-
* Defines the base Opra exception, which is handled by the default Exceptions Handler.
|
|
7
|
-
*/
|
|
8
|
-
class ApiException extends Error {
|
|
9
|
-
static stackAsDiagnostics = false;
|
|
10
|
-
response;
|
|
11
|
-
status;
|
|
12
|
-
cause;
|
|
13
|
-
constructor(response, cause) {
|
|
14
|
-
super('');
|
|
15
|
-
this._initName();
|
|
16
|
-
this.status = index_js_1.HttpStatus.INTERNAL_SERVER_ERROR;
|
|
17
|
-
cause = cause || (response instanceof Error ? response : undefined);
|
|
18
|
-
if (cause)
|
|
19
|
-
Object.defineProperty(this, 'cause', { enumerable: false, configurable: true, writable: true, value: cause });
|
|
20
|
-
if (response instanceof Error)
|
|
21
|
-
this._initErrorInstance(response);
|
|
22
|
-
else if (typeof response === 'string')
|
|
23
|
-
this._initResponse({ message: response });
|
|
24
|
-
else
|
|
25
|
-
this._initResponse(response);
|
|
26
|
-
if (!this.response.severity)
|
|
27
|
-
if (this.status >= 500)
|
|
28
|
-
this.response.severity = 'fatal';
|
|
29
|
-
else
|
|
30
|
-
this.response.severity = 'error';
|
|
31
|
-
if (this.cause instanceof Error && this.cause.stack) {
|
|
32
|
-
if (ApiException.stackAsDiagnostics)
|
|
33
|
-
this.response.diagnostics = this.cause.stack.split('\n');
|
|
34
|
-
this.stack = this.cause.stack;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
setStatus(status) {
|
|
38
|
-
this.status = status;
|
|
39
|
-
return this;
|
|
40
|
-
}
|
|
41
|
-
_initName() {
|
|
42
|
-
this.name = this.constructor.name;
|
|
43
|
-
}
|
|
44
|
-
_initErrorInstance(init) {
|
|
45
|
-
this._initResponse({
|
|
46
|
-
message: init.message
|
|
47
|
-
});
|
|
48
|
-
if (typeof init.status === 'number')
|
|
49
|
-
this.setStatus(init.status);
|
|
50
|
-
else if (typeof init.getStatus === 'function')
|
|
51
|
-
this.setStatus(init.getStatus());
|
|
52
|
-
}
|
|
53
|
-
_initResponse(response) {
|
|
54
|
-
this.response = {
|
|
55
|
-
message: 'Unknown error',
|
|
56
|
-
...response
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
static wrap(response) {
|
|
60
|
-
if (response instanceof ApiException)
|
|
61
|
-
return response;
|
|
62
|
-
const out = new this(response, response instanceof Error ? response : undefined);
|
|
63
|
-
if (response instanceof Error)
|
|
64
|
-
out.stack = response.stack;
|
|
65
|
-
return out;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
exports.ApiException = ApiException;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BadRequestError = void 0;
|
|
4
|
-
const i18n_1 = require("@opra/i18n");
|
|
5
|
-
const index_js_1 = require("../../enums/index.js");
|
|
6
|
-
const api_exception_js_1 = require("../api-exception.js");
|
|
7
|
-
/**
|
|
8
|
-
* 400 Bad Request
|
|
9
|
-
* The server cannot or will not process the request due to something that is perceived to be a client error
|
|
10
|
-
* (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
|
|
11
|
-
*/
|
|
12
|
-
class BadRequestError extends api_exception_js_1.ApiException {
|
|
13
|
-
constructor(response, cause) {
|
|
14
|
-
super(response, cause);
|
|
15
|
-
this.status = index_js_1.HttpStatus.BAD_REQUEST;
|
|
16
|
-
}
|
|
17
|
-
_initResponse(response) {
|
|
18
|
-
super._initResponse({
|
|
19
|
-
message: (0, i18n_1.translate)('error:BAD_REQUEST'),
|
|
20
|
-
severity: 'error',
|
|
21
|
-
code: 'BAD_REQUEST',
|
|
22
|
-
...response
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.BadRequestError = BadRequestError;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FailedDependencyError = void 0;
|
|
4
|
-
const i18n_1 = require("@opra/i18n");
|
|
5
|
-
const index_js_1 = require("../../enums/index.js");
|
|
6
|
-
const api_exception_js_1 = require("../api-exception.js");
|
|
7
|
-
/**
|
|
8
|
-
* 424 Failed Dependency
|
|
9
|
-
* The request failed due to failure of a previous request.
|
|
10
|
-
*/
|
|
11
|
-
class FailedDependencyError extends api_exception_js_1.ApiException {
|
|
12
|
-
constructor(response, cause) {
|
|
13
|
-
super(response, cause);
|
|
14
|
-
this.status = index_js_1.HttpStatus.FAILED_DEPENDENCY;
|
|
15
|
-
}
|
|
16
|
-
_initResponse(response) {
|
|
17
|
-
super._initResponse({
|
|
18
|
-
message: (0, i18n_1.translate)('error:FAILED_DEPENDENCY'),
|
|
19
|
-
severity: 'error',
|
|
20
|
-
code: 'FAILED_DEPENDENCY',
|
|
21
|
-
...response
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.FailedDependencyError = FailedDependencyError;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ForbiddenError = void 0;
|
|
4
|
-
const i18n_1 = require("@opra/i18n");
|
|
5
|
-
const index_js_1 = require("../../enums/index.js");
|
|
6
|
-
const api_exception_js_1 = require("../api-exception.js");
|
|
7
|
-
/**
|
|
8
|
-
* 403 Forbidden
|
|
9
|
-
* The client does not have access rights to the content; that is, it is unauthorized,
|
|
10
|
-
* so the server is refusing to give the requested resource. Unlike 401 Unauthorized,
|
|
11
|
-
* the client's identity is known to the server.
|
|
12
|
-
*/
|
|
13
|
-
class ForbiddenError extends api_exception_js_1.ApiException {
|
|
14
|
-
constructor(response, cause) {
|
|
15
|
-
super(response, cause);
|
|
16
|
-
this.status = index_js_1.HttpStatus.FORBIDDEN;
|
|
17
|
-
}
|
|
18
|
-
_initResponse(response) {
|
|
19
|
-
super._initResponse({
|
|
20
|
-
message: (0, i18n_1.translate)('error:FORBIDDEN'),
|
|
21
|
-
severity: 'error',
|
|
22
|
-
code: 'FORBIDDEN',
|
|
23
|
-
...response
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.ForbiddenError = ForbiddenError;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InternalServerError = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
6
|
-
const i18n_1 = require("@opra/i18n");
|
|
7
|
-
const index_js_1 = require("../../enums/index.js");
|
|
8
|
-
const api_exception_js_1 = require("../api-exception.js");
|
|
9
|
-
/**
|
|
10
|
-
* 500 Internal Server Error
|
|
11
|
-
* The server has encountered a situation it does not know how to handle.
|
|
12
|
-
*/
|
|
13
|
-
class InternalServerError extends api_exception_js_1.ApiException {
|
|
14
|
-
constructor(response, cause) {
|
|
15
|
-
super(response, cause);
|
|
16
|
-
this.status = index_js_1.HttpStatus.INTERNAL_SERVER_ERROR;
|
|
17
|
-
}
|
|
18
|
-
_initResponse(response) {
|
|
19
|
-
super._initResponse({
|
|
20
|
-
message: (0, i18n_1.translate)('error:INTERNAL_SERVER_ERROR'),
|
|
21
|
-
severity: 'error',
|
|
22
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
23
|
-
...lodash_1.default.omitBy(response, lodash_1.default.isNil)
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.InternalServerError = InternalServerError;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MethodNotAllowedError = void 0;
|
|
4
|
-
const i18n_1 = require("@opra/i18n");
|
|
5
|
-
const index_js_1 = require("../../enums/index.js");
|
|
6
|
-
const api_exception_js_1 = require("../api-exception.js");
|
|
7
|
-
/**
|
|
8
|
-
* 405 Method Not Allowed
|
|
9
|
-
* The request method is known by the server but is not supported by the target resource.
|
|
10
|
-
* For example, an API may not allow calling DELETE to remove a resource.
|
|
11
|
-
*/
|
|
12
|
-
class MethodNotAllowedError extends api_exception_js_1.ApiException {
|
|
13
|
-
constructor(response, cause) {
|
|
14
|
-
super(response, cause);
|
|
15
|
-
this.status = index_js_1.HttpStatus.METHOD_NOT_ALLOWED;
|
|
16
|
-
}
|
|
17
|
-
_initResponse(response) {
|
|
18
|
-
super._initResponse({
|
|
19
|
-
message: (0, i18n_1.translate)('error:METHOD_NOT_ALLOWED'),
|
|
20
|
-
severity: 'error',
|
|
21
|
-
code: 'METHOD_NOT_ALLOWED',
|
|
22
|
-
...response
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.MethodNotAllowedError = MethodNotAllowedError;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NotAcceptableError = void 0;
|
|
4
|
-
const i18n_1 = require("@opra/i18n");
|
|
5
|
-
const index_js_1 = require("../../enums/index.js");
|
|
6
|
-
const api_exception_js_1 = require("../api-exception.js");
|
|
7
|
-
/**
|
|
8
|
-
* 406 Not Acceptable
|
|
9
|
-
* This response is sent when the web server, after performing server-driven content negotiation,
|
|
10
|
-
* doesn't find any content that conforms to the criteria given by the user agent.
|
|
11
|
-
*/
|
|
12
|
-
class NotAcceptableError extends api_exception_js_1.ApiException {
|
|
13
|
-
constructor(response, cause) {
|
|
14
|
-
super(response, cause);
|
|
15
|
-
this.status = index_js_1.HttpStatus.NOT_ACCEPTABLE;
|
|
16
|
-
}
|
|
17
|
-
_initResponse(response) {
|
|
18
|
-
super._initResponse({
|
|
19
|
-
message: (0, i18n_1.translate)('error:NOT_ACCEPTABLE', 'Not Acceptable'),
|
|
20
|
-
severity: 'error',
|
|
21
|
-
code: 'NOT_ACCEPTABLE',
|
|
22
|
-
...response
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.NotAcceptableError = NotAcceptableError;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NotFoundError = void 0;
|
|
4
|
-
const i18n_1 = require("@opra/i18n");
|
|
5
|
-
const index_js_1 = require("../../enums/index.js");
|
|
6
|
-
const api_exception_js_1 = require("../api-exception.js");
|
|
7
|
-
/**
|
|
8
|
-
* 404 Not Found
|
|
9
|
-
* The server can not find the requested resource. In the browser, this means the URL is not recognized.
|
|
10
|
-
* In an API, this can also mean that the endpoint is valid but the resource itself does not exist.
|
|
11
|
-
* Servers may also send this response instead of 403 Forbidden to hide the existence of a resource
|
|
12
|
-
* from an unauthorized client. This response code is probably the most well known due to its
|
|
13
|
-
* frequent occurrence on the web.
|
|
14
|
-
*/
|
|
15
|
-
class NotFoundError extends api_exception_js_1.ApiException {
|
|
16
|
-
constructor(response, cause) {
|
|
17
|
-
super(response, cause);
|
|
18
|
-
this.status = index_js_1.HttpStatus.NOT_FOUND;
|
|
19
|
-
}
|
|
20
|
-
_initResponse(response) {
|
|
21
|
-
super._initResponse({
|
|
22
|
-
message: (0, i18n_1.translate)('error:NOT_FOUND', 'Not found'),
|
|
23
|
-
severity: 'error',
|
|
24
|
-
code: 'NOT_FOUND',
|
|
25
|
-
...response
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.NotFoundError = NotFoundError;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UnauthorizedError = void 0;
|
|
4
|
-
const i18n_1 = require("@opra/i18n");
|
|
5
|
-
const index_js_1 = require("../../enums/index.js");
|
|
6
|
-
const api_exception_js_1 = require("../api-exception.js");
|
|
7
|
-
/**
|
|
8
|
-
* 401 Unauthorized
|
|
9
|
-
* Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated".
|
|
10
|
-
* That is, the client must authenticate itself to get the requested response.
|
|
11
|
-
*/
|
|
12
|
-
class UnauthorizedError extends api_exception_js_1.ApiException {
|
|
13
|
-
constructor(response, cause) {
|
|
14
|
-
super(response, cause);
|
|
15
|
-
this.status = index_js_1.HttpStatus.UNAUTHORIZED;
|
|
16
|
-
}
|
|
17
|
-
_initResponse(response) {
|
|
18
|
-
super._initResponse({
|
|
19
|
-
message: (0, i18n_1.translate)('error:UNAUTHORIZED', 'Unauthorized'),
|
|
20
|
-
severity: 'error',
|
|
21
|
-
code: 'UNAUTHORIZED',
|
|
22
|
-
...response
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.UnauthorizedError = UnauthorizedError;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UnprocessableEntityError = void 0;
|
|
4
|
-
const i18n_1 = require("@opra/i18n");
|
|
5
|
-
const index_js_1 = require("../../enums/index.js");
|
|
6
|
-
const api_exception_js_1 = require("../api-exception.js");
|
|
7
|
-
/**
|
|
8
|
-
* 422 Unprocessable Entity
|
|
9
|
-
* The request was well-formed but was unable to be followed due to semantic errors.
|
|
10
|
-
*/
|
|
11
|
-
class UnprocessableEntityError extends api_exception_js_1.ApiException {
|
|
12
|
-
constructor(response, cause) {
|
|
13
|
-
super(response, cause);
|
|
14
|
-
this.status = index_js_1.HttpStatus.UNPROCESSABLE_ENTITY;
|
|
15
|
-
}
|
|
16
|
-
_initResponse(response) {
|
|
17
|
-
super._initResponse({
|
|
18
|
-
message: (0, i18n_1.translate)('error:UNPROCESSABLE_ENTITY'),
|
|
19
|
-
severity: 'error',
|
|
20
|
-
code: 'UNPROCESSABLE_ENTITY',
|
|
21
|
-
...response
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.UnprocessableEntityError = UnprocessableEntityError;
|
package/cjs/exception/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./api-exception.js"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./http-errors/bad-request.error.js"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./http-errors/failed-dependency.error.js"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./http-errors/forbidden.error.js"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./http-errors/internal-server.error.js"), exports);
|
|
9
|
-
tslib_1.__exportStar(require("./http-errors/method-not-allowed.error.js"), exports);
|
|
10
|
-
tslib_1.__exportStar(require("./http-errors/not-acceptable.error.js"), exports);
|
|
11
|
-
tslib_1.__exportStar(require("./http-errors/not-found.error.js"), exports);
|
|
12
|
-
tslib_1.__exportStar(require("./http-errors/unauthorized.error.js"), exports);
|
|
13
|
-
tslib_1.__exportStar(require("./http-errors/unprocessable-entity.error.js"), exports);
|
|
14
|
-
tslib_1.__exportStar(require("./resource-errors/resource-conflict.error.js"), exports);
|
|
15
|
-
tslib_1.__exportStar(require("./resource-errors/resource-not-found.error.js"), exports);
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ResourceConflictError = void 0;
|
|
4
|
-
const i18n_1 = require("@opra/i18n");
|
|
5
|
-
const index_js_1 = require("../../enums/index.js");
|
|
6
|
-
const api_exception_js_1 = require("../api-exception.js");
|
|
7
|
-
class ResourceConflictError extends api_exception_js_1.ApiException {
|
|
8
|
-
constructor(resource, fields, cause) {
|
|
9
|
-
super({
|
|
10
|
-
message: (0, i18n_1.translate)(`error:RESOURCE_CONFLICT`, { resource, fields }),
|
|
11
|
-
severity: 'error',
|
|
12
|
-
code: 'RESOURCE_CONFLICT',
|
|
13
|
-
subject: resource,
|
|
14
|
-
location: fields
|
|
15
|
-
}, cause);
|
|
16
|
-
this.status = index_js_1.HttpStatus.CONFLICT;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.ResourceConflictError = ResourceConflictError;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ResourceNotFoundError = void 0;
|
|
4
|
-
const i18n_1 = require("@opra/i18n");
|
|
5
|
-
const index_js_1 = require("../../enums/index.js");
|
|
6
|
-
const api_exception_js_1 = require("../api-exception.js");
|
|
7
|
-
class ResourceNotFoundError extends api_exception_js_1.ApiException {
|
|
8
|
-
constructor(resource, keyValue, cause) {
|
|
9
|
-
super({
|
|
10
|
-
message: (0, i18n_1.translate)(`error:RESOURCE_NOT_FOUND`, { resource: resource + '@' + keyValue }),
|
|
11
|
-
severity: 'error',
|
|
12
|
-
code: 'RESOURCE_NOT_FOUND',
|
|
13
|
-
subject: resource,
|
|
14
|
-
key: keyValue
|
|
15
|
-
}, cause);
|
|
16
|
-
this.status = index_js_1.HttpStatus.NOT_FOUND;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.ResourceNotFoundError = ResourceNotFoundError;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.wrapError = void 0;
|
|
4
|
-
const api_exception_js_1 = require("./api-exception.js");
|
|
5
|
-
const internal_server_error_js_1 = require("./http-errors/internal-server.error.js");
|
|
6
|
-
function wrapError(response) {
|
|
7
|
-
if (response instanceof api_exception_js_1.ApiException)
|
|
8
|
-
return response;
|
|
9
|
-
if (response instanceof Error) {
|
|
10
|
-
const x = response;
|
|
11
|
-
if (typeof x.status === 'number' || typeof x.getStatus === 'function')
|
|
12
|
-
return new api_exception_js_1.ApiException(response);
|
|
13
|
-
return new internal_server_error_js_1.InternalServerError(response);
|
|
14
|
-
}
|
|
15
|
-
return new internal_server_error_js_1.InternalServerError();
|
|
16
|
-
}
|
|
17
|
-
exports.wrapError = wrapError;
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpraQuery = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
6
|
-
const schema_1 = require("@opra/schema");
|
|
7
|
-
const path_to_tree_js_1 = require("../utils/path-to-tree.js");
|
|
8
|
-
var OpraQuery;
|
|
9
|
-
(function (OpraQuery) {
|
|
10
|
-
function forCreate(resource, values, options) {
|
|
11
|
-
if (options?.pick)
|
|
12
|
-
options.pick = normalizePick(resource, options.pick);
|
|
13
|
-
if (options?.omit)
|
|
14
|
-
options.omit = normalizePick(resource, options.omit);
|
|
15
|
-
if (options?.include)
|
|
16
|
-
options.include = normalizePick(resource, options.include);
|
|
17
|
-
const out = {
|
|
18
|
-
queryType: 'create',
|
|
19
|
-
scope: 'collection',
|
|
20
|
-
operation: 'create',
|
|
21
|
-
resource,
|
|
22
|
-
data: values
|
|
23
|
-
};
|
|
24
|
-
Object.assign(out, lodash_1.default.omit(options, Object.keys(out)));
|
|
25
|
-
return out;
|
|
26
|
-
}
|
|
27
|
-
OpraQuery.forCreate = forCreate;
|
|
28
|
-
function forGetSchema(resourcePath, options) {
|
|
29
|
-
// if (options?.pick)
|
|
30
|
-
// options.pick = normalizePick(resource, options.pick);
|
|
31
|
-
// if (options?.omit)
|
|
32
|
-
// options.omit = normalizePick(resource, options.omit);
|
|
33
|
-
// if (options?.include)
|
|
34
|
-
// options.include = normalizePick(resource, options.include);
|
|
35
|
-
const out = {
|
|
36
|
-
queryType: 'schema',
|
|
37
|
-
scope: 'instance',
|
|
38
|
-
resourcePath,
|
|
39
|
-
operation: 'read',
|
|
40
|
-
};
|
|
41
|
-
Object.assign(out, lodash_1.default.omit(options, Object.keys(out)));
|
|
42
|
-
return out;
|
|
43
|
-
}
|
|
44
|
-
OpraQuery.forGetSchema = forGetSchema;
|
|
45
|
-
function forGetEntity(resource, key, options) {
|
|
46
|
-
if (options?.pick)
|
|
47
|
-
options.pick = normalizePick(resource, options.pick);
|
|
48
|
-
if (options?.omit)
|
|
49
|
-
options.omit = normalizePick(resource, options.omit);
|
|
50
|
-
if (options?.include)
|
|
51
|
-
options.include = normalizePick(resource, options.include);
|
|
52
|
-
checkKeyFields(resource, key);
|
|
53
|
-
const out = {
|
|
54
|
-
queryType: 'get',
|
|
55
|
-
scope: 'instance',
|
|
56
|
-
operation: 'read',
|
|
57
|
-
resource,
|
|
58
|
-
keyValue: key
|
|
59
|
-
};
|
|
60
|
-
Object.assign(out, lodash_1.default.omit(options, Object.keys(out)));
|
|
61
|
-
return out;
|
|
62
|
-
}
|
|
63
|
-
OpraQuery.forGetEntity = forGetEntity;
|
|
64
|
-
function forSearch(resource, options) {
|
|
65
|
-
if (options?.pick)
|
|
66
|
-
options.pick = normalizePick(resource, options.pick);
|
|
67
|
-
if (options?.omit)
|
|
68
|
-
options.omit = normalizePick(resource, options.omit);
|
|
69
|
-
if (options?.include)
|
|
70
|
-
options.include = normalizePick(resource, options.include);
|
|
71
|
-
if (options?.sort)
|
|
72
|
-
options.sort = normalizePick(resource, options.sort); // todo check allowed sort fields
|
|
73
|
-
const out = {
|
|
74
|
-
queryType: 'search',
|
|
75
|
-
scope: 'collection',
|
|
76
|
-
operation: 'read',
|
|
77
|
-
resource
|
|
78
|
-
};
|
|
79
|
-
Object.assign(out, lodash_1.default.omit(options, Object.keys(out)));
|
|
80
|
-
return out;
|
|
81
|
-
}
|
|
82
|
-
OpraQuery.forSearch = forSearch;
|
|
83
|
-
function forGetProperty(property, options) {
|
|
84
|
-
const out = {
|
|
85
|
-
queryType: 'get',
|
|
86
|
-
scope: 'property',
|
|
87
|
-
operation: 'read',
|
|
88
|
-
property
|
|
89
|
-
};
|
|
90
|
-
Object.assign(out, lodash_1.default.omit(options, Object.keys(out)));
|
|
91
|
-
return out;
|
|
92
|
-
}
|
|
93
|
-
OpraQuery.forGetProperty = forGetProperty;
|
|
94
|
-
function forUpdate(resource, keyValue, values, options) {
|
|
95
|
-
if (options?.pick)
|
|
96
|
-
options.pick = normalizePick(resource, options.pick);
|
|
97
|
-
if (options?.omit)
|
|
98
|
-
options.omit = normalizePick(resource, options.omit);
|
|
99
|
-
if (options?.include)
|
|
100
|
-
options.include = normalizePick(resource, options.include);
|
|
101
|
-
checkKeyFields(resource, keyValue);
|
|
102
|
-
const out = {
|
|
103
|
-
queryType: 'update',
|
|
104
|
-
scope: 'instance',
|
|
105
|
-
operation: 'update',
|
|
106
|
-
resource,
|
|
107
|
-
keyValue,
|
|
108
|
-
data: values
|
|
109
|
-
};
|
|
110
|
-
Object.assign(out, lodash_1.default.omit(options, Object.keys(out)));
|
|
111
|
-
return out;
|
|
112
|
-
}
|
|
113
|
-
OpraQuery.forUpdate = forUpdate;
|
|
114
|
-
function forUpdateMany(resource, values, options) {
|
|
115
|
-
const out = {
|
|
116
|
-
queryType: 'updateMany',
|
|
117
|
-
scope: 'collection',
|
|
118
|
-
operation: 'update',
|
|
119
|
-
resource,
|
|
120
|
-
data: values
|
|
121
|
-
};
|
|
122
|
-
Object.assign(out, lodash_1.default.omit(options, Object.keys(out)));
|
|
123
|
-
return out;
|
|
124
|
-
}
|
|
125
|
-
OpraQuery.forUpdateMany = forUpdateMany;
|
|
126
|
-
function forDelete(resource, key) {
|
|
127
|
-
checkKeyFields(resource, key);
|
|
128
|
-
return {
|
|
129
|
-
queryType: 'delete',
|
|
130
|
-
scope: 'instance',
|
|
131
|
-
operation: 'delete',
|
|
132
|
-
resource,
|
|
133
|
-
keyValue: key
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
OpraQuery.forDelete = forDelete;
|
|
137
|
-
function forDeleteMany(resource, options) {
|
|
138
|
-
const out = {
|
|
139
|
-
queryType: 'deleteMany',
|
|
140
|
-
scope: 'collection',
|
|
141
|
-
operation: 'delete',
|
|
142
|
-
resource,
|
|
143
|
-
};
|
|
144
|
-
Object.assign(out, lodash_1.default.omit(options, Object.keys(out)));
|
|
145
|
-
return out;
|
|
146
|
-
}
|
|
147
|
-
OpraQuery.forDeleteMany = forDeleteMany;
|
|
148
|
-
function isCreateQuery(q) {
|
|
149
|
-
return q && typeof q === 'object' && q.scope === 'collection' && q.queryType === 'create';
|
|
150
|
-
}
|
|
151
|
-
OpraQuery.isCreateQuery = isCreateQuery;
|
|
152
|
-
function isSearchQuery(q) {
|
|
153
|
-
return q && typeof q === 'object' && q.scope === 'collection' && q.queryType === 'search';
|
|
154
|
-
}
|
|
155
|
-
OpraQuery.isSearchQuery = isSearchQuery;
|
|
156
|
-
function isReadQuery(q) {
|
|
157
|
-
return q && typeof q === 'object' && q.scope === 'instance' && q.queryType === 'read';
|
|
158
|
-
}
|
|
159
|
-
OpraQuery.isReadQuery = isReadQuery;
|
|
160
|
-
function isDeleteQuery(q) {
|
|
161
|
-
return q && typeof q === 'object' && q.scope === 'instance' && q.queryType === 'delete';
|
|
162
|
-
}
|
|
163
|
-
OpraQuery.isDeleteQuery = isDeleteQuery;
|
|
164
|
-
})(OpraQuery = exports.OpraQuery || (exports.OpraQuery = {}));
|
|
165
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
166
|
-
function checkKeyFields(resource, key) {
|
|
167
|
-
if (!resource.dataType.primaryKey)
|
|
168
|
-
throw new Error(`"${resource.name}" has no primary key`);
|
|
169
|
-
}
|
|
170
|
-
function normalizePick(resource, fields) {
|
|
171
|
-
const fieldsTree = (0, path_to_tree_js_1.pathToTree)(fields) || {};
|
|
172
|
-
return _normalizeFieldsList([], resource.service, resource, resource.dataType, fieldsTree, '', {
|
|
173
|
-
additionalFields: true
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
function _normalizeFieldsList(target, service, resource, dataType, node, parentPath = '', options) {
|
|
177
|
-
let curPath = '';
|
|
178
|
-
for (const k of Object.keys(node)) {
|
|
179
|
-
const nodeVal = node[k];
|
|
180
|
-
const prop = dataType?.fields.get(k);
|
|
181
|
-
if (!prop) {
|
|
182
|
-
curPath = parentPath ? parentPath + '.' + k : k;
|
|
183
|
-
if (!options?.additionalFields || (dataType && !dataType.additionalFields))
|
|
184
|
-
throw new TypeError(`Unknown field path "${resource.name + '.' + curPath}"`);
|
|
185
|
-
if (typeof nodeVal === 'object')
|
|
186
|
-
_normalizeFieldsList(target, service, resource, undefined, nodeVal, curPath, options);
|
|
187
|
-
else
|
|
188
|
-
target.push(curPath);
|
|
189
|
-
continue;
|
|
190
|
-
}
|
|
191
|
-
curPath = parentPath ? parentPath + '.' + prop.name : prop.name;
|
|
192
|
-
const propType = service.getDataType(prop.type || 'string');
|
|
193
|
-
if (typeof nodeVal === 'object') {
|
|
194
|
-
if (!(propType && propType instanceof schema_1.ComplexType))
|
|
195
|
-
throw new TypeError(`"${curPath}" is not a complex type and has no sub fields`);
|
|
196
|
-
if (target.findIndex(x => x === parentPath) >= 0)
|
|
197
|
-
continue;
|
|
198
|
-
target = _normalizeFieldsList(target, service, resource, propType, nodeVal, curPath, options);
|
|
199
|
-
continue;
|
|
200
|
-
}
|
|
201
|
-
if (target.findIndex(x => x.startsWith(curPath + '.')) >= 0) {
|
|
202
|
-
target = target.filter(x => !x.startsWith(curPath + '.'));
|
|
203
|
-
}
|
|
204
|
-
target.push(curPath);
|
|
205
|
-
}
|
|
206
|
-
return target;
|
|
207
|
-
}
|