@opra/core 1.0.0-alpha.2 → 1.0.0-alpha.3
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/impl/http-handler.js +13 -18
- package/esm/http/impl/http-handler.js +13 -18
- package/i18n/i18n/en/error.json +21 -0
- package/package.json +3 -3
|
@@ -482,28 +482,23 @@ class HttpHandler {
|
|
|
482
482
|
const { request, response } = context;
|
|
483
483
|
const { document } = this.adapter;
|
|
484
484
|
response.setHeader('content-type', common_1.MimeTypes.json);
|
|
485
|
+
const url = new URL(request.originalUrl || request.url || '/', 'http://tempuri.org');
|
|
486
|
+
const { searchParams } = url;
|
|
487
|
+
const documentId = searchParams.get('id');
|
|
488
|
+
const doc = documentId ? document.findDocument(documentId) : document;
|
|
489
|
+
if (!doc)
|
|
490
|
+
return this.sendErrorResponse(response, [
|
|
491
|
+
new common_1.BadRequestError({
|
|
492
|
+
message: `Document with given id [${documentId}] does not exists`,
|
|
493
|
+
}),
|
|
494
|
+
]);
|
|
485
495
|
/** Check if response cache exists */
|
|
486
|
-
let responseBody = this[constants_js_1.kAssetCache].get(
|
|
496
|
+
let responseBody = this[constants_js_1.kAssetCache].get(doc, `$schema`);
|
|
487
497
|
/** Create response if response cache does not exists */
|
|
488
498
|
if (!responseBody) {
|
|
489
|
-
const
|
|
490
|
-
const { searchParams } = url;
|
|
491
|
-
// const nsPath = searchParams.get('ns');
|
|
492
|
-
// if (nsPath) {
|
|
493
|
-
// const arr = nsPath.split('/');
|
|
494
|
-
// let doc = document;
|
|
495
|
-
// for (const a of arr) {
|
|
496
|
-
// }
|
|
497
|
-
// }
|
|
498
|
-
const schema = document.export({ references: searchParams.get('references') });
|
|
499
|
-
const dt = document.node.getComplexType('OperationResult');
|
|
500
|
-
let encode = this[constants_js_1.kAssetCache].get(dt, 'encode');
|
|
501
|
-
if (!encode) {
|
|
502
|
-
encode = dt.generateCodec('encode');
|
|
503
|
-
this[constants_js_1.kAssetCache].set(dt, 'encode', encode);
|
|
504
|
-
}
|
|
499
|
+
const schema = doc.export();
|
|
505
500
|
responseBody = JSON.stringify(schema);
|
|
506
|
-
this[constants_js_1.kAssetCache].set(
|
|
501
|
+
this[constants_js_1.kAssetCache].set(doc, `$schema`, responseBody);
|
|
507
502
|
}
|
|
508
503
|
response.end(responseBody);
|
|
509
504
|
}
|
|
@@ -478,28 +478,23 @@ export class HttpHandler {
|
|
|
478
478
|
const { request, response } = context;
|
|
479
479
|
const { document } = this.adapter;
|
|
480
480
|
response.setHeader('content-type', MimeTypes.json);
|
|
481
|
+
const url = new URL(request.originalUrl || request.url || '/', 'http://tempuri.org');
|
|
482
|
+
const { searchParams } = url;
|
|
483
|
+
const documentId = searchParams.get('id');
|
|
484
|
+
const doc = documentId ? document.findDocument(documentId) : document;
|
|
485
|
+
if (!doc)
|
|
486
|
+
return this.sendErrorResponse(response, [
|
|
487
|
+
new BadRequestError({
|
|
488
|
+
message: `Document with given id [${documentId}] does not exists`,
|
|
489
|
+
}),
|
|
490
|
+
]);
|
|
481
491
|
/** Check if response cache exists */
|
|
482
|
-
let responseBody = this[kAssetCache].get(
|
|
492
|
+
let responseBody = this[kAssetCache].get(doc, `$schema`);
|
|
483
493
|
/** Create response if response cache does not exists */
|
|
484
494
|
if (!responseBody) {
|
|
485
|
-
const
|
|
486
|
-
const { searchParams } = url;
|
|
487
|
-
// const nsPath = searchParams.get('ns');
|
|
488
|
-
// if (nsPath) {
|
|
489
|
-
// const arr = nsPath.split('/');
|
|
490
|
-
// let doc = document;
|
|
491
|
-
// for (const a of arr) {
|
|
492
|
-
// }
|
|
493
|
-
// }
|
|
494
|
-
const schema = document.export({ references: searchParams.get('references') });
|
|
495
|
-
const dt = document.node.getComplexType('OperationResult');
|
|
496
|
-
let encode = this[kAssetCache].get(dt, 'encode');
|
|
497
|
-
if (!encode) {
|
|
498
|
-
encode = dt.generateCodec('encode');
|
|
499
|
-
this[kAssetCache].set(dt, 'encode', encode);
|
|
500
|
-
}
|
|
495
|
+
const schema = doc.export();
|
|
501
496
|
responseBody = JSON.stringify(schema);
|
|
502
|
-
this[kAssetCache].set(
|
|
497
|
+
this[kAssetCache].set(doc, `$schema`, responseBody);
|
|
503
498
|
}
|
|
504
499
|
response.end(responseBody);
|
|
505
500
|
}
|
|
@@ -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_AVAILABLE": "Resource is not available or you dont have access",
|
|
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": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.3",
|
|
4
4
|
"description": "Opra schema package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@browsery/type-is": "^1.6.18-r2",
|
|
34
|
-
"@opra/common": "^1.0.0-alpha.
|
|
34
|
+
"@opra/common": "^1.0.0-alpha.3",
|
|
35
35
|
"@types/formidable": "^3.4.5",
|
|
36
36
|
"accepts": "^1.3.8",
|
|
37
37
|
"base64-stream": "^1.0.0",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"cookie-parser": "^1.4.6",
|
|
77
77
|
"crypto-browserify": "^3.12.0",
|
|
78
78
|
"express": "^4.19.2",
|
|
79
|
-
"fastify": "^4.
|
|
79
|
+
"fastify": "^4.28.0",
|
|
80
80
|
"path-browserify": "^1.0.1",
|
|
81
81
|
"ts-gems": "^3.4.0"
|
|
82
82
|
},
|