@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
package/esm/index.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
import './augmentation/resource.augmentation.js';
|
|
3
3
|
import './augmentation/collection.augmentation.js';
|
|
4
|
+
import './augmentation/container.augmentation.js';
|
|
4
5
|
import './augmentation/singleton.augmentation.js';
|
|
5
6
|
import './augmentation/storage.augmentation.js';
|
|
6
7
|
export * from './types.js';
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './
|
|
12
|
-
export * from './
|
|
13
|
-
export * from './
|
|
14
|
-
export * from './
|
|
15
|
-
export * from './
|
|
16
|
-
export * from './
|
|
17
|
-
export * from './
|
|
18
|
-
export * from './
|
|
19
|
-
export * from './
|
|
20
|
-
export * from './
|
|
21
|
-
export * from './
|
|
22
|
-
export * from './
|
|
8
|
+
export * from './execution-context.js';
|
|
9
|
+
export * from './request-context.js';
|
|
10
|
+
export * from './platform-adapter.js';
|
|
11
|
+
export * from './request.js';
|
|
12
|
+
export * from './response.js';
|
|
13
|
+
export * from './http/adapters/express-adapter.js';
|
|
14
|
+
export * from './http/adapters/node-http-adapter.js';
|
|
15
|
+
export * from './http/impl/http-incoming-message.host.js';
|
|
16
|
+
export * from './http/impl/http-outgoing-message.host.js';
|
|
17
|
+
export * from './http/http-server-request.js';
|
|
18
|
+
export * from './http/http-server-response.js';
|
|
19
|
+
export * from './http/helpers/multipart-helper.js';
|
|
20
|
+
export * from './interfaces/interceptor.interface.js';
|
|
21
|
+
export * from './interfaces/logger.interface.js';
|
|
22
|
+
export * from './interfaces/request-handler.interface.js';
|
|
23
|
+
export * from './services/logger.js';
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { pascalCase } from 'putil-varhelpers';
|
|
3
|
+
import { AsyncEventEmitter } from 'strict-typed-events';
|
|
4
|
+
import { Container, CrudResource, ForbiddenError, getStackFileName, I18n, Resource, translate } from '@opra/common';
|
|
5
|
+
import { Logger } from './services/logger.js';
|
|
6
|
+
const resourceInitialized = Symbol.for('opra.resource.initialized');
|
|
7
|
+
/**
|
|
8
|
+
* @class PlatformAdapterHost
|
|
9
|
+
*/
|
|
10
|
+
export class PlatformAdapterHost extends AsyncEventEmitter {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this._controllers = new Map();
|
|
14
|
+
}
|
|
15
|
+
get api() {
|
|
16
|
+
return this._api;
|
|
17
|
+
}
|
|
18
|
+
get platform() {
|
|
19
|
+
return this._platform;
|
|
20
|
+
}
|
|
21
|
+
get protocol() {
|
|
22
|
+
return this._protocol;
|
|
23
|
+
}
|
|
24
|
+
get serviceName() {
|
|
25
|
+
return this._serviceName;
|
|
26
|
+
}
|
|
27
|
+
get i18n() {
|
|
28
|
+
return this._i18n;
|
|
29
|
+
}
|
|
30
|
+
async close() {
|
|
31
|
+
const promises = [];
|
|
32
|
+
for (const r of this._controllers.values()) {
|
|
33
|
+
const onShutdown = r?.onShutdown;
|
|
34
|
+
if (onShutdown)
|
|
35
|
+
promises.push((async () => onShutdown.call(r.controller, r))());
|
|
36
|
+
}
|
|
37
|
+
await Promise.allSettled(promises);
|
|
38
|
+
this._controllers.clear();
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Initializes the adapter
|
|
42
|
+
*/
|
|
43
|
+
async init(api, options) {
|
|
44
|
+
if (this._api)
|
|
45
|
+
throw new Error(`Already initialized`);
|
|
46
|
+
this._api = api;
|
|
47
|
+
this._interceptors = [...(options?.interceptors || [])];
|
|
48
|
+
this._logger = options?.logger && options.logger instanceof Logger
|
|
49
|
+
? options.logger
|
|
50
|
+
: new Logger({ instance: options?.logger });
|
|
51
|
+
// Assign events
|
|
52
|
+
if (options?.on) {
|
|
53
|
+
for (const [event, fn] of Object.entries(options.on)) {
|
|
54
|
+
/* istanbul ignore next */
|
|
55
|
+
if (typeof fn === 'function')
|
|
56
|
+
this.on(event, fn);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Make a safe service name
|
|
60
|
+
this._serviceName = pascalCase((api.info.title || '').replace(/[^a-z0-9_ ]/ig, '')) || 'OpraService';
|
|
61
|
+
if (!/^[a-z]/i.test(this._serviceName))
|
|
62
|
+
this._serviceName = 'X' + this._serviceName;
|
|
63
|
+
// Init I18n
|
|
64
|
+
if (options?.i18n instanceof I18n)
|
|
65
|
+
this._i18n = options.i18n;
|
|
66
|
+
else if (typeof options?.i18n === 'function')
|
|
67
|
+
this._i18n = await options.i18n();
|
|
68
|
+
else
|
|
69
|
+
this._i18n = await this._createI18n(options?.i18n);
|
|
70
|
+
this._i18n = this._i18n || I18n.defaultInstance;
|
|
71
|
+
if (!this._i18n.isInitialized)
|
|
72
|
+
await this._i18n.init();
|
|
73
|
+
// Initialize all resources
|
|
74
|
+
await this.getController(this.api.root);
|
|
75
|
+
}
|
|
76
|
+
async getController(resource) {
|
|
77
|
+
resource = typeof resource === 'object' && resource instanceof Resource
|
|
78
|
+
? resource : this.api.getResource(resource);
|
|
79
|
+
let controller = this._controllers.get(resource);
|
|
80
|
+
if (!controller) {
|
|
81
|
+
controller = resource.controller;
|
|
82
|
+
if (!controller && resource.ctor) {
|
|
83
|
+
controller = new resource.ctor();
|
|
84
|
+
}
|
|
85
|
+
this._controllers.set(resource, controller);
|
|
86
|
+
}
|
|
87
|
+
if (controller && !controller[resourceInitialized]) {
|
|
88
|
+
controller[resourceInitialized] = true;
|
|
89
|
+
// Initialize controller
|
|
90
|
+
if (typeof controller.onInit === 'function')
|
|
91
|
+
await controller.onInit.call(controller);
|
|
92
|
+
// Initialize sub resources of Container
|
|
93
|
+
if (resource instanceof Container) {
|
|
94
|
+
for (const r of resource.resources.values()) {
|
|
95
|
+
await this.getController(r);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return controller;
|
|
100
|
+
}
|
|
101
|
+
async getOperationHandler(resource, operationOrAction) {
|
|
102
|
+
resource = typeof resource === 'object' && resource instanceof Resource
|
|
103
|
+
? resource
|
|
104
|
+
: this.api.getResource(resource);
|
|
105
|
+
const controller = await this.getController(resource);
|
|
106
|
+
const endpoint = (resource instanceof CrudResource && resource.operations.get(operationOrAction)) ||
|
|
107
|
+
resource.actions.get(operationOrAction);
|
|
108
|
+
if (endpoint) {
|
|
109
|
+
const handler = typeof controller[operationOrAction] === 'function' ? controller[operationOrAction] : undefined;
|
|
110
|
+
if (handler)
|
|
111
|
+
return { controller, endpoint, handler };
|
|
112
|
+
}
|
|
113
|
+
throw new ForbiddenError({
|
|
114
|
+
message: translate('OPERATION_FORBIDDEN', { resource: resource.name, endpoint: operationOrAction }, `'{{resource}}' does not accept '{{endpoint}}' operations`),
|
|
115
|
+
severity: 'error',
|
|
116
|
+
code: 'OPERATION_FORBIDDEN'
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
async _createI18n(options) {
|
|
120
|
+
const opts = {
|
|
121
|
+
...options,
|
|
122
|
+
};
|
|
123
|
+
delete opts.resourceDirs;
|
|
124
|
+
const instance = I18n.createInstance(opts);
|
|
125
|
+
await instance.init();
|
|
126
|
+
await instance.loadResourceDir(path.resolve(getStackFileName(), '../../../i18n'));
|
|
127
|
+
if (options?.resourceDirs)
|
|
128
|
+
for (const dir of options.resourceDirs)
|
|
129
|
+
await instance.loadResourceDir(dir);
|
|
130
|
+
return instance;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export var
|
|
2
|
-
(function (
|
|
1
|
+
export var RequestContext;
|
|
2
|
+
(function (RequestContext) {
|
|
3
3
|
function from(executionContext, request, response) {
|
|
4
4
|
const out = {
|
|
5
5
|
request,
|
|
@@ -9,5 +9,5 @@ export var EndpointContext;
|
|
|
9
9
|
Object.setPrototypeOf(out, executionContext);
|
|
10
10
|
return out;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
})(
|
|
12
|
+
RequestContext.from = from;
|
|
13
|
+
})(RequestContext || (RequestContext = {}));
|
package/esm/response.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/i18n/en/error.json
CHANGED
|
@@ -8,12 +8,11 @@
|
|
|
8
8
|
"NOT_FOUND": "Not found",
|
|
9
9
|
"UNAUTHORIZED": "You have not been authenticated to perform this action",
|
|
10
10
|
"UNPROCESSABLE_ENTITY": "Unprocessable entity",
|
|
11
|
-
"SOURCE_NOT_FOUND": "Source not found",
|
|
12
11
|
"REQUEST_VALIDATION": "Request validation failed",
|
|
13
12
|
"RESPONSE_VALIDATION": "Response validation failed",
|
|
14
13
|
"RESOURCE_NOT_FOUND": "Resource not found",
|
|
15
14
|
"RESOURCE_CONFLICT": "There is already an other {{resource}} resource with same field values ({{fields}})",
|
|
16
|
-
"
|
|
15
|
+
"OPERATION_FORBIDDEN": "The {{resource}} endpoint does not accept '{{endpoint}}' operations",
|
|
17
16
|
"UNKNOWN_FIELD": "Unknown field '{{field}}'",
|
|
18
17
|
"UNACCEPTED_SORT_FIELD": "Field '{{field}}' is not available for sort operation",
|
|
19
18
|
"UNACCEPTED_FILTER_FIELD": "Field '{{field}}' is not available for filter operation",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "Opra schema package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"clean:cover": "rimraf ../../coverage/core"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@opra/common": "^0.
|
|
30
|
+
"@opra/common": "^0.26.0",
|
|
31
31
|
"accepts": "^1.3.8",
|
|
32
32
|
"content-disposition": "^0.5.4",
|
|
33
33
|
"content-type": "^1.0.5",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"@types/vary": "^1.1.0",
|
|
66
66
|
"crypto-browserify": "^3.12.0",
|
|
67
67
|
"path-browserify": "^1.0.1",
|
|
68
|
-
"ts-gems": "^2.
|
|
68
|
+
"ts-gems": "^2.5.0"
|
|
69
69
|
},
|
|
70
70
|
"type": "module",
|
|
71
71
|
"module": "./esm/index.js",
|
|
@@ -1,50 +1,55 @@
|
|
|
1
1
|
import type { PartialOutput } from '@opra/common';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
2
|
+
import type { Request as _Request } from '../request.js';
|
|
3
|
+
import type { RequestContext } from '../request-context';
|
|
4
4
|
declare module "@opra/common" {
|
|
5
5
|
namespace Collection {
|
|
6
6
|
namespace Action {
|
|
7
|
+
interface Request extends _Request {
|
|
8
|
+
operation: 'action';
|
|
9
|
+
action: string;
|
|
10
|
+
}
|
|
7
11
|
interface Context<TSession extends {} = {}> extends Resource.Context<TSession> {
|
|
8
|
-
key?: any;
|
|
9
12
|
}
|
|
10
13
|
}
|
|
11
14
|
namespace Create {
|
|
12
15
|
interface Request extends _Request {
|
|
13
|
-
|
|
16
|
+
operation: 'create';
|
|
14
17
|
data: any;
|
|
15
18
|
params: {
|
|
16
19
|
pick?: string[];
|
|
17
20
|
omit?: string[];
|
|
18
21
|
include?: string[];
|
|
22
|
+
[key: string]: any;
|
|
19
23
|
};
|
|
20
24
|
}
|
|
21
|
-
interface Context<TSession extends {} = {}> extends
|
|
25
|
+
interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
|
|
22
26
|
request: Request;
|
|
23
27
|
}
|
|
24
28
|
}
|
|
25
29
|
namespace Delete {
|
|
26
30
|
interface Request extends _Request {
|
|
27
|
-
|
|
31
|
+
operation: 'delete';
|
|
28
32
|
key: any;
|
|
29
33
|
}
|
|
30
|
-
interface Context<TSession extends {} = {}> extends
|
|
34
|
+
interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
|
|
31
35
|
request: Request;
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
38
|
namespace DeleteMany {
|
|
35
39
|
interface Request extends _Request {
|
|
36
|
-
|
|
40
|
+
operation: 'deleteMany';
|
|
37
41
|
params: {
|
|
38
42
|
filter?: any;
|
|
43
|
+
[key: string]: any;
|
|
39
44
|
};
|
|
40
45
|
}
|
|
41
|
-
interface Context<TSession extends {} = {}> extends
|
|
46
|
+
interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
|
|
42
47
|
request: Request;
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
50
|
namespace FindMany {
|
|
46
51
|
interface Request extends _Request {
|
|
47
|
-
|
|
52
|
+
operation: 'findMany';
|
|
48
53
|
params: {
|
|
49
54
|
filter?: any;
|
|
50
55
|
pick?: string[];
|
|
@@ -55,50 +60,54 @@ declare module "@opra/common" {
|
|
|
55
60
|
skip?: number;
|
|
56
61
|
distinct?: boolean;
|
|
57
62
|
count?: boolean;
|
|
63
|
+
[key: string]: any;
|
|
58
64
|
};
|
|
59
65
|
}
|
|
60
|
-
interface Context<TSession extends {} = {}> extends
|
|
66
|
+
interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
|
|
61
67
|
request: Request;
|
|
62
68
|
}
|
|
63
69
|
}
|
|
64
70
|
namespace Get {
|
|
65
71
|
interface Request extends _Request {
|
|
66
|
-
|
|
72
|
+
operation: 'get';
|
|
67
73
|
key: any;
|
|
68
74
|
params: {
|
|
69
75
|
pick?: string[];
|
|
70
76
|
omit?: string[];
|
|
71
77
|
include?: string[];
|
|
78
|
+
[key: string]: any;
|
|
72
79
|
};
|
|
73
80
|
}
|
|
74
|
-
interface Context<TSession extends {} = {}> extends
|
|
81
|
+
interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
|
|
75
82
|
request: Request;
|
|
76
83
|
}
|
|
77
84
|
}
|
|
78
85
|
namespace Update {
|
|
79
86
|
interface Request extends _Request {
|
|
80
|
-
|
|
87
|
+
operation: 'update';
|
|
81
88
|
key: any;
|
|
82
89
|
data: any;
|
|
83
90
|
params: {
|
|
84
91
|
pick?: string[];
|
|
85
92
|
omit?: string[];
|
|
86
93
|
include?: string[];
|
|
94
|
+
[key: string]: any;
|
|
87
95
|
};
|
|
88
96
|
}
|
|
89
|
-
interface Context<TSession extends {} = {}> extends
|
|
97
|
+
interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
|
|
90
98
|
request: Request;
|
|
91
99
|
}
|
|
92
100
|
}
|
|
93
101
|
namespace UpdateMany {
|
|
94
102
|
interface Request extends _Request {
|
|
95
|
-
|
|
103
|
+
operation: 'updateMany';
|
|
96
104
|
data: any;
|
|
97
105
|
params: {
|
|
98
106
|
filter?: any;
|
|
107
|
+
[key: string]: any;
|
|
99
108
|
};
|
|
100
109
|
}
|
|
101
|
-
interface Context<TSession extends {} = {}> extends
|
|
110
|
+
interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
|
|
102
111
|
request: Request;
|
|
103
112
|
}
|
|
104
113
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Request as _Request } from '../request.js';
|
|
2
|
+
declare module "@opra/common" {
|
|
3
|
+
namespace Container {
|
|
4
|
+
namespace Action {
|
|
5
|
+
interface Request extends _Request {
|
|
6
|
+
operation: 'action';
|
|
7
|
+
action: string;
|
|
8
|
+
}
|
|
9
|
+
interface Context<TSession extends {} = {}> extends Resource.Context<TSession> {
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RequestContext } from '../request-context.js';
|
|
2
2
|
declare module "@opra/common" {
|
|
3
3
|
interface CollectionConstructor {
|
|
4
4
|
OnInit(): any;
|
|
@@ -9,7 +9,7 @@ declare module "@opra/common" {
|
|
|
9
9
|
OnShutdown(): any;
|
|
10
10
|
}
|
|
11
11
|
namespace Resource {
|
|
12
|
-
interface Context<TSession extends {} = {}> extends
|
|
12
|
+
interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
|
|
13
13
|
params: Record<string, any>;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import type { PartialOutput } from '@opra/common';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
2
|
+
import type { Request as _Request } from '../request.js';
|
|
3
|
+
import type { RequestContext } from '../request-context.js';
|
|
4
4
|
declare module "@opra/common" {
|
|
5
5
|
namespace Singleton {
|
|
6
6
|
namespace Action {
|
|
7
|
+
interface Request extends _Request {
|
|
8
|
+
operation: 'action';
|
|
9
|
+
action: string;
|
|
10
|
+
}
|
|
7
11
|
interface Context<TSession extends {} = {}> extends Resource.Context<TSession> {
|
|
8
12
|
}
|
|
9
13
|
}
|
|
10
14
|
namespace Create {
|
|
11
15
|
interface Request extends _Request {
|
|
12
|
-
|
|
16
|
+
operation: 'create';
|
|
13
17
|
data: any;
|
|
14
18
|
params: {
|
|
15
19
|
pick?: string[];
|
|
@@ -17,34 +21,34 @@ declare module "@opra/common" {
|
|
|
17
21
|
include?: string[];
|
|
18
22
|
};
|
|
19
23
|
}
|
|
20
|
-
interface Context<TSession extends {} = {}> extends
|
|
24
|
+
interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
|
|
21
25
|
request: Request;
|
|
22
26
|
}
|
|
23
27
|
}
|
|
24
28
|
namespace Delete {
|
|
25
29
|
interface Request extends _Request {
|
|
26
|
-
|
|
30
|
+
operation: 'delete';
|
|
27
31
|
}
|
|
28
|
-
interface Context<TSession extends {} = {}> extends
|
|
32
|
+
interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
|
|
29
33
|
request: Request;
|
|
30
34
|
}
|
|
31
35
|
}
|
|
32
36
|
namespace Get {
|
|
33
37
|
interface Request extends _Request {
|
|
34
|
-
|
|
38
|
+
operation: 'get';
|
|
35
39
|
params: {
|
|
36
40
|
pick?: string[];
|
|
37
41
|
omit?: string[];
|
|
38
42
|
include?: string[];
|
|
39
43
|
};
|
|
40
44
|
}
|
|
41
|
-
interface Context<TSession extends {} = {}> extends
|
|
45
|
+
interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
|
|
42
46
|
request: Request;
|
|
43
47
|
}
|
|
44
48
|
}
|
|
45
49
|
namespace Update {
|
|
46
50
|
interface Request extends _Request {
|
|
47
|
-
|
|
51
|
+
operation: 'update';
|
|
48
52
|
data: any;
|
|
49
53
|
params: {
|
|
50
54
|
pick?: string[];
|
|
@@ -52,7 +56,7 @@ declare module "@opra/common" {
|
|
|
52
56
|
include?: string[];
|
|
53
57
|
};
|
|
54
58
|
}
|
|
55
|
-
interface Context<TSession extends {} = {}> extends
|
|
59
|
+
interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
|
|
56
60
|
request: Request;
|
|
57
61
|
}
|
|
58
62
|
}
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
import type { EndpointContext } from '../adapter/endpoint-context';
|
|
5
|
-
import type { MultipartIterator } from '../adapter/http/helpers/multipart-helper';
|
|
6
|
-
import type { Request as _Request } from '../adapter/request.js';
|
|
1
|
+
import type { MultipartIterator } from '../http/helpers/multipart-helper';
|
|
2
|
+
import type { Request as _Request } from '../request.js';
|
|
3
|
+
import type { RequestContext } from '../request-context.js';
|
|
7
4
|
declare module "@opra/common" {
|
|
8
5
|
namespace Storage {
|
|
9
6
|
namespace Action {
|
|
7
|
+
interface Request extends _Request {
|
|
8
|
+
operation: 'action';
|
|
9
|
+
action: string;
|
|
10
|
+
}
|
|
10
11
|
interface Context<TSession extends {} = {}> extends Resource.Context<TSession> {
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
14
|
namespace Delete {
|
|
14
15
|
interface Request extends _Request {
|
|
16
|
+
operation: 'delete';
|
|
17
|
+
path?: string;
|
|
15
18
|
}
|
|
16
|
-
interface Context<TSession extends {} = {}> extends
|
|
19
|
+
interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
|
|
17
20
|
request: Request;
|
|
18
21
|
}
|
|
19
22
|
}
|
|
20
23
|
namespace Get {
|
|
21
24
|
interface Request extends _Request {
|
|
25
|
+
operation: 'get';
|
|
26
|
+
path?: string;
|
|
22
27
|
}
|
|
23
|
-
interface Context<TSession extends {} = {}> extends
|
|
28
|
+
interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
|
|
24
29
|
request: Request;
|
|
25
30
|
}
|
|
26
31
|
}
|
|
27
32
|
namespace Post {
|
|
28
33
|
interface Request extends _Request {
|
|
34
|
+
operation: 'post';
|
|
35
|
+
path?: string;
|
|
29
36
|
parts: MultipartIterator;
|
|
30
37
|
}
|
|
31
|
-
interface Context<TSession extends {} = {}> extends
|
|
38
|
+
interface Context<TSession extends {} = {}> extends RequestContext<TSession> {
|
|
32
39
|
request: Request;
|
|
33
40
|
}
|
|
34
41
|
}
|
|
35
42
|
}
|
|
36
|
-
interface IStorage {
|
|
37
|
-
delete?(context: Storage.Delete.Context): Promise<number | undefined>;
|
|
38
|
-
get?(context: Storage.Get.Context): Promise<Buffer | Readable | undefined>;
|
|
39
|
-
post?(context: Storage.Post.Context): Promise<void>;
|
|
40
|
-
onInit?(): Promise<void>;
|
|
41
|
-
onShutdown?(): Promise<void>;
|
|
42
|
-
}
|
|
43
43
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { HttpServerRequest } from './http/http-server-request';
|
|
2
|
-
import type { HttpServerResponse } from './http/http-server-response';
|
|
3
|
-
import type { Protocol } from './platform-adapter';
|
|
1
|
+
import type { HttpServerRequest } from './http/http-server-request.js';
|
|
2
|
+
import type { HttpServerResponse } from './http/http-server-response.js';
|
|
3
|
+
import type { Protocol } from './platform-adapter.js';
|
|
4
4
|
export interface ExecutionContext<TSession extends {} = {}> {
|
|
5
5
|
readonly protocol: Protocol;
|
|
6
6
|
readonly platform: string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AsyncEventEmitter } from 'strict-typed-events';
|
|
2
2
|
import type { ApiDocument } from '@opra/common';
|
|
3
|
-
import type { HttpServerResponse } from './/http/http-server-response.js';
|
|
4
3
|
import type { ExecutionContext, HttpMessageContext, RpcMessageContext, WsMessageContext } from './execution-context.js';
|
|
5
4
|
import type { HttpServerRequest } from './http/http-server-request.js';
|
|
5
|
+
import type { HttpServerResponse } from './http/http-server-response.js';
|
|
6
6
|
import { Protocol } from './platform-adapter.js';
|
|
7
7
|
export declare class ExecutionContextHost<TSession extends {} = {}> extends AsyncEventEmitter implements ExecutionContext<TSession> {
|
|
8
8
|
readonly api: ApiDocument;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Application } from 'express';
|
|
2
2
|
import type { ApiDocument } from '@opra/common';
|
|
3
|
-
import type { PlatformAdapter } from '
|
|
4
|
-
import type {
|
|
3
|
+
import type { PlatformAdapter } from '../../platform-adapter';
|
|
4
|
+
import type { NodeHttpAdapter } from './node-http-adapter';
|
|
5
5
|
export interface ExpressAdapter extends PlatformAdapter {
|
|
6
6
|
readonly app: Application;
|
|
7
7
|
}
|
|
@@ -9,7 +9,7 @@ export interface ExpressAdapter extends PlatformAdapter {
|
|
|
9
9
|
* @namespace
|
|
10
10
|
*/
|
|
11
11
|
export declare namespace ExpressAdapter {
|
|
12
|
-
interface Options extends
|
|
12
|
+
interface Options extends NodeHttpAdapter.Options {
|
|
13
13
|
}
|
|
14
14
|
function create(app: Application, api: ApiDocument, options?: ExpressAdapter.Options): Promise<ExpressAdapter>;
|
|
15
15
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Application } from 'express';
|
|
2
|
+
import { ApiDocument } from '@opra/common';
|
|
3
|
+
import { HttpAdapterHost } from '../http-adapter-host.js';
|
|
4
|
+
import type { ExpressAdapter } from './express-adapter.js';
|
|
5
|
+
export declare class ExpressAdapterHost extends HttpAdapterHost implements ExpressAdapter {
|
|
6
|
+
protected _platform: string;
|
|
7
|
+
protected _app: Application;
|
|
8
|
+
constructor(app: Application);
|
|
9
|
+
get app(): Application;
|
|
10
|
+
protected init(api: ApiDocument, options?: ExpressAdapter.Options): Promise<void>;
|
|
11
|
+
static create(app: Application, api: ApiDocument, options?: ExpressAdapter.Options): Promise<ExpressAdapter>;
|
|
12
|
+
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import http from 'http';
|
|
3
3
|
import type { ApiDocument, OpraURLPath } from '@opra/common';
|
|
4
|
-
import type { PlatformAdapter } from '
|
|
5
|
-
export interface
|
|
4
|
+
import type { PlatformAdapter } from '../../platform-adapter';
|
|
5
|
+
export interface NodeHttpAdapter extends PlatformAdapter {
|
|
6
6
|
readonly basePath: OpraURLPath;
|
|
7
7
|
readonly server: http.Server;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
* @namespace
|
|
10
|
+
* @namespace NodeHttpAdapter
|
|
11
11
|
*/
|
|
12
|
-
export declare namespace
|
|
12
|
+
export declare namespace NodeHttpAdapter {
|
|
13
13
|
type Options = PlatformAdapter.Options & {
|
|
14
14
|
basePath?: string;
|
|
15
15
|
};
|
|
16
|
-
function create(api: ApiDocument, options?: Options): Promise<
|
|
16
|
+
function create(api: ApiDocument, options?: Options): Promise<NodeHttpAdapter>;
|
|
17
17
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import http from 'http';
|
|
3
|
+
import { ApiDocument, OpraURLPath } from '@opra/common';
|
|
4
|
+
import { HttpAdapterHost } from '../http-adapter-host.js';
|
|
5
|
+
import type { NodeHttpAdapter } from './node-http-adapter';
|
|
6
|
+
/**
|
|
7
|
+
* @class NodeHttpAdapterHost
|
|
8
|
+
*/
|
|
9
|
+
export declare class NodeHttpAdapterHost extends HttpAdapterHost implements NodeHttpAdapter {
|
|
10
|
+
protected _platform: string;
|
|
11
|
+
protected _basePath: OpraURLPath;
|
|
12
|
+
protected _server: http.Server;
|
|
13
|
+
get basePath(): OpraURLPath;
|
|
14
|
+
get server(): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
15
|
+
close(): Promise<void>;
|
|
16
|
+
protected init(api: ApiDocument, options?: NodeHttpAdapter.Options): Promise<void>;
|
|
17
|
+
protected _serverListener(incomingMessage: http.IncomingMessage, serverResponse: http.ServerResponse): void;
|
|
18
|
+
static create(api: ApiDocument, options?: NodeHttpAdapter.Options): Promise<NodeHttpAdapter>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import bodyParser from 'body-parser';
|
|
2
|
+
import type { HttpServerRequest } from '../http-server-request.js';
|
|
3
|
+
type BodyLoaderFunction = (incoming: HttpServerRequest) => Promise<any>;
|
|
4
|
+
export declare function jsonBodyLoader(options?: bodyParser.OptionsJson, cachePoint?: Object): BodyLoaderFunction;
|
|
5
|
+
export {};
|