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