@xuda.io/xuda-worker-bundle-min 1.3.2450 → 1.3.2452

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.js +206 -96
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -4789,6 +4789,58 @@ func.datasource.update = async function (SESSION_ID, datasource_changes, update_
4789
4789
  var datasource_changed = [];
4790
4790
  let client_datasource_changes = {};
4791
4791
  let server_datasource_changes = {};
4792
+ const mark_field_changed = async function (dataSource, field_id) {
4793
+ if (!fields_changed.includes(field_id)) {
4794
+ fields_changed.push(field_id);
4795
+
4796
+ // Refresh dependent in-parameters that reference this field.
4797
+ for (const [_dsSession, _ds] of Object.entries(_session.DS_GLB)) {
4798
+ if (_ds.args.parameters_raw_obj) {
4799
+ for (const [key, exp] of Object.entries(_ds.args.parameters_raw_obj)) {
4800
+ if (exp.includes(field_id)) {
4801
+ let ret = await func.expression.get(SESSION_ID, exp, _dsSession, 'parameters');
4802
+ _ds.in_parameters[key].value = ret.result;
4803
+ }
4804
+ }
4805
+ }
4806
+ }
4807
+ }
4808
+ if (!datasource_changed.includes(dataSource)) {
4809
+ datasource_changed.push(dataSource);
4810
+ }
4811
+ };
4812
+ const queue_remote_change = async function (dataSource, record_id, field_id, value, _ds) {
4813
+ if (update_local_scope_only) {
4814
+ return;
4815
+ }
4816
+
4817
+ let tree_ret = await func.utils.TREE_OBJ.get(SESSION_ID, _ds.prog_id);
4818
+ if (glb.IS_WORKER) {
4819
+ if (tree_ret.menuType === 'globals' || tree_ret.menuType === 'component') {
4820
+ const _progFields = await func.datasource.get_progFields(SESSION_ID, dataSource);
4821
+ let view_field_obj = func.common.find_item_by_key(_progFields, 'field_id', field_id);
4822
+ if (!view_field_obj?.data?.serverField && record_id !== 'data_system') {
4823
+ if (!client_datasource_changes[dataSource]) {
4824
+ client_datasource_changes[dataSource] = {};
4825
+ }
4826
+ if (!client_datasource_changes[dataSource][record_id]) {
4827
+ client_datasource_changes[dataSource][record_id] = {};
4828
+ }
4829
+ client_datasource_changes[dataSource][record_id][field_id] = value;
4830
+ }
4831
+ }
4832
+ } else {
4833
+ if ((tree_ret.menuType === 'component' && _ds._run_at !== 'client') || tree_ret.menuType === 'globals') {
4834
+ if (!server_datasource_changes[dataSource]) {
4835
+ server_datasource_changes[dataSource] = {};
4836
+ }
4837
+ if (!server_datasource_changes[dataSource][record_id]) {
4838
+ server_datasource_changes[dataSource][record_id] = {};
4839
+ }
4840
+ server_datasource_changes[dataSource][record_id][field_id] = value;
4841
+ }
4842
+ }
4843
+ };
4792
4844
 
4793
4845
  const update_xu_ref = function (dataSource) {
4794
4846
  let ret;
@@ -4859,6 +4911,18 @@ func.datasource.update = async function (SESSION_ID, datasource_changes, update_
4859
4911
  continue;
4860
4912
  }
4861
4913
 
4914
+ const dynamic_field = _ds?.dynamic_fields?.[field_id];
4915
+ if (dynamic_field) {
4916
+ if (!xu_isEqual(dynamic_field.value, value)) {
4917
+ dynamic_field.value = value;
4918
+ await set_fieldComputed_dependencies(dataSource, field_id, null);
4919
+ update_xu_ref(dataSource);
4920
+ await queue_remote_change(dataSource, record_id, field_id, value, _ds);
4921
+ await mark_field_changed(dataSource, field_id);
4922
+ }
4923
+ continue;
4924
+ }
4925
+
4862
4926
  try {
4863
4927
  const row_idx = func.common.find_ROWID_idx(_ds, record_id);
4864
4928
  // if (_ds.data_feed.rows[row_idx][field_id] !== value) {
@@ -4869,55 +4933,8 @@ func.datasource.update = async function (SESSION_ID, datasource_changes, update_
4869
4933
  // search the field in refs
4870
4934
  update_xu_ref(dataSource);
4871
4935
 
4872
- if (!update_local_scope_only) {
4873
- let tree_ret = await func.utils.TREE_OBJ.get(SESSION_ID, _ds.prog_id);
4874
- if (glb.IS_WORKER) {
4875
- // RUN AT SERVER
4876
- if (tree_ret.menuType === 'globals' || tree_ret.menuType === 'component') {
4877
- const _progFields = await func.datasource.get_progFields(SESSION_ID, dataSource);
4878
- let view_field_obj = func.common.find_item_by_key(_progFields, 'field_id', field_id);
4879
- if (!view_field_obj?.data?.serverField && record_id !== 'data_system') {
4880
- if (!client_datasource_changes[dataSource]) {
4881
- client_datasource_changes[dataSource] = {};
4882
- }
4883
- if (!client_datasource_changes[dataSource][record_id]) {
4884
- client_datasource_changes[dataSource][record_id] = {};
4885
- }
4886
- client_datasource_changes[dataSource][record_id][field_id] = value;
4887
- }
4888
- }
4889
- } else {
4890
- // RUN AT CLIENT
4891
- if ((tree_ret.menuType === 'component' && _ds._run_at !== 'client') || tree_ret.menuType === 'globals') {
4892
- if (!server_datasource_changes[dataSource]) {
4893
- server_datasource_changes[dataSource] = {};
4894
- }
4895
- if (!server_datasource_changes[dataSource][record_id]) {
4896
- server_datasource_changes[dataSource][record_id] = {};
4897
- }
4898
- server_datasource_changes[dataSource][record_id][field_id] = value;
4899
- }
4900
- }
4901
- }
4902
-
4903
- if (!fields_changed.includes(field_id)) {
4904
- fields_changed.push(field_id);
4905
-
4906
- ///// REFRESH PARAMETERS IN
4907
- for (const [_dsSession, _ds] of Object.entries(_session.DS_GLB)) {
4908
- if (_ds.args.parameters_raw_obj) {
4909
- for (const [key, exp] of Object.entries(_ds.args.parameters_raw_obj)) {
4910
- if (exp.includes(field_id)) {
4911
- let ret = await func.expression.get(SESSION_ID, exp, _dsSession, 'parameters');
4912
- _ds.in_parameters[key].value = ret.result;
4913
- }
4914
- }
4915
- }
4916
- }
4917
- }
4918
- if (!datasource_changed.includes(dataSource)) {
4919
- datasource_changed.push(dataSource);
4920
- }
4936
+ await queue_remote_change(dataSource, record_id, field_id, value, _ds);
4937
+ await mark_field_changed(dataSource, field_id);
4921
4938
 
4922
4939
  if (!_ds.data_feed.rows_changed) {
4923
4940
  _ds.data_feed.rows_changed = [];
@@ -5126,56 +5143,149 @@ func.datasource.get_viewFields_for_update_function = function (SESSION_ID, calli
5126
5143
  if (!exp) {
5127
5144
  return viewFields;
5128
5145
  }
5129
- try {
5130
- // parse json
5131
- var json = JSON5.parse(exp.replace(/\n/gi, ''));
5132
- for (const [key, val] of Object.entries(json)) {
5133
- let id = key.substr(1, key.length - 1);
5134
- if (!id) continue;
5135
- viewFields.push({
5136
- val,
5137
- id,
5138
- });
5146
+ const trim_wrapping_braces = function (value) {
5147
+ const trimmed = value.trim();
5148
+ if (trimmed.startsWith('{') && trimmed.endsWith('}')) {
5149
+ return trimmed.substring(1, trimmed.length - 1);
5150
+ }
5151
+ return trimmed;
5152
+ };
5153
+ const strip_wrapping_quotes = function (value) {
5154
+ const trimmed = value.trim();
5155
+ const first = trimmed.substring(0, 1);
5156
+ const last = trimmed.substring(trimmed.length - 1);
5157
+ if ((first === "'" || first === '"' || first === '`') && last === first) {
5158
+ return trimmed.substring(1, trimmed.length - 1);
5159
+ }
5160
+ return trimmed;
5161
+ };
5162
+ const split_top_level = function (value) {
5163
+ const parts = [];
5164
+ let current = '';
5165
+ let quote = null;
5166
+ let escape = false;
5167
+ let paren_depth = 0;
5168
+ let bracket_depth = 0;
5169
+ let brace_depth = 0;
5170
+
5171
+ for (let index = 0; index < value.length; index++) {
5172
+ const char = value[index];
5173
+
5174
+ if (escape) {
5175
+ current += char;
5176
+ escape = false;
5177
+ continue;
5178
+ }
5179
+
5180
+ if (quote) {
5181
+ current += char;
5182
+ if (char === '\\') {
5183
+ escape = true;
5184
+ } else if (char === quote) {
5185
+ quote = null;
5186
+ }
5187
+ continue;
5188
+ }
5189
+
5190
+ if (char === "'" || char === '"' || char === '`') {
5191
+ quote = char;
5192
+ current += char;
5193
+ continue;
5194
+ }
5195
+
5196
+ if (char === '(') paren_depth++;
5197
+ if (char === ')') paren_depth = Math.max(0, paren_depth - 1);
5198
+ if (char === '[') bracket_depth++;
5199
+ if (char === ']') bracket_depth = Math.max(0, bracket_depth - 1);
5200
+ if (char === '{') brace_depth++;
5201
+ if (char === '}') brace_depth = Math.max(0, brace_depth - 1);
5202
+
5203
+ if ((char === ',' || char === ';') && !paren_depth && !bracket_depth && !brace_depth) {
5204
+ if (current.trim()) {
5205
+ parts.push(current.trim());
5206
+ }
5207
+ current = '';
5208
+ continue;
5209
+ }
5210
+
5211
+ current += char;
5139
5212
  }
5140
- return viewFields;
5141
- } catch (e) {
5142
- if (!exp) {
5143
- return;
5213
+
5214
+ if (current.trim()) {
5215
+ parts.push(current.trim());
5144
5216
  }
5145
- if (exp.substr(exp.length - 1, 1) === ';') exp = exp.substr(0, exp.length - 1); // remove closing if exist;
5146
- var exp_arr = exp.split(/;\s*(?=(?:[^"]|"[^"]*")*$)/g); // split ; outside quotes
5147
- if (exp_arr?.length) {
5148
- for (let val of exp_arr) {
5149
- // run view fields
5150
- var pos = val.indexOf(':');
5151
- var seg = [val.substring(0, pos), val.substring(pos + 1)];
5152
- if (seg && seg.length === 2) {
5153
- let id = seg[0].substr(1, seg[0].length);
5154
- if (!id) continue;
5155
- viewFields.push({
5156
- id,
5157
- val: seg[1],
5158
- // , props: {},
5159
- });
5160
- } else {
5161
- func.utils.debug.log(SESSION_ID, _ds.prog_id, {
5162
- module: _ds.viewModule,
5163
- action: 'set',
5164
- prop: 'parse update exp',
5165
- details: exp,
5166
- result: '',
5167
- error: 'Invalid json; too many segments',
5168
- source: _ds.viewSourceDesc,
5169
- json: '',
5170
- fields: '',
5171
- dsSession: dsSessionP,
5172
- });
5217
+
5218
+ return parts;
5219
+ };
5220
+ const find_top_level_colon = function (value) {
5221
+ let quote = null;
5222
+ let escape = false;
5223
+ let paren_depth = 0;
5224
+ let bracket_depth = 0;
5225
+ let brace_depth = 0;
5226
+
5227
+ for (let index = 0; index < value.length; index++) {
5228
+ const char = value[index];
5229
+
5230
+ if (escape) {
5231
+ escape = false;
5232
+ continue;
5233
+ }
5234
+
5235
+ if (quote) {
5236
+ if (char === '\\') {
5237
+ escape = true;
5238
+ } else if (char === quote) {
5239
+ quote = null;
5173
5240
  }
5241
+ continue;
5242
+ }
5243
+
5244
+ if (char === "'" || char === '"' || char === '`') {
5245
+ quote = char;
5246
+ continue;
5247
+ }
5248
+
5249
+ if (char === '(') paren_depth++;
5250
+ if (char === ')') paren_depth = Math.max(0, paren_depth - 1);
5251
+ if (char === '[') bracket_depth++;
5252
+ if (char === ']') bracket_depth = Math.max(0, bracket_depth - 1);
5253
+ if (char === '{') brace_depth++;
5254
+ if (char === '}') brace_depth = Math.max(0, brace_depth - 1);
5255
+
5256
+ if (char === ':' && !paren_depth && !bracket_depth && !brace_depth) {
5257
+ return index;
5174
5258
  }
5175
5259
  }
5176
5260
 
5177
- return viewFields;
5261
+ return -1;
5262
+ };
5263
+
5264
+ exp = trim_wrapping_braces(exp.replace(/\n/gi, ''));
5265
+ const exp_arr = split_top_level(exp);
5266
+ for (let index = 0; index < exp_arr.length; index++) {
5267
+ const segment = exp_arr[index];
5268
+ const pos = find_top_level_colon(segment);
5269
+ if (pos === -1) {
5270
+ continue;
5271
+ }
5272
+
5273
+ let id = strip_wrapping_quotes(segment.substring(0, pos));
5274
+ const val = segment.substring(pos + 1).trim();
5275
+ if (id.substring(0, 1) === '@') {
5276
+ id = id.substring(1);
5277
+ }
5278
+ if (!id || !val) {
5279
+ continue;
5280
+ }
5281
+
5282
+ viewFields.push({
5283
+ id,
5284
+ val,
5285
+ });
5178
5286
  }
5287
+
5288
+ return viewFields;
5179
5289
  };
5180
5290
  func.datasource.get_value = async function (SESSION_ID, fieldIdP, dsSessionP, rowIdP, org_dsSessionP) {
5181
5291
  const return_value = async (field_id, value) => {
@@ -5367,6 +5477,10 @@ func.datasource.get_value = async function (SESSION_ID, fieldIdP, dsSessionP, ro
5367
5477
  if (_ds.alias) _field_id = _ds.alias[fieldIdP];
5368
5478
  }
5369
5479
 
5480
+ if (typeof _ds?.dynamic_fields?.[_field_id] !== 'undefined') {
5481
+ return await return_dynamic_value(_field_id, _ds.dynamic_fields[_field_id]);
5482
+ }
5483
+
5370
5484
  if (!org_dsSessionP && recordId) {
5371
5485
  try {
5372
5486
  const row_idx = func.common.find_ROWID_idx(_ds, recordId);
@@ -5392,10 +5506,6 @@ func.datasource.get_value = async function (SESSION_ID, fieldIdP, dsSessionP, ro
5392
5506
  }
5393
5507
  } catch (error) {}
5394
5508
 
5395
- if (typeof _ds?.dynamic_fields?.[_field_id] !== 'undefined') {
5396
- return await return_dynamic_value(_field_id, _ds.dynamic_fields[_field_id]);
5397
- }
5398
-
5399
5509
  return await search_in_parameters(fieldIdP);
5400
5510
  };
5401
5511
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/xuda-worker-bundle-min",
3
- "version": "1.3.2450",
3
+ "version": "1.3.2452",
4
4
  "description": "xuda framework min",
5
5
  "main": "index.js",
6
6
  "scripts": {