xml-model 0.1.0 → 0.2.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 (62) hide show
  1. package/build/main/defaults/index.js +22 -16
  2. package/build/main/defaults/models.js +4 -4
  3. package/build/main/errors.d.ts +4 -0
  4. package/build/main/errors.js +35 -0
  5. package/build/main/middleware.js +11 -11
  6. package/build/main/model/index.d.ts +7 -9
  7. package/build/main/model/index.js +94 -72
  8. package/build/main/model/property.js +25 -23
  9. package/build/main/model/types.d.ts +5 -1
  10. package/build/main/model/types.js +86 -70
  11. package/build/main/xml.d.ts +2 -0
  12. package/build/main/xml.js +20 -10
  13. package/build/module/defaults/index.d.ts +11 -10
  14. package/build/module/defaults/index.js +139 -46
  15. package/build/module/defaults/models.js +37 -6
  16. package/build/module/errors.d.ts +3 -2
  17. package/build/module/errors.js +15 -20
  18. package/build/module/index.d.ts +2 -1
  19. package/build/module/index.js +1 -0
  20. package/build/module/middleware.js +11 -11
  21. package/build/module/model/index.d.ts +24 -0
  22. package/build/module/model/index.js +316 -0
  23. package/build/module/model/property.d.ts +5 -0
  24. package/build/module/model/property.js +96 -0
  25. package/build/module/model/types.d.ts +73 -0
  26. package/build/module/model/types.js +230 -0
  27. package/build/module/types.d.ts +6 -11
  28. package/build/module/types.js +2 -25
  29. package/build/module/xml.d.ts +22 -4
  30. package/build/module/xml.js +36 -15
  31. package/package.json +8 -6
  32. package/.eslintignore +0 -3
  33. package/.eslintrc.js +0 -6
  34. package/.gitignore +0 -2
  35. package/.vscode/launch.json +0 -21
  36. package/.vscode/settings.json +0 -3
  37. package/build/main/model.spec.d.ts +0 -1
  38. package/build/main/model.spec.js +0 -261
  39. package/build/module/model.d.ts +0 -71
  40. package/build/module/model.js +0 -466
  41. package/build/module/model.spec.d.ts +0 -1
  42. package/build/module/model.spec.js +0 -76
  43. package/build/module/xml-from-object.d.ts +0 -11
  44. package/build/module/xml-from-object.js +0 -58
  45. package/build/module/xml-from-object.spec.d.ts +0 -1
  46. package/build/module/xml-from-object.spec.js +0 -104
  47. package/build/module/xml-to-object.d.ts +0 -11
  48. package/build/module/xml-to-object.js +0 -55
  49. package/register-ts-node.js +0 -9
  50. package/src/defaults/index.ts +0 -181
  51. package/src/defaults/models.ts +0 -45
  52. package/src/index.ts +0 -6
  53. package/src/middleware.ts +0 -34
  54. package/src/model/index.ts +0 -245
  55. package/src/model/property.ts +0 -104
  56. package/src/model/types.ts +0 -99
  57. package/src/model.spec.ts +0 -178
  58. package/src/types.ts +0 -8
  59. package/src/xml.ts +0 -80
  60. package/tsconfig.json +0 -106
  61. package/tsconfig.module.json +0 -9
  62. package/yarn.lock +0 -2217
@@ -1,13 +1,14 @@
1
- import { PropDecoratorOptions, TagnameFromPropertyResolver } from "../model";
2
- import type { InstantiateHandler } from "../model";
3
- import { ClassType } from "../types";
4
- declare type defaults = {
5
- instantiate: InstantiateHandler<unknown>;
6
- tagnameFromClass: (ctx: {
7
- class: ClassType;
8
- }) => string;
9
- tagnameFromProperty: TagnameFromPropertyResolver;
10
- handleProperty: Required<PropDecoratorOptions>["handleProperty"];
1
+ import type { XMLModelPropertyOptions } from "../model/types";
2
+ import type { XMLModelOptions, XMLModel } from "../model/types";
3
+ declare type defaults<T = any> = {
4
+ fromXML: Required<XMLModelOptions<T>>["fromXML"]["middlewares"][number];
5
+ propertySourceElementsFilter: XMLModelPropertyOptions<T>["isSourceElement"];
6
+ propertyResolveSourceElements: XMLModelPropertyOptions<T>["resolveElements"];
7
+ propertyFromXML: Required<XMLModelPropertyOptions<T>>["fromXML"];
8
+ toXML: Required<XMLModelOptions<T>>["toXML"]["middlewares"][number];
9
+ tagnameFromModel: (model: XMLModel) => string;
10
+ tagnameFromProperty: (property: XMLModelPropertyOptions<T>) => string;
11
+ propertyToXML: Required<XMLModelPropertyOptions<T>>["toXML"];
11
12
  };
12
13
  export declare const defaults: defaults;
13
14
  export {};
@@ -13,59 +13,152 @@ const __RΦ = { m: (k, v) => (t, ...a) => t && Reflect.metadata ? Reflect.metada
13
13
  __RΦ.t[id] = t = l;
14
14
  }
15
15
  return t;
16
- }, t: { [833]: { RΦ: t => ({ TΦ: "&", t: [__RΦ.a(813), __RΦ.a(832)] }) }, [813]: { LΦ: t => LΦ_0.IΦXMLFromObjectPropHandlerContext }, [832]: { RΦ: t => ({ TΦ: "O", m: [{ n: "type", f: "", t: __RΦ.a(812) }] }) }, [812]: { LΦ: t => Object }, [22]: { RΦ: t => ({ TΦ: "V" }) }, [1044]: { RΦ: t => ({ TΦ: "&", t: [__RΦ.a(813), __RΦ.a(1043)] }) }, [1043]: { RΦ: t => ({ TΦ: "O", m: [{ n: "type", f: "", t: __RΦ.a(812) }] }) }, [4]: { RΦ: t => ({ TΦ: "~" }) } } };
17
- import { addElement as addXMLElement } from "../xml";
18
- import { findModel, } from "../model";
16
+ }, t: {} };
17
+ import { getModel } from "../model";
19
18
  import kebabCase from "lodash/kebabCase";
20
- import * as LΦ_0 from "../model";
21
- function handleClassProperty(context) {
22
- const propModel = findModel(context.type.class);
23
- if (propModel) {
24
- const el = propModel.toXMLElement(context.value);
25
- if (context.tagname)
26
- el.name = context.tagname;
27
- addXMLElement(context.xml, el);
28
- }
29
- }
30
- __RΦ.m("rt:p", [{ n: "context", t: () => __RΦ.a(833), v: null }])(handleClassProperty);
31
- __RΦ.m("rt:f", "F")(handleClassProperty);
32
- __RΦ.m("rt:t", () => __RΦ.a(22))(handleClassProperty);
33
- function handleClassArrayProperty(context) {
34
- const elementModel = findModel(context.type.elementType.class);
35
- if (elementModel) {
36
- const xmlEl = {
37
- type: "element",
38
- elements: [],
39
- };
40
- context.value.forEach(__RΦ.f((arrayEl) => {
41
- addXMLElement(xmlEl, elementModel.toXMLElement(arrayEl));
42
- }, [__RΦ.m("rt:p", [{ n: "arrayEl", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], ""));
43
- if (context.tagname)
44
- xmlEl.name = context.tagname;
45
- addXMLElement(context.xml, xmlEl);
46
- }
47
- }
48
- __RΦ.m("rt:p", [{ n: "context", t: () => __RΦ.a(1044), v: null }])(handleClassArrayProperty);
49
- __RΦ.m("rt:f", "F")(handleClassArrayProperty);
50
- __RΦ.m("rt:t", () => __RΦ.a(22))(handleClassArrayProperty);
51
19
  export const defaults = {
52
- instantiate() {
53
- throw new Error("you should define defaults.instantiate yourself or provide an instantiate function to @Model() decorator's options");
20
+ fromXML() {
21
+ throw new TypeError("you should define 'defaults.fromXML' yourself or provide a 'fromXML' function to @Model() decorator's options");
54
22
  },
55
- tagnameFromClass(ctx) {
56
- return kebabCase(ctx.class.name);
23
+ propertyResolveSourceElements(context) {
24
+ // We assume context.xml.elements is a single tag containing all the props
25
+ // FIXME: is it safe ?
26
+ const innerElements = context.xml.elements[0]?.elements || [];
27
+ return innerElements.filter((el) => context.property.isSourceElement(el, context));
57
28
  },
58
- tagnameFromProperty(context) {
59
- return kebabCase(context.property);
29
+ propertySourceElementsFilter(element, context) {
30
+ return context.property.tagname === element.name;
60
31
  },
61
- /* Handle Property */
62
- handleProperty(context) {
63
- const type = context.type;
32
+ propertyFromXML(context) {
33
+ // TODO: handle inline
34
+ const prop = context.property;
35
+ const elements = context.elements;
36
+ if (prop.model) {
37
+ return prop.model.fromXML({ elements });
38
+ }
39
+ const type = context.property.reflected.type;
40
+ if (prop.reflected.isOptional && elements.length === 0) {
41
+ return undefined;
42
+ }
64
43
  if (type.is("class")) {
65
- handleClassProperty(context);
44
+ const model = getModel(type.class);
45
+ return model.fromXML({ elements: context.elements });
46
+ }
47
+ else if (type.is("array")) {
48
+ let arrayEl = {};
49
+ if (!prop.inline &&
50
+ elements.length === 1 &&
51
+ elements[0].name === prop.tagname) {
52
+ // we assume our array is contained in a root tag
53
+ arrayEl = elements[0];
54
+ }
55
+ else if (prop.inline) {
56
+ // we assume our array is contained in xml.elements
57
+ arrayEl = { elements };
58
+ }
59
+ const els = arrayEl.elements || [];
60
+ const elType = type.elementType;
61
+ if (elType.is("class")) {
62
+ const model = getModel(elType.class);
63
+ const xmlInstances = els.map((el) => ({
64
+ elements: [el],
65
+ }));
66
+ return xmlInstances.map((xml) => model.fromXML(xml));
67
+ }
68
+ }
69
+ else if (type.is("union") &&
70
+ type.types.length &&
71
+ type.types[0].is("literal")) {
72
+ const firstType = type.types[0];
73
+ if (firstType.is("literal")) {
74
+ const firstTypeCtor = firstType.value.constructor;
75
+ if (type.types.every((type) => type.is("literal") && type.value.constructor === firstTypeCtor)) {
76
+ // all elements of unions are litteral with same type
77
+ const model = getModel(firstTypeCtor);
78
+ return model.fromXML({ elements });
79
+ }
80
+ }
81
+ }
82
+ // TODO: should warn ???
83
+ return undefined;
84
+ },
85
+ /* Object -> XML */
86
+ toXML({ properties, model }) {
87
+ const elements = [];
88
+ model.resolveAllProperties().forEach((prop) => {
89
+ if (prop.name in properties && typeof prop.name !== "symbol") {
90
+ // FIXME: prop.name should never be a symbol anyway
91
+ const _xml = properties[prop.name];
92
+ _xml.elements.forEach((el) => {
93
+ if (!prop.inline) {
94
+ // overwrite tagnames
95
+ el.name = prop.tagname; // TODO: configurable ?
96
+ }
97
+ elements.push(el);
98
+ });
99
+ }
100
+ });
101
+ return {
102
+ elements: [
103
+ {
104
+ type: "element",
105
+ name: model.options.tagname,
106
+ elements,
107
+ },
108
+ ],
109
+ };
110
+ },
111
+ tagnameFromModel(model) {
112
+ return kebabCase(model.type.name);
113
+ },
114
+ tagnameFromProperty(property) {
115
+ return kebabCase(String(property.name));
116
+ },
117
+ propertyToXML(context) {
118
+ const property = context.property;
119
+ if (property.model) {
120
+ return property.model.toXML(context.value);
66
121
  }
67
- else if (type.is("array") && type.elementType.is("class")) {
68
- handleClassArrayProperty(context);
122
+ const type = property.reflected.type;
123
+ const value = context.value;
124
+ if (property.reflected.isOptional && typeof value === "undefined") {
125
+ return { elements: [] }; // FIXME should return unefined ???
69
126
  }
127
+ const getXML = () => {
128
+ if (type.is("class")) {
129
+ const model = getModel(type.class);
130
+ return model.toXML(value);
131
+ }
132
+ else if (type.is("array") && type.elementType.is("class")) {
133
+ const elementType = type.elementType;
134
+ if (elementType.is("class")) {
135
+ const model = getModel(elementType.class);
136
+ const elements = [];
137
+ value.forEach((el) => elements.push(...model.toXML(el).elements));
138
+ return { elements: [{ type: "element", name: "array", elements }] };
139
+ }
140
+ // TODO: handle other types of array
141
+ }
142
+ else if (type.is("union") &&
143
+ type.types.length &&
144
+ type.types[0].is("literal")) {
145
+ const firstType = type.types[0];
146
+ if (firstType.is("literal")) {
147
+ const firstTypeCtor = firstType.value.constructor;
148
+ if (type.types.every((type) => type.is("literal") && type.value.constructor === firstTypeCtor)) {
149
+ // all elements of unions are litteral with same type
150
+ const model = getModel(firstTypeCtor);
151
+ return model.toXML(context.value);
152
+ }
153
+ }
154
+ }
155
+ // TODO: should warn ???
156
+ return { elements: [] };
157
+ };
158
+ const xml = getXML();
159
+ if (context.property.inline)
160
+ return { elements: xml.elements.map((el) => el.elements || []).flat() };
161
+ else
162
+ return xml;
70
163
  },
71
164
  };
@@ -13,15 +13,46 @@ const __RΦ = { m: (k, v) => (t, ...a) => t && Reflect.metadata ? Reflect.metada
13
13
  __RΦ.t[id] = t = l;
14
14
  }
15
15
  return t;
16
- }, t: { [4]: { RΦ: t => ({ TΦ: "~" }) }, [384]: { LΦ: t => LΦ_0.IΦElement }, [13]: { LΦ: t => String }, [14]: { LΦ: t => Number } } };
16
+ }, t: { [4]: { RΦ: t => ({ TΦ: "~" }) }, [103]: { RΦ: t => ({ TΦ: "O", m: [{ n: "elements", f: "", t: __RΦ.a(102) }] }) }, [102]: { RΦ: t => ({ TΦ: "[", e: __RΦ.a(101) }) }, [101]: { LΦ: t => LΦ_0.IΦElement }, [13]: { LΦ: t => String }, [14]: { LΦ: t => Number }, [1718]: { RΦ: t => ({ TΦ: "O", m: [{ n: "elements", f: "", t: __RΦ.a(3141) }] }) }, [3141]: { RΦ: t => ({ TΦ: "[", e: __RΦ.a(3139) }) }, [3139]: { RΦ: t => ({ TΦ: "O", m: [{ n: "type", f: "", t: __RΦ.a(13) }, { n: "name", f: "", t: __RΦ.a(13) }] }) }, [20]: { LΦ: t => Boolean } } };
17
17
  import { createModel } from "../model";
18
- import { getContent as getXMLContent, fromContent as xmlFromContent, } from "../xml";
18
+ import { getContent, fromContent } from "../xml";
19
19
  import * as LΦ_0 from "xml-js/types";
20
+ // string is <string>value</string>
20
21
  createModel(String, {
21
- toXML: __RΦ.f((ctx) => (ctx.xml = xmlFromContent(ctx.object)), [__RΦ.m("rt:p", [{ n: "ctx", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(384))], "toXML"),
22
- instantiate: __RΦ.f((ctx) => String(getXMLContent(ctx.xml)), [__RΦ.m("rt:p", [{ n: "ctx", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(13))], "instantiate"),
22
+ toXML: __RΦ.f((ctx) => {
23
+ return {
24
+ elements: [fromContent(ctx.object, "string")],
25
+ };
26
+ }, [__RΦ.m("rt:p", [{ n: "ctx", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(103))], "toXML"),
27
+ fromXML: __RΦ.f((ctx) => {
28
+ return String(getContent(ctx.xml.elements[0]));
29
+ }, [__RΦ.m("rt:p", [{ n: "ctx", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(13))], "fromXML"),
23
30
  });
31
+ // number is <number>value</number>
24
32
  createModel(Number, {
25
- toXML: __RΦ.f((ctx) => (ctx.xml = xmlFromContent(String(ctx.object))), [__RΦ.m("rt:p", [{ n: "ctx", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(384))], "toXML"),
26
- instantiate: __RΦ.f((ctx) => Number(getXMLContent(ctx.xml)), [__RΦ.m("rt:p", [{ n: "ctx", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(14))], "instantiate"),
33
+ toXML: __RΦ.f((ctx) => {
34
+ return {
35
+ elements: [fromContent(String(ctx.object), "number")],
36
+ };
37
+ }, [__RΦ.m("rt:p", [{ n: "ctx", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(103))], "toXML"),
38
+ fromXML: __RΦ.f((ctx) => {
39
+ return Number(getContent(ctx.xml.elements[0]));
40
+ }, [__RΦ.m("rt:p", [{ n: "ctx", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(14))], "fromXML"),
41
+ });
42
+ // number is <boolean>value</boolean>
43
+ createModel(Boolean, {
44
+ toXML: __RΦ.f((ctx) => {
45
+ return {
46
+ elements: [
47
+ {
48
+ type: "element",
49
+ name: "boolean",
50
+ ...fromContent(String(ctx.object)),
51
+ },
52
+ ],
53
+ };
54
+ }, [__RΦ.m("rt:p", [{ n: "ctx", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(1718))], "toXML"),
55
+ fromXML: __RΦ.f((ctx) => {
56
+ return Boolean(getContent(ctx.xml.elements[0]));
57
+ }, [__RΦ.m("rt:p", [{ n: "ctx", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(20))], "fromXML"),
27
58
  });
@@ -1,3 +1,4 @@
1
- export declare class NoExplicitTypeError extends Error {
2
- constructor(typeName: string, propertyKey: string, parameterIndex?: number, argName?: string);
1
+ export declare class XMLConversionError extends Error {
2
+ origin: unknown;
3
+ constructor(message: string, origin?: XMLConversionError["origin"]);
3
4
  }
@@ -13,25 +13,20 @@ const __RΦ = { m: (k, v) => (t, ...a) => t && Reflect.metadata ? Reflect.metada
13
13
  __RΦ.t[id] = t = l;
14
14
  }
15
15
  return t;
16
- }, t: { [13]: { LΦ: t => String }, [14]: { LΦ: t => Number } } };
17
- export class NoExplicitTypeError extends Error {
18
- constructor(typeName, propertyKey, parameterIndex, argName) {
19
- let errorMessage = `Unable to infer XMLModel type from TypeScript reflection system. You need to provide explicit type for `;
20
- if (argName) {
21
- errorMessage += `argument named '${argName}' of `;
22
- }
23
- else if (parameterIndex !== undefined) {
24
- errorMessage += `parameter #${parameterIndex} of `;
25
- }
26
- errorMessage += `'${propertyKey}' of '${typeName}' class.`;
27
- super(errorMessage);
28
- Object.setPrototypeOf(this, new.target.prototype);
16
+ }, t: { [13]: { LΦ: t => String }, [8]: { RΦ: t => ({ TΦ: "U" }) } } };
17
+ export class XMLConversionError extends Error {
18
+ origin;
19
+ constructor(message, origin) {
20
+ super(message);
21
+ this.origin = origin;
29
22
  }
30
23
  }
31
- (t => __RΦ.t[85] = t)(NoExplicitTypeError);
32
- __RΦ.m("rt:SP", [])(NoExplicitTypeError);
33
- __RΦ.m("rt:P", [])(NoExplicitTypeError);
34
- __RΦ.m("rt:Sm", [])(NoExplicitTypeError);
35
- __RΦ.m("rt:m", [])(NoExplicitTypeError);
36
- __RΦ.m("rt:p", [{ n: "typeName", t: () => __RΦ.a(13), v: null }, { n: "propertyKey", t: () => __RΦ.a(13), v: null }, { n: "parameterIndex", t: () => __RΦ.a(14), v: null, f: "?" }, { n: "argName", t: () => __RΦ.a(13), v: null, f: "?" }])(NoExplicitTypeError);
37
- __RΦ.m("rt:f", "Ce")(NoExplicitTypeError);
24
+ (t => __RΦ.t[85] = t)(XMLConversionError);
25
+ __RΦ.m("rt:SP", [])(XMLConversionError);
26
+ __RΦ.m("rt:P", ["origin"])(XMLConversionError);
27
+ __RΦ.m("rt:Sm", [])(XMLConversionError);
28
+ __RΦ.m("rt:m", [])(XMLConversionError);
29
+ __RΦ.m("rt:p", [{ n: "message", t: () => __RΦ.a(13), v: null }, { n: "origin", t: () => __RΦ.a(8), v: null, f: "?" }])(XMLConversionError);
30
+ __RΦ.m("rt:f", "Ce")(XMLConversionError);
31
+ __RΦ.m("rt:t", () => __RΦ.a(8))(XMLConversionError.prototype, "origin");
32
+ __RΦ.m("rt:f", "P")(XMLConversionError.prototype, "origin");
@@ -1,4 +1,5 @@
1
- export type { XMLElement } from "./types";
1
+ export type { XMLElement, XMLRoot, Constructor } from "./types";
2
+ export { defaults } from "./defaults";
2
3
  export { getModel, createModel, Model, Prop } from "./model";
3
4
  import XML from "./xml";
4
5
  export { XML };
@@ -14,6 +14,7 @@ const __RΦ = { m: (k, v) => (t, ...a) => t && Reflect.metadata ? Reflect.metada
14
14
  }
15
15
  return t;
16
16
  }, t: {} };
17
+ export { defaults } from "./defaults";
17
18
  export { getModel, createModel, Model, Prop } from "./model";
18
19
  import XML from "./xml";
19
20
  export { XML };
@@ -13,19 +13,19 @@ const __RΦ = { m: (k, v) => (t, ...a) => t && Reflect.metadata ? Reflect.metada
13
13
  __RΦ.t[id] = t = l;
14
14
  }
15
15
  return t;
16
- }, t: { [311]: { RΦ: t => ({ TΦ: "|", t: [__RΦ.a(12), __RΦ.a(308)] }) }, [12]: { RΦ: t => ({ TΦ: "n" }) }, [308]: { TΦ: "5", name: "ChainableOptions" }, [314]: { RΦ: t => ({ TΦ: "[", e: __RΦ.a(313) }) }, [313]: { RΦ: t => ({ TΦ: "O", m: [{ n: "__call", f: "", t: __RΦ.a(4) }] }) }, [4]: { RΦ: t => ({ TΦ: "~" }) }, [317]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(308), p: [__RΦ.a(315), __RΦ.a(316)] }) }, [315]: { LΦ: t => Object }, [316]: { LΦ: t => Object }, [331]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(326), p: [__RΦ.a(318), __RΦ.a(22), __RΦ.a(8)] }) }, [326]: { LΦ: t => Object }, [318]: { RΦ: t => ({ TΦ: "O", m: [{ n: "__call", f: "", t: __RΦ.a(4) }] }) }, [22]: { RΦ: t => ({ TΦ: "V" }) }, [8]: { RΦ: t => ({ TΦ: "U" }) }, [343]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(335), p: [__RΦ.a(346), __RΦ.a(1), __RΦ.a(10)] }) }, [335]: { LΦ: t => Object }, [346]: { RΦ: t => ({ TΦ: "O", m: [{ n: "__call", f: "", t: __RΦ.a(4) }] }) }, [1]: { RΦ: t => ({ TΦ: "~" }) }, [10]: { RΦ: t => ({ TΦ: "u" }) }, [341]: { LΦ: t => Object }, [342]: { LΦ: t => Object } } };
16
+ }, t: { [112]: { RΦ: t => ({ TΦ: "|", t: [__RΦ.a(12), __RΦ.a(109)] }) }, [12]: { RΦ: t => ({ TΦ: "n" }) }, [109]: { TΦ: "5", name: "ChainableOptions" }, [115]: { RΦ: t => ({ TΦ: "[", e: __RΦ.a(114) }) }, [114]: { RΦ: t => ({ TΦ: "O", m: [{ n: "__call", f: "", t: __RΦ.a(4) }] }) }, [4]: { RΦ: t => ({ TΦ: "~" }) }, [118]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(109), p: [__RΦ.a(116), __RΦ.a(117)] }) }, [116]: { LΦ: t => Object }, [117]: { LΦ: t => Object }, [137]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(132), p: [__RΦ.a(119), __RΦ.a(22), __RΦ.a(8)] }) }, [132]: { LΦ: t => Object }, [119]: { RΦ: t => ({ TΦ: "O", m: [{ n: "__call", f: "", t: __RΦ.a(4) }] }) }, [22]: { RΦ: t => ({ TΦ: "V" }) }, [8]: { RΦ: t => ({ TΦ: "U" }) }, [149]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(141), p: [__RΦ.a(152), __RΦ.a(1), __RΦ.a(10)] }) }, [141]: { LΦ: t => Object }, [152]: { RΦ: t => ({ TΦ: "O", m: [{ n: "__call", f: "", t: __RΦ.a(4) }] }) }, [1]: { RΦ: t => ({ TΦ: "~" }) }, [10]: { RΦ: t => ({ TΦ: "u" }) }, [147]: { LΦ: t => Object }, [148]: { LΦ: t => Object } } };
17
17
  var IΦChainableOptions = { name: "ChainableOptions", prototype: {}, identity: Symbol("ChainableOptions (interface)") };
18
- (t => __RΦ.t[308] = t)(IΦChainableOptions);
18
+ (t => __RΦ.t[109] = t)(IΦChainableOptions);
19
19
  __RΦ.m("rt:P", ["parent", "middlewares"])(IΦChainableOptions);
20
20
  __RΦ.m("rt:m", [])(IΦChainableOptions);
21
21
  __RΦ.m("rt:f", "I")(IΦChainableOptions);
22
- __RΦ.m("rt:t", () => __RΦ.a(311))(IΦChainableOptions.prototype, "parent");
22
+ __RΦ.m("rt:t", () => __RΦ.a(112))(IΦChainableOptions.prototype, "parent");
23
23
  __RΦ.m("rt:f", "P")(IΦChainableOptions.prototype, "parent");
24
- __RΦ.m("rt:t", () => __RΦ.a(314))(IΦChainableOptions.prototype, "middlewares");
24
+ __RΦ.m("rt:t", () => __RΦ.a(115))(IΦChainableOptions.prototype, "middlewares");
25
25
  __RΦ.m("rt:f", "P")(IΦChainableOptions.prototype, "middlewares");
26
- __RΦ.m("rt:t", () => __RΦ.a(311))(IΦChainableOptions.prototype, "parent");
26
+ __RΦ.m("rt:t", () => __RΦ.a(112))(IΦChainableOptions.prototype, "parent");
27
27
  __RΦ.m("rt:f", "P")(IΦChainableOptions.prototype, "parent");
28
- __RΦ.m("rt:t", () => __RΦ.a(314))(IΦChainableOptions.prototype, "middlewares");
28
+ __RΦ.m("rt:t", () => __RΦ.a(115))(IΦChainableOptions.prototype, "middlewares");
29
29
  __RΦ.m("rt:f", "P")(IΦChainableOptions.prototype, "middlewares");
30
30
  export function* MiddlewareChain(options) {
31
31
  do {
@@ -38,9 +38,9 @@ export function* MiddlewareChain(options) {
38
38
  return;
39
39
  } while (true);
40
40
  }
41
- __RΦ.m("rt:p", [{ n: "options", t: () => __RΦ.a(317), v: null }])(MiddlewareChain);
41
+ __RΦ.m("rt:p", [{ n: "options", t: () => __RΦ.a(118), v: null }])(MiddlewareChain);
42
42
  __RΦ.m("rt:f", "F")(MiddlewareChain);
43
- __RΦ.m("rt:t", () => __RΦ.a(331))(MiddlewareChain);
43
+ __RΦ.m("rt:t", () => __RΦ.a(137))(MiddlewareChain);
44
44
  export function resolve(middlewares, context) {
45
45
  const next = __RΦ.f(() => {
46
46
  const { value: nextMiddleware, done } = middlewares.next();
@@ -52,9 +52,9 @@ export function resolve(middlewares, context) {
52
52
  else {
53
53
  return nextMiddleware(context, next);
54
54
  }
55
- }, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(342))], "next");
55
+ }, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(148))], "next");
56
56
  return next();
57
57
  }
58
- __RΦ.m("rt:p", [{ n: "middlewares", t: () => __RΦ.a(343), v: null }, { n: "context", t: () => __RΦ.a(341), v: null }])(resolve);
58
+ __RΦ.m("rt:p", [{ n: "middlewares", t: () => __RΦ.a(149), v: null }, { n: "context", t: () => __RΦ.a(147), v: null }])(resolve);
59
59
  __RΦ.m("rt:f", "F")(resolve);
60
- __RΦ.m("rt:t", () => __RΦ.a(342))(resolve);
60
+ __RΦ.m("rt:t", () => __RΦ.a(148))(resolve);
@@ -0,0 +1,24 @@
1
+ import "reflect-metadata";
2
+ import type { Constructor } from "typescript-rtti";
3
+ import { XMLModelOptions, XMLModelPropertyOptions, CreateXMLModelOptions } from "./types";
4
+ import { XMLRoot } from "../types";
5
+ export declare class XMLModel<T = any> {
6
+ readonly type: Constructor<T>;
7
+ options: XMLModelOptions<T>;
8
+ constructor(type: Constructor<T>, options: CreateXMLModelOptions<T>);
9
+ fromXML(xml: XMLRoot | string): T;
10
+ toXML(instance: object): XMLRoot;
11
+ get reflectedClass(): import("typescript-rtti").ReflectedClass<Constructor<T>>;
12
+ resolveAllProperties(): Map<string, XMLModelPropertyOptions<any> & {
13
+ model: any;
14
+ }>;
15
+ }
16
+ export declare function createModel<T>(type: Constructor<T>, options: CreateXMLModelOptions<T>): XMLModel<T>;
17
+ declare type ModelID<T> = Constructor<T>;
18
+ export declare const Models: Map<ModelID<unknown>, XMLModel<unknown>>;
19
+ export declare function findModel<T>(id: ModelID<T>): XMLModel<T> | undefined;
20
+ export declare function getModel<T>(id: ModelID<T>): XMLModel<T>;
21
+ declare function ModelDecoratorFactory<T>(options?: CreateXMLModelOptions<T>): (constructor: Constructor<T>) => void;
22
+ export { ModelDecoratorFactory as Model };
23
+ export { Prop } from "./property";
24
+ import "../defaults/models";