@xapi-js/adaptor-fetch 1.3.0 → 1.4.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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Robert Soriano <https://github.com/wobsoriano>
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.
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Robert Soriano <https://github.com/wobsoriano>
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 CHANGED
@@ -1,119 +1,119 @@
1
- # @xapi-ts/adaptor-fetch
2
-
3
- This package provides a Fetch API adaptor for X-API data.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- # npm
9
- npm install @xapi-ts/adaptor-fetch
10
-
11
- # yarn
12
- yarn add @xapi-ts/adaptor-fetch
13
-
14
- # pnpm
15
- pnpm add @xapi-ts/adaptor-fetch
16
-
17
- # bun
18
- bun add @xapi-ts/adaptor-fetch
19
-
20
- # deno
21
- deno add @xapi-ts/adaptor-fetch
22
- ```
23
-
24
- ## Usage
25
-
26
- Here's how to use `@xapi-ts/adaptor-fetch` to send and receive X-API data:
27
-
28
- ```typescript
29
- import { xapiFetch } from '@xapi-ts/adaptor-fetch';
30
- import { XapiRoot } from '@xapi-ts/core';
31
-
32
- async function sendXapiRequest() {
33
- const requestXapi = new XapiRoot();
34
- requestXapi.addParameter({ id: 'service', value: 'stock' });
35
- requestXapi.addParameter({ id: 'method', value: 'search' });
36
-
37
- try {
38
- const responseXapi = await xapiFetch('http://localhost:3000/api/xapi', requestXapi);
39
-
40
- // Access parameters from the response
41
- const result = responseXapi.parameters.get('result')?.value;
42
- console.log(`Result: ${result}`);
43
-
44
- // Access datasets from the response
45
- const stockDataset = responseXapi.getDataset('stockList');
46
- if (stockDataset) {
47
- console.log('Stock List:');
48
- stockDataset.rows.forEach(row => {
49
- console.log(` Code: ${row.get('stockCode')}, Price: ${row.get('currentPrice')}`);
50
- });
51
- }
52
- } catch (error) {
53
- console.error('Error sending X-API request:', error);
54
- }
55
- }
56
-
57
- sendXapiRequest();
58
- ```
59
-
60
- ---
61
-
62
- # @xapi-ts/adaptor-fetch
63
-
64
- 이 패키지는 X-API 데이터를 위한 Fetch API 어댑터를 제공합니다.
65
-
66
- ## 설치
67
-
68
- ```bash
69
- # npm
70
- npm install @xapi-ts/adaptor-fetch
71
-
72
- # yarn
73
- yarn add @xapi-ts/adaptor-fetch
74
-
75
- # pnpm
76
- pnpm add @xapi-ts/adaptor-fetch
77
-
78
- # bun
79
- bun add @xapi-ts/adaptor-fetch
80
-
81
- # deno
82
- deno add @xapi-ts/adaptor-fetch
83
- ```
84
-
85
- ## 사용법
86
-
87
- 다음은 `@xapi-ts/adaptor-fetch`를 사용하여 X-API 데이터를 송수신하는 방법입니다:
88
-
89
- ```typescript
90
- import { xapiFetch } from '@xapi-ts/adaptor-fetch';
91
- import { XapiRoot } from '@xapi-ts/core';
92
-
93
- async function sendXapiRequest() {
94
- const requestXapi = new XapiRoot();
95
- requestXapi.addParameter({ id: 'service', value: 'stock' });
96
- requestXapi.addParameter({ id: 'method', value: 'search' });
97
-
98
- try {
99
- const responseXapi = await xapiFetch('http://localhost:3000/api/xapi', requestXapi);
100
-
101
- // 응답에서 파라미터 접근
102
- const result = responseXapi.parameters.get('result')?.value;
103
- console.log(`결과: ${result}`);
104
-
105
- // 응답에서 데이터셋 접근
106
- const stockDataset = responseXapi.getDataset('stockList');
107
- if (stockDataset) {
108
- console.log('주식 목록:');
109
- stockDataset.rows.forEach(row => {
110
- console.log(` 코드: ${row.get('stockCode')}, 가격: ${row.get('currentPrice')}`);
111
- });
112
- }
113
- } catch (error) {
114
- console.error('X-API 요청 전송 오류:', error);
115
- }
116
- }
117
-
118
- sendXapiRequest();
1
+ # @xapi-ts/adaptor-fetch
2
+
3
+ This package provides a Fetch API adaptor for X-API data.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ # npm
9
+ npm install @xapi-ts/adaptor-fetch
10
+
11
+ # yarn
12
+ yarn add @xapi-ts/adaptor-fetch
13
+
14
+ # pnpm
15
+ pnpm add @xapi-ts/adaptor-fetch
16
+
17
+ # bun
18
+ bun add @xapi-ts/adaptor-fetch
19
+
20
+ # deno
21
+ deno add @xapi-ts/adaptor-fetch
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ Here's how to use `@xapi-ts/adaptor-fetch` to send and receive X-API data:
27
+
28
+ ```typescript
29
+ import { xapiFetch } from '@xapi-ts/adaptor-fetch';
30
+ import { XapiRoot } from '@xapi-ts/core';
31
+
32
+ async function sendXapiRequest() {
33
+ const requestXapi = new XapiRoot();
34
+ requestXapi.addParameter({ id: 'service', value: 'stock' });
35
+ requestXapi.addParameter({ id: 'method', value: 'search' });
36
+
37
+ try {
38
+ const responseXapi = await xapiFetch('http://localhost:3000/api/xapi', requestXapi);
39
+
40
+ // Access parameters from the response
41
+ const result = responseXapi.parameters.get('result')?.value;
42
+ console.log(`Result: ${result}`);
43
+
44
+ // Access datasets from the response
45
+ const stockDataset = responseXapi.getDataset('stockList');
46
+ if (stockDataset) {
47
+ console.log('Stock List:');
48
+ stockDataset.rows.forEach(row => {
49
+ console.log(` Code: ${row.get('stockCode')}, Price: ${row.get('currentPrice')}`);
50
+ });
51
+ }
52
+ } catch (error) {
53
+ console.error('Error sending X-API request:', error);
54
+ }
55
+ }
56
+
57
+ sendXapiRequest();
58
+ ```
59
+
60
+ ---
61
+
62
+ # @xapi-ts/adaptor-fetch
63
+
64
+ 이 패키지는 X-API 데이터를 위한 Fetch API 어댑터를 제공합니다.
65
+
66
+ ## 설치
67
+
68
+ ```bash
69
+ # npm
70
+ npm install @xapi-ts/adaptor-fetch
71
+
72
+ # yarn
73
+ yarn add @xapi-ts/adaptor-fetch
74
+
75
+ # pnpm
76
+ pnpm add @xapi-ts/adaptor-fetch
77
+
78
+ # bun
79
+ bun add @xapi-ts/adaptor-fetch
80
+
81
+ # deno
82
+ deno add @xapi-ts/adaptor-fetch
83
+ ```
84
+
85
+ ## 사용법
86
+
87
+ 다음은 `@xapi-ts/adaptor-fetch`를 사용하여 X-API 데이터를 송수신하는 방법입니다:
88
+
89
+ ```typescript
90
+ import { xapiFetch } from '@xapi-ts/adaptor-fetch';
91
+ import { XapiRoot } from '@xapi-ts/core';
92
+
93
+ async function sendXapiRequest() {
94
+ const requestXapi = new XapiRoot();
95
+ requestXapi.addParameter({ id: 'service', value: 'stock' });
96
+ requestXapi.addParameter({ id: 'method', value: 'search' });
97
+
98
+ try {
99
+ const responseXapi = await xapiFetch('http://localhost:3000/api/xapi', requestXapi);
100
+
101
+ // 응답에서 파라미터 접근
102
+ const result = responseXapi.parameters.get('result')?.value;
103
+ console.log(`결과: ${result}`);
104
+
105
+ // 응답에서 데이터셋 접근
106
+ const stockDataset = responseXapi.getDataset('stockList');
107
+ if (stockDataset) {
108
+ console.log('주식 목록:');
109
+ stockDataset.rows.forEach(row => {
110
+ console.log(` 코드: ${row.get('stockCode')}, 가격: ${row.get('currentPrice')}`);
111
+ });
112
+ }
113
+ } catch (error) {
114
+ console.error('X-API 요청 전송 오류:', error);
115
+ }
116
+ }
117
+
118
+ sendXapiRequest();
119
119
  ```
package/dist/index.cjs CHANGED
@@ -1,41 +1,11 @@
1
- //#region rolldown:runtime
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
- });
15
- }
16
- return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
- value: mod,
20
- enumerable: true
21
- }) : target, mod));
22
-
23
- //#endregion
24
- let __xapi_js_core = require("@xapi-js/core");
25
- __xapi_js_core = __toESM(__xapi_js_core);
26
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _xapi_js_core = require("@xapi-js/core");
27
3
  //#region src/index.ts
28
- /**
29
- * Sends an X-API request using the Fetch API and parses the XML response.
30
- *
31
- * @param url - The URL to send the request to.
32
- * @param xapi - The XapiRoot object to be serialized into the request body.
33
- * @param options - Optional Fetch API request initialization options.
34
- * @returns A Promise that resolves to an XapiRoot object parsed from the response.
35
- * @throws {Error} if the response body is empty.
36
- */
37
- async function xapiFetch(url, xapi, options) {
38
- const xml = (0, __xapi_js_core.write)(xapi);
4
+ async function xapiFetch(url, input, requestOrOptions, operationOptions) {
5
+ const operation = input instanceof _xapi_js_core.XapiRoot ? void 0 : input;
6
+ const requestRoot = operation ? (0, _xapi_js_core.encodeRoot)(operation.request, requestOrOptions) : input;
7
+ const options = operation ? operationOptions : requestOrOptions;
8
+ const xml = (0, _xapi_js_core.write)(requestRoot);
39
9
  const response = await fetch(url, {
40
10
  method: "POST",
41
11
  ...options,
@@ -46,8 +16,8 @@ async function xapiFetch(url, xapi, options) {
46
16
  body: xml
47
17
  });
48
18
  if (!response.body) throw new Error("Response body is empty");
49
- return (0, __xapi_js_core.parse)(await response.text());
19
+ const retRoot = (0, _xapi_js_core.parse)(await response.text());
20
+ return operation ? (0, _xapi_js_core.decodeRoot)(operation.response, retRoot) : retRoot;
50
21
  }
51
-
52
22
  //#endregion
53
- exports.xapiFetch = xapiFetch;
23
+ exports.xapiFetch = xapiFetch;
package/dist/index.d.cts CHANGED
@@ -1,7 +1,5 @@
1
- import { XapiRoot } from "@xapi-js/core";
2
-
1
+ import { RequestOf, ResponseOf, XapiOperation, XapiRoot } from "@xapi-js/core";
3
2
  //#region src/index.d.ts
4
-
5
3
  /**
6
4
  * Sends an X-API request using the Fetch API and parses the XML response.
7
5
  *
@@ -12,5 +10,6 @@ import { XapiRoot } from "@xapi-js/core";
12
10
  * @throws {Error} if the response body is empty.
13
11
  */
14
12
  declare function xapiFetch(url: string, xapi: XapiRoot, options?: RequestInit): Promise<XapiRoot>;
13
+ declare function xapiFetch<Operation extends XapiOperation>(url: string, operation: Operation, request: RequestOf<Operation>, options?: RequestInit): Promise<ResponseOf<Operation>>;
15
14
  //#endregion
16
15
  export { xapiFetch };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,5 @@
1
- import { XapiRoot } from "@xapi-js/core";
2
-
1
+ import { RequestOf, ResponseOf, XapiOperation, XapiRoot } from "@xapi-js/core";
3
2
  //#region src/index.d.ts
4
-
5
3
  /**
6
4
  * Sends an X-API request using the Fetch API and parses the XML response.
7
5
  *
@@ -12,5 +10,6 @@ import { XapiRoot } from "@xapi-js/core";
12
10
  * @throws {Error} if the response body is empty.
13
11
  */
14
12
  declare function xapiFetch(url: string, xapi: XapiRoot, options?: RequestInit): Promise<XapiRoot>;
13
+ declare function xapiFetch<Operation extends XapiOperation>(url: string, operation: Operation, request: RequestOf<Operation>, options?: RequestInit): Promise<ResponseOf<Operation>>;
15
14
  //#endregion
16
15
  export { xapiFetch };
package/dist/index.js CHANGED
@@ -1,17 +1,10 @@
1
- import { parse, write } from "@xapi-js/core";
2
-
1
+ import { XapiRoot, decodeRoot, encodeRoot, parse, write } from "@xapi-js/core";
3
2
  //#region src/index.ts
4
- /**
5
- * Sends an X-API request using the Fetch API and parses the XML response.
6
- *
7
- * @param url - The URL to send the request to.
8
- * @param xapi - The XapiRoot object to be serialized into the request body.
9
- * @param options - Optional Fetch API request initialization options.
10
- * @returns A Promise that resolves to an XapiRoot object parsed from the response.
11
- * @throws {Error} if the response body is empty.
12
- */
13
- async function xapiFetch(url, xapi, options) {
14
- const xml = write(xapi);
3
+ async function xapiFetch(url, input, requestOrOptions, operationOptions) {
4
+ const operation = input instanceof XapiRoot ? void 0 : input;
5
+ const requestRoot = operation ? encodeRoot(operation.request, requestOrOptions) : input;
6
+ const options = operation ? operationOptions : requestOrOptions;
7
+ const xml = write(requestRoot);
15
8
  const response = await fetch(url, {
16
9
  method: "POST",
17
10
  ...options,
@@ -22,8 +15,8 @@ async function xapiFetch(url, xapi, options) {
22
15
  body: xml
23
16
  });
24
17
  if (!response.body) throw new Error("Response body is empty");
25
- return parse(await response.text());
18
+ const retRoot = parse(await response.text());
19
+ return operation ? decodeRoot(operation.response, retRoot) : retRoot;
26
20
  }
27
-
28
21
  //#endregion
29
- export { xapiFetch };
22
+ export { xapiFetch };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xapi-js/adaptor-fetch",
3
3
  "type": "module",
4
- "version": "1.3.0",
4
+ "version": "1.4.0",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -30,11 +30,11 @@
30
30
  },
31
31
  "author": "Clickin <josh87786@gmail.com>",
32
32
  "dependencies": {
33
- "vitest": "^3.2.4",
34
- "@xapi-js/core": "1.3.0"
33
+ "vitest": "^4.1.10",
34
+ "@xapi-js/core": "1.4.0"
35
35
  },
36
36
  "devDependencies": {
37
- "typescript": "^5.0.0",
37
+ "typescript": "^7.0.2",
38
38
  "vitest-fetch-mock": "^0.4.5"
39
39
  },
40
40
  "scripts": {