diff --git a/js_adapter/js_class_adapter.ts b/js_adapter/js_class_adapter.ts index caf65f88..f56f445b 100644 --- a/js_adapter/js_class_adapter.ts +++ b/js_adapter/js_class_adapter.ts @@ -1150,26 +1150,31 @@ function getMethodParams(target:Function, method_name:string, meta_param_index?: if (!(method_name in target)) return null; - let tuple = new Tuple(); - let metadata:any[] = MetadataReflect.getMetadata && MetadataReflect.getMetadata("design:paramtypes", target, method_name); + const tuple = new Tuple(); + const metadata:any[] = MetadataReflect.getMetadata && MetadataReflect.getMetadata("design:paramtypes", target, method_name); if (!metadata) return null; // get parmeters names from function body string const function_body:string = target[method_name]?.toString(); - const args_strings = function_body?.match(/^[^(]*\(([^)]*)\)/)?.[1]?.split(","); - if (args_strings) { - for (let i=0;i any = (...args: any) => any> e const args_match = function_body?.match(/^[^(]*\(([^)]*)\)/)?.[1]; if (!args_match?.length) return tuple; - const args_strings = args_match.split(","); + const args_strings = this.normalizeFunctionParams(args_match).split(","); if (args_strings) { for (let arg of args_strings) { arg = arg.trim().split(/[ =]/)[0]; @@ -244,6 +244,32 @@ export class Function any = (...args: any) => any> e return tuple; } + /** + * Normalizes a function params string, replacing destructuring with a single variable + */ + private static normalizeFunctionParams(params: string) { + let scopes = 0; + let nestedIndex = undefined; + + let i=0; + let varCount = 0; + for (const x of params) { + if (x === "["||x === "{") scopes++; + if (x === "]"||x === "}") scopes--; + if (nestedIndex == undefined && scopes !== 0) { + nestedIndex = i; + } + else if(nestedIndex != undefined && scopes == 0) { + params = [...params].toSpliced(nestedIndex, i-nestedIndex+1, 'x_'+(varCount++)).join("") + i = nestedIndex + nestedIndex = undefined; + } + i++; + } + + return params; + } + // execute this function remotely, set the endpoint private setRemoteEndpoint(endpoint: Endpoint){ diff --git a/utils/error-reporting.ts b/utils/error-reporting.ts index 3ebd8bbe..9676f820 100644 --- a/utils/error-reporting.ts +++ b/utils/error-reporting.ts @@ -1,6 +1,7 @@ import { Compiler } from "../compiler/compiler.ts"; import { sendDatexViaHTTPChannel } from "../network/datex-http-channel.ts"; import { Runtime } from "../runtime/runtime.ts"; +import { LOCAL_ENDPOINT } from "../types/addressing.ts"; import { getCallerInfo } from "../utils/caller_metadata.ts"; import { logger } from "./global_values.ts"; @@ -24,7 +25,7 @@ export async function sendReport(identifier: string, reportData:Record await Compiler.compile(dx, [report], {sign: false, encrypt: false}); + const dxb = await Compiler.compile(dx, [report], {sign: false, encrypt: false, to: LOCAL_ENDPOINT}); sendDatexViaHTTPChannel(dxb, "https://status.unyt.org") }