feat: Implement Anisette JS/TS API with WASM support
- Added main Anisette class for high-level API. - Introduced device management with Device class. - Created HTTP client abstraction for network requests. - Implemented provisioning session handling with ProvisioningSession class. - Added utility functions for encoding, decoding, and random generation. - Established library management with LibraryStore class. - Integrated WASM loading and bridging with WasmBridge. - Defined core types and interfaces for the API. - Set up TypeScript configuration and build scripts. - Updated package.json for new build and run commands. - Added bun.lock and package.json for JS dependencies. - Enhanced error handling and memory management in Rust code.
This commit is contained in:
27
js/src/wasm-loader.ts
Normal file
27
js/src/wasm-loader.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
// Loads the Emscripten WASM glue bundled alongside this file.
|
||||
// The .wasm binary is resolved relative to this JS file at runtime.
|
||||
|
||||
// @ts-ignore — glue file is generated, no types available
|
||||
import ModuleFactory from "../../dist/anisette_rs.node.js";
|
||||
import { createRequire } from "node:module";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import path from "node:path";
|
||||
|
||||
// Resolve the .wasm file next to the bundled output JS
|
||||
function resolveWasmPath(outputFile: string): string {
|
||||
// __filename of the *bundled* output — bun sets import.meta.url correctly
|
||||
const dir = path.dirname(fileURLToPath(import.meta.url));
|
||||
return path.join(dir, outputFile);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export async function loadWasm(): Promise<any> {
|
||||
return ModuleFactory({
|
||||
locateFile(file: string) {
|
||||
if (file.endsWith(".wasm")) {
|
||||
return resolveWasmPath("anisette_rs.node.wasm");
|
||||
}
|
||||
return file;
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user