@xuda.io/xuda-worker-bundle-min 1.3.1511 → 1.3.1513
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.
- package/index.js +180 -36
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -7753,7 +7753,7 @@ func.events.invoke = async function (event_id) {
|
|
|
7753
7753
|
};
|
|
7754
7754
|
func.expression = {};
|
|
7755
7755
|
|
|
7756
|
-
func.expression.
|
|
7756
|
+
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) {
|
|
7757
7757
|
class xu_class {
|
|
7758
7758
|
async get() {
|
|
7759
7759
|
var ret;
|
|
@@ -7873,7 +7873,7 @@ func.expression.get = async function (SESSION_ID, valP, dsSessionP, sourceP, row
|
|
|
7873
7873
|
// var split = [];
|
|
7874
7874
|
var var_Arr = [];
|
|
7875
7875
|
const split = func.expression.parse(ret) || [];
|
|
7876
|
-
console.log(valP, split);
|
|
7876
|
+
// console.log(valP, split);
|
|
7877
7877
|
for await (const [arr_key, val] of Object.entries(split)) {
|
|
7878
7878
|
// run each field
|
|
7879
7879
|
const key = Number(arr_key);
|
|
@@ -8107,6 +8107,177 @@ func.expression.get = async function (SESSION_ID, valP, dsSessionP, sourceP, row
|
|
|
8107
8107
|
return new_class.get();
|
|
8108
8108
|
};
|
|
8109
8109
|
|
|
8110
|
+
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) {
|
|
8111
|
+
const evalJson = (text) => eval(`(${text})`);
|
|
8112
|
+
const replaceQuotes = (str) => {
|
|
8113
|
+
for (const [key, val] of Object.entries(fields)) {
|
|
8114
|
+
if (typeof val === 'string') str = str.replace(`"${val}"`, val.replace(/"/g, ''));
|
|
8115
|
+
}
|
|
8116
|
+
return str;
|
|
8117
|
+
};
|
|
8118
|
+
|
|
8119
|
+
let ret, error, warning, var_error_found;
|
|
8120
|
+
const fields = { ...fieldsP };
|
|
8121
|
+
|
|
8122
|
+
// Initial value processing
|
|
8123
|
+
if (valP === null || typeof valP === 'undefined') ret = '';
|
|
8124
|
+
else if (typeof valP === 'boolean') ret = valP ? 'Y' : 'N';
|
|
8125
|
+
else ret = valP.toString();
|
|
8126
|
+
|
|
8127
|
+
ret = ret.replace(/\&/g, '&');
|
|
8128
|
+
ret = func.utils.replace_studio_drive_url(SESSION_ID, ret);
|
|
8129
|
+
|
|
8130
|
+
// End results helper
|
|
8131
|
+
const endResults = () => {
|
|
8132
|
+
if (['update', 'javascript'].includes(sourceP) && typeof ret === 'string') {
|
|
8133
|
+
ret = replaceQuotes(ret);
|
|
8134
|
+
}
|
|
8135
|
+
if ((error || warning) && SESSION_OBJ[SESSION_ID]?.DS_GLB[dsSessionP]) {
|
|
8136
|
+
func.utils.debug.log(SESSION_ID, SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].nodeId, {
|
|
8137
|
+
module: 'expression',
|
|
8138
|
+
action: sourceP,
|
|
8139
|
+
source: calling_fieldIdP,
|
|
8140
|
+
prop: ret,
|
|
8141
|
+
details: ret,
|
|
8142
|
+
result: ret,
|
|
8143
|
+
error,
|
|
8144
|
+
warning,
|
|
8145
|
+
fields: null,
|
|
8146
|
+
type: 'exp',
|
|
8147
|
+
prog_id: SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].prog_id,
|
|
8148
|
+
debug_info: debug_infoP,
|
|
8149
|
+
});
|
|
8150
|
+
}
|
|
8151
|
+
return { result: ret, fields, error, warning, req: valP, var_error_found };
|
|
8152
|
+
};
|
|
8153
|
+
|
|
8154
|
+
// Handle non-variable cases
|
|
8155
|
+
const handleNonVariable = async () => {
|
|
8156
|
+
try {
|
|
8157
|
+
if (sourceP !== 'arguments') {
|
|
8158
|
+
if (ret.startsWith('_DATE_')) ret = ret.slice(6);
|
|
8159
|
+
else if (/^\d{4}-\d{2}-\d{2}$/.test(ret) || ret === 'self') return endResults();
|
|
8160
|
+
else ret = await func.expression.secure_eval(SESSION_ID, sourceP, ret, jobNo, dsSessionP, js_script_callback);
|
|
8161
|
+
} else {
|
|
8162
|
+
ret = ret.replace(/_NULL/gi, '');
|
|
8163
|
+
}
|
|
8164
|
+
return endResults();
|
|
8165
|
+
} catch (err) {
|
|
8166
|
+
error = err.message;
|
|
8167
|
+
return endResults();
|
|
8168
|
+
}
|
|
8169
|
+
};
|
|
8170
|
+
|
|
8171
|
+
// Early return for simple cases
|
|
8172
|
+
if (!func.expression.validate_variables(valP)) return await handleNonVariable();
|
|
8173
|
+
if (glb.emailRegex.test(await func.expression.secure_eval(SESSION_ID, sourceP, valP, jobNo, dsSessionP, js_script_callback))) {
|
|
8174
|
+
return await handleNonVariable();
|
|
8175
|
+
}
|
|
8176
|
+
|
|
8177
|
+
// Parse and process variables
|
|
8178
|
+
const split = func.expression.parse(ret) || [];
|
|
8179
|
+
const var_Arr = await Promise.all(
|
|
8180
|
+
split.map(async (val, key) => {
|
|
8181
|
+
const result = { value: val.value, fieldId: val.fieldId };
|
|
8182
|
+
|
|
8183
|
+
if (!val.fieldId) return result;
|
|
8184
|
+
|
|
8185
|
+
// Handle _THIS substitution
|
|
8186
|
+
if (val.fieldId.startsWith('_THIS') && calling_fieldIdP) {
|
|
8187
|
+
result.fieldId = val.fieldId.length === 5 ? calling_fieldIdP : calling_fieldIdP + val.fieldId.slice(5);
|
|
8188
|
+
}
|
|
8189
|
+
|
|
8190
|
+
// Fetch value from datasource
|
|
8191
|
+
const { ret: fetchedValue, fieldIdP } = await func.datasource.get_value(SESSION_ID, result.fieldId, dsSessionP, rowIdP);
|
|
8192
|
+
result.value = fetchedValue?.value ?? (sourceP === 'exp' ? fetchedValue?.value : '""');
|
|
8193
|
+
result.type = fetchedValue?.type;
|
|
8194
|
+
|
|
8195
|
+
// Handle iteration
|
|
8196
|
+
if (iterate_info) {
|
|
8197
|
+
if (iterate_info.iterator_key === fieldIdP) result.value = iterate_info._key;
|
|
8198
|
+
if (iterate_info.iterator_val === fieldIdP) result.value = iterate_info._val;
|
|
8199
|
+
}
|
|
8200
|
+
|
|
8201
|
+
// Process nested properties
|
|
8202
|
+
if (val.value.includes('[') || val.value.includes('.')) {
|
|
8203
|
+
const { property1, property2 } = await func.expression.get_property(val.value);
|
|
8204
|
+
const data = fetchedValue?.type === 'object' ? fetchedValue.value : fetchedValue?.prop;
|
|
8205
|
+
|
|
8206
|
+
if (key > 0 && val.value.includes(']') && !val.value.includes('[') && split[key - 1].value) {
|
|
8207
|
+
const prevData = split[key - 1].value;
|
|
8208
|
+
result.value = prevData[fieldIdP];
|
|
8209
|
+
if (val.value.includes('.') && prevData[fieldIdP]) {
|
|
8210
|
+
result.value = prevData[fieldIdP][property2] ?? '';
|
|
8211
|
+
}
|
|
8212
|
+
} else if (data) {
|
|
8213
|
+
if (property1) result.value = data[property1] ?? '';
|
|
8214
|
+
if (property2) result.value = (property1 ? data[property1]?.[property2] : data[property2]) ?? '';
|
|
8215
|
+
}
|
|
8216
|
+
}
|
|
8217
|
+
|
|
8218
|
+
fields[fieldIdP] = result.value;
|
|
8219
|
+
return result;
|
|
8220
|
+
}),
|
|
8221
|
+
);
|
|
8222
|
+
|
|
8223
|
+
// Final evaluation
|
|
8224
|
+
try {
|
|
8225
|
+
const res = var_Arr.map((val, key) => {
|
|
8226
|
+
if (sourceP === 'UI Property EXP' || sourceP === 'UI Attr EXP') {
|
|
8227
|
+
const { changed, value } = func.utils.get_drive_url(SESSION_ID, val.value, sourceP === 'UI Attr EXP' && var_Arr.length > 1);
|
|
8228
|
+
if (changed) return value;
|
|
8229
|
+
}
|
|
8230
|
+
|
|
8231
|
+
let value = val.value;
|
|
8232
|
+
if (var_Arr.length > 1) {
|
|
8233
|
+
if (!['DbQuery', 'alert', 'exp', 'api_rendered_output'].includes(sourceP) && ['string', 'date'].includes(val.type)) {
|
|
8234
|
+
value = `\`${value}\``;
|
|
8235
|
+
} else if (sourceP === 'api_rendered_output' && api_output_type === 'json' && ['string', 'date'].includes(val.type)) {
|
|
8236
|
+
value = `"${value}"`;
|
|
8237
|
+
}
|
|
8238
|
+
}
|
|
8239
|
+
|
|
8240
|
+
if (val.fieldId && typeof value === 'string') {
|
|
8241
|
+
if (['query', 'condition', 'range', 'sort', 'locate'].includes(sourceP)) value = value.replace(/↵|\r\n|\n|\r/g, '');
|
|
8242
|
+
if (['init', 'update', 'virtual'].includes(sourceP)) value = value.replace(/↵|\r\n|\n|\r/g, '\\n');
|
|
8243
|
+
if (typeof IS_PROCESS_SERVER !== 'undefined') value = value.replace(/↵|\r\n|\n|\r/g, '<br>');
|
|
8244
|
+
fields[val.fieldId] = value;
|
|
8245
|
+
}
|
|
8246
|
+
|
|
8247
|
+
if (typeof value === 'object' && var_Arr.length > 1) {
|
|
8248
|
+
value = Array.isArray(value) || var_Arr[key + 1]?.value?.includes('.') ? JSON.stringify(value) : `(${JSON.stringify(value)})`;
|
|
8249
|
+
}
|
|
8250
|
+
|
|
8251
|
+
if (!val.type === 'exp' && sourceP !== 'exp' && typeof value === 'string' && value.startsWith('@')) {
|
|
8252
|
+
warning = `Error encoding ${value}`;
|
|
8253
|
+
var_error_found = true;
|
|
8254
|
+
return '0';
|
|
8255
|
+
}
|
|
8256
|
+
return value;
|
|
8257
|
+
});
|
|
8258
|
+
|
|
8259
|
+
ret = res.length === 1 ? res[0] : res.join('');
|
|
8260
|
+
if (var_Arr.some((v) => v.type === 'exp') && sourceP !== 'exp' && !secondPassP) {
|
|
8261
|
+
const exp = await func.expression.get(SESSION_ID, ret, dsSessionP, sourceP, rowIdP, sourceActionP, true, calling_fieldIdP, fields, debug_infoP);
|
|
8262
|
+
ret = exp.res?.[0] ?? exp.result;
|
|
8263
|
+
Object.assign(fields, exp.fields);
|
|
8264
|
+
} else if (!secondPassP && !['arguments', 'api_rendered_output', 'DbQuery'].includes(sourceP)) {
|
|
8265
|
+
ret = await func.expression.secure_eval(SESSION_ID, sourceP, ret, jobNo, dsSessionP, js_script_callback);
|
|
8266
|
+
} else if (sourceP === 'DbQuery') {
|
|
8267
|
+
ret = JSON.stringify(evalJson(ret));
|
|
8268
|
+
}
|
|
8269
|
+
|
|
8270
|
+
if (typeof ret === 'string' && ret.startsWith('@')) {
|
|
8271
|
+
error = 'Error encoding @ var';
|
|
8272
|
+
var_error_found = true;
|
|
8273
|
+
}
|
|
8274
|
+
} catch (err) {
|
|
8275
|
+
error = err.message;
|
|
8276
|
+
}
|
|
8277
|
+
|
|
8278
|
+
return endResults();
|
|
8279
|
+
};
|
|
8280
|
+
|
|
8110
8281
|
func.expression.parse_org = function (strP) {
|
|
8111
8282
|
var extract_str = function (strP, posP) {
|
|
8112
8283
|
if (!posP) posP = 0;
|
|
@@ -8266,50 +8437,23 @@ func.expression.parse = function (input) {
|
|
|
8266
8437
|
const segments = [];
|
|
8267
8438
|
let pos = 0;
|
|
8268
8439
|
|
|
8269
|
-
const parts = input.split(/(
|
|
8270
|
-
|
|
8271
|
-
for (let i = 0; i < parts.length; i++) {
|
|
8272
|
-
const part = parts[i];
|
|
8440
|
+
const parts = input.split(/(@\w+)/).filter(Boolean);
|
|
8273
8441
|
|
|
8274
|
-
|
|
8275
|
-
|
|
8276
|
-
const
|
|
8277
|
-
let fieldId, remainder;
|
|
8278
|
-
|
|
8279
|
-
if (varEnd > 0) {
|
|
8280
|
-
fieldId = nextPart.slice(0, varEnd);
|
|
8281
|
-
remainder = nextPart.slice(varEnd);
|
|
8282
|
-
} else {
|
|
8283
|
-
fieldId = nextPart;
|
|
8284
|
-
remainder = '';
|
|
8285
|
-
}
|
|
8286
|
-
|
|
8287
|
-
// Add @variable segment
|
|
8288
|
-
const fullVarValue = `@${fieldId}`;
|
|
8442
|
+
for (const part of parts) {
|
|
8443
|
+
if (part.startsWith('@')) {
|
|
8444
|
+
const fieldId = part.slice(1);
|
|
8289
8445
|
segments.push({
|
|
8290
|
-
value:
|
|
8446
|
+
value: part,
|
|
8291
8447
|
fieldId,
|
|
8292
8448
|
pos,
|
|
8293
8449
|
});
|
|
8294
|
-
|
|
8295
|
-
|
|
8296
|
-
// Add remainder as a separate segment, if any
|
|
8297
|
-
if (remainder) {
|
|
8298
|
-
segments.push({
|
|
8299
|
-
value: remainder,
|
|
8300
|
-
pos,
|
|
8301
|
-
});
|
|
8302
|
-
pos += remainder.length;
|
|
8303
|
-
}
|
|
8304
|
-
|
|
8305
|
-
i++; // Skip the next part since we consumed it
|
|
8306
|
-
} else if (part !== '@') {
|
|
8450
|
+
} else {
|
|
8307
8451
|
segments.push({
|
|
8308
8452
|
value: part,
|
|
8309
8453
|
pos,
|
|
8310
8454
|
});
|
|
8311
|
-
pos += part.length;
|
|
8312
8455
|
}
|
|
8456
|
+
pos += part.length;
|
|
8313
8457
|
}
|
|
8314
8458
|
|
|
8315
8459
|
return segments;
|