@opra/common 1.0.0-alpha.2 → 1.0.0-alpha.20

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 (178) hide show
  1. package/browser.js +5835 -5538
  2. package/cjs/document/api-document.js +28 -12
  3. package/cjs/document/common/data-type-map.js +1 -1
  4. package/cjs/document/common/document-element.js +5 -1
  5. package/cjs/document/constants.js +1 -1
  6. package/cjs/document/data-type/api-field.js +7 -2
  7. package/cjs/document/data-type/complex-type-base.js +6 -1
  8. package/cjs/document/data-type/complex-type.js +8 -5
  9. package/cjs/document/data-type/data-type.js +2 -1
  10. package/cjs/document/data-type/enum-type.js +5 -2
  11. package/cjs/document/data-type/extended-types/base64.type.js +6 -1
  12. package/cjs/document/data-type/extended-types/date-string.type.js +11 -4
  13. package/cjs/document/data-type/extended-types/date-time-string.type.js +11 -4
  14. package/cjs/document/data-type/extended-types/date-time.type.js +11 -4
  15. package/cjs/document/data-type/extended-types/date.type.js +11 -4
  16. package/cjs/document/data-type/extended-types/email.type.js +25 -11
  17. package/cjs/document/data-type/extended-types/field-path.type.js +13 -7
  18. package/cjs/document/data-type/extended-types/filter.type.js +25 -20
  19. package/cjs/document/data-type/extended-types/object-id.type.js +6 -1
  20. package/cjs/document/data-type/extended-types/operation-result.type.js +20 -10
  21. package/cjs/document/data-type/extended-types/time.type.js +11 -4
  22. package/cjs/document/data-type/extended-types/url.type.js +7 -2
  23. package/cjs/document/data-type/extended-types/uuid.type.js +8 -2
  24. package/cjs/document/data-type/mapped-type.js +12 -5
  25. package/cjs/document/data-type/mixin-type.js +5 -1
  26. package/cjs/document/data-type/omit-type.js +1 -2
  27. package/cjs/document/data-type/partial-type.js +1 -2
  28. package/cjs/document/data-type/pick-type.js +1 -2
  29. package/cjs/document/data-type/primitive-types/any.type.js +2 -1
  30. package/cjs/document/data-type/primitive-types/bigint.type.js +6 -1
  31. package/cjs/document/data-type/primitive-types/boolean.type.js +6 -1
  32. package/cjs/document/data-type/primitive-types/integer.type.js +6 -1
  33. package/cjs/document/data-type/primitive-types/null.type.js +6 -1
  34. package/cjs/document/data-type/primitive-types/number.type.js +10 -3
  35. package/cjs/document/data-type/primitive-types/object.type.js +2 -1
  36. package/cjs/document/data-type/primitive-types/string.type.js +14 -5
  37. package/cjs/document/data-type/required-type.js +1 -2
  38. package/cjs/document/data-type/simple-type.js +16 -10
  39. package/cjs/document/data-type/utils/create-mapped-class.js +3 -3
  40. package/cjs/document/data-type/utils/get-is-inherited-predicate-fn.js +1 -2
  41. package/cjs/document/decorators/api-field-decorator.js +1 -2
  42. package/cjs/document/decorators/complex-type.decorator.js +1 -2
  43. package/cjs/document/decorators/http-controller.decorator.js +26 -2
  44. package/cjs/document/decorators/http-operation-entity.decorator.js +59 -34
  45. package/cjs/document/decorators/http-operation.decorator.js +12 -6
  46. package/cjs/document/decorators/simple-type.decorator.js +2 -3
  47. package/cjs/document/factory/api-document.factory.js +14 -6
  48. package/cjs/document/factory/data-type.factory.js +98 -57
  49. package/cjs/document/factory/http-api.factory.js +4 -2
  50. package/cjs/document/http/http-api.js +2 -2
  51. package/cjs/document/http/http-controller.js +25 -13
  52. package/cjs/document/http/http-media-type.js +4 -2
  53. package/cjs/document/http/http-operation-response.js +2 -1
  54. package/cjs/document/http/http-operation.js +28 -4
  55. package/cjs/document/http/http-parameter.js +3 -1
  56. package/cjs/document/http/http-status-range.js +6 -4
  57. package/cjs/document/index.js +5 -5
  58. package/cjs/document/utils/parse-regexp.util.js +1 -2
  59. package/cjs/document/utils/string-compare.util.js +1 -2
  60. package/cjs/exception/index.js +5 -5
  61. package/cjs/filter/antlr/OpraFilterParser.js +28 -82
  62. package/cjs/filter/ast/index.js +1 -1
  63. package/cjs/filter/build.js +22 -25
  64. package/cjs/filter/filter-rules.js +4 -2
  65. package/cjs/filter/opra-filter.ns.js +2 -2
  66. package/cjs/filter/parse.js +2 -5
  67. package/cjs/filter/utils.js +2 -3
  68. package/cjs/helpers/function-utils.js +1 -2
  69. package/cjs/helpers/get-stack-filename.js +2 -3
  70. package/cjs/helpers/mixin-utils.js +4 -4
  71. package/cjs/helpers/monkey-patches.js +4 -2
  72. package/cjs/helpers/object-utils.js +3 -4
  73. package/cjs/helpers/parse-fields-projection.js +4 -6
  74. package/cjs/helpers/responsive-map.js +5 -4
  75. package/cjs/helpers/type-guards.js +10 -11
  76. package/cjs/i18n/i18n.js +4 -3
  77. package/cjs/i18n/index.js +1 -1
  78. package/cjs/i18n/string-utils.js +2 -3
  79. package/cjs/i18n/translate.js +1 -2
  80. package/cjs/index.js +1 -1
  81. package/cjs/schema/type-guards.js +7 -8
  82. package/esm/document/api-document.js +27 -12
  83. package/esm/document/common/data-type-map.js +1 -1
  84. package/esm/document/common/document-element.js +4 -1
  85. package/esm/document/constants.js +1 -1
  86. package/esm/document/data-type/api-field.js +7 -2
  87. package/esm/document/data-type/complex-type-base.js +6 -1
  88. package/esm/document/data-type/complex-type.js +8 -5
  89. package/esm/document/data-type/data-type.js +2 -1
  90. package/esm/document/data-type/enum-type.js +5 -2
  91. package/esm/document/data-type/extended-types/base64.type.js +7 -2
  92. package/esm/document/data-type/extended-types/date-string.type.js +12 -5
  93. package/esm/document/data-type/extended-types/date-time-string.type.js +12 -5
  94. package/esm/document/data-type/extended-types/date-time.type.js +12 -5
  95. package/esm/document/data-type/extended-types/date.type.js +12 -5
  96. package/esm/document/data-type/extended-types/email.type.js +26 -12
  97. package/esm/document/data-type/extended-types/field-path.type.js +14 -8
  98. package/esm/document/data-type/extended-types/filter.type.js +26 -21
  99. package/esm/document/data-type/extended-types/object-id.type.js +7 -2
  100. package/esm/document/data-type/extended-types/operation-result.type.js +21 -11
  101. package/esm/document/data-type/extended-types/time.type.js +12 -5
  102. package/esm/document/data-type/extended-types/url.type.js +8 -3
  103. package/esm/document/data-type/extended-types/uuid.type.js +9 -3
  104. package/esm/document/data-type/mapped-type.js +12 -5
  105. package/esm/document/data-type/mixin-type.js +5 -1
  106. package/esm/document/data-type/primitive-types/any.type.js +3 -2
  107. package/esm/document/data-type/primitive-types/bigint.type.js +7 -2
  108. package/esm/document/data-type/primitive-types/boolean.type.js +7 -2
  109. package/esm/document/data-type/primitive-types/integer.type.js +7 -2
  110. package/esm/document/data-type/primitive-types/null.type.js +7 -2
  111. package/esm/document/data-type/primitive-types/number.type.js +11 -4
  112. package/esm/document/data-type/primitive-types/object.type.js +3 -2
  113. package/esm/document/data-type/primitive-types/string.type.js +15 -6
  114. package/esm/document/data-type/simple-type.js +16 -10
  115. package/esm/document/data-type/utils/create-mapped-class.js +2 -1
  116. package/esm/document/decorators/http-controller.decorator.js +25 -0
  117. package/esm/document/decorators/http-operation-entity.decorator.js +59 -34
  118. package/esm/document/decorators/http-operation.decorator.js +11 -4
  119. package/esm/document/factory/api-document.factory.js +14 -6
  120. package/esm/document/factory/data-type.factory.js +98 -57
  121. package/esm/document/factory/http-api.factory.js +4 -2
  122. package/esm/document/http/http-api.js +2 -2
  123. package/esm/document/http/http-controller.js +24 -13
  124. package/esm/document/http/http-media-type.js +4 -2
  125. package/esm/document/http/http-operation-response.js +2 -1
  126. package/esm/document/http/http-operation.js +27 -4
  127. package/esm/document/http/http-parameter.js +3 -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/filter/antlr/OpraFilterParser.js +28 -82
  132. package/esm/filter/ast/index.js +1 -1
  133. package/esm/filter/build.js +1 -3
  134. package/esm/filter/filter-rules.js +4 -2
  135. package/esm/filter/opra-filter.ns.js +2 -2
  136. package/esm/filter/parse.js +1 -3
  137. package/esm/helpers/mixin-utils.js +2 -1
  138. package/esm/helpers/monkey-patches.js +4 -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 +9 -8
  145. package/types/document/api-document.d.ts +4 -6
  146. package/types/document/common/document-element.d.ts +1 -0
  147. package/types/document/data-type/api-field.d.ts +2 -0
  148. package/types/document/data-type/complex-type.d.ts +1 -1
  149. package/types/document/data-type/data-type.d.ts +4 -2
  150. package/types/document/data-type/enum-type.d.ts +2 -2
  151. package/types/document/data-type/mapped-type.d.ts +3 -3
  152. package/types/document/data-type/mixin-type.d.ts +2 -2
  153. package/types/document/data-type/simple-type.d.ts +4 -2
  154. package/types/document/decorators/http-controller.decorator.d.ts +1 -0
  155. package/types/document/factory/api-document.factory.d.ts +1 -1
  156. package/types/document/factory/data-type.factory.d.ts +5 -0
  157. package/types/document/http/http-controller.d.ts +1 -0
  158. package/types/document/http/http-operation.d.ts +4 -2
  159. package/types/document/http/http-parameter.d.ts +3 -2
  160. package/types/document/http/http-status-range.d.ts +2 -1
  161. package/types/document/index.d.ts +5 -5
  162. package/types/exception/index.d.ts +5 -5
  163. package/types/filter/ast/index.d.ts +1 -1
  164. package/types/filter/opra-filter.ns.d.ts +2 -2
  165. package/types/helpers/type-guards.d.ts +0 -2
  166. package/types/i18n/i18n.d.ts +21 -19
  167. package/types/index.d.ts +1 -1
  168. package/types/schema/data-type/data-type.interface.d.ts +1 -1
  169. package/types/schema/data-type/mapped-type.interface.d.ts +2 -2
  170. package/types/schema/data-type/simple-type.interface.d.ts +4 -0
  171. package/types/schema/data-type-container.interface.d.ts +1 -1
  172. package/types/schema/document.interface.d.ts +14 -2
  173. package/types/schema/http/http-controller.interface.d.ts +2 -2
  174. package/types/schema/http/http-media-type.interface.d.ts +1 -1
  175. package/types/schema/http/http-operation-response.interface.d.ts +2 -2
  176. package/types/schema/http/http-operation.interface.d.ts +8 -4
  177. package/types/schema/http/http-parameter.interface.d.ts +5 -1
  178. package/types/schema/index.d.ts +1 -0
@@ -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");
@@ -30,18 +32,29 @@ class ApiDocument extends document_element_js_1.DocumentElement {
30
32
  if (dt)
31
33
  return this[constants_js_1.kTypeNSMap].get(dt);
32
34
  }
35
+ findDocument(id) {
36
+ if (this.id === id)
37
+ return this;
38
+ for (const doc of this.references.values()) {
39
+ if (doc.id === id)
40
+ return doc;
41
+ const d = doc.findDocument(id);
42
+ if (d)
43
+ return d;
44
+ }
45
+ }
33
46
  toJSON() {
34
47
  return this.export();
35
48
  }
36
49
  /**
37
50
  * Export as Opra schema definition object
38
51
  */
39
- export(options) {
52
+ export() {
40
53
  const out = (0, index_js_1.omitUndefined)({
41
54
  spec: index_js_2.OpraSchema.SpecVersion,
55
+ id: this.id,
42
56
  url: this.url,
43
57
  info: (0, index_js_1.cloneObject)(this.info, true),
44
- // api: this.api ? this.api.toJSON() : undefined,
45
58
  });
46
59
  if (this.references.size) {
47
60
  let i = 0;
@@ -49,16 +62,11 @@ class ApiDocument extends document_element_js_1.DocumentElement {
49
62
  for (const [ns, doc] of this.references.entries()) {
50
63
  if (doc[constants_js_1.BUILTIN])
51
64
  continue;
52
- if (options?.references === 'external-url') {
53
- if (doc.url)
54
- references[ns] = doc.url;
55
- else
56
- references[ns] = `/$schema?ns=${ns}`;
57
- }
58
- else if (options?.references === 'relative-url')
59
- references[ns] = `/$schema?ns=${ns}`;
60
- else
61
- references[ns] = doc.export(options);
65
+ references[ns] = {
66
+ id: doc.id,
67
+ url: doc.url,
68
+ info: (0, index_js_1.cloneObject)(doc.info, true),
69
+ };
62
70
  i++;
63
71
  }
64
72
  if (i)
@@ -74,6 +82,14 @@ class ApiDocument extends document_element_js_1.DocumentElement {
74
82
  out.api = this.api.toJSON();
75
83
  return out;
76
84
  }
85
+ invalidate() {
86
+ /** Generate id */
87
+ const x = this.export();
88
+ delete x.id;
89
+ this.id = node_crypto_1.default.createHash('md5').update(JSON.stringify(x)).digest('base64url');
90
+ /** Clear [kTypeNSMap] */
91
+ this[constants_js_1.kTypeNSMap] = new WeakMap();
92
+ }
77
93
  _findDataType(nameOrCtor, visitedRefs) {
78
94
  let result = this.types.get(nameOrCtor);
79
95
  if (result || !this.references.size)
@@ -23,7 +23,7 @@ class DataTypeMap {
23
23
  }
24
24
  get(nameOrCtor) {
25
25
  let name = typeof nameOrCtor === 'string' ? nameOrCtor : this[kCtorMap].get(nameOrCtor);
26
- if (!name) {
26
+ if (!name && typeof nameOrCtor === 'function') {
27
27
  const metadata = Reflect.getMetadata(constants_js_1.DATATYPE_METADATA, nameOrCtor);
28
28
  name = metadata?.name;
29
29
  }
@@ -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
@@ -7,7 +7,7 @@ exports.DECODER = Symbol.for('opra.type.decoder');
7
7
  exports.ENCODER = Symbol('opra.type.encoder');
8
8
  exports.DECORATOR = Symbol.for('DECORATOR');
9
9
  exports.BUILTIN = Symbol.for('BUILTIN');
10
- exports.NAMESPACE_PATTERN = /([a-z$_]\w+)(:.+)/i;
10
+ exports.NAMESPACE_PATTERN = /([a-z$_]\w+):(.+)/i;
11
11
  exports.CLASS_NAME_PATTERN = /^[a-z][\w_]*$/i;
12
12
  exports.EXTRACT_TYPENAME_PATTERN = /^(.*)Type(\d*)$/;
13
13
  exports.kDataTypeMap = Symbol.for('kDataTypeMap');
@@ -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,6 +37,8 @@ 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;
40
43
  };
41
44
  /**
@@ -46,7 +49,7 @@ class ApiFieldClass extends document_element_js_1.DocumentElement {
46
49
  toJSON() {
47
50
  const typeName = this.type ? this.node.getDataTypeNameWithNs(this.type) : undefined;
48
51
  return (0, index_js_1.omitUndefined)({
49
- type: this.type ? (typeName ? typeName : this.type?.toJSON()) : undefined,
52
+ type: typeName ? typeName : this.type?.toJSON(),
50
53
  description: this.description,
51
54
  isArray: this.isArray,
52
55
  default: this.default,
@@ -55,6 +58,8 @@ class ApiFieldClass extends document_element_js_1.DocumentElement {
55
58
  exclusive: this.exclusive,
56
59
  translatable: this.translatable,
57
60
  deprecated: this.deprecated,
61
+ readonly: this.readonly,
62
+ writeonly: this.writeonly,
58
63
  examples: this.examples,
59
64
  });
60
65
  }
@@ -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)) {
@@ -146,6 +147,10 @@ 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) || (context.ignoreWriteonlyFields && field.writeonly)) {
151
+ schema[field.name] = valgen_1.vg.isUndefined({ coerce: true });
152
+ continue;
153
+ }
149
154
  fieldName = field.name;
150
155
  let p;
151
156
  if (projection !== '*') {
@@ -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)
@@ -75,9 +79,8 @@ class ComplexTypeClass extends complex_type_base_js_1.ComplexTypeBase {
75
79
  });
76
80
  if (this.additionalFields) {
77
81
  if (this.additionalFields instanceof data_type_js_1.DataType) {
78
- out.additionalFields = this.additionalFields[1].name
79
- ? this.additionalFields[1].name
80
- : this.additionalFields[1].toJSON();
82
+ const typeName = this.node.getDataTypeNameWithNs(this.additionalFields);
83
+ out.additionalFields = typeName ? typeName : this.additionalFields.toJSON();
81
84
  }
82
85
  else
83
86
  out.additionalFields = this.additionalFields;
@@ -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,5 +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
- })
24
+ nameMappings: {
25
+ js: 'string',
26
+ json: 'string',
27
+ },
28
+ }),
29
+ tslib_1.__metadata("design:paramtypes", [Object])
25
30
  ], Base64Type);
@@ -27,18 +27,25 @@ exports.DateStringType = DateStringType;
27
27
  tslib_1.__decorate([
28
28
  simple_type_js_1.SimpleType.Attribute({
29
29
  description: 'Minimum value',
30
- })
30
+ }),
31
+ tslib_1.__metadata("design:type", String)
31
32
  ], DateStringType.prototype, "minValue", void 0);
32
33
  tslib_1.__decorate([
33
34
  simple_type_js_1.SimpleType.Attribute({
34
35
  description: 'Maximum value',
35
- })
36
+ }),
37
+ tslib_1.__metadata("design:type", String)
36
38
  ], DateStringType.prototype, "maxValue", void 0);
37
39
  exports.DateStringType = DateStringType = tslib_1.__decorate([
38
- (0, simple_type_js_1.SimpleType)({
40
+ ((0, simple_type_js_1.SimpleType)({
39
41
  description: 'Date string value',
42
+ nameMappings: {
43
+ js: 'string',
44
+ json: 'string',
45
+ },
40
46
  })
41
47
  .Example('2021-04-18', 'Full date value')
42
48
  .Example('2021-04', 'Date value without day')
43
- .Example('2021', 'Year only value')
49
+ .Example('2021', 'Year only value')),
50
+ tslib_1.__metadata("design:paramtypes", [Object])
44
51
  ], DateStringType);
@@ -27,21 +27,28 @@ exports.DateTimeStringType = DateTimeStringType;
27
27
  tslib_1.__decorate([
28
28
  simple_type_js_1.SimpleType.Attribute({
29
29
  description: 'Minimum value',
30
- })
30
+ }),
31
+ tslib_1.__metadata("design:type", String)
31
32
  ], DateTimeStringType.prototype, "minValue", void 0);
32
33
  tslib_1.__decorate([
33
34
  simple_type_js_1.SimpleType.Attribute({
34
35
  description: 'Maximum value',
35
- })
36
+ }),
37
+ tslib_1.__metadata("design:type", String)
36
38
  ], DateTimeStringType.prototype, "maxValue", void 0);
37
39
  exports.DateTimeStringType = DateTimeStringType = tslib_1.__decorate([
38
- (0, simple_type_js_1.SimpleType)({
40
+ ((0, simple_type_js_1.SimpleType)({
39
41
  description: 'DateTime string value',
42
+ nameMappings: {
43
+ js: 'string',
44
+ json: 'string',
45
+ },
40
46
  })
41
47
  .Example('2021-04-18T22:30:15+01:00', 'Full date-time value with timezone')
42
48
  .Example('2021-04-18T22:30:15', 'Full date-time value without timezone')
43
49
  .Example('2021-04-18 22:30', 'Date-time value')
44
50
  .Example('2021-04-18', 'Date value')
45
51
  .Example('2021-04', 'Date value without day')
46
- .Example('2021', 'Year only value')
52
+ .Example('2021', 'Year only value')),
53
+ tslib_1.__metadata("design:paramtypes", [Object])
47
54
  ], DateTimeStringType);
@@ -41,18 +41,25 @@ exports.DateTimeType = DateTimeType;
41
41
  tslib_1.__decorate([
42
42
  simple_type_js_1.SimpleType.Attribute({
43
43
  description: 'Minimum value',
44
- })
44
+ }),
45
+ tslib_1.__metadata("design:type", String)
45
46
  ], DateTimeType.prototype, "minValue", void 0);
46
47
  tslib_1.__decorate([
47
48
  simple_type_js_1.SimpleType.Attribute({
48
49
  description: 'Maximum value',
49
- })
50
+ }),
51
+ tslib_1.__metadata("design:type", String)
50
52
  ], DateTimeType.prototype, "maxValue", void 0);
51
53
  exports.DateTimeType = DateTimeType = tslib_1.__decorate([
52
- (0, simple_type_js_1.SimpleType)({
54
+ ((0, simple_type_js_1.SimpleType)({
53
55
  description: 'A full datetime value',
56
+ nameMappings: {
57
+ js: 'string',
58
+ json: 'string',
59
+ },
54
60
  })
55
61
  .Example('2021-04-18T22:30:15')
56
62
  .Example('2021-04-18 22:30:15')
57
- .Example('2021-04-18 22:30')
63
+ .Example('2021-04-18 22:30')),
64
+ tslib_1.__metadata("design:paramtypes", [Object])
58
65
  ], DateTimeType);
@@ -41,15 +41,22 @@ exports.DateType = DateType;
41
41
  tslib_1.__decorate([
42
42
  simple_type_js_1.SimpleType.Attribute({
43
43
  description: 'Minimum value',
44
- })
44
+ }),
45
+ tslib_1.__metadata("design:type", String)
45
46
  ], DateType.prototype, "minValue", void 0);
46
47
  tslib_1.__decorate([
47
48
  simple_type_js_1.SimpleType.Attribute({
48
49
  description: 'Maximum value',
49
- })
50
+ }),
51
+ tslib_1.__metadata("design:type", String)
50
52
  ], DateType.prototype, "maxValue", void 0);
51
53
  exports.DateType = DateType = tslib_1.__decorate([
52
- (0, simple_type_js_1.SimpleType)({
54
+ ((0, simple_type_js_1.SimpleType)({
53
55
  description: 'A date without time',
54
- }).Example('2021-04-18', 'Full date value')
56
+ nameMappings: {
57
+ js: 'Date',
58
+ json: 'string',
59
+ },
60
+ }).Example('2021-04-18', 'Full date value')),
61
+ tslib_1.__metadata("design:paramtypes", [Object])
55
62
  ], DateType);
@@ -22,59 +22,73 @@ tslib_1.__decorate([
22
22
  simple_type_js_1.SimpleType.Attribute({
23
23
  description: 'If set to `true`, the validator will also match `Display Name <email-address>',
24
24
  default: false,
25
- })
25
+ }),
26
+ tslib_1.__metadata("design:type", Boolean)
26
27
  ], EmailType.prototype, "allowDisplayName", void 0);
27
28
  tslib_1.__decorate([
28
29
  simple_type_js_1.SimpleType.Attribute({
29
30
  description: 'If set to `true`, the validator will reject strings without the format `Display Name <email-address>',
30
31
  default: false,
31
- })
32
+ }),
33
+ tslib_1.__metadata("design:type", Boolean)
32
34
  ], EmailType.prototype, "requireDisplayName", void 0);
33
35
  tslib_1.__decorate([
34
36
  simple_type_js_1.SimpleType.Attribute({
35
37
  description: "If set to `false`, the validator will not allow any non-English UTF8 character in email address's local part",
36
38
  default: true,
37
- })
39
+ }),
40
+ tslib_1.__metadata("design:type", Boolean)
38
41
  ], EmailType.prototype, "utf8LocalPart", void 0);
39
42
  tslib_1.__decorate([
40
43
  simple_type_js_1.SimpleType.Attribute({
41
44
  description: 'If set to `true`, the validator will not check for the standard max length of an email',
42
45
  default: false,
43
- })
46
+ }),
47
+ tslib_1.__metadata("design:type", Boolean)
44
48
  ], EmailType.prototype, "ignoreMaxLength", void 0);
45
49
  tslib_1.__decorate([
46
50
  simple_type_js_1.SimpleType.Attribute({
47
51
  description: 'If set to `true`, the validator will allow IP addresses in the host part',
48
52
  default: false,
49
- })
53
+ }),
54
+ tslib_1.__metadata("design:type", Boolean)
50
55
  ], EmailType.prototype, "allowIpDomain", void 0);
51
56
  tslib_1.__decorate([
52
57
  simple_type_js_1.SimpleType.Attribute({
53
58
  description: 'If set to `true`, some additional validation will be enabled, ' +
54
59
  'e.g. disallowing certain syntactically valid email addresses that are rejected by GMail.',
55
60
  default: false,
56
- })
61
+ }),
62
+ tslib_1.__metadata("design:type", Boolean)
57
63
  ], EmailType.prototype, "domainSpecificValidation", void 0);
58
64
  tslib_1.__decorate([
59
65
  simple_type_js_1.SimpleType.Attribute({
60
66
  description: 'If set to an array of strings and the part of the email after the @ symbol ' +
61
67
  ' one of the strings defined in it, the validation fails.',
62
- })
68
+ }),
69
+ tslib_1.__metadata("design:type", Array)
63
70
  ], EmailType.prototype, "hostBlacklist", void 0);
64
71
  tslib_1.__decorate([
65
72
  simple_type_js_1.SimpleType.Attribute({
66
73
  description: 'If set to an array of strings and the part of the email after the @ symbol ' +
67
74
  ' matches none of the strings defined in it, the validation fails.',
68
- })
75
+ }),
76
+ tslib_1.__metadata("design:type", Array)
69
77
  ], EmailType.prototype, "hostWhitelist", void 0);
70
78
  tslib_1.__decorate([
71
79
  simple_type_js_1.SimpleType.Attribute({
72
80
  description: 'If set to a string, then the validator will reject emails that include ' +
73
81
  ' any of the characters in the string, in the name part.',
74
- })
82
+ }),
83
+ tslib_1.__metadata("design:type", String)
75
84
  ], EmailType.prototype, "blacklistedChars", void 0);
76
85
  exports.EmailType = EmailType = tslib_1.__decorate([
77
- (0, simple_type_js_1.SimpleType)({
86
+ ((0, simple_type_js_1.SimpleType)({
78
87
  description: 'An email value',
79
- }).Example('some.body@example.com')
88
+ nameMappings: {
89
+ js: 'string',
90
+ json: 'string',
91
+ },
92
+ }).Example('some.body@example.com')),
93
+ tslib_1.__metadata("design:paramtypes", [Object])
80
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) {
@@ -27,8 +25,9 @@ let FieldPathType = class FieldPathType {
27
25
  const dataType = properties.dataType
28
26
  ? element.node.getComplexType(properties.dataType)
29
27
  : element.node.getComplexType('object');
28
+ const typeName = dataType ? element.node.getDataTypeNameWithNs(dataType) : undefined;
30
29
  return {
31
- dataType: dataType.name ? dataType.name : dataType.toJSON(),
30
+ dataType: typeName ? typeName : dataType.toJSON(),
32
31
  allowSigns: properties.allowSigns,
33
32
  };
34
33
  }
@@ -37,17 +36,24 @@ exports.FieldPathType = FieldPathType;
37
36
  tslib_1.__decorate([
38
37
  simple_type_js_1.SimpleType.Attribute({
39
38
  description: 'Data type which field belong to',
40
- })
39
+ }),
40
+ tslib_1.__metadata("design:type", Object)
41
41
  ], FieldPathType.prototype, "dataType", void 0);
42
42
  tslib_1.__decorate([
43
43
  simple_type_js_1.SimpleType.Attribute({
44
44
  description: 'Determines if signs (+,-) are allowed. ' +
45
45
  'If set "first" signs are allowed only beginning of the field path' +
46
46
  'If set "each" signs are allowed at each field in the path',
47
- })
47
+ }),
48
+ tslib_1.__metadata("design:type", String)
48
49
  ], FieldPathType.prototype, "allowSigns", void 0);
49
50
  exports.FieldPathType = FieldPathType = tslib_1.__decorate([
50
51
  (0, simple_type_js_1.SimpleType)({
51
52
  description: 'Field path',
52
- })
53
+ nameMappings: {
54
+ js: 'string',
55
+ json: 'string',
56
+ },
57
+ }),
58
+ tslib_1.__metadata("design:paramtypes", [Object])
53
59
  ], FieldPathType);
@@ -36,37 +36,42 @@ exports.FilterType = FilterType;
36
36
  tslib_1.__decorate([
37
37
  simple_type_js_1.SimpleType.Attribute({
38
38
  description: 'Data type which filtering fields belong to',
39
- })
39
+ }),
40
+ tslib_1.__metadata("design:type", Object)
40
41
  ], FilterType.prototype, "dataType", void 0);
41
42
  tslib_1.__decorate([
42
43
  simple_type_js_1.SimpleType.Attribute({
43
44
  description: 'Stringified JSON object defines filtering rules',
44
45
  format: 'string',
45
- })
46
+ }),
47
+ tslib_1.__metadata("design:type", Object)
46
48
  ], FilterType.prototype, "rules", void 0);
47
49
  exports.FilterType = FilterType = tslib_1.__decorate([
48
50
  (0, simple_type_js_1.SimpleType)({
49
51
  description: 'A query filter',
50
- })
52
+ nameMappings: {
53
+ js: 'object',
54
+ json: 'string',
55
+ },
56
+ }),
57
+ tslib_1.__metadata("design:paramtypes", [Object])
51
58
  ], FilterType);
52
- const decodeFilter = (dataType, rules) => {
53
- return (0, valgen_1.validator)('decodeFilter', function (input, context, _this) {
54
- if (typeof input === 'string') {
55
- try {
56
- const filter = index_js_1.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
- }
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;
65
66
  }
66
- context.fail(_this, `Nt a valid filter expression string`, input);
67
- });
68
- };
69
- 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) => {
70
75
  if (input instanceof index_js_1.OpraFilter.Ast) {
71
76
  return input.toString();
72
77
  }
@@ -21,5 +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
- })
24
+ nameMappings: {
25
+ js: 'object',
26
+ json: 'string',
27
+ },
28
+ }),
29
+ tslib_1.__metadata("design:paramtypes", [Object])
25
30
  ], ObjectIdType);