@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.
Files changed (64) hide show
  1. package/browser/index.cjs +5 -5
  2. package/browser/index.mjs +5 -5
  3. package/cjs/document/api-document.js +4 -4
  4. package/cjs/document/constants.js +2 -2
  5. package/cjs/document/decorators/{msg-controller.decorator.js → rpc-controller.decorator.js} +13 -8
  6. package/cjs/document/decorators/{msg-operation.decorator.js → rpc-operation.decorator.js} +6 -6
  7. package/cjs/document/factory/api-document.factory.js +3 -3
  8. package/cjs/document/factory/{msg-api.factory.js → rpc-api.factory.js} +28 -28
  9. package/cjs/document/http/http-operation.js +6 -0
  10. package/cjs/document/index.js +8 -6
  11. package/cjs/document/{msg/msg-api.js → rpc/rpc-api.js} +5 -5
  12. package/cjs/document/{msg/msg-controller.js → rpc/rpc-controller.js} +20 -20
  13. package/cjs/document/{msg/msg-header.js → rpc/rpc-header.js} +5 -5
  14. package/cjs/document/{msg/msg-operation-response.js → rpc/rpc-operation-response.js} +4 -4
  15. package/cjs/document/{msg/msg-operation.js → rpc/rpc-operation.js} +10 -10
  16. package/cjs/schema/opra-schema.js +3 -3
  17. package/cjs/schema/rpc/rpc-controller.interface.js +11 -0
  18. package/cjs/schema/rpc/rpc-operation.interface.js +7 -0
  19. package/esm/document/api-document.js +4 -4
  20. package/esm/document/constants.js +1 -1
  21. package/esm/document/decorators/{msg-controller.decorator.js → rpc-controller.decorator.js} +13 -8
  22. package/esm/document/decorators/{msg-operation.decorator.js → rpc-operation.decorator.js} +6 -6
  23. package/esm/document/factory/api-document.factory.js +3 -3
  24. package/esm/document/factory/{msg-api.factory.js → rpc-api.factory.js} +27 -27
  25. package/esm/document/http/http-operation.js +6 -0
  26. package/esm/document/index.js +8 -6
  27. package/esm/document/{msg/msg-api.js → rpc/rpc-api.js} +3 -3
  28. package/esm/document/{msg/msg-controller.js → rpc/rpc-controller.js} +20 -20
  29. package/esm/document/{msg/msg-header.js → rpc/rpc-header.js} +4 -4
  30. package/esm/document/{msg/msg-operation-response.js → rpc/rpc-operation-response.js} +2 -2
  31. package/esm/document/{msg/msg-operation.js → rpc/rpc-operation.js} +9 -9
  32. package/esm/schema/opra-schema.js +3 -3
  33. package/esm/schema/rpc/rpc-controller.interface.js +8 -0
  34. package/esm/schema/rpc/rpc-operation.interface.js +4 -0
  35. package/package.json +1 -1
  36. package/types/document/api-document.d.ts +3 -3
  37. package/types/document/constants.d.ts +1 -1
  38. package/types/document/decorators/rpc-controller.decorator.d.ts +20 -0
  39. package/types/document/decorators/rpc-operation.decorator.d.ts +32 -0
  40. package/types/document/factory/api-document.factory.d.ts +2 -2
  41. package/types/document/factory/rpc-api.factory.d.ts +40 -0
  42. package/types/document/index.d.ts +11 -8
  43. package/types/document/rpc/rpc-api.d.ts +27 -0
  44. package/types/document/rpc/rpc-controller.d.ts +89 -0
  45. package/types/document/{msg/msg-header.d.ts → rpc/rpc-header.d.ts} +15 -15
  46. package/types/document/{msg/msg-operation-response.d.ts → rpc/rpc-operation-response.d.ts} +13 -13
  47. package/types/document/{msg/msg-operation.d.ts → rpc/rpc-operation.d.ts} +27 -27
  48. package/types/schema/api-document.interface.d.ts +9 -11
  49. package/types/schema/opra-schema.d.ts +3 -3
  50. package/types/schema/rpc/rpc-controller.interface.d.ts +22 -0
  51. package/types/schema/{msg/msg-header.interface.d.ts → rpc/rpc-header.interface.d.ts} +2 -2
  52. package/types/schema/{msg/msg-operation.interface.d.ts → rpc/rpc-operation.interface.d.ts} +11 -11
  53. package/cjs/schema/msg/msg-controller.interface.js +0 -11
  54. package/cjs/schema/msg/msg-operation.interface.js +0 -7
  55. package/esm/schema/msg/msg-controller.interface.js +0 -8
  56. package/esm/schema/msg/msg-operation.interface.js +0 -4
  57. package/types/document/decorators/msg-controller.decorator.d.ts +0 -11
  58. package/types/document/decorators/msg-operation.decorator.d.ts +0 -29
  59. package/types/document/factory/msg-api.factory.d.ts +0 -40
  60. package/types/document/msg/msg-api.d.ts +0 -27
  61. package/types/document/msg/msg-controller.d.ts +0 -89
  62. package/types/schema/msg/msg-controller.interface.d.ts +0 -22
  63. /package/cjs/schema/{msg/msg-header.interface.js → rpc/rpc-header.interface.js} +0 -0
  64. /package/esm/schema/{msg/msg-header.interface.js → rpc/rpc-header.interface.js} +0 -0
@@ -7,7 +7,7 @@ import { DocumentElement } from './common/document-element.js';
7
7
  import { BUILTIN, kDataTypeMap, kTypeNSMap, NAMESPACE_PATTERN } from './constants.js';
8
8
  import { DataType } from './data-type/data-type.js';
9
9
  import { HttpApi } from './http/http-api.js';
10
- import { MsgApi } from './msg/msg-api.js';
10
+ import { RpcApi } from './rpc/rpc-api.js';
11
11
  /**
12
12
  *
13
13
  * @class ApiDocument
@@ -49,9 +49,9 @@ export class ApiDocument extends DocumentElement {
49
49
  }
50
50
  return this.api;
51
51
  }
52
- get msgApi() {
53
- if (!(this.api && this.api instanceof MsgApi)) {
54
- throw new TypeError('The document do not contains MsgApi instance');
52
+ get rpcApi() {
53
+ if (!(this.api && this.api instanceof RpcApi)) {
54
+ throw new TypeError('The document do not contains RpcApi instance');
55
55
  }
56
56
  return this.api;
57
57
  }
@@ -1,6 +1,6 @@
1
1
  export const DATATYPE_METADATA = Symbol.for('opra.type.metadata');
2
2
  export const HTTP_CONTROLLER_METADATA = Symbol('opra.http-controller.metadata');
3
- export const MSG_CONTROLLER_METADATA = Symbol('opra.msg-controller.metadata');
3
+ export const RPC_CONTROLLER_METADATA = Symbol('opra.rpc-controller.metadata');
4
4
  export const DECODER = Symbol.for('opra.type.decoder');
5
5
  export const ENCODER = Symbol('opra.type.encoder');
6
6
  export const DECORATOR = Symbol.for('DECORATOR');
@@ -1,9 +1,10 @@
1
1
  import omit from 'lodash.omit';
2
2
  import merge from 'putil-merge';
3
3
  import { OpraSchema } from '../../schema/index.js';
4
- import { MSG_CONTROLLER_METADATA } from '../constants.js';
4
+ import { RPC_CONTROLLER_METADATA } from '../constants.js';
5
5
  const CLASS_NAME_PATTERN = /^(.*)(Controller)$/;
6
- export function MsgControllerDecoratorFactory(options) {
6
+ const augmentationRegistry = [];
7
+ export function RpcControllerDecoratorFactory(options) {
7
8
  const decoratorChain = [];
8
9
  /**
9
10
  *
@@ -13,22 +14,22 @@ export function MsgControllerDecoratorFactory(options) {
13
14
  if (!name)
14
15
  name = CLASS_NAME_PATTERN.exec(target.name)?.[1] || target.name;
15
16
  const metadata = {};
16
- const baseMetadata = Reflect.getOwnMetadata(MSG_CONTROLLER_METADATA, Object.getPrototypeOf(target));
17
+ const baseMetadata = Reflect.getOwnMetadata(RPC_CONTROLLER_METADATA, Object.getPrototypeOf(target));
17
18
  if (baseMetadata)
18
19
  merge(metadata, baseMetadata, { deep: true });
19
- const oldMetadata = Reflect.getOwnMetadata(MSG_CONTROLLER_METADATA, target);
20
+ const oldMetadata = Reflect.getOwnMetadata(RPC_CONTROLLER_METADATA, target);
20
21
  if (oldMetadata)
21
22
  merge(metadata, oldMetadata, { deep: true });
22
23
  merge(metadata, {
23
- kind: OpraSchema.MsgController.Kind,
24
+ kind: OpraSchema.RpcController.Kind,
24
25
  name,
25
26
  path: name,
26
27
  ...omit(options, ['kind', 'name', 'instance', 'endpoints', 'key']),
27
28
  }, { deep: true });
28
- Reflect.defineMetadata(MSG_CONTROLLER_METADATA, metadata, target);
29
+ Reflect.defineMetadata(RPC_CONTROLLER_METADATA, metadata, target);
29
30
  for (const fn of decoratorChain)
30
- fn(metadata);
31
- Reflect.defineMetadata(MSG_CONTROLLER_METADATA, metadata, target);
31
+ fn(metadata, target);
32
+ Reflect.defineMetadata(RPC_CONTROLLER_METADATA, metadata, target);
32
33
  };
33
34
  /**
34
35
  *
@@ -56,5 +57,9 @@ export function MsgControllerDecoratorFactory(options) {
56
57
  });
57
58
  return decorator;
58
59
  };
60
+ augmentationRegistry.forEach(fn => fn(decorator, decoratorChain, options));
59
61
  return decorator;
60
62
  }
63
+ RpcControllerDecoratorFactory.augment = function (fn) {
64
+ augmentationRegistry.push(fn);
65
+ };
@@ -1,8 +1,8 @@
1
1
  import omit from 'lodash.omit';
2
2
  import { OpraSchema } from '../../schema/index.js';
3
- import { MSG_CONTROLLER_METADATA } from '../constants.js';
3
+ import { RPC_CONTROLLER_METADATA } from '../constants.js';
4
4
  const augmentationRegistry = [];
5
- export function MsgOperationDecoratorFactory(decoratorChain, payloadType, options) {
5
+ export function RpcOperationDecoratorFactory(decoratorChain, payloadType, options) {
6
6
  let inResponse = false;
7
7
  /**
8
8
  *
@@ -11,18 +11,18 @@ export function MsgOperationDecoratorFactory(decoratorChain, payloadType, option
11
11
  if (typeof propertyKey !== 'string')
12
12
  throw new TypeError(`Symbol properties can not be decorated`);
13
13
  const operationMetadata = {
14
- kind: OpraSchema.MsgOperation.Kind,
14
+ kind: OpraSchema.RpcOperation.Kind,
15
15
  channel: propertyKey,
16
16
  ...omit(options, ['kind']),
17
17
  payloadType,
18
18
  };
19
- const controllerMetadata = (Reflect.getOwnMetadata(MSG_CONTROLLER_METADATA, target.constructor) ||
19
+ const controllerMetadata = (Reflect.getOwnMetadata(RPC_CONTROLLER_METADATA, target.constructor) ||
20
20
  {});
21
21
  controllerMetadata.operations = controllerMetadata.operations || {};
22
22
  controllerMetadata.operations[propertyKey] = operationMetadata;
23
23
  for (const fn of decoratorChain)
24
24
  fn(operationMetadata, target, propertyKey);
25
- Reflect.defineMetadata(MSG_CONTROLLER_METADATA, controllerMetadata, target.constructor);
25
+ Reflect.defineMetadata(RPC_CONTROLLER_METADATA, controllerMetadata, target.constructor);
26
26
  });
27
27
  /**
28
28
  *
@@ -71,6 +71,6 @@ export function MsgOperationDecoratorFactory(decoratorChain, payloadType, option
71
71
  augmentationRegistry.forEach(fn => fn(decorator, decoratorChain, payloadType, options));
72
72
  return decorator;
73
73
  }
74
- MsgOperationDecoratorFactory.augment = function (fn) {
74
+ RpcOperationDecoratorFactory.augment = function (fn) {
75
75
  augmentationRegistry.push(fn);
76
76
  };
@@ -8,7 +8,7 @@ import { Base64Type, DateStringType, DateTimeStringType, DateTimeType, DateType,
8
8
  import { AnyType, BigintType, BooleanType, IntegerType, NullType, NumberType, ObjectType, StringType, } from '../data-type/primitive-types/index.js';
9
9
  import { DataTypeFactory } from './data-type.factory.js';
10
10
  import { HttpApiFactory } from './http-api.factory.js';
11
- import { MsgApiFactory } from './msg-api.factory.js';
11
+ import { RpcApiFactory } from './rpc-api.factory.js';
12
12
  const OPRA_SPEC_URL = 'https://oprajs.com/spec/v' + OpraSchema.SpecVersion;
13
13
  /**
14
14
  * @class ApiDocumentFactory
@@ -114,8 +114,8 @@ export class ApiDocumentFactory {
114
114
  if (api)
115
115
  document.api = api;
116
116
  }
117
- else if (init.api && init.api.transport === 'msg') {
118
- const api = await MsgApiFactory.createApi(context, { ...init.api, owner: document });
117
+ else if (init.api && init.api.transport === 'rpc') {
118
+ const api = await RpcApiFactory.createApi(context, { ...init.api, owner: document });
119
119
  if (api)
120
120
  document.api = api;
121
121
  }
@@ -1,22 +1,22 @@
1
1
  import { isConstructor, resolveThunk } from '../../helpers/index.js';
2
- import { MSG_CONTROLLER_METADATA } from '../constants.js';
3
- import { MsgApi } from '../msg/msg-api.js';
4
- import { MsgController } from '../msg/msg-controller.js';
5
- import { MsgHeader } from '../msg/msg-header.js';
6
- import { MsgOperation } from '../msg/msg-operation.js';
7
- import { MsgOperationResponse } from '../msg/msg-operation-response.js';
2
+ import { RPC_CONTROLLER_METADATA } from '../constants.js';
3
+ import { RpcApi } from '../rpc/rpc-api.js';
4
+ import { RpcController } from '../rpc/rpc-controller.js';
5
+ import { RpcHeader } from '../rpc/rpc-header.js';
6
+ import { RpcOperation } from '../rpc/rpc-operation.js';
7
+ import { RpcOperationResponse } from '../rpc/rpc-operation-response.js';
8
8
  import { DataTypeFactory } from './data-type.factory.js';
9
9
  /**
10
- * @class MsgApiFactory
10
+ * @class RpcApiFactory
11
11
  */
12
- export class MsgApiFactory {
12
+ export class RpcApiFactory {
13
13
  /**
14
- * Generates MsgApi
14
+ * Generates RpcApi
15
15
  * @param context
16
16
  * @param init
17
17
  */
18
18
  static async createApi(context, init) {
19
- const api = new MsgApi(init);
19
+ const api = new RpcApi(init);
20
20
  if (init.controllers) {
21
21
  await context.enterAsync('.controllers', async () => {
22
22
  if (Array.isArray(init.controllers)) {
@@ -47,15 +47,15 @@ export class MsgApiFactory {
47
47
  let instance;
48
48
  // If thunk is a class
49
49
  if (typeof thunk === 'function') {
50
- metadata = Reflect.getMetadata(MSG_CONTROLLER_METADATA, thunk);
50
+ metadata = Reflect.getMetadata(RPC_CONTROLLER_METADATA, thunk);
51
51
  if (!metadata)
52
- return context.addError(`Class "${thunk.name}" doesn't have a valid MsgController metadata`);
52
+ return context.addError(`Class "${thunk.name}" doesn't have a valid RpcController metadata`);
53
53
  ctor = thunk;
54
54
  }
55
55
  else {
56
- // If thunk is an instance of a class decorated with MsgController()
56
+ // If thunk is an instance of a class decorated with RpcController()
57
57
  ctor = Object.getPrototypeOf(thunk).constructor;
58
- metadata = Reflect.getMetadata(MSG_CONTROLLER_METADATA, ctor);
58
+ metadata = Reflect.getMetadata(RPC_CONTROLLER_METADATA, ctor);
59
59
  if (metadata)
60
60
  instance = thunk;
61
61
  else {
@@ -68,11 +68,11 @@ export class MsgApiFactory {
68
68
  }
69
69
  }
70
70
  if (!metadata)
71
- return context.addError(`Class "${ctor.name}" is not decorated with MsgController()`);
71
+ return context.addError(`Class "${ctor.name}" is not decorated with RpcController()`);
72
72
  name = name || metadata.name;
73
73
  if (!name)
74
74
  throw new TypeError(`Controller name required`);
75
- const controller = new MsgController(parent, {
75
+ const controller = new RpcController(parent, {
76
76
  ...metadata,
77
77
  name,
78
78
  instance,
@@ -98,7 +98,7 @@ export class MsgApiFactory {
98
98
  if (!prmArgs.type)
99
99
  prmArgs.type = controller.node.getDataType('any');
100
100
  });
101
- const prm = new MsgHeader(controller, prmArgs);
101
+ const prm = new RpcHeader(controller, prmArgs);
102
102
  controller.headers.push(prm);
103
103
  });
104
104
  }
@@ -108,14 +108,14 @@ export class MsgApiFactory {
108
108
  await context.enterAsync('.operations', async () => {
109
109
  for (const [operationName, operationMeta] of Object.entries(metadata.operations)) {
110
110
  await context.enterAsync(`[${operationName}]`, async () => {
111
- const operation = new MsgOperation(controller, {
111
+ const operation = new RpcOperation(controller, {
112
112
  ...operationMeta,
113
113
  name: operationName,
114
114
  types: undefined,
115
115
  payloadType: undefined,
116
116
  keyType: undefined,
117
117
  });
118
- await this._initMsgOperation(context, operation, operationMeta);
118
+ await this._initRpcOperation(context, operation, operationMeta);
119
119
  controller.operations.set(operation.name, operation);
120
120
  });
121
121
  }
@@ -124,13 +124,13 @@ export class MsgApiFactory {
124
124
  return controller;
125
125
  }
126
126
  /**
127
- * Initializes MsgOperation
127
+ * Initializes RpcOperation
128
128
  * @param context
129
129
  * @param operation
130
130
  * @param metadata
131
131
  * @protected
132
132
  */
133
- static async _initMsgOperation(context, operation, metadata) {
133
+ static async _initRpcOperation(context, operation, metadata) {
134
134
  if (metadata.types) {
135
135
  await context.enterAsync('.types', async () => {
136
136
  await DataTypeFactory.addDataTypes(context, operation, metadata.types);
@@ -149,7 +149,7 @@ export class MsgApiFactory {
149
149
  await context.enterAsync('.type', async () => {
150
150
  prmArgs.type = await DataTypeFactory.resolveDataType(context, operation, v.type);
151
151
  });
152
- const prm = new MsgHeader(operation, prmArgs);
152
+ const prm = new RpcHeader(operation, prmArgs);
153
153
  operation.headers.push(prm);
154
154
  });
155
155
  }
@@ -157,24 +157,24 @@ export class MsgApiFactory {
157
157
  }
158
158
  if (metadata.response) {
159
159
  await context.enterAsync('.response', async () => {
160
- const response = new MsgOperationResponse(operation, {
160
+ const response = new RpcOperationResponse(operation, {
161
161
  ...metadata.response,
162
162
  payloadType: undefined,
163
163
  keyType: undefined,
164
164
  });
165
- await this._initMsgOperationResponse(context, response, metadata.response);
165
+ await this._initRpcOperationResponse(context, response, metadata.response);
166
166
  operation.response = response;
167
167
  });
168
168
  }
169
169
  }
170
170
  /**
171
- * Initializes MsgOperationResponse
171
+ * Initializes RpcOperationResponse
172
172
  * @param context
173
173
  * @param response
174
174
  * @param metadata
175
175
  * @protected
176
176
  */
177
- static async _initMsgOperationResponse(context, response, metadata) {
177
+ static async _initRpcOperationResponse(context, response, metadata) {
178
178
  response.payloadType = await DataTypeFactory.resolveDataType(context, response, metadata.payloadType);
179
179
  if (metadata.keyType) {
180
180
  response.keyType = await DataTypeFactory.resolveDataType(context, response, metadata.keyType);
@@ -188,7 +188,7 @@ export class MsgApiFactory {
188
188
  await context.enterAsync('.type', async () => {
189
189
  prmArgs.type = await DataTypeFactory.resolveDataType(context, response, v.type);
190
190
  });
191
- const prm = new MsgHeader(response, prmArgs);
191
+ const prm = new RpcHeader(response, prmArgs);
192
192
  response.headers.push(prm);
193
193
  });
194
194
  }
@@ -74,6 +74,12 @@ class HttpOperationClass extends DocumentElement {
74
74
  composition: this.composition,
75
75
  requestBody: this.requestBody?.toJSON(),
76
76
  });
77
+ if (this.types.size) {
78
+ out.types = {};
79
+ for (const v of this.types.values()) {
80
+ out.types[v.name] = v.toJSON();
81
+ }
82
+ }
77
83
  if (this.parameters.length) {
78
84
  out.parameters = [];
79
85
  for (const prm of this.parameters) {
@@ -1,5 +1,6 @@
1
1
  import 'reflect-metadata';
2
- import * as MsgOperationDecorator_ from './decorators/msg-operation.decorator.js';
2
+ import * as RpcControllerDecorator_ from './decorators/rpc-controller.decorator.js';
3
+ import * as RpcOperationDecorator_ from './decorators/rpc-operation.decorator.js';
3
4
  import * as DataTypeFactory_ from './factory/data-type.factory.js';
4
5
  import * as HttpApiFactory_ from './factory/http-api.factory.js';
5
6
  export * from './api-document.js';
@@ -34,13 +35,14 @@ export * from './http/http-operation-response.js';
34
35
  export * from './http/http-parameter.js';
35
36
  export * from './http/http-request-body.js';
36
37
  export * from './http/http-status-range.js';
37
- export * from './msg/msg-api.js';
38
- export * from './msg/msg-controller.js';
39
- export * from './msg/msg-header.js';
40
- export * from './msg/msg-operation.js';
38
+ export * from './rpc/rpc-api.js';
39
+ export * from './rpc/rpc-controller.js';
40
+ export * from './rpc/rpc-header.js';
41
+ export * from './rpc/rpc-operation.js';
41
42
  export var classes;
42
43
  (function (classes) {
43
44
  classes.HttpApiFactory = HttpApiFactory_.HttpApiFactory;
44
45
  classes.DataTypeFactory = DataTypeFactory_.DataTypeFactory;
45
- classes.MsgOperationDecoratorFactory = MsgOperationDecorator_.MsgOperationDecoratorFactory;
46
+ classes.RpcOperationDecoratorFactory = RpcOperationDecorator_.RpcOperationDecoratorFactory;
47
+ classes.RpcControllerDecoratorFactory = RpcControllerDecorator_.RpcControllerDecoratorFactory;
46
48
  })(classes || (classes = {}));
@@ -1,14 +1,14 @@
1
1
  import { ResponsiveMap } from '../../helpers/index.js';
2
2
  import { ApiBase } from '../common/api-base.js';
3
3
  /**
4
- * @class MsgApi
4
+ * @class RpcApi
5
5
  */
6
- export class MsgApi extends ApiBase {
6
+ export class RpcApi extends ApiBase {
7
7
  constructor(init) {
8
8
  super(init);
9
9
  // noinspection JSUnusedGlobalSymbols
10
10
  this._controllerReverseMap = new WeakMap();
11
- this.transport = 'msg';
11
+ this.transport = 'rpc';
12
12
  this.controllers = new ResponsiveMap();
13
13
  this.platform = init.platform;
14
14
  }
@@ -3,23 +3,23 @@ import { omitUndefined, ResponsiveMap } from '../../helpers/index.js';
3
3
  import { OpraSchema } from '../../schema/index.js';
4
4
  import { DataTypeMap } from '../common/data-type-map.js';
5
5
  import { DocumentElement } from '../common/document-element.js';
6
- import { CLASS_NAME_PATTERN, DECORATOR, kDataTypeMap, MSG_CONTROLLER_METADATA } from '../constants.js';
7
- import { MsgControllerDecoratorFactory } from '../decorators/msg-controller.decorator.js';
6
+ import { CLASS_NAME_PATTERN, DECORATOR, kDataTypeMap, RPC_CONTROLLER_METADATA } from '../constants.js';
7
+ import { RpcControllerDecoratorFactory } from '../decorators/rpc-controller.decorator.js';
8
8
  import { colorFgMagenta, colorFgYellow, colorReset, nodeInspectCustom } from '../utils/inspect.util.js';
9
9
  /**
10
- * MsgController
10
+ * RpcController
11
11
  */
12
- export const MsgController = function (...args) {
12
+ export const RpcController = function (...args) {
13
13
  // ClassDecorator
14
14
  if (!this)
15
- return MsgController[DECORATOR].apply(undefined, args);
15
+ return RpcController[DECORATOR].apply(undefined, args);
16
16
  // Constructor
17
17
  const [owner, initArgs] = args;
18
18
  DocumentElement.call(this, owner);
19
19
  if (!CLASS_NAME_PATTERN.test(initArgs.name))
20
20
  throw new TypeError(`Invalid resource name (${initArgs.name})`);
21
21
  const _this = asMutable(this);
22
- _this.kind = OpraSchema.MsgController.Kind;
22
+ _this.kind = OpraSchema.RpcController.Kind;
23
23
  _this.types = _this.node[kDataTypeMap] = new DataTypeMap();
24
24
  _this.operations = new ResponsiveMap();
25
25
  _this.headers = [];
@@ -34,9 +34,9 @@ export const MsgController = function (...args) {
34
34
  };
35
35
  /**
36
36
  *
37
- * @class MsgController
37
+ * @class RpcController
38
38
  */
39
- class MsgControllerClass extends DocumentElement {
39
+ class RpcControllerClass extends DocumentElement {
40
40
  findHeader(paramName, location) {
41
41
  const paramNameLower = paramName.toLowerCase();
42
42
  let prm;
@@ -49,7 +49,7 @@ class MsgControllerClass extends DocumentElement {
49
49
  if (prm.name instanceof RegExp && prm.name.test(paramName))
50
50
  return prm;
51
51
  }
52
- if (this.node.parent && this.node.parent.element instanceof MsgController) {
52
+ if (this.node.parent && this.node.parent.element instanceof RpcController) {
53
53
  return this.node.parent.element.findHeader(paramName, location);
54
54
  }
55
55
  }
@@ -57,7 +57,7 @@ class MsgControllerClass extends DocumentElement {
57
57
  *
58
58
  */
59
59
  toString() {
60
- return `[MsgController ${this.name}]`;
60
+ return `[RpcController ${this.name}]`;
61
61
  }
62
62
  /**
63
63
  *
@@ -91,23 +91,23 @@ class MsgControllerClass extends DocumentElement {
91
91
  *
92
92
  */
93
93
  [nodeInspectCustom]() {
94
- return `[${colorFgYellow}MsgController${colorFgMagenta + this.name + colorReset}]`;
94
+ return `[${colorFgYellow}RpcController${colorFgMagenta + this.name + colorReset}]`;
95
95
  }
96
96
  }
97
- MsgController.prototype = MsgControllerClass.prototype;
98
- Object.assign(MsgController, MsgControllerDecoratorFactory);
99
- MsgController[DECORATOR] = MsgControllerDecoratorFactory;
100
- MsgController.OnInit = function () {
97
+ RpcController.prototype = RpcControllerClass.prototype;
98
+ Object.assign(RpcController, RpcControllerDecoratorFactory);
99
+ RpcController[DECORATOR] = RpcControllerDecoratorFactory;
100
+ RpcController.OnInit = function () {
101
101
  return (target, propertyKey) => {
102
- const sourceMetadata = (Reflect.getOwnMetadata(MSG_CONTROLLER_METADATA, target.constructor) || {});
102
+ const sourceMetadata = (Reflect.getOwnMetadata(RPC_CONTROLLER_METADATA, target.constructor) || {});
103
103
  sourceMetadata.onInit = target[propertyKey];
104
- Reflect.defineMetadata(MSG_CONTROLLER_METADATA, target.constructor, sourceMetadata);
104
+ Reflect.defineMetadata(RPC_CONTROLLER_METADATA, target.constructor, sourceMetadata);
105
105
  };
106
106
  };
107
- MsgController.OnShutdown = function () {
107
+ RpcController.OnShutdown = function () {
108
108
  return (target, propertyKey) => {
109
- const sourceMetadata = (Reflect.getOwnMetadata(MSG_CONTROLLER_METADATA, target.constructor) || {});
109
+ const sourceMetadata = (Reflect.getOwnMetadata(RPC_CONTROLLER_METADATA, target.constructor) || {});
110
110
  sourceMetadata.onShutdown = target[propertyKey];
111
- Reflect.defineMetadata(MSG_CONTROLLER_METADATA, target.constructor, sourceMetadata);
111
+ Reflect.defineMetadata(RPC_CONTROLLER_METADATA, target.constructor, sourceMetadata);
112
112
  };
113
113
  };
@@ -2,7 +2,7 @@ import { asMutable } from 'ts-gems';
2
2
  import { omitUndefined } from '../../helpers/index.js';
3
3
  import { Value } from '../common/value.js';
4
4
  import { parseRegExp } from '../utils/parse-regexp.util.js';
5
- export const MsgHeader = function (owner, initArgs) {
5
+ export const RpcHeader = function (owner, initArgs) {
6
6
  if (!this)
7
7
  throw new TypeError('"this" should be passed to call class constructor');
8
8
  Value.call(this, owner, initArgs);
@@ -22,9 +22,9 @@ export const MsgHeader = function (owner, initArgs) {
22
22
  _this.required = initArgs.required;
23
23
  };
24
24
  /**
25
- * @class MsgHeader
25
+ * @class RpcHeader
26
26
  */
27
- class MsgHeaderClass extends Value {
27
+ class RpcHeaderClass extends Value {
28
28
  toJSON() {
29
29
  return omitUndefined({
30
30
  ...super.toJSON(),
@@ -34,4 +34,4 @@ class MsgHeaderClass extends Value {
34
34
  });
35
35
  }
36
36
  }
37
- MsgHeader.prototype = MsgHeaderClass.prototype;
37
+ RpcHeader.prototype = RpcHeaderClass.prototype;
@@ -2,9 +2,9 @@ import { omitUndefined } from '../../helpers/index.js';
2
2
  import { DocumentElement } from '../common/document-element.js';
3
3
  import { DataType } from '../data-type/data-type.js';
4
4
  /**
5
- * @class MsgOperationResponse
5
+ * @class RpcOperationResponse
6
6
  */
7
- export class MsgOperationResponse extends DocumentElement {
7
+ export class RpcOperationResponse extends DocumentElement {
8
8
  constructor(owner, initArgs) {
9
9
  super(owner);
10
10
  this.headers = [];
@@ -5,16 +5,16 @@ import { DataTypeMap } from '../common/data-type-map.js';
5
5
  import { DocumentElement } from '../common/document-element.js';
6
6
  import { CLASS_NAME_PATTERN, DECORATOR, kDataTypeMap } from '../constants.js';
7
7
  import { DataType } from '../data-type/data-type.js';
8
- import { MsgOperationDecoratorFactory } from '../decorators/msg-operation.decorator.js';
8
+ import { RpcOperationDecoratorFactory } from '../decorators/rpc-operation.decorator.js';
9
9
  /**
10
- * MsgOperation
10
+ * RpcOperation
11
11
  */
12
- export const MsgOperation = function (...args) {
12
+ export const RpcOperation = function (...args) {
13
13
  // Decorator
14
14
  if (!this) {
15
15
  const [payloadType, options] = args;
16
16
  const decoratorChain = [];
17
- return MsgOperation[DECORATOR].call(undefined, decoratorChain, payloadType, options);
17
+ return RpcOperation[DECORATOR].call(undefined, decoratorChain, payloadType, options);
18
18
  }
19
19
  // Constructor
20
20
  const [resource, initArgs] = args;
@@ -39,9 +39,9 @@ export const MsgOperation = function (...args) {
39
39
  }
40
40
  };
41
41
  /**
42
- * @class MsgOperation
42
+ * @class RpcOperation
43
43
  */
44
- class MsgOperationClass extends DocumentElement {
44
+ class RpcOperationClass extends DocumentElement {
45
45
  findHeader(paramName) {
46
46
  const paramNameLower = paramName.toLowerCase();
47
47
  let prm;
@@ -57,7 +57,7 @@ class MsgOperationClass extends DocumentElement {
57
57
  }
58
58
  toJSON() {
59
59
  const out = omitUndefined({
60
- kind: OpraSchema.MsgOperation.Kind,
60
+ kind: OpraSchema.RpcOperation.Kind,
61
61
  description: this.description,
62
62
  channel: this.channel,
63
63
  payloadType: this.payloadType.name ? this.payloadType.name : this.payloadType.toJSON(),
@@ -73,5 +73,5 @@ class MsgOperationClass extends DocumentElement {
73
73
  return out;
74
74
  }
75
75
  }
76
- MsgOperation.prototype = MsgOperationClass.prototype;
77
- MsgOperation[DECORATOR] = MsgOperationDecoratorFactory;
76
+ RpcOperation.prototype = RpcOperationClass.prototype;
77
+ RpcOperation[DECORATOR] = RpcOperationDecoratorFactory;
@@ -16,9 +16,9 @@ export * from './http/http-operation-response.interface.js';
16
16
  export * from './http/http-parameter.interface.js';
17
17
  export * from './http/http-request-body.interface.js';
18
18
  export * from './http/http-status-range.interface.js';
19
- export * from './msg/msg-controller.interface.js';
20
- export * from './msg/msg-header.interface.js';
21
- export * from './msg/msg-operation.interface.js';
19
+ export * from './rpc/rpc-controller.interface.js';
20
+ export * from './rpc/rpc-header.interface.js';
21
+ export * from './rpc/rpc-operation.interface.js';
22
22
  export * from './type-guards.js';
23
23
  export * from './types.js';
24
24
  export * from './value.interface.js';
@@ -0,0 +1,8 @@
1
+ /**
2
+ *
3
+ * @namespace RpcController
4
+ */
5
+ export var RpcController;
6
+ (function (RpcController) {
7
+ RpcController.Kind = 'RpcController';
8
+ })(RpcController || (RpcController = {}));
@@ -0,0 +1,4 @@
1
+ export var RpcOperation;
2
+ (function (RpcOperation) {
3
+ RpcOperation.Kind = 'RpcOperation';
4
+ })(RpcOperation || (RpcOperation = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/common",
3
- "version": "1.0.0-beta.3",
3
+ "version": "1.0.0-beta.5",
4
4
  "description": "Opra common package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -7,7 +7,7 @@ import { kTypeNSMap } from './constants.js';
7
7
  import { DataType } from './data-type/data-type.js';
8
8
  import type { EnumType } from './data-type/enum-type.js';
9
9
  import { HttpApi } from './http/http-api.js';
10
- import { MsgApi } from './msg/msg-api.js';
10
+ import { RpcApi } from './rpc/rpc-api.js';
11
11
  /**
12
12
  *
13
13
  * @class ApiDocument
@@ -19,7 +19,7 @@ export declare class ApiDocument extends DocumentElement {
19
19
  info: OpraSchema.DocumentInfo;
20
20
  references: ResponsiveMap<ApiDocument>;
21
21
  types: DataTypeMap;
22
- api?: HttpApi | MsgApi;
22
+ api?: HttpApi | RpcApi;
23
23
  constructor();
24
24
  /**
25
25
  * Returns NS of datatype. Returns undefined if not found
@@ -28,7 +28,7 @@ export declare class ApiDocument extends DocumentElement {
28
28
  getDataTypeNs(nameOrCtor: string | Type | Function | EnumType.EnumArray | EnumType.EnumObject | DataType): string | undefined;
29
29
  findDocument(id: string): ApiDocument | undefined;
30
30
  get httpApi(): HttpApi;
31
- get msgApi(): MsgApi;
31
+ get rpcApi(): RpcApi;
32
32
  toJSON(): OpraSchema.ApiDocument;
33
33
  /**
34
34
  * Export as Opra schema definition object
@@ -1,6 +1,6 @@
1
1
  export declare const DATATYPE_METADATA: unique symbol;
2
2
  export declare const HTTP_CONTROLLER_METADATA: unique symbol;
3
- export declare const MSG_CONTROLLER_METADATA: unique symbol;
3
+ export declare const RPC_CONTROLLER_METADATA: unique symbol;
4
4
  export declare const DECODER: unique symbol;
5
5
  export declare const ENCODER: unique symbol;
6
6
  export declare const DECORATOR: unique symbol;
@@ -0,0 +1,20 @@
1
+ import type { TypeThunkAsync } from 'ts-gems';
2
+ import type { RpcController } from '../rpc/rpc-controller';
3
+ import type { RpcHeader } from '../rpc/rpc-header';
4
+ export interface RpcControllerDecorator<T extends RpcControllerDecorator<any> = RpcControllerDecorator<any>> extends ClassDecorator {
5
+ Header(name: string | RegExp, optionsOrType?: RpcHeader.Options | string | TypeThunkAsync | false): T;
6
+ UseType(...type: TypeThunkAsync[]): T;
7
+ }
8
+ export interface RpcControllerDecoratorFactory {
9
+ <T extends RpcController.Options>(options?: T): RpcControllerDecorator;
10
+ }
11
+ /**
12
+ * @namespace RpcControllerDecoratorFactory
13
+ */
14
+ export declare namespace RpcControllerDecoratorFactory {
15
+ type AugmentationFunction = (decorator: RpcControllerDecorator, decoratorChain: Function[], options?: RpcController.Options) => void;
16
+ }
17
+ export declare function RpcControllerDecoratorFactory<O extends RpcController.Options>(options?: O): RpcControllerDecorator;
18
+ export declare namespace RpcControllerDecoratorFactory {
19
+ var augment: (fn: RpcControllerDecoratorFactory.AugmentationFunction) => void;
20
+ }