@opra/core 0.33.13 → 1.0.0-alpha.2
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/augmentation/18n.augmentation.js +17 -4
- package/cjs/augmentation/http-controller.augmentation.js +25 -0
- package/cjs/constants.js +5 -0
- package/cjs/execution-context.js +25 -12
- package/cjs/{services → helpers}/logger.js +1 -2
- package/cjs/{services/api-service.js → helpers/service-base.js} +8 -8
- package/cjs/http/express-adapter.js +164 -0
- package/cjs/http/http-adapter.js +27 -0
- package/cjs/http/http-context.js +116 -0
- package/cjs/http/impl/asset-cache.js +21 -0
- package/cjs/http/impl/http-handler.js +575 -0
- package/cjs/http/{http-server-request.js → impl/http-incoming.host.js} +21 -46
- package/cjs/http/{http-server-response.js → impl/http-outgoing.host.js} +7 -26
- package/cjs/http/{helpers/multipart-helper.js → impl/multipart-reader.js} +24 -22
- package/cjs/http/impl/{http-incoming-message.host.js → node-incoming-message.host.js} +13 -54
- package/cjs/http/impl/{http-outgoing-message.host.js → node-outgoing-message.host.js} +11 -14
- package/cjs/http/interfaces/http-incoming.interface.js +25 -0
- package/cjs/http/interfaces/http-outgoing.interface.js +22 -0
- package/cjs/http/interfaces/node-incoming-message.interface.js +63 -0
- package/cjs/http/interfaces/node-outgoing-message.interface.js +15 -0
- package/cjs/http/utils/body-reader.js +215 -0
- package/cjs/http/{helpers → utils}/convert-to-raw-headers.js +1 -2
- package/cjs/http/{helpers → utils}/match-known-fields.js +11 -9
- package/cjs/http/utils/wrap-exception.js +34 -0
- package/cjs/index.js +25 -25
- package/cjs/platform-adapter.js +21 -0
- package/cjs/type-guards.js +23 -0
- package/esm/augmentation/18n.augmentation.js +20 -7
- package/esm/augmentation/http-controller.augmentation.js +23 -0
- package/esm/constants.js +2 -0
- package/esm/execution-context.js +25 -13
- package/esm/{services → helpers}/logger.js +1 -2
- package/esm/{services/api-service.js → helpers/service-base.js} +6 -6
- package/esm/http/express-adapter.js +159 -0
- package/esm/http/http-adapter.js +23 -0
- package/esm/http/http-context.js +111 -0
- package/esm/http/impl/asset-cache.js +17 -0
- package/esm/http/impl/http-handler.js +570 -0
- package/esm/http/{http-server-request.js → impl/http-incoming.host.js} +17 -43
- package/esm/http/{http-server-response.js → impl/http-outgoing.host.js} +6 -26
- package/esm/http/{helpers/multipart-helper.js → impl/multipart-reader.js} +22 -20
- package/esm/http/impl/{http-incoming-message.host.js → node-incoming-message.host.js} +11 -52
- package/esm/http/impl/{http-outgoing-message.host.js → node-outgoing-message.host.js} +9 -12
- package/esm/http/interfaces/http-incoming.interface.js +22 -0
- package/esm/http/interfaces/http-outgoing.interface.js +19 -0
- package/esm/http/interfaces/node-incoming-message.interface.js +60 -0
- package/esm/http/interfaces/node-outgoing-message.interface.js +12 -0
- package/esm/http/utils/body-reader.js +210 -0
- package/esm/http/{helpers → utils}/convert-to-headers.js +1 -1
- package/esm/http/{helpers → utils}/convert-to-raw-headers.js +2 -3
- package/esm/http/{helpers → utils}/match-known-fields.js +11 -9
- package/esm/http/utils/wrap-exception.js +30 -0
- package/esm/index.js +25 -26
- package/esm/platform-adapter.js +19 -1
- package/esm/type-guards.js +16 -0
- package/package.json +22 -10
- package/types/augmentation/18n.augmentation.d.ts +32 -2
- package/types/augmentation/http-controller.augmentation.d.ts +21 -0
- package/types/constants.d.ts +2 -0
- package/types/execution-context.d.ts +24 -26
- package/types/helpers/service-base.d.ts +10 -0
- package/types/http/express-adapter.d.ts +13 -0
- package/types/http/http-adapter.d.ts +27 -0
- package/types/http/http-context.d.ts +44 -0
- package/types/http/impl/asset-cache.d.ts +5 -0
- package/types/http/impl/http-handler.d.ts +73 -0
- package/types/http/impl/http-incoming.host.d.ts +23 -0
- package/types/http/impl/http-outgoing.host.d.ts +17 -0
- package/types/http/{helpers/multipart-helper.d.ts → impl/multipart-reader.d.ts} +8 -6
- package/types/http/impl/{http-incoming-message.host.d.ts → node-incoming-message.host.d.ts} +9 -22
- package/types/http/impl/{http-outgoing-message.host.d.ts → node-outgoing-message.host.d.ts} +11 -27
- package/types/http/{http-server-request.d.ts → interfaces/http-incoming.interface.d.ts} +28 -17
- package/types/http/{http-server-response.d.ts → interfaces/http-outgoing.interface.d.ts} +17 -10
- package/types/http/interfaces/node-incoming-message.interface.d.ts +38 -0
- package/types/http/interfaces/node-outgoing-message.interface.d.ts +29 -0
- package/types/http/utils/body-reader.d.ts +41 -0
- package/types/http/utils/wrap-exception.d.ts +2 -0
- package/types/index.d.ts +24 -26
- package/types/platform-adapter.d.ts +20 -48
- package/types/type-guards.d.ts +8 -0
- package/cjs/augmentation/collection.augmentation.js +0 -2
- package/cjs/augmentation/container.augmentation.js +0 -2
- package/cjs/augmentation/resource.augmentation.js +0 -26
- package/cjs/augmentation/singleton.augmentation.js +0 -2
- package/cjs/augmentation/storage.augmentation.js +0 -2
- package/cjs/execution-context.host.js +0 -46
- package/cjs/http/adapters/express-adapter.host.js +0 -34
- package/cjs/http/adapters/express-adapter.js +0 -14
- package/cjs/http/adapters/node-http-adapter.host.js +0 -70
- package/cjs/http/adapters/node-http-adapter.js +0 -14
- package/cjs/http/helpers/json-body-loader.js +0 -29
- package/cjs/http/helpers/query-parsers.js +0 -16
- package/cjs/http/http-adapter-host.js +0 -715
- package/cjs/interfaces/interceptor.interface.js +0 -2
- package/cjs/interfaces/request-handler.interface.js +0 -2
- package/cjs/platform-adapter.host.js +0 -154
- package/cjs/request-context.js +0 -25
- package/cjs/request.host.js +0 -24
- package/cjs/request.js +0 -2
- package/cjs/response.host.js +0 -22
- package/cjs/response.js +0 -2
- package/esm/augmentation/collection.augmentation.js +0 -1
- package/esm/augmentation/container.augmentation.js +0 -1
- package/esm/augmentation/resource.augmentation.js +0 -24
- package/esm/augmentation/singleton.augmentation.js +0 -1
- package/esm/augmentation/storage.augmentation.js +0 -1
- package/esm/execution-context.host.js +0 -42
- package/esm/http/adapters/express-adapter.host.js +0 -30
- package/esm/http/adapters/express-adapter.js +0 -11
- package/esm/http/adapters/node-http-adapter.host.js +0 -65
- package/esm/http/adapters/node-http-adapter.js +0 -11
- package/esm/http/helpers/json-body-loader.js +0 -24
- package/esm/http/helpers/query-parsers.js +0 -12
- package/esm/http/http-adapter-host.js +0 -710
- package/esm/interfaces/interceptor.interface.js +0 -1
- package/esm/interfaces/request-handler.interface.js +0 -1
- package/esm/platform-adapter.host.js +0 -149
- package/esm/request-context.js +0 -22
- package/esm/request.host.js +0 -20
- package/esm/request.js +0 -1
- package/esm/response.host.js +0 -18
- package/esm/response.js +0 -1
- package/i18n/i18n/en/error.json +0 -21
- package/types/augmentation/collection.augmentation.d.ts +0 -146
- package/types/augmentation/container.augmentation.d.ts +0 -14
- package/types/augmentation/resource.augmentation.d.ts +0 -38
- package/types/augmentation/singleton.augmentation.d.ts +0 -83
- package/types/augmentation/storage.augmentation.d.ts +0 -50
- package/types/execution-context.host.d.ts +0 -25
- package/types/http/adapters/express-adapter.d.ts +0 -15
- package/types/http/adapters/express-adapter.host.d.ts +0 -12
- package/types/http/adapters/node-http-adapter.d.ts +0 -17
- package/types/http/adapters/node-http-adapter.host.d.ts +0 -19
- package/types/http/helpers/json-body-loader.d.ts +0 -5
- package/types/http/helpers/query-parsers.d.ts +0 -1
- package/types/http/http-adapter-host.d.ts +0 -34
- package/types/interfaces/interceptor.interface.d.ts +0 -2
- package/types/interfaces/request-handler.interface.d.ts +0 -4
- package/types/platform-adapter.host.d.ts +0 -43
- package/types/request-context.d.ts +0 -13
- package/types/request.d.ts +0 -14
- package/types/request.host.d.ts +0 -27
- package/types/response.d.ts +0 -22
- package/types/response.host.d.ts +0 -22
- package/types/services/api-service.d.ts +0 -10
- /package/cjs/http/{helpers → utils}/common.js +0 -0
- /package/cjs/http/{helpers → utils}/concat-readable.js +0 -0
- /package/cjs/http/{helpers → utils}/convert-to-headers.js +0 -0
- /package/esm/http/{helpers → utils}/common.js +0 -0
- /package/esm/http/{helpers → utils}/concat-readable.js +0 -0
- /package/types/{services → helpers}/logger.d.ts +0 -0
- /package/types/http/{helpers → utils}/common.d.ts +0 -0
- /package/types/http/{helpers → utils}/concat-readable.d.ts +0 -0
- /package/types/http/{helpers → utils}/convert-to-headers.d.ts +0 -0
- /package/types/http/{helpers → utils}/convert-to-raw-headers.d.ts +0 -0
- /package/types/http/{helpers → utils}/match-known-fields.d.ts +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import './augmentation/18n.augmentation.js';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { pascalCase } from 'putil-varhelpers';
|
|
4
|
-
import { AsyncEventEmitter } from 'strict-typed-events';
|
|
5
|
-
import { BadRequestError, Container, CrudResource, ForbiddenError, getStackFileName, I18n, Resource, translate } from '@opra/common';
|
|
6
|
-
import { Logger } from './services/logger.js';
|
|
7
|
-
const resourceInitialized = Symbol.for('opra.resource.initialized');
|
|
8
|
-
/**
|
|
9
|
-
* @class PlatformAdapterHost
|
|
10
|
-
*/
|
|
11
|
-
export class PlatformAdapterHost extends AsyncEventEmitter {
|
|
12
|
-
constructor() {
|
|
13
|
-
super(...arguments);
|
|
14
|
-
this._controllers = new Map();
|
|
15
|
-
}
|
|
16
|
-
get api() {
|
|
17
|
-
return this._api;
|
|
18
|
-
}
|
|
19
|
-
get platform() {
|
|
20
|
-
return this._platform;
|
|
21
|
-
}
|
|
22
|
-
get protocol() {
|
|
23
|
-
return this._protocol;
|
|
24
|
-
}
|
|
25
|
-
get serviceName() {
|
|
26
|
-
return this._serviceName;
|
|
27
|
-
}
|
|
28
|
-
get i18n() {
|
|
29
|
-
return this._i18n;
|
|
30
|
-
}
|
|
31
|
-
async close() {
|
|
32
|
-
const promises = [];
|
|
33
|
-
for (const r of this._controllers.values()) {
|
|
34
|
-
const onShutdown = r?.onShutdown;
|
|
35
|
-
if (onShutdown)
|
|
36
|
-
promises.push((async () => onShutdown.call(r.controller, r))());
|
|
37
|
-
}
|
|
38
|
-
await Promise.allSettled(promises);
|
|
39
|
-
this._controllers.clear();
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Initializes the adapter
|
|
43
|
-
*/
|
|
44
|
-
async init(api, options) {
|
|
45
|
-
if (this._api)
|
|
46
|
-
throw new Error(`Already initialized`);
|
|
47
|
-
this._api = api;
|
|
48
|
-
this._interceptors = [...(options?.interceptors || [])];
|
|
49
|
-
this._logger = options?.logger && options.logger instanceof Logger
|
|
50
|
-
? options.logger
|
|
51
|
-
: new Logger({ instance: options?.logger });
|
|
52
|
-
// Assign events
|
|
53
|
-
if (options?.on) {
|
|
54
|
-
for (const [event, fn] of Object.entries(options.on)) {
|
|
55
|
-
/* istanbul ignore next */
|
|
56
|
-
if (typeof fn === 'function')
|
|
57
|
-
this.on(event, fn);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
// Make a safe service name
|
|
61
|
-
this._serviceName = pascalCase((api.info.title || '').replace(/[^a-z0-9_ ]/ig, '')) || 'OpraService';
|
|
62
|
-
if (!/^[a-z]/i.test(this._serviceName))
|
|
63
|
-
this._serviceName = 'X' + this._serviceName;
|
|
64
|
-
// Init I18n
|
|
65
|
-
if (options?.i18n instanceof I18n)
|
|
66
|
-
this._i18n = options.i18n;
|
|
67
|
-
else if (typeof options?.i18n === 'function')
|
|
68
|
-
this._i18n = await options.i18n();
|
|
69
|
-
else
|
|
70
|
-
this._i18n = await this._createI18n(options?.i18n);
|
|
71
|
-
this._i18n = this._i18n || I18n.defaultInstance;
|
|
72
|
-
if (!this._i18n.isInitialized)
|
|
73
|
-
await this._i18n.init();
|
|
74
|
-
// Initialize all resources
|
|
75
|
-
await this.getController(this.api.root);
|
|
76
|
-
}
|
|
77
|
-
async getController(resource) {
|
|
78
|
-
resource = typeof resource === 'object' && resource instanceof Resource
|
|
79
|
-
? resource : this.api.getResource(resource);
|
|
80
|
-
let controller = this._controllers.get(resource);
|
|
81
|
-
if (!controller) {
|
|
82
|
-
controller = resource.controller;
|
|
83
|
-
if (!controller && resource.ctor) {
|
|
84
|
-
controller = new resource.ctor();
|
|
85
|
-
}
|
|
86
|
-
this._controllers.set(resource, controller);
|
|
87
|
-
}
|
|
88
|
-
if (controller && !controller[resourceInitialized]) {
|
|
89
|
-
controller[resourceInitialized] = true;
|
|
90
|
-
// Initialize controller
|
|
91
|
-
if (typeof controller.onInit === 'function')
|
|
92
|
-
await controller.onInit.call(controller);
|
|
93
|
-
// Initialize sub resources of Container
|
|
94
|
-
if (resource instanceof Container) {
|
|
95
|
-
for (const r of resource.resources.values()) {
|
|
96
|
-
await this.getController(r);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return controller;
|
|
101
|
-
}
|
|
102
|
-
async getActionHandler(resource, name) {
|
|
103
|
-
resource = typeof resource === 'object' && resource instanceof Resource
|
|
104
|
-
? resource
|
|
105
|
-
: this.api.getResource(resource);
|
|
106
|
-
const controller = await this.getController(resource);
|
|
107
|
-
const endpoint = resource.actions.get(name);
|
|
108
|
-
if (endpoint) {
|
|
109
|
-
const handler = typeof controller[endpoint.name] === 'function' ? controller[endpoint.name] : undefined;
|
|
110
|
-
if (handler)
|
|
111
|
-
return { controller, endpoint, handler };
|
|
112
|
-
}
|
|
113
|
-
throw new BadRequestError({
|
|
114
|
-
message: translate('error:ACTION_NOT_FOUND', { resource: resource.name, action: name }),
|
|
115
|
-
severity: 'error',
|
|
116
|
-
code: 'ACTION_NOT_FOUND'
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
async getOperationHandler(resource, name) {
|
|
120
|
-
resource = typeof resource === 'object' && resource instanceof Resource
|
|
121
|
-
? resource
|
|
122
|
-
: this.api.getResource(resource);
|
|
123
|
-
const controller = await this.getController(resource);
|
|
124
|
-
const endpoint = resource instanceof CrudResource && resource.operations.get(name);
|
|
125
|
-
if (endpoint) {
|
|
126
|
-
const handler = typeof controller[endpoint.name] === 'function' ? controller[endpoint.name] : undefined;
|
|
127
|
-
if (handler)
|
|
128
|
-
return { controller, endpoint, handler };
|
|
129
|
-
}
|
|
130
|
-
throw new ForbiddenError({
|
|
131
|
-
message: translate('error:OPERATION_FORBIDDEN', { resource: resource.name, operation: name }),
|
|
132
|
-
severity: 'error',
|
|
133
|
-
code: 'OPERATION_FORBIDDEN'
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
async _createI18n(options) {
|
|
137
|
-
const opts = {
|
|
138
|
-
...options,
|
|
139
|
-
};
|
|
140
|
-
delete opts.resourceDirs;
|
|
141
|
-
const instance = I18n.createInstance(opts);
|
|
142
|
-
await instance.init();
|
|
143
|
-
await instance.loadResourceDir(path.resolve(getStackFileName(), '../../../i18n'));
|
|
144
|
-
if (options?.resourceDirs)
|
|
145
|
-
for (const dir of options.resourceDirs)
|
|
146
|
-
await instance.loadResourceDir(dir);
|
|
147
|
-
return instance;
|
|
148
|
-
}
|
|
149
|
-
}
|
package/esm/request-context.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ApiDocument } from '@opra/common';
|
|
2
|
-
import { ExecutionContext } from './execution-context.js';
|
|
3
|
-
export var RequestContext;
|
|
4
|
-
(function (RequestContext) {
|
|
5
|
-
function from(executionContext, api, request, response) {
|
|
6
|
-
const out = {
|
|
7
|
-
api,
|
|
8
|
-
request,
|
|
9
|
-
response
|
|
10
|
-
};
|
|
11
|
-
Object.setPrototypeOf(out, executionContext);
|
|
12
|
-
return out;
|
|
13
|
-
}
|
|
14
|
-
RequestContext.from = from;
|
|
15
|
-
function is(v) {
|
|
16
|
-
return ExecutionContext.is(v) &&
|
|
17
|
-
v.api instanceof ApiDocument &&
|
|
18
|
-
v.request &&
|
|
19
|
-
v.response;
|
|
20
|
-
}
|
|
21
|
-
RequestContext.is = is;
|
|
22
|
-
})(RequestContext || (RequestContext = {}));
|
package/esm/request.host.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export class RequestHost {
|
|
2
|
-
constructor(init) {
|
|
3
|
-
Object.assign(this, init);
|
|
4
|
-
this.params = this.params || {};
|
|
5
|
-
}
|
|
6
|
-
get resource() {
|
|
7
|
-
return this.endpoint.resource;
|
|
8
|
-
}
|
|
9
|
-
switchToHttp() {
|
|
10
|
-
if (this.http)
|
|
11
|
-
return this.http;
|
|
12
|
-
throw new TypeError('Not executing in an "Http" context');
|
|
13
|
-
}
|
|
14
|
-
switchToWs() {
|
|
15
|
-
throw new TypeError('Not executing in an "WebSocket" context');
|
|
16
|
-
}
|
|
17
|
-
switchToRpc() {
|
|
18
|
-
throw new TypeError('Not executing in an "RPC" context');
|
|
19
|
-
}
|
|
20
|
-
}
|
package/esm/request.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/esm/response.host.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export class ResponseHost {
|
|
2
|
-
constructor(init) {
|
|
3
|
-
if (init)
|
|
4
|
-
Object.assign(this, init);
|
|
5
|
-
this.errors = this.errors || [];
|
|
6
|
-
}
|
|
7
|
-
switchToHttp() {
|
|
8
|
-
if (this.http)
|
|
9
|
-
return this.http;
|
|
10
|
-
throw new TypeError('Not executing in an "Http" context');
|
|
11
|
-
}
|
|
12
|
-
switchToWs() {
|
|
13
|
-
throw new TypeError('Not executing in an "WebSocket" context');
|
|
14
|
-
}
|
|
15
|
-
switchToRpc() {
|
|
16
|
-
throw new TypeError('Not executing in an "RPC" context');
|
|
17
|
-
}
|
|
18
|
-
}
|
package/esm/response.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/i18n/i18n/en/error.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { StrictOmit } from 'ts-gems';
|
|
2
|
-
import type { Action as _Action, CrudOperation as _Operation, PartialDTO } from '@opra/common';
|
|
3
|
-
import type { Request as _Request } from '../request.js';
|
|
4
|
-
import type { RequestContext } from '../request-context';
|
|
5
|
-
declare module "@opra/common" {
|
|
6
|
-
namespace Collection {
|
|
7
|
-
namespace Action {
|
|
8
|
-
interface Request extends StrictOmit<_Request, 'endpoint'> {
|
|
9
|
-
endpoint: _Action;
|
|
10
|
-
params: {
|
|
11
|
-
[key: string]: any;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
interface Context extends Resource.Context {
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
namespace Create {
|
|
18
|
-
interface Request extends StrictOmit<_Request, 'endpoint'> {
|
|
19
|
-
endpoint: _Operation & {
|
|
20
|
-
name: 'create';
|
|
21
|
-
};
|
|
22
|
-
data: any;
|
|
23
|
-
params: {
|
|
24
|
-
pick?: string[];
|
|
25
|
-
omit?: string[];
|
|
26
|
-
include?: string[];
|
|
27
|
-
[key: string]: any;
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
interface Context extends RequestContext {
|
|
31
|
-
request: Request;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
namespace Delete {
|
|
35
|
-
interface Request extends StrictOmit<_Request, 'endpoint'> {
|
|
36
|
-
endpoint: _Operation & {
|
|
37
|
-
name: 'delete';
|
|
38
|
-
};
|
|
39
|
-
key: any;
|
|
40
|
-
params: {
|
|
41
|
-
[key: string]: any;
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
interface Context extends RequestContext {
|
|
45
|
-
request: Request;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
namespace DeleteMany {
|
|
49
|
-
interface Request extends StrictOmit<_Request, 'endpoint'> {
|
|
50
|
-
endpoint: _Operation & {
|
|
51
|
-
name: 'deleteMany';
|
|
52
|
-
};
|
|
53
|
-
params: {
|
|
54
|
-
filter?: any;
|
|
55
|
-
[key: string]: any;
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
interface Context extends RequestContext {
|
|
59
|
-
request: Request;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
namespace FindMany {
|
|
63
|
-
interface Request extends StrictOmit<_Request, 'endpoint'> {
|
|
64
|
-
endpoint: _Operation & {
|
|
65
|
-
name: 'findMany';
|
|
66
|
-
};
|
|
67
|
-
params: {
|
|
68
|
-
filter?: any;
|
|
69
|
-
pick?: string[];
|
|
70
|
-
omit?: string[];
|
|
71
|
-
include?: string[];
|
|
72
|
-
sort?: string[];
|
|
73
|
-
limit?: number;
|
|
74
|
-
skip?: number;
|
|
75
|
-
distinct?: boolean;
|
|
76
|
-
count?: boolean;
|
|
77
|
-
[key: string]: any;
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
interface Context extends RequestContext {
|
|
81
|
-
request: Request;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
namespace Get {
|
|
85
|
-
interface Request extends StrictOmit<_Request, 'endpoint'> {
|
|
86
|
-
endpoint: _Operation & {
|
|
87
|
-
name: 'get';
|
|
88
|
-
};
|
|
89
|
-
key: any;
|
|
90
|
-
params: {
|
|
91
|
-
pick?: string[];
|
|
92
|
-
omit?: string[];
|
|
93
|
-
include?: string[];
|
|
94
|
-
[key: string]: any;
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
interface Context extends RequestContext {
|
|
98
|
-
request: Request;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
namespace Update {
|
|
102
|
-
interface Request extends StrictOmit<_Request, 'endpoint'> {
|
|
103
|
-
endpoint: _Operation & {
|
|
104
|
-
name: 'update';
|
|
105
|
-
};
|
|
106
|
-
key: any;
|
|
107
|
-
data: any;
|
|
108
|
-
params: {
|
|
109
|
-
pick?: string[];
|
|
110
|
-
omit?: string[];
|
|
111
|
-
include?: string[];
|
|
112
|
-
[key: string]: any;
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
interface Context extends RequestContext {
|
|
116
|
-
request: Request;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
namespace UpdateMany {
|
|
120
|
-
interface Request extends StrictOmit<_Request, 'endpoint'> {
|
|
121
|
-
endpoint: _Operation & {
|
|
122
|
-
name: 'updateMany';
|
|
123
|
-
};
|
|
124
|
-
data: any;
|
|
125
|
-
params: {
|
|
126
|
-
filter?: any;
|
|
127
|
-
[key: string]: any;
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
interface Context extends RequestContext {
|
|
131
|
-
request: Request;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
interface ICollection<T> {
|
|
136
|
-
create?(context: Collection.Create.Context): Promise<PartialDTO<T>>;
|
|
137
|
-
delete?(context: Collection.Delete.Context): Promise<number> | undefined;
|
|
138
|
-
deleteMany?(context: Collection.DeleteMany.Context): Promise<number> | undefined;
|
|
139
|
-
findMany?(context: Collection.FindMany.Context): Promise<PartialDTO<T>[] | undefined>;
|
|
140
|
-
get?(context: Collection.Get.Context): Promise<PartialDTO<T> | undefined>;
|
|
141
|
-
update?(context: Collection.Update.Context): Promise<PartialDTO<T> | undefined>;
|
|
142
|
-
updateMany?(context: Collection.UpdateMany.Context): Promise<number> | undefined;
|
|
143
|
-
onInit?(): Promise<void>;
|
|
144
|
-
onShutdown?(): Promise<void>;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { StrictOmit } from 'ts-gems';
|
|
2
|
-
import { Action as _Action } from '@opra/common';
|
|
3
|
-
import type { Request as _Request } from '../request.js';
|
|
4
|
-
declare module "@opra/common" {
|
|
5
|
-
namespace Container {
|
|
6
|
-
namespace Action {
|
|
7
|
-
interface Request extends StrictOmit<_Request, 'endpoint'> {
|
|
8
|
-
endpoint: _Action;
|
|
9
|
-
}
|
|
10
|
-
interface Context extends Resource.Context {
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { RequestContext } from '../request-context.js';
|
|
2
|
-
declare module "@opra/common" {
|
|
3
|
-
interface CollectionConstructor {
|
|
4
|
-
OnInit(): any;
|
|
5
|
-
OnShutdown(): any;
|
|
6
|
-
}
|
|
7
|
-
interface SingletonConstructor {
|
|
8
|
-
OnInit(): any;
|
|
9
|
-
OnShutdown(): any;
|
|
10
|
-
}
|
|
11
|
-
namespace Resource {
|
|
12
|
-
interface Context extends RequestContext {
|
|
13
|
-
params: Record<string, any>;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
interface Resource {
|
|
17
|
-
onInit?: (resource: Resource) => void | Promise<void>;
|
|
18
|
-
onShutdown?: (resource: Resource) => void | Promise<void>;
|
|
19
|
-
}
|
|
20
|
-
namespace Resource {
|
|
21
|
-
interface InitArguments {
|
|
22
|
-
onInit?: (resource: Resource) => void | Promise<void>;
|
|
23
|
-
onShutdown?: (resource: Resource) => void | Promise<void>;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
namespace Collection {
|
|
27
|
-
interface Metadata {
|
|
28
|
-
onInit?: (resource: Collection) => void | Promise<void>;
|
|
29
|
-
onShutdown?: (resource: Collection) => void | Promise<void>;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
namespace Singleton {
|
|
33
|
-
interface Metadata {
|
|
34
|
-
onInit?: (resource: Singleton) => void | Promise<void>;
|
|
35
|
-
onShutdown?: (resource: Singleton) => void | Promise<void>;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { StrictOmit } from 'ts-gems';
|
|
2
|
-
import type { Action as _Action, CrudOperation as _Operation, PartialDTO } from '@opra/common';
|
|
3
|
-
import type { Request as _Request } from '../request.js';
|
|
4
|
-
import type { RequestContext } from '../request-context.js';
|
|
5
|
-
declare module "@opra/common" {
|
|
6
|
-
namespace Singleton {
|
|
7
|
-
namespace Action {
|
|
8
|
-
interface Request extends StrictOmit<_Request, 'endpoint'> {
|
|
9
|
-
endpoint: _Action;
|
|
10
|
-
}
|
|
11
|
-
interface Context extends Resource.Context {
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
namespace Create {
|
|
15
|
-
interface Request extends StrictOmit<_Request, 'endpoint'> {
|
|
16
|
-
endpoint: _Operation & {
|
|
17
|
-
name: 'create';
|
|
18
|
-
};
|
|
19
|
-
data: any;
|
|
20
|
-
params: {
|
|
21
|
-
pick?: string[];
|
|
22
|
-
omit?: string[];
|
|
23
|
-
include?: string[];
|
|
24
|
-
[key: string]: any;
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
interface Context extends RequestContext {
|
|
28
|
-
request: Request;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
namespace Delete {
|
|
32
|
-
interface Request extends StrictOmit<_Request, 'endpoint'> {
|
|
33
|
-
endpoint: _Operation & {
|
|
34
|
-
name: 'delete';
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
interface Context extends RequestContext {
|
|
38
|
-
request: Request;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
namespace Get {
|
|
42
|
-
interface Request extends StrictOmit<_Request, 'endpoint'> {
|
|
43
|
-
endpoint: _Operation & {
|
|
44
|
-
name: 'get';
|
|
45
|
-
};
|
|
46
|
-
params: {
|
|
47
|
-
pick?: string[];
|
|
48
|
-
omit?: string[];
|
|
49
|
-
include?: string[];
|
|
50
|
-
[key: string]: any;
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
interface Context extends RequestContext {
|
|
54
|
-
request: Request;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
namespace Update {
|
|
58
|
-
interface Request extends StrictOmit<_Request, 'endpoint'> {
|
|
59
|
-
endpoint: _Operation & {
|
|
60
|
-
name: 'update';
|
|
61
|
-
};
|
|
62
|
-
data: any;
|
|
63
|
-
params: {
|
|
64
|
-
pick?: string[];
|
|
65
|
-
omit?: string[];
|
|
66
|
-
include?: string[];
|
|
67
|
-
[key: string]: any;
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
interface Context extends RequestContext {
|
|
71
|
-
request: Request;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
interface ISingleton<T> {
|
|
76
|
-
create?(context: Singleton.Create.Context): Promise<PartialDTO<T>>;
|
|
77
|
-
delete?(context: Singleton.Delete.Context): Promise<number> | undefined;
|
|
78
|
-
get?(context: Singleton.Get.Context): Promise<PartialDTO<T> | undefined>;
|
|
79
|
-
update?(context: Singleton.Update.Context): Promise<PartialDTO<T> | undefined>;
|
|
80
|
-
onInit?(): Promise<void>;
|
|
81
|
-
onShutdown?(): Promise<void>;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { StrictOmit } from 'ts-gems';
|
|
2
|
-
import type { Action as _Action, CrudOperation as _Operation } from '@opra/common';
|
|
3
|
-
import type { MultipartIterator } from '../http/helpers/multipart-helper';
|
|
4
|
-
import type { Request as _Request } from '../request.js';
|
|
5
|
-
import type { RequestContext } from '../request-context.js';
|
|
6
|
-
declare module "@opra/common" {
|
|
7
|
-
namespace Storage {
|
|
8
|
-
namespace Action {
|
|
9
|
-
interface Request extends StrictOmit<_Request, 'endpoint'> {
|
|
10
|
-
endpoint: _Action;
|
|
11
|
-
}
|
|
12
|
-
interface Context extends Resource.Context {
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
namespace Delete {
|
|
16
|
-
interface Request extends StrictOmit<_Request, 'endpoint'> {
|
|
17
|
-
endpoint: _Operation & {
|
|
18
|
-
name: 'delete';
|
|
19
|
-
};
|
|
20
|
-
path?: string;
|
|
21
|
-
}
|
|
22
|
-
interface Context extends RequestContext {
|
|
23
|
-
request: Request;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
namespace Get {
|
|
27
|
-
interface Request extends StrictOmit<_Request, 'endpoint'> {
|
|
28
|
-
endpoint: _Operation & {
|
|
29
|
-
name: 'get';
|
|
30
|
-
};
|
|
31
|
-
path?: string;
|
|
32
|
-
}
|
|
33
|
-
interface Context extends RequestContext {
|
|
34
|
-
request: Request;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
namespace Post {
|
|
38
|
-
interface Request extends StrictOmit<_Request, 'endpoint'> {
|
|
39
|
-
endpoint: _Operation & {
|
|
40
|
-
name: 'post';
|
|
41
|
-
};
|
|
42
|
-
path?: string;
|
|
43
|
-
parts: MultipartIterator;
|
|
44
|
-
}
|
|
45
|
-
interface Context extends RequestContext {
|
|
46
|
-
request: Request;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { AsyncEventEmitter } from 'strict-typed-events';
|
|
2
|
-
import type { ApiDocument } from '@opra/common';
|
|
3
|
-
import type { ExecutionContext, HttpMessageContext, RpcMessageContext, WsMessageContext } from './execution-context.js';
|
|
4
|
-
import type { HttpServerRequest } from './http/http-server-request.js';
|
|
5
|
-
import type { HttpServerResponse } from './http/http-server-response.js';
|
|
6
|
-
import { Protocol } from './platform-adapter.js';
|
|
7
|
-
export declare class ExecutionContextHost extends AsyncEventEmitter implements ExecutionContext {
|
|
8
|
-
readonly api: ApiDocument;
|
|
9
|
-
readonly platform: string;
|
|
10
|
-
readonly protocol: Protocol;
|
|
11
|
-
readonly http?: HttpMessageContext;
|
|
12
|
-
readonly ws?: WsMessageContext;
|
|
13
|
-
readonly rpc?: RpcMessageContext;
|
|
14
|
-
constructor(api: ApiDocument, platform: string, protocol: {
|
|
15
|
-
http?: {
|
|
16
|
-
incoming: HttpServerRequest;
|
|
17
|
-
outgoing: HttpServerResponse;
|
|
18
|
-
};
|
|
19
|
-
ws?: WsMessageContext;
|
|
20
|
-
rpc?: RpcMessageContext;
|
|
21
|
-
});
|
|
22
|
-
switchToHttp(): HttpMessageContext;
|
|
23
|
-
switchToWs(): WsMessageContext;
|
|
24
|
-
switchToRpc(): RpcMessageContext;
|
|
25
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Application } from 'express';
|
|
2
|
-
import type { ApiDocument } from '@opra/common';
|
|
3
|
-
import type { PlatformAdapter } from '../../platform-adapter';
|
|
4
|
-
import type { NodeHttpAdapter } from './node-http-adapter';
|
|
5
|
-
export interface ExpressAdapter extends PlatformAdapter {
|
|
6
|
-
readonly app: Application;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* @namespace
|
|
10
|
-
*/
|
|
11
|
-
export declare namespace ExpressAdapter {
|
|
12
|
-
interface Options extends NodeHttpAdapter.Options {
|
|
13
|
-
}
|
|
14
|
-
function create(app: Application, api: ApiDocument, options?: ExpressAdapter.Options): Promise<ExpressAdapter>;
|
|
15
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import http from 'http';
|
|
3
|
-
import type { ApiDocument, OpraURLPath } from '@opra/common';
|
|
4
|
-
import type { PlatformAdapter } from '../../platform-adapter';
|
|
5
|
-
export interface NodeHttpAdapter extends PlatformAdapter {
|
|
6
|
-
readonly basePath: OpraURLPath;
|
|
7
|
-
readonly server: http.Server;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* @namespace NodeHttpAdapter
|
|
11
|
-
*/
|
|
12
|
-
export declare namespace NodeHttpAdapter {
|
|
13
|
-
type Options = PlatformAdapter.Options & {
|
|
14
|
-
basePath?: string;
|
|
15
|
-
};
|
|
16
|
-
function create(api: ApiDocument, options?: Options): Promise<NodeHttpAdapter>;
|
|
17
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
}
|