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
package/build/main/model.spec.js
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
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;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
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 => {
|
|
13
|
-
let t = __RΦ.t[id];
|
|
14
|
-
if (t === void 0)
|
|
15
|
-
return void 0;
|
|
16
|
-
if (t.RΦ) {
|
|
17
|
-
let r = t.RΦ;
|
|
18
|
-
delete t.RΦ;
|
|
19
|
-
__RΦ.r(t, r(t));
|
|
20
|
-
}
|
|
21
|
-
else if (t.LΦ) {
|
|
22
|
-
let l = t.LΦ();
|
|
23
|
-
delete t.LΦ;
|
|
24
|
-
__RΦ.t[id] = t = l;
|
|
25
|
-
}
|
|
26
|
-
return t;
|
|
27
|
-
}, t: { [2574]: { 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(2590) }, { n: "propD", f: "", t: __RΦ.a(1562) }, { n: "equals", f: "", t: __RΦ.a(2671) }, { n: "__constructor", f: "", t: __RΦ.a(4) }] }) }, [13]: { LΦ: t => String }, [20]: { LΦ: t => Boolean }, [2590]: { RΦ: t => ({ TΦ: "[", e: __RΦ.a(2588) }) }, [2588]: { TΦ: "5", name: "B" }, [1562]: { RΦ: t => ({ TΦ: "|", t: [__RΦ.a(47), __RΦ.a(117)] }) }, [47]: { LΦ: t => 0 }, [117]: { LΦ: t => 1 }, [2671]: { RΦ: t => ({ TΦ: "O", m: [] }) }, [4]: { RΦ: t => ({ TΦ: "~" }) }, [2522]: { RΦ: t => ({ TΦ: "O", m: [{ n: "name", f: "", t: __RΦ.a(13) }, { n: "nbPages", f: "", t: __RΦ.a(14) }] }) }, [14]: { LΦ: t => Number }, [2482]: { TΦ: "5", name: "Book" }, [2525]: { LΦ: t => Boolean }, [2543]: { RΦ: t => ({ TΦ: "[", e: __RΦ.a(2482) }) }, [2526]: { TΦ: "5", name: "Library" }, [22]: { RΦ: t => ({ TΦ: "V" }) }, [89]: { RΦ: t => ({ TΦ: "m", t: __RΦ.a(90), p: [] }) }, [90]: { LΦ: t => Object }, [2575]: { TΦ: "5", name: "A" } } };
|
|
28
|
-
require("mocha");
|
|
29
|
-
const chai_1 = require("chai");
|
|
30
|
-
const model_1 = require("./model");
|
|
31
|
-
const xml_1 = __importDefault(require("./xml"));
|
|
32
|
-
const typescript_rtti_1 = require("typescript-rtti");
|
|
33
|
-
let Book = class Book {
|
|
34
|
-
constructor(options) {
|
|
35
|
-
this.name = options.name;
|
|
36
|
-
this.nbPages = options.nbPages;
|
|
37
|
-
}
|
|
38
|
-
equals(book) {
|
|
39
|
-
if (this.name !== book.name)
|
|
40
|
-
return false;
|
|
41
|
-
if (this.nbPages !== book.nbPages)
|
|
42
|
-
return false;
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
Book = __decorate([
|
|
47
|
-
(0, model_1.Model)({
|
|
48
|
-
fromXML({ model, properties }) {
|
|
49
|
-
return new model.type(properties);
|
|
50
|
-
},
|
|
51
|
-
})
|
|
52
|
-
], Book);
|
|
53
|
-
(t => __RΦ.t[2482] = t)(Book);
|
|
54
|
-
__RΦ.m("rt:SP", [])(Book);
|
|
55
|
-
__RΦ.m("rt:P", ["name", "nbPages"])(Book);
|
|
56
|
-
__RΦ.m("rt:Sm", [])(Book);
|
|
57
|
-
__RΦ.m("rt:m", ["fromXML", "equals"])(Book);
|
|
58
|
-
__RΦ.m("rt:p", [{ n: "options", t: () => __RΦ.a(2522), v: null }])(Book);
|
|
59
|
-
__RΦ.m("rt:f", "C")(Book);
|
|
60
|
-
__RΦ.m("rt:t", () => __RΦ.a(13))(Book.prototype, "name");
|
|
61
|
-
__RΦ.m("rt:f", "P")(Book.prototype, "name");
|
|
62
|
-
__RΦ.m("rt:t", () => __RΦ.a(14))(Book.prototype, "nbPages");
|
|
63
|
-
__RΦ.m("rt:f", "P")(Book.prototype, "nbPages");
|
|
64
|
-
__RΦ.m("rt:f", "M.")(Book.prototype["equals"]);
|
|
65
|
-
((t, p) => __RΦ.m("rt:h", () => typeof t === "object" ? t.constructor : t)(t[p]))(Book.prototype, "equals");
|
|
66
|
-
__RΦ.m("rt:p", [{ n: "book", t: () => __RΦ.a(2482), v: null }])(Book.prototype, "equals");
|
|
67
|
-
__RΦ.m("rt:f", "M.")(Book.prototype, "equals");
|
|
68
|
-
__RΦ.m("rt:t", () => __RΦ.a(2525))(Book.prototype, "equals");
|
|
69
|
-
let Library = class Library {
|
|
70
|
-
constructor(name, ...books) {
|
|
71
|
-
this.books = [];
|
|
72
|
-
this.name = name;
|
|
73
|
-
this.books.push(...books);
|
|
74
|
-
}
|
|
75
|
-
equals(library) {
|
|
76
|
-
if (this.name !== library.name)
|
|
77
|
-
return false;
|
|
78
|
-
if (this.books.length !== library.books.length)
|
|
79
|
-
return false;
|
|
80
|
-
for (let index = 0; index < this.books.length; index++) {
|
|
81
|
-
if (!this.books[index].equals(library.books[index]))
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
return true;
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
Library = __decorate([
|
|
88
|
-
(0, model_1.Model)({
|
|
89
|
-
fromXML({ model, properties }) {
|
|
90
|
-
return new model.type(properties.name, ...properties.books);
|
|
91
|
-
},
|
|
92
|
-
})
|
|
93
|
-
], Library);
|
|
94
|
-
(t => __RΦ.t[2526] = t)(Library);
|
|
95
|
-
__RΦ.m("rt:SP", [])(Library);
|
|
96
|
-
__RΦ.m("rt:P", ["name", "books"])(Library);
|
|
97
|
-
__RΦ.m("rt:Sm", [])(Library);
|
|
98
|
-
__RΦ.m("rt:m", ["fromXML", "equals"])(Library);
|
|
99
|
-
__RΦ.m("rt:p", [{ n: "name", t: () => __RΦ.a(13), v: null }, { n: "books", t: () => __RΦ.a(2543), v: null }])(Library);
|
|
100
|
-
__RΦ.m("rt:f", "C")(Library);
|
|
101
|
-
__RΦ.m("rt:t", () => __RΦ.a(13))(Library.prototype, "name");
|
|
102
|
-
__RΦ.m("rt:f", "P")(Library.prototype, "name");
|
|
103
|
-
__RΦ.m("rt:t", () => __RΦ.a(2543))(Library.prototype, "books");
|
|
104
|
-
__RΦ.m("rt:f", "P")(Library.prototype, "books");
|
|
105
|
-
__RΦ.m("rt:f", "M.")(Library.prototype["equals"]);
|
|
106
|
-
((t, p) => __RΦ.m("rt:h", () => typeof t === "object" ? t.constructor : t)(t[p]))(Library.prototype, "equals");
|
|
107
|
-
__RΦ.m("rt:p", [{ n: "library", t: () => __RΦ.a(2526), v: null }])(Library.prototype, "equals");
|
|
108
|
-
__RΦ.m("rt:f", "M.")(Library.prototype, "equals");
|
|
109
|
-
__RΦ.m("rt:t", () => __RΦ.a(2525))(Library.prototype, "equals");
|
|
110
|
-
describe("Library Example", __RΦ.f(() => {
|
|
111
|
-
const library = new Library("test");
|
|
112
|
-
for (let i = 1; i <= 4; i++) {
|
|
113
|
-
const book = new Book({ name: `Book #${i}`, nbPages: Math.pow(10, i) });
|
|
114
|
-
library.books.push(book);
|
|
115
|
-
}
|
|
116
|
-
const libraryXMLString = xml_1.default.stringify(xml_1.default.parse(`<library>
|
|
117
|
-
<name>${library.name}</name>
|
|
118
|
-
<books>
|
|
119
|
-
${library.books
|
|
120
|
-
.map(__RΦ.f((book) => ` <book>
|
|
121
|
-
<name>${book.name}</name>
|
|
122
|
-
<nb-pages>${book.nbPages}</nb-pages>
|
|
123
|
-
</book>`, [__RΦ.m("rt:p", [{ n: "book", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(13))], ""))
|
|
124
|
-
.join("")}
|
|
125
|
-
</books>
|
|
126
|
-
</library>`));
|
|
127
|
-
it("Object -> XML", __RΦ.f(() => {
|
|
128
|
-
const xml = (0, model_1.getModel)(Library).toXML(library);
|
|
129
|
-
(0, chai_1.expect)(xml_1.default.stringify(xml)).to.equal(libraryXMLString);
|
|
130
|
-
}, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], ""));
|
|
131
|
-
it("XML -> Object", __RΦ.f(() => {
|
|
132
|
-
const parsedLibrary = (0, model_1.getModel)(Library).fromXML(libraryXMLString);
|
|
133
|
-
(0, chai_1.expect)(parsedLibrary instanceof Library).to.be.true;
|
|
134
|
-
(0, chai_1.expect)(library.equals(parsedLibrary)).to.be.true;
|
|
135
|
-
}, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], ""));
|
|
136
|
-
}, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], ""));
|
|
137
|
-
let A = class A {
|
|
138
|
-
constructor(record) {
|
|
139
|
-
this.propA = "";
|
|
140
|
-
this.propB = true;
|
|
141
|
-
this.propC = [];
|
|
142
|
-
this.propD = 0;
|
|
143
|
-
if (record)
|
|
144
|
-
Object.entries(record).forEach(__RΦ.f(([key, val]) => {
|
|
145
|
-
this[key] = val;
|
|
146
|
-
}, [__RΦ.m("rt:p", [{ n: "[key, val]", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], ""));
|
|
147
|
-
}
|
|
148
|
-
equals(a) {
|
|
149
|
-
//
|
|
150
|
-
if (this.propA !== a.propA ||
|
|
151
|
-
this.propB !== a.propB ||
|
|
152
|
-
this.propC.length !== a.propC.length ||
|
|
153
|
-
this.propD !== a.propD)
|
|
154
|
-
return false;
|
|
155
|
-
for (let i = 0; i < this.propC.length; i++) {
|
|
156
|
-
if (!this.propC[i].equals(a.propC[i]))
|
|
157
|
-
return false;
|
|
158
|
-
}
|
|
159
|
-
return true;
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
__decorate([
|
|
163
|
-
(0, model_1.Prop)({ tagname: "b", inline: true })
|
|
164
|
-
], A.prototype, "propC", void 0);
|
|
165
|
-
__decorate([
|
|
166
|
-
(0, model_1.Prop)({ tagname: "propd" })
|
|
167
|
-
], A.prototype, "propD", void 0);
|
|
168
|
-
A = __decorate([
|
|
169
|
-
(0, model_1.Model)({
|
|
170
|
-
fromXML({ model, properties }) {
|
|
171
|
-
return new model.type(properties);
|
|
172
|
-
},
|
|
173
|
-
})
|
|
174
|
-
], A);
|
|
175
|
-
(t => __RΦ.t[2575] = t)(A);
|
|
176
|
-
__RΦ.m("rt:SP", [])(A);
|
|
177
|
-
__RΦ.m("rt:P", ["propA", "propB", "propC", "propD"])(A);
|
|
178
|
-
__RΦ.m("rt:Sm", [])(A);
|
|
179
|
-
__RΦ.m("rt:m", ["fromXML", "equals"])(A);
|
|
180
|
-
__RΦ.m("rt:p", [{ n: "record", t: () => __RΦ.a(89), v: null, f: "?" }])(A);
|
|
181
|
-
__RΦ.m("rt:f", "C")(A);
|
|
182
|
-
__RΦ.m("rt:t", () => __RΦ.a(13))(A.prototype, "propA");
|
|
183
|
-
__RΦ.m("rt:f", "P")(A.prototype, "propA");
|
|
184
|
-
__RΦ.m("rt:t", () => __RΦ.a(20))(A.prototype, "propB");
|
|
185
|
-
__RΦ.m("rt:f", "P")(A.prototype, "propB");
|
|
186
|
-
__RΦ.m("rt:t", () => __RΦ.a(2590))(A.prototype, "propC");
|
|
187
|
-
__RΦ.m("rt:f", "P")(A.prototype, "propC");
|
|
188
|
-
__RΦ.m("rt:t", () => __RΦ.a(1562))(A.prototype, "propD");
|
|
189
|
-
__RΦ.m("rt:f", "P")(A.prototype, "propD");
|
|
190
|
-
__RΦ.m("rt:f", "M.")(A.prototype["equals"]);
|
|
191
|
-
((t, p) => __RΦ.m("rt:h", () => typeof t === "object" ? t.constructor : t)(t[p]))(A.prototype, "equals");
|
|
192
|
-
__RΦ.m("rt:p", [{ n: "a", t: () => __RΦ.a(2575), v: null }])(A.prototype, "equals");
|
|
193
|
-
__RΦ.m("rt:f", "M.")(A.prototype, "equals");
|
|
194
|
-
__RΦ.m("rt:t", () => __RΦ.a(2525))(A.prototype, "equals");
|
|
195
|
-
let B = class B {
|
|
196
|
-
constructor(record) {
|
|
197
|
-
this.propA = 0;
|
|
198
|
-
if (record)
|
|
199
|
-
Object.entries(record).forEach(__RΦ.f(([key, val]) => {
|
|
200
|
-
this[key] = val;
|
|
201
|
-
}, [__RΦ.m("rt:p", [{ n: "[key, val]", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], ""));
|
|
202
|
-
}
|
|
203
|
-
equals(b) {
|
|
204
|
-
return this.propA === b.propA;
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
B = __decorate([
|
|
208
|
-
(0, model_1.Model)({
|
|
209
|
-
fromXML({ model, properties }) {
|
|
210
|
-
return new model.type(properties);
|
|
211
|
-
},
|
|
212
|
-
})
|
|
213
|
-
], B);
|
|
214
|
-
(t => __RΦ.t[2588] = t)(B);
|
|
215
|
-
__RΦ.m("rt:SP", [])(B);
|
|
216
|
-
__RΦ.m("rt:P", ["propA"])(B);
|
|
217
|
-
__RΦ.m("rt:Sm", [])(B);
|
|
218
|
-
__RΦ.m("rt:m", ["fromXML", "equals"])(B);
|
|
219
|
-
__RΦ.m("rt:p", [{ n: "record", t: () => __RΦ.a(89), v: null, f: "?" }])(B);
|
|
220
|
-
__RΦ.m("rt:f", "C")(B);
|
|
221
|
-
__RΦ.m("rt:t", () => __RΦ.a(14))(B.prototype, "propA");
|
|
222
|
-
__RΦ.m("rt:f", "P")(B.prototype, "propA");
|
|
223
|
-
__RΦ.m("rt:f", "M.")(B.prototype["equals"]);
|
|
224
|
-
((t, p) => __RΦ.m("rt:h", () => typeof t === "object" ? t.constructor : t)(t[p]))(B.prototype, "equals");
|
|
225
|
-
__RΦ.m("rt:p", [{ n: "b", t: () => __RΦ.a(2588), v: null }])(B.prototype, "equals");
|
|
226
|
-
__RΦ.m("rt:f", "M.")(B.prototype, "equals");
|
|
227
|
-
__RΦ.m("rt:t", () => __RΦ.a(20))(B.prototype, "equals");
|
|
228
|
-
describe("Edgy Cases", __RΦ.f(() => {
|
|
229
|
-
const instance = new A();
|
|
230
|
-
for (let i = 0; i < 8; i++) {
|
|
231
|
-
const b = new B();
|
|
232
|
-
b.propA = i;
|
|
233
|
-
instance.propC.push(b);
|
|
234
|
-
}
|
|
235
|
-
const instanceXMLString = xml_1.default.stringify(xml_1.default.parse(`<a>
|
|
236
|
-
<prop-a>${instance.propA}</prop-a>
|
|
237
|
-
<prop-b>${instance.propB}</prop-b>
|
|
238
|
-
${instance.propC.map(__RΦ.f((b) => `<b><prop-a>${b.propA}</prop-a></b>`, [__RΦ.m("rt:p", [{ n: "b", t: () => __RΦ.a(4), v: null }]), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(13))], "")).join("")}
|
|
239
|
-
<propd>${instance.propD}</propd>
|
|
240
|
-
</a>`));
|
|
241
|
-
it("should give right type infos", __RΦ.f(() => {
|
|
242
|
-
const reflectedA = (0, typescript_rtti_1.reflect)(A, { TΦ: "c", t: void 0, p: [__RΦ.a(2574)], r: void 0, tp: [] });
|
|
243
|
-
(0, chai_1.assert)(reflectedA === (0, typescript_rtti_1.reflect)(A, { TΦ: "c", t: void 0, p: [__RΦ.a(2574)], r: void 0, tp: [] }));
|
|
244
|
-
(0, chai_1.expect)(reflectedA.getProperty("propA").type.isClass(String)).to.be.true;
|
|
245
|
-
(0, chai_1.expect)(reflectedA.getProperty("propB").type.isClass(Boolean)).to.be.true;
|
|
246
|
-
const ModelAPropCType = reflectedA.getProperty("propC").type;
|
|
247
|
-
(0, chai_1.expect)(ModelAPropCType.is("array") && ModelAPropCType.elementType.isClass(B)).to.be.true;
|
|
248
|
-
const ModelAPropDType = reflectedA.getProperty("propD").type;
|
|
249
|
-
(0, chai_1.expect)(ModelAPropDType.is("union")).to.be.true;
|
|
250
|
-
}, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], ""));
|
|
251
|
-
it("XML -> Object", __RΦ.f(() => {
|
|
252
|
-
const parsed = (0, model_1.getModel)(A).fromXML(instanceXMLString);
|
|
253
|
-
(0, chai_1.expect)(parsed instanceof A).to.be.true;
|
|
254
|
-
const equals = instance.equals(parsed);
|
|
255
|
-
(0, chai_1.expect)(equals).to.be.true;
|
|
256
|
-
}, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], ""));
|
|
257
|
-
it("Object -> XML", __RΦ.f(() => {
|
|
258
|
-
const xml = (0, model_1.getModel)(A).toXML(instance);
|
|
259
|
-
(0, chai_1.expect)(xml_1.default.stringify(xml)).to.equal(instanceXMLString);
|
|
260
|
-
}, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], ""));
|
|
261
|
-
}, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], ""));
|
package/build/module/model.d.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
import { ReflectedTypeRef } from "typescript-rtti";
|
|
3
|
-
import { XMLToObjectOptions, XMLToObjectMiddlewareContext } from "./xml-to-object";
|
|
4
|
-
import { XMLFromObjectOptions, XMLFromObjectMiddlewareContext } from "./xml-from-object";
|
|
5
|
-
import { ClassType, XMLElement } from "./types";
|
|
6
|
-
declare type ModelProperty = string;
|
|
7
|
-
interface XMLFromObjectPropHandlerContext extends XMLFromObjectMiddlewareContext {
|
|
8
|
-
property: ModelProperty;
|
|
9
|
-
value: unknown;
|
|
10
|
-
type: ReflectedTypeRef;
|
|
11
|
-
tagname: string | null;
|
|
12
|
-
}
|
|
13
|
-
interface XMLToObjectPropHandlerContext extends XMLToObjectMiddlewareContext {
|
|
14
|
-
element: XMLElement;
|
|
15
|
-
}
|
|
16
|
-
export interface PropertyConversionOptions {
|
|
17
|
-
property: ModelProperty;
|
|
18
|
-
type: ReflectedTypeRef;
|
|
19
|
-
forElement: (el: XMLElement) => boolean;
|
|
20
|
-
handleElement: (context: XMLToObjectPropHandlerContext) => void;
|
|
21
|
-
handleProperty: (context: XMLFromObjectMiddlewareContext) => void;
|
|
22
|
-
}
|
|
23
|
-
export interface XMLToObjectInstantiateContext<T> extends XMLToObjectMiddlewareContext {
|
|
24
|
-
class: ClassType;
|
|
25
|
-
}
|
|
26
|
-
export declare type InstantiateHandler<T> = (ctx: XMLToObjectInstantiateContext<T>) => T;
|
|
27
|
-
export interface ObjectConversionOptions {
|
|
28
|
-
fromXML?: XMLToObjectOptions["middlewares"][number];
|
|
29
|
-
instantiate?: InstantiateHandler<unknown>;
|
|
30
|
-
tagname?: string;
|
|
31
|
-
toXML?: XMLFromObjectOptions["middlewares"][number];
|
|
32
|
-
}
|
|
33
|
-
interface ConversionOptions {
|
|
34
|
-
fromXML: XMLToObjectOptions;
|
|
35
|
-
toXML: XMLFromObjectOptions;
|
|
36
|
-
}
|
|
37
|
-
export declare class XMLModel {
|
|
38
|
-
readonly type: ClassType;
|
|
39
|
-
readonly options: ObjectConversionOptions;
|
|
40
|
-
conversionOptions?: ConversionOptions;
|
|
41
|
-
constructor(type: ClassType, options: ObjectConversionOptions);
|
|
42
|
-
private resolveConversionOptions;
|
|
43
|
-
private getConversionOptions;
|
|
44
|
-
recordFromXMLElement(xml: XMLElement): import("./types").UnknownRecord;
|
|
45
|
-
fromXMLElement(xml: XMLElement): unknown;
|
|
46
|
-
toXMLElement(instance: any): XMLElement;
|
|
47
|
-
}
|
|
48
|
-
export declare function createModel(...args: ConstructorParameters<typeof XMLModel>): XMLModel;
|
|
49
|
-
export declare const Models: Map<ClassType<any>, XMLModel>;
|
|
50
|
-
export declare function findModel(type: ClassType): XMLModel | undefined;
|
|
51
|
-
export declare function getModel(type: ClassType): XMLModel;
|
|
52
|
-
declare function ModelDecoratorFactory(options?: ObjectConversionOptions): (constructor: ClassType) => void;
|
|
53
|
-
export { ModelDecoratorFactory as Model };
|
|
54
|
-
export declare type TagnameFromPropertyResolver = (context: {
|
|
55
|
-
property: ModelProperty;
|
|
56
|
-
type: ReflectedTypeRef;
|
|
57
|
-
value: unknown;
|
|
58
|
-
}) => string | null;
|
|
59
|
-
export interface PropDecoratorOptions {
|
|
60
|
-
tagname?: string;
|
|
61
|
-
fromElement?: string | RegExp | ((element: XMLElement) => boolean);
|
|
62
|
-
toTagname?: TagnameFromPropertyResolver | ReturnType<TagnameFromPropertyResolver>;
|
|
63
|
-
toXML?: (context: XMLFromObjectPropHandlerContext) => XMLElement;
|
|
64
|
-
handleProperty?: (context: XMLFromObjectPropHandlerContext) => void;
|
|
65
|
-
fromXML?: (context: XMLToObjectPropHandlerContext) => unknown;
|
|
66
|
-
handleElement?: (context: XMLToObjectPropHandlerContext) => void;
|
|
67
|
-
ignore?: boolean;
|
|
68
|
-
}
|
|
69
|
-
declare function PropDecoratorFactory(options?: PropDecoratorOptions): (prototype: any, property: ModelProperty) => void;
|
|
70
|
-
export { PropDecoratorFactory as Prop };
|
|
71
|
-
import "./defaults/models";
|