@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
@@ -16,18 +16,26 @@ let FilterType = class FilterType {
16
16
  const dataType = properties.dataType
17
17
  ? element.node.getComplexType(properties.dataType)
18
18
  : element.node.getComplexType('object');
19
- const rules = properties.rules ? new filter_rules_js_1.FilterRules(properties.rules) : undefined;
19
+ const rules = properties.rules
20
+ ? new filter_rules_js_1.FilterRules(properties.rules)
21
+ : undefined;
20
22
  return decodeFilter(dataType, rules);
21
23
  }
22
24
  [constants_js_1.ENCODER]() {
23
25
  return encodeFilter;
24
26
  }
25
- toJSON(properties, element) {
27
+ toJSON(properties, element, options) {
26
28
  const dataType = properties.dataType
27
29
  ? element.node.getComplexType(properties.dataType)
28
30
  : element.node.getComplexType('object');
31
+ const typeName = dataType
32
+ ? element.node.getDataTypeNameWithNs(dataType)
33
+ : undefined;
34
+ if (options?.scopes && !dataType.inScope(options?.scopes))
35
+ throw new TypeError(`Data type ${typeName ? '(' + typeName + ')' : ''} ` +
36
+ `is not in required scope(s) [${options.scopes}`);
29
37
  return {
30
- dataType: dataType.name ? dataType.name : dataType.toJSON(),
38
+ dataType: typeName ? typeName : dataType.toJSON(options),
31
39
  rules: properties.rules,
32
40
  };
33
41
  }
@@ -48,6 +56,7 @@ tslib_1.__decorate([
48
56
  ], FilterType.prototype, "rules", void 0);
49
57
  exports.FilterType = FilterType = tslib_1.__decorate([
50
58
  (0, simple_type_js_1.SimpleType)({
59
+ name: 'filter',
51
60
  description: 'A query filter',
52
61
  nameMappings: {
53
62
  js: 'object',
@@ -56,12 +65,12 @@ exports.FilterType = FilterType = tslib_1.__decorate([
56
65
  }),
57
66
  tslib_1.__metadata("design:paramtypes", [Object])
58
67
  ], FilterType);
59
- const decodeFilter = (dataType, rules) => (0, valgen_1.validator)('decodeFilter', (input, context, _this) => {
68
+ const decodeFilter = (dataType, rules, element) => (0, valgen_1.validator)('decodeFilter', (input, context, _this) => {
60
69
  if (typeof input === 'string') {
61
70
  try {
62
71
  const filter = index_js_1.OpraFilter.parse(input);
63
72
  if (rules)
64
- return rules.normalizeFilter(filter, dataType);
73
+ return rules.normalizeFilter(filter, dataType, element);
65
74
  return filter;
66
75
  }
67
76
  catch (e) {
@@ -20,6 +20,7 @@ let ObjectIdType = class ObjectIdType {
20
20
  exports.ObjectIdType = ObjectIdType;
21
21
  exports.ObjectIdType = ObjectIdType = tslib_1.__decorate([
22
22
  (0, simple_type_js_1.SimpleType)({
23
+ name: 'ObjectId',
23
24
  description: 'A MongoDB ObjectID value',
24
25
  nameMappings: {
25
26
  js: 'object',
@@ -41,6 +41,7 @@ tslib_1.__decorate([
41
41
  ], OperationResult.prototype, "errors", void 0);
42
42
  exports.OperationResult = OperationResult = tslib_1.__decorate([
43
43
  (0, complex_type_js_1.ComplexType)({
44
+ name: 'OperationResult',
44
45
  description: 'Operation result',
45
46
  }),
46
47
  tslib_1.__metadata("design:paramtypes", [Object])
@@ -42,6 +42,7 @@ tslib_1.__decorate([
42
42
  ], TimeType.prototype, "maxValue", void 0);
43
43
  exports.TimeType = TimeType = tslib_1.__decorate([
44
44
  ((0, simple_type_js_1.SimpleType)({
45
+ name: 'time',
45
46
  description: 'Time string in 24h format',
46
47
  nameMappings: {
47
48
  js: 'string',
@@ -20,6 +20,7 @@ let UrlType = class UrlType {
20
20
  exports.UrlType = UrlType;
21
21
  exports.UrlType = UrlType = tslib_1.__decorate([
22
22
  ((0, simple_type_js_1.SimpleType)({
23
+ name: 'url',
23
24
  description: 'A Uniform Resource Identifier Reference (RFC 3986 icon) value',
24
25
  nameMappings: {
25
26
  js: 'string',
@@ -26,6 +26,7 @@ tslib_1.__decorate([
26
26
  ], UuidType.prototype, "version", void 0);
27
27
  exports.UuidType = UuidType = tslib_1.__decorate([
28
28
  (0, simple_type_js_1.SimpleType)({
29
+ name: 'uuid',
29
30
  description: 'A Universal Unique Identifier (UUID) value',
30
31
  nameMappings: {
31
32
  js: 'string',
@@ -43,16 +43,22 @@ exports.MappedType = function (...args) {
43
43
  }
44
44
  /** Copy fields from base */
45
45
  const isInheritedPredicate = (0, get_is_inherited_predicate_fn_js_1.getIsInheritedPredicateFn)(_this.pick, _this.omit);
46
- const partial = Array.isArray(_this.partial) ? _this.partial.map(x => x.toLowerCase()) : _this.partial;
47
- const required = Array.isArray(_this.required) ? _this.required.map(x => x.toLowerCase()) : _this.required;
46
+ const partial = Array.isArray(_this.partial)
47
+ ? _this.partial.map(x => x.toLowerCase())
48
+ : _this.partial;
49
+ const required = Array.isArray(_this.required)
50
+ ? _this.required.map(x => x.toLowerCase())
51
+ : _this.required;
48
52
  for (const [k, v] of _this.base.fields.entries()) {
49
53
  if (!isInheritedPredicate(k))
50
54
  continue;
51
55
  const meta = { ...v };
52
- if (partial === true || (Array.isArray(partial) && partial.includes(v.name.toLowerCase()))) {
56
+ if (partial === true ||
57
+ (Array.isArray(partial) && partial.includes(v.name.toLowerCase()))) {
53
58
  meta.required = false;
54
59
  }
55
- else if (required === true || (Array.isArray(required) && required.includes(v.name.toLowerCase()))) {
60
+ else if (required === true ||
61
+ (Array.isArray(required) && required.includes(v.name.toLowerCase()))) {
56
62
  meta.required = true;
57
63
  }
58
64
  const field = new api_field_js_1.ApiField(this, meta);
@@ -60,7 +66,8 @@ exports.MappedType = function (...args) {
60
66
  }
61
67
  if (!_this.pick ||
62
68
  _this.base.additionalFields === false ||
63
- (Array.isArray(_this.base.additionalFields) && _this.base.additionalFields?.[0] === 'error')) {
69
+ (Array.isArray(_this.base.additionalFields) &&
70
+ _this.base.additionalFields?.[0] === 'error')) {
64
71
  _this.additionalFields = _this.base.additionalFields;
65
72
  }
66
73
  if (initArgs.base.keyField && isInheritedPredicate(initArgs.base.keyField))
@@ -81,11 +88,16 @@ class MappedTypeClass extends complex_type_base_js_1.ComplexTypeBase {
81
88
  return true;
82
89
  return !!this.base?.extendsFrom(baseType);
83
90
  }
84
- toJSON() {
85
- const baseName = this.base ? this.node.getDataTypeNameWithNs(this.base) : undefined;
91
+ toJSON(options) {
92
+ const baseName = this.base
93
+ ? this.node.getDataTypeNameWithNs(this.base)
94
+ : undefined;
95
+ if (options?.scopes && !this.base?.inScope(options?.scopes))
96
+ throw new TypeError(`Base type ${baseName ? '(' + baseName + ')' : ''} of ${this.name ? +this.name : 'embedded'} type ` +
97
+ `is not in required scope(s) [${options.scopes}`);
86
98
  return (0, objects_1.omitUndefined)({
87
- ...complex_type_base_js_1.ComplexTypeBase.prototype.toJSON.call(this),
88
- base: baseName ? baseName : this.base.toJSON(),
99
+ ...complex_type_base_js_1.ComplexTypeBase.prototype.toJSON.call(this, options),
100
+ base: baseName ? baseName : this.base.toJSON(options),
89
101
  kind: this.kind,
90
102
  pick: this.pick,
91
103
  omit: this.omit,
@@ -57,13 +57,16 @@ class MixinTypeClass extends complex_type_base_js_1.ComplexTypeBase {
57
57
  }
58
58
  return false;
59
59
  }
60
- toJSON() {
60
+ toJSON(options) {
61
61
  return (0, objects_1.omitUndefined)({
62
62
  ...complex_type_base_js_1.ComplexTypeBase.prototype.toJSON.call(this),
63
63
  kind: this.kind,
64
- types: this.types.map(t => {
65
- const baseName = this.node.getDataTypeNameWithNs(t);
66
- return baseName ? baseName : t.toJSON();
64
+ types: this.types.map(base => {
65
+ const baseName = this.node.getDataTypeNameWithNs(base);
66
+ if (options?.scopes && !base?.inScope(options?.scopes))
67
+ throw new TypeError(`Base type ${baseName ? '(' + baseName + ')' : ''} of ${this.name ? +this.name : 'embedded'} type ` +
68
+ `is not in required scope(s) [${options.scopes}`);
69
+ return baseName ? baseName : base.toJSON(options);
67
70
  }),
68
71
  });
69
72
  }
@@ -76,7 +79,9 @@ exports.MixinType[constants_js_1.DECORATOR] = MixinTypeFactory;
76
79
  function MixinTypeFactory(...args) {
77
80
  // Filter undefined items
78
81
  const clasRefs = args.filter(x => typeof x === 'function');
79
- const options = typeof args[args.length - 1] === 'object' ? args[args.length - 1] : undefined;
82
+ const options = typeof args[args.length - 1] === 'object'
83
+ ? args[args.length - 1]
84
+ : undefined;
80
85
  if (!clasRefs.length)
81
86
  throw new TypeError('No Class has been provided');
82
87
  if (clasRefs.length === 1)
@@ -20,6 +20,7 @@ let AnyType = class AnyType {
20
20
  exports.AnyType = AnyType;
21
21
  exports.AnyType = AnyType = tslib_1.__decorate([
22
22
  (0, simple_type_js_1.SimpleType)({
23
+ name: 'any',
23
24
  description: 'Represents any value',
24
25
  }),
25
26
  tslib_1.__metadata("design:paramtypes", [Object])
@@ -16,7 +16,9 @@ let BigintType = class BigintType extends number_type_js_1.NumberType {
16
16
  x.push(valgen_1.vg.isGte(properties.minValue));
17
17
  if (properties.maxValue)
18
18
  x.push(valgen_1.vg.isLte(properties.maxValue));
19
- return x.length > 0 ? valgen_1.vg.pipe([valgen_1.toBigint, ...x], { returnIndex: 0 }) : valgen_1.toBigint;
19
+ return x.length > 0
20
+ ? valgen_1.vg.pipe([valgen_1.toBigint, ...x], { returnIndex: 0 })
21
+ : valgen_1.toBigint;
20
22
  }
21
23
  [constants_js_1.ENCODER](properties) {
22
24
  return this[constants_js_1.DECODER](properties);
@@ -25,6 +27,7 @@ let BigintType = class BigintType extends number_type_js_1.NumberType {
25
27
  exports.BigintType = BigintType;
26
28
  exports.BigintType = BigintType = tslib_1.__decorate([
27
29
  (0, simple_type_js_1.SimpleType)({
30
+ name: 'bigint',
28
31
  description: 'BigInt number',
29
32
  nameMappings: {
30
33
  js: 'bigint',
@@ -20,6 +20,7 @@ let BooleanType = class BooleanType {
20
20
  exports.BooleanType = BooleanType;
21
21
  exports.BooleanType = BooleanType = tslib_1.__decorate([
22
22
  (0, simple_type_js_1.SimpleType)({
23
+ name: 'boolean',
23
24
  description: 'Simple true/false value',
24
25
  nameMappings: {
25
26
  js: 'boolean',
@@ -16,7 +16,9 @@ let IntegerType = class IntegerType extends number_type_js_1.NumberType {
16
16
  x.push(valgen_1.vg.isGte(properties.minValue));
17
17
  if (properties.maxValue)
18
18
  x.push(valgen_1.vg.isLte(properties.maxValue));
19
- return x.length > 0 ? valgen_1.vg.pipe([valgen_1.toInteger, ...x], { returnIndex: 0 }) : valgen_1.toInteger;
19
+ return x.length > 0
20
+ ? valgen_1.vg.pipe([valgen_1.toInteger, ...x], { returnIndex: 0 })
21
+ : valgen_1.toInteger;
20
22
  }
21
23
  [constants_js_1.ENCODER](properties) {
22
24
  return this[constants_js_1.DECODER](properties);
@@ -25,6 +27,7 @@ let IntegerType = class IntegerType extends number_type_js_1.NumberType {
25
27
  exports.IntegerType = IntegerType;
26
28
  exports.IntegerType = IntegerType = tslib_1.__decorate([
27
29
  (0, simple_type_js_1.SimpleType)({
30
+ name: 'integer',
28
31
  description: 'An integer number',
29
32
  nameMappings: {
30
33
  js: 'number',
@@ -20,6 +20,7 @@ let NullType = class NullType {
20
20
  exports.NullType = NullType;
21
21
  exports.NullType = NullType = tslib_1.__decorate([
22
22
  (0, simple_type_js_1.SimpleType)({
23
+ name: 'null',
23
24
  description: 'A Null value',
24
25
  nameMappings: {
25
26
  js: 'null',
@@ -16,7 +16,9 @@ let NumberType = class NumberType {
16
16
  x.push(valgen_1.vg.isGte(properties.minValue));
17
17
  if (properties.maxValue)
18
18
  x.push(valgen_1.vg.isLte(properties.maxValue));
19
- return x.length > 0 ? valgen_1.vg.pipe([valgen_1.toNumber, ...x], { returnIndex: 0 }) : valgen_1.toNumber;
19
+ return x.length > 0
20
+ ? valgen_1.vg.pipe([valgen_1.toNumber, ...x], { returnIndex: 0 })
21
+ : valgen_1.toNumber;
20
22
  }
21
23
  [constants_js_1.ENCODER](properties) {
22
24
  return this[constants_js_1.DECODER](properties);
@@ -37,6 +39,7 @@ tslib_1.__decorate([
37
39
  ], NumberType.prototype, "maxValue", void 0);
38
40
  exports.NumberType = NumberType = tslib_1.__decorate([
39
41
  (0, simple_type_js_1.SimpleType)({
42
+ name: 'number',
40
43
  description: 'Both Integer as well as Floating-Point numbers',
41
44
  nameMappings: {
42
45
  js: 'number',
@@ -24,7 +24,9 @@ let StringType = class StringType {
24
24
  x.push(valgen_1.vg.lengthMin(properties.minLength));
25
25
  if (properties.maxLength)
26
26
  x.push(valgen_1.vg.lengthMax(properties.maxLength));
27
- return x.length > 0 ? valgen_1.vg.pipe([valgen_1.toString, ...x], { returnIndex: 0 }) : valgen_1.toString;
27
+ return x.length > 0
28
+ ? valgen_1.vg.pipe([valgen_1.toString, ...x], { returnIndex: 0 })
29
+ : valgen_1.toString;
28
30
  }
29
31
  [constants_js_1.ENCODER](properties) {
30
32
  return this[constants_js_1.DECODER](properties);
@@ -57,6 +59,7 @@ tslib_1.__decorate([
57
59
  ], StringType.prototype, "maxLength", void 0);
58
60
  exports.StringType = StringType = tslib_1.__decorate([
59
61
  (0, simple_type_js_1.SimpleType)({
62
+ name: 'string',
60
63
  description: 'A sequence of characters',
61
64
  nameMappings: {
62
65
  js: 'string',
@@ -31,7 +31,10 @@ exports.SimpleType = function (...args) {
31
31
  }
32
32
  _this.properties = initArgs.properties;
33
33
  _this.ownNameMappings = { ...initArgs.nameMappings };
34
- _this.nameMappings = { ..._this.base?.nameMappings, ...initArgs.nameMappings };
34
+ _this.nameMappings = {
35
+ ..._this.base?.nameMappings,
36
+ ...initArgs.nameMappings,
37
+ };
35
38
  _this.ownAttributes = (0, index_js_1.cloneObject)(initArgs.attributes || {});
36
39
  _this.attributes = _this.base ? (0, index_js_1.cloneObject)(_this.base.attributes) : {};
37
40
  if (_this.ownAttributes) {
@@ -80,18 +83,27 @@ class SimpleTypeClass extends data_type_js_1.DataType {
80
83
  }
81
84
  return valgen_1.isAny;
82
85
  }
83
- toJSON() {
86
+ toJSON(options) {
84
87
  const attributes = (0, objects_1.omitUndefined)(this.ownAttributes);
85
88
  let properties;
86
89
  if (this.properties && typeof this.properties.toJSON === 'function') {
87
- properties = this.properties.toJSON(this.properties, this.owner);
90
+ properties = this.properties.toJSON(this.properties, this.owner, options);
88
91
  }
89
92
  else
90
93
  properties = this.properties ? (0, index_js_1.cloneObject)(this.properties) : {};
91
- const baseName = this.base ? this.node.getDataTypeNameWithNs(this.base) : undefined;
94
+ const baseName = this.base
95
+ ? this.node.getDataTypeNameWithNs(this.base)
96
+ : undefined;
97
+ if (options?.scopes && !this.base?.inScope(options?.scopes))
98
+ throw new TypeError(`Base type ${baseName ? '(' + baseName + ')' : ''} of ${this.name ? +this.name : 'embedded'} type ` +
99
+ `is not in required scope(s) [${options.scopes}`);
92
100
  const out = (0, objects_1.omitUndefined)({
93
101
  ...data_type_js_1.DataType.prototype.toJSON.apply(this),
94
- base: this.base ? (baseName ? baseName : this.base.toJSON()) : undefined,
102
+ base: this.base
103
+ ? baseName
104
+ ? baseName
105
+ : this.base.toJSON(options)
106
+ : undefined,
95
107
  attributes: attributes && Object.keys(attributes).length ? attributes : undefined,
96
108
  properties: Object.keys(properties).length ? properties : undefined,
97
109
  });
@@ -8,7 +8,9 @@ const mapped_type_js_1 = require("../mapped-type.js");
8
8
  const get_is_inherited_predicate_fn_js_1 = require("./get-is-inherited-predicate-fn.js");
9
9
  function createMappedClass(source, config, options) {
10
10
  const isInheritedPredicate = (0, get_is_inherited_predicate_fn_js_1.getIsInheritedPredicateFn)(config.pick, config.omit);
11
- const sourceName = typeof source === 'string' ? source.charAt(0).toUpperCase() + source.substring(1) : source.name;
11
+ const sourceName = typeof source === 'string'
12
+ ? source.charAt(0).toUpperCase() + source.substring(1)
13
+ : source.name;
12
14
  const className = options?.name || sourceName + 'Mapped';
13
15
  const MappedClass = {
14
16
  [className]: class {
@@ -7,7 +7,8 @@ function ApiFieldDecorator(options) {
7
7
  return function (target, propertyKey) {
8
8
  if (typeof propertyKey !== 'string')
9
9
  throw new TypeError(`Symbol properties can't be used as a field`);
10
- const metadata = Reflect.getOwnMetadata(constants_js_1.DATATYPE_METADATA, target.constructor) || {};
10
+ const metadata = Reflect.getOwnMetadata(constants_js_1.DATATYPE_METADATA, target.constructor) ||
11
+ {};
11
12
  metadata.kind = index_js_1.OpraSchema.ComplexType.Kind;
12
13
  metadata.fields = metadata.fields || {};
13
14
  const designType = Reflect.getMetadata('design:type', target, propertyKey);
@@ -14,7 +14,7 @@ function ComplexTypeDecorator(options) {
14
14
  name = options.name;
15
15
  }
16
16
  else {
17
- name = target.name.match(constants_js_1.EXTRACT_TYPENAME_PATTERN)?.[1] || target.name;
17
+ name = target.name;
18
18
  }
19
19
  }
20
20
  let metadata = Reflect.getOwnMetadata(constants_js_1.DATATYPE_METADATA, target);
@@ -25,7 +25,13 @@ function HttpControllerDecoratorFactory(options) {
25
25
  kind: index_js_1.OpraSchema.HttpController.Kind,
26
26
  name,
27
27
  path: name,
28
- ...(0, objects_1.omit)(options, ['kind', 'name', 'instance', 'endpoints', 'key']),
28
+ ...(0, objects_1.omit)(options, [
29
+ 'kind',
30
+ 'name',
31
+ 'instance',
32
+ 'endpoints',
33
+ 'key',
34
+ ]),
29
35
  }, { deep: true });
30
36
  Reflect.defineMetadata(constants_js_1.HTTP_CONTROLLER_METADATA, metadata, target);
31
37
  for (const fn of decoratorChain)
@@ -53,7 +53,8 @@ http_operation_js_1.HttpOperation.Entity.Create = function (arg0, arg1) {
53
53
  contentType: index_js_1.MimeTypes.opra_response_json,
54
54
  });
55
55
  decoratorChain.push((operationMeta) => {
56
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
56
+ const compositionOptions = (operationMeta.compositionOptions =
57
+ operationMeta.compositionOptions || {});
57
58
  compositionOptions.type = getDataTypeName(args.type);
58
59
  });
59
60
  return decorator;
@@ -110,7 +111,8 @@ http_operation_js_1.HttpOperation.Entity.Delete = function (arg0, arg1) {
110
111
  return decorator;
111
112
  };
112
113
  decoratorChain.push((operationMeta) => {
113
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
114
+ const compositionOptions = (operationMeta.compositionOptions =
115
+ operationMeta.compositionOptions || {});
114
116
  compositionOptions.type = getDataTypeName(args.type);
115
117
  });
116
118
  return decorator;
@@ -149,7 +151,8 @@ http_operation_js_1.HttpOperation.Entity.DeleteMany = function (arg0, arg1) {
149
151
  description: 'Determines filter fields',
150
152
  });
151
153
  decoratorChain.push((operationMeta) => {
152
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
154
+ const compositionOptions = (operationMeta.compositionOptions =
155
+ operationMeta.compositionOptions || {});
153
156
  compositionOptions.type = getDataTypeName(args.type);
154
157
  });
155
158
  decorator.Filter = (field, operators, description) => {
@@ -228,7 +231,8 @@ http_operation_js_1.HttpOperation.Entity.FindMany = function (arg0, arg1) {
228
231
  arraySeparator: ',',
229
232
  });
230
233
  decoratorChain.push((operationMeta) => {
231
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
234
+ const compositionOptions = (operationMeta.compositionOptions =
235
+ operationMeta.compositionOptions || {});
232
236
  compositionOptions.type = getDataTypeName(args.type);
233
237
  if (args.defaultLimit)
234
238
  compositionOptions.defaultLimit = args.defaultLimit;
@@ -239,14 +243,16 @@ http_operation_js_1.HttpOperation.Entity.FindMany = function (arg0, arg1) {
239
243
  });
240
244
  decorator.DefaultSort = (...fields) => {
241
245
  decoratorChain.push((operationMeta) => {
242
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
246
+ const compositionOptions = (operationMeta.compositionOptions =
247
+ operationMeta.compositionOptions || {});
243
248
  compositionOptions.defaultSort = fields;
244
249
  });
245
250
  return decorator;
246
251
  };
247
252
  decorator.SortFields = (...fields) => {
248
253
  decoratorChain.push((operationMeta) => {
249
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
254
+ const compositionOptions = (operationMeta.compositionOptions =
255
+ operationMeta.compositionOptions || {});
250
256
  compositionOptions.sortFields = fields;
251
257
  });
252
258
  return decorator;
@@ -326,7 +332,8 @@ http_operation_js_1.HttpOperation.Entity.Get = function (arg0, arg1) {
326
332
  return decorator;
327
333
  };
328
334
  decoratorChain.push((operationMeta) => {
329
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
335
+ const compositionOptions = (operationMeta.compositionOptions =
336
+ operationMeta.compositionOptions || {});
330
337
  compositionOptions.type = getDataTypeName(args.type);
331
338
  });
332
339
  return decorator;
@@ -397,7 +404,8 @@ http_operation_js_1.HttpOperation.Entity.Replace = function (arg0, arg1) {
397
404
  return decorator;
398
405
  };
399
406
  decoratorChain.push((operationMeta) => {
400
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
407
+ const compositionOptions = (operationMeta.compositionOptions =
408
+ operationMeta.compositionOptions || {});
401
409
  compositionOptions.type = getDataTypeName(args.type);
402
410
  });
403
411
  return decorator;
@@ -444,7 +452,8 @@ http_operation_js_1.HttpOperation.Entity.UpdateMany = function (arg0, arg1) {
444
452
  description: 'Determines filter fields',
445
453
  });
446
454
  decoratorChain.push((operationMeta) => {
447
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
455
+ const compositionOptions = (operationMeta.compositionOptions =
456
+ operationMeta.compositionOptions || {});
448
457
  compositionOptions.type = getDataTypeName(args.type);
449
458
  });
450
459
  decorator.Filter = (field, operators, description) => {
@@ -537,7 +546,8 @@ http_operation_js_1.HttpOperation.Entity.Update = function (arg0, arg1) {
537
546
  return decorator;
538
547
  };
539
548
  decoratorChain.push((operationMeta) => {
540
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
549
+ const compositionOptions = (operationMeta.compositionOptions =
550
+ operationMeta.compositionOptions || {});
541
551
  compositionOptions.type = getDataTypeName(args.type);
542
552
  });
543
553
  decorator.Filter = (field, operators, description) => {
@@ -15,8 +15,7 @@ function HttpOperationDecoratorFactory(decoratorChain, options) {
15
15
  ...options,
16
16
  kind: index_js_2.OpraSchema.HttpOperation.Kind,
17
17
  };
18
- const controllerMetadata = (Reflect.getOwnMetadata(constants_js_1.HTTP_CONTROLLER_METADATA, target.constructor) ||
19
- {});
18
+ const controllerMetadata = (Reflect.getOwnMetadata(constants_js_1.HTTP_CONTROLLER_METADATA, target.constructor) || {});
20
19
  controllerMetadata.operations = controllerMetadata.operations || {};
21
20
  controllerMetadata.operations[propertyKey] = operationMetadata;
22
21
  for (const fn of decoratorChain)
@@ -111,9 +110,13 @@ function HttpOperationDecoratorFactory(decoratorChain, options) {
111
110
  *
112
111
  */
113
112
  decorator.Response = (statusCode, responseOptions) => {
114
- const responseMeta = { ...responseOptions, statusCode };
113
+ const responseMeta = {
114
+ ...responseOptions,
115
+ statusCode,
116
+ };
115
117
  if (responseMeta.type) {
116
- responseMeta.contentType = responseMeta.contentType || index_js_1.MimeTypes.opra_response_json;
118
+ responseMeta.contentType =
119
+ responseMeta.contentType || index_js_1.MimeTypes.opra_response_json;
117
120
  responseMeta.contentEncoding = responseMeta.contentEncoding || 'utf-8';
118
121
  }
119
122
  if (responseMeta.contentType === index_js_1.MimeTypes.opra_response_json) {
@@ -132,8 +135,12 @@ function HttpOperationDecoratorFactory(decoratorChain, options) {
132
135
  contentMeta.contentEncoding = contentMeta.contentEncoding || 'utf-8';
133
136
  }
134
137
  decoratorChain.push((operationMetadata) => {
135
- operationMetadata.requestBody = operationMetadata.requestBody || { required: true, content: [] };
136
- operationMetadata.requestBody.content = operationMetadata.requestBody.content || [];
138
+ operationMetadata.requestBody = operationMetadata.requestBody || {
139
+ required: true,
140
+ content: [],
141
+ };
142
+ operationMetadata.requestBody.content =
143
+ operationMetadata.requestBody.content || [];
137
144
  operationMetadata.requestBody.content.push(contentMeta);
138
145
  });
139
146
  return decorator;
@@ -144,14 +151,19 @@ function HttpOperationDecoratorFactory(decoratorChain, options) {
144
151
  contentType: contentOpts?.contentType || 'multipart/form-data',
145
152
  };
146
153
  decoratorChain.push((operationMetadata) => {
147
- operationMetadata.requestBody = operationMetadata.requestBody || { required: true, content: [] };
148
- operationMetadata.requestBody.content = operationMetadata.requestBody.content || [];
154
+ operationMetadata.requestBody = operationMetadata.requestBody || {
155
+ required: true,
156
+ content: [],
157
+ };
158
+ operationMetadata.requestBody.content =
159
+ operationMetadata.requestBody.content || [];
149
160
  operationMetadata.requestBody.content.push(contentMetadata);
150
161
  });
151
162
  if (subInit) {
152
163
  const configScope = {
153
164
  Field(fieldName, opts) {
154
- contentMetadata.multipartFields = contentMetadata.multipartFields || [];
165
+ contentMetadata.multipartFields =
166
+ contentMetadata.multipartFields || [];
155
167
  contentMetadata.multipartFields.push({
156
168
  fieldName,
157
169
  fieldType: 'field',
@@ -160,7 +172,8 @@ function HttpOperationDecoratorFactory(decoratorChain, options) {
160
172
  return configScope;
161
173
  },
162
174
  File(fieldName, opts) {
163
- contentMetadata.multipartFields = contentMetadata.multipartFields || [];
175
+ contentMetadata.multipartFields =
176
+ contentMetadata.multipartFields || [];
164
177
  contentMetadata.multipartFields.push({
165
178
  fieldName,
166
179
  fieldType: 'file',
@@ -19,8 +19,7 @@ function RpcOperationDecoratorFactory(decoratorChain, payloadType, options) {
19
19
  payloadType,
20
20
  ...(0, objects_1.omit)(options, ['kind', 'payloadType']),
21
21
  };
22
- const controllerMetadata = (Reflect.getOwnMetadata(constants_js_1.RPC_CONTROLLER_METADATA, target.constructor) ||
23
- {});
22
+ const controllerMetadata = (Reflect.getOwnMetadata(constants_js_1.RPC_CONTROLLER_METADATA, target.constructor) || {});
24
23
  controllerMetadata.operations = controllerMetadata.operations || {};
25
24
  controllerMetadata.operations[propertyKey] = operationMetadata;
26
25
  for (const fn of decoratorChain)
@@ -18,7 +18,7 @@ function SimpleTypeDecoratorFactory(options) {
18
18
  name = options.name;
19
19
  }
20
20
  else {
21
- name = target.name.match(constants_js_1.EXTRACT_TYPENAME_PATTERN)?.[1] || target.name;
21
+ name = target.name;
22
22
  name = name.toLowerCase();
23
23
  }
24
24
  }
@@ -45,7 +45,8 @@ function AttributeDecoratorFactory(options) {
45
45
  return (target, propertyKey) => {
46
46
  if (typeof propertyKey !== 'string')
47
47
  throw new TypeError(`Symbol properties can't be decorated with Attribute`);
48
- const metadata = Reflect.getOwnMetadata(constants_js_1.DATATYPE_METADATA, target.constructor) || {};
48
+ const metadata = Reflect.getOwnMetadata(constants_js_1.DATATYPE_METADATA, target.constructor) ||
49
+ {};
49
50
  const designType = Reflect.getMetadata('design:type', target, propertyKey);
50
51
  let format = 'string';
51
52
  if (designType === Boolean)
@@ -25,9 +25,12 @@ class ApiDocumentFactory {
25
25
  */
26
26
  static async createDocument(schemaOrUrl, options) {
27
27
  const factory = new ApiDocumentFactory();
28
- const context = options instanceof document_init_context_js_1.DocumentInitContext ? options : new document_init_context_js_1.DocumentInitContext(options);
28
+ const context = options instanceof document_init_context_js_1.DocumentInitContext
29
+ ? options
30
+ : new document_init_context_js_1.DocumentInitContext(options);
29
31
  try {
30
32
  const document = new api_document_js_1.ApiDocument();
33
+ document.scopes = context.scopes;
31
34
  await factory.initDocument(document, context, schemaOrUrl);
32
35
  if (context.error.details.length)
33
36
  throw context.error;
@@ -113,12 +116,18 @@ class ApiDocumentFactory {
113
116
  if (init.api) {
114
117
  await context.enterAsync(`.api`, async () => {
115
118
  if (init.api && init.api.transport === 'http') {
116
- const api = await http_api_factory_js_1.HttpApiFactory.createApi(context, { ...init.api, owner: document });
119
+ const api = await http_api_factory_js_1.HttpApiFactory.createApi(context, {
120
+ ...init.api,
121
+ owner: document,
122
+ });
117
123
  if (api)
118
124
  document.api = api;
119
125
  }
120
126
  else if (init.api && init.api.transport === 'rpc') {
121
- const api = await rpc_api_factory_js_1.RpcApiFactory.createApi(context, { ...init.api, owner: document });
127
+ const api = await rpc_api_factory_js_1.RpcApiFactory.createApi(context, {
128
+ ...init.api,
129
+ owner: document,
130
+ });
122
131
  if (api)
123
132
  document.api = api;
124
133
  }