xml-model 0.1.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.
Files changed (65) hide show
  1. package/.eslintignore +3 -0
  2. package/.eslintrc.js +6 -0
  3. package/.gitignore +2 -0
  4. package/.vscode/launch.json +21 -0
  5. package/.vscode/settings.json +3 -0
  6. package/README.md +7 -0
  7. package/build/main/defaults/index.d.ts +14 -0
  8. package/build/main/defaults/index.js +165 -0
  9. package/build/main/defaults/models.d.ts +1 -0
  10. package/build/main/defaults/models.js +55 -0
  11. package/build/main/index.d.ts +5 -0
  12. package/build/main/index.js +31 -0
  13. package/build/main/middleware.d.ts +9 -0
  14. package/build/main/middleware.js +65 -0
  15. package/build/main/model/index.d.ts +26 -0
  16. package/build/main/model/index.js +304 -0
  17. package/build/main/model/property.d.ts +5 -0
  18. package/build/main/model/property.js +95 -0
  19. package/build/main/model/types.d.ts +69 -0
  20. package/build/main/model/types.js +214 -0
  21. package/build/main/model.spec.d.ts +1 -0
  22. package/build/main/model.spec.js +261 -0
  23. package/build/main/types.d.ts +8 -0
  24. package/build/main/types.js +18 -0
  25. package/build/main/xml.d.ts +31 -0
  26. package/build/main/xml.js +95 -0
  27. package/build/module/defaults/index.d.ts +13 -0
  28. package/build/module/defaults/index.js +71 -0
  29. package/build/module/defaults/models.d.ts +1 -0
  30. package/build/module/defaults/models.js +27 -0
  31. package/build/module/errors.d.ts +3 -0
  32. package/build/module/errors.js +37 -0
  33. package/build/module/index.d.ts +4 -0
  34. package/build/module/index.js +19 -0
  35. package/build/module/middleware.d.ts +9 -0
  36. package/build/module/middleware.js +60 -0
  37. package/build/module/model.d.ts +71 -0
  38. package/build/module/model.js +466 -0
  39. package/build/module/model.spec.d.ts +1 -0
  40. package/build/module/model.spec.js +76 -0
  41. package/build/module/types.d.ts +13 -0
  42. package/build/module/types.js +40 -0
  43. package/build/module/xml-from-object.d.ts +11 -0
  44. package/build/module/xml-from-object.js +58 -0
  45. package/build/module/xml-from-object.spec.d.ts +1 -0
  46. package/build/module/xml-from-object.spec.js +104 -0
  47. package/build/module/xml-to-object.d.ts +11 -0
  48. package/build/module/xml-to-object.js +55 -0
  49. package/build/module/xml.d.ts +15 -0
  50. package/build/module/xml.js +74 -0
  51. package/package.json +50 -0
  52. package/register-ts-node.js +9 -0
  53. package/src/defaults/index.ts +181 -0
  54. package/src/defaults/models.ts +45 -0
  55. package/src/index.ts +6 -0
  56. package/src/middleware.ts +34 -0
  57. package/src/model/index.ts +245 -0
  58. package/src/model/property.ts +104 -0
  59. package/src/model/types.ts +99 -0
  60. package/src/model.spec.ts +178 -0
  61. package/src/types.ts +8 -0
  62. package/src/xml.ts +80 -0
  63. package/tsconfig.json +106 -0
  64. package/tsconfig.module.json +9 -0
  65. package/yarn.lock +2217 -0
@@ -0,0 +1,466 @@
1
+ const __RΦ = { m: (k, v) => (t, ...a) => t && Reflect.metadata ? Reflect.metadata(k, v)(t, ...a) : void 0, f: (f, d, n) => (d.forEach(d => d(f)), Object.defineProperty(f, "name", { value: n, writable: false }), f), c: (c, d, dp, dsp, n) => (d.forEach(d => d(c)), dp.forEach(([p, d]) => d(c.prototype, p)), dsp.forEach(([p, d]) => d(c, p)), n ? Object.defineProperty(c, "name", { value: n, writable: false }) : undefined, c), r: (o, a) => (Object.assign(o, a)), a: id => {
2
+ let t = __RΦ.t[id];
3
+ if (t === void 0)
4
+ return void 0;
5
+ if (t.RΦ) {
6
+ let r = t.RΦ;
7
+ delete t.RΦ;
8
+ __RΦ.r(t, r(t));
9
+ }
10
+ else if (t.LΦ) {
11
+ let l = t.LΦ();
12
+ delete t.LΦ;
13
+ __RΦ.t[id] = t = l;
14
+ }
15
+ return t;
16
+ }, t: { [297]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(100), p: [__RΦ.a(1)] }) }, [100]: { LΦ: t => LΦ_0.IΦClassType }, [1]: { RΦ: t => ({ TΦ: "~" }) }, [13]: { LΦ: t => String }, [8]: { RΦ: t => ({ TΦ: "U" }) }, [887]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(118), p: [__RΦ.a(886)] }) }, [118]: { LΦ: t => LΦ_1.ReflectedTypeRef }, [886]: { RΦ: t => ({ TΦ: "|", t: [__RΦ.a(13), __RΦ.a(14), __RΦ.a(64), __RΦ.a(869), __RΦ.a(870), __RΦ.a(871), __RΦ.a(872), __RΦ.a(873), __RΦ.a(874), __RΦ.a(875), __RΦ.a(876), __RΦ.a(877), __RΦ.a(878), __RΦ.a(879), __RΦ.a(880), __RΦ.a(885)] }) }, [14]: { LΦ: t => Number }, [64]: { LΦ: t => Function }, [869]: { RΦ: t => ({ TΦ: "O", m: [{ n: "T\u03A6", f: "", t: __RΦ.a(853) }] }) }, [853]: { LΦ: t => Object }, [870]: { LΦ: t => LΦ_2.IΦRtObjectType }, [871]: { LΦ: t => LΦ_2.IΦRtUnionType }, [872]: { LΦ: t => LΦ_2.IΦRtIntersectionType }, [873]: { LΦ: t => LΦ_2.IΦRtTupleType }, [874]: { LΦ: t => LΦ_2.IΦRtArrayType }, [875]: { LΦ: t => LΦ_2.IΦRtGenericType }, [876]: { LΦ: t => LΦ_2.IΦRtMappedType }, [877]: { LΦ: t => LΦ_2.IΦRtEnumType }, [878]: { LΦ: t => LΦ_2.IΦRtCallSite }, [879]: { RΦ: t => ({ TΦ: "O", m: [{ n: "T\u03A6", f: "", t: __RΦ.a(1889) }] }) }, [1889]: { LΦ: t => "5" }, [880]: { LΦ: t => LΦ_2.IΦRtFunctionType }, [885]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(882), p: [__RΦ.a(1)] }) }, [882]: { LΦ: t => LΦ_1.IΦInterfaceToken }, [1040]: { RΦ: t => ({ TΦ: "|", t: [__RΦ.a(12), __RΦ.a(13)] }) }, [12]: { RΦ: t => ({ TΦ: "n" }) }, [384]: { LΦ: t => LΦ_0.IΦElement }, [1230]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(1227), p: [__RΦ.a(1226)] }) }, [1227]: { LΦ: t => Object }, [1226]: { TΦ: "5", name: "PropertyConversionOptions" }, [1231]: { RΦ: t => ({ TΦ: "F", r: __RΦ.a(22), p: [{ n: "context", t: () => __RΦ.a(383), v: null }], f: "" }) }, [22]: { RΦ: t => ({ TΦ: "V" }) }, [383]: { LΦ: t => LΦ_4.IΦXMLToObjectMiddlewareContext }, [1232]: { RΦ: t => ({ TΦ: "F", r: __RΦ.a(22), p: [{ n: "context", t: () => __RΦ.a(608), v: null }], f: "" }) }, [608]: { LΦ: t => LΦ_3.IΦXMLFromObjectMiddlewareContext }, [1233]: { RΦ: t => ({ TΦ: "F", r: __RΦ.a(20), p: [{ n: "el", t: () => __RΦ.a(384), v: null }], f: "" }) }, [20]: { LΦ: t => Boolean }, [1234]: { RΦ: t => ({ TΦ: "F", r: __RΦ.a(22), p: [{ n: "context", t: () => __RΦ.a(1225), v: null }], f: "" }) }, [1225]: { TΦ: "5", name: "XMLToObjectPropHandlerContext" }, [1235]: { RΦ: t => ({ TΦ: "F", r: __RΦ.a(22), p: [{ n: "context", t: () => __RΦ.a(608), v: null }], f: "" }) }, [387]: { RΦ: t => ({ TΦ: "O", m: [{ n: "__call", f: "", t: __RΦ.a(4) }] }) }, [4]: { RΦ: t => ({ TΦ: "~" }) }, [787]: { RΦ: t => ({ TΦ: "O", m: [{ n: "__call", f: "", t: __RΦ.a(4) }] }) }, [611]: { RΦ: t => ({ TΦ: "O", m: [{ n: "__call", f: "", t: __RΦ.a(4) }] }) }, [385]: { LΦ: t => LΦ_4.IΦXMLToObjectOptions }, [609]: { LΦ: t => LΦ_3.IΦXMLFromObjectOptions }, [1196]: { TΦ: "5", name: "ObjectConversionOptions" }, [1039]: { TΦ: "5", name: "ConversionOptions" }, [113]: { RΦ: t => ({ TΦ: "m", t: __RΦ.a(114), p: [] }) }, [114]: { LΦ: t => Object }, [1201]: { RΦ: t => ({ TΦ: "T", e: [{ n: "type", t: __RΦ.a(297) }, { n: "options", t: __RΦ.a(1196) }] }) }, [840]: { TΦ: "5", name: "XMLModel" }, [851]: { RΦ: t => ({ TΦ: "|", t: [__RΦ.a(10), __RΦ.a(840)] }) }, [10]: { RΦ: t => ({ TΦ: "u" }) }, [1345]: { RΦ: t => ({ TΦ: "F", r: __RΦ.a(22), p: [{ n: "constructor", t: () => __RΦ.a(297), v: null }], f: "" }) }, [1348]: { RΦ: t => ({ TΦ: "|", t: [__RΦ.a(13), __RΦ.a(74), __RΦ.a(1347)] }) }, [74]: { LΦ: t => RegExp }, [1347]: { RΦ: t => ({ TΦ: "O", m: [{ n: "__call", f: "", t: __RΦ.a(4) }] }) }, [1361]: { RΦ: t => ({ TΦ: "|", t: [__RΦ.a(12), __RΦ.a(13), __RΦ.a(790)] }) }, [790]: { RΦ: t => ({ TΦ: "O", m: [{ n: "__call", f: "", t: __RΦ.a(4) }] }) }, [1363]: { RΦ: t => ({ TΦ: "F", r: __RΦ.a(384), p: [{ n: "context", t: () => __RΦ.a(813), v: null }], f: "" }) }, [813]: { TΦ: "5", name: "XMLFromObjectPropHandlerContext" }, [809]: { RΦ: t => ({ TΦ: "F", r: __RΦ.a(22), p: [{ n: "context", t: () => __RΦ.a(813), v: null }], f: "" }) }, [1365]: { RΦ: t => ({ TΦ: "F", r: __RΦ.a(8), p: [{ n: "context", t: () => __RΦ.a(1225), v: null }], f: "" }) }, [1367]: { RΦ: t => ({ TΦ: "F", r: __RΦ.a(22), p: [{ n: "context", t: () => __RΦ.a(1225), v: null }], f: "" }) }, [791]: { TΦ: "5", name: "PropDecoratorOptions" }, [16]: { RΦ: t => ({ TΦ: "0" }) }, [1302]: { RΦ: t => ({ TΦ: "|", t: [__RΦ.a(10), __RΦ.a(1226)] }) }, [1548]: { RΦ: t => ({ TΦ: "F", r: __RΦ.a(22), p: [{ n: "prototype", t: () => __RΦ.a(1), v: null }, { n: "property", t: () => __RΦ.a(13), v: null }], f: "" }) } } };
17
+ import "reflect-metadata";
18
+ import { reflect } from "typescript-rtti";
19
+ import * as LΦ_4 from "./xml-to-object";
20
+ import { xmlToObject, } from "./xml-to-object";
21
+ import * as LΦ_3 from "./xml-from-object";
22
+ import { xmlFromObject, } from "./xml-from-object";
23
+ import { typeToString } from "./types";
24
+ import { addElement as addXMLElement } from "./xml";
25
+ import { defaults } from "./defaults";
26
+ import * as LΦ_1 from "typescript-rtti/dist";
27
+ import * as LΦ_2 from "typescript-rtti/dist/common";
28
+ var IΦXMLFromObjectPropHandlerContext = { name: "XMLFromObjectPropHandlerContext", prototype: {}, identity: Symbol("XMLFromObjectPropHandlerContext (interface)") };
29
+ (t => __RΦ.t[813] = t)(IΦXMLFromObjectPropHandlerContext);
30
+ __RΦ.m("rt:P", ["property", "value", "type", "tagname"])(IΦXMLFromObjectPropHandlerContext);
31
+ __RΦ.m("rt:m", [])(IΦXMLFromObjectPropHandlerContext);
32
+ __RΦ.m("rt:i", [() => LΦ_3.IΦXMLFromObjectMiddlewareContext])(IΦXMLFromObjectPropHandlerContext);
33
+ __RΦ.m("rt:f", "I")(IΦXMLFromObjectPropHandlerContext);
34
+ __RΦ.m("rt:t", () => __RΦ.a(13))(IΦXMLFromObjectPropHandlerContext.prototype, "property");
35
+ __RΦ.m("rt:f", "P")(IΦXMLFromObjectPropHandlerContext.prototype, "property");
36
+ __RΦ.m("rt:t", () => __RΦ.a(8))(IΦXMLFromObjectPropHandlerContext.prototype, "value");
37
+ __RΦ.m("rt:f", "P")(IΦXMLFromObjectPropHandlerContext.prototype, "value");
38
+ __RΦ.m("rt:t", () => __RΦ.a(887))(IΦXMLFromObjectPropHandlerContext.prototype, "type");
39
+ __RΦ.m("rt:f", "P")(IΦXMLFromObjectPropHandlerContext.prototype, "type");
40
+ __RΦ.m("rt:t", () => __RΦ.a(1040))(IΦXMLFromObjectPropHandlerContext.prototype, "tagname");
41
+ __RΦ.m("rt:f", "P")(IΦXMLFromObjectPropHandlerContext.prototype, "tagname");
42
+ __RΦ.m("rt:t", () => __RΦ.a(13))(IΦXMLFromObjectPropHandlerContext.prototype, "property");
43
+ __RΦ.m("rt:f", "P")(IΦXMLFromObjectPropHandlerContext.prototype, "property");
44
+ __RΦ.m("rt:t", () => __RΦ.a(8))(IΦXMLFromObjectPropHandlerContext.prototype, "value");
45
+ __RΦ.m("rt:f", "P")(IΦXMLFromObjectPropHandlerContext.prototype, "value");
46
+ __RΦ.m("rt:t", () => __RΦ.a(887))(IΦXMLFromObjectPropHandlerContext.prototype, "type");
47
+ __RΦ.m("rt:f", "P")(IΦXMLFromObjectPropHandlerContext.prototype, "type");
48
+ __RΦ.m("rt:t", () => __RΦ.a(1040))(IΦXMLFromObjectPropHandlerContext.prototype, "tagname");
49
+ __RΦ.m("rt:f", "P")(IΦXMLFromObjectPropHandlerContext.prototype, "tagname");
50
+ var IΦXMLToObjectPropHandlerContext = { name: "XMLToObjectPropHandlerContext", prototype: {}, identity: Symbol("XMLToObjectPropHandlerContext (interface)") };
51
+ (t => __RΦ.t[1225] = t)(IΦXMLToObjectPropHandlerContext);
52
+ __RΦ.m("rt:P", ["element"])(IΦXMLToObjectPropHandlerContext);
53
+ __RΦ.m("rt:m", [])(IΦXMLToObjectPropHandlerContext);
54
+ __RΦ.m("rt:i", [() => LΦ_4.IΦXMLToObjectMiddlewareContext])(IΦXMLToObjectPropHandlerContext);
55
+ __RΦ.m("rt:f", "I")(IΦXMLToObjectPropHandlerContext);
56
+ __RΦ.m("rt:t", () => __RΦ.a(384))(IΦXMLToObjectPropHandlerContext.prototype, "element");
57
+ __RΦ.m("rt:f", "P")(IΦXMLToObjectPropHandlerContext.prototype, "element");
58
+ __RΦ.m("rt:t", () => __RΦ.a(384))(IΦXMLToObjectPropHandlerContext.prototype, "element");
59
+ __RΦ.m("rt:f", "P")(IΦXMLToObjectPropHandlerContext.prototype, "element");
60
+ function XMLToObjectMiddlewareFromProps(props) {
61
+ return __RΦ.f((context) => {
62
+ if (context.xml.elements) {
63
+ for (const prop of props) {
64
+ context.xml.elements.forEach(__RΦ.f((element) => {
65
+ if (prop.forElement(element)) {
66
+ prop.handleElement({ ...context, element });
67
+ }
68
+ }, [__RΦ.m("rt:p", [{ n: "element", t: () => __RΦ.a(384), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], ""));
69
+ }
70
+ }
71
+ else {
72
+ // TODO: we should throw an error here ?
73
+ }
74
+ }, [__RΦ.m("rt:p", [{ n: "context", t: () => __RΦ.a(383), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], "");
75
+ }
76
+ __RΦ.m("rt:p", [{ n: "props", t: () => __RΦ.a(1230), v: null }])(XMLToObjectMiddlewareFromProps);
77
+ __RΦ.m("rt:f", "F")(XMLToObjectMiddlewareFromProps);
78
+ __RΦ.m("rt:t", () => __RΦ.a(1231))(XMLToObjectMiddlewareFromProps);
79
+ function XMLFromObjectMiddlewareFromProps(props) {
80
+ return __RΦ.f((context) => {
81
+ for (const prop of props) {
82
+ prop.handleProperty(context);
83
+ }
84
+ }, [__RΦ.m("rt:p", [{ n: "context", t: () => __RΦ.a(608), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], "");
85
+ }
86
+ __RΦ.m("rt:p", [{ n: "props", t: () => __RΦ.a(1230), v: null }])(XMLFromObjectMiddlewareFromProps);
87
+ __RΦ.m("rt:f", "F")(XMLFromObjectMiddlewareFromProps);
88
+ __RΦ.m("rt:t", () => __RΦ.a(1232))(XMLFromObjectMiddlewareFromProps);
89
+ var IΦPropertyConversionOptions = { name: "PropertyConversionOptions", prototype: {}, identity: Symbol("PropertyConversionOptions (interface)") };
90
+ export { IΦPropertyConversionOptions };
91
+ (t => __RΦ.t[1226] = t)(IΦPropertyConversionOptions);
92
+ __RΦ.m("rt:P", ["property", "type", "forElement", "handleElement", "handleProperty"])(IΦPropertyConversionOptions);
93
+ __RΦ.m("rt:m", [])(IΦPropertyConversionOptions);
94
+ __RΦ.m("rt:f", "Ie")(IΦPropertyConversionOptions);
95
+ __RΦ.m("rt:t", () => __RΦ.a(13))(IΦPropertyConversionOptions.prototype, "property");
96
+ __RΦ.m("rt:f", "P")(IΦPropertyConversionOptions.prototype, "property");
97
+ __RΦ.m("rt:t", () => __RΦ.a(887))(IΦPropertyConversionOptions.prototype, "type");
98
+ __RΦ.m("rt:f", "P")(IΦPropertyConversionOptions.prototype, "type");
99
+ __RΦ.m("rt:t", () => __RΦ.a(1233))(IΦPropertyConversionOptions.prototype, "forElement");
100
+ __RΦ.m("rt:f", "P")(IΦPropertyConversionOptions.prototype, "forElement");
101
+ __RΦ.m("rt:t", () => __RΦ.a(1234))(IΦPropertyConversionOptions.prototype, "handleElement");
102
+ __RΦ.m("rt:f", "P")(IΦPropertyConversionOptions.prototype, "handleElement");
103
+ __RΦ.m("rt:t", () => __RΦ.a(1235))(IΦPropertyConversionOptions.prototype, "handleProperty");
104
+ __RΦ.m("rt:f", "P")(IΦPropertyConversionOptions.prototype, "handleProperty");
105
+ __RΦ.m("rt:t", () => __RΦ.a(13))(IΦPropertyConversionOptions.prototype, "property");
106
+ __RΦ.m("rt:f", "P")(IΦPropertyConversionOptions.prototype, "property");
107
+ __RΦ.m("rt:t", () => __RΦ.a(887))(IΦPropertyConversionOptions.prototype, "type");
108
+ __RΦ.m("rt:f", "P")(IΦPropertyConversionOptions.prototype, "type");
109
+ __RΦ.m("rt:t", () => __RΦ.a(1233))(IΦPropertyConversionOptions.prototype, "forElement");
110
+ __RΦ.m("rt:f", "P")(IΦPropertyConversionOptions.prototype, "forElement");
111
+ __RΦ.m("rt:t", () => __RΦ.a(1234))(IΦPropertyConversionOptions.prototype, "handleElement");
112
+ __RΦ.m("rt:f", "P")(IΦPropertyConversionOptions.prototype, "handleElement");
113
+ __RΦ.m("rt:t", () => __RΦ.a(1235))(IΦPropertyConversionOptions.prototype, "handleProperty");
114
+ __RΦ.m("rt:f", "P")(IΦPropertyConversionOptions.prototype, "handleProperty");
115
+ var IΦXMLToObjectInstantiateContext = { name: "XMLToObjectInstantiateContext", prototype: {}, identity: Symbol("XMLToObjectInstantiateContext (interface)") };
116
+ export { IΦXMLToObjectInstantiateContext };
117
+ (t => __RΦ.t[1091] = t)(IΦXMLToObjectInstantiateContext);
118
+ __RΦ.m("rt:P", ["class"])(IΦXMLToObjectInstantiateContext);
119
+ __RΦ.m("rt:m", [])(IΦXMLToObjectInstantiateContext);
120
+ __RΦ.m("rt:i", [() => LΦ_4.IΦXMLToObjectMiddlewareContext])(IΦXMLToObjectInstantiateContext);
121
+ __RΦ.m("rt:f", "Ie")(IΦXMLToObjectInstantiateContext);
122
+ __RΦ.m("rt:t", () => __RΦ.a(297))(IΦXMLToObjectInstantiateContext.prototype, "class");
123
+ __RΦ.m("rt:f", "P")(IΦXMLToObjectInstantiateContext.prototype, "class");
124
+ __RΦ.m("rt:t", () => __RΦ.a(297))(IΦXMLToObjectInstantiateContext.prototype, "class");
125
+ __RΦ.m("rt:f", "P")(IΦXMLToObjectInstantiateContext.prototype, "class");
126
+ var IΦObjectConversionOptions = { name: "ObjectConversionOptions", prototype: {}, identity: Symbol("ObjectConversionOptions (interface)") };
127
+ export { IΦObjectConversionOptions };
128
+ (t => __RΦ.t[1196] = t)(IΦObjectConversionOptions);
129
+ __RΦ.m("rt:P", ["fromXML", "instantiate", "tagname", "toXML"])(IΦObjectConversionOptions);
130
+ __RΦ.m("rt:m", [])(IΦObjectConversionOptions);
131
+ __RΦ.m("rt:f", "Ie")(IΦObjectConversionOptions);
132
+ __RΦ.m("rt:t", () => __RΦ.a(387))(IΦObjectConversionOptions.prototype, "fromXML");
133
+ __RΦ.m("rt:f", "P?")(IΦObjectConversionOptions.prototype, "fromXML");
134
+ __RΦ.m("rt:t", () => __RΦ.a(787))(IΦObjectConversionOptions.prototype, "instantiate");
135
+ __RΦ.m("rt:f", "P?")(IΦObjectConversionOptions.prototype, "instantiate");
136
+ __RΦ.m("rt:t", () => __RΦ.a(13))(IΦObjectConversionOptions.prototype, "tagname");
137
+ __RΦ.m("rt:f", "P?")(IΦObjectConversionOptions.prototype, "tagname");
138
+ __RΦ.m("rt:t", () => __RΦ.a(611))(IΦObjectConversionOptions.prototype, "toXML");
139
+ __RΦ.m("rt:f", "P?")(IΦObjectConversionOptions.prototype, "toXML");
140
+ __RΦ.m("rt:t", () => __RΦ.a(387))(IΦObjectConversionOptions.prototype, "fromXML");
141
+ __RΦ.m("rt:f", "P?")(IΦObjectConversionOptions.prototype, "fromXML");
142
+ __RΦ.m("rt:t", () => __RΦ.a(787))(IΦObjectConversionOptions.prototype, "instantiate");
143
+ __RΦ.m("rt:f", "P?")(IΦObjectConversionOptions.prototype, "instantiate");
144
+ __RΦ.m("rt:t", () => __RΦ.a(13))(IΦObjectConversionOptions.prototype, "tagname");
145
+ __RΦ.m("rt:f", "P?")(IΦObjectConversionOptions.prototype, "tagname");
146
+ __RΦ.m("rt:t", () => __RΦ.a(611))(IΦObjectConversionOptions.prototype, "toXML");
147
+ __RΦ.m("rt:f", "P?")(IΦObjectConversionOptions.prototype, "toXML");
148
+ var IΦConversionOptions = { name: "ConversionOptions", prototype: {}, identity: Symbol("ConversionOptions (interface)") };
149
+ (t => __RΦ.t[1039] = t)(IΦConversionOptions);
150
+ __RΦ.m("rt:P", ["fromXML", "toXML"])(IΦConversionOptions);
151
+ __RΦ.m("rt:m", [])(IΦConversionOptions);
152
+ __RΦ.m("rt:f", "I")(IΦConversionOptions);
153
+ __RΦ.m("rt:t", () => __RΦ.a(385))(IΦConversionOptions.prototype, "fromXML");
154
+ __RΦ.m("rt:f", "P")(IΦConversionOptions.prototype, "fromXML");
155
+ __RΦ.m("rt:t", () => __RΦ.a(609))(IΦConversionOptions.prototype, "toXML");
156
+ __RΦ.m("rt:f", "P")(IΦConversionOptions.prototype, "toXML");
157
+ __RΦ.m("rt:t", () => __RΦ.a(385))(IΦConversionOptions.prototype, "fromXML");
158
+ __RΦ.m("rt:f", "P")(IΦConversionOptions.prototype, "fromXML");
159
+ __RΦ.m("rt:t", () => __RΦ.a(609))(IΦConversionOptions.prototype, "toXML");
160
+ __RΦ.m("rt:f", "P")(IΦConversionOptions.prototype, "toXML");
161
+ import * as LΦ_0 from "./types";
162
+ export class XMLModel {
163
+ type;
164
+ options;
165
+ conversionOptions;
166
+ constructor(type, options) {
167
+ this.type = type;
168
+ this.options = options;
169
+ }
170
+ resolveConversionOptions() {
171
+ const options = {
172
+ toXML: {
173
+ parent: null,
174
+ middlewares: [],
175
+ },
176
+ fromXML: {
177
+ parent: null,
178
+ middlewares: [],
179
+ },
180
+ };
181
+ const properties = reflect(this.type, { TΦ: "c", t: void 0, p: [__RΦ.a(297)], r: void 0, tp: [] }).ownProperties.filter((prop) => typeof prop.host.constructor.prototype[prop.name] !== "function"); // filter out methods like String.prototype.concat etc... that are seen as properties
182
+ const propertyConversionOptions = properties.map((property) => findPropertyConversionOptions(this.type, property.name) ||
183
+ getPropertyConversionOptions({}, this.type, property.name));
184
+ /* Properties */
185
+ // from XML
186
+ options.fromXML.middlewares.push(XMLToObjectMiddlewareFromProps(propertyConversionOptions));
187
+ // to XML
188
+ options.toXML.middlewares.push(XMLFromObjectMiddlewareFromProps(propertyConversionOptions));
189
+ /* Global */
190
+ // from XML
191
+ if (this.options.fromXML)
192
+ options.fromXML.middlewares.push(this.options.fromXML);
193
+ // to XML
194
+ if (this.options.toXML) {
195
+ options.toXML.middlewares.push(this.options.toXML);
196
+ }
197
+ options.toXML.middlewares.push((ctx, next) => {
198
+ ctx.xml.name =
199
+ "tagname" in options
200
+ ? this.options.tagname
201
+ : defaults.tagnameFromClass({ class: this.type });
202
+ next();
203
+ });
204
+ return options;
205
+ }
206
+ getConversionOptions() {
207
+ if (!this.conversionOptions) {
208
+ this.conversionOptions = this.resolveConversionOptions();
209
+ }
210
+ return this.conversionOptions;
211
+ }
212
+ recordFromXMLElement(xml) {
213
+ return xmlToObject(xml, this.getConversionOptions().fromXML);
214
+ }
215
+ fromXMLElement(xml) {
216
+ const record = this.recordFromXMLElement(xml);
217
+ const object = (this.options.instantiate || defaults.instantiate)({
218
+ xml,
219
+ record,
220
+ class: this.type,
221
+ });
222
+ return object;
223
+ }
224
+ toXMLElement(instance) {
225
+ if (instance instanceof this.type || instance.constructor === this.type) {
226
+ // FIXME: intanceof won't work with type "String" for example
227
+ return xmlFromObject(instance, this.getConversionOptions().toXML);
228
+ }
229
+ else {
230
+ throw new Error(`provided object is not an instance of ${this.type.name}`);
231
+ }
232
+ }
233
+ }
234
+ (t => __RΦ.t[840] = t)(XMLModel);
235
+ __RΦ.m("rt:SP", [])(XMLModel);
236
+ __RΦ.m("rt:P", ["conversionOptions", "type", "options"])(XMLModel);
237
+ __RΦ.m("rt:Sm", [])(XMLModel);
238
+ __RΦ.m("rt:m", ["resolveConversionOptions", "getConversionOptions", "recordFromXMLElement", "fromXMLElement", "toXMLElement"])(XMLModel);
239
+ __RΦ.m("rt:p", [{ n: "type", t: () => __RΦ.a(297), v: null, f: "R" }, { n: "options", t: () => __RΦ.a(1196), v: null, f: "R" }])(XMLModel);
240
+ __RΦ.m("rt:f", "Ce")(XMLModel);
241
+ __RΦ.m("rt:t", () => __RΦ.a(1039))(XMLModel.prototype, "conversionOptions");
242
+ __RΦ.m("rt:f", "P?")(XMLModel.prototype, "conversionOptions");
243
+ __RΦ.m("rt:f", "M#")(XMLModel.prototype["getConversionOptions"]);
244
+ ((t, p) => __RΦ.m("rt:h", () => typeof t === "object" ? t.constructor : t)(t[p]))(XMLModel.prototype, "getConversionOptions");
245
+ __RΦ.m("rt:p", [])(XMLModel.prototype, "getConversionOptions");
246
+ __RΦ.m("rt:f", "M#")(XMLModel.prototype, "getConversionOptions");
247
+ __RΦ.m("rt:t", () => __RΦ.a(1039))(XMLModel.prototype, "getConversionOptions");
248
+ __RΦ.m("rt:f", "M.")(XMLModel.prototype["recordFromXMLElement"]);
249
+ ((t, p) => __RΦ.m("rt:h", () => typeof t === "object" ? t.constructor : t)(t[p]))(XMLModel.prototype, "recordFromXMLElement");
250
+ __RΦ.m("rt:p", [{ n: "xml", t: () => __RΦ.a(384), v: null }])(XMLModel.prototype, "recordFromXMLElement");
251
+ __RΦ.m("rt:f", "M.")(XMLModel.prototype, "recordFromXMLElement");
252
+ __RΦ.m("rt:t", () => __RΦ.a(113))(XMLModel.prototype, "recordFromXMLElement");
253
+ __RΦ.m("rt:f", "M.")(XMLModel.prototype["fromXMLElement"]);
254
+ ((t, p) => __RΦ.m("rt:h", () => typeof t === "object" ? t.constructor : t)(t[p]))(XMLModel.prototype, "fromXMLElement");
255
+ __RΦ.m("rt:p", [{ n: "xml", t: () => __RΦ.a(384), v: null }])(XMLModel.prototype, "fromXMLElement");
256
+ __RΦ.m("rt:f", "M.")(XMLModel.prototype, "fromXMLElement");
257
+ __RΦ.m("rt:t", () => __RΦ.a(8))(XMLModel.prototype, "fromXMLElement");
258
+ __RΦ.m("rt:f", "M.")(XMLModel.prototype["toXMLElement"]);
259
+ ((t, p) => __RΦ.m("rt:h", () => typeof t === "object" ? t.constructor : t)(t[p]))(XMLModel.prototype, "toXMLElement");
260
+ __RΦ.m("rt:p", [{ n: "instance", t: () => __RΦ.a(1), v: null }])(XMLModel.prototype, "toXMLElement");
261
+ __RΦ.m("rt:f", "M.")(XMLModel.prototype, "toXMLElement");
262
+ __RΦ.m("rt:t", () => __RΦ.a(384))(XMLModel.prototype, "toXMLElement");
263
+ export function createModel(...args) {
264
+ const type = args[0];
265
+ if (findModel(type)) {
266
+ throw new Error(`a model for type ${typeToString(type)} already exists`);
267
+ }
268
+ const model = new XMLModel(...args);
269
+ Models.set(args[0], model);
270
+ return model;
271
+ }
272
+ __RΦ.m("rt:p", [{ n: "args", t: () => __RΦ.a(1201), v: null }])(createModel);
273
+ __RΦ.m("rt:f", "F")(createModel);
274
+ __RΦ.m("rt:t", () => __RΦ.a(840))(createModel);
275
+ export const Models = new Map();
276
+ export function findModel(type) {
277
+ return Models.get(type);
278
+ }
279
+ __RΦ.m("rt:p", [{ n: "type", t: () => __RΦ.a(297), v: null }])(findModel);
280
+ __RΦ.m("rt:f", "F")(findModel);
281
+ __RΦ.m("rt:t", () => __RΦ.a(851))(findModel);
282
+ export function getModel(type) {
283
+ const model = findModel(type);
284
+ if (model)
285
+ return model;
286
+ else
287
+ throw new Error(`couln't find model for type ${typeToString(type)}`);
288
+ }
289
+ __RΦ.m("rt:p", [{ n: "type", t: () => __RΦ.a(297), v: null }])(getModel);
290
+ __RΦ.m("rt:f", "F")(getModel);
291
+ __RΦ.m("rt:t", () => __RΦ.a(840))(getModel);
292
+ function ensureModel(type) {
293
+ return findModel(type) || createModel(type, {});
294
+ }
295
+ __RΦ.m("rt:p", [{ n: "type", t: () => __RΦ.a(297), v: null }])(ensureModel);
296
+ __RΦ.m("rt:f", "F")(ensureModel);
297
+ __RΦ.m("rt:t", () => __RΦ.a(840))(ensureModel);
298
+ // Model decorator
299
+ function ModelDecoratorFactory(options) {
300
+ return __RΦ.f(function (constructor) {
301
+ const model = ensureModel(constructor);
302
+ if (options) {
303
+ Object.assign(model.options, options);
304
+ }
305
+ }, [__RΦ.m("rt:p", [{ n: "constructor", t: () => __RΦ.a(297), v: null }]), __RΦ.m("rt:f", "M"), __RΦ.m("rt:t", () => __RΦ.a(22))], "");
306
+ }
307
+ __RΦ.m("rt:p", [{ n: "options", t: () => __RΦ.a(1196), v: null, f: "?" }])(ModelDecoratorFactory);
308
+ __RΦ.m("rt:f", "F")(ModelDecoratorFactory);
309
+ __RΦ.m("rt:t", () => __RΦ.a(1345))(ModelDecoratorFactory);
310
+ export { ModelDecoratorFactory as Model };
311
+ var IΦPropDecoratorOptions = { name: "PropDecoratorOptions", prototype: {}, identity: Symbol("PropDecoratorOptions (interface)") };
312
+ export { IΦPropDecoratorOptions };
313
+ (t => __RΦ.t[791] = t)(IΦPropDecoratorOptions);
314
+ __RΦ.m("rt:P", ["tagname", "fromElement", "toTagname", "toXML", "handleProperty", "fromXML", "handleElement", "ignore"])(IΦPropDecoratorOptions);
315
+ __RΦ.m("rt:m", [])(IΦPropDecoratorOptions);
316
+ __RΦ.m("rt:f", "Ie")(IΦPropDecoratorOptions);
317
+ __RΦ.m("rt:t", () => __RΦ.a(13))(IΦPropDecoratorOptions.prototype, "tagname");
318
+ __RΦ.m("rt:f", "P?")(IΦPropDecoratorOptions.prototype, "tagname");
319
+ __RΦ.m("rt:t", () => __RΦ.a(1348))(IΦPropDecoratorOptions.prototype, "fromElement");
320
+ __RΦ.m("rt:f", "P?")(IΦPropDecoratorOptions.prototype, "fromElement");
321
+ __RΦ.m("rt:t", () => __RΦ.a(1361))(IΦPropDecoratorOptions.prototype, "toTagname");
322
+ __RΦ.m("rt:f", "P?")(IΦPropDecoratorOptions.prototype, "toTagname");
323
+ __RΦ.m("rt:t", () => __RΦ.a(1363))(IΦPropDecoratorOptions.prototype, "toXML");
324
+ __RΦ.m("rt:f", "P?")(IΦPropDecoratorOptions.prototype, "toXML");
325
+ __RΦ.m("rt:t", () => __RΦ.a(809))(IΦPropDecoratorOptions.prototype, "handleProperty");
326
+ __RΦ.m("rt:f", "P?")(IΦPropDecoratorOptions.prototype, "handleProperty");
327
+ __RΦ.m("rt:t", () => __RΦ.a(1365))(IΦPropDecoratorOptions.prototype, "fromXML");
328
+ __RΦ.m("rt:f", "P?")(IΦPropDecoratorOptions.prototype, "fromXML");
329
+ __RΦ.m("rt:t", () => __RΦ.a(1367))(IΦPropDecoratorOptions.prototype, "handleElement");
330
+ __RΦ.m("rt:f", "P?")(IΦPropDecoratorOptions.prototype, "handleElement");
331
+ __RΦ.m("rt:t", () => __RΦ.a(20))(IΦPropDecoratorOptions.prototype, "ignore");
332
+ __RΦ.m("rt:f", "P?")(IΦPropDecoratorOptions.prototype, "ignore");
333
+ __RΦ.m("rt:t", () => __RΦ.a(13))(IΦPropDecoratorOptions.prototype, "tagname");
334
+ __RΦ.m("rt:f", "P?")(IΦPropDecoratorOptions.prototype, "tagname");
335
+ __RΦ.m("rt:t", () => __RΦ.a(1348))(IΦPropDecoratorOptions.prototype, "fromElement");
336
+ __RΦ.m("rt:f", "P?")(IΦPropDecoratorOptions.prototype, "fromElement");
337
+ __RΦ.m("rt:t", () => __RΦ.a(1361))(IΦPropDecoratorOptions.prototype, "toTagname");
338
+ __RΦ.m("rt:f", "P?")(IΦPropDecoratorOptions.prototype, "toTagname");
339
+ __RΦ.m("rt:t", () => __RΦ.a(1363))(IΦPropDecoratorOptions.prototype, "toXML");
340
+ __RΦ.m("rt:f", "P?")(IΦPropDecoratorOptions.prototype, "toXML");
341
+ __RΦ.m("rt:t", () => __RΦ.a(809))(IΦPropDecoratorOptions.prototype, "handleProperty");
342
+ __RΦ.m("rt:f", "P?")(IΦPropDecoratorOptions.prototype, "handleProperty");
343
+ __RΦ.m("rt:t", () => __RΦ.a(1365))(IΦPropDecoratorOptions.prototype, "fromXML");
344
+ __RΦ.m("rt:f", "P?")(IΦPropDecoratorOptions.prototype, "fromXML");
345
+ __RΦ.m("rt:t", () => __RΦ.a(1367))(IΦPropDecoratorOptions.prototype, "handleElement");
346
+ __RΦ.m("rt:f", "P?")(IΦPropDecoratorOptions.prototype, "handleElement");
347
+ __RΦ.m("rt:t", () => __RΦ.a(20))(IΦPropDecoratorOptions.prototype, "ignore");
348
+ __RΦ.m("rt:f", "P?")(IΦPropDecoratorOptions.prototype, "ignore");
349
+ function getPropertyConversionOptions(options, prototype /* FIXME: should be typed */, property) {
350
+ // normalize into PropertyConversionOptions
351
+ const resolveType = __RΦ.f(() => reflect(prototype.constructor, { TΦ: "c", t: void 0, p: [__RΦ.a(1)], r: void 0, tp: [] }).getProperty(property).type, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(887))], "");
352
+ // XML -> Object
353
+ // fromElement
354
+ let forElement = options.ignore
355
+ ? __RΦ.f(() => false, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(16))], "") : __RΦ.f(() => false, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(16))], ""); // TODO: default;
356
+ if (options?.fromElement) {
357
+ const _fromElement = options.fromElement;
358
+ if (typeof _fromElement === "string") {
359
+ forElement = __RΦ.f((el) => el.name === _fromElement, [__RΦ.m("rt:p", [{ n: "el", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(20))], "");
360
+ }
361
+ else if (_fromElement && _fromElement instanceof RegExp) {
362
+ forElement = __RΦ.f((el) => _fromElement.test(el.name || ""), [__RΦ.m("rt:p", [{ n: "el", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(20))], "");
363
+ }
364
+ else {
365
+ forElement = _fromElement;
366
+ }
367
+ }
368
+ else if (options?.tagname) {
369
+ const tagname = options.tagname;
370
+ forElement = __RΦ.f((el) => el.name === tagname, [__RΦ.m("rt:p", [{ n: "el", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(20))], "");
371
+ }
372
+ // deserialization
373
+ let handleElement = options.ignore
374
+ ? __RΦ.f(() => { }, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], "") : __RΦ.f(() => { }, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], ""); // TODO: default;
375
+ if (options?.handleElement) {
376
+ handleElement = options.handleElement;
377
+ }
378
+ else if (options?.fromXML) {
379
+ const fromXML = options.fromXML;
380
+ handleElement = __RΦ.f((context) => (context.record[property] = fromXML(context)), [__RΦ.m("rt:p", [{ n: "context", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(8))], "");
381
+ }
382
+ // Object -> XML
383
+ let getTagname = defaults.tagnameFromProperty;
384
+ if (options?.toTagname) {
385
+ const toTagname = options?.toTagname;
386
+ if (typeof toTagname === "string") {
387
+ getTagname = __RΦ.f(() => toTagname, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(13))], "");
388
+ }
389
+ else {
390
+ getTagname = toTagname;
391
+ }
392
+ }
393
+ const getContext = __RΦ.f((_context) => {
394
+ const value = _context.object[property]; // FIXME: better typing ?
395
+ const context = {
396
+ ..._context,
397
+ property,
398
+ value,
399
+ get type() {
400
+ return resolveType();
401
+ },
402
+ tagname: getTagname({
403
+ property,
404
+ get type() {
405
+ return resolveType();
406
+ },
407
+ value,
408
+ }),
409
+ };
410
+ return context;
411
+ }, [__RΦ.m("rt:p", [{ n: "_context", t: () => __RΦ.a(608), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(813))], "");
412
+ let handleProperty = options.ignore
413
+ ? __RΦ.f(() => { }, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], "") : __RΦ.f((ctx) => defaults.handleProperty(getContext(ctx)), [__RΦ.m("rt:p", [{ n: "ctx", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], "");
414
+ if (options?.handleProperty) {
415
+ const _handleProperty = options.handleProperty;
416
+ handleProperty = __RΦ.f((ctx) => _handleProperty(getContext(ctx)), [__RΦ.m("rt:p", [{ n: "ctx", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], "");
417
+ }
418
+ else if (options?.toXML) {
419
+ const toXML = options.toXML;
420
+ handleProperty = __RΦ.f((ctx) => {
421
+ const element = toXML(getContext(ctx));
422
+ addXMLElement(ctx.xml, element);
423
+ }, [__RΦ.m("rt:p", [{ n: "ctx", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], "");
424
+ }
425
+ const _options = {
426
+ property,
427
+ get type() {
428
+ return resolveType();
429
+ },
430
+ forElement,
431
+ handleElement,
432
+ handleProperty,
433
+ };
434
+ return _options;
435
+ }
436
+ __RΦ.m("rt:p", [{ n: "options", t: () => __RΦ.a(791), v: null }, { n: "prototype", t: () => __RΦ.a(1), v: null }, { n: "property", t: () => __RΦ.a(13), v: null }])(getPropertyConversionOptions);
437
+ __RΦ.m("rt:f", "F")(getPropertyConversionOptions);
438
+ __RΦ.m("rt:t", () => __RΦ.a(1226))(getPropertyConversionOptions);
439
+ const PropertyOptions = new Map();
440
+ function storePropertyConversionOptions(_class, property, options) {
441
+ if (!PropertyOptions.has(_class))
442
+ PropertyOptions.set(_class, new Map());
443
+ PropertyOptions.get(_class).set(property, options);
444
+ }
445
+ __RΦ.m("rt:p", [{ n: "_class", t: () => __RΦ.a(297), v: null }, { n: "property", t: () => __RΦ.a(13), v: null }, { n: "options", t: () => __RΦ.a(1226), v: null }])(storePropertyConversionOptions);
446
+ __RΦ.m("rt:f", "F")(storePropertyConversionOptions);
447
+ __RΦ.m("rt:t", () => __RΦ.a(22))(storePropertyConversionOptions);
448
+ function findPropertyConversionOptions(_class, property) {
449
+ if (PropertyOptions.has(_class)) {
450
+ return PropertyOptions.get(_class).get(property);
451
+ }
452
+ }
453
+ __RΦ.m("rt:p", [{ n: "_class", t: () => __RΦ.a(297), v: null }, { n: "property", t: () => __RΦ.a(13), v: null }])(findPropertyConversionOptions);
454
+ __RΦ.m("rt:f", "F")(findPropertyConversionOptions);
455
+ __RΦ.m("rt:t", () => __RΦ.a(1302))(findPropertyConversionOptions);
456
+ function PropDecoratorFactory(options) {
457
+ return __RΦ.f(function (prototype /* FIXME: should be typed */, property) {
458
+ const _options = getPropertyConversionOptions(options || {}, prototype, property);
459
+ storePropertyConversionOptions(prototype.constructor, property, _options);
460
+ }, [__RΦ.m("rt:p", [{ n: "prototype", t: () => __RΦ.a(1), v: null }, { n: "property", t: () => __RΦ.a(13), v: null }]), __RΦ.m("rt:f", "M."), __RΦ.m("rt:t", () => __RΦ.a(22))], "");
461
+ }
462
+ __RΦ.m("rt:p", [{ n: "options", t: () => __RΦ.a(791), v: null, f: "?" }])(PropDecoratorFactory);
463
+ __RΦ.m("rt:f", "F")(PropDecoratorFactory);
464
+ __RΦ.m("rt:t", () => __RΦ.a(1548))(PropDecoratorFactory);
465
+ export { PropDecoratorFactory as Prop };
466
+ import "./defaults/models";
@@ -0,0 +1 @@
1
+ import "mocha";
@@ -0,0 +1,76 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ const __RΦ = { m: (k, v) => (t, ...a) => t && Reflect.metadata ? Reflect.metadata(k, v)(t, ...a) : void 0, f: (f, d, n) => (d.forEach(d => d(f)), Object.defineProperty(f, "name", { value: n, writable: false }), f), c: (c, d, dp, dsp, n) => (d.forEach(d => d(c)), dp.forEach(([p, d]) => d(c.prototype, p)), dsp.forEach(([p, d]) => d(c, p)), n ? Object.defineProperty(c, "name", { value: n, writable: false }) : undefined, c), r: (o, a) => (Object.assign(o, a)), a: id => {
8
+ let t = __RΦ.t[id];
9
+ if (t === void 0)
10
+ return void 0;
11
+ if (t.RΦ) {
12
+ let r = t.RΦ;
13
+ delete t.RΦ;
14
+ __RΦ.r(t, r(t));
15
+ }
16
+ else if (t.LΦ) {
17
+ let l = t.LΦ();
18
+ delete t.LΦ;
19
+ __RΦ.t[id] = t = l;
20
+ }
21
+ return t;
22
+ }, t: { [1577]: { RΦ: t => ({ TΦ: "O", m: [{ n: "propA", f: "", t: __RΦ.a(13) }, { n: "propB", f: "", t: __RΦ.a(20) }, { n: "propC", f: "", t: __RΦ.a(1584) }, { n: "propD", f: "", t: __RΦ.a(464) }] }) }, [13]: { LΦ: t => String }, [20]: { LΦ: t => Boolean }, [1584]: { RΦ: t => ({ TΦ: "[", e: __RΦ.a(1582) }) }, [1582]: { TΦ: "5", name: "ModelB" }, [464]: { RΦ: t => ({ TΦ: "|", t: [__RΦ.a(47), __RΦ.a(322)] }) }, [47]: { LΦ: t => 0 }, [322]: { LΦ: t => 1 }, [14]: { LΦ: t => Number }, [22]: { RΦ: t => ({ TΦ: "V" }) } } };
23
+ import "mocha";
24
+ import { expect, assert } from "chai";
25
+ import { Model } from "./model";
26
+ import { reflect } from "typescript-rtti";
27
+ let ModelA = class ModelA {
28
+ propA = "";
29
+ propB = true;
30
+ propC = [];
31
+ propD = 0;
32
+ };
33
+ ModelA = __decorate([
34
+ Model()
35
+ ], ModelA);
36
+ (t => __RΦ.t[1578] = t)(ModelA);
37
+ __RΦ.m("rt:SP", [])(ModelA);
38
+ __RΦ.m("rt:P", ["propA", "propB", "propC", "propD"])(ModelA);
39
+ __RΦ.m("rt:Sm", [])(ModelA);
40
+ __RΦ.m("rt:m", [])(ModelA);
41
+ __RΦ.m("rt:f", "C")(ModelA);
42
+ __RΦ.m("rt:t", () => __RΦ.a(13))(ModelA.prototype, "propA");
43
+ __RΦ.m("rt:f", "P")(ModelA.prototype, "propA");
44
+ __RΦ.m("rt:t", () => __RΦ.a(20))(ModelA.prototype, "propB");
45
+ __RΦ.m("rt:f", "P")(ModelA.prototype, "propB");
46
+ __RΦ.m("rt:t", () => __RΦ.a(1584))(ModelA.prototype, "propC");
47
+ __RΦ.m("rt:f", "P")(ModelA.prototype, "propC");
48
+ __RΦ.m("rt:t", () => __RΦ.a(464))(ModelA.prototype, "propD");
49
+ __RΦ.m("rt:f", "P")(ModelA.prototype, "propD");
50
+ let ModelB = class ModelB {
51
+ propA = 0;
52
+ };
53
+ ModelB = __decorate([
54
+ Model()
55
+ ], ModelB);
56
+ (t => __RΦ.t[1582] = t)(ModelB);
57
+ __RΦ.m("rt:SP", [])(ModelB);
58
+ __RΦ.m("rt:P", ["propA"])(ModelB);
59
+ __RΦ.m("rt:Sm", [])(ModelB);
60
+ __RΦ.m("rt:m", [])(ModelB);
61
+ __RΦ.m("rt:f", "C")(ModelB);
62
+ __RΦ.m("rt:t", () => __RΦ.a(14))(ModelB.prototype, "propA");
63
+ __RΦ.m("rt:f", "P")(ModelB.prototype, "propA");
64
+ describe("XML Models", __RΦ.f(() => {
65
+ it("should give right type infos", __RΦ.f(() => {
66
+ assert(reflect(ModelA, { TΦ: "c", t: void 0, p: [__RΦ.a(1577)], r: void 0, tp: [] }) === reflect(ModelA, { TΦ: "c", t: void 0, p: [__RΦ.a(1577)], r: void 0, tp: [] }));
67
+ expect(reflect(ModelA, { TΦ: "c", t: void 0, p: [__RΦ.a(1577)], r: void 0, tp: [] }).getProperty("propA").type.isClass(String)).to.be
68
+ .true;
69
+ expect(reflect(ModelA, { TΦ: "c", t: void 0, p: [__RΦ.a(1577)], r: void 0, tp: [] }).getProperty("propB").type.isClass(Boolean)).to.be
70
+ .true;
71
+ const ModelAPropCType = reflect(ModelA, { TΦ: "c", t: void 0, p: [__RΦ.a(1577)], r: void 0, tp: [] }).getProperty("propC").type;
72
+ expect(ModelAPropCType.is("array") && ModelAPropCType.elementType.isClass(ModelB)).to.be.true;
73
+ const ModelAPropDType = reflect(ModelA, { TΦ: "c", t: void 0, p: [__RΦ.a(1577)], r: void 0, tp: [] }).getProperty("propD").type;
74
+ expect(ModelAPropDType.is("union")).to.be.true;
75
+ }, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], ""));
76
+ }, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], ""));
@@ -0,0 +1,13 @@
1
+ import { ReflectedTypeRef } from "typescript-rtti";
2
+ export interface ClassType<T = any> {
3
+ new (...args: any[]): T;
4
+ }
5
+ export declare type UnknownRecord = Record<string | number | symbol, unknown>;
6
+ export declare type UnknownObject = object;
7
+ export type { Element as XMLElement } from "xml-js";
8
+ export declare type ScalarType = Boolean | Number | String;
9
+ export declare type TypeValue = ClassType | ScalarType | Function | object | symbol;
10
+ export declare type TypeInfo = ReflectedTypeRef;
11
+ export declare const allowedTypes: Function[];
12
+ export declare const bannedTypes: Function[];
13
+ export declare function typeToString(type: TypeValue): string;
@@ -0,0 +1,40 @@
1
+ const __RΦ = { m: (k, v) => (t, ...a) => t && Reflect.metadata ? Reflect.metadata(k, v)(t, ...a) : void 0, f: (f, d, n) => (d.forEach(d => d(f)), Object.defineProperty(f, "name", { value: n, writable: false }), f), c: (c, d, dp, dsp, n) => (d.forEach(d => d(c)), dp.forEach(([p, d]) => d(c.prototype, p)), dsp.forEach(([p, d]) => d(c, p)), n ? Object.defineProperty(c, "name", { value: n, writable: false }) : undefined, c), r: (o, a) => (Object.assign(o, a)), a: id => {
2
+ let t = __RΦ.t[id];
3
+ if (t === void 0)
4
+ return void 0;
5
+ if (t.RΦ) {
6
+ let r = t.RΦ;
7
+ delete t.RΦ;
8
+ __RΦ.r(t, r(t));
9
+ }
10
+ else if (t.LΦ) {
11
+ let l = t.LΦ();
12
+ delete t.LΦ;
13
+ __RΦ.t[id] = t = l;
14
+ }
15
+ return t;
16
+ }, t: { [117]: { RΦ: t => ({ TΦ: "|", t: [__RΦ.a(21), __RΦ.a(28), __RΦ.a(64), __RΦ.a(67), __RΦ.a(72), __RΦ.a(73), __RΦ.a(116)] }) }, [21]: { LΦ: t => Object }, [28]: { LΦ: t => Object }, [64]: { LΦ: t => Function }, [67]: { LΦ: t => String }, [72]: { LΦ: t => Number }, [73]: { LΦ: t => Boolean }, [116]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(100), p: [__RΦ.a(1)] }) }, [100]: { TΦ: "5", name: "ClassType" }, [1]: { RΦ: t => ({ TΦ: "~" }) }, [13]: { LΦ: t => String } } };
17
+ var IΦClassType = { name: "ClassType", prototype: {}, identity: Symbol("ClassType (interface)") };
18
+ export { IΦClassType };
19
+ (t => __RΦ.t[100] = t)(IΦClassType);
20
+ __RΦ.m("rt:P", [])(IΦClassType);
21
+ __RΦ.m("rt:m", [])(IΦClassType);
22
+ __RΦ.m("rt:f", "Ie")(IΦClassType);
23
+ export const allowedTypes = [String, Number, Date, Boolean];
24
+ export const bannedTypes = [Promise, Array, Object, Function];
25
+ export function typeToString(type) {
26
+ // primitives
27
+ switch (typeof type) {
28
+ case "symbol":
29
+ return String(type);
30
+ default:
31
+ break;
32
+ }
33
+ if ("name" in type)
34
+ return type.name;
35
+ else
36
+ return String(type);
37
+ }
38
+ __RΦ.m("rt:p", [{ n: "type", t: () => __RΦ.a(117), v: null }])(typeToString);
39
+ __RΦ.m("rt:f", "F")(typeToString);
40
+ __RΦ.m("rt:t", () => __RΦ.a(13))(typeToString);
@@ -0,0 +1,11 @@
1
+ import type { XMLElement, UnknownObject } from "./types";
2
+ import { Middleware } from "./middleware";
3
+ export interface XMLFromObjectMiddlewareContext {
4
+ xml: XMLElement;
5
+ object: UnknownObject;
6
+ }
7
+ export interface XMLFromObjectOptions {
8
+ parent: XMLFromObjectOptions | null;
9
+ middlewares: Middleware<XMLFromObjectMiddlewareContext, void>[];
10
+ }
11
+ export declare function xmlFromObject(object: UnknownObject, options: XMLFromObjectOptions): XMLElement;