@opra/common 1.20.0 → 1.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,6 +17,6 @@ function WsParam(type) {
17
17
  paramMetadata = [];
18
18
  Reflect.defineMetadata(constants_js_1.WS_PARAM_METADATA, paramMetadata, target, propertyKey);
19
19
  }
20
- paramMetadata[parameterIndex] = type;
20
+ paramMetadata.push({ type, parameterIndex });
21
21
  };
22
22
  }
@@ -104,6 +104,7 @@ class WSApiFactory {
104
104
  type: undefined,
105
105
  keyType: undefined,
106
106
  arguments: undefined,
107
+ response: undefined,
107
108
  });
108
109
  await this._initWSOperation(context, operation, operationMeta);
109
110
  controller.operations.set(operationName, operation);
@@ -129,9 +130,19 @@ class WSApiFactory {
129
130
  if (metadata.arguments?.length) {
130
131
  await context.enterAsync('.arguments', async () => {
131
132
  operation.arguments = [];
132
- for (const x of metadata.arguments) {
133
- const t = await data_type_factory_js_1.DataTypeFactory.resolveDataType(context, operation, x);
134
- operation.arguments?.push(t);
133
+ let x;
134
+ for (x of metadata.arguments) {
135
+ const xx = {};
136
+ if (typeof x === 'object' && x.type && x.parameterIndex !== null) {
137
+ Object.assign(xx, x);
138
+ }
139
+ else
140
+ xx.type = x;
141
+ const t = await data_type_factory_js_1.DataTypeFactory.resolveDataType(context, operation, xx.type);
142
+ operation.arguments?.push({
143
+ type: t,
144
+ parameterIndex: xx.parameterIndex,
145
+ });
135
146
  }
136
147
  });
137
148
  }
@@ -27,6 +27,7 @@ exports.WSOperation = function (...args) {
27
27
  throw new TypeError(`Invalid operation name (${initArgs.name})`);
28
28
  const _this = (0, ts_gems_1.asMutable)(this);
29
29
  _this.types = _this.node[constants_js_1.kDataTypeMap] = new data_type_map_js_1.DataTypeMap();
30
+ // noinspection JSConstantReassignment
30
31
  _this.name = initArgs.name;
31
32
  _this.description = initArgs.description;
32
33
  if (initArgs.event)
@@ -39,8 +40,15 @@ exports.WSOperation = function (...args) {
39
40
  else
40
41
  _this.event = this.name;
41
42
  if (initArgs?.arguments) {
42
- _this.arguments = initArgs.arguments.map(arg => arg instanceof data_type_js_1.DataType ? arg : _this.owner.node.getDataType(arg));
43
+ _this.arguments = initArgs.arguments.map(arg => {
44
+ const type = arg.type instanceof data_type_js_1.DataType
45
+ ? arg.type
46
+ : _this.owner.node.getDataType(arg.type);
47
+ return { type, parameterIndex: arg.parameterIndex };
48
+ });
43
49
  }
50
+ else
51
+ _this.arguments = [];
44
52
  if (initArgs?.response)
45
53
  _this.response =
46
54
  initArgs.response instanceof data_type_js_1.DataType
@@ -56,7 +64,7 @@ class WSOperationClass extends document_element_js_1.DocumentElement {
56
64
  kind: index_js_1.OpraSchema.WSOperation.Kind,
57
65
  description: this.description,
58
66
  event: this.event,
59
- arguments: this.arguments?.map(arg => arg.name ? arg.name : arg.toJSON()),
67
+ arguments: this.arguments?.map(arg => arg.type.name ? arg.type.name : arg.type.toJSON()),
60
68
  });
61
69
  }
62
70
  }
@@ -14,6 +14,6 @@ export function WsParam(type) {
14
14
  paramMetadata = [];
15
15
  Reflect.defineMetadata(WS_PARAM_METADATA, paramMetadata, target, propertyKey);
16
16
  }
17
- paramMetadata[parameterIndex] = type;
17
+ paramMetadata.push({ type, parameterIndex });
18
18
  };
19
19
  }
@@ -101,6 +101,7 @@ export class WSApiFactory {
101
101
  type: undefined,
102
102
  keyType: undefined,
103
103
  arguments: undefined,
104
+ response: undefined,
104
105
  });
105
106
  await this._initWSOperation(context, operation, operationMeta);
106
107
  controller.operations.set(operationName, operation);
@@ -126,9 +127,19 @@ export class WSApiFactory {
126
127
  if (metadata.arguments?.length) {
127
128
  await context.enterAsync('.arguments', async () => {
128
129
  operation.arguments = [];
129
- for (const x of metadata.arguments) {
130
- const t = await DataTypeFactory.resolveDataType(context, operation, x);
131
- operation.arguments?.push(t);
130
+ let x;
131
+ for (x of metadata.arguments) {
132
+ const xx = {};
133
+ if (typeof x === 'object' && x.type && x.parameterIndex !== null) {
134
+ Object.assign(xx, x);
135
+ }
136
+ else
137
+ xx.type = x;
138
+ const t = await DataTypeFactory.resolveDataType(context, operation, xx.type);
139
+ operation.arguments?.push({
140
+ type: t,
141
+ parameterIndex: xx.parameterIndex,
142
+ });
132
143
  }
133
144
  });
134
145
  }
@@ -24,6 +24,7 @@ export const WSOperation = function (...args) {
24
24
  throw new TypeError(`Invalid operation name (${initArgs.name})`);
25
25
  const _this = asMutable(this);
26
26
  _this.types = _this.node[kDataTypeMap] = new DataTypeMap();
27
+ // noinspection JSConstantReassignment
27
28
  _this.name = initArgs.name;
28
29
  _this.description = initArgs.description;
29
30
  if (initArgs.event)
@@ -36,8 +37,15 @@ export const WSOperation = function (...args) {
36
37
  else
37
38
  _this.event = this.name;
38
39
  if (initArgs?.arguments) {
39
- _this.arguments = initArgs.arguments.map(arg => arg instanceof DataType ? arg : _this.owner.node.getDataType(arg));
40
+ _this.arguments = initArgs.arguments.map(arg => {
41
+ const type = arg.type instanceof DataType
42
+ ? arg.type
43
+ : _this.owner.node.getDataType(arg.type);
44
+ return { type, parameterIndex: arg.parameterIndex };
45
+ });
40
46
  }
47
+ else
48
+ _this.arguments = [];
41
49
  if (initArgs?.response)
42
50
  _this.response =
43
51
  initArgs.response instanceof DataType
@@ -53,7 +61,7 @@ class WSOperationClass extends DocumentElement {
53
61
  kind: OpraSchema.WSOperation.Kind,
54
62
  description: this.description,
55
63
  event: this.event,
56
- arguments: this.arguments?.map(arg => arg.name ? arg.name : arg.toJSON()),
64
+ arguments: this.arguments?.map(arg => arg.type.name ? arg.type.name : arg.type.toJSON()),
57
65
  });
58
66
  }
59
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/common",
3
- "version": "1.20.0",
3
+ "version": "1.21.0",
4
4
  "description": "Opra common package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -11,7 +11,10 @@ import { WSController } from './ws-controller.js';
11
11
  */
12
12
  export declare namespace WSOperation {
13
13
  interface Metadata extends Pick<OpraSchema.WSOperation, 'description' | 'event'> {
14
- arguments?: (ThunkAsync<Type | EnumType.EnumObject | EnumType.EnumArray> | string)[];
14
+ arguments?: {
15
+ type: ThunkAsync<Type | EnumType.EnumObject | EnumType.EnumArray> | string;
16
+ parameterIndex: number;
17
+ }[];
15
18
  types?: ThunkAsync<Type | EnumType.EnumObject | EnumType.EnumArray>[];
16
19
  response?: ThunkAsync<Type | EnumType.EnumObject | EnumType.EnumArray>[];
17
20
  }
@@ -22,7 +25,10 @@ export declare namespace WSOperation {
22
25
  interface InitArguments extends Combine<{
23
26
  name: string;
24
27
  types?: DataType[];
25
- arguments?: (DataType | string | Type)[];
28
+ arguments?: {
29
+ type: DataType | string | Type;
30
+ parameterIndex: number;
31
+ }[];
26
32
  }, Pick<Metadata, 'description'>> {
27
33
  event?: string | RegExp;
28
34
  response?: DataType | string | Type;
@@ -62,7 +68,10 @@ declare class WSOperationClass extends DocumentElement {
62
68
  readonly name: string;
63
69
  description?: string;
64
70
  event: string | RegExp;
65
- arguments?: DataType[];
71
+ arguments: {
72
+ type: DataType;
73
+ parameterIndex: number;
74
+ }[];
66
75
  types: DataTypeMap;
67
76
  response?: DataType;
68
77
  toJSON(): OpraSchema.WSOperation;
@@ -6,6 +6,10 @@ import { WSController } from './ws-controller.interface.js';
6
6
  */
7
7
  export interface WSApi extends Api {
8
8
  transport: 'ws';
9
+ /**
10
+ * Name of the platform. (Socketio, ...)
11
+ */
12
+ platform?: string;
9
13
  description?: string;
10
14
  controllers: Record<string, WSController>;
11
15
  }