@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
@@ -2,6 +2,8 @@
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.ApiDocument = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const node_crypto_1 = tslib_1.__importDefault(require("node:crypto"));
5
7
  const index_js_1 = require("../helpers/index.js");
6
8
  const index_js_2 = require("../schema/index.js");
7
9
  const data_type_map_js_1 = require("./common/data-type-map.js");
@@ -16,6 +18,8 @@ class ApiDocument extends document_element_js_1.DocumentElement {
16
18
  constructor() {
17
19
  super(null);
18
20
  this[_a] = new WeakMap();
21
+ this.id = '';
22
+ this.info = {};
19
23
  this.references = new index_js_1.ResponsiveMap();
20
24
  this.types = new data_type_map_js_1.DataTypeMap();
21
25
  this.node[constants_js_1.kDataTypeMap] = this.types;
@@ -80,6 +84,14 @@ class ApiDocument extends document_element_js_1.DocumentElement {
80
84
  out.api = this.api.toJSON();
81
85
  return out;
82
86
  }
87
+ invalidate() {
88
+ /** Generate id */
89
+ const x = this.export();
90
+ delete x.id;
91
+ this.id = node_crypto_1.default.createHash('md5').update(JSON.stringify(x)).digest('base64url');
92
+ /** Clear [kTypeNSMap] */
93
+ this[constants_js_1.kTypeNSMap] = new WeakMap();
94
+ }
83
95
  _findDataType(nameOrCtor, visitedRefs) {
84
96
  let result = this.types.get(nameOrCtor);
85
97
  if (result || !this.references.size)
@@ -8,6 +8,7 @@ class ApiBase extends document_element_js_1.DocumentElement {
8
8
  constructor(owner) {
9
9
  super(owner);
10
10
  this.owner = owner;
11
+ this.name = 'OpraApi';
11
12
  }
12
13
  toJSON() {
13
14
  return (0, index_js_1.omitUndefined)({
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DocumentElement = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const node_crypto_1 = tslib_1.__importDefault(require("node:crypto"));
4
6
  const ts_gems_1 = require("ts-gems");
5
7
  const document_node_js_1 = require("./document-node.js");
6
8
  /**
@@ -11,17 +13,19 @@ exports.DocumentElement = function (owner) {
11
13
  if (!this)
12
14
  throw new TypeError('"this" should be passed to call class constructor');
13
15
  const _this = (0, ts_gems_1.asMutable)(this);
16
+ _this.id = node_crypto_1.default.randomBytes(16).toString('base64url');
14
17
  Object.defineProperty(_this, 'node', {
15
18
  value: new document_node_js_1.DocumentNode(this, owner?.node),
16
19
  enumerable: false,
17
20
  writable: true,
18
21
  });
19
- if (owner)
22
+ if (owner) {
20
23
  Object.defineProperty(_this, 'owner', {
21
24
  value: owner,
22
25
  enumerable: false,
23
26
  writable: true,
24
27
  });
28
+ }
25
29
  };
26
30
  /**
27
31
  * @class DocumentElement
@@ -24,8 +24,9 @@ exports.ApiField = function (...args) {
24
24
  _this.name = initArgs.name;
25
25
  const origin = initArgs.origin || owner;
26
26
  /* istanbul ignore next */
27
- if (!(origin instanceof complex_type_base_js_1.ComplexTypeBase))
27
+ if (!(origin instanceof complex_type_base_js_1.ComplexTypeBase)) {
28
28
  throw new Error('Field origin should be one of ComplexType, MappedType or MixinType');
29
+ }
29
30
  _this.origin = origin;
30
31
  _this.type = initArgs.type || owner.node.getDataType('any');
31
32
  _this.description = initArgs.description;
@@ -36,7 +37,10 @@ exports.ApiField = function (...args) {
36
37
  _this.exclusive = initArgs.exclusive;
37
38
  _this.translatable = initArgs.translatable;
38
39
  _this.deprecated = initArgs.deprecated;
40
+ _this.readonly = initArgs.readonly;
41
+ _this.writeonly = initArgs.writeonly;
39
42
  _this.examples = initArgs.examples;
43
+ _this.hidden = initArgs.hidden;
40
44
  };
41
45
  /**
42
46
  *
@@ -48,13 +52,15 @@ class ApiFieldClass extends document_element_js_1.DocumentElement {
48
52
  return (0, index_js_1.omitUndefined)({
49
53
  type: typeName ? typeName : this.type?.toJSON(),
50
54
  description: this.description,
51
- isArray: this.isArray,
55
+ isArray: this.isArray || undefined,
52
56
  default: this.default,
53
57
  fixed: this.fixed,
54
- required: this.required,
55
- exclusive: this.exclusive,
56
- translatable: this.translatable,
57
- deprecated: this.deprecated,
58
+ required: this.required || undefined,
59
+ exclusive: this.exclusive || undefined,
60
+ translatable: this.translatable || undefined,
61
+ deprecated: this.deprecated || undefined,
62
+ readonly: this.readonly || undefined,
63
+ writeonly: this.writeonly || undefined,
58
64
  examples: this.examples,
59
65
  });
60
66
  }
@@ -118,8 +118,9 @@ class ComplexTypeBaseClass extends data_type_js_1.DataType {
118
118
  : options?.projection;
119
119
  const schema = this._generateSchema(codec, { ...options, projection, currentPath: '' });
120
120
  let additionalFields;
121
- if (this.additionalFields instanceof data_type_js_1.DataType)
121
+ if (this.additionalFields instanceof data_type_js_1.DataType) {
122
122
  additionalFields = this.additionalFields.generateCodec(codec, options);
123
+ }
123
124
  else if (typeof this.additionalFields === 'boolean')
124
125
  additionalFields = this.additionalFields;
125
126
  else if (Array.isArray(this.additionalFields)) {
@@ -131,7 +132,7 @@ class ComplexTypeBaseClass extends data_type_js_1.DataType {
131
132
  }
132
133
  }
133
134
  return valgen_1.vg.isObject(schema, {
134
- ctor: this.ctor,
135
+ ctor: this.name === 'object' ? Object : this.ctor,
135
136
  additionalFields,
136
137
  name: this.name,
137
138
  coerce: true,
@@ -146,6 +147,12 @@ class ComplexTypeBaseClass extends data_type_js_1.DataType {
146
147
  // Process fields
147
148
  let fieldName;
148
149
  for (const field of this.fields.values()) {
150
+ if ((context.ignoreReadonlyFields && field.readonly) ||
151
+ (context.ignoreWriteonlyFields && field.writeonly) ||
152
+ (context.ignoreHiddenFields && field.hidden)) {
153
+ schema[field.name] = valgen_1.vg.isUndefined({ coerce: true });
154
+ continue;
155
+ }
149
156
  fieldName = field.name;
150
157
  let p;
151
158
  if (projection !== '*') {
@@ -164,7 +171,7 @@ class ComplexTypeBaseClass extends data_type_js_1.DataType {
164
171
  const fn = this._generateFieldCodec(codec, field, {
165
172
  ...context,
166
173
  partial: context.partial === 'deep' ? context.partial : undefined,
167
- projection: projection !== '*' ? projection : p?.projection,
174
+ projection,
168
175
  currentPath: currentPath + (currentPath ? '.' : '') + fieldName,
169
176
  });
170
177
  schema[fieldName] = context.partial || !field.required ? valgen_1.vg.optional(fn) : valgen_1.vg.required(fn);
@@ -29,11 +29,13 @@ exports.ComplexType = function (...args) {
29
29
  if (initArgs.base) {
30
30
  context.enter('.base', () => {
31
31
  // noinspection SuspiciousTypeOfGuard
32
- if (!(initArgs.base instanceof complex_type_base_js_1.ComplexTypeBase))
32
+ if (!(initArgs.base instanceof complex_type_base_js_1.ComplexTypeBase)) {
33
33
  throw new TypeError(`"${initArgs.base.kind}" can't be set as base for a "${this.kind}"`);
34
+ }
34
35
  _this.base = initArgs.base;
35
- if (_this.additionalFields == null && _this.base.additionalFields)
36
+ if (_this.additionalFields == null && _this.base.additionalFields) {
36
37
  _this.additionalFields = _this.base.additionalFields;
38
+ }
37
39
  /** Copy fields from base */
38
40
  for (const v of _this.base.fields.values()) {
39
41
  this.fields.set(v.name, new api_field_js_1.ApiField(this, v));
@@ -60,6 +62,8 @@ exports.ComplexType = function (...args) {
60
62
  */
61
63
  class ComplexTypeClass extends complex_type_base_js_1.ComplexTypeBase {
62
64
  extendsFrom(baseType) {
65
+ if (!(baseType instanceof data_type_js_1.DataType))
66
+ baseType = this.node.getDataType(baseType);
63
67
  if (!(baseType instanceof complex_type_base_js_1.ComplexTypeBase))
64
68
  return false;
65
69
  if (baseType === this)
@@ -14,8 +14,9 @@ exports.DataType = function (owner, initArgs,
14
14
  context) {
15
15
  if (!this)
16
16
  throw new TypeError('"this" should be passed to call class constructor');
17
- if (initArgs?.name && !constants_js_1.CLASS_NAME_PATTERN.test(initArgs.name))
17
+ if (initArgs?.name && !constants_js_1.CLASS_NAME_PATTERN.test(initArgs.name)) {
18
18
  throw new TypeError(`"${initArgs.name}" is not a valid DataType name`);
19
+ }
19
20
  document_element_js_1.DocumentElement.call(this, owner);
20
21
  const _this = (0, ts_gems_1.asMutable)(this);
21
22
  _this.kind = initArgs.kind;
@@ -22,8 +22,9 @@ exports.EnumType = function (...args) {
22
22
  _this.kind = index_js_2.OpraSchema.EnumType.Kind;
23
23
  if (initArgs.base) {
24
24
  // noinspection SuspiciousTypeOfGuard
25
- if (!(initArgs.base instanceof exports.EnumType))
26
- throw new TypeError(`"${initArgs.base.kind}" can't be set as base for a "${this.kind}"`);
25
+ if (!(initArgs.base instanceof exports.EnumType)) {
26
+ throw new TypeError(`"${initArgs.base.kind}" can't be set as base for a "${_this.kind}"`);
27
+ }
27
28
  _this.base = initArgs.base;
28
29
  }
29
30
  _this.instance = initArgs.instance;
@@ -38,6 +39,8 @@ exports.EnumType = function (...args) {
38
39
  */
39
40
  class EnumTypeClass extends data_type_js_1.DataType {
40
41
  extendsFrom(baseType) {
42
+ if (!(baseType instanceof data_type_js_1.DataType))
43
+ baseType = this.node.getDataType(baseType);
41
44
  if (!(baseType instanceof exports.EnumType))
42
45
  return false;
43
46
  if (baseType === this)
@@ -21,6 +21,10 @@ exports.Base64Type = Base64Type;
21
21
  exports.Base64Type = Base64Type = tslib_1.__decorate([
22
22
  (0, simple_type_js_1.SimpleType)({
23
23
  description: 'A stream of bytes, base64 encoded',
24
+ nameMappings: {
25
+ js: 'string',
26
+ json: 'string',
27
+ },
24
28
  }),
25
29
  tslib_1.__metadata("design:paramtypes", [Object])
26
30
  ], Base64Type);
@@ -37,11 +37,15 @@ tslib_1.__decorate([
37
37
  tslib_1.__metadata("design:type", String)
38
38
  ], DateStringType.prototype, "maxValue", void 0);
39
39
  exports.DateStringType = DateStringType = tslib_1.__decorate([
40
- (0, simple_type_js_1.SimpleType)({
40
+ ((0, simple_type_js_1.SimpleType)({
41
41
  description: 'Date string value',
42
+ nameMappings: {
43
+ js: 'string',
44
+ json: 'string',
45
+ },
42
46
  })
43
47
  .Example('2021-04-18', 'Full date value')
44
48
  .Example('2021-04', 'Date value without day')
45
- .Example('2021', 'Year only value'),
49
+ .Example('2021', 'Year only value')),
46
50
  tslib_1.__metadata("design:paramtypes", [Object])
47
51
  ], DateStringType);
@@ -37,14 +37,18 @@ tslib_1.__decorate([
37
37
  tslib_1.__metadata("design:type", String)
38
38
  ], DateTimeStringType.prototype, "maxValue", void 0);
39
39
  exports.DateTimeStringType = DateTimeStringType = tslib_1.__decorate([
40
- (0, simple_type_js_1.SimpleType)({
40
+ ((0, simple_type_js_1.SimpleType)({
41
41
  description: 'DateTime string value',
42
+ nameMappings: {
43
+ js: 'string',
44
+ json: 'string',
45
+ },
42
46
  })
43
47
  .Example('2021-04-18T22:30:15+01:00', 'Full date-time value with timezone')
44
48
  .Example('2021-04-18T22:30:15', 'Full date-time value without timezone')
45
49
  .Example('2021-04-18 22:30', 'Date-time value')
46
50
  .Example('2021-04-18', 'Date value')
47
51
  .Example('2021-04', 'Date value without day')
48
- .Example('2021', 'Year only value'),
52
+ .Example('2021', 'Year only value')),
49
53
  tslib_1.__metadata("design:paramtypes", [Object])
50
54
  ], DateTimeStringType);
@@ -51,11 +51,15 @@ tslib_1.__decorate([
51
51
  tslib_1.__metadata("design:type", String)
52
52
  ], DateTimeType.prototype, "maxValue", void 0);
53
53
  exports.DateTimeType = DateTimeType = tslib_1.__decorate([
54
- (0, simple_type_js_1.SimpleType)({
54
+ ((0, simple_type_js_1.SimpleType)({
55
55
  description: 'A full datetime value',
56
+ nameMappings: {
57
+ js: 'string',
58
+ json: 'string',
59
+ },
56
60
  })
57
61
  .Example('2021-04-18T22:30:15')
58
62
  .Example('2021-04-18 22:30:15')
59
- .Example('2021-04-18 22:30'),
63
+ .Example('2021-04-18 22:30')),
60
64
  tslib_1.__metadata("design:paramtypes", [Object])
61
65
  ], DateTimeType);
@@ -51,8 +51,12 @@ tslib_1.__decorate([
51
51
  tslib_1.__metadata("design:type", String)
52
52
  ], DateType.prototype, "maxValue", void 0);
53
53
  exports.DateType = DateType = tslib_1.__decorate([
54
- (0, simple_type_js_1.SimpleType)({
54
+ ((0, simple_type_js_1.SimpleType)({
55
55
  description: 'A date without time',
56
- }).Example('2021-04-18', 'Full date value'),
56
+ nameMappings: {
57
+ js: 'Date',
58
+ json: 'string',
59
+ },
60
+ }).Example('2021-04-18', 'Full date value')),
57
61
  tslib_1.__metadata("design:paramtypes", [Object])
58
62
  ], DateType);
@@ -83,8 +83,12 @@ tslib_1.__decorate([
83
83
  tslib_1.__metadata("design:type", String)
84
84
  ], EmailType.prototype, "blacklistedChars", void 0);
85
85
  exports.EmailType = EmailType = tslib_1.__decorate([
86
- (0, simple_type_js_1.SimpleType)({
86
+ ((0, simple_type_js_1.SimpleType)({
87
87
  description: 'An email value',
88
- }).Example('some.body@example.com'),
88
+ nameMappings: {
89
+ js: 'string',
90
+ json: 'string',
91
+ },
92
+ }).Example('some.body@example.com')),
89
93
  tslib_1.__metadata("design:paramtypes", [Object])
90
94
  ], EmailType);
@@ -15,9 +15,7 @@ let FieldPathType = class FieldPathType {
15
15
  ? element.node.getComplexType(properties.dataType)
16
16
  : element.node.getComplexType('object');
17
17
  const allowSigns = properties.allowSigns;
18
- const decodeFieldPath = (0, valgen_1.validator)('decodeFieldPath', function (input) {
19
- return dataType.normalizeFieldPath(input, { allowSigns });
20
- });
18
+ const decodeFieldPath = (0, valgen_1.validator)('decodeFieldPath', (input) => dataType.normalizeFieldPath(input, { allowSigns }));
21
19
  return valgen_1.vg.pipe([valgen_1.toString, decodeFieldPath]);
22
20
  }
23
21
  [constants_js_1.ENCODER](properties, element) {
@@ -52,6 +50,10 @@ tslib_1.__decorate([
52
50
  exports.FieldPathType = FieldPathType = tslib_1.__decorate([
53
51
  (0, simple_type_js_1.SimpleType)({
54
52
  description: 'Field path',
53
+ nameMappings: {
54
+ js: 'string',
55
+ json: 'string',
56
+ },
55
57
  }),
56
58
  tslib_1.__metadata("design:paramtypes", [Object])
57
59
  ], FieldPathType);
@@ -49,27 +49,29 @@ tslib_1.__decorate([
49
49
  exports.FilterType = FilterType = tslib_1.__decorate([
50
50
  (0, simple_type_js_1.SimpleType)({
51
51
  description: 'A query filter',
52
+ nameMappings: {
53
+ js: 'object',
54
+ json: 'string',
55
+ },
52
56
  }),
53
57
  tslib_1.__metadata("design:paramtypes", [Object])
54
58
  ], FilterType);
55
- const decodeFilter = (dataType, rules) => {
56
- return (0, valgen_1.validator)('decodeFilter', function (input, context, _this) {
57
- if (typeof input === 'string') {
58
- try {
59
- const filter = index_js_1.OpraFilter.parse(input);
60
- if (rules)
61
- return rules.normalizeFilter(filter, dataType);
62
- return filter;
63
- }
64
- catch (e) {
65
- context.fail(_this, `Not a valid filter expression. ${e.message}`, input, e.errors);
66
- return;
67
- }
59
+ const decodeFilter = (dataType, rules) => (0, valgen_1.validator)('decodeFilter', (input, context, _this) => {
60
+ if (typeof input === 'string') {
61
+ try {
62
+ const filter = index_js_1.OpraFilter.parse(input);
63
+ if (rules)
64
+ return rules.normalizeFilter(filter, dataType);
65
+ return filter;
68
66
  }
69
- context.fail(_this, `Nt a valid filter expression string`, input);
70
- });
71
- };
72
- const encodeFilter = (0, valgen_1.validator)('encodeFilter', function (input, context, _this) {
67
+ catch (e) {
68
+ context.fail(_this, `Not a valid filter expression. ${e.message}`, input, e.errors);
69
+ return;
70
+ }
71
+ }
72
+ context.fail(_this, `Nt a valid filter expression string`, input);
73
+ });
74
+ const encodeFilter = (0, valgen_1.validator)('encodeFilter', (input, context, _this) => {
73
75
  if (input instanceof index_js_1.OpraFilter.Ast) {
74
76
  return input.toString();
75
77
  }
@@ -21,6 +21,10 @@ exports.ObjectIdType = ObjectIdType;
21
21
  exports.ObjectIdType = ObjectIdType = tslib_1.__decorate([
22
22
  (0, simple_type_js_1.SimpleType)({
23
23
  description: 'A MongoDB ObjectID value',
24
+ nameMappings: {
25
+ js: 'object',
26
+ json: 'string',
27
+ },
24
28
  }),
25
29
  tslib_1.__metadata("design:paramtypes", [Object])
26
30
  ], ObjectIdType);
@@ -41,10 +41,14 @@ tslib_1.__decorate([
41
41
  tslib_1.__metadata("design:type", String)
42
42
  ], TimeType.prototype, "maxValue", void 0);
43
43
  exports.TimeType = TimeType = tslib_1.__decorate([
44
- (0, simple_type_js_1.SimpleType)({
44
+ ((0, simple_type_js_1.SimpleType)({
45
45
  description: 'Time string in 24h format',
46
+ nameMappings: {
47
+ js: 'string',
48
+ json: 'string',
49
+ },
46
50
  })
47
51
  .Example('18:23:00', 'Full time value')
48
- .Example('18:23:00', 'Time value without seconds'),
52
+ .Example('18:23:00', 'Time value without seconds')),
49
53
  tslib_1.__metadata("design:paramtypes", [Object])
50
54
  ], TimeType);
@@ -19,8 +19,12 @@ let UrlType = class UrlType {
19
19
  };
20
20
  exports.UrlType = UrlType;
21
21
  exports.UrlType = UrlType = tslib_1.__decorate([
22
- (0, simple_type_js_1.SimpleType)({
22
+ ((0, simple_type_js_1.SimpleType)({
23
23
  description: 'A Uniform Resource Identifier Reference (RFC 3986 icon) value',
24
- }).Example('http://tempuri.org'),
24
+ nameMappings: {
25
+ js: 'string',
26
+ json: 'string',
27
+ },
28
+ }).Example('http://tempuri.org')),
25
29
  tslib_1.__metadata("design:paramtypes", [Object])
26
30
  ], UrlType);
@@ -27,6 +27,10 @@ tslib_1.__decorate([
27
27
  exports.UuidType = UuidType = tslib_1.__decorate([
28
28
  (0, simple_type_js_1.SimpleType)({
29
29
  description: 'A Universal Unique Identifier (UUID) value',
30
+ nameMappings: {
31
+ js: 'string',
32
+ json: 'string',
33
+ },
30
34
  }),
31
35
  tslib_1.__metadata("design:paramtypes", [Object])
32
36
  ], UuidType);
@@ -7,6 +7,7 @@ const index_js_1 = require("../../helpers/index.js");
7
7
  const index_js_2 = require("../../schema/index.js");
8
8
  const api_field_js_1 = require("./api-field.js");
9
9
  const complex_type_base_js_1 = require("./complex-type-base.js");
10
+ const data_type_js_1 = require("./data-type.js");
10
11
  const get_is_inherited_predicate_fn_js_1 = require("./utils/get-is-inherited-predicate-fn.js");
11
12
  /**
12
13
  * MappedType constructor
@@ -21,22 +22,25 @@ exports.MappedType = function (...args) {
21
22
  _this.kind = index_js_2.OpraSchema.MappedType.Kind;
22
23
  if (initArgs.base) {
23
24
  // noinspection SuspiciousTypeOfGuard
24
- if (!(initArgs.base instanceof complex_type_base_js_1.ComplexTypeBase))
25
+ if (!(initArgs.base instanceof complex_type_base_js_1.ComplexTypeBase)) {
25
26
  throw new TypeError(`"${initArgs.base.kind}" can't be set as base for a "${this.kind}"`);
27
+ }
26
28
  _this.base = initArgs.base;
27
29
  _this.ctor = initArgs.ctor || _this.base.ctor;
28
30
  if (initArgs.pick)
29
31
  _this.pick = initArgs.pick.map(f => _this.base.normalizeFieldPath(f));
30
32
  else if (initArgs.omit)
31
33
  _this.omit = initArgs.omit.map(f => _this.base.normalizeFieldPath(f));
32
- else if (initArgs.partial)
34
+ else if (initArgs.partial) {
33
35
  _this.partial = Array.isArray(initArgs.partial)
34
36
  ? initArgs.partial.map(f => _this.base.normalizeFieldPath(f))
35
37
  : initArgs.partial;
36
- else if (initArgs.required)
38
+ }
39
+ else if (initArgs.required) {
37
40
  _this.required = Array.isArray(initArgs.required)
38
41
  ? initArgs.required.map(f => _this.base.normalizeFieldPath(f))
39
42
  : initArgs.required;
43
+ }
40
44
  /** Copy fields from base */
41
45
  const isInheritedPredicate = (0, get_is_inherited_predicate_fn_js_1.getIsInheritedPredicateFn)(_this.pick, _this.omit);
42
46
  const partial = Array.isArray(_this.partial) ? _this.partial.map(x => x.toLowerCase()) : _this.partial;
@@ -56,8 +60,9 @@ exports.MappedType = function (...args) {
56
60
  }
57
61
  if (!_this.pick ||
58
62
  _this.base.additionalFields === false ||
59
- (Array.isArray(_this.base.additionalFields) && _this.base.additionalFields?.[0] === 'error'))
63
+ (Array.isArray(_this.base.additionalFields) && _this.base.additionalFields?.[0] === 'error')) {
60
64
  _this.additionalFields = _this.base.additionalFields;
65
+ }
61
66
  if (initArgs.base.keyField && isInheritedPredicate(initArgs.base.keyField))
62
67
  _this.keyField = initArgs.base.keyField;
63
68
  }
@@ -68,6 +73,8 @@ exports.MappedType = function (...args) {
68
73
  */
69
74
  class MappedTypeClass extends complex_type_base_js_1.ComplexTypeBase {
70
75
  extendsFrom(baseType) {
76
+ if (!(baseType instanceof data_type_js_1.DataType))
77
+ baseType = this.node.getDataType(baseType);
71
78
  if (!(baseType instanceof complex_type_base_js_1.ComplexTypeBase))
72
79
  return false;
73
80
  if (baseType === this)
@@ -88,4 +95,4 @@ class MappedTypeClass extends complex_type_base_js_1.ComplexTypeBase {
88
95
  }
89
96
  }
90
97
  exports.MappedType.prototype = MappedTypeClass.prototype;
91
- exports.MappedType._applyMixin = () => void 0;
98
+ exports.MappedType._applyMixin = () => undefined;
@@ -8,6 +8,7 @@ const index_js_2 = require("../../schema/index.js");
8
8
  const constants_js_1 = require("../constants.js");
9
9
  const api_field_js_1 = require("./api-field.js");
10
10
  const complex_type_base_js_1 = require("./complex-type-base.js");
11
+ const data_type_js_1 = require("./data-type.js");
11
12
  /**
12
13
  * @class MixinType
13
14
  */
@@ -43,6 +44,8 @@ exports.MixinType = function (...args) {
43
44
  */
44
45
  class MixinTypeClass extends complex_type_base_js_1.ComplexTypeBase {
45
46
  extendsFrom(baseType) {
47
+ if (!(baseType instanceof data_type_js_1.DataType))
48
+ baseType = this.node.getDataType(baseType);
46
49
  if (!(baseType instanceof complex_type_base_js_1.ComplexTypeBase))
47
50
  return false;
48
51
  if (baseType === this)
@@ -97,8 +100,9 @@ function MixinTypeFactory(...args) {
97
100
  if (!(itemMeta &&
98
101
  (itemMeta.kind === index_js_2.OpraSchema.ComplexType.Kind ||
99
102
  itemMeta.kind === index_js_2.OpraSchema.MixinType.Kind ||
100
- itemMeta.kind === index_js_2.OpraSchema.MappedType.Kind)))
103
+ itemMeta.kind === index_js_2.OpraSchema.MappedType.Kind))) {
101
104
  throw new TypeError(`Class "${c.name}" is not a ${index_js_2.OpraSchema.ComplexType.Kind}, ${index_js_2.OpraSchema.MixinType.Kind} or ${index_js_2.OpraSchema.MappedType.Kind}`);
105
+ }
102
106
  metadata.types.push(c);
103
107
  (0, index_js_1.mergePrototype)(MixinClass.prototype, c.prototype);
104
108
  }
@@ -1,11 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OmitType = void 0;
3
+ exports.OmitType = OmitType;
4
4
  const create_mapped_class_js_1 = require("./utils/create-mapped-class.js");
5
+ /**
6
+ * Create a new MappedType that omits given fields from base type
7
+ * @param baseType
8
+ * @param keys
9
+ * @param options
10
+ */
5
11
  /**
6
12
  *
7
13
  */
8
14
  function OmitType(baseType, keys, options) {
9
15
  return (0, create_mapped_class_js_1.createMappedClass)(baseType, { omit: keys }, options);
10
16
  }
11
- exports.OmitType = OmitType;
@@ -1,7 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PartialType = void 0;
3
+ exports.PartialType = PartialType;
4
4
  const create_mapped_class_js_1 = require("./utils/create-mapped-class.js");
5
+ /**
6
+ * Create a new MappedType that marks given or all fields as optional
7
+ * @param baseType
8
+ * @param keys
9
+ * @param options
10
+ */
5
11
  /**
6
12
  *
7
13
  */
@@ -10,4 +16,3 @@ function PartialType(base, ...args) {
10
16
  const options = Array.isArray(args[0]) ? args[1] : args[0];
11
17
  return (0, create_mapped_class_js_1.createMappedClass)(base, { partial: keys }, options);
12
18
  }
13
- exports.PartialType = PartialType;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PickType = void 0;
3
+ exports.PickType = PickType;
4
4
  const create_mapped_class_js_1 = require("./utils/create-mapped-class.js");
5
5
  /**
6
6
  *
@@ -8,4 +8,3 @@ const create_mapped_class_js_1 = require("./utils/create-mapped-class.js");
8
8
  function PickType(baseType, keys, options) {
9
9
  return (0, create_mapped_class_js_1.createMappedClass)(baseType, { pick: keys }, options);
10
10
  }
11
- exports.PickType = PickType;
@@ -26,6 +26,10 @@ exports.BigintType = BigintType;
26
26
  exports.BigintType = BigintType = tslib_1.__decorate([
27
27
  (0, simple_type_js_1.SimpleType)({
28
28
  description: 'BigInt number',
29
+ nameMappings: {
30
+ js: 'bigint',
31
+ json: 'string',
32
+ },
29
33
  }),
30
34
  tslib_1.__metadata("design:paramtypes", [Object])
31
35
  ], BigintType);
@@ -21,6 +21,10 @@ exports.BooleanType = BooleanType;
21
21
  exports.BooleanType = BooleanType = tslib_1.__decorate([
22
22
  (0, simple_type_js_1.SimpleType)({
23
23
  description: 'Simple true/false value',
24
+ nameMappings: {
25
+ js: 'boolean',
26
+ json: 'boolean',
27
+ },
24
28
  }),
25
29
  tslib_1.__metadata("design:paramtypes", [Object])
26
30
  ], BooleanType);
@@ -26,6 +26,10 @@ exports.IntegerType = IntegerType;
26
26
  exports.IntegerType = IntegerType = tslib_1.__decorate([
27
27
  (0, simple_type_js_1.SimpleType)({
28
28
  description: 'An integer number',
29
+ nameMappings: {
30
+ js: 'number',
31
+ json: 'number',
32
+ },
29
33
  }),
30
34
  tslib_1.__metadata("design:paramtypes", [Object])
31
35
  ], IntegerType);
@@ -21,6 +21,10 @@ exports.NullType = NullType;
21
21
  exports.NullType = NullType = tslib_1.__decorate([
22
22
  (0, simple_type_js_1.SimpleType)({
23
23
  description: 'A Null value',
24
+ nameMappings: {
25
+ js: 'null',
26
+ json: 'null',
27
+ },
24
28
  }),
25
29
  tslib_1.__metadata("design:paramtypes", [Object])
26
30
  ], NullType);