@opra/common 1.4.3 → 1.4.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.
Files changed (118) hide show
  1. package/browser/index.cjs +1 -1
  2. package/browser/index.mjs +1 -1
  3. package/cjs/document/api-document.js +3 -1
  4. package/cjs/document/common/api-base.js +2 -1
  5. package/cjs/document/common/data-type-map.js +14 -3
  6. package/cjs/document/common/value.js +3 -1
  7. package/cjs/document/data-type/api-field.js +3 -1
  8. package/cjs/document/data-type/complex-type-base.js +12 -4
  9. package/cjs/document/data-type/complex-type.js +6 -2
  10. package/cjs/document/data-type/enum-type.js +3 -1
  11. package/cjs/document/data-type/extended-types/date-time.type.js +5 -1
  12. package/cjs/document/data-type/extended-types/date.type.js +5 -1
  13. package/cjs/document/data-type/extended-types/field-path.type.js +3 -1
  14. package/cjs/document/data-type/extended-types/filter.type.js +3 -1
  15. package/cjs/document/data-type/mapped-type.js +15 -6
  16. package/cjs/document/data-type/mixin-type.js +3 -1
  17. package/cjs/document/data-type/primitive-types/bigint.type.js +3 -1
  18. package/cjs/document/data-type/primitive-types/integer.type.js +3 -1
  19. package/cjs/document/data-type/primitive-types/number.type.js +3 -1
  20. package/cjs/document/data-type/primitive-types/string.type.js +3 -1
  21. package/cjs/document/data-type/simple-type.js +7 -2
  22. package/cjs/document/data-type/utils/create-mapped-class.js +3 -1
  23. package/cjs/document/decorators/api-field-decorator.js +2 -1
  24. package/cjs/document/decorators/http-controller.decorator.js +7 -1
  25. package/cjs/document/decorators/http-operation-entity.decorator.js +20 -10
  26. package/cjs/document/decorators/http-operation.decorator.js +23 -10
  27. package/cjs/document/decorators/rpc-operation.decorator.js +1 -2
  28. package/cjs/document/decorators/simple-type.decorator.js +2 -1
  29. package/cjs/document/factory/api-document.factory.js +11 -3
  30. package/cjs/document/factory/data-type.factory.js +19 -7
  31. package/cjs/document/factory/http-api.factory.js +13 -4
  32. package/cjs/document/http/http-controller.js +2 -1
  33. package/cjs/document/http/http-media-type.js +15 -5
  34. package/cjs/document/http/http-operation-response.js +8 -3
  35. package/cjs/document/http/http-operation.js +3 -1
  36. package/cjs/document/http/http-status-range.js +3 -1
  37. package/cjs/document/rpc/rpc-operation-response.js +11 -3
  38. package/cjs/document/rpc/rpc-operation.js +11 -3
  39. package/cjs/document/utils/parse-regexp.util.js +2 -2
  40. package/cjs/exception/opra-exception.js +3 -1
  41. package/cjs/filter/antlr/OpraFilterLexer.js +190 -123
  42. package/cjs/filter/antlr/OpraFilterParser.js +53 -35
  43. package/cjs/filter/ast/expressions/arithmetic-expression.js +3 -1
  44. package/cjs/filter/ast/terms/number-literal.js +3 -1
  45. package/cjs/filter/filter-rules.js +13 -4
  46. package/cjs/filter/filter-tree-visitor.js +2 -1
  47. package/cjs/filter/opra-error-listener.js +7 -1
  48. package/cjs/filter/parse.js +3 -1
  49. package/cjs/filter/utils.js +3 -1
  50. package/cjs/helpers/get-stack-filename.js +6 -2
  51. package/cjs/helpers/mixin-utils.js +7 -2
  52. package/cjs/helpers/object-utils.js +3 -1
  53. package/cjs/helpers/parse-fields-projection.js +4 -2
  54. package/cjs/helpers/type-guards.js +7 -2
  55. package/cjs/i18n/i18n.js +13 -3
  56. package/cjs/i18n/translate.js +3 -1
  57. package/cjs/polifils/array-find-last.js +0 -2
  58. package/esm/document/api-document.js +4 -2
  59. package/esm/document/common/api-base.js +2 -1
  60. package/esm/document/common/data-type-map.js +14 -3
  61. package/esm/document/common/value.js +3 -1
  62. package/esm/document/data-type/api-field.js +3 -1
  63. package/esm/document/data-type/complex-type-base.js +13 -5
  64. package/esm/document/data-type/complex-type.js +6 -2
  65. package/esm/document/data-type/data-type.js +1 -1
  66. package/esm/document/data-type/enum-type.js +3 -1
  67. package/esm/document/data-type/extended-types/date-time.type.js +5 -1
  68. package/esm/document/data-type/extended-types/date.type.js +5 -1
  69. package/esm/document/data-type/extended-types/field-path.type.js +3 -1
  70. package/esm/document/data-type/extended-types/filter.type.js +3 -1
  71. package/esm/document/data-type/mapped-type.js +15 -6
  72. package/esm/document/data-type/mixin-type.js +4 -2
  73. package/esm/document/data-type/primitive-types/bigint.type.js +3 -1
  74. package/esm/document/data-type/primitive-types/integer.type.js +3 -1
  75. package/esm/document/data-type/primitive-types/number.type.js +3 -1
  76. package/esm/document/data-type/primitive-types/string.type.js +3 -1
  77. package/esm/document/data-type/simple-type.js +8 -3
  78. package/esm/document/data-type/utils/create-mapped-class.js +4 -2
  79. package/esm/document/decorators/api-field-decorator.js +2 -1
  80. package/esm/document/decorators/complex-type.decorator.js +1 -1
  81. package/esm/document/decorators/http-controller.decorator.js +7 -1
  82. package/esm/document/decorators/http-operation-entity.decorator.js +22 -12
  83. package/esm/document/decorators/http-operation.decorator.js +23 -10
  84. package/esm/document/decorators/rpc-operation.decorator.js +1 -2
  85. package/esm/document/decorators/simple-type.decorator.js +3 -2
  86. package/esm/document/factory/api-document.factory.js +11 -3
  87. package/esm/document/factory/data-type.factory.js +21 -9
  88. package/esm/document/factory/http-api.factory.js +13 -4
  89. package/esm/document/http/http-controller.js +3 -2
  90. package/esm/document/http/http-media-type.js +15 -5
  91. package/esm/document/http/http-operation-response.js +8 -3
  92. package/esm/document/http/http-operation.js +4 -2
  93. package/esm/document/http/http-parameter.js +1 -1
  94. package/esm/document/http/http-status-range.js +3 -1
  95. package/esm/document/rpc/rpc-controller.js +1 -1
  96. package/esm/document/rpc/rpc-header.js +1 -1
  97. package/esm/document/rpc/rpc-operation-response.js +11 -3
  98. package/esm/document/rpc/rpc-operation.js +12 -4
  99. package/esm/document/utils/parse-regexp.util.js +2 -2
  100. package/esm/exception/opra-exception.js +3 -1
  101. package/esm/filter/antlr/OpraFilterLexer.js +190 -123
  102. package/esm/filter/antlr/OpraFilterParser.js +53 -35
  103. package/esm/filter/ast/expressions/arithmetic-expression.js +3 -1
  104. package/esm/filter/ast/terms/number-literal.js +3 -1
  105. package/esm/filter/filter-rules.js +13 -4
  106. package/esm/filter/filter-tree-visitor.js +2 -1
  107. package/esm/filter/opra-error-listener.js +8 -2
  108. package/esm/filter/parse.js +3 -1
  109. package/esm/filter/utils.js +3 -1
  110. package/esm/helpers/get-stack-filename.js +6 -2
  111. package/esm/helpers/mixin-utils.js +7 -2
  112. package/esm/helpers/object-utils.js +3 -1
  113. package/esm/helpers/parse-fields-projection.js +4 -2
  114. package/esm/helpers/type-guards.js +7 -2
  115. package/esm/i18n/i18n.js +13 -3
  116. package/esm/i18n/translate.js +3 -1
  117. package/esm/polifils/array-find-last.js +0 -2
  118. package/package.json +1 -1
@@ -113,7 +113,8 @@ class DataTypeFactory {
113
113
  for (let thunk of types) {
114
114
  await context.enterAsync(`$[${i++}]`, async () => {
115
115
  thunk = await (0, index_js_1.resolveThunk)(thunk);
116
- const metadata = Reflect.getMetadata(constants_js_1.DATATYPE_METADATA, thunk) || thunk[constants_js_1.DATATYPE_METADATA];
116
+ const metadata = Reflect.getMetadata(constants_js_1.DATATYPE_METADATA, thunk) ||
117
+ thunk[constants_js_1.DATATYPE_METADATA];
117
118
  if (!(metadata && metadata.name)) {
118
119
  if (typeof thunk === 'function') {
119
120
  return context.addError(`Class "${thunk.name}" doesn't have a valid data type metadata`);
@@ -203,7 +204,8 @@ class DataTypeFactory {
203
204
  const baseArgs = await this._importDataTypeArgs(context, owner, metadata.name);
204
205
  if (!baseArgs)
205
206
  return;
206
- if (typeof baseArgs === 'object' && baseArgs.kind !== index_js_2.OpraSchema.SimpleType.Kind) {
207
+ if (typeof baseArgs === 'object' &&
208
+ baseArgs.kind !== index_js_2.OpraSchema.SimpleType.Kind) {
207
209
  return context.addError('Kind of base data type is not same');
208
210
  }
209
211
  return {
@@ -303,7 +305,8 @@ class DataTypeFactory {
303
305
  });
304
306
  // Initialize additionalFields
305
307
  if (metadata.additionalFields != null) {
306
- if (typeof metadata.additionalFields === 'boolean' || Array.isArray(metadata.additionalFields)) {
308
+ if (typeof metadata.additionalFields === 'boolean' ||
309
+ Array.isArray(metadata.additionalFields)) {
307
310
  initArgs.additionalFields = metadata.additionalFields;
308
311
  }
309
312
  else {
@@ -401,10 +404,14 @@ class DataTypeFactory {
401
404
  else if (metadata.omit)
402
405
  initArgs.omit = [...metadata.omit];
403
406
  else if (metadata.partial) {
404
- initArgs.partial = Array.isArray(metadata.partial) ? [...metadata.partial] : metadata.partial;
407
+ initArgs.partial = Array.isArray(metadata.partial)
408
+ ? [...metadata.partial]
409
+ : metadata.partial;
405
410
  }
406
411
  else if (metadata.required) {
407
- initArgs.required = Array.isArray(metadata.required) ? [...metadata.required] : metadata.required;
412
+ initArgs.required = Array.isArray(metadata.required)
413
+ ? [...metadata.required]
414
+ : metadata.required;
408
415
  }
409
416
  }
410
417
  static async _prepareMixinTypeArgs(context, owner, initArgs, metadata) {
@@ -465,7 +472,8 @@ class DataTypeFactory {
465
472
  /** Set additionalFields */
466
473
  if (args.additionalFields) {
467
474
  context.enter('.additionalFields', () => {
468
- if (typeof args.additionalFields === 'boolean' || Array.isArray(args.additionalFields)) {
475
+ if (typeof args.additionalFields === 'boolean' ||
476
+ Array.isArray(args.additionalFields)) {
469
477
  initArgs.additionalFields = args.additionalFields;
470
478
  }
471
479
  else {
@@ -556,5 +564,9 @@ class DataTypeFactory {
556
564
  }
557
565
  exports.DataTypeFactory = DataTypeFactory;
558
566
  function preferName(initArgs) {
559
- return typeof initArgs === 'object' ? (initArgs.name ? initArgs.name : initArgs) : initArgs;
567
+ return typeof initArgs === 'object'
568
+ ? initArgs.name
569
+ ? initArgs.name
570
+ : initArgs
571
+ : initArgs;
560
572
  }
@@ -71,7 +71,8 @@ class HttpApiFactory {
71
71
  }
72
72
  static async _resolveControllerMetadata(context, parent, thunk) {
73
73
  if (typeof thunk === 'function' && !(0, objects_1.isConstructor)(thunk)) {
74
- thunk = parent instanceof http_controller_js_1.HttpController ? thunk(parent.instance) : thunk();
74
+ thunk =
75
+ parent instanceof http_controller_js_1.HttpController ? thunk(parent.instance) : thunk();
75
76
  }
76
77
  thunk = await (0, index_js_1.resolveThunk)(thunk);
77
78
  let ctor;
@@ -135,7 +136,10 @@ class HttpApiFactory {
135
136
  await context.enterAsync('.operations', async () => {
136
137
  for (const [k, v] of Object.entries(metadata.operations)) {
137
138
  await context.enterAsync(`[${k}]`, async () => {
138
- const operation = new http_operation_js_1.HttpOperation(controller, { name: k, method: 'GET' });
139
+ const operation = new http_operation_js_1.HttpOperation(controller, {
140
+ name: k,
141
+ method: 'GET',
142
+ });
139
143
  await this._initHttpOperation(context, operation, v);
140
144
  controller.operations.set(k, operation);
141
145
  });
@@ -188,7 +192,9 @@ class HttpApiFactory {
188
192
  let i = 0;
189
193
  for (const v of metadata.responses) {
190
194
  await context.enterAsync(`[${i++}]`, async () => {
191
- const response = new http_operation_response_js_1.HttpOperationResponse(operation, { statusCode: v.statusCode });
195
+ const response = new http_operation_response_js_1.HttpOperationResponse(operation, {
196
+ statusCode: v.statusCode,
197
+ });
192
198
  await this._initHttpOperationResponse(context, response, v);
193
199
  operation.responses.push(response);
194
200
  });
@@ -227,7 +233,10 @@ class HttpApiFactory {
227
233
  for (let i = 0; i < metadata.multipartFields.length; i++) {
228
234
  await context.enterAsync(`[${i}]`, async () => {
229
235
  const src = metadata.multipartFields[i];
230
- const field = new http_multipart_field_js_1.HttpMultipartField(target, { fieldName: src.fieldName, fieldType: src.fieldType });
236
+ const field = new http_multipart_field_js_1.HttpMultipartField(target, {
237
+ fieldName: src.fieldName,
238
+ fieldType: src.fieldType,
239
+ });
231
240
  await this._initHttpMediaType(context, field, src);
232
241
  target.multipartFields.push(field);
233
242
  });
@@ -98,7 +98,8 @@ class HttpControllerClass extends document_element_js_1.DocumentElement {
98
98
  if (prm.name instanceof RegExp && prm.name.test(paramName))
99
99
  return prm;
100
100
  }
101
- if (this.node.parent && this.node.parent.element instanceof exports.HttpController) {
101
+ if (this.node.parent &&
102
+ this.node.parent.element instanceof exports.HttpController) {
102
103
  return this.node.parent.element.findParameter(paramName, location);
103
104
  }
104
105
  }
@@ -14,7 +14,9 @@ exports.HttpMediaType = function (owner, initArgs) {
14
14
  document_element_js_1.DocumentElement.call(this, owner);
15
15
  const _this = (0, ts_gems_1.asMutable)(this);
16
16
  if (initArgs.contentType) {
17
- let arr = Array.isArray(initArgs.contentType) ? initArgs.contentType : [initArgs.contentType];
17
+ let arr = Array.isArray(initArgs.contentType)
18
+ ? initArgs.contentType
19
+ : [initArgs.contentType];
18
20
  arr = arr.map(x => x.split(/\s*,\s*/)).flat();
19
21
  _this.contentType = arr.length > 1 ? arr : arr[0];
20
22
  }
@@ -28,7 +30,10 @@ exports.HttpMediaType = function (owner, initArgs) {
28
30
  _this.maxFileSize = initArgs.maxFileSize;
29
31
  _this.maxTotalFileSize = initArgs.maxTotalFileSize;
30
32
  if (initArgs?.type) {
31
- _this.type = initArgs?.type instanceof data_type_js_1.DataType ? initArgs.type : _this.owner.node.getDataType(initArgs.type);
33
+ _this.type =
34
+ initArgs?.type instanceof data_type_js_1.DataType
35
+ ? initArgs.type
36
+ : _this.owner.node.getDataType(initArgs.type);
32
37
  }
33
38
  _this.isArray = initArgs.isArray;
34
39
  };
@@ -41,13 +46,16 @@ class HttpMediaTypeClass extends document_element_js_1.DocumentElement {
41
46
  return;
42
47
  for (const f of this.multipartFields) {
43
48
  if ((!fieldType || fieldType === f.fieldType) &&
44
- ((f.fieldName instanceof RegExp && f.fieldName.test(fieldName)) || f.fieldName === fieldName)) {
49
+ ((f.fieldName instanceof RegExp && f.fieldName.test(fieldName)) ||
50
+ f.fieldName === fieldName)) {
45
51
  return f;
46
52
  }
47
53
  }
48
54
  }
49
55
  toJSON() {
50
- const typeName = this.type ? this.node.getDataTypeNameWithNs(this.type) : undefined;
56
+ const typeName = this.type
57
+ ? this.node.getDataTypeNameWithNs(this.type)
58
+ : undefined;
51
59
  const out = (0, objects_1.omitUndefined)({
52
60
  description: this.description,
53
61
  contentType: this.contentType,
@@ -73,7 +81,9 @@ class HttpMediaTypeClass extends document_element_js_1.DocumentElement {
73
81
  fn = this.type.generateCodec(codec, options);
74
82
  }
75
83
  else if (this.contentType) {
76
- const arr = Array.isArray(this.contentType) ? this.contentType : [this.contentType];
84
+ const arr = Array.isArray(this.contentType)
85
+ ? this.contentType
86
+ : [this.contentType];
77
87
  if (arr.find(ct => type_is_1.default.is(ct, ['json']))) {
78
88
  fn = this.node.findDataType('object').generateCodec(codec);
79
89
  }
@@ -11,14 +11,17 @@ class HttpOperationResponse extends http_media_type_js_1.HttpMediaType {
11
11
  constructor(owner, init) {
12
12
  super(owner, init);
13
13
  this.parameters = [];
14
- this.statusCode = (Array.isArray(init.statusCode) ? init.statusCode : [init.statusCode]).map(x => typeof x === 'object' ? new http_status_range_js_1.HttpStatusRange(x.start, x.end) : new http_status_range_js_1.HttpStatusRange(x));
14
+ this.statusCode = (Array.isArray(init.statusCode) ? init.statusCode : [init.statusCode]).map(x => typeof x === 'object'
15
+ ? new http_status_range_js_1.HttpStatusRange(x.start, x.end)
16
+ : new http_status_range_js_1.HttpStatusRange(x));
15
17
  this.partial = init.partial;
16
18
  }
17
19
  findParameter(paramName, location) {
18
20
  paramName = paramName.toLowerCase();
19
21
  for (const prm of this.parameters) {
20
22
  if ((!location || location === prm.location) &&
21
- ((prm.name instanceof RegExp && prm.name.test(paramName)) || prm.name === paramName)) {
23
+ ((prm.name instanceof RegExp && prm.name.test(paramName)) ||
24
+ prm.name === paramName)) {
22
25
  return prm;
23
26
  }
24
27
  }
@@ -27,7 +30,9 @@ class HttpOperationResponse extends http_media_type_js_1.HttpMediaType {
27
30
  const statusCode = this.statusCode.map(x => x.toJSON());
28
31
  const out = (0, objects_1.omitUndefined)({
29
32
  ...super.toJSON(),
30
- statusCode: statusCode.length === 1 && typeof statusCode[0] === 'number' ? statusCode[0] : statusCode,
33
+ statusCode: statusCode.length === 1 && typeof statusCode[0] === 'number'
34
+ ? statusCode[0]
35
+ : statusCode,
31
36
  partial: this.partial,
32
37
  });
33
38
  if (this.parameters.length) {
@@ -36,7 +36,9 @@ exports.HttpOperation = function (...args) {
36
36
  _this.method = initArgs.method || 'GET';
37
37
  _this.description = initArgs.description;
38
38
  _this.composition = initArgs.composition;
39
- _this.compositionOptions = initArgs.compositionOptions ? (0, index_js_1.cloneObject)(initArgs.compositionOptions) : undefined;
39
+ _this.compositionOptions = initArgs.compositionOptions
40
+ ? (0, index_js_1.cloneObject)(initArgs.compositionOptions)
41
+ : undefined;
40
42
  };
41
43
  /**
42
44
  * @class HttpOperation
@@ -37,7 +37,9 @@ class HttpStatusRange {
37
37
  return String(this.start) + '-' + String(this.end);
38
38
  }
39
39
  toJSON() {
40
- return !this.end || this.start === this.end ? this.start : { start: this.start, end: this.end };
40
+ return !this.end || this.start === this.end
41
+ ? this.start
42
+ : { start: this.start, end: this.end };
41
43
  }
42
44
  }
43
45
  exports.HttpStatusRange = HttpStatusRange;
@@ -23,7 +23,9 @@ class RpcOperationResponse extends document_element_js_1.DocumentElement {
23
23
  this.payloadType = this.owner.node.getDataType('any');
24
24
  if (initArgs?.keyType) {
25
25
  this.keyType =
26
- initArgs?.keyType instanceof data_type_js_1.DataType ? initArgs.keyType : this.owner.node.getDataType(initArgs.keyType);
26
+ initArgs?.keyType instanceof data_type_js_1.DataType
27
+ ? initArgs.keyType
28
+ : this.owner.node.getDataType(initArgs.keyType);
27
29
  }
28
30
  }
29
31
  findHeader(paramName) {
@@ -43,8 +45,14 @@ class RpcOperationResponse extends document_element_js_1.DocumentElement {
43
45
  const out = (0, objects_1.omitUndefined)({
44
46
  description: this.description,
45
47
  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
+ payloadType: this.payloadType.name
49
+ ? this.payloadType.name
50
+ : this.payloadType.toJSON(),
51
+ keyType: this.keyType
52
+ ? this.keyType.name
53
+ ? this.keyType.name
54
+ : this.keyType.toJSON()
55
+ : undefined,
48
56
  });
49
57
  if (this.headers.length) {
50
58
  out.headers = [];
@@ -38,7 +38,9 @@ exports.RpcOperation = function (...args) {
38
38
  }
39
39
  if (initArgs?.keyType) {
40
40
  _this.keyType =
41
- initArgs?.keyType instanceof data_type_js_1.DataType ? initArgs.keyType : _this.owner.node.getDataType(initArgs.keyType);
41
+ initArgs?.keyType instanceof data_type_js_1.DataType
42
+ ? initArgs.keyType
43
+ : _this.owner.node.getDataType(initArgs.keyType);
42
44
  }
43
45
  };
44
46
  /**
@@ -63,8 +65,14 @@ class RpcOperationClass extends document_element_js_1.DocumentElement {
63
65
  kind: index_js_1.OpraSchema.RpcOperation.Kind,
64
66
  description: this.description,
65
67
  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
+ payloadType: this.payloadType.name
69
+ ? this.payloadType.name
70
+ : this.payloadType.toJSON(),
71
+ keyType: this.keyType
72
+ ? this.keyType.name
73
+ ? this.keyType.name
74
+ : this.keyType.toJSON()
75
+ : undefined,
68
76
  response: this.response?.toJSON(),
69
77
  });
70
78
  if (this.headers.length) {
@@ -7,12 +7,12 @@ function parseRegExp(str, options) {
7
7
  const s = str.substring(1, i);
8
8
  let flags = str.substring(i + 1);
9
9
  if (options?.includeFlags) {
10
- for (const f of options?.includeFlags)
10
+ for (const f of options.includeFlags)
11
11
  if (!flags.includes(f))
12
12
  flags += f;
13
13
  }
14
14
  if (options?.excludeFlags) {
15
- for (const f of options?.excludeFlags)
15
+ for (const f of options.excludeFlags)
16
16
  flags.replace(f, '');
17
17
  }
18
18
  return new RegExp(s, flags);
@@ -38,7 +38,9 @@ class OpraException extends Error {
38
38
  system: this.system,
39
39
  code: this.code,
40
40
  details: this.details,
41
- stack: env === 'dev' || env === 'development' || env === 'test' ? this.stack?.split('\n') : undefined,
41
+ stack: env === 'dev' || env === 'development' || env === 'test'
42
+ ? this.stack?.split('\n')
43
+ : undefined,
42
44
  }, true);
43
45
  }
44
46
  init(issue) {