@opra/common 1.0.0-alpha.3 → 1.0.0-alpha.31

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 (187) hide show
  1. package/browser.js +6035 -5791
  2. package/cjs/document/api-document.js +11 -0
  3. package/cjs/document/common/api-base.js +1 -1
  4. package/cjs/document/common/document-element.js +4 -1
  5. package/cjs/document/data-type/api-field.js +12 -6
  6. package/cjs/document/data-type/complex-type-base.js +10 -3
  7. package/cjs/document/data-type/complex-type.js +6 -2
  8. package/cjs/document/data-type/data-type.js +2 -1
  9. package/cjs/document/data-type/enum-type.js +5 -2
  10. package/cjs/document/data-type/extended-types/base64.type.js +4 -0
  11. package/cjs/document/data-type/extended-types/date-string.type.js +6 -2
  12. package/cjs/document/data-type/extended-types/date-time-string.type.js +6 -2
  13. package/cjs/document/data-type/extended-types/date-time.type.js +6 -2
  14. package/cjs/document/data-type/extended-types/date.type.js +6 -2
  15. package/cjs/document/data-type/extended-types/email.type.js +6 -2
  16. package/cjs/document/data-type/extended-types/field-path.type.js +5 -3
  17. package/cjs/document/data-type/extended-types/filter.type.js +19 -17
  18. package/cjs/document/data-type/extended-types/object-id.type.js +4 -0
  19. package/cjs/document/data-type/extended-types/time.type.js +6 -2
  20. package/cjs/document/data-type/extended-types/url.type.js +6 -2
  21. package/cjs/document/data-type/extended-types/uuid.type.js +4 -0
  22. package/cjs/document/data-type/mapped-type.js +12 -5
  23. package/cjs/document/data-type/mixin-type.js +5 -1
  24. package/cjs/document/data-type/omit-type.js +7 -2
  25. package/cjs/document/data-type/partial-type.js +7 -2
  26. package/cjs/document/data-type/pick-type.js +1 -2
  27. package/cjs/document/data-type/primitive-types/bigint.type.js +4 -0
  28. package/cjs/document/data-type/primitive-types/boolean.type.js +4 -0
  29. package/cjs/document/data-type/primitive-types/integer.type.js +4 -0
  30. package/cjs/document/data-type/primitive-types/null.type.js +4 -0
  31. package/cjs/document/data-type/primitive-types/number.type.js +4 -0
  32. package/cjs/document/data-type/primitive-types/object.type.js +0 -3
  33. package/cjs/document/data-type/primitive-types/string.type.js +4 -0
  34. package/cjs/document/data-type/required-type.js +1 -2
  35. package/cjs/document/data-type/simple-type.js +17 -16
  36. package/cjs/document/data-type/utils/create-mapped-class.js +3 -3
  37. package/cjs/document/data-type/utils/get-is-inherited-predicate-fn.js +1 -2
  38. package/cjs/document/decorators/api-field-decorator.js +4 -6
  39. package/cjs/document/decorators/complex-type.decorator.js +1 -2
  40. package/cjs/document/decorators/http-controller.decorator.js +26 -2
  41. package/cjs/document/decorators/http-operation-entity.decorator.js +123 -93
  42. package/cjs/document/decorators/http-operation.decorator.js +12 -6
  43. package/cjs/document/decorators/simple-type.decorator.js +2 -3
  44. package/cjs/document/factory/api-document.factory.js +14 -11
  45. package/cjs/document/factory/data-type.factory.js +97 -56
  46. package/cjs/document/factory/http-api.factory.js +3 -1
  47. package/cjs/document/http/http-api.js +2 -3
  48. package/cjs/document/http/http-controller.js +26 -14
  49. package/cjs/document/http/http-media-type.js +21 -4
  50. package/cjs/document/http/http-operation-response.js +2 -2
  51. package/cjs/document/http/http-operation.js +28 -4
  52. package/cjs/document/http/http-parameter.js +4 -0
  53. package/cjs/document/http/http-request-body.js +0 -1
  54. package/cjs/document/http/http-status-range.js +6 -4
  55. package/cjs/document/index.js +5 -5
  56. package/cjs/document/utils/parse-regexp.util.js +1 -2
  57. package/cjs/document/utils/string-compare.util.js +1 -2
  58. package/cjs/exception/index.js +5 -5
  59. package/cjs/exception/opra-exception.js +1 -0
  60. package/cjs/filter/antlr/OpraFilterParser.js +28 -82
  61. package/cjs/filter/ast/index.js +1 -1
  62. package/cjs/filter/build.js +22 -25
  63. package/cjs/filter/filter-rules.js +4 -2
  64. package/cjs/filter/opra-filter.ns.js +2 -2
  65. package/cjs/filter/parse.js +2 -5
  66. package/cjs/filter/utils.js +2 -3
  67. package/cjs/helpers/function-utils.js +1 -2
  68. package/cjs/helpers/get-stack-filename.js +2 -3
  69. package/cjs/helpers/mixin-utils.js +4 -4
  70. package/cjs/helpers/monkey-patches.js +4 -2
  71. package/cjs/helpers/object-utils.js +5 -6
  72. package/cjs/helpers/parse-fields-projection.js +4 -6
  73. package/cjs/helpers/responsive-map.js +5 -4
  74. package/cjs/helpers/type-guards.js +10 -11
  75. package/cjs/i18n/i18n.js +4 -3
  76. package/cjs/i18n/index.js +1 -1
  77. package/cjs/i18n/string-utils.js +2 -3
  78. package/cjs/i18n/translate.js +1 -2
  79. package/cjs/index.js +1 -1
  80. package/cjs/schema/type-guards.js +7 -8
  81. package/esm/document/api-document.js +11 -0
  82. package/esm/document/common/api-base.js +1 -1
  83. package/esm/document/common/document-element.js +4 -1
  84. package/esm/document/data-type/api-field.js +12 -6
  85. package/esm/document/data-type/complex-type-base.js +10 -3
  86. package/esm/document/data-type/complex-type.js +6 -2
  87. package/esm/document/data-type/data-type.js +2 -1
  88. package/esm/document/data-type/enum-type.js +5 -2
  89. package/esm/document/data-type/extended-types/base64.type.js +4 -0
  90. package/esm/document/data-type/extended-types/date-string.type.js +6 -2
  91. package/esm/document/data-type/extended-types/date-time-string.type.js +6 -2
  92. package/esm/document/data-type/extended-types/date-time.type.js +6 -2
  93. package/esm/document/data-type/extended-types/date.type.js +6 -2
  94. package/esm/document/data-type/extended-types/email.type.js +6 -2
  95. package/esm/document/data-type/extended-types/field-path.type.js +5 -3
  96. package/esm/document/data-type/extended-types/filter.type.js +19 -17
  97. package/esm/document/data-type/extended-types/object-id.type.js +4 -0
  98. package/esm/document/data-type/extended-types/time.type.js +6 -2
  99. package/esm/document/data-type/extended-types/url.type.js +6 -2
  100. package/esm/document/data-type/extended-types/uuid.type.js +4 -0
  101. package/esm/document/data-type/mapped-type.js +12 -5
  102. package/esm/document/data-type/mixin-type.js +5 -1
  103. package/esm/document/data-type/omit-type.js +6 -0
  104. package/esm/document/data-type/partial-type.js +6 -0
  105. package/esm/document/data-type/primitive-types/bigint.type.js +4 -0
  106. package/esm/document/data-type/primitive-types/boolean.type.js +4 -0
  107. package/esm/document/data-type/primitive-types/integer.type.js +4 -0
  108. package/esm/document/data-type/primitive-types/null.type.js +4 -0
  109. package/esm/document/data-type/primitive-types/number.type.js +4 -0
  110. package/esm/document/data-type/primitive-types/object.type.js +0 -3
  111. package/esm/document/data-type/primitive-types/string.type.js +4 -0
  112. package/esm/document/data-type/simple-type.js +17 -16
  113. package/esm/document/data-type/utils/create-mapped-class.js +2 -1
  114. package/esm/document/decorators/api-field-decorator.js +1 -2
  115. package/esm/document/decorators/http-controller.decorator.js +25 -0
  116. package/esm/document/decorators/http-operation-entity.decorator.js +80 -50
  117. package/esm/document/decorators/http-operation.decorator.js +11 -4
  118. package/esm/document/factory/api-document.factory.js +14 -10
  119. package/esm/document/factory/data-type.factory.js +97 -56
  120. package/esm/document/factory/http-api.factory.js +3 -1
  121. package/esm/document/http/http-api.js +2 -3
  122. package/esm/document/http/http-controller.js +25 -14
  123. package/esm/document/http/http-media-type.js +20 -4
  124. package/esm/document/http/http-operation-response.js +2 -2
  125. package/esm/document/http/http-operation.js +27 -4
  126. package/esm/document/http/http-parameter.js +4 -0
  127. package/esm/document/http/http-request-body.js +0 -1
  128. package/esm/document/http/http-status-range.js +6 -4
  129. package/esm/document/index.js +5 -5
  130. package/esm/exception/index.js +5 -5
  131. package/esm/exception/opra-exception.js +1 -0
  132. package/esm/filter/antlr/OpraFilterParser.js +28 -82
  133. package/esm/filter/ast/index.js +1 -1
  134. package/esm/filter/build.js +1 -3
  135. package/esm/filter/filter-rules.js +4 -2
  136. package/esm/filter/opra-filter.ns.js +2 -2
  137. package/esm/filter/parse.js +1 -3
  138. package/esm/helpers/mixin-utils.js +2 -1
  139. package/esm/helpers/monkey-patches.js +4 -2
  140. package/esm/helpers/object-utils.js +2 -2
  141. package/esm/helpers/parse-fields-projection.js +1 -3
  142. package/esm/helpers/responsive-map.js +5 -4
  143. package/esm/i18n/i18n.js +4 -3
  144. package/esm/i18n/index.js +1 -1
  145. package/esm/index.js +1 -1
  146. package/package.json +12 -8
  147. package/types/document/api-document.d.ts +1 -0
  148. package/types/document/common/api-base.d.ts +1 -1
  149. package/types/document/common/document-element.d.ts +1 -0
  150. package/types/document/data-type/api-field.d.ts +12 -0
  151. package/types/document/data-type/complex-type-base.d.ts +1 -1
  152. package/types/document/data-type/complex-type.d.ts +1 -1
  153. package/types/document/data-type/data-type.d.ts +5 -2
  154. package/types/document/data-type/enum-type.d.ts +2 -2
  155. package/types/document/data-type/mapped-type.d.ts +3 -3
  156. package/types/document/data-type/mixin-type.d.ts +2 -2
  157. package/types/document/data-type/omit-type.d.ts +0 -6
  158. package/types/document/data-type/partial-type.d.ts +0 -6
  159. package/types/document/data-type/pick-type.d.ts +2 -2
  160. package/types/document/data-type/required-type.d.ts +7 -7
  161. package/types/document/data-type/simple-type.d.ts +4 -2
  162. package/types/document/decorators/http-controller.decorator.d.ts +1 -0
  163. package/types/document/decorators/http-operation-entity.decorator.d.ts +1 -0
  164. package/types/document/factory/data-type.factory.d.ts +5 -0
  165. package/types/document/http/http-api.d.ts +1 -1
  166. package/types/document/http/http-controller.d.ts +1 -0
  167. package/types/document/http/http-media-type.d.ts +2 -1
  168. package/types/document/http/http-operation.d.ts +5 -3
  169. package/types/document/http/http-parameter.d.ts +3 -2
  170. package/types/document/http/http-status-range.d.ts +2 -1
  171. package/types/document/index.d.ts +5 -5
  172. package/types/exception/index.d.ts +5 -5
  173. package/types/filter/ast/index.d.ts +1 -1
  174. package/types/filter/opra-filter.ns.d.ts +2 -2
  175. package/types/helpers/type-guards.d.ts +0 -2
  176. package/types/i18n/i18n.d.ts +21 -19
  177. package/types/index.d.ts +1 -1
  178. package/types/schema/data-type/data-type.interface.d.ts +1 -1
  179. package/types/schema/data-type/mapped-type.interface.d.ts +2 -2
  180. package/types/schema/data-type/simple-type.interface.d.ts +4 -0
  181. package/types/schema/data-type-container.interface.d.ts +1 -1
  182. package/types/schema/document.interface.d.ts +1 -1
  183. package/types/schema/http/http-controller.interface.d.ts +2 -2
  184. package/types/schema/http/http-media-type.interface.d.ts +1 -1
  185. package/types/schema/http/http-operation-response.interface.d.ts +2 -2
  186. package/types/schema/http/http-operation.interface.d.ts +8 -4
  187. package/types/schema/http/http-parameter.interface.d.ts +5 -1
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ObjectType = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const constants_js_1 = require("../../constants.js");
6
5
  const complex_type_js_1 = require("../complex-type.js");
7
6
  let ObjectType = class ObjectType {
8
7
  constructor(properties) {
@@ -19,5 +18,3 @@ exports.ObjectType = ObjectType = tslib_1.__decorate([
19
18
  }),
20
19
  tslib_1.__metadata("design:paramtypes", [Object])
21
20
  ], ObjectType);
22
- const metadata = Reflect.getMetadata(constants_js_1.DATATYPE_METADATA, ObjectType);
23
- metadata.ctor = Object;
@@ -58,6 +58,10 @@ tslib_1.__decorate([
58
58
  exports.StringType = StringType = tslib_1.__decorate([
59
59
  (0, simple_type_js_1.SimpleType)({
60
60
  description: 'A sequence of characters',
61
+ nameMappings: {
62
+ js: 'string',
63
+ json: 'string',
64
+ },
61
65
  }),
62
66
  tslib_1.__metadata("design:paramtypes", [Object])
63
67
  ], StringType);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RequiredType = void 0;
3
+ exports.RequiredType = RequiredType;
4
4
  const create_mapped_class_js_1 = require("./utils/create-mapped-class.js");
5
5
  /**
6
6
  *
@@ -10,4 +10,3 @@ function RequiredType(base, ...args) {
10
10
  const options = Array.isArray(args[0]) ? args[1] : args[0];
11
11
  return (0, create_mapped_class_js_1.createMappedClass)(base, { required: keys }, options);
12
12
  }
13
- exports.RequiredType = RequiredType;
@@ -23,11 +23,14 @@ exports.SimpleType = function (...args) {
23
23
  _this.kind = index_js_2.OpraSchema.SimpleType.Kind;
24
24
  if (initArgs.base) {
25
25
  // noinspection SuspiciousTypeOfGuard
26
- if (!(initArgs.base instanceof exports.SimpleType))
26
+ if (!(initArgs.base instanceof exports.SimpleType)) {
27
27
  throw new TypeError(`"${initArgs.base.kind}" can't be set as base for a "${this.kind}"`);
28
+ }
28
29
  _this.base = initArgs.base;
29
30
  }
30
31
  _this.properties = initArgs.properties;
32
+ _this.ownNameMappings = { ...initArgs.nameMappings };
33
+ _this.nameMappings = { ..._this.base?.nameMappings, ...initArgs.nameMappings };
31
34
  _this.ownAttributes = (0, index_js_1.cloneObject)(initArgs.attributes || {});
32
35
  _this.attributes = _this.base ? (0, index_js_1.cloneObject)(_this.base.attributes) : {};
33
36
  if (_this.ownAttributes) {
@@ -46,6 +49,8 @@ exports.SimpleType = function (...args) {
46
49
  */
47
50
  class SimpleTypeClass extends data_type_js_1.DataType {
48
51
  extendsFrom(baseType) {
52
+ if (!(baseType instanceof data_type_js_1.DataType))
53
+ baseType = this.node.getDataType(baseType);
49
54
  if (!(baseType instanceof exports.SimpleType))
50
55
  return false;
51
56
  if (baseType === this)
@@ -66,15 +71,13 @@ class SimpleTypeClass extends data_type_js_1.DataType {
66
71
  }
67
72
  return valgen_1.isAny;
68
73
  }
69
- else {
70
- let t = this;
71
- while (t) {
72
- if (t._generateEncoder)
73
- return t._generateEncoder(prop, options?.documentElement || this.owner);
74
- t = this.base;
75
- }
76
- return valgen_1.isAny;
74
+ let t = this;
75
+ while (t) {
76
+ if (t._generateEncoder)
77
+ return t._generateEncoder(prop, options?.documentElement || this.owner);
78
+ t = this.base;
77
79
  }
80
+ return valgen_1.isAny;
78
81
  }
79
82
  toJSON() {
80
83
  const attributes = (0, index_js_1.omitUndefined)(this.ownAttributes);
@@ -83,19 +86,17 @@ class SimpleTypeClass extends data_type_js_1.DataType {
83
86
  properties = this.properties.toJSON(this.properties, this.owner);
84
87
  }
85
88
  else
86
- properties = this.properties || {};
87
- properties = Object.keys(this.attributes).reduce((o, k) => {
88
- if (properties[k] !== undefined)
89
- o[k] = properties[k];
90
- return o;
91
- }, {});
89
+ properties = this.properties ? (0, index_js_1.cloneObject)(this.properties) : {};
92
90
  const baseName = this.base ? this.node.getDataTypeNameWithNs(this.base) : undefined;
93
- return (0, index_js_1.omitUndefined)({
91
+ const out = (0, index_js_1.omitUndefined)({
94
92
  ...data_type_js_1.DataType.prototype.toJSON.apply(this),
95
93
  base: this.base ? (baseName ? baseName : this.base.toJSON()) : undefined,
96
94
  attributes: attributes && Object.keys(attributes).length ? attributes : undefined,
97
95
  properties: Object.keys(properties).length ? properties : undefined,
98
96
  });
97
+ if (Object.keys(this.ownNameMappings).length)
98
+ out.nameMappings = { ...this.ownNameMappings };
99
+ return out;
99
100
  }
100
101
  }
101
102
  exports.SimpleType.prototype = SimpleTypeClass.prototype;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createMappedClass = void 0;
3
+ exports.createMappedClass = createMappedClass;
4
4
  const index_js_1 = require("../../../helpers/index.js");
5
5
  const index_js_2 = require("../../../schema/index.js");
6
6
  const constants_js_1 = require("../../constants.js");
@@ -26,8 +26,9 @@ function createMappedClass(source, config, options) {
26
26
  throw new TypeError(`Class "${source}" doesn't have datatype metadata information`);
27
27
  if (!(m.kind === index_js_2.OpraSchema.ComplexType.Kind ||
28
28
  m.kind === index_js_2.OpraSchema.MappedType.Kind ||
29
- m.kind === index_js_2.OpraSchema.MixinType.Kind))
29
+ m.kind === index_js_2.OpraSchema.MixinType.Kind)) {
30
30
  throw new TypeError(`Class "${source}" is not a ${index_js_2.OpraSchema.ComplexType.Kind}`);
31
+ }
31
32
  }
32
33
  const metadata = {
33
34
  ...options,
@@ -51,4 +52,3 @@ function createMappedClass(source, config, options) {
51
52
  }
52
53
  return MappedClass;
53
54
  }
54
- exports.createMappedClass = createMappedClass;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getIsInheritedPredicateFn = void 0;
3
+ exports.getIsInheritedPredicateFn = getIsInheritedPredicateFn;
4
4
  function getIsInheritedPredicateFn(pick, omit) {
5
5
  const pickKeys = pick?.map(x => String(x).toLowerCase());
6
6
  const omitKeys = omit?.map(x => String(x).toLowerCase());
@@ -12,4 +12,3 @@ function getIsInheritedPredicateFn(pick, omit) {
12
12
  return true;
13
13
  };
14
14
  }
15
- exports.getIsInheritedPredicateFn = getIsInheritedPredicateFn;
@@ -1,15 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiFieldDecorator = void 0;
4
- const index_js_1 = require("../../helpers/index.js");
5
- const index_js_2 = require("../../schema/index.js");
3
+ exports.ApiFieldDecorator = ApiFieldDecorator;
4
+ const index_js_1 = require("../../schema/index.js");
6
5
  const constants_js_1 = require("../constants.js");
7
6
  function ApiFieldDecorator(options) {
8
7
  return function (target, propertyKey) {
9
8
  if (typeof propertyKey !== 'string')
10
9
  throw new TypeError(`Symbol properties can't be used as a field`);
11
10
  const metadata = Reflect.getOwnMetadata(constants_js_1.DATATYPE_METADATA, target.constructor) || {};
12
- metadata.kind = index_js_2.OpraSchema.ComplexType.Kind;
11
+ metadata.kind = index_js_1.OpraSchema.ComplexType.Kind;
13
12
  metadata.fields = metadata.fields || {};
14
13
  const designType = Reflect.getMetadata('design:type', target, propertyKey);
15
14
  const elemMeta = (metadata.fields[propertyKey] = {
@@ -20,7 +19,6 @@ function ApiFieldDecorator(options) {
20
19
  }
21
20
  else
22
21
  elemMeta.type = elemMeta.type || designType;
23
- Reflect.defineMetadata(constants_js_1.DATATYPE_METADATA, (0, index_js_1.omitUndefined)(metadata), target.constructor);
22
+ Reflect.defineMetadata(constants_js_1.DATATYPE_METADATA, metadata, target.constructor);
24
23
  };
25
24
  }
26
- exports.ApiFieldDecorator = ApiFieldDecorator;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ComplexTypeDecorator = void 0;
3
+ exports.ComplexTypeDecorator = ComplexTypeDecorator;
4
4
  const tslib_1 = require("tslib");
5
5
  const lodash_omit_1 = tslib_1.__importDefault(require("lodash.omit"));
6
6
  const index_js_1 = require("../../schema/index.js");
@@ -30,4 +30,3 @@ function ComplexTypeDecorator(options) {
30
30
  Object.assign(metadata, (0, lodash_omit_1.default)(options, ['kind', 'name', 'base', 'fields']));
31
31
  };
32
32
  }
33
- exports.ComplexTypeDecorator = ComplexTypeDecorator;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpControllerDecoratorFactory = void 0;
3
+ exports.HttpControllerDecoratorFactory = HttpControllerDecoratorFactory;
4
4
  const tslib_1 = require("tslib");
5
5
  const lodash_omit_1 = tslib_1.__importDefault(require("lodash.omit"));
6
6
  const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
@@ -102,6 +102,31 @@ function HttpControllerDecoratorFactory(options) {
102
102
  });
103
103
  return decorator;
104
104
  };
105
+ /**
106
+ *
107
+ */
108
+ decorator.KeyParam = (name, arg1) => {
109
+ decoratorChain.push((meta) => {
110
+ if (!meta.path?.includes(':' + name))
111
+ meta.path = (meta.path || '') + '@:' + name;
112
+ const paramMeta = typeof arg1 === 'string' || typeof arg1 === 'function'
113
+ ? {
114
+ name,
115
+ location: 'path',
116
+ type: arg1,
117
+ keyParam: true,
118
+ }
119
+ : {
120
+ ...arg1,
121
+ name,
122
+ location: 'path',
123
+ keyParam: true,
124
+ };
125
+ meta.parameters = meta.parameters || [];
126
+ meta.parameters.push(paramMeta);
127
+ });
128
+ return decorator;
129
+ };
105
130
  /**
106
131
  *
107
132
  */
@@ -114,4 +139,3 @@ function HttpControllerDecoratorFactory(options) {
114
139
  };
115
140
  return decorator;
116
141
  }
117
- exports.HttpControllerDecoratorFactory = HttpControllerDecoratorFactory;
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const filter_rules_js_1 = require("../../filter/filter-rules.js");
4
- const index_js_1 = require("../../helpers/index.js");
5
- const index_js_2 = require("../../http/index.js");
4
+ const index_js_1 = require("../../http/index.js");
6
5
  const constants_js_1 = require("../constants.js");
7
- const index_js_3 = require("../data-type/extended-types/index.js");
8
- const index_js_4 = require("../data-type/primitive-types/index.js");
6
+ const index_js_2 = require("../data-type/extended-types/index.js");
7
+ const index_js_3 = require("../data-type/primitive-types/index.js");
9
8
  const http_operation_js_1 = require("../http/http-operation.js");
10
9
  const http_operation_decorator_js_1 = require("./http-operation.decorator.js");
11
10
  /** Implementation **/
@@ -22,20 +21,20 @@ http_operation_js_1.HttpOperation.Entity.Create = function (arg0, arg1) {
22
21
  args = { ...arg1, type: arg0 };
23
22
  /** Initialize the decorator and the chain */
24
23
  const decoratorChain = [];
25
- const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, (0, index_js_1.omitUndefined)({
26
- description: args.description,
24
+ const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, {
27
25
  method: 'POST',
26
+ ...args,
28
27
  composition: 'Entity.Create',
29
28
  requestBody: {
30
29
  immediateFetch: true,
31
30
  ...args.requestBody,
32
31
  required: true,
33
32
  },
34
- }));
33
+ });
35
34
  decorator
36
35
  .QueryParam('projection', {
37
36
  description: 'Determines fields projection',
38
- type: new index_js_3.FieldPathType({
37
+ type: new index_js_2.FieldPathType({
39
38
  dataType: args.type,
40
39
  allowSigns: 'each',
41
40
  }),
@@ -43,18 +42,16 @@ http_operation_js_1.HttpOperation.Entity.Create = function (arg0, arg1) {
43
42
  arraySeparator: ',',
44
43
  })
45
44
  .RequestContent(args.requestBody?.type || args.type)
46
- .Response(index_js_2.HttpStatusCode.CREATED, {
45
+ .Response(index_js_1.HttpStatusCode.CREATED, {
47
46
  description: 'Operation is successful. Returns OperationResult with "payload" field that contains the created resource.',
48
- contentType: index_js_2.MimeTypes.opra_response_json,
47
+ contentType: index_js_1.MimeTypes.opra_response_json,
49
48
  type: args.type,
50
49
  partial: 'deep',
51
50
  })
52
- .Response(index_js_2.HttpStatusCode.UNPROCESSABLE_ENTITY, {
51
+ .Response(index_js_1.HttpStatusCode.UNPROCESSABLE_ENTITY, {
53
52
  description: 'The request was well-formed but was unable to process operation due to one or many errors.',
54
- contentType: index_js_2.MimeTypes.opra_response_json,
53
+ contentType: index_js_1.MimeTypes.opra_response_json,
55
54
  });
56
- if (typeof args.type === 'function')
57
- decorator.UseType(args.type);
58
55
  decoratorChain.push((operationMeta) => {
59
56
  const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
60
57
  compositionOptions.type = getDataTypeName(args.type);
@@ -73,31 +70,42 @@ http_operation_js_1.HttpOperation.Entity.Delete = function (arg0, arg1) {
73
70
  args = { ...arg1, type: arg0 };
74
71
  /** Initialize the decorator and the chain */
75
72
  const decoratorChain = [];
76
- const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, (0, index_js_1.omitUndefined)({
77
- description: args.description,
73
+ const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, {
78
74
  method: 'DELETE',
75
+ ...args,
79
76
  composition: 'Entity.Delete',
80
- }));
77
+ });
81
78
  decorator
82
- .Response(index_js_2.HttpStatusCode.OK, {
79
+ .Response(index_js_1.HttpStatusCode.OK, {
83
80
  description: 'Operation is successful. Returns OperationResult with "affected" field.',
84
- contentType: index_js_2.MimeTypes.opra_response_json,
81
+ contentType: index_js_1.MimeTypes.opra_response_json,
85
82
  })
86
- .Response(index_js_2.HttpStatusCode.UNPROCESSABLE_ENTITY, {
83
+ .Response(index_js_1.HttpStatusCode.UNPROCESSABLE_ENTITY, {
87
84
  description: 'The request was well-formed but was unable to process operation due to one or many errors.',
88
- contentType: index_js_2.MimeTypes.opra_response_json,
85
+ contentType: index_js_1.MimeTypes.opra_response_json,
89
86
  });
90
- if (typeof args.type === 'function')
91
- decorator.UseType(args.type);
92
87
  /**
93
88
  *
94
89
  */
95
90
  decorator.KeyParam = (name, prmOptions) => {
96
- decorator.PathParam(name, prmOptions);
91
+ const paramMeta = typeof prmOptions === 'string' || typeof prmOptions === 'function'
92
+ ? {
93
+ name,
94
+ location: 'path',
95
+ type: prmOptions,
96
+ keyParam: true,
97
+ }
98
+ : {
99
+ ...prmOptions,
100
+ name,
101
+ location: 'path',
102
+ keyParam: true,
103
+ };
104
+ decorator.PathParam(name, paramMeta);
97
105
  decoratorChain.push((meta) => {
98
- meta.path = (meta.path || '') + '@:' + name;
99
- meta.compositionOptions = meta.compositionOptions || {};
100
- meta.compositionOptions.keyParameter = name;
106
+ if (!meta.path?.includes(':' + name))
107
+ meta.path = (meta.path || '') + '@:' + name;
108
+ meta.mergePath = true;
101
109
  });
102
110
  return decorator;
103
111
  };
@@ -120,28 +128,26 @@ http_operation_js_1.HttpOperation.Entity.DeleteMany = function (arg0, arg1) {
120
128
  /** Initialize the decorator and the chain */
121
129
  const decoratorChain = [];
122
130
  const filterRules = new filter_rules_js_1.FilterRules();
123
- const filterType = new index_js_3.FilterType({ dataType: args.type });
131
+ const filterType = new index_js_2.FilterType({ dataType: args.type });
124
132
  filterType.rules = {};
125
- const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, (0, index_js_1.omitUndefined)({
126
- description: args.description,
133
+ const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, {
127
134
  method: 'DELETE',
135
+ ...args,
128
136
  composition: 'Entity.DeleteMany',
129
- }));
137
+ });
130
138
  decorator
131
- .Response(index_js_2.HttpStatusCode.OK, {
139
+ .Response(index_js_1.HttpStatusCode.OK, {
132
140
  description: 'Operation is successful. Returns OperationResult with "affected" field.',
133
- contentType: index_js_2.MimeTypes.opra_response_json,
141
+ contentType: index_js_1.MimeTypes.opra_response_json,
134
142
  })
135
- .Response(index_js_2.HttpStatusCode.UNPROCESSABLE_ENTITY, {
143
+ .Response(index_js_1.HttpStatusCode.UNPROCESSABLE_ENTITY, {
136
144
  description: 'The request was well-formed but was unable to process operation due to one or many errors.',
137
- contentType: index_js_2.MimeTypes.opra_response_json,
145
+ contentType: index_js_1.MimeTypes.opra_response_json,
138
146
  })
139
147
  .QueryParam('filter', {
140
148
  type: filterType,
141
149
  description: 'Determines filter fields',
142
150
  });
143
- if (typeof args.type === 'function')
144
- decorator.UseType(args.type);
145
151
  decoratorChain.push((operationMeta) => {
146
152
  const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
147
153
  compositionOptions.type = getDataTypeName(args.type);
@@ -168,32 +174,32 @@ http_operation_js_1.HttpOperation.Entity.FindMany = function (arg0, arg1) {
168
174
  /** Initialize the decorator and the chain */
169
175
  const decoratorChain = [];
170
176
  const filterRules = new filter_rules_js_1.FilterRules();
171
- const filterType = new index_js_3.FilterType({ dataType: args.type });
177
+ const filterType = new index_js_2.FilterType({ dataType: args.type });
172
178
  filterType.rules = {};
173
- const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, (0, index_js_1.omitUndefined)({
174
- description: args.description,
179
+ const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, {
175
180
  method: 'GET',
181
+ ...args,
176
182
  composition: 'Entity.FindMany',
177
- }));
183
+ });
178
184
  decorator
179
- .Response(index_js_2.HttpStatusCode.OK, {
185
+ .Response(index_js_1.HttpStatusCode.OK, {
180
186
  description: 'Operation is successful. Returns OperationResult with "payload" field that contains list of resources.',
181
- contentType: index_js_2.MimeTypes.opra_response_json,
187
+ contentType: index_js_1.MimeTypes.opra_response_json,
182
188
  type: args.type,
183
189
  partial: 'deep',
184
190
  isArray: true,
185
191
  })
186
- .Response(index_js_2.HttpStatusCode.UNPROCESSABLE_ENTITY, {
192
+ .Response(index_js_1.HttpStatusCode.UNPROCESSABLE_ENTITY, {
187
193
  description: 'The request was well-formed but was unable to process operation due to one or many errors.',
188
- contentType: index_js_2.MimeTypes.opra_response_json,
194
+ contentType: index_js_1.MimeTypes.opra_response_json,
189
195
  })
190
196
  .QueryParam('limit', {
191
197
  description: 'Determines number of returning instances',
192
- type: new index_js_4.IntegerType({ minValue: 1 }),
198
+ type: new index_js_3.IntegerType({ minValue: 1, maxValue: args.maxLimit }),
193
199
  })
194
200
  .QueryParam('skip', {
195
201
  description: 'Determines number of returning instances',
196
- type: new index_js_4.IntegerType({ minValue: 1 }),
202
+ type: new index_js_3.IntegerType({ minValue: 1 }),
197
203
  })
198
204
  .QueryParam('count', {
199
205
  description: 'Counts all matching instances if enabled',
@@ -201,7 +207,7 @@ http_operation_js_1.HttpOperation.Entity.FindMany = function (arg0, arg1) {
201
207
  })
202
208
  .QueryParam('projection', {
203
209
  description: 'Determines fields projection',
204
- type: new index_js_3.FieldPathType({
210
+ type: new index_js_2.FieldPathType({
205
211
  dataType: args.type,
206
212
  allowSigns: 'each',
207
213
  }),
@@ -214,18 +220,22 @@ http_operation_js_1.HttpOperation.Entity.FindMany = function (arg0, arg1) {
214
220
  })
215
221
  .QueryParam('sort', {
216
222
  description: 'Determines sort fields',
217
- type: new index_js_3.FieldPathType({
223
+ type: new index_js_2.FieldPathType({
218
224
  dataType: args.type,
219
225
  allowSigns: 'first',
220
226
  }),
221
227
  isArray: true,
222
228
  arraySeparator: ',',
223
229
  });
224
- if (typeof args.type === 'function')
225
- decorator.UseType(args.type);
226
230
  decoratorChain.push((operationMeta) => {
227
231
  const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
228
232
  compositionOptions.type = getDataTypeName(args.type);
233
+ if (args.defaultLimit)
234
+ compositionOptions.defaultLimit = args.defaultLimit;
235
+ if (args.defaultProjection)
236
+ compositionOptions.defaultProjection = args.defaultProjection;
237
+ if (args.maxLimit)
238
+ compositionOptions.maxLimit = args.maxLimit;
229
239
  });
230
240
  decorator.DefaultSort = (...fields) => {
231
241
  decoratorChain.push((operationMeta) => {
@@ -262,45 +272,56 @@ http_operation_js_1.HttpOperation.Entity.Get = function (arg0, arg1) {
262
272
  args = { ...arg1, type: arg0 };
263
273
  /** Initialize the decorator and the chain */
264
274
  const decoratorChain = [];
265
- const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, (0, index_js_1.omitUndefined)({
266
- description: args.description,
275
+ const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, {
267
276
  method: 'GET',
277
+ ...args,
268
278
  composition: 'Entity.Get',
269
- }));
279
+ });
270
280
  decorator
271
281
  .QueryParam('projection', {
272
282
  description: 'Determines fields projection',
273
- type: new index_js_3.FieldPathType({
283
+ type: new index_js_2.FieldPathType({
274
284
  dataType: args.type,
275
285
  allowSigns: 'each',
276
286
  }),
277
287
  isArray: true,
278
288
  arraySeparator: ',',
279
289
  })
280
- .Response(index_js_2.HttpStatusCode.OK, {
290
+ .Response(index_js_1.HttpStatusCode.OK, {
281
291
  description: 'Operation is successful. Returns OperationResult with "payload" field that contains the resource asked for.',
282
- contentType: index_js_2.MimeTypes.opra_response_json,
292
+ contentType: index_js_1.MimeTypes.opra_response_json,
283
293
  type: args.type,
284
294
  partial: 'deep',
285
295
  })
286
- .Response(index_js_2.HttpStatusCode.NO_CONTENT, {
296
+ .Response(index_js_1.HttpStatusCode.NO_CONTENT, {
287
297
  description: 'Operation is successful but no resource found',
288
298
  })
289
- .Response(index_js_2.HttpStatusCode.UNPROCESSABLE_ENTITY, {
299
+ .Response(index_js_1.HttpStatusCode.UNPROCESSABLE_ENTITY, {
290
300
  description: 'The request was well-formed but was unable to process operation due to one or many errors.',
291
- contentType: index_js_2.MimeTypes.opra_response_json,
301
+ contentType: index_js_1.MimeTypes.opra_response_json,
292
302
  });
293
- if (typeof args.type === 'function')
294
- decorator.UseType(args.type);
295
303
  /**
296
304
  *
297
305
  */
298
306
  decorator.KeyParam = (name, prmOptions) => {
299
- decorator.PathParam(name, prmOptions);
307
+ const paramMeta = typeof prmOptions === 'string' || typeof prmOptions === 'function'
308
+ ? {
309
+ name,
310
+ location: 'path',
311
+ type: prmOptions,
312
+ keyParam: true,
313
+ }
314
+ : {
315
+ ...prmOptions,
316
+ name,
317
+ location: 'path',
318
+ keyParam: true,
319
+ };
320
+ decorator.PathParam(name, paramMeta);
300
321
  decoratorChain.push((meta) => {
301
- meta.path = (meta.path || '') + '@:' + name;
302
- meta.compositionOptions = meta.compositionOptions || {};
303
- meta.compositionOptions.keyParameter = name;
322
+ if (!meta.path?.includes(':' + name))
323
+ meta.path = (meta.path || '') + '@:' + name;
324
+ meta.mergePath = true;
304
325
  });
305
326
  return decorator;
306
327
  };
@@ -322,12 +343,12 @@ http_operation_js_1.HttpOperation.Entity.UpdateMany = function (arg0, arg1) {
322
343
  args = { ...arg1, type: arg0 };
323
344
  /** Initialize the decorator and the chain */
324
345
  const decoratorChain = [];
325
- const filterType = new index_js_3.FilterType({ dataType: args.type });
346
+ const filterType = new index_js_2.FilterType({ dataType: args.type });
326
347
  filterType.rules = {};
327
348
  const filterRules = new filter_rules_js_1.FilterRules();
328
- const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, (0, index_js_1.omitUndefined)({
329
- description: args.description,
349
+ const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, {
330
350
  method: 'PATCH',
351
+ ...args,
331
352
  composition: 'Entity.UpdateMany',
332
353
  requestBody: {
333
354
  immediateFetch: true,
@@ -335,18 +356,16 @@ http_operation_js_1.HttpOperation.Entity.UpdateMany = function (arg0, arg1) {
335
356
  ...args.requestBody,
336
357
  required: true,
337
358
  },
338
- }));
339
- decorator.RequestContent(args.requestBody?.type || args.type);
340
- if (typeof args.type === 'function')
341
- decorator.UseType(args.type);
359
+ });
342
360
  decorator
343
- .Response(index_js_2.HttpStatusCode.OK, {
361
+ .RequestContent(args.requestBody?.type || args.type)
362
+ .Response(index_js_1.HttpStatusCode.OK, {
344
363
  description: 'Operation is successful. Returns OperationResult with "affected" field.',
345
- contentType: index_js_2.MimeTypes.opra_response_json,
364
+ contentType: index_js_1.MimeTypes.opra_response_json,
346
365
  })
347
- .Response(index_js_2.HttpStatusCode.UNPROCESSABLE_ENTITY, {
366
+ .Response(index_js_1.HttpStatusCode.UNPROCESSABLE_ENTITY, {
348
367
  description: 'The request was well-formed but was unable to process operation due to one or many errors.',
349
- contentType: index_js_2.MimeTypes.opra_response_json,
368
+ contentType: index_js_1.MimeTypes.opra_response_json,
350
369
  })
351
370
  .QueryParam('filter', {
352
371
  type: filterType,
@@ -378,11 +397,11 @@ http_operation_js_1.HttpOperation.Entity.Update = function (arg0, arg1) {
378
397
  /** Initialize the decorator and the chain */
379
398
  const decoratorChain = [];
380
399
  const filterRules = new filter_rules_js_1.FilterRules();
381
- const filterType = new index_js_3.FilterType({ dataType: args.type });
400
+ const filterType = new index_js_2.FilterType({ dataType: args.type });
382
401
  filterType.rules = {};
383
- const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, (0, index_js_1.omitUndefined)({
384
- description: args.description,
402
+ const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, {
385
403
  method: 'PATCH',
404
+ ...args,
386
405
  composition: 'Entity.Update',
387
406
  requestBody: {
388
407
  partial: 'deep',
@@ -390,11 +409,11 @@ http_operation_js_1.HttpOperation.Entity.Update = function (arg0, arg1) {
390
409
  ...args.requestBody,
391
410
  required: true,
392
411
  },
393
- }));
412
+ });
394
413
  decorator
395
414
  .QueryParam('projection', {
396
415
  description: 'Determines fields projection',
397
- type: new index_js_3.FieldPathType({
416
+ type: new index_js_2.FieldPathType({
398
417
  dataType: args.type,
399
418
  allowSigns: 'each',
400
419
  }),
@@ -406,30 +425,41 @@ http_operation_js_1.HttpOperation.Entity.Update = function (arg0, arg1) {
406
425
  description: 'Determines filter fields',
407
426
  })
408
427
  .RequestContent(args.requestBody?.type || args.type)
409
- .Response(index_js_2.HttpStatusCode.OK, {
428
+ .Response(index_js_1.HttpStatusCode.OK, {
410
429
  description: 'Operation is successful. Returns OperationResult with "payload" field that contains updated resource.',
411
- contentType: index_js_2.MimeTypes.opra_response_json,
430
+ contentType: index_js_1.MimeTypes.opra_response_json,
412
431
  type: args.type,
413
432
  partial: 'deep',
414
433
  })
415
- .Response(index_js_2.HttpStatusCode.NO_CONTENT, {
434
+ .Response(index_js_1.HttpStatusCode.NO_CONTENT, {
416
435
  description: 'Operation is successful but no resource found',
417
436
  })
418
- .Response(index_js_2.HttpStatusCode.UNPROCESSABLE_ENTITY, {
437
+ .Response(index_js_1.HttpStatusCode.UNPROCESSABLE_ENTITY, {
419
438
  description: 'The request was well-formed but was unable to process operation due to one or many errors.',
420
- contentType: index_js_2.MimeTypes.opra_response_json,
439
+ contentType: index_js_1.MimeTypes.opra_response_json,
421
440
  });
422
- if (typeof args.type === 'function')
423
- decorator.UseType(args.type);
424
441
  /**
425
442
  *
426
443
  */
427
444
  decorator.KeyParam = (name, prmOptions) => {
428
- decorator.PathParam(name, prmOptions);
445
+ const paramMeta = typeof prmOptions === 'string' || typeof prmOptions === 'function'
446
+ ? {
447
+ name,
448
+ location: 'path',
449
+ type: prmOptions,
450
+ keyParam: true,
451
+ }
452
+ : {
453
+ ...prmOptions,
454
+ name,
455
+ location: 'path',
456
+ keyParam: true,
457
+ };
458
+ decorator.PathParam(name, paramMeta);
429
459
  decoratorChain.push((meta) => {
430
- meta.path = (meta.path || '') + '@:' + name;
431
- meta.compositionOptions = meta.compositionOptions || {};
432
- meta.compositionOptions.keyParameter = name;
460
+ if (!meta.path?.includes(':' + name))
461
+ meta.path = (meta.path || '') + '@:' + name;
462
+ meta.mergePath = true;
433
463
  });
434
464
  return decorator;
435
465
  };