xml-model 0.1.2 → 0.2.2
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 +88 -67
- package/build/main/model/property.js +16 -14
- package/build/main/model/types.d.ts +5 -1
- package/build/main/model/types.js +86 -70
- package/build/main/types.d.ts +10 -2
- package/build/main/types.js +34 -1
- package/build/{module/xml.d.ts → main/xml/index.d.ts} +5 -4
- package/build/main/{xml.js → xml/index.js} +29 -19
- package/build/main/xml/xml-js.d.ts +9 -0
- package/build/main/xml/xml-js.js +26 -0
- package/build/module/defaults/index.js +24 -17
- package/build/module/defaults/models.js +6 -10
- package/build/module/errors.d.ts +4 -0
- package/build/module/errors.js +31 -0
- package/build/module/middleware.js +11 -11
- package/build/module/model/index.d.ts +7 -9
- package/build/module/model/index.js +97 -74
- package/build/module/model/property.js +18 -16
- package/build/module/model/types.d.ts +5 -1
- package/build/module/model/types.js +88 -72
- package/build/module/types.d.ts +10 -2
- package/build/module/types.js +33 -2
- package/build/{main/xml.d.ts → module/xml/index.d.ts} +5 -4
- package/build/module/{xml.js → xml/index.js} +26 -18
- package/build/module/xml/xml-js.d.ts +9 -0
- package/build/module/xml/xml-js.js +24 -0
- package/package.json +2 -2
- package/build/main/model.spec.d.ts +0 -1
- package/build/main/model.spec.js +0 -261
- package/build/module/model.spec.d.ts +0 -1
- package/build/module/model.spec.js +0 -259
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: { [2596]: { 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(2612) }, { n: "propD", f: "", t: __RΦ.a(1574) }, { n: "equals", f: "", t: __RΦ.a(2693) }, { n: "__constructor", f: "", t: __RΦ.a(4) }] }) }, [13]: { LΦ: t => String }, [20]: { LΦ: t => Boolean }, [2612]: { RΦ: t => ({ TΦ: "[", e: __RΦ.a(2610) }) }, [2610]: { TΦ: "5", name: "B" }, [1574]: { RΦ: t => ({ TΦ: "|", t: [__RΦ.a(47), __RΦ.a(117)] }) }, [47]: { LΦ: t => 0 }, [117]: { LΦ: t => 1 }, [2693]: { RΦ: t => ({ TΦ: "O", m: [] }) }, [4]: { RΦ: t => ({ TΦ: "~" }) }, [2544]: { RΦ: t => ({ TΦ: "O", m: [{ n: "name", f: "", t: __RΦ.a(13) }, { n: "nbPages", f: "", t: __RΦ.a(14) }] }) }, [14]: { LΦ: t => Number }, [2504]: { TΦ: "5", name: "Book" }, [2547]: { LΦ: t => Boolean }, [2565]: { RΦ: t => ({ TΦ: "[", e: __RΦ.a(2504) }) }, [2548]: { TΦ: "5", name: "Library" }, [22]: { RΦ: t => ({ TΦ: "V" }) }, [89]: { RΦ: t => ({ TΦ: "m", t: __RΦ.a(90), p: [] }) }, [90]: { LΦ: t => Object }, [2597]: { 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[2504] = 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(2544), 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(2504), v: null }])(Book.prototype, "equals");
|
|
67
|
-
__RΦ.m("rt:f", "M.")(Book.prototype, "equals");
|
|
68
|
-
__RΦ.m("rt:t", () => __RΦ.a(2547))(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[2548] = 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(2565), v: null, f: "3" }])(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(2565))(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(2548), v: null }])(Library.prototype, "equals");
|
|
108
|
-
__RΦ.m("rt:f", "M.")(Library.prototype, "equals");
|
|
109
|
-
__RΦ.m("rt:t", () => __RΦ.a(2547))(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[2597] = 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(2612))(A.prototype, "propC");
|
|
187
|
-
__RΦ.m("rt:f", "P")(A.prototype, "propC");
|
|
188
|
-
__RΦ.m("rt:t", () => __RΦ.a(1574))(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(2597), v: null }])(A.prototype, "equals");
|
|
193
|
-
__RΦ.m("rt:f", "M.")(A.prototype, "equals");
|
|
194
|
-
__RΦ.m("rt:t", () => __RΦ.a(2547))(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[2610] = 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(2610), 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(2596)], r: void 0, tp: [] });
|
|
243
|
-
(0, chai_1.assert)(reflectedA === (0, typescript_rtti_1.reflect)(A, { TΦ: "c", t: void 0, p: [__RΦ.a(2596)], 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))], ""));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "mocha";
|
|
@@ -1,259 +0,0 @@
|
|
|
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: { [2600]: { 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(2616) }, { n: "propD", f: "", t: __RΦ.a(1578) }, { n: "equals", f: "", t: __RΦ.a(2697) }, { n: "__constructor", f: "", t: __RΦ.a(4) }] }) }, [13]: { LΦ: t => String }, [20]: { LΦ: t => Boolean }, [2616]: { RΦ: t => ({ TΦ: "[", e: __RΦ.a(2614) }) }, [2614]: { TΦ: "5", name: "B" }, [1578]: { RΦ: t => ({ TΦ: "|", t: [__RΦ.a(47), __RΦ.a(117)] }) }, [47]: { LΦ: t => 0 }, [117]: { LΦ: t => 1 }, [2697]: { RΦ: t => ({ TΦ: "O", m: [] }) }, [4]: { RΦ: t => ({ TΦ: "~" }) }, [2548]: { RΦ: t => ({ TΦ: "O", m: [{ n: "name", f: "", t: __RΦ.a(13) }, { n: "nbPages", f: "", t: __RΦ.a(14) }] }) }, [14]: { LΦ: t => Number }, [2508]: { TΦ: "5", name: "Book" }, [2551]: { LΦ: t => Boolean }, [2569]: { RΦ: t => ({ TΦ: "[", e: __RΦ.a(2508) }) }, [2552]: { TΦ: "5", name: "Library" }, [22]: { RΦ: t => ({ TΦ: "V" }) }, [89]: { RΦ: t => ({ TΦ: "m", t: __RΦ.a(90), p: [] }) }, [90]: { LΦ: t => Object }, [2601]: { TΦ: "5", name: "A" } } };
|
|
23
|
-
import "mocha";
|
|
24
|
-
import { expect, assert } from "chai";
|
|
25
|
-
import { Model, Prop, getModel } from "./model";
|
|
26
|
-
import XML from "./xml";
|
|
27
|
-
import { reflect } from "typescript-rtti";
|
|
28
|
-
let Book = class Book {
|
|
29
|
-
name;
|
|
30
|
-
nbPages;
|
|
31
|
-
constructor(options) {
|
|
32
|
-
this.name = options.name;
|
|
33
|
-
this.nbPages = options.nbPages;
|
|
34
|
-
}
|
|
35
|
-
equals(book) {
|
|
36
|
-
if (this.name !== book.name)
|
|
37
|
-
return false;
|
|
38
|
-
if (this.nbPages !== book.nbPages)
|
|
39
|
-
return false;
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
Book = __decorate([
|
|
44
|
-
Model({
|
|
45
|
-
fromXML({ model, properties }) {
|
|
46
|
-
return new model.type(properties);
|
|
47
|
-
},
|
|
48
|
-
})
|
|
49
|
-
], Book);
|
|
50
|
-
(t => __RΦ.t[2508] = t)(Book);
|
|
51
|
-
__RΦ.m("rt:SP", [])(Book);
|
|
52
|
-
__RΦ.m("rt:P", ["name", "nbPages"])(Book);
|
|
53
|
-
__RΦ.m("rt:Sm", [])(Book);
|
|
54
|
-
__RΦ.m("rt:m", ["fromXML", "equals"])(Book);
|
|
55
|
-
__RΦ.m("rt:p", [{ n: "options", t: () => __RΦ.a(2548), v: null }])(Book);
|
|
56
|
-
__RΦ.m("rt:f", "C")(Book);
|
|
57
|
-
__RΦ.m("rt:t", () => __RΦ.a(13))(Book.prototype, "name");
|
|
58
|
-
__RΦ.m("rt:f", "P")(Book.prototype, "name");
|
|
59
|
-
__RΦ.m("rt:t", () => __RΦ.a(14))(Book.prototype, "nbPages");
|
|
60
|
-
__RΦ.m("rt:f", "P")(Book.prototype, "nbPages");
|
|
61
|
-
__RΦ.m("rt:f", "M.")(Book.prototype["equals"]);
|
|
62
|
-
((t, p) => __RΦ.m("rt:h", () => typeof t === "object" ? t.constructor : t)(t[p]))(Book.prototype, "equals");
|
|
63
|
-
__RΦ.m("rt:p", [{ n: "book", t: () => __RΦ.a(2508), v: null }])(Book.prototype, "equals");
|
|
64
|
-
__RΦ.m("rt:f", "M.")(Book.prototype, "equals");
|
|
65
|
-
__RΦ.m("rt:t", () => __RΦ.a(2551))(Book.prototype, "equals");
|
|
66
|
-
let Library = class Library {
|
|
67
|
-
name;
|
|
68
|
-
books = [];
|
|
69
|
-
constructor(name, ...books) {
|
|
70
|
-
this.name = name;
|
|
71
|
-
this.books.push(...books);
|
|
72
|
-
}
|
|
73
|
-
equals(library) {
|
|
74
|
-
if (this.name !== library.name)
|
|
75
|
-
return false;
|
|
76
|
-
if (this.books.length !== library.books.length)
|
|
77
|
-
return false;
|
|
78
|
-
for (let index = 0; index < this.books.length; index++) {
|
|
79
|
-
if (!this.books[index].equals(library.books[index]))
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
Library = __decorate([
|
|
86
|
-
Model({
|
|
87
|
-
fromXML({ model, properties }) {
|
|
88
|
-
return new model.type(properties.name, ...properties.books);
|
|
89
|
-
},
|
|
90
|
-
})
|
|
91
|
-
], Library);
|
|
92
|
-
(t => __RΦ.t[2552] = t)(Library);
|
|
93
|
-
__RΦ.m("rt:SP", [])(Library);
|
|
94
|
-
__RΦ.m("rt:P", ["name", "books"])(Library);
|
|
95
|
-
__RΦ.m("rt:Sm", [])(Library);
|
|
96
|
-
__RΦ.m("rt:m", ["fromXML", "equals"])(Library);
|
|
97
|
-
__RΦ.m("rt:p", [{ n: "name", t: () => __RΦ.a(13), v: null }, { n: "books", t: () => __RΦ.a(2569), v: null, f: "3" }])(Library);
|
|
98
|
-
__RΦ.m("rt:f", "C")(Library);
|
|
99
|
-
__RΦ.m("rt:t", () => __RΦ.a(13))(Library.prototype, "name");
|
|
100
|
-
__RΦ.m("rt:f", "P")(Library.prototype, "name");
|
|
101
|
-
__RΦ.m("rt:t", () => __RΦ.a(2569))(Library.prototype, "books");
|
|
102
|
-
__RΦ.m("rt:f", "P")(Library.prototype, "books");
|
|
103
|
-
__RΦ.m("rt:f", "M.")(Library.prototype["equals"]);
|
|
104
|
-
((t, p) => __RΦ.m("rt:h", () => typeof t === "object" ? t.constructor : t)(t[p]))(Library.prototype, "equals");
|
|
105
|
-
__RΦ.m("rt:p", [{ n: "library", t: () => __RΦ.a(2552), v: null }])(Library.prototype, "equals");
|
|
106
|
-
__RΦ.m("rt:f", "M.")(Library.prototype, "equals");
|
|
107
|
-
__RΦ.m("rt:t", () => __RΦ.a(2551))(Library.prototype, "equals");
|
|
108
|
-
describe("Library Example", __RΦ.f(() => {
|
|
109
|
-
const library = new Library("test");
|
|
110
|
-
for (let i = 1; i <= 4; i++) {
|
|
111
|
-
const book = new Book({ name: `Book #${i}`, nbPages: Math.pow(10, i) });
|
|
112
|
-
library.books.push(book);
|
|
113
|
-
}
|
|
114
|
-
const libraryXMLString = XML.stringify(XML.parse(`<library>
|
|
115
|
-
<name>${library.name}</name>
|
|
116
|
-
<books>
|
|
117
|
-
${library.books
|
|
118
|
-
.map(__RΦ.f((book) => ` <book>
|
|
119
|
-
<name>${book.name}</name>
|
|
120
|
-
<nb-pages>${book.nbPages}</nb-pages>
|
|
121
|
-
</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))], ""))
|
|
122
|
-
.join("")}
|
|
123
|
-
</books>
|
|
124
|
-
</library>`));
|
|
125
|
-
it("Object -> XML", __RΦ.f(() => {
|
|
126
|
-
const xml = getModel(Library).toXML(library);
|
|
127
|
-
expect(XML.stringify(xml)).to.equal(libraryXMLString);
|
|
128
|
-
}, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], ""));
|
|
129
|
-
it("XML -> Object", __RΦ.f(() => {
|
|
130
|
-
const parsedLibrary = getModel(Library).fromXML(libraryXMLString);
|
|
131
|
-
expect(parsedLibrary instanceof Library).to.be.true;
|
|
132
|
-
expect(library.equals(parsedLibrary)).to.be.true;
|
|
133
|
-
}, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], ""));
|
|
134
|
-
}, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], ""));
|
|
135
|
-
let A = class A {
|
|
136
|
-
propA = "";
|
|
137
|
-
propB = true;
|
|
138
|
-
propC = [];
|
|
139
|
-
propD = 0;
|
|
140
|
-
equals(a) {
|
|
141
|
-
//
|
|
142
|
-
if (this.propA !== a.propA ||
|
|
143
|
-
this.propB !== a.propB ||
|
|
144
|
-
this.propC.length !== a.propC.length ||
|
|
145
|
-
this.propD !== a.propD)
|
|
146
|
-
return false;
|
|
147
|
-
for (let i = 0; i < this.propC.length; i++) {
|
|
148
|
-
if (!this.propC[i].equals(a.propC[i]))
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
return true;
|
|
152
|
-
}
|
|
153
|
-
constructor(record) {
|
|
154
|
-
if (record)
|
|
155
|
-
Object.entries(record).forEach(__RΦ.f(([key, val]) => {
|
|
156
|
-
this[key] = val;
|
|
157
|
-
}, [__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))], ""));
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
__decorate([
|
|
161
|
-
Prop({ tagname: "b", inline: true })
|
|
162
|
-
], A.prototype, "propC", void 0);
|
|
163
|
-
__decorate([
|
|
164
|
-
Prop({ tagname: "propd" })
|
|
165
|
-
], A.prototype, "propD", void 0);
|
|
166
|
-
A = __decorate([
|
|
167
|
-
Model({
|
|
168
|
-
fromXML({ model, properties }) {
|
|
169
|
-
return new model.type(properties);
|
|
170
|
-
},
|
|
171
|
-
})
|
|
172
|
-
], A);
|
|
173
|
-
(t => __RΦ.t[2601] = t)(A);
|
|
174
|
-
__RΦ.m("rt:SP", [])(A);
|
|
175
|
-
__RΦ.m("rt:P", ["propA", "propB", "propC", "propD"])(A);
|
|
176
|
-
__RΦ.m("rt:Sm", [])(A);
|
|
177
|
-
__RΦ.m("rt:m", ["fromXML", "equals"])(A);
|
|
178
|
-
__RΦ.m("rt:p", [{ n: "record", t: () => __RΦ.a(89), v: null, f: "?" }])(A);
|
|
179
|
-
__RΦ.m("rt:f", "C")(A);
|
|
180
|
-
__RΦ.m("rt:t", () => __RΦ.a(13))(A.prototype, "propA");
|
|
181
|
-
__RΦ.m("rt:f", "P")(A.prototype, "propA");
|
|
182
|
-
__RΦ.m("rt:t", () => __RΦ.a(20))(A.prototype, "propB");
|
|
183
|
-
__RΦ.m("rt:f", "P")(A.prototype, "propB");
|
|
184
|
-
__RΦ.m("rt:t", () => __RΦ.a(2616))(A.prototype, "propC");
|
|
185
|
-
__RΦ.m("rt:f", "P")(A.prototype, "propC");
|
|
186
|
-
__RΦ.m("rt:t", () => __RΦ.a(1578))(A.prototype, "propD");
|
|
187
|
-
__RΦ.m("rt:f", "P")(A.prototype, "propD");
|
|
188
|
-
__RΦ.m("rt:f", "M.")(A.prototype["equals"]);
|
|
189
|
-
((t, p) => __RΦ.m("rt:h", () => typeof t === "object" ? t.constructor : t)(t[p]))(A.prototype, "equals");
|
|
190
|
-
__RΦ.m("rt:p", [{ n: "a", t: () => __RΦ.a(2601), v: null }])(A.prototype, "equals");
|
|
191
|
-
__RΦ.m("rt:f", "M.")(A.prototype, "equals");
|
|
192
|
-
__RΦ.m("rt:t", () => __RΦ.a(2551))(A.prototype, "equals");
|
|
193
|
-
let B = class B {
|
|
194
|
-
propA = 0;
|
|
195
|
-
equals(b) {
|
|
196
|
-
return this.propA === b.propA;
|
|
197
|
-
}
|
|
198
|
-
constructor(record) {
|
|
199
|
-
if (record)
|
|
200
|
-
Object.entries(record).forEach(__RΦ.f(([key, val]) => {
|
|
201
|
-
this[key] = val;
|
|
202
|
-
}, [__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))], ""));
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
B = __decorate([
|
|
206
|
-
Model({
|
|
207
|
-
fromXML({ model, properties }) {
|
|
208
|
-
return new model.type(properties);
|
|
209
|
-
},
|
|
210
|
-
})
|
|
211
|
-
], B);
|
|
212
|
-
(t => __RΦ.t[2614] = t)(B);
|
|
213
|
-
__RΦ.m("rt:SP", [])(B);
|
|
214
|
-
__RΦ.m("rt:P", ["propA"])(B);
|
|
215
|
-
__RΦ.m("rt:Sm", [])(B);
|
|
216
|
-
__RΦ.m("rt:m", ["fromXML", "equals"])(B);
|
|
217
|
-
__RΦ.m("rt:p", [{ n: "record", t: () => __RΦ.a(89), v: null, f: "?" }])(B);
|
|
218
|
-
__RΦ.m("rt:f", "C")(B);
|
|
219
|
-
__RΦ.m("rt:t", () => __RΦ.a(14))(B.prototype, "propA");
|
|
220
|
-
__RΦ.m("rt:f", "P")(B.prototype, "propA");
|
|
221
|
-
__RΦ.m("rt:f", "M.")(B.prototype["equals"]);
|
|
222
|
-
((t, p) => __RΦ.m("rt:h", () => typeof t === "object" ? t.constructor : t)(t[p]))(B.prototype, "equals");
|
|
223
|
-
__RΦ.m("rt:p", [{ n: "b", t: () => __RΦ.a(2614), v: null }])(B.prototype, "equals");
|
|
224
|
-
__RΦ.m("rt:f", "M.")(B.prototype, "equals");
|
|
225
|
-
__RΦ.m("rt:t", () => __RΦ.a(20))(B.prototype, "equals");
|
|
226
|
-
describe("Edgy Cases", __RΦ.f(() => {
|
|
227
|
-
const instance = new A();
|
|
228
|
-
for (let i = 0; i < 8; i++) {
|
|
229
|
-
const b = new B();
|
|
230
|
-
b.propA = i;
|
|
231
|
-
instance.propC.push(b);
|
|
232
|
-
}
|
|
233
|
-
const instanceXMLString = XML.stringify(XML.parse(`<a>
|
|
234
|
-
<prop-a>${instance.propA}</prop-a>
|
|
235
|
-
<prop-b>${instance.propB}</prop-b>
|
|
236
|
-
${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("")}
|
|
237
|
-
<propd>${instance.propD}</propd>
|
|
238
|
-
</a>`));
|
|
239
|
-
it("should give right type infos", __RΦ.f(() => {
|
|
240
|
-
const reflectedA = reflect(A, { TΦ: "c", t: void 0, p: [__RΦ.a(2600)], r: void 0, tp: [] });
|
|
241
|
-
assert(reflectedA === reflect(A, { TΦ: "c", t: void 0, p: [__RΦ.a(2600)], r: void 0, tp: [] }));
|
|
242
|
-
expect(reflectedA.getProperty("propA").type.isClass(String)).to.be.true;
|
|
243
|
-
expect(reflectedA.getProperty("propB").type.isClass(Boolean)).to.be.true;
|
|
244
|
-
const ModelAPropCType = reflectedA.getProperty("propC").type;
|
|
245
|
-
expect(ModelAPropCType.is("array") && ModelAPropCType.elementType.isClass(B)).to.be.true;
|
|
246
|
-
const ModelAPropDType = reflectedA.getProperty("propD").type;
|
|
247
|
-
expect(ModelAPropDType.is("union")).to.be.true;
|
|
248
|
-
}, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], ""));
|
|
249
|
-
it("XML -> Object", __RΦ.f(() => {
|
|
250
|
-
const parsed = getModel(A).fromXML(instanceXMLString);
|
|
251
|
-
expect(parsed instanceof A).to.be.true;
|
|
252
|
-
const equals = instance.equals(parsed);
|
|
253
|
-
expect(equals).to.be.true;
|
|
254
|
-
}, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], ""));
|
|
255
|
-
it("Object -> XML", __RΦ.f(() => {
|
|
256
|
-
const xml = getModel(A).toXML(instance);
|
|
257
|
-
expect(XML.stringify(xml)).to.equal(instanceXMLString);
|
|
258
|
-
}, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], ""));
|
|
259
|
-
}, [__RΦ.m("rt:p", []), __RΦ.m("rt:f", "F>"), __RΦ.m("rt:t", () => __RΦ.a(22))], ""));
|