A WebSocket client for communicating with Hexput Runtime servers. This client allows for remote execution of Hexput code, parsing, and function registration with a Hexput Runtime instance.
npm install hexputimportHexputClientfrom'hexput';// Create a new client instanceconstclient=newHexputClient('ws://localhost:9091',{debug: true});// Close connection when doneclient.close();Execute Hexput code on the remote Hexput Runtime:
constresult=awaitclient.execute(` vl x = 10; vl y = 20; res x + y;`);console.log(result);// 30With execution options:
constoptions={no_loops: true,no_conditionals: true};try{constresult=awaitclient.execute(` vl items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; loop item in items { // This will fail due to no_loops option print(item); } `,options);}catch(error){console.error('Execution failed:',error.message);// Will throw an error due to no_loops option}Parse Hexput code to obtain its AST:
constast=awaitclient.parse(`cb add(a, b) { res a + b; }`);console.log(ast);Register JavaScript functions that can be called from Hexput code:
// Register a functionclient.registerFunction('fetchData',async(url)=>{constresponse=awaitfetch(url);returnresponse.json();});// Unregister a functionclient.unregisterFunction('fetchData');newHexputClient(url: string,options?: {debug?: boolean})url: WebSocket URL of the Hexput Runtime serveroptions: Configuration optionsdebug: Enable debug logging (default: false)
Connect to the Hexput Runtime server.
Close the WebSocket connection.
Execute Hexput code in the Hexput Runtime.
code: The Hexput code to executeoptions: Execution options (see below)context: Initial context for execution
Parse Hexput code using the Hexput Runtime.
code: The Hexput code to parseoptions: Parse options (see below)
Register a JavaScript function that can be called from Hexput code.
name: The name of the functionhandler: The function handler
Unregister a function.
name: The name of the function to unregister
interfaceHexputOptions{/** Minify the output (default: true) */minify?: boolean;/** Include source mapping in output (default: false) */include_source_mapping?: boolean;/** Disable object construction literals (default: false) */no_object_constructions?: boolean;/** Disable array construction literals (default: false) */no_array_constructions?: boolean;/** Disable object property access (default: false) */no_object_navigation?: boolean;/** Disable variable declarations (default: false) */no_variable_declaration?: boolean;/** Disable loops (default: false) */no_loops?: boolean;/** Disable object keys access (default: false) */no_object_keys?: boolean;/** Disable callback functions (default: false) */no_callbacks?: boolean;/** Disable conditional statements (default: false) */no_conditionals?: boolean;/** Disable return statements (default: false) */no_return_statements?: boolean;/** Disable loop control (break/continue) (default: false) */no_loop_control?: boolean;/** Disable operators (default: false) */no_operators?: boolean;/** Disable equality operators (default: false) */no_equality?: boolean;/** Disable assignment operators (default: false) */no_assignments?: boolean;}/** Options for parse operation */typeHexputParseOptions=HexputOptions;/** Options for execution operation */typeHexputExecutionOptions=Omit<HexputOptions,"minify">;