@opra/client 0.7.0 → 0.8.0

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 (229) hide show
  1. package/README.md +1 -1
  2. package/cjs/714.min.cjs +1 -0
  3. package/cjs/antlr4ts.min.cjs +2 -0
  4. package/cjs/antlr4ts.min.cjs.LICENSE.txt +4 -0
  5. package/cjs/main.min.cjs +1 -0
  6. package/cjs/opra-common.min.cjs +1 -0
  7. package/cjs/vendors.min.cjs +2 -0
  8. package/cjs/vendors.min.cjs.LICENSE.txt +52 -0
  9. package/esm/714.min.mjs +1 -0
  10. package/esm/antlr4ts.min.mjs +2 -0
  11. package/esm/antlr4ts.min.mjs.LICENSE.txt +4 -0
  12. package/esm/main.min.mjs +1 -0
  13. package/esm/opra-common.min.mjs +1 -0
  14. package/esm/vendors.min.mjs +2 -0
  15. package/esm/vendors.min.mjs.LICENSE.txt +52 -0
  16. package/package.json +22 -50
  17. package/{esm → typings}/client-error.d.ts +1 -1
  18. package/typings/common/constants.d.ts +0 -0
  19. package/typings/common/exception/enums/issue-severity.enum.d.ts +13 -0
  20. package/typings/common/exception/error-issue.d.ts +9 -0
  21. package/typings/common/exception/http-errors/bad-request.error.d.ts +10 -0
  22. package/typings/common/exception/http-errors/failed-dependency.error.d.ts +9 -0
  23. package/typings/common/exception/http-errors/forbidden.error.d.ts +11 -0
  24. package/typings/common/exception/http-errors/internal-server.error.d.ts +9 -0
  25. package/typings/common/exception/http-errors/method-not-allowed.error.d.ts +10 -0
  26. package/typings/common/exception/http-errors/not-acceptable.error.d.ts +10 -0
  27. package/typings/common/exception/http-errors/not-found.error.d.ts +13 -0
  28. package/typings/common/exception/http-errors/unauthorized.error.d.ts +10 -0
  29. package/typings/common/exception/http-errors/unprocessable-entity.error.d.ts +9 -0
  30. package/typings/common/exception/index.d.ts +15 -0
  31. package/typings/common/exception/opra-exception.d.ts +15 -0
  32. package/typings/common/exception/resource-errors/resource-conflict.error.d.ts +5 -0
  33. package/typings/common/exception/resource-errors/resource-not-found.error.d.ts +4 -0
  34. package/typings/common/exception/wrap-exception.d.ts +2 -0
  35. package/typings/common/filter/antlr/OpraFilterLexer.d.ts +78 -0
  36. package/typings/common/filter/antlr/OpraFilterParser.d.ts +365 -0
  37. package/typings/common/filter/antlr/OpraFilterVisitor.d.ts +290 -0
  38. package/typings/common/filter/ast/abstract/ast.d.ts +5 -0
  39. package/typings/common/filter/ast/abstract/expression.d.ts +3 -0
  40. package/typings/common/filter/ast/abstract/literal.d.ts +6 -0
  41. package/typings/common/filter/ast/abstract/term.d.ts +3 -0
  42. package/typings/common/filter/ast/expressions/arithmetic-expression.d.ts +13 -0
  43. package/typings/common/filter/ast/expressions/array-expression.d.ts +7 -0
  44. package/typings/common/filter/ast/expressions/comparison-expression.d.ts +10 -0
  45. package/typings/common/filter/ast/expressions/logical-expression.d.ts +8 -0
  46. package/typings/common/filter/ast/expressions/parentheses-expression.d.ts +6 -0
  47. package/typings/common/filter/ast/index.d.ts +16 -0
  48. package/typings/common/filter/ast/terms/boolean-literal.d.ts +5 -0
  49. package/typings/common/filter/ast/terms/date-literal.d.ts +6 -0
  50. package/typings/common/filter/ast/terms/external-constant.d.ts +5 -0
  51. package/typings/common/filter/ast/terms/null-literal.d.ts +5 -0
  52. package/typings/common/filter/ast/terms/number-literal.d.ts +6 -0
  53. package/typings/common/filter/ast/terms/qualified-identifier.d.ts +4 -0
  54. package/typings/common/filter/ast/terms/string-literal.d.ts +5 -0
  55. package/typings/common/filter/ast/terms/time-literal.d.ts +6 -0
  56. package/typings/common/filter/build.d.ts +31 -0
  57. package/typings/common/filter/error-listener.d.ts +8 -0
  58. package/typings/common/filter/errors.d.ts +20 -0
  59. package/typings/common/filter/filter-tree-visitor.d.ts +30 -0
  60. package/typings/common/filter/index.d.ts +5 -0
  61. package/typings/common/filter/parse.d.ts +2 -0
  62. package/typings/common/filter/utils.d.ts +2 -0
  63. package/typings/common/helpers/index.d.ts +1 -0
  64. package/typings/common/helpers/responsive-map.d.ts +18 -0
  65. package/typings/common/http/enums/http-headers.enum.d.ts +379 -0
  66. package/typings/common/http/enums/http-status.enum.d.ts +290 -0
  67. package/typings/common/http/http-request.d.ts +34 -0
  68. package/typings/common/http/index.d.ts +6 -0
  69. package/typings/common/http/interfaces/client-http-headers.interface.d.ts +65 -0
  70. package/typings/common/http/interfaces/server-http-headers.interface.d.ts +1 -0
  71. package/typings/common/http/multipart/batch-multipart.d.ts +31 -0
  72. package/typings/common/http/multipart/http-request-content.d.ts +8 -0
  73. package/typings/common/http/multipart/http-response-content.d.ts +7 -0
  74. package/typings/common/http/multipart/index.d.ts +1 -0
  75. package/typings/common/http/utils/normalize-headers.d.ts +1 -0
  76. package/typings/common/i18n/i18n.d.ts +28 -0
  77. package/typings/common/i18n/index.d.ts +5 -0
  78. package/typings/common/i18n/string-utils.d.ts +2 -0
  79. package/typings/common/i18n/translate.d.ts +4 -0
  80. package/typings/common/index.d.ts +10 -0
  81. package/typings/common/schema/constants.d.ts +8 -0
  82. package/typings/common/schema/decorators/opr-collection-resource.decorator.d.ts +8 -0
  83. package/typings/common/schema/decorators/opr-complex-type.decorator.d.ts +6 -0
  84. package/typings/common/schema/decorators/opr-field.decorator.d.ts +3 -0
  85. package/typings/common/schema/decorators/opr-resolver.decorator.d.ts +8 -0
  86. package/typings/common/schema/decorators/opr-simple-type.decorator.d.ts +6 -0
  87. package/typings/common/schema/decorators/opr-singleton-resource.decorator.d.ts +8 -0
  88. package/typings/common/schema/implementation/data-type/builtin/any.type.d.ts +2 -0
  89. package/typings/common/schema/implementation/data-type/builtin/base64-binary.type.d.ts +2 -0
  90. package/typings/common/schema/implementation/data-type/builtin/bigint.type.d.ts +2 -0
  91. package/typings/common/schema/implementation/data-type/builtin/boolean.type.d.ts +2 -0
  92. package/typings/common/schema/implementation/data-type/builtin/date-string.type.d.ts +2 -0
  93. package/typings/common/schema/implementation/data-type/builtin/date.type.d.ts +2 -0
  94. package/typings/common/schema/implementation/data-type/builtin/guid.type.d.ts +2 -0
  95. package/typings/common/schema/implementation/data-type/builtin/integer.type.d.ts +2 -0
  96. package/typings/common/schema/implementation/data-type/builtin/number.type.d.ts +2 -0
  97. package/typings/common/schema/implementation/data-type/builtin/object.type.d.ts +2 -0
  98. package/typings/common/schema/implementation/data-type/builtin/string.type.d.ts +2 -0
  99. package/typings/common/schema/implementation/data-type/builtin-data-types.d.ts +4 -0
  100. package/typings/common/schema/implementation/data-type/complex-type.d.ts +29 -0
  101. package/typings/common/schema/implementation/data-type/data-type.d.ts +16 -0
  102. package/typings/common/schema/implementation/data-type/simple-type.d.ts +12 -0
  103. package/typings/common/schema/implementation/data-type/union-type.d.ts +16 -0
  104. package/typings/common/schema/implementation/document-builder.d.ts +16 -0
  105. package/typings/common/schema/implementation/opra-document.d.ts +44 -0
  106. package/typings/common/schema/implementation/query/collection-count-query.d.ts +14 -0
  107. package/typings/common/schema/implementation/query/collection-create-query.d.ts +18 -0
  108. package/typings/common/schema/implementation/query/collection-delete-many-query.d.ts +14 -0
  109. package/typings/common/schema/implementation/query/collection-delete-query.d.ts +10 -0
  110. package/typings/common/schema/implementation/query/collection-get-query.d.ts +21 -0
  111. package/typings/common/schema/implementation/query/collection-search-query.d.ts +30 -0
  112. package/typings/common/schema/implementation/query/collection-update-many-query.d.ts +15 -0
  113. package/typings/common/schema/implementation/query/collection-update-query.d.ts +19 -0
  114. package/typings/common/schema/implementation/query/field-get-query.d.ts +30 -0
  115. package/typings/common/schema/implementation/query/index.d.ts +27 -0
  116. package/typings/common/schema/implementation/query/singleton-get-query.d.ts +20 -0
  117. package/typings/common/schema/implementation/resource/collection-resource-info.d.ts +19 -0
  118. package/typings/common/schema/implementation/resource/container-resource-info.d.ts +13 -0
  119. package/typings/common/schema/implementation/resource/resource-info.d.ts +17 -0
  120. package/typings/common/schema/implementation/resource/singleton-resource-info.d.ts +14 -0
  121. package/typings/common/schema/implementation/schema-builder/extract-resource-metadata.util.d.ts +3 -0
  122. package/typings/common/schema/implementation/schema-builder/extract-type-metadata.util.d.ts +4 -0
  123. package/typings/common/schema/index.d.ts +25 -0
  124. package/typings/common/schema/interfaces/child-field-query.interface.d.ts +4 -0
  125. package/typings/common/schema/interfaces/data-type.metadata.d.ts +18 -0
  126. package/typings/common/schema/interfaces/resource-container.interface.d.ts +8 -0
  127. package/typings/common/schema/interfaces/resource.metadata.d.ts +18 -0
  128. package/typings/common/schema/opra-schema.definition.d.ts +178 -0
  129. package/typings/common/schema/type-helpers/extend-type.helper.d.ts +3 -0
  130. package/typings/common/schema/type-helpers/mixin-type.helper.d.ts +2 -0
  131. package/typings/common/schema/type-helpers/mixin.utils.d.ts +3 -0
  132. package/typings/common/schema/types.d.ts +14 -0
  133. package/typings/common/schema/utils/class.utils.d.ts +2 -0
  134. package/typings/common/schema/utils/clone-object.util.d.ts +1 -0
  135. package/typings/common/schema/utils/inspect.util.d.ts +4 -0
  136. package/typings/common/schema/utils/normalize-field-array.util.d.ts +3 -0
  137. package/typings/common/schema/utils/path-to-tree.util.d.ts +4 -0
  138. package/typings/common/schema/utils/string-compare.util.d.ts +1 -0
  139. package/typings/common/url/formats/boolean-format.d.ts +5 -0
  140. package/typings/common/url/formats/date-format.d.ts +16 -0
  141. package/typings/common/url/formats/filter-format.d.ts +6 -0
  142. package/typings/common/url/formats/format.d.ts +4 -0
  143. package/typings/common/url/formats/integer-format.d.ts +9 -0
  144. package/typings/common/url/formats/number-format.d.ts +12 -0
  145. package/typings/common/url/formats/string-format.d.ts +14 -0
  146. package/typings/common/url/index.d.ts +5 -0
  147. package/typings/common/url/opra-url-path-component.d.ts +15 -0
  148. package/typings/common/url/opra-url-path.d.ts +30 -0
  149. package/typings/common/url/opra-url-search-params.d.ts +44 -0
  150. package/typings/common/url/opra-url.d.ts +79 -0
  151. package/typings/common/url/utils/path-utils.d.ts +8 -0
  152. package/typings/common/utils/index.d.ts +3 -0
  153. package/typings/common/utils/is-url.d.ts +1 -0
  154. package/typings/common/utils/path-to-tree.d.ts +4 -0
  155. package/typings/common/utils/type-guards.d.ts +9 -0
  156. package/{esm → typings}/constants.d.ts +0 -0
  157. package/{esm → typings}/http/http-client.d.ts +1 -1
  158. package/{esm → typings}/http/http-collection-service.d.ts +1 -1
  159. package/{esm → typings}/http/http-request.d.ts +1 -1
  160. package/{esm → typings}/http/http-response.d.ts +0 -0
  161. package/{esm → typings}/http/http-singleton-service.d.ts +1 -1
  162. package/{esm → typings}/http/http-types.d.ts +1 -1
  163. package/{esm → typings}/http/requests/batch-request.d.ts +1 -1
  164. package/{esm → typings}/http/requests/collection-create-request.d.ts +1 -1
  165. package/{esm → typings}/http/requests/collection-delete-many-request.d.ts +1 -1
  166. package/{esm → typings}/http/requests/collection-delete-request.d.ts +1 -1
  167. package/{esm → typings}/http/requests/collection-get-request.d.ts +1 -1
  168. package/{esm → typings}/http/requests/collection-search-request.d.ts +1 -1
  169. package/{esm → typings}/http/requests/collection-update-many-request.d.ts +1 -1
  170. package/{esm → typings}/http/requests/collection-update-request.d.ts +1 -1
  171. package/{esm → typings}/http/requests/http-singleton-get-request.d.ts +1 -1
  172. package/{esm → typings}/http/utils/merge-raw-http-requests.util.d.ts +0 -0
  173. package/{esm → typings}/index.d.ts +0 -1
  174. package/{esm → typings}/interfaces/http-options.interface.d.ts +1 -4
  175. package/{esm → typings}/interfaces/http-request-config.interface.d.ts +1 -1
  176. package/umd/714.min.cjs +1 -0
  177. package/umd/antlr4ts.min.cjs +2 -0
  178. package/umd/antlr4ts.min.cjs.LICENSE.txt +4 -0
  179. package/umd/main.min.cjs +1 -0
  180. package/umd/opra-common.min.cjs +1 -0
  181. package/umd/vendors.min.cjs +2 -0
  182. package/umd/vendors.min.cjs.LICENSE.txt +52 -0
  183. package/cjs/client-error.js +0 -20
  184. package/cjs/constants.js +0 -6
  185. package/cjs/http/http-client.js +0 -164
  186. package/cjs/http/http-collection-service.js +0 -40
  187. package/cjs/http/http-request.js +0 -66
  188. package/cjs/http/http-response.js +0 -2
  189. package/cjs/http/http-singleton-service.js +0 -16
  190. package/cjs/http/http-types.js +0 -2
  191. package/cjs/http/requests/batch-request.js +0 -80
  192. package/cjs/http/requests/collection-create-request.js +0 -35
  193. package/cjs/http/requests/collection-delete-many-request.js +0 -28
  194. package/cjs/http/requests/collection-delete-request.js +0 -29
  195. package/cjs/http/requests/collection-get-request.js +0 -37
  196. package/cjs/http/requests/collection-search-request.js +0 -44
  197. package/cjs/http/requests/collection-update-many-request.js +0 -31
  198. package/cjs/http/requests/collection-update-request.js +0 -40
  199. package/cjs/http/requests/http-singleton-get-request.js +0 -31
  200. package/cjs/http/utils/merge-raw-http-requests.util.js +0 -29
  201. package/cjs/index.js +0 -20
  202. package/cjs/interfaces/http-options.interface.js +0 -2
  203. package/cjs/interfaces/http-request-config.interface.js +0 -2
  204. package/cjs/package.json +0 -3
  205. package/cjs/types.js +0 -2
  206. package/esm/client-error.js +0 -16
  207. package/esm/constants.js +0 -3
  208. package/esm/http/http-client.js +0 -160
  209. package/esm/http/http-collection-service.js +0 -36
  210. package/esm/http/http-request.js +0 -62
  211. package/esm/http/http-response.js +0 -1
  212. package/esm/http/http-singleton-service.js +0 -12
  213. package/esm/http/http-types.js +0 -1
  214. package/esm/http/requests/batch-request.js +0 -76
  215. package/esm/http/requests/collection-create-request.js +0 -31
  216. package/esm/http/requests/collection-delete-many-request.js +0 -24
  217. package/esm/http/requests/collection-delete-request.js +0 -25
  218. package/esm/http/requests/collection-get-request.js +0 -33
  219. package/esm/http/requests/collection-search-request.js +0 -40
  220. package/esm/http/requests/collection-update-many-request.js +0 -27
  221. package/esm/http/requests/collection-update-request.js +0 -36
  222. package/esm/http/requests/http-singleton-get-request.js +0 -27
  223. package/esm/http/utils/merge-raw-http-requests.util.js +0 -25
  224. package/esm/index.js +0 -17
  225. package/esm/interfaces/http-options.interface.js +0 -1
  226. package/esm/interfaces/http-request-config.interface.js +0 -1
  227. package/esm/types.d.ts +0 -7
  228. package/esm/types.js +0 -1
  229. package/umd/opra-client.umd.min.js +0 -1
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergeRawHttpRequests = void 0;
4
- const common_1 = require("@opra/common");
5
- function mergeRawHttpRequests(target, ...other) {
6
- let params;
7
- const arr = [target, ...other];
8
- let headers;
9
- for (let i = arr.length - 1; i >= 0; i--) {
10
- const o = arr[i];
11
- if (o?.headers) {
12
- headers = headers || {};
13
- Object.assign(headers, (0, common_1.normalizeHeaders)(o.headers));
14
- }
15
- }
16
- for (const o of arr) {
17
- if (!o)
18
- continue;
19
- Object.assign(target, o);
20
- if (o?.params) {
21
- params = params || new common_1.OpraURLSearchParams();
22
- o.params.forEach((v, n) => params?.append(n, v));
23
- }
24
- }
25
- target.headers = headers;
26
- target.params = params;
27
- return target;
28
- }
29
- exports.mergeRawHttpRequests = mergeRawHttpRequests;
package/cjs/index.js DELETED
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./http/http-client.js"), exports);
5
- tslib_1.__exportStar(require("./http/http-request.js"), exports);
6
- tslib_1.__exportStar(require("./http/http-response.js"), exports);
7
- tslib_1.__exportStar(require("./http/http-collection-service.js"), exports);
8
- tslib_1.__exportStar(require("./http/http-singleton-service.js"), exports);
9
- tslib_1.__exportStar(require("./http/http-types.js"), exports);
10
- tslib_1.__exportStar(require("./types.js"), exports);
11
- tslib_1.__exportStar(require("./client-error.js"), exports);
12
- tslib_1.__exportStar(require("./http/requests/batch-request.js"), exports);
13
- tslib_1.__exportStar(require("./http/requests/collection-create-request.js"), exports);
14
- tslib_1.__exportStar(require("./http/requests/collection-delete-request.js"), exports);
15
- tslib_1.__exportStar(require("./http/requests/collection-delete-many-request.js"), exports);
16
- tslib_1.__exportStar(require("./http/requests/collection-get-request.js"), exports);
17
- tslib_1.__exportStar(require("./http/requests/collection-search-request.js"), exports);
18
- tslib_1.__exportStar(require("./http/requests/collection-update-request.js"), exports);
19
- tslib_1.__exportStar(require("./http/requests/collection-update-many-request.js"), exports);
20
- tslib_1.__exportStar(require("./http/requests/http-singleton-get-request.js"), exports);
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/package.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
package/cjs/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,16 +0,0 @@
1
- export class ClientError extends Error {
2
- cause;
3
- issues;
4
- status;
5
- constructor(init, cause) {
6
- super(init.message);
7
- this.cause = cause;
8
- this.issues = init.issues || [];
9
- this.status = init.status;
10
- if (cause) {
11
- this.cause = cause;
12
- if (cause.stack)
13
- this.stack = cause.stack;
14
- }
15
- }
16
- }
package/esm/constants.js DELETED
@@ -1,3 +0,0 @@
1
- export const JSON_CONTENT_TYPE_PATTERN = /^application\/([\w-]+\+)?\bjson\b/i;
2
- export const TEXT_CONTENT_TYPE_PATTERN = /^text\/.*$/i;
3
- export const FORMDATA_CONTENT_TYPE_PATTERN = /^multipart\/\bform-data\b/i;
@@ -1,160 +0,0 @@
1
- import { isReadable, isReadableStream, joinPath, OpraDocument } from '@opra/common';
2
- import { ClientError } from '../client-error.js';
3
- import { FORMDATA_CONTENT_TYPE_PATTERN, JSON_CONTENT_TYPE_PATTERN, TEXT_CONTENT_TYPE_PATTERN } from '../constants.js';
4
- import { HttpCollectionService } from './http-collection-service.js';
5
- import { HttpSingletonService } from './http-singleton-service.js';
6
- import { BatchRequest } from './requests/batch-request.js';
7
- import { mergeRawHttpRequests } from './utils/merge-raw-http-requests.util.js';
8
- const documentCache = new Map();
9
- const documentResolverCaches = new Map();
10
- export class OpraHttpClient {
11
- _serviceUrl;
12
- _metadata;
13
- defaults;
14
- constructor(serviceUrl, options) {
15
- this._serviceUrl = serviceUrl;
16
- this._metadata = options?.document;
17
- if (!this._metadata) {
18
- const document = documentCache.get(this.serviceUrl.toLowerCase());
19
- if (document)
20
- this._metadata = document;
21
- }
22
- this.defaults = options?.defaults || {};
23
- }
24
- get serviceUrl() {
25
- return this._serviceUrl;
26
- }
27
- get initialized() {
28
- return !!this._metadata;
29
- }
30
- get metadata() {
31
- this._assertMetadata();
32
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
33
- return this._metadata;
34
- }
35
- async init(forceRefresh) {
36
- if (!forceRefresh && this.initialized)
37
- return;
38
- const cacheName = this.serviceUrl.toLowerCase();
39
- let promise = documentResolverCaches.get(cacheName);
40
- if (promise) {
41
- await promise;
42
- return;
43
- }
44
- promise = this._resolveMetadata();
45
- documentResolverCaches.set(cacheName, promise);
46
- return promise
47
- .catch(() => void 0)
48
- .finally(() => documentResolverCaches.delete(cacheName));
49
- }
50
- batch(requests) {
51
- this._assertMetadata();
52
- return new BatchRequest(req => this._handleRequest(req), requests);
53
- }
54
- collection(name) {
55
- this._assertMetadata();
56
- // If name argument is a class, we extract name from the class
57
- if (typeof name === 'function')
58
- name = name.name;
59
- const resource = this.metadata.getCollectionResource(name);
60
- return new HttpCollectionService(resource, req => this._handleRequest(req));
61
- }
62
- singleton(name) {
63
- this._assertMetadata();
64
- // If name argument is a class, we extract name from the class
65
- if (typeof name === 'function')
66
- name = name.name;
67
- const resource = this.metadata.getSingletonResource(name);
68
- return new HttpSingletonService(resource, req => this._handleRequest(req));
69
- }
70
- async _resolveMetadata() {
71
- const resp = await this._handleRequest({
72
- method: 'GET',
73
- path: '/$metadata',
74
- headers: { 'accept': 'application/json' }
75
- });
76
- this._metadata = new OpraDocument(resp.data);
77
- }
78
- async _handleRequest(req) {
79
- mergeRawHttpRequests(req, this.defaults);
80
- let url = joinPath(this.serviceUrl, req.path);
81
- if (req.params)
82
- url += '?' + req.params.toString();
83
- if (req.body) {
84
- if (typeof req.body === 'object') {
85
- if (!(isReadable(req.body) || isReadableStream(req.body) || Buffer.isBuffer(req.body))) {
86
- if (!req.headers?.['content-type']) {
87
- req.headers = req.headers || {};
88
- req.headers['content-type'] = 'application/json';
89
- }
90
- req.body = JSON.stringify(req.body);
91
- }
92
- }
93
- }
94
- return this._fetch(url, req);
95
- }
96
- async _fetch(url, req) {
97
- const resp = await fetch(url, req);
98
- let data;
99
- if (resp.body) {
100
- if (JSON_CONTENT_TYPE_PATTERN.test(resp.headers.get('Content-Type') || '')) {
101
- data = await resp.json();
102
- if (typeof data === 'string')
103
- data = JSON.parse(data);
104
- }
105
- else if (TEXT_CONTENT_TYPE_PATTERN.test(resp.headers.get('Content-Type') || ''))
106
- data = await resp.text();
107
- else if (FORMDATA_CONTENT_TYPE_PATTERN.test(resp.headers.get('Content-Type') || ''))
108
- data = await resp.formData();
109
- else
110
- data = await resp.arrayBuffer();
111
- }
112
- if (resp.status >= 400 && resp.status < 600) {
113
- throw new ClientError({
114
- message: resp.status + ' ' + resp.statusText,
115
- status: resp.status,
116
- issues: data?.errors
117
- });
118
- }
119
- const out = {
120
- get headers() {
121
- return resp.headers;
122
- },
123
- get ok() {
124
- return resp.ok;
125
- },
126
- get redirected() {
127
- return resp.redirected;
128
- },
129
- get status() {
130
- return resp.status;
131
- },
132
- get statusText() {
133
- return resp.statusText;
134
- },
135
- get type() {
136
- return resp.type;
137
- },
138
- get url() {
139
- return resp.url;
140
- },
141
- get contentId() {
142
- return resp.headers.get('Content-ID');
143
- },
144
- get data() {
145
- return data;
146
- }
147
- };
148
- return out;
149
- }
150
- _assertMetadata() {
151
- if (!this._metadata)
152
- throw new Error('You must call init() to before using the client instance');
153
- }
154
- static async create(serviceUrl, options) {
155
- const client = new this(serviceUrl, options);
156
- if (!client._metadata)
157
- await client.init();
158
- return client;
159
- }
160
- }
@@ -1,36 +0,0 @@
1
- import { CollectionCreateRequest } from './requests/collection-create-request.js';
2
- import { CollectionDeleteManyRequest } from './requests/collection-delete-many-request.js';
3
- import { CollectionDeleteRequest } from './requests/collection-delete-request.js';
4
- import { CollectionGetRequest } from './requests/collection-get-request.js';
5
- import { CollectionSearchRequest } from './requests/collection-search-request.js';
6
- import { CollectionUpdateManyRequest } from './requests/collection-update-many-request.js';
7
- import { CollectionUpdateRequest } from './requests/collection-update-request.js';
8
- export class HttpCollectionService {
9
- resource;
10
- _handler;
11
- constructor(resource, _handler) {
12
- this.resource = resource;
13
- this._handler = _handler;
14
- }
15
- create(data, options) {
16
- return new CollectionCreateRequest(this._handler, this.resource, data, options);
17
- }
18
- delete(keyValue, options) {
19
- return new CollectionDeleteRequest(this._handler, this.resource, keyValue, options);
20
- }
21
- deleteMany(options) {
22
- return new CollectionDeleteManyRequest(this._handler, this.resource, options);
23
- }
24
- get(keyValue, options) {
25
- return new CollectionGetRequest(this._handler, this.resource, keyValue, options);
26
- }
27
- search(options) {
28
- return new CollectionSearchRequest(this._handler, this.resource, options);
29
- }
30
- update(keyValue, data, options) {
31
- return new CollectionUpdateRequest(this._handler, this.resource, keyValue, data, options);
32
- }
33
- updateMany(data, options) {
34
- return new CollectionUpdateManyRequest(this._handler, this.resource, data, options);
35
- }
36
- }
@@ -1,62 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- import { uid } from '@opra/common';
3
- export class HttpRequest extends Observable {
4
- _handler;
5
- options;
6
- contentId;
7
- _promise;
8
- _headers;
9
- constructor(_handler, options = {}) {
10
- super((subscriber) => {
11
- if (options.observe === 'response') {
12
- this.fetch().then(v => {
13
- subscriber.next(v);
14
- subscriber.complete();
15
- }).catch(e => subscriber.error(e));
16
- return;
17
- }
18
- this.resolve().then(v => {
19
- subscriber.next(v);
20
- subscriber.complete();
21
- }).catch(e => subscriber.error(e));
22
- });
23
- this._handler = _handler;
24
- this.options = options;
25
- this.contentId = uid(6);
26
- this.options = options;
27
- }
28
- header(name, value) {
29
- this._headers = this._headers || {};
30
- this._headers[name] = value;
31
- return this;
32
- }
33
- /**
34
- * Sends the request
35
- */
36
- async fetch() {
37
- const promise = this._promise || (this._promise = new Promise((resolve, reject) => {
38
- setTimeout(() => {
39
- this._execute().then(resolve).catch(reject);
40
- }, 0);
41
- }));
42
- return await promise;
43
- }
44
- /**
45
- * Sends the request and returns response data
46
- */
47
- async resolve() {
48
- const resp = await this.fetch();
49
- return resp.data;
50
- }
51
- with(cb) {
52
- cb(this);
53
- return this;
54
- }
55
- binding() {
56
- return {};
57
- }
58
- async _execute() {
59
- const req = this.prepare();
60
- return await this._handler(req);
61
- }
62
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,12 +0,0 @@
1
- import { HttpSingletonGetRequest } from './requests/http-singleton-get-request.js';
2
- export class HttpSingletonService {
3
- resource;
4
- _handler;
5
- constructor(resource, _handler) {
6
- this.resource = resource;
7
- this._handler = _handler;
8
- }
9
- get(options) {
10
- return new HttpSingletonGetRequest(this._handler, this.resource, options);
11
- }
12
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,76 +0,0 @@
1
- import { BatchMultipart } from '@opra/common';
2
- import { HttpRequest } from '../http-request.js';
3
- import { mergeRawHttpRequests } from '../utils/merge-raw-http-requests.util.js';
4
- export class BatchRequest extends HttpRequest {
5
- _handler;
6
- requests;
7
- options;
8
- _results = new WeakMap();
9
- _listeners = new Set();
10
- constructor(_handler, requests, options = {}) {
11
- super(_handler, options);
12
- this._handler = _handler;
13
- this.requests = requests;
14
- this.options = options;
15
- requests.forEach(request => {
16
- // Overwrite the _execute method
17
- Object.defineProperty(request, '_execute', {
18
- writable: true,
19
- enumerable: false,
20
- configurable: true,
21
- value: () => {
22
- return new Promise((resolve, reject) => {
23
- const x = this._results.get(request);
24
- if (x) {
25
- if (x.error)
26
- return reject(x.error);
27
- return resolve(x.response);
28
- }
29
- const callback = (error, response) => {
30
- this._listeners.delete(callback);
31
- if (error)
32
- return reject(error);
33
- resolve(response);
34
- };
35
- this._listeners.add(callback);
36
- });
37
- }
38
- });
39
- });
40
- }
41
- prepare() {
42
- const batch = this._buildBatchMultipart(this);
43
- const headers = {
44
- 'content-type': 'multipart/mixed;boundary=' + batch.boundary
45
- };
46
- return mergeRawHttpRequests({
47
- method: 'POST',
48
- path: '/$batch',
49
- headers,
50
- body: batch.stream()
51
- }, this.options.http);
52
- }
53
- _buildBatchMultipart(batch) {
54
- const multipart = new BatchMultipart();
55
- for (const req of batch.requests) {
56
- const prepared = req.prepare();
57
- if (req instanceof BatchRequest) {
58
- const subMultipart = this._buildBatchMultipart(req);
59
- multipart.addBatch(subMultipart);
60
- continue;
61
- }
62
- multipart.addRequestPart({
63
- method: prepared.method,
64
- url: prepared.path,
65
- headers: prepared.headers,
66
- data: prepared.body
67
- });
68
- }
69
- return multipart;
70
- }
71
- async _execute() {
72
- const req = this.prepare();
73
- const resp = await this._handler(req);
74
- return resp;
75
- }
76
- }
@@ -1,31 +0,0 @@
1
- import { OpraURLSearchParams } from '@opra/common';
2
- import { HttpRequest } from '../http-request.js';
3
- import { mergeRawHttpRequests } from '../utils/merge-raw-http-requests.util.js';
4
- export class CollectionCreateRequest extends HttpRequest {
5
- _handler;
6
- resource;
7
- data;
8
- options;
9
- constructor(_handler, resource, data, options = {}) {
10
- super(_handler, options);
11
- this._handler = _handler;
12
- this.resource = resource;
13
- this.data = data;
14
- this.options = options;
15
- }
16
- prepare() {
17
- const searchParams = new OpraURLSearchParams();
18
- if (this.options.include)
19
- searchParams.set('$include', this.options.include);
20
- if (this.options.pick)
21
- searchParams.set('$pick', this.options.pick);
22
- if (this.options.omit)
23
- searchParams.set('$omit', this.options.omit);
24
- return mergeRawHttpRequests({
25
- method: 'POST',
26
- path: this.resource.name,
27
- params: searchParams,
28
- body: this.data,
29
- }, this.options.http);
30
- }
31
- }
@@ -1,24 +0,0 @@
1
- import { OpraURLSearchParams, } from '@opra/common';
2
- import { HttpRequest } from '../http-request.js';
3
- import { mergeRawHttpRequests } from '../utils/merge-raw-http-requests.util.js';
4
- export class CollectionDeleteManyRequest extends HttpRequest {
5
- _handler;
6
- resource;
7
- options;
8
- constructor(_handler, resource, options = {}) {
9
- super(_handler, options);
10
- this._handler = _handler;
11
- this.resource = resource;
12
- this.options = options;
13
- }
14
- prepare() {
15
- const searchParams = new OpraURLSearchParams();
16
- if (this.options.filter)
17
- searchParams.set('$filter', this.options.filter);
18
- return mergeRawHttpRequests({
19
- method: 'DELETE',
20
- path: this.resource.name,
21
- params: searchParams,
22
- }, this.options.http);
23
- }
24
- }
@@ -1,25 +0,0 @@
1
- import { OpraURLPath } from '@opra/common';
2
- import { HttpRequest } from '../http-request.js';
3
- import { mergeRawHttpRequests } from '../utils/merge-raw-http-requests.util.js';
4
- export class CollectionDeleteRequest extends HttpRequest {
5
- _handler;
6
- resource;
7
- keyValue;
8
- options;
9
- constructor(_handler, resource, keyValue, options = {}) {
10
- super(_handler, options);
11
- this._handler = _handler;
12
- this.resource = resource;
13
- this.keyValue = keyValue;
14
- this.options = options;
15
- }
16
- prepare() {
17
- if (this.keyValue == null || this.keyValue === '')
18
- throw new TypeError('Key value required to perform "delete" request');
19
- const path = new OpraURLPath({ resource: this.resource.name, key: this.keyValue });
20
- return mergeRawHttpRequests({
21
- method: 'DELETE',
22
- path: path.toString(),
23
- }, this.options.http);
24
- }
25
- }
@@ -1,33 +0,0 @@
1
- import { OpraURLPath, OpraURLSearchParams, } from '@opra/common';
2
- import { HttpRequest } from '../http-request.js';
3
- import { mergeRawHttpRequests } from '../utils/merge-raw-http-requests.util.js';
4
- export class CollectionGetRequest extends HttpRequest {
5
- _handler;
6
- resource;
7
- keyValue;
8
- options;
9
- constructor(_handler, resource, keyValue, options = {}) {
10
- super(_handler, options);
11
- this._handler = _handler;
12
- this.resource = resource;
13
- this.keyValue = keyValue;
14
- this.options = options;
15
- }
16
- prepare() {
17
- if (this.keyValue == null || this.keyValue === '')
18
- throw new TypeError('Key value required to perform "get" request');
19
- const path = new OpraURLPath({ resource: this.resource.name, key: this.keyValue });
20
- const searchParams = new OpraURLSearchParams();
21
- if (this.options.include)
22
- searchParams.set('$include', this.options.include);
23
- if (this.options.pick)
24
- searchParams.set('$pick', this.options.pick);
25
- if (this.options.omit)
26
- searchParams.set('$omit', this.options.omit);
27
- return mergeRawHttpRequests({
28
- method: 'GET',
29
- path: path.toString(),
30
- params: searchParams
31
- }, this.options.http);
32
- }
33
- }
@@ -1,40 +0,0 @@
1
- import { OpraURLSearchParams, } from '@opra/common';
2
- import { HttpRequest } from '../http-request.js';
3
- import { mergeRawHttpRequests } from '../utils/merge-raw-http-requests.util.js';
4
- export class CollectionSearchRequest extends HttpRequest {
5
- _handler;
6
- resource;
7
- options;
8
- constructor(_handler, resource, options = {}) {
9
- super(_handler, options);
10
- this._handler = _handler;
11
- this.resource = resource;
12
- this.options = options;
13
- }
14
- prepare() {
15
- const searchParams = new OpraURLSearchParams();
16
- if (this.options.include)
17
- searchParams.set('$include', this.options.include);
18
- if (this.options.pick)
19
- searchParams.set('$pick', this.options.pick);
20
- if (this.options.omit)
21
- searchParams.set('$omit', this.options.omit);
22
- if (this.options.sort)
23
- searchParams.set('$sort', this.options.sort);
24
- if (this.options.filter)
25
- searchParams.set('$filter', this.options.filter);
26
- if (this.options.limit != null)
27
- searchParams.set('$limit', this.options.limit);
28
- if (this.options.skip != null)
29
- searchParams.set('$skip', this.options.skip);
30
- if (this.options.count != null)
31
- searchParams.set('$count', this.options.count);
32
- if (this.options.distinct != null)
33
- searchParams.set('$distinct', this.options.distinct);
34
- return mergeRawHttpRequests({
35
- method: 'GET',
36
- path: this.resource.name,
37
- params: searchParams
38
- }, this.options.http);
39
- }
40
- }
@@ -1,27 +0,0 @@
1
- import { OpraURLSearchParams, } from '@opra/common';
2
- import { HttpRequest } from '../http-request.js';
3
- import { mergeRawHttpRequests } from '../utils/merge-raw-http-requests.util.js';
4
- export class CollectionUpdateManyRequest extends HttpRequest {
5
- _handler;
6
- resource;
7
- data;
8
- options;
9
- constructor(_handler, resource, data, options = {}) {
10
- super(_handler, options);
11
- this._handler = _handler;
12
- this.resource = resource;
13
- this.data = data;
14
- this.options = options;
15
- }
16
- prepare() {
17
- const searchParams = new OpraURLSearchParams();
18
- if (this.options.filter)
19
- searchParams.set('$filter', this.options.filter);
20
- return mergeRawHttpRequests({
21
- method: 'PATCH',
22
- path: this.resource.name,
23
- params: searchParams,
24
- body: this.data
25
- }, this.options.http);
26
- }
27
- }
@@ -1,36 +0,0 @@
1
- import { OpraURLPath, OpraURLSearchParams, } from '@opra/common';
2
- import { HttpRequest } from '../http-request.js';
3
- import { mergeRawHttpRequests } from '../utils/merge-raw-http-requests.util.js';
4
- export class CollectionUpdateRequest extends HttpRequest {
5
- _handler;
6
- resource;
7
- keyValue;
8
- data;
9
- options;
10
- constructor(_handler, resource, keyValue, data, options = {}) {
11
- super(_handler, options);
12
- this._handler = _handler;
13
- this.resource = resource;
14
- this.keyValue = keyValue;
15
- this.data = data;
16
- this.options = options;
17
- }
18
- prepare() {
19
- if (this.keyValue == null || this.keyValue === '')
20
- throw new TypeError('Key value required to perform "get" request');
21
- const path = new OpraURLPath({ resource: this.resource.name, key: this.keyValue });
22
- const searchParams = new OpraURLSearchParams();
23
- if (this.options.include)
24
- searchParams.set('$include', this.options.include);
25
- if (this.options.pick)
26
- searchParams.set('$pick', this.options.pick);
27
- if (this.options.omit)
28
- searchParams.set('$omit', this.options.omit);
29
- return mergeRawHttpRequests({
30
- method: 'PATCH',
31
- path: path.toString(),
32
- params: searchParams,
33
- body: this.data
34
- }, this.options.http);
35
- }
36
- }