@opra/core 0.31.2 → 0.31.5
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/http/http-adapter-host.js +2 -2
- package/cjs/request-context.js +2 -1
- package/cjs/services/api-service.js +3 -1
- package/esm/http/http-adapter-host.js +2 -2
- package/esm/request-context.js +2 -1
- package/esm/services/api-service.js +3 -1
- package/i18n/i18n/en/error.json +21 -0
- package/package.json +22 -21
- package/types/augmentation/collection.augmentation.d.ts +6 -0
- package/types/augmentation/singleton.augmentation.d.ts +3 -0
- package/types/request-context.d.ts +3 -1
- package/types/services/api-service.d.ts +3 -1
|
@@ -100,7 +100,7 @@ class HttpAdapterHost extends platform_adapter_host_js_1.PlatformAdapterHost {
|
|
|
100
100
|
try {
|
|
101
101
|
const { outgoing } = executionContext.switchToHttp();
|
|
102
102
|
const response = new response_host_js_1.ResponseHost({ http: outgoing });
|
|
103
|
-
const context = request_context_js_1.RequestContext.from(executionContext, request, response);
|
|
103
|
+
const context = request_context_js_1.RequestContext.from(executionContext, this.api, request, response);
|
|
104
104
|
await this.executeRequest(context);
|
|
105
105
|
await this.sendResponse(context);
|
|
106
106
|
}
|
|
@@ -617,7 +617,7 @@ class HttpAdapterHost extends platform_adapter_host_js_1.PlatformAdapterHost {
|
|
|
617
617
|
if (returnType) {
|
|
618
618
|
if (response.value == null)
|
|
619
619
|
throw new common_1.InternalServerError(`"${request.endpoint.name}" endpoint should return value`);
|
|
620
|
-
if (returnType.
|
|
620
|
+
if (!returnType.isAnonymous) {
|
|
621
621
|
const ns = this.api.getDataTypeNs(returnType);
|
|
622
622
|
// const isOpraSpec = returnType.document.url?.startsWith('https://oprajs.com/spec/v1.0')
|
|
623
623
|
body.type = (ns ? ns + ':' : '') + returnType.name;
|
package/cjs/request-context.js
CHANGED
|
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RequestContext = void 0;
|
|
4
4
|
var RequestContext;
|
|
5
5
|
(function (RequestContext) {
|
|
6
|
-
function from(executionContext, request, response) {
|
|
6
|
+
function from(executionContext, api, request, response) {
|
|
7
7
|
const out = {
|
|
8
|
+
api,
|
|
8
9
|
request,
|
|
9
10
|
response
|
|
10
11
|
};
|
|
@@ -7,7 +7,9 @@ class ApiService {
|
|
|
7
7
|
throw new Error(`No context assigned for ${Object.getPrototypeOf(this).constructor.name}`);
|
|
8
8
|
return this._context;
|
|
9
9
|
}
|
|
10
|
-
forContext(context) {
|
|
10
|
+
forContext(context, options) {
|
|
11
|
+
if (this._context === context && !options?.newInstance)
|
|
12
|
+
return this;
|
|
11
13
|
const instance = { context };
|
|
12
14
|
Object.setPrototypeOf(instance, this);
|
|
13
15
|
return instance;
|
|
@@ -96,7 +96,7 @@ export class HttpAdapterHost extends PlatformAdapterHost {
|
|
|
96
96
|
try {
|
|
97
97
|
const { outgoing } = executionContext.switchToHttp();
|
|
98
98
|
const response = new ResponseHost({ http: outgoing });
|
|
99
|
-
const context = RequestContext.from(executionContext, request, response);
|
|
99
|
+
const context = RequestContext.from(executionContext, this.api, request, response);
|
|
100
100
|
await this.executeRequest(context);
|
|
101
101
|
await this.sendResponse(context);
|
|
102
102
|
}
|
|
@@ -613,7 +613,7 @@ export class HttpAdapterHost extends PlatformAdapterHost {
|
|
|
613
613
|
if (returnType) {
|
|
614
614
|
if (response.value == null)
|
|
615
615
|
throw new InternalServerError(`"${request.endpoint.name}" endpoint should return value`);
|
|
616
|
-
if (returnType.
|
|
616
|
+
if (!returnType.isAnonymous) {
|
|
617
617
|
const ns = this.api.getDataTypeNs(returnType);
|
|
618
618
|
// const isOpraSpec = returnType.document.url?.startsWith('https://oprajs.com/spec/v1.0')
|
|
619
619
|
body.type = (ns ? ns + ':' : '') + returnType.name;
|
package/esm/request-context.js
CHANGED
|
@@ -4,7 +4,9 @@ export class ApiService {
|
|
|
4
4
|
throw new Error(`No context assigned for ${Object.getPrototypeOf(this).constructor.name}`);
|
|
5
5
|
return this._context;
|
|
6
6
|
}
|
|
7
|
-
forContext(context) {
|
|
7
|
+
forContext(context, options) {
|
|
8
|
+
if (this._context === context && !options?.newInstance)
|
|
9
|
+
return this;
|
|
8
10
|
const instance = { context };
|
|
9
11
|
Object.setPrototypeOf(instance, this);
|
|
10
12
|
return instance;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"BAD_REQUEST": "Bad request",
|
|
3
|
+
"FAILED_DEPENDENCY": "The request failed due to failure of a previous request",
|
|
4
|
+
"FORBIDDEN": "You are not authorized to perform this action",
|
|
5
|
+
"INTERNAL_SERVER_ERROR": "Internal server error",
|
|
6
|
+
"METHOD_NOT_ALLOWED": "Method not allowed",
|
|
7
|
+
"NOT_ACCEPTABLE": "Not acceptable",
|
|
8
|
+
"NOT_FOUND": "Not found",
|
|
9
|
+
"UNAUTHORIZED": "You have not been authenticated to perform this action",
|
|
10
|
+
"UNPROCESSABLE_ENTITY": "Unprocessable entity",
|
|
11
|
+
"REQUEST_VALIDATION": "Request validation failed",
|
|
12
|
+
"RESPONSE_VALIDATION": "Response validation failed",
|
|
13
|
+
"RESOURCE_NOT_FOUND": "Resource not found",
|
|
14
|
+
"RESOURCE_CONFLICT": "There is already an other {{resource}} resource with same field values ({{fields}})",
|
|
15
|
+
"OPERATION_FORBIDDEN": "The {{resource}} resource does not accept '{{operation}}' operations",
|
|
16
|
+
"ACTION_NOT_FOUND": "The {{resource}} resource doesn't have an action named '{{action}}'",
|
|
17
|
+
"UNKNOWN_FIELD": "Unknown field '{{field}}'",
|
|
18
|
+
"UNACCEPTED_SORT_FIELD": "Field '{{field}}' is not available for sort operation",
|
|
19
|
+
"UNACCEPTED_FILTER_FIELD": "Field '{{field}}' is not available for filter operation",
|
|
20
|
+
"UNACCEPTED_FILTER_OPERATION": "'{{operation}}' for field '{{field}}' is not available for filter operation"
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/core",
|
|
3
|
-
"version": "0.31.
|
|
3
|
+
"version": "0.31.5",
|
|
4
4
|
"description": "Opra schema package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,18 +21,19 @@
|
|
|
21
21
|
"lint": "eslint . --max-warnings=0",
|
|
22
22
|
"test": "jest",
|
|
23
23
|
"cover": "jest --collect-coverage",
|
|
24
|
-
"clean": "npm run clean:src && npm run clean:dist && npm run clean:cover",
|
|
25
|
-
"clean:src": "ts-cleanup -s src --all
|
|
26
|
-
"clean:
|
|
27
|
-
"clean:
|
|
24
|
+
"clean": "npm run clean:src && npm run clean:test && npm run clean:dist && npm run clean:cover",
|
|
25
|
+
"clean:src": "ts-cleanup -s src --all",
|
|
26
|
+
"clean:test": "ts-cleanup -s test --all",
|
|
27
|
+
"clean:dist": "rimraf ../../build/client",
|
|
28
|
+
"clean:cover": "rimraf ../../coverage/client"
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
30
31
|
"@browsery/type-is": "^0.6.3",
|
|
31
|
-
"@opra/common": "^0.31.
|
|
32
|
+
"@opra/common": "^0.31.5",
|
|
32
33
|
"accepts": "^1.3.8",
|
|
33
34
|
"content-disposition": "^0.5.4",
|
|
34
35
|
"content-type": "^1.0.5",
|
|
35
|
-
"cookie": "^0.
|
|
36
|
+
"cookie": "^0.6.0",
|
|
36
37
|
"cookie-signature": "^1.2.1",
|
|
37
38
|
"encodeurl": "^1.0.2",
|
|
38
39
|
"formidable": "^3.5.1",
|
|
@@ -49,20 +50,20 @@
|
|
|
49
50
|
"express": "^4.x.x || ^5.x.x"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
|
-
"@faker-js/faker": "^8.
|
|
53
|
-
"@types/accepts": "^1.3.
|
|
54
|
-
"@types/content-disposition": "^0.5.
|
|
55
|
-
"@types/content-type": "^1.1.
|
|
56
|
-
"@types/cookie": "^0.5.
|
|
57
|
-
"@types/cookie-signature": "^1.1.
|
|
58
|
-
"@types/encodeurl": "^1.0.
|
|
59
|
-
"@types/express": "^4.17.
|
|
60
|
-
"@types/formidable": "^3.4.
|
|
61
|
-
"@types/fresh": "^0.5.
|
|
62
|
-
"@types/mime-types": "^2.1.
|
|
63
|
-
"@types/range-parser": "^1.2.
|
|
64
|
-
"@types/type-is": "^1.6.
|
|
65
|
-
"@types/vary": "^1.1.
|
|
53
|
+
"@faker-js/faker": "^8.3.1",
|
|
54
|
+
"@types/accepts": "^1.3.7",
|
|
55
|
+
"@types/content-disposition": "^0.5.8",
|
|
56
|
+
"@types/content-type": "^1.1.8",
|
|
57
|
+
"@types/cookie": "^0.5.4",
|
|
58
|
+
"@types/cookie-signature": "^1.1.2",
|
|
59
|
+
"@types/encodeurl": "^1.0.2",
|
|
60
|
+
"@types/express": "^4.17.21",
|
|
61
|
+
"@types/formidable": "^3.4.5",
|
|
62
|
+
"@types/fresh": "^0.5.2",
|
|
63
|
+
"@types/mime-types": "^2.1.4",
|
|
64
|
+
"@types/range-parser": "^1.2.7",
|
|
65
|
+
"@types/type-is": "^1.6.6",
|
|
66
|
+
"@types/vary": "^1.1.3",
|
|
66
67
|
"crypto-browserify": "^3.12.0",
|
|
67
68
|
"path-browserify": "^1.0.1",
|
|
68
69
|
"ts-gems": "^2.5.0"
|
|
@@ -7,6 +7,9 @@ declare module "@opra/common" {
|
|
|
7
7
|
namespace Action {
|
|
8
8
|
interface Request extends StrictOmit<_Request, 'endpoint'> {
|
|
9
9
|
endpoint: _Action;
|
|
10
|
+
params: {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
};
|
|
10
13
|
}
|
|
11
14
|
interface Context extends Resource.Context {
|
|
12
15
|
}
|
|
@@ -34,6 +37,9 @@ declare module "@opra/common" {
|
|
|
34
37
|
name: 'delete';
|
|
35
38
|
};
|
|
36
39
|
key: any;
|
|
40
|
+
params: {
|
|
41
|
+
[key: string]: any;
|
|
42
|
+
};
|
|
37
43
|
}
|
|
38
44
|
interface Context extends RequestContext {
|
|
39
45
|
request: Request;
|
|
@@ -21,6 +21,7 @@ declare module "@opra/common" {
|
|
|
21
21
|
pick?: string[];
|
|
22
22
|
omit?: string[];
|
|
23
23
|
include?: string[];
|
|
24
|
+
[key: string]: any;
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
27
|
interface Context extends RequestContext {
|
|
@@ -46,6 +47,7 @@ declare module "@opra/common" {
|
|
|
46
47
|
pick?: string[];
|
|
47
48
|
omit?: string[];
|
|
48
49
|
include?: string[];
|
|
50
|
+
[key: string]: any;
|
|
49
51
|
};
|
|
50
52
|
}
|
|
51
53
|
interface Context extends RequestContext {
|
|
@@ -62,6 +64,7 @@ declare module "@opra/common" {
|
|
|
62
64
|
pick?: string[];
|
|
63
65
|
omit?: string[];
|
|
64
66
|
include?: string[];
|
|
67
|
+
[key: string]: any;
|
|
65
68
|
};
|
|
66
69
|
}
|
|
67
70
|
interface Context extends RequestContext {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { ApiDocument } from '@opra/common';
|
|
1
2
|
import type { ExecutionContext } from './execution-context.js';
|
|
2
3
|
import type { Request } from './request.js';
|
|
3
4
|
import type { Response } from './response.js';
|
|
4
5
|
export interface RequestContext extends ExecutionContext {
|
|
5
6
|
request: Request;
|
|
6
7
|
response: Response;
|
|
8
|
+
api: ApiDocument;
|
|
7
9
|
}
|
|
8
10
|
export declare namespace RequestContext {
|
|
9
|
-
function from(executionContext: ExecutionContext, request: Request, response: Response): RequestContext;
|
|
11
|
+
function from(executionContext: ExecutionContext, api: ApiDocument, request: Request, response: Response): RequestContext;
|
|
10
12
|
}
|
|
@@ -2,5 +2,7 @@ import { RequestContext } from '../request-context.js';
|
|
|
2
2
|
export declare abstract class ApiService {
|
|
3
3
|
protected _context: RequestContext;
|
|
4
4
|
get context(): RequestContext;
|
|
5
|
-
forContext(context: RequestContext
|
|
5
|
+
forContext(context: RequestContext, options?: {
|
|
6
|
+
newInstance?: boolean;
|
|
7
|
+
}): this;
|
|
6
8
|
}
|