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.
- package/build/main/defaults/index.js +22 -16
- package/build/main/defaults/models.js +4 -4
- package/build/main/errors.d.ts +4 -0
- package/build/main/errors.js +35 -0
- package/build/main/middleware.js +11 -11
- package/build/main/model/index.d.ts +7 -9
- package/build/main/model/index.js +94 -72
- package/build/main/model/property.js +25 -23
- package/build/main/model/types.d.ts +5 -1
- package/build/main/model/types.js +86 -70
- package/build/main/xml.d.ts +2 -0
- package/build/main/xml.js +20 -10
- package/build/module/defaults/index.d.ts +11 -10
- package/build/module/defaults/index.js +139 -46
- package/build/module/defaults/models.js +37 -6
- package/build/module/errors.d.ts +3 -2
- package/build/module/errors.js +15 -20
- package/build/module/index.d.ts +2 -1
- package/build/module/index.js +1 -0
- package/build/module/middleware.js +11 -11
- package/build/module/model/index.d.ts +24 -0
- package/build/module/model/index.js +316 -0
- package/build/module/model/property.d.ts +5 -0
- package/build/module/model/property.js +96 -0
- package/build/module/model/types.d.ts +73 -0
- package/build/module/model/types.js +230 -0
- package/build/module/types.d.ts +6 -11
- package/build/module/types.js +2 -25
- package/build/module/xml.d.ts +22 -4
- package/build/module/xml.js +36 -15
- package/package.json +8 -6
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -6
- package/.gitignore +0 -2
- package/.vscode/launch.json +0 -21
- package/.vscode/settings.json +0 -3
- package/build/main/model.spec.d.ts +0 -1
- package/build/main/model.spec.js +0 -261
- package/build/module/model.d.ts +0 -71
- package/build/module/model.js +0 -466
- package/build/module/model.spec.d.ts +0 -1
- package/build/module/model.spec.js +0 -76
- package/build/module/xml-from-object.d.ts +0 -11
- package/build/module/xml-from-object.js +0 -58
- package/build/module/xml-from-object.spec.d.ts +0 -1
- package/build/module/xml-from-object.spec.js +0 -104
- package/build/module/xml-to-object.d.ts +0 -11
- package/build/module/xml-to-object.js +0 -55
- package/register-ts-node.js +0 -9
- package/src/defaults/index.ts +0 -181
- package/src/defaults/models.ts +0 -45
- package/src/index.ts +0 -6
- package/src/middleware.ts +0 -34
- package/src/model/index.ts +0 -245
- package/src/model/property.ts +0 -104
- package/src/model/types.ts +0 -99
- package/src/model.spec.ts +0 -178
- package/src/types.ts +0 -8
- package/src/xml.ts +0 -80
- package/tsconfig.json +0 -106
- package/tsconfig.module.json +0 -9
- package/yarn.lock +0 -2217
|
@@ -34,12 +34,15 @@ exports.defaults = {
|
|
|
34
34
|
return innerElements.filter((el) => context.property.isSourceElement(el, context));
|
|
35
35
|
},
|
|
36
36
|
propertySourceElementsFilter(element, context) {
|
|
37
|
-
return context.property.tagname
|
|
37
|
+
return context.property.tagname === element.name;
|
|
38
38
|
},
|
|
39
39
|
propertyFromXML(context) {
|
|
40
40
|
// TODO: handle inline
|
|
41
41
|
const prop = context.property;
|
|
42
42
|
const elements = context.elements;
|
|
43
|
+
if (prop.model) {
|
|
44
|
+
return prop.model.fromXML({ elements });
|
|
45
|
+
}
|
|
43
46
|
const type = context.property.reflected.type;
|
|
44
47
|
if (prop.reflected.isOptional && elements.length === 0) {
|
|
45
48
|
return undefined;
|
|
@@ -56,20 +59,18 @@ exports.defaults = {
|
|
|
56
59
|
// we assume our array is contained in a root tag
|
|
57
60
|
arrayEl = elements[0];
|
|
58
61
|
}
|
|
59
|
-
else if (prop.inline
|
|
60
|
-
elements.every((el) => el.name === prop.tagname)) {
|
|
62
|
+
else if (prop.inline) {
|
|
61
63
|
// we assume our array is contained in xml.elements
|
|
62
64
|
arrayEl = { elements };
|
|
63
65
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
66
|
+
const els = arrayEl.elements || [];
|
|
67
|
+
const elType = type.elementType;
|
|
68
|
+
if (elType.is("class")) {
|
|
69
|
+
const model = (0, model_1.getModel)(elType.class);
|
|
70
|
+
const xmlInstances = els.map((el) => ({
|
|
71
|
+
elements: [el],
|
|
72
|
+
}));
|
|
73
|
+
return xmlInstances.map((xml) => model.fromXML(xml));
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
else if (type.is("union") &&
|
|
@@ -91,14 +92,16 @@ exports.defaults = {
|
|
|
91
92
|
/* Object -> XML */
|
|
92
93
|
toXML({ properties, model }) {
|
|
93
94
|
const elements = [];
|
|
94
|
-
model.
|
|
95
|
+
model.resolveAllProperties().forEach((prop) => {
|
|
95
96
|
if (prop.name in properties && typeof prop.name !== "symbol") {
|
|
96
97
|
// FIXME: prop.name should never be a symbol anyway
|
|
97
98
|
const _xml = properties[prop.name];
|
|
98
|
-
// overwrite tagnames
|
|
99
99
|
_xml.elements.forEach((el) => {
|
|
100
|
-
(
|
|
101
|
-
|
|
100
|
+
if (!prop.inline) {
|
|
101
|
+
// overwrite tagnames
|
|
102
|
+
el.name = prop.tagname; // TODO: configurable ?
|
|
103
|
+
}
|
|
104
|
+
elements.push(el);
|
|
102
105
|
});
|
|
103
106
|
}
|
|
104
107
|
});
|
|
@@ -120,6 +123,9 @@ exports.defaults = {
|
|
|
120
123
|
},
|
|
121
124
|
propertyToXML(context) {
|
|
122
125
|
const property = context.property;
|
|
126
|
+
if (property.model) {
|
|
127
|
+
return property.model.toXML(context.value);
|
|
128
|
+
}
|
|
123
129
|
const type = property.reflected.type;
|
|
124
130
|
const value = context.value;
|
|
125
131
|
if (property.reflected.isOptional && typeof value === "undefined") {
|
|
@@ -15,7 +15,7 @@ const __RΦ = { m: (k, v) => (t, ...a) => t && Reflect.metadata ? Reflect.metada
|
|
|
15
15
|
__RΦ.t[id] = t = l;
|
|
16
16
|
}
|
|
17
17
|
return t;
|
|
18
|
-
}, t: { [4]: { RΦ: t => ({ TΦ: "~" }) }, [
|
|
18
|
+
}, 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 => require("xml-js/types").IΦElement }, [13]: { LΦ: t => String }, [14]: { LΦ: t => Number }, [1714]: { RΦ: t => ({ TΦ: "O", m: [{ n: "elements", f: "", t: __RΦ.a(3137) }] }) }, [3137]: { RΦ: t => ({ TΦ: "[", e: __RΦ.a(3135) }) }, [3135]: { RΦ: t => ({ TΦ: "O", m: [{ n: "type", f: "", t: __RΦ.a(13) }, { n: "name", f: "", t: __RΦ.a(13) }] }) }, [20]: { LΦ: t => Boolean } } };
|
|
19
19
|
const model_1 = require("../model");
|
|
20
20
|
const xml_1 = require("../xml");
|
|
21
21
|
// string is <string>value</string>
|
|
@@ -24,7 +24,7 @@ const xml_1 = require("../xml");
|
|
|
24
24
|
return {
|
|
25
25
|
elements: [(0, xml_1.fromContent)(ctx.object, "string")],
|
|
26
26
|
};
|
|
27
|
-
}, [__RΦ.m("rt:p", [{ n: "ctx", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(
|
|
27
|
+
}, [__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"),
|
|
28
28
|
fromXML: __RΦ.f((ctx) => {
|
|
29
29
|
return String((0, xml_1.getContent)(ctx.xml.elements[0]));
|
|
30
30
|
}, [__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"),
|
|
@@ -35,7 +35,7 @@ const xml_1 = require("../xml");
|
|
|
35
35
|
return {
|
|
36
36
|
elements: [(0, xml_1.fromContent)(String(ctx.object), "number")],
|
|
37
37
|
};
|
|
38
|
-
}, [__RΦ.m("rt:p", [{ n: "ctx", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(
|
|
38
|
+
}, [__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"),
|
|
39
39
|
fromXML: __RΦ.f((ctx) => {
|
|
40
40
|
return Number((0, xml_1.getContent)(ctx.xml.elements[0]));
|
|
41
41
|
}, [__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"),
|
|
@@ -48,7 +48,7 @@ const xml_1 = require("../xml");
|
|
|
48
48
|
Object.assign({ type: "element", name: "boolean" }, (0, xml_1.fromContent)(String(ctx.object))),
|
|
49
49
|
],
|
|
50
50
|
};
|
|
51
|
-
}, [__RΦ.m("rt:p", [{ n: "ctx", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(
|
|
51
|
+
}, [__RΦ.m("rt:p", [{ n: "ctx", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(1714))], "toXML"),
|
|
52
52
|
fromXML: __RΦ.f((ctx) => {
|
|
53
53
|
return Boolean((0, xml_1.getContent)(ctx.xml.elements[0]));
|
|
54
54
|
}, [__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"),
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.XMLConversionError = void 0;
|
|
4
|
+
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 => {
|
|
5
|
+
let t = __RΦ.t[id];
|
|
6
|
+
if (t === void 0)
|
|
7
|
+
return void 0;
|
|
8
|
+
if (t.RΦ) {
|
|
9
|
+
let r = t.RΦ;
|
|
10
|
+
delete t.RΦ;
|
|
11
|
+
__RΦ.r(t, r(t));
|
|
12
|
+
}
|
|
13
|
+
else if (t.LΦ) {
|
|
14
|
+
let l = t.LΦ();
|
|
15
|
+
delete t.LΦ;
|
|
16
|
+
__RΦ.t[id] = t = l;
|
|
17
|
+
}
|
|
18
|
+
return t;
|
|
19
|
+
}, t: { [13]: { LΦ: t => String }, [8]: { RΦ: t => ({ TΦ: "U" }) } } };
|
|
20
|
+
class XMLConversionError extends Error {
|
|
21
|
+
constructor(message, origin) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.origin = origin;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.XMLConversionError = XMLConversionError;
|
|
27
|
+
(t => __RΦ.t[85] = t)(XMLConversionError);
|
|
28
|
+
__RΦ.m("rt:SP", [])(XMLConversionError);
|
|
29
|
+
__RΦ.m("rt:P", ["origin"])(XMLConversionError);
|
|
30
|
+
__RΦ.m("rt:Sm", [])(XMLConversionError);
|
|
31
|
+
__RΦ.m("rt:m", [])(XMLConversionError);
|
|
32
|
+
__RΦ.m("rt:p", [{ n: "message", t: () => __RΦ.a(13), v: null }, { n: "origin", t: () => __RΦ.a(8), v: null, f: "?" }])(XMLConversionError);
|
|
33
|
+
__RΦ.m("rt:f", "Ce")(XMLConversionError);
|
|
34
|
+
__RΦ.m("rt:t", () => __RΦ.a(8))(XMLConversionError.prototype, "origin");
|
|
35
|
+
__RΦ.m("rt:f", "P")(XMLConversionError.prototype, "origin");
|
package/build/main/middleware.js
CHANGED
|
@@ -16,19 +16,19 @@ const __RΦ = { m: (k, v) => (t, ...a) => t && Reflect.metadata ? Reflect.metada
|
|
|
16
16
|
__RΦ.t[id] = t = l;
|
|
17
17
|
}
|
|
18
18
|
return t;
|
|
19
|
-
}, t: { [
|
|
19
|
+
}, 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 } } };
|
|
20
20
|
var IΦChainableOptions = { name: "ChainableOptions", prototype: {}, identity: Symbol("ChainableOptions (interface)") };
|
|
21
|
-
(t => __RΦ.t[
|
|
21
|
+
(t => __RΦ.t[109] = t)(IΦChainableOptions);
|
|
22
22
|
__RΦ.m("rt:P", ["parent", "middlewares"])(IΦChainableOptions);
|
|
23
23
|
__RΦ.m("rt:m", [])(IΦChainableOptions);
|
|
24
24
|
__RΦ.m("rt:f", "I")(IΦChainableOptions);
|
|
25
|
-
__RΦ.m("rt:t", () => __RΦ.a(
|
|
25
|
+
__RΦ.m("rt:t", () => __RΦ.a(112))(IΦChainableOptions.prototype, "parent");
|
|
26
26
|
__RΦ.m("rt:f", "P")(IΦChainableOptions.prototype, "parent");
|
|
27
|
-
__RΦ.m("rt:t", () => __RΦ.a(
|
|
27
|
+
__RΦ.m("rt:t", () => __RΦ.a(115))(IΦChainableOptions.prototype, "middlewares");
|
|
28
28
|
__RΦ.m("rt:f", "P")(IΦChainableOptions.prototype, "middlewares");
|
|
29
|
-
__RΦ.m("rt:t", () => __RΦ.a(
|
|
29
|
+
__RΦ.m("rt:t", () => __RΦ.a(112))(IΦChainableOptions.prototype, "parent");
|
|
30
30
|
__RΦ.m("rt:f", "P")(IΦChainableOptions.prototype, "parent");
|
|
31
|
-
__RΦ.m("rt:t", () => __RΦ.a(
|
|
31
|
+
__RΦ.m("rt:t", () => __RΦ.a(115))(IΦChainableOptions.prototype, "middlewares");
|
|
32
32
|
__RΦ.m("rt:f", "P")(IΦChainableOptions.prototype, "middlewares");
|
|
33
33
|
function* MiddlewareChain(options) {
|
|
34
34
|
do {
|
|
@@ -42,9 +42,9 @@ function* MiddlewareChain(options) {
|
|
|
42
42
|
} while (true);
|
|
43
43
|
}
|
|
44
44
|
exports.MiddlewareChain = MiddlewareChain;
|
|
45
|
-
__RΦ.m("rt:p", [{ n: "options", t: () => __RΦ.a(
|
|
45
|
+
__RΦ.m("rt:p", [{ n: "options", t: () => __RΦ.a(118), v: null }])(MiddlewareChain);
|
|
46
46
|
__RΦ.m("rt:f", "F")(MiddlewareChain);
|
|
47
|
-
__RΦ.m("rt:t", () => __RΦ.a(
|
|
47
|
+
__RΦ.m("rt:t", () => __RΦ.a(137))(MiddlewareChain);
|
|
48
48
|
function resolve(middlewares, context) {
|
|
49
49
|
const next = __RΦ.f(() => {
|
|
50
50
|
const { value: nextMiddleware, done } = middlewares.next();
|
|
@@ -56,10 +56,10 @@ function resolve(middlewares, context) {
|
|
|
56
56
|
else {
|
|
57
57
|
return nextMiddleware(context, next);
|
|
58
58
|
}
|
|
59
|
-
}, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(
|
|
59
|
+
}, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(148))], "next");
|
|
60
60
|
return next();
|
|
61
61
|
}
|
|
62
62
|
exports.resolve = resolve;
|
|
63
|
-
__RΦ.m("rt:p", [{ n: "middlewares", t: () => __RΦ.a(
|
|
63
|
+
__RΦ.m("rt:p", [{ n: "middlewares", t: () => __RΦ.a(149), v: null }, { n: "context", t: () => __RΦ.a(147), v: null }])(resolve);
|
|
64
64
|
__RΦ.m("rt:f", "F")(resolve);
|
|
65
|
-
__RΦ.m("rt:t", () => __RΦ.a(
|
|
65
|
+
__RΦ.m("rt:t", () => __RΦ.a(148))(resolve);
|
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
import type { Constructor } from "typescript-rtti";
|
|
3
|
-
import { XMLModelOptions } from "./types";
|
|
3
|
+
import { XMLModelOptions, XMLModelPropertyOptions, CreateXMLModelOptions } from "./types";
|
|
4
4
|
import { XMLRoot } from "../types";
|
|
5
|
-
export interface XMLModelConversionOptions<T> {
|
|
6
|
-
fromXML?: XMLModelOptions<T>["fromXML"]["middlewares"][number];
|
|
7
|
-
tagname?: string;
|
|
8
|
-
toXML?: XMLModelOptions<T>["toXML"]["middlewares"][number];
|
|
9
|
-
}
|
|
10
5
|
export declare class XMLModel<T = any> {
|
|
11
6
|
readonly type: Constructor<T>;
|
|
12
7
|
options: XMLModelOptions<T>;
|
|
13
|
-
constructor(type: Constructor<T>, options:
|
|
8
|
+
constructor(type: Constructor<T>, options: CreateXMLModelOptions<T>);
|
|
14
9
|
fromXML(xml: XMLRoot | string): T;
|
|
15
10
|
toXML(instance: object): XMLRoot;
|
|
16
11
|
get reflectedClass(): import("typescript-rtti").ReflectedClass<Constructor<T>>;
|
|
12
|
+
resolveAllProperties(): Map<string, XMLModelPropertyOptions<any> & {
|
|
13
|
+
model: any;
|
|
14
|
+
}>;
|
|
17
15
|
}
|
|
18
|
-
export declare function createModel<T>(type: Constructor<T>, options:
|
|
16
|
+
export declare function createModel<T>(type: Constructor<T>, options: CreateXMLModelOptions<T>): XMLModel<T>;
|
|
19
17
|
declare type ModelID<T> = Constructor<T>;
|
|
20
18
|
export declare const Models: Map<ModelID<unknown>, XMLModel<unknown>>;
|
|
21
19
|
export declare function findModel<T>(id: ModelID<T>): XMLModel<T> | undefined;
|
|
22
20
|
export declare function getModel<T>(id: ModelID<T>): XMLModel<T>;
|
|
23
|
-
declare function ModelDecoratorFactory<T>(options?:
|
|
21
|
+
declare function ModelDecoratorFactory<T>(options?: CreateXMLModelOptions<T>): (constructor: Constructor<T>) => void;
|
|
24
22
|
export { ModelDecoratorFactory as Model };
|
|
25
23
|
export { Prop } from "./property";
|
|
26
24
|
import "../defaults/models";
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Prop = exports.Model = exports.getModel = exports.findModel = exports.Models = exports.createModel = exports.XMLModel =
|
|
6
|
+
exports.Prop = exports.Model = exports.getModel = exports.findModel = exports.Models = exports.createModel = exports.XMLModel = void 0;
|
|
7
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
8
|
let t = __RΦ.t[id];
|
|
9
9
|
if (t === void 0)
|
|
@@ -19,7 +19,7 @@ const __RΦ = { m: (k, v) => (t, ...a) => t && Reflect.metadata ? Reflect.metada
|
|
|
19
19
|
__RΦ.t[id] = t = l;
|
|
20
20
|
}
|
|
21
21
|
return t;
|
|
22
|
-
}, t: { [
|
|
22
|
+
}, t: { [524]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(194), p: [__RΦ.a(495)] }) }, [194]: { LΦ: t => require("typescript-rtti/dist").IΦConstructor }, [495]: { LΦ: t => Object }, [1732]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(194), p: [__RΦ.a(8)] }) }, [8]: { RΦ: t => ({ TΦ: "U" }) }, [1735]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(132), p: [__RΦ.a(1732), __RΦ.a(22), __RΦ.a(8)] }) }, [132]: { LΦ: t => Object }, [22]: { RΦ: t => ({ TΦ: "V" }) }, [497]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(494), p: [__RΦ.a(1)] }) }, [494]: { TΦ: "5", name: "XMLModel" }, [1]: { RΦ: t => ({ TΦ: "~" }) }, [1758]: { RΦ: t => ({ TΦ: "|", t: [__RΦ.a(12), __RΦ.a(497)] }) }, [12]: { RΦ: t => ({ TΦ: "n" }) }, [1767]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(1638), p: [__RΦ.a(495)] }) }, [1638]: { LΦ: t => require("./types").IΦCreateXMLModelOptions }, [517]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(514), p: [__RΦ.a(495)] }) }, [514]: { LΦ: t => require("./types").IΦXMLModelOptions }, [1791]: { RΦ: t => ({ TΦ: "|", t: [__RΦ.a(12), __RΦ.a(1313)] }) }, [1313]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(594), p: [__RΦ.a(414), __RΦ.a(1311)] }) }, [594]: { LΦ: t => require("./types").IΦConversionOptions }, [414]: { RΦ: t => ({ TΦ: "m", t: __RΦ.a(415), p: [__RΦ.a(413), __RΦ.a(376)] }) }, [415]: { LΦ: t => Object }, [413]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(372), p: [__RΦ.a(1)] }) }, [372]: { LΦ: t => require("./types").IΦfromXMLContext }, [376]: { LΦ: t => "properties" }, [1311]: { RΦ: t => ({ TΦ: "m", t: __RΦ.a(1312), p: [__RΦ.a(1)] }) }, [1312]: { LΦ: t => Object }, [4]: { RΦ: t => ({ TΦ: "~" }) }, [643]: { RΦ: t => ({ TΦ: "m", t: __RΦ.a(644), p: [__RΦ.a(495)] }) }, [644]: { LΦ: t => Object }, [1801]: { RΦ: t => ({ TΦ: "|", t: [__RΦ.a(12), __RΦ.a(1799)] }) }, [1799]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(594), p: [__RΦ.a(1345), __RΦ.a(1797)] }) }, [1345]: { RΦ: t => ({ TΦ: "m", t: __RΦ.a(1346), p: [__RΦ.a(1344), __RΦ.a(376)] }) }, [1346]: { LΦ: t => Object }, [1344]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(845), p: [__RΦ.a(1)] }) }, [845]: { LΦ: t => require("./types").IΦtoXMLContext }, [1797]: { RΦ: t => ({ TΦ: "m", t: __RΦ.a(1798), p: [__RΦ.a(1)] }) }, [1798]: { LΦ: t => Object }, [875]: { RΦ: t => ({ TΦ: "m", t: __RΦ.a(876), p: [__RΦ.a(495)] }) }, [876]: { LΦ: t => Object }, [20]: { LΦ: t => Boolean }, [646]: { RΦ: t => ({ TΦ: "O", m: [{ n: "fromXML", f: "", t: __RΦ.a(652) }, { n: "toXML", f: "", t: __RΦ.a(883) }, { n: "options", f: "", t: __RΦ.a(1059) }] }) }, [652]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(594), p: [__RΦ.a(648), __RΦ.a(650)] }) }, [648]: { RΦ: t => ({ TΦ: "m", t: __RΦ.a(649), p: [__RΦ.a(598), __RΦ.a(376)] }) }, [649]: { LΦ: t => Object }, [598]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(372), p: [__RΦ.a(515)] }) }, [515]: { LΦ: t => Object }, [650]: { RΦ: t => ({ TΦ: "m", t: __RΦ.a(651), p: [__RΦ.a(515)] }) }, [651]: { LΦ: t => Object }, [883]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(594), p: [__RΦ.a(879), __RΦ.a(881)] }) }, [879]: { RΦ: t => ({ TΦ: "m", t: __RΦ.a(880), p: [__RΦ.a(848), __RΦ.a(376)] }) }, [880]: { LΦ: t => Object }, [848]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(845), p: [__RΦ.a(515)] }) }, [881]: { RΦ: t => ({ TΦ: "m", t: __RΦ.a(882), p: [__RΦ.a(515)] }) }, [882]: { LΦ: t => Object }, [1059]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(1049), p: [__RΦ.a(1057), __RΦ.a(1058)] }) }, [1049]: { LΦ: t => Map }, [1057]: { LΦ: t => Object }, [1058]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(206), p: [__RΦ.a(515)] }) }, [206]: { LΦ: t => require("./types").IΦXMLModelPropertyOptions }, [1817]: { RΦ: t => ({ TΦ: "|", t: [__RΦ.a(12), __RΦ.a(1815)] }) }, [1815]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(594), p: [__RΦ.a(413), __RΦ.a(1)] }) }, [1822]: { RΦ: t => ({ TΦ: "|", t: [__RΦ.a(12), __RΦ.a(1820)] }) }, [1820]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(594), p: [__RΦ.a(1344), __RΦ.a(103)] }) }, [103]: { RΦ: t => ({ TΦ: "O", m: [{ n: "elements", f: "", t: __RΦ.a(102) }] }) }, [102]: { RΦ: t => ({ TΦ: "[", e: __RΦ.a(101) }) }, [101]: { LΦ: t => require("xml-js/types").IΦElement }, [13]: { LΦ: t => String }, [533]: { RΦ: t => ({ TΦ: "|", t: [__RΦ.a(13), __RΦ.a(103)] }) }, [28]: { LΦ: t => Object }, [933]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(929), p: [__RΦ.a(524)] }) }, [929]: { LΦ: t => require("typescript-rtti/dist").ReflectedClass }, [1054]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(1049), p: [__RΦ.a(13), __RΦ.a(1048)] }) }, [1048]: { RΦ: t => ({ TΦ: "&", t: [__RΦ.a(1046), __RΦ.a(1047)] }) }, [1046]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(206), p: [__RΦ.a(1)] }) }, [1047]: { RΦ: t => ({ TΦ: "O", m: [{ n: "model", f: "", t: __RΦ.a(1) }] }) }, [1642]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(194), p: [__RΦ.a(1637)] }) }, [1637]: { LΦ: t => Object }, [1641]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(1638), p: [__RΦ.a(1637)] }) }, [1675]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(494), p: [__RΦ.a(1637)] }) }, [1740]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(194), p: [__RΦ.a(1737)] }) }, [1737]: { LΦ: t => Object }, [1753]: { RΦ: t => ({ TΦ: "|", t: [__RΦ.a(10), __RΦ.a(1752)] }) }, [10]: { RΦ: t => ({ TΦ: "u" }) }, [1752]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(494), p: [__RΦ.a(1737)] }) }, [1954]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(194), p: [__RΦ.a(1953)] }) }, [1953]: { LΦ: t => Object }, [1957]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(494), p: [__RΦ.a(1953)] }) }, [1960]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(1638), p: [__RΦ.a(1959)] }) }, [1959]: { LΦ: t => Object }, [1962]: { RΦ: t => ({ TΦ: "F", r: __RΦ.a(22), p: [{ n: "constructor", t: () => __RΦ.a(1963), v: null }], f: "" }) }, [1963]: { RΦ: t => ({ TΦ: "g", t: __RΦ.a(194), p: [__RΦ.a(1959)] }) } } };
|
|
23
23
|
require("reflect-metadata");
|
|
24
24
|
const typescript_rtti_1 = require("typescript-rtti");
|
|
25
25
|
const middleware_1 = require("../middleware");
|
|
@@ -41,10 +41,12 @@ function* ParentChain(constructor) {
|
|
|
41
41
|
}
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
|
-
__RΦ.m("rt:p", [{ n: "constructor", t: () => __RΦ.a(
|
|
44
|
+
__RΦ.m("rt:p", [{ n: "constructor", t: () => __RΦ.a(1732), v: null }])(ParentChain);
|
|
45
45
|
__RΦ.m("rt:f", "F")(ParentChain);
|
|
46
|
-
__RΦ.m("rt:t", () => __RΦ.a(
|
|
46
|
+
__RΦ.m("rt:t", () => __RΦ.a(1735))(ParentChain);
|
|
47
47
|
function getParentModel(model) {
|
|
48
|
+
if (model.options.parent)
|
|
49
|
+
return model.options.parent;
|
|
48
50
|
for (const constructor of ParentChain(model.type)) {
|
|
49
51
|
const model = findModel(constructor);
|
|
50
52
|
if (model) {
|
|
@@ -53,37 +55,20 @@ function getParentModel(model) {
|
|
|
53
55
|
}
|
|
54
56
|
return null;
|
|
55
57
|
}
|
|
56
|
-
__RΦ.m("rt:p", [{ n: "model", t: () => __RΦ.a(
|
|
58
|
+
__RΦ.m("rt:p", [{ n: "model", t: () => __RΦ.a(497), v: null }])(getParentModel);
|
|
57
59
|
__RΦ.m("rt:f", "F")(getParentModel);
|
|
58
|
-
__RΦ.m("rt:t", () => __RΦ.a(
|
|
59
|
-
var IΦXMLModelConversionOptions = { name: "XMLModelConversionOptions", prototype: {}, identity: Symbol("XMLModelConversionOptions (interface)") };
|
|
60
|
-
exports.IΦXMLModelConversionOptions = IΦXMLModelConversionOptions;
|
|
61
|
-
(t => __RΦ.t[1186] = t)(IΦXMLModelConversionOptions);
|
|
62
|
-
__RΦ.m("rt:P", ["fromXML", "tagname", "toXML"])(IΦXMLModelConversionOptions);
|
|
63
|
-
__RΦ.m("rt:m", [])(IΦXMLModelConversionOptions);
|
|
64
|
-
__RΦ.m("rt:f", "Ie")(IΦXMLModelConversionOptions);
|
|
65
|
-
__RΦ.m("rt:t", () => __RΦ.a(1211))(IΦXMLModelConversionOptions.prototype, "fromXML");
|
|
66
|
-
__RΦ.m("rt:f", "P?")(IΦXMLModelConversionOptions.prototype, "fromXML");
|
|
67
|
-
__RΦ.m("rt:t", () => __RΦ.a(13))(IΦXMLModelConversionOptions.prototype, "tagname");
|
|
68
|
-
__RΦ.m("rt:f", "P?")(IΦXMLModelConversionOptions.prototype, "tagname");
|
|
69
|
-
__RΦ.m("rt:t", () => __RΦ.a(1200))(IΦXMLModelConversionOptions.prototype, "toXML");
|
|
70
|
-
__RΦ.m("rt:f", "P?")(IΦXMLModelConversionOptions.prototype, "toXML");
|
|
71
|
-
__RΦ.m("rt:t", () => __RΦ.a(1211))(IΦXMLModelConversionOptions.prototype, "fromXML");
|
|
72
|
-
__RΦ.m("rt:f", "P?")(IΦXMLModelConversionOptions.prototype, "fromXML");
|
|
73
|
-
__RΦ.m("rt:t", () => __RΦ.a(13))(IΦXMLModelConversionOptions.prototype, "tagname");
|
|
74
|
-
__RΦ.m("rt:f", "P?")(IΦXMLModelConversionOptions.prototype, "tagname");
|
|
75
|
-
__RΦ.m("rt:t", () => __RΦ.a(1200))(IΦXMLModelConversionOptions.prototype, "toXML");
|
|
76
|
-
__RΦ.m("rt:f", "P?")(IΦXMLModelConversionOptions.prototype, "toXML");
|
|
60
|
+
__RΦ.m("rt:t", () => __RΦ.a(1758))(getParentModel);
|
|
77
61
|
class XMLModel {
|
|
78
62
|
constructor(type, options) {
|
|
79
63
|
this.type = type;
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
80
65
|
const model = this;
|
|
81
66
|
let parent = undefined;
|
|
82
67
|
const getParent = __RΦ.f(() => {
|
|
83
68
|
if (typeof parent === "undefined")
|
|
84
69
|
parent = getParentModel(this);
|
|
85
70
|
return parent;
|
|
86
|
-
}, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(
|
|
71
|
+
}, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(1758))], "getParent");
|
|
87
72
|
let propertiesLoaded = false;
|
|
88
73
|
const properties = {
|
|
89
74
|
options: new Map(),
|
|
@@ -94,7 +79,6 @@ class XMLModel {
|
|
|
94
79
|
},
|
|
95
80
|
middlewares: [
|
|
96
81
|
__RΦ.f((context, next) => {
|
|
97
|
-
// TODO: typing
|
|
98
82
|
const record = getParent() ? next() : {};
|
|
99
83
|
properties.options.forEach(__RΦ.f((property) => {
|
|
100
84
|
const xml = context.xml;
|
|
@@ -103,15 +87,20 @@ class XMLModel {
|
|
|
103
87
|
xml,
|
|
104
88
|
property,
|
|
105
89
|
});
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
90
|
+
try {
|
|
91
|
+
record[property.name] = property.fromXML({
|
|
92
|
+
model,
|
|
93
|
+
xml: context.xml,
|
|
94
|
+
property,
|
|
95
|
+
elements,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
throw new errors_1.XMLConversionError(`[Model: ${context.model.type.name}] failed to convert prop <${String(property.name)}> from XML`, error);
|
|
100
|
+
}
|
|
112
101
|
}, [__RΦ.m("rt:p", [{ n: "property", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], ""));
|
|
113
102
|
return record;
|
|
114
|
-
}, [__RΦ.m("rt:p", [{ n: "context", t: () => __RΦ.a(4), v: null }, { n: "next", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(
|
|
103
|
+
}, [__RΦ.m("rt:p", [{ n: "context", t: () => __RΦ.a(4), v: null }, { n: "next", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(643))], ""),
|
|
115
104
|
],
|
|
116
105
|
},
|
|
117
106
|
toXML: {
|
|
@@ -123,26 +112,32 @@ class XMLModel {
|
|
|
123
112
|
__RΦ.f((context, next) => {
|
|
124
113
|
const record = getParent() ? next() : {};
|
|
125
114
|
properties.options.forEach(__RΦ.f((options) => {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
115
|
+
try {
|
|
116
|
+
record[options.name] = options.toXML({
|
|
117
|
+
model,
|
|
118
|
+
object: context.object,
|
|
119
|
+
property: options,
|
|
120
|
+
value: context.object[options.name],
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
throw new errors_1.XMLConversionError(`[Model: ${context.model.type.name}] failed to convert prop <${String(options.name)}> to XML`, error);
|
|
125
|
+
}
|
|
132
126
|
}, [__RΦ.m("rt:p", [{ n: "options", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], ""));
|
|
133
127
|
return record;
|
|
134
|
-
}, [__RΦ.m("rt:p", [{ n: "context", t: () => __RΦ.a(4), v: null }, { n: "next", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(
|
|
128
|
+
}, [__RΦ.m("rt:p", [{ n: "context", t: () => __RΦ.a(4), v: null }, { n: "next", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(875))], ""),
|
|
135
129
|
],
|
|
136
130
|
},
|
|
137
131
|
};
|
|
138
132
|
const loadProperties = __RΦ.f(() => {
|
|
139
|
-
const props = (0, typescript_rtti_1.reflect)(this.type, { TΦ: "c", t: void 0, p: [__RΦ.a(
|
|
133
|
+
const props = (0, typescript_rtti_1.reflect)(this.type, { TΦ: "c", t: void 0, p: [__RΦ.a(524)], r: void 0, tp: [] }).ownProperties.filter(__RΦ.f((prop) => typeof prop.host.constructor.prototype[prop.name] !== "function", [__RΦ.m("rt:p", [{ n: "prop", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(20))], "")); // filter out methods like String.prototype.concat etc... that are seen as properties
|
|
140
134
|
props.forEach(__RΦ.f((property) => {
|
|
141
135
|
const options = (0, property_1.getPropertyConversionOptions)(this.type, property.name);
|
|
142
136
|
if (!options.ignored) {
|
|
143
137
|
properties.options.set(property.name, options);
|
|
144
138
|
}
|
|
145
139
|
}, [__RΦ.m("rt:p", [{ n: "property", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], ""));
|
|
140
|
+
propertiesLoaded = true;
|
|
146
141
|
}, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], "");
|
|
147
142
|
this.options = {
|
|
148
143
|
get properties() {
|
|
@@ -168,9 +163,11 @@ class XMLModel {
|
|
|
168
163
|
return options.tagname || defaults_1.defaults.tagnameFromModel(model);
|
|
169
164
|
},
|
|
170
165
|
};
|
|
166
|
+
if (options.parent)
|
|
167
|
+
this.options.parent = options.parent;
|
|
171
168
|
if (!getParent()) {
|
|
172
|
-
this.options.fromXML.middlewares.push(__RΦ.f((...args) => defaults_1.defaults.fromXML(...args), [__RΦ.m("rt:p", [{ n: "args", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(1))], ""));
|
|
173
|
-
this.options.toXML.middlewares.push(__RΦ.f((...args) => defaults_1.defaults.toXML(...args), [__RΦ.m("rt:p", [{ n: "args", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(
|
|
169
|
+
this.options.fromXML.middlewares.push(__RΦ.f((...args) => defaults_1.defaults.fromXML(...args), [__RΦ.m("rt:p", [{ n: "args", t: () => __RΦ.a(4), v: null, f: "3" }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(1))], ""));
|
|
170
|
+
this.options.toXML.middlewares.push(__RΦ.f((...args) => defaults_1.defaults.toXML(...args), [__RΦ.m("rt:p", [{ n: "args", t: () => __RΦ.a(4), v: null, f: "3" }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(103))], ""));
|
|
174
171
|
}
|
|
175
172
|
if (options.fromXML)
|
|
176
173
|
this.options.fromXML.middlewares.push(options.fromXML);
|
|
@@ -179,6 +176,7 @@ class XMLModel {
|
|
|
179
176
|
}
|
|
180
177
|
fromXML(xml) {
|
|
181
178
|
const _xml = typeof xml === "string" ? xml_1.default.parse(xml) : xml;
|
|
179
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
182
180
|
const model = this;
|
|
183
181
|
const context = {
|
|
184
182
|
xml: _xml,
|
|
@@ -194,9 +192,11 @@ class XMLModel {
|
|
|
194
192
|
return (0, middleware_1.resolve)((0, middleware_1.MiddlewareChain)(this.options.fromXML), context);
|
|
195
193
|
}
|
|
196
194
|
toXML(instance) {
|
|
197
|
-
//
|
|
195
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
198
196
|
const model = this;
|
|
199
|
-
if (instance instanceof this.type ||
|
|
197
|
+
if (instance instanceof this.type ||
|
|
198
|
+
(typeof instance !== "undefined" && instance.constructor === this.type) // FIXME: allow instance to be Undefined ?
|
|
199
|
+
) {
|
|
200
200
|
// intanceof won't work with type "String" for example
|
|
201
201
|
const context = {
|
|
202
202
|
object: instance,
|
|
@@ -205,8 +205,7 @@ class XMLModel {
|
|
|
205
205
|
object: instance,
|
|
206
206
|
model,
|
|
207
207
|
};
|
|
208
|
-
return (0, middleware_1.resolve)((0, middleware_1.MiddlewareChain)(model.options.properties.toXML), propContext
|
|
209
|
-
);
|
|
208
|
+
return (0, middleware_1.resolve)((0, middleware_1.MiddlewareChain)(model.options.properties.toXML), propContext);
|
|
210
209
|
},
|
|
211
210
|
model: this,
|
|
212
211
|
};
|
|
@@ -217,47 +216,69 @@ class XMLModel {
|
|
|
217
216
|
}
|
|
218
217
|
}
|
|
219
218
|
get reflectedClass() {
|
|
220
|
-
return (0, typescript_rtti_1.reflect)(this.type, { TΦ: "c", t: void 0, p: [__RΦ.a(
|
|
219
|
+
return (0, typescript_rtti_1.reflect)(this.type, { TΦ: "c", t: void 0, p: [__RΦ.a(524)], r: void 0, tp: [] });
|
|
220
|
+
}
|
|
221
|
+
resolveAllProperties() {
|
|
222
|
+
const properties = new Map();
|
|
223
|
+
const parent = getParentModel(this);
|
|
224
|
+
if (parent)
|
|
225
|
+
parent
|
|
226
|
+
.resolveAllProperties()
|
|
227
|
+
.forEach(__RΦ.f((prop, key) => properties.set(key, prop), [__RΦ.m("rt:p", [{ n: "prop", t: () => __RΦ.a(4), v: null }, { n: "key", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(1054))], ""));
|
|
228
|
+
this.options.properties.options.forEach(__RΦ.f((options, key) => properties.set(key, new Proxy(options, {
|
|
229
|
+
get: __RΦ.f((target, p, reciever) => {
|
|
230
|
+
if (p === "model")
|
|
231
|
+
return this;
|
|
232
|
+
else
|
|
233
|
+
return Reflect.get(target, p, reciever);
|
|
234
|
+
}, [__RΦ.m("rt:p", [{ n: "target", t: () => __RΦ.a(4), v: null }, { n: "p", t: () => __RΦ.a(4), v: null }, { n: "reciever", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(1))], "get"),
|
|
235
|
+
})), [__RΦ.m("rt:p", [{ n: "options", t: () => __RΦ.a(4), v: null }, { n: "key", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(1054))], ""));
|
|
236
|
+
return properties;
|
|
221
237
|
}
|
|
222
238
|
}
|
|
223
239
|
exports.XMLModel = XMLModel;
|
|
224
|
-
(t => __RΦ.t[
|
|
240
|
+
(t => __RΦ.t[494] = t)(XMLModel);
|
|
225
241
|
__RΦ.m("rt:SP", [])(XMLModel);
|
|
226
242
|
__RΦ.m("rt:P", ["options", "type", "reflectedClass"])(XMLModel);
|
|
227
243
|
__RΦ.m("rt:Sm", [])(XMLModel);
|
|
228
|
-
__RΦ.m("rt:m", ["fromXML", "toXML"])(XMLModel);
|
|
229
|
-
__RΦ.m("rt:p", [{ n: "type", t: () => __RΦ.a(
|
|
244
|
+
__RΦ.m("rt:m", ["fromXML", "toXML", "resolveAllProperties"])(XMLModel);
|
|
245
|
+
__RΦ.m("rt:p", [{ n: "type", t: () => __RΦ.a(524), v: null, f: "R" }, { n: "options", t: () => __RΦ.a(1767), v: null }])(XMLModel);
|
|
230
246
|
__RΦ.m("rt:f", "Ce")(XMLModel);
|
|
231
|
-
__RΦ.m("rt:t", () => __RΦ.a(
|
|
247
|
+
__RΦ.m("rt:t", () => __RΦ.a(517))(XMLModel.prototype, "options");
|
|
232
248
|
__RΦ.m("rt:f", "P")(XMLModel.prototype, "options");
|
|
233
|
-
__RΦ.m("rt:t", () => __RΦ.a(
|
|
249
|
+
__RΦ.m("rt:t", () => __RΦ.a(1791))(XMLModel.prototype, "parent");
|
|
234
250
|
__RΦ.m("rt:f", "P")(XMLModel.prototype, "parent");
|
|
235
|
-
__RΦ.m("rt:t", () => __RΦ.a(
|
|
251
|
+
__RΦ.m("rt:t", () => __RΦ.a(1801))(XMLModel.prototype, "parent");
|
|
236
252
|
__RΦ.m("rt:f", "P")(XMLModel.prototype, "parent");
|
|
237
|
-
__RΦ.m("rt:t", () => __RΦ.a(
|
|
253
|
+
__RΦ.m("rt:t", () => __RΦ.a(646))(XMLModel.prototype, "properties");
|
|
238
254
|
__RΦ.m("rt:f", "P")(XMLModel.prototype, "properties");
|
|
239
|
-
__RΦ.m("rt:t", () => __RΦ.a(
|
|
255
|
+
__RΦ.m("rt:t", () => __RΦ.a(1817))(XMLModel.prototype, "parent");
|
|
240
256
|
__RΦ.m("rt:f", "P")(XMLModel.prototype, "parent");
|
|
241
|
-
__RΦ.m("rt:t", () => __RΦ.a(
|
|
257
|
+
__RΦ.m("rt:t", () => __RΦ.a(1822))(XMLModel.prototype, "parent");
|
|
242
258
|
__RΦ.m("rt:f", "P")(XMLModel.prototype, "parent");
|
|
243
259
|
__RΦ.m("rt:t", () => __RΦ.a(13))(XMLModel.prototype, "tagname");
|
|
244
260
|
__RΦ.m("rt:f", "P")(XMLModel.prototype, "tagname");
|
|
245
261
|
__RΦ.m("rt:f", "M.")(XMLModel.prototype["fromXML"]);
|
|
246
262
|
((t, p) => __RΦ.m("rt:h", () => typeof t === "object" ? t.constructor : t)(t[p]))(XMLModel.prototype, "fromXML");
|
|
247
|
-
__RΦ.m("rt:p", [{ n: "xml", t: () => __RΦ.a(
|
|
263
|
+
__RΦ.m("rt:p", [{ n: "xml", t: () => __RΦ.a(533), v: null }])(XMLModel.prototype, "fromXML");
|
|
248
264
|
__RΦ.m("rt:f", "M.")(XMLModel.prototype, "fromXML");
|
|
249
|
-
__RΦ.m("rt:t", () => __RΦ.a(
|
|
250
|
-
__RΦ.m("rt:t", () => __RΦ.a(
|
|
265
|
+
__RΦ.m("rt:t", () => __RΦ.a(495))(XMLModel.prototype, "fromXML");
|
|
266
|
+
__RΦ.m("rt:t", () => __RΦ.a(643))(XMLModel.prototype, "properties");
|
|
251
267
|
__RΦ.m("rt:f", "P")(XMLModel.prototype, "properties");
|
|
252
268
|
__RΦ.m("rt:f", "M.")(XMLModel.prototype["toXML"]);
|
|
253
269
|
((t, p) => __RΦ.m("rt:h", () => typeof t === "object" ? t.constructor : t)(t[p]))(XMLModel.prototype, "toXML");
|
|
254
270
|
__RΦ.m("rt:p", [{ n: "instance", t: () => __RΦ.a(28), v: null }])(XMLModel.prototype, "toXML");
|
|
255
271
|
__RΦ.m("rt:f", "M.")(XMLModel.prototype, "toXML");
|
|
256
|
-
__RΦ.m("rt:t", () => __RΦ.a(
|
|
257
|
-
__RΦ.m("rt:t", () => __RΦ.a(
|
|
272
|
+
__RΦ.m("rt:t", () => __RΦ.a(103))(XMLModel.prototype, "toXML");
|
|
273
|
+
__RΦ.m("rt:t", () => __RΦ.a(875))(XMLModel.prototype, "properties");
|
|
258
274
|
__RΦ.m("rt:f", "P")(XMLModel.prototype, "properties");
|
|
259
|
-
__RΦ.m("rt:t", () => __RΦ.a(
|
|
275
|
+
__RΦ.m("rt:t", () => __RΦ.a(933))(XMLModel.prototype, "reflectedClass");
|
|
260
276
|
__RΦ.m("rt:f", "P")(XMLModel.prototype, "reflectedClass");
|
|
277
|
+
__RΦ.m("rt:f", "M.")(XMLModel.prototype["resolveAllProperties"]);
|
|
278
|
+
((t, p) => __RΦ.m("rt:h", () => typeof t === "object" ? t.constructor : t)(t[p]))(XMLModel.prototype, "resolveAllProperties");
|
|
279
|
+
__RΦ.m("rt:p", [])(XMLModel.prototype, "resolveAllProperties");
|
|
280
|
+
__RΦ.m("rt:f", "M.")(XMLModel.prototype, "resolveAllProperties");
|
|
281
|
+
__RΦ.m("rt:t", () => __RΦ.a(1054))(XMLModel.prototype, "resolveAllProperties");
|
|
261
282
|
function createModel(type, options) {
|
|
262
283
|
if (findModel(type)) {
|
|
263
284
|
throw new TypeError(`a model for type ${type.name} already exists`);
|
|
@@ -267,17 +288,17 @@ function createModel(type, options) {
|
|
|
267
288
|
return model;
|
|
268
289
|
}
|
|
269
290
|
exports.createModel = createModel;
|
|
270
|
-
__RΦ.m("rt:p", [{ n: "type", t: () => __RΦ.a(
|
|
291
|
+
__RΦ.m("rt:p", [{ n: "type", t: () => __RΦ.a(1642), v: null }, { n: "options", t: () => __RΦ.a(1641), v: null }])(createModel);
|
|
271
292
|
__RΦ.m("rt:f", "F")(createModel);
|
|
272
|
-
__RΦ.m("rt:t", () => __RΦ.a(
|
|
293
|
+
__RΦ.m("rt:t", () => __RΦ.a(1675))(createModel);
|
|
273
294
|
exports.Models = new Map();
|
|
274
295
|
function findModel(id) {
|
|
275
296
|
return exports.Models.get(id);
|
|
276
297
|
}
|
|
277
298
|
exports.findModel = findModel;
|
|
278
|
-
__RΦ.m("rt:p", [{ n: "id", t: () => __RΦ.a(
|
|
299
|
+
__RΦ.m("rt:p", [{ n: "id", t: () => __RΦ.a(1740), v: null }])(findModel);
|
|
279
300
|
__RΦ.m("rt:f", "F")(findModel);
|
|
280
|
-
__RΦ.m("rt:t", () => __RΦ.a(
|
|
301
|
+
__RΦ.m("rt:t", () => __RΦ.a(1753))(findModel);
|
|
281
302
|
function getModel(id) {
|
|
282
303
|
const model = findModel(id);
|
|
283
304
|
if (model)
|
|
@@ -286,19 +307,20 @@ function getModel(id) {
|
|
|
286
307
|
throw new TypeError(`couln't find model for type ${id.name}`);
|
|
287
308
|
}
|
|
288
309
|
exports.getModel = getModel;
|
|
289
|
-
__RΦ.m("rt:p", [{ n: "id", t: () => __RΦ.a(
|
|
310
|
+
__RΦ.m("rt:p", [{ n: "id", t: () => __RΦ.a(1954), v: null }])(getModel);
|
|
290
311
|
__RΦ.m("rt:f", "F")(getModel);
|
|
291
|
-
__RΦ.m("rt:t", () => __RΦ.a(
|
|
312
|
+
__RΦ.m("rt:t", () => __RΦ.a(1957))(getModel);
|
|
292
313
|
// Model decorator
|
|
293
314
|
function ModelDecoratorFactory(options) {
|
|
294
315
|
return __RΦ.f(function (constructor) {
|
|
295
316
|
findModel(constructor) || createModel(constructor, options || {});
|
|
296
|
-
}, [__RΦ.m("rt:p", [{ n: "constructor", t: () => __RΦ.a(
|
|
317
|
+
}, [__RΦ.m("rt:p", [{ n: "constructor", t: () => __RΦ.a(1963), v: null }]), __RΦ.m("rt:f", "M"), __RΦ.m("rt:t", () => __RΦ.a(22))], "");
|
|
297
318
|
}
|
|
298
319
|
exports.Model = ModelDecoratorFactory;
|
|
299
|
-
__RΦ.m("rt:p", [{ n: "options", t: () => __RΦ.a(
|
|
320
|
+
__RΦ.m("rt:p", [{ n: "options", t: () => __RΦ.a(1960), v: null, f: "?" }])(ModelDecoratorFactory);
|
|
300
321
|
__RΦ.m("rt:f", "F")(ModelDecoratorFactory);
|
|
301
|
-
__RΦ.m("rt:t", () => __RΦ.a(
|
|
322
|
+
__RΦ.m("rt:t", () => __RΦ.a(1962))(ModelDecoratorFactory);
|
|
302
323
|
var property_2 = require("./property");
|
|
303
324
|
Object.defineProperty(exports, "Prop", { enumerable: true, get: function () { return property_2.Prop; } });
|
|
304
325
|
require("../defaults/models");
|
|
326
|
+
const errors_1 = require("../errors");
|