@odata2ts/http-client-jquery 0.8.1 → 0.9.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,24 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [0.9.0](https://github.com/odata2ts/http-client/compare/@odata2ts/http-client-jquery@0.8.2...@odata2ts/http-client-jquery@0.9.0) (2024-08-13)
7
+
8
+ ### Code Refactoring
9
+
10
+ * switch to vitest & ESM ([#18](https://github.com/odata2ts/http-client/issues/18)) ([748558f](https://github.com/odata2ts/http-client/commit/748558f1e3f699085ade1058b1459c843f60994f))
11
+
12
+ ### Features
13
+
14
+ * blob and stream support ([#12](https://github.com/odata2ts/http-client/issues/12)) ([ae6f062](https://github.com/odata2ts/http-client/commit/ae6f062371a0ad11707fa3f9edff9571998edb5b))
15
+
16
+ ### BREAKING CHANGES
17
+
18
+ * switch to ESM tends to break stuff
19
+
20
+ ## [0.8.2](https://github.com/odata2ts/http-client/compare/@odata2ts/http-client-jquery@0.8.1...@odata2ts/http-client-jquery@0.8.2) (2023-09-13)
21
+
22
+ **Note:** Version bump only for package @odata2ts/http-client-jquery
23
+
6
24
  ## [0.8.1](https://github.com/odata2ts/http-client/compare/@odata2ts/http-client-jquery@0.8.0...@odata2ts/http-client-jquery@0.8.1) (2023-09-13)
7
25
 
8
26
  **Note:** Version bump only for package @odata2ts/http-client-jquery
package/README.md CHANGED
@@ -1,46 +1,46 @@
1
- [![npm (scoped)](https://img.shields.io/npm/v/@odata2ts/http-client-jquery?style=for-the-badge)](https://www.npmjs.com/package/@odata2ts/http-client-jquery)
2
-
3
- # JQuery HTTP Client
4
-
5
- [odata2ts](https://github.com/odata2ts/odata2ts) compatible odata client based on [JQuery](https://jquery.com/)
6
- and its [ajax method](https://api.jquery.com/Jquery.ajax/).
7
-
8
- JQuery is used by this client but not installed (declared as peer dependency).
9
- The existing JQuery instance must be provided when initializing the client.
10
-
11
- The whole client is meant to support usage of `odata2ts` in UI5 apps, which use Jquery for HTTP communication.
12
-
13
- ## Installation
14
-
15
- Install package `@odata2ts/http-client-jquery` as runtime dependency:
16
-
17
- ```bash
18
- npm install --save @odata2ts/http-client-jquery
19
- ```
20
-
21
- JQuery is a peer-dependency of this package, so it's not contained in or installed through this package.
22
-
23
- ## Documentation
24
-
25
- [JQuery Client Documentation](https://odata2ts.github.io/docs/odata-client/http-client/jquery)
26
-
27
- Main documentation for the odata2ts eco system:
28
- [https://odata2ts.github.io](https://odata2ts.github.io/)
29
-
30
- ## Tests
31
-
32
- See folder [test](https://github.com/odata2ts/http-client/tree/main/packages/jquery/test)
33
- for unit tests.
34
-
35
- ## Support, Feedback, Contributing
36
-
37
- This project is open to feature requests, suggestions, bug reports, usage questions etc.
38
- via [GitHub issues](https://github.com/odata2ts/odata2ts/issues).
39
-
40
- Contributions and feedback are encouraged and always welcome.
41
-
42
- See the [contribution guidelines](https://github.com/odata2ts/odata2ts/blob/main/CONTRIBUTING.md) for further information.
43
-
44
- ## License
45
-
46
- MIT - see [License](./LICENSE).
1
+ [![npm (scoped)](https://img.shields.io/npm/v/@odata2ts/http-client-jquery?style=for-the-badge)](https://www.npmjs.com/package/@odata2ts/http-client-jquery)
2
+
3
+ # JQuery HTTP Client
4
+
5
+ [odata2ts](https://github.com/odata2ts/odata2ts) compatible odata client based on [JQuery](https://jquery.com/)
6
+ and its [ajax method](https://api.jquery.com/Jquery.ajax/).
7
+
8
+ JQuery is used by this client but not installed (declared as peer dependency).
9
+ The existing JQuery instance must be provided when initializing the client.
10
+
11
+ The whole client is meant to support usage of `odata2ts` in UI5 apps, which use Jquery for HTTP communication.
12
+
13
+ ## Installation
14
+
15
+ Install package `@odata2ts/http-client-jquery` as runtime dependency:
16
+
17
+ ```bash
18
+ npm install --save @odata2ts/http-client-jquery
19
+ ```
20
+
21
+ JQuery is a peer-dependency of this package, so it's not contained in or installed through this package.
22
+
23
+ ## Documentation
24
+
25
+ [JQuery Client Documentation](https://odata2ts.github.io/docs/odata-client/http-client/jquery)
26
+
27
+ Main documentation for the odata2ts eco system:
28
+ [https://odata2ts.github.io](https://odata2ts.github.io/)
29
+
30
+ ## Tests
31
+
32
+ See folder [test](https://github.com/odata2ts/http-client/tree/main/packages/jquery/test)
33
+ for unit tests.
34
+
35
+ ## Support, Feedback, Contributing
36
+
37
+ This project is open to feature requests, suggestions, bug reports, usage questions etc.
38
+ via [GitHub issues](https://github.com/odata2ts/odata2ts/issues).
39
+
40
+ Contributions and feedback are encouraged and always welcome.
41
+
42
+ See the [contribution guidelines](https://github.com/odata2ts/odata2ts/blob/main/CONTRIBUTING.md) for further information.
43
+
44
+ ## License
45
+
46
+ MIT - see [License](./LICENSE).
@@ -1,21 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergeAjaxConfig = exports.getDefaultConfig = void 0;
4
- const tslib_1 = require("tslib");
1
+ import { __rest } from "tslib";
5
2
  const DEFAULT_CONFIG = {
6
3
  // we never want caching
7
4
  cache: false,
8
5
  // we always want JSON
9
6
  // dataType: "json",
10
7
  };
11
- function getDefaultConfig(config) {
8
+ export function getDefaultConfig(config) {
12
9
  return mergeAjaxConfig(DEFAULT_CONFIG, config);
13
10
  }
14
- exports.getDefaultConfig = getDefaultConfig;
15
- function mergeAjaxConfig(config, toMerge) {
16
- const _a = config || {}, { headers } = _a, passThrough = tslib_1.__rest(_a, ["headers"]);
17
- const _b = toMerge || {}, { headers: headers2 } = _b, passThrough2 = tslib_1.__rest(_b, ["headers"]);
11
+ export function mergeAjaxConfig(config, toMerge) {
12
+ const _a = config || {}, { headers } = _a, passThrough = __rest(_a, ["headers"]);
13
+ const _b = toMerge || {}, { headers: headers2 } = _b, passThrough2 = __rest(_b, ["headers"]);
18
14
  return Object.assign(Object.assign(Object.assign({}, passThrough), passThrough2), { headers: Object.assign(Object.assign({}, headers), headers2) });
19
15
  }
20
- exports.mergeAjaxConfig = mergeAjaxConfig;
21
16
  //# sourceMappingURL=AjaxRequestConfig.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AjaxRequestConfig.js","sourceRoot":"","sources":["../src/AjaxRequestConfig.ts"],"names":[],"mappings":";;;;AAAA,MAAM,cAAc,GAAwB;IAC1C,wBAAwB;IACxB,KAAK,EAAE,KAAK;IACZ,sBAAsB;IACtB,oBAAoB;CACrB,CAAC;AAeF,SAAgB,gBAAgB,CAAC,MAA0B;IACzD,OAAO,eAAe,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;AACjD,CAAC;AAFD,4CAEC;AAED,SAAgB,eAAe,CAAC,MAA4B,EAAE,OAA6B;IACzF,MAAM,KAA8B,MAAM,IAAI,EAAE,EAA1C,EAAE,OAAO,OAAiC,EAA5B,WAAW,sBAAzB,WAA2B,CAAe,CAAC;IACjD,MAAM,KAAyC,OAAO,IAAI,EAAE,EAAtD,EAAE,OAAO,EAAE,QAAQ,OAAmC,EAA9B,YAAY,sBAApC,WAAsC,CAAgB,CAAC;IAC7D,qDACK,WAAW,GACX,YAAY,KACf,OAAO,kCACF,OAAO,GACP,QAAQ,KAEb;AACJ,CAAC;AAXD,0CAWC","sourcesContent":["const DEFAULT_CONFIG: JQuery.AjaxSettings = {\r\n // we never want caching\r\n cache: false,\r\n // we always want JSON\r\n // dataType: \"json\",\r\n};\r\n\r\n/**\r\n * Available config options for end user when making a given request.\r\n */\r\nexport interface AjaxRequestConfig\r\n extends Pick<JQuery.AjaxSettings, \"complete\" | \"beforeSend\" | \"headers\" | \"statusCode\" | \"timeout\"> {\r\n /**\r\n * Add query params.\r\n */\r\n params?: Record<string, string | number | boolean | Array<string | number | boolean>>;\r\n}\r\n\r\nexport interface InternalRequestConfig extends JQuery.AjaxSettings, Pick<AjaxRequestConfig, \"params\"> {}\r\n\r\nexport function getDefaultConfig(config?: AjaxRequestConfig): InternalRequestConfig {\r\n return mergeAjaxConfig(DEFAULT_CONFIG, config);\r\n}\r\n\r\nexport function mergeAjaxConfig(config?: JQuery.AjaxSettings, toMerge?: JQuery.AjaxSettings): InternalRequestConfig {\r\n const { headers, ...passThrough } = config || {};\r\n const { headers: headers2, ...passThrough2 } = toMerge || {};\r\n return {\r\n ...passThrough,\r\n ...passThrough2,\r\n headers: {\r\n ...headers,\r\n ...headers2,\r\n },\r\n };\r\n}\r\n"]}
1
+ {"version":3,"file":"AjaxRequestConfig.js","sourceRoot":"","sources":["../src/AjaxRequestConfig.ts"],"names":[],"mappings":";AAAA,MAAM,cAAc,GAAwB;IAC1C,wBAAwB;IACxB,KAAK,EAAE,KAAK;IACZ,sBAAsB;IACtB,oBAAoB;CACrB,CAAC;AAeF,MAAM,UAAU,gBAAgB,CAAC,MAA0B;IACzD,OAAO,eAAe,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,MAA4B,EAAE,OAA6B;IACzF,MAAM,KAA8B,MAAM,IAAI,EAAE,EAA1C,EAAE,OAAO,OAAiC,EAA5B,WAAW,cAAzB,WAA2B,CAAe,CAAC;IACjD,MAAM,KAAyC,OAAO,IAAI,EAAE,EAAtD,EAAE,OAAO,EAAE,QAAQ,OAAmC,EAA9B,YAAY,cAApC,WAAsC,CAAgB,CAAC;IAC7D,qDACK,WAAW,GACX,YAAY,KACf,OAAO,kCACF,OAAO,GACP,QAAQ,KAEb;AACJ,CAAC","sourcesContent":["const DEFAULT_CONFIG: JQuery.AjaxSettings = {\n // we never want caching\n cache: false,\n // we always want JSON\n // dataType: \"json\",\n};\n\n/**\n * Available config options for end user when making a given request.\n */\nexport interface AjaxRequestConfig\n extends Pick<JQuery.AjaxSettings, \"complete\" | \"beforeSend\" | \"headers\" | \"statusCode\" | \"timeout\"> {\n /**\n * Add query params.\n */\n params?: Record<string, string | number | boolean | Array<string | number | boolean>>;\n}\n\nexport interface InternalRequestConfig extends JQuery.AjaxSettings, Pick<AjaxRequestConfig, \"params\"> {}\n\nexport function getDefaultConfig(config?: AjaxRequestConfig): InternalRequestConfig {\n return mergeAjaxConfig(DEFAULT_CONFIG, config);\n}\n\nexport function mergeAjaxConfig(config?: JQuery.AjaxSettings, toMerge?: JQuery.AjaxSettings): InternalRequestConfig {\n const { headers, ...passThrough } = config || {};\n const { headers: headers2, ...passThrough2 } = toMerge || {};\n return {\n ...passThrough,\n ...passThrough2,\n headers: {\n ...headers,\n ...headers2,\n },\n };\n}\n"]}
@@ -1,12 +1,12 @@
1
1
  /// <reference types="jquery/jquerystatic" />
2
- import { HttpResponseModel, InternalHttpClientConfig } from "@odata2ts/http-client-api";
3
- import { BaseHttpClient, BaseHttpClientOptions, HttpMethods } from "@odata2ts/http-client-base";
2
+ import { HttpResponseModel, ODataHttpClient } from "@odata2ts/http-client-api";
3
+ import { BaseHttpClient, BaseHttpClientOptions, HttpMethods, InternalHttpClientConfig } from "@odata2ts/http-client-base";
4
4
  import { AjaxRequestConfig } from "./AjaxRequestConfig";
5
5
  import jqXHR = JQuery.jqXHR;
6
6
  export declare const DEFAULT_ERROR_MESSAGE = "No error message!";
7
7
  export interface ClientOptions extends BaseHttpClientOptions {
8
8
  }
9
- export declare class JQueryClient extends BaseHttpClient<AjaxRequestConfig> {
9
+ export declare class JQueryClient extends BaseHttpClient<AjaxRequestConfig> implements ODataHttpClient<AjaxRequestConfig> {
10
10
  private readonly client;
11
11
  private readonly config;
12
12
  constructor(jquery: JQueryStatic, config?: AjaxRequestConfig, clientOptions?: ClientOptions);
@@ -1,17 +1,14 @@
1
- "use strict";
2
1
  /// <reference path="../../../node_modules/@types/jquery/JQueryStatic.d.ts" />
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.JQueryClient = exports.DEFAULT_ERROR_MESSAGE = void 0;
5
- const tslib_1 = require("tslib");
6
- const http_client_base_1 = require("@odata2ts/http-client-base");
7
- const AjaxRequestConfig_1 = require("./AjaxRequestConfig");
8
- const JQueryClientError_1 = require("./JQueryClientError");
9
- exports.DEFAULT_ERROR_MESSAGE = "No error message!";
10
- class JQueryClient extends http_client_base_1.BaseHttpClient {
2
+ import { __awaiter, __rest } from "tslib";
3
+ import { BaseHttpClient, } from "@odata2ts/http-client-base";
4
+ import { getDefaultConfig, mergeAjaxConfig } from "./AjaxRequestConfig";
5
+ import { JQueryClientError } from "./JQueryClientError";
6
+ export const DEFAULT_ERROR_MESSAGE = "No error message!";
7
+ export class JQueryClient extends BaseHttpClient {
11
8
  constructor(jquery, config, clientOptions) {
12
9
  super(clientOptions);
13
10
  this.client = jquery;
14
- this.config = (0, AjaxRequestConfig_1.getDefaultConfig)(config);
11
+ this.config = getDefaultConfig(config);
15
12
  }
16
13
  mapHeaders(jqXhr) {
17
14
  return jqXhr
@@ -29,9 +26,9 @@ class JQueryClient extends http_client_base_1.BaseHttpClient {
29
26
  }, {});
30
27
  }
31
28
  executeRequest(method, url, data, requestConfig, internalConfig = {}) {
32
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
33
- const withInternalConfig = (0, AjaxRequestConfig_1.mergeAjaxConfig)({ headers: internalConfig.headers }, requestConfig);
34
- const _a = (0, AjaxRequestConfig_1.mergeAjaxConfig)(this.config, withInternalConfig), { params } = _a, mergedConfig = tslib_1.__rest(_a, ["params"]);
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ const withInternalConfig = mergeAjaxConfig({ headers: internalConfig.headers }, requestConfig);
31
+ const _a = mergeAjaxConfig(this.config, withInternalConfig), { params } = _a, mergedConfig = __rest(_a, ["params"]);
35
32
  mergedConfig.method = method;
36
33
  mergedConfig.data = JSON.stringify(data);
37
34
  mergedConfig.url = url;
@@ -41,6 +38,12 @@ class JQueryClient extends http_client_base_1.BaseHttpClient {
41
38
  // @ts-ignore
42
39
  new URLSearchParams(params).toString();
43
40
  }
41
+ if (internalConfig.dataType === "blob") {
42
+ mergedConfig.xhrFields = { responseType: "blob" };
43
+ }
44
+ else if (internalConfig.dataType === "stream") {
45
+ throw new Error("Streaming is not supported by the JqueryClient!");
46
+ }
44
47
  // the actual request
45
48
  return new Promise((resolve, reject) => {
46
49
  this.client.ajax(Object.assign(Object.assign({}, mergedConfig), { success: (response, textStatus, jqXHR) => {
@@ -51,16 +54,14 @@ class JQueryClient extends http_client_base_1.BaseHttpClient {
51
54
  data: response,
52
55
  });
53
56
  }, error: (jqXHR, textStatus, thrownError) => {
54
- var _a;
55
57
  const responseMessage = this.retrieveErrorMessage(jqXHR === null || jqXHR === void 0 ? void 0 : jqXHR.responseJSON);
56
- const failMsg = (_a = responseMessage !== null && responseMessage !== void 0 ? responseMessage : thrownError) !== null && _a !== void 0 ? _a : exports.DEFAULT_ERROR_MESSAGE;
58
+ const failMsg = responseMessage || thrownError || DEFAULT_ERROR_MESSAGE;
57
59
  const errorMessage = responseMessage ? "OData server responded with error: " + responseMessage : failMsg;
58
60
  const responseHeaders = this.mapHeaders(jqXHR);
59
- reject(new JQueryClientError_1.JQueryClientError(errorMessage, jqXHR.status, responseHeaders, new Error(failMsg), jqXHR));
61
+ reject(new JQueryClientError(errorMessage, jqXHR.status, responseHeaders, new Error(failMsg), jqXHR));
60
62
  } }));
61
63
  });
62
64
  });
63
65
  }
64
66
  }
65
- exports.JQueryClient = JQueryClient;
66
67
  //# sourceMappingURL=JQueryClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"JQueryClient.js","sourceRoot":"","sources":["../src/JQueryClient.ts"],"names":[],"mappings":";AAAA,8EAA8E;;;;AAG9E,iEAAgG;AAEhG,2DAA2F;AAC3F,2DAAwD;AAI3C,QAAA,qBAAqB,GAAG,mBAAmB,CAAC;AAIzD,MAAa,YAAa,SAAQ,iCAAiC;IAIjE,YAAY,MAAoB,EAAE,MAA0B,EAAE,aAA6B;QACzF,KAAK,CAAC,aAAa,CAAC,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,IAAA,oCAAgB,EAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IA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ternalHttpClientConfig } from \"@odata2ts/http-client-api\";\r\nimport { BaseHttpClient, BaseHttpClientOptions, HttpMethods } from \"@odata2ts/http-client-base\";\r\n\r\nimport { AjaxRequestConfig, getDefaultConfig, mergeAjaxConfig } from \"./AjaxRequestConfig\";\r\nimport { JQueryClientError } from \"./JQueryClientError\";\r\n\r\nimport jqXHR = JQuery.jqXHR;\r\n\r\nexport const DEFAULT_ERROR_MESSAGE = \"No error message!\";\r\n\r\nexport interface ClientOptions extends BaseHttpClientOptions {}\r\n\r\nexport class JQueryClient extends BaseHttpClient<AjaxRequestConfig> {\r\n private readonly client: JQueryStatic;\r\n private readonly config: JQuery.AjaxSettings;\r\n\r\n constructor(jquery: JQueryStatic, config?: AjaxRequestConfig, clientOptions?: ClientOptions) {\r\n super(clientOptions);\r\n this.client = jquery;\r\n this.config = getDefaultConfig(config);\r\n }\r\n\r\n protected mapHeaders(jqXhr: jqXHR): Record<string, string> {\r\n return jqXhr\r\n .getAllResponseHeaders()\r\n .trim()\r\n .split(/[\\r\\n]+/)\r\n .reduce((collector: Record<string, string>, line: string) => {\r\n const parts = line.split(\": \");\r\n const header = parts.shift();\r\n const value = parts.join(\": \");\r\n\r\n if (header) {\r\n collector[header.toLowerCase()] = value;\r\n }\r\n return collector;\r\n }, {});\r\n }\r\n\r\n protected async executeRequest<ResponseModel>(\r\n method: HttpMethods,\r\n url: string,\r\n data: any,\r\n requestConfig?: JQuery.AjaxSettings,\r\n internalConfig: InternalHttpClientConfig = {}\r\n ): Promise<HttpResponseModel<ResponseModel>> {\r\n const withInternalConfig = mergeAjaxConfig({ headers: internalConfig.headers }, requestConfig);\r\n const { params, ...mergedConfig } = mergeAjaxConfig(this.config, withInternalConfig);\r\n mergedConfig.method = method;\r\n mergedConfig.data = JSON.stringify(data);\r\n mergedConfig.url = url;\r\n if (params && Object.values(params).length) {\r\n mergedConfig.url +=\r\n (url.match(/\\?/) ? \"&\" : \"?\") +\r\n // @ts-ignore\r\n new URLSearchParams(params).toString();\r\n }\r\n\r\n // the actual request\r\n return new Promise((resolve, reject) => {\r\n this.client.ajax({\r\n ...mergedConfig,\r\n success: (response: any, textStatus: string, jqXHR: JQuery.jqXHR) => {\r\n resolve({\r\n status: jqXHR.status,\r\n statusText: jqXHR.statusText,\r\n headers: this.mapHeaders(jqXHR),\r\n data: response,\r\n });\r\n },\r\n error: (jqXHR: JQuery.jqXHR, textStatus: string, thrownError: string) => {\r\n const responseMessage = this.retrieveErrorMessage(jqXHR?.responseJSON);\r\n const failMsg = responseMessage ?? thrownError ?? DEFAULT_ERROR_MESSAGE;\r\n const errorMessage = responseMessage ? \"OData server responded with error: \" + responseMessage : failMsg;\r\n const responseHeaders = this.mapHeaders(jqXHR);\r\n reject(new JQueryClientError(errorMessage, jqXHR.status, responseHeaders, new Error(failMsg), jqXHR));\r\n },\r\n });\r\n });\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"JQueryClient.js","sourceRoot":"","sources":["../src/JQueryClient.ts"],"names":[],"mappings":"AAAA,8EAA8E;;AAG9E,OAAO,EACL,cAAc,GAIf,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAqB,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3F,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAIxD,MAAM,CAAC,MAAM,qBAAqB,GAAG,mBAAmB,CAAC;AAIzD,MAAM,OAAO,YAAa,SAAQ,cAAiC;IAIjE,YAAY,MAAoB,EAAE,MAA0B,EAAE,aAA6B;QACzF,KAAK,CAAC,aAAa,CAAC,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAES,UAAU,CAAC,KAAY;QAC/B,OAAO,KAAK;aACT,qBAAqB,EAAE;aACvB,IAAI,EAAE;aACN,KAAK,CAAC,SAAS,CAAC;aAChB,MAAM,CAAC,CAAC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QueryStatic.d.ts\" />\n\nimport { HttpResponseModel, ODataHttpClient } from \"@odata2ts/http-client-api\";\nimport {\n BaseHttpClient,\n BaseHttpClientOptions,\n HttpMethods,\n InternalHttpClientConfig,\n} from \"@odata2ts/http-client-base\";\nimport { AjaxRequestConfig, getDefaultConfig, mergeAjaxConfig } from \"./AjaxRequestConfig\";\nimport { JQueryClientError } from \"./JQueryClientError\";\n\nimport jqXHR = JQuery.jqXHR;\n\nexport const DEFAULT_ERROR_MESSAGE = \"No error message!\";\n\nexport interface ClientOptions extends BaseHttpClientOptions {}\n\nexport class JQueryClient extends BaseHttpClient<AjaxRequestConfig> implements ODataHttpClient<AjaxRequestConfig> {\n private readonly client: JQueryStatic;\n private readonly config: JQuery.AjaxSettings;\n\n constructor(jquery: JQueryStatic, config?: AjaxRequestConfig, clientOptions?: ClientOptions) {\n super(clientOptions);\n this.client = jquery;\n this.config = getDefaultConfig(config);\n }\n\n protected mapHeaders(jqXhr: jqXHR): Record<string, string> {\n return jqXhr\n .getAllResponseHeaders()\n .trim()\n .split(/[\\r\\n]+/)\n .reduce((collector: Record<string, string>, line: string) => {\n const parts = line.split(\": \");\n const header = parts.shift();\n const value = parts.join(\": \");\n\n if (header) {\n collector[header.toLowerCase()] = value;\n }\n return collector;\n }, {});\n }\n\n protected async executeRequest<ResponseModel>(\n method: HttpMethods,\n url: string,\n data: any,\n requestConfig?: JQuery.AjaxSettings,\n internalConfig: InternalHttpClientConfig = {},\n ): Promise<HttpResponseModel<ResponseModel>> {\n const withInternalConfig = mergeAjaxConfig({ headers: internalConfig.headers }, requestConfig);\n const { params, ...mergedConfig } = mergeAjaxConfig(this.config, withInternalConfig);\n mergedConfig.method = method;\n mergedConfig.data = JSON.stringify(data);\n mergedConfig.url = url;\n if (params && Object.values(params).length) {\n mergedConfig.url +=\n (url.match(/\\?/) ? \"&\" : \"?\") +\n // @ts-ignore\n new URLSearchParams(params).toString();\n }\n\n if (internalConfig.dataType === \"blob\") {\n mergedConfig.xhrFields = { responseType: \"blob\" };\n } else if (internalConfig.dataType === \"stream\") {\n throw new Error(\"Streaming is not supported by the JqueryClient!\");\n }\n\n // the actual request\n return new Promise((resolve, reject) => {\n this.client.ajax({\n ...mergedConfig,\n success: (response: any, textStatus: string, jqXHR: JQuery.jqXHR) => {\n resolve({\n status: jqXHR.status,\n statusText: jqXHR.statusText,\n headers: this.mapHeaders(jqXHR),\n data: response,\n });\n },\n error: (jqXHR: JQuery.jqXHR, textStatus: string, thrownError: string) => {\n const responseMessage = this.retrieveErrorMessage(jqXHR?.responseJSON);\n const failMsg = responseMessage || thrownError || DEFAULT_ERROR_MESSAGE;\n const errorMessage = responseMessage ? \"OData server responded with error: \" + responseMessage : failMsg;\n const responseHeaders = this.mapHeaders(jqXHR);\n reject(new JQueryClientError(errorMessage, jqXHR.status, responseHeaders, new Error(failMsg), jqXHR));\n },\n });\n });\n }\n}\n"]}
@@ -1,8 +1,5 @@
1
- "use strict";
2
1
  /// <reference path="../../../node_modules/@types/jquery/misc.d.ts" />
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.JQueryClientError = void 0;
5
- class JQueryClientError extends Error {
2
+ export class JQueryClientError extends Error {
6
3
  constructor(msg, status, headers, cause, jqXHR) {
7
4
  // @ts-ignore: fetch requires lib "dom" or "webworker", but then the "cause" property becomes unknown to TS
8
5
  super(msg, { cause });
@@ -13,5 +10,4 @@ class JQueryClientError extends Error {
13
10
  this.name = this.constructor.name;
14
11
  }
15
12
  }
16
- exports.JQueryClientError = JQueryClientError;
17
13
  //# sourceMappingURL=JQueryClientError.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"JQueryClientError.js","sourceRoot":"","sources":["../src/JQueryClientError.ts"],"names":[],"mappings":";AAAA,sEAAsE;;;AAItE,MAAa,iBAAkB,SAAQ,KAAK;IAC1C,YACE,GAAW,EACK,MAA0B,EAC1B,OAA2C,EAC3C,KAAwB,EACxB,KAAmB;QAEnC,2GAA2G;QAC3G,KAAK,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QANN,WAAM,GAAN,MAAM,CAAoB;QAC1B,YAAO,GAAP,OAAO,CAAoC;QAC3C,UAAK,GAAL,KAAK,CAAmB;QACxB,UAAK,GAAL,KAAK,CAAc;QAInC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IACpC,CAAC;CACF;AAZD,8CAYC","sourcesContent":["/// <reference path=\"../../../node_modules/@types/jquery/misc.d.ts\" />\r\n\r\nimport { ODataClientError } from \"@odata2ts/http-client-api\";\r\n\r\nexport class JQueryClientError extends Error implements ODataClientError {\r\n constructor(\r\n msg: string,\r\n public readonly status: number | undefined,\r\n public readonly headers: Record<string, string> | undefined,\r\n public readonly cause: Error | undefined,\r\n public readonly jqXHR: JQuery.jqXHR\r\n ) {\r\n // @ts-ignore: fetch requires lib \"dom\" or \"webworker\", but then the \"cause\" property becomes unknown to TS\r\n super(msg, { cause });\r\n this.name = this.constructor.name;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"JQueryClientError.js","sourceRoot":"","sources":["../src/JQueryClientError.ts"],"names":[],"mappings":"AAAA,sEAAsE;AAItE,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,YACE,GAAW,EACK,MAA0B,EAC1B,OAA2C,EAC3C,KAAwB,EACxB,KAAmB;QAEnC,2GAA2G;QAC3G,KAAK,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QANN,WAAM,GAAN,MAAM,CAAoB;QAC1B,YAAO,GAAP,OAAO,CAAoC;QAC3C,UAAK,GAAL,KAAK,CAAmB;QACxB,UAAK,GAAL,KAAK,CAAc;QAInC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IACpC,CAAC;CACF","sourcesContent":["/// <reference path=\"../../../node_modules/@types/jquery/misc.d.ts\" />\n\nimport { ODataClientError } from \"@odata2ts/http-client-api\";\n\nexport class JQueryClientError extends Error implements ODataClientError {\n constructor(\n msg: string,\n public readonly status: number | undefined,\n public readonly headers: Record<string, string> | undefined,\n public readonly cause: Error | undefined,\n public readonly jqXHR: JQuery.jqXHR,\n ) {\n // @ts-ignore: fetch requires lib \"dom\" or \"webworker\", but then the \"cause\" property becomes unknown to TS\n super(msg, { cause });\n this.name = this.constructor.name;\n }\n}\n"]}
package/lib/index.js CHANGED
@@ -1,8 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JQueryClientError = void 0;
4
- const tslib_1 = require("tslib");
5
- tslib_1.__exportStar(require("./JQueryClient"), exports);
6
- var JQueryClientError_1 = require("./JQueryClientError");
7
- Object.defineProperty(exports, "JQueryClientError", { enumerable: true, get: function () { return JQueryClientError_1.JQueryClientError; } });
1
+ export * from "./JQueryClient";
2
+ export { JQueryClientError } from "./JQueryClientError";
8
3
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AACA,yDAA+B;AAC/B,yDAAwD;AAA/C,sHAAA,iBAAiB,OAAA","sourcesContent":["export { AjaxRequestConfig } from \"./AjaxRequestConfig\";\r\nexport * from \"./JQueryClient\";\r\nexport { JQueryClientError } from \"./JQueryClientError\";\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["export { AjaxRequestConfig } from \"./AjaxRequestConfig\";\nexport * from \"./JQueryClient\";\nexport { JQueryClientError } from \"./JQueryClientError\";\n"]}
package/package.json CHANGED
@@ -1,54 +1,50 @@
1
1
  {
2
2
  "name": "@odata2ts/http-client-jquery",
3
- "version": "0.8.1",
4
- "publishConfig": {
5
- "access": "public"
6
- },
3
+ "version": "0.9.0",
7
4
  "description": "JQuery based http client usable by odata2ts",
8
- "license": "MIT",
5
+ "keywords": [
6
+ "http client",
7
+ "jquery",
8
+ "odata2ts",
9
+ "ui5",
10
+ "ts",
11
+ "typescript"
12
+ ],
9
13
  "repository": "git@github.com:odata2ts/http-client.git",
14
+ "license": "MIT",
10
15
  "author": "texttechne",
16
+ "type": "module",
11
17
  "main": "./lib/index.js",
18
+ "types": "./lib/index.d.ts",
19
+ "files": [
20
+ "*.md",
21
+ "lib",
22
+ "LICENSE"
23
+ ],
12
24
  "scripts": {
13
25
  "build": "yarn clean && yarn compile",
14
26
  "check-circular-deps": "madge ./src --extensions ts --circular",
15
27
  "clean": "rimraf lib coverage",
16
28
  "compile": "tsc",
17
- "int-test": "jest ./int-test",
29
+ "int-test": "vitest run int-test/**",
18
30
  "prepublish": "yarn build",
19
- "test": "jest ./test"
20
- },
21
- "files": [
22
- "*.md",
23
- "lib",
24
- "LICENSE"
25
- ],
26
- "keywords": [
27
- "http client",
28
- "jquery",
29
- "odata2ts",
30
- "ui5",
31
- "ts",
32
- "typescript"
33
- ],
34
- "peerDependencies": {
35
- "jquery": ">1.0"
31
+ "test": "vitest run test/**"
36
32
  },
37
33
  "dependencies": {
38
- "@odata2ts/http-client-base": "^0.4.1"
34
+ "@odata2ts/http-client-base": "^0.5.0"
39
35
  },
40
36
  "devDependencies": {
41
- "@types/jest": "^27.4.1",
42
37
  "@types/jquery": "^3.5.16",
43
38
  "@types/node": "^20.2.5",
44
- "jest": "29.5.0",
45
- "jest-environment-jsdom": "^29.5.0",
46
39
  "jquery": "^3.6.3",
47
40
  "rimraf": "^5.0.1",
48
- "ts-jest": "^29.1.0",
49
- "ts-node": "10.9.1",
50
41
  "typescript": "5.0.4"
51
42
  },
52
- "types": "./lib/index.d.ts",
53
- "gitHead": "86202a1b93868d7d25e4832ed254ad20e7a14bdb"
43
+ "peerDependencies": {
44
+ "jquery": ">1.0"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "gitHead": "6a0905bd7f201a5c91d83a9319c2a0325a017651"
54
50
  }