@xapi-js/adaptor-express 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.
- package/README.md +36 -100
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,115 +1,51 @@
|
|
|
1
|
-
# @xapi-
|
|
1
|
+
# @xapi-js/adaptor-express
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Express middleware for raw or schema-typed X-API handlers.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
|
|
9
|
-
npm install @xapi-ts/adaptor-express
|
|
10
|
-
|
|
11
|
-
# yarn
|
|
12
|
-
yarn add @xapi-ts/adaptor-express
|
|
13
|
-
|
|
14
|
-
# pnpm
|
|
15
|
-
pnpm add @xapi-ts/adaptor-express
|
|
16
|
-
|
|
17
|
-
# bun
|
|
18
|
-
bun add @xapi-ts/adaptor-express
|
|
19
|
-
|
|
20
|
-
# deno
|
|
21
|
-
deno add @xapi-ts/adaptor-express
|
|
8
|
+
pnpm add @xapi-js/core @xapi-js/adaptor-express express
|
|
22
9
|
```
|
|
23
10
|
|
|
24
|
-
##
|
|
11
|
+
## Typed usage
|
|
25
12
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
```typescript
|
|
13
|
+
```ts
|
|
29
14
|
import express from 'express';
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Use the xapiExpress middleware
|
|
49
|
-
app.use('/xapi', xapiExpress(xapiHandler));
|
|
50
|
-
|
|
51
|
-
// Start the server
|
|
52
|
-
const PORT = 3000;
|
|
53
|
-
app.listen(PORT, () => {
|
|
54
|
-
console.log(`Express server listening on port ${PORT}`);
|
|
15
|
+
import { xapi } from '@xapi-js/core';
|
|
16
|
+
import { xapiExpress } from '@xapi-js/adaptor-express';
|
|
17
|
+
|
|
18
|
+
const search = xapi.operation({
|
|
19
|
+
request: xapi.root({
|
|
20
|
+
datasets: {
|
|
21
|
+
input: xapi.dataset({ id: xapi.int() }),
|
|
22
|
+
},
|
|
23
|
+
}),
|
|
24
|
+
response: xapi.root({
|
|
25
|
+
datasets: {
|
|
26
|
+
users: xapi.dataset({
|
|
27
|
+
id: xapi.int(),
|
|
28
|
+
name: xapi.string({ size: 100 }),
|
|
29
|
+
}),
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
55
32
|
});
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
---
|
|
59
|
-
|
|
60
|
-
# @xapi-ts/adaptor-express
|
|
61
|
-
|
|
62
|
-
이 패키지는 X-API 데이터를 위한 Express.js 어댑터를 제공합니다.
|
|
63
|
-
|
|
64
|
-
## 설치
|
|
65
|
-
|
|
66
|
-
```bash
|
|
67
|
-
# npm
|
|
68
|
-
npm install @xapi-ts/adaptor-express
|
|
69
|
-
|
|
70
|
-
# yarn
|
|
71
|
-
yarn add @xapi-ts/adaptor-express
|
|
72
|
-
|
|
73
|
-
# pnpm
|
|
74
|
-
pnpm add @xapi-ts/adaptor-express
|
|
75
|
-
|
|
76
|
-
# bun
|
|
77
|
-
bun add @xapi-ts/adaptor-express
|
|
78
|
-
|
|
79
|
-
# deno
|
|
80
|
-
deno add @xapi-ts/adaptor-express
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
## 사용법
|
|
84
|
-
|
|
85
|
-
다음은 Express 애플리케이션에서 `@xapi-ts/adaptor-express`를 사용하는 방법입니다:
|
|
86
|
-
|
|
87
|
-
```typescript
|
|
88
|
-
import express from 'express';
|
|
89
|
-
import { xapiExpress } from '@xapi-ts/adaptor-express';
|
|
90
|
-
import { XapiRoot } from '@xapi-ts/core';
|
|
91
33
|
|
|
92
34
|
const app = express();
|
|
35
|
+
app.use(express.text({ type: 'application/xml' }));
|
|
36
|
+
app.post('/xapi', xapiExpress(search, request => ({
|
|
37
|
+
parameters: {},
|
|
38
|
+
datasets: {
|
|
39
|
+
users: request.datasets.input.map(({ id }) => ({ id, name: `user-${id}` })),
|
|
40
|
+
},
|
|
41
|
+
})));
|
|
42
|
+
```
|
|
93
43
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
// 예를 들어, 파라미터 또는 데이터셋에 접근할 수 있습니다:
|
|
98
|
-
const service = xapi.parameters.get('service')?.value;
|
|
99
|
-
console.log(`Service requested: ${service}`);
|
|
100
|
-
|
|
101
|
-
// 응답 X-API 객체 생성
|
|
102
|
-
const responseXapi = new XapiRoot();
|
|
103
|
-
responseXapi.addParameter({ id: 'result', value: 'success' });
|
|
104
|
-
return responseXapi;
|
|
105
|
-
};
|
|
44
|
+
The handler request and response types are inferred from the operation. The
|
|
45
|
+
existing `xapiExpress(handler)` overload remains available for `XapiRoot`
|
|
46
|
+
handlers.
|
|
106
47
|
|
|
107
|
-
|
|
108
|
-
app.use('/xapi', xapiExpress(xapiHandler));
|
|
48
|
+
---
|
|
109
49
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
app.listen(PORT, () => {
|
|
113
|
-
console.log(`Express server listening on port ${PORT}`);
|
|
114
|
-
});
|
|
115
|
-
```
|
|
50
|
+
operation schema를 넘기면 Express 핸들러가 Dataset 대신 타입이 추론된 배열과
|
|
51
|
+
plain object를 직접 받고 반환합니다.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xapi-js/adaptor-express",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
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
|
"license": "MIT",
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"express": "^5.1.0",
|
|
34
|
-
"@xapi-js/core": "1.
|
|
34
|
+
"@xapi-js/core": "1.5.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/express": "^5.0.3",
|