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

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 (183) hide show
  1. package/browser.js +6036 -5788
  2. package/cjs/document/api-document.js +12 -0
  3. package/cjs/document/common/api-base.js +1 -0
  4. package/cjs/document/common/document-element.js +5 -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 -2
  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 -1
  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-status-range.js +6 -4
  54. package/cjs/document/index.js +5 -5
  55. package/cjs/document/utils/parse-regexp.util.js +1 -2
  56. package/cjs/document/utils/string-compare.util.js +1 -2
  57. package/cjs/exception/index.js +5 -5
  58. package/cjs/exception/opra-exception.js +1 -0
  59. package/cjs/filter/antlr/OpraFilterParser.js +28 -82
  60. package/cjs/filter/ast/index.js +1 -1
  61. package/cjs/filter/build.js +22 -25
  62. package/cjs/filter/filter-rules.js +4 -2
  63. package/cjs/filter/opra-filter.ns.js +2 -2
  64. package/cjs/filter/parse.js +2 -5
  65. package/cjs/filter/utils.js +2 -3
  66. package/cjs/helpers/function-utils.js +1 -2
  67. package/cjs/helpers/get-stack-filename.js +2 -3
  68. package/cjs/helpers/mixin-utils.js +4 -4
  69. package/cjs/helpers/monkey-patches.js +4 -2
  70. package/cjs/helpers/object-utils.js +5 -6
  71. package/cjs/helpers/parse-fields-projection.js +4 -6
  72. package/cjs/helpers/responsive-map.js +5 -4
  73. package/cjs/helpers/type-guards.js +10 -11
  74. package/cjs/i18n/i18n.js +4 -3
  75. package/cjs/i18n/index.js +1 -1
  76. package/cjs/i18n/string-utils.js +2 -3
  77. package/cjs/i18n/translate.js +1 -2
  78. package/cjs/index.js +1 -1
  79. package/cjs/schema/type-guards.js +7 -8
  80. package/esm/document/api-document.js +11 -0
  81. package/esm/document/common/api-base.js +1 -0
  82. package/esm/document/common/document-element.js +4 -1
  83. package/esm/document/data-type/api-field.js +12 -6
  84. package/esm/document/data-type/complex-type-base.js +10 -3
  85. package/esm/document/data-type/complex-type.js +6 -2
  86. package/esm/document/data-type/data-type.js +2 -1
  87. package/esm/document/data-type/enum-type.js +5 -2
  88. package/esm/document/data-type/extended-types/base64.type.js +4 -0
  89. package/esm/document/data-type/extended-types/date-string.type.js +6 -2
  90. package/esm/document/data-type/extended-types/date-time-string.type.js +6 -2
  91. package/esm/document/data-type/extended-types/date-time.type.js +6 -2
  92. package/esm/document/data-type/extended-types/date.type.js +6 -2
  93. package/esm/document/data-type/extended-types/email.type.js +6 -2
  94. package/esm/document/data-type/extended-types/field-path.type.js +5 -3
  95. package/esm/document/data-type/extended-types/filter.type.js +19 -17
  96. package/esm/document/data-type/extended-types/object-id.type.js +4 -0
  97. package/esm/document/data-type/extended-types/time.type.js +6 -2
  98. package/esm/document/data-type/extended-types/url.type.js +6 -2
  99. package/esm/document/data-type/extended-types/uuid.type.js +4 -0
  100. package/esm/document/data-type/mapped-type.js +12 -5
  101. package/esm/document/data-type/mixin-type.js +5 -1
  102. package/esm/document/data-type/omit-type.js +6 -0
  103. package/esm/document/data-type/partial-type.js +6 -0
  104. package/esm/document/data-type/primitive-types/bigint.type.js +4 -0
  105. package/esm/document/data-type/primitive-types/boolean.type.js +4 -0
  106. package/esm/document/data-type/primitive-types/integer.type.js +4 -0
  107. package/esm/document/data-type/primitive-types/null.type.js +4 -0
  108. package/esm/document/data-type/primitive-types/number.type.js +4 -0
  109. package/esm/document/data-type/primitive-types/object.type.js +0 -3
  110. package/esm/document/data-type/primitive-types/string.type.js +4 -0
  111. package/esm/document/data-type/simple-type.js +17 -16
  112. package/esm/document/data-type/utils/create-mapped-class.js +2 -1
  113. package/esm/document/decorators/api-field-decorator.js +1 -2
  114. package/esm/document/decorators/http-controller.decorator.js +25 -0
  115. package/esm/document/decorators/http-operation-entity.decorator.js +80 -50
  116. package/esm/document/decorators/http-operation.decorator.js +11 -4
  117. package/esm/document/factory/api-document.factory.js +14 -10
  118. package/esm/document/factory/data-type.factory.js +97 -56
  119. package/esm/document/factory/http-api.factory.js +3 -1
  120. package/esm/document/http/http-api.js +2 -2
  121. package/esm/document/http/http-controller.js +25 -14
  122. package/esm/document/http/http-media-type.js +20 -4
  123. package/esm/document/http/http-operation-response.js +2 -1
  124. package/esm/document/http/http-operation.js +27 -4
  125. package/esm/document/http/http-parameter.js +4 -0
  126. package/esm/document/http/http-status-range.js +6 -4
  127. package/esm/document/index.js +5 -5
  128. package/esm/exception/index.js +5 -5
  129. package/esm/exception/opra-exception.js +1 -0
  130. package/esm/filter/antlr/OpraFilterParser.js +28 -82
  131. package/esm/filter/ast/index.js +1 -1
  132. package/esm/filter/build.js +1 -3
  133. package/esm/filter/filter-rules.js +4 -2
  134. package/esm/filter/opra-filter.ns.js +2 -2
  135. package/esm/filter/parse.js +1 -3
  136. package/esm/helpers/mixin-utils.js +2 -1
  137. package/esm/helpers/monkey-patches.js +4 -2
  138. package/esm/helpers/object-utils.js +2 -2
  139. package/esm/helpers/parse-fields-projection.js +1 -3
  140. package/esm/helpers/responsive-map.js +5 -4
  141. package/esm/i18n/i18n.js +4 -3
  142. package/esm/i18n/index.js +1 -1
  143. package/esm/index.js +1 -1
  144. package/package.json +11 -8
  145. package/types/document/api-document.d.ts +1 -0
  146. package/types/document/common/document-element.d.ts +1 -0
  147. package/types/document/data-type/api-field.d.ts +12 -0
  148. package/types/document/data-type/complex-type-base.d.ts +1 -1
  149. package/types/document/data-type/complex-type.d.ts +1 -1
  150. package/types/document/data-type/data-type.d.ts +5 -2
  151. package/types/document/data-type/enum-type.d.ts +2 -2
  152. package/types/document/data-type/mapped-type.d.ts +3 -3
  153. package/types/document/data-type/mixin-type.d.ts +2 -2
  154. package/types/document/data-type/omit-type.d.ts +0 -6
  155. package/types/document/data-type/partial-type.d.ts +0 -6
  156. package/types/document/data-type/pick-type.d.ts +2 -2
  157. package/types/document/data-type/required-type.d.ts +7 -7
  158. package/types/document/data-type/simple-type.d.ts +4 -2
  159. package/types/document/decorators/http-controller.decorator.d.ts +1 -0
  160. package/types/document/decorators/http-operation-entity.decorator.d.ts +1 -0
  161. package/types/document/factory/data-type.factory.d.ts +5 -0
  162. package/types/document/http/http-controller.d.ts +1 -0
  163. package/types/document/http/http-media-type.d.ts +2 -1
  164. package/types/document/http/http-operation.d.ts +5 -3
  165. package/types/document/http/http-parameter.d.ts +3 -2
  166. package/types/document/http/http-status-range.d.ts +2 -1
  167. package/types/document/index.d.ts +5 -5
  168. package/types/exception/index.d.ts +5 -5
  169. package/types/filter/ast/index.d.ts +1 -1
  170. package/types/filter/opra-filter.ns.d.ts +2 -2
  171. package/types/helpers/type-guards.d.ts +0 -2
  172. package/types/i18n/i18n.d.ts +21 -19
  173. package/types/index.d.ts +1 -1
  174. package/types/schema/data-type/data-type.interface.d.ts +1 -1
  175. package/types/schema/data-type/mapped-type.interface.d.ts +2 -2
  176. package/types/schema/data-type/simple-type.interface.d.ts +4 -0
  177. package/types/schema/data-type-container.interface.d.ts +1 -1
  178. package/types/schema/document.interface.d.ts +1 -1
  179. package/types/schema/http/http-controller.interface.d.ts +2 -2
  180. package/types/schema/http/http-media-type.interface.d.ts +1 -1
  181. package/types/schema/http/http-operation-response.interface.d.ts +2 -2
  182. package/types/schema/http/http-operation.interface.d.ts +8 -4
  183. package/types/schema/http/http-parameter.interface.d.ts +5 -1
@@ -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
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpOperationDecoratorFactory = void 0;
3
+ exports.HttpOperationDecoratorFactory = HttpOperationDecoratorFactory;
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("../../http/index.js");
@@ -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);
@@ -114,6 +118,9 @@ function HttpOperationDecoratorFactory(decoratorChain, options) {
114
118
  responseMeta.contentType = responseMeta.contentType || index_js_1.MimeTypes.opra_response_json;
115
119
  responseMeta.contentEncoding = responseMeta.contentEncoding || 'utf-8';
116
120
  }
121
+ if (responseMeta.contentType === index_js_1.MimeTypes.opra_response_json) {
122
+ responseMeta.contentEncoding = responseMeta.contentEncoding || 'utf-8';
123
+ }
117
124
  decoratorChain.push((meta) => {
118
125
  meta.responses = meta.responses || [];
119
126
  meta.responses.push(responseMeta);
@@ -180,4 +187,3 @@ function HttpOperationDecoratorFactory(decoratorChain, options) {
180
187
  };
181
188
  return decorator;
182
189
  }
183
- exports.HttpOperationDecoratorFactory = HttpOperationDecoratorFactory;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AttributeDecoratorFactory = exports.SimpleTypeDecoratorFactory = void 0;
3
+ exports.SimpleTypeDecoratorFactory = SimpleTypeDecoratorFactory;
4
+ exports.AttributeDecoratorFactory = AttributeDecoratorFactory;
4
5
  const tslib_1 = require("tslib");
5
6
  const lodash_omit_1 = tslib_1.__importDefault(require("lodash.omit"));
6
7
  const index_js_1 = require("../../schema/index.js");
@@ -42,7 +43,6 @@ function SimpleTypeDecoratorFactory(options) {
42
43
  };
43
44
  return decorator;
44
45
  }
45
- exports.SimpleTypeDecoratorFactory = SimpleTypeDecoratorFactory;
46
46
  function AttributeDecoratorFactory(options) {
47
47
  return (target, propertyKey) => {
48
48
  if (typeof propertyKey !== 'string')
@@ -64,4 +64,3 @@ function AttributeDecoratorFactory(options) {
64
64
  Reflect.defineMetadata(constants_js_1.DATATYPE_METADATA, metadata, target.constructor);
65
65
  };
66
66
  }
67
- exports.AttributeDecoratorFactory = AttributeDecoratorFactory;
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ApiDocumentFactory = void 0;
4
- const tslib_1 = require("tslib");
5
- const node_crypto_1 = tslib_1.__importDefault(require("node:crypto"));
6
- const ts_gems_1 = require("ts-gems");
7
4
  const index_js_1 = require("../../helpers/index.js");
8
5
  const index_js_2 = require("../../schema/index.js");
9
6
  const api_document_js_1 = require("../api-document.js");
@@ -46,9 +43,7 @@ class ApiDocumentFactory {
46
43
  context.error.message = `(${l}) error${l > 1 ? 's' : ''} found in document schema.`;
47
44
  if (context.showErrorDetails) {
48
45
  context.error.message += context.error.details
49
- .map(d => {
50
- return `\n\n - ${d.message}` + (d.path ? `\n @${d.path}` : '');
51
- })
46
+ .map(d => `\n\n - ${d.message}` + (d.path ? `\n @${d.path}` : ''))
52
47
  .join('');
53
48
  }
54
49
  }
@@ -70,9 +65,14 @@ class ApiDocumentFactory {
70
65
  else
71
66
  init = schemaOrUrl;
72
67
  // Add builtin data types if this document is the root
68
+ let builtinDocument;
73
69
  if (!document[constants_js_1.BUILTIN]) {
74
- const builtinDocument = await this.createBuiltinDocument(context);
75
- document.references.set('opra', builtinDocument);
70
+ const t = document.node.findDataType('string');
71
+ builtinDocument = t?.node.getDocument();
72
+ if (!builtinDocument) {
73
+ builtinDocument = await this.createBuiltinDocument(context);
74
+ document.references.set('opra', builtinDocument);
75
+ }
76
76
  }
77
77
  init.spec = init.spec || index_js_2.OpraSchema.SpecVersion;
78
78
  document.url = init.url;
@@ -93,8 +93,12 @@ class ApiDocumentFactory {
93
93
  return;
94
94
  }
95
95
  const refDoc = new api_document_js_1.ApiDocument();
96
+ if (builtinDocument)
97
+ refDoc.references.set('opra', builtinDocument);
96
98
  await this.initDocument(refDoc, context, r);
97
- document.references.set(ns, refDoc);
99
+ /** If same document already exists in document tree, we use it except the new one */
100
+ const preDoc = document.findDocument(refDoc.id);
101
+ document.references.set(ns, preDoc || refDoc);
98
102
  });
99
103
  }
100
104
  });
@@ -115,8 +119,7 @@ class ApiDocumentFactory {
115
119
  context.addError(`Unknown service protocol (${init.api.protocol})`);
116
120
  });
117
121
  }
118
- const x = document.export();
119
- (0, ts_gems_1.asMutable)(document).id = node_crypto_1.default.createHash('md5').update(JSON.stringify(x)).digest('base64url');
122
+ document.invalidate();
120
123
  }
121
124
  /**
122
125
  *