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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/browser.js +6035 -5791
  2. package/cjs/document/api-document.js +11 -0
  3. package/cjs/document/common/api-base.js +1 -1
  4. package/cjs/document/common/document-element.js +4 -1
  5. package/cjs/document/data-type/api-field.js +12 -6
  6. package/cjs/document/data-type/complex-type-base.js +10 -3
  7. package/cjs/document/data-type/complex-type.js +6 -2
  8. package/cjs/document/data-type/data-type.js +2 -1
  9. package/cjs/document/data-type/enum-type.js +5 -2
  10. package/cjs/document/data-type/extended-types/base64.type.js +4 -0
  11. package/cjs/document/data-type/extended-types/date-string.type.js +6 -2
  12. package/cjs/document/data-type/extended-types/date-time-string.type.js +6 -2
  13. package/cjs/document/data-type/extended-types/date-time.type.js +6 -2
  14. package/cjs/document/data-type/extended-types/date.type.js +6 -2
  15. package/cjs/document/data-type/extended-types/email.type.js +6 -2
  16. package/cjs/document/data-type/extended-types/field-path.type.js +5 -3
  17. package/cjs/document/data-type/extended-types/filter.type.js +19 -17
  18. package/cjs/document/data-type/extended-types/object-id.type.js +4 -0
  19. package/cjs/document/data-type/extended-types/time.type.js +6 -2
  20. package/cjs/document/data-type/extended-types/url.type.js +6 -2
  21. package/cjs/document/data-type/extended-types/uuid.type.js +4 -0
  22. package/cjs/document/data-type/mapped-type.js +12 -5
  23. package/cjs/document/data-type/mixin-type.js +5 -1
  24. package/cjs/document/data-type/omit-type.js +7 -2
  25. package/cjs/document/data-type/partial-type.js +7 -2
  26. package/cjs/document/data-type/pick-type.js +1 -2
  27. package/cjs/document/data-type/primitive-types/bigint.type.js +4 -0
  28. package/cjs/document/data-type/primitive-types/boolean.type.js +4 -0
  29. package/cjs/document/data-type/primitive-types/integer.type.js +4 -0
  30. package/cjs/document/data-type/primitive-types/null.type.js +4 -0
  31. package/cjs/document/data-type/primitive-types/number.type.js +4 -0
  32. package/cjs/document/data-type/primitive-types/object.type.js +0 -3
  33. package/cjs/document/data-type/primitive-types/string.type.js +4 -0
  34. package/cjs/document/data-type/required-type.js +1 -2
  35. package/cjs/document/data-type/simple-type.js +17 -16
  36. package/cjs/document/data-type/utils/create-mapped-class.js +3 -3
  37. package/cjs/document/data-type/utils/get-is-inherited-predicate-fn.js +1 -2
  38. package/cjs/document/decorators/api-field-decorator.js +4 -6
  39. package/cjs/document/decorators/complex-type.decorator.js +1 -2
  40. package/cjs/document/decorators/http-controller.decorator.js +26 -2
  41. package/cjs/document/decorators/http-operation-entity.decorator.js +123 -93
  42. package/cjs/document/decorators/http-operation.decorator.js +12 -6
  43. package/cjs/document/decorators/simple-type.decorator.js +2 -3
  44. package/cjs/document/factory/api-document.factory.js +14 -11
  45. package/cjs/document/factory/data-type.factory.js +97 -56
  46. package/cjs/document/factory/http-api.factory.js +3 -1
  47. package/cjs/document/http/http-api.js +2 -3
  48. package/cjs/document/http/http-controller.js +26 -14
  49. package/cjs/document/http/http-media-type.js +21 -4
  50. package/cjs/document/http/http-operation-response.js +2 -2
  51. package/cjs/document/http/http-operation.js +28 -4
  52. package/cjs/document/http/http-parameter.js +4 -0
  53. package/cjs/document/http/http-request-body.js +0 -1
  54. package/cjs/document/http/http-status-range.js +6 -4
  55. package/cjs/document/index.js +5 -5
  56. package/cjs/document/utils/parse-regexp.util.js +1 -2
  57. package/cjs/document/utils/string-compare.util.js +1 -2
  58. package/cjs/exception/index.js +5 -5
  59. package/cjs/exception/opra-exception.js +1 -0
  60. package/cjs/filter/antlr/OpraFilterParser.js +28 -82
  61. package/cjs/filter/ast/index.js +1 -1
  62. package/cjs/filter/build.js +22 -25
  63. package/cjs/filter/filter-rules.js +4 -2
  64. package/cjs/filter/opra-filter.ns.js +2 -2
  65. package/cjs/filter/parse.js +2 -5
  66. package/cjs/filter/utils.js +2 -3
  67. package/cjs/helpers/function-utils.js +1 -2
  68. package/cjs/helpers/get-stack-filename.js +2 -3
  69. package/cjs/helpers/mixin-utils.js +4 -4
  70. package/cjs/helpers/monkey-patches.js +4 -2
  71. package/cjs/helpers/object-utils.js +5 -6
  72. package/cjs/helpers/parse-fields-projection.js +4 -6
  73. package/cjs/helpers/responsive-map.js +5 -4
  74. package/cjs/helpers/type-guards.js +10 -11
  75. package/cjs/i18n/i18n.js +4 -3
  76. package/cjs/i18n/index.js +1 -1
  77. package/cjs/i18n/string-utils.js +2 -3
  78. package/cjs/i18n/translate.js +1 -2
  79. package/cjs/index.js +1 -1
  80. package/cjs/schema/type-guards.js +7 -8
  81. package/esm/document/api-document.js +11 -0
  82. package/esm/document/common/api-base.js +1 -1
  83. package/esm/document/common/document-element.js +4 -1
  84. package/esm/document/data-type/api-field.js +12 -6
  85. package/esm/document/data-type/complex-type-base.js +10 -3
  86. package/esm/document/data-type/complex-type.js +6 -2
  87. package/esm/document/data-type/data-type.js +2 -1
  88. package/esm/document/data-type/enum-type.js +5 -2
  89. package/esm/document/data-type/extended-types/base64.type.js +4 -0
  90. package/esm/document/data-type/extended-types/date-string.type.js +6 -2
  91. package/esm/document/data-type/extended-types/date-time-string.type.js +6 -2
  92. package/esm/document/data-type/extended-types/date-time.type.js +6 -2
  93. package/esm/document/data-type/extended-types/date.type.js +6 -2
  94. package/esm/document/data-type/extended-types/email.type.js +6 -2
  95. package/esm/document/data-type/extended-types/field-path.type.js +5 -3
  96. package/esm/document/data-type/extended-types/filter.type.js +19 -17
  97. package/esm/document/data-type/extended-types/object-id.type.js +4 -0
  98. package/esm/document/data-type/extended-types/time.type.js +6 -2
  99. package/esm/document/data-type/extended-types/url.type.js +6 -2
  100. package/esm/document/data-type/extended-types/uuid.type.js +4 -0
  101. package/esm/document/data-type/mapped-type.js +12 -5
  102. package/esm/document/data-type/mixin-type.js +5 -1
  103. package/esm/document/data-type/omit-type.js +6 -0
  104. package/esm/document/data-type/partial-type.js +6 -0
  105. package/esm/document/data-type/primitive-types/bigint.type.js +4 -0
  106. package/esm/document/data-type/primitive-types/boolean.type.js +4 -0
  107. package/esm/document/data-type/primitive-types/integer.type.js +4 -0
  108. package/esm/document/data-type/primitive-types/null.type.js +4 -0
  109. package/esm/document/data-type/primitive-types/number.type.js +4 -0
  110. package/esm/document/data-type/primitive-types/object.type.js +0 -3
  111. package/esm/document/data-type/primitive-types/string.type.js +4 -0
  112. package/esm/document/data-type/simple-type.js +17 -16
  113. package/esm/document/data-type/utils/create-mapped-class.js +2 -1
  114. package/esm/document/decorators/api-field-decorator.js +1 -2
  115. package/esm/document/decorators/http-controller.decorator.js +25 -0
  116. package/esm/document/decorators/http-operation-entity.decorator.js +80 -50
  117. package/esm/document/decorators/http-operation.decorator.js +11 -4
  118. package/esm/document/factory/api-document.factory.js +14 -10
  119. package/esm/document/factory/data-type.factory.js +97 -56
  120. package/esm/document/factory/http-api.factory.js +3 -1
  121. package/esm/document/http/http-api.js +2 -3
  122. package/esm/document/http/http-controller.js +25 -14
  123. package/esm/document/http/http-media-type.js +20 -4
  124. package/esm/document/http/http-operation-response.js +2 -2
  125. package/esm/document/http/http-operation.js +27 -4
  126. package/esm/document/http/http-parameter.js +4 -0
  127. package/esm/document/http/http-request-body.js +0 -1
  128. package/esm/document/http/http-status-range.js +6 -4
  129. package/esm/document/index.js +5 -5
  130. package/esm/exception/index.js +5 -5
  131. package/esm/exception/opra-exception.js +1 -0
  132. package/esm/filter/antlr/OpraFilterParser.js +28 -82
  133. package/esm/filter/ast/index.js +1 -1
  134. package/esm/filter/build.js +1 -3
  135. package/esm/filter/filter-rules.js +4 -2
  136. package/esm/filter/opra-filter.ns.js +2 -2
  137. package/esm/filter/parse.js +1 -3
  138. package/esm/helpers/mixin-utils.js +2 -1
  139. package/esm/helpers/monkey-patches.js +4 -2
  140. package/esm/helpers/object-utils.js +2 -2
  141. package/esm/helpers/parse-fields-projection.js +1 -3
  142. package/esm/helpers/responsive-map.js +5 -4
  143. package/esm/i18n/i18n.js +4 -3
  144. package/esm/i18n/index.js +1 -1
  145. package/esm/index.js +1 -1
  146. package/package.json +12 -8
  147. package/types/document/api-document.d.ts +1 -0
  148. package/types/document/common/api-base.d.ts +1 -1
  149. package/types/document/common/document-element.d.ts +1 -0
  150. package/types/document/data-type/api-field.d.ts +12 -0
  151. package/types/document/data-type/complex-type-base.d.ts +1 -1
  152. package/types/document/data-type/complex-type.d.ts +1 -1
  153. package/types/document/data-type/data-type.d.ts +5 -2
  154. package/types/document/data-type/enum-type.d.ts +2 -2
  155. package/types/document/data-type/mapped-type.d.ts +3 -3
  156. package/types/document/data-type/mixin-type.d.ts +2 -2
  157. package/types/document/data-type/omit-type.d.ts +0 -6
  158. package/types/document/data-type/partial-type.d.ts +0 -6
  159. package/types/document/data-type/pick-type.d.ts +2 -2
  160. package/types/document/data-type/required-type.d.ts +7 -7
  161. package/types/document/data-type/simple-type.d.ts +4 -2
  162. package/types/document/decorators/http-controller.decorator.d.ts +1 -0
  163. package/types/document/decorators/http-operation-entity.decorator.d.ts +1 -0
  164. package/types/document/factory/data-type.factory.d.ts +5 -0
  165. package/types/document/http/http-api.d.ts +1 -1
  166. package/types/document/http/http-controller.d.ts +1 -0
  167. package/types/document/http/http-media-type.d.ts +2 -1
  168. package/types/document/http/http-operation.d.ts +5 -3
  169. package/types/document/http/http-parameter.d.ts +3 -2
  170. package/types/document/http/http-status-range.d.ts +2 -1
  171. package/types/document/index.d.ts +5 -5
  172. package/types/exception/index.d.ts +5 -5
  173. package/types/filter/ast/index.d.ts +1 -1
  174. package/types/filter/opra-filter.ns.d.ts +2 -2
  175. package/types/helpers/type-guards.d.ts +0 -2
  176. package/types/i18n/i18n.d.ts +21 -19
  177. package/types/index.d.ts +1 -1
  178. package/types/schema/data-type/data-type.interface.d.ts +1 -1
  179. package/types/schema/data-type/mapped-type.interface.d.ts +2 -2
  180. package/types/schema/data-type/simple-type.interface.d.ts +4 -0
  181. package/types/schema/data-type-container.interface.d.ts +1 -1
  182. package/types/schema/document.interface.d.ts +1 -1
  183. package/types/schema/http/http-controller.interface.d.ts +2 -2
  184. package/types/schema/http/http-media-type.interface.d.ts +1 -1
  185. package/types/schema/http/http-operation-response.interface.d.ts +2 -2
  186. package/types/schema/http/http-operation.interface.d.ts +8 -4
  187. package/types/schema/http/http-parameter.interface.d.ts +5 -1
@@ -21,8 +21,9 @@ export const ApiField = function (...args) {
21
21
  _this.name = initArgs.name;
22
22
  const origin = initArgs.origin || owner;
23
23
  /* istanbul ignore next */
24
- if (!(origin instanceof ComplexTypeBase))
24
+ if (!(origin instanceof ComplexTypeBase)) {
25
25
  throw new Error('Field origin should be one of ComplexType, MappedType or MixinType');
26
+ }
26
27
  _this.origin = origin;
27
28
  _this.type = initArgs.type || owner.node.getDataType('any');
28
29
  _this.description = initArgs.description;
@@ -33,7 +34,10 @@ export const ApiField = function (...args) {
33
34
  _this.exclusive = initArgs.exclusive;
34
35
  _this.translatable = initArgs.translatable;
35
36
  _this.deprecated = initArgs.deprecated;
37
+ _this.readonly = initArgs.readonly;
38
+ _this.writeonly = initArgs.writeonly;
36
39
  _this.examples = initArgs.examples;
40
+ _this.hidden = initArgs.hidden;
37
41
  };
38
42
  /**
39
43
  *
@@ -45,13 +49,15 @@ class ApiFieldClass extends DocumentElement {
45
49
  return omitUndefined({
46
50
  type: typeName ? typeName : this.type?.toJSON(),
47
51
  description: this.description,
48
- isArray: this.isArray,
52
+ isArray: this.isArray || undefined,
49
53
  default: this.default,
50
54
  fixed: this.fixed,
51
- required: this.required,
52
- exclusive: this.exclusive,
53
- translatable: this.translatable,
54
- deprecated: this.deprecated,
55
+ required: this.required || undefined,
56
+ exclusive: this.exclusive || undefined,
57
+ translatable: this.translatable || undefined,
58
+ deprecated: this.deprecated || undefined,
59
+ readonly: this.readonly || undefined,
60
+ writeonly: this.writeonly || undefined,
55
61
  examples: this.examples,
56
62
  });
57
63
  }
@@ -115,8 +115,9 @@ class ComplexTypeBaseClass extends DataType {
115
115
  : options?.projection;
116
116
  const schema = this._generateSchema(codec, { ...options, projection, currentPath: '' });
117
117
  let additionalFields;
118
- if (this.additionalFields instanceof DataType)
118
+ if (this.additionalFields instanceof DataType) {
119
119
  additionalFields = this.additionalFields.generateCodec(codec, options);
120
+ }
120
121
  else if (typeof this.additionalFields === 'boolean')
121
122
  additionalFields = this.additionalFields;
122
123
  else if (Array.isArray(this.additionalFields)) {
@@ -128,7 +129,7 @@ class ComplexTypeBaseClass extends DataType {
128
129
  }
129
130
  }
130
131
  return vg.isObject(schema, {
131
- ctor: this.ctor,
132
+ ctor: this.name === 'object' ? Object : this.ctor,
132
133
  additionalFields,
133
134
  name: this.name,
134
135
  coerce: true,
@@ -143,6 +144,12 @@ class ComplexTypeBaseClass extends DataType {
143
144
  // Process fields
144
145
  let fieldName;
145
146
  for (const field of this.fields.values()) {
147
+ if ((context.ignoreReadonlyFields && field.readonly) ||
148
+ (context.ignoreWriteonlyFields && field.writeonly) ||
149
+ (context.ignoreHiddenFields && field.hidden)) {
150
+ schema[field.name] = vg.isUndefined({ coerce: true });
151
+ continue;
152
+ }
146
153
  fieldName = field.name;
147
154
  let p;
148
155
  if (projection !== '*') {
@@ -161,7 +168,7 @@ class ComplexTypeBaseClass extends DataType {
161
168
  const fn = this._generateFieldCodec(codec, field, {
162
169
  ...context,
163
170
  partial: context.partial === 'deep' ? context.partial : undefined,
164
- projection: projection !== '*' ? projection : p?.projection,
171
+ projection,
165
172
  currentPath: currentPath + (currentPath ? '.' : '') + fieldName,
166
173
  });
167
174
  schema[fieldName] = context.partial || !field.required ? vg.optional(fn) : vg.required(fn);
@@ -26,11 +26,13 @@ export const ComplexType = function (...args) {
26
26
  if (initArgs.base) {
27
27
  context.enter('.base', () => {
28
28
  // noinspection SuspiciousTypeOfGuard
29
- if (!(initArgs.base instanceof ComplexTypeBase))
29
+ if (!(initArgs.base instanceof ComplexTypeBase)) {
30
30
  throw new TypeError(`"${initArgs.base.kind}" can't be set as base for a "${this.kind}"`);
31
+ }
31
32
  _this.base = initArgs.base;
32
- if (_this.additionalFields == null && _this.base.additionalFields)
33
+ if (_this.additionalFields == null && _this.base.additionalFields) {
33
34
  _this.additionalFields = _this.base.additionalFields;
35
+ }
34
36
  /** Copy fields from base */
35
37
  for (const v of _this.base.fields.values()) {
36
38
  this.fields.set(v.name, new ApiField(this, v));
@@ -57,6 +59,8 @@ export const ComplexType = function (...args) {
57
59
  */
58
60
  class ComplexTypeClass extends ComplexTypeBase {
59
61
  extendsFrom(baseType) {
62
+ if (!(baseType instanceof DataType))
63
+ baseType = this.node.getDataType(baseType);
60
64
  if (!(baseType instanceof ComplexTypeBase))
61
65
  return false;
62
66
  if (baseType === this)
@@ -11,8 +11,9 @@ export const DataType = function (owner, initArgs,
11
11
  context) {
12
12
  if (!this)
13
13
  throw new TypeError('"this" should be passed to call class constructor');
14
- if (initArgs?.name && !CLASS_NAME_PATTERN.test(initArgs.name))
14
+ if (initArgs?.name && !CLASS_NAME_PATTERN.test(initArgs.name)) {
15
15
  throw new TypeError(`"${initArgs.name}" is not a valid DataType name`);
16
+ }
16
17
  DocumentElement.call(this, owner);
17
18
  const _this = asMutable(this);
18
19
  _this.kind = initArgs.kind;
@@ -19,8 +19,9 @@ export const EnumType = function (...args) {
19
19
  _this.kind = OpraSchema.EnumType.Kind;
20
20
  if (initArgs.base) {
21
21
  // noinspection SuspiciousTypeOfGuard
22
- if (!(initArgs.base instanceof EnumType))
23
- throw new TypeError(`"${initArgs.base.kind}" can't be set as base for a "${this.kind}"`);
22
+ if (!(initArgs.base instanceof EnumType)) {
23
+ throw new TypeError(`"${initArgs.base.kind}" can't be set as base for a "${_this.kind}"`);
24
+ }
24
25
  _this.base = initArgs.base;
25
26
  }
26
27
  _this.instance = initArgs.instance;
@@ -35,6 +36,8 @@ export const EnumType = function (...args) {
35
36
  */
36
37
  class EnumTypeClass extends DataType {
37
38
  extendsFrom(baseType) {
39
+ if (!(baseType instanceof DataType))
40
+ baseType = this.node.getDataType(baseType);
38
41
  if (!(baseType instanceof EnumType))
39
42
  return false;
40
43
  if (baseType === this)
@@ -17,6 +17,10 @@ let Base64Type = class Base64Type {
17
17
  Base64Type = __decorate([
18
18
  SimpleType({
19
19
  description: 'A stream of bytes, base64 encoded',
20
+ nameMappings: {
21
+ js: 'string',
22
+ json: 'string',
23
+ },
20
24
  }),
21
25
  __metadata("design:paramtypes", [Object])
22
26
  ], Base64Type);
@@ -33,12 +33,16 @@ __decorate([
33
33
  __metadata("design:type", String)
34
34
  ], DateStringType.prototype, "maxValue", void 0);
35
35
  DateStringType = __decorate([
36
- SimpleType({
36
+ (SimpleType({
37
37
  description: 'Date string value',
38
+ nameMappings: {
39
+ js: 'string',
40
+ json: 'string',
41
+ },
38
42
  })
39
43
  .Example('2021-04-18', 'Full date value')
40
44
  .Example('2021-04', 'Date value without day')
41
- .Example('2021', 'Year only value'),
45
+ .Example('2021', 'Year only value')),
42
46
  __metadata("design:paramtypes", [Object])
43
47
  ], DateStringType);
44
48
  export { DateStringType };
@@ -33,15 +33,19 @@ __decorate([
33
33
  __metadata("design:type", String)
34
34
  ], DateTimeStringType.prototype, "maxValue", void 0);
35
35
  DateTimeStringType = __decorate([
36
- SimpleType({
36
+ (SimpleType({
37
37
  description: 'DateTime string value',
38
+ nameMappings: {
39
+ js: 'string',
40
+ json: 'string',
41
+ },
38
42
  })
39
43
  .Example('2021-04-18T22:30:15+01:00', 'Full date-time value with timezone')
40
44
  .Example('2021-04-18T22:30:15', 'Full date-time value without timezone')
41
45
  .Example('2021-04-18 22:30', 'Date-time value')
42
46
  .Example('2021-04-18', 'Date value')
43
47
  .Example('2021-04', 'Date value without day')
44
- .Example('2021', 'Year only value'),
48
+ .Example('2021', 'Year only value')),
45
49
  __metadata("design:paramtypes", [Object])
46
50
  ], DateTimeStringType);
47
51
  export { DateTimeStringType };
@@ -47,12 +47,16 @@ __decorate([
47
47
  __metadata("design:type", String)
48
48
  ], DateTimeType.prototype, "maxValue", void 0);
49
49
  DateTimeType = __decorate([
50
- SimpleType({
50
+ (SimpleType({
51
51
  description: 'A full datetime value',
52
+ nameMappings: {
53
+ js: 'string',
54
+ json: 'string',
55
+ },
52
56
  })
53
57
  .Example('2021-04-18T22:30:15')
54
58
  .Example('2021-04-18 22:30:15')
55
- .Example('2021-04-18 22:30'),
59
+ .Example('2021-04-18 22:30')),
56
60
  __metadata("design:paramtypes", [Object])
57
61
  ], DateTimeType);
58
62
  export { DateTimeType };
@@ -47,9 +47,13 @@ __decorate([
47
47
  __metadata("design:type", String)
48
48
  ], DateType.prototype, "maxValue", void 0);
49
49
  DateType = __decorate([
50
- SimpleType({
50
+ (SimpleType({
51
51
  description: 'A date without time',
52
- }).Example('2021-04-18', 'Full date value'),
52
+ nameMappings: {
53
+ js: 'Date',
54
+ json: 'string',
55
+ },
56
+ }).Example('2021-04-18', 'Full date value')),
53
57
  __metadata("design:paramtypes", [Object])
54
58
  ], DateType);
55
59
  export { DateType };
@@ -79,9 +79,13 @@ __decorate([
79
79
  __metadata("design:type", String)
80
80
  ], EmailType.prototype, "blacklistedChars", void 0);
81
81
  EmailType = __decorate([
82
- SimpleType({
82
+ (SimpleType({
83
83
  description: 'An email value',
84
- }).Example('some.body@example.com'),
84
+ nameMappings: {
85
+ js: 'string',
86
+ json: 'string',
87
+ },
88
+ }).Example('some.body@example.com')),
85
89
  __metadata("design:paramtypes", [Object])
86
90
  ], EmailType);
87
91
  export { EmailType };
@@ -12,9 +12,7 @@ let FieldPathType = class FieldPathType {
12
12
  ? element.node.getComplexType(properties.dataType)
13
13
  : element.node.getComplexType('object');
14
14
  const allowSigns = properties.allowSigns;
15
- const decodeFieldPath = validator('decodeFieldPath', function (input) {
16
- return dataType.normalizeFieldPath(input, { allowSigns });
17
- });
15
+ const decodeFieldPath = validator('decodeFieldPath', (input) => dataType.normalizeFieldPath(input, { allowSigns }));
18
16
  return vg.pipe([toString, decodeFieldPath]);
19
17
  }
20
18
  [ENCODER](properties, element) {
@@ -48,6 +46,10 @@ __decorate([
48
46
  FieldPathType = __decorate([
49
47
  SimpleType({
50
48
  description: 'Field path',
49
+ nameMappings: {
50
+ js: 'string',
51
+ json: 'string',
52
+ },
51
53
  }),
52
54
  __metadata("design:paramtypes", [Object])
53
55
  ], FieldPathType);
@@ -45,28 +45,30 @@ __decorate([
45
45
  FilterType = __decorate([
46
46
  SimpleType({
47
47
  description: 'A query filter',
48
+ nameMappings: {
49
+ js: 'object',
50
+ json: 'string',
51
+ },
48
52
  }),
49
53
  __metadata("design:paramtypes", [Object])
50
54
  ], FilterType);
51
55
  export { FilterType };
52
- const decodeFilter = (dataType, rules) => {
53
- return validator('decodeFilter', function (input, context, _this) {
54
- if (typeof input === 'string') {
55
- try {
56
- const filter = OpraFilter.parse(input);
57
- if (rules)
58
- return rules.normalizeFilter(filter, dataType);
59
- return filter;
60
- }
61
- catch (e) {
62
- context.fail(_this, `Not a valid filter expression. ${e.message}`, input, e.errors);
63
- return;
64
- }
56
+ const decodeFilter = (dataType, rules) => validator('decodeFilter', (input, context, _this) => {
57
+ if (typeof input === 'string') {
58
+ try {
59
+ const filter = OpraFilter.parse(input);
60
+ if (rules)
61
+ return rules.normalizeFilter(filter, dataType);
62
+ return filter;
65
63
  }
66
- context.fail(_this, `Nt a valid filter expression string`, input);
67
- });
68
- };
69
- const encodeFilter = validator('encodeFilter', function (input, context, _this) {
64
+ catch (e) {
65
+ context.fail(_this, `Not a valid filter expression. ${e.message}`, input, e.errors);
66
+ return;
67
+ }
68
+ }
69
+ context.fail(_this, `Nt a valid filter expression string`, input);
70
+ });
71
+ const encodeFilter = validator('encodeFilter', (input, context, _this) => {
70
72
  if (input instanceof OpraFilter.Ast) {
71
73
  return input.toString();
72
74
  }
@@ -17,6 +17,10 @@ let ObjectIdType = class ObjectIdType {
17
17
  ObjectIdType = __decorate([
18
18
  SimpleType({
19
19
  description: 'A MongoDB ObjectID value',
20
+ nameMappings: {
21
+ js: 'object',
22
+ json: 'string',
23
+ },
20
24
  }),
21
25
  __metadata("design:paramtypes", [Object])
22
26
  ], ObjectIdType);
@@ -37,11 +37,15 @@ __decorate([
37
37
  __metadata("design:type", String)
38
38
  ], TimeType.prototype, "maxValue", void 0);
39
39
  TimeType = __decorate([
40
- SimpleType({
40
+ (SimpleType({
41
41
  description: 'Time string in 24h format',
42
+ nameMappings: {
43
+ js: 'string',
44
+ json: 'string',
45
+ },
42
46
  })
43
47
  .Example('18:23:00', 'Full time value')
44
- .Example('18:23:00', 'Time value without seconds'),
48
+ .Example('18:23:00', 'Time value without seconds')),
45
49
  __metadata("design:paramtypes", [Object])
46
50
  ], TimeType);
47
51
  export { TimeType };
@@ -15,9 +15,13 @@ let UrlType = class UrlType {
15
15
  }
16
16
  };
17
17
  UrlType = __decorate([
18
- SimpleType({
18
+ (SimpleType({
19
19
  description: 'A Uniform Resource Identifier Reference (RFC 3986 icon) value',
20
- }).Example('http://tempuri.org'),
20
+ nameMappings: {
21
+ js: 'string',
22
+ json: 'string',
23
+ },
24
+ }).Example('http://tempuri.org')),
21
25
  __metadata("design:paramtypes", [Object])
22
26
  ], UrlType);
23
27
  export { UrlType };
@@ -23,6 +23,10 @@ __decorate([
23
23
  UuidType = __decorate([
24
24
  SimpleType({
25
25
  description: 'A Universal Unique Identifier (UUID) value',
26
+ nameMappings: {
27
+ js: 'string',
28
+ json: 'string',
29
+ },
26
30
  }),
27
31
  __metadata("design:paramtypes", [Object])
28
32
  ], UuidType);
@@ -4,6 +4,7 @@ import { omitUndefined } from '../../helpers/index.js';
4
4
  import { OpraSchema } from '../../schema/index.js';
5
5
  import { ApiField } from './api-field.js';
6
6
  import { ComplexTypeBase } from './complex-type-base.js';
7
+ import { DataType } from './data-type.js';
7
8
  import { getIsInheritedPredicateFn } from './utils/get-is-inherited-predicate-fn.js';
8
9
  /**
9
10
  * MappedType constructor
@@ -18,22 +19,25 @@ export const MappedType = function (...args) {
18
19
  _this.kind = OpraSchema.MappedType.Kind;
19
20
  if (initArgs.base) {
20
21
  // noinspection SuspiciousTypeOfGuard
21
- if (!(initArgs.base instanceof ComplexTypeBase))
22
+ if (!(initArgs.base instanceof ComplexTypeBase)) {
22
23
  throw new TypeError(`"${initArgs.base.kind}" can't be set as base for a "${this.kind}"`);
24
+ }
23
25
  _this.base = initArgs.base;
24
26
  _this.ctor = initArgs.ctor || _this.base.ctor;
25
27
  if (initArgs.pick)
26
28
  _this.pick = initArgs.pick.map(f => _this.base.normalizeFieldPath(f));
27
29
  else if (initArgs.omit)
28
30
  _this.omit = initArgs.omit.map(f => _this.base.normalizeFieldPath(f));
29
- else if (initArgs.partial)
31
+ else if (initArgs.partial) {
30
32
  _this.partial = Array.isArray(initArgs.partial)
31
33
  ? initArgs.partial.map(f => _this.base.normalizeFieldPath(f))
32
34
  : initArgs.partial;
33
- else if (initArgs.required)
35
+ }
36
+ else if (initArgs.required) {
34
37
  _this.required = Array.isArray(initArgs.required)
35
38
  ? initArgs.required.map(f => _this.base.normalizeFieldPath(f))
36
39
  : initArgs.required;
40
+ }
37
41
  /** Copy fields from base */
38
42
  const isInheritedPredicate = getIsInheritedPredicateFn(_this.pick, _this.omit);
39
43
  const partial = Array.isArray(_this.partial) ? _this.partial.map(x => x.toLowerCase()) : _this.partial;
@@ -53,8 +57,9 @@ export const MappedType = function (...args) {
53
57
  }
54
58
  if (!_this.pick ||
55
59
  _this.base.additionalFields === false ||
56
- (Array.isArray(_this.base.additionalFields) && _this.base.additionalFields?.[0] === 'error'))
60
+ (Array.isArray(_this.base.additionalFields) && _this.base.additionalFields?.[0] === 'error')) {
57
61
  _this.additionalFields = _this.base.additionalFields;
62
+ }
58
63
  if (initArgs.base.keyField && isInheritedPredicate(initArgs.base.keyField))
59
64
  _this.keyField = initArgs.base.keyField;
60
65
  }
@@ -65,6 +70,8 @@ export const MappedType = function (...args) {
65
70
  */
66
71
  class MappedTypeClass extends ComplexTypeBase {
67
72
  extendsFrom(baseType) {
73
+ if (!(baseType instanceof DataType))
74
+ baseType = this.node.getDataType(baseType);
68
75
  if (!(baseType instanceof ComplexTypeBase))
69
76
  return false;
70
77
  if (baseType === this)
@@ -85,4 +92,4 @@ class MappedTypeClass extends ComplexTypeBase {
85
92
  }
86
93
  }
87
94
  MappedType.prototype = MappedTypeClass.prototype;
88
- MappedType._applyMixin = () => void 0;
95
+ MappedType._applyMixin = () => undefined;
@@ -5,6 +5,7 @@ import { OpraSchema } from '../../schema/index.js';
5
5
  import { DATATYPE_METADATA, DECORATOR } from '../constants.js';
6
6
  import { ApiField } from './api-field.js';
7
7
  import { ComplexTypeBase } from './complex-type-base.js';
8
+ import { DataType } from './data-type.js';
8
9
  /**
9
10
  * @class MixinType
10
11
  */
@@ -40,6 +41,8 @@ export const MixinType = function (...args) {
40
41
  */
41
42
  class MixinTypeClass extends ComplexTypeBase {
42
43
  extendsFrom(baseType) {
44
+ if (!(baseType instanceof DataType))
45
+ baseType = this.node.getDataType(baseType);
43
46
  if (!(baseType instanceof ComplexTypeBase))
44
47
  return false;
45
48
  if (baseType === this)
@@ -94,8 +97,9 @@ function MixinTypeFactory(...args) {
94
97
  if (!(itemMeta &&
95
98
  (itemMeta.kind === OpraSchema.ComplexType.Kind ||
96
99
  itemMeta.kind === OpraSchema.MixinType.Kind ||
97
- itemMeta.kind === OpraSchema.MappedType.Kind)))
100
+ itemMeta.kind === OpraSchema.MappedType.Kind))) {
98
101
  throw new TypeError(`Class "${c.name}" is not a ${OpraSchema.ComplexType.Kind}, ${OpraSchema.MixinType.Kind} or ${OpraSchema.MappedType.Kind}`);
102
+ }
99
103
  metadata.types.push(c);
100
104
  mergePrototype(MixinClass.prototype, c.prototype);
101
105
  }
@@ -1,4 +1,10 @@
1
1
  import { createMappedClass } from './utils/create-mapped-class.js';
2
+ /**
3
+ * Create a new MappedType that omits given fields from base type
4
+ * @param baseType
5
+ * @param keys
6
+ * @param options
7
+ */
2
8
  /**
3
9
  *
4
10
  */
@@ -1,4 +1,10 @@
1
1
  import { createMappedClass } from './utils/create-mapped-class.js';
2
+ /**
3
+ * Create a new MappedType that marks given or all fields as optional
4
+ * @param baseType
5
+ * @param keys
6
+ * @param options
7
+ */
2
8
  /**
3
9
  *
4
10
  */
@@ -22,6 +22,10 @@ let BigintType = class BigintType extends NumberType {
22
22
  BigintType = __decorate([
23
23
  SimpleType({
24
24
  description: 'BigInt number',
25
+ nameMappings: {
26
+ js: 'bigint',
27
+ json: 'string',
28
+ },
25
29
  }),
26
30
  __metadata("design:paramtypes", [Object])
27
31
  ], BigintType);
@@ -17,6 +17,10 @@ let BooleanType = class BooleanType {
17
17
  BooleanType = __decorate([
18
18
  SimpleType({
19
19
  description: 'Simple true/false value',
20
+ nameMappings: {
21
+ js: 'boolean',
22
+ json: 'boolean',
23
+ },
20
24
  }),
21
25
  __metadata("design:paramtypes", [Object])
22
26
  ], BooleanType);
@@ -22,6 +22,10 @@ let IntegerType = class IntegerType extends NumberType {
22
22
  IntegerType = __decorate([
23
23
  SimpleType({
24
24
  description: 'An integer number',
25
+ nameMappings: {
26
+ js: 'number',
27
+ json: 'number',
28
+ },
25
29
  }),
26
30
  __metadata("design:paramtypes", [Object])
27
31
  ], IntegerType);
@@ -17,6 +17,10 @@ let NullType = class NullType {
17
17
  NullType = __decorate([
18
18
  SimpleType({
19
19
  description: 'A Null value',
20
+ nameMappings: {
21
+ js: 'null',
22
+ json: 'null',
23
+ },
20
24
  }),
21
25
  __metadata("design:paramtypes", [Object])
22
26
  ], NullType);
@@ -34,6 +34,10 @@ __decorate([
34
34
  NumberType = __decorate([
35
35
  SimpleType({
36
36
  description: 'Both Integer as well as Floating-Point numbers',
37
+ nameMappings: {
38
+ js: 'number',
39
+ json: 'number',
40
+ },
37
41
  }),
38
42
  __metadata("design:paramtypes", [Object])
39
43
  ], NumberType);
@@ -1,5 +1,4 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
- import { DATATYPE_METADATA } from '../../constants.js';
3
2
  import { ComplexType } from '../complex-type.js';
4
3
  let ObjectType = class ObjectType {
5
4
  constructor(properties) {
@@ -16,5 +15,3 @@ ObjectType = __decorate([
16
15
  __metadata("design:paramtypes", [Object])
17
16
  ], ObjectType);
18
17
  export { ObjectType };
19
- const metadata = Reflect.getMetadata(DATATYPE_METADATA, ObjectType);
20
- metadata.ctor = Object;
@@ -54,6 +54,10 @@ __decorate([
54
54
  StringType = __decorate([
55
55
  SimpleType({
56
56
  description: 'A sequence of characters',
57
+ nameMappings: {
58
+ js: 'string',
59
+ json: 'string',
60
+ },
57
61
  }),
58
62
  __metadata("design:paramtypes", [Object])
59
63
  ], StringType);
@@ -20,11 +20,14 @@ export const SimpleType = function (...args) {
20
20
  _this.kind = OpraSchema.SimpleType.Kind;
21
21
  if (initArgs.base) {
22
22
  // noinspection SuspiciousTypeOfGuard
23
- if (!(initArgs.base instanceof SimpleType))
23
+ if (!(initArgs.base instanceof SimpleType)) {
24
24
  throw new TypeError(`"${initArgs.base.kind}" can't be set as base for a "${this.kind}"`);
25
+ }
25
26
  _this.base = initArgs.base;
26
27
  }
27
28
  _this.properties = initArgs.properties;
29
+ _this.ownNameMappings = { ...initArgs.nameMappings };
30
+ _this.nameMappings = { ..._this.base?.nameMappings, ...initArgs.nameMappings };
28
31
  _this.ownAttributes = cloneObject(initArgs.attributes || {});
29
32
  _this.attributes = _this.base ? cloneObject(_this.base.attributes) : {};
30
33
  if (_this.ownAttributes) {
@@ -43,6 +46,8 @@ export const SimpleType = function (...args) {
43
46
  */
44
47
  class SimpleTypeClass extends DataType {
45
48
  extendsFrom(baseType) {
49
+ if (!(baseType instanceof DataType))
50
+ baseType = this.node.getDataType(baseType);
46
51
  if (!(baseType instanceof SimpleType))
47
52
  return false;
48
53
  if (baseType === this)
@@ -63,15 +68,13 @@ class SimpleTypeClass extends DataType {
63
68
  }
64
69
  return isAny;
65
70
  }
66
- else {
67
- let t = this;
68
- while (t) {
69
- if (t._generateEncoder)
70
- return t._generateEncoder(prop, options?.documentElement || this.owner);
71
- t = this.base;
72
- }
73
- return isAny;
71
+ let t = this;
72
+ while (t) {
73
+ if (t._generateEncoder)
74
+ return t._generateEncoder(prop, options?.documentElement || this.owner);
75
+ t = this.base;
74
76
  }
77
+ return isAny;
75
78
  }
76
79
  toJSON() {
77
80
  const attributes = omitUndefined(this.ownAttributes);
@@ -80,19 +83,17 @@ class SimpleTypeClass extends DataType {
80
83
  properties = this.properties.toJSON(this.properties, this.owner);
81
84
  }
82
85
  else
83
- properties = this.properties || {};
84
- properties = Object.keys(this.attributes).reduce((o, k) => {
85
- if (properties[k] !== undefined)
86
- o[k] = properties[k];
87
- return o;
88
- }, {});
86
+ properties = this.properties ? cloneObject(this.properties) : {};
89
87
  const baseName = this.base ? this.node.getDataTypeNameWithNs(this.base) : undefined;
90
- return omitUndefined({
88
+ const out = omitUndefined({
91
89
  ...DataType.prototype.toJSON.apply(this),
92
90
  base: this.base ? (baseName ? baseName : this.base.toJSON()) : undefined,
93
91
  attributes: attributes && Object.keys(attributes).length ? attributes : undefined,
94
92
  properties: Object.keys(properties).length ? properties : undefined,
95
93
  });
94
+ if (Object.keys(this.ownNameMappings).length)
95
+ out.nameMappings = { ...this.ownNameMappings };
96
+ return out;
96
97
  }
97
98
  }
98
99
  SimpleType.prototype = SimpleTypeClass.prototype;