@odata2ts/http-client-api 0.1.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 ADDED
@@ -0,0 +1,10 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # 0.1.0 (2023-06-03)
7
+
8
+ ### Features
9
+
10
+ * force new minor for new http-client-api ([5628666](https://github.com/odata2ts/odata2ts/commit/56286668abf6fe5f3c0639f07a4a9f99cc549068))
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 odata2ts
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +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).
@@ -0,0 +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
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ODataHttpClient.js.map
@@ -0,0 +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"]}
@@ -0,0 +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>>;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ODataResponseModel.js.map
@@ -0,0 +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"]}
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./ODataResponseModel";
2
+ export * from "./ODataHttpClient";
package/lib/index.js ADDED
@@ -0,0 +1,6 @@
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
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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"]}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@odata2ts/http-client-api",
3
+ "version": "0.1.0",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "description": "Specifies the contract between HTTP clients and odata2ts",
8
+ "license": "MIT",
9
+ "repository": "git@github.com:odata2ts/odata2ts.git",
10
+ "author": "texttechne",
11
+ "main": "./lib/index.js",
12
+ "scripts": {
13
+ "build": "yarn clean && yarn compile",
14
+ "check-circular-deps": "madge ./src --extensions ts --circular",
15
+ "clean": "rimraf lib coverage",
16
+ "compile": "tsc",
17
+ "prepublish": "yarn build",
18
+ "test": "jest --passWithNoTests"
19
+ },
20
+ "files": [
21
+ "*.md",
22
+ "lib",
23
+ "LICENSE"
24
+ ],
25
+ "keywords": [
26
+ "http client",
27
+ "api",
28
+ "odata2ts",
29
+ "ts",
30
+ "typescript"
31
+ ],
32
+ "devDependencies": {
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"
40
+ },
41
+ "types": "./lib/index.d.ts",
42
+ "gitHead": "a3d6457b87ce8c9ec42772c8a5fd02b4246a2e37"
43
+ }