@xuda.io/xuda-worker-bundle 1.3.2714 → 1.4.8

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 +178 -47
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -484,6 +484,13 @@ func.runtime.platform.apply_element_attributes = function (node, attributes, exc
484
484
  return node;
485
485
  };
486
486
  func.runtime.platform.load_script = function (url, type, callback, attributes) {
487
+ const normalized_url = typeof url === 'string' ? url.trim() : '';
488
+ if (!normalized_url || normalized_url === 'undefined' || normalized_url === 'null') {
489
+ if (callback) {
490
+ callback();
491
+ }
492
+ return null;
493
+ }
487
494
  const doc = func.runtime.platform.get_document();
488
495
  if (!doc?.createElement || !doc?.head?.appendChild) {
489
496
  if (callback) {
@@ -498,7 +505,7 @@ func.runtime.platform.load_script = function (url, type, callback, attributes) {
498
505
  if (asset_key && script.getAttribute('data-xuda-asset-key') === asset_key) {
499
506
  return true;
500
507
  }
501
- return !!(url && script.getAttribute('src') === url);
508
+ return script.getAttribute('src') === normalized_url;
502
509
  }) || null;
503
510
  };
504
511
 
@@ -516,7 +523,7 @@ func.runtime.platform.load_script = function (url, type, callback, attributes) {
516
523
  }
517
524
 
518
525
  const script = doc.createElement('script');
519
- script.src = url;
526
+ script.src = normalized_url;
520
527
  if (type) script.type = type;
521
528
  func.runtime.platform.apply_element_attributes(script, attributes, ['src', 'type']);
522
529
  script.onload = function () {
@@ -534,6 +541,10 @@ func.runtime.platform.load_script = function (url, type, callback, attributes) {
534
541
  return script;
535
542
  };
536
543
  func.runtime.platform.load_css = function (href, attributes) {
544
+ const normalized_href = typeof href === 'string' ? href.trim() : '';
545
+ if (!normalized_href || normalized_href === 'undefined' || normalized_href === 'null') {
546
+ return null;
547
+ }
537
548
  const doc = func.runtime.platform.get_document();
538
549
  if (!doc?.createElement || !doc?.head) {
539
550
  return;
@@ -545,7 +556,7 @@ func.runtime.platform.load_css = function (href, attributes) {
545
556
  if (asset_key && link.getAttribute('data-xuda-asset-key') === asset_key) {
546
557
  return true;
547
558
  }
548
- return !!(href && link.getAttribute('href') === href);
559
+ return link.getAttribute('href') === normalized_href;
549
560
  });
550
561
  if (existing) return existing;
551
562
  } catch (err) {
@@ -554,7 +565,7 @@ func.runtime.platform.load_css = function (href, attributes) {
554
565
  const link = doc.createElement('link');
555
566
  link.rel = 'stylesheet';
556
567
  link.type = 'text/css';
557
- link.href = href;
568
+ link.href = normalized_href;
558
569
  func.runtime.platform.apply_element_attributes(link, attributes, ['href']);
559
570
  doc.head.insertBefore(link, doc.head.firstChild);
560
571
  return link;
@@ -2389,7 +2400,16 @@ func.common.getContrast_color = function (hexcolor) {
2389
2400
  };
2390
2401
 
2391
2402
  func.common.get_url = function (SESSION_ID, method, path) {
2392
- return `https://${SESSION_OBJ[SESSION_ID].domain}/${method}${path ? '/' + path : '/'}`;
2403
+ const _session = SESSION_OBJ[SESSION_ID] || {};
2404
+ const origin =
2405
+ ((typeof globalThis !== 'undefined' && globalThis.__XU_SERVER_ORIGIN__)) ||
2406
+ (_session.domain ? `https://${_session.domain}` : '');
2407
+
2408
+ if (!origin) {
2409
+ return `/${method}${path ? '/' + path : '/'}`;
2410
+ }
2411
+
2412
+ return `${origin}/${method}${path ? '/' + path : '/'}`;
2393
2413
  };
2394
2414
 
2395
2415
  var UI_FRAMEWORK_INSTALLED = null;
@@ -2467,8 +2487,24 @@ func.common.get_module = async function (SESSION_ID, module, paramsP = {}) {
2467
2487
  return module_ret;
2468
2488
  };
2469
2489
  const _session = SESSION_OBJ[SESSION_ID];
2490
+ const append_ts = function (resource_path) {
2491
+ const cache_tag =
2492
+ _session?.build_info?.runtime_ts ||
2493
+ _session?.build_info?.last_changed_ts ||
2494
+ _session?.build_info?.server_ts ||
2495
+ _session?.opt?.app_build_id ||
2496
+ (typeof globalThis !== 'undefined' ? globalThis.__XU_SERVER_BOOTSTRAP__?.version : 0) ||
2497
+ 0;
2498
+
2499
+ if (!cache_tag) {
2500
+ return resource_path;
2501
+ }
2502
+
2503
+ return `${resource_path}${resource_path.includes('?') ? '&' : '?'}ts=${cache_tag}`;
2504
+ };
2505
+
2470
2506
  if (_session.worker_type === 'Dev') {
2471
- ret = await get_ret('./modules/' + module);
2507
+ ret = await get_ret(append_ts('./modules/' + module));
2472
2508
 
2473
2509
  return ret;
2474
2510
  }
@@ -2476,7 +2512,15 @@ func.common.get_module = async function (SESSION_ID, module, paramsP = {}) {
2476
2512
  if (typeof IS_DOCKER !== 'undefined' || typeof IS_PROCESS_SERVER !== 'undefined') {
2477
2513
  ret = await get_ret(func.utils.get_resource_filename(['live_preview', 'miniapp'].includes(_session.engine_mode) ? '' : _session?.opt?.app_build_id, `${_conf.xuda_home}root/dist/runtime/js/modules/` + module));
2478
2514
  } else {
2479
- ret = await get_ret(func.common.get_url(SESSION_ID, 'dist', func.utils.get_resource_filename(['live_preview', 'miniapp'].includes(_session.engine_mode) ? '' : _session?.opt?.app_build_id, 'runtime/js/modules/' + module)));
2515
+ ret = await get_ret(
2516
+ append_ts(
2517
+ func.common.get_url(
2518
+ SESSION_ID,
2519
+ 'dist',
2520
+ func.utils.get_resource_filename(['live_preview', 'miniapp'].includes(_session.engine_mode) ? '' : _session?.opt?.app_build_id, 'runtime/js/modules/' + module),
2521
+ ),
2522
+ ),
2523
+ );
2480
2524
  }
2481
2525
 
2482
2526
  return ret;
@@ -2489,7 +2533,15 @@ func.common.get_module = async function (SESSION_ID, module, paramsP = {}) {
2489
2533
  if (typeof IS_DOCKER !== 'undefined' || typeof IS_PROCESS_SERVER !== 'undefined') {
2490
2534
  ret = await get_ret(func.utils.get_resource_filename(['live_preview', 'miniapp'].includes(_session.engine_mode) ? '' : _session?.opt?.app_build_id, `${_conf.xuda_home}root/dist/runtime/js/modules/` + rep()));
2491
2535
  } else {
2492
- ret = await get_ret(func.common.get_url(SESSION_ID, 'dist', func.utils.get_resource_filename(['live_preview', 'miniapp'].includes(_session.engine_mode) ? '' : _session?.opt?.app_build_id, 'runtime/js/modules/' + rep())));
2536
+ ret = await get_ret(
2537
+ append_ts(
2538
+ func.common.get_url(
2539
+ SESSION_ID,
2540
+ 'dist',
2541
+ func.utils.get_resource_filename(['live_preview', 'miniapp'].includes(_session.engine_mode) ? '' : _session?.opt?.app_build_id, 'runtime/js/modules/' + rep()),
2542
+ ),
2543
+ ),
2544
+ );
2493
2545
  }
2494
2546
 
2495
2547
  return ret;
@@ -2710,7 +2762,10 @@ func.common.perform_rpi_request = async function (SESSION_ID, serviceP, opt = {}
2710
2762
  const app_id = _session.app_id;
2711
2763
 
2712
2764
  if (APP_OBJ[app_id].is_deployment && _session.rpi_http_methods?.includes(serviceP)) {
2713
- url = 'https://' + _session.host + '/rpi/';
2765
+ const origin =
2766
+ ((typeof globalThis !== 'undefined' && globalThis.__XU_SERVER_ORIGIN__)) ||
2767
+ (_session.host ? 'https://' + _session.host : '');
2768
+ url = origin ? origin + '/rpi/' : url;
2714
2769
  }
2715
2770
 
2716
2771
  url += serviceP;
@@ -5151,9 +5206,9 @@ func.datasource.execute = async function (SESSION_ID, dataSourceSession, IS_DATA
5151
5206
 
5152
5207
  try {
5153
5208
  const row_idx = find_ROWID_idx_from_raw_data_arr('newRecord');
5154
- _raw_data_rows[row_idx] = [{ id: 'newRecord', value: {} }];
5209
+ _raw_data_rows[row_idx] = { id: 'newRecord', value: {} };
5155
5210
  } catch (error) {
5156
- _raw_data_rows.push({ _ROWID: 'newRecord' });
5211
+ _raw_data_rows.push({ id: 'newRecord', value: {} });
5157
5212
  }
5158
5213
  }
5159
5214
 
@@ -7200,25 +7255,54 @@ func.datasource.update_changes_for_out_parameter = async function (SESSION_ID, d
7200
7255
  let _session = SESSION_OBJ[SESSION_ID];
7201
7256
  let _ds = _session.DS_GLB[dsSessionP];
7202
7257
  const _calling_ds = _session.DS_GLB[calling_dsP];
7258
+ const get_row_idx_safe = function (target_ds, row_id) {
7259
+ if (!target_ds || !row_id) {
7260
+ return null;
7261
+ }
7262
+ try {
7263
+ return func.common.find_ROWID_idx(target_ds, row_id);
7264
+ } catch (_error) {
7265
+ return null;
7266
+ }
7267
+ };
7203
7268
 
7204
- if (_ds.PARAM_OUT_INFO) {
7205
- let data = {};
7206
- for await (const [key, val] of Object.entries(_ds.PARAM_OUT_INFO)) {
7207
- if (val.prop === 'out') {
7208
- try {
7209
- const row_idx = func.common.find_ROWID_idx(_ds, _ds.currentRecordId);
7210
- data[val.details] = _ds.data_feed.rows[row_idx][val.fieldId];
7211
- } catch (err) {
7212
- console.error(err);
7269
+ if (!_ds?.PARAM_OUT_INFO || !calling_dsP || !_calling_ds) {
7270
+ return;
7271
+ }
7272
+
7273
+ let data = {};
7274
+ for await (const [key, val] of Object.entries(_ds.PARAM_OUT_INFO)) {
7275
+ if (val.prop === 'out') {
7276
+ try {
7277
+ const current_row_idx = get_row_idx_safe(_ds, _ds.currentRecordId);
7278
+ const dataset_row_idx = get_row_idx_safe(_ds, 'dataset');
7279
+ let result;
7280
+
7281
+ if (
7282
+ current_row_idx !== null &&
7283
+ typeof _ds?.data_feed?.rows?.[current_row_idx]?.[val.fieldId] !== 'undefined'
7284
+ ) {
7285
+ result = _ds.data_feed.rows[current_row_idx][val.fieldId];
7286
+ } else if (
7287
+ dataset_row_idx !== null &&
7288
+ typeof _ds?.data_feed?.rows?.[dataset_row_idx]?.[val.fieldId] !== 'undefined'
7289
+ ) {
7290
+ result = _ds.data_feed.rows[dataset_row_idx][val.fieldId];
7213
7291
  }
7292
+
7293
+ if (typeof result !== 'undefined') {
7294
+ data[val.details] = result;
7295
+ }
7296
+ } catch (err) {
7297
+ console.error(err);
7214
7298
  }
7215
7299
  }
7216
- if (!xu_isEmpty(data)) {
7217
- let datasource_changes = {
7218
- [calling_dsP]: { [_calling_ds.currentRecordId]: data },
7219
- };
7220
- await func.datasource.update(SESSION_ID, datasource_changes);
7221
- }
7300
+ }
7301
+ if (!xu_isEmpty(data)) {
7302
+ let datasource_changes = {
7303
+ [calling_dsP]: { [_calling_ds.currentRecordId]: data },
7304
+ };
7305
+ await func.datasource.update(SESSION_ID, datasource_changes);
7222
7306
  }
7223
7307
  };
7224
7308
 
@@ -8076,6 +8160,11 @@ func.utils.clean_stringify_null = function (key, value) {
8076
8160
  };
8077
8161
 
8078
8162
  func.utils.load_js_on_demand = async function (js_src, type) {
8163
+ const normalized_src = typeof js_src === 'string' ? js_src.trim() : '';
8164
+ if (!normalized_src || normalized_src === 'undefined' || normalized_src === 'null') {
8165
+ return false;
8166
+ }
8167
+
8079
8168
  const get_script = function (callback) {
8080
8169
  if (glb.IS_WORKER) {
8081
8170
  callback();
@@ -8085,12 +8174,12 @@ func.utils.load_js_on_demand = async function (js_src, type) {
8085
8174
  return GLB_JS_SCRIPTS_LOADED.includes(src);
8086
8175
  }
8087
8176
 
8088
- if (isScriptLoaded(js_src)) {
8177
+ if (isScriptLoaded(normalized_src)) {
8089
8178
  callback(false);
8090
8179
  } else {
8091
- func.runtime.platform.load_script(js_src, type, function () {
8180
+ func.runtime.platform.load_script(normalized_src, type, function () {
8092
8181
  callback(true);
8093
- GLB_JS_SCRIPTS_LOADED.push(js_src);
8182
+ GLB_JS_SCRIPTS_LOADED.push(normalized_src);
8094
8183
  });
8095
8184
  }
8096
8185
  };
@@ -8101,7 +8190,11 @@ func.utils.load_js_on_demand = async function (js_src, type) {
8101
8190
  };
8102
8191
 
8103
8192
  func.utils.load_css_on_demand = function (css_href) {
8104
- func.runtime.platform.load_css(css_href);
8193
+ const normalized_href = typeof css_href === 'string' ? css_href.trim() : '';
8194
+ if (!normalized_href || normalized_href === 'undefined' || normalized_href === 'null') {
8195
+ return null;
8196
+ }
8197
+ return func.runtime.platform.load_css(normalized_href);
8105
8198
  };
8106
8199
 
8107
8200
  func.utils.remove_js_css_file = function (filename, filetype) {
@@ -9165,6 +9258,17 @@ func.utils.find_key_in_ViewUITreeObj = function (arr, key, val) {
9165
9258
  };
9166
9259
 
9167
9260
  func.utils.get_plugin_setup = function (SESSION_ID, plugin_name) {
9261
+ const _session = SESSION_OBJ[SESSION_ID];
9262
+ const normalize_setup_response = function (value) {
9263
+ if (value && typeof value === 'object' && Object.prototype.hasOwnProperty.call(value, 'code')) {
9264
+ return value;
9265
+ }
9266
+
9267
+ return {
9268
+ code: 1,
9269
+ data: value && typeof value === 'object' ? value : {},
9270
+ };
9271
+ };
9168
9272
  const report_error = function (descP, warn) {
9169
9273
  func.utils.debug.log(SESSION_ID, plugin_name, {
9170
9274
  module: 'plugin',
@@ -9182,20 +9286,28 @@ func.utils.get_plugin_setup = function (SESSION_ID, plugin_name) {
9182
9286
  return new Promise(async (resolve, reject) => {
9183
9287
  try {
9184
9288
  const db = await func.utils.connect_pouchdb(SESSION_ID);
9289
+ const should_bypass_cache =
9290
+ _session?.worker_type === 'Dev' ||
9291
+ (_session?.engine_mode === 'miniapp' && !_session?.app_token);
9185
9292
 
9186
- try {
9187
- let ret = await db.get(`cache_plugin_setup_${plugin_name}`);
9188
- return resolve(ret.data);
9189
- } catch (err) {
9190
- // cache not found
9191
- const json = await func.common.db(SESSION_ID, 'get_plugin_setup', {
9192
- plugin_name,
9193
- });
9194
- if (json.code < 0) {
9195
- report_error('Error: ' + json.data, json.error_type === 'W' ? true : false);
9293
+ if (!should_bypass_cache) {
9294
+ try {
9295
+ let ret = await db.get(`cache_plugin_setup_${plugin_name}`);
9296
+ return resolve(normalize_setup_response(ret.data));
9297
+ } catch (err) {
9298
+ // cache miss
9196
9299
  }
9197
- resolve(json);
9300
+ }
9198
9301
 
9302
+ const json = normalize_setup_response(await func.common.db(SESSION_ID, 'get_plugin_setup', {
9303
+ plugin_name,
9304
+ }));
9305
+ if (json.code < 0) {
9306
+ report_error('Error: ' + json.data, json.error_type === 'W' ? true : false);
9307
+ }
9308
+ resolve(json);
9309
+
9310
+ if (!should_bypass_cache) {
9199
9311
  var doc = {
9200
9312
  _id: `cache_plugin_setup_${plugin_name}`,
9201
9313
  data: json,
@@ -9206,8 +9318,13 @@ func.utils.get_plugin_setup = function (SESSION_ID, plugin_name) {
9206
9318
  } catch (e) {
9207
9319
  console.error(e);
9208
9320
 
9209
- report_error('Error: ' + e.msg, e.error_type === 'W' ? true : false);
9210
- resolve(e.msg);
9321
+ const error_message = e?.message || e?.msg || String(e || 'Unknown plugin setup error');
9322
+ report_error('Error: ' + error_message, e?.error_type === 'W' ? true : false);
9323
+ resolve({
9324
+ code: -1,
9325
+ data: error_message,
9326
+ error_type: e?.error_type,
9327
+ });
9211
9328
  }
9212
9329
  });
9213
9330
  };
@@ -9365,16 +9482,23 @@ func.utils.call_plugin_api = function (SESSION_ID, plugin_nameP, dataP) {
9365
9482
 
9366
9483
  func.utils.get_plugin_resource = function (SESSION_ID, plugin_name, plugin_resource) {
9367
9484
  var _session = SESSION_OBJ[SESSION_ID];
9485
+ const resource_ts =
9486
+ _session?.build_info?.runtime_ts ||
9487
+ _session?.build_info?.last_changed_ts ||
9488
+ _session?.build_info?.server_ts ||
9489
+ _session?.opt?.app_build_id ||
9490
+ (typeof globalThis !== 'undefined' ? globalThis.__XU_SERVER_BOOTSTRAP__?.version : 0) ||
9491
+ 0;
9368
9492
 
9369
9493
  const get_path = function (resource) {
9370
9494
  if (_session.worker_type === 'Dev') {
9371
- return `../../plugins/${plugin_name}/${resource}`;
9495
+ return `../../plugins/${plugin_name}/${resource}?ts=${resource_ts}`;
9372
9496
  }
9373
9497
  if (typeof IS_PROCESS_SERVER !== 'undefined') {
9374
9498
  return `${_conf.plugins_drive_path}/${_session.app_id}/node_modules/${plugin_name}/${resource}`;
9375
9499
  } else {
9376
9500
  // return `./node_modules/${plugin_name}/${resource}?app_id=${_session.app_id}`;
9377
- return `https://${_session.domain}/plugins/${plugin_name}/${resource}?app_id=${_session.app_id}&ts=${_session?.opt?.app_build_id || 0}`;
9501
+ return `https://${_session.domain}/plugins/${plugin_name}/${resource}?app_id=${_session.app_id}&ts=${resource_ts}`;
9378
9502
  }
9379
9503
  };
9380
9504
 
@@ -9465,6 +9589,13 @@ func.utils.remove_cached_objects = async function (SESSION_ID) {
9465
9589
 
9466
9590
  func.utils.get_plugin_npm_cdn = async function (SESSION_ID, plugin_name, resource) {
9467
9591
  const _session = SESSION_OBJ[SESSION_ID];
9592
+ const resource_ts =
9593
+ _session?.build_info?.runtime_ts ||
9594
+ _session?.build_info?.last_changed_ts ||
9595
+ _session?.build_info?.server_ts ||
9596
+ _session?.opt?.app_build_id ||
9597
+ (typeof globalThis !== 'undefined' ? globalThis.__XU_SERVER_BOOTSTRAP__?.version : 0) ||
9598
+ 0;
9468
9599
 
9469
9600
  const local_plugin_resource_url = await func.utils.get_local_studio_plugin_resource_url(SESSION_ID, plugin_name, resource);
9470
9601
  if (local_plugin_resource_url) {
@@ -9473,10 +9604,10 @@ func.utils.get_plugin_npm_cdn = async function (SESSION_ID, plugin_name, resourc
9473
9604
 
9474
9605
  const get_path = function (resource) {
9475
9606
  if (_session.worker_type === 'Dev') {
9476
- return `../../plugins/${plugin_name}/${resource}`;
9607
+ return `../../plugins/${plugin_name}/${resource}?ts=${resource_ts}`;
9477
9608
  }
9478
9609
 
9479
- return `https://${_session.domain}/plugins/${plugin_name}/${resource}?app_id=${_session.app_id}&ts=${_session?.opt?.app_build_id || 0}`;
9610
+ return `https://${_session.domain}/plugins/${plugin_name}/${resource}?app_id=${_session.app_id}&ts=${resource_ts}`;
9480
9611
  };
9481
9612
 
9482
9613
  return get_path(resource);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/xuda-worker-bundle",
3
- "version": "1.3.2714",
3
+ "version": "1.4.8",
4
4
  "description": "xuda framework",
5
5
  "main": "index.js",
6
6
  "scripts": {