@xuda.io/runtime-bundle 1.0.517 → 1.0.519

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.
@@ -5057,201 +5057,201 @@ func.datasource.del = function (SESSION_ID, dsP) {
5057
5057
  }
5058
5058
  perform_delete();
5059
5059
  };
5060
- func.datasource.update_old = async function (SESSION_ID, datasource_changes, update_local_scope_only, avoid_refresh) {
5061
- return new Promise(async (resolve, reject) => {
5062
- var _session = SESSION_OBJ[SESSION_ID];
5063
-
5064
- if (_session.IS_API || typeof IS_MASTER_WEBSOCKET !== 'undefined' || typeof IS_PROCESS_SERVER !== 'undefined') {
5065
- update_local_scope_only = true;
5066
- }
5067
-
5068
- if (typeof glb.GLOBAL_VARS === 'undefined') {
5069
- glb.GLOBAL_VARS = (await func.common.get_module(SESSION_ID, 'xuda-system-globals-module.mjs')).system_globals;
5070
- }
5071
-
5072
- const set_fieldComputed_dependencies = async function (dsNo, field_id, parent_ds) {
5073
- // iterate child ds
5074
- for (const [dsSession, _ds] of Object.entries(_session.DS_GLB)) {
5075
- if (parent_ds !== null) {
5076
- if (_ds.parentDataSourceNo != parent_ds) continue;
5077
- } else {
5078
- if (dsSession != dsNo) continue;
5079
- }
5080
- let tree_ret = await func.utils.TREE_OBJ.get(SESSION_ID, _ds.prog_id);
5081
- if (tree_ret.menuType === 'component' || tree_ret.menuType === 'globals') {
5082
- // check if field has fieldComputed property
5083
- const _progFields = await func.datasource.get_progFields(SESSION_ID, dsSession);
5084
- // find if field is computed
5085
- let fieldComputed_propExpressions, fieldComputed_id;
5086
- for await (const val of _progFields) {
5087
- const fieldId = val.data.field_id;
5060
+ // func.datasource.update_old = async function (SESSION_ID, datasource_changes, update_local_scope_only, avoid_refresh) {
5061
+ // return new Promise(async (resolve, reject) => {
5062
+ // var _session = SESSION_OBJ[SESSION_ID];
5088
5063
 
5089
- // if (fieldId !== field_id) continue
5090
- if (val.data.type !== 'virtual' || !val.props.fieldComputed) continue;
5091
-
5092
- const _propExpressions = val.props?.propExpressions?.fieldValue;
5093
- if (_propExpressions && JSON.stringify(_propExpressions).includes(field_id)) {
5094
- fieldComputed_propExpressions = _propExpressions;
5095
- fieldComputed_id = fieldId;
5096
- }
5097
- }
5098
-
5099
- if (!fieldComputed_id) return;
5100
-
5101
- // iterate ds rows
5102
- for (const row of _ds.data_feed?.rows || []) {
5103
- // iterate row fields
5104
- for (const [key, val] of Object.entries(row)) {
5105
- if (key !== fieldComputed_id) continue;
5106
- try {
5107
- let ret = await func.expression.get(SESSION_ID, fieldComputed_propExpressions, dsNo, 'update', row._ROWID);
5108
-
5109
- const row_idx = func.common.find_ROWID_idx(_ds, row._ROWID);
5110
- if (_ds.data_feed.rows[row_idx][fieldComputed_id] !== ret.result) {
5111
- _ds.data_feed.rows[row_idx][fieldComputed_id] = ret.result;
5112
- if (!fields_changed.includes(fieldComputed_id)) {
5113
- fields_changed.push(fieldComputed_id);
5114
- }
5115
- if (!datasource_changed.includes(dsSession)) {
5116
- datasource_changed.push(dsSession);
5117
- }
5118
- }
5119
- } catch (err) {
5120
- console.error(err);
5121
- }
5122
- }
5123
- }
5124
- }
5125
- await set_fieldComputed_dependencies(dsNo, field_id, dsSession);
5126
- }
5127
- };
5128
-
5129
- var fields_changed = [];
5130
- var datasource_changed = [];
5131
- let client_datasource_changes = {};
5132
- let server_datasource_changes = {};
5133
- // iterate changes datasource
5134
- for await (const [dataSource, row_data] of Object.entries(datasource_changes)) {
5135
- var _ds = _session.DS_GLB[dataSource];
5136
- if (!_ds) {
5137
- continue;
5138
- }
5139
-
5140
- const update_xu_ref = async function () {
5141
- let _ds_0 = _session.DS_GLB[0];
5142
- for ([ref_name, val] of Object.entries(_ds_0.data_system['SYS_GLOBAL_OBJ_REFS'])) {
5143
- if (val.ds.dsSession == dataSource) {
5144
- func.UI.update_xu_ref(SESSION_ID, dataSource, ref_name);
5145
- }
5146
- }
5147
- };
5148
-
5149
- // iterate changes records
5150
- for (const [record_id, fields_data] of Object.entries(row_data)) {
5151
- // iterate changes fields
5152
- for (const [field_id, value] of Object.entries(fields_data)) {
5153
- // mechanism to make update directly on the datasource object
5154
- if (record_id === 'datasource_main') {
5155
- _.set(_ds, field_id, value);
5156
- update_xu_ref();
5157
- continue;
5158
- }
5159
-
5160
- if (typeof fields_data === 'object') {
5161
- if (glb.GLOBAL_VARS[field_id]) {
5162
- _ds.data_system[field_id] = value;
5163
- continue;
5164
- }
5064
+ // if (_session.IS_API || typeof IS_MASTER_WEBSOCKET !== 'undefined' || typeof IS_PROCESS_SERVER !== 'undefined') {
5065
+ // update_local_scope_only = true;
5066
+ // }
5165
5067
 
5166
- // try {
5167
- const row_idx = func.common.find_ROWID_idx(_ds, record_id);
5168
- if (_ds.data_feed.rows[row_idx][field_id] !== value) {
5169
- _ds.data_feed.rows[row_idx][field_id] = value;
5170
- await set_fieldComputed_dependencies(dataSource, field_id, null);
5068
+ // if (typeof glb.GLOBAL_VARS === 'undefined') {
5069
+ // glb.GLOBAL_VARS = (await func.common.get_module(SESSION_ID, 'xuda-system-globals-module.mjs')).system_globals;
5070
+ // }
5171
5071
 
5172
- // search the field in refs
5173
- update_xu_ref();
5072
+ // const set_fieldComputed_dependencies = async function (dsNo, field_id, parent_ds) {
5073
+ // // iterate child ds
5074
+ // for (const [dsSession, _ds] of Object.entries(_session.DS_GLB)) {
5075
+ // if (parent_ds !== null) {
5076
+ // if (_ds.parentDataSourceNo != parent_ds) continue;
5077
+ // } else {
5078
+ // if (dsSession != dsNo) continue;
5079
+ // }
5080
+ // let tree_ret = await func.utils.TREE_OBJ.get(SESSION_ID, _ds.prog_id);
5081
+ // if (tree_ret.menuType === 'component' || tree_ret.menuType === 'globals') {
5082
+ // // check if field has fieldComputed property
5083
+ // const _progFields = await func.datasource.get_progFields(SESSION_ID, dsSession);
5084
+ // // find if field is computed
5085
+ // let fieldComputed_propExpressions, fieldComputed_id;
5086
+ // for await (const val of _progFields) {
5087
+ // const fieldId = val.data.field_id;
5088
+
5089
+ // // if (fieldId !== field_id) continue
5090
+ // if (val.data.type !== 'virtual' || !val.props.fieldComputed) continue;
5091
+
5092
+ // const _propExpressions = val.props?.propExpressions?.fieldValue;
5093
+ // if (_propExpressions && JSON.stringify(_propExpressions).includes(field_id)) {
5094
+ // fieldComputed_propExpressions = _propExpressions;
5095
+ // fieldComputed_id = fieldId;
5096
+ // }
5097
+ // }
5174
5098
 
5175
- if (!update_local_scope_only) {
5176
- let tree_ret = await func.utils.TREE_OBJ.get(SESSION_ID, _ds.prog_id);
5177
- if (glb.IS_WORKER) {
5178
- // RUN AT SERVER
5179
- if (tree_ret.menuType === 'globals' || tree_ret.menuType === 'component') {
5180
- const _progFields = await func.datasource.get_progFields(SESSION_ID, dataSource);
5181
- let view_field_obj = func.common.find_item_by_key(_progFields, 'field_id', field_id);
5182
- if (!view_field_obj?.data?.serverField && record_id !== 'data_system') {
5183
- if (!client_datasource_changes[dataSource]) {
5184
- client_datasource_changes[dataSource] = {};
5185
- }
5186
- if (!client_datasource_changes[dataSource][record_id]) {
5187
- client_datasource_changes[dataSource][record_id] = {};
5188
- }
5189
- client_datasource_changes[dataSource][record_id][field_id] = value;
5190
- }
5191
- }
5192
- } else {
5193
- // RUN AT CLIENT
5194
- if ((tree_ret.menuType === 'component' && _ds._run_at !== 'client') || tree_ret.menuType === 'globals') {
5195
- if (!server_datasource_changes[dataSource]) {
5196
- server_datasource_changes[dataSource] = {};
5197
- }
5198
- if (!server_datasource_changes[dataSource][record_id]) {
5199
- server_datasource_changes[dataSource][record_id] = {};
5200
- }
5201
- server_datasource_changes[dataSource][record_id][field_id] = value;
5202
- }
5203
- }
5204
- }
5099
+ // if (!fieldComputed_id) return;
5100
+
5101
+ // // iterate ds rows
5102
+ // for (const row of _ds.data_feed?.rows || []) {
5103
+ // // iterate row fields
5104
+ // for (const [key, val] of Object.entries(row)) {
5105
+ // if (key !== fieldComputed_id) continue;
5106
+ // try {
5107
+ // let ret = await func.expression.get(SESSION_ID, fieldComputed_propExpressions, dsNo, 'update', row._ROWID);
5108
+
5109
+ // const row_idx = func.common.find_ROWID_idx(_ds, row._ROWID);
5110
+ // if (_ds.data_feed.rows[row_idx][fieldComputed_id] !== ret.result) {
5111
+ // _ds.data_feed.rows[row_idx][fieldComputed_id] = ret.result;
5112
+ // if (!fields_changed.includes(fieldComputed_id)) {
5113
+ // fields_changed.push(fieldComputed_id);
5114
+ // }
5115
+ // if (!datasource_changed.includes(dsSession)) {
5116
+ // datasource_changed.push(dsSession);
5117
+ // }
5118
+ // }
5119
+ // } catch (err) {
5120
+ // console.error(err);
5121
+ // }
5122
+ // }
5123
+ // }
5124
+ // }
5125
+ // await set_fieldComputed_dependencies(dsNo, field_id, dsSession);
5126
+ // }
5127
+ // };
5128
+
5129
+ // var fields_changed = [];
5130
+ // var datasource_changed = [];
5131
+ // let client_datasource_changes = {};
5132
+ // let server_datasource_changes = {};
5133
+ // // iterate changes datasource
5134
+ // for await (const [dataSource, row_data] of Object.entries(datasource_changes)) {
5135
+ // var _ds = _session.DS_GLB[dataSource];
5136
+ // if (!_ds) {
5137
+ // continue;
5138
+ // }
5205
5139
 
5206
- if (!fields_changed.includes(field_id)) {
5207
- fields_changed.push(field_id);
5208
- }
5209
- if (!datasource_changed.includes(dataSource)) {
5210
- datasource_changed.push(dataSource);
5211
- }
5140
+ // const update_xu_ref = async function () {
5141
+ // let _ds_0 = _session.DS_GLB[0];
5142
+ // for ([ref_name, val] of Object.entries(_ds_0.data_system['SYS_GLOBAL_OBJ_REFS'])) {
5143
+ // if (val.ds.dsSession == dataSource) {
5144
+ // func.UI.update_xu_ref(SESSION_ID, dataSource, ref_name);
5145
+ // }
5146
+ // }
5147
+ // };
5148
+
5149
+ // // iterate changes records
5150
+ // for (const [record_id, fields_data] of Object.entries(row_data)) {
5151
+ // // iterate changes fields
5152
+ // for (const [field_id, value] of Object.entries(fields_data)) {
5153
+ // // mechanism to make update directly on the datasource object
5154
+ // if (record_id === 'datasource_main') {
5155
+ // _.set(_ds, field_id, value);
5156
+ // update_xu_ref();
5157
+ // continue;
5158
+ // }
5212
5159
 
5213
- if (!_ds.data_feed.rows_changed) {
5214
- _ds.data_feed.rows_changed = [];
5215
- }
5216
- if (!_ds.data_feed.rows_changed.includes(record_id)) _ds.data_feed.rows_changed.push(record_id);
5217
- }
5218
- } else if (fields_data === 'set') {
5219
- _ds.currentRecordId = record_id;
5220
- }
5221
- }
5222
- }
5223
- }
5160
+ // if (typeof fields_data === 'object') {
5161
+ // if (glb.GLOBAL_VARS[field_id]) {
5162
+ // _ds.data_system[field_id] = value;
5163
+ // continue;
5164
+ // }
5165
+
5166
+ // // try {
5167
+ // const row_idx = func.common.find_ROWID_idx(_ds, record_id);
5168
+ // if (_ds.data_feed.rows[row_idx][field_id] !== value) {
5169
+ // _ds.data_feed.rows[row_idx][field_id] = value;
5170
+ // await set_fieldComputed_dependencies(dataSource, field_id, null);
5171
+
5172
+ // // search the field in refs
5173
+ // update_xu_ref();
5174
+
5175
+ // if (!update_local_scope_only) {
5176
+ // let tree_ret = await func.utils.TREE_OBJ.get(SESSION_ID, _ds.prog_id);
5177
+ // if (glb.IS_WORKER) {
5178
+ // // RUN AT SERVER
5179
+ // if (tree_ret.menuType === 'globals' || tree_ret.menuType === 'component') {
5180
+ // const _progFields = await func.datasource.get_progFields(SESSION_ID, dataSource);
5181
+ // let view_field_obj = func.common.find_item_by_key(_progFields, 'field_id', field_id);
5182
+ // if (!view_field_obj?.data?.serverField && record_id !== 'data_system') {
5183
+ // if (!client_datasource_changes[dataSource]) {
5184
+ // client_datasource_changes[dataSource] = {};
5185
+ // }
5186
+ // if (!client_datasource_changes[dataSource][record_id]) {
5187
+ // client_datasource_changes[dataSource][record_id] = {};
5188
+ // }
5189
+ // client_datasource_changes[dataSource][record_id][field_id] = value;
5190
+ // }
5191
+ // }
5192
+ // } else {
5193
+ // // RUN AT CLIENT
5194
+ // if ((tree_ret.menuType === 'component' && _ds._run_at !== 'client') || tree_ret.menuType === 'globals') {
5195
+ // if (!server_datasource_changes[dataSource]) {
5196
+ // server_datasource_changes[dataSource] = {};
5197
+ // }
5198
+ // if (!server_datasource_changes[dataSource][record_id]) {
5199
+ // server_datasource_changes[dataSource][record_id] = {};
5200
+ // }
5201
+ // server_datasource_changes[dataSource][record_id][field_id] = value;
5202
+ // }
5203
+ // }
5204
+ // }
5205
+
5206
+ // if (!fields_changed.includes(field_id)) {
5207
+ // fields_changed.push(field_id);
5208
+ // }
5209
+ // if (!datasource_changed.includes(dataSource)) {
5210
+ // datasource_changed.push(dataSource);
5211
+ // }
5212
+
5213
+ // if (!_ds.data_feed.rows_changed) {
5214
+ // _ds.data_feed.rows_changed = [];
5215
+ // }
5216
+ // if (!_ds.data_feed.rows_changed.includes(record_id)) _ds.data_feed.rows_changed.push(record_id);
5217
+ // }
5218
+ // } else if (fields_data === 'set') {
5219
+ // _ds.currentRecordId = record_id;
5220
+ // }
5221
+ // }
5222
+ // }
5223
+ // }
5224
5224
 
5225
- if (glb.IS_WORKER) {
5226
- if (!update_local_scope_only && !_.isEmpty(client_datasource_changes)) {
5227
- func.utils.post_back_to_client(SESSION_ID, 'update_client_eventChangesResults_from_worker', _session.worker_id, client_datasource_changes);
5228
- }
5229
- } else {
5230
- if (!update_local_scope_only && !_.isEmpty(server_datasource_changes)) {
5231
- const ret = await func.index.call_worker(SESSION_ID, {
5232
- service: 'update_datasource_changes_from_client',
5233
- data: {
5234
- session_id: SESSION_ID,
5235
- datasource_changes: server_datasource_changes,
5236
- },
5237
- id: _ds.worker_id,
5238
- });
5239
- }
5240
- ///// REFRESH SCREEN
5241
- if (!avoid_refresh && fields_changed.length) {
5242
- await func.UI.screen.refresh_xu_attributes(SESSION_ID, fields_changed);
5243
- // await removed from the below function cause to dead lock Mar 3 25
5244
- func.UI.screen.refresh_screen(
5245
- SESSION_ID,
5246
- fields_changed,
5247
- null,
5248
- datasource_changed[0], // refresh the current datasource only
5249
- );
5250
- }
5251
- }
5252
- resolve();
5253
- });
5254
- };
5225
+ // if (glb.IS_WORKER) {
5226
+ // if (!update_local_scope_only && !_.isEmpty(client_datasource_changes)) {
5227
+ // func.utils.post_back_to_client(SESSION_ID, 'update_client_eventChangesResults_from_worker', _session.worker_id, client_datasource_changes);
5228
+ // }
5229
+ // } else {
5230
+ // if (!update_local_scope_only && !_.isEmpty(server_datasource_changes)) {
5231
+ // const ret = await func.index.call_worker(SESSION_ID, {
5232
+ // service: 'update_datasource_changes_from_client',
5233
+ // data: {
5234
+ // session_id: SESSION_ID,
5235
+ // datasource_changes: server_datasource_changes,
5236
+ // },
5237
+ // id: _ds.worker_id,
5238
+ // });
5239
+ // }
5240
+ // ///// REFRESH SCREEN
5241
+ // if (!avoid_refresh && fields_changed.length) {
5242
+ // await func.UI.screen.refresh_xu_attributes(SESSION_ID, fields_changed);
5243
+ // // await removed from the below function cause to dead lock Mar 3 25
5244
+ // func.UI.screen.refresh_screen(
5245
+ // SESSION_ID,
5246
+ // fields_changed,
5247
+ // null,
5248
+ // datasource_changed[0], // refresh the current datasource only
5249
+ // );
5250
+ // }
5251
+ // }
5252
+ // resolve();
5253
+ // });
5254
+ // };
5255
5255
 
5256
5256
  func.datasource.update = async function (SESSION_ID, datasource_changes, update_local_scope_only, avoid_refresh) {
5257
5257
  return new Promise(async (resolve, reject) => {
@@ -5326,6 +5326,19 @@ func.datasource.update = async function (SESSION_ID, datasource_changes, update_
5326
5326
  var datasource_changed = [];
5327
5327
  let client_datasource_changes = {};
5328
5328
  let server_datasource_changes = {};
5329
+
5330
+ const update_xu_ref = async function (dataSource, field_id) {
5331
+ let ret;
5332
+ let _ds_0 = _session.DS_GLB[0];
5333
+ for ([ref_name, val] of Object.entries(_ds_0.data_system['SYS_GLOBAL_OBJ_REFS'])) {
5334
+ if (val.ds.dsSession == dataSource) {
5335
+ func.UI.update_xu_ref(SESSION_ID, dataSource, ref_name);
5336
+ ret = true;
5337
+ }
5338
+ }
5339
+ return ret;
5340
+ };
5341
+
5329
5342
  // iterate changes datasource
5330
5343
  for await (const [dataSource, row_data] of Object.entries(datasource_changes)) {
5331
5344
  var _ds = _session.DS_GLB[dataSource];
@@ -5333,15 +5346,6 @@ func.datasource.update = async function (SESSION_ID, datasource_changes, update_
5333
5346
  continue;
5334
5347
  }
5335
5348
 
5336
- const update_xu_ref = async function () {
5337
- let _ds_0 = _session.DS_GLB[0];
5338
- for ([ref_name, val] of Object.entries(_ds_0.data_system['SYS_GLOBAL_OBJ_REFS'])) {
5339
- if (val.ds.dsSession == dataSource) {
5340
- func.UI.update_xu_ref(SESSION_ID, dataSource, ref_name);
5341
- }
5342
- }
5343
- };
5344
-
5345
5349
  // iterate changes records
5346
5350
  for (const [record_id, fields_data] of Object.entries(row_data)) {
5347
5351
  // iterate changes fields
@@ -5349,7 +5353,11 @@ func.datasource.update = async function (SESSION_ID, datasource_changes, update_
5349
5353
  // mechanism to make update directly on the datasource object
5350
5354
  if (record_id === 'datasource_main') {
5351
5355
  _.set(_ds, field_id, value);
5352
- update_xu_ref();
5356
+ const ret = update_xu_ref(dataSource, field_id);
5357
+ if (ret) {
5358
+ fields_changed.push(field_id);
5359
+ datasource_changed.push(dataSource);
5360
+ }
5353
5361
  continue;
5354
5362
  }
5355
5363
 
@@ -5366,7 +5374,7 @@ func.datasource.update = async function (SESSION_ID, datasource_changes, update_
5366
5374
  await set_fieldComputed_dependencies(dataSource, field_id, null);
5367
5375
 
5368
5376
  // search the field in refs
5369
- update_xu_ref();
5377
+ update_xu_ref(dataSource, field_id);
5370
5378
 
5371
5379
  if (!update_local_scope_only) {
5372
5380
  let tree_ret = await func.utils.TREE_OBJ.get(SESSION_ID, _ds.prog_id);