@opra/core 1.0.0-alpha.2 → 1.0.0-alpha.4
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/execution-context.js +0 -1
- package/cjs/http/express-adapter.js +0 -5
- package/cjs/http/impl/http-handler.js +13 -18
- package/esm/execution-context.js +0 -1
- package/esm/http/express-adapter.js +0 -5
- package/esm/http/impl/http-handler.js +13 -18
- package/package.json +5 -5
- package/types/execution-context.d.ts +0 -2
package/cjs/execution-context.js
CHANGED
|
@@ -11,7 +11,6 @@ class ExecutionContext extends strict_typed_events_1.AsyncEventEmitter {
|
|
|
11
11
|
this.document = init.document;
|
|
12
12
|
this.protocol = init.protocol;
|
|
13
13
|
this.platform = init.platform;
|
|
14
|
-
this.platformArgs = init.platformArgs;
|
|
15
14
|
}
|
|
16
15
|
addListener(event, listener) {
|
|
17
16
|
return super.addListener(event, listener);
|
|
@@ -65,14 +65,9 @@ class ExpressAdapter extends http_adapter_js_1.HttpAdapter {
|
|
|
65
65
|
const createContext = (_req, _res, args) => {
|
|
66
66
|
const request = http_incoming_interface_js_1.HttpIncoming.from(_req);
|
|
67
67
|
const response = http_outgoing_interface_js_1.HttpOutgoing.from(_res);
|
|
68
|
-
const platformArgs = {
|
|
69
|
-
request: _req,
|
|
70
|
-
response: _res,
|
|
71
|
-
};
|
|
72
68
|
return new http_context_js_1.HttpContext({
|
|
73
69
|
adapter: this,
|
|
74
70
|
platform: this.platform,
|
|
75
|
-
platformArgs,
|
|
76
71
|
request,
|
|
77
72
|
response,
|
|
78
73
|
controller: args?.controller,
|
|
@@ -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
|
}
|
package/esm/execution-context.js
CHANGED
|
@@ -8,7 +8,6 @@ export class ExecutionContext extends AsyncEventEmitter {
|
|
|
8
8
|
this.document = init.document;
|
|
9
9
|
this.protocol = init.protocol;
|
|
10
10
|
this.platform = init.platform;
|
|
11
|
-
this.platformArgs = init.platformArgs;
|
|
12
11
|
}
|
|
13
12
|
addListener(event, listener) {
|
|
14
13
|
return super.addListener(event, listener);
|
|
@@ -61,14 +61,9 @@ export class ExpressAdapter extends HttpAdapter {
|
|
|
61
61
|
const createContext = (_req, _res, args) => {
|
|
62
62
|
const request = HttpIncoming.from(_req);
|
|
63
63
|
const response = HttpOutgoing.from(_res);
|
|
64
|
-
const platformArgs = {
|
|
65
|
-
request: _req,
|
|
66
|
-
response: _res,
|
|
67
|
-
};
|
|
68
64
|
return new HttpContext({
|
|
69
65
|
adapter: this,
|
|
70
66
|
platform: this.platform,
|
|
71
|
-
platformArgs,
|
|
72
67
|
request,
|
|
73
68
|
response,
|
|
74
69
|
controller: args?.controller,
|
|
@@ -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
|
}
|
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.4",
|
|
4
4
|
"description": "Opra schema package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"lint": "eslint . --max-warnings=0",
|
|
22
22
|
"check": "madge --circular src/**",
|
|
23
23
|
"format": "prettier . --write --log-level=warn",
|
|
24
|
-
"test": "jest",
|
|
25
|
-
"cover": "jest --collect-coverage",
|
|
24
|
+
"test": "jest --passWithNoTests",
|
|
25
|
+
"cover": "jest --passWithNoTests --collect-coverage",
|
|
26
26
|
"clean": "npm run clean:src && npm run clean:test && npm run clean:dist && npm run clean:cover",
|
|
27
27
|
"clean:src": "ts-cleanup -s src --all",
|
|
28
28
|
"clean:test": "ts-cleanup -s test --all",
|
|
@@ -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.4",
|
|
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
|
},
|
|
@@ -8,7 +8,6 @@ export declare namespace ExecutionContext {
|
|
|
8
8
|
document: ApiDocument;
|
|
9
9
|
protocol: OpraSchema.Protocol;
|
|
10
10
|
platform: string;
|
|
11
|
-
platformArgs: any;
|
|
12
11
|
}
|
|
13
12
|
type OnFinishListener = (error: Error | undefined, context: ExecutionContext) => void | Promise<void>;
|
|
14
13
|
}
|
|
@@ -19,7 +18,6 @@ export declare abstract class ExecutionContext extends AsyncEventEmitter {
|
|
|
19
18
|
readonly document: ApiDocument;
|
|
20
19
|
readonly protocol: OpraSchema.Protocol;
|
|
21
20
|
readonly platform: string;
|
|
22
|
-
readonly platformArgs: any;
|
|
23
21
|
protected constructor(init: ExecutionContext.Initiator);
|
|
24
22
|
addListener(event: 'finish', listener: ExecutionContext.OnFinishListener): this;
|
|
25
23
|
removeListener(event: 'finish', listener: ExecutionContext.OnFinishListener): this;
|