@xapi-js/adaptor-nestjs 1.1.1 → 1.3.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/dist/index.cjs CHANGED
@@ -1,150 +1,83 @@
1
- "use strict";
1
+ //#region rolldown:runtime
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
6
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
8
- var __typeError = (msg) => {
9
- throw TypeError(msg);
10
- };
11
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
13
- var __export = (target, all) => {
14
- for (var name in all)
15
- __defProp(target, name, { get: all[name], enumerable: true });
16
- };
17
8
  var __copyProps = (to, from, except, desc) => {
18
- if (from && typeof from === "object" || typeof from === "function") {
19
- for (let key of __getOwnPropNames(from))
20
- if (!__hasOwnProp.call(to, key) && key !== except)
21
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
- }
23
- return to;
24
- };
25
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
- var __decoratorStart = (base) => [, , , __create(base?.[__knownSymbol("metadata")] ?? null)];
27
- var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
28
- var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
29
- var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
30
- var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
31
- var __runInitializers = (array, flags, self, value) => {
32
- for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
33
- return value;
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;
34
17
  };
35
- var __decorateElement = (array, flags, name, decorators, target, extra) => {
36
- var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
37
- var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
38
- var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
39
- var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
40
- return __privateGet(this, extra);
41
- }, set [name](x) {
42
- return __privateSet(this, extra, x);
43
- } }, name));
44
- k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
45
- for (var i = decorators.length - 1; i >= 0; i--) {
46
- ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
47
- if (k) {
48
- ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
49
- if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
50
- if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
51
- }
52
- it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
53
- if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
54
- else if (typeof it !== "object" || it === null) __typeError("Object expected");
55
- else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
56
- }
57
- return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
58
- };
59
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
60
- var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
61
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
62
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
63
- var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
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));
64
22
 
65
- // src/index.ts
66
- var index_exports = {};
67
- __export(index_exports, {
68
- XapiRequestInterceptor: () => XapiRequestInterceptor,
69
- XapiResponseInterceptor: () => XapiResponseInterceptor
70
- });
71
- module.exports = __toCommonJS(index_exports);
23
+ //#endregion
24
+ let __nestjs_common = require("@nestjs/common");
25
+ __nestjs_common = __toESM(__nestjs_common);
26
+ let __xapi_js_core = require("@xapi-js/core");
27
+ __xapi_js_core = __toESM(__xapi_js_core);
28
+ let rxjs = require("rxjs");
29
+ rxjs = __toESM(rxjs);
72
30
 
73
- // src/xapi-request-interceptor.ts
74
- var import_common = require("@nestjs/common");
75
- var import_core = require("@xapi-js/core");
76
- var _XapiRequestInterceptor_decorators, _init;
77
- _XapiRequestInterceptor_decorators = [(0, import_common.Injectable)()];
78
- var _XapiRequestInterceptor = class _XapiRequestInterceptor {
79
- constructor() {
80
- this.logger = new import_common.Logger(_XapiRequestInterceptor.name);
81
- }
82
- /**
83
- * Intercepts the incoming request to parse XML body.
84
- * If the content type is `application/xml` and a body exists, it attempts to parse the body
85
- * into an `XapiRoot` object and replaces the original request body with it.
86
- * @param context - The execution context of the request.
87
- * @param next - A `CallHandler` to invoke the next interceptor or the route handler.
88
- * @returns An `Observable` that will eventually contain the response.
89
- */
90
- async intercept(context, next) {
91
- const request = context.switchToHttp().getRequest();
92
- this.logger.debug(`XapiRequestInterceptor Intercepting request: ${request.method} ${request.url}`);
93
- if (request.headers["content-type"] === "application/xml" && request.body) {
94
- request.body = await (0, import_core.parse)(request.body);
95
- }
96
- return next.handle();
97
- }
31
+ //#region src/xapi-request-interceptor.ts
32
+ var XapiRequestInterceptor = @((0, __nestjs_common.Injectable)()) class XapiRequestInterceptor {
33
+ constructor() {
34
+ this.logger = new __nestjs_common.Logger(XapiRequestInterceptor.name);
35
+ }
36
+ /**
37
+ * Intercepts the incoming request to parse XML body.
38
+ * If the content type is `application/xml` and a body exists, it attempts to parse the body
39
+ * into an `XapiRoot` object and replaces the original request body with it.
40
+ * @param context - The execution context of the request.
41
+ * @param next - A `CallHandler` to invoke the next interceptor or the route handler.
42
+ * @returns An `Observable` that will eventually contain the response.
43
+ */
44
+ async intercept(context, next) {
45
+ const request = context.switchToHttp().getRequest();
46
+ this.logger.debug(`XapiRequestInterceptor Intercepting request: ${request.method} ${request.url}`);
47
+ if (request.headers["content-type"] === "application/xml" && request.body) request.body = await (0, __xapi_js_core.parse)(request.body);
48
+ return next.handle();
49
+ }
98
50
  };
99
- _init = __decoratorStart(null);
100
- _XapiRequestInterceptor = __decorateElement(_init, 0, "XapiRequestInterceptor", _XapiRequestInterceptor_decorators, _XapiRequestInterceptor);
101
- __runInitializers(_init, 1, _XapiRequestInterceptor);
102
- var XapiRequestInterceptor = _XapiRequestInterceptor;
103
51
 
104
- // src/xapi-response-interceptor.ts
105
- var import_common2 = require("@nestjs/common");
106
- var import_core2 = require("@xapi-js/core");
107
- var import_rxjs = require("rxjs");
108
- var _XapiResponseInterceptor_decorators, _init2;
109
- _XapiResponseInterceptor_decorators = [(0, import_common2.Injectable)()];
110
- var _XapiResponseInterceptor = class _XapiResponseInterceptor {
111
- constructor() {
112
- this.logger = new import_common2.Logger(_XapiResponseInterceptor.name);
113
- }
114
- /**
115
- * Intercepts the outgoing response to serialize XapiRoot to XML string.
116
- * If the handler returns an `XapiRoot` instance, it attempts to serialize it
117
- * into an XML string.
118
- * @param context - The execution context of the request.
119
- * @param next - A `CallHandler` to invoke the next interceptor or the route handler.
120
- * @returns An `Observable` that will eventually contain the XML string response.
121
- * @throws {Error} if the handler does not return an `XapiRoot` instance or serialization fails.
122
- */
123
- intercept(context, next) {
124
- this.logger.debug(`XapiResponseInterceptor Intercepting response`);
125
- return next.handle().pipe(
126
- (0, import_rxjs.map)(async (value) => {
127
- if (value instanceof import_core2.XapiRoot) {
128
- try {
129
- const xmlOutput = await (0, import_core2.writeString)(value);
130
- return xmlOutput;
131
- } catch (error) {
132
- this.logger.error(`Failed to serialize XapiRoot to XML string: ${error}`);
133
- throw error;
134
- }
135
- } else {
136
- throw new Error("Handler did not return an XapiRoot instance");
137
- }
138
- })
139
- );
140
- }
52
+ //#endregion
53
+ //#region src/xapi-response-interceptor.ts
54
+ var XapiResponseInterceptor = @((0, __nestjs_common.Injectable)()) class XapiResponseInterceptor {
55
+ constructor() {
56
+ this.logger = new __nestjs_common.Logger(XapiResponseInterceptor.name);
57
+ }
58
+ /**
59
+ * Intercepts the outgoing response to serialize XapiRoot to XML string.
60
+ * If the handler returns an `XapiRoot` instance, it attempts to serialize it
61
+ * into an XML string.
62
+ * @param context - The execution context of the request.
63
+ * @param next - A `CallHandler` to invoke the next interceptor or the route handler.
64
+ * @returns An `Observable` that will eventually contain the XML string response.
65
+ * @throws {Error} if the handler does not return an `XapiRoot` instance or serialization fails.
66
+ */
67
+ intercept(context, next) {
68
+ this.logger.debug(`XapiResponseInterceptor Intercepting response`);
69
+ return next.handle().pipe((0, rxjs.map)((value) => {
70
+ if ((0, __xapi_js_core.isXapiRoot)(value)) try {
71
+ return (0, __xapi_js_core.write)(value);
72
+ } catch (error) {
73
+ this.logger.error(`Failed to serialize XapiRoot to XML string: ${error}`);
74
+ throw error;
75
+ }
76
+ else throw new Error("Handler did not return an XapiRoot instance");
77
+ }));
78
+ }
141
79
  };
142
- _init2 = __decoratorStart(null);
143
- _XapiResponseInterceptor = __decorateElement(_init2, 0, "XapiResponseInterceptor", _XapiResponseInterceptor_decorators, _XapiResponseInterceptor);
144
- __runInitializers(_init2, 1, _XapiResponseInterceptor);
145
- var XapiResponseInterceptor = _XapiResponseInterceptor;
146
- // Annotate the CommonJS export names for ESM import in node:
147
- 0 && (module.exports = {
148
- XapiRequestInterceptor,
149
- XapiResponseInterceptor
150
- });
80
+
81
+ //#endregion
82
+ exports.XapiRequestInterceptor = XapiRequestInterceptor;
83
+ exports.XapiResponseInterceptor = XapiResponseInterceptor;
package/dist/index.d.cts CHANGED
@@ -1,6 +1,8 @@
1
- import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
2
- import { Observable } from 'rxjs';
3
- import { XapiRoot } from '@xapi-js/core';
1
+ import { CallHandler, ExecutionContext, NestInterceptor } from "@nestjs/common";
2
+ import { Observable } from "rxjs";
3
+ import { XapiRoot } from "@xapi-js/core";
4
+
5
+ //#region src/xapi-request-interceptor.d.ts
4
6
 
5
7
  /**
6
8
  * Interceptor that parses incoming XML request bodies into XapiRoot objects.
@@ -8,35 +10,36 @@ import { XapiRoot } from '@xapi-js/core';
8
10
  * and whose body contains X-API XML data.
9
11
  */
10
12
  declare class XapiRequestInterceptor implements NestInterceptor {
11
- private readonly logger;
12
- /**
13
- * Intercepts the incoming request to parse XML body.
14
- * If the content type is `application/xml` and a body exists, it attempts to parse the body
15
- * into an `XapiRoot` object and replaces the original request body with it.
16
- * @param context - The execution context of the request.
17
- * @param next - A `CallHandler` to invoke the next interceptor or the route handler.
18
- * @returns An `Observable` that will eventually contain the response.
19
- */
20
- intercept(context: ExecutionContext, next: CallHandler): Promise<Observable<any>>;
13
+ private readonly logger;
14
+ /**
15
+ * Intercepts the incoming request to parse XML body.
16
+ * If the content type is `application/xml` and a body exists, it attempts to parse the body
17
+ * into an `XapiRoot` object and replaces the original request body with it.
18
+ * @param context - The execution context of the request.
19
+ * @param next - A `CallHandler` to invoke the next interceptor or the route handler.
20
+ * @returns An `Observable` that will eventually contain the response.
21
+ */
22
+ intercept(context: ExecutionContext, next: CallHandler): Promise<Observable<any>>;
21
23
  }
22
-
24
+ //#endregion
25
+ //#region src/xapi-response-interceptor.d.ts
23
26
  /**
24
27
  * Interceptor that serializes XapiRoot objects returned by NestJS route handlers into XML strings.
25
28
  * This interceptor should be applied to routes that return an `XapiRoot` instance
26
29
  * and whose response should be `application/xml`.
27
30
  */
28
- declare class XapiResponseInterceptor implements NestInterceptor<XapiRoot, Promise<string>> {
29
- private readonly logger;
30
- /**
31
- * Intercepts the outgoing response to serialize XapiRoot to XML string.
32
- * If the handler returns an `XapiRoot` instance, it attempts to serialize it
33
- * into an XML string.
34
- * @param context - The execution context of the request.
35
- * @param next - A `CallHandler` to invoke the next interceptor or the route handler.
36
- * @returns An `Observable` that will eventually contain the XML string response.
37
- * @throws {Error} if the handler does not return an `XapiRoot` instance or serialization fails.
38
- */
39
- intercept(context: ExecutionContext, next: CallHandler): Observable<Promise<string>>;
31
+ declare class XapiResponseInterceptor implements NestInterceptor<XapiRoot, string> {
32
+ private readonly logger;
33
+ /**
34
+ * Intercepts the outgoing response to serialize XapiRoot to XML string.
35
+ * If the handler returns an `XapiRoot` instance, it attempts to serialize it
36
+ * into an XML string.
37
+ * @param context - The execution context of the request.
38
+ * @param next - A `CallHandler` to invoke the next interceptor or the route handler.
39
+ * @returns An `Observable` that will eventually contain the XML string response.
40
+ * @throws {Error} if the handler does not return an `XapiRoot` instance or serialization fails.
41
+ */
42
+ intercept(context: ExecutionContext, next: CallHandler): Observable<string>;
40
43
  }
41
-
42
- export { XapiRequestInterceptor, XapiResponseInterceptor };
44
+ //#endregion
45
+ export { XapiRequestInterceptor, XapiResponseInterceptor };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
2
- import { Observable } from 'rxjs';
3
- import { XapiRoot } from '@xapi-js/core';
1
+ import { CallHandler, ExecutionContext, NestInterceptor } from "@nestjs/common";
2
+ import { XapiRoot } from "@xapi-js/core";
3
+ import { Observable } from "rxjs";
4
+
5
+ //#region src/xapi-request-interceptor.d.ts
4
6
 
5
7
  /**
6
8
  * Interceptor that parses incoming XML request bodies into XapiRoot objects.
@@ -8,35 +10,36 @@ import { XapiRoot } from '@xapi-js/core';
8
10
  * and whose body contains X-API XML data.
9
11
  */
10
12
  declare class XapiRequestInterceptor implements NestInterceptor {
11
- private readonly logger;
12
- /**
13
- * Intercepts the incoming request to parse XML body.
14
- * If the content type is `application/xml` and a body exists, it attempts to parse the body
15
- * into an `XapiRoot` object and replaces the original request body with it.
16
- * @param context - The execution context of the request.
17
- * @param next - A `CallHandler` to invoke the next interceptor or the route handler.
18
- * @returns An `Observable` that will eventually contain the response.
19
- */
20
- intercept(context: ExecutionContext, next: CallHandler): Promise<Observable<any>>;
13
+ private readonly logger;
14
+ /**
15
+ * Intercepts the incoming request to parse XML body.
16
+ * If the content type is `application/xml` and a body exists, it attempts to parse the body
17
+ * into an `XapiRoot` object and replaces the original request body with it.
18
+ * @param context - The execution context of the request.
19
+ * @param next - A `CallHandler` to invoke the next interceptor or the route handler.
20
+ * @returns An `Observable` that will eventually contain the response.
21
+ */
22
+ intercept(context: ExecutionContext, next: CallHandler): Promise<Observable<any>>;
21
23
  }
22
-
24
+ //#endregion
25
+ //#region src/xapi-response-interceptor.d.ts
23
26
  /**
24
27
  * Interceptor that serializes XapiRoot objects returned by NestJS route handlers into XML strings.
25
28
  * This interceptor should be applied to routes that return an `XapiRoot` instance
26
29
  * and whose response should be `application/xml`.
27
30
  */
28
- declare class XapiResponseInterceptor implements NestInterceptor<XapiRoot, Promise<string>> {
29
- private readonly logger;
30
- /**
31
- * Intercepts the outgoing response to serialize XapiRoot to XML string.
32
- * If the handler returns an `XapiRoot` instance, it attempts to serialize it
33
- * into an XML string.
34
- * @param context - The execution context of the request.
35
- * @param next - A `CallHandler` to invoke the next interceptor or the route handler.
36
- * @returns An `Observable` that will eventually contain the XML string response.
37
- * @throws {Error} if the handler does not return an `XapiRoot` instance or serialization fails.
38
- */
39
- intercept(context: ExecutionContext, next: CallHandler): Observable<Promise<string>>;
31
+ declare class XapiResponseInterceptor implements NestInterceptor<XapiRoot, string> {
32
+ private readonly logger;
33
+ /**
34
+ * Intercepts the outgoing response to serialize XapiRoot to XML string.
35
+ * If the handler returns an `XapiRoot` instance, it attempts to serialize it
36
+ * into an XML string.
37
+ * @param context - The execution context of the request.
38
+ * @param next - A `CallHandler` to invoke the next interceptor or the route handler.
39
+ * @returns An `Observable` that will eventually contain the XML string response.
40
+ * @throws {Error} if the handler does not return an `XapiRoot` instance or serialization fails.
41
+ */
42
+ intercept(context: ExecutionContext, next: CallHandler): Observable<string>;
40
43
  }
41
-
42
- export { XapiRequestInterceptor, XapiResponseInterceptor };
44
+ //#endregion
45
+ export { XapiRequestInterceptor, XapiResponseInterceptor };
package/dist/index.js CHANGED
@@ -1,125 +1,56 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
5
- var __typeError = (msg) => {
6
- throw TypeError(msg);
7
- };
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
- var __decoratorStart = (base) => [, , , __create(base?.[__knownSymbol("metadata")] ?? null)];
11
- var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
12
- var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
13
- var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
14
- var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
15
- var __runInitializers = (array, flags, self, value) => {
16
- for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
17
- return value;
18
- };
19
- var __decorateElement = (array, flags, name, decorators, target, extra) => {
20
- var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
21
- var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
22
- var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
23
- var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
24
- return __privateGet(this, extra);
25
- }, set [name](x) {
26
- return __privateSet(this, extra, x);
27
- } }, name));
28
- k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
29
- for (var i = decorators.length - 1; i >= 0; i--) {
30
- ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
31
- if (k) {
32
- ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
33
- if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
34
- if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
35
- }
36
- it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
37
- if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
38
- else if (typeof it !== "object" || it === null) __typeError("Object expected");
39
- else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
40
- }
41
- return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
42
- };
43
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
44
- var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
45
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
46
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
47
- var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
48
-
49
- // src/xapi-request-interceptor.ts
50
1
  import { Injectable, Logger } from "@nestjs/common";
51
- import { parse } from "@xapi-js/core";
52
- var _XapiRequestInterceptor_decorators, _init;
53
- _XapiRequestInterceptor_decorators = [Injectable()];
54
- var _XapiRequestInterceptor = class _XapiRequestInterceptor {
55
- constructor() {
56
- this.logger = new Logger(_XapiRequestInterceptor.name);
57
- }
58
- /**
59
- * Intercepts the incoming request to parse XML body.
60
- * If the content type is `application/xml` and a body exists, it attempts to parse the body
61
- * into an `XapiRoot` object and replaces the original request body with it.
62
- * @param context - The execution context of the request.
63
- * @param next - A `CallHandler` to invoke the next interceptor or the route handler.
64
- * @returns An `Observable` that will eventually contain the response.
65
- */
66
- async intercept(context, next) {
67
- const request = context.switchToHttp().getRequest();
68
- this.logger.debug(`XapiRequestInterceptor Intercepting request: ${request.method} ${request.url}`);
69
- if (request.headers["content-type"] === "application/xml" && request.body) {
70
- request.body = await parse(request.body);
71
- }
72
- return next.handle();
73
- }
74
- };
75
- _init = __decoratorStart(null);
76
- _XapiRequestInterceptor = __decorateElement(_init, 0, "XapiRequestInterceptor", _XapiRequestInterceptor_decorators, _XapiRequestInterceptor);
77
- __runInitializers(_init, 1, _XapiRequestInterceptor);
78
- var XapiRequestInterceptor = _XapiRequestInterceptor;
79
-
80
- // src/xapi-response-interceptor.ts
81
- import { Injectable as Injectable2, Logger as Logger2 } from "@nestjs/common";
82
- import { XapiRoot, writeString } from "@xapi-js/core";
2
+ import { isXapiRoot, parse, write } from "@xapi-js/core";
83
3
  import { map } from "rxjs";
84
- var _XapiResponseInterceptor_decorators, _init2;
85
- _XapiResponseInterceptor_decorators = [Injectable2()];
86
- var _XapiResponseInterceptor = class _XapiResponseInterceptor {
87
- constructor() {
88
- this.logger = new Logger2(_XapiResponseInterceptor.name);
89
- }
90
- /**
91
- * Intercepts the outgoing response to serialize XapiRoot to XML string.
92
- * If the handler returns an `XapiRoot` instance, it attempts to serialize it
93
- * into an XML string.
94
- * @param context - The execution context of the request.
95
- * @param next - A `CallHandler` to invoke the next interceptor or the route handler.
96
- * @returns An `Observable` that will eventually contain the XML string response.
97
- * @throws {Error} if the handler does not return an `XapiRoot` instance or serialization fails.
98
- */
99
- intercept(context, next) {
100
- this.logger.debug(`XapiResponseInterceptor Intercepting response`);
101
- return next.handle().pipe(
102
- map(async (value) => {
103
- if (value instanceof XapiRoot) {
104
- try {
105
- const xmlOutput = await writeString(value);
106
- return xmlOutput;
107
- } catch (error) {
108
- this.logger.error(`Failed to serialize XapiRoot to XML string: ${error}`);
109
- throw error;
110
- }
111
- } else {
112
- throw new Error("Handler did not return an XapiRoot instance");
113
- }
114
- })
115
- );
116
- }
4
+
5
+ //#region src/xapi-request-interceptor.ts
6
+ var XapiRequestInterceptor = @Injectable() class XapiRequestInterceptor {
7
+ constructor() {
8
+ this.logger = new Logger(XapiRequestInterceptor.name);
9
+ }
10
+ /**
11
+ * Intercepts the incoming request to parse XML body.
12
+ * If the content type is `application/xml` and a body exists, it attempts to parse the body
13
+ * into an `XapiRoot` object and replaces the original request body with it.
14
+ * @param context - The execution context of the request.
15
+ * @param next - A `CallHandler` to invoke the next interceptor or the route handler.
16
+ * @returns An `Observable` that will eventually contain the response.
17
+ */
18
+ async intercept(context, next) {
19
+ const request = context.switchToHttp().getRequest();
20
+ this.logger.debug(`XapiRequestInterceptor Intercepting request: ${request.method} ${request.url}`);
21
+ if (request.headers["content-type"] === "application/xml" && request.body) request.body = await parse(request.body);
22
+ return next.handle();
23
+ }
117
24
  };
118
- _init2 = __decoratorStart(null);
119
- _XapiResponseInterceptor = __decorateElement(_init2, 0, "XapiResponseInterceptor", _XapiResponseInterceptor_decorators, _XapiResponseInterceptor);
120
- __runInitializers(_init2, 1, _XapiResponseInterceptor);
121
- var XapiResponseInterceptor = _XapiResponseInterceptor;
122
- export {
123
- XapiRequestInterceptor,
124
- XapiResponseInterceptor
25
+
26
+ //#endregion
27
+ //#region src/xapi-response-interceptor.ts
28
+ var XapiResponseInterceptor = @Injectable() class XapiResponseInterceptor {
29
+ constructor() {
30
+ this.logger = new Logger(XapiResponseInterceptor.name);
31
+ }
32
+ /**
33
+ * Intercepts the outgoing response to serialize XapiRoot to XML string.
34
+ * If the handler returns an `XapiRoot` instance, it attempts to serialize it
35
+ * into an XML string.
36
+ * @param context - The execution context of the request.
37
+ * @param next - A `CallHandler` to invoke the next interceptor or the route handler.
38
+ * @returns An `Observable` that will eventually contain the XML string response.
39
+ * @throws {Error} if the handler does not return an `XapiRoot` instance or serialization fails.
40
+ */
41
+ intercept(context, next) {
42
+ this.logger.debug(`XapiResponseInterceptor Intercepting response`);
43
+ return next.handle().pipe(map((value) => {
44
+ if (isXapiRoot(value)) try {
45
+ return write(value);
46
+ } catch (error) {
47
+ this.logger.error(`Failed to serialize XapiRoot to XML string: ${error}`);
48
+ throw error;
49
+ }
50
+ else throw new Error("Handler did not return an XapiRoot instance");
51
+ }));
52
+ }
125
53
  };
54
+
55
+ //#endregion
56
+ export { XapiRequestInterceptor, XapiResponseInterceptor };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xapi-js/adaptor-nestjs",
3
3
  "type": "module",
4
- "version": "1.1.1",
4
+ "version": "1.3.0",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -11,6 +11,9 @@
11
11
  "import": "./dist/index.js",
12
12
  "require": "./dist/index.cjs"
13
13
  },
14
+ "files": [
15
+ "dist"
16
+ ],
14
17
  "keywords": [
15
18
  "tobesoft",
16
19
  "x-api",
@@ -30,11 +33,11 @@
30
33
  "express": "^5.1.0",
31
34
  "rxjs": "^7.8.1",
32
35
  "@nestjs/common": "^10.3.10",
33
- "@xapi-js/core": "1.1.1"
36
+ "@xapi-js/core": "1.3.0"
34
37
  },
35
38
  "devDependencies": {},
36
39
  "scripts": {
37
- "build": "tsup src/index.ts --format cjs,esm --dts",
40
+ "build": "tsdown",
38
41
  "test": "vitest run",
39
42
  "test:watch": "vitest",
40
43
  "coverage": "vitest run --coverage"