xml-model 2.0.0-beta.1 → 2.0.0-beta.3
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/dist/_virtual/_rolldown/runtime.js +8 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +5 -19
- package/dist/model.js +68 -62
- package/dist/node_modules/sax/lib/sax.js +1249 -0
- package/dist/node_modules/xml-js/lib/array-helper.js +13 -0
- package/dist/node_modules/xml-js/lib/index.js +19 -0
- package/dist/node_modules/xml-js/lib/js2xml.js +258 -0
- package/dist/node_modules/xml-js/lib/json2xml.js +22 -0
- package/dist/node_modules/xml-js/lib/options-helper.js +33 -0
- package/dist/node_modules/xml-js/lib/xml2js.js +246 -0
- package/dist/node_modules/xml-js/lib/xml2json.js +26 -0
- package/dist/util/kebab-case.js +24 -13
- package/dist/util/zod.js +16 -16
- package/dist/xml/codec.js +317 -363
- package/dist/xml/index.js +4 -17
- package/dist/xml/model.js +29 -33
- package/dist/xml/schema-meta.js +73 -81
- package/dist/xml/xml-js.d.ts +147 -5
- package/dist/xml/xml-js.js +99 -70
- package/package.json +20 -22
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
3
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
6
|
+
});
|
|
7
|
+
//#endregion
|
|
8
|
+
export { __commonJSMin, __require };
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,21 +1,7 @@
|
|
|
1
|
-
import { isModel, model } from "./model.js";
|
|
2
|
-
import "./xml/
|
|
3
|
-
import { XML, ZXMLCommentNode, ZXMLElementNode, ZXMLNode, ZXMLRoot, ZXMLTextNode } from "./xml/xml-js.js";
|
|
4
|
-
import { normalizeCodecOptions, registerDefault } from "./xml/codec.js";
|
|
1
|
+
import { DATA, isModel, model } from "./model.js";
|
|
2
|
+
import XML, { ZXMLCommentNode, ZXMLElementNode, ZXMLNode, ZXMLRoot, ZXMLTextNode } from "./xml/xml-js.js";
|
|
5
3
|
import { xml } from "./xml/schema-meta.js";
|
|
4
|
+
import { normalizeCodecOptions, registerDefault } from "./xml/codec.js";
|
|
6
5
|
import { xmlModel } from "./xml/model.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
ZXMLCommentNode,
|
|
10
|
-
ZXMLElementNode,
|
|
11
|
-
ZXMLNode,
|
|
12
|
-
ZXMLRoot,
|
|
13
|
-
ZXMLTextNode,
|
|
14
|
-
isModel,
|
|
15
|
-
model,
|
|
16
|
-
normalizeCodecOptions,
|
|
17
|
-
registerDefault,
|
|
18
|
-
xml,
|
|
19
|
-
xmlModel
|
|
20
|
-
};
|
|
21
|
-
//# sourceMappingURL=index.js.map
|
|
6
|
+
import "./xml/index.js";
|
|
7
|
+
export { DATA, XML, ZXMLCommentNode, ZXMLElementNode, ZXMLNode, ZXMLRoot, ZXMLTextNode, isModel, model, normalizeCodecOptions, registerDefault, xml, xmlModel };
|
package/dist/model.js
CHANGED
|
@@ -1,69 +1,75 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
//#region src/model.ts
|
|
3
|
+
var schemaSymbol = Symbol("model:schema");
|
|
4
|
+
/** Marker placed on every class returned by `model()`. Used by `isModel()`. */
|
|
5
|
+
var MODEL_MARKER = Symbol("model:marker");
|
|
6
|
+
/** Stores the raw data object on model instances. */
|
|
7
|
+
var DATA = Symbol("model:data");
|
|
8
|
+
/** Returns true if `cls` is a class produced by `model()` (or a subclass of one). */
|
|
5
9
|
function isModel(cls) {
|
|
6
|
-
|
|
10
|
+
return typeof cls === "function" && MODEL_MARKER in cls;
|
|
7
11
|
}
|
|
8
12
|
function defineFieldAccessors(proto, keys) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
});
|
|
20
|
-
}
|
|
13
|
+
for (const key of keys) Object.defineProperty(proto, key, {
|
|
14
|
+
get() {
|
|
15
|
+
return this[DATA][key];
|
|
16
|
+
},
|
|
17
|
+
set(v) {
|
|
18
|
+
this[DATA][key] = v;
|
|
19
|
+
},
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true
|
|
22
|
+
});
|
|
21
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Generic class factory. Creates a class with typed instance properties
|
|
26
|
+
* and codec-agnostic from()/to() methods.
|
|
27
|
+
*
|
|
28
|
+
* Codec-specific factories (e.g. xmlModel) wrap this and inject named helpers.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* class Book extends model(z.object({ title: z.string() })) {}
|
|
32
|
+
*/
|
|
22
33
|
function model(schema) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
defineFieldAccessors(Base.prototype, Object.keys(schema.def.shape));
|
|
62
|
-
return Base;
|
|
34
|
+
class Base {
|
|
35
|
+
static dataSchema = schema;
|
|
36
|
+
static [MODEL_MARKER] = true;
|
|
37
|
+
static schema() {
|
|
38
|
+
if (!Object.prototype.hasOwnProperty.call(this, schemaSymbol)) this[schemaSymbol] = z.codec(this.dataSchema, z.instanceof(this), {
|
|
39
|
+
decode: (data) => {
|
|
40
|
+
return this.fromData(data);
|
|
41
|
+
},
|
|
42
|
+
encode: (instance) => {
|
|
43
|
+
return instance[DATA];
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return this[schemaSymbol];
|
|
47
|
+
}
|
|
48
|
+
static extend(extension, meta) {
|
|
49
|
+
let extended = this.dataSchema.extend(extension);
|
|
50
|
+
if (meta) extended = extended.meta(meta);
|
|
51
|
+
const Child = class extends this {
|
|
52
|
+
static dataSchema = extended;
|
|
53
|
+
};
|
|
54
|
+
defineFieldAccessors(Child.prototype, Object.keys(extension));
|
|
55
|
+
return Child;
|
|
56
|
+
}
|
|
57
|
+
static fromData(data) {
|
|
58
|
+
return new this(data);
|
|
59
|
+
}
|
|
60
|
+
static toData(instance) {
|
|
61
|
+
const data = instance[DATA];
|
|
62
|
+
if (!data) throw new Error("failed to retrieve instance data");
|
|
63
|
+
return data;
|
|
64
|
+
}
|
|
65
|
+
constructor(data) {
|
|
66
|
+
this[DATA] = data;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
defineFieldAccessors(Base.prototype, Object.keys(schema.def.shape));
|
|
70
|
+
return Base;
|
|
63
71
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
};
|
|
69
|
-
//# sourceMappingURL=model.js.map
|
|
72
|
+
//#endregion
|
|
73
|
+
export { DATA, isModel, model };
|
|
74
|
+
|
|
75
|
+
//# sourceMappingURL=model.js.map
|