@opra/core 0.1.1 → 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
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { HttpStatus } from '../enums/index.js';
|
|
2
|
-
export declare type IssueSeverity = 'error' | 'fatal' | 'warning' | 'info';
|
|
3
|
-
export interface ErrorResponse {
|
|
4
|
-
/**
|
|
5
|
-
* Error message
|
|
6
|
-
*/
|
|
7
|
-
message: string;
|
|
8
|
-
/**
|
|
9
|
-
* Error or warning code
|
|
10
|
-
*/
|
|
11
|
-
code?: string;
|
|
12
|
-
/**
|
|
13
|
-
* Severity of the issue
|
|
14
|
-
*/
|
|
15
|
-
severity?: IssueSeverity;
|
|
16
|
-
/**
|
|
17
|
-
* Additional details about the error
|
|
18
|
-
*/
|
|
19
|
-
details?: string;
|
|
20
|
-
/**
|
|
21
|
-
* Additional diagnostic information about the issue. Error stack etc.
|
|
22
|
-
*/
|
|
23
|
-
diagnostics?: string | string[];
|
|
24
|
-
[index: string]: any;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Defines the base Opra exception, which is handled by the default Exceptions Handler.
|
|
28
|
-
*/
|
|
29
|
-
export declare class ApiException extends Error {
|
|
30
|
-
static stackAsDiagnostics: boolean;
|
|
31
|
-
response: ErrorResponse;
|
|
32
|
-
status: number;
|
|
33
|
-
cause?: Error;
|
|
34
|
-
constructor(response?: string | ErrorResponse | Error, cause?: Error);
|
|
35
|
-
setStatus(status: number | HttpStatus): this;
|
|
36
|
-
protected _initName(): void;
|
|
37
|
-
protected _initErrorInstance(init: Error): void;
|
|
38
|
-
protected _initResponse(response?: Partial<ErrorResponse>): void;
|
|
39
|
-
static wrap(response: string | ErrorResponse | Error): ApiException;
|
|
40
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { HttpStatus } from '../enums/index.js';
|
|
2
|
-
/**
|
|
3
|
-
* Defines the base Opra exception, which is handled by the default Exceptions Handler.
|
|
4
|
-
*/
|
|
5
|
-
export class ApiException extends Error {
|
|
6
|
-
static stackAsDiagnostics = false;
|
|
7
|
-
response;
|
|
8
|
-
status;
|
|
9
|
-
cause;
|
|
10
|
-
constructor(response, cause) {
|
|
11
|
-
super('');
|
|
12
|
-
this._initName();
|
|
13
|
-
this.status = HttpStatus.INTERNAL_SERVER_ERROR;
|
|
14
|
-
cause = cause || (response instanceof Error ? response : undefined);
|
|
15
|
-
if (cause)
|
|
16
|
-
Object.defineProperty(this, 'cause', { enumerable: false, configurable: true, writable: true, value: cause });
|
|
17
|
-
if (response instanceof Error)
|
|
18
|
-
this._initErrorInstance(response);
|
|
19
|
-
else if (typeof response === 'string')
|
|
20
|
-
this._initResponse({ message: response });
|
|
21
|
-
else
|
|
22
|
-
this._initResponse(response);
|
|
23
|
-
if (!this.response.severity)
|
|
24
|
-
if (this.status >= 500)
|
|
25
|
-
this.response.severity = 'fatal';
|
|
26
|
-
else
|
|
27
|
-
this.response.severity = 'error';
|
|
28
|
-
if (this.cause instanceof Error && this.cause.stack) {
|
|
29
|
-
if (ApiException.stackAsDiagnostics)
|
|
30
|
-
this.response.diagnostics = this.cause.stack.split('\n');
|
|
31
|
-
this.stack = this.cause.stack;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
setStatus(status) {
|
|
35
|
-
this.status = status;
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
_initName() {
|
|
39
|
-
this.name = this.constructor.name;
|
|
40
|
-
}
|
|
41
|
-
_initErrorInstance(init) {
|
|
42
|
-
this._initResponse({
|
|
43
|
-
message: init.message
|
|
44
|
-
});
|
|
45
|
-
if (typeof init.status === 'number')
|
|
46
|
-
this.setStatus(init.status);
|
|
47
|
-
else if (typeof init.getStatus === 'function')
|
|
48
|
-
this.setStatus(init.getStatus());
|
|
49
|
-
}
|
|
50
|
-
_initResponse(response) {
|
|
51
|
-
this.response = {
|
|
52
|
-
message: 'Unknown error',
|
|
53
|
-
...response
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
static wrap(response) {
|
|
57
|
-
if (response instanceof ApiException)
|
|
58
|
-
return response;
|
|
59
|
-
const out = new this(response, response instanceof Error ? response : undefined);
|
|
60
|
-
if (response instanceof Error)
|
|
61
|
-
out.stack = response.stack;
|
|
62
|
-
return out;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ApiException, ErrorResponse } from '../api-exception.js';
|
|
2
|
-
/**
|
|
3
|
-
* 400 Bad Request
|
|
4
|
-
* The server cannot or will not process the request due to something that is perceived to be a client error
|
|
5
|
-
* (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
|
|
6
|
-
*/
|
|
7
|
-
export declare class BadRequestError extends ApiException {
|
|
8
|
-
constructor(response?: string | ErrorResponse | Error, cause?: Error);
|
|
9
|
-
protected _initResponse(response: Partial<ErrorResponse>): void;
|
|
10
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { translate } from '@opra/i18n';
|
|
2
|
-
import { HttpStatus } from '../../enums/index.js';
|
|
3
|
-
import { ApiException } from '../api-exception.js';
|
|
4
|
-
/**
|
|
5
|
-
* 400 Bad Request
|
|
6
|
-
* The server cannot or will not process the request due to something that is perceived to be a client error
|
|
7
|
-
* (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
|
|
8
|
-
*/
|
|
9
|
-
export class BadRequestError extends ApiException {
|
|
10
|
-
constructor(response, cause) {
|
|
11
|
-
super(response, cause);
|
|
12
|
-
this.status = HttpStatus.BAD_REQUEST;
|
|
13
|
-
}
|
|
14
|
-
_initResponse(response) {
|
|
15
|
-
super._initResponse({
|
|
16
|
-
message: translate('error:BAD_REQUEST'),
|
|
17
|
-
severity: 'error',
|
|
18
|
-
code: 'BAD_REQUEST',
|
|
19
|
-
...response
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ApiException, ErrorResponse } from '../api-exception.js';
|
|
2
|
-
/**
|
|
3
|
-
* 424 Failed Dependency
|
|
4
|
-
* The request failed due to failure of a previous request.
|
|
5
|
-
*/
|
|
6
|
-
export declare class FailedDependencyError extends ApiException {
|
|
7
|
-
constructor(response?: string | ErrorResponse | Error, cause?: Error);
|
|
8
|
-
protected _initResponse(response: Partial<ErrorResponse>): void;
|
|
9
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { translate } from '@opra/i18n';
|
|
2
|
-
import { HttpStatus } from '../../enums/index.js';
|
|
3
|
-
import { ApiException } from '../api-exception.js';
|
|
4
|
-
/**
|
|
5
|
-
* 424 Failed Dependency
|
|
6
|
-
* The request failed due to failure of a previous request.
|
|
7
|
-
*/
|
|
8
|
-
export class FailedDependencyError extends ApiException {
|
|
9
|
-
constructor(response, cause) {
|
|
10
|
-
super(response, cause);
|
|
11
|
-
this.status = HttpStatus.FAILED_DEPENDENCY;
|
|
12
|
-
}
|
|
13
|
-
_initResponse(response) {
|
|
14
|
-
super._initResponse({
|
|
15
|
-
message: translate('error:FAILED_DEPENDENCY'),
|
|
16
|
-
severity: 'error',
|
|
17
|
-
code: 'FAILED_DEPENDENCY',
|
|
18
|
-
...response
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ApiException, ErrorResponse } from '../api-exception.js';
|
|
2
|
-
/**
|
|
3
|
-
* 403 Forbidden
|
|
4
|
-
* The client does not have access rights to the content; that is, it is unauthorized,
|
|
5
|
-
* so the server is refusing to give the requested resource. Unlike 401 Unauthorized,
|
|
6
|
-
* the client's identity is known to the server.
|
|
7
|
-
*/
|
|
8
|
-
export declare class ForbiddenError extends ApiException {
|
|
9
|
-
constructor(response?: string | ErrorResponse | Error, cause?: Error);
|
|
10
|
-
protected _initResponse(response: Partial<ErrorResponse>): void;
|
|
11
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { translate } from '@opra/i18n';
|
|
2
|
-
import { HttpStatus } from '../../enums/index.js';
|
|
3
|
-
import { ApiException } from '../api-exception.js';
|
|
4
|
-
/**
|
|
5
|
-
* 403 Forbidden
|
|
6
|
-
* The client does not have access rights to the content; that is, it is unauthorized,
|
|
7
|
-
* so the server is refusing to give the requested resource. Unlike 401 Unauthorized,
|
|
8
|
-
* the client's identity is known to the server.
|
|
9
|
-
*/
|
|
10
|
-
export class ForbiddenError extends ApiException {
|
|
11
|
-
constructor(response, cause) {
|
|
12
|
-
super(response, cause);
|
|
13
|
-
this.status = HttpStatus.FORBIDDEN;
|
|
14
|
-
}
|
|
15
|
-
_initResponse(response) {
|
|
16
|
-
super._initResponse({
|
|
17
|
-
message: translate('error:FORBIDDEN'),
|
|
18
|
-
severity: 'error',
|
|
19
|
-
code: 'FORBIDDEN',
|
|
20
|
-
...response
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ApiException, ErrorResponse } from '../api-exception.js';
|
|
2
|
-
/**
|
|
3
|
-
* 500 Internal Server Error
|
|
4
|
-
* The server has encountered a situation it does not know how to handle.
|
|
5
|
-
*/
|
|
6
|
-
export declare class InternalServerError extends ApiException {
|
|
7
|
-
constructor(response?: string | ErrorResponse | Error, cause?: Error);
|
|
8
|
-
protected _initResponse(response: Partial<ErrorResponse>): void;
|
|
9
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import { translate } from '@opra/i18n';
|
|
3
|
-
import { HttpStatus } from '../../enums/index.js';
|
|
4
|
-
import { ApiException } from '../api-exception.js';
|
|
5
|
-
/**
|
|
6
|
-
* 500 Internal Server Error
|
|
7
|
-
* The server has encountered a situation it does not know how to handle.
|
|
8
|
-
*/
|
|
9
|
-
export class InternalServerError extends ApiException {
|
|
10
|
-
constructor(response, cause) {
|
|
11
|
-
super(response, cause);
|
|
12
|
-
this.status = HttpStatus.INTERNAL_SERVER_ERROR;
|
|
13
|
-
}
|
|
14
|
-
_initResponse(response) {
|
|
15
|
-
super._initResponse({
|
|
16
|
-
message: translate('error:INTERNAL_SERVER_ERROR'),
|
|
17
|
-
severity: 'error',
|
|
18
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
19
|
-
..._.omitBy(response, _.isNil)
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ApiException, ErrorResponse } from '../api-exception.js';
|
|
2
|
-
/**
|
|
3
|
-
* 405 Method Not Allowed
|
|
4
|
-
* The request method is known by the server but is not supported by the target resource.
|
|
5
|
-
* For example, an API may not allow calling DELETE to remove a resource.
|
|
6
|
-
*/
|
|
7
|
-
export declare class MethodNotAllowedError extends ApiException {
|
|
8
|
-
constructor(response?: string | ErrorResponse | Error, cause?: Error);
|
|
9
|
-
protected _initResponse(response: Partial<ErrorResponse>): void;
|
|
10
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { translate } from '@opra/i18n';
|
|
2
|
-
import { HttpStatus } from '../../enums/index.js';
|
|
3
|
-
import { ApiException } from '../api-exception.js';
|
|
4
|
-
/**
|
|
5
|
-
* 405 Method Not Allowed
|
|
6
|
-
* The request method is known by the server but is not supported by the target resource.
|
|
7
|
-
* For example, an API may not allow calling DELETE to remove a resource.
|
|
8
|
-
*/
|
|
9
|
-
export class MethodNotAllowedError extends ApiException {
|
|
10
|
-
constructor(response, cause) {
|
|
11
|
-
super(response, cause);
|
|
12
|
-
this.status = HttpStatus.METHOD_NOT_ALLOWED;
|
|
13
|
-
}
|
|
14
|
-
_initResponse(response) {
|
|
15
|
-
super._initResponse({
|
|
16
|
-
message: translate('error:METHOD_NOT_ALLOWED'),
|
|
17
|
-
severity: 'error',
|
|
18
|
-
code: 'METHOD_NOT_ALLOWED',
|
|
19
|
-
...response
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ApiException, ErrorResponse } from '../api-exception.js';
|
|
2
|
-
/**
|
|
3
|
-
* 406 Not Acceptable
|
|
4
|
-
* This response is sent when the web server, after performing server-driven content negotiation,
|
|
5
|
-
* doesn't find any content that conforms to the criteria given by the user agent.
|
|
6
|
-
*/
|
|
7
|
-
export declare class NotAcceptableError extends ApiException {
|
|
8
|
-
constructor(response?: string | ErrorResponse | Error, cause?: Error);
|
|
9
|
-
protected _initResponse(response: Partial<ErrorResponse>): void;
|
|
10
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { translate } from '@opra/i18n';
|
|
2
|
-
import { HttpStatus } from '../../enums/index.js';
|
|
3
|
-
import { ApiException } from '../api-exception.js';
|
|
4
|
-
/**
|
|
5
|
-
* 406 Not Acceptable
|
|
6
|
-
* This response is sent when the web server, after performing server-driven content negotiation,
|
|
7
|
-
* doesn't find any content that conforms to the criteria given by the user agent.
|
|
8
|
-
*/
|
|
9
|
-
export class NotAcceptableError extends ApiException {
|
|
10
|
-
constructor(response, cause) {
|
|
11
|
-
super(response, cause);
|
|
12
|
-
this.status = HttpStatus.NOT_ACCEPTABLE;
|
|
13
|
-
}
|
|
14
|
-
_initResponse(response) {
|
|
15
|
-
super._initResponse({
|
|
16
|
-
message: translate('error:NOT_ACCEPTABLE', 'Not Acceptable'),
|
|
17
|
-
severity: 'error',
|
|
18
|
-
code: 'NOT_ACCEPTABLE',
|
|
19
|
-
...response
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ApiException, ErrorResponse } from '../api-exception.js';
|
|
2
|
-
/**
|
|
3
|
-
* 404 Not Found
|
|
4
|
-
* The server can not find the requested resource. In the browser, this means the URL is not recognized.
|
|
5
|
-
* In an API, this can also mean that the endpoint is valid but the resource itself does not exist.
|
|
6
|
-
* Servers may also send this response instead of 403 Forbidden to hide the existence of a resource
|
|
7
|
-
* from an unauthorized client. This response code is probably the most well known due to its
|
|
8
|
-
* frequent occurrence on the web.
|
|
9
|
-
*/
|
|
10
|
-
export declare class NotFoundError extends ApiException {
|
|
11
|
-
constructor(response?: string | ErrorResponse | Error, cause?: Error);
|
|
12
|
-
protected _initResponse(response: Partial<ErrorResponse>): void;
|
|
13
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { translate } from '@opra/i18n';
|
|
2
|
-
import { HttpStatus } from '../../enums/index.js';
|
|
3
|
-
import { ApiException } from '../api-exception.js';
|
|
4
|
-
/**
|
|
5
|
-
* 404 Not Found
|
|
6
|
-
* The server can not find the requested resource. In the browser, this means the URL is not recognized.
|
|
7
|
-
* In an API, this can also mean that the endpoint is valid but the resource itself does not exist.
|
|
8
|
-
* Servers may also send this response instead of 403 Forbidden to hide the existence of a resource
|
|
9
|
-
* from an unauthorized client. This response code is probably the most well known due to its
|
|
10
|
-
* frequent occurrence on the web.
|
|
11
|
-
*/
|
|
12
|
-
export class NotFoundError extends ApiException {
|
|
13
|
-
constructor(response, cause) {
|
|
14
|
-
super(response, cause);
|
|
15
|
-
this.status = HttpStatus.NOT_FOUND;
|
|
16
|
-
}
|
|
17
|
-
_initResponse(response) {
|
|
18
|
-
super._initResponse({
|
|
19
|
-
message: translate('error:NOT_FOUND', 'Not found'),
|
|
20
|
-
severity: 'error',
|
|
21
|
-
code: 'NOT_FOUND',
|
|
22
|
-
...response
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ApiException, ErrorResponse } from '../api-exception.js';
|
|
2
|
-
/**
|
|
3
|
-
* 401 Unauthorized
|
|
4
|
-
* Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated".
|
|
5
|
-
* That is, the client must authenticate itself to get the requested response.
|
|
6
|
-
*/
|
|
7
|
-
export declare class UnauthorizedError extends ApiException {
|
|
8
|
-
constructor(response?: string | ErrorResponse | Error, cause?: Error);
|
|
9
|
-
protected _initResponse(response: Partial<ErrorResponse>): void;
|
|
10
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { translate } from '@opra/i18n';
|
|
2
|
-
import { HttpStatus } from '../../enums/index.js';
|
|
3
|
-
import { ApiException } from '../api-exception.js';
|
|
4
|
-
/**
|
|
5
|
-
* 401 Unauthorized
|
|
6
|
-
* Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated".
|
|
7
|
-
* That is, the client must authenticate itself to get the requested response.
|
|
8
|
-
*/
|
|
9
|
-
export class UnauthorizedError extends ApiException {
|
|
10
|
-
constructor(response, cause) {
|
|
11
|
-
super(response, cause);
|
|
12
|
-
this.status = HttpStatus.UNAUTHORIZED;
|
|
13
|
-
}
|
|
14
|
-
_initResponse(response) {
|
|
15
|
-
super._initResponse({
|
|
16
|
-
message: translate('error:UNAUTHORIZED', 'Unauthorized'),
|
|
17
|
-
severity: 'error',
|
|
18
|
-
code: 'UNAUTHORIZED',
|
|
19
|
-
...response
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ApiException, ErrorResponse } from '../api-exception.js';
|
|
2
|
-
/**
|
|
3
|
-
* 422 Unprocessable Entity
|
|
4
|
-
* The request was well-formed but was unable to be followed due to semantic errors.
|
|
5
|
-
*/
|
|
6
|
-
export declare class UnprocessableEntityError extends ApiException {
|
|
7
|
-
constructor(response?: string | ErrorResponse | Error, cause?: Error);
|
|
8
|
-
protected _initResponse(response: Partial<ErrorResponse>): void;
|
|
9
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { translate } from '@opra/i18n';
|
|
2
|
-
import { HttpStatus } from '../../enums/index.js';
|
|
3
|
-
import { ApiException } from '../api-exception.js';
|
|
4
|
-
/**
|
|
5
|
-
* 422 Unprocessable Entity
|
|
6
|
-
* The request was well-formed but was unable to be followed due to semantic errors.
|
|
7
|
-
*/
|
|
8
|
-
export class UnprocessableEntityError extends ApiException {
|
|
9
|
-
constructor(response, cause) {
|
|
10
|
-
super(response, cause);
|
|
11
|
-
this.status = HttpStatus.UNPROCESSABLE_ENTITY;
|
|
12
|
-
}
|
|
13
|
-
_initResponse(response) {
|
|
14
|
-
super._initResponse({
|
|
15
|
-
message: translate('error:UNPROCESSABLE_ENTITY'),
|
|
16
|
-
severity: 'error',
|
|
17
|
-
code: 'UNPROCESSABLE_ENTITY',
|
|
18
|
-
...response
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
package/esm/exception/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export * from './api-exception.js';
|
|
2
|
-
export * from './http-errors/bad-request.error.js';
|
|
3
|
-
export * from './http-errors/failed-dependency.error.js';
|
|
4
|
-
export * from './http-errors/forbidden.error.js';
|
|
5
|
-
export * from './http-errors/internal-server.error.js';
|
|
6
|
-
export * from './http-errors/method-not-allowed.error.js';
|
|
7
|
-
export * from './http-errors/not-acceptable.error.js';
|
|
8
|
-
export * from './http-errors/not-found.error.js';
|
|
9
|
-
export * from './http-errors/unauthorized.error.js';
|
|
10
|
-
export * from './http-errors/unprocessable-entity.error.js';
|
|
11
|
-
export * from './resource-errors/resource-conflict.error.js';
|
|
12
|
-
export * from './resource-errors/resource-not-found.error.js';
|
package/esm/exception/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export * from './api-exception.js';
|
|
2
|
-
export * from './http-errors/bad-request.error.js';
|
|
3
|
-
export * from './http-errors/failed-dependency.error.js';
|
|
4
|
-
export * from './http-errors/forbidden.error.js';
|
|
5
|
-
export * from './http-errors/internal-server.error.js';
|
|
6
|
-
export * from './http-errors/method-not-allowed.error.js';
|
|
7
|
-
export * from './http-errors/not-acceptable.error.js';
|
|
8
|
-
export * from './http-errors/not-found.error.js';
|
|
9
|
-
export * from './http-errors/unauthorized.error.js';
|
|
10
|
-
export * from './http-errors/unprocessable-entity.error.js';
|
|
11
|
-
export * from './resource-errors/resource-conflict.error.js';
|
|
12
|
-
export * from './resource-errors/resource-not-found.error.js';
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { translate } from '@opra/i18n';
|
|
2
|
-
import { HttpStatus } from '../../enums/index.js';
|
|
3
|
-
import { ApiException } from '../api-exception.js';
|
|
4
|
-
export class ResourceConflictError extends ApiException {
|
|
5
|
-
constructor(resource, fields, cause) {
|
|
6
|
-
super({
|
|
7
|
-
message: translate(`error:RESOURCE_CONFLICT`, { resource, fields }),
|
|
8
|
-
severity: 'error',
|
|
9
|
-
code: 'RESOURCE_CONFLICT',
|
|
10
|
-
subject: resource,
|
|
11
|
-
location: fields
|
|
12
|
-
}, cause);
|
|
13
|
-
this.status = HttpStatus.CONFLICT;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { translate } from '@opra/i18n';
|
|
2
|
-
import { HttpStatus } from '../../enums/index.js';
|
|
3
|
-
import { ApiException } from '../api-exception.js';
|
|
4
|
-
export class ResourceNotFoundError extends ApiException {
|
|
5
|
-
constructor(resource, keyValue, cause) {
|
|
6
|
-
super({
|
|
7
|
-
message: translate(`error:RESOURCE_NOT_FOUND`, { resource: resource + '@' + keyValue }),
|
|
8
|
-
severity: 'error',
|
|
9
|
-
code: 'RESOURCE_NOT_FOUND',
|
|
10
|
-
subject: resource,
|
|
11
|
-
key: keyValue
|
|
12
|
-
}, cause);
|
|
13
|
-
this.status = HttpStatus.NOT_FOUND;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ApiException } from './api-exception.js';
|
|
2
|
-
import { InternalServerError } from './http-errors/internal-server.error.js';
|
|
3
|
-
export function wrapError(response) {
|
|
4
|
-
if (response instanceof ApiException)
|
|
5
|
-
return response;
|
|
6
|
-
if (response instanceof Error) {
|
|
7
|
-
const x = response;
|
|
8
|
-
if (typeof x.status === 'number' || typeof x.getStatus === 'function')
|
|
9
|
-
return new ApiException(response);
|
|
10
|
-
return new InternalServerError(response);
|
|
11
|
-
}
|
|
12
|
-
return new InternalServerError();
|
|
13
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { StrictOmit } from 'ts-gems';
|
|
2
|
-
import { EntityResource, OpraSchema } from '@opra/schema';
|
|
3
|
-
import { Expression } from '@opra/url';
|
|
4
|
-
import { KeyValue, QueryType } from '../types.js';
|
|
5
|
-
export declare type OpraQuery = OpraGetSchemaQuery | OpraCreateQuery | OpraGetEntityQuery | OpraSearchQuery | OpraUpdateQuery | OpraUpdateManyQuery | OpraDeleteQuery | OpraDeleteManyQuery;
|
|
6
|
-
interface BaseOpraQuery {
|
|
7
|
-
queryType: QueryType;
|
|
8
|
-
scope: OpraSchema.QueryScope;
|
|
9
|
-
operation: OpraSchema.OperationType;
|
|
10
|
-
}
|
|
11
|
-
export interface OpraGetSchemaQuery extends BaseOpraQuery {
|
|
12
|
-
queryType: 'schema';
|
|
13
|
-
scope: OpraSchema.QueryScope;
|
|
14
|
-
operation: 'read';
|
|
15
|
-
resourcePath: string[];
|
|
16
|
-
}
|
|
17
|
-
export interface OpraCreateQuery extends BaseOpraQuery {
|
|
18
|
-
queryType: 'create';
|
|
19
|
-
scope: 'collection';
|
|
20
|
-
operation: 'create';
|
|
21
|
-
resource: EntityResource;
|
|
22
|
-
data: {};
|
|
23
|
-
pick?: string[];
|
|
24
|
-
omit?: string[];
|
|
25
|
-
include?: string[];
|
|
26
|
-
}
|
|
27
|
-
export interface OpraGetEntityQuery extends BaseOpraQuery {
|
|
28
|
-
queryType: 'get';
|
|
29
|
-
scope: 'instance';
|
|
30
|
-
operation: 'read';
|
|
31
|
-
resource: EntityResource;
|
|
32
|
-
keyValue: KeyValue;
|
|
33
|
-
pick?: string[];
|
|
34
|
-
omit?: string[];
|
|
35
|
-
include?: string[];
|
|
36
|
-
nested?: OpraPropertyQuery;
|
|
37
|
-
}
|
|
38
|
-
export interface OpraPropertyQuery extends BaseOpraQuery {
|
|
39
|
-
queryType: 'get';
|
|
40
|
-
scope: 'property';
|
|
41
|
-
operation: 'read';
|
|
42
|
-
property: OpraSchema.Field;
|
|
43
|
-
nested?: OpraPropertyQuery;
|
|
44
|
-
}
|
|
45
|
-
export interface OpraUpdateQuery extends BaseOpraQuery {
|
|
46
|
-
queryType: 'update';
|
|
47
|
-
scope: 'instance';
|
|
48
|
-
operation: 'update';
|
|
49
|
-
resource: EntityResource;
|
|
50
|
-
keyValue: KeyValue;
|
|
51
|
-
data: {};
|
|
52
|
-
pick?: string[];
|
|
53
|
-
omit?: string[];
|
|
54
|
-
include?: string[];
|
|
55
|
-
}
|
|
56
|
-
export interface OpraUpdateManyQuery extends BaseOpraQuery {
|
|
57
|
-
queryType: 'updateMany';
|
|
58
|
-
scope: 'collection';
|
|
59
|
-
operation: 'update';
|
|
60
|
-
resource: EntityResource;
|
|
61
|
-
filter?: string | Expression;
|
|
62
|
-
data: {};
|
|
63
|
-
}
|
|
64
|
-
export interface OpraDeleteQuery extends BaseOpraQuery {
|
|
65
|
-
queryType: 'delete';
|
|
66
|
-
scope: 'instance';
|
|
67
|
-
operation: 'delete';
|
|
68
|
-
resource: EntityResource;
|
|
69
|
-
keyValue: KeyValue;
|
|
70
|
-
}
|
|
71
|
-
export interface OpraDeleteManyQuery extends BaseOpraQuery {
|
|
72
|
-
queryType: 'deleteMany';
|
|
73
|
-
scope: 'collection';
|
|
74
|
-
operation: 'delete';
|
|
75
|
-
resource: EntityResource;
|
|
76
|
-
filter?: string | Expression;
|
|
77
|
-
}
|
|
78
|
-
export interface OpraSearchQuery extends BaseOpraQuery {
|
|
79
|
-
queryType: 'search';
|
|
80
|
-
scope: 'collection';
|
|
81
|
-
operation: 'read';
|
|
82
|
-
resource: EntityResource;
|
|
83
|
-
pick?: string[];
|
|
84
|
-
omit?: string[];
|
|
85
|
-
include?: string[];
|
|
86
|
-
filter?: string | Expression;
|
|
87
|
-
limit?: number;
|
|
88
|
-
skip?: number;
|
|
89
|
-
distinct?: boolean;
|
|
90
|
-
count?: boolean;
|
|
91
|
-
sort?: string[];
|
|
92
|
-
}
|
|
93
|
-
export declare type CreateQueryOptions = StrictOmit<OpraCreateQuery, 'queryType' | 'scope' | 'operation' | 'resource' | 'data'>;
|
|
94
|
-
export declare type GetEntityQueryOptions = StrictOmit<OpraGetEntityQuery, 'queryType' | 'scope' | 'operation' | 'resource' | 'keyValue'>;
|
|
95
|
-
export declare type SearchQueryOptions = StrictOmit<OpraSearchQuery, 'queryType' | 'scope' | 'operation' | 'resource'>;
|
|
96
|
-
export declare type UpdateQueryOptions = StrictOmit<OpraUpdateQuery, 'queryType' | 'scope' | 'operation' | 'resource' | 'keyValue' | 'data'>;
|
|
97
|
-
export declare type UpdateManyQueryOptions = StrictOmit<OpraUpdateManyQuery, 'queryType' | 'scope' | 'operation' | 'resource' | 'data'>;
|
|
98
|
-
export declare type DeleteQueryOptions = StrictOmit<OpraDeleteQuery, 'queryType' | 'scope' | 'operation' | 'resource' | 'keyValue'>;
|
|
99
|
-
export declare type DeleteManyQueryOption = StrictOmit<OpraDeleteManyQuery, 'queryType' | 'scope' | 'operation' | 'resource'>;
|
|
100
|
-
export declare namespace OpraQuery {
|
|
101
|
-
function forCreate(resource: EntityResource, values: {}, options?: CreateQueryOptions): OpraCreateQuery;
|
|
102
|
-
function forGetSchema(resourcePath: string[], options?: GetEntityQueryOptions): OpraGetSchemaQuery;
|
|
103
|
-
function forGetEntity(resource: EntityResource, key: KeyValue, options?: GetEntityQueryOptions): OpraGetEntityQuery;
|
|
104
|
-
function forSearch(resource: EntityResource, options?: SearchQueryOptions): OpraSearchQuery;
|
|
105
|
-
function forGetProperty(property: OpraSchema.Field, options?: StrictOmit<OpraPropertyQuery, 'queryType' | 'scope' | 'operation' | 'property'>): OpraPropertyQuery;
|
|
106
|
-
function forUpdate(resource: EntityResource, keyValue: KeyValue, values: any, options?: UpdateQueryOptions): OpraUpdateQuery;
|
|
107
|
-
function forUpdateMany(resource: EntityResource, values: any, options?: UpdateManyQueryOptions): OpraUpdateManyQuery;
|
|
108
|
-
function forDelete(resource: EntityResource, key: KeyValue): OpraDeleteQuery;
|
|
109
|
-
function forDeleteMany(resource: EntityResource, options?: DeleteManyQueryOption): OpraDeleteManyQuery;
|
|
110
|
-
function isCreateQuery(q: any): q is OpraCreateQuery;
|
|
111
|
-
function isSearchQuery(q: any): q is OpraSearchQuery;
|
|
112
|
-
function isReadQuery(q: any): q is OpraGetEntityQuery;
|
|
113
|
-
function isDeleteQuery(q: any): q is OpraDeleteQuery;
|
|
114
|
-
}
|
|
115
|
-
export {};
|