@opra/common 1.0.0-alpha.7 → 1.0.0-alpha.9

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 (78) hide show
  1. package/browser.js +5648 -5640
  2. package/cjs/document/common/document-element.js +2 -1
  3. package/cjs/document/data-type/api-field.js +2 -1
  4. package/cjs/document/data-type/complex-type-base.js +2 -1
  5. package/cjs/document/data-type/complex-type.js +4 -2
  6. package/cjs/document/data-type/data-type.js +2 -1
  7. package/cjs/document/data-type/enum-type.js +3 -2
  8. package/cjs/document/data-type/extended-types/field-path.type.js +1 -3
  9. package/cjs/document/data-type/extended-types/filter.type.js +15 -17
  10. package/cjs/document/data-type/mapped-type.js +9 -5
  11. package/cjs/document/data-type/mixin-type.js +2 -1
  12. package/cjs/document/data-type/simple-type.js +8 -9
  13. package/cjs/document/data-type/utils/create-mapped-class.js +2 -1
  14. package/cjs/document/decorators/http-operation.decorator.js +8 -4
  15. package/cjs/document/factory/api-document.factory.js +1 -3
  16. package/cjs/document/factory/data-type.factory.js +37 -19
  17. package/cjs/document/factory/http-api.factory.js +2 -1
  18. package/cjs/document/http/http-controller.js +3 -2
  19. package/cjs/document/http/http-media-type.js +4 -2
  20. package/cjs/document/http/http-operation-response.js +2 -1
  21. package/cjs/document/http/http-status-range.js +1 -2
  22. package/cjs/document/index.js +5 -5
  23. package/cjs/exception/index.js +5 -5
  24. package/cjs/filter/antlr/OpraFilterParser.js +28 -82
  25. package/cjs/filter/ast/index.js +1 -1
  26. package/cjs/filter/build.js +1 -3
  27. package/cjs/filter/filter-rules.js +4 -2
  28. package/cjs/filter/opra-filter.ns.js +2 -2
  29. package/cjs/filter/parse.js +1 -3
  30. package/cjs/helpers/mixin-utils.js +2 -1
  31. package/cjs/helpers/monkey-patches.js +4 -2
  32. package/cjs/helpers/parse-fields-projection.js +1 -3
  33. package/cjs/helpers/responsive-map.js +5 -4
  34. package/cjs/i18n/i18n.js +4 -3
  35. package/cjs/i18n/index.js +1 -1
  36. package/cjs/index.js +1 -1
  37. package/esm/document/common/document-element.js +2 -1
  38. package/esm/document/data-type/api-field.js +2 -1
  39. package/esm/document/data-type/complex-type-base.js +2 -1
  40. package/esm/document/data-type/complex-type.js +4 -2
  41. package/esm/document/data-type/data-type.js +2 -1
  42. package/esm/document/data-type/enum-type.js +3 -2
  43. package/esm/document/data-type/extended-types/field-path.type.js +1 -3
  44. package/esm/document/data-type/extended-types/filter.type.js +15 -17
  45. package/esm/document/data-type/mapped-type.js +9 -5
  46. package/esm/document/data-type/mixin-type.js +2 -1
  47. package/esm/document/data-type/simple-type.js +8 -9
  48. package/esm/document/data-type/utils/create-mapped-class.js +2 -1
  49. package/esm/document/decorators/http-operation.decorator.js +8 -4
  50. package/esm/document/factory/api-document.factory.js +1 -3
  51. package/esm/document/factory/data-type.factory.js +37 -19
  52. package/esm/document/factory/http-api.factory.js +2 -1
  53. package/esm/document/http/http-controller.js +3 -2
  54. package/esm/document/http/http-media-type.js +4 -2
  55. package/esm/document/http/http-operation-response.js +2 -1
  56. package/esm/document/http/http-status-range.js +1 -2
  57. package/esm/document/index.js +5 -5
  58. package/esm/exception/index.js +5 -5
  59. package/esm/filter/antlr/OpraFilterParser.js +28 -82
  60. package/esm/filter/ast/index.js +1 -1
  61. package/esm/filter/build.js +1 -3
  62. package/esm/filter/filter-rules.js +4 -2
  63. package/esm/filter/opra-filter.ns.js +2 -2
  64. package/esm/filter/parse.js +1 -3
  65. package/esm/helpers/mixin-utils.js +2 -1
  66. package/esm/helpers/monkey-patches.js +4 -2
  67. package/esm/helpers/parse-fields-projection.js +1 -3
  68. package/esm/helpers/responsive-map.js +5 -4
  69. package/esm/i18n/i18n.js +4 -3
  70. package/esm/i18n/index.js +1 -1
  71. package/esm/index.js +1 -1
  72. package/package.json +5 -4
  73. package/types/document/index.d.ts +5 -5
  74. package/types/exception/index.d.ts +5 -5
  75. package/types/filter/ast/index.d.ts +1 -1
  76. package/types/filter/opra-filter.ns.d.ts +2 -2
  77. package/types/i18n/i18n.d.ts +21 -19
  78. package/types/index.d.ts +1 -1
@@ -16,12 +16,13 @@ exports.DocumentElement = function (owner) {
16
16
  enumerable: false,
17
17
  writable: true,
18
18
  });
19
- if (owner)
19
+ if (owner) {
20
20
  Object.defineProperty(_this, 'owner', {
21
21
  value: owner,
22
22
  enumerable: false,
23
23
  writable: true,
24
24
  });
25
+ }
25
26
  };
26
27
  /**
27
28
  * @class DocumentElement
@@ -24,8 +24,9 @@ exports.ApiField = function (...args) {
24
24
  _this.name = initArgs.name;
25
25
  const origin = initArgs.origin || owner;
26
26
  /* istanbul ignore next */
27
- if (!(origin instanceof complex_type_base_js_1.ComplexTypeBase))
27
+ if (!(origin instanceof complex_type_base_js_1.ComplexTypeBase)) {
28
28
  throw new Error('Field origin should be one of ComplexType, MappedType or MixinType');
29
+ }
29
30
  _this.origin = origin;
30
31
  _this.type = initArgs.type || owner.node.getDataType('any');
31
32
  _this.description = initArgs.description;
@@ -118,8 +118,9 @@ class ComplexTypeBaseClass extends data_type_js_1.DataType {
118
118
  : options?.projection;
119
119
  const schema = this._generateSchema(codec, { ...options, projection, currentPath: '' });
120
120
  let additionalFields;
121
- if (this.additionalFields instanceof data_type_js_1.DataType)
121
+ if (this.additionalFields instanceof data_type_js_1.DataType) {
122
122
  additionalFields = this.additionalFields.generateCodec(codec, options);
123
+ }
123
124
  else if (typeof this.additionalFields === 'boolean')
124
125
  additionalFields = this.additionalFields;
125
126
  else if (Array.isArray(this.additionalFields)) {
@@ -29,11 +29,13 @@ exports.ComplexType = function (...args) {
29
29
  if (initArgs.base) {
30
30
  context.enter('.base', () => {
31
31
  // noinspection SuspiciousTypeOfGuard
32
- if (!(initArgs.base instanceof complex_type_base_js_1.ComplexTypeBase))
32
+ if (!(initArgs.base instanceof complex_type_base_js_1.ComplexTypeBase)) {
33
33
  throw new TypeError(`"${initArgs.base.kind}" can't be set as base for a "${this.kind}"`);
34
+ }
34
35
  _this.base = initArgs.base;
35
- if (_this.additionalFields == null && _this.base.additionalFields)
36
+ if (_this.additionalFields == null && _this.base.additionalFields) {
36
37
  _this.additionalFields = _this.base.additionalFields;
38
+ }
37
39
  /** Copy fields from base */
38
40
  for (const v of _this.base.fields.values()) {
39
41
  this.fields.set(v.name, new api_field_js_1.ApiField(this, v));
@@ -14,8 +14,9 @@ exports.DataType = function (owner, initArgs,
14
14
  context) {
15
15
  if (!this)
16
16
  throw new TypeError('"this" should be passed to call class constructor');
17
- if (initArgs?.name && !constants_js_1.CLASS_NAME_PATTERN.test(initArgs.name))
17
+ if (initArgs?.name && !constants_js_1.CLASS_NAME_PATTERN.test(initArgs.name)) {
18
18
  throw new TypeError(`"${initArgs.name}" is not a valid DataType name`);
19
+ }
19
20
  document_element_js_1.DocumentElement.call(this, owner);
20
21
  const _this = (0, ts_gems_1.asMutable)(this);
21
22
  _this.kind = initArgs.kind;
@@ -22,8 +22,9 @@ exports.EnumType = function (...args) {
22
22
  _this.kind = index_js_2.OpraSchema.EnumType.Kind;
23
23
  if (initArgs.base) {
24
24
  // noinspection SuspiciousTypeOfGuard
25
- if (!(initArgs.base instanceof exports.EnumType))
26
- throw new TypeError(`"${initArgs.base.kind}" can't be set as base for a "${this.kind}"`);
25
+ if (!(initArgs.base instanceof exports.EnumType)) {
26
+ throw new TypeError(`"${initArgs.base.kind}" can't be set as base for a "${_this.kind}"`);
27
+ }
27
28
  _this.base = initArgs.base;
28
29
  }
29
30
  _this.instance = initArgs.instance;
@@ -15,9 +15,7 @@ let FieldPathType = class FieldPathType {
15
15
  ? element.node.getComplexType(properties.dataType)
16
16
  : element.node.getComplexType('object');
17
17
  const allowSigns = properties.allowSigns;
18
- const decodeFieldPath = (0, valgen_1.validator)('decodeFieldPath', function (input) {
19
- return dataType.normalizeFieldPath(input, { allowSigns });
20
- });
18
+ const decodeFieldPath = (0, valgen_1.validator)('decodeFieldPath', (input) => dataType.normalizeFieldPath(input, { allowSigns }));
21
19
  return valgen_1.vg.pipe([valgen_1.toString, decodeFieldPath]);
22
20
  }
23
21
  [constants_js_1.ENCODER](properties, element) {
@@ -56,24 +56,22 @@ exports.FilterType = FilterType = tslib_1.__decorate([
56
56
  }),
57
57
  tslib_1.__metadata("design:paramtypes", [Object])
58
58
  ], FilterType);
59
- const decodeFilter = (dataType, rules) => {
60
- return (0, valgen_1.validator)('decodeFilter', function (input, context, _this) {
61
- if (typeof input === 'string') {
62
- try {
63
- const filter = index_js_1.OpraFilter.parse(input);
64
- if (rules)
65
- return rules.normalizeFilter(filter, dataType);
66
- return filter;
67
- }
68
- catch (e) {
69
- context.fail(_this, `Not a valid filter expression. ${e.message}`, input, e.errors);
70
- return;
71
- }
59
+ const decodeFilter = (dataType, rules) => (0, valgen_1.validator)('decodeFilter', (input, context, _this) => {
60
+ if (typeof input === 'string') {
61
+ try {
62
+ const filter = index_js_1.OpraFilter.parse(input);
63
+ if (rules)
64
+ return rules.normalizeFilter(filter, dataType);
65
+ return filter;
72
66
  }
73
- context.fail(_this, `Nt a valid filter expression string`, input);
74
- });
75
- };
76
- const encodeFilter = (0, valgen_1.validator)('encodeFilter', function (input, context, _this) {
67
+ catch (e) {
68
+ context.fail(_this, `Not a valid filter expression. ${e.message}`, input, e.errors);
69
+ return;
70
+ }
71
+ }
72
+ context.fail(_this, `Nt a valid filter expression string`, input);
73
+ });
74
+ const encodeFilter = (0, valgen_1.validator)('encodeFilter', (input, context, _this) => {
77
75
  if (input instanceof index_js_1.OpraFilter.Ast) {
78
76
  return input.toString();
79
77
  }
@@ -22,22 +22,25 @@ exports.MappedType = function (...args) {
22
22
  _this.kind = index_js_2.OpraSchema.MappedType.Kind;
23
23
  if (initArgs.base) {
24
24
  // noinspection SuspiciousTypeOfGuard
25
- if (!(initArgs.base instanceof complex_type_base_js_1.ComplexTypeBase))
25
+ if (!(initArgs.base instanceof complex_type_base_js_1.ComplexTypeBase)) {
26
26
  throw new TypeError(`"${initArgs.base.kind}" can't be set as base for a "${this.kind}"`);
27
+ }
27
28
  _this.base = initArgs.base;
28
29
  _this.ctor = initArgs.ctor || _this.base.ctor;
29
30
  if (initArgs.pick)
30
31
  _this.pick = initArgs.pick.map(f => _this.base.normalizeFieldPath(f));
31
32
  else if (initArgs.omit)
32
33
  _this.omit = initArgs.omit.map(f => _this.base.normalizeFieldPath(f));
33
- else if (initArgs.partial)
34
+ else if (initArgs.partial) {
34
35
  _this.partial = Array.isArray(initArgs.partial)
35
36
  ? initArgs.partial.map(f => _this.base.normalizeFieldPath(f))
36
37
  : initArgs.partial;
37
- else if (initArgs.required)
38
+ }
39
+ else if (initArgs.required) {
38
40
  _this.required = Array.isArray(initArgs.required)
39
41
  ? initArgs.required.map(f => _this.base.normalizeFieldPath(f))
40
42
  : initArgs.required;
43
+ }
41
44
  /** Copy fields from base */
42
45
  const isInheritedPredicate = (0, get_is_inherited_predicate_fn_js_1.getIsInheritedPredicateFn)(_this.pick, _this.omit);
43
46
  const partial = Array.isArray(_this.partial) ? _this.partial.map(x => x.toLowerCase()) : _this.partial;
@@ -57,8 +60,9 @@ exports.MappedType = function (...args) {
57
60
  }
58
61
  if (!_this.pick ||
59
62
  _this.base.additionalFields === false ||
60
- (Array.isArray(_this.base.additionalFields) && _this.base.additionalFields?.[0] === 'error'))
63
+ (Array.isArray(_this.base.additionalFields) && _this.base.additionalFields?.[0] === 'error')) {
61
64
  _this.additionalFields = _this.base.additionalFields;
65
+ }
62
66
  if (initArgs.base.keyField && isInheritedPredicate(initArgs.base.keyField))
63
67
  _this.keyField = initArgs.base.keyField;
64
68
  }
@@ -91,4 +95,4 @@ class MappedTypeClass extends complex_type_base_js_1.ComplexTypeBase {
91
95
  }
92
96
  }
93
97
  exports.MappedType.prototype = MappedTypeClass.prototype;
94
- exports.MappedType._applyMixin = () => void 0;
98
+ exports.MappedType._applyMixin = () => undefined;
@@ -100,8 +100,9 @@ function MixinTypeFactory(...args) {
100
100
  if (!(itemMeta &&
101
101
  (itemMeta.kind === index_js_2.OpraSchema.ComplexType.Kind ||
102
102
  itemMeta.kind === index_js_2.OpraSchema.MixinType.Kind ||
103
- itemMeta.kind === index_js_2.OpraSchema.MappedType.Kind)))
103
+ itemMeta.kind === index_js_2.OpraSchema.MappedType.Kind))) {
104
104
  throw new TypeError(`Class "${c.name}" is not a ${index_js_2.OpraSchema.ComplexType.Kind}, ${index_js_2.OpraSchema.MixinType.Kind} or ${index_js_2.OpraSchema.MappedType.Kind}`);
105
+ }
105
106
  metadata.types.push(c);
106
107
  (0, index_js_1.mergePrototype)(MixinClass.prototype, c.prototype);
107
108
  }
@@ -23,8 +23,9 @@ 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;
@@ -70,15 +71,13 @@ class SimpleTypeClass extends data_type_js_1.DataType {
70
71
  }
71
72
  return valgen_1.isAny;
72
73
  }
73
- else {
74
- let t = this;
75
- while (t) {
76
- if (t._generateEncoder)
77
- return t._generateEncoder(prop, options?.documentElement || this.owner);
78
- t = this.base;
79
- }
80
- 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;
81
79
  }
80
+ return valgen_1.isAny;
82
81
  }
83
82
  toJSON() {
84
83
  const attributes = (0, index_js_1.omitUndefined)(this.ownAttributes);
@@ -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,
@@ -37,8 +37,9 @@ function HttpOperationDecoratorFactory(decoratorChain, options) {
37
37
  type: arg1,
38
38
  }
39
39
  : { ...arg1, name, location: 'cookie' };
40
- if (meta.parameters)
40
+ if (meta.parameters) {
41
41
  meta.parameters = meta.parameters.filter(p => !(p.location === 'cookie' && String(p.name) === String(name)));
42
+ }
42
43
  else
43
44
  meta.parameters = [];
44
45
  meta.parameters.push(paramMeta);
@@ -57,8 +58,9 @@ function HttpOperationDecoratorFactory(decoratorChain, options) {
57
58
  type: arg1,
58
59
  }
59
60
  : { ...arg1, name, location: 'header' };
60
- if (meta.parameters)
61
+ if (meta.parameters) {
61
62
  meta.parameters = meta.parameters.filter(p => !(p.location === 'header' && String(p.name) === String(name)));
63
+ }
62
64
  else
63
65
  meta.parameters = [];
64
66
  meta.parameters.push(paramMeta);
@@ -77,8 +79,9 @@ function HttpOperationDecoratorFactory(decoratorChain, options) {
77
79
  type: arg1,
78
80
  }
79
81
  : { ...arg1, name, location: 'query' };
80
- if (meta.parameters)
82
+ if (meta.parameters) {
81
83
  meta.parameters = meta.parameters.filter(p => !(p.location === 'query' && String(p.name) === String(name)));
84
+ }
82
85
  else
83
86
  meta.parameters = [];
84
87
  meta.parameters.push(paramMeta);
@@ -97,8 +100,9 @@ function HttpOperationDecoratorFactory(decoratorChain, options) {
97
100
  type: arg1,
98
101
  }
99
102
  : { ...arg1, name, location: 'path' };
100
- if (meta.parameters)
103
+ if (meta.parameters) {
101
104
  meta.parameters = meta.parameters.filter(p => !(p.location === 'path' && String(p.name) === String(name)));
105
+ }
102
106
  else
103
107
  meta.parameters = [];
104
108
  meta.parameters.push(paramMeta);
@@ -46,9 +46,7 @@ class ApiDocumentFactory {
46
46
  context.error.message = `(${l}) error${l > 1 ? 's' : ''} found in document schema.`;
47
47
  if (context.showErrorDetails) {
48
48
  context.error.message += context.error.details
49
- .map(d => {
50
- return `\n\n - ${d.message}` + (d.path ? `\n @${d.path}` : '');
51
- })
49
+ .map(d => `\n\n - ${d.message}` + (d.path ? `\n @${d.path}` : ''))
52
50
  .join('');
53
51
  }
54
52
  }
@@ -95,10 +95,10 @@ class DataTypeFactory {
95
95
  thunk = await (0, index_js_1.resolveThunk)(thunk);
96
96
  const metadata = Reflect.getMetadata(constants_js_1.DATATYPE_METADATA, thunk) || thunk[constants_js_1.DATATYPE_METADATA];
97
97
  if (!(metadata && metadata.name)) {
98
- if (typeof thunk === 'function')
98
+ if (typeof thunk === 'function') {
99
99
  return context.addError(`Class "${thunk.name}" doesn't have a valid data type metadata`);
100
- else
101
- return context.addError(`Object doesn't have a valid data type metadata`);
100
+ }
101
+ return context.addError(`Object doesn't have a valid data type metadata`);
102
102
  }
103
103
  importQueue.set(metadata.name, thunk);
104
104
  });
@@ -117,8 +117,9 @@ class DataTypeFactory {
117
117
  continue;
118
118
  const dt = await this._importDataTypeArgs(context, owner, name);
119
119
  // istanbul ignore next
120
- if (dt && typeof dt !== 'string')
120
+ if (dt && typeof dt !== 'string') {
121
121
  context.addError(`Embedded data type can't be loaded into document node directly`);
122
+ }
122
123
  }
123
124
  return Array.from(initArgsMap.values());
124
125
  }
@@ -182,8 +183,9 @@ class DataTypeFactory {
182
183
  const baseArgs = await this._importDataTypeArgs(context, owner, metadata.name);
183
184
  if (!baseArgs)
184
185
  return;
185
- if (typeof baseArgs === 'object' && baseArgs.kind !== index_js_2.OpraSchema.SimpleType.Kind)
186
+ if (typeof baseArgs === 'object' && baseArgs.kind !== index_js_2.OpraSchema.SimpleType.Kind) {
186
187
  return context.addError('Kind of base data type is not same');
188
+ }
187
189
  return {
188
190
  kind: index_js_2.OpraSchema.SimpleType.Kind,
189
191
  name: undefined,
@@ -219,8 +221,9 @@ class DataTypeFactory {
219
221
  out._instance = { name: metadata.name };
220
222
  out[constants_js_1.kDataTypeMap] = owner.node[constants_js_1.kDataTypeMap];
221
223
  }
222
- else
224
+ else {
223
225
  return context.addError(`Data Type (${out.name}) must be explicitly added to type list in the document scope`);
226
+ }
224
227
  }
225
228
  switch (out.kind) {
226
229
  case index_js_2.OpraSchema.ComplexType.Kind:
@@ -268,8 +271,9 @@ class DataTypeFactory {
268
271
  }
269
272
  else if (initArgs.ctor) {
270
273
  const baseClass = Object.getPrototypeOf(initArgs.ctor.prototype).constructor;
271
- if (Reflect.hasMetadata(constants_js_1.DATATYPE_METADATA, baseClass))
274
+ if (Reflect.hasMetadata(constants_js_1.DATATYPE_METADATA, baseClass)) {
272
275
  baseArgs = await this._importDataTypeArgs(context, owner, baseClass);
276
+ }
273
277
  }
274
278
  if (!baseArgs)
275
279
  return;
@@ -278,14 +282,16 @@ class DataTypeFactory {
278
282
  });
279
283
  // Initialize additionalFields
280
284
  if (metadata.additionalFields != null) {
281
- if (typeof metadata.additionalFields === 'boolean' || Array.isArray(metadata.additionalFields))
285
+ if (typeof metadata.additionalFields === 'boolean' || Array.isArray(metadata.additionalFields)) {
282
286
  initArgs.additionalFields = metadata.additionalFields;
283
- else
287
+ }
288
+ else {
284
289
  await context.enterAsync('.additionalFields', async () => {
285
290
  const t = await this._importDataTypeArgs(context, owner, metadata.additionalFields);
286
291
  if (t)
287
292
  initArgs.additionalFields = preferName(t);
288
293
  });
294
+ }
289
295
  }
290
296
  if (metadata.fields) {
291
297
  initArgs.fields = {};
@@ -293,8 +299,9 @@ class DataTypeFactory {
293
299
  for (const [k, v] of Object.entries(metadata.fields)) {
294
300
  await context.enterAsync(`[${k}]`, async () => {
295
301
  const fieldMeta = typeof v === 'string' ? { type: v } : v;
296
- if (fieldMeta.isArray && !fieldMeta.type)
302
+ if (fieldMeta.isArray && !fieldMeta.type) {
297
303
  return context.addError(`"type" must be defined explicitly for array fields`);
304
+ }
298
305
  const t = await this._importDataTypeArgs(context, owner, fieldMeta.type || 'any');
299
306
  if (!t)
300
307
  return;
@@ -328,8 +335,9 @@ class DataTypeFactory {
328
335
  }
329
336
  else if (initArgs.ctor) {
330
337
  const baseClass = Object.getPrototypeOf(initArgs.ctor.prototype).constructor;
331
- if (Reflect.hasMetadata(constants_js_1.DATATYPE_METADATA, baseClass))
338
+ if (Reflect.hasMetadata(constants_js_1.DATATYPE_METADATA, baseClass)) {
332
339
  baseArgs = await this._importDataTypeArgs(context, owner, baseClass);
340
+ }
333
341
  }
334
342
  if (!baseArgs)
335
343
  return;
@@ -342,10 +350,12 @@ class DataTypeFactory {
342
350
  initArgs.properties = new initArgs.ctor();
343
351
  if (metadata.attributes)
344
352
  initArgs.attributes = (0, index_js_1.cloneObject)(metadata.attributes);
345
- if (typeof initArgs.properties?.[constants_js_1.DECODER] === 'function')
353
+ if (typeof initArgs.properties?.[constants_js_1.DECODER] === 'function') {
346
354
  initArgs.generateDecoder = initArgs.properties?.[constants_js_1.DECODER].bind(initArgs.properties);
347
- if (typeof initArgs.properties?.[constants_js_1.ENCODER] === 'function')
355
+ }
356
+ if (typeof initArgs.properties?.[constants_js_1.ENCODER] === 'function') {
348
357
  initArgs.generateEncoder = initArgs.properties?.[constants_js_1.ENCODER].bind(initArgs.properties);
358
+ }
349
359
  }
350
360
  static async _prepareMappedTypeArgs(context, owner, initArgs, metadata) {
351
361
  await this._prepareDataTypeArgs(context, initArgs, metadata);
@@ -356,8 +366,9 @@ class DataTypeFactory {
356
366
  }
357
367
  else if (initArgs.ctor) {
358
368
  const baseClass = Object.getPrototypeOf(initArgs.ctor.prototype).constructor;
359
- if (Reflect.hasMetadata(constants_js_1.DATATYPE_METADATA, baseClass))
369
+ if (Reflect.hasMetadata(constants_js_1.DATATYPE_METADATA, baseClass)) {
360
370
  baseArgs = await this._importDataTypeArgs(context, owner, baseClass);
371
+ }
361
372
  }
362
373
  if (!baseArgs)
363
374
  return;
@@ -368,10 +379,12 @@ class DataTypeFactory {
368
379
  initArgs.pick = [...metadata.pick];
369
380
  else if (metadata.omit)
370
381
  initArgs.omit = [...metadata.omit];
371
- else if (metadata.partial)
382
+ else if (metadata.partial) {
372
383
  initArgs.partial = Array.isArray(metadata.partial) ? [...metadata.partial] : metadata.partial;
373
- else if (metadata.required)
384
+ }
385
+ else if (metadata.required) {
374
386
  initArgs.required = Array.isArray(metadata.required) ? [...metadata.required] : metadata.required;
387
+ }
375
388
  }
376
389
  static async _prepareMixinTypeArgs(context, owner, initArgs, metadata) {
377
390
  await this._prepareDataTypeArgs(context, initArgs, metadata);
@@ -413,6 +426,8 @@ class DataTypeFactory {
413
426
  return this._createMixinType(context, owner, initArgs);
414
427
  case index_js_2.OpraSchema.SimpleType.Kind:
415
428
  return this._createSimpleType(context, owner, initArgs);
429
+ default:
430
+ break;
416
431
  }
417
432
  }
418
433
  context.addError(`Unknown data type (${String(args)})`);
@@ -429,8 +444,9 @@ class DataTypeFactory {
429
444
  /** Set additionalFields */
430
445
  if (args.additionalFields) {
431
446
  context.enter('.additionalFields', () => {
432
- if (typeof args.additionalFields === 'boolean' || Array.isArray(args.additionalFields))
447
+ if (typeof args.additionalFields === 'boolean' || Array.isArray(args.additionalFields)) {
433
448
  initArgs.additionalFields = args.additionalFields;
449
+ }
434
450
  else {
435
451
  initArgs.additionalFields = this._createDataType(context, owner, args.additionalFields);
436
452
  }
@@ -443,12 +459,13 @@ class DataTypeFactory {
443
459
  for (const [k, v] of Object.entries(args.fields)) {
444
460
  context.enter(`[${k}]`, () => {
445
461
  const type = this._createDataType(context, owner, v.type);
446
- if (type)
462
+ if (type) {
447
463
  initArgs.fields[k] = {
448
464
  ...v,
449
465
  name: k,
450
466
  type,
451
467
  };
468
+ }
452
469
  });
453
470
  }
454
471
  });
@@ -492,8 +509,9 @@ class DataTypeFactory {
492
509
  for (const t of args.types) {
493
510
  context.enter(`[${i++}]`, () => {
494
511
  const base = this._createDataType(context, owner, t);
495
- if (!(base instanceof complex_type_base_js_1.ComplexTypeBase))
512
+ if (!(base instanceof complex_type_base_js_1.ComplexTypeBase)) {
496
513
  throw new TypeError(`"${base?.kind}" can't be set as base for a "${initArgs.kind}"`);
514
+ }
497
515
  initArgs.types.push(base);
498
516
  });
499
517
  }
@@ -48,8 +48,9 @@ class HttpApiFactory {
48
48
  return api;
49
49
  }
50
50
  static async _createController(context, parent, thunk, name) {
51
- if (typeof thunk === 'function' && !(0, index_js_1.isConstructor)(thunk))
51
+ if (typeof thunk === 'function' && !(0, index_js_1.isConstructor)(thunk)) {
52
52
  thunk = parent instanceof http_controller_js_1.HttpController ? thunk(parent.instance) : thunk();
53
+ }
53
54
  thunk = await (0, index_js_1.resolveThunk)(thunk);
54
55
  let ctor;
55
56
  let metadata;
@@ -61,7 +61,7 @@ class HttpControllerClass extends document_element_js_1.DocumentElement {
61
61
  if (c.controllers.size) {
62
62
  controller = c.findController(arg0);
63
63
  if (controller) {
64
- this._controllerReverseMap.set(arg0, c);
64
+ this._controllerReverseMap.set(arg0, controller);
65
65
  return controller;
66
66
  }
67
67
  }
@@ -95,8 +95,9 @@ class HttpControllerClass extends document_element_js_1.DocumentElement {
95
95
  if (prm.name instanceof RegExp && prm.name.test(paramName))
96
96
  return prm;
97
97
  }
98
- if (this.node.parent && this.node.parent.element instanceof exports.HttpController)
98
+ if (this.node.parent && this.node.parent.element instanceof exports.HttpController) {
99
99
  return this.node.parent.element.findParameter(paramName, location);
100
+ }
100
101
  }
101
102
  getFullUrl() {
102
103
  return (this.owner instanceof exports.HttpController ? this.owner.getFullUrl() : '/') + this.path;
@@ -25,8 +25,9 @@ exports.HttpMediaType = function (owner, initArgs) {
25
25
  _this.maxFileSize = initArgs.maxFileSize;
26
26
  _this.maxTotalFileSize = initArgs.maxTotalFileSize;
27
27
  _this.minFileSize = initArgs.minFileSize;
28
- if (initArgs?.type)
28
+ if (initArgs?.type) {
29
29
  _this.type = initArgs?.type instanceof data_type_js_1.DataType ? initArgs.type : _this.owner.node.getDataType(initArgs.type);
30
+ }
30
31
  _this.isArray = initArgs.isArray;
31
32
  };
32
33
  /**
@@ -38,8 +39,9 @@ class HttpMediaTypeClass extends document_element_js_1.DocumentElement {
38
39
  return;
39
40
  for (const f of this.multipartFields) {
40
41
  if ((!fieldType || fieldType === f.fieldType) &&
41
- ((f.fieldName instanceof RegExp && f.fieldName.test(fieldName)) || f.fieldName === fieldName))
42
+ ((f.fieldName instanceof RegExp && f.fieldName.test(fieldName)) || f.fieldName === fieldName)) {
42
43
  return f;
44
+ }
43
45
  }
44
46
  }
45
47
  toJSON() {
@@ -19,8 +19,9 @@ class HttpOperationResponse extends http_media_type_js_1.HttpMediaType {
19
19
  paramName = paramName.toLowerCase();
20
20
  for (const prm of this.parameters) {
21
21
  if ((!location || location === prm.location) &&
22
- ((prm.name instanceof RegExp && prm.name.test(paramName)) || prm.name === paramName))
22
+ ((prm.name instanceof RegExp && prm.name.test(paramName)) || prm.name === paramName)) {
23
23
  return prm;
24
+ }
24
25
  }
25
26
  }
26
27
  toJSON() {
@@ -31,8 +31,7 @@ class HttpStatusRange {
31
31
  toString() {
32
32
  if (this.start === this.end)
33
33
  return String(this.start);
34
- else
35
- return String(this.start) + '-' + String(this.end);
34
+ return String(this.start) + '-' + String(this.end);
36
35
  }
37
36
  toJSON() {
38
37
  return !this.end || this.start === this.end ? this.start : { start: this.start, end: this.end };
@@ -6,36 +6,36 @@ require("reflect-metadata");
6
6
  const DataTypeFactory_ = tslib_1.__importStar(require("./factory/data-type.factory.js"));
7
7
  const HttpApiFactory_ = tslib_1.__importStar(require("./factory/http-api.factory.js"));
8
8
  tslib_1.__exportStar(require("./api-document.js"), exports);
9
- tslib_1.__exportStar(require("./constants.js"), exports);
10
9
  tslib_1.__exportStar(require("./common/api-base.js"), exports);
11
10
  tslib_1.__exportStar(require("./common/data-type-map.js"), exports);
12
11
  tslib_1.__exportStar(require("./common/document-element.js"), exports);
13
12
  tslib_1.__exportStar(require("./common/document-init-context.js"), exports);
14
13
  tslib_1.__exportStar(require("./common/document-node.js"), exports);
15
14
  tslib_1.__exportStar(require("./common/opra-document-error.js"), exports);
15
+ tslib_1.__exportStar(require("./constants.js"), exports);
16
+ tslib_1.__exportStar(require("./data-type/api-field.js"), exports);
16
17
  tslib_1.__exportStar(require("./data-type/complex-type.js"), exports);
17
18
  tslib_1.__exportStar(require("./data-type/data-type.js"), exports);
18
19
  tslib_1.__exportStar(require("./data-type/enum-type.js"), exports);
19
- tslib_1.__exportStar(require("./data-type/api-field.js"), exports);
20
+ tslib_1.__exportStar(require("./data-type/extended-types/index.js"), exports);
20
21
  tslib_1.__exportStar(require("./data-type/mapped-type.js"), exports);
21
22
  tslib_1.__exportStar(require("./data-type/mixin-type.js"), exports);
22
23
  tslib_1.__exportStar(require("./data-type/omit-type.js"), exports);
23
24
  tslib_1.__exportStar(require("./data-type/partial-type.js"), exports);
24
25
  tslib_1.__exportStar(require("./data-type/pick-type.js"), exports);
26
+ tslib_1.__exportStar(require("./data-type/primitive-types/index.js"), exports);
25
27
  tslib_1.__exportStar(require("./data-type/required-type.js"), exports);
26
28
  tslib_1.__exportStar(require("./data-type/simple-type.js"), exports);
27
- tslib_1.__exportStar(require("./data-type/primitive-types/index.js"), exports);
28
- tslib_1.__exportStar(require("./data-type/extended-types/index.js"), exports);
29
29
  tslib_1.__exportStar(require("./decorators/http-operation-entity.decorator.js"), exports);
30
30
  tslib_1.__exportStar(require("./factory/api-document.factory.js"), exports);
31
31
  tslib_1.__exportStar(require("./http/http-api.js"), exports);
32
+ tslib_1.__exportStar(require("./http/http-controller.js"), exports);
32
33
  tslib_1.__exportStar(require("./http/http-media-type.js"), exports);
33
34
  tslib_1.__exportStar(require("./http/http-multipart-field.js"), exports);
34
35
  tslib_1.__exportStar(require("./http/http-operation.js"), exports);
35
36
  tslib_1.__exportStar(require("./http/http-operation-response.js"), exports);
36
37
  tslib_1.__exportStar(require("./http/http-parameter.js"), exports);
37
38
  tslib_1.__exportStar(require("./http/http-request-body.js"), exports);
38
- tslib_1.__exportStar(require("./http/http-controller.js"), exports);
39
39
  tslib_1.__exportStar(require("./http/http-status-range.js"), exports);
40
40
  var classes;
41
41
  (function (classes) {
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./opra-exception.js"), exports);
5
- tslib_1.__exportStar(require("./opra-http-error.js"), exports);
6
4
  tslib_1.__exportStar(require("./error-issue.js"), exports);
7
- tslib_1.__exportStar(require("./issue-severity.enum.js"), exports);
8
5
  tslib_1.__exportStar(require("./http-errors/bad-request.error.js"), exports);
9
6
  tslib_1.__exportStar(require("./http-errors/conflict.error.js"), exports);
10
7
  tslib_1.__exportStar(require("./http-errors/failed-dependency.error.js"), exports);
@@ -13,8 +10,11 @@ tslib_1.__exportStar(require("./http-errors/internal-server.error.js"), exports)
13
10
  tslib_1.__exportStar(require("./http-errors/method-not-allowed.error.js"), exports);
14
11
  tslib_1.__exportStar(require("./http-errors/not-acceptable.error.js"), exports);
15
12
  tslib_1.__exportStar(require("./http-errors/not-found.error.js"), exports);
16
- tslib_1.__exportStar(require("./http-errors/unauthorized.error.js"), exports);
17
- tslib_1.__exportStar(require("./http-errors/unprocessable-entity.error.js"), exports);
18
13
  tslib_1.__exportStar(require("./http-errors/permission.error.js"), exports);
19
14
  tslib_1.__exportStar(require("./http-errors/resource-conflict.error.js"), exports);
20
15
  tslib_1.__exportStar(require("./http-errors/resource-not.available.error.js"), exports);
16
+ tslib_1.__exportStar(require("./http-errors/unauthorized.error.js"), exports);
17
+ tslib_1.__exportStar(require("./http-errors/unprocessable-entity.error.js"), exports);
18
+ tslib_1.__exportStar(require("./issue-severity.enum.js"), exports);
19
+ tslib_1.__exportStar(require("./opra-exception.js"), exports);
20
+ tslib_1.__exportStar(require("./opra-http-error.js"), exports);