xml-model 2.0.0-beta.7 → 2.0.0-beta.8
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/index.js +2 -2
- package/dist/xml/codec.js +13 -1
- package/dist/xml/index.d.ts +2 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DATA, isModel, model } from "./model.js";
|
|
2
2
|
import XML, { ZXMLCommentNode, ZXMLElementNode, ZXMLNode, ZXMLRoot, ZXMLTextNode } from "./xml/xml-js.js";
|
|
3
3
|
import { xml } from "./xml/schema-meta.js";
|
|
4
|
-
import { XMLCodecError, normalizeCodecOptions, registerDefault, xmlStateSchema } from "./xml/codec.js";
|
|
4
|
+
import { XMLCodecError, normalizeCodecOptions, registerDefault, xmlCodec, xmlStateSchema } from "./xml/codec.js";
|
|
5
5
|
import { xmlModel } from "./xml/model.js";
|
|
6
6
|
import "./xml/index.js";
|
|
7
|
-
export { DATA, XML, XMLCodecError, ZXMLCommentNode, ZXMLElementNode, ZXMLNode, ZXMLRoot, ZXMLTextNode, isModel, model, normalizeCodecOptions, registerDefault, xml, xmlModel, xmlStateSchema };
|
|
7
|
+
export { DATA, XML, XMLCodecError, ZXMLCommentNode, ZXMLElementNode, ZXMLNode, ZXMLRoot, ZXMLTextNode, isModel, model, normalizeCodecOptions, registerDefault, xml, xmlCodec, xmlModel, xmlStateSchema };
|
package/dist/xml/codec.js
CHANGED
|
@@ -499,7 +499,19 @@ registerDefault((schema) => {
|
|
|
499
499
|
});
|
|
500
500
|
}
|
|
501
501
|
});
|
|
502
|
+
function xmlCodec(schema) {
|
|
503
|
+
return z.codec(z.string(), schema, {
|
|
504
|
+
decode(xml) {
|
|
505
|
+
const xmlRoot = XML.parse(xml);
|
|
506
|
+
return decode(schema, XML.elementFromRoot(xmlRoot));
|
|
507
|
+
},
|
|
508
|
+
encode(value) {
|
|
509
|
+
const xmlEl = encode(schema, value);
|
|
510
|
+
return XML.stringify({ elements: [xmlEl] });
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
}
|
|
502
514
|
//#endregion
|
|
503
|
-
export { XMLCodecError, decode, encode, normalizeCodecOptions, registerDefault, xmlStateSchema };
|
|
515
|
+
export { XMLCodecError, decode, encode, normalizeCodecOptions, registerDefault, xmlCodec, xmlStateSchema };
|
|
504
516
|
|
|
505
517
|
//# sourceMappingURL=codec.js.map
|
package/dist/xml/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './xml-js';
|
|
2
2
|
export { xml } from './schema-meta';
|
|
3
3
|
export type { UserCodecOptions, XMLState } from './codec';
|
|
4
|
-
export {
|
|
4
|
+
export { xmlCodec, // if not re-exported here, xmlCodec is not exported from "./codex.js" but only from "./codec.d.ts"
|
|
5
|
+
registerDefault, normalizeCodecOptions, XMLCodecError, xmlStateSchema, } from './codec';
|
|
5
6
|
export { xmlModel, type XmlModelConstructor } from './model';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xml-model",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.8",
|
|
4
4
|
"description": "allows transparent XML <-> Object conversion in typescript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "MathisTLD",
|
|
@@ -53,4 +53,4 @@
|
|
|
53
53
|
"vitest": "npm:@voidzero-dev/vite-plus-test@latest"
|
|
54
54
|
},
|
|
55
55
|
"packageManager": "npm@11.12.0"
|
|
56
|
-
}
|
|
56
|
+
}
|