@opra/common 1.0.0-beta.3 → 1.0.0-beta.5
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 +4 -4
- package/cjs/document/constants.js +2 -2
- package/cjs/document/decorators/{msg-controller.decorator.js → rpc-controller.decorator.js} +13 -8
- package/cjs/document/decorators/{msg-operation.decorator.js → rpc-operation.decorator.js} +6 -6
- package/cjs/document/factory/api-document.factory.js +3 -3
- package/cjs/document/factory/{msg-api.factory.js → rpc-api.factory.js} +28 -28
- package/cjs/document/http/http-operation.js +6 -0
- package/cjs/document/index.js +8 -6
- package/cjs/document/{msg/msg-api.js → rpc/rpc-api.js} +5 -5
- package/cjs/document/{msg/msg-controller.js → rpc/rpc-controller.js} +20 -20
- package/cjs/document/{msg/msg-header.js → rpc/rpc-header.js} +5 -5
- package/cjs/document/{msg/msg-operation-response.js → rpc/rpc-operation-response.js} +4 -4
- package/cjs/document/{msg/msg-operation.js → rpc/rpc-operation.js} +10 -10
- package/cjs/schema/opra-schema.js +3 -3
- package/cjs/schema/rpc/rpc-controller.interface.js +11 -0
- package/cjs/schema/rpc/rpc-operation.interface.js +7 -0
- package/esm/document/api-document.js +4 -4
- package/esm/document/constants.js +1 -1
- package/esm/document/decorators/{msg-controller.decorator.js → rpc-controller.decorator.js} +13 -8
- package/esm/document/decorators/{msg-operation.decorator.js → rpc-operation.decorator.js} +6 -6
- package/esm/document/factory/api-document.factory.js +3 -3
- package/esm/document/factory/{msg-api.factory.js → rpc-api.factory.js} +27 -27
- package/esm/document/http/http-operation.js +6 -0
- package/esm/document/index.js +8 -6
- package/esm/document/{msg/msg-api.js → rpc/rpc-api.js} +3 -3
- package/esm/document/{msg/msg-controller.js → rpc/rpc-controller.js} +20 -20
- package/esm/document/{msg/msg-header.js → rpc/rpc-header.js} +4 -4
- package/esm/document/{msg/msg-operation-response.js → rpc/rpc-operation-response.js} +2 -2
- package/esm/document/{msg/msg-operation.js → rpc/rpc-operation.js} +9 -9
- package/esm/schema/opra-schema.js +3 -3
- package/esm/schema/rpc/rpc-controller.interface.js +8 -0
- package/esm/schema/rpc/rpc-operation.interface.js +4 -0
- package/package.json +1 -1
- package/types/document/api-document.d.ts +3 -3
- package/types/document/constants.d.ts +1 -1
- 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 -2
- package/types/document/factory/rpc-api.factory.d.ts +40 -0
- package/types/document/index.d.ts +11 -8
- package/types/document/rpc/rpc-api.d.ts +27 -0
- package/types/document/rpc/rpc-controller.d.ts +89 -0
- package/types/document/{msg/msg-header.d.ts → rpc/rpc-header.d.ts} +15 -15
- package/types/document/{msg/msg-operation-response.d.ts → rpc/rpc-operation-response.d.ts} +13 -13
- package/types/document/{msg/msg-operation.d.ts → rpc/rpc-operation.d.ts} +27 -27
- package/types/schema/api-document.interface.d.ts +9 -11
- package/types/schema/opra-schema.d.ts +3 -3
- package/types/schema/rpc/rpc-controller.interface.d.ts +22 -0
- package/types/schema/{msg/msg-header.interface.d.ts → rpc/rpc-header.interface.d.ts} +2 -2
- package/types/schema/{msg/msg-operation.interface.d.ts → rpc/rpc-operation.interface.d.ts} +11 -11
- package/cjs/schema/msg/msg-controller.interface.js +0 -11
- package/cjs/schema/msg/msg-operation.interface.js +0 -7
- package/esm/schema/msg/msg-controller.interface.js +0 -8
- package/esm/schema/msg/msg-operation.interface.js +0 -4
- package/types/document/decorators/msg-controller.decorator.d.ts +0 -11
- package/types/document/decorators/msg-operation.decorator.d.ts +0 -29
- package/types/document/factory/msg-api.factory.d.ts +0 -40
- package/types/document/msg/msg-api.d.ts +0 -27
- package/types/document/msg/msg-controller.d.ts +0 -89
- package/types/schema/msg/msg-controller.interface.d.ts +0 -22
- /package/cjs/schema/{msg/msg-header.interface.js → rpc/rpc-header.interface.js} +0 -0
- /package/esm/schema/{msg/msg-header.interface.js → rpc/rpc-header.interface.js} +0 -0
|
@@ -10,7 +10,7 @@ const document_element_js_1 = require("./common/document-element.js");
|
|
|
10
10
|
const constants_js_1 = require("./constants.js");
|
|
11
11
|
const data_type_js_1 = require("./data-type/data-type.js");
|
|
12
12
|
const http_api_js_1 = require("./http/http-api.js");
|
|
13
|
-
const
|
|
13
|
+
const rpc_api_js_1 = require("./rpc/rpc-api.js");
|
|
14
14
|
/**
|
|
15
15
|
*
|
|
16
16
|
* @class ApiDocument
|
|
@@ -52,9 +52,9 @@ class ApiDocument extends document_element_js_1.DocumentElement {
|
|
|
52
52
|
}
|
|
53
53
|
return this.api;
|
|
54
54
|
}
|
|
55
|
-
get
|
|
56
|
-
if (!(this.api && this.api instanceof
|
|
57
|
-
throw new TypeError('The document do not contains
|
|
55
|
+
get rpcApi() {
|
|
56
|
+
if (!(this.api && this.api instanceof rpc_api_js_1.RpcApi)) {
|
|
57
|
+
throw new TypeError('The document do not contains RpcApi instance');
|
|
58
58
|
}
|
|
59
59
|
return this.api;
|
|
60
60
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.kTypeNSMap = exports.kCtorMap = exports.kDataTypeMap = exports.EXTRACT_TYPENAME_PATTERN = exports.CLASS_NAME_PATTERN = exports.NAMESPACE_PATTERN = exports.BUILTIN = exports.DECORATOR = exports.ENCODER = exports.DECODER = exports.
|
|
3
|
+
exports.kTypeNSMap = exports.kCtorMap = exports.kDataTypeMap = exports.EXTRACT_TYPENAME_PATTERN = exports.CLASS_NAME_PATTERN = exports.NAMESPACE_PATTERN = exports.BUILTIN = exports.DECORATOR = exports.ENCODER = exports.DECODER = exports.RPC_CONTROLLER_METADATA = exports.HTTP_CONTROLLER_METADATA = exports.DATATYPE_METADATA = void 0;
|
|
4
4
|
exports.DATATYPE_METADATA = Symbol.for('opra.type.metadata');
|
|
5
5
|
exports.HTTP_CONTROLLER_METADATA = Symbol('opra.http-controller.metadata');
|
|
6
|
-
exports.
|
|
6
|
+
exports.RPC_CONTROLLER_METADATA = Symbol('opra.rpc-controller.metadata');
|
|
7
7
|
exports.DECODER = Symbol.for('opra.type.decoder');
|
|
8
8
|
exports.ENCODER = Symbol('opra.type.encoder');
|
|
9
9
|
exports.DECORATOR = Symbol.for('DECORATOR');
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.RpcControllerDecoratorFactory = RpcControllerDecoratorFactory;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const lodash_omit_1 = tslib_1.__importDefault(require("lodash.omit"));
|
|
6
6
|
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
7
7
|
const index_js_1 = require("../../schema/index.js");
|
|
8
8
|
const constants_js_1 = require("../constants.js");
|
|
9
9
|
const CLASS_NAME_PATTERN = /^(.*)(Controller)$/;
|
|
10
|
-
|
|
10
|
+
const augmentationRegistry = [];
|
|
11
|
+
function RpcControllerDecoratorFactory(options) {
|
|
11
12
|
const decoratorChain = [];
|
|
12
13
|
/**
|
|
13
14
|
*
|
|
@@ -17,22 +18,22 @@ function MsgControllerDecoratorFactory(options) {
|
|
|
17
18
|
if (!name)
|
|
18
19
|
name = CLASS_NAME_PATTERN.exec(target.name)?.[1] || target.name;
|
|
19
20
|
const metadata = {};
|
|
20
|
-
const baseMetadata = Reflect.getOwnMetadata(constants_js_1.
|
|
21
|
+
const baseMetadata = Reflect.getOwnMetadata(constants_js_1.RPC_CONTROLLER_METADATA, Object.getPrototypeOf(target));
|
|
21
22
|
if (baseMetadata)
|
|
22
23
|
(0, putil_merge_1.default)(metadata, baseMetadata, { deep: true });
|
|
23
|
-
const oldMetadata = Reflect.getOwnMetadata(constants_js_1.
|
|
24
|
+
const oldMetadata = Reflect.getOwnMetadata(constants_js_1.RPC_CONTROLLER_METADATA, target);
|
|
24
25
|
if (oldMetadata)
|
|
25
26
|
(0, putil_merge_1.default)(metadata, oldMetadata, { deep: true });
|
|
26
27
|
(0, putil_merge_1.default)(metadata, {
|
|
27
|
-
kind: index_js_1.OpraSchema.
|
|
28
|
+
kind: index_js_1.OpraSchema.RpcController.Kind,
|
|
28
29
|
name,
|
|
29
30
|
path: name,
|
|
30
31
|
...(0, lodash_omit_1.default)(options, ['kind', 'name', 'instance', 'endpoints', 'key']),
|
|
31
32
|
}, { deep: true });
|
|
32
|
-
Reflect.defineMetadata(constants_js_1.
|
|
33
|
+
Reflect.defineMetadata(constants_js_1.RPC_CONTROLLER_METADATA, metadata, target);
|
|
33
34
|
for (const fn of decoratorChain)
|
|
34
|
-
fn(metadata);
|
|
35
|
-
Reflect.defineMetadata(constants_js_1.
|
|
35
|
+
fn(metadata, target);
|
|
36
|
+
Reflect.defineMetadata(constants_js_1.RPC_CONTROLLER_METADATA, metadata, target);
|
|
36
37
|
};
|
|
37
38
|
/**
|
|
38
39
|
*
|
|
@@ -60,5 +61,9 @@ function MsgControllerDecoratorFactory(options) {
|
|
|
60
61
|
});
|
|
61
62
|
return decorator;
|
|
62
63
|
};
|
|
64
|
+
augmentationRegistry.forEach(fn => fn(decorator, decoratorChain, options));
|
|
63
65
|
return decorator;
|
|
64
66
|
}
|
|
67
|
+
RpcControllerDecoratorFactory.augment = function (fn) {
|
|
68
|
+
augmentationRegistry.push(fn);
|
|
69
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.RpcOperationDecoratorFactory = RpcOperationDecoratorFactory;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const lodash_omit_1 = tslib_1.__importDefault(require("lodash.omit"));
|
|
6
6
|
const index_js_1 = require("../../schema/index.js");
|
|
7
7
|
const constants_js_1 = require("../constants.js");
|
|
8
8
|
const augmentationRegistry = [];
|
|
9
|
-
function
|
|
9
|
+
function RpcOperationDecoratorFactory(decoratorChain, payloadType, options) {
|
|
10
10
|
let inResponse = false;
|
|
11
11
|
/**
|
|
12
12
|
*
|
|
@@ -15,18 +15,18 @@ function MsgOperationDecoratorFactory(decoratorChain, payloadType, options) {
|
|
|
15
15
|
if (typeof propertyKey !== 'string')
|
|
16
16
|
throw new TypeError(`Symbol properties can not be decorated`);
|
|
17
17
|
const operationMetadata = {
|
|
18
|
-
kind: index_js_1.OpraSchema.
|
|
18
|
+
kind: index_js_1.OpraSchema.RpcOperation.Kind,
|
|
19
19
|
channel: propertyKey,
|
|
20
20
|
...(0, lodash_omit_1.default)(options, ['kind']),
|
|
21
21
|
payloadType,
|
|
22
22
|
};
|
|
23
|
-
const controllerMetadata = (Reflect.getOwnMetadata(constants_js_1.
|
|
23
|
+
const controllerMetadata = (Reflect.getOwnMetadata(constants_js_1.RPC_CONTROLLER_METADATA, target.constructor) ||
|
|
24
24
|
{});
|
|
25
25
|
controllerMetadata.operations = controllerMetadata.operations || {};
|
|
26
26
|
controllerMetadata.operations[propertyKey] = operationMetadata;
|
|
27
27
|
for (const fn of decoratorChain)
|
|
28
28
|
fn(operationMetadata, target, propertyKey);
|
|
29
|
-
Reflect.defineMetadata(constants_js_1.
|
|
29
|
+
Reflect.defineMetadata(constants_js_1.RPC_CONTROLLER_METADATA, controllerMetadata, target.constructor);
|
|
30
30
|
});
|
|
31
31
|
/**
|
|
32
32
|
*
|
|
@@ -75,6 +75,6 @@ function MsgOperationDecoratorFactory(decoratorChain, payloadType, options) {
|
|
|
75
75
|
augmentationRegistry.forEach(fn => fn(decorator, decoratorChain, payloadType, options));
|
|
76
76
|
return decorator;
|
|
77
77
|
}
|
|
78
|
-
|
|
78
|
+
RpcOperationDecoratorFactory.augment = function (fn) {
|
|
79
79
|
augmentationRegistry.push(fn);
|
|
80
80
|
};
|
|
@@ -11,7 +11,7 @@ const index_js_3 = require("../data-type/extended-types/index.js");
|
|
|
11
11
|
const index_js_4 = require("../data-type/primitive-types/index.js");
|
|
12
12
|
const data_type_factory_js_1 = require("./data-type.factory.js");
|
|
13
13
|
const http_api_factory_js_1 = require("./http-api.factory.js");
|
|
14
|
-
const
|
|
14
|
+
const rpc_api_factory_js_1 = require("./rpc-api.factory.js");
|
|
15
15
|
const OPRA_SPEC_URL = 'https://oprajs.com/spec/v' + index_js_2.OpraSchema.SpecVersion;
|
|
16
16
|
/**
|
|
17
17
|
* @class ApiDocumentFactory
|
|
@@ -117,8 +117,8 @@ class ApiDocumentFactory {
|
|
|
117
117
|
if (api)
|
|
118
118
|
document.api = api;
|
|
119
119
|
}
|
|
120
|
-
else if (init.api && init.api.transport === '
|
|
121
|
-
const api = await
|
|
120
|
+
else if (init.api && init.api.transport === 'rpc') {
|
|
121
|
+
const api = await rpc_api_factory_js_1.RpcApiFactory.createApi(context, { ...init.api, owner: document });
|
|
122
122
|
if (api)
|
|
123
123
|
document.api = api;
|
|
124
124
|
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.RpcApiFactory = void 0;
|
|
4
4
|
const index_js_1 = require("../../helpers/index.js");
|
|
5
5
|
const constants_js_1 = require("../constants.js");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
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
11
|
const data_type_factory_js_1 = require("./data-type.factory.js");
|
|
12
12
|
/**
|
|
13
|
-
* @class
|
|
13
|
+
* @class RpcApiFactory
|
|
14
14
|
*/
|
|
15
|
-
class
|
|
15
|
+
class RpcApiFactory {
|
|
16
16
|
/**
|
|
17
|
-
* Generates
|
|
17
|
+
* Generates RpcApi
|
|
18
18
|
* @param context
|
|
19
19
|
* @param init
|
|
20
20
|
*/
|
|
21
21
|
static async createApi(context, init) {
|
|
22
|
-
const api = new
|
|
22
|
+
const api = new rpc_api_js_1.RpcApi(init);
|
|
23
23
|
if (init.controllers) {
|
|
24
24
|
await context.enterAsync('.controllers', async () => {
|
|
25
25
|
if (Array.isArray(init.controllers)) {
|
|
@@ -50,15 +50,15 @@ class MsgApiFactory {
|
|
|
50
50
|
let instance;
|
|
51
51
|
// If thunk is a class
|
|
52
52
|
if (typeof thunk === 'function') {
|
|
53
|
-
metadata = Reflect.getMetadata(constants_js_1.
|
|
53
|
+
metadata = Reflect.getMetadata(constants_js_1.RPC_CONTROLLER_METADATA, thunk);
|
|
54
54
|
if (!metadata)
|
|
55
|
-
return context.addError(`Class "${thunk.name}" doesn't have a valid
|
|
55
|
+
return context.addError(`Class "${thunk.name}" doesn't have a valid RpcController metadata`);
|
|
56
56
|
ctor = thunk;
|
|
57
57
|
}
|
|
58
58
|
else {
|
|
59
|
-
// If thunk is an instance of a class decorated with
|
|
59
|
+
// If thunk is an instance of a class decorated with RpcController()
|
|
60
60
|
ctor = Object.getPrototypeOf(thunk).constructor;
|
|
61
|
-
metadata = Reflect.getMetadata(constants_js_1.
|
|
61
|
+
metadata = Reflect.getMetadata(constants_js_1.RPC_CONTROLLER_METADATA, ctor);
|
|
62
62
|
if (metadata)
|
|
63
63
|
instance = thunk;
|
|
64
64
|
else {
|
|
@@ -71,11 +71,11 @@ class MsgApiFactory {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
if (!metadata)
|
|
74
|
-
return context.addError(`Class "${ctor.name}" is not decorated with
|
|
74
|
+
return context.addError(`Class "${ctor.name}" is not decorated with RpcController()`);
|
|
75
75
|
name = name || metadata.name;
|
|
76
76
|
if (!name)
|
|
77
77
|
throw new TypeError(`Controller name required`);
|
|
78
|
-
const controller = new
|
|
78
|
+
const controller = new rpc_controller_js_1.RpcController(parent, {
|
|
79
79
|
...metadata,
|
|
80
80
|
name,
|
|
81
81
|
instance,
|
|
@@ -101,7 +101,7 @@ class MsgApiFactory {
|
|
|
101
101
|
if (!prmArgs.type)
|
|
102
102
|
prmArgs.type = controller.node.getDataType('any');
|
|
103
103
|
});
|
|
104
|
-
const prm = new
|
|
104
|
+
const prm = new rpc_header_js_1.RpcHeader(controller, prmArgs);
|
|
105
105
|
controller.headers.push(prm);
|
|
106
106
|
});
|
|
107
107
|
}
|
|
@@ -111,14 +111,14 @@ class MsgApiFactory {
|
|
|
111
111
|
await context.enterAsync('.operations', async () => {
|
|
112
112
|
for (const [operationName, operationMeta] of Object.entries(metadata.operations)) {
|
|
113
113
|
await context.enterAsync(`[${operationName}]`, async () => {
|
|
114
|
-
const operation = new
|
|
114
|
+
const operation = new rpc_operation_js_1.RpcOperation(controller, {
|
|
115
115
|
...operationMeta,
|
|
116
116
|
name: operationName,
|
|
117
117
|
types: undefined,
|
|
118
118
|
payloadType: undefined,
|
|
119
119
|
keyType: undefined,
|
|
120
120
|
});
|
|
121
|
-
await this.
|
|
121
|
+
await this._initRpcOperation(context, operation, operationMeta);
|
|
122
122
|
controller.operations.set(operation.name, operation);
|
|
123
123
|
});
|
|
124
124
|
}
|
|
@@ -127,13 +127,13 @@ class MsgApiFactory {
|
|
|
127
127
|
return controller;
|
|
128
128
|
}
|
|
129
129
|
/**
|
|
130
|
-
* Initializes
|
|
130
|
+
* Initializes RpcOperation
|
|
131
131
|
* @param context
|
|
132
132
|
* @param operation
|
|
133
133
|
* @param metadata
|
|
134
134
|
* @protected
|
|
135
135
|
*/
|
|
136
|
-
static async
|
|
136
|
+
static async _initRpcOperation(context, operation, metadata) {
|
|
137
137
|
if (metadata.types) {
|
|
138
138
|
await context.enterAsync('.types', async () => {
|
|
139
139
|
await data_type_factory_js_1.DataTypeFactory.addDataTypes(context, operation, metadata.types);
|
|
@@ -152,7 +152,7 @@ class MsgApiFactory {
|
|
|
152
152
|
await context.enterAsync('.type', async () => {
|
|
153
153
|
prmArgs.type = await data_type_factory_js_1.DataTypeFactory.resolveDataType(context, operation, v.type);
|
|
154
154
|
});
|
|
155
|
-
const prm = new
|
|
155
|
+
const prm = new rpc_header_js_1.RpcHeader(operation, prmArgs);
|
|
156
156
|
operation.headers.push(prm);
|
|
157
157
|
});
|
|
158
158
|
}
|
|
@@ -160,24 +160,24 @@ class MsgApiFactory {
|
|
|
160
160
|
}
|
|
161
161
|
if (metadata.response) {
|
|
162
162
|
await context.enterAsync('.response', async () => {
|
|
163
|
-
const response = new
|
|
163
|
+
const response = new rpc_operation_response_js_1.RpcOperationResponse(operation, {
|
|
164
164
|
...metadata.response,
|
|
165
165
|
payloadType: undefined,
|
|
166
166
|
keyType: undefined,
|
|
167
167
|
});
|
|
168
|
-
await this.
|
|
168
|
+
await this._initRpcOperationResponse(context, response, metadata.response);
|
|
169
169
|
operation.response = response;
|
|
170
170
|
});
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
/**
|
|
174
|
-
* Initializes
|
|
174
|
+
* Initializes RpcOperationResponse
|
|
175
175
|
* @param context
|
|
176
176
|
* @param response
|
|
177
177
|
* @param metadata
|
|
178
178
|
* @protected
|
|
179
179
|
*/
|
|
180
|
-
static async
|
|
180
|
+
static async _initRpcOperationResponse(context, response, metadata) {
|
|
181
181
|
response.payloadType = await data_type_factory_js_1.DataTypeFactory.resolveDataType(context, response, metadata.payloadType);
|
|
182
182
|
if (metadata.keyType) {
|
|
183
183
|
response.keyType = await data_type_factory_js_1.DataTypeFactory.resolveDataType(context, response, metadata.keyType);
|
|
@@ -191,7 +191,7 @@ class MsgApiFactory {
|
|
|
191
191
|
await context.enterAsync('.type', async () => {
|
|
192
192
|
prmArgs.type = await data_type_factory_js_1.DataTypeFactory.resolveDataType(context, response, v.type);
|
|
193
193
|
});
|
|
194
|
-
const prm = new
|
|
194
|
+
const prm = new rpc_header_js_1.RpcHeader(response, prmArgs);
|
|
195
195
|
response.headers.push(prm);
|
|
196
196
|
});
|
|
197
197
|
}
|
|
@@ -199,4 +199,4 @@ class MsgApiFactory {
|
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
|
-
exports.
|
|
202
|
+
exports.RpcApiFactory = RpcApiFactory;
|
|
@@ -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,7 +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
|
|
6
|
+
const RpcControllerDecorator_ = tslib_1.__importStar(require("./decorators/rpc-controller.decorator.js"));
|
|
7
|
+
const RpcOperationDecorator_ = tslib_1.__importStar(require("./decorators/rpc-operation.decorator.js"));
|
|
7
8
|
const DataTypeFactory_ = tslib_1.__importStar(require("./factory/data-type.factory.js"));
|
|
8
9
|
const HttpApiFactory_ = tslib_1.__importStar(require("./factory/http-api.factory.js"));
|
|
9
10
|
tslib_1.__exportStar(require("./api-document.js"), exports);
|
|
@@ -38,13 +39,14 @@ tslib_1.__exportStar(require("./http/http-operation-response.js"), exports);
|
|
|
38
39
|
tslib_1.__exportStar(require("./http/http-parameter.js"), exports);
|
|
39
40
|
tslib_1.__exportStar(require("./http/http-request-body.js"), exports);
|
|
40
41
|
tslib_1.__exportStar(require("./http/http-status-range.js"), exports);
|
|
41
|
-
tslib_1.__exportStar(require("./
|
|
42
|
-
tslib_1.__exportStar(require("./
|
|
43
|
-
tslib_1.__exportStar(require("./
|
|
44
|
-
tslib_1.__exportStar(require("./
|
|
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);
|
|
45
46
|
var classes;
|
|
46
47
|
(function (classes) {
|
|
47
48
|
classes.HttpApiFactory = HttpApiFactory_.HttpApiFactory;
|
|
48
49
|
classes.DataTypeFactory = DataTypeFactory_.DataTypeFactory;
|
|
49
|
-
classes.
|
|
50
|
+
classes.RpcOperationDecoratorFactory = RpcOperationDecorator_.RpcOperationDecoratorFactory;
|
|
51
|
+
classes.RpcControllerDecoratorFactory = RpcControllerDecorator_.RpcControllerDecoratorFactory;
|
|
50
52
|
})(classes || (exports.classes = classes = {}));
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.RpcApi = void 0;
|
|
4
4
|
const index_js_1 = require("../../helpers/index.js");
|
|
5
5
|
const api_base_js_1 = require("../common/api-base.js");
|
|
6
6
|
/**
|
|
7
|
-
* @class
|
|
7
|
+
* @class RpcApi
|
|
8
8
|
*/
|
|
9
|
-
class
|
|
9
|
+
class RpcApi extends api_base_js_1.ApiBase {
|
|
10
10
|
constructor(init) {
|
|
11
11
|
super(init);
|
|
12
12
|
// noinspection JSUnusedGlobalSymbols
|
|
13
13
|
this._controllerReverseMap = new WeakMap();
|
|
14
|
-
this.transport = '
|
|
14
|
+
this.transport = 'rpc';
|
|
15
15
|
this.controllers = new index_js_1.ResponsiveMap();
|
|
16
16
|
this.platform = init.platform;
|
|
17
17
|
}
|
|
@@ -51,4 +51,4 @@ class MsgApi extends api_base_js_1.ApiBase {
|
|
|
51
51
|
return out;
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
exports.
|
|
54
|
+
exports.RpcApi = RpcApi;
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.RpcController = void 0;
|
|
4
4
|
const ts_gems_1 = require("ts-gems");
|
|
5
5
|
const index_js_1 = require("../../helpers/index.js");
|
|
6
6
|
const index_js_2 = require("../../schema/index.js");
|
|
7
7
|
const data_type_map_js_1 = require("../common/data-type-map.js");
|
|
8
8
|
const document_element_js_1 = require("../common/document-element.js");
|
|
9
9
|
const constants_js_1 = require("../constants.js");
|
|
10
|
-
const
|
|
10
|
+
const rpc_controller_decorator_js_1 = require("../decorators/rpc-controller.decorator.js");
|
|
11
11
|
const inspect_util_js_1 = require("../utils/inspect.util.js");
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* RpcController
|
|
14
14
|
*/
|
|
15
|
-
exports.
|
|
15
|
+
exports.RpcController = function (...args) {
|
|
16
16
|
// ClassDecorator
|
|
17
17
|
if (!this)
|
|
18
|
-
return exports.
|
|
18
|
+
return exports.RpcController[constants_js_1.DECORATOR].apply(undefined, args);
|
|
19
19
|
// Constructor
|
|
20
20
|
const [owner, initArgs] = args;
|
|
21
21
|
document_element_js_1.DocumentElement.call(this, owner);
|
|
22
22
|
if (!constants_js_1.CLASS_NAME_PATTERN.test(initArgs.name))
|
|
23
23
|
throw new TypeError(`Invalid resource name (${initArgs.name})`);
|
|
24
24
|
const _this = (0, ts_gems_1.asMutable)(this);
|
|
25
|
-
_this.kind = index_js_2.OpraSchema.
|
|
25
|
+
_this.kind = index_js_2.OpraSchema.RpcController.Kind;
|
|
26
26
|
_this.types = _this.node[constants_js_1.kDataTypeMap] = new data_type_map_js_1.DataTypeMap();
|
|
27
27
|
_this.operations = new index_js_1.ResponsiveMap();
|
|
28
28
|
_this.headers = [];
|
|
@@ -37,9 +37,9 @@ exports.MsgController = function (...args) {
|
|
|
37
37
|
};
|
|
38
38
|
/**
|
|
39
39
|
*
|
|
40
|
-
* @class
|
|
40
|
+
* @class RpcController
|
|
41
41
|
*/
|
|
42
|
-
class
|
|
42
|
+
class RpcControllerClass extends document_element_js_1.DocumentElement {
|
|
43
43
|
findHeader(paramName, location) {
|
|
44
44
|
const paramNameLower = paramName.toLowerCase();
|
|
45
45
|
let prm;
|
|
@@ -52,7 +52,7 @@ class MsgControllerClass extends document_element_js_1.DocumentElement {
|
|
|
52
52
|
if (prm.name instanceof RegExp && prm.name.test(paramName))
|
|
53
53
|
return prm;
|
|
54
54
|
}
|
|
55
|
-
if (this.node.parent && this.node.parent.element instanceof exports.
|
|
55
|
+
if (this.node.parent && this.node.parent.element instanceof exports.RpcController) {
|
|
56
56
|
return this.node.parent.element.findHeader(paramName, location);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -60,7 +60,7 @@ class MsgControllerClass extends document_element_js_1.DocumentElement {
|
|
|
60
60
|
*
|
|
61
61
|
*/
|
|
62
62
|
toString() {
|
|
63
|
-
return `[
|
|
63
|
+
return `[RpcController ${this.name}]`;
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
66
|
*
|
|
@@ -94,23 +94,23 @@ class MsgControllerClass extends document_element_js_1.DocumentElement {
|
|
|
94
94
|
*
|
|
95
95
|
*/
|
|
96
96
|
[inspect_util_js_1.nodeInspectCustom]() {
|
|
97
|
-
return `[${inspect_util_js_1.colorFgYellow}
|
|
97
|
+
return `[${inspect_util_js_1.colorFgYellow}RpcController${inspect_util_js_1.colorFgMagenta + this.name + inspect_util_js_1.colorReset}]`;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
exports.
|
|
101
|
-
Object.assign(exports.
|
|
102
|
-
exports.
|
|
103
|
-
exports.
|
|
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
104
|
return (target, propertyKey) => {
|
|
105
|
-
const sourceMetadata = (Reflect.getOwnMetadata(constants_js_1.
|
|
105
|
+
const sourceMetadata = (Reflect.getOwnMetadata(constants_js_1.RPC_CONTROLLER_METADATA, target.constructor) || {});
|
|
106
106
|
sourceMetadata.onInit = target[propertyKey];
|
|
107
|
-
Reflect.defineMetadata(constants_js_1.
|
|
107
|
+
Reflect.defineMetadata(constants_js_1.RPC_CONTROLLER_METADATA, target.constructor, sourceMetadata);
|
|
108
108
|
};
|
|
109
109
|
};
|
|
110
|
-
exports.
|
|
110
|
+
exports.RpcController.OnShutdown = function () {
|
|
111
111
|
return (target, propertyKey) => {
|
|
112
|
-
const sourceMetadata = (Reflect.getOwnMetadata(constants_js_1.
|
|
112
|
+
const sourceMetadata = (Reflect.getOwnMetadata(constants_js_1.RPC_CONTROLLER_METADATA, target.constructor) || {});
|
|
113
113
|
sourceMetadata.onShutdown = target[propertyKey];
|
|
114
|
-
Reflect.defineMetadata(constants_js_1.
|
|
114
|
+
Reflect.defineMetadata(constants_js_1.RPC_CONTROLLER_METADATA, target.constructor, sourceMetadata);
|
|
115
115
|
};
|
|
116
116
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.RpcHeader = void 0;
|
|
4
4
|
const ts_gems_1 = require("ts-gems");
|
|
5
5
|
const index_js_1 = require("../../helpers/index.js");
|
|
6
6
|
const value_js_1 = require("../common/value.js");
|
|
7
7
|
const parse_regexp_util_js_1 = require("../utils/parse-regexp.util.js");
|
|
8
|
-
exports.
|
|
8
|
+
exports.RpcHeader = function (owner, initArgs) {
|
|
9
9
|
if (!this)
|
|
10
10
|
throw new TypeError('"this" should be passed to call class constructor');
|
|
11
11
|
value_js_1.Value.call(this, owner, initArgs);
|
|
@@ -25,9 +25,9 @@ exports.MsgHeader = function (owner, initArgs) {
|
|
|
25
25
|
_this.required = initArgs.required;
|
|
26
26
|
};
|
|
27
27
|
/**
|
|
28
|
-
* @class
|
|
28
|
+
* @class RpcHeader
|
|
29
29
|
*/
|
|
30
|
-
class
|
|
30
|
+
class RpcHeaderClass extends value_js_1.Value {
|
|
31
31
|
toJSON() {
|
|
32
32
|
return (0, index_js_1.omitUndefined)({
|
|
33
33
|
...super.toJSON(),
|
|
@@ -37,4 +37,4 @@ class MsgHeaderClass extends value_js_1.Value {
|
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
exports.
|
|
40
|
+
exports.RpcHeader.prototype = RpcHeaderClass.prototype;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.RpcOperationResponse = void 0;
|
|
4
4
|
const index_js_1 = require("../../helpers/index.js");
|
|
5
5
|
const document_element_js_1 = require("../common/document-element.js");
|
|
6
6
|
const data_type_js_1 = require("../data-type/data-type.js");
|
|
7
7
|
/**
|
|
8
|
-
* @class
|
|
8
|
+
* @class RpcOperationResponse
|
|
9
9
|
*/
|
|
10
|
-
class
|
|
10
|
+
class RpcOperationResponse extends document_element_js_1.DocumentElement {
|
|
11
11
|
constructor(owner, initArgs) {
|
|
12
12
|
super(owner);
|
|
13
13
|
this.headers = [];
|
|
@@ -55,4 +55,4 @@ class MsgOperationResponse extends document_element_js_1.DocumentElement {
|
|
|
55
55
|
return out;
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
exports.
|
|
58
|
+
exports.RpcOperationResponse = RpcOperationResponse;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.RpcOperation = void 0;
|
|
4
4
|
const ts_gems_1 = require("ts-gems");
|
|
5
5
|
const index_js_1 = require("../../helpers/index.js");
|
|
6
6
|
const index_js_2 = require("../../schema/index.js");
|
|
@@ -8,16 +8,16 @@ const data_type_map_js_1 = require("../common/data-type-map.js");
|
|
|
8
8
|
const document_element_js_1 = require("../common/document-element.js");
|
|
9
9
|
const constants_js_1 = require("../constants.js");
|
|
10
10
|
const data_type_js_1 = require("../data-type/data-type.js");
|
|
11
|
-
const
|
|
11
|
+
const rpc_operation_decorator_js_1 = require("../decorators/rpc-operation.decorator.js");
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* RpcOperation
|
|
14
14
|
*/
|
|
15
|
-
exports.
|
|
15
|
+
exports.RpcOperation = function (...args) {
|
|
16
16
|
// Decorator
|
|
17
17
|
if (!this) {
|
|
18
18
|
const [payloadType, options] = args;
|
|
19
19
|
const decoratorChain = [];
|
|
20
|
-
return exports.
|
|
20
|
+
return exports.RpcOperation[constants_js_1.DECORATOR].call(undefined, decoratorChain, payloadType, options);
|
|
21
21
|
}
|
|
22
22
|
// Constructor
|
|
23
23
|
const [resource, initArgs] = args;
|
|
@@ -42,9 +42,9 @@ exports.MsgOperation = function (...args) {
|
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
44
|
/**
|
|
45
|
-
* @class
|
|
45
|
+
* @class RpcOperation
|
|
46
46
|
*/
|
|
47
|
-
class
|
|
47
|
+
class RpcOperationClass extends document_element_js_1.DocumentElement {
|
|
48
48
|
findHeader(paramName) {
|
|
49
49
|
const paramNameLower = paramName.toLowerCase();
|
|
50
50
|
let prm;
|
|
@@ -60,7 +60,7 @@ class MsgOperationClass extends document_element_js_1.DocumentElement {
|
|
|
60
60
|
}
|
|
61
61
|
toJSON() {
|
|
62
62
|
const out = (0, index_js_1.omitUndefined)({
|
|
63
|
-
kind: index_js_2.OpraSchema.
|
|
63
|
+
kind: index_js_2.OpraSchema.RpcOperation.Kind,
|
|
64
64
|
description: this.description,
|
|
65
65
|
channel: this.channel,
|
|
66
66
|
payloadType: this.payloadType.name ? this.payloadType.name : this.payloadType.toJSON(),
|
|
@@ -76,5 +76,5 @@ class MsgOperationClass extends document_element_js_1.DocumentElement {
|
|
|
76
76
|
return out;
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
-
exports.
|
|
80
|
-
exports.
|
|
79
|
+
exports.RpcOperation.prototype = RpcOperationClass.prototype;
|
|
80
|
+
exports.RpcOperation[constants_js_1.DECORATOR] = rpc_operation_decorator_js_1.RpcOperationDecoratorFactory;
|
|
@@ -19,9 +19,9 @@ tslib_1.__exportStar(require("./http/http-operation-response.interface.js"), exp
|
|
|
19
19
|
tslib_1.__exportStar(require("./http/http-parameter.interface.js"), exports);
|
|
20
20
|
tslib_1.__exportStar(require("./http/http-request-body.interface.js"), exports);
|
|
21
21
|
tslib_1.__exportStar(require("./http/http-status-range.interface.js"), exports);
|
|
22
|
-
tslib_1.__exportStar(require("./
|
|
23
|
-
tslib_1.__exportStar(require("./
|
|
24
|
-
tslib_1.__exportStar(require("./
|
|
22
|
+
tslib_1.__exportStar(require("./rpc/rpc-controller.interface.js"), exports);
|
|
23
|
+
tslib_1.__exportStar(require("./rpc/rpc-header.interface.js"), exports);
|
|
24
|
+
tslib_1.__exportStar(require("./rpc/rpc-operation.interface.js"), exports);
|
|
25
25
|
tslib_1.__exportStar(require("./type-guards.js"), exports);
|
|
26
26
|
tslib_1.__exportStar(require("./types.js"), exports);
|
|
27
27
|
tslib_1.__exportStar(require("./value.interface.js"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RpcController = void 0;
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @namespace RpcController
|
|
7
|
+
*/
|
|
8
|
+
var RpcController;
|
|
9
|
+
(function (RpcController) {
|
|
10
|
+
RpcController.Kind = 'RpcController';
|
|
11
|
+
})(RpcController || (exports.RpcController = RpcController = {}));
|