@xuda.io/xuda-studio-checker 1.0.11 → 1.0.12

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.
Files changed (2) hide show
  1. package/index.mjs +50 -0
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -3940,3 +3940,53 @@ export const get_zod_schema = function (type) {
3940
3940
 
3941
3941
  return XudaComponentSchema;
3942
3942
  };
3943
+
3944
+ export const get_fields_z_schema = function (fields = {}, exclude_props = []) {
3945
+ let inputSchema = {};
3946
+
3947
+ const get_z_item = function (key, val) {
3948
+ let prop = {};
3949
+ if (val.type === 'object' && val.items) {
3950
+ for (const [item_key, item_val] of Object.entries(val.items.properties)) {
3951
+ prop[item_key] = get_z_item(item_key, item_val);
3952
+ if (!val?.items?.required?.includes(item_key)) {
3953
+ prop[item_key] = prop[item_key].optional();
3954
+ }
3955
+ }
3956
+ }
3957
+
3958
+ if (val.type === 'array') {
3959
+ prop = get_z_item('', val.items);
3960
+ }
3961
+
3962
+ let _z = z[val.type](prop);
3963
+
3964
+ if (!val.mandatory) {
3965
+ _z = _z.optional();
3966
+ }
3967
+
3968
+ if (val.enum) {
3969
+ _z = z.enum(val.enum);
3970
+ }
3971
+
3972
+ let valid_values = '';
3973
+ if (val.options) {
3974
+ valid_values = val.options.join(', ');
3975
+ }
3976
+ if (val.description) {
3977
+ const desc = val.name || key.replace(/_/g, ' ').replace(/\b(\w)/g, (_, char) => char.toUpperCase());
3978
+ _z = _z.describe((desc ? desc + ' - ' : '') + val.description + (valid_values ? ' Valid values: ' + valid_values : ''));
3979
+ }
3980
+
3981
+ return _z;
3982
+ };
3983
+
3984
+ try {
3985
+ for (const [key, val] of Object.entries(fields)) {
3986
+ if (exclude_props.includes(key)) continue;
3987
+ inputSchema[key] = get_z_item(key, val);
3988
+ }
3989
+ } catch (error) {
3990
+ debugger;
3991
+ }
3992
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/xuda-studio-checker",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "main": "index.mjs",
5
5
  "type": "module",
6
6
  "description": "Auto-generated build for xuda-studio-checker.mjs",