@opra/common 1.4.3 → 1.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/browser/index.cjs +1 -1
  2. package/browser/index.mjs +1 -1
  3. package/cjs/document/api-document.js +3 -1
  4. package/cjs/document/common/api-base.js +2 -1
  5. package/cjs/document/common/data-type-map.js +14 -3
  6. package/cjs/document/common/value.js +3 -1
  7. package/cjs/document/data-type/api-field.js +3 -1
  8. package/cjs/document/data-type/complex-type-base.js +12 -4
  9. package/cjs/document/data-type/complex-type.js +6 -2
  10. package/cjs/document/data-type/enum-type.js +3 -1
  11. package/cjs/document/data-type/extended-types/date-time.type.js +5 -1
  12. package/cjs/document/data-type/extended-types/date.type.js +5 -1
  13. package/cjs/document/data-type/extended-types/field-path.type.js +3 -1
  14. package/cjs/document/data-type/extended-types/filter.type.js +3 -1
  15. package/cjs/document/data-type/mapped-type.js +15 -6
  16. package/cjs/document/data-type/mixin-type.js +3 -1
  17. package/cjs/document/data-type/primitive-types/bigint.type.js +3 -1
  18. package/cjs/document/data-type/primitive-types/integer.type.js +3 -1
  19. package/cjs/document/data-type/primitive-types/number.type.js +3 -1
  20. package/cjs/document/data-type/primitive-types/string.type.js +3 -1
  21. package/cjs/document/data-type/simple-type.js +7 -2
  22. package/cjs/document/data-type/utils/create-mapped-class.js +3 -1
  23. package/cjs/document/decorators/api-field-decorator.js +2 -1
  24. package/cjs/document/decorators/http-controller.decorator.js +7 -1
  25. package/cjs/document/decorators/http-operation-entity.decorator.js +20 -10
  26. package/cjs/document/decorators/http-operation.decorator.js +23 -10
  27. package/cjs/document/decorators/rpc-operation.decorator.js +1 -2
  28. package/cjs/document/decorators/simple-type.decorator.js +2 -1
  29. package/cjs/document/factory/api-document.factory.js +11 -3
  30. package/cjs/document/factory/data-type.factory.js +19 -7
  31. package/cjs/document/factory/http-api.factory.js +13 -4
  32. package/cjs/document/http/http-controller.js +2 -1
  33. package/cjs/document/http/http-media-type.js +15 -5
  34. package/cjs/document/http/http-operation-response.js +8 -3
  35. package/cjs/document/http/http-operation.js +3 -1
  36. package/cjs/document/http/http-status-range.js +3 -1
  37. package/cjs/document/rpc/rpc-operation-response.js +11 -3
  38. package/cjs/document/rpc/rpc-operation.js +11 -3
  39. package/cjs/document/utils/parse-regexp.util.js +2 -2
  40. package/cjs/exception/opra-exception.js +3 -1
  41. package/cjs/filter/antlr/OpraFilterLexer.js +190 -123
  42. package/cjs/filter/antlr/OpraFilterParser.js +53 -35
  43. package/cjs/filter/ast/expressions/arithmetic-expression.js +3 -1
  44. package/cjs/filter/ast/terms/number-literal.js +3 -1
  45. package/cjs/filter/filter-rules.js +13 -4
  46. package/cjs/filter/filter-tree-visitor.js +2 -1
  47. package/cjs/filter/opra-error-listener.js +7 -1
  48. package/cjs/filter/parse.js +3 -1
  49. package/cjs/filter/utils.js +3 -1
  50. package/cjs/helpers/get-stack-filename.js +6 -2
  51. package/cjs/helpers/mixin-utils.js +7 -2
  52. package/cjs/helpers/object-utils.js +3 -1
  53. package/cjs/helpers/parse-fields-projection.js +4 -2
  54. package/cjs/helpers/type-guards.js +7 -2
  55. package/cjs/i18n/i18n.js +13 -3
  56. package/cjs/i18n/translate.js +3 -1
  57. package/cjs/polifils/array-find-last.js +0 -2
  58. package/esm/document/api-document.js +4 -2
  59. package/esm/document/common/api-base.js +2 -1
  60. package/esm/document/common/data-type-map.js +14 -3
  61. package/esm/document/common/value.js +3 -1
  62. package/esm/document/data-type/api-field.js +3 -1
  63. package/esm/document/data-type/complex-type-base.js +13 -5
  64. package/esm/document/data-type/complex-type.js +6 -2
  65. package/esm/document/data-type/data-type.js +1 -1
  66. package/esm/document/data-type/enum-type.js +3 -1
  67. package/esm/document/data-type/extended-types/date-time.type.js +5 -1
  68. package/esm/document/data-type/extended-types/date.type.js +5 -1
  69. package/esm/document/data-type/extended-types/field-path.type.js +3 -1
  70. package/esm/document/data-type/extended-types/filter.type.js +3 -1
  71. package/esm/document/data-type/mapped-type.js +15 -6
  72. package/esm/document/data-type/mixin-type.js +4 -2
  73. package/esm/document/data-type/primitive-types/bigint.type.js +3 -1
  74. package/esm/document/data-type/primitive-types/integer.type.js +3 -1
  75. package/esm/document/data-type/primitive-types/number.type.js +3 -1
  76. package/esm/document/data-type/primitive-types/string.type.js +3 -1
  77. package/esm/document/data-type/simple-type.js +8 -3
  78. package/esm/document/data-type/utils/create-mapped-class.js +4 -2
  79. package/esm/document/decorators/api-field-decorator.js +2 -1
  80. package/esm/document/decorators/complex-type.decorator.js +1 -1
  81. package/esm/document/decorators/http-controller.decorator.js +7 -1
  82. package/esm/document/decorators/http-operation-entity.decorator.js +22 -12
  83. package/esm/document/decorators/http-operation.decorator.js +23 -10
  84. package/esm/document/decorators/rpc-operation.decorator.js +1 -2
  85. package/esm/document/decorators/simple-type.decorator.js +3 -2
  86. package/esm/document/factory/api-document.factory.js +11 -3
  87. package/esm/document/factory/data-type.factory.js +21 -9
  88. package/esm/document/factory/http-api.factory.js +13 -4
  89. package/esm/document/http/http-controller.js +3 -2
  90. package/esm/document/http/http-media-type.js +15 -5
  91. package/esm/document/http/http-operation-response.js +8 -3
  92. package/esm/document/http/http-operation.js +4 -2
  93. package/esm/document/http/http-parameter.js +1 -1
  94. package/esm/document/http/http-status-range.js +3 -1
  95. package/esm/document/rpc/rpc-controller.js +1 -1
  96. package/esm/document/rpc/rpc-header.js +1 -1
  97. package/esm/document/rpc/rpc-operation-response.js +11 -3
  98. package/esm/document/rpc/rpc-operation.js +12 -4
  99. package/esm/document/utils/parse-regexp.util.js +2 -2
  100. package/esm/exception/opra-exception.js +3 -1
  101. package/esm/filter/antlr/OpraFilterLexer.js +190 -123
  102. package/esm/filter/antlr/OpraFilterParser.js +53 -35
  103. package/esm/filter/ast/expressions/arithmetic-expression.js +3 -1
  104. package/esm/filter/ast/terms/number-literal.js +3 -1
  105. package/esm/filter/filter-rules.js +13 -4
  106. package/esm/filter/filter-tree-visitor.js +2 -1
  107. package/esm/filter/opra-error-listener.js +8 -2
  108. package/esm/filter/parse.js +3 -1
  109. package/esm/filter/utils.js +3 -1
  110. package/esm/helpers/get-stack-filename.js +6 -2
  111. package/esm/helpers/mixin-utils.js +7 -2
  112. package/esm/helpers/object-utils.js +3 -1
  113. package/esm/helpers/parse-fields-projection.js +4 -2
  114. package/esm/helpers/type-guards.js +7 -2
  115. package/esm/i18n/i18n.js +13 -3
  116. package/esm/i18n/translate.js +3 -1
  117. package/esm/polifils/array-find-last.js +0 -2
  118. package/package.json +1 -1
@@ -1,11 +1,13 @@
1
- import { inheritPropertyInitializers, mergePrototype } from '../../../helpers/index.js';
1
+ import { inheritPropertyInitializers, mergePrototype, } from '../../../helpers/index.js';
2
2
  import { OpraSchema } from '../../../schema/index.js';
3
3
  import { DATATYPE_METADATA } from '../../constants.js';
4
4
  import { MappedType } from '../mapped-type.js';
5
5
  import { getIsInheritedPredicateFn } from './get-is-inherited-predicate-fn.js';
6
6
  export function createMappedClass(source, config, options) {
7
7
  const isInheritedPredicate = getIsInheritedPredicateFn(config.pick, config.omit);
8
- const sourceName = typeof source === 'string' ? source.charAt(0).toUpperCase() + source.substring(1) : source.name;
8
+ const sourceName = typeof source === 'string'
9
+ ? source.charAt(0).toUpperCase() + source.substring(1)
10
+ : source.name;
9
11
  const className = options?.name || sourceName + 'Mapped';
10
12
  const MappedClass = {
11
13
  [className]: class {
@@ -4,7 +4,8 @@ export function ApiFieldDecorator(options) {
4
4
  return function (target, propertyKey) {
5
5
  if (typeof propertyKey !== 'string')
6
6
  throw new TypeError(`Symbol properties can't be used as a field`);
7
- const metadata = Reflect.getOwnMetadata(DATATYPE_METADATA, target.constructor) || {};
7
+ const metadata = Reflect.getOwnMetadata(DATATYPE_METADATA, target.constructor) ||
8
+ {};
8
9
  metadata.kind = OpraSchema.ComplexType.Kind;
9
10
  metadata.fields = metadata.fields || {};
10
11
  const designType = Reflect.getMetadata('design:type', target, propertyKey);
@@ -1,6 +1,6 @@
1
1
  import { omit } from '@jsopen/objects';
2
2
  import { OpraSchema } from '../../schema/index.js';
3
- import { CLASS_NAME_PATTERN, DATATYPE_METADATA, EXTRACT_TYPENAME_PATTERN } from '../constants.js';
3
+ import { CLASS_NAME_PATTERN, DATATYPE_METADATA, EXTRACT_TYPENAME_PATTERN, } from '../constants.js';
4
4
  export function ComplexTypeDecorator(options) {
5
5
  return function (target) {
6
6
  let name;
@@ -22,7 +22,13 @@ export function HttpControllerDecoratorFactory(options) {
22
22
  kind: OpraSchema.HttpController.Kind,
23
23
  name,
24
24
  path: name,
25
- ...omit(options, ['kind', 'name', 'instance', 'endpoints', 'key']),
25
+ ...omit(options, [
26
+ 'kind',
27
+ 'name',
28
+ 'instance',
29
+ 'endpoints',
30
+ 'key',
31
+ ]),
26
32
  }, { deep: true });
27
33
  Reflect.defineMetadata(HTTP_CONTROLLER_METADATA, metadata, target);
28
34
  for (const fn of decoratorChain)
@@ -1,10 +1,10 @@
1
1
  import { HttpStatusCode, MimeTypes } from '../../enums/index.js';
2
2
  import { FilterRules } from '../../filter/filter-rules.js';
3
3
  import { DATATYPE_METADATA } from '../constants.js';
4
- import { FieldPathType, FilterType } from '../data-type/extended-types/index.js';
4
+ import { FieldPathType, FilterType, } from '../data-type/extended-types/index.js';
5
5
  import { IntegerType } from '../data-type/primitive-types/index.js';
6
6
  import { HttpOperation } from '../http/http-operation.js';
7
- import { HttpOperationDecoratorFactory } from './http-operation.decorator.js';
7
+ import { HttpOperationDecoratorFactory, } from './http-operation.decorator.js';
8
8
  /** Implementation **/
9
9
  HttpOperation.Entity = {};
10
10
  /**
@@ -51,7 +51,8 @@ HttpOperation.Entity.Create = function (arg0, arg1) {
51
51
  contentType: MimeTypes.opra_response_json,
52
52
  });
53
53
  decoratorChain.push((operationMeta) => {
54
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
54
+ const compositionOptions = (operationMeta.compositionOptions =
55
+ operationMeta.compositionOptions || {});
55
56
  compositionOptions.type = getDataTypeName(args.type);
56
57
  });
57
58
  return decorator;
@@ -108,7 +109,8 @@ HttpOperation.Entity.Delete = function (arg0, arg1) {
108
109
  return decorator;
109
110
  };
110
111
  decoratorChain.push((operationMeta) => {
111
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
112
+ const compositionOptions = (operationMeta.compositionOptions =
113
+ operationMeta.compositionOptions || {});
112
114
  compositionOptions.type = getDataTypeName(args.type);
113
115
  });
114
116
  return decorator;
@@ -147,7 +149,8 @@ HttpOperation.Entity.DeleteMany = function (arg0, arg1) {
147
149
  description: 'Determines filter fields',
148
150
  });
149
151
  decoratorChain.push((operationMeta) => {
150
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
152
+ const compositionOptions = (operationMeta.compositionOptions =
153
+ operationMeta.compositionOptions || {});
151
154
  compositionOptions.type = getDataTypeName(args.type);
152
155
  });
153
156
  decorator.Filter = (field, operators, description) => {
@@ -226,7 +229,8 @@ HttpOperation.Entity.FindMany = function (arg0, arg1) {
226
229
  arraySeparator: ',',
227
230
  });
228
231
  decoratorChain.push((operationMeta) => {
229
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
232
+ const compositionOptions = (operationMeta.compositionOptions =
233
+ operationMeta.compositionOptions || {});
230
234
  compositionOptions.type = getDataTypeName(args.type);
231
235
  if (args.defaultLimit)
232
236
  compositionOptions.defaultLimit = args.defaultLimit;
@@ -237,14 +241,16 @@ HttpOperation.Entity.FindMany = function (arg0, arg1) {
237
241
  });
238
242
  decorator.DefaultSort = (...fields) => {
239
243
  decoratorChain.push((operationMeta) => {
240
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
244
+ const compositionOptions = (operationMeta.compositionOptions =
245
+ operationMeta.compositionOptions || {});
241
246
  compositionOptions.defaultSort = fields;
242
247
  });
243
248
  return decorator;
244
249
  };
245
250
  decorator.SortFields = (...fields) => {
246
251
  decoratorChain.push((operationMeta) => {
247
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
252
+ const compositionOptions = (operationMeta.compositionOptions =
253
+ operationMeta.compositionOptions || {});
248
254
  compositionOptions.sortFields = fields;
249
255
  });
250
256
  return decorator;
@@ -324,7 +330,8 @@ HttpOperation.Entity.Get = function (arg0, arg1) {
324
330
  return decorator;
325
331
  };
326
332
  decoratorChain.push((operationMeta) => {
327
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
333
+ const compositionOptions = (operationMeta.compositionOptions =
334
+ operationMeta.compositionOptions || {});
328
335
  compositionOptions.type = getDataTypeName(args.type);
329
336
  });
330
337
  return decorator;
@@ -395,7 +402,8 @@ HttpOperation.Entity.Replace = function (arg0, arg1) {
395
402
  return decorator;
396
403
  };
397
404
  decoratorChain.push((operationMeta) => {
398
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
405
+ const compositionOptions = (operationMeta.compositionOptions =
406
+ operationMeta.compositionOptions || {});
399
407
  compositionOptions.type = getDataTypeName(args.type);
400
408
  });
401
409
  return decorator;
@@ -442,7 +450,8 @@ HttpOperation.Entity.UpdateMany = function (arg0, arg1) {
442
450
  description: 'Determines filter fields',
443
451
  });
444
452
  decoratorChain.push((operationMeta) => {
445
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
453
+ const compositionOptions = (operationMeta.compositionOptions =
454
+ operationMeta.compositionOptions || {});
446
455
  compositionOptions.type = getDataTypeName(args.type);
447
456
  });
448
457
  decorator.Filter = (field, operators, description) => {
@@ -535,7 +544,8 @@ HttpOperation.Entity.Update = function (arg0, arg1) {
535
544
  return decorator;
536
545
  };
537
546
  decoratorChain.push((operationMeta) => {
538
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
547
+ const compositionOptions = (operationMeta.compositionOptions =
548
+ operationMeta.compositionOptions || {});
539
549
  compositionOptions.type = getDataTypeName(args.type);
540
550
  });
541
551
  decorator.Filter = (field, operators, description) => {
@@ -12,8 +12,7 @@ export function HttpOperationDecoratorFactory(decoratorChain, options) {
12
12
  ...options,
13
13
  kind: OpraSchema.HttpOperation.Kind,
14
14
  };
15
- const controllerMetadata = (Reflect.getOwnMetadata(HTTP_CONTROLLER_METADATA, target.constructor) ||
16
- {});
15
+ const controllerMetadata = (Reflect.getOwnMetadata(HTTP_CONTROLLER_METADATA, target.constructor) || {});
17
16
  controllerMetadata.operations = controllerMetadata.operations || {};
18
17
  controllerMetadata.operations[propertyKey] = operationMetadata;
19
18
  for (const fn of decoratorChain)
@@ -108,9 +107,13 @@ export function HttpOperationDecoratorFactory(decoratorChain, options) {
108
107
  *
109
108
  */
110
109
  decorator.Response = (statusCode, responseOptions) => {
111
- const responseMeta = { ...responseOptions, statusCode };
110
+ const responseMeta = {
111
+ ...responseOptions,
112
+ statusCode,
113
+ };
112
114
  if (responseMeta.type) {
113
- responseMeta.contentType = responseMeta.contentType || MimeTypes.opra_response_json;
115
+ responseMeta.contentType =
116
+ responseMeta.contentType || MimeTypes.opra_response_json;
114
117
  responseMeta.contentEncoding = responseMeta.contentEncoding || 'utf-8';
115
118
  }
116
119
  if (responseMeta.contentType === MimeTypes.opra_response_json) {
@@ -129,8 +132,12 @@ export function HttpOperationDecoratorFactory(decoratorChain, options) {
129
132
  contentMeta.contentEncoding = contentMeta.contentEncoding || 'utf-8';
130
133
  }
131
134
  decoratorChain.push((operationMetadata) => {
132
- operationMetadata.requestBody = operationMetadata.requestBody || { required: true, content: [] };
133
- operationMetadata.requestBody.content = operationMetadata.requestBody.content || [];
135
+ operationMetadata.requestBody = operationMetadata.requestBody || {
136
+ required: true,
137
+ content: [],
138
+ };
139
+ operationMetadata.requestBody.content =
140
+ operationMetadata.requestBody.content || [];
134
141
  operationMetadata.requestBody.content.push(contentMeta);
135
142
  });
136
143
  return decorator;
@@ -141,14 +148,19 @@ export function HttpOperationDecoratorFactory(decoratorChain, options) {
141
148
  contentType: contentOpts?.contentType || 'multipart/form-data',
142
149
  };
143
150
  decoratorChain.push((operationMetadata) => {
144
- operationMetadata.requestBody = operationMetadata.requestBody || { required: true, content: [] };
145
- operationMetadata.requestBody.content = operationMetadata.requestBody.content || [];
151
+ operationMetadata.requestBody = operationMetadata.requestBody || {
152
+ required: true,
153
+ content: [],
154
+ };
155
+ operationMetadata.requestBody.content =
156
+ operationMetadata.requestBody.content || [];
146
157
  operationMetadata.requestBody.content.push(contentMetadata);
147
158
  });
148
159
  if (subInit) {
149
160
  const configScope = {
150
161
  Field(fieldName, opts) {
151
- contentMetadata.multipartFields = contentMetadata.multipartFields || [];
162
+ contentMetadata.multipartFields =
163
+ contentMetadata.multipartFields || [];
152
164
  contentMetadata.multipartFields.push({
153
165
  fieldName,
154
166
  fieldType: 'field',
@@ -157,7 +169,8 @@ export function HttpOperationDecoratorFactory(decoratorChain, options) {
157
169
  return configScope;
158
170
  },
159
171
  File(fieldName, opts) {
160
- contentMetadata.multipartFields = contentMetadata.multipartFields || [];
172
+ contentMetadata.multipartFields =
173
+ contentMetadata.multipartFields || [];
161
174
  contentMetadata.multipartFields.push({
162
175
  fieldName,
163
176
  fieldType: 'file',
@@ -16,8 +16,7 @@ export function RpcOperationDecoratorFactory(decoratorChain, payloadType, option
16
16
  payloadType,
17
17
  ...omit(options, ['kind', 'payloadType']),
18
18
  };
19
- const controllerMetadata = (Reflect.getOwnMetadata(RPC_CONTROLLER_METADATA, target.constructor) ||
20
- {});
19
+ const controllerMetadata = (Reflect.getOwnMetadata(RPC_CONTROLLER_METADATA, target.constructor) || {});
21
20
  controllerMetadata.operations = controllerMetadata.operations || {};
22
21
  controllerMetadata.operations[propertyKey] = operationMetadata;
23
22
  for (const fn of decoratorChain)
@@ -1,5 +1,5 @@
1
1
  import { OpraSchema } from '../../schema/index.js';
2
- import { CLASS_NAME_PATTERN, DATATYPE_METADATA, EXTRACT_TYPENAME_PATTERN } from '../constants.js';
2
+ import { CLASS_NAME_PATTERN, DATATYPE_METADATA, EXTRACT_TYPENAME_PATTERN, } from '../constants.js';
3
3
  export function SimpleTypeDecoratorFactory(options) {
4
4
  const decoratorChain = [];
5
5
  /**
@@ -41,7 +41,8 @@ export function AttributeDecoratorFactory(options) {
41
41
  return (target, propertyKey) => {
42
42
  if (typeof propertyKey !== 'string')
43
43
  throw new TypeError(`Symbol properties can't be decorated with Attribute`);
44
- const metadata = Reflect.getOwnMetadata(DATATYPE_METADATA, target.constructor) || {};
44
+ const metadata = Reflect.getOwnMetadata(DATATYPE_METADATA, target.constructor) ||
45
+ {};
45
46
  const designType = Reflect.getMetadata('design:type', target, propertyKey);
46
47
  let format = 'string';
47
48
  if (designType === Boolean)
@@ -22,7 +22,9 @@ export class ApiDocumentFactory {
22
22
  */
23
23
  static async createDocument(schemaOrUrl, options) {
24
24
  const factory = new ApiDocumentFactory();
25
- const context = options instanceof DocumentInitContext ? options : new DocumentInitContext(options);
25
+ const context = options instanceof DocumentInitContext
26
+ ? options
27
+ : new DocumentInitContext(options);
26
28
  try {
27
29
  const document = new ApiDocument();
28
30
  await factory.initDocument(document, context, schemaOrUrl);
@@ -110,12 +112,18 @@ export class ApiDocumentFactory {
110
112
  if (init.api) {
111
113
  await context.enterAsync(`.api`, async () => {
112
114
  if (init.api && init.api.transport === 'http') {
113
- const api = await HttpApiFactory.createApi(context, { ...init.api, owner: document });
115
+ const api = await HttpApiFactory.createApi(context, {
116
+ ...init.api,
117
+ owner: document,
118
+ });
114
119
  if (api)
115
120
  document.api = api;
116
121
  }
117
122
  else if (init.api && init.api.transport === 'rpc') {
118
- const api = await RpcApiFactory.createApi(context, { ...init.api, owner: document });
123
+ const api = await RpcApiFactory.createApi(context, {
124
+ ...init.api,
125
+ owner: document,
126
+ });
119
127
  if (api)
120
128
  document.api = api;
121
129
  }
@@ -1,7 +1,7 @@
1
- import { cloneObject, resolveThunk, ResponsiveMap } from '../../helpers/index.js';
1
+ import { cloneObject, resolveThunk, ResponsiveMap, } from '../../helpers/index.js';
2
2
  import { OpraSchema } from '../../schema/index.js';
3
3
  import { DocumentInitContext } from '../common/document-init-context.js';
4
- import { DATATYPE_METADATA, DECODER, ENCODER, kCtorMap, kDataTypeMap } from '../constants.js';
4
+ import { DATATYPE_METADATA, DECODER, ENCODER, kCtorMap, kDataTypeMap, } from '../constants.js';
5
5
  import { ComplexType } from '../data-type/complex-type.js';
6
6
  import { ComplexTypeBase } from '../data-type/complex-type-base.js';
7
7
  import { DataType } from '../data-type/data-type.js';
@@ -110,7 +110,8 @@ export class DataTypeFactory {
110
110
  for (let thunk of types) {
111
111
  await context.enterAsync(`$[${i++}]`, async () => {
112
112
  thunk = await resolveThunk(thunk);
113
- const metadata = Reflect.getMetadata(DATATYPE_METADATA, thunk) || thunk[DATATYPE_METADATA];
113
+ const metadata = Reflect.getMetadata(DATATYPE_METADATA, thunk) ||
114
+ thunk[DATATYPE_METADATA];
114
115
  if (!(metadata && metadata.name)) {
115
116
  if (typeof thunk === 'function') {
116
117
  return context.addError(`Class "${thunk.name}" doesn't have a valid data type metadata`);
@@ -200,7 +201,8 @@ export class DataTypeFactory {
200
201
  const baseArgs = await this._importDataTypeArgs(context, owner, metadata.name);
201
202
  if (!baseArgs)
202
203
  return;
203
- if (typeof baseArgs === 'object' && baseArgs.kind !== OpraSchema.SimpleType.Kind) {
204
+ if (typeof baseArgs === 'object' &&
205
+ baseArgs.kind !== OpraSchema.SimpleType.Kind) {
204
206
  return context.addError('Kind of base data type is not same');
205
207
  }
206
208
  return {
@@ -300,7 +302,8 @@ export class DataTypeFactory {
300
302
  });
301
303
  // Initialize additionalFields
302
304
  if (metadata.additionalFields != null) {
303
- if (typeof metadata.additionalFields === 'boolean' || Array.isArray(metadata.additionalFields)) {
305
+ if (typeof metadata.additionalFields === 'boolean' ||
306
+ Array.isArray(metadata.additionalFields)) {
304
307
  initArgs.additionalFields = metadata.additionalFields;
305
308
  }
306
309
  else {
@@ -398,10 +401,14 @@ export class DataTypeFactory {
398
401
  else if (metadata.omit)
399
402
  initArgs.omit = [...metadata.omit];
400
403
  else if (metadata.partial) {
401
- initArgs.partial = Array.isArray(metadata.partial) ? [...metadata.partial] : metadata.partial;
404
+ initArgs.partial = Array.isArray(metadata.partial)
405
+ ? [...metadata.partial]
406
+ : metadata.partial;
402
407
  }
403
408
  else if (metadata.required) {
404
- initArgs.required = Array.isArray(metadata.required) ? [...metadata.required] : metadata.required;
409
+ initArgs.required = Array.isArray(metadata.required)
410
+ ? [...metadata.required]
411
+ : metadata.required;
405
412
  }
406
413
  }
407
414
  static async _prepareMixinTypeArgs(context, owner, initArgs, metadata) {
@@ -462,7 +469,8 @@ export class DataTypeFactory {
462
469
  /** Set additionalFields */
463
470
  if (args.additionalFields) {
464
471
  context.enter('.additionalFields', () => {
465
- if (typeof args.additionalFields === 'boolean' || Array.isArray(args.additionalFields)) {
472
+ if (typeof args.additionalFields === 'boolean' ||
473
+ Array.isArray(args.additionalFields)) {
466
474
  initArgs.additionalFields = args.additionalFields;
467
475
  }
468
476
  else {
@@ -552,5 +560,9 @@ export class DataTypeFactory {
552
560
  }
553
561
  }
554
562
  function preferName(initArgs) {
555
- return typeof initArgs === 'object' ? (initArgs.name ? initArgs.name : initArgs) : initArgs;
563
+ return typeof initArgs === 'object'
564
+ ? initArgs.name
565
+ ? initArgs.name
566
+ : initArgs
567
+ : initArgs;
556
568
  }
@@ -68,7 +68,8 @@ export class HttpApiFactory {
68
68
  }
69
69
  static async _resolveControllerMetadata(context, parent, thunk) {
70
70
  if (typeof thunk === 'function' && !isConstructor(thunk)) {
71
- thunk = parent instanceof HttpController ? thunk(parent.instance) : thunk();
71
+ thunk =
72
+ parent instanceof HttpController ? thunk(parent.instance) : thunk();
72
73
  }
73
74
  thunk = await resolveThunk(thunk);
74
75
  let ctor;
@@ -132,7 +133,10 @@ export class HttpApiFactory {
132
133
  await context.enterAsync('.operations', async () => {
133
134
  for (const [k, v] of Object.entries(metadata.operations)) {
134
135
  await context.enterAsync(`[${k}]`, async () => {
135
- const operation = new HttpOperation(controller, { name: k, method: 'GET' });
136
+ const operation = new HttpOperation(controller, {
137
+ name: k,
138
+ method: 'GET',
139
+ });
136
140
  await this._initHttpOperation(context, operation, v);
137
141
  controller.operations.set(k, operation);
138
142
  });
@@ -185,7 +189,9 @@ export class HttpApiFactory {
185
189
  let i = 0;
186
190
  for (const v of metadata.responses) {
187
191
  await context.enterAsync(`[${i++}]`, async () => {
188
- const response = new HttpOperationResponse(operation, { statusCode: v.statusCode });
192
+ const response = new HttpOperationResponse(operation, {
193
+ statusCode: v.statusCode,
194
+ });
189
195
  await this._initHttpOperationResponse(context, response, v);
190
196
  operation.responses.push(response);
191
197
  });
@@ -224,7 +230,10 @@ export class HttpApiFactory {
224
230
  for (let i = 0; i < metadata.multipartFields.length; i++) {
225
231
  await context.enterAsync(`[${i}]`, async () => {
226
232
  const src = metadata.multipartFields[i];
227
- const field = new HttpMultipartField(target, { fieldName: src.fieldName, fieldType: src.fieldType });
233
+ const field = new HttpMultipartField(target, {
234
+ fieldName: src.fieldName,
235
+ fieldType: src.fieldType,
236
+ });
228
237
  await this._initHttpMediaType(context, field, src);
229
238
  target.multipartFields.push(field);
230
239
  });
@@ -7,7 +7,7 @@ import { DataTypeMap } from '../common/data-type-map.js';
7
7
  import { DocumentElement } from '../common/document-element.js';
8
8
  import { CLASS_NAME_PATTERN, DECORATOR, kDataTypeMap } from '../constants.js';
9
9
  import { HttpControllerDecoratorFactory } from '../decorators/http-controller.decorator.js';
10
- import { colorFgMagenta, colorFgYellow, colorReset, nodeInspectCustom } from '../utils/inspect.util.js';
10
+ import { colorFgMagenta, colorFgYellow, colorReset, nodeInspectCustom, } from '../utils/inspect.util.js';
11
11
  /**
12
12
  * HttpController
13
13
  */
@@ -94,7 +94,8 @@ class HttpControllerClass extends DocumentElement {
94
94
  if (prm.name instanceof RegExp && prm.name.test(paramName))
95
95
  return prm;
96
96
  }
97
- if (this.node.parent && this.node.parent.element instanceof HttpController) {
97
+ if (this.node.parent &&
98
+ this.node.parent.element instanceof HttpController) {
98
99
  return this.node.parent.element.findParameter(paramName, location);
99
100
  }
100
101
  }
@@ -10,7 +10,9 @@ export const HttpMediaType = function (owner, initArgs) {
10
10
  DocumentElement.call(this, owner);
11
11
  const _this = asMutable(this);
12
12
  if (initArgs.contentType) {
13
- let arr = Array.isArray(initArgs.contentType) ? initArgs.contentType : [initArgs.contentType];
13
+ let arr = Array.isArray(initArgs.contentType)
14
+ ? initArgs.contentType
15
+ : [initArgs.contentType];
14
16
  arr = arr.map(x => x.split(/\s*,\s*/)).flat();
15
17
  _this.contentType = arr.length > 1 ? arr : arr[0];
16
18
  }
@@ -24,7 +26,10 @@ export const HttpMediaType = function (owner, initArgs) {
24
26
  _this.maxFileSize = initArgs.maxFileSize;
25
27
  _this.maxTotalFileSize = initArgs.maxTotalFileSize;
26
28
  if (initArgs?.type) {
27
- _this.type = initArgs?.type instanceof DataType ? initArgs.type : _this.owner.node.getDataType(initArgs.type);
29
+ _this.type =
30
+ initArgs?.type instanceof DataType
31
+ ? initArgs.type
32
+ : _this.owner.node.getDataType(initArgs.type);
28
33
  }
29
34
  _this.isArray = initArgs.isArray;
30
35
  };
@@ -37,13 +42,16 @@ class HttpMediaTypeClass extends DocumentElement {
37
42
  return;
38
43
  for (const f of this.multipartFields) {
39
44
  if ((!fieldType || fieldType === f.fieldType) &&
40
- ((f.fieldName instanceof RegExp && f.fieldName.test(fieldName)) || f.fieldName === fieldName)) {
45
+ ((f.fieldName instanceof RegExp && f.fieldName.test(fieldName)) ||
46
+ f.fieldName === fieldName)) {
41
47
  return f;
42
48
  }
43
49
  }
44
50
  }
45
51
  toJSON() {
46
- const typeName = this.type ? this.node.getDataTypeNameWithNs(this.type) : undefined;
52
+ const typeName = this.type
53
+ ? this.node.getDataTypeNameWithNs(this.type)
54
+ : undefined;
47
55
  const out = omitUndefined({
48
56
  description: this.description,
49
57
  contentType: this.contentType,
@@ -69,7 +77,9 @@ class HttpMediaTypeClass extends DocumentElement {
69
77
  fn = this.type.generateCodec(codec, options);
70
78
  }
71
79
  else if (this.contentType) {
72
- const arr = Array.isArray(this.contentType) ? this.contentType : [this.contentType];
80
+ const arr = Array.isArray(this.contentType)
81
+ ? this.contentType
82
+ : [this.contentType];
73
83
  if (arr.find(ct => typeIs.is(ct, ['json']))) {
74
84
  fn = this.node.findDataType('object').generateCodec(codec);
75
85
  }
@@ -8,14 +8,17 @@ export class HttpOperationResponse extends HttpMediaType {
8
8
  constructor(owner, init) {
9
9
  super(owner, init);
10
10
  this.parameters = [];
11
- this.statusCode = (Array.isArray(init.statusCode) ? init.statusCode : [init.statusCode]).map(x => typeof x === 'object' ? new HttpStatusRange(x.start, x.end) : new HttpStatusRange(x));
11
+ this.statusCode = (Array.isArray(init.statusCode) ? init.statusCode : [init.statusCode]).map(x => typeof x === 'object'
12
+ ? new HttpStatusRange(x.start, x.end)
13
+ : new HttpStatusRange(x));
12
14
  this.partial = init.partial;
13
15
  }
14
16
  findParameter(paramName, location) {
15
17
  paramName = paramName.toLowerCase();
16
18
  for (const prm of this.parameters) {
17
19
  if ((!location || location === prm.location) &&
18
- ((prm.name instanceof RegExp && prm.name.test(paramName)) || prm.name === paramName)) {
20
+ ((prm.name instanceof RegExp && prm.name.test(paramName)) ||
21
+ prm.name === paramName)) {
19
22
  return prm;
20
23
  }
21
24
  }
@@ -24,7 +27,9 @@ export class HttpOperationResponse extends HttpMediaType {
24
27
  const statusCode = this.statusCode.map(x => x.toJSON());
25
28
  const out = omitUndefined({
26
29
  ...super.toJSON(),
27
- statusCode: statusCode.length === 1 && typeof statusCode[0] === 'number' ? statusCode[0] : statusCode,
30
+ statusCode: statusCode.length === 1 && typeof statusCode[0] === 'number'
31
+ ? statusCode[0]
32
+ : statusCode,
28
33
  partial: this.partial,
29
34
  });
30
35
  if (this.parameters.length) {
@@ -6,7 +6,7 @@ import { OpraSchema } from '../../schema/index.js';
6
6
  import { DataTypeMap } from '../common/data-type-map.js';
7
7
  import { DocumentElement } from '../common/document-element.js';
8
8
  import { CLASS_NAME_PATTERN, DECORATOR, kDataTypeMap } from '../constants.js';
9
- import { HttpOperationDecoratorFactory } from '../decorators/http-operation.decorator.js';
9
+ import { HttpOperationDecoratorFactory, } from '../decorators/http-operation.decorator.js';
10
10
  /**
11
11
  * HttpOperation
12
12
  */
@@ -32,7 +32,9 @@ export const HttpOperation = function (...args) {
32
32
  _this.method = initArgs.method || 'GET';
33
33
  _this.description = initArgs.description;
34
34
  _this.composition = initArgs.composition;
35
- _this.compositionOptions = initArgs.compositionOptions ? cloneObject(initArgs.compositionOptions) : undefined;
35
+ _this.compositionOptions = initArgs.compositionOptions
36
+ ? cloneObject(initArgs.compositionOptions)
37
+ : undefined;
36
38
  };
37
39
  /**
38
40
  * @class HttpOperation
@@ -1,5 +1,5 @@
1
1
  import { omitUndefined } from '@jsopen/objects';
2
- import { asMutable } from 'ts-gems';
2
+ import { asMutable, } from 'ts-gems';
3
3
  import { Value } from '../common/value.js';
4
4
  import { parseRegExp } from '../utils/parse-regexp.util.js';
5
5
  export const HttpParameter = function (owner, initArgs) {
@@ -34,6 +34,8 @@ export class HttpStatusRange {
34
34
  return String(this.start) + '-' + String(this.end);
35
35
  }
36
36
  toJSON() {
37
- return !this.end || this.start === this.end ? this.start : { start: this.start, end: this.end };
37
+ return !this.end || this.start === this.end
38
+ ? this.start
39
+ : { start: this.start, end: this.end };
38
40
  }
39
41
  }
@@ -6,7 +6,7 @@ import { DataTypeMap } from '../common/data-type-map.js';
6
6
  import { DocumentElement } from '../common/document-element.js';
7
7
  import { CLASS_NAME_PATTERN, DECORATOR, kDataTypeMap } from '../constants.js';
8
8
  import { RpcControllerDecoratorFactory } from '../decorators/rpc-controller.decorator.js';
9
- import { colorFgMagenta, colorFgYellow, colorReset, nodeInspectCustom } from '../utils/inspect.util.js';
9
+ import { colorFgMagenta, colorFgYellow, colorReset, nodeInspectCustom, } from '../utils/inspect.util.js';
10
10
  /**
11
11
  * RpcController
12
12
  */
@@ -1,5 +1,5 @@
1
1
  import { omitUndefined } from '@jsopen/objects';
2
- import { asMutable } from 'ts-gems';
2
+ import { asMutable, } from 'ts-gems';
3
3
  import { Value } from '../common/value.js';
4
4
  import { parseRegExp } from '../utils/parse-regexp.util.js';
5
5
  export const RpcHeader = function (owner, initArgs) {
@@ -20,7 +20,9 @@ export class RpcOperationResponse extends DocumentElement {
20
20
  this.payloadType = this.owner.node.getDataType('any');
21
21
  if (initArgs?.keyType) {
22
22
  this.keyType =
23
- initArgs?.keyType instanceof DataType ? initArgs.keyType : this.owner.node.getDataType(initArgs.keyType);
23
+ initArgs?.keyType instanceof DataType
24
+ ? initArgs.keyType
25
+ : this.owner.node.getDataType(initArgs.keyType);
24
26
  }
25
27
  }
26
28
  findHeader(paramName) {
@@ -40,8 +42,14 @@ export class RpcOperationResponse extends DocumentElement {
40
42
  const out = omitUndefined({
41
43
  description: this.description,
42
44
  channel: this.channel,
43
- payloadType: this.payloadType.name ? this.payloadType.name : this.payloadType.toJSON(),
44
- keyType: this.keyType ? (this.keyType.name ? this.keyType.name : this.keyType.toJSON()) : undefined,
45
+ payloadType: this.payloadType.name
46
+ ? this.payloadType.name
47
+ : this.payloadType.toJSON(),
48
+ keyType: this.keyType
49
+ ? this.keyType.name
50
+ ? this.keyType.name
51
+ : this.keyType.toJSON()
52
+ : undefined,
45
53
  });
46
54
  if (this.headers.length) {
47
55
  out.headers = [];
@@ -5,7 +5,7 @@ import { DataTypeMap } from '../common/data-type-map.js';
5
5
  import { DocumentElement } from '../common/document-element.js';
6
6
  import { CLASS_NAME_PATTERN, DECORATOR, kDataTypeMap } from '../constants.js';
7
7
  import { DataType } from '../data-type/data-type.js';
8
- import { RpcOperationDecoratorFactory } from '../decorators/rpc-operation.decorator.js';
8
+ import { RpcOperationDecoratorFactory, } from '../decorators/rpc-operation.decorator.js';
9
9
  /**
10
10
  * RpcOperation
11
11
  */
@@ -35,7 +35,9 @@ export const RpcOperation = function (...args) {
35
35
  }
36
36
  if (initArgs?.keyType) {
37
37
  _this.keyType =
38
- initArgs?.keyType instanceof DataType ? initArgs.keyType : _this.owner.node.getDataType(initArgs.keyType);
38
+ initArgs?.keyType instanceof DataType
39
+ ? initArgs.keyType
40
+ : _this.owner.node.getDataType(initArgs.keyType);
39
41
  }
40
42
  };
41
43
  /**
@@ -60,8 +62,14 @@ class RpcOperationClass extends DocumentElement {
60
62
  kind: OpraSchema.RpcOperation.Kind,
61
63
  description: this.description,
62
64
  channel: this.channel,
63
- payloadType: this.payloadType.name ? this.payloadType.name : this.payloadType.toJSON(),
64
- keyType: this.keyType ? (this.keyType.name ? this.keyType.name : this.keyType.toJSON()) : undefined,
65
+ payloadType: this.payloadType.name
66
+ ? this.payloadType.name
67
+ : this.payloadType.toJSON(),
68
+ keyType: this.keyType
69
+ ? this.keyType.name
70
+ ? this.keyType.name
71
+ : this.keyType.toJSON()
72
+ : undefined,
65
73
  response: this.response?.toJSON(),
66
74
  });
67
75
  if (this.headers.length) {