@opra/common 1.4.3 → 1.5.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.
Files changed (182) hide show
  1. package/browser/index.cjs +5 -5
  2. package/browser/index.mjs +5 -5
  3. package/cjs/document/api-document.js +16 -9
  4. package/cjs/document/common/api-base.js +4 -2
  5. package/cjs/document/common/data-type-map.js +14 -3
  6. package/cjs/document/common/document-init-context.js +5 -0
  7. package/cjs/document/common/document-node.js +25 -29
  8. package/cjs/document/common/value.js +9 -3
  9. package/cjs/document/constants.js +1 -2
  10. package/cjs/document/data-type/api-field.js +19 -4
  11. package/cjs/document/data-type/complex-type-base.js +24 -7
  12. package/cjs/document/data-type/complex-type.js +17 -6
  13. package/cjs/document/data-type/data-type.js +16 -1
  14. package/cjs/document/data-type/enum-type.js +12 -3
  15. package/cjs/document/data-type/extended-types/base64.type.js +1 -0
  16. package/cjs/document/data-type/extended-types/date-string.type.js +1 -0
  17. package/cjs/document/data-type/extended-types/date-time-string.type.js +1 -0
  18. package/cjs/document/data-type/extended-types/date-time.type.js +6 -1
  19. package/cjs/document/data-type/extended-types/date.type.js +6 -1
  20. package/cjs/document/data-type/extended-types/email.type.js +1 -0
  21. package/cjs/document/data-type/extended-types/field-path.type.js +9 -3
  22. package/cjs/document/data-type/extended-types/filter.type.js +14 -5
  23. package/cjs/document/data-type/extended-types/object-id.type.js +1 -0
  24. package/cjs/document/data-type/extended-types/operation-result.type.js +1 -0
  25. package/cjs/document/data-type/extended-types/time.type.js +1 -0
  26. package/cjs/document/data-type/extended-types/url.type.js +1 -0
  27. package/cjs/document/data-type/extended-types/uuid.type.js +1 -0
  28. package/cjs/document/data-type/mapped-type.js +21 -9
  29. package/cjs/document/data-type/mixin-type.js +10 -5
  30. package/cjs/document/data-type/primitive-types/any.type.js +1 -0
  31. package/cjs/document/data-type/primitive-types/bigint.type.js +4 -1
  32. package/cjs/document/data-type/primitive-types/boolean.type.js +1 -0
  33. package/cjs/document/data-type/primitive-types/integer.type.js +4 -1
  34. package/cjs/document/data-type/primitive-types/null.type.js +1 -0
  35. package/cjs/document/data-type/primitive-types/number.type.js +4 -1
  36. package/cjs/document/data-type/primitive-types/string.type.js +4 -1
  37. package/cjs/document/data-type/simple-type.js +17 -5
  38. package/cjs/document/data-type/utils/create-mapped-class.js +3 -1
  39. package/cjs/document/decorators/api-field-decorator.js +2 -1
  40. package/cjs/document/decorators/complex-type.decorator.js +1 -1
  41. package/cjs/document/decorators/http-controller.decorator.js +7 -1
  42. package/cjs/document/decorators/http-operation-entity.decorator.js +20 -10
  43. package/cjs/document/decorators/http-operation.decorator.js +23 -10
  44. package/cjs/document/decorators/rpc-operation.decorator.js +1 -2
  45. package/cjs/document/decorators/simple-type.decorator.js +3 -2
  46. package/cjs/document/factory/api-document.factory.js +12 -3
  47. package/cjs/document/factory/data-type.factory.js +19 -7
  48. package/cjs/document/factory/http-api.factory.js +13 -4
  49. package/cjs/document/http/http-api.js +2 -2
  50. package/cjs/document/http/http-controller.js +7 -6
  51. package/cjs/document/http/http-media-type.js +18 -8
  52. package/cjs/document/http/http-multipart-field.js +2 -2
  53. package/cjs/document/http/http-operation-response.js +11 -6
  54. package/cjs/document/http/http-operation.js +8 -6
  55. package/cjs/document/http/http-parameter.js +2 -2
  56. package/cjs/document/http/http-request-body.js +4 -2
  57. package/cjs/document/http/http-status-range.js +3 -1
  58. package/cjs/document/rpc/rpc-operation-response.js +11 -3
  59. package/cjs/document/rpc/rpc-operation.js +11 -3
  60. package/cjs/document/utils/parse-regexp.util.js +2 -2
  61. package/cjs/exception/opra-exception.js +3 -1
  62. package/cjs/filter/antlr/OpraFilterLexer.js +190 -123
  63. package/cjs/filter/antlr/OpraFilterParser.js +53 -35
  64. package/cjs/filter/ast/expressions/arithmetic-expression.js +3 -1
  65. package/cjs/filter/ast/terms/number-literal.js +3 -1
  66. package/cjs/filter/filter-rules.js +18 -8
  67. package/cjs/filter/filter-tree-visitor.js +2 -1
  68. package/cjs/filter/opra-error-listener.js +7 -1
  69. package/cjs/filter/parse.js +3 -1
  70. package/cjs/filter/utils.js +3 -1
  71. package/cjs/helpers/get-stack-filename.js +6 -2
  72. package/cjs/helpers/mixin-utils.js +7 -2
  73. package/cjs/helpers/object-utils.js +3 -1
  74. package/cjs/helpers/parse-fields-projection.js +4 -2
  75. package/cjs/helpers/type-guards.js +7 -2
  76. package/cjs/i18n/i18n.js +13 -3
  77. package/cjs/i18n/translate.js +3 -1
  78. package/cjs/polifils/array-find-last.js +0 -2
  79. package/esm/document/api-document.js +17 -10
  80. package/esm/document/common/api-base.js +4 -2
  81. package/esm/document/common/data-type-map.js +14 -3
  82. package/esm/document/common/document-init-context.js +5 -0
  83. package/esm/document/common/document-node.js +25 -29
  84. package/esm/document/common/value.js +9 -3
  85. package/esm/document/constants.js +0 -1
  86. package/esm/document/data-type/api-field.js +19 -4
  87. package/esm/document/data-type/complex-type-base.js +25 -8
  88. package/esm/document/data-type/complex-type.js +17 -6
  89. package/esm/document/data-type/data-type.js +17 -2
  90. package/esm/document/data-type/enum-type.js +12 -3
  91. package/esm/document/data-type/extended-types/base64.type.js +1 -0
  92. package/esm/document/data-type/extended-types/date-string.type.js +1 -0
  93. package/esm/document/data-type/extended-types/date-time-string.type.js +1 -0
  94. package/esm/document/data-type/extended-types/date-time.type.js +6 -1
  95. package/esm/document/data-type/extended-types/date.type.js +6 -1
  96. package/esm/document/data-type/extended-types/email.type.js +1 -0
  97. package/esm/document/data-type/extended-types/field-path.type.js +9 -3
  98. package/esm/document/data-type/extended-types/filter.type.js +14 -5
  99. package/esm/document/data-type/extended-types/object-id.type.js +1 -0
  100. package/esm/document/data-type/extended-types/operation-result.type.js +1 -0
  101. package/esm/document/data-type/extended-types/time.type.js +1 -0
  102. package/esm/document/data-type/extended-types/url.type.js +1 -0
  103. package/esm/document/data-type/extended-types/uuid.type.js +1 -0
  104. package/esm/document/data-type/mapped-type.js +21 -9
  105. package/esm/document/data-type/mixin-type.js +11 -6
  106. package/esm/document/data-type/primitive-types/any.type.js +1 -0
  107. package/esm/document/data-type/primitive-types/bigint.type.js +4 -1
  108. package/esm/document/data-type/primitive-types/boolean.type.js +1 -0
  109. package/esm/document/data-type/primitive-types/integer.type.js +4 -1
  110. package/esm/document/data-type/primitive-types/null.type.js +1 -0
  111. package/esm/document/data-type/primitive-types/number.type.js +4 -1
  112. package/esm/document/data-type/primitive-types/string.type.js +4 -1
  113. package/esm/document/data-type/simple-type.js +18 -6
  114. package/esm/document/data-type/utils/create-mapped-class.js +4 -2
  115. package/esm/document/decorators/api-field-decorator.js +2 -1
  116. package/esm/document/decorators/complex-type.decorator.js +2 -2
  117. package/esm/document/decorators/http-controller.decorator.js +7 -1
  118. package/esm/document/decorators/http-operation-entity.decorator.js +22 -12
  119. package/esm/document/decorators/http-operation.decorator.js +23 -10
  120. package/esm/document/decorators/rpc-operation.decorator.js +1 -2
  121. package/esm/document/decorators/simple-type.decorator.js +4 -3
  122. package/esm/document/factory/api-document.factory.js +12 -3
  123. package/esm/document/factory/data-type.factory.js +21 -9
  124. package/esm/document/factory/http-api.factory.js +13 -4
  125. package/esm/document/http/http-api.js +2 -2
  126. package/esm/document/http/http-controller.js +8 -7
  127. package/esm/document/http/http-media-type.js +18 -8
  128. package/esm/document/http/http-multipart-field.js +2 -2
  129. package/esm/document/http/http-operation-response.js +11 -6
  130. package/esm/document/http/http-operation.js +9 -7
  131. package/esm/document/http/http-parameter.js +3 -3
  132. package/esm/document/http/http-request-body.js +4 -2
  133. package/esm/document/http/http-status-range.js +3 -1
  134. package/esm/document/rpc/rpc-controller.js +1 -1
  135. package/esm/document/rpc/rpc-header.js +1 -1
  136. package/esm/document/rpc/rpc-operation-response.js +11 -3
  137. package/esm/document/rpc/rpc-operation.js +12 -4
  138. package/esm/document/utils/parse-regexp.util.js +2 -2
  139. package/esm/exception/opra-exception.js +3 -1
  140. package/esm/filter/antlr/OpraFilterLexer.js +190 -123
  141. package/esm/filter/antlr/OpraFilterParser.js +53 -35
  142. package/esm/filter/ast/expressions/arithmetic-expression.js +3 -1
  143. package/esm/filter/ast/terms/number-literal.js +3 -1
  144. package/esm/filter/filter-rules.js +18 -8
  145. package/esm/filter/filter-tree-visitor.js +2 -1
  146. package/esm/filter/opra-error-listener.js +8 -2
  147. package/esm/filter/parse.js +3 -1
  148. package/esm/filter/utils.js +3 -1
  149. package/esm/helpers/get-stack-filename.js +6 -2
  150. package/esm/helpers/mixin-utils.js +7 -2
  151. package/esm/helpers/object-utils.js +3 -1
  152. package/esm/helpers/parse-fields-projection.js +4 -2
  153. package/esm/helpers/type-guards.js +7 -2
  154. package/esm/i18n/i18n.js +13 -3
  155. package/esm/i18n/translate.js +3 -1
  156. package/esm/polifils/array-find-last.js +0 -2
  157. package/package.json +1 -1
  158. package/types/document/api-document.d.ts +8 -2
  159. package/types/document/common/api-base.d.ts +1 -1
  160. package/types/document/common/document-init-context.d.ts +2 -0
  161. package/types/document/common/document-node.d.ts +8 -14
  162. package/types/document/common/value.d.ts +2 -1
  163. package/types/document/constants.d.ts +0 -1
  164. package/types/document/data-type/api-field.d.ts +6 -11
  165. package/types/document/data-type/complex-type.d.ts +2 -1
  166. package/types/document/data-type/data-type.d.ts +7 -2
  167. package/types/document/data-type/enum-type.d.ts +2 -1
  168. package/types/document/data-type/extended-types/field-path.type.d.ts +2 -1
  169. package/types/document/data-type/extended-types/filter.type.d.ts +2 -1
  170. package/types/document/data-type/mapped-type.d.ts +2 -1
  171. package/types/document/data-type/mixin-type.d.ts +2 -1
  172. package/types/document/data-type/simple-type.d.ts +2 -1
  173. package/types/document/factory/api-document.factory.d.ts +2 -1
  174. package/types/document/http/http-api.d.ts +1 -1
  175. package/types/document/http/http-controller.d.ts +2 -1
  176. package/types/document/http/http-media-type.d.ts +2 -1
  177. package/types/document/http/http-multipart-field.d.ts +2 -1
  178. package/types/document/http/http-operation-response.d.ts +2 -1
  179. package/types/document/http/http-operation.d.ts +2 -1
  180. package/types/document/http/http-parameter.d.ts +2 -1
  181. package/types/document/http/http-request-body.d.ts +2 -1
  182. package/types/filter/filter-rules.d.ts +3 -3
@@ -6,7 +6,7 @@ import { OpraSchema } from '../../schema/index.js';
6
6
  import { DataTypeMap } from '../common/data-type-map.js';
7
7
  import { DocumentElement } from '../common/document-element.js';
8
8
  import { CLASS_NAME_PATTERN, DECORATOR, kDataTypeMap } from '../constants.js';
9
- import { HttpOperationDecoratorFactory } from '../decorators/http-operation.decorator.js';
9
+ import { HttpOperationDecoratorFactory, } from '../decorators/http-operation.decorator.js';
10
10
  /**
11
11
  * HttpOperation
12
12
  */
@@ -32,7 +32,9 @@ export const HttpOperation = function (...args) {
32
32
  _this.method = initArgs.method || 'GET';
33
33
  _this.description = initArgs.description;
34
34
  _this.composition = initArgs.composition;
35
- _this.compositionOptions = initArgs.compositionOptions ? cloneObject(initArgs.compositionOptions) : undefined;
35
+ _this.compositionOptions = initArgs.compositionOptions
36
+ ? cloneObject(initArgs.compositionOptions)
37
+ : undefined;
36
38
  };
37
39
  /**
38
40
  * @class HttpOperation
@@ -65,7 +67,7 @@ class HttpOperationClass extends DocumentElement {
65
67
  }
66
68
  return this.path || '/';
67
69
  }
68
- toJSON() {
70
+ toJSON(options) {
69
71
  const out = omitUndefined({
70
72
  kind: OpraSchema.HttpOperation.Kind,
71
73
  description: this.description,
@@ -73,22 +75,22 @@ class HttpOperationClass extends DocumentElement {
73
75
  path: this.path,
74
76
  mergePath: this.mergePath,
75
77
  composition: this.composition,
76
- requestBody: this.requestBody?.toJSON(),
78
+ requestBody: this.requestBody?.toJSON(options),
77
79
  });
78
80
  if (this.types.size) {
79
81
  out.types = {};
80
82
  for (const v of this.types.values()) {
81
- out.types[v.name] = v.toJSON();
83
+ out.types[v.name] = v.toJSON(options);
82
84
  }
83
85
  }
84
86
  if (this.parameters.length) {
85
87
  out.parameters = [];
86
88
  for (const prm of this.parameters) {
87
- out.parameters.push(prm.toJSON());
89
+ out.parameters.push(prm.toJSON(options));
88
90
  }
89
91
  }
90
92
  if (this.responses.length)
91
- out.responses = this.responses.map(r => r.toJSON());
93
+ out.responses = this.responses.map(r => r.toJSON(options));
92
94
  return out;
93
95
  }
94
96
  }
@@ -1,5 +1,5 @@
1
1
  import { omitUndefined } from '@jsopen/objects';
2
- import { asMutable } from 'ts-gems';
2
+ import { asMutable, } from 'ts-gems';
3
3
  import { Value } from '../common/value.js';
4
4
  import { parseRegExp } from '../utils/parse-regexp.util.js';
5
5
  export const HttpParameter = function (owner, initArgs) {
@@ -30,9 +30,9 @@ export const HttpParameter = function (owner, initArgs) {
30
30
  * @class HttpParameter
31
31
  */
32
32
  class HttpParameterClass extends Value {
33
- toJSON() {
33
+ toJSON(options) {
34
34
  return omitUndefined({
35
- ...super.toJSON(),
35
+ ...super.toJSON(options),
36
36
  name: this.name,
37
37
  location: this.location,
38
38
  arraySeparator: this.arraySeparator,
@@ -8,12 +8,14 @@ export class HttpRequestBody extends DocumentElement {
8
8
  super(owner);
9
9
  this.content = [];
10
10
  }
11
- toJSON() {
11
+ toJSON(options) {
12
12
  return omitUndefined({
13
13
  description: this.description,
14
14
  required: this.required,
15
15
  maxContentSize: this.maxContentSize,
16
- content: this.content.length ? this.content.map(x => x.toJSON()) : [],
16
+ content: this.content.length
17
+ ? this.content.map(x => x.toJSON(options))
18
+ : [],
17
19
  partial: this.partial,
18
20
  allowPatchOperators: this.allowPatchOperators,
19
21
  });
@@ -34,6 +34,8 @@ export class HttpStatusRange {
34
34
  return String(this.start) + '-' + String(this.end);
35
35
  }
36
36
  toJSON() {
37
- return !this.end || this.start === this.end ? this.start : { start: this.start, end: this.end };
37
+ return !this.end || this.start === this.end
38
+ ? this.start
39
+ : { start: this.start, end: this.end };
38
40
  }
39
41
  }
@@ -6,7 +6,7 @@ import { DataTypeMap } from '../common/data-type-map.js';
6
6
  import { DocumentElement } from '../common/document-element.js';
7
7
  import { CLASS_NAME_PATTERN, DECORATOR, kDataTypeMap } from '../constants.js';
8
8
  import { RpcControllerDecoratorFactory } from '../decorators/rpc-controller.decorator.js';
9
- import { colorFgMagenta, colorFgYellow, colorReset, nodeInspectCustom } from '../utils/inspect.util.js';
9
+ import { colorFgMagenta, colorFgYellow, colorReset, nodeInspectCustom, } from '../utils/inspect.util.js';
10
10
  /**
11
11
  * RpcController
12
12
  */
@@ -1,5 +1,5 @@
1
1
  import { omitUndefined } from '@jsopen/objects';
2
- import { asMutable } from 'ts-gems';
2
+ import { asMutable, } from 'ts-gems';
3
3
  import { Value } from '../common/value.js';
4
4
  import { parseRegExp } from '../utils/parse-regexp.util.js';
5
5
  export const RpcHeader = function (owner, initArgs) {
@@ -20,7 +20,9 @@ export class RpcOperationResponse extends DocumentElement {
20
20
  this.payloadType = this.owner.node.getDataType('any');
21
21
  if (initArgs?.keyType) {
22
22
  this.keyType =
23
- initArgs?.keyType instanceof DataType ? initArgs.keyType : this.owner.node.getDataType(initArgs.keyType);
23
+ initArgs?.keyType instanceof DataType
24
+ ? initArgs.keyType
25
+ : this.owner.node.getDataType(initArgs.keyType);
24
26
  }
25
27
  }
26
28
  findHeader(paramName) {
@@ -40,8 +42,14 @@ export class RpcOperationResponse extends DocumentElement {
40
42
  const out = omitUndefined({
41
43
  description: this.description,
42
44
  channel: this.channel,
43
- payloadType: this.payloadType.name ? this.payloadType.name : this.payloadType.toJSON(),
44
- keyType: this.keyType ? (this.keyType.name ? this.keyType.name : this.keyType.toJSON()) : undefined,
45
+ payloadType: this.payloadType.name
46
+ ? this.payloadType.name
47
+ : this.payloadType.toJSON(),
48
+ keyType: this.keyType
49
+ ? this.keyType.name
50
+ ? this.keyType.name
51
+ : this.keyType.toJSON()
52
+ : undefined,
45
53
  });
46
54
  if (this.headers.length) {
47
55
  out.headers = [];
@@ -5,7 +5,7 @@ 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 { RpcOperationDecoratorFactory } from '../decorators/rpc-operation.decorator.js';
8
+ import { RpcOperationDecoratorFactory, } from '../decorators/rpc-operation.decorator.js';
9
9
  /**
10
10
  * RpcOperation
11
11
  */
@@ -35,7 +35,9 @@ export const RpcOperation = function (...args) {
35
35
  }
36
36
  if (initArgs?.keyType) {
37
37
  _this.keyType =
38
- initArgs?.keyType instanceof DataType ? initArgs.keyType : _this.owner.node.getDataType(initArgs.keyType);
38
+ initArgs?.keyType instanceof DataType
39
+ ? initArgs.keyType
40
+ : _this.owner.node.getDataType(initArgs.keyType);
39
41
  }
40
42
  };
41
43
  /**
@@ -60,8 +62,14 @@ class RpcOperationClass extends DocumentElement {
60
62
  kind: OpraSchema.RpcOperation.Kind,
61
63
  description: this.description,
62
64
  channel: this.channel,
63
- payloadType: this.payloadType.name ? this.payloadType.name : this.payloadType.toJSON(),
64
- keyType: this.keyType ? (this.keyType.name ? this.keyType.name : this.keyType.toJSON()) : undefined,
65
+ payloadType: this.payloadType.name
66
+ ? this.payloadType.name
67
+ : this.payloadType.toJSON(),
68
+ keyType: this.keyType
69
+ ? this.keyType.name
70
+ ? this.keyType.name
71
+ : this.keyType.toJSON()
72
+ : undefined,
65
73
  response: this.response?.toJSON(),
66
74
  });
67
75
  if (this.headers.length) {
@@ -4,12 +4,12 @@ export function parseRegExp(str, options) {
4
4
  const s = str.substring(1, i);
5
5
  let flags = str.substring(i + 1);
6
6
  if (options?.includeFlags) {
7
- for (const f of options?.includeFlags)
7
+ for (const f of options.includeFlags)
8
8
  if (!flags.includes(f))
9
9
  flags += f;
10
10
  }
11
11
  if (options?.excludeFlags) {
12
- for (const f of options?.excludeFlags)
12
+ for (const f of options.excludeFlags)
13
13
  flags.replace(f, '');
14
14
  }
15
15
  return new RegExp(s, flags);
@@ -35,7 +35,9 @@ export class OpraException extends Error {
35
35
  system: this.system,
36
36
  code: this.code,
37
37
  details: this.details,
38
- stack: env === 'dev' || env === 'development' || env === 'test' ? this.stack?.split('\n') : undefined,
38
+ stack: env === 'dev' || env === 'development' || env === 'test'
39
+ ? this.stack?.split('\n')
40
+ : undefined,
39
41
  }, true);
40
42
  }
41
43
  init(issue) {