const std = @import("std"); const builtin = @import("builtin"); const mod = @import("../root.zig"); const Env = mod.Env; const Function = Env.Function; const wasm = @import("wasm.root.zig"); const server = @import("server.root.zig"); pub fn Bridge(T: type) type { if (builtin.target.cpu.arch.isWasm()) { return wasm.Bridge(T); } else { return server.Bridge(T); } } pub const Context = struct { gpa: std.mem.Allocator, arena: std.mem.Allocator, io: std.Io, }; pub const bindings = struct { pub const call: Function = .from( \\async function(ptr, len, result_ptr, len_check) { \\ const response = await fetch("/api", { \\ method: "POST", \\ body: new DateView(wasm.memory.buffer, ptr, len), \\ }) \\ const bytes = await response.bytes(); \\ if (bytes.length != len_check) { \\ throw "response has incorrect size"; \\ } \\ const memory = new Uint8Array(wasm.memory.buffer); \\ memory.set(bytes, result_ptr); \\} ); };