@odata2ts/http-client-api 0.1.0 → 0.2.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,12 @@
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.2.0 (2023-06-10)
7
+
8
+ ### Features
9
+
10
+ * **http-client-api:** conventionalize client errors ([65ee7b8](https://github.com/odata2ts/http-client/commit/65ee7b811379881332839236692889b0414bd008))
11
+
6
12
  # 0.1.0 (2023-06-03)
7
13
 
8
14
  ### Features
package/README.md CHANGED
@@ -1,46 +1,46 @@
1
- [![npm (scoped)](https://img.shields.io/npm/v/@odata2ts/http-client-api?style=for-the-badge)](https://www.npmjs.com/package/@odata2ts/http-client-api)
2
-
3
- # HTTP Client API
4
-
5
- Defines the contract between [odata2ts](https://github.com/odata2ts/odata2ts) and any HTTP client implementation.
6
-
7
- The responsibilities of the HTTP Client are:
8
- - HTTP request execution
9
- - mapping responses to conventionalized structures
10
- - custom request configuration (optional)
11
- - automatic CSRF Token Handling (optional)
12
-
13
- Features like **optimistic locking** (via `ETag`) or **batch requests** are currently not in scope
14
- of the HTTP client and may never be.
15
-
16
- ## Documentation
17
- [HTTP Client Documentation](https://odata2ts.github.io/docs/odata-client/http-client)
18
-
19
- Main documentation for the odata2ts eco system:
20
- [https://odata2ts.github.io](https://odata2ts.github.io/)
21
-
22
- ## Tests
23
- As this library provides the API as TypeScript types, there are no runtime
24
- artefacts to test.
25
-
26
- ## Support, Feedback, Contributing
27
- This project is open to feature requests, suggestions, bug reports, usage questions etc.
28
- via [GitHub issues](https://github.com/odata2ts/odata2ts/issues).
29
-
30
- Contributions and feedback are encouraged and always welcome.
31
-
32
- See the [contribution guidelines](https://github.com/odata2ts/odata2ts/blob/main/CONTRIBUTING.md) for further information.
33
-
34
- ## Spirit
35
- This project and this module have been created and are maintained in the following spirit:
36
-
37
- * adhere to the **OData specification** as much as possible
38
- * support any OData service implementation which conforms to the spec
39
- * allow to work around faulty implementations if possible
40
- * stability matters
41
- * exercise Test Driven Development
42
- * bomb the place with unit tests (code coverage > 95%)
43
- * ensure that assumptions & understanding are correct by creating integration tests
44
-
45
- ## License
46
- MIT - see [License](./LICENSE).
1
+ [![npm (scoped)](https://img.shields.io/npm/v/@odata2ts/http-client-api?style=for-the-badge)](https://www.npmjs.com/package/@odata2ts/http-client-api)
2
+
3
+ # HTTP Client API
4
+
5
+ Defines the contract between [odata2ts](https://github.com/odata2ts/odata2ts) and any HTTP client implementation.
6
+
7
+ The responsibilities of the HTTP Client are:
8
+ - HTTP request execution
9
+ - mapping responses to conventionalized structures
10
+ - custom request configuration (optional)
11
+ - automatic CSRF Token Handling (optional)
12
+
13
+ Features like **optimistic locking** (via `ETag`) or **batch requests** are currently not in scope
14
+ of the HTTP client and may never be.
15
+
16
+ ## Documentation
17
+ [HTTP Client Documentation](https://odata2ts.github.io/docs/odata-client/http-client)
18
+
19
+ Main documentation for the odata2ts eco system:
20
+ [https://odata2ts.github.io](https://odata2ts.github.io/)
21
+
22
+ ## Tests
23
+ As this library provides the API as TypeScript types, there are no runtime
24
+ artefacts to test.
25
+
26
+ ## Support, Feedback, Contributing
27
+ This project is open to feature requests, suggestions, bug reports, usage questions etc.
28
+ via [GitHub issues](https://github.com/odata2ts/odata2ts/issues).
29
+
30
+ Contributions and feedback are encouraged and always welcome.
31
+
32
+ See the [contribution guidelines](https://github.com/odata2ts/odata2ts/blob/main/CONTRIBUTING.md) for further information.
33
+
34
+ ## Spirit
35
+ This project and this module have been created and are maintained in the following spirit:
36
+
37
+ * adhere to the **OData specification** as much as possible
38
+ * support any OData service implementation which conforms to the spec
39
+ * allow to work around faulty implementations if possible
40
+ * stability matters
41
+ * exercise Test Driven Development
42
+ * bomb the place with unit tests (code coverage > 95%)
43
+ * ensure that assumptions & understanding are correct by creating integration tests
44
+
45
+ ## License
46
+ MIT - see [License](./LICENSE).
@@ -0,0 +1,6 @@
1
+ export interface ODataClientError {
2
+ readonly name: string;
3
+ readonly status?: number;
4
+ readonly headers?: Record<string, string>;
5
+ readonly cause?: Error;
6
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ODataClientError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ODataClientError.js","sourceRoot":"","sources":["../src/ODataClientError.ts"],"names":[],"mappings":"","sourcesContent":["export interface ODataClientError {\r\n readonly name: string;\r\n readonly status?: number;\r\n readonly headers?: Record<string, string>;\r\n readonly cause?: Error;\r\n}\r\n"]}
@@ -1,54 +1,54 @@
1
- import { ODataResponse } from "./ODataResponseModel";
2
- /**
3
- * Retrieves the configuration type for the given HTTP client.
4
- */
5
- export type ODataHttpClientConfig<ClientType extends ODataHttpClient> = ClientType extends ODataHttpClient<infer Config> ? Config : never;
6
- export interface ODataHttpClient<RequestConfig = any> {
7
- /**
8
- * Create a model or collection entry.
9
- *
10
- * @param url
11
- * @param data
12
- * @param requestConfig
13
- */
14
- post<ResponseModel>(url: string, data: any, requestConfig?: RequestConfig): ODataResponse<ResponseModel>;
15
- get<ResponseModel>(url: string, requestConfig?: RequestConfig): ODataResponse<ResponseModel>;
16
- /**
17
- * Replace a model.
18
- *
19
- * @param url
20
- * @param data
21
- * @param requestConfig
22
- */
23
- put<ResponseModel>(url: string, data: any, requestConfig?: RequestConfig): ODataResponse<ResponseModel>;
24
- /**
25
- * Partially update a model.
26
- *
27
- * @param url
28
- * @param data
29
- * @param requestConfig
30
- */
31
- patch<ResponseModel>(url: string, data: any, requestConfig?: RequestConfig): ODataResponse<ResponseModel>;
32
- /**
33
- * OData V2 only feature.
34
- * Historically, PATCH method was not part of the official HTTP spec, when V1 & V2 were specified;
35
- * but use of PATCH was already envisioned {@link https://www.odata.org/documentation/odata-version-2-0/operations/}.
36
- * V3 and all following versions, specify use of PATCH method.
37
- *
38
- * If implemented, this method wil be used instead of patch to partially update models.
39
- * Use case: You want to reuse this client and one server can only handle MERGE,
40
- * but not PATCH http requests.
41
- *
42
- * @param url
43
- * @param data
44
- * @param requestConfig
45
- */
46
- merge?<ResponseModel>(url: string, data: any, requestConfig?: RequestConfig): ODataResponse<ResponseModel>;
47
- /**
48
- * Delete a model or collection.
49
- *
50
- * @param url
51
- * @param requestConfig
52
- */
53
- delete(url: string, requestConfig?: RequestConfig): ODataResponse<void>;
54
- }
1
+ import { ODataResponse } from "./ODataResponseModel";
2
+ /**
3
+ * Retrieves the configuration type for the given HTTP client.
4
+ */
5
+ export type ODataHttpClientConfig<ClientType extends ODataHttpClient> = ClientType extends ODataHttpClient<infer Config> ? Config : never;
6
+ export interface ODataHttpClient<RequestConfig = any> {
7
+ /**
8
+ * Create a model or collection entry.
9
+ *
10
+ * @param url
11
+ * @param data
12
+ * @param requestConfig
13
+ */
14
+ post<ResponseModel>(url: string, data: any, requestConfig?: RequestConfig): ODataResponse<ResponseModel>;
15
+ get<ResponseModel>(url: string, requestConfig?: RequestConfig): ODataResponse<ResponseModel>;
16
+ /**
17
+ * Replace a model.
18
+ *
19
+ * @param url
20
+ * @param data
21
+ * @param requestConfig
22
+ */
23
+ put<ResponseModel>(url: string, data: any, requestConfig?: RequestConfig): ODataResponse<ResponseModel>;
24
+ /**
25
+ * Partially update a model.
26
+ *
27
+ * @param url
28
+ * @param data
29
+ * @param requestConfig
30
+ */
31
+ patch<ResponseModel>(url: string, data: any, requestConfig?: RequestConfig): ODataResponse<ResponseModel>;
32
+ /**
33
+ * OData V2 only feature.
34
+ * Historically, PATCH method was not part of the official HTTP spec, when V1 & V2 were specified;
35
+ * but use of PATCH was already envisioned {@link https://www.odata.org/documentation/odata-version-2-0/operations/}.
36
+ * V3 and all following versions, specify use of PATCH method.
37
+ *
38
+ * If implemented, this method wil be used instead of patch to partially update models.
39
+ * Use case: You want to reuse this client and one server can only handle MERGE,
40
+ * but not PATCH http requests.
41
+ *
42
+ * @param url
43
+ * @param data
44
+ * @param requestConfig
45
+ */
46
+ merge?<ResponseModel>(url: string, data: any, requestConfig?: RequestConfig): ODataResponse<ResponseModel>;
47
+ /**
48
+ * Delete a model or collection.
49
+ *
50
+ * @param url
51
+ * @param requestConfig
52
+ */
53
+ delete(url: string, requestConfig?: RequestConfig): ODataResponse<void>;
54
+ }
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=ODataHttpClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ODataHttpClient.js","sourceRoot":"","sources":["../src/ODataHttpClient.ts"],"names":[],"mappings":"","sourcesContent":["import { ODataResponse } from \"./ODataResponseModel\";\n\n/**\n * Retrieves the configuration type for the given HTTP client.\n */\nexport type ODataHttpClientConfig<ClientType extends ODataHttpClient> = ClientType extends ODataHttpClient<infer Config>\n ? Config\n : never;\n\nexport interface ODataHttpClient<RequestConfig = any> {\n /**\n * Create a model or collection entry.\n *\n * @param url\n * @param data\n * @param requestConfig\n */\n post<ResponseModel>(url: string, data: any, requestConfig?: RequestConfig): ODataResponse<ResponseModel>;\n\n get<ResponseModel>(url: string, requestConfig?: RequestConfig): ODataResponse<ResponseModel>;\n\n /**\n * Replace a model.\n *\n * @param url\n * @param data\n * @param requestConfig\n */\n put<ResponseModel>(url: string, data: any, requestConfig?: RequestConfig): ODataResponse<ResponseModel>;\n\n /**\n * Partially update a model.\n *\n * @param url\n * @param data\n * @param requestConfig\n */\n patch<ResponseModel>(url: string, data: any, requestConfig?: RequestConfig): ODataResponse<ResponseModel>;\n\n /**\n * OData V2 only feature.\n * Historically, PATCH method was not part of the official HTTP spec, when V1 & V2 were specified;\n * but use of PATCH was already envisioned {@link https://www.odata.org/documentation/odata-version-2-0/operations/}.\n * V3 and all following versions, specify use of PATCH method.\n *\n * If implemented, this method wil be used instead of patch to partially update models.\n * Use case: You want to reuse this client and one server can only handle MERGE,\n * but not PATCH http requests.\n *\n * @param url\n * @param data\n * @param requestConfig\n */\n merge?<ResponseModel>(url: string, data: any, requestConfig?: RequestConfig): ODataResponse<ResponseModel>;\n\n /**\n * Delete a model or collection.\n *\n * @param url\n * @param requestConfig\n */\n delete(url: string, requestConfig?: RequestConfig): ODataResponse<void>;\n}\n"]}
1
+ {"version":3,"file":"ODataHttpClient.js","sourceRoot":"","sources":["../src/ODataHttpClient.ts"],"names":[],"mappings":"","sourcesContent":["import { ODataResponse } from \"./ODataResponseModel\";\r\n\r\n/**\r\n * Retrieves the configuration type for the given HTTP client.\r\n */\r\nexport type ODataHttpClientConfig<ClientType extends ODataHttpClient> = ClientType extends ODataHttpClient<infer Config>\r\n ? Config\r\n : never;\r\n\r\nexport interface ODataHttpClient<RequestConfig = any> {\r\n /**\r\n * Create a model or collection entry.\r\n *\r\n * @param url\r\n * @param data\r\n * @param requestConfig\r\n */\r\n post<ResponseModel>(url: string, data: any, requestConfig?: RequestConfig): ODataResponse<ResponseModel>;\r\n\r\n get<ResponseModel>(url: string, requestConfig?: RequestConfig): ODataResponse<ResponseModel>;\r\n\r\n /**\r\n * Replace a model.\r\n *\r\n * @param url\r\n * @param data\r\n * @param requestConfig\r\n */\r\n put<ResponseModel>(url: string, data: any, requestConfig?: RequestConfig): ODataResponse<ResponseModel>;\r\n\r\n /**\r\n * Partially update a model.\r\n *\r\n * @param url\r\n * @param data\r\n * @param requestConfig\r\n */\r\n patch<ResponseModel>(url: string, data: any, requestConfig?: RequestConfig): ODataResponse<ResponseModel>;\r\n\r\n /**\r\n * OData V2 only feature.\r\n * Historically, PATCH method was not part of the official HTTP spec, when V1 & V2 were specified;\r\n * but use of PATCH was already envisioned {@link https://www.odata.org/documentation/odata-version-2-0/operations/}.\r\n * V3 and all following versions, specify use of PATCH method.\r\n *\r\n * If implemented, this method wil be used instead of patch to partially update models.\r\n * Use case: You want to reuse this client and one server can only handle MERGE,\r\n * but not PATCH http requests.\r\n *\r\n * @param url\r\n * @param data\r\n * @param requestConfig\r\n */\r\n merge?<ResponseModel>(url: string, data: any, requestConfig?: RequestConfig): ODataResponse<ResponseModel>;\r\n\r\n /**\r\n * Delete a model or collection.\r\n *\r\n * @param url\r\n * @param requestConfig\r\n */\r\n delete(url: string, requestConfig?: RequestConfig): ODataResponse<void>;\r\n}\r\n"]}
@@ -1,20 +1,20 @@
1
- /**
2
- * This model represents the response for any completed HTTP request.
3
- */
4
- export interface HttpResponseModel<T> {
5
- /** status code, e.g. 200 or 404 */
6
- status: number;
7
- /** status text, e.g. 200 = "OK" or 404 = "Not Found" */
8
- statusText: string;
9
- /** response headers as key value pairs */
10
- headers: {
11
- [key: string]: string;
12
- };
13
- /** response data */
14
- data: T;
15
- }
16
- /**
17
- * Wrapping response instance, containing status code info, headers
18
- * and the response body.
19
- */
20
- export type ODataResponse<T> = Promise<HttpResponseModel<T>>;
1
+ /**
2
+ * This model represents the response for any completed HTTP request.
3
+ */
4
+ export interface HttpResponseModel<T> {
5
+ /** status code, e.g. 200 or 404 */
6
+ status: number;
7
+ /** status text, e.g. 200 = "OK" or 404 = "Not Found" */
8
+ statusText: string;
9
+ /** response headers as key value pairs */
10
+ headers: {
11
+ [key: string]: string;
12
+ };
13
+ /** response data */
14
+ data: T;
15
+ }
16
+ /**
17
+ * Wrapping response instance, containing status code info, headers
18
+ * and the response body.
19
+ */
20
+ export type ODataResponse<T> = Promise<HttpResponseModel<T>>;
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=ODataResponseModel.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ODataResponseModel.js","sourceRoot":"","sources":["../src/ODataResponseModel.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * This model represents the response for any completed HTTP request.\n */\nexport interface HttpResponseModel<T> {\n /** status code, e.g. 200 or 404 */\n status: number;\n /** status text, e.g. 200 = \"OK\" or 404 = \"Not Found\" */\n statusText: string;\n /** response headers as key value pairs */\n headers: { [key: string]: string };\n // config?: any;\n /** response data */\n data: T;\n}\n\n/**\n * Wrapping response instance, containing status code info, headers\n * and the response body.\n */\nexport type ODataResponse<T> = Promise<HttpResponseModel<T>>;\n"]}
1
+ {"version":3,"file":"ODataResponseModel.js","sourceRoot":"","sources":["../src/ODataResponseModel.ts"],"names":[],"mappings":"","sourcesContent":["/**\r\n * This model represents the response for any completed HTTP request.\r\n */\r\nexport interface HttpResponseModel<T> {\r\n /** status code, e.g. 200 or 404 */\r\n status: number;\r\n /** status text, e.g. 200 = \"OK\" or 404 = \"Not Found\" */\r\n statusText: string;\r\n /** response headers as key value pairs */\r\n headers: { [key: string]: string };\r\n // config?: any;\r\n /** response data */\r\n data: T;\r\n}\r\n\r\n/**\r\n * Wrapping response instance, containing status code info, headers\r\n * and the response body.\r\n */\r\nexport type ODataResponse<T> = Promise<HttpResponseModel<T>>;\r\n"]}
package/lib/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- export * from "./ODataResponseModel";
2
- export * from "./ODataHttpClient";
1
+ export * from "./ODataResponseModel";
2
+ export * from "./ODataHttpClient";
3
+ export * from "./ODataClientError";
package/lib/index.js CHANGED
@@ -1,6 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./ODataResponseModel"), exports);
5
- tslib_1.__exportStar(require("./ODataHttpClient"), exports);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./ODataResponseModel"), exports);
5
+ tslib_1.__exportStar(require("./ODataHttpClient"), exports);
6
+ tslib_1.__exportStar(require("./ODataClientError"), exports);
6
7
  //# 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":";;;AAAA,+DAAqC;AACrC,4DAAkC","sourcesContent":["export * from \"./ODataResponseModel\";\nexport * from \"./ODataHttpClient\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+DAAqC;AACrC,4DAAkC;AAClC,6DAAmC","sourcesContent":["export * from \"./ODataResponseModel\";\r\nexport * from \"./ODataHttpClient\";\r\nexport * from \"./ODataClientError\";\r\n"]}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@odata2ts/http-client-api",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
7
  "description": "Specifies the contract between HTTP clients and odata2ts",
8
8
  "license": "MIT",
9
- "repository": "git@github.com:odata2ts/odata2ts.git",
9
+ "repository": "git@github.com:odata2ts/http-client.git",
10
10
  "author": "texttechne",
11
11
  "main": "./lib/index.js",
12
12
  "scripts": {
@@ -31,13 +31,13 @@
31
31
  ],
32
32
  "devDependencies": {
33
33
  "@types/jest": "^27.4.1",
34
- "@types/node": "^17.0.23",
35
- "jest": "27.5.1",
36
- "rimraf": "^3.0.2",
37
- "ts-jest": "^27.1.4",
38
- "ts-node": "10.7.0",
39
- "typescript": "4.9.4"
34
+ "@types/node": "^20.2.5",
35
+ "jest": "29.5.0",
36
+ "rimraf": "^5.0.1",
37
+ "ts-jest": "^29.1.0",
38
+ "ts-node": "10.9.1",
39
+ "typescript": "5.0.4"
40
40
  },
41
41
  "types": "./lib/index.d.ts",
42
- "gitHead": "a3d6457b87ce8c9ec42772c8a5fd02b4246a2e37"
42
+ "gitHead": "485559dce9388b480c7d0b3ded2fe2f3f5f98fad"
43
43
  }