@xuda.io/runtime-bundle 1.0.506 → 1.0.508

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.
@@ -1662,8 +1662,11 @@ func.datasource.create = async function (
1662
1662
  };
1663
1663
 
1664
1664
  var run_at = _prog_obj?.properties?.runAt;
1665
- if (_session.opt.app_computing_mode === 'main') {
1666
- run_at = 'client';
1665
+
1666
+ if (_session.engine_mode !== 'live_preview') {
1667
+ if (_session.opt.app_computing_mode === 'main') {
1668
+ run_at = 'client';
1669
+ }
1667
1670
  }
1668
1671
 
1669
1672
  if (_prog_obj?.properties.menuType === 'globals') {
@@ -3419,7 +3422,7 @@ func.datasource.del = function (SESSION_ID, dsP) {
3419
3422
  }
3420
3423
  perform_delete();
3421
3424
  };
3422
- func.datasource.update = async function (SESSION_ID, datasource_changes, update_local_scope_only, avoid_refresh) {
3425
+ func.datasource.update_old = async function (SESSION_ID, datasource_changes, update_local_scope_only, avoid_refresh) {
3423
3426
  return new Promise(async (resolve, reject) => {
3424
3427
  var _session = SESSION_OBJ[SESSION_ID];
3425
3428
 
@@ -3522,7 +3525,202 @@ func.datasource.update = async function (SESSION_ID, datasource_changes, update_
3522
3525
  if (typeof fields_data === 'object') {
3523
3526
  if (glb.GLOBAL_VARS[field_id]) {
3524
3527
  _ds.data_system[field_id] = value;
3528
+ continue;
3529
+ }
3530
+
3531
+ // try {
3532
+ const row_idx = func.common.find_ROWID_idx(_ds, record_id);
3533
+ if (_ds.data_feed.rows[row_idx][field_id] !== value) {
3534
+ _ds.data_feed.rows[row_idx][field_id] = value;
3535
+ await set_fieldComputed_dependencies(dataSource, field_id, null);
3536
+
3537
+ // search the field in refs
3538
+ update_xu_ref();
3539
+
3540
+ if (!update_local_scope_only) {
3541
+ let tree_ret = await func.utils.TREE_OBJ.get(SESSION_ID, _ds.prog_id);
3542
+ if (glb.IS_WORKER) {
3543
+ // RUN AT SERVER
3544
+ if (tree_ret.menuType === 'globals' || tree_ret.menuType === 'component') {
3545
+ const _progFields = await func.datasource.get_progFields(SESSION_ID, dataSource);
3546
+ let view_field_obj = func.common.find_item_by_key(_progFields, 'field_id', field_id);
3547
+ if (!view_field_obj?.data?.serverField && record_id !== 'data_system') {
3548
+ if (!client_datasource_changes[dataSource]) {
3549
+ client_datasource_changes[dataSource] = {};
3550
+ }
3551
+ if (!client_datasource_changes[dataSource][record_id]) {
3552
+ client_datasource_changes[dataSource][record_id] = {};
3553
+ }
3554
+ client_datasource_changes[dataSource][record_id][field_id] = value;
3555
+ }
3556
+ }
3557
+ } else {
3558
+ // RUN AT CLIENT
3559
+ if ((tree_ret.menuType === 'component' && _ds._run_at !== 'client') || tree_ret.menuType === 'globals') {
3560
+ if (!server_datasource_changes[dataSource]) {
3561
+ server_datasource_changes[dataSource] = {};
3562
+ }
3563
+ if (!server_datasource_changes[dataSource][record_id]) {
3564
+ server_datasource_changes[dataSource][record_id] = {};
3565
+ }
3566
+ server_datasource_changes[dataSource][record_id][field_id] = value;
3567
+ }
3568
+ }
3569
+ }
3570
+
3571
+ if (!fields_changed.includes(field_id)) {
3572
+ fields_changed.push(field_id);
3573
+ }
3574
+ if (!datasource_changed.includes(dataSource)) {
3575
+ datasource_changed.push(dataSource);
3576
+ }
3577
+
3578
+ if (!_ds.data_feed.rows_changed) {
3579
+ _ds.data_feed.rows_changed = [];
3580
+ }
3581
+ if (!_ds.data_feed.rows_changed.includes(record_id)) _ds.data_feed.rows_changed.push(record_id);
3582
+ }
3583
+ } else if (fields_data === 'set') {
3584
+ _ds.currentRecordId = record_id;
3585
+ }
3586
+ }
3587
+ }
3588
+ }
3589
+
3590
+ if (glb.IS_WORKER) {
3591
+ if (!update_local_scope_only && !_.isEmpty(client_datasource_changes)) {
3592
+ func.utils.post_back_to_client(SESSION_ID, 'update_client_eventChangesResults_from_worker', _session.worker_id, client_datasource_changes);
3593
+ }
3594
+ } else {
3595
+ if (!update_local_scope_only && !_.isEmpty(server_datasource_changes)) {
3596
+ const ret = await func.index.call_worker(SESSION_ID, {
3597
+ service: 'update_datasource_changes_from_client',
3598
+ data: {
3599
+ session_id: SESSION_ID,
3600
+ datasource_changes: server_datasource_changes,
3601
+ },
3602
+ id: _ds.worker_id,
3603
+ });
3604
+ }
3605
+ ///// REFRESH SCREEN
3606
+ if (!avoid_refresh && fields_changed.length) {
3607
+ await func.UI.screen.refresh_xu_attributes(SESSION_ID, fields_changed);
3608
+ // await removed from the below function cause to dead lock Mar 3 25
3609
+ func.UI.screen.refresh_screen(
3610
+ SESSION_ID,
3611
+ fields_changed,
3612
+ null,
3613
+ datasource_changed[0], // refresh the current datasource only
3614
+ );
3615
+ }
3616
+ }
3617
+ resolve();
3618
+ });
3619
+ };
3620
+
3621
+ func.datasource.update = async function (SESSION_ID, datasource_changes, update_local_scope_only, avoid_refresh) {
3622
+ return new Promise(async (resolve, reject) => {
3623
+ var _session = SESSION_OBJ[SESSION_ID];
3525
3624
 
3625
+ if (_session.IS_API || typeof IS_MASTER_WEBSOCKET !== 'undefined' || typeof IS_PROCESS_SERVER !== 'undefined') {
3626
+ update_local_scope_only = true;
3627
+ }
3628
+
3629
+ if (typeof glb.GLOBAL_VARS === 'undefined') {
3630
+ glb.GLOBAL_VARS = (await func.common.get_module(SESSION_ID, 'xuda-system-globals-module.mjs')).system_globals;
3631
+ }
3632
+
3633
+ const set_fieldComputed_dependencies = async function (dsNo, field_id, parent_ds) {
3634
+ // iterate child ds
3635
+ for (const [dsSession, _ds] of Object.entries(_session.DS_GLB)) {
3636
+ if (parent_ds !== null) {
3637
+ if (_ds.parentDataSourceNo != parent_ds) continue;
3638
+ } else {
3639
+ if (dsSession != dsNo) continue;
3640
+ }
3641
+ let tree_ret = await func.utils.TREE_OBJ.get(SESSION_ID, _ds.prog_id);
3642
+ if (tree_ret.menuType === 'component' || tree_ret.menuType === 'globals') {
3643
+ // check if field has fieldComputed property
3644
+ const _progFields = await func.datasource.get_progFields(SESSION_ID, dsSession);
3645
+ // find if field is computed
3646
+ let fieldComputed_propExpressions, fieldComputed_id;
3647
+ for await (const val of _progFields) {
3648
+ const fieldId = val.data.field_id;
3649
+
3650
+ // if (fieldId !== field_id) continue
3651
+ if (val.data.type !== 'virtual' || !val.props.fieldComputed) continue;
3652
+
3653
+ const _propExpressions = val.props?.propExpressions?.fieldValue;
3654
+ if (_propExpressions && JSON.stringify(_propExpressions).includes(field_id)) {
3655
+ fieldComputed_propExpressions = _propExpressions;
3656
+ fieldComputed_id = fieldId;
3657
+ }
3658
+ }
3659
+
3660
+ if (!fieldComputed_id) return;
3661
+
3662
+ // iterate ds rows
3663
+ for (const row of _ds.data_feed?.rows || []) {
3664
+ // iterate row fields
3665
+ for (const [key, val] of Object.entries(row)) {
3666
+ if (key !== fieldComputed_id) continue;
3667
+ try {
3668
+ let ret = await func.expression.get(SESSION_ID, fieldComputed_propExpressions, dsNo, 'update', row._ROWID);
3669
+
3670
+ const row_idx = func.common.find_ROWID_idx(_ds, row._ROWID);
3671
+ if (_ds.data_feed.rows[row_idx][fieldComputed_id] !== ret.result) {
3672
+ _ds.data_feed.rows[row_idx][fieldComputed_id] = ret.result;
3673
+ if (!fields_changed.includes(fieldComputed_id)) {
3674
+ fields_changed.push(fieldComputed_id);
3675
+ }
3676
+ if (!datasource_changed.includes(dsSession)) {
3677
+ datasource_changed.push(dsSession);
3678
+ }
3679
+ }
3680
+ } catch (err) {
3681
+ console.error(err);
3682
+ }
3683
+ }
3684
+ }
3685
+ }
3686
+ await set_fieldComputed_dependencies(dsNo, field_id, dsSession);
3687
+ }
3688
+ };
3689
+
3690
+ var fields_changed = [];
3691
+ var datasource_changed = [];
3692
+ let client_datasource_changes = {};
3693
+ let server_datasource_changes = {};
3694
+ // iterate changes datasource
3695
+ for await (const [dataSource, row_data] of Object.entries(datasource_changes)) {
3696
+ var _ds = _session.DS_GLB[dataSource];
3697
+ if (!_ds) {
3698
+ continue;
3699
+ }
3700
+
3701
+ const update_xu_ref = async function () {
3702
+ let _ds_0 = _session.DS_GLB[0];
3703
+ for ([ref_name, val] of Object.entries(_ds_0.data_system['SYS_GLOBAL_OBJ_REFS'])) {
3704
+ if (val.ds.dsSession == dataSource) {
3705
+ func.UI.update_xu_ref(SESSION_ID, dataSource, ref_name);
3706
+ }
3707
+ }
3708
+ };
3709
+
3710
+ // iterate changes records
3711
+ for (const [record_id, fields_data] of Object.entries(row_data)) {
3712
+ // iterate changes fields
3713
+ for (const [field_id, value] of Object.entries(fields_data)) {
3714
+ // mechanism to make update directly on the datasource object
3715
+ if (record_id === 'datasource_main') {
3716
+ _.set(_ds, field_id, value);
3717
+ update_xu_ref();
3718
+ continue;
3719
+ }
3720
+
3721
+ if (typeof fields_data === 'object') {
3722
+ if (glb.GLOBAL_VARS[field_id]) {
3723
+ _ds.data_system[field_id] = value;
3526
3724
  continue;
3527
3725
  }
3528
3726
 
@@ -3534,15 +3732,6 @@ func.datasource.update = async function (SESSION_ID, datasource_changes, update_
3534
3732
 
3535
3733
  // search the field in refs
3536
3734
  update_xu_ref();
3537
- // let _ds_0 = _session.DS_GLB[0];
3538
- // for ([ref_name, val] of Object.entries(_ds_0.data_system['SYS_GLOBAL_OBJ_REFS'])) {
3539
- // if (val.ds.dsSession == dataSource) {
3540
- // func.UI.update_xu_ref(SESSION_ID, dataSource, ref_name);
3541
- // // if (!fields_changed.includes(ref_name)) {
3542
- // // fields_changed.push(ref_name);
3543
- // // }
3544
- // }
3545
- // }
3546
3735
 
3547
3736
  if (!update_local_scope_only) {
3548
3737
  let tree_ret = await func.utils.TREE_OBJ.get(SESSION_ID, _ds.prog_id);
@@ -1662,8 +1662,11 @@ func.datasource.create = async function (
1662
1662
  };
1663
1663
 
1664
1664
  var run_at = _prog_obj?.properties?.runAt;
1665
- if (_session.opt.app_computing_mode === 'main') {
1666
- run_at = 'client';
1665
+
1666
+ if (_session.engine_mode !== 'live_preview') {
1667
+ if (_session.opt.app_computing_mode === 'main') {
1668
+ run_at = 'client';
1669
+ }
1667
1670
  }
1668
1671
 
1669
1672
  if (_prog_obj?.properties.menuType === 'globals') {
@@ -3419,7 +3422,7 @@ func.datasource.del = function (SESSION_ID, dsP) {
3419
3422
  }
3420
3423
  perform_delete();
3421
3424
  };
3422
- func.datasource.update = async function (SESSION_ID, datasource_changes, update_local_scope_only, avoid_refresh) {
3425
+ func.datasource.update_old = async function (SESSION_ID, datasource_changes, update_local_scope_only, avoid_refresh) {
3423
3426
  return new Promise(async (resolve, reject) => {
3424
3427
  var _session = SESSION_OBJ[SESSION_ID];
3425
3428
 
@@ -3522,7 +3525,202 @@ func.datasource.update = async function (SESSION_ID, datasource_changes, update_
3522
3525
  if (typeof fields_data === 'object') {
3523
3526
  if (glb.GLOBAL_VARS[field_id]) {
3524
3527
  _ds.data_system[field_id] = value;
3528
+ continue;
3529
+ }
3530
+
3531
+ // try {
3532
+ const row_idx = func.common.find_ROWID_idx(_ds, record_id);
3533
+ if (_ds.data_feed.rows[row_idx][field_id] !== value) {
3534
+ _ds.data_feed.rows[row_idx][field_id] = value;
3535
+ await set_fieldComputed_dependencies(dataSource, field_id, null);
3536
+
3537
+ // search the field in refs
3538
+ update_xu_ref();
3539
+
3540
+ if (!update_local_scope_only) {
3541
+ let tree_ret = await func.utils.TREE_OBJ.get(SESSION_ID, _ds.prog_id);
3542
+ if (glb.IS_WORKER) {
3543
+ // RUN AT SERVER
3544
+ if (tree_ret.menuType === 'globals' || tree_ret.menuType === 'component') {
3545
+ const _progFields = await func.datasource.get_progFields(SESSION_ID, dataSource);
3546
+ let view_field_obj = func.common.find_item_by_key(_progFields, 'field_id', field_id);
3547
+ if (!view_field_obj?.data?.serverField && record_id !== 'data_system') {
3548
+ if (!client_datasource_changes[dataSource]) {
3549
+ client_datasource_changes[dataSource] = {};
3550
+ }
3551
+ if (!client_datasource_changes[dataSource][record_id]) {
3552
+ client_datasource_changes[dataSource][record_id] = {};
3553
+ }
3554
+ client_datasource_changes[dataSource][record_id][field_id] = value;
3555
+ }
3556
+ }
3557
+ } else {
3558
+ // RUN AT CLIENT
3559
+ if ((tree_ret.menuType === 'component' && _ds._run_at !== 'client') || tree_ret.menuType === 'globals') {
3560
+ if (!server_datasource_changes[dataSource]) {
3561
+ server_datasource_changes[dataSource] = {};
3562
+ }
3563
+ if (!server_datasource_changes[dataSource][record_id]) {
3564
+ server_datasource_changes[dataSource][record_id] = {};
3565
+ }
3566
+ server_datasource_changes[dataSource][record_id][field_id] = value;
3567
+ }
3568
+ }
3569
+ }
3570
+
3571
+ if (!fields_changed.includes(field_id)) {
3572
+ fields_changed.push(field_id);
3573
+ }
3574
+ if (!datasource_changed.includes(dataSource)) {
3575
+ datasource_changed.push(dataSource);
3576
+ }
3577
+
3578
+ if (!_ds.data_feed.rows_changed) {
3579
+ _ds.data_feed.rows_changed = [];
3580
+ }
3581
+ if (!_ds.data_feed.rows_changed.includes(record_id)) _ds.data_feed.rows_changed.push(record_id);
3582
+ }
3583
+ } else if (fields_data === 'set') {
3584
+ _ds.currentRecordId = record_id;
3585
+ }
3586
+ }
3587
+ }
3588
+ }
3589
+
3590
+ if (glb.IS_WORKER) {
3591
+ if (!update_local_scope_only && !_.isEmpty(client_datasource_changes)) {
3592
+ func.utils.post_back_to_client(SESSION_ID, 'update_client_eventChangesResults_from_worker', _session.worker_id, client_datasource_changes);
3593
+ }
3594
+ } else {
3595
+ if (!update_local_scope_only && !_.isEmpty(server_datasource_changes)) {
3596
+ const ret = await func.index.call_worker(SESSION_ID, {
3597
+ service: 'update_datasource_changes_from_client',
3598
+ data: {
3599
+ session_id: SESSION_ID,
3600
+ datasource_changes: server_datasource_changes,
3601
+ },
3602
+ id: _ds.worker_id,
3603
+ });
3604
+ }
3605
+ ///// REFRESH SCREEN
3606
+ if (!avoid_refresh && fields_changed.length) {
3607
+ await func.UI.screen.refresh_xu_attributes(SESSION_ID, fields_changed);
3608
+ // await removed from the below function cause to dead lock Mar 3 25
3609
+ func.UI.screen.refresh_screen(
3610
+ SESSION_ID,
3611
+ fields_changed,
3612
+ null,
3613
+ datasource_changed[0], // refresh the current datasource only
3614
+ );
3615
+ }
3616
+ }
3617
+ resolve();
3618
+ });
3619
+ };
3620
+
3621
+ func.datasource.update = async function (SESSION_ID, datasource_changes, update_local_scope_only, avoid_refresh) {
3622
+ return new Promise(async (resolve, reject) => {
3623
+ var _session = SESSION_OBJ[SESSION_ID];
3525
3624
 
3625
+ if (_session.IS_API || typeof IS_MASTER_WEBSOCKET !== 'undefined' || typeof IS_PROCESS_SERVER !== 'undefined') {
3626
+ update_local_scope_only = true;
3627
+ }
3628
+
3629
+ if (typeof glb.GLOBAL_VARS === 'undefined') {
3630
+ glb.GLOBAL_VARS = (await func.common.get_module(SESSION_ID, 'xuda-system-globals-module.mjs')).system_globals;
3631
+ }
3632
+
3633
+ const set_fieldComputed_dependencies = async function (dsNo, field_id, parent_ds) {
3634
+ // iterate child ds
3635
+ for (const [dsSession, _ds] of Object.entries(_session.DS_GLB)) {
3636
+ if (parent_ds !== null) {
3637
+ if (_ds.parentDataSourceNo != parent_ds) continue;
3638
+ } else {
3639
+ if (dsSession != dsNo) continue;
3640
+ }
3641
+ let tree_ret = await func.utils.TREE_OBJ.get(SESSION_ID, _ds.prog_id);
3642
+ if (tree_ret.menuType === 'component' || tree_ret.menuType === 'globals') {
3643
+ // check if field has fieldComputed property
3644
+ const _progFields = await func.datasource.get_progFields(SESSION_ID, dsSession);
3645
+ // find if field is computed
3646
+ let fieldComputed_propExpressions, fieldComputed_id;
3647
+ for await (const val of _progFields) {
3648
+ const fieldId = val.data.field_id;
3649
+
3650
+ // if (fieldId !== field_id) continue
3651
+ if (val.data.type !== 'virtual' || !val.props.fieldComputed) continue;
3652
+
3653
+ const _propExpressions = val.props?.propExpressions?.fieldValue;
3654
+ if (_propExpressions && JSON.stringify(_propExpressions).includes(field_id)) {
3655
+ fieldComputed_propExpressions = _propExpressions;
3656
+ fieldComputed_id = fieldId;
3657
+ }
3658
+ }
3659
+
3660
+ if (!fieldComputed_id) return;
3661
+
3662
+ // iterate ds rows
3663
+ for (const row of _ds.data_feed?.rows || []) {
3664
+ // iterate row fields
3665
+ for (const [key, val] of Object.entries(row)) {
3666
+ if (key !== fieldComputed_id) continue;
3667
+ try {
3668
+ let ret = await func.expression.get(SESSION_ID, fieldComputed_propExpressions, dsNo, 'update', row._ROWID);
3669
+
3670
+ const row_idx = func.common.find_ROWID_idx(_ds, row._ROWID);
3671
+ if (_ds.data_feed.rows[row_idx][fieldComputed_id] !== ret.result) {
3672
+ _ds.data_feed.rows[row_idx][fieldComputed_id] = ret.result;
3673
+ if (!fields_changed.includes(fieldComputed_id)) {
3674
+ fields_changed.push(fieldComputed_id);
3675
+ }
3676
+ if (!datasource_changed.includes(dsSession)) {
3677
+ datasource_changed.push(dsSession);
3678
+ }
3679
+ }
3680
+ } catch (err) {
3681
+ console.error(err);
3682
+ }
3683
+ }
3684
+ }
3685
+ }
3686
+ await set_fieldComputed_dependencies(dsNo, field_id, dsSession);
3687
+ }
3688
+ };
3689
+
3690
+ var fields_changed = [];
3691
+ var datasource_changed = [];
3692
+ let client_datasource_changes = {};
3693
+ let server_datasource_changes = {};
3694
+ // iterate changes datasource
3695
+ for await (const [dataSource, row_data] of Object.entries(datasource_changes)) {
3696
+ var _ds = _session.DS_GLB[dataSource];
3697
+ if (!_ds) {
3698
+ continue;
3699
+ }
3700
+
3701
+ const update_xu_ref = async function () {
3702
+ let _ds_0 = _session.DS_GLB[0];
3703
+ for ([ref_name, val] of Object.entries(_ds_0.data_system['SYS_GLOBAL_OBJ_REFS'])) {
3704
+ if (val.ds.dsSession == dataSource) {
3705
+ func.UI.update_xu_ref(SESSION_ID, dataSource, ref_name);
3706
+ }
3707
+ }
3708
+ };
3709
+
3710
+ // iterate changes records
3711
+ for (const [record_id, fields_data] of Object.entries(row_data)) {
3712
+ // iterate changes fields
3713
+ for (const [field_id, value] of Object.entries(fields_data)) {
3714
+ // mechanism to make update directly on the datasource object
3715
+ if (record_id === 'datasource_main') {
3716
+ _.set(_ds, field_id, value);
3717
+ update_xu_ref();
3718
+ continue;
3719
+ }
3720
+
3721
+ if (typeof fields_data === 'object') {
3722
+ if (glb.GLOBAL_VARS[field_id]) {
3723
+ _ds.data_system[field_id] = value;
3526
3724
  continue;
3527
3725
  }
3528
3726
 
@@ -3534,15 +3732,6 @@ func.datasource.update = async function (SESSION_ID, datasource_changes, update_
3534
3732
 
3535
3733
  // search the field in refs
3536
3734
  update_xu_ref();
3537
- // let _ds_0 = _session.DS_GLB[0];
3538
- // for ([ref_name, val] of Object.entries(_ds_0.data_system['SYS_GLOBAL_OBJ_REFS'])) {
3539
- // if (val.ds.dsSession == dataSource) {
3540
- // func.UI.update_xu_ref(SESSION_ID, dataSource, ref_name);
3541
- // // if (!fields_changed.includes(ref_name)) {
3542
- // // fields_changed.push(ref_name);
3543
- // // }
3544
- // }
3545
- // }
3546
3735
 
3547
3736
  if (!update_local_scope_only) {
3548
3737
  let tree_ret = await func.utils.TREE_OBJ.get(SESSION_ID, _ds.prog_id);