@xapi-js/core 1.1.0 → 1.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/README.md CHANGED
@@ -1,217 +1,201 @@
1
- # @xapi-ts/core
2
-
3
- This package provides core utilities and types for working with X-API data.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- # npm
9
- npm install @xapi-ts/core
10
-
11
- # yarn
12
- yarn add @xapi-ts/core
13
-
14
- # pnpm
15
- pnpm add @xapi-ts/core
16
-
17
- # bun
18
- bun add @xapi-ts/core
19
-
20
- # deno
21
- deno add @xapi-ts/core
22
- ```
23
-
24
- ## Usage
25
-
26
- `@xapi-ts/core` provides the fundamental classes and functions for working with X-API data.
27
-
28
- ### Parsing X-API XML
29
-
30
- You can parse an X-API XML string into an `XapiRoot` object:
31
-
32
- ```typescript
33
- import { parse, XapiRoot } from '@xapi-ts/core';
34
-
35
- const xmlString = `<?xml version="1.0" encoding="UTF-8"?>
36
- <Root xmlns="http://www.tobesoft.com/platform/Dataset" ver="4000">
37
- <Parameters>
38
- <Parameter id="service">stock</Parameter>
39
- <Parameter id="method">search</Parameter>
40
- </Parameters>
41
- </Root>`;
42
-
43
- async function parseXapi() {
44
- const xapi = await parse(xmlString);
45
- console.log('Service:', xapi.getParameter('service')?.value);
46
- console.log('Method:', xapi.getParameter('method')?.value);
47
- }
48
-
49
- parseXapi();
50
- ```
51
-
52
- ### Creating and Manipulating XapiRoot
53
-
54
- You can create an `XapiRoot` object and add parameters and datasets programmatically:
55
-
56
- ```typescript
57
- import { XapiRoot, Dataset } from '@xapi-ts/core';
58
-
59
- const xapi = new XapiRoot();
60
-
61
- // Add parameters
62
- xapi.addParameter({ id: 'resultCode', value: '0' });
63
- xapi.addParameter({ id: 'resultMsg', value: 'SUCCESS' });
64
-
65
- // Create and add a dataset
66
- const usersDataset = new Dataset('users');
67
- usersDataset.addColumn({ id: 'id', type: 'INT' });
68
- usersDataset.addColumn({ id: 'name', type: 'STRING' });
69
-
70
- usersDataset.newRow();
71
- usersDataset.setColumn(0, 'id', 1);
72
- usersDataset.setColumn(0, 'name', 'Alice');
73
-
74
- usersDataset.newRow();
75
- usersDataset.setColumn(1, 'id', 2);
76
- usersDataset.setColumn(1, 'name', 'Bob');
77
-
78
- xapi.addDataset(usersDataset);
79
-
80
- console.log('XapiRoot created:', xapi);
81
- ```
82
-
83
- ### Serializing XapiRoot to XML
84
-
85
- You can serialize an `XapiRoot` object back into an X-API XML string:
86
-
87
- ```typescript
88
- import { write, XapiRoot, Dataset } from '@xapi-ts/core';
89
-
90
- const xapi = new XapiRoot();
91
- xapi.addParameter({ id: 'status', value: 'OK' });
92
-
93
- const productsDataset = new Dataset('products');
94
- productsDataset.addColumn({ id: 'productId', type: 'STRING' });
95
- productsDataset.addColumn({ id: 'price', type: 'INT' });
96
- productsDataset.newRow();
97
- productsDataset.setColumn(0, 'productId', 'P001');
98
- productsDataset.setColumn(0, 'price', 1000);
99
- xapi.addDataset(productsDataset);
100
-
101
- async function writeXapi() {
102
- const xmlOutput = await write(xapi);
103
- console.log('Generated XML:\n', xmlOutput);
104
- }
105
-
106
- writeXapi();
107
- ```
108
-
109
- ---
110
-
111
- # @xapi-ts/core
112
-
113
- 패키지는 X-API 데이터를 다루기 위한 핵심 유틸리티 및 타입을 제공합니다.
114
-
115
- ## 설치
116
-
117
- ```bash
118
- # npm
119
- npm install @xapi-ts/core
120
-
121
- # yarn
122
- yarn add @xapi-ts/core
123
-
124
- # pnpm
125
- pnpm add @xapi-ts/core
126
-
127
- # bun
128
- bun add @xapi-ts/core
129
-
130
- # deno
131
- deno add @xapi-ts/core
132
- ```
133
-
134
- ## 사용법
135
-
136
- `@xapi-ts/core`는 X-API 데이터를 다루기 위한 기본적인 클래스와 함수를 제공합니다.
137
-
138
- ### X-API XML 파싱
139
-
140
- X-API XML 문자열을 `XapiRoot` 객체로 파싱할 수 있습니다:
141
-
142
- ```typescript
143
- import { parse, XapiRoot } from '@xapi-ts/core';
144
-
145
- const xmlString = `<?xml version="1.0" encoding="UTF-8"?>
146
- <Root xmlns="http://www.tobesoft.com/platform/Dataset" ver="4000">
147
- <Parameters>
148
- <Parameter id="service">stock</Parameter>
149
- <Parameter id="method">search</Parameter>
150
- </Parameters>
151
- </Root>`;
152
-
153
- async function parseXapi() {
154
- const xapi = await parse(xmlString);
155
- console.log('서비스:', xapi.getParameter('service')?.value);
156
- console.log('메서드:', xapi.getParameter('method')?.value);
157
- }
158
-
159
- parseXapi();
160
- ```
161
-
162
- ### XapiRoot 생성 및 조작
163
-
164
- `XapiRoot` 객체를 생성하고 매개변수 및 데이터셋을 프로그래밍 방식으로 추가할 수 있습니다:
165
-
166
- ```typescript
167
- import { XapiRoot, Dataset } from '@xapi-ts/core';
168
-
169
- const xapi = new XapiRoot();
170
-
171
- // 매개변수 추가
172
- xapi.addParameter({ id: 'resultCode', value: '0' });
173
- xapi.addParameter({ id: 'resultMsg', value: 'SUCCESS' });
174
-
175
- // 데이터셋 생성 및 추가
176
- const usersDataset = new Dataset('users');
177
- usersDataset.addColumn({ id: 'id', type: 'INT' });
178
- usersDataset.addColumn({ id: 'name', type: 'STRING' });
179
- let rowIdx: number;
180
- rowIdx = usersDataset.newRow();
181
- usersDataset.setColumn(rowIdx, 'id', 1);
182
- usersDataset.setColumn(rowIdx, 'name', 'Alice');
183
-
184
- rowIdx = usersDataset.newRow();
185
- usersDataset.setColumn(rowIdx, 'id', 2);
186
- usersDataset.setColumn(rowIdx, 'name', 'Bob');
187
-
188
- xapi.addDataset(usersDataset);
189
-
190
- console.log('XapiRoot 생성됨:', xapi);
191
- ```
192
-
193
- ### XapiRoot를 XML로 직렬화
194
-
195
- `XapiRoot` 객체를 X-API XML 문자열로 다시 직렬화할 수 있습니다:
196
-
197
- ```typescript
198
- import { write, XapiRoot, Dataset } from '@xapi-ts/core';
199
-
200
- const xapi = new XapiRoot();
201
- xapi.addParameter({ id: 'status', value: 'OK' });
202
-
203
- const productsDataset = new Dataset('products');
204
- productsDataset.addColumn({ id: 'productId', type: 'STRING' });
205
- productsDataset.addColumn({ id: 'price', type: 'INT' });
206
- productsDataset.newRow();
207
- productsDataset.setColumn(0, 'productId', 'P001');
208
- productsDataset.setColumn(0, 'price', 1000);
209
- xapi.addDataset(productsDataset);
210
-
211
- async function writeXapi() {
212
- const xmlOutput = await write(xapi);
213
- console.log('생성된 XML:\n', xmlOutput);
214
- }
215
-
216
- writeXapi();
1
+ # @xapi-ts/core
2
+
3
+ This package provides core utilities and types for working with X-API data.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ # npm
9
+ npm install @xapi-ts/core
10
+
11
+ # yarn
12
+ yarn add @xapi-ts/core
13
+
14
+ # pnpm
15
+ pnpm add @xapi-ts/core
16
+
17
+ # bun
18
+ bun add @xapi-ts/core
19
+
20
+ # deno
21
+ deno add @xapi-ts/core
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ `@xapi-ts/core` provides the fundamental classes and functions for working with X-API data.
27
+
28
+ ### Parsing X-API XML
29
+
30
+ You can parse an X-API XML string into an `XapiRoot` object:
31
+
32
+ ```typescript
33
+ import { parse, XapiRoot } from '@xapi-ts/core';
34
+
35
+ const xmlString = `<?xml version="1.0" encoding="UTF-8"?>
36
+ <Root xmlns="http://www.tobesoft.com/platform/Dataset" ver="4000">
37
+ <Parameters>
38
+ <Parameter id="service">stock</Parameter>
39
+ <Parameter id="method">search</Parameter>
40
+ </Parameters>
41
+ </Root>`;
42
+
43
+ const xapi = parse(xmlString);
44
+ console.log('Service:', xapi.getParameter('service')?.value);
45
+ console.log('Method:', xapi.getParameter('method')?.value);
46
+ ```
47
+
48
+ ### Creating and Manipulating XapiRoot
49
+
50
+ You can create an `XapiRoot` object and add parameters and datasets programmatically:
51
+
52
+ ```typescript
53
+ import { XapiRoot, Dataset } from '@xapi-ts/core';
54
+
55
+ const xapi = new XapiRoot();
56
+
57
+ // Add parameters
58
+ xapi.addParameter({ id: 'resultCode', value: '0' });
59
+ xapi.addParameter({ id: 'resultMsg', value: 'SUCCESS' });
60
+
61
+ // Create and add a dataset
62
+ const usersDataset = new Dataset('users');
63
+ usersDataset.addColumn({ id: 'id', type: 'INT' });
64
+ usersDataset.addColumn({ id: 'name', type: 'STRING' });
65
+
66
+ usersDataset.newRow();
67
+ usersDataset.setColumn(0, 'id', 1);
68
+ usersDataset.setColumn(0, 'name', 'Alice');
69
+
70
+ usersDataset.newRow();
71
+ usersDataset.setColumn(1, 'id', 2);
72
+ usersDataset.setColumn(1, 'name', 'Bob');
73
+
74
+ xapi.addDataset(usersDataset);
75
+
76
+ console.log('XapiRoot created:', xapi);
77
+ ```
78
+
79
+ ### Serializing XapiRoot to XML
80
+
81
+ You can serialize an `XapiRoot` object back into an X-API XML string:
82
+
83
+ ```typescript
84
+ import { write, XapiRoot, Dataset } from '@xapi-ts/core';
85
+
86
+ const xapi = new XapiRoot();
87
+ xapi.addParameter({ id: 'status', value: 'OK' });
88
+
89
+ const productsDataset = new Dataset('products');
90
+ productsDataset.addColumn({ id: 'productId', type: 'STRING' });
91
+ productsDataset.addColumn({ id: 'price', type: 'INT' });
92
+ productsDataset.newRow();
93
+ productsDataset.setColumn(0, 'productId', 'P001');
94
+ productsDataset.setColumn(0, 'price', 1000);
95
+ xapi.addDataset(productsDataset);
96
+
97
+ const xmlOutput = write(xapi);
98
+ console.log('Generated XML:\n', xmlOutput);
99
+ ```
100
+
101
+ ---
102
+
103
+ # @xapi-ts/core
104
+
105
+ 이 패키지는 X-API 데이터를 다루기 위한 핵심 유틸리티 및 타입을 제공합니다.
106
+
107
+ ## 설치
108
+
109
+ ```bash
110
+ # npm
111
+ npm install @xapi-ts/core
112
+
113
+ # yarn
114
+ yarn add @xapi-ts/core
115
+
116
+ # pnpm
117
+ pnpm add @xapi-ts/core
118
+
119
+ # bun
120
+ bun add @xapi-ts/core
121
+
122
+ # deno
123
+ deno add @xapi-ts/core
124
+ ```
125
+
126
+ ## 사용법
127
+
128
+ `@xapi-ts/core`는 X-API 데이터를 다루기 위한 기본적인 클래스와 함수를 제공합니다.
129
+
130
+ ### X-API XML 파싱
131
+
132
+ X-API XML 문자열을 `XapiRoot` 객체로 파싱할 수 있습니다:
133
+
134
+ ```typescript
135
+ import { parse, XapiRoot } from '@xapi-ts/core';
136
+
137
+ const xmlString = `<?xml version="1.0" encoding="UTF-8"?>
138
+ <Root xmlns="http://www.tobesoft.com/platform/Dataset" ver="4000">
139
+ <Parameters>
140
+ <Parameter id="service">stock</Parameter>
141
+ <Parameter id="method">search</Parameter>
142
+ </Parameters>
143
+ </Root>`;
144
+
145
+ const xapi = parse(xmlString);
146
+ console.log('서비스:', xapi.getParameter('service')?.value);
147
+ console.log('메서드:', xapi.getParameter('method')?.value);
148
+ ```
149
+
150
+ ### XapiRoot 생성 및 조작
151
+
152
+ `XapiRoot` 객체를 생성하고 매개변수 및 데이터셋을 프로그래밍 방식으로 추가할 수 있습니다:
153
+
154
+ ```typescript
155
+ import { XapiRoot, Dataset } from '@xapi-ts/core';
156
+
157
+ const xapi = new XapiRoot();
158
+
159
+ // 매개변수 추가
160
+ xapi.addParameter({ id: 'resultCode', value: '0' });
161
+ xapi.addParameter({ id: 'resultMsg', value: 'SUCCESS' });
162
+
163
+ // 데이터셋 생성 및 추가
164
+ const usersDataset = new Dataset('users');
165
+ usersDataset.addColumn({ id: 'id', type: 'INT' });
166
+ usersDataset.addColumn({ id: 'name', type: 'STRING' });
167
+ let rowIdx: number;
168
+ rowIdx = usersDataset.newRow();
169
+ usersDataset.setColumn(rowIdx, 'id', 1);
170
+ usersDataset.setColumn(rowIdx, 'name', 'Alice');
171
+
172
+ rowIdx = usersDataset.newRow();
173
+ usersDataset.setColumn(rowIdx, 'id', 2);
174
+ usersDataset.setColumn(rowIdx, 'name', 'Bob');
175
+
176
+ xapi.addDataset(usersDataset);
177
+
178
+ console.log('XapiRoot 생성됨:', xapi);
179
+ ```
180
+
181
+ ### XapiRoot를 XML로 직렬화
182
+
183
+ `XapiRoot` 객체를 X-API XML 문자열로 다시 직렬화할 수 있습니다:
184
+
185
+ ```typescript
186
+ import { write, XapiRoot, Dataset } from '@xapi-ts/core';
187
+
188
+ const xapi = new XapiRoot();
189
+ xapi.addParameter({ id: 'status', value: 'OK' });
190
+
191
+ const productsDataset = new Dataset('products');
192
+ productsDataset.addColumn({ id: 'productId', type: 'STRING' });
193
+ productsDataset.addColumn({ id: 'price', type: 'INT' });
194
+ productsDataset.newRow();
195
+ productsDataset.setColumn(0, 'productId', 'P001');
196
+ productsDataset.setColumn(0, 'price', 1000);
197
+ xapi.addDataset(productsDataset);
198
+
199
+ const xmlOutput = write(xapi);
200
+ console.log('생성된 XML:\n', xmlOutput);
217
201
  ```