From 70e074dfdddc2801d78176654675a076b7d89c1e Mon Sep 17 00:00:00 2001 From: Hannah Date: Tue, 4 Jun 2024 19:02:07 +0200 Subject: [PATCH] test --- client/js/src/helpers/data.ts | 48 +++++++++++++++++++++++++---------- client/js/src/utils/stream.ts | 4 ++- client/js/src/utils/submit.ts | 19 +++++++------- 3 files changed, 48 insertions(+), 23 deletions(-) diff --git a/client/js/src/helpers/data.ts b/client/js/src/helpers/data.ts index 22431dc821774..d6edf43835e84 100644 --- a/client/js/src/helpers/data.ts +++ b/client/js/src/helpers/data.ts @@ -136,23 +136,45 @@ export function handle_payload( dependency: Dependency, components: ComponentMeta[], with_null_state = false -): unknown[] { - let payload_index = 0; +): any[] { + try { + let payload_index = 0; + let updated_payload: unknown[] = []; + + dependency.inputs.forEach((input_id) => { + const component = components.find((c) => c.id === input_id); + if (component?.type === "state") { + if (with_null_state) { + updated_payload.push(null); + } + if (!with_null_state) payload_index++; + } else { + const value = resolved_payload[payload_index]; + updated_payload.push(value); + payload_index++; + } + }); + + return updated_payload; + } catch (e) { + console.error(e); + return resolved_payload; + } +} + +export function build_payload( + resolved_payload: unknown[], + dependency: Dependency, + components: ComponentMeta[] +): any[] { let updated_payload: unknown[] = []; - dependency.inputs.forEach((input_id) => { - const component = components.find((c) => c.id === input_id); + dependency.inputs.map((input_id: number, index: number): any => { + const component = components.find((c: any) => c.id === input_id); if (component?.type === "state") { - if (with_null_state) { - updated_payload.push(null); - } - if (!with_null_state) payload_index++; - } else { - const value = resolved_payload[payload_index]; - updated_payload.push(value); - payload_index++; + return null; } + updated_payload.push(resolved_payload[index]); }); - return updated_payload; } diff --git a/client/js/src/utils/stream.ts b/client/js/src/utils/stream.ts index 02df1a968919d..9134d2eb880cb 100644 --- a/client/js/src/utils/stream.ts +++ b/client/js/src/utils/stream.ts @@ -51,7 +51,9 @@ export async function open_stream(this: Client): Promise { } else if (event_callbacks[event_id] && config) { if ( _data.msg === "process_completed" && - ["sse", "sse_v1", "sse_v2", "sse_v2.1"].includes(config.protocol) + ["sse", "sse_v1", "sse_v2", "sse_v2.1", "sse_v3"].includes( + config.protocol + ) ) { unclosed_events.delete(event_id); if (unclosed_events.size === 0) { diff --git a/client/js/src/utils/submit.ts b/client/js/src/utils/submit.ts index 97230192cb5ed..53467933dd7ff 100644 --- a/client/js/src/utils/submit.ts +++ b/client/js/src/utils/submit.ts @@ -14,7 +14,12 @@ import type { Dependency } from "../types"; -import { skip_queue, post_message, handle_payload } from "../helpers/data"; +import { + skip_queue, + post_message, + handle_payload, + build_payload +} from "../helpers/data"; import { resolve_root } from "../helpers/init_helpers"; import { handle_message, @@ -193,14 +198,9 @@ export function submit( this.handle_blob(config.root, resolved_data, endpoint_info).then( async (_payload) => { - let input_data = handle_payload( - _payload, - dependency, - config.components, - true - ); + let input_data = build_payload(_payload, dependency, config.components); payload = { - data: input_data || [], + data: input_data || _payload || [], event_data, fn_index, trigger_id @@ -231,7 +231,8 @@ export function submit( type: "data", endpoint: _endpoint, fn_index, - data: handle_payload(data, dependency, config.components), + // data: handle_payload(data, dependency, config.components), + data: data, time: new Date(), event_data, trigger_id