@xuda.io/runtime-bundle 1.0.1425 → 1.0.1426

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.
@@ -39953,56 +39953,149 @@ func.datasource.get_viewFields_for_update_function = function (SESSION_ID, calli
39953
39953
  if (!exp) {
39954
39954
  return viewFields;
39955
39955
  }
39956
- try {
39957
- // parse json
39958
- var json = JSON5.parse(exp.replace(/\n/gi, ''));
39959
- for (const [key, val] of Object.entries(json)) {
39960
- let id = key.substr(1, key.length - 1);
39961
- if (!id) continue;
39962
- viewFields.push({
39963
- val,
39964
- id,
39965
- });
39956
+ const trim_wrapping_braces = function (value) {
39957
+ const trimmed = value.trim();
39958
+ if (trimmed.startsWith('{') && trimmed.endsWith('}')) {
39959
+ return trimmed.substring(1, trimmed.length - 1);
39960
+ }
39961
+ return trimmed;
39962
+ };
39963
+ const strip_wrapping_quotes = function (value) {
39964
+ const trimmed = value.trim();
39965
+ const first = trimmed.substring(0, 1);
39966
+ const last = trimmed.substring(trimmed.length - 1);
39967
+ if ((first === "'" || first === '"' || first === '`') && last === first) {
39968
+ return trimmed.substring(1, trimmed.length - 1);
39969
+ }
39970
+ return trimmed;
39971
+ };
39972
+ const split_top_level = function (value) {
39973
+ const parts = [];
39974
+ let current = '';
39975
+ let quote = null;
39976
+ let escape = false;
39977
+ let paren_depth = 0;
39978
+ let bracket_depth = 0;
39979
+ let brace_depth = 0;
39980
+
39981
+ for (let index = 0; index < value.length; index++) {
39982
+ const char = value[index];
39983
+
39984
+ if (escape) {
39985
+ current += char;
39986
+ escape = false;
39987
+ continue;
39988
+ }
39989
+
39990
+ if (quote) {
39991
+ current += char;
39992
+ if (char === '\\') {
39993
+ escape = true;
39994
+ } else if (char === quote) {
39995
+ quote = null;
39996
+ }
39997
+ continue;
39998
+ }
39999
+
40000
+ if (char === "'" || char === '"' || char === '`') {
40001
+ quote = char;
40002
+ current += char;
40003
+ continue;
40004
+ }
40005
+
40006
+ if (char === '(') paren_depth++;
40007
+ if (char === ')') paren_depth = Math.max(0, paren_depth - 1);
40008
+ if (char === '[') bracket_depth++;
40009
+ if (char === ']') bracket_depth = Math.max(0, bracket_depth - 1);
40010
+ if (char === '{') brace_depth++;
40011
+ if (char === '}') brace_depth = Math.max(0, brace_depth - 1);
40012
+
40013
+ if ((char === ',' || char === ';') && !paren_depth && !bracket_depth && !brace_depth) {
40014
+ if (current.trim()) {
40015
+ parts.push(current.trim());
40016
+ }
40017
+ current = '';
40018
+ continue;
40019
+ }
40020
+
40021
+ current += char;
39966
40022
  }
39967
- return viewFields;
39968
- } catch (e) {
39969
- if (!exp) {
39970
- return;
40023
+
40024
+ if (current.trim()) {
40025
+ parts.push(current.trim());
39971
40026
  }
39972
- if (exp.substr(exp.length - 1, 1) === ';') exp = exp.substr(0, exp.length - 1); // remove closing if exist;
39973
- var exp_arr = exp.split(/;\s*(?=(?:[^"]|"[^"]*")*$)/g); // split ; outside quotes
39974
- if (exp_arr?.length) {
39975
- for (let val of exp_arr) {
39976
- // run view fields
39977
- var pos = val.indexOf(':');
39978
- var seg = [val.substring(0, pos), val.substring(pos + 1)];
39979
- if (seg && seg.length === 2) {
39980
- let id = seg[0].substr(1, seg[0].length);
39981
- if (!id) continue;
39982
- viewFields.push({
39983
- id,
39984
- val: seg[1],
39985
- // , props: {},
39986
- });
39987
- } else {
39988
- func.utils.debug.log(SESSION_ID, _ds.prog_id, {
39989
- module: _ds.viewModule,
39990
- action: 'set',
39991
- prop: 'parse update exp',
39992
- details: exp,
39993
- result: '',
39994
- error: 'Invalid json; too many segments',
39995
- source: _ds.viewSourceDesc,
39996
- json: '',
39997
- fields: '',
39998
- dsSession: dsSessionP,
39999
- });
40027
+
40028
+ return parts;
40029
+ };
40030
+ const find_top_level_colon = function (value) {
40031
+ let quote = null;
40032
+ let escape = false;
40033
+ let paren_depth = 0;
40034
+ let bracket_depth = 0;
40035
+ let brace_depth = 0;
40036
+
40037
+ for (let index = 0; index < value.length; index++) {
40038
+ const char = value[index];
40039
+
40040
+ if (escape) {
40041
+ escape = false;
40042
+ continue;
40043
+ }
40044
+
40045
+ if (quote) {
40046
+ if (char === '\\') {
40047
+ escape = true;
40048
+ } else if (char === quote) {
40049
+ quote = null;
40000
40050
  }
40051
+ continue;
40052
+ }
40053
+
40054
+ if (char === "'" || char === '"' || char === '`') {
40055
+ quote = char;
40056
+ continue;
40057
+ }
40058
+
40059
+ if (char === '(') paren_depth++;
40060
+ if (char === ')') paren_depth = Math.max(0, paren_depth - 1);
40061
+ if (char === '[') bracket_depth++;
40062
+ if (char === ']') bracket_depth = Math.max(0, bracket_depth - 1);
40063
+ if (char === '{') brace_depth++;
40064
+ if (char === '}') brace_depth = Math.max(0, brace_depth - 1);
40065
+
40066
+ if (char === ':' && !paren_depth && !bracket_depth && !brace_depth) {
40067
+ return index;
40001
40068
  }
40002
40069
  }
40003
40070
 
40004
- return viewFields;
40071
+ return -1;
40072
+ };
40073
+
40074
+ exp = trim_wrapping_braces(exp.replace(/\n/gi, ''));
40075
+ const exp_arr = split_top_level(exp);
40076
+ for (let index = 0; index < exp_arr.length; index++) {
40077
+ const segment = exp_arr[index];
40078
+ const pos = find_top_level_colon(segment);
40079
+ if (pos === -1) {
40080
+ continue;
40081
+ }
40082
+
40083
+ let id = strip_wrapping_quotes(segment.substring(0, pos));
40084
+ const val = segment.substring(pos + 1).trim();
40085
+ if (id.substring(0, 1) === '@') {
40086
+ id = id.substring(1);
40087
+ }
40088
+ if (!id || !val) {
40089
+ continue;
40090
+ }
40091
+
40092
+ viewFields.push({
40093
+ id,
40094
+ val,
40095
+ });
40005
40096
  }
40097
+
40098
+ return viewFields;
40006
40099
  };
40007
40100
  func.datasource.get_value = async function (SESSION_ID, fieldIdP, dsSessionP, rowIdP, org_dsSessionP) {
40008
40101
  const return_value = async (field_id, value) => {