@xuda.io/xuda-worker-bundle-min 1.3.2449 → 1.3.2451

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 +136 -43
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -5126,56 +5126,149 @@ func.datasource.get_viewFields_for_update_function = function (SESSION_ID, calli
5126
5126
  if (!exp) {
5127
5127
  return viewFields;
5128
5128
  }
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
- });
5129
+ const trim_wrapping_braces = function (value) {
5130
+ const trimmed = value.trim();
5131
+ if (trimmed.startsWith('{') && trimmed.endsWith('}')) {
5132
+ return trimmed.substring(1, trimmed.length - 1);
5133
+ }
5134
+ return trimmed;
5135
+ };
5136
+ const strip_wrapping_quotes = function (value) {
5137
+ const trimmed = value.trim();
5138
+ const first = trimmed.substring(0, 1);
5139
+ const last = trimmed.substring(trimmed.length - 1);
5140
+ if ((first === "'" || first === '"' || first === '`') && last === first) {
5141
+ return trimmed.substring(1, trimmed.length - 1);
5142
+ }
5143
+ return trimmed;
5144
+ };
5145
+ const split_top_level = function (value) {
5146
+ const parts = [];
5147
+ let current = '';
5148
+ let quote = null;
5149
+ let escape = false;
5150
+ let paren_depth = 0;
5151
+ let bracket_depth = 0;
5152
+ let brace_depth = 0;
5153
+
5154
+ for (let index = 0; index < value.length; index++) {
5155
+ const char = value[index];
5156
+
5157
+ if (escape) {
5158
+ current += char;
5159
+ escape = false;
5160
+ continue;
5161
+ }
5162
+
5163
+ if (quote) {
5164
+ current += char;
5165
+ if (char === '\\') {
5166
+ escape = true;
5167
+ } else if (char === quote) {
5168
+ quote = null;
5169
+ }
5170
+ continue;
5171
+ }
5172
+
5173
+ if (char === "'" || char === '"' || char === '`') {
5174
+ quote = char;
5175
+ current += char;
5176
+ continue;
5177
+ }
5178
+
5179
+ if (char === '(') paren_depth++;
5180
+ if (char === ')') paren_depth = Math.max(0, paren_depth - 1);
5181
+ if (char === '[') bracket_depth++;
5182
+ if (char === ']') bracket_depth = Math.max(0, bracket_depth - 1);
5183
+ if (char === '{') brace_depth++;
5184
+ if (char === '}') brace_depth = Math.max(0, brace_depth - 1);
5185
+
5186
+ if ((char === ',' || char === ';') && !paren_depth && !bracket_depth && !brace_depth) {
5187
+ if (current.trim()) {
5188
+ parts.push(current.trim());
5189
+ }
5190
+ current = '';
5191
+ continue;
5192
+ }
5193
+
5194
+ current += char;
5139
5195
  }
5140
- return viewFields;
5141
- } catch (e) {
5142
- if (!exp) {
5143
- return;
5196
+
5197
+ if (current.trim()) {
5198
+ parts.push(current.trim());
5144
5199
  }
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
- });
5200
+
5201
+ return parts;
5202
+ };
5203
+ const find_top_level_colon = function (value) {
5204
+ let quote = null;
5205
+ let escape = false;
5206
+ let paren_depth = 0;
5207
+ let bracket_depth = 0;
5208
+ let brace_depth = 0;
5209
+
5210
+ for (let index = 0; index < value.length; index++) {
5211
+ const char = value[index];
5212
+
5213
+ if (escape) {
5214
+ escape = false;
5215
+ continue;
5216
+ }
5217
+
5218
+ if (quote) {
5219
+ if (char === '\\') {
5220
+ escape = true;
5221
+ } else if (char === quote) {
5222
+ quote = null;
5173
5223
  }
5224
+ continue;
5225
+ }
5226
+
5227
+ if (char === "'" || char === '"' || char === '`') {
5228
+ quote = char;
5229
+ continue;
5230
+ }
5231
+
5232
+ if (char === '(') paren_depth++;
5233
+ if (char === ')') paren_depth = Math.max(0, paren_depth - 1);
5234
+ if (char === '[') bracket_depth++;
5235
+ if (char === ']') bracket_depth = Math.max(0, bracket_depth - 1);
5236
+ if (char === '{') brace_depth++;
5237
+ if (char === '}') brace_depth = Math.max(0, brace_depth - 1);
5238
+
5239
+ if (char === ':' && !paren_depth && !bracket_depth && !brace_depth) {
5240
+ return index;
5174
5241
  }
5175
5242
  }
5176
5243
 
5177
- return viewFields;
5244
+ return -1;
5245
+ };
5246
+
5247
+ exp = trim_wrapping_braces(exp.replace(/\n/gi, ''));
5248
+ const exp_arr = split_top_level(exp);
5249
+ for (let index = 0; index < exp_arr.length; index++) {
5250
+ const segment = exp_arr[index];
5251
+ const pos = find_top_level_colon(segment);
5252
+ if (pos === -1) {
5253
+ continue;
5254
+ }
5255
+
5256
+ let id = strip_wrapping_quotes(segment.substring(0, pos));
5257
+ const val = segment.substring(pos + 1).trim();
5258
+ if (id.substring(0, 1) === '@') {
5259
+ id = id.substring(1);
5260
+ }
5261
+ if (!id || !val) {
5262
+ continue;
5263
+ }
5264
+
5265
+ viewFields.push({
5266
+ id,
5267
+ val,
5268
+ });
5178
5269
  }
5270
+
5271
+ return viewFields;
5179
5272
  };
5180
5273
  func.datasource.get_value = async function (SESSION_ID, fieldIdP, dsSessionP, rowIdP, org_dsSessionP) {
5181
5274
  const return_value = async (field_id, value) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/xuda-worker-bundle-min",
3
- "version": "1.3.2449",
3
+ "version": "1.3.2451",
4
4
  "description": "xuda framework min",
5
5
  "main": "index.js",
6
6
  "scripts": {