// jsAdapter.h -- QuickJS-ng (JavaScript, ES2023+) engine adapter for the broker.
//
// Exposes broker-registered native functions into a QuickJS context, marshals values
// between JavaScript and CalogValueT by value (binary-safe strings; array <-> list,
// object <-> map; a JS BigInt round-trips to int64 exactly), and exports JS functions
// as refcounted CalogFnT handles. A JS function crossing out is retained with
// JS_DupValue and dropped with JS_FreeValue on release -- no GC registry needed.
//
// Lifetime note (as with Lua/Squirrel): release every CalogFnT obtained from
// calogJsExport (and drop every function value marshalled out) BEFORE calogJsDestroy,
// since the release touches the JS runtime.

#ifndef JS_ADAPTER_H
#define JS_ADAPTER_H

#include "calogInternal.h"

typedef struct CalogJsT CalogJsT;

int32_t calogJsCreate(CalogJsT **out, CalogT *broker, uint64_t ctxId);
void    calogJsDestroy(CalogJsT *context);
int32_t calogJsExport(CalogJsT *context, const char *globalName, CalogFnT **out);
int32_t calogJsExpose(CalogJsT *context, const char *name);
int32_t calogJsRun(CalogJsT *context, const char *source);

#endif
