@xuda.io/runtime-bundle 1.0.1430 → 1.0.1431

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.
@@ -36695,7 +36695,7 @@ func.runtime.render.handle_xu_bind = async function (options) {
36695
36695
  };
36696
36696
  func.runtime.render.apply_xu_class = async function (options) {
36697
36697
  try {
36698
- const classes_obj = typeof options.val.value === 'string' ? JSON.parse(options.val.value) : Object.assign({}, {}, options.val.value);
36698
+ const classes_obj = typeof options.val.value === 'string' ? JSON5.parse(options.val.value) : Object.assign({}, {}, options.val.value);
36699
36699
  const xuData = func.runtime.ui.get_data(options.$elm)?.xuData;
36700
36700
  const class_names = Object.keys(classes_obj);
36701
36701
 
@@ -36725,7 +36725,18 @@ func.runtime.render.apply_xu_class = async function (options) {
36725
36725
  xuData.debug_info.attribute_stat['xu-class'] = func.runtime.ui.get_first_node(options.$elm)?.className || func.runtime.ui.get_attr(options.$elm, 'class');
36726
36726
  return {};
36727
36727
  } catch (e) {
36728
- console.warn('parse error:' + options.val.value);
36728
+ await func.runtime.render.report_xu_runtime_error(
36729
+ {
36730
+ ...options,
36731
+ xu_func: 'xu-class',
36732
+ val: {
36733
+ key: 'xu-class',
36734
+ value: options?.val?.value,
36735
+ },
36736
+ },
36737
+ e,
36738
+ 'xu-class has invalid object syntax',
36739
+ );
36729
36740
  return { abort: true };
36730
36741
  }
36731
36742
  };
@@ -37406,14 +37417,43 @@ func.runtime.widgets = func.runtime.widgets || {};
37406
37417
  // Browser-only common xu handler factories live here so registry composition can stay small.
37407
37418
 
37408
37419
  func.runtime.render.build_base_xu_handlers = function (options, _ds) {
37420
+ const parse_object_value = function (attr_name, val, shape = 'object') {
37421
+ let parsed_value = val?.value;
37422
+ if (typeof parsed_value === 'string') {
37423
+ try {
37424
+ parsed_value = JSON5.parse(parsed_value);
37425
+ } catch (error) {
37426
+ throw func.runtime.render.build_xu_runtime_error(
37427
+ { ...options, xu_func: attr_name, val: { key: attr_name, value: val?.value } },
37428
+ error,
37429
+ `${attr_name} has invalid ${shape} syntax`,
37430
+ );
37431
+ }
37432
+ }
37433
+
37434
+ const valid =
37435
+ shape === 'array'
37436
+ ? Array.isArray(parsed_value)
37437
+ : typeof parsed_value === 'object' && parsed_value !== null && !Array.isArray(parsed_value);
37438
+
37439
+ if (!valid) {
37440
+ throw func.runtime.render.build_xu_runtime_error(
37441
+ { ...options, xu_func: attr_name, val: { key: attr_name, value: val?.value } },
37442
+ null,
37443
+ `${attr_name} expects a ${shape} value`,
37444
+ );
37445
+ }
37446
+
37447
+ return parsed_value;
37448
+ };
37409
37449
  return {
37410
37450
  'xu-attrs': async function ($elm, val) {
37411
37451
  if (!val.value) return {};
37412
- if (!(typeof val.value === 'object' && val.value !== null)) throw 'xu-attrs value us not an object';
37413
- const attr_keys = Object.keys(val.value);
37452
+ const attrs_obj = parse_object_value('xu-attrs', val, 'object');
37453
+ const attr_keys = Object.keys(attrs_obj);
37414
37454
  for (let index = 0; index < attr_keys.length; index++) {
37415
37455
  const attr_key = attr_keys[index];
37416
- options.nodeP.attributes[attr_key] = val.value[attr_key];
37456
+ options.nodeP.attributes[attr_key] = attrs_obj[attr_key];
37417
37457
  }
37418
37458
  return {};
37419
37459
  },
@@ -37533,7 +37573,7 @@ func.runtime.render.build_base_xu_handlers = function (options, _ds) {
37533
37573
  return {};
37534
37574
  },
37535
37575
  'xu-cdn': async function ($elm, val) {
37536
- const resources_obj = val.value || {};
37576
+ const resources_obj = parse_object_value('xu-cdn', val, 'object');
37537
37577
  const resource_keys = Object.keys(resources_obj);
37538
37578
  for (let index = 0; index < resource_keys.length; index++) {
37539
37579
  const resource = resources_obj[resource_keys[index]];
@@ -37542,7 +37582,7 @@ func.runtime.render.build_base_xu_handlers = function (options, _ds) {
37542
37582
  return {};
37543
37583
  },
37544
37584
  'xu-ui-plugin': async function ($elm, val) {
37545
- const plugins_obj = val.value || {};
37585
+ const plugins_obj = parse_object_value('xu-ui-plugin', val, 'object');
37546
37586
  const plugin_names = Object.keys(plugins_obj);
37547
37587
  for (let index = 0; index < plugin_names.length; index++) {
37548
37588
  const plugin_name = plugin_names[index];
@@ -37553,14 +37593,14 @@ func.runtime.render.build_base_xu_handlers = function (options, _ds) {
37553
37593
  },
37554
37594
  'xu-store': async function ($elm, val) {
37555
37595
  try {
37556
- const fields_obj = JSON5.parse(val.value);
37596
+ const fields_obj = parse_object_value('xu-store', val, 'object');
37557
37597
  const field_ids = Object.keys(fields_obj);
37558
37598
  for (let index = 0; index < field_ids.length; index++) {
37559
37599
  const field_id = field_ids[index];
37560
37600
  func.datasource.add_dynamic_field_to_ds(options.SESSION_ID, options.paramsP.dsSessionP, field_id, fields_obj[field_id]);
37561
37601
  }
37562
37602
  } catch (err) {
37563
- console.error(err);
37603
+ throw err;
37564
37604
  }
37565
37605
  return {};
37566
37606
  },
@@ -37683,6 +37723,36 @@ func.runtime.render = func.runtime.render || {};
37683
37723
  func.runtime.widgets = func.runtime.widgets || {};
37684
37724
 
37685
37725
  // Browser-only xu-attribute dispatch lives here so the attribute phase engine can stay focused.
37726
+ func.runtime.render.build_xu_runtime_error = function (options, error, fallback_message) {
37727
+ const raw_message = error?.message || error || fallback_message || 'Unknown runtime error';
37728
+ const err = error instanceof Error ? error : new Error(raw_message);
37729
+ err.xu_func = options?.xu_func;
37730
+ err.node_tag = options?.nodeP?.tagName;
37731
+ err.raw_value = options?.val?.value;
37732
+ err.ui_id = func.runtime?.ui?.get_attr ? func.runtime.ui.get_attr(options?.$elm, 'xu-ui-id') : null;
37733
+ return err;
37734
+ };
37735
+ func.runtime.render.report_xu_runtime_error = async function (options, error, fallback_message) {
37736
+ const err = func.runtime.render.build_xu_runtime_error(options, error, fallback_message);
37737
+ const attr_name = options?.val?.key || options?.xu_func || 'xu-*';
37738
+ const tag_name = options?.nodeP?.tagName || 'unknown';
37739
+ const raw_value = typeof err.raw_value === 'string' ? err.raw_value : JSON.stringify(err.raw_value);
37740
+ const message = [`${attr_name} failed on <${tag_name}>`, err.message];
37741
+
37742
+ if (raw_value) {
37743
+ message.push(`Value: ${raw_value}`);
37744
+ }
37745
+
37746
+ if (err.ui_id) {
37747
+ message.push(`xu-ui-id: ${err.ui_id}`);
37748
+ }
37749
+
37750
+ console.error('XUDA RUNTIME', message.join(' | '), err);
37751
+ if (func.utils?.debug_report) {
37752
+ await func.utils.debug_report(options?.SESSION_ID, 'Slim runtime', message.join(' | '), 'E', err);
37753
+ }
37754
+ return {};
37755
+ };
37686
37756
  func.runtime.render.execute_xu_function = async function (options) {
37687
37757
  if (options.is_skeleton) return;
37688
37758
 
@@ -37714,13 +37784,13 @@ func.runtime.render.execute_xu_function = async function (options) {
37714
37784
 
37715
37785
  try {
37716
37786
  if (!common_fx[options.xu_func]) {
37717
- console.warn('invalid xu-tag', options.xu_func);
37787
+ await func.runtime.render.report_xu_runtime_error(options, null, `Unknown xu directive: ${options.xu_func}`);
37718
37788
  return {};
37719
37789
  }
37720
37790
 
37721
37791
  return await common_fx[options.xu_func](options.$elm, options.val);
37722
37792
  } catch (error) {
37723
- debugger;
37793
+ return await func.runtime.render.report_xu_runtime_error(options, error);
37724
37794
  }
37725
37795
  };
37726
37796
  func.datasource = {};