@navios/adapter-xml 0.8.0 → 1.0.0-alpha.2
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/CHANGELOG.md +30 -0
- package/README.md +3 -13
- package/bunPlugin.cache +1 -1
- package/dist/src/adapters/xml-stream-adapter.service.d.mts.map +1 -1
- package/dist/src/decorators/xml-stream.decorator.d.mts +26 -70
- package/dist/src/decorators/xml-stream.decorator.d.mts.map +1 -1
- package/dist/src/handlers/xml-stream.d.mts +3 -5
- package/dist/src/handlers/xml-stream.d.mts.map +1 -1
- package/dist/src/types/config.d.mts +9 -5
- package/dist/src/types/config.d.mts.map +1 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/tsconfig.spec.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/vitest.config.d.mts.map +1 -1
- package/e2e/bun/xml-stream.spec.tsx +1 -18
- package/e2e/fastify/xml-stream.spec.tsx +1 -18
- package/lib/index.cjs +10 -70
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +34 -77
- package/lib/index.d.cts.map +1 -1
- package/lib/index.d.mts +33 -76
- package/lib/index.d.mts.map +1 -1
- package/lib/index.mjs +10 -70
- package/lib/index.mjs.map +1 -1
- package/package.json +9 -9
- package/src/adapters/xml-stream-adapter.service.mts +2 -5
- package/src/decorators/xml-stream.decorator.mts +92 -101
- package/src/handlers/xml-stream.mts +19 -11
- package/src/types/config.mts +19 -10
- package/vitest.config.mts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xml-stream-adapter.service.d.mts","sourceRoot":"","sources":["../../../src/adapters/xml-stream-adapter.service.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mCAAmC,EACnC,SAAS,EACT,eAAe,EACf,aAAa,EAEd,MAAM,cAAc,CAAA;AAErB,OAAO,
|
|
1
|
+
{"version":3,"file":"xml-stream-adapter.service.d.mts","sourceRoot":"","sources":["../../../src/adapters/xml-stream-adapter.service.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mCAAmC,EACnC,SAAS,EACT,eAAe,EACf,aAAa,EAEd,MAAM,cAAc,CAAA;AAErB,OAAO,EAGL,uBAAuB,EAExB,MAAM,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAK9D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBACa,uBAAwB,YAAW,mCAAmC;IACjF,sFAAsF;IACtF,SAAS,CAAC,aAAa,sCAA6B;IACpD,SAAS,CAAC,gBAAgB,0BAAkC;IAE5D;;;;;;;;;OASG;IACH,gBAAgB,CAAC,eAAe,EAAE,eAAe,CAAC,mBAAmB,CAAC;IAItE;;;;;;;;OAQG;IACH,aAAa,CACX,eAAe,EAAE,eAAe,CAAC,mBAAmB,CAAC,GACpD,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAUtB;;;;;;;OAOG;IACH,SAAS,CAAC,eAAe,EAAE,eAAe,CAAC,GAAG,CAAC,GAAG,OAAO;IAUzD;;;;;;;;;;;;;;;OAeG;IACG,cAAc,CAClB,UAAU,EAAE,SAAS,EACrB,eAAe,EAAE,eAAe,CAAC,mBAAmB,CAAC,GACpD,OAAO,CAAC,aAAa,CAAC;CAiK1B"}
|
|
@@ -1,65 +1,35 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type { BaseXmlStreamConfig } from '../types/config.mjs';
|
|
1
|
+
import type { BaseEndpointOptions, RequestArgs, Simplify, StreamHandler } from '@navios/builder';
|
|
2
|
+
import type { BaseXmlStreamConfig } from '../index.mjs';
|
|
4
3
|
/**
|
|
5
|
-
*
|
|
4
|
+
* Extracts the typed parameters for an XML stream endpoint handler function.
|
|
6
5
|
*
|
|
7
|
-
*
|
|
8
|
-
* configuration, including URL parameters, query parameters, and request body.
|
|
6
|
+
* Similar to `EndpointParams`, but specifically for XML streaming endpoints.
|
|
9
7
|
*
|
|
10
|
-
* @
|
|
11
|
-
* @template Url - The URL path pattern.
|
|
12
|
-
* @template QuerySchema - The query parameter schema type.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* const getFeed = declareXmlStream({
|
|
17
|
-
* method: 'GET',
|
|
18
|
-
* url: '/feed/:category',
|
|
19
|
-
* querySchema: z.object({ page: z.string() }),
|
|
20
|
-
* })
|
|
21
|
-
*
|
|
22
|
-
* // XmlStreamParams<typeof getFeed> resolves to:
|
|
23
|
-
* // { urlParams: { category: string }, query: { page: string } }
|
|
24
|
-
* ```
|
|
8
|
+
* @typeParam EndpointDeclaration - The XML stream endpoint declaration from @navios/builder
|
|
25
9
|
*/
|
|
26
|
-
export type XmlStreamParams<EndpointDeclaration extends
|
|
27
|
-
config: BaseXmlStreamConfig<any, any, any, any>;
|
|
28
|
-
}, Url extends string = EndpointDeclaration['config']['url'], QuerySchema = EndpointDeclaration['config']['querySchema']> = QuerySchema extends ZodObject ? EndpointDeclaration['config']['requestSchema'] extends ZodType ? Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, EndpointDeclaration['config']['requestSchema'], true>> : Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, undefined, true>> : EndpointDeclaration['config']['requestSchema'] extends ZodType ? Util_FlatObject<EndpointFunctionArgs<Url, undefined, EndpointDeclaration['config']['requestSchema'], true>> : Util_FlatObject<EndpointFunctionArgs<Url, undefined, undefined, true>>;
|
|
10
|
+
export type XmlStreamParams<EndpointDeclaration extends StreamHandler<Config, false>, Config extends BaseXmlStreamConfig = EndpointDeclaration['config']> = Simplify<RequestArgs<Config['url'], Config['querySchema'], Config['requestSchema'], Config['urlParamsSchema'], true>>;
|
|
29
11
|
/**
|
|
30
|
-
* Decorator
|
|
31
|
-
*
|
|
32
|
-
* This decorator marks controller methods that return JSX elements, which will be
|
|
33
|
-
* automatically rendered to XML and sent with the appropriate Content-Type header.
|
|
34
|
-
* The method can be async and can contain async components, class components, and
|
|
35
|
-
* regular JSX elements.
|
|
36
|
-
*
|
|
37
|
-
* @template Method - The HTTP method (GET, POST, etc.).
|
|
38
|
-
* @template Url - The URL path pattern (supports parameters like `/posts/:id`).
|
|
39
|
-
* @template QuerySchema - Optional Zod schema for query parameter validation.
|
|
40
|
-
* @template RequestSchema - Optional Zod schema for request body validation.
|
|
12
|
+
* Decorator that marks a method as an XML streaming endpoint.
|
|
41
13
|
*
|
|
42
|
-
*
|
|
43
|
-
* @
|
|
14
|
+
* Use this decorator for endpoints that stream XML data (e.g., RSS feeds, sitemaps).
|
|
15
|
+
* The endpoint must be defined using @navios/builder's `declareXmlStream` method.
|
|
16
|
+
* The method returns JSX elements, which will be automatically rendered to XML.
|
|
44
17
|
*
|
|
45
|
-
* @
|
|
46
|
-
* @
|
|
18
|
+
* @param endpoint - The XML stream endpoint declaration from @navios/builder
|
|
19
|
+
* @returns A method decorator
|
|
47
20
|
*
|
|
48
21
|
* @example
|
|
49
22
|
* ```typescript
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* const getRssFeed = declareXmlStream({
|
|
54
|
-
* method: 'GET',
|
|
23
|
+
* const getRssFeed = api.declareXmlStream({
|
|
24
|
+
* method: 'get',
|
|
55
25
|
* url: '/feed.xml',
|
|
56
26
|
* contentType: 'application/rss+xml',
|
|
57
27
|
* })
|
|
58
28
|
*
|
|
59
|
-
* @Controller(
|
|
60
|
-
* class FeedController {
|
|
29
|
+
* @Controller()
|
|
30
|
+
* export class FeedController {
|
|
61
31
|
* @XmlStream(getRssFeed)
|
|
62
|
-
* async getFeed() {
|
|
32
|
+
* async getFeed(request: XmlStreamParams<typeof getRssFeed>) {
|
|
63
33
|
* return (
|
|
64
34
|
* <rss version="2.0">
|
|
65
35
|
* <channel>
|
|
@@ -70,28 +40,14 @@ export type XmlStreamParams<EndpointDeclaration extends {
|
|
|
70
40
|
* }
|
|
71
41
|
* }
|
|
72
42
|
* ```
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* ```typescript
|
|
76
|
-
* // With query parameters
|
|
77
|
-
* const getSitemap = declareXmlStream({
|
|
78
|
-
* method: 'GET',
|
|
79
|
-
* url: '/sitemap.xml',
|
|
80
|
-
* querySchema: z.object({ page: z.string().optional() }),
|
|
81
|
-
* })
|
|
82
|
-
*
|
|
83
|
-
* @Controller()
|
|
84
|
-
* class SitemapController {
|
|
85
|
-
* @XmlStream(getSitemap)
|
|
86
|
-
* async getSitemap(params: { query?: { page?: string } }) {
|
|
87
|
-
* const page = params.query?.page
|
|
88
|
-
* return <urlset>...</urlset>
|
|
89
|
-
* }
|
|
90
|
-
* }
|
|
91
|
-
* ```
|
|
92
43
|
*/
|
|
93
|
-
export declare function XmlStream<
|
|
94
|
-
config:
|
|
95
|
-
}): (target: (params:
|
|
96
|
-
|
|
44
|
+
export declare function XmlStream<Config extends BaseEndpointOptions>(endpoint: {
|
|
45
|
+
config: Config;
|
|
46
|
+
}): (target: (params: RequestArgs<Config['url'], Config['querySchema'], Config['requestSchema'], Config['urlParamsSchema'], true>, reply: any) => any, context: ClassMethodDecoratorContext) => void;
|
|
47
|
+
export declare function XmlStream<Config extends BaseEndpointOptions>(endpoint: {
|
|
48
|
+
config: Config;
|
|
49
|
+
}): (target: (params: RequestArgs<Config['url'], Config['querySchema'], Config['requestSchema'], Config['urlParamsSchema'], true>) => any, context: ClassMethodDecoratorContext) => void;
|
|
50
|
+
export declare function XmlStream<Config extends BaseEndpointOptions>(endpoint: {
|
|
51
|
+
config: Config;
|
|
52
|
+
}): (target: () => any, context: ClassMethodDecoratorContext) => void;
|
|
97
53
|
//# sourceMappingURL=xml-stream.decorator.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xml-stream.decorator.d.mts","sourceRoot":"","sources":["../../../src/decorators/xml-stream.decorator.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"xml-stream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IAAI,CACL,KACE,GAAG,EACR,OAAO,EAAE,2BAA2B,KACjC,IAAI,CAAA;AACT,wBAAgB,SAAS,CAAC,MAAM,SAAS,mBAAmB,EAAE,QAAQ,EAAE;IACtE,MAAM,EAAE,MAAM,CAAA;CACf,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,EAAE,OAAO,EAAE,2BAA2B,KAAK,IAAI,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { StreamHandler } from '@navios/builder';
|
|
2
|
+
import type { XmlStreamConfig } from '../types/config.mjs';
|
|
3
3
|
/**
|
|
4
4
|
* Declares an XML Stream endpoint configuration for use with `@XmlStream` decorator.
|
|
5
5
|
*
|
|
@@ -39,7 +39,5 @@ import type { BaseXmlStreamConfig } from '../types/config.mjs';
|
|
|
39
39
|
* })
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
|
-
export declare function declareXmlStream<
|
|
43
|
-
config: BaseXmlStreamConfig<Method, Url, QuerySchema, RequestSchema>;
|
|
44
|
-
};
|
|
42
|
+
export declare function declareXmlStream<const Config extends XmlStreamConfig>(config: Config): StreamHandler<Config, false>;
|
|
45
43
|
//# sourceMappingURL=xml-stream.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xml-stream.d.mts","sourceRoot":"","sources":["../../../src/handlers/xml-stream.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"xml-stream.d.mts","sourceRoot":"","sources":["../../../src/handlers/xml-stream.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA2B,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAG7E,OAAO,KAAK,EAAuB,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,CAAC,MAAM,SAAS,eAAe,EACnE,MAAM,EAAE,MAAM,GACb,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC,CAc9B"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BaseEndpointOptions, HttpMethod } from '@navios/builder';
|
|
2
|
+
import type { ZodObject, ZodType } from 'zod/v4';
|
|
2
3
|
/**
|
|
3
4
|
* Configuration interface for XML Stream endpoints.
|
|
4
5
|
*
|
|
@@ -21,12 +22,15 @@ import type { BaseStreamConfig, HttpMethod } from '@navios/builder';
|
|
|
21
22
|
* }
|
|
22
23
|
* ```
|
|
23
24
|
*/
|
|
24
|
-
export interface
|
|
25
|
-
/** Content-Type header, defaults to 'application/xml' */
|
|
25
|
+
export interface XmlStreamConfig extends BaseEndpointOptions {
|
|
26
26
|
contentType?: 'application/xml' | 'text/xml' | 'application/rss+xml' | 'application/atom+xml';
|
|
27
|
-
/** Include XML declaration (<?xml version="1.0"?>) - defaults to true */
|
|
28
27
|
xmlDeclaration?: boolean;
|
|
29
|
-
/** XML encoding, defaults to 'UTF-8' */
|
|
30
28
|
encoding?: string;
|
|
31
29
|
}
|
|
30
|
+
export interface BaseXmlStreamConfig<Method extends HttpMethod = HttpMethod, Url extends string = string, QuerySchema extends ZodObject | undefined = undefined, RequestSchema extends ZodType | undefined = undefined> extends XmlStreamConfig {
|
|
31
|
+
method: Method;
|
|
32
|
+
url: Url;
|
|
33
|
+
querySchema?: QuerySchema;
|
|
34
|
+
requestSchema?: RequestSchema;
|
|
35
|
+
}
|
|
32
36
|
//# sourceMappingURL=config.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.mts","sourceRoot":"","sources":["../../../src/types/config.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"config.d.mts","sourceRoot":"","sources":["../../../src/types/config.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAEhD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,eAAgB,SAAQ,mBAAmB;IAC1D,WAAW,CAAC,EACR,iBAAiB,GACjB,UAAU,GACV,qBAAqB,GACrB,sBAAsB,CAAA;IAC1B,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,mBAAmB,CAClC,MAAM,SAAS,UAAU,GAAG,UAAU,EACtC,GAAG,SAAS,MAAM,GAAG,MAAM,EAC3B,WAAW,SAAS,SAAS,GAAG,SAAS,GAAG,SAAS,EACrD,aAAa,SAAS,OAAO,GAAG,SAAS,GAAG,SAAS,CACrD,SAAQ,eAAe;IACvB,MAAM,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,GAAG,CAAA;IACR,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,aAAa,CAAC,EAAE,aAAa,CAAA;CAC9B"}
|