@xapi-js/adaptor-fetch 1.4.0 → 1.5.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.
Files changed (2) hide show
  1. package/README.md +44 -108
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,119 +1,55 @@
1
- # @xapi-ts/adaptor-fetch
1
+ # @xapi-js/adaptor-fetch
2
2
 
3
- This package provides a Fetch API adaptor for X-API data.
3
+ Fetch API client for raw or schema-typed X-API requests.
4
4
 
5
5
  ## Installation
6
6
 
7
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
8
+ pnpm add @xapi-js/core @xapi-js/adaptor-fetch
22
9
  ```
23
10
 
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();
11
+ ## Typed usage
12
+
13
+ ```ts
14
+ import { xapi } from '@xapi-js/core';
15
+ import { xapiFetch } from '@xapi-js/adaptor-fetch';
16
+
17
+ const search = xapi.operation({
18
+ request: xapi.root({
19
+ datasets: {
20
+ input: xapi.dataset({
21
+ id: xapi.int(),
22
+ minimumBalance: xapi.bigdecimal(),
23
+ }),
24
+ },
25
+ }),
26
+ response: xapi.root({
27
+ parameters: { ErrorCode: xapi.int() },
28
+ datasets: {
29
+ users: xapi.dataset({
30
+ id: xapi.int(),
31
+ name: xapi.string(),
32
+ balance: xapi.bigdecimal(),
33
+ }),
34
+ },
35
+ }),
36
+ });
37
+
38
+ const response = await xapiFetch('/api/users', search, {
39
+ parameters: {},
40
+ datasets: {
41
+ input: [{ id: 1, minimumBalance: 100.5 }],
42
+ },
43
+ });
44
+
45
+ response.datasets.users[0].name; // string
58
46
  ```
59
47
 
60
- ---
61
-
62
- # @xapi-ts/adaptor-fetch
63
-
64
- 이 패키지는 X-API 데이터를 위한 Fetch API 어댑터를 제공합니다.
65
-
66
- ## 설치
48
+ The operation controls both XML column metadata and the inferred request and
49
+ response types. For dynamic payloads, the existing
50
+ `xapiFetch(url, xapiRoot, options)` overload remains available.
67
51
 
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
- }
52
+ ---
117
53
 
118
- sendXapiRequest();
119
- ```
54
+ operation schema를 전달하면 요청과 응답이 plain object로 자동 변환되며,
55
+ Dataset별 변환기나 `XapiRoot` 타입 단언이 필요하지 않습니다.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xapi-js/adaptor-fetch",
3
3
  "type": "module",
4
- "version": "1.4.0",
4
+ "version": "1.5.0",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -31,7 +31,7 @@
31
31
  "author": "Clickin <josh87786@gmail.com>",
32
32
  "dependencies": {
33
33
  "vitest": "^4.1.10",
34
- "@xapi-js/core": "1.4.0"
34
+ "@xapi-js/core": "1.5.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "typescript": "^7.0.2",