@opra/common 1.0.0-beta.2 → 1.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/index.cjs +5 -5
- package/browser/index.mjs +5 -5
- package/cjs/document/api-document.js +14 -0
- package/cjs/document/common/api-base.js +5 -3
- package/cjs/document/common/document-node.js +6 -2
- package/cjs/document/constants.js +2 -1
- package/cjs/document/decorators/http-controller.decorator.js +1 -1
- package/cjs/document/decorators/http-operation-entity.decorator.js +1 -1
- package/cjs/document/decorators/http-operation.decorator.js +5 -5
- package/cjs/document/decorators/rpc-controller.decorator.js +69 -0
- package/cjs/document/decorators/rpc-operation.decorator.js +80 -0
- package/cjs/document/factory/api-document.factory.js +9 -3
- package/cjs/document/factory/data-type.factory.js +20 -0
- package/cjs/document/factory/http-api.factory.js +50 -77
- package/cjs/document/factory/rpc-api.factory.js +202 -0
- package/cjs/document/http/http-api.js +5 -4
- package/cjs/document/http/http-controller.js +16 -0
- package/cjs/document/http/http-operation.js +6 -0
- package/cjs/document/index.js +8 -0
- package/cjs/document/rpc/rpc-api.js +54 -0
- package/cjs/document/rpc/rpc-controller.js +116 -0
- package/cjs/document/rpc/rpc-header.js +40 -0
- package/cjs/document/rpc/rpc-operation-response.js +58 -0
- package/cjs/document/rpc/rpc-operation.js +80 -0
- package/cjs/enums/index.js +7 -0
- package/cjs/exception/http-errors/forbidden.error.js +1 -1
- package/cjs/exception/http-errors/resource-not.available.error.js +1 -1
- package/cjs/index.js +1 -1
- package/cjs/schema/opra-schema.js +3 -0
- package/cjs/schema/rpc/rpc-controller.interface.js +11 -0
- package/cjs/schema/rpc/rpc-header.interface.js +2 -0
- package/cjs/schema/rpc/rpc-operation.interface.js +7 -0
- package/esm/document/api-document.js +14 -0
- package/esm/document/common/api-base.js +5 -3
- package/esm/document/common/document-node.js +6 -2
- package/esm/document/constants.js +1 -0
- package/esm/document/decorators/http-controller.decorator.js +1 -1
- package/esm/document/decorators/http-operation-entity.decorator.js +1 -1
- package/esm/document/decorators/http-operation.decorator.js +5 -5
- package/esm/document/decorators/rpc-controller.decorator.js +65 -0
- package/esm/document/decorators/rpc-operation.decorator.js +76 -0
- package/esm/document/factory/api-document.factory.js +9 -3
- package/esm/document/factory/data-type.factory.js +20 -0
- package/esm/document/factory/http-api.factory.js +50 -77
- package/esm/document/factory/rpc-api.factory.js +198 -0
- package/esm/document/http/http-api.js +5 -4
- package/esm/document/http/http-controller.js +17 -1
- package/esm/document/http/http-operation.js +6 -0
- package/esm/document/index.js +8 -0
- package/esm/document/rpc/rpc-api.js +50 -0
- package/esm/document/rpc/rpc-controller.js +113 -0
- package/esm/document/rpc/rpc-header.js +37 -0
- package/esm/document/rpc/rpc-operation-response.js +54 -0
- package/esm/document/rpc/rpc-operation.js +77 -0
- package/esm/enums/index.js +4 -0
- package/esm/exception/http-errors/forbidden.error.js +1 -1
- package/esm/exception/http-errors/resource-not.available.error.js +1 -1
- package/esm/index.js +1 -1
- package/esm/schema/opra-schema.js +3 -0
- package/esm/schema/rpc/rpc-controller.interface.js +8 -0
- package/esm/schema/rpc/rpc-header.interface.js +1 -0
- package/esm/schema/rpc/rpc-operation.interface.js +4 -0
- package/package.json +2 -2
- package/types/document/api-document.d.ts +5 -2
- package/types/document/common/api-base.d.ts +3 -2
- package/types/document/constants.d.ts +1 -0
- package/types/document/decorators/http-operation.decorator.d.ts +3 -3
- package/types/document/decorators/rpc-controller.decorator.d.ts +20 -0
- package/types/document/decorators/rpc-operation.decorator.d.ts +32 -0
- package/types/document/factory/api-document.factory.d.ts +2 -1
- package/types/document/factory/data-type.factory.d.ts +1 -0
- package/types/document/factory/http-api.factory.d.ts +10 -6
- package/types/document/factory/rpc-api.factory.d.ts +40 -0
- package/types/document/http/http-api.d.ts +8 -3
- package/types/document/http/http-controller.d.ts +8 -2
- package/types/document/index.d.ts +11 -0
- package/types/document/rpc/rpc-api.d.ts +27 -0
- package/types/document/rpc/rpc-controller.d.ts +89 -0
- package/types/document/rpc/rpc-header.d.ts +47 -0
- package/types/document/rpc/rpc-operation-response.d.ts +41 -0
- package/types/document/rpc/rpc-operation.d.ts +77 -0
- package/types/enums/index.d.ts +4 -0
- package/types/exception/http-errors/forbidden.error.d.ts +1 -1
- package/types/index.d.cts +1 -1
- package/types/index.d.ts +1 -1
- package/types/schema/api-document.interface.d.ts +25 -4
- package/types/schema/opra-schema.d.ts +3 -0
- package/types/schema/rpc/rpc-controller.interface.d.ts +22 -0
- package/types/schema/rpc/rpc-header.interface.d.ts +19 -0
- package/types/schema/rpc/rpc-operation.interface.d.ts +26 -0
- package/cjs/http/index.js +0 -7
- package/esm/http/index.js +0 -4
- package/types/http/index.d.ts +0 -4
- /package/cjs/{http/enums → enums}/http-headers-codes.enum.js +0 -0
- /package/cjs/{http/enums → enums}/http-status-codes.enum.js +0 -0
- /package/cjs/{http/enums → enums}/http-status-messages.js +0 -0
- /package/cjs/{http/enums → enums}/mime-types.enum.js +0 -0
- /package/esm/{http/enums → enums}/http-headers-codes.enum.js +0 -0
- /package/esm/{http/enums → enums}/http-status-codes.enum.js +0 -0
- /package/esm/{http/enums → enums}/http-status-messages.js +0 -0
- /package/esm/{http/enums → enums}/mime-types.enum.js +0 -0
- /package/types/{http/enums → enums}/http-headers-codes.enum.d.ts +0 -0
- /package/types/{http/enums → enums}/http-status-codes.enum.d.ts +0 -0
- /package/types/{http/enums → enums}/http-status-messages.d.ts +0 -0
- /package/types/{http/enums → enums}/mime-types.enum.d.ts +0 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RpcApiFactory = void 0;
|
|
4
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
5
|
+
const constants_js_1 = require("../constants.js");
|
|
6
|
+
const rpc_api_js_1 = require("../rpc/rpc-api.js");
|
|
7
|
+
const rpc_controller_js_1 = require("../rpc/rpc-controller.js");
|
|
8
|
+
const rpc_header_js_1 = require("../rpc/rpc-header.js");
|
|
9
|
+
const rpc_operation_js_1 = require("../rpc/rpc-operation.js");
|
|
10
|
+
const rpc_operation_response_js_1 = require("../rpc/rpc-operation-response.js");
|
|
11
|
+
const data_type_factory_js_1 = require("./data-type.factory.js");
|
|
12
|
+
/**
|
|
13
|
+
* @class RpcApiFactory
|
|
14
|
+
*/
|
|
15
|
+
class RpcApiFactory {
|
|
16
|
+
/**
|
|
17
|
+
* Generates RpcApi
|
|
18
|
+
* @param context
|
|
19
|
+
* @param init
|
|
20
|
+
*/
|
|
21
|
+
static async createApi(context, init) {
|
|
22
|
+
const api = new rpc_api_js_1.RpcApi(init);
|
|
23
|
+
if (init.controllers) {
|
|
24
|
+
await context.enterAsync('.controllers', async () => {
|
|
25
|
+
if (Array.isArray(init.controllers)) {
|
|
26
|
+
for (const c of init.controllers) {
|
|
27
|
+
const controller = await this._createController(context, api, c);
|
|
28
|
+
if (controller)
|
|
29
|
+
api.controllers.set(controller.name, controller);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
for (const [k, v] of Object.entries(init.controllers)) {
|
|
34
|
+
const controller = await this._createController(context, api, v, k);
|
|
35
|
+
if (controller)
|
|
36
|
+
api.controllers.set(controller.name, controller);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return api;
|
|
42
|
+
}
|
|
43
|
+
static async _createController(context, parent, thunk, name) {
|
|
44
|
+
if (typeof thunk === 'function' && !(0, index_js_1.isConstructor)(thunk)) {
|
|
45
|
+
thunk = thunk();
|
|
46
|
+
}
|
|
47
|
+
thunk = await (0, index_js_1.resolveThunk)(thunk);
|
|
48
|
+
let ctor;
|
|
49
|
+
let metadata;
|
|
50
|
+
let instance;
|
|
51
|
+
// If thunk is a class
|
|
52
|
+
if (typeof thunk === 'function') {
|
|
53
|
+
metadata = Reflect.getMetadata(constants_js_1.RPC_CONTROLLER_METADATA, thunk);
|
|
54
|
+
if (!metadata)
|
|
55
|
+
return context.addError(`Class "${thunk.name}" doesn't have a valid RpcController metadata`);
|
|
56
|
+
ctor = thunk;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
// If thunk is an instance of a class decorated with RpcController()
|
|
60
|
+
ctor = Object.getPrototypeOf(thunk).constructor;
|
|
61
|
+
metadata = Reflect.getMetadata(constants_js_1.RPC_CONTROLLER_METADATA, ctor);
|
|
62
|
+
if (metadata)
|
|
63
|
+
instance = thunk;
|
|
64
|
+
else {
|
|
65
|
+
// If thunk is a DecoratorMetadata or InitArguments
|
|
66
|
+
metadata = thunk;
|
|
67
|
+
if (thunk.instance === 'object') {
|
|
68
|
+
instance = thunk.instance;
|
|
69
|
+
ctor = Object.getPrototypeOf(instance).constructor;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (!metadata)
|
|
74
|
+
return context.addError(`Class "${ctor.name}" is not decorated with RpcController()`);
|
|
75
|
+
name = name || metadata.name;
|
|
76
|
+
if (!name)
|
|
77
|
+
throw new TypeError(`Controller name required`);
|
|
78
|
+
const controller = new rpc_controller_js_1.RpcController(parent, {
|
|
79
|
+
...metadata,
|
|
80
|
+
name,
|
|
81
|
+
instance,
|
|
82
|
+
ctor,
|
|
83
|
+
});
|
|
84
|
+
if (metadata.types) {
|
|
85
|
+
await context.enterAsync('.types', async () => {
|
|
86
|
+
await data_type_factory_js_1.DataTypeFactory.addDataTypes(context, controller, metadata.types);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (metadata.headers) {
|
|
90
|
+
await context.enterAsync('.headers', async () => {
|
|
91
|
+
let i = 0;
|
|
92
|
+
for (const v of metadata.headers) {
|
|
93
|
+
await context.enterAsync(`[${i++}]`, async () => {
|
|
94
|
+
const prmArgs = { ...v };
|
|
95
|
+
await context.enterAsync('.type', async () => {
|
|
96
|
+
if (v.type)
|
|
97
|
+
prmArgs.type = controller.node.findDataType(v.type);
|
|
98
|
+
if (!prmArgs.type && typeof v.type === 'object') {
|
|
99
|
+
prmArgs.type = await data_type_factory_js_1.DataTypeFactory.createDataType(context, controller, v.type);
|
|
100
|
+
}
|
|
101
|
+
if (!prmArgs.type)
|
|
102
|
+
prmArgs.type = controller.node.getDataType('any');
|
|
103
|
+
});
|
|
104
|
+
const prm = new rpc_header_js_1.RpcHeader(controller, prmArgs);
|
|
105
|
+
controller.headers.push(prm);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
if (metadata.operations) {
|
|
111
|
+
await context.enterAsync('.operations', async () => {
|
|
112
|
+
for (const [operationName, operationMeta] of Object.entries(metadata.operations)) {
|
|
113
|
+
await context.enterAsync(`[${operationName}]`, async () => {
|
|
114
|
+
const operation = new rpc_operation_js_1.RpcOperation(controller, {
|
|
115
|
+
...operationMeta,
|
|
116
|
+
name: operationName,
|
|
117
|
+
types: undefined,
|
|
118
|
+
payloadType: undefined,
|
|
119
|
+
keyType: undefined,
|
|
120
|
+
});
|
|
121
|
+
await this._initRpcOperation(context, operation, operationMeta);
|
|
122
|
+
controller.operations.set(operation.name, operation);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return controller;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Initializes RpcOperation
|
|
131
|
+
* @param context
|
|
132
|
+
* @param operation
|
|
133
|
+
* @param metadata
|
|
134
|
+
* @protected
|
|
135
|
+
*/
|
|
136
|
+
static async _initRpcOperation(context, operation, metadata) {
|
|
137
|
+
if (metadata.types) {
|
|
138
|
+
await context.enterAsync('.types', async () => {
|
|
139
|
+
await data_type_factory_js_1.DataTypeFactory.addDataTypes(context, operation, metadata.types);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
operation.payloadType = await data_type_factory_js_1.DataTypeFactory.resolveDataType(context, operation, metadata.payloadType);
|
|
143
|
+
if (metadata.keyType) {
|
|
144
|
+
operation.keyType = await data_type_factory_js_1.DataTypeFactory.resolveDataType(context, operation, metadata.keyType);
|
|
145
|
+
}
|
|
146
|
+
if (metadata.headers) {
|
|
147
|
+
await context.enterAsync('.headers', async () => {
|
|
148
|
+
let i = 0;
|
|
149
|
+
for (const v of metadata.headers) {
|
|
150
|
+
await context.enterAsync(`[${i++}]`, async () => {
|
|
151
|
+
const prmArgs = { ...v };
|
|
152
|
+
await context.enterAsync('.type', async () => {
|
|
153
|
+
prmArgs.type = await data_type_factory_js_1.DataTypeFactory.resolveDataType(context, operation, v.type);
|
|
154
|
+
});
|
|
155
|
+
const prm = new rpc_header_js_1.RpcHeader(operation, prmArgs);
|
|
156
|
+
operation.headers.push(prm);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
if (metadata.response) {
|
|
162
|
+
await context.enterAsync('.response', async () => {
|
|
163
|
+
const response = new rpc_operation_response_js_1.RpcOperationResponse(operation, {
|
|
164
|
+
...metadata.response,
|
|
165
|
+
payloadType: undefined,
|
|
166
|
+
keyType: undefined,
|
|
167
|
+
});
|
|
168
|
+
await this._initRpcOperationResponse(context, response, metadata.response);
|
|
169
|
+
operation.response = response;
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Initializes RpcOperationResponse
|
|
175
|
+
* @param context
|
|
176
|
+
* @param response
|
|
177
|
+
* @param metadata
|
|
178
|
+
* @protected
|
|
179
|
+
*/
|
|
180
|
+
static async _initRpcOperationResponse(context, response, metadata) {
|
|
181
|
+
response.payloadType = await data_type_factory_js_1.DataTypeFactory.resolveDataType(context, response, metadata.payloadType);
|
|
182
|
+
if (metadata.keyType) {
|
|
183
|
+
response.keyType = await data_type_factory_js_1.DataTypeFactory.resolveDataType(context, response, metadata.keyType);
|
|
184
|
+
}
|
|
185
|
+
if (metadata.headers) {
|
|
186
|
+
await context.enterAsync('.headers', async () => {
|
|
187
|
+
let i = 0;
|
|
188
|
+
for (const v of metadata.headers) {
|
|
189
|
+
await context.enterAsync(`[${i++}]`, async () => {
|
|
190
|
+
const prmArgs = { ...v };
|
|
191
|
+
await context.enterAsync('.type', async () => {
|
|
192
|
+
prmArgs.type = await data_type_factory_js_1.DataTypeFactory.resolveDataType(context, response, v.type);
|
|
193
|
+
});
|
|
194
|
+
const prm = new rpc_header_js_1.RpcHeader(response, prmArgs);
|
|
195
|
+
response.headers.push(prm);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
exports.RpcApiFactory = RpcApiFactory;
|
|
@@ -8,12 +8,13 @@ const http_controller_js_1 = require("./http-controller.js");
|
|
|
8
8
|
* @class HttpApi
|
|
9
9
|
*/
|
|
10
10
|
class HttpApi extends api_base_js_1.ApiBase {
|
|
11
|
-
constructor(
|
|
12
|
-
super(
|
|
11
|
+
constructor(init) {
|
|
12
|
+
super(init);
|
|
13
13
|
// noinspection JSUnusedGlobalSymbols
|
|
14
14
|
this._controllerReverseMap = new WeakMap();
|
|
15
|
-
this.
|
|
15
|
+
this.transport = 'http';
|
|
16
16
|
this.controllers = new index_js_1.ResponsiveMap();
|
|
17
|
+
this.url = init.url;
|
|
17
18
|
}
|
|
18
19
|
findController(arg0) {
|
|
19
20
|
return http_controller_js_1.HttpController.prototype.findController.call(this, arg0);
|
|
@@ -26,7 +27,7 @@ class HttpApi extends api_base_js_1.ApiBase {
|
|
|
26
27
|
const schema = super.toJSON();
|
|
27
28
|
const out = {
|
|
28
29
|
...schema,
|
|
29
|
-
|
|
30
|
+
transport: this.transport,
|
|
30
31
|
url: this.url,
|
|
31
32
|
controllers: {},
|
|
32
33
|
};
|
|
@@ -36,6 +36,8 @@ exports.HttpController = function (...args) {
|
|
|
36
36
|
_this.ctor = initArgs.ctor;
|
|
37
37
|
_this._controllerReverseMap = new WeakMap();
|
|
38
38
|
_this._initialize?.(initArgs);
|
|
39
|
+
_this.onInit = initArgs.onInit;
|
|
40
|
+
_this.onShutdown = initArgs.onShutdown;
|
|
39
41
|
};
|
|
40
42
|
/**
|
|
41
43
|
*
|
|
@@ -155,3 +157,17 @@ class HttpControllerClass extends document_element_js_1.DocumentElement {
|
|
|
155
157
|
exports.HttpController.prototype = HttpControllerClass.prototype;
|
|
156
158
|
Object.assign(exports.HttpController, http_controller_decorator_js_1.HttpControllerDecoratorFactory);
|
|
157
159
|
exports.HttpController[constants_js_1.DECORATOR] = http_controller_decorator_js_1.HttpControllerDecoratorFactory;
|
|
160
|
+
exports.HttpController.OnInit = function () {
|
|
161
|
+
return (target, propertyKey) => {
|
|
162
|
+
const sourceMetadata = (Reflect.getOwnMetadata(constants_js_1.HTTP_CONTROLLER_METADATA, target.constructor) || {});
|
|
163
|
+
sourceMetadata.onInit = target[propertyKey];
|
|
164
|
+
Reflect.defineMetadata(constants_js_1.HTTP_CONTROLLER_METADATA, target.constructor, sourceMetadata);
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
exports.HttpController.OnShutdown = function () {
|
|
168
|
+
return (target, propertyKey) => {
|
|
169
|
+
const sourceMetadata = (Reflect.getOwnMetadata(constants_js_1.HTTP_CONTROLLER_METADATA, target.constructor) || {});
|
|
170
|
+
sourceMetadata.onShutdown = target[propertyKey];
|
|
171
|
+
Reflect.defineMetadata(constants_js_1.HTTP_CONTROLLER_METADATA, target.constructor, sourceMetadata);
|
|
172
|
+
};
|
|
173
|
+
};
|
|
@@ -78,6 +78,12 @@ class HttpOperationClass extends document_element_js_1.DocumentElement {
|
|
|
78
78
|
composition: this.composition,
|
|
79
79
|
requestBody: this.requestBody?.toJSON(),
|
|
80
80
|
});
|
|
81
|
+
if (this.types.size) {
|
|
82
|
+
out.types = {};
|
|
83
|
+
for (const v of this.types.values()) {
|
|
84
|
+
out.types[v.name] = v.toJSON();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
81
87
|
if (this.parameters.length) {
|
|
82
88
|
out.parameters = [];
|
|
83
89
|
for (const prm of this.parameters) {
|
package/cjs/document/index.js
CHANGED
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.classes = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
require("reflect-metadata");
|
|
6
|
+
const RpcControllerDecorator_ = tslib_1.__importStar(require("./decorators/rpc-controller.decorator.js"));
|
|
7
|
+
const RpcOperationDecorator_ = tslib_1.__importStar(require("./decorators/rpc-operation.decorator.js"));
|
|
6
8
|
const DataTypeFactory_ = tslib_1.__importStar(require("./factory/data-type.factory.js"));
|
|
7
9
|
const HttpApiFactory_ = tslib_1.__importStar(require("./factory/http-api.factory.js"));
|
|
8
10
|
tslib_1.__exportStar(require("./api-document.js"), exports);
|
|
@@ -37,8 +39,14 @@ tslib_1.__exportStar(require("./http/http-operation-response.js"), exports);
|
|
|
37
39
|
tslib_1.__exportStar(require("./http/http-parameter.js"), exports);
|
|
38
40
|
tslib_1.__exportStar(require("./http/http-request-body.js"), exports);
|
|
39
41
|
tslib_1.__exportStar(require("./http/http-status-range.js"), exports);
|
|
42
|
+
tslib_1.__exportStar(require("./rpc/rpc-api.js"), exports);
|
|
43
|
+
tslib_1.__exportStar(require("./rpc/rpc-controller.js"), exports);
|
|
44
|
+
tslib_1.__exportStar(require("./rpc/rpc-header.js"), exports);
|
|
45
|
+
tslib_1.__exportStar(require("./rpc/rpc-operation.js"), exports);
|
|
40
46
|
var classes;
|
|
41
47
|
(function (classes) {
|
|
42
48
|
classes.HttpApiFactory = HttpApiFactory_.HttpApiFactory;
|
|
43
49
|
classes.DataTypeFactory = DataTypeFactory_.DataTypeFactory;
|
|
50
|
+
classes.RpcOperationDecoratorFactory = RpcOperationDecorator_.RpcOperationDecoratorFactory;
|
|
51
|
+
classes.RpcControllerDecoratorFactory = RpcControllerDecorator_.RpcControllerDecoratorFactory;
|
|
44
52
|
})(classes || (exports.classes = classes = {}));
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RpcApi = void 0;
|
|
4
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
5
|
+
const api_base_js_1 = require("../common/api-base.js");
|
|
6
|
+
/**
|
|
7
|
+
* @class RpcApi
|
|
8
|
+
*/
|
|
9
|
+
class RpcApi extends api_base_js_1.ApiBase {
|
|
10
|
+
constructor(init) {
|
|
11
|
+
super(init);
|
|
12
|
+
// noinspection JSUnusedGlobalSymbols
|
|
13
|
+
this._controllerReverseMap = new WeakMap();
|
|
14
|
+
this.transport = 'rpc';
|
|
15
|
+
this.controllers = new index_js_1.ResponsiveMap();
|
|
16
|
+
this.platform = init.platform;
|
|
17
|
+
}
|
|
18
|
+
findController(arg0) {
|
|
19
|
+
if (typeof arg0 === 'function') {
|
|
20
|
+
/** Check for cached mapping */
|
|
21
|
+
const controller = this._controllerReverseMap.get(arg0);
|
|
22
|
+
if (controller != null)
|
|
23
|
+
return controller;
|
|
24
|
+
/** Lookup for ctor in all controllers */
|
|
25
|
+
for (const c of this.controllers.values()) {
|
|
26
|
+
if (c.ctor === arg0) {
|
|
27
|
+
this._controllerReverseMap.set(arg0, c);
|
|
28
|
+
return c;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
this._controllerReverseMap.set(arg0, null);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
return this.controllers.get(arg0);
|
|
35
|
+
}
|
|
36
|
+
findOperation(arg0, operationName) {
|
|
37
|
+
const controller = this.findController(arg0);
|
|
38
|
+
return controller?.operations.get(operationName);
|
|
39
|
+
}
|
|
40
|
+
toJSON() {
|
|
41
|
+
const schema = super.toJSON();
|
|
42
|
+
const out = {
|
|
43
|
+
...schema,
|
|
44
|
+
transport: this.transport,
|
|
45
|
+
platform: this.platform,
|
|
46
|
+
controllers: {},
|
|
47
|
+
};
|
|
48
|
+
for (const v of this.controllers.values()) {
|
|
49
|
+
out.controllers[v.name] = v.toJSON();
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.RpcApi = RpcApi;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RpcController = void 0;
|
|
4
|
+
const ts_gems_1 = require("ts-gems");
|
|
5
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
6
|
+
const index_js_2 = require("../../schema/index.js");
|
|
7
|
+
const data_type_map_js_1 = require("../common/data-type-map.js");
|
|
8
|
+
const document_element_js_1 = require("../common/document-element.js");
|
|
9
|
+
const constants_js_1 = require("../constants.js");
|
|
10
|
+
const rpc_controller_decorator_js_1 = require("../decorators/rpc-controller.decorator.js");
|
|
11
|
+
const inspect_util_js_1 = require("../utils/inspect.util.js");
|
|
12
|
+
/**
|
|
13
|
+
* RpcController
|
|
14
|
+
*/
|
|
15
|
+
exports.RpcController = function (...args) {
|
|
16
|
+
// ClassDecorator
|
|
17
|
+
if (!this)
|
|
18
|
+
return exports.RpcController[constants_js_1.DECORATOR].apply(undefined, args);
|
|
19
|
+
// Constructor
|
|
20
|
+
const [owner, initArgs] = args;
|
|
21
|
+
document_element_js_1.DocumentElement.call(this, owner);
|
|
22
|
+
if (!constants_js_1.CLASS_NAME_PATTERN.test(initArgs.name))
|
|
23
|
+
throw new TypeError(`Invalid resource name (${initArgs.name})`);
|
|
24
|
+
const _this = (0, ts_gems_1.asMutable)(this);
|
|
25
|
+
_this.kind = index_js_2.OpraSchema.RpcController.Kind;
|
|
26
|
+
_this.types = _this.node[constants_js_1.kDataTypeMap] = new data_type_map_js_1.DataTypeMap();
|
|
27
|
+
_this.operations = new index_js_1.ResponsiveMap();
|
|
28
|
+
_this.headers = [];
|
|
29
|
+
_this.name = initArgs.name;
|
|
30
|
+
_this.description = initArgs.description;
|
|
31
|
+
_this.instance = initArgs.instance;
|
|
32
|
+
_this.ctor = initArgs.ctor;
|
|
33
|
+
_this._controllerReverseMap = new WeakMap();
|
|
34
|
+
_this._initialize?.(initArgs);
|
|
35
|
+
_this.onInit = initArgs.onInit;
|
|
36
|
+
_this.onShutdown = initArgs.onShutdown;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @class RpcController
|
|
41
|
+
*/
|
|
42
|
+
class RpcControllerClass extends document_element_js_1.DocumentElement {
|
|
43
|
+
findHeader(paramName, location) {
|
|
44
|
+
const paramNameLower = paramName.toLowerCase();
|
|
45
|
+
let prm;
|
|
46
|
+
for (prm of this.headers) {
|
|
47
|
+
if (typeof prm.name === 'string') {
|
|
48
|
+
prm._nameLower = prm._nameLower || prm.name.toLowerCase();
|
|
49
|
+
if (prm._nameLower === paramNameLower)
|
|
50
|
+
return prm;
|
|
51
|
+
}
|
|
52
|
+
if (prm.name instanceof RegExp && prm.name.test(paramName))
|
|
53
|
+
return prm;
|
|
54
|
+
}
|
|
55
|
+
if (this.node.parent && this.node.parent.element instanceof exports.RpcController) {
|
|
56
|
+
return this.node.parent.element.findHeader(paramName, location);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
*
|
|
61
|
+
*/
|
|
62
|
+
toString() {
|
|
63
|
+
return `[RpcController ${this.name}]`;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
*
|
|
67
|
+
*/
|
|
68
|
+
toJSON() {
|
|
69
|
+
const out = (0, index_js_1.omitUndefined)({
|
|
70
|
+
kind: this.kind,
|
|
71
|
+
description: this.description,
|
|
72
|
+
});
|
|
73
|
+
if (this.operations.size) {
|
|
74
|
+
out.operations = {};
|
|
75
|
+
for (const v of this.operations.values()) {
|
|
76
|
+
out.operations[v.name] = v.toJSON();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (this.types.size) {
|
|
80
|
+
out.types = {};
|
|
81
|
+
for (const v of this.types.values()) {
|
|
82
|
+
out.types[v.name] = v.toJSON();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (this.headers.length) {
|
|
86
|
+
out.headers = [];
|
|
87
|
+
for (const prm of this.headers) {
|
|
88
|
+
out.headers.push(prm.toJSON());
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
*
|
|
95
|
+
*/
|
|
96
|
+
[inspect_util_js_1.nodeInspectCustom]() {
|
|
97
|
+
return `[${inspect_util_js_1.colorFgYellow}RpcController${inspect_util_js_1.colorFgMagenta + this.name + inspect_util_js_1.colorReset}]`;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.RpcController.prototype = RpcControllerClass.prototype;
|
|
101
|
+
Object.assign(exports.RpcController, rpc_controller_decorator_js_1.RpcControllerDecoratorFactory);
|
|
102
|
+
exports.RpcController[constants_js_1.DECORATOR] = rpc_controller_decorator_js_1.RpcControllerDecoratorFactory;
|
|
103
|
+
exports.RpcController.OnInit = function () {
|
|
104
|
+
return (target, propertyKey) => {
|
|
105
|
+
const sourceMetadata = (Reflect.getOwnMetadata(constants_js_1.RPC_CONTROLLER_METADATA, target.constructor) || {});
|
|
106
|
+
sourceMetadata.onInit = target[propertyKey];
|
|
107
|
+
Reflect.defineMetadata(constants_js_1.RPC_CONTROLLER_METADATA, target.constructor, sourceMetadata);
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
exports.RpcController.OnShutdown = function () {
|
|
111
|
+
return (target, propertyKey) => {
|
|
112
|
+
const sourceMetadata = (Reflect.getOwnMetadata(constants_js_1.RPC_CONTROLLER_METADATA, target.constructor) || {});
|
|
113
|
+
sourceMetadata.onShutdown = target[propertyKey];
|
|
114
|
+
Reflect.defineMetadata(constants_js_1.RPC_CONTROLLER_METADATA, target.constructor, sourceMetadata);
|
|
115
|
+
};
|
|
116
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RpcHeader = void 0;
|
|
4
|
+
const ts_gems_1 = require("ts-gems");
|
|
5
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
6
|
+
const value_js_1 = require("../common/value.js");
|
|
7
|
+
const parse_regexp_util_js_1 = require("../utils/parse-regexp.util.js");
|
|
8
|
+
exports.RpcHeader = function (owner, initArgs) {
|
|
9
|
+
if (!this)
|
|
10
|
+
throw new TypeError('"this" should be passed to call class constructor');
|
|
11
|
+
value_js_1.Value.call(this, owner, initArgs);
|
|
12
|
+
const _this = (0, ts_gems_1.asMutable)(this);
|
|
13
|
+
if (initArgs.name) {
|
|
14
|
+
_this.name =
|
|
15
|
+
initArgs.name instanceof RegExp
|
|
16
|
+
? initArgs.name
|
|
17
|
+
: initArgs.name.startsWith('/')
|
|
18
|
+
? (0, parse_regexp_util_js_1.parseRegExp)(initArgs.name, {
|
|
19
|
+
includeFlags: 'i',
|
|
20
|
+
excludeFlags: 'm',
|
|
21
|
+
})
|
|
22
|
+
: initArgs.name;
|
|
23
|
+
}
|
|
24
|
+
_this.deprecated = initArgs.deprecated;
|
|
25
|
+
_this.required = initArgs.required;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* @class RpcHeader
|
|
29
|
+
*/
|
|
30
|
+
class RpcHeaderClass extends value_js_1.Value {
|
|
31
|
+
toJSON() {
|
|
32
|
+
return (0, index_js_1.omitUndefined)({
|
|
33
|
+
...super.toJSON(),
|
|
34
|
+
name: this.name,
|
|
35
|
+
required: this.required,
|
|
36
|
+
deprecated: this.deprecated,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.RpcHeader.prototype = RpcHeaderClass.prototype;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RpcOperationResponse = void 0;
|
|
4
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
5
|
+
const document_element_js_1 = require("../common/document-element.js");
|
|
6
|
+
const data_type_js_1 = require("../data-type/data-type.js");
|
|
7
|
+
/**
|
|
8
|
+
* @class RpcOperationResponse
|
|
9
|
+
*/
|
|
10
|
+
class RpcOperationResponse extends document_element_js_1.DocumentElement {
|
|
11
|
+
constructor(owner, initArgs) {
|
|
12
|
+
super(owner);
|
|
13
|
+
this.headers = [];
|
|
14
|
+
this.channel = initArgs?.channel;
|
|
15
|
+
this.description = initArgs?.description;
|
|
16
|
+
if (initArgs?.payloadType) {
|
|
17
|
+
this.payloadType =
|
|
18
|
+
initArgs?.payloadType instanceof data_type_js_1.DataType
|
|
19
|
+
? initArgs.payloadType
|
|
20
|
+
: this.owner.node.getDataType(initArgs.payloadType);
|
|
21
|
+
}
|
|
22
|
+
else
|
|
23
|
+
this.payloadType = this.owner.node.getDataType('any');
|
|
24
|
+
if (initArgs?.keyType) {
|
|
25
|
+
this.keyType =
|
|
26
|
+
initArgs?.keyType instanceof data_type_js_1.DataType ? initArgs.keyType : this.owner.node.getDataType(initArgs.keyType);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
findHeader(paramName) {
|
|
30
|
+
const paramNameLower = paramName.toLowerCase();
|
|
31
|
+
let prm;
|
|
32
|
+
for (prm of this.headers) {
|
|
33
|
+
if (typeof prm.name === 'string') {
|
|
34
|
+
prm._nameLower = prm._nameLower || prm.name.toLowerCase();
|
|
35
|
+
if (prm._nameLower === paramNameLower)
|
|
36
|
+
return prm;
|
|
37
|
+
}
|
|
38
|
+
if (prm.name instanceof RegExp && prm.name.test(paramName))
|
|
39
|
+
return prm;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
toJSON() {
|
|
43
|
+
const out = (0, index_js_1.omitUndefined)({
|
|
44
|
+
description: this.description,
|
|
45
|
+
channel: this.channel,
|
|
46
|
+
payloadType: this.payloadType.name ? this.payloadType.name : this.payloadType.toJSON(),
|
|
47
|
+
keyType: this.keyType ? (this.keyType.name ? this.keyType.name : this.keyType.toJSON()) : undefined,
|
|
48
|
+
});
|
|
49
|
+
if (this.headers.length) {
|
|
50
|
+
out.headers = [];
|
|
51
|
+
for (const prm of this.headers) {
|
|
52
|
+
out.headers.push(prm.toJSON());
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.RpcOperationResponse = RpcOperationResponse;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RpcOperation = void 0;
|
|
4
|
+
const ts_gems_1 = require("ts-gems");
|
|
5
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
6
|
+
const index_js_2 = require("../../schema/index.js");
|
|
7
|
+
const data_type_map_js_1 = require("../common/data-type-map.js");
|
|
8
|
+
const document_element_js_1 = require("../common/document-element.js");
|
|
9
|
+
const constants_js_1 = require("../constants.js");
|
|
10
|
+
const data_type_js_1 = require("../data-type/data-type.js");
|
|
11
|
+
const rpc_operation_decorator_js_1 = require("../decorators/rpc-operation.decorator.js");
|
|
12
|
+
/**
|
|
13
|
+
* RpcOperation
|
|
14
|
+
*/
|
|
15
|
+
exports.RpcOperation = function (...args) {
|
|
16
|
+
// Decorator
|
|
17
|
+
if (!this) {
|
|
18
|
+
const [payloadType, options] = args;
|
|
19
|
+
const decoratorChain = [];
|
|
20
|
+
return exports.RpcOperation[constants_js_1.DECORATOR].call(undefined, decoratorChain, payloadType, options);
|
|
21
|
+
}
|
|
22
|
+
// Constructor
|
|
23
|
+
const [resource, initArgs] = args;
|
|
24
|
+
document_element_js_1.DocumentElement.call(this, resource);
|
|
25
|
+
if (!constants_js_1.CLASS_NAME_PATTERN.test(initArgs.name))
|
|
26
|
+
throw new TypeError(`Invalid operation name (${initArgs.name})`);
|
|
27
|
+
const _this = (0, ts_gems_1.asMutable)(this);
|
|
28
|
+
_this.headers = [];
|
|
29
|
+
_this.types = _this.node[constants_js_1.kDataTypeMap] = new data_type_map_js_1.DataTypeMap();
|
|
30
|
+
_this.name = initArgs.name;
|
|
31
|
+
_this.description = initArgs.description;
|
|
32
|
+
_this.channel = initArgs.channel;
|
|
33
|
+
if (initArgs?.payloadType) {
|
|
34
|
+
_this.payloadType =
|
|
35
|
+
initArgs?.payloadType instanceof data_type_js_1.DataType
|
|
36
|
+
? initArgs.payloadType
|
|
37
|
+
: _this.owner.node.getDataType(initArgs.payloadType);
|
|
38
|
+
}
|
|
39
|
+
if (initArgs?.keyType) {
|
|
40
|
+
_this.keyType =
|
|
41
|
+
initArgs?.keyType instanceof data_type_js_1.DataType ? initArgs.keyType : _this.owner.node.getDataType(initArgs.keyType);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* @class RpcOperation
|
|
46
|
+
*/
|
|
47
|
+
class RpcOperationClass extends document_element_js_1.DocumentElement {
|
|
48
|
+
findHeader(paramName) {
|
|
49
|
+
const paramNameLower = paramName.toLowerCase();
|
|
50
|
+
let prm;
|
|
51
|
+
for (prm of this.headers) {
|
|
52
|
+
if (typeof prm.name === 'string') {
|
|
53
|
+
prm._nameLower = prm._nameLower || prm.name.toLowerCase();
|
|
54
|
+
if (prm._nameLower === paramNameLower)
|
|
55
|
+
return prm;
|
|
56
|
+
}
|
|
57
|
+
if (prm.name instanceof RegExp && prm.name.test(paramName))
|
|
58
|
+
return prm;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
toJSON() {
|
|
62
|
+
const out = (0, index_js_1.omitUndefined)({
|
|
63
|
+
kind: index_js_2.OpraSchema.RpcOperation.Kind,
|
|
64
|
+
description: this.description,
|
|
65
|
+
channel: this.channel,
|
|
66
|
+
payloadType: this.payloadType.name ? this.payloadType.name : this.payloadType.toJSON(),
|
|
67
|
+
keyType: this.keyType ? (this.keyType.name ? this.keyType.name : this.keyType.toJSON()) : undefined,
|
|
68
|
+
response: this.response?.toJSON(),
|
|
69
|
+
});
|
|
70
|
+
if (this.headers.length) {
|
|
71
|
+
out.headers = [];
|
|
72
|
+
for (const prm of this.headers) {
|
|
73
|
+
out.headers.push(prm.toJSON());
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.RpcOperation.prototype = RpcOperationClass.prototype;
|
|
80
|
+
exports.RpcOperation[constants_js_1.DECORATOR] = rpc_operation_decorator_js_1.RpcOperationDecoratorFactory;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./http-headers-codes.enum.js"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./http-status-codes.enum.js"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./http-status-messages.js"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./mime-types.enum.js"), exports);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ForbiddenError = void 0;
|
|
4
|
-
const index_js_1 = require("../../
|
|
4
|
+
const index_js_1 = require("../../enums/index.js");
|
|
5
5
|
const index_js_2 = require("../../i18n/index.js");
|
|
6
6
|
const opra_http_error_js_1 = require("../opra-http-error.js");
|
|
7
7
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ResourceNotAvailableError = void 0;
|
|
4
|
-
const index_js_1 = require("../../
|
|
4
|
+
const index_js_1 = require("../../enums/index.js");
|
|
5
5
|
const index_js_2 = require("../../i18n/index.js");
|
|
6
6
|
const opra_http_error_js_1 = require("../opra-http-error.js");
|
|
7
7
|
/**
|