@xapi-js/adaptor-nestjs 1.4.0 → 1.4.1
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 +39 -132
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,151 +1,58 @@
|
|
|
1
|
-
# @xapi-
|
|
1
|
+
# @xapi-js/adaptor-nestjs
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
NestJS interceptors for raw or schema-typed X-API requests and responses.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
|
|
9
|
-
npm install @xapi-ts/adaptor-nestjs
|
|
10
|
-
|
|
11
|
-
# yarn
|
|
12
|
-
yarn add @xapi-ts/adaptor-nestjs
|
|
13
|
-
|
|
14
|
-
# pnpm
|
|
15
|
-
pnpm add @xapi-ts/adaptor-nestjs
|
|
16
|
-
|
|
17
|
-
# bun
|
|
18
|
-
bun add @xapi-ts/adaptor-nestjs
|
|
19
|
-
|
|
20
|
-
# deno
|
|
21
|
-
deno add @xapi-ts/adaptor-nestjs
|
|
8
|
+
pnpm add @xapi-js/core @xapi-js/adaptor-nestjs @nestjs/common rxjs
|
|
22
9
|
```
|
|
23
10
|
|
|
24
|
-
##
|
|
25
|
-
|
|
26
|
-
`@xapi-ts/adaptor-nestjs` provides NestJS interceptors to automatically handle X-API request deserialization and response serialization.
|
|
11
|
+
## Typed usage
|
|
27
12
|
|
|
28
|
-
|
|
13
|
+
```ts
|
|
14
|
+
import { Body, Controller, Post, UseInterceptors } from '@nestjs/common';
|
|
15
|
+
import { InferRoot, xapi } from '@xapi-js/core';
|
|
16
|
+
import {
|
|
17
|
+
XapiRequestInterceptor,
|
|
18
|
+
XapiResponseInterceptor,
|
|
19
|
+
} from '@xapi-js/adaptor-nestjs';
|
|
29
20
|
|
|
30
|
-
|
|
21
|
+
const requestSchema = xapi.root({
|
|
22
|
+
datasets: {
|
|
23
|
+
input: xapi.dataset({ id: xapi.int() }),
|
|
24
|
+
},
|
|
25
|
+
});
|
|
31
26
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
const responseSchema = xapi.root({
|
|
28
|
+
datasets: {
|
|
29
|
+
users: xapi.dataset({ id: xapi.int(), name: xapi.string() }),
|
|
30
|
+
},
|
|
31
|
+
});
|
|
37
32
|
|
|
38
33
|
@Controller('xapi')
|
|
39
|
-
export class
|
|
40
|
-
@Post(
|
|
41
|
-
@UseInterceptors(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
34
|
+
export class XapiController {
|
|
35
|
+
@Post()
|
|
36
|
+
@UseInterceptors(
|
|
37
|
+
new XapiRequestInterceptor(requestSchema),
|
|
38
|
+
new XapiResponseInterceptor(responseSchema),
|
|
39
|
+
)
|
|
40
|
+
handle(
|
|
41
|
+
@Body() request: InferRoot<typeof requestSchema>,
|
|
42
|
+
): InferRoot<typeof responseSchema> {
|
|
43
|
+
return {
|
|
44
|
+
parameters: {},
|
|
45
|
+
datasets: {
|
|
46
|
+
users: request.datasets.input.map(({ id }) => ({ id, name: `user-${id}` })),
|
|
47
|
+
},
|
|
48
|
+
};
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
```
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
Use `XapiResponseInterceptor` to automatically serialize `XapiRoot` objects returned from your NestJS controllers into `application/xml` responses.
|
|
55
|
-
|
|
56
|
-
```typescript
|
|
57
|
-
// app.controller.ts
|
|
58
|
-
import { Controller, Post, UseInterceptors, Body } from '@nestjs/common';
|
|
59
|
-
import { XapiRoot } from '@xapi-ts/core
|
|
60
|
-
import { XapiRequestInterceptor, XapiResponseInterceptor } from '@xapi-ts/adaptor-nestjs';
|
|
61
|
-
|
|
62
|
-
@Controller('xapi')
|
|
63
|
-
export class AppController {
|
|
64
|
-
@Post('/')
|
|
65
|
-
@UseInterceptors(XapiRequestInterceptor, XapiResponseInterceptor)
|
|
66
|
-
handleXapi(@Body() xapi: XapiRoot): XapiRoot {
|
|
67
|
-
console.log('Received XapiRoot:', xapi.parameters.get('service')?.value);
|
|
68
|
-
// Process the XapiRoot object
|
|
69
|
-
const responseXapi = new XapiRoot();
|
|
70
|
-
responseXapi.addParameter({ id: 'result', value: 'success' });
|
|
71
|
-
return responseXapi;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
```
|
|
53
|
+
Without a schema, both interceptors retain their original `XapiRoot` behavior.
|
|
75
54
|
|
|
76
55
|
---
|
|
77
56
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
이 패키지는 X-API 데이터를 위한 NestJS 어댑터를 제공합니다.
|
|
81
|
-
|
|
82
|
-
## 설치
|
|
83
|
-
|
|
84
|
-
```bash
|
|
85
|
-
# npm
|
|
86
|
-
npm install @xapi-ts/adaptor-nestjs
|
|
87
|
-
|
|
88
|
-
# yarn
|
|
89
|
-
yarn add @xapi-ts/adaptor-nestjs
|
|
90
|
-
|
|
91
|
-
# pnpm
|
|
92
|
-
pnpm add @xapi-ts/adaptor-nestjs
|
|
93
|
-
|
|
94
|
-
# bun
|
|
95
|
-
bun add @xapi-ts/adaptor-nestjs
|
|
96
|
-
|
|
97
|
-
# deno
|
|
98
|
-
deno add @xapi-ts/adaptor-nestjs
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
## 사용법
|
|
102
|
-
|
|
103
|
-
`@xapi-ts/adaptor-nestjs`는 X-API 요청 역직렬화 및 응답 직렬화를 자동으로 처리하는 NestJS 인터셉터를 제공합니다.
|
|
104
|
-
|
|
105
|
-
### XapiRequestInterceptor
|
|
106
|
-
|
|
107
|
-
들어오는 `application/xml` 요청을 `XapiRoot` 객체로 자동 구문 분석하려면 `XapiRequestInterceptor`를 사용하십시오.
|
|
108
|
-
|
|
109
|
-
```typescript
|
|
110
|
-
// app.controller.ts
|
|
111
|
-
import { Controller, Post, UseInterceptors, Body } from '@nestjs/common';
|
|
112
|
-
import { XapiRoot } from '@xapi-ts/core';
|
|
113
|
-
import { XapiRequestInterceptor } from '@xapi-ts/adaptor-nestjs';
|
|
114
|
-
|
|
115
|
-
@Controller('xapi')
|
|
116
|
-
export class AppController {
|
|
117
|
-
@Post('/')
|
|
118
|
-
@UseInterceptors(XapiRequestInterceptor)
|
|
119
|
-
handleXapi(@Body() xapi: XapiRoot): XapiRoot {
|
|
120
|
-
console.log('Received XapiRoot:', xapi.parameters.get('service')?.value);
|
|
121
|
-
// XapiRoot 객체 처리
|
|
122
|
-
const responseXapi = new XapiRoot();
|
|
123
|
-
responseXapi.addParameter({ id: 'result', value: 'success' });
|
|
124
|
-
return responseXapi;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
### XapiResponseInterceptor
|
|
130
|
-
|
|
131
|
-
NestJS 컨트롤러에서 반환된 `XapiRoot` 객체를 `application/xml` 응답으로 자동 직렬화하려면 `XapiResponseInterceptor`를 사용하십시오.
|
|
132
|
-
|
|
133
|
-
```typescript
|
|
134
|
-
// app.controller.ts
|
|
135
|
-
import { Controller, Post, UseInterceptors, Body } from '@nestjs/common';
|
|
136
|
-
import { XapiRoot } from '@xapi-ts/core
|
|
137
|
-
import { XapiRequestInterceptor, XapiResponseInterceptor } from '@xapi-ts/adaptor-nestjs';
|
|
138
|
-
|
|
139
|
-
@Controller('xapi')
|
|
140
|
-
export class AppController {
|
|
141
|
-
@Post('/')
|
|
142
|
-
@UseInterceptors(XapiRequestInterceptor, XapiResponseInterceptor)
|
|
143
|
-
handleXapi(@Body() xapi: XapiRoot): XapiRoot {
|
|
144
|
-
console.log('Received XapiRoot:', xapi.parameters.get('service')?.value);
|
|
145
|
-
// XapiRoot 객체 처리
|
|
146
|
-
const responseXapi = new XapiRoot();
|
|
147
|
-
responseXapi.addParameter({ id: 'result', value: 'success' });
|
|
148
|
-
return responseXapi;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
```
|
|
57
|
+
schema를 interceptor에 전달하면 컨트롤러 body와 반환값을 Dataset 기반
|
|
58
|
+
`XapiRoot` 대신 타입이 추론된 plain object로 사용할 수 있습니다.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xapi-js/adaptor-nestjs",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.4.
|
|
4
|
+
"version": "1.4.1",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"express": "^5.1.0",
|
|
34
34
|
"rxjs": "^7.8.1",
|
|
35
35
|
"@nestjs/common": "^10.3.10",
|
|
36
|
-
"@xapi-js/core": "1.4.
|
|
36
|
+
"@xapi-js/core": "1.4.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {},
|
|
39
39
|
"scripts": {
|