@xuda.io/xuda-worker-bundle 1.3.2693 → 1.3.2694
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 +264 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -610,6 +610,147 @@ func.runtime.workers.delete_promise = function (SESSION_ID, worker_id, promise_q
|
|
|
610
610
|
delete registry_entry.promise_queue[promise_queue_id];
|
|
611
611
|
return true;
|
|
612
612
|
};
|
|
613
|
+
func.runtime.render.clone_runtime_options = function (value) {
|
|
614
|
+
if (typeof structuredClone === 'function') {
|
|
615
|
+
try {
|
|
616
|
+
return structuredClone(value);
|
|
617
|
+
} catch (_) {}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
if (Array.isArray(value)) {
|
|
621
|
+
return value.map(function (item) {
|
|
622
|
+
return func.runtime.render.clone_runtime_options(item);
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
if (value && typeof value === 'object') {
|
|
627
|
+
const cloned = {};
|
|
628
|
+
const keys = Object.keys(value);
|
|
629
|
+
for (let index = 0; index < keys.length; index++) {
|
|
630
|
+
const key = keys[index];
|
|
631
|
+
cloned[key] = func.runtime.render.clone_runtime_options(value[key]);
|
|
632
|
+
}
|
|
633
|
+
return cloned;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
return value;
|
|
637
|
+
};
|
|
638
|
+
func.runtime.render.normalize_runtime_bootstrap = function (raw_options = {}) {
|
|
639
|
+
const options = raw_options || {};
|
|
640
|
+
let app_computing_mode = options.app_computing_mode || '';
|
|
641
|
+
let app_render_mode = options.app_render_mode || '';
|
|
642
|
+
let app_client_activation = options.app_client_activation || '';
|
|
643
|
+
let ssr_payload = options.ssr_payload || null;
|
|
644
|
+
|
|
645
|
+
if (typeof ssr_payload === 'string') {
|
|
646
|
+
try {
|
|
647
|
+
ssr_payload = JSON.parse(ssr_payload);
|
|
648
|
+
} catch (_) {
|
|
649
|
+
ssr_payload = null;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
if (ssr_payload && typeof ssr_payload === 'object') {
|
|
654
|
+
ssr_payload = func.runtime.render.clone_runtime_options(ssr_payload);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
if (!app_computing_mode) {
|
|
658
|
+
if (app_render_mode === 'ssr_first_page' || app_render_mode === 'ssr_full') {
|
|
659
|
+
app_computing_mode = 'server';
|
|
660
|
+
} else {
|
|
661
|
+
app_computing_mode = 'main';
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
switch (app_computing_mode) {
|
|
666
|
+
case 'main':
|
|
667
|
+
app_render_mode = 'csr';
|
|
668
|
+
app_client_activation = 'none';
|
|
669
|
+
break;
|
|
670
|
+
|
|
671
|
+
case 'worker':
|
|
672
|
+
app_render_mode = 'csr';
|
|
673
|
+
app_client_activation = 'none';
|
|
674
|
+
break;
|
|
675
|
+
|
|
676
|
+
default:
|
|
677
|
+
app_computing_mode = 'server';
|
|
678
|
+
if (app_render_mode !== 'ssr_full') {
|
|
679
|
+
app_render_mode = 'ssr_first_page';
|
|
680
|
+
}
|
|
681
|
+
app_client_activation = app_render_mode === 'ssr_full' ? 'hydrate' : 'takeover';
|
|
682
|
+
break;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
if (ssr_payload && typeof ssr_payload === 'object') {
|
|
686
|
+
if (!ssr_payload.app_render_mode) {
|
|
687
|
+
ssr_payload.app_render_mode = app_render_mode;
|
|
688
|
+
}
|
|
689
|
+
if (!ssr_payload.app_client_activation) {
|
|
690
|
+
ssr_payload.app_client_activation = app_client_activation;
|
|
691
|
+
}
|
|
692
|
+
if (!ssr_payload.app_computing_mode) {
|
|
693
|
+
ssr_payload.app_computing_mode = app_computing_mode;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
return {
|
|
698
|
+
app_computing_mode,
|
|
699
|
+
app_render_mode,
|
|
700
|
+
app_client_activation,
|
|
701
|
+
ssr_payload,
|
|
702
|
+
};
|
|
703
|
+
};
|
|
704
|
+
func.runtime.render.apply_runtime_bootstrap_defaults = function (target = {}) {
|
|
705
|
+
const normalized = func.runtime.render.normalize_runtime_bootstrap(target);
|
|
706
|
+
target.app_computing_mode = normalized.app_computing_mode;
|
|
707
|
+
target.app_render_mode = normalized.app_render_mode;
|
|
708
|
+
target.app_client_activation = normalized.app_client_activation;
|
|
709
|
+
target.ssr_payload = normalized.ssr_payload;
|
|
710
|
+
return normalized;
|
|
711
|
+
};
|
|
712
|
+
func.runtime.render.is_server_render_mode = function (target = {}) {
|
|
713
|
+
const normalized = func.runtime.render.normalize_runtime_bootstrap(target?.opt || target);
|
|
714
|
+
return normalized.app_computing_mode === 'server' && normalized.app_render_mode !== 'csr';
|
|
715
|
+
};
|
|
716
|
+
func.runtime.render.is_takeover_mode = function (target = {}) {
|
|
717
|
+
const normalized = func.runtime.render.normalize_runtime_bootstrap(target?.opt || target);
|
|
718
|
+
return normalized.app_client_activation === 'takeover';
|
|
719
|
+
};
|
|
720
|
+
func.runtime.render.is_hydration_mode = function (target = {}) {
|
|
721
|
+
const normalized = func.runtime.render.normalize_runtime_bootstrap(target?.opt || target);
|
|
722
|
+
return normalized.app_client_activation === 'hydrate';
|
|
723
|
+
};
|
|
724
|
+
func.runtime.render.get_ssr_payload = function (target = {}) {
|
|
725
|
+
if (target?.opt?.ssr_payload) {
|
|
726
|
+
return target.opt.ssr_payload;
|
|
727
|
+
}
|
|
728
|
+
if (target?.ssr_payload) {
|
|
729
|
+
return target.ssr_payload;
|
|
730
|
+
}
|
|
731
|
+
const win = func.runtime.platform.get_window();
|
|
732
|
+
return win?.__XUDA_SSR__ || null;
|
|
733
|
+
};
|
|
734
|
+
func.runtime.render.should_use_ssr_payload = function (SESSION_ID, paramsP) {
|
|
735
|
+
const session = SESSION_OBJ?.[SESSION_ID];
|
|
736
|
+
const payload = func.runtime.render.get_ssr_payload(session);
|
|
737
|
+
if (!payload || payload._consumed) {
|
|
738
|
+
return false;
|
|
739
|
+
}
|
|
740
|
+
if (paramsP?.prog_id && payload.prog_id && payload.prog_id !== paramsP.prog_id) {
|
|
741
|
+
return false;
|
|
742
|
+
}
|
|
743
|
+
return true;
|
|
744
|
+
};
|
|
745
|
+
func.runtime.render.mark_ssr_payload_consumed = function (SESSION_ID) {
|
|
746
|
+
const session = SESSION_OBJ?.[SESSION_ID];
|
|
747
|
+
const payload = func.runtime.render.get_ssr_payload(session);
|
|
748
|
+
if (!payload || typeof payload !== 'object') {
|
|
749
|
+
return false;
|
|
750
|
+
}
|
|
751
|
+
payload._consumed = true;
|
|
752
|
+
return true;
|
|
753
|
+
};
|
|
613
754
|
func.runtime.render.get_root_data_system = function (SESSION_ID) {
|
|
614
755
|
return SESSION_OBJ[SESSION_ID]?.DS_GLB?.[0]?.data_system || null;
|
|
615
756
|
};
|
|
@@ -2914,6 +3055,129 @@ func.runtime.render.render_to_string = async function (options = {}) {
|
|
|
2914
3055
|
});
|
|
2915
3056
|
|
|
2916
3057
|
return await func.runtime.render.render_tree_to_string(treeP, options);
|
|
3058
|
+
};
|
|
3059
|
+
func.runtime.render.get_server_render_mode = function (options = {}) {
|
|
3060
|
+
const normalized = func.runtime.render.normalize_runtime_bootstrap({
|
|
3061
|
+
app_computing_mode: options.app_computing_mode,
|
|
3062
|
+
app_render_mode: options.app_render_mode,
|
|
3063
|
+
app_client_activation: options.app_client_activation,
|
|
3064
|
+
});
|
|
3065
|
+
|
|
3066
|
+
return normalized;
|
|
3067
|
+
};
|
|
3068
|
+
func.runtime.render.build_server_render_params = async function (options = {}) {
|
|
3069
|
+
const SESSION_ID = options.SESSION_ID;
|
|
3070
|
+
const prog_id = options.prog_id;
|
|
3071
|
+
const dsSessionP = options.dsSessionP;
|
|
3072
|
+
const _session = SESSION_OBJ?.[SESSION_ID] || {};
|
|
3073
|
+
const _ds = _session?.DS_GLB?.[dsSessionP] || {};
|
|
3074
|
+
const viewDoc = options.viewDoc || (await func.utils?.VIEWS_OBJ?.get?.(SESSION_ID, prog_id));
|
|
3075
|
+
|
|
3076
|
+
if (!viewDoc?.properties) {
|
|
3077
|
+
throw new Error(`view document not found for ${prog_id}`);
|
|
3078
|
+
}
|
|
3079
|
+
|
|
3080
|
+
const base_params = _ds?.screen_params ? func.runtime.render.safe_clone_tree_value(_ds.screen_params) : {};
|
|
3081
|
+
const screenId = options.screenId || base_params.screenId || `ssr_${prog_id}_${dsSessionP || '0'}`;
|
|
3082
|
+
const paramsP = {
|
|
3083
|
+
...base_params,
|
|
3084
|
+
prog_id,
|
|
3085
|
+
sourceScreenP: null,
|
|
3086
|
+
$callingContainerP: null,
|
|
3087
|
+
triggerIdP: null,
|
|
3088
|
+
callingDataSource_objP: _ds,
|
|
3089
|
+
rowIdP: typeof options.rowIdP !== 'undefined' ? options.rowIdP : (_ds?.currentRecordId || null),
|
|
3090
|
+
renderType: viewDoc.properties?.renderType,
|
|
3091
|
+
parameters_obj_inP: options.parameters_obj_inP || base_params.parameters_obj_inP || options.parameters_raw_obj || {},
|
|
3092
|
+
source_functionP: options.source_functionP || base_params.source_functionP || 'render_string',
|
|
3093
|
+
is_panelP: false,
|
|
3094
|
+
screen_type: options.screen_type || base_params.screen_type || 'render_string',
|
|
3095
|
+
screenInfo: viewDoc,
|
|
3096
|
+
call_screen_propertiesP: base_params.call_screen_propertiesP,
|
|
3097
|
+
parentDataSourceNoP: typeof _ds?.parentDataSourceNo === 'undefined' || _ds?.parentDataSourceNo === null ? 0 : _ds.parentDataSourceNo,
|
|
3098
|
+
parameters_raw_obj: options.parameters_raw_obj || base_params.parameters_raw_obj || {},
|
|
3099
|
+
dsSessionP,
|
|
3100
|
+
screenId,
|
|
3101
|
+
containerIdP: base_params.containerIdP || `ssr_container_${screenId}`,
|
|
3102
|
+
};
|
|
3103
|
+
|
|
3104
|
+
if (_ds) {
|
|
3105
|
+
_ds.screen_params = paramsP;
|
|
3106
|
+
}
|
|
3107
|
+
|
|
3108
|
+
return paramsP;
|
|
3109
|
+
};
|
|
3110
|
+
func.runtime.render.build_prog_tree = async function (options = {}) {
|
|
3111
|
+
const SESSION_ID = options.SESSION_ID;
|
|
3112
|
+
const prog_id = options.prog_id;
|
|
3113
|
+
const viewDoc = options.viewDoc || (await func.utils?.VIEWS_OBJ?.get?.(SESSION_ID, prog_id));
|
|
3114
|
+
|
|
3115
|
+
if (!viewDoc?.progUi?.length) {
|
|
3116
|
+
throw new Error(`progUi not found for ${prog_id}`);
|
|
3117
|
+
}
|
|
3118
|
+
|
|
3119
|
+
const paramsP = options.paramsP || (await func.runtime.render.build_server_render_params({
|
|
3120
|
+
...options,
|
|
3121
|
+
SESSION_ID,
|
|
3122
|
+
prog_id,
|
|
3123
|
+
viewDoc,
|
|
3124
|
+
}));
|
|
3125
|
+
const root_index = typeof options.root_index === 'number' ? options.root_index : 0;
|
|
3126
|
+
const root_node = func.runtime.render.safe_clone_tree_value(viewDoc.progUi[root_index]);
|
|
3127
|
+
const tree = await func.runtime.render.build_tree({
|
|
3128
|
+
SESSION_ID,
|
|
3129
|
+
nodeP: root_node,
|
|
3130
|
+
paramsP,
|
|
3131
|
+
});
|
|
3132
|
+
|
|
3133
|
+
return {
|
|
3134
|
+
tree,
|
|
3135
|
+
paramsP,
|
|
3136
|
+
viewDoc,
|
|
3137
|
+
};
|
|
3138
|
+
};
|
|
3139
|
+
func.runtime.render.build_ssr_payload = function (render_program, options = {}) {
|
|
3140
|
+
const runtime_profile = func.runtime.render.get_server_render_mode(options);
|
|
3141
|
+
return {
|
|
3142
|
+
contract: 'xuda.ssr.v1',
|
|
3143
|
+
prog_id: options.prog_id,
|
|
3144
|
+
screenId: render_program.paramsP.screenId,
|
|
3145
|
+
containerId: render_program.paramsP.containerIdP,
|
|
3146
|
+
app_computing_mode: runtime_profile.app_computing_mode,
|
|
3147
|
+
app_render_mode: runtime_profile.app_render_mode,
|
|
3148
|
+
app_client_activation: runtime_profile.app_client_activation,
|
|
3149
|
+
tree_contract: func.runtime.render.TREE_CONTRACT_VERSION,
|
|
3150
|
+
};
|
|
3151
|
+
};
|
|
3152
|
+
func.runtime.render.build_ssr_screen_html = function (html, render_program, options = {}) {
|
|
3153
|
+
const payload = func.runtime.render.build_ssr_payload(render_program, options);
|
|
3154
|
+
const screenId = func.runtime.render.escape_html_attribute(payload.screenId || '');
|
|
3155
|
+
const containerId = func.runtime.render.escape_html_attribute(payload.containerId || '');
|
|
3156
|
+
const activation = func.runtime.render.escape_html_attribute(payload.app_client_activation || 'takeover');
|
|
3157
|
+
|
|
3158
|
+
return `<div data-xuda-ssr-embed="true" class="xu_embed_div"><div id="${screenId}" class="xu_embed_container" data-xuda-ssr-screen="true" data-xuda-ssr-screen-id="${screenId}" data-xuda-activation="${activation}" style="display: contents;"><div id="${containerId}" data-xuda-ssr-root-frame="true" data-xuda-ssr-screen-id="${screenId}" data-xuda-activation="${activation}" style="display: contents;">${html}</div></div></div>`;
|
|
3159
|
+
};
|
|
3160
|
+
func.runtime.render.render_prog_to_string = async function (options = {}) {
|
|
3161
|
+
const render_program = await func.runtime.render.build_prog_tree(options);
|
|
3162
|
+
const html = await func.runtime.render.render_to_string({
|
|
3163
|
+
...options,
|
|
3164
|
+
SESSION_ID: options.SESSION_ID,
|
|
3165
|
+
treeP: render_program.tree,
|
|
3166
|
+
paramsP: render_program.paramsP,
|
|
3167
|
+
});
|
|
3168
|
+
const ssr_payload = func.runtime.render.build_ssr_payload(render_program, options);
|
|
3169
|
+
const screen_html = func.runtime.render.build_ssr_screen_html(html, render_program, options);
|
|
3170
|
+
|
|
3171
|
+
return {
|
|
3172
|
+
prog_id: options.prog_id,
|
|
3173
|
+
dsSessionP: render_program.paramsP.dsSessionP,
|
|
3174
|
+
screenId: render_program.paramsP.screenId,
|
|
3175
|
+
html,
|
|
3176
|
+
screen_html,
|
|
3177
|
+
tree_json: func.runtime.render.serialize_tree(render_program.tree),
|
|
3178
|
+
paramsP: render_program.paramsP,
|
|
3179
|
+
ssr_payload,
|
|
3180
|
+
};
|
|
2917
3181
|
};
|
|
2918
3182
|
glb.DEBUG_INFO_OBJ = {};
|
|
2919
3183
|
// var CONNECTION_ATTEMPTS = 0;
|