@odata2ts/http-client-jquery 0.5.1 → 0.6.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,20 @@
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.6.0](https://github.com/odata2ts/http-client/compare/@odata2ts/http-client-jquery@0.5.1...@odata2ts/http-client-jquery@0.6.0) (2023-08-03)
7
+
8
+ ### Code Refactoring
9
+
10
+ * **jquery:** remove default headers ([3106d97](https://github.com/odata2ts/http-client/commit/3106d9768765e7cc228097ed1270439d47ff0e0c))
11
+
12
+ ### Features
13
+
14
+ * allow for additional headers for all operations ([#10](https://github.com/odata2ts/http-client/issues/10)) ([75eedd3](https://github.com/odata2ts/http-client/commit/75eedd3ebb8534188a5a644aee9e69e17f1f0c80))
15
+
16
+ ### BREAKING CHANGES
17
+
18
+ * **jquery:** removed default accept & content-type headers as well as `dataType=json`; removed merge & retrieveBigNumbersAsString methods (base-lib); all of these settings can now be configured per operation via the `additionalHeaders` option.
19
+
6
20
  ## [0.5.1](https://github.com/odata2ts/http-client/compare/@odata2ts/http-client-jquery@0.5.0...@odata2ts/http-client-jquery@0.5.1) (2023-07-26)
7
21
 
8
22
  **Note:** Version bump only for package @odata2ts/http-client-jquery
@@ -6,8 +6,7 @@ const DEFAULT_CONFIG = {
6
6
  // we never want caching
7
7
  cache: false,
8
8
  // we always want JSON
9
- dataType: "json",
10
- headers: { Accept: "application/json", "Content-Type": "application/json" },
9
+ // dataType: "json",
11
10
  };
12
11
  function getDefaultConfig(config) {
13
12
  return mergeAjaxConfig(DEFAULT_CONFIG, config);
@@ -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,QAAQ,EAAE,MAAM;IAChB,OAAO,EAAE,EAAE,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,kBAAkB,EAAE;CAC5E,CAAC;AAUF,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 headers: { Accept: \"application/json\", \"Content-Type\": \"application/json\" },\r\n};\r\n\r\n/**\r\n * Available config options for end user when making a given request.\r\n */\r\nexport type AjaxRequestConfig = Pick<\r\n JQuery.AjaxSettings,\r\n \"complete\" | \"beforeSend\" | \"headers\" | \"statusCode\" | \"timeout\"\r\n>;\r\n\r\nexport function getDefaultConfig(config?: AjaxRequestConfig): JQuery.AjaxSettings {\r\n return mergeAjaxConfig(DEFAULT_CONFIG, config);\r\n}\r\n\r\nexport function mergeAjaxConfig(config?: JQuery.AjaxSettings, toMerge?: JQuery.AjaxSettings) {\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;AAUF,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 type AjaxRequestConfig = Pick<\r\n JQuery.AjaxSettings,\r\n \"complete\" | \"beforeSend\" | \"headers\" | \"statusCode\" | \"timeout\"\r\n>;\r\n\r\nexport function getDefaultConfig(config?: AjaxRequestConfig): JQuery.AjaxSettings {\r\n return mergeAjaxConfig(DEFAULT_CONFIG, config);\r\n}\r\n\r\nexport function mergeAjaxConfig(config?: JQuery.AjaxSettings, toMerge?: JQuery.AjaxSettings) {\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"]}
@@ -3,6 +3,7 @@ import { HttpResponseModel } from "@odata2ts/http-client-api";
3
3
  import { BaseHttpClient, BaseHttpClientOptions, HttpMethods } from "@odata2ts/http-client-base";
4
4
  import { AjaxRequestConfig } from "./AjaxRequestConfig";
5
5
  import jqXHR = JQuery.jqXHR;
6
+ export declare const DEFAULT_ERROR_MESSAGE = "No error message!";
6
7
  export interface ClientOptions extends BaseHttpClientOptions {
7
8
  }
8
9
  export declare class JQueryClient extends BaseHttpClient<AjaxRequestConfig> {
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  /// <reference path="../../../node_modules/@types/jquery/JQueryStatic.d.ts" />
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.JQueryClient = void 0;
4
+ exports.JQueryClient = exports.DEFAULT_ERROR_MESSAGE = void 0;
5
+ const tslib_1 = require("tslib");
5
6
  const http_client_base_1 = require("@odata2ts/http-client-base");
6
7
  const AjaxRequestConfig_1 = require("./AjaxRequestConfig");
7
8
  const JQueryClientError_1 = require("./JQueryClientError");
9
+ exports.DEFAULT_ERROR_MESSAGE = "No error message!";
8
10
  class JQueryClient extends http_client_base_1.BaseHttpClient {
9
11
  constructor(jquery, config, clientOptions) {
10
12
  super(clientOptions);
@@ -28,30 +30,32 @@ class JQueryClient extends http_client_base_1.BaseHttpClient {
28
30
  }, {});
29
31
  }
30
32
  addHeaderToRequestConfig(headers, config) {
31
- return (0, AjaxRequestConfig_1.mergeAjaxConfig)(config, { headers });
33
+ return (0, AjaxRequestConfig_1.mergeAjaxConfig)({ headers }, config);
32
34
  }
33
35
  executeRequest(method, url, data, requestConfig) {
34
- const mergedConfig = (0, AjaxRequestConfig_1.mergeAjaxConfig)(this.config, requestConfig);
35
- mergedConfig.method = method;
36
- mergedConfig.url = url;
37
- mergedConfig.data = JSON.stringify(data);
38
- // the actual request
39
- return new Promise((resolve, reject) => {
40
- this.client.ajax(Object.assign(Object.assign({}, mergedConfig), { success: (response, textStatus, jqXHR) => {
41
- resolve({
42
- status: jqXHR.status,
43
- statusText: jqXHR.statusText,
44
- headers: this.mapHeaders(jqXHR),
45
- data: response,
46
- });
47
- }, error: (jqXHR, textStatus, thrownError) => {
48
- const responseMessage = this.retrieveErrorMessage(jqXHR.responseJSON);
49
- const errorMessage = responseMessage
50
- ? "Server responded with error: " + responseMessage
51
- : textStatus + " " + thrownError;
52
- const responseHeaders = this.mapHeaders(jqXHR);
53
- reject(new JQueryClientError_1.JQueryClientError(errorMessage, jqXHR.status, responseHeaders, new Error(thrownError), jqXHR));
54
- } }));
36
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
37
+ const mergedConfig = (0, AjaxRequestConfig_1.mergeAjaxConfig)(this.config, requestConfig);
38
+ mergedConfig.method = method;
39
+ mergedConfig.url = url;
40
+ mergedConfig.data = JSON.stringify(data);
41
+ // the actual request
42
+ return new Promise((resolve, reject) => {
43
+ this.client.ajax(Object.assign(Object.assign({}, mergedConfig), { success: (response, textStatus, jqXHR) => {
44
+ resolve({
45
+ status: jqXHR.status,
46
+ statusText: jqXHR.statusText,
47
+ headers: this.mapHeaders(jqXHR),
48
+ data: response,
49
+ });
50
+ }, error: (jqXHR, textStatus, thrownError) => {
51
+ var _a;
52
+ const responseMessage = this.retrieveErrorMessage(jqXHR === null || jqXHR === void 0 ? void 0 : jqXHR.responseJSON);
53
+ const failMsg = (_a = responseMessage !== null && responseMessage !== void 0 ? responseMessage : thrownError) !== null && _a !== void 0 ? _a : exports.DEFAULT_ERROR_MESSAGE;
54
+ const errorMessage = responseMessage ? "OData server responded with error: " + responseMessage : failMsg;
55
+ const responseHeaders = this.mapHeaders(jqXHR);
56
+ reject(new JQueryClientError_1.JQueryClientError(errorMessage, jqXHR.status, responseHeaders, new Error(failMsg), jqXHR));
57
+ } }));
58
+ });
55
59
  });
56
60
  }
57
61
  }
@@ -1 +1 @@
1
- {"version":3,"file":"JQueryClient.js","sourceRoot":"","sources":["../src/JQueryClient.ts"],"names":[],"mapp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Y,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAEzC,qBAAqB;QACrB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,MAAM,CAAC,IAAI,iCACX,YAAY,KACf,OAAO,EAAE,CAAC,QAAa,EAAE,UAAkB,EAAE,KAAmB,EAAE,EAAE;oBAClE,OAAO,CAAC;wBACN,MAAM,EAAE,KAAK,CAAC,MAAM;wBACpB,UAAU,EAAE,KAAK,CAAC,UAAU;wBAC5B,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;wBAC/B,IAAI,EAAE,QAAQ;qBACf,CAAC,CAAC;gBACL,CAAC,EACD,KAAK,EAAE,CAAC,KAAmB,EAAE,UAAkB,EAAE,WAAmB,EAAE,EAAE;oBACtE,MAAM,eAAe,GAAG,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;oBACtE,MAAM,YAAY,GAAG,eAAe;wBAClC,CAAC,CAAC,+BAA+B,GAAG,eAAe;wBACnD,CAAC,CAAC,UAAU,GAAG,GAAG,GAAG,WAAW,CAAC;oBACnC,MAAM,eAAe,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;oBAC/C,MAAM,CAAC,IAAI,qCAAiB,CAAC,YAAY,EAAE,KAAK,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,KAAK,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;gBAC5G,CAAC,IACD,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAjED,oCAiEC","sourcesContent":["/// <reference path=\"../../../node_modules/@types/jquery/JQueryStatic.d.ts\" />\r\n\r\nimport { HttpResponseModel } 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 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, private 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 addHeaderToRequestConfig(headers: Record<string, string>, config?: AjaxRequestConfig): AjaxRequestConfig {\r\n return mergeAjaxConfig(config, { headers });\r\n }\r\n\r\n protected executeRequest<ResponseModel>(\r\n method: HttpMethods,\r\n url: string,\r\n data: any,\r\n requestConfig?: JQuery.AjaxSettings\r\n ): Promise<HttpResponseModel<ResponseModel>> {\r\n const mergedConfig = mergeAjaxConfig(this.config, requestConfig);\r\n mergedConfig.method = method;\r\n mergedConfig.url = url;\r\n mergedConfig.data = JSON.stringify(data);\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 errorMessage = responseMessage\r\n ? \"Server responded with error: \" + responseMessage\r\n : textStatus + \" \" + thrownError;\r\n const responseHeaders = this.mapHeaders(jqXHR);\r\n reject(new JQueryClientError(errorMessage, jqXHR.status, responseHeaders, new Error(thrownError), 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,iEAAgG;AAEhG,2DAA2F;AAC3F,2DAAwD;AAI3C,QAAA,qBAAqB,GAAG,mBAAmB,CAAC;AAIzD,MAAa,YAAa,SAAQ,iCAAiC;IAIjE,YAAY,MAAoB,EAAE,MAA0B,EAAU,aAA6B;QACjG,KAAK,CAAC,aAAa,CAAC,CAAC;QAD+C,kBAAa,GAAb,aAAa,CAAgB;QAEjG,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,IAAA,oCAAgB,EAAC,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,SAAiC,EAAE,IAAY,EAAE,EAAE;YAC1D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC/B,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;YAC7B,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAE/B,IAAI,MAAM,EAAE;gBACV,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,GAAG,KAAK,CAAC;aACzC;YACD,OAAO,SAAS,CAAC;QACnB,CAAC,EAAE,EAAE,CAAC,CAAC;IACX,CAAC;IAES,wBAAwB,CAAC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AAU,CAAC,KAAK,CAAC,CAAC;wBAC/C,MAAM,CAAC,IAAI,qCAAiB,CAAC,YAAY,EAAE,KAAK,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;oBACxG,CAAC,IACD,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;KAAA;CACF;AAhED,oCAgEC","sourcesContent":["/// <reference path=\"../../../node_modules/@types/jquery/JQueryStatic.d.ts\" />\r\n\r\nimport { HttpResponseModel } 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, private 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 addHeaderToRequestConfig(headers: Record<string, string>, config?: AjaxRequestConfig): AjaxRequestConfig {\r\n return mergeAjaxConfig({ headers }, config);\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 ): Promise<HttpResponseModel<ResponseModel>> {\r\n const mergedConfig = mergeAjaxConfig(this.config, requestConfig);\r\n mergedConfig.method = method;\r\n mergedConfig.url = url;\r\n mergedConfig.data = JSON.stringify(data);\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 +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,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\" />\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.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { AjaxRequestConfig } from "./AjaxRequestConfig";
2
2
  export * from "./JQueryClient";
3
- export type { JQueryClientError } from "./JQueryClientError";
3
+ export { JQueryClientError } from "./JQueryClientError";
package/lib/index.js CHANGED
@@ -1,5 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JQueryClientError = void 0;
3
4
  const tslib_1 = require("tslib");
4
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; } });
5
8
  //# 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","sourcesContent":["export { AjaxRequestConfig } from \"./AjaxRequestConfig\";\r\nexport * from \"./JQueryClient\";\r\nexport type { JQueryClientError } from \"./JQueryClientError\";\r\n"]}
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\";\nexport * from \"./JQueryClient\";\nexport { JQueryClientError } from \"./JQueryClientError\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odata2ts/http-client-jquery",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -14,8 +14,9 @@
14
14
  "check-circular-deps": "madge ./src --extensions ts --circular",
15
15
  "clean": "rimraf lib coverage",
16
16
  "compile": "tsc",
17
+ "int-test": "jest ./int-test",
17
18
  "prepublish": "yarn build",
18
- "test": "jest --passWithNoTests"
19
+ "test": "jest ./test"
19
20
  },
20
21
  "files": [
21
22
  "*.md",
@@ -25,8 +26,8 @@
25
26
  "keywords": [
26
27
  "http client",
27
28
  "jquery",
28
- "ui5",
29
29
  "odata2ts",
30
+ "ui5",
30
31
  "ts",
31
32
  "typescript"
32
33
  ],
@@ -34,7 +35,7 @@
34
35
  "jquery": ">1.0"
35
36
  },
36
37
  "dependencies": {
37
- "@odata2ts/http-client-base": "^0.2.0"
38
+ "@odata2ts/http-client-base": "^0.3.0"
38
39
  },
39
40
  "devDependencies": {
40
41
  "@types/jest": "^27.4.1",
@@ -49,5 +50,5 @@
49
50
  "typescript": "5.0.4"
50
51
  },
51
52
  "types": "./lib/index.d.ts",
52
- "gitHead": "9babd2df3010673249e7e3fa26705a8ba84f2cef"
53
+ "gitHead": "dc6e29cef27b2f5fca6e838e4a22766b90249e8e"
53
54
  }