@opra/core 0.25.4 → 0.26.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/http/adapters/express-adapter.host.js +34 -0
- package/cjs/{adapter/http → http/adapters}/express-adapter.js +1 -3
- package/cjs/{adapter/http/http-adapter.host.js → http/adapters/node-http-adapter.host.js} +30 -22
- package/cjs/http/adapters/node-http-adapter.js +14 -0
- package/cjs/http/helpers/json-body-loader.js +29 -0
- package/cjs/http/http-adapter-host.js +678 -0
- package/cjs/index.js +17 -16
- package/cjs/{adapter/platform-adapter.host.js → platform-adapter.host.js} +74 -45
- package/cjs/{adapter/endpoint-context.js → request-context.js} +5 -5
- package/cjs/{adapter/request.host.js → request.host.js} +3 -0
- package/cjs/response.js +2 -0
- package/esm/http/adapters/express-adapter.host.js +30 -0
- package/esm/{adapter/http → http/adapters}/express-adapter.js +1 -3
- package/esm/{adapter/http/http-adapter.host.js → http/adapters/node-http-adapter.host.js} +28 -20
- package/esm/http/adapters/node-http-adapter.js +11 -0
- package/esm/http/helpers/json-body-loader.js +24 -0
- package/esm/http/http-adapter-host.js +673 -0
- package/esm/index.js +17 -16
- package/esm/platform-adapter.host.js +132 -0
- package/esm/{adapter/endpoint-context.js → request-context.js} +4 -4
- package/esm/{adapter/request.host.js → request.host.js} +3 -0
- package/esm/response.js +1 -0
- package/i18n/en/error.json +1 -2
- package/package.json +3 -3
- package/types/augmentation/collection.augmentation.d.ts +26 -17
- package/types/augmentation/container.augmentation.d.ts +13 -0
- package/types/augmentation/resource.augmentation.d.ts +2 -2
- package/types/augmentation/singleton.augmentation.d.ts +14 -10
- package/types/augmentation/storage.augmentation.d.ts +16 -16
- package/types/{adapter/execution-context.d.ts → execution-context.d.ts} +3 -3
- package/types/{adapter/execution-context.host.d.ts → execution-context.host.d.ts} +1 -1
- package/types/{adapter/http → http/adapters}/express-adapter.d.ts +3 -3
- package/types/http/adapters/express-adapter.host.d.ts +12 -0
- package/types/{adapter/http/http-adapter.d.ts → http/adapters/node-http-adapter.d.ts} +5 -5
- package/types/http/adapters/node-http-adapter.host.d.ts +19 -0
- package/types/http/helpers/json-body-loader.d.ts +5 -0
- package/types/http/http-adapter-host.d.ts +34 -0
- package/types/{adapter/http → http}/impl/http-outgoing-message.host.d.ts +1 -1
- package/types/index.d.ts +17 -16
- package/types/{adapter/interfaces → interfaces}/request-handler.interface.d.ts +1 -1
- package/types/{adapter/platform-adapter.d.ts → platform-adapter.d.ts} +2 -2
- package/types/platform-adapter.host.d.ts +37 -0
- package/types/request-context.d.ts +10 -0
- package/types/{adapter/request.d.ts → request.d.ts} +8 -3
- package/types/{adapter/request.host.d.ts → request.host.d.ts} +7 -4
- package/types/{adapter/response.d.ts → response.d.ts} +1 -1
- package/types/{adapter/response.host.d.ts → response.host.d.ts} +2 -2
- package/cjs/adapter/http/express-adapter.host.js +0 -24
- package/cjs/adapter/http/http-adapter-base.js +0 -138
- package/cjs/adapter/http/http-adapter.js +0 -16
- package/cjs/adapter/http/request-handlers/entity-request-handler.js +0 -418
- package/cjs/adapter/http/request-handlers/parse-batch-request.js +0 -169
- package/cjs/adapter/http/request-handlers/request-handler-base.js +0 -27
- package/cjs/adapter/http/request-handlers/storage-request-handler.js +0 -133
- package/esm/adapter/http/express-adapter.host.js +0 -20
- package/esm/adapter/http/http-adapter-base.js +0 -134
- package/esm/adapter/http/http-adapter.js +0 -13
- package/esm/adapter/http/request-handlers/entity-request-handler.js +0 -413
- package/esm/adapter/http/request-handlers/parse-batch-request.js +0 -169
- package/esm/adapter/http/request-handlers/request-handler-base.js +0 -23
- package/esm/adapter/http/request-handlers/storage-request-handler.js +0 -128
- package/esm/adapter/platform-adapter.host.js +0 -103
- package/types/adapter/endpoint-context.d.ts +0 -10
- package/types/adapter/http/express-adapter.host.d.ts +0 -11
- package/types/adapter/http/http-adapter-base.d.ts +0 -23
- package/types/adapter/http/http-adapter.host.d.ts +0 -18
- package/types/adapter/http/request-handlers/entity-request-handler.d.ts +0 -24
- package/types/adapter/http/request-handlers/parse-batch-request.d.ts +0 -0
- package/types/adapter/http/request-handlers/request-handler-base.d.ts +0 -15
- package/types/adapter/http/request-handlers/storage-request-handler.d.ts +0 -23
- package/types/adapter/platform-adapter.host.d.ts +0 -33
- /package/cjs/{adapter/execution-context.js → augmentation/container.augmentation.js} +0 -0
- /package/cjs/{adapter/execution-context.host.js → execution-context.host.js} +0 -0
- /package/cjs/{adapter/interfaces/interceptor.interface.js → execution-context.js} +0 -0
- /package/cjs/{adapter/http → http}/helpers/common.js +0 -0
- /package/cjs/{adapter/http → http}/helpers/concat-readable.js +0 -0
- /package/cjs/{adapter/http → http}/helpers/convert-to-headers.js +0 -0
- /package/cjs/{adapter/http → http}/helpers/convert-to-raw-headers.js +0 -0
- /package/cjs/{adapter/http → http}/helpers/match-known-fields.js +0 -0
- /package/cjs/{adapter/http → http}/helpers/multipart-helper.js +0 -0
- /package/cjs/{adapter/http → http}/helpers/query-parsers.js +0 -0
- /package/cjs/{adapter/http → http}/http-server-request.js +0 -0
- /package/cjs/{adapter/http → http}/http-server-response.js +0 -0
- /package/cjs/{adapter/http → http}/impl/http-incoming-message.host.js +0 -0
- /package/cjs/{adapter/http → http}/impl/http-outgoing-message.host.js +0 -0
- /package/cjs/{adapter/interfaces/logger.interface.js → interfaces/interceptor.interface.js} +0 -0
- /package/cjs/{adapter/interfaces/request-handler.interface.js → interfaces/logger.interface.js} +0 -0
- /package/cjs/{adapter/platform-adapter.js → interfaces/request-handler.interface.js} +0 -0
- /package/cjs/{adapter/request.js → platform-adapter.js} +0 -0
- /package/cjs/{adapter/response.js → request.js} +0 -0
- /package/cjs/{adapter/response.host.js → response.host.js} +0 -0
- /package/cjs/{adapter/services → services}/logger.js +0 -0
- /package/esm/{adapter/execution-context.js → augmentation/container.augmentation.js} +0 -0
- /package/esm/{adapter/execution-context.host.js → execution-context.host.js} +0 -0
- /package/esm/{adapter/interfaces/interceptor.interface.js → execution-context.js} +0 -0
- /package/esm/{adapter/http → http}/helpers/common.js +0 -0
- /package/esm/{adapter/http → http}/helpers/concat-readable.js +0 -0
- /package/esm/{adapter/http → http}/helpers/convert-to-headers.js +0 -0
- /package/esm/{adapter/http → http}/helpers/convert-to-raw-headers.js +0 -0
- /package/esm/{adapter/http → http}/helpers/match-known-fields.js +0 -0
- /package/esm/{adapter/http → http}/helpers/multipart-helper.js +0 -0
- /package/esm/{adapter/http → http}/helpers/query-parsers.js +0 -0
- /package/esm/{adapter/http → http}/http-server-request.js +0 -0
- /package/esm/{adapter/http → http}/http-server-response.js +0 -0
- /package/esm/{adapter/http → http}/impl/http-incoming-message.host.js +0 -0
- /package/esm/{adapter/http → http}/impl/http-outgoing-message.host.js +0 -0
- /package/esm/{adapter/interfaces/logger.interface.js → interfaces/interceptor.interface.js} +0 -0
- /package/esm/{adapter/interfaces/request-handler.interface.js → interfaces/logger.interface.js} +0 -0
- /package/esm/{adapter/platform-adapter.js → interfaces/request-handler.interface.js} +0 -0
- /package/esm/{adapter/request.js → platform-adapter.js} +0 -0
- /package/esm/{adapter/response.js → request.js} +0 -0
- /package/esm/{adapter/response.host.js → response.host.js} +0 -0
- /package/esm/{adapter/services → services}/logger.js +0 -0
- /package/types/{adapter/http → http}/helpers/common.d.ts +0 -0
- /package/types/{adapter/http → http}/helpers/concat-readable.d.ts +0 -0
- /package/types/{adapter/http → http}/helpers/convert-to-headers.d.ts +0 -0
- /package/types/{adapter/http → http}/helpers/convert-to-raw-headers.d.ts +0 -0
- /package/types/{adapter/http → http}/helpers/match-known-fields.d.ts +0 -0
- /package/types/{adapter/http → http}/helpers/multipart-helper.d.ts +0 -0
- /package/types/{adapter/http → http}/helpers/query-parsers.d.ts +0 -0
- /package/types/{adapter/http → http}/http-server-request.d.ts +0 -0
- /package/types/{adapter/http → http}/http-server-response.d.ts +0 -0
- /package/types/{adapter/http → http}/impl/http-incoming-message.host.d.ts +0 -0
- /package/types/{adapter/interfaces → interfaces}/interceptor.interface.d.ts +0 -0
- /package/types/{adapter/interfaces → interfaces}/logger.interface.d.ts +0 -0
- /package/types/{adapter/services → services}/logger.d.ts +0 -0
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
import os from 'os';
|
|
3
|
-
import { BadRequestError, HttpStatusCodes, isReadable, OpraException, Storage, uid } from '@opra/common';
|
|
4
|
-
import { EndpointContext } from '../../endpoint-context.js';
|
|
5
|
-
import { RequestHost } from '../../request.host.js';
|
|
6
|
-
import { ResponseHost } from '../../response.host.js';
|
|
7
|
-
import { MultipartIterator } from '../helpers/multipart-helper.js';
|
|
8
|
-
import { RequestHandlerBase } from './request-handler-base.js';
|
|
9
|
-
/**
|
|
10
|
-
* @class StorageRequestHandler
|
|
11
|
-
*/
|
|
12
|
-
export class StorageRequestHandler extends RequestHandlerBase {
|
|
13
|
-
constructor(adapter, options) {
|
|
14
|
-
super(adapter);
|
|
15
|
-
this.adapter = adapter;
|
|
16
|
-
this._uploadDir = options?.uploadDir || os.tmpdir();
|
|
17
|
-
}
|
|
18
|
-
async processRequest(executionContext) {
|
|
19
|
-
const { incoming, outgoing } = executionContext.switchToHttp();
|
|
20
|
-
// Parse incoming message and create Request object
|
|
21
|
-
const request = await this.parseRequest(executionContext, incoming);
|
|
22
|
-
if (!request)
|
|
23
|
-
return;
|
|
24
|
-
const response = new ResponseHost({ http: outgoing });
|
|
25
|
-
const context = EndpointContext.from(executionContext, request, response);
|
|
26
|
-
await this.callEndpoint(context);
|
|
27
|
-
if (response.errors.length) {
|
|
28
|
-
context.errors.push(...response.errors);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
await this.sendResponse(context);
|
|
32
|
-
}
|
|
33
|
-
async parseRequest(executionContext, incoming) {
|
|
34
|
-
const contentId = incoming.headers['content-id'];
|
|
35
|
-
const p = incoming.parsedUrl.path[0];
|
|
36
|
-
const resource = this.adapter.api.getResource(p.resource);
|
|
37
|
-
try {
|
|
38
|
-
if (!(resource instanceof Storage))
|
|
39
|
-
return;
|
|
40
|
-
switch (incoming.method) {
|
|
41
|
-
case 'GET': {
|
|
42
|
-
const endpointMeta = await this.assertEndpoint(resource, 'get');
|
|
43
|
-
return new RequestHost({
|
|
44
|
-
controller: endpointMeta.controller,
|
|
45
|
-
http: incoming,
|
|
46
|
-
resource,
|
|
47
|
-
endpoint: 'get',
|
|
48
|
-
contentId
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
case 'DELETE': {
|
|
52
|
-
const endpointMeta = await this.assertEndpoint(resource, 'delete');
|
|
53
|
-
return new RequestHost({
|
|
54
|
-
controller: endpointMeta.controller,
|
|
55
|
-
http: incoming,
|
|
56
|
-
resource,
|
|
57
|
-
endpoint: 'delete',
|
|
58
|
-
contentId
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
case 'POST': {
|
|
62
|
-
const endpointMeta = await this.assertEndpoint(resource, 'post');
|
|
63
|
-
await fs.mkdir(this._uploadDir, { recursive: true });
|
|
64
|
-
const multipartIterator = new MultipartIterator(incoming, {
|
|
65
|
-
...endpointMeta,
|
|
66
|
-
filename: () => this.adapter.serviceName + '_p' + process.pid +
|
|
67
|
-
't' + String(Date.now()).substring(8) + 'r' + uid(12)
|
|
68
|
-
});
|
|
69
|
-
multipartIterator.pause();
|
|
70
|
-
// Add an hook to clean up files after request finished
|
|
71
|
-
executionContext.on('finish', async () => {
|
|
72
|
-
multipartIterator.cancel();
|
|
73
|
-
await multipartIterator.deleteFiles().catch(() => void 0);
|
|
74
|
-
});
|
|
75
|
-
return new RequestHost({
|
|
76
|
-
controller: endpointMeta.controller,
|
|
77
|
-
http: incoming,
|
|
78
|
-
resource,
|
|
79
|
-
endpoint: 'post',
|
|
80
|
-
contentId,
|
|
81
|
-
parts: multipartIterator
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
catch (e) {
|
|
87
|
-
if (e instanceof OpraException)
|
|
88
|
-
throw e;
|
|
89
|
-
throw new BadRequestError(e);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
async callEndpoint(context) {
|
|
93
|
-
const request = context.request;
|
|
94
|
-
const { response } = context;
|
|
95
|
-
// Call endpoint handler method
|
|
96
|
-
let value;
|
|
97
|
-
try {
|
|
98
|
-
value = await request.controller[request.endpoint].call(request.controller, context);
|
|
99
|
-
if (response.value == null)
|
|
100
|
-
response.value = value;
|
|
101
|
-
}
|
|
102
|
-
catch (error) {
|
|
103
|
-
response.errors.push(error);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
async sendResponse(context) {
|
|
107
|
-
const { response } = context;
|
|
108
|
-
const outgoing = response.switchToHttp();
|
|
109
|
-
outgoing.statusCode = outgoing.statusCode || HttpStatusCodes.OK;
|
|
110
|
-
if (response.value != null) {
|
|
111
|
-
if (typeof response.value === 'string') {
|
|
112
|
-
if (!outgoing.hasHeader('content-type'))
|
|
113
|
-
outgoing.setHeader('content-type', 'text/plain');
|
|
114
|
-
outgoing.send(response.value);
|
|
115
|
-
}
|
|
116
|
-
else if (Buffer.isBuffer(response.value) || isReadable(response.value)) {
|
|
117
|
-
if (!outgoing.hasHeader('content-type'))
|
|
118
|
-
outgoing.setHeader('content-type', 'application/octet-stream');
|
|
119
|
-
outgoing.send(response.value);
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
outgoing.setHeader('content-type', 'application/json; charset=utf-8');
|
|
123
|
-
outgoing.send(JSON.stringify(response.value));
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
outgoing.end();
|
|
127
|
-
}
|
|
128
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { pascalCase } from 'putil-varhelpers';
|
|
3
|
-
import { AsyncEventEmitter } from 'strict-typed-events';
|
|
4
|
-
import { getStackFileName, I18n, Resource } from '@opra/common';
|
|
5
|
-
import { Logger } from './services/logger.js';
|
|
6
|
-
/**
|
|
7
|
-
* @class PlatformAdapterHost
|
|
8
|
-
*/
|
|
9
|
-
export class PlatformAdapterHost extends AsyncEventEmitter {
|
|
10
|
-
constructor(api, options) {
|
|
11
|
-
super();
|
|
12
|
-
this.api = api;
|
|
13
|
-
this._controllers = new WeakMap();
|
|
14
|
-
this._initialized = false;
|
|
15
|
-
this._options = options || {};
|
|
16
|
-
this._interceptors = [...(options?.interceptors || [])];
|
|
17
|
-
this._logger = options?.logger && options.logger instanceof Logger
|
|
18
|
-
? options.logger
|
|
19
|
-
: new Logger({ instance: options?.logger });
|
|
20
|
-
// Assign events
|
|
21
|
-
if (options?.on) {
|
|
22
|
-
for (const [event, fn] of Object.entries(options.on)) {
|
|
23
|
-
/* istanbul ignore next */
|
|
24
|
-
if (typeof fn === 'function')
|
|
25
|
-
this.on(event, fn);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
// Make a safe service name
|
|
29
|
-
this._serviceName = pascalCase((api.info.title || '').replace(/[^a-z0-9_ ]/ig, '')) || 'OpraService';
|
|
30
|
-
if (!/^[a-z]/i.test(this._serviceName))
|
|
31
|
-
this._serviceName = 'X' + this._serviceName;
|
|
32
|
-
}
|
|
33
|
-
get platform() {
|
|
34
|
-
return this._platform;
|
|
35
|
-
}
|
|
36
|
-
get protocol() {
|
|
37
|
-
return this._protocol;
|
|
38
|
-
}
|
|
39
|
-
get serviceName() {
|
|
40
|
-
return this.api.info.title;
|
|
41
|
-
}
|
|
42
|
-
async close() {
|
|
43
|
-
const promises = [];
|
|
44
|
-
for (const r of this.api.resources.values()) {
|
|
45
|
-
const onShutdown = r.onShutdown;
|
|
46
|
-
if (onShutdown)
|
|
47
|
-
promises.push((async () => onShutdown.call(r.controller, r))());
|
|
48
|
-
}
|
|
49
|
-
await Promise.allSettled(promises);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Initializes the adapter
|
|
53
|
-
*/
|
|
54
|
-
async init() {
|
|
55
|
-
if (this._initialized)
|
|
56
|
-
return;
|
|
57
|
-
// Init I18n
|
|
58
|
-
if (this._options?.i18n instanceof I18n)
|
|
59
|
-
this._i18n = this._options.i18n;
|
|
60
|
-
else if (typeof this._options?.i18n === 'function')
|
|
61
|
-
this._i18n = await this._options.i18n();
|
|
62
|
-
else
|
|
63
|
-
this._i18n = await this._createI18n(this._options?.i18n);
|
|
64
|
-
this._i18n = this._i18n || I18n.defaultInstance;
|
|
65
|
-
if (!this._i18n.isInitialized)
|
|
66
|
-
await this._i18n.init();
|
|
67
|
-
// Initialize all resources
|
|
68
|
-
for (const resource of this.api.resources.values()) {
|
|
69
|
-
await this.getController(resource);
|
|
70
|
-
}
|
|
71
|
-
this._initialized = true;
|
|
72
|
-
}
|
|
73
|
-
async getController(resource) {
|
|
74
|
-
resource = typeof resource === 'object' && resource instanceof Resource
|
|
75
|
-
? resource : this.api.getResource(resource);
|
|
76
|
-
let controller = this._controllers.get(resource);
|
|
77
|
-
if (!controller) {
|
|
78
|
-
if (resource.controller) {
|
|
79
|
-
controller = typeof resource.controller === 'function' ?
|
|
80
|
-
new resource.controller()
|
|
81
|
-
: resource.controller;
|
|
82
|
-
// Initialize controller
|
|
83
|
-
if (typeof controller.onInit === 'function')
|
|
84
|
-
await controller.onInit.call(controller);
|
|
85
|
-
this._controllers.set(resource, controller);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return controller;
|
|
89
|
-
}
|
|
90
|
-
async _createI18n(options) {
|
|
91
|
-
const opts = {
|
|
92
|
-
...options,
|
|
93
|
-
};
|
|
94
|
-
delete opts.resourceDirs;
|
|
95
|
-
const instance = I18n.createInstance(opts);
|
|
96
|
-
await instance.init();
|
|
97
|
-
await instance.loadResourceDir(path.resolve(getStackFileName(), '../../../i18n'));
|
|
98
|
-
if (options?.resourceDirs)
|
|
99
|
-
for (const dir of options.resourceDirs)
|
|
100
|
-
await instance.loadResourceDir(dir);
|
|
101
|
-
return instance;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { ExecutionContext } from './execution-context';
|
|
2
|
-
import type { Request } from './request';
|
|
3
|
-
import type { Response } from './response';
|
|
4
|
-
export interface EndpointContext<TSession extends {} = {}> extends ExecutionContext<TSession> {
|
|
5
|
-
request: Request;
|
|
6
|
-
response: Response;
|
|
7
|
-
}
|
|
8
|
-
export declare namespace EndpointContext {
|
|
9
|
-
function from(executionContext: ExecutionContext, request: Request, response: Response): EndpointContext;
|
|
10
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Application } from 'express';
|
|
2
|
-
import { ApiDocument } from '@opra/common';
|
|
3
|
-
import type { ExpressAdapter } from './express-adapter';
|
|
4
|
-
import { HttpAdapterBase } from './http-adapter-base.js';
|
|
5
|
-
export declare class ExpressAdapterHost extends HttpAdapterBase implements ExpressAdapter {
|
|
6
|
-
_platform: string;
|
|
7
|
-
_options: ExpressAdapter.Options;
|
|
8
|
-
_app: Application;
|
|
9
|
-
constructor(app: Application, api: ApiDocument, options?: ExpressAdapter.Options);
|
|
10
|
-
get app(): Application;
|
|
11
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { ExecutionContext } from '../execution-context.js';
|
|
2
|
-
import { RequestHandler } from '../interfaces/request-handler.interface.js';
|
|
3
|
-
import type { Protocol } from '../platform-adapter';
|
|
4
|
-
import { PlatformAdapterHost } from '../platform-adapter.host.js';
|
|
5
|
-
import { HttpServerRequest } from './http-server-request.js';
|
|
6
|
-
import { HttpServerResponse } from './http-server-response.js';
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* @class HttpAdapterBase
|
|
10
|
-
*/
|
|
11
|
-
export declare abstract class HttpAdapterBase extends PlatformAdapterHost {
|
|
12
|
-
_protocol: Protocol;
|
|
13
|
-
_requestHandlers: RequestHandler[];
|
|
14
|
-
/**
|
|
15
|
-
* Main http request handler
|
|
16
|
-
* @param incoming
|
|
17
|
-
* @param outgoing
|
|
18
|
-
* @protected
|
|
19
|
-
*/
|
|
20
|
-
protected handleIncoming(incoming: HttpServerRequest, outgoing: HttpServerResponse): Promise<void>;
|
|
21
|
-
processRequest(context: ExecutionContext): Promise<void>;
|
|
22
|
-
protected handleError(context: ExecutionContext): Promise<void>;
|
|
23
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import http from 'http';
|
|
3
|
-
import { ApiDocument, OpraURLPath } from '@opra/common';
|
|
4
|
-
import type { HttpAdapter } from './http-adapter';
|
|
5
|
-
import { HttpAdapterBase } from './http-adapter-base.js';
|
|
6
|
-
/**
|
|
7
|
-
* @class HttpAdapterHost
|
|
8
|
-
*/
|
|
9
|
-
export declare class HttpAdapterHost extends HttpAdapterBase implements HttpAdapter {
|
|
10
|
-
_basePath: OpraURLPath;
|
|
11
|
-
_options: HttpAdapter.Options;
|
|
12
|
-
_server: http.Server;
|
|
13
|
-
constructor(api: ApiDocument, options?: HttpAdapter.Options);
|
|
14
|
-
get basePath(): OpraURLPath;
|
|
15
|
-
get server(): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
16
|
-
protected _serverListener(incomingMessage: http.IncomingMessage, serverResponse: http.ServerResponse): void;
|
|
17
|
-
close(): Promise<void>;
|
|
18
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Collection, OpraSchema, Singleton } from '@opra/common';
|
|
2
|
-
import { EndpointContext } from '../../endpoint-context.js';
|
|
3
|
-
import { ExecutionContext } from '../../execution-context.js';
|
|
4
|
-
import { Request } from '../../request.js';
|
|
5
|
-
import type { HttpAdapterBase } from '../http-adapter-base.js';
|
|
6
|
-
import { HttpServerRequest } from '../http-server-request.js';
|
|
7
|
-
import { RequestHandlerBase } from './request-handler-base.js';
|
|
8
|
-
type BodyLoaderFunction = (incoming: HttpServerRequest) => Promise<any>;
|
|
9
|
-
/**
|
|
10
|
-
* @class EntityRequestHandler
|
|
11
|
-
*/
|
|
12
|
-
export declare class EntityRequestHandler extends RequestHandlerBase {
|
|
13
|
-
readonly adapter: HttpAdapterBase;
|
|
14
|
-
readonly bodyLoaders: WeakMap<Object, BodyLoaderFunction>;
|
|
15
|
-
constructor(adapter: HttpAdapterBase);
|
|
16
|
-
processRequest(executionContext: ExecutionContext): Promise<void>;
|
|
17
|
-
parseRequest(incoming: HttpServerRequest): Promise<Request | undefined>;
|
|
18
|
-
callEndpoint(context: EndpointContext): Promise<void>;
|
|
19
|
-
sendResponse(context: EndpointContext): Promise<void>;
|
|
20
|
-
parseCollectionRequest(resource: Collection, incoming: HttpServerRequest): Promise<Request>;
|
|
21
|
-
parseSingletonRequest(resource: Singleton, incoming: HttpServerRequest): Promise<Request>;
|
|
22
|
-
getBodyLoader(endpoint: OpraSchema.Collection.CreateEndpoint | OpraSchema.Collection.UpdateEndpoint | OpraSchema.Collection.UpdateManyEndpoint): BodyLoaderFunction;
|
|
23
|
-
}
|
|
24
|
-
export {};
|
|
File without changes
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { OpraSchema, Resource } from '@opra/common';
|
|
2
|
-
import type { ExecutionContext } from '../../execution-context';
|
|
3
|
-
import type { RequestHandler } from '../../interfaces/request-handler.interface';
|
|
4
|
-
import type { HttpAdapterBase } from '../http-adapter-base';
|
|
5
|
-
/**
|
|
6
|
-
* @class RequestHandlerBase
|
|
7
|
-
*/
|
|
8
|
-
export declare abstract class RequestHandlerBase implements RequestHandler {
|
|
9
|
-
readonly adapter: HttpAdapterBase;
|
|
10
|
-
protected constructor(adapter: HttpAdapterBase);
|
|
11
|
-
abstract processRequest(executionContext: ExecutionContext): Promise<void>;
|
|
12
|
-
assertEndpoint<T extends OpraSchema.Endpoint = OpraSchema.Endpoint>(resource: Resource, endpoint: string): Promise<T & {
|
|
13
|
-
controller: any;
|
|
14
|
-
}>;
|
|
15
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { EndpointContext } from '../../endpoint-context.js';
|
|
2
|
-
import type { ExecutionContext } from '../../execution-context';
|
|
3
|
-
import { Request } from '../../request.js';
|
|
4
|
-
import type { HttpAdapterBase } from '../http-adapter-base.js';
|
|
5
|
-
import { HttpServerRequest } from '../http-server-request.js';
|
|
6
|
-
import { RequestHandlerBase } from './request-handler-base.js';
|
|
7
|
-
export declare namespace StorageRequestHandler {
|
|
8
|
-
interface Options {
|
|
9
|
-
uploadDir?: string;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* @class StorageRequestHandler
|
|
14
|
-
*/
|
|
15
|
-
export declare class StorageRequestHandler extends RequestHandlerBase {
|
|
16
|
-
readonly adapter: HttpAdapterBase;
|
|
17
|
-
_uploadDir: string;
|
|
18
|
-
constructor(adapter: HttpAdapterBase, options?: StorageRequestHandler.Options);
|
|
19
|
-
processRequest(executionContext: ExecutionContext): Promise<void>;
|
|
20
|
-
parseRequest(executionContext: ExecutionContext, incoming: HttpServerRequest): Promise<Request | undefined>;
|
|
21
|
-
callEndpoint(context: EndpointContext): Promise<void>;
|
|
22
|
-
sendResponse(context: EndpointContext): Promise<void>;
|
|
23
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { AsyncEventEmitter } from 'strict-typed-events';
|
|
2
|
-
import { ApiDocument, I18n, Resource } from '@opra/common';
|
|
3
|
-
import { ExecutionContext } from './execution-context.js';
|
|
4
|
-
import { Interceptor } from './interfaces/interceptor.interface.js';
|
|
5
|
-
import type { PlatformAdapter, Protocol } from './platform-adapter';
|
|
6
|
-
import { Logger } from './services/logger.js';
|
|
7
|
-
/**
|
|
8
|
-
* @class PlatformAdapterHost
|
|
9
|
-
*/
|
|
10
|
-
export declare abstract class PlatformAdapterHost extends AsyncEventEmitter implements PlatformAdapter {
|
|
11
|
-
readonly api: ApiDocument;
|
|
12
|
-
_controllers: WeakMap<Resource, any>;
|
|
13
|
-
_protocol: Protocol;
|
|
14
|
-
_platform: string;
|
|
15
|
-
_initialized: boolean;
|
|
16
|
-
_serviceName: string;
|
|
17
|
-
_options: PlatformAdapter.Options;
|
|
18
|
-
_i18n: I18n;
|
|
19
|
-
_logger: Logger;
|
|
20
|
-
_interceptors: Interceptor[];
|
|
21
|
-
protected constructor(api: ApiDocument, options?: PlatformAdapter.Options);
|
|
22
|
-
get platform(): string;
|
|
23
|
-
get protocol(): Protocol;
|
|
24
|
-
get serviceName(): string;
|
|
25
|
-
close(): Promise<void>;
|
|
26
|
-
/**
|
|
27
|
-
* Initializes the adapter
|
|
28
|
-
*/
|
|
29
|
-
init(): Promise<void>;
|
|
30
|
-
getController(resource: Resource | string): Promise<any>;
|
|
31
|
-
protected _createI18n(options?: PlatformAdapter.I18nOptions): Promise<I18n>;
|
|
32
|
-
abstract processRequest(executionContext: ExecutionContext): Promise<void>;
|
|
33
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/cjs/{adapter/interfaces/request-handler.interface.js → interfaces/logger.interface.js}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/esm/{adapter/interfaces/request-handler.interface.js → interfaces/logger.interface.js}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|