@opra/common 1.0.0-alpha.9 → 1.0.0-beta.1

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 (199) hide show
  1. package/browser/index.cjs +12 -0
  2. package/browser/index.mjs +12 -0
  3. package/cjs/document/api-document.js +11 -0
  4. package/cjs/document/common/api-base.js +1 -1
  5. package/cjs/document/common/document-element.js +2 -0
  6. package/cjs/document/data-type/api-field.js +8 -7
  7. package/cjs/document/data-type/complex-type-base.js +5 -3
  8. package/cjs/document/data-type/extended-types/date-string.type.js +2 -2
  9. package/cjs/document/data-type/extended-types/date-time-string.type.js +2 -2
  10. package/cjs/document/data-type/extended-types/date-time.type.js +2 -2
  11. package/cjs/document/data-type/extended-types/date.type.js +2 -2
  12. package/cjs/document/data-type/extended-types/email.type.js +2 -2
  13. package/cjs/document/data-type/extended-types/filter.type.js +1 -1
  14. package/cjs/document/data-type/extended-types/time.type.js +2 -2
  15. package/cjs/document/data-type/extended-types/url.type.js +2 -2
  16. package/cjs/document/data-type/omit-type.js +7 -2
  17. package/cjs/document/data-type/partial-type.js +7 -2
  18. package/cjs/document/data-type/pick-type.js +1 -2
  19. package/cjs/document/data-type/primitive-types/object.type.js +0 -3
  20. package/cjs/document/data-type/required-type.js +1 -2
  21. package/cjs/document/data-type/simple-type.js +1 -6
  22. package/cjs/document/data-type/utils/create-mapped-class.js +1 -2
  23. package/cjs/document/data-type/utils/get-is-inherited-predicate-fn.js +1 -2
  24. package/cjs/document/decorators/api-field-decorator.js +4 -6
  25. package/cjs/document/decorators/complex-type.decorator.js +1 -2
  26. package/cjs/document/decorators/http-controller.decorator.js +2 -3
  27. package/cjs/document/decorators/http-operation-entity.decorator.js +68 -74
  28. package/cjs/document/decorators/http-operation.decorator.js +4 -2
  29. package/cjs/document/decorators/simple-type.decorator.js +2 -3
  30. package/cjs/document/factory/api-document.factory.js +17 -8
  31. package/cjs/document/http/http-api.js +0 -1
  32. package/cjs/document/http/http-controller.js +4 -2
  33. package/cjs/document/http/http-media-type.js +17 -2
  34. package/cjs/document/http/http-multipart-field.js +0 -1
  35. package/cjs/document/http/http-operation-response.js +0 -1
  36. package/cjs/document/http/http-operation.js +12 -1
  37. package/cjs/document/http/http-parameter.js +2 -0
  38. package/cjs/document/http/http-request-body.js +0 -1
  39. package/cjs/document/http/http-status-range.js +5 -2
  40. package/cjs/document/utils/parse-regexp.util.js +1 -2
  41. package/cjs/document/utils/string-compare.util.js +1 -2
  42. package/cjs/exception/opra-exception.js +1 -0
  43. package/cjs/filter/build.js +21 -22
  44. package/cjs/filter/filter-rules.js +17 -16
  45. package/cjs/filter/parse.js +1 -2
  46. package/cjs/filter/utils.js +2 -3
  47. package/cjs/helpers/function-utils.js +1 -2
  48. package/cjs/helpers/get-stack-filename.js +2 -3
  49. package/cjs/helpers/index.js +1 -0
  50. package/cjs/helpers/mixin-utils.js +2 -3
  51. package/cjs/helpers/object-utils.js +5 -6
  52. package/cjs/helpers/parse-fields-projection.js +3 -3
  53. package/cjs/helpers/safe-json-stringify.js +16 -0
  54. package/cjs/helpers/type-guards.js +10 -11
  55. package/cjs/i18n/string-utils.js +2 -3
  56. package/cjs/i18n/translate.js +1 -2
  57. package/cjs/schema/index.js +2 -27
  58. package/cjs/schema/opra-schema.js +24 -0
  59. package/cjs/schema/type-guards.js +7 -8
  60. package/esm/document/api-document.js +11 -0
  61. package/esm/document/common/api-base.js +1 -1
  62. package/esm/document/common/document-element.js +2 -0
  63. package/esm/document/data-type/api-field.js +8 -7
  64. package/esm/document/data-type/complex-type-base.js +5 -3
  65. package/esm/document/data-type/extended-types/date-string.type.js +2 -2
  66. package/esm/document/data-type/extended-types/date-time-string.type.js +2 -2
  67. package/esm/document/data-type/extended-types/date-time.type.js +2 -2
  68. package/esm/document/data-type/extended-types/date.type.js +2 -2
  69. package/esm/document/data-type/extended-types/email.type.js +2 -2
  70. package/esm/document/data-type/extended-types/filter.type.js +1 -1
  71. package/esm/document/data-type/extended-types/time.type.js +2 -2
  72. package/esm/document/data-type/extended-types/url.type.js +2 -2
  73. package/esm/document/data-type/omit-type.js +6 -0
  74. package/esm/document/data-type/partial-type.js +6 -0
  75. package/esm/document/data-type/primitive-types/object.type.js +0 -3
  76. package/esm/document/data-type/simple-type.js +1 -6
  77. package/esm/document/decorators/api-field-decorator.js +1 -2
  78. package/esm/document/decorators/http-controller.decorator.js +1 -1
  79. package/esm/document/decorators/http-operation-entity.decorator.js +25 -31
  80. package/esm/document/decorators/http-operation.decorator.js +3 -0
  81. package/esm/document/factory/api-document.factory.js +17 -7
  82. package/esm/document/http/http-api.js +0 -1
  83. package/esm/document/http/http-controller.js +3 -2
  84. package/esm/document/http/http-media-type.js +16 -2
  85. package/esm/document/http/http-multipart-field.js +0 -1
  86. package/esm/document/http/http-operation-response.js +0 -1
  87. package/esm/document/http/http-operation.js +12 -1
  88. package/esm/document/http/http-parameter.js +2 -0
  89. package/esm/document/http/http-request-body.js +0 -1
  90. package/esm/document/http/http-status-range.js +5 -2
  91. package/esm/exception/opra-exception.js +1 -0
  92. package/esm/filter/filter-rules.js +10 -9
  93. package/esm/helpers/index.js +1 -0
  94. package/esm/helpers/object-utils.js +2 -2
  95. package/esm/helpers/safe-json-stringify.js +13 -0
  96. package/esm/package.json +3 -0
  97. package/esm/schema/index.js +2 -27
  98. package/esm/schema/opra-schema.js +21 -0
  99. package/package.json +47 -53
  100. package/types/document/api-document.d.ts +2 -1
  101. package/types/document/common/api-base.d.ts +2 -2
  102. package/types/document/common/data-type-map.d.ts +1 -1
  103. package/types/document/common/document-element.d.ts +1 -0
  104. package/types/document/common/document-node.d.ts +8 -8
  105. package/types/document/common/value.d.ts +1 -1
  106. package/types/document/data-type/api-field.d.ts +11 -1
  107. package/types/document/data-type/complex-type-base.d.ts +6 -7
  108. package/types/document/data-type/complex-type.d.ts +1 -1
  109. package/types/document/data-type/data-type.d.ts +3 -2
  110. package/types/document/data-type/enum-type.d.ts +2 -2
  111. package/types/document/data-type/extended-types/base64.type.d.ts +1 -1
  112. package/types/document/data-type/extended-types/date-string.type.d.ts +1 -1
  113. package/types/document/data-type/extended-types/date-time-string.type.d.ts +1 -1
  114. package/types/document/data-type/extended-types/date-time.type.d.ts +1 -1
  115. package/types/document/data-type/extended-types/date.type.d.ts +1 -1
  116. package/types/document/data-type/extended-types/email.type.d.ts +1 -1
  117. package/types/document/data-type/extended-types/field-path.type.d.ts +3 -3
  118. package/types/document/data-type/extended-types/filter.type.d.ts +3 -3
  119. package/types/document/data-type/extended-types/object-id.type.d.ts +1 -1
  120. package/types/document/data-type/extended-types/operation-result.type.d.ts +2 -2
  121. package/types/document/data-type/extended-types/time.type.d.ts +1 -1
  122. package/types/document/data-type/extended-types/url.type.d.ts +1 -1
  123. package/types/document/data-type/extended-types/uuid.type.d.ts +1 -1
  124. package/types/document/data-type/mapped-type.d.ts +3 -3
  125. package/types/document/data-type/mixin-type.d.ts +1 -1
  126. package/types/document/data-type/omit-type.d.ts +1 -7
  127. package/types/document/data-type/partial-type.d.ts +1 -7
  128. package/types/document/data-type/pick-type.d.ts +3 -3
  129. package/types/document/data-type/primitive-types/any.type.d.ts +1 -1
  130. package/types/document/data-type/primitive-types/bigint.type.d.ts +1 -1
  131. package/types/document/data-type/primitive-types/boolean.type.d.ts +1 -1
  132. package/types/document/data-type/primitive-types/integer.type.d.ts +1 -1
  133. package/types/document/data-type/primitive-types/null.type.d.ts +1 -1
  134. package/types/document/data-type/primitive-types/number.type.d.ts +1 -1
  135. package/types/document/data-type/primitive-types/string.type.d.ts +1 -1
  136. package/types/document/data-type/required-type.d.ts +8 -8
  137. package/types/document/data-type/simple-type.d.ts +2 -2
  138. package/types/document/data-type/utils/create-mapped-class.d.ts +2 -2
  139. package/types/document/decorators/api-field-decorator.d.ts +1 -1
  140. package/types/document/decorators/http-controller.decorator.d.ts +3 -3
  141. package/types/document/decorators/http-operation-entity.decorator.d.ts +5 -4
  142. package/types/document/decorators/http-operation.decorator.d.ts +1 -1
  143. package/types/document/factory/api-document.factory.d.ts +2 -1
  144. package/types/document/factory/data-type.factory.d.ts +1 -1
  145. package/types/document/factory/http-api.factory.d.ts +1 -1
  146. package/types/document/http/http-api.d.ts +2 -2
  147. package/types/document/http/http-controller.d.ts +1 -1
  148. package/types/document/http/http-media-type.d.ts +3 -2
  149. package/types/document/http/http-multipart-field.d.ts +1 -2
  150. package/types/document/http/http-operation-response.d.ts +1 -1
  151. package/types/document/http/http-operation.d.ts +6 -5
  152. package/types/document/http/http-parameter.d.ts +2 -2
  153. package/types/document/http/http-request-body.d.ts +1 -1
  154. package/types/document/http/http-status-range.d.ts +2 -1
  155. package/types/exception/http-errors/bad-request.error.d.ts +1 -1
  156. package/types/exception/http-errors/conflict.error.d.ts +1 -1
  157. package/types/exception/http-errors/failed-dependency.error.d.ts +1 -1
  158. package/types/exception/http-errors/forbidden.error.d.ts +1 -1
  159. package/types/exception/http-errors/internal-server.error.d.ts +1 -1
  160. package/types/exception/http-errors/method-not-allowed.error.d.ts +1 -1
  161. package/types/exception/http-errors/not-acceptable.error.d.ts +1 -1
  162. package/types/exception/http-errors/not-found.error.d.ts +1 -1
  163. package/types/exception/http-errors/permission.error.d.ts +1 -1
  164. package/types/exception/http-errors/unauthorized.error.d.ts +1 -1
  165. package/types/exception/http-errors/unprocessable-entity.error.d.ts +1 -1
  166. package/types/exception/opra-exception.d.ts +1 -1
  167. package/types/exception/opra-http-error.d.ts +1 -1
  168. package/types/filter/antlr/OpraFilterParser.d.ts +1 -1
  169. package/types/filter/ast/expressions/comparison-expression.d.ts +1 -1
  170. package/types/filter/errors.d.ts +3 -4
  171. package/types/filter/filter-rules.d.ts +5 -5
  172. package/types/filter/opra-error-listener.d.ts +1 -2
  173. package/types/helpers/function-utils.d.ts +1 -1
  174. package/types/helpers/index.d.ts +1 -0
  175. package/types/helpers/mixin-utils.d.ts +1 -1
  176. package/types/helpers/object-utils.d.ts +1 -1
  177. package/types/helpers/safe-json-stringify.d.ts +1 -0
  178. package/types/helpers/type-guards.d.ts +1 -3
  179. package/types/i18n/i18n.d.ts +2 -2
  180. package/types/i18n/translate.d.ts +1 -1
  181. package/types/index.d.cts +9 -0
  182. package/types/schema/{document.interface.d.ts → api-document.interface.d.ts} +4 -4
  183. package/types/schema/data-type/complex-type.interface.d.ts +1 -1
  184. package/types/schema/data-type/data-type.interface.d.ts +1 -1
  185. package/types/schema/data-type/enum-type.interface.d.ts +1 -1
  186. package/types/schema/data-type/mapped-type.interface.d.ts +3 -3
  187. package/types/schema/data-type/mixin-type.interface.d.ts +1 -1
  188. package/types/schema/data-type-container.interface.d.ts +1 -1
  189. package/types/schema/http/http-controller.interface.d.ts +2 -2
  190. package/types/schema/http/http-media-type.interface.d.ts +1 -1
  191. package/types/schema/http/http-operation-response.interface.d.ts +2 -2
  192. package/types/schema/http/http-operation.interface.d.ts +8 -4
  193. package/types/schema/http/http-parameter.interface.d.ts +2 -2
  194. package/types/schema/index.d.ts +2 -62
  195. package/types/schema/opra-schema.d.ts +21 -0
  196. package/types/schema/type-guards.d.ts +1 -1
  197. package/browser.js +0 -13393
  198. /package/cjs/schema/{document.interface.js → api-document.interface.js} +0 -0
  199. /package/esm/schema/{document.interface.js → api-document.interface.js} +0 -0
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ApiDocumentFactory = void 0;
4
- const tslib_1 = require("tslib");
5
- const node_crypto_1 = tslib_1.__importDefault(require("node:crypto"));
6
- const ts_gems_1 = require("ts-gems");
7
4
  const index_js_1 = require("../../helpers/index.js");
8
5
  const index_js_2 = require("../../schema/index.js");
9
6
  const api_document_js_1 = require("../api-document.js");
@@ -19,6 +16,9 @@ const OPRA_SPEC_URL = 'https://oprajs.com/spec/v' + index_js_2.OpraSchema.SpecVe
19
16
  * @class ApiDocumentFactory
20
17
  */
21
18
  class ApiDocumentFactory {
19
+ constructor() {
20
+ this._allDocuments = {};
21
+ }
22
22
  /**
23
23
  * Creates ApiDocument instance from given schema object
24
24
  */
@@ -68,9 +68,14 @@ class ApiDocumentFactory {
68
68
  else
69
69
  init = schemaOrUrl;
70
70
  // Add builtin data types if this document is the root
71
+ let builtinDocument;
71
72
  if (!document[constants_js_1.BUILTIN]) {
72
- const builtinDocument = await this.createBuiltinDocument(context);
73
- document.references.set('opra', builtinDocument);
73
+ const t = document.node.findDataType('string');
74
+ builtinDocument = t?.node.getDocument();
75
+ if (!builtinDocument) {
76
+ builtinDocument = await this.createBuiltinDocument(context);
77
+ document.references.set('opra', builtinDocument);
78
+ }
74
79
  }
75
80
  init.spec = init.spec || index_js_2.OpraSchema.SpecVersion;
76
81
  document.url = init.url;
@@ -91,8 +96,10 @@ class ApiDocumentFactory {
91
96
  return;
92
97
  }
93
98
  const refDoc = new api_document_js_1.ApiDocument();
99
+ if (builtinDocument)
100
+ refDoc.references.set('opra', builtinDocument);
94
101
  await this.initDocument(refDoc, context, r);
95
- document.references.set(ns, refDoc);
102
+ document.references.set(ns, this._allDocuments[refDoc.id]);
96
103
  });
97
104
  }
98
105
  });
@@ -113,8 +120,10 @@ class ApiDocumentFactory {
113
120
  context.addError(`Unknown service protocol (${init.api.protocol})`);
114
121
  });
115
122
  }
116
- const x = document.export();
117
- (0, ts_gems_1.asMutable)(document).id = node_crypto_1.default.createHash('md5').update(JSON.stringify(x)).digest('base64url');
123
+ document.invalidate();
124
+ /** Add document to global registry */
125
+ if (!this._allDocuments[document.id])
126
+ this._allDocuments[document.id] = document;
118
127
  }
119
128
  /**
120
129
  *
@@ -10,7 +10,6 @@ const http_controller_js_1 = require("./http-controller.js");
10
10
  class HttpApi extends api_base_js_1.ApiBase {
11
11
  constructor(owner) {
12
12
  super(owner);
13
- this.owner = owner;
14
13
  // noinspection JSUnusedGlobalSymbols
15
14
  this._controllerReverseMap = new WeakMap();
16
15
  this.protocol = 'http';
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HttpController = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const node_path_1 = tslib_1.__importDefault(require("node:path"));
4
6
  const ts_gems_1 = require("ts-gems");
5
7
  const index_js_1 = require("../../helpers/index.js");
6
8
  const index_js_2 = require("../../schema/index.js");
@@ -29,7 +31,7 @@ exports.HttpController = function (...args) {
29
31
  _this.parameters = [];
30
32
  _this.name = initArgs.name;
31
33
  _this.description = initArgs.description;
32
- _this.path = initArgs.path || initArgs.name;
34
+ _this.path = initArgs.path ?? initArgs.name;
33
35
  _this.instance = initArgs.instance;
34
36
  _this.ctor = initArgs.ctor;
35
37
  _this._controllerReverseMap = new WeakMap();
@@ -100,7 +102,7 @@ class HttpControllerClass extends document_element_js_1.DocumentElement {
100
102
  }
101
103
  }
102
104
  getFullUrl() {
103
- return (this.owner instanceof exports.HttpController ? this.owner.getFullUrl() : '/') + this.path;
105
+ return node_path_1.default.posix.join(this.owner instanceof exports.HttpController ? this.owner.getFullUrl() : '/', this.path);
104
106
  }
105
107
  /**
106
108
  *
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HttpMediaType = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const type_is_1 = tslib_1.__importDefault(require("@browsery/type-is"));
4
6
  const ts_gems_1 = require("ts-gems");
7
+ const valgen_1 = require("valgen");
5
8
  const index_js_1 = require("../../helpers/index.js");
6
9
  const document_element_js_1 = require("../common/document-element.js");
7
10
  const data_type_js_1 = require("../data-type/data-type.js");
@@ -24,7 +27,6 @@ exports.HttpMediaType = function (owner, initArgs) {
24
27
  _this.maxFiles = initArgs.maxFiles;
25
28
  _this.maxFileSize = initArgs.maxFileSize;
26
29
  _this.maxTotalFileSize = initArgs.maxTotalFileSize;
27
- _this.minFileSize = initArgs.minFileSize;
28
30
  if (initArgs?.type) {
29
31
  _this.type = initArgs?.type instanceof data_type_js_1.DataType ? initArgs.type : _this.owner.node.getDataType(initArgs.type);
30
32
  }
@@ -59,12 +61,25 @@ class HttpMediaTypeClass extends document_element_js_1.DocumentElement {
59
61
  maxFiles: this.maxFiles,
60
62
  maxFileSize: this.maxFileSize,
61
63
  maxTotalFileSize: this.maxTotalFileSize,
62
- minFileSize: this.minFileSize,
63
64
  });
64
65
  if (this.multipartFields?.length) {
65
66
  out.multipartFields = this.multipartFields.map(x => x.toJSON());
66
67
  }
67
68
  return out;
68
69
  }
70
+ generateCodec(codec, options) {
71
+ let fn;
72
+ if (this.type) {
73
+ fn = this.type.generateCodec(codec, options);
74
+ }
75
+ else if (this.contentType) {
76
+ const arr = Array.isArray(this.contentType) ? this.contentType : [this.contentType];
77
+ if (arr.find(ct => type_is_1.default.is(ct, ['json']))) {
78
+ fn = this.node.findDataType('object').generateCodec(codec);
79
+ }
80
+ }
81
+ fn = fn || valgen_1.isAny;
82
+ return this.isArray ? valgen_1.vg.isArray(fn) : fn;
83
+ }
69
84
  }
70
85
  exports.HttpMediaType.prototype = HttpMediaTypeClass.prototype;
@@ -11,7 +11,6 @@ const http_media_type_js_1 = require("./http-media-type.js");
11
11
  class HttpMultipartField extends http_media_type_js_1.HttpMediaType {
12
12
  constructor(owner, initArgs) {
13
13
  super(owner, initArgs);
14
- this.owner = owner;
15
14
  this.fieldName =
16
15
  initArgs.fieldName instanceof RegExp
17
16
  ? initArgs.fieldName
@@ -10,7 +10,6 @@ const http_status_range_js_1 = require("./http-status-range.js");
10
10
  class HttpOperationResponse extends http_media_type_js_1.HttpMediaType {
11
11
  constructor(owner, init) {
12
12
  super(owner, init);
13
- this.owner = owner;
14
13
  this.parameters = [];
15
14
  this.statusCode = (Array.isArray(init.statusCode) ? init.statusCode : [init.statusCode]).map(x => typeof x === 'object' ? new http_status_range_js_1.HttpStatusRange(x.start, x.end) : new http_status_range_js_1.HttpStatusRange(x));
16
15
  this.partial = init.partial;
@@ -31,6 +31,7 @@ exports.HttpOperation = function (...args) {
31
31
  _this.types = _this.node[constants_js_1.kDataTypeMap] = new data_type_map_js_1.DataTypeMap();
32
32
  _this.name = initArgs.name;
33
33
  _this.path = initArgs.path;
34
+ _this.mergePath = initArgs.mergePath;
34
35
  _this.method = initArgs.method || 'GET';
35
36
  _this.description = initArgs.description;
36
37
  _this.composition = initArgs.composition;
@@ -57,13 +58,23 @@ class HttpOperationClass extends document_element_js_1.DocumentElement {
57
58
  }
58
59
  getFullUrl() {
59
60
  const out = this.owner.getFullUrl();
60
- return out ? (this.path ? node_path_1.default.posix.join(out, this.path) : out) : this.path || '/';
61
+ if (out) {
62
+ if (this.path) {
63
+ if (this.mergePath)
64
+ return out + this.path;
65
+ return node_path_1.default.posix.join(out, this.path);
66
+ }
67
+ return out;
68
+ }
69
+ return this.path || '/';
61
70
  }
62
71
  toJSON() {
63
72
  const out = (0, index_js_1.omitUndefined)({
64
73
  kind: index_js_2.OpraSchema.HttpOperation.Kind,
65
74
  description: this.description,
66
75
  method: this.method,
76
+ path: this.path,
77
+ mergePath: this.mergePath,
67
78
  composition: this.composition,
68
79
  requestBody: this.requestBody?.toJSON(),
69
80
  });
@@ -24,6 +24,8 @@ exports.HttpParameter = function (owner, initArgs) {
24
24
  _this.location = initArgs.location;
25
25
  _this.deprecated = initArgs.deprecated;
26
26
  _this.required = initArgs.required;
27
+ if (_this.required == null && initArgs.location === 'path')
28
+ _this.required = true;
27
29
  _this.arraySeparator = initArgs.arraySeparator;
28
30
  _this.keyParam = initArgs.keyParam;
29
31
  };
@@ -9,7 +9,6 @@ const document_element_js_1 = require("../common/document-element.js");
9
9
  class HttpRequestBody extends document_element_js_1.DocumentElement {
10
10
  constructor(owner) {
11
11
  super(owner);
12
- this.owner = owner;
13
12
  this.content = [];
14
13
  }
15
14
  toJSON() {
@@ -25,8 +25,11 @@ class HttpStatusRange {
25
25
  this.end = m[2] ? parseInt(m[2], 10) : this.start;
26
26
  }
27
27
  }
28
- get distance() {
29
- return this.end - this.start;
28
+ includes(statusCode) {
29
+ return statusCode >= this.start && statusCode <= this.end;
30
+ }
31
+ intersects(start, end) {
32
+ return end >= this.start && start <= this.end;
30
33
  }
31
34
  toString() {
32
35
  if (this.start === this.end)
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseRegExp = void 0;
3
+ exports.parseRegExp = parseRegExp;
4
4
  function parseRegExp(str, options) {
5
5
  const i = str.lastIndexOf('/');
6
6
  if (str.startsWith('/') && i) {
@@ -19,4 +19,3 @@ function parseRegExp(str, options) {
19
19
  }
20
20
  throw new TypeError(`"${str}" is not a valid RegExp string`);
21
21
  }
22
- exports.parseRegExp = parseRegExp;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stringCompare = void 0;
3
+ exports.stringCompare = stringCompare;
4
4
  function stringCompare(a, b) {
5
5
  if (a < b)
6
6
  return -1;
@@ -8,4 +8,3 @@ function stringCompare(a, b) {
8
8
  return 1;
9
9
  return 0;
10
10
  }
11
- exports.stringCompare = stringCompare;
@@ -9,6 +9,7 @@ const index_js_2 = require("../i18n/index.js");
9
9
  class OpraException extends Error {
10
10
  constructor(issue, cause) {
11
11
  super('Unknown error');
12
+ this.severity = 'error';
12
13
  cause = cause || (issue instanceof Error ? issue : undefined);
13
14
  if (issue instanceof Error)
14
15
  cause = issue;
@@ -1,87 +1,87 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.$arithmetic = exports.$paren = exports.$notILike = exports.$ilike = exports.$notLike = exports.$like = exports.$notIn = exports.$in = exports.$lte = exports.$lt = exports.$gte = exports.$gt = exports.$ne = exports.$eq = exports.$field = exports.$array = exports.$number = exports.$time = exports.$date = exports.$and = exports.$or = void 0;
3
+ exports.$or = $or;
4
+ exports.$and = $and;
5
+ exports.$date = $date;
6
+ exports.$time = $time;
7
+ exports.$number = $number;
8
+ exports.$array = $array;
9
+ exports.$field = $field;
10
+ exports.$eq = $eq;
11
+ exports.$ne = $ne;
12
+ exports.$gt = $gt;
13
+ exports.$gte = $gte;
14
+ exports.$lt = $lt;
15
+ exports.$lte = $lte;
16
+ exports.$in = $in;
17
+ exports.$notIn = $notIn;
18
+ exports.$like = $like;
19
+ exports.$notLike = $notLike;
20
+ exports.$ilike = $ilike;
21
+ exports.$notILike = $notILike;
22
+ exports.$paren = $paren;
23
+ exports.$arithmetic = $arithmetic;
4
24
  const index_js_1 = require("./ast/index.js");
5
25
  function $or(...items) {
6
26
  return new index_js_1.LogicalExpression({ op: 'or', items });
7
27
  }
8
- exports.$or = $or;
9
28
  function $and(...items) {
10
29
  return new index_js_1.LogicalExpression({ op: 'and', items });
11
30
  }
12
- exports.$and = $and;
13
31
  function $date(v) {
14
32
  return new index_js_1.DateLiteral(v);
15
33
  }
16
- exports.$date = $date;
17
34
  function $time(v) {
18
35
  return new index_js_1.TimeLiteral(v);
19
36
  }
20
- exports.$time = $time;
21
37
  function $number(v) {
22
38
  return new index_js_1.NumberLiteral(v);
23
39
  }
24
- exports.$number = $number;
25
40
  function $array(...items) {
26
41
  return new index_js_1.ArrayExpression(items.map(wrapEntryValue));
27
42
  }
28
- exports.$array = $array;
29
43
  function $field(v) {
30
44
  return new index_js_1.QualifiedIdentifier(v);
31
45
  }
32
- exports.$field = $field;
33
46
  function $eq(left, right) {
34
47
  return comparisonExpression('=', left, right);
35
48
  }
36
- exports.$eq = $eq;
37
49
  function $ne(left, right) {
38
50
  return comparisonExpression('!=', left, right);
39
51
  }
40
- exports.$ne = $ne;
41
52
  function $gt(left, right) {
42
53
  return comparisonExpression('>', left, right);
43
54
  }
44
- exports.$gt = $gt;
45
55
  function $gte(left, right) {
46
56
  return comparisonExpression('>=', left, right);
47
57
  }
48
- exports.$gte = $gte;
49
58
  function $lt(left, right) {
50
59
  return comparisonExpression('<', left, right);
51
60
  }
52
- exports.$lt = $lt;
53
61
  function $lte(left, right) {
54
62
  return comparisonExpression('<=', left, right);
55
63
  }
56
- exports.$lte = $lte;
57
64
  function $in(left, right) {
58
65
  return comparisonExpression('in', left, right);
59
66
  }
60
- exports.$in = $in;
61
67
  function $notIn(left, right) {
62
68
  return comparisonExpression('!in', left, right);
63
69
  }
64
- exports.$notIn = $notIn;
65
70
  function $like(left, right) {
66
71
  return comparisonExpression('like', left, right);
67
72
  }
68
- exports.$like = $like;
69
73
  function $notLike(left, right) {
70
74
  return comparisonExpression('!like', left, right);
71
75
  }
72
- exports.$notLike = $notLike;
73
76
  function $ilike(left, right) {
74
77
  return comparisonExpression('ilike', left, right);
75
78
  }
76
- exports.$ilike = $ilike;
77
79
  function $notILike(left, right) {
78
80
  return comparisonExpression('!ilike', left, right);
79
81
  }
80
- exports.$notILike = $notILike;
81
82
  function $paren(expression) {
82
83
  return new index_js_1.ParenthesizedExpression(expression);
83
84
  }
84
- exports.$paren = $paren;
85
85
  function $arithmetic(n) {
86
86
  const exp = new index_js_1.ArithmeticExpression();
87
87
  exp.add = (expression) => {
@@ -103,7 +103,6 @@ function $arithmetic(n) {
103
103
  exp.append('+', wrapEntryValue(n));
104
104
  return exp;
105
105
  }
106
- exports.$arithmetic = $arithmetic;
107
106
  function comparisonExpression(op, left, right) {
108
107
  const lex = wrapEntryValue(left);
109
108
  const rex = wrapEntryValue(right);
@@ -2,14 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FilterRules = void 0;
4
4
  const index_js_1 = require("../exception/index.js");
5
- const index_js_2 = require("../filter/index.js");
6
- const index_js_3 = require("../helpers/index.js");
7
- const index_js_4 = require("../i18n/index.js");
5
+ const index_js_2 = require("../helpers/index.js");
6
+ const index_js_3 = require("../i18n/index.js");
7
+ const index_js_4 = require("./ast/index.js");
8
+ const parse_js_1 = require("./parse.js");
8
9
  class FilterRules {
9
10
  constructor(rules, options) {
10
- this._rules = new index_js_3.ResponsiveMap();
11
+ this._rules = new index_js_2.ResponsiveMap();
11
12
  Object.defineProperty(this, '_rules', {
12
- value: new index_js_3.ResponsiveMap(null, { caseSensitive: options?.caseSensitive }),
13
+ value: new index_js_2.ResponsiveMap(null, { caseSensitive: options?.caseSensitive }),
13
14
  enumerable: false,
14
15
  });
15
16
  if (rules) {
@@ -22,7 +23,7 @@ class FilterRules {
22
23
  const operators = typeof options?.operators === 'string'
23
24
  ? options.operators.split(/\s*[,| ]\s*/)
24
25
  : options?.operators;
25
- this._rules.set(fieldName, (0, index_js_3.omitUndefined)({
26
+ this._rules.set(fieldName, (0, index_js_2.omitUndefined)({
26
27
  ...options,
27
28
  operators,
28
29
  }));
@@ -30,10 +31,10 @@ class FilterRules {
30
31
  normalizeFilter(filter, dataType) {
31
32
  if (!filter)
32
33
  return;
33
- const ast = typeof filter === 'string' ? index_js_2.OpraFilter.parse(filter) : filter;
34
- if (ast instanceof index_js_2.OpraFilter.ComparisonExpression) {
34
+ const ast = typeof filter === 'string' ? (0, parse_js_1.parse)(filter) : filter;
35
+ if (ast instanceof index_js_4.ComparisonExpression) {
35
36
  this.normalizeFilter(ast.left, dataType);
36
- if (!(ast.left instanceof index_js_2.OpraFilter.QualifiedIdentifier && ast.left.field)) {
37
+ if (!(ast.left instanceof index_js_4.QualifiedIdentifier && ast.left.field)) {
37
38
  throw new TypeError(`Invalid filter query. Left side should be a data field.`);
38
39
  }
39
40
  // Check if filtering accepted for given field
@@ -41,7 +42,7 @@ class FilterRules {
41
42
  const rule = this._rules.get(ast.left.value);
42
43
  if (!rule) {
43
44
  throw new index_js_1.OpraException({
44
- message: (0, index_js_4.translate)('error:UNACCEPTED_FILTER_FIELD', { field: ast.left.value }),
45
+ message: (0, index_js_3.translate)('error:UNACCEPTED_FILTER_FIELD', { field: ast.left.value }),
45
46
  code: 'UNACCEPTED_FILTER_FIELD',
46
47
  details: {
47
48
  field: ast.left.value,
@@ -51,7 +52,7 @@ class FilterRules {
51
52
  // Check if filtering endpoint accepted for given field
52
53
  if (rule.operators && !rule.operators.includes(ast.op)) {
53
54
  throw new index_js_1.OpraException({
54
- message: (0, index_js_4.translate)('error:UNACCEPTED_FILTER_OPERATION', { field: ast.left.value }),
55
+ message: (0, index_js_3.translate)('error:UNACCEPTED_FILTER_OPERATION', { field: ast.left.value }),
55
56
  code: 'UNACCEPTED_FILTER_OPERATION',
56
57
  details: {
57
58
  field: ast.left.value,
@@ -62,23 +63,23 @@ class FilterRules {
62
63
  this.normalizeFilter(ast.right, dataType);
63
64
  return ast;
64
65
  }
65
- if (ast instanceof index_js_2.OpraFilter.LogicalExpression) {
66
+ if (ast instanceof index_js_4.LogicalExpression) {
66
67
  ast.items.forEach(item => this.normalizeFilter(item, dataType));
67
68
  return ast;
68
69
  }
69
- if (ast instanceof index_js_2.OpraFilter.ArithmeticExpression) {
70
+ if (ast instanceof index_js_4.ArithmeticExpression) {
70
71
  ast.items.forEach(item => this.normalizeFilter(item.expression, dataType));
71
72
  return ast;
72
73
  }
73
- if (ast instanceof index_js_2.OpraFilter.ArrayExpression) {
74
+ if (ast instanceof index_js_4.ArrayExpression) {
74
75
  ast.items.forEach(item => this.normalizeFilter(item, dataType));
75
76
  return ast;
76
77
  }
77
- if (ast instanceof index_js_2.OpraFilter.ParenthesizedExpression) {
78
+ if (ast instanceof index_js_4.ParenthesizedExpression) {
78
79
  this.normalizeFilter(ast.expression, dataType);
79
80
  return ast;
80
81
  }
81
- if (ast instanceof index_js_2.OpraFilter.QualifiedIdentifier && dataType) {
82
+ if (ast instanceof index_js_4.QualifiedIdentifier && dataType) {
82
83
  ast.value = dataType.normalizeFieldPath(ast.value);
83
84
  ast.field = dataType.getField(ast.value);
84
85
  ast.dataType = ast.field.type;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parse = void 0;
3
+ exports.parse = parse;
4
4
  const tslib_1 = require("tslib");
5
5
  const antlr4_1 = require("@browsery/antlr4");
6
6
  const OpraFilterLexer_js_1 = tslib_1.__importDefault(require("./antlr/OpraFilterLexer.js"));
@@ -34,4 +34,3 @@ function parse(text, visitor) {
34
34
  visitor = visitor || new filter_tree_visitor_js_1.FilterTreeVisitor();
35
35
  return visitor.visit(tree);
36
36
  }
37
- exports.parse = parse;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.unquoteFilterString = exports.quoteFilterString = void 0;
3
+ exports.quoteFilterString = quoteFilterString;
4
+ exports.unquoteFilterString = unquoteFilterString;
4
5
  const quotesRegEx = /'/g;
5
6
  const escapeRegEx = /(\\)/g;
6
7
  const unescapeRegEx = /\\(.)/g;
@@ -13,7 +14,6 @@ function unescapeString(s) {
13
14
  function quoteFilterString(s) {
14
15
  return "'" + escapeString(s).replace(quotesRegEx, "\\'") + "'";
15
16
  }
16
- exports.quoteFilterString = quoteFilterString;
17
17
  function unquoteFilterString(s) {
18
18
  if (s && (s.startsWith("'") || s.startsWith('"')) && s.endsWith(s.charAt(0))) {
19
19
  return unescapeString(s.substring(1, s.length - 1));
@@ -21,4 +21,3 @@ function unquoteFilterString(s) {
21
21
  /* istanbul ignore next */
22
22
  return s;
23
23
  }
24
- exports.unquoteFilterString = unquoteFilterString;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveThunk = void 0;
3
+ exports.resolveThunk = resolveThunk;
4
4
  const tslib_1 = require("tslib");
5
5
  const putil_promisify_1 = tslib_1.__importDefault(require("putil-promisify"));
6
6
  const type_guards_js_1 = require("./type-guards.js");
@@ -13,4 +13,3 @@ async function resolveThunk(thunk) {
13
13
  }
14
14
  return thunk;
15
15
  }
16
- exports.resolveThunk = resolveThunk;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getErrorStack = exports.getStackFileName = void 0;
3
+ exports.getStackFileName = getStackFileName;
4
+ exports.getErrorStack = getErrorStack;
4
5
  const PATH_PATTERN = /^(?:file:\/\/)?(.+)$/;
5
6
  function getStackFileName(position = 1) {
6
7
  if (position >= Error.stackTraceLimit) {
@@ -23,7 +24,6 @@ function getStackFileName(position = 1) {
23
24
  }
24
25
  return '';
25
26
  }
26
- exports.getStackFileName = getStackFileName;
27
27
  function getErrorStack(position = 1) {
28
28
  if (position >= Error.stackTraceLimit) {
29
29
  throw new TypeError('getCallerFile(position) requires position be less then Error.stackTraceLimit but position was: `' +
@@ -45,4 +45,3 @@ function getErrorStack(position = 1) {
45
45
  }
46
46
  return '';
47
47
  }
48
- exports.getErrorStack = getErrorStack;
@@ -8,4 +8,5 @@ tslib_1.__exportStar(require("./mixin-utils.js"), exports);
8
8
  tslib_1.__exportStar(require("./object-utils.js"), exports);
9
9
  tslib_1.__exportStar(require("./parse-fields-projection.js"), exports);
10
10
  tslib_1.__exportStar(require("./responsive-map.js"), exports);
11
+ tslib_1.__exportStar(require("./safe-json-stringify.js"), exports);
11
12
  tslib_1.__exportStar(require("./type-guards.js"), exports);
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.inheritPropertyInitializers = exports.mergePrototype = void 0;
3
+ exports.mergePrototype = mergePrototype;
4
+ exports.inheritPropertyInitializers = inheritPropertyInitializers;
4
5
  function mergePrototype(targetProto, baseProto, filter) {
5
6
  for (const k of Object.getOwnPropertyNames(baseProto)) {
6
7
  if (k === 'constructor' || k === '__proto__' || k === 'toJSON' || k === 'toString' || (filter && !filter(k))) {
@@ -9,7 +10,6 @@ function mergePrototype(targetProto, baseProto, filter) {
9
10
  Object.defineProperty(targetProto, k, Object.getOwnPropertyDescriptor(baseProto, k) || Object.create(null));
10
11
  }
11
12
  }
12
- exports.mergePrototype = mergePrototype;
13
13
  // noinspection JSUnusedLocalSymbols
14
14
  function inheritPropertyInitializers(target, clazz,
15
15
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -28,4 +28,3 @@ isPropertyInherited = (key) => true) {
28
28
  //
29
29
  }
30
30
  }
31
- exports.inheritPropertyInitializers = inheritPropertyInitializers;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.omitNullish = exports.omitUndefined = exports.cloneObject = void 0;
3
+ exports.cloneObject = cloneObject;
4
+ exports.omitUndefined = omitUndefined;
5
+ exports.omitNullish = omitNullish;
4
6
  const tslib_1 = require("tslib");
5
7
  const putil_isplainobject_1 = tslib_1.__importDefault(require("putil-isplainobject"));
6
8
  const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
@@ -8,14 +10,13 @@ const constants_js_1 = require("../document/constants.js");
8
10
  function cloneObject(obj, jsonOnly) {
9
11
  return (0, putil_merge_1.default)({}, obj, {
10
12
  deep: v => (0, putil_isplainobject_1.default)(v) && !v[constants_js_1.DATATYPE_METADATA],
13
+ descriptor: true,
11
14
  filter: (source, key) => {
12
15
  const v = source[key];
13
- return ((v != null && !jsonOnly) ||
14
- (typeof v !== 'function' && (typeof v !== 'object' || (0, putil_isplainobject_1.default)(v) || Array.isArray(v))));
16
+ return !jsonOnly || (typeof v !== 'function' && (typeof v !== 'object' || (0, putil_isplainobject_1.default)(v) || Array.isArray(v)));
15
17
  },
16
18
  });
17
19
  }
18
- exports.cloneObject = cloneObject;
19
20
  function omitUndefined(obj, recursive) {
20
21
  if (!(obj && typeof obj === 'object'))
21
22
  return obj;
@@ -27,7 +28,6 @@ function omitUndefined(obj, recursive) {
27
28
  }
28
29
  return obj;
29
30
  }
30
- exports.omitUndefined = omitUndefined;
31
31
  function omitNullish(obj, recursive) {
32
32
  if (!(obj && typeof obj === 'object'))
33
33
  return obj;
@@ -39,4 +39,3 @@ function omitNullish(obj, recursive) {
39
39
  }
40
40
  return obj;
41
41
  }
42
- exports.omitNullish = omitNullish;
@@ -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,7 +26,6 @@ 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
31
  input = input.replace(NO_DOT_BRACKET_PATTERN, s => s.charAt(0) + '.' + s.substring(1));
@@ -62,4 +63,3 @@ function parse(input, target) {
62
63
  }
63
64
  }
64
65
  }
65
- exports.parse = parse;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.safeJsonStringify = safeJsonStringify;
4
+ function safeJsonStringify(value, replacer, space) {
5
+ const seen = new WeakSet();
6
+ return JSON.stringify(value, (k, v) => {
7
+ if (v !== null && typeof v === 'object') {
8
+ if (seen.has(v))
9
+ return;
10
+ seen.add(v);
11
+ }
12
+ if (replacer)
13
+ return replacer(k, v);
14
+ return v;
15
+ }, space);
16
+ }