@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
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parse = exports.parseFieldsProjection = exports.FieldsProjection = void 0;
3
+ exports.FieldsProjection = void 0;
4
+ exports.parseFieldsProjection = parseFieldsProjection;
5
+ exports.parse = parse;
4
6
  const fast_tokenizer_1 = require("fast-tokenizer");
5
7
  const FIELD_PATTERN = /^([+-])?([a-z_$]\w*)$/i;
6
8
  const NO_DOT_BRACKET_PATTERN = /[^.]\(/g;
@@ -24,12 +26,9 @@ function parseFieldsProjection(projection, keepCase) {
24
26
  }
25
27
  return out;
26
28
  }
27
- exports.parseFieldsProjection = parseFieldsProjection;
28
29
  function parse(input, target) {
29
30
  /** Add dot before brackets which is required to split fields */
30
- input = input.replace(NO_DOT_BRACKET_PATTERN, s => {
31
- return s.charAt(0) + '.' + s.substring(1);
32
- });
31
+ input = input.replace(NO_DOT_BRACKET_PATTERN, s => s.charAt(0) + '.' + s.substring(1));
33
32
  const fields = (0, fast_tokenizer_1.splitString)(input, {
34
33
  delimiters: '.',
35
34
  brackets: true,
@@ -64,4 +63,3 @@ function parse(input, target) {
64
63
  }
65
64
  }
66
65
  }
67
- exports.parse = parse;
@@ -41,13 +41,14 @@ class ResponsiveMap {
41
41
  },
42
42
  enumerable: false,
43
43
  });
44
- if (options?.wellKnownKeys)
44
+ if (options?.wellKnownKeys) {
45
45
  options.wellKnownKeys.forEach(k => {
46
46
  if (caseSensitive)
47
47
  this[kWellKnownKeys][k] = k;
48
48
  else
49
49
  this[kWellKnownKeys][k.toLowerCase()] = k;
50
50
  });
51
+ }
51
52
  this.clear();
52
53
  if (init)
53
54
  this.setAll(init);
@@ -73,12 +74,12 @@ class ResponsiveMap {
73
74
  has(key) {
74
75
  if (!key)
75
76
  return false;
76
- return this[kEntries].hasOwnProperty(this._getStoringKey(key));
77
+ return Object.prototype.hasOwnProperty.call(this[kEntries], this._getStoringKey(key));
77
78
  }
78
79
  set(key, value) {
79
80
  const storeKey = this._getStoringKey(key);
80
81
  key = this._getOriginalKey(key);
81
- const exists = this[kEntries].hasOwnProperty(storeKey);
82
+ const exists = Object.prototype.hasOwnProperty.call(this[kEntries], storeKey);
82
83
  this[kEntries][storeKey] = value;
83
84
  if (!exists)
84
85
  this[kSize]++;
@@ -103,7 +104,7 @@ class ResponsiveMap {
103
104
  }
104
105
  delete(key) {
105
106
  const storeKey = this._getStoringKey(key);
106
- const exists = this[kEntries].hasOwnProperty(storeKey);
107
+ const exists = Object.prototype.hasOwnProperty.call(this[kEntries], storeKey);
107
108
  delete this[kEntries][storeKey];
108
109
  delete this[kKeyMap][storeKey];
109
110
  if (!exists)
@@ -1,6 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isAsyncIterable = exports.isIterable = exports.isURL = exports.isFormData = exports.isBlob = exports.isReadableStream = exports.isWritable = exports.isReadable = exports.isStream = exports.isConstructor = void 0;
3
+ exports.isConstructor = isConstructor;
4
+ exports.isStream = isStream;
5
+ exports.isReadable = isReadable;
6
+ exports.isWritable = isWritable;
7
+ exports.isReadableStream = isReadableStream;
8
+ exports.isBlob = isBlob;
9
+ exports.isFormData = isFormData;
10
+ exports.isURL = isURL;
11
+ exports.isIterable = isIterable;
12
+ exports.isAsyncIterable = isAsyncIterable;
4
13
  function isConstructor(fn) {
5
14
  return (typeof fn === 'function' &&
6
15
  fn.prototype &&
@@ -8,26 +17,21 @@ function isConstructor(fn) {
8
17
  fn.prototype.constructor.name !== 'Function' &&
9
18
  fn.prototype.constructor.name !== 'embedded');
10
19
  }
11
- exports.isConstructor = isConstructor;
12
20
  function isStream(x) {
13
21
  return x !== null && typeof x === 'object' && typeof x.pipe === 'function';
14
22
  }
15
- exports.isStream = isStream;
16
23
  function isReadable(x) {
17
24
  return isStream(x) && typeof x._read === 'function' && typeof x._readableState === 'object';
18
25
  }
19
- exports.isReadable = isReadable;
20
26
  function isWritable(x) {
21
27
  return isStream(x) && typeof x._write === 'function';
22
28
  }
23
- exports.isWritable = isWritable;
24
29
  function isReadableStream(x) {
25
30
  return (isStream(x) &&
26
31
  typeof x.getReader === 'function' &&
27
32
  typeof x.pipeThrough === 'function' &&
28
33
  typeof x.pipeTo === 'function');
29
34
  }
30
- exports.isReadableStream = isReadableStream;
31
35
  function isBlob(x) {
32
36
  return (x !== null &&
33
37
  typeof x === 'object' &&
@@ -35,7 +39,6 @@ function isBlob(x) {
35
39
  typeof x.arrayBuffer === 'function' &&
36
40
  typeof x.stream === 'function');
37
41
  }
38
- exports.isBlob = isBlob;
39
42
  function isFormData(x) {
40
43
  return (x !== null &&
41
44
  typeof x.constructor === 'function' &&
@@ -43,16 +46,12 @@ function isFormData(x) {
43
46
  typeof x.append === 'function' &&
44
47
  typeof x.getAll === 'function');
45
48
  }
46
- exports.isFormData = isFormData;
47
49
  function isURL(x) {
48
50
  return x !== null && typeof x == 'object' && typeof x.host === 'string' && typeof x.href === 'string';
49
51
  }
50
- exports.isURL = isURL;
51
52
  function isIterable(x) {
52
53
  return Symbol.iterator in x;
53
54
  }
54
- exports.isIterable = isIterable;
55
55
  function isAsyncIterable(x) {
56
56
  return Symbol.asyncIterator in x;
57
57
  }
58
- exports.isAsyncIterable = isAsyncIterable;
package/cjs/i18n/i18n.js CHANGED
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.I18n = exports.BaseI18n = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const fast_tokenizer_1 = require("fast-tokenizer");
6
5
  const i18next_1 = tslib_1.__importDefault(require("@browsery/i18next"));
6
+ const fast_tokenizer_1 = require("fast-tokenizer");
7
7
  const string_utils_js_1 = require("./string-utils.js");
8
8
  exports.BaseI18n = Object.getPrototypeOf(i18next_1.default.createInstance()).constructor;
9
9
  class I18n extends exports.BaseI18n {
@@ -42,7 +42,7 @@ class I18n extends exports.BaseI18n {
42
42
  const objectStack = new WeakMap();
43
43
  return this._deepTranslate(input, objectStack, options);
44
44
  }
45
- createInstance(options = {}, callback) {
45
+ createInstance(options, callback) {
46
46
  return new I18n(options, callback);
47
47
  }
48
48
  static createInstance(options, callback) {
@@ -106,8 +106,9 @@ class I18n extends exports.BaseI18n {
106
106
  input instanceof Map ||
107
107
  input instanceof Set ||
108
108
  input instanceof WeakMap ||
109
- input instanceof WeakSet)
109
+ input instanceof WeakSet) {
110
110
  return input;
111
+ }
111
112
  const out = {};
112
113
  objectStack.set(input, out);
113
114
  const keys = Object.keys(input);
package/cjs/i18n/index.js CHANGED
@@ -7,4 +7,4 @@ tslib_1.__exportStar(require("./i18n.js"), exports);
7
7
  tslib_1.__exportStar(require("./translate.js"), exports);
8
8
  const i18n = i18n_js_1.I18n.createInstance();
9
9
  exports.i18n = i18n;
10
- i18n.init().catch(() => void 0);
10
+ i18n.init().catch(() => undefined);
@@ -1,13 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.unescapeString = exports.escapeString = void 0;
3
+ exports.escapeString = escapeString;
4
+ exports.unescapeString = unescapeString;
4
5
  const unescapeRegEx = /\\(.)/g;
5
6
  const escapeRegEx = /(\\)/g;
6
7
  function escapeString(s) {
7
8
  return s.replace(escapeRegEx, '\\\\');
8
9
  }
9
- exports.escapeString = escapeString;
10
10
  function unescapeString(s) {
11
11
  return s.replace(unescapeRegEx, '$1');
12
12
  }
13
- exports.unescapeString = unescapeString;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.translate = void 0;
3
+ exports.translate = translate;
4
4
  const string_utils_js_1 = require("./string-utils.js");
5
5
  const bracketRegEx = /(\))/g;
6
6
  function translate(key, arg0, arg1) {
@@ -12,4 +12,3 @@ function translate(key, arg0, arg1) {
12
12
  (fallback ? '?' + (0, string_utils_js_1.escapeString)(fallback).replace(bracketRegEx, '\\$1') : '') +
13
13
  ')');
14
14
  }
15
- exports.translate = translate;
package/cjs/index.js CHANGED
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.uid = void 0;
4
4
  const tslib_1 = require("tslib");
5
- tslib_1.__exportStar(require("./types.js"), exports);
6
5
  tslib_1.__exportStar(require("./document/index.js"), exports);
7
6
  tslib_1.__exportStar(require("./exception/index.js"), exports);
8
7
  tslib_1.__exportStar(require("./filter/index.js"), exports);
@@ -10,5 +9,6 @@ tslib_1.__exportStar(require("./helpers/index.js"), exports);
10
9
  tslib_1.__exportStar(require("./http/index.js"), exports);
11
10
  tslib_1.__exportStar(require("./i18n/index.js"), exports);
12
11
  tslib_1.__exportStar(require("./schema/index.js"), exports);
12
+ tslib_1.__exportStar(require("./types.js"), exports);
13
13
  var uid_1 = require("uid");
14
14
  Object.defineProperty(exports, "uid", { enumerable: true, get: function () { return uid_1.uid; } });
@@ -1,6 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isHttpController = exports.isEnumType = exports.isMappedType = exports.isMixinType = exports.isSimpleType = exports.isComplexType = exports.isDataType = void 0;
3
+ exports.isDataType = isDataType;
4
+ exports.isComplexType = isComplexType;
5
+ exports.isSimpleType = isSimpleType;
6
+ exports.isMixinType = isMixinType;
7
+ exports.isMappedType = isMappedType;
8
+ exports.isEnumType = isEnumType;
9
+ exports.isHttpController = isHttpController;
4
10
  const complex_type_interface_js_1 = require("./data-type/complex-type.interface.js");
5
11
  const enum_type_interface_js_1 = require("./data-type/enum-type.interface.js");
6
12
  const mapped_type_interface_js_1 = require("./data-type/mapped-type.interface.js");
@@ -16,28 +22,21 @@ function isDataType(obj) {
16
22
  obj.kind === simple_type_interface_js_1.SimpleType.Kind ||
17
23
  obj.kind === mixin_type_interface_js_1.MixinType.Kind));
18
24
  }
19
- exports.isDataType = isDataType;
20
25
  function isComplexType(obj) {
21
26
  return obj && typeof obj === 'object' && obj.kind === complex_type_interface_js_1.ComplexType.Kind;
22
27
  }
23
- exports.isComplexType = isComplexType;
24
28
  function isSimpleType(obj) {
25
29
  return obj && typeof obj === 'object' && obj.kind === simple_type_interface_js_1.SimpleType.Kind;
26
30
  }
27
- exports.isSimpleType = isSimpleType;
28
31
  function isMixinType(obj) {
29
32
  return obj && typeof obj === 'object' && obj.kind === mixin_type_interface_js_1.MixinType.Kind;
30
33
  }
31
- exports.isMixinType = isMixinType;
32
34
  function isMappedType(obj) {
33
35
  return obj && typeof obj === 'object' && obj.kind === mapped_type_interface_js_1.MappedType.Kind;
34
36
  }
35
- exports.isMappedType = isMappedType;
36
37
  function isEnumType(obj) {
37
38
  return obj && typeof obj === 'object' && obj.kind === enum_type_interface_js_1.EnumType.Kind;
38
39
  }
39
- exports.isEnumType = isEnumType;
40
40
  function isHttpController(obj) {
41
41
  return obj && typeof obj === 'object' && obj.kind === http_controller_interface_js_1.HttpController.Kind;
42
42
  }
43
- exports.isHttpController = isHttpController;
@@ -1,4 +1,5 @@
1
1
  var _a;
2
+ import crypto from 'node:crypto';
2
3
  import { cloneObject, omitUndefined, ResponsiveMap } from '../helpers/index.js';
3
4
  import { OpraSchema } from '../schema/index.js';
4
5
  import { DataTypeMap } from './common/data-type-map.js';
@@ -27,18 +28,29 @@ export class ApiDocument extends DocumentElement {
27
28
  if (dt)
28
29
  return this[kTypeNSMap].get(dt);
29
30
  }
31
+ findDocument(id) {
32
+ if (this.id === id)
33
+ return this;
34
+ for (const doc of this.references.values()) {
35
+ if (doc.id === id)
36
+ return doc;
37
+ const d = doc.findDocument(id);
38
+ if (d)
39
+ return d;
40
+ }
41
+ }
30
42
  toJSON() {
31
43
  return this.export();
32
44
  }
33
45
  /**
34
46
  * Export as Opra schema definition object
35
47
  */
36
- export(options) {
48
+ export() {
37
49
  const out = omitUndefined({
38
50
  spec: OpraSchema.SpecVersion,
51
+ id: this.id,
39
52
  url: this.url,
40
53
  info: cloneObject(this.info, true),
41
- // api: this.api ? this.api.toJSON() : undefined,
42
54
  });
43
55
  if (this.references.size) {
44
56
  let i = 0;
@@ -46,16 +58,11 @@ export class ApiDocument extends DocumentElement {
46
58
  for (const [ns, doc] of this.references.entries()) {
47
59
  if (doc[BUILTIN])
48
60
  continue;
49
- if (options?.references === 'external-url') {
50
- if (doc.url)
51
- references[ns] = doc.url;
52
- else
53
- references[ns] = `/$schema?ns=${ns}`;
54
- }
55
- else if (options?.references === 'relative-url')
56
- references[ns] = `/$schema?ns=${ns}`;
57
- else
58
- references[ns] = doc.export(options);
61
+ references[ns] = {
62
+ id: doc.id,
63
+ url: doc.url,
64
+ info: cloneObject(doc.info, true),
65
+ };
59
66
  i++;
60
67
  }
61
68
  if (i)
@@ -71,6 +78,14 @@ export class ApiDocument extends DocumentElement {
71
78
  out.api = this.api.toJSON();
72
79
  return out;
73
80
  }
81
+ invalidate() {
82
+ /** Generate id */
83
+ const x = this.export();
84
+ delete x.id;
85
+ this.id = crypto.createHash('md5').update(JSON.stringify(x)).digest('base64url');
86
+ /** Clear [kTypeNSMap] */
87
+ this[kTypeNSMap] = new WeakMap();
88
+ }
74
89
  _findDataType(nameOrCtor, visitedRefs) {
75
90
  let result = this.types.get(nameOrCtor);
76
91
  if (result || !this.references.size)
@@ -20,7 +20,7 @@ export class DataTypeMap {
20
20
  }
21
21
  get(nameOrCtor) {
22
22
  let name = typeof nameOrCtor === 'string' ? nameOrCtor : this[kCtorMap].get(nameOrCtor);
23
- if (!name) {
23
+ if (!name && typeof nameOrCtor === 'function') {
24
24
  const metadata = Reflect.getMetadata(DATATYPE_METADATA, nameOrCtor);
25
25
  name = metadata?.name;
26
26
  }
@@ -1,3 +1,4 @@
1
+ import crypto from 'node:crypto';
1
2
  import { asMutable } from 'ts-gems';
2
3
  import { DocumentNode } from './document-node.js';
3
4
  /**
@@ -8,17 +9,19 @@ export const DocumentElement = function (owner) {
8
9
  if (!this)
9
10
  throw new TypeError('"this" should be passed to call class constructor');
10
11
  const _this = asMutable(this);
12
+ _this.id = crypto.randomBytes(16).toString('base64url');
11
13
  Object.defineProperty(_this, 'node', {
12
14
  value: new DocumentNode(this, owner?.node),
13
15
  enumerable: false,
14
16
  writable: true,
15
17
  });
16
- if (owner)
18
+ if (owner) {
17
19
  Object.defineProperty(_this, 'owner', {
18
20
  value: owner,
19
21
  enumerable: false,
20
22
  writable: true,
21
23
  });
24
+ }
22
25
  };
23
26
  /**
24
27
  * @class DocumentElement
@@ -4,7 +4,7 @@ export const DECODER = Symbol.for('opra.type.decoder');
4
4
  export const ENCODER = Symbol('opra.type.encoder');
5
5
  export const DECORATOR = Symbol.for('DECORATOR');
6
6
  export const BUILTIN = Symbol.for('BUILTIN');
7
- export const NAMESPACE_PATTERN = /([a-z$_]\w+)(:.+)/i;
7
+ export const NAMESPACE_PATTERN = /([a-z$_]\w+):(.+)/i;
8
8
  export const CLASS_NAME_PATTERN = /^[a-z][\w_]*$/i;
9
9
  export const EXTRACT_TYPENAME_PATTERN = /^(.*)Type(\d*)$/;
10
10
  export const kDataTypeMap = Symbol.for('kDataTypeMap');
@@ -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,6 +34,8 @@ 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;
37
40
  };
38
41
  /**
@@ -43,7 +46,7 @@ class ApiFieldClass extends DocumentElement {
43
46
  toJSON() {
44
47
  const typeName = this.type ? this.node.getDataTypeNameWithNs(this.type) : undefined;
45
48
  return omitUndefined({
46
- type: this.type ? (typeName ? typeName : this.type?.toJSON()) : undefined,
49
+ type: typeName ? typeName : this.type?.toJSON(),
47
50
  description: this.description,
48
51
  isArray: this.isArray,
49
52
  default: this.default,
@@ -52,6 +55,8 @@ class ApiFieldClass extends DocumentElement {
52
55
  exclusive: this.exclusive,
53
56
  translatable: this.translatable,
54
57
  deprecated: this.deprecated,
58
+ readonly: this.readonly,
59
+ writeonly: this.writeonly,
55
60
  examples: this.examples,
56
61
  });
57
62
  }
@@ -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)) {
@@ -143,6 +144,10 @@ 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) || (context.ignoreWriteonlyFields && field.writeonly)) {
148
+ schema[field.name] = vg.isUndefined({ coerce: true });
149
+ continue;
150
+ }
146
151
  fieldName = field.name;
147
152
  let p;
148
153
  if (projection !== '*') {
@@ -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)
@@ -72,9 +76,8 @@ class ComplexTypeClass extends ComplexTypeBase {
72
76
  });
73
77
  if (this.additionalFields) {
74
78
  if (this.additionalFields instanceof DataType) {
75
- out.additionalFields = this.additionalFields[1].name
76
- ? this.additionalFields[1].name
77
- : this.additionalFields[1].toJSON();
79
+ const typeName = this.node.getDataTypeNameWithNs(this.additionalFields);
80
+ out.additionalFields = typeName ? typeName : this.additionalFields.toJSON();
78
81
  }
79
82
  else
80
83
  out.additionalFields = this.additionalFields;
@@ -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)
@@ -1,4 +1,4 @@
1
- import { __decorate } from "tslib";
1
+ import { __decorate, __metadata } from "tslib";
2
2
  import { vg } from 'valgen';
3
3
  import { DECODER, ENCODER } from '../../constants.js';
4
4
  import { SimpleType } from '../simple-type.js';
@@ -17,6 +17,11 @@ let Base64Type = class Base64Type {
17
17
  Base64Type = __decorate([
18
18
  SimpleType({
19
19
  description: 'A stream of bytes, base64 encoded',
20
- })
20
+ nameMappings: {
21
+ js: 'string',
22
+ json: 'string',
23
+ },
24
+ }),
25
+ __metadata("design:paramtypes", [Object])
21
26
  ], Base64Type);
22
27
  export { Base64Type };
@@ -1,4 +1,4 @@
1
- import { __decorate } from "tslib";
1
+ import { __decorate, __metadata } from "tslib";
2
2
  import { vg } from 'valgen';
3
3
  import { DECODER, ENCODER } from '../../constants.js';
4
4
  import { SimpleType } from '../simple-type.js';
@@ -23,19 +23,26 @@ let DateStringType = class DateStringType {
23
23
  __decorate([
24
24
  SimpleType.Attribute({
25
25
  description: 'Minimum value',
26
- })
26
+ }),
27
+ __metadata("design:type", String)
27
28
  ], DateStringType.prototype, "minValue", void 0);
28
29
  __decorate([
29
30
  SimpleType.Attribute({
30
31
  description: 'Maximum value',
31
- })
32
+ }),
33
+ __metadata("design:type", String)
32
34
  ], DateStringType.prototype, "maxValue", void 0);
33
35
  DateStringType = __decorate([
34
- SimpleType({
36
+ (SimpleType({
35
37
  description: 'Date string value',
38
+ nameMappings: {
39
+ js: 'string',
40
+ json: 'string',
41
+ },
36
42
  })
37
43
  .Example('2021-04-18', 'Full date value')
38
44
  .Example('2021-04', 'Date value without day')
39
- .Example('2021', 'Year only value')
45
+ .Example('2021', 'Year only value')),
46
+ __metadata("design:paramtypes", [Object])
40
47
  ], DateStringType);
41
48
  export { DateStringType };
@@ -1,4 +1,4 @@
1
- import { __decorate } from "tslib";
1
+ import { __decorate, __metadata } from "tslib";
2
2
  import { vg } from 'valgen';
3
3
  import { DECODER, ENCODER } from '../../constants.js';
4
4
  import { SimpleType } from '../simple-type.js';
@@ -23,22 +23,29 @@ let DateTimeStringType = class DateTimeStringType {
23
23
  __decorate([
24
24
  SimpleType.Attribute({
25
25
  description: 'Minimum value',
26
- })
26
+ }),
27
+ __metadata("design:type", String)
27
28
  ], DateTimeStringType.prototype, "minValue", void 0);
28
29
  __decorate([
29
30
  SimpleType.Attribute({
30
31
  description: 'Maximum value',
31
- })
32
+ }),
33
+ __metadata("design:type", String)
32
34
  ], DateTimeStringType.prototype, "maxValue", void 0);
33
35
  DateTimeStringType = __decorate([
34
- SimpleType({
36
+ (SimpleType({
35
37
  description: 'DateTime string value',
38
+ nameMappings: {
39
+ js: 'string',
40
+ json: 'string',
41
+ },
36
42
  })
37
43
  .Example('2021-04-18T22:30:15+01:00', 'Full date-time value with timezone')
38
44
  .Example('2021-04-18T22:30:15', 'Full date-time value without timezone')
39
45
  .Example('2021-04-18 22:30', 'Date-time value')
40
46
  .Example('2021-04-18', 'Date value')
41
47
  .Example('2021-04', 'Date value without day')
42
- .Example('2021', 'Year only value')
48
+ .Example('2021', 'Year only value')),
49
+ __metadata("design:paramtypes", [Object])
43
50
  ], DateTimeStringType);
44
51
  export { DateTimeStringType };
@@ -1,4 +1,4 @@
1
- import { __decorate } from "tslib";
1
+ import { __decorate, __metadata } from "tslib";
2
2
  import { isDateString, toString, vg } from 'valgen';
3
3
  import { DECODER, ENCODER } from '../../constants.js';
4
4
  import { SimpleType } from '../simple-type.js';
@@ -37,19 +37,26 @@ let DateTimeType = class DateTimeType {
37
37
  __decorate([
38
38
  SimpleType.Attribute({
39
39
  description: 'Minimum value',
40
- })
40
+ }),
41
+ __metadata("design:type", String)
41
42
  ], DateTimeType.prototype, "minValue", void 0);
42
43
  __decorate([
43
44
  SimpleType.Attribute({
44
45
  description: 'Maximum value',
45
- })
46
+ }),
47
+ __metadata("design:type", String)
46
48
  ], DateTimeType.prototype, "maxValue", void 0);
47
49
  DateTimeType = __decorate([
48
- SimpleType({
50
+ (SimpleType({
49
51
  description: 'A full datetime value',
52
+ nameMappings: {
53
+ js: 'string',
54
+ json: 'string',
55
+ },
50
56
  })
51
57
  .Example('2021-04-18T22:30:15')
52
58
  .Example('2021-04-18 22:30:15')
53
- .Example('2021-04-18 22:30')
59
+ .Example('2021-04-18 22:30')),
60
+ __metadata("design:paramtypes", [Object])
54
61
  ], DateTimeType);
55
62
  export { DateTimeType };