@xuda.io/runtime-bundle 1.0.488 → 1.0.490

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.
@@ -34922,7 +34922,7 @@ func.UI.component.init_xu_nav = function ($container, $nav) {
34922
34922
  };
34923
34923
  func.expression = {};
34924
34924
 
34925
- func.expression.get = async function (SESSION_ID, valP, dsSessionP, sourceP, rowIdP, sourceActionP, secondPassP, calling_fieldIdP, fieldsP, debug_infoP, iterate_info, js_script_callback, jobNo, api_output_type) {
34925
+ func.expression.get_org = async function (SESSION_ID, valP, dsSessionP, sourceP, rowIdP, sourceActionP, secondPassP, calling_fieldIdP, fieldsP, debug_infoP, iterate_info, js_script_callback, jobNo, api_output_type) {
34926
34926
  class xu_class {
34927
34927
  async get() {
34928
34928
  var ret;
@@ -35042,7 +35042,7 @@ func.expression.get = async function (SESSION_ID, valP, dsSessionP, sourceP, row
35042
35042
  // var split = [];
35043
35043
  var var_Arr = [];
35044
35044
  const split = func.expression.parse(ret) || [];
35045
- console.log(valP, split);
35045
+ // console.log(valP, split);
35046
35046
  for await (const [arr_key, val] of Object.entries(split)) {
35047
35047
  // run each field
35048
35048
  const key = Number(arr_key);
@@ -35276,6 +35276,177 @@ func.expression.get = async function (SESSION_ID, valP, dsSessionP, sourceP, row
35276
35276
  return new_class.get();
35277
35277
  };
35278
35278
 
35279
+ func.expression.get = async function (SESSION_ID, valP, dsSessionP, sourceP, rowIdP, sourceActionP, secondPassP, calling_fieldIdP, fieldsP = {}, debug_infoP, iterate_info, js_script_callback, jobNo, api_output_type) {
35280
+ const evalJson = (text) => eval(`(${text})`);
35281
+ const replaceQuotes = (str) => {
35282
+ for (const [key, val] of Object.entries(fields)) {
35283
+ if (typeof val === 'string') str = str.replace(`"${val}"`, val.replace(/"/g, ''));
35284
+ }
35285
+ return str;
35286
+ };
35287
+
35288
+ let ret, error, warning, var_error_found;
35289
+ const fields = { ...fieldsP };
35290
+
35291
+ // Initial value processing
35292
+ if (valP === null || typeof valP === 'undefined') ret = '';
35293
+ else if (typeof valP === 'boolean') ret = valP ? 'Y' : 'N';
35294
+ else ret = valP.toString();
35295
+
35296
+ ret = ret.replace(/\&/g, '&');
35297
+ ret = func.utils.replace_studio_drive_url(SESSION_ID, ret);
35298
+
35299
+ // End results helper
35300
+ const endResults = () => {
35301
+ if (['update', 'javascript'].includes(sourceP) && typeof ret === 'string') {
35302
+ ret = replaceQuotes(ret);
35303
+ }
35304
+ if ((error || warning) && SESSION_OBJ[SESSION_ID]?.DS_GLB[dsSessionP]) {
35305
+ func.utils.debug.log(SESSION_ID, SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].nodeId, {
35306
+ module: 'expression',
35307
+ action: sourceP,
35308
+ source: calling_fieldIdP,
35309
+ prop: ret,
35310
+ details: ret,
35311
+ result: ret,
35312
+ error,
35313
+ warning,
35314
+ fields: null,
35315
+ type: 'exp',
35316
+ prog_id: SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].prog_id,
35317
+ debug_info: debug_infoP,
35318
+ });
35319
+ }
35320
+ return { result: ret, fields, error, warning, req: valP, var_error_found };
35321
+ };
35322
+
35323
+ // Handle non-variable cases
35324
+ const handleNonVariable = async () => {
35325
+ try {
35326
+ if (sourceP !== 'arguments') {
35327
+ if (ret.startsWith('_DATE_')) ret = ret.slice(6);
35328
+ else if (/^\d{4}-\d{2}-\d{2}$/.test(ret) || ret === 'self') return endResults();
35329
+ else ret = await func.expression.secure_eval(SESSION_ID, sourceP, ret, jobNo, dsSessionP, js_script_callback);
35330
+ } else {
35331
+ ret = ret.replace(/_NULL/gi, '');
35332
+ }
35333
+ return endResults();
35334
+ } catch (err) {
35335
+ error = err.message;
35336
+ return endResults();
35337
+ }
35338
+ };
35339
+
35340
+ // Early return for simple cases
35341
+ if (!func.expression.validate_variables(valP)) return await handleNonVariable();
35342
+ if (glb.emailRegex.test(await func.expression.secure_eval(SESSION_ID, sourceP, valP, jobNo, dsSessionP, js_script_callback))) {
35343
+ return await handleNonVariable();
35344
+ }
35345
+
35346
+ // Parse and process variables
35347
+ const split = func.expression.parse(ret) || [];
35348
+ const var_Arr = await Promise.all(
35349
+ split.map(async (val, key) => {
35350
+ const result = { value: val.value, fieldId: val.fieldId };
35351
+
35352
+ if (!val.fieldId) return result;
35353
+
35354
+ // Handle _THIS substitution
35355
+ if (val.fieldId.startsWith('_THIS') && calling_fieldIdP) {
35356
+ result.fieldId = val.fieldId.length === 5 ? calling_fieldIdP : calling_fieldIdP + val.fieldId.slice(5);
35357
+ }
35358
+
35359
+ // Fetch value from datasource
35360
+ const { ret: fetchedValue, fieldIdP } = await func.datasource.get_value(SESSION_ID, result.fieldId, dsSessionP, rowIdP);
35361
+ result.value = fetchedValue?.value ?? (sourceP === 'exp' ? fetchedValue?.value : '""');
35362
+ result.type = fetchedValue?.type;
35363
+
35364
+ // Handle iteration
35365
+ if (iterate_info) {
35366
+ if (iterate_info.iterator_key === fieldIdP) result.value = iterate_info._key;
35367
+ if (iterate_info.iterator_val === fieldIdP) result.value = iterate_info._val;
35368
+ }
35369
+
35370
+ // Process nested properties
35371
+ if (val.value.includes('[') || val.value.includes('.')) {
35372
+ const { property1, property2 } = await func.expression.get_property(val.value);
35373
+ const data = fetchedValue?.type === 'object' ? fetchedValue.value : fetchedValue?.prop;
35374
+
35375
+ if (key > 0 && val.value.includes(']') && !val.value.includes('[') && split[key - 1].value) {
35376
+ const prevData = split[key - 1].value;
35377
+ result.value = prevData[fieldIdP];
35378
+ if (val.value.includes('.') && prevData[fieldIdP]) {
35379
+ result.value = prevData[fieldIdP][property2] ?? '';
35380
+ }
35381
+ } else if (data) {
35382
+ if (property1) result.value = data[property1] ?? '';
35383
+ if (property2) result.value = (property1 ? data[property1]?.[property2] : data[property2]) ?? '';
35384
+ }
35385
+ }
35386
+
35387
+ fields[fieldIdP] = result.value;
35388
+ return result;
35389
+ }),
35390
+ );
35391
+
35392
+ // Final evaluation
35393
+ try {
35394
+ const res = var_Arr.map((val, key) => {
35395
+ if (sourceP === 'UI Property EXP' || sourceP === 'UI Attr EXP') {
35396
+ const { changed, value } = func.utils.get_drive_url(SESSION_ID, val.value, sourceP === 'UI Attr EXP' && var_Arr.length > 1);
35397
+ if (changed) return value;
35398
+ }
35399
+
35400
+ let value = val.value;
35401
+ if (var_Arr.length > 1) {
35402
+ if (!['DbQuery', 'alert', 'exp', 'api_rendered_output'].includes(sourceP) && ['string', 'date'].includes(val.type)) {
35403
+ value = `\`${value}\``;
35404
+ } else if (sourceP === 'api_rendered_output' && api_output_type === 'json' && ['string', 'date'].includes(val.type)) {
35405
+ value = `"${value}"`;
35406
+ }
35407
+ }
35408
+
35409
+ if (val.fieldId && typeof value === 'string') {
35410
+ if (['query', 'condition', 'range', 'sort', 'locate'].includes(sourceP)) value = value.replace(/↵|\r\n|\n|\r/g, '');
35411
+ if (['init', 'update', 'virtual'].includes(sourceP)) value = value.replace(/↵|\r\n|\n|\r/g, '\\n');
35412
+ if (typeof IS_PROCESS_SERVER !== 'undefined') value = value.replace(/↵|\r\n|\n|\r/g, '<br>');
35413
+ fields[val.fieldId] = value;
35414
+ }
35415
+
35416
+ if (typeof value === 'object' && var_Arr.length > 1) {
35417
+ value = Array.isArray(value) || var_Arr[key + 1]?.value?.includes('.') ? JSON.stringify(value) : `(${JSON.stringify(value)})`;
35418
+ }
35419
+
35420
+ if (!val.type === 'exp' && sourceP !== 'exp' && typeof value === 'string' && value.startsWith('@')) {
35421
+ warning = `Error encoding ${value}`;
35422
+ var_error_found = true;
35423
+ return '0';
35424
+ }
35425
+ return value;
35426
+ });
35427
+
35428
+ ret = res.length === 1 ? res[0] : res.join('');
35429
+ if (var_Arr.some((v) => v.type === 'exp') && sourceP !== 'exp' && !secondPassP) {
35430
+ const exp = await func.expression.get(SESSION_ID, ret, dsSessionP, sourceP, rowIdP, sourceActionP, true, calling_fieldIdP, fields, debug_infoP);
35431
+ ret = exp.res?.[0] ?? exp.result;
35432
+ Object.assign(fields, exp.fields);
35433
+ } else if (!secondPassP && !['arguments', 'api_rendered_output', 'DbQuery'].includes(sourceP)) {
35434
+ ret = await func.expression.secure_eval(SESSION_ID, sourceP, ret, jobNo, dsSessionP, js_script_callback);
35435
+ } else if (sourceP === 'DbQuery') {
35436
+ ret = JSON.stringify(evalJson(ret));
35437
+ }
35438
+
35439
+ if (typeof ret === 'string' && ret.startsWith('@')) {
35440
+ error = 'Error encoding @ var';
35441
+ var_error_found = true;
35442
+ }
35443
+ } catch (err) {
35444
+ error = err.message;
35445
+ }
35446
+
35447
+ return endResults();
35448
+ };
35449
+
35279
35450
  func.expression.parse_org = function (strP) {
35280
35451
  var extract_str = function (strP, posP) {
35281
35452
  if (!posP) posP = 0;
@@ -35435,50 +35606,23 @@ func.expression.parse = function (input) {
35435
35606
  const segments = [];
35436
35607
  let pos = 0;
35437
35608
 
35438
- const parts = input.split(/(@)/).filter(Boolean);
35439
-
35440
- for (let i = 0; i < parts.length; i++) {
35441
- const part = parts[i];
35609
+ const parts = input.split(/(@\w+)/).filter(Boolean);
35442
35610
 
35443
- if (part === '@' && i + 1 < parts.length) {
35444
- const nextPart = parts[i + 1];
35445
- const varEnd = nextPart.search(/[.\[]/); // Split at first . or [
35446
- let fieldId, remainder;
35447
-
35448
- if (varEnd > 0) {
35449
- fieldId = nextPart.slice(0, varEnd);
35450
- remainder = nextPart.slice(varEnd);
35451
- } else {
35452
- fieldId = nextPart;
35453
- remainder = '';
35454
- }
35455
-
35456
- // Add @variable segment
35457
- const fullVarValue = `@${fieldId}`;
35611
+ for (const part of parts) {
35612
+ if (part.startsWith('@')) {
35613
+ const fieldId = part.slice(1);
35458
35614
  segments.push({
35459
- value: fullVarValue,
35615
+ value: part,
35460
35616
  fieldId,
35461
35617
  pos,
35462
35618
  });
35463
- pos += fullVarValue.length;
35464
-
35465
- // Add remainder as a separate segment, if any
35466
- if (remainder) {
35467
- segments.push({
35468
- value: remainder,
35469
- pos,
35470
- });
35471
- pos += remainder.length;
35472
- }
35473
-
35474
- i++; // Skip the next part since we consumed it
35475
- } else if (part !== '@') {
35619
+ } else {
35476
35620
  segments.push({
35477
35621
  value: part,
35478
35622
  pos,
35479
35623
  });
35480
- pos += part.length;
35481
35624
  }
35625
+ pos += part.length;
35482
35626
  }
35483
35627
 
35484
35628
  return segments;