@navios/adapter-xml 0.1.0 → 0.7.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/CHANGELOG.md +35 -0
- package/README.md +2 -1
- package/bun-plugin.mts +5 -3
- package/bunPlugin.cache +1 -1
- package/dist/bun-plugin.d.mts.map +1 -1
- package/dist/src/adapters/xml-stream-adapter.service.d.mts +63 -8
- package/dist/src/adapters/xml-stream-adapter.service.d.mts.map +1 -1
- package/dist/src/decorators/component.decorator.d.mts +68 -2
- package/dist/src/decorators/component.decorator.d.mts.map +1 -1
- package/dist/src/decorators/xml-stream.decorator.d.mts +58 -3
- package/dist/src/decorators/xml-stream.decorator.d.mts.map +1 -1
- package/dist/src/define-environment.d.mts +2 -2
- package/dist/src/define-environment.d.mts.map +1 -1
- package/dist/src/handlers/xml-stream.d.mts +25 -3
- package/dist/src/handlers/xml-stream.d.mts.map +1 -1
- package/dist/src/runtime/render-to-xml.d.mts +70 -2
- package/dist/src/runtime/render-to-xml.d.mts.map +1 -1
- package/dist/src/tags/define-tag.d.mts +8 -0
- package/dist/src/tags/define-tag.d.mts.map +1 -1
- package/dist/src/types/component.d.mts +46 -2
- package/dist/src/types/component.d.mts.map +1 -1
- package/dist/src/types/config.d.mts +22 -0
- 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/tsdown.config.d.mts +3 -0
- package/dist/tsdown.config.d.mts.map +1 -0
- package/dist/vitest.e2e.fastify.config.d.mts.map +1 -1
- package/lib/create-element--Gd2L8UR.d.cts +26 -0
- package/lib/create-element--Gd2L8UR.d.cts.map +1 -0
- package/lib/create-element-61MP7_99.d.mts +26 -0
- package/lib/create-element-61MP7_99.d.mts.map +1 -0
- package/lib/create-element-DiOt_-Vs.cjs +183 -0
- package/lib/create-element-DiOt_-Vs.cjs.map +1 -0
- package/lib/create-element-NZEYaRw5.mjs +124 -0
- package/lib/create-element-NZEYaRw5.mjs.map +1 -0
- package/lib/index.cjs +746 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.cts +520 -0
- package/lib/index.d.cts.map +1 -0
- package/lib/index.d.mts +520 -29
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +692 -223
- package/lib/index.mjs.map +1 -1
- package/lib/jsx-dev-runtime.cjs +11 -0
- package/lib/jsx-dev-runtime.cjs.map +1 -0
- package/lib/jsx-dev-runtime.d.cts +8 -0
- package/lib/jsx-dev-runtime.d.cts.map +1 -0
- package/lib/jsx-dev-runtime.d.mts +8 -4
- package/lib/jsx-dev-runtime.d.mts.map +1 -0
- package/lib/jsx-dev-runtime.mjs +5 -6
- package/lib/jsx-dev-runtime.mjs.map +1 -1
- package/lib/jsx-runtime.cjs +5 -0
- package/lib/jsx-runtime.d.cts +3 -0
- package/lib/jsx-runtime.d.mts +3 -3
- package/lib/jsx-runtime.mjs +3 -3
- package/lib/jsx.cjs +0 -0
- package/lib/jsx.d.cts +19 -0
- package/lib/jsx.d.cts.map +1 -0
- package/lib/jsx.d.mts +19 -1
- package/lib/jsx.d.mts.map +1 -0
- package/lib/jsx.mjs +1 -3
- package/lib/xml-node-BQA44ydQ.d.mts +96 -0
- package/lib/xml-node-BQA44ydQ.d.mts.map +1 -0
- package/lib/xml-node-CddziLym.d.cts +96 -0
- package/lib/xml-node-CddziLym.d.cts.map +1 -0
- package/package.json +20 -20
- package/project.json +2 -2
- package/src/adapters/xml-stream-adapter.service.mts +77 -16
- package/src/decorators/component.decorator.mts +72 -10
- package/src/decorators/component.decorator.spec.mts +40 -22
- package/src/decorators/xml-stream.decorator.mts +58 -3
- package/src/define-environment.mts +5 -6
- package/src/handlers/xml-stream.mts +25 -3
- package/src/runtime/render-to-xml.mts +72 -4
- package/src/tags/define-tag.mts +8 -0
- package/src/types/component.mts +46 -2
- package/src/types/config.mts +22 -0
- package/tsdown.config.mts +39 -0
- package/dist/tsup.config.d.mts +0 -3
- package/dist/tsup.config.d.mts.map +0 -1
- package/lib/_tsup-dts-rollup.d.mts +0 -414
- package/lib/_tsup-dts-rollup.d.ts +0 -414
- package/lib/chunk-6OR6LGJA.mjs +0 -153
- package/lib/chunk-6OR6LGJA.mjs.map +0 -1
- package/lib/index.d.ts +0 -29
- package/lib/index.js +0 -376
- package/lib/index.js.map +0 -1
- package/lib/jsx-dev-runtime.d.ts +0 -4
- package/lib/jsx-dev-runtime.js +0 -61
- package/lib/jsx-dev-runtime.js.map +0 -1
- package/lib/jsx-runtime.d.ts +0 -3
- package/lib/jsx-runtime.js +0 -57
- package/lib/jsx-runtime.js.map +0 -1
- package/lib/jsx-runtime.mjs.map +0 -1
- package/lib/jsx.d.ts +0 -1
- package/lib/jsx.js +0 -4
- package/lib/jsx.js.map +0 -1
- package/lib/jsx.mjs.map +0 -1
- package/tsup.config.mts +0 -18
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tsdown.config.d.mts","sourceRoot":"","sources":["../tsdown.config.mts"],"names":[],"mappings":";AAIA,wBAkCE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vitest.e2e.fastify.config.d.mts","sourceRoot":"","sources":["../vitest.e2e.fastify.config.mts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"vitest.e2e.fastify.config.d.mts","sourceRoot":"","sources":["../vitest.e2e.fastify.config.mts"],"names":[],"mappings":";AAIA,wBAwBE"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { c as Fragment, d as XmlNode, f as ComponentClass, r as AsyncXmlNode, s as ClassComponentNode } from "./xml-node-CddziLym.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/create-element.d.mts
|
|
4
|
+
type SyncComponent = (props: any) => XmlNode | AsyncXmlNode | ClassComponentNode;
|
|
5
|
+
type AsyncComponentFn = (props: any) => Promise<XmlNode | AsyncXmlNode | ClassComponentNode>;
|
|
6
|
+
type FunctionalComponent = SyncComponent | AsyncComponentFn;
|
|
7
|
+
type ComponentType = FunctionalComponent | ComponentClass;
|
|
8
|
+
/**
|
|
9
|
+
* JSX automatic runtime function.
|
|
10
|
+
* Used by the JSX transformer when jsxImportSource is set.
|
|
11
|
+
* Children are passed as part of props.children.
|
|
12
|
+
*/
|
|
13
|
+
declare function jsx(type: string | typeof Fragment | ComponentType, props: Record<string, unknown> | null): XmlNode | AsyncXmlNode | ClassComponentNode;
|
|
14
|
+
/**
|
|
15
|
+
* JSX automatic runtime function for static children.
|
|
16
|
+
* Identical to jsx() for XML - React uses this for optimization hints.
|
|
17
|
+
*/
|
|
18
|
+
declare const jsxs: typeof jsx;
|
|
19
|
+
/**
|
|
20
|
+
* Classic createElement for manual usage.
|
|
21
|
+
* Children are passed as rest arguments.
|
|
22
|
+
*/
|
|
23
|
+
declare function createElement(type: string | typeof Fragment | ComponentType, props: Record<string, unknown> | null, ...children: any[]): XmlNode | AsyncXmlNode | ClassComponentNode;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { jsx as n, jsxs as r, createElement as t };
|
|
26
|
+
//# sourceMappingURL=create-element--Gd2L8UR.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-element--Gd2L8UR.d.cts","names":[],"sources":["../src/runtime/create-element.mts"],"sourcesContent":[],"mappings":";;;AAIgF,KAE3E,aAAA,GAAa,CAAA,KAAA,EAAA,GAAA,EAAA,GAAmB,OAAnB,GAA6B,YAA7B,GAA4C,kBAA5C;KACb,gBAAA,GADgC,CAAA,KAAA,EAAA,GAAA,EAAA,GACG,OADH,CACW,OADX,GACqB,YADrB,GACoC,kBADpC,CAAA;KAEhC,mBAAA,GAAsB,aAFoB,GAEJ,gBAFI;KAG1C,aAAA,GAAgB,mBAHyC,GAGnB,cAHmB;;AAAkB;;;;AACxC,iBAmBxB,GAAA,CAnBwB,IAAA,EAAA,MAAA,GAAA,OAoBhB,QApBgB,GAoBL,aApBK,EAAA,KAAA,EAqB/B,MArB+B,CAAA,MAAA,EAAA,OAAA,CAAA,GAAA,IAAA,CAAA,EAsBrC,OAtBqC,GAsB3B,YAtB2B,GAsBZ,kBAtBY;;AAAO;AACY;AAkB3D;AACwB,cAyCX,IAzCW,EAAA,OAyCP,GAzCO;;;;;AAEI,iBA6CZ,aAAA,CA7CY,IAAA,EAAA,MAAA,GAAA,OA8CJ,QA9CI,GA8CO,aA9CP,EAAA,KAAA,EA+CnB,MA/CmB,CAAA,MAAA,EAAA,OAAA,CAAA,GAAA,IAAA,EAAA,GAAA,QAAA,EAAA,GAAA,EAAA,CAAA,EAiDzB,OAjDyB,GAiDf,YAjDe,GAiDA,kBAjDA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { c as Fragment, d as XmlNode, f as ComponentClass, r as AsyncXmlNode, s as ClassComponentNode } from "./xml-node-BQA44ydQ.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/create-element.d.mts
|
|
4
|
+
type SyncComponent = (props: any) => XmlNode | AsyncXmlNode | ClassComponentNode;
|
|
5
|
+
type AsyncComponentFn = (props: any) => Promise<XmlNode | AsyncXmlNode | ClassComponentNode>;
|
|
6
|
+
type FunctionalComponent = SyncComponent | AsyncComponentFn;
|
|
7
|
+
type ComponentType = FunctionalComponent | ComponentClass;
|
|
8
|
+
/**
|
|
9
|
+
* JSX automatic runtime function.
|
|
10
|
+
* Used by the JSX transformer when jsxImportSource is set.
|
|
11
|
+
* Children are passed as part of props.children.
|
|
12
|
+
*/
|
|
13
|
+
declare function jsx(type: string | typeof Fragment | ComponentType, props: Record<string, unknown> | null): XmlNode | AsyncXmlNode | ClassComponentNode;
|
|
14
|
+
/**
|
|
15
|
+
* JSX automatic runtime function for static children.
|
|
16
|
+
* Identical to jsx() for XML - React uses this for optimization hints.
|
|
17
|
+
*/
|
|
18
|
+
declare const jsxs: typeof jsx;
|
|
19
|
+
/**
|
|
20
|
+
* Classic createElement for manual usage.
|
|
21
|
+
* Children are passed as rest arguments.
|
|
22
|
+
*/
|
|
23
|
+
declare function createElement(type: string | typeof Fragment | ComponentType, props: Record<string, unknown> | null, ...children: any[]): XmlNode | AsyncXmlNode | ClassComponentNode;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { jsx as n, jsxs as r, createElement as t };
|
|
26
|
+
//# sourceMappingURL=create-element-61MP7_99.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-element-61MP7_99.d.mts","names":[],"sources":["../src/runtime/create-element.mts"],"sourcesContent":[],"mappings":";;;AAIgF,KAE3E,aAAA,GAAa,CAAA,KAAA,EAAA,GAAA,EAAA,GAAmB,OAAnB,GAA6B,YAA7B,GAA4C,kBAA5C;KACb,gBAAA,GADgC,CAAA,KAAA,EAAA,GAAA,EAAA,GACG,OADH,CACW,OADX,GACqB,YADrB,GACoC,kBADpC,CAAA;KAEhC,mBAAA,GAAsB,aAFoB,GAEJ,gBAFI;KAG1C,aAAA,GAAgB,mBAHyC,GAGnB,cAHmB;;AAAkB;;;;AACxC,iBAmBxB,GAAA,CAnBwB,IAAA,EAAA,MAAA,GAAA,OAoBhB,QApBgB,GAoBL,aApBK,EAAA,KAAA,EAqB/B,MArB+B,CAAA,MAAA,EAAA,OAAA,CAAA,GAAA,IAAA,CAAA,EAsBrC,OAtBqC,GAsB3B,YAtB2B,GAsBZ,kBAtBY;;AAAO;AACY;AAkB3D;AACwB,cAyCX,IAzCW,EAAA,OAyCP,GAzCO;;;;;AAEI,iBA6CZ,aAAA,CA7CY,IAAA,EAAA,MAAA,GAAA,OA8CJ,QA9CI,GA8CO,aA9CP,EAAA,KAAA,EA+CnB,MA/CmB,CAAA,MAAA,EAAA,OAAA,CAAA,GAAA,IAAA,EAAA,GAAA,QAAA,EAAA,GAAA,EAAA,CAAA,EAiDzB,OAjDyB,GAiDf,YAjDe,GAiDA,kBAjDA"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
let _navios_core = require("@navios/core");
|
|
2
|
+
|
|
3
|
+
//#region src/types/xml-node.mts
|
|
4
|
+
const Fragment = Symbol.for("xml.fragment");
|
|
5
|
+
const AsyncComponent = Symbol.for("xml.async");
|
|
6
|
+
const CDataSymbol = Symbol.for("xml.cdata");
|
|
7
|
+
const RawXmlSymbol = Symbol.for("xml.raw");
|
|
8
|
+
const ClassComponent = Symbol.for("xml.class-component");
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/decorators/component.decorator.mts
|
|
12
|
+
const ComponentMeta = Symbol.for("xml.component.meta");
|
|
13
|
+
function Component(options = {}) {
|
|
14
|
+
const { schema, registry = _navios_core.globalRegistry } = options;
|
|
15
|
+
return (target, context) => {
|
|
16
|
+
if (context && context.kind !== "class" || target instanceof Function && !context) throw new Error("[@navios/adapter-xml] @Component decorator can only be used on classes.");
|
|
17
|
+
if (typeof target.prototype.render !== "function") throw new Error(`[@navios/adapter-xml] @Component class "${target.name}" must implement render() method.`);
|
|
18
|
+
const injectableToken = schema ? _navios_core.InjectionToken.create(target, schema) : _navios_core.InjectionToken.create(target);
|
|
19
|
+
registry.set(injectableToken, _navios_core.InjectableScope.Request, target, _navios_core.InjectableType.Class);
|
|
20
|
+
target[_navios_core.InjectableTokenMeta] = injectableToken;
|
|
21
|
+
target[ComponentMeta] = true;
|
|
22
|
+
return target;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Type guard to check if a value is a component class.
|
|
27
|
+
*
|
|
28
|
+
* Component classes are classes decorated with `@Component` that implement
|
|
29
|
+
* the `XmlComponent` interface.
|
|
30
|
+
*
|
|
31
|
+
* @param value - The value to check.
|
|
32
|
+
* @returns `true` if the value is a component class, `false` otherwise.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* if (isComponentClass(MyClass)) {
|
|
37
|
+
* // MyClass is a component class
|
|
38
|
+
* const instance = await container.get(MyClass)
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/ function isComponentClass(value) {
|
|
42
|
+
return typeof value === "function" && value[ComponentMeta] === true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/runtime/create-element.mts
|
|
47
|
+
function flattenChildren(children) {
|
|
48
|
+
if (children == null || children === false) return [];
|
|
49
|
+
if (Array.isArray(children)) return children.flat(Infinity).filter((c) => c != null && c !== false);
|
|
50
|
+
return [children];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* JSX automatic runtime function.
|
|
54
|
+
* Used by the JSX transformer when jsxImportSource is set.
|
|
55
|
+
* Children are passed as part of props.children.
|
|
56
|
+
*/
|
|
57
|
+
function jsx(type, props) {
|
|
58
|
+
const { children, ...restProps } = props ?? {};
|
|
59
|
+
const flatChildren = flattenChildren(children);
|
|
60
|
+
if (isComponentClass(type)) return {
|
|
61
|
+
type: ClassComponent,
|
|
62
|
+
componentClass: type,
|
|
63
|
+
props: {
|
|
64
|
+
...restProps,
|
|
65
|
+
children: flatChildren
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
if (typeof type === "function") {
|
|
69
|
+
const result = type({
|
|
70
|
+
...restProps,
|
|
71
|
+
children: flatChildren
|
|
72
|
+
});
|
|
73
|
+
if (result instanceof Promise) return {
|
|
74
|
+
type: AsyncComponent,
|
|
75
|
+
promise: result
|
|
76
|
+
};
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
type,
|
|
81
|
+
props: restProps,
|
|
82
|
+
children: flatChildren
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* JSX automatic runtime function for static children.
|
|
87
|
+
* Identical to jsx() for XML - React uses this for optimization hints.
|
|
88
|
+
*/
|
|
89
|
+
const jsxs = jsx;
|
|
90
|
+
/**
|
|
91
|
+
* Classic createElement for manual usage.
|
|
92
|
+
* Children are passed as rest arguments.
|
|
93
|
+
*/
|
|
94
|
+
function createElement(type, props, ...children) {
|
|
95
|
+
const flatChildren = flattenChildren(children);
|
|
96
|
+
if (isComponentClass(type)) return {
|
|
97
|
+
type: ClassComponent,
|
|
98
|
+
componentClass: type,
|
|
99
|
+
props: {
|
|
100
|
+
...props,
|
|
101
|
+
children: flatChildren
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
if (typeof type === "function") {
|
|
105
|
+
const result = type({
|
|
106
|
+
...props,
|
|
107
|
+
children: flatChildren
|
|
108
|
+
});
|
|
109
|
+
if (result instanceof Promise) return {
|
|
110
|
+
type: AsyncComponent,
|
|
111
|
+
promise: result
|
|
112
|
+
};
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
type,
|
|
117
|
+
props: props ?? {},
|
|
118
|
+
children: flatChildren
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
//#endregion
|
|
123
|
+
Object.defineProperty(exports, 'AsyncComponent', {
|
|
124
|
+
enumerable: true,
|
|
125
|
+
get: function () {
|
|
126
|
+
return AsyncComponent;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
Object.defineProperty(exports, 'CDataSymbol', {
|
|
130
|
+
enumerable: true,
|
|
131
|
+
get: function () {
|
|
132
|
+
return CDataSymbol;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
Object.defineProperty(exports, 'ClassComponent', {
|
|
136
|
+
enumerable: true,
|
|
137
|
+
get: function () {
|
|
138
|
+
return ClassComponent;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
Object.defineProperty(exports, 'Component', {
|
|
142
|
+
enumerable: true,
|
|
143
|
+
get: function () {
|
|
144
|
+
return Component;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
Object.defineProperty(exports, 'Fragment', {
|
|
148
|
+
enumerable: true,
|
|
149
|
+
get: function () {
|
|
150
|
+
return Fragment;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
Object.defineProperty(exports, 'RawXmlSymbol', {
|
|
154
|
+
enumerable: true,
|
|
155
|
+
get: function () {
|
|
156
|
+
return RawXmlSymbol;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
Object.defineProperty(exports, 'createElement', {
|
|
160
|
+
enumerable: true,
|
|
161
|
+
get: function () {
|
|
162
|
+
return createElement;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
Object.defineProperty(exports, 'isComponentClass', {
|
|
166
|
+
enumerable: true,
|
|
167
|
+
get: function () {
|
|
168
|
+
return isComponentClass;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
Object.defineProperty(exports, 'jsx', {
|
|
172
|
+
enumerable: true,
|
|
173
|
+
get: function () {
|
|
174
|
+
return jsx;
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
Object.defineProperty(exports, 'jsxs', {
|
|
178
|
+
enumerable: true,
|
|
179
|
+
get: function () {
|
|
180
|
+
return jsxs;
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
//# sourceMappingURL=create-element-DiOt_-Vs.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-element-DiOt_-Vs.cjs","names":["globalRegistry","InjectableScope","InjectableTokenMeta","InjectableType","InjectionToken","ComponentMeta","Symbol","for","Component","options","schema","registry","target","context","kind","Function","Error","prototype","render","name","injectableToken","create","set","Request","Class","isComponentClass","value"],"sources":["../src/types/xml-node.mts","../src/decorators/component.decorator.mts","../src/runtime/create-element.mts"],"sourcesContent":["import type { ComponentClass } from './component.mjs'\n\nexport const Fragment = Symbol.for('xml.fragment')\nexport const AsyncComponent = Symbol.for('xml.async')\nexport const CDataSymbol = Symbol.for('xml.cdata')\nexport const RawXmlSymbol = Symbol.for('xml.raw')\nexport const ClassComponent = Symbol.for('xml.class-component')\n\n/** Represents a CDATA section - content is wrapped in <![CDATA[...]]> */\nexport interface CDataNode {\n type: typeof CDataSymbol\n content: string\n}\n\n/** Represents raw XML content - inserted without any escaping or wrapping */\nexport interface RawXmlNode {\n type: typeof RawXmlSymbol\n content: string\n}\n\n/** Represents a class component that needs to be resolved via DI */\nexport interface ClassComponentNode {\n type: typeof ClassComponent\n componentClass: ComponentClass\n props: Record<string, unknown>\n}\n\nexport interface XmlNode {\n type: string | typeof Fragment\n props: Record<string, unknown>\n children: AnyXmlNode[]\n}\n\n/** Represents an async component that needs to be resolved before rendering */\nexport interface AsyncXmlNode {\n type: typeof AsyncComponent\n promise: Promise<AnyXmlNode>\n}\n\n/** Union type for all possible node types */\nexport type AnyXmlNode =\n | XmlNode\n | AsyncXmlNode\n | CDataNode\n | RawXmlNode\n | ClassComponentNode\n | string\n | number\n | null\n | undefined\n","import type { Registry } from '@navios/core'\nimport type { z, ZodObject, ZodRawShape } from 'zod/v4'\n\nimport {\n globalRegistry,\n InjectableScope,\n InjectableTokenMeta,\n InjectableType,\n InjectionToken,\n} from '@navios/core'\n\nimport type { ComponentClass, XmlComponent } from '../types/component.mjs'\n\nexport const ComponentMeta = Symbol.for('xml.component.meta')\n\n/**\n * Decorator for class-based XML components with dependency injection support.\n *\n * Class components must implement the `XmlComponent` interface with a `render()` method.\n * They can optionally accept props via constructor, validated with a Zod schema.\n *\n * @overload\n * Component without props (no schema).\n *\n * @example\n * ```tsx\n * @Component()\n * class LatestPostsComponent implements XmlComponent {\n * private readonly postService = inject(PostService)\n *\n * async render() {\n * const posts = await this.postService.getLatestPosts()\n * return <>{posts.map(post => <item>...</item>)}</>\n * }\n * }\n * ```\n *\n * @overload\n * Component with props schema for type-safe props.\n *\n * @param options - Configuration object with schema and optional registry.\n * @param options.schema - Zod schema for validating and typing component props.\n * @param options.registry - Optional custom DI registry (defaults to global registry).\n *\n * @example\n * ```tsx\n * const DescriptionSchema = z.object({\n * content: z.string(),\n * wrapInCData: z.boolean().optional(),\n * })\n *\n * @Component({ schema: DescriptionSchema })\n * class DescriptionComponent implements XmlComponent {\n * constructor(private props: z.output<typeof DescriptionSchema>) {}\n *\n * async render() {\n * return <description>{this.props.wrapInCData ? <CData>{this.props.content}</CData> : this.props.content}</description>\n * }\n * }\n * ```\n *\n * @overload\n * Component with custom registry only (no props).\n *\n * @param options - Configuration object with registry.\n * @param options.registry - Custom DI registry to use for this component.\n */\n// #1 Component without props (no schema)\nexport function Component(): <T extends ComponentClass>(\n target: T,\n context?: ClassDecoratorContext,\n) => T\n\n// #2 Component with props schema\nexport function Component<Schema extends ZodObject<ZodRawShape>>(options: {\n schema: Schema\n registry?: Registry\n}): <T extends new (props: z.output<Schema>, ...args: any[]) => XmlComponent>(\n target: T,\n context?: ClassDecoratorContext,\n) => T\n\n// #3 Component with custom registry only\nexport function Component(options: {\n registry: Registry\n}): <T extends ComponentClass>(target: T, context?: ClassDecoratorContext) => T\n\nexport function Component(\n options: {\n schema?: ZodObject<ZodRawShape>\n registry?: Registry\n } = {},\n) {\n const { schema, registry = globalRegistry } = options\n\n return <T extends ComponentClass>(\n target: T,\n context?: ClassDecoratorContext,\n ): T => {\n if (\n (context && context.kind !== 'class') ||\n (target instanceof Function && !context)\n ) {\n throw new Error(\n '[@navios/adapter-xml] @Component decorator can only be used on classes.',\n )\n }\n\n // Verify the class has a render method\n if (typeof target.prototype.render !== 'function') {\n throw new Error(\n `[@navios/adapter-xml] @Component class \"${target.name}\" must implement render() method.`,\n )\n }\n\n // Create token with schema if provided\n const injectableToken = schema\n ? InjectionToken.create(target, schema)\n : InjectionToken.create(target)\n\n // Register with Request scope - each render gets fresh instances\n registry.set(\n injectableToken,\n InjectableScope.Request,\n target,\n InjectableType.Class,\n )\n\n // Store token metadata on the class (same pattern as @Injectable)\n // @ts-expect-error - Adding metadata to class\n target[InjectableTokenMeta] = injectableToken\n\n // Mark as component for JSX runtime detection\n // @ts-expect-error - Adding metadata to class\n target[ComponentMeta] = true\n\n return target\n }\n}\n\n/**\n * Type guard to check if a value is a component class.\n *\n * Component classes are classes decorated with `@Component` that implement\n * the `XmlComponent` interface.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a component class, `false` otherwise.\n *\n * @example\n * ```ts\n * if (isComponentClass(MyClass)) {\n * // MyClass is a component class\n * const instance = await container.get(MyClass)\n * }\n * ```\n */\nexport function isComponentClass(value: unknown): value is ComponentClass {\n return (\n typeof value === 'function' &&\n // @ts-expect-error - Checking metadata\n value[ComponentMeta] === true\n )\n}\n","import type { AnyXmlNode, AsyncXmlNode, ClassComponentNode, XmlNode } from '../types/xml-node.mjs'\nimport type { ComponentClass } from '../types/component.mjs'\n\nimport { isComponentClass } from '../decorators/component.decorator.mjs'\nimport { AsyncComponent, ClassComponent, Fragment } from '../types/xml-node.mjs'\n\ntype SyncComponent = (props: any) => XmlNode | AsyncXmlNode | ClassComponentNode\ntype AsyncComponentFn = (props: any) => Promise<XmlNode | AsyncXmlNode | ClassComponentNode>\ntype FunctionalComponent = SyncComponent | AsyncComponentFn\ntype ComponentType = FunctionalComponent | ComponentClass\n\nfunction flattenChildren(children: any): AnyXmlNode[] {\n if (children == null || children === false) {\n return []\n }\n if (Array.isArray(children)) {\n return children.flat(Infinity).filter((c) => c != null && c !== false)\n }\n return [children]\n}\n\n/**\n * JSX automatic runtime function.\n * Used by the JSX transformer when jsxImportSource is set.\n * Children are passed as part of props.children.\n */\nexport function jsx(\n type: string | typeof Fragment | ComponentType,\n props: Record<string, unknown> | null,\n): XmlNode | AsyncXmlNode | ClassComponentNode {\n const { children, ...restProps } = props ?? {}\n const flatChildren = flattenChildren(children)\n\n // Handle class components - create ClassComponentNode for later resolution\n if (isComponentClass(type)) {\n return {\n type: ClassComponent,\n componentClass: type,\n props: { ...restProps, children: flatChildren },\n }\n }\n\n // Handle function components (sync or async)\n if (typeof type === 'function') {\n const result = type({ ...restProps, children: flatChildren })\n\n // If component returns a Promise, wrap it in AsyncXmlNode\n if (result instanceof Promise) {\n return {\n type: AsyncComponent,\n promise: result,\n }\n }\n\n return result\n }\n\n return {\n type,\n props: restProps,\n children: flatChildren,\n }\n}\n\n/**\n * JSX automatic runtime function for static children.\n * Identical to jsx() for XML - React uses this for optimization hints.\n */\nexport const jsxs = jsx\n\n/**\n * Classic createElement for manual usage.\n * Children are passed as rest arguments.\n */\nexport function createElement(\n type: string | typeof Fragment | ComponentType,\n props: Record<string, unknown> | null,\n ...children: any[]\n): XmlNode | AsyncXmlNode | ClassComponentNode {\n const flatChildren = flattenChildren(children)\n\n // Handle class components - create ClassComponentNode for later resolution\n if (isComponentClass(type)) {\n return {\n type: ClassComponent,\n componentClass: type,\n props: { ...props, children: flatChildren },\n }\n }\n\n // Handle function components (sync or async)\n if (typeof type === 'function') {\n const result = type({ ...props, children: flatChildren })\n\n // If component returns a Promise, wrap it in AsyncXmlNode\n if (result instanceof Promise) {\n return {\n type: AsyncComponent,\n promise: result,\n }\n }\n\n return result\n }\n\n return {\n type,\n props: props ?? {},\n children: flatChildren,\n }\n}\n\nexport { Fragment }\n"],"mappings":";;;AAEA,MAAa,WAAW,OAAO,IAAI,eAAe;AAClD,MAAa,iBAAiB,OAAO,IAAI,YAAY;AACrD,MAAa,cAAc,OAAO,IAAI,YAAY;AAClD,MAAa,eAAe,OAAO,IAAI,UAAU;AACjD,MAAa,iBAAiB,OAAO,IAAI,sBAAsB;;;;ACO/D,MAAaK,gBAAgBC,OAAOC,IAAI,qBAAA;AA0ExC,SAAgBC,UACdC,UAGI,EAAE,EAAA;CAEN,MAAM,EAAEC,QAAQC,WAAWX,gCAAmBS;AAE9C,SACEG,QACAC,YAAAA;AAEA,MACE,WAAYA,QAAQC,SAAS,WAC5BF,kBAAkBG,YAAY,CAACF,QAEhC,OAAM,IAAIG,MACR,0EAAA;AAKJ,MAAI,OAAOJ,OAAOK,UAAUC,WAAW,WACrC,OAAM,IAAIF,MACR,2CAA2CJ,OAAOO,KAAK,mCAAkC;EAK7F,MAAMC,kBAAkBV,SACpBN,4BAAeiB,OAAOT,QAAQF,OAAAA,GAC9BN,4BAAeiB,OAAOT,OAAAA;AAG1BD,WAASW,IACPF,iBACAnB,6BAAgBsB,SAChBX,QACAT,4BAAeqB,MAAK;AAKtBZ,SAAOV,oCAAuBkB;AAI9BR,SAAOP,iBAAiB;AAExB,SAAOO;;;;;;;;;;;;;;;;;;;GAqBX,SAAgBa,iBAAiBC,OAAc;AAC7C,QACE,OAAOA,UAAU,cAEjBA,MAAMrB,mBAAmB;;;;;ACtJ7B,SAAS,gBAAgB,UAA6B;AACpD,KAAI,YAAY,QAAQ,aAAa,MACnC,QAAO,EAAE;AAEX,KAAI,MAAM,QAAQ,SAAS,CACzB,QAAO,SAAS,KAAK,SAAS,CAAC,QAAQ,MAAM,KAAK,QAAQ,MAAM,MAAM;AAExE,QAAO,CAAC,SAAS;;;;;;;AAQnB,SAAgB,IACd,MACA,OAC6C;CAC7C,MAAM,EAAE,UAAU,GAAG,cAAc,SAAS,EAAE;CAC9C,MAAM,eAAe,gBAAgB,SAAS;AAG9C,KAAI,iBAAiB,KAAK,CACxB,QAAO;EACL,MAAM;EACN,gBAAgB;EAChB,OAAO;GAAE,GAAG;GAAW,UAAU;GAAc;EAChD;AAIH,KAAI,OAAO,SAAS,YAAY;EAC9B,MAAM,SAAS,KAAK;GAAE,GAAG;GAAW,UAAU;GAAc,CAAC;AAG7D,MAAI,kBAAkB,QACpB,QAAO;GACL,MAAM;GACN,SAAS;GACV;AAGH,SAAO;;AAGT,QAAO;EACL;EACA,OAAO;EACP,UAAU;EACX;;;;;;AAOH,MAAa,OAAO;;;;;AAMpB,SAAgB,cACd,MACA,OACA,GAAG,UAC0C;CAC7C,MAAM,eAAe,gBAAgB,SAAS;AAG9C,KAAI,iBAAiB,KAAK,CACxB,QAAO;EACL,MAAM;EACN,gBAAgB;EAChB,OAAO;GAAE,GAAG;GAAO,UAAU;GAAc;EAC5C;AAIH,KAAI,OAAO,SAAS,YAAY;EAC9B,MAAM,SAAS,KAAK;GAAE,GAAG;GAAO,UAAU;GAAc,CAAC;AAGzD,MAAI,kBAAkB,QACpB,QAAO;GACL,MAAM;GACN,SAAS;GACV;AAGH,SAAO;;AAGT,QAAO;EACL;EACA,OAAO,SAAS,EAAE;EAClB,UAAU;EACX"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { InjectableScope, InjectableTokenMeta, InjectableType, InjectionToken, globalRegistry } from "@navios/core";
|
|
2
|
+
|
|
3
|
+
//#region src/types/xml-node.mts
|
|
4
|
+
const Fragment = Symbol.for("xml.fragment");
|
|
5
|
+
const AsyncComponent = Symbol.for("xml.async");
|
|
6
|
+
const CDataSymbol = Symbol.for("xml.cdata");
|
|
7
|
+
const RawXmlSymbol = Symbol.for("xml.raw");
|
|
8
|
+
const ClassComponent = Symbol.for("xml.class-component");
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/decorators/component.decorator.mts
|
|
12
|
+
const ComponentMeta = Symbol.for("xml.component.meta");
|
|
13
|
+
function Component(options = {}) {
|
|
14
|
+
const { schema, registry = globalRegistry } = options;
|
|
15
|
+
return (target, context) => {
|
|
16
|
+
if (context && context.kind !== "class" || target instanceof Function && !context) throw new Error("[@navios/adapter-xml] @Component decorator can only be used on classes.");
|
|
17
|
+
if (typeof target.prototype.render !== "function") throw new Error(`[@navios/adapter-xml] @Component class "${target.name}" must implement render() method.`);
|
|
18
|
+
const injectableToken = schema ? InjectionToken.create(target, schema) : InjectionToken.create(target);
|
|
19
|
+
registry.set(injectableToken, InjectableScope.Request, target, InjectableType.Class);
|
|
20
|
+
target[InjectableTokenMeta] = injectableToken;
|
|
21
|
+
target[ComponentMeta] = true;
|
|
22
|
+
return target;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Type guard to check if a value is a component class.
|
|
27
|
+
*
|
|
28
|
+
* Component classes are classes decorated with `@Component` that implement
|
|
29
|
+
* the `XmlComponent` interface.
|
|
30
|
+
*
|
|
31
|
+
* @param value - The value to check.
|
|
32
|
+
* @returns `true` if the value is a component class, `false` otherwise.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* if (isComponentClass(MyClass)) {
|
|
37
|
+
* // MyClass is a component class
|
|
38
|
+
* const instance = await container.get(MyClass)
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/ function isComponentClass(value) {
|
|
42
|
+
return typeof value === "function" && value[ComponentMeta] === true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/runtime/create-element.mts
|
|
47
|
+
function flattenChildren(children) {
|
|
48
|
+
if (children == null || children === false) return [];
|
|
49
|
+
if (Array.isArray(children)) return children.flat(Infinity).filter((c) => c != null && c !== false);
|
|
50
|
+
return [children];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* JSX automatic runtime function.
|
|
54
|
+
* Used by the JSX transformer when jsxImportSource is set.
|
|
55
|
+
* Children are passed as part of props.children.
|
|
56
|
+
*/
|
|
57
|
+
function jsx(type, props) {
|
|
58
|
+
const { children, ...restProps } = props ?? {};
|
|
59
|
+
const flatChildren = flattenChildren(children);
|
|
60
|
+
if (isComponentClass(type)) return {
|
|
61
|
+
type: ClassComponent,
|
|
62
|
+
componentClass: type,
|
|
63
|
+
props: {
|
|
64
|
+
...restProps,
|
|
65
|
+
children: flatChildren
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
if (typeof type === "function") {
|
|
69
|
+
const result = type({
|
|
70
|
+
...restProps,
|
|
71
|
+
children: flatChildren
|
|
72
|
+
});
|
|
73
|
+
if (result instanceof Promise) return {
|
|
74
|
+
type: AsyncComponent,
|
|
75
|
+
promise: result
|
|
76
|
+
};
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
type,
|
|
81
|
+
props: restProps,
|
|
82
|
+
children: flatChildren
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* JSX automatic runtime function for static children.
|
|
87
|
+
* Identical to jsx() for XML - React uses this for optimization hints.
|
|
88
|
+
*/
|
|
89
|
+
const jsxs = jsx;
|
|
90
|
+
/**
|
|
91
|
+
* Classic createElement for manual usage.
|
|
92
|
+
* Children are passed as rest arguments.
|
|
93
|
+
*/
|
|
94
|
+
function createElement(type, props, ...children) {
|
|
95
|
+
const flatChildren = flattenChildren(children);
|
|
96
|
+
if (isComponentClass(type)) return {
|
|
97
|
+
type: ClassComponent,
|
|
98
|
+
componentClass: type,
|
|
99
|
+
props: {
|
|
100
|
+
...props,
|
|
101
|
+
children: flatChildren
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
if (typeof type === "function") {
|
|
105
|
+
const result = type({
|
|
106
|
+
...props,
|
|
107
|
+
children: flatChildren
|
|
108
|
+
});
|
|
109
|
+
if (result instanceof Promise) return {
|
|
110
|
+
type: AsyncComponent,
|
|
111
|
+
promise: result
|
|
112
|
+
};
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
type,
|
|
117
|
+
props: props ?? {},
|
|
118
|
+
children: flatChildren
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
//#endregion
|
|
123
|
+
export { isComponentClass as a, ClassComponent as c, Component as i, Fragment as l, jsx as n, AsyncComponent as o, jsxs as r, CDataSymbol as s, createElement as t, RawXmlSymbol as u };
|
|
124
|
+
//# sourceMappingURL=create-element-NZEYaRw5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-element-NZEYaRw5.mjs","names":["globalRegistry","InjectableScope","InjectableTokenMeta","InjectableType","InjectionToken","ComponentMeta","Symbol","for","Component","options","schema","registry","target","context","kind","Function","Error","prototype","render","name","injectableToken","create","set","Request","Class","isComponentClass","value"],"sources":["../src/types/xml-node.mts","../src/decorators/component.decorator.mts","../src/runtime/create-element.mts"],"sourcesContent":["import type { ComponentClass } from './component.mjs'\n\nexport const Fragment = Symbol.for('xml.fragment')\nexport const AsyncComponent = Symbol.for('xml.async')\nexport const CDataSymbol = Symbol.for('xml.cdata')\nexport const RawXmlSymbol = Symbol.for('xml.raw')\nexport const ClassComponent = Symbol.for('xml.class-component')\n\n/** Represents a CDATA section - content is wrapped in <![CDATA[...]]> */\nexport interface CDataNode {\n type: typeof CDataSymbol\n content: string\n}\n\n/** Represents raw XML content - inserted without any escaping or wrapping */\nexport interface RawXmlNode {\n type: typeof RawXmlSymbol\n content: string\n}\n\n/** Represents a class component that needs to be resolved via DI */\nexport interface ClassComponentNode {\n type: typeof ClassComponent\n componentClass: ComponentClass\n props: Record<string, unknown>\n}\n\nexport interface XmlNode {\n type: string | typeof Fragment\n props: Record<string, unknown>\n children: AnyXmlNode[]\n}\n\n/** Represents an async component that needs to be resolved before rendering */\nexport interface AsyncXmlNode {\n type: typeof AsyncComponent\n promise: Promise<AnyXmlNode>\n}\n\n/** Union type for all possible node types */\nexport type AnyXmlNode =\n | XmlNode\n | AsyncXmlNode\n | CDataNode\n | RawXmlNode\n | ClassComponentNode\n | string\n | number\n | null\n | undefined\n","import type { Registry } from '@navios/core'\nimport type { z, ZodObject, ZodRawShape } from 'zod/v4'\n\nimport {\n globalRegistry,\n InjectableScope,\n InjectableTokenMeta,\n InjectableType,\n InjectionToken,\n} from '@navios/core'\n\nimport type { ComponentClass, XmlComponent } from '../types/component.mjs'\n\nexport const ComponentMeta = Symbol.for('xml.component.meta')\n\n/**\n * Decorator for class-based XML components with dependency injection support.\n *\n * Class components must implement the `XmlComponent` interface with a `render()` method.\n * They can optionally accept props via constructor, validated with a Zod schema.\n *\n * @overload\n * Component without props (no schema).\n *\n * @example\n * ```tsx\n * @Component()\n * class LatestPostsComponent implements XmlComponent {\n * private readonly postService = inject(PostService)\n *\n * async render() {\n * const posts = await this.postService.getLatestPosts()\n * return <>{posts.map(post => <item>...</item>)}</>\n * }\n * }\n * ```\n *\n * @overload\n * Component with props schema for type-safe props.\n *\n * @param options - Configuration object with schema and optional registry.\n * @param options.schema - Zod schema for validating and typing component props.\n * @param options.registry - Optional custom DI registry (defaults to global registry).\n *\n * @example\n * ```tsx\n * const DescriptionSchema = z.object({\n * content: z.string(),\n * wrapInCData: z.boolean().optional(),\n * })\n *\n * @Component({ schema: DescriptionSchema })\n * class DescriptionComponent implements XmlComponent {\n * constructor(private props: z.output<typeof DescriptionSchema>) {}\n *\n * async render() {\n * return <description>{this.props.wrapInCData ? <CData>{this.props.content}</CData> : this.props.content}</description>\n * }\n * }\n * ```\n *\n * @overload\n * Component with custom registry only (no props).\n *\n * @param options - Configuration object with registry.\n * @param options.registry - Custom DI registry to use for this component.\n */\n// #1 Component without props (no schema)\nexport function Component(): <T extends ComponentClass>(\n target: T,\n context?: ClassDecoratorContext,\n) => T\n\n// #2 Component with props schema\nexport function Component<Schema extends ZodObject<ZodRawShape>>(options: {\n schema: Schema\n registry?: Registry\n}): <T extends new (props: z.output<Schema>, ...args: any[]) => XmlComponent>(\n target: T,\n context?: ClassDecoratorContext,\n) => T\n\n// #3 Component with custom registry only\nexport function Component(options: {\n registry: Registry\n}): <T extends ComponentClass>(target: T, context?: ClassDecoratorContext) => T\n\nexport function Component(\n options: {\n schema?: ZodObject<ZodRawShape>\n registry?: Registry\n } = {},\n) {\n const { schema, registry = globalRegistry } = options\n\n return <T extends ComponentClass>(\n target: T,\n context?: ClassDecoratorContext,\n ): T => {\n if (\n (context && context.kind !== 'class') ||\n (target instanceof Function && !context)\n ) {\n throw new Error(\n '[@navios/adapter-xml] @Component decorator can only be used on classes.',\n )\n }\n\n // Verify the class has a render method\n if (typeof target.prototype.render !== 'function') {\n throw new Error(\n `[@navios/adapter-xml] @Component class \"${target.name}\" must implement render() method.`,\n )\n }\n\n // Create token with schema if provided\n const injectableToken = schema\n ? InjectionToken.create(target, schema)\n : InjectionToken.create(target)\n\n // Register with Request scope - each render gets fresh instances\n registry.set(\n injectableToken,\n InjectableScope.Request,\n target,\n InjectableType.Class,\n )\n\n // Store token metadata on the class (same pattern as @Injectable)\n // @ts-expect-error - Adding metadata to class\n target[InjectableTokenMeta] = injectableToken\n\n // Mark as component for JSX runtime detection\n // @ts-expect-error - Adding metadata to class\n target[ComponentMeta] = true\n\n return target\n }\n}\n\n/**\n * Type guard to check if a value is a component class.\n *\n * Component classes are classes decorated with `@Component` that implement\n * the `XmlComponent` interface.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a component class, `false` otherwise.\n *\n * @example\n * ```ts\n * if (isComponentClass(MyClass)) {\n * // MyClass is a component class\n * const instance = await container.get(MyClass)\n * }\n * ```\n */\nexport function isComponentClass(value: unknown): value is ComponentClass {\n return (\n typeof value === 'function' &&\n // @ts-expect-error - Checking metadata\n value[ComponentMeta] === true\n )\n}\n","import type { AnyXmlNode, AsyncXmlNode, ClassComponentNode, XmlNode } from '../types/xml-node.mjs'\nimport type { ComponentClass } from '../types/component.mjs'\n\nimport { isComponentClass } from '../decorators/component.decorator.mjs'\nimport { AsyncComponent, ClassComponent, Fragment } from '../types/xml-node.mjs'\n\ntype SyncComponent = (props: any) => XmlNode | AsyncXmlNode | ClassComponentNode\ntype AsyncComponentFn = (props: any) => Promise<XmlNode | AsyncXmlNode | ClassComponentNode>\ntype FunctionalComponent = SyncComponent | AsyncComponentFn\ntype ComponentType = FunctionalComponent | ComponentClass\n\nfunction flattenChildren(children: any): AnyXmlNode[] {\n if (children == null || children === false) {\n return []\n }\n if (Array.isArray(children)) {\n return children.flat(Infinity).filter((c) => c != null && c !== false)\n }\n return [children]\n}\n\n/**\n * JSX automatic runtime function.\n * Used by the JSX transformer when jsxImportSource is set.\n * Children are passed as part of props.children.\n */\nexport function jsx(\n type: string | typeof Fragment | ComponentType,\n props: Record<string, unknown> | null,\n): XmlNode | AsyncXmlNode | ClassComponentNode {\n const { children, ...restProps } = props ?? {}\n const flatChildren = flattenChildren(children)\n\n // Handle class components - create ClassComponentNode for later resolution\n if (isComponentClass(type)) {\n return {\n type: ClassComponent,\n componentClass: type,\n props: { ...restProps, children: flatChildren },\n }\n }\n\n // Handle function components (sync or async)\n if (typeof type === 'function') {\n const result = type({ ...restProps, children: flatChildren })\n\n // If component returns a Promise, wrap it in AsyncXmlNode\n if (result instanceof Promise) {\n return {\n type: AsyncComponent,\n promise: result,\n }\n }\n\n return result\n }\n\n return {\n type,\n props: restProps,\n children: flatChildren,\n }\n}\n\n/**\n * JSX automatic runtime function for static children.\n * Identical to jsx() for XML - React uses this for optimization hints.\n */\nexport const jsxs = jsx\n\n/**\n * Classic createElement for manual usage.\n * Children are passed as rest arguments.\n */\nexport function createElement(\n type: string | typeof Fragment | ComponentType,\n props: Record<string, unknown> | null,\n ...children: any[]\n): XmlNode | AsyncXmlNode | ClassComponentNode {\n const flatChildren = flattenChildren(children)\n\n // Handle class components - create ClassComponentNode for later resolution\n if (isComponentClass(type)) {\n return {\n type: ClassComponent,\n componentClass: type,\n props: { ...props, children: flatChildren },\n }\n }\n\n // Handle function components (sync or async)\n if (typeof type === 'function') {\n const result = type({ ...props, children: flatChildren })\n\n // If component returns a Promise, wrap it in AsyncXmlNode\n if (result instanceof Promise) {\n return {\n type: AsyncComponent,\n promise: result,\n }\n }\n\n return result\n }\n\n return {\n type,\n props: props ?? {},\n children: flatChildren,\n }\n}\n\nexport { Fragment }\n"],"mappings":";;;AAEA,MAAa,WAAW,OAAO,IAAI,eAAe;AAClD,MAAa,iBAAiB,OAAO,IAAI,YAAY;AACrD,MAAa,cAAc,OAAO,IAAI,YAAY;AAClD,MAAa,eAAe,OAAO,IAAI,UAAU;AACjD,MAAa,iBAAiB,OAAO,IAAI,sBAAsB;;;;ACO/D,MAAaK,gBAAgBC,OAAOC,IAAI,qBAAA;AA0ExC,SAAgBC,UACdC,UAGI,EAAE,EAAA;CAEN,MAAM,EAAEC,QAAQC,WAAWX,mBAAmBS;AAE9C,SACEG,QACAC,YAAAA;AAEA,MACE,WAAYA,QAAQC,SAAS,WAC5BF,kBAAkBG,YAAY,CAACF,QAEhC,OAAM,IAAIG,MACR,0EAAA;AAKJ,MAAI,OAAOJ,OAAOK,UAAUC,WAAW,WACrC,OAAM,IAAIF,MACR,2CAA2CJ,OAAOO,KAAK,mCAAkC;EAK7F,MAAMC,kBAAkBV,SACpBN,eAAeiB,OAAOT,QAAQF,OAAAA,GAC9BN,eAAeiB,OAAOT,OAAAA;AAG1BD,WAASW,IACPF,iBACAnB,gBAAgBsB,SAChBX,QACAT,eAAeqB,MAAK;AAKtBZ,SAAOV,uBAAuBkB;AAI9BR,SAAOP,iBAAiB;AAExB,SAAOO;;;;;;;;;;;;;;;;;;;GAqBX,SAAgBa,iBAAiBC,OAAc;AAC7C,QACE,OAAOA,UAAU,cAEjBA,MAAMrB,mBAAmB;;;;;ACtJ7B,SAAS,gBAAgB,UAA6B;AACpD,KAAI,YAAY,QAAQ,aAAa,MACnC,QAAO,EAAE;AAEX,KAAI,MAAM,QAAQ,SAAS,CACzB,QAAO,SAAS,KAAK,SAAS,CAAC,QAAQ,MAAM,KAAK,QAAQ,MAAM,MAAM;AAExE,QAAO,CAAC,SAAS;;;;;;;AAQnB,SAAgB,IACd,MACA,OAC6C;CAC7C,MAAM,EAAE,UAAU,GAAG,cAAc,SAAS,EAAE;CAC9C,MAAM,eAAe,gBAAgB,SAAS;AAG9C,KAAI,iBAAiB,KAAK,CACxB,QAAO;EACL,MAAM;EACN,gBAAgB;EAChB,OAAO;GAAE,GAAG;GAAW,UAAU;GAAc;EAChD;AAIH,KAAI,OAAO,SAAS,YAAY;EAC9B,MAAM,SAAS,KAAK;GAAE,GAAG;GAAW,UAAU;GAAc,CAAC;AAG7D,MAAI,kBAAkB,QACpB,QAAO;GACL,MAAM;GACN,SAAS;GACV;AAGH,SAAO;;AAGT,QAAO;EACL;EACA,OAAO;EACP,UAAU;EACX;;;;;;AAOH,MAAa,OAAO;;;;;AAMpB,SAAgB,cACd,MACA,OACA,GAAG,UAC0C;CAC7C,MAAM,eAAe,gBAAgB,SAAS;AAG9C,KAAI,iBAAiB,KAAK,CACxB,QAAO;EACL,MAAM;EACN,gBAAgB;EAChB,OAAO;GAAE,GAAG;GAAO,UAAU;GAAc;EAC5C;AAIH,KAAI,OAAO,SAAS,YAAY;EAC9B,MAAM,SAAS,KAAK;GAAE,GAAG;GAAO,UAAU;GAAc,CAAC;AAGzD,MAAI,kBAAkB,QACpB,QAAO;GACL,MAAM;GACN,SAAS;GACV;AAGH,SAAO;;AAGT,QAAO;EACL;EACA,OAAO,SAAS,EAAE;EAClB,UAAU;EACX"}
|